@cuongtran001/kanna 0.92.0 → 0.92.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 (59) hide show
  1. package/dist/client/assets/{arc-fKdt_LUe.js → arc-CljOBLld.js} +1 -1
  2. package/dist/client/assets/{architectureDiagram-3BPJPVTR-zH7VfSA0.js → architectureDiagram-3BPJPVTR-Ch9aZ4K-.js} +1 -1
  3. package/dist/client/assets/{blockDiagram-GPEHLZMM-DXv27B72.js → blockDiagram-GPEHLZMM-C_fIhfj-.js} +1 -1
  4. package/dist/client/assets/{c4Diagram-AAUBKEIU-Bu5rPLVO.js → c4Diagram-AAUBKEIU-B_TTpwcH.js} +1 -1
  5. package/dist/client/assets/channel-BzcqXGIm.js +1 -0
  6. package/dist/client/assets/{chunk-2J33WTMH-CKI33soh.js → chunk-2J33WTMH-CxYImJnB.js} +1 -1
  7. package/dist/client/assets/{chunk-4BX2VUAB-By2ip4Oy.js → chunk-4BX2VUAB-wC294VeL.js} +1 -1
  8. package/dist/client/assets/{chunk-55IACEB6-BbtjUPfZ.js → chunk-55IACEB6-BsOLe445.js} +1 -1
  9. package/dist/client/assets/{chunk-727SXJPM-BA0OqPut.js → chunk-727SXJPM-XQzAUDCh.js} +1 -1
  10. package/dist/client/assets/{chunk-AQP2D5EJ-CB-CgR4J.js → chunk-AQP2D5EJ-CLgfb-9f.js} +1 -1
  11. package/dist/client/assets/{chunk-FMBD7UC4-DSv8R528.js → chunk-FMBD7UC4-BhgT7tjw.js} +1 -1
  12. package/dist/client/assets/{chunk-ND2GUHAM-BcH08YX_.js → chunk-ND2GUHAM-BM10-7Xo.js} +1 -1
  13. package/dist/client/assets/{chunk-QZHKN3VN-D0KjJSsS.js → chunk-QZHKN3VN-BKZ6UfKr.js} +1 -1
  14. package/dist/client/assets/classDiagram-4FO5ZUOK-8sNSlepd.js +1 -0
  15. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-8sNSlepd.js +1 -0
  16. package/dist/client/assets/{cose-bilkent-S5V4N54A-CcMAhXn0.js → cose-bilkent-S5V4N54A-alWsyEJv.js} +1 -1
  17. package/dist/client/assets/{dagre-BM42HDAG-aBoF4N7B.js → dagre-BM42HDAG-DJ4mfrnA.js} +1 -1
  18. package/dist/client/assets/{diagram-2AECGRRQ-lUESGKVI.js → diagram-2AECGRRQ-DeRW_yc2.js} +1 -1
  19. package/dist/client/assets/{diagram-5GNKFQAL-Cqi6DnfF.js → diagram-5GNKFQAL-V0x_Bc6A.js} +1 -1
  20. package/dist/client/assets/{diagram-KO2AKTUF-CX5CrfKz.js → diagram-KO2AKTUF-qKMmMAlp.js} +1 -1
  21. package/dist/client/assets/{diagram-LMA3HP47-BWR-Ui6I.js → diagram-LMA3HP47-CeYF7CEz.js} +1 -1
  22. package/dist/client/assets/{diagram-OG6HWLK6-DetKD-mW.js → diagram-OG6HWLK6-BdJxAdn0.js} +1 -1
  23. package/dist/client/assets/{erDiagram-TEJ5UH35-BT6h7sNY.js → erDiagram-TEJ5UH35-ByVizcWQ.js} +1 -1
  24. package/dist/client/assets/{flowDiagram-I6XJVG4X-gJV89Sot.js → flowDiagram-I6XJVG4X-BDu00bzp.js} +1 -1
  25. package/dist/client/assets/{ganttDiagram-6RSMTGT7-BCXElcXB.js → ganttDiagram-6RSMTGT7-BH01gFTU.js} +1 -1
  26. package/dist/client/assets/{gitGraphDiagram-PVQCEYII-BglqCErN.js → gitGraphDiagram-PVQCEYII-6geet3k9.js} +1 -1
  27. package/dist/client/assets/{index-CWaqoEe9.js → index-CMqCpZAN.js} +1 -1
  28. package/dist/client/assets/{index-82uEJPIW.js → index-CaXHTzrb.js} +2 -2
  29. package/dist/client/assets/{infoDiagram-5YYISTIA-O1LldAKl.js → infoDiagram-5YYISTIA-k1wxP-1T.js} +1 -1
  30. package/dist/client/assets/{ishikawaDiagram-YF4QCWOH-B8GFHp68.js → ishikawaDiagram-YF4QCWOH-UUR4Db74.js} +1 -1
  31. package/dist/client/assets/{journeyDiagram-JHISSGLW-Bg_DCf3D.js → journeyDiagram-JHISSGLW-BClA9u-R.js} +1 -1
  32. package/dist/client/assets/{kanban-definition-UN3LZRKU-qiznSapx.js → kanban-definition-UN3LZRKU-DsiWjcCZ.js} +1 -1
  33. package/dist/client/assets/{linear-D6rKm-ZW.js → linear-Uac35MKo.js} +1 -1
  34. package/dist/client/assets/{mermaid.core-iiPRaxhL.js → mermaid.core-DR7L5nHt.js} +4 -4
  35. package/dist/client/assets/{mindmap-definition-RKZ34NQL-Cut0I9i-.js → mindmap-definition-RKZ34NQL-D2jKrF3G.js} +1 -1
  36. package/dist/client/assets/{pieDiagram-4H26LBE5-Cna5TkTG.js → pieDiagram-4H26LBE5-vL_eRYpm.js} +1 -1
  37. package/dist/client/assets/{quadrantDiagram-W4KKPZXB-BSAgANMx.js → quadrantDiagram-W4KKPZXB-DwVv47ww.js} +1 -1
  38. package/dist/client/assets/{requirementDiagram-4Y6WPE33-C8ptXML_.js → requirementDiagram-4Y6WPE33-iTJ6k6cP.js} +1 -1
  39. package/dist/client/assets/{sankeyDiagram-5OEKKPKP-Ce5aL3LN.js → sankeyDiagram-5OEKKPKP-u2sT616S.js} +1 -1
  40. package/dist/client/assets/{sequenceDiagram-3UESZ5HK-Bmm9wa3A.js → sequenceDiagram-3UESZ5HK-D387A5A4.js} +1 -1
  41. package/dist/client/assets/{stateDiagram-AJRCARHV-Dg_RM53J.js → stateDiagram-AJRCARHV-4IfpBZz4.js} +1 -1
  42. package/dist/client/assets/stateDiagram-v2-BHNVJYJU-CaCvrgJm.js +1 -0
  43. package/dist/client/assets/{timeline-definition-PNZ67QCA-DhgweRu1.js → timeline-definition-PNZ67QCA-gldfMeIF.js} +1 -1
  44. package/dist/client/assets/{vennDiagram-CIIHVFJN-BiMuig9e.js → vennDiagram-CIIHVFJN-C0KeJaHX.js} +1 -1
  45. package/dist/client/assets/{wardley-L42UT6IY-B3QxIwk9.js → wardley-L42UT6IY-BSjsdQMQ.js} +1 -1
  46. package/dist/client/assets/{wardleyDiagram-YWT4CUSO-CAvoSonb.js → wardleyDiagram-YWT4CUSO-DkXeRRTh.js} +1 -1
  47. package/dist/client/assets/{xychartDiagram-2RQKCTM6-CxswFTkb.js → xychartDiagram-2RQKCTM6-DOyRL1ic.js} +1 -1
  48. package/dist/client/index.html +1 -1
  49. package/package.json +1 -1
  50. package/src/server/claude-pty/jsonl-path.test.ts +6 -6
  51. package/src/server/claude-pty/jsonl-to-event.test.ts +238 -0
  52. package/src/server/claude-pty/jsonl-to-event.ts +101 -5
  53. package/src/server/claude-pty/smoke-test.ts +9 -1
  54. package/src/server/claude-pty/tui-source.adapter.test.ts +33 -0
  55. package/src/server/claude-pty/tui-source.adapter.ts +25 -5
  56. package/dist/client/assets/channel-BaysENFN.js +0 -1
  57. package/dist/client/assets/classDiagram-4FO5ZUOK-BhEeai6q.js +0 -1
  58. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-BhEeai6q.js +0 -1
  59. package/dist/client/assets/stateDiagram-v2-BHNVJYJU-BQpD6JRb.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(Rs,{className:"max-w-2xl",children:[u.jsxs(oo,{children:["Permissions — ",t]}),u.jsxs(Uo,{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(ji,{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(Yl,{className:"justify-between",children:[u.jsx(Ie,{variant:"ghost",onClick:k,children:"Reset to defaults"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ie,{variant:"ghost",onClick:s,children:"Cancel"}),u.jsx(Ie,{onClick:E,children:"Apply"})]})]})]})}),u.jsx(so,{open:g,onOpenChange:T=>{T||(b(!1),_(null))},children:u.jsxs(Rs,{className:"max-w-md",children:[u.jsx(oo,{children:"Enable auto-allow for this chat?"}),u.jsxs(Uo,{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(Yl,{className:"justify-end gap-2",children:[u.jsx(Ie,{variant:"ghost",onClick:()=>{b(!1),_(null)},children:"Cancel"}),u.jsx(Ie,{variant:"destructive",onClick:()=>{y&&a(y),b(!1),_(null)},children:"Enable auto-allow"})]})]})})]})}const CZ={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:[]},un=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}));un.displayName="Input";const z3=v.createContext(null);function kZ({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(z3.Provider,{value:g,children:[e,u.jsx(so,{open:t!==null,onOpenChange:b=>{b||!t||a()},children:u.jsx(Rs,{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(Uo,{className:"space-y-4",children:[u.jsx(oo,{children:t.options.title}),t.options.description?u.jsx(op,{children:t.options.description}):null,t.kind==="prompt"?u.jsx(un,{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(Yl,{children:[u.jsx(Ie,{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(Ie,{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 up(){const e=v.useContext(z3);if(!e)throw new Error("useAppDialog must be used within AppDialogProvider");return e}const Wk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("bg-card text-card-foreground",e),...t}));Wk.displayName="Card";const Gk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("flex flex-col space-y-1.5 p-2",e),...t}));Gk.displayName="CardHeader";const B3=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:de("text-2xl font-semibold leading-none tracking-tight",e),...t}));B3.displayName="CardTitle";const F3=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:de("text-sm text-muted-foreground",e),...t}));F3.displayName="CardDescription";const qk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("p-6 pt-0",e),...t}));qk.displayName="CardContent";const EZ=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("flex items-center p-6 pt-0",e),...t}));EZ.displayName="CardFooter";const NZ={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 TZ({variant:e,children:t,dot:n=!0,className:r}){const i=NZ[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 RZ="modulepreload",AZ=function(e){return"/"+e},qj={},X=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=AZ(d),d in qj)return;qj[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":RZ,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)})},jZ=v.lazy(()=>X(()=>import("./index-CWaqoEe9.js"),[]).then(e=>({default:e.Toaster})));function MZ(){return u.jsx(v.Suspense,{fallback:null,children:u.jsx(jZ,{position:"bottom-right",theme:"system",closeButton:!0,duration:6e3})})}const LZ="0.92.0",IZ={version:LZ},Xn="Kanna",Kj="kanna",DZ=".kanna",PZ=".kanna-dev",OZ="KANNA_RUNTIME_PROFILE",Kk=`kanna/${IZ.version}`,zZ="[kanna]",BZ=`~/${Xn}`;function Vx(){var t;return(t=globalThis.process)==null?void 0:t.env}function FZ(e=Vx()){var t;return((t=e==null?void 0:e[OZ])==null?void 0:t.trim().toLowerCase())==="dev"?"dev":"prod"}function $Z(e=Vx()){return FZ(e)==="dev"?PZ:DZ}function HZ(e=Vx()){return`~/${$Z(e)}`}function UZ(e=Vx()){return`${HZ(e)}/keybindings.json`}function Yg(e){return e?`${Kj} ${e}`:Kj}const Yj=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},VZ=(e=>e?Yj(e):Yj),WZ=e=>e;function GZ(e,t=WZ){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 Xj=e=>{const t=VZ(e),n=r=>GZ(t,r);return Object.assign(n,t),n},is=(e=>e?Xj(e):Xj),$3="always",H3="funk",qZ=[{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 KZ(e){switch(e){case"never":case"unfocused":case"always":return e;default:return $3}}function YZ(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 H3}}const Bc=is()(e=>({chatSoundPreference:$3,chatSoundId:H3,setChatSoundPreference:t=>e({chatSoundPreference:KZ(t)}),setChatSoundId:t=>e({chatSoundId:YZ(t)})})),XZ={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 QZ(e=document){return e.visibilityState!=="visible"||!e.hasFocus()}function ZZ(e){const t=new Audio(XZ[e]);return t.preload="auto",t.play()}async function e1(e,t){if(t<=0)return;const n=Array.from({length:t},(r,i)=>new Promise(s=>{window.setTimeout(()=>{ZZ(e).catch(()=>{}).finally(()=>s())},i*90)}));await Promise.all(n)}function JZ(e,t=document){return e==="never"?!1:e==="always"?!0:QZ(t)}function eJ(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 tJ(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 t1(e){return e.split(/[\s_-]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}const nJ=[/^(?:\/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 U3(e){const t=e.trim();for(const n of nJ){const r=t.match(n);if(!r)continue;const i=(r[2]??r[1]??"").trim();if(i)return i}return t}function Yk(e){return e.split("/").pop()||e}const rJ=1440*6e4;function iJ(e,t){if(e===void 0)return null;const n=Math.max(0,t-e),r=6e4,i=60*r,s=rJ,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 sJ(e){return e.lastMessageAt??e._creationTime}const Xk=1e3,nb=60*Xk,kd=60*nb,Q_=24*kd;function Ys(e){const t=Math.max(0,e);if(t<nb)return`${Math.floor(t/Xk)}s`;if(t<kd)return`${Math.floor(t/nb)}m`;if(t<Q_){const i=Math.floor(t/kd),s=Math.floor(t%kd/nb);return s===0?`${i}h`:`${i}h ${s}m`}const n=Math.floor(t/Q_),r=Math.floor(t%Q_/kd);return r===0?`${n}d`:`${n}d ${r}h`}function n1(e){const t=Math.max(0,e);if(t>=kd)return Ys(t);const n=Math.floor(t/Xk),r=Math.floor(n/60),i=n%60;return`${r}:${i.toString().padStart(2,"0")}`}function r1(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 Zj(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 Jj(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 Qk(e){const t=e+"CollectionProvider",[n,r]=Va(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=Yc(a),d=yn.forwardRef((_,w)=>{const{scope:C,children:E}=_,k=s(a,C),T=xn(w,k.collectionRef);return u.jsx(c,{ref:T,children:E})});d.displayName=a;const f=e+"CollectionItemSlot",m="data-radix-collection-item",g=Yc(f),b=yn.forwardRef((_,w)=>{const{scope:C,children:E,...k}=_,T=yn.useRef(null),R=xn(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 oJ=v.createContext(void 0);function Zk(e){const t=v.useContext(oJ);return e||t||"ltr"}var Z_="rovingFocusGroup.onEntryFocus",aJ={bubbles:!1,cancelable:!0},dp="RovingFocusGroup",[i1,V3,lJ]=Qk(dp),[cJ,W3]=Va(dp,[lJ]),[uJ,dJ]=cJ(dp),G3=v.forwardRef((e,t)=>u.jsx(i1.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(i1.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(hJ,{...e,ref:t})})}));G3.displayName=dp;var hJ=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=xn(t,g),y=Zk(s),[_,w]=Ud({prop:o,defaultProp:a??null,onChange:c,caller:dp}),[C,E]=v.useState(!1),k=io(d),T=V3(n),R=v.useRef(!1),[A,j]=v.useState(0);return v.useEffect(()=>{const L=g.current;if(L)return L.addEventListener(Z_,k),()=>L.removeEventListener(Z_,k)},[k]),u.jsx(uJ,{scope:n,orientation:r,dir:y,loop:i,currentTabStopId:_,onItemFocus:v.useCallback(L=>w(L),[w]),onItemShiftTab:v.useCallback(()=>E(!0),[]),onFocusableItemAdd:v.useCallback(()=>j(L=>L+1),[]),onFocusableItemRemove:v.useCallback(()=>j(L=>L-1),[]),children:u.jsx(tn.div,{tabIndex:C||A===0?-1:0,"data-orientation":r,...m,ref:b,style:{outline:"none",...e.style},onMouseDown:rt(e.onMouseDown,()=>{R.current=!0}),onFocus:rt(e.onFocus,L=>{const H=!R.current;if(L.target===L.currentTarget&&H&&!C){const M=new CustomEvent(Z_,aJ);if(L.currentTarget.dispatchEvent(M),!M.defaultPrevented){const D=T().filter(B=>B.focusable),z=D.find(B=>B.active),O=D.find(B=>B.id===_),$=[z,O,...D].filter(Boolean).map(B=>B.ref.current);Y3($,f)}}R.current=!1}),onBlur:rt(e.onBlur,()=>E(!1))})})}),q3="RovingFocusGroupItem",K3=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...a}=e,c=ja(),d=s||c,f=dJ(q3,n),m=f.currentTabStopId===d,g=V3(n),{onFocusableItemAdd:b,onFocusableItemRemove:y,currentTabStopId:_}=f;return v.useEffect(()=>{if(r)return b(),()=>y()},[r,b,y]),u.jsx(i1.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:u.jsx(tn.span,{tabIndex:m?0:-1,"data-orientation":f.orientation,...a,ref:t,onMouseDown:rt(e.onMouseDown,w=>{r?f.onItemFocus(d):w.preventDefault()}),onFocus:rt(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:rt(e.onKeyDown,w=>{if(w.key==="Tab"&&w.shiftKey){f.onItemShiftTab();return}if(w.target!==w.currentTarget)return;const C=pJ(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?gJ(k,T+1):k.slice(T+1)}setTimeout(()=>Y3(k))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:_!=null}):o})})});K3.displayName=q3;var fJ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function mJ(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function pJ(e,t,n){const r=mJ(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return fJ[r]}function Y3(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function gJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var vJ=G3,bJ=K3,s1=["Enter"," "],xJ=["ArrowDown","PageUp","Home"],X3=["ArrowUp","PageDown","End"],yJ=[...xJ,...X3],_J={ltr:[...s1,"ArrowRight"],rtl:[...s1,"ArrowLeft"]},wJ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},hp="Menu",[wm,SJ,CJ]=Qk(hp),[mu,Q3]=Va(hp,[CJ,ec,W3]),Wx=ec(),Z3=W3(),[kJ,pu]=mu(hp),[EJ,fp]=mu(hp),J3=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,a=Wx(t),[c,d]=v.useState(null),f=v.useRef(!1),m=io(s),g=Zk(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(Bx,{...a,children:u.jsx(kJ,{scope:t,open:n,onOpenChange:m,content:c,onContentChange:d,children:u.jsx(EJ,{scope:t,onClose:v.useCallback(()=>m(!1),[m]),isUsingKeyboardRef:f,dir:g,modal:o,children:r})})})};J3.displayName=hp;var NJ="MenuAnchor",Jk=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Wx(n);return u.jsx(lp,{...i,...r,ref:t})});Jk.displayName=NJ;var eE="MenuPortal",[TJ,e4]=mu(eE,{forceMount:void 0}),t4=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=pu(eE,t);return u.jsx(TJ,{scope:t,forceMount:n,children:u.jsx(Is,{present:n||s.open,children:u.jsx(fh,{asChild:!0,container:i,children:r})})})};t4.displayName=eE;var Es="MenuContent",[RJ,tE]=mu(Es),n4=v.forwardRef((e,t)=>{const n=e4(Es,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=pu(Es,e.__scopeMenu),o=fp(Es,e.__scopeMenu);return u.jsx(wm.Provider,{scope:e.__scopeMenu,children:u.jsx(Is,{present:r||s.open,children:u.jsx(wm.Slot,{scope:e.__scopeMenu,children:o.modal?u.jsx(AJ,{...i,ref:t}):u.jsx(jJ,{...i,ref:t})})})})}),AJ=v.forwardRef((e,t)=>{const n=pu(Es,e.__scopeMenu),r=v.useRef(null),i=xn(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Lx(s)},[]),u.jsx(nE,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:rt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),jJ=v.forwardRef((e,t)=>{const n=pu(Es,e.__scopeMenu);return u.jsx(nE,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),MJ=Yc("MenuContent.ScrollLock"),nE=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=pu(Es,n),C=fp(Es,n),E=Wx(n),k=Z3(n),T=SJ(n),[R,A]=v.useState(null),j=v.useRef(null),L=xn(t,j,w.onContentChange),H=v.useRef(0),M=v.useRef(""),D=v.useRef(0),z=v.useRef(null),O=v.useRef("right"),F=v.useRef(0),$=y?sp:v.Fragment,B=y?{as:MJ,allowPinchZoom:!0}:void 0,U=te=>{var ne,ie;const P=M.current+te,Y=T().filter(le=>!le.disabled),ee=document.activeElement,V=(ne=Y.find(le=>le.ref.current===ee))==null?void 0:ne.textValue,ue=Y.map(le=>le.textValue),ge=VJ(ue,P,V),Z=(ie=Y.find(le=>le.textValue===ge))==null?void 0:ie.ref.current;(function le(oe){M.current=oe,window.clearTimeout(H.current),oe!==""&&(H.current=window.setTimeout(()=>le(""),1e3))})(P),Z&&setTimeout(()=>Z.focus())};v.useEffect(()=>()=>window.clearTimeout(H.current),[]),jx();const G=v.useCallback(te=>{var Y,ee;return O.current===((Y=z.current)==null?void 0:Y.side)&&GJ(te,(ee=z.current)==null?void 0:ee.area)},[]);return u.jsx(RJ,{scope:n,searchRef:M,onItemEnter:v.useCallback(te=>{G(te)&&te.preventDefault()},[G]),onItemLeave:v.useCallback(te=>{var P;G(te)||((P=j.current)==null||P.focus(),A(null))},[G]),onTriggerLeave:v.useCallback(te=>{G(te)&&te.preventDefault()},[G]),pointerGraceTimerRef:D,onPointerGraceIntentChange:v.useCallback(te=>{z.current=te},[]),children:u.jsx($,{...B,children:u.jsx(ip,{asChild:!0,trapped:i,onMountAutoFocus:rt(s,te=>{var P;te.preventDefault(),(P=j.current)==null||P.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:u.jsx(hh,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:g,onDismiss:b,children:u.jsx(vJ,{asChild:!0,...k,dir:C.dir,orientation:"vertical",loop:r,currentTabStopId:R,onCurrentTabStopIdChange:A,onEntryFocus:rt(c,te=>{C.isUsingKeyboardRef.current||te.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(Fx,{role:"menu","aria-orientation":"vertical","data-state":b4(w.open),"data-radix-menu-content":"",dir:C.dir,...E,..._,ref:L,style:{outline:"none",..._.style},onKeyDown:rt(_.onKeyDown,te=>{const Y=te.target.closest("[data-radix-menu-content]")===te.currentTarget,ee=te.ctrlKey||te.altKey||te.metaKey,V=te.key.length===1;Y&&(te.key==="Tab"&&te.preventDefault(),!ee&&V&&U(te.key));const ue=j.current;if(te.target!==ue||!yJ.includes(te.key))return;te.preventDefault();const Z=T().filter(ne=>!ne.disabled).map(ne=>ne.ref.current);X3.includes(te.key)&&Z.reverse(),HJ(Z)}),onBlur:rt(e.onBlur,te=>{te.currentTarget.contains(te.target)||(window.clearTimeout(H.current),M.current="")}),onPointerMove:rt(e.onPointerMove,Sm(te=>{const P=te.target,Y=F.current!==te.clientX;if(te.currentTarget.contains(P)&&Y){const ee=te.clientX>F.current?"right":"left";O.current=ee,F.current=te.clientX}}))})})})})})})});n4.displayName=Es;var LJ="MenuGroup",rE=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(tn.div,{role:"group",...r,ref:t})});rE.displayName=LJ;var IJ="MenuLabel",r4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(tn.div,{...r,ref:t})});r4.displayName=IJ;var Ob="MenuItem",eM="menu.itemSelect",Gx=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=v.useRef(null),o=fp(Ob,e.__scopeMenu),a=tE(Ob,e.__scopeMenu),c=xn(t,s),d=v.useRef(!1),f=()=>{const m=s.current;if(!n&&m){const g=new CustomEvent(eM,{bubbles:!0,cancelable:!0});m.addEventListener(eM,b=>r==null?void 0:r(b),{once:!0}),wO(m,g),g.defaultPrevented?d.current=!1:o.onClose()}};return u.jsx(i4,{...i,ref:c,disabled:n,onClick:rt(e.onClick,f),onPointerDown:m=>{var g;(g=e.onPointerDown)==null||g.call(e,m),d.current=!0},onPointerUp:rt(e.onPointerUp,m=>{var g;d.current||(g=m.currentTarget)==null||g.click()}),onKeyDown:rt(e.onKeyDown,m=>{const g=a.searchRef.current!=="";n||g&&m.key===" "||s1.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})});Gx.displayName=Ob;var i4=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=tE(Ob,n),a=Z3(n),c=v.useRef(null),d=xn(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(wm.ItemSlot,{scope:n,disabled:r,textValue:i??g,children:u.jsx(bJ,{asChild:!0,...a,focusable:!r,children:u.jsx(tn.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:rt(e.onPointerMove,Sm(y=>{r?o.onItemLeave(y):(o.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:rt(e.onPointerLeave,Sm(y=>o.onItemLeave(y))),onFocus:rt(e.onFocus,()=>m(!0)),onBlur:rt(e.onBlur,()=>m(!1))})})})}),DJ="MenuCheckboxItem",s4=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return u.jsx(u4,{scope:e.__scopeMenu,checked:n,children:u.jsx(Gx,{role:"menuitemcheckbox","aria-checked":zb(n)?"mixed":n,...i,ref:t,"data-state":sE(n),onSelect:rt(i.onSelect,()=>r==null?void 0:r(zb(n)?!0:!n),{checkForDefaultPrevented:!1})})})});s4.displayName=DJ;var o4="MenuRadioGroup",[PJ,OJ]=mu(o4,{value:void 0,onValueChange:()=>{}}),a4=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=io(r);return u.jsx(PJ,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(rE,{...i,ref:t})})});a4.displayName=o4;var l4="MenuRadioItem",c4=v.forwardRef((e,t)=>{const{value:n,...r}=e,i=OJ(l4,e.__scopeMenu),s=n===i.value;return u.jsx(u4,{scope:e.__scopeMenu,checked:s,children:u.jsx(Gx,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":sE(s),onSelect:rt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});c4.displayName=l4;var iE="MenuItemIndicator",[u4,zJ]=mu(iE,{checked:!1}),d4=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=zJ(iE,n);return u.jsx(Is,{present:r||zb(s.checked)||s.checked===!0,children:u.jsx(tn.span,{...i,ref:t,"data-state":sE(s.checked)})})});d4.displayName=iE;var BJ="MenuSeparator",h4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(tn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});h4.displayName=BJ;var FJ="MenuArrow",f4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Wx(n);return u.jsx($x,{...i,...r,ref:t})});f4.displayName=FJ;var $J="MenuSub",[QRe,m4]=mu($J),Ff="MenuSubTrigger",p4=v.forwardRef((e,t)=>{const n=pu(Ff,e.__scopeMenu),r=fp(Ff,e.__scopeMenu),i=m4(Ff,e.__scopeMenu),s=tE(Ff,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(Jk,{asChild:!0,...d,children:u.jsx(i4,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":b4(n.open),...e,ref:Ek(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:rt(e.onPointerMove,Sm(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:rt(e.onPointerLeave,Sm(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:rt(e.onKeyDown,m=>{var b;const g=s.searchRef.current!=="";e.disabled||g&&m.key===" "||_J[r.dir].includes(m.key)&&(n.onOpenChange(!0),(b=n.content)==null||b.focus(),m.preventDefault())})})})});p4.displayName=Ff;var g4="MenuSubContent",v4=v.forwardRef((e,t)=>{const n=e4(Es,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=pu(Es,e.__scopeMenu),o=fp(Es,e.__scopeMenu),a=m4(g4,e.__scopeMenu),c=v.useRef(null),d=xn(t,c);return u.jsx(wm.Provider,{scope:e.__scopeMenu,children:u.jsx(Is,{present:r||s.open,children:u.jsx(wm.Slot,{scope:e.__scopeMenu,children:u.jsx(nE,{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:rt(e.onFocusOutside,f=>{f.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:rt(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:rt(e.onKeyDown,f=>{var b;const m=f.currentTarget.contains(f.target),g=wJ[o.dir].includes(f.key);m&&g&&(s.onOpenChange(!1),(b=a.trigger)==null||b.focus(),f.preventDefault())})})})})})});v4.displayName=g4;function b4(e){return e?"open":"closed"}function zb(e){return e==="indeterminate"}function sE(e){return zb(e)?"indeterminate":e?"checked":"unchecked"}function HJ(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function UJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function VJ(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=UJ(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 WJ(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 GJ(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return WJ(n,t)}function Sm(e){return t=>t.pointerType==="mouse"?e(t):void 0}var qJ=J3,KJ=Jk,YJ=t4,XJ=n4,QJ=rE,ZJ=r4,JJ=Gx,eee=s4,tee=a4,nee=c4,ree=d4,iee=h4,see=f4,oee=p4,aee=v4,oE="ContextMenu",[lee]=Va(oE,[Q3]),bi=Q3(),[cee,x4]=lee(oE),y4=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:s=!0}=e,[o,a]=v.useState(!1),c=bi(t),d=io(r),f=v.useCallback(m=>{a(m),d(m)},[d]);return u.jsx(cee,{scope:t,open:o,onOpenChange:f,modal:s,children:u.jsx(qJ,{...c,dir:i,open:o,onOpenChange:f,modal:s,children:n})})};y4.displayName=oE;var _4="ContextMenuTrigger",w4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,disabled:r=!1,...i}=e,s=x4(_4,n),o=bi(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(KJ,{...o,virtualRef:c}),u.jsx(tn.span,{"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,...i,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:rt(e.onContextMenu,g=>{f(),m(g),g.preventDefault()}),onPointerDown:r?e.onPointerDown:rt(e.onPointerDown,Xg(g=>{f(),d.current=window.setTimeout(()=>m(g),700)})),onPointerMove:r?e.onPointerMove:rt(e.onPointerMove,Xg(f)),onPointerCancel:r?e.onPointerCancel:rt(e.onPointerCancel,Xg(f)),onPointerUp:r?e.onPointerUp:rt(e.onPointerUp,Xg(f))})]})});w4.displayName=_4;var uee="ContextMenuPortal",S4=e=>{const{__scopeContextMenu:t,...n}=e,r=bi(t);return u.jsx(YJ,{...r,...n})};S4.displayName=uee;var C4="ContextMenuContent",k4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=x4(C4,n),s=bi(n),o=v.useRef(!1);return u.jsx(XJ,{...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)"}})});k4.displayName=C4;var dee="ContextMenuGroup",hee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(QJ,{...i,...r,ref:t})});hee.displayName=dee;var fee="ContextMenuLabel",mee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(ZJ,{...i,...r,ref:t})});mee.displayName=fee;var pee="ContextMenuItem",E4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(JJ,{...i,...r,ref:t})});E4.displayName=pee;var gee="ContextMenuCheckboxItem",vee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(eee,{...i,...r,ref:t})});vee.displayName=gee;var bee="ContextMenuRadioGroup",xee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(tee,{...i,...r,ref:t})});xee.displayName=bee;var yee="ContextMenuRadioItem",_ee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(nee,{...i,...r,ref:t})});_ee.displayName=yee;var wee="ContextMenuItemIndicator",See=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(ree,{...i,...r,ref:t})});See.displayName=wee;var Cee="ContextMenuSeparator",N4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(iee,{...i,...r,ref:t})});N4.displayName=Cee;var kee="ContextMenuArrow",Eee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(see,{...i,...r,ref:t})});Eee.displayName=kee;var Nee="ContextMenuSubTrigger",Tee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(oee,{...i,...r,ref:t})});Tee.displayName=Nee;var Ree="ContextMenuSubContent",Aee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(aee,{...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)"}})});Aee.displayName=Ree;function Xg(e){return t=>t.pointerType!=="mouse"?e(t):void 0}var jee=y4,Mee=w4,Lee=S4,T4=k4,R4=E4,A4=N4;const j4=v.createContext(null);function gu({onOpenChange:e,...t}){const[n,r]=v.useState(0),i=v.useCallback(()=>{r(s=>s+1),e==null||e(!1)},[e]);return u.jsx(j4.Provider,{value:i,children:u.jsx(jee,{onOpenChange:e,...t},n)})}const vu=Mee,tc=v.forwardRef(({className:e,...t},n)=>u.jsx(Lee,{children:u.jsx(T4,{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})}));tc.displayName=T4.displayName;const In=v.forwardRef(({className:e,onSelect:t,...n},r)=>{const i=v.useContext(j4);return u.jsx(R4,{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})});In.displayName=R4.displayName;const M4=v.forwardRef(({className:e,...t},n)=>u.jsx(A4,{ref:n,className:de("-mx-1 my-1 h-px bg-border",e),...t}));M4.displayName=A4.displayName;var qx="Popover",[L4]=Va(qx,[ec]),mp=ec(),[Iee,nc]=L4(qx),I4=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,a=mp(t),c=v.useRef(null),[d,f]=v.useState(!1),[m,g]=Ud({prop:r,defaultProp:i??!1,onChange:s,caller:qx});return u.jsx(Bx,{...a,children:u.jsx(Iee,{scope:t,contentId:ja(),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})})};I4.displayName=qx;var D4="PopoverAnchor",Dee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=nc(D4,n),s=mp(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:a}=i;return v.useEffect(()=>(o(),()=>a()),[o,a]),u.jsx(lp,{...s,...r,ref:t})});Dee.displayName=D4;var P4="PopoverTrigger",O4=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=nc(P4,n),s=mp(n),o=xn(t,i.triggerRef),a=u.jsx(tn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":H4(i.open),...r,ref:o,onClick:rt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?a:u.jsx(lp,{asChild:!0,...s,children:a})});O4.displayName=P4;var aE="PopoverPortal",[Pee,Oee]=L4(aE,{forceMount:void 0}),z4=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=nc(aE,t);return u.jsx(Pee,{scope:t,forceMount:n,children:u.jsx(Is,{present:n||s.open,children:u.jsx(fh,{asChild:!0,container:i,children:r})})})};z4.displayName=aE;var Gd="PopoverContent",B4=v.forwardRef((e,t)=>{const n=Oee(Gd,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=nc(Gd,e.__scopePopover);return u.jsx(Is,{present:r||s.open,children:s.modal?u.jsx(Bee,{...i,ref:t}):u.jsx(Fee,{...i,ref:t})})});B4.displayName=Gd;var zee=Yc("PopoverContent.RemoveScroll"),Bee=v.forwardRef((e,t)=>{const n=nc(Gd,e.__scopePopover),r=v.useRef(null),i=xn(t,r),s=v.useRef(!1);return v.useEffect(()=>{const o=r.current;if(o)return Lx(o)},[]),u.jsx(sp,{as:zee,allowPinchZoom:!0,children:u.jsx(F4,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:rt(e.onCloseAutoFocus,o=>{var a;o.preventDefault(),s.current||(a=n.triggerRef.current)==null||a.focus()}),onPointerDownOutside:rt(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:rt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Fee=v.forwardRef((e,t)=>{const n=nc(Gd,e.__scopePopover),r=v.useRef(!1),i=v.useRef(!1);return u.jsx(F4,{...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()}})}),F4=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=nc(Gd,n),b=mp(n);return jx(),u.jsx(ip,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:u.jsx(hh,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:f,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:d,onDismiss:()=>g.onOpenChange(!1),children:u.jsx(Fx,{"data-state":H4(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)"}})})})}),$4="PopoverClose",$ee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=nc($4,n);return u.jsx(tn.button,{type:"button",...r,ref:t,onClick:rt(e.onClick,()=>i.onOpenChange(!1))})});$ee.displayName=$4;var Hee="PopoverArrow",Uee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=mp(n);return u.jsx($x,{...i,...r,ref:t})});Uee.displayName=Hee;function H4(e){return e?"open":"closed"}var Vee=I4,Wee=O4,Gee=z4,U4=B4;const bu=Vee,xu=Wee,rc=v.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},i)=>u.jsx(Gee,{children:u.jsx(U4,{ref:i,align:t,sideOffset:n,[vm]:"",onCloseAutoFocus:s=>{var o;s.preventDefault(),window.dispatchEvent(new Event(Ab)),(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})}));rc.displayName=U4.displayName;function qee({editorLabel:e,starred:t,onCopyPath:n,onShowArchived:r,onOpenInFinder:i,onOpenInEditor:s,onToggleStar:o,onHide:a,children:c}){return u.jsxs(gu,{children:[u.jsx(vu,{asChild:!0,children:c}),u.jsxs(tc,{children:[u.jsxs(In,{onSelect:d=>{d.stopPropagation(),o()},children:[t?u.jsx(Xq,{className:"h-3.5 w-3.5"}):u.jsx(rO,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:t?"Unstar project":"Star project"})]}),u.jsxs(In,{onSelect:d=>{d.stopPropagation(),n()},children:[u.jsx(Da,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Copy Path"})]}),u.jsxs(In,{onSelect:d=>{d.stopPropagation(),r()},children:[u.jsx(gk,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Show Archived"})]}),u.jsxs(In,{onSelect:d=>{d.stopPropagation(),i()},children:[u.jsx(Tx,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Show in Finder"})]}),u.jsxs(In,{onSelect:d=>{d.stopPropagation(),s()},children:[u.jsx(vk,{className:"h-3.5 w-3.5"}),u.jsxs("span",{className:"text-xs font-medium",children:["Open in ",e]})]}),u.jsxs(In,{onSelect:d=>{d.stopPropagation(),a()},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[u.jsx(HW,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Hide"})]})]})]})}function Kee({canFork:e,onRename:t,onOpenInFinder:n,onFork:r,onArchive:i,onDelete:s,onEditPermissions:o,children:a}){return u.jsxs(gu,{children:[u.jsx(vu,{asChild:!0,children:a}),u.jsxs(tc,{children:[u.jsxs(In,{onSelect:c=>{c.preventDefault(),t()},children:[u.jsx(dh,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),u.jsxs(In,{onSelect:c=>{c.preventDefault(),n()},children:[u.jsx(Tx,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),u.jsxs(In,{disabled:!e,onSelect:c=>{c.preventDefault(),e&&r()},children:[u.jsx(nO,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Fork"})]}),o?u.jsxs(In,{onSelect:c=>{c.preventDefault(),o()},children:[u.jsx(_k,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Permissions…"})]}):null,u.jsxs(In,{onSelect:c=>{c.preventDefault(),i()},children:[u.jsx(gk,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Archive"})]}),u.jsxs(In,{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(hu,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Delete"})]})]})]})}function Yee({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(bu,{open:s,onOpenChange:o,children:[u.jsx(xu,{asChild:!0,children:i}),u.jsxs(rc,{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(dh,{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(iO,{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(hu,{className:"h-3.5 w-3.5"}),u.jsxs("span",{children:["Delete ",e]})]})]})]})}function Xee({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){return u.jsxs(gu,{children:[u.jsx(vu,{asChild:!0,children:i}),u.jsxs(tc,{children:[u.jsxs(In,{onSelect:s=>{s.preventDefault(),t()},children:[u.jsx(dh,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),u.jsxs(In,{onSelect:s=>{s.preventDefault(),n()},children:[u.jsx(iO,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Edit members"})]}),u.jsxs(In,{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(hu,{className:"h-3.5 w-3.5"}),u.jsxs("span",{className:"text-xs font-medium",children:["Delete ",e]})]})]})]})}function Qee(e){return e.status==="running"||e.status==="starting"?"warning":e.status==="waiting_for_user"?"info":e.status==="failed"?"destructive":e.unread?"success":null}function Zee(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 Jee(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 ete(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 tte({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?`${r1(e.status)} ${n1(n-e.stateEnteredAt)}`:Ys(n-(e.lastMessageAt??e._creationTime)),y=i&&r?r:b,_=i&&!!r,w=sY(e.chatId),C=t===w,E=Qee(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",Zee(E))}):null}),(()=>{const R=ete(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(_k,{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(P3,{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?Jee(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(Ie,{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(nO,{className:"size-3.5"})}):null,u.jsx(Ie,{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(gk,{className:"size-3.5"})})]})]})]},e._id);return u.jsx(Kee,{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 nte=v.memo(tte);function rte(){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 Kx=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function gh(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function lE(e){return"nodeType"in e}function zi(e){var t,n;return e?gh(e)?e:lE(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function cE(e){const{Document:t}=zi(e);return e instanceof t}function pp(e){return gh(e)?!1:e instanceof zi(e).HTMLElement}function V4(e){return e instanceof zi(e).SVGElement}function vh(e){return e?gh(e)?e.document:lE(e)?cE(e)?e:pp(e)||V4(e)?e.ownerDocument:document:document:document}const Vo=Kx?v.useLayoutEffect:v.useEffect;function uE(e){const t=v.useRef(e);return Vo(()=>{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 ite(){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 Cm(e,t){t===void 0&&(t=[e]);const n=v.useRef(e);return Vo(()=>{n.current!==e&&(n.current=e)},t),n}function gp(e,t){const n=v.useRef();return v.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function Bb(e){const t=uE(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 o1(e){const t=v.useRef();return v.useEffect(()=>{t.current=e},[e]),t.current}let J_={};function vp(e,t){return v.useMemo(()=>{if(t)return t;const n=J_[e]==null?0:J_[e]+1;return J_[e]=n,e+"-"+n},[e,t])}function W4(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 Md=W4(1),Fb=W4(-1);function ste(e){return"clientX"in e&&"clientY"in e}function dE(e){if(!e)return!1;const{KeyboardEvent:t}=zi(e.target);return t&&e instanceof t}function ote(e){if(!e)return!1;const{TouchEvent:t}=zi(e.target);return t&&e instanceof t}function a1(e){if(ote(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 ste(e)?{x:e.clientX,y:e.clientY}:null}const km=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[km.Translate.toString(e),km.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),tM="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function ate(e){return e.matches(tM)?e:e.querySelector(tM)}const lte={display:"none"};function cte(e){let{id:t,value:n}=e;return yn.createElement("div",{id:t,style:lte},n)}function ute(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 dte(){const[e,t]=v.useState("");return{announce:v.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const G4=v.createContext(null);function hte(e){const t=v.useContext(G4);v.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function fte(){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 mte={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(Rs,{className:"max-w-2xl",children:[u.jsxs(oo,{children:["Permissions — ",t]}),u.jsxs(Uo,{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(ji,{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(Yl,{className:"justify-between",children:[u.jsx(Ie,{variant:"ghost",onClick:k,children:"Reset to defaults"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ie,{variant:"ghost",onClick:s,children:"Cancel"}),u.jsx(Ie,{onClick:E,children:"Apply"})]})]})]})}),u.jsx(so,{open:g,onOpenChange:T=>{T||(b(!1),_(null))},children:u.jsxs(Rs,{className:"max-w-md",children:[u.jsx(oo,{children:"Enable auto-allow for this chat?"}),u.jsxs(Uo,{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(Yl,{className:"justify-end gap-2",children:[u.jsx(Ie,{variant:"ghost",onClick:()=>{b(!1),_(null)},children:"Cancel"}),u.jsx(Ie,{variant:"destructive",onClick:()=>{y&&a(y),b(!1),_(null)},children:"Enable auto-allow"})]})]})})]})}const CZ={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:[]},un=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}));un.displayName="Input";const z3=v.createContext(null);function kZ({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(z3.Provider,{value:g,children:[e,u.jsx(so,{open:t!==null,onOpenChange:b=>{b||!t||a()},children:u.jsx(Rs,{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(Uo,{className:"space-y-4",children:[u.jsx(oo,{children:t.options.title}),t.options.description?u.jsx(op,{children:t.options.description}):null,t.kind==="prompt"?u.jsx(un,{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(Yl,{children:[u.jsx(Ie,{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(Ie,{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 up(){const e=v.useContext(z3);if(!e)throw new Error("useAppDialog must be used within AppDialogProvider");return e}const Wk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("bg-card text-card-foreground",e),...t}));Wk.displayName="Card";const Gk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("flex flex-col space-y-1.5 p-2",e),...t}));Gk.displayName="CardHeader";const B3=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:de("text-2xl font-semibold leading-none tracking-tight",e),...t}));B3.displayName="CardTitle";const F3=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:de("text-sm text-muted-foreground",e),...t}));F3.displayName="CardDescription";const qk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("p-6 pt-0",e),...t}));qk.displayName="CardContent";const EZ=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("flex items-center p-6 pt-0",e),...t}));EZ.displayName="CardFooter";const NZ={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 TZ({variant:e,children:t,dot:n=!0,className:r}){const i=NZ[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 RZ="modulepreload",AZ=function(e){return"/"+e},qj={},X=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=AZ(d),d in qj)return;qj[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":RZ,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)})},jZ=v.lazy(()=>X(()=>import("./index-CMqCpZAN.js"),[]).then(e=>({default:e.Toaster})));function MZ(){return u.jsx(v.Suspense,{fallback:null,children:u.jsx(jZ,{position:"bottom-right",theme:"system",closeButton:!0,duration:6e3})})}const LZ="0.92.2",IZ={version:LZ},Xn="Kanna",Kj="kanna",DZ=".kanna",PZ=".kanna-dev",OZ="KANNA_RUNTIME_PROFILE",Kk=`kanna/${IZ.version}`,zZ="[kanna]",BZ=`~/${Xn}`;function Vx(){var t;return(t=globalThis.process)==null?void 0:t.env}function FZ(e=Vx()){var t;return((t=e==null?void 0:e[OZ])==null?void 0:t.trim().toLowerCase())==="dev"?"dev":"prod"}function $Z(e=Vx()){return FZ(e)==="dev"?PZ:DZ}function HZ(e=Vx()){return`~/${$Z(e)}`}function UZ(e=Vx()){return`${HZ(e)}/keybindings.json`}function Yg(e){return e?`${Kj} ${e}`:Kj}const Yj=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},VZ=(e=>e?Yj(e):Yj),WZ=e=>e;function GZ(e,t=WZ){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 Xj=e=>{const t=VZ(e),n=r=>GZ(t,r);return Object.assign(n,t),n},is=(e=>e?Xj(e):Xj),$3="always",H3="funk",qZ=[{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 KZ(e){switch(e){case"never":case"unfocused":case"always":return e;default:return $3}}function YZ(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 H3}}const Bc=is()(e=>({chatSoundPreference:$3,chatSoundId:H3,setChatSoundPreference:t=>e({chatSoundPreference:KZ(t)}),setChatSoundId:t=>e({chatSoundId:YZ(t)})})),XZ={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 QZ(e=document){return e.visibilityState!=="visible"||!e.hasFocus()}function ZZ(e){const t=new Audio(XZ[e]);return t.preload="auto",t.play()}async function e1(e,t){if(t<=0)return;const n=Array.from({length:t},(r,i)=>new Promise(s=>{window.setTimeout(()=>{ZZ(e).catch(()=>{}).finally(()=>s())},i*90)}));await Promise.all(n)}function JZ(e,t=document){return e==="never"?!1:e==="always"?!0:QZ(t)}function eJ(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 tJ(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 t1(e){return e.split(/[\s_-]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}const nJ=[/^(?:\/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 U3(e){const t=e.trim();for(const n of nJ){const r=t.match(n);if(!r)continue;const i=(r[2]??r[1]??"").trim();if(i)return i}return t}function Yk(e){return e.split("/").pop()||e}const rJ=1440*6e4;function iJ(e,t){if(e===void 0)return null;const n=Math.max(0,t-e),r=6e4,i=60*r,s=rJ,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 sJ(e){return e.lastMessageAt??e._creationTime}const Xk=1e3,nb=60*Xk,kd=60*nb,Q_=24*kd;function Ys(e){const t=Math.max(0,e);if(t<nb)return`${Math.floor(t/Xk)}s`;if(t<kd)return`${Math.floor(t/nb)}m`;if(t<Q_){const i=Math.floor(t/kd),s=Math.floor(t%kd/nb);return s===0?`${i}h`:`${i}h ${s}m`}const n=Math.floor(t/Q_),r=Math.floor(t%Q_/kd);return r===0?`${n}d`:`${n}d ${r}h`}function n1(e){const t=Math.max(0,e);if(t>=kd)return Ys(t);const n=Math.floor(t/Xk),r=Math.floor(n/60),i=n%60;return`${r}:${i.toString().padStart(2,"0")}`}function r1(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 Zj(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 Jj(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 Qk(e){const t=e+"CollectionProvider",[n,r]=Va(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=Yc(a),d=yn.forwardRef((_,w)=>{const{scope:C,children:E}=_,k=s(a,C),T=xn(w,k.collectionRef);return u.jsx(c,{ref:T,children:E})});d.displayName=a;const f=e+"CollectionItemSlot",m="data-radix-collection-item",g=Yc(f),b=yn.forwardRef((_,w)=>{const{scope:C,children:E,...k}=_,T=yn.useRef(null),R=xn(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 oJ=v.createContext(void 0);function Zk(e){const t=v.useContext(oJ);return e||t||"ltr"}var Z_="rovingFocusGroup.onEntryFocus",aJ={bubbles:!1,cancelable:!0},dp="RovingFocusGroup",[i1,V3,lJ]=Qk(dp),[cJ,W3]=Va(dp,[lJ]),[uJ,dJ]=cJ(dp),G3=v.forwardRef((e,t)=>u.jsx(i1.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(i1.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(hJ,{...e,ref:t})})}));G3.displayName=dp;var hJ=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=xn(t,g),y=Zk(s),[_,w]=Ud({prop:o,defaultProp:a??null,onChange:c,caller:dp}),[C,E]=v.useState(!1),k=io(d),T=V3(n),R=v.useRef(!1),[A,j]=v.useState(0);return v.useEffect(()=>{const L=g.current;if(L)return L.addEventListener(Z_,k),()=>L.removeEventListener(Z_,k)},[k]),u.jsx(uJ,{scope:n,orientation:r,dir:y,loop:i,currentTabStopId:_,onItemFocus:v.useCallback(L=>w(L),[w]),onItemShiftTab:v.useCallback(()=>E(!0),[]),onFocusableItemAdd:v.useCallback(()=>j(L=>L+1),[]),onFocusableItemRemove:v.useCallback(()=>j(L=>L-1),[]),children:u.jsx(tn.div,{tabIndex:C||A===0?-1:0,"data-orientation":r,...m,ref:b,style:{outline:"none",...e.style},onMouseDown:rt(e.onMouseDown,()=>{R.current=!0}),onFocus:rt(e.onFocus,L=>{const H=!R.current;if(L.target===L.currentTarget&&H&&!C){const M=new CustomEvent(Z_,aJ);if(L.currentTarget.dispatchEvent(M),!M.defaultPrevented){const D=T().filter(B=>B.focusable),z=D.find(B=>B.active),O=D.find(B=>B.id===_),$=[z,O,...D].filter(Boolean).map(B=>B.ref.current);Y3($,f)}}R.current=!1}),onBlur:rt(e.onBlur,()=>E(!1))})})}),q3="RovingFocusGroupItem",K3=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...a}=e,c=ja(),d=s||c,f=dJ(q3,n),m=f.currentTabStopId===d,g=V3(n),{onFocusableItemAdd:b,onFocusableItemRemove:y,currentTabStopId:_}=f;return v.useEffect(()=>{if(r)return b(),()=>y()},[r,b,y]),u.jsx(i1.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:u.jsx(tn.span,{tabIndex:m?0:-1,"data-orientation":f.orientation,...a,ref:t,onMouseDown:rt(e.onMouseDown,w=>{r?f.onItemFocus(d):w.preventDefault()}),onFocus:rt(e.onFocus,()=>f.onItemFocus(d)),onKeyDown:rt(e.onKeyDown,w=>{if(w.key==="Tab"&&w.shiftKey){f.onItemShiftTab();return}if(w.target!==w.currentTarget)return;const C=pJ(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?gJ(k,T+1):k.slice(T+1)}setTimeout(()=>Y3(k))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:_!=null}):o})})});K3.displayName=q3;var fJ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function mJ(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function pJ(e,t,n){const r=mJ(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return fJ[r]}function Y3(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function gJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var vJ=G3,bJ=K3,s1=["Enter"," "],xJ=["ArrowDown","PageUp","Home"],X3=["ArrowUp","PageDown","End"],yJ=[...xJ,...X3],_J={ltr:[...s1,"ArrowRight"],rtl:[...s1,"ArrowLeft"]},wJ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},hp="Menu",[wm,SJ,CJ]=Qk(hp),[mu,Q3]=Va(hp,[CJ,ec,W3]),Wx=ec(),Z3=W3(),[kJ,pu]=mu(hp),[EJ,fp]=mu(hp),J3=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,a=Wx(t),[c,d]=v.useState(null),f=v.useRef(!1),m=io(s),g=Zk(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(Bx,{...a,children:u.jsx(kJ,{scope:t,open:n,onOpenChange:m,content:c,onContentChange:d,children:u.jsx(EJ,{scope:t,onClose:v.useCallback(()=>m(!1),[m]),isUsingKeyboardRef:f,dir:g,modal:o,children:r})})})};J3.displayName=hp;var NJ="MenuAnchor",Jk=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Wx(n);return u.jsx(lp,{...i,...r,ref:t})});Jk.displayName=NJ;var eE="MenuPortal",[TJ,e4]=mu(eE,{forceMount:void 0}),t4=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=pu(eE,t);return u.jsx(TJ,{scope:t,forceMount:n,children:u.jsx(Is,{present:n||s.open,children:u.jsx(fh,{asChild:!0,container:i,children:r})})})};t4.displayName=eE;var Es="MenuContent",[RJ,tE]=mu(Es),n4=v.forwardRef((e,t)=>{const n=e4(Es,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=pu(Es,e.__scopeMenu),o=fp(Es,e.__scopeMenu);return u.jsx(wm.Provider,{scope:e.__scopeMenu,children:u.jsx(Is,{present:r||s.open,children:u.jsx(wm.Slot,{scope:e.__scopeMenu,children:o.modal?u.jsx(AJ,{...i,ref:t}):u.jsx(jJ,{...i,ref:t})})})})}),AJ=v.forwardRef((e,t)=>{const n=pu(Es,e.__scopeMenu),r=v.useRef(null),i=xn(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Lx(s)},[]),u.jsx(nE,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:rt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),jJ=v.forwardRef((e,t)=>{const n=pu(Es,e.__scopeMenu);return u.jsx(nE,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),MJ=Yc("MenuContent.ScrollLock"),nE=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=pu(Es,n),C=fp(Es,n),E=Wx(n),k=Z3(n),T=SJ(n),[R,A]=v.useState(null),j=v.useRef(null),L=xn(t,j,w.onContentChange),H=v.useRef(0),M=v.useRef(""),D=v.useRef(0),z=v.useRef(null),O=v.useRef("right"),F=v.useRef(0),$=y?sp:v.Fragment,B=y?{as:MJ,allowPinchZoom:!0}:void 0,U=te=>{var ne,ie;const P=M.current+te,Y=T().filter(le=>!le.disabled),ee=document.activeElement,V=(ne=Y.find(le=>le.ref.current===ee))==null?void 0:ne.textValue,ue=Y.map(le=>le.textValue),ge=VJ(ue,P,V),Z=(ie=Y.find(le=>le.textValue===ge))==null?void 0:ie.ref.current;(function le(oe){M.current=oe,window.clearTimeout(H.current),oe!==""&&(H.current=window.setTimeout(()=>le(""),1e3))})(P),Z&&setTimeout(()=>Z.focus())};v.useEffect(()=>()=>window.clearTimeout(H.current),[]),jx();const G=v.useCallback(te=>{var Y,ee;return O.current===((Y=z.current)==null?void 0:Y.side)&&GJ(te,(ee=z.current)==null?void 0:ee.area)},[]);return u.jsx(RJ,{scope:n,searchRef:M,onItemEnter:v.useCallback(te=>{G(te)&&te.preventDefault()},[G]),onItemLeave:v.useCallback(te=>{var P;G(te)||((P=j.current)==null||P.focus(),A(null))},[G]),onTriggerLeave:v.useCallback(te=>{G(te)&&te.preventDefault()},[G]),pointerGraceTimerRef:D,onPointerGraceIntentChange:v.useCallback(te=>{z.current=te},[]),children:u.jsx($,{...B,children:u.jsx(ip,{asChild:!0,trapped:i,onMountAutoFocus:rt(s,te=>{var P;te.preventDefault(),(P=j.current)==null||P.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:u.jsx(hh,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:d,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:g,onDismiss:b,children:u.jsx(vJ,{asChild:!0,...k,dir:C.dir,orientation:"vertical",loop:r,currentTabStopId:R,onCurrentTabStopIdChange:A,onEntryFocus:rt(c,te=>{C.isUsingKeyboardRef.current||te.preventDefault()}),preventScrollOnEntryFocus:!0,children:u.jsx(Fx,{role:"menu","aria-orientation":"vertical","data-state":b4(w.open),"data-radix-menu-content":"",dir:C.dir,...E,..._,ref:L,style:{outline:"none",..._.style},onKeyDown:rt(_.onKeyDown,te=>{const Y=te.target.closest("[data-radix-menu-content]")===te.currentTarget,ee=te.ctrlKey||te.altKey||te.metaKey,V=te.key.length===1;Y&&(te.key==="Tab"&&te.preventDefault(),!ee&&V&&U(te.key));const ue=j.current;if(te.target!==ue||!yJ.includes(te.key))return;te.preventDefault();const Z=T().filter(ne=>!ne.disabled).map(ne=>ne.ref.current);X3.includes(te.key)&&Z.reverse(),HJ(Z)}),onBlur:rt(e.onBlur,te=>{te.currentTarget.contains(te.target)||(window.clearTimeout(H.current),M.current="")}),onPointerMove:rt(e.onPointerMove,Sm(te=>{const P=te.target,Y=F.current!==te.clientX;if(te.currentTarget.contains(P)&&Y){const ee=te.clientX>F.current?"right":"left";O.current=ee,F.current=te.clientX}}))})})})})})})});n4.displayName=Es;var LJ="MenuGroup",rE=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(tn.div,{role:"group",...r,ref:t})});rE.displayName=LJ;var IJ="MenuLabel",r4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(tn.div,{...r,ref:t})});r4.displayName=IJ;var Ob="MenuItem",eM="menu.itemSelect",Gx=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=v.useRef(null),o=fp(Ob,e.__scopeMenu),a=tE(Ob,e.__scopeMenu),c=xn(t,s),d=v.useRef(!1),f=()=>{const m=s.current;if(!n&&m){const g=new CustomEvent(eM,{bubbles:!0,cancelable:!0});m.addEventListener(eM,b=>r==null?void 0:r(b),{once:!0}),wO(m,g),g.defaultPrevented?d.current=!1:o.onClose()}};return u.jsx(i4,{...i,ref:c,disabled:n,onClick:rt(e.onClick,f),onPointerDown:m=>{var g;(g=e.onPointerDown)==null||g.call(e,m),d.current=!0},onPointerUp:rt(e.onPointerUp,m=>{var g;d.current||(g=m.currentTarget)==null||g.click()}),onKeyDown:rt(e.onKeyDown,m=>{const g=a.searchRef.current!=="";n||g&&m.key===" "||s1.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})});Gx.displayName=Ob;var i4=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=tE(Ob,n),a=Z3(n),c=v.useRef(null),d=xn(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(wm.ItemSlot,{scope:n,disabled:r,textValue:i??g,children:u.jsx(bJ,{asChild:!0,...a,focusable:!r,children:u.jsx(tn.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:rt(e.onPointerMove,Sm(y=>{r?o.onItemLeave(y):(o.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:rt(e.onPointerLeave,Sm(y=>o.onItemLeave(y))),onFocus:rt(e.onFocus,()=>m(!0)),onBlur:rt(e.onBlur,()=>m(!1))})})})}),DJ="MenuCheckboxItem",s4=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return u.jsx(u4,{scope:e.__scopeMenu,checked:n,children:u.jsx(Gx,{role:"menuitemcheckbox","aria-checked":zb(n)?"mixed":n,...i,ref:t,"data-state":sE(n),onSelect:rt(i.onSelect,()=>r==null?void 0:r(zb(n)?!0:!n),{checkForDefaultPrevented:!1})})})});s4.displayName=DJ;var o4="MenuRadioGroup",[PJ,OJ]=mu(o4,{value:void 0,onValueChange:()=>{}}),a4=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=io(r);return u.jsx(PJ,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(rE,{...i,ref:t})})});a4.displayName=o4;var l4="MenuRadioItem",c4=v.forwardRef((e,t)=>{const{value:n,...r}=e,i=OJ(l4,e.__scopeMenu),s=n===i.value;return u.jsx(u4,{scope:e.__scopeMenu,checked:s,children:u.jsx(Gx,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":sE(s),onSelect:rt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});c4.displayName=l4;var iE="MenuItemIndicator",[u4,zJ]=mu(iE,{checked:!1}),d4=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=zJ(iE,n);return u.jsx(Is,{present:r||zb(s.checked)||s.checked===!0,children:u.jsx(tn.span,{...i,ref:t,"data-state":sE(s.checked)})})});d4.displayName=iE;var BJ="MenuSeparator",h4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(tn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});h4.displayName=BJ;var FJ="MenuArrow",f4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Wx(n);return u.jsx($x,{...i,...r,ref:t})});f4.displayName=FJ;var $J="MenuSub",[QRe,m4]=mu($J),Ff="MenuSubTrigger",p4=v.forwardRef((e,t)=>{const n=pu(Ff,e.__scopeMenu),r=fp(Ff,e.__scopeMenu),i=m4(Ff,e.__scopeMenu),s=tE(Ff,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(Jk,{asChild:!0,...d,children:u.jsx(i4,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":b4(n.open),...e,ref:Ek(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:rt(e.onPointerMove,Sm(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:rt(e.onPointerLeave,Sm(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:rt(e.onKeyDown,m=>{var b;const g=s.searchRef.current!=="";e.disabled||g&&m.key===" "||_J[r.dir].includes(m.key)&&(n.onOpenChange(!0),(b=n.content)==null||b.focus(),m.preventDefault())})})})});p4.displayName=Ff;var g4="MenuSubContent",v4=v.forwardRef((e,t)=>{const n=e4(Es,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=pu(Es,e.__scopeMenu),o=fp(Es,e.__scopeMenu),a=m4(g4,e.__scopeMenu),c=v.useRef(null),d=xn(t,c);return u.jsx(wm.Provider,{scope:e.__scopeMenu,children:u.jsx(Is,{present:r||s.open,children:u.jsx(wm.Slot,{scope:e.__scopeMenu,children:u.jsx(nE,{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:rt(e.onFocusOutside,f=>{f.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:rt(e.onEscapeKeyDown,f=>{o.onClose(),f.preventDefault()}),onKeyDown:rt(e.onKeyDown,f=>{var b;const m=f.currentTarget.contains(f.target),g=wJ[o.dir].includes(f.key);m&&g&&(s.onOpenChange(!1),(b=a.trigger)==null||b.focus(),f.preventDefault())})})})})})});v4.displayName=g4;function b4(e){return e?"open":"closed"}function zb(e){return e==="indeterminate"}function sE(e){return zb(e)?"indeterminate":e?"checked":"unchecked"}function HJ(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function UJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function VJ(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=UJ(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 WJ(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 GJ(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return WJ(n,t)}function Sm(e){return t=>t.pointerType==="mouse"?e(t):void 0}var qJ=J3,KJ=Jk,YJ=t4,XJ=n4,QJ=rE,ZJ=r4,JJ=Gx,eee=s4,tee=a4,nee=c4,ree=d4,iee=h4,see=f4,oee=p4,aee=v4,oE="ContextMenu",[lee]=Va(oE,[Q3]),bi=Q3(),[cee,x4]=lee(oE),y4=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:s=!0}=e,[o,a]=v.useState(!1),c=bi(t),d=io(r),f=v.useCallback(m=>{a(m),d(m)},[d]);return u.jsx(cee,{scope:t,open:o,onOpenChange:f,modal:s,children:u.jsx(qJ,{...c,dir:i,open:o,onOpenChange:f,modal:s,children:n})})};y4.displayName=oE;var _4="ContextMenuTrigger",w4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,disabled:r=!1,...i}=e,s=x4(_4,n),o=bi(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(KJ,{...o,virtualRef:c}),u.jsx(tn.span,{"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,...i,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:rt(e.onContextMenu,g=>{f(),m(g),g.preventDefault()}),onPointerDown:r?e.onPointerDown:rt(e.onPointerDown,Xg(g=>{f(),d.current=window.setTimeout(()=>m(g),700)})),onPointerMove:r?e.onPointerMove:rt(e.onPointerMove,Xg(f)),onPointerCancel:r?e.onPointerCancel:rt(e.onPointerCancel,Xg(f)),onPointerUp:r?e.onPointerUp:rt(e.onPointerUp,Xg(f))})]})});w4.displayName=_4;var uee="ContextMenuPortal",S4=e=>{const{__scopeContextMenu:t,...n}=e,r=bi(t);return u.jsx(YJ,{...r,...n})};S4.displayName=uee;var C4="ContextMenuContent",k4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=x4(C4,n),s=bi(n),o=v.useRef(!1);return u.jsx(XJ,{...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)"}})});k4.displayName=C4;var dee="ContextMenuGroup",hee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(QJ,{...i,...r,ref:t})});hee.displayName=dee;var fee="ContextMenuLabel",mee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(ZJ,{...i,...r,ref:t})});mee.displayName=fee;var pee="ContextMenuItem",E4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(JJ,{...i,...r,ref:t})});E4.displayName=pee;var gee="ContextMenuCheckboxItem",vee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(eee,{...i,...r,ref:t})});vee.displayName=gee;var bee="ContextMenuRadioGroup",xee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(tee,{...i,...r,ref:t})});xee.displayName=bee;var yee="ContextMenuRadioItem",_ee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(nee,{...i,...r,ref:t})});_ee.displayName=yee;var wee="ContextMenuItemIndicator",See=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(ree,{...i,...r,ref:t})});See.displayName=wee;var Cee="ContextMenuSeparator",N4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(iee,{...i,...r,ref:t})});N4.displayName=Cee;var kee="ContextMenuArrow",Eee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(see,{...i,...r,ref:t})});Eee.displayName=kee;var Nee="ContextMenuSubTrigger",Tee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(oee,{...i,...r,ref:t})});Tee.displayName=Nee;var Ree="ContextMenuSubContent",Aee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(aee,{...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)"}})});Aee.displayName=Ree;function Xg(e){return t=>t.pointerType!=="mouse"?e(t):void 0}var jee=y4,Mee=w4,Lee=S4,T4=k4,R4=E4,A4=N4;const j4=v.createContext(null);function gu({onOpenChange:e,...t}){const[n,r]=v.useState(0),i=v.useCallback(()=>{r(s=>s+1),e==null||e(!1)},[e]);return u.jsx(j4.Provider,{value:i,children:u.jsx(jee,{onOpenChange:e,...t},n)})}const vu=Mee,tc=v.forwardRef(({className:e,...t},n)=>u.jsx(Lee,{children:u.jsx(T4,{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})}));tc.displayName=T4.displayName;const In=v.forwardRef(({className:e,onSelect:t,...n},r)=>{const i=v.useContext(j4);return u.jsx(R4,{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})});In.displayName=R4.displayName;const M4=v.forwardRef(({className:e,...t},n)=>u.jsx(A4,{ref:n,className:de("-mx-1 my-1 h-px bg-border",e),...t}));M4.displayName=A4.displayName;var qx="Popover",[L4]=Va(qx,[ec]),mp=ec(),[Iee,nc]=L4(qx),I4=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,a=mp(t),c=v.useRef(null),[d,f]=v.useState(!1),[m,g]=Ud({prop:r,defaultProp:i??!1,onChange:s,caller:qx});return u.jsx(Bx,{...a,children:u.jsx(Iee,{scope:t,contentId:ja(),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})})};I4.displayName=qx;var D4="PopoverAnchor",Dee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=nc(D4,n),s=mp(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:a}=i;return v.useEffect(()=>(o(),()=>a()),[o,a]),u.jsx(lp,{...s,...r,ref:t})});Dee.displayName=D4;var P4="PopoverTrigger",O4=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=nc(P4,n),s=mp(n),o=xn(t,i.triggerRef),a=u.jsx(tn.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":H4(i.open),...r,ref:o,onClick:rt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?a:u.jsx(lp,{asChild:!0,...s,children:a})});O4.displayName=P4;var aE="PopoverPortal",[Pee,Oee]=L4(aE,{forceMount:void 0}),z4=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=nc(aE,t);return u.jsx(Pee,{scope:t,forceMount:n,children:u.jsx(Is,{present:n||s.open,children:u.jsx(fh,{asChild:!0,container:i,children:r})})})};z4.displayName=aE;var Gd="PopoverContent",B4=v.forwardRef((e,t)=>{const n=Oee(Gd,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=nc(Gd,e.__scopePopover);return u.jsx(Is,{present:r||s.open,children:s.modal?u.jsx(Bee,{...i,ref:t}):u.jsx(Fee,{...i,ref:t})})});B4.displayName=Gd;var zee=Yc("PopoverContent.RemoveScroll"),Bee=v.forwardRef((e,t)=>{const n=nc(Gd,e.__scopePopover),r=v.useRef(null),i=xn(t,r),s=v.useRef(!1);return v.useEffect(()=>{const o=r.current;if(o)return Lx(o)},[]),u.jsx(sp,{as:zee,allowPinchZoom:!0,children:u.jsx(F4,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:rt(e.onCloseAutoFocus,o=>{var a;o.preventDefault(),s.current||(a=n.triggerRef.current)==null||a.focus()}),onPointerDownOutside:rt(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:rt(e.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})})}),Fee=v.forwardRef((e,t)=>{const n=nc(Gd,e.__scopePopover),r=v.useRef(!1),i=v.useRef(!1);return u.jsx(F4,{...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()}})}),F4=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=nc(Gd,n),b=mp(n);return jx(),u.jsx(ip,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:u.jsx(hh,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:f,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:d,onDismiss:()=>g.onOpenChange(!1),children:u.jsx(Fx,{"data-state":H4(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)"}})})})}),$4="PopoverClose",$ee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=nc($4,n);return u.jsx(tn.button,{type:"button",...r,ref:t,onClick:rt(e.onClick,()=>i.onOpenChange(!1))})});$ee.displayName=$4;var Hee="PopoverArrow",Uee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=mp(n);return u.jsx($x,{...i,...r,ref:t})});Uee.displayName=Hee;function H4(e){return e?"open":"closed"}var Vee=I4,Wee=O4,Gee=z4,U4=B4;const bu=Vee,xu=Wee,rc=v.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},i)=>u.jsx(Gee,{children:u.jsx(U4,{ref:i,align:t,sideOffset:n,[vm]:"",onCloseAutoFocus:s=>{var o;s.preventDefault(),window.dispatchEvent(new Event(Ab)),(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})}));rc.displayName=U4.displayName;function qee({editorLabel:e,starred:t,onCopyPath:n,onShowArchived:r,onOpenInFinder:i,onOpenInEditor:s,onToggleStar:o,onHide:a,children:c}){return u.jsxs(gu,{children:[u.jsx(vu,{asChild:!0,children:c}),u.jsxs(tc,{children:[u.jsxs(In,{onSelect:d=>{d.stopPropagation(),o()},children:[t?u.jsx(Xq,{className:"h-3.5 w-3.5"}):u.jsx(rO,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:t?"Unstar project":"Star project"})]}),u.jsxs(In,{onSelect:d=>{d.stopPropagation(),n()},children:[u.jsx(Da,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Copy Path"})]}),u.jsxs(In,{onSelect:d=>{d.stopPropagation(),r()},children:[u.jsx(gk,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Show Archived"})]}),u.jsxs(In,{onSelect:d=>{d.stopPropagation(),i()},children:[u.jsx(Tx,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Show in Finder"})]}),u.jsxs(In,{onSelect:d=>{d.stopPropagation(),s()},children:[u.jsx(vk,{className:"h-3.5 w-3.5"}),u.jsxs("span",{className:"text-xs font-medium",children:["Open in ",e]})]}),u.jsxs(In,{onSelect:d=>{d.stopPropagation(),a()},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[u.jsx(HW,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Hide"})]})]})]})}function Kee({canFork:e,onRename:t,onOpenInFinder:n,onFork:r,onArchive:i,onDelete:s,onEditPermissions:o,children:a}){return u.jsxs(gu,{children:[u.jsx(vu,{asChild:!0,children:a}),u.jsxs(tc,{children:[u.jsxs(In,{onSelect:c=>{c.preventDefault(),t()},children:[u.jsx(dh,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),u.jsxs(In,{onSelect:c=>{c.preventDefault(),n()},children:[u.jsx(Tx,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),u.jsxs(In,{disabled:!e,onSelect:c=>{c.preventDefault(),e&&r()},children:[u.jsx(nO,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Fork"})]}),o?u.jsxs(In,{onSelect:c=>{c.preventDefault(),o()},children:[u.jsx(_k,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Permissions…"})]}):null,u.jsxs(In,{onSelect:c=>{c.preventDefault(),i()},children:[u.jsx(gk,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Archive"})]}),u.jsxs(In,{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(hu,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Delete"})]})]})]})}function Yee({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(bu,{open:s,onOpenChange:o,children:[u.jsx(xu,{asChild:!0,children:i}),u.jsxs(rc,{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(dh,{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(iO,{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(hu,{className:"h-3.5 w-3.5"}),u.jsxs("span",{children:["Delete ",e]})]})]})]})}function Xee({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){return u.jsxs(gu,{children:[u.jsx(vu,{asChild:!0,children:i}),u.jsxs(tc,{children:[u.jsxs(In,{onSelect:s=>{s.preventDefault(),t()},children:[u.jsx(dh,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Rename"})]}),u.jsxs(In,{onSelect:s=>{s.preventDefault(),n()},children:[u.jsx(iO,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Edit members"})]}),u.jsxs(In,{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(hu,{className:"h-3.5 w-3.5"}),u.jsxs("span",{className:"text-xs font-medium",children:["Delete ",e]})]})]})]})}function Qee(e){return e.status==="running"||e.status==="starting"?"warning":e.status==="waiting_for_user"?"info":e.status==="failed"?"destructive":e.unread?"success":null}function Zee(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 Jee(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 ete(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 tte({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?`${r1(e.status)} ${n1(n-e.stateEnteredAt)}`:Ys(n-(e.lastMessageAt??e._creationTime)),y=i&&r?r:b,_=i&&!!r,w=sY(e.chatId),C=t===w,E=Qee(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",Zee(E))}):null}),(()=>{const R=ete(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(_k,{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(P3,{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?Jee(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(Ie,{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(nO,{className:"size-3.5"})}):null,u.jsx(Ie,{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(gk,{className:"size-3.5"})})]})]})]},e._id);return u.jsx(Kee,{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 nte=v.memo(tte);function rte(){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 Kx=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function gh(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function lE(e){return"nodeType"in e}function zi(e){var t,n;return e?gh(e)?e:lE(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function cE(e){const{Document:t}=zi(e);return e instanceof t}function pp(e){return gh(e)?!1:e instanceof zi(e).HTMLElement}function V4(e){return e instanceof zi(e).SVGElement}function vh(e){return e?gh(e)?e.document:lE(e)?cE(e)?e:pp(e)||V4(e)?e.ownerDocument:document:document:document}const Vo=Kx?v.useLayoutEffect:v.useEffect;function uE(e){const t=v.useRef(e);return Vo(()=>{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 ite(){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 Cm(e,t){t===void 0&&(t=[e]);const n=v.useRef(e);return Vo(()=>{n.current!==e&&(n.current=e)},t),n}function gp(e,t){const n=v.useRef();return v.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function Bb(e){const t=uE(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 o1(e){const t=v.useRef();return v.useEffect(()=>{t.current=e},[e]),t.current}let J_={};function vp(e,t){return v.useMemo(()=>{if(t)return t;const n=J_[e]==null?0:J_[e]+1;return J_[e]=n,e+"-"+n},[e,t])}function W4(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 Md=W4(1),Fb=W4(-1);function ste(e){return"clientX"in e&&"clientY"in e}function dE(e){if(!e)return!1;const{KeyboardEvent:t}=zi(e.target);return t&&e instanceof t}function ote(e){if(!e)return!1;const{TouchEvent:t}=zi(e.target);return t&&e instanceof t}function a1(e){if(ote(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 ste(e)?{x:e.clientX,y:e.clientY}:null}const km=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[km.Translate.toString(e),km.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),tM="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function ate(e){return e.matches(tM)?e:e.querySelector(tM)}const lte={display:"none"};function cte(e){let{id:t,value:n}=e;return yn.createElement("div",{id:t,style:lte},n)}function ute(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 dte(){const[e,t]=v.useState("");return{announce:v.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const G4=v.createContext(null);function hte(e){const t=v.useContext(G4);v.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function fte(){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 mte={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=>[cy(e),e])),Yle=new Map([["s",_r(383)],[_r(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 _I(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function wI(e,t){const n=_ve(e,t),r=n.one(e,void 0),i=xve(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 Eve(e,t){return e&&"run"in e?async function(n,r){const i=wI(n,{file:r,...t});await e.run(i,r)}:function(n,r){return wI(n,{file:r,...e||t})}}function SI(e){if(e)throw e}var Gw,CI;function Nve(){if(CI)return Gw;CI=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 Gw=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 _},Gw}var Tve=Nve();const qw=wx(Tve);function rC(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 Rve(){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?Ave(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 Ave(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 Ro={basename:jve,dirname:Mve,extname:Lve,join:Ive,sep:"/"};function jve(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');kp(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 Mve(e){if(kp(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 Lve(e){kp(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 Ive(...e){let t=-1,n;for(;++t<e.length;)kp(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":Dve(n)}function Dve(e){kp(e);const t=e.codePointAt(0)===47;let n=Pve(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function Pve(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 kp(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const Ove={cwd:zve};function zve(){return"/"}function iC(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function Bve(e){if(typeof e=="string")e=new URL(e);else if(!iC(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 Fve(e)}function Fve(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 Kw=["history","path","basename","stem","extname","dirname"];class rF{constructor(t){let n;t?iC(t)?n={path:t}:typeof t=="string"||$ve(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":Ove.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<Kw.length;){const s=Kw[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)Kw.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?Ro.basename(this.path):void 0}set basename(t){Xw(t,"basename"),Yw(t,"basename"),this.path=Ro.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?Ro.dirname(this.path):void 0}set dirname(t){kI(this.basename,"dirname"),this.path=Ro.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?Ro.extname(this.path):void 0}set extname(t){if(Yw(t,"extname"),kI(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=Ro.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){iC(t)&&(t=Bve(t)),Xw(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?Ro.basename(this.path,this.extname):void 0}set stem(t){Xw(t,"stem"),Yw(t,"stem"),this.path=Ro.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 oi(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 Yw(e,t){if(e&&e.includes(Ro.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+Ro.sep+"`")}function Xw(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function kI(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function $ve(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Hve=(function(e){const r=this.constructor.prototype,i=r[e],s=function(){return i.apply(s,arguments)};return Object.setPrototypeOf(s,r),s}),Uve={}.hasOwnProperty;class m2 extends Hve{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=Rve()}copy(){const t=new m2;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(qw(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(Jw("data",this.frozen),this.namespace[t]=n,this):Uve.call(this.namespace,t)&&this.namespace[t]||void 0:t?(Jw("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=Sv(t),r=this.parser||this.Parser;return Qw("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),Qw("process",this.parser||this.Parser),Zw("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(s,o){const a=Sv(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);Gve(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(),Qw("processSync",this.parser||this.Parser),Zw("processSync",this.compiler||this.Compiler),this.process(t,i),NI("processSync","process",n),r;function i(s,o){n=!0,SI(s),r=o}}run(t,n,r){EI(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=Sv(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),NI("runSync","run",r),i;function s(o,a){SI(o),i=a,r=!0}}stringify(t,n){this.freeze();const r=Sv(n),i=this.compiler||this.Compiler;return Zw("stringify",i),EI(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(Jw("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=qw(!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];rC(_)&&rC(b)&&(b=qw(!0,_,b)),r[g]=[d,b,...y]}}}}const Vve=new m2().freeze();function Qw(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function Zw(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function Jw(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 EI(e){if(!rC(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function NI(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function Sv(e){return Wve(e)?e:new rF(e)}function Wve(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function Gve(e){return typeof e=="string"||qve(e)}function qve(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Kve="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",TI=[],RI={allowDangerousHtml:!0},Yve=/^(https?|ircs?|mailto|xmpp)$/i,Xve=[{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 Wo(e){const t=Qve(e),n=Zve(e);return Jve(t.runSync(t.parse(n),n),e)}function Qve(e){const t=e.rehypePlugins||TI,n=e.remarkPlugins||TI,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...RI}:RI;return Vve().use(Fge).use(n).use(Eve,r).use(t)}function Zve(e){const t=e.children||"",n=new rF;return typeof t=="string"&&(n.value=t),n}function Jve(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,s=t.disallowedElements,o=t.skipHtml,a=t.unwrapDisallowed,c=t.urlTransform||ebe;for(const f of Xve)Object.hasOwn(t,f.from)&&(""+f.from+(f.to?"use `"+f.to+"` instead":"remove it")+Kve+f.id,void 0);return JE(e,d),Kpe(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 Ww)if(Object.hasOwn(Ww,b)&&Object.hasOwn(f.properties,b)){const y=f.properties[b],_=Ww[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 ebe(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||Yve.test(e.slice(0,t))?e:""}const Cv=new Map;function tbe(e){return`${e.id}|${e.contentUrl}|${e.size??0}`}function by(e){const t=tbe(e),n=Cv.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(Cv.get(t)??{status:"loading"})),v.useEffect(()=>{if(n&&n.status!=="loading")return;let c=!1;const d=t;return QE(e.contentUrl,eB).then(f=>{if(c||a.current!==d)return;const m={status:"ready",content:f.content,truncated:f.truncated};Cv.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."};Cv.set(d,g),i(g)}),()=>{c=!0}},[n,t,e.contentUrl]),r}function nbe({source:e}){const t=by(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(Wo,{remarkPlugins:Fa,components:$a,children:t.content})})]})}const kv=new Map;function rbe(e){return`${e.id}|${e.contentUrl}|${e.size??0}|${e.mimeType}`}function ibe({source:e}){const t=rbe(e),n=kv.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(kv.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 QE(e.contentUrl,eB).then(_=>{if(b||a.current!==y)return;const w={status:"ready",table:Dde(_.content,g),truncated:_.truncated};kv.set(y,w),i(w)}).catch(_=>{if(b||a.current!==y)return;const w={status:"error",message:_ instanceof Error?_.message:"Unable to load preview."};kv.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 ${Y1} 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 sbe({source:e}){const t=by(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(obe,{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 obe({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 abe({source:e}){const t=by(e),n=v.useMemo(()=>t.status==="ready"?Ide(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 lbe({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 cbe({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 ube=200*1024;function dbe(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 hbe({source:e}){const t=by(e),n=t.status==="ready"&&t.content.length<=ube,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 X(()=>Promise.resolve().then(()=>W8),void 0).then(async c=>{if(o)return;const d=await c.codeToHtml(t.content,{lang:dbe(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 fbe(e){var r;const t=pbe(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 mbe(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 pbe(e){return typeof window>"u"?e:new URL(e,document.baseURI||window.location.href).toString()}function Th({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(Rs,{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(xbe,{source:e,onClose:r}):null})})}const gbe=120,vbe=.5;function bbe({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>gbe||a>vbe}function xbe({source:e,onClose:t}){const n=_be(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&&(bbe({startY:g.y,lastY:g.lastY,lastT:g.lastT,endY:m.clientY,now:Date.now()})?t():i(0))},[t]),d=v.useCallback(()=>{fbe(e)},[e]),f=v.useCallback(()=>mbe(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(op,{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(ybe(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(Ie,{type:"button",variant:"outline",onClick:d,children:[u.jsx(Oq,{className:"mr-2 h-4 w-4"}),"Share"]}),e.origin==="offer_download"?u.jsxs(Ie,{type:"button",onClick:f,children:[u.jsx(bk,{className:"mr-2 h-4 w-4"}),"Download"]}):null]})]})}function ybe(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=Eh(t);return n==="image"?Lpe:n==="pdf"?iI:n==="audio"?lbe:n==="video"?cbe:n==="table"?ibe:n==="markdown"?nbe:n==="json"?abe:n==="code"?hbe:kh(t).kind==="external"?iI:sbe}function _be(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=Eh(t),r=hy(n,e.mimeType),i=e.size?` · ${Rh(e.size)}`:"";return`${r}${i}`}function Ep(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 wbe(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function Sbe({path:e,linkText:t}){const n=v.useMemo(()=>s2(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 L=((D=(M=j.headers.get("Content-Type"))==null?void 0:M.split(";")[0])==null?void 0:D.trim())||"application/octet-stream",H=Number.parseInt(j.headers.get("Content-Length")??"0",10)||0;i({kind:"ready",mimeType:L,size:H})}).catch(()=>{A.signal.aborted||i({kind:"error"})}),()=>A.abort()},[n]);const a=wbe(e),c=t||a,d=Mpe(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($o,{attachment:g,disabledReason:"File no longer available"})});const b=Eh(g),y=hy(b,f),_=m>0?Rh(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"?kh(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($o,{attachment:g,onClick:()=>o(!0),meta:E,ariaLabel:R.join(", ")})}),u.jsx(Th,{source:s?Ep(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($o,{attachment:g,href:n,download:a,meta:E,ariaLabel:R.join(", ")})})}function Cbe(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 Mi=is()(e=>({settings:null,hydrationStatus:"idle",setHydrationStatus:t=>e({hydrationStatus:t}),setFromServer:t=>e({settings:t,hydrationStatus:"ready"}),applyOptimisticPatch:t=>e(n=>({settings:n.settings?Cbe(n.settings,t):n.settings}))})),kbe=[],Ebe=e=>{var t;return((t=e.settings)==null?void 0:t.customMcpServers)??kbe},iF=v.createContext(void 0),Nbe=e=>e==="light"||e==="dark"||e==="system";function Tbe(e){return e==="dark"?"black-translucent":"default"}function AI(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 jI(e){if(typeof document>"u"||typeof window>"u")return;const t=getComputedStyle(document.body).backgroundColor||getComputedStyle(document.documentElement).backgroundColor;t&&AI("theme-color",t),AI("apple-mobile-web-app-status-bar-style",Tbe(e)),document.documentElement.style.colorScheme=e}const fb=()=>typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",MI=e=>{if(typeof document>"u")return;const t=e==="system"?fb():e;document.documentElement.classList.toggle("dark",t==="dark")},Rbe=()=>{var t;const e=(t=Mi.getState().settings)==null?void 0:t.theme;return e&&Nbe(e)?e:"system"};function Abe({children:e}){const t=Mi(o=>{var a;return(a=o.settings)==null?void 0:a.theme}),n=Mi(o=>o.applyOptimisticPatch),[r,i]=v.useState(Rbe);v.useEffect(()=>{!t||t===r||i(t)},[t,r]),v.useEffect(()=>{MI(r)},[r]),v.useEffect(()=>{const o=r==="system"?fb():r;jI(o)},[r]),v.useEffect(()=>{if(r!=="system")return;const o=window.matchMedia("(prefers-color-scheme: dark)"),a=()=>{MI("system"),jI(fb())};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"?fb():r;return{theme:r,resolvedTheme:o,setTheme:a=>{i(a),n({theme:a})}}},[n,r]);return u.jsx(iF.Provider,{value:s,children:e})}function xy(){const e=v.useContext(iF);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}function jbe({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 Zi.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(Ie,{variant:"ghost",size:"icon","aria-label":"Zoom out",className:"h-9 w-9",onClick:()=>r(g=>c(g-.25)),children:u.jsx(J5,{className:"h-4 w-4"})}),u.jsx(Ie,{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(Ie,{variant:"ghost",size:"icon","aria-label":"Reset view",className:"h-9 w-9",onClick:()=>{r(1),s({x:0,y:0})},children:u.jsx(wq,{className:"h-4 w-4"})}),u.jsx(Ie,{variant:"ghost",size:"icon","aria-label":"Close",className:"h-9 w-9",onClick:t,children:u.jsx(Ls,{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 eS=null;function Mbe(){return eS||(eS=X(()=>import("./mermaid.core-iiPRaxhL.js").then(e=>e.bm),[]).then(e=>e.default)),eS}function Lbe({source:e}){const{resolvedTheme:t}=xy(),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 Mbe().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(tS,{source:e}):r.status==="loading"?u.jsx("div",{className:"relative group/mermaid",children:u.jsx(tS,{source:e})}):a?u.jsxs("div",{className:"relative group/mermaid",children:[u.jsx(tS,{source:e}),u.jsx(LI,{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(LI,{showSource:a,onToggleSource:()=>c(_=>!_),onCopy:y,copied:m,onZoom:()=>f(!0)}),d&&u.jsx(jbe,{svg:r.svg,onClose:b})]})}function LI({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(Ie,{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(qG,{className:"h-4 w-4"})}),u.jsx(Ie,{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(VS,{className:"h-4 w-4"})}),u.jsx(Ie,{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(ts,{className:"h-4 w-4 text-success"}):u.jsx(Da,{className:"h-4 w-4"})})]})}const Ibe=200*1024,Dbe={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 Pbe(e){return Dbe[e.toLowerCase()]??null}const Obe=/^<pre[^>]*>/,zbe=/<\/pre>\s*$/,Bbe=/^<code[^>]*>/,Fbe=/<\/code>\s*$/;function $be(e){return e.replace(Obe,"").replace(zbe,"").replace(Bbe,"").replace(Fbe,"")}function Uf({source:e,lang:t}){const{resolvedTheme:n}=xy(),r=n==="dark"?"github-dark":"github-light",i=Pbe(t),s=i!==null&&e.length<=Ibe,[o,a]=v.useState(null);v.useEffect(()=>{if(!s||i===null)return;let f=!1;return X(()=>Promise.resolve().then(()=>W8),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:$be(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 sF={readonly:!1,localLinkMode:"open"},oF=v.createContext(sF);function Hbe({children:e,value:t}){return u.jsx(oF.Provider,{value:{...sF,...t},children:e})}function yy(){return v.useContext(oF)}const aF=()=>{},Ube=v.createContext(aF);function lF({children:e,onOpenLocalLink:t}){return u.jsx(Ube.Provider,{value:t??aF,children:e})}const sC={Task:Nb,TaskOutput:Nb,Bash:Rx,Glob:Qf,Grep:Qf,ExitPlanMode:aj,Read:q5,Edit:JW,Write:tG,Delete:lG,NotebookEdit:dh,WebFetch:XV,TodoWrite:mW,WebSearch:Qf,KillShell:Kq,AskUserQuestion:Q5,Skill:Hq,EnterPlanMode:aj},cF=iK;function uF(e){return sC[e]?sC[e]:cF}function dF({icon:e,className:t}){return u.jsx(e,{className:t})}function qa({children:e,className:t}){return u.jsx("div",{className:de("flex gap-3 justify-start items-center",t),children:e})}function hF({children:e,className:t}){return u.jsx("div",{className:de("flex items-center gap-1.5 text-xs",t),children:e})}function ru({children:e,className:t}){return u.jsx("span",{className:de("font-medium text-foreground/80",t),children:e})}function Vbe({children:e}){return u.jsx("span",{className:"text-muted-foreground",children:e})}function Wbe({children:e,className:t}){return u.jsxs(qa,{className:de("px-0.5 text-xs tracking-wide",t),children:[u.jsx("div",{className:"w-full h-[1px] bg-border"}),u.jsx(ru,{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 p2({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(Ts,{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 oC({label:e,children:t,copyText:n}){const[r,i]=v.useState(!1),s=n??Jd(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(Ie,{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(ts,{className:"h-3.5 w-3.5 text-success"}):u.jsx(Da,{className:"h-4 w-4"})})]})]})}function fF({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 _y({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 Jd(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(Array.isArray(e))return e.map(Jd).join("");if(e&&typeof e=="object"&&"props"in e){const t=e.props;return Jd(t.children)}return""}function II(e,t){return v.isValidElement(e)?v.cloneElement(e,{className:de(e.props.className,t)}):e}function mF({children:e,...t}){const[n,r]=v.useState(!1),i=Jd(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(Ie,{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(ts,{className:"h-4 w-4 text-success"}):u.jsx(Da,{className:"h-4 w-4"})})]})}function tS({source:e}){return u.jsx(mF,{children:u.jsx("code",{className:"block text-xs whitespace-pre language-mermaid",children:e})})}const g2={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:mF,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(Lbe,{source:Jd(e)});const s=i.find(a=>a.startsWith("language-")),o=s?s.slice(9):"";return o?u.jsx(Uf,{source:Jd(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]=II(r,"mt-0"));const i=n.length-1,s=n[i];return s!==void 0&&(n[i]=II(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"&&jpe(e)?s2(e):e;return u.jsx("img",{src:n,...t})}};function Gbe({children:e,href:t,onClick:n,...r}){const i=yy(),s=Tpe(t);if(s&&i.localLinkMode==="text")return u.jsx("span",{className:"transition-all underline decoration-2 text-logo decoration-logo/50",children:e});if(s){const o=aC(e).trim();return u.jsx(Sbe,{path:s.path,linkText:o||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:"_blank",rel:"noopener noreferrer",onClick:n,...r,children:e})}function qbe(){return{...g2,a:e=>u.jsx(Gbe,{...e})}}const Fa=[$B],$a=qbe();function aC(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(aC).join(""):v.isValidElement(e)?aC(e.props.children):""}({...g2});function v2({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(G5,{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," · ",Rh(e.size)]})]})]}),f?u.jsx(sB,{progress:o??null,onCancel:a,size:d?"sm":"md",cancelLabel:`Cancel upload of ${e.displayName}`}):null,r&&!f?u.jsx(pF,{displayName:e.displayName,onRemove:r}):null]})}function $o({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":Eh(e),g=Xbe(m),b=e.kind==="mention",y=b?Kbe(e.displayName):e.displayName,_=b?Ybe(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," · ",Rh(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(dF,{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(sB,{progress:i??null,onCancel:s,size:"sm",cancelLabel:`Cancel upload of ${e.displayName}`}):null,n&&!w?u.jsx(pF,{displayName:e.displayName,onRemove:n}):null]})}function Kbe(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function Ybe(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function pF({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(Ls,{className:"h-3.5 w-3.5"})})}function Xbe(e){switch(e){case"image":return G5;case"pdf":return xq;case"markdown":return Tq;case"json":return GW;case"table":return rG;case"code":return KW;case"text":return Nx;case"archive":return VW;case"audio":return XW;case"video":return oG;default:return q5}}function Rh(e){return e<1024?`${e} B`:e<1024*1024?`${Math.max(1,Math.round(e/1024))} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}const La=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}));La.displayName="Textarea";const Ev={};function DI(e){return!e.isCollapsed&&!e.hasPreviewAttachment&&e.patch===void 0&&e.patchError===void 0&&!e.isPatchLoading}function Qbe(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 gF(e){return e.isUntracked}function Zbe(e){return gF(e)?e.path.includes("/"):!1}function nS(e){return u.jsxs(Pi,{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(vi,{children:e.label})]})}function vF({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(J5,{className:"h-3 w-3",strokeWidth:3}):e?u.jsx(ts,{className:"h-3 w-3",strokeWidth:3}):null})}function b2(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 Jbe(e){return e?`Last fetched ${b2(e)}`:"No local fetch recorded"}function exe({entry:e,isPendingPush:t=!1}){const n=b2(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(Hd,{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(Hd,{className:"size-3"})})}):null]})}function PI(e){switch(e.kind){case"local":return 0;case"pull_request":return 1;case"remote":default:return 2}}function txe(e){const t=new Map;for(const n of e){const r=t.get(n.name);(!r||PI(n)<PI(r))&&t.set(n.name,n)}return t}function nxe(e,t){const n=txe([...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 rxe({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 H=!1;return c(!0),E(null),n().then(M=>{H||(o(M),f(M.owners[0]??M.activeAccountLogin??""),g(M.suggestedRepoName),y("private"),w(""))}).finally(()=>{H||c(!1)}),()=>{H=!0}},[n,e]),v.useEffect(()=>{if(!e||!(s!=null&&s.ghInstalled)||!s.authenticated)return;const H=d.trim(),M=m.trim();if(!H||!M){E(null);return}let D=!1;T(!0);const z=window.setTimeout(()=>{r({owner:H,name:M}).then(O=>{D||E(O)}).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 H=await i({owner:d.trim(),name:m.trim(),visibility:b,description:_});H!=null&&H.ok&&t(!1)}finally{A(!1)}}}const L=!!(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(Rs,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[u.jsxs(Uo,{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(op,{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(bn,{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(Io,{value:d,onValueChange:f,children:[u.jsx(Qs,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:u.jsx(Ca,{placeholder:"Select owner"})}),u.jsx(Zs,{children:((s==null?void 0:s.owners)??[]).map(H=>u.jsx(ti,{value:H,children:u.jsxs("span",{className:"flex items-center gap-2",children:[H===(s==null?void 0:s.activeAccountLogin)?u.jsx(Ax,{className:"size-4 text-muted-foreground"}):u.jsx(uW,{className:"size-4 text-muted-foreground"}),u.jsx("span",{className:"pl-[1px]",children:H})]})},H))})]})}),u.jsx("div",{className:"space-y-2",children:u.jsxs("div",{className:"relative",children:[u.jsx(un,{value:m,onChange:H=>g(H.target.value),placeholder:"my-repo",className:"pl-9 pr-10"}),u.jsx(uq,{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(bn,{className:"size-4 animate-spin"})}):C?u.jsx("div",{className:"absolute inset-y-0 right-2 flex items-center",children:u.jsxs(Pi,{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(ts,{className:"size-4"}):u.jsx(gm,{className:"size-4"})})}),u.jsx(vi,{children:C.message})]})}):null]})}),u.jsx("div",{className:"space-y-2",children:u.jsxs("div",{className:"relative",children:[u.jsx(Nx,{className:"pointer-events-none absolute left-3 top-3 size-4 text-muted-foreground"}),u.jsx(La,{value:_,onChange:H=>w(H.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(Io,{value:b,onValueChange:H=>y(H),children:[u.jsx(Qs,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:u.jsx(Ca,{placeholder:"Select visibility"})}),u.jsxs(Zs,{children:[u.jsx(ti,{value:"private",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(UG,{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(EG,{className:"size-4 text-muted-foreground"}),u.jsx("span",{className:"pl-[1px]",children:"Public"})]})})]})]})})]})]}),u.jsxs(Yl,{children:[u.jsx(Ie,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),u.jsx(Ie,{size:"sm",disabled:!L,onClick:()=>void j(),children:R?u.jsxs(u.Fragment,{children:[u.jsx(bn,{className:"mr-1.5 size-3.5 animate-spin"}),"Publishing…"]}):"Push to GitHub"})]})]})})}function bF({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(un,{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 Uc({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(X5,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):u.jsx(Na,{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:b2(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 ixe({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?nxe(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),L=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||!L){m(null),b(null),_(!1);return}let D=!1;return m(null),b(null),_(!0),i(L).then(z=>{D||m(z)}).catch(z=>{D||b(z instanceof Error?z.message:String(z))}).finally(()=>{D||_(!1)}),()=>{D=!0}},[i,e,L]);const H=!L||!f||y||w||f.status!=="mergeable";async function M(){if(!(!L||H)){C(!0);try{const D=await s(L);D!=null&&D.ok&&t(!1)}finally{C(!1)}}}return u.jsx(so,{open:e,onOpenChange:t,children:u.jsxs(Rs,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[u.jsxs(Uo,{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(op,{children:"Choose a branch to continue."})]}),u.jsx(bF,{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(Uc,{title:"Default Branch",entries:R?[R]:[],emptyLabel:"No default branch available.",selectedName:c,onSelect:D=>d(D.name)}),u.jsx(Uc,{title:"Recent Branches",entries:A,emptyLabel:"No recent branches.",selectedName:c,onSelect:D=>d(D.name)}),u.jsx(Uc,{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:L?y?u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(bn,{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(ts,{className:"mt-1 size-3.5 shrink-0 text-success"}):f.status==="conflicts"?u.jsx(gm,{className:"mt-1 size-3.5 shrink-0 text-warning"}):f.status==="mergeable"?u.jsx(Y5,{className:"mt-1 size-3.5 shrink-0 text-muted-foreground"}):u.jsx(gm,{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(Yl,{children:u.jsxs("div",{className:"flex min-w-0 w-full items-center justify-end gap-2",children:[u.jsx(Ie,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),u.jsx(Ie,{className:"max-w-full min-w-0",size:"sm",disabled:H,onClick:()=>void M(),children:w?u.jsxs(u.Fragment,{children:[u.jsx(bn,{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 sxe({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(G=>k(G)).catch(G=>{R(G instanceof Error?G.message:String(G))}).finally(()=>{m(!1)}))},[t,o]);const A=y.trim().toLowerCase(),j=G=>G.filter(te=>A?[te.displayName,te.name,te.description,te.prTitle,te.headLabel].some(P=>P==null?void 0:P.toLowerCase().includes(A)):!0),L=(E==null?void 0:E.currentBranchName)??e,H=new Set(((E==null?void 0:E.pullRequests)??[]).map(G=>G.headRefName??G.name)),M=j((E==null?void 0:E.recent)??[]).filter(G=>G.name!==L),D=j((E==null?void 0:E.local)??[]).filter(G=>G.name!==L),z=j((E==null?void 0:E.remote)??[]).filter(G=>G.name!==L&&!H.has(G.name)),O=j((E==null?void 0:E.pullRequests)??[]).filter(G=>G.name!==L),F=(E==null?void 0:E.pullRequests.length)??0;async function $(G){b(!0);try{await i(G),a(!1),_(""),C("branches")}finally{b(!1)}}async function B(){b(!0);try{await s(),a(!1),_(""),C("branches")}finally{b(!1)}}function U(){a(!1),d(!0)}return u.jsxs(bu,{open:o,onOpenChange:a,children:[u.jsx(xu,{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(Na,{className:"h-3.5 w-3.5 shrink-0"}),u.jsx("span",{className:"truncate",children:e??"Detached HEAD"}),u.jsx(uh,{className:"h-3.5 w-3.5 shrink-0"})]})}),u.jsx(rc,{align:"start",className:"w-[320px] p-2",children:u.jsxs("div",{className:"space-y-2",children:[u.jsx(bF,{value:y,onChange:_,placeholder:w==="pull_requests"?"Search pull requests":"Search branches",disabled:f||g,trailingAction:u.jsx(Ie,{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(ji,{value:w,onValueChange:G=>C(G),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(bn,{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(Uc,{title:"Open PRs",entries:O,emptyLabel:(E==null?void 0:E.pullRequestsStatus)==="error"?E.pullRequestsError??"Could not load pull requests.":(E==null?void 0:E.pullRequestsStatus)==="unavailable"?"Pull requests unavailable for this repository.":"No open pull requests.",disabled:g,stickyTitle:!0,onSelect:G=>{$(G)}}):u.jsxs("div",{className:"space-y-3",children:[u.jsx(Uc,{title:"Recent",entries:M,emptyLabel:"No recent branches.",disabled:g,stickyTitle:!0,onSelect:G=>{$(G)}}),u.jsx(Uc,{title:"Local",entries:D,emptyLabel:"No local branches.",disabled:g,stickyTitle:!0,onSelect:G=>{$(G)}}),u.jsx(Uc,{title:"Remote",entries:z,emptyLabel:"No remote branches.",disabled:g,stickyTitle:!0,onSelect:G=>{$(G)}})]})}),L?u.jsx(Ie,{variant:"default",size:"sm",disabled:f||g||!!T,onClick:U,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(_G,{className:"mr-1.5 inline h-3.5 w-3.5 shrink-0"}),"Merge branch into ",L,"..."]})}):null]})}),u.jsx(ixe,{open:c,onOpenChange:d,branchList:E,currentBranchName:L,onPreviewMergeBranch:n,onMergeBranch:r})]})}function oxe({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 _=gF(e),w=Zbe(e),[C,E]=v.useState(null),k=v.useRef(null),T=v.useRef(null),{sentinelRef:R,isStuck:A}=Cde({rootRef:t,disabled:r}),j=v.useMemo(()=>Qbe(n,e),[e,n]),L=j!==null,H=DI({isCollapsed:r,hasPreviewAttachment:L,patch:m,patchError:g,isPatchLoading:b});v.useEffect(()=>{if(!H)return;const O=`${e.path}\0${e.patchDigest}`;T.current!==O&&(T.current=O,y(e.path).catch(()=>{}))},[e.patchDigest,e.path,y,H]);function M(O){if(kh(O).openInNewTab){typeof window<"u"&&window.open(new URL(O.contentUrl,window.location.origin).toString(),"_blank","noopener,noreferrer");return}E(O.id)}function D(O){var $;O.preventDefault(),O.stopPropagation();const F=O.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(L||m!==void 0){c();return}if(b)return;if(!(g!==void 0||DI({isCollapsed:!1,hasPreviewAttachment:L,patch:m,patchError:g,isPatchLoading:b}))){c();return}y(e.path).then(()=>{c()}).catch(()=>{})}return u.jsxs(gu,{children:[u.jsx(vu,{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:O=>{O.key!=="Enter"&&O.key!==" "||(O.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(vF,{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(pm,{className:"h-3.5 w-3.5 shrink-0"})}),b&&r&&!j?u.jsx(bn,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):r?u.jsx(uh,{className:"h-3.5 w-3.5 shrink-0"}):u.jsx(V5,{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(v2,{attachment:j,onClick:()=>M(j)}):u.jsx($o,{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(bn,{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(wde,{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(Th,{source:j&&C===j.id?Ep(j,"user_attachment"):null,open:j!==null&&C===j.id,onOpenChange:O=>!O&&E(null)})]},e.path)}),u.jsxs(tc,{children:[u.jsxs(In,{onSelect:O=>{O.stopPropagation(),f.onOpenFile(e.path)},children:[u.jsx(vk,{className:"h-3.5 w-3.5"}),u.jsxs("span",{className:"text-xs font-medium",children:["Open in ",s]})]}),u.jsxs(In,{onSelect:O=>{O.stopPropagation(),f.onOpenInFinder(e.path)},children:[u.jsx(Tx,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),u.jsxs(In,{onSelect:O=>{O.stopPropagation(),f.onDiscardFile(e.path)},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[u.jsx(hu,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Discard Changes"})]}),u.jsxs(In,{disabled:!_,onSelect:O=>{O.stopPropagation(),_&&f.onIgnoreFile(e.path)},children:[u.jsx(nj,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Ignore File"})]}),u.jsxs(In,{disabled:!w,onSelect:O=>{O.stopPropagation(),w&&f.onIgnoreFolder(e.path)},children:[u.jsx(nj,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Ignore folder..."})]}),u.jsx(M4,{}),u.jsxs(In,{onSelect:O=>{O.stopPropagation(),f.onCopyFilePath(e.path)},children:[u.jsx(Da,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Copy File Path"})]}),u.jsxs(In,{onSelect:O=>{O.stopPropagation(),f.onCopyRelativePath(e.path)},children:[u.jsx(Da,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Copy Relative Path"})]})]})]})}function axe({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:L,onDiffRenderModeChange:H,onWrapLinesChange:M}){var Xe;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,[O,F]=v.useState(!1),[$,B]=v.useState(null),[U,G]=v.useState(!1),[te,P]=v.useState(!1),[Y,ee]=v.useState({}),[V,ue]=v.useState({}),[ge,Z]=v.useState({}),ne=v.useRef(null),ie=v.useRef({}),le=v.useMemo(()=>t.files.map(_e=>_e.path),[t.files]),oe=v.useMemo(()=>le.join("\0"),[le]),ke=Ai(_e=>{var De;return e?((De=_e.projectUi[e])==null?void 0:De.viewMode)??(z?"changes":"history"):z?"changes":"history"}),Ee=Ai(_e=>{var De;return e?((De=_e.projectUi[e])==null?void 0:De.collapsedPaths)??Ev:Ev}),Pe=Ai(_e=>{var De;return e?((De=_e.projectUi[e])==null?void 0:De.summary)??"":""}),Ze=Ai(_e=>{var De;return e?((De=_e.projectUi[e])==null?void 0:De.description)??"":""}),ut=Ai(_e=>_e.reconcileCollapsedPaths),Mt=Ai(_e=>_e.toggleCollapsedPath),ye=Ai(_e=>_e.setViewMode),an=Ai(_e=>_e.setCommitDraft),jt=Ai(_e=>_e.clearCommitDraft),_t=bv(_e=>e?_e.checkedPathsByProjectId[e]??Ev:Ev),ft=bv(_e=>_e.reconcileProject),Pt=bv(_e=>_e.setChecked),It=bv(_e=>_e.setAllChecked),st=v.useRef(z);v.useEffect(()=>{e&&ut(e,le)},[le,oe,e,ut]),v.useEffect(()=>{const _e=Object.fromEntries(t.files.map(Ve=>[Ve.path,Ve.patchDigest])),De=Ve=>ie.current[Ve]===_e[Ve];ee(Ve=>Object.fromEntries(Object.entries(Ve).filter(([We])=>le.includes(We)&&De(We)))),ue(Ve=>Object.fromEntries(Object.entries(Ve).filter(([We])=>le.includes(We)&&De(We)))),Z(Ve=>Object.fromEntries(Object.entries(Ve).filter(([We])=>le.includes(We)&&De(We)))),ie.current=_e},[t.files,le,oe]),v.useEffect(()=>{e&&ft(e,le)},[le,oe,e,ft]),v.useEffect(()=>{if(!e)return;if(st.current!==z){ye(e,z?"changes":"history"),st.current=z;return}st.current=z},[z,e,ye]);const Ot=v.useMemo(()=>t.files.filter(_e=>_t[_e.path]??!0).map(_e=>_e.path),[_t,t.files]),he=Ot.length,Re=t.files.length>0&&he===t.files.length,Ue=he>0&&he<t.files.length,Je=Pe.trim(),Ke=Je.length>0,vt=$!==null,St=O||vt,ze=((Xe=t.branchHistory)==null?void 0:Xe.entries)??[],Be=t.behindCount??0,Oe=t.aheadCount??0,Fe=t.hasUpstream===!0,bt=t.hasUpstream===!1&&!!t.branchName,wt=t.hasOriginRemote===!0,fn=t.branchName?t.branchName.split("/").map(_e=>encodeURIComponent(_e)).join("/"):null,Xt=bt?"publish":Be>0?"pull":"fetch",Qt=t.originRepoSlug&&fn?`https://github.com/${t.originRepoSlug}/compare/${fn}?expand=1`:null,Rt=!!(Fe&&Qt&&t.branchName&&t.branchName!==t.defaultBranchName),xt=t.status==="ready"&&he>0&&!St,mt=t.status==="ready"&&he>0&&Ke&&!St,kt=wt?"commit_and_push":"commit_only",pt=t.branchName??"current branch";async function $t(_e){if(mt){B(_e);try{const De=await A({paths:Ot,summary:Je,description:Ze.trim(),mode:_e});(De!=null&&De.ok||De!=null&&De.localCommitCreated)&&e&&jt(e)}finally{B(null)}}}async function nt(){if(xt){F(!0);try{const _e=await C({paths:Ot});e&&an(e,{summary:_e.subject,description:_e.body})}finally{F(!1)}}}function we(_e){if(!(!(_e.metaKey||_e.ctrlKey)||_e.key!=="Enter")){if(_e.preventDefault(),Ke){$t(kt);return}nt()}}async function tt(_e=Xt){if(!(t.status!=="ready"||U)){G(!0);try{await j(_e)}finally{G(!1)}}}const qe=v.useCallback(async _e=>{var De;if(Y[_e]!==void 0||ge[_e])return Y[_e]??"";Z(Ve=>({...Ve,[_e]:!0})),ue(Ve=>{if(!(_e in Ve))return Ve;const{[_e]:We,...Ut}=Ve;return Ut});try{const Ve=await L(_e);ee(Ut=>({...Ut,[_e]:Ve}));const We=(De=t.files.find(Ut=>Ut.path===_e))==null?void 0:De.patchDigest;return We&&(ie.current={...ie.current,[_e]:We}),Ve}catch(Ve){const We=Ve instanceof Error?Ve.message:String(Ve);throw ue(Ut=>({...Ut,[_e]:We})),Ve}finally{Z(Ve=>{const{[_e]:We,...Ut}=Ve;return Ut})}},[t.files,ge,L,Y]);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(sxe,{currentBranchName:t.branchName,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:y,onCheckoutBranch:_,onCreateBranch:w})}),t.status==="ready"?wt?Xt==="publish"?u.jsxs(Ie,{variant:"ghost",size:"sm",onClick:()=>void tt(),disabled:U,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[U?u.jsx(bn,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(Zv,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Publish Branch"})]}):u.jsxs("div",{className:"flex items-center gap-1",children:[Xt==="fetch"?u.jsxs(Pi,{delayDuration:0,children:[u.jsx(Oi,{asChild:!0,children:u.jsxs(Ie,{variant:"ghost",size:"sm",onClick:()=>void tt(),disabled:U,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[U?u.jsx(bn,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(tO,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Fetch"})]})}),u.jsx(vi,{children:Jbe(t.lastFetchedAt)})]}):u.jsxs(Ie,{variant:"ghost",size:"sm",onClick:()=>void tt(),disabled:U,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[U?u.jsx(bn,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(bk,{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})]}),Fe&&Oe>0?u.jsxs(Ie,{variant:"default",size:"sm",onClick:()=>void tt("push"),disabled:U,className:"h-7 gap-1.5 px-2 text-xs",children:[U?u.jsx(bn,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(Zv,{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:Oe})]}):null,Rt&&Qt?u.jsxs(Ie,{variant:"ghost",size:"sm",onClick:()=>{typeof window>"u"||window.open(Qt,"_blank","noopener,noreferrer")},className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[u.jsx(X5,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"PR"})]}):null]}):u.jsxs(Ie,{variant:"default",size:"sm",onClick:()=>P(!0),className:"h-7 gap-1.5 px-3 text-xs",children:[u.jsx(CG,{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:[ke==="changes"?u.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground/70",children:[u.jsx(vF,{checked:Re,mixed:Ue,label:Ue?"Select all files for commit":Re?"Unselect all files from commit":"Select all files for commit",onClick:()=>{!e||t.files.length===0||It(e,le,Ue?!0:!Re)}}),u.jsxs("span",{children:[he," 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(ji,{value:ke,onValueChange:_e=>{e&&ye(e,_e)},size:"sm",optionClassName:"flex-1 justify-center",options:[{value:"changes",label:"Changes"},{value:"history",label:"History"}]})})}),ke==="changes"?u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(nS,{label:"Unified diff",active:r==="unified",onClick:()=>H("unified"),children:u.jsx(Eq,{className:"h-4 w-4"})}),u.jsx(nS,{label:"Side-by-side diff",active:r==="split",onClick:()=>H("split"),children:u.jsx(AW,{className:"h-4 w-4"})}),u.jsx(nS,{label:i?"Disable word wrap":"Enable word wrap",active:i,onClick:()=>M(!i),children:u.jsx(nK,{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(Ie,{size:"sm",onClick:()=>void E(),children:"Init Git"})]})}):ke==="history"?ze.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:ze.map((_e,De)=>u.jsx(exe,{entry:_e,isPendingPush:De<Oe},_e.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(_e=>{const De=Ee[_e.path]??!0,Ve=_t[_e.path]??!0;return u.jsx(oxe,{file:_e,rootRef:ne,projectId:e,isCollapsed:De,isChecked:Ve,editorLabel:n,diffRenderMode:r,wrapLines:i,onToggleCollapsed:()=>{e&&Mt(e,_e.path)},onToggleChecked:()=>{e&&Pt(e,_e.path,!Ve)},fileActions:D,patch:Y[_e.path],patchError:V[_e.path],isPatchLoading:!!ge[_e.path],onLoadPatch:qe},_e.path)}),ke==="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(un,{value:Pe,onChange:_e=>{e&&an(e,{summary:_e.target.value,description:Ze})},onKeyDown:we,placeholder:"Commit message (override)",className:"rounded-t-xl rounded-b-none px-3",disabled:St||t.status!=="ready"}),u.jsx(La,{value:Ze,onChange:_e=>{e&&an(e,{summary:Pe,description:_e.target.value})},onKeyDown:we,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:St||t.status!=="ready"}),u.jsx("div",{className:"w-full flex flex-row",children:u.jsxs(gu,{children:[u.jsx(vu,{asChild:!0,children:u.jsx(Ie,{type:"button",className:"-mt-px w-full rounded-xl",disabled:Ke?!mt:!xt,onClick:()=>{if(Ke){$t(kt);return}nt()},children:u.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[Ke?vt?u.jsx(bn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):kt==="commit_and_push"?t.hasUpstream?u.jsx(Zv,{strokeWidth:2.5,className:"size-3 shrink-0"}):u.jsx(Y5,{strokeWidth:2.5,className:"size-3 shrink-0"}):u.jsx(ts,{strokeWidth:2.5,className:"size-3 shrink-0"}):O?u.jsx(bn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):u.jsx(lq,{strokeWidth:2.5,className:"size-3 shrink-0"}),u.jsx("span",{className:"min-w-0 truncate text-left",children:Ke?vt?$==="commit_only"?"Committing...":"Committing & Pushing...":kt==="commit_only"?u.jsxs(u.Fragment,{children:["Commit to ",u.jsx(Na,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),pt]}):t.hasUpstream?u.jsxs(u.Fragment,{children:["Commit & push to ",u.jsx(Na,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),pt]}):u.jsxs(u.Fragment,{children:["Commit & publish ",u.jsx(Na,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),pt]}):O?"Generating...":u.jsxs(u.Fragment,{children:["Generate message for ",u.jsx(Na,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),pt]})})]})})}),t.hasUpstream?u.jsx(tc,{children:u.jsx(In,{disabled:!Ke||!mt,onSelect:_e=>{_e.stopPropagation(),$t("commit_only")},children:"Commit Only"})}):null]})})]})})]}):null]})})]}),u.jsx(rxe,{open:te,onOpenChange:P,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:T,onPublish:R})]})})}const lxe=v.memo(axe);function cxe(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function uxe(e,t){const n=getComputedStyle(e.ownerDocument.body),r=parseFloat(n.fontSize);return t*r}function dxe(e){return e/100*window.innerHeight}function hxe(e){return e/100*window.innerWidth}function fxe(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 Vf({groupSize:e,panelElement:t,styleProp:n}){let r;const[i,s]=fxe(n);switch(s){case"%":{r=i/100*e;break}case"px":{r=i;break}case"rem":{r=uxe(t,i);break}case"em":{r=cxe(t,i);break}case"vh":{r=dxe(i);break}case"vw":{r=hxe(i);break}}return r}function Ii(e){return parseFloat(e.toFixed(3))}function eh({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 lC(e){const{panels:t}=e,n=eh({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=Vf({groupSize:n,panelElement:i,styleProp:s.collapsedSize});o=Ii(f/n*100)}let a;if(s.defaultSize!==void 0){const f=Vf({groupSize:n,panelElement:i,styleProp:s.defaultSize});a=Ii(f/n*100)}let c=0;if(s.minSize!==void 0){const f=Vf({groupSize:n,panelElement:i,styleProp:s.minSize});c=Ii(f/n*100)}let d=100;if(s.maxSize!==void 0){const f=Vf({groupSize:n,panelElement:i,styleProp:s.maxSize});d=Ii(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 Rn(e,t="Assertion error"){if(!e)throw Error(t)}function cC(e,t){return Array.from(t).sort(e==="horizontal"?mxe:pxe)}function mxe(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function pxe(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function xF(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function yF(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 gxe({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}=yF(r,o),d=e==="horizontal"?a:c;d<s&&(s=d,i=o)}return Rn(i,"No rect found"),i}let Nv;function vxe(){return Nv===void 0&&(typeof matchMedia=="function"?Nv=!!matchMedia("(pointer:coarse)").matches:Nv=!1),Nv}function _F(e){const{element:t,orientation:n,panels:r,separators:i}=e,s=cC(n,Array.from(t.children).filter(xF).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=gxe({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=vxe()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(R.width<A){const L=A-R.width;R=new DOMRect(R.x-L/2,R.y,R.width+L,R.height)}if(R.height<A){const L=A-R.height;R=new DOMRect(R.x,R.y-L/2,R.width,R.height+L)}const j=y<=d||y>f;!a&&!j&&o.push({group:e,groupSize:eh({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 Fl,b5;let wF=(b5=class{constructor(){Sl(this,Fl,{})}addListener(t,n){const r=gr(this,Fl)[t];return r===void 0?gr(this,Fl)[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=gr(this,Fl)[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(){ms(this,Fl,{})}removeListener(t,n){const r=gr(this,Fl)[t];if(r!==void 0){const i=r.indexOf(n);i>=0&&r.splice(i,1)}}},Fl=new WeakMap,b5),Oo=new Map;const SF=new wF;function bxe(e){Oo=new Map(Oo),Oo.delete(e)}function OI(e,t){for(const[n]of Oo)if(n.id===e)return n}function Gl(e,t){for(const[n,r]of Oo)if(n.id===e)return r;if(t)throw Error(`Could not find data for Group with id ${e}`)}function _u(){return Oo}function x2(e,t){return SF.addListener("groupChange",n=>{n.group.id===e&&t(n)})}function Ha(e,t){const n=Oo.get(e);Oo=new Map(Oo),Oo.set(e,t),SF.emit("groupChange",{group:e,prev:n,next:t})}function xxe(e,t,n){let r,i={x:1/0,y:1/0};for(const s of t){const o=yF(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 yxe(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function _xe(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:FI(e),b:FI(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();Rn(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:BI(zI(n.a)),b:BI(zI(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 wxe=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Sxe(e){const t=getComputedStyle(CF(e)??e).display;return t==="flex"||t==="inline-flex"}function Cxe(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||Sxe(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"||wxe.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function zI(e){let t=e.length;for(;t--;){const n=e[t];if(Rn(n,"Missing node"),Cxe(n))return n}return null}function BI(e){return e&&Number(getComputedStyle(e).zIndex)||0}function FI(e){const t=[];for(;e;)t.push(e),e=CF(e);return t}function CF(e){const{parentNode:t}=e;return yxe(t)?t.host:t}function kxe(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 Exe({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!xF(n)||n.contains(e)||e.contains(n))return!0;if(_xe(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(kxe(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function y2(e,t){const n=[];return t.forEach((r,i)=>{if(i.disabled)return;const s=_F(i),o=xxe(i.orientation,s,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&Exe({groupElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&n.push(o.hitRegion)}),n}function Nxe(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 hi(e,t,n=0){return Math.abs(Ii(e)-Ii(t))<=n}function Ao(e,t){return hi(e,t)?0:e>t?1:-1}function Nd({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(Ao(r,c)<0)if(s){const d=(i+c)/2;Ao(r,d)<0?r=i:r=c}else r=c;return r=Math.min(a,r),r=Ii(r),r}function Wm({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(hi(e,0))return t;const o=s==="imperative-api",a=Object.values(t),c=Object.values(i),d=[...a],[f,m]=r;Rn(f!=null,"Invalid first pivot index"),Rn(m!=null,"Invalid second pivot index");let g=0;switch(s){case"keyboard":{{const _=e<0?m:f,w=n[_];Rn(w,`Panel constraints not found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const T=a[_];if(Rn(T!=null,`Previous layout not found for panel index ${_}`),hi(T,C)){const R=k-T;Ao(R,Math.abs(e))>0&&(e=e<0?0-R:R)}}}{const _=e<0?f:m,w=n[_];Rn(w,`No panel constraints found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const T=a[_];if(Rn(T!=null,`Previous layout not found for panel index ${_}`),hi(T,k)){const R=T-C;Ao(R,Math.abs(e))>0&&(e=e<0?0-R:R)}}}break}default:{const _=e<0?m:f,w=n[_];Rn(w,`Panel constraints not found for index ${_}`);const C=a[_],{collapsible:E,collapsedSize:k,minSize:T}=w;if(E&&Ao(C,T)<0)if(e>0){const R=T-k,A=R/2,j=C+e;Ao(j,T)<0&&(e=Ao(e,A)<=0?0:R)}else{const R=T-k,A=100-R/2,j=C-e;Ao(j,T)<0&&(e=Ao(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];Rn(k!=null,`Previous layout not found for panel index ${w}`);const T=Nd({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[_];Rn(C!=null,`Previous layout not found for panel index ${_}`);const E=C-w,k=Nd({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:C,size:E});if(!hi(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(Nxe(c,d))return i;{const _=e<0?m:f,w=a[_];Rn(w!=null,`Previous layout not found for panel index ${_}`);const C=w+g,E=Nd({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:w,size:C});if(d[_]=E,!hi(E,C)){let k=C-E,T=e<0?m:f;for(;T>=0&&T<n.length;){const R=d[T];Rn(R!=null,`Previous layout not found for panel index ${T}`);const A=R+k,j=Nd({overrideDisabledPanels:o,panelConstraints:n[T],prevSize:R,size:A});if(hi(R,j)||(k-=j-R,d[T]=j),hi(k,0))break;e>0?T--:T++}}}const b=Object.values(d).reduce((_,w)=>w+_,0);if(!hi(b,100,.1))return i;const y=Object.keys(i);return d.reduce((_,w,C)=>(_[y[C]]=w,_),{})}function iu(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(t[n]===void 0||Ao(e[n],t[n])!==0)return!1;return!0}function su({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(!hi(i,100)&&r.length>0)for(let a=0;a<t.length;a++){const c=r[a];Rn(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];Rn(c!=null,`No layout data found for index ${a}`);const d=r[a];Rn(d!=null,`No layout data found for index ${a}`);const f=Nd({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:c,size:d});d!=f&&(s+=d-f,r[a]=f)}if(!hi(s,0))for(let a=0;a<t.length;a++){const c=r[a];Rn(c!=null,`No layout data found for index ${a}`);const d=c+s,f=Nd({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:c,size:d});if(c!==f&&(s-=f-c,r[a]=f,hi(s,0)))break}const o=Object.keys(e);return r.reduce((a,c,d)=>(a[o[d]]=c,a),{})}function kF({groupId:e,panelId:t}){const n=()=>{const a=_u();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=Wm({delta:w?c-a:a-c,initialLayout:b,panelConstraints:f,pivotIndices:w?[_-1,_]:[_,_+1],prevLayout:b,trigger:"imperative-api"}),E=su({layout:C,panelConstraints:f});iu(b,E)||Ha(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&&hi(c,d)},resize:a=>{const{group:c}=n(),{element:d}=i(),f=eh({group:c}),m=Vf({groupSize:f,panelElement:d,styleProp:a}),g=Ii(m/f*100);o(g)}}}function $I(e){if(e.defaultPrevented)return;const t=_u();y2(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=kF({groupId:n.group.id,panelId:r.id});s&&i!==void 0&&(s.resize(i),e.preventDefault())}}})}function mb(e){const t=_u();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 EF({groupId:e}){const t=()=>{const n=_u();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=su({layout:n,panelConstraints:i});return r?a:(iu(a,d)||Ha(s,{defaultLayoutDeferred:r,derivedPanelConstraints:i,groupSize:o,layout:d,separatorToPanels:c}),d)}}}function Ac(e,t){const n=mb(e),r=Gl(n.id,!0),i=n.separators.find(f=>f.element===e);Rn(i,"Matching separator not found");const s=r.separatorToPanels.get(i);Rn(s,"Matching panels not found");const o=s.map(f=>n.panels.indexOf(f)),a=EF({groupId:n.id}).getLayout(),c=Wm({delta:t,initialLayout:a,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:a,trigger:"keyboard"}),d=su({layout:c,panelConstraints:r.derivedPanelConstraints});iu(a,d)||Ha(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:d,separatorToPanels:r.separatorToPanels})}function HI(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=mb(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&Ac(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&Ac(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&Ac(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&Ac(t,-5);break}case"End":{e.preventDefault(),Ac(t,100);break}case"Enter":{e.preventDefault();const r=mb(t),i=Gl(r.id,!0),{derivedPanelConstraints:s,layout:o,separatorToPanels:a}=i,c=r.separators.find(g=>g.element===t);Rn(c,"Matching separator not found");const d=a.get(c);Rn(d,"Matching panels not found");const f=d[0],m=s.find(g=>g.panelId===f.id);if(Rn(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;Ac(t,b-g)}break}case"F6":{e.preventDefault();const r=mb(t).separators.map(o=>o.element),i=Array.from(r).findIndex(o=>o===e.currentTarget);Rn(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(),Ac(t,-100);break}}}let Bd={cursorFlags:0,state:"inactive"};const _2=new wF;function ou(){return Bd}function Txe(e){return _2.addListener("change",e)}function Rxe(e){const t=Bd,n={...Bd};n.cursorFlags=e,Bd=n,_2.emit("change",{prev:t,next:n})}function Fd(e){const t=Bd;Bd=e,_2.emit("change",{prev:t,next:e})}function UI(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=_u(),n=y2(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)}),Fd({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}const Axe=e=>e,rS=()=>{},NF=1,TF=2,RF=4,AF=8,VI=3,WI=12;let Tv;function GI(){return Tv===void 0&&(Tv=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(Tv=!0)),Tv}function jxe({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&&GI()){const s=(e&NF)!==0,o=(e&TF)!==0,a=(e&RF)!==0,c=(e&AF)!==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 GI()?r>0&&i>0?"move":r>0?"ew-resize":"ns-resize":r>0&&i>0?"grab":r>0?"col-resize":"row-resize"}}const qI=new WeakMap;function w2(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=qI.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&e.adoptedStyleSheets.push(n));const r=ou();switch(r.state){case"active":case"hover":{const i=jxe({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}}qI.set(e,{prevStyle:t,styleSheet:n})}function jF({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=Wm({delta:_,initialLayout:w,panelConstraints:k,pivotIndices:d.panels.map(L=>b.indexOf(L)),prevLayout:R,trigger:"mouse-or-touch"});if(iu(j,R)){if(_!==0&&!y)switch(g){case"horizontal":{a|=_<0?NF:TF;break}case"vertical":{a|=_<0?RF:AF;break}}}else Ha(d.group,{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:T,layout:j,separatorToPanels:A})}});let c=0;t.movementX===0?c|=o&VI:c|=a&VI,t.movementY===0?c|=o&WI:c|=a&WI,Rxe(c),w2(e)}function KI(e){const t=_u(),n=ou();switch(n.state){case"active":jF({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function YI(e){if(e.defaultPrevented)return;const t=ou(),n=_u();switch(t.state){case"active":{if(e.buttons===0){Fd({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(r=>{const i=Gl(r.group.id,!0);Ha(r.group,i)});return}jF({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const r=y2(e,n);r.length===0?t.state!=="inactive"&&Fd({cursorFlags:0,state:"inactive"}):Fd({cursorFlags:0,hitRegions:r,state:"hover"}),w2(e.currentTarget);break}}}function XI(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(ou().state){case"hover":Fd({cursorFlags:0,state:"inactive"})}}function QI(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=ou();switch(t.state){case"active":Fd({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(w2(e.currentTarget),t.hitRegions.forEach(n=>{const r=Gl(n.group.id,!0);Ha(n.group,r)}),e.preventDefault())}}function ZI(e){let t=0,n=0;const r={};for(const s of e)if(s.defaultSize!==void 0){t++;const o=Ii(s.defaultSize);n+=o,r[s.panelId]=o}else r[s.panelId]=void 0;const i=e.length-t;if(i!==0){const s=Ii((100-n)/i);for(const o of e)o.defaultSize===void 0&&(r[o.panelId]=s)}return r}function Mxe(e,t,n){if(!n[0])return;const r=e.panels.find(c=>c.element===t);if(!r||!r.onResize)return;const i=eh({group:e}),s=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,a={asPercentage:Ii(s/i*100),inPixels:s};r.mutableValues.prevSize=a,r.onResize(a,r.id,o)}function Lxe(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 Ixe({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=Ii(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]=Ii(g/s*d)}else{const m=Ii(d/c.length);for(const g of c)f[g]=m}return f}function Dxe(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 md=new Map;function Pxe(e){let t=!0;Rn(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=eh({group:e});if(E===0)return;const k=Gl(e.id);if(!k)return;const T=lC(e),R=k.defaultLayoutDeferred?ZI(T):k.layout,A=Ixe({group:e,nextGroupSize:E,prevGroupSize:k.groupSize,prevLayout:R}),j=su({layout:A,panelConstraints:T});if(!k.defaultLayoutDeferred&&iu(k.layout,j)&&Lxe(k.derivedPanelConstraints,T)&&k.groupSize===E)return;Ha(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:T,groupSize:E,layout:j,separatorToPanels:k.separatorToPanels})}}else Mxe(e,C,w)}});s.observe(e.element),e.panels.forEach(y=>{Rn(!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=eh({group:e}),a=lC(e),c=e.panels.map(({id:y})=>y).join(",");let d=e.mutableState.defaultLayout;d&&(Dxe(e.panels,d)||(d=void 0));const f=e.mutableState.layouts[c]??d??ZI(a),m=su({layout:f,panelConstraints:a}),g=e.element.ownerDocument;md.set(g,(md.get(g)??0)+1);const b=new Map;return _F(e).forEach(y=>{y.separator&&b.set(y.separator,y.panels)}),Ha(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:a,groupSize:o,layout:m,separatorToPanels:b}),e.separators.forEach(y=>{Rn(!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",HI)}),md.get(g)===1&&(g.addEventListener("dblclick",$I,!0),g.addEventListener("pointerdown",UI,!0),g.addEventListener("pointerleave",KI),g.addEventListener("pointermove",YI),g.addEventListener("pointerout",XI),g.addEventListener("pointerup",QI,!0)),function(){t=!1,md.set(g,Math.max(0,(md.get(g)??0)-1)),bxe(e),e.separators.forEach(y=>{y.element.removeEventListener("keydown",HI)}),md.get(g)||(g.removeEventListener("dblclick",$I,!0),g.removeEventListener("pointerdown",UI,!0),g.removeEventListener("pointerleave",KI),g.removeEventListener("pointermove",YI),g.removeEventListener("pointerout",XI),g.removeEventListener("pointerup",QI,!0)),s.disconnect()}}function Oxe(){const[e,t]=v.useState({}),n=v.useCallback(()=>t({}),[]);return[e,n]}function S2(e){const t=v.useId();return`${e??t}`}const wu=typeof window<"u"?v.useLayoutEffect:v.useEffect;function lm(e){const t=v.useRef(e);return wu(()=>{t.current=e},[e]),v.useCallback((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[t])}function C2(...e){return lm(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function k2(e){const t=v.useRef({...e});return wu(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const MF=v.createContext(null);function zxe(e,t){const n=v.useRef({getLayout:()=>({}),setLayout:Axe});v.useImperativeHandle(t,()=>n.current,[]),wu(()=>{Object.assign(n.current,EF({groupId:e}))})}function LF({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:{}}),_=lm(D=>{iu(y.current.onLayoutChange,D)||(y.current.onLayoutChange=D,c==null||c(D))}),w=lm(D=>{iu(y.current.onLayoutChanged,D)||(y.current.onLayoutChanged=D,d==null||d(D))}),C=S2(a),E=v.useRef(null),[k,T]=Oxe(),R=v.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:m,separators:[]}),A=C2(E,s);zxe(C,o);const j=lm((D,z)=>{const O=ou(),F=OI(D),$=Gl(D);if($){let B=!1;switch(O.state){case"active":{B=O.hitRegions.some(U=>U.group===F);break}}return{flexGrow:$.layout[z]??1,pointerEvents:B?"none":void 0}}return{flexGrow:(n==null?void 0:n[z])??1}}),L=k2({defaultLayout:n,disableCursor:r}),H=v.useMemo(()=>({get disableCursor(){return!!L.disableCursor},getPanelStyles:j,id:C,orientation:f,registerPanel:D=>{const z=R.current;return z.panels=cC(f,[...z.panels,D]),T(),()=>{z.panels=z.panels.filter(O=>O!==D),T()}},registerSeparator:D=>{const z=R.current;return z.separators=cC(f,[...z.separators,D]),T(),()=>{z.separators=z.separators.filter(O=>O!==D),T()}},togglePanelDisabled:(D,z)=>{const O=R.current.panels.find(B=>B.id===D);O&&(O.panelConstraints.disabled=z);const F=OI(C),$=Gl(C);F&&$&&Ha(F,{...$,derivedPanelConstraints:lC(F)})},toggleSeparatorDisabled:(D,z)=>{const O=R.current.separators.find(F=>F.id===D);O&&(O.disabled=z)}}),[j,C,T,f,L]),M=v.useRef(null);return wu(()=>{const D=E.current;if(D===null)return;const z=R.current;let O;if(L.defaultLayout!==void 0&&Object.keys(L.defaultLayout).length===z.panels.length){O={};for(const P of z.panels){const Y=L.defaultLayout[P.id];Y!==void 0&&(O[P.id]=Y)}}const F={disabled:!!i,element:D,id:C,mutableState:{defaultLayout:O,disableCursor:!!L.disableCursor,expandedPanelSizes:R.current.lastExpandedPanelSizes,layouts:R.current.layouts},orientation:f,panels:z.panels,resizeTargetMinimumSize:z.resizeTargetMinimumSize,separators:z.separators};M.current=F;const $=Pxe(F),{defaultLayoutDeferred:B,derivedPanelConstraints:U,layout:G}=Gl(F.id,!0);!B&&U.length>0&&(_(G),w(G));const te=x2(C,P=>{const{defaultLayoutDeferred:Y,derivedPanelConstraints:ee,layout:V}=P.next;if(Y||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}=P.prev??{};if(ne){const ie=hi(Z.collapsedSize,V[Z.panelId]),le=hi(Z.collapsedSize,ne[Z.panelId]);ie&&!le&&(F.mutableState.expandedPanelSizes[Z.panelId]=ne[Z.panelId])}}});const ge=ou().state!=="active";_(V),ge&&w(V)});return()=>{M.current=null,$(),te()}},[i,C,w,_,f,k,L]),v.useEffect(()=>{const D=M.current;D&&(D.mutableState.defaultLayout=n,D.mutableState.disableCursor=!!r)}),u.jsx(MF.Provider,{value:H,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})})}LF.displayName="Group";function E2(){const e=v.useContext(MF);return Rn(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function Bxe(e,t){const{id:n}=E2(),r=v.useRef({collapse:rS,expand:rS,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:rS});v.useImperativeHandle(t,()=>r.current,[]),wu(()=>{Object.assign(r.current,kF({groupId:n,panelId:e}))})}function IF({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=S2(c),C=k2({disabled:s}),E=v.useRef(null),k=C2(E,o),{getPanelStyles:T,id:R,orientation:A,registerPanel:j,togglePanelDisabled:L}=E2(),H=m!==null,M=lm((z,O,F)=>{m==null||m(z,c,F)});wu(()=>{const z=E.current;if(z!==null){const O={element:z,id:w,idIsStable:_,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:H?M:void 0,panelConstraints:{groupResizeBehavior:a,collapsedSize:n,collapsible:r,defaultSize:i,disabled:C.disabled,maxSize:d,minSize:f}};return j(O)}},[a,n,r,i,H,w,_,d,f,M,j,C]),v.useEffect(()=>{L(w,!!s)},[s,w,L]),Bxe(w,g);const D=v.useSyncExternalStore(z=>x2(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:{...Fxe,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})})}IF.displayName="Panel";const Fxe={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function $xe({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=su({layout:Wm({delta:d-o,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e}),panelConstraints:t})[n],i=su({layout:Wm({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:s,valueNow:o}}function DF({children:e,className:t,disabled:n,elementRef:r,id:i,style:s,...o}){const a=S2(i),c=k2({disabled:n}),[d,f]=v.useState({}),[m,g]=v.useState("inactive"),b=v.useRef(null),y=C2(b,r),{disableCursor:_,id:w,orientation:C,registerSeparator:E,toggleSeparatorDisabled:k}=E2(),T=C==="horizontal"?"vertical":"horizontal";wu(()=>{const A=b.current;if(A!==null){const j={disabled:c.disabled,element:A,id:a},L=E(j),H=Txe(D=>{g(D.next.state!=="inactive"&&D.next.hitRegions.some(z=>z.separator===j)?D.next.state:"inactive")}),M=x2(w,D=>{const{derivedPanelConstraints:z,layout:O,separatorToPanels:F}=D.next,$=F.get(j);if($){const B=$[0],U=$.indexOf(B);f($xe({layout:O,panelConstraints:z,panelId:B.id,panelIndex:U}))}});return()=>{H(),M(),L()}}},[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})}DF.displayName="Separator";const N2=({className:e,...t})=>u.jsx(LF,{className:de("flex h-full w-full",e),...t}),Gm=e=>u.jsx(IF,{...e}),T2=({withHandle:e,orientation:t,disabled:n,className:r,...i})=>u.jsx(DF,{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 PF(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 Hxe(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 PF(r.usage,new Date(r.createdAt).toISOString(),t)}return null}function Uxe(e,t){return!e||t===null||!Number.isFinite(t)||t<=0?e:PF({...e,maxTokens:t},e.updatedAt,e.compactsAutomatically)}function Vxe(e){if(!e)return null;const t=iS(e.inputTokens),n=iS(e.outputTokens),r=iS(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 iS(e){return e===void 0||!Number.isFinite(e)||e<0?0:e}function Li(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 R2=[68,32];function Wxe(){return{isVisible:!1,mainSizes:[...R2],terminals:[],nextTerminalIndex:0}}function Gxe(e,t){return e[t]??Wxe()}function sS(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 qxe(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 Kxe(e){if(e.length===0)return e;const t=e.length+1;return e.map(n=>({...n,size:n.size*e.length/t}))}function pd(e,t,n){return{...e,[t]:n(Gxe(e,t))}}const Il=is()(Ch(e=>({projects:{},addTerminal:(t,n)=>e(r=>({projects:pd(r.projects,t,i=>{var c,d;const s=Kxe(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:qxe(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:pd(r.projects,t,i=>{const s=i.terminals.filter(a=>a.id!==n);if(s.length===0)return{...i,isVisible:!1,terminals:[]};const o=sS(s.map(a=>a.size));return{...i,terminals:s.map((a,c)=>({...a,size:o[c]??100/s.length}))}})})),toggleVisibility:t=>e(n=>({projects:pd(n.projects,t,r=>({...r,isVisible:r.terminals.length>0?!r.isVisible:!1}))})),resetMainSizes:t=>e(n=>({projects:pd(n.projects,t,r=>({...r,mainSizes:[...R2]}))})),setMainSizes:(t,n)=>e(r=>{if(n.length!==2)return r;const i=sS(n);return{projects:pd(r.projects,t,s=>({...s,mainSizes:i}))}}),setTerminalSizes:(t,n)=>e(r=>({projects:pd(r.projects,t,i=>{if(n.length!==i.terminals.length)return i;const s=sS(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})),Yxe={isVisible:!1,mainSizes:[...R2],terminals:[],nextTerminalIndex:0},Xxe=35;function Qxe(e,t){return!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<=0?0:e*(t/100)}function Zxe(e,t){const n=Qxe(e,t);return n>=0&&n<Xxe}const wy=350,Jxe=[.4,0,.2,1],eye=8,JI=1e-6;function tye(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function nye(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function rye(e,t,n){const r=1-e;return 3*r*r*t+6*r*e*(n-t)+3*e*e*(1-n)}function iye(e,t,n){let r=e;for(let i=0;i<eye;i+=1){const s=tye(r,t,n)-e;if(Math.abs(s)<JI)return r;const o=rye(r,t,n);if(Math.abs(o)<JI)break;r-=s/o}return r}function sye(e){if(e<=0)return 0;if(e>=1)return 1;const[t,n,r,i]=Jxe,s=iye(e,t,r);return nye(s,n,i)}function OF(e,t,n){const r=sye(n);return[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r]}function oye({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,L,H,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"),(L=o.current)==null||L.setAttribute("data-right-sidebar-open",n?"true":"false"),(H=o.current)==null||H.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=O=>{const F=Math.min(1,(O-R)/wy),$=OF(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 aye(e){return e.visibilityState==="visible"?e.activeChatId:null}function lye(e){e.socket.setFocusedChat(aye({activeChatId:e.activeChatId,visibilityState:e.visibilityState}))}function cye({socket:e,activeChatId:t}){v.useEffect(()=>{if(typeof document>"u")return;const n=()=>{lye({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 uye({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(Lj({trigger:"pointer",activeElement:document.activeElement,pointerStartTarget:s,pointerEndTarget:g,root:b,fallback:y,hasActiveOverlay:Mj(document),hasActiveSelection:PX(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;Lj({trigger:"escape",activeElement:document.activeElement,fallback:g,hasActiveOverlay:Mj(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(Ab,d),()=>{cancelAnimationFrame(i),window.removeEventListener("pointerdown",a,!0),window.removeEventListener("pointerup",c,!0),window.removeEventListener("keydown",f,!0),window.removeEventListener(Ab,d)}},[r,n,t,e])}function dye(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 hye({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 fye({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;dye({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 L,H,M,D,z,O;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}=hye({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]}),(L=o.current)==null||L.setAttribute("data-terminal-open",r?"true":"false"),(H=a.current)==null||H.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"),(O=a.current)==null||O.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)/wy),B=OF(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 eD=e=>Symbol.iterator in e,tD=e=>"entries"in e,nD=(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},mye=(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 pye(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:eD(e)&&eD(t)?tD(e)&&tD(t)?nD(e,t):mye(e,t):nD({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function cx(e){const t=yn.useRef(void 0);return n=>{const r=e(n);return pye(t.current,r)?t.current:t.current=r}}const cm="__new__";function jc(e){var s,o;const t=(s=e==null?void 0:e.modelOptions)==null?void 0:s.reasoningEffort,n=d1(t)?t:d1(e==null?void 0:e.effort)?e.effort:Zc.reasoningEffort,r=ere(e==null?void 0:e.model),i=bE(r,(o=e==null?void 0:e.modelOptions)==null?void 0:o.contextWindow);return{model:r,modelOptions:{reasoningEffort:!fz(r)&&n==="max"?"high":n,contextWindow:i},planMode:!!(e!=null&&e.planMode)}}function Rv(e){var n,r;const t=(n=e==null?void 0:e.modelOptions)==null?void 0:n.reasoningEffort;return{model:tre(e==null?void 0:e.model),modelOptions:{reasoningEffort:h1(t)?t:h1(e==null?void 0:e.effort)?e.effort:Tm.reasoningEffort,fastMode:typeof((r=e==null?void 0:e.modelOptions)==null?void 0:r.fastMode)=="boolean"?e.modelOptions.fastMode:Tm.fastMode},planMode:!!(e!=null&&e.planMode)}}function gye(){return{claude:{model:"claude-opus-4-7",modelOptions:{...Zc},planMode:!1},codex:{model:"gpt-5.5",modelOptions:{...Tm},planMode:!1}}}function vye(e,t){return e.reasoningEffort===t.reasoningEffort&&e.contextWindow===t.contextWindow}function bye(e,t){return e.reasoningEffort===t.reasoningEffort&&e.fastMode===t.fastMode}function xye(e,t){return e.claude.model===t.claude.model&&e.claude.planMode===t.claude.planMode&&vye(e.claude.modelOptions,t.claude.modelOptions)&&e.codex.model===t.codex.model&&e.codex.planMode===t.codex.planMode&&bye(e.codex.modelOptions,t.codex.modelOptions)}function yye(e,t){if(t===void 0){console.info(`[chat-preferences] ${e}`);return}console.info(`[chat-preferences] ${e}`,t)}function um(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 uC(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 zF(e){return e.providerHint?um(e.providerHint,e.providerDefaults):e.defaultProvider==="last_used"?e.sourceState?uC(e.sourceState):um("claude",e.providerDefaults):um(e.defaultProvider,e.providerDefaults)}function BF(e,t){const n=e.chatStates[t];return n||zF({defaultProvider:e.defaultProvider,providerDefaults:e.providerDefaults,legacyComposerState:e.legacyComposerState})}function Av(e,t,n){const r=BF(e,t);return{chatStates:{...e.chatStates,[t]:n(r)}}}const mi=is()(Ch((e,t)=>({defaultProvider:"last_used",providerDefaults:gye(),chatStates:{},legacyComposerState:{provider:"claude",model:"claude-opus-4-7",modelOptions:{...Zc},planMode:!1},setDefaultProvider:n=>e({defaultProvider:n}),applyServerDefaults:(n,r)=>e(i=>{if(i.defaultProvider===n&&xye(i.providerDefaults,r))return{defaultProvider:n,providerDefaults:r};const{[cm]:o,...a}=i.chatStates;return{defaultProvider:n,providerDefaults:r,chatStates:a}}),setProviderDefaultModel:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?jc({...i.providerDefaults.claude,model:r}):Rv({...i.providerDefaults.codex,model:r})}})),setProviderDefaultModelOptions:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?jc({...i.providerDefaults.claude,modelOptions:{...i.providerDefaults.claude.modelOptions,...r}}):Rv({...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=>uC(BF(t(),n)),initializeComposerForChat:(n,r)=>e(i=>{if(i.chatStates[n])return i;const s=zF({defaultProvider:i.defaultProvider,providerDefaults:i.providerDefaults,sourceState:r==null?void 0:r.sourceState,legacyComposerState:i.legacyComposerState,providerHint:r==null?void 0:r.providerHint});return yye("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:jc(r).model,modelOptions:jc(r).modelOptions,planMode:r.planMode}:uC(r)}})),setChatComposerProvider:(n,r)=>e(i=>Av(i,n,()=>um(r,i.providerDefaults))),setChatComposerModel:(n,r)=>e(i=>Av(i,n,s=>s.provider==="claude"?{provider:"claude",model:jc({...s,model:r}).model,modelOptions:jc({...s,model:r}).modelOptions,planMode:s.planMode}:{provider:"codex",model:r,modelOptions:Rv({...s,model:r}).modelOptions,planMode:s.planMode})),setChatComposerModelOptions:(n,r)=>e(i=>Av(i,n,s=>s.provider==="claude"?{provider:"claude",model:s.model,modelOptions:jc({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode}:{provider:"codex",model:s.model,modelOptions:Rv({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode})),setChatComposerPlanMode:(n,r)=>e(i=>Av(i,n,s=>({...s,planMode:r}))),resetChatComposerFromProvider:(n,r)=>e(i=>({chatStates:{...i.chatStates,[n]:um(r,i.providerDefaults)}}))}),{name:"chat-preferences-state",version:1,partialize:e=>({chatStates:e.chatStates,legacyComposerState:e.legacyComposerState})})),dC=is()(Ch((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"})),A2=is()(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 _ye(e){return{autoResumeOnRateLimit:!!(e!=null&&e.autoResumeOnRateLimit)}}const hC=is()(Ch(e=>({autoResumeOnRateLimit:!1,setAutoResumeOnRateLimit:t=>e({autoResumeOnRateLimit:t})}),{name:"kanna-preferences",version:1,migrate:e=>_ye(e)}));function gd(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function jv(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function wye(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 oS(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 Sye(e,t){var r;const n=jv(t);switch(e.toolKind){case"ask_user_question":{const o=oS(n),a=o!==null?jv(o):n,c=gd(a),d=gd(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=oS(n),a=o!==null?jv(o):n,c=gd(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=oS(n),a=o?jv(o):n,c=gd(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=gd(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=wye(n);if(i.length>0)return{content:i.flatMap(o=>o.type==="text"?[o.text]:[]).join(""),blocks:i};const s=gd(n);return{content:typeof(s==null?void 0:s.content)=="string"?s.content:JSON.stringify(n,null,2)};default:return n}}function FF(e){return new Date(e).toISOString()}function Tr(e){return{id:e._id,messageId:e.messageId,timestamp:FF(e.createdAt),hidden:e.hidden}}function Cye(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:FF(e.createdAt)}}function kye(e){if(e.debugRaw)try{return JSON.parse(e.debugRaw).tool_use_result}catch{return}}function jo(e){return typeof e=="number"?e:void 0}function Mv(e){return typeof e=="string"?e:void 0}function Eye(e){if(!e||typeof e!="object")return;const t=e,n={readCount:jo(t.readCount),searchCount:jo(t.searchCount),bashCount:jo(t.bashCount),editFileCount:jo(t.editFileCount),linesAdded:jo(t.linesAdded),linesRemoved:jo(t.linesRemoved),otherToolCount:jo(t.otherToolCount)};return Object.values(n).some(r=>r!==void 0)?n:void 0}function Nye(e){if(!e.debugRaw)return;let t;try{t=JSON.parse(e.debugRaw).toolUseResult}catch{return}if(!t||typeof t!="object")return;const n=t,r={agentId:Mv(n.agentId),agentType:Mv(n.agentType),status:Mv(n.status),totalTokens:jo(n.totalTokens),totalDurationMs:jo(n.totalDurationMs),totalToolUseCount:jo(n.totalToolUseCount),toolStats:Eye(n.toolStats),content:Mv(n.content)};return r.agentId!==void 0||r.agentType!==void 0||r.totalTokens!==void 0||r.totalDurationMs!==void 0||r.status!==void 0?r:void 0}function j2(e){const t=new Map,n=[];for(const r of e)switch(r.kind){case"user_prompt":n.push({...Tr(r),kind:"user_prompt",content:r.content,attachments:r.attachments??[],steered:r.steered,autoContinue:r.autoContinue});break;case"system_init":n.push({...Tr(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({...Tr(r),kind:"account_info",accountInfo:r.accountInfo});break;case"assistant_text":n.push({...Tr(r),kind:"assistant_text",text:r.text});break;case"assistant_thinking":n.push({...Tr(r),kind:"assistant_thinking",text:r.text,signature:r.signature});break;case"api_error":n.push({...Tr(r),kind:"api_error",status:r.status,text:r.text,requestId:r.requestId});break;case"policy_refusal":n.push({...Tr(r),kind:"policy_refusal",text:r.text,requestId:r.requestId});break;case"tool_call":{const i=Cye(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"?kye(r)??r.content:r.content;i.normalized.toolKind==="subagent_task"?i.hydrated.result=Nye(r):i.hydrated.result=Sye(i.normalized,s),i.hydrated.rawResult=s,i.hydrated.isError=r.isError,r.persisted&&(i.hydrated.persisted=r.persisted)}break}case"result":n.push({...Tr(r),kind:"result",success:!r.isError,cancelled:r.subtype==="cancelled",result:r.result,durationMs:r.durationMs,costUsd:r.costUsd});break;case"status":n.push({...Tr(r),kind:"status",status:r.status});break;case"context_window_updated":n.push({...Tr(r),kind:"context_window_updated",usage:r.usage});break;case"compact_boundary":n.push({...Tr(r),kind:"compact_boundary"});break;case"compact_summary":n.push({...Tr(r),kind:"compact_summary",summary:r.summary});break;case"context_cleared":n.push({...Tr(r),kind:"context_cleared"});break;case"interrupted":n.push({...Tr(r),kind:"interrupted"});break;case"memory_loaded":n.push({...Tr(r),kind:"memory_loaded",path:r.path});break;case"auto_continue_prompt":n.push({...Tr(r),kind:"auto_continue_prompt",scheduleId:r.scheduleId});break;case"pending_tool_request":n.push({...Tr(r),kind:"pending_tool_request",toolRequestId:r.toolRequestId,toolName:r.toolName,arguments:r.arguments});break;case"tool_request_resolved":break;default:n.push({...Tr(r),kind:"unknown",json:JSON.stringify(r,null,2)});break}return n}const Tye=["AskUserQuestion","ExitPlanMode","TodoWrite"],Rye=new Set(["TodoWrite"]);function Aye(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 jye(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 Mye(e){const t={};for(const n of Tye)t[n]=Rye.has(n)?jye(e,n):Aye(e,n);return t}function Lye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}function Iye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}const M2="pushDeviceId";function $F(){return typeof localStorage>"u"?null:localStorage.getItem(M2)}function Dye(e){typeof localStorage>"u"||localStorage.setItem(M2,e)}function Pye(){typeof localStorage>"u"||localStorage.removeItem(M2)}function Oye(){return!(typeof window>"u"||typeof Notification>"u"||!("serviceWorker"in navigator)||typeof globalThis.PushManager>"u")}function zye(){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 fC(){if(!Oye())return{state:"unsupported"};if(!zye())return{state:"insecure-context"};switch(Notification.permission){case"granted":return{state:"granted"};case"denied":return{state:"denied"};default:return{state:"default"}}}function Bye(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 Fye(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 $ye(e){const t=fC();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:Bye(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:Fye(c),userAgent:c});return d}async function Hye(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 Uye=25e3,Vye=15e3,Wye=4e3,rD="kanna:profile-send-to-starting";function iD(){try{return window.sessionStorage.getItem(rD)==="1"||window.localStorage.getItem(rD)==="1"}catch{return!1}}class Gye{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=Pc();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=Pc(),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=Pc(),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=Pc();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=$F();t&&this.sendNow({v:1,type:"command",id:Pc(),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(iD()&&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}),iD()&&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(zZ,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>=Uye}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()},Wye),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()},Vye))}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 qye=[],L2=is()(e=>({byChat:{},setRuns:(t,n)=>e(r=>({byChat:{...r.byChat,[t]:n}}))}));function HF(e){return t=>t.byChat[e]??qye}function Kye(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 Yye(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&&Kye(e.sessionTokensByProvider,t.sessionTokensByProvider)}function Xye(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 Qye(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 Zye(e,t){return e===t?!0:!e||!t?!1:e.hasOlder===t.hasOlder&&e.olderCursor===t.olderCursor&&e.recentLimit===t.recentLimit}function Jye(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)&&e0e(e.attachments,t.attachments)}function e0e(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 t0e(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>Jye(n,t[r]))}function n0e(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 r0e(e,t){return!!(e&&e.status!=="unknown"&&t&&t.status==="unknown"&&t.files.length===0)}function i0e(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 s0e(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 o0e(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 a0e(e,t){return e===t?!0:!e||!t?!1:Yye(e.runtime,t.runtime)&&t0e(e.queuedMessages,t.queuedMessages)&&Xye(e.messages,t.messages)&&Zye(e.history,t.history)&&Qye(e.availableProviders,t.availableProviders)&&i0e(e.schedules,t.schedules)&&e.liveScheduleId===t.liveScheduleId&&s0e(e.tunnels,t.tunnels)&&e.liveTunnelId===t.liveTunnelId&&o0e(e.subagentRuns,t.subagentRuns)}function sD(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 l0e(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 oD="__new_chat__",UF="lever-theme",VF="chat-sound-preferences",WF="terminal-preferences",GF="chat-preferences";function aS(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 c0e(){if(typeof window>"u")return null;const e={},t=window.localStorage.getItem(UF);(t==="light"||t==="dark"||t==="system")&&(e.theme=t);const n=aS(VF);((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=aS(WF);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=aS(GF);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 u0e(){typeof window>"u"||(window.localStorage.removeItem(UF),window.localStorage.removeItem(VF),window.localStorage.removeItem(WF),window.localStorage.removeItem(GF))}function Lf(e){Mi.getState().setFromServer(e);const t=di.getState();t.setScrollbackLines(e.terminal.scrollbackLines),t.setMinColumnWidth(e.terminal.minColumnWidth),t.setEditorPreset(e.editor.preset),t.setEditorCommandTemplate(e.editor.commandTemplate);const n=Bc.getState();n.setChatSoundPreference(e.chatSoundPreference),n.setChatSoundId(e.chatSoundId),mi.getState().applyServerDefaults(e.defaultProvider,e.providerDefaults)}function d0e(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 I2(e,t=[]){return JSON.stringify({content:e,attachments:t.map(d0e)})}function h0e(e,t){return e.reduce((n,r)=>r.kind!=="user_prompt"?n:n+(I2(r.content,r.attachments??[])===t?1:0),0)}function f0e(e,t,n){const r=new Map;for(const i of n){if(i.kind!=="user_prompt")continue;const s=I2(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 m0e(e,t,n){return e.some(r=>r.id===t)?e.filter(r=>r.id!==t):e}const p0e=200,g0e=500;function aD(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 lD(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 v0e(e=document){return e.visibilityState==="visible"&&e.hasFocus()}function b0e(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`}function x0e(){const[e]=v.useState(()=>new Gye(b0e()));return v.useEffect(()=>(e.start(),()=>{e.dispose()}),[e]),e}const cD="kanna:profile-send-to-starting";function y0e(){try{return window.sessionStorage.getItem(cD)==="1"||window.localStorage.getItem(cD)==="1"}catch{return!1}}function qF(e){return Number((performance.now()-e).toFixed(1))}function Nl(e,t,n){!e||!y0e()||console.debug("[kanna/send->starting][client]",{traceId:e.traceId,stage:t,elapsedMs:qF(e.startedAt),serverChatId:e.serverChatId,routeChatIdAtSend:e.routeChatIdAtSend,...n})}function _0e(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 w0e(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 S0e(e,t){return e==="awaiting_disconnect"&&t==="disconnected"?"awaiting_server_ready":"none"}function C0e(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 k0e=30,D2="kanna:ui-update-restart",KF="kanna:last-update-reload-request";function E0e(e){return e+k0e}function N0e(e,t){return t>0?t:e}function lS(){return window.sessionStorage.getItem(D2)}function T0e(e){window.sessionStorage.setItem(D2,e)}function R0e(){window.sessionStorage.removeItem(D2)}function A0e(e,t){return e?String(e)!==t:!1}function j0e(){return window.sessionStorage.getItem(KF)}function M0e(e){window.sessionStorage.setItem(KF,String(e))}function L0e(){return"/auth/status"}async function I0e(e=fetch){return(await e(L0e(),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}})).ok}function D0e(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 P0e(e,t){return!e||!t?null:e.runtime.chatId!==t?(e.runtime.chatId,e.runtime.provider,null):e}function O0e(e){var Nu,uc,Ih;const t=du(),n=x0e(),r=up(),[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(()=>lS()),y=v.useCallback(Q=>{T0e(Q),b(Q)},[]),_=v.useCallback(()=>{R0e(),b(null)},[]),[w,C]=v.useState(null),[E,k]=v.useState([]),[T,R]=v.useState(!1),[A,j]=v.useState(null),[L,H]=v.useState(!1),[M,D]=v.useState({}),[z,O]=v.useState(null),[F,$]=v.useState(null),[B,U]=v.useState(null),[G,te]=v.useState(null),[P,Y]=v.useState("connecting"),[ee,V]=v.useState(!1),[ue,ge]=v.useState(!1),[Z,ne]=v.useState(!1),[ie,le]=v.useState(null),[oe,ke]=v.useState(!1),[Ee,Pe]=v.useState(!1),[Ze,ut]=v.useState(!1),[Mt,ye]=v.useState(null),[an,jt]=v.useState(null),[_t,ft]=v.useState(null),[Pt,It]=v.useState([]),[st,Ot]=v.useState(null),[he,Re]=v.useState(0),Ue=v.useRef(new Map),Je=dC(cx(Q=>Object.keys(Q.drafts).sort())),Ke=dC(cx(Q=>Object.keys(Q.attachmentDrafts).sort())),vt=v.useRef(0),St=v.useRef(null),ze=v.useRef({projectId:null,diffs:null}),Be=Ere(di(Q=>Q.editorPreset)),Oe=v.useMemo(()=>lD(i.projectGroups,o),[o,i.projectGroups]),Fe=v.useRef(Oe);v.useLayoutEffect(()=>{Fe.current=Oe});const bt=v.useMemo(()=>Oe===i.projectGroups?i:{...i,projectGroups:Oe},[i,Oe]);v.useEffect(()=>n.onStatus(Y),[n]),v.useEffect(()=>n.subscribe({type:"sidebar"},Q=>{s(Q),a(J=>J&&lD(Q.projectGroups,J)===Q.projectGroups?null:J),V(!0),ye(null)}),[n]),v.useEffect(()=>{if(P!=="connected")return;const Q=[...new Set([...Je,...Ke])].sort();n.command({type:"chat.setDraftProtection",chatIds:Q}).catch(J=>{ye(J instanceof Error?J.message:String(J))})},[Ke,P,Je,n]),v.useEffect(()=>n.subscribe({type:"local-projects"},Q=>{d(Q),ge(!0),ye(null)}),[n]),v.useEffect(()=>n.subscribe({type:"update"},Q=>{m(Q),ye(null)}),[n]),v.useEffect(()=>{P==="connected"&&n.command({type:"update.check",force:!0}).catch(Q=>{ye(Q instanceof Error?Q.message:String(Q))})},[P,n]),v.useEffect(()=>{const Q=f==null?void 0:f.reloadRequestedAt;A0e(Q,j0e())&&Q&&(M0e(Q),y("awaiting_disconnect"))},[y,f==null?void 0:f.reloadRequestedAt]),v.useEffect(()=>{const Q=lS();if(S0e(Q,P)==="awaiting_server_ready"){y("awaiting_server_ready");return}},[P,y]),v.useEffect(()=>{if(lS()!=="awaiting_server_ready")return;let Q=!1,J=null;const Le=async()=>{try{if(await I0e()){if(Q)return;_(),window.location.reload();return}}catch{}Q||(J=window.setTimeout(()=>{Le()},500))};return Le(),()=>{Q=!0,J!==null&&window.clearTimeout(J)}},[P,_]),v.useEffect(()=>{function Q(){f!=null&&f.lastCheckedAt&&(Date.now()-f.lastCheckedAt<=3600*1e3||n.command({type:"update.check"}).catch(J=>{ye(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=>{O(Q),ye(null)}),[n]),v.useEffect(()=>n.subscribe({type:"app-settings"},Q=>{$(Q),Lf(Q),ye(null)}),[n]),v.useEffect(()=>n.subscribe({type:"push-config"},Q=>{U(Q)}),[n]),v.useEffect(()=>n.subscribe({type:"pty-instances"},Q=>{Ta.getState().applySnapshot(Q.instances)},Q=>{Q.type==="pty-instances.added"?Ta.getState().applyDiff({op:"added",instance:Q.instance}):Q.type==="pty-instances.updated"?Ta.getState().applyDiff({op:"updated",instance:Q.instance}):Ta.getState().applyDiff({op:"removed",chatId:Q.chatId})}),[n]);const wt=v.useCallback(async()=>{try{Mi.getState().setHydrationStatus("loading");const Q=await n.command({type:"settings.readAppSettings"});$(Q),Lf(Q),ye(null)}catch(Q){Mi.getState().setHydrationStatus("error"),ye(Q instanceof Error?Q.message:String(Q))}},[n]),fn=v.useCallback(async(Q,J)=>{try{await n.command({type:"chat.setPolicyOverride",chatId:Q,policyOverride:J}),ye(null)}catch(Le){throw ye(Le instanceof Error?Le.message:String(Le)),Le}},[n]),Xt=v.useCallback(async Q=>{try{Mi.getState().applyOptimisticPatch(Q);const J=await n.command({type:"settings.writeAppSettingsPatch",patch:Q});$(J),Lf(J),ye(null)}catch(J){throw ye(J instanceof Error?J.message:String(J)),await wt(),J}},[wt,n]),Qt=v.useCallback(async Q=>{try{await n.command({type:"settings.testMcpServer",id:Q}),ye(null)}catch(J){throw ye(J instanceof Error?J.message:String(J)),J}},[n]),Rt=v.useCallback(async Q=>{try{Mi.getState().applyOptimisticPatch({cloudflareTunnel:Q});const J=await n.command({type:"appSettings.setCloudflareTunnel",patch:Q});$(J),Lf(J),ye(null)}catch(J){throw ye(J instanceof Error?J.message:String(J)),await wt(),J}},[wt,n]),xt=v.useCallback(async Q=>{try{Mi.getState().applyOptimisticPatch({claudeAuth:Q});const J=await n.command({type:"appSettings.setClaudeAuth",patch:Q});$(J),Lf(J),ye(null)}catch(J){throw ye(J instanceof Error?J.message:String(J)),await wt(),J}},[wt,n]),mt=v.useCallback(async Q=>await n.command({type:"appSettings.testOAuthToken",token:Q}),[n]),kt=v.useCallback(async()=>{try{const Q=await n.command({type:"settings.readLlmProvider"});te(Q),ye(null)}catch(Q){ye(Q instanceof Error?Q.message:String(Q))}},[n]),pt=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),ye(null)}catch(J){throw ye(J instanceof Error?J.message:String(J)),J}},[n]),$t=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(()=>{P==="connected"&&wt()},[P,wt]),v.useEffect(()=>{if(P!=="connected"||(F==null?void 0:F.browserSettingsMigrated)!==!1)return;const Q=c0e();Q&&Xt(Q).then(u0e).catch(()=>{})},[F==null?void 0:F.browserSettingsMigrated,P,Xt]),v.useEffect(()=>{P==="connected"&&kt()},[P,kt]),v.useEffect(()=>{function Q(){Re(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}++vt.current,Fe.current.length,Fe.current.reduce((J,Le)=>J+Le.chats.length,0),C(null),ne(!1);const Q=n.subscribe({type:"chat",chatId:e,recentLimit:p0e},J=>{if(J!=null&&J.runtime.chatId){const Le=[...Ue.current.values()].filter(ot=>ot.serverChatId===J.runtime.chatId).sort((ot,An)=>An.startedAt-ot.startedAt)[0];Le&&Le.snapshotAt===void 0&&(Le.snapshotAt=performance.now(),Nl(Le,"chat_snapshot_received",{status:J.runtime.status,messageCount:J.messages.length}))}if(C(Le=>{const ot=a0e(Le,J);return J==null||J.runtime.chatId,J==null||J.runtime.provider,J==null||J.runtime.status,J==null||J.messages.length,ot?Le:J}),j((J==null?void 0:J.history.olderCursor)??null),H((J==null?void 0:J.history.hasOlder)??!1),ne(!0),ye(null),J){const Le=A2.getState();Le.setForChat(J.runtime.chatId,J.slashCommands??[]),Le.setLoadingForChat(J.runtime.chatId,J.slashCommandsLoading??!1)}});return()=>{Fe.current.length,Fe.current.reduce((J,Le)=>J+Le.chats.length,0),Q()}},[e,n]),v.useEffect(()=>{if(e)return n.subscribe({type:"workflows",chatId:e},Q=>{L2.getState().setRuns(Q.chatId,Q.runs)})},[e,n]),v.useEffect(()=>{if(ie)return;const Q=Oe[0];Q&&le(Q.groupKey)},[ie,Oe]),v.useEffect(()=>{if(!e||!ee||!Z)return;if(Oe.some(J=>J.chats.some(Le=>Le.chatId===e))){_t===e&&ft(null);return}_t!==e&&t("/")},[e,Z,t,_t,Oe,ee]),v.useEffect(()=>{w&&(le(w.runtime.projectId),_t===w.runtime.chatId&&ft(null))},[w,_t]),v.useEffect(()=>{if(!e||!ee||!v0e())return;const Q=Oe.flatMap(J=>J.chats).find(J=>J.chatId===e);Q!=null&&Q.unread&&n.command({type:"chat.markRead",chatId:e}).catch(J=>{ye(J instanceof Error?J.message:String(J))})},[e,he,Oe,ee,n]),v.useEffect(()=>{k([]),R(!1),j(null),H(!1)},[e]);const nt=v.useMemo(()=>P0e(w,e),[e,w]),we=v.useMemo(()=>(nt==null?void 0:nt.runtime.projectId)??w0e(Oe,e)??ie,[e,nt==null?void 0:nt.runtime.projectId,ie,Oe]),tt=v.useMemo(()=>{const Q=we?M[we]??null:null;return we&&Q?(ze.current={projectId:we,diffs:Q},Q):we&&ze.current.projectId===we?ze.current.diffs:Q},[we,M]);v.useEffect(()=>we?n.subscribe({type:"project-git",projectId:we},J=>{D(Le=>{const ot=J??null;return r0e(Le[we]??null,ot)||n0e(Le[we]??null,ot)?Le:{...Le,[we]:ot}}),ye(null)}):void 0,[we,n]),v.useEffect(()=>{w==null||w.runtime.chatId,w==null||w.runtime.provider,nt==null||nt.runtime.chatId,nt==null||nt.runtime.provider},[e,nt,w,_t]);const qe=v.useMemo(()=>sD(E,(nt==null?void 0:nt.messages)??[]),[nt==null?void 0:nt.messages,E]),Xe=e??oD,_e=v.useMemo(()=>Pt.filter(Q=>Q.scopeId===Xe).map(Q=>Q.entry),[Xe,Pt]),De=v.useMemo(()=>[...qe,..._e],[_e,qe]),Ve=v.useMemo(()=>j2(De),[De]),We=v.useMemo(()=>l0e(Ve),[Ve]),Ut=v.useMemo(()=>Mye(Ve),[Ve]),$e=(nt==null?void 0:nt.runtime)??null,Ht=(nt==null?void 0:nt.queuedMessages)??[],_n=((st==null?void 0:st.scopeId)===Xe&&(!$e||$e.status==="idle")?"starting":null)??($e==null?void 0:$e.status)??null,kr=(nt==null?void 0:nt.availableProviders)??tm,Cn=Iye(_n??void 0),Bn=Lye(_n??void 0),Er=($e==null?void 0:$e.isDraining)??!1,q=((Nu=c==null?void 0:c.projects[0])==null?void 0:Nu.localPath)??null,be=($e==null?void 0:$e.localPath)??q??((uc=Oe[0])==null?void 0:uc.localPath),je=!!(ie??($e==null?void 0:$e.projectId)??((Ih=Oe[0])==null?void 0:Ih.groupKey)??q);v.useEffect(()=>{(st==null?void 0:st.scopeId)===Xe&&$e!=null&&$e.status&&$e.status!=="idle"&&Ot(null)},[st,Xe,$e==null?void 0:$e.status]),v.useEffect(()=>{if(!(st!=null&&st.ackedAt)||st.scopeId!==Xe||$e!=null&&$e.status&&$e.status!=="idle")return;const Q=window.setTimeout(()=>{Ot(J=>(J==null?void 0:J.scopeId)===Xe&&J.ackedAt===st.ackedAt?null:J)},300);return()=>window.clearTimeout(Q)},[st,Xe,$e==null?void 0:$e.status]),v.useEffect(()=>{if(!e||($e==null?void 0:$e.status)!=="starting")return;const Q=[...Ue.current.values()].filter(J=>J.serverChatId===e).sort((J,Le)=>Le.startedAt-J.startedAt)[0];!Q||Q.startingStatusAt!==void 0||(Q.startingStatusAt=performance.now(),Nl(Q,"runtime_status_starting",{status:$e.status}))},[e,$e==null?void 0:$e.status]),v.useEffect(()=>{if(!e||!$e||$e.status==="starting")return;const Q=[...Ue.current.values()].filter(J=>J.serverChatId===e).sort((J,Le)=>Le.startedAt-J.startedAt)[0];!Q||Q.startingRenderedAt!==void 0||(Nl(Q,"starting_not_observed",{status:$e.status}),Ue.current.delete(Q.traceId))},[e,$e]),v.useLayoutEffect(()=>{if(!e||($e==null?void 0:$e.status)!=="starting"){St.current=null;return}const Q=[...Ue.current.values()].filter(J=>J.serverChatId===e).sort((J,Le)=>Le.startedAt-J.startedAt)[0];Q&&St.current!==Q.traceId&&(St.current=Q.traceId,Q.startingRenderedAt=performance.now(),Nl(Q,"starting_render_committed",{totalMs:qF(Q.startedAt)}),Ue.current.delete(Q.traceId))},[e,$e==null?void 0:$e.status]),v.useEffect(()=>{It(Q=>{const J=f0e(Q,Xe,qe);return J.length===Q.length&&J.every((Le,ot)=>Le===Q[ot])?Q:J})},[Xe,qe]);const Qe=v.useCallback(async()=>{if(!(!e||!A||T||!L)){R(!0);try{const Q=await n.command({type:"chat.loadHistory",chatId:e,beforeCursor:A,limit:g0e});k(J=>sD(Q.messages,J)),j(Q.olderCursor),H(Q.hasOlder),ye(null)}catch(Q){const J=Q instanceof Error?Q.message:String(Q);ye(J)}finally{R(!1)}}},[e,L,A,T,n]),dt=v.useCallback(async Q=>{const J=mi.getState(),Le=e?J.getComposerState(e):J.getComposerState(cm),ot=await n.command({type:"chat.create",projectId:Q});J.initializeComposerForChat(ot.chatId,{sourceState:Le}),le(Q),ft(ot.chatId),t(`/chat/${ot.chatId}`),ke(!1),ye(null)},[e,t,n]),Ye=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]),it=v.useCallback(async Q=>{try{const J=Q.kind==="project_id"?null:Q.kind==="local_path"?Q.localPath:Q.project.localPath;J&&jt(J);const{projectId:Le}=await Ye(Q);await dt(Le)}catch(J){ye(J instanceof Error?J.message:String(J))}finally{jt(null)}},[dt,Ye]),cn=v.useCallback(async Q=>{await it({kind:"project_id",projectId:Q})},[it]),Wn=v.useCallback(async Q=>{try{const J=await n.command({type:"chat.fork",chatId:Q.chatId}),Le=mi.getState();Le.initializeComposerForChat(J.chatId,{sourceState:Le.getComposerState(Q.chatId)}),ft(J.chatId),t(`/chat/${J.chatId}`),ke(!1),ye(null)}catch(J){ye(J instanceof Error?J.message:String(J))}},[t,n]),or=v.useCallback(async Q=>{await it({kind:"local_path",localPath:Q})},[it]),ai=v.useCallback(async Q=>{await it({kind:"project_request",project:Q})},[it]),ss=v.useCallback(async Q=>{try{await n.command({type:"update.check",force:Q==null?void 0:Q.force}),ye(null)}catch(J){ye(J instanceof Error?J.message:String(J))}},[n]),qr=v.useCallback(async Q=>{y("awaiting_disconnect");try{const J=await n.command({type:"update.install",version:Q});if(!J.ok){_(),ye(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}ye(null)}catch(J){_(),ye(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){_(),ye(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}ye(null)}catch(Q){_(),ye(Q instanceof Error?Q.message:String(Q))}},[_,r,y,n]),Fi=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}`);ye(null),window.location.reload()}catch(Q){ye(Q instanceof Error?Q.message:String(Q))}},[]),Et=v.useCallback(async(Q,J)=>{var Tu;const Le=(J==null?void 0:J.attachments)??[],ot=Pc(),An=Pc(),Xr=I2(Q,Le),zs=e??oD;Ot({scopeId:zs,ackedAt:null});const Bs={traceId:An,optimisticId:ot,startedAt:performance.now(),serverChatId:e,routeChatIdAtSend:e,contentPreview:Q.slice(0,80)};Ue.current.set(An,Bs),Nl(Bs,"handle_send_called",{optimisticScopeId:zs,attachments:Le.length,contentLength:Q.length,contentPreview:Bs.contentPreview});const Dh=h0e(qe,Xr)+Pt.filter(Fn=>Fn.scopeId===zs&&Fn.signature===Xr).length+1;It(Fn=>[...Fn,{id:ot,scopeId:zs,signature:Xr,requiredMatchCount:Dh,entry:{_id:`optimistic:${ot}`,kind:"user_prompt",content:Q,attachments:Le,createdAt:Date.now()}}]),Nl(Bs,"optimistic_prompt_added",{optimisticId:ot,optimisticScopeId:zs});try{let Fn=ie??((Tu=Oe[0])==null?void 0:Tu.groupKey)??null;if(!e&&!Fn&&q&&(Fn=(await n.command({type:"project.open",localPath:q})).projectId,le(Fn)),!e&&!Fn)throw new Error("Open a project first");const el=hC.getState().autoResumeOnRateLimit,Qr=await n.command({type:"chat.send",chatId:e??void 0,projectId:e?void 0:Fn??void 0,clientTraceId:An,provider:J==null?void 0:J.provider,content:Q,attachments:Le,model:J==null?void 0:J.model,modelOptions:J==null?void 0:J.modelOptions,planMode:J==null?void 0:J.planMode,autoResumeOnRateLimit:el});if(Bs.ackAt=performance.now(),Bs.serverChatId=Qr.chatId??Bs.serverChatId,Qr.queued?(It(Fs=>m0e(Fs,ot,{queued:!0})),Ot(null)):Ot(Fs=>Fs&&{scopeId:!e&&Qr.chatId?Qr.chatId:Fs.scopeId,ackedAt:performance.now()}),Nl(Bs,"chat_send_ack_received",{resultChatId:Qr.chatId??null,queued:Qr.queued??!1}),!e&&Qr.chatId){It(Dp=>Dp.map(Ph=>Ph.id===ot?{...Ph,scopeId:Qr.chatId}:Ph));const Fs=mi.getState();Fs.setComposerState(Qr.chatId,_0e(J)??Fs.getComposerState(cm)),ft(Qr.chatId),t(`/chat/${Qr.chatId}`)}ye(null)}catch(Fn){throw It(el=>el.filter(Qr=>Qr.id!==ot)),Ot(null),Nl(Bs,"handle_send_failed",{error:Fn instanceof Error?Fn.message:String(Fn)}),Ue.current.delete(An),ye(Fn instanceof Error?Fn.message:String(Fn)),Fn}},[e,q,t,Pt,ie,qe,Oe,n]),nn=v.useCallback(async Q=>{if(e)try{await n.command({type:"message.steer",chatId:e,queuedMessageId:Q}),ye(null)}catch(J){ye(J instanceof Error?J.message:String(J))}},[e,n]),mn=v.useCallback(async Q=>{if(e)try{await n.command({type:"message.dequeue",chatId:e,queuedMessageId:Q}),ye(null)}catch(J){ye(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){ye(Q instanceof Error?Q.message:String(Q))}},[e,n]),Kr=v.useCallback(async()=>{if(e)try{await n.command({type:"chat.stopDraining",chatId:e})}catch(Q){ye(Q instanceof Error?Q.message:String(Q))}},[e,n]),Qa=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}),ye(null)}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[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 Le=aD(Oe,Q.chatId);t(Le?`/chat/${Le}`:"/")}}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[e,r,t,Oe,n]),Yo=v.useCallback(async Q=>{try{if(await n.command({type:"chat.archive",chatId:Q.chatId}),Q.chatId===e){const J=aD(Oe,Q.chatId);t(J?`/chat/${J}`:"/")}ye(null)}catch(J){ye(J instanceof Error?J.message:String(J))}},[e,t,Oe,n]),Ds=v.useCallback(async Q=>{try{ft(Q),await n.command({type:"chat.unarchive",chatId:Q}),t(`/chat/${Q}`),ye(null)}catch(J){ft(null),ye(J instanceof Error?J.message:String(J))}},[t,n]),Za=v.useCallback(async Q=>{try{await n.command({type:"project.remove",projectId:Q}),Il.getState().clearProject(Q),Ai.getState().clearProject(Q),($e==null?void 0:$e.projectId)===Q&&t("/"),ye(null)}catch(J){ye(J instanceof Error?J.message:String(J))}},[t,$e,n]),er=v.useCallback(async(Q,J)=>{try{await n.command({type:"project.setStar",projectId:Q,starred:J}),ye(null)}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[n]),po=v.useCallback(async Q=>{a(Q);try{await n.command({type:"sidebar.reorderProjectGroups",projectIds:Q}),ye(null)}catch(J){a(null),ye(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}),ye(null)}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[n]),vo=v.useCallback(async(Q,J)=>{try{await n.command({type:"stack.rename",stackId:Q,title:J}),ye(null)}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[n]),_i=v.useCallback(async Q=>{try{await n.command({type:"stack.remove",stackId:Q}),ye(null)}catch(J){ye(J instanceof Error?J.message:String(J))}},[n]),Xo=v.useCallback(async(Q,J)=>{try{await n.command({type:"stack.addProject",stackId:Q,projectId:J}),ye(null)}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[n]),Qo=v.useCallback(async(Q,J)=>{try{await n.command({type:"stack.removeProject",stackId:Q,projectId:J}),ye(null)}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[n]),wi=v.useCallback(async(Q,J,Le)=>{try{const ot=mi.getState(),An=e?ot.getComposerState(e):ot.getComposerState(cm),Xr=await n.command({type:"chat.create",projectId:Q,stackId:J,stackBindings:Le});ot.initializeComposerForChat(Xr.chatId,{sourceState:An}),le(Q),ft(Xr.chatId),t(`/chat/${Xr.chatId}`),ke(!1),ye(null)}catch(ot){ye(ot instanceof Error?ot.message:String(ot))}},[e,t,n]),Zo=v.useCallback(async Q=>{try{const J=await n.command({type:"stack.listWorktrees",projectId:Q});return ye(null),J.worktrees}catch(J){return ye(J instanceof Error?J.message:String(J)),[]}},[n]),bo=v.useCallback(async()=>await n.command({type:"sessions.importClaude"}),[n]),Se=v.useCallback(async Q=>{const J=di.getState();ye(null),await n.command({type:"system.openExternal",...Q,editor:Q.action==="open_editor"?Q.editor??{preset:J.editorPreset,commandTemplate:J.editorCommandTemplate}:void 0})},[n]),W=v.useCallback(async(Q,J)=>{var ot,An;const Le=($e==null?void 0:$e.localPath)??((ot=c==null?void 0:c.projects[0])==null?void 0:ot.localPath)??((An=Oe[0])==null?void 0:An.localPath);if(Le)try{await Se({action:Q,localPath:Le,editor:J})}catch(Xr){ye(Xr instanceof Error?Xr.message:String(Xr))}},[c==null?void 0:c.projects,Se,$e==null?void 0:$e.localPath,Oe]),xe=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),ye(null)}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[]),Wt=v.useCallback(async(Q,J="open_editor",Le)=>{try{await Se({action:J,localPath:Q.path,line:Q.line,column:Q.column,editor:Le})}catch(ot){ye(ot instanceof Error?ot.message:String(ot))}},[Se]),ar=v.useCallback(async(Q,J)=>{try{await Se({action:Q,localPath:J})}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[Se]),Yr=v.useCallback(()=>{var J;const Q=D0e({selectedProjectId:ie,sidebarProjectId:(J=Oe[0])==null?void 0:J.groupKey,fallbackLocalProjectPath:q});if(Q){it(Q);return}t("/")},[q,t,ie,Oe,it]),Jo=v.useCallback(()=>ke(!0),[]),ac=v.useCallback(()=>ke(!1),[]),xo=v.useCallback(()=>Pe(!0),[]),Ja=v.useCallback(()=>Pe(!1),[]),Lp=v.useCallback(()=>ut(!0),[]),Mh=v.useCallback(()=>ut(!1),[]),Ip=v.useCallback(async(Q,J,Le)=>{if(e)try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Q,result:{questions:J,answers:Le}})}catch(ot){ye(ot instanceof Error?ot.message:String(ot))}},[e,n]),lc=v.useCallback(async(Q,J,Le,ot)=>{if(e){J&&mi.getState().setChatComposerPlanMode(e,!1);try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Q,result:{confirmed:J,...Le?{clearContext:!0}:{},...ot?{message:ot}:{}}})}catch(An){ye(An instanceof Error?An.message:String(An))}}},[e,n]),Ps=v.useCallback(async(Q,J,Le,ot)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Q,toolUseId:J,result:{questions:Le,answers:ot}})}catch(An){ye(An instanceof Error?An.message:String(An))}},[e,n]),Lh=v.useCallback(async(Q,J,Le)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Q,toolUseId:J,result:Le})}catch(ot){ye(ot instanceof Error?ot.message:String(ot))}},[e,n]),cc=v.useCallback(async(Q,J)=>{if(e)try{await n.command({type:"chat.toolRequestAnswer",chatId:e,toolRequestId:Q,decision:J})}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[e,n]),Os=C0e(g,f==null?void 0:f.status);return{socket:n,activeChatId:e,activeProjectId:we,sidebarData:bt,localProjects:c,updateSnapshot:f,chatSnapshot:w,chatDiffSnapshot:tt,keybindings:z,appSettings:F,pushConfig:B,llmProvider:G,connectionStatus:P,sidebarReady:ee,uiRestartActive:Os.active,uiRestartLabel:Os.label,localProjectsReady:ue,commandError:Mt,startingLocalPath:an,sidebarOpen:oe,sidebarCollapsed:Ee,messages:Ve,queuedMessages:Ht,previousPrompt:We,latestToolIds:Ut,runtime:$e,runtimeStatus:_n,isHistoryLoading:T,hasOlderHistory:L,availableProviders:kr,isProcessing:Cn,canCancel:Bn,isDraining:Er,navbarLocalPath:be,editorLabel:Be,hasSelectedProject:je,addProjectModalOpen:Ze,openSidebar:Jo,closeSidebar:ac,collapseSidebar:xo,expandSidebar:Ja,openAddProjectModal:Lp,closeAddProjectModal:Mh,loadOlderHistory:Qe,handleCreateChat:cn,handleForkChat:Wn,handleOpenLocalProject:or,handleCreateProject:ai,handleCheckForUpdates:ss,handleInstallUpdate:qr,handleForceReload:fo,handleReadAppSettings:wt,handleWriteAppSettings:Xt,handleTestMcpServer:Qt,handleSetChatPolicyOverride:fn,handleWriteCloudflareTunnel:Rt,handleWriteClaudeAuth:xt,handleTestOAuthToken:mt,handleReadLlmProvider:kt,handleWriteLlmProvider:pt,handleValidateLlmProvider:$t,handleSignOut:Fi,handleSend:Et,handleSteerQueuedMessage:nn,handleRemoveQueuedMessage:mn,handleCancel:pn,handleStopDraining:Kr,handleRenameChat:Qa,handleArchiveChat:Yo,handleOpenArchivedChat:Ds,handleDeleteChat:mo,handleHideProject:Za,handleToggleProjectStar:er,handleReorderProjectGroups:po,stacks:bt.stacks,handleCreateStack:go,handleRenameStack:vo,handleRemoveStack:_i,handleAddProjectToStack:Xo,handleRemoveProjectFromStack:Qo,handleCreateStackChat:wi,handleListStackWorktrees:Zo,importClaudeSessions:bo,handleCopyPath:xe,handleOpenExternal:W,handleOpenExternalPath:ar,handleOpenLocalLink:Wt,handleCompose:Yr,handleAskUserQuestion:Ip,handleExitPlanMode:lc,handleSubagentAskUserQuestion:Ps,handleSubagentExitPlanMode:Lh,handleToolRequestAnswer:cc}}const uD=/<thinking>([\s\S]*?)<\/thinking>/gi;function z0e(e){const t=[];let n=0;uD.lastIndex=0;let r;for(;(r=uD.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 B0e(t)}function B0e(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 P2=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(Qv,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"font-medium uppercase tracking-wider",children:"Thinking"}),u.jsx(Ts,{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(Wo,{remarkPlugins:Fa,components:$a,children:i})})]})}),YF=v.memo(function({message:t}){const n=v.useMemo(()=>z0e(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(P2,{content:r.content},i):u.jsx(Wo,{remarkPlugins:Fa,components:$a,children:r.content},i))})}),XF=v.memo(function({message:t}){return u.jsx("div",{className:"px-0.5 w-full max-w-[70ch]",children:u.jsx(P2,{content:t.text})})}),Np=({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 F0e(e){const t=e.split(`
2635
+ `},i),s}function Eve(e,t){return e&&"run"in e?async function(n,r){const i=wI(n,{file:r,...t});await e.run(i,r)}:function(n,r){return wI(n,{file:r,...e||t})}}function SI(e){if(e)throw e}var Gw,CI;function Nve(){if(CI)return Gw;CI=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 Gw=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 _},Gw}var Tve=Nve();const qw=wx(Tve);function rC(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 Rve(){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?Ave(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 Ave(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 Ro={basename:jve,dirname:Mve,extname:Lve,join:Ive,sep:"/"};function jve(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');kp(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 Mve(e){if(kp(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 Lve(e){kp(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 Ive(...e){let t=-1,n;for(;++t<e.length;)kp(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":Dve(n)}function Dve(e){kp(e);const t=e.codePointAt(0)===47;let n=Pve(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function Pve(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 kp(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const Ove={cwd:zve};function zve(){return"/"}function iC(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function Bve(e){if(typeof e=="string")e=new URL(e);else if(!iC(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 Fve(e)}function Fve(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 Kw=["history","path","basename","stem","extname","dirname"];class rF{constructor(t){let n;t?iC(t)?n={path:t}:typeof t=="string"||$ve(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":Ove.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<Kw.length;){const s=Kw[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)Kw.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?Ro.basename(this.path):void 0}set basename(t){Xw(t,"basename"),Yw(t,"basename"),this.path=Ro.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?Ro.dirname(this.path):void 0}set dirname(t){kI(this.basename,"dirname"),this.path=Ro.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?Ro.extname(this.path):void 0}set extname(t){if(Yw(t,"extname"),kI(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=Ro.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){iC(t)&&(t=Bve(t)),Xw(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?Ro.basename(this.path,this.extname):void 0}set stem(t){Xw(t,"stem"),Yw(t,"stem"),this.path=Ro.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 oi(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 Yw(e,t){if(e&&e.includes(Ro.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+Ro.sep+"`")}function Xw(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function kI(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function $ve(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Hve=(function(e){const r=this.constructor.prototype,i=r[e],s=function(){return i.apply(s,arguments)};return Object.setPrototypeOf(s,r),s}),Uve={}.hasOwnProperty;class m2 extends Hve{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=Rve()}copy(){const t=new m2;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(qw(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(Jw("data",this.frozen),this.namespace[t]=n,this):Uve.call(this.namespace,t)&&this.namespace[t]||void 0:t?(Jw("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=Sv(t),r=this.parser||this.Parser;return Qw("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),Qw("process",this.parser||this.Parser),Zw("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(s,o){const a=Sv(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);Gve(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(),Qw("processSync",this.parser||this.Parser),Zw("processSync",this.compiler||this.Compiler),this.process(t,i),NI("processSync","process",n),r;function i(s,o){n=!0,SI(s),r=o}}run(t,n,r){EI(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=Sv(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),NI("runSync","run",r),i;function s(o,a){SI(o),i=a,r=!0}}stringify(t,n){this.freeze();const r=Sv(n),i=this.compiler||this.Compiler;return Zw("stringify",i),EI(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(Jw("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=qw(!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];rC(_)&&rC(b)&&(b=qw(!0,_,b)),r[g]=[d,b,...y]}}}}const Vve=new m2().freeze();function Qw(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function Zw(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function Jw(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 EI(e){if(!rC(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function NI(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function Sv(e){return Wve(e)?e:new rF(e)}function Wve(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function Gve(e){return typeof e=="string"||qve(e)}function qve(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Kve="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",TI=[],RI={allowDangerousHtml:!0},Yve=/^(https?|ircs?|mailto|xmpp)$/i,Xve=[{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 Wo(e){const t=Qve(e),n=Zve(e);return Jve(t.runSync(t.parse(n),n),e)}function Qve(e){const t=e.rehypePlugins||TI,n=e.remarkPlugins||TI,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...RI}:RI;return Vve().use(Fge).use(n).use(Eve,r).use(t)}function Zve(e){const t=e.children||"",n=new rF;return typeof t=="string"&&(n.value=t),n}function Jve(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,s=t.disallowedElements,o=t.skipHtml,a=t.unwrapDisallowed,c=t.urlTransform||ebe;for(const f of Xve)Object.hasOwn(t,f.from)&&(""+f.from+(f.to?"use `"+f.to+"` instead":"remove it")+Kve+f.id,void 0);return JE(e,d),Kpe(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 Ww)if(Object.hasOwn(Ww,b)&&Object.hasOwn(f.properties,b)){const y=f.properties[b],_=Ww[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 ebe(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||Yve.test(e.slice(0,t))?e:""}const Cv=new Map;function tbe(e){return`${e.id}|${e.contentUrl}|${e.size??0}`}function by(e){const t=tbe(e),n=Cv.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(Cv.get(t)??{status:"loading"})),v.useEffect(()=>{if(n&&n.status!=="loading")return;let c=!1;const d=t;return QE(e.contentUrl,eB).then(f=>{if(c||a.current!==d)return;const m={status:"ready",content:f.content,truncated:f.truncated};Cv.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."};Cv.set(d,g),i(g)}),()=>{c=!0}},[n,t,e.contentUrl]),r}function nbe({source:e}){const t=by(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(Wo,{remarkPlugins:Fa,components:$a,children:t.content})})]})}const kv=new Map;function rbe(e){return`${e.id}|${e.contentUrl}|${e.size??0}|${e.mimeType}`}function ibe({source:e}){const t=rbe(e),n=kv.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(kv.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 QE(e.contentUrl,eB).then(_=>{if(b||a.current!==y)return;const w={status:"ready",table:Dde(_.content,g),truncated:_.truncated};kv.set(y,w),i(w)}).catch(_=>{if(b||a.current!==y)return;const w={status:"error",message:_ instanceof Error?_.message:"Unable to load preview."};kv.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 ${Y1} 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 sbe({source:e}){const t=by(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(obe,{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 obe({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 abe({source:e}){const t=by(e),n=v.useMemo(()=>t.status==="ready"?Ide(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 lbe({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 cbe({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 ube=200*1024;function dbe(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 hbe({source:e}){const t=by(e),n=t.status==="ready"&&t.content.length<=ube,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 X(()=>Promise.resolve().then(()=>W8),void 0).then(async c=>{if(o)return;const d=await c.codeToHtml(t.content,{lang:dbe(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 fbe(e){var r;const t=pbe(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 mbe(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 pbe(e){return typeof window>"u"?e:new URL(e,document.baseURI||window.location.href).toString()}function Th({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(Rs,{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(xbe,{source:e,onClose:r}):null})})}const gbe=120,vbe=.5;function bbe({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>gbe||a>vbe}function xbe({source:e,onClose:t}){const n=_be(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&&(bbe({startY:g.y,lastY:g.lastY,lastT:g.lastT,endY:m.clientY,now:Date.now()})?t():i(0))},[t]),d=v.useCallback(()=>{fbe(e)},[e]),f=v.useCallback(()=>mbe(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(op,{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(ybe(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(Ie,{type:"button",variant:"outline",onClick:d,children:[u.jsx(Oq,{className:"mr-2 h-4 w-4"}),"Share"]}),e.origin==="offer_download"?u.jsxs(Ie,{type:"button",onClick:f,children:[u.jsx(bk,{className:"mr-2 h-4 w-4"}),"Download"]}):null]})]})}function ybe(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=Eh(t);return n==="image"?Lpe:n==="pdf"?iI:n==="audio"?lbe:n==="video"?cbe:n==="table"?ibe:n==="markdown"?nbe:n==="json"?abe:n==="code"?hbe:kh(t).kind==="external"?iI:sbe}function _be(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=Eh(t),r=hy(n,e.mimeType),i=e.size?` · ${Rh(e.size)}`:"";return`${r}${i}`}function Ep(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 wbe(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function Sbe({path:e,linkText:t}){const n=v.useMemo(()=>s2(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 L=((D=(M=j.headers.get("Content-Type"))==null?void 0:M.split(";")[0])==null?void 0:D.trim())||"application/octet-stream",H=Number.parseInt(j.headers.get("Content-Length")??"0",10)||0;i({kind:"ready",mimeType:L,size:H})}).catch(()=>{A.signal.aborted||i({kind:"error"})}),()=>A.abort()},[n]);const a=wbe(e),c=t||a,d=Mpe(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($o,{attachment:g,disabledReason:"File no longer available"})});const b=Eh(g),y=hy(b,f),_=m>0?Rh(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"?kh(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($o,{attachment:g,onClick:()=>o(!0),meta:E,ariaLabel:R.join(", ")})}),u.jsx(Th,{source:s?Ep(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($o,{attachment:g,href:n,download:a,meta:E,ariaLabel:R.join(", ")})})}function Cbe(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 Mi=is()(e=>({settings:null,hydrationStatus:"idle",setHydrationStatus:t=>e({hydrationStatus:t}),setFromServer:t=>e({settings:t,hydrationStatus:"ready"}),applyOptimisticPatch:t=>e(n=>({settings:n.settings?Cbe(n.settings,t):n.settings}))})),kbe=[],Ebe=e=>{var t;return((t=e.settings)==null?void 0:t.customMcpServers)??kbe},iF=v.createContext(void 0),Nbe=e=>e==="light"||e==="dark"||e==="system";function Tbe(e){return e==="dark"?"black-translucent":"default"}function AI(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 jI(e){if(typeof document>"u"||typeof window>"u")return;const t=getComputedStyle(document.body).backgroundColor||getComputedStyle(document.documentElement).backgroundColor;t&&AI("theme-color",t),AI("apple-mobile-web-app-status-bar-style",Tbe(e)),document.documentElement.style.colorScheme=e}const fb=()=>typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",MI=e=>{if(typeof document>"u")return;const t=e==="system"?fb():e;document.documentElement.classList.toggle("dark",t==="dark")},Rbe=()=>{var t;const e=(t=Mi.getState().settings)==null?void 0:t.theme;return e&&Nbe(e)?e:"system"};function Abe({children:e}){const t=Mi(o=>{var a;return(a=o.settings)==null?void 0:a.theme}),n=Mi(o=>o.applyOptimisticPatch),[r,i]=v.useState(Rbe);v.useEffect(()=>{!t||t===r||i(t)},[t,r]),v.useEffect(()=>{MI(r)},[r]),v.useEffect(()=>{const o=r==="system"?fb():r;jI(o)},[r]),v.useEffect(()=>{if(r!=="system")return;const o=window.matchMedia("(prefers-color-scheme: dark)"),a=()=>{MI("system"),jI(fb())};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"?fb():r;return{theme:r,resolvedTheme:o,setTheme:a=>{i(a),n({theme:a})}}},[n,r]);return u.jsx(iF.Provider,{value:s,children:e})}function xy(){const e=v.useContext(iF);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}function jbe({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 Zi.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(Ie,{variant:"ghost",size:"icon","aria-label":"Zoom out",className:"h-9 w-9",onClick:()=>r(g=>c(g-.25)),children:u.jsx(J5,{className:"h-4 w-4"})}),u.jsx(Ie,{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(Ie,{variant:"ghost",size:"icon","aria-label":"Reset view",className:"h-9 w-9",onClick:()=>{r(1),s({x:0,y:0})},children:u.jsx(wq,{className:"h-4 w-4"})}),u.jsx(Ie,{variant:"ghost",size:"icon","aria-label":"Close",className:"h-9 w-9",onClick:t,children:u.jsx(Ls,{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 eS=null;function Mbe(){return eS||(eS=X(()=>import("./mermaid.core-DR7L5nHt.js").then(e=>e.bm),[]).then(e=>e.default)),eS}function Lbe({source:e}){const{resolvedTheme:t}=xy(),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 Mbe().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(tS,{source:e}):r.status==="loading"?u.jsx("div",{className:"relative group/mermaid",children:u.jsx(tS,{source:e})}):a?u.jsxs("div",{className:"relative group/mermaid",children:[u.jsx(tS,{source:e}),u.jsx(LI,{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(LI,{showSource:a,onToggleSource:()=>c(_=>!_),onCopy:y,copied:m,onZoom:()=>f(!0)}),d&&u.jsx(jbe,{svg:r.svg,onClose:b})]})}function LI({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(Ie,{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(qG,{className:"h-4 w-4"})}),u.jsx(Ie,{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(VS,{className:"h-4 w-4"})}),u.jsx(Ie,{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(ts,{className:"h-4 w-4 text-success"}):u.jsx(Da,{className:"h-4 w-4"})})]})}const Ibe=200*1024,Dbe={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 Pbe(e){return Dbe[e.toLowerCase()]??null}const Obe=/^<pre[^>]*>/,zbe=/<\/pre>\s*$/,Bbe=/^<code[^>]*>/,Fbe=/<\/code>\s*$/;function $be(e){return e.replace(Obe,"").replace(zbe,"").replace(Bbe,"").replace(Fbe,"")}function Uf({source:e,lang:t}){const{resolvedTheme:n}=xy(),r=n==="dark"?"github-dark":"github-light",i=Pbe(t),s=i!==null&&e.length<=Ibe,[o,a]=v.useState(null);v.useEffect(()=>{if(!s||i===null)return;let f=!1;return X(()=>Promise.resolve().then(()=>W8),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:$be(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 sF={readonly:!1,localLinkMode:"open"},oF=v.createContext(sF);function Hbe({children:e,value:t}){return u.jsx(oF.Provider,{value:{...sF,...t},children:e})}function yy(){return v.useContext(oF)}const aF=()=>{},Ube=v.createContext(aF);function lF({children:e,onOpenLocalLink:t}){return u.jsx(Ube.Provider,{value:t??aF,children:e})}const sC={Task:Nb,TaskOutput:Nb,Bash:Rx,Glob:Qf,Grep:Qf,ExitPlanMode:aj,Read:q5,Edit:JW,Write:tG,Delete:lG,NotebookEdit:dh,WebFetch:XV,TodoWrite:mW,WebSearch:Qf,KillShell:Kq,AskUserQuestion:Q5,Skill:Hq,EnterPlanMode:aj},cF=iK;function uF(e){return sC[e]?sC[e]:cF}function dF({icon:e,className:t}){return u.jsx(e,{className:t})}function qa({children:e,className:t}){return u.jsx("div",{className:de("flex gap-3 justify-start items-center",t),children:e})}function hF({children:e,className:t}){return u.jsx("div",{className:de("flex items-center gap-1.5 text-xs",t),children:e})}function ru({children:e,className:t}){return u.jsx("span",{className:de("font-medium text-foreground/80",t),children:e})}function Vbe({children:e}){return u.jsx("span",{className:"text-muted-foreground",children:e})}function Wbe({children:e,className:t}){return u.jsxs(qa,{className:de("px-0.5 text-xs tracking-wide",t),children:[u.jsx("div",{className:"w-full h-[1px] bg-border"}),u.jsx(ru,{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 p2({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(Ts,{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 oC({label:e,children:t,copyText:n}){const[r,i]=v.useState(!1),s=n??Jd(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(Ie,{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(ts,{className:"h-3.5 w-3.5 text-success"}):u.jsx(Da,{className:"h-4 w-4"})})]})]})}function fF({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 _y({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 Jd(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(Array.isArray(e))return e.map(Jd).join("");if(e&&typeof e=="object"&&"props"in e){const t=e.props;return Jd(t.children)}return""}function II(e,t){return v.isValidElement(e)?v.cloneElement(e,{className:de(e.props.className,t)}):e}function mF({children:e,...t}){const[n,r]=v.useState(!1),i=Jd(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(Ie,{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(ts,{className:"h-4 w-4 text-success"}):u.jsx(Da,{className:"h-4 w-4"})})]})}function tS({source:e}){return u.jsx(mF,{children:u.jsx("code",{className:"block text-xs whitespace-pre language-mermaid",children:e})})}const g2={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:mF,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(Lbe,{source:Jd(e)});const s=i.find(a=>a.startsWith("language-")),o=s?s.slice(9):"";return o?u.jsx(Uf,{source:Jd(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]=II(r,"mt-0"));const i=n.length-1,s=n[i];return s!==void 0&&(n[i]=II(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"&&jpe(e)?s2(e):e;return u.jsx("img",{src:n,...t})}};function Gbe({children:e,href:t,onClick:n,...r}){const i=yy(),s=Tpe(t);if(s&&i.localLinkMode==="text")return u.jsx("span",{className:"transition-all underline decoration-2 text-logo decoration-logo/50",children:e});if(s){const o=aC(e).trim();return u.jsx(Sbe,{path:s.path,linkText:o||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:"_blank",rel:"noopener noreferrer",onClick:n,...r,children:e})}function qbe(){return{...g2,a:e=>u.jsx(Gbe,{...e})}}const Fa=[$B],$a=qbe();function aC(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(aC).join(""):v.isValidElement(e)?aC(e.props.children):""}({...g2});function v2({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(G5,{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," · ",Rh(e.size)]})]})]}),f?u.jsx(sB,{progress:o??null,onCancel:a,size:d?"sm":"md",cancelLabel:`Cancel upload of ${e.displayName}`}):null,r&&!f?u.jsx(pF,{displayName:e.displayName,onRemove:r}):null]})}function $o({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":Eh(e),g=Xbe(m),b=e.kind==="mention",y=b?Kbe(e.displayName):e.displayName,_=b?Ybe(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," · ",Rh(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(dF,{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(sB,{progress:i??null,onCancel:s,size:"sm",cancelLabel:`Cancel upload of ${e.displayName}`}):null,n&&!w?u.jsx(pF,{displayName:e.displayName,onRemove:n}):null]})}function Kbe(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function Ybe(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function pF({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(Ls,{className:"h-3.5 w-3.5"})})}function Xbe(e){switch(e){case"image":return G5;case"pdf":return xq;case"markdown":return Tq;case"json":return GW;case"table":return rG;case"code":return KW;case"text":return Nx;case"archive":return VW;case"audio":return XW;case"video":return oG;default:return q5}}function Rh(e){return e<1024?`${e} B`:e<1024*1024?`${Math.max(1,Math.round(e/1024))} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}const La=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}));La.displayName="Textarea";const Ev={};function DI(e){return!e.isCollapsed&&!e.hasPreviewAttachment&&e.patch===void 0&&e.patchError===void 0&&!e.isPatchLoading}function Qbe(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 gF(e){return e.isUntracked}function Zbe(e){return gF(e)?e.path.includes("/"):!1}function nS(e){return u.jsxs(Pi,{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(vi,{children:e.label})]})}function vF({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(J5,{className:"h-3 w-3",strokeWidth:3}):e?u.jsx(ts,{className:"h-3 w-3",strokeWidth:3}):null})}function b2(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 Jbe(e){return e?`Last fetched ${b2(e)}`:"No local fetch recorded"}function exe({entry:e,isPendingPush:t=!1}){const n=b2(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(Hd,{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(Hd,{className:"size-3"})})}):null]})}function PI(e){switch(e.kind){case"local":return 0;case"pull_request":return 1;case"remote":default:return 2}}function txe(e){const t=new Map;for(const n of e){const r=t.get(n.name);(!r||PI(n)<PI(r))&&t.set(n.name,n)}return t}function nxe(e,t){const n=txe([...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 rxe({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 H=!1;return c(!0),E(null),n().then(M=>{H||(o(M),f(M.owners[0]??M.activeAccountLogin??""),g(M.suggestedRepoName),y("private"),w(""))}).finally(()=>{H||c(!1)}),()=>{H=!0}},[n,e]),v.useEffect(()=>{if(!e||!(s!=null&&s.ghInstalled)||!s.authenticated)return;const H=d.trim(),M=m.trim();if(!H||!M){E(null);return}let D=!1;T(!0);const z=window.setTimeout(()=>{r({owner:H,name:M}).then(O=>{D||E(O)}).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 H=await i({owner:d.trim(),name:m.trim(),visibility:b,description:_});H!=null&&H.ok&&t(!1)}finally{A(!1)}}}const L=!!(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(Rs,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[u.jsxs(Uo,{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(op,{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(bn,{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(Io,{value:d,onValueChange:f,children:[u.jsx(Qs,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:u.jsx(Ca,{placeholder:"Select owner"})}),u.jsx(Zs,{children:((s==null?void 0:s.owners)??[]).map(H=>u.jsx(ti,{value:H,children:u.jsxs("span",{className:"flex items-center gap-2",children:[H===(s==null?void 0:s.activeAccountLogin)?u.jsx(Ax,{className:"size-4 text-muted-foreground"}):u.jsx(uW,{className:"size-4 text-muted-foreground"}),u.jsx("span",{className:"pl-[1px]",children:H})]})},H))})]})}),u.jsx("div",{className:"space-y-2",children:u.jsxs("div",{className:"relative",children:[u.jsx(un,{value:m,onChange:H=>g(H.target.value),placeholder:"my-repo",className:"pl-9 pr-10"}),u.jsx(uq,{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(bn,{className:"size-4 animate-spin"})}):C?u.jsx("div",{className:"absolute inset-y-0 right-2 flex items-center",children:u.jsxs(Pi,{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(ts,{className:"size-4"}):u.jsx(gm,{className:"size-4"})})}),u.jsx(vi,{children:C.message})]})}):null]})}),u.jsx("div",{className:"space-y-2",children:u.jsxs("div",{className:"relative",children:[u.jsx(Nx,{className:"pointer-events-none absolute left-3 top-3 size-4 text-muted-foreground"}),u.jsx(La,{value:_,onChange:H=>w(H.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(Io,{value:b,onValueChange:H=>y(H),children:[u.jsx(Qs,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:u.jsx(Ca,{placeholder:"Select visibility"})}),u.jsxs(Zs,{children:[u.jsx(ti,{value:"private",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(UG,{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(EG,{className:"size-4 text-muted-foreground"}),u.jsx("span",{className:"pl-[1px]",children:"Public"})]})})]})]})})]})]}),u.jsxs(Yl,{children:[u.jsx(Ie,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),u.jsx(Ie,{size:"sm",disabled:!L,onClick:()=>void j(),children:R?u.jsxs(u.Fragment,{children:[u.jsx(bn,{className:"mr-1.5 size-3.5 animate-spin"}),"Publishing…"]}):"Push to GitHub"})]})]})})}function bF({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(un,{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 Uc({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(X5,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):u.jsx(Na,{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:b2(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 ixe({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?nxe(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),L=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||!L){m(null),b(null),_(!1);return}let D=!1;return m(null),b(null),_(!0),i(L).then(z=>{D||m(z)}).catch(z=>{D||b(z instanceof Error?z.message:String(z))}).finally(()=>{D||_(!1)}),()=>{D=!0}},[i,e,L]);const H=!L||!f||y||w||f.status!=="mergeable";async function M(){if(!(!L||H)){C(!0);try{const D=await s(L);D!=null&&D.ok&&t(!1)}finally{C(!1)}}}return u.jsx(so,{open:e,onOpenChange:t,children:u.jsxs(Rs,{size:"sm",className:"max-w-[min(92vw,475px)]",children:[u.jsxs(Uo,{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(op,{children:"Choose a branch to continue."})]}),u.jsx(bF,{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(Uc,{title:"Default Branch",entries:R?[R]:[],emptyLabel:"No default branch available.",selectedName:c,onSelect:D=>d(D.name)}),u.jsx(Uc,{title:"Recent Branches",entries:A,emptyLabel:"No recent branches.",selectedName:c,onSelect:D=>d(D.name)}),u.jsx(Uc,{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:L?y?u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(bn,{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(ts,{className:"mt-1 size-3.5 shrink-0 text-success"}):f.status==="conflicts"?u.jsx(gm,{className:"mt-1 size-3.5 shrink-0 text-warning"}):f.status==="mergeable"?u.jsx(Y5,{className:"mt-1 size-3.5 shrink-0 text-muted-foreground"}):u.jsx(gm,{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(Yl,{children:u.jsxs("div",{className:"flex min-w-0 w-full items-center justify-end gap-2",children:[u.jsx(Ie,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),u.jsx(Ie,{className:"max-w-full min-w-0",size:"sm",disabled:H,onClick:()=>void M(),children:w?u.jsxs(u.Fragment,{children:[u.jsx(bn,{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 sxe({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(G=>k(G)).catch(G=>{R(G instanceof Error?G.message:String(G))}).finally(()=>{m(!1)}))},[t,o]);const A=y.trim().toLowerCase(),j=G=>G.filter(te=>A?[te.displayName,te.name,te.description,te.prTitle,te.headLabel].some(P=>P==null?void 0:P.toLowerCase().includes(A)):!0),L=(E==null?void 0:E.currentBranchName)??e,H=new Set(((E==null?void 0:E.pullRequests)??[]).map(G=>G.headRefName??G.name)),M=j((E==null?void 0:E.recent)??[]).filter(G=>G.name!==L),D=j((E==null?void 0:E.local)??[]).filter(G=>G.name!==L),z=j((E==null?void 0:E.remote)??[]).filter(G=>G.name!==L&&!H.has(G.name)),O=j((E==null?void 0:E.pullRequests)??[]).filter(G=>G.name!==L),F=(E==null?void 0:E.pullRequests.length)??0;async function $(G){b(!0);try{await i(G),a(!1),_(""),C("branches")}finally{b(!1)}}async function B(){b(!0);try{await s(),a(!1),_(""),C("branches")}finally{b(!1)}}function U(){a(!1),d(!0)}return u.jsxs(bu,{open:o,onOpenChange:a,children:[u.jsx(xu,{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(Na,{className:"h-3.5 w-3.5 shrink-0"}),u.jsx("span",{className:"truncate",children:e??"Detached HEAD"}),u.jsx(uh,{className:"h-3.5 w-3.5 shrink-0"})]})}),u.jsx(rc,{align:"start",className:"w-[320px] p-2",children:u.jsxs("div",{className:"space-y-2",children:[u.jsx(bF,{value:y,onChange:_,placeholder:w==="pull_requests"?"Search pull requests":"Search branches",disabled:f||g,trailingAction:u.jsx(Ie,{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(ji,{value:w,onValueChange:G=>C(G),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(bn,{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(Uc,{title:"Open PRs",entries:O,emptyLabel:(E==null?void 0:E.pullRequestsStatus)==="error"?E.pullRequestsError??"Could not load pull requests.":(E==null?void 0:E.pullRequestsStatus)==="unavailable"?"Pull requests unavailable for this repository.":"No open pull requests.",disabled:g,stickyTitle:!0,onSelect:G=>{$(G)}}):u.jsxs("div",{className:"space-y-3",children:[u.jsx(Uc,{title:"Recent",entries:M,emptyLabel:"No recent branches.",disabled:g,stickyTitle:!0,onSelect:G=>{$(G)}}),u.jsx(Uc,{title:"Local",entries:D,emptyLabel:"No local branches.",disabled:g,stickyTitle:!0,onSelect:G=>{$(G)}}),u.jsx(Uc,{title:"Remote",entries:z,emptyLabel:"No remote branches.",disabled:g,stickyTitle:!0,onSelect:G=>{$(G)}})]})}),L?u.jsx(Ie,{variant:"default",size:"sm",disabled:f||g||!!T,onClick:U,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(_G,{className:"mr-1.5 inline h-3.5 w-3.5 shrink-0"}),"Merge branch into ",L,"..."]})}):null]})}),u.jsx(ixe,{open:c,onOpenChange:d,branchList:E,currentBranchName:L,onPreviewMergeBranch:n,onMergeBranch:r})]})}function oxe({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 _=gF(e),w=Zbe(e),[C,E]=v.useState(null),k=v.useRef(null),T=v.useRef(null),{sentinelRef:R,isStuck:A}=Cde({rootRef:t,disabled:r}),j=v.useMemo(()=>Qbe(n,e),[e,n]),L=j!==null,H=DI({isCollapsed:r,hasPreviewAttachment:L,patch:m,patchError:g,isPatchLoading:b});v.useEffect(()=>{if(!H)return;const O=`${e.path}\0${e.patchDigest}`;T.current!==O&&(T.current=O,y(e.path).catch(()=>{}))},[e.patchDigest,e.path,y,H]);function M(O){if(kh(O).openInNewTab){typeof window<"u"&&window.open(new URL(O.contentUrl,window.location.origin).toString(),"_blank","noopener,noreferrer");return}E(O.id)}function D(O){var $;O.preventDefault(),O.stopPropagation();const F=O.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(L||m!==void 0){c();return}if(b)return;if(!(g!==void 0||DI({isCollapsed:!1,hasPreviewAttachment:L,patch:m,patchError:g,isPatchLoading:b}))){c();return}y(e.path).then(()=>{c()}).catch(()=>{})}return u.jsxs(gu,{children:[u.jsx(vu,{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:O=>{O.key!=="Enter"&&O.key!==" "||(O.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(vF,{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(pm,{className:"h-3.5 w-3.5 shrink-0"})}),b&&r&&!j?u.jsx(bn,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):r?u.jsx(uh,{className:"h-3.5 w-3.5 shrink-0"}):u.jsx(V5,{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(v2,{attachment:j,onClick:()=>M(j)}):u.jsx($o,{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(bn,{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(wde,{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(Th,{source:j&&C===j.id?Ep(j,"user_attachment"):null,open:j!==null&&C===j.id,onOpenChange:O=>!O&&E(null)})]},e.path)}),u.jsxs(tc,{children:[u.jsxs(In,{onSelect:O=>{O.stopPropagation(),f.onOpenFile(e.path)},children:[u.jsx(vk,{className:"h-3.5 w-3.5"}),u.jsxs("span",{className:"text-xs font-medium",children:["Open in ",s]})]}),u.jsxs(In,{onSelect:O=>{O.stopPropagation(),f.onOpenInFinder(e.path)},children:[u.jsx(Tx,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Open in Finder"})]}),u.jsxs(In,{onSelect:O=>{O.stopPropagation(),f.onDiscardFile(e.path)},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[u.jsx(hu,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Discard Changes"})]}),u.jsxs(In,{disabled:!_,onSelect:O=>{O.stopPropagation(),_&&f.onIgnoreFile(e.path)},children:[u.jsx(nj,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Ignore File"})]}),u.jsxs(In,{disabled:!w,onSelect:O=>{O.stopPropagation(),w&&f.onIgnoreFolder(e.path)},children:[u.jsx(nj,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Ignore folder..."})]}),u.jsx(M4,{}),u.jsxs(In,{onSelect:O=>{O.stopPropagation(),f.onCopyFilePath(e.path)},children:[u.jsx(Da,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Copy File Path"})]}),u.jsxs(In,{onSelect:O=>{O.stopPropagation(),f.onCopyRelativePath(e.path)},children:[u.jsx(Da,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Copy Relative Path"})]})]})]})}function axe({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:L,onDiffRenderModeChange:H,onWrapLinesChange:M}){var Xe;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,[O,F]=v.useState(!1),[$,B]=v.useState(null),[U,G]=v.useState(!1),[te,P]=v.useState(!1),[Y,ee]=v.useState({}),[V,ue]=v.useState({}),[ge,Z]=v.useState({}),ne=v.useRef(null),ie=v.useRef({}),le=v.useMemo(()=>t.files.map(_e=>_e.path),[t.files]),oe=v.useMemo(()=>le.join("\0"),[le]),ke=Ai(_e=>{var De;return e?((De=_e.projectUi[e])==null?void 0:De.viewMode)??(z?"changes":"history"):z?"changes":"history"}),Ee=Ai(_e=>{var De;return e?((De=_e.projectUi[e])==null?void 0:De.collapsedPaths)??Ev:Ev}),Pe=Ai(_e=>{var De;return e?((De=_e.projectUi[e])==null?void 0:De.summary)??"":""}),Ze=Ai(_e=>{var De;return e?((De=_e.projectUi[e])==null?void 0:De.description)??"":""}),ut=Ai(_e=>_e.reconcileCollapsedPaths),Mt=Ai(_e=>_e.toggleCollapsedPath),ye=Ai(_e=>_e.setViewMode),an=Ai(_e=>_e.setCommitDraft),jt=Ai(_e=>_e.clearCommitDraft),_t=bv(_e=>e?_e.checkedPathsByProjectId[e]??Ev:Ev),ft=bv(_e=>_e.reconcileProject),Pt=bv(_e=>_e.setChecked),It=bv(_e=>_e.setAllChecked),st=v.useRef(z);v.useEffect(()=>{e&&ut(e,le)},[le,oe,e,ut]),v.useEffect(()=>{const _e=Object.fromEntries(t.files.map(Ve=>[Ve.path,Ve.patchDigest])),De=Ve=>ie.current[Ve]===_e[Ve];ee(Ve=>Object.fromEntries(Object.entries(Ve).filter(([We])=>le.includes(We)&&De(We)))),ue(Ve=>Object.fromEntries(Object.entries(Ve).filter(([We])=>le.includes(We)&&De(We)))),Z(Ve=>Object.fromEntries(Object.entries(Ve).filter(([We])=>le.includes(We)&&De(We)))),ie.current=_e},[t.files,le,oe]),v.useEffect(()=>{e&&ft(e,le)},[le,oe,e,ft]),v.useEffect(()=>{if(!e)return;if(st.current!==z){ye(e,z?"changes":"history"),st.current=z;return}st.current=z},[z,e,ye]);const Ot=v.useMemo(()=>t.files.filter(_e=>_t[_e.path]??!0).map(_e=>_e.path),[_t,t.files]),he=Ot.length,Re=t.files.length>0&&he===t.files.length,Ue=he>0&&he<t.files.length,Je=Pe.trim(),Ke=Je.length>0,vt=$!==null,St=O||vt,ze=((Xe=t.branchHistory)==null?void 0:Xe.entries)??[],Be=t.behindCount??0,Oe=t.aheadCount??0,Fe=t.hasUpstream===!0,bt=t.hasUpstream===!1&&!!t.branchName,wt=t.hasOriginRemote===!0,fn=t.branchName?t.branchName.split("/").map(_e=>encodeURIComponent(_e)).join("/"):null,Xt=bt?"publish":Be>0?"pull":"fetch",Qt=t.originRepoSlug&&fn?`https://github.com/${t.originRepoSlug}/compare/${fn}?expand=1`:null,Rt=!!(Fe&&Qt&&t.branchName&&t.branchName!==t.defaultBranchName),xt=t.status==="ready"&&he>0&&!St,mt=t.status==="ready"&&he>0&&Ke&&!St,kt=wt?"commit_and_push":"commit_only",pt=t.branchName??"current branch";async function $t(_e){if(mt){B(_e);try{const De=await A({paths:Ot,summary:Je,description:Ze.trim(),mode:_e});(De!=null&&De.ok||De!=null&&De.localCommitCreated)&&e&&jt(e)}finally{B(null)}}}async function nt(){if(xt){F(!0);try{const _e=await C({paths:Ot});e&&an(e,{summary:_e.subject,description:_e.body})}finally{F(!1)}}}function we(_e){if(!(!(_e.metaKey||_e.ctrlKey)||_e.key!=="Enter")){if(_e.preventDefault(),Ke){$t(kt);return}nt()}}async function tt(_e=Xt){if(!(t.status!=="ready"||U)){G(!0);try{await j(_e)}finally{G(!1)}}}const qe=v.useCallback(async _e=>{var De;if(Y[_e]!==void 0||ge[_e])return Y[_e]??"";Z(Ve=>({...Ve,[_e]:!0})),ue(Ve=>{if(!(_e in Ve))return Ve;const{[_e]:We,...Ut}=Ve;return Ut});try{const Ve=await L(_e);ee(Ut=>({...Ut,[_e]:Ve}));const We=(De=t.files.find(Ut=>Ut.path===_e))==null?void 0:De.patchDigest;return We&&(ie.current={...ie.current,[_e]:We}),Ve}catch(Ve){const We=Ve instanceof Error?Ve.message:String(Ve);throw ue(Ut=>({...Ut,[_e]:We})),Ve}finally{Z(Ve=>{const{[_e]:We,...Ut}=Ve;return Ut})}},[t.files,ge,L,Y]);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(sxe,{currentBranchName:t.branchName,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:y,onCheckoutBranch:_,onCreateBranch:w})}),t.status==="ready"?wt?Xt==="publish"?u.jsxs(Ie,{variant:"ghost",size:"sm",onClick:()=>void tt(),disabled:U,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[U?u.jsx(bn,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(Zv,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Publish Branch"})]}):u.jsxs("div",{className:"flex items-center gap-1",children:[Xt==="fetch"?u.jsxs(Pi,{delayDuration:0,children:[u.jsx(Oi,{asChild:!0,children:u.jsxs(Ie,{variant:"ghost",size:"sm",onClick:()=>void tt(),disabled:U,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[U?u.jsx(bn,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(tO,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Fetch"})]})}),u.jsx(vi,{children:Jbe(t.lastFetchedAt)})]}):u.jsxs(Ie,{variant:"ghost",size:"sm",onClick:()=>void tt(),disabled:U,className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[U?u.jsx(bn,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(bk,{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})]}),Fe&&Oe>0?u.jsxs(Ie,{variant:"default",size:"sm",onClick:()=>void tt("push"),disabled:U,className:"h-7 gap-1.5 px-2 text-xs",children:[U?u.jsx(bn,{className:"h-3.5 w-3.5 animate-spin"}):u.jsx(Zv,{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:Oe})]}):null,Rt&&Qt?u.jsxs(Ie,{variant:"ghost",size:"sm",onClick:()=>{typeof window>"u"||window.open(Qt,"_blank","noopener,noreferrer")},className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[u.jsx(X5,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"PR"})]}):null]}):u.jsxs(Ie,{variant:"default",size:"sm",onClick:()=>P(!0),className:"h-7 gap-1.5 px-3 text-xs",children:[u.jsx(CG,{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:[ke==="changes"?u.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground/70",children:[u.jsx(vF,{checked:Re,mixed:Ue,label:Ue?"Select all files for commit":Re?"Unselect all files from commit":"Select all files for commit",onClick:()=>{!e||t.files.length===0||It(e,le,Ue?!0:!Re)}}),u.jsxs("span",{children:[he," 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(ji,{value:ke,onValueChange:_e=>{e&&ye(e,_e)},size:"sm",optionClassName:"flex-1 justify-center",options:[{value:"changes",label:"Changes"},{value:"history",label:"History"}]})})}),ke==="changes"?u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(nS,{label:"Unified diff",active:r==="unified",onClick:()=>H("unified"),children:u.jsx(Eq,{className:"h-4 w-4"})}),u.jsx(nS,{label:"Side-by-side diff",active:r==="split",onClick:()=>H("split"),children:u.jsx(AW,{className:"h-4 w-4"})}),u.jsx(nS,{label:i?"Disable word wrap":"Enable word wrap",active:i,onClick:()=>M(!i),children:u.jsx(nK,{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(Ie,{size:"sm",onClick:()=>void E(),children:"Init Git"})]})}):ke==="history"?ze.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:ze.map((_e,De)=>u.jsx(exe,{entry:_e,isPendingPush:De<Oe},_e.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(_e=>{const De=Ee[_e.path]??!0,Ve=_t[_e.path]??!0;return u.jsx(oxe,{file:_e,rootRef:ne,projectId:e,isCollapsed:De,isChecked:Ve,editorLabel:n,diffRenderMode:r,wrapLines:i,onToggleCollapsed:()=>{e&&Mt(e,_e.path)},onToggleChecked:()=>{e&&Pt(e,_e.path,!Ve)},fileActions:D,patch:Y[_e.path],patchError:V[_e.path],isPatchLoading:!!ge[_e.path],onLoadPatch:qe},_e.path)}),ke==="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(un,{value:Pe,onChange:_e=>{e&&an(e,{summary:_e.target.value,description:Ze})},onKeyDown:we,placeholder:"Commit message (override)",className:"rounded-t-xl rounded-b-none px-3",disabled:St||t.status!=="ready"}),u.jsx(La,{value:Ze,onChange:_e=>{e&&an(e,{summary:Pe,description:_e.target.value})},onKeyDown:we,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:St||t.status!=="ready"}),u.jsx("div",{className:"w-full flex flex-row",children:u.jsxs(gu,{children:[u.jsx(vu,{asChild:!0,children:u.jsx(Ie,{type:"button",className:"-mt-px w-full rounded-xl",disabled:Ke?!mt:!xt,onClick:()=>{if(Ke){$t(kt);return}nt()},children:u.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[Ke?vt?u.jsx(bn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):kt==="commit_and_push"?t.hasUpstream?u.jsx(Zv,{strokeWidth:2.5,className:"size-3 shrink-0"}):u.jsx(Y5,{strokeWidth:2.5,className:"size-3 shrink-0"}):u.jsx(ts,{strokeWidth:2.5,className:"size-3 shrink-0"}):O?u.jsx(bn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):u.jsx(lq,{strokeWidth:2.5,className:"size-3 shrink-0"}),u.jsx("span",{className:"min-w-0 truncate text-left",children:Ke?vt?$==="commit_only"?"Committing...":"Committing & Pushing...":kt==="commit_only"?u.jsxs(u.Fragment,{children:["Commit to ",u.jsx(Na,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),pt]}):t.hasUpstream?u.jsxs(u.Fragment,{children:["Commit & push to ",u.jsx(Na,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),pt]}):u.jsxs(u.Fragment,{children:["Commit & publish ",u.jsx(Na,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),pt]}):O?"Generating...":u.jsxs(u.Fragment,{children:["Generate message for ",u.jsx(Na,{strokeWidth:2.5,className:"mr-[4.5px] ml-0.5 inline size-3 "}),pt]})})]})})}),t.hasUpstream?u.jsx(tc,{children:u.jsx(In,{disabled:!Ke||!mt,onSelect:_e=>{_e.stopPropagation(),$t("commit_only")},children:"Commit Only"})}):null]})})]})})]}):null]})})]}),u.jsx(rxe,{open:te,onOpenChange:P,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:T,onPublish:R})]})})}const lxe=v.memo(axe);function cxe(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function uxe(e,t){const n=getComputedStyle(e.ownerDocument.body),r=parseFloat(n.fontSize);return t*r}function dxe(e){return e/100*window.innerHeight}function hxe(e){return e/100*window.innerWidth}function fxe(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 Vf({groupSize:e,panelElement:t,styleProp:n}){let r;const[i,s]=fxe(n);switch(s){case"%":{r=i/100*e;break}case"px":{r=i;break}case"rem":{r=uxe(t,i);break}case"em":{r=cxe(t,i);break}case"vh":{r=dxe(i);break}case"vw":{r=hxe(i);break}}return r}function Ii(e){return parseFloat(e.toFixed(3))}function eh({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 lC(e){const{panels:t}=e,n=eh({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=Vf({groupSize:n,panelElement:i,styleProp:s.collapsedSize});o=Ii(f/n*100)}let a;if(s.defaultSize!==void 0){const f=Vf({groupSize:n,panelElement:i,styleProp:s.defaultSize});a=Ii(f/n*100)}let c=0;if(s.minSize!==void 0){const f=Vf({groupSize:n,panelElement:i,styleProp:s.minSize});c=Ii(f/n*100)}let d=100;if(s.maxSize!==void 0){const f=Vf({groupSize:n,panelElement:i,styleProp:s.maxSize});d=Ii(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 Rn(e,t="Assertion error"){if(!e)throw Error(t)}function cC(e,t){return Array.from(t).sort(e==="horizontal"?mxe:pxe)}function mxe(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function pxe(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function xF(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function yF(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 gxe({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}=yF(r,o),d=e==="horizontal"?a:c;d<s&&(s=d,i=o)}return Rn(i,"No rect found"),i}let Nv;function vxe(){return Nv===void 0&&(typeof matchMedia=="function"?Nv=!!matchMedia("(pointer:coarse)").matches:Nv=!1),Nv}function _F(e){const{element:t,orientation:n,panels:r,separators:i}=e,s=cC(n,Array.from(t.children).filter(xF).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=gxe({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=vxe()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(R.width<A){const L=A-R.width;R=new DOMRect(R.x-L/2,R.y,R.width+L,R.height)}if(R.height<A){const L=A-R.height;R=new DOMRect(R.x,R.y-L/2,R.width,R.height+L)}const j=y<=d||y>f;!a&&!j&&o.push({group:e,groupSize:eh({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 Fl,b5;let wF=(b5=class{constructor(){Sl(this,Fl,{})}addListener(t,n){const r=gr(this,Fl)[t];return r===void 0?gr(this,Fl)[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=gr(this,Fl)[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(){ms(this,Fl,{})}removeListener(t,n){const r=gr(this,Fl)[t];if(r!==void 0){const i=r.indexOf(n);i>=0&&r.splice(i,1)}}},Fl=new WeakMap,b5),Oo=new Map;const SF=new wF;function bxe(e){Oo=new Map(Oo),Oo.delete(e)}function OI(e,t){for(const[n]of Oo)if(n.id===e)return n}function Gl(e,t){for(const[n,r]of Oo)if(n.id===e)return r;if(t)throw Error(`Could not find data for Group with id ${e}`)}function _u(){return Oo}function x2(e,t){return SF.addListener("groupChange",n=>{n.group.id===e&&t(n)})}function Ha(e,t){const n=Oo.get(e);Oo=new Map(Oo),Oo.set(e,t),SF.emit("groupChange",{group:e,prev:n,next:t})}function xxe(e,t,n){let r,i={x:1/0,y:1/0};for(const s of t){const o=yF(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 yxe(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function _xe(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:FI(e),b:FI(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();Rn(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:BI(zI(n.a)),b:BI(zI(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 wxe=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Sxe(e){const t=getComputedStyle(CF(e)??e).display;return t==="flex"||t==="inline-flex"}function Cxe(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||Sxe(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"||wxe.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function zI(e){let t=e.length;for(;t--;){const n=e[t];if(Rn(n,"Missing node"),Cxe(n))return n}return null}function BI(e){return e&&Number(getComputedStyle(e).zIndex)||0}function FI(e){const t=[];for(;e;)t.push(e),e=CF(e);return t}function CF(e){const{parentNode:t}=e;return yxe(t)?t.host:t}function kxe(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 Exe({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!xF(n)||n.contains(e)||e.contains(n))return!0;if(_xe(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(kxe(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function y2(e,t){const n=[];return t.forEach((r,i)=>{if(i.disabled)return;const s=_F(i),o=xxe(i.orientation,s,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&Exe({groupElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&n.push(o.hitRegion)}),n}function Nxe(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 hi(e,t,n=0){return Math.abs(Ii(e)-Ii(t))<=n}function Ao(e,t){return hi(e,t)?0:e>t?1:-1}function Nd({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(Ao(r,c)<0)if(s){const d=(i+c)/2;Ao(r,d)<0?r=i:r=c}else r=c;return r=Math.min(a,r),r=Ii(r),r}function Wm({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(hi(e,0))return t;const o=s==="imperative-api",a=Object.values(t),c=Object.values(i),d=[...a],[f,m]=r;Rn(f!=null,"Invalid first pivot index"),Rn(m!=null,"Invalid second pivot index");let g=0;switch(s){case"keyboard":{{const _=e<0?m:f,w=n[_];Rn(w,`Panel constraints not found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const T=a[_];if(Rn(T!=null,`Previous layout not found for panel index ${_}`),hi(T,C)){const R=k-T;Ao(R,Math.abs(e))>0&&(e=e<0?0-R:R)}}}{const _=e<0?f:m,w=n[_];Rn(w,`No panel constraints found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const T=a[_];if(Rn(T!=null,`Previous layout not found for panel index ${_}`),hi(T,k)){const R=T-C;Ao(R,Math.abs(e))>0&&(e=e<0?0-R:R)}}}break}default:{const _=e<0?m:f,w=n[_];Rn(w,`Panel constraints not found for index ${_}`);const C=a[_],{collapsible:E,collapsedSize:k,minSize:T}=w;if(E&&Ao(C,T)<0)if(e>0){const R=T-k,A=R/2,j=C+e;Ao(j,T)<0&&(e=Ao(e,A)<=0?0:R)}else{const R=T-k,A=100-R/2,j=C-e;Ao(j,T)<0&&(e=Ao(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];Rn(k!=null,`Previous layout not found for panel index ${w}`);const T=Nd({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[_];Rn(C!=null,`Previous layout not found for panel index ${_}`);const E=C-w,k=Nd({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:C,size:E});if(!hi(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(Nxe(c,d))return i;{const _=e<0?m:f,w=a[_];Rn(w!=null,`Previous layout not found for panel index ${_}`);const C=w+g,E=Nd({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:w,size:C});if(d[_]=E,!hi(E,C)){let k=C-E,T=e<0?m:f;for(;T>=0&&T<n.length;){const R=d[T];Rn(R!=null,`Previous layout not found for panel index ${T}`);const A=R+k,j=Nd({overrideDisabledPanels:o,panelConstraints:n[T],prevSize:R,size:A});if(hi(R,j)||(k-=j-R,d[T]=j),hi(k,0))break;e>0?T--:T++}}}const b=Object.values(d).reduce((_,w)=>w+_,0);if(!hi(b,100,.1))return i;const y=Object.keys(i);return d.reduce((_,w,C)=>(_[y[C]]=w,_),{})}function iu(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(t[n]===void 0||Ao(e[n],t[n])!==0)return!1;return!0}function su({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(!hi(i,100)&&r.length>0)for(let a=0;a<t.length;a++){const c=r[a];Rn(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];Rn(c!=null,`No layout data found for index ${a}`);const d=r[a];Rn(d!=null,`No layout data found for index ${a}`);const f=Nd({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:c,size:d});d!=f&&(s+=d-f,r[a]=f)}if(!hi(s,0))for(let a=0;a<t.length;a++){const c=r[a];Rn(c!=null,`No layout data found for index ${a}`);const d=c+s,f=Nd({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:c,size:d});if(c!==f&&(s-=f-c,r[a]=f,hi(s,0)))break}const o=Object.keys(e);return r.reduce((a,c,d)=>(a[o[d]]=c,a),{})}function kF({groupId:e,panelId:t}){const n=()=>{const a=_u();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=Wm({delta:w?c-a:a-c,initialLayout:b,panelConstraints:f,pivotIndices:w?[_-1,_]:[_,_+1],prevLayout:b,trigger:"imperative-api"}),E=su({layout:C,panelConstraints:f});iu(b,E)||Ha(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&&hi(c,d)},resize:a=>{const{group:c}=n(),{element:d}=i(),f=eh({group:c}),m=Vf({groupSize:f,panelElement:d,styleProp:a}),g=Ii(m/f*100);o(g)}}}function $I(e){if(e.defaultPrevented)return;const t=_u();y2(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=kF({groupId:n.group.id,panelId:r.id});s&&i!==void 0&&(s.resize(i),e.preventDefault())}}})}function mb(e){const t=_u();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 EF({groupId:e}){const t=()=>{const n=_u();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=su({layout:n,panelConstraints:i});return r?a:(iu(a,d)||Ha(s,{defaultLayoutDeferred:r,derivedPanelConstraints:i,groupSize:o,layout:d,separatorToPanels:c}),d)}}}function Ac(e,t){const n=mb(e),r=Gl(n.id,!0),i=n.separators.find(f=>f.element===e);Rn(i,"Matching separator not found");const s=r.separatorToPanels.get(i);Rn(s,"Matching panels not found");const o=s.map(f=>n.panels.indexOf(f)),a=EF({groupId:n.id}).getLayout(),c=Wm({delta:t,initialLayout:a,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:a,trigger:"keyboard"}),d=su({layout:c,panelConstraints:r.derivedPanelConstraints});iu(a,d)||Ha(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:d,separatorToPanels:r.separatorToPanels})}function HI(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=mb(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&Ac(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&Ac(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&Ac(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&Ac(t,-5);break}case"End":{e.preventDefault(),Ac(t,100);break}case"Enter":{e.preventDefault();const r=mb(t),i=Gl(r.id,!0),{derivedPanelConstraints:s,layout:o,separatorToPanels:a}=i,c=r.separators.find(g=>g.element===t);Rn(c,"Matching separator not found");const d=a.get(c);Rn(d,"Matching panels not found");const f=d[0],m=s.find(g=>g.panelId===f.id);if(Rn(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;Ac(t,b-g)}break}case"F6":{e.preventDefault();const r=mb(t).separators.map(o=>o.element),i=Array.from(r).findIndex(o=>o===e.currentTarget);Rn(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(),Ac(t,-100);break}}}let Bd={cursorFlags:0,state:"inactive"};const _2=new wF;function ou(){return Bd}function Txe(e){return _2.addListener("change",e)}function Rxe(e){const t=Bd,n={...Bd};n.cursorFlags=e,Bd=n,_2.emit("change",{prev:t,next:n})}function Fd(e){const t=Bd;Bd=e,_2.emit("change",{prev:t,next:e})}function UI(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=_u(),n=y2(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)}),Fd({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}const Axe=e=>e,rS=()=>{},NF=1,TF=2,RF=4,AF=8,VI=3,WI=12;let Tv;function GI(){return Tv===void 0&&(Tv=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(Tv=!0)),Tv}function jxe({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&&GI()){const s=(e&NF)!==0,o=(e&TF)!==0,a=(e&RF)!==0,c=(e&AF)!==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 GI()?r>0&&i>0?"move":r>0?"ew-resize":"ns-resize":r>0&&i>0?"grab":r>0?"col-resize":"row-resize"}}const qI=new WeakMap;function w2(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=qI.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&e.adoptedStyleSheets.push(n));const r=ou();switch(r.state){case"active":case"hover":{const i=jxe({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}}qI.set(e,{prevStyle:t,styleSheet:n})}function jF({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=Wm({delta:_,initialLayout:w,panelConstraints:k,pivotIndices:d.panels.map(L=>b.indexOf(L)),prevLayout:R,trigger:"mouse-or-touch"});if(iu(j,R)){if(_!==0&&!y)switch(g){case"horizontal":{a|=_<0?NF:TF;break}case"vertical":{a|=_<0?RF:AF;break}}}else Ha(d.group,{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:T,layout:j,separatorToPanels:A})}});let c=0;t.movementX===0?c|=o&VI:c|=a&VI,t.movementY===0?c|=o&WI:c|=a&WI,Rxe(c),w2(e)}function KI(e){const t=_u(),n=ou();switch(n.state){case"active":jF({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function YI(e){if(e.defaultPrevented)return;const t=ou(),n=_u();switch(t.state){case"active":{if(e.buttons===0){Fd({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(r=>{const i=Gl(r.group.id,!0);Ha(r.group,i)});return}jF({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const r=y2(e,n);r.length===0?t.state!=="inactive"&&Fd({cursorFlags:0,state:"inactive"}):Fd({cursorFlags:0,hitRegions:r,state:"hover"}),w2(e.currentTarget);break}}}function XI(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(ou().state){case"hover":Fd({cursorFlags:0,state:"inactive"})}}function QI(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=ou();switch(t.state){case"active":Fd({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(w2(e.currentTarget),t.hitRegions.forEach(n=>{const r=Gl(n.group.id,!0);Ha(n.group,r)}),e.preventDefault())}}function ZI(e){let t=0,n=0;const r={};for(const s of e)if(s.defaultSize!==void 0){t++;const o=Ii(s.defaultSize);n+=o,r[s.panelId]=o}else r[s.panelId]=void 0;const i=e.length-t;if(i!==0){const s=Ii((100-n)/i);for(const o of e)o.defaultSize===void 0&&(r[o.panelId]=s)}return r}function Mxe(e,t,n){if(!n[0])return;const r=e.panels.find(c=>c.element===t);if(!r||!r.onResize)return;const i=eh({group:e}),s=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,a={asPercentage:Ii(s/i*100),inPixels:s};r.mutableValues.prevSize=a,r.onResize(a,r.id,o)}function Lxe(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 Ixe({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=Ii(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]=Ii(g/s*d)}else{const m=Ii(d/c.length);for(const g of c)f[g]=m}return f}function Dxe(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 md=new Map;function Pxe(e){let t=!0;Rn(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=eh({group:e});if(E===0)return;const k=Gl(e.id);if(!k)return;const T=lC(e),R=k.defaultLayoutDeferred?ZI(T):k.layout,A=Ixe({group:e,nextGroupSize:E,prevGroupSize:k.groupSize,prevLayout:R}),j=su({layout:A,panelConstraints:T});if(!k.defaultLayoutDeferred&&iu(k.layout,j)&&Lxe(k.derivedPanelConstraints,T)&&k.groupSize===E)return;Ha(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:T,groupSize:E,layout:j,separatorToPanels:k.separatorToPanels})}}else Mxe(e,C,w)}});s.observe(e.element),e.panels.forEach(y=>{Rn(!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=eh({group:e}),a=lC(e),c=e.panels.map(({id:y})=>y).join(",");let d=e.mutableState.defaultLayout;d&&(Dxe(e.panels,d)||(d=void 0));const f=e.mutableState.layouts[c]??d??ZI(a),m=su({layout:f,panelConstraints:a}),g=e.element.ownerDocument;md.set(g,(md.get(g)??0)+1);const b=new Map;return _F(e).forEach(y=>{y.separator&&b.set(y.separator,y.panels)}),Ha(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:a,groupSize:o,layout:m,separatorToPanels:b}),e.separators.forEach(y=>{Rn(!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",HI)}),md.get(g)===1&&(g.addEventListener("dblclick",$I,!0),g.addEventListener("pointerdown",UI,!0),g.addEventListener("pointerleave",KI),g.addEventListener("pointermove",YI),g.addEventListener("pointerout",XI),g.addEventListener("pointerup",QI,!0)),function(){t=!1,md.set(g,Math.max(0,(md.get(g)??0)-1)),bxe(e),e.separators.forEach(y=>{y.element.removeEventListener("keydown",HI)}),md.get(g)||(g.removeEventListener("dblclick",$I,!0),g.removeEventListener("pointerdown",UI,!0),g.removeEventListener("pointerleave",KI),g.removeEventListener("pointermove",YI),g.removeEventListener("pointerout",XI),g.removeEventListener("pointerup",QI,!0)),s.disconnect()}}function Oxe(){const[e,t]=v.useState({}),n=v.useCallback(()=>t({}),[]);return[e,n]}function S2(e){const t=v.useId();return`${e??t}`}const wu=typeof window<"u"?v.useLayoutEffect:v.useEffect;function lm(e){const t=v.useRef(e);return wu(()=>{t.current=e},[e]),v.useCallback((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[t])}function C2(...e){return lm(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function k2(e){const t=v.useRef({...e});return wu(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const MF=v.createContext(null);function zxe(e,t){const n=v.useRef({getLayout:()=>({}),setLayout:Axe});v.useImperativeHandle(t,()=>n.current,[]),wu(()=>{Object.assign(n.current,EF({groupId:e}))})}function LF({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:{}}),_=lm(D=>{iu(y.current.onLayoutChange,D)||(y.current.onLayoutChange=D,c==null||c(D))}),w=lm(D=>{iu(y.current.onLayoutChanged,D)||(y.current.onLayoutChanged=D,d==null||d(D))}),C=S2(a),E=v.useRef(null),[k,T]=Oxe(),R=v.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:m,separators:[]}),A=C2(E,s);zxe(C,o);const j=lm((D,z)=>{const O=ou(),F=OI(D),$=Gl(D);if($){let B=!1;switch(O.state){case"active":{B=O.hitRegions.some(U=>U.group===F);break}}return{flexGrow:$.layout[z]??1,pointerEvents:B?"none":void 0}}return{flexGrow:(n==null?void 0:n[z])??1}}),L=k2({defaultLayout:n,disableCursor:r}),H=v.useMemo(()=>({get disableCursor(){return!!L.disableCursor},getPanelStyles:j,id:C,orientation:f,registerPanel:D=>{const z=R.current;return z.panels=cC(f,[...z.panels,D]),T(),()=>{z.panels=z.panels.filter(O=>O!==D),T()}},registerSeparator:D=>{const z=R.current;return z.separators=cC(f,[...z.separators,D]),T(),()=>{z.separators=z.separators.filter(O=>O!==D),T()}},togglePanelDisabled:(D,z)=>{const O=R.current.panels.find(B=>B.id===D);O&&(O.panelConstraints.disabled=z);const F=OI(C),$=Gl(C);F&&$&&Ha(F,{...$,derivedPanelConstraints:lC(F)})},toggleSeparatorDisabled:(D,z)=>{const O=R.current.separators.find(F=>F.id===D);O&&(O.disabled=z)}}),[j,C,T,f,L]),M=v.useRef(null);return wu(()=>{const D=E.current;if(D===null)return;const z=R.current;let O;if(L.defaultLayout!==void 0&&Object.keys(L.defaultLayout).length===z.panels.length){O={};for(const P of z.panels){const Y=L.defaultLayout[P.id];Y!==void 0&&(O[P.id]=Y)}}const F={disabled:!!i,element:D,id:C,mutableState:{defaultLayout:O,disableCursor:!!L.disableCursor,expandedPanelSizes:R.current.lastExpandedPanelSizes,layouts:R.current.layouts},orientation:f,panels:z.panels,resizeTargetMinimumSize:z.resizeTargetMinimumSize,separators:z.separators};M.current=F;const $=Pxe(F),{defaultLayoutDeferred:B,derivedPanelConstraints:U,layout:G}=Gl(F.id,!0);!B&&U.length>0&&(_(G),w(G));const te=x2(C,P=>{const{defaultLayoutDeferred:Y,derivedPanelConstraints:ee,layout:V}=P.next;if(Y||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}=P.prev??{};if(ne){const ie=hi(Z.collapsedSize,V[Z.panelId]),le=hi(Z.collapsedSize,ne[Z.panelId]);ie&&!le&&(F.mutableState.expandedPanelSizes[Z.panelId]=ne[Z.panelId])}}});const ge=ou().state!=="active";_(V),ge&&w(V)});return()=>{M.current=null,$(),te()}},[i,C,w,_,f,k,L]),v.useEffect(()=>{const D=M.current;D&&(D.mutableState.defaultLayout=n,D.mutableState.disableCursor=!!r)}),u.jsx(MF.Provider,{value:H,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})})}LF.displayName="Group";function E2(){const e=v.useContext(MF);return Rn(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function Bxe(e,t){const{id:n}=E2(),r=v.useRef({collapse:rS,expand:rS,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:rS});v.useImperativeHandle(t,()=>r.current,[]),wu(()=>{Object.assign(r.current,kF({groupId:n,panelId:e}))})}function IF({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=S2(c),C=k2({disabled:s}),E=v.useRef(null),k=C2(E,o),{getPanelStyles:T,id:R,orientation:A,registerPanel:j,togglePanelDisabled:L}=E2(),H=m!==null,M=lm((z,O,F)=>{m==null||m(z,c,F)});wu(()=>{const z=E.current;if(z!==null){const O={element:z,id:w,idIsStable:_,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:H?M:void 0,panelConstraints:{groupResizeBehavior:a,collapsedSize:n,collapsible:r,defaultSize:i,disabled:C.disabled,maxSize:d,minSize:f}};return j(O)}},[a,n,r,i,H,w,_,d,f,M,j,C]),v.useEffect(()=>{L(w,!!s)},[s,w,L]),Bxe(w,g);const D=v.useSyncExternalStore(z=>x2(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:{...Fxe,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})})}IF.displayName="Panel";const Fxe={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function $xe({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=su({layout:Wm({delta:d-o,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e}),panelConstraints:t})[n],i=su({layout:Wm({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:f,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:s,valueNow:o}}function DF({children:e,className:t,disabled:n,elementRef:r,id:i,style:s,...o}){const a=S2(i),c=k2({disabled:n}),[d,f]=v.useState({}),[m,g]=v.useState("inactive"),b=v.useRef(null),y=C2(b,r),{disableCursor:_,id:w,orientation:C,registerSeparator:E,toggleSeparatorDisabled:k}=E2(),T=C==="horizontal"?"vertical":"horizontal";wu(()=>{const A=b.current;if(A!==null){const j={disabled:c.disabled,element:A,id:a},L=E(j),H=Txe(D=>{g(D.next.state!=="inactive"&&D.next.hitRegions.some(z=>z.separator===j)?D.next.state:"inactive")}),M=x2(w,D=>{const{derivedPanelConstraints:z,layout:O,separatorToPanels:F}=D.next,$=F.get(j);if($){const B=$[0],U=$.indexOf(B);f($xe({layout:O,panelConstraints:z,panelId:B.id,panelIndex:U}))}});return()=>{H(),M(),L()}}},[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})}DF.displayName="Separator";const N2=({className:e,...t})=>u.jsx(LF,{className:de("flex h-full w-full",e),...t}),Gm=e=>u.jsx(IF,{...e}),T2=({withHandle:e,orientation:t,disabled:n,className:r,...i})=>u.jsx(DF,{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 PF(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 Hxe(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 PF(r.usage,new Date(r.createdAt).toISOString(),t)}return null}function Uxe(e,t){return!e||t===null||!Number.isFinite(t)||t<=0?e:PF({...e,maxTokens:t},e.updatedAt,e.compactsAutomatically)}function Vxe(e){if(!e)return null;const t=iS(e.inputTokens),n=iS(e.outputTokens),r=iS(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 iS(e){return e===void 0||!Number.isFinite(e)||e<0?0:e}function Li(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 R2=[68,32];function Wxe(){return{isVisible:!1,mainSizes:[...R2],terminals:[],nextTerminalIndex:0}}function Gxe(e,t){return e[t]??Wxe()}function sS(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 qxe(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 Kxe(e){if(e.length===0)return e;const t=e.length+1;return e.map(n=>({...n,size:n.size*e.length/t}))}function pd(e,t,n){return{...e,[t]:n(Gxe(e,t))}}const Il=is()(Ch(e=>({projects:{},addTerminal:(t,n)=>e(r=>({projects:pd(r.projects,t,i=>{var c,d;const s=Kxe(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:qxe(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:pd(r.projects,t,i=>{const s=i.terminals.filter(a=>a.id!==n);if(s.length===0)return{...i,isVisible:!1,terminals:[]};const o=sS(s.map(a=>a.size));return{...i,terminals:s.map((a,c)=>({...a,size:o[c]??100/s.length}))}})})),toggleVisibility:t=>e(n=>({projects:pd(n.projects,t,r=>({...r,isVisible:r.terminals.length>0?!r.isVisible:!1}))})),resetMainSizes:t=>e(n=>({projects:pd(n.projects,t,r=>({...r,mainSizes:[...R2]}))})),setMainSizes:(t,n)=>e(r=>{if(n.length!==2)return r;const i=sS(n);return{projects:pd(r.projects,t,s=>({...s,mainSizes:i}))}}),setTerminalSizes:(t,n)=>e(r=>({projects:pd(r.projects,t,i=>{if(n.length!==i.terminals.length)return i;const s=sS(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})),Yxe={isVisible:!1,mainSizes:[...R2],terminals:[],nextTerminalIndex:0},Xxe=35;function Qxe(e,t){return!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<=0?0:e*(t/100)}function Zxe(e,t){const n=Qxe(e,t);return n>=0&&n<Xxe}const wy=350,Jxe=[.4,0,.2,1],eye=8,JI=1e-6;function tye(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function nye(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function rye(e,t,n){const r=1-e;return 3*r*r*t+6*r*e*(n-t)+3*e*e*(1-n)}function iye(e,t,n){let r=e;for(let i=0;i<eye;i+=1){const s=tye(r,t,n)-e;if(Math.abs(s)<JI)return r;const o=rye(r,t,n);if(Math.abs(o)<JI)break;r-=s/o}return r}function sye(e){if(e<=0)return 0;if(e>=1)return 1;const[t,n,r,i]=Jxe,s=iye(e,t,r);return nye(s,n,i)}function OF(e,t,n){const r=sye(n);return[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r]}function oye({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,L,H,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"),(L=o.current)==null||L.setAttribute("data-right-sidebar-open",n?"true":"false"),(H=o.current)==null||H.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=O=>{const F=Math.min(1,(O-R)/wy),$=OF(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 aye(e){return e.visibilityState==="visible"?e.activeChatId:null}function lye(e){e.socket.setFocusedChat(aye({activeChatId:e.activeChatId,visibilityState:e.visibilityState}))}function cye({socket:e,activeChatId:t}){v.useEffect(()=>{if(typeof document>"u")return;const n=()=>{lye({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 uye({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(Lj({trigger:"pointer",activeElement:document.activeElement,pointerStartTarget:s,pointerEndTarget:g,root:b,fallback:y,hasActiveOverlay:Mj(document),hasActiveSelection:PX(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;Lj({trigger:"escape",activeElement:document.activeElement,fallback:g,hasActiveOverlay:Mj(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(Ab,d),()=>{cancelAnimationFrame(i),window.removeEventListener("pointerdown",a,!0),window.removeEventListener("pointerup",c,!0),window.removeEventListener("keydown",f,!0),window.removeEventListener(Ab,d)}},[r,n,t,e])}function dye(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 hye({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 fye({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;dye({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 L,H,M,D,z,O;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}=hye({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]}),(L=o.current)==null||L.setAttribute("data-terminal-open",r?"true":"false"),(H=a.current)==null||H.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"),(O=a.current)==null||O.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)/wy),B=OF(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 eD=e=>Symbol.iterator in e,tD=e=>"entries"in e,nD=(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},mye=(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 pye(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:eD(e)&&eD(t)?tD(e)&&tD(t)?nD(e,t):mye(e,t):nD({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function cx(e){const t=yn.useRef(void 0);return n=>{const r=e(n);return pye(t.current,r)?t.current:t.current=r}}const cm="__new__";function jc(e){var s,o;const t=(s=e==null?void 0:e.modelOptions)==null?void 0:s.reasoningEffort,n=d1(t)?t:d1(e==null?void 0:e.effort)?e.effort:Zc.reasoningEffort,r=ere(e==null?void 0:e.model),i=bE(r,(o=e==null?void 0:e.modelOptions)==null?void 0:o.contextWindow);return{model:r,modelOptions:{reasoningEffort:!fz(r)&&n==="max"?"high":n,contextWindow:i},planMode:!!(e!=null&&e.planMode)}}function Rv(e){var n,r;const t=(n=e==null?void 0:e.modelOptions)==null?void 0:n.reasoningEffort;return{model:tre(e==null?void 0:e.model),modelOptions:{reasoningEffort:h1(t)?t:h1(e==null?void 0:e.effort)?e.effort:Tm.reasoningEffort,fastMode:typeof((r=e==null?void 0:e.modelOptions)==null?void 0:r.fastMode)=="boolean"?e.modelOptions.fastMode:Tm.fastMode},planMode:!!(e!=null&&e.planMode)}}function gye(){return{claude:{model:"claude-opus-4-7",modelOptions:{...Zc},planMode:!1},codex:{model:"gpt-5.5",modelOptions:{...Tm},planMode:!1}}}function vye(e,t){return e.reasoningEffort===t.reasoningEffort&&e.contextWindow===t.contextWindow}function bye(e,t){return e.reasoningEffort===t.reasoningEffort&&e.fastMode===t.fastMode}function xye(e,t){return e.claude.model===t.claude.model&&e.claude.planMode===t.claude.planMode&&vye(e.claude.modelOptions,t.claude.modelOptions)&&e.codex.model===t.codex.model&&e.codex.planMode===t.codex.planMode&&bye(e.codex.modelOptions,t.codex.modelOptions)}function yye(e,t){if(t===void 0){console.info(`[chat-preferences] ${e}`);return}console.info(`[chat-preferences] ${e}`,t)}function um(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 uC(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 zF(e){return e.providerHint?um(e.providerHint,e.providerDefaults):e.defaultProvider==="last_used"?e.sourceState?uC(e.sourceState):um("claude",e.providerDefaults):um(e.defaultProvider,e.providerDefaults)}function BF(e,t){const n=e.chatStates[t];return n||zF({defaultProvider:e.defaultProvider,providerDefaults:e.providerDefaults,legacyComposerState:e.legacyComposerState})}function Av(e,t,n){const r=BF(e,t);return{chatStates:{...e.chatStates,[t]:n(r)}}}const mi=is()(Ch((e,t)=>({defaultProvider:"last_used",providerDefaults:gye(),chatStates:{},legacyComposerState:{provider:"claude",model:"claude-opus-4-7",modelOptions:{...Zc},planMode:!1},setDefaultProvider:n=>e({defaultProvider:n}),applyServerDefaults:(n,r)=>e(i=>{if(i.defaultProvider===n&&xye(i.providerDefaults,r))return{defaultProvider:n,providerDefaults:r};const{[cm]:o,...a}=i.chatStates;return{defaultProvider:n,providerDefaults:r,chatStates:a}}),setProviderDefaultModel:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?jc({...i.providerDefaults.claude,model:r}):Rv({...i.providerDefaults.codex,model:r})}})),setProviderDefaultModelOptions:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?jc({...i.providerDefaults.claude,modelOptions:{...i.providerDefaults.claude.modelOptions,...r}}):Rv({...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=>uC(BF(t(),n)),initializeComposerForChat:(n,r)=>e(i=>{if(i.chatStates[n])return i;const s=zF({defaultProvider:i.defaultProvider,providerDefaults:i.providerDefaults,sourceState:r==null?void 0:r.sourceState,legacyComposerState:i.legacyComposerState,providerHint:r==null?void 0:r.providerHint});return yye("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:jc(r).model,modelOptions:jc(r).modelOptions,planMode:r.planMode}:uC(r)}})),setChatComposerProvider:(n,r)=>e(i=>Av(i,n,()=>um(r,i.providerDefaults))),setChatComposerModel:(n,r)=>e(i=>Av(i,n,s=>s.provider==="claude"?{provider:"claude",model:jc({...s,model:r}).model,modelOptions:jc({...s,model:r}).modelOptions,planMode:s.planMode}:{provider:"codex",model:r,modelOptions:Rv({...s,model:r}).modelOptions,planMode:s.planMode})),setChatComposerModelOptions:(n,r)=>e(i=>Av(i,n,s=>s.provider==="claude"?{provider:"claude",model:s.model,modelOptions:jc({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode}:{provider:"codex",model:s.model,modelOptions:Rv({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode})),setChatComposerPlanMode:(n,r)=>e(i=>Av(i,n,s=>({...s,planMode:r}))),resetChatComposerFromProvider:(n,r)=>e(i=>({chatStates:{...i.chatStates,[n]:um(r,i.providerDefaults)}}))}),{name:"chat-preferences-state",version:1,partialize:e=>({chatStates:e.chatStates,legacyComposerState:e.legacyComposerState})})),dC=is()(Ch((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"})),A2=is()(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 _ye(e){return{autoResumeOnRateLimit:!!(e!=null&&e.autoResumeOnRateLimit)}}const hC=is()(Ch(e=>({autoResumeOnRateLimit:!1,setAutoResumeOnRateLimit:t=>e({autoResumeOnRateLimit:t})}),{name:"kanna-preferences",version:1,migrate:e=>_ye(e)}));function gd(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function jv(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function wye(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 oS(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 Sye(e,t){var r;const n=jv(t);switch(e.toolKind){case"ask_user_question":{const o=oS(n),a=o!==null?jv(o):n,c=gd(a),d=gd(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=oS(n),a=o!==null?jv(o):n,c=gd(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=oS(n),a=o?jv(o):n,c=gd(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=gd(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=wye(n);if(i.length>0)return{content:i.flatMap(o=>o.type==="text"?[o.text]:[]).join(""),blocks:i};const s=gd(n);return{content:typeof(s==null?void 0:s.content)=="string"?s.content:JSON.stringify(n,null,2)};default:return n}}function FF(e){return new Date(e).toISOString()}function Tr(e){return{id:e._id,messageId:e.messageId,timestamp:FF(e.createdAt),hidden:e.hidden}}function Cye(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:FF(e.createdAt)}}function kye(e){if(e.debugRaw)try{return JSON.parse(e.debugRaw).tool_use_result}catch{return}}function jo(e){return typeof e=="number"?e:void 0}function Mv(e){return typeof e=="string"?e:void 0}function Eye(e){if(!e||typeof e!="object")return;const t=e,n={readCount:jo(t.readCount),searchCount:jo(t.searchCount),bashCount:jo(t.bashCount),editFileCount:jo(t.editFileCount),linesAdded:jo(t.linesAdded),linesRemoved:jo(t.linesRemoved),otherToolCount:jo(t.otherToolCount)};return Object.values(n).some(r=>r!==void 0)?n:void 0}function Nye(e){if(!e.debugRaw)return;let t;try{t=JSON.parse(e.debugRaw).toolUseResult}catch{return}if(!t||typeof t!="object")return;const n=t,r={agentId:Mv(n.agentId),agentType:Mv(n.agentType),status:Mv(n.status),totalTokens:jo(n.totalTokens),totalDurationMs:jo(n.totalDurationMs),totalToolUseCount:jo(n.totalToolUseCount),toolStats:Eye(n.toolStats),content:Mv(n.content)};return r.agentId!==void 0||r.agentType!==void 0||r.totalTokens!==void 0||r.totalDurationMs!==void 0||r.status!==void 0?r:void 0}function j2(e){const t=new Map,n=[];for(const r of e)switch(r.kind){case"user_prompt":n.push({...Tr(r),kind:"user_prompt",content:r.content,attachments:r.attachments??[],steered:r.steered,autoContinue:r.autoContinue});break;case"system_init":n.push({...Tr(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({...Tr(r),kind:"account_info",accountInfo:r.accountInfo});break;case"assistant_text":n.push({...Tr(r),kind:"assistant_text",text:r.text});break;case"assistant_thinking":n.push({...Tr(r),kind:"assistant_thinking",text:r.text,signature:r.signature});break;case"api_error":n.push({...Tr(r),kind:"api_error",status:r.status,text:r.text,requestId:r.requestId});break;case"policy_refusal":n.push({...Tr(r),kind:"policy_refusal",text:r.text,requestId:r.requestId});break;case"tool_call":{const i=Cye(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"?kye(r)??r.content:r.content;i.normalized.toolKind==="subagent_task"?i.hydrated.result=Nye(r):i.hydrated.result=Sye(i.normalized,s),i.hydrated.rawResult=s,i.hydrated.isError=r.isError,r.persisted&&(i.hydrated.persisted=r.persisted)}break}case"result":n.push({...Tr(r),kind:"result",success:!r.isError,cancelled:r.subtype==="cancelled",result:r.result,durationMs:r.durationMs,costUsd:r.costUsd});break;case"status":n.push({...Tr(r),kind:"status",status:r.status});break;case"context_window_updated":n.push({...Tr(r),kind:"context_window_updated",usage:r.usage});break;case"compact_boundary":n.push({...Tr(r),kind:"compact_boundary"});break;case"compact_summary":n.push({...Tr(r),kind:"compact_summary",summary:r.summary});break;case"context_cleared":n.push({...Tr(r),kind:"context_cleared"});break;case"interrupted":n.push({...Tr(r),kind:"interrupted"});break;case"memory_loaded":n.push({...Tr(r),kind:"memory_loaded",path:r.path});break;case"auto_continue_prompt":n.push({...Tr(r),kind:"auto_continue_prompt",scheduleId:r.scheduleId});break;case"pending_tool_request":n.push({...Tr(r),kind:"pending_tool_request",toolRequestId:r.toolRequestId,toolName:r.toolName,arguments:r.arguments});break;case"tool_request_resolved":break;default:n.push({...Tr(r),kind:"unknown",json:JSON.stringify(r,null,2)});break}return n}const Tye=["AskUserQuestion","ExitPlanMode","TodoWrite"],Rye=new Set(["TodoWrite"]);function Aye(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 jye(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 Mye(e){const t={};for(const n of Tye)t[n]=Rye.has(n)?jye(e,n):Aye(e,n);return t}function Lye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}function Iye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}const M2="pushDeviceId";function $F(){return typeof localStorage>"u"?null:localStorage.getItem(M2)}function Dye(e){typeof localStorage>"u"||localStorage.setItem(M2,e)}function Pye(){typeof localStorage>"u"||localStorage.removeItem(M2)}function Oye(){return!(typeof window>"u"||typeof Notification>"u"||!("serviceWorker"in navigator)||typeof globalThis.PushManager>"u")}function zye(){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 fC(){if(!Oye())return{state:"unsupported"};if(!zye())return{state:"insecure-context"};switch(Notification.permission){case"granted":return{state:"granted"};case"denied":return{state:"denied"};default:return{state:"default"}}}function Bye(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 Fye(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 $ye(e){const t=fC();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:Bye(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:Fye(c),userAgent:c});return d}async function Hye(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 Uye=25e3,Vye=15e3,Wye=4e3,rD="kanna:profile-send-to-starting";function iD(){try{return window.sessionStorage.getItem(rD)==="1"||window.localStorage.getItem(rD)==="1"}catch{return!1}}class Gye{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=Pc();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=Pc(),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=Pc(),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=Pc();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=$F();t&&this.sendNow({v:1,type:"command",id:Pc(),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(iD()&&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}),iD()&&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(zZ,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>=Uye}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()},Wye),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()},Vye))}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 qye=[],L2=is()(e=>({byChat:{},setRuns:(t,n)=>e(r=>({byChat:{...r.byChat,[t]:n}}))}));function HF(e){return t=>t.byChat[e]??qye}function Kye(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 Yye(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&&Kye(e.sessionTokensByProvider,t.sessionTokensByProvider)}function Xye(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 Qye(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 Zye(e,t){return e===t?!0:!e||!t?!1:e.hasOlder===t.hasOlder&&e.olderCursor===t.olderCursor&&e.recentLimit===t.recentLimit}function Jye(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)&&e0e(e.attachments,t.attachments)}function e0e(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 t0e(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>Jye(n,t[r]))}function n0e(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 r0e(e,t){return!!(e&&e.status!=="unknown"&&t&&t.status==="unknown"&&t.files.length===0)}function i0e(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 s0e(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 o0e(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 a0e(e,t){return e===t?!0:!e||!t?!1:Yye(e.runtime,t.runtime)&&t0e(e.queuedMessages,t.queuedMessages)&&Xye(e.messages,t.messages)&&Zye(e.history,t.history)&&Qye(e.availableProviders,t.availableProviders)&&i0e(e.schedules,t.schedules)&&e.liveScheduleId===t.liveScheduleId&&s0e(e.tunnels,t.tunnels)&&e.liveTunnelId===t.liveTunnelId&&o0e(e.subagentRuns,t.subagentRuns)}function sD(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 l0e(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 oD="__new_chat__",UF="lever-theme",VF="chat-sound-preferences",WF="terminal-preferences",GF="chat-preferences";function aS(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 c0e(){if(typeof window>"u")return null;const e={},t=window.localStorage.getItem(UF);(t==="light"||t==="dark"||t==="system")&&(e.theme=t);const n=aS(VF);((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=aS(WF);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=aS(GF);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 u0e(){typeof window>"u"||(window.localStorage.removeItem(UF),window.localStorage.removeItem(VF),window.localStorage.removeItem(WF),window.localStorage.removeItem(GF))}function Lf(e){Mi.getState().setFromServer(e);const t=di.getState();t.setScrollbackLines(e.terminal.scrollbackLines),t.setMinColumnWidth(e.terminal.minColumnWidth),t.setEditorPreset(e.editor.preset),t.setEditorCommandTemplate(e.editor.commandTemplate);const n=Bc.getState();n.setChatSoundPreference(e.chatSoundPreference),n.setChatSoundId(e.chatSoundId),mi.getState().applyServerDefaults(e.defaultProvider,e.providerDefaults)}function d0e(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 I2(e,t=[]){return JSON.stringify({content:e,attachments:t.map(d0e)})}function h0e(e,t){return e.reduce((n,r)=>r.kind!=="user_prompt"?n:n+(I2(r.content,r.attachments??[])===t?1:0),0)}function f0e(e,t,n){const r=new Map;for(const i of n){if(i.kind!=="user_prompt")continue;const s=I2(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 m0e(e,t,n){return e.some(r=>r.id===t)?e.filter(r=>r.id!==t):e}const p0e=200,g0e=500;function aD(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 lD(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 v0e(e=document){return e.visibilityState==="visible"&&e.hasFocus()}function b0e(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`}function x0e(){const[e]=v.useState(()=>new Gye(b0e()));return v.useEffect(()=>(e.start(),()=>{e.dispose()}),[e]),e}const cD="kanna:profile-send-to-starting";function y0e(){try{return window.sessionStorage.getItem(cD)==="1"||window.localStorage.getItem(cD)==="1"}catch{return!1}}function qF(e){return Number((performance.now()-e).toFixed(1))}function Nl(e,t,n){!e||!y0e()||console.debug("[kanna/send->starting][client]",{traceId:e.traceId,stage:t,elapsedMs:qF(e.startedAt),serverChatId:e.serverChatId,routeChatIdAtSend:e.routeChatIdAtSend,...n})}function _0e(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 w0e(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 S0e(e,t){return e==="awaiting_disconnect"&&t==="disconnected"?"awaiting_server_ready":"none"}function C0e(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 k0e=30,D2="kanna:ui-update-restart",KF="kanna:last-update-reload-request";function E0e(e){return e+k0e}function N0e(e,t){return t>0?t:e}function lS(){return window.sessionStorage.getItem(D2)}function T0e(e){window.sessionStorage.setItem(D2,e)}function R0e(){window.sessionStorage.removeItem(D2)}function A0e(e,t){return e?String(e)!==t:!1}function j0e(){return window.sessionStorage.getItem(KF)}function M0e(e){window.sessionStorage.setItem(KF,String(e))}function L0e(){return"/auth/status"}async function I0e(e=fetch){return(await e(L0e(),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}})).ok}function D0e(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 P0e(e,t){return!e||!t?null:e.runtime.chatId!==t?(e.runtime.chatId,e.runtime.provider,null):e}function O0e(e){var Nu,uc,Ih;const t=du(),n=x0e(),r=up(),[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(()=>lS()),y=v.useCallback(Q=>{T0e(Q),b(Q)},[]),_=v.useCallback(()=>{R0e(),b(null)},[]),[w,C]=v.useState(null),[E,k]=v.useState([]),[T,R]=v.useState(!1),[A,j]=v.useState(null),[L,H]=v.useState(!1),[M,D]=v.useState({}),[z,O]=v.useState(null),[F,$]=v.useState(null),[B,U]=v.useState(null),[G,te]=v.useState(null),[P,Y]=v.useState("connecting"),[ee,V]=v.useState(!1),[ue,ge]=v.useState(!1),[Z,ne]=v.useState(!1),[ie,le]=v.useState(null),[oe,ke]=v.useState(!1),[Ee,Pe]=v.useState(!1),[Ze,ut]=v.useState(!1),[Mt,ye]=v.useState(null),[an,jt]=v.useState(null),[_t,ft]=v.useState(null),[Pt,It]=v.useState([]),[st,Ot]=v.useState(null),[he,Re]=v.useState(0),Ue=v.useRef(new Map),Je=dC(cx(Q=>Object.keys(Q.drafts).sort())),Ke=dC(cx(Q=>Object.keys(Q.attachmentDrafts).sort())),vt=v.useRef(0),St=v.useRef(null),ze=v.useRef({projectId:null,diffs:null}),Be=Ere(di(Q=>Q.editorPreset)),Oe=v.useMemo(()=>lD(i.projectGroups,o),[o,i.projectGroups]),Fe=v.useRef(Oe);v.useLayoutEffect(()=>{Fe.current=Oe});const bt=v.useMemo(()=>Oe===i.projectGroups?i:{...i,projectGroups:Oe},[i,Oe]);v.useEffect(()=>n.onStatus(Y),[n]),v.useEffect(()=>n.subscribe({type:"sidebar"},Q=>{s(Q),a(J=>J&&lD(Q.projectGroups,J)===Q.projectGroups?null:J),V(!0),ye(null)}),[n]),v.useEffect(()=>{if(P!=="connected")return;const Q=[...new Set([...Je,...Ke])].sort();n.command({type:"chat.setDraftProtection",chatIds:Q}).catch(J=>{ye(J instanceof Error?J.message:String(J))})},[Ke,P,Je,n]),v.useEffect(()=>n.subscribe({type:"local-projects"},Q=>{d(Q),ge(!0),ye(null)}),[n]),v.useEffect(()=>n.subscribe({type:"update"},Q=>{m(Q),ye(null)}),[n]),v.useEffect(()=>{P==="connected"&&n.command({type:"update.check",force:!0}).catch(Q=>{ye(Q instanceof Error?Q.message:String(Q))})},[P,n]),v.useEffect(()=>{const Q=f==null?void 0:f.reloadRequestedAt;A0e(Q,j0e())&&Q&&(M0e(Q),y("awaiting_disconnect"))},[y,f==null?void 0:f.reloadRequestedAt]),v.useEffect(()=>{const Q=lS();if(S0e(Q,P)==="awaiting_server_ready"){y("awaiting_server_ready");return}},[P,y]),v.useEffect(()=>{if(lS()!=="awaiting_server_ready")return;let Q=!1,J=null;const Le=async()=>{try{if(await I0e()){if(Q)return;_(),window.location.reload();return}}catch{}Q||(J=window.setTimeout(()=>{Le()},500))};return Le(),()=>{Q=!0,J!==null&&window.clearTimeout(J)}},[P,_]),v.useEffect(()=>{function Q(){f!=null&&f.lastCheckedAt&&(Date.now()-f.lastCheckedAt<=3600*1e3||n.command({type:"update.check"}).catch(J=>{ye(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=>{O(Q),ye(null)}),[n]),v.useEffect(()=>n.subscribe({type:"app-settings"},Q=>{$(Q),Lf(Q),ye(null)}),[n]),v.useEffect(()=>n.subscribe({type:"push-config"},Q=>{U(Q)}),[n]),v.useEffect(()=>n.subscribe({type:"pty-instances"},Q=>{Ta.getState().applySnapshot(Q.instances)},Q=>{Q.type==="pty-instances.added"?Ta.getState().applyDiff({op:"added",instance:Q.instance}):Q.type==="pty-instances.updated"?Ta.getState().applyDiff({op:"updated",instance:Q.instance}):Ta.getState().applyDiff({op:"removed",chatId:Q.chatId})}),[n]);const wt=v.useCallback(async()=>{try{Mi.getState().setHydrationStatus("loading");const Q=await n.command({type:"settings.readAppSettings"});$(Q),Lf(Q),ye(null)}catch(Q){Mi.getState().setHydrationStatus("error"),ye(Q instanceof Error?Q.message:String(Q))}},[n]),fn=v.useCallback(async(Q,J)=>{try{await n.command({type:"chat.setPolicyOverride",chatId:Q,policyOverride:J}),ye(null)}catch(Le){throw ye(Le instanceof Error?Le.message:String(Le)),Le}},[n]),Xt=v.useCallback(async Q=>{try{Mi.getState().applyOptimisticPatch(Q);const J=await n.command({type:"settings.writeAppSettingsPatch",patch:Q});$(J),Lf(J),ye(null)}catch(J){throw ye(J instanceof Error?J.message:String(J)),await wt(),J}},[wt,n]),Qt=v.useCallback(async Q=>{try{await n.command({type:"settings.testMcpServer",id:Q}),ye(null)}catch(J){throw ye(J instanceof Error?J.message:String(J)),J}},[n]),Rt=v.useCallback(async Q=>{try{Mi.getState().applyOptimisticPatch({cloudflareTunnel:Q});const J=await n.command({type:"appSettings.setCloudflareTunnel",patch:Q});$(J),Lf(J),ye(null)}catch(J){throw ye(J instanceof Error?J.message:String(J)),await wt(),J}},[wt,n]),xt=v.useCallback(async Q=>{try{Mi.getState().applyOptimisticPatch({claudeAuth:Q});const J=await n.command({type:"appSettings.setClaudeAuth",patch:Q});$(J),Lf(J),ye(null)}catch(J){throw ye(J instanceof Error?J.message:String(J)),await wt(),J}},[wt,n]),mt=v.useCallback(async Q=>await n.command({type:"appSettings.testOAuthToken",token:Q}),[n]),kt=v.useCallback(async()=>{try{const Q=await n.command({type:"settings.readLlmProvider"});te(Q),ye(null)}catch(Q){ye(Q instanceof Error?Q.message:String(Q))}},[n]),pt=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),ye(null)}catch(J){throw ye(J instanceof Error?J.message:String(J)),J}},[n]),$t=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(()=>{P==="connected"&&wt()},[P,wt]),v.useEffect(()=>{if(P!=="connected"||(F==null?void 0:F.browserSettingsMigrated)!==!1)return;const Q=c0e();Q&&Xt(Q).then(u0e).catch(()=>{})},[F==null?void 0:F.browserSettingsMigrated,P,Xt]),v.useEffect(()=>{P==="connected"&&kt()},[P,kt]),v.useEffect(()=>{function Q(){Re(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}++vt.current,Fe.current.length,Fe.current.reduce((J,Le)=>J+Le.chats.length,0),C(null),ne(!1);const Q=n.subscribe({type:"chat",chatId:e,recentLimit:p0e},J=>{if(J!=null&&J.runtime.chatId){const Le=[...Ue.current.values()].filter(ot=>ot.serverChatId===J.runtime.chatId).sort((ot,An)=>An.startedAt-ot.startedAt)[0];Le&&Le.snapshotAt===void 0&&(Le.snapshotAt=performance.now(),Nl(Le,"chat_snapshot_received",{status:J.runtime.status,messageCount:J.messages.length}))}if(C(Le=>{const ot=a0e(Le,J);return J==null||J.runtime.chatId,J==null||J.runtime.provider,J==null||J.runtime.status,J==null||J.messages.length,ot?Le:J}),j((J==null?void 0:J.history.olderCursor)??null),H((J==null?void 0:J.history.hasOlder)??!1),ne(!0),ye(null),J){const Le=A2.getState();Le.setForChat(J.runtime.chatId,J.slashCommands??[]),Le.setLoadingForChat(J.runtime.chatId,J.slashCommandsLoading??!1)}});return()=>{Fe.current.length,Fe.current.reduce((J,Le)=>J+Le.chats.length,0),Q()}},[e,n]),v.useEffect(()=>{if(e)return n.subscribe({type:"workflows",chatId:e},Q=>{L2.getState().setRuns(Q.chatId,Q.runs)})},[e,n]),v.useEffect(()=>{if(ie)return;const Q=Oe[0];Q&&le(Q.groupKey)},[ie,Oe]),v.useEffect(()=>{if(!e||!ee||!Z)return;if(Oe.some(J=>J.chats.some(Le=>Le.chatId===e))){_t===e&&ft(null);return}_t!==e&&t("/")},[e,Z,t,_t,Oe,ee]),v.useEffect(()=>{w&&(le(w.runtime.projectId),_t===w.runtime.chatId&&ft(null))},[w,_t]),v.useEffect(()=>{if(!e||!ee||!v0e())return;const Q=Oe.flatMap(J=>J.chats).find(J=>J.chatId===e);Q!=null&&Q.unread&&n.command({type:"chat.markRead",chatId:e}).catch(J=>{ye(J instanceof Error?J.message:String(J))})},[e,he,Oe,ee,n]),v.useEffect(()=>{k([]),R(!1),j(null),H(!1)},[e]);const nt=v.useMemo(()=>P0e(w,e),[e,w]),we=v.useMemo(()=>(nt==null?void 0:nt.runtime.projectId)??w0e(Oe,e)??ie,[e,nt==null?void 0:nt.runtime.projectId,ie,Oe]),tt=v.useMemo(()=>{const Q=we?M[we]??null:null;return we&&Q?(ze.current={projectId:we,diffs:Q},Q):we&&ze.current.projectId===we?ze.current.diffs:Q},[we,M]);v.useEffect(()=>we?n.subscribe({type:"project-git",projectId:we},J=>{D(Le=>{const ot=J??null;return r0e(Le[we]??null,ot)||n0e(Le[we]??null,ot)?Le:{...Le,[we]:ot}}),ye(null)}):void 0,[we,n]),v.useEffect(()=>{w==null||w.runtime.chatId,w==null||w.runtime.provider,nt==null||nt.runtime.chatId,nt==null||nt.runtime.provider},[e,nt,w,_t]);const qe=v.useMemo(()=>sD(E,(nt==null?void 0:nt.messages)??[]),[nt==null?void 0:nt.messages,E]),Xe=e??oD,_e=v.useMemo(()=>Pt.filter(Q=>Q.scopeId===Xe).map(Q=>Q.entry),[Xe,Pt]),De=v.useMemo(()=>[...qe,..._e],[_e,qe]),Ve=v.useMemo(()=>j2(De),[De]),We=v.useMemo(()=>l0e(Ve),[Ve]),Ut=v.useMemo(()=>Mye(Ve),[Ve]),$e=(nt==null?void 0:nt.runtime)??null,Ht=(nt==null?void 0:nt.queuedMessages)??[],_n=((st==null?void 0:st.scopeId)===Xe&&(!$e||$e.status==="idle")?"starting":null)??($e==null?void 0:$e.status)??null,kr=(nt==null?void 0:nt.availableProviders)??tm,Cn=Iye(_n??void 0),Bn=Lye(_n??void 0),Er=($e==null?void 0:$e.isDraining)??!1,q=((Nu=c==null?void 0:c.projects[0])==null?void 0:Nu.localPath)??null,be=($e==null?void 0:$e.localPath)??q??((uc=Oe[0])==null?void 0:uc.localPath),je=!!(ie??($e==null?void 0:$e.projectId)??((Ih=Oe[0])==null?void 0:Ih.groupKey)??q);v.useEffect(()=>{(st==null?void 0:st.scopeId)===Xe&&$e!=null&&$e.status&&$e.status!=="idle"&&Ot(null)},[st,Xe,$e==null?void 0:$e.status]),v.useEffect(()=>{if(!(st!=null&&st.ackedAt)||st.scopeId!==Xe||$e!=null&&$e.status&&$e.status!=="idle")return;const Q=window.setTimeout(()=>{Ot(J=>(J==null?void 0:J.scopeId)===Xe&&J.ackedAt===st.ackedAt?null:J)},300);return()=>window.clearTimeout(Q)},[st,Xe,$e==null?void 0:$e.status]),v.useEffect(()=>{if(!e||($e==null?void 0:$e.status)!=="starting")return;const Q=[...Ue.current.values()].filter(J=>J.serverChatId===e).sort((J,Le)=>Le.startedAt-J.startedAt)[0];!Q||Q.startingStatusAt!==void 0||(Q.startingStatusAt=performance.now(),Nl(Q,"runtime_status_starting",{status:$e.status}))},[e,$e==null?void 0:$e.status]),v.useEffect(()=>{if(!e||!$e||$e.status==="starting")return;const Q=[...Ue.current.values()].filter(J=>J.serverChatId===e).sort((J,Le)=>Le.startedAt-J.startedAt)[0];!Q||Q.startingRenderedAt!==void 0||(Nl(Q,"starting_not_observed",{status:$e.status}),Ue.current.delete(Q.traceId))},[e,$e]),v.useLayoutEffect(()=>{if(!e||($e==null?void 0:$e.status)!=="starting"){St.current=null;return}const Q=[...Ue.current.values()].filter(J=>J.serverChatId===e).sort((J,Le)=>Le.startedAt-J.startedAt)[0];Q&&St.current!==Q.traceId&&(St.current=Q.traceId,Q.startingRenderedAt=performance.now(),Nl(Q,"starting_render_committed",{totalMs:qF(Q.startedAt)}),Ue.current.delete(Q.traceId))},[e,$e==null?void 0:$e.status]),v.useEffect(()=>{It(Q=>{const J=f0e(Q,Xe,qe);return J.length===Q.length&&J.every((Le,ot)=>Le===Q[ot])?Q:J})},[Xe,qe]);const Qe=v.useCallback(async()=>{if(!(!e||!A||T||!L)){R(!0);try{const Q=await n.command({type:"chat.loadHistory",chatId:e,beforeCursor:A,limit:g0e});k(J=>sD(Q.messages,J)),j(Q.olderCursor),H(Q.hasOlder),ye(null)}catch(Q){const J=Q instanceof Error?Q.message:String(Q);ye(J)}finally{R(!1)}}},[e,L,A,T,n]),dt=v.useCallback(async Q=>{const J=mi.getState(),Le=e?J.getComposerState(e):J.getComposerState(cm),ot=await n.command({type:"chat.create",projectId:Q});J.initializeComposerForChat(ot.chatId,{sourceState:Le}),le(Q),ft(ot.chatId),t(`/chat/${ot.chatId}`),ke(!1),ye(null)},[e,t,n]),Ye=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]),it=v.useCallback(async Q=>{try{const J=Q.kind==="project_id"?null:Q.kind==="local_path"?Q.localPath:Q.project.localPath;J&&jt(J);const{projectId:Le}=await Ye(Q);await dt(Le)}catch(J){ye(J instanceof Error?J.message:String(J))}finally{jt(null)}},[dt,Ye]),cn=v.useCallback(async Q=>{await it({kind:"project_id",projectId:Q})},[it]),Wn=v.useCallback(async Q=>{try{const J=await n.command({type:"chat.fork",chatId:Q.chatId}),Le=mi.getState();Le.initializeComposerForChat(J.chatId,{sourceState:Le.getComposerState(Q.chatId)}),ft(J.chatId),t(`/chat/${J.chatId}`),ke(!1),ye(null)}catch(J){ye(J instanceof Error?J.message:String(J))}},[t,n]),or=v.useCallback(async Q=>{await it({kind:"local_path",localPath:Q})},[it]),ai=v.useCallback(async Q=>{await it({kind:"project_request",project:Q})},[it]),ss=v.useCallback(async Q=>{try{await n.command({type:"update.check",force:Q==null?void 0:Q.force}),ye(null)}catch(J){ye(J instanceof Error?J.message:String(J))}},[n]),qr=v.useCallback(async Q=>{y("awaiting_disconnect");try{const J=await n.command({type:"update.install",version:Q});if(!J.ok){_(),ye(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}ye(null)}catch(J){_(),ye(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){_(),ye(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}ye(null)}catch(Q){_(),ye(Q instanceof Error?Q.message:String(Q))}},[_,r,y,n]),Fi=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}`);ye(null),window.location.reload()}catch(Q){ye(Q instanceof Error?Q.message:String(Q))}},[]),Et=v.useCallback(async(Q,J)=>{var Tu;const Le=(J==null?void 0:J.attachments)??[],ot=Pc(),An=Pc(),Xr=I2(Q,Le),zs=e??oD;Ot({scopeId:zs,ackedAt:null});const Bs={traceId:An,optimisticId:ot,startedAt:performance.now(),serverChatId:e,routeChatIdAtSend:e,contentPreview:Q.slice(0,80)};Ue.current.set(An,Bs),Nl(Bs,"handle_send_called",{optimisticScopeId:zs,attachments:Le.length,contentLength:Q.length,contentPreview:Bs.contentPreview});const Dh=h0e(qe,Xr)+Pt.filter(Fn=>Fn.scopeId===zs&&Fn.signature===Xr).length+1;It(Fn=>[...Fn,{id:ot,scopeId:zs,signature:Xr,requiredMatchCount:Dh,entry:{_id:`optimistic:${ot}`,kind:"user_prompt",content:Q,attachments:Le,createdAt:Date.now()}}]),Nl(Bs,"optimistic_prompt_added",{optimisticId:ot,optimisticScopeId:zs});try{let Fn=ie??((Tu=Oe[0])==null?void 0:Tu.groupKey)??null;if(!e&&!Fn&&q&&(Fn=(await n.command({type:"project.open",localPath:q})).projectId,le(Fn)),!e&&!Fn)throw new Error("Open a project first");const el=hC.getState().autoResumeOnRateLimit,Qr=await n.command({type:"chat.send",chatId:e??void 0,projectId:e?void 0:Fn??void 0,clientTraceId:An,provider:J==null?void 0:J.provider,content:Q,attachments:Le,model:J==null?void 0:J.model,modelOptions:J==null?void 0:J.modelOptions,planMode:J==null?void 0:J.planMode,autoResumeOnRateLimit:el});if(Bs.ackAt=performance.now(),Bs.serverChatId=Qr.chatId??Bs.serverChatId,Qr.queued?(It(Fs=>m0e(Fs,ot,{queued:!0})),Ot(null)):Ot(Fs=>Fs&&{scopeId:!e&&Qr.chatId?Qr.chatId:Fs.scopeId,ackedAt:performance.now()}),Nl(Bs,"chat_send_ack_received",{resultChatId:Qr.chatId??null,queued:Qr.queued??!1}),!e&&Qr.chatId){It(Dp=>Dp.map(Ph=>Ph.id===ot?{...Ph,scopeId:Qr.chatId}:Ph));const Fs=mi.getState();Fs.setComposerState(Qr.chatId,_0e(J)??Fs.getComposerState(cm)),ft(Qr.chatId),t(`/chat/${Qr.chatId}`)}ye(null)}catch(Fn){throw It(el=>el.filter(Qr=>Qr.id!==ot)),Ot(null),Nl(Bs,"handle_send_failed",{error:Fn instanceof Error?Fn.message:String(Fn)}),Ue.current.delete(An),ye(Fn instanceof Error?Fn.message:String(Fn)),Fn}},[e,q,t,Pt,ie,qe,Oe,n]),nn=v.useCallback(async Q=>{if(e)try{await n.command({type:"message.steer",chatId:e,queuedMessageId:Q}),ye(null)}catch(J){ye(J instanceof Error?J.message:String(J))}},[e,n]),mn=v.useCallback(async Q=>{if(e)try{await n.command({type:"message.dequeue",chatId:e,queuedMessageId:Q}),ye(null)}catch(J){ye(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){ye(Q instanceof Error?Q.message:String(Q))}},[e,n]),Kr=v.useCallback(async()=>{if(e)try{await n.command({type:"chat.stopDraining",chatId:e})}catch(Q){ye(Q instanceof Error?Q.message:String(Q))}},[e,n]),Qa=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}),ye(null)}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[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 Le=aD(Oe,Q.chatId);t(Le?`/chat/${Le}`:"/")}}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[e,r,t,Oe,n]),Yo=v.useCallback(async Q=>{try{if(await n.command({type:"chat.archive",chatId:Q.chatId}),Q.chatId===e){const J=aD(Oe,Q.chatId);t(J?`/chat/${J}`:"/")}ye(null)}catch(J){ye(J instanceof Error?J.message:String(J))}},[e,t,Oe,n]),Ds=v.useCallback(async Q=>{try{ft(Q),await n.command({type:"chat.unarchive",chatId:Q}),t(`/chat/${Q}`),ye(null)}catch(J){ft(null),ye(J instanceof Error?J.message:String(J))}},[t,n]),Za=v.useCallback(async Q=>{try{await n.command({type:"project.remove",projectId:Q}),Il.getState().clearProject(Q),Ai.getState().clearProject(Q),($e==null?void 0:$e.projectId)===Q&&t("/"),ye(null)}catch(J){ye(J instanceof Error?J.message:String(J))}},[t,$e,n]),er=v.useCallback(async(Q,J)=>{try{await n.command({type:"project.setStar",projectId:Q,starred:J}),ye(null)}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[n]),po=v.useCallback(async Q=>{a(Q);try{await n.command({type:"sidebar.reorderProjectGroups",projectIds:Q}),ye(null)}catch(J){a(null),ye(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}),ye(null)}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[n]),vo=v.useCallback(async(Q,J)=>{try{await n.command({type:"stack.rename",stackId:Q,title:J}),ye(null)}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[n]),_i=v.useCallback(async Q=>{try{await n.command({type:"stack.remove",stackId:Q}),ye(null)}catch(J){ye(J instanceof Error?J.message:String(J))}},[n]),Xo=v.useCallback(async(Q,J)=>{try{await n.command({type:"stack.addProject",stackId:Q,projectId:J}),ye(null)}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[n]),Qo=v.useCallback(async(Q,J)=>{try{await n.command({type:"stack.removeProject",stackId:Q,projectId:J}),ye(null)}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[n]),wi=v.useCallback(async(Q,J,Le)=>{try{const ot=mi.getState(),An=e?ot.getComposerState(e):ot.getComposerState(cm),Xr=await n.command({type:"chat.create",projectId:Q,stackId:J,stackBindings:Le});ot.initializeComposerForChat(Xr.chatId,{sourceState:An}),le(Q),ft(Xr.chatId),t(`/chat/${Xr.chatId}`),ke(!1),ye(null)}catch(ot){ye(ot instanceof Error?ot.message:String(ot))}},[e,t,n]),Zo=v.useCallback(async Q=>{try{const J=await n.command({type:"stack.listWorktrees",projectId:Q});return ye(null),J.worktrees}catch(J){return ye(J instanceof Error?J.message:String(J)),[]}},[n]),bo=v.useCallback(async()=>await n.command({type:"sessions.importClaude"}),[n]),Se=v.useCallback(async Q=>{const J=di.getState();ye(null),await n.command({type:"system.openExternal",...Q,editor:Q.action==="open_editor"?Q.editor??{preset:J.editorPreset,commandTemplate:J.editorCommandTemplate}:void 0})},[n]),W=v.useCallback(async(Q,J)=>{var ot,An;const Le=($e==null?void 0:$e.localPath)??((ot=c==null?void 0:c.projects[0])==null?void 0:ot.localPath)??((An=Oe[0])==null?void 0:An.localPath);if(Le)try{await Se({action:Q,localPath:Le,editor:J})}catch(Xr){ye(Xr instanceof Error?Xr.message:String(Xr))}},[c==null?void 0:c.projects,Se,$e==null?void 0:$e.localPath,Oe]),xe=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),ye(null)}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[]),Wt=v.useCallback(async(Q,J="open_editor",Le)=>{try{await Se({action:J,localPath:Q.path,line:Q.line,column:Q.column,editor:Le})}catch(ot){ye(ot instanceof Error?ot.message:String(ot))}},[Se]),ar=v.useCallback(async(Q,J)=>{try{await Se({action:Q,localPath:J})}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[Se]),Yr=v.useCallback(()=>{var J;const Q=D0e({selectedProjectId:ie,sidebarProjectId:(J=Oe[0])==null?void 0:J.groupKey,fallbackLocalProjectPath:q});if(Q){it(Q);return}t("/")},[q,t,ie,Oe,it]),Jo=v.useCallback(()=>ke(!0),[]),ac=v.useCallback(()=>ke(!1),[]),xo=v.useCallback(()=>Pe(!0),[]),Ja=v.useCallback(()=>Pe(!1),[]),Lp=v.useCallback(()=>ut(!0),[]),Mh=v.useCallback(()=>ut(!1),[]),Ip=v.useCallback(async(Q,J,Le)=>{if(e)try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Q,result:{questions:J,answers:Le}})}catch(ot){ye(ot instanceof Error?ot.message:String(ot))}},[e,n]),lc=v.useCallback(async(Q,J,Le,ot)=>{if(e){J&&mi.getState().setChatComposerPlanMode(e,!1);try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Q,result:{confirmed:J,...Le?{clearContext:!0}:{},...ot?{message:ot}:{}}})}catch(An){ye(An instanceof Error?An.message:String(An))}}},[e,n]),Ps=v.useCallback(async(Q,J,Le,ot)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Q,toolUseId:J,result:{questions:Le,answers:ot}})}catch(An){ye(An instanceof Error?An.message:String(An))}},[e,n]),Lh=v.useCallback(async(Q,J,Le)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Q,toolUseId:J,result:Le})}catch(ot){ye(ot instanceof Error?ot.message:String(ot))}},[e,n]),cc=v.useCallback(async(Q,J)=>{if(e)try{await n.command({type:"chat.toolRequestAnswer",chatId:e,toolRequestId:Q,decision:J})}catch(Le){ye(Le instanceof Error?Le.message:String(Le))}},[e,n]),Os=C0e(g,f==null?void 0:f.status);return{socket:n,activeChatId:e,activeProjectId:we,sidebarData:bt,localProjects:c,updateSnapshot:f,chatSnapshot:w,chatDiffSnapshot:tt,keybindings:z,appSettings:F,pushConfig:B,llmProvider:G,connectionStatus:P,sidebarReady:ee,uiRestartActive:Os.active,uiRestartLabel:Os.label,localProjectsReady:ue,commandError:Mt,startingLocalPath:an,sidebarOpen:oe,sidebarCollapsed:Ee,messages:Ve,queuedMessages:Ht,previousPrompt:We,latestToolIds:Ut,runtime:$e,runtimeStatus:_n,isHistoryLoading:T,hasOlderHistory:L,availableProviders:kr,isProcessing:Cn,canCancel:Bn,isDraining:Er,navbarLocalPath:be,editorLabel:Be,hasSelectedProject:je,addProjectModalOpen:Ze,openSidebar:Jo,closeSidebar:ac,collapseSidebar:xo,expandSidebar:Ja,openAddProjectModal:Lp,closeAddProjectModal:Mh,loadOlderHistory:Qe,handleCreateChat:cn,handleForkChat:Wn,handleOpenLocalProject:or,handleCreateProject:ai,handleCheckForUpdates:ss,handleInstallUpdate:qr,handleForceReload:fo,handleReadAppSettings:wt,handleWriteAppSettings:Xt,handleTestMcpServer:Qt,handleSetChatPolicyOverride:fn,handleWriteCloudflareTunnel:Rt,handleWriteClaudeAuth:xt,handleTestOAuthToken:mt,handleReadLlmProvider:kt,handleWriteLlmProvider:pt,handleValidateLlmProvider:$t,handleSignOut:Fi,handleSend:Et,handleSteerQueuedMessage:nn,handleRemoveQueuedMessage:mn,handleCancel:pn,handleStopDraining:Kr,handleRenameChat:Qa,handleArchiveChat:Yo,handleOpenArchivedChat:Ds,handleDeleteChat:mo,handleHideProject:Za,handleToggleProjectStar:er,handleReorderProjectGroups:po,stacks:bt.stacks,handleCreateStack:go,handleRenameStack:vo,handleRemoveStack:_i,handleAddProjectToStack:Xo,handleRemoveProjectFromStack:Qo,handleCreateStackChat:wi,handleListStackWorktrees:Zo,importClaudeSessions:bo,handleCopyPath:xe,handleOpenExternal:W,handleOpenExternalPath:ar,handleOpenLocalLink:Wt,handleCompose:Yr,handleAskUserQuestion:Ip,handleExitPlanMode:lc,handleSubagentAskUserQuestion:Ps,handleSubagentExitPlanMode:Lh,handleToolRequestAnswer:cc}}const uD=/<thinking>([\s\S]*?)<\/thinking>/gi;function z0e(e){const t=[];let n=0;uD.lastIndex=0;let r;for(;(r=uD.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 B0e(t)}function B0e(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 P2=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(Qv,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"font-medium uppercase tracking-wider",children:"Thinking"}),u.jsx(Ts,{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(Wo,{remarkPlugins:Fa,components:$a,children:i})})]})}),YF=v.memo(function({message:t}){const n=v.useMemo(()=>z0e(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(P2,{content:r.content},i):u.jsx(Wo,{remarkPlugins:Fa,components:$a,children:r.content},i))})}),XF=v.memo(function({message:t}){return u.jsx("div",{className:"px-0.5 w-full max-w-[70ch]",children:u.jsx(P2,{content:t.text})})}),Np=({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 F0e(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 $0e(e){return e.replace(/<[^>]+>/g,"")}function H0e(e,t){const n=e.split(`
2637
2637
  `),r=t.split(`
2638
2638
  `),i=U0e(n,r),s=V0e(n,r,i);return W0e(s)}function U0e(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 V0e(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 W0e(e){return e.map(t=>{const n=t.type==="removed"?"-":t.type==="added"?"+":" ";return{type:t.type,content:`${n}${t.text}`}})}function Lv({content:e,isDiff:t=!1,oldString:n,newString:r}){const i=v.useMemo(()=>t&&n!==void 0&&r!==void 0?H0e(n,r):[],[t,n,r]),s=v.useMemo(()=>t?[]:F0e(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:$0e(a.content)})]},c))})})})})}function G0e(e){switch(e){case"running":return"active";case"failed":return"destructive";case"killed":return"warning";case"completed":case"unknown":default:return"muted"}}function q0e(e){switch(e){case"running":return"Running";case"completed":return"Completed";case"failed":return"Failed";case"killed":return"Killed";case"unknown":return"Unknown"}}function K0e(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 Y0e(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 X0e({status:e}){const t=G0e(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",K0e(t))}),u.jsx("span",{className:Y0e(t),children:q0e(e)})]})}function Q0e(){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 Z0e({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(Na,{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(X0e,{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(Q0e,{})]})]})}const QF=v.createContext(null);function J0e({children:e,value:t}){return u.jsx(QF.Provider,{value:t,children:e})}function e_e(){return v.useContext(QF)}function t_e(e,t){return t||e==="failed"||e==="error"?"destructive":e==="in_progress"||e==="running"?"active":"muted"}function n_e(e){switch(e){case"active":return"bg-emerald-500 dark:bg-emerald-400";case"destructive":return"bg-destructive";case"muted":default:return"bg-muted-foreground"}}function r_e(e){switch(e){case"active":return"text-emerald-500 dark:text-emerald-400";case"destructive":return"text-destructive";case"muted":default:return"text-muted-foreground"}}function i_e(e){if(!e)return"";const t=[],n=(r,i,s)=>{r&&r>0&&t.push(`${r} ${r===1?i:s}`)};return n(e.readCount,"read","reads"),n(e.editFileCount,"edit","edits"),n(e.bashCount,"cmd","cmds"),n(e.searchCount,"search","searches"),n(e.otherToolCount,"tool","tools"),t.join(" · ")}function s_e({subagentType:e,result:t,isError:n,localPath:r}){const i=e||"Agent",s=t_e(t==null?void 0:t.status,n),o=i_e(t==null?void 0:t.toolStats),a=e_e(),c=t==null?void 0:t.agentId,d=!!(a&&c),[f,m]=v.useState(!1),[g,b]=v.useState(!1),[y,_]=v.useState(!1),[w,C]=v.useState([]),[E,k]=v.useState(null),T=v.useCallback(()=>{if(!a||!c)return;const A=!f;m(A),A&&!y&&!g&&(b(!0),k(null),a(c).then(j=>{C(j2(j)),_(!0)}).catch(j=>k(j instanceof Error?j.message:"Failed to load subagent transcript")).finally(()=>b(!1)))},[a,c,f,y,g]),R=u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d?u.jsx(Ts,{className:de("size-4 text-muted-icon shrink-0 transition-transform",f&&"rotate-90"),"aria-hidden":!0}):u.jsx(Ax,{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:i}),(t==null?void 0:t.status)&&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",n_e(s))}),u.jsx("span",{className:r_e(s),children:t.status})]}),(t==null?void 0:t.totalTokens)!=null&&t.totalTokens>0&&u.jsxs("span",{className:"inline-flex items-center gap-0.5 text-xs text-muted-foreground tabular-nums",children:[u.jsx(Hd,{className:"size-3","aria-hidden":!0}),Li(t.totalTokens)," tokens"]}),(t==null?void 0:t.totalDurationMs)!=null&&t.totalDurationMs>0&&u.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:Ys(t.totalDurationMs)}),o&&u.jsx("span",{className:"text-xs text-muted-foreground tabular-nums truncate",children:o}),g&&u.jsx(bn,{className:"size-3 animate-spin text-muted-foreground","aria-label":"Loading"})]})]});return d?u.jsxs("div",{className:"min-w-0",children:[u.jsx("button",{type:"button",onClick:T,"aria-expanded":f,className:"w-full text-left cursor-pointer",children:R}),f&&u.jsxs("div",{className:"mt-2 ml-2 border-l-2 border-muted-foreground/20 pl-3 space-y-2",children:[E&&u.jsx("div",{className:"text-xs text-destructive",children:E}),!E&&y&&w.length===0&&u.jsx("div",{className:"text-xs text-muted-foreground",children:"No subagent activity recorded."}),w.map(A=>u.jsx(e$,{message:A,localPath:r??""},A.id))]})]}):R}function dD(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 o_e({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 ux({message:e,isLoading:t=!1,localPath:n,chatId:r=""}){var E;const i=e.result!==void 0,s=!i&&t,o=L2(cx(HF(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?U3(e.input.command):"Bash"):e.toolKind==="web_search"?e.input.query||"Web Search":e.toolKind==="read_file"?`Read ${Ul(e.input.filePath,n)}`:e.toolKind==="write_file"?`Write ${Ul(e.input.filePath,n)}`:e.toolKind==="edit_file"?`Edit ${Ul(e.input.filePath,n)}`:e.toolKind==="delete_file"?`Delete ${Ul(e.input.filePath,n)}`:e.toolKind==="mcp_generic"?`${t1(e.input.tool)} from ${t1(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=dD(k);if(T.length>0)return T}}return dD(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(qa,{className:"w-full",children:u.jsx(p2,{expandedContent:u.jsx(_y,{className:"my-4 text-sm",children:u.jsxs("div",{className:"flex flex-col gap-2",children:[g?u.jsx(Lv,{content:"",isDiff:!0,oldString:e.input.oldString,newString:e.input.newString}):b?u.jsx(Lv,{content:e.input.content}):!y&&!m&&u.jsx(oC,{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(o_e,{images:w})})]}):u.jsx(Lv,{content:_})),m&&!e.isError&&u.jsx(Lv,{content:e.input.content}),i&&!y&&!(m&&!e.isError)&&!(g&&!e.isError)&&!(b&&!e.isError)&&u.jsx(oC,{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(Z0e,{name:e.input.name,description:e.input.description,run:R})})():e.toolKind==="subagent_task"&&e.result?u.jsx(s_e,{subagentType:e.input.subagentType,result:e.result,isError:e.isError,localPath:n}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:e.isError?u.jsx(Ls,{className:"size-4 text-destructive"}):c?u.jsx(Ax,{className:"size-4 text-muted-icon"}):e.toolKind==="workflow"?u.jsx(Na,{className:"size-4 text-muted-icon"}):u.jsx(dF,{icon:uF(e.toolName),className:"size-4 text-muted-icon"})}),u.jsx(ru,{className:"text-left transition-opacity duration-200 truncate",children:u.jsx(Np,{animate:s,shimmerWidth:Math.max(20,(((E=d||a)==null?void 0:E.length)??33)*3),children:d||a})})]})})})}function a_e(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 hD({durationMs:e,prefix:t="Worked for"}){return e<=0?null:u.jsxs(Wbe,{children:[t," ",a_e(e)]})}const cS=/\[([^\]]+)\]\(\/chat\/([0-9a-fA-F][0-9a-fA-F-]{7,})\)/g;function ZF(e,t){const n=[];let r=0,i=0;cS.lastIndex=0;for(let s=cS.exec(e);s!==null;s=cS.exec(e))s.index>r&&n.push(e.slice(r,s.index)),n.push(u.jsx(pk,{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 JF({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:ZF(t)}),e.durationMs>0?u.jsx(hD,{durationMs:e.durationMs,prefix:"Failed after"}):null]})}return u.jsx(hD,{durationMs:e.durationMs})}function l_e(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}function c_e(e){return typeof e=="string"?e:JSON.stringify(e,null,2)}function u_e(e){return e.replace(/<persisted-output>\n?/g,"").replace(/\n?<\/persisted-output>/g,"")}function e$({message:e,localPath:t,isRunning:n=!1}){if(e.kind==="tool"&&e.persisted){const i=u_e(c_e(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 (",l_e(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:s2(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(YF,{message:e});break;case"assistant_thinking":r=u.jsx(XF,{message:e});break;case"tool":r=u.jsx(ux,{message:e,isLoading:n,localPath:t});break;case"result":r=u.jsx(JF,{message:e});break;default:return null}return u.jsx("div",{className:"animate-in fade-in-0 duration-200",children:r})}function d_e(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 h_e({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(gm,{className:"h-4 w-4"}),u.jsx("span",{children:d_e(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(MG,{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(Cq,{className:"h-3 w-3"})," Retry"]})]})]})}function f_e({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(bW,{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 fD({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 t$({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(ts,{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 m_e({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(fD,{label:e.label,description:e.description})}),u.jsx(t$,{selected:t,multiSelect:n})]})}):u.jsx("div",{className:de(s,o),children:u.jsx(fD,{label:e.label,description:e.description})})}function n$({questions:e,onSubmit:t,onCancel:n}){var H;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(),O=s[M]||"",F=D||e.find(U=>d(U)===M);if(F!=null&&F.multiSelect)return[O,z].filter(Boolean).flatMap(U=>U.split(", ").filter(Boolean));const $=z||O;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 O=s[z]?s[z].split(", ").filter(Boolean):[],F=O.includes(D)?O.filter($=>$!==D):[...O,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),L=a[d(w)]||"";return u.jsxs("div",{className:"w-full space-y-3",children:[u.jsxs(f_e,{question:w.question,header:w.header,currentIndex:r,totalQuestions:e.length,onBack:r>0?T:void 0,children:[(H=w.options)==null?void 0:H.map(M=>u.jsx(m_e,{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:L,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(t$,{selected:!!L,multiSelect:w.multiSelect,onClick:w.multiSelect&&L?()=>y(w):void 0})]})})]}),u.jsxs("div",{className:"flex items-center mx-2",children:[n?u.jsx(Ie,{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||!!L)&&u.jsx(Ie,{size:"sm",onClick:k,children:"Next"}),C&&u.jsx(Ie,{size:"sm",onClick:R,disabled:!_,className:de(!_&&"opacity-50 cursor-not-allowed","rounded-full"),children:"Submit"})]})]})]})}function p_e(e){return e==null?void 0:e.answers}function uS(e){return e.id||e.question}function r$({message:e,onSubmit:t,isLatest:n}){var g;const r=yy(),i=e.input.questions,s=!!e.result,o=p_e(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[uS(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"})})]},uS(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"})]},uS(b))})]})}):n?u.jsx(n$,{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(Q5,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"Questions pending (newer question active)"})]})})}function i$({message:e,onConfirm:t,isLatest:n}){const r=yy(),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(Ie,{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(ts,{className:"h-4 w-4 text-success"}):u.jsx(Da,{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(Ie,{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(uh,{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(Wo,{remarkPlugins:Fa,components:$a,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(DW,{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(Ie,{size:"sm",onClick:()=>t(e.toolId,!0,!0),className:"rounded-full bg-primary text-background pr-4 md:order-last",children:[u.jsx(hW,{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(Ie,{size:"sm",variant:"outline",onClick:()=>f(!0),className:"rounded-full border-border flex-1 md:flex-initial md:order-first",children:[u.jsx(dh,{className:"h-4 w-4 mr-1.5"}),"Suggest Edits"]}),u.jsxs(Ie,{size:"sm",variant:"outline",onClick:()=>t(e.toolId,!0),className:"rounded-full border-border flex-1 md:flex-initial",children:[u.jsx(ts,{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(Ie,{size:"sm",variant:"ghost",onClick:()=>{f(!1),g("")},className:"rounded-full text-muted-foreground",children:"Cancel"}),u.jsxs(Ie,{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(jq,{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 g_e({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(r$,{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(i$,{message:i,onConfirm:(s,o,a,c)=>n(s,{confirmed:o,clearContext:a,message:c}),isLatest:!0})]})}return null}const v_e=40;function ps(e,t=v_e){return e.length<=t?e:`${e.slice(0,t-1)}…`}function b_e(e,t){switch(e.toolKind){case"bash":{const n=e.input.description||(e.input.command?U3(e.input.command):"");return n?`$ ${ps(n)}`:"running bash..."}case"read_file":{const n=Ul(e.input.filePath,t);return n?`reading ${ps(n)}`:"reading file..."}case"write_file":{const n=Ul(e.input.filePath,t);return n?`writing ${ps(n)}`:"writing file..."}case"edit_file":{const n=Ul(e.input.filePath,t);return n?`editing ${ps(n)}`:"editing file..."}case"delete_file":{const n=Ul(e.input.filePath,t);return n?`deleting ${ps(n)}`:"deleting file..."}case"glob":return e.input.pattern?`globbing ${ps(e.input.pattern)}`:"globbing...";case"grep":return e.input.pattern?`grepping ${ps(e.input.pattern)}`:"grepping...";case"web_search":return e.input.query?`searching: ${ps(e.input.query)}`:"searching web...";case"skill":return e.input.skill?`skill ${ps(e.input.skill)}`:"running skill...";case"todo_write":return"updating todos...";case"subagent_task":return e.input.subagentType?`delegating ${ps(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 ps(`${e.input.server}.${e.input.tool}`);case"unknown_tool":return`running ${ps(e.toolName)}`;default:return"running..."}}function x_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 b_e(o.tool,t)}const i=n[n.length-1];return(i==null?void 0:i.kind)==="assistant_text"?"streaming...":"running..."}function s$({run:e,indentDepth:t,localPath:n,onOpenSettings:r,onRetry:i,onSubagentAskUserQuestionSubmit:s,onSubagentExitPlanModeSubmit:o,onCancelSubagentRun:a}){var g;const c=j2(e.entries),d=c.some(b=>b.kind==="assistant_text"),f=e.status==="running"&&d,m=e.status==="running"?x_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`},[bm]:"",children:[u.jsxs("header",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[u.jsx(ch,{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(Ls,{className:"h-3.5 w-3.5"})})]}),c.map(b=>u.jsx(e$,{message:b,localPath:n,isRunning:e.status==="running"},b.id)),e.pendingTool&&u.jsx(g_e,{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(h_e,{error:e.error,runId:e.runId,subagentId:e.subagentId,onOpenSettings:r,onRetry:i})})]})}function y_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 __e=v.memo(function({content:t,attachments:n=[],steered:r=!1,autoContinue:i}){const[s,o]=v.useState(null),a=yy(),c=v.useMemo(()=>y_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?Ep(g,"user_attachment"):null;function y(_){if(!d||!_.contentUrl)return;if(kh(_).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(v2,{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($o,{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(mK,{"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(Wo,{remarkPlugins:Fa,components:$a,children:c.body})})]}):null,i?u.jsx("span",{className:"text-xs text-muted-foreground opacity-70",children:"auto-sent"}):null]}),u.jsx(Th,{source:b,open:b!==null,onOpenChange:_=>!_&&o(null)})]})});function w_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 o$({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(Ts,{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 dS({title:e,items:t,icon:n,getIcon:r}){return t.length===0?null:u.jsx(o$,{title:e,count:t.length,children:u.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.map(i=>u.jsx(fF,{icon:r?r(i):n,children:i},i))})})}function S_e(e){const t=e.match(/^mcp__([^_]+)__(.+)$/);return t?{server:t[1],tool:t[2]}:null}function a$({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 C_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 mD({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(Ts,{className:de("h-3 w-3 text-muted-foreground transition-transform duration-200",t&&"rotate-90")}),u.jsx(a$,{status:e.status}),u.jsx("span",{className:"text-muted-foreground font-medium",children:t1(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:C_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(fF,{icon:uF(`mcp__${e.name}__${i}`),children:i},i))})]})}function k_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(a$,{status:"failed"}),u.jsxs("span",{className:"text-muted-foreground/60",children:[n.length," disconnected"]})]}):null;return u.jsx(o$,{title:"MCP Servers",count:e.length,badge:r,children:u.jsxs("div",{className:"flex flex-col gap-2",children:[t.map(i=>u.jsx(mD,{server:i},i.name)),n.map(i=>u.jsx(mD,{server:i},i.name))]})})}function E_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(Ts,{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 N_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=S_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(qa,{children:u.jsxs(p2,{expandedContent:u.jsx(_y,{className:"my-4 text-xs",children:u.jsxs("div",{className:"flex flex-col gap-3",children:[u.jsx(Vbe,{children:e.model}),u.jsx(dS,{title:"Tools",items:n,getIcon:i=>sC[i]??cF}),u.jsx(dS,{title:"Agents",items:e.agents,icon:Ax}),u.jsx(dS,{title:"Commands",items:e.slashCommands,icon:Fq}),u.jsx(k_e,{servers:r}),t&&u.jsx(E_e,{rawJson:t})]})}),children:[u.jsx(tW,{className:"h-5 w-5 text-logo"}),u.jsx(ru,{children:"Session Started"})]})})}const T_e={"kanna-oauth-pool":"Pool token","claude-pro":"Claude Pro","claude-max":"Claude Max"};function R_e(e,t){return e?T_e[e]??e:t?`API key (${t})`:null}function A_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=R_e(n,r),[d,f]=v.useState(!1);return u.jsx(qa,{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(Ts,{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(_y,{className:"mt-3 mb-2 text-xs",children:u.jsxs("div",{className:"flex flex-col gap-3",children:[u.jsx(oC,{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 j_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 M_e(e){if(e!==0)return"https://status.claude.com"}function L_e({message:e}){const t=e.status>0?`${e.status} ${j_e(e.status)}`:"API Error",n=M_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(gm,{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 I_e="https://www.anthropic.com/legal/aup";function D_e(e){return e.replace(/^API Error:\s*/i,"")}function P_e({message:e}){const t=D_e(e.text);return u.jsx("div",{className:"w-full max-w-[70ch]",children:u.jsxs("div",{className:"rounded-md border border-warning/40 bg-warning/10 px-3 py-2.5 space-y-1.5",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-warning",children:[u.jsx(_k,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"uppercase tracking-wide",children:"Blocked by Usage Policy"})]}),u.jsx("div",{className:"text-sm whitespace-pre-wrap break-words text-foreground/90",children:t}),u.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground pt-0.5",children:[u.jsx("a",{href:I_e,target:"_blank",rel:"noreferrer",className:"hover:underline",children:"Usage Policy"}),e.requestId&&u.jsxs("span",{children:["Request ID: ",u.jsx("code",{className:"text-xs",children:e.requestId})]})]})]})})}const O_e={completed:{Icon:ts,iconClass:"text-success",textClass:"text-muted-foreground"},in_progress:{Icon:bn,iconClass:"text-foreground animate-spin",textClass:"text-foreground font-medium"},pending:{Icon:CW,iconClass:"text-muted-foreground",textClass:"text-muted-foreground"}};function z_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(zG,{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}=O_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 B_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=Eh(a),d=hy(c,t.mimeType),f=t.size>0?Rh(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($o,{attachment:a,disabledReason:"File no longer available"})});if(!kh(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($o,{attachment:a,onClick:()=>o(!0),meta:m,ariaLabel:_})}),u.jsx(Th,{source:s?Ep(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($o,{attachment:a,href:n,download:t.fileName||void 0,meta:m,ariaLabel:y.join(", ")})})}const hS=new Map;function F_e(e){const{cacheKey:t,enabled:n,ref:r,fetcher:i,rootMargin:s}=e,o=hS.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=hS.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(L=>{E||w.current!==k||(hS.set(k,L),f(L),c("ready"))}).catch(L=>{E||j.signal.aborted||w.current!==k||(g(L instanceof Error?L:new Error(String(L))),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=Eh(r),s=hy(i,e.mimeType),o=e.size&&e.size>0?Rh(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(H_e,{source:e,onOpen:t,friendlyType:s,sizeLabel:o}):u.jsx($o,{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 H_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 QE(o,4096);if(f.aborted)throw new Error("aborted");return m.content.slice(0,200)},[o]),c=F_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 U_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(Th,{source:o?c:null,open:o,onOpenChange:a})]})}function V_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(wW,{className:"h-4 w-4 ml-1.5"}),u.jsx("em",{children:"Interrupted"})]})})}function dx({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 W_e(){return u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx(dx,{}),u.jsx("span",{className:"text-[11px] tracking-widest text-muted-foreground uppercase flex-shrink-0",children:"Compacted"}),u.jsx(dx,{})]})}function G_e(){return u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx(dx,{}),u.jsx("span",{className:"text-[11px] tracking-widest text-muted-foreground uppercase flex-shrink-0",children:"Context Cleared"}),u.jsx(dx,{})]})}function q_e({message:e}){const t=e.path.lastIndexOf("/"),n=t>=0?e.path.slice(0,t+1):"",r=t>=0?e.path.slice(t+1):e.path;return u.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[u.jsx(Nx,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/70","aria-hidden":"true"}),u.jsx("span",{className:"text-xs",children:"Loaded"}),u.jsxs("span",{className:"min-w-0 truncate font-mono text-xs",children:[n?u.jsx("span",{className:"opacity-60",children:n}):null,u.jsx("span",{className:"text-foreground/70",children:r})]})]})}function K_e({message:e}){return u.jsx(qa,{children:u.jsxs(p2,{expandedContent:u.jsx(_y,{className:"my-4 text-xs",children:u.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none",children:u.jsx(Wo,{remarkPlugins:Fa,components:$a,children:e.summary})})}),children:[u.jsx("div",{className:"w-5 h-5 relative flex items-center justify-center",children:u.jsx(Z5,{className:"h-4.5 w-4.5 text-muted-foreground"})}),u.jsx(ru,{children:"Summarized"})]})})}const Y_e={compacting:"Compacting..."};function X_e({message:e}){const t=Y_e[e.status]||e.status;return u.jsxs(qa,{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(Z5,{className:"h-4.5 w-4.5 text-muted-foreground"})}),u.jsx(ru,{className:"text-left transition-opacity duration-200 truncate",children:t})]})}const Q_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"}},Z_e={key:"other",singular:"tool call",plural:"tool calls"};function J_e(e){return Q_e[e]??Z_e}function ewe(e){const t=new Map,n=[];for(const r of e){const i=r.toolKind,s=J_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 twe({messages:e,isLoading:t,localPath:n,expanded:r,onExpandedChange:i,chatId:s}){const o=v.useMemo(()=>ewe(e),[e]),c=e.some(d=>d.result===void 0)&&t;return u.jsx(qa,{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(Ts,{className:`h-4.5 w-4.5 text-muted-icon transition-all duration-200 ${r?"rotate-90":""}`})}),u.jsx(ru,{className:"text-left",children:u.jsx(Np,{animate:c,children:o})})]})}),r&&u.jsxs("div",{className:"my-4 flex flex-col gap-3",children:[e.map(d=>u.jsx(ux,{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(Ts,{className:"h-4.5 w-4.5 text-muted-icon -rotate-90"})}),u.jsx(ru,{className:"text-left",children:"Collapse"})]})})]})]})})}function nwe(e){if(e!=="system")return e}function fS(e,t){const n=nwe(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 rwe=/^(\d{2})\/(\d{2})\/(\d{4}) (\d{2}):(\d{2})$/;function pD(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 iwe(e,t){const n=rwe.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=pD(t,b),_=b-y*6e4,w=pD(t,_);return _-(w-y)*6e4}const swe={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"},owe={primary:"default",secondary:"secondary",ghost:"ghost",destructive:"destructive"};function ka({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",swe[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(Ie,{type:"button",size:"sm",variant:owe[g.variant??"ghost"],disabled:g.disabled||m&&!b,onClick:()=>{f(g)},className:"gap-1.5",children:[b?u.jsx(bn,{className:"size-3.5 animate-spin"}):null,g.label]},g.id)})}):null]})}function awe({schedule:e,onAccept:t,onReschedule:n,onCancel:r}){const[i,s]=v.useState(()=>fS(e.scheduledAt??e.resetAt,e.tz)),[o,a]=v.useState(!1),c=v.useMemo(()=>iwe(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=fS(e.scheduledAt??e.resetAt,e.tz);return u.jsx(ka,{title:`Auto-continued at ${y}`,tone:"success"})}if(e.state==="cancelled")return u.jsx(ka,{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(ka,{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(un,{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=fS(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(ka,{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(ka,{title:`Auto-continue at ${m} (${g})`,body:u.jsxs("div",{className:"space-y-1",children:[u.jsx(un,{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 lwe({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(Ie,{size:"sm",variant:"outline",className:"rounded-full",onClick:()=>n(e,{kind:"deny",reason:"user_canceled"}),children:"Edit"}),u.jsx(Ie,{size:"sm",className:"rounded-full",onClick:()=>n(e,{kind:"answer",payload:{confirmed:!0}}),children:"Confirm"})]})]})}function cwe({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(Ie,{variant:"ghost",size:"sm",onClick:()=>r(e,{kind:"deny",reason:"user_canceled"}),children:"Deny"}),u.jsx(Ie,{variant:"default",size:"sm",onClick:()=>r(e,{kind:"allow"}),children:"Allow"})]})]})}function uwe({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(n$,{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(lwe,{toolRequestId:n,plan:s,onAnswer:t})}return u.jsx(cwe,{toolRequestId:n,toolName:r,args:i,onAnswer:t})}const O2="mcp__kanna__delegate_subagent";function dwe(e){const t=[];for(const n of e){if(n.kind!=="tool"||n.toolKind!=="mcp_generic"||n.toolName!==O2)continue;const r=n.input.payload.subagent_id;typeof r=="string"&&t.push({toolId:n.toolId,subagentId:r})}return t}function hwe(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 fwe(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 mwe=new Set(["AskUserQuestion","ExitPlanMode","TodoWrite",O2]);function gD(e){if(e.kind!=="tool")return!1;const t=e.toolName;return!mwe.has(t)}function pwe(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 gwe(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 pwe(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 vwe(e,t){const n=[];let r=0;for(;r<e.length;){const i=e[r],s=t[r];if(s!=null&&s.shouldRender&&gD(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(!gD(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 vD(e){var n;return e.type==="single"?e.message.id:`tool-group:${((n=e.messages[0])==null?void 0:n.id)??e.startIndex}`}function mS(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>n===t[r])}function bwe(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 xwe(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>bwe(n,t[r]))}function th(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)&&xwe(e.attachments,t.attachments);case"system_init":return t.kind==="system_init"&&e.provider===t.provider&&e.model===t.model&&mS(e.tools,t.tools)&&mS(e.agents,t.agents)&&mS(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"assistant_thinking":return t.kind==="assistant_thinking"&&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"policy_refusal":return t.kind==="policy_refusal"&&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"memory_loaded":return t.kind==="memory_loaded"&&e.path===t.path;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 ywe(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&&th(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)=>th(n,t.messages[r])):!1}function _we(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&&ywe(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 wwe(e){const t=v.useRef({byId:new Map,result:[]}),n=v.useMemo(()=>_we(e,t.current),[e]);return v.useLayoutEffect(()=>{t.current=n}),n.result}const l$=(e,t)=>{},Swe=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=l$,schedules:_,onAutoContinueAccept:w,onAutoContinueReschedule:C,onAutoContinueCancel:E,chatId:k}){let T=null;if(t.kind==="user_prompt")T=u.jsx(__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(awe,{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(w_e,{json:t.json},t.id);break;case"system_init":T=s?u.jsx(N_e,{message:t,rawJson:t.debugRaw},t.id):null;break;case"account_info":T=o?u.jsx(A_e,{message:t},t.id):null;break;case"assistant_text":T=u.jsx(YF,{message:t},t.id);break;case"assistant_thinking":T=u.jsx(XF,{message:t},t.id);break;case"api_error":T=u.jsx(L_e,{message:t},t.id);break;case"policy_refusal":T=u.jsx(P_e,{message:t},t.id);break;case"tool":if(t.isError){T=u.jsx(ux,{message:t,isLoading:r,localPath:i,chatId:k},t.id);break}if(t.toolKind==="ask_user_question"){T=u.jsx(r$,{message:t,onSubmit:g,isLatest:a},t.id);break}if(t.toolKind==="exit_plan_mode"){T=u.jsx(i$,{message:t,onConfirm:b,isLatest:c},t.id);break}if(t.toolKind==="todo_write"){T=d?u.jsx(z_e,{message:t},t.id):null;break}if(t.toolKind==="offer_download"&&t.result){T=u.jsx(B_e,{message:t},t.id);break}if(t.toolKind==="image_generation"){T=u.jsx(U_e,{message:t},t.id);break}T=u.jsx(ux,{message:t,isLoading:r,localPath:i,chatId:k},t.id);break;case"result":T=f?null:u.jsx(JF,{message:t},t.id);break;case"context_window_updated":T=null;break;case"interrupted":T=u.jsx(V_e,{message:t},t.id);break;case"compact_boundary":T=u.jsx(W_e,{},t.id);break;case"context_cleared":T=u.jsx(G_e,{},t.id);break;case"memory_loaded":T=u.jsx(q_e,{message:t},t.id);break;case"compact_summary":T=u.jsx(K_e,{message:t},t.id);break;case"status":T=m?u.jsx(X_e,{message:t},t.id):null;break;case"pending_tool_request":T=u.jsx(uwe,{entry:t,onAnswer:y},t.id);break}return T?u.jsx("div",{id:`msg-${t.id}`,className:"group relative","data-index":n,[bm]:"",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&&th(e.message,t.message)),Cwe=v.memo(function({id:t,messages:n,isLoading:r,localPath:i,expanded:s,onExpandedChange:o,chatId:a}){return u.jsx("div",{className:"group relative",[bm]:"",children:u.jsx(twe,{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)=>th(n,t.messages[r])));function c$(e,{isLoading:t,localPath:n,latestToolIds:r}){const i=gwe(e,r),s=vwe(e,i),o=[];for(const a of s){if(a.type==="tool-group"){o.push({kind:"tool-group",id:vD(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:vD(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 kwe={};function u$(e,t,n,r,i,s,o){const a=n.get(e.runId)??[];return u.jsxs(yn.Fragment,{children:[u.jsx(s$,{run:e,indentDepth:t,localPath:r,onSubagentAskUserQuestionSubmit:i,onSubagentExitPlanModeSubmit:s,onCancelSubagentRun:o}),a.map(c=>u$(c,t+1,n,r,i,s,o))]},e.runId)}const d$=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(Cwe,{id:t.id,startIndex:t.startIndex,messages:t.messages,isLoading:t.isLoading,localPath:t.localPath,expanded:n??!1,onExpandedChange:r,chatId:m}):u.jsx(Swe,{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)=>th(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&&th(e.row.message,t.row.message):!1}),h$={},Ewe=(e,t)=>{},Nwe=(e,t)=>{},Twe=e=>{};function Rwe({messages:e,isLoading:t,localPath:n,latestToolIds:r,onOpenLocalLink:i,chatId:s,onAskUserQuestionSubmit:o,onExitPlanModeConfirm:a,onToolRequestAnswer:c=l$,schedules:d=h$,onAutoContinueAccept:f=Ewe,onAutoContinueReschedule:m=Nwe,onAutoContinueCancel:g=Twe,onTunnelAccept:b,onTunnelStop:y,onTunnelRetry:_,subagentRuns:w=kwe,onSubagentAskUserQuestionSubmit:C,onSubagentExitPlanModeSubmit:E,onCancelSubagentRun:k}){const[T,R]=v.useState({}),A=v.useMemo(()=>c$(e,{isLoading:t,localPath:n,latestToolIds:r}),[t,r,n,e]),{matchedRunsByToolId:j,childrenByParentRunId:L}=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:O,orphans:F}=hwe(dwe(e),M);return fwe(F,!1),{matchedRunsByToolId:O,childrenByParentRunId:D}},[w,e]),H=v.useCallback((M,D)=>{R(z=>z[M]===D?z:{...z,[M]:D})},[]);return u.jsx(lF,{onOpenLocalLink:i,children:A.map(M=>{const D=M.kind==="single"&&M.message.kind==="tool"&&M.message.toolName===O2?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(d$,{row:M,toolGroupExpanded:M.kind==="tool-group"?T[M.id]??!1:void 0,onToolGroupExpandedChange:H,onAskUserQuestionSubmit:o,onExitPlanModeConfirm:a,onToolRequestAnswer:c,schedules:d,onAutoContinueAccept:f,onAutoContinueReschedule:m,onAutoContinueCancel:g,chatId:s}),z?u$(z,0,L,n??"",C,E,k):null]},M.id)})})}v.memo(Rwe);const Awe=Object.freeze([]),pS=is((e,t)=>({sharesByChat:{},listForChat(n){return t().sharesByChat[n]??Awe},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)}}))}})),jwe=/^\/(\S*)$/;function f$(e){return e.replace(/^\/+/,"")}function Mwe(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=f$(t.name),f=t.argumentHint?`/${d} `:`/${d}`,m=`${c}${f}${s}`,g=c.length+f.length;return{value:m,caret:g}}function Lwe(e,t){if(t<=0)return{open:!1,query:""};const n=e.slice(0,t),r=jwe.exec(n);return r?{open:!0,query:r[1]??""}:{open:!1,query:""}}function Iwe(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 Dwe=4,bD=80;function Pwe(e){return e.length<=bD?e:`${e.slice(0,bD-1).trimEnd()}…`}function Owe({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:Dwe}).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:["/",f$(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 zwe=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:zwe}).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"?K5:Nx;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(rW,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),c?u.jsxs(u.Fragment,{children:[u.jsx(ch,{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 Iv={open:!1,query:"",tokenStart:-1};function Fwe(e,t){if(t<=0)return Iv;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===`