@cuongtran001/kanna 0.85.0 → 0.85.2

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.
Files changed (60) hide show
  1. package/dist/client/assets/{arc-Kt9FjdSX.js → arc-DqufIF2i.js} +1 -1
  2. package/dist/client/assets/{architectureDiagram-3BPJPVTR-tm4reZg8.js → architectureDiagram-3BPJPVTR-BzpTUOed.js} +1 -1
  3. package/dist/client/assets/{blockDiagram-GPEHLZMM-BNb3jFY7.js → blockDiagram-GPEHLZMM-Djo9-djJ.js} +1 -1
  4. package/dist/client/assets/{c4Diagram-AAUBKEIU-Br7Qfsmd.js → c4Diagram-AAUBKEIU-xjXcsR6d.js} +1 -1
  5. package/dist/client/assets/channel-3lOnBu6-.js +1 -0
  6. package/dist/client/assets/{chunk-2J33WTMH-DuGnCxwq.js → chunk-2J33WTMH-Lxu5Ir5t.js} +1 -1
  7. package/dist/client/assets/{chunk-4BX2VUAB-CH33-yFl.js → chunk-4BX2VUAB-CjEeAJto.js} +1 -1
  8. package/dist/client/assets/{chunk-55IACEB6-DxZxt-D-.js → chunk-55IACEB6-B13RtSPQ.js} +1 -1
  9. package/dist/client/assets/{chunk-727SXJPM-RCW7V-bU.js → chunk-727SXJPM-C7E3san4.js} +1 -1
  10. package/dist/client/assets/{chunk-AQP2D5EJ-W9JREvRo.js → chunk-AQP2D5EJ-O5gNd7J6.js} +1 -1
  11. package/dist/client/assets/{chunk-FMBD7UC4-CwM-p2xP.js → chunk-FMBD7UC4-BaLgZ1Ss.js} +1 -1
  12. package/dist/client/assets/{chunk-ND2GUHAM-DFEyH0Mb.js → chunk-ND2GUHAM-C7YGUGCD.js} +1 -1
  13. package/dist/client/assets/{chunk-QZHKN3VN-C8D7Vxby.js → chunk-QZHKN3VN-CXUb7E80.js} +1 -1
  14. package/dist/client/assets/classDiagram-4FO5ZUOK-DOR_gFe1.js +1 -0
  15. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-DOR_gFe1.js +1 -0
  16. package/dist/client/assets/{cose-bilkent-S5V4N54A-WCX7XvfB.js → cose-bilkent-S5V4N54A-Dqd6zrLY.js} +1 -1
  17. package/dist/client/assets/{dagre-BM42HDAG-B8V3Rg2_.js → dagre-BM42HDAG-CmCJXG8x.js} +1 -1
  18. package/dist/client/assets/{diagram-2AECGRRQ-C0rM1XA-.js → diagram-2AECGRRQ-DSm-yB9l.js} +1 -1
  19. package/dist/client/assets/{diagram-5GNKFQAL-BtSgEMet.js → diagram-5GNKFQAL-DZ8DajUY.js} +1 -1
  20. package/dist/client/assets/{diagram-KO2AKTUF-D9oHu2vn.js → diagram-KO2AKTUF-CUMiO5Z6.js} +1 -1
  21. package/dist/client/assets/{diagram-LMA3HP47-CqcyrW5y.js → diagram-LMA3HP47-J83pv63u.js} +1 -1
  22. package/dist/client/assets/{diagram-OG6HWLK6-CjBJCZcM.js → diagram-OG6HWLK6-B4J-23TD.js} +1 -1
  23. package/dist/client/assets/{erDiagram-TEJ5UH35-D_QshwG1.js → erDiagram-TEJ5UH35-ZGIgeBj2.js} +1 -1
  24. package/dist/client/assets/{flowDiagram-I6XJVG4X-DzmnDYXh.js → flowDiagram-I6XJVG4X-ywg0eA_Y.js} +1 -1
  25. package/dist/client/assets/{ganttDiagram-6RSMTGT7-Cy_RGHLm.js → ganttDiagram-6RSMTGT7-Dwj065D2.js} +1 -1
  26. package/dist/client/assets/{gitGraphDiagram-PVQCEYII-C2WODWRU.js → gitGraphDiagram-PVQCEYII-B6hfRSVN.js} +1 -1
  27. package/dist/client/assets/{index-D8qSUuu7.js → index-DPk3P79C.js} +1 -1
  28. package/dist/client/assets/{index-_9JL0pB2.js → index-DvZfv6FI.js} +2 -2
  29. package/dist/client/assets/{infoDiagram-5YYISTIA-nm8mIAr5.js → infoDiagram-5YYISTIA-C1_Xs5N6.js} +1 -1
  30. package/dist/client/assets/{ishikawaDiagram-YF4QCWOH-B3w-gvF4.js → ishikawaDiagram-YF4QCWOH-b7DYesFr.js} +1 -1
  31. package/dist/client/assets/{journeyDiagram-JHISSGLW-BqaIhoIL.js → journeyDiagram-JHISSGLW-uzCJrkSx.js} +1 -1
  32. package/dist/client/assets/{kanban-definition-UN3LZRKU-D0N2e0eu.js → kanban-definition-UN3LZRKU-B785m1Cp.js} +1 -1
  33. package/dist/client/assets/{linear-DMfrSq3I.js → linear-BIScwe3Z.js} +1 -1
  34. package/dist/client/assets/{mermaid.core-BdksXM55.js → mermaid.core-k9C_NeOW.js} +4 -4
  35. package/dist/client/assets/{mindmap-definition-RKZ34NQL-IuzkWeUF.js → mindmap-definition-RKZ34NQL-BTHC8I0j.js} +1 -1
  36. package/dist/client/assets/{pieDiagram-4H26LBE5-geMESRpM.js → pieDiagram-4H26LBE5-C9flyOVo.js} +1 -1
  37. package/dist/client/assets/{quadrantDiagram-W4KKPZXB-ncr5piiK.js → quadrantDiagram-W4KKPZXB-SKfSZSFu.js} +1 -1
  38. package/dist/client/assets/{requirementDiagram-4Y6WPE33-CTxS_6lu.js → requirementDiagram-4Y6WPE33-Bs5Wm8SH.js} +1 -1
  39. package/dist/client/assets/{sankeyDiagram-5OEKKPKP-BKeeVVjN.js → sankeyDiagram-5OEKKPKP-DNaQm50M.js} +1 -1
  40. package/dist/client/assets/{sequenceDiagram-3UESZ5HK-vfP3esQH.js → sequenceDiagram-3UESZ5HK-1b7hlOri.js} +1 -1
  41. package/dist/client/assets/{stateDiagram-AJRCARHV-DwXsxOl4.js → stateDiagram-AJRCARHV-BfwNyiKj.js} +1 -1
  42. package/dist/client/assets/stateDiagram-v2-BHNVJYJU-BSBCfneW.js +1 -0
  43. package/dist/client/assets/{timeline-definition-PNZ67QCA-vzPMS_82.js → timeline-definition-PNZ67QCA-BN3tSaSX.js} +1 -1
  44. package/dist/client/assets/{vennDiagram-CIIHVFJN-0PyLVKSW.js → vennDiagram-CIIHVFJN-vpwblBC9.js} +1 -1
  45. package/dist/client/assets/{wardley-L42UT6IY-Cm8gdV4l.js → wardley-L42UT6IY-C10F_jOZ.js} +1 -1
  46. package/dist/client/assets/{wardleyDiagram-YWT4CUSO-BzhxMonl.js → wardleyDiagram-YWT4CUSO-BB2zRzgO.js} +1 -1
  47. package/dist/client/assets/{xychartDiagram-2RQKCTM6-5euoA7yB.js → xychartDiagram-2RQKCTM6-CEPtwV34.js} +1 -1
  48. package/dist/client/index.html +1 -1
  49. package/package.json +1 -1
  50. package/src/server/agent.test.ts +251 -1
  51. package/src/server/agent.ts +113 -4
  52. package/src/server/claude-pty/driver.ts +21 -8
  53. package/src/server/claude-pty/pid-registry.adapter.ts +82 -10
  54. package/src/server/claude-pty/pid-registry.test.ts +77 -9
  55. package/src/server/claude-pty/pty-instance-registry.test.ts +34 -0
  56. package/src/server/claude-pty/pty-instance-registry.ts +17 -0
  57. package/dist/client/assets/channel-CWPZ2NK8.js +0 -1
  58. package/dist/client/assets/classDiagram-4FO5ZUOK-Bba1hVEY.js +0 -1
  59. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-Bba1hVEY.js +0 -1
  60. package/dist/client/assets/stateDiagram-v2-BHNVJYJU-BFdFnv9h.js +0 -1
@@ -733,7 +733,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
733
733
  `)!==n.readPathDeny.join(`
734
734
  `)&&(A.readPathDeny=T),R.join(`
735
735
  `)!==n.writePathDeny.join(`
736
- `)&&(A.writePathDeny=R),Object.keys(A).length===0?null:A}function E(){i(C())}function k(){i(null)}return u.jsxs(u.Fragment,{children:[u.jsx(so,{open:e,onOpenChange:T=>{T||s()},children:u.jsxs(As,{className:"max-w-2xl",children:[u.jsxs(oo,{children:["Permissions — ",t]}),u.jsxs(Ho,{className:"space-y-5",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx("div",{className:"text-sm font-medium",children:"Default action"}),u.jsxs("div",{className:"text-xs text-muted-foreground",children:["Behaviour when a tool call has no explicit allow/deny rule. ",u.jsx("strong",{children:"auto-allow"})," bypasses prompts and runs untrusted shell commands without supervision — use a worktree."]}),u.jsx(Ii,{value:o,onValueChange:w,options:[{value:"ask",label:"Ask"},{value:"auto-allow",label:"Auto-allow (unsafe)"},{value:"auto-deny",label:"Auto-deny"}]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("div",{className:"text-sm font-medium",children:"Read-path deny list"}),u.jsx("div",{className:"text-xs text-muted-foreground",children:"One glob per line. The model cannot read paths matching any entry. Defaults shown below — edit to add or remove."}),u.jsx("textarea",{value:c,onChange:T=>d(T.target.value),rows:8,className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-xs",spellCheck:!1})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("div",{className:"text-sm font-medium",children:"Write-path deny list"}),u.jsx("div",{className:"text-xs text-muted-foreground",children:"One glob per line. The model cannot edit or write paths matching any entry."}),u.jsx("textarea",{value:f,onChange:T=>m(T.target.value),rows:8,className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-xs",spellCheck:!1})]})]}),u.jsxs(Kl,{className:"justify-between",children:[u.jsx(De,{variant:"ghost",onClick:k,children:"Reset to defaults"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(De,{variant:"ghost",onClick:s,children:"Cancel"}),u.jsx(De,{onClick:E,children:"Apply"})]})]})]})}),u.jsx(so,{open:g,onOpenChange:T=>{T||(b(!1),_(null))},children:u.jsxs(As,{className:"max-w-md",children:[u.jsx(oo,{children:"Enable auto-allow for this chat?"}),u.jsxs(Ho,{className:"space-y-3 text-sm",children:[u.jsx("p",{children:"Auto-allow disables tool-call prompts. The model can run shell commands, write files, and edit code without asking. Read/write deny lists still apply."}),u.jsx("p",{className:"text-warning",children:"Use a worktree for risky tasks."})]}),u.jsxs(Kl,{className:"justify-end gap-2",children:[u.jsx(De,{variant:"ghost",onClick:()=>{b(!1),_(null)},children:"Cancel"}),u.jsx(De,{variant:"destructive",onClick:()=>{y&&a(y),b(!1),_(null)},children:"Enable auto-allow"})]})]})})]})}const vZ={defaultAction:"ask",bash:{autoAllowVerbs:["ls","pwd","git status","git diff","git log"]},readPathDeny:["~/.ssh","~/.aws","~/.gcp","~/.config/gh","~/.claude","~/.kanna","~/Library/Keychains","/etc/shadow","/etc/sudoers","~/.gnupg","~/.gitconfig","**/.git/config","~/.npmrc","~/.netrc","~/.docker/config.json","**/.env","**/.env.*","**/credentials*","**/*.pem","**/*.key","**/id_rsa*","**/id_ed25519*"],writePathDeny:["/etc/**","/usr/**","/System/**","~/.ssh/**","~/.aws/**","~/.config/gh/**","~/.claude/**","~/.kanna/**","~/.gnupg/**","~/.gitconfig","**/.git/config"],toolDenyList:[{tool:"mcp__kanna__bash",pattern:"rm\\s+-rf\\s+(/|~|\\$HOME)(?:\\b|$|\\s)"},{tool:"mcp__kanna__bash",pattern:"git\\s+push\\b.*--force"}],toolAllowList:[]},mn=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{ref:r,type:t,className:de("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}));mn.displayName="Input";const I3=v.createContext(null);function bZ({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,y;(b=s.current)==null||b.focus(),(y=s.current)==null||y.select()},0))},[t]);const o=v.useCallback(()=>{n(null),i("")},[]),a=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]),d=v.useCallback(b=>new Promise(y=>{n({kind:"confirm",options:b,resolve:y})}),[]),f=v.useCallback(b=>new Promise(y=>{n({kind:"prompt",options:b,resolve:y})}),[]),m=v.useCallback(b=>new Promise(y=>{n({kind:"alert",options:b,resolve:y})}),[]),g=v.useMemo(()=>({confirm:d,prompt:f,alert:m}),[m,d,f]);return u.jsxs(I3.Provider,{value:g,children:[e,u.jsx(so,{open:t!==null,onOpenChange:b=>{b||!t||a()},children:u.jsx(As,{size:"sm",onKeyDown:b=>{b.key!=="Enter"||b.shiftKey||!t||t.kind!=="confirm"||(b.preventDefault(),c())},children:t?u.jsxs(u.Fragment,{children:[u.jsxs(Ho,{className:"space-y-4",children:[u.jsx(oo,{children:t.options.title}),t.options.description?u.jsx(np,{children:t.options.description}):null,t.kind==="prompt"?u.jsx(mn,{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]}),u.jsxs(Kl,{children:[u.jsx(De,{variant:"ghost",size:"sm",onClick:a,className:t.kind==="alert"?"hidden":void 0,children:"cancelLabel"in t.options?t.options.cancelLabel??"Cancel":"Cancel"}),u.jsx(De,{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 op(){const e=v.useContext(I3);if(!e)throw new Error("useAppDialog must be used within AppDialogProvider");return e}const Uk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("bg-card text-card-foreground",e),...t}));Uk.displayName="Card";const Vk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("flex flex-col space-y-1.5 p-2",e),...t}));Vk.displayName="CardHeader";const D3=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:de("text-2xl font-semibold leading-none tracking-tight",e),...t}));D3.displayName="CardTitle";const P3=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:de("text-sm text-muted-foreground",e),...t}));P3.displayName="CardDescription";const Wk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("p-6 pt-0",e),...t}));Wk.displayName="CardContent";const xZ=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("flex items-center p-6 pt-0",e),...t}));xZ.displayName="CardFooter";const yZ={info:{dotVar:"var(--info)",bgClass:"bg-info/[0.06]"},warning:{dotVar:"var(--warning)",bgClass:"bg-warning/[0.06]"},success:{dotVar:"var(--success)",bgClass:"bg-success/[0.06]"},error:{dotVar:"var(--destructive)",bgClass:"bg-destructive/[0.06]"}};function _Z({variant:e,children:t,dot:n=!0,className:r}){const i=yZ[e];return u.jsxs("div",{role:"status",className:de("flex flex-wrap items-center justify-center gap-x-2 gap-y-1 border-b border-border px-4 py-2 text-xs leading-tight",i.bgClass,r),children:[n?u.jsx("span",{"aria-hidden":"true",className:"inline-block size-1.5 shrink-0 rounded-full",style:{backgroundColor:i.dotVar}}):null,t]})}const wZ="modulepreload",SZ=function(e){return"/"+e},Uj={},Y=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(d){return Promise.all(d.map(f=>Promise.resolve(f).then(m=>({status:"fulfilled",value:m}),m=>({status:"rejected",reason:m}))))};document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),c=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));i=o(n.map(d=>{if(d=SZ(d),d in Uj)return;Uj[d]=!0;const f=d.endsWith(".css"),m=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${m}`))return;const g=document.createElement("link");if(g.rel=f?"stylesheet":wZ,f||(g.as="script"),g.crossOrigin="",g.href=d,c&&g.setAttribute("nonce",c),document.head.appendChild(g),f)return new Promise((b,y)=>{g.addEventListener("load",b),g.addEventListener("error",()=>y(new Error(`Unable to preload CSS for ${d}`)))})}))}function s(o){const a=new Event("vite:preloadError",{cancelable:!0});if(a.payload=o,window.dispatchEvent(a),!a.defaultPrevented)throw o}return i.then(o=>{for(const a of o||[])a.status==="rejected"&&s(a.reason);return t().catch(s)})},CZ=v.lazy(()=>Y(()=>import("./index-D8qSUuu7.js"),[]).then(e=>({default:e.Toaster})));function kZ(){return u.jsx(v.Suspense,{fallback:null,children:u.jsx(CZ,{position:"bottom-right",theme:"system",closeButton:!0,duration:6e3})})}const EZ="0.85.0",NZ={version:EZ},Zn="Kanna",Vj="kanna",TZ=".kanna",RZ=".kanna-dev",AZ="KANNA_RUNTIME_PROFILE",Gk=`kanna/${NZ.version}`,jZ="[kanna]",MZ=`~/${Zn}`;function $x(){var t;return(t=globalThis.process)==null?void 0:t.env}function LZ(e=$x()){var t;return((t=e==null?void 0:e[AZ])==null?void 0:t.trim().toLowerCase())==="dev"?"dev":"prod"}function IZ(e=$x()){return LZ(e)==="dev"?RZ:TZ}function DZ(e=$x()){return`~/${IZ(e)}`}function PZ(e=$x()){return`${DZ(e)}/keybindings.json`}function qg(e){return e?`${Vj} ${e}`:Vj}const Wj=e=>{let t;const n=new Set,r=(d,f)=>{const m=typeof d=="function"?d(t):d;if(!Object.is(m,t)){const g=t;t=f??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(b=>b(t,g))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>c,subscribe:d=>(n.add(d),()=>n.delete(d))},c=t=e(r,i,a);return a},OZ=(e=>e?Wj(e):Wj),zZ=e=>e;function BZ(e,t=zZ){const n=yn.useSyncExternalStore(e.subscribe,yn.useCallback(()=>t(e.getState()),[e,t]),yn.useCallback(()=>t(e.getInitialState()),[e,t]));return yn.useDebugValue(n),n}const Gj=e=>{const t=OZ(e),n=r=>BZ(t,r);return Object.assign(n,t),n},ss=(e=>e?Gj(e):Gj),O3="always",z3="funk",FZ=[{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 $Z(e){switch(e){case"never":case"unfocused":case"always":return e;default:return O3}}function HZ(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 z3}}const Oc=ss()(e=>({chatSoundPreference:O3,chatSoundId:z3,setChatSoundPreference:t=>e({chatSoundPreference:$Z(t)}),setChatSoundId:t=>e({chatSoundId:HZ(t)})})),UZ={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 VZ(e=document){return e.visibilityState!=="visible"||!e.hasFocus()}function WZ(e){const t=new Audio(UZ[e]);return t.preload="auto",t.play()}async function QS(e,t){if(t<=0)return;const n=Array.from({length:t},(r,i)=>new Promise(s=>{window.setTimeout(()=>{WZ(e).catch(()=>{}).finally(()=>s())},i*90)}));await Promise.all(n)}function GZ(e,t=document){return e==="never"?!1:e==="always"?!0:VZ(t)}function qZ(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 qj(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 KZ(e,t){if(!e)return 0;const n=qj(e),r=qj(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 ZS(e){return e.split(/[\s_-]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}const YZ=[/^(?:\/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 B3(e){const t=e.trim();for(const n of YZ){const r=t.match(n);if(!r)continue;const i=(r[2]??r[1]??"").trim();if(i)return i}return t}function qk(e){return e.split("/").pop()||e}const XZ=1440*6e4;function QZ(e,t){if(e===void 0)return null;const n=Math.max(0,t-e),r=6e4,i=60*r,s=XZ,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 ZZ(e){return e.lastMessageAt??e._creationTime}const Kk=1e3,Jv=60*Kk,yd=60*Jv,K_=24*yd;function Ao(e){const t=Math.max(0,e);if(t<Jv)return`${Math.floor(t/Kk)}s`;if(t<yd)return`${Math.floor(t/Jv)}m`;if(t<K_){const i=Math.floor(t/yd),s=Math.floor(t%yd/Jv);return s===0?`${i}h`:`${i}h ${s}m`}const n=Math.floor(t/K_),r=Math.floor(t%K_/yd);return r===0?`${n}d`:`${n}d ${r}h`}function JS(e){const t=Math.max(0,e);if(t>=yd)return Ao(t);const n=Math.floor(t/Kk),r=Math.floor(n/60),i=n%60;return`${r}:${i.toString().padStart(2,"0")}`}function e1(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 Kj(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 Yj(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 Yk(e){const t=e+"CollectionProvider",[n,r]=Ha(t),[i,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=_=>{const{scope:w,children:C}=_,E=yn.useRef(null),k=yn.useRef(new Map).current;return u.jsx(i,{scope:w,itemMap:k,collectionRef:E,children:C})};o.displayName=t;const a=e+"CollectionSlot",c=Gc(a),d=yn.forwardRef((_,w)=>{const{scope:C,children:E}=_,k=s(a,C),T=bn(w,k.collectionRef);return u.jsx(c,{ref:T,children:E})});d.displayName=a;const f=e+"CollectionItemSlot",m="data-radix-collection-item",g=Gc(f),b=yn.forwardRef((_,w)=>{const{scope:C,children:E,...k}=_,T=yn.useRef(null),R=bn(w,T),A=s(f,C);return yn.useEffect(()=>(A.itemMap.set(T,{ref:T,...k}),()=>void A.itemMap.delete(T))),u.jsx(g,{[m]:"",ref:R,children:E})});b.displayName=f;function y(_){const w=s(e+"CollectionConsumer",_);return yn.useCallback(()=>{const E=w.collectionRef.current;if(!E)return[];const k=Array.from(E.querySelectorAll(`[${m}]`));return Array.from(w.itemMap.values()).sort((A,j)=>k.indexOf(A.ref.current)-k.indexOf(j.ref.current))},[w.collectionRef,w.itemMap])}return[{Provider:o,Slot:d,ItemSlot:b},y,r]}var JZ=v.createContext(void 0);function Xk(e){const t=v.useContext(JZ);return e||t||"ltr"}var Y_="rovingFocusGroup.onEntryFocus",eJ={bubbles:!1,cancelable:!0},ap="RovingFocusGroup",[t1,F3,tJ]=Yk(ap),[nJ,$3]=Ha(ap,[tJ]),[rJ,iJ]=nJ(ap),H3=v.forwardRef((e,t)=>u.jsx(t1.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(t1.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(sJ,{...e,ref:t})})}));H3.displayName=ap;var sJ=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:d,preventScrollOnEntryFocus:f=!1,...m}=e,g=v.useRef(null),b=bn(t,g),y=Xk(s),[_,w]=zd({prop:o,defaultProp:a??null,onChange:c,caller:ap}),[C,E]=v.useState(!1),k=io(d),T=F3(n),R=v.useRef(!1),[A,j]=v.useState(0);return v.useEffect(()=>{const I=g.current;if(I)return I.addEventListener(Y_,k),()=>I.removeEventListener(Y_,k)},[k]),u.jsx(rJ,{scope:n,orientation:r,dir:y,loop:i,currentTabStopId:_,onItemFocus:v.useCallback(I=>w(I),[w]),onItemShiftTab:v.useCallback(()=>E(!0),[]),onFocusableItemAdd:v.useCallback(()=>j(I=>I+1),[]),onFocusableItemRemove:v.useCallback(()=>j(I=>I-1),[]),children:u.jsx(nn.div,{tabIndex:C||A===0?-1:0,"data-orientation":r,...m,ref:b,style:{outline:"none",...e.style},onMouseDown:st(e.onMouseDown,()=>{R.current=!0}),onFocus:st(e.onFocus,I=>{const U=!R.current;if(I.target===I.currentTarget&&U&&!C){const M=new CustomEvent(Y_,eJ);if(I.currentTarget.dispatchEvent(M),!M.defaultPrevented){const D=T().filter(B=>B.focusable),z=D.find(B=>B.active),P=D.find(B=>B.id===_),$=[z,P,...D].filter(Boolean).map(B=>B.ref.current);W3($,f)}}R.current=!1}),onBlur:st(e.onBlur,()=>E(!1))})})}),U3="RovingFocusGroupItem",V3=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...a}=e,c=Aa(),d=s||c,f=iJ(U3,n),m=f.currentTabStopId===d,g=F3(n),{onFocusableItemAdd:b,onFocusableItemRemove:y,currentTabStopId:_}=f;return v.useEffect(()=>{if(r)return b(),()=>y()},[r,b,y]),u.jsx(t1.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:u.jsx(nn.span,{tabIndex:m?0:-1,"data-orientation":f.orientation,...a,ref:t,onMouseDown:st(e.onMouseDown,w=>{r?f.onItemFocus(d):w.preventDefault()}),onFocus:st(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:st(e.onKeyDown,w=>{if(w.key==="Tab"&&w.shiftKey){f.onItemShiftTab();return}if(w.target!==w.currentTarget)return;const C=lJ(w,f.orientation,f.dir);if(C!==void 0){if(w.metaKey||w.ctrlKey||w.altKey||w.shiftKey)return;w.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(w.currentTarget);k=f.loop?cJ(k,T+1):k.slice(T+1)}setTimeout(()=>W3(k))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:_!=null}):o})})});V3.displayName=U3;var oJ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function aJ(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function lJ(e,t,n){const r=aJ(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return oJ[r]}function W3(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function cJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var uJ=H3,dJ=V3,n1=["Enter"," "],hJ=["ArrowDown","PageUp","Home"],G3=["ArrowUp","PageDown","End"],fJ=[...hJ,...G3],mJ={ltr:[...n1,"ArrowRight"],rtl:[...n1,"ArrowLeft"]},pJ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},lp="Menu",[bm,gJ,vJ]=Yk(lp),[du,q3]=Ha(lp,[vJ,Jl,$3]),Hx=Jl(),K3=$3(),[bJ,hu]=du(lp),[xJ,cp]=du(lp),Y3=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,a=Hx(t),[c,d]=v.useState(null),f=v.useRef(!1),m=io(s),g=Xk(i);return v.useEffect(()=>{const b=()=>{f.current=!0,document.addEventListener("pointerdown",y,{capture:!0,once:!0}),document.addEventListener("pointermove",y,{capture:!0,once:!0})},y=()=>f.current=!1;return document.addEventListener("keydown",b,{capture:!0}),()=>{document.removeEventListener("keydown",b,{capture:!0}),document.removeEventListener("pointerdown",y,{capture:!0}),document.removeEventListener("pointermove",y,{capture:!0})}},[]),u.jsx(Px,{...a,children:u.jsx(bJ,{scope:t,open:n,onOpenChange:m,content:c,onContentChange:d,children:u.jsx(xJ,{scope:t,onClose:v.useCallback(()=>m(!1),[m]),isUsingKeyboardRef:f,dir:g,modal:o,children:r})})})};Y3.displayName=lp;var yJ="MenuAnchor",Qk=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Hx(n);return u.jsx(ip,{...i,...r,ref:t})});Qk.displayName=yJ;var Zk="MenuPortal",[_J,X3]=du(Zk,{forceMount:void 0}),Q3=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=hu(Zk,t);return u.jsx(_J,{scope:t,forceMount:n,children:u.jsx(Ds,{present:n||s.open,children:u.jsx(lh,{asChild:!0,container:i,children:r})})})};Q3.displayName=Zk;var Ts="MenuContent",[wJ,Jk]=du(Ts),Z3=v.forwardRef((e,t)=>{const n=X3(Ts,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=hu(Ts,e.__scopeMenu),o=cp(Ts,e.__scopeMenu);return u.jsx(bm.Provider,{scope:e.__scopeMenu,children:u.jsx(Ds,{present:r||s.open,children:u.jsx(bm.Slot,{scope:e.__scopeMenu,children:o.modal?u.jsx(SJ,{...i,ref:t}):u.jsx(CJ,{...i,ref:t})})})})}),SJ=v.forwardRef((e,t)=>{const n=hu(Ts,e.__scopeMenu),r=v.useRef(null),i=bn(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Ax(s)},[]),u.jsx(eE,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:st(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),CJ=v.forwardRef((e,t)=>{const n=hu(Ts,e.__scopeMenu);return u.jsx(eE,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),kJ=Gc("MenuContent.ScrollLock"),eE=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:a,onEntryFocus:c,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:g,onDismiss:b,disableOutsideScroll:y,..._}=e,w=hu(Ts,n),C=cp(Ts,n),E=Hx(n),k=K3(n),T=gJ(n),[R,A]=v.useState(null),j=v.useRef(null),I=bn(t,j,w.onContentChange),U=v.useRef(0),M=v.useRef(""),D=v.useRef(0),z=v.useRef(null),P=v.useRef("right"),F=v.useRef(0),$=y?tp:v.Fragment,B=y?{as:kJ,allowPinchZoom:!0}:void 0,H=te=>{var ne,ie;const O=M.current+te,K=T().filter(le=>!le.disabled),ee=document.activeElement,V=(ne=K.find(le=>le.ref.current===ee))==null?void 0:ne.textValue,ue=K.map(le=>le.textValue),ge=OJ(ue,O,V),Z=(ie=K.find(le=>le.textValue===ge))==null?void 0:ie.ref.current;(function le(oe){M.current=oe,window.clearTimeout(U.current),oe!==""&&(U.current=window.setTimeout(()=>le(""),1e3))})(O),Z&&setTimeout(()=>Z.focus())};v.useEffect(()=>()=>window.clearTimeout(U.current),[]),Tx();const W=v.useCallback(te=>{var K,ee;return P.current===((K=z.current)==null?void 0:K.side)&&BJ(te,(ee=z.current)==null?void 0:ee.area)},[]);return u.jsx(wJ,{scope:n,searchRef:M,onItemEnter:v.useCallback(te=>{W(te)&&te.preventDefault()},[W]),onItemLeave:v.useCallback(te=>{var O;W(te)||((O=j.current)==null||O.focus(),A(null))},[W]),onTriggerLeave:v.useCallback(te=>{W(te)&&te.preventDefault()},[W]),pointerGraceTimerRef:D,onPointerGraceIntentChange:v.useCallback(te=>{z.current=te},[]),children:u.jsx($,{...B,children:u.jsx(ep,{asChild:!0,trapped:i,onMountAutoFocus:st(s,te=>{var O;te.preventDefault(),(O=j.current)==null||O.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:u.jsx(ah,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:g,onDismiss:b,children:u.jsx(uJ,{asChild:!0,...k,dir:C.dir,orientation:"vertical",loop:r,currentTabStopId:R,onCurrentTabStopIdChange:A,onEntryFocus:st(c,te=>{C.isUsingKeyboardRef.current||te.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(Ox,{role:"menu","aria-orientation":"vertical","data-state":m4(w.open),"data-radix-menu-content":"",dir:C.dir,...E,..._,ref:I,style:{outline:"none",..._.style},onKeyDown:st(_.onKeyDown,te=>{const K=te.target.closest("[data-radix-menu-content]")===te.currentTarget,ee=te.ctrlKey||te.altKey||te.metaKey,V=te.key.length===1;K&&(te.key==="Tab"&&te.preventDefault(),!ee&&V&&H(te.key));const ue=j.current;if(te.target!==ue||!fJ.includes(te.key))return;te.preventDefault();const Z=T().filter(ne=>!ne.disabled).map(ne=>ne.ref.current);G3.includes(te.key)&&Z.reverse(),DJ(Z)}),onBlur:st(e.onBlur,te=>{te.currentTarget.contains(te.target)||(window.clearTimeout(U.current),M.current="")}),onPointerMove:st(e.onPointerMove,xm(te=>{const O=te.target,K=F.current!==te.clientX;if(te.currentTarget.contains(O)&&K){const ee=te.clientX>F.current?"right":"left";P.current=ee,F.current=te.clientX}}))})})})})})})});Z3.displayName=Ts;var EJ="MenuGroup",tE=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(nn.div,{role:"group",...r,ref:t})});tE.displayName=EJ;var NJ="MenuLabel",J3=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(nn.div,{...r,ref:t})});J3.displayName=NJ;var Db="MenuItem",Xj="menu.itemSelect",Ux=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=v.useRef(null),o=cp(Db,e.__scopeMenu),a=Jk(Db,e.__scopeMenu),c=bn(t,s),d=v.useRef(!1),f=()=>{const m=s.current;if(!n&&m){const g=new CustomEvent(Xj,{bubbles:!0,cancelable:!0});m.addEventListener(Xj,b=>r==null?void 0:r(b),{once:!0}),bO(m,g),g.defaultPrevented?d.current=!1:o.onClose()}};return u.jsx(e4,{...i,ref:c,disabled:n,onClick:st(e.onClick,f),onPointerDown:m=>{var g;(g=e.onPointerDown)==null||g.call(e,m),d.current=!0},onPointerUp:st(e.onPointerUp,m=>{var g;d.current||(g=m.currentTarget)==null||g.click()}),onKeyDown:st(e.onKeyDown,m=>{const g=a.searchRef.current!=="";n||g&&m.key===" "||n1.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})});Ux.displayName=Db;var e4=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=Jk(Db,n),a=K3(n),c=v.useRef(null),d=bn(t,c),[f,m]=v.useState(!1),[g,b]=v.useState("");return v.useEffect(()=>{const y=c.current;y&&b((y.textContent??"").trim())},[s.children]),u.jsx(bm.ItemSlot,{scope:n,disabled:r,textValue:i??g,children:u.jsx(dJ,{asChild:!0,...a,focusable:!r,children:u.jsx(nn.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:st(e.onPointerMove,xm(y=>{r?o.onItemLeave(y):(o.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:st(e.onPointerLeave,xm(y=>o.onItemLeave(y))),onFocus:st(e.onFocus,()=>m(!0)),onBlur:st(e.onBlur,()=>m(!1))})})})}),TJ="MenuCheckboxItem",t4=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return u.jsx(o4,{scope:e.__scopeMenu,checked:n,children:u.jsx(Ux,{role:"menuitemcheckbox","aria-checked":Pb(n)?"mixed":n,...i,ref:t,"data-state":rE(n),onSelect:st(i.onSelect,()=>r==null?void 0:r(Pb(n)?!0:!n),{checkForDefaultPrevented:!1})})})});t4.displayName=TJ;var n4="MenuRadioGroup",[RJ,AJ]=du(n4,{value:void 0,onValueChange:()=>{}}),r4=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=io(r);return u.jsx(RJ,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(tE,{...i,ref:t})})});r4.displayName=n4;var i4="MenuRadioItem",s4=v.forwardRef((e,t)=>{const{value:n,...r}=e,i=AJ(i4,e.__scopeMenu),s=n===i.value;return u.jsx(o4,{scope:e.__scopeMenu,checked:s,children:u.jsx(Ux,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":rE(s),onSelect:st(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});s4.displayName=i4;var nE="MenuItemIndicator",[o4,jJ]=du(nE,{checked:!1}),a4=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=jJ(nE,n);return u.jsx(Ds,{present:r||Pb(s.checked)||s.checked===!0,children:u.jsx(nn.span,{...i,ref:t,"data-state":rE(s.checked)})})});a4.displayName=nE;var MJ="MenuSeparator",l4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(nn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});l4.displayName=MJ;var LJ="MenuArrow",c4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Hx(n);return u.jsx(zx,{...i,...r,ref:t})});c4.displayName=LJ;var IJ="MenuSub",[RRe,u4]=du(IJ),Pf="MenuSubTrigger",d4=v.forwardRef((e,t)=>{const n=hu(Pf,e.__scopeMenu),r=cp(Pf,e.__scopeMenu),i=u4(Pf,e.__scopeMenu),s=Jk(Pf,e.__scopeMenu),o=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:c}=s,d={__scopeMenu:e.__scopeMenu},f=v.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return v.useEffect(()=>f,[f]),v.useEffect(()=>{const m=a.current;return()=>{window.clearTimeout(m),c(null)}},[a,c]),u.jsx(Qk,{asChild:!0,...d,children:u.jsx(e4,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":m4(n.open),...e,ref:Ck(t,i.onTriggerChange),onClick:m=>{var g;(g=e.onClick)==null||g.call(e,m),!(e.disabled||m.defaultPrevented)&&(m.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:st(e.onPointerMove,xm(m=>{s.onItemEnter(m),!m.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),f()},100))})),onPointerLeave:st(e.onPointerLeave,xm(m=>{var b,y;f();const g=(b=n.content)==null?void 0:b.getBoundingClientRect();if(g){const _=(y=n.content)==null?void 0:y.dataset.side,w=_==="right",C=w?-5:5,E=g[w?"left":"right"],k=g[w?"right":"left"];s.onPointerGraceIntentChange({area:[{x:m.clientX+C,y:m.clientY},{x:E,y:g.top},{x:k,y:g.top},{x:k,y:g.bottom},{x:E,y:g.bottom}],side:_}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(m),m.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:st(e.onKeyDown,m=>{var b;const g=s.searchRef.current!=="";e.disabled||g&&m.key===" "||mJ[r.dir].includes(m.key)&&(n.onOpenChange(!0),(b=n.content)==null||b.focus(),m.preventDefault())})})})});d4.displayName=Pf;var h4="MenuSubContent",f4=v.forwardRef((e,t)=>{const n=X3(Ts,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=hu(Ts,e.__scopeMenu),o=cp(Ts,e.__scopeMenu),a=u4(h4,e.__scopeMenu),c=v.useRef(null),d=bn(t,c);return u.jsx(bm.Provider,{scope:e.__scopeMenu,children:u.jsx(Ds,{present:r||s.open,children:u.jsx(bm.Slot,{scope:e.__scopeMenu,children:u.jsx(eE,{id:a.contentId,"aria-labelledby":a.triggerId,...i,ref:d,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:f=>{var m;o.isUsingKeyboardRef.current&&((m=c.current)==null||m.focus()),f.preventDefault()},onCloseAutoFocus:f=>f.preventDefault(),onFocusOutside:st(e.onFocusOutside,f=>{f.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:st(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:st(e.onKeyDown,f=>{var b;const m=f.currentTarget.contains(f.target),g=pJ[o.dir].includes(f.key);m&&g&&(s.onOpenChange(!1),(b=a.trigger)==null||b.focus(),f.preventDefault())})})})})})});f4.displayName=h4;function m4(e){return e?"open":"closed"}function Pb(e){return e==="indeterminate"}function rE(e){return Pb(e)?"indeterminate":e?"checked":"unchecked"}function DJ(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function PJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function OJ(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=PJ(e,Math.max(s,0));i.length===1&&(o=o.filter(d=>d!==n));const c=o.find(d=>d.toLowerCase().startsWith(i.toLowerCase()));return c!==n?c:void 0}function zJ(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 a=t[s],c=t[o],d=a.x,f=a.y,m=c.x,g=c.y;f>r!=g>r&&n<(m-d)*(r-f)/(g-f)+d&&(i=!i)}return i}function BJ(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return zJ(n,t)}function xm(e){return t=>t.pointerType==="mouse"?e(t):void 0}var FJ=Y3,$J=Qk,HJ=Q3,UJ=Z3,VJ=tE,WJ=J3,GJ=Ux,qJ=t4,KJ=r4,YJ=s4,XJ=a4,QJ=l4,ZJ=c4,JJ=d4,eee=f4,iE="ContextMenu",[tee]=Ha(iE,[q3]),yi=q3(),[nee,p4]=tee(iE),g4=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:s=!0}=e,[o,a]=v.useState(!1),c=yi(t),d=io(r),f=v.useCallback(m=>{a(m),d(m)},[d]);return u.jsx(nee,{scope:t,open:o,onOpenChange:f,modal:s,children:u.jsx(FJ,{...c,dir:i,open:o,onOpenChange:f,modal:s,children:n})})};g4.displayName=iE;var v4="ContextMenuTrigger",b4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,disabled:r=!1,...i}=e,s=p4(v4,n),o=yi(n),a=v.useRef({x:0,y:0}),c=v.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),d=v.useRef(0),f=v.useCallback(()=>window.clearTimeout(d.current),[]),m=g=>{a.current={x:g.clientX,y:g.clientY},s.onOpenChange(!0)};return v.useEffect(()=>f,[f]),v.useEffect(()=>void(r&&f()),[r,f]),u.jsxs(u.Fragment,{children:[u.jsx($J,{...o,virtualRef:c}),u.jsx(nn.span,{"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,...i,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:st(e.onContextMenu,g=>{f(),m(g),g.preventDefault()}),onPointerDown:r?e.onPointerDown:st(e.onPointerDown,Kg(g=>{f(),d.current=window.setTimeout(()=>m(g),700)})),onPointerMove:r?e.onPointerMove:st(e.onPointerMove,Kg(f)),onPointerCancel:r?e.onPointerCancel:st(e.onPointerCancel,Kg(f)),onPointerUp:r?e.onPointerUp:st(e.onPointerUp,Kg(f))})]})});b4.displayName=v4;var ree="ContextMenuPortal",x4=e=>{const{__scopeContextMenu:t,...n}=e,r=yi(t);return u.jsx(HJ,{...r,...n})};x4.displayName=ree;var y4="ContextMenuContent",_4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=p4(y4,n),s=yi(n),o=v.useRef(!1);return u.jsx(UJ,{...s,...r,ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var c;(c=e.onCloseAutoFocus)==null||c.call(e,a),!a.defaultPrevented&&o.current&&a.preventDefault(),o.current=!1},onInteractOutside:a=>{var c;(c=e.onInteractOutside)==null||c.call(e,a),!a.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)"}})});_4.displayName=y4;var iee="ContextMenuGroup",see=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(VJ,{...i,...r,ref:t})});see.displayName=iee;var oee="ContextMenuLabel",aee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(WJ,{...i,...r,ref:t})});aee.displayName=oee;var lee="ContextMenuItem",w4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(GJ,{...i,...r,ref:t})});w4.displayName=lee;var cee="ContextMenuCheckboxItem",uee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(qJ,{...i,...r,ref:t})});uee.displayName=cee;var dee="ContextMenuRadioGroup",hee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(KJ,{...i,...r,ref:t})});hee.displayName=dee;var fee="ContextMenuRadioItem",mee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(YJ,{...i,...r,ref:t})});mee.displayName=fee;var pee="ContextMenuItemIndicator",gee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(XJ,{...i,...r,ref:t})});gee.displayName=pee;var vee="ContextMenuSeparator",S4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(QJ,{...i,...r,ref:t})});S4.displayName=vee;var bee="ContextMenuArrow",xee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(ZJ,{...i,...r,ref:t})});xee.displayName=bee;var yee="ContextMenuSubTrigger",_ee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(JJ,{...i,...r,ref:t})});_ee.displayName=yee;var wee="ContextMenuSubContent",See=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(eee,{...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)"}})});See.displayName=wee;function Kg(e){return t=>t.pointerType!=="mouse"?e(t):void 0}var Cee=g4,kee=b4,Eee=x4,C4=_4,k4=w4,E4=S4;const N4=v.createContext(null);function fu({onOpenChange:e,...t}){const[n,r]=v.useState(0),i=v.useCallback(()=>{r(s=>s+1),e==null||e(!1)},[e]);return u.jsx(N4.Provider,{value:i,children:u.jsx(Cee,{onOpenChange:e,...t},n)})}const mu=kee,ec=v.forwardRef(({className:e,...t},n)=>u.jsx(Eee,{children:u.jsx(C4,{ref:n,className:de("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})}));ec.displayName=C4.displayName;const Pn=v.forwardRef(({className:e,onSelect:t,...n},r)=>{const i=v.useContext(N4);return u.jsx(k4,{ref:r,className:de("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})});Pn.displayName=k4.displayName;const T4=v.forwardRef(({className:e,...t},n)=>u.jsx(E4,{ref:n,className:de("-mx-1 my-1 h-px bg-border",e),...t}));T4.displayName=E4.displayName;var Vx="Popover",[R4]=Ha(Vx,[Jl]),up=Jl(),[Nee,tc]=R4(Vx),A4=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,a=up(t),c=v.useRef(null),[d,f]=v.useState(!1),[m,g]=zd({prop:r,defaultProp:i??!1,onChange:s,caller:Vx});return u.jsx(Px,{...a,children:u.jsx(Nee,{scope:t,contentId:Aa(),triggerRef:c,open:m,onOpenChange:g,onOpenToggle:v.useCallback(()=>g(b=>!b),[g]),hasCustomAnchor:d,onCustomAnchorAdd:v.useCallback(()=>f(!0),[]),onCustomAnchorRemove:v.useCallback(()=>f(!1),[]),modal:o,children:n})})};A4.displayName=Vx;var j4="PopoverAnchor",Tee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=tc(j4,n),s=up(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:a}=i;return v.useEffect(()=>(o(),()=>a()),[o,a]),u.jsx(ip,{...s,...r,ref:t})});Tee.displayName=j4;var M4="PopoverTrigger",L4=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=tc(M4,n),s=up(n),o=bn(t,i.triggerRef),a=u.jsx(nn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":z4(i.open),...r,ref:o,onClick:st(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?a:u.jsx(ip,{asChild:!0,...s,children:a})});L4.displayName=M4;var sE="PopoverPortal",[Ree,Aee]=R4(sE,{forceMount:void 0}),I4=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=tc(sE,t);return u.jsx(Ree,{scope:t,forceMount:n,children:u.jsx(Ds,{present:n||s.open,children:u.jsx(lh,{asChild:!0,container:i,children:r})})})};I4.displayName=sE;var $d="PopoverContent",D4=v.forwardRef((e,t)=>{const n=Aee($d,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=tc($d,e.__scopePopover);return u.jsx(Ds,{present:r||s.open,children:s.modal?u.jsx(Mee,{...i,ref:t}):u.jsx(Lee,{...i,ref:t})})});D4.displayName=$d;var jee=Gc("PopoverContent.RemoveScroll"),Mee=v.forwardRef((e,t)=>{const n=tc($d,e.__scopePopover),r=v.useRef(null),i=bn(t,r),s=v.useRef(!1);return v.useEffect(()=>{const o=r.current;if(o)return Ax(o)},[]),u.jsx(tp,{as:jee,allowPinchZoom:!0,children:u.jsx(P4,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:st(e.onCloseAutoFocus,o=>{var a;o.preventDefault(),s.current||(a=n.triggerRef.current)==null||a.focus()}),onPointerDownOutside:st(e.onPointerDownOutside,o=>{const a=o.detail.originalEvent,c=a.button===0&&a.ctrlKey===!0,d=a.button===2||c;s.current=d},{checkForDefaultPrevented:!1}),onFocusOutside:st(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Lee=v.forwardRef((e,t)=>{const n=tc($d,e.__scopePopover),r=v.useRef(!1),i=v.useRef(!1);return u.jsx(P4,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,a;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var c,d;(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;((d=n.triggerRef.current)==null?void 0:d.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),P4=v.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:d,onInteractOutside:f,...m}=e,g=tc($d,n),b=up(n);return Tx(),u.jsx(ep,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:u.jsx(ah,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:f,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:d,onDismiss:()=>g.onOpenChange(!1),children:u.jsx(Ox,{"data-state":z4(g.open),role:"dialog",id:g.contentId,...b,...m,ref:t,style:{...m.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)"}})})})}),O4="PopoverClose",Iee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=tc(O4,n);return u.jsx(nn.button,{type:"button",...r,ref:t,onClick:st(e.onClick,()=>i.onOpenChange(!1))})});Iee.displayName=O4;var Dee="PopoverArrow",Pee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=up(n);return u.jsx(zx,{...i,...r,ref:t})});Pee.displayName=Dee;function z4(e){return e?"open":"closed"}var Oee=A4,zee=L4,Bee=I4,B4=D4;const dp=Oee,hp=zee,dh=v.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},i)=>u.jsx(Bee,{children:u.jsx(B4,{ref:i,align:t,sideOffset:n,[mm]:"",onCloseAutoFocus:s=>{var o;s.preventDefault(),window.dispatchEvent(new Event(Nb)),(o=r.onCloseAutoFocus)==null||o.call(r,s)},className:de("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})}));dh.displayName=B4.displayName;function Fee({editorLabel:e,starred:t,onCopyPath:n,onShowArchived:r,onOpenInFinder:i,onOpenInEditor:s,onToggleStar:o,onHide:a,children:c}){return u.jsxs(fu,{children:[u.jsx(mu,{asChild:!0,children:c}),u.jsxs(ec,{children:[u.jsxs(Pn,{onSelect:d=>{d.stopPropagation(),o()},children:[t?u.jsx(Uq,{className:"h-3.5 w-3.5"}):u.jsx(J5,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:t?"Unstar project":"Star project"})]}),u.jsxs(Pn,{onSelect:d=>{d.stopPropagation(),n()},children:[u.jsx(La,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Copy Path"})]}),u.jsxs(Pn,{onSelect:d=>{d.stopPropagation(),r()},children:[u.jsx(fk,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Show Archived"})]}),u.jsxs(Pn,{onSelect:d=>{d.stopPropagation(),i()},children:[u.jsx(Ex,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Show in Finder"})]}),u.jsxs(Pn,{onSelect:d=>{d.stopPropagation(),s()},children:[u.jsx(mk,{className:"h-3.5 w-3.5"}),u.jsxs("span",{className:"text-xs font-medium",children:["Open in ",e]})]}),u.jsxs(Pn,{onSelect:d=>{d.stopPropagation(),a()},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[u.jsx(DW,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Hide"})]})]})]})}function $ee({canFork:e,onRename:t,onOpenInFinder:n,onFork:r,onArchive:i,onDelete:s,onEditPermissions:o,children:a}){return u.jsxs(fu,{children:[u.jsx(mu,{asChild:!0,children:a}),u.jsxs(ec,{children:[u.jsxs(Pn,{onSelect:c=>{c.preventDefault(),t()},children:[u.jsx(oh,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),u.jsxs(Pn,{onSelect:c=>{c.preventDefault(),n()},children:[u.jsx(Ex,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),u.jsxs(Pn,{disabled:!e,onSelect:c=>{c.preventDefault(),e&&r()},children:[u.jsx(Z5,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Fork"})]}),o?u.jsxs(Pn,{onSelect:c=>{c.preventDefault(),o()},children:[u.jsx(Q5,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Permissions…"})]}):null,u.jsxs(Pn,{onSelect:c=>{c.preventDefault(),i()},children:[u.jsx(fk,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Archive"})]}),u.jsxs(Pn,{onSelect:c=>{c.preventDefault(),s()},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:[u.jsx(cu,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Delete"})]})]})]})}function Hee({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){const[s,o]=v.useState(!1);function a(c){return()=>{o(!1),c()}}return u.jsxs(dp,{open:s,onOpenChange:o,children:[u.jsx(hp,{asChild:!0,children:i}),u.jsxs(dh,{align:"end",sideOffset:4,className:"w-44 p-1",role:"menu","aria-label":`Actions for ${e}`,children:[u.jsxs("button",{type:"button",role:"menuitem",onClick:a(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:[u.jsx(oh,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Rename"})]}),u.jsxs("button",{type:"button",role:"menuitem",onClick:a(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:[u.jsx(eO,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Edit members"})]}),u.jsxs("button",{type:"button",role:"menuitem",onClick:a(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:[u.jsx(cu,{className:"h-3.5 w-3.5"}),u.jsxs("span",{children:["Delete ",e]})]})]})]})}function Uee({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){return u.jsxs(fu,{children:[u.jsx(mu,{asChild:!0,children:i}),u.jsxs(ec,{children:[u.jsxs(Pn,{onSelect:s=>{s.preventDefault(),t()},children:[u.jsx(oh,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),u.jsxs(Pn,{onSelect:s=>{s.preventDefault(),n()},children:[u.jsx(eO,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Edit members"})]}),u.jsxs(Pn,{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:[u.jsx(cu,{className:"h-3.5 w-3.5"}),u.jsxs("span",{className:"text-xs font-medium",children:["Delete ",e]})]})]})]})}function Vee(e){return e.status==="running"||e.status==="starting"?"warning":e.status==="waiting_for_user"?"info":e.status==="failed"?"destructive":e.unread?"success":null}function Wee(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 Gee(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 qee(e){switch(e){case"active":return{glyph:"●",tone:"text-success",title:"Claude PTY session active"};case"warming":return{glyph:"◐",tone:"text-warning",title:"Claude PTY session warming"};case"idle":return{glyph:"○",tone:"text-muted-foreground",title:"Claude PTY session idle"};case"cooling":return{glyph:"◌",tone:"text-muted-foreground",title:"Claude PTY session cooling down"};case"cold":default:return null}}function Kee({chat:e,activeChatId:t,nowMs:n,shortcutHint:r=null,showShortcutHint:i=!1,onSelectChat:s,onRenameChat:o,onOpenInFinder:a,onForkChat:c,onArchiveChat:d,onDeleteChat:f,onEditPermissions:m}){const g=(e.status==="running"||e.status==="waiting_for_user")&&e.stateEnteredAt!=null,b=g&&e.stateEnteredAt!=null?`${e1(e.status)} ${JS(n-e.stateEnteredAt)}`:Ao(n-(e.lastMessageAt??e._creationTime)),y=i&&r?r:b,_=i&&!!r,w=ZK(e.chatId),C=t===w,E=Vee(e),k=e.canFork?"w-12":g?"w-12 md:w-20":"w-6 md:w-14",T=u.jsxs("div",{"data-chat-id":w,className:de("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:[u.jsx("span",{className:"relative flex h-3.5 w-3.5 shrink-0 items-center justify-center","aria-hidden":!0,children:E?u.jsx("span",{className:de("h-2 w-2 rounded-full",Wee(E))}):null}),(()=>{const R=qee(e.sessionState);return R?u.jsx("span",{className:de("shrink-0 text-[10px] leading-none",R.tone),title:R.title,"aria-label":R.title,children:R.glyph}):null})(),e.hasPolicyOverride?u.jsx(Q5,{className:"size-3 shrink-0 text-warning","aria-label":"Per-chat permission override active"}):null,u.jsx("span",{className:de("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}),u.jsxs("div",{className:de("relative h-6 shrink-0",k),children:[y?_?u.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:u.jsx(M3,{className:"h-4 min-w-4 rounded-sm border-border/50 bg-transparent px-1 text-[10px]",children:r})}):u.jsx("span",{className:de("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?Gee(E):"text-muted-foreground"),children:y}):null,u.jsxs("div",{className:de("absolute inset-0 flex items-center justify-end gap-0 transition-opacity duration-150",y?"opacity-100 md:opacity-0 md:group-hover:opacity-100":"opacity-100"),children:[e.canFork?u.jsx(De,{variant:"ghost",size:"icon",className:"h-6 w-6 cursor-pointer rounded-sm hover:!bg-transparent !border-0",onClick:R=>{R.stopPropagation(),c(e.chatId)},title:"Fork chat",children:u.jsx(Z5,{className:"size-3.5"})}):null,u.jsx(De,{variant:"ghost",size:"icon",className:"h-6 w-6 cursor-pointer rounded-sm hover:!bg-transparent !border-0",onClick:R=>{R.stopPropagation(),d(e.chatId)},title:"Archive chat",children:u.jsx(fk,{className:"size-3.5"})})]})]})]},e._id);return u.jsx($ee,{canFork:e.canFork,onRename:()=>o(e.chatId),onOpenInFinder:()=>a(e.localPath),onFork:()=>c(e.chatId),onArchive:()=>d(e.chatId),onDelete:()=>f(e.chatId),onEditPermissions:m?()=>m(e.chatId):void 0,children:T})}const Yee=v.memo(Kee);function Xee(){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 Wx=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function hh(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function oE(e){return"nodeType"in e}function zi(e){var t,n;return e?hh(e)?e:oE(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function aE(e){const{Document:t}=zi(e);return e instanceof t}function fp(e){return hh(e)?!1:e instanceof zi(e).HTMLElement}function F4(e){return e instanceof zi(e).SVGElement}function fh(e){return e?hh(e)?e.document:oE(e)?aE(e)?e:fp(e)||F4(e)?e.ownerDocument:document:document:document}const Uo=Wx?v.useLayoutEffect:v.useEffect;function lE(e){const t=v.useRef(e);return Uo(()=>{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 Qee(){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 ym(e,t){t===void 0&&(t=[e]);const n=v.useRef(e);return Uo(()=>{n.current!==e&&(n.current=e)},t),n}function mp(e,t){const n=v.useRef();return v.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function Ob(e){const t=lE(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 r1(e){const t=v.useRef();return v.useEffect(()=>{t.current=e},[e]),t.current}let X_={};function pp(e,t){return v.useMemo(()=>{if(t)return t;const n=X_[e]==null?0:X_[e]+1;return X_[e]=n,e+"-"+n},[e,t])}function $4(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 a=Object.entries(o);for(const[c,d]of a){const f=s[c];f!=null&&(s[c]=f+e*d)}return s},{...t})}}const Nd=$4(1),zb=$4(-1);function Zee(e){return"clientX"in e&&"clientY"in e}function cE(e){if(!e)return!1;const{KeyboardEvent:t}=zi(e.target);return t&&e instanceof t}function Jee(e){if(!e)return!1;const{TouchEvent:t}=zi(e.target);return t&&e instanceof t}function i1(e){if(Jee(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 Zee(e)?{x:e.clientX,y:e.clientY}:null}const _m=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[_m.Translate.toString(e),_m.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),Qj="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function ete(e){return e.matches(Qj)?e:e.querySelector(Qj)}const tte={display:"none"};function nte(e){let{id:t,value:n}=e;return yn.createElement("div",{id:t,style:tte},n)}function rte(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 yn.createElement("div",{id:t,style:i,role:"status","aria-live":r,"aria-atomic":!0},n)}function ite(){const[e,t]=v.useState("");return{announce:v.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const H4=v.createContext(null);function ste(e){const t=v.useContext(H4);v.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function ote(){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 a;return(a=o[i])==null?void 0:a.call(o,s)})},[e]),t]}const ate={draggable:`
736
+ `)&&(A.writePathDeny=R),Object.keys(A).length===0?null:A}function E(){i(C())}function k(){i(null)}return u.jsxs(u.Fragment,{children:[u.jsx(so,{open:e,onOpenChange:T=>{T||s()},children:u.jsxs(As,{className:"max-w-2xl",children:[u.jsxs(oo,{children:["Permissions — ",t]}),u.jsxs(Ho,{className:"space-y-5",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx("div",{className:"text-sm font-medium",children:"Default action"}),u.jsxs("div",{className:"text-xs text-muted-foreground",children:["Behaviour when a tool call has no explicit allow/deny rule. ",u.jsx("strong",{children:"auto-allow"})," bypasses prompts and runs untrusted shell commands without supervision — use a worktree."]}),u.jsx(Ii,{value:o,onValueChange:w,options:[{value:"ask",label:"Ask"},{value:"auto-allow",label:"Auto-allow (unsafe)"},{value:"auto-deny",label:"Auto-deny"}]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("div",{className:"text-sm font-medium",children:"Read-path deny list"}),u.jsx("div",{className:"text-xs text-muted-foreground",children:"One glob per line. The model cannot read paths matching any entry. Defaults shown below — edit to add or remove."}),u.jsx("textarea",{value:c,onChange:T=>d(T.target.value),rows:8,className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-xs",spellCheck:!1})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx("div",{className:"text-sm font-medium",children:"Write-path deny list"}),u.jsx("div",{className:"text-xs text-muted-foreground",children:"One glob per line. The model cannot edit or write paths matching any entry."}),u.jsx("textarea",{value:f,onChange:T=>m(T.target.value),rows:8,className:"w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-xs",spellCheck:!1})]})]}),u.jsxs(Kl,{className:"justify-between",children:[u.jsx(De,{variant:"ghost",onClick:k,children:"Reset to defaults"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(De,{variant:"ghost",onClick:s,children:"Cancel"}),u.jsx(De,{onClick:E,children:"Apply"})]})]})]})}),u.jsx(so,{open:g,onOpenChange:T=>{T||(b(!1),_(null))},children:u.jsxs(As,{className:"max-w-md",children:[u.jsx(oo,{children:"Enable auto-allow for this chat?"}),u.jsxs(Ho,{className:"space-y-3 text-sm",children:[u.jsx("p",{children:"Auto-allow disables tool-call prompts. The model can run shell commands, write files, and edit code without asking. Read/write deny lists still apply."}),u.jsx("p",{className:"text-warning",children:"Use a worktree for risky tasks."})]}),u.jsxs(Kl,{className:"justify-end gap-2",children:[u.jsx(De,{variant:"ghost",onClick:()=>{b(!1),_(null)},children:"Cancel"}),u.jsx(De,{variant:"destructive",onClick:()=>{y&&a(y),b(!1),_(null)},children:"Enable auto-allow"})]})]})})]})}const vZ={defaultAction:"ask",bash:{autoAllowVerbs:["ls","pwd","git status","git diff","git log"]},readPathDeny:["~/.ssh","~/.aws","~/.gcp","~/.config/gh","~/.claude","~/.kanna","~/Library/Keychains","/etc/shadow","/etc/sudoers","~/.gnupg","~/.gitconfig","**/.git/config","~/.npmrc","~/.netrc","~/.docker/config.json","**/.env","**/.env.*","**/credentials*","**/*.pem","**/*.key","**/id_rsa*","**/id_ed25519*"],writePathDeny:["/etc/**","/usr/**","/System/**","~/.ssh/**","~/.aws/**","~/.config/gh/**","~/.claude/**","~/.kanna/**","~/.gnupg/**","~/.gitconfig","**/.git/config"],toolDenyList:[{tool:"mcp__kanna__bash",pattern:"rm\\s+-rf\\s+(/|~|\\$HOME)(?:\\b|$|\\s)"},{tool:"mcp__kanna__bash",pattern:"git\\s+push\\b.*--force"}],toolAllowList:[]},mn=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{ref:r,type:t,className:de("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}));mn.displayName="Input";const I3=v.createContext(null);function bZ({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,y;(b=s.current)==null||b.focus(),(y=s.current)==null||y.select()},0))},[t]);const o=v.useCallback(()=>{n(null),i("")},[]),a=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]),d=v.useCallback(b=>new Promise(y=>{n({kind:"confirm",options:b,resolve:y})}),[]),f=v.useCallback(b=>new Promise(y=>{n({kind:"prompt",options:b,resolve:y})}),[]),m=v.useCallback(b=>new Promise(y=>{n({kind:"alert",options:b,resolve:y})}),[]),g=v.useMemo(()=>({confirm:d,prompt:f,alert:m}),[m,d,f]);return u.jsxs(I3.Provider,{value:g,children:[e,u.jsx(so,{open:t!==null,onOpenChange:b=>{b||!t||a()},children:u.jsx(As,{size:"sm",onKeyDown:b=>{b.key!=="Enter"||b.shiftKey||!t||t.kind!=="confirm"||(b.preventDefault(),c())},children:t?u.jsxs(u.Fragment,{children:[u.jsxs(Ho,{className:"space-y-4",children:[u.jsx(oo,{children:t.options.title}),t.options.description?u.jsx(np,{children:t.options.description}):null,t.kind==="prompt"?u.jsx(mn,{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]}),u.jsxs(Kl,{children:[u.jsx(De,{variant:"ghost",size:"sm",onClick:a,className:t.kind==="alert"?"hidden":void 0,children:"cancelLabel"in t.options?t.options.cancelLabel??"Cancel":"Cancel"}),u.jsx(De,{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 op(){const e=v.useContext(I3);if(!e)throw new Error("useAppDialog must be used within AppDialogProvider");return e}const Uk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("bg-card text-card-foreground",e),...t}));Uk.displayName="Card";const Vk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("flex flex-col space-y-1.5 p-2",e),...t}));Vk.displayName="CardHeader";const D3=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:de("text-2xl font-semibold leading-none tracking-tight",e),...t}));D3.displayName="CardTitle";const P3=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:de("text-sm text-muted-foreground",e),...t}));P3.displayName="CardDescription";const Wk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("p-6 pt-0",e),...t}));Wk.displayName="CardContent";const xZ=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("flex items-center p-6 pt-0",e),...t}));xZ.displayName="CardFooter";const yZ={info:{dotVar:"var(--info)",bgClass:"bg-info/[0.06]"},warning:{dotVar:"var(--warning)",bgClass:"bg-warning/[0.06]"},success:{dotVar:"var(--success)",bgClass:"bg-success/[0.06]"},error:{dotVar:"var(--destructive)",bgClass:"bg-destructive/[0.06]"}};function _Z({variant:e,children:t,dot:n=!0,className:r}){const i=yZ[e];return u.jsxs("div",{role:"status",className:de("flex flex-wrap items-center justify-center gap-x-2 gap-y-1 border-b border-border px-4 py-2 text-xs leading-tight",i.bgClass,r),children:[n?u.jsx("span",{"aria-hidden":"true",className:"inline-block size-1.5 shrink-0 rounded-full",style:{backgroundColor:i.dotVar}}):null,t]})}const wZ="modulepreload",SZ=function(e){return"/"+e},Uj={},Y=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(d){return Promise.all(d.map(f=>Promise.resolve(f).then(m=>({status:"fulfilled",value:m}),m=>({status:"rejected",reason:m}))))};document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),c=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));i=o(n.map(d=>{if(d=SZ(d),d in Uj)return;Uj[d]=!0;const f=d.endsWith(".css"),m=f?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${m}`))return;const g=document.createElement("link");if(g.rel=f?"stylesheet":wZ,f||(g.as="script"),g.crossOrigin="",g.href=d,c&&g.setAttribute("nonce",c),document.head.appendChild(g),f)return new Promise((b,y)=>{g.addEventListener("load",b),g.addEventListener("error",()=>y(new Error(`Unable to preload CSS for ${d}`)))})}))}function s(o){const a=new Event("vite:preloadError",{cancelable:!0});if(a.payload=o,window.dispatchEvent(a),!a.defaultPrevented)throw o}return i.then(o=>{for(const a of o||[])a.status==="rejected"&&s(a.reason);return t().catch(s)})},CZ=v.lazy(()=>Y(()=>import("./index-DPk3P79C.js"),[]).then(e=>({default:e.Toaster})));function kZ(){return u.jsx(v.Suspense,{fallback:null,children:u.jsx(CZ,{position:"bottom-right",theme:"system",closeButton:!0,duration:6e3})})}const EZ="0.85.2",NZ={version:EZ},Zn="Kanna",Vj="kanna",TZ=".kanna",RZ=".kanna-dev",AZ="KANNA_RUNTIME_PROFILE",Gk=`kanna/${NZ.version}`,jZ="[kanna]",MZ=`~/${Zn}`;function $x(){var t;return(t=globalThis.process)==null?void 0:t.env}function LZ(e=$x()){var t;return((t=e==null?void 0:e[AZ])==null?void 0:t.trim().toLowerCase())==="dev"?"dev":"prod"}function IZ(e=$x()){return LZ(e)==="dev"?RZ:TZ}function DZ(e=$x()){return`~/${IZ(e)}`}function PZ(e=$x()){return`${DZ(e)}/keybindings.json`}function qg(e){return e?`${Vj} ${e}`:Vj}const Wj=e=>{let t;const n=new Set,r=(d,f)=>{const m=typeof d=="function"?d(t):d;if(!Object.is(m,t)){const g=t;t=f??(typeof m!="object"||m===null)?m:Object.assign({},t,m),n.forEach(b=>b(t,g))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>c,subscribe:d=>(n.add(d),()=>n.delete(d))},c=t=e(r,i,a);return a},OZ=(e=>e?Wj(e):Wj),zZ=e=>e;function BZ(e,t=zZ){const n=yn.useSyncExternalStore(e.subscribe,yn.useCallback(()=>t(e.getState()),[e,t]),yn.useCallback(()=>t(e.getInitialState()),[e,t]));return yn.useDebugValue(n),n}const Gj=e=>{const t=OZ(e),n=r=>BZ(t,r);return Object.assign(n,t),n},ss=(e=>e?Gj(e):Gj),O3="always",z3="funk",FZ=[{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 $Z(e){switch(e){case"never":case"unfocused":case"always":return e;default:return O3}}function HZ(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 z3}}const Oc=ss()(e=>({chatSoundPreference:O3,chatSoundId:z3,setChatSoundPreference:t=>e({chatSoundPreference:$Z(t)}),setChatSoundId:t=>e({chatSoundId:HZ(t)})})),UZ={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 VZ(e=document){return e.visibilityState!=="visible"||!e.hasFocus()}function WZ(e){const t=new Audio(UZ[e]);return t.preload="auto",t.play()}async function QS(e,t){if(t<=0)return;const n=Array.from({length:t},(r,i)=>new Promise(s=>{window.setTimeout(()=>{WZ(e).catch(()=>{}).finally(()=>s())},i*90)}));await Promise.all(n)}function GZ(e,t=document){return e==="never"?!1:e==="always"?!0:VZ(t)}function qZ(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 qj(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 KZ(e,t){if(!e)return 0;const n=qj(e),r=qj(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 ZS(e){return e.split(/[\s_-]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}const YZ=[/^(?:\/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 B3(e){const t=e.trim();for(const n of YZ){const r=t.match(n);if(!r)continue;const i=(r[2]??r[1]??"").trim();if(i)return i}return t}function qk(e){return e.split("/").pop()||e}const XZ=1440*6e4;function QZ(e,t){if(e===void 0)return null;const n=Math.max(0,t-e),r=6e4,i=60*r,s=XZ,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 ZZ(e){return e.lastMessageAt??e._creationTime}const Kk=1e3,Jv=60*Kk,yd=60*Jv,K_=24*yd;function Ao(e){const t=Math.max(0,e);if(t<Jv)return`${Math.floor(t/Kk)}s`;if(t<yd)return`${Math.floor(t/Jv)}m`;if(t<K_){const i=Math.floor(t/yd),s=Math.floor(t%yd/Jv);return s===0?`${i}h`:`${i}h ${s}m`}const n=Math.floor(t/K_),r=Math.floor(t%K_/yd);return r===0?`${n}d`:`${n}d ${r}h`}function JS(e){const t=Math.max(0,e);if(t>=yd)return Ao(t);const n=Math.floor(t/Kk),r=Math.floor(n/60),i=n%60;return`${r}:${i.toString().padStart(2,"0")}`}function e1(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 Kj(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 Yj(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 Yk(e){const t=e+"CollectionProvider",[n,r]=Ha(t),[i,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=_=>{const{scope:w,children:C}=_,E=yn.useRef(null),k=yn.useRef(new Map).current;return u.jsx(i,{scope:w,itemMap:k,collectionRef:E,children:C})};o.displayName=t;const a=e+"CollectionSlot",c=Gc(a),d=yn.forwardRef((_,w)=>{const{scope:C,children:E}=_,k=s(a,C),T=bn(w,k.collectionRef);return u.jsx(c,{ref:T,children:E})});d.displayName=a;const f=e+"CollectionItemSlot",m="data-radix-collection-item",g=Gc(f),b=yn.forwardRef((_,w)=>{const{scope:C,children:E,...k}=_,T=yn.useRef(null),R=bn(w,T),A=s(f,C);return yn.useEffect(()=>(A.itemMap.set(T,{ref:T,...k}),()=>void A.itemMap.delete(T))),u.jsx(g,{[m]:"",ref:R,children:E})});b.displayName=f;function y(_){const w=s(e+"CollectionConsumer",_);return yn.useCallback(()=>{const E=w.collectionRef.current;if(!E)return[];const k=Array.from(E.querySelectorAll(`[${m}]`));return Array.from(w.itemMap.values()).sort((A,j)=>k.indexOf(A.ref.current)-k.indexOf(j.ref.current))},[w.collectionRef,w.itemMap])}return[{Provider:o,Slot:d,ItemSlot:b},y,r]}var JZ=v.createContext(void 0);function Xk(e){const t=v.useContext(JZ);return e||t||"ltr"}var Y_="rovingFocusGroup.onEntryFocus",eJ={bubbles:!1,cancelable:!0},ap="RovingFocusGroup",[t1,F3,tJ]=Yk(ap),[nJ,$3]=Ha(ap,[tJ]),[rJ,iJ]=nJ(ap),H3=v.forwardRef((e,t)=>u.jsx(t1.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(t1.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(sJ,{...e,ref:t})})}));H3.displayName=ap;var sJ=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:d,preventScrollOnEntryFocus:f=!1,...m}=e,g=v.useRef(null),b=bn(t,g),y=Xk(s),[_,w]=zd({prop:o,defaultProp:a??null,onChange:c,caller:ap}),[C,E]=v.useState(!1),k=io(d),T=F3(n),R=v.useRef(!1),[A,j]=v.useState(0);return v.useEffect(()=>{const I=g.current;if(I)return I.addEventListener(Y_,k),()=>I.removeEventListener(Y_,k)},[k]),u.jsx(rJ,{scope:n,orientation:r,dir:y,loop:i,currentTabStopId:_,onItemFocus:v.useCallback(I=>w(I),[w]),onItemShiftTab:v.useCallback(()=>E(!0),[]),onFocusableItemAdd:v.useCallback(()=>j(I=>I+1),[]),onFocusableItemRemove:v.useCallback(()=>j(I=>I-1),[]),children:u.jsx(nn.div,{tabIndex:C||A===0?-1:0,"data-orientation":r,...m,ref:b,style:{outline:"none",...e.style},onMouseDown:st(e.onMouseDown,()=>{R.current=!0}),onFocus:st(e.onFocus,I=>{const U=!R.current;if(I.target===I.currentTarget&&U&&!C){const M=new CustomEvent(Y_,eJ);if(I.currentTarget.dispatchEvent(M),!M.defaultPrevented){const D=T().filter(B=>B.focusable),z=D.find(B=>B.active),P=D.find(B=>B.id===_),$=[z,P,...D].filter(Boolean).map(B=>B.ref.current);W3($,f)}}R.current=!1}),onBlur:st(e.onBlur,()=>E(!1))})})}),U3="RovingFocusGroupItem",V3=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...a}=e,c=Aa(),d=s||c,f=iJ(U3,n),m=f.currentTabStopId===d,g=F3(n),{onFocusableItemAdd:b,onFocusableItemRemove:y,currentTabStopId:_}=f;return v.useEffect(()=>{if(r)return b(),()=>y()},[r,b,y]),u.jsx(t1.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:u.jsx(nn.span,{tabIndex:m?0:-1,"data-orientation":f.orientation,...a,ref:t,onMouseDown:st(e.onMouseDown,w=>{r?f.onItemFocus(d):w.preventDefault()}),onFocus:st(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:st(e.onKeyDown,w=>{if(w.key==="Tab"&&w.shiftKey){f.onItemShiftTab();return}if(w.target!==w.currentTarget)return;const C=lJ(w,f.orientation,f.dir);if(C!==void 0){if(w.metaKey||w.ctrlKey||w.altKey||w.shiftKey)return;w.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(w.currentTarget);k=f.loop?cJ(k,T+1):k.slice(T+1)}setTimeout(()=>W3(k))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:_!=null}):o})})});V3.displayName=U3;var oJ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function aJ(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function lJ(e,t,n){const r=aJ(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return oJ[r]}function W3(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function cJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var uJ=H3,dJ=V3,n1=["Enter"," "],hJ=["ArrowDown","PageUp","Home"],G3=["ArrowUp","PageDown","End"],fJ=[...hJ,...G3],mJ={ltr:[...n1,"ArrowRight"],rtl:[...n1,"ArrowLeft"]},pJ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},lp="Menu",[bm,gJ,vJ]=Yk(lp),[du,q3]=Ha(lp,[vJ,Jl,$3]),Hx=Jl(),K3=$3(),[bJ,hu]=du(lp),[xJ,cp]=du(lp),Y3=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,a=Hx(t),[c,d]=v.useState(null),f=v.useRef(!1),m=io(s),g=Xk(i);return v.useEffect(()=>{const b=()=>{f.current=!0,document.addEventListener("pointerdown",y,{capture:!0,once:!0}),document.addEventListener("pointermove",y,{capture:!0,once:!0})},y=()=>f.current=!1;return document.addEventListener("keydown",b,{capture:!0}),()=>{document.removeEventListener("keydown",b,{capture:!0}),document.removeEventListener("pointerdown",y,{capture:!0}),document.removeEventListener("pointermove",y,{capture:!0})}},[]),u.jsx(Px,{...a,children:u.jsx(bJ,{scope:t,open:n,onOpenChange:m,content:c,onContentChange:d,children:u.jsx(xJ,{scope:t,onClose:v.useCallback(()=>m(!1),[m]),isUsingKeyboardRef:f,dir:g,modal:o,children:r})})})};Y3.displayName=lp;var yJ="MenuAnchor",Qk=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Hx(n);return u.jsx(ip,{...i,...r,ref:t})});Qk.displayName=yJ;var Zk="MenuPortal",[_J,X3]=du(Zk,{forceMount:void 0}),Q3=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=hu(Zk,t);return u.jsx(_J,{scope:t,forceMount:n,children:u.jsx(Ds,{present:n||s.open,children:u.jsx(lh,{asChild:!0,container:i,children:r})})})};Q3.displayName=Zk;var Ts="MenuContent",[wJ,Jk]=du(Ts),Z3=v.forwardRef((e,t)=>{const n=X3(Ts,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=hu(Ts,e.__scopeMenu),o=cp(Ts,e.__scopeMenu);return u.jsx(bm.Provider,{scope:e.__scopeMenu,children:u.jsx(Ds,{present:r||s.open,children:u.jsx(bm.Slot,{scope:e.__scopeMenu,children:o.modal?u.jsx(SJ,{...i,ref:t}):u.jsx(CJ,{...i,ref:t})})})})}),SJ=v.forwardRef((e,t)=>{const n=hu(Ts,e.__scopeMenu),r=v.useRef(null),i=bn(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Ax(s)},[]),u.jsx(eE,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:st(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),CJ=v.forwardRef((e,t)=>{const n=hu(Ts,e.__scopeMenu);return u.jsx(eE,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),kJ=Gc("MenuContent.ScrollLock"),eE=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:a,onEntryFocus:c,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:g,onDismiss:b,disableOutsideScroll:y,..._}=e,w=hu(Ts,n),C=cp(Ts,n),E=Hx(n),k=K3(n),T=gJ(n),[R,A]=v.useState(null),j=v.useRef(null),I=bn(t,j,w.onContentChange),U=v.useRef(0),M=v.useRef(""),D=v.useRef(0),z=v.useRef(null),P=v.useRef("right"),F=v.useRef(0),$=y?tp:v.Fragment,B=y?{as:kJ,allowPinchZoom:!0}:void 0,H=te=>{var ne,ie;const O=M.current+te,K=T().filter(le=>!le.disabled),ee=document.activeElement,V=(ne=K.find(le=>le.ref.current===ee))==null?void 0:ne.textValue,ue=K.map(le=>le.textValue),ge=OJ(ue,O,V),Z=(ie=K.find(le=>le.textValue===ge))==null?void 0:ie.ref.current;(function le(oe){M.current=oe,window.clearTimeout(U.current),oe!==""&&(U.current=window.setTimeout(()=>le(""),1e3))})(O),Z&&setTimeout(()=>Z.focus())};v.useEffect(()=>()=>window.clearTimeout(U.current),[]),Tx();const W=v.useCallback(te=>{var K,ee;return P.current===((K=z.current)==null?void 0:K.side)&&BJ(te,(ee=z.current)==null?void 0:ee.area)},[]);return u.jsx(wJ,{scope:n,searchRef:M,onItemEnter:v.useCallback(te=>{W(te)&&te.preventDefault()},[W]),onItemLeave:v.useCallback(te=>{var O;W(te)||((O=j.current)==null||O.focus(),A(null))},[W]),onTriggerLeave:v.useCallback(te=>{W(te)&&te.preventDefault()},[W]),pointerGraceTimerRef:D,onPointerGraceIntentChange:v.useCallback(te=>{z.current=te},[]),children:u.jsx($,{...B,children:u.jsx(ep,{asChild:!0,trapped:i,onMountAutoFocus:st(s,te=>{var O;te.preventDefault(),(O=j.current)==null||O.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:u.jsx(ah,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:g,onDismiss:b,children:u.jsx(uJ,{asChild:!0,...k,dir:C.dir,orientation:"vertical",loop:r,currentTabStopId:R,onCurrentTabStopIdChange:A,onEntryFocus:st(c,te=>{C.isUsingKeyboardRef.current||te.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(Ox,{role:"menu","aria-orientation":"vertical","data-state":m4(w.open),"data-radix-menu-content":"",dir:C.dir,...E,..._,ref:I,style:{outline:"none",..._.style},onKeyDown:st(_.onKeyDown,te=>{const K=te.target.closest("[data-radix-menu-content]")===te.currentTarget,ee=te.ctrlKey||te.altKey||te.metaKey,V=te.key.length===1;K&&(te.key==="Tab"&&te.preventDefault(),!ee&&V&&H(te.key));const ue=j.current;if(te.target!==ue||!fJ.includes(te.key))return;te.preventDefault();const Z=T().filter(ne=>!ne.disabled).map(ne=>ne.ref.current);G3.includes(te.key)&&Z.reverse(),DJ(Z)}),onBlur:st(e.onBlur,te=>{te.currentTarget.contains(te.target)||(window.clearTimeout(U.current),M.current="")}),onPointerMove:st(e.onPointerMove,xm(te=>{const O=te.target,K=F.current!==te.clientX;if(te.currentTarget.contains(O)&&K){const ee=te.clientX>F.current?"right":"left";P.current=ee,F.current=te.clientX}}))})})})})})})});Z3.displayName=Ts;var EJ="MenuGroup",tE=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(nn.div,{role:"group",...r,ref:t})});tE.displayName=EJ;var NJ="MenuLabel",J3=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(nn.div,{...r,ref:t})});J3.displayName=NJ;var Db="MenuItem",Xj="menu.itemSelect",Ux=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=v.useRef(null),o=cp(Db,e.__scopeMenu),a=Jk(Db,e.__scopeMenu),c=bn(t,s),d=v.useRef(!1),f=()=>{const m=s.current;if(!n&&m){const g=new CustomEvent(Xj,{bubbles:!0,cancelable:!0});m.addEventListener(Xj,b=>r==null?void 0:r(b),{once:!0}),bO(m,g),g.defaultPrevented?d.current=!1:o.onClose()}};return u.jsx(e4,{...i,ref:c,disabled:n,onClick:st(e.onClick,f),onPointerDown:m=>{var g;(g=e.onPointerDown)==null||g.call(e,m),d.current=!0},onPointerUp:st(e.onPointerUp,m=>{var g;d.current||(g=m.currentTarget)==null||g.click()}),onKeyDown:st(e.onKeyDown,m=>{const g=a.searchRef.current!=="";n||g&&m.key===" "||n1.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})});Ux.displayName=Db;var e4=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=Jk(Db,n),a=K3(n),c=v.useRef(null),d=bn(t,c),[f,m]=v.useState(!1),[g,b]=v.useState("");return v.useEffect(()=>{const y=c.current;y&&b((y.textContent??"").trim())},[s.children]),u.jsx(bm.ItemSlot,{scope:n,disabled:r,textValue:i??g,children:u.jsx(dJ,{asChild:!0,...a,focusable:!r,children:u.jsx(nn.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:st(e.onPointerMove,xm(y=>{r?o.onItemLeave(y):(o.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:st(e.onPointerLeave,xm(y=>o.onItemLeave(y))),onFocus:st(e.onFocus,()=>m(!0)),onBlur:st(e.onBlur,()=>m(!1))})})})}),TJ="MenuCheckboxItem",t4=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return u.jsx(o4,{scope:e.__scopeMenu,checked:n,children:u.jsx(Ux,{role:"menuitemcheckbox","aria-checked":Pb(n)?"mixed":n,...i,ref:t,"data-state":rE(n),onSelect:st(i.onSelect,()=>r==null?void 0:r(Pb(n)?!0:!n),{checkForDefaultPrevented:!1})})})});t4.displayName=TJ;var n4="MenuRadioGroup",[RJ,AJ]=du(n4,{value:void 0,onValueChange:()=>{}}),r4=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=io(r);return u.jsx(RJ,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(tE,{...i,ref:t})})});r4.displayName=n4;var i4="MenuRadioItem",s4=v.forwardRef((e,t)=>{const{value:n,...r}=e,i=AJ(i4,e.__scopeMenu),s=n===i.value;return u.jsx(o4,{scope:e.__scopeMenu,checked:s,children:u.jsx(Ux,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":rE(s),onSelect:st(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});s4.displayName=i4;var nE="MenuItemIndicator",[o4,jJ]=du(nE,{checked:!1}),a4=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=jJ(nE,n);return u.jsx(Ds,{present:r||Pb(s.checked)||s.checked===!0,children:u.jsx(nn.span,{...i,ref:t,"data-state":rE(s.checked)})})});a4.displayName=nE;var MJ="MenuSeparator",l4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(nn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});l4.displayName=MJ;var LJ="MenuArrow",c4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Hx(n);return u.jsx(zx,{...i,...r,ref:t})});c4.displayName=LJ;var IJ="MenuSub",[RRe,u4]=du(IJ),Pf="MenuSubTrigger",d4=v.forwardRef((e,t)=>{const n=hu(Pf,e.__scopeMenu),r=cp(Pf,e.__scopeMenu),i=u4(Pf,e.__scopeMenu),s=Jk(Pf,e.__scopeMenu),o=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:c}=s,d={__scopeMenu:e.__scopeMenu},f=v.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return v.useEffect(()=>f,[f]),v.useEffect(()=>{const m=a.current;return()=>{window.clearTimeout(m),c(null)}},[a,c]),u.jsx(Qk,{asChild:!0,...d,children:u.jsx(e4,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":m4(n.open),...e,ref:Ck(t,i.onTriggerChange),onClick:m=>{var g;(g=e.onClick)==null||g.call(e,m),!(e.disabled||m.defaultPrevented)&&(m.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:st(e.onPointerMove,xm(m=>{s.onItemEnter(m),!m.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),f()},100))})),onPointerLeave:st(e.onPointerLeave,xm(m=>{var b,y;f();const g=(b=n.content)==null?void 0:b.getBoundingClientRect();if(g){const _=(y=n.content)==null?void 0:y.dataset.side,w=_==="right",C=w?-5:5,E=g[w?"left":"right"],k=g[w?"right":"left"];s.onPointerGraceIntentChange({area:[{x:m.clientX+C,y:m.clientY},{x:E,y:g.top},{x:k,y:g.top},{x:k,y:g.bottom},{x:E,y:g.bottom}],side:_}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(m),m.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:st(e.onKeyDown,m=>{var b;const g=s.searchRef.current!=="";e.disabled||g&&m.key===" "||mJ[r.dir].includes(m.key)&&(n.onOpenChange(!0),(b=n.content)==null||b.focus(),m.preventDefault())})})})});d4.displayName=Pf;var h4="MenuSubContent",f4=v.forwardRef((e,t)=>{const n=X3(Ts,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=hu(Ts,e.__scopeMenu),o=cp(Ts,e.__scopeMenu),a=u4(h4,e.__scopeMenu),c=v.useRef(null),d=bn(t,c);return u.jsx(bm.Provider,{scope:e.__scopeMenu,children:u.jsx(Ds,{present:r||s.open,children:u.jsx(bm.Slot,{scope:e.__scopeMenu,children:u.jsx(eE,{id:a.contentId,"aria-labelledby":a.triggerId,...i,ref:d,align:"start",side:o.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:f=>{var m;o.isUsingKeyboardRef.current&&((m=c.current)==null||m.focus()),f.preventDefault()},onCloseAutoFocus:f=>f.preventDefault(),onFocusOutside:st(e.onFocusOutside,f=>{f.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:st(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:st(e.onKeyDown,f=>{var b;const m=f.currentTarget.contains(f.target),g=pJ[o.dir].includes(f.key);m&&g&&(s.onOpenChange(!1),(b=a.trigger)==null||b.focus(),f.preventDefault())})})})})})});f4.displayName=h4;function m4(e){return e?"open":"closed"}function Pb(e){return e==="indeterminate"}function rE(e){return Pb(e)?"indeterminate":e?"checked":"unchecked"}function DJ(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function PJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function OJ(e,t,n){const i=t.length>1&&Array.from(t).every(d=>d===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let o=PJ(e,Math.max(s,0));i.length===1&&(o=o.filter(d=>d!==n));const c=o.find(d=>d.toLowerCase().startsWith(i.toLowerCase()));return c!==n?c:void 0}function zJ(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 a=t[s],c=t[o],d=a.x,f=a.y,m=c.x,g=c.y;f>r!=g>r&&n<(m-d)*(r-f)/(g-f)+d&&(i=!i)}return i}function BJ(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return zJ(n,t)}function xm(e){return t=>t.pointerType==="mouse"?e(t):void 0}var FJ=Y3,$J=Qk,HJ=Q3,UJ=Z3,VJ=tE,WJ=J3,GJ=Ux,qJ=t4,KJ=r4,YJ=s4,XJ=a4,QJ=l4,ZJ=c4,JJ=d4,eee=f4,iE="ContextMenu",[tee]=Ha(iE,[q3]),yi=q3(),[nee,p4]=tee(iE),g4=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:s=!0}=e,[o,a]=v.useState(!1),c=yi(t),d=io(r),f=v.useCallback(m=>{a(m),d(m)},[d]);return u.jsx(nee,{scope:t,open:o,onOpenChange:f,modal:s,children:u.jsx(FJ,{...c,dir:i,open:o,onOpenChange:f,modal:s,children:n})})};g4.displayName=iE;var v4="ContextMenuTrigger",b4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,disabled:r=!1,...i}=e,s=p4(v4,n),o=yi(n),a=v.useRef({x:0,y:0}),c=v.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),d=v.useRef(0),f=v.useCallback(()=>window.clearTimeout(d.current),[]),m=g=>{a.current={x:g.clientX,y:g.clientY},s.onOpenChange(!0)};return v.useEffect(()=>f,[f]),v.useEffect(()=>void(r&&f()),[r,f]),u.jsxs(u.Fragment,{children:[u.jsx($J,{...o,virtualRef:c}),u.jsx(nn.span,{"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,...i,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:st(e.onContextMenu,g=>{f(),m(g),g.preventDefault()}),onPointerDown:r?e.onPointerDown:st(e.onPointerDown,Kg(g=>{f(),d.current=window.setTimeout(()=>m(g),700)})),onPointerMove:r?e.onPointerMove:st(e.onPointerMove,Kg(f)),onPointerCancel:r?e.onPointerCancel:st(e.onPointerCancel,Kg(f)),onPointerUp:r?e.onPointerUp:st(e.onPointerUp,Kg(f))})]})});b4.displayName=v4;var ree="ContextMenuPortal",x4=e=>{const{__scopeContextMenu:t,...n}=e,r=yi(t);return u.jsx(HJ,{...r,...n})};x4.displayName=ree;var y4="ContextMenuContent",_4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=p4(y4,n),s=yi(n),o=v.useRef(!1);return u.jsx(UJ,{...s,...r,ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var c;(c=e.onCloseAutoFocus)==null||c.call(e,a),!a.defaultPrevented&&o.current&&a.preventDefault(),o.current=!1},onInteractOutside:a=>{var c;(c=e.onInteractOutside)==null||c.call(e,a),!a.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)"}})});_4.displayName=y4;var iee="ContextMenuGroup",see=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(VJ,{...i,...r,ref:t})});see.displayName=iee;var oee="ContextMenuLabel",aee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(WJ,{...i,...r,ref:t})});aee.displayName=oee;var lee="ContextMenuItem",w4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(GJ,{...i,...r,ref:t})});w4.displayName=lee;var cee="ContextMenuCheckboxItem",uee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(qJ,{...i,...r,ref:t})});uee.displayName=cee;var dee="ContextMenuRadioGroup",hee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(KJ,{...i,...r,ref:t})});hee.displayName=dee;var fee="ContextMenuRadioItem",mee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(YJ,{...i,...r,ref:t})});mee.displayName=fee;var pee="ContextMenuItemIndicator",gee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(XJ,{...i,...r,ref:t})});gee.displayName=pee;var vee="ContextMenuSeparator",S4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(QJ,{...i,...r,ref:t})});S4.displayName=vee;var bee="ContextMenuArrow",xee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(ZJ,{...i,...r,ref:t})});xee.displayName=bee;var yee="ContextMenuSubTrigger",_ee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(JJ,{...i,...r,ref:t})});_ee.displayName=yee;var wee="ContextMenuSubContent",See=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=yi(n);return u.jsx(eee,{...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)"}})});See.displayName=wee;function Kg(e){return t=>t.pointerType!=="mouse"?e(t):void 0}var Cee=g4,kee=b4,Eee=x4,C4=_4,k4=w4,E4=S4;const N4=v.createContext(null);function fu({onOpenChange:e,...t}){const[n,r]=v.useState(0),i=v.useCallback(()=>{r(s=>s+1),e==null||e(!1)},[e]);return u.jsx(N4.Provider,{value:i,children:u.jsx(Cee,{onOpenChange:e,...t},n)})}const mu=kee,ec=v.forwardRef(({className:e,...t},n)=>u.jsx(Eee,{children:u.jsx(C4,{ref:n,className:de("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})}));ec.displayName=C4.displayName;const Pn=v.forwardRef(({className:e,onSelect:t,...n},r)=>{const i=v.useContext(N4);return u.jsx(k4,{ref:r,className:de("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})});Pn.displayName=k4.displayName;const T4=v.forwardRef(({className:e,...t},n)=>u.jsx(E4,{ref:n,className:de("-mx-1 my-1 h-px bg-border",e),...t}));T4.displayName=E4.displayName;var Vx="Popover",[R4]=Ha(Vx,[Jl]),up=Jl(),[Nee,tc]=R4(Vx),A4=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,a=up(t),c=v.useRef(null),[d,f]=v.useState(!1),[m,g]=zd({prop:r,defaultProp:i??!1,onChange:s,caller:Vx});return u.jsx(Px,{...a,children:u.jsx(Nee,{scope:t,contentId:Aa(),triggerRef:c,open:m,onOpenChange:g,onOpenToggle:v.useCallback(()=>g(b=>!b),[g]),hasCustomAnchor:d,onCustomAnchorAdd:v.useCallback(()=>f(!0),[]),onCustomAnchorRemove:v.useCallback(()=>f(!1),[]),modal:o,children:n})})};A4.displayName=Vx;var j4="PopoverAnchor",Tee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=tc(j4,n),s=up(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:a}=i;return v.useEffect(()=>(o(),()=>a()),[o,a]),u.jsx(ip,{...s,...r,ref:t})});Tee.displayName=j4;var M4="PopoverTrigger",L4=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=tc(M4,n),s=up(n),o=bn(t,i.triggerRef),a=u.jsx(nn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":z4(i.open),...r,ref:o,onClick:st(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?a:u.jsx(ip,{asChild:!0,...s,children:a})});L4.displayName=M4;var sE="PopoverPortal",[Ree,Aee]=R4(sE,{forceMount:void 0}),I4=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=tc(sE,t);return u.jsx(Ree,{scope:t,forceMount:n,children:u.jsx(Ds,{present:n||s.open,children:u.jsx(lh,{asChild:!0,container:i,children:r})})})};I4.displayName=sE;var $d="PopoverContent",D4=v.forwardRef((e,t)=>{const n=Aee($d,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=tc($d,e.__scopePopover);return u.jsx(Ds,{present:r||s.open,children:s.modal?u.jsx(Mee,{...i,ref:t}):u.jsx(Lee,{...i,ref:t})})});D4.displayName=$d;var jee=Gc("PopoverContent.RemoveScroll"),Mee=v.forwardRef((e,t)=>{const n=tc($d,e.__scopePopover),r=v.useRef(null),i=bn(t,r),s=v.useRef(!1);return v.useEffect(()=>{const o=r.current;if(o)return Ax(o)},[]),u.jsx(tp,{as:jee,allowPinchZoom:!0,children:u.jsx(P4,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:st(e.onCloseAutoFocus,o=>{var a;o.preventDefault(),s.current||(a=n.triggerRef.current)==null||a.focus()}),onPointerDownOutside:st(e.onPointerDownOutside,o=>{const a=o.detail.originalEvent,c=a.button===0&&a.ctrlKey===!0,d=a.button===2||c;s.current=d},{checkForDefaultPrevented:!1}),onFocusOutside:st(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Lee=v.forwardRef((e,t)=>{const n=tc($d,e.__scopePopover),r=v.useRef(!1),i=v.useRef(!1);return u.jsx(P4,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o,a;(o=e.onCloseAutoFocus)==null||o.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{var c,d;(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;((d=n.triggerRef.current)==null?void 0:d.contains(o))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),P4=v.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:d,onInteractOutside:f,...m}=e,g=tc($d,n),b=up(n);return Tx(),u.jsx(ep,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:u.jsx(ah,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:f,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:d,onDismiss:()=>g.onOpenChange(!1),children:u.jsx(Ox,{"data-state":z4(g.open),role:"dialog",id:g.contentId,...b,...m,ref:t,style:{...m.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)"}})})})}),O4="PopoverClose",Iee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=tc(O4,n);return u.jsx(nn.button,{type:"button",...r,ref:t,onClick:st(e.onClick,()=>i.onOpenChange(!1))})});Iee.displayName=O4;var Dee="PopoverArrow",Pee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=up(n);return u.jsx(zx,{...i,...r,ref:t})});Pee.displayName=Dee;function z4(e){return e?"open":"closed"}var Oee=A4,zee=L4,Bee=I4,B4=D4;const dp=Oee,hp=zee,dh=v.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},i)=>u.jsx(Bee,{children:u.jsx(B4,{ref:i,align:t,sideOffset:n,[mm]:"",onCloseAutoFocus:s=>{var o;s.preventDefault(),window.dispatchEvent(new Event(Nb)),(o=r.onCloseAutoFocus)==null||o.call(r,s)},className:de("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})}));dh.displayName=B4.displayName;function Fee({editorLabel:e,starred:t,onCopyPath:n,onShowArchived:r,onOpenInFinder:i,onOpenInEditor:s,onToggleStar:o,onHide:a,children:c}){return u.jsxs(fu,{children:[u.jsx(mu,{asChild:!0,children:c}),u.jsxs(ec,{children:[u.jsxs(Pn,{onSelect:d=>{d.stopPropagation(),o()},children:[t?u.jsx(Uq,{className:"h-3.5 w-3.5"}):u.jsx(J5,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:t?"Unstar project":"Star project"})]}),u.jsxs(Pn,{onSelect:d=>{d.stopPropagation(),n()},children:[u.jsx(La,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Copy Path"})]}),u.jsxs(Pn,{onSelect:d=>{d.stopPropagation(),r()},children:[u.jsx(fk,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Show Archived"})]}),u.jsxs(Pn,{onSelect:d=>{d.stopPropagation(),i()},children:[u.jsx(Ex,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Show in Finder"})]}),u.jsxs(Pn,{onSelect:d=>{d.stopPropagation(),s()},children:[u.jsx(mk,{className:"h-3.5 w-3.5"}),u.jsxs("span",{className:"text-xs font-medium",children:["Open in ",e]})]}),u.jsxs(Pn,{onSelect:d=>{d.stopPropagation(),a()},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[u.jsx(DW,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Hide"})]})]})]})}function $ee({canFork:e,onRename:t,onOpenInFinder:n,onFork:r,onArchive:i,onDelete:s,onEditPermissions:o,children:a}){return u.jsxs(fu,{children:[u.jsx(mu,{asChild:!0,children:a}),u.jsxs(ec,{children:[u.jsxs(Pn,{onSelect:c=>{c.preventDefault(),t()},children:[u.jsx(oh,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),u.jsxs(Pn,{onSelect:c=>{c.preventDefault(),n()},children:[u.jsx(Ex,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),u.jsxs(Pn,{disabled:!e,onSelect:c=>{c.preventDefault(),e&&r()},children:[u.jsx(Z5,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Fork"})]}),o?u.jsxs(Pn,{onSelect:c=>{c.preventDefault(),o()},children:[u.jsx(Q5,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Permissions…"})]}):null,u.jsxs(Pn,{onSelect:c=>{c.preventDefault(),i()},children:[u.jsx(fk,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Archive"})]}),u.jsxs(Pn,{onSelect:c=>{c.preventDefault(),s()},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:[u.jsx(cu,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Delete"})]})]})]})}function Hee({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){const[s,o]=v.useState(!1);function a(c){return()=>{o(!1),c()}}return u.jsxs(dp,{open:s,onOpenChange:o,children:[u.jsx(hp,{asChild:!0,children:i}),u.jsxs(dh,{align:"end",sideOffset:4,className:"w-44 p-1",role:"menu","aria-label":`Actions for ${e}`,children:[u.jsxs("button",{type:"button",role:"menuitem",onClick:a(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:[u.jsx(oh,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Rename"})]}),u.jsxs("button",{type:"button",role:"menuitem",onClick:a(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:[u.jsx(eO,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Edit members"})]}),u.jsxs("button",{type:"button",role:"menuitem",onClick:a(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:[u.jsx(cu,{className:"h-3.5 w-3.5"}),u.jsxs("span",{children:["Delete ",e]})]})]})]})}function Uee({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){return u.jsxs(fu,{children:[u.jsx(mu,{asChild:!0,children:i}),u.jsxs(ec,{children:[u.jsxs(Pn,{onSelect:s=>{s.preventDefault(),t()},children:[u.jsx(oh,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),u.jsxs(Pn,{onSelect:s=>{s.preventDefault(),n()},children:[u.jsx(eO,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Edit members"})]}),u.jsxs(Pn,{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:[u.jsx(cu,{className:"h-3.5 w-3.5"}),u.jsxs("span",{className:"text-xs font-medium",children:["Delete ",e]})]})]})]})}function Vee(e){return e.status==="running"||e.status==="starting"?"warning":e.status==="waiting_for_user"?"info":e.status==="failed"?"destructive":e.unread?"success":null}function Wee(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 Gee(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 qee(e){switch(e){case"active":return{glyph:"●",tone:"text-success",title:"Claude PTY session active"};case"warming":return{glyph:"◐",tone:"text-warning",title:"Claude PTY session warming"};case"idle":return{glyph:"○",tone:"text-muted-foreground",title:"Claude PTY session idle"};case"cooling":return{glyph:"◌",tone:"text-muted-foreground",title:"Claude PTY session cooling down"};case"cold":default:return null}}function Kee({chat:e,activeChatId:t,nowMs:n,shortcutHint:r=null,showShortcutHint:i=!1,onSelectChat:s,onRenameChat:o,onOpenInFinder:a,onForkChat:c,onArchiveChat:d,onDeleteChat:f,onEditPermissions:m}){const g=(e.status==="running"||e.status==="waiting_for_user")&&e.stateEnteredAt!=null,b=g&&e.stateEnteredAt!=null?`${e1(e.status)} ${JS(n-e.stateEnteredAt)}`:Ao(n-(e.lastMessageAt??e._creationTime)),y=i&&r?r:b,_=i&&!!r,w=ZK(e.chatId),C=t===w,E=Vee(e),k=e.canFork?"w-12":g?"w-12 md:w-20":"w-6 md:w-14",T=u.jsxs("div",{"data-chat-id":w,className:de("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:[u.jsx("span",{className:"relative flex h-3.5 w-3.5 shrink-0 items-center justify-center","aria-hidden":!0,children:E?u.jsx("span",{className:de("h-2 w-2 rounded-full",Wee(E))}):null}),(()=>{const R=qee(e.sessionState);return R?u.jsx("span",{className:de("shrink-0 text-[10px] leading-none",R.tone),title:R.title,"aria-label":R.title,children:R.glyph}):null})(),e.hasPolicyOverride?u.jsx(Q5,{className:"size-3 shrink-0 text-warning","aria-label":"Per-chat permission override active"}):null,u.jsx("span",{className:de("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}),u.jsxs("div",{className:de("relative h-6 shrink-0",k),children:[y?_?u.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:u.jsx(M3,{className:"h-4 min-w-4 rounded-sm border-border/50 bg-transparent px-1 text-[10px]",children:r})}):u.jsx("span",{className:de("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?Gee(E):"text-muted-foreground"),children:y}):null,u.jsxs("div",{className:de("absolute inset-0 flex items-center justify-end gap-0 transition-opacity duration-150",y?"opacity-100 md:opacity-0 md:group-hover:opacity-100":"opacity-100"),children:[e.canFork?u.jsx(De,{variant:"ghost",size:"icon",className:"h-6 w-6 cursor-pointer rounded-sm hover:!bg-transparent !border-0",onClick:R=>{R.stopPropagation(),c(e.chatId)},title:"Fork chat",children:u.jsx(Z5,{className:"size-3.5"})}):null,u.jsx(De,{variant:"ghost",size:"icon",className:"h-6 w-6 cursor-pointer rounded-sm hover:!bg-transparent !border-0",onClick:R=>{R.stopPropagation(),d(e.chatId)},title:"Archive chat",children:u.jsx(fk,{className:"size-3.5"})})]})]})]},e._id);return u.jsx($ee,{canFork:e.canFork,onRename:()=>o(e.chatId),onOpenInFinder:()=>a(e.localPath),onFork:()=>c(e.chatId),onArchive:()=>d(e.chatId),onDelete:()=>f(e.chatId),onEditPermissions:m?()=>m(e.chatId):void 0,children:T})}const Yee=v.memo(Kee);function Xee(){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 Wx=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function hh(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function oE(e){return"nodeType"in e}function zi(e){var t,n;return e?hh(e)?e:oE(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function aE(e){const{Document:t}=zi(e);return e instanceof t}function fp(e){return hh(e)?!1:e instanceof zi(e).HTMLElement}function F4(e){return e instanceof zi(e).SVGElement}function fh(e){return e?hh(e)?e.document:oE(e)?aE(e)?e:fp(e)||F4(e)?e.ownerDocument:document:document:document}const Uo=Wx?v.useLayoutEffect:v.useEffect;function lE(e){const t=v.useRef(e);return Uo(()=>{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 Qee(){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 ym(e,t){t===void 0&&(t=[e]);const n=v.useRef(e);return Uo(()=>{n.current!==e&&(n.current=e)},t),n}function mp(e,t){const n=v.useRef();return v.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function Ob(e){const t=lE(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 r1(e){const t=v.useRef();return v.useEffect(()=>{t.current=e},[e]),t.current}let X_={};function pp(e,t){return v.useMemo(()=>{if(t)return t;const n=X_[e]==null?0:X_[e]+1;return X_[e]=n,e+"-"+n},[e,t])}function $4(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 a=Object.entries(o);for(const[c,d]of a){const f=s[c];f!=null&&(s[c]=f+e*d)}return s},{...t})}}const Nd=$4(1),zb=$4(-1);function Zee(e){return"clientX"in e&&"clientY"in e}function cE(e){if(!e)return!1;const{KeyboardEvent:t}=zi(e.target);return t&&e instanceof t}function Jee(e){if(!e)return!1;const{TouchEvent:t}=zi(e.target);return t&&e instanceof t}function i1(e){if(Jee(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 Zee(e)?{x:e.clientX,y:e.clientY}:null}const _m=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[_m.Translate.toString(e),_m.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),Qj="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function ete(e){return e.matches(Qj)?e:e.querySelector(Qj)}const tte={display:"none"};function nte(e){let{id:t,value:n}=e;return yn.createElement("div",{id:t,style:tte},n)}function rte(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 yn.createElement("div",{id:t,style:i,role:"status","aria-live":r,"aria-atomic":!0},n)}function ite(){const[e,t]=v.useState("");return{announce:v.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const H4=v.createContext(null);function ste(e){const t=v.useContext(H4);v.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function ote(){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 a;return(a=o[i])==null?void 0:a.call(o,s)})},[e]),t]}const ate={draggable:`
737
737
  To pick up a draggable item, press the space bar.
738
738
  While dragging, use the arrow keys to move the item.
739
739
  Press space again to drop the item in its new position, or press escape to cancel.
@@ -2632,7 +2632,7 @@ XID_Start XIDS`.split(/\s/).map(e=>[oy(e),e])),$le=new Map([["s",wr(383)],[wr(38
2632
2632
  `});++r<e.length;)r&&n.push({type:"text",value:`
2633
2633
  `}),n.push(e[r]);return t&&e.length>0&&n.push({type:"text",value:`
2634
2634
  `}),n}function gI(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function vI(e,t){const n=hve(e,t),r=n.one(e,void 0),i=uve(n),s=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return i&&s.children.push({type:"text",value:`
2635
- `},i),s}function vve(e,t){return e&&"run"in e?async function(n,r){const i=vI(n,{file:r,...t});await e.run(i,r)}:function(n,r){return vI(n,{file:r,...e||t})}}function bI(e){if(e)throw e}var Uw,xI;function bve(){if(xI)return Uw;xI=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=function(d){return typeof Array.isArray=="function"?Array.isArray(d):t.call(d)==="[object Array]"},s=function(d){if(!d||t.call(d)!=="[object Object]")return!1;var f=e.call(d,"constructor"),m=d.constructor&&d.constructor.prototype&&e.call(d.constructor.prototype,"isPrototypeOf");if(d.constructor&&!f&&!m)return!1;var g;for(g in d);return typeof g>"u"||e.call(d,g)},o=function(d,f){n&&f.name==="__proto__"?n(d,f.name,{enumerable:!0,configurable:!0,value:f.newValue,writable:!0}):d[f.name]=f.newValue},a=function(d,f){if(f==="__proto__")if(e.call(d,f)){if(r)return r(d,f).value}else return;return d[f]};return Uw=function c(){var d,f,m,g,b,y,_=arguments[0],w=1,C=arguments.length,E=!1;for(typeof _=="boolean"&&(E=_,_=arguments[1]||{},w=2),(_==null||typeof _!="object"&&typeof _!="function")&&(_={});w<C;++w)if(d=arguments[w],d!=null)for(f in d)m=a(_,f),g=a(d,f),_!==g&&(E&&g&&(s(g)||(b=i(g)))?(b?(b=!1,y=m&&i(m)?m:[]):y=m&&s(m)?m:{},o(_,{name:f,newValue:c(E,y,g)})):typeof g<"u"&&o(_,{name:f,newValue:g}));return _},Uw}var xve=bve();const Vw=_x(xve);function eC(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function yve(){const e=[],t={run:n,use:r};return t;function n(...i){let s=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);a(null,...i);function a(c,...d){const f=e[++s];let m=-1;if(c){o(c);return}for(;++m<i.length;)(d[m]===null||d[m]===void 0)&&(d[m]=i[m]);i=d,f?_ve(f,a)(...d):o(null,...d)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function _ve(e,t){let n;return r;function r(...o){const a=e.length>o.length;let c;a&&o.push(i);try{c=e.apply(this,o)}catch(d){const f=d;if(a&&n)throw f;return i(f)}a||(c&&c.then&&typeof c.then=="function"?c.then(s,i):c instanceof Error?i(c):s(c))}function i(o,...a){n||(n=!0,t(o,...a))}function s(o){i(null,o)}}const To={basename:wve,dirname:Sve,extname:Cve,join:kve,sep:"/"};function wve(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');Sp(e);let n=0,r=-1,i=e.length,s;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else r<0&&(s=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,a=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else o<0&&(s=!0,o=i+1),a>-1&&(e.codePointAt(i)===t.codePointAt(a--)?a<0&&(r=i):(a=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function Sve(e){if(Sp(e),e.length===0)return".";let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||(r=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function Cve(e){Sp(e);let t=e.length,n=-1,r=0,i=-1,s=0,o;for(;t--;){const a=e.codePointAt(t);if(a===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),a===46?i<0?i=t:s!==1&&(s=1):i>-1&&(s=-1)}return i<0||n<0||s===0||s===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function kve(...e){let t=-1,n;for(;++t<e.length;)Sp(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":Eve(n)}function Eve(e){Sp(e);const t=e.codePointAt(0)===47;let n=Nve(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function Nve(e,t){let n="",r=0,i=-1,s=0,o=-1,a,c;for(;++o<=e.length;){if(o<e.length)a=e.codePointAt(o);else{if(a===47)break;a=47}if(a===47){if(!(i===o-1||s===1))if(i!==o-1&&s===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf("/"),c!==n.length-1){c<0?(n="",r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf("/")),i=o,s=0;continue}}else if(n.length>0){n="",r=0,i=o,s=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,s=0}else a===46&&s>-1?s++:s=-1}return n}function Sp(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const Tve={cwd:Rve};function Rve(){return"/"}function tC(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function Ave(e){if(typeof e=="string")e=new URL(e);else if(!tC(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return jve(e)}function jve(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(t)}const Ww=["history","path","basename","stem","extname","dirname"];class eF{constructor(t){let n;t?tC(t)?n={path:t}:typeof t=="string"||Mve(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":Tve.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<Ww.length;){const s=Ww[r];s in n&&n[s]!==void 0&&n[s]!==null&&(this[s]=s==="history"?[...n[s]]:n[s])}let i;for(i in n)Ww.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?To.basename(this.path):void 0}set basename(t){qw(t,"basename"),Gw(t,"basename"),this.path=To.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?To.dirname(this.path):void 0}set dirname(t){yI(this.basename,"dirname"),this.path=To.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?To.extname(this.path):void 0}set extname(t){if(Gw(t,"extname"),yI(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=To.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){tC(t)&&(t=Ave(t)),qw(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?To.basename(this.path,this.extname):void 0}set stem(t){qw(t,"stem"),Gw(t,"stem"),this.path=To.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const i=this.message(t,n,r);throw i.fatal=!0,i}info(t,n,r){const i=this.message(t,n,r);return i.fatal=void 0,i}message(t,n,r){const i=new li(t,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function Gw(e,t){if(e&&e.includes(To.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+To.sep+"`")}function qw(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function yI(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function Mve(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Lve=(function(e){const r=this.constructor.prototype,i=r[e],s=function(){return i.apply(s,arguments)};return Object.setPrototypeOf(s,r),s}),Ive={}.hasOwnProperty;class h2 extends Lve{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=yve()}copy(){const t=new h2;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(Vw(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(Xw("data",this.frozen),this.namespace[t]=n,this):Ive.call(this.namespace,t)&&this.namespace[t]||void 0:t?(Xw("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=n.call(t,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=_v(t),r=this.parser||this.Parser;return Kw("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),Kw("process",this.parser||this.Parser),Yw("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(s,o){const a=_v(t),c=r.parse(a);r.run(c,a,function(f,m,g){if(f||!m||!g)return d(f);const b=m,y=r.stringify(b,g);Ove(y)?g.value=y:g.result=y,d(f,g)});function d(f,m){f||!m?o(f):s?s(m):n(void 0,m)}}}processSync(t){let n=!1,r;return this.freeze(),Kw("processSync",this.parser||this.Parser),Yw("processSync",this.compiler||this.Compiler),this.process(t,i),wI("processSync","process",n),r;function i(s,o){n=!0,bI(s),r=o}}run(t,n,r){_I(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?s(void 0,r):new Promise(s);function s(o,a){const c=_v(n);i.run(t,c,d);function d(f,m,g){const b=m||t;f?a(f):o?o(b):r(void 0,b,g)}}}runSync(t,n){let r=!1,i;return this.run(t,n,s),wI("runSync","run",r),i;function s(o,a){bI(o),i=a,r=!0}}stringify(t,n){this.freeze();const r=_v(n),i=this.compiler||this.Compiler;return Yw("stringify",i),_I(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(Xw("use",this.frozen),t!=null)if(typeof t=="function")c(t,n);else if(typeof t=="object")Array.isArray(t)?a(t):o(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function s(d){if(typeof d=="function")c(d,[]);else if(typeof d=="object")if(Array.isArray(d)){const[f,...m]=d;c(f,m)}else o(d);else throw new TypeError("Expected usable value, not `"+d+"`")}function o(d){if(!("plugins"in d)&&!("settings"in d))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");a(d.plugins),d.settings&&(i.settings=Vw(!0,i.settings,d.settings))}function a(d){let f=-1;if(d!=null)if(Array.isArray(d))for(;++f<d.length;){const m=d[f];s(m)}else throw new TypeError("Expected a list of plugins, not `"+d+"`")}function c(d,f){let m=-1,g=-1;for(;++m<r.length;)if(r[m][0]===d){g=m;break}if(g===-1)r.push([d,...f]);else if(f.length>0){let[b,...y]=f;const _=r[g][1];eC(_)&&eC(b)&&(b=Vw(!0,_,b)),r[g]=[d,b,...y]}}}}const Dve=new h2().freeze();function Kw(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function Yw(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function Xw(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function _I(e){if(!eC(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function wI(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function _v(e){return Pve(e)?e:new eF(e)}function Pve(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function Ove(e){return typeof e=="string"||zve(e)}function zve(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Bve="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",SI=[],CI={allowDangerousHtml:!0},Fve=/^(https?|ircs?|mailto|xmpp)$/i,$ve=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function Vo(e){const t=Hve(e),n=Uve(e);return Vve(t.runSync(t.parse(n),n),e)}function Hve(e){const t=e.rehypePlugins||SI,n=e.remarkPlugins||SI,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...CI}:CI;return Dve().use(jge).use(n).use(vve,r).use(t)}function Uve(e){const t=e.children||"",n=new eF;return typeof t=="string"&&(n.value=t),n}function Vve(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,s=t.disallowedElements,o=t.skipHtml,a=t.unwrapDisallowed,c=t.urlTransform||Wve;for(const f of $ve)Object.hasOwn(t,f.from)&&(""+f.from+(f.to?"use `"+f.to+"` instead":"remove it")+Bve+f.id,void 0);return QE(e,d),Bpe(e,{Fragment:u.Fragment,components:i,ignoreInvalidStyle:!0,jsx:u.jsx,jsxs:u.jsxs,passKeys:!0,passNode:!0});function d(f,m,g){if(f.type==="raw"&&g&&typeof m=="number")return o?g.children.splice(m,1):g.children[m]={type:"text",value:f.value},m;if(f.type==="element"){let b;for(b in Hw)if(Object.hasOwn(Hw,b)&&Object.hasOwn(f.properties,b)){const y=f.properties[b],_=Hw[b];(_===null||_.includes(f.tagName))&&(f.properties[b]=c(String(y||""),b,f))}}if(f.type==="element"){let b=n?!n.includes(f.tagName):s?s.includes(f.tagName):!1;if(!b&&r&&typeof m=="number"&&(b=!r(f,m,g)),b&&g&&typeof m=="number")return a&&f.children?g.children.splice(m,1,...f.children):g.children.splice(m,1),m}}}function Wve(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||Fve.test(e.slice(0,t))?e:""}const wv=new Map;function Gve(e){return`${e.id}|${e.contentUrl}|${e.size??0}`}function py(e){const t=Gve(e),n=wv.get(t),[r,i]=v.useState(n??{status:"loading"}),[s,o]=v.useState(t),a=v.useRef(t);return a.current=t,s!==t&&(o(t),i(wv.get(t)??{status:"loading"})),v.useEffect(()=>{if(n&&n.status!=="loading")return;let c=!1;const d=t;return YE(e.contentUrl,X8).then(f=>{if(c||a.current!==d)return;const m={status:"ready",content:f.content,truncated:f.truncated};wv.set(d,m),i(m)}).catch(f=>{if(c||a.current!==d)return;const g={status:"error",message:f instanceof Error?f.message:"Unable to load preview."};wv.set(d,g),i(g)}),()=>{c=!0}},[n,t,e.contentUrl]),r}function qve({source:e}){const t=py(e);return t.status==="loading"?u.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[u.jsx("div",{className:"prose hidden"})," Loading…"]}):t.status==="error"?u.jsx("div",{className:"p-4 text-sm text-destructive",children:t.message}):u.jsxs("div",{className:"space-y-2 p-3",children:[t.truncated?u.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:"Preview truncated to 1024 KB."}):null,u.jsx("div",{className:"prose prose-sm prose-invert max-w-none rounded-xl border border-border bg-background p-4",children:u.jsx(Vo,{remarkPlugins:za,components:Ba,children:t.content})})]})}const Sv=new Map;function Kve(e){return`${e.id}|${e.contentUrl}|${e.size??0}|${e.mimeType}`}function Yve({source:e}){const t=Kve(e),n=Sv.get(t),[r,i]=v.useState(n??{status:"loading"}),[s,o]=v.useState(t),a=v.useRef(t);if(a.current=t,s!==t&&(o(t),i(Sv.get(t)??{status:"loading"})),v.useEffect(()=>{if(n&&n.status!=="loading")return;const g=e.mimeType==="text/tab-separated-values"?" ":",";let b=!1;const y=t;return YE(e.contentUrl,X8).then(_=>{if(b||a.current!==y)return;const w={status:"ready",table:Nde(_.content,g),truncated:_.truncated};Sv.set(y,w),i(w)}).catch(_=>{if(b||a.current!==y)return;const w={status:"error",message:_ instanceof Error?_.message:"Unable to load preview."};Sv.set(y,w),i(w)}),()=>{b=!0}},[n,t,e.contentUrl,e.mimeType]),r.status==="loading")return u.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[u.jsx("table",{className:"sr-only"})," Loading…"]});if(r.status==="error")return u.jsxs("div",{className:"p-4 text-sm text-destructive",children:[u.jsx("table",{className:"sr-only"})," ",r.message]});const{table:c}=r,[d,...f]=c.rows,m=[r.truncated?"Preview truncated to 1024 KB.":null,c.truncatedRows?`Showing first ${c.rows.length} of ${c.rowCount} rows.`:null,c.truncatedColumns?`Showing first ${G1} of ${c.columnCount} columns.`:null].filter(Boolean);return u.jsxs("div",{className:"space-y-2 p-3",children:[m.length?u.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:m.join(" ")}):null,u.jsx("div",{className:"overflow-x-auto rounded-xl border border-border bg-background",children:u.jsxs("table",{className:"min-w-full border-collapse text-xs",children:[d?u.jsx("thead",{className:"sticky top-0 bg-muted",children:u.jsx("tr",{children:d.map((g,b)=>u.jsx("th",{className:"border-b border-border px-3 py-2 text-left font-medium",children:g||" "},b))})}):null,u.jsx("tbody",{children:f.map((g,b)=>u.jsx("tr",{className:"odd:bg-background even:bg-muted/20",children:g.map((y,_)=>u.jsx("td",{className:"max-w-[320px] border-b border-border px-3 py-2 align-top",children:u.jsx("div",{className:"whitespace-pre-wrap break-words",children:y||" "})},_))},b))})]})})]})}function Xve({source:e}){const t=py(e);return t.status==="loading"?u.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[u.jsx("pre",{className:"sr-only"})," Loading…"]}):t.status==="error"?u.jsxs("div",{className:"p-4 text-sm text-destructive",children:[u.jsx("pre",{className:"sr-only"})," ",t.message]}):u.jsxs("div",{className:"space-y-2 p-3",children:[t.truncated?u.jsx(Qve,{children:"Preview truncated to 1024 KB."}):null,u.jsx("pre",{className:"whitespace-pre-wrap break-words rounded-xl border border-border bg-background p-3 text-xs",children:t.content})]})}function Qve({children:e}){return u.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:e})}function Zve({source:e}){const t=py(e),n=v.useMemo(()=>t.status==="ready"?Ede(t.content):"",[t]);return t.status==="loading"?u.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[u.jsx("pre",{className:"sr-only"})," Loading…"]}):t.status==="error"?u.jsxs("div",{className:"p-4 text-sm text-destructive",children:[u.jsx("pre",{className:"sr-only"})," ",t.message]}):u.jsxs("div",{className:"space-y-2 p-3",children:[t.truncated?u.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:"Preview truncated to 1024 KB."}):null,u.jsx("pre",{className:"whitespace-pre-wrap break-words rounded-xl border border-border bg-background p-3 text-xs",children:n})]})}function Jve({source:e}){return u.jsxs("div",{className:"flex h-full flex-col items-stretch justify-center gap-3 p-4",children:[u.jsx("div",{className:"text-sm font-medium text-foreground",children:e.displayName}),u.jsx("audio",{src:e.contentUrl,controls:!0,preload:"metadata",className:"w-full"})]})}function ebe({source:e}){return u.jsx("div",{className:"flex h-full items-center justify-center bg-black/40 p-2",children:u.jsx("video",{src:e.contentUrl,controls:!0,playsInline:!0,preload:"metadata",className:"max-h-[60dvh] w-full rounded-xl"})})}const tbe=200*1024;function nbe(e){const t=e.lastIndexOf(".");if(t<0)return"text";const n=e.slice(t+1).toLowerCase();return{ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",py:"python",go:"go",rs:"rust",java:"java",rb:"ruby",sh:"bash",zsh:"bash",yml:"yaml",yaml:"yaml",css:"css",scss:"scss",html:"html",json:"json",md:"markdown",sql:"sql",cpp:"cpp",c:"c",h:"c",swift:"swift",kt:"kotlin",php:"php",toml:"toml"}[n]??"text"}function rbe({source:e}){const t=py(e),n=t.status==="ready"&&t.content.length<=tbe,r=n?`${e.id}|${e.contentUrl}|${e.size??0}|${t.content.length}`:null,[i,s]=v.useState(null);return v.useEffect(()=>{if(!n||t.status!=="ready"||r===null)return;let o=!1;const a=r;return Y(()=>Promise.resolve().then(()=>$8),void 0).then(async c=>{if(o)return;const d=await c.codeToHtml(t.content,{lang:nbe(e.fileName),theme:"github-dark"});o||s({key:a,html:d})}).catch(()=>{typeof console<"u"&&console.warn("[file-preview] Shiki unavailable; falling back to plain text")}),()=>{o=!0}},[n,r,t,e.fileName]),t.status==="loading"?u.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[u.jsx("pre",{className:"sr-only"})," Loading…"]}):t.status==="error"?u.jsxs("div",{className:"p-4 text-sm text-destructive",children:[u.jsx("pre",{className:"sr-only"})," ",t.message]}):i&&i.key===r?u.jsx("div",{className:"overflow-x-auto p-3 text-xs",dangerouslySetInnerHTML:{__html:i.html}}):u.jsxs("div",{className:"space-y-2 p-3",children:[t.truncated?u.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:"Preview truncated to 1024 KB."}):null,u.jsx("pre",{className:"whitespace-pre-wrap break-words rounded-xl border border-border bg-background p-3 text-xs",children:t.content})]})}async function ibe(e){var r;const t=obe(e.contentUrl),n=navigator.share;if(typeof n=="function")try{return await n.call(navigator,{title:e.displayName,url:t}),"shared"}catch(i){if(i instanceof DOMException&&i.name==="AbortError")return"shared"}if((r=navigator.clipboard)!=null&&r.writeText)try{return await navigator.clipboard.writeText(t),"copied"}catch{return"failed"}return"failed"}function sbe(e){const t=document.createElement("a");t.href=e.contentUrl,t.download=e.fileName,t.rel="noopener",document.body.appendChild(t),t.click(),t.remove()}function obe(e){return typeof window>"u"?e:new URL(e,document.baseURI||window.location.href).toString()}function Ch({source:e,open:t,onOpenChange:n}){const r=v.useCallback(()=>n(!1),[n]);return u.jsx(so,{open:t&&e!==null,onOpenChange:n,children:u.jsx(As,{size:"lg",className:"inset-0 h-[100dvh] max-h-none w-full max-w-none translate-x-0 translate-y-0 rounded-none p-0 md:inset-auto md:left-1/2 md:top-1/2 md:h-auto md:max-h-[90dvh] md:w-auto md:max-w-3xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-2xl",children:e?u.jsx(ube,{source:e,onClose:r}):null})})}const abe=120,lbe=.5;function cbe({startY:e,lastY:t,lastT:n,endY:r,now:i}){const s=r-e,o=Math.max(1,i-n),a=(r-t)/o;return s>abe||a>lbe}function ube({source:e,onClose:t}){const n=hbe(e),[r,i]=v.useState(0),s=v.useRef(null),o=v.useCallback(m=>{s.current={y:m.clientY,lastY:m.clientY,lastT:Date.now()};try{m.currentTarget.setPointerCapture(m.pointerId)}catch{}},[]),a=v.useCallback(m=>{if(!s.current)return;const g=m.clientY-s.current.y;g<0||(s.current.lastY=m.clientY,s.current.lastT=Date.now(),i(g))},[]),c=v.useCallback(m=>{const g=s.current;s.current=null;try{m.currentTarget.releasePointerCapture(m.pointerId)}catch{}g&&(cbe({startY:g.y,lastY:g.lastY,lastT:g.lastT,endY:m.clientY,now:Date.now()})?t():i(0))},[t]),d=v.useCallback(()=>{ibe(e)},[e]),f=v.useCallback(()=>sbe(e),[e]);return u.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",style:r>0?{transform:`translateY(${r}px)`,transition:"none"}:void 0,children:[u.jsxs("div",{onPointerDown:o,onPointerMove:a,onPointerUp:c,onPointerCancel:c,className:"border-b border-border px-4 py-3 touch-none",children:[u.jsx("div",{className:"mx-auto mb-2 h-1 w-12 rounded-full bg-muted md:hidden",role:"button","aria-label":"Drag down to close"}),u.jsx(oo,{className:"truncate text-base",children:e.displayName}),u.jsx(np,{className:"truncate text-xs",children:n})]}),u.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain touch-pan-y [-webkit-overflow-scrolling:touch]",role:"region","aria-label":"File preview",children:v.createElement(dbe(e),{source:e})},e.id),u.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border px-4 py-3",children:[u.jsxs(De,{type:"button",variant:"outline",onClick:d,children:[u.jsx(Aq,{className:"mr-2 h-4 w-4"}),"Share"]}),e.origin==="offer_download"?u.jsxs(De,{type:"button",onClick:f,children:[u.jsx(pk,{className:"mr-2 h-4 w-4"}),"Download"]}):null]})]})}function dbe(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=wh(t);return n==="image"?Cpe:n==="pdf"?JL:n==="audio"?Jve:n==="video"?ebe:n==="table"?Yve:n==="markdown"?qve:n==="json"?Zve:n==="code"?rbe:_h(t).kind==="external"?JL:Xve}function hbe(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=wh(t),r=cy(n,e.mimeType),i=e.size?` · ${kh(e.size)}`:"";return`${r}${i}`}function Cp(e,t){return{id:e.id,contentUrl:e.contentUrl,displayName:e.displayName,fileName:e.displayName,relativePath:e.relativePath,mimeType:e.mimeType,size:e.size,origin:t}}function fbe(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function mbe({path:e,linkText:t}){const n=v.useMemo(()=>r2(e),[e]),[r,i]=v.useState({kind:"loading"}),[s,o]=v.useState(!1);v.useEffect(()=>{const A=new AbortController;return fetch(n,{method:"HEAD",signal:A.signal}).then(j=>{var M,D;if(A.signal.aborted)return;if(!j.ok){i({kind:j.status===404?"missing":"error"});return}const I=((D=(M=j.headers.get("Content-Type"))==null?void 0:M.split(";")[0])==null?void 0:D.trim())||"application/octet-stream",U=Number.parseInt(j.headers.get("Content-Length")??"0",10)||0;i({kind:"ready",mimeType:I,size:U})}).catch(()=>{A.signal.aborted||i({kind:"error"})}),()=>A.abort()},[n]);const a=fbe(e),c=t||a,d=Spe(c,28),f=r.kind==="ready"?r.mimeType:"application/octet-stream",m=r.kind==="ready"?r.size:0,g={id:`local-file-${n}`,kind:"file",displayName:d,absolutePath:e,relativePath:e,contentUrl:n,mimeType:f,size:m};if(r.kind==="missing")return u.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:u.jsx(Fo,{attachment:g,disabledReason:"File no longer available"})});const b=wh(g),y=cy(b,f),_=m>0?kh(m):null,w=r.kind==="loading",C=r.kind==="error",E=w?u.jsx("span",{className:"text-muted-foreground",children:"Fetching…"}):C?u.jsx("span",{className:"text-muted-foreground",children:"Unable to load"}):u.jsxs(u.Fragment,{children:[y,_?u.jsxs(u.Fragment,{children:[" · ",u.jsx("span",{className:"tabular-nums",children:_})]}):null]}),k=r.kind==="ready"?_h(g):null,T=k!==null&&!k.openInNewTab,R=[T?"Preview":"Download",c,y,_].filter(Boolean);return T?u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:u.jsx(Fo,{attachment:g,onClick:()=>o(!0),meta:E,ariaLabel:R.join(", ")})}),u.jsx(Ch,{source:s?Cp(g,"local_file_link"):null,open:s,onOpenChange:o})]}):u.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:u.jsx(Fo,{attachment:g,href:n,download:a,meta:E,ariaLabel:R.join(", ")})})}function pbe(e,t){var n,r,i,s,o,a,c,d,f,m;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,...(a=(o=t.providerDefaults)==null?void 0:o.codex)==null?void 0:a.modelOptions}}},cloudflareTunnel:{...e.cloudflareTunnel,...t.cloudflareTunnel},claudeAuth:{tokens:((c=t.claudeAuth)==null?void 0:c.tokens)??e.claudeAuth.tokens,concurrencyDefault:((d=t.claudeAuth)==null?void 0:d.concurrencyDefault)??e.claudeAuth.concurrencyDefault},auth:{...e.auth,...t.auth},uploads:{...e.uploads,...t.uploads},subagents:e.subagents,customMcpServers:e.customMcpServers,claudeDriver:{preference:((f=t.claudeDriver)==null?void 0:f.preference)??e.claudeDriver.preference,lifecycle:{...e.claudeDriver.lifecycle,...(m=t.claudeDriver)==null?void 0:m.lifecycle}},globalPromptAppend:t.globalPromptAppend??e.globalPromptAppend}}const Di=ss()(e=>({settings:null,hydrationStatus:"idle",setHydrationStatus:t=>e({hydrationStatus:t}),setFromServer:t=>e({settings:t,hydrationStatus:"ready"}),applyOptimisticPatch:t=>e(n=>({settings:n.settings?pbe(n.settings,t):n.settings}))})),gbe=[],vbe=e=>{var t;return((t=e.settings)==null?void 0:t.customMcpServers)??gbe},tF=v.createContext(void 0),bbe=e=>e==="light"||e==="dark"||e==="system";function xbe(e){return e==="dark"?"black-translucent":"default"}function kI(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 EI(e){if(typeof document>"u"||typeof window>"u")return;const t=getComputedStyle(document.body).backgroundColor||getComputedStyle(document.documentElement).backgroundColor;t&&kI("theme-color",t),kI("apple-mobile-web-app-status-bar-style",xbe(e)),document.documentElement.style.colorScheme=e}const ub=()=>typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",NI=e=>{if(typeof document>"u")return;const t=e==="system"?ub():e;document.documentElement.classList.toggle("dark",t==="dark")},ybe=()=>{var t;const e=(t=Di.getState().settings)==null?void 0:t.theme;return e&&bbe(e)?e:"system"};function _be({children:e}){const t=Di(o=>{var a;return(a=o.settings)==null?void 0:a.theme}),n=Di(o=>o.applyOptimisticPatch),[r,i]=v.useState(ybe);v.useEffect(()=>{!t||t===r||i(t)},[t,r]),v.useEffect(()=>{NI(r)},[r]),v.useEffect(()=>{const o=r==="system"?ub():r;EI(o)},[r]),v.useEffect(()=>{if(r!=="system")return;const o=window.matchMedia("(prefers-color-scheme: dark)"),a=()=>{NI("system"),EI(ub())};return o.addEventListener?(o.addEventListener("change",a),()=>o.removeEventListener("change",a)):(o.addListener(a),()=>o.removeListener(a))},[r]);const s=v.useMemo(()=>{const o=r==="system"?ub():r;return{theme:r,resolvedTheme:o,setTheme:a=>{i(a),n({theme:a})}}},[n,r]);return u.jsx(tF.Provider,{value:s,children:e})}function gy(){const e=v.useContext(tF);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}function wbe({svg:e,onClose:t}){const[n,r]=v.useState(1),[i,s]=v.useState({x:0,y:0}),[o,a]=v.useState(null);v.useEffect(()=>{const g=b=>{b.key==="Escape"&&t()};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[t]);const c=g=>Math.min(8,Math.max(.25,g)),d=g=>{a({x:g.clientX-i.x,y:g.clientY-i.y})},f=g=>{o&&s({x:g.clientX-o.x,y:g.clientY-o.y})},m=()=>a(null);return Ji.createPortal(u.jsxs("div",{className:"fixed inset-0 z-[100] flex flex-col bg-background/95",role:"dialog","aria-modal":"true","aria-label":"Diagram zoom view",children:[u.jsxs("div",{className:"flex justify-end gap-1 p-2",children:[u.jsx(De,{variant:"ghost",size:"icon","aria-label":"Zoom out",className:"h-9 w-9",onClick:()=>r(g=>c(g-.25)),children:u.jsx(K5,{className:"h-4 w-4"})}),u.jsx(De,{variant:"ghost",size:"icon","aria-label":"Zoom in",className:"h-9 w-9",onClick:()=>r(g=>c(g+.25)),children:u.jsx(ro,{className:"h-4 w-4"})}),u.jsx(De,{variant:"ghost",size:"icon","aria-label":"Reset view",className:"h-9 w-9",onClick:()=>{r(1),s({x:0,y:0})},children:u.jsx(pq,{className:"h-4 w-4"})}),u.jsx(De,{variant:"ghost",size:"icon","aria-label":"Close",className:"h-9 w-9",onClick:t,children:u.jsx(Is,{className:"h-4 w-4"})})]}),u.jsx("div",{className:"flex-1 overflow-hidden touch-none cursor-grab active:cursor-grabbing",onPointerDown:d,onPointerMove:f,onPointerUp:m,onPointerLeave:m,children:u.jsx("div",{"data-mermaid-stage":!0,className:"w-full h-full flex items-center justify-center",style:{transform:`translate(${i.x}px, ${i.y}px) scale(${n})`},dangerouslySetInnerHTML:{__html:e}})})]}),document.body)}let Qw=null;function Sbe(){return Qw||(Qw=Y(()=>import("./mermaid.core-BdksXM55.js").then(e=>e.bm),[]).then(e=>e.default)),Qw}function Cbe({source:e}){const{resolvedTheme:t}=gy(),n=t==="dark"?"dark":"default",[r,i]=v.useState({status:"loading"}),o=`mermaid-${v.useId().replace(/[^a-zA-Z0-9_-]/g,"")}`,[a,c]=v.useState(!1),[d,f]=v.useState(!1),[m,g]=v.useState(!1),b=v.useCallback(()=>f(!1),[]),y=async()=>{await navigator.clipboard.writeText(e),g(!0),setTimeout(()=>g(!1),2e3)};return v.useEffect(()=>{let _=!1;return Sbe().then(async w=>{w.initialize({startOnLoad:!1,securityLevel:"strict",theme:n});const{svg:C}=await w.render(o,e);_||i({status:"ready",svg:C})}).catch(()=>{_||i({status:"error"})}),()=>{_=!0}},[e,n,o]),r.status==="error"?u.jsx(Zw,{source:e}):r.status==="loading"?u.jsx("div",{className:"relative group/mermaid",children:u.jsx(Zw,{source:e})}):a?u.jsxs("div",{className:"relative group/mermaid",children:[u.jsx(Zw,{source:e}),u.jsx(TI,{showSource:a,onToggleSource:()=>c(_=>!_),onCopy:y,copied:m,onZoom:void 0})]}):u.jsxs("div",{className:"relative group/mermaid my-3",children:[u.jsx("div",{className:"flex justify-center overflow-x-auto",dangerouslySetInnerHTML:{__html:r.svg}}),u.jsx(TI,{showSource:a,onToggleSource:()=>c(_=>!_),onCopy:y,copied:m,onZoom:()=>f(!0)}),d&&u.jsx(wbe,{svg:r.svg,onClose:b})]})}function TI({showSource:e,onToggleSource:t,onCopy:n,copied:r,onZoom:i}){return u.jsxs("div",{className:"absolute top-1.5 right-1.5 flex gap-1 opacity-100 md:opacity-0 md:group-hover/mermaid:opacity-100 transition-opacity [@media(hover:none)]:!opacity-100",children:[i&&!e&&u.jsx(De,{variant:"ghost",size:"icon","aria-label":"Zoom diagram",className:"h-8 w-8 rounded-md text-muted-foreground hover:text-foreground",onClick:i,children:u.jsx(FG,{className:"h-4 w-4"})}),u.jsx(De,{variant:"ghost",size:"icon","aria-label":e?"View rendered diagram":"View diagram source",className:"h-8 w-8 rounded-md text-muted-foreground hover:text-foreground",onClick:t,children:u.jsx($S,{className:"h-4 w-4"})}),u.jsx(De,{variant:"ghost",size:"icon","aria-label":r?"Copied":"Copy diagram source",className:de("h-8 w-8 rounded-md text-muted-foreground",!r&&"hover:text-foreground",r&&"hover:!bg-transparent"),onClick:n,children:r?u.jsx(ns,{className:"h-4 w-4 text-success"}):u.jsx(La,{className:"h-4 w-4"})})]})}const kbe=200*1024,Ebe={ts:"typescript",typescript:"typescript",tsx:"tsx",js:"javascript",javascript:"javascript",jsx:"jsx",py:"python",python:"python",go:"go",golang:"go",rs:"rust",rust:"rust",java:"java",rb:"ruby",ruby:"ruby",sh:"bash",bash:"bash",zsh:"bash",shell:"bash",yml:"yaml",yaml:"yaml",css:"css",scss:"scss",html:"html",xml:"xml",json:"json",json5:"json5",md:"markdown",markdown:"markdown",sql:"sql",cpp:"cpp","c++":"cpp",c:"c",h:"c",swift:"swift",kt:"kotlin",kotlin:"kotlin",php:"php",toml:"toml",dockerfile:"dockerfile",diff:"diff",patch:"diff",vue:"vue",svelte:"svelte"};function Nbe(e){return Ebe[e.toLowerCase()]??null}const Tbe=/^<pre[^>]*>/,Rbe=/<\/pre>\s*$/,Abe=/^<code[^>]*>/,jbe=/<\/code>\s*$/;function Mbe(e){return e.replace(Tbe,"").replace(Rbe,"").replace(Abe,"").replace(jbe,"")}function Bf({source:e,lang:t}){const{resolvedTheme:n}=gy(),r=n==="dark"?"github-dark":"github-light",i=Nbe(t),s=i!==null&&e.length<=kbe,[o,a]=v.useState(null);v.useEffect(()=>{if(!s||i===null)return;let f=!1;return Y(()=>Promise.resolve().then(()=>$8),void 0).then(async m=>{if(f)return;const g=await m.codeToHtml(e,{lang:i,theme:r});f||a({source:e,theme:r,lang:i,html:Mbe(g)})}).catch(()=>{typeof console<"u"&&console.warn("[transcript] Shiki unavailable; falling back to plain code")}),()=>{f=!0}},[s,e,i,r]);const c=i??t.toLowerCase();return o!==null&&o.source===e&&o.theme===r&&o.lang===i?u.jsx("code",{className:`block text-xs whitespace-pre language-${c} shiki-highlighted`,dangerouslySetInnerHTML:{__html:o.html}}):u.jsx("code",{className:`block text-xs whitespace-pre language-${c}`,children:e})}const nF={readonly:!1,localLinkMode:"open"},rF=v.createContext(nF);function Lbe({children:e,value:t}){return u.jsx(rF.Provider,{value:{...nF,...t},children:e})}function vy(){return v.useContext(rF)}const ax=()=>{},iF=v.createContext(ax);function sF({children:e,onOpenLocalLink:t}){return u.jsx(iF.Provider,{value:t??ax,children:e})}const nC={Task:Cb,TaskOutput:Cb,Bash:Nx,Glob:qf,Grep:qf,ExitPlanMode:rj,Read:H5,Edit:GW,Write:KW,Delete:tG,NotebookEdit:oh,WebFetch:UV,TodoWrite:aW,WebSearch:qf,KillShell:$q,AskUserQuestion:G5,Skill:Dq,EnterPlanMode:rj},oF=Qq;function aF(e){return nC[e]?nC[e]:oF}function lF({icon:e,className:t}){return u.jsx(e,{className:t})}function Wa({children:e,className:t}){return u.jsx("div",{className:de("flex gap-3 justify-start items-center",t),children:e})}function cF({children:e,className:t}){return u.jsx("div",{className:de("flex items-center gap-1.5 text-xs",t),children:e})}function eu({children:e,className:t}){return u.jsx("span",{className:de("font-medium text-foreground/80",t),children:e})}function Ibe({children:e}){return u.jsx("span",{className:"text-muted-foreground",children:e})}function Dbe({children:e,className:t}){return u.jsxs(Wa,{className:de("px-0.5 text-xs tracking-wide",t),children:[u.jsx("div",{className:"w-full h-[1px] bg-border"}),u.jsx(eu,{className:"whitespace-nowrap text-[11px] tracking-widest text-muted-foreground/60 uppercase flex-shrink-0",children:e}),u.jsx("div",{className:"w-full h-[1px] bg-border"})]})}function f2({children:e,expandedContent:t,defaultExpanded:n=!1}){const[r,i]=v.useState(n);return u.jsxs("div",{className:"flex flex-col w-full",children:[u.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:[u.jsx("div",{className:"grid grid-cols-[auto_1fr] items-center gap-1.5",children:e}),u.jsx(no,{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 rC({label:e,children:t,copyText:n}){const[r,i]=v.useState(!1),s=n??Kd(t),o=v.useCallback(async()=>{await navigator.clipboard.writeText(s),i(!0),setTimeout(()=>i(!1),2e3)},[s]);return u.jsxs("div",{children:[u.jsx("span",{className:"font-medium text-muted-foreground",children:e}),u.jsxs("div",{className:"relative group/codeblock",children:[u.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}),u.jsx(De,{variant:"ghost",size:"icon","aria-label":r?"Copied":"Copy code",className:de("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?u.jsx(ns,{className:"h-3.5 w-3.5 text-success"}):u.jsx(La,{className:"h-4 w-4"})})]})]})}function uF({children:e,icon:t,className:n}){return u.jsxs("span",{className:de("inline-flex items-center gap-1 px-2 py-1 bg-muted border border-border rounded-full",n),children:[t&&u.jsx(t,{className:"h-3 w-3 text-muted-foreground"}),e]})}function by({children:e,className:t}){return u.jsxs("div",{className:de("grid grid-cols-[auto_1fr] gap-2 min-w-0",t),children:[u.jsx("div",{className:" min-w-5 flex flex-col relative items-center justify-center",children:u.jsx("div",{className:"min-h-full w-[1px] bg-muted-foreground/20"})}),u.jsx("div",{className:"-ml-[1px] min-w-0 overflow-hidden",children:e})]})}function Kd(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(Array.isArray(e))return e.map(Kd).join("");if(e&&typeof e=="object"&&"props"in e){const t=e.props;return Kd(t.children)}return""}function RI(e,t){return v.isValidElement(e)?v.cloneElement(e,{className:de(e.props.className,t)}):e}function dF({children:e,...t}){const[n,r]=v.useState(!1),i=Kd(e),s=async()=>{await navigator.clipboard.writeText(i),r(!0),setTimeout(()=>r(!1),2e3)};return u.jsxs("div",{className:"relative overflow-x-auto max-w-full min-w-0 no-code-highlight group/pre",children:[u.jsx("pre",{className:"min-w-0 rounded-xl py-2.5 px-3.5 [.no-pre-highlight_&]:bg-background",...t,children:e}),u.jsx(De,{variant:"ghost",size:"icon","aria-label":n?"Copied":"Copy code",className:de("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?u.jsx(ns,{className:"h-4 w-4 text-success"}):u.jsx(La,{className:"h-4 w-4"})})]})}function Zw({source:e}){return u.jsx(dF,{children:u.jsx("code",{className:"block text-xs whitespace-pre language-mermaid",children:e})})}const m2={h1:({children:e})=>u.jsx("h1",{className:"text-[20px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h2:({children:e})=>u.jsx("h2",{className:"text-[18px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h3:({children:e})=>u.jsx("h3",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h4:({children:e})=>u.jsx("h4",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h5:({children:e})=>u.jsx("h5",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h6:({children:e})=>u.jsx("h6",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),pre:dF,code:({children:e,className:t,...n})=>{if(!t)return u.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});const i=t.split(/\s+/);if(i.includes("language-mermaid"))return u.jsx(Cbe,{source:Kd(e)});const s=i.find(a=>a.startsWith("language-")),o=s?s.slice(9):"";return o?u.jsx(Bf,{source:Kd(e),lang:o}):u.jsx("code",{className:"block text-xs whitespace-pre",...n,children:e})},table:({children:e,...t})=>u.jsx("div",{className:"border border-border rounded-xl overflow-x-auto",children:u.jsx("table",{className:"table-auto min-w-full divide-y divide-border bg-background",...t,children:e})}),tbody:({children:e,...t})=>u.jsx("tbody",{className:"divide-y divide-border",...t,children:e}),th:({children:e,...t})=>u.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})=>u.jsx("td",{className:"text-left p-2 pl-0 first:pl-3 [&_*]:font-normal ",...t,children:e}),p:({children:e,...t})=>u.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]=RI(r,"mt-0"));const i=n.length-1,s=n[i];return s!==void 0&&(n[i]=RI(s,"mb-0")),u.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})=>u.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"&&wpe(e)?r2(e):e;return u.jsx("img",{src:n,...t})}};function Pbe({children:e,href:t,onClick:n,overrideOpenLocalLink:r,...i}){const s=v.useContext(iF),o=r??s,a=vy(),c=ype(t);if(c&&a.localLinkMode==="text")return u.jsx("span",{className:"transition-all underline decoration-2 text-logo decoration-logo/50",children:e});if(c&&!zB(c.path)){const d=iC(e).trim();return u.jsx(mbe,{path:c.path,linkText:d||void 0})}return u.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:d=>{n==null||n(d),!(d.defaultPrevented||!c||o===ax)&&(d.preventDefault(),o({...c,clientX:d.clientX,clientY:d.clientY,trigger:"click"}))},onContextMenu:d=>{!c||o===ax||(d.preventDefault(),o({...c,clientX:d.clientX,clientY:d.clientY,trigger:"contextmenu"}))},...i,children:e})}function Obe(e){return{...m2,a:t=>u.jsx(Pbe,{...t,overrideOpenLocalLink:e==null?void 0:e.onOpenLocalLink})}}const za=[OB],Ba=Obe();function iC(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(iC).join(""):v.isValidElement(e)?iC(e.props.children):""}({...m2});function p2({attachment:e,previewUrl:t,onClick:n,onRemove:r,className:i,size:s="transcript",uploadProgress:o,onCancelUpload:a}){const c=e.contentUrl||t,d=s==="composer",f=o!==void 0;return u.jsxs("div",{className:de("group relative flex flex-row items-end",i),children:[u.jsxs("button",{type:"button",onClick:n,className:de("group/image relative overflow-hidden rounded-xl border border-border/80 bg-background shadow-sm",d?"min-w-[80px]":"min-w-[200px]"),children:[c?u.jsx("img",{src:c,alt:e.displayName,className:de("rounded-xl object-contain bg-muted",d?"min-h-[50px] min-w-[80px] max-h-[120px] max-w-[200px]":"min-h-[100px] min-w-[200px] max-h-[300px] max-w-[300px]")}):u.jsx("div",{className:de("flex items-center justify-center rounded-xl bg-muted text-muted-foreground",d?"min-h-[64px] min-w-[80px]":"min-h-[160px] min-w-[200px]"),children:u.jsx($5,{className:de(d?"size-6":"size-8")})}),u.jsxs("div",{className:de("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",d?"px-2.5 pb-2 pt-6":"px-4 pb-3 pt-10"),children:[u.jsx("div",{className:de("truncate font-medium text-white",d?"text-xs":"text-sm"),children:e.displayName}),u.jsxs("div",{className:"truncate text-xs text-white/80",children:[e.mimeType," · ",kh(e.size)]})]})]}),f?u.jsx(tB,{progress:o??null,onCancel:a,size:d?"sm":"md",cancelLabel:`Cancel upload of ${e.displayName}`}):null,r&&!f?u.jsx(hF,{displayName:e.displayName,onRemove:r}):null]})}function Fo({attachment:e,onClick:t,onRemove:n,className:r,uploadProgress:i,onCancelUpload:s,href:o,download:a,meta:c,ariaLabel:d,disabledReason:f}){const m=e.kind==="mention"?"text":wh(e),g=Fbe(m),b=e.kind==="mention",y=b?zbe(e.displayName):e.displayName,_=b?Bbe(e.displayName):"",w=i!==void 0,C=!!f,E=de("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?u.jsx("div",{className:"max-w-[150px] truncate text-[11px] text-muted-foreground",children:_?`@${_}`:"@mention"}):f?u.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:f}):c!==void 0?u.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:c}):u.jsxs("div",{className:"truncate text-[11px] text-muted-foreground",children:[e.mimeType," · ",kh(e.size)]}),T=u.jsxs(u.Fragment,{children:[u.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:u.jsx(lF,{icon:g,className:"size-5"})}),u.jsxs("div",{className:"min-w-0",children:[u.jsx("div",{className:de("max-w-[150px] truncate text-[13px] font-medium",C?"text-muted-foreground line-through":"text-foreground"),children:y}),k]})]});return u.jsxs("div",{className:de("group relative",r),children:[o&&!C?u.jsx("a",{href:o,download:a,rel:"noopener","aria-label":d,className:E,children:T}):u.jsx("button",{type:"button",onClick:C?void 0:t,title:b?e.displayName:void 0,"aria-label":d,"aria-disabled":C||void 0,disabled:C,className:E,children:T}),w?u.jsx(tB,{progress:i??null,onCancel:s,size:"sm",cancelLabel:`Cancel upload of ${e.displayName}`}):null,n&&!w?u.jsx(hF,{displayName:e.displayName,onRemove:n}):null]})}function zbe(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function Bbe(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function hF({displayName:e,onRemove:t}){return u.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:u.jsx(Is,{className:"h-3.5 w-3.5"})})}function Fbe(e){switch(e){case"image":return $5;case"pdf":return hq;case"markdown":return _q;case"json":return BW;case"table":return XW;case"code":return $W;case"text":return gk;case"archive":return OW;case"audio":return UW;case"video":return JW;default:return H5}}function kh(e){return e<1024?`${e} B`:e<1024*1024?`${Math.max(1,Math.round(e/1024))} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}const Vl=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{"data-gramm":"false","data-gramm_editor":"false","data-enable-grammarly":"false","data-1p-ignore":!0,autoComplete:"off",className:de("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}));Vl.displayName="Textarea";const Cv={};function AI(e){return!e.isCollapsed&&!e.hasPreviewAttachment&&e.patch===void 0&&e.patchError===void 0&&!e.isPatchLoading}function $be(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 fF(e){return e.isUntracked}function Hbe(e){return fF(e)?e.path.includes("/"):!1}function Jw(e){return u.jsxs(si,{delayDuration:0,children:[u.jsx(oi,{asChild:!0,children:u.jsx("button",{type:"button","aria-label":e.label,title:e.label,onClick:e.onClick,className:de("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})}),u.jsx(qr,{children:e.label})]})}function mF({checked:e,mixed:t=!1,label:n,className:r,onClick:i}){return u.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:de("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?u.jsx(K5,{className:"h-3 w-3",strokeWidth:3}):e?u.jsx(ns,{className:"h-3 w-3",strokeWidth:3}):null})}function g2(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,a=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<a?`${Math.round(n/o)}wk ago`:n<c?`${Math.round(n/a)}mo ago`:`${Math.round(n/c)}yr ago`}function Ube(e){return e?`Last fetched ${g2(e)}`:"No local fetch recorded"}function Vbe({entry:e,isPendingPush:t=!1}){const n=g2(e.authoredAt),r=!!e.githubUrl;return u.jsxs("button",{type:"button",disabled:!r,onClick:()=>{!e.githubUrl||typeof window>"u"||window.open(e.githubUrl,"_blank","noopener,noreferrer")},className:de("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:[u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:e.summary}),e.description?u.jsx("div",{className:"mt-1 line-clamp-2 whitespace-pre-wrap text-xs text-muted-foreground",children:e.description}):null,u.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-1 text-xs text-muted-foreground",children:[e.authorName?u.jsx("span",{className:"truncate",children:e.authorName}):null,e.authorName&&n?u.jsx("span",{"aria-hidden":"true",children:"•"}):null,n?u.jsx("span",{children:n}):null]})]}),e.tags.length>0?u.jsxs("div",{className:"flex shrink-0 flex-wrap justify-end gap-1",children:[e.tags.map(i=>u.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?u.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:u.jsx(dm,{className:"size-3"})}):null]}):t?u.jsx("div",{className:"flex shrink-0 flex-wrap justify-end gap-1",children:u.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:u.jsx(dm,{className:"size-3"})})}):null]})}function jI(e){switch(e.kind){case"local":return 0;case"pull_request":return 1;case"remote":default:return 2}}function Wbe(e){const t=new Map;for(const n of e){const r=t.get(n.name);(!r||jI(n)<jI(r))&&t.set(n.name,n)}return t}function Gbe(e,t){const n=Wbe([...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(a=>n.get(a.name)??a).filter(a=>!!a&&!r.has(a.name));for(const a of s)r.add(a.name);const o=[...n.values()].filter(a=>!r.has(a.name)).sort((a,c)=>a.displayName.localeCompare(c.displayName));return{defaultBranch:i,recent:s,other:o}}function qbe({open:e,onOpenChange:t,onGetGitHubPublishInfo:n,onCheckGitHubRepoAvailability:r,onPublish:i}){const[s,o]=v.useState(null),[a,c]=v.useState(!1),[d,f]=v.useState(""),[m,g]=v.useState(""),[b,y]=v.useState("private"),[_,w]=v.useState(""),[C,E]=v.useState(null),[k,T]=v.useState(!1),[R,A]=v.useState(!1);v.useEffect(()=>{if(!e)return;let U=!1;return c(!0),E(null),n().then(M=>{U||(o(M),f(M.owners[0]??M.activeAccountLogin??""),g(M.suggestedRepoName),y("private"),w(""))}).finally(()=>{U||c(!1)}),()=>{U=!0}},[n,e]),v.useEffect(()=>{if(!e||!(s!=null&&s.ghInstalled)||!s.authenticated)return;const U=d.trim(),M=m.trim();if(!U||!M){E(null);return}let D=!1;T(!0);const z=window.setTimeout(()=>{r({owner:U,name:M}).then(P=>{D||E(P)}).finally(()=>{D||T(!1)})},250);return()=>{D=!0,window.clearTimeout(z)}},[s==null?void 0:s.authenticated,s==null?void 0:s.ghInstalled,m,r,e,d]);async function j(){if(!(!d.trim()||!m.trim())){A(!0);try{const U=await i({owner:d.trim(),name:m.trim(),visibility:b,description:_});U!=null&&U.ok&&t(!1)}finally{A(!1)}}}const I=!!(s!=null&&s.ghInstalled&&s.authenticated&&d.trim()&&m.trim()&&(C!=null&&C.available)&&!k&&!R);return u.jsx(so,{open:e,onOpenChange:t,children:u.jsxs(As,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[u.jsxs(Ho,{className:"space-y-2 px-4 pb-4 pt-4",children:[u.jsxs("div",{className:"space-y-1",children:[u.jsx(oo,{children:"Push to GitHub"}),u.jsx(np,{children:"Create a GitHub repository from this local project using GitHub CLI."})]}),a?u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(_n,{className:"size-4 animate-spin"}),u.jsx("span",{children:"Checking GitHub CLI…"})]}):s&&!s.ghInstalled?u.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[u.jsx("p",{children:"GitHub CLI is not installed."}),u.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"brew install gh"}),u.jsx("p",{children:"Then run:"}),u.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?u.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[u.jsx("p",{children:"GitHub CLI is installed but not signed in."}),u.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"gh auth login"})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"space-y-2",children:u.jsxs(Lo,{value:d,onValueChange:f,children:[u.jsx(Xs,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:u.jsx(Sa,{placeholder:"Select owner"})}),u.jsx(Qs,{children:((s==null?void 0:s.owners)??[]).map(U=>u.jsx(ti,{value:U,children:u.jsxs("span",{className:"flex items-center gap-2",children:[U===(s==null?void 0:s.activeAccountLogin)?u.jsx(yk,{className:"size-4 text-muted-foreground"}):u.jsx(rW,{className:"size-4 text-muted-foreground"}),u.jsx("span",{className:"pl-[1px]",children:U})]})},U))})]})}),u.jsx("div",{className:"space-y-2",children:u.jsxs("div",{className:"relative",children:[u.jsx(mn,{value:m,onChange:U=>g(U.target.value),placeholder:"my-repo",className:"pl-9 pr-10"}),u.jsx(rq,{className:"pointer-events-none absolute inset-y-0 left-3 my-auto size-4 text-muted-foreground"}),k?u.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-3 flex items-center text-muted-foreground",children:u.jsx(_n,{className:"size-4 animate-spin"})}):C?u.jsx("div",{className:"absolute inset-y-0 right-2 flex items-center",children:u.jsxs(si,{delayDuration:0,children:[u.jsx(oi,{asChild:!0,children:u.jsx("button",{type:"button",tabIndex:-1,"aria-label":C.message,className:de("flex size-6 items-center justify-center rounded-md",C.available?"text-success":"text-destructive"),children:C.available?u.jsx(ns,{className:"size-4"}):u.jsx(fm,{className:"size-4"})})}),u.jsx(qr,{children:C.message})]})}):null]})}),u.jsx("div",{className:"space-y-2",children:u.jsxs("div",{className:"relative",children:[u.jsx(gk,{className:"pointer-events-none absolute left-3 top-3 size-4 text-muted-foreground"}),u.jsx(Vl,{value:_,onChange:U=>w(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"})]})}),u.jsx("div",{className:"space-y-2",children:u.jsxs(Lo,{value:b,onValueChange:U=>y(U),children:[u.jsx(Xs,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:u.jsx(Sa,{placeholder:"Select visibility"})}),u.jsxs(Qs,{children:[u.jsx(ti,{value:"private",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(PG,{className:"size-4 text-muted-foreground"}),u.jsx("span",{className:"pl-[1px]",children:"Private"})]})}),u.jsx(ti,{value:"public",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(xG,{className:"size-4 text-muted-foreground"}),u.jsx("span",{className:"pl-[1px]",children:"Public"})]})})]})]})})]})]}),u.jsxs(Kl,{children:[u.jsx(De,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),u.jsx(De,{size:"sm",disabled:!I,onClick:()=>void j(),children:R?u.jsxs(u.Fragment,{children:[u.jsx(_n,{className:"mr-1.5 size-3.5 animate-spin"}),"Publishing…"]}):"Push to GitHub"})]})]})})}function pF({value:e,onChange:t,placeholder:n,disabled:r,trailingAction:i}){return u.jsxs("div",{className:"relative",children:[u.jsx(qf,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),u.jsx(mn,{value:e,onChange:s=>t(s.target.value),placeholder:n,className:de("h-9 pl-7 text-sm",i?"pr-14":void 0),disabled:r}),i?u.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2",children:i}):null]})}function Fc({title:e,entries:t,emptyLabel:n,selectedName:r,disabled:i,stickyTitle:s=!1,onSelect:o}){return t.length===0&&!n?null:u.jsxs("div",{className:"space-y-1",children:[u.jsx("div",{className:de("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?u.jsx("div",{className:"px-1 py-1 text-xs text-muted-foreground",children:n}):t.map(a=>{const c=r===a.name;return u.jsxs("button",{type:"button",disabled:i,onClick:()=>o(a),className:de("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:[a.kind==="pull_request"?u.jsx(W5,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):u.jsx(Ea,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsxs("div",{className:"flex w-full items-center gap-3",children:[u.jsx("div",{className:"min-w-0 flex-1 overflow-hidden whitespace-nowrap text-sm text-foreground",children:a.displayName}),a.updatedAt?u.jsx("div",{className:"ml-auto shrink-0 text-right text-[11px] text-muted-foreground",children:g2(a.updatedAt)}):null]}),a.kind==="pull_request"&&a.description||a.headLabel?u.jsx("div",{className:"truncate text-xs text-muted-foreground",children:a.kind==="pull_request"?a.description??a.headLabel??a.name:a.headLabel??void 0}):null]})]},a.id)})]})}function Kbe({open:e,onOpenChange:t,branchList:n,currentBranchName:r,onPreviewMergeBranch:i,onMergeBranch:s}){const[o,a]=v.useState(""),[c,d]=v.useState(null),[f,m]=v.useState(null),[g,b]=v.useState(null),[y,_]=v.useState(!1),[w,C]=v.useState(!1),E=v.useMemo(()=>n?Gbe(n,r):{defaultBranch:void 0,recent:[],other:[]},[n,r]),k=o.trim().toLowerCase(),T=v.useCallback(D=>k?[D.displayName,D.name,D.description,D.prTitle,D.headLabel].some(z=>z==null?void 0:z.toLowerCase().includes(k)):!0,[k]),R=E.defaultBranch&&T(E.defaultBranch)?E.defaultBranch:void 0,A=E.recent.filter(T),j=E.other.filter(T),I=v.useMemo(()=>c?[E.defaultBranch,...E.recent,...E.other].find(D=>D!==void 0&&D.name===c)??null:null,[E.defaultBranch,E.other,E.recent,c]);v.useEffect(()=>{e||(a(""),d(null),m(null),b(null),_(!1),C(!1))},[e]),v.useEffect(()=>{if(!e||!I){m(null),b(null),_(!1);return}let D=!1;return m(null),b(null),_(!0),i(I).then(z=>{D||m(z)}).catch(z=>{D||b(z instanceof Error?z.message:String(z))}).finally(()=>{D||_(!1)}),()=>{D=!0}},[i,e,I]);const U=!I||!f||y||w||f.status!=="mergeable";async function M(){if(!(!I||U)){C(!0);try{const D=await s(I);D!=null&&D.ok&&t(!1)}finally{C(!1)}}}return u.jsx(so,{open:e,onOpenChange:t,children:u.jsxs(As,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[u.jsxs(Ho,{className:"flex min-h-0 flex-col gap-3 px-4 pb-4 pt-4",children:[u.jsxs("div",{className:"space-y-1",children:[u.jsxs(oo,{children:["Merge into ",r??"current branch"]}),u.jsx(np,{children:"Choose a branch to continue."})]}),u.jsx(pF,{value:o,onChange:a,placeholder:"Search branches"}),u.jsxs("div",{className:"max-h-[375px] space-y-3 overflow-y-auto pr-1",children:[u.jsx(Fc,{title:"Default Branch",entries:R?[R]:[],emptyLabel:"No default branch available.",selectedName:c,onSelect:D=>d(D.name)}),u.jsx(Fc,{title:"Recent Branches",entries:A,emptyLabel:"No recent branches.",selectedName:c,onSelect:D=>d(D.name)}),u.jsx(Fc,{title:"Other Branches",entries:j,emptyLabel:"No other branches match this search.",selectedName:c,onSelect:D=>d(D.name)})]}),u.jsx("div",{className:"px-2",children:I?y?u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(_n,{className:"size-3.5 animate-spin"}),u.jsx("span",{children:"Checking merge preview…"})]}):g?u.jsx("div",{className:"text-sm text-destructive",children:g}):f?u.jsxs("div",{className:"flex items-start gap-2",children:[f.status==="up_to_date"?u.jsx(ns,{className:"mt-1 size-3.5 shrink-0 text-success"}):f.status==="conflicts"?u.jsx(fm,{className:"mt-1 size-3.5 shrink-0 text-warning"}):f.status==="mergeable"?u.jsx(V5,{className:"mt-1 size-3.5 shrink-0 text-muted-foreground"}):u.jsx(fm,{className:"mt-1 size-3.5 shrink-0 text-destructive"}),u.jsxs("div",{className:"min-w-0 space-y-1",children:[u.jsx("div",{className:"text-sm font-medium text-foreground",children:f.message}),f.detail?u.jsx("div",{className:"line-clamp-2 whitespace-pre-wrap text-xs text-muted-foreground",children:f.detail}):null]})]}):u.jsx("div",{className:"text-sm text-muted-foreground",children:"Preview unavailable."}):u.jsx("div",{className:"text-sm text-muted-foreground",children:"Select a branch to preview the merge."})})]}),u.jsx(Kl,{children:u.jsxs("div",{className:"flex min-w-0 w-full items-center justify-end gap-2",children:[u.jsx(De,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),u.jsx(De,{className:"max-w-full min-w-0",size:"sm",disabled:U,onClick:()=>void M(),children:w?u.jsxs(u.Fragment,{children:[u.jsx(_n,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),"Merging…"]}):u.jsx("span",{className:"block max-w-full truncate",children:"Merge"})})]})})]})})}function Ybe({currentBranchName:e,onListBranches:t,onPreviewMergeBranch:n,onMergeBranch:r,onCheckoutBranch:i,onCreateBranch:s}){const[o,a]=v.useState(!1),[c,d]=v.useState(!1),[f,m]=v.useState(!1),[g,b]=v.useState(!1),[y,_]=v.useState(""),[w,C]=v.useState("branches"),[E,k]=v.useState(null),[T,R]=v.useState(null);v.useEffect(()=>{o&&(m(!0),R(null),t().then(W=>k(W)).catch(W=>{R(W instanceof Error?W.message:String(W))}).finally(()=>{m(!1)}))},[t,o]);const A=y.trim().toLowerCase(),j=W=>W.filter(te=>A?[te.displayName,te.name,te.description,te.prTitle,te.headLabel].some(O=>O==null?void 0:O.toLowerCase().includes(A)):!0),I=(E==null?void 0:E.currentBranchName)??e,U=new Set(((E==null?void 0:E.pullRequests)??[]).map(W=>W.headRefName??W.name)),M=j((E==null?void 0:E.recent)??[]).filter(W=>W.name!==I),D=j((E==null?void 0:E.local)??[]).filter(W=>W.name!==I),z=j((E==null?void 0:E.remote)??[]).filter(W=>W.name!==I&&!U.has(W.name)),P=j((E==null?void 0:E.pullRequests)??[]).filter(W=>W.name!==I),F=(E==null?void 0:E.pullRequests.length)??0;async function $(W){b(!0);try{await i(W),a(!1),_(""),C("branches")}finally{b(!1)}}async function B(){b(!0);try{await s(),a(!1),_(""),C("branches")}finally{b(!1)}}function H(){a(!1),d(!0)}return u.jsxs(dp,{open:o,onOpenChange:a,children:[u.jsx(hp,{asChild:!0,children:u.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:[u.jsx(Ea,{className:"h-3.5 w-3.5 shrink-0"}),u.jsx("span",{className:"truncate",children:e??"Detached HEAD"}),u.jsx(sh,{className:"h-3.5 w-3.5 shrink-0"})]})}),u.jsx(dh,{align:"start",className:"w-[320px] p-2",children:u.jsxs("div",{className:"space-y-2",children:[u.jsx(pF,{value:y,onChange:_,placeholder:w==="pull_requests"?"Search pull requests":"Search branches",disabled:f||g,trailingAction:u.jsx(De,{variant:"ghost",size:"sm",onClick:()=>void B(),disabled:f||g,className:"h-7 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:"+ New"})}),u.jsx(Ii,{value:w,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}`}]}),u.jsx("div",{className:"max-h-[420px] overflow-y-auto pr-1.5 -mr-[8px]",children:f?u.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[u.jsx(_n,{className:"h-4 w-4 animate-spin"}),u.jsx("span",{children:"Loading branches…"})]}):T?u.jsx("div",{className:"rounded-lg border border-border px-3 py-2 text-sm text-muted-foreground",children:T}):w==="pull_requests"?u.jsx(Fc,{title:"Open PRs",entries:P,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=>{$(W)}}):u.jsxs("div",{className:"space-y-3",children:[u.jsx(Fc,{title:"Recent",entries:M,emptyLabel:"No recent branches.",disabled:g,stickyTitle:!0,onSelect:W=>{$(W)}}),u.jsx(Fc,{title:"Local",entries:D,emptyLabel:"No local branches.",disabled:g,stickyTitle:!0,onSelect:W=>{$(W)}}),u.jsx(Fc,{title:"Remote",entries:z,emptyLabel:"No remote branches.",disabled:g,stickyTitle:!0,onSelect:W=>{$(W)}})]})}),I?u.jsx(De,{variant:"default",size:"sm",disabled:f||g||!!T,onClick:H,className:"h-9 w-full justify-center rounded-lg px-3 text-sm",children:u.jsxs("span",{className:"block max-w-full truncate",children:[u.jsx(mG,{className:"mr-1.5 inline h-3.5 w-3.5 shrink-0"}),"Merge branch into ",I,"..."]})}):null]})}),u.jsx(Kbe,{open:c,onOpenChange:d,branchList:E,currentBranchName:I,onPreviewMergeBranch:n,onMergeBranch:r})]})}function Xbe({file:e,rootRef:t,projectId:n,isCollapsed:r,isChecked:i,editorLabel:s,diffRenderMode:o,wrapLines:a,onToggleCollapsed:c,onToggleChecked:d,fileActions:f,patch:m,patchError:g,isPatchLoading:b,onLoadPatch:y}){const _=fF(e),w=Hbe(e),[C,E]=v.useState(null),k=v.useRef(null),T=v.useRef(null),{sentinelRef:R,isStuck:A}=gde({rootRef:t,disabled:r}),j=v.useMemo(()=>$be(n,e),[e,n]),I=j!==null,U=AI({isCollapsed:r,hasPreviewAttachment:I,patch:m,patchError:g,isPatchLoading:b});v.useEffect(()=>{if(!U)return;const P=`${e.path}\0${e.patchDigest}`;T.current!==P&&(T.current=P,y(e.path).catch(()=>{}))},[e.patchDigest,e.path,y,U]);function M(P){if(_h(P).openInNewTab){typeof window<"u"&&window.open(new URL(P.contentUrl,window.location.origin).toString(),"_blank","noopener,noreferrer");return}E(P.id)}function D(P){var $;P.preventDefault(),P.stopPropagation();const F=P.currentTarget.getBoundingClientRect();($=k.current)==null||$.dispatchEvent(new MouseEvent("contextmenu",{bubbles:!0,cancelable:!0,clientX:F.left+F.width/2,clientY:F.bottom,view:window}))}function z(){if(!r){c();return}if(I||m!==void 0){c();return}if(b)return;if(!(g!==void 0||AI({isCollapsed:!1,hasPreviewAttachment:I,patch:m,patchError:g,isPatchLoading:b}))){c();return}y(e.path).then(()=>{c()}).catch(()=>{})}return u.jsxs(fu,{children:[u.jsx(mu,{asChild:!0,children:u.jsxs("div",{ref:k,className:"relative rounded-lg border border-border bg-background",children:[r?null:u.jsx("div",{ref:R,className:"pointer-events-none absolute inset-x-0 top-0 h-px","aria-hidden":"true"}),u.jsxs("div",{role:"button",tabIndex:0,onClick:z,onKeyDown:P=>{P.key!=="Enter"&&P.key!==" "||(P.preventDefault(),z())},className:de("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&&!A&&"rounded-t-[calc(theme(borderRadius.lg)-1px)]",r&&"rounded-[calc(theme(borderRadius.lg)-1px)]",!r&&"border-b border-border/50"),children:[u.jsxs("div",{className:"flex min-w-0 items-center",children:[u.jsx(mF,{checked:i,onClick:d}),u.jsx("div",{className:"min-w-0 truncate select-none ml-2 mr-1",children:e.path})]}),u.jsxs("div",{className:"flex shrink-0 items-center gap-2 select-none",children:[u.jsxs("span",{className:"whitespace-nowrap text-xs font-mono",children:[e.additions>0?u.jsxs("span",{className:"text-success",children:["+",e.additions]}):null,e.deletions>0?u.jsxs("span",{className:e.additions>0?"ml-2 text-destructive":"text-destructive",children:["-",e.deletions]}):null]}),u.jsx("button",{type:"button","aria-label":`Open actions for ${e.path}`,onClick:D,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:u.jsx(hm,{className:"h-3.5 w-3.5 shrink-0"})}),b&&r&&!j?u.jsx(_n,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):r?u.jsx(sh,{className:"h-3.5 w-3.5 shrink-0"}):u.jsx(B5,{className:"h-3.5 w-3.5 shrink-0"})]})]}),r?null:u.jsx("div",{className:"kanna-diff-patch overflow-hidden rounded-b-[calc(theme(borderRadius.lg)-1px)] pb-[1px]",children:j?u.jsx("div",{className:"flex justify-center p-3",children:j.kind==="image"?u.jsx(p2,{attachment:j,onClick:()=>M(j)}):u.jsx(Fo,{attachment:j,onClick:()=>M(j)})}):b?u.jsxs("div",{className:"flex items-center justify-center px-3 py-8 text-sm text-muted-foreground",children:[u.jsx(_n,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading diff..."]}):g?u.jsx("div",{className:"px-3 py-4 text-sm text-destructive",children:g}):m!==void 0?u.jsx(mde,{patch:m,options:{diffStyle:o,disableFileHeader:!0,disableBackground:!1,overflow:a?"wrap":"scroll",lineDiffType:"word",diffIndicators:"classic"}}):u.jsx("div",{className:"px-3 py-4 text-sm text-muted-foreground",children:"Diff unavailable."})}),u.jsx(Ch,{source:j&&C===j.id?Cp(j,"user_attachment"):null,open:j!==null&&C===j.id,onOpenChange:P=>!P&&E(null)})]},e.path)}),u.jsxs(ec,{children:[u.jsxs(Pn,{onSelect:P=>{P.stopPropagation(),f.onOpenFile(e.path)},children:[u.jsx(mk,{className:"h-3.5 w-3.5"}),u.jsxs("span",{className:"text-xs font-medium",children:["Open in ",s]})]}),u.jsxs(Pn,{onSelect:P=>{P.stopPropagation(),f.onOpenInFinder(e.path)},children:[u.jsx(Ex,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),u.jsxs(Pn,{onSelect:P=>{P.stopPropagation(),f.onDiscardFile(e.path)},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[u.jsx(cu,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Discard Changes"})]}),u.jsxs(Pn,{disabled:!_,onSelect:P=>{P.stopPropagation(),_&&f.onIgnoreFile(e.path)},children:[u.jsx(ZA,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Ignore File"})]}),u.jsxs(Pn,{disabled:!w,onSelect:P=>{P.stopPropagation(),w&&f.onIgnoreFolder(e.path)},children:[u.jsx(ZA,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Ignore folder..."})]}),u.jsx(T4,{}),u.jsxs(Pn,{onSelect:P=>{P.stopPropagation(),f.onCopyFilePath(e.path)},children:[u.jsx(La,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Copy File Path"})]}),u.jsxs(Pn,{onSelect:P=>{P.stopPropagation(),f.onCopyRelativePath(e.path)},children:[u.jsx(La,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Copy Relative Path"})]})]})]})}function Qbe({projectId:e,diffs:t,editorLabel:n,diffRenderMode:r,wrapLines:i,onOpenFile:s,onOpenInFinder:o,onDiscardFile:a,onIgnoreFile:c,onIgnoreFolder:d,onCopyFilePath:f,onCopyRelativePath:m,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:y,onCheckoutBranch:_,onCreateBranch:w,onGenerateCommitMessage:C,onInitializeGit:E,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:T,onSetupGitHub:R,onCommit:A,onSyncWithRemote:j,onLoadPatch:I,onDiffRenderModeChange:U,onWrapLinesChange:M}){var Je;const D=v.useMemo(()=>({onOpenFile:s,onOpenInFinder:o,onDiscardFile:a,onIgnoreFile:c,onIgnoreFolder:d,onCopyFilePath:f,onCopyRelativePath:m}),[s,o,a,c,d,f,m]),z=t.files.length>0,[P,F]=v.useState(!1),[$,B]=v.useState(null),[H,W]=v.useState(!1),[te,O]=v.useState(!1),[K,ee]=v.useState({}),[V,ue]=v.useState({}),[ge,Z]=v.useState({}),ne=v.useRef(null),ie=v.useRef({}),le=v.useMemo(()=>t.files.map(xe=>xe.path),[t.files]),oe=v.useMemo(()=>le.join("\0"),[le]),we=Li(xe=>{var Pe;return e?((Pe=xe.projectUi[e])==null?void 0:Pe.viewMode)??(z?"changes":"history"):z?"changes":"history"}),Ce=Li(xe=>{var Pe;return e?((Pe=xe.projectUi[e])==null?void 0:Pe.collapsedPaths)??Cv:Cv}),Oe=Li(xe=>{var Pe;return e?((Pe=xe.projectUi[e])==null?void 0:Pe.summary)??"":""}),Ze=Li(xe=>{var Pe;return e?((Pe=xe.projectUi[e])==null?void 0:Pe.description)??"":""}),ft=Li(xe=>xe.reconcileCollapsedPaths),Tt=Li(xe=>xe.toggleCollapsedPath),_e=Li(xe=>xe.setViewMode),cn=Li(xe=>xe.setCommitDraft),Lt=Li(xe=>xe.clearCommitDraft),pt=gv(xe=>e?xe.checkedPathsByProjectId[e]??Cv:Cv),xt=gv(xe=>xe.reconcileProject),Bt=gv(xe=>xe.setChecked),Dt=gv(xe=>xe.setAllChecked),lt=v.useRef(z);v.useEffect(()=>{e&&ft(e,le)},[le,oe,e,ft]),v.useEffect(()=>{const xe=Object.fromEntries(t.files.map(Ue=>[Ue.path,Ue.patchDigest])),Pe=Ue=>ie.current[Ue]===xe[Ue];ee(Ue=>Object.fromEntries(Object.entries(Ue).filter(([Ve])=>le.includes(Ve)&&Pe(Ve)))),ue(Ue=>Object.fromEntries(Object.entries(Ue).filter(([Ve])=>le.includes(Ve)&&Pe(Ve)))),Z(Ue=>Object.fromEntries(Object.entries(Ue).filter(([Ve])=>le.includes(Ve)&&Pe(Ve)))),ie.current=xe},[t.files,le,oe]),v.useEffect(()=>{e&&xt(e,le)},[le,oe,e,xt]),v.useEffect(()=>{if(!e)return;if(lt.current!==z){_e(e,z?"changes":"history"),lt.current=z;return}lt.current=z},[z,e,_e]);const Ot=v.useMemo(()=>t.files.filter(xe=>pt[xe.path]??!0).map(xe=>xe.path),[pt,t.files]),me=Ot.length,Te=t.files.length>0&&me===t.files.length,He=me>0&&me<t.files.length,tt=Oe.trim(),Xe=tt.length>0,yt=$!==null,ze=P||yt,Ke=((Je=t.branchHistory)==null?void 0:Je.entries)??[],Be=t.behindCount??0,Ie=t.aheadCount??0,qe=t.hasUpstream===!0,It=t.hasUpstream===!1&&!!t.branchName,Rt=t.hasOriginRemote===!0,xn=t.branchName?t.branchName.split("/").map(xe=>encodeURIComponent(xe)).join("/"):null,on=It?"publish":Be>0?"pull":"fetch",Zt=t.originRepoSlug&&xn?`https://github.com/${t.originRepoSlug}/compare/${xn}?expand=1`:null,At=!!(qe&&Zt&&t.branchName&&t.branchName!==t.defaultBranchName),_t=t.status==="ready"&&me>0&&!ze,gt=t.status==="ready"&&me>0&&Xe&&!ze,Ct=Rt?"commit_and_push":"commit_only",vt=t.branchName??"current branch";async function Ut(xe){if(gt){B(xe);try{const Pe=await A({paths:Ot,summary:tt,description:Ze.trim(),mode:xe});(Pe!=null&&Pe.ok||Pe!=null&&Pe.localCommitCreated)&&e&&Lt(e)}finally{B(null)}}}async function it(){if(_t){F(!0);try{const xe=await C({paths:Ot});e&&cn(e,{summary:xe.subject,description:xe.body})}finally{F(!1)}}}function ye(xe){if(!(!(xe.metaKey||xe.ctrlKey)||xe.key!=="Enter")){if(xe.preventDefault(),Xe){Ut(Ct);return}it()}}async function rt(xe=on){if(!(t.status!=="ready"||H)){W(!0);try{await j(xe)}finally{W(!1)}}}const Ye=v.useCallback(async xe=>{var Pe;if(K[xe]!==void 0||ge[xe])return K[xe]??"";Z(Ue=>({...Ue,[xe]:!0})),ue(Ue=>{if(!(xe in Ue))return Ue;const{[xe]:Ve,...Wt}=Ue;return Wt});try{const Ue=await I(xe);ee(Wt=>({...Wt,[xe]:Ue}));const Ve=(Pe=t.files.find(Wt=>Wt.path===xe))==null?void 0:Pe.patchDigest;return Ve&&(ie.current={...ie.current,[xe]:Ve}),Ue}catch(Ue){const Ve=Ue instanceof Error?Ue.message:String(Ue);throw ue(Wt=>({...Wt,[xe]:Ve})),Ue}finally{Z(Ue=>{const{[xe]:Ve,...Wt}=Ue;return Wt})}},[t.files,ge,I,K]);return u.jsx("div",{className:"h-full min-h-0 border-l border-border bg-background md:min-w-[370px]",children:u.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[u.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pl-2.5 pr-2 py-2",children:[u.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:u.jsx(Ybe,{currentBranchName:t.branchName,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:y,onCheckoutBranch:_,onCreateBranch:w})}),t.status==="ready"?Rt?on==="publish"?u.jsxs(De,{variant:"ghost",size:"sm",onClick:()=>void rt(),disabled:H,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[H?u.jsx(_n,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(Yv,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Publish Branch"})]}):u.jsxs("div",{className:"flex items-center gap-1",children:[on==="fetch"?u.jsxs(si,{delayDuration:0,children:[u.jsx(oi,{asChild:!0,children:u.jsxs(De,{variant:"ghost",size:"sm",onClick:()=>void rt(),disabled:H,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[H?u.jsx(_n,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(X5,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Fetch"})]})}),u.jsx(qr,{children:Ube(t.lastFetchedAt)})]}):u.jsxs(De,{variant:"ghost",size:"sm",onClick:()=>void rt(),disabled:H,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[H?u.jsx(_n,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(pk,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Pull"}),u.jsx("span",{className:"inline-flex min-w-4 items-center justify-center rounded-full bg-muted px-1 text-[10px] text-muted-foreground",children:Be})]}),qe&&Ie>0?u.jsxs(De,{variant:"default",size:"sm",onClick:()=>void rt("push"),disabled:H,className:"h-7 gap-1.5 px-2 text-xs",children:[H?u.jsx(_n,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(Yv,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Push"}),u.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:Ie})]}):null,At&&Zt?u.jsxs(De,{variant:"ghost",size:"sm",onClick:()=>{typeof window>"u"||window.open(Zt,"_blank","noopener,noreferrer")},className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[u.jsx(W5,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"PR"})]}):null]}):u.jsxs(De,{variant:"default",size:"sm",onClick:()=>O(!0),className:"h-7 gap-1.5 px-3 text-xs",children:[u.jsx(vG,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Push to GitHub"})]}):null]}),u.jsxs("div",{className:"relative min-h-0 flex-1",children:[u.jsx("div",{className:"sticky top-0 z-30 pl-[14px] pr-[12px] pt-[6px] bg-gradient-to-b from-background to-transparent",children:u.jsx("div",{className:"relative h-[40px] flex min-w-0 items-center justify-center gap-[13px]",children:u.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-[13px] relative",children:[we==="changes"?u.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground/70",children:[u.jsx(mF,{checked:Te,mixed:He,label:He?"Select all files for commit":Te?"Unselect all files from commit":"Select all files for commit",onClick:()=>{!e||t.files.length===0||Dt(e,le,He?!0:!Te)}}),u.jsxs("span",{children:[me," files"]})]}):u.jsx("div",{}),u.jsx("div",{className:"pointer-events-none absolute left-1/2 -translate-x-1/2 top-1/2 -translate-y-1/2",children:u.jsx("div",{className:"pointer-events-auto",children:u.jsx(Ii,{value:we,onValueChange:xe=>{e&&_e(e,xe)},size:"sm",optionClassName:"flex-1 justify-center",options:[{value:"changes",label:"Changes"},{value:"history",label:"History"}]})})}),we==="changes"?u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(Jw,{label:"Unified diff",active:r==="unified",onClick:()=>U("unified"),children:u.jsx(xq,{className:"h-4 w-4"})}),u.jsx(Jw,{label:"Side-by-side diff",active:r==="split",onClick:()=>U("split"),children:u.jsx(SW,{className:"h-4 w-4"})}),u.jsx(Jw,{label:i?"Disable word wrap":"Enable word wrap",active:i,onClick:()=>M(!i),children:u.jsx(Yq,{className:"h-4 w-4"})})]}):u.jsx("div",{})]})})}),u.jsx("div",{ref:ne,className:"h-full overflow-y-auto [scrollbar-gutter:stable]",children:t.status==="no_repo"?u.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:u.jsxs("div",{className:"flex max-w-[280px] flex-col items-center gap-3",children:[u.jsx("p",{className:"text-sm text-muted-foreground",children:"Initialize git here to start tracking branches, diffs, and history."}),u.jsx(De,{size:"sm",onClick:()=>void E(),children:"Init Git"})]})}):we==="history"?Ke.length===0?u.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:u.jsxs("p",{className:"text-sm text-muted-foreground",children:["No recent commits on ",t.branchName??"this branch","."]})}):u.jsx("div",{className:"space-y-1.5 p-1.5",children:Ke.map((xe,Pe)=>u.jsx(Vbe,{entry:xe,isPendingPush:Pe<Ie},xe.sha))}):t.files.length===0?u.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:u.jsx("p",{className:"text-sm text-muted-foreground",children:"No file changes."})}):u.jsxs("div",{className:"space-y-1.5 p-1.5 pb-10",children:[t.files.map(xe=>{const Pe=Ce[xe.path]??!0,Ue=pt[xe.path]??!0;return u.jsx(Xbe,{file:xe,rootRef:ne,projectId:e,isCollapsed:Pe,isChecked:Ue,editorLabel:n,diffRenderMode:r,wrapLines:i,onToggleCollapsed:()=>{e&&Tt(e,xe.path)},onToggleChecked:()=>{e&&Bt(e,xe.path,!Ue)},fileActions:D,patch:K[xe.path],patchError:V[xe.path],isPatchLoading:!!ge[xe.path],onLoadPatch:Ye},xe.path)}),we==="changes"?u.jsxs("div",{className:"pointer-events-none sticky inset-x-0 bottom-11 py-1 pb-6 z-30 overflow-y-auto",children:[u.jsx("div",{className:"absolute inset-x-0 bottom-0 top-0 bg-gradient-to-t from-background to-transparent"}),u.jsx("div",{className:"pointer-events-auto relative",children:u.jsxs("div",{className:"space-y-0 rounded-xl mx-auto max-w-[700px]",children:[u.jsx(mn,{value:Oe,onChange:xe=>{e&&cn(e,{summary:xe.target.value,description:Ze})},onKeyDown:ye,placeholder:"Commit message (override)",className:"rounded-t-xl rounded-b-none px-3",disabled:ze||t.status!=="ready"}),u.jsx(Vl,{value:Ze,onChange:xe=>{e&&cn(e,{summary:Oe,description:xe.target.value})},onKeyDown:ye,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:ze||t.status!=="ready"}),u.jsx("div",{className:"w-full flex flex-row",children:u.jsxs(fu,{children:[u.jsx(mu,{asChild:!0,children:u.jsx(De,{type:"button",className:"-mt-px w-full rounded-xl",disabled:Xe?!gt:!_t,onClick:()=>{if(Xe){Ut(Ct);return}it()},children:u.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[Xe?yt?u.jsx(_n,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):Ct==="commit_and_push"?t.hasUpstream?u.jsx(Yv,{strokeWidth:2.5,className:"size-3 shrink-0"}):u.jsx(V5,{strokeWidth:2.5,className:"size-3 shrink-0"}):u.jsx(ns,{strokeWidth:2.5,className:"size-3 shrink-0"}):P?u.jsx(_n,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):u.jsx(tq,{strokeWidth:2.5,className:"size-3 shrink-0"}),u.jsx("span",{className:"min-w-0 truncate text-left",children:Xe?yt?$==="commit_only"?"Committing...":"Committing & Pushing...":Ct==="commit_only"?u.jsxs(u.Fragment,{children:["Commit to ",u.jsx(Ea,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),vt]}):t.hasUpstream?u.jsxs(u.Fragment,{children:["Commit & push to ",u.jsx(Ea,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),vt]}):u.jsxs(u.Fragment,{children:["Commit & publish ",u.jsx(Ea,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),vt]}):P?"Generating...":u.jsxs(u.Fragment,{children:["Generate message for ",u.jsx(Ea,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),vt]})})]})})}),t.hasUpstream?u.jsx(ec,{children:u.jsx(Pn,{disabled:!Xe||!gt,onSelect:xe=>{xe.stopPropagation(),Ut("commit_only")},children:"Commit Only"})}):null]})})]})})]}):null]})})]}),u.jsx(qbe,{open:te,onOpenChange:O,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:T,onPublish:R})]})})}const Zbe=v.memo(Qbe);function Jbe(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function exe(e,t){const n=getComputedStyle(e.ownerDocument.body),r=parseFloat(n.fontSize);return t*r}function txe(e){return e/100*window.innerHeight}function nxe(e){return e/100*window.innerWidth}function rxe(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 Ff({groupSize:e,panelElement:t,styleProp:n}){let r;const[i,s]=rxe(n);switch(s){case"%":{r=i/100*e;break}case"px":{r=i;break}case"rem":{r=exe(t,i);break}case"em":{r=Jbe(t,i);break}case"vh":{r=txe(i);break}case"vw":{r=nxe(i);break}}return r}function Pi(e){return parseFloat(e.toFixed(3))}function Yd({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 sC(e){const{panels:t}=e,n=Yd({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 f=Ff({groupSize:n,panelElement:i,styleProp:s.collapsedSize});o=Pi(f/n*100)}let a;if(s.defaultSize!==void 0){const f=Ff({groupSize:n,panelElement:i,styleProp:s.defaultSize});a=Pi(f/n*100)}let c=0;if(s.minSize!==void 0){const f=Ff({groupSize:n,panelElement:i,styleProp:s.minSize});c=Pi(f/n*100)}let d=100;if(s.maxSize!==void 0){const f=Ff({groupSize:n,panelElement:i,styleProp:s.maxSize});d=Pi(f/n*100)}return{groupResizeBehavior:s.groupResizeBehavior,collapsedSize:o,collapsible:s.collapsible===!0,defaultSize:a,disabled:s.disabled,minSize:c,maxSize:d,panelId:r.id}})}function jn(e,t="Assertion error"){if(!e)throw Error(t)}function oC(e,t){return Array.from(t).sort(e==="horizontal"?ixe:sxe)}function ixe(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function sxe(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function gF(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function vF(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 oxe({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:a,y:c}=vF(r,o),d=e==="horizontal"?a:c;d<s&&(s=d,i=o)}return jn(i,"No rect found"),i}let kv;function axe(){return kv===void 0&&(typeof matchMedia=="function"?kv=!!matchMedia("(pointer:coarse)").matches:kv=!1),kv}function bF(e){const{element:t,orientation:n,panels:r,separators:i}=e,s=oC(n,Array.from(t.children).filter(gF).map(y=>({element:y}))).map(({element:y})=>y),o=[];let a=!1,c=!1,d=-1,f=-1,m=0,g,b=[];{let y=-1;for(const _ of s)_.hasAttribute("data-panel")&&(y++,_.ariaDisabled===null&&(m++,d===-1&&(d=y),f=y))}if(m>1){let y=-1;for(const _ of s)if(_.hasAttribute("data-panel")){y++;const w=r.find(C=>C.element===_);if(w){if(g){const C=g.element.getBoundingClientRect(),E=_.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),R=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,R];break}case 1:{const A=b[0],j=oxe({orientation:n,rects:[C,E],targetRect:A.element.getBoundingClientRect()});k=[A,j===C?R: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 R="width"in T?T:T.element.getBoundingClientRect();const A=axe()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(R.width<A){const I=A-R.width;R=new DOMRect(R.x-I/2,R.y,R.width+I,R.height)}if(R.height<A){const I=A-R.height;R=new DOMRect(R.x,R.y-I/2,R.width,R.height+I)}const j=y<=d||y>f;!a&&!j&&o.push({group:e,groupSize:Yd({group:e}),panels:[g,w],separator:"width"in T?void 0:T,rect:R}),a=!1}}c=!1,g=w,b=[]}}else if(_.hasAttribute("data-separator")){_.ariaDisabled!==null&&(a=!0);const w=i.find(C=>C.element===_);w?b.push(w):(g=void 0,b=[])}else c=!0}return o}var zl,f5;let xF=(f5=class{constructor(){_l(this,zl,{})}addListener(t,n){const r=vr(this,zl)[t];return r===void 0?vr(this,zl)[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=vr(this,zl)[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 a=0;a<o.length;a++){const c=o[a];try{c.call(null,n)}catch(d){s===null&&(i=!0,s=d)}}if(i)throw s}}removeAllListeners(){gs(this,zl,{})}removeListener(t,n){const r=vr(this,zl)[t];if(r!==void 0){const i=r.indexOf(n);i>=0&&r.splice(i,1)}}},zl=new WeakMap,f5),Po=new Map;const yF=new xF;function lxe(e){Po=new Map(Po),Po.delete(e)}function MI(e,t){for(const[n]of Po)if(n.id===e)return n}function Wl(e,t){for(const[n,r]of Po)if(n.id===e)return r;if(t)throw Error(`Could not find data for Group with id ${e}`)}function gu(){return Po}function v2(e,t){return yF.addListener("groupChange",n=>{n.group.id===e&&t(n)})}function Fa(e,t){const n=Po.get(e);Po=new Map(Po),Po.set(e,t),yF.emit("groupChange",{group:e,prev:n,next:t})}function cxe(e,t,n){let r,i={x:1/0,y:1/0};for(const s of t){const o=vF(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 uxe(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function dxe(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:DI(e),b:DI(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();jn(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:II(LI(n.a)),b:II(LI(n.b))};if(i.a===i.b){const s=r.childNodes,o={a:n.a.at(-1),b:n.b.at(-1)};let a=s.length;for(;a--;){const c=s[a];if(c===o.a)return 1;if(c===o.b)return-1}}return Math.sign(i.a-i.b)}const hxe=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function fxe(e){const t=getComputedStyle(_F(e)??e).display;return t==="flex"||t==="inline-flex"}function mxe(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||fxe(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"||hxe.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function LI(e){let t=e.length;for(;t--;){const n=e[t];if(jn(n,"Missing node"),mxe(n))return n}return null}function II(e){return e&&Number(getComputedStyle(e).zIndex)||0}function DI(e){const t=[];for(;e;)t.push(e),e=_F(e);return t}function _F(e){const{parentNode:t}=e;return uxe(t)?t.host:t}function pxe(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 gxe({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!gF(n)||n.contains(e)||e.contains(n))return!0;if(dxe(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(pxe(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function b2(e,t){const n=[];return t.forEach((r,i)=>{if(i.disabled)return;const s=bF(i),o=cxe(i.orientation,s,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&gxe({groupElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&n.push(o.hitRegion)}),n}function vxe(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 pi(e,t,n=0){return Math.abs(Pi(e)-Pi(t))<=n}function Ro(e,t){return pi(e,t)?0:e>t?1:-1}function wd({overrideDisabledPanels:e,panelConstraints:t,prevSize:n,size:r}){const{collapsedSize:i=0,collapsible:s,disabled:o,maxSize:a=100,minSize:c=0}=t;if(o&&!e)return n;if(Ro(r,c)<0)if(s){const d=(i+c)/2;Ro(r,d)<0?r=i:r=c}else r=c;return r=Math.min(a,r),r=Pi(r),r}function $m({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(pi(e,0))return t;const o=s==="imperative-api",a=Object.values(t),c=Object.values(i),d=[...a],[f,m]=r;jn(f!=null,"Invalid first pivot index"),jn(m!=null,"Invalid second pivot index");let g=0;switch(s){case"keyboard":{{const _=e<0?m:f,w=n[_];jn(w,`Panel constraints not found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const T=a[_];if(jn(T!=null,`Previous layout not found for panel index ${_}`),pi(T,C)){const R=k-T;Ro(R,Math.abs(e))>0&&(e=e<0?0-R:R)}}}{const _=e<0?f:m,w=n[_];jn(w,`No panel constraints found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const T=a[_];if(jn(T!=null,`Previous layout not found for panel index ${_}`),pi(T,k)){const R=T-C;Ro(R,Math.abs(e))>0&&(e=e<0?0-R:R)}}}break}default:{const _=e<0?m:f,w=n[_];jn(w,`Panel constraints not found for index ${_}`);const C=a[_],{collapsible:E,collapsedSize:k,minSize:T}=w;if(E&&Ro(C,T)<0)if(e>0){const R=T-k,A=R/2,j=C+e;Ro(j,T)<0&&(e=Ro(e,A)<=0?0:R)}else{const R=T-k,A=100-R/2,j=C-e;Ro(j,T)<0&&(e=Ro(100+e,A)>0?0:-R)}break}}{const _=e<0?1:-1;let w=e<0?m:f,C=0;for(;;){const k=a[w];jn(k!=null,`Previous layout not found for panel index ${w}`);const T=wd({overrideDisabledPanels:o,panelConstraints:n[w],prevSize:k,size:100})-k;if(C+=T,w+=_,w<0||w>=n.length)break}const E=Math.min(Math.abs(e),Math.abs(C));e=e<0?0-E:E}{let _=e<0?f:m;for(;_>=0&&_<n.length;){const w=Math.abs(e)-Math.abs(g),C=a[_];jn(C!=null,`Previous layout not found for panel index ${_}`);const E=C-w,k=wd({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:C,size:E});if(!pi(C,k)&&(g+=C-k,d[_]=k,g.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?_--:_++}}if(vxe(c,d))return i;{const _=e<0?m:f,w=a[_];jn(w!=null,`Previous layout not found for panel index ${_}`);const C=w+g,E=wd({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:w,size:C});if(d[_]=E,!pi(E,C)){let k=C-E,T=e<0?m:f;for(;T>=0&&T<n.length;){const R=d[T];jn(R!=null,`Previous layout not found for panel index ${T}`);const A=R+k,j=wd({overrideDisabledPanels:o,panelConstraints:n[T],prevSize:R,size:A});if(pi(R,j)||(k-=j-R,d[T]=j),pi(k,0))break;e>0?T--:T++}}}const b=Object.values(d).reduce((_,w)=>w+_,0);if(!pi(b,100,.1))return i;const y=Object.keys(i);return d.reduce((_,w,C)=>(_[y[C]]=w,_),{})}function tu(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(t[n]===void 0||Ro(e[n],t[n])!==0)return!1;return!0}function nu({layout:e,panelConstraints:t}){const n=Object.values(e),r=[...n],i=r.reduce((a,c)=>a+c,0);if(r.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${r.map(a=>`${a}%`).join(", ")}`);if(!pi(i,100)&&r.length>0)for(let a=0;a<t.length;a++){const c=r[a];jn(c!=null,`No layout data found for index ${a}`);const d=100/i*c;r[a]=d}let s=0;for(let a=0;a<t.length;a++){const c=n[a];jn(c!=null,`No layout data found for index ${a}`);const d=r[a];jn(d!=null,`No layout data found for index ${a}`);const f=wd({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:c,size:d});d!=f&&(s+=d-f,r[a]=f)}if(!pi(s,0))for(let a=0;a<t.length;a++){const c=r[a];jn(c!=null,`No layout data found for index ${a}`);const d=c+s,f=wd({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:c,size:d});if(c!==f&&(s-=f-c,r[a]=f,pi(s,0)))break}const o=Object.keys(e);return r.reduce((a,c,d)=>(a[o[d]]=c,a),{})}function wF({groupId:e,panelId:t}){const n=()=>{const a=gu();for(const[c,{defaultLayoutDeferred:d,derivedPanelConstraints:f,layout:m,groupSize:g,separatorToPanels:b}]of a)if(c.id===e)return{defaultLayoutDeferred:d,derivedPanelConstraints:f,group:c,groupSize:g,layout:m,separatorToPanels:b};throw Error(`Group ${e} not found`)},r=()=>{const a=n().derivedPanelConstraints.find(c=>c.panelId===t);if(a!==void 0)return a;throw Error(`Panel constraints not found for Panel ${t}`)},i=()=>{const a=n().group.panels.find(c=>c.id===t);if(a!==void 0)return a;throw Error(`Layout not found for Panel ${t}`)},s=()=>{const a=n().layout[t];if(a!==void 0)return a;throw Error(`Layout not found for Panel ${t}`)},o=a=>{const c=s();if(a===c)return;const{defaultLayoutDeferred:d,derivedPanelConstraints:f,group:m,groupSize:g,layout:b,separatorToPanels:y}=n(),_=m.panels.findIndex(k=>k.id===t),w=_===m.panels.length-1,C=$m({delta:w?c-a:a-c,initialLayout:b,panelConstraints:f,pivotIndices:w?[_-1,_]:[_,_+1],prevLayout:b,trigger:"imperative-api"}),E=nu({layout:C,panelConstraints:f});tu(b,E)||Fa(m,{defaultLayoutDeferred:d,derivedPanelConstraints:f,groupSize:g,layout:E,separatorToPanels:y})};return{collapse:()=>{const{collapsible:a,collapsedSize:c}=r(),{mutableValues:d}=i(),f=s();a&&f!==c&&(d.expandToSize=f,o(c))},expand:()=>{const{collapsible:a,collapsedSize:c,minSize:d}=r(),{mutableValues:f}=i(),m=s();if(a&&m===c){let g=f.expandToSize??d;g===0&&(g=1),o(g)}},getSize:()=>{const{group:a}=n(),c=s(),{element:d}=i(),f=a.orientation==="horizontal"?d.offsetWidth:d.offsetHeight;return{asPercentage:c,inPixels:f}},isCollapsed:()=>{const{collapsible:a,collapsedSize:c}=r(),d=s();return a&&pi(c,d)},resize:a=>{const{group:c}=n(),{element:d}=i(),f=Yd({group:c}),m=Ff({groupSize:f,panelElement:d,styleProp:a}),g=Pi(m/f*100);o(g)}}}function PI(e){if(e.defaultPrevented)return;const t=gu();b2(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=wF({groupId:n.group.id,panelId:r.id});s&&i!==void 0&&(s.resize(i),e.preventDefault())}}})}function db(e){const t=gu();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 SF({groupId:e}){const t=()=>{const n=gu();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:a,separatorToPanels:c}=t(),d=nu({layout:n,panelConstraints:i});return r?a:(tu(a,d)||Fa(s,{defaultLayoutDeferred:r,derivedPanelConstraints:i,groupSize:o,layout:d,separatorToPanels:c}),d)}}}function Tc(e,t){const n=db(e),r=Wl(n.id,!0),i=n.separators.find(f=>f.element===e);jn(i,"Matching separator not found");const s=r.separatorToPanels.get(i);jn(s,"Matching panels not found");const o=s.map(f=>n.panels.indexOf(f)),a=SF({groupId:n.id}).getLayout(),c=$m({delta:t,initialLayout:a,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:a,trigger:"keyboard"}),d=nu({layout:c,panelConstraints:r.derivedPanelConstraints});tu(a,d)||Fa(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:d,separatorToPanels:r.separatorToPanels})}function OI(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=db(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&Tc(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&Tc(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&Tc(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&Tc(t,-5);break}case"End":{e.preventDefault(),Tc(t,100);break}case"Enter":{e.preventDefault();const r=db(t),i=Wl(r.id,!0),{derivedPanelConstraints:s,layout:o,separatorToPanels:a}=i,c=r.separators.find(g=>g.element===t);jn(c,"Matching separator not found");const d=a.get(c);jn(d,"Matching panels not found");const f=d[0],m=s.find(g=>g.panelId===f.id);if(jn(m,"Panel metadata not found"),m.collapsible){const g=o[f.id],b=m.collapsedSize===g?r.mutableState.expandedPanelSizes[f.id]??m.minSize:m.collapsedSize;Tc(t,b-g)}break}case"F6":{e.preventDefault();const r=db(t).separators.map(o=>o.element),i=Array.from(r).findIndex(o=>o===e.currentTarget);jn(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(),Tc(t,-100);break}}}let Dd={cursorFlags:0,state:"inactive"};const x2=new xF;function ru(){return Dd}function bxe(e){return x2.addListener("change",e)}function xxe(e){const t=Dd,n={...Dd};n.cursorFlags=e,Dd=n,x2.emit("change",{prev:t,next:n})}function Pd(e){const t=Dd;Dd=e,x2.emit("change",{prev:t,next:e})}function zI(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=gu(),n=b2(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)}),Pd({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}const yxe=e=>e,eS=()=>{},CF=1,kF=2,EF=4,NF=8,BI=3,FI=12;let Ev;function $I(){return Ev===void 0&&(Ev=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(Ev=!0)),Ev}function _xe({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&&$I()){const s=(e&CF)!==0,o=(e&kF)!==0,a=(e&EF)!==0,c=(e&NF)!==0;if(s)return a?"se-resize":c?"ne-resize":"e-resize";if(o)return a?"sw-resize":c?"nw-resize":"w-resize";if(a)return"s-resize";if(c)return"n-resize"}break}}return $I()?r>0&&i>0?"move":r>0?"ew-resize":"ns-resize":r>0&&i>0?"grab":r>0?"col-resize":"row-resize"}}const HI=new WeakMap;function y2(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=HI.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&e.adoptedStyleSheets.push(n));const r=ru();switch(r.state){case"active":case"hover":{const i=_xe({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}}HI.set(e,{prevStyle:t,styleSheet:n})}function TF({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:i,pointerDownAtPoint:s,prevCursorFlags:o}){let a=0;n.forEach(d=>{const{group:f,groupSize:m}=d,{orientation:g,panels:b}=f,{disableCursor:y}=f.mutableState;let _=0;s?g==="horizontal"?_=(t.clientX-s.x)/m*100:_=(t.clientY-s.y)/m*100:g==="horizontal"?_=t.clientX<0?-100:100:_=t.clientY<0?-100:100;const w=r.get(f),C=i.get(f);if(!w||!C)return;const{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:T,layout:R,separatorToPanels:A}=C;if(k&&R&&A){const j=$m({delta:_,initialLayout:w,panelConstraints:k,pivotIndices:d.panels.map(I=>b.indexOf(I)),prevLayout:R,trigger:"mouse-or-touch"});if(tu(j,R)){if(_!==0&&!y)switch(g){case"horizontal":{a|=_<0?CF:kF;break}case"vertical":{a|=_<0?EF:NF;break}}}else Fa(d.group,{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:T,layout:j,separatorToPanels:A})}});let c=0;t.movementX===0?c|=o&BI:c|=a&BI,t.movementY===0?c|=o&FI:c|=a&FI,xxe(c),y2(e)}function UI(e){const t=gu(),n=ru();switch(n.state){case"active":TF({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function VI(e){if(e.defaultPrevented)return;const t=ru(),n=gu();switch(t.state){case"active":{if(e.buttons===0){Pd({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(r=>{const i=Wl(r.group.id,!0);Fa(r.group,i)});return}TF({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const r=b2(e,n);r.length===0?t.state!=="inactive"&&Pd({cursorFlags:0,state:"inactive"}):Pd({cursorFlags:0,hitRegions:r,state:"hover"}),y2(e.currentTarget);break}}}function WI(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(ru().state){case"hover":Pd({cursorFlags:0,state:"inactive"})}}function GI(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=ru();switch(t.state){case"active":Pd({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(y2(e.currentTarget),t.hitRegions.forEach(n=>{const r=Wl(n.group.id,!0);Fa(n.group,r)}),e.preventDefault())}}function qI(e){let t=0,n=0;const r={};for(const s of e)if(s.defaultSize!==void 0){t++;const o=Pi(s.defaultSize);n+=o,r[s.panelId]=o}else r[s.panelId]=void 0;const i=e.length-t;if(i!==0){const s=Pi((100-n)/i);for(const o of e)o.defaultSize===void 0&&(r[o.panelId]=s)}return r}function wxe(e,t,n){if(!n[0])return;const r=e.panels.find(c=>c.element===t);if(!r||!r.onResize)return;const i=Yd({group:e}),s=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,a={asPercentage:Pi(s/i*100),inPixels:s};r.mutableValues.prevSize=a,r.onResize(a,r.id,o)}function Sxe(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 Cxe({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 a=new Map,c=[];for(const m of e.panels){const g=r[m.id]??0;switch(m.panelConstraints.groupResizeBehavior){case"preserve-pixel-size":{o=!0;const b=g/100*n,y=Pi(b/t*100);a.set(m.id,y),i+=y;break}case"preserve-relative-size":default:{c.push(m.id),s+=g;break}}}if(!o||c.length===0)return r;const d=100-i,f={...r};if(a.forEach((m,g)=>{f[g]=m}),s>0)for(const m of c){const g=r[m]??0;f[m]=Pi(g/s*d)}else{const m=Pi(d/c.length);for(const g of c)f[g]=m}return f}function kxe(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 cd=new Map;function Exe(e){let t=!0;jn(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(y=>{for(const _ of y){const{borderBoxSize:w,target:C}=_;if(C===e.element){if(t){const E=Yd({group:e});if(E===0)return;const k=Wl(e.id);if(!k)return;const T=sC(e),R=k.defaultLayoutDeferred?qI(T):k.layout,A=Cxe({group:e,nextGroupSize:E,prevGroupSize:k.groupSize,prevLayout:R}),j=nu({layout:A,panelConstraints:T});if(!k.defaultLayoutDeferred&&tu(k.layout,j)&&Sxe(k.derivedPanelConstraints,T)&&k.groupSize===E)return;Fa(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:T,groupSize:E,layout:j,separatorToPanels:k.separatorToPanels})}}else wxe(e,C,w)}});s.observe(e.element),e.panels.forEach(y=>{jn(!r.has(y.id),`Panel ids must be unique; id "${y.id}" was used more than once`),r.add(y.id),y.onResize&&s.observe(y.element)});const o=Yd({group:e}),a=sC(e),c=e.panels.map(({id:y})=>y).join(",");let d=e.mutableState.defaultLayout;d&&(kxe(e.panels,d)||(d=void 0));const f=e.mutableState.layouts[c]??d??qI(a),m=nu({layout:f,panelConstraints:a}),g=e.element.ownerDocument;cd.set(g,(cd.get(g)??0)+1);const b=new Map;return bF(e).forEach(y=>{y.separator&&b.set(y.separator,y.panels)}),Fa(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:a,groupSize:o,layout:m,separatorToPanels:b}),e.separators.forEach(y=>{jn(!i.has(y.id),`Separator ids must be unique; id "${y.id}" was used more than once`),i.add(y.id),y.element.addEventListener("keydown",OI)}),cd.get(g)===1&&(g.addEventListener("dblclick",PI,!0),g.addEventListener("pointerdown",zI,!0),g.addEventListener("pointerleave",UI),g.addEventListener("pointermove",VI),g.addEventListener("pointerout",WI),g.addEventListener("pointerup",GI,!0)),function(){t=!1,cd.set(g,Math.max(0,(cd.get(g)??0)-1)),lxe(e),e.separators.forEach(y=>{y.element.removeEventListener("keydown",OI)}),cd.get(g)||(g.removeEventListener("dblclick",PI,!0),g.removeEventListener("pointerdown",zI,!0),g.removeEventListener("pointerleave",UI),g.removeEventListener("pointermove",VI),g.removeEventListener("pointerout",WI),g.removeEventListener("pointerup",GI,!0)),s.disconnect()}}function Nxe(){const[e,t]=v.useState({}),n=v.useCallback(()=>t({}),[]);return[e,n]}function _2(e){const t=v.useId();return`${e??t}`}const vu=typeof window<"u"?v.useLayoutEffect:v.useEffect;function im(e){const t=v.useRef(e);return vu(()=>{t.current=e},[e]),v.useCallback((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[t])}function w2(...e){return im(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function S2(e){const t=v.useRef({...e});return vu(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const RF=v.createContext(null);function Txe(e,t){const n=v.useRef({getLayout:()=>({}),setLayout:yxe});v.useImperativeHandle(t,()=>n.current,[]),vu(()=>{Object.assign(n.current,SF({groupId:e}))})}function AF({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:s,groupRef:o,id:a,onLayoutChange:c,onLayoutChanged:d,orientation:f="horizontal",resizeTargetMinimumSize:m={coarse:20,fine:10},style:g,...b}){const y=v.useRef({onLayoutChange:{},onLayoutChanged:{}}),_=im(D=>{tu(y.current.onLayoutChange,D)||(y.current.onLayoutChange=D,c==null||c(D))}),w=im(D=>{tu(y.current.onLayoutChanged,D)||(y.current.onLayoutChanged=D,d==null||d(D))}),C=_2(a),E=v.useRef(null),[k,T]=Nxe(),R=v.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:m,separators:[]}),A=w2(E,s);Txe(C,o);const j=im((D,z)=>{const P=ru(),F=MI(D),$=Wl(D);if($){let B=!1;switch(P.state){case"active":{B=P.hitRegions.some(H=>H.group===F);break}}return{flexGrow:$.layout[z]??1,pointerEvents:B?"none":void 0}}return{flexGrow:(n==null?void 0:n[z])??1}}),I=S2({defaultLayout:n,disableCursor:r}),U=v.useMemo(()=>({get disableCursor(){return!!I.disableCursor},getPanelStyles:j,id:C,orientation:f,registerPanel:D=>{const z=R.current;return z.panels=oC(f,[...z.panels,D]),T(),()=>{z.panels=z.panels.filter(P=>P!==D),T()}},registerSeparator:D=>{const z=R.current;return z.separators=oC(f,[...z.separators,D]),T(),()=>{z.separators=z.separators.filter(P=>P!==D),T()}},togglePanelDisabled:(D,z)=>{const P=R.current.panels.find(B=>B.id===D);P&&(P.panelConstraints.disabled=z);const F=MI(C),$=Wl(C);F&&$&&Fa(F,{...$,derivedPanelConstraints:sC(F)})},toggleSeparatorDisabled:(D,z)=>{const P=R.current.separators.find(F=>F.id===D);P&&(P.disabled=z)}}),[j,C,T,f,I]),M=v.useRef(null);return vu(()=>{const D=E.current;if(D===null)return;const z=R.current;let P;if(I.defaultLayout!==void 0&&Object.keys(I.defaultLayout).length===z.panels.length){P={};for(const O of z.panels){const K=I.defaultLayout[O.id];K!==void 0&&(P[O.id]=K)}}const F={disabled:!!i,element:D,id:C,mutableState:{defaultLayout:P,disableCursor:!!I.disableCursor,expandedPanelSizes:R.current.lastExpandedPanelSizes,layouts:R.current.layouts},orientation:f,panels:z.panels,resizeTargetMinimumSize:z.resizeTargetMinimumSize,separators:z.separators};M.current=F;const $=Exe(F),{defaultLayoutDeferred:B,derivedPanelConstraints:H,layout:W}=Wl(F.id,!0);!B&&H.length>0&&(_(W),w(W));const te=v2(C,O=>{const{defaultLayoutDeferred:K,derivedPanelConstraints:ee,layout:V}=O.next;if(K||ee.length===0)return;const ue=F.panels.map(({id:Z})=>Z).join(",");F.mutableState.layouts[ue]=V,ee.forEach(Z=>{if(Z.collapsible){const{layout:ne}=O.prev??{};if(ne){const ie=pi(Z.collapsedSize,V[Z.panelId]),le=pi(Z.collapsedSize,ne[Z.panelId]);ie&&!le&&(F.mutableState.expandedPanelSizes[Z.panelId]=ne[Z.panelId])}}});const ge=ru().state!=="active";_(V),ge&&w(V)});return()=>{M.current=null,$(),te()}},[i,C,w,_,f,k,I]),v.useEffect(()=>{const D=M.current;D&&(D.mutableState.defaultLayout=n,D.mutableState.disableCursor=!!r)}),u.jsx(RF.Provider,{value:U,children:u.jsx("div",{...b,className:t,"data-group":!0,"data-testid":C,id:C,ref:A,style:{height:"100%",width:"100%",overflow:"hidden",...g,display:"flex",flexDirection:f==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:f==="horizontal"?"pan-y":"pan-x"},children:e})})}AF.displayName="Group";function C2(){const e=v.useContext(RF);return jn(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function Rxe(e,t){const{id:n}=C2(),r=v.useRef({collapse:eS,expand:eS,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:eS});v.useImperativeHandle(t,()=>r.current,[]),vu(()=>{Object.assign(r.current,wF({groupId:n,panelId:e}))})}function jF({children:e,className:t,collapsedSize:n="0%",collapsible:r=!1,defaultSize:i,disabled:s,elementRef:o,groupResizeBehavior:a="preserve-relative-size",id:c,maxSize:d="100%",minSize:f="0%",onResize:m,panelRef:g,style:b,...y}){const _=!!c,w=_2(c),C=S2({disabled:s}),E=v.useRef(null),k=w2(E,o),{getPanelStyles:T,id:R,orientation:A,registerPanel:j,togglePanelDisabled:I}=C2(),U=m!==null,M=im((z,P,F)=>{m==null||m(z,c,F)});vu(()=>{const z=E.current;if(z!==null){const P={element:z,id:w,idIsStable:_,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:U?M:void 0,panelConstraints:{groupResizeBehavior:a,collapsedSize:n,collapsible:r,defaultSize:i,disabled:C.disabled,maxSize:d,minSize:f}};return j(P)}},[a,n,r,i,U,w,_,d,f,M,j,C]),v.useEffect(()=>{I(w,!!s)},[s,w,I]),Rxe(w,g);const D=v.useSyncExternalStore(z=>v2(R,z),()=>JSON.stringify(T(R,w)),()=>JSON.stringify(T(R,w)));return u.jsx("div",{...y,"aria-disabled":s||void 0,"data-panel":!0,"data-testid":w,id:w,ref:k,style:{...Axe,display:"flex",flexBasis:0,flexShrink:1,overflow:"visible",...JSON.parse(D)},children:u.jsx("div",{className:t,style:{maxHeight:"100%",maxWidth:"100%",flexGrow:1,overflow:"auto",...b,touchAction:A==="horizontal"?"pan-y":"pan-x"},children:e})})}jF.displayName="Panel";const Axe={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function jxe({layout:e,panelConstraints:t,panelId:n,panelIndex:r}){let i,s;const o=e[n],a=t.find(c=>c.panelId===n);if(a){const c=a.maxSize,d=a.collapsible?a.collapsedSize:a.minSize,f=[r,r+1];s=nu({layout:$m({delta:d-o,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e}),panelConstraints:t})[n],i=nu({layout:$m({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:s,valueNow:o}}function MF({children:e,className:t,disabled:n,elementRef:r,id:i,style:s,...o}){const a=_2(i),c=S2({disabled:n}),[d,f]=v.useState({}),[m,g]=v.useState("inactive"),b=v.useRef(null),y=w2(b,r),{disableCursor:_,id:w,orientation:C,registerSeparator:E,toggleSeparatorDisabled:k}=C2(),T=C==="horizontal"?"vertical":"horizontal";vu(()=>{const A=b.current;if(A!==null){const j={disabled:c.disabled,element:A,id:a},I=E(j),U=bxe(D=>{g(D.next.state!=="inactive"&&D.next.hitRegions.some(z=>z.separator===j)?D.next.state:"inactive")}),M=v2(w,D=>{const{derivedPanelConstraints:z,layout:P,separatorToPanels:F}=D.next,$=F.get(j);if($){const B=$[0],H=$.indexOf(B);f(jxe({layout:P,panelConstraints:z,panelId:B.id,panelIndex:H}))}});return()=>{U(),M(),I()}}},[w,a,E,c]),v.useEffect(()=>{k(a,!!n)},[n,a,k]);let R;return n&&!_&&(R="not-allowed"),u.jsx("div",{...o,"aria-controls":d.valueControls,"aria-disabled":n||void 0,"aria-orientation":T,"aria-valuemax":d.valueMax,"aria-valuemin":d.valueMin,"aria-valuenow":d.valueNow,children:e,className:t,"data-separator":n?"disabled":m,"data-testid":a,id:a,ref:y,role:"separator",style:{flexBasis:"auto",cursor:R,...s,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:n?void 0:0})}MF.displayName="Separator";const k2=({className:e,...t})=>u.jsx(AF,{className:de("flex h-full w-full",e),...t}),Hm=e=>u.jsx(jF,{...e}),E2=({withHandle:e,orientation:t,disabled:n,className:r,...i})=>u.jsx(MF,{disabled:n,className:de("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:u.jsx("span",{className:"sr-only",children:t==="vertical"?"Resize rows":"Resize columns"})});function LF(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 Mxe(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 LF(r.usage,new Date(r.createdAt).toISOString(),t)}return null}function Lxe(e,t){return!e||t===null||!Number.isFinite(t)||t<=0?e:LF({...e,maxTokens:t},e.updatedAt,e.compactsAutomatically)}function Ixe(e){if(!e)return null;const t=tS(e.inputTokens),n=tS(e.outputTokens),r=tS(e.cachedInputTokens);if(t===0&&n===0&&r===0)return null;const i=t+r,s=i>0?r/i*100:null;return{input:t,output:n,cached:r,cacheHitPercentage:s}}function tS(e){return e===void 0||!Number.isFinite(e)||e<0?0:e}function Zi(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 N2=[68,32];function Dxe(){return{isVisible:!1,mainSizes:[...N2],terminals:[],nextTerminalIndex:0}}function Pxe(e,t){return e[t]??Dxe()}function nS(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 Oxe(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 zxe(e){if(e.length===0)return e;const t=e.length+1;return e.map(n=>({...n,size:n.size*e.length/t}))}function ud(e,t,n){return{...e,[t]:n(Pxe(e,t))}}const Ml=ss()(yh(e=>({projects:{},addTerminal:(t,n)=>e(r=>({projects:ud(r.projects,t,i=>{var c,d;const s=zxe(i.terminals),o={id:((d=(c=globalThis.crypto)==null?void 0:c.randomUUID)==null?void 0:d.call(c))??`terminal-${Date.now()}-${i.nextTerminalIndex}`,title:Oxe(i.nextTerminalIndex),size:100/(s.length+1)},a=n?Math.max(s.findIndex(f=>f.id===n)+1,0):s.length;return{...i,isVisible:!0,nextTerminalIndex:i.nextTerminalIndex+1,terminals:[...s.slice(0,a),o,...s.slice(a)]}})})),removeTerminal:(t,n)=>e(r=>({projects:ud(r.projects,t,i=>{const s=i.terminals.filter(a=>a.id!==n);if(s.length===0)return{...i,isVisible:!1,terminals:[]};const o=nS(s.map(a=>a.size));return{...i,terminals:s.map((a,c)=>({...a,size:o[c]??100/s.length}))}})})),toggleVisibility:t=>e(n=>({projects:ud(n.projects,t,r=>({...r,isVisible:r.terminals.length>0?!r.isVisible:!1}))})),resetMainSizes:t=>e(n=>({projects:ud(n.projects,t,r=>({...r,mainSizes:[...N2]}))})),setMainSizes:(t,n)=>e(r=>{if(n.length!==2)return r;const i=nS(n);return{projects:ud(r.projects,t,s=>({...s,mainSizes:i}))}}),setTerminalSizes:(t,n)=>e(r=>({projects:ud(r.projects,t,i=>{if(n.length!==i.terminals.length)return i;const s=nS(n);return{...i,terminals:i.terminals.map((o,a)=>({...o,size:s[a]??o.size}))}})})),clearProject:t=>e(n=>{const{[t]:r,...i}=n.projects;return{projects:i}})}),{name:"terminal-layouts",version:1})),Bxe={isVisible:!1,mainSizes:[...N2],terminals:[],nextTerminalIndex:0},Fxe=35;function $xe(e,t){return!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<=0?0:e*(t/100)}function Hxe(e,t){const n=$xe(e,t);return n>=0&&n<Fxe}const xy=350,Uxe=[.4,0,.2,1],Vxe=8,KI=1e-6;function Wxe(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function Gxe(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function qxe(e,t,n){const r=1-e;return 3*r*r*t+6*r*e*(n-t)+3*e*e*(1-n)}function Kxe(e,t,n){let r=e;for(let i=0;i<Vxe;i+=1){const s=Wxe(r,t,n)-e;if(Math.abs(s)<KI)return r;const o=qxe(r,t,n);if(Math.abs(o)<KI)break;r-=s/o}return r}function Yxe(e){if(e<=0)return 0;if(e>=1)return 1;const[t,n,r,i]=Uxe,s=Kxe(e,t,r);return Gxe(s,n,i)}function IF(e,t,n){const r=Yxe(n);return[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r]}function Xxe({projectId:e,shouldRenderRightSidebarLayout:t,showRightSidebar:n,rightSidebarSize:r}){const i=v.useRef(null),s=v.useRef(null),o=v.useRef(null),a=v.useRef(null),c=v.useRef(null),d=v.useRef(!1),f=v.useRef(null),m=v.useRef(!1),g=v.useRef(!1);return v.useEffect(()=>()=>{a.current!==null&&window.cancelAnimationFrame(a.current),c.current!==null&&window.clearTimeout(c.current)},[]),v.useLayoutEffect(()=>{var j,I,U,M,D,z;if(!t){a.current!==null&&(window.cancelAnimationFrame(a.current),a.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null),d.current=!1;return}const b=i.current;if(!b)return;a.current!==null&&(window.cancelAnimationFrame(a.current),a.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null);const y=f.current,_=y!==null&&y!==e,w=n&&!g.current,C=!m.current,E=n?[100-r,r]:[100,0],k=_||C&&n,T=w||C?[100,0]:[b.getLayout().workspace??E[0],b.getLayout().rightSidebar??E[1]];if(f.current=e,m.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]}),(j=s.current)==null||j.setAttribute("data-right-sidebar-open",n?"true":"false"),(I=o.current)==null||I.setAttribute("data-right-sidebar-open",n?"true":"false"),(U=o.current)==null||U.setAttribute("data-right-sidebar-animated","false");return}d.current=!0,(M=s.current)==null||M.setAttribute("data-right-sidebar-open",n?"true":"false"),(D=o.current)==null||D.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 R=performance.now(),A=P=>{const F=Math.min(1,(P-R)/xy),$=IF(T,E,F);if(b.setLayout({workspace:$[0],rightSidebar:$[1]}),F<1){a.current=window.requestAnimationFrame(A);return}b.setLayout({workspace:E[0],rightSidebar:E[1]}),a.current=null,c.current=window.setTimeout(()=>{d.current=!1,c.current=null},0)};a.current=window.requestAnimationFrame(A)},[e,r,t,n]),v.useEffect(()=>{t||(m.current=!1,g.current=!1)},[t]),{isAnimating:d,panelGroupRef:i,sidebarPanelRef:s,sidebarVisualRef:o}}function Qxe(e){return e.visibilityState==="visible"?e.activeChatId:null}function Zxe(e){e.socket.setFocusedChat(Qxe({activeChatId:e.activeChatId,visibilityState:e.visibilityState}))}function Jxe({socket:e,activeChatId:t}){v.useEffect(()=>{if(typeof document>"u")return;const n=()=>{Zxe({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 eye({rootRef:e,fallbackRef:t,enabled:n,canCancel:r}){v.useEffect(()=>{if(!n)return;let i=0,s=null;const o=m=>{const g=m instanceof Element?m:null,b=e.current,y=t.current;if(Rj({trigger:"pointer",activeElement:document.activeElement,pointerStartTarget:s,pointerEndTarget:g,root:b,fallback:y,hasActiveOverlay:Tj(document),hasActiveSelection:RX(window.getSelection())})!=="restore"){s=null;return}y==null||y.focus({preventScroll:!0}),s=null},a=m=>{cancelAnimationFrame(i),s=m.target instanceof Element?m.target:null},c=m=>{cancelAnimationFrame(i),i=window.requestAnimationFrame(()=>{o(m.target)})},d=()=>{s=null;const m=t.current;!m||m.disabled||m.focus({preventScroll:!0})},f=m=>{if(m.key!=="Escape")return;const g=t.current;Rj({trigger:"escape",activeElement:document.activeElement,fallback:g,hasActiveOverlay:Tj(document),canCancel:r,defaultPrevented:m.defaultPrevented})==="escape-focus"&&(m.preventDefault(),g==null||g.focus({preventScroll:!0}))};return window.addEventListener("pointerdown",a,!0),window.addEventListener("pointerup",c,!0),window.addEventListener("keydown",f,!0),window.addEventListener(Nb,d),()=>{cancelAnimationFrame(i),window.removeEventListener("pointerdown",a,!0),window.removeEventListener("pointerup",c,!0),window.removeEventListener("keydown",f,!0),window.removeEventListener(Nb,d)}},[r,n,t,e])}function tye(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 nye({previousProjectId:e,projectId:t,previousShouldRenderTerminalLayout:n,previousShowTerminalPane:r,showTerminalPane:i,terminalLayout:s,liveLayout:o}){const a=e!==null&&e!==t,c=i&&!r,d=!n,f=e===null&&t!==null,m=i?s.mainSizes:[100,0];return{currentLayout:c||d?[100,0]:o,shouldSkipAnimation:a||f&&d,targetLayout:m}}function rye({chatInputRef:e,projectId:t,shouldRenderTerminalLayout:n,showTerminalPane:r,terminalLayout:i}){const s=v.useRef(null),o=v.useRef(null),a=v.useRef(null),c=v.useRef(null),d=v.useRef(null),f=v.useRef(!1),m=v.useRef(null),g=v.useRef(!1),b=v.useRef(!1),y=v.useRef(!1),[_,w]=v.useState(0);return v.useEffect(()=>{var k;const C=m.current,E=y.current;tye({previousProjectId:C,projectId:t,showTerminalPane:r,wasTerminalVisible:E})&&w(T=>T+1),C!==null&&C===t&&!r&&E&&((k=e.current)==null||k.focus({preventScroll:!0})),y.current=r,m.current=t},[e,t,r]),v.useEffect(()=>()=>{c.current!==null&&window.cancelAnimationFrame(c.current),d.current!==null&&window.clearTimeout(d.current)},[]),v.useLayoutEffect(()=>{var I,U,M,D,z,P;if(!n){c.current!==null&&(window.cancelAnimationFrame(c.current),c.current=null),d.current!==null&&(window.clearTimeout(d.current),d.current=null),f.current=!1;return}const C=s.current;if(!C)return;c.current!==null&&(window.cancelAnimationFrame(c.current),c.current=null),d.current!==null&&(window.clearTimeout(d.current),d.current=null);const E=m.current,{currentLayout:k,shouldSkipAnimation:T,targetLayout:R}=nye({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]-R[0])<.1&&Math.abs(k[1]-R[1])<.1){C.setLayout({chat:R[0],terminal:R[1]}),(I=o.current)==null||I.setAttribute("data-terminal-open",r?"true":"false"),(U=a.current)==null||U.setAttribute("data-terminal-open",r?"true":"false"),(M=a.current)==null||M.setAttribute("data-terminal-animated","false");return}f.current=!0,(D=o.current)==null||D.setAttribute("data-terminal-open",r?"true":"false"),(z=a.current)==null||z.setAttribute("data-terminal-open",r?"true":"false"),(P=a.current)==null||P.setAttribute("data-terminal-animated","true"),C.setLayout({chat:k[0],terminal:k[1]});const A=performance.now(),j=F=>{const $=Math.min(1,(F-A)/xy),B=IF(k,R,$);if(C.setLayout({chat:B[0],terminal:B[1]}),$<1){c.current=window.requestAnimationFrame(j);return}C.setLayout({chat:R[0],terminal:R[1]}),c.current=null,d.current=window.setTimeout(()=>{f.current=!1,d.current=null},0)};c.current=window.requestAnimationFrame(j)},[t,n,r,i]),v.useEffect(()=>{n||(g.current=!1,b.current=!1)},[n]),{isAnimating:f,mainPanelGroupRef:s,terminalFocusRequestVersion:_,terminalPanelRef:o,terminalVisualRef:a}}const YI=e=>Symbol.iterator in e,XI=e=>"entries"in e,QI=(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},iye=(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 sye(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:YI(e)&&YI(t)?XI(e)&&XI(t)?QI(e,t):iye(e,t):QI({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function lx(e){const t=yn.useRef(void 0);return n=>{const r=e(n);return sye(t.current,r)?t.current:t.current=r}}const sm="__new__";function Rc(e){var s,o;const t=(s=e==null?void 0:e.modelOptions)==null?void 0:s.reasoningEffort,n=l1(t)?t:l1(e==null?void 0:e.effort)?e.effort:Yc.reasoningEffort,r=qne(e==null?void 0:e.model),i=gE(r,(o=e==null?void 0:e.modelOptions)==null?void 0:o.contextWindow);return{model:r,modelOptions:{reasoningEffort:!cz(r)&&n==="max"?"high":n,contextWindow:i},planMode:!!(e!=null&&e.planMode)}}function Nv(e){var n,r;const t=(n=e==null?void 0:e.modelOptions)==null?void 0:n.reasoningEffort;return{model:Kne(e==null?void 0:e.model),modelOptions:{reasoningEffort:c1(t)?t:c1(e==null?void 0:e.effort)?e.effort:Cm.reasoningEffort,fastMode:typeof((r=e==null?void 0:e.modelOptions)==null?void 0:r.fastMode)=="boolean"?e.modelOptions.fastMode:Cm.fastMode},planMode:!!(e!=null&&e.planMode)}}function oye(){return{claude:{model:"claude-opus-4-7",modelOptions:{...Yc},planMode:!1},codex:{model:"gpt-5.5",modelOptions:{...Cm},planMode:!1}}}function aye(e,t){return e.reasoningEffort===t.reasoningEffort&&e.contextWindow===t.contextWindow}function lye(e,t){return e.reasoningEffort===t.reasoningEffort&&e.fastMode===t.fastMode}function cye(e,t){return e.claude.model===t.claude.model&&e.claude.planMode===t.claude.planMode&&aye(e.claude.modelOptions,t.claude.modelOptions)&&e.codex.model===t.codex.model&&e.codex.planMode===t.codex.planMode&&lye(e.codex.modelOptions,t.codex.modelOptions)}function uye(e,t){if(t===void 0){console.info(`[chat-preferences] ${e}`);return}console.info(`[chat-preferences] ${e}`,t)}function om(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 aC(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 DF(e){return e.providerHint?om(e.providerHint,e.providerDefaults):e.defaultProvider==="last_used"?e.sourceState?aC(e.sourceState):om("claude",e.providerDefaults):om(e.defaultProvider,e.providerDefaults)}function PF(e,t){const n=e.chatStates[t];return n||DF({defaultProvider:e.defaultProvider,providerDefaults:e.providerDefaults,legacyComposerState:e.legacyComposerState})}function Tv(e,t,n){const r=PF(e,t);return{chatStates:{...e.chatStates,[t]:n(r)}}}const vi=ss()(yh((e,t)=>({defaultProvider:"last_used",providerDefaults:oye(),chatStates:{},legacyComposerState:{provider:"claude",model:"claude-opus-4-7",modelOptions:{...Yc},planMode:!1},setDefaultProvider:n=>e({defaultProvider:n}),applyServerDefaults:(n,r)=>e(i=>{if(i.defaultProvider===n&&cye(i.providerDefaults,r))return{defaultProvider:n,providerDefaults:r};const{[sm]:o,...a}=i.chatStates;return{defaultProvider:n,providerDefaults:r,chatStates:a}}),setProviderDefaultModel:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?Rc({...i.providerDefaults.claude,model:r}):Nv({...i.providerDefaults.codex,model:r})}})),setProviderDefaultModelOptions:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?Rc({...i.providerDefaults.claude,modelOptions:{...i.providerDefaults.claude.modelOptions,...r}}):Nv({...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=>aC(PF(t(),n)),initializeComposerForChat:(n,r)=>e(i=>{if(i.chatStates[n])return i;const s=DF({defaultProvider:i.defaultProvider,providerDefaults:i.providerDefaults,sourceState:r==null?void 0:r.sourceState,legacyComposerState:i.legacyComposerState,providerHint:r==null?void 0:r.providerHint});return uye("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:Rc(r).model,modelOptions:Rc(r).modelOptions,planMode:r.planMode}:aC(r)}})),setChatComposerProvider:(n,r)=>e(i=>Tv(i,n,()=>om(r,i.providerDefaults))),setChatComposerModel:(n,r)=>e(i=>Tv(i,n,s=>s.provider==="claude"?{provider:"claude",model:Rc({...s,model:r}).model,modelOptions:Rc({...s,model:r}).modelOptions,planMode:s.planMode}:{provider:"codex",model:r,modelOptions:Nv({...s,model:r}).modelOptions,planMode:s.planMode})),setChatComposerModelOptions:(n,r)=>e(i=>Tv(i,n,s=>s.provider==="claude"?{provider:"claude",model:s.model,modelOptions:Rc({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode}:{provider:"codex",model:s.model,modelOptions:Nv({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode})),setChatComposerPlanMode:(n,r)=>e(i=>Tv(i,n,s=>({...s,planMode:r}))),resetChatComposerFromProvider:(n,r)=>e(i=>({chatStates:{...i.chatStates,[n]:om(r,i.providerDefaults)}}))}),{name:"chat-preferences-state",version:1,partialize:e=>({chatStates:e.chatStates,legacyComposerState:e.legacyComposerState})})),lC=ss()(yh((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"})),T2=ss()(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]:a,...c}=n.loadingByChatId;return{byChatId:o,loadingByChatId:c}})}));function dye(e){return{autoResumeOnRateLimit:!!(e!=null&&e.autoResumeOnRateLimit)}}const cC=ss()(yh(e=>({autoResumeOnRateLimit:!1,setAutoResumeOnRateLimit:t=>e({autoResumeOnRateLimit:t})}),{name:"kanna-preferences",version:1,migrate:e=>dye(e)}));function dd(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function Rv(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function hye(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 rS(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 fye(e,t){var r;const n=Rv(t);switch(e.toolKind){case"ask_user_question":{const o=rS(n),a=o!==null?Rv(o):n,c=dd(a),d=dd(c==null?void 0:c.answers)??(c||{});return{answers:Object.fromEntries(Object.entries(d).map(([f,m])=>Array.isArray(m)?[f,m.map(g=>String(g))]:m&&typeof m=="object"&&Array.isArray(m.answers)?[f,m.answers.map(g=>String(g))]:m==null||m===""?[f,[]]:[f,[String(m)]])),...(c==null?void 0:c.discarded)===!0?{discarded:!0}:{}}}case"exit_plan_mode":{const o=rS(n),a=o!==null?Rv(o):n,c=dd(a);return{confirmed:typeof(c==null?void 0:c.confirmed)=="boolean"?c.confirmed:void 0,clearContext:typeof(c==null?void 0:c.clearContext)=="boolean"?c.clearContext:void 0,message:typeof(c==null?void 0:c.message)=="string"?c.message:void 0,...(c==null?void 0:c.discarded)===!0?{discarded:!0}:{}}}case"offer_download":{const o=rS(n),a=o?Rv(o):n,c=dd(a);return{contentUrl:typeof(c==null?void 0:c.contentUrl)=="string"?c.contentUrl:"",relativePath:typeof(c==null?void 0:c.relativePath)=="string"?c.relativePath:"",fileName:typeof(c==null?void 0:c.fileName)=="string"?c.fileName:"",displayName:typeof(c==null?void 0:c.displayName)=="string"?c.displayName:typeof(c==null?void 0:c.fileName)=="string"?c.fileName:"",size:typeof(c==null?void 0:c.size)=="number"?c.size:0,...typeof(c==null?void 0:c.mimeType)=="string"?{mimeType:c.mimeType}:{}}}case"image_generation":{const o=dd(n);return{contentUrl:typeof(o==null?void 0:o.contentUrl)=="string"?o.contentUrl:"",relativePath:typeof(o==null?void 0:o.relativePath)=="string"?o.relativePath:"",fileName:typeof(o==null?void 0:o.fileName)=="string"?o.fileName:""}}case"workflow":{const o=typeof t=="string"?t:"";return{taskId:(r=o.match(/Task ID:\s*(\S+)/))==null?void 0:r[1],text:o}}case"read_file":if(typeof n=="string")return n;const i=hye(n);if(i.length>0)return{content:i.flatMap(o=>o.type==="text"?[o.text]:[]).join(""),blocks:i};const s=dd(n);return{content:typeof(s==null?void 0:s.content)=="string"?s.content:JSON.stringify(n,null,2)};default:return n}}function OF(e){return new Date(e).toISOString()}function di(e){return{id:e._id,messageId:e.messageId,timestamp:OF(e.createdAt),hidden:e.hidden}}function mye(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:OF(e.createdAt)}}function pye(e){if(e.debugRaw)try{return JSON.parse(e.debugRaw).tool_use_result}catch{return}}function zF(e){const t=new Map,n=[];for(const r of e)switch(r.kind){case"user_prompt":n.push({...di(r),kind:"user_prompt",content:r.content,attachments:r.attachments??[],steered:r.steered,autoContinue:r.autoContinue});break;case"system_init":n.push({...di(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({...di(r),kind:"account_info",accountInfo:r.accountInfo});break;case"assistant_text":n.push({...di(r),kind:"assistant_text",text:r.text});break;case"api_error":n.push({...di(r),kind:"api_error",status:r.status,text:r.text,requestId:r.requestId});break;case"tool_call":{const i=mye(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"?pye(r)??r.content:r.content;i.hydrated.result=fye(i.normalized,s),i.hydrated.rawResult=s,i.hydrated.isError=r.isError,r.persisted&&(i.hydrated.persisted=r.persisted)}break}case"result":n.push({...di(r),kind:"result",success:!r.isError,cancelled:r.subtype==="cancelled",result:r.result,durationMs:r.durationMs,costUsd:r.costUsd});break;case"status":n.push({...di(r),kind:"status",status:r.status});break;case"context_window_updated":n.push({...di(r),kind:"context_window_updated",usage:r.usage});break;case"compact_boundary":n.push({...di(r),kind:"compact_boundary"});break;case"compact_summary":n.push({...di(r),kind:"compact_summary",summary:r.summary});break;case"context_cleared":n.push({...di(r),kind:"context_cleared"});break;case"interrupted":n.push({...di(r),kind:"interrupted"});break;case"auto_continue_prompt":n.push({...di(r),kind:"auto_continue_prompt",scheduleId:r.scheduleId});break;case"pending_tool_request":n.push({...di(r),kind:"pending_tool_request",toolRequestId:r.toolRequestId,toolName:r.toolName,arguments:r.arguments});break;case"tool_request_resolved":break;default:n.push({...di(r),kind:"unknown",json:JSON.stringify(r,null,2)});break}return n}const gye=["AskUserQuestion","ExitPlanMode","TodoWrite"],vye=new Set(["TodoWrite"]);function bye(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 xye(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 yye(e){const t={};for(const n of gye)t[n]=vye.has(n)?xye(e,n):bye(e,n);return t}function _ye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}function wye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}const R2="pushDeviceId";function BF(){return typeof localStorage>"u"?null:localStorage.getItem(R2)}function Sye(e){typeof localStorage>"u"||localStorage.setItem(R2,e)}function Cye(){typeof localStorage>"u"||localStorage.removeItem(R2)}function kye(){return!(typeof window>"u"||typeof Notification>"u"||!("serviceWorker"in navigator)||typeof globalThis.PushManager>"u")}function Eye(){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 uC(){if(!kye())return{state:"unsupported"};if(!Eye())return{state:"insecure-context"};switch(Notification.permission){case"granted":return{state:"granted"};case"denied":return{state:"denied"};default:return{state:"default"}}}function Nye(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 Tye(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 Rye(e){const t=uC();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:Nye(e.vapidPublicKey)}),s=i.toJSON(),o=s.endpoint??i.endpoint,a=s.keys??{};if(!o||!a.p256dh||!a.auth)throw new Error("Subscription returned without endpoint or keys");const c=navigator.userAgent??"",{id:d}=await e.sendToServer({subscription:{endpoint:o,keys:{p256dh:a.p256dh,auth:a.auth}},label:Tye(c),userAgent:c});return d}async function Aye(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 jye=25e3,Mye=15e3,Lye=4e3,ZI="kanna:profile-send-to-starting";function JI(){try{return window.sessionStorage.getItem(ZI)==="1"||window.localStorage.getItem(ZI)==="1"}catch{return!1}}class Iye{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=Ic();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=Ic(),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=Ic(),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=Ic();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=BF();t&&this.sendNow({v:1,type:"command",id:Ic(),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(JI()&&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}),JI()&&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 a=this.subscriptions.get(i.id);a==null||a.listener(i.snapshot.data);return}if(i.type==="event"){const a=this.subscriptions.get(i.id);(o=a==null?void 0:a.eventListener)==null||o.call(a,i.event);return}if(i.type==="ack"){const a=this.pending.get(i.id);if(!a)return;this.pending.delete(i.id),a.resolve(i.result);return}if(i.type==="error"){if(!i.id){console.error(jZ,i.message);return}const a=this.pending.get(i.id);if(!a)return;this.pending.delete(i.id),a.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>=jye}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()},Lye),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()},Mye))}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))}}const Dye=[],A2=ss()(e=>({byChat:{},setRuns:(t,n)=>e(r=>({byChat:{...r.byChat,[t]:n}}))}));function FF(e){return t=>t.byChat[e]??Dye}function Pye(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 Oye(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&&Pye(e.sessionTokensByProvider,t.sessionTokensByProvider)}function zye(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 Bye(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 Fye(e,t){return e===t?!0:!e||!t?!1:e.hasOlder===t.hasOlder&&e.olderCursor===t.olderCursor&&e.recentLimit===t.recentLimit}function $ye(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)&&Hye(e.attachments,t.attachments)}function Hye(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 Uye(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>$ye(n,t[r]))}function Vye(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((a,c)=>{const d=r[c];return!!d&&a.sha===d.sha&&a.summary===d.summary&&a.description===d.description&&a.authorName===d.authorName&&a.authoredAt===d.authoredAt&&a.githubUrl===d.githubUrl&&a.tags.length===d.tags.length&&a.tags.every((f,m)=>f===d.tags[m])})||e.files.length!==t.files.length?!1:e.files.every((a,c)=>{const d=t.files[c];return!!d&&a.path===d.path&&a.changeType===d.changeType&&a.isUntracked===d.isUntracked&&a.additions===d.additions&&a.deletions===d.deletions&&a.patchDigest===d.patchDigest&&a.mimeType===d.mimeType&&a.size===d.size})}function Wye(e,t){return!!(e&&e.status!=="unknown"&&t&&t.status==="unknown"&&t.files.length===0)}function Gye(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 qye(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 Kye(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=>{var a,c,d,f,m,g;const s=e[i],o=t[i];return!s||!o?!1:s.status===o.status&&s.entries.length===o.entries.length&&(s.finalText??"")===(o.finalText??"")&&(((a=s.pendingTool)==null?void 0:a.toolUseId)??null)===(((c=o.pendingTool)==null?void 0:c.toolUseId)??null)&&(((d=s.usage)==null?void 0:d.outputTokens)??null)===(((f=o.usage)==null?void 0:f.outputTokens)??null)&&s.finishedAt===o.finishedAt&&(((m=s.error)==null?void 0:m.code)??null)===(((g=o.error)==null?void 0:g.code)??null)})}function Yye(e,t){return e===t?!0:!e||!t?!1:Oye(e.runtime,t.runtime)&&Uye(e.queuedMessages,t.queuedMessages)&&zye(e.messages,t.messages)&&Fye(e.history,t.history)&&Bye(e.availableProviders,t.availableProviders)&&Gye(e.schedules,t.schedules)&&e.liveScheduleId===t.liveScheduleId&&qye(e.tunnels,t.tunnels)&&e.liveTunnelId===t.liveTunnelId&&Kye(e.subagentRuns,t.subagentRuns)}function eD(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 Xye(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 tD="__new_chat__",$F="lever-theme",HF="chat-sound-preferences",UF="terminal-preferences",VF="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 Qye(){if(typeof window>"u")return null;const e={},t=window.localStorage.getItem($F);(t==="light"||t==="dark"||t==="system")&&(e.theme=t);const n=iS(HF);((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(UF);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(VF);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 Zye(){typeof window>"u"||(window.localStorage.removeItem($F),window.localStorage.removeItem(HF),window.localStorage.removeItem(UF),window.localStorage.removeItem(VF))}function Rf(e){Di.getState().setFromServer(e);const t=mi.getState();t.setScrollbackLines(e.terminal.scrollbackLines),t.setMinColumnWidth(e.terminal.minColumnWidth),t.setEditorPreset(e.editor.preset),t.setEditorCommandTemplate(e.editor.commandTemplate);const n=Oc.getState();n.setChatSoundPreference(e.chatSoundPreference),n.setChatSoundId(e.chatSoundId),vi.getState().applyServerDefaults(e.defaultProvider,e.providerDefaults)}function Jye(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 j2(e,t=[]){return JSON.stringify({content:e,attachments:t.map(Jye)})}function e0e(e,t){return e.reduce((n,r)=>r.kind!=="user_prompt"?n:n+(j2(r.content,r.attachments??[])===t?1:0),0)}function t0e(e,t,n){const r=new Map;for(const i of n){if(i.kind!=="user_prompt")continue;const s=j2(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)}function n0e(e,t,n){return e.some(r=>r.id===t)?e.filter(r=>r.id!==t):e}const r0e=200,i0e=500;function nD(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 rD(e,t){if(!(t!=null&&t.length)||e.length<=1)return e;const n=new Map(e.map((o,a)=>[o.groupKey,a])),r=new Set,i=t.map(o=>{if(r.has(o))return null;r.add(o);const a=n.get(o);return a===void 0?null:e[a]}).filter(o=>!!o);if(i.length===0)return e;const s=[...i,...e.filter(o=>!r.has(o.groupKey))];return s.every((o,a)=>o===e[a])?e:s}function s0e(e=document){return e.visibilityState==="visible"&&e.hasFocus()}function o0e(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`}function a0e(){const[e]=v.useState(()=>new Iye(o0e()));return v.useEffect(()=>(e.start(),()=>{e.dispose()}),[e]),e}const iD="kanna:profile-send-to-starting";function l0e(){try{return window.sessionStorage.getItem(iD)==="1"||window.localStorage.getItem(iD)==="1"}catch{return!1}}function WF(e){return Number((performance.now()-e).toFixed(1))}function kl(e,t,n){!e||!l0e()||console.debug("[kanna/send->starting][client]",{traceId:e.traceId,stage:t,elapsedMs:WF(e.startedAt),serverChatId:e.serverChatId,routeChatIdAtSend:e.routeChatIdAtSend,...n})}function c0e(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 u0e(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 d0e(e,t){return e==="awaiting_disconnect"&&t==="disconnected"?"awaiting_server_ready":"none"}function h0e(e,t){return t==="updating"||t==="restart_pending"?{active:!0,label:"Installing update"}:e==="awaiting_disconnect"||e==="awaiting_server_ready"?{active:!0,label:"Re-deploying Kanna"}:{active:!1,label:""}}const f0e=30,M2="kanna:ui-update-restart",GF="kanna:last-update-reload-request";function m0e(e){return e+f0e}function p0e(e,t){return t>0?t:e}function sS(){return window.sessionStorage.getItem(M2)}function g0e(e){window.sessionStorage.setItem(M2,e)}function v0e(){window.sessionStorage.removeItem(M2)}function b0e(e,t){return e?String(e)!==t:!1}function x0e(){return window.sessionStorage.getItem(GF)}function y0e(e){window.sessionStorage.setItem(GF,String(e))}function _0e(){return"/auth/status"}async function w0e(e=fetch){return(await e(_0e(),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}})).ok}function S0e(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 C0e(e,t){return!e||!t?null:e.runtime.chatId!==t?(e.runtime.chatId,e.runtime.provider,null):e}function k0e(e){var wu,lc,Ah;const t=lu(),n=a0e(),r=op(),[i,s]=v.useState({starredProjectGroups:[],projectGroups:[],stacks:[]}),[o,a]=v.useState(null),[c,d]=v.useState(null),[f,m]=v.useState(null),[g,b]=v.useState(()=>sS()),y=v.useCallback(Q=>{g0e(Q),b(Q)},[]),_=v.useCallback(()=>{v0e(),b(null)},[]),[w,C]=v.useState(null),[E,k]=v.useState([]),[T,R]=v.useState(!1),[A,j]=v.useState(null),[I,U]=v.useState(!1),[M,D]=v.useState({}),[z,P]=v.useState(null),[F,$]=v.useState(null),[B,H]=v.useState(null),[W,te]=v.useState(null),[O,K]=v.useState("connecting"),[ee,V]=v.useState(!1),[ue,ge]=v.useState(!1),[Z,ne]=v.useState(!1),[ie,le]=v.useState(null),[oe,we]=v.useState(!1),[Ce,Oe]=v.useState(!1),[Ze,ft]=v.useState(!1),[Tt,_e]=v.useState(null),[cn,Lt]=v.useState(null),[pt,xt]=v.useState(null),[Bt,Dt]=v.useState([]),[lt,Ot]=v.useState(null),[me,Te]=v.useState(0),He=v.useRef(new Map),tt=lC(lx(Q=>Object.keys(Q.drafts).sort())),Xe=lC(lx(Q=>Object.keys(Q.attachmentDrafts).sort())),yt=v.useRef(0),ze=v.useRef(null),Ke=v.useRef({projectId:null,diffs:null}),Be=bre(mi(Q=>Q.editorPreset)),Ie=v.useMemo(()=>rD(i.projectGroups,o),[o,i.projectGroups]),qe=v.useRef(Ie);v.useLayoutEffect(()=>{qe.current=Ie});const It=v.useMemo(()=>Ie===i.projectGroups?i:{...i,projectGroups:Ie},[i,Ie]);v.useEffect(()=>n.onStatus(K),[n]),v.useEffect(()=>n.subscribe({type:"sidebar"},Q=>{s(Q),a(J=>J&&rD(Q.projectGroups,J)===Q.projectGroups?null:J),V(!0),_e(null)}),[n]),v.useEffect(()=>{if(O!=="connected")return;const Q=[...new Set([...tt,...Xe])].sort();n.command({type:"chat.setDraftProtection",chatIds:Q}).catch(J=>{_e(J instanceof Error?J.message:String(J))})},[Xe,O,tt,n]),v.useEffect(()=>n.subscribe({type:"local-projects"},Q=>{d(Q),ge(!0),_e(null)}),[n]),v.useEffect(()=>n.subscribe({type:"update"},Q=>{m(Q),_e(null)}),[n]),v.useEffect(()=>{O==="connected"&&n.command({type:"update.check",force:!0}).catch(Q=>{_e(Q instanceof Error?Q.message:String(Q))})},[O,n]),v.useEffect(()=>{const Q=f==null?void 0:f.reloadRequestedAt;b0e(Q,x0e())&&Q&&(y0e(Q),y("awaiting_disconnect"))},[y,f==null?void 0:f.reloadRequestedAt]),v.useEffect(()=>{const Q=sS();if(d0e(Q,O)==="awaiting_server_ready"){y("awaiting_server_ready");return}},[O,y]),v.useEffect(()=>{if(sS()!=="awaiting_server_ready")return;let Q=!1,J=null;const Me=async()=>{try{if(await w0e()){if(Q)return;_(),window.location.reload();return}}catch{}Q||(J=window.setTimeout(()=>{Me()},500))};return Me(),()=>{Q=!0,J!==null&&window.clearTimeout(J)}},[O,_]),v.useEffect(()=>{function Q(){f!=null&&f.lastCheckedAt&&(Date.now()-f.lastCheckedAt<=3600*1e3||n.command({type:"update.check"}).catch(J=>{_e(J instanceof Error?J.message:String(J))}))}return window.addEventListener("focus",Q),()=>{window.removeEventListener("focus",Q)}},[n,f==null?void 0:f.lastCheckedAt]),v.useEffect(()=>n.subscribe({type:"keybindings"},Q=>{P(Q),_e(null)}),[n]),v.useEffect(()=>n.subscribe({type:"app-settings"},Q=>{$(Q),Rf(Q),_e(null)}),[n]),v.useEffect(()=>n.subscribe({type:"push-config"},Q=>{H(Q)}),[n]),v.useEffect(()=>n.subscribe({type:"pty-instances"},Q=>{Na.getState().applySnapshot(Q.instances)},Q=>{Q.type==="pty-instances.added"?Na.getState().applyDiff({op:"added",instance:Q.instance}):Q.type==="pty-instances.updated"?Na.getState().applyDiff({op:"updated",instance:Q.instance}):Na.getState().applyDiff({op:"removed",chatId:Q.chatId})}),[n]);const Rt=v.useCallback(async()=>{try{Di.getState().setHydrationStatus("loading");const Q=await n.command({type:"settings.readAppSettings"});$(Q),Rf(Q),_e(null)}catch(Q){Di.getState().setHydrationStatus("error"),_e(Q instanceof Error?Q.message:String(Q))}},[n]),xn=v.useCallback(async(Q,J)=>{try{await n.command({type:"chat.setPolicyOverride",chatId:Q,policyOverride:J}),_e(null)}catch(Me){throw _e(Me instanceof Error?Me.message:String(Me)),Me}},[n]),on=v.useCallback(async Q=>{try{Di.getState().applyOptimisticPatch(Q);const J=await n.command({type:"settings.writeAppSettingsPatch",patch:Q});$(J),Rf(J),_e(null)}catch(J){throw _e(J instanceof Error?J.message:String(J)),await Rt(),J}},[Rt,n]),Zt=v.useCallback(async Q=>{try{await n.command({type:"settings.testMcpServer",id:Q}),_e(null)}catch(J){throw _e(J instanceof Error?J.message:String(J)),J}},[n]),At=v.useCallback(async Q=>{try{Di.getState().applyOptimisticPatch({cloudflareTunnel:Q});const J=await n.command({type:"appSettings.setCloudflareTunnel",patch:Q});$(J),Rf(J),_e(null)}catch(J){throw _e(J instanceof Error?J.message:String(J)),await Rt(),J}},[Rt,n]),_t=v.useCallback(async Q=>{try{Di.getState().applyOptimisticPatch({claudeAuth:Q});const J=await n.command({type:"appSettings.setClaudeAuth",patch:Q});$(J),Rf(J),_e(null)}catch(J){throw _e(J instanceof Error?J.message:String(J)),await Rt(),J}},[Rt,n]),gt=v.useCallback(async Q=>await n.command({type:"appSettings.testOAuthToken",token:Q}),[n]),Ct=v.useCallback(async()=>{try{const Q=await n.command({type:"settings.readLlmProvider"});te(Q),_e(null)}catch(Q){_e(Q instanceof Error?Q.message:String(Q))}},[n]),vt=v.useCallback(async Q=>{try{const J=await n.command({type:"settings.writeLlmProvider",provider:Q.provider,apiKey:Q.apiKey,model:Q.model,baseUrl:Q.baseUrl});te(J),_e(null)}catch(J){throw _e(J instanceof Error?J.message:String(J)),J}},[n]),Ut=v.useCallback(async Q=>await n.command({type:"settings.validateLlmProvider",provider:Q.provider,apiKey:Q.apiKey,model:Q.model,baseUrl:Q.baseUrl}),[n]);v.useEffect(()=>{O==="connected"&&Rt()},[O,Rt]),v.useEffect(()=>{if(O!=="connected"||(F==null?void 0:F.browserSettingsMigrated)!==!1)return;const Q=Qye();Q&&on(Q).then(Zye).catch(()=>{})},[F==null?void 0:F.browserSettingsMigrated,O,on]),v.useEffect(()=>{O==="connected"&&Ct()},[O,Ct]),v.useEffect(()=>{function Q(){Te(J=>J+1)}return window.addEventListener("focus",Q),document.addEventListener("visibilitychange",Q),()=>{window.removeEventListener("focus",Q),document.removeEventListener("visibilitychange",Q)}},[]),v.useEffect(()=>{if(!e){C(null),ne(!0);return}++yt.current,qe.current.length,qe.current.reduce((J,Me)=>J+Me.chats.length,0),C(null),ne(!1);const Q=n.subscribe({type:"chat",chatId:e,recentLimit:r0e},J=>{if(J!=null&&J.runtime.chatId){const Me=[...He.current.values()].filter(at=>at.serverChatId===J.runtime.chatId).sort((at,Mn)=>Mn.startedAt-at.startedAt)[0];Me&&Me.snapshotAt===void 0&&(Me.snapshotAt=performance.now(),kl(Me,"chat_snapshot_received",{status:J.runtime.status,messageCount:J.messages.length}))}if(C(Me=>{const at=Yye(Me,J);return J==null||J.runtime.chatId,J==null||J.runtime.provider,J==null||J.runtime.status,J==null||J.messages.length,at?Me:J}),j((J==null?void 0:J.history.olderCursor)??null),U((J==null?void 0:J.history.hasOlder)??!1),ne(!0),_e(null),J){const Me=T2.getState();Me.setForChat(J.runtime.chatId,J.slashCommands??[]),Me.setLoadingForChat(J.runtime.chatId,J.slashCommandsLoading??!1)}});return()=>{qe.current.length,qe.current.reduce((J,Me)=>J+Me.chats.length,0),Q()}},[e,n]),v.useEffect(()=>{if(e)return n.subscribe({type:"workflows",chatId:e},Q=>{A2.getState().setRuns(Q.chatId,Q.runs)})},[e,n]),v.useEffect(()=>{if(ie)return;const Q=Ie[0];Q&&le(Q.groupKey)},[ie,Ie]),v.useEffect(()=>{if(!e||!ee||!Z)return;if(Ie.some(J=>J.chats.some(Me=>Me.chatId===e))){pt===e&&xt(null);return}pt!==e&&t("/")},[e,Z,t,pt,Ie,ee]),v.useEffect(()=>{w&&(le(w.runtime.projectId),pt===w.runtime.chatId&&xt(null))},[w,pt]),v.useEffect(()=>{if(!e||!ee||!s0e())return;const Q=Ie.flatMap(J=>J.chats).find(J=>J.chatId===e);Q!=null&&Q.unread&&n.command({type:"chat.markRead",chatId:e}).catch(J=>{_e(J instanceof Error?J.message:String(J))})},[e,me,Ie,ee,n]),v.useEffect(()=>{k([]),R(!1),j(null),U(!1)},[e]);const it=v.useMemo(()=>C0e(w,e),[e,w]),ye=v.useMemo(()=>(it==null?void 0:it.runtime.projectId)??u0e(Ie,e)??ie,[e,it==null?void 0:it.runtime.projectId,ie,Ie]),rt=v.useMemo(()=>{const Q=ye?M[ye]??null:null;return ye&&Q?(Ke.current={projectId:ye,diffs:Q},Q):ye&&Ke.current.projectId===ye?Ke.current.diffs:Q},[ye,M]);v.useEffect(()=>ye?n.subscribe({type:"project-git",projectId:ye},J=>{D(Me=>{const at=J??null;return Wye(Me[ye]??null,at)||Vye(Me[ye]??null,at)?Me:{...Me,[ye]:at}}),_e(null)}):void 0,[ye,n]),v.useEffect(()=>{w==null||w.runtime.chatId,w==null||w.runtime.provider,it==null||it.runtime.chatId,it==null||it.runtime.provider},[e,it,w,pt]);const Ye=v.useMemo(()=>eD(E,(it==null?void 0:it.messages)??[]),[it==null?void 0:it.messages,E]),Je=e??tD,xe=v.useMemo(()=>Bt.filter(Q=>Q.scopeId===Je).map(Q=>Q.entry),[Je,Bt]),Pe=v.useMemo(()=>[...Ye,...xe],[xe,Ye]),Ue=v.useMemo(()=>zF(Pe),[Pe]),Ve=v.useMemo(()=>Xye(Ue),[Ue]),Wt=v.useMemo(()=>yye(Ue),[Ue]),Fe=(it==null?void 0:it.runtime)??null,Vt=(it==null?void 0:it.queuedMessages)??[],wn=((lt==null?void 0:lt.scopeId)===Je&&(!Fe||Fe.status==="idle")?"starting":null)??(Fe==null?void 0:Fe.status)??null,Er=(it==null?void 0:it.availableProviders)??Qf,En=wye(wn??void 0),$n=_ye(wn??void 0),Nr=(Fe==null?void 0:Fe.isDraining)??!1,G=((wu=c==null?void 0:c.projects[0])==null?void 0:wu.localPath)??null,be=(Fe==null?void 0:Fe.localPath)??G??((lc=Ie[0])==null?void 0:lc.localPath),Ae=!!(ie??(Fe==null?void 0:Fe.projectId)??((Ah=Ie[0])==null?void 0:Ah.groupKey)??G);v.useEffect(()=>{(lt==null?void 0:lt.scopeId)===Je&&Fe!=null&&Fe.status&&Fe.status!=="idle"&&Ot(null)},[lt,Je,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!(lt!=null&&lt.ackedAt)||lt.scopeId!==Je||Fe!=null&&Fe.status&&Fe.status!=="idle")return;const Q=window.setTimeout(()=>{Ot(J=>(J==null?void 0:J.scopeId)===Je&&J.ackedAt===lt.ackedAt?null:J)},300);return()=>window.clearTimeout(Q)},[lt,Je,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting")return;const Q=[...He.current.values()].filter(J=>J.serverChatId===e).sort((J,Me)=>Me.startedAt-J.startedAt)[0];!Q||Q.startingStatusAt!==void 0||(Q.startingStatusAt=performance.now(),kl(Q,"runtime_status_starting",{status:Fe.status}))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||!Fe||Fe.status==="starting")return;const Q=[...He.current.values()].filter(J=>J.serverChatId===e).sort((J,Me)=>Me.startedAt-J.startedAt)[0];!Q||Q.startingRenderedAt!==void 0||(kl(Q,"starting_not_observed",{status:Fe.status}),He.current.delete(Q.traceId))},[e,Fe]),v.useLayoutEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting"){ze.current=null;return}const Q=[...He.current.values()].filter(J=>J.serverChatId===e).sort((J,Me)=>Me.startedAt-J.startedAt)[0];Q&&ze.current!==Q.traceId&&(ze.current=Q.traceId,Q.startingRenderedAt=performance.now(),kl(Q,"starting_render_committed",{totalMs:WF(Q.startedAt)}),He.current.delete(Q.traceId))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{Dt(Q=>{const J=t0e(Q,Je,Ye);return J.length===Q.length&&J.every((Me,at)=>Me===Q[at])?Q:J})},[Je,Ye]);const et=v.useCallback(async()=>{if(!(!e||!A||T||!I)){R(!0);try{const Q=await n.command({type:"chat.loadHistory",chatId:e,beforeCursor:A,limit:i0e});k(J=>eD(Q.messages,J)),j(Q.olderCursor),U(Q.hasOlder),_e(null)}catch(Q){const J=Q instanceof Error?Q.message:String(Q);_e(J)}finally{R(!1)}}},[e,I,A,T,n]),ht=v.useCallback(async Q=>{const J=vi.getState(),Me=e?J.getComposerState(e):J.getComposerState(sm),at=await n.command({type:"chat.create",projectId:Q});J.initializeComposerForChat(at.chatId,{sourceState:Me}),le(Q),xt(at.chatId),t(`/chat/${at.chatId}`),we(!1),_e(null)},[e,t,n]),Qe=v.useCallback(async Q=>Q.kind==="project_id"?{projectId:Q.projectId}:Q.kind==="local_path"?{projectId:(await n.command({type:"project.open",localPath:Q.localPath})).projectId,localPath:Q.localPath}:{projectId:(await n.command(Q.project.mode==="new"?{type:"project.create",localPath:Q.project.localPath,title:Q.project.title}:{type:"project.open",localPath:Q.project.localPath})).projectId,localPath:Q.project.localPath},[n]),ot=v.useCallback(async Q=>{try{const J=Q.kind==="project_id"?null:Q.kind==="local_path"?Q.localPath:Q.project.localPath;J&&Lt(J);const{projectId:Me}=await Qe(Q);await ht(Me)}catch(J){_e(J instanceof Error?J.message:String(J))}finally{Lt(null)}},[ht,Qe]),un=v.useCallback(async Q=>{await ot({kind:"project_id",projectId:Q})},[ot]),qn=v.useCallback(async Q=>{try{const J=await n.command({type:"chat.fork",chatId:Q.chatId}),Me=vi.getState();Me.initializeComposerForChat(J.chatId,{sourceState:Me.getComposerState(Q.chatId)}),xt(J.chatId),t(`/chat/${J.chatId}`),we(!1),_e(null)}catch(J){_e(J instanceof Error?J.message:String(J))}},[t,n]),lr=v.useCallback(async Q=>{await ot({kind:"local_path",localPath:Q})},[ot]),Kr=v.useCallback(async Q=>{await ot({kind:"project_request",project:Q})},[ot]),os=v.useCallback(async Q=>{try{await n.command({type:"update.check",force:Q==null?void 0:Q.force}),_e(null)}catch(J){_e(J instanceof Error?J.message:String(J))}},[n]),ci=v.useCallback(async Q=>{y("awaiting_disconnect");try{const J=await n.command({type:"update.install",version:Q});if(!J.ok){_(),_e(null),await r.alert({title:J.userTitle??"Update failed",description:J.userMessage??"Kanna could not install the update. Try again later.",closeLabel:"OK"});return}if(J.ok&&J.action==="reload"){window.location.reload();return}_e(null)}catch(J){_(),_e(J instanceof Error?J.message:String(J))}},[_,r,y,n]),fo=v.useCallback(async()=>{y("awaiting_disconnect");try{const Q=await n.command({type:"update.reload"});if(!Q.ok){_(),_e(null),await r.alert({title:Q.userTitle??"Re-deploy failed",description:Q.userMessage??"Kanna could not re-deploy. Try again later.",closeLabel:"OK"});return}if(Q.action==="reload"){window.location.reload();return}_e(null)}catch(Q){_(),_e(Q instanceof Error?Q.message:String(Q))}},[_,r,y,n]),Si=v.useCallback(async()=>{try{const Q=await fetch("/auth/logout",{method:"POST",headers:{Accept:"application/json"}});if(!Q.ok)throw new Error(`Sign out failed with status ${Q.status}`);_e(null),window.location.reload()}catch(Q){_e(Q instanceof Error?Q.message:String(Q))}},[]),kt=v.useCallback(async(Q,J)=>{var Su;const Me=(J==null?void 0:J.attachments)??[],at=Ic(),Mn=Ic(),Xr=j2(Q,Me),Bs=e??tD;Ot({scopeId:Bs,ackedAt:null});const Fs={traceId:Mn,optimisticId:at,startedAt:performance.now(),serverChatId:e,routeChatIdAtSend:e,contentPreview:Q.slice(0,80)};He.current.set(Mn,Fs),kl(Fs,"handle_send_called",{optimisticScopeId:Bs,attachments:Me.length,contentLength:Q.length,contentPreview:Fs.contentPreview});const jh=e0e(Ye,Xr)+Bt.filter(Hn=>Hn.scopeId===Bs&&Hn.signature===Xr).length+1;Dt(Hn=>[...Hn,{id:at,scopeId:Bs,signature:Xr,requiredMatchCount:jh,entry:{_id:`optimistic:${at}`,kind:"user_prompt",content:Q,attachments:Me,createdAt:Date.now()}}]),kl(Fs,"optimistic_prompt_added",{optimisticId:at,optimisticScopeId:Bs});try{let Hn=ie??((Su=Ie[0])==null?void 0:Su.groupKey)??null;if(!e&&!Hn&&G&&(Hn=(await n.command({type:"project.open",localPath:G})).projectId,le(Hn)),!e&&!Hn)throw new Error("Open a project first");const Za=cC.getState().autoResumeOnRateLimit,Qr=await n.command({type:"chat.send",chatId:e??void 0,projectId:e?void 0:Hn??void 0,clientTraceId:Mn,provider:J==null?void 0:J.provider,content:Q,attachments:Me,model:J==null?void 0:J.model,modelOptions:J==null?void 0:J.modelOptions,planMode:J==null?void 0:J.planMode,autoResumeOnRateLimit:Za});if(Fs.ackAt=performance.now(),Fs.serverChatId=Qr.chatId??Fs.serverChatId,Qr.queued?(Dt($s=>n0e($s,at,{queued:!0})),Ot(null)):Ot($s=>$s&&{scopeId:!e&&Qr.chatId?Qr.chatId:$s.scopeId,ackedAt:performance.now()}),kl(Fs,"chat_send_ack_received",{resultChatId:Qr.chatId??null,queued:Qr.queued??!1}),!e&&Qr.chatId){Dt(Lp=>Lp.map(Mh=>Mh.id===at?{...Mh,scopeId:Qr.chatId}:Mh));const $s=vi.getState();$s.setComposerState(Qr.chatId,c0e(J)??$s.getComposerState(sm)),xt(Qr.chatId),t(`/chat/${Qr.chatId}`)}_e(null)}catch(Hn){throw Dt(Za=>Za.filter(Qr=>Qr.id!==at)),Ot(null),kl(Fs,"handle_send_failed",{error:Hn instanceof Error?Hn.message:String(Hn)}),He.current.delete(Mn),_e(Hn instanceof Error?Hn.message:String(Hn)),Hn}},[e,G,t,Bt,ie,Ye,Ie,n]),Qt=v.useCallback(async Q=>{if(e)try{await n.command({type:"message.steer",chatId:e,queuedMessageId:Q}),_e(null)}catch(J){_e(J instanceof Error?J.message:String(J))}},[e,n]),Sn=v.useCallback(async Q=>{if(e)try{await n.command({type:"message.dequeue",chatId:e,queuedMessageId:Q}),_e(null)}catch(J){_e(J instanceof Error?J.message:String(J))}},[e,n]),pn=v.useCallback(async()=>{if(e)try{await n.command({type:"chat.cancel",chatId:e})}catch(Q){_e(Q instanceof Error?Q.message:String(Q))}},[e,n]),Yr=v.useCallback(async()=>{if(e)try{await n.command({type:"chat.stopDraining",chatId:e})}catch(Q){_e(Q instanceof Error?Q.message:String(Q))}},[e,n]),Ya=v.useCallback(async Q=>{const J=await r.prompt({title:"Rename Chat",initialValue:Q.title,confirmLabel:"Rename"});if(!(!J||J===Q.title))try{await n.command({type:"chat.rename",chatId:Q.chatId,title:J}),_e(null)}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[r,n]),mo=v.useCallback(async Q=>{if(await r.confirm({title:"Delete Chat",description:`Delete "${Q.title}"? This cannot be undone.`,confirmLabel:"Delete",confirmVariant:"destructive"}))try{if(await n.command({type:"chat.delete",chatId:Q.chatId}),Q.chatId===e){const Me=nD(Ie,Q.chatId);t(Me?`/chat/${Me}`:"/")}}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[e,r,t,Ie,n]),Ko=v.useCallback(async Q=>{try{if(await n.command({type:"chat.archive",chatId:Q.chatId}),Q.chatId===e){const J=nD(Ie,Q.chatId);t(J?`/chat/${J}`:"/")}_e(null)}catch(J){_e(J instanceof Error?J.message:String(J))}},[e,t,Ie,n]),Ps=v.useCallback(async Q=>{try{xt(Q),await n.command({type:"chat.unarchive",chatId:Q}),t(`/chat/${Q}`),_e(null)}catch(J){xt(null),_e(J instanceof Error?J.message:String(J))}},[t,n]),Xa=v.useCallback(async Q=>{try{await n.command({type:"project.remove",projectId:Q}),Ml.getState().clearProject(Q),Li.getState().clearProject(Q),(Fe==null?void 0:Fe.projectId)===Q&&t("/"),_e(null)}catch(J){_e(J instanceof Error?J.message:String(J))}},[t,Fe,n]),nr=v.useCallback(async(Q,J)=>{try{await n.command({type:"project.setStar",projectId:Q,starred:J}),_e(null)}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[n]),po=v.useCallback(async Q=>{a(Q);try{await n.command({type:"sidebar.reorderProjectGroups",projectIds:Q}),_e(null)}catch(J){a(null),_e(J instanceof Error?J.message:String(J))}},[n]),go=v.useCallback(async(Q,J)=>{try{await n.command({type:"stack.create",title:Q,projectIds:J}),_e(null)}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[n]),vo=v.useCallback(async(Q,J)=>{try{await n.command({type:"stack.rename",stackId:Q,title:J}),_e(null)}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[n]),Ci=v.useCallback(async Q=>{try{await n.command({type:"stack.remove",stackId:Q}),_e(null)}catch(J){_e(J instanceof Error?J.message:String(J))}},[n]),Yo=v.useCallback(async(Q,J)=>{try{await n.command({type:"stack.addProject",stackId:Q,projectId:J}),_e(null)}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[n]),Xo=v.useCallback(async(Q,J)=>{try{await n.command({type:"stack.removeProject",stackId:Q,projectId:J}),_e(null)}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[n]),ki=v.useCallback(async(Q,J,Me)=>{try{const at=vi.getState(),Mn=e?at.getComposerState(e):at.getComposerState(sm),Xr=await n.command({type:"chat.create",projectId:Q,stackId:J,stackBindings:Me});at.initializeComposerForChat(Xr.chatId,{sourceState:Mn}),le(Q),xt(Xr.chatId),t(`/chat/${Xr.chatId}`),we(!1),_e(null)}catch(at){_e(at instanceof Error?at.message:String(at))}},[e,t,n]),Ee=v.useCallback(async Q=>{try{const J=await n.command({type:"stack.listWorktrees",projectId:Q});return _e(null),J.worktrees}catch(J){return _e(J instanceof Error?J.message:String(J)),[]}},[n]),Ge=v.useCallback(async()=>await n.command({type:"sessions.importClaude"}),[n]),jt=v.useCallback(async Q=>{const J=mi.getState();_e(null),await n.command({type:"system.openExternal",...Q,editor:Q.action==="open_editor"?Q.editor??{preset:J.editorPreset,commandTemplate:J.editorCommandTemplate}:void 0})},[n]),X=v.useCallback(async(Q,J)=>{var at,Mn;const Me=(Fe==null?void 0:Fe.localPath)??((at=c==null?void 0:c.projects[0])==null?void 0:at.localPath)??((Mn=Ie[0])==null?void 0:Mn.localPath);if(Me)try{await jt({action:Q,localPath:Me,editor:J})}catch(Xr){_e(Xr instanceof Error?Xr.message:String(Xr))}},[c==null?void 0:c.projects,jt,Fe==null?void 0:Fe.localPath,Ie]),Le=v.useCallback(async Q=>{var J;try{if(typeof navigator>"u"||!((J=navigator.clipboard)!=null&&J.writeText))throw new Error("Clipboard is not available");await navigator.clipboard.writeText(Q),_e(null)}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[]),dn=v.useCallback(async(Q,J="open_editor",Me)=>{try{await jt({action:J,localPath:Q.path,line:Q.line,column:Q.column,editor:Me})}catch(at){_e(at instanceof Error?at.message:String(at))}},[jt]),as=v.useCallback(async(Q,J)=>{try{await jt({action:Q,localPath:J})}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[jt]),Fi=v.useCallback(()=>{var J;const Q=S0e({selectedProjectId:ie,sidebarProjectId:(J=Ie[0])==null?void 0:J.groupKey,fallbackLocalProjectPath:G});if(Q){ot(Q);return}t("/")},[G,t,ie,Ie,ot]),Qo=v.useCallback(()=>we(!0),[]),sc=v.useCallback(()=>we(!1),[]),bo=v.useCallback(()=>Oe(!0),[]),Qa=v.useCallback(()=>Oe(!1),[]),jp=v.useCallback(()=>ft(!0),[]),Th=v.useCallback(()=>ft(!1),[]),Mp=v.useCallback(async(Q,J,Me)=>{if(e)try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Q,result:{questions:J,answers:Me}})}catch(at){_e(at instanceof Error?at.message:String(at))}},[e,n]),oc=v.useCallback(async(Q,J,Me,at)=>{if(e){J&&vi.getState().setChatComposerPlanMode(e,!1);try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Q,result:{confirmed:J,...Me?{clearContext:!0}:{},...at?{message:at}:{}}})}catch(Mn){_e(Mn instanceof Error?Mn.message:String(Mn))}}},[e,n]),Os=v.useCallback(async(Q,J,Me,at)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Q,toolUseId:J,result:{questions:Me,answers:at}})}catch(Mn){_e(Mn instanceof Error?Mn.message:String(Mn))}},[e,n]),Rh=v.useCallback(async(Q,J,Me)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Q,toolUseId:J,result:Me})}catch(at){_e(at instanceof Error?at.message:String(at))}},[e,n]),ac=v.useCallback(async(Q,J)=>{if(e)try{await n.command({type:"chat.toolRequestAnswer",chatId:e,toolRequestId:Q,decision:J})}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[e,n]),zs=h0e(g,f==null?void 0:f.status);return{socket:n,activeChatId:e,activeProjectId:ye,sidebarData:It,localProjects:c,updateSnapshot:f,chatSnapshot:w,chatDiffSnapshot:rt,keybindings:z,appSettings:F,pushConfig:B,llmProvider:W,connectionStatus:O,sidebarReady:ee,uiRestartActive:zs.active,uiRestartLabel:zs.label,localProjectsReady:ue,commandError:Tt,startingLocalPath:cn,sidebarOpen:oe,sidebarCollapsed:Ce,messages:Ue,queuedMessages:Vt,previousPrompt:Ve,latestToolIds:Wt,runtime:Fe,runtimeStatus:wn,isHistoryLoading:T,hasOlderHistory:I,availableProviders:Er,isProcessing:En,canCancel:$n,isDraining:Nr,navbarLocalPath:be,editorLabel:Be,hasSelectedProject:Ae,addProjectModalOpen:Ze,openSidebar:Qo,closeSidebar:sc,collapseSidebar:bo,expandSidebar:Qa,openAddProjectModal:jp,closeAddProjectModal:Th,loadOlderHistory:et,handleCreateChat:un,handleForkChat:qn,handleOpenLocalProject:lr,handleCreateProject:Kr,handleCheckForUpdates:os,handleInstallUpdate:ci,handleForceReload:fo,handleReadAppSettings:Rt,handleWriteAppSettings:on,handleTestMcpServer:Zt,handleSetChatPolicyOverride:xn,handleWriteCloudflareTunnel:At,handleWriteClaudeAuth:_t,handleTestOAuthToken:gt,handleReadLlmProvider:Ct,handleWriteLlmProvider:vt,handleValidateLlmProvider:Ut,handleSignOut:Si,handleSend:kt,handleSteerQueuedMessage:Qt,handleRemoveQueuedMessage:Sn,handleCancel:pn,handleStopDraining:Yr,handleRenameChat:Ya,handleArchiveChat:Ko,handleOpenArchivedChat:Ps,handleDeleteChat:mo,handleHideProject:Xa,handleToggleProjectStar:nr,handleReorderProjectGroups:po,stacks:It.stacks,handleCreateStack:go,handleRenameStack:vo,handleRemoveStack:Ci,handleAddProjectToStack:Yo,handleRemoveProjectFromStack:Xo,handleCreateStackChat:ki,handleListStackWorktrees:Ee,importClaudeSessions:Ge,handleCopyPath:Le,handleOpenExternal:X,handleOpenExternalPath:as,handleOpenLocalLink:dn,handleCompose:Fi,handleAskUserQuestion:Mp,handleExitPlanMode:oc,handleSubagentAskUserQuestion:Os,handleSubagentExitPlanMode:Rh,handleToolRequestAnswer:ac}}const sD=/<thinking>([\s\S]*?)<\/thinking>/gi;function E0e(e){const t=[];let n=0;sD.lastIndex=0;let r;for(;(r=sD.exec(e))!==null;){if(r.index>n){const o=e.slice(n,r.index);o.length>0&&t.push({kind:"text",content:o})}t.push({kind:"thinking",content:r[1]??""}),n=r.index+r[0].length}const i=e.slice(n),s=i.search(/<thinking>/i);if(s!==-1){const o=i.slice(0,s);o.length>0&&t.push({kind:"text",content:o});const a=i.slice(s+10);t.push({kind:"thinking",content:a})}else i.length>0&&t.push({kind:"text",content:i});return N0e(t)}function N0e(e){const t=[];for(const n of e){const r=t[t.length-1];n.kind==="text"&&r&&r.kind==="text"?r.content+=n.content:t.push(n)}return t}const T0e=v.memo(function({content:t}){const[n,r]=v.useState(!1),i=t.trim();return i.length===0?null:u.jsxs("div",{className:"my-3 first:mt-0 last:mb-0",children:[u.jsxs("button",{type:"button",onClick:()=>r(s=>!s),"aria-expanded":n,className:"group/thinking flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer",children:[u.jsx(Kv,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"font-medium uppercase tracking-wider",children:"Thinking"}),u.jsx(no,{className:de("h-3.5 w-3.5 transition-transform duration-200",n&&"rotate-90")})]}),n&&u.jsx("div",{className:"mt-2 border-l-2 border-muted-foreground/20 pl-3 text-sm text-muted-foreground italic prose prose-sm dark:prose-invert max-w-[70ch]",children:u.jsx(Vo,{remarkPlugins:za,components:Ba,children:i})})]})}),qF=v.memo(function({message:t}){const n=v.useMemo(()=>E0e(t.text),[t.text]);return u.jsx("div",{className:"text-pretty prose prose-sm dark:prose-invert px-0.5 w-full max-w-[70ch] space-y-4",children:n.map((r,i)=>r.kind==="thinking"?u.jsx(T0e,{content:r.content},i):u.jsx(Vo,{remarkPlugins:za,components:Ba,children:r.content},i))})}),kp=({children:e,className:t,animate:n=!0,shimmerWidth:r,...i})=>u.jsx("span",{className:de("mx-auto max-w-md text-foreground/60",n&&"animate-shiny-pulse",t),...i,children:e});function R0e(e){const t=e.split(`
2635
+ `},i),s}function vve(e,t){return e&&"run"in e?async function(n,r){const i=vI(n,{file:r,...t});await e.run(i,r)}:function(n,r){return vI(n,{file:r,...e||t})}}function bI(e){if(e)throw e}var Uw,xI;function bve(){if(xI)return Uw;xI=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=function(d){return typeof Array.isArray=="function"?Array.isArray(d):t.call(d)==="[object Array]"},s=function(d){if(!d||t.call(d)!=="[object Object]")return!1;var f=e.call(d,"constructor"),m=d.constructor&&d.constructor.prototype&&e.call(d.constructor.prototype,"isPrototypeOf");if(d.constructor&&!f&&!m)return!1;var g;for(g in d);return typeof g>"u"||e.call(d,g)},o=function(d,f){n&&f.name==="__proto__"?n(d,f.name,{enumerable:!0,configurable:!0,value:f.newValue,writable:!0}):d[f.name]=f.newValue},a=function(d,f){if(f==="__proto__")if(e.call(d,f)){if(r)return r(d,f).value}else return;return d[f]};return Uw=function c(){var d,f,m,g,b,y,_=arguments[0],w=1,C=arguments.length,E=!1;for(typeof _=="boolean"&&(E=_,_=arguments[1]||{},w=2),(_==null||typeof _!="object"&&typeof _!="function")&&(_={});w<C;++w)if(d=arguments[w],d!=null)for(f in d)m=a(_,f),g=a(d,f),_!==g&&(E&&g&&(s(g)||(b=i(g)))?(b?(b=!1,y=m&&i(m)?m:[]):y=m&&s(m)?m:{},o(_,{name:f,newValue:c(E,y,g)})):typeof g<"u"&&o(_,{name:f,newValue:g}));return _},Uw}var xve=bve();const Vw=_x(xve);function eC(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function yve(){const e=[],t={run:n,use:r};return t;function n(...i){let s=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);a(null,...i);function a(c,...d){const f=e[++s];let m=-1;if(c){o(c);return}for(;++m<i.length;)(d[m]===null||d[m]===void 0)&&(d[m]=i[m]);i=d,f?_ve(f,a)(...d):o(null,...d)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function _ve(e,t){let n;return r;function r(...o){const a=e.length>o.length;let c;a&&o.push(i);try{c=e.apply(this,o)}catch(d){const f=d;if(a&&n)throw f;return i(f)}a||(c&&c.then&&typeof c.then=="function"?c.then(s,i):c instanceof Error?i(c):s(c))}function i(o,...a){n||(n=!0,t(o,...a))}function s(o){i(null,o)}}const To={basename:wve,dirname:Sve,extname:Cve,join:kve,sep:"/"};function wve(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');Sp(e);let n=0,r=-1,i=e.length,s;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else r<0&&(s=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,a=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else o<0&&(s=!0,o=i+1),a>-1&&(e.codePointAt(i)===t.codePointAt(a--)?a<0&&(r=i):(a=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function Sve(e){if(Sp(e),e.length===0)return".";let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||(r=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function Cve(e){Sp(e);let t=e.length,n=-1,r=0,i=-1,s=0,o;for(;t--;){const a=e.codePointAt(t);if(a===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),a===46?i<0?i=t:s!==1&&(s=1):i>-1&&(s=-1)}return i<0||n<0||s===0||s===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function kve(...e){let t=-1,n;for(;++t<e.length;)Sp(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":Eve(n)}function Eve(e){Sp(e);const t=e.codePointAt(0)===47;let n=Nve(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function Nve(e,t){let n="",r=0,i=-1,s=0,o=-1,a,c;for(;++o<=e.length;){if(o<e.length)a=e.codePointAt(o);else{if(a===47)break;a=47}if(a===47){if(!(i===o-1||s===1))if(i!==o-1&&s===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf("/"),c!==n.length-1){c<0?(n="",r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf("/")),i=o,s=0;continue}}else if(n.length>0){n="",r=0,i=o,s=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,s=0}else a===46&&s>-1?s++:s=-1}return n}function Sp(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const Tve={cwd:Rve};function Rve(){return"/"}function tC(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function Ave(e){if(typeof e=="string")e=new URL(e);else if(!tC(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return jve(e)}function jve(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(t)}const Ww=["history","path","basename","stem","extname","dirname"];class eF{constructor(t){let n;t?tC(t)?n={path:t}:typeof t=="string"||Mve(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":Tve.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<Ww.length;){const s=Ww[r];s in n&&n[s]!==void 0&&n[s]!==null&&(this[s]=s==="history"?[...n[s]]:n[s])}let i;for(i in n)Ww.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?To.basename(this.path):void 0}set basename(t){qw(t,"basename"),Gw(t,"basename"),this.path=To.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?To.dirname(this.path):void 0}set dirname(t){yI(this.basename,"dirname"),this.path=To.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?To.extname(this.path):void 0}set extname(t){if(Gw(t,"extname"),yI(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=To.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){tC(t)&&(t=Ave(t)),qw(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?To.basename(this.path,this.extname):void 0}set stem(t){qw(t,"stem"),Gw(t,"stem"),this.path=To.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const i=this.message(t,n,r);throw i.fatal=!0,i}info(t,n,r){const i=this.message(t,n,r);return i.fatal=void 0,i}message(t,n,r){const i=new li(t,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function Gw(e,t){if(e&&e.includes(To.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+To.sep+"`")}function qw(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function yI(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function Mve(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Lve=(function(e){const r=this.constructor.prototype,i=r[e],s=function(){return i.apply(s,arguments)};return Object.setPrototypeOf(s,r),s}),Ive={}.hasOwnProperty;class h2 extends Lve{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=yve()}copy(){const t=new h2;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(Vw(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(Xw("data",this.frozen),this.namespace[t]=n,this):Ive.call(this.namespace,t)&&this.namespace[t]||void 0:t?(Xw("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=n.call(t,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=_v(t),r=this.parser||this.Parser;return Kw("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),Kw("process",this.parser||this.Parser),Yw("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(s,o){const a=_v(t),c=r.parse(a);r.run(c,a,function(f,m,g){if(f||!m||!g)return d(f);const b=m,y=r.stringify(b,g);Ove(y)?g.value=y:g.result=y,d(f,g)});function d(f,m){f||!m?o(f):s?s(m):n(void 0,m)}}}processSync(t){let n=!1,r;return this.freeze(),Kw("processSync",this.parser||this.Parser),Yw("processSync",this.compiler||this.Compiler),this.process(t,i),wI("processSync","process",n),r;function i(s,o){n=!0,bI(s),r=o}}run(t,n,r){_I(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?s(void 0,r):new Promise(s);function s(o,a){const c=_v(n);i.run(t,c,d);function d(f,m,g){const b=m||t;f?a(f):o?o(b):r(void 0,b,g)}}}runSync(t,n){let r=!1,i;return this.run(t,n,s),wI("runSync","run",r),i;function s(o,a){bI(o),i=a,r=!0}}stringify(t,n){this.freeze();const r=_v(n),i=this.compiler||this.Compiler;return Yw("stringify",i),_I(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(Xw("use",this.frozen),t!=null)if(typeof t=="function")c(t,n);else if(typeof t=="object")Array.isArray(t)?a(t):o(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function s(d){if(typeof d=="function")c(d,[]);else if(typeof d=="object")if(Array.isArray(d)){const[f,...m]=d;c(f,m)}else o(d);else throw new TypeError("Expected usable value, not `"+d+"`")}function o(d){if(!("plugins"in d)&&!("settings"in d))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");a(d.plugins),d.settings&&(i.settings=Vw(!0,i.settings,d.settings))}function a(d){let f=-1;if(d!=null)if(Array.isArray(d))for(;++f<d.length;){const m=d[f];s(m)}else throw new TypeError("Expected a list of plugins, not `"+d+"`")}function c(d,f){let m=-1,g=-1;for(;++m<r.length;)if(r[m][0]===d){g=m;break}if(g===-1)r.push([d,...f]);else if(f.length>0){let[b,...y]=f;const _=r[g][1];eC(_)&&eC(b)&&(b=Vw(!0,_,b)),r[g]=[d,b,...y]}}}}const Dve=new h2().freeze();function Kw(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function Yw(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function Xw(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function _I(e){if(!eC(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function wI(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function _v(e){return Pve(e)?e:new eF(e)}function Pve(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function Ove(e){return typeof e=="string"||zve(e)}function zve(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Bve="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",SI=[],CI={allowDangerousHtml:!0},Fve=/^(https?|ircs?|mailto|xmpp)$/i,$ve=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function Vo(e){const t=Hve(e),n=Uve(e);return Vve(t.runSync(t.parse(n),n),e)}function Hve(e){const t=e.rehypePlugins||SI,n=e.remarkPlugins||SI,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...CI}:CI;return Dve().use(jge).use(n).use(vve,r).use(t)}function Uve(e){const t=e.children||"",n=new eF;return typeof t=="string"&&(n.value=t),n}function Vve(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,s=t.disallowedElements,o=t.skipHtml,a=t.unwrapDisallowed,c=t.urlTransform||Wve;for(const f of $ve)Object.hasOwn(t,f.from)&&(""+f.from+(f.to?"use `"+f.to+"` instead":"remove it")+Bve+f.id,void 0);return QE(e,d),Bpe(e,{Fragment:u.Fragment,components:i,ignoreInvalidStyle:!0,jsx:u.jsx,jsxs:u.jsxs,passKeys:!0,passNode:!0});function d(f,m,g){if(f.type==="raw"&&g&&typeof m=="number")return o?g.children.splice(m,1):g.children[m]={type:"text",value:f.value},m;if(f.type==="element"){let b;for(b in Hw)if(Object.hasOwn(Hw,b)&&Object.hasOwn(f.properties,b)){const y=f.properties[b],_=Hw[b];(_===null||_.includes(f.tagName))&&(f.properties[b]=c(String(y||""),b,f))}}if(f.type==="element"){let b=n?!n.includes(f.tagName):s?s.includes(f.tagName):!1;if(!b&&r&&typeof m=="number"&&(b=!r(f,m,g)),b&&g&&typeof m=="number")return a&&f.children?g.children.splice(m,1,...f.children):g.children.splice(m,1),m}}}function Wve(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||Fve.test(e.slice(0,t))?e:""}const wv=new Map;function Gve(e){return`${e.id}|${e.contentUrl}|${e.size??0}`}function py(e){const t=Gve(e),n=wv.get(t),[r,i]=v.useState(n??{status:"loading"}),[s,o]=v.useState(t),a=v.useRef(t);return a.current=t,s!==t&&(o(t),i(wv.get(t)??{status:"loading"})),v.useEffect(()=>{if(n&&n.status!=="loading")return;let c=!1;const d=t;return YE(e.contentUrl,X8).then(f=>{if(c||a.current!==d)return;const m={status:"ready",content:f.content,truncated:f.truncated};wv.set(d,m),i(m)}).catch(f=>{if(c||a.current!==d)return;const g={status:"error",message:f instanceof Error?f.message:"Unable to load preview."};wv.set(d,g),i(g)}),()=>{c=!0}},[n,t,e.contentUrl]),r}function qve({source:e}){const t=py(e);return t.status==="loading"?u.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[u.jsx("div",{className:"prose hidden"})," Loading…"]}):t.status==="error"?u.jsx("div",{className:"p-4 text-sm text-destructive",children:t.message}):u.jsxs("div",{className:"space-y-2 p-3",children:[t.truncated?u.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:"Preview truncated to 1024 KB."}):null,u.jsx("div",{className:"prose prose-sm prose-invert max-w-none rounded-xl border border-border bg-background p-4",children:u.jsx(Vo,{remarkPlugins:za,components:Ba,children:t.content})})]})}const Sv=new Map;function Kve(e){return`${e.id}|${e.contentUrl}|${e.size??0}|${e.mimeType}`}function Yve({source:e}){const t=Kve(e),n=Sv.get(t),[r,i]=v.useState(n??{status:"loading"}),[s,o]=v.useState(t),a=v.useRef(t);if(a.current=t,s!==t&&(o(t),i(Sv.get(t)??{status:"loading"})),v.useEffect(()=>{if(n&&n.status!=="loading")return;const g=e.mimeType==="text/tab-separated-values"?" ":",";let b=!1;const y=t;return YE(e.contentUrl,X8).then(_=>{if(b||a.current!==y)return;const w={status:"ready",table:Nde(_.content,g),truncated:_.truncated};Sv.set(y,w),i(w)}).catch(_=>{if(b||a.current!==y)return;const w={status:"error",message:_ instanceof Error?_.message:"Unable to load preview."};Sv.set(y,w),i(w)}),()=>{b=!0}},[n,t,e.contentUrl,e.mimeType]),r.status==="loading")return u.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[u.jsx("table",{className:"sr-only"})," Loading…"]});if(r.status==="error")return u.jsxs("div",{className:"p-4 text-sm text-destructive",children:[u.jsx("table",{className:"sr-only"})," ",r.message]});const{table:c}=r,[d,...f]=c.rows,m=[r.truncated?"Preview truncated to 1024 KB.":null,c.truncatedRows?`Showing first ${c.rows.length} of ${c.rowCount} rows.`:null,c.truncatedColumns?`Showing first ${G1} of ${c.columnCount} columns.`:null].filter(Boolean);return u.jsxs("div",{className:"space-y-2 p-3",children:[m.length?u.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:m.join(" ")}):null,u.jsx("div",{className:"overflow-x-auto rounded-xl border border-border bg-background",children:u.jsxs("table",{className:"min-w-full border-collapse text-xs",children:[d?u.jsx("thead",{className:"sticky top-0 bg-muted",children:u.jsx("tr",{children:d.map((g,b)=>u.jsx("th",{className:"border-b border-border px-3 py-2 text-left font-medium",children:g||" "},b))})}):null,u.jsx("tbody",{children:f.map((g,b)=>u.jsx("tr",{className:"odd:bg-background even:bg-muted/20",children:g.map((y,_)=>u.jsx("td",{className:"max-w-[320px] border-b border-border px-3 py-2 align-top",children:u.jsx("div",{className:"whitespace-pre-wrap break-words",children:y||" "})},_))},b))})]})})]})}function Xve({source:e}){const t=py(e);return t.status==="loading"?u.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[u.jsx("pre",{className:"sr-only"})," Loading…"]}):t.status==="error"?u.jsxs("div",{className:"p-4 text-sm text-destructive",children:[u.jsx("pre",{className:"sr-only"})," ",t.message]}):u.jsxs("div",{className:"space-y-2 p-3",children:[t.truncated?u.jsx(Qve,{children:"Preview truncated to 1024 KB."}):null,u.jsx("pre",{className:"whitespace-pre-wrap break-words rounded-xl border border-border bg-background p-3 text-xs",children:t.content})]})}function Qve({children:e}){return u.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:e})}function Zve({source:e}){const t=py(e),n=v.useMemo(()=>t.status==="ready"?Ede(t.content):"",[t]);return t.status==="loading"?u.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[u.jsx("pre",{className:"sr-only"})," Loading…"]}):t.status==="error"?u.jsxs("div",{className:"p-4 text-sm text-destructive",children:[u.jsx("pre",{className:"sr-only"})," ",t.message]}):u.jsxs("div",{className:"space-y-2 p-3",children:[t.truncated?u.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:"Preview truncated to 1024 KB."}):null,u.jsx("pre",{className:"whitespace-pre-wrap break-words rounded-xl border border-border bg-background p-3 text-xs",children:n})]})}function Jve({source:e}){return u.jsxs("div",{className:"flex h-full flex-col items-stretch justify-center gap-3 p-4",children:[u.jsx("div",{className:"text-sm font-medium text-foreground",children:e.displayName}),u.jsx("audio",{src:e.contentUrl,controls:!0,preload:"metadata",className:"w-full"})]})}function ebe({source:e}){return u.jsx("div",{className:"flex h-full items-center justify-center bg-black/40 p-2",children:u.jsx("video",{src:e.contentUrl,controls:!0,playsInline:!0,preload:"metadata",className:"max-h-[60dvh] w-full rounded-xl"})})}const tbe=200*1024;function nbe(e){const t=e.lastIndexOf(".");if(t<0)return"text";const n=e.slice(t+1).toLowerCase();return{ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",py:"python",go:"go",rs:"rust",java:"java",rb:"ruby",sh:"bash",zsh:"bash",yml:"yaml",yaml:"yaml",css:"css",scss:"scss",html:"html",json:"json",md:"markdown",sql:"sql",cpp:"cpp",c:"c",h:"c",swift:"swift",kt:"kotlin",php:"php",toml:"toml"}[n]??"text"}function rbe({source:e}){const t=py(e),n=t.status==="ready"&&t.content.length<=tbe,r=n?`${e.id}|${e.contentUrl}|${e.size??0}|${t.content.length}`:null,[i,s]=v.useState(null);return v.useEffect(()=>{if(!n||t.status!=="ready"||r===null)return;let o=!1;const a=r;return Y(()=>Promise.resolve().then(()=>$8),void 0).then(async c=>{if(o)return;const d=await c.codeToHtml(t.content,{lang:nbe(e.fileName),theme:"github-dark"});o||s({key:a,html:d})}).catch(()=>{typeof console<"u"&&console.warn("[file-preview] Shiki unavailable; falling back to plain text")}),()=>{o=!0}},[n,r,t,e.fileName]),t.status==="loading"?u.jsxs("div",{className:"p-4 text-sm text-muted-foreground",children:[u.jsx("pre",{className:"sr-only"})," Loading…"]}):t.status==="error"?u.jsxs("div",{className:"p-4 text-sm text-destructive",children:[u.jsx("pre",{className:"sr-only"})," ",t.message]}):i&&i.key===r?u.jsx("div",{className:"overflow-x-auto p-3 text-xs",dangerouslySetInnerHTML:{__html:i.html}}):u.jsxs("div",{className:"space-y-2 p-3",children:[t.truncated?u.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:"Preview truncated to 1024 KB."}):null,u.jsx("pre",{className:"whitespace-pre-wrap break-words rounded-xl border border-border bg-background p-3 text-xs",children:t.content})]})}async function ibe(e){var r;const t=obe(e.contentUrl),n=navigator.share;if(typeof n=="function")try{return await n.call(navigator,{title:e.displayName,url:t}),"shared"}catch(i){if(i instanceof DOMException&&i.name==="AbortError")return"shared"}if((r=navigator.clipboard)!=null&&r.writeText)try{return await navigator.clipboard.writeText(t),"copied"}catch{return"failed"}return"failed"}function sbe(e){const t=document.createElement("a");t.href=e.contentUrl,t.download=e.fileName,t.rel="noopener",document.body.appendChild(t),t.click(),t.remove()}function obe(e){return typeof window>"u"?e:new URL(e,document.baseURI||window.location.href).toString()}function Ch({source:e,open:t,onOpenChange:n}){const r=v.useCallback(()=>n(!1),[n]);return u.jsx(so,{open:t&&e!==null,onOpenChange:n,children:u.jsx(As,{size:"lg",className:"inset-0 h-[100dvh] max-h-none w-full max-w-none translate-x-0 translate-y-0 rounded-none p-0 md:inset-auto md:left-1/2 md:top-1/2 md:h-auto md:max-h-[90dvh] md:w-auto md:max-w-3xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-2xl",children:e?u.jsx(ube,{source:e,onClose:r}):null})})}const abe=120,lbe=.5;function cbe({startY:e,lastY:t,lastT:n,endY:r,now:i}){const s=r-e,o=Math.max(1,i-n),a=(r-t)/o;return s>abe||a>lbe}function ube({source:e,onClose:t}){const n=hbe(e),[r,i]=v.useState(0),s=v.useRef(null),o=v.useCallback(m=>{s.current={y:m.clientY,lastY:m.clientY,lastT:Date.now()};try{m.currentTarget.setPointerCapture(m.pointerId)}catch{}},[]),a=v.useCallback(m=>{if(!s.current)return;const g=m.clientY-s.current.y;g<0||(s.current.lastY=m.clientY,s.current.lastT=Date.now(),i(g))},[]),c=v.useCallback(m=>{const g=s.current;s.current=null;try{m.currentTarget.releasePointerCapture(m.pointerId)}catch{}g&&(cbe({startY:g.y,lastY:g.lastY,lastT:g.lastT,endY:m.clientY,now:Date.now()})?t():i(0))},[t]),d=v.useCallback(()=>{ibe(e)},[e]),f=v.useCallback(()=>sbe(e),[e]);return u.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",style:r>0?{transform:`translateY(${r}px)`,transition:"none"}:void 0,children:[u.jsxs("div",{onPointerDown:o,onPointerMove:a,onPointerUp:c,onPointerCancel:c,className:"border-b border-border px-4 py-3 touch-none",children:[u.jsx("div",{className:"mx-auto mb-2 h-1 w-12 rounded-full bg-muted md:hidden",role:"button","aria-label":"Drag down to close"}),u.jsx(oo,{className:"truncate text-base",children:e.displayName}),u.jsx(np,{className:"truncate text-xs",children:n})]}),u.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain touch-pan-y [-webkit-overflow-scrolling:touch]",role:"region","aria-label":"File preview",children:v.createElement(dbe(e),{source:e})},e.id),u.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border px-4 py-3",children:[u.jsxs(De,{type:"button",variant:"outline",onClick:d,children:[u.jsx(Aq,{className:"mr-2 h-4 w-4"}),"Share"]}),e.origin==="offer_download"?u.jsxs(De,{type:"button",onClick:f,children:[u.jsx(pk,{className:"mr-2 h-4 w-4"}),"Download"]}):null]})]})}function dbe(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=wh(t);return n==="image"?Cpe:n==="pdf"?JL:n==="audio"?Jve:n==="video"?ebe:n==="table"?Yve:n==="markdown"?qve:n==="json"?Zve:n==="code"?rbe:_h(t).kind==="external"?JL:Xve}function hbe(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=wh(t),r=cy(n,e.mimeType),i=e.size?` · ${kh(e.size)}`:"";return`${r}${i}`}function Cp(e,t){return{id:e.id,contentUrl:e.contentUrl,displayName:e.displayName,fileName:e.displayName,relativePath:e.relativePath,mimeType:e.mimeType,size:e.size,origin:t}}function fbe(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function mbe({path:e,linkText:t}){const n=v.useMemo(()=>r2(e),[e]),[r,i]=v.useState({kind:"loading"}),[s,o]=v.useState(!1);v.useEffect(()=>{const A=new AbortController;return fetch(n,{method:"HEAD",signal:A.signal}).then(j=>{var M,D;if(A.signal.aborted)return;if(!j.ok){i({kind:j.status===404?"missing":"error"});return}const I=((D=(M=j.headers.get("Content-Type"))==null?void 0:M.split(";")[0])==null?void 0:D.trim())||"application/octet-stream",U=Number.parseInt(j.headers.get("Content-Length")??"0",10)||0;i({kind:"ready",mimeType:I,size:U})}).catch(()=>{A.signal.aborted||i({kind:"error"})}),()=>A.abort()},[n]);const a=fbe(e),c=t||a,d=Spe(c,28),f=r.kind==="ready"?r.mimeType:"application/octet-stream",m=r.kind==="ready"?r.size:0,g={id:`local-file-${n}`,kind:"file",displayName:d,absolutePath:e,relativePath:e,contentUrl:n,mimeType:f,size:m};if(r.kind==="missing")return u.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:u.jsx(Fo,{attachment:g,disabledReason:"File no longer available"})});const b=wh(g),y=cy(b,f),_=m>0?kh(m):null,w=r.kind==="loading",C=r.kind==="error",E=w?u.jsx("span",{className:"text-muted-foreground",children:"Fetching…"}):C?u.jsx("span",{className:"text-muted-foreground",children:"Unable to load"}):u.jsxs(u.Fragment,{children:[y,_?u.jsxs(u.Fragment,{children:[" · ",u.jsx("span",{className:"tabular-nums",children:_})]}):null]}),k=r.kind==="ready"?_h(g):null,T=k!==null&&!k.openInNewTab,R=[T?"Preview":"Download",c,y,_].filter(Boolean);return T?u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:u.jsx(Fo,{attachment:g,onClick:()=>o(!0),meta:E,ariaLabel:R.join(", ")})}),u.jsx(Ch,{source:s?Cp(g,"local_file_link"):null,open:s,onOpenChange:o})]}):u.jsx("span",{className:"inline-flex align-bottom","data-testid":"local-file-link",children:u.jsx(Fo,{attachment:g,href:n,download:a,meta:E,ariaLabel:R.join(", ")})})}function pbe(e,t){var n,r,i,s,o,a,c,d,f,m;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,...(a=(o=t.providerDefaults)==null?void 0:o.codex)==null?void 0:a.modelOptions}}},cloudflareTunnel:{...e.cloudflareTunnel,...t.cloudflareTunnel},claudeAuth:{tokens:((c=t.claudeAuth)==null?void 0:c.tokens)??e.claudeAuth.tokens,concurrencyDefault:((d=t.claudeAuth)==null?void 0:d.concurrencyDefault)??e.claudeAuth.concurrencyDefault},auth:{...e.auth,...t.auth},uploads:{...e.uploads,...t.uploads},subagents:e.subagents,customMcpServers:e.customMcpServers,claudeDriver:{preference:((f=t.claudeDriver)==null?void 0:f.preference)??e.claudeDriver.preference,lifecycle:{...e.claudeDriver.lifecycle,...(m=t.claudeDriver)==null?void 0:m.lifecycle}},globalPromptAppend:t.globalPromptAppend??e.globalPromptAppend}}const Di=ss()(e=>({settings:null,hydrationStatus:"idle",setHydrationStatus:t=>e({hydrationStatus:t}),setFromServer:t=>e({settings:t,hydrationStatus:"ready"}),applyOptimisticPatch:t=>e(n=>({settings:n.settings?pbe(n.settings,t):n.settings}))})),gbe=[],vbe=e=>{var t;return((t=e.settings)==null?void 0:t.customMcpServers)??gbe},tF=v.createContext(void 0),bbe=e=>e==="light"||e==="dark"||e==="system";function xbe(e){return e==="dark"?"black-translucent":"default"}function kI(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 EI(e){if(typeof document>"u"||typeof window>"u")return;const t=getComputedStyle(document.body).backgroundColor||getComputedStyle(document.documentElement).backgroundColor;t&&kI("theme-color",t),kI("apple-mobile-web-app-status-bar-style",xbe(e)),document.documentElement.style.colorScheme=e}const ub=()=>typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",NI=e=>{if(typeof document>"u")return;const t=e==="system"?ub():e;document.documentElement.classList.toggle("dark",t==="dark")},ybe=()=>{var t;const e=(t=Di.getState().settings)==null?void 0:t.theme;return e&&bbe(e)?e:"system"};function _be({children:e}){const t=Di(o=>{var a;return(a=o.settings)==null?void 0:a.theme}),n=Di(o=>o.applyOptimisticPatch),[r,i]=v.useState(ybe);v.useEffect(()=>{!t||t===r||i(t)},[t,r]),v.useEffect(()=>{NI(r)},[r]),v.useEffect(()=>{const o=r==="system"?ub():r;EI(o)},[r]),v.useEffect(()=>{if(r!=="system")return;const o=window.matchMedia("(prefers-color-scheme: dark)"),a=()=>{NI("system"),EI(ub())};return o.addEventListener?(o.addEventListener("change",a),()=>o.removeEventListener("change",a)):(o.addListener(a),()=>o.removeListener(a))},[r]);const s=v.useMemo(()=>{const o=r==="system"?ub():r;return{theme:r,resolvedTheme:o,setTheme:a=>{i(a),n({theme:a})}}},[n,r]);return u.jsx(tF.Provider,{value:s,children:e})}function gy(){const e=v.useContext(tF);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}function wbe({svg:e,onClose:t}){const[n,r]=v.useState(1),[i,s]=v.useState({x:0,y:0}),[o,a]=v.useState(null);v.useEffect(()=>{const g=b=>{b.key==="Escape"&&t()};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[t]);const c=g=>Math.min(8,Math.max(.25,g)),d=g=>{a({x:g.clientX-i.x,y:g.clientY-i.y})},f=g=>{o&&s({x:g.clientX-o.x,y:g.clientY-o.y})},m=()=>a(null);return Ji.createPortal(u.jsxs("div",{className:"fixed inset-0 z-[100] flex flex-col bg-background/95",role:"dialog","aria-modal":"true","aria-label":"Diagram zoom view",children:[u.jsxs("div",{className:"flex justify-end gap-1 p-2",children:[u.jsx(De,{variant:"ghost",size:"icon","aria-label":"Zoom out",className:"h-9 w-9",onClick:()=>r(g=>c(g-.25)),children:u.jsx(K5,{className:"h-4 w-4"})}),u.jsx(De,{variant:"ghost",size:"icon","aria-label":"Zoom in",className:"h-9 w-9",onClick:()=>r(g=>c(g+.25)),children:u.jsx(ro,{className:"h-4 w-4"})}),u.jsx(De,{variant:"ghost",size:"icon","aria-label":"Reset view",className:"h-9 w-9",onClick:()=>{r(1),s({x:0,y:0})},children:u.jsx(pq,{className:"h-4 w-4"})}),u.jsx(De,{variant:"ghost",size:"icon","aria-label":"Close",className:"h-9 w-9",onClick:t,children:u.jsx(Is,{className:"h-4 w-4"})})]}),u.jsx("div",{className:"flex-1 overflow-hidden touch-none cursor-grab active:cursor-grabbing",onPointerDown:d,onPointerMove:f,onPointerUp:m,onPointerLeave:m,children:u.jsx("div",{"data-mermaid-stage":!0,className:"w-full h-full flex items-center justify-center",style:{transform:`translate(${i.x}px, ${i.y}px) scale(${n})`},dangerouslySetInnerHTML:{__html:e}})})]}),document.body)}let Qw=null;function Sbe(){return Qw||(Qw=Y(()=>import("./mermaid.core-k9C_NeOW.js").then(e=>e.bm),[]).then(e=>e.default)),Qw}function Cbe({source:e}){const{resolvedTheme:t}=gy(),n=t==="dark"?"dark":"default",[r,i]=v.useState({status:"loading"}),o=`mermaid-${v.useId().replace(/[^a-zA-Z0-9_-]/g,"")}`,[a,c]=v.useState(!1),[d,f]=v.useState(!1),[m,g]=v.useState(!1),b=v.useCallback(()=>f(!1),[]),y=async()=>{await navigator.clipboard.writeText(e),g(!0),setTimeout(()=>g(!1),2e3)};return v.useEffect(()=>{let _=!1;return Sbe().then(async w=>{w.initialize({startOnLoad:!1,securityLevel:"strict",theme:n});const{svg:C}=await w.render(o,e);_||i({status:"ready",svg:C})}).catch(()=>{_||i({status:"error"})}),()=>{_=!0}},[e,n,o]),r.status==="error"?u.jsx(Zw,{source:e}):r.status==="loading"?u.jsx("div",{className:"relative group/mermaid",children:u.jsx(Zw,{source:e})}):a?u.jsxs("div",{className:"relative group/mermaid",children:[u.jsx(Zw,{source:e}),u.jsx(TI,{showSource:a,onToggleSource:()=>c(_=>!_),onCopy:y,copied:m,onZoom:void 0})]}):u.jsxs("div",{className:"relative group/mermaid my-3",children:[u.jsx("div",{className:"flex justify-center overflow-x-auto",dangerouslySetInnerHTML:{__html:r.svg}}),u.jsx(TI,{showSource:a,onToggleSource:()=>c(_=>!_),onCopy:y,copied:m,onZoom:()=>f(!0)}),d&&u.jsx(wbe,{svg:r.svg,onClose:b})]})}function TI({showSource:e,onToggleSource:t,onCopy:n,copied:r,onZoom:i}){return u.jsxs("div",{className:"absolute top-1.5 right-1.5 flex gap-1 opacity-100 md:opacity-0 md:group-hover/mermaid:opacity-100 transition-opacity [@media(hover:none)]:!opacity-100",children:[i&&!e&&u.jsx(De,{variant:"ghost",size:"icon","aria-label":"Zoom diagram",className:"h-8 w-8 rounded-md text-muted-foreground hover:text-foreground",onClick:i,children:u.jsx(FG,{className:"h-4 w-4"})}),u.jsx(De,{variant:"ghost",size:"icon","aria-label":e?"View rendered diagram":"View diagram source",className:"h-8 w-8 rounded-md text-muted-foreground hover:text-foreground",onClick:t,children:u.jsx($S,{className:"h-4 w-4"})}),u.jsx(De,{variant:"ghost",size:"icon","aria-label":r?"Copied":"Copy diagram source",className:de("h-8 w-8 rounded-md text-muted-foreground",!r&&"hover:text-foreground",r&&"hover:!bg-transparent"),onClick:n,children:r?u.jsx(ns,{className:"h-4 w-4 text-success"}):u.jsx(La,{className:"h-4 w-4"})})]})}const kbe=200*1024,Ebe={ts:"typescript",typescript:"typescript",tsx:"tsx",js:"javascript",javascript:"javascript",jsx:"jsx",py:"python",python:"python",go:"go",golang:"go",rs:"rust",rust:"rust",java:"java",rb:"ruby",ruby:"ruby",sh:"bash",bash:"bash",zsh:"bash",shell:"bash",yml:"yaml",yaml:"yaml",css:"css",scss:"scss",html:"html",xml:"xml",json:"json",json5:"json5",md:"markdown",markdown:"markdown",sql:"sql",cpp:"cpp","c++":"cpp",c:"c",h:"c",swift:"swift",kt:"kotlin",kotlin:"kotlin",php:"php",toml:"toml",dockerfile:"dockerfile",diff:"diff",patch:"diff",vue:"vue",svelte:"svelte"};function Nbe(e){return Ebe[e.toLowerCase()]??null}const Tbe=/^<pre[^>]*>/,Rbe=/<\/pre>\s*$/,Abe=/^<code[^>]*>/,jbe=/<\/code>\s*$/;function Mbe(e){return e.replace(Tbe,"").replace(Rbe,"").replace(Abe,"").replace(jbe,"")}function Bf({source:e,lang:t}){const{resolvedTheme:n}=gy(),r=n==="dark"?"github-dark":"github-light",i=Nbe(t),s=i!==null&&e.length<=kbe,[o,a]=v.useState(null);v.useEffect(()=>{if(!s||i===null)return;let f=!1;return Y(()=>Promise.resolve().then(()=>$8),void 0).then(async m=>{if(f)return;const g=await m.codeToHtml(e,{lang:i,theme:r});f||a({source:e,theme:r,lang:i,html:Mbe(g)})}).catch(()=>{typeof console<"u"&&console.warn("[transcript] Shiki unavailable; falling back to plain code")}),()=>{f=!0}},[s,e,i,r]);const c=i??t.toLowerCase();return o!==null&&o.source===e&&o.theme===r&&o.lang===i?u.jsx("code",{className:`block text-xs whitespace-pre language-${c} shiki-highlighted`,dangerouslySetInnerHTML:{__html:o.html}}):u.jsx("code",{className:`block text-xs whitespace-pre language-${c}`,children:e})}const nF={readonly:!1,localLinkMode:"open"},rF=v.createContext(nF);function Lbe({children:e,value:t}){return u.jsx(rF.Provider,{value:{...nF,...t},children:e})}function vy(){return v.useContext(rF)}const ax=()=>{},iF=v.createContext(ax);function sF({children:e,onOpenLocalLink:t}){return u.jsx(iF.Provider,{value:t??ax,children:e})}const nC={Task:Cb,TaskOutput:Cb,Bash:Nx,Glob:qf,Grep:qf,ExitPlanMode:rj,Read:H5,Edit:GW,Write:KW,Delete:tG,NotebookEdit:oh,WebFetch:UV,TodoWrite:aW,WebSearch:qf,KillShell:$q,AskUserQuestion:G5,Skill:Dq,EnterPlanMode:rj},oF=Qq;function aF(e){return nC[e]?nC[e]:oF}function lF({icon:e,className:t}){return u.jsx(e,{className:t})}function Wa({children:e,className:t}){return u.jsx("div",{className:de("flex gap-3 justify-start items-center",t),children:e})}function cF({children:e,className:t}){return u.jsx("div",{className:de("flex items-center gap-1.5 text-xs",t),children:e})}function eu({children:e,className:t}){return u.jsx("span",{className:de("font-medium text-foreground/80",t),children:e})}function Ibe({children:e}){return u.jsx("span",{className:"text-muted-foreground",children:e})}function Dbe({children:e,className:t}){return u.jsxs(Wa,{className:de("px-0.5 text-xs tracking-wide",t),children:[u.jsx("div",{className:"w-full h-[1px] bg-border"}),u.jsx(eu,{className:"whitespace-nowrap text-[11px] tracking-widest text-muted-foreground/60 uppercase flex-shrink-0",children:e}),u.jsx("div",{className:"w-full h-[1px] bg-border"})]})}function f2({children:e,expandedContent:t,defaultExpanded:n=!1}){const[r,i]=v.useState(n);return u.jsxs("div",{className:"flex flex-col w-full",children:[u.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:[u.jsx("div",{className:"grid grid-cols-[auto_1fr] items-center gap-1.5",children:e}),u.jsx(no,{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 rC({label:e,children:t,copyText:n}){const[r,i]=v.useState(!1),s=n??Kd(t),o=v.useCallback(async()=>{await navigator.clipboard.writeText(s),i(!0),setTimeout(()=>i(!1),2e3)},[s]);return u.jsxs("div",{children:[u.jsx("span",{className:"font-medium text-muted-foreground",children:e}),u.jsxs("div",{className:"relative group/codeblock",children:[u.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}),u.jsx(De,{variant:"ghost",size:"icon","aria-label":r?"Copied":"Copy code",className:de("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?u.jsx(ns,{className:"h-3.5 w-3.5 text-success"}):u.jsx(La,{className:"h-4 w-4"})})]})]})}function uF({children:e,icon:t,className:n}){return u.jsxs("span",{className:de("inline-flex items-center gap-1 px-2 py-1 bg-muted border border-border rounded-full",n),children:[t&&u.jsx(t,{className:"h-3 w-3 text-muted-foreground"}),e]})}function by({children:e,className:t}){return u.jsxs("div",{className:de("grid grid-cols-[auto_1fr] gap-2 min-w-0",t),children:[u.jsx("div",{className:" min-w-5 flex flex-col relative items-center justify-center",children:u.jsx("div",{className:"min-h-full w-[1px] bg-muted-foreground/20"})}),u.jsx("div",{className:"-ml-[1px] min-w-0 overflow-hidden",children:e})]})}function Kd(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(Array.isArray(e))return e.map(Kd).join("");if(e&&typeof e=="object"&&"props"in e){const t=e.props;return Kd(t.children)}return""}function RI(e,t){return v.isValidElement(e)?v.cloneElement(e,{className:de(e.props.className,t)}):e}function dF({children:e,...t}){const[n,r]=v.useState(!1),i=Kd(e),s=async()=>{await navigator.clipboard.writeText(i),r(!0),setTimeout(()=>r(!1),2e3)};return u.jsxs("div",{className:"relative overflow-x-auto max-w-full min-w-0 no-code-highlight group/pre",children:[u.jsx("pre",{className:"min-w-0 rounded-xl py-2.5 px-3.5 [.no-pre-highlight_&]:bg-background",...t,children:e}),u.jsx(De,{variant:"ghost",size:"icon","aria-label":n?"Copied":"Copy code",className:de("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?u.jsx(ns,{className:"h-4 w-4 text-success"}):u.jsx(La,{className:"h-4 w-4"})})]})}function Zw({source:e}){return u.jsx(dF,{children:u.jsx("code",{className:"block text-xs whitespace-pre language-mermaid",children:e})})}const m2={h1:({children:e})=>u.jsx("h1",{className:"text-[20px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h2:({children:e})=>u.jsx("h2",{className:"text-[18px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h3:({children:e})=>u.jsx("h3",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h4:({children:e})=>u.jsx("h4",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h5:({children:e})=>u.jsx("h5",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),h6:({children:e})=>u.jsx("h6",{className:"text-[16px] font-normal leading-tight mt-5 mb-3 first:mt-0 last:mb-0",children:e}),pre:dF,code:({children:e,className:t,...n})=>{if(!t)return u.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});const i=t.split(/\s+/);if(i.includes("language-mermaid"))return u.jsx(Cbe,{source:Kd(e)});const s=i.find(a=>a.startsWith("language-")),o=s?s.slice(9):"";return o?u.jsx(Bf,{source:Kd(e),lang:o}):u.jsx("code",{className:"block text-xs whitespace-pre",...n,children:e})},table:({children:e,...t})=>u.jsx("div",{className:"border border-border rounded-xl overflow-x-auto",children:u.jsx("table",{className:"table-auto min-w-full divide-y divide-border bg-background",...t,children:e})}),tbody:({children:e,...t})=>u.jsx("tbody",{className:"divide-y divide-border",...t,children:e}),th:({children:e,...t})=>u.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})=>u.jsx("td",{className:"text-left p-2 pl-0 first:pl-3 [&_*]:font-normal ",...t,children:e}),p:({children:e,...t})=>u.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]=RI(r,"mt-0"));const i=n.length-1,s=n[i];return s!==void 0&&(n[i]=RI(s,"mb-0")),u.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})=>u.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"&&wpe(e)?r2(e):e;return u.jsx("img",{src:n,...t})}};function Pbe({children:e,href:t,onClick:n,overrideOpenLocalLink:r,...i}){const s=v.useContext(iF),o=r??s,a=vy(),c=ype(t);if(c&&a.localLinkMode==="text")return u.jsx("span",{className:"transition-all underline decoration-2 text-logo decoration-logo/50",children:e});if(c&&!zB(c.path)){const d=iC(e).trim();return u.jsx(mbe,{path:c.path,linkText:d||void 0})}return u.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:d=>{n==null||n(d),!(d.defaultPrevented||!c||o===ax)&&(d.preventDefault(),o({...c,clientX:d.clientX,clientY:d.clientY,trigger:"click"}))},onContextMenu:d=>{!c||o===ax||(d.preventDefault(),o({...c,clientX:d.clientX,clientY:d.clientY,trigger:"contextmenu"}))},...i,children:e})}function Obe(e){return{...m2,a:t=>u.jsx(Pbe,{...t,overrideOpenLocalLink:e==null?void 0:e.onOpenLocalLink})}}const za=[OB],Ba=Obe();function iC(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(iC).join(""):v.isValidElement(e)?iC(e.props.children):""}({...m2});function p2({attachment:e,previewUrl:t,onClick:n,onRemove:r,className:i,size:s="transcript",uploadProgress:o,onCancelUpload:a}){const c=e.contentUrl||t,d=s==="composer",f=o!==void 0;return u.jsxs("div",{className:de("group relative flex flex-row items-end",i),children:[u.jsxs("button",{type:"button",onClick:n,className:de("group/image relative overflow-hidden rounded-xl border border-border/80 bg-background shadow-sm",d?"min-w-[80px]":"min-w-[200px]"),children:[c?u.jsx("img",{src:c,alt:e.displayName,className:de("rounded-xl object-contain bg-muted",d?"min-h-[50px] min-w-[80px] max-h-[120px] max-w-[200px]":"min-h-[100px] min-w-[200px] max-h-[300px] max-w-[300px]")}):u.jsx("div",{className:de("flex items-center justify-center rounded-xl bg-muted text-muted-foreground",d?"min-h-[64px] min-w-[80px]":"min-h-[160px] min-w-[200px]"),children:u.jsx($5,{className:de(d?"size-6":"size-8")})}),u.jsxs("div",{className:de("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",d?"px-2.5 pb-2 pt-6":"px-4 pb-3 pt-10"),children:[u.jsx("div",{className:de("truncate font-medium text-white",d?"text-xs":"text-sm"),children:e.displayName}),u.jsxs("div",{className:"truncate text-xs text-white/80",children:[e.mimeType," · ",kh(e.size)]})]})]}),f?u.jsx(tB,{progress:o??null,onCancel:a,size:d?"sm":"md",cancelLabel:`Cancel upload of ${e.displayName}`}):null,r&&!f?u.jsx(hF,{displayName:e.displayName,onRemove:r}):null]})}function Fo({attachment:e,onClick:t,onRemove:n,className:r,uploadProgress:i,onCancelUpload:s,href:o,download:a,meta:c,ariaLabel:d,disabledReason:f}){const m=e.kind==="mention"?"text":wh(e),g=Fbe(m),b=e.kind==="mention",y=b?zbe(e.displayName):e.displayName,_=b?Bbe(e.displayName):"",w=i!==void 0,C=!!f,E=de("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?u.jsx("div",{className:"max-w-[150px] truncate text-[11px] text-muted-foreground",children:_?`@${_}`:"@mention"}):f?u.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:f}):c!==void 0?u.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:c}):u.jsxs("div",{className:"truncate text-[11px] text-muted-foreground",children:[e.mimeType," · ",kh(e.size)]}),T=u.jsxs(u.Fragment,{children:[u.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:u.jsx(lF,{icon:g,className:"size-5"})}),u.jsxs("div",{className:"min-w-0",children:[u.jsx("div",{className:de("max-w-[150px] truncate text-[13px] font-medium",C?"text-muted-foreground line-through":"text-foreground"),children:y}),k]})]});return u.jsxs("div",{className:de("group relative",r),children:[o&&!C?u.jsx("a",{href:o,download:a,rel:"noopener","aria-label":d,className:E,children:T}):u.jsx("button",{type:"button",onClick:C?void 0:t,title:b?e.displayName:void 0,"aria-label":d,"aria-disabled":C||void 0,disabled:C,className:E,children:T}),w?u.jsx(tB,{progress:i??null,onCancel:s,size:"sm",cancelLabel:`Cancel upload of ${e.displayName}`}):null,n&&!w?u.jsx(hF,{displayName:e.displayName,onRemove:n}):null]})}function zbe(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function Bbe(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function hF({displayName:e,onRemove:t}){return u.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:u.jsx(Is,{className:"h-3.5 w-3.5"})})}function Fbe(e){switch(e){case"image":return $5;case"pdf":return hq;case"markdown":return _q;case"json":return BW;case"table":return XW;case"code":return $W;case"text":return gk;case"archive":return OW;case"audio":return UW;case"video":return JW;default:return H5}}function kh(e){return e<1024?`${e} B`:e<1024*1024?`${Math.max(1,Math.round(e/1024))} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}const Vl=v.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{"data-gramm":"false","data-gramm_editor":"false","data-enable-grammarly":"false","data-1p-ignore":!0,autoComplete:"off",className:de("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}));Vl.displayName="Textarea";const Cv={};function AI(e){return!e.isCollapsed&&!e.hasPreviewAttachment&&e.patch===void 0&&e.patchError===void 0&&!e.isPatchLoading}function $be(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 fF(e){return e.isUntracked}function Hbe(e){return fF(e)?e.path.includes("/"):!1}function Jw(e){return u.jsxs(si,{delayDuration:0,children:[u.jsx(oi,{asChild:!0,children:u.jsx("button",{type:"button","aria-label":e.label,title:e.label,onClick:e.onClick,className:de("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})}),u.jsx(qr,{children:e.label})]})}function mF({checked:e,mixed:t=!1,label:n,className:r,onClick:i}){return u.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:de("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?u.jsx(K5,{className:"h-3 w-3",strokeWidth:3}):e?u.jsx(ns,{className:"h-3 w-3",strokeWidth:3}):null})}function g2(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,a=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<a?`${Math.round(n/o)}wk ago`:n<c?`${Math.round(n/a)}mo ago`:`${Math.round(n/c)}yr ago`}function Ube(e){return e?`Last fetched ${g2(e)}`:"No local fetch recorded"}function Vbe({entry:e,isPendingPush:t=!1}){const n=g2(e.authoredAt),r=!!e.githubUrl;return u.jsxs("button",{type:"button",disabled:!r,onClick:()=>{!e.githubUrl||typeof window>"u"||window.open(e.githubUrl,"_blank","noopener,noreferrer")},className:de("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:[u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:e.summary}),e.description?u.jsx("div",{className:"mt-1 line-clamp-2 whitespace-pre-wrap text-xs text-muted-foreground",children:e.description}):null,u.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-1 text-xs text-muted-foreground",children:[e.authorName?u.jsx("span",{className:"truncate",children:e.authorName}):null,e.authorName&&n?u.jsx("span",{"aria-hidden":"true",children:"•"}):null,n?u.jsx("span",{children:n}):null]})]}),e.tags.length>0?u.jsxs("div",{className:"flex shrink-0 flex-wrap justify-end gap-1",children:[e.tags.map(i=>u.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?u.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:u.jsx(dm,{className:"size-3"})}):null]}):t?u.jsx("div",{className:"flex shrink-0 flex-wrap justify-end gap-1",children:u.jsx("span",{className:"inline-flex items-center rounded-full bg-muted border border-border px-2 py-0.5 text-[11px]",children:u.jsx(dm,{className:"size-3"})})}):null]})}function jI(e){switch(e.kind){case"local":return 0;case"pull_request":return 1;case"remote":default:return 2}}function Wbe(e){const t=new Map;for(const n of e){const r=t.get(n.name);(!r||jI(n)<jI(r))&&t.set(n.name,n)}return t}function Gbe(e,t){const n=Wbe([...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(a=>n.get(a.name)??a).filter(a=>!!a&&!r.has(a.name));for(const a of s)r.add(a.name);const o=[...n.values()].filter(a=>!r.has(a.name)).sort((a,c)=>a.displayName.localeCompare(c.displayName));return{defaultBranch:i,recent:s,other:o}}function qbe({open:e,onOpenChange:t,onGetGitHubPublishInfo:n,onCheckGitHubRepoAvailability:r,onPublish:i}){const[s,o]=v.useState(null),[a,c]=v.useState(!1),[d,f]=v.useState(""),[m,g]=v.useState(""),[b,y]=v.useState("private"),[_,w]=v.useState(""),[C,E]=v.useState(null),[k,T]=v.useState(!1),[R,A]=v.useState(!1);v.useEffect(()=>{if(!e)return;let U=!1;return c(!0),E(null),n().then(M=>{U||(o(M),f(M.owners[0]??M.activeAccountLogin??""),g(M.suggestedRepoName),y("private"),w(""))}).finally(()=>{U||c(!1)}),()=>{U=!0}},[n,e]),v.useEffect(()=>{if(!e||!(s!=null&&s.ghInstalled)||!s.authenticated)return;const U=d.trim(),M=m.trim();if(!U||!M){E(null);return}let D=!1;T(!0);const z=window.setTimeout(()=>{r({owner:U,name:M}).then(P=>{D||E(P)}).finally(()=>{D||T(!1)})},250);return()=>{D=!0,window.clearTimeout(z)}},[s==null?void 0:s.authenticated,s==null?void 0:s.ghInstalled,m,r,e,d]);async function j(){if(!(!d.trim()||!m.trim())){A(!0);try{const U=await i({owner:d.trim(),name:m.trim(),visibility:b,description:_});U!=null&&U.ok&&t(!1)}finally{A(!1)}}}const I=!!(s!=null&&s.ghInstalled&&s.authenticated&&d.trim()&&m.trim()&&(C!=null&&C.available)&&!k&&!R);return u.jsx(so,{open:e,onOpenChange:t,children:u.jsxs(As,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[u.jsxs(Ho,{className:"space-y-2 px-4 pb-4 pt-4",children:[u.jsxs("div",{className:"space-y-1",children:[u.jsx(oo,{children:"Push to GitHub"}),u.jsx(np,{children:"Create a GitHub repository from this local project using GitHub CLI."})]}),a?u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(_n,{className:"size-4 animate-spin"}),u.jsx("span",{children:"Checking GitHub CLI…"})]}):s&&!s.ghInstalled?u.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[u.jsx("p",{children:"GitHub CLI is not installed."}),u.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"brew install gh"}),u.jsx("p",{children:"Then run:"}),u.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?u.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[u.jsx("p",{children:"GitHub CLI is installed but not signed in."}),u.jsx("div",{className:"rounded-lg border border-border px-3 py-2 font-mono text-xs text-foreground",children:"gh auth login"})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"space-y-2",children:u.jsxs(Lo,{value:d,onValueChange:f,children:[u.jsx(Xs,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:u.jsx(Sa,{placeholder:"Select owner"})}),u.jsx(Qs,{children:((s==null?void 0:s.owners)??[]).map(U=>u.jsx(ti,{value:U,children:u.jsxs("span",{className:"flex items-center gap-2",children:[U===(s==null?void 0:s.activeAccountLogin)?u.jsx(yk,{className:"size-4 text-muted-foreground"}):u.jsx(rW,{className:"size-4 text-muted-foreground"}),u.jsx("span",{className:"pl-[1px]",children:U})]})},U))})]})}),u.jsx("div",{className:"space-y-2",children:u.jsxs("div",{className:"relative",children:[u.jsx(mn,{value:m,onChange:U=>g(U.target.value),placeholder:"my-repo",className:"pl-9 pr-10"}),u.jsx(rq,{className:"pointer-events-none absolute inset-y-0 left-3 my-auto size-4 text-muted-foreground"}),k?u.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-3 flex items-center text-muted-foreground",children:u.jsx(_n,{className:"size-4 animate-spin"})}):C?u.jsx("div",{className:"absolute inset-y-0 right-2 flex items-center",children:u.jsxs(si,{delayDuration:0,children:[u.jsx(oi,{asChild:!0,children:u.jsx("button",{type:"button",tabIndex:-1,"aria-label":C.message,className:de("flex size-6 items-center justify-center rounded-md",C.available?"text-success":"text-destructive"),children:C.available?u.jsx(ns,{className:"size-4"}):u.jsx(fm,{className:"size-4"})})}),u.jsx(qr,{children:C.message})]})}):null]})}),u.jsx("div",{className:"space-y-2",children:u.jsxs("div",{className:"relative",children:[u.jsx(gk,{className:"pointer-events-none absolute left-3 top-3 size-4 text-muted-foreground"}),u.jsx(Vl,{value:_,onChange:U=>w(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"})]})}),u.jsx("div",{className:"space-y-2",children:u.jsxs(Lo,{value:b,onValueChange:U=>y(U),children:[u.jsx(Xs,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:u.jsx(Sa,{placeholder:"Select visibility"})}),u.jsxs(Qs,{children:[u.jsx(ti,{value:"private",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(PG,{className:"size-4 text-muted-foreground"}),u.jsx("span",{className:"pl-[1px]",children:"Private"})]})}),u.jsx(ti,{value:"public",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(xG,{className:"size-4 text-muted-foreground"}),u.jsx("span",{className:"pl-[1px]",children:"Public"})]})})]})]})})]})]}),u.jsxs(Kl,{children:[u.jsx(De,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),u.jsx(De,{size:"sm",disabled:!I,onClick:()=>void j(),children:R?u.jsxs(u.Fragment,{children:[u.jsx(_n,{className:"mr-1.5 size-3.5 animate-spin"}),"Publishing…"]}):"Push to GitHub"})]})]})})}function pF({value:e,onChange:t,placeholder:n,disabled:r,trailingAction:i}){return u.jsxs("div",{className:"relative",children:[u.jsx(qf,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),u.jsx(mn,{value:e,onChange:s=>t(s.target.value),placeholder:n,className:de("h-9 pl-7 text-sm",i?"pr-14":void 0),disabled:r}),i?u.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2",children:i}):null]})}function Fc({title:e,entries:t,emptyLabel:n,selectedName:r,disabled:i,stickyTitle:s=!1,onSelect:o}){return t.length===0&&!n?null:u.jsxs("div",{className:"space-y-1",children:[u.jsx("div",{className:de("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?u.jsx("div",{className:"px-1 py-1 text-xs text-muted-foreground",children:n}):t.map(a=>{const c=r===a.name;return u.jsxs("button",{type:"button",disabled:i,onClick:()=>o(a),className:de("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:[a.kind==="pull_request"?u.jsx(W5,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):u.jsx(Ea,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsxs("div",{className:"flex w-full items-center gap-3",children:[u.jsx("div",{className:"min-w-0 flex-1 overflow-hidden whitespace-nowrap text-sm text-foreground",children:a.displayName}),a.updatedAt?u.jsx("div",{className:"ml-auto shrink-0 text-right text-[11px] text-muted-foreground",children:g2(a.updatedAt)}):null]}),a.kind==="pull_request"&&a.description||a.headLabel?u.jsx("div",{className:"truncate text-xs text-muted-foreground",children:a.kind==="pull_request"?a.description??a.headLabel??a.name:a.headLabel??void 0}):null]})]},a.id)})]})}function Kbe({open:e,onOpenChange:t,branchList:n,currentBranchName:r,onPreviewMergeBranch:i,onMergeBranch:s}){const[o,a]=v.useState(""),[c,d]=v.useState(null),[f,m]=v.useState(null),[g,b]=v.useState(null),[y,_]=v.useState(!1),[w,C]=v.useState(!1),E=v.useMemo(()=>n?Gbe(n,r):{defaultBranch:void 0,recent:[],other:[]},[n,r]),k=o.trim().toLowerCase(),T=v.useCallback(D=>k?[D.displayName,D.name,D.description,D.prTitle,D.headLabel].some(z=>z==null?void 0:z.toLowerCase().includes(k)):!0,[k]),R=E.defaultBranch&&T(E.defaultBranch)?E.defaultBranch:void 0,A=E.recent.filter(T),j=E.other.filter(T),I=v.useMemo(()=>c?[E.defaultBranch,...E.recent,...E.other].find(D=>D!==void 0&&D.name===c)??null:null,[E.defaultBranch,E.other,E.recent,c]);v.useEffect(()=>{e||(a(""),d(null),m(null),b(null),_(!1),C(!1))},[e]),v.useEffect(()=>{if(!e||!I){m(null),b(null),_(!1);return}let D=!1;return m(null),b(null),_(!0),i(I).then(z=>{D||m(z)}).catch(z=>{D||b(z instanceof Error?z.message:String(z))}).finally(()=>{D||_(!1)}),()=>{D=!0}},[i,e,I]);const U=!I||!f||y||w||f.status!=="mergeable";async function M(){if(!(!I||U)){C(!0);try{const D=await s(I);D!=null&&D.ok&&t(!1)}finally{C(!1)}}}return u.jsx(so,{open:e,onOpenChange:t,children:u.jsxs(As,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[u.jsxs(Ho,{className:"flex min-h-0 flex-col gap-3 px-4 pb-4 pt-4",children:[u.jsxs("div",{className:"space-y-1",children:[u.jsxs(oo,{children:["Merge into ",r??"current branch"]}),u.jsx(np,{children:"Choose a branch to continue."})]}),u.jsx(pF,{value:o,onChange:a,placeholder:"Search branches"}),u.jsxs("div",{className:"max-h-[375px] space-y-3 overflow-y-auto pr-1",children:[u.jsx(Fc,{title:"Default Branch",entries:R?[R]:[],emptyLabel:"No default branch available.",selectedName:c,onSelect:D=>d(D.name)}),u.jsx(Fc,{title:"Recent Branches",entries:A,emptyLabel:"No recent branches.",selectedName:c,onSelect:D=>d(D.name)}),u.jsx(Fc,{title:"Other Branches",entries:j,emptyLabel:"No other branches match this search.",selectedName:c,onSelect:D=>d(D.name)})]}),u.jsx("div",{className:"px-2",children:I?y?u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(_n,{className:"size-3.5 animate-spin"}),u.jsx("span",{children:"Checking merge preview…"})]}):g?u.jsx("div",{className:"text-sm text-destructive",children:g}):f?u.jsxs("div",{className:"flex items-start gap-2",children:[f.status==="up_to_date"?u.jsx(ns,{className:"mt-1 size-3.5 shrink-0 text-success"}):f.status==="conflicts"?u.jsx(fm,{className:"mt-1 size-3.5 shrink-0 text-warning"}):f.status==="mergeable"?u.jsx(V5,{className:"mt-1 size-3.5 shrink-0 text-muted-foreground"}):u.jsx(fm,{className:"mt-1 size-3.5 shrink-0 text-destructive"}),u.jsxs("div",{className:"min-w-0 space-y-1",children:[u.jsx("div",{className:"text-sm font-medium text-foreground",children:f.message}),f.detail?u.jsx("div",{className:"line-clamp-2 whitespace-pre-wrap text-xs text-muted-foreground",children:f.detail}):null]})]}):u.jsx("div",{className:"text-sm text-muted-foreground",children:"Preview unavailable."}):u.jsx("div",{className:"text-sm text-muted-foreground",children:"Select a branch to preview the merge."})})]}),u.jsx(Kl,{children:u.jsxs("div",{className:"flex min-w-0 w-full items-center justify-end gap-2",children:[u.jsx(De,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),u.jsx(De,{className:"max-w-full min-w-0",size:"sm",disabled:U,onClick:()=>void M(),children:w?u.jsxs(u.Fragment,{children:[u.jsx(_n,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),"Merging…"]}):u.jsx("span",{className:"block max-w-full truncate",children:"Merge"})})]})})]})})}function Ybe({currentBranchName:e,onListBranches:t,onPreviewMergeBranch:n,onMergeBranch:r,onCheckoutBranch:i,onCreateBranch:s}){const[o,a]=v.useState(!1),[c,d]=v.useState(!1),[f,m]=v.useState(!1),[g,b]=v.useState(!1),[y,_]=v.useState(""),[w,C]=v.useState("branches"),[E,k]=v.useState(null),[T,R]=v.useState(null);v.useEffect(()=>{o&&(m(!0),R(null),t().then(W=>k(W)).catch(W=>{R(W instanceof Error?W.message:String(W))}).finally(()=>{m(!1)}))},[t,o]);const A=y.trim().toLowerCase(),j=W=>W.filter(te=>A?[te.displayName,te.name,te.description,te.prTitle,te.headLabel].some(O=>O==null?void 0:O.toLowerCase().includes(A)):!0),I=(E==null?void 0:E.currentBranchName)??e,U=new Set(((E==null?void 0:E.pullRequests)??[]).map(W=>W.headRefName??W.name)),M=j((E==null?void 0:E.recent)??[]).filter(W=>W.name!==I),D=j((E==null?void 0:E.local)??[]).filter(W=>W.name!==I),z=j((E==null?void 0:E.remote)??[]).filter(W=>W.name!==I&&!U.has(W.name)),P=j((E==null?void 0:E.pullRequests)??[]).filter(W=>W.name!==I),F=(E==null?void 0:E.pullRequests.length)??0;async function $(W){b(!0);try{await i(W),a(!1),_(""),C("branches")}finally{b(!1)}}async function B(){b(!0);try{await s(),a(!1),_(""),C("branches")}finally{b(!1)}}function H(){a(!1),d(!0)}return u.jsxs(dp,{open:o,onOpenChange:a,children:[u.jsx(hp,{asChild:!0,children:u.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:[u.jsx(Ea,{className:"h-3.5 w-3.5 shrink-0"}),u.jsx("span",{className:"truncate",children:e??"Detached HEAD"}),u.jsx(sh,{className:"h-3.5 w-3.5 shrink-0"})]})}),u.jsx(dh,{align:"start",className:"w-[320px] p-2",children:u.jsxs("div",{className:"space-y-2",children:[u.jsx(pF,{value:y,onChange:_,placeholder:w==="pull_requests"?"Search pull requests":"Search branches",disabled:f||g,trailingAction:u.jsx(De,{variant:"ghost",size:"sm",onClick:()=>void B(),disabled:f||g,className:"h-7 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:"+ New"})}),u.jsx(Ii,{value:w,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}`}]}),u.jsx("div",{className:"max-h-[420px] overflow-y-auto pr-1.5 -mr-[8px]",children:f?u.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[u.jsx(_n,{className:"h-4 w-4 animate-spin"}),u.jsx("span",{children:"Loading branches…"})]}):T?u.jsx("div",{className:"rounded-lg border border-border px-3 py-2 text-sm text-muted-foreground",children:T}):w==="pull_requests"?u.jsx(Fc,{title:"Open PRs",entries:P,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=>{$(W)}}):u.jsxs("div",{className:"space-y-3",children:[u.jsx(Fc,{title:"Recent",entries:M,emptyLabel:"No recent branches.",disabled:g,stickyTitle:!0,onSelect:W=>{$(W)}}),u.jsx(Fc,{title:"Local",entries:D,emptyLabel:"No local branches.",disabled:g,stickyTitle:!0,onSelect:W=>{$(W)}}),u.jsx(Fc,{title:"Remote",entries:z,emptyLabel:"No remote branches.",disabled:g,stickyTitle:!0,onSelect:W=>{$(W)}})]})}),I?u.jsx(De,{variant:"default",size:"sm",disabled:f||g||!!T,onClick:H,className:"h-9 w-full justify-center rounded-lg px-3 text-sm",children:u.jsxs("span",{className:"block max-w-full truncate",children:[u.jsx(mG,{className:"mr-1.5 inline h-3.5 w-3.5 shrink-0"}),"Merge branch into ",I,"..."]})}):null]})}),u.jsx(Kbe,{open:c,onOpenChange:d,branchList:E,currentBranchName:I,onPreviewMergeBranch:n,onMergeBranch:r})]})}function Xbe({file:e,rootRef:t,projectId:n,isCollapsed:r,isChecked:i,editorLabel:s,diffRenderMode:o,wrapLines:a,onToggleCollapsed:c,onToggleChecked:d,fileActions:f,patch:m,patchError:g,isPatchLoading:b,onLoadPatch:y}){const _=fF(e),w=Hbe(e),[C,E]=v.useState(null),k=v.useRef(null),T=v.useRef(null),{sentinelRef:R,isStuck:A}=gde({rootRef:t,disabled:r}),j=v.useMemo(()=>$be(n,e),[e,n]),I=j!==null,U=AI({isCollapsed:r,hasPreviewAttachment:I,patch:m,patchError:g,isPatchLoading:b});v.useEffect(()=>{if(!U)return;const P=`${e.path}\0${e.patchDigest}`;T.current!==P&&(T.current=P,y(e.path).catch(()=>{}))},[e.patchDigest,e.path,y,U]);function M(P){if(_h(P).openInNewTab){typeof window<"u"&&window.open(new URL(P.contentUrl,window.location.origin).toString(),"_blank","noopener,noreferrer");return}E(P.id)}function D(P){var $;P.preventDefault(),P.stopPropagation();const F=P.currentTarget.getBoundingClientRect();($=k.current)==null||$.dispatchEvent(new MouseEvent("contextmenu",{bubbles:!0,cancelable:!0,clientX:F.left+F.width/2,clientY:F.bottom,view:window}))}function z(){if(!r){c();return}if(I||m!==void 0){c();return}if(b)return;if(!(g!==void 0||AI({isCollapsed:!1,hasPreviewAttachment:I,patch:m,patchError:g,isPatchLoading:b}))){c();return}y(e.path).then(()=>{c()}).catch(()=>{})}return u.jsxs(fu,{children:[u.jsx(mu,{asChild:!0,children:u.jsxs("div",{ref:k,className:"relative rounded-lg border border-border bg-background",children:[r?null:u.jsx("div",{ref:R,className:"pointer-events-none absolute inset-x-0 top-0 h-px","aria-hidden":"true"}),u.jsxs("div",{role:"button",tabIndex:0,onClick:z,onKeyDown:P=>{P.key!=="Enter"&&P.key!==" "||(P.preventDefault(),z())},className:de("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&&!A&&"rounded-t-[calc(theme(borderRadius.lg)-1px)]",r&&"rounded-[calc(theme(borderRadius.lg)-1px)]",!r&&"border-b border-border/50"),children:[u.jsxs("div",{className:"flex min-w-0 items-center",children:[u.jsx(mF,{checked:i,onClick:d}),u.jsx("div",{className:"min-w-0 truncate select-none ml-2 mr-1",children:e.path})]}),u.jsxs("div",{className:"flex shrink-0 items-center gap-2 select-none",children:[u.jsxs("span",{className:"whitespace-nowrap text-xs font-mono",children:[e.additions>0?u.jsxs("span",{className:"text-success",children:["+",e.additions]}):null,e.deletions>0?u.jsxs("span",{className:e.additions>0?"ml-2 text-destructive":"text-destructive",children:["-",e.deletions]}):null]}),u.jsx("button",{type:"button","aria-label":`Open actions for ${e.path}`,onClick:D,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:u.jsx(hm,{className:"h-3.5 w-3.5 shrink-0"})}),b&&r&&!j?u.jsx(_n,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):r?u.jsx(sh,{className:"h-3.5 w-3.5 shrink-0"}):u.jsx(B5,{className:"h-3.5 w-3.5 shrink-0"})]})]}),r?null:u.jsx("div",{className:"kanna-diff-patch overflow-hidden rounded-b-[calc(theme(borderRadius.lg)-1px)] pb-[1px]",children:j?u.jsx("div",{className:"flex justify-center p-3",children:j.kind==="image"?u.jsx(p2,{attachment:j,onClick:()=>M(j)}):u.jsx(Fo,{attachment:j,onClick:()=>M(j)})}):b?u.jsxs("div",{className:"flex items-center justify-center px-3 py-8 text-sm text-muted-foreground",children:[u.jsx(_n,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading diff..."]}):g?u.jsx("div",{className:"px-3 py-4 text-sm text-destructive",children:g}):m!==void 0?u.jsx(mde,{patch:m,options:{diffStyle:o,disableFileHeader:!0,disableBackground:!1,overflow:a?"wrap":"scroll",lineDiffType:"word",diffIndicators:"classic"}}):u.jsx("div",{className:"px-3 py-4 text-sm text-muted-foreground",children:"Diff unavailable."})}),u.jsx(Ch,{source:j&&C===j.id?Cp(j,"user_attachment"):null,open:j!==null&&C===j.id,onOpenChange:P=>!P&&E(null)})]},e.path)}),u.jsxs(ec,{children:[u.jsxs(Pn,{onSelect:P=>{P.stopPropagation(),f.onOpenFile(e.path)},children:[u.jsx(mk,{className:"h-3.5 w-3.5"}),u.jsxs("span",{className:"text-xs font-medium",children:["Open in ",s]})]}),u.jsxs(Pn,{onSelect:P=>{P.stopPropagation(),f.onOpenInFinder(e.path)},children:[u.jsx(Ex,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),u.jsxs(Pn,{onSelect:P=>{P.stopPropagation(),f.onDiscardFile(e.path)},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[u.jsx(cu,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Discard Changes"})]}),u.jsxs(Pn,{disabled:!_,onSelect:P=>{P.stopPropagation(),_&&f.onIgnoreFile(e.path)},children:[u.jsx(ZA,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Ignore File"})]}),u.jsxs(Pn,{disabled:!w,onSelect:P=>{P.stopPropagation(),w&&f.onIgnoreFolder(e.path)},children:[u.jsx(ZA,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Ignore folder..."})]}),u.jsx(T4,{}),u.jsxs(Pn,{onSelect:P=>{P.stopPropagation(),f.onCopyFilePath(e.path)},children:[u.jsx(La,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Copy File Path"})]}),u.jsxs(Pn,{onSelect:P=>{P.stopPropagation(),f.onCopyRelativePath(e.path)},children:[u.jsx(La,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Copy Relative Path"})]})]})]})}function Qbe({projectId:e,diffs:t,editorLabel:n,diffRenderMode:r,wrapLines:i,onOpenFile:s,onOpenInFinder:o,onDiscardFile:a,onIgnoreFile:c,onIgnoreFolder:d,onCopyFilePath:f,onCopyRelativePath:m,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:y,onCheckoutBranch:_,onCreateBranch:w,onGenerateCommitMessage:C,onInitializeGit:E,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:T,onSetupGitHub:R,onCommit:A,onSyncWithRemote:j,onLoadPatch:I,onDiffRenderModeChange:U,onWrapLinesChange:M}){var Je;const D=v.useMemo(()=>({onOpenFile:s,onOpenInFinder:o,onDiscardFile:a,onIgnoreFile:c,onIgnoreFolder:d,onCopyFilePath:f,onCopyRelativePath:m}),[s,o,a,c,d,f,m]),z=t.files.length>0,[P,F]=v.useState(!1),[$,B]=v.useState(null),[H,W]=v.useState(!1),[te,O]=v.useState(!1),[K,ee]=v.useState({}),[V,ue]=v.useState({}),[ge,Z]=v.useState({}),ne=v.useRef(null),ie=v.useRef({}),le=v.useMemo(()=>t.files.map(xe=>xe.path),[t.files]),oe=v.useMemo(()=>le.join("\0"),[le]),we=Li(xe=>{var Pe;return e?((Pe=xe.projectUi[e])==null?void 0:Pe.viewMode)??(z?"changes":"history"):z?"changes":"history"}),Ce=Li(xe=>{var Pe;return e?((Pe=xe.projectUi[e])==null?void 0:Pe.collapsedPaths)??Cv:Cv}),Oe=Li(xe=>{var Pe;return e?((Pe=xe.projectUi[e])==null?void 0:Pe.summary)??"":""}),Ze=Li(xe=>{var Pe;return e?((Pe=xe.projectUi[e])==null?void 0:Pe.description)??"":""}),ft=Li(xe=>xe.reconcileCollapsedPaths),Tt=Li(xe=>xe.toggleCollapsedPath),_e=Li(xe=>xe.setViewMode),cn=Li(xe=>xe.setCommitDraft),Lt=Li(xe=>xe.clearCommitDraft),pt=gv(xe=>e?xe.checkedPathsByProjectId[e]??Cv:Cv),xt=gv(xe=>xe.reconcileProject),Bt=gv(xe=>xe.setChecked),Dt=gv(xe=>xe.setAllChecked),lt=v.useRef(z);v.useEffect(()=>{e&&ft(e,le)},[le,oe,e,ft]),v.useEffect(()=>{const xe=Object.fromEntries(t.files.map(Ue=>[Ue.path,Ue.patchDigest])),Pe=Ue=>ie.current[Ue]===xe[Ue];ee(Ue=>Object.fromEntries(Object.entries(Ue).filter(([Ve])=>le.includes(Ve)&&Pe(Ve)))),ue(Ue=>Object.fromEntries(Object.entries(Ue).filter(([Ve])=>le.includes(Ve)&&Pe(Ve)))),Z(Ue=>Object.fromEntries(Object.entries(Ue).filter(([Ve])=>le.includes(Ve)&&Pe(Ve)))),ie.current=xe},[t.files,le,oe]),v.useEffect(()=>{e&&xt(e,le)},[le,oe,e,xt]),v.useEffect(()=>{if(!e)return;if(lt.current!==z){_e(e,z?"changes":"history"),lt.current=z;return}lt.current=z},[z,e,_e]);const Ot=v.useMemo(()=>t.files.filter(xe=>pt[xe.path]??!0).map(xe=>xe.path),[pt,t.files]),me=Ot.length,Te=t.files.length>0&&me===t.files.length,He=me>0&&me<t.files.length,tt=Oe.trim(),Xe=tt.length>0,yt=$!==null,ze=P||yt,Ke=((Je=t.branchHistory)==null?void 0:Je.entries)??[],Be=t.behindCount??0,Ie=t.aheadCount??0,qe=t.hasUpstream===!0,It=t.hasUpstream===!1&&!!t.branchName,Rt=t.hasOriginRemote===!0,xn=t.branchName?t.branchName.split("/").map(xe=>encodeURIComponent(xe)).join("/"):null,on=It?"publish":Be>0?"pull":"fetch",Zt=t.originRepoSlug&&xn?`https://github.com/${t.originRepoSlug}/compare/${xn}?expand=1`:null,At=!!(qe&&Zt&&t.branchName&&t.branchName!==t.defaultBranchName),_t=t.status==="ready"&&me>0&&!ze,gt=t.status==="ready"&&me>0&&Xe&&!ze,Ct=Rt?"commit_and_push":"commit_only",vt=t.branchName??"current branch";async function Ut(xe){if(gt){B(xe);try{const Pe=await A({paths:Ot,summary:tt,description:Ze.trim(),mode:xe});(Pe!=null&&Pe.ok||Pe!=null&&Pe.localCommitCreated)&&e&&Lt(e)}finally{B(null)}}}async function it(){if(_t){F(!0);try{const xe=await C({paths:Ot});e&&cn(e,{summary:xe.subject,description:xe.body})}finally{F(!1)}}}function ye(xe){if(!(!(xe.metaKey||xe.ctrlKey)||xe.key!=="Enter")){if(xe.preventDefault(),Xe){Ut(Ct);return}it()}}async function rt(xe=on){if(!(t.status!=="ready"||H)){W(!0);try{await j(xe)}finally{W(!1)}}}const Ye=v.useCallback(async xe=>{var Pe;if(K[xe]!==void 0||ge[xe])return K[xe]??"";Z(Ue=>({...Ue,[xe]:!0})),ue(Ue=>{if(!(xe in Ue))return Ue;const{[xe]:Ve,...Wt}=Ue;return Wt});try{const Ue=await I(xe);ee(Wt=>({...Wt,[xe]:Ue}));const Ve=(Pe=t.files.find(Wt=>Wt.path===xe))==null?void 0:Pe.patchDigest;return Ve&&(ie.current={...ie.current,[xe]:Ve}),Ue}catch(Ue){const Ve=Ue instanceof Error?Ue.message:String(Ue);throw ue(Wt=>({...Wt,[xe]:Ve})),Ue}finally{Z(Ue=>{const{[xe]:Ve,...Wt}=Ue;return Wt})}},[t.files,ge,I,K]);return u.jsx("div",{className:"h-full min-h-0 border-l border-border bg-background md:min-w-[370px]",children:u.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[u.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pl-2.5 pr-2 py-2",children:[u.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:u.jsx(Ybe,{currentBranchName:t.branchName,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:y,onCheckoutBranch:_,onCreateBranch:w})}),t.status==="ready"?Rt?on==="publish"?u.jsxs(De,{variant:"ghost",size:"sm",onClick:()=>void rt(),disabled:H,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[H?u.jsx(_n,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(Yv,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Publish Branch"})]}):u.jsxs("div",{className:"flex items-center gap-1",children:[on==="fetch"?u.jsxs(si,{delayDuration:0,children:[u.jsx(oi,{asChild:!0,children:u.jsxs(De,{variant:"ghost",size:"sm",onClick:()=>void rt(),disabled:H,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[H?u.jsx(_n,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(X5,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Fetch"})]})}),u.jsx(qr,{children:Ube(t.lastFetchedAt)})]}):u.jsxs(De,{variant:"ghost",size:"sm",onClick:()=>void rt(),disabled:H,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[H?u.jsx(_n,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(pk,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Pull"}),u.jsx("span",{className:"inline-flex min-w-4 items-center justify-center rounded-full bg-muted px-1 text-[10px] text-muted-foreground",children:Be})]}),qe&&Ie>0?u.jsxs(De,{variant:"default",size:"sm",onClick:()=>void rt("push"),disabled:H,className:"h-7 gap-1.5 px-2 text-xs",children:[H?u.jsx(_n,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(Yv,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Push"}),u.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:Ie})]}):null,At&&Zt?u.jsxs(De,{variant:"ghost",size:"sm",onClick:()=>{typeof window>"u"||window.open(Zt,"_blank","noopener,noreferrer")},className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[u.jsx(W5,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"PR"})]}):null]}):u.jsxs(De,{variant:"default",size:"sm",onClick:()=>O(!0),className:"h-7 gap-1.5 px-3 text-xs",children:[u.jsx(vG,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Push to GitHub"})]}):null]}),u.jsxs("div",{className:"relative min-h-0 flex-1",children:[u.jsx("div",{className:"sticky top-0 z-30 pl-[14px] pr-[12px] pt-[6px] bg-gradient-to-b from-background to-transparent",children:u.jsx("div",{className:"relative h-[40px] flex min-w-0 items-center justify-center gap-[13px]",children:u.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-[13px] relative",children:[we==="changes"?u.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground/70",children:[u.jsx(mF,{checked:Te,mixed:He,label:He?"Select all files for commit":Te?"Unselect all files from commit":"Select all files for commit",onClick:()=>{!e||t.files.length===0||Dt(e,le,He?!0:!Te)}}),u.jsxs("span",{children:[me," files"]})]}):u.jsx("div",{}),u.jsx("div",{className:"pointer-events-none absolute left-1/2 -translate-x-1/2 top-1/2 -translate-y-1/2",children:u.jsx("div",{className:"pointer-events-auto",children:u.jsx(Ii,{value:we,onValueChange:xe=>{e&&_e(e,xe)},size:"sm",optionClassName:"flex-1 justify-center",options:[{value:"changes",label:"Changes"},{value:"history",label:"History"}]})})}),we==="changes"?u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(Jw,{label:"Unified diff",active:r==="unified",onClick:()=>U("unified"),children:u.jsx(xq,{className:"h-4 w-4"})}),u.jsx(Jw,{label:"Side-by-side diff",active:r==="split",onClick:()=>U("split"),children:u.jsx(SW,{className:"h-4 w-4"})}),u.jsx(Jw,{label:i?"Disable word wrap":"Enable word wrap",active:i,onClick:()=>M(!i),children:u.jsx(Yq,{className:"h-4 w-4"})})]}):u.jsx("div",{})]})})}),u.jsx("div",{ref:ne,className:"h-full overflow-y-auto [scrollbar-gutter:stable]",children:t.status==="no_repo"?u.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:u.jsxs("div",{className:"flex max-w-[280px] flex-col items-center gap-3",children:[u.jsx("p",{className:"text-sm text-muted-foreground",children:"Initialize git here to start tracking branches, diffs, and history."}),u.jsx(De,{size:"sm",onClick:()=>void E(),children:"Init Git"})]})}):we==="history"?Ke.length===0?u.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:u.jsxs("p",{className:"text-sm text-muted-foreground",children:["No recent commits on ",t.branchName??"this branch","."]})}):u.jsx("div",{className:"space-y-1.5 p-1.5",children:Ke.map((xe,Pe)=>u.jsx(Vbe,{entry:xe,isPendingPush:Pe<Ie},xe.sha))}):t.files.length===0?u.jsx("div",{className:"flex h-full items-center justify-center px-6 py-3 text-center",children:u.jsx("p",{className:"text-sm text-muted-foreground",children:"No file changes."})}):u.jsxs("div",{className:"space-y-1.5 p-1.5 pb-10",children:[t.files.map(xe=>{const Pe=Ce[xe.path]??!0,Ue=pt[xe.path]??!0;return u.jsx(Xbe,{file:xe,rootRef:ne,projectId:e,isCollapsed:Pe,isChecked:Ue,editorLabel:n,diffRenderMode:r,wrapLines:i,onToggleCollapsed:()=>{e&&Tt(e,xe.path)},onToggleChecked:()=>{e&&Bt(e,xe.path,!Ue)},fileActions:D,patch:K[xe.path],patchError:V[xe.path],isPatchLoading:!!ge[xe.path],onLoadPatch:Ye},xe.path)}),we==="changes"?u.jsxs("div",{className:"pointer-events-none sticky inset-x-0 bottom-11 py-1 pb-6 z-30 overflow-y-auto",children:[u.jsx("div",{className:"absolute inset-x-0 bottom-0 top-0 bg-gradient-to-t from-background to-transparent"}),u.jsx("div",{className:"pointer-events-auto relative",children:u.jsxs("div",{className:"space-y-0 rounded-xl mx-auto max-w-[700px]",children:[u.jsx(mn,{value:Oe,onChange:xe=>{e&&cn(e,{summary:xe.target.value,description:Ze})},onKeyDown:ye,placeholder:"Commit message (override)",className:"rounded-t-xl rounded-b-none px-3",disabled:ze||t.status!=="ready"}),u.jsx(Vl,{value:Ze,onChange:xe=>{e&&cn(e,{summary:Oe,description:xe.target.value})},onKeyDown:ye,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:ze||t.status!=="ready"}),u.jsx("div",{className:"w-full flex flex-row",children:u.jsxs(fu,{children:[u.jsx(mu,{asChild:!0,children:u.jsx(De,{type:"button",className:"-mt-px w-full rounded-xl",disabled:Xe?!gt:!_t,onClick:()=>{if(Xe){Ut(Ct);return}it()},children:u.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[Xe?yt?u.jsx(_n,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):Ct==="commit_and_push"?t.hasUpstream?u.jsx(Yv,{strokeWidth:2.5,className:"size-3 shrink-0"}):u.jsx(V5,{strokeWidth:2.5,className:"size-3 shrink-0"}):u.jsx(ns,{strokeWidth:2.5,className:"size-3 shrink-0"}):P?u.jsx(_n,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):u.jsx(tq,{strokeWidth:2.5,className:"size-3 shrink-0"}),u.jsx("span",{className:"min-w-0 truncate text-left",children:Xe?yt?$==="commit_only"?"Committing...":"Committing & Pushing...":Ct==="commit_only"?u.jsxs(u.Fragment,{children:["Commit to ",u.jsx(Ea,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),vt]}):t.hasUpstream?u.jsxs(u.Fragment,{children:["Commit & push to ",u.jsx(Ea,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),vt]}):u.jsxs(u.Fragment,{children:["Commit & publish ",u.jsx(Ea,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),vt]}):P?"Generating...":u.jsxs(u.Fragment,{children:["Generate message for ",u.jsx(Ea,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),vt]})})]})})}),t.hasUpstream?u.jsx(ec,{children:u.jsx(Pn,{disabled:!Xe||!gt,onSelect:xe=>{xe.stopPropagation(),Ut("commit_only")},children:"Commit Only"})}):null]})})]})})]}):null]})})]}),u.jsx(qbe,{open:te,onOpenChange:O,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:T,onPublish:R})]})})}const Zbe=v.memo(Qbe);function Jbe(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function exe(e,t){const n=getComputedStyle(e.ownerDocument.body),r=parseFloat(n.fontSize);return t*r}function txe(e){return e/100*window.innerHeight}function nxe(e){return e/100*window.innerWidth}function rxe(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 Ff({groupSize:e,panelElement:t,styleProp:n}){let r;const[i,s]=rxe(n);switch(s){case"%":{r=i/100*e;break}case"px":{r=i;break}case"rem":{r=exe(t,i);break}case"em":{r=Jbe(t,i);break}case"vh":{r=txe(i);break}case"vw":{r=nxe(i);break}}return r}function Pi(e){return parseFloat(e.toFixed(3))}function Yd({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 sC(e){const{panels:t}=e,n=Yd({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 f=Ff({groupSize:n,panelElement:i,styleProp:s.collapsedSize});o=Pi(f/n*100)}let a;if(s.defaultSize!==void 0){const f=Ff({groupSize:n,panelElement:i,styleProp:s.defaultSize});a=Pi(f/n*100)}let c=0;if(s.minSize!==void 0){const f=Ff({groupSize:n,panelElement:i,styleProp:s.minSize});c=Pi(f/n*100)}let d=100;if(s.maxSize!==void 0){const f=Ff({groupSize:n,panelElement:i,styleProp:s.maxSize});d=Pi(f/n*100)}return{groupResizeBehavior:s.groupResizeBehavior,collapsedSize:o,collapsible:s.collapsible===!0,defaultSize:a,disabled:s.disabled,minSize:c,maxSize:d,panelId:r.id}})}function jn(e,t="Assertion error"){if(!e)throw Error(t)}function oC(e,t){return Array.from(t).sort(e==="horizontal"?ixe:sxe)}function ixe(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function sxe(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function gF(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function vF(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 oxe({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:a,y:c}=vF(r,o),d=e==="horizontal"?a:c;d<s&&(s=d,i=o)}return jn(i,"No rect found"),i}let kv;function axe(){return kv===void 0&&(typeof matchMedia=="function"?kv=!!matchMedia("(pointer:coarse)").matches:kv=!1),kv}function bF(e){const{element:t,orientation:n,panels:r,separators:i}=e,s=oC(n,Array.from(t.children).filter(gF).map(y=>({element:y}))).map(({element:y})=>y),o=[];let a=!1,c=!1,d=-1,f=-1,m=0,g,b=[];{let y=-1;for(const _ of s)_.hasAttribute("data-panel")&&(y++,_.ariaDisabled===null&&(m++,d===-1&&(d=y),f=y))}if(m>1){let y=-1;for(const _ of s)if(_.hasAttribute("data-panel")){y++;const w=r.find(C=>C.element===_);if(w){if(g){const C=g.element.getBoundingClientRect(),E=_.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),R=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,R];break}case 1:{const A=b[0],j=oxe({orientation:n,rects:[C,E],targetRect:A.element.getBoundingClientRect()});k=[A,j===C?R: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 R="width"in T?T:T.element.getBoundingClientRect();const A=axe()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(R.width<A){const I=A-R.width;R=new DOMRect(R.x-I/2,R.y,R.width+I,R.height)}if(R.height<A){const I=A-R.height;R=new DOMRect(R.x,R.y-I/2,R.width,R.height+I)}const j=y<=d||y>f;!a&&!j&&o.push({group:e,groupSize:Yd({group:e}),panels:[g,w],separator:"width"in T?void 0:T,rect:R}),a=!1}}c=!1,g=w,b=[]}}else if(_.hasAttribute("data-separator")){_.ariaDisabled!==null&&(a=!0);const w=i.find(C=>C.element===_);w?b.push(w):(g=void 0,b=[])}else c=!0}return o}var zl,f5;let xF=(f5=class{constructor(){_l(this,zl,{})}addListener(t,n){const r=vr(this,zl)[t];return r===void 0?vr(this,zl)[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=vr(this,zl)[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 a=0;a<o.length;a++){const c=o[a];try{c.call(null,n)}catch(d){s===null&&(i=!0,s=d)}}if(i)throw s}}removeAllListeners(){gs(this,zl,{})}removeListener(t,n){const r=vr(this,zl)[t];if(r!==void 0){const i=r.indexOf(n);i>=0&&r.splice(i,1)}}},zl=new WeakMap,f5),Po=new Map;const yF=new xF;function lxe(e){Po=new Map(Po),Po.delete(e)}function MI(e,t){for(const[n]of Po)if(n.id===e)return n}function Wl(e,t){for(const[n,r]of Po)if(n.id===e)return r;if(t)throw Error(`Could not find data for Group with id ${e}`)}function gu(){return Po}function v2(e,t){return yF.addListener("groupChange",n=>{n.group.id===e&&t(n)})}function Fa(e,t){const n=Po.get(e);Po=new Map(Po),Po.set(e,t),yF.emit("groupChange",{group:e,prev:n,next:t})}function cxe(e,t,n){let r,i={x:1/0,y:1/0};for(const s of t){const o=vF(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 uxe(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function dxe(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:DI(e),b:DI(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();jn(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:II(LI(n.a)),b:II(LI(n.b))};if(i.a===i.b){const s=r.childNodes,o={a:n.a.at(-1),b:n.b.at(-1)};let a=s.length;for(;a--;){const c=s[a];if(c===o.a)return 1;if(c===o.b)return-1}}return Math.sign(i.a-i.b)}const hxe=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function fxe(e){const t=getComputedStyle(_F(e)??e).display;return t==="flex"||t==="inline-flex"}function mxe(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||fxe(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"||hxe.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function LI(e){let t=e.length;for(;t--;){const n=e[t];if(jn(n,"Missing node"),mxe(n))return n}return null}function II(e){return e&&Number(getComputedStyle(e).zIndex)||0}function DI(e){const t=[];for(;e;)t.push(e),e=_F(e);return t}function _F(e){const{parentNode:t}=e;return uxe(t)?t.host:t}function pxe(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 gxe({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!gF(n)||n.contains(e)||e.contains(n))return!0;if(dxe(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(pxe(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function b2(e,t){const n=[];return t.forEach((r,i)=>{if(i.disabled)return;const s=bF(i),o=cxe(i.orientation,s,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&gxe({groupElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&n.push(o.hitRegion)}),n}function vxe(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 pi(e,t,n=0){return Math.abs(Pi(e)-Pi(t))<=n}function Ro(e,t){return pi(e,t)?0:e>t?1:-1}function wd({overrideDisabledPanels:e,panelConstraints:t,prevSize:n,size:r}){const{collapsedSize:i=0,collapsible:s,disabled:o,maxSize:a=100,minSize:c=0}=t;if(o&&!e)return n;if(Ro(r,c)<0)if(s){const d=(i+c)/2;Ro(r,d)<0?r=i:r=c}else r=c;return r=Math.min(a,r),r=Pi(r),r}function $m({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(pi(e,0))return t;const o=s==="imperative-api",a=Object.values(t),c=Object.values(i),d=[...a],[f,m]=r;jn(f!=null,"Invalid first pivot index"),jn(m!=null,"Invalid second pivot index");let g=0;switch(s){case"keyboard":{{const _=e<0?m:f,w=n[_];jn(w,`Panel constraints not found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const T=a[_];if(jn(T!=null,`Previous layout not found for panel index ${_}`),pi(T,C)){const R=k-T;Ro(R,Math.abs(e))>0&&(e=e<0?0-R:R)}}}{const _=e<0?f:m,w=n[_];jn(w,`No panel constraints found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const T=a[_];if(jn(T!=null,`Previous layout not found for panel index ${_}`),pi(T,k)){const R=T-C;Ro(R,Math.abs(e))>0&&(e=e<0?0-R:R)}}}break}default:{const _=e<0?m:f,w=n[_];jn(w,`Panel constraints not found for index ${_}`);const C=a[_],{collapsible:E,collapsedSize:k,minSize:T}=w;if(E&&Ro(C,T)<0)if(e>0){const R=T-k,A=R/2,j=C+e;Ro(j,T)<0&&(e=Ro(e,A)<=0?0:R)}else{const R=T-k,A=100-R/2,j=C-e;Ro(j,T)<0&&(e=Ro(100+e,A)>0?0:-R)}break}}{const _=e<0?1:-1;let w=e<0?m:f,C=0;for(;;){const k=a[w];jn(k!=null,`Previous layout not found for panel index ${w}`);const T=wd({overrideDisabledPanels:o,panelConstraints:n[w],prevSize:k,size:100})-k;if(C+=T,w+=_,w<0||w>=n.length)break}const E=Math.min(Math.abs(e),Math.abs(C));e=e<0?0-E:E}{let _=e<0?f:m;for(;_>=0&&_<n.length;){const w=Math.abs(e)-Math.abs(g),C=a[_];jn(C!=null,`Previous layout not found for panel index ${_}`);const E=C-w,k=wd({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:C,size:E});if(!pi(C,k)&&(g+=C-k,d[_]=k,g.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?_--:_++}}if(vxe(c,d))return i;{const _=e<0?m:f,w=a[_];jn(w!=null,`Previous layout not found for panel index ${_}`);const C=w+g,E=wd({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:w,size:C});if(d[_]=E,!pi(E,C)){let k=C-E,T=e<0?m:f;for(;T>=0&&T<n.length;){const R=d[T];jn(R!=null,`Previous layout not found for panel index ${T}`);const A=R+k,j=wd({overrideDisabledPanels:o,panelConstraints:n[T],prevSize:R,size:A});if(pi(R,j)||(k-=j-R,d[T]=j),pi(k,0))break;e>0?T--:T++}}}const b=Object.values(d).reduce((_,w)=>w+_,0);if(!pi(b,100,.1))return i;const y=Object.keys(i);return d.reduce((_,w,C)=>(_[y[C]]=w,_),{})}function tu(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(t[n]===void 0||Ro(e[n],t[n])!==0)return!1;return!0}function nu({layout:e,panelConstraints:t}){const n=Object.values(e),r=[...n],i=r.reduce((a,c)=>a+c,0);if(r.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${r.map(a=>`${a}%`).join(", ")}`);if(!pi(i,100)&&r.length>0)for(let a=0;a<t.length;a++){const c=r[a];jn(c!=null,`No layout data found for index ${a}`);const d=100/i*c;r[a]=d}let s=0;for(let a=0;a<t.length;a++){const c=n[a];jn(c!=null,`No layout data found for index ${a}`);const d=r[a];jn(d!=null,`No layout data found for index ${a}`);const f=wd({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:c,size:d});d!=f&&(s+=d-f,r[a]=f)}if(!pi(s,0))for(let a=0;a<t.length;a++){const c=r[a];jn(c!=null,`No layout data found for index ${a}`);const d=c+s,f=wd({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:c,size:d});if(c!==f&&(s-=f-c,r[a]=f,pi(s,0)))break}const o=Object.keys(e);return r.reduce((a,c,d)=>(a[o[d]]=c,a),{})}function wF({groupId:e,panelId:t}){const n=()=>{const a=gu();for(const[c,{defaultLayoutDeferred:d,derivedPanelConstraints:f,layout:m,groupSize:g,separatorToPanels:b}]of a)if(c.id===e)return{defaultLayoutDeferred:d,derivedPanelConstraints:f,group:c,groupSize:g,layout:m,separatorToPanels:b};throw Error(`Group ${e} not found`)},r=()=>{const a=n().derivedPanelConstraints.find(c=>c.panelId===t);if(a!==void 0)return a;throw Error(`Panel constraints not found for Panel ${t}`)},i=()=>{const a=n().group.panels.find(c=>c.id===t);if(a!==void 0)return a;throw Error(`Layout not found for Panel ${t}`)},s=()=>{const a=n().layout[t];if(a!==void 0)return a;throw Error(`Layout not found for Panel ${t}`)},o=a=>{const c=s();if(a===c)return;const{defaultLayoutDeferred:d,derivedPanelConstraints:f,group:m,groupSize:g,layout:b,separatorToPanels:y}=n(),_=m.panels.findIndex(k=>k.id===t),w=_===m.panels.length-1,C=$m({delta:w?c-a:a-c,initialLayout:b,panelConstraints:f,pivotIndices:w?[_-1,_]:[_,_+1],prevLayout:b,trigger:"imperative-api"}),E=nu({layout:C,panelConstraints:f});tu(b,E)||Fa(m,{defaultLayoutDeferred:d,derivedPanelConstraints:f,groupSize:g,layout:E,separatorToPanels:y})};return{collapse:()=>{const{collapsible:a,collapsedSize:c}=r(),{mutableValues:d}=i(),f=s();a&&f!==c&&(d.expandToSize=f,o(c))},expand:()=>{const{collapsible:a,collapsedSize:c,minSize:d}=r(),{mutableValues:f}=i(),m=s();if(a&&m===c){let g=f.expandToSize??d;g===0&&(g=1),o(g)}},getSize:()=>{const{group:a}=n(),c=s(),{element:d}=i(),f=a.orientation==="horizontal"?d.offsetWidth:d.offsetHeight;return{asPercentage:c,inPixels:f}},isCollapsed:()=>{const{collapsible:a,collapsedSize:c}=r(),d=s();return a&&pi(c,d)},resize:a=>{const{group:c}=n(),{element:d}=i(),f=Yd({group:c}),m=Ff({groupSize:f,panelElement:d,styleProp:a}),g=Pi(m/f*100);o(g)}}}function PI(e){if(e.defaultPrevented)return;const t=gu();b2(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=wF({groupId:n.group.id,panelId:r.id});s&&i!==void 0&&(s.resize(i),e.preventDefault())}}})}function db(e){const t=gu();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 SF({groupId:e}){const t=()=>{const n=gu();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:a,separatorToPanels:c}=t(),d=nu({layout:n,panelConstraints:i});return r?a:(tu(a,d)||Fa(s,{defaultLayoutDeferred:r,derivedPanelConstraints:i,groupSize:o,layout:d,separatorToPanels:c}),d)}}}function Tc(e,t){const n=db(e),r=Wl(n.id,!0),i=n.separators.find(f=>f.element===e);jn(i,"Matching separator not found");const s=r.separatorToPanels.get(i);jn(s,"Matching panels not found");const o=s.map(f=>n.panels.indexOf(f)),a=SF({groupId:n.id}).getLayout(),c=$m({delta:t,initialLayout:a,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:a,trigger:"keyboard"}),d=nu({layout:c,panelConstraints:r.derivedPanelConstraints});tu(a,d)||Fa(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:d,separatorToPanels:r.separatorToPanels})}function OI(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=db(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&Tc(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&Tc(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&Tc(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&Tc(t,-5);break}case"End":{e.preventDefault(),Tc(t,100);break}case"Enter":{e.preventDefault();const r=db(t),i=Wl(r.id,!0),{derivedPanelConstraints:s,layout:o,separatorToPanels:a}=i,c=r.separators.find(g=>g.element===t);jn(c,"Matching separator not found");const d=a.get(c);jn(d,"Matching panels not found");const f=d[0],m=s.find(g=>g.panelId===f.id);if(jn(m,"Panel metadata not found"),m.collapsible){const g=o[f.id],b=m.collapsedSize===g?r.mutableState.expandedPanelSizes[f.id]??m.minSize:m.collapsedSize;Tc(t,b-g)}break}case"F6":{e.preventDefault();const r=db(t).separators.map(o=>o.element),i=Array.from(r).findIndex(o=>o===e.currentTarget);jn(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(),Tc(t,-100);break}}}let Dd={cursorFlags:0,state:"inactive"};const x2=new xF;function ru(){return Dd}function bxe(e){return x2.addListener("change",e)}function xxe(e){const t=Dd,n={...Dd};n.cursorFlags=e,Dd=n,x2.emit("change",{prev:t,next:n})}function Pd(e){const t=Dd;Dd=e,x2.emit("change",{prev:t,next:e})}function zI(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=gu(),n=b2(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)}),Pd({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}const yxe=e=>e,eS=()=>{},CF=1,kF=2,EF=4,NF=8,BI=3,FI=12;let Ev;function $I(){return Ev===void 0&&(Ev=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(Ev=!0)),Ev}function _xe({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&&$I()){const s=(e&CF)!==0,o=(e&kF)!==0,a=(e&EF)!==0,c=(e&NF)!==0;if(s)return a?"se-resize":c?"ne-resize":"e-resize";if(o)return a?"sw-resize":c?"nw-resize":"w-resize";if(a)return"s-resize";if(c)return"n-resize"}break}}return $I()?r>0&&i>0?"move":r>0?"ew-resize":"ns-resize":r>0&&i>0?"grab":r>0?"col-resize":"row-resize"}}const HI=new WeakMap;function y2(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=HI.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&e.adoptedStyleSheets.push(n));const r=ru();switch(r.state){case"active":case"hover":{const i=_xe({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}}HI.set(e,{prevStyle:t,styleSheet:n})}function TF({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:i,pointerDownAtPoint:s,prevCursorFlags:o}){let a=0;n.forEach(d=>{const{group:f,groupSize:m}=d,{orientation:g,panels:b}=f,{disableCursor:y}=f.mutableState;let _=0;s?g==="horizontal"?_=(t.clientX-s.x)/m*100:_=(t.clientY-s.y)/m*100:g==="horizontal"?_=t.clientX<0?-100:100:_=t.clientY<0?-100:100;const w=r.get(f),C=i.get(f);if(!w||!C)return;const{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:T,layout:R,separatorToPanels:A}=C;if(k&&R&&A){const j=$m({delta:_,initialLayout:w,panelConstraints:k,pivotIndices:d.panels.map(I=>b.indexOf(I)),prevLayout:R,trigger:"mouse-or-touch"});if(tu(j,R)){if(_!==0&&!y)switch(g){case"horizontal":{a|=_<0?CF:kF;break}case"vertical":{a|=_<0?EF:NF;break}}}else Fa(d.group,{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:T,layout:j,separatorToPanels:A})}});let c=0;t.movementX===0?c|=o&BI:c|=a&BI,t.movementY===0?c|=o&FI:c|=a&FI,xxe(c),y2(e)}function UI(e){const t=gu(),n=ru();switch(n.state){case"active":TF({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function VI(e){if(e.defaultPrevented)return;const t=ru(),n=gu();switch(t.state){case"active":{if(e.buttons===0){Pd({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(r=>{const i=Wl(r.group.id,!0);Fa(r.group,i)});return}TF({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const r=b2(e,n);r.length===0?t.state!=="inactive"&&Pd({cursorFlags:0,state:"inactive"}):Pd({cursorFlags:0,hitRegions:r,state:"hover"}),y2(e.currentTarget);break}}}function WI(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(ru().state){case"hover":Pd({cursorFlags:0,state:"inactive"})}}function GI(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=ru();switch(t.state){case"active":Pd({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(y2(e.currentTarget),t.hitRegions.forEach(n=>{const r=Wl(n.group.id,!0);Fa(n.group,r)}),e.preventDefault())}}function qI(e){let t=0,n=0;const r={};for(const s of e)if(s.defaultSize!==void 0){t++;const o=Pi(s.defaultSize);n+=o,r[s.panelId]=o}else r[s.panelId]=void 0;const i=e.length-t;if(i!==0){const s=Pi((100-n)/i);for(const o of e)o.defaultSize===void 0&&(r[o.panelId]=s)}return r}function wxe(e,t,n){if(!n[0])return;const r=e.panels.find(c=>c.element===t);if(!r||!r.onResize)return;const i=Yd({group:e}),s=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,a={asPercentage:Pi(s/i*100),inPixels:s};r.mutableValues.prevSize=a,r.onResize(a,r.id,o)}function Sxe(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 Cxe({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 a=new Map,c=[];for(const m of e.panels){const g=r[m.id]??0;switch(m.panelConstraints.groupResizeBehavior){case"preserve-pixel-size":{o=!0;const b=g/100*n,y=Pi(b/t*100);a.set(m.id,y),i+=y;break}case"preserve-relative-size":default:{c.push(m.id),s+=g;break}}}if(!o||c.length===0)return r;const d=100-i,f={...r};if(a.forEach((m,g)=>{f[g]=m}),s>0)for(const m of c){const g=r[m]??0;f[m]=Pi(g/s*d)}else{const m=Pi(d/c.length);for(const g of c)f[g]=m}return f}function kxe(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 cd=new Map;function Exe(e){let t=!0;jn(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(y=>{for(const _ of y){const{borderBoxSize:w,target:C}=_;if(C===e.element){if(t){const E=Yd({group:e});if(E===0)return;const k=Wl(e.id);if(!k)return;const T=sC(e),R=k.defaultLayoutDeferred?qI(T):k.layout,A=Cxe({group:e,nextGroupSize:E,prevGroupSize:k.groupSize,prevLayout:R}),j=nu({layout:A,panelConstraints:T});if(!k.defaultLayoutDeferred&&tu(k.layout,j)&&Sxe(k.derivedPanelConstraints,T)&&k.groupSize===E)return;Fa(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:T,groupSize:E,layout:j,separatorToPanels:k.separatorToPanels})}}else wxe(e,C,w)}});s.observe(e.element),e.panels.forEach(y=>{jn(!r.has(y.id),`Panel ids must be unique; id "${y.id}" was used more than once`),r.add(y.id),y.onResize&&s.observe(y.element)});const o=Yd({group:e}),a=sC(e),c=e.panels.map(({id:y})=>y).join(",");let d=e.mutableState.defaultLayout;d&&(kxe(e.panels,d)||(d=void 0));const f=e.mutableState.layouts[c]??d??qI(a),m=nu({layout:f,panelConstraints:a}),g=e.element.ownerDocument;cd.set(g,(cd.get(g)??0)+1);const b=new Map;return bF(e).forEach(y=>{y.separator&&b.set(y.separator,y.panels)}),Fa(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:a,groupSize:o,layout:m,separatorToPanels:b}),e.separators.forEach(y=>{jn(!i.has(y.id),`Separator ids must be unique; id "${y.id}" was used more than once`),i.add(y.id),y.element.addEventListener("keydown",OI)}),cd.get(g)===1&&(g.addEventListener("dblclick",PI,!0),g.addEventListener("pointerdown",zI,!0),g.addEventListener("pointerleave",UI),g.addEventListener("pointermove",VI),g.addEventListener("pointerout",WI),g.addEventListener("pointerup",GI,!0)),function(){t=!1,cd.set(g,Math.max(0,(cd.get(g)??0)-1)),lxe(e),e.separators.forEach(y=>{y.element.removeEventListener("keydown",OI)}),cd.get(g)||(g.removeEventListener("dblclick",PI,!0),g.removeEventListener("pointerdown",zI,!0),g.removeEventListener("pointerleave",UI),g.removeEventListener("pointermove",VI),g.removeEventListener("pointerout",WI),g.removeEventListener("pointerup",GI,!0)),s.disconnect()}}function Nxe(){const[e,t]=v.useState({}),n=v.useCallback(()=>t({}),[]);return[e,n]}function _2(e){const t=v.useId();return`${e??t}`}const vu=typeof window<"u"?v.useLayoutEffect:v.useEffect;function im(e){const t=v.useRef(e);return vu(()=>{t.current=e},[e]),v.useCallback((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[t])}function w2(...e){return im(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function S2(e){const t=v.useRef({...e});return vu(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const RF=v.createContext(null);function Txe(e,t){const n=v.useRef({getLayout:()=>({}),setLayout:yxe});v.useImperativeHandle(t,()=>n.current,[]),vu(()=>{Object.assign(n.current,SF({groupId:e}))})}function AF({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:s,groupRef:o,id:a,onLayoutChange:c,onLayoutChanged:d,orientation:f="horizontal",resizeTargetMinimumSize:m={coarse:20,fine:10},style:g,...b}){const y=v.useRef({onLayoutChange:{},onLayoutChanged:{}}),_=im(D=>{tu(y.current.onLayoutChange,D)||(y.current.onLayoutChange=D,c==null||c(D))}),w=im(D=>{tu(y.current.onLayoutChanged,D)||(y.current.onLayoutChanged=D,d==null||d(D))}),C=_2(a),E=v.useRef(null),[k,T]=Nxe(),R=v.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:m,separators:[]}),A=w2(E,s);Txe(C,o);const j=im((D,z)=>{const P=ru(),F=MI(D),$=Wl(D);if($){let B=!1;switch(P.state){case"active":{B=P.hitRegions.some(H=>H.group===F);break}}return{flexGrow:$.layout[z]??1,pointerEvents:B?"none":void 0}}return{flexGrow:(n==null?void 0:n[z])??1}}),I=S2({defaultLayout:n,disableCursor:r}),U=v.useMemo(()=>({get disableCursor(){return!!I.disableCursor},getPanelStyles:j,id:C,orientation:f,registerPanel:D=>{const z=R.current;return z.panels=oC(f,[...z.panels,D]),T(),()=>{z.panels=z.panels.filter(P=>P!==D),T()}},registerSeparator:D=>{const z=R.current;return z.separators=oC(f,[...z.separators,D]),T(),()=>{z.separators=z.separators.filter(P=>P!==D),T()}},togglePanelDisabled:(D,z)=>{const P=R.current.panels.find(B=>B.id===D);P&&(P.panelConstraints.disabled=z);const F=MI(C),$=Wl(C);F&&$&&Fa(F,{...$,derivedPanelConstraints:sC(F)})},toggleSeparatorDisabled:(D,z)=>{const P=R.current.separators.find(F=>F.id===D);P&&(P.disabled=z)}}),[j,C,T,f,I]),M=v.useRef(null);return vu(()=>{const D=E.current;if(D===null)return;const z=R.current;let P;if(I.defaultLayout!==void 0&&Object.keys(I.defaultLayout).length===z.panels.length){P={};for(const O of z.panels){const K=I.defaultLayout[O.id];K!==void 0&&(P[O.id]=K)}}const F={disabled:!!i,element:D,id:C,mutableState:{defaultLayout:P,disableCursor:!!I.disableCursor,expandedPanelSizes:R.current.lastExpandedPanelSizes,layouts:R.current.layouts},orientation:f,panels:z.panels,resizeTargetMinimumSize:z.resizeTargetMinimumSize,separators:z.separators};M.current=F;const $=Exe(F),{defaultLayoutDeferred:B,derivedPanelConstraints:H,layout:W}=Wl(F.id,!0);!B&&H.length>0&&(_(W),w(W));const te=v2(C,O=>{const{defaultLayoutDeferred:K,derivedPanelConstraints:ee,layout:V}=O.next;if(K||ee.length===0)return;const ue=F.panels.map(({id:Z})=>Z).join(",");F.mutableState.layouts[ue]=V,ee.forEach(Z=>{if(Z.collapsible){const{layout:ne}=O.prev??{};if(ne){const ie=pi(Z.collapsedSize,V[Z.panelId]),le=pi(Z.collapsedSize,ne[Z.panelId]);ie&&!le&&(F.mutableState.expandedPanelSizes[Z.panelId]=ne[Z.panelId])}}});const ge=ru().state!=="active";_(V),ge&&w(V)});return()=>{M.current=null,$(),te()}},[i,C,w,_,f,k,I]),v.useEffect(()=>{const D=M.current;D&&(D.mutableState.defaultLayout=n,D.mutableState.disableCursor=!!r)}),u.jsx(RF.Provider,{value:U,children:u.jsx("div",{...b,className:t,"data-group":!0,"data-testid":C,id:C,ref:A,style:{height:"100%",width:"100%",overflow:"hidden",...g,display:"flex",flexDirection:f==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:f==="horizontal"?"pan-y":"pan-x"},children:e})})}AF.displayName="Group";function C2(){const e=v.useContext(RF);return jn(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function Rxe(e,t){const{id:n}=C2(),r=v.useRef({collapse:eS,expand:eS,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:eS});v.useImperativeHandle(t,()=>r.current,[]),vu(()=>{Object.assign(r.current,wF({groupId:n,panelId:e}))})}function jF({children:e,className:t,collapsedSize:n="0%",collapsible:r=!1,defaultSize:i,disabled:s,elementRef:o,groupResizeBehavior:a="preserve-relative-size",id:c,maxSize:d="100%",minSize:f="0%",onResize:m,panelRef:g,style:b,...y}){const _=!!c,w=_2(c),C=S2({disabled:s}),E=v.useRef(null),k=w2(E,o),{getPanelStyles:T,id:R,orientation:A,registerPanel:j,togglePanelDisabled:I}=C2(),U=m!==null,M=im((z,P,F)=>{m==null||m(z,c,F)});vu(()=>{const z=E.current;if(z!==null){const P={element:z,id:w,idIsStable:_,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:U?M:void 0,panelConstraints:{groupResizeBehavior:a,collapsedSize:n,collapsible:r,defaultSize:i,disabled:C.disabled,maxSize:d,minSize:f}};return j(P)}},[a,n,r,i,U,w,_,d,f,M,j,C]),v.useEffect(()=>{I(w,!!s)},[s,w,I]),Rxe(w,g);const D=v.useSyncExternalStore(z=>v2(R,z),()=>JSON.stringify(T(R,w)),()=>JSON.stringify(T(R,w)));return u.jsx("div",{...y,"aria-disabled":s||void 0,"data-panel":!0,"data-testid":w,id:w,ref:k,style:{...Axe,display:"flex",flexBasis:0,flexShrink:1,overflow:"visible",...JSON.parse(D)},children:u.jsx("div",{className:t,style:{maxHeight:"100%",maxWidth:"100%",flexGrow:1,overflow:"auto",...b,touchAction:A==="horizontal"?"pan-y":"pan-x"},children:e})})}jF.displayName="Panel";const Axe={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function jxe({layout:e,panelConstraints:t,panelId:n,panelIndex:r}){let i,s;const o=e[n],a=t.find(c=>c.panelId===n);if(a){const c=a.maxSize,d=a.collapsible?a.collapsedSize:a.minSize,f=[r,r+1];s=nu({layout:$m({delta:d-o,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e}),panelConstraints:t})[n],i=nu({layout:$m({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:s,valueNow:o}}function MF({children:e,className:t,disabled:n,elementRef:r,id:i,style:s,...o}){const a=_2(i),c=S2({disabled:n}),[d,f]=v.useState({}),[m,g]=v.useState("inactive"),b=v.useRef(null),y=w2(b,r),{disableCursor:_,id:w,orientation:C,registerSeparator:E,toggleSeparatorDisabled:k}=C2(),T=C==="horizontal"?"vertical":"horizontal";vu(()=>{const A=b.current;if(A!==null){const j={disabled:c.disabled,element:A,id:a},I=E(j),U=bxe(D=>{g(D.next.state!=="inactive"&&D.next.hitRegions.some(z=>z.separator===j)?D.next.state:"inactive")}),M=v2(w,D=>{const{derivedPanelConstraints:z,layout:P,separatorToPanels:F}=D.next,$=F.get(j);if($){const B=$[0],H=$.indexOf(B);f(jxe({layout:P,panelConstraints:z,panelId:B.id,panelIndex:H}))}});return()=>{U(),M(),I()}}},[w,a,E,c]),v.useEffect(()=>{k(a,!!n)},[n,a,k]);let R;return n&&!_&&(R="not-allowed"),u.jsx("div",{...o,"aria-controls":d.valueControls,"aria-disabled":n||void 0,"aria-orientation":T,"aria-valuemax":d.valueMax,"aria-valuemin":d.valueMin,"aria-valuenow":d.valueNow,children:e,className:t,"data-separator":n?"disabled":m,"data-testid":a,id:a,ref:y,role:"separator",style:{flexBasis:"auto",cursor:R,...s,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:n?void 0:0})}MF.displayName="Separator";const k2=({className:e,...t})=>u.jsx(AF,{className:de("flex h-full w-full",e),...t}),Hm=e=>u.jsx(jF,{...e}),E2=({withHandle:e,orientation:t,disabled:n,className:r,...i})=>u.jsx(MF,{disabled:n,className:de("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:u.jsx("span",{className:"sr-only",children:t==="vertical"?"Resize rows":"Resize columns"})});function LF(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 Mxe(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 LF(r.usage,new Date(r.createdAt).toISOString(),t)}return null}function Lxe(e,t){return!e||t===null||!Number.isFinite(t)||t<=0?e:LF({...e,maxTokens:t},e.updatedAt,e.compactsAutomatically)}function Ixe(e){if(!e)return null;const t=tS(e.inputTokens),n=tS(e.outputTokens),r=tS(e.cachedInputTokens);if(t===0&&n===0&&r===0)return null;const i=t+r,s=i>0?r/i*100:null;return{input:t,output:n,cached:r,cacheHitPercentage:s}}function tS(e){return e===void 0||!Number.isFinite(e)||e<0?0:e}function Zi(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 N2=[68,32];function Dxe(){return{isVisible:!1,mainSizes:[...N2],terminals:[],nextTerminalIndex:0}}function Pxe(e,t){return e[t]??Dxe()}function nS(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 Oxe(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 zxe(e){if(e.length===0)return e;const t=e.length+1;return e.map(n=>({...n,size:n.size*e.length/t}))}function ud(e,t,n){return{...e,[t]:n(Pxe(e,t))}}const Ml=ss()(yh(e=>({projects:{},addTerminal:(t,n)=>e(r=>({projects:ud(r.projects,t,i=>{var c,d;const s=zxe(i.terminals),o={id:((d=(c=globalThis.crypto)==null?void 0:c.randomUUID)==null?void 0:d.call(c))??`terminal-${Date.now()}-${i.nextTerminalIndex}`,title:Oxe(i.nextTerminalIndex),size:100/(s.length+1)},a=n?Math.max(s.findIndex(f=>f.id===n)+1,0):s.length;return{...i,isVisible:!0,nextTerminalIndex:i.nextTerminalIndex+1,terminals:[...s.slice(0,a),o,...s.slice(a)]}})})),removeTerminal:(t,n)=>e(r=>({projects:ud(r.projects,t,i=>{const s=i.terminals.filter(a=>a.id!==n);if(s.length===0)return{...i,isVisible:!1,terminals:[]};const o=nS(s.map(a=>a.size));return{...i,terminals:s.map((a,c)=>({...a,size:o[c]??100/s.length}))}})})),toggleVisibility:t=>e(n=>({projects:ud(n.projects,t,r=>({...r,isVisible:r.terminals.length>0?!r.isVisible:!1}))})),resetMainSizes:t=>e(n=>({projects:ud(n.projects,t,r=>({...r,mainSizes:[...N2]}))})),setMainSizes:(t,n)=>e(r=>{if(n.length!==2)return r;const i=nS(n);return{projects:ud(r.projects,t,s=>({...s,mainSizes:i}))}}),setTerminalSizes:(t,n)=>e(r=>({projects:ud(r.projects,t,i=>{if(n.length!==i.terminals.length)return i;const s=nS(n);return{...i,terminals:i.terminals.map((o,a)=>({...o,size:s[a]??o.size}))}})})),clearProject:t=>e(n=>{const{[t]:r,...i}=n.projects;return{projects:i}})}),{name:"terminal-layouts",version:1})),Bxe={isVisible:!1,mainSizes:[...N2],terminals:[],nextTerminalIndex:0},Fxe=35;function $xe(e,t){return!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<=0?0:e*(t/100)}function Hxe(e,t){const n=$xe(e,t);return n>=0&&n<Fxe}const xy=350,Uxe=[.4,0,.2,1],Vxe=8,KI=1e-6;function Wxe(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function Gxe(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function qxe(e,t,n){const r=1-e;return 3*r*r*t+6*r*e*(n-t)+3*e*e*(1-n)}function Kxe(e,t,n){let r=e;for(let i=0;i<Vxe;i+=1){const s=Wxe(r,t,n)-e;if(Math.abs(s)<KI)return r;const o=qxe(r,t,n);if(Math.abs(o)<KI)break;r-=s/o}return r}function Yxe(e){if(e<=0)return 0;if(e>=1)return 1;const[t,n,r,i]=Uxe,s=Kxe(e,t,r);return Gxe(s,n,i)}function IF(e,t,n){const r=Yxe(n);return[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r]}function Xxe({projectId:e,shouldRenderRightSidebarLayout:t,showRightSidebar:n,rightSidebarSize:r}){const i=v.useRef(null),s=v.useRef(null),o=v.useRef(null),a=v.useRef(null),c=v.useRef(null),d=v.useRef(!1),f=v.useRef(null),m=v.useRef(!1),g=v.useRef(!1);return v.useEffect(()=>()=>{a.current!==null&&window.cancelAnimationFrame(a.current),c.current!==null&&window.clearTimeout(c.current)},[]),v.useLayoutEffect(()=>{var j,I,U,M,D,z;if(!t){a.current!==null&&(window.cancelAnimationFrame(a.current),a.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null),d.current=!1;return}const b=i.current;if(!b)return;a.current!==null&&(window.cancelAnimationFrame(a.current),a.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null);const y=f.current,_=y!==null&&y!==e,w=n&&!g.current,C=!m.current,E=n?[100-r,r]:[100,0],k=_||C&&n,T=w||C?[100,0]:[b.getLayout().workspace??E[0],b.getLayout().rightSidebar??E[1]];if(f.current=e,m.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]}),(j=s.current)==null||j.setAttribute("data-right-sidebar-open",n?"true":"false"),(I=o.current)==null||I.setAttribute("data-right-sidebar-open",n?"true":"false"),(U=o.current)==null||U.setAttribute("data-right-sidebar-animated","false");return}d.current=!0,(M=s.current)==null||M.setAttribute("data-right-sidebar-open",n?"true":"false"),(D=o.current)==null||D.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 R=performance.now(),A=P=>{const F=Math.min(1,(P-R)/xy),$=IF(T,E,F);if(b.setLayout({workspace:$[0],rightSidebar:$[1]}),F<1){a.current=window.requestAnimationFrame(A);return}b.setLayout({workspace:E[0],rightSidebar:E[1]}),a.current=null,c.current=window.setTimeout(()=>{d.current=!1,c.current=null},0)};a.current=window.requestAnimationFrame(A)},[e,r,t,n]),v.useEffect(()=>{t||(m.current=!1,g.current=!1)},[t]),{isAnimating:d,panelGroupRef:i,sidebarPanelRef:s,sidebarVisualRef:o}}function Qxe(e){return e.visibilityState==="visible"?e.activeChatId:null}function Zxe(e){e.socket.setFocusedChat(Qxe({activeChatId:e.activeChatId,visibilityState:e.visibilityState}))}function Jxe({socket:e,activeChatId:t}){v.useEffect(()=>{if(typeof document>"u")return;const n=()=>{Zxe({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 eye({rootRef:e,fallbackRef:t,enabled:n,canCancel:r}){v.useEffect(()=>{if(!n)return;let i=0,s=null;const o=m=>{const g=m instanceof Element?m:null,b=e.current,y=t.current;if(Rj({trigger:"pointer",activeElement:document.activeElement,pointerStartTarget:s,pointerEndTarget:g,root:b,fallback:y,hasActiveOverlay:Tj(document),hasActiveSelection:RX(window.getSelection())})!=="restore"){s=null;return}y==null||y.focus({preventScroll:!0}),s=null},a=m=>{cancelAnimationFrame(i),s=m.target instanceof Element?m.target:null},c=m=>{cancelAnimationFrame(i),i=window.requestAnimationFrame(()=>{o(m.target)})},d=()=>{s=null;const m=t.current;!m||m.disabled||m.focus({preventScroll:!0})},f=m=>{if(m.key!=="Escape")return;const g=t.current;Rj({trigger:"escape",activeElement:document.activeElement,fallback:g,hasActiveOverlay:Tj(document),canCancel:r,defaultPrevented:m.defaultPrevented})==="escape-focus"&&(m.preventDefault(),g==null||g.focus({preventScroll:!0}))};return window.addEventListener("pointerdown",a,!0),window.addEventListener("pointerup",c,!0),window.addEventListener("keydown",f,!0),window.addEventListener(Nb,d),()=>{cancelAnimationFrame(i),window.removeEventListener("pointerdown",a,!0),window.removeEventListener("pointerup",c,!0),window.removeEventListener("keydown",f,!0),window.removeEventListener(Nb,d)}},[r,n,t,e])}function tye(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 nye({previousProjectId:e,projectId:t,previousShouldRenderTerminalLayout:n,previousShowTerminalPane:r,showTerminalPane:i,terminalLayout:s,liveLayout:o}){const a=e!==null&&e!==t,c=i&&!r,d=!n,f=e===null&&t!==null,m=i?s.mainSizes:[100,0];return{currentLayout:c||d?[100,0]:o,shouldSkipAnimation:a||f&&d,targetLayout:m}}function rye({chatInputRef:e,projectId:t,shouldRenderTerminalLayout:n,showTerminalPane:r,terminalLayout:i}){const s=v.useRef(null),o=v.useRef(null),a=v.useRef(null),c=v.useRef(null),d=v.useRef(null),f=v.useRef(!1),m=v.useRef(null),g=v.useRef(!1),b=v.useRef(!1),y=v.useRef(!1),[_,w]=v.useState(0);return v.useEffect(()=>{var k;const C=m.current,E=y.current;tye({previousProjectId:C,projectId:t,showTerminalPane:r,wasTerminalVisible:E})&&w(T=>T+1),C!==null&&C===t&&!r&&E&&((k=e.current)==null||k.focus({preventScroll:!0})),y.current=r,m.current=t},[e,t,r]),v.useEffect(()=>()=>{c.current!==null&&window.cancelAnimationFrame(c.current),d.current!==null&&window.clearTimeout(d.current)},[]),v.useLayoutEffect(()=>{var I,U,M,D,z,P;if(!n){c.current!==null&&(window.cancelAnimationFrame(c.current),c.current=null),d.current!==null&&(window.clearTimeout(d.current),d.current=null),f.current=!1;return}const C=s.current;if(!C)return;c.current!==null&&(window.cancelAnimationFrame(c.current),c.current=null),d.current!==null&&(window.clearTimeout(d.current),d.current=null);const E=m.current,{currentLayout:k,shouldSkipAnimation:T,targetLayout:R}=nye({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]-R[0])<.1&&Math.abs(k[1]-R[1])<.1){C.setLayout({chat:R[0],terminal:R[1]}),(I=o.current)==null||I.setAttribute("data-terminal-open",r?"true":"false"),(U=a.current)==null||U.setAttribute("data-terminal-open",r?"true":"false"),(M=a.current)==null||M.setAttribute("data-terminal-animated","false");return}f.current=!0,(D=o.current)==null||D.setAttribute("data-terminal-open",r?"true":"false"),(z=a.current)==null||z.setAttribute("data-terminal-open",r?"true":"false"),(P=a.current)==null||P.setAttribute("data-terminal-animated","true"),C.setLayout({chat:k[0],terminal:k[1]});const A=performance.now(),j=F=>{const $=Math.min(1,(F-A)/xy),B=IF(k,R,$);if(C.setLayout({chat:B[0],terminal:B[1]}),$<1){c.current=window.requestAnimationFrame(j);return}C.setLayout({chat:R[0],terminal:R[1]}),c.current=null,d.current=window.setTimeout(()=>{f.current=!1,d.current=null},0)};c.current=window.requestAnimationFrame(j)},[t,n,r,i]),v.useEffect(()=>{n||(g.current=!1,b.current=!1)},[n]),{isAnimating:f,mainPanelGroupRef:s,terminalFocusRequestVersion:_,terminalPanelRef:o,terminalVisualRef:a}}const YI=e=>Symbol.iterator in e,XI=e=>"entries"in e,QI=(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},iye=(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 sye(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:YI(e)&&YI(t)?XI(e)&&XI(t)?QI(e,t):iye(e,t):QI({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function lx(e){const t=yn.useRef(void 0);return n=>{const r=e(n);return sye(t.current,r)?t.current:t.current=r}}const sm="__new__";function Rc(e){var s,o;const t=(s=e==null?void 0:e.modelOptions)==null?void 0:s.reasoningEffort,n=l1(t)?t:l1(e==null?void 0:e.effort)?e.effort:Yc.reasoningEffort,r=qne(e==null?void 0:e.model),i=gE(r,(o=e==null?void 0:e.modelOptions)==null?void 0:o.contextWindow);return{model:r,modelOptions:{reasoningEffort:!cz(r)&&n==="max"?"high":n,contextWindow:i},planMode:!!(e!=null&&e.planMode)}}function Nv(e){var n,r;const t=(n=e==null?void 0:e.modelOptions)==null?void 0:n.reasoningEffort;return{model:Kne(e==null?void 0:e.model),modelOptions:{reasoningEffort:c1(t)?t:c1(e==null?void 0:e.effort)?e.effort:Cm.reasoningEffort,fastMode:typeof((r=e==null?void 0:e.modelOptions)==null?void 0:r.fastMode)=="boolean"?e.modelOptions.fastMode:Cm.fastMode},planMode:!!(e!=null&&e.planMode)}}function oye(){return{claude:{model:"claude-opus-4-7",modelOptions:{...Yc},planMode:!1},codex:{model:"gpt-5.5",modelOptions:{...Cm},planMode:!1}}}function aye(e,t){return e.reasoningEffort===t.reasoningEffort&&e.contextWindow===t.contextWindow}function lye(e,t){return e.reasoningEffort===t.reasoningEffort&&e.fastMode===t.fastMode}function cye(e,t){return e.claude.model===t.claude.model&&e.claude.planMode===t.claude.planMode&&aye(e.claude.modelOptions,t.claude.modelOptions)&&e.codex.model===t.codex.model&&e.codex.planMode===t.codex.planMode&&lye(e.codex.modelOptions,t.codex.modelOptions)}function uye(e,t){if(t===void 0){console.info(`[chat-preferences] ${e}`);return}console.info(`[chat-preferences] ${e}`,t)}function om(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 aC(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 DF(e){return e.providerHint?om(e.providerHint,e.providerDefaults):e.defaultProvider==="last_used"?e.sourceState?aC(e.sourceState):om("claude",e.providerDefaults):om(e.defaultProvider,e.providerDefaults)}function PF(e,t){const n=e.chatStates[t];return n||DF({defaultProvider:e.defaultProvider,providerDefaults:e.providerDefaults,legacyComposerState:e.legacyComposerState})}function Tv(e,t,n){const r=PF(e,t);return{chatStates:{...e.chatStates,[t]:n(r)}}}const vi=ss()(yh((e,t)=>({defaultProvider:"last_used",providerDefaults:oye(),chatStates:{},legacyComposerState:{provider:"claude",model:"claude-opus-4-7",modelOptions:{...Yc},planMode:!1},setDefaultProvider:n=>e({defaultProvider:n}),applyServerDefaults:(n,r)=>e(i=>{if(i.defaultProvider===n&&cye(i.providerDefaults,r))return{defaultProvider:n,providerDefaults:r};const{[sm]:o,...a}=i.chatStates;return{defaultProvider:n,providerDefaults:r,chatStates:a}}),setProviderDefaultModel:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?Rc({...i.providerDefaults.claude,model:r}):Nv({...i.providerDefaults.codex,model:r})}})),setProviderDefaultModelOptions:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?Rc({...i.providerDefaults.claude,modelOptions:{...i.providerDefaults.claude.modelOptions,...r}}):Nv({...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=>aC(PF(t(),n)),initializeComposerForChat:(n,r)=>e(i=>{if(i.chatStates[n])return i;const s=DF({defaultProvider:i.defaultProvider,providerDefaults:i.providerDefaults,sourceState:r==null?void 0:r.sourceState,legacyComposerState:i.legacyComposerState,providerHint:r==null?void 0:r.providerHint});return uye("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:Rc(r).model,modelOptions:Rc(r).modelOptions,planMode:r.planMode}:aC(r)}})),setChatComposerProvider:(n,r)=>e(i=>Tv(i,n,()=>om(r,i.providerDefaults))),setChatComposerModel:(n,r)=>e(i=>Tv(i,n,s=>s.provider==="claude"?{provider:"claude",model:Rc({...s,model:r}).model,modelOptions:Rc({...s,model:r}).modelOptions,planMode:s.planMode}:{provider:"codex",model:r,modelOptions:Nv({...s,model:r}).modelOptions,planMode:s.planMode})),setChatComposerModelOptions:(n,r)=>e(i=>Tv(i,n,s=>s.provider==="claude"?{provider:"claude",model:s.model,modelOptions:Rc({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode}:{provider:"codex",model:s.model,modelOptions:Nv({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode})),setChatComposerPlanMode:(n,r)=>e(i=>Tv(i,n,s=>({...s,planMode:r}))),resetChatComposerFromProvider:(n,r)=>e(i=>({chatStates:{...i.chatStates,[n]:om(r,i.providerDefaults)}}))}),{name:"chat-preferences-state",version:1,partialize:e=>({chatStates:e.chatStates,legacyComposerState:e.legacyComposerState})})),lC=ss()(yh((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"})),T2=ss()(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]:a,...c}=n.loadingByChatId;return{byChatId:o,loadingByChatId:c}})}));function dye(e){return{autoResumeOnRateLimit:!!(e!=null&&e.autoResumeOnRateLimit)}}const cC=ss()(yh(e=>({autoResumeOnRateLimit:!1,setAutoResumeOnRateLimit:t=>e({autoResumeOnRateLimit:t})}),{name:"kanna-preferences",version:1,migrate:e=>dye(e)}));function dd(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function Rv(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function hye(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 rS(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 fye(e,t){var r;const n=Rv(t);switch(e.toolKind){case"ask_user_question":{const o=rS(n),a=o!==null?Rv(o):n,c=dd(a),d=dd(c==null?void 0:c.answers)??(c||{});return{answers:Object.fromEntries(Object.entries(d).map(([f,m])=>Array.isArray(m)?[f,m.map(g=>String(g))]:m&&typeof m=="object"&&Array.isArray(m.answers)?[f,m.answers.map(g=>String(g))]:m==null||m===""?[f,[]]:[f,[String(m)]])),...(c==null?void 0:c.discarded)===!0?{discarded:!0}:{}}}case"exit_plan_mode":{const o=rS(n),a=o!==null?Rv(o):n,c=dd(a);return{confirmed:typeof(c==null?void 0:c.confirmed)=="boolean"?c.confirmed:void 0,clearContext:typeof(c==null?void 0:c.clearContext)=="boolean"?c.clearContext:void 0,message:typeof(c==null?void 0:c.message)=="string"?c.message:void 0,...(c==null?void 0:c.discarded)===!0?{discarded:!0}:{}}}case"offer_download":{const o=rS(n),a=o?Rv(o):n,c=dd(a);return{contentUrl:typeof(c==null?void 0:c.contentUrl)=="string"?c.contentUrl:"",relativePath:typeof(c==null?void 0:c.relativePath)=="string"?c.relativePath:"",fileName:typeof(c==null?void 0:c.fileName)=="string"?c.fileName:"",displayName:typeof(c==null?void 0:c.displayName)=="string"?c.displayName:typeof(c==null?void 0:c.fileName)=="string"?c.fileName:"",size:typeof(c==null?void 0:c.size)=="number"?c.size:0,...typeof(c==null?void 0:c.mimeType)=="string"?{mimeType:c.mimeType}:{}}}case"image_generation":{const o=dd(n);return{contentUrl:typeof(o==null?void 0:o.contentUrl)=="string"?o.contentUrl:"",relativePath:typeof(o==null?void 0:o.relativePath)=="string"?o.relativePath:"",fileName:typeof(o==null?void 0:o.fileName)=="string"?o.fileName:""}}case"workflow":{const o=typeof t=="string"?t:"";return{taskId:(r=o.match(/Task ID:\s*(\S+)/))==null?void 0:r[1],text:o}}case"read_file":if(typeof n=="string")return n;const i=hye(n);if(i.length>0)return{content:i.flatMap(o=>o.type==="text"?[o.text]:[]).join(""),blocks:i};const s=dd(n);return{content:typeof(s==null?void 0:s.content)=="string"?s.content:JSON.stringify(n,null,2)};default:return n}}function OF(e){return new Date(e).toISOString()}function di(e){return{id:e._id,messageId:e.messageId,timestamp:OF(e.createdAt),hidden:e.hidden}}function mye(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:OF(e.createdAt)}}function pye(e){if(e.debugRaw)try{return JSON.parse(e.debugRaw).tool_use_result}catch{return}}function zF(e){const t=new Map,n=[];for(const r of e)switch(r.kind){case"user_prompt":n.push({...di(r),kind:"user_prompt",content:r.content,attachments:r.attachments??[],steered:r.steered,autoContinue:r.autoContinue});break;case"system_init":n.push({...di(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({...di(r),kind:"account_info",accountInfo:r.accountInfo});break;case"assistant_text":n.push({...di(r),kind:"assistant_text",text:r.text});break;case"api_error":n.push({...di(r),kind:"api_error",status:r.status,text:r.text,requestId:r.requestId});break;case"tool_call":{const i=mye(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"?pye(r)??r.content:r.content;i.hydrated.result=fye(i.normalized,s),i.hydrated.rawResult=s,i.hydrated.isError=r.isError,r.persisted&&(i.hydrated.persisted=r.persisted)}break}case"result":n.push({...di(r),kind:"result",success:!r.isError,cancelled:r.subtype==="cancelled",result:r.result,durationMs:r.durationMs,costUsd:r.costUsd});break;case"status":n.push({...di(r),kind:"status",status:r.status});break;case"context_window_updated":n.push({...di(r),kind:"context_window_updated",usage:r.usage});break;case"compact_boundary":n.push({...di(r),kind:"compact_boundary"});break;case"compact_summary":n.push({...di(r),kind:"compact_summary",summary:r.summary});break;case"context_cleared":n.push({...di(r),kind:"context_cleared"});break;case"interrupted":n.push({...di(r),kind:"interrupted"});break;case"auto_continue_prompt":n.push({...di(r),kind:"auto_continue_prompt",scheduleId:r.scheduleId});break;case"pending_tool_request":n.push({...di(r),kind:"pending_tool_request",toolRequestId:r.toolRequestId,toolName:r.toolName,arguments:r.arguments});break;case"tool_request_resolved":break;default:n.push({...di(r),kind:"unknown",json:JSON.stringify(r,null,2)});break}return n}const gye=["AskUserQuestion","ExitPlanMode","TodoWrite"],vye=new Set(["TodoWrite"]);function bye(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 xye(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 yye(e){const t={};for(const n of gye)t[n]=vye.has(n)?xye(e,n):bye(e,n);return t}function _ye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}function wye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}const R2="pushDeviceId";function BF(){return typeof localStorage>"u"?null:localStorage.getItem(R2)}function Sye(e){typeof localStorage>"u"||localStorage.setItem(R2,e)}function Cye(){typeof localStorage>"u"||localStorage.removeItem(R2)}function kye(){return!(typeof window>"u"||typeof Notification>"u"||!("serviceWorker"in navigator)||typeof globalThis.PushManager>"u")}function Eye(){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 uC(){if(!kye())return{state:"unsupported"};if(!Eye())return{state:"insecure-context"};switch(Notification.permission){case"granted":return{state:"granted"};case"denied":return{state:"denied"};default:return{state:"default"}}}function Nye(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 Tye(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 Rye(e){const t=uC();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:Nye(e.vapidPublicKey)}),s=i.toJSON(),o=s.endpoint??i.endpoint,a=s.keys??{};if(!o||!a.p256dh||!a.auth)throw new Error("Subscription returned without endpoint or keys");const c=navigator.userAgent??"",{id:d}=await e.sendToServer({subscription:{endpoint:o,keys:{p256dh:a.p256dh,auth:a.auth}},label:Tye(c),userAgent:c});return d}async function Aye(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 jye=25e3,Mye=15e3,Lye=4e3,ZI="kanna:profile-send-to-starting";function JI(){try{return window.sessionStorage.getItem(ZI)==="1"||window.localStorage.getItem(ZI)==="1"}catch{return!1}}class Iye{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=Ic();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=Ic(),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=Ic(),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=Ic();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=BF();t&&this.sendNow({v:1,type:"command",id:Ic(),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(JI()&&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}),JI()&&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 a=this.subscriptions.get(i.id);a==null||a.listener(i.snapshot.data);return}if(i.type==="event"){const a=this.subscriptions.get(i.id);(o=a==null?void 0:a.eventListener)==null||o.call(a,i.event);return}if(i.type==="ack"){const a=this.pending.get(i.id);if(!a)return;this.pending.delete(i.id),a.resolve(i.result);return}if(i.type==="error"){if(!i.id){console.error(jZ,i.message);return}const a=this.pending.get(i.id);if(!a)return;this.pending.delete(i.id),a.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>=jye}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()},Lye),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()},Mye))}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))}}const Dye=[],A2=ss()(e=>({byChat:{},setRuns:(t,n)=>e(r=>({byChat:{...r.byChat,[t]:n}}))}));function FF(e){return t=>t.byChat[e]??Dye}function Pye(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 Oye(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&&Pye(e.sessionTokensByProvider,t.sessionTokensByProvider)}function zye(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 Bye(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 Fye(e,t){return e===t?!0:!e||!t?!1:e.hasOlder===t.hasOlder&&e.olderCursor===t.olderCursor&&e.recentLimit===t.recentLimit}function $ye(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)&&Hye(e.attachments,t.attachments)}function Hye(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 Uye(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>$ye(n,t[r]))}function Vye(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((a,c)=>{const d=r[c];return!!d&&a.sha===d.sha&&a.summary===d.summary&&a.description===d.description&&a.authorName===d.authorName&&a.authoredAt===d.authoredAt&&a.githubUrl===d.githubUrl&&a.tags.length===d.tags.length&&a.tags.every((f,m)=>f===d.tags[m])})||e.files.length!==t.files.length?!1:e.files.every((a,c)=>{const d=t.files[c];return!!d&&a.path===d.path&&a.changeType===d.changeType&&a.isUntracked===d.isUntracked&&a.additions===d.additions&&a.deletions===d.deletions&&a.patchDigest===d.patchDigest&&a.mimeType===d.mimeType&&a.size===d.size})}function Wye(e,t){return!!(e&&e.status!=="unknown"&&t&&t.status==="unknown"&&t.files.length===0)}function Gye(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 qye(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 Kye(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=>{var a,c,d,f,m,g;const s=e[i],o=t[i];return!s||!o?!1:s.status===o.status&&s.entries.length===o.entries.length&&(s.finalText??"")===(o.finalText??"")&&(((a=s.pendingTool)==null?void 0:a.toolUseId)??null)===(((c=o.pendingTool)==null?void 0:c.toolUseId)??null)&&(((d=s.usage)==null?void 0:d.outputTokens)??null)===(((f=o.usage)==null?void 0:f.outputTokens)??null)&&s.finishedAt===o.finishedAt&&(((m=s.error)==null?void 0:m.code)??null)===(((g=o.error)==null?void 0:g.code)??null)})}function Yye(e,t){return e===t?!0:!e||!t?!1:Oye(e.runtime,t.runtime)&&Uye(e.queuedMessages,t.queuedMessages)&&zye(e.messages,t.messages)&&Fye(e.history,t.history)&&Bye(e.availableProviders,t.availableProviders)&&Gye(e.schedules,t.schedules)&&e.liveScheduleId===t.liveScheduleId&&qye(e.tunnels,t.tunnels)&&e.liveTunnelId===t.liveTunnelId&&Kye(e.subagentRuns,t.subagentRuns)}function eD(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 Xye(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 tD="__new_chat__",$F="lever-theme",HF="chat-sound-preferences",UF="terminal-preferences",VF="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 Qye(){if(typeof window>"u")return null;const e={},t=window.localStorage.getItem($F);(t==="light"||t==="dark"||t==="system")&&(e.theme=t);const n=iS(HF);((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(UF);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(VF);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 Zye(){typeof window>"u"||(window.localStorage.removeItem($F),window.localStorage.removeItem(HF),window.localStorage.removeItem(UF),window.localStorage.removeItem(VF))}function Rf(e){Di.getState().setFromServer(e);const t=mi.getState();t.setScrollbackLines(e.terminal.scrollbackLines),t.setMinColumnWidth(e.terminal.minColumnWidth),t.setEditorPreset(e.editor.preset),t.setEditorCommandTemplate(e.editor.commandTemplate);const n=Oc.getState();n.setChatSoundPreference(e.chatSoundPreference),n.setChatSoundId(e.chatSoundId),vi.getState().applyServerDefaults(e.defaultProvider,e.providerDefaults)}function Jye(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 j2(e,t=[]){return JSON.stringify({content:e,attachments:t.map(Jye)})}function e0e(e,t){return e.reduce((n,r)=>r.kind!=="user_prompt"?n:n+(j2(r.content,r.attachments??[])===t?1:0),0)}function t0e(e,t,n){const r=new Map;for(const i of n){if(i.kind!=="user_prompt")continue;const s=j2(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)}function n0e(e,t,n){return e.some(r=>r.id===t)?e.filter(r=>r.id!==t):e}const r0e=200,i0e=500;function nD(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 rD(e,t){if(!(t!=null&&t.length)||e.length<=1)return e;const n=new Map(e.map((o,a)=>[o.groupKey,a])),r=new Set,i=t.map(o=>{if(r.has(o))return null;r.add(o);const a=n.get(o);return a===void 0?null:e[a]}).filter(o=>!!o);if(i.length===0)return e;const s=[...i,...e.filter(o=>!r.has(o.groupKey))];return s.every((o,a)=>o===e[a])?e:s}function s0e(e=document){return e.visibilityState==="visible"&&e.hasFocus()}function o0e(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`}function a0e(){const[e]=v.useState(()=>new Iye(o0e()));return v.useEffect(()=>(e.start(),()=>{e.dispose()}),[e]),e}const iD="kanna:profile-send-to-starting";function l0e(){try{return window.sessionStorage.getItem(iD)==="1"||window.localStorage.getItem(iD)==="1"}catch{return!1}}function WF(e){return Number((performance.now()-e).toFixed(1))}function kl(e,t,n){!e||!l0e()||console.debug("[kanna/send->starting][client]",{traceId:e.traceId,stage:t,elapsedMs:WF(e.startedAt),serverChatId:e.serverChatId,routeChatIdAtSend:e.routeChatIdAtSend,...n})}function c0e(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 u0e(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 d0e(e,t){return e==="awaiting_disconnect"&&t==="disconnected"?"awaiting_server_ready":"none"}function h0e(e,t){return t==="updating"||t==="restart_pending"?{active:!0,label:"Installing update"}:e==="awaiting_disconnect"||e==="awaiting_server_ready"?{active:!0,label:"Re-deploying Kanna"}:{active:!1,label:""}}const f0e=30,M2="kanna:ui-update-restart",GF="kanna:last-update-reload-request";function m0e(e){return e+f0e}function p0e(e,t){return t>0?t:e}function sS(){return window.sessionStorage.getItem(M2)}function g0e(e){window.sessionStorage.setItem(M2,e)}function v0e(){window.sessionStorage.removeItem(M2)}function b0e(e,t){return e?String(e)!==t:!1}function x0e(){return window.sessionStorage.getItem(GF)}function y0e(e){window.sessionStorage.setItem(GF,String(e))}function _0e(){return"/auth/status"}async function w0e(e=fetch){return(await e(_0e(),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}})).ok}function S0e(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 C0e(e,t){return!e||!t?null:e.runtime.chatId!==t?(e.runtime.chatId,e.runtime.provider,null):e}function k0e(e){var wu,lc,Ah;const t=lu(),n=a0e(),r=op(),[i,s]=v.useState({starredProjectGroups:[],projectGroups:[],stacks:[]}),[o,a]=v.useState(null),[c,d]=v.useState(null),[f,m]=v.useState(null),[g,b]=v.useState(()=>sS()),y=v.useCallback(Q=>{g0e(Q),b(Q)},[]),_=v.useCallback(()=>{v0e(),b(null)},[]),[w,C]=v.useState(null),[E,k]=v.useState([]),[T,R]=v.useState(!1),[A,j]=v.useState(null),[I,U]=v.useState(!1),[M,D]=v.useState({}),[z,P]=v.useState(null),[F,$]=v.useState(null),[B,H]=v.useState(null),[W,te]=v.useState(null),[O,K]=v.useState("connecting"),[ee,V]=v.useState(!1),[ue,ge]=v.useState(!1),[Z,ne]=v.useState(!1),[ie,le]=v.useState(null),[oe,we]=v.useState(!1),[Ce,Oe]=v.useState(!1),[Ze,ft]=v.useState(!1),[Tt,_e]=v.useState(null),[cn,Lt]=v.useState(null),[pt,xt]=v.useState(null),[Bt,Dt]=v.useState([]),[lt,Ot]=v.useState(null),[me,Te]=v.useState(0),He=v.useRef(new Map),tt=lC(lx(Q=>Object.keys(Q.drafts).sort())),Xe=lC(lx(Q=>Object.keys(Q.attachmentDrafts).sort())),yt=v.useRef(0),ze=v.useRef(null),Ke=v.useRef({projectId:null,diffs:null}),Be=bre(mi(Q=>Q.editorPreset)),Ie=v.useMemo(()=>rD(i.projectGroups,o),[o,i.projectGroups]),qe=v.useRef(Ie);v.useLayoutEffect(()=>{qe.current=Ie});const It=v.useMemo(()=>Ie===i.projectGroups?i:{...i,projectGroups:Ie},[i,Ie]);v.useEffect(()=>n.onStatus(K),[n]),v.useEffect(()=>n.subscribe({type:"sidebar"},Q=>{s(Q),a(J=>J&&rD(Q.projectGroups,J)===Q.projectGroups?null:J),V(!0),_e(null)}),[n]),v.useEffect(()=>{if(O!=="connected")return;const Q=[...new Set([...tt,...Xe])].sort();n.command({type:"chat.setDraftProtection",chatIds:Q}).catch(J=>{_e(J instanceof Error?J.message:String(J))})},[Xe,O,tt,n]),v.useEffect(()=>n.subscribe({type:"local-projects"},Q=>{d(Q),ge(!0),_e(null)}),[n]),v.useEffect(()=>n.subscribe({type:"update"},Q=>{m(Q),_e(null)}),[n]),v.useEffect(()=>{O==="connected"&&n.command({type:"update.check",force:!0}).catch(Q=>{_e(Q instanceof Error?Q.message:String(Q))})},[O,n]),v.useEffect(()=>{const Q=f==null?void 0:f.reloadRequestedAt;b0e(Q,x0e())&&Q&&(y0e(Q),y("awaiting_disconnect"))},[y,f==null?void 0:f.reloadRequestedAt]),v.useEffect(()=>{const Q=sS();if(d0e(Q,O)==="awaiting_server_ready"){y("awaiting_server_ready");return}},[O,y]),v.useEffect(()=>{if(sS()!=="awaiting_server_ready")return;let Q=!1,J=null;const Me=async()=>{try{if(await w0e()){if(Q)return;_(),window.location.reload();return}}catch{}Q||(J=window.setTimeout(()=>{Me()},500))};return Me(),()=>{Q=!0,J!==null&&window.clearTimeout(J)}},[O,_]),v.useEffect(()=>{function Q(){f!=null&&f.lastCheckedAt&&(Date.now()-f.lastCheckedAt<=3600*1e3||n.command({type:"update.check"}).catch(J=>{_e(J instanceof Error?J.message:String(J))}))}return window.addEventListener("focus",Q),()=>{window.removeEventListener("focus",Q)}},[n,f==null?void 0:f.lastCheckedAt]),v.useEffect(()=>n.subscribe({type:"keybindings"},Q=>{P(Q),_e(null)}),[n]),v.useEffect(()=>n.subscribe({type:"app-settings"},Q=>{$(Q),Rf(Q),_e(null)}),[n]),v.useEffect(()=>n.subscribe({type:"push-config"},Q=>{H(Q)}),[n]),v.useEffect(()=>n.subscribe({type:"pty-instances"},Q=>{Na.getState().applySnapshot(Q.instances)},Q=>{Q.type==="pty-instances.added"?Na.getState().applyDiff({op:"added",instance:Q.instance}):Q.type==="pty-instances.updated"?Na.getState().applyDiff({op:"updated",instance:Q.instance}):Na.getState().applyDiff({op:"removed",chatId:Q.chatId})}),[n]);const Rt=v.useCallback(async()=>{try{Di.getState().setHydrationStatus("loading");const Q=await n.command({type:"settings.readAppSettings"});$(Q),Rf(Q),_e(null)}catch(Q){Di.getState().setHydrationStatus("error"),_e(Q instanceof Error?Q.message:String(Q))}},[n]),xn=v.useCallback(async(Q,J)=>{try{await n.command({type:"chat.setPolicyOverride",chatId:Q,policyOverride:J}),_e(null)}catch(Me){throw _e(Me instanceof Error?Me.message:String(Me)),Me}},[n]),on=v.useCallback(async Q=>{try{Di.getState().applyOptimisticPatch(Q);const J=await n.command({type:"settings.writeAppSettingsPatch",patch:Q});$(J),Rf(J),_e(null)}catch(J){throw _e(J instanceof Error?J.message:String(J)),await Rt(),J}},[Rt,n]),Zt=v.useCallback(async Q=>{try{await n.command({type:"settings.testMcpServer",id:Q}),_e(null)}catch(J){throw _e(J instanceof Error?J.message:String(J)),J}},[n]),At=v.useCallback(async Q=>{try{Di.getState().applyOptimisticPatch({cloudflareTunnel:Q});const J=await n.command({type:"appSettings.setCloudflareTunnel",patch:Q});$(J),Rf(J),_e(null)}catch(J){throw _e(J instanceof Error?J.message:String(J)),await Rt(),J}},[Rt,n]),_t=v.useCallback(async Q=>{try{Di.getState().applyOptimisticPatch({claudeAuth:Q});const J=await n.command({type:"appSettings.setClaudeAuth",patch:Q});$(J),Rf(J),_e(null)}catch(J){throw _e(J instanceof Error?J.message:String(J)),await Rt(),J}},[Rt,n]),gt=v.useCallback(async Q=>await n.command({type:"appSettings.testOAuthToken",token:Q}),[n]),Ct=v.useCallback(async()=>{try{const Q=await n.command({type:"settings.readLlmProvider"});te(Q),_e(null)}catch(Q){_e(Q instanceof Error?Q.message:String(Q))}},[n]),vt=v.useCallback(async Q=>{try{const J=await n.command({type:"settings.writeLlmProvider",provider:Q.provider,apiKey:Q.apiKey,model:Q.model,baseUrl:Q.baseUrl});te(J),_e(null)}catch(J){throw _e(J instanceof Error?J.message:String(J)),J}},[n]),Ut=v.useCallback(async Q=>await n.command({type:"settings.validateLlmProvider",provider:Q.provider,apiKey:Q.apiKey,model:Q.model,baseUrl:Q.baseUrl}),[n]);v.useEffect(()=>{O==="connected"&&Rt()},[O,Rt]),v.useEffect(()=>{if(O!=="connected"||(F==null?void 0:F.browserSettingsMigrated)!==!1)return;const Q=Qye();Q&&on(Q).then(Zye).catch(()=>{})},[F==null?void 0:F.browserSettingsMigrated,O,on]),v.useEffect(()=>{O==="connected"&&Ct()},[O,Ct]),v.useEffect(()=>{function Q(){Te(J=>J+1)}return window.addEventListener("focus",Q),document.addEventListener("visibilitychange",Q),()=>{window.removeEventListener("focus",Q),document.removeEventListener("visibilitychange",Q)}},[]),v.useEffect(()=>{if(!e){C(null),ne(!0);return}++yt.current,qe.current.length,qe.current.reduce((J,Me)=>J+Me.chats.length,0),C(null),ne(!1);const Q=n.subscribe({type:"chat",chatId:e,recentLimit:r0e},J=>{if(J!=null&&J.runtime.chatId){const Me=[...He.current.values()].filter(at=>at.serverChatId===J.runtime.chatId).sort((at,Mn)=>Mn.startedAt-at.startedAt)[0];Me&&Me.snapshotAt===void 0&&(Me.snapshotAt=performance.now(),kl(Me,"chat_snapshot_received",{status:J.runtime.status,messageCount:J.messages.length}))}if(C(Me=>{const at=Yye(Me,J);return J==null||J.runtime.chatId,J==null||J.runtime.provider,J==null||J.runtime.status,J==null||J.messages.length,at?Me:J}),j((J==null?void 0:J.history.olderCursor)??null),U((J==null?void 0:J.history.hasOlder)??!1),ne(!0),_e(null),J){const Me=T2.getState();Me.setForChat(J.runtime.chatId,J.slashCommands??[]),Me.setLoadingForChat(J.runtime.chatId,J.slashCommandsLoading??!1)}});return()=>{qe.current.length,qe.current.reduce((J,Me)=>J+Me.chats.length,0),Q()}},[e,n]),v.useEffect(()=>{if(e)return n.subscribe({type:"workflows",chatId:e},Q=>{A2.getState().setRuns(Q.chatId,Q.runs)})},[e,n]),v.useEffect(()=>{if(ie)return;const Q=Ie[0];Q&&le(Q.groupKey)},[ie,Ie]),v.useEffect(()=>{if(!e||!ee||!Z)return;if(Ie.some(J=>J.chats.some(Me=>Me.chatId===e))){pt===e&&xt(null);return}pt!==e&&t("/")},[e,Z,t,pt,Ie,ee]),v.useEffect(()=>{w&&(le(w.runtime.projectId),pt===w.runtime.chatId&&xt(null))},[w,pt]),v.useEffect(()=>{if(!e||!ee||!s0e())return;const Q=Ie.flatMap(J=>J.chats).find(J=>J.chatId===e);Q!=null&&Q.unread&&n.command({type:"chat.markRead",chatId:e}).catch(J=>{_e(J instanceof Error?J.message:String(J))})},[e,me,Ie,ee,n]),v.useEffect(()=>{k([]),R(!1),j(null),U(!1)},[e]);const it=v.useMemo(()=>C0e(w,e),[e,w]),ye=v.useMemo(()=>(it==null?void 0:it.runtime.projectId)??u0e(Ie,e)??ie,[e,it==null?void 0:it.runtime.projectId,ie,Ie]),rt=v.useMemo(()=>{const Q=ye?M[ye]??null:null;return ye&&Q?(Ke.current={projectId:ye,diffs:Q},Q):ye&&Ke.current.projectId===ye?Ke.current.diffs:Q},[ye,M]);v.useEffect(()=>ye?n.subscribe({type:"project-git",projectId:ye},J=>{D(Me=>{const at=J??null;return Wye(Me[ye]??null,at)||Vye(Me[ye]??null,at)?Me:{...Me,[ye]:at}}),_e(null)}):void 0,[ye,n]),v.useEffect(()=>{w==null||w.runtime.chatId,w==null||w.runtime.provider,it==null||it.runtime.chatId,it==null||it.runtime.provider},[e,it,w,pt]);const Ye=v.useMemo(()=>eD(E,(it==null?void 0:it.messages)??[]),[it==null?void 0:it.messages,E]),Je=e??tD,xe=v.useMemo(()=>Bt.filter(Q=>Q.scopeId===Je).map(Q=>Q.entry),[Je,Bt]),Pe=v.useMemo(()=>[...Ye,...xe],[xe,Ye]),Ue=v.useMemo(()=>zF(Pe),[Pe]),Ve=v.useMemo(()=>Xye(Ue),[Ue]),Wt=v.useMemo(()=>yye(Ue),[Ue]),Fe=(it==null?void 0:it.runtime)??null,Vt=(it==null?void 0:it.queuedMessages)??[],wn=((lt==null?void 0:lt.scopeId)===Je&&(!Fe||Fe.status==="idle")?"starting":null)??(Fe==null?void 0:Fe.status)??null,Er=(it==null?void 0:it.availableProviders)??Qf,En=wye(wn??void 0),$n=_ye(wn??void 0),Nr=(Fe==null?void 0:Fe.isDraining)??!1,G=((wu=c==null?void 0:c.projects[0])==null?void 0:wu.localPath)??null,be=(Fe==null?void 0:Fe.localPath)??G??((lc=Ie[0])==null?void 0:lc.localPath),Ae=!!(ie??(Fe==null?void 0:Fe.projectId)??((Ah=Ie[0])==null?void 0:Ah.groupKey)??G);v.useEffect(()=>{(lt==null?void 0:lt.scopeId)===Je&&Fe!=null&&Fe.status&&Fe.status!=="idle"&&Ot(null)},[lt,Je,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!(lt!=null&&lt.ackedAt)||lt.scopeId!==Je||Fe!=null&&Fe.status&&Fe.status!=="idle")return;const Q=window.setTimeout(()=>{Ot(J=>(J==null?void 0:J.scopeId)===Je&&J.ackedAt===lt.ackedAt?null:J)},300);return()=>window.clearTimeout(Q)},[lt,Je,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting")return;const Q=[...He.current.values()].filter(J=>J.serverChatId===e).sort((J,Me)=>Me.startedAt-J.startedAt)[0];!Q||Q.startingStatusAt!==void 0||(Q.startingStatusAt=performance.now(),kl(Q,"runtime_status_starting",{status:Fe.status}))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||!Fe||Fe.status==="starting")return;const Q=[...He.current.values()].filter(J=>J.serverChatId===e).sort((J,Me)=>Me.startedAt-J.startedAt)[0];!Q||Q.startingRenderedAt!==void 0||(kl(Q,"starting_not_observed",{status:Fe.status}),He.current.delete(Q.traceId))},[e,Fe]),v.useLayoutEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting"){ze.current=null;return}const Q=[...He.current.values()].filter(J=>J.serverChatId===e).sort((J,Me)=>Me.startedAt-J.startedAt)[0];Q&&ze.current!==Q.traceId&&(ze.current=Q.traceId,Q.startingRenderedAt=performance.now(),kl(Q,"starting_render_committed",{totalMs:WF(Q.startedAt)}),He.current.delete(Q.traceId))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{Dt(Q=>{const J=t0e(Q,Je,Ye);return J.length===Q.length&&J.every((Me,at)=>Me===Q[at])?Q:J})},[Je,Ye]);const et=v.useCallback(async()=>{if(!(!e||!A||T||!I)){R(!0);try{const Q=await n.command({type:"chat.loadHistory",chatId:e,beforeCursor:A,limit:i0e});k(J=>eD(Q.messages,J)),j(Q.olderCursor),U(Q.hasOlder),_e(null)}catch(Q){const J=Q instanceof Error?Q.message:String(Q);_e(J)}finally{R(!1)}}},[e,I,A,T,n]),ht=v.useCallback(async Q=>{const J=vi.getState(),Me=e?J.getComposerState(e):J.getComposerState(sm),at=await n.command({type:"chat.create",projectId:Q});J.initializeComposerForChat(at.chatId,{sourceState:Me}),le(Q),xt(at.chatId),t(`/chat/${at.chatId}`),we(!1),_e(null)},[e,t,n]),Qe=v.useCallback(async Q=>Q.kind==="project_id"?{projectId:Q.projectId}:Q.kind==="local_path"?{projectId:(await n.command({type:"project.open",localPath:Q.localPath})).projectId,localPath:Q.localPath}:{projectId:(await n.command(Q.project.mode==="new"?{type:"project.create",localPath:Q.project.localPath,title:Q.project.title}:{type:"project.open",localPath:Q.project.localPath})).projectId,localPath:Q.project.localPath},[n]),ot=v.useCallback(async Q=>{try{const J=Q.kind==="project_id"?null:Q.kind==="local_path"?Q.localPath:Q.project.localPath;J&&Lt(J);const{projectId:Me}=await Qe(Q);await ht(Me)}catch(J){_e(J instanceof Error?J.message:String(J))}finally{Lt(null)}},[ht,Qe]),un=v.useCallback(async Q=>{await ot({kind:"project_id",projectId:Q})},[ot]),qn=v.useCallback(async Q=>{try{const J=await n.command({type:"chat.fork",chatId:Q.chatId}),Me=vi.getState();Me.initializeComposerForChat(J.chatId,{sourceState:Me.getComposerState(Q.chatId)}),xt(J.chatId),t(`/chat/${J.chatId}`),we(!1),_e(null)}catch(J){_e(J instanceof Error?J.message:String(J))}},[t,n]),lr=v.useCallback(async Q=>{await ot({kind:"local_path",localPath:Q})},[ot]),Kr=v.useCallback(async Q=>{await ot({kind:"project_request",project:Q})},[ot]),os=v.useCallback(async Q=>{try{await n.command({type:"update.check",force:Q==null?void 0:Q.force}),_e(null)}catch(J){_e(J instanceof Error?J.message:String(J))}},[n]),ci=v.useCallback(async Q=>{y("awaiting_disconnect");try{const J=await n.command({type:"update.install",version:Q});if(!J.ok){_(),_e(null),await r.alert({title:J.userTitle??"Update failed",description:J.userMessage??"Kanna could not install the update. Try again later.",closeLabel:"OK"});return}if(J.ok&&J.action==="reload"){window.location.reload();return}_e(null)}catch(J){_(),_e(J instanceof Error?J.message:String(J))}},[_,r,y,n]),fo=v.useCallback(async()=>{y("awaiting_disconnect");try{const Q=await n.command({type:"update.reload"});if(!Q.ok){_(),_e(null),await r.alert({title:Q.userTitle??"Re-deploy failed",description:Q.userMessage??"Kanna could not re-deploy. Try again later.",closeLabel:"OK"});return}if(Q.action==="reload"){window.location.reload();return}_e(null)}catch(Q){_(),_e(Q instanceof Error?Q.message:String(Q))}},[_,r,y,n]),Si=v.useCallback(async()=>{try{const Q=await fetch("/auth/logout",{method:"POST",headers:{Accept:"application/json"}});if(!Q.ok)throw new Error(`Sign out failed with status ${Q.status}`);_e(null),window.location.reload()}catch(Q){_e(Q instanceof Error?Q.message:String(Q))}},[]),kt=v.useCallback(async(Q,J)=>{var Su;const Me=(J==null?void 0:J.attachments)??[],at=Ic(),Mn=Ic(),Xr=j2(Q,Me),Bs=e??tD;Ot({scopeId:Bs,ackedAt:null});const Fs={traceId:Mn,optimisticId:at,startedAt:performance.now(),serverChatId:e,routeChatIdAtSend:e,contentPreview:Q.slice(0,80)};He.current.set(Mn,Fs),kl(Fs,"handle_send_called",{optimisticScopeId:Bs,attachments:Me.length,contentLength:Q.length,contentPreview:Fs.contentPreview});const jh=e0e(Ye,Xr)+Bt.filter(Hn=>Hn.scopeId===Bs&&Hn.signature===Xr).length+1;Dt(Hn=>[...Hn,{id:at,scopeId:Bs,signature:Xr,requiredMatchCount:jh,entry:{_id:`optimistic:${at}`,kind:"user_prompt",content:Q,attachments:Me,createdAt:Date.now()}}]),kl(Fs,"optimistic_prompt_added",{optimisticId:at,optimisticScopeId:Bs});try{let Hn=ie??((Su=Ie[0])==null?void 0:Su.groupKey)??null;if(!e&&!Hn&&G&&(Hn=(await n.command({type:"project.open",localPath:G})).projectId,le(Hn)),!e&&!Hn)throw new Error("Open a project first");const Za=cC.getState().autoResumeOnRateLimit,Qr=await n.command({type:"chat.send",chatId:e??void 0,projectId:e?void 0:Hn??void 0,clientTraceId:Mn,provider:J==null?void 0:J.provider,content:Q,attachments:Me,model:J==null?void 0:J.model,modelOptions:J==null?void 0:J.modelOptions,planMode:J==null?void 0:J.planMode,autoResumeOnRateLimit:Za});if(Fs.ackAt=performance.now(),Fs.serverChatId=Qr.chatId??Fs.serverChatId,Qr.queued?(Dt($s=>n0e($s,at,{queued:!0})),Ot(null)):Ot($s=>$s&&{scopeId:!e&&Qr.chatId?Qr.chatId:$s.scopeId,ackedAt:performance.now()}),kl(Fs,"chat_send_ack_received",{resultChatId:Qr.chatId??null,queued:Qr.queued??!1}),!e&&Qr.chatId){Dt(Lp=>Lp.map(Mh=>Mh.id===at?{...Mh,scopeId:Qr.chatId}:Mh));const $s=vi.getState();$s.setComposerState(Qr.chatId,c0e(J)??$s.getComposerState(sm)),xt(Qr.chatId),t(`/chat/${Qr.chatId}`)}_e(null)}catch(Hn){throw Dt(Za=>Za.filter(Qr=>Qr.id!==at)),Ot(null),kl(Fs,"handle_send_failed",{error:Hn instanceof Error?Hn.message:String(Hn)}),He.current.delete(Mn),_e(Hn instanceof Error?Hn.message:String(Hn)),Hn}},[e,G,t,Bt,ie,Ye,Ie,n]),Qt=v.useCallback(async Q=>{if(e)try{await n.command({type:"message.steer",chatId:e,queuedMessageId:Q}),_e(null)}catch(J){_e(J instanceof Error?J.message:String(J))}},[e,n]),Sn=v.useCallback(async Q=>{if(e)try{await n.command({type:"message.dequeue",chatId:e,queuedMessageId:Q}),_e(null)}catch(J){_e(J instanceof Error?J.message:String(J))}},[e,n]),pn=v.useCallback(async()=>{if(e)try{await n.command({type:"chat.cancel",chatId:e})}catch(Q){_e(Q instanceof Error?Q.message:String(Q))}},[e,n]),Yr=v.useCallback(async()=>{if(e)try{await n.command({type:"chat.stopDraining",chatId:e})}catch(Q){_e(Q instanceof Error?Q.message:String(Q))}},[e,n]),Ya=v.useCallback(async Q=>{const J=await r.prompt({title:"Rename Chat",initialValue:Q.title,confirmLabel:"Rename"});if(!(!J||J===Q.title))try{await n.command({type:"chat.rename",chatId:Q.chatId,title:J}),_e(null)}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[r,n]),mo=v.useCallback(async Q=>{if(await r.confirm({title:"Delete Chat",description:`Delete "${Q.title}"? This cannot be undone.`,confirmLabel:"Delete",confirmVariant:"destructive"}))try{if(await n.command({type:"chat.delete",chatId:Q.chatId}),Q.chatId===e){const Me=nD(Ie,Q.chatId);t(Me?`/chat/${Me}`:"/")}}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[e,r,t,Ie,n]),Ko=v.useCallback(async Q=>{try{if(await n.command({type:"chat.archive",chatId:Q.chatId}),Q.chatId===e){const J=nD(Ie,Q.chatId);t(J?`/chat/${J}`:"/")}_e(null)}catch(J){_e(J instanceof Error?J.message:String(J))}},[e,t,Ie,n]),Ps=v.useCallback(async Q=>{try{xt(Q),await n.command({type:"chat.unarchive",chatId:Q}),t(`/chat/${Q}`),_e(null)}catch(J){xt(null),_e(J instanceof Error?J.message:String(J))}},[t,n]),Xa=v.useCallback(async Q=>{try{await n.command({type:"project.remove",projectId:Q}),Ml.getState().clearProject(Q),Li.getState().clearProject(Q),(Fe==null?void 0:Fe.projectId)===Q&&t("/"),_e(null)}catch(J){_e(J instanceof Error?J.message:String(J))}},[t,Fe,n]),nr=v.useCallback(async(Q,J)=>{try{await n.command({type:"project.setStar",projectId:Q,starred:J}),_e(null)}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[n]),po=v.useCallback(async Q=>{a(Q);try{await n.command({type:"sidebar.reorderProjectGroups",projectIds:Q}),_e(null)}catch(J){a(null),_e(J instanceof Error?J.message:String(J))}},[n]),go=v.useCallback(async(Q,J)=>{try{await n.command({type:"stack.create",title:Q,projectIds:J}),_e(null)}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[n]),vo=v.useCallback(async(Q,J)=>{try{await n.command({type:"stack.rename",stackId:Q,title:J}),_e(null)}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[n]),Ci=v.useCallback(async Q=>{try{await n.command({type:"stack.remove",stackId:Q}),_e(null)}catch(J){_e(J instanceof Error?J.message:String(J))}},[n]),Yo=v.useCallback(async(Q,J)=>{try{await n.command({type:"stack.addProject",stackId:Q,projectId:J}),_e(null)}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[n]),Xo=v.useCallback(async(Q,J)=>{try{await n.command({type:"stack.removeProject",stackId:Q,projectId:J}),_e(null)}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[n]),ki=v.useCallback(async(Q,J,Me)=>{try{const at=vi.getState(),Mn=e?at.getComposerState(e):at.getComposerState(sm),Xr=await n.command({type:"chat.create",projectId:Q,stackId:J,stackBindings:Me});at.initializeComposerForChat(Xr.chatId,{sourceState:Mn}),le(Q),xt(Xr.chatId),t(`/chat/${Xr.chatId}`),we(!1),_e(null)}catch(at){_e(at instanceof Error?at.message:String(at))}},[e,t,n]),Ee=v.useCallback(async Q=>{try{const J=await n.command({type:"stack.listWorktrees",projectId:Q});return _e(null),J.worktrees}catch(J){return _e(J instanceof Error?J.message:String(J)),[]}},[n]),Ge=v.useCallback(async()=>await n.command({type:"sessions.importClaude"}),[n]),jt=v.useCallback(async Q=>{const J=mi.getState();_e(null),await n.command({type:"system.openExternal",...Q,editor:Q.action==="open_editor"?Q.editor??{preset:J.editorPreset,commandTemplate:J.editorCommandTemplate}:void 0})},[n]),X=v.useCallback(async(Q,J)=>{var at,Mn;const Me=(Fe==null?void 0:Fe.localPath)??((at=c==null?void 0:c.projects[0])==null?void 0:at.localPath)??((Mn=Ie[0])==null?void 0:Mn.localPath);if(Me)try{await jt({action:Q,localPath:Me,editor:J})}catch(Xr){_e(Xr instanceof Error?Xr.message:String(Xr))}},[c==null?void 0:c.projects,jt,Fe==null?void 0:Fe.localPath,Ie]),Le=v.useCallback(async Q=>{var J;try{if(typeof navigator>"u"||!((J=navigator.clipboard)!=null&&J.writeText))throw new Error("Clipboard is not available");await navigator.clipboard.writeText(Q),_e(null)}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[]),dn=v.useCallback(async(Q,J="open_editor",Me)=>{try{await jt({action:J,localPath:Q.path,line:Q.line,column:Q.column,editor:Me})}catch(at){_e(at instanceof Error?at.message:String(at))}},[jt]),as=v.useCallback(async(Q,J)=>{try{await jt({action:Q,localPath:J})}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[jt]),Fi=v.useCallback(()=>{var J;const Q=S0e({selectedProjectId:ie,sidebarProjectId:(J=Ie[0])==null?void 0:J.groupKey,fallbackLocalProjectPath:G});if(Q){ot(Q);return}t("/")},[G,t,ie,Ie,ot]),Qo=v.useCallback(()=>we(!0),[]),sc=v.useCallback(()=>we(!1),[]),bo=v.useCallback(()=>Oe(!0),[]),Qa=v.useCallback(()=>Oe(!1),[]),jp=v.useCallback(()=>ft(!0),[]),Th=v.useCallback(()=>ft(!1),[]),Mp=v.useCallback(async(Q,J,Me)=>{if(e)try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Q,result:{questions:J,answers:Me}})}catch(at){_e(at instanceof Error?at.message:String(at))}},[e,n]),oc=v.useCallback(async(Q,J,Me,at)=>{if(e){J&&vi.getState().setChatComposerPlanMode(e,!1);try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Q,result:{confirmed:J,...Me?{clearContext:!0}:{},...at?{message:at}:{}}})}catch(Mn){_e(Mn instanceof Error?Mn.message:String(Mn))}}},[e,n]),Os=v.useCallback(async(Q,J,Me,at)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Q,toolUseId:J,result:{questions:Me,answers:at}})}catch(Mn){_e(Mn instanceof Error?Mn.message:String(Mn))}},[e,n]),Rh=v.useCallback(async(Q,J,Me)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Q,toolUseId:J,result:Me})}catch(at){_e(at instanceof Error?at.message:String(at))}},[e,n]),ac=v.useCallback(async(Q,J)=>{if(e)try{await n.command({type:"chat.toolRequestAnswer",chatId:e,toolRequestId:Q,decision:J})}catch(Me){_e(Me instanceof Error?Me.message:String(Me))}},[e,n]),zs=h0e(g,f==null?void 0:f.status);return{socket:n,activeChatId:e,activeProjectId:ye,sidebarData:It,localProjects:c,updateSnapshot:f,chatSnapshot:w,chatDiffSnapshot:rt,keybindings:z,appSettings:F,pushConfig:B,llmProvider:W,connectionStatus:O,sidebarReady:ee,uiRestartActive:zs.active,uiRestartLabel:zs.label,localProjectsReady:ue,commandError:Tt,startingLocalPath:cn,sidebarOpen:oe,sidebarCollapsed:Ce,messages:Ue,queuedMessages:Vt,previousPrompt:Ve,latestToolIds:Wt,runtime:Fe,runtimeStatus:wn,isHistoryLoading:T,hasOlderHistory:I,availableProviders:Er,isProcessing:En,canCancel:$n,isDraining:Nr,navbarLocalPath:be,editorLabel:Be,hasSelectedProject:Ae,addProjectModalOpen:Ze,openSidebar:Qo,closeSidebar:sc,collapseSidebar:bo,expandSidebar:Qa,openAddProjectModal:jp,closeAddProjectModal:Th,loadOlderHistory:et,handleCreateChat:un,handleForkChat:qn,handleOpenLocalProject:lr,handleCreateProject:Kr,handleCheckForUpdates:os,handleInstallUpdate:ci,handleForceReload:fo,handleReadAppSettings:Rt,handleWriteAppSettings:on,handleTestMcpServer:Zt,handleSetChatPolicyOverride:xn,handleWriteCloudflareTunnel:At,handleWriteClaudeAuth:_t,handleTestOAuthToken:gt,handleReadLlmProvider:Ct,handleWriteLlmProvider:vt,handleValidateLlmProvider:Ut,handleSignOut:Si,handleSend:kt,handleSteerQueuedMessage:Qt,handleRemoveQueuedMessage:Sn,handleCancel:pn,handleStopDraining:Yr,handleRenameChat:Ya,handleArchiveChat:Ko,handleOpenArchivedChat:Ps,handleDeleteChat:mo,handleHideProject:Xa,handleToggleProjectStar:nr,handleReorderProjectGroups:po,stacks:It.stacks,handleCreateStack:go,handleRenameStack:vo,handleRemoveStack:Ci,handleAddProjectToStack:Yo,handleRemoveProjectFromStack:Xo,handleCreateStackChat:ki,handleListStackWorktrees:Ee,importClaudeSessions:Ge,handleCopyPath:Le,handleOpenExternal:X,handleOpenExternalPath:as,handleOpenLocalLink:dn,handleCompose:Fi,handleAskUserQuestion:Mp,handleExitPlanMode:oc,handleSubagentAskUserQuestion:Os,handleSubagentExitPlanMode:Rh,handleToolRequestAnswer:ac}}const sD=/<thinking>([\s\S]*?)<\/thinking>/gi;function E0e(e){const t=[];let n=0;sD.lastIndex=0;let r;for(;(r=sD.exec(e))!==null;){if(r.index>n){const o=e.slice(n,r.index);o.length>0&&t.push({kind:"text",content:o})}t.push({kind:"thinking",content:r[1]??""}),n=r.index+r[0].length}const i=e.slice(n),s=i.search(/<thinking>/i);if(s!==-1){const o=i.slice(0,s);o.length>0&&t.push({kind:"text",content:o});const a=i.slice(s+10);t.push({kind:"thinking",content:a})}else i.length>0&&t.push({kind:"text",content:i});return N0e(t)}function N0e(e){const t=[];for(const n of e){const r=t[t.length-1];n.kind==="text"&&r&&r.kind==="text"?r.content+=n.content:t.push(n)}return t}const T0e=v.memo(function({content:t}){const[n,r]=v.useState(!1),i=t.trim();return i.length===0?null:u.jsxs("div",{className:"my-3 first:mt-0 last:mb-0",children:[u.jsxs("button",{type:"button",onClick:()=>r(s=>!s),"aria-expanded":n,className:"group/thinking flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer",children:[u.jsx(Kv,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"font-medium uppercase tracking-wider",children:"Thinking"}),u.jsx(no,{className:de("h-3.5 w-3.5 transition-transform duration-200",n&&"rotate-90")})]}),n&&u.jsx("div",{className:"mt-2 border-l-2 border-muted-foreground/20 pl-3 text-sm text-muted-foreground italic prose prose-sm dark:prose-invert max-w-[70ch]",children:u.jsx(Vo,{remarkPlugins:za,components:Ba,children:i})})]})}),qF=v.memo(function({message:t}){const n=v.useMemo(()=>E0e(t.text),[t.text]);return u.jsx("div",{className:"text-pretty prose prose-sm dark:prose-invert px-0.5 w-full max-w-[70ch] space-y-4",children:n.map((r,i)=>r.kind==="thinking"?u.jsx(T0e,{content:r.content},i):u.jsx(Vo,{remarkPlugins:za,components:Ba,children:r.content},i))})}),kp=({children:e,className:t,animate:n=!0,shimmerWidth:r,...i})=>u.jsx("span",{className:de("mx-auto max-w-md text-foreground/60",n&&"animate-shiny-pulse",t),...i,children:e});function R0e(e){const t=e.split(`
2636
2636
  `),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 A0e(e){return e.replace(/<[^>]+>/g,"")}function j0e(e,t){const n=e.split(`
2637
2637
  `),r=t.split(`
2638
2638
  `),i=M0e(n,r),s=L0e(n,r,i);return I0e(s)}function M0e(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 L0e(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 I0e(e){return e.map(t=>{const n=t.type==="removed"?"-":t.type==="added"?"+":" ";return{type:t.type,content:`${n}${t.text}`}})}function Av({content:e,isDiff:t=!1,oldString:n,newString:r}){const i=v.useMemo(()=>t&&n!==void 0&&r!==void 0?j0e(n,r):[],[t,n,r]),s=v.useMemo(()=>t?[]:R0e(e),[e,t]),o=v.useMemo(()=>s.some(a=>a.lineNumber!==null),[s]);return t&&i.length>0?u.jsx("div",{className:"my-1 rounded-lg border border-border overflow-hidden",children:u.jsx("div",{className:"overflow-auto max-h-64 md:max-h-[50vh]",children:u.jsx("table",{className:"w-full border-collapse text-xs font-mono",children:u.jsx("tbody",{children:i.map((a,c)=>{const d=a.type==="removed"?"bg-destructive/10 dark:bg-destructive/15":a.type==="added"?"bg-success/10 dark:bg-success/15":"",f=a.type==="removed"?"text-destructive":a.type==="added"?"text-success":"text-foreground";return u.jsxs("tr",{className:d,children:[u.jsx("td",{className:`px-2 py-0 select-none w-0 whitespace-nowrap ${a.type==="removed"?"text-destructive/50":a.type==="added"?"text-success/50":"text-muted-foreground/50"}`,children:a.type==="removed"?"-":a.type==="added"?"+":" "}),u.jsx("td",{className:`px-2 py-0 whitespace-pre select-all ${f}`,children:a.content.slice(1)})]},c)})})})})}):u.jsx("div",{className:"my-1 rounded-lg border border-border overflow-hidden",children:u.jsx("div",{className:"overflow-auto max-h-64 md:max-h-[50vh]",children:u.jsx("table",{className:"w-full border-collapse text-xs font-mono",children:u.jsx("tbody",{children:s.map((a,c)=>u.jsxs("tr",{children:[o&&u.jsx("td",{className:"px-2 py-0 select-none w-0 whitespace-nowrap text-muted-foreground/50 text-right",children:a.lineNumber!==null?a.lineNumber:""}),u.jsx("td",{className:"px-2 py-0 whitespace-pre select-all text-foreground",children:A0e(a.content)})]},c))})})})})}function D0e(e){switch(e){case"running":return"active";case"failed":return"destructive";case"killed":return"warning";case"completed":case"unknown":default:return"muted"}}function P0e(e){switch(e){case"running":return"Running";case"completed":return"Completed";case"failed":return"Failed";case"killed":return"Killed";case"unknown":return"Unknown"}}function O0e(e){switch(e){case"active":return"bg-emerald-500 dark:bg-emerald-400";case"destructive":return"bg-destructive";case"warning":return"bg-amber-500 dark:bg-amber-400";case"muted":default:return"bg-muted-foreground"}}function z0e(e){switch(e){case"active":return"text-emerald-500 dark:text-emerald-400";case"destructive":return"text-destructive";case"warning":return"text-amber-500 dark:text-amber-400";case"muted":default:return"text-muted-foreground"}}function B0e({status:e}){const t=D0e(e);return u.jsxs("span",{className:"inline-flex items-center gap-1 rounded border border-border bg-card px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide",children:[u.jsx("span",{"aria-hidden":!0,className:de("inline-block size-1.5 rounded-full",O0e(t))}),u.jsx("span",{className:z0e(t),children:P0e(e)})]})}function F0e(){return u.jsx("span",{className:"inline-flex items-center gap-1 rounded border border-border bg-card px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:"started…"})}function $0e({name:e,description:t,run:n}){const r=e??"Workflow";return u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[u.jsx(Ea,{className:"size-4 text-muted-icon shrink-0"}),u.jsxs("div",{className:"flex flex-1 items-center gap-2 min-w-0 overflow-hidden",children:[u.jsx("span",{className:"font-medium text-foreground/80 text-sm truncate",children:r}),t&&u.jsx("span",{className:"text-xs text-muted-foreground truncate",children:t}),n?u.jsxs(u.Fragment,{children:[u.jsx(B0e,{status:n.status}),n.agentCount!=null&&n.agentCount>0&&u.jsxs("span",{className:"text-xs text-muted-foreground tabular-nums",children:[n.agentCount," agents"]})]}):u.jsx(F0e,{})]})]})}function oD(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 H0e({images:e}){return u.jsx("div",{className:"flex flex-col gap-3",children:e.map((t,n)=>{const r=t.mimeType||"image/png";return u.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-muted/20",children:u.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 cx({message:e,isLoading:t=!1,localPath:n,chatId:r=""}){var E;const i=e.result!==void 0,s=!i&&t,o=A2(lx(FF(r))),a=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 k=e.input.pattern,T=e.input.outputMode;return T==="count"?`Count \`${k}\` occurrences`:T==="content"?`Find \`${k}\` in text`:`Find \`${k}\` in files`}return e.toolKind==="bash"?e.input.description||(e.input.command?B3(e.input.command):"Bash"):e.toolKind==="web_search"?e.input.query||"Web Search":e.toolKind==="read_file"?`Read ${$l(e.input.filePath,n)}`:e.toolKind==="write_file"?`Write ${$l(e.input.filePath,n)}`:e.toolKind==="edit_file"?`Edit ${$l(e.input.filePath,n)}`:e.toolKind==="delete_file"?`Delete ${$l(e.input.filePath,n)}`:e.toolKind==="mcp_generic"?`${ZS(e.input.tool)} from ${ZS(e.input.server)}`:e.toolKind==="subagent_task"?e.input.subagentType||e.toolName:e.toolKind==="workflow"?e.input.name??"Workflow":e.toolName},[e.input,e.toolKind,e.toolName,n]),c=v.useMemo(()=>e.toolKind==="subagent_task",[e.toolKind]),d=v.useMemo(()=>{if(e.toolKind==="skill")return e.input.skill},[e.input,e.toolKind]),f=e.toolKind==="bash",m=e.toolKind==="write_file",g=e.toolKind==="edit_file",b=e.toolKind==="delete_file",y=e.toolKind==="read_file",_=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 k=e.result.content;if(typeof k=="string")return k}return JSON.stringify(e.result,null,2)},[e.result]),w=v.useMemo(()=>{if(!y)return[];if(e.result&&typeof e.result=="object"&&"blocks"in e.result){const k=e.result.blocks;if(Array.isArray(k)){const T=oD(k);if(T.length>0)return T}}return oD(e.rawResult)},[y,e.rawResult,e.result]),C=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 u.jsx(Wa,{className:"w-full",children:u.jsx(f2,{expandedContent:u.jsx(by,{className:"my-4 text-sm",children:u.jsxs("div",{className:"flex flex-col gap-2",children:[g?u.jsx(Av,{content:"",isDiff:!0,oldString:e.input.oldString,newString:e.input.newString}):b?u.jsx(Av,{content:e.input.content}):!y&&!m&&u.jsx(rC,{label:f?u.jsxs("span",{className:"flex items-center gap-2 w-full",children:[u.jsx("span",{children:"Command"}),!!e.input.timeoutMs&&u.jsxs("span",{className:"text-muted-foreground",children:["timeout: ",String(e.input.timeoutMs),"ms"]}),!!e.input.runInBackground&&u.jsx("span",{className:"text-muted-foreground",children:"background"})]}):m?"Contents":"Input",copyText:C,children:C}),i&&y&&!e.isError&&(w.length>0?u.jsxs("div",{children:[u.jsx("span",{className:"font-medium text-muted-foreground",children:"Image"}),u.jsx("div",{className:"mt-1",children:u.jsx(H0e,{images:w})})]}):u.jsx(Av,{content:_})),m&&!e.isError&&u.jsx(Av,{content:e.input.content}),i&&!y&&!(m&&!e.isError)&&!(g&&!e.isError)&&!(b&&!e.isError)&&u.jsx(rC,{label:e.isError?"Error":"Result",copyText:_,children:_})]})}),children:e.toolKind==="workflow"&&!e.isError?(()=>{const k=e.result,T=k==null?void 0:k.taskId,R=T?o.find(A=>A.taskId===T):void 0;return u.jsx($0e,{name:e.input.name,description:e.input.description,run:R})})():u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:e.isError?u.jsx(Is,{className:"size-4 text-destructive"}):c?u.jsx(yk,{className:"size-4 text-muted-icon"}):e.toolKind==="workflow"?u.jsx(Ea,{className:"size-4 text-muted-icon"}):u.jsx(lF,{icon:aF(e.toolName),className:"size-4 text-muted-icon"})}),u.jsx(eu,{className:"text-left transition-opacity duration-200 truncate",children:u.jsx(kp,{animate:s,shimmerWidth:Math.max(20,(((E=d||a)==null?void 0:E.length)??33)*3),children:d||a})})]})})})}function U0e(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 aD({durationMs:e,prefix:t="Worked for"}){return e<=0?null:u.jsxs(Dbe,{children:[t," ",U0e(e)]})}const oS=/\[([^\]]+)\]\(\/chat\/([0-9a-fA-F][0-9a-fA-F-]{7,})\)/g;function KF(e,t){const n=[];let r=0,i=0;oS.lastIndex=0;for(let s=oS.exec(e);s!==null;s=oS.exec(e))s.index>r&&n.push(e.slice(r,s.index)),n.push(u.jsx(hk,{to:`/chat/${s[2]}`,className:"underline decoration-destructive/40 hover:decoration-destructive",children:s[1]},`chat-link-${i++}`)),r=s.index+s[0].length;return r<e.length&&n.push(e.slice(r)),n.length===0?e:n}function YF({message:e}){if(!e.success){const t=e.result||"An unknown error occurred.";return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"px-4 py-3 mx-2 my-1 rounded-lg bg-destructive/10 border border-destructive/20 text-destructive text-sm whitespace-pre-wrap",children:KF(t)}),e.durationMs>0?u.jsx(aD,{durationMs:e.durationMs,prefix:"Failed after"}):null]})}return u.jsx(aD,{durationMs:e.durationMs})}function V0e(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}function W0e(e){return typeof e=="string"?e:JSON.stringify(e,null,2)}function G0e(e){return e.replace(/<persisted-output>\n?/g,"").replace(/\n?<\/persisted-output>/g,"")}function q0e({message:e,localPath:t,isRunning:n=!1}){if(e.kind==="tool"&&e.persisted){const i=G0e(W0e(e.rawResult??""));return u.jsxs("div",{className:"animate-in fade-in-0 duration-200 rounded-md border border-border bg-muted/30 p-2 space-y-1 text-xs",children:[u.jsxs("div",{className:"font-medium",children:[e.toolName,": output too large (",V0e(e.persisted.originalSize),") — saved to disk"]}),u.jsx("pre",{className:"text-[11px] whitespace-pre-wrap overflow-hidden max-h-48",children:i}),u.jsxs("a",{href:r2(e.persisted.filePath),className:"text-blue-500 hover:underline break-all",target:"_blank",rel:"noreferrer",children:["View full output (",e.persisted.filePath,")"]})]})}let r;switch(e.kind){case"assistant_text":r=u.jsx(qF,{message:e});break;case"tool":r=u.jsx(cx,{message:e,isLoading:n,localPath:t});break;case"result":r=u.jsx(YF,{message:e});break;default:return null}return u.jsx("div",{className:"animate-in fade-in-0 duration-200",children:r})}function K0e(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 Y0e({error:e,runId:t,onRetry:n,onOpenSettings:r}){const i=e.code==="TIMEOUT"||e.code==="PROVIDER_ERROR",s=e.code==="AUTH_REQUIRED";return u.jsxs("div",{"data-testid":`subagent-error:${t}`,className:"rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm",children:[u.jsxs("div",{className:"flex items-center gap-2 font-medium text-destructive",children:[u.jsx(fm,{className:"h-4 w-4"}),u.jsx("span",{children:K0e(e.code)})]}),u.jsx("p",{className:"mt-1 text-foreground",children:e.message}),u.jsxs("div",{className:"mt-2 flex gap-2",children:[s&&r&&u.jsxs("button",{type:"button",onClick:r,className:"inline-flex items-center gap-1 text-xs underline",children:[u.jsx(kG,{className:"h-3 w-3"})," Open settings"]}),i&&n&&u.jsxs("button",{type:"button",onClick:n,className:"inline-flex items-center gap-1 text-xs underline",children:[u.jsx(vq,{className:"h-3 w-3"})," Retry"]})]})]})}function X0e({question:e,header:t,currentIndex:n,totalQuestions:r,onBack:i,children:s}){const o=i&&n>0,a=o||r>1||!!t;return u.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[u.jsxs("div",{className:"relative",children:[u.jsxs("div",{className:"p-3 px-4 bg-card border-b border-border",children:[a&&u.jsxs("div",{className:"flex flex-row items-center gap-2 mb-1",children:[o?u.jsx("button",{onClick:i,className:"text-muted-foreground hover:opacity-60 transition-all flex items-center",children:u.jsx(dW,{className:"h-4 w-4 -ml-0.5",strokeWidth:3})}):r>1?u.jsxs("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground whitespace-nowrap",children:[n+1," of ",r]}):null,t?u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground text-pretty",children:t}):null]}),u.jsx("h3",{className:"font-medium text-foreground text-sm text-pretty",children:e})]}),r>1&&u.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-0.5 bg-border",children:u.jsx("div",{className:"h-full bg-muted-foreground/40 transition-all duration-300",style:{width:`${n/r*100}%`}})})]}),s]})}function lD({label:e,description:t}){return u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"text-foreground text-sm",children:e}),t&&u.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:t})]})}function XF({selected:e,multiSelect:t,onClick:n}){const r=de("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"),i=e?u.jsx(ns,{strokeWidth:3,className:"translate-y-[0.5px] h-3 w-3 text-white dark:text-background"}):null;return n?u.jsx("button",{type:"button",onClick:n,className:r,children:i}):u.jsx("div",{"aria-hidden":!0,className:r,children:i})}function Q0e({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?u.jsx("button",{onClick:r,className:de(s,o,"transition-all cursor-pointer"),children:u.jsxs("div",{className:"flex items-center justify-between gap-3",children:[u.jsx("div",{className:"flex-1 min-w-0",children:u.jsx(lD,{label:e.label,description:e.description})}),u.jsx(XF,{selected:t,multiSelect:n})]})}):u.jsx("div",{className:de(s,o),children:u.jsx(lD,{label:e.label,description:e.description})})}function QF({questions:e,onSubmit:t,onCancel:n}){var U;const[r,i]=v.useState(0),[s,o]=v.useState({}),[a,c]=v.useState({});if(e.length===0)return null;const d=M=>M.id||M.question,f=(M,D)=>{var B;const z=(B=a[M])==null?void 0:B.trim(),P=s[M]||"",F=D||e.find(H=>d(H)===M);if(F!=null&&F.multiSelect)return[P,z].filter(Boolean).flatMap(H=>H.split(", ").filter(Boolean));const $=z||P;return $?[$]:[]},m=M=>{const D=s[d(M)]||"";return M.multiSelect?D.split(", ").filter(Boolean):[D]},g=(M,D)=>{const z=d(M);if(M.multiSelect){const P=s[z]?s[z].split(", ").filter(Boolean):[],F=P.includes(D)?P.filter($=>$!==D):[...P,D];o({...s,[z]:F.join(", ")})}else o({...s,[z]:D}),c({...a,[z]:""}),r<e.length-1&&setTimeout(()=>i(r+1),150)},b=(M,D)=>{const z=d(M);c({...a,[z]:D}),D&&!M.multiSelect&&o({...s,[z]:""})},y=M=>{const D=d(M);M.multiSelect&&a[D]&&c({...a,[D]:""})},_=e.every(M=>f(d(M),M).length>0),w=e[Math.min(r,e.length-1)],C=r>=e.length-1,E=f(d(w),w).length>0,k=()=>{r<e.length-1&&i(r+1)},T=()=>{r>0&&i(r-1)},R=()=>{if(!_)return;const M={};for(const D of e){const z=d(D);M[z]=f(z,D)}t(M)},A=M=>{if(M.key==="Enter"&&E){if(M.preventDefault(),C){R();return}k()}},j=m(w),I=a[d(w)]||"";return u.jsxs("div",{className:"w-full space-y-3",children:[u.jsxs(X0e,{question:w.question,header:w.header,currentIndex:r,totalQuestions:e.length,onBack:r>0?T:void 0,children:[(U=w.options)==null?void 0:U.map(M=>u.jsx(Q0e,{option:M,selected:j.includes(M.label),multiSelect:w.multiSelect,onClick:()=>g(w,M.label)},M.label)),u.jsx("div",{className:"transition-all bg-background",children:u.jsxs("div",{className:"flex pr-5 items-center justify-between gap-3",children:[u.jsx("input",{type:"text",value:I,onChange:M=>b(w,M.target.value),onKeyDown:A,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"}),u.jsx(XF,{selected:!!I,multiSelect:w.multiSelect,onClick:w.multiSelect&&I?()=>y(w):void 0})]})})]}),u.jsxs("div",{className:"flex items-center mx-2",children:[n?u.jsx(De,{size:"sm",variant:"outline",className:"rounded-full",onClick:n,children:"Cancel"}):null,u.jsxs("div",{className:"ml-auto flex gap-2",children:[!C&&E&&(w.multiSelect||!!I)&&u.jsx(De,{size:"sm",onClick:k,children:"Next"}),C&&u.jsx(De,{size:"sm",onClick:R,disabled:!_,className:de(!_&&"opacity-50 cursor-not-allowed","rounded-full"),children:"Submit"})]})]})]})}function Z0e(e){return e==null?void 0:e.answers}function aS(e){return e.id||e.question}function ZF({message:e,onSubmit:t,isLatest:n}){var g;const r=vy(),i=e.input.questions,s=!!e.result,o=Z0e(e.result),a=((g=e.result)==null?void 0:g.discarded)===!0,[c,d]=v.useState(o??null),[f,m]=v.useState(s);if(f||s){const b=o||c||{};return u.jsx("div",{className:"w-full",children:u.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[u.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:[u.jsxs("p",{children:["Question",i.length!==1?"s":""]}),u.jsx("p",{className:"",children:a?"Discarded":"Answers"})]}),i.map((y,_)=>{const w=b[aS(y)]||b[y.question]||[],C=_===i.length-1,E=y.options?w.map(k=>{var T,R;return(R=(T=y.options)==null?void 0:T.find(A=>A.label===k))==null?void 0:R.description}).filter(k=>!!k):[];return u.jsxs("div",{className:de("w-full p-3 pt-2.5 pl-4 pr-5 bg-background flex items-start justify-between gap-3",!C&&"border-b border-border"),children:[u.jsxs("div",{className:"flex-1 min-w-0",children:[y.header&&u.jsx("div",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground text-pretty",children:y.header}),u.jsx("div",{className:"text-sm text-pretty",children:y.question})]}),u.jsx("div",{className:"max-w-[50%] text-right",children:w.length>0?u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"text-sm font-medium text-pretty",children:w.join(", ")}),E.length>0&&u.jsx("div",{className:"text-xs text-muted-foreground mt-0.5 text-pretty",children:E.join(" · ")})]}):u.jsx("div",{className:"text-sm font-medium italic",children:a?"Discarded":"No Response"})})]},aS(y))})]})})}return r.readonly?u.jsx("div",{className:"w-full",children:u.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[u.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:[u.jsxs("p",{children:["Question",i.length!==1?"s":""]}),u.jsx("p",{className:"text-muted-foreground",children:"Awaiting response"})]}),i.map((b,y)=>{var _;return u.jsxs("div",{className:de("w-full p-3 pt-2.5 pl-4 pr-5 bg-background flex items-start justify-between gap-3",y<i.length-1&&"border-b border-border"),children:[u.jsxs("div",{className:"flex-1 min-w-0",children:[b.header&&u.jsx("div",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground text-pretty",children:b.header}),u.jsx("div",{className:"text-sm text-pretty",children:b.question})]}),u.jsx("div",{className:"max-w-[50%] text-right text-xs text-muted-foreground text-pretty",children:((_=b.options)==null?void 0:_.map(w=>w.label).join(", "))||"Freeform response"})]},aS(b))})]})}):n?u.jsx(QF,{questions:i,onSubmit:b=>{d(b),m(!0),t(e.toolId,i,b)}}):u.jsx("div",{className:"w-full py-2",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(G5,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"Questions pending (newer question active)"})]})})}function JF({message:e,onConfirm:t,isLatest:n}){const r=vy(),i=!!e.result,[s,o]=v.useState(!1),[a,c]=v.useState(!1),[d,f]=v.useState(!1),[m,g]=v.useState(""),b=v.useRef(null),y=e.input;v.useEffect(()=>{d&&b.current&&b.current.focus()},[d]);const _=async()=>{y!=null&&y.plan&&(await navigator.clipboard.writeText(y.plan),c(!0),setTimeout(()=>c(!1),2e3))},w=i?e.result:null,C=(w==null?void 0:w.discarded)===!0;return u.jsxs("div",{className:"flex flex-col gap-3",children:[u.jsxs("div",{className:"relative rounded-2xl border border-border overflow-hidden group/plan",children:[(y==null?void 0:y.plan)&&u.jsx(De,{variant:"ghost",size:"icon","aria-label":a?"Copied":"Copy plan",className:de("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",!a&&"hover:text-foreground",a&&"hover:!bg-transparent hover:!border-transparent"),onClick:_,children:a?u.jsx(ns,{className:"h-4 w-4 text-success"}):u.jsx(La,{className:"h-4 w-4"})}),u.jsxs("div",{className:de("!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&&u.jsxs(De,{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",u.jsx(sh,{className:`size-3.5 transition-transform ${s?"rotate-180":""}`})]}),y!=null&&y.plan?u.jsxs("div",{className:"prose prose-sm dark:prose-invert max-w-none",children:[u.jsx(Vo,{remarkPlugins:za,components:Ba,children:y.plan}),u.jsx("div",{className:"mt-5"})]}):u.jsx("p",{className:"text-sm text-muted-foreground",children:"No plan provided"})]})]}),i?u.jsx("div",{className:"flex justify-end mx-2",children:u.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:[u.jsx("em",{children:C?"Discarded":w!=null&&w.clearContext?"Approved & Cleared Context":w!=null&&w.confirmed?"Approved":w!=null&&w.message?`Adjusted: "${w.message}"`:"Adjusted Plan"}),u.jsx(TW,{className:"inline h-4 w-4 ml-1.5 -mt-0.5"})]})}):n?r.readonly?u.jsx("div",{className:"flex justify-end mx-2",children:u.jsx("span",{className:"inline text-sm text-muted-foreground italic",children:"Plan pending in original session"})}):u.jsxs("div",{className:"flex flex-col gap-3",children:[!d&&u.jsxs("div",{className:"flex flex-col md:flex-row items-stretch md:items-center justify-end gap-2 mx-2",children:[u.jsxs(De,{size:"sm",onClick:()=>t(e.toolId,!0,!0),className:"rounded-full bg-primary text-background pr-4 md:order-last",children:[u.jsx(sW,{className:"h-4 w-4 mr-1.5"}),"Approve & Clear"]}),u.jsxs("div",{className:"flex items-stretch md:items-center gap-2 md:contents",children:[u.jsxs(De,{size:"sm",variant:"outline",onClick:()=>f(!0),className:"rounded-full border-border flex-1 md:flex-initial md:order-first",children:[u.jsx(oh,{className:"h-4 w-4 mr-1.5"}),"Suggest Edits"]}),u.jsxs(De,{size:"sm",variant:"outline",onClick:()=>t(e.toolId,!0),className:"rounded-full border-border flex-1 md:flex-initial",children:[u.jsx(ns,{className:"h-4 w-4 mr-1.5"}),"Approve"]})]})]}),d&&u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx("textarea",{ref:b,value:m,onChange:E=>g(E.target.value),onKeyDown:E=>{E.key==="Enter"&&!E.shiftKey&&m.trim()&&(E.preventDefault(),t(e.toolId,!1,void 0,m.trim())),E.key==="Escape"&&(f(!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"}),u.jsxs("div",{className:"flex items-center justify-end gap-2 mx-2",children:[u.jsx(De,{size:"sm",variant:"ghost",onClick:()=>{f(!1),g("")},className:"rounded-full text-muted-foreground",children:"Cancel"}),u.jsxs(De,{size:"sm",disabled:!m.trim(),onClick:()=>t(e.toolId,!1,void 0,m.trim()),className:"rounded-full bg-primary text-background disabled:opacity-50 disabled:pointer-events-none",children:[u.jsx(Cq,{className:"h-4 w-4 mr-1.5"}),"Adjust Plan"]})]})]})]}):u.jsx("div",{className:"flex justify-end mx-2",children:u.jsx("span",{className:"inline text-sm text-muted-foreground italic",children:"Plan pending (newer prompt active)"})})]})}function J0e({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 u.jsxs("div",{"data-testid":`subagent-pending-tool:${e.toolUseId}`,children:[u.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"awaiting your response"}),u.jsx(ZF,{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 u.jsxs("div",{"data-testid":`subagent-pending-tool:${e.toolUseId}`,children:[u.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"awaiting your response"}),u.jsx(JF,{message:i,onConfirm:(s,o,a,c)=>n(s,{confirmed:o,clearContext:a,message:c}),isLatest:!0})]})}return null}const e_e=40;function vs(e,t=e_e){return e.length<=t?e:`${e.slice(0,t-1)}…`}function t_e(e,t){switch(e.toolKind){case"bash":{const n=e.input.description||(e.input.command?B3(e.input.command):"");return n?`$ ${vs(n)}`:"running bash..."}case"read_file":{const n=$l(e.input.filePath,t);return n?`reading ${vs(n)}`:"reading file..."}case"write_file":{const n=$l(e.input.filePath,t);return n?`writing ${vs(n)}`:"writing file..."}case"edit_file":{const n=$l(e.input.filePath,t);return n?`editing ${vs(n)}`:"editing file..."}case"delete_file":{const n=$l(e.input.filePath,t);return n?`deleting ${vs(n)}`:"deleting file..."}case"glob":return e.input.pattern?`globbing ${vs(e.input.pattern)}`:"globbing...";case"grep":return e.input.pattern?`grepping ${vs(e.input.pattern)}`:"grepping...";case"web_search":return e.input.query?`searching: ${vs(e.input.query)}`:"searching web...";case"skill":return e.input.skill?`skill ${vs(e.input.skill)}`:"running skill...";case"todo_write":return"updating todos...";case"subagent_task":return e.input.subagentType?`delegating ${vs(e.input.subagentType)}`:"delegating...";case"ask_user_question":return"asking...";case"exit_plan_mode":return"presenting plan...";case"offer_download":return"preparing download...";case"image_generation":return"generating image...";case"mcp_generic":return vs(`${e.input.server}.${e.input.tool}`);case"unknown_tool":return`running ${vs(e.toolName)}`;default:return"running..."}}function n_e(e,t){if(e.pendingTool)return"waiting for input...";const n=e.entries,r=new Set;for(let s=n.length-1;s>=0;s--){const o=n[s];if(o.kind==="tool_result")r.add(o.toolId);else if(o.kind==="tool_call"&&!r.has(o.tool.toolId))return t_e(o.tool,t)}const i=n[n.length-1];return(i==null?void 0:i.kind)==="assistant_text"?"streaming...":"running..."}function e$({run:e,indentDepth:t,localPath:n,onOpenSettings:r,onRetry:i,onSubagentAskUserQuestionSubmit:s,onSubagentExitPlanModeSubmit:o,onCancelSubagentRun:a}){var g;const c=zF(e.entries),d=c.some(b=>b.kind==="assistant_text"),f=e.status==="running"&&d,m=e.status==="running"?n_e(e,n):"";return u.jsxs("div",{"data-testid":`subagent-message:${e.runId}`,className:de("border-l-2 border-accent pl-3 py-2 space-y-2"),style:{marginLeft:`${t*24}px`},children:[u.jsxs("header",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[u.jsx(ih,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:e.subagentName}),u.jsxs("span",{className:"opacity-60",children:[e.provider,e.model?`/${e.model}`:""]}),((g=e.usage)==null?void 0:g.outputTokens)!=null&&u.jsxs("span",{className:"opacity-60",children:["· ",e.usage.inputTokens??0,"↑ ",e.usage.outputTokens,"↓"]}),e.status==="running"&&u.jsx("span",{"data-testid":`subagent-activity:${e.runId}`,className:"ml-auto inline-block animate-pulse",children:m}),a&&e.status==="running"&&u.jsx("button",{type:"button","data-testid":`subagent-cancel:${e.runId}`,"aria-label":"Cancel subagent",onClick:()=>a(e.chatId,e.runId),className:"text-muted-foreground hover:text-foreground",children:u.jsx(Is,{className:"h-3.5 w-3.5"})})]}),c.map(b=>u.jsx(q0e,{message:b,localPath:n,isRunning:e.status==="running"},b.id)),e.pendingTool&&u.jsx(J0e,{pendingTool:e.pendingTool,onAskUserQuestionSubmit:(b,y,_)=>s==null?void 0:s(e.runId,b,y,_),onExitPlanModeSubmit:(b,y)=>o==null?void 0:o(e.runId,b,y)}),c.length===0&&e.finalText&&u.jsxs("div",{className:de("whitespace-pre-wrap text-sm",f&&"text-foreground/80"),children:[e.finalText,f&&u.jsx("span",{className:"ml-0.5 inline-block w-2 animate-pulse",children:"▍"})]}),e.status==="failed"&&e.error&&u.jsx("div",{children:u.jsx(Y0e,{error:e.error,runId:e.runId,subagentId:e.subagentId,onOpenSettings:r,onRetry:i})})]})}function r_e(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}}const i_e=v.memo(function({content:t,attachments:n=[],steered:r=!1,autoContinue:i}){const[s,o]=v.useState(null),a=vy(),c=v.useMemo(()=>r_e(t),[t]),d=!a.readonly,f=v.useMemo(()=>n.filter(_=>_.kind==="image"&&_.contentUrl),[n]),m=v.useMemo(()=>n.filter(_=>_.kind!=="image"||!_.contentUrl),[n]),g=n.find(_=>_.id===s)??null,b=g?Cp(g,"user_attachment"):null;function y(_){if(!d||!_.contentUrl)return;if(_h(_).openInNewTab){typeof window<"u"&&window.open(new URL(_.contentUrl,document.baseURI||window.location.href).toString(),"_blank","noopener,noreferrer");return}o(_.id)}return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"flex flex-col items-end gap-2",children:[f.length>0?u.jsx("div",{className:"flex max-w-[85%] sm:max-w-[80%] flex-wrap justify-end gap-3",children:f.map(_=>u.jsx(p2,{attachment:_,onClick:d?()=>y(_):void 0},_.id))}):null,m.length>0?u.jsx("div",{className:"flex max-w-[85%] sm:max-w-[80%] flex-wrap justify-end gap-2",children:m.map(_=>u.jsx(Fo,{attachment:_,onClick:d?()=>y(_):void 0},_.id))}):null,c.body||!c.body&&n.length===0&&t&&!c.systemMessage?u.jsxs("div",{className:"flex max-w-[85%] items-center gap-2 sm:max-w-[80%]",children:[r?u.jsx(aK,{"aria-label":"Sent mid-turn",className:"size-3.5 shrink-0 text-muted-foreground"}):null,u.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:u.jsx(Vo,{remarkPlugins:za,components:Ba,children:c.body})})]}):null,i?u.jsx("span",{className:"text-xs text-muted-foreground opacity-70",children:"auto-sent"}):null]}),u.jsx(Ch,{source:b,open:b!==null,onOpenChange:_=>!_&&o(null)})]})});function s_e({json:e}){return u.jsx("div",{className:"flex gap-3 justify-start",children:u.jsx("div",{className:"flex-1 max-w-[90%]",children:u.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 t$({title:e,count:t,children:n,badge:r}){const[i,s]=v.useState(!1);return t===0?null:u.jsxs("div",{className:"flex flex-col gap-1.5",children:[u.jsxs("button",{onClick:()=>s(!i),className:"flex items-center gap-1 cursor-pointer group/section hover:opacity-60 transition-opacity",children:[u.jsx(no,{className:de("h-3.5 w-3.5 text-muted-foreground transition-transform duration-200",i&&"rotate-90")}),u.jsx("span",{className:"text-muted-foreground font-medium",children:e}),u.jsx("span",{className:"text-muted-foreground/60",children:t}),r]}),i&&u.jsx("div",{className:"ml-5",children:n})]})}function lS({title:e,items:t,icon:n,getIcon:r}){return t.length===0?null:u.jsx(t$,{title:e,count:t.length,children:u.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.map(i=>u.jsx(uF,{icon:r?r(i):n,children:i},i))})})}function o_e(e){const t=e.match(/^mcp__([^_]+)__(.+)$/);return t?{server:t[1],tool:t[2]}:null}function n$({status:e}){const t=e==="connected"?"bg-success":e==="pending"?"bg-warning":"bg-destructive";return u.jsx("span",{className:de("inline-block h-2 w-2 rounded-full shrink-0",t)})}function a_e(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 cD({server:e}){const[t,n]=v.useState(!1),r=e.status==="connected";return u.jsxs("div",{className:"flex flex-col gap-1.5",children:[u.jsxs("button",{onClick:()=>r&&e.tools.length>0&&n(!t),className:de("flex items-center gap-1.5",r&&e.tools.length>0&&"cursor-pointer hover:opacity-60 transition-opacity"),children:[r&&e.tools.length>0&&u.jsx(no,{className:de("h-3 w-3 text-muted-foreground transition-transform duration-200",t&&"rotate-90")}),u.jsx(n$,{status:e.status}),u.jsx("span",{className:"text-muted-foreground font-medium",children:ZS(e.name)}),r?u.jsxs("span",{className:"text-muted-foreground/50",children:[e.tools.length," tools"]}):u.jsx("span",{className:"text-muted-foreground/50",children:a_e(e.status)})]}),!r&&e.error&&u.jsx("span",{className:"text-destructive ml-5",children:e.error}),t&&e.tools.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5 ml-5",children:e.tools.map(i=>u.jsx(uF,{icon:aF(`mcp__${e.name}__${i}`),children:i},i))})]})}function l_e({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?u.jsxs("span",{className:"flex items-center gap-1 ml-1",children:[u.jsx(n$,{status:"failed"}),u.jsxs("span",{className:"text-muted-foreground/60",children:[n.length," disconnected"]})]}):null;return u.jsx(t$,{title:"MCP Servers",count:e.length,badge:r,children:u.jsxs("div",{className:"flex flex-col gap-2",children:[t.map(i=>u.jsx(cD,{server:i},i.name)),n.map(i=>u.jsx(cD,{server:i},i.name))]})})}function c_e({rawJson:e}){const[t,n]=v.useState(!1);return u.jsxs("div",{className:"flex flex-col gap-1.5",children:[u.jsxs("button",{onClick:()=>n(!t),className:"flex items-center gap-1 cursor-pointer group/section hover:opacity-60 transition-opacity",children:[u.jsx(no,{className:de("h-3.5 w-3.5 text-muted-foreground transition-transform duration-200",t&&"rotate-90")}),u.jsx("span",{className:"text-muted-foreground font-medium",children:"Raw Message"})]}),t&&u.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 u_e({message:e,rawJson:t}){const{coreTools:n,mcpServersWithTools:r}=v.useMemo(()=>{const i=new Map,s=[];for(const a of e.tools){const c=o_e(a);if(c){const d=i.get(c.server)||[];d.push(c.tool),i.set(c.server,d)}else s.push(a)}const o=e.mcpServers.map(a=>({name:a.name,status:a.status,error:a.error,tools:i.get(a.name)||[]}));return{coreTools:s,mcpServersWithTools:o}},[e.tools,e.mcpServers]);return u.jsx(Wa,{children:u.jsxs(f2,{expandedContent:u.jsx(by,{className:"my-4 text-xs",children:u.jsxs("div",{className:"flex flex-col gap-3",children:[u.jsx(Ibe,{children:e.model}),u.jsx(lS,{title:"Tools",items:n,getIcon:i=>nC[i]??oF}),u.jsx(lS,{title:"Agents",items:e.agents,icon:yk}),u.jsx(lS,{title:"Commands",items:e.slashCommands,icon:Lq}),u.jsx(l_e,{servers:r}),t&&u.jsx(c_e,{rawJson:t})]})}),children:[u.jsx(KV,{className:"h-5 w-5 text-logo"}),u.jsx(eu,{children:"Session Started"})]})})}const d_e={"kanna-oauth-pool":"Pool token","claude-pro":"Claude Pro","claude-max":"Claude Max"};function h_e(e,t){return e?d_e[e]??e:t?`API key (${t})`:null}function f_e({message:e}){const{organization:t,tokenSource:n,apiKeySource:r,subscriptionType:i,email:s,oauthKeyMasked:o}=e.accountInfo,a=o??t??s??"Unknown account",c=h_e(n,r),[d,f]=v.useState(!1);return u.jsx(Wa,{children:u.jsxs("div",{className:"flex w-full flex-col",children:[u.jsxs("button",{type:"button",onClick:()=>f(m=>!m),"aria-expanded":d,className:"group/account flex w-full items-center gap-2.5 text-left transition-opacity hover:opacity-80 focus-visible:opacity-100",children:[u.jsx("span",{className:"text-[12px] font-medium text-muted-foreground",children:"Account"}),u.jsx("span",{className:"h-3 w-px bg-border/60","aria-hidden":!0}),u.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[13px] font-medium leading-snug text-foreground",children:a}),c?u.jsx("span",{className:"hidden whitespace-nowrap text-[11px] text-muted-foreground sm:inline",children:c}):null,u.jsx(no,{className:de("h-3.5 w-3.5 flex-shrink-0 text-muted-foreground transition-transform duration-200",d&&"rotate-90"),"aria-hidden":!0})]}),c?u.jsx("span",{className:"mt-0.5 text-[11px] text-muted-foreground sm:hidden",children:c}):null,d?u.jsx(by,{className:"mt-3 mb-2 text-xs",children:u.jsxs("div",{className:"flex flex-col gap-3",children:[u.jsx(rC,{label:"OAuth key",copyText:a,children:u.jsx("code",{className:"block text-xs whitespace-pre-wrap break-all",children:a})}),u.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-5 gap-y-1.5",children:[c?u.jsxs(u.Fragment,{children:[u.jsx("dt",{className:"text-muted-foreground",children:"Source"}),u.jsx("dd",{className:"text-foreground/90",children:c})]}):null,i?u.jsxs(u.Fragment,{children:[u.jsx("dt",{className:"text-muted-foreground",children:"Plan"}),u.jsx("dd",{className:"text-foreground/90",children:i})]}):null,s?u.jsxs(u.Fragment,{children:[u.jsx("dt",{className:"text-muted-foreground",children:"Email"}),u.jsx("dd",{className:"font-mono break-all text-foreground/90",children:s})]}):null,t?u.jsxs(u.Fragment,{children:[u.jsx("dt",{className:"text-muted-foreground",children:"Organization"}),u.jsx("dd",{className:"text-foreground/90",children:t})]}):null]})]})}):null]})})}function m_e(e){return e===429?"Rate Limited":e===500?"Internal Server Error":e===502?"Bad Gateway":e===503?"Service Unavailable":e===529?"Overloaded":e>=500?"Server Error":(e>=400,"API Error")}function p_e(e){if(e!==0)return"https://status.claude.com"}function g_e({message:e}){const t=e.status>0?`${e.status} ${m_e(e.status)}`:"API Error",n=p_e(e.status);return u.jsx("div",{className:"w-full max-w-[70ch]",children:u.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 text-destructive-foreground px-3 py-2.5 space-y-1.5",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-destructive",children:[u.jsx(fm,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"uppercase tracking-wide",children:t})]}),u.jsx("div",{className:"text-sm whitespace-pre-wrap break-words text-foreground/90",children:e.text}),(e.requestId||n)&&u.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground pt-0.5",children:[n&&u.jsx("a",{href:n,target:"_blank",rel:"noreferrer",className:"hover:underline",children:"Check status"}),e.requestId&&u.jsxs("span",{children:["Request ID: ",u.jsx("code",{className:"text-xs",children:e.requestId})]})]})]})})}const v_e={completed:{Icon:ns,iconClass:"text-success",textClass:"text-muted-foreground"},in_progress:{Icon:_n,iconClass:"text-foreground animate-spin",textClass:"text-foreground font-medium"},pending:{Icon:vW,iconClass:"text-muted-foreground",textClass:"text-muted-foreground"}};function b_e({message:e}){const t=e.input.todos;return t.length?u.jsx("div",{className:"w-full",children:u.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[u.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:[u.jsx(jG,{className:"h-4 w-4 text-muted-foreground"}),"Progress"]}),u.jsx("div",{children:t.map((n,r)=>{const i=r===t.length-1,{Icon:s,iconClass:o,textClass:a}=v_e[n.status];return u.jsxs("div",{className:de("flex items-center gap-3 px-4 py-2.5 bg-background",!i&&"border-b border-border"),children:[u.jsx(s,{className:de("h-4 w-4 flex-shrink-0",o)}),u.jsx("span",{className:de("text-sm",a),children:n.status==="in_progress"?n.activeForm:n.content})]},r)})})]})}):null}function x_e({message:e}){const t=e.result,n=t==null?void 0:t.contentUrl,[r,i]=v.useState("idle"),[s,o]=v.useState(!1);if(v.useEffect(()=>{if(!n)return;const _=new AbortController;return fetch(n,{method:"HEAD",signal:_.signal}).then(w=>{_.signal.aborted||i(w.ok?"ready":"missing")}).catch(()=>{}),()=>_.abort()},[n]),!t||!n)return null;const a={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},c=wh(a),d=cy(c,t.mimeType),f=t.size>0?kh(t.size):null,m=u.jsxs(u.Fragment,{children:[d,f?u.jsxs(u.Fragment,{children:[" · ",u.jsx("span",{className:"tabular-nums",children:f})]}):null]});if(r==="missing")return u.jsx("div",{className:"flex","data-testid":"offer-download-link",children:u.jsx(Fo,{attachment:a,disabledReason:"File no longer available"})});if(!_h(a).openInNewTab){const _=`Preview ${a.displayName}, ${d}${f?`, ${f}`:""}`;return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"flex","data-testid":"offer-download-link",children:u.jsx(Fo,{attachment:a,onClick:()=>o(!0),meta:m,ariaLabel:_})}),u.jsx(Ch,{source:s?Cp(a,"offer_download"):null,open:s,onOpenChange:o})]})}const y=["Download",a.displayName,d,f].filter(Boolean);return u.jsx("div",{className:"flex","data-testid":"offer-download-link",children:u.jsx(Fo,{attachment:a,href:n,download:t.fileName||void 0,meta:m,ariaLabel:y.join(", ")})})}const cS=new Map;function y_e(e){const{cacheKey:t,enabled:n,ref:r,fetcher:i,rootMargin:s}=e,o=cS.get(t),[a,c]=v.useState(o!==void 0?"ready":"idle"),[d,f]=v.useState(o!==void 0?o:null),[m,g]=v.useState(null),[b,y]=v.useState(t),_=v.useRef(null),w=v.useRef(t);if(w.current=t,b!==t){y(t);const C=cS.get(t);c(C!==void 0?"ready":"idle"),f(C!==void 0?C:null),g(null)}return v.useEffect(()=>{if(!n||o!==void 0)return;const C=r.current;if(!C||typeof IntersectionObserver>"u")return;let E=!1;const k=t,T=new IntersectionObserver(R=>{for(const A of R){if(!A.isIntersecting)continue;if(T.disconnect(),E)return;const j=new AbortController;_.current=j,c("loading"),i(j.signal).then(I=>{E||w.current!==k||(cS.set(k,I),f(I),c("ready"))}).catch(I=>{E||j.signal.aborted||w.current!==k||(g(I instanceof Error?I:new Error(String(I))),c("error"))});break}},{rootMargin:s??"200px"});return T.observe(C),()=>{var R;E=!0,T.disconnect(),(R=_.current)==null||R.abort(),_.current=null}},[o,t,n,r,i,s]),v.useMemo(()=>({state:a,data:d,error:m}),[a,d,m])}function __e({source:e,onOpen:t,variant:n}){const r={id:e.id,kind:"file",displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??"",absolutePath:""},i=wh(r),s=cy(i,e.mimeType),o=e.size&&e.size>0?kh(e.size):null;return i==="image"?u.jsx("button",{type:"button",onClick:t,"aria-label":`Preview ${e.displayName}`,className:"overflow-hidden rounded-xl border border-border bg-background",children:u.jsx("img",{src:e.contentUrl,alt:e.altText??e.displayName,loading:"lazy",className:"max-h-64 w-auto max-w-full object-contain"})}):n==="expanded"&&(i==="text"||i==="code"||i==="markdown"||i==="json"||i==="table")?u.jsx(w_e,{source:e,onOpen:t,friendlyType:s,sizeLabel:o}):u.jsx(Fo,{attachment:r,onClick:t,meta:u.jsxs(u.Fragment,{children:[s,o?u.jsxs(u.Fragment,{children:[" · ",u.jsx("span",{className:"tabular-nums",children:o})]}):null]}),ariaLabel:`Preview ${e.displayName}, ${s}${o?`, ${o}`:""}`})}const w_e=function({source:t,onOpen:n,friendlyType:r,sizeLabel:i}){const s=v.useRef(null),o=t.contentUrl,a=v.useCallback(async f=>{const m=await YE(o,4096);if(f.aborted)throw new Error("aborted");return m.content.slice(0,200)},[o]),c=y_e({ref:s,enabled:!0,cacheKey:`snippet:${t.id}|${t.contentUrl}|${t.size??0}`,fetcher:a}),d=c.state==="ready"&&typeof c.data=="string"?c.data:"";return u.jsxs("button",{ref:s,type:"button",onClick:n,"aria-label":`Preview ${t.displayName}`,className:"flex w-full max-w-md flex-col items-start gap-1 rounded-xl border border-border bg-background p-3 text-left hover:bg-accent/40",children:[u.jsx("div",{className:"text-sm font-medium text-foreground",children:t.displayName}),u.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[r,i?` · ${i}`:""]}),d?u.jsx("pre",{className:"line-clamp-3 max-h-16 w-full whitespace-pre-wrap break-words text-[11px] text-muted-foreground",children:d}):null]})};function S_e({message:e}){const{status:t,revisedPrompt:n}=e.input,r=e.result,i=r==null?void 0:r.contentUrl,s=e.isError||t==="failed",[o,a]=v.useState(!1);if(!s&&!r&&t==="in_progress")return u.jsxs("div",{className:"flex flex-col gap-1 rounded-md border border-border/40 bg-muted/30 px-3 py-2 text-sm text-muted-foreground","data-testid":"image-generation-pending",children:[u.jsx("span",{children:"Generating image…"}),n?u.jsx("span",{className:"italic",children:n}):null]});if(s||!r||!i)return u.jsxs("div",{className:"flex flex-col gap-1 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm","data-testid":"image-generation-error",children:[u.jsx("span",{children:"Image generation failed."}),r!=null&&r.relativePath?u.jsx("span",{className:"text-muted-foreground",children:r.relativePath}):null]});const c={id:`image-gen-${e.toolId}`,contentUrl:i,displayName:r.fileName,fileName:r.fileName,relativePath:r.relativePath,mimeType:"image/png",origin:"image_generation",altText:n??void 0};return u.jsxs("figure",{className:"flex flex-col gap-2","data-testid":"image-generation",children:[u.jsx(__e,{source:c,onOpen:()=>a(!0),variant:"expanded"}),n?u.jsx("figcaption",{className:"text-xs text-muted-foreground italic",children:n}):null,u.jsx(Ch,{source:o?c:null,open:o,onOpenChange:a})]})}function C_e({message:e}){return u.jsx("div",{className:"flex items-center justify-end gap-2 text-sm text-muted-foreground",children:u.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:[u.jsx(pW,{className:"h-4 w-4 ml-1.5"}),u.jsx("em",{children:"Interrupted"})]})})}function ux({size:e=4}){return u.jsxs("svg",{className:"flex-1",viewBox:`0 0 100 ${e}`,preserveAspectRatio:"none",style:{height:`${e}px`},children:[u.jsx("pattern",{id:"zigzag",width:e,height:e,patternUnits:"userSpaceOnUse",children:u.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"}})}),u.jsx("rect",{width:"100%",height:e,fill:"url(#zigzag)",className:"text-muted-foreground/30"})]})}function k_e(){return u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx(ux,{}),u.jsx("span",{className:"text-[11px] tracking-widest text-muted-foreground uppercase flex-shrink-0",children:"Compacted"}),u.jsx(ux,{})]})}function E_e(){return u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx(ux,{}),u.jsx("span",{className:"text-[11px] tracking-widest text-muted-foreground uppercase flex-shrink-0",children:"Context Cleared"}),u.jsx(ux,{})]})}function N_e({message:e}){return u.jsx(Wa,{children:u.jsxs(f2,{expandedContent:u.jsx(by,{className:"my-4 text-xs",children:u.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none",children:u.jsx(Vo,{remarkPlugins:za,components:Ba,children:e.summary})})}),children:[u.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:u.jsx(q5,{className:"h-4.5 w-4.5 text-muted-foreground"})}),u.jsx(eu,{children:"Summarized"})]})})}const T_e={compacting:"Compacting..."};function R_e({message:e}){const t=T_e[e.status]||e.status;return u.jsxs(Wa,{className:"grid grid-cols-[auto_1fr] items-center gap-1.5 text-sm animate-pulse",children:[u.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:u.jsx(q5,{className:"h-4.5 w-4.5 text-muted-foreground"})}),u.jsx(eu,{className:"text-left transition-opacity duration-200 truncate",children:t})]})}const A_e={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"}},j_e={key:"other",singular:"tool call",plural:"tool calls"};function M_e(e){return A_e[e]??j_e}function L_e(e){const t=new Map,n=[];for(const r of e){const i=r.toolKind,s=M_e(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 I_e({messages:e,isLoading:t,localPath:n,expanded:r,onExpandedChange:i,chatId:s}){const o=v.useMemo(()=>L_e(e),[e]),c=e.some(d=>d.result===void 0)&&t;return u.jsx(Wa,{className:"w-full",children:u.jsxs("div",{className:"flex flex-col w-full",children:[u.jsx("button",{onClick:()=>i(!r),className:`group cursor-pointer grid grid-cols-[auto_1fr] items-center gap-1 text-sm ${!r&&!c?"hover:opacity-60 transition-opacity":""}`,children:u.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-center gap-1.5",children:[u.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:u.jsx(no,{className:`h-4.5 w-4.5 text-muted-icon transition-all duration-200 ${r?"rotate-90":""}`})}),u.jsx(eu,{className:"text-left",children:u.jsx(kp,{animate:c,children:o})})]})}),r&&u.jsxs("div",{className:"my-4 flex flex-col gap-3",children:[e.map(d=>u.jsx(cx,{message:d,isLoading:t,localPath:n,chatId:s},d.id)),e.length>5&&u.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:u.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-center gap-1.5",children:[u.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:u.jsx(no,{className:"h-4.5 w-4.5 text-muted-icon -rotate-90"})}),u.jsx(eu,{className:"text-left",children:"Collapse"})]})})]})]})})}function D_e(e){if(e!=="system")return e}function uS(e,t){const n=D_e(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 a;return((a=r.find(c=>c.type===o))==null?void 0:a.value)??"00"};let s=i("hour");return s==="24"&&(s="00"),`${i("day")}/${i("month")}/${i("year")} ${s}:${i("minute")}`}const P_e=/^(\d{2})\/(\d{2})\/(\d{4}) (\d{2}):(\d{2})$/;function uD(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 a;return Number(((a=n.find(c=>c.type===o))==null?void 0:a.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 O_e(e,t){const n=P_e.exec(e.trim());if(!n)return null;const[,r,i,s,o,a]=n,c=Number(r),d=Number(i),f=Number(s),m=Number(o),g=Number(a);if(d<1||d>12||c<1||c>31||m>23||g>59)return null;const b=Date.UTC(f,d-1,c,m,g),y=uD(t,b),_=b-y*6e4,w=uD(t,_);return _-(w-y)*6e4}const z_e={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"},B_e={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,a]=v.useState(null),[c,d]=v.useState(null),f=v.useCallback(async g=>{if(o)return;d(null);let b;try{b=g.onClick()}catch(y){console.error("[transcript-action-card] sync click threw",y),d(y instanceof Error?y.message:String(y));return}if(b instanceof Promise){a(g.id);try{await b}catch(y){console.error("[transcript-action-card] async click rejected",y),d(y instanceof Error?y.message:String(y))}finally{a(null)}}},[o]),m=o!==null;return u.jsxs("div",{"data-focus-fallback-ignore":!0,className:de("rounded-lg border px-4 py-3 text-sm space-y-2 transition-colors",z_e[i]),children:[u.jsx("div",{className:"flex items-start justify-between gap-3",children:u.jsxs("div",{className:"space-y-1 min-w-0 flex-1",children:[u.jsx("div",{className:"font-medium leading-tight",children:e}),t?u.jsx("div",{className:"text-muted-foreground text-xs leading-snug",children:t}):null]})}),n?u.jsx("div",{className:"text-xs leading-snug",children:n}):null,r?u.jsx("div",{className:"text-destructive text-xs leading-snug",children:r}):null,c?u.jsx("div",{className:"text-destructive text-xs leading-snug",role:"alert",children:c}):null,s.length>0?u.jsx("div",{className:"flex flex-wrap gap-2 pt-1",children:s.map(g=>{const b=o===g.id;return u.jsxs(De,{type:"button",size:"sm",variant:B_e[g.variant??"ghost"],disabled:g.disabled||m&&!b,onClick:()=>{f(g)},className:"gap-1.5",children:[b?u.jsx(_n,{className:"size-3.5 animate-spin"}):null,g.label]},g.id)})}):null]})}function F_e({schedule:e,onAccept:t,onReschedule:n,onCancel:r}){const[i,s]=v.useState(()=>uS(e.scheduledAt??e.resetAt,e.tz)),[o,a]=v.useState(!1),c=v.useMemo(()=>O_e(i,e.tz),[i,e.tz]),d=c!==null&&c>Date.now(),f=c===null?"Use format dd/mm/yyyy hh:mm":d?null:"Time must be in the future";if(e.state==="fired"){const y=uS(e.scheduledAt??e.resetAt,e.tz);return u.jsx(Ca,{title:`Auto-continued at ${y}`,tone:"success"})}if(e.state==="cancelled")return u.jsx(Ca,{title:"Auto-continue cancelled",tone:"muted"});if(e.state==="proposed"){const y=e.resetAt<=Date.now(),_=[{id:"schedule",label:"Schedule",variant:"primary",disabled:!d,onClick:()=>{c!==null&&t(c)}},{id:"dismiss",label:"Dismiss",variant:"ghost",onClick:()=>r()}];return u.jsx(Ca,{title:"Rate limit hit — schedule auto-continue?",description:y?"Reset time has passed — accept to continue now.":void 0,body:u.jsxs("div",{className:"space-y-1",children:[u.jsx(mn,{value:i,onChange:w=>s(w.target.value),placeholder:"dd/mm/yyyy hh:mm"}),f&&u.jsx("div",{className:"text-destructive text-xs",children:f})]}),actions:_})}const m=uS(e.scheduledAt??e.resetAt,e.tz),g=e.tz==="system"?"local":e.tz;if(!o){const y=[{id:"change",label:"Change time",variant:"secondary",onClick:()=>a(!0)},{id:"cancel",label:"Cancel",variant:"ghost",onClick:()=>r()}];return u.jsx(Ca,{title:`Auto-continue at ${m} (${g})`,actions:y})}const b=[{id:"save",label:"Save",variant:"primary",disabled:!d,onClick:()=>{c!==null&&(n(c),a(!1))}},{id:"back",label:"Back",variant:"ghost",onClick:()=>a(!1)}];return u.jsx(Ca,{title:`Auto-continue at ${m} (${g})`,body:u.jsxs("div",{className:"space-y-1",children:[u.jsx(mn,{value:i,onChange:y=>s(y.target.value),placeholder:"dd/mm/yyyy hh:mm"}),f&&u.jsx("div",{className:"text-destructive text-xs",children:f})]}),actions:b})}function $_e({toolRequestId:e,plan:t,onAnswer:n}){return u.jsxs("div",{className:"rounded-2xl border border-border overflow-hidden",children:[u.jsxs("div",{className:"font-medium text-sm p-3 px-4 bg-muted border-b border-border flex items-center justify-between",children:[u.jsx("span",{children:"Plan"}),u.jsx("span",{className:"text-xs text-muted-foreground",children:"Reconnected — awaiting your response"})]}),u.jsx("div",{className:"bg-background px-4 py-3",children:u.jsx("p",{className:"text-sm whitespace-pre-wrap",children:t})}),u.jsxs("div",{className:"flex justify-end gap-2 px-4 py-3 bg-background border-t border-border",children:[u.jsx(De,{size:"sm",variant:"outline",className:"rounded-full",onClick:()=>n(e,{kind:"deny",reason:"user_canceled"}),children:"Edit"}),u.jsx(De,{size:"sm",className:"rounded-full",onClick:()=>n(e,{kind:"answer",payload:{confirmed:!0}}),children:"Confirm"})]})]})}function H_e({toolRequestId:e,toolName:t,args:n,onAnswer:r}){const i=["command","path","url","pattern","query"].find(o=>typeof n[o]=="string"&&n[o].length>0),s=i?n[i]:JSON.stringify(n);return u.jsxs("div",{className:"rounded-2xl border border-border bg-background px-4 py-3 text-sm",children:[u.jsxs("div",{className:"flex items-baseline gap-2",children:[u.jsx("span",{className:"text-muted-foreground shrink-0",children:"Pending tool:"}),u.jsx("span",{className:"font-mono text-foreground",children:t})]}),s?u.jsx("pre",{className:"mt-1 max-h-32 overflow-auto whitespace-pre-wrap break-all font-mono text-xs text-muted-foreground",children:s}):null,u.jsxs("div",{className:"mt-3 flex items-center justify-end gap-2",children:[u.jsx(De,{variant:"ghost",size:"sm",onClick:()=>r(e,{kind:"deny",reason:"user_canceled"}),children:"Deny"}),u.jsx(De,{variant:"default",size:"sm",onClick:()=>r(e,{kind:"allow"}),children:"Allow"})]})]})}function U_e({entry:e,onAnswer:t}){const{toolRequestId:n,toolName:r,arguments:i}=e;if(r==="mcp__kanna__ask_user_question"){const o=(Array.isArray(i.questions)?i.questions:[]).map(a=>({id:typeof a.id=="string"?a.id:void 0,question:typeof a.question=="string"?a.question:typeof a.text=="string"?a.text:"",header:typeof a.header=="string"?a.header:void 0,options:Array.isArray(a.options)?a.options:void 0,multiSelect:typeof a.multiSelect=="boolean"?a.multiSelect:!1}));return u.jsx(QF,{questions:o,onSubmit:a=>t(n,{kind:"answer",payload:{questions:o,answers:a}}),onCancel:()=>t(n,{kind:"deny",reason:"user_canceled"})})}if(r==="mcp__kanna__exit_plan_mode"){const s=typeof i.plan=="string"?i.plan:"";return u.jsx($_e,{toolRequestId:n,plan:s,onAnswer:t})}return u.jsx(H_e,{toolRequestId:n,toolName:r,args:i,onAnswer:t})}const L2="mcp__kanna__delegate_subagent";function V_e(e){const t=[];for(const n of e){if(n.kind!=="tool"||n.toolKind!=="mcp_generic"||n.toolName!==L2)continue;const r=n.input.payload.subagent_id;typeof r=="string"&&t.push({toolId:n.toolId,subagentId:r})}return t}function W_e(e,t){const n=new Map;for(const a of t){const c=a.subagentId??"\0null",d=n.get(c)??[];d.push(a),n.set(c,d)}for(const a of n.values())a.sort((c,d)=>c.startedAt-d.startedAt||c.runId.localeCompare(d.runId));const r=new Map,i=new Set,s=new Map;for(const a of e){const c=n.get(a.subagentId);if(!c)continue;const d=s.get(a.subagentId)??0,f=c[d];f&&(r.set(a.toolId,f),i.add(f.runId),s.set(a.subagentId,d+1))}const o=t.filter(a=>!i.has(a.runId));return{matched:r,orphans:o}}function G_e(e,t){if(e.length===0)return;const n=e.map(i=>`${i.runId} (subagentId=${i.subagentId})`).join(", "),r=`Subagent run placement: ${e.length} orphan top-level run(s) with no delegate_subagent tool call: ${n}`;if(t)throw new Error(r);console.error(r)}const q_e=new Set(["AskUserQuestion","ExitPlanMode","TodoWrite",L2]);function dD(e){if(e.kind!=="tool")return!1;const t=e.toolName;return!q_e.has(t)}function K_e(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 Y_e(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],a=e[s+1];return K_e(i,{isFirstSystem:n===s,isFirstAccount:r===s,isLatestTodoWrite:i.id===t.TodoWrite,hideResult:(a==null?void 0:a.kind)==="context_cleared"||(o==null?void 0:o.kind)==="context_cleared",isFinalStatus:s===e.length-1})})}function X_e(e,t){const n=[];let r=0;for(;r<e.length;){const i=e[r],s=t[r];if(s!=null&&s.shouldRender&&dD(i)){const o=[i],a=r;for(r+=1;r<e.length;){const c=e[r],d=t[r];if(!(d!=null&&d.shouldRender)){r+=1;continue}if(!dD(c))break;o.push(c),r+=1}o.length>=2?n.push({type:"tool-group",messages:o,startIndex:a}):n.push({type:"single",message:i,index:a});continue}n.push({type:"single",message:i,index:r}),r+=1}return n}function hD(e){var n;return e.type==="single"?e.message.id:`tool-group:${((n=e.messages[0])==null?void 0:n.id)??e.startIndex}`}function dS(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>n===t[r])}function Q_e(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 Z_e(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>Q_e(n,t[r]))}function Xd(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)&&Z_e(e.attachments,t.attachments);case"system_init":return t.kind==="system_init"&&e.provider===t.provider&&e.model===t.model&&dS(e.tools,t.tools)&&dS(e.agents,t.agents)&&dS(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"api_error":return t.kind==="api_error"&&e.status===t.status&&e.text===t.text&&e.requestId===t.requestId;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 J_e(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&&Xd(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)=>Xd(n,t.messages[r])):!1}function ewe(e,t){const n=new Map;let r=e.length!==t.byId.size;const i=e.map((s,o)=>{const a=t.byId.get(s.id),c=a&&J_e(a,s)?a:s;return n.set(s.id,c),!r&&t.result[o]!==c&&(r=!0),c});return r?{byId:n,result:i}:t}function twe(e){const t=v.useRef({byId:new Map,result:[]}),n=v.useMemo(()=>ewe(e,t.current),[e]);return v.useLayoutEffect(()=>{t.current=n}),n.result}const r$=(e,t)=>{},nwe=v.memo(function({message:t,index:n,isLoading:r,localPath:i,isFirstSystem:s,isFirstAccount:o,isLatestAskUserQuestion:a,isLatestExitPlanMode:c,isLatestTodoWrite:d,hideResult:f,isFinalStatus:m,onAskUserQuestionSubmit:g,onExitPlanModeConfirm:b,onToolRequestAnswer:y=r$,schedules:_,onAutoContinueAccept:w,onAutoContinueReschedule:C,onAutoContinueCancel:E,chatId:k}){let T=null;if(t.kind==="user_prompt")T=u.jsx(i_e,{content:t.content,attachments:t.attachments,steered:t.steered,autoContinue:t.autoContinue},t.id);else switch(t.kind){case"auto_continue_prompt":{const R=_[t.scheduleId];if(!R){T=u.jsx("div",{className:"rounded border px-3 py-2 text-sm opacity-70",children:"Auto-continue expired"},t.id);break}T=u.jsx(F_e,{schedule:R,onAccept:A=>w(t.scheduleId,A),onReschedule:A=>C(t.scheduleId,A),onCancel:()=>E(t.scheduleId)},t.id);break}case"unknown":T=u.jsx(s_e,{json:t.json},t.id);break;case"system_init":T=s?u.jsx(u_e,{message:t,rawJson:t.debugRaw},t.id):null;break;case"account_info":T=o?u.jsx(f_e,{message:t},t.id):null;break;case"assistant_text":T=u.jsx(qF,{message:t},t.id);break;case"api_error":T=u.jsx(g_e,{message:t},t.id);break;case"tool":if(t.isError){T=u.jsx(cx,{message:t,isLoading:r,localPath:i,chatId:k},t.id);break}if(t.toolKind==="ask_user_question"){T=u.jsx(ZF,{message:t,onSubmit:g,isLatest:a},t.id);break}if(t.toolKind==="exit_plan_mode"){T=u.jsx(JF,{message:t,onConfirm:b,isLatest:c},t.id);break}if(t.toolKind==="todo_write"){T=d?u.jsx(b_e,{message:t},t.id):null;break}if(t.toolKind==="offer_download"&&t.result){T=u.jsx(x_e,{message:t},t.id);break}if(t.toolKind==="image_generation"){T=u.jsx(S_e,{message:t},t.id);break}T=u.jsx(cx,{message:t,isLoading:r,localPath:i,chatId:k},t.id);break;case"result":T=f?null:u.jsx(YF,{message:t},t.id);break;case"context_window_updated":T=null;break;case"interrupted":T=u.jsx(C_e,{message:t},t.id);break;case"compact_boundary":T=u.jsx(k_e,{},t.id);break;case"context_cleared":T=u.jsx(E_e,{},t.id);break;case"compact_summary":T=u.jsx(N_e,{message:t},t.id);break;case"status":T=m?u.jsx(R_e,{message:t},t.id):null;break;case"pending_tool_request":T=u.jsx(U_e,{entry:t,onAnswer:y},t.id);break}return T?u.jsx("div",{id:`msg-${t.id}`,className:"group relative","data-index":n,[Tb]:"",children:T}):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&&e.chatId===t.chatId&&Xd(e.message,t.message)),rwe=v.memo(function({id:t,messages:n,isLoading:r,localPath:i,expanded:s,onExpandedChange:o,chatId:a}){return u.jsx("div",{className:"group relative",[Tb]:"",children:u.jsx(I_e,{messages:n,isLoading:r,localPath:i,expanded:s,onExpandedChange:c=>o(t,c),chatId:a})})},(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.chatId===t.chatId&&e.messages.length===t.messages.length&&e.messages.every((n,r)=>Xd(n,t.messages[r])));function i$(e,{isLoading:t,localPath:n,latestToolIds:r}){const i=Y_e(e,r),s=X_e(e,i),o=[];for(const a of s){if(a.type==="tool-group"){o.push({kind:"tool-group",id:hD(a),startIndex:a.startIndex,messages:a.messages,isLoading:t&&a.messages.some(f=>f.kind==="tool"&&f.result===void 0),localPath:n});continue}const c=i[a.index];if(!c)continue;const d={kind:"single",id:hD(a),message:a.message,index:a.index,isLoading:a.message.kind==="tool"&&a.message.result===void 0&&t,localPath:n,isFirstSystem:c.isFirstSystem,isFirstAccount:c.isFirstAccount,isLatestAskUserQuestion:a.message.id===r.AskUserQuestion,isLatestExitPlanMode:a.message.id===r.ExitPlanMode,isLatestTodoWrite:c.isLatestTodoWrite,hideResult:c.hideResult,isFinalStatus:c.isFinalStatus};c.shouldRender&&o.push(d)}return o}const iwe={};function s$(e,t,n,r,i,s,o){const a=n.get(e.runId)??[];return u.jsxs(yn.Fragment,{children:[u.jsx(e$,{run:e,indentDepth:t,localPath:r,onSubagentAskUserQuestionSubmit:i,onSubagentExitPlanModeSubmit:s,onCancelSubagentRun:o}),a.map(c=>s$(c,t+1,n,r,i,s,o))]},e.runId)}const o$=v.memo(function({row:t,toolGroupExpanded:n,onToolGroupExpandedChange:r,onAskUserQuestionSubmit:i,onExitPlanModeConfirm:s,onToolRequestAnswer:o,schedules:a,onAutoContinueAccept:c,onAutoContinueReschedule:d,onAutoContinueCancel:f,chatId:m}){return t.kind==="tool-group"?u.jsx(rwe,{id:t.id,startIndex:t.startIndex,messages:t.messages,isLoading:t.isLoading,localPath:t.localPath,expanded:n??!1,onExpandedChange:r,chatId:m}):u.jsx(nwe,{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:a,onAutoContinueAccept:c,onAutoContinueReschedule:d,onAutoContinueCancel:f,chatId:m})},(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.chatId!==t.chatId||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)=>Xd(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&&Xd(e.row.message,t.row.message):!1}),a$={},swe=(e,t)=>{},owe=(e,t)=>{},awe=e=>{};function lwe({messages:e,isLoading:t,localPath:n,latestToolIds:r,onOpenLocalLink:i,chatId:s,onAskUserQuestionSubmit:o,onExitPlanModeConfirm:a,onToolRequestAnswer:c=r$,schedules:d=a$,onAutoContinueAccept:f=swe,onAutoContinueReschedule:m=owe,onAutoContinueCancel:g=awe,onTunnelAccept:b,onTunnelStop:y,onTunnelRetry:_,subagentRuns:w=iwe,onSubagentAskUserQuestionSubmit:C,onSubagentExitPlanModeSubmit:E,onCancelSubagentRun:k}){const[T,R]=v.useState({}),A=v.useMemo(()=>i$(e,{isLoading:t,localPath:n,latestToolIds:r}),[t,r,n,e]),{matchedRunsByToolId:j,childrenByParentRunId:I}=v.useMemo(()=>{const M=[],D=new Map;for(const $ of Object.values(w))if($.parentRunId===null)M.push($);else{const B=D.get($.parentRunId)??[];B.push($),D.set($.parentRunId,B)}const z=($,B)=>$.startedAt-B.startedAt||$.runId.localeCompare(B.runId);for(const $ of D.values())$.sort(z);const{matched:P,orphans:F}=W_e(V_e(e),M);return G_e(F,!1),{matchedRunsByToolId:P,childrenByParentRunId:D}},[w,e]),U=v.useCallback((M,D)=>{R(z=>z[M]===D?z:{...z,[M]:D})},[]);return u.jsx(sF,{onOpenLocalLink:i,children:A.map(M=>{const D=M.kind==="single"&&M.message.kind==="tool"&&M.message.toolName===L2?M.message.toolId:null,z=D?j.get(D):void 0;return u.jsxs("div",{className:"mx-auto max-w-[800px] pb-5",children:[u.jsx(o$,{row:M,toolGroupExpanded:M.kind==="tool-group"?T[M.id]??!1:void 0,onToolGroupExpandedChange:U,onAskUserQuestionSubmit:o,onExitPlanModeConfirm:a,onToolRequestAnswer:c,schedules:d,onAutoContinueAccept:f,onAutoContinueReschedule:m,onAutoContinueCancel:g,chatId:s}),z?s$(z,0,I,n??"",C,E,k):null]},M.id)})})}v.memo(lwe);const cwe=Object.freeze([]),hS=ss((e,t)=>({sharesByChat:{},listForChat(n){return t().sharesByChat[n]??cwe},setShares(n,r){e(i=>({sharesByChat:{...i.sharesByChat,[n]:r}}))},addShare(n,r){e(i=>({sharesByChat:{...i.sharesByChat,[n]:[...i.sharesByChat[n]??[],r]}}))},removeShare(n,r){e(i=>({sharesByChat:{...i.sharesByChat,[n]:(i.sharesByChat[n]??[]).filter(s=>s.tokenId!==r)}}))}})),uwe=/^\/(\S*)$/;function l$(e){return e.replace(/^\/+/,"")}function dwe(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 a=o[0].length,c=i.slice(0,i.length-a),d=l$(t.name),f=t.argumentHint?`/${d} `:`/${d}`,m=`${c}${f}${s}`,g=c.length+f.length;return{value:m,caret:g}}function hwe(e,t){if(t<=0)return{open:!1,query:""};const n=e.slice(0,t),r=uwe.exec(n);return r?{open:!0,query:r[1]??""}:{open:!1,query:""}}function fwe(e,t){const n=(o,a)=>o.name.localeCompare(a.name);if(t==="")return[...e].sort(n);const r=t.toLowerCase(),i=[],s=[];for(const o of e){const a=o.name.toLowerCase();a.startsWith(r)?i.push(o):a.includes(r)&&s.push(o)}return[...i.sort(n),...s.sort(n)]}const mwe=4,fD=80;function pwe(e){return e.length<=fD?e:`${e.slice(0,fD-1).trimEnd()}…`}function gwe({items:e,activeIndex:t,loading:n,onSelect:r,onHoverIndex:i}){const s=v.useRef(null);return v.useEffect(()=>{var a;const o=(a=s.current)==null?void 0:a.children.item(t);o==null||o.scrollIntoView({block:"nearest"})},[t]),e.length===0&&n?u.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:mwe}).map((o,a)=>u.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:[u.jsx("span",{className:"h-3 w-28 rounded bg-muted animate-pulse"}),u.jsx("span",{className:"hidden h-3 w-16 rounded bg-muted/70 animate-pulse sm:inline-block"}),u.jsx("span",{className:"h-3 w-40 max-w-full rounded bg-muted/60 animate-pulse sm:ml-auto"})]},a))}):e.length===0?u.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"}):u.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,a)=>u.jsxs("li",{role:"option","aria-selected":a===t,onMouseDown:c=>{c.preventDefault(),r(o)},onMouseEnter:()=>i(a),className:de("flex flex-col gap-0.5 px-3 py-1.5 cursor-pointer text-sm sm:flex-row sm:items-center sm:gap-3",a===t&&"bg-accent text-accent-foreground"),children:[u.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[u.jsxs("span",{className:"font-mono break-all sm:whitespace-nowrap sm:break-normal",children:["/",l$(o.name)]}),o.argumentHint?u.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground whitespace-nowrap",children:o.argumentHint}):null]}),o.description?u.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground sm:text-right",children:pwe(o.description)}):null]},o.name))})}const vwe=4;function bwe({items:e,activeIndex:t,loading:n,onSelect:r,onHoverIndex:i}){const s=v.useRef(null);return v.useEffect(()=>{var a;const o=(a=s.current)==null?void 0:a.children.item(t);o==null||o.scrollIntoView({block:"nearest"})},[t]),e.length===0&&n?u.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:vwe}).map((o,a)=>u.jsxs("li",{className:"flex items-center gap-2 px-3 py-1.5","data-testid":"mention-picker-skeleton-row",children:[u.jsx("span",{className:"h-3.5 w-3.5 rounded bg-muted animate-pulse"}),u.jsx("span",{className:"h-3 w-40 max-w-full rounded bg-muted animate-pulse"})]},a))}):e.length===0?u.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"}):u.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,a)=>{const c=o.kind==="agent",d=o.kind==="path"?o.path:null,f=(d==null?void 0:d.kind)==="dir"?U5:gk;return u.jsxs("li",{role:"option","aria-selected":a===t,onMouseDown:m=>{m.preventDefault(),r(o)},onMouseEnter:()=>i(a),className:de("flex items-center gap-2 px-3 py-1.5 cursor-pointer text-sm",a===t&&"bg-accent text-accent-foreground"),children:[u.jsx(XV,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),c?u.jsxs(u.Fragment,{children:[u.jsx(ih,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),u.jsxs("span",{className:"font-mono truncate",children:["agent/",o.subagent.name]}),o.subagent.description?u.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",children:o.subagent.description}):null]}):d?u.jsxs(u.Fragment,{children:[u.jsx(f,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),u.jsx("span",{className:"font-mono truncate",children:d.path})]}):null]},c?`agent:${o.subagent.id}`:`path:${d==null?void 0:d.kind}:${d==null?void 0:d.path}`)})})}const jv={open:!1,query:"",tokenStart:-1};function xwe(e,t){if(t<=0)return jv;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===`