@cuongtran001/kanna 0.97.1 → 0.97.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 (55) hide show
  1. package/dist/client/assets/{arc-0gGR0Z40.js → arc-BeYqRlS4.js} +1 -1
  2. package/dist/client/assets/{architectureDiagram-3BPJPVTR-I6MDczES.js → architectureDiagram-3BPJPVTR-BTxcC3Bx.js} +1 -1
  3. package/dist/client/assets/{blockDiagram-GPEHLZMM-C9SVtk9i.js → blockDiagram-GPEHLZMM-B_CLWeW3.js} +1 -1
  4. package/dist/client/assets/{c4Diagram-AAUBKEIU-CHnbfgC3.js → c4Diagram-AAUBKEIU-kZm6qlQm.js} +1 -1
  5. package/dist/client/assets/channel-ohENpLj7.js +1 -0
  6. package/dist/client/assets/{chunk-2J33WTMH-CYdJbG8_.js → chunk-2J33WTMH-C77Np9ft.js} +1 -1
  7. package/dist/client/assets/{chunk-4BX2VUAB-DOQ6nObh.js → chunk-4BX2VUAB-DUyKnkbT.js} +1 -1
  8. package/dist/client/assets/{chunk-55IACEB6-Bkd-rmrv.js → chunk-55IACEB6-HUFJLmvp.js} +1 -1
  9. package/dist/client/assets/{chunk-727SXJPM-7Mgkyy-u.js → chunk-727SXJPM-eMaVSOKi.js} +1 -1
  10. package/dist/client/assets/{chunk-AQP2D5EJ-C_3BL3vu.js → chunk-AQP2D5EJ-Dqr7iBWK.js} +1 -1
  11. package/dist/client/assets/{chunk-FMBD7UC4-CzUyzc3-.js → chunk-FMBD7UC4-BtAWu6Fv.js} +1 -1
  12. package/dist/client/assets/{chunk-ND2GUHAM-CUYRAZuM.js → chunk-ND2GUHAM-CyxbGgpO.js} +1 -1
  13. package/dist/client/assets/{chunk-QZHKN3VN-Duij8e2_.js → chunk-QZHKN3VN-aqVpGxUl.js} +1 -1
  14. package/dist/client/assets/classDiagram-4FO5ZUOK-BlyPnDJH.js +1 -0
  15. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-BlyPnDJH.js +1 -0
  16. package/dist/client/assets/{cose-bilkent-S5V4N54A-BYxpTHSy.js → cose-bilkent-S5V4N54A-GzK3z9WD.js} +1 -1
  17. package/dist/client/assets/{dagre-BM42HDAG-7F9u2uST.js → dagre-BM42HDAG-Djd07Bgc.js} +1 -1
  18. package/dist/client/assets/{diagram-2AECGRRQ-CC_CHLBl.js → diagram-2AECGRRQ-CPTC78mN.js} +1 -1
  19. package/dist/client/assets/{diagram-5GNKFQAL-BWSy06XD.js → diagram-5GNKFQAL-DVTkaw4f.js} +1 -1
  20. package/dist/client/assets/{diagram-KO2AKTUF--t_nyy6l.js → diagram-KO2AKTUF-10KOjvpy.js} +1 -1
  21. package/dist/client/assets/{diagram-LMA3HP47-DZtQqDSl.js → diagram-LMA3HP47-Myxb2cAv.js} +1 -1
  22. package/dist/client/assets/{diagram-OG6HWLK6-DqZ21Pd1.js → diagram-OG6HWLK6-BuRZkgMd.js} +1 -1
  23. package/dist/client/assets/{erDiagram-TEJ5UH35-BaUNKGCo.js → erDiagram-TEJ5UH35-Be5hhZh4.js} +1 -1
  24. package/dist/client/assets/{flowDiagram-I6XJVG4X-CQO_q7vi.js → flowDiagram-I6XJVG4X-BhiDJ4Mp.js} +1 -1
  25. package/dist/client/assets/{ganttDiagram-6RSMTGT7-BmIHYCwc.js → ganttDiagram-6RSMTGT7-CZ_jbXit.js} +1 -1
  26. package/dist/client/assets/{gitGraphDiagram-PVQCEYII-CCiBB8h9.js → gitGraphDiagram-PVQCEYII-DcliQiyM.js} +1 -1
  27. package/dist/client/assets/{index-CTA1huWY.js → index-BC-Tl-79.js} +1 -1
  28. package/dist/client/assets/{index-FTTMtcqA.js → index-MixgFXRr.js} +3 -3
  29. package/dist/client/assets/{infoDiagram-5YYISTIA-DErXn_Zx.js → infoDiagram-5YYISTIA-pteIHWnV.js} +1 -1
  30. package/dist/client/assets/{ishikawaDiagram-YF4QCWOH-oM7drLw1.js → ishikawaDiagram-YF4QCWOH-B_L5beaQ.js} +1 -1
  31. package/dist/client/assets/{journeyDiagram-JHISSGLW-4QaQbzoJ.js → journeyDiagram-JHISSGLW-hen4Bh6f.js} +1 -1
  32. package/dist/client/assets/{kanban-definition-UN3LZRKU-Usrv4pIb.js → kanban-definition-UN3LZRKU-BtUymVff.js} +1 -1
  33. package/dist/client/assets/{linear-csvKup_t.js → linear-FUiPyB6F.js} +1 -1
  34. package/dist/client/assets/{mermaid.core-GVOEJSwQ.js → mermaid.core-CoJEFYct.js} +4 -4
  35. package/dist/client/assets/{mindmap-definition-RKZ34NQL-BPD57XiL.js → mindmap-definition-RKZ34NQL-CazuLaBR.js} +1 -1
  36. package/dist/client/assets/{pieDiagram-4H26LBE5-ppinb7WI.js → pieDiagram-4H26LBE5-CRb7TKXS.js} +1 -1
  37. package/dist/client/assets/{quadrantDiagram-W4KKPZXB-DaM2AwiI.js → quadrantDiagram-W4KKPZXB-BSJq42JJ.js} +1 -1
  38. package/dist/client/assets/{requirementDiagram-4Y6WPE33-CFv8FIQc.js → requirementDiagram-4Y6WPE33-BnvGLDfm.js} +1 -1
  39. package/dist/client/assets/{sankeyDiagram-5OEKKPKP-CHlmHj73.js → sankeyDiagram-5OEKKPKP-BsefP6U4.js} +1 -1
  40. package/dist/client/assets/{sequenceDiagram-3UESZ5HK-DUBGVLTV.js → sequenceDiagram-3UESZ5HK-9nUKArcj.js} +1 -1
  41. package/dist/client/assets/{stateDiagram-AJRCARHV-DvaK-zL4.js → stateDiagram-AJRCARHV-BzYVPtVp.js} +1 -1
  42. package/dist/client/assets/stateDiagram-v2-BHNVJYJU-BRLtys3w.js +1 -0
  43. package/dist/client/assets/{timeline-definition-PNZ67QCA-BjuJEg4f.js → timeline-definition-PNZ67QCA-Dk6D_V0F.js} +1 -1
  44. package/dist/client/assets/{vennDiagram-CIIHVFJN-ZBfjEaz5.js → vennDiagram-CIIHVFJN-B-gVcndn.js} +1 -1
  45. package/dist/client/assets/{wardley-L42UT6IY-BwukOuhW.js → wardley-L42UT6IY-DKOWjaGp.js} +1 -1
  46. package/dist/client/assets/{wardleyDiagram-YWT4CUSO-sb0WFFaN.js → wardleyDiagram-YWT4CUSO-DhXoRo4O.js} +1 -1
  47. package/dist/client/assets/{xychartDiagram-2RQKCTM6-DhszTw1f.js → xychartDiagram-2RQKCTM6-Bth68Xec.js} +1 -1
  48. package/dist/client/index.html +1 -1
  49. package/package.json +1 -1
  50. package/src/server/agent.test.ts +16 -0
  51. package/src/server/agent.ts +6 -2
  52. package/dist/client/assets/channel-Bxbp5CU9.js +0 -1
  53. package/dist/client/assets/classDiagram-4FO5ZUOK-DwOKYn3F.js +0 -1
  54. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-DwOKYn3F.js +0 -1
  55. package/dist/client/assets/stateDiagram-v2-BHNVJYJU-D78gnoEY.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(ro,{open:e,onOpenChange:T=>{T||s()},children:u.jsxs(js,{className:"max-w-2xl",children:[u.jsxs(io,{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(fi,{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:m,onChange:T=>f(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(Pe,{variant:"ghost",onClick:k,children:"Reset to defaults"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Pe,{variant:"ghost",onClick:s,children:"Cancel"}),u.jsx(Pe,{onClick:E,children:"Apply"})]})]})]})}),u.jsx(ro,{open:g,onOpenChange:T=>{T||(b(!1),_(null))},children:u.jsxs(js,{className:"max-w-md",children:[u.jsx(io,{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(Pe,{variant:"ghost",onClick:()=>{b(!1),_(null)},children:"Cancel"}),u.jsx(Pe,{variant:"destructive",onClick:()=>{y&&a(y),b(!1),_(null)},children:"Enable auto-allow"})]})]})})]})}const NZ={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:[]},dn=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}));dn.displayName="Input";const $3=v.createContext(null);function TZ({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})}),[]),m=v.useCallback(b=>new Promise(y=>{n({kind:"prompt",options:b,resolve:y})}),[]),f=v.useCallback(b=>new Promise(y=>{n({kind:"alert",options:b,resolve:y})}),[]),g=v.useMemo(()=>({confirm:d,prompt:m,alert:f}),[f,d,m]);return u.jsxs($3.Provider,{value:g,children:[e,u.jsx(ro,{open:t!==null,onOpenChange:b=>{b||!t||a()},children:u.jsx(js,{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(io,{children:t.options.title}),t.options.description?u.jsx(up,{children:t.options.description}):null,t.kind==="prompt"?u.jsx(dn,{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(Pe,{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(Pe,{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 mp(){const e=v.useContext($3);if(!e)throw new Error("useAppDialog must be used within AppDialogProvider");return e}const Yk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("bg-card text-card-foreground",e),...t}));Yk.displayName="Card";const Xk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("flex flex-col space-y-1.5 p-2",e),...t}));Xk.displayName="CardHeader";const H3=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:de("text-2xl font-semibold leading-none tracking-tight",e),...t}));H3.displayName="CardTitle";const U3=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:de("text-sm text-muted-foreground",e),...t}));U3.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 RZ=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("flex items-center p-6 pt-0",e),...t}));RZ.displayName="CardFooter";const AZ={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 jZ({variant:e,children:t,dot:n=!0,className:r}){const i=AZ[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 MZ="modulepreload",LZ=function(e){return"/"+e},Xj={},X=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(d){return Promise.all(d.map(m=>Promise.resolve(m).then(f=>({status:"fulfilled",value:f}),f=>({status:"rejected",reason:f}))))};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=LZ(d),d in Xj)return;Xj[d]=!0;const m=d.endsWith(".css"),f=m?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${f}`))return;const g=document.createElement("link");if(g.rel=m?"stylesheet":MZ,m||(g.as="script"),g.crossOrigin="",g.href=d,c&&g.setAttribute("nonce",c),document.head.appendChild(g),m)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)})},IZ=v.lazy(()=>X(()=>import("./index-CTA1huWY.js"),[]).then(e=>({default:e.Toaster})));function DZ(){return u.jsx(v.Suspense,{fallback:null,children:u.jsx(IZ,{position:"bottom-right",theme:"system",closeButton:!0,duration:6e3})})}const PZ="0.97.1",OZ={version:PZ},Yn="Kanna",Qj="kanna",zZ=".kanna",BZ=".kanna-dev",FZ="KANNA_RUNTIME_PROFILE",Zk=`kanna/${OZ.version}`,$Z="[kanna]",HZ=`~/${Yn}`;function qx(){var t;return(t=globalThis.process)==null?void 0:t.env}function UZ(e=qx()){var t;return((t=e==null?void 0:e[FZ])==null?void 0:t.trim().toLowerCase())==="dev"?"dev":"prod"}function VZ(e=qx()){return UZ(e)==="dev"?BZ:zZ}function WZ(e=qx()){return`~/${VZ(e)}`}function GZ(e=qx()){return`${WZ(e)}/keybindings.json`}function Zg(e){return e?`${Qj} ${e}`:Qj}const Zj=e=>{let t;const n=new Set,r=(d,m)=>{const f=typeof d=="function"?d(t):d;if(!Object.is(f,t)){const g=t;t=m??(typeof f!="object"||f===null)?f:Object.assign({},t,f),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},qZ=(e=>e?Zj(e):Zj),KZ=e=>e;function YZ(e,t=KZ){const n=_n.useSyncExternalStore(e.subscribe,_n.useCallback(()=>t(e.getState()),[e,t]),_n.useCallback(()=>t(e.getInitialState()),[e,t]));return _n.useDebugValue(n),n}const Jj=e=>{const t=qZ(e),n=r=>YZ(t,r);return Object.assign(n,t),n},Oi=(e=>e?Jj(e):Jj),V3="always",W3="funk",XZ=[{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 QZ(e){switch(e){case"never":case"unfocused":case"always":return e;default:return V3}}function ZZ(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 W3}}const Vc=Oi()(e=>({chatSoundPreference:V3,chatSoundId:W3,setChatSoundPreference:t=>e({chatSoundPreference:QZ(t)}),setChatSoundId:t=>e({chatSoundId:ZZ(t)})})),JZ={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 eJ(e=document){return e.visibilityState!=="visible"||!e.hasFocus()}function tJ(e){const t=new Audio(JZ[e]);return t.preload="auto",t.play()}async function i1(e,t){if(t<=0)return;const n=Array.from({length:t},(r,i)=>new Promise(s=>{window.setTimeout(()=>{tJ(e).catch(()=>{}).finally(()=>s())},i*90)}));await Promise.all(n)}function nJ(e,t=document){return e==="never"?!1:e==="always"?!0:eJ(t)}function rJ(e){return e.projectGroups.reduce((t,n)=>t+n.chats.reduce((r,i)=>r+(i.unread?1:0)+(i.status==="waiting_for_user"?1:0),0),0)}function eM(e){let t=0;const n=new Set;for(const r of e.projectGroups)for(const i of r.chats)i.unread&&(t+=1),i.status==="waiting_for_user"&&n.add(i.chatId);return{unreadCount:t,waitingChatIds:n}}function iJ(e,t){if(!e)return 0;const n=eM(e),r=eM(t),i=Math.max(0,r.unreadCount-n.unreadCount);let s=0;for(const o of r.waitingChatIds)n.waitingChatIds.has(o)||(s+=1);return i+s}function s1(e){return e.split(/[\s_-]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}const sJ=[/^(?:\/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 G3(e){const t=e.trim();for(const n of sJ){const r=t.match(n);if(!r)continue;const i=(r[2]??r[1]??"").trim();if(i)return i}return t}function Jk(e){return e.split("/").pop()||e}const oJ=1440*6e4;function aJ(e,t){if(e===void 0)return null;const n=Math.max(0,t-e),r=6e4,i=60*r,s=oJ,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 lJ(e){return e.lastMessageAt??e._creationTime}const eE=1e3,ob=60*eE,Td=60*ob,ew=24*Td;function qs(e){const t=Math.max(0,e);if(t<ob)return`${Math.floor(t/eE)}s`;if(t<Td)return`${Math.floor(t/ob)}m`;if(t<ew){const i=Math.floor(t/Td),s=Math.floor(t%Td/ob);return s===0?`${i}h`:`${i}h ${s}m`}const n=Math.floor(t/ew),r=Math.floor(t%ew/Td);return r===0?`${n}d`:`${n}d ${r}h`}function o1(e){const t=Math.max(0,e);if(t>=Td)return qs(t);const n=Math.floor(t/eE),r=Math.floor(n/60),i=n%60;return`${r}:${i.toString().padStart(2,"0")}`}function a1(e){switch(e){case"idle":return"Idle";case"starting":return"Starting";case"running":return"Running";case"waiting_for_user":return"Waiting";case"failed":return"Failed"}}function tM(e){switch(e){case"running":return"active";case"waiting_for_user":return"attention";case"failed":return"destructive";case"idle":case"starting":default:return"muted"}}function nM(e){switch(e){case"active":return"text-emerald-500 dark:text-emerald-400";case"attention":return"text-amber-500 dark:text-amber-400";case"destructive":return"text-destructive";case"muted":default:return"text-muted-foreground"}}function tE(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=_n.useRef(null),k=_n.useRef(new Map).current;return u.jsx(i,{scope:w,itemMap:k,collectionRef:E,children:C})};o.displayName=t;const a=e+"CollectionSlot",c=eu(a),d=_n.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 m=e+"CollectionItemSlot",f="data-radix-collection-item",g=eu(m),b=_n.forwardRef((_,w)=>{const{scope:C,children:E,...k}=_,T=_n.useRef(null),R=xn(w,T),A=s(m,C);return _n.useEffect(()=>(A.itemMap.set(T,{ref:T,...k}),()=>void A.itemMap.delete(T))),u.jsx(g,{[f]:"",ref:R,children:E})});b.displayName=m;function y(_){const w=s(e+"CollectionConsumer",_);return _n.useCallback(()=>{const E=w.collectionRef.current;if(!E)return[];const k=Array.from(E.querySelectorAll(`[${f}]`));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 cJ=v.createContext(void 0);function nE(e){const t=v.useContext(cJ);return e||t||"ltr"}var tw="rovingFocusGroup.onEntryFocus",uJ={bubbles:!1,cancelable:!0},pp="RovingFocusGroup",[l1,q3,dJ]=tE(pp),[hJ,K3]=Va(pp,[dJ]),[fJ,mJ]=hJ(pp),Y3=v.forwardRef((e,t)=>u.jsx(l1.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(l1.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(pJ,{...e,ref:t})})}));Y3.displayName=pp;var pJ=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:d,preventScrollOnEntryFocus:m=!1,...f}=e,g=v.useRef(null),b=xn(t,g),y=nE(s),[_,w]=qd({prop:o,defaultProp:a??null,onChange:c,caller:pp}),[C,E]=v.useState(!1),k=no(d),T=q3(n),R=v.useRef(!1),[A,j]=v.useState(0);return v.useEffect(()=>{const L=g.current;if(L)return L.addEventListener(tw,k),()=>L.removeEventListener(tw,k)},[k]),u.jsx(fJ,{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,...f,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(tw,uJ);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);Z3($,m)}}R.current=!1}),onBlur:rt(e.onBlur,()=>E(!1))})})}),X3="RovingFocusGroupItem",Q3=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...a}=e,c=ja(),d=s||c,m=mJ(X3,n),f=m.currentTabStopId===d,g=q3(n),{onFocusableItemAdd:b,onFocusableItemRemove:y,currentTabStopId:_}=m;return v.useEffect(()=>{if(r)return b(),()=>y()},[r,b,y]),u.jsx(l1.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:u.jsx(tn.span,{tabIndex:f?0:-1,"data-orientation":m.orientation,...a,ref:t,onMouseDown:rt(e.onMouseDown,w=>{r?m.onItemFocus(d):w.preventDefault()}),onFocus:rt(e.onFocus,()=>m.onItemFocus(d)),onKeyDown:rt(e.onKeyDown,w=>{if(w.key==="Tab"&&w.shiftKey){m.onItemShiftTab();return}if(w.target!==w.currentTarget)return;const C=bJ(w,m.orientation,m.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=m.loop?xJ(k,T+1):k.slice(T+1)}setTimeout(()=>Z3(k))}}),children:typeof o=="function"?o({isCurrentTabStop:f,hasTabStop:_!=null}):o})})});Q3.displayName=X3;var gJ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function vJ(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function bJ(e,t,n){const r=vJ(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return gJ[r]}function Z3(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function xJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var yJ=Y3,_J=Q3,c1=["Enter"," "],wJ=["ArrowDown","PageUp","Home"],J3=["ArrowUp","PageDown","End"],SJ=[...wJ,...J3],CJ={ltr:[...c1,"ArrowRight"],rtl:[...c1,"ArrowLeft"]},kJ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},gp="Menu",[Em,EJ,NJ]=tE(gp),[yu,e4]=Va(gp,[NJ,ec,K3]),Kx=ec(),t4=K3(),[TJ,_u]=yu(gp),[RJ,vp]=yu(gp),n4=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,a=Kx(t),[c,d]=v.useState(null),m=v.useRef(!1),f=no(s),g=nE(i);return v.useEffect(()=>{const b=()=>{m.current=!0,document.addEventListener("pointerdown",y,{capture:!0,once:!0}),document.addEventListener("pointermove",y,{capture:!0,once:!0})},y=()=>m.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(Hx,{...a,children:u.jsx(TJ,{scope:t,open:n,onOpenChange:f,content:c,onContentChange:d,children:u.jsx(RJ,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:m,dir:g,modal:o,children:r})})})};n4.displayName=gp;var AJ="MenuAnchor",rE=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Kx(n);return u.jsx(hp,{...i,...r,ref:t})});rE.displayName=AJ;var iE="MenuPortal",[jJ,r4]=yu(iE,{forceMount:void 0}),i4=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=_u(iE,t);return u.jsx(jJ,{scope:t,forceMount:n,children:u.jsx(Ps,{present:n||s.open,children:u.jsx(gh,{asChild:!0,container:i,children:r})})})};i4.displayName=iE;var Ts="MenuContent",[MJ,sE]=yu(Ts),s4=v.forwardRef((e,t)=>{const n=r4(Ts,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=_u(Ts,e.__scopeMenu),o=vp(Ts,e.__scopeMenu);return u.jsx(Em.Provider,{scope:e.__scopeMenu,children:u.jsx(Ps,{present:r||s.open,children:u.jsx(Em.Slot,{scope:e.__scopeMenu,children:o.modal?u.jsx(LJ,{...i,ref:t}):u.jsx(IJ,{...i,ref:t})})})})}),LJ=v.forwardRef((e,t)=>{const n=_u(Ts,e.__scopeMenu),r=v.useRef(null),i=xn(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Px(s)},[]),u.jsx(oE,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:rt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),IJ=v.forwardRef((e,t)=>{const n=_u(Ts,e.__scopeMenu);return u.jsx(oE,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),DJ=eu("MenuContent.ScrollLock"),oE=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:a,onEntryFocus:c,onEscapeKeyDown:d,onPointerDownOutside:m,onFocusOutside:f,onInteractOutside:g,onDismiss:b,disableOutsideScroll:y,..._}=e,w=_u(Ts,n),C=vp(Ts,n),E=Kx(n),k=t4(n),T=EJ(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?cp:v.Fragment,B=y?{as:DJ,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=qJ(ue,P,V),J=(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),J&&setTimeout(()=>J.focus())};v.useEffect(()=>()=>window.clearTimeout(H.current),[]),Ix();const G=v.useCallback(te=>{var Y,ee;return O.current===((Y=z.current)==null?void 0:Y.side)&&YJ(te,(ee=z.current)==null?void 0:ee.area)},[]);return u.jsx(MJ,{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(lp,{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(ph,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:d,onPointerDownOutside:m,onFocusOutside:f,onInteractOutside:g,onDismiss:b,children:u.jsx(yJ,{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(Ux,{role:"menu","aria-orientation":"vertical","data-state":_4(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||!SJ.includes(te.key))return;te.preventDefault();const J=T().filter(ne=>!ne.disabled).map(ne=>ne.ref.current);J3.includes(te.key)&&J.reverse(),WJ(J)}),onBlur:rt(e.onBlur,te=>{te.currentTarget.contains(te.target)||(window.clearTimeout(H.current),M.current="")}),onPointerMove:rt(e.onPointerMove,Nm(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}}))})})})})})})});s4.displayName=Ts;var PJ="MenuGroup",aE=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(tn.div,{role:"group",...r,ref:t})});aE.displayName=PJ;var OJ="MenuLabel",o4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(tn.div,{...r,ref:t})});o4.displayName=OJ;var $b="MenuItem",rM="menu.itemSelect",Yx=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=v.useRef(null),o=vp($b,e.__scopeMenu),a=sE($b,e.__scopeMenu),c=xn(t,s),d=v.useRef(!1),m=()=>{const f=s.current;if(!n&&f){const g=new CustomEvent(rM,{bubbles:!0,cancelable:!0});f.addEventListener(rM,b=>r==null?void 0:r(b),{once:!0}),kO(f,g),g.defaultPrevented?d.current=!1:o.onClose()}};return u.jsx(a4,{...i,ref:c,disabled:n,onClick:rt(e.onClick,m),onPointerDown:f=>{var g;(g=e.onPointerDown)==null||g.call(e,f),d.current=!0},onPointerUp:rt(e.onPointerUp,f=>{var g;d.current||(g=f.currentTarget)==null||g.click()}),onKeyDown:rt(e.onKeyDown,f=>{const g=a.searchRef.current!=="";n||g&&f.key===" "||c1.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Yx.displayName=$b;var a4=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=sE($b,n),a=t4(n),c=v.useRef(null),d=xn(t,c),[m,f]=v.useState(!1),[g,b]=v.useState("");return v.useEffect(()=>{const y=c.current;y&&b((y.textContent??"").trim())},[s.children]),u.jsx(Em.ItemSlot,{scope:n,disabled:r,textValue:i??g,children:u.jsx(_J,{asChild:!0,...a,focusable:!r,children:u.jsx(tn.div,{role:"menuitem","data-highlighted":m?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:rt(e.onPointerMove,Nm(y=>{r?o.onItemLeave(y):(o.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:rt(e.onPointerLeave,Nm(y=>o.onItemLeave(y))),onFocus:rt(e.onFocus,()=>f(!0)),onBlur:rt(e.onBlur,()=>f(!1))})})})}),zJ="MenuCheckboxItem",l4=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return u.jsx(f4,{scope:e.__scopeMenu,checked:n,children:u.jsx(Yx,{role:"menuitemcheckbox","aria-checked":Hb(n)?"mixed":n,...i,ref:t,"data-state":cE(n),onSelect:rt(i.onSelect,()=>r==null?void 0:r(Hb(n)?!0:!n),{checkForDefaultPrevented:!1})})})});l4.displayName=zJ;var c4="MenuRadioGroup",[BJ,FJ]=yu(c4,{value:void 0,onValueChange:()=>{}}),u4=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=no(r);return u.jsx(BJ,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(aE,{...i,ref:t})})});u4.displayName=c4;var d4="MenuRadioItem",h4=v.forwardRef((e,t)=>{const{value:n,...r}=e,i=FJ(d4,e.__scopeMenu),s=n===i.value;return u.jsx(f4,{scope:e.__scopeMenu,checked:s,children:u.jsx(Yx,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":cE(s),onSelect:rt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});h4.displayName=d4;var lE="MenuItemIndicator",[f4,$J]=yu(lE,{checked:!1}),m4=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=$J(lE,n);return u.jsx(Ps,{present:r||Hb(s.checked)||s.checked===!0,children:u.jsx(tn.span,{...i,ref:t,"data-state":cE(s.checked)})})});m4.displayName=lE;var HJ="MenuSeparator",p4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(tn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});p4.displayName=HJ;var UJ="MenuArrow",g4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Kx(n);return u.jsx(Vx,{...i,...r,ref:t})});g4.displayName=UJ;var VJ="MenuSub",[iAe,v4]=yu(VJ),Vf="MenuSubTrigger",b4=v.forwardRef((e,t)=>{const n=_u(Vf,e.__scopeMenu),r=vp(Vf,e.__scopeMenu),i=v4(Vf,e.__scopeMenu),s=sE(Vf,e.__scopeMenu),o=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:c}=s,d={__scopeMenu:e.__scopeMenu},m=v.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return v.useEffect(()=>m,[m]),v.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),c(null)}},[a,c]),u.jsx(rE,{asChild:!0,...d,children:u.jsx(a4,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":_4(n.open),...e,ref:Ak(t,i.onTriggerChange),onClick:f=>{var g;(g=e.onClick)==null||g.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:rt(e.onPointerMove,Nm(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),m()},100))})),onPointerLeave:rt(e.onPointerLeave,Nm(f=>{var b,y;m();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:f.clientX+C,y:f.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(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:rt(e.onKeyDown,f=>{var b;const g=s.searchRef.current!=="";e.disabled||g&&f.key===" "||CJ[r.dir].includes(f.key)&&(n.onOpenChange(!0),(b=n.content)==null||b.focus(),f.preventDefault())})})})});b4.displayName=Vf;var x4="MenuSubContent",y4=v.forwardRef((e,t)=>{const n=r4(Ts,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=_u(Ts,e.__scopeMenu),o=vp(Ts,e.__scopeMenu),a=v4(x4,e.__scopeMenu),c=v.useRef(null),d=xn(t,c);return u.jsx(Em.Provider,{scope:e.__scopeMenu,children:u.jsx(Ps,{present:r||s.open,children:u.jsx(Em.Slot,{scope:e.__scopeMenu,children:u.jsx(oE,{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:m=>{var f;o.isUsingKeyboardRef.current&&((f=c.current)==null||f.focus()),m.preventDefault()},onCloseAutoFocus:m=>m.preventDefault(),onFocusOutside:rt(e.onFocusOutside,m=>{m.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:rt(e.onEscapeKeyDown,m=>{o.onClose(),m.preventDefault()}),onKeyDown:rt(e.onKeyDown,m=>{var b;const f=m.currentTarget.contains(m.target),g=kJ[o.dir].includes(m.key);f&&g&&(s.onOpenChange(!1),(b=a.trigger)==null||b.focus(),m.preventDefault())})})})})})});y4.displayName=x4;function _4(e){return e?"open":"closed"}function Hb(e){return e==="indeterminate"}function cE(e){return Hb(e)?"indeterminate":e?"checked":"unchecked"}function WJ(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function GJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function qJ(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=GJ(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 KJ(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,m=a.y,f=c.x,g=c.y;m>r!=g>r&&n<(f-d)*(r-m)/(g-m)+d&&(i=!i)}return i}function YJ(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return KJ(n,t)}function Nm(e){return t=>t.pointerType==="mouse"?e(t):void 0}var XJ=n4,QJ=rE,ZJ=i4,JJ=s4,eee=aE,tee=o4,nee=Yx,ree=l4,iee=u4,see=h4,oee=m4,aee=p4,lee=g4,cee=b4,uee=y4,uE="ContextMenu",[dee]=Va(uE,[e4]),bi=e4(),[hee,w4]=dee(uE),S4=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:s=!0}=e,[o,a]=v.useState(!1),c=bi(t),d=no(r),m=v.useCallback(f=>{a(f),d(f)},[d]);return u.jsx(hee,{scope:t,open:o,onOpenChange:m,modal:s,children:u.jsx(XJ,{...c,dir:i,open:o,onOpenChange:m,modal:s,children:n})})};S4.displayName=uE;var C4="ContextMenuTrigger",k4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,disabled:r=!1,...i}=e,s=w4(C4,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),m=v.useCallback(()=>window.clearTimeout(d.current),[]),f=g=>{a.current={x:g.clientX,y:g.clientY},s.onOpenChange(!0)};return v.useEffect(()=>m,[m]),v.useEffect(()=>void(r&&m()),[r,m]),u.jsxs(u.Fragment,{children:[u.jsx(QJ,{...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=>{m(),f(g),g.preventDefault()}),onPointerDown:r?e.onPointerDown:rt(e.onPointerDown,Jg(g=>{m(),d.current=window.setTimeout(()=>f(g),700)})),onPointerMove:r?e.onPointerMove:rt(e.onPointerMove,Jg(m)),onPointerCancel:r?e.onPointerCancel:rt(e.onPointerCancel,Jg(m)),onPointerUp:r?e.onPointerUp:rt(e.onPointerUp,Jg(m))})]})});k4.displayName=C4;var fee="ContextMenuPortal",E4=e=>{const{__scopeContextMenu:t,...n}=e,r=bi(t);return u.jsx(ZJ,{...r,...n})};E4.displayName=fee;var N4="ContextMenuContent",T4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=w4(N4,n),s=bi(n),o=v.useRef(!1);return u.jsx(JJ,{...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)"}})});T4.displayName=N4;var mee="ContextMenuGroup",pee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(eee,{...i,...r,ref:t})});pee.displayName=mee;var gee="ContextMenuLabel",vee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(tee,{...i,...r,ref:t})});vee.displayName=gee;var bee="ContextMenuItem",R4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(nee,{...i,...r,ref:t})});R4.displayName=bee;var xee="ContextMenuCheckboxItem",yee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(ree,{...i,...r,ref:t})});yee.displayName=xee;var _ee="ContextMenuRadioGroup",wee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(iee,{...i,...r,ref:t})});wee.displayName=_ee;var See="ContextMenuRadioItem",Cee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(see,{...i,...r,ref:t})});Cee.displayName=See;var kee="ContextMenuItemIndicator",Eee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(oee,{...i,...r,ref:t})});Eee.displayName=kee;var Nee="ContextMenuSeparator",A4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(aee,{...i,...r,ref:t})});A4.displayName=Nee;var Tee="ContextMenuArrow",Ree=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(lee,{...i,...r,ref:t})});Ree.displayName=Tee;var Aee="ContextMenuSubTrigger",jee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(cee,{...i,...r,ref:t})});jee.displayName=Aee;var Mee="ContextMenuSubContent",Lee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(uee,{...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)"}})});Lee.displayName=Mee;function Jg(e){return t=>t.pointerType!=="mouse"?e(t):void 0}var Iee=S4,Dee=k4,Pee=E4,j4=T4,M4=R4,L4=A4;const I4=v.createContext(null);function wu({onOpenChange:e,...t}){const[n,r]=v.useState(0),i=v.useCallback(()=>{r(s=>s+1),e==null||e(!1)},[e]);return u.jsx(I4.Provider,{value:i,children:u.jsx(Iee,{onOpenChange:e,...t},n)})}const Su=Dee,tc=v.forwardRef(({className:e,...t},n)=>u.jsx(Pee,{children:u.jsx(j4,{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=j4.displayName;const In=v.forwardRef(({className:e,onSelect:t,...n},r)=>{const i=v.useContext(I4);return u.jsx(M4,{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=M4.displayName;const D4=v.forwardRef(({className:e,...t},n)=>u.jsx(L4,{ref:n,className:de("-mx-1 my-1 h-px bg-border",e),...t}));D4.displayName=L4.displayName;var Xx="Popover",[P4]=Va(Xx,[ec]),bp=ec(),[Oee,nc]=P4(Xx),O4=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,a=bp(t),c=v.useRef(null),[d,m]=v.useState(!1),[f,g]=qd({prop:r,defaultProp:i??!1,onChange:s,caller:Xx});return u.jsx(Hx,{...a,children:u.jsx(Oee,{scope:t,contentId:ja(),triggerRef:c,open:f,onOpenChange:g,onOpenToggle:v.useCallback(()=>g(b=>!b),[g]),hasCustomAnchor:d,onCustomAnchorAdd:v.useCallback(()=>m(!0),[]),onCustomAnchorRemove:v.useCallback(()=>m(!1),[]),modal:o,children:n})})};O4.displayName=Xx;var z4="PopoverAnchor",zee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=nc(z4,n),s=bp(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:a}=i;return v.useEffect(()=>(o(),()=>a()),[o,a]),u.jsx(hp,{...s,...r,ref:t})});zee.displayName=z4;var B4="PopoverTrigger",F4=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=nc(B4,n),s=bp(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":W4(i.open),...r,ref:o,onClick:rt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?a:u.jsx(hp,{asChild:!0,...s,children:a})});F4.displayName=B4;var dE="PopoverPortal",[Bee,Fee]=P4(dE,{forceMount:void 0}),$4=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=nc(dE,t);return u.jsx(Bee,{scope:t,forceMount:n,children:u.jsx(Ps,{present:n||s.open,children:u.jsx(gh,{asChild:!0,container:i,children:r})})})};$4.displayName=dE;var Xd="PopoverContent",H4=v.forwardRef((e,t)=>{const n=Fee(Xd,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=nc(Xd,e.__scopePopover);return u.jsx(Ps,{present:r||s.open,children:s.modal?u.jsx(Hee,{...i,ref:t}):u.jsx(Uee,{...i,ref:t})})});H4.displayName=Xd;var $ee=eu("PopoverContent.RemoveScroll"),Hee=v.forwardRef((e,t)=>{const n=nc(Xd,e.__scopePopover),r=v.useRef(null),i=xn(t,r),s=v.useRef(!1);return v.useEffect(()=>{const o=r.current;if(o)return Px(o)},[]),u.jsx(cp,{as:$ee,allowPinchZoom:!0,children:u.jsx(U4,{...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})})})}),Uee=v.forwardRef((e,t)=>{const n=nc(Xd,e.__scopePopover),r=v.useRef(!1),i=v.useRef(!1);return u.jsx(U4,{...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()}})}),U4=v.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:d,onInteractOutside:m,...f}=e,g=nc(Xd,n),b=bp(n);return Ix(),u.jsx(lp,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:u.jsx(ph,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:m,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:d,onDismiss:()=>g.onOpenChange(!1),children:u.jsx(Ux,{"data-state":W4(g.open),role:"dialog",id:g.contentId,...b,...f,ref:t,style:{...f.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)"}})})})}),V4="PopoverClose",Vee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=nc(V4,n);return u.jsx(tn.button,{type:"button",...r,ref:t,onClick:rt(e.onClick,()=>i.onOpenChange(!1))})});Vee.displayName=V4;var Wee="PopoverArrow",Gee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=bp(n);return u.jsx(Vx,{...i,...r,ref:t})});Gee.displayName=Wee;function W4(e){return e?"open":"closed"}var qee=O4,Kee=F4,Yee=$4,G4=H4;const rc=qee,ic=Kee,Ga=v.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},i)=>u.jsx(Yee,{children:u.jsx(G4,{ref:i,align:t,sideOffset:n,[_m]:"",onCloseAutoFocus:s=>{var o;s.preventDefault(),window.dispatchEvent(new Event(Ib)),(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})}));Ga.displayName=G4.displayName;function Xee({editorLabel:e,starred:t,onCopyPath:n,onShowArchived:r,onOpenInFinder:i,onOpenInEditor:s,onToggleStar:o,onHide:a,children:c}){return u.jsxs(wu,{children:[u.jsx(Su,{asChild:!0,children:c}),u.jsxs(tc,{children:[u.jsxs(In,{onSelect:d=>{d.stopPropagation(),o()},children:[t?u.jsx(Jq,{className:"h-3.5 w-3.5"}):u.jsx(oO,{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(yk,{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(jx,{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(_k,{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(WW,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Hide"})]})]})]})}function Qee({canFork:e,onRename:t,onOpenInFinder:n,onFork:r,onArchive:i,onDelete:s,onEditPermissions:o,children:a}){return u.jsxs(wu,{children:[u.jsx(Su,{asChild:!0,children:a}),u.jsxs(tc,{children:[u.jsxs(In,{onSelect:c=>{c.preventDefault(),t()},children:[u.jsx(mh,{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(jx,{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(sO,{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(kk,{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(yk,{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(bu,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Delete"})]})]})]})}function Zee({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(rc,{open:s,onOpenChange:o,children:[u.jsx(ic,{asChild:!0,children:i}),u.jsxs(Ga,{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(mh,{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(aO,{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(bu,{className:"h-3.5 w-3.5"}),u.jsxs("span",{children:["Delete ",e]})]})]})]})}function Jee({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){return u.jsxs(wu,{children:[u.jsx(Su,{asChild:!0,children:i}),u.jsxs(tc,{children:[u.jsxs(In,{onSelect:s=>{s.preventDefault(),t()},children:[u.jsx(mh,{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(aO,{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(bu,{className:"h-3.5 w-3.5"}),u.jsxs("span",{className:"text-xs font-medium",children:["Delete ",e]})]})]})]})}function ete(e){return e.status==="running"||e.status==="starting"?"warning":e.status==="waiting_for_user"?"info":e.status==="failed"?"destructive":e.unread?"success":null}function tte(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 nte(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 rte(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 ite({chat:e,activeChatId:t,nowMs:n,shortcutHint:r=null,showShortcutHint:i=!1,onSelectChat:s,onRenameChat:o,onOpenInFinder:a,onForkChat:c,onArchiveChat:d,onDeleteChat:m,onEditPermissions:f}){const g=(e.status==="running"||e.status==="waiting_for_user")&&e.stateEnteredAt!=null,b=g&&e.stateEnteredAt!=null?`${a1(e.status)} ${o1(n-e.stateEnteredAt)}`:qs(n-(e.lastMessageAt??e._creationTime)),y=i&&r?r:b,_=i&&!!r,w=lY(e.chatId),C=t===w,E=ete(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",tte(E))}):null}),(()=>{const R=rte(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(kk,{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(B3,{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?nte(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(Pe,{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(sO,{className:"size-3.5"})}):null,u.jsx(Pe,{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(yk,{className:"size-3.5"})})]})]})]},e._id);return u.jsx(Qee,{canFork:e.canFork,onRename:()=>o(e.chatId),onOpenInFinder:()=>a(e.localPath),onFork:()=>c(e.chatId),onArchive:()=>d(e.chatId),onDelete:()=>m(e.chatId),onEditPermissions:f?()=>f(e.chatId):void 0,children:T})}const ste=v.memo(ite);function ote(){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 Qx=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function xh(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function hE(e){return"nodeType"in e}function zi(e){var t,n;return e?xh(e)?e:hE(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function fE(e){const{Document:t}=zi(e);return e instanceof t}function xp(e){return xh(e)?!1:e instanceof zi(e).HTMLElement}function q4(e){return e instanceof zi(e).SVGElement}function yh(e){return e?xh(e)?e.document:hE(e)?fE(e)?e:xp(e)||q4(e)?e.ownerDocument:document:document:document}const Vo=Qx?v.useLayoutEffect:v.useEffect;function mE(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 ate(){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 Tm(e,t){t===void 0&&(t=[e]);const n=v.useRef(e);return Vo(()=>{n.current!==e&&(n.current=e)},t),n}function yp(e,t){const n=v.useRef();return v.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function Ub(e){const t=mE(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 u1(e){const t=v.useRef();return v.useEffect(()=>{t.current=e},[e]),t.current}let nw={};function _p(e,t){return v.useMemo(()=>{if(t)return t;const n=nw[e]==null?0:nw[e]+1;return nw[e]=n,e+"-"+n},[e,t])}function K4(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 m=s[c];m!=null&&(s[c]=m+e*d)}return s},{...t})}}const Pd=K4(1),Vb=K4(-1);function lte(e){return"clientX"in e&&"clientY"in e}function pE(e){if(!e)return!1;const{KeyboardEvent:t}=zi(e.target);return t&&e instanceof t}function cte(e){if(!e)return!1;const{TouchEvent:t}=zi(e.target);return t&&e instanceof t}function d1(e){if(cte(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 lte(e)?{x:e.clientX,y:e.clientY}:null}const Rm=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[Rm.Translate.toString(e),Rm.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),iM="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function ute(e){return e.matches(iM)?e:e.querySelector(iM)}const dte={display:"none"};function hte(e){let{id:t,value:n}=e;return _n.createElement("div",{id:t,style:dte},n)}function fte(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 _n.createElement("div",{id:t,style:i,role:"status","aria-live":r,"aria-atomic":!0},n)}function mte(){const[e,t]=v.useState("");return{announce:v.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const Y4=v.createContext(null);function pte(e){const t=v.useContext(Y4);v.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function gte(){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 vte={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(ro,{open:e,onOpenChange:T=>{T||s()},children:u.jsxs(js,{className:"max-w-2xl",children:[u.jsxs(io,{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(fi,{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:m,onChange:T=>f(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(Pe,{variant:"ghost",onClick:k,children:"Reset to defaults"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Pe,{variant:"ghost",onClick:s,children:"Cancel"}),u.jsx(Pe,{onClick:E,children:"Apply"})]})]})]})}),u.jsx(ro,{open:g,onOpenChange:T=>{T||(b(!1),_(null))},children:u.jsxs(js,{className:"max-w-md",children:[u.jsx(io,{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(Pe,{variant:"ghost",onClick:()=>{b(!1),_(null)},children:"Cancel"}),u.jsx(Pe,{variant:"destructive",onClick:()=>{y&&a(y),b(!1),_(null)},children:"Enable auto-allow"})]})]})})]})}const NZ={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:[]},dn=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}));dn.displayName="Input";const $3=v.createContext(null);function TZ({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})}),[]),m=v.useCallback(b=>new Promise(y=>{n({kind:"prompt",options:b,resolve:y})}),[]),f=v.useCallback(b=>new Promise(y=>{n({kind:"alert",options:b,resolve:y})}),[]),g=v.useMemo(()=>({confirm:d,prompt:m,alert:f}),[f,d,m]);return u.jsxs($3.Provider,{value:g,children:[e,u.jsx(ro,{open:t!==null,onOpenChange:b=>{b||!t||a()},children:u.jsx(js,{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(io,{children:t.options.title}),t.options.description?u.jsx(up,{children:t.options.description}):null,t.kind==="prompt"?u.jsx(dn,{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(Pe,{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(Pe,{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 mp(){const e=v.useContext($3);if(!e)throw new Error("useAppDialog must be used within AppDialogProvider");return e}const Yk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("bg-card text-card-foreground",e),...t}));Yk.displayName="Card";const Xk=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("flex flex-col space-y-1.5 p-2",e),...t}));Xk.displayName="CardHeader";const H3=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:de("text-2xl font-semibold leading-none tracking-tight",e),...t}));H3.displayName="CardTitle";const U3=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:de("text-sm text-muted-foreground",e),...t}));U3.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 RZ=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:de("flex items-center p-6 pt-0",e),...t}));RZ.displayName="CardFooter";const AZ={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 jZ({variant:e,children:t,dot:n=!0,className:r}){const i=AZ[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 MZ="modulepreload",LZ=function(e){return"/"+e},Xj={},X=function(t,n,r){let i=Promise.resolve();if(n&&n.length>0){let o=function(d){return Promise.all(d.map(m=>Promise.resolve(m).then(f=>({status:"fulfilled",value:f}),f=>({status:"rejected",reason:f}))))};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=LZ(d),d in Xj)return;Xj[d]=!0;const m=d.endsWith(".css"),f=m?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${f}`))return;const g=document.createElement("link");if(g.rel=m?"stylesheet":MZ,m||(g.as="script"),g.crossOrigin="",g.href=d,c&&g.setAttribute("nonce",c),document.head.appendChild(g),m)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)})},IZ=v.lazy(()=>X(()=>import("./index-BC-Tl-79.js"),[]).then(e=>({default:e.Toaster})));function DZ(){return u.jsx(v.Suspense,{fallback:null,children:u.jsx(IZ,{position:"bottom-right",theme:"system",closeButton:!0,duration:6e3})})}const PZ="0.97.2",OZ={version:PZ},Yn="Kanna",Qj="kanna",zZ=".kanna",BZ=".kanna-dev",FZ="KANNA_RUNTIME_PROFILE",Zk=`kanna/${OZ.version}`,$Z="[kanna]",HZ=`~/${Yn}`;function qx(){var t;return(t=globalThis.process)==null?void 0:t.env}function UZ(e=qx()){var t;return((t=e==null?void 0:e[FZ])==null?void 0:t.trim().toLowerCase())==="dev"?"dev":"prod"}function VZ(e=qx()){return UZ(e)==="dev"?BZ:zZ}function WZ(e=qx()){return`~/${VZ(e)}`}function GZ(e=qx()){return`${WZ(e)}/keybindings.json`}function Zg(e){return e?`${Qj} ${e}`:Qj}const Zj=e=>{let t;const n=new Set,r=(d,m)=>{const f=typeof d=="function"?d(t):d;if(!Object.is(f,t)){const g=t;t=m??(typeof f!="object"||f===null)?f:Object.assign({},t,f),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},qZ=(e=>e?Zj(e):Zj),KZ=e=>e;function YZ(e,t=KZ){const n=_n.useSyncExternalStore(e.subscribe,_n.useCallback(()=>t(e.getState()),[e,t]),_n.useCallback(()=>t(e.getInitialState()),[e,t]));return _n.useDebugValue(n),n}const Jj=e=>{const t=qZ(e),n=r=>YZ(t,r);return Object.assign(n,t),n},Oi=(e=>e?Jj(e):Jj),V3="always",W3="funk",XZ=[{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 QZ(e){switch(e){case"never":case"unfocused":case"always":return e;default:return V3}}function ZZ(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 W3}}const Vc=Oi()(e=>({chatSoundPreference:V3,chatSoundId:W3,setChatSoundPreference:t=>e({chatSoundPreference:QZ(t)}),setChatSoundId:t=>e({chatSoundId:ZZ(t)})})),JZ={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 eJ(e=document){return e.visibilityState!=="visible"||!e.hasFocus()}function tJ(e){const t=new Audio(JZ[e]);return t.preload="auto",t.play()}async function i1(e,t){if(t<=0)return;const n=Array.from({length:t},(r,i)=>new Promise(s=>{window.setTimeout(()=>{tJ(e).catch(()=>{}).finally(()=>s())},i*90)}));await Promise.all(n)}function nJ(e,t=document){return e==="never"?!1:e==="always"?!0:eJ(t)}function rJ(e){return e.projectGroups.reduce((t,n)=>t+n.chats.reduce((r,i)=>r+(i.unread?1:0)+(i.status==="waiting_for_user"?1:0),0),0)}function eM(e){let t=0;const n=new Set;for(const r of e.projectGroups)for(const i of r.chats)i.unread&&(t+=1),i.status==="waiting_for_user"&&n.add(i.chatId);return{unreadCount:t,waitingChatIds:n}}function iJ(e,t){if(!e)return 0;const n=eM(e),r=eM(t),i=Math.max(0,r.unreadCount-n.unreadCount);let s=0;for(const o of r.waitingChatIds)n.waitingChatIds.has(o)||(s+=1);return i+s}function s1(e){return e.split(/[\s_-]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}const sJ=[/^(?:\/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 G3(e){const t=e.trim();for(const n of sJ){const r=t.match(n);if(!r)continue;const i=(r[2]??r[1]??"").trim();if(i)return i}return t}function Jk(e){return e.split("/").pop()||e}const oJ=1440*6e4;function aJ(e,t){if(e===void 0)return null;const n=Math.max(0,t-e),r=6e4,i=60*r,s=oJ,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 lJ(e){return e.lastMessageAt??e._creationTime}const eE=1e3,ob=60*eE,Td=60*ob,ew=24*Td;function qs(e){const t=Math.max(0,e);if(t<ob)return`${Math.floor(t/eE)}s`;if(t<Td)return`${Math.floor(t/ob)}m`;if(t<ew){const i=Math.floor(t/Td),s=Math.floor(t%Td/ob);return s===0?`${i}h`:`${i}h ${s}m`}const n=Math.floor(t/ew),r=Math.floor(t%ew/Td);return r===0?`${n}d`:`${n}d ${r}h`}function o1(e){const t=Math.max(0,e);if(t>=Td)return qs(t);const n=Math.floor(t/eE),r=Math.floor(n/60),i=n%60;return`${r}:${i.toString().padStart(2,"0")}`}function a1(e){switch(e){case"idle":return"Idle";case"starting":return"Starting";case"running":return"Running";case"waiting_for_user":return"Waiting";case"failed":return"Failed"}}function tM(e){switch(e){case"running":return"active";case"waiting_for_user":return"attention";case"failed":return"destructive";case"idle":case"starting":default:return"muted"}}function nM(e){switch(e){case"active":return"text-emerald-500 dark:text-emerald-400";case"attention":return"text-amber-500 dark:text-amber-400";case"destructive":return"text-destructive";case"muted":default:return"text-muted-foreground"}}function tE(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=_n.useRef(null),k=_n.useRef(new Map).current;return u.jsx(i,{scope:w,itemMap:k,collectionRef:E,children:C})};o.displayName=t;const a=e+"CollectionSlot",c=eu(a),d=_n.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 m=e+"CollectionItemSlot",f="data-radix-collection-item",g=eu(m),b=_n.forwardRef((_,w)=>{const{scope:C,children:E,...k}=_,T=_n.useRef(null),R=xn(w,T),A=s(m,C);return _n.useEffect(()=>(A.itemMap.set(T,{ref:T,...k}),()=>void A.itemMap.delete(T))),u.jsx(g,{[f]:"",ref:R,children:E})});b.displayName=m;function y(_){const w=s(e+"CollectionConsumer",_);return _n.useCallback(()=>{const E=w.collectionRef.current;if(!E)return[];const k=Array.from(E.querySelectorAll(`[${f}]`));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 cJ=v.createContext(void 0);function nE(e){const t=v.useContext(cJ);return e||t||"ltr"}var tw="rovingFocusGroup.onEntryFocus",uJ={bubbles:!1,cancelable:!0},pp="RovingFocusGroup",[l1,q3,dJ]=tE(pp),[hJ,K3]=Va(pp,[dJ]),[fJ,mJ]=hJ(pp),Y3=v.forwardRef((e,t)=>u.jsx(l1.Provider,{scope:e.__scopeRovingFocusGroup,children:u.jsx(l1.Slot,{scope:e.__scopeRovingFocusGroup,children:u.jsx(pJ,{...e,ref:t})})}));Y3.displayName=pp;var pJ=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:s,currentTabStopId:o,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:d,preventScrollOnEntryFocus:m=!1,...f}=e,g=v.useRef(null),b=xn(t,g),y=nE(s),[_,w]=qd({prop:o,defaultProp:a??null,onChange:c,caller:pp}),[C,E]=v.useState(!1),k=no(d),T=q3(n),R=v.useRef(!1),[A,j]=v.useState(0);return v.useEffect(()=>{const L=g.current;if(L)return L.addEventListener(tw,k),()=>L.removeEventListener(tw,k)},[k]),u.jsx(fJ,{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,...f,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(tw,uJ);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);Z3($,m)}}R.current=!1}),onBlur:rt(e.onBlur,()=>E(!1))})})}),X3="RovingFocusGroupItem",Q3=v.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:s,children:o,...a}=e,c=ja(),d=s||c,m=mJ(X3,n),f=m.currentTabStopId===d,g=q3(n),{onFocusableItemAdd:b,onFocusableItemRemove:y,currentTabStopId:_}=m;return v.useEffect(()=>{if(r)return b(),()=>y()},[r,b,y]),u.jsx(l1.ItemSlot,{scope:n,id:d,focusable:r,active:i,children:u.jsx(tn.span,{tabIndex:f?0:-1,"data-orientation":m.orientation,...a,ref:t,onMouseDown:rt(e.onMouseDown,w=>{r?m.onItemFocus(d):w.preventDefault()}),onFocus:rt(e.onFocus,()=>m.onItemFocus(d)),onKeyDown:rt(e.onKeyDown,w=>{if(w.key==="Tab"&&w.shiftKey){m.onItemShiftTab();return}if(w.target!==w.currentTarget)return;const C=bJ(w,m.orientation,m.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=m.loop?xJ(k,T+1):k.slice(T+1)}setTimeout(()=>Z3(k))}}),children:typeof o=="function"?o({isCurrentTabStop:f,hasTabStop:_!=null}):o})})});Q3.displayName=X3;var gJ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function vJ(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function bJ(e,t,n){const r=vJ(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return gJ[r]}function Z3(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function xJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var yJ=Y3,_J=Q3,c1=["Enter"," "],wJ=["ArrowDown","PageUp","Home"],J3=["ArrowUp","PageDown","End"],SJ=[...wJ,...J3],CJ={ltr:[...c1,"ArrowRight"],rtl:[...c1,"ArrowLeft"]},kJ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},gp="Menu",[Em,EJ,NJ]=tE(gp),[yu,e4]=Va(gp,[NJ,ec,K3]),Kx=ec(),t4=K3(),[TJ,_u]=yu(gp),[RJ,vp]=yu(gp),n4=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,a=Kx(t),[c,d]=v.useState(null),m=v.useRef(!1),f=no(s),g=nE(i);return v.useEffect(()=>{const b=()=>{m.current=!0,document.addEventListener("pointerdown",y,{capture:!0,once:!0}),document.addEventListener("pointermove",y,{capture:!0,once:!0})},y=()=>m.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(Hx,{...a,children:u.jsx(TJ,{scope:t,open:n,onOpenChange:f,content:c,onContentChange:d,children:u.jsx(RJ,{scope:t,onClose:v.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:m,dir:g,modal:o,children:r})})})};n4.displayName=gp;var AJ="MenuAnchor",rE=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Kx(n);return u.jsx(hp,{...i,...r,ref:t})});rE.displayName=AJ;var iE="MenuPortal",[jJ,r4]=yu(iE,{forceMount:void 0}),i4=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=_u(iE,t);return u.jsx(jJ,{scope:t,forceMount:n,children:u.jsx(Ps,{present:n||s.open,children:u.jsx(gh,{asChild:!0,container:i,children:r})})})};i4.displayName=iE;var Ts="MenuContent",[MJ,sE]=yu(Ts),s4=v.forwardRef((e,t)=>{const n=r4(Ts,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=_u(Ts,e.__scopeMenu),o=vp(Ts,e.__scopeMenu);return u.jsx(Em.Provider,{scope:e.__scopeMenu,children:u.jsx(Ps,{present:r||s.open,children:u.jsx(Em.Slot,{scope:e.__scopeMenu,children:o.modal?u.jsx(LJ,{...i,ref:t}):u.jsx(IJ,{...i,ref:t})})})})}),LJ=v.forwardRef((e,t)=>{const n=_u(Ts,e.__scopeMenu),r=v.useRef(null),i=xn(t,r);return v.useEffect(()=>{const s=r.current;if(s)return Px(s)},[]),u.jsx(oE,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:rt(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),IJ=v.forwardRef((e,t)=>{const n=_u(Ts,e.__scopeMenu);return u.jsx(oE,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),DJ=eu("MenuContent.ScrollLock"),oE=v.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:a,onEntryFocus:c,onEscapeKeyDown:d,onPointerDownOutside:m,onFocusOutside:f,onInteractOutside:g,onDismiss:b,disableOutsideScroll:y,..._}=e,w=_u(Ts,n),C=vp(Ts,n),E=Kx(n),k=t4(n),T=EJ(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?cp:v.Fragment,B=y?{as:DJ,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=qJ(ue,P,V),J=(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),J&&setTimeout(()=>J.focus())};v.useEffect(()=>()=>window.clearTimeout(H.current),[]),Ix();const G=v.useCallback(te=>{var Y,ee;return O.current===((Y=z.current)==null?void 0:Y.side)&&YJ(te,(ee=z.current)==null?void 0:ee.area)},[]);return u.jsx(MJ,{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(lp,{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(ph,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:d,onPointerDownOutside:m,onFocusOutside:f,onInteractOutside:g,onDismiss:b,children:u.jsx(yJ,{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(Ux,{role:"menu","aria-orientation":"vertical","data-state":_4(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||!SJ.includes(te.key))return;te.preventDefault();const J=T().filter(ne=>!ne.disabled).map(ne=>ne.ref.current);J3.includes(te.key)&&J.reverse(),WJ(J)}),onBlur:rt(e.onBlur,te=>{te.currentTarget.contains(te.target)||(window.clearTimeout(H.current),M.current="")}),onPointerMove:rt(e.onPointerMove,Nm(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}}))})})})})})})});s4.displayName=Ts;var PJ="MenuGroup",aE=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(tn.div,{role:"group",...r,ref:t})});aE.displayName=PJ;var OJ="MenuLabel",o4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(tn.div,{...r,ref:t})});o4.displayName=OJ;var $b="MenuItem",rM="menu.itemSelect",Yx=v.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=v.useRef(null),o=vp($b,e.__scopeMenu),a=sE($b,e.__scopeMenu),c=xn(t,s),d=v.useRef(!1),m=()=>{const f=s.current;if(!n&&f){const g=new CustomEvent(rM,{bubbles:!0,cancelable:!0});f.addEventListener(rM,b=>r==null?void 0:r(b),{once:!0}),kO(f,g),g.defaultPrevented?d.current=!1:o.onClose()}};return u.jsx(a4,{...i,ref:c,disabled:n,onClick:rt(e.onClick,m),onPointerDown:f=>{var g;(g=e.onPointerDown)==null||g.call(e,f),d.current=!0},onPointerUp:rt(e.onPointerUp,f=>{var g;d.current||(g=f.currentTarget)==null||g.click()}),onKeyDown:rt(e.onKeyDown,f=>{const g=a.searchRef.current!=="";n||g&&f.key===" "||c1.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Yx.displayName=$b;var a4=v.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=sE($b,n),a=t4(n),c=v.useRef(null),d=xn(t,c),[m,f]=v.useState(!1),[g,b]=v.useState("");return v.useEffect(()=>{const y=c.current;y&&b((y.textContent??"").trim())},[s.children]),u.jsx(Em.ItemSlot,{scope:n,disabled:r,textValue:i??g,children:u.jsx(_J,{asChild:!0,...a,focusable:!r,children:u.jsx(tn.div,{role:"menuitem","data-highlighted":m?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:d,onPointerMove:rt(e.onPointerMove,Nm(y=>{r?o.onItemLeave(y):(o.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:rt(e.onPointerLeave,Nm(y=>o.onItemLeave(y))),onFocus:rt(e.onFocus,()=>f(!0)),onBlur:rt(e.onBlur,()=>f(!1))})})})}),zJ="MenuCheckboxItem",l4=v.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return u.jsx(f4,{scope:e.__scopeMenu,checked:n,children:u.jsx(Yx,{role:"menuitemcheckbox","aria-checked":Hb(n)?"mixed":n,...i,ref:t,"data-state":cE(n),onSelect:rt(i.onSelect,()=>r==null?void 0:r(Hb(n)?!0:!n),{checkForDefaultPrevented:!1})})})});l4.displayName=zJ;var c4="MenuRadioGroup",[BJ,FJ]=yu(c4,{value:void 0,onValueChange:()=>{}}),u4=v.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=no(r);return u.jsx(BJ,{scope:e.__scopeMenu,value:n,onValueChange:s,children:u.jsx(aE,{...i,ref:t})})});u4.displayName=c4;var d4="MenuRadioItem",h4=v.forwardRef((e,t)=>{const{value:n,...r}=e,i=FJ(d4,e.__scopeMenu),s=n===i.value;return u.jsx(f4,{scope:e.__scopeMenu,checked:s,children:u.jsx(Yx,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":cE(s),onSelect:rt(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});h4.displayName=d4;var lE="MenuItemIndicator",[f4,$J]=yu(lE,{checked:!1}),m4=v.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=$J(lE,n);return u.jsx(Ps,{present:r||Hb(s.checked)||s.checked===!0,children:u.jsx(tn.span,{...i,ref:t,"data-state":cE(s.checked)})})});m4.displayName=lE;var HJ="MenuSeparator",p4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return u.jsx(tn.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});p4.displayName=HJ;var UJ="MenuArrow",g4=v.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Kx(n);return u.jsx(Vx,{...i,...r,ref:t})});g4.displayName=UJ;var VJ="MenuSub",[iAe,v4]=yu(VJ),Vf="MenuSubTrigger",b4=v.forwardRef((e,t)=>{const n=_u(Vf,e.__scopeMenu),r=vp(Vf,e.__scopeMenu),i=v4(Vf,e.__scopeMenu),s=sE(Vf,e.__scopeMenu),o=v.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:c}=s,d={__scopeMenu:e.__scopeMenu},m=v.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);return v.useEffect(()=>m,[m]),v.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),c(null)}},[a,c]),u.jsx(rE,{asChild:!0,...d,children:u.jsx(a4,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":_4(n.open),...e,ref:Ak(t,i.onTriggerChange),onClick:f=>{var g;(g=e.onClick)==null||g.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:rt(e.onPointerMove,Nm(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!o.current&&(s.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{n.onOpenChange(!0),m()},100))})),onPointerLeave:rt(e.onPointerLeave,Nm(f=>{var b,y;m();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:f.clientX+C,y:f.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(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:rt(e.onKeyDown,f=>{var b;const g=s.searchRef.current!=="";e.disabled||g&&f.key===" "||CJ[r.dir].includes(f.key)&&(n.onOpenChange(!0),(b=n.content)==null||b.focus(),f.preventDefault())})})})});b4.displayName=Vf;var x4="MenuSubContent",y4=v.forwardRef((e,t)=>{const n=r4(Ts,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=_u(Ts,e.__scopeMenu),o=vp(Ts,e.__scopeMenu),a=v4(x4,e.__scopeMenu),c=v.useRef(null),d=xn(t,c);return u.jsx(Em.Provider,{scope:e.__scopeMenu,children:u.jsx(Ps,{present:r||s.open,children:u.jsx(Em.Slot,{scope:e.__scopeMenu,children:u.jsx(oE,{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:m=>{var f;o.isUsingKeyboardRef.current&&((f=c.current)==null||f.focus()),m.preventDefault()},onCloseAutoFocus:m=>m.preventDefault(),onFocusOutside:rt(e.onFocusOutside,m=>{m.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:rt(e.onEscapeKeyDown,m=>{o.onClose(),m.preventDefault()}),onKeyDown:rt(e.onKeyDown,m=>{var b;const f=m.currentTarget.contains(m.target),g=kJ[o.dir].includes(m.key);f&&g&&(s.onOpenChange(!1),(b=a.trigger)==null||b.focus(),m.preventDefault())})})})})})});y4.displayName=x4;function _4(e){return e?"open":"closed"}function Hb(e){return e==="indeterminate"}function cE(e){return Hb(e)?"indeterminate":e?"checked":"unchecked"}function WJ(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function GJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function qJ(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=GJ(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 KJ(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,m=a.y,f=c.x,g=c.y;m>r!=g>r&&n<(f-d)*(r-m)/(g-m)+d&&(i=!i)}return i}function YJ(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return KJ(n,t)}function Nm(e){return t=>t.pointerType==="mouse"?e(t):void 0}var XJ=n4,QJ=rE,ZJ=i4,JJ=s4,eee=aE,tee=o4,nee=Yx,ree=l4,iee=u4,see=h4,oee=m4,aee=p4,lee=g4,cee=b4,uee=y4,uE="ContextMenu",[dee]=Va(uE,[e4]),bi=e4(),[hee,w4]=dee(uE),S4=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:s=!0}=e,[o,a]=v.useState(!1),c=bi(t),d=no(r),m=v.useCallback(f=>{a(f),d(f)},[d]);return u.jsx(hee,{scope:t,open:o,onOpenChange:m,modal:s,children:u.jsx(XJ,{...c,dir:i,open:o,onOpenChange:m,modal:s,children:n})})};S4.displayName=uE;var C4="ContextMenuTrigger",k4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,disabled:r=!1,...i}=e,s=w4(C4,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),m=v.useCallback(()=>window.clearTimeout(d.current),[]),f=g=>{a.current={x:g.clientX,y:g.clientY},s.onOpenChange(!0)};return v.useEffect(()=>m,[m]),v.useEffect(()=>void(r&&m()),[r,m]),u.jsxs(u.Fragment,{children:[u.jsx(QJ,{...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=>{m(),f(g),g.preventDefault()}),onPointerDown:r?e.onPointerDown:rt(e.onPointerDown,Jg(g=>{m(),d.current=window.setTimeout(()=>f(g),700)})),onPointerMove:r?e.onPointerMove:rt(e.onPointerMove,Jg(m)),onPointerCancel:r?e.onPointerCancel:rt(e.onPointerCancel,Jg(m)),onPointerUp:r?e.onPointerUp:rt(e.onPointerUp,Jg(m))})]})});k4.displayName=C4;var fee="ContextMenuPortal",E4=e=>{const{__scopeContextMenu:t,...n}=e,r=bi(t);return u.jsx(ZJ,{...r,...n})};E4.displayName=fee;var N4="ContextMenuContent",T4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=w4(N4,n),s=bi(n),o=v.useRef(!1);return u.jsx(JJ,{...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)"}})});T4.displayName=N4;var mee="ContextMenuGroup",pee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(eee,{...i,...r,ref:t})});pee.displayName=mee;var gee="ContextMenuLabel",vee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(tee,{...i,...r,ref:t})});vee.displayName=gee;var bee="ContextMenuItem",R4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(nee,{...i,...r,ref:t})});R4.displayName=bee;var xee="ContextMenuCheckboxItem",yee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(ree,{...i,...r,ref:t})});yee.displayName=xee;var _ee="ContextMenuRadioGroup",wee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(iee,{...i,...r,ref:t})});wee.displayName=_ee;var See="ContextMenuRadioItem",Cee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(see,{...i,...r,ref:t})});Cee.displayName=See;var kee="ContextMenuItemIndicator",Eee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(oee,{...i,...r,ref:t})});Eee.displayName=kee;var Nee="ContextMenuSeparator",A4=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(aee,{...i,...r,ref:t})});A4.displayName=Nee;var Tee="ContextMenuArrow",Ree=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(lee,{...i,...r,ref:t})});Ree.displayName=Tee;var Aee="ContextMenuSubTrigger",jee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(cee,{...i,...r,ref:t})});jee.displayName=Aee;var Mee="ContextMenuSubContent",Lee=v.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,i=bi(n);return u.jsx(uee,{...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)"}})});Lee.displayName=Mee;function Jg(e){return t=>t.pointerType!=="mouse"?e(t):void 0}var Iee=S4,Dee=k4,Pee=E4,j4=T4,M4=R4,L4=A4;const I4=v.createContext(null);function wu({onOpenChange:e,...t}){const[n,r]=v.useState(0),i=v.useCallback(()=>{r(s=>s+1),e==null||e(!1)},[e]);return u.jsx(I4.Provider,{value:i,children:u.jsx(Iee,{onOpenChange:e,...t},n)})}const Su=Dee,tc=v.forwardRef(({className:e,...t},n)=>u.jsx(Pee,{children:u.jsx(j4,{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=j4.displayName;const In=v.forwardRef(({className:e,onSelect:t,...n},r)=>{const i=v.useContext(I4);return u.jsx(M4,{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=M4.displayName;const D4=v.forwardRef(({className:e,...t},n)=>u.jsx(L4,{ref:n,className:de("-mx-1 my-1 h-px bg-border",e),...t}));D4.displayName=L4.displayName;var Xx="Popover",[P4]=Va(Xx,[ec]),bp=ec(),[Oee,nc]=P4(Xx),O4=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=e,a=bp(t),c=v.useRef(null),[d,m]=v.useState(!1),[f,g]=qd({prop:r,defaultProp:i??!1,onChange:s,caller:Xx});return u.jsx(Hx,{...a,children:u.jsx(Oee,{scope:t,contentId:ja(),triggerRef:c,open:f,onOpenChange:g,onOpenToggle:v.useCallback(()=>g(b=>!b),[g]),hasCustomAnchor:d,onCustomAnchorAdd:v.useCallback(()=>m(!0),[]),onCustomAnchorRemove:v.useCallback(()=>m(!1),[]),modal:o,children:n})})};O4.displayName=Xx;var z4="PopoverAnchor",zee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=nc(z4,n),s=bp(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:a}=i;return v.useEffect(()=>(o(),()=>a()),[o,a]),u.jsx(hp,{...s,...r,ref:t})});zee.displayName=z4;var B4="PopoverTrigger",F4=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=nc(B4,n),s=bp(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":W4(i.open),...r,ref:o,onClick:rt(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?a:u.jsx(hp,{asChild:!0,...s,children:a})});F4.displayName=B4;var dE="PopoverPortal",[Bee,Fee]=P4(dE,{forceMount:void 0}),$4=e=>{const{__scopePopover:t,forceMount:n,children:r,container:i}=e,s=nc(dE,t);return u.jsx(Bee,{scope:t,forceMount:n,children:u.jsx(Ps,{present:n||s.open,children:u.jsx(gh,{asChild:!0,container:i,children:r})})})};$4.displayName=dE;var Xd="PopoverContent",H4=v.forwardRef((e,t)=>{const n=Fee(Xd,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,s=nc(Xd,e.__scopePopover);return u.jsx(Ps,{present:r||s.open,children:s.modal?u.jsx(Hee,{...i,ref:t}):u.jsx(Uee,{...i,ref:t})})});H4.displayName=Xd;var $ee=eu("PopoverContent.RemoveScroll"),Hee=v.forwardRef((e,t)=>{const n=nc(Xd,e.__scopePopover),r=v.useRef(null),i=xn(t,r),s=v.useRef(!1);return v.useEffect(()=>{const o=r.current;if(o)return Px(o)},[]),u.jsx(cp,{as:$ee,allowPinchZoom:!0,children:u.jsx(U4,{...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})})})}),Uee=v.forwardRef((e,t)=>{const n=nc(Xd,e.__scopePopover),r=v.useRef(!1),i=v.useRef(!1);return u.jsx(U4,{...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()}})}),U4=v.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:d,onInteractOutside:m,...f}=e,g=nc(Xd,n),b=bp(n);return Ix(),u.jsx(lp,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:u.jsx(ph,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:m,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:d,onDismiss:()=>g.onOpenChange(!1),children:u.jsx(Ux,{"data-state":W4(g.open),role:"dialog",id:g.contentId,...b,...f,ref:t,style:{...f.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)"}})})})}),V4="PopoverClose",Vee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=nc(V4,n);return u.jsx(tn.button,{type:"button",...r,ref:t,onClick:rt(e.onClick,()=>i.onOpenChange(!1))})});Vee.displayName=V4;var Wee="PopoverArrow",Gee=v.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,i=bp(n);return u.jsx(Vx,{...i,...r,ref:t})});Gee.displayName=Wee;function W4(e){return e?"open":"closed"}var qee=O4,Kee=F4,Yee=$4,G4=H4;const rc=qee,ic=Kee,Ga=v.forwardRef(({className:e,align:t="center",sideOffset:n=4,...r},i)=>u.jsx(Yee,{children:u.jsx(G4,{ref:i,align:t,sideOffset:n,[_m]:"",onCloseAutoFocus:s=>{var o;s.preventDefault(),window.dispatchEvent(new Event(Ib)),(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})}));Ga.displayName=G4.displayName;function Xee({editorLabel:e,starred:t,onCopyPath:n,onShowArchived:r,onOpenInFinder:i,onOpenInEditor:s,onToggleStar:o,onHide:a,children:c}){return u.jsxs(wu,{children:[u.jsx(Su,{asChild:!0,children:c}),u.jsxs(tc,{children:[u.jsxs(In,{onSelect:d=>{d.stopPropagation(),o()},children:[t?u.jsx(Jq,{className:"h-3.5 w-3.5"}):u.jsx(oO,{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(yk,{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(jx,{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(_k,{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(WW,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Hide"})]})]})]})}function Qee({canFork:e,onRename:t,onOpenInFinder:n,onFork:r,onArchive:i,onDelete:s,onEditPermissions:o,children:a}){return u.jsxs(wu,{children:[u.jsx(Su,{asChild:!0,children:a}),u.jsxs(tc,{children:[u.jsxs(In,{onSelect:c=>{c.preventDefault(),t()},children:[u.jsx(mh,{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(jx,{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(sO,{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(kk,{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(yk,{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(bu,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Delete"})]})]})]})}function Zee({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(rc,{open:s,onOpenChange:o,children:[u.jsx(ic,{asChild:!0,children:i}),u.jsxs(Ga,{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(mh,{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(aO,{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(bu,{className:"h-3.5 w-3.5"}),u.jsxs("span",{children:["Delete ",e]})]})]})]})}function Jee({stackTitle:e,onRename:t,onEditMembers:n,onDelete:r,children:i}){return u.jsxs(wu,{children:[u.jsx(Su,{asChild:!0,children:i}),u.jsxs(tc,{children:[u.jsxs(In,{onSelect:s=>{s.preventDefault(),t()},children:[u.jsx(mh,{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(aO,{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(bu,{className:"h-3.5 w-3.5"}),u.jsxs("span",{className:"text-xs font-medium",children:["Delete ",e]})]})]})]})}function ete(e){return e.status==="running"||e.status==="starting"?"warning":e.status==="waiting_for_user"?"info":e.status==="failed"?"destructive":e.unread?"success":null}function tte(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 nte(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 rte(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 ite({chat:e,activeChatId:t,nowMs:n,shortcutHint:r=null,showShortcutHint:i=!1,onSelectChat:s,onRenameChat:o,onOpenInFinder:a,onForkChat:c,onArchiveChat:d,onDeleteChat:m,onEditPermissions:f}){const g=(e.status==="running"||e.status==="waiting_for_user")&&e.stateEnteredAt!=null,b=g&&e.stateEnteredAt!=null?`${a1(e.status)} ${o1(n-e.stateEnteredAt)}`:qs(n-(e.lastMessageAt??e._creationTime)),y=i&&r?r:b,_=i&&!!r,w=lY(e.chatId),C=t===w,E=ete(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",tte(E))}):null}),(()=>{const R=rte(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(kk,{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(B3,{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?nte(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(Pe,{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(sO,{className:"size-3.5"})}):null,u.jsx(Pe,{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(yk,{className:"size-3.5"})})]})]})]},e._id);return u.jsx(Qee,{canFork:e.canFork,onRename:()=>o(e.chatId),onOpenInFinder:()=>a(e.localPath),onFork:()=>c(e.chatId),onArchive:()=>d(e.chatId),onDelete:()=>m(e.chatId),onEditPermissions:f?()=>f(e.chatId):void 0,children:T})}const ste=v.memo(ite);function ote(){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 Qx=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function xh(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function hE(e){return"nodeType"in e}function zi(e){var t,n;return e?xh(e)?e:hE(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function fE(e){const{Document:t}=zi(e);return e instanceof t}function xp(e){return xh(e)?!1:e instanceof zi(e).HTMLElement}function q4(e){return e instanceof zi(e).SVGElement}function yh(e){return e?xh(e)?e.document:hE(e)?fE(e)?e:xp(e)||q4(e)?e.ownerDocument:document:document:document}const Vo=Qx?v.useLayoutEffect:v.useEffect;function mE(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 ate(){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 Tm(e,t){t===void 0&&(t=[e]);const n=v.useRef(e);return Vo(()=>{n.current!==e&&(n.current=e)},t),n}function yp(e,t){const n=v.useRef();return v.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function Ub(e){const t=mE(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 u1(e){const t=v.useRef();return v.useEffect(()=>{t.current=e},[e]),t.current}let nw={};function _p(e,t){return v.useMemo(()=>{if(t)return t;const n=nw[e]==null?0:nw[e]+1;return nw[e]=n,e+"-"+n},[e,t])}function K4(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 m=s[c];m!=null&&(s[c]=m+e*d)}return s},{...t})}}const Pd=K4(1),Vb=K4(-1);function lte(e){return"clientX"in e&&"clientY"in e}function pE(e){if(!e)return!1;const{KeyboardEvent:t}=zi(e.target);return t&&e instanceof t}function cte(e){if(!e)return!1;const{TouchEvent:t}=zi(e.target);return t&&e instanceof t}function d1(e){if(cte(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 lte(e)?{x:e.clientX,y:e.clientY}:null}const Rm=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[Rm.Translate.toString(e),Rm.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),iM="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function ute(e){return e.matches(iM)?e:e.querySelector(iM)}const dte={display:"none"};function hte(e){let{id:t,value:n}=e;return _n.createElement("div",{id:t,style:dte},n)}function fte(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 _n.createElement("div",{id:t,style:i,role:"status","aria-live":r,"aria-atomic":!0},n)}function mte(){const[e,t]=v.useState("");return{announce:v.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const Y4=v.createContext(null);function pte(e){const t=v.useContext(Y4);v.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function gte(){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 vte={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,10 +2632,10 @@ XID_Start XIDS`.split(/\s/).map(e=>[fy(e),e])),Qle=new Map([["s",wr(383)],[wr(38
2632
2632
  `});++r<e.length;)r&&n.push({type:"text",value:`
2633
2633
  `}),n.push(e[r]);return t&&e.length>0&&n.push({type:"text",value:`
2634
2634
  `}),n}function CI(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function kI(e,t){const n=Sve(e,t),r=n.one(e,void 0),i=_ve(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 Tve(e,t){return e&&"run"in e?async function(n,r){const i=kI(n,{file:r,...t});await e.run(i,r)}:function(n,r){return kI(n,{file:r,...e||t})}}function EI(e){if(e)throw e}var Yw,NI;function Rve(){if(NI)return Yw;NI=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 m=e.call(d,"constructor"),f=d.constructor&&d.constructor.prototype&&e.call(d.constructor.prototype,"isPrototypeOf");if(d.constructor&&!m&&!f)return!1;var g;for(g in d);return typeof g>"u"||e.call(d,g)},o=function(d,m){n&&m.name==="__proto__"?n(d,m.name,{enumerable:!0,configurable:!0,value:m.newValue,writable:!0}):d[m.name]=m.newValue},a=function(d,m){if(m==="__proto__")if(e.call(d,m)){if(r)return r(d,m).value}else return;return d[m]};return Yw=function c(){var d,m,f,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(m in d)f=a(_,m),g=a(d,m),_!==g&&(E&&g&&(s(g)||(b=i(g)))?(b?(b=!1,y=f&&i(f)?f:[]):y=f&&s(f)?f:{},o(_,{name:m,newValue:c(E,y,g)})):typeof g<"u"&&o(_,{name:m,newValue:g}));return _},Yw}var Ave=Rve();const Xw=kx(Ave);function aC(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 jve(){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 m=e[++s];let f=-1;if(c){o(c);return}for(;++f<i.length;)(d[f]===null||d[f]===void 0)&&(d[f]=i[f]);i=d,m?Mve(m,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 Mve(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 m=d;if(a&&n)throw m;return i(m)}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:Lve,dirname:Ive,extname:Dve,join:Pve,sep:"/"};function Lve(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');Rp(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 Ive(e){if(Rp(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 Dve(e){Rp(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 Pve(...e){let t=-1,n;for(;++t<e.length;)Rp(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":Ove(n)}function Ove(e){Rp(e);const t=e.codePointAt(0)===47;let n=zve(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function zve(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 Rp(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const Bve={cwd:Fve};function Fve(){return"/"}function lC(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function $ve(e){if(typeof e=="string")e=new URL(e);else if(!lC(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 Hve(e)}function Hve(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 Qw=["history","path","basename","stem","extname","dirname"];class oF{constructor(t){let n;t?lC(t)?n={path:t}:typeof t=="string"||Uve(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":Bve.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<Qw.length;){const s=Qw[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)Qw.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?Ro.basename(this.path):void 0}set basename(t){Jw(t,"basename"),Zw(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){TI(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(Zw(t,"extname"),TI(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){lC(t)&&(t=$ve(t)),Jw(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){Jw(t,"stem"),Zw(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 ii(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 Zw(e,t){if(e&&e.includes(Ro.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+Ro.sep+"`")}function Jw(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function TI(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function Uve(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Vve=(function(e){const r=this.constructor.prototype,i=r[e],s=function(){return i.apply(s,arguments)};return Object.setPrototypeOf(s,r),s}),Wve={}.hasOwnProperty;class b2 extends Vve{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=jve()}copy(){const t=new b2;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(Xw(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(nS("data",this.frozen),this.namespace[t]=n,this):Wve.call(this.namespace,t)&&this.namespace[t]||void 0:t?(nS("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=Ev(t),r=this.parser||this.Parser;return eS("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),eS("process",this.parser||this.Parser),tS("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(s,o){const a=Ev(t),c=r.parse(a);r.run(c,a,function(m,f,g){if(m||!f||!g)return d(m);const b=f,y=r.stringify(b,g);Kve(y)?g.value=y:g.result=y,d(m,g)});function d(m,f){m||!f?o(m):s?s(f):n(void 0,f)}}}processSync(t){let n=!1,r;return this.freeze(),eS("processSync",this.parser||this.Parser),tS("processSync",this.compiler||this.Compiler),this.process(t,i),AI("processSync","process",n),r;function i(s,o){n=!0,EI(s),r=o}}run(t,n,r){RI(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=Ev(n);i.run(t,c,d);function d(m,f,g){const b=f||t;m?a(m):o?o(b):r(void 0,b,g)}}}runSync(t,n){let r=!1,i;return this.run(t,n,s),AI("runSync","run",r),i;function s(o,a){EI(o),i=a,r=!0}}stringify(t,n){this.freeze();const r=Ev(n),i=this.compiler||this.Compiler;return tS("stringify",i),RI(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(nS("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[m,...f]=d;c(m,f)}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=Xw(!0,i.settings,d.settings))}function a(d){let m=-1;if(d!=null)if(Array.isArray(d))for(;++m<d.length;){const f=d[m];s(f)}else throw new TypeError("Expected a list of plugins, not `"+d+"`")}function c(d,m){let f=-1,g=-1;for(;++f<r.length;)if(r[f][0]===d){g=f;break}if(g===-1)r.push([d,...m]);else if(m.length>0){let[b,...y]=m;const _=r[g][1];aC(_)&&aC(b)&&(b=Xw(!0,_,b)),r[g]=[d,b,...y]}}}}const Gve=new b2().freeze();function eS(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function tS(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function nS(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 RI(e){if(!aC(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function AI(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function Ev(e){return qve(e)?e:new oF(e)}function qve(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function Kve(e){return typeof e=="string"||Yve(e)}function Yve(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Xve="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",jI=[],MI={allowDangerousHtml:!0},Qve=/^(https?|ircs?|mailto|xmpp)$/i,Zve=[{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=Jve(e),n=ebe(e);return tbe(t.runSync(t.parse(n),n),e)}function Jve(e){const t=e.rehypePlugins||jI,n=e.remarkPlugins||jI,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...MI}:MI;return Gve().use(Hge).use(n).use(Tve,r).use(t)}function ebe(e){const t=e.children||"",n=new oF;return typeof t=="string"&&(n.value=t),n}function tbe(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,s=t.disallowedElements,o=t.skipHtml,a=t.unwrapDisallowed,c=t.urlTransform||nbe;for(const m of Zve)Object.hasOwn(t,m.from)&&(""+m.from+(m.to?"use `"+m.to+"` instead":"remove it")+Xve+m.id,void 0);return r2(e,d),Xpe(e,{Fragment:u.Fragment,components:i,ignoreInvalidStyle:!0,jsx:u.jsx,jsxs:u.jsxs,passKeys:!0,passNode:!0});function d(m,f,g){if(m.type==="raw"&&g&&typeof f=="number")return o?g.children.splice(f,1):g.children[f]={type:"text",value:m.value},f;if(m.type==="element"){let b;for(b in Kw)if(Object.hasOwn(Kw,b)&&Object.hasOwn(m.properties,b)){const y=m.properties[b],_=Kw[b];(_===null||_.includes(m.tagName))&&(m.properties[b]=c(String(y||""),b,m))}}if(m.type==="element"){let b=n?!n.includes(m.tagName):s?s.includes(m.tagName):!1;if(!b&&r&&typeof f=="number"&&(b=!r(m,f,g)),b&&g&&typeof f=="number")return a&&m.children?g.children.splice(f,1,...m.children):g.children.splice(f,1),f}}}function nbe(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||Qve.test(e.slice(0,t))?e:""}const Nv=new Map;function rbe(e){return`${e.id}|${e.contentUrl}|${e.size??0}`}function wy(e){const t=rbe(e),n=Nv.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(Nv.get(t)??{status:"loading"})),v.useEffect(()=>{if(n&&n.status!=="loading")return;let c=!1;const d=t;return t2(e.contentUrl,rB).then(m=>{if(c||a.current!==d)return;const f={status:"ready",content:m.content,truncated:m.truncated};Nv.set(d,f),i(f)}).catch(m=>{if(c||a.current!==d)return;const g={status:"error",message:m instanceof Error?m.message:"Unable to load preview."};Nv.set(d,g),i(g)}),()=>{c=!0}},[n,t,e.contentUrl]),r}function ibe({source:e}){const t=wy(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 Tv=new Map;function sbe(e){return`${e.id}|${e.contentUrl}|${e.size??0}|${e.mimeType}`}function obe({source:e}){const t=sbe(e),n=Tv.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(Tv.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 t2(e.contentUrl,rB).then(_=>{if(b||a.current!==y)return;const w={status:"ready",table:Ode(_.content,g),truncated:_.truncated};Tv.set(y,w),i(w)}).catch(_=>{if(b||a.current!==y)return;const w={status:"error",message:_ instanceof Error?_.message:"Unable to load preview."};Tv.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,...m]=c.rows,f=[r.truncated?"Preview truncated to 1024 KB.":null,c.truncatedRows?`Showing first ${c.rows.length} of ${c.rowCount} rows.`:null,c.truncatedColumns?`Showing first ${J1} of ${c.columnCount} columns.`:null].filter(Boolean);return u.jsxs("div",{className:"space-y-2 p-3",children:[f.length?u.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:f.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:m.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 abe({source:e}){const t=wy(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(lbe,{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 lbe({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 cbe({source:e}){const t=wy(e),n=v.useMemo(()=>t.status==="ready"?Pde(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 ube({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 dbe({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 hbe=200*1024;function fbe(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 mbe({source:e}){const t=wy(e),n=t.status==="ready"&&t.content.length<=hbe,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(()=>K8),void 0).then(async c=>{if(o)return;const d=await c.codeToHtml(t.content,{lang:fbe(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 pbe(e){var r;const t=vbe(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 gbe(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 vbe(e){return typeof window>"u"?e:new URL(e,document.baseURI||window.location.href).toString()}function jh({source:e,open:t,onOpenChange:n}){const r=v.useCallback(()=>n(!1),[n]);return u.jsx(ro,{open:t&&e!==null,onOpenChange:n,children:u.jsx(js,{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(_be,{source:e,onClose:r}):null})})}const bbe=120,xbe=.5;function ybe({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>bbe||a>xbe}function _be({source:e,onClose:t}){const n=Sbe(e),[r,i]=v.useState(0),s=v.useRef(null),o=v.useCallback(f=>{s.current={y:f.clientY,lastY:f.clientY,lastT:Date.now()};try{f.currentTarget.setPointerCapture(f.pointerId)}catch{}},[]),a=v.useCallback(f=>{if(!s.current)return;const g=f.clientY-s.current.y;g<0||(s.current.lastY=f.clientY,s.current.lastT=Date.now(),i(g))},[]),c=v.useCallback(f=>{const g=s.current;s.current=null;try{f.currentTarget.releasePointerCapture(f.pointerId)}catch{}g&&(ybe({startY:g.y,lastY:g.lastY,lastT:g.lastT,endY:f.clientY,now:Date.now()})?t():i(0))},[t]),d=v.useCallback(()=>{pbe(e)},[e]),m=v.useCallback(()=>gbe(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(io,{className:"truncate text-base",children:e.displayName}),u.jsx(up,{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(wbe(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(Pe,{type:"button",variant:"outline",onClick:d,children:[u.jsx(Fq,{className:"mr-2 h-4 w-4"}),"Share"]}),e.origin==="offer_download"?u.jsxs(Pe,{type:"button",onClick:m,children:[u.jsx(wk,{className:"mr-2 h-4 w-4"}),"Download"]}):null]})]})}function wbe(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=Rh(t);return n==="image"?Dpe:n==="pdf"?aI:n==="audio"?ube:n==="video"?dbe:n==="table"?obe:n==="markdown"?ibe:n==="json"?cbe:n==="code"?mbe:Th(t).kind==="external"?aI:abe}function Sbe(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=Rh(t),r=gy(n,e.mimeType),i=e.size?` · ${Mh(e.size)}`:"";return`${r}${i}`}function Ap(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 Cbe(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function kbe({path:e,linkText:t}){const n=v.useMemo(()=>c2(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=Cbe(e),c=t||a,d=Ipe(c,28),m=r.kind==="ready"?r.mimeType:"application/octet-stream",f=r.kind==="ready"?r.size:0,g={id:`local-file-${n}`,kind:"file",displayName:d,absolutePath:e,relativePath:e,contentUrl:n,mimeType:m,size:f};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=Rh(g),y=gy(b,m),_=f>0?Mh(f):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"?Th(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(jh,{source:s?Ap(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 Ebe(e,t){var n,r,i,s,o,a,c,d,m,f,g;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}},openrouter:{...e.providerDefaults.openrouter,...(c=t.providerDefaults)==null?void 0:c.openrouter,modelOptions:{}}},cloudflareTunnel:{...e.cloudflareTunnel,...t.cloudflareTunnel},claudeAuth:{tokens:((d=t.claudeAuth)==null?void 0:d.tokens)??e.claudeAuth.tokens,concurrencyDefault:((m=t.claudeAuth)==null?void 0:m.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,...(g=t.claudeDriver)==null?void 0:g.lifecycle}},globalPromptAppend:t.globalPromptAppend??e.globalPromptAppend}}const ji=Oi()(e=>({settings:null,hydrationStatus:"idle",setHydrationStatus:t=>e({hydrationStatus:t}),setFromServer:t=>e({settings:t,hydrationStatus:"ready"}),applyOptimisticPatch:t=>e(n=>({settings:n.settings?Ebe(n.settings,t):n.settings}))})),Nbe=[],Tbe=e=>{var t;return((t=e.settings)==null?void 0:t.customMcpServers)??Nbe},aF=v.createContext(void 0),Rbe=e=>e==="light"||e==="dark"||e==="system";function Abe(e){return e==="dark"?"black-translucent":"default"}function LI(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 II(e){if(typeof document>"u"||typeof window>"u")return;const t=getComputedStyle(document.body).backgroundColor||getComputedStyle(document.documentElement).backgroundColor;t&&LI("theme-color",t),LI("apple-mobile-web-app-status-bar-style",Abe(e)),document.documentElement.style.colorScheme=e}const vb=()=>typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",DI=e=>{if(typeof document>"u")return;const t=e==="system"?vb():e;document.documentElement.classList.toggle("dark",t==="dark")},jbe=()=>{var t;const e=(t=ji.getState().settings)==null?void 0:t.theme;return e&&Rbe(e)?e:"system"};function Mbe({children:e}){const t=ji(o=>{var a;return(a=o.settings)==null?void 0:a.theme}),n=ji(o=>o.applyOptimisticPatch),[r,i]=v.useState(jbe);v.useEffect(()=>{!t||t===r||i(t)},[t,r]),v.useEffect(()=>{DI(r)},[r]),v.useEffect(()=>{const o=r==="system"?vb():r;II(o)},[r]),v.useEffect(()=>{if(r!=="system")return;const o=window.matchMedia("(prefers-color-scheme: dark)"),a=()=>{DI("system"),II(vb())};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"?vb():r;return{theme:r,resolvedTheme:o,setTheme:a=>{i(a),n({theme:a})}}},[n,r]);return u.jsx(aF.Provider,{value:s,children:e})}function Sy(){const e=v.useContext(aF);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}function Lbe({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})},m=g=>{o&&s({x:g.clientX-o.x,y:g.clientY-o.y})},f=()=>a(null);return es.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(Pe,{variant:"ghost",size:"icon","aria-label":"Zoom out",className:"h-9 w-9",onClick:()=>r(g=>c(g-.25)),children:u.jsx(nO,{className:"h-4 w-4"})}),u.jsx(Pe,{variant:"ghost",size:"icon","aria-label":"Zoom in",className:"h-9 w-9",onClick:()=>r(g=>c(g+.25)),children:u.jsx(to,{className:"h-4 w-4"})}),u.jsx(Pe,{variant:"ghost",size:"icon","aria-label":"Reset view",className:"h-9 w-9",onClick:()=>{r(1),s({x:0,y:0})},children:u.jsx(kq,{className:"h-4 w-4"})}),u.jsx(Pe,{variant:"ghost",size:"icon","aria-label":"Close",className:"h-9 w-9",onClick:t,children:u.jsx(Ds,{className:"h-4 w-4"})})]}),u.jsx("div",{className:"flex-1 overflow-hidden touch-none cursor-grab active:cursor-grabbing",onPointerDown:d,onPointerMove:m,onPointerUp:f,onPointerLeave:f,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 rS=null;function Ibe(){return rS||(rS=X(()=>import("./mermaid.core-GVOEJSwQ.js").then(e=>e.bm),[]).then(e=>e.default)),rS}function Dbe({source:e}){const{resolvedTheme:t}=Sy(),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,m]=v.useState(!1),[f,g]=v.useState(!1),b=v.useCallback(()=>m(!1),[]),y=async()=>{await navigator.clipboard.writeText(e),g(!0),setTimeout(()=>g(!1),2e3)};return v.useEffect(()=>{let _=!1;return Ibe().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(iS,{source:e}):r.status==="loading"?u.jsx("div",{className:"relative group/mermaid",children:u.jsx(iS,{source:e})}):a?u.jsxs("div",{className:"relative group/mermaid",children:[u.jsx(iS,{source:e}),u.jsx(PI,{showSource:a,onToggleSource:()=>c(_=>!_),onCopy:y,copied:f,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(PI,{showSource:a,onToggleSource:()=>c(_=>!_),onCopy:y,copied:f,onZoom:()=>m(!0)}),d&&u.jsx(Lbe,{svg:r.svg,onClose:b})]})}function PI({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(Pe,{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(XG,{className:"h-4 w-4"})}),u.jsx(Pe,{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(KS,{className:"h-4 w-4"})}),u.jsx(Pe,{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(rs,{className:"h-4 w-4 text-success"}):u.jsx(Da,{className:"h-4 w-4"})})]})}const Pbe=200*1024,Obe={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 zbe(e){return Obe[e.toLowerCase()]??null}const Bbe=/^<pre[^>]*>/,Fbe=/<\/pre>\s*$/,$be=/^<code[^>]*>/,Hbe=/<\/code>\s*$/;function Ube(e){return e.replace(Bbe,"").replace(Fbe,"").replace($be,"").replace(Hbe,"")}function qf({source:e,lang:t}){const{resolvedTheme:n}=Sy(),r=n==="dark"?"github-dark":"github-light",i=zbe(t),s=i!==null&&e.length<=Pbe,[o,a]=v.useState(null);v.useEffect(()=>{if(!s||i===null)return;let m=!1;return X(()=>Promise.resolve().then(()=>K8),void 0).then(async f=>{if(m)return;const g=await f.codeToHtml(e,{lang:i,theme:r});m||a({source:e,theme:r,lang:i,html:Ube(g)})}).catch(()=>{typeof console<"u"&&console.warn("[transcript] Shiki unavailable; falling back to plain code")}),()=>{m=!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 lF={readonly:!1,localLinkMode:"open"},cF=v.createContext(lF);function Vbe({children:e,value:t}){return u.jsx(cF.Provider,{value:{...lF,...t},children:e})}function Cy(){return v.useContext(cF)}const uF=()=>{},Wbe=v.createContext(uF);function dF({children:e,onOpenLocalLink:t}){return u.jsx(Wbe.Provider,{value:t??uF,children:e})}const cC={Task:jb,TaskOutput:jb,Bash:Mx,Glob:Ld,Grep:Ld,ExitPlanMode:uj,Read:X5,Edit:nG,Write:iG,Delete:dG,NotebookEdit:mh,WebFetch:JV,TodoWrite:vW,WebSearch:Ld,KillShell:Qq,AskUserQuestion:eO,Skill:Wq,EnterPlanMode:uj},hF=aK;function fF(e){return cC[e]?cC[e]:hF}function mF({icon:e,className:t}){return u.jsx(e,{className:t})}function Ka({children:e,className:t}){return u.jsx("div",{className:de("flex gap-3 justify-start items-center",t),children:e})}function pF({children:e,className:t}){return u.jsx("div",{className:de("flex items-center gap-1.5 text-xs",t),children:e})}function lu({children:e,className:t}){return u.jsx("span",{className:de("font-medium text-foreground/80",t),children:e})}function Gbe({children:e}){return u.jsx("span",{className:"text-muted-foreground",children:e})}function qbe({children:e,className:t}){return u.jsxs(Ka,{className:de("px-0.5 text-xs tracking-wide",t),children:[u.jsx("div",{className:"w-full h-[1px] bg-border"}),u.jsx(lu,{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 x2({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(As,{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 uC({label:e,children:t,copyText:n}){const[r,i]=v.useState(!1),s=n??rh(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(Pe,{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(rs,{className:"h-3.5 w-3.5 text-success"}):u.jsx(Da,{className:"h-4 w-4"})})]})]})}function gF({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 ky({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 rh(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(Array.isArray(e))return e.map(rh).join("");if(e&&typeof e=="object"&&"props"in e){const t=e.props;return rh(t.children)}return""}function OI(e,t){return v.isValidElement(e)?v.cloneElement(e,{className:de(e.props.className,t)}):e}function vF({children:e,...t}){const[n,r]=v.useState(!1),i=rh(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(Pe,{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(rs,{className:"h-4 w-4 text-success"}):u.jsx(Da,{className:"h-4 w-4"})})]})}function iS({source:e}){return u.jsx(vF,{children:u.jsx("code",{className:"block text-xs whitespace-pre language-mermaid",children:e})})}const y2={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:vF,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(Dbe,{source:rh(e)});const s=i.find(a=>a.startsWith("language-")),o=s?s.slice(9):"";return o?u.jsx(qf,{source:rh(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]=OI(r,"mt-0"));const i=n.length-1,s=n[i];return s!==void 0&&(n[i]=OI(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"&&Lpe(e)?c2(e):e;return u.jsx("img",{src:n,...t})}};function Kbe({children:e,href:t,onClick:n,...r}){const i=Cy(),s=Ape(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=dC(e).trim();return u.jsx(kbe,{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 Ybe(){return{...y2,a:e=>u.jsx(Kbe,{...e})}}const Fa=[VB],$a=Ybe();function dC(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(dC).join(""):v.isValidElement(e)?dC(e.props.children):""}({...y2});function _2({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",m=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(Y5,{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," · ",Mh(e.size)]})]})]}),m?u.jsx(lB,{progress:o??null,onCancel:a,size:d?"sm":"md",cancelLabel:`Cancel upload of ${e.displayName}`}):null,r&&!m?u.jsx(bF,{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:m}){const f=e.kind==="mention"?"text":Rh(e),g=Zbe(f),b=e.kind==="mention",y=b?Xbe(e.displayName):e.displayName,_=b?Qbe(e.displayName):"",w=i!==void 0,C=!!m,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"}):m?u.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:m}):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," · ",Mh(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(mF,{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(lB,{progress:i??null,onCancel:s,size:"sm",cancelLabel:`Cancel upload of ${e.displayName}`}):null,n&&!w?u.jsx(bF,{displayName:e.displayName,onRemove:n}):null]})}function Xbe(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function Qbe(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function bF({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(Ds,{className:"h-3.5 w-3.5"})})}function Zbe(e){switch(e){case"image":return Y5;case"pdf":return wq;case"markdown":return jq;case"json":return YW;case"table":return oG;case"code":return QW;case"text":return Ax;case"archive":return qW;case"audio":return JW;case"video":return cG;default:return X5}}function Mh(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 Rv={};function zI(e){return!e.isCollapsed&&!e.hasPreviewAttachment&&e.patch===void 0&&e.patchError===void 0&&!e.isPatchLoading}function Jbe(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 xF(e){return e.isUntracked}function exe(e){return xF(e)?e.path.includes("/"):!1}function sS(e){return u.jsxs(Di,{delayDuration:0,children:[u.jsx(Pi,{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 yF({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(nO,{className:"h-3 w-3",strokeWidth:3}):e?u.jsx(rs,{className:"h-3 w-3",strokeWidth:3}):null})}function w2(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 txe(e){return e?`Last fetched ${w2(e)}`:"No local fetch recorded"}function nxe({entry:e,isPendingPush:t=!1}){const n=w2(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(Gd,{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(Gd,{className:"size-3"})})}):null]})}function BI(e){switch(e.kind){case"local":return 0;case"pull_request":return 1;case"remote":default:return 2}}function rxe(e){const t=new Map;for(const n of e){const r=t.get(n.name);(!r||BI(n)<BI(r))&&t.set(n.name,n)}return t}function ixe(e,t){const n=rxe([...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 sxe({open:e,onOpenChange:t,onGetGitHubPublishInfo:n,onCheckGitHubRepoAvailability:r,onPublish:i}){const[s,o]=v.useState(null),[a,c]=v.useState(!1),[d,m]=v.useState(""),[f,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),m(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=f.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,f,r,e,d]);async function j(){if(!(!d.trim()||!f.trim())){A(!0);try{const H=await i({owner:d.trim(),name:f.trim(),visibility:b,description:_});H!=null&&H.ok&&t(!1)}finally{A(!1)}}}const L=!!(s!=null&&s.ghInstalled&&s.authenticated&&d.trim()&&f.trim()&&(C!=null&&C.available)&&!k&&!R);return u.jsx(ro,{open:e,onOpenChange:t,children:u.jsxs(js,{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(io,{children:"Push to GitHub"}),u.jsx(up,{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:m,children:[u.jsx(Ys,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:u.jsx(Ca,{placeholder:"Select owner"})}),u.jsx(Xs,{children:((s==null?void 0:s.owners)??[]).map(H=>u.jsx(Jr,{value:H,children:u.jsxs("span",{className:"flex items-center gap-2",children:[H===(s==null?void 0:s.activeAccountLogin)?u.jsx(Lx,{className:"size-4 text-muted-foreground"}):u.jsx(fW,{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(dn,{value:f,onChange:H=>g(H.target.value),placeholder:"my-repo",className:"pl-9 pr-10"}),u.jsx(fq,{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(Di,{delayDuration:0,children:[u.jsx(Pi,{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(rs,{className:"size-4"}):u.jsx(ym,{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(Ax,{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(Ys,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:u.jsx(Ca,{placeholder:"Select visibility"})}),u.jsxs(Xs,{children:[u.jsx(Jr,{value:"private",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(GG,{className:"size-4 text-muted-foreground"}),u.jsx("span",{className:"pl-[1px]",children:"Private"})]})}),u.jsx(Jr,{value:"public",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(RG,{className:"size-4 text-muted-foreground"}),u.jsx("span",{className:"pl-[1px]",children:"Public"})]})})]})]})})]})]}),u.jsxs(Yl,{children:[u.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),u.jsx(Pe,{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 _F({value:e,onChange:t,placeholder:n,disabled:r,trailingAction:i}){return u.jsxs("div",{className:"relative",children:[u.jsx(Ld,{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(dn,{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 Kc({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(J5,{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:w2(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 oxe({open:e,onOpenChange:t,branchList:n,currentBranchName:r,onPreviewMergeBranch:i,onMergeBranch:s}){const[o,a]=v.useState(""),[c,d]=v.useState(null),[m,f]=v.useState(null),[g,b]=v.useState(null),[y,_]=v.useState(!1),[w,C]=v.useState(!1),E=v.useMemo(()=>n?ixe(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),f(null),b(null),_(!1),C(!1))},[e]),v.useEffect(()=>{if(!e||!L){f(null),b(null),_(!1);return}let D=!1;return f(null),b(null),_(!0),i(L).then(z=>{D||f(z)}).catch(z=>{D||b(z instanceof Error?z.message:String(z))}).finally(()=>{D||_(!1)}),()=>{D=!0}},[i,e,L]);const H=!L||!m||y||w||m.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(ro,{open:e,onOpenChange:t,children:u.jsxs(js,{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(io,{children:["Merge into ",r??"current branch"]}),u.jsx(up,{children:"Choose a branch to continue."})]}),u.jsx(_F,{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(Kc,{title:"Default Branch",entries:R?[R]:[],emptyLabel:"No default branch available.",selectedName:c,onSelect:D=>d(D.name)}),u.jsx(Kc,{title:"Recent Branches",entries:A,emptyLabel:"No recent branches.",selectedName:c,onSelect:D=>d(D.name)}),u.jsx(Kc,{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}):m?u.jsxs("div",{className:"flex items-start gap-2",children:[m.status==="up_to_date"?u.jsx(rs,{className:"mt-1 size-3.5 shrink-0 text-success"}):m.status==="conflicts"?u.jsx(ym,{className:"mt-1 size-3.5 shrink-0 text-warning"}):m.status==="mergeable"?u.jsx(Z5,{className:"mt-1 size-3.5 shrink-0 text-muted-foreground"}):u.jsx(ym,{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:m.message}),m.detail?u.jsx("div",{className:"line-clamp-2 whitespace-pre-wrap text-xs text-muted-foreground",children:m.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(Pe,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),u.jsx(Pe,{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 axe({currentBranchName:e,onListBranches:t,onPreviewMergeBranch:n,onMergeBranch:r,onCheckoutBranch:i,onCreateBranch:s}){const[o,a]=v.useState(!1),[c,d]=v.useState(!1),[m,f]=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&&(f(!0),R(null),t().then(G=>k(G)).catch(G=>{R(G instanceof Error?G.message:String(G))}).finally(()=>{f(!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(rc,{open:o,onOpenChange:a,children:[u.jsx(ic,{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(fh,{className:"h-3.5 w-3.5 shrink-0"})]})}),u.jsx(Ga,{align:"start",className:"w-[320px] p-2",children:u.jsxs("div",{className:"space-y-2",children:[u.jsx(_F,{value:y,onChange:_,placeholder:w==="pull_requests"?"Search pull requests":"Search branches",disabled:m||g,trailingAction:u.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>void B(),disabled:m||g,className:"h-7 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:"+ New"})}),u.jsx(fi,{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:m?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(Kc,{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(Kc,{title:"Recent",entries:M,emptyLabel:"No recent branches.",disabled:g,stickyTitle:!0,onSelect:G=>{$(G)}}),u.jsx(Kc,{title:"Local",entries:D,emptyLabel:"No local branches.",disabled:g,stickyTitle:!0,onSelect:G=>{$(G)}}),u.jsx(Kc,{title:"Remote",entries:z,emptyLabel:"No remote branches.",disabled:g,stickyTitle:!0,onSelect:G=>{$(G)}})]})}),L?u.jsx(Pe,{variant:"default",size:"sm",disabled:m||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(CG,{className:"mr-1.5 inline h-3.5 w-3.5 shrink-0"}),"Merge branch into ",L,"..."]})}):null]})}),u.jsx(oxe,{open:c,onOpenChange:d,branchList:E,currentBranchName:L,onPreviewMergeBranch:n,onMergeBranch:r})]})}function lxe({file:e,rootRef:t,projectId:n,isCollapsed:r,isChecked:i,editorLabel:s,diffRenderMode:o,wrapLines:a,onToggleCollapsed:c,onToggleChecked:d,fileActions:m,patch:f,patchError:g,isPatchLoading:b,onLoadPatch:y}){const _=xF(e),w=exe(e),[C,E]=v.useState(null),k=v.useRef(null),T=v.useRef(null),{sentinelRef:R,isStuck:A}=Ede({rootRef:t,disabled:r}),j=v.useMemo(()=>Jbe(n,e),[e,n]),L=j!==null,H=zI({isCollapsed:r,hasPreviewAttachment:L,patch:f,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(Th(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||f!==void 0){c();return}if(b)return;if(!(g!==void 0||zI({isCollapsed:!1,hasPreviewAttachment:L,patch:f,patchError:g,isPatchLoading:b}))){c();return}y(e.path).then(()=>{c()}).catch(()=>{})}return u.jsxs(wu,{children:[u.jsx(Su,{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(yF,{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(xm,{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(fh,{className:"h-3.5 w-3.5 shrink-0"}):u.jsx(q5,{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(_2,{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}):f!==void 0?u.jsx(Cde,{patch:f,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(jh,{source:j&&C===j.id?Ap(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(),m.onOpenFile(e.path)},children:[u.jsx(_k,{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(),m.onOpenInFinder(e.path)},children:[u.jsx(jx,{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(),m.onDiscardFile(e.path)},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[u.jsx(bu,{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(),_&&m.onIgnoreFile(e.path)},children:[u.jsx(oj,{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&&m.onIgnoreFolder(e.path)},children:[u.jsx(oj,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Ignore folder..."})]}),u.jsx(D4,{}),u.jsxs(In,{onSelect:O=>{O.stopPropagation(),m.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(),m.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 cxe({projectId:e,diffs:t,editorLabel:n,diffRenderMode:r,wrapLines:i,onOpenFile:s,onOpenInFinder:o,onDiscardFile:a,onIgnoreFile:c,onIgnoreFolder:d,onCopyFilePath:m,onCopyRelativePath:f,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:m,onCopyRelativePath:f}),[s,o,a,c,d,m,f]),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,J]=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]),Ce=Ai(_e=>{var Oe;return e?((Oe=_e.projectUi[e])==null?void 0:Oe.viewMode)??(z?"changes":"history"):z?"changes":"history"}),ke=Ai(_e=>{var Oe;return e?((Oe=_e.projectUi[e])==null?void 0:Oe.collapsedPaths)??Rv:Rv}),ze=Ai(_e=>{var Oe;return e?((Oe=_e.projectUi[e])==null?void 0:Oe.summary)??"":""}),Ze=Ai(_e=>{var Oe;return e?((Oe=_e.projectUi[e])==null?void 0:Oe.description)??"":""}),lt=Ai(_e=>_e.reconcileCollapsedPaths),Mt=Ai(_e=>_e.toggleCollapsedPath),ye=Ai(_e=>_e.setViewMode),ln=Ai(_e=>_e.setCommitDraft),jt=Ai(_e=>_e.clearCommitDraft),_t=_v(_e=>e?_e.checkedPathsByProjectId[e]??Rv:Rv),ft=_v(_e=>_e.reconcileProject),Ot=_v(_e=>_e.setChecked),It=_v(_e=>_e.setAllChecked),it=v.useRef(z);v.useEffect(()=>{e&&lt(e,le)},[le,oe,e,lt]),v.useEffect(()=>{const _e=Object.fromEntries(t.files.map(Ue=>[Ue.path,Ue.patchDigest])),Oe=Ue=>ie.current[Ue]===_e[Ue];ee(Ue=>Object.fromEntries(Object.entries(Ue).filter(([Ve])=>le.includes(Ve)&&Oe(Ve)))),ue(Ue=>Object.fromEntries(Object.entries(Ue).filter(([Ve])=>le.includes(Ve)&&Oe(Ve)))),J(Ue=>Object.fromEntries(Object.entries(Ue).filter(([Ve])=>le.includes(Ve)&&Oe(Ve)))),ie.current=_e},[t.files,le,oe]),v.useEffect(()=>{e&&ft(e,le)},[le,oe,e,ft]),v.useEffect(()=>{if(!e)return;if(it.current!==z){ye(e,z?"changes":"history"),it.current=z;return}it.current=z},[z,e,ye]);const Dt=v.useMemo(()=>t.files.filter(_e=>_t[_e.path]??!0).map(_e=>_e.path),[_t,t.files]),fe=Dt.length,Ae=t.files.length>0&&fe===t.files.length,He=fe>0&&fe<t.files.length,Je=ze.trim(),qe=Je.length>0,bt=$!==null,wt=O||bt,Tt=((Xe=t.branchHistory)==null?void 0:Xe.entries)??[],Ne=t.behindCount??0,De=t.aheadCount??0,Be=t.hasUpstream===!0,Ye=t.hasUpstream===!1&&!!t.branchName,ct=t.hasOriginRemote===!0,nn=t.branchName?t.branchName.split("/").map(_e=>encodeURIComponent(_e)).join("/"):null,Qt=Ye?"publish":Ne>0?"pull":"fetch",Ut=t.originRepoSlug&&nn?`https://github.com/${t.originRepoSlug}/compare/${nn}?expand=1`:null,Rt=!!(Be&&Ut&&t.branchName&&t.branchName!==t.defaultBranchName),xt=t.status==="ready"&&fe>0&&!wt,mt=t.status==="ready"&&fe>0&&qe&&!wt,Ct=ct?"commit_and_push":"commit_only",pt=t.branchName??"current branch";async function $t(_e){if(mt){B(_e);try{const Oe=await A({paths:Dt,summary:Je,description:Ze.trim(),mode:_e});(Oe!=null&&Oe.ok||Oe!=null&&Oe.localCommitCreated)&&e&&jt(e)}finally{B(null)}}}async function nt(){if(xt){F(!0);try{const _e=await C({paths:Dt});e&&ln(e,{summary:_e.subject,description:_e.body})}finally{F(!1)}}}function we(_e){if(!(!(_e.metaKey||_e.ctrlKey)||_e.key!=="Enter")){if(_e.preventDefault(),qe){$t(Ct);return}nt()}}async function tt(_e=Qt){if(!(t.status!=="ready"||U)){G(!0);try{await j(_e)}finally{G(!1)}}}const Ge=v.useCallback(async _e=>{var Oe;if(Y[_e]!==void 0||ge[_e])return Y[_e]??"";J(Ue=>({...Ue,[_e]:!0})),ue(Ue=>{if(!(_e in Ue))return Ue;const{[_e]:Ve,...Vt}=Ue;return Vt});try{const Ue=await L(_e);ee(Vt=>({...Vt,[_e]:Ue}));const Ve=(Oe=t.files.find(Vt=>Vt.path===_e))==null?void 0:Oe.patchDigest;return Ve&&(ie.current={...ie.current,[_e]:Ve}),Ue}catch(Ue){const Ve=Ue instanceof Error?Ue.message:String(Ue);throw ue(Vt=>({...Vt,[_e]:Ve})),Ue}finally{J(Ue=>{const{[_e]:Ve,...Vt}=Ue;return Vt})}},[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(axe,{currentBranchName:t.branchName,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:y,onCheckoutBranch:_,onCreateBranch:w})}),t.status==="ready"?ct?Qt==="publish"?u.jsxs(Pe,{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(nb,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Publish Branch"})]}):u.jsxs("div",{className:"flex items-center gap-1",children:[Qt==="fetch"?u.jsxs(Di,{delayDuration:0,children:[u.jsx(Pi,{asChild:!0,children:u.jsxs(Pe,{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(iO,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Fetch"})]})}),u.jsx(vi,{children:txe(t.lastFetchedAt)})]}):u.jsxs(Pe,{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(wk,{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:Ne})]}),Be&&De>0?u.jsxs(Pe,{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(nb,{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:De})]}):null,Rt&&Ut?u.jsxs(Pe,{variant:"ghost",size:"sm",onClick:()=>{typeof window>"u"||window.open(Ut,"_blank","noopener,noreferrer")},className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[u.jsx(J5,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"PR"})]}):null]}):u.jsxs(Pe,{variant:"default",size:"sm",onClick:()=>P(!0),className:"h-7 gap-1.5 px-3 text-xs",children:[u.jsx(NG,{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:[Ce==="changes"?u.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground/70",children:[u.jsx(yF,{checked:Ae,mixed:He,label:He?"Select all files for commit":Ae?"Unselect all files from commit":"Select all files for commit",onClick:()=>{!e||t.files.length===0||It(e,le,He?!0:!Ae)}}),u.jsxs("span",{children:[fe," 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(fi,{value:Ce,onValueChange:_e=>{e&&ye(e,_e)},size:"sm",optionClassName:"flex-1 justify-center",options:[{value:"changes",label:"Changes"},{value:"history",label:"History"}]})})}),Ce==="changes"?u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(sS,{label:"Unified diff",active:r==="unified",onClick:()=>H("unified"),children:u.jsx(Rq,{className:"h-4 w-4"})}),u.jsx(sS,{label:"Side-by-side diff",active:r==="split",onClick:()=>H("split"),children:u.jsx(LW,{className:"h-4 w-4"})}),u.jsx(sS,{label:i?"Disable word wrap":"Enable word wrap",active:i,onClick:()=>M(!i),children:u.jsx(sK,{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(Pe,{size:"sm",onClick:()=>void E(),children:"Init Git"})]})}):Ce==="history"?Tt.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:Tt.map((_e,Oe)=>u.jsx(nxe,{entry:_e,isPendingPush:Oe<De},_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 Oe=ke[_e.path]??!0,Ue=_t[_e.path]??!0;return u.jsx(lxe,{file:_e,rootRef:ne,projectId:e,isCollapsed:Oe,isChecked:Ue,editorLabel:n,diffRenderMode:r,wrapLines:i,onToggleCollapsed:()=>{e&&Mt(e,_e.path)},onToggleChecked:()=>{e&&Ot(e,_e.path,!Ue)},fileActions:D,patch:Y[_e.path],patchError:V[_e.path],isPatchLoading:!!ge[_e.path],onLoadPatch:Ge},_e.path)}),Ce==="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(dn,{value:ze,onChange:_e=>{e&&ln(e,{summary:_e.target.value,description:Ze})},onKeyDown:we,placeholder:"Commit message (override)",className:"rounded-t-xl rounded-b-none px-3",disabled:wt||t.status!=="ready"}),u.jsx(La,{value:Ze,onChange:_e=>{e&&ln(e,{summary:ze,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:wt||t.status!=="ready"}),u.jsx("div",{className:"w-full flex flex-row",children:u.jsxs(wu,{children:[u.jsx(Su,{asChild:!0,children:u.jsx(Pe,{type:"button",className:"-mt-px w-full rounded-xl",disabled:qe?!mt:!xt,onClick:()=>{if(qe){$t(Ct);return}nt()},children:u.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[qe?bt?u.jsx(bn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):Ct==="commit_and_push"?t.hasUpstream?u.jsx(nb,{strokeWidth:2.5,className:"size-3 shrink-0"}):u.jsx(Z5,{strokeWidth:2.5,className:"size-3 shrink-0"}):u.jsx(rs,{strokeWidth:2.5,className:"size-3 shrink-0"}):O?u.jsx(bn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):u.jsx(dq,{strokeWidth:2.5,className:"size-3 shrink-0"}),u.jsx("span",{className:"min-w-0 truncate text-left",children:qe?bt?$==="commit_only"?"Committing...":"Committing & Pushing...":Ct==="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:!qe||!mt,onSelect:_e=>{_e.stopPropagation(),$t("commit_only")},children:"Commit Only"})}):null]})})]})})]}):null]})})]}),u.jsx(sxe,{open:te,onOpenChange:P,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:T,onPublish:R})]})})}const uxe=v.memo(cxe);function dxe(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function hxe(e,t){const n=getComputedStyle(e.ownerDocument.body),r=parseFloat(n.fontSize);return t*r}function fxe(e){return e/100*window.innerHeight}function mxe(e){return e/100*window.innerWidth}function pxe(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 Kf({groupSize:e,panelElement:t,styleProp:n}){let r;const[i,s]=pxe(n);switch(s){case"%":{r=i/100*e;break}case"px":{r=i;break}case"rem":{r=hxe(t,i);break}case"em":{r=dxe(t,i);break}case"vh":{r=fxe(i);break}case"vw":{r=mxe(i);break}}return r}function Li(e){return parseFloat(e.toFixed(3))}function ih({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 hC(e){const{panels:t}=e,n=ih({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 m=Kf({groupSize:n,panelElement:i,styleProp:s.collapsedSize});o=Li(m/n*100)}let a;if(s.defaultSize!==void 0){const m=Kf({groupSize:n,panelElement:i,styleProp:s.defaultSize});a=Li(m/n*100)}let c=0;if(s.minSize!==void 0){const m=Kf({groupSize:n,panelElement:i,styleProp:s.minSize});c=Li(m/n*100)}let d=100;if(s.maxSize!==void 0){const m=Kf({groupSize:n,panelElement:i,styleProp:s.maxSize});d=Li(m/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 An(e,t="Assertion error"){if(!e)throw Error(t)}function fC(e,t){return Array.from(t).sort(e==="horizontal"?gxe:vxe)}function gxe(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function vxe(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function wF(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function SF(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 bxe({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}=SF(r,o),d=e==="horizontal"?a:c;d<s&&(s=d,i=o)}return An(i,"No rect found"),i}let Av;function xxe(){return Av===void 0&&(typeof matchMedia=="function"?Av=!!matchMedia("(pointer:coarse)").matches:Av=!1),Av}function CF(e){const{element:t,orientation:n,panels:r,separators:i}=e,s=fC(n,Array.from(t.children).filter(wF).map(y=>({element:y}))).map(({element:y})=>y),o=[];let a=!1,c=!1,d=-1,m=-1,f=0,g,b=[];{let y=-1;for(const _ of s)_.hasAttribute("data-panel")&&(y++,_.ariaDisabled===null&&(f++,d===-1&&(d=y),m=y))}if(f>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=bxe({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=xxe()?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>m;!a&&!j&&o.push({group:e,groupSize:ih({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,_5;let kF=(_5=class{constructor(){Sl(this,Fl,{})}addListener(t,n){const r=vr(this,Fl)[t];return r===void 0?vr(this,Fl)[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=vr(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(){ps(this,Fl,{})}removeListener(t,n){const r=vr(this,Fl)[t];if(r!==void 0){const i=r.indexOf(n);i>=0&&r.splice(i,1)}}},Fl=new WeakMap,_5),Oo=new Map;const EF=new kF;function yxe(e){Oo=new Map(Oo),Oo.delete(e)}function FI(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 ku(){return Oo}function S2(e,t){return EF.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),EF.emit("groupChange",{group:e,prev:n,next:t})}function _xe(e,t,n){let r,i={x:1/0,y:1/0};for(const s of t){const o=SF(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 wxe(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function Sxe(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:UI(e),b:UI(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();An(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:HI($I(n.a)),b:HI($I(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 Cxe=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function kxe(e){const t=getComputedStyle(NF(e)??e).display;return t==="flex"||t==="inline-flex"}function Exe(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||kxe(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"||Cxe.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function $I(e){let t=e.length;for(;t--;){const n=e[t];if(An(n,"Missing node"),Exe(n))return n}return null}function HI(e){return e&&Number(getComputedStyle(e).zIndex)||0}function UI(e){const t=[];for(;e;)t.push(e),e=NF(e);return t}function NF(e){const{parentNode:t}=e;return wxe(t)?t.host:t}function Nxe(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 Txe({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!wF(n)||n.contains(e)||e.contains(n))return!0;if(Sxe(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(Nxe(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function C2(e,t){const n=[];return t.forEach((r,i)=>{if(i.disabled)return;const s=CF(i),o=_xe(i.orientation,s,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&Txe({groupElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&n.push(o.hitRegion)}),n}function Rxe(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function di(e,t,n=0){return Math.abs(Li(e)-Li(t))<=n}function Ao(e,t){return di(e,t)?0:e>t?1:-1}function Ad({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=Li(r),r}function Ym({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(di(e,0))return t;const o=s==="imperative-api",a=Object.values(t),c=Object.values(i),d=[...a],[m,f]=r;An(m!=null,"Invalid first pivot index"),An(f!=null,"Invalid second pivot index");let g=0;switch(s){case"keyboard":{{const _=e<0?f:m,w=n[_];An(w,`Panel constraints not found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const T=a[_];if(An(T!=null,`Previous layout not found for panel index ${_}`),di(T,C)){const R=k-T;Ao(R,Math.abs(e))>0&&(e=e<0?0-R:R)}}}{const _=e<0?m:f,w=n[_];An(w,`No panel constraints found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const T=a[_];if(An(T!=null,`Previous layout not found for panel index ${_}`),di(T,k)){const R=T-C;Ao(R,Math.abs(e))>0&&(e=e<0?0-R:R)}}}break}default:{const _=e<0?f:m,w=n[_];An(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?f:m,C=0;for(;;){const k=a[w];An(k!=null,`Previous layout not found for panel index ${w}`);const T=Ad({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?m:f;for(;_>=0&&_<n.length;){const w=Math.abs(e)-Math.abs(g),C=a[_];An(C!=null,`Previous layout not found for panel index ${_}`);const E=C-w,k=Ad({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:C,size:E});if(!di(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(Rxe(c,d))return i;{const _=e<0?f:m,w=a[_];An(w!=null,`Previous layout not found for panel index ${_}`);const C=w+g,E=Ad({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:w,size:C});if(d[_]=E,!di(E,C)){let k=C-E,T=e<0?f:m;for(;T>=0&&T<n.length;){const R=d[T];An(R!=null,`Previous layout not found for panel index ${T}`);const A=R+k,j=Ad({overrideDisabledPanels:o,panelConstraints:n[T],prevSize:R,size:A});if(di(R,j)||(k-=j-R,d[T]=j),di(k,0))break;e>0?T--:T++}}}const b=Object.values(d).reduce((_,w)=>w+_,0);if(!di(b,100,.1))return i;const y=Object.keys(i);return d.reduce((_,w,C)=>(_[y[C]]=w,_),{})}function cu(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 uu({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(!di(i,100)&&r.length>0)for(let a=0;a<t.length;a++){const c=r[a];An(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];An(c!=null,`No layout data found for index ${a}`);const d=r[a];An(d!=null,`No layout data found for index ${a}`);const m=Ad({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:c,size:d});d!=m&&(s+=d-m,r[a]=m)}if(!di(s,0))for(let a=0;a<t.length;a++){const c=r[a];An(c!=null,`No layout data found for index ${a}`);const d=c+s,m=Ad({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:c,size:d});if(c!==m&&(s-=m-c,r[a]=m,di(s,0)))break}const o=Object.keys(e);return r.reduce((a,c,d)=>(a[o[d]]=c,a),{})}function TF({groupId:e,panelId:t}){const n=()=>{const a=ku();for(const[c,{defaultLayoutDeferred:d,derivedPanelConstraints:m,layout:f,groupSize:g,separatorToPanels:b}]of a)if(c.id===e)return{defaultLayoutDeferred:d,derivedPanelConstraints:m,group:c,groupSize:g,layout:f,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:m,group:f,groupSize:g,layout:b,separatorToPanels:y}=n(),_=f.panels.findIndex(k=>k.id===t),w=_===f.panels.length-1,C=Ym({delta:w?c-a:a-c,initialLayout:b,panelConstraints:m,pivotIndices:w?[_-1,_]:[_,_+1],prevLayout:b,trigger:"imperative-api"}),E=uu({layout:C,panelConstraints:m});cu(b,E)||Ha(f,{defaultLayoutDeferred:d,derivedPanelConstraints:m,groupSize:g,layout:E,separatorToPanels:y})};return{collapse:()=>{const{collapsible:a,collapsedSize:c}=r(),{mutableValues:d}=i(),m=s();a&&m!==c&&(d.expandToSize=m,o(c))},expand:()=>{const{collapsible:a,collapsedSize:c,minSize:d}=r(),{mutableValues:m}=i(),f=s();if(a&&f===c){let g=m.expandToSize??d;g===0&&(g=1),o(g)}},getSize:()=>{const{group:a}=n(),c=s(),{element:d}=i(),m=a.orientation==="horizontal"?d.offsetWidth:d.offsetHeight;return{asPercentage:c,inPixels:m}},isCollapsed:()=>{const{collapsible:a,collapsedSize:c}=r(),d=s();return a&&di(c,d)},resize:a=>{const{group:c}=n(),{element:d}=i(),m=ih({group:c}),f=Kf({groupSize:m,panelElement:d,styleProp:a}),g=Li(f/m*100);o(g)}}}function VI(e){if(e.defaultPrevented)return;const t=ku();C2(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=TF({groupId:n.group.id,panelId:r.id});s&&i!==void 0&&(s.resize(i),e.preventDefault())}}})}function bb(e){const t=ku();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 RF({groupId:e}){const t=()=>{const n=ku();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=uu({layout:n,panelConstraints:i});return r?a:(cu(a,d)||Ha(s,{defaultLayoutDeferred:r,derivedPanelConstraints:i,groupSize:o,layout:d,separatorToPanels:c}),d)}}}function Dc(e,t){const n=bb(e),r=Gl(n.id,!0),i=n.separators.find(m=>m.element===e);An(i,"Matching separator not found");const s=r.separatorToPanels.get(i);An(s,"Matching panels not found");const o=s.map(m=>n.panels.indexOf(m)),a=RF({groupId:n.id}).getLayout(),c=Ym({delta:t,initialLayout:a,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:a,trigger:"keyboard"}),d=uu({layout:c,panelConstraints:r.derivedPanelConstraints});cu(a,d)||Ha(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:d,separatorToPanels:r.separatorToPanels})}function WI(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=bb(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&Dc(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&Dc(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&Dc(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&Dc(t,-5);break}case"End":{e.preventDefault(),Dc(t,100);break}case"Enter":{e.preventDefault();const r=bb(t),i=Gl(r.id,!0),{derivedPanelConstraints:s,layout:o,separatorToPanels:a}=i,c=r.separators.find(g=>g.element===t);An(c,"Matching separator not found");const d=a.get(c);An(d,"Matching panels not found");const m=d[0],f=s.find(g=>g.panelId===m.id);if(An(f,"Panel metadata not found"),f.collapsible){const g=o[m.id],b=f.collapsedSize===g?r.mutableState.expandedPanelSizes[m.id]??f.minSize:f.collapsedSize;Dc(t,b-g)}break}case"F6":{e.preventDefault();const r=bb(t).separators.map(o=>o.element),i=Array.from(r).findIndex(o=>o===e.currentTarget);An(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(),Dc(t,-100);break}}}let Ud={cursorFlags:0,state:"inactive"};const k2=new kF;function du(){return Ud}function Axe(e){return k2.addListener("change",e)}function jxe(e){const t=Ud,n={...Ud};n.cursorFlags=e,Ud=n,k2.emit("change",{prev:t,next:n})}function Vd(e){const t=Ud;Ud=e,k2.emit("change",{prev:t,next:e})}function GI(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=ku(),n=C2(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)}),Vd({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}const Mxe=e=>e,oS=()=>{},AF=1,jF=2,MF=4,LF=8,qI=3,KI=12;let jv;function YI(){return jv===void 0&&(jv=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(jv=!0)),jv}function Lxe({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&&YI()){const s=(e&AF)!==0,o=(e&jF)!==0,a=(e&MF)!==0,c=(e&LF)!==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 YI()?r>0&&i>0?"move":r>0?"ew-resize":"ns-resize":r>0&&i>0?"grab":r>0?"col-resize":"row-resize"}}const XI=new WeakMap;function E2(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=XI.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&e.adoptedStyleSheets.push(n));const r=du();switch(r.state){case"active":case"hover":{const i=Lxe({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}}XI.set(e,{prevStyle:t,styleSheet:n})}function IF({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:i,pointerDownAtPoint:s,prevCursorFlags:o}){let a=0;n.forEach(d=>{const{group:m,groupSize:f}=d,{orientation:g,panels:b}=m,{disableCursor:y}=m.mutableState;let _=0;s?g==="horizontal"?_=(t.clientX-s.x)/f*100:_=(t.clientY-s.y)/f*100:g==="horizontal"?_=t.clientX<0?-100:100:_=t.clientY<0?-100:100;const w=r.get(m),C=i.get(m);if(!w||!C)return;const{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:T,layout:R,separatorToPanels:A}=C;if(k&&R&&A){const j=Ym({delta:_,initialLayout:w,panelConstraints:k,pivotIndices:d.panels.map(L=>b.indexOf(L)),prevLayout:R,trigger:"mouse-or-touch"});if(cu(j,R)){if(_!==0&&!y)switch(g){case"horizontal":{a|=_<0?AF:jF;break}case"vertical":{a|=_<0?MF:LF;break}}}else Ha(d.group,{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:T,layout:j,separatorToPanels:A})}});let c=0;t.movementX===0?c|=o&qI:c|=a&qI,t.movementY===0?c|=o&KI:c|=a&KI,jxe(c),E2(e)}function QI(e){const t=ku(),n=du();switch(n.state){case"active":IF({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function ZI(e){if(e.defaultPrevented)return;const t=du(),n=ku();switch(t.state){case"active":{if(e.buttons===0){Vd({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(r=>{const i=Gl(r.group.id,!0);Ha(r.group,i)});return}IF({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const r=C2(e,n);r.length===0?t.state!=="inactive"&&Vd({cursorFlags:0,state:"inactive"}):Vd({cursorFlags:0,hitRegions:r,state:"hover"}),E2(e.currentTarget);break}}}function JI(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(du().state){case"hover":Vd({cursorFlags:0,state:"inactive"})}}function eD(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=du();switch(t.state){case"active":Vd({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(E2(e.currentTarget),t.hitRegions.forEach(n=>{const r=Gl(n.group.id,!0);Ha(n.group,r)}),e.preventDefault())}}function tD(e){let t=0,n=0;const r={};for(const s of e)if(s.defaultSize!==void 0){t++;const o=Li(s.defaultSize);n+=o,r[s.panelId]=o}else r[s.panelId]=void 0;const i=e.length-t;if(i!==0){const s=Li((100-n)/i);for(const o of e)o.defaultSize===void 0&&(r[o.panelId]=s)}return r}function Ixe(e,t,n){if(!n[0])return;const r=e.panels.find(c=>c.element===t);if(!r||!r.onResize)return;const i=ih({group:e}),s=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,a={asPercentage:Li(s/i*100),inPixels:s};r.mutableValues.prevSize=a,r.onResize(a,r.id,o)}function Dxe(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 Pxe({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 f of e.panels){const g=r[f.id]??0;switch(f.panelConstraints.groupResizeBehavior){case"preserve-pixel-size":{o=!0;const b=g/100*n,y=Li(b/t*100);a.set(f.id,y),i+=y;break}case"preserve-relative-size":default:{c.push(f.id),s+=g;break}}}if(!o||c.length===0)return r;const d=100-i,m={...r};if(a.forEach((f,g)=>{m[g]=f}),s>0)for(const f of c){const g=r[f]??0;m[f]=Li(g/s*d)}else{const f=Li(d/c.length);for(const g of c)m[g]=f}return m}function Oxe(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 vd=new Map;function zxe(e){let t=!0;An(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=ih({group:e});if(E===0)return;const k=Gl(e.id);if(!k)return;const T=hC(e),R=k.defaultLayoutDeferred?tD(T):k.layout,A=Pxe({group:e,nextGroupSize:E,prevGroupSize:k.groupSize,prevLayout:R}),j=uu({layout:A,panelConstraints:T});if(!k.defaultLayoutDeferred&&cu(k.layout,j)&&Dxe(k.derivedPanelConstraints,T)&&k.groupSize===E)return;Ha(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:T,groupSize:E,layout:j,separatorToPanels:k.separatorToPanels})}}else Ixe(e,C,w)}});s.observe(e.element),e.panels.forEach(y=>{An(!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=ih({group:e}),a=hC(e),c=e.panels.map(({id:y})=>y).join(",");let d=e.mutableState.defaultLayout;d&&(Oxe(e.panels,d)||(d=void 0));const m=e.mutableState.layouts[c]??d??tD(a),f=uu({layout:m,panelConstraints:a}),g=e.element.ownerDocument;vd.set(g,(vd.get(g)??0)+1);const b=new Map;return CF(e).forEach(y=>{y.separator&&b.set(y.separator,y.panels)}),Ha(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:a,groupSize:o,layout:f,separatorToPanels:b}),e.separators.forEach(y=>{An(!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",WI)}),vd.get(g)===1&&(g.addEventListener("dblclick",VI,!0),g.addEventListener("pointerdown",GI,!0),g.addEventListener("pointerleave",QI),g.addEventListener("pointermove",ZI),g.addEventListener("pointerout",JI),g.addEventListener("pointerup",eD,!0)),function(){t=!1,vd.set(g,Math.max(0,(vd.get(g)??0)-1)),yxe(e),e.separators.forEach(y=>{y.element.removeEventListener("keydown",WI)}),vd.get(g)||(g.removeEventListener("dblclick",VI,!0),g.removeEventListener("pointerdown",GI,!0),g.removeEventListener("pointerleave",QI),g.removeEventListener("pointermove",ZI),g.removeEventListener("pointerout",JI),g.removeEventListener("pointerup",eD,!0)),s.disconnect()}}function Bxe(){const[e,t]=v.useState({}),n=v.useCallback(()=>t({}),[]);return[e,n]}function N2(e){const t=v.useId();return`${e??t}`}const Eu=typeof window<"u"?v.useLayoutEffect:v.useEffect;function dm(e){const t=v.useRef(e);return Eu(()=>{t.current=e},[e]),v.useCallback((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[t])}function T2(...e){return dm(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function R2(e){const t=v.useRef({...e});return Eu(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const DF=v.createContext(null);function Fxe(e,t){const n=v.useRef({getLayout:()=>({}),setLayout:Mxe});v.useImperativeHandle(t,()=>n.current,[]),Eu(()=>{Object.assign(n.current,RF({groupId:e}))})}function PF({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:s,groupRef:o,id:a,onLayoutChange:c,onLayoutChanged:d,orientation:m="horizontal",resizeTargetMinimumSize:f={coarse:20,fine:10},style:g,...b}){const y=v.useRef({onLayoutChange:{},onLayoutChanged:{}}),_=dm(D=>{cu(y.current.onLayoutChange,D)||(y.current.onLayoutChange=D,c==null||c(D))}),w=dm(D=>{cu(y.current.onLayoutChanged,D)||(y.current.onLayoutChanged=D,d==null||d(D))}),C=N2(a),E=v.useRef(null),[k,T]=Bxe(),R=v.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:f,separators:[]}),A=T2(E,s);Fxe(C,o);const j=dm((D,z)=>{const O=du(),F=FI(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=R2({defaultLayout:n,disableCursor:r}),H=v.useMemo(()=>({get disableCursor(){return!!L.disableCursor},getPanelStyles:j,id:C,orientation:m,registerPanel:D=>{const z=R.current;return z.panels=fC(m,[...z.panels,D]),T(),()=>{z.panels=z.panels.filter(O=>O!==D),T()}},registerSeparator:D=>{const z=R.current;return z.separators=fC(m,[...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=FI(C),$=Gl(C);F&&$&&Ha(F,{...$,derivedPanelConstraints:hC(F)})},toggleSeparatorDisabled:(D,z)=>{const O=R.current.separators.find(F=>F.id===D);O&&(O.disabled=z)}}),[j,C,T,m,L]),M=v.useRef(null);return Eu(()=>{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:m,panels:z.panels,resizeTargetMinimumSize:z.resizeTargetMinimumSize,separators:z.separators};M.current=F;const $=zxe(F),{defaultLayoutDeferred:B,derivedPanelConstraints:U,layout:G}=Gl(F.id,!0);!B&&U.length>0&&(_(G),w(G));const te=S2(C,P=>{const{defaultLayoutDeferred:Y,derivedPanelConstraints:ee,layout:V}=P.next;if(Y||ee.length===0)return;const ue=F.panels.map(({id:J})=>J).join(",");F.mutableState.layouts[ue]=V,ee.forEach(J=>{if(J.collapsible){const{layout:ne}=P.prev??{};if(ne){const ie=di(J.collapsedSize,V[J.panelId]),le=di(J.collapsedSize,ne[J.panelId]);ie&&!le&&(F.mutableState.expandedPanelSizes[J.panelId]=ne[J.panelId])}}});const ge=du().state!=="active";_(V),ge&&w(V)});return()=>{M.current=null,$(),te()}},[i,C,w,_,m,k,L]),v.useEffect(()=>{const D=M.current;D&&(D.mutableState.defaultLayout=n,D.mutableState.disableCursor=!!r)}),u.jsx(DF.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:m==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:m==="horizontal"?"pan-y":"pan-x"},children:e})})}PF.displayName="Group";function A2(){const e=v.useContext(DF);return An(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function $xe(e,t){const{id:n}=A2(),r=v.useRef({collapse:oS,expand:oS,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:oS});v.useImperativeHandle(t,()=>r.current,[]),Eu(()=>{Object.assign(r.current,TF({groupId:n,panelId:e}))})}function OF({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:m="0%",onResize:f,panelRef:g,style:b,...y}){const _=!!c,w=N2(c),C=R2({disabled:s}),E=v.useRef(null),k=T2(E,o),{getPanelStyles:T,id:R,orientation:A,registerPanel:j,togglePanelDisabled:L}=A2(),H=f!==null,M=dm((z,O,F)=>{f==null||f(z,c,F)});Eu(()=>{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:m}};return j(O)}},[a,n,r,i,H,w,_,d,m,M,j,C]),v.useEffect(()=>{L(w,!!s)},[s,w,L]),$xe(w,g);const D=v.useSyncExternalStore(z=>S2(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:{...Hxe,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})})}OF.displayName="Panel";const Hxe={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function Uxe({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,m=[r,r+1];s=uu({layout:Ym({delta:d-o,initialLayout:e,panelConstraints:t,pivotIndices:m,prevLayout:e}),panelConstraints:t})[n],i=uu({layout:Ym({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:m,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:s,valueNow:o}}function zF({children:e,className:t,disabled:n,elementRef:r,id:i,style:s,...o}){const a=N2(i),c=R2({disabled:n}),[d,m]=v.useState({}),[f,g]=v.useState("inactive"),b=v.useRef(null),y=T2(b,r),{disableCursor:_,id:w,orientation:C,registerSeparator:E,toggleSeparatorDisabled:k}=A2(),T=C==="horizontal"?"vertical":"horizontal";Eu(()=>{const A=b.current;if(A!==null){const j={disabled:c.disabled,element:A,id:a},L=E(j),H=Axe(D=>{g(D.next.state!=="inactive"&&D.next.hitRegions.some(z=>z.separator===j)?D.next.state:"inactive")}),M=S2(w,D=>{const{derivedPanelConstraints:z,layout:O,separatorToPanels:F}=D.next,$=F.get(j);if($){const B=$[0],U=$.indexOf(B);m(Uxe({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":f,"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})}zF.displayName="Separator";const j2=({className:e,...t})=>u.jsx(PF,{className:de("flex h-full w-full",e),...t}),Xm=e=>u.jsx(OF,{...e}),M2=({withHandle:e,orientation:t,disabled:n,className:r,...i})=>u.jsx(zF,{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 BF(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 Vxe(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 BF(r.usage,new Date(r.createdAt).toISOString(),t)}return null}function Wxe(e,t){return!e||t===null||!Number.isFinite(t)||t<=0?e:BF({...e,maxTokens:t},e.updatedAt,e.compactsAutomatically)}function Gxe(e){if(!e)return null;const t=aS(e.inputTokens),n=aS(e.outputTokens),r=aS(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 aS(e){return e===void 0||!Number.isFinite(e)||e<0?0:e}function Mi(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 L2=[68,32];function qxe(){return{isVisible:!1,mainSizes:[...L2],terminals:[],nextTerminalIndex:0}}function Kxe(e,t){return e[t]??qxe()}function lS(e){if(e.length===0)return[];const t=e.reduce((n,r)=>n+Math.max(r,0),0);return!Number.isFinite(t)||t<=0?Array.from({length:e.length},()=>100/e.length):e.map(n=>Math.max(n,0)/t*100)}function Yxe(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 Xxe(e){if(e.length===0)return e;const t=e.length+1;return e.map(n=>({...n,size:n.size*e.length/t}))}function bd(e,t,n){return{...e,[t]:n(Kxe(e,t))}}const Il=Oi()(Nh(e=>({projects:{},addTerminal:(t,n)=>e(r=>({projects:bd(r.projects,t,i=>{var c,d;const s=Xxe(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:Yxe(i.nextTerminalIndex),size:100/(s.length+1)},a=n?Math.max(s.findIndex(m=>m.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:bd(r.projects,t,i=>{const s=i.terminals.filter(a=>a.id!==n);if(s.length===0)return{...i,isVisible:!1,terminals:[]};const o=lS(s.map(a=>a.size));return{...i,terminals:s.map((a,c)=>({...a,size:o[c]??100/s.length}))}})})),toggleVisibility:t=>e(n=>({projects:bd(n.projects,t,r=>({...r,isVisible:r.terminals.length>0?!r.isVisible:!1}))})),resetMainSizes:t=>e(n=>({projects:bd(n.projects,t,r=>({...r,mainSizes:[...L2]}))})),setMainSizes:(t,n)=>e(r=>{if(n.length!==2)return r;const i=lS(n);return{projects:bd(r.projects,t,s=>({...s,mainSizes:i}))}}),setTerminalSizes:(t,n)=>e(r=>({projects:bd(r.projects,t,i=>{if(n.length!==i.terminals.length)return i;const s=lS(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})),Qxe={isVisible:!1,mainSizes:[...L2],terminals:[],nextTerminalIndex:0},Zxe=35;function Jxe(e,t){return!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<=0?0:e*(t/100)}function eye(e,t){const n=Jxe(e,t);return n>=0&&n<Zxe}const Ey=350,tye=[.4,0,.2,1],nye=8,nD=1e-6;function rye(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function iye(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function sye(e,t,n){const r=1-e;return 3*r*r*t+6*r*e*(n-t)+3*e*e*(1-n)}function oye(e,t,n){let r=e;for(let i=0;i<nye;i+=1){const s=rye(r,t,n)-e;if(Math.abs(s)<nD)return r;const o=sye(r,t,n);if(Math.abs(o)<nD)break;r-=s/o}return r}function aye(e){if(e<=0)return 0;if(e>=1)return 1;const[t,n,r,i]=tye,s=oye(e,t,r);return iye(s,n,i)}function FF(e,t,n){const r=aye(n);return[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r]}function lye({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),m=v.useRef(null),f=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=m.current,_=y!==null&&y!==e,w=n&&!g.current,C=!f.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(m.current=e,f.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)/Ey),$=FF(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||(f.current=!1,g.current=!1)},[t]),{isAnimating:d,panelGroupRef:i,sidebarPanelRef:s,sidebarVisualRef:o}}function cye(e){return e.visibilityState==="visible"?e.activeChatId:null}function uye(e){e.socket.setFocusedChat(cye({activeChatId:e.activeChatId,visibilityState:e.visibilityState}))}function dye({socket:e,activeChatId:t}){v.useEffect(()=>{if(typeof document>"u")return;const n=()=>{uye({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 hye({rootRef:e,fallbackRef:t,enabled:n,canCancel:r}){v.useEffect(()=>{if(!n)return;let i=0,s=null;const o=f=>{const g=f instanceof Element?f:null,b=e.current,y=t.current;if(Pj({trigger:"pointer",activeElement:document.activeElement,pointerStartTarget:s,pointerEndTarget:g,root:b,fallback:y,hasActiveOverlay:Dj(document),hasActiveSelection:BX(window.getSelection())})!=="restore"){s=null;return}y==null||y.focus({preventScroll:!0}),s=null},a=f=>{cancelAnimationFrame(i),s=f.target instanceof Element?f.target:null},c=f=>{cancelAnimationFrame(i),i=window.requestAnimationFrame(()=>{o(f.target)})},d=()=>{s=null;const f=t.current;!f||f.disabled||f.focus({preventScroll:!0})},m=f=>{if(f.key!=="Escape")return;const g=t.current;Pj({trigger:"escape",activeElement:document.activeElement,fallback:g,hasActiveOverlay:Dj(document),canCancel:r,defaultPrevented:f.defaultPrevented})==="escape-focus"&&(f.preventDefault(),g==null||g.focus({preventScroll:!0}))};return window.addEventListener("pointerdown",a,!0),window.addEventListener("pointerup",c,!0),window.addEventListener("keydown",m,!0),window.addEventListener(Ib,d),()=>{cancelAnimationFrame(i),window.removeEventListener("pointerdown",a,!0),window.removeEventListener("pointerup",c,!0),window.removeEventListener("keydown",m,!0),window.removeEventListener(Ib,d)}},[r,n,t,e])}function fye(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 mye({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,m=e===null&&t!==null,f=i?s.mainSizes:[100,0];return{currentLayout:c||d?[100,0]:o,shouldSkipAnimation:a||m&&d,targetLayout:f}}function pye({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),m=v.useRef(!1),f=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=f.current,E=y.current;fye({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,f.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),m.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=f.current,{currentLayout:k,shouldSkipAnimation:T,targetLayout:R}=mye({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}m.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)/Ey),B=FF(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(()=>{m.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:m,mainPanelGroupRef:s,terminalFocusRequestVersion:_,terminalPanelRef:o,terminalVisualRef:a}}const rD=e=>Symbol.iterator in e,iD=e=>"entries"in e,sD=(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},gye=(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 vye(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:rD(e)&&rD(t)?iD(e)&&iD(t)?sD(e,t):gye(e,t):sD({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function hm(e){const t=_n.useRef(void 0);return n=>{const r=e(n);return vye(t.current,r)?t.current:t.current=r}}const fm="__new__";function Pc(e){var s,o;const t=(s=e==null?void 0:e.modelOptions)==null?void 0:s.reasoningEffort,n=p1(t)?t:p1(e==null?void 0:e.effort)?e.effort:ru.reasoningEffort,r=nre(e==null?void 0:e.model),i=wE(r,(o=e==null?void 0:e.modelOptions)==null?void 0:o.contextWindow);return{model:r,modelOptions:{reasoningEffort:!gz(r)&&n==="max"?"high":n,contextWindow:i},planMode:!!(e!=null&&e.planMode)}}function Mv(e){var n,r;const t=(n=e==null?void 0:e.modelOptions)==null?void 0:n.reasoningEffort;return{model:rre(e==null?void 0:e.model),modelOptions:{reasoningEffort:g1(t)?t:g1(e==null?void 0:e.effort)?e.effort:Mm.reasoningEffort,fastMode:typeof((r=e==null?void 0:e.modelOptions)==null?void 0:r.fastMode)=="boolean"?e.modelOptions.fastMode:Mm.fastMode},planMode:!!(e!=null&&e.planMode)}}function bye(){return{claude:{model:"claude-opus-4-7",modelOptions:{...ru},planMode:!1},codex:{model:"gpt-5.5",modelOptions:{...Mm},planMode:!1},openrouter:{model:ey,modelOptions:{},planMode:!1}}}function xye(e,t){return e.reasoningEffort===t.reasoningEffort&&e.contextWindow===t.contextWindow}function yye(e,t){return e.reasoningEffort===t.reasoningEffort&&e.fastMode===t.fastMode}function _ye(e,t){return e.claude.model===t.claude.model&&e.claude.planMode===t.claude.planMode&&xye(e.claude.modelOptions,t.claude.modelOptions)&&e.codex.model===t.codex.model&&e.codex.planMode===t.codex.planMode&&yye(e.codex.modelOptions,t.codex.modelOptions)&&e.openrouter.model===t.openrouter.model&&e.openrouter.planMode===t.openrouter.planMode}function wye(e,t){if(t===void 0){console.info(`[chat-preferences] ${e}`);return}console.info(`[chat-preferences] ${e}`,t)}function mm(e,t){if(e==="claude"){const r=t.claude;return{provider:"claude",model:r.model,modelOptions:{...r.modelOptions},planMode:r.planMode}}if(e==="openrouter"){const r=t.openrouter;return{provider:"openrouter",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 mC(e){return e.provider==="claude"?{provider:"claude",model:e.model,modelOptions:{...e.modelOptions},planMode:e.planMode}:e.provider==="openrouter"?{provider:"openrouter",model:e.model,modelOptions:{...e.modelOptions},planMode:e.planMode}:{provider:"codex",model:e.model,modelOptions:{...e.modelOptions},planMode:e.planMode}}function $F(e){return e.providerHint?mm(e.providerHint,e.providerDefaults):e.defaultProvider==="last_used"?e.sourceState?mC(e.sourceState):mm("claude",e.providerDefaults):mm(e.defaultProvider,e.providerDefaults)}function HF(e,t){const n=e.chatStates[t];return n||$F({defaultProvider:e.defaultProvider,providerDefaults:e.providerDefaults,legacyComposerState:e.legacyComposerState})}function Lv(e,t,n){const r=HF(e,t);return{chatStates:{...e.chatStates,[t]:n(r)}}}const mi=Oi()(Nh((e,t)=>({defaultProvider:"last_used",providerDefaults:bye(),chatStates:{},legacyComposerState:{provider:"claude",model:"claude-opus-4-7",modelOptions:{...ru},planMode:!1},setDefaultProvider:n=>e({defaultProvider:n}),applyServerDefaults:(n,r)=>e(i=>{if(i.defaultProvider===n&&_ye(i.providerDefaults,r))return{defaultProvider:n,providerDefaults:r};const{[fm]:o,...a}=i.chatStates;return{defaultProvider:n,providerDefaults:r,chatStates:a}}),setProviderDefaultModel:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?Pc({...i.providerDefaults.claude,model:r}):n==="openrouter"?{...i.providerDefaults.openrouter,model:r}:Mv({...i.providerDefaults.codex,model:r})}})),setProviderDefaultModelOptions:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?Pc({...i.providerDefaults.claude,modelOptions:{...i.providerDefaults.claude.modelOptions,...r}}):n==="openrouter"?{...i.providerDefaults.openrouter,modelOptions:{}}:Mv({...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=>mC(HF(t(),n)),initializeComposerForChat:(n,r)=>e(i=>{if(i.chatStates[n])return i;const s=$F({defaultProvider:i.defaultProvider,providerDefaults:i.providerDefaults,sourceState:r==null?void 0:r.sourceState,legacyComposerState:i.legacyComposerState,providerHint:r==null?void 0:r.providerHint});return wye("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:Pc(r).model,modelOptions:Pc(r).modelOptions,planMode:r.planMode}:mC(r)}})),setChatComposerProvider:(n,r)=>e(i=>Lv(i,n,()=>mm(r,i.providerDefaults))),setChatComposerModel:(n,r)=>e(i=>Lv(i,n,s=>s.provider==="claude"?{provider:"claude",model:Pc({...s,model:r}).model,modelOptions:Pc({...s,model:r}).modelOptions,planMode:s.planMode}:s.provider==="openrouter"?{provider:"openrouter",model:r,modelOptions:{},planMode:s.planMode}:{provider:"codex",model:r,modelOptions:Mv({...s,model:r}).modelOptions,planMode:s.planMode})),setChatComposerModelOptions:(n,r)=>e(i=>Lv(i,n,s=>s.provider==="claude"?{provider:"claude",model:s.model,modelOptions:Pc({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode}:s.provider==="openrouter"?{provider:"openrouter",model:s.model,modelOptions:{},planMode:s.planMode}:{provider:"codex",model:s.model,modelOptions:Mv({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode})),setChatComposerPlanMode:(n,r)=>e(i=>Lv(i,n,s=>({...s,planMode:r}))),resetChatComposerFromProvider:(n,r)=>e(i=>({chatStates:{...i.chatStates,[n]:mm(r,i.providerDefaults)}}))}),{name:"chat-preferences-state",version:1,partialize:e=>({chatStates:e.chatStates,legacyComposerState:e.legacyComposerState})})),pC=Oi()(Nh((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"})),I2=Oi()(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 Sye(e){return{autoResumeOnRateLimit:!!(e!=null&&e.autoResumeOnRateLimit)}}const gC=Oi()(Nh(e=>({autoResumeOnRateLimit:!1,setAutoResumeOnRateLimit:t=>e({autoResumeOnRateLimit:t})}),{name:"kanna-preferences",version:1,migrate:e=>Sye(e)}));function xd(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function Iv(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function Cye(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 cS(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 kye(e,t){var r;const n=Iv(t);switch(e.toolKind){case"ask_user_question":{const o=cS(n),a=o!==null?Iv(o):n,c=xd(a),d=xd(c==null?void 0:c.answers)??(c||{});return{answers:Object.fromEntries(Object.entries(d).map(([m,f])=>Array.isArray(f)?[m,f.map(g=>String(g))]:f&&typeof f=="object"&&Array.isArray(f.answers)?[m,f.answers.map(g=>String(g))]:f==null||f===""?[m,[]]:[m,[String(f)]])),...(c==null?void 0:c.discarded)===!0?{discarded:!0}:{}}}case"exit_plan_mode":{const o=cS(n),a=o!==null?Iv(o):n,c=xd(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=cS(n),a=o?Iv(o):n,c=xd(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=xd(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=Cye(n);if(i.length>0)return{content:i.flatMap(o=>o.type==="text"?[o.text]:[]).join(""),blocks:i};const s=xd(n);return{content:typeof(s==null?void 0:s.content)=="string"?s.content:JSON.stringify(n,null,2)};default:return n}}function UF(e){return new Date(e).toISOString()}function Tr(e){return{id:e._id,messageId:e.messageId,timestamp:UF(e.createdAt),hidden:e.hidden}}function Eye(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:UF(e.createdAt)}}function Nye(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 Dv(e){return typeof e=="string"?e:void 0}function Tye(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 Rye(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:Dv(n.agentId),agentType:Dv(n.agentType),status:Dv(n.status),totalTokens:jo(n.totalTokens),totalDurationMs:jo(n.totalDurationMs),totalToolUseCount:jo(n.totalToolUseCount),toolStats:Tye(n.toolStats),content:Dv(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 D2(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=Eye(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"?Nye(r)??r.content:r.content;i.normalized.toolKind==="subagent_task"?i.hydrated.result=Rye(r):i.hydrated.result=kye(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 Aye=["AskUserQuestion","ExitPlanMode","TodoWrite"],jye=new Set(["TodoWrite"]);function Mye(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 Lye(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 Iye(e){const t={};for(const n of Aye)t[n]=jye.has(n)?Lye(e,n):Mye(e,n);return t}function Dye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}function Pye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}const P2="pushDeviceId";function VF(){return typeof localStorage>"u"?null:localStorage.getItem(P2)}function Oye(e){typeof localStorage>"u"||localStorage.setItem(P2,e)}function zye(){typeof localStorage>"u"||localStorage.removeItem(P2)}function Bye(){return!(typeof window>"u"||typeof Notification>"u"||!("serviceWorker"in navigator)||typeof globalThis.PushManager>"u")}function Fye(){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 vC(){if(!Bye())return{state:"unsupported"};if(!Fye())return{state:"insecure-context"};switch(Notification.permission){case"granted":return{state:"granted"};case"denied":return{state:"denied"};default:return{state:"default"}}}function $ye(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 Hye(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 Uye(e){const t=vC();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:$ye(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:Hye(c),userAgent:c});return d}async function Vye(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 Wye=25e3,Gye=15e3,qye=4e3,oD="kanna:profile-send-to-starting";function aD(){try{return window.sessionStorage.getItem(oD)==="1"||window.localStorage.getItem(oD)==="1"}catch{return!1}}class Kye{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=$c();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=$c(),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=$c(),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=$c();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=VF();t&&this.sendNow({v:1,type:"command",id:$c(),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(aD()&&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}),aD()&&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($Z,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>=Wye}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()},qye),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()},Gye))}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 Yye=[],O2=Oi()(e=>({byChat:{},setRuns:(t,n)=>e(r=>({byChat:{...r.byChat,[t]:n}}))}));function WF(e){return t=>t.byChat[e]??Yye}const Xye=[],Pv=Oi()(e=>({models:Xye,status:"idle",error:null,setLoading:()=>e({status:"loading",error:null}),setModels:t=>e({models:t,status:"ready",error:null}),setError:t=>e({status:"error",error:t})}));function Qye(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 Zye(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&&Qye(e.sessionTokensByProvider,t.sessionTokensByProvider)}function Jye(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 e0e(e,t){return t.length===0?e:e.map(n=>n.id!=="openrouter"?n:{...n,models:t.map(r=>({id:r.id,label:r.label,supportsEffort:!1}))})}function t0e(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 n0e(e,t){return e===t?!0:!e||!t?!1:e.hasOlder===t.hasOlder&&e.olderCursor===t.olderCursor&&e.recentLimit===t.recentLimit}function r0e(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)&&i0e(e.attachments,t.attachments)}function i0e(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 s0e(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>r0e(n,t[r]))}function o0e(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((m,f)=>m===d.tags[f])})||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 a0e(e,t){return!!(e&&e.status!=="unknown"&&t&&t.status==="unknown"&&t.files.length===0)}function l0e(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 c0e(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 u0e(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,m,f,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)===(((m=o.usage)==null?void 0:m.outputTokens)??null)&&s.finishedAt===o.finishedAt&&(((f=s.error)==null?void 0:f.code)??null)===(((g=o.error)==null?void 0:g.code)??null)})}function d0e(e,t){return e===t?!0:!e||!t?!1:Zye(e.runtime,t.runtime)&&s0e(e.queuedMessages,t.queuedMessages)&&Jye(e.messages,t.messages)&&n0e(e.history,t.history)&&t0e(e.availableProviders,t.availableProviders)&&l0e(e.schedules,t.schedules)&&e.liveScheduleId===t.liveScheduleId&&c0e(e.tunnels,t.tunnels)&&e.liveTunnelId===t.liveTunnelId&&u0e(e.subagentRuns,t.subagentRuns)}function lD(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 h0e(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 cD="__new_chat__",GF="lever-theme",qF="chat-sound-preferences",KF="terminal-preferences",YF="chat-preferences";function uS(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 f0e(){if(typeof window>"u")return null;const e={},t=window.localStorage.getItem(GF);(t==="light"||t==="dark"||t==="system")&&(e.theme=t);const n=uS(qF);((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=uS(KF);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=uS(YF);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 m0e(){typeof window>"u"||(window.localStorage.removeItem(GF),window.localStorage.removeItem(qF),window.localStorage.removeItem(KF),window.localStorage.removeItem(YF))}function Of(e){ji.getState().setFromServer(e);const t=ui.getState();t.setScrollbackLines(e.terminal.scrollbackLines),t.setMinColumnWidth(e.terminal.minColumnWidth),t.setEditorPreset(e.editor.preset),t.setEditorCommandTemplate(e.editor.commandTemplate);const n=Vc.getState();n.setChatSoundPreference(e.chatSoundPreference),n.setChatSoundId(e.chatSoundId),mi.getState().applyServerDefaults(e.defaultProvider,e.providerDefaults)}function p0e(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 z2(e,t=[]){return JSON.stringify({content:e,attachments:t.map(p0e)})}function g0e(e,t){return e.reduce((n,r)=>r.kind!=="user_prompt"?n:n+(z2(r.content,r.attachments??[])===t?1:0),0)}function v0e(e,t,n){const r=new Map;for(const i of n){if(i.kind!=="user_prompt")continue;const s=z2(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 b0e(e,t,n){return e.some(r=>r.id===t)?e.filter(r=>r.id!==t):e}const x0e=200,y0e=500;function uD(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 dD(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 _0e(e=document){return e.visibilityState==="visible"&&e.hasFocus()}function w0e(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`}function S0e(){const[e]=v.useState(()=>new Kye(w0e()));return v.useEffect(()=>(e.start(),()=>{e.dispose()}),[e]),e}const hD="kanna:profile-send-to-starting";function C0e(){try{return window.sessionStorage.getItem(hD)==="1"||window.localStorage.getItem(hD)==="1"}catch{return!1}}function XF(e){return Number((performance.now()-e).toFixed(1))}function Nl(e,t,n){!e||!C0e()||console.debug("[kanna/send->starting][client]",{traceId:e.traceId,stage:t,elapsedMs:XF(e.startedAt),serverChatId:e.serverChatId,routeChatIdAtSend:e.routeChatIdAtSend,...n})}function k0e(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 E0e(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 N0e(e,t){return e==="awaiting_disconnect"&&t==="disconnected"?"awaiting_server_ready":"none"}function T0e(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 R0e=30,B2="kanna:ui-update-restart",QF="kanna:last-update-reload-request";function A0e(e){return e+R0e}function j0e(e,t){return t>0?t:e}function dS(){return window.sessionStorage.getItem(B2)}function M0e(e){window.sessionStorage.setItem(B2,e)}function L0e(){window.sessionStorage.removeItem(B2)}function I0e(e,t){return e?String(e)!==t:!1}function D0e(){return window.sessionStorage.getItem(QF)}function P0e(e){window.sessionStorage.setItem(QF,String(e))}function O0e(){return"/auth/status"}async function z0e(e=fetch){return(await e(O0e(),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}})).ok}function B0e(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 F0e(e,t){return!e||!t?null:e.runtime.chatId!==t?(e.runtime.chatId,e.runtime.provider,null):e}function $0e(e){var zh,hc,fc;const t=gu(),n=S0e(),r=mp(),[i,s]=v.useState({starredProjectGroups:[],projectGroups:[],stacks:[]}),[o,a]=v.useState(null),[c,d]=v.useState(null),[m,f]=v.useState(null),[g,b]=v.useState(()=>dS()),y=v.useCallback(Q=>{M0e(Q),b(Q)},[]),_=v.useCallback(()=>{L0e(),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),[J,ne]=v.useState(!1),[ie,le]=v.useState(null),[oe,Ce]=v.useState(!1),[ke,ze]=v.useState(!1),[Ze,lt]=v.useState(!1),[Mt,ye]=v.useState(null),[ln,jt]=v.useState(null),[_t,ft]=v.useState(null),[Ot,It]=v.useState([]),[it,Dt]=v.useState(null),[fe,Ae]=v.useState(0),He=v.useRef(new Map),Je=pC(hm(Q=>Object.keys(Q.drafts).sort())),qe=pC(hm(Q=>Object.keys(Q.attachmentDrafts).sort())),bt=v.useRef(0),wt=v.useRef(null),Tt=v.useRef({projectId:null,diffs:null}),Ne=Tre(ui(Q=>Q.editorPreset)),De=v.useMemo(()=>dD(i.projectGroups,o),[o,i.projectGroups]),Be=v.useRef(De);v.useLayoutEffect(()=>{Be.current=De});const Ye=v.useMemo(()=>De===i.projectGroups?i:{...i,projectGroups:De},[i,De]);v.useEffect(()=>n.onStatus(Y),[n]),v.useEffect(()=>n.subscribe({type:"sidebar"},Q=>{s(Q),a(Z=>Z&&dD(Q.projectGroups,Z)===Q.projectGroups?null:Z),V(!0),ye(null)}),[n]),v.useEffect(()=>{if(P!=="connected")return;const Q=[...new Set([...Je,...qe])].sort();n.command({type:"chat.setDraftProtection",chatIds:Q}).catch(Z=>{ye(Z instanceof Error?Z.message:String(Z))})},[qe,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=>{f(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=m==null?void 0:m.reloadRequestedAt;I0e(Q,D0e())&&Q&&(P0e(Q),y("awaiting_disconnect"))},[y,m==null?void 0:m.reloadRequestedAt]),v.useEffect(()=>{const Q=dS();if(N0e(Q,P)==="awaiting_server_ready"){y("awaiting_server_ready");return}},[P,y]),v.useEffect(()=>{if(dS()!=="awaiting_server_ready")return;let Q=!1,Z=null;const je=async()=>{try{if(await z0e()){if(Q)return;_(),window.location.reload();return}}catch{}Q||(Z=window.setTimeout(()=>{je()},500))};return je(),()=>{Q=!0,Z!==null&&window.clearTimeout(Z)}},[P,_]),v.useEffect(()=>{function Q(){m!=null&&m.lastCheckedAt&&(Date.now()-m.lastCheckedAt<=3600*1e3||n.command({type:"update.check"}).catch(Z=>{ye(Z instanceof Error?Z.message:String(Z))}))}return window.addEventListener("focus",Q),()=>{window.removeEventListener("focus",Q)}},[n,m==null?void 0:m.lastCheckedAt]),v.useEffect(()=>n.subscribe({type:"keybindings"},Q=>{O(Q),ye(null)}),[n]),v.useEffect(()=>n.subscribe({type:"app-settings"},Q=>{$(Q),Of(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 ct=v.useCallback(async()=>{try{ji.getState().setHydrationStatus("loading");const Q=await n.command({type:"settings.readAppSettings"});$(Q),Of(Q),ye(null)}catch(Q){ji.getState().setHydrationStatus("error"),ye(Q instanceof Error?Q.message:String(Q))}},[n]),nn=v.useCallback(async(Q,Z)=>{try{await n.command({type:"chat.setPolicyOverride",chatId:Q,policyOverride:Z}),ye(null)}catch(je){throw ye(je instanceof Error?je.message:String(je)),je}},[n]),Qt=v.useCallback(async Q=>{try{ji.getState().applyOptimisticPatch(Q);const Z=await n.command({type:"settings.writeAppSettingsPatch",patch:Q});$(Z),Of(Z),ye(null)}catch(Z){throw ye(Z instanceof Error?Z.message:String(Z)),await ct(),Z}},[ct,n]),Ut=v.useCallback(async Q=>{try{await n.command({type:"settings.testMcpServer",id:Q}),ye(null)}catch(Z){throw ye(Z instanceof Error?Z.message:String(Z)),Z}},[n]),Rt=v.useCallback(async Q=>{try{ji.getState().applyOptimisticPatch({cloudflareTunnel:Q});const Z=await n.command({type:"appSettings.setCloudflareTunnel",patch:Q});$(Z),Of(Z),ye(null)}catch(Z){throw ye(Z instanceof Error?Z.message:String(Z)),await ct(),Z}},[ct,n]),xt=v.useCallback(async Q=>{try{ji.getState().applyOptimisticPatch({claudeAuth:Q});const Z=await n.command({type:"appSettings.setClaudeAuth",patch:Q});$(Z),Of(Z),ye(null)}catch(Z){throw ye(Z instanceof Error?Z.message:String(Z)),await ct(),Z}},[ct,n]),mt=v.useCallback(async Q=>await n.command({type:"appSettings.testOAuthToken",token:Q}),[n]),Ct=v.useCallback(async()=>{try{const Q=await n.command({type:"settings.readLlmProvider"});te(Q),ye(null)}catch(Q){ye(Q instanceof Error?Q.message:String(Q))}},[n]),pt=v.useCallback(async Q=>{try{const Z=await n.command({type:"settings.writeLlmProvider",provider:Q.provider,apiKey:Q.apiKey,model:Q.model,baseUrl:Q.baseUrl});te(Z),ye(null)}catch(Z){throw ye(Z instanceof Error?Z.message:String(Z)),Z}},[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"&&ct()},[P,ct]),v.useEffect(()=>{if(P!=="connected")return;Pv.getState().setLoading(),n.command({type:"settings.listOpenRouterModels"}).then(Z=>{Pv.getState().setModels(Z)}).catch(Z=>{const je=Z instanceof Error?Z.message:String(Z);Pv.getState().setError(je)})},[P,n]),v.useEffect(()=>{if(P!=="connected"||(F==null?void 0:F.browserSettingsMigrated)!==!1)return;const Q=f0e();Q&&Qt(Q).then(m0e).catch(()=>{})},[F==null?void 0:F.browserSettingsMigrated,P,Qt]),v.useEffect(()=>{P==="connected"&&Ct()},[P,Ct]),v.useEffect(()=>{function Q(){Ae(Z=>Z+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}++bt.current,Be.current.length,Be.current.reduce((Z,je)=>Z+je.chats.length,0),C(null),ne(!1);const Q=n.subscribe({type:"chat",chatId:e,recentLimit:x0e},Z=>{if(Z!=null&&Z.runtime.chatId){const je=[...He.current.values()].filter(vt=>vt.serverChatId===Z.runtime.chatId).sort((vt,Dn)=>Dn.startedAt-vt.startedAt)[0];je&&je.snapshotAt===void 0&&(je.snapshotAt=performance.now(),Nl(je,"chat_snapshot_received",{status:Z.runtime.status,messageCount:Z.messages.length}))}if(C(je=>{const vt=d0e(je,Z);return Z==null||Z.runtime.chatId,Z==null||Z.runtime.provider,Z==null||Z.runtime.status,Z==null||Z.messages.length,vt?je:Z}),j((Z==null?void 0:Z.history.olderCursor)??null),H((Z==null?void 0:Z.history.hasOlder)??!1),ne(!0),ye(null),Z){const je=I2.getState();je.setForChat(Z.runtime.chatId,Z.slashCommands??[]),je.setLoadingForChat(Z.runtime.chatId,Z.slashCommandsLoading??!1)}});return()=>{Be.current.length,Be.current.reduce((Z,je)=>Z+je.chats.length,0),Q()}},[e,n]),v.useEffect(()=>{if(e)return n.subscribe({type:"workflows",chatId:e},Q=>{O2.getState().setRuns(Q.chatId,Q.runs)})},[e,n]),v.useEffect(()=>{if(ie)return;const Q=De[0];Q&&le(Q.groupKey)},[ie,De]),v.useEffect(()=>{if(!e||!ee||!J)return;if(De.some(Z=>Z.chats.some(je=>je.chatId===e))){_t===e&&ft(null);return}_t!==e&&t("/")},[e,J,t,_t,De,ee]),v.useEffect(()=>{w&&(le(w.runtime.projectId),_t===w.runtime.chatId&&ft(null))},[w,_t]),v.useEffect(()=>{if(!e||!ee||!_0e())return;const Q=De.flatMap(Z=>Z.chats).find(Z=>Z.chatId===e);Q!=null&&Q.unread&&n.command({type:"chat.markRead",chatId:e}).catch(Z=>{ye(Z instanceof Error?Z.message:String(Z))})},[e,fe,De,ee,n]),v.useEffect(()=>{k([]),R(!1),j(null),H(!1)},[e]);const nt=v.useMemo(()=>F0e(w,e),[e,w]),we=v.useMemo(()=>(nt==null?void 0:nt.runtime.projectId)??E0e(De,e)??ie,[e,nt==null?void 0:nt.runtime.projectId,ie,De]),tt=v.useMemo(()=>{const Q=we?M[we]??null:null;return we&&Q?(Tt.current={projectId:we,diffs:Q},Q):we&&Tt.current.projectId===we?Tt.current.diffs:Q},[we,M]);v.useEffect(()=>we?n.subscribe({type:"project-git",projectId:we},Z=>{D(je=>{const vt=Z??null;return a0e(je[we]??null,vt)||o0e(je[we]??null,vt)?je:{...je,[we]:vt}}),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 Ge=v.useMemo(()=>lD(E,(nt==null?void 0:nt.messages)??[]),[nt==null?void 0:nt.messages,E]),Xe=e??cD,_e=v.useMemo(()=>Ot.filter(Q=>Q.scopeId===Xe).map(Q=>Q.entry),[Xe,Ot]),Oe=v.useMemo(()=>[...Ge,..._e],[_e,Ge]),Ue=v.useMemo(()=>D2(Oe),[Oe]),Ve=v.useMemo(()=>h0e(Ue),[Ue]),Vt=v.useMemo(()=>Iye(Ue),[Ue]),Fe=(nt==null?void 0:nt.runtime)??null,Ht=(nt==null?void 0:nt.queuedMessages)??[],wn=((it==null?void 0:it.scopeId)===Xe&&(!Fe||Fe.status==="idle")?"starting":null)??(Fe==null?void 0:Fe.status)??null,pr=(nt==null?void 0:nt.availableProviders)??im,Sn=Pv(hm(Q=>Q.models)),Fn=v.useMemo(()=>e0e(pr,Sn),[pr,Sn]),Er=Pye(wn??void 0),K=Dye(wn??void 0),xe=(Fe==null?void 0:Fe.isDraining)??!1,Re=((zh=c==null?void 0:c.projects[0])==null?void 0:zh.localPath)??null,Qe=(Fe==null?void 0:Fe.localPath)??Re??((hc=De[0])==null?void 0:hc.localPath),ut=!!(ie??(Fe==null?void 0:Fe.projectId)??((fc=De[0])==null?void 0:fc.groupKey)??Re);v.useEffect(()=>{(it==null?void 0:it.scopeId)===Xe&&Fe!=null&&Fe.status&&Fe.status!=="idle"&&Dt(null)},[it,Xe,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!(it!=null&&it.ackedAt)||it.scopeId!==Xe||Fe!=null&&Fe.status&&Fe.status!=="idle")return;const Q=window.setTimeout(()=>{Dt(Z=>(Z==null?void 0:Z.scopeId)===Xe&&Z.ackedAt===it.ackedAt?null:Z)},300);return()=>window.clearTimeout(Q)},[it,Xe,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting")return;const Q=[...He.current.values()].filter(Z=>Z.serverChatId===e).sort((Z,je)=>je.startedAt-Z.startedAt)[0];!Q||Q.startingStatusAt!==void 0||(Q.startingStatusAt=performance.now(),Nl(Q,"runtime_status_starting",{status:Fe.status}))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||!Fe||Fe.status==="starting")return;const Q=[...He.current.values()].filter(Z=>Z.serverChatId===e).sort((Z,je)=>je.startedAt-Z.startedAt)[0];!Q||Q.startingRenderedAt!==void 0||(Nl(Q,"starting_not_observed",{status:Fe.status}),He.current.delete(Q.traceId))},[e,Fe]),v.useLayoutEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting"){wt.current=null;return}const Q=[...He.current.values()].filter(Z=>Z.serverChatId===e).sort((Z,je)=>je.startedAt-Z.startedAt)[0];Q&&wt.current!==Q.traceId&&(wt.current=Q.traceId,Q.startingRenderedAt=performance.now(),Nl(Q,"starting_render_committed",{totalMs:XF(Q.startedAt)}),He.current.delete(Q.traceId))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{It(Q=>{const Z=v0e(Q,Xe,Ge);return Z.length===Q.length&&Z.every((je,vt)=>je===Q[vt])?Q:Z})},[Xe,Ge]);const Ke=v.useCallback(async()=>{if(!(!e||!A||T||!L)){R(!0);try{const Q=await n.command({type:"chat.loadHistory",chatId:e,beforeCursor:A,limit:y0e});k(Z=>lD(Q.messages,Z)),j(Q.olderCursor),H(Q.hasOlder),ye(null)}catch(Q){const Z=Q instanceof Error?Q.message:String(Q);ye(Z)}finally{R(!1)}}},[e,L,A,T,n]),dt=v.useCallback(async Q=>{const Z=mi.getState(),je=e?Z.getComposerState(e):Z.getComposerState(fm),vt=await n.command({type:"chat.create",projectId:Q});Z.initializeComposerForChat(vt.chatId,{sourceState:je}),le(Q),ft(vt.chatId),t(`/chat/${vt.chatId}`),Ce(!1),ye(null)},[e,t,n]),cn=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]),yn=v.useCallback(async Q=>{try{const Z=Q.kind==="project_id"?null:Q.kind==="local_path"?Q.localPath:Q.project.localPath;Z&&jt(Z);const{projectId:je}=await cn(Q);await dt(je)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}finally{jt(null)}},[dt,cn]),or=v.useCallback(async Q=>{await yn({kind:"project_id",projectId:Q})},[yn]),si=v.useCallback(async Q=>{try{const Z=await n.command({type:"chat.fork",chatId:Q.chatId}),je=mi.getState();je.initializeComposerForChat(Z.chatId,{sourceState:je.getComposerState(Q.chatId)}),ft(Z.chatId),t(`/chat/${Z.chatId}`),Ce(!1),ye(null)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}},[t,n]),os=v.useCallback(async Q=>{await yn({kind:"local_path",localPath:Q})},[yn]),qr=v.useCallback(async Q=>{await yn({kind:"project_request",project:Q})},[yn]),uo=v.useCallback(async Q=>{try{await n.command({type:"update.check",force:Q==null?void 0:Q.force}),ye(null)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}},[n]),Fi=v.useCallback(async Q=>{y("awaiting_disconnect");try{const Z=await n.command({type:"update.install",version:Q});if(!Z.ok){_(),ye(null),await r.alert({title:Z.userTitle??"Update failed",description:Z.userMessage??"Kanna could not install the update. Try again later.",closeLabel:"OK"});return}if(Z.ok&&Z.action==="reload"){window.location.reload();return}ye(null)}catch(Z){_(),ye(Z instanceof Error?Z.message:String(Z))}},[_,r,y,n]),kt=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]),rn=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))}},[]),mn=v.useCallback(async(Q,Z)=>{var pc;const je=(Z==null?void 0:Z.attachments)??[],vt=$c(),Dn=$c(),$i=z2(Q,je),ea=e??cD;Dt({scopeId:ea,ackedAt:null});const Hi={traceId:Dn,optimisticId:vt,startedAt:performance.now(),serverChatId:e,routeChatIdAtSend:e,contentPreview:Q.slice(0,80)};He.current.set(Dn,Hi),Nl(Hi,"handle_send_called",{optimisticScopeId:ea,attachments:je.length,contentLength:Q.length,contentPreview:Hi.contentPreview});const mc=g0e(Ge,$i)+Ot.filter(er=>er.scopeId===ea&&er.signature===$i).length+1;It(er=>[...er,{id:vt,scopeId:ea,signature:$i,requiredMatchCount:mc,entry:{_id:`optimistic:${vt}`,kind:"user_prompt",content:Q,attachments:je,createdAt:Date.now()}}]),Nl(Hi,"optimistic_prompt_added",{optimisticId:vt,optimisticScopeId:ea});try{let er=ie??((pc=De[0])==null?void 0:pc.groupKey)??null;if(!e&&!er&&Re&&(er=(await n.command({type:"project.open",localPath:Re})).projectId,le(er)),!e&&!er)throw new Error("Open a project first");const Bh=gC.getState().autoResumeOnRateLimit,oi=await n.command({type:"chat.send",chatId:e??void 0,projectId:e?void 0:er??void 0,clientTraceId:Dn,provider:Z==null?void 0:Z.provider,content:Q,attachments:je,model:Z==null?void 0:Z.model,modelOptions:Z==null?void 0:Z.modelOptions,planMode:Z==null?void 0:Z.planMode,autoResumeOnRateLimit:Bh});if(Hi.ackAt=performance.now(),Hi.serverChatId=oi.chatId??Hi.serverChatId,oi.queued?(It(Bs=>b0e(Bs,vt,{queued:!0})),Dt(null)):Dt(Bs=>Bs&&{scopeId:!e&&oi.chatId?oi.chatId:Bs.scopeId,ackedAt:performance.now()}),Nl(Hi,"chat_send_ack_received",{resultChatId:oi.chatId??null,queued:oi.queued??!1}),!e&&oi.chatId){It(ju=>ju.map(Fh=>Fh.id===vt?{...Fh,scopeId:oi.chatId}:Fh));const Bs=mi.getState();Bs.setComposerState(oi.chatId,k0e(Z)??Bs.getComposerState(fm)),ft(oi.chatId),t(`/chat/${oi.chatId}`)}ye(null)}catch(er){throw It(Bh=>Bh.filter(oi=>oi.id!==vt)),Dt(null),Nl(Hi,"handle_send_failed",{error:er instanceof Error?er.message:String(er)}),He.current.delete(Dn),ye(er instanceof Error?er.message:String(er)),er}},[e,Re,t,Ot,ie,Ge,De,n]),pn=v.useCallback(async Q=>{if(e)try{await n.command({type:"message.steer",chatId:e,queuedMessageId:Q}),ye(null)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}},[e,n]),Kr=v.useCallback(async Q=>{if(e)try{await n.command({type:"message.dequeue",chatId:e,queuedMessageId:Q}),ye(null)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}},[e,n]),Za=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]),ho=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]),Yo=v.useCallback(async Q=>{const Z=await r.prompt({title:"Rename Chat",initialValue:Q.title,confirmLabel:"Rename"});if(!(!Z||Z===Q.title))try{await n.command({type:"chat.rename",chatId:Q.chatId,title:Z}),ye(null)}catch(je){ye(je instanceof Error?je.message:String(je))}},[r,n]),Os=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 je=uD(De,Q.chatId);t(je?`/chat/${je}`:"/")}}catch(je){ye(je instanceof Error?je.message:String(je))}},[e,r,t,De,n]),Ja=v.useCallback(async Q=>{try{if(await n.command({type:"chat.archive",chatId:Q.chatId}),Q.chatId===e){const Z=uD(De,Q.chatId);t(Z?`/chat/${Z}`:"/")}ye(null)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}},[e,t,De,n]),Jn=v.useCallback(async Q=>{try{ft(Q),await n.command({type:"chat.unarchive",chatId:Q}),t(`/chat/${Q}`),ye(null)}catch(Z){ft(null),ye(Z instanceof Error?Z.message:String(Z))}},[t,n]),fo=v.useCallback(async Q=>{try{await n.command({type:"project.remove",projectId:Q}),Il.getState().clearProject(Q),Ai.getState().clearProject(Q),(Fe==null?void 0:Fe.projectId)===Q&&t("/"),ye(null)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}},[t,Fe,n]),mo=v.useCallback(async(Q,Z)=>{try{await n.command({type:"project.setStar",projectId:Q,starred:Z}),ye(null)}catch(je){ye(je instanceof Error?je.message:String(je))}},[n]),po=v.useCallback(async Q=>{a(Q);try{await n.command({type:"sidebar.reorderProjectGroups",projectIds:Q}),ye(null)}catch(Z){a(null),ye(Z instanceof Error?Z.message:String(Z))}},[n]),_i=v.useCallback(async(Q,Z)=>{try{await n.command({type:"stack.create",title:Q,projectIds:Z}),ye(null)}catch(je){ye(je instanceof Error?je.message:String(je))}},[n]),Xo=v.useCallback(async(Q,Z)=>{try{await n.command({type:"stack.rename",stackId:Q,title:Z}),ye(null)}catch(je){ye(je instanceof Error?je.message:String(je))}},[n]),Qo=v.useCallback(async Q=>{try{await n.command({type:"stack.remove",stackId:Q}),ye(null)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}},[n]),wi=v.useCallback(async(Q,Z)=>{try{await n.command({type:"stack.addProject",stackId:Q,projectId:Z}),ye(null)}catch(je){ye(je instanceof Error?je.message:String(je))}},[n]),Zo=v.useCallback(async(Q,Z)=>{try{await n.command({type:"stack.removeProject",stackId:Q,projectId:Z}),ye(null)}catch(je){ye(je instanceof Error?je.message:String(je))}},[n]),go=v.useCallback(async(Q,Z,je)=>{try{const vt=mi.getState(),Dn=e?vt.getComposerState(e):vt.getComposerState(fm),$i=await n.command({type:"chat.create",projectId:Q,stackId:Z,stackBindings:je});vt.initializeComposerForChat($i.chatId,{sourceState:Dn}),le(Q),ft($i.chatId),t(`/chat/${$i.chatId}`),Ce(!1),ye(null)}catch(vt){ye(vt instanceof Error?vt.message:String(vt))}},[e,t,n]),Ee=v.useCallback(async Q=>{try{const Z=await n.command({type:"stack.listWorktrees",projectId:Q});return ye(null),Z.worktrees}catch(Z){return ye(Z instanceof Error?Z.message:String(Z)),[]}},[n]),W=v.useCallback(async()=>await n.command({type:"sessions.importClaude"}),[n]),ve=v.useCallback(async Q=>{const Z=ui.getState();ye(null),await n.command({type:"system.openExternal",...Q,editor:Q.action==="open_editor"?Q.editor??{preset:Z.editorPreset,commandTemplate:Z.editorCommandTemplate}:void 0})},[n]),Gt=v.useCallback(async(Q,Z)=>{var vt,Dn;const je=(Fe==null?void 0:Fe.localPath)??((vt=c==null?void 0:c.projects[0])==null?void 0:vt.localPath)??((Dn=De[0])==null?void 0:Dn.localPath);if(je)try{await ve({action:Q,localPath:je,editor:Z})}catch($i){ye($i instanceof Error?$i.message:String($i))}},[c==null?void 0:c.projects,ve,Fe==null?void 0:Fe.localPath,De]),ar=v.useCallback(async Q=>{var Z;try{if(typeof navigator>"u"||!((Z=navigator.clipboard)!=null&&Z.writeText))throw new Error("Clipboard is not available");await navigator.clipboard.writeText(Q),ye(null)}catch(je){ye(je instanceof Error?je.message:String(je))}},[]),Yr=v.useCallback(async(Q,Z="open_editor",je)=>{try{await ve({action:Z,localPath:Q.path,line:Q.line,column:Q.column,editor:je})}catch(vt){ye(vt instanceof Error?vt.message:String(vt))}},[ve]),Jo=v.useCallback(async(Q,Z)=>{try{await ve({action:Q,localPath:Z})}catch(je){ye(je instanceof Error?je.message:String(je))}},[ve]),lc=v.useCallback(()=>{var Z;const Q=B0e({selectedProjectId:ie,sidebarProjectId:(Z=De[0])==null?void 0:Z.groupKey,fallbackLocalProjectPath:Re});if(Q){yn(Q);return}t("/")},[Re,t,ie,De,yn]),vo=v.useCallback(()=>Ce(!0),[]),el=v.useCallback(()=>Ce(!1),[]),Op=v.useCallback(()=>ze(!0),[]),Dh=v.useCallback(()=>ze(!1),[]),zp=v.useCallback(()=>lt(!0),[]),cc=v.useCallback(()=>lt(!1),[]),zs=v.useCallback(async(Q,Z,je)=>{if(e)try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Q,result:{questions:Z,answers:je}})}catch(vt){ye(vt instanceof Error?vt.message:String(vt))}},[e,n]),Ph=v.useCallback(async(Q,Z,je,vt)=>{if(e){Z&&mi.getState().setChatComposerPlanMode(e,!1);try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Q,result:{confirmed:Z,...je?{clearContext:!0}:{},...vt?{message:vt}:{}}})}catch(Dn){ye(Dn instanceof Error?Dn.message:String(Dn))}}},[e,n]),uc=v.useCallback(async(Q,Z,je,vt)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Q,toolUseId:Z,result:{questions:je,answers:vt}})}catch(Dn){ye(Dn instanceof Error?Dn.message:String(Dn))}},[e,n]),bo=v.useCallback(async(Q,Z,je)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Q,toolUseId:Z,result:je})}catch(vt){ye(vt instanceof Error?vt.message:String(vt))}},[e,n]),Oh=v.useCallback(async(Q,Z)=>{if(e)try{await n.command({type:"chat.toolRequestAnswer",chatId:e,toolRequestId:Q,decision:Z})}catch(je){ye(je instanceof Error?je.message:String(je))}},[e,n]),dc=T0e(g,m==null?void 0:m.status);return{socket:n,activeChatId:e,activeProjectId:we,sidebarData:Ye,localProjects:c,updateSnapshot:m,chatSnapshot:w,chatDiffSnapshot:tt,keybindings:z,appSettings:F,pushConfig:B,llmProvider:G,connectionStatus:P,sidebarReady:ee,uiRestartActive:dc.active,uiRestartLabel:dc.label,localProjectsReady:ue,commandError:Mt,startingLocalPath:ln,sidebarOpen:oe,sidebarCollapsed:ke,messages:Ue,queuedMessages:Ht,previousPrompt:Ve,latestToolIds:Vt,runtime:Fe,runtimeStatus:wn,isHistoryLoading:T,hasOlderHistory:L,availableProviders:Fn,isProcessing:Er,canCancel:K,isDraining:xe,navbarLocalPath:Qe,editorLabel:Ne,hasSelectedProject:ut,addProjectModalOpen:Ze,openSidebar:vo,closeSidebar:el,collapseSidebar:Op,expandSidebar:Dh,openAddProjectModal:zp,closeAddProjectModal:cc,loadOlderHistory:Ke,handleCreateChat:or,handleForkChat:si,handleOpenLocalProject:os,handleCreateProject:qr,handleCheckForUpdates:uo,handleInstallUpdate:Fi,handleForceReload:kt,handleReadAppSettings:ct,handleWriteAppSettings:Qt,handleTestMcpServer:Ut,handleSetChatPolicyOverride:nn,handleWriteCloudflareTunnel:Rt,handleWriteClaudeAuth:xt,handleTestOAuthToken:mt,handleReadLlmProvider:Ct,handleWriteLlmProvider:pt,handleValidateLlmProvider:$t,handleSignOut:rn,handleSend:mn,handleSteerQueuedMessage:pn,handleRemoveQueuedMessage:Kr,handleCancel:Za,handleStopDraining:ho,handleRenameChat:Yo,handleArchiveChat:Ja,handleOpenArchivedChat:Jn,handleDeleteChat:Os,handleHideProject:fo,handleToggleProjectStar:mo,handleReorderProjectGroups:po,stacks:Ye.stacks,handleCreateStack:_i,handleRenameStack:Xo,handleRemoveStack:Qo,handleAddProjectToStack:wi,handleRemoveProjectFromStack:Zo,handleCreateStackChat:go,handleListStackWorktrees:Ee,importClaudeSessions:W,handleCopyPath:ar,handleOpenExternal:Gt,handleOpenExternalPath:Jo,handleOpenLocalLink:Yr,handleCompose:lc,handleAskUserQuestion:zs,handleExitPlanMode:Ph,handleSubagentAskUserQuestion:uc,handleSubagentExitPlanMode:bo,handleToolRequestAnswer:Oh}}const fD=/<thinking>([\s\S]*?)<\/thinking>/gi;function H0e(e){const t=[];let n=0;fD.lastIndex=0;let r;for(;(r=fD.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 U0e(t)}function U0e(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 F2=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(tb,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"font-medium uppercase tracking-wider",children:"Thinking"}),u.jsx(As,{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})})]})}),ZF=v.memo(function({message:t}){const n=v.useMemo(()=>H0e(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(F2,{content:r.content},i):u.jsx(Wo,{remarkPlugins:Fa,components:$a,children:r.content},i))})}),JF=v.memo(function({message:t}){return u.jsx("div",{className:"px-0.5 w-full max-w-[70ch]",children:u.jsx(F2,{content:t.text})})}),jp=({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 V0e(e){const t=e.split(`
2635
+ `},i),s}function Tve(e,t){return e&&"run"in e?async function(n,r){const i=kI(n,{file:r,...t});await e.run(i,r)}:function(n,r){return kI(n,{file:r,...e||t})}}function EI(e){if(e)throw e}var Yw,NI;function Rve(){if(NI)return Yw;NI=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 m=e.call(d,"constructor"),f=d.constructor&&d.constructor.prototype&&e.call(d.constructor.prototype,"isPrototypeOf");if(d.constructor&&!m&&!f)return!1;var g;for(g in d);return typeof g>"u"||e.call(d,g)},o=function(d,m){n&&m.name==="__proto__"?n(d,m.name,{enumerable:!0,configurable:!0,value:m.newValue,writable:!0}):d[m.name]=m.newValue},a=function(d,m){if(m==="__proto__")if(e.call(d,m)){if(r)return r(d,m).value}else return;return d[m]};return Yw=function c(){var d,m,f,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(m in d)f=a(_,m),g=a(d,m),_!==g&&(E&&g&&(s(g)||(b=i(g)))?(b?(b=!1,y=f&&i(f)?f:[]):y=f&&s(f)?f:{},o(_,{name:m,newValue:c(E,y,g)})):typeof g<"u"&&o(_,{name:m,newValue:g}));return _},Yw}var Ave=Rve();const Xw=kx(Ave);function aC(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 jve(){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 m=e[++s];let f=-1;if(c){o(c);return}for(;++f<i.length;)(d[f]===null||d[f]===void 0)&&(d[f]=i[f]);i=d,m?Mve(m,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 Mve(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 m=d;if(a&&n)throw m;return i(m)}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:Lve,dirname:Ive,extname:Dve,join:Pve,sep:"/"};function Lve(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');Rp(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 Ive(e){if(Rp(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 Dve(e){Rp(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 Pve(...e){let t=-1,n;for(;++t<e.length;)Rp(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":Ove(n)}function Ove(e){Rp(e);const t=e.codePointAt(0)===47;let n=zve(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function zve(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 Rp(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const Bve={cwd:Fve};function Fve(){return"/"}function lC(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function $ve(e){if(typeof e=="string")e=new URL(e);else if(!lC(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 Hve(e)}function Hve(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 Qw=["history","path","basename","stem","extname","dirname"];class oF{constructor(t){let n;t?lC(t)?n={path:t}:typeof t=="string"||Uve(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":Bve.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<Qw.length;){const s=Qw[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)Qw.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?Ro.basename(this.path):void 0}set basename(t){Jw(t,"basename"),Zw(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){TI(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(Zw(t,"extname"),TI(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){lC(t)&&(t=$ve(t)),Jw(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){Jw(t,"stem"),Zw(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 ii(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 Zw(e,t){if(e&&e.includes(Ro.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+Ro.sep+"`")}function Jw(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function TI(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function Uve(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Vve=(function(e){const r=this.constructor.prototype,i=r[e],s=function(){return i.apply(s,arguments)};return Object.setPrototypeOf(s,r),s}),Wve={}.hasOwnProperty;class b2 extends Vve{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=jve()}copy(){const t=new b2;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(Xw(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(nS("data",this.frozen),this.namespace[t]=n,this):Wve.call(this.namespace,t)&&this.namespace[t]||void 0:t?(nS("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=Ev(t),r=this.parser||this.Parser;return eS("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),eS("process",this.parser||this.Parser),tS("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(s,o){const a=Ev(t),c=r.parse(a);r.run(c,a,function(m,f,g){if(m||!f||!g)return d(m);const b=f,y=r.stringify(b,g);Kve(y)?g.value=y:g.result=y,d(m,g)});function d(m,f){m||!f?o(m):s?s(f):n(void 0,f)}}}processSync(t){let n=!1,r;return this.freeze(),eS("processSync",this.parser||this.Parser),tS("processSync",this.compiler||this.Compiler),this.process(t,i),AI("processSync","process",n),r;function i(s,o){n=!0,EI(s),r=o}}run(t,n,r){RI(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=Ev(n);i.run(t,c,d);function d(m,f,g){const b=f||t;m?a(m):o?o(b):r(void 0,b,g)}}}runSync(t,n){let r=!1,i;return this.run(t,n,s),AI("runSync","run",r),i;function s(o,a){EI(o),i=a,r=!0}}stringify(t,n){this.freeze();const r=Ev(n),i=this.compiler||this.Compiler;return tS("stringify",i),RI(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(nS("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[m,...f]=d;c(m,f)}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=Xw(!0,i.settings,d.settings))}function a(d){let m=-1;if(d!=null)if(Array.isArray(d))for(;++m<d.length;){const f=d[m];s(f)}else throw new TypeError("Expected a list of plugins, not `"+d+"`")}function c(d,m){let f=-1,g=-1;for(;++f<r.length;)if(r[f][0]===d){g=f;break}if(g===-1)r.push([d,...m]);else if(m.length>0){let[b,...y]=m;const _=r[g][1];aC(_)&&aC(b)&&(b=Xw(!0,_,b)),r[g]=[d,b,...y]}}}}const Gve=new b2().freeze();function eS(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function tS(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function nS(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 RI(e){if(!aC(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function AI(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function Ev(e){return qve(e)?e:new oF(e)}function qve(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function Kve(e){return typeof e=="string"||Yve(e)}function Yve(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Xve="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",jI=[],MI={allowDangerousHtml:!0},Qve=/^(https?|ircs?|mailto|xmpp)$/i,Zve=[{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=Jve(e),n=ebe(e);return tbe(t.runSync(t.parse(n),n),e)}function Jve(e){const t=e.rehypePlugins||jI,n=e.remarkPlugins||jI,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...MI}:MI;return Gve().use(Hge).use(n).use(Tve,r).use(t)}function ebe(e){const t=e.children||"",n=new oF;return typeof t=="string"&&(n.value=t),n}function tbe(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,s=t.disallowedElements,o=t.skipHtml,a=t.unwrapDisallowed,c=t.urlTransform||nbe;for(const m of Zve)Object.hasOwn(t,m.from)&&(""+m.from+(m.to?"use `"+m.to+"` instead":"remove it")+Xve+m.id,void 0);return r2(e,d),Xpe(e,{Fragment:u.Fragment,components:i,ignoreInvalidStyle:!0,jsx:u.jsx,jsxs:u.jsxs,passKeys:!0,passNode:!0});function d(m,f,g){if(m.type==="raw"&&g&&typeof f=="number")return o?g.children.splice(f,1):g.children[f]={type:"text",value:m.value},f;if(m.type==="element"){let b;for(b in Kw)if(Object.hasOwn(Kw,b)&&Object.hasOwn(m.properties,b)){const y=m.properties[b],_=Kw[b];(_===null||_.includes(m.tagName))&&(m.properties[b]=c(String(y||""),b,m))}}if(m.type==="element"){let b=n?!n.includes(m.tagName):s?s.includes(m.tagName):!1;if(!b&&r&&typeof f=="number"&&(b=!r(m,f,g)),b&&g&&typeof f=="number")return a&&m.children?g.children.splice(f,1,...m.children):g.children.splice(f,1),f}}}function nbe(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||Qve.test(e.slice(0,t))?e:""}const Nv=new Map;function rbe(e){return`${e.id}|${e.contentUrl}|${e.size??0}`}function wy(e){const t=rbe(e),n=Nv.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(Nv.get(t)??{status:"loading"})),v.useEffect(()=>{if(n&&n.status!=="loading")return;let c=!1;const d=t;return t2(e.contentUrl,rB).then(m=>{if(c||a.current!==d)return;const f={status:"ready",content:m.content,truncated:m.truncated};Nv.set(d,f),i(f)}).catch(m=>{if(c||a.current!==d)return;const g={status:"error",message:m instanceof Error?m.message:"Unable to load preview."};Nv.set(d,g),i(g)}),()=>{c=!0}},[n,t,e.contentUrl]),r}function ibe({source:e}){const t=wy(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 Tv=new Map;function sbe(e){return`${e.id}|${e.contentUrl}|${e.size??0}|${e.mimeType}`}function obe({source:e}){const t=sbe(e),n=Tv.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(Tv.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 t2(e.contentUrl,rB).then(_=>{if(b||a.current!==y)return;const w={status:"ready",table:Ode(_.content,g),truncated:_.truncated};Tv.set(y,w),i(w)}).catch(_=>{if(b||a.current!==y)return;const w={status:"error",message:_ instanceof Error?_.message:"Unable to load preview."};Tv.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,...m]=c.rows,f=[r.truncated?"Preview truncated to 1024 KB.":null,c.truncatedRows?`Showing first ${c.rows.length} of ${c.rowCount} rows.`:null,c.truncatedColumns?`Showing first ${J1} of ${c.columnCount} columns.`:null].filter(Boolean);return u.jsxs("div",{className:"space-y-2 p-3",children:[f.length?u.jsx("div",{className:"rounded-xl border border-border bg-background px-3 py-2 text-xs text-muted-foreground",children:f.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:m.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 abe({source:e}){const t=wy(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(lbe,{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 lbe({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 cbe({source:e}){const t=wy(e),n=v.useMemo(()=>t.status==="ready"?Pde(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 ube({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 dbe({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 hbe=200*1024;function fbe(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 mbe({source:e}){const t=wy(e),n=t.status==="ready"&&t.content.length<=hbe,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(()=>K8),void 0).then(async c=>{if(o)return;const d=await c.codeToHtml(t.content,{lang:fbe(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 pbe(e){var r;const t=vbe(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 gbe(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 vbe(e){return typeof window>"u"?e:new URL(e,document.baseURI||window.location.href).toString()}function jh({source:e,open:t,onOpenChange:n}){const r=v.useCallback(()=>n(!1),[n]);return u.jsx(ro,{open:t&&e!==null,onOpenChange:n,children:u.jsx(js,{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(_be,{source:e,onClose:r}):null})})}const bbe=120,xbe=.5;function ybe({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>bbe||a>xbe}function _be({source:e,onClose:t}){const n=Sbe(e),[r,i]=v.useState(0),s=v.useRef(null),o=v.useCallback(f=>{s.current={y:f.clientY,lastY:f.clientY,lastT:Date.now()};try{f.currentTarget.setPointerCapture(f.pointerId)}catch{}},[]),a=v.useCallback(f=>{if(!s.current)return;const g=f.clientY-s.current.y;g<0||(s.current.lastY=f.clientY,s.current.lastT=Date.now(),i(g))},[]),c=v.useCallback(f=>{const g=s.current;s.current=null;try{f.currentTarget.releasePointerCapture(f.pointerId)}catch{}g&&(ybe({startY:g.y,lastY:g.lastY,lastT:g.lastT,endY:f.clientY,now:Date.now()})?t():i(0))},[t]),d=v.useCallback(()=>{pbe(e)},[e]),m=v.useCallback(()=>gbe(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(io,{className:"truncate text-base",children:e.displayName}),u.jsx(up,{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(wbe(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(Pe,{type:"button",variant:"outline",onClick:d,children:[u.jsx(Fq,{className:"mr-2 h-4 w-4"}),"Share"]}),e.origin==="offer_download"?u.jsxs(Pe,{type:"button",onClick:m,children:[u.jsx(wk,{className:"mr-2 h-4 w-4"}),"Download"]}):null]})]})}function wbe(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=Rh(t);return n==="image"?Dpe:n==="pdf"?aI:n==="audio"?ube:n==="video"?dbe:n==="table"?obe:n==="markdown"?ibe:n==="json"?cbe:n==="code"?mbe:Th(t).kind==="external"?aI:abe}function Sbe(e){const t={id:e.id,displayName:e.displayName,mimeType:e.mimeType,size:e.size??0,contentUrl:e.contentUrl,relativePath:e.relativePath??""},n=Rh(t),r=gy(n,e.mimeType),i=e.size?` · ${Mh(e.size)}`:"";return`${r}${i}`}function Ap(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 Cbe(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function kbe({path:e,linkText:t}){const n=v.useMemo(()=>c2(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=Cbe(e),c=t||a,d=Ipe(c,28),m=r.kind==="ready"?r.mimeType:"application/octet-stream",f=r.kind==="ready"?r.size:0,g={id:`local-file-${n}`,kind:"file",displayName:d,absolutePath:e,relativePath:e,contentUrl:n,mimeType:m,size:f};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=Rh(g),y=gy(b,m),_=f>0?Mh(f):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"?Th(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(jh,{source:s?Ap(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 Ebe(e,t){var n,r,i,s,o,a,c,d,m,f,g;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}},openrouter:{...e.providerDefaults.openrouter,...(c=t.providerDefaults)==null?void 0:c.openrouter,modelOptions:{}}},cloudflareTunnel:{...e.cloudflareTunnel,...t.cloudflareTunnel},claudeAuth:{tokens:((d=t.claudeAuth)==null?void 0:d.tokens)??e.claudeAuth.tokens,concurrencyDefault:((m=t.claudeAuth)==null?void 0:m.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,...(g=t.claudeDriver)==null?void 0:g.lifecycle}},globalPromptAppend:t.globalPromptAppend??e.globalPromptAppend}}const ji=Oi()(e=>({settings:null,hydrationStatus:"idle",setHydrationStatus:t=>e({hydrationStatus:t}),setFromServer:t=>e({settings:t,hydrationStatus:"ready"}),applyOptimisticPatch:t=>e(n=>({settings:n.settings?Ebe(n.settings,t):n.settings}))})),Nbe=[],Tbe=e=>{var t;return((t=e.settings)==null?void 0:t.customMcpServers)??Nbe},aF=v.createContext(void 0),Rbe=e=>e==="light"||e==="dark"||e==="system";function Abe(e){return e==="dark"?"black-translucent":"default"}function LI(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 II(e){if(typeof document>"u"||typeof window>"u")return;const t=getComputedStyle(document.body).backgroundColor||getComputedStyle(document.documentElement).backgroundColor;t&&LI("theme-color",t),LI("apple-mobile-web-app-status-bar-style",Abe(e)),document.documentElement.style.colorScheme=e}const vb=()=>typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",DI=e=>{if(typeof document>"u")return;const t=e==="system"?vb():e;document.documentElement.classList.toggle("dark",t==="dark")},jbe=()=>{var t;const e=(t=ji.getState().settings)==null?void 0:t.theme;return e&&Rbe(e)?e:"system"};function Mbe({children:e}){const t=ji(o=>{var a;return(a=o.settings)==null?void 0:a.theme}),n=ji(o=>o.applyOptimisticPatch),[r,i]=v.useState(jbe);v.useEffect(()=>{!t||t===r||i(t)},[t,r]),v.useEffect(()=>{DI(r)},[r]),v.useEffect(()=>{const o=r==="system"?vb():r;II(o)},[r]),v.useEffect(()=>{if(r!=="system")return;const o=window.matchMedia("(prefers-color-scheme: dark)"),a=()=>{DI("system"),II(vb())};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"?vb():r;return{theme:r,resolvedTheme:o,setTheme:a=>{i(a),n({theme:a})}}},[n,r]);return u.jsx(aF.Provider,{value:s,children:e})}function Sy(){const e=v.useContext(aF);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}function Lbe({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})},m=g=>{o&&s({x:g.clientX-o.x,y:g.clientY-o.y})},f=()=>a(null);return es.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(Pe,{variant:"ghost",size:"icon","aria-label":"Zoom out",className:"h-9 w-9",onClick:()=>r(g=>c(g-.25)),children:u.jsx(nO,{className:"h-4 w-4"})}),u.jsx(Pe,{variant:"ghost",size:"icon","aria-label":"Zoom in",className:"h-9 w-9",onClick:()=>r(g=>c(g+.25)),children:u.jsx(to,{className:"h-4 w-4"})}),u.jsx(Pe,{variant:"ghost",size:"icon","aria-label":"Reset view",className:"h-9 w-9",onClick:()=>{r(1),s({x:0,y:0})},children:u.jsx(kq,{className:"h-4 w-4"})}),u.jsx(Pe,{variant:"ghost",size:"icon","aria-label":"Close",className:"h-9 w-9",onClick:t,children:u.jsx(Ds,{className:"h-4 w-4"})})]}),u.jsx("div",{className:"flex-1 overflow-hidden touch-none cursor-grab active:cursor-grabbing",onPointerDown:d,onPointerMove:m,onPointerUp:f,onPointerLeave:f,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 rS=null;function Ibe(){return rS||(rS=X(()=>import("./mermaid.core-CoJEFYct.js").then(e=>e.bm),[]).then(e=>e.default)),rS}function Dbe({source:e}){const{resolvedTheme:t}=Sy(),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,m]=v.useState(!1),[f,g]=v.useState(!1),b=v.useCallback(()=>m(!1),[]),y=async()=>{await navigator.clipboard.writeText(e),g(!0),setTimeout(()=>g(!1),2e3)};return v.useEffect(()=>{let _=!1;return Ibe().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(iS,{source:e}):r.status==="loading"?u.jsx("div",{className:"relative group/mermaid",children:u.jsx(iS,{source:e})}):a?u.jsxs("div",{className:"relative group/mermaid",children:[u.jsx(iS,{source:e}),u.jsx(PI,{showSource:a,onToggleSource:()=>c(_=>!_),onCopy:y,copied:f,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(PI,{showSource:a,onToggleSource:()=>c(_=>!_),onCopy:y,copied:f,onZoom:()=>m(!0)}),d&&u.jsx(Lbe,{svg:r.svg,onClose:b})]})}function PI({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(Pe,{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(XG,{className:"h-4 w-4"})}),u.jsx(Pe,{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(KS,{className:"h-4 w-4"})}),u.jsx(Pe,{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(rs,{className:"h-4 w-4 text-success"}):u.jsx(Da,{className:"h-4 w-4"})})]})}const Pbe=200*1024,Obe={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 zbe(e){return Obe[e.toLowerCase()]??null}const Bbe=/^<pre[^>]*>/,Fbe=/<\/pre>\s*$/,$be=/^<code[^>]*>/,Hbe=/<\/code>\s*$/;function Ube(e){return e.replace(Bbe,"").replace(Fbe,"").replace($be,"").replace(Hbe,"")}function qf({source:e,lang:t}){const{resolvedTheme:n}=Sy(),r=n==="dark"?"github-dark":"github-light",i=zbe(t),s=i!==null&&e.length<=Pbe,[o,a]=v.useState(null);v.useEffect(()=>{if(!s||i===null)return;let m=!1;return X(()=>Promise.resolve().then(()=>K8),void 0).then(async f=>{if(m)return;const g=await f.codeToHtml(e,{lang:i,theme:r});m||a({source:e,theme:r,lang:i,html:Ube(g)})}).catch(()=>{typeof console<"u"&&console.warn("[transcript] Shiki unavailable; falling back to plain code")}),()=>{m=!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 lF={readonly:!1,localLinkMode:"open"},cF=v.createContext(lF);function Vbe({children:e,value:t}){return u.jsx(cF.Provider,{value:{...lF,...t},children:e})}function Cy(){return v.useContext(cF)}const uF=()=>{},Wbe=v.createContext(uF);function dF({children:e,onOpenLocalLink:t}){return u.jsx(Wbe.Provider,{value:t??uF,children:e})}const cC={Task:jb,TaskOutput:jb,Bash:Mx,Glob:Ld,Grep:Ld,ExitPlanMode:uj,Read:X5,Edit:nG,Write:iG,Delete:dG,NotebookEdit:mh,WebFetch:JV,TodoWrite:vW,WebSearch:Ld,KillShell:Qq,AskUserQuestion:eO,Skill:Wq,EnterPlanMode:uj},hF=aK;function fF(e){return cC[e]?cC[e]:hF}function mF({icon:e,className:t}){return u.jsx(e,{className:t})}function Ka({children:e,className:t}){return u.jsx("div",{className:de("flex gap-3 justify-start items-center",t),children:e})}function pF({children:e,className:t}){return u.jsx("div",{className:de("flex items-center gap-1.5 text-xs",t),children:e})}function lu({children:e,className:t}){return u.jsx("span",{className:de("font-medium text-foreground/80",t),children:e})}function Gbe({children:e}){return u.jsx("span",{className:"text-muted-foreground",children:e})}function qbe({children:e,className:t}){return u.jsxs(Ka,{className:de("px-0.5 text-xs tracking-wide",t),children:[u.jsx("div",{className:"w-full h-[1px] bg-border"}),u.jsx(lu,{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 x2({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(As,{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 uC({label:e,children:t,copyText:n}){const[r,i]=v.useState(!1),s=n??rh(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(Pe,{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(rs,{className:"h-3.5 w-3.5 text-success"}):u.jsx(Da,{className:"h-4 w-4"})})]})]})}function gF({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 ky({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 rh(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(Array.isArray(e))return e.map(rh).join("");if(e&&typeof e=="object"&&"props"in e){const t=e.props;return rh(t.children)}return""}function OI(e,t){return v.isValidElement(e)?v.cloneElement(e,{className:de(e.props.className,t)}):e}function vF({children:e,...t}){const[n,r]=v.useState(!1),i=rh(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(Pe,{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(rs,{className:"h-4 w-4 text-success"}):u.jsx(Da,{className:"h-4 w-4"})})]})}function iS({source:e}){return u.jsx(vF,{children:u.jsx("code",{className:"block text-xs whitespace-pre language-mermaid",children:e})})}const y2={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:vF,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(Dbe,{source:rh(e)});const s=i.find(a=>a.startsWith("language-")),o=s?s.slice(9):"";return o?u.jsx(qf,{source:rh(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]=OI(r,"mt-0"));const i=n.length-1,s=n[i];return s!==void 0&&(n[i]=OI(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"&&Lpe(e)?c2(e):e;return u.jsx("img",{src:n,...t})}};function Kbe({children:e,href:t,onClick:n,...r}){const i=Cy(),s=Ape(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=dC(e).trim();return u.jsx(kbe,{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 Ybe(){return{...y2,a:e=>u.jsx(Kbe,{...e})}}const Fa=[VB],$a=Ybe();function dC(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(dC).join(""):v.isValidElement(e)?dC(e.props.children):""}({...y2});function _2({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",m=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(Y5,{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," · ",Mh(e.size)]})]})]}),m?u.jsx(lB,{progress:o??null,onCancel:a,size:d?"sm":"md",cancelLabel:`Cancel upload of ${e.displayName}`}):null,r&&!m?u.jsx(bF,{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:m}){const f=e.kind==="mention"?"text":Rh(e),g=Zbe(f),b=e.kind==="mention",y=b?Xbe(e.displayName):e.displayName,_=b?Qbe(e.displayName):"",w=i!==void 0,C=!!m,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"}):m?u.jsx("div",{className:"truncate text-[11px] text-muted-foreground",children:m}):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," · ",Mh(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(mF,{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(lB,{progress:i??null,onCancel:s,size:"sm",cancelLabel:`Cancel upload of ${e.displayName}`}):null,n&&!w?u.jsx(bF,{displayName:e.displayName,onRemove:n}):null]})}function Xbe(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function Qbe(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}function bF({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(Ds,{className:"h-3.5 w-3.5"})})}function Zbe(e){switch(e){case"image":return Y5;case"pdf":return wq;case"markdown":return jq;case"json":return YW;case"table":return oG;case"code":return QW;case"text":return Ax;case"archive":return qW;case"audio":return JW;case"video":return cG;default:return X5}}function Mh(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 Rv={};function zI(e){return!e.isCollapsed&&!e.hasPreviewAttachment&&e.patch===void 0&&e.patchError===void 0&&!e.isPatchLoading}function Jbe(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 xF(e){return e.isUntracked}function exe(e){return xF(e)?e.path.includes("/"):!1}function sS(e){return u.jsxs(Di,{delayDuration:0,children:[u.jsx(Pi,{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 yF({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(nO,{className:"h-3 w-3",strokeWidth:3}):e?u.jsx(rs,{className:"h-3 w-3",strokeWidth:3}):null})}function w2(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 txe(e){return e?`Last fetched ${w2(e)}`:"No local fetch recorded"}function nxe({entry:e,isPendingPush:t=!1}){const n=w2(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(Gd,{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(Gd,{className:"size-3"})})}):null]})}function BI(e){switch(e.kind){case"local":return 0;case"pull_request":return 1;case"remote":default:return 2}}function rxe(e){const t=new Map;for(const n of e){const r=t.get(n.name);(!r||BI(n)<BI(r))&&t.set(n.name,n)}return t}function ixe(e,t){const n=rxe([...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 sxe({open:e,onOpenChange:t,onGetGitHubPublishInfo:n,onCheckGitHubRepoAvailability:r,onPublish:i}){const[s,o]=v.useState(null),[a,c]=v.useState(!1),[d,m]=v.useState(""),[f,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),m(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=f.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,f,r,e,d]);async function j(){if(!(!d.trim()||!f.trim())){A(!0);try{const H=await i({owner:d.trim(),name:f.trim(),visibility:b,description:_});H!=null&&H.ok&&t(!1)}finally{A(!1)}}}const L=!!(s!=null&&s.ghInstalled&&s.authenticated&&d.trim()&&f.trim()&&(C!=null&&C.available)&&!k&&!R);return u.jsx(ro,{open:e,onOpenChange:t,children:u.jsxs(js,{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(io,{children:"Push to GitHub"}),u.jsx(up,{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:m,children:[u.jsx(Ys,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:u.jsx(Ca,{placeholder:"Select owner"})}),u.jsx(Xs,{children:((s==null?void 0:s.owners)??[]).map(H=>u.jsx(Jr,{value:H,children:u.jsxs("span",{className:"flex items-center gap-2",children:[H===(s==null?void 0:s.activeAccountLogin)?u.jsx(Lx,{className:"size-4 text-muted-foreground"}):u.jsx(fW,{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(dn,{value:f,onChange:H=>g(H.target.value),placeholder:"my-repo",className:"pl-9 pr-10"}),u.jsx(fq,{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(Di,{delayDuration:0,children:[u.jsx(Pi,{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(rs,{className:"size-4"}):u.jsx(ym,{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(Ax,{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(Ys,{className:"pl-[11px] [&>span]:flex [&>span]:items-center [&>span]:gap-2",children:u.jsx(Ca,{placeholder:"Select visibility"})}),u.jsxs(Xs,{children:[u.jsx(Jr,{value:"private",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(GG,{className:"size-4 text-muted-foreground"}),u.jsx("span",{className:"pl-[1px]",children:"Private"})]})}),u.jsx(Jr,{value:"public",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(RG,{className:"size-4 text-muted-foreground"}),u.jsx("span",{className:"pl-[1px]",children:"Public"})]})})]})]})})]})]}),u.jsxs(Yl,{children:[u.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),u.jsx(Pe,{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 _F({value:e,onChange:t,placeholder:n,disabled:r,trailingAction:i}){return u.jsxs("div",{className:"relative",children:[u.jsx(Ld,{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(dn,{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 Kc({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(J5,{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:w2(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 oxe({open:e,onOpenChange:t,branchList:n,currentBranchName:r,onPreviewMergeBranch:i,onMergeBranch:s}){const[o,a]=v.useState(""),[c,d]=v.useState(null),[m,f]=v.useState(null),[g,b]=v.useState(null),[y,_]=v.useState(!1),[w,C]=v.useState(!1),E=v.useMemo(()=>n?ixe(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),f(null),b(null),_(!1),C(!1))},[e]),v.useEffect(()=>{if(!e||!L){f(null),b(null),_(!1);return}let D=!1;return f(null),b(null),_(!0),i(L).then(z=>{D||f(z)}).catch(z=>{D||b(z instanceof Error?z.message:String(z))}).finally(()=>{D||_(!1)}),()=>{D=!0}},[i,e,L]);const H=!L||!m||y||w||m.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(ro,{open:e,onOpenChange:t,children:u.jsxs(js,{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(io,{children:["Merge into ",r??"current branch"]}),u.jsx(up,{children:"Choose a branch to continue."})]}),u.jsx(_F,{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(Kc,{title:"Default Branch",entries:R?[R]:[],emptyLabel:"No default branch available.",selectedName:c,onSelect:D=>d(D.name)}),u.jsx(Kc,{title:"Recent Branches",entries:A,emptyLabel:"No recent branches.",selectedName:c,onSelect:D=>d(D.name)}),u.jsx(Kc,{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}):m?u.jsxs("div",{className:"flex items-start gap-2",children:[m.status==="up_to_date"?u.jsx(rs,{className:"mt-1 size-3.5 shrink-0 text-success"}):m.status==="conflicts"?u.jsx(ym,{className:"mt-1 size-3.5 shrink-0 text-warning"}):m.status==="mergeable"?u.jsx(Z5,{className:"mt-1 size-3.5 shrink-0 text-muted-foreground"}):u.jsx(ym,{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:m.message}),m.detail?u.jsx("div",{className:"line-clamp-2 whitespace-pre-wrap text-xs text-muted-foreground",children:m.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(Pe,{variant:"ghost",size:"sm",onClick:()=>t(!1),children:"Cancel"}),u.jsx(Pe,{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 axe({currentBranchName:e,onListBranches:t,onPreviewMergeBranch:n,onMergeBranch:r,onCheckoutBranch:i,onCreateBranch:s}){const[o,a]=v.useState(!1),[c,d]=v.useState(!1),[m,f]=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&&(f(!0),R(null),t().then(G=>k(G)).catch(G=>{R(G instanceof Error?G.message:String(G))}).finally(()=>{f(!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(rc,{open:o,onOpenChange:a,children:[u.jsx(ic,{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(fh,{className:"h-3.5 w-3.5 shrink-0"})]})}),u.jsx(Ga,{align:"start",className:"w-[320px] p-2",children:u.jsxs("div",{className:"space-y-2",children:[u.jsx(_F,{value:y,onChange:_,placeholder:w==="pull_requests"?"Search pull requests":"Search branches",disabled:m||g,trailingAction:u.jsx(Pe,{variant:"ghost",size:"sm",onClick:()=>void B(),disabled:m||g,className:"h-7 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:"+ New"})}),u.jsx(fi,{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:m?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(Kc,{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(Kc,{title:"Recent",entries:M,emptyLabel:"No recent branches.",disabled:g,stickyTitle:!0,onSelect:G=>{$(G)}}),u.jsx(Kc,{title:"Local",entries:D,emptyLabel:"No local branches.",disabled:g,stickyTitle:!0,onSelect:G=>{$(G)}}),u.jsx(Kc,{title:"Remote",entries:z,emptyLabel:"No remote branches.",disabled:g,stickyTitle:!0,onSelect:G=>{$(G)}})]})}),L?u.jsx(Pe,{variant:"default",size:"sm",disabled:m||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(CG,{className:"mr-1.5 inline h-3.5 w-3.5 shrink-0"}),"Merge branch into ",L,"..."]})}):null]})}),u.jsx(oxe,{open:c,onOpenChange:d,branchList:E,currentBranchName:L,onPreviewMergeBranch:n,onMergeBranch:r})]})}function lxe({file:e,rootRef:t,projectId:n,isCollapsed:r,isChecked:i,editorLabel:s,diffRenderMode:o,wrapLines:a,onToggleCollapsed:c,onToggleChecked:d,fileActions:m,patch:f,patchError:g,isPatchLoading:b,onLoadPatch:y}){const _=xF(e),w=exe(e),[C,E]=v.useState(null),k=v.useRef(null),T=v.useRef(null),{sentinelRef:R,isStuck:A}=Ede({rootRef:t,disabled:r}),j=v.useMemo(()=>Jbe(n,e),[e,n]),L=j!==null,H=zI({isCollapsed:r,hasPreviewAttachment:L,patch:f,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(Th(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||f!==void 0){c();return}if(b)return;if(!(g!==void 0||zI({isCollapsed:!1,hasPreviewAttachment:L,patch:f,patchError:g,isPatchLoading:b}))){c();return}y(e.path).then(()=>{c()}).catch(()=>{})}return u.jsxs(wu,{children:[u.jsx(Su,{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(yF,{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(xm,{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(fh,{className:"h-3.5 w-3.5 shrink-0"}):u.jsx(q5,{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(_2,{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}):f!==void 0?u.jsx(Cde,{patch:f,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(jh,{source:j&&C===j.id?Ap(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(),m.onOpenFile(e.path)},children:[u.jsx(_k,{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(),m.onOpenInFinder(e.path)},children:[u.jsx(jx,{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(),m.onDiscardFile(e.path)},className:"text-destructive hover:bg-destructive/10 focus:bg-destructive/10",children:[u.jsx(bu,{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(),_&&m.onIgnoreFile(e.path)},children:[u.jsx(oj,{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&&m.onIgnoreFolder(e.path)},children:[u.jsx(oj,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium",children:"Ignore folder..."})]}),u.jsx(D4,{}),u.jsxs(In,{onSelect:O=>{O.stopPropagation(),m.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(),m.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 cxe({projectId:e,diffs:t,editorLabel:n,diffRenderMode:r,wrapLines:i,onOpenFile:s,onOpenInFinder:o,onDiscardFile:a,onIgnoreFile:c,onIgnoreFolder:d,onCopyFilePath:m,onCopyRelativePath:f,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:m,onCopyRelativePath:f}),[s,o,a,c,d,m,f]),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,J]=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]),Ce=Ai(_e=>{var Oe;return e?((Oe=_e.projectUi[e])==null?void 0:Oe.viewMode)??(z?"changes":"history"):z?"changes":"history"}),ke=Ai(_e=>{var Oe;return e?((Oe=_e.projectUi[e])==null?void 0:Oe.collapsedPaths)??Rv:Rv}),ze=Ai(_e=>{var Oe;return e?((Oe=_e.projectUi[e])==null?void 0:Oe.summary)??"":""}),Ze=Ai(_e=>{var Oe;return e?((Oe=_e.projectUi[e])==null?void 0:Oe.description)??"":""}),lt=Ai(_e=>_e.reconcileCollapsedPaths),Mt=Ai(_e=>_e.toggleCollapsedPath),ye=Ai(_e=>_e.setViewMode),ln=Ai(_e=>_e.setCommitDraft),jt=Ai(_e=>_e.clearCommitDraft),_t=_v(_e=>e?_e.checkedPathsByProjectId[e]??Rv:Rv),ft=_v(_e=>_e.reconcileProject),Ot=_v(_e=>_e.setChecked),It=_v(_e=>_e.setAllChecked),it=v.useRef(z);v.useEffect(()=>{e&&lt(e,le)},[le,oe,e,lt]),v.useEffect(()=>{const _e=Object.fromEntries(t.files.map(Ue=>[Ue.path,Ue.patchDigest])),Oe=Ue=>ie.current[Ue]===_e[Ue];ee(Ue=>Object.fromEntries(Object.entries(Ue).filter(([Ve])=>le.includes(Ve)&&Oe(Ve)))),ue(Ue=>Object.fromEntries(Object.entries(Ue).filter(([Ve])=>le.includes(Ve)&&Oe(Ve)))),J(Ue=>Object.fromEntries(Object.entries(Ue).filter(([Ve])=>le.includes(Ve)&&Oe(Ve)))),ie.current=_e},[t.files,le,oe]),v.useEffect(()=>{e&&ft(e,le)},[le,oe,e,ft]),v.useEffect(()=>{if(!e)return;if(it.current!==z){ye(e,z?"changes":"history"),it.current=z;return}it.current=z},[z,e,ye]);const Dt=v.useMemo(()=>t.files.filter(_e=>_t[_e.path]??!0).map(_e=>_e.path),[_t,t.files]),fe=Dt.length,Ae=t.files.length>0&&fe===t.files.length,He=fe>0&&fe<t.files.length,Je=ze.trim(),qe=Je.length>0,bt=$!==null,wt=O||bt,Tt=((Xe=t.branchHistory)==null?void 0:Xe.entries)??[],Ne=t.behindCount??0,De=t.aheadCount??0,Be=t.hasUpstream===!0,Ye=t.hasUpstream===!1&&!!t.branchName,ct=t.hasOriginRemote===!0,nn=t.branchName?t.branchName.split("/").map(_e=>encodeURIComponent(_e)).join("/"):null,Qt=Ye?"publish":Ne>0?"pull":"fetch",Ut=t.originRepoSlug&&nn?`https://github.com/${t.originRepoSlug}/compare/${nn}?expand=1`:null,Rt=!!(Be&&Ut&&t.branchName&&t.branchName!==t.defaultBranchName),xt=t.status==="ready"&&fe>0&&!wt,mt=t.status==="ready"&&fe>0&&qe&&!wt,Ct=ct?"commit_and_push":"commit_only",pt=t.branchName??"current branch";async function $t(_e){if(mt){B(_e);try{const Oe=await A({paths:Dt,summary:Je,description:Ze.trim(),mode:_e});(Oe!=null&&Oe.ok||Oe!=null&&Oe.localCommitCreated)&&e&&jt(e)}finally{B(null)}}}async function nt(){if(xt){F(!0);try{const _e=await C({paths:Dt});e&&ln(e,{summary:_e.subject,description:_e.body})}finally{F(!1)}}}function we(_e){if(!(!(_e.metaKey||_e.ctrlKey)||_e.key!=="Enter")){if(_e.preventDefault(),qe){$t(Ct);return}nt()}}async function tt(_e=Qt){if(!(t.status!=="ready"||U)){G(!0);try{await j(_e)}finally{G(!1)}}}const Ge=v.useCallback(async _e=>{var Oe;if(Y[_e]!==void 0||ge[_e])return Y[_e]??"";J(Ue=>({...Ue,[_e]:!0})),ue(Ue=>{if(!(_e in Ue))return Ue;const{[_e]:Ve,...Vt}=Ue;return Vt});try{const Ue=await L(_e);ee(Vt=>({...Vt,[_e]:Ue}));const Ve=(Oe=t.files.find(Vt=>Vt.path===_e))==null?void 0:Oe.patchDigest;return Ve&&(ie.current={...ie.current,[_e]:Ve}),Ue}catch(Ue){const Ve=Ue instanceof Error?Ue.message:String(Ue);throw ue(Vt=>({...Vt,[_e]:Ve})),Ue}finally{J(Ue=>{const{[_e]:Ve,...Vt}=Ue;return Vt})}},[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(axe,{currentBranchName:t.branchName,onListBranches:g,onPreviewMergeBranch:b,onMergeBranch:y,onCheckoutBranch:_,onCreateBranch:w})}),t.status==="ready"?ct?Qt==="publish"?u.jsxs(Pe,{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(nb,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Publish Branch"})]}):u.jsxs("div",{className:"flex items-center gap-1",children:[Qt==="fetch"?u.jsxs(Di,{delayDuration:0,children:[u.jsx(Pi,{asChild:!0,children:u.jsxs(Pe,{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(iO,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"Fetch"})]})}),u.jsx(vi,{children:txe(t.lastFetchedAt)})]}):u.jsxs(Pe,{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(wk,{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:Ne})]}),Be&&De>0?u.jsxs(Pe,{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(nb,{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:De})]}):null,Rt&&Ut?u.jsxs(Pe,{variant:"ghost",size:"sm",onClick:()=>{typeof window>"u"||window.open(Ut,"_blank","noopener,noreferrer")},className:"h-7 gap-1.5 px-2 text-xs hover:!bg-transparent hover:!border-border/0",children:[u.jsx(J5,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:"PR"})]}):null]}):u.jsxs(Pe,{variant:"default",size:"sm",onClick:()=>P(!0),className:"h-7 gap-1.5 px-3 text-xs",children:[u.jsx(NG,{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:[Ce==="changes"?u.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-muted-foreground/70",children:[u.jsx(yF,{checked:Ae,mixed:He,label:He?"Select all files for commit":Ae?"Unselect all files from commit":"Select all files for commit",onClick:()=>{!e||t.files.length===0||It(e,le,He?!0:!Ae)}}),u.jsxs("span",{children:[fe," 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(fi,{value:Ce,onValueChange:_e=>{e&&ye(e,_e)},size:"sm",optionClassName:"flex-1 justify-center",options:[{value:"changes",label:"Changes"},{value:"history",label:"History"}]})})}),Ce==="changes"?u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(sS,{label:"Unified diff",active:r==="unified",onClick:()=>H("unified"),children:u.jsx(Rq,{className:"h-4 w-4"})}),u.jsx(sS,{label:"Side-by-side diff",active:r==="split",onClick:()=>H("split"),children:u.jsx(LW,{className:"h-4 w-4"})}),u.jsx(sS,{label:i?"Disable word wrap":"Enable word wrap",active:i,onClick:()=>M(!i),children:u.jsx(sK,{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(Pe,{size:"sm",onClick:()=>void E(),children:"Init Git"})]})}):Ce==="history"?Tt.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:Tt.map((_e,Oe)=>u.jsx(nxe,{entry:_e,isPendingPush:Oe<De},_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 Oe=ke[_e.path]??!0,Ue=_t[_e.path]??!0;return u.jsx(lxe,{file:_e,rootRef:ne,projectId:e,isCollapsed:Oe,isChecked:Ue,editorLabel:n,diffRenderMode:r,wrapLines:i,onToggleCollapsed:()=>{e&&Mt(e,_e.path)},onToggleChecked:()=>{e&&Ot(e,_e.path,!Ue)},fileActions:D,patch:Y[_e.path],patchError:V[_e.path],isPatchLoading:!!ge[_e.path],onLoadPatch:Ge},_e.path)}),Ce==="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(dn,{value:ze,onChange:_e=>{e&&ln(e,{summary:_e.target.value,description:Ze})},onKeyDown:we,placeholder:"Commit message (override)",className:"rounded-t-xl rounded-b-none px-3",disabled:wt||t.status!=="ready"}),u.jsx(La,{value:Ze,onChange:_e=>{e&&ln(e,{summary:ze,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:wt||t.status!=="ready"}),u.jsx("div",{className:"w-full flex flex-row",children:u.jsxs(wu,{children:[u.jsx(Su,{asChild:!0,children:u.jsx(Pe,{type:"button",className:"-mt-px w-full rounded-xl",disabled:qe?!mt:!xt,onClick:()=>{if(qe){$t(Ct);return}nt()},children:u.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[qe?bt?u.jsx(bn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):Ct==="commit_and_push"?t.hasUpstream?u.jsx(nb,{strokeWidth:2.5,className:"size-3 shrink-0"}):u.jsx(Z5,{strokeWidth:2.5,className:"size-3 shrink-0"}):u.jsx(rs,{strokeWidth:2.5,className:"size-3 shrink-0"}):O?u.jsx(bn,{strokeWidth:2.5,className:"size-3 shrink-0 animate-spin"}):u.jsx(dq,{strokeWidth:2.5,className:"size-3 shrink-0"}),u.jsx("span",{className:"min-w-0 truncate text-left",children:qe?bt?$==="commit_only"?"Committing...":"Committing & Pushing...":Ct==="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:!qe||!mt,onSelect:_e=>{_e.stopPropagation(),$t("commit_only")},children:"Commit Only"})}):null]})})]})})]}):null]})})]}),u.jsx(sxe,{open:te,onOpenChange:P,onGetGitHubPublishInfo:k,onCheckGitHubRepoAvailability:T,onPublish:R})]})})}const uxe=v.memo(cxe);function dxe(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function hxe(e,t){const n=getComputedStyle(e.ownerDocument.body),r=parseFloat(n.fontSize);return t*r}function fxe(e){return e/100*window.innerHeight}function mxe(e){return e/100*window.innerWidth}function pxe(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 Kf({groupSize:e,panelElement:t,styleProp:n}){let r;const[i,s]=pxe(n);switch(s){case"%":{r=i/100*e;break}case"px":{r=i;break}case"rem":{r=hxe(t,i);break}case"em":{r=dxe(t,i);break}case"vh":{r=fxe(i);break}case"vw":{r=mxe(i);break}}return r}function Li(e){return parseFloat(e.toFixed(3))}function ih({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 hC(e){const{panels:t}=e,n=ih({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 m=Kf({groupSize:n,panelElement:i,styleProp:s.collapsedSize});o=Li(m/n*100)}let a;if(s.defaultSize!==void 0){const m=Kf({groupSize:n,panelElement:i,styleProp:s.defaultSize});a=Li(m/n*100)}let c=0;if(s.minSize!==void 0){const m=Kf({groupSize:n,panelElement:i,styleProp:s.minSize});c=Li(m/n*100)}let d=100;if(s.maxSize!==void 0){const m=Kf({groupSize:n,panelElement:i,styleProp:s.maxSize});d=Li(m/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 An(e,t="Assertion error"){if(!e)throw Error(t)}function fC(e,t){return Array.from(t).sort(e==="horizontal"?gxe:vxe)}function gxe(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function vxe(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function wF(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function SF(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 bxe({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}=SF(r,o),d=e==="horizontal"?a:c;d<s&&(s=d,i=o)}return An(i,"No rect found"),i}let Av;function xxe(){return Av===void 0&&(typeof matchMedia=="function"?Av=!!matchMedia("(pointer:coarse)").matches:Av=!1),Av}function CF(e){const{element:t,orientation:n,panels:r,separators:i}=e,s=fC(n,Array.from(t.children).filter(wF).map(y=>({element:y}))).map(({element:y})=>y),o=[];let a=!1,c=!1,d=-1,m=-1,f=0,g,b=[];{let y=-1;for(const _ of s)_.hasAttribute("data-panel")&&(y++,_.ariaDisabled===null&&(f++,d===-1&&(d=y),m=y))}if(f>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=bxe({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=xxe()?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>m;!a&&!j&&o.push({group:e,groupSize:ih({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,_5;let kF=(_5=class{constructor(){Sl(this,Fl,{})}addListener(t,n){const r=vr(this,Fl)[t];return r===void 0?vr(this,Fl)[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=vr(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(){ps(this,Fl,{})}removeListener(t,n){const r=vr(this,Fl)[t];if(r!==void 0){const i=r.indexOf(n);i>=0&&r.splice(i,1)}}},Fl=new WeakMap,_5),Oo=new Map;const EF=new kF;function yxe(e){Oo=new Map(Oo),Oo.delete(e)}function FI(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 ku(){return Oo}function S2(e,t){return EF.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),EF.emit("groupChange",{group:e,prev:n,next:t})}function _xe(e,t,n){let r,i={x:1/0,y:1/0};for(const s of t){const o=SF(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 wxe(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function Sxe(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:UI(e),b:UI(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();An(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:HI($I(n.a)),b:HI($I(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 Cxe=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function kxe(e){const t=getComputedStyle(NF(e)??e).display;return t==="flex"||t==="inline-flex"}function Exe(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||kxe(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"||Cxe.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function $I(e){let t=e.length;for(;t--;){const n=e[t];if(An(n,"Missing node"),Exe(n))return n}return null}function HI(e){return e&&Number(getComputedStyle(e).zIndex)||0}function UI(e){const t=[];for(;e;)t.push(e),e=NF(e);return t}function NF(e){const{parentNode:t}=e;return wxe(t)?t.host:t}function Nxe(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 Txe({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!wF(n)||n.contains(e)||e.contains(n))return!0;if(Sxe(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(Nxe(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function C2(e,t){const n=[];return t.forEach((r,i)=>{if(i.disabled)return;const s=CF(i),o=_xe(i.orientation,s,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&Txe({groupElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&n.push(o.hitRegion)}),n}function Rxe(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function di(e,t,n=0){return Math.abs(Li(e)-Li(t))<=n}function Ao(e,t){return di(e,t)?0:e>t?1:-1}function Ad({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=Li(r),r}function Ym({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(di(e,0))return t;const o=s==="imperative-api",a=Object.values(t),c=Object.values(i),d=[...a],[m,f]=r;An(m!=null,"Invalid first pivot index"),An(f!=null,"Invalid second pivot index");let g=0;switch(s){case"keyboard":{{const _=e<0?f:m,w=n[_];An(w,`Panel constraints not found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const T=a[_];if(An(T!=null,`Previous layout not found for panel index ${_}`),di(T,C)){const R=k-T;Ao(R,Math.abs(e))>0&&(e=e<0?0-R:R)}}}{const _=e<0?m:f,w=n[_];An(w,`No panel constraints found for index ${_}`);const{collapsedSize:C=0,collapsible:E,minSize:k=0}=w;if(E){const T=a[_];if(An(T!=null,`Previous layout not found for panel index ${_}`),di(T,k)){const R=T-C;Ao(R,Math.abs(e))>0&&(e=e<0?0-R:R)}}}break}default:{const _=e<0?f:m,w=n[_];An(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?f:m,C=0;for(;;){const k=a[w];An(k!=null,`Previous layout not found for panel index ${w}`);const T=Ad({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?m:f;for(;_>=0&&_<n.length;){const w=Math.abs(e)-Math.abs(g),C=a[_];An(C!=null,`Previous layout not found for panel index ${_}`);const E=C-w,k=Ad({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:C,size:E});if(!di(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(Rxe(c,d))return i;{const _=e<0?f:m,w=a[_];An(w!=null,`Previous layout not found for panel index ${_}`);const C=w+g,E=Ad({overrideDisabledPanels:o,panelConstraints:n[_],prevSize:w,size:C});if(d[_]=E,!di(E,C)){let k=C-E,T=e<0?f:m;for(;T>=0&&T<n.length;){const R=d[T];An(R!=null,`Previous layout not found for panel index ${T}`);const A=R+k,j=Ad({overrideDisabledPanels:o,panelConstraints:n[T],prevSize:R,size:A});if(di(R,j)||(k-=j-R,d[T]=j),di(k,0))break;e>0?T--:T++}}}const b=Object.values(d).reduce((_,w)=>w+_,0);if(!di(b,100,.1))return i;const y=Object.keys(i);return d.reduce((_,w,C)=>(_[y[C]]=w,_),{})}function cu(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 uu({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(!di(i,100)&&r.length>0)for(let a=0;a<t.length;a++){const c=r[a];An(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];An(c!=null,`No layout data found for index ${a}`);const d=r[a];An(d!=null,`No layout data found for index ${a}`);const m=Ad({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:c,size:d});d!=m&&(s+=d-m,r[a]=m)}if(!di(s,0))for(let a=0;a<t.length;a++){const c=r[a];An(c!=null,`No layout data found for index ${a}`);const d=c+s,m=Ad({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:c,size:d});if(c!==m&&(s-=m-c,r[a]=m,di(s,0)))break}const o=Object.keys(e);return r.reduce((a,c,d)=>(a[o[d]]=c,a),{})}function TF({groupId:e,panelId:t}){const n=()=>{const a=ku();for(const[c,{defaultLayoutDeferred:d,derivedPanelConstraints:m,layout:f,groupSize:g,separatorToPanels:b}]of a)if(c.id===e)return{defaultLayoutDeferred:d,derivedPanelConstraints:m,group:c,groupSize:g,layout:f,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:m,group:f,groupSize:g,layout:b,separatorToPanels:y}=n(),_=f.panels.findIndex(k=>k.id===t),w=_===f.panels.length-1,C=Ym({delta:w?c-a:a-c,initialLayout:b,panelConstraints:m,pivotIndices:w?[_-1,_]:[_,_+1],prevLayout:b,trigger:"imperative-api"}),E=uu({layout:C,panelConstraints:m});cu(b,E)||Ha(f,{defaultLayoutDeferred:d,derivedPanelConstraints:m,groupSize:g,layout:E,separatorToPanels:y})};return{collapse:()=>{const{collapsible:a,collapsedSize:c}=r(),{mutableValues:d}=i(),m=s();a&&m!==c&&(d.expandToSize=m,o(c))},expand:()=>{const{collapsible:a,collapsedSize:c,minSize:d}=r(),{mutableValues:m}=i(),f=s();if(a&&f===c){let g=m.expandToSize??d;g===0&&(g=1),o(g)}},getSize:()=>{const{group:a}=n(),c=s(),{element:d}=i(),m=a.orientation==="horizontal"?d.offsetWidth:d.offsetHeight;return{asPercentage:c,inPixels:m}},isCollapsed:()=>{const{collapsible:a,collapsedSize:c}=r(),d=s();return a&&di(c,d)},resize:a=>{const{group:c}=n(),{element:d}=i(),m=ih({group:c}),f=Kf({groupSize:m,panelElement:d,styleProp:a}),g=Li(f/m*100);o(g)}}}function VI(e){if(e.defaultPrevented)return;const t=ku();C2(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=TF({groupId:n.group.id,panelId:r.id});s&&i!==void 0&&(s.resize(i),e.preventDefault())}}})}function bb(e){const t=ku();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 RF({groupId:e}){const t=()=>{const n=ku();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=uu({layout:n,panelConstraints:i});return r?a:(cu(a,d)||Ha(s,{defaultLayoutDeferred:r,derivedPanelConstraints:i,groupSize:o,layout:d,separatorToPanels:c}),d)}}}function Dc(e,t){const n=bb(e),r=Gl(n.id,!0),i=n.separators.find(m=>m.element===e);An(i,"Matching separator not found");const s=r.separatorToPanels.get(i);An(s,"Matching panels not found");const o=s.map(m=>n.panels.indexOf(m)),a=RF({groupId:n.id}).getLayout(),c=Ym({delta:t,initialLayout:a,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:a,trigger:"keyboard"}),d=uu({layout:c,panelConstraints:r.derivedPanelConstraints});cu(a,d)||Ha(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:d,separatorToPanels:r.separatorToPanels})}function WI(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=bb(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&Dc(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&Dc(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&Dc(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&Dc(t,-5);break}case"End":{e.preventDefault(),Dc(t,100);break}case"Enter":{e.preventDefault();const r=bb(t),i=Gl(r.id,!0),{derivedPanelConstraints:s,layout:o,separatorToPanels:a}=i,c=r.separators.find(g=>g.element===t);An(c,"Matching separator not found");const d=a.get(c);An(d,"Matching panels not found");const m=d[0],f=s.find(g=>g.panelId===m.id);if(An(f,"Panel metadata not found"),f.collapsible){const g=o[m.id],b=f.collapsedSize===g?r.mutableState.expandedPanelSizes[m.id]??f.minSize:f.collapsedSize;Dc(t,b-g)}break}case"F6":{e.preventDefault();const r=bb(t).separators.map(o=>o.element),i=Array.from(r).findIndex(o=>o===e.currentTarget);An(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(),Dc(t,-100);break}}}let Ud={cursorFlags:0,state:"inactive"};const k2=new kF;function du(){return Ud}function Axe(e){return k2.addListener("change",e)}function jxe(e){const t=Ud,n={...Ud};n.cursorFlags=e,Ud=n,k2.emit("change",{prev:t,next:n})}function Vd(e){const t=Ud;Ud=e,k2.emit("change",{prev:t,next:e})}function GI(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=ku(),n=C2(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)}),Vd({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}const Mxe=e=>e,oS=()=>{},AF=1,jF=2,MF=4,LF=8,qI=3,KI=12;let jv;function YI(){return jv===void 0&&(jv=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(jv=!0)),jv}function Lxe({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&&YI()){const s=(e&AF)!==0,o=(e&jF)!==0,a=(e&MF)!==0,c=(e&LF)!==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 YI()?r>0&&i>0?"move":r>0?"ew-resize":"ns-resize":r>0&&i>0?"grab":r>0?"col-resize":"row-resize"}}const XI=new WeakMap;function E2(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=XI.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&e.adoptedStyleSheets.push(n));const r=du();switch(r.state){case"active":case"hover":{const i=Lxe({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}}XI.set(e,{prevStyle:t,styleSheet:n})}function IF({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:i,pointerDownAtPoint:s,prevCursorFlags:o}){let a=0;n.forEach(d=>{const{group:m,groupSize:f}=d,{orientation:g,panels:b}=m,{disableCursor:y}=m.mutableState;let _=0;s?g==="horizontal"?_=(t.clientX-s.x)/f*100:_=(t.clientY-s.y)/f*100:g==="horizontal"?_=t.clientX<0?-100:100:_=t.clientY<0?-100:100;const w=r.get(m),C=i.get(m);if(!w||!C)return;const{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:T,layout:R,separatorToPanels:A}=C;if(k&&R&&A){const j=Ym({delta:_,initialLayout:w,panelConstraints:k,pivotIndices:d.panels.map(L=>b.indexOf(L)),prevLayout:R,trigger:"mouse-or-touch"});if(cu(j,R)){if(_!==0&&!y)switch(g){case"horizontal":{a|=_<0?AF:jF;break}case"vertical":{a|=_<0?MF:LF;break}}}else Ha(d.group,{defaultLayoutDeferred:E,derivedPanelConstraints:k,groupSize:T,layout:j,separatorToPanels:A})}});let c=0;t.movementX===0?c|=o&qI:c|=a&qI,t.movementY===0?c|=o&KI:c|=a&KI,jxe(c),E2(e)}function QI(e){const t=ku(),n=du();switch(n.state){case"active":IF({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function ZI(e){if(e.defaultPrevented)return;const t=du(),n=ku();switch(t.state){case"active":{if(e.buttons===0){Vd({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(r=>{const i=Gl(r.group.id,!0);Ha(r.group,i)});return}IF({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const r=C2(e,n);r.length===0?t.state!=="inactive"&&Vd({cursorFlags:0,state:"inactive"}):Vd({cursorFlags:0,hitRegions:r,state:"hover"}),E2(e.currentTarget);break}}}function JI(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(du().state){case"hover":Vd({cursorFlags:0,state:"inactive"})}}function eD(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=du();switch(t.state){case"active":Vd({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(E2(e.currentTarget),t.hitRegions.forEach(n=>{const r=Gl(n.group.id,!0);Ha(n.group,r)}),e.preventDefault())}}function tD(e){let t=0,n=0;const r={};for(const s of e)if(s.defaultSize!==void 0){t++;const o=Li(s.defaultSize);n+=o,r[s.panelId]=o}else r[s.panelId]=void 0;const i=e.length-t;if(i!==0){const s=Li((100-n)/i);for(const o of e)o.defaultSize===void 0&&(r[o.panelId]=s)}return r}function Ixe(e,t,n){if(!n[0])return;const r=e.panels.find(c=>c.element===t);if(!r||!r.onResize)return;const i=ih({group:e}),s=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,a={asPercentage:Li(s/i*100),inPixels:s};r.mutableValues.prevSize=a,r.onResize(a,r.id,o)}function Dxe(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 Pxe({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 f of e.panels){const g=r[f.id]??0;switch(f.panelConstraints.groupResizeBehavior){case"preserve-pixel-size":{o=!0;const b=g/100*n,y=Li(b/t*100);a.set(f.id,y),i+=y;break}case"preserve-relative-size":default:{c.push(f.id),s+=g;break}}}if(!o||c.length===0)return r;const d=100-i,m={...r};if(a.forEach((f,g)=>{m[g]=f}),s>0)for(const f of c){const g=r[f]??0;m[f]=Li(g/s*d)}else{const f=Li(d/c.length);for(const g of c)m[g]=f}return m}function Oxe(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 vd=new Map;function zxe(e){let t=!0;An(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=ih({group:e});if(E===0)return;const k=Gl(e.id);if(!k)return;const T=hC(e),R=k.defaultLayoutDeferred?tD(T):k.layout,A=Pxe({group:e,nextGroupSize:E,prevGroupSize:k.groupSize,prevLayout:R}),j=uu({layout:A,panelConstraints:T});if(!k.defaultLayoutDeferred&&cu(k.layout,j)&&Dxe(k.derivedPanelConstraints,T)&&k.groupSize===E)return;Ha(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:T,groupSize:E,layout:j,separatorToPanels:k.separatorToPanels})}}else Ixe(e,C,w)}});s.observe(e.element),e.panels.forEach(y=>{An(!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=ih({group:e}),a=hC(e),c=e.panels.map(({id:y})=>y).join(",");let d=e.mutableState.defaultLayout;d&&(Oxe(e.panels,d)||(d=void 0));const m=e.mutableState.layouts[c]??d??tD(a),f=uu({layout:m,panelConstraints:a}),g=e.element.ownerDocument;vd.set(g,(vd.get(g)??0)+1);const b=new Map;return CF(e).forEach(y=>{y.separator&&b.set(y.separator,y.panels)}),Ha(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:a,groupSize:o,layout:f,separatorToPanels:b}),e.separators.forEach(y=>{An(!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",WI)}),vd.get(g)===1&&(g.addEventListener("dblclick",VI,!0),g.addEventListener("pointerdown",GI,!0),g.addEventListener("pointerleave",QI),g.addEventListener("pointermove",ZI),g.addEventListener("pointerout",JI),g.addEventListener("pointerup",eD,!0)),function(){t=!1,vd.set(g,Math.max(0,(vd.get(g)??0)-1)),yxe(e),e.separators.forEach(y=>{y.element.removeEventListener("keydown",WI)}),vd.get(g)||(g.removeEventListener("dblclick",VI,!0),g.removeEventListener("pointerdown",GI,!0),g.removeEventListener("pointerleave",QI),g.removeEventListener("pointermove",ZI),g.removeEventListener("pointerout",JI),g.removeEventListener("pointerup",eD,!0)),s.disconnect()}}function Bxe(){const[e,t]=v.useState({}),n=v.useCallback(()=>t({}),[]);return[e,n]}function N2(e){const t=v.useId();return`${e??t}`}const Eu=typeof window<"u"?v.useLayoutEffect:v.useEffect;function dm(e){const t=v.useRef(e);return Eu(()=>{t.current=e},[e]),v.useCallback((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[t])}function T2(...e){return dm(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function R2(e){const t=v.useRef({...e});return Eu(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const DF=v.createContext(null);function Fxe(e,t){const n=v.useRef({getLayout:()=>({}),setLayout:Mxe});v.useImperativeHandle(t,()=>n.current,[]),Eu(()=>{Object.assign(n.current,RF({groupId:e}))})}function PF({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:s,groupRef:o,id:a,onLayoutChange:c,onLayoutChanged:d,orientation:m="horizontal",resizeTargetMinimumSize:f={coarse:20,fine:10},style:g,...b}){const y=v.useRef({onLayoutChange:{},onLayoutChanged:{}}),_=dm(D=>{cu(y.current.onLayoutChange,D)||(y.current.onLayoutChange=D,c==null||c(D))}),w=dm(D=>{cu(y.current.onLayoutChanged,D)||(y.current.onLayoutChanged=D,d==null||d(D))}),C=N2(a),E=v.useRef(null),[k,T]=Bxe(),R=v.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:f,separators:[]}),A=T2(E,s);Fxe(C,o);const j=dm((D,z)=>{const O=du(),F=FI(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=R2({defaultLayout:n,disableCursor:r}),H=v.useMemo(()=>({get disableCursor(){return!!L.disableCursor},getPanelStyles:j,id:C,orientation:m,registerPanel:D=>{const z=R.current;return z.panels=fC(m,[...z.panels,D]),T(),()=>{z.panels=z.panels.filter(O=>O!==D),T()}},registerSeparator:D=>{const z=R.current;return z.separators=fC(m,[...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=FI(C),$=Gl(C);F&&$&&Ha(F,{...$,derivedPanelConstraints:hC(F)})},toggleSeparatorDisabled:(D,z)=>{const O=R.current.separators.find(F=>F.id===D);O&&(O.disabled=z)}}),[j,C,T,m,L]),M=v.useRef(null);return Eu(()=>{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:m,panels:z.panels,resizeTargetMinimumSize:z.resizeTargetMinimumSize,separators:z.separators};M.current=F;const $=zxe(F),{defaultLayoutDeferred:B,derivedPanelConstraints:U,layout:G}=Gl(F.id,!0);!B&&U.length>0&&(_(G),w(G));const te=S2(C,P=>{const{defaultLayoutDeferred:Y,derivedPanelConstraints:ee,layout:V}=P.next;if(Y||ee.length===0)return;const ue=F.panels.map(({id:J})=>J).join(",");F.mutableState.layouts[ue]=V,ee.forEach(J=>{if(J.collapsible){const{layout:ne}=P.prev??{};if(ne){const ie=di(J.collapsedSize,V[J.panelId]),le=di(J.collapsedSize,ne[J.panelId]);ie&&!le&&(F.mutableState.expandedPanelSizes[J.panelId]=ne[J.panelId])}}});const ge=du().state!=="active";_(V),ge&&w(V)});return()=>{M.current=null,$(),te()}},[i,C,w,_,m,k,L]),v.useEffect(()=>{const D=M.current;D&&(D.mutableState.defaultLayout=n,D.mutableState.disableCursor=!!r)}),u.jsx(DF.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:m==="horizontal"?"row":"column",flexWrap:"nowrap",touchAction:m==="horizontal"?"pan-y":"pan-x"},children:e})})}PF.displayName="Group";function A2(){const e=v.useContext(DF);return An(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function $xe(e,t){const{id:n}=A2(),r=v.useRef({collapse:oS,expand:oS,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:oS});v.useImperativeHandle(t,()=>r.current,[]),Eu(()=>{Object.assign(r.current,TF({groupId:n,panelId:e}))})}function OF({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:m="0%",onResize:f,panelRef:g,style:b,...y}){const _=!!c,w=N2(c),C=R2({disabled:s}),E=v.useRef(null),k=T2(E,o),{getPanelStyles:T,id:R,orientation:A,registerPanel:j,togglePanelDisabled:L}=A2(),H=f!==null,M=dm((z,O,F)=>{f==null||f(z,c,F)});Eu(()=>{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:m}};return j(O)}},[a,n,r,i,H,w,_,d,m,M,j,C]),v.useEffect(()=>{L(w,!!s)},[s,w,L]),$xe(w,g);const D=v.useSyncExternalStore(z=>S2(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:{...Hxe,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})})}OF.displayName="Panel";const Hxe={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function Uxe({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,m=[r,r+1];s=uu({layout:Ym({delta:d-o,initialLayout:e,panelConstraints:t,pivotIndices:m,prevLayout:e}),panelConstraints:t})[n],i=uu({layout:Ym({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:m,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:s,valueNow:o}}function zF({children:e,className:t,disabled:n,elementRef:r,id:i,style:s,...o}){const a=N2(i),c=R2({disabled:n}),[d,m]=v.useState({}),[f,g]=v.useState("inactive"),b=v.useRef(null),y=T2(b,r),{disableCursor:_,id:w,orientation:C,registerSeparator:E,toggleSeparatorDisabled:k}=A2(),T=C==="horizontal"?"vertical":"horizontal";Eu(()=>{const A=b.current;if(A!==null){const j={disabled:c.disabled,element:A,id:a},L=E(j),H=Axe(D=>{g(D.next.state!=="inactive"&&D.next.hitRegions.some(z=>z.separator===j)?D.next.state:"inactive")}),M=S2(w,D=>{const{derivedPanelConstraints:z,layout:O,separatorToPanels:F}=D.next,$=F.get(j);if($){const B=$[0],U=$.indexOf(B);m(Uxe({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":f,"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})}zF.displayName="Separator";const j2=({className:e,...t})=>u.jsx(PF,{className:de("flex h-full w-full",e),...t}),Xm=e=>u.jsx(OF,{...e}),M2=({withHandle:e,orientation:t,disabled:n,className:r,...i})=>u.jsx(zF,{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 BF(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 Vxe(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 BF(r.usage,new Date(r.createdAt).toISOString(),t)}return null}function Wxe(e,t){return!e||t===null||!Number.isFinite(t)||t<=0?e:BF({...e,maxTokens:t},e.updatedAt,e.compactsAutomatically)}function Gxe(e){if(!e)return null;const t=aS(e.inputTokens),n=aS(e.outputTokens),r=aS(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 aS(e){return e===void 0||!Number.isFinite(e)||e<0?0:e}function Mi(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 L2=[68,32];function qxe(){return{isVisible:!1,mainSizes:[...L2],terminals:[],nextTerminalIndex:0}}function Kxe(e,t){return e[t]??qxe()}function lS(e){if(e.length===0)return[];const t=e.reduce((n,r)=>n+Math.max(r,0),0);return!Number.isFinite(t)||t<=0?Array.from({length:e.length},()=>100/e.length):e.map(n=>Math.max(n,0)/t*100)}function Yxe(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 Xxe(e){if(e.length===0)return e;const t=e.length+1;return e.map(n=>({...n,size:n.size*e.length/t}))}function bd(e,t,n){return{...e,[t]:n(Kxe(e,t))}}const Il=Oi()(Nh(e=>({projects:{},addTerminal:(t,n)=>e(r=>({projects:bd(r.projects,t,i=>{var c,d;const s=Xxe(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:Yxe(i.nextTerminalIndex),size:100/(s.length+1)},a=n?Math.max(s.findIndex(m=>m.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:bd(r.projects,t,i=>{const s=i.terminals.filter(a=>a.id!==n);if(s.length===0)return{...i,isVisible:!1,terminals:[]};const o=lS(s.map(a=>a.size));return{...i,terminals:s.map((a,c)=>({...a,size:o[c]??100/s.length}))}})})),toggleVisibility:t=>e(n=>({projects:bd(n.projects,t,r=>({...r,isVisible:r.terminals.length>0?!r.isVisible:!1}))})),resetMainSizes:t=>e(n=>({projects:bd(n.projects,t,r=>({...r,mainSizes:[...L2]}))})),setMainSizes:(t,n)=>e(r=>{if(n.length!==2)return r;const i=lS(n);return{projects:bd(r.projects,t,s=>({...s,mainSizes:i}))}}),setTerminalSizes:(t,n)=>e(r=>({projects:bd(r.projects,t,i=>{if(n.length!==i.terminals.length)return i;const s=lS(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})),Qxe={isVisible:!1,mainSizes:[...L2],terminals:[],nextTerminalIndex:0},Zxe=35;function Jxe(e,t){return!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<=0?0:e*(t/100)}function eye(e,t){const n=Jxe(e,t);return n>=0&&n<Zxe}const Ey=350,tye=[.4,0,.2,1],nye=8,nD=1e-6;function rye(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function iye(e,t,n){const r=1-e;return 3*r*r*e*t+3*r*e*e*n+e*e*e}function sye(e,t,n){const r=1-e;return 3*r*r*t+6*r*e*(n-t)+3*e*e*(1-n)}function oye(e,t,n){let r=e;for(let i=0;i<nye;i+=1){const s=rye(r,t,n)-e;if(Math.abs(s)<nD)return r;const o=sye(r,t,n);if(Math.abs(o)<nD)break;r-=s/o}return r}function aye(e){if(e<=0)return 0;if(e>=1)return 1;const[t,n,r,i]=tye,s=oye(e,t,r);return iye(s,n,i)}function FF(e,t,n){const r=aye(n);return[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r]}function lye({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),m=v.useRef(null),f=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=m.current,_=y!==null&&y!==e,w=n&&!g.current,C=!f.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(m.current=e,f.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)/Ey),$=FF(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||(f.current=!1,g.current=!1)},[t]),{isAnimating:d,panelGroupRef:i,sidebarPanelRef:s,sidebarVisualRef:o}}function cye(e){return e.visibilityState==="visible"?e.activeChatId:null}function uye(e){e.socket.setFocusedChat(cye({activeChatId:e.activeChatId,visibilityState:e.visibilityState}))}function dye({socket:e,activeChatId:t}){v.useEffect(()=>{if(typeof document>"u")return;const n=()=>{uye({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 hye({rootRef:e,fallbackRef:t,enabled:n,canCancel:r}){v.useEffect(()=>{if(!n)return;let i=0,s=null;const o=f=>{const g=f instanceof Element?f:null,b=e.current,y=t.current;if(Pj({trigger:"pointer",activeElement:document.activeElement,pointerStartTarget:s,pointerEndTarget:g,root:b,fallback:y,hasActiveOverlay:Dj(document),hasActiveSelection:BX(window.getSelection())})!=="restore"){s=null;return}y==null||y.focus({preventScroll:!0}),s=null},a=f=>{cancelAnimationFrame(i),s=f.target instanceof Element?f.target:null},c=f=>{cancelAnimationFrame(i),i=window.requestAnimationFrame(()=>{o(f.target)})},d=()=>{s=null;const f=t.current;!f||f.disabled||f.focus({preventScroll:!0})},m=f=>{if(f.key!=="Escape")return;const g=t.current;Pj({trigger:"escape",activeElement:document.activeElement,fallback:g,hasActiveOverlay:Dj(document),canCancel:r,defaultPrevented:f.defaultPrevented})==="escape-focus"&&(f.preventDefault(),g==null||g.focus({preventScroll:!0}))};return window.addEventListener("pointerdown",a,!0),window.addEventListener("pointerup",c,!0),window.addEventListener("keydown",m,!0),window.addEventListener(Ib,d),()=>{cancelAnimationFrame(i),window.removeEventListener("pointerdown",a,!0),window.removeEventListener("pointerup",c,!0),window.removeEventListener("keydown",m,!0),window.removeEventListener(Ib,d)}},[r,n,t,e])}function fye(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 mye({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,m=e===null&&t!==null,f=i?s.mainSizes:[100,0];return{currentLayout:c||d?[100,0]:o,shouldSkipAnimation:a||m&&d,targetLayout:f}}function pye({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),m=v.useRef(!1),f=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=f.current,E=y.current;fye({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,f.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),m.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=f.current,{currentLayout:k,shouldSkipAnimation:T,targetLayout:R}=mye({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}m.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)/Ey),B=FF(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(()=>{m.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:m,mainPanelGroupRef:s,terminalFocusRequestVersion:_,terminalPanelRef:o,terminalVisualRef:a}}const rD=e=>Symbol.iterator in e,iD=e=>"entries"in e,sD=(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},gye=(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 vye(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:rD(e)&&rD(t)?iD(e)&&iD(t)?sD(e,t):gye(e,t):sD({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function hm(e){const t=_n.useRef(void 0);return n=>{const r=e(n);return vye(t.current,r)?t.current:t.current=r}}const fm="__new__";function Pc(e){var s,o;const t=(s=e==null?void 0:e.modelOptions)==null?void 0:s.reasoningEffort,n=p1(t)?t:p1(e==null?void 0:e.effort)?e.effort:ru.reasoningEffort,r=nre(e==null?void 0:e.model),i=wE(r,(o=e==null?void 0:e.modelOptions)==null?void 0:o.contextWindow);return{model:r,modelOptions:{reasoningEffort:!gz(r)&&n==="max"?"high":n,contextWindow:i},planMode:!!(e!=null&&e.planMode)}}function Mv(e){var n,r;const t=(n=e==null?void 0:e.modelOptions)==null?void 0:n.reasoningEffort;return{model:rre(e==null?void 0:e.model),modelOptions:{reasoningEffort:g1(t)?t:g1(e==null?void 0:e.effort)?e.effort:Mm.reasoningEffort,fastMode:typeof((r=e==null?void 0:e.modelOptions)==null?void 0:r.fastMode)=="boolean"?e.modelOptions.fastMode:Mm.fastMode},planMode:!!(e!=null&&e.planMode)}}function bye(){return{claude:{model:"claude-opus-4-7",modelOptions:{...ru},planMode:!1},codex:{model:"gpt-5.5",modelOptions:{...Mm},planMode:!1},openrouter:{model:ey,modelOptions:{},planMode:!1}}}function xye(e,t){return e.reasoningEffort===t.reasoningEffort&&e.contextWindow===t.contextWindow}function yye(e,t){return e.reasoningEffort===t.reasoningEffort&&e.fastMode===t.fastMode}function _ye(e,t){return e.claude.model===t.claude.model&&e.claude.planMode===t.claude.planMode&&xye(e.claude.modelOptions,t.claude.modelOptions)&&e.codex.model===t.codex.model&&e.codex.planMode===t.codex.planMode&&yye(e.codex.modelOptions,t.codex.modelOptions)&&e.openrouter.model===t.openrouter.model&&e.openrouter.planMode===t.openrouter.planMode}function wye(e,t){if(t===void 0){console.info(`[chat-preferences] ${e}`);return}console.info(`[chat-preferences] ${e}`,t)}function mm(e,t){if(e==="claude"){const r=t.claude;return{provider:"claude",model:r.model,modelOptions:{...r.modelOptions},planMode:r.planMode}}if(e==="openrouter"){const r=t.openrouter;return{provider:"openrouter",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 mC(e){return e.provider==="claude"?{provider:"claude",model:e.model,modelOptions:{...e.modelOptions},planMode:e.planMode}:e.provider==="openrouter"?{provider:"openrouter",model:e.model,modelOptions:{...e.modelOptions},planMode:e.planMode}:{provider:"codex",model:e.model,modelOptions:{...e.modelOptions},planMode:e.planMode}}function $F(e){return e.providerHint?mm(e.providerHint,e.providerDefaults):e.defaultProvider==="last_used"?e.sourceState?mC(e.sourceState):mm("claude",e.providerDefaults):mm(e.defaultProvider,e.providerDefaults)}function HF(e,t){const n=e.chatStates[t];return n||$F({defaultProvider:e.defaultProvider,providerDefaults:e.providerDefaults,legacyComposerState:e.legacyComposerState})}function Lv(e,t,n){const r=HF(e,t);return{chatStates:{...e.chatStates,[t]:n(r)}}}const mi=Oi()(Nh((e,t)=>({defaultProvider:"last_used",providerDefaults:bye(),chatStates:{},legacyComposerState:{provider:"claude",model:"claude-opus-4-7",modelOptions:{...ru},planMode:!1},setDefaultProvider:n=>e({defaultProvider:n}),applyServerDefaults:(n,r)=>e(i=>{if(i.defaultProvider===n&&_ye(i.providerDefaults,r))return{defaultProvider:n,providerDefaults:r};const{[fm]:o,...a}=i.chatStates;return{defaultProvider:n,providerDefaults:r,chatStates:a}}),setProviderDefaultModel:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?Pc({...i.providerDefaults.claude,model:r}):n==="openrouter"?{...i.providerDefaults.openrouter,model:r}:Mv({...i.providerDefaults.codex,model:r})}})),setProviderDefaultModelOptions:(n,r)=>e(i=>({providerDefaults:{...i.providerDefaults,[n]:n==="claude"?Pc({...i.providerDefaults.claude,modelOptions:{...i.providerDefaults.claude.modelOptions,...r}}):n==="openrouter"?{...i.providerDefaults.openrouter,modelOptions:{}}:Mv({...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=>mC(HF(t(),n)),initializeComposerForChat:(n,r)=>e(i=>{if(i.chatStates[n])return i;const s=$F({defaultProvider:i.defaultProvider,providerDefaults:i.providerDefaults,sourceState:r==null?void 0:r.sourceState,legacyComposerState:i.legacyComposerState,providerHint:r==null?void 0:r.providerHint});return wye("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:Pc(r).model,modelOptions:Pc(r).modelOptions,planMode:r.planMode}:mC(r)}})),setChatComposerProvider:(n,r)=>e(i=>Lv(i,n,()=>mm(r,i.providerDefaults))),setChatComposerModel:(n,r)=>e(i=>Lv(i,n,s=>s.provider==="claude"?{provider:"claude",model:Pc({...s,model:r}).model,modelOptions:Pc({...s,model:r}).modelOptions,planMode:s.planMode}:s.provider==="openrouter"?{provider:"openrouter",model:r,modelOptions:{},planMode:s.planMode}:{provider:"codex",model:r,modelOptions:Mv({...s,model:r}).modelOptions,planMode:s.planMode})),setChatComposerModelOptions:(n,r)=>e(i=>Lv(i,n,s=>s.provider==="claude"?{provider:"claude",model:s.model,modelOptions:Pc({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode}:s.provider==="openrouter"?{provider:"openrouter",model:s.model,modelOptions:{},planMode:s.planMode}:{provider:"codex",model:s.model,modelOptions:Mv({...s,modelOptions:{...s.modelOptions,...r}}).modelOptions,planMode:s.planMode})),setChatComposerPlanMode:(n,r)=>e(i=>Lv(i,n,s=>({...s,planMode:r}))),resetChatComposerFromProvider:(n,r)=>e(i=>({chatStates:{...i.chatStates,[n]:mm(r,i.providerDefaults)}}))}),{name:"chat-preferences-state",version:1,partialize:e=>({chatStates:e.chatStates,legacyComposerState:e.legacyComposerState})})),pC=Oi()(Nh((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"})),I2=Oi()(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 Sye(e){return{autoResumeOnRateLimit:!!(e!=null&&e.autoResumeOnRateLimit)}}const gC=Oi()(Nh(e=>({autoResumeOnRateLimit:!1,setAutoResumeOnRateLimit:t=>e({autoResumeOnRateLimit:t})}),{name:"kanna-preferences",version:1,migrate:e=>Sye(e)}));function xd(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function Iv(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function Cye(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 cS(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 kye(e,t){var r;const n=Iv(t);switch(e.toolKind){case"ask_user_question":{const o=cS(n),a=o!==null?Iv(o):n,c=xd(a),d=xd(c==null?void 0:c.answers)??(c||{});return{answers:Object.fromEntries(Object.entries(d).map(([m,f])=>Array.isArray(f)?[m,f.map(g=>String(g))]:f&&typeof f=="object"&&Array.isArray(f.answers)?[m,f.answers.map(g=>String(g))]:f==null||f===""?[m,[]]:[m,[String(f)]])),...(c==null?void 0:c.discarded)===!0?{discarded:!0}:{}}}case"exit_plan_mode":{const o=cS(n),a=o!==null?Iv(o):n,c=xd(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=cS(n),a=o?Iv(o):n,c=xd(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=xd(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=Cye(n);if(i.length>0)return{content:i.flatMap(o=>o.type==="text"?[o.text]:[]).join(""),blocks:i};const s=xd(n);return{content:typeof(s==null?void 0:s.content)=="string"?s.content:JSON.stringify(n,null,2)};default:return n}}function UF(e){return new Date(e).toISOString()}function Tr(e){return{id:e._id,messageId:e.messageId,timestamp:UF(e.createdAt),hidden:e.hidden}}function Eye(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:UF(e.createdAt)}}function Nye(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 Dv(e){return typeof e=="string"?e:void 0}function Tye(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 Rye(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:Dv(n.agentId),agentType:Dv(n.agentType),status:Dv(n.status),totalTokens:jo(n.totalTokens),totalDurationMs:jo(n.totalDurationMs),totalToolUseCount:jo(n.totalToolUseCount),toolStats:Tye(n.toolStats),content:Dv(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 D2(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=Eye(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"?Nye(r)??r.content:r.content;i.normalized.toolKind==="subagent_task"?i.hydrated.result=Rye(r):i.hydrated.result=kye(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 Aye=["AskUserQuestion","ExitPlanMode","TodoWrite"],jye=new Set(["TodoWrite"]);function Mye(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 Lye(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 Iye(e){const t={};for(const n of Aye)t[n]=jye.has(n)?Lye(e,n):Mye(e,n);return t}function Dye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}function Pye(e){return e==="starting"||e==="running"||e==="waiting_for_user"}const P2="pushDeviceId";function VF(){return typeof localStorage>"u"?null:localStorage.getItem(P2)}function Oye(e){typeof localStorage>"u"||localStorage.setItem(P2,e)}function zye(){typeof localStorage>"u"||localStorage.removeItem(P2)}function Bye(){return!(typeof window>"u"||typeof Notification>"u"||!("serviceWorker"in navigator)||typeof globalThis.PushManager>"u")}function Fye(){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 vC(){if(!Bye())return{state:"unsupported"};if(!Fye())return{state:"insecure-context"};switch(Notification.permission){case"granted":return{state:"granted"};case"denied":return{state:"denied"};default:return{state:"default"}}}function $ye(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 Hye(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 Uye(e){const t=vC();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:$ye(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:Hye(c),userAgent:c});return d}async function Vye(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 Wye=25e3,Gye=15e3,qye=4e3,oD="kanna:profile-send-to-starting";function aD(){try{return window.sessionStorage.getItem(oD)==="1"||window.localStorage.getItem(oD)==="1"}catch{return!1}}class Kye{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=$c();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=$c(),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=$c(),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=$c();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=VF();t&&this.sendNow({v:1,type:"command",id:$c(),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(aD()&&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}),aD()&&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($Z,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>=Wye}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()},qye),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()},Gye))}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 Yye=[],O2=Oi()(e=>({byChat:{},setRuns:(t,n)=>e(r=>({byChat:{...r.byChat,[t]:n}}))}));function WF(e){return t=>t.byChat[e]??Yye}const Xye=[],Pv=Oi()(e=>({models:Xye,status:"idle",error:null,setLoading:()=>e({status:"loading",error:null}),setModels:t=>e({models:t,status:"ready",error:null}),setError:t=>e({status:"error",error:t})}));function Qye(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 Zye(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&&Qye(e.sessionTokensByProvider,t.sessionTokensByProvider)}function Jye(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 e0e(e,t){return t.length===0?e:e.map(n=>n.id!=="openrouter"?n:{...n,models:t.map(r=>({id:r.id,label:r.label,supportsEffort:!1}))})}function t0e(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 n0e(e,t){return e===t?!0:!e||!t?!1:e.hasOlder===t.hasOlder&&e.olderCursor===t.olderCursor&&e.recentLimit===t.recentLimit}function r0e(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)&&i0e(e.attachments,t.attachments)}function i0e(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 s0e(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>r0e(n,t[r]))}function o0e(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((m,f)=>m===d.tags[f])})||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 a0e(e,t){return!!(e&&e.status!=="unknown"&&t&&t.status==="unknown"&&t.files.length===0)}function l0e(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 c0e(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 u0e(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,m,f,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)===(((m=o.usage)==null?void 0:m.outputTokens)??null)&&s.finishedAt===o.finishedAt&&(((f=s.error)==null?void 0:f.code)??null)===(((g=o.error)==null?void 0:g.code)??null)})}function d0e(e,t){return e===t?!0:!e||!t?!1:Zye(e.runtime,t.runtime)&&s0e(e.queuedMessages,t.queuedMessages)&&Jye(e.messages,t.messages)&&n0e(e.history,t.history)&&t0e(e.availableProviders,t.availableProviders)&&l0e(e.schedules,t.schedules)&&e.liveScheduleId===t.liveScheduleId&&c0e(e.tunnels,t.tunnels)&&e.liveTunnelId===t.liveTunnelId&&u0e(e.subagentRuns,t.subagentRuns)}function lD(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 h0e(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 cD="__new_chat__",GF="lever-theme",qF="chat-sound-preferences",KF="terminal-preferences",YF="chat-preferences";function uS(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 f0e(){if(typeof window>"u")return null;const e={},t=window.localStorage.getItem(GF);(t==="light"||t==="dark"||t==="system")&&(e.theme=t);const n=uS(qF);((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=uS(KF);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=uS(YF);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 m0e(){typeof window>"u"||(window.localStorage.removeItem(GF),window.localStorage.removeItem(qF),window.localStorage.removeItem(KF),window.localStorage.removeItem(YF))}function Of(e){ji.getState().setFromServer(e);const t=ui.getState();t.setScrollbackLines(e.terminal.scrollbackLines),t.setMinColumnWidth(e.terminal.minColumnWidth),t.setEditorPreset(e.editor.preset),t.setEditorCommandTemplate(e.editor.commandTemplate);const n=Vc.getState();n.setChatSoundPreference(e.chatSoundPreference),n.setChatSoundId(e.chatSoundId),mi.getState().applyServerDefaults(e.defaultProvider,e.providerDefaults)}function p0e(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 z2(e,t=[]){return JSON.stringify({content:e,attachments:t.map(p0e)})}function g0e(e,t){return e.reduce((n,r)=>r.kind!=="user_prompt"?n:n+(z2(r.content,r.attachments??[])===t?1:0),0)}function v0e(e,t,n){const r=new Map;for(const i of n){if(i.kind!=="user_prompt")continue;const s=z2(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 b0e(e,t,n){return e.some(r=>r.id===t)?e.filter(r=>r.id!==t):e}const x0e=200,y0e=500;function uD(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 dD(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 _0e(e=document){return e.visibilityState==="visible"&&e.hasFocus()}function w0e(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`}function S0e(){const[e]=v.useState(()=>new Kye(w0e()));return v.useEffect(()=>(e.start(),()=>{e.dispose()}),[e]),e}const hD="kanna:profile-send-to-starting";function C0e(){try{return window.sessionStorage.getItem(hD)==="1"||window.localStorage.getItem(hD)==="1"}catch{return!1}}function XF(e){return Number((performance.now()-e).toFixed(1))}function Nl(e,t,n){!e||!C0e()||console.debug("[kanna/send->starting][client]",{traceId:e.traceId,stage:t,elapsedMs:XF(e.startedAt),serverChatId:e.serverChatId,routeChatIdAtSend:e.routeChatIdAtSend,...n})}function k0e(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 E0e(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 N0e(e,t){return e==="awaiting_disconnect"&&t==="disconnected"?"awaiting_server_ready":"none"}function T0e(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 R0e=30,B2="kanna:ui-update-restart",QF="kanna:last-update-reload-request";function A0e(e){return e+R0e}function j0e(e,t){return t>0?t:e}function dS(){return window.sessionStorage.getItem(B2)}function M0e(e){window.sessionStorage.setItem(B2,e)}function L0e(){window.sessionStorage.removeItem(B2)}function I0e(e,t){return e?String(e)!==t:!1}function D0e(){return window.sessionStorage.getItem(QF)}function P0e(e){window.sessionStorage.setItem(QF,String(e))}function O0e(){return"/auth/status"}async function z0e(e=fetch){return(await e(O0e(),{method:"GET",cache:"no-store",headers:{Accept:"application/json"}})).ok}function B0e(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 F0e(e,t){return!e||!t?null:e.runtime.chatId!==t?(e.runtime.chatId,e.runtime.provider,null):e}function $0e(e){var zh,hc,fc;const t=gu(),n=S0e(),r=mp(),[i,s]=v.useState({starredProjectGroups:[],projectGroups:[],stacks:[]}),[o,a]=v.useState(null),[c,d]=v.useState(null),[m,f]=v.useState(null),[g,b]=v.useState(()=>dS()),y=v.useCallback(Q=>{M0e(Q),b(Q)},[]),_=v.useCallback(()=>{L0e(),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),[J,ne]=v.useState(!1),[ie,le]=v.useState(null),[oe,Ce]=v.useState(!1),[ke,ze]=v.useState(!1),[Ze,lt]=v.useState(!1),[Mt,ye]=v.useState(null),[ln,jt]=v.useState(null),[_t,ft]=v.useState(null),[Ot,It]=v.useState([]),[it,Dt]=v.useState(null),[fe,Ae]=v.useState(0),He=v.useRef(new Map),Je=pC(hm(Q=>Object.keys(Q.drafts).sort())),qe=pC(hm(Q=>Object.keys(Q.attachmentDrafts).sort())),bt=v.useRef(0),wt=v.useRef(null),Tt=v.useRef({projectId:null,diffs:null}),Ne=Tre(ui(Q=>Q.editorPreset)),De=v.useMemo(()=>dD(i.projectGroups,o),[o,i.projectGroups]),Be=v.useRef(De);v.useLayoutEffect(()=>{Be.current=De});const Ye=v.useMemo(()=>De===i.projectGroups?i:{...i,projectGroups:De},[i,De]);v.useEffect(()=>n.onStatus(Y),[n]),v.useEffect(()=>n.subscribe({type:"sidebar"},Q=>{s(Q),a(Z=>Z&&dD(Q.projectGroups,Z)===Q.projectGroups?null:Z),V(!0),ye(null)}),[n]),v.useEffect(()=>{if(P!=="connected")return;const Q=[...new Set([...Je,...qe])].sort();n.command({type:"chat.setDraftProtection",chatIds:Q}).catch(Z=>{ye(Z instanceof Error?Z.message:String(Z))})},[qe,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=>{f(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=m==null?void 0:m.reloadRequestedAt;I0e(Q,D0e())&&Q&&(P0e(Q),y("awaiting_disconnect"))},[y,m==null?void 0:m.reloadRequestedAt]),v.useEffect(()=>{const Q=dS();if(N0e(Q,P)==="awaiting_server_ready"){y("awaiting_server_ready");return}},[P,y]),v.useEffect(()=>{if(dS()!=="awaiting_server_ready")return;let Q=!1,Z=null;const je=async()=>{try{if(await z0e()){if(Q)return;_(),window.location.reload();return}}catch{}Q||(Z=window.setTimeout(()=>{je()},500))};return je(),()=>{Q=!0,Z!==null&&window.clearTimeout(Z)}},[P,_]),v.useEffect(()=>{function Q(){m!=null&&m.lastCheckedAt&&(Date.now()-m.lastCheckedAt<=3600*1e3||n.command({type:"update.check"}).catch(Z=>{ye(Z instanceof Error?Z.message:String(Z))}))}return window.addEventListener("focus",Q),()=>{window.removeEventListener("focus",Q)}},[n,m==null?void 0:m.lastCheckedAt]),v.useEffect(()=>n.subscribe({type:"keybindings"},Q=>{O(Q),ye(null)}),[n]),v.useEffect(()=>n.subscribe({type:"app-settings"},Q=>{$(Q),Of(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 ct=v.useCallback(async()=>{try{ji.getState().setHydrationStatus("loading");const Q=await n.command({type:"settings.readAppSettings"});$(Q),Of(Q),ye(null)}catch(Q){ji.getState().setHydrationStatus("error"),ye(Q instanceof Error?Q.message:String(Q))}},[n]),nn=v.useCallback(async(Q,Z)=>{try{await n.command({type:"chat.setPolicyOverride",chatId:Q,policyOverride:Z}),ye(null)}catch(je){throw ye(je instanceof Error?je.message:String(je)),je}},[n]),Qt=v.useCallback(async Q=>{try{ji.getState().applyOptimisticPatch(Q);const Z=await n.command({type:"settings.writeAppSettingsPatch",patch:Q});$(Z),Of(Z),ye(null)}catch(Z){throw ye(Z instanceof Error?Z.message:String(Z)),await ct(),Z}},[ct,n]),Ut=v.useCallback(async Q=>{try{await n.command({type:"settings.testMcpServer",id:Q}),ye(null)}catch(Z){throw ye(Z instanceof Error?Z.message:String(Z)),Z}},[n]),Rt=v.useCallback(async Q=>{try{ji.getState().applyOptimisticPatch({cloudflareTunnel:Q});const Z=await n.command({type:"appSettings.setCloudflareTunnel",patch:Q});$(Z),Of(Z),ye(null)}catch(Z){throw ye(Z instanceof Error?Z.message:String(Z)),await ct(),Z}},[ct,n]),xt=v.useCallback(async Q=>{try{ji.getState().applyOptimisticPatch({claudeAuth:Q});const Z=await n.command({type:"appSettings.setClaudeAuth",patch:Q});$(Z),Of(Z),ye(null)}catch(Z){throw ye(Z instanceof Error?Z.message:String(Z)),await ct(),Z}},[ct,n]),mt=v.useCallback(async Q=>await n.command({type:"appSettings.testOAuthToken",token:Q}),[n]),Ct=v.useCallback(async()=>{try{const Q=await n.command({type:"settings.readLlmProvider"});te(Q),ye(null)}catch(Q){ye(Q instanceof Error?Q.message:String(Q))}},[n]),pt=v.useCallback(async Q=>{try{const Z=await n.command({type:"settings.writeLlmProvider",provider:Q.provider,apiKey:Q.apiKey,model:Q.model,baseUrl:Q.baseUrl});te(Z),ye(null)}catch(Z){throw ye(Z instanceof Error?Z.message:String(Z)),Z}},[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"&&ct()},[P,ct]),v.useEffect(()=>{if(P!=="connected")return;Pv.getState().setLoading(),n.command({type:"settings.listOpenRouterModels"}).then(Z=>{Pv.getState().setModels(Z)}).catch(Z=>{const je=Z instanceof Error?Z.message:String(Z);Pv.getState().setError(je)})},[P,n]),v.useEffect(()=>{if(P!=="connected"||(F==null?void 0:F.browserSettingsMigrated)!==!1)return;const Q=f0e();Q&&Qt(Q).then(m0e).catch(()=>{})},[F==null?void 0:F.browserSettingsMigrated,P,Qt]),v.useEffect(()=>{P==="connected"&&Ct()},[P,Ct]),v.useEffect(()=>{function Q(){Ae(Z=>Z+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}++bt.current,Be.current.length,Be.current.reduce((Z,je)=>Z+je.chats.length,0),C(null),ne(!1);const Q=n.subscribe({type:"chat",chatId:e,recentLimit:x0e},Z=>{if(Z!=null&&Z.runtime.chatId){const je=[...He.current.values()].filter(vt=>vt.serverChatId===Z.runtime.chatId).sort((vt,Dn)=>Dn.startedAt-vt.startedAt)[0];je&&je.snapshotAt===void 0&&(je.snapshotAt=performance.now(),Nl(je,"chat_snapshot_received",{status:Z.runtime.status,messageCount:Z.messages.length}))}if(C(je=>{const vt=d0e(je,Z);return Z==null||Z.runtime.chatId,Z==null||Z.runtime.provider,Z==null||Z.runtime.status,Z==null||Z.messages.length,vt?je:Z}),j((Z==null?void 0:Z.history.olderCursor)??null),H((Z==null?void 0:Z.history.hasOlder)??!1),ne(!0),ye(null),Z){const je=I2.getState();je.setForChat(Z.runtime.chatId,Z.slashCommands??[]),je.setLoadingForChat(Z.runtime.chatId,Z.slashCommandsLoading??!1)}});return()=>{Be.current.length,Be.current.reduce((Z,je)=>Z+je.chats.length,0),Q()}},[e,n]),v.useEffect(()=>{if(e)return n.subscribe({type:"workflows",chatId:e},Q=>{O2.getState().setRuns(Q.chatId,Q.runs)})},[e,n]),v.useEffect(()=>{if(ie)return;const Q=De[0];Q&&le(Q.groupKey)},[ie,De]),v.useEffect(()=>{if(!e||!ee||!J)return;if(De.some(Z=>Z.chats.some(je=>je.chatId===e))){_t===e&&ft(null);return}_t!==e&&t("/")},[e,J,t,_t,De,ee]),v.useEffect(()=>{w&&(le(w.runtime.projectId),_t===w.runtime.chatId&&ft(null))},[w,_t]),v.useEffect(()=>{if(!e||!ee||!_0e())return;const Q=De.flatMap(Z=>Z.chats).find(Z=>Z.chatId===e);Q!=null&&Q.unread&&n.command({type:"chat.markRead",chatId:e}).catch(Z=>{ye(Z instanceof Error?Z.message:String(Z))})},[e,fe,De,ee,n]),v.useEffect(()=>{k([]),R(!1),j(null),H(!1)},[e]);const nt=v.useMemo(()=>F0e(w,e),[e,w]),we=v.useMemo(()=>(nt==null?void 0:nt.runtime.projectId)??E0e(De,e)??ie,[e,nt==null?void 0:nt.runtime.projectId,ie,De]),tt=v.useMemo(()=>{const Q=we?M[we]??null:null;return we&&Q?(Tt.current={projectId:we,diffs:Q},Q):we&&Tt.current.projectId===we?Tt.current.diffs:Q},[we,M]);v.useEffect(()=>we?n.subscribe({type:"project-git",projectId:we},Z=>{D(je=>{const vt=Z??null;return a0e(je[we]??null,vt)||o0e(je[we]??null,vt)?je:{...je,[we]:vt}}),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 Ge=v.useMemo(()=>lD(E,(nt==null?void 0:nt.messages)??[]),[nt==null?void 0:nt.messages,E]),Xe=e??cD,_e=v.useMemo(()=>Ot.filter(Q=>Q.scopeId===Xe).map(Q=>Q.entry),[Xe,Ot]),Oe=v.useMemo(()=>[...Ge,..._e],[_e,Ge]),Ue=v.useMemo(()=>D2(Oe),[Oe]),Ve=v.useMemo(()=>h0e(Ue),[Ue]),Vt=v.useMemo(()=>Iye(Ue),[Ue]),Fe=(nt==null?void 0:nt.runtime)??null,Ht=(nt==null?void 0:nt.queuedMessages)??[],wn=((it==null?void 0:it.scopeId)===Xe&&(!Fe||Fe.status==="idle")?"starting":null)??(Fe==null?void 0:Fe.status)??null,pr=(nt==null?void 0:nt.availableProviders)??im,Sn=Pv(hm(Q=>Q.models)),Fn=v.useMemo(()=>e0e(pr,Sn),[pr,Sn]),Er=Pye(wn??void 0),K=Dye(wn??void 0),xe=(Fe==null?void 0:Fe.isDraining)??!1,Re=((zh=c==null?void 0:c.projects[0])==null?void 0:zh.localPath)??null,Qe=(Fe==null?void 0:Fe.localPath)??Re??((hc=De[0])==null?void 0:hc.localPath),ut=!!(ie??(Fe==null?void 0:Fe.projectId)??((fc=De[0])==null?void 0:fc.groupKey)??Re);v.useEffect(()=>{(it==null?void 0:it.scopeId)===Xe&&Fe!=null&&Fe.status&&Fe.status!=="idle"&&Dt(null)},[it,Xe,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!(it!=null&&it.ackedAt)||it.scopeId!==Xe||Fe!=null&&Fe.status&&Fe.status!=="idle")return;const Q=window.setTimeout(()=>{Dt(Z=>(Z==null?void 0:Z.scopeId)===Xe&&Z.ackedAt===it.ackedAt?null:Z)},300);return()=>window.clearTimeout(Q)},[it,Xe,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting")return;const Q=[...He.current.values()].filter(Z=>Z.serverChatId===e).sort((Z,je)=>je.startedAt-Z.startedAt)[0];!Q||Q.startingStatusAt!==void 0||(Q.startingStatusAt=performance.now(),Nl(Q,"runtime_status_starting",{status:Fe.status}))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{if(!e||!Fe||Fe.status==="starting")return;const Q=[...He.current.values()].filter(Z=>Z.serverChatId===e).sort((Z,je)=>je.startedAt-Z.startedAt)[0];!Q||Q.startingRenderedAt!==void 0||(Nl(Q,"starting_not_observed",{status:Fe.status}),He.current.delete(Q.traceId))},[e,Fe]),v.useLayoutEffect(()=>{if(!e||(Fe==null?void 0:Fe.status)!=="starting"){wt.current=null;return}const Q=[...He.current.values()].filter(Z=>Z.serverChatId===e).sort((Z,je)=>je.startedAt-Z.startedAt)[0];Q&&wt.current!==Q.traceId&&(wt.current=Q.traceId,Q.startingRenderedAt=performance.now(),Nl(Q,"starting_render_committed",{totalMs:XF(Q.startedAt)}),He.current.delete(Q.traceId))},[e,Fe==null?void 0:Fe.status]),v.useEffect(()=>{It(Q=>{const Z=v0e(Q,Xe,Ge);return Z.length===Q.length&&Z.every((je,vt)=>je===Q[vt])?Q:Z})},[Xe,Ge]);const Ke=v.useCallback(async()=>{if(!(!e||!A||T||!L)){R(!0);try{const Q=await n.command({type:"chat.loadHistory",chatId:e,beforeCursor:A,limit:y0e});k(Z=>lD(Q.messages,Z)),j(Q.olderCursor),H(Q.hasOlder),ye(null)}catch(Q){const Z=Q instanceof Error?Q.message:String(Q);ye(Z)}finally{R(!1)}}},[e,L,A,T,n]),dt=v.useCallback(async Q=>{const Z=mi.getState(),je=e?Z.getComposerState(e):Z.getComposerState(fm),vt=await n.command({type:"chat.create",projectId:Q});Z.initializeComposerForChat(vt.chatId,{sourceState:je}),le(Q),ft(vt.chatId),t(`/chat/${vt.chatId}`),Ce(!1),ye(null)},[e,t,n]),cn=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]),yn=v.useCallback(async Q=>{try{const Z=Q.kind==="project_id"?null:Q.kind==="local_path"?Q.localPath:Q.project.localPath;Z&&jt(Z);const{projectId:je}=await cn(Q);await dt(je)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}finally{jt(null)}},[dt,cn]),or=v.useCallback(async Q=>{await yn({kind:"project_id",projectId:Q})},[yn]),si=v.useCallback(async Q=>{try{const Z=await n.command({type:"chat.fork",chatId:Q.chatId}),je=mi.getState();je.initializeComposerForChat(Z.chatId,{sourceState:je.getComposerState(Q.chatId)}),ft(Z.chatId),t(`/chat/${Z.chatId}`),Ce(!1),ye(null)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}},[t,n]),os=v.useCallback(async Q=>{await yn({kind:"local_path",localPath:Q})},[yn]),qr=v.useCallback(async Q=>{await yn({kind:"project_request",project:Q})},[yn]),uo=v.useCallback(async Q=>{try{await n.command({type:"update.check",force:Q==null?void 0:Q.force}),ye(null)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}},[n]),Fi=v.useCallback(async Q=>{y("awaiting_disconnect");try{const Z=await n.command({type:"update.install",version:Q});if(!Z.ok){_(),ye(null),await r.alert({title:Z.userTitle??"Update failed",description:Z.userMessage??"Kanna could not install the update. Try again later.",closeLabel:"OK"});return}if(Z.ok&&Z.action==="reload"){window.location.reload();return}ye(null)}catch(Z){_(),ye(Z instanceof Error?Z.message:String(Z))}},[_,r,y,n]),kt=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]),rn=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))}},[]),mn=v.useCallback(async(Q,Z)=>{var pc;const je=(Z==null?void 0:Z.attachments)??[],vt=$c(),Dn=$c(),$i=z2(Q,je),ea=e??cD;Dt({scopeId:ea,ackedAt:null});const Hi={traceId:Dn,optimisticId:vt,startedAt:performance.now(),serverChatId:e,routeChatIdAtSend:e,contentPreview:Q.slice(0,80)};He.current.set(Dn,Hi),Nl(Hi,"handle_send_called",{optimisticScopeId:ea,attachments:je.length,contentLength:Q.length,contentPreview:Hi.contentPreview});const mc=g0e(Ge,$i)+Ot.filter(er=>er.scopeId===ea&&er.signature===$i).length+1;It(er=>[...er,{id:vt,scopeId:ea,signature:$i,requiredMatchCount:mc,entry:{_id:`optimistic:${vt}`,kind:"user_prompt",content:Q,attachments:je,createdAt:Date.now()}}]),Nl(Hi,"optimistic_prompt_added",{optimisticId:vt,optimisticScopeId:ea});try{let er=ie??((pc=De[0])==null?void 0:pc.groupKey)??null;if(!e&&!er&&Re&&(er=(await n.command({type:"project.open",localPath:Re})).projectId,le(er)),!e&&!er)throw new Error("Open a project first");const Bh=gC.getState().autoResumeOnRateLimit,oi=await n.command({type:"chat.send",chatId:e??void 0,projectId:e?void 0:er??void 0,clientTraceId:Dn,provider:Z==null?void 0:Z.provider,content:Q,attachments:je,model:Z==null?void 0:Z.model,modelOptions:Z==null?void 0:Z.modelOptions,planMode:Z==null?void 0:Z.planMode,autoResumeOnRateLimit:Bh});if(Hi.ackAt=performance.now(),Hi.serverChatId=oi.chatId??Hi.serverChatId,oi.queued?(It(Bs=>b0e(Bs,vt,{queued:!0})),Dt(null)):Dt(Bs=>Bs&&{scopeId:!e&&oi.chatId?oi.chatId:Bs.scopeId,ackedAt:performance.now()}),Nl(Hi,"chat_send_ack_received",{resultChatId:oi.chatId??null,queued:oi.queued??!1}),!e&&oi.chatId){It(ju=>ju.map(Fh=>Fh.id===vt?{...Fh,scopeId:oi.chatId}:Fh));const Bs=mi.getState();Bs.setComposerState(oi.chatId,k0e(Z)??Bs.getComposerState(fm)),ft(oi.chatId),t(`/chat/${oi.chatId}`)}ye(null)}catch(er){throw It(Bh=>Bh.filter(oi=>oi.id!==vt)),Dt(null),Nl(Hi,"handle_send_failed",{error:er instanceof Error?er.message:String(er)}),He.current.delete(Dn),ye(er instanceof Error?er.message:String(er)),er}},[e,Re,t,Ot,ie,Ge,De,n]),pn=v.useCallback(async Q=>{if(e)try{await n.command({type:"message.steer",chatId:e,queuedMessageId:Q}),ye(null)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}},[e,n]),Kr=v.useCallback(async Q=>{if(e)try{await n.command({type:"message.dequeue",chatId:e,queuedMessageId:Q}),ye(null)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}},[e,n]),Za=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]),ho=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]),Yo=v.useCallback(async Q=>{const Z=await r.prompt({title:"Rename Chat",initialValue:Q.title,confirmLabel:"Rename"});if(!(!Z||Z===Q.title))try{await n.command({type:"chat.rename",chatId:Q.chatId,title:Z}),ye(null)}catch(je){ye(je instanceof Error?je.message:String(je))}},[r,n]),Os=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 je=uD(De,Q.chatId);t(je?`/chat/${je}`:"/")}}catch(je){ye(je instanceof Error?je.message:String(je))}},[e,r,t,De,n]),Ja=v.useCallback(async Q=>{try{if(await n.command({type:"chat.archive",chatId:Q.chatId}),Q.chatId===e){const Z=uD(De,Q.chatId);t(Z?`/chat/${Z}`:"/")}ye(null)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}},[e,t,De,n]),Jn=v.useCallback(async Q=>{try{ft(Q),await n.command({type:"chat.unarchive",chatId:Q}),t(`/chat/${Q}`),ye(null)}catch(Z){ft(null),ye(Z instanceof Error?Z.message:String(Z))}},[t,n]),fo=v.useCallback(async Q=>{try{await n.command({type:"project.remove",projectId:Q}),Il.getState().clearProject(Q),Ai.getState().clearProject(Q),(Fe==null?void 0:Fe.projectId)===Q&&t("/"),ye(null)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}},[t,Fe,n]),mo=v.useCallback(async(Q,Z)=>{try{await n.command({type:"project.setStar",projectId:Q,starred:Z}),ye(null)}catch(je){ye(je instanceof Error?je.message:String(je))}},[n]),po=v.useCallback(async Q=>{a(Q);try{await n.command({type:"sidebar.reorderProjectGroups",projectIds:Q}),ye(null)}catch(Z){a(null),ye(Z instanceof Error?Z.message:String(Z))}},[n]),_i=v.useCallback(async(Q,Z)=>{try{await n.command({type:"stack.create",title:Q,projectIds:Z}),ye(null)}catch(je){ye(je instanceof Error?je.message:String(je))}},[n]),Xo=v.useCallback(async(Q,Z)=>{try{await n.command({type:"stack.rename",stackId:Q,title:Z}),ye(null)}catch(je){ye(je instanceof Error?je.message:String(je))}},[n]),Qo=v.useCallback(async Q=>{try{await n.command({type:"stack.remove",stackId:Q}),ye(null)}catch(Z){ye(Z instanceof Error?Z.message:String(Z))}},[n]),wi=v.useCallback(async(Q,Z)=>{try{await n.command({type:"stack.addProject",stackId:Q,projectId:Z}),ye(null)}catch(je){ye(je instanceof Error?je.message:String(je))}},[n]),Zo=v.useCallback(async(Q,Z)=>{try{await n.command({type:"stack.removeProject",stackId:Q,projectId:Z}),ye(null)}catch(je){ye(je instanceof Error?je.message:String(je))}},[n]),go=v.useCallback(async(Q,Z,je)=>{try{const vt=mi.getState(),Dn=e?vt.getComposerState(e):vt.getComposerState(fm),$i=await n.command({type:"chat.create",projectId:Q,stackId:Z,stackBindings:je});vt.initializeComposerForChat($i.chatId,{sourceState:Dn}),le(Q),ft($i.chatId),t(`/chat/${$i.chatId}`),Ce(!1),ye(null)}catch(vt){ye(vt instanceof Error?vt.message:String(vt))}},[e,t,n]),Ee=v.useCallback(async Q=>{try{const Z=await n.command({type:"stack.listWorktrees",projectId:Q});return ye(null),Z.worktrees}catch(Z){return ye(Z instanceof Error?Z.message:String(Z)),[]}},[n]),W=v.useCallback(async()=>await n.command({type:"sessions.importClaude"}),[n]),ve=v.useCallback(async Q=>{const Z=ui.getState();ye(null),await n.command({type:"system.openExternal",...Q,editor:Q.action==="open_editor"?Q.editor??{preset:Z.editorPreset,commandTemplate:Z.editorCommandTemplate}:void 0})},[n]),Gt=v.useCallback(async(Q,Z)=>{var vt,Dn;const je=(Fe==null?void 0:Fe.localPath)??((vt=c==null?void 0:c.projects[0])==null?void 0:vt.localPath)??((Dn=De[0])==null?void 0:Dn.localPath);if(je)try{await ve({action:Q,localPath:je,editor:Z})}catch($i){ye($i instanceof Error?$i.message:String($i))}},[c==null?void 0:c.projects,ve,Fe==null?void 0:Fe.localPath,De]),ar=v.useCallback(async Q=>{var Z;try{if(typeof navigator>"u"||!((Z=navigator.clipboard)!=null&&Z.writeText))throw new Error("Clipboard is not available");await navigator.clipboard.writeText(Q),ye(null)}catch(je){ye(je instanceof Error?je.message:String(je))}},[]),Yr=v.useCallback(async(Q,Z="open_editor",je)=>{try{await ve({action:Z,localPath:Q.path,line:Q.line,column:Q.column,editor:je})}catch(vt){ye(vt instanceof Error?vt.message:String(vt))}},[ve]),Jo=v.useCallback(async(Q,Z)=>{try{await ve({action:Q,localPath:Z})}catch(je){ye(je instanceof Error?je.message:String(je))}},[ve]),lc=v.useCallback(()=>{var Z;const Q=B0e({selectedProjectId:ie,sidebarProjectId:(Z=De[0])==null?void 0:Z.groupKey,fallbackLocalProjectPath:Re});if(Q){yn(Q);return}t("/")},[Re,t,ie,De,yn]),vo=v.useCallback(()=>Ce(!0),[]),el=v.useCallback(()=>Ce(!1),[]),Op=v.useCallback(()=>ze(!0),[]),Dh=v.useCallback(()=>ze(!1),[]),zp=v.useCallback(()=>lt(!0),[]),cc=v.useCallback(()=>lt(!1),[]),zs=v.useCallback(async(Q,Z,je)=>{if(e)try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Q,result:{questions:Z,answers:je}})}catch(vt){ye(vt instanceof Error?vt.message:String(vt))}},[e,n]),Ph=v.useCallback(async(Q,Z,je,vt)=>{if(e){Z&&mi.getState().setChatComposerPlanMode(e,!1);try{await n.command({type:"chat.respondTool",chatId:e,toolUseId:Q,result:{confirmed:Z,...je?{clearContext:!0}:{},...vt?{message:vt}:{}}})}catch(Dn){ye(Dn instanceof Error?Dn.message:String(Dn))}}},[e,n]),uc=v.useCallback(async(Q,Z,je,vt)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Q,toolUseId:Z,result:{questions:je,answers:vt}})}catch(Dn){ye(Dn instanceof Error?Dn.message:String(Dn))}},[e,n]),bo=v.useCallback(async(Q,Z,je)=>{if(e)try{await n.command({type:"chat.respondSubagentTool",chatId:e,runId:Q,toolUseId:Z,result:je})}catch(vt){ye(vt instanceof Error?vt.message:String(vt))}},[e,n]),Oh=v.useCallback(async(Q,Z)=>{if(e)try{await n.command({type:"chat.toolRequestAnswer",chatId:e,toolRequestId:Q,decision:Z})}catch(je){ye(je instanceof Error?je.message:String(je))}},[e,n]),dc=T0e(g,m==null?void 0:m.status);return{socket:n,activeChatId:e,activeProjectId:we,sidebarData:Ye,localProjects:c,updateSnapshot:m,chatSnapshot:w,chatDiffSnapshot:tt,keybindings:z,appSettings:F,pushConfig:B,llmProvider:G,connectionStatus:P,sidebarReady:ee,uiRestartActive:dc.active,uiRestartLabel:dc.label,localProjectsReady:ue,commandError:Mt,startingLocalPath:ln,sidebarOpen:oe,sidebarCollapsed:ke,messages:Ue,queuedMessages:Ht,previousPrompt:Ve,latestToolIds:Vt,runtime:Fe,runtimeStatus:wn,isHistoryLoading:T,hasOlderHistory:L,availableProviders:Fn,isProcessing:Er,canCancel:K,isDraining:xe,navbarLocalPath:Qe,editorLabel:Ne,hasSelectedProject:ut,addProjectModalOpen:Ze,openSidebar:vo,closeSidebar:el,collapseSidebar:Op,expandSidebar:Dh,openAddProjectModal:zp,closeAddProjectModal:cc,loadOlderHistory:Ke,handleCreateChat:or,handleForkChat:si,handleOpenLocalProject:os,handleCreateProject:qr,handleCheckForUpdates:uo,handleInstallUpdate:Fi,handleForceReload:kt,handleReadAppSettings:ct,handleWriteAppSettings:Qt,handleTestMcpServer:Ut,handleSetChatPolicyOverride:nn,handleWriteCloudflareTunnel:Rt,handleWriteClaudeAuth:xt,handleTestOAuthToken:mt,handleReadLlmProvider:Ct,handleWriteLlmProvider:pt,handleValidateLlmProvider:$t,handleSignOut:rn,handleSend:mn,handleSteerQueuedMessage:pn,handleRemoveQueuedMessage:Kr,handleCancel:Za,handleStopDraining:ho,handleRenameChat:Yo,handleArchiveChat:Ja,handleOpenArchivedChat:Jn,handleDeleteChat:Os,handleHideProject:fo,handleToggleProjectStar:mo,handleReorderProjectGroups:po,stacks:Ye.stacks,handleCreateStack:_i,handleRenameStack:Xo,handleRemoveStack:Qo,handleAddProjectToStack:wi,handleRemoveProjectFromStack:Zo,handleCreateStackChat:go,handleListStackWorktrees:Ee,importClaudeSessions:W,handleCopyPath:ar,handleOpenExternal:Gt,handleOpenExternalPath:Jo,handleOpenLocalLink:Yr,handleCompose:lc,handleAskUserQuestion:zs,handleExitPlanMode:Ph,handleSubagentAskUserQuestion:uc,handleSubagentExitPlanMode:bo,handleToolRequestAnswer:Oh}}const fD=/<thinking>([\s\S]*?)<\/thinking>/gi;function H0e(e){const t=[];let n=0;fD.lastIndex=0;let r;for(;(r=fD.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 U0e(t)}function U0e(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 F2=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(tb,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"font-medium uppercase tracking-wider",children:"Thinking"}),u.jsx(As,{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})})]})}),ZF=v.memo(function({message:t}){const n=v.useMemo(()=>H0e(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(F2,{content:r.content},i):u.jsx(Wo,{remarkPlugins:Fa,components:$a,children:r.content},i))})}),JF=v.memo(function({message:t}){return u.jsx("div",{className:"px-0.5 w-full max-w-[70ch]",children:u.jsx(F2,{content:t.text})})}),jp=({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 V0e(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 W0e(e){return e.replace(/<[^>]+>/g,"")}function G0e(e,t){const n=e.split(`
2637
2637
  `),r=t.split(`
2638
- `),i=q0e(n,r),s=K0e(n,r,i);return Y0e(s)}function q0e(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 K0e(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 Y0e(e){return e.map(t=>{const n=t.type==="removed"?"-":t.type==="added"?"+":" ";return{type:t.type,content:`${n}${t.text}`}})}function Ov({content:e,isDiff:t=!1,oldString:n,newString:r}){const i=v.useMemo(()=>t&&n!==void 0&&r!==void 0?G0e(n,r):[],[t,n,r]),s=v.useMemo(()=>t?[]:V0e(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":"",m=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 ${m}`,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:W0e(a.content)})]},c))})})})})}function X0e(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 Z0e(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 J0e(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 e_e({status:e}){const t=X0e(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",Z0e(t))}),u.jsx("span",{className:J0e(t),children:Q0e(e)})]})}function t_e(){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 n_e({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(e_e,{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(t_e,{})]})]})}const e$=v.createContext(null);function r_e({children:e,value:t}){return u.jsx(e$.Provider,{value:t,children:e})}function i_e(){return v.useContext(e$)}function s_e(e,t){return t||e==="failed"||e==="error"?"destructive":e==="in_progress"||e==="running"?"active":"muted"}function o_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 a_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 l_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 c_e({subagentType:e,result:t,isError:n,localPath:r}){const i=e||"Agent",s=s_e(t==null?void 0:t.status,n),o=l_e(t==null?void 0:t.toolStats),a=i_e(),c=t==null?void 0:t.agentId,d=!!(a&&c),[m,f]=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=!m;f(A),A&&!y&&!g&&(b(!0),k(null),a(c).then(j=>{C(D2(j)),_(!0)}).catch(j=>k(j instanceof Error?j.message:"Failed to load subagent transcript")).finally(()=>b(!1)))},[a,c,m,y,g]),R=u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d?u.jsx(As,{className:de("size-4 text-muted-icon shrink-0 transition-transform",m&&"rotate-90"),"aria-hidden":!0}):u.jsx(Lx,{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",o_e(s))}),u.jsx("span",{className:a_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(Gd,{className:"size-3","aria-hidden":!0}),Mi(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:qs(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":m,className:"w-full text-left cursor-pointer",children:R}),m&&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(r$,{message:A,localPath:r??""},A.id))]})]}):R}function mD(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 u_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 fx({message:e,isLoading:t=!1,localPath:n,chatId:r=""}){var E;const i=e.result!==void 0,s=!i&&t,o=O2(hm(WF(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?G3(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"?`${s1(e.input.tool)} from ${s1(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]),m=e.toolKind==="bash",f=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=mD(k);if(T.length>0)return T}}return mD(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(Ka,{className:"w-full",children:u.jsx(x2,{expandedContent:u.jsx(ky,{className:"my-4 text-sm",children:u.jsxs("div",{className:"flex flex-col gap-2",children:[g?u.jsx(Ov,{content:"",isDiff:!0,oldString:e.input.oldString,newString:e.input.newString}):b?u.jsx(Ov,{content:e.input.content}):!y&&!f&&u.jsx(uC,{label:m?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"})]}):f?"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(u_e,{images:w})})]}):u.jsx(Ov,{content:_})),f&&!e.isError&&u.jsx(Ov,{content:e.input.content}),i&&!y&&!(f&&!e.isError)&&!(g&&!e.isError)&&!(b&&!e.isError)&&u.jsx(uC,{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(n_e,{name:e.input.name,description:e.input.description,run:R})})():e.toolKind==="subagent_task"&&e.result?u.jsx(c_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(Ds,{className:"size-4 text-destructive"}):c?u.jsx(Lx,{className:"size-4 text-muted-icon"}):e.toolKind==="workflow"?u.jsx(Na,{className:"size-4 text-muted-icon"}):u.jsx(mF,{icon:fF(e.toolName),className:"size-4 text-muted-icon"})}),u.jsx(lu,{className:"text-left transition-opacity duration-200 truncate",children:u.jsx(jp,{animate:s,shimmerWidth:Math.max(20,(((E=d||a)==null?void 0:E.length)??33)*3),children:d||a})})]})})})}function d_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 pD({durationMs:e,prefix:t="Worked for"}){return e<=0?null:u.jsxs(qbe,{children:[t," ",d_e(e)]})}const hS=/\[([^\]]+)\]\(\/chat\/([0-9a-fA-F][0-9a-fA-F-]{7,})\)/g;function t$(e,t){const n=[];let r=0,i=0;hS.lastIndex=0;for(let s=hS.exec(e);s!==null;s=hS.exec(e))s.index>r&&n.push(e.slice(r,s.index)),n.push(u.jsx(xk,{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 n$({message:e}){if(!e.success){const t=e.result.trim().length>0;return u.jsxs(u.Fragment,{children:[t?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:t$(e.result)}):null,e.durationMs>0?u.jsx(pD,{durationMs:e.durationMs,prefix:"Failed after"}):null]})}return u.jsx(pD,{durationMs:e.durationMs})}function h_e(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}function f_e(e){return typeof e=="string"?e:JSON.stringify(e,null,2)}function m_e(e){return e.replace(/<persisted-output>\n?/g,"").replace(/\n?<\/persisted-output>/g,"")}function r$({message:e,localPath:t,isRunning:n=!1}){if(e.kind==="tool"&&e.persisted){const i=m_e(f_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 (",h_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:c2(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(ZF,{message:e});break;case"assistant_thinking":r=u.jsx(JF,{message:e});break;case"tool":r=u.jsx(fx,{message:e,isLoading:n,localPath:t});break;case"result":r=u.jsx(n$,{message:e});break;default:return null}return u.jsx("div",{className:"animate-in fade-in-0 duration-200",children:r})}function p_e(e){switch(e){case"AUTH_REQUIRED":return"Auth required";case"UNKNOWN_SUBAGENT":return"Unknown subagent";case"MANUAL_ONLY":return"Manual only";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 g_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(ym,{className:"h-4 w-4"}),u.jsx("span",{children:p_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(DG,{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(Nq,{className:"h-3 w-3"})," Retry"]})]})]})}function v_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(_W,{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 gD({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 i$({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(rs,{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 b_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(gD,{label:e.label,description:e.description})}),u.jsx(i$,{selected:t,multiSelect:n})]})}):u.jsx("div",{className:de(s,o),children:u.jsx(gD,{label:e.label,description:e.description})})}function s$({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,m=(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 $?[$]:[]},f=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=>m(d(M),M).length>0),w=e[Math.min(r,e.length-1)],C=r>=e.length-1,E=m(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]=m(z,D)}t(M)},A=M=>{if(M.key==="Enter"&&E){if(M.preventDefault(),C){R();return}k()}},j=f(w),L=a[d(w)]||"";return u.jsxs("div",{className:"w-full space-y-3",children:[u.jsxs(v_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(b_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(i$,{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(Pe,{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(Pe,{size:"sm",onClick:k,children:"Next"}),C&&u.jsx(Pe,{size:"sm",onClick:R,disabled:!_,className:de(!_&&"opacity-50 cursor-not-allowed","rounded-full"),children:"Submit"})]})]})]})}function x_e(e){return e==null?void 0:e.answers}function fS(e){return e.id||e.question}function o$({message:e,onSubmit:t,isLatest:n}){var g;const r=Cy(),i=e.input.questions,s=!!e.result,o=x_e(e.result),a=((g=e.result)==null?void 0:g.discarded)===!0,[c,d]=v.useState(o??null),[m,f]=v.useState(s);if(m||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[fS(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"})})]},fS(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"})]},fS(b))})]})}):n?u.jsx(s$,{questions:i,onSubmit:b=>{d(b),f(!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(eO,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"Questions pending (newer question active)"})]})})}function a$({message:e,onConfirm:t,isLatest:n}){const r=Cy(),i=!!e.result,[s,o]=v.useState(!1),[a,c]=v.useState(!1),[d,m]=v.useState(!1),[f,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(Pe,{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(rs,{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(Pe,{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(fh,{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(zW,{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(Pe,{size:"sm",onClick:()=>t(e.toolId,!0,!0),className:"rounded-full bg-primary text-background pr-4 md:order-last",children:[u.jsx(pW,{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(Pe,{size:"sm",variant:"outline",onClick:()=>m(!0),className:"rounded-full border-border flex-1 md:flex-initial md:order-first",children:[u.jsx(mh,{className:"h-4 w-4 mr-1.5"}),"Suggest Edits"]}),u.jsxs(Pe,{size:"sm",variant:"outline",onClick:()=>t(e.toolId,!0),className:"rounded-full border-border flex-1 md:flex-initial",children:[u.jsx(rs,{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:f,onChange:E=>g(E.target.value),onKeyDown:E=>{E.key==="Enter"&&!E.shiftKey&&f.trim()&&(E.preventDefault(),t(e.toolId,!1,void 0,f.trim())),E.key==="Escape"&&(m(!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(Pe,{size:"sm",variant:"ghost",onClick:()=>{m(!1),g("")},className:"rounded-full text-muted-foreground",children:"Cancel"}),u.jsxs(Pe,{size:"sm",disabled:!f.trim(),onClick:()=>t(e.toolId,!1,void 0,f.trim()),className:"rounded-full bg-primary text-background disabled:opacity-50 disabled:pointer-events-none",children:[u.jsx(Iq,{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 l$({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(o$,{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(a$,{message:i,onConfirm:(s,o,a,c)=>n(s,{confirmed:o,clearContext:a,message:c}),isLatest:!0})]})}return null}const y_e=40;function gs(e,t=y_e){return e.length<=t?e:`${e.slice(0,t-1)}…`}function __e(e,t){switch(e.toolKind){case"bash":{const n=e.input.description||(e.input.command?G3(e.input.command):"");return n?`$ ${gs(n)}`:"running bash..."}case"read_file":{const n=Ul(e.input.filePath,t);return n?`reading ${gs(n)}`:"reading file..."}case"write_file":{const n=Ul(e.input.filePath,t);return n?`writing ${gs(n)}`:"writing file..."}case"edit_file":{const n=Ul(e.input.filePath,t);return n?`editing ${gs(n)}`:"editing file..."}case"delete_file":{const n=Ul(e.input.filePath,t);return n?`deleting ${gs(n)}`:"deleting file..."}case"glob":return e.input.pattern?`globbing ${gs(e.input.pattern)}`:"globbing...";case"grep":return e.input.pattern?`grepping ${gs(e.input.pattern)}`:"grepping...";case"web_search":return e.input.query?`searching: ${gs(e.input.query)}`:"searching web...";case"skill":return e.input.skill?`skill ${gs(e.input.skill)}`:"running skill...";case"todo_write":return"updating todos...";case"subagent_task":return e.input.subagentType?`delegating ${gs(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 gs(`${e.input.server}.${e.input.tool}`);case"unknown_tool":return`running ${gs(e.toolName)}`;default:return"running..."}}function w_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 __e(o.tool,t)}const i=n[n.length-1];return(i==null?void 0:i.kind)==="assistant_text"?"streaming...":"running..."}function c$({run:e,indentDepth:t,localPath:n,onOpenSettings:r,onRetry:i,onSubagentAskUserQuestionSubmit:s,onSubagentExitPlanModeSubmit:o,onCancelSubagentRun:a,suppressPendingTool:c=!1}){var b;const d=D2(e.entries),m=d.some(y=>y.kind==="assistant_text"),f=e.status==="running"&&m,g=e.status==="running"?w_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`},[wm]:"",children:[u.jsxs("header",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[u.jsx(vu,{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}`:""]}),((b=e.usage)==null?void 0:b.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:g}),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(Ds,{className:"h-3.5 w-3.5"})})]}),d.map(y=>u.jsx(r$,{message:y,localPath:n,isRunning:e.status==="running"},y.id)),!c&&e.pendingTool&&u.jsx(l$,{pendingTool:e.pendingTool,onAskUserQuestionSubmit:(y,_,w)=>s==null?void 0:s(e.runId,y,_,w),onExitPlanModeSubmit:(y,_)=>o==null?void 0:o(e.runId,y,_)}),d.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(g_e,{error:e.error,runId:e.runId,subagentId:e.subagentId,onOpenSettings:r,onRetry:i})})]})}function S_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 C_e=v.memo(function({content:t,attachments:n=[],steered:r=!1,autoContinue:i}){const[s,o]=v.useState(null),a=Cy(),c=v.useMemo(()=>S_e(t),[t]),d=!a.readonly,m=v.useMemo(()=>n.filter(_=>_.kind==="image"&&_.contentUrl),[n]),f=v.useMemo(()=>n.filter(_=>_.kind!=="image"||!_.contentUrl),[n]),g=n.find(_=>_.id===s)??null,b=g?Ap(g,"user_attachment"):null;function y(_){if(!d||!_.contentUrl)return;if(Th(_).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:[m.length>0?u.jsx("div",{className:"flex max-w-[85%] sm:max-w-[80%] flex-wrap justify-end gap-3",children:m.map(_=>u.jsx(_2,{attachment:_,onClick:d?()=>y(_):void 0},_.id))}):null,f.length>0?u.jsx("div",{className:"flex max-w-[85%] sm:max-w-[80%] flex-wrap justify-end gap-2",children:f.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(vK,{"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(jh,{source:b,open:b!==null,onOpenChange:_=>!_&&o(null)})]})});function k_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 u$({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(As,{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 mS({title:e,items:t,icon:n,getIcon:r}){return t.length===0?null:u.jsx(u$,{title:e,count:t.length,children:u.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.map(i=>u.jsx(gF,{icon:r?r(i):n,children:i},i))})})}function E_e(e){const t=e.match(/^mcp__([^_]+)__(.+)$/);return t?{server:t[1],tool:t[2]}:null}function d$({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 N_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 vD({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(As,{className:de("h-3 w-3 text-muted-foreground transition-transform duration-200",t&&"rotate-90")}),u.jsx(d$,{status:e.status}),u.jsx("span",{className:"text-muted-foreground font-medium",children:s1(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:N_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(gF,{icon:fF(`mcp__${e.name}__${i}`),children:i},i))})]})}function T_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(d$,{status:"failed"}),u.jsxs("span",{className:"text-muted-foreground/60",children:[n.length," disconnected"]})]}):null;return u.jsx(u$,{title:"MCP Servers",count:e.length,badge:r,children:u.jsxs("div",{className:"flex flex-col gap-2",children:[t.map(i=>u.jsx(vD,{server:i},i.name)),n.map(i=>u.jsx(vD,{server:i},i.name))]})})}function R_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(As,{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 A_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=E_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(Ka,{children:u.jsxs(x2,{expandedContent:u.jsx(ky,{className:"my-4 text-xs",children:u.jsxs("div",{className:"flex flex-col gap-3",children:[u.jsx(Gbe,{children:e.model}),u.jsx(mS,{title:"Tools",items:n,getIcon:i=>cC[i]??hF}),u.jsx(mS,{title:"Agents",items:e.agents,icon:Lx}),u.jsx(mS,{title:"Commands",items:e.slashCommands,icon:Uq}),u.jsx(T_e,{servers:r}),t&&u.jsx(R_e,{rawJson:t})]})}),children:[u.jsx(iW,{className:"h-5 w-5 text-logo"}),u.jsx(lu,{children:"Session Started"})]})})}const j_e={"kanna-oauth-pool":"Pool token","claude-pro":"Claude Pro","claude-max":"Claude Max",openrouter:"OpenRouter"};function M_e(e,t){return e?j_e[e]??e:t?`API key (${t})`:null}function L_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=M_e(n,r),[d,m]=v.useState(!1);return u.jsx(Ka,{children:u.jsxs("div",{className:"flex w-full flex-col",children:[u.jsxs("button",{type:"button",onClick:()=>m(f=>!f),"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(As,{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(ky,{className:"mt-3 mb-2 text-xs",children:u.jsxs("div",{className:"flex flex-col gap-3",children:[u.jsx(uC,{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 I_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 D_e(e){if(e!==0)return"https://status.claude.com"}function P_e({message:e}){const t=e.status>0?`${e.status} ${I_e(e.status)}`:"API Error",n=D_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(ym,{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 O_e="https://www.anthropic.com/legal/aup";function z_e(e){return e.replace(/^API Error:\s*/i,"")}function B_e({message:e}){const t=z_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(kk,{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:O_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 F_e={completed:{Icon:rs,iconClass:"text-success",textClass:"text-muted-foreground"},in_progress:{Icon:bn,iconClass:"text-foreground animate-spin",textClass:"text-foreground font-medium"},pending:{Icon:NW,iconClass:"text-muted-foreground",textClass:"text-muted-foreground"}};function $_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($G,{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}=F_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 H_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=Rh(a),d=gy(c,t.mimeType),m=t.size>0?Mh(t.size):null,f=u.jsxs(u.Fragment,{children:[d,m?u.jsxs(u.Fragment,{children:[" · ",u.jsx("span",{className:"tabular-nums",children:m})]}):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(!Th(a).openInNewTab){const _=`Preview ${a.displayName}, ${d}${m?`, ${m}`:""}`;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:f,ariaLabel:_})}),u.jsx(jh,{source:s?Ap(a,"offer_download"):null,open:s,onOpenChange:o})]})}const y=["Download",a.displayName,d,m].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:f,ariaLabel:y.join(", ")})})}const pS=new Map;function U_e(e){const{cacheKey:t,enabled:n,ref:r,fetcher:i,rootMargin:s}=e,o=pS.get(t),[a,c]=v.useState(o!==void 0?"ready":"idle"),[d,m]=v.useState(o!==void 0?o:null),[f,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=pS.get(t);c(C!==void 0?"ready":"idle"),m(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||(pS.set(k,L),m(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:f}),[a,d,f])}function V_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=Rh(r),s=gy(i,e.mimeType),o=e.size&&e.size>0?Mh(e.size):null;return i==="image"?u.jsx("button",{type:"button",onClick:t,"aria-label":`Preview ${e.displayName}`,className:"overflow-hidden rounded-xl border border-border bg-background",children:u.jsx("img",{src:e.contentUrl,alt:e.altText??e.displayName,loading:"lazy",className:"max-h-64 w-auto max-w-full object-contain"})}):n==="expanded"&&(i==="text"||i==="code"||i==="markdown"||i==="json"||i==="table")?u.jsx(W_e,{source:e,onOpen:t,friendlyType:s,sizeLabel:o}):u.jsx($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 W_e=function({source:t,onOpen:n,friendlyType:r,sizeLabel:i}){const s=v.useRef(null),o=t.contentUrl,a=v.useCallback(async m=>{const f=await t2(o,4096);if(m.aborted)throw new Error("aborted");return f.content.slice(0,200)},[o]),c=U_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 G_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(V_e,{source:c,onOpen:()=>a(!0),variant:"expanded"}),n?u.jsx("figcaption",{className:"text-xs text-muted-foreground italic",children:n}):null,u.jsx(jh,{source:o?c:null,open:o,onOpenChange:a})]})}function q_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(kW,{className:"h-4 w-4 ml-1.5"}),u.jsx("em",{children:"Interrupted"})]})})}function mx({size:e=4}){return u.jsxs("svg",{className:"flex-1",viewBox:`0 0 100 ${e}`,preserveAspectRatio:"none",style:{height:`${e}px`},children:[u.jsx("pattern",{id:"zigzag",width:e,height:e,patternUnits:"userSpaceOnUse",children:u.jsx("path",{d:`M0 ${e} L${e/2} 0 L${e} ${e}`,fill:"none",stroke:"currentColor",strokeWidth:"0.5",className:"text-muted-foreground/30",style:{stroke:"currentColor"}})}),u.jsx("rect",{width:"100%",height:e,fill:"url(#zigzag)",className:"text-muted-foreground/30"})]})}function K_e(){return u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx(mx,{}),u.jsx("span",{className:"text-[11px] tracking-widest text-muted-foreground uppercase flex-shrink-0",children:"Compacted"}),u.jsx(mx,{})]})}function Y_e(){return u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx(mx,{}),u.jsx("span",{className:"text-[11px] tracking-widest text-muted-foreground uppercase flex-shrink-0",children:"Context Cleared"}),u.jsx(mx,{})]})}function X_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(Ax,{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 Q_e({message:e}){return u.jsx(Ka,{children:u.jsxs(x2,{expandedContent:u.jsx(ky,{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(tO,{className:"h-4.5 w-4.5 text-muted-foreground"})}),u.jsx(lu,{children:"Summarized"})]})})}const Z_e={compacting:"Compacting..."};function J_e({message:e}){const t=Z_e[e.status]||e.status;return u.jsxs(Ka,{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(tO,{className:"h-4.5 w-4.5 text-muted-foreground"})}),u.jsx(lu,{className:"text-left transition-opacity duration-200 truncate",children:t})]})}const ewe={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"}},twe={key:"other",singular:"tool call",plural:"tool calls"};function nwe(e){return ewe[e]??twe}function rwe(e){const t=new Map,n=[];for(const r of e){const i=r.toolKind,s=nwe(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 iwe({messages:e,isLoading:t,localPath:n,expanded:r,onExpandedChange:i,chatId:s}){const o=v.useMemo(()=>rwe(e),[e]),c=e.some(d=>d.result===void 0)&&t;return u.jsx(Ka,{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(As,{className:`h-4.5 w-4.5 text-muted-icon transition-all duration-200 ${r?"rotate-90":""}`})}),u.jsx(lu,{className:"text-left",children:u.jsx(jp,{animate:c,children:o})})]})}),r&&u.jsxs("div",{className:"my-4 flex flex-col gap-3",children:[e.map(d=>u.jsx(fx,{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(As,{className:"h-4.5 w-4.5 text-muted-icon -rotate-90"})}),u.jsx(lu,{className:"text-left",children:"Collapse"})]})})]})]})})}function swe(e){if(e!=="system")return e}function gS(e,t){const n=swe(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 owe=/^(\d{2})\/(\d{2})\/(\d{4}) (\d{2}):(\d{2})$/;function bD(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 awe(e,t){const n=owe.exec(e.trim());if(!n)return null;const[,r,i,s,o,a]=n,c=Number(r),d=Number(i),m=Number(s),f=Number(o),g=Number(a);if(d<1||d>12||c<1||c>31||f>23||g>59)return null;const b=Date.UTC(m,d-1,c,f,g),y=bD(t,b),_=b-y*6e4,w=bD(t,_);return _-(w-y)*6e4}const lwe={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"},cwe={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),m=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]),f=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",lwe[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(Pe,{type:"button",size:"sm",variant:cwe[g.variant??"ghost"],disabled:g.disabled||f&&!b,onClick:()=>{m(g)},className:"gap-1.5",children:[b?u.jsx(bn,{className:"size-3.5 animate-spin"}):null,g.label]},g.id)})}):null]})}function uwe({schedule:e,onAccept:t,onReschedule:n,onCancel:r}){const[i,s]=v.useState(()=>gS(e.scheduledAt??e.resetAt,e.tz)),[o,a]=v.useState(!1),c=v.useMemo(()=>awe(i,e.tz),[i,e.tz]),d=c!==null&&c>Date.now(),m=c===null?"Use format dd/mm/yyyy hh:mm":d?null:"Time must be in the future";if(e.state==="fired"){const y=gS(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(dn,{value:i,onChange:w=>s(w.target.value),placeholder:"dd/mm/yyyy hh:mm"}),m&&u.jsx("div",{className:"text-destructive text-xs",children:m})]}),actions:_})}const f=gS(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 ${f} (${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 ${f} (${g})`,body:u.jsxs("div",{className:"space-y-1",children:[u.jsx(dn,{value:i,onChange:y=>s(y.target.value),placeholder:"dd/mm/yyyy hh:mm"}),m&&u.jsx("div",{className:"text-destructive text-xs",children:m})]}),actions:b})}function dwe({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(Pe,{size:"sm",variant:"outline",className:"rounded-full",onClick:()=>n(e,{kind:"deny",reason:"user_canceled"}),children:"Edit"}),u.jsx(Pe,{size:"sm",className:"rounded-full",onClick:()=>n(e,{kind:"answer",payload:{confirmed:!0}}),children:"Confirm"})]})]})}function hwe({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(Pe,{variant:"ghost",size:"sm",onClick:()=>r(e,{kind:"deny",reason:"user_canceled"}),children:"Deny"}),u.jsx(Pe,{variant:"default",size:"sm",onClick:()=>r(e,{kind:"allow"}),children:"Allow"})]})]})}function fwe({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(s$,{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(dwe,{toolRequestId:n,plan:s,onAnswer:t})}return u.jsx(hwe,{toolRequestId:n,toolName:r,args:i,onAnswer:t})}const $2="mcp__kanna__delegate_subagent";function mwe(e){const t=[];for(const n of e){if(n.kind!=="tool"||n.toolKind!=="mcp_generic"||n.toolName!==$2)continue;const r=n.input.payload.subagent_id;typeof r=="string"&&t.push({toolId:n.toolId,subagentId:r})}return t}function pwe(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,m=c[d];m&&(r.set(a.toolId,m),i.add(m.runId),s.set(a.subagentId,d+1))}const o=t.filter(a=>!i.has(a.runId));return{matched:r,orphans:o}}function gwe(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 vwe=new Set(["AskUserQuestion","ExitPlanMode","TodoWrite",$2]);function xD(e){if(e.kind!=="tool")return!1;const t=e.toolName;return!vwe.has(t)}function bwe(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 xwe(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 bwe(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 ywe(e,t){const n=[];let r=0;for(;r<e.length;){const i=e[r],s=t[r];if(s!=null&&s.shouldRender&&xD(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(!xD(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 yD(e){var n;return e.type==="single"?e.message.id:`tool-group:${((n=e.messages[0])==null?void 0:n.id)??e.startIndex}`}function vS(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>n===t[r])}function _we(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 wwe(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>_we(n,t[r]))}function sh(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)&&wwe(e.attachments,t.attachments);case"system_init":return t.kind==="system_init"&&e.provider===t.provider&&e.model===t.model&&vS(e.tools,t.tools)&&vS(e.agents,t.agents)&&vS(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 Swe(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&&sh(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)=>sh(n,t.messages[r])):!1}function Cwe(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&&Swe(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 kwe(e){const t=v.useRef({byId:new Map,result:[]}),n=v.useMemo(()=>Cwe(e,t.current),[e]);return v.useLayoutEffect(()=>{t.current=n}),n.result}const h$=(e,t)=>{},Ewe=v.memo(function({message:t,index:n,isLoading:r,localPath:i,isFirstSystem:s,isFirstAccount:o,isLatestAskUserQuestion:a,isLatestExitPlanMode:c,isLatestTodoWrite:d,hideResult:m,isFinalStatus:f,onAskUserQuestionSubmit:g,onExitPlanModeConfirm:b,onToolRequestAnswer:y=h$,schedules:_,onAutoContinueAccept:w,onAutoContinueReschedule:C,onAutoContinueCancel:E,chatId:k}){let T=null;if(t.kind==="user_prompt")T=u.jsx(C_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(uwe,{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(k_e,{json:t.json},t.id);break;case"system_init":T=s?u.jsx(A_e,{message:t,rawJson:t.debugRaw},t.id):null;break;case"account_info":T=o?u.jsx(L_e,{message:t},t.id):null;break;case"assistant_text":T=u.jsx(ZF,{message:t},t.id);break;case"assistant_thinking":T=u.jsx(JF,{message:t},t.id);break;case"api_error":T=u.jsx(P_e,{message:t},t.id);break;case"policy_refusal":T=u.jsx(B_e,{message:t},t.id);break;case"tool":if(t.isError){T=u.jsx(fx,{message:t,isLoading:r,localPath:i,chatId:k},t.id);break}if(t.toolKind==="ask_user_question"){T=u.jsx(o$,{message:t,onSubmit:g,isLatest:a},t.id);break}if(t.toolKind==="exit_plan_mode"){T=u.jsx(a$,{message:t,onConfirm:b,isLatest:c},t.id);break}if(t.toolKind==="todo_write"){T=d?u.jsx($_e,{message:t},t.id):null;break}if(t.toolKind==="offer_download"&&t.result){T=u.jsx(H_e,{message:t},t.id);break}if(t.toolKind==="image_generation"){T=u.jsx(G_e,{message:t},t.id);break}T=u.jsx(fx,{message:t,isLoading:r,localPath:i,chatId:k},t.id);break;case"result":T=m?null:u.jsx(n$,{message:t},t.id);break;case"context_window_updated":T=null;break;case"interrupted":T=u.jsx(q_e,{message:t},t.id);break;case"compact_boundary":T=u.jsx(K_e,{},t.id);break;case"context_cleared":T=u.jsx(Y_e,{},t.id);break;case"memory_loaded":T=u.jsx(X_e,{message:t},t.id);break;case"compact_summary":T=u.jsx(Q_e,{message:t},t.id);break;case"status":T=f?u.jsx(J_e,{message:t},t.id):null;break;case"pending_tool_request":T=u.jsx(fwe,{entry:t,onAnswer:y},t.id);break}return T?u.jsx("div",{id:`msg-${t.id}`,className:"group relative","data-index":n,[wm]:"",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&&sh(e.message,t.message)),Nwe=v.memo(function({id:t,messages:n,isLoading:r,localPath:i,expanded:s,onExpandedChange:o,chatId:a}){return u.jsx("div",{className:"group relative",[wm]:"",children:u.jsx(iwe,{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)=>sh(n,t.messages[r])));function f$(e,{isLoading:t,localPath:n,latestToolIds:r}){const i=xwe(e,r),s=ywe(e,i),o=[];for(const a of s){if(a.type==="tool-group"){o.push({kind:"tool-group",id:yD(a),startIndex:a.startIndex,messages:a.messages,isLoading:t&&a.messages.some(m=>m.kind==="tool"&&m.result===void 0),localPath:n});continue}const c=i[a.index];if(!c)continue;const d={kind:"single",id:yD(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 Twe={};function m$(e,t,n,r,i,s,o){const a=n.get(e.runId)??[];return u.jsxs(_n.Fragment,{children:[u.jsx(c$,{run:e,indentDepth:t,localPath:r,onSubagentAskUserQuestionSubmit:i,onSubagentExitPlanModeSubmit:s,onCancelSubagentRun:o}),a.map(c=>m$(c,t+1,n,r,i,s,o))]},e.runId)}const p$=v.memo(function({row:t,toolGroupExpanded:n,onToolGroupExpandedChange:r,onAskUserQuestionSubmit:i,onExitPlanModeConfirm:s,onToolRequestAnswer:o,schedules:a,onAutoContinueAccept:c,onAutoContinueReschedule:d,onAutoContinueCancel:m,chatId:f}){return t.kind==="tool-group"?u.jsx(Nwe,{id:t.id,startIndex:t.startIndex,messages:t.messages,isLoading:t.isLoading,localPath:t.localPath,expanded:n??!1,onExpandedChange:r,chatId:f}):u.jsx(Ewe,{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:m,chatId:f})},(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)=>sh(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&&sh(e.row.message,t.row.message):!1}),g$={},Rwe=(e,t)=>{},Awe=(e,t)=>{},jwe=e=>{};function Mwe({messages:e,isLoading:t,localPath:n,latestToolIds:r,onOpenLocalLink:i,chatId:s,onAskUserQuestionSubmit:o,onExitPlanModeConfirm:a,onToolRequestAnswer:c=h$,schedules:d=g$,onAutoContinueAccept:m=Rwe,onAutoContinueReschedule:f=Awe,onAutoContinueCancel:g=jwe,onTunnelAccept:b,onTunnelStop:y,onTunnelRetry:_,subagentRuns:w=Twe,onSubagentAskUserQuestionSubmit:C,onSubagentExitPlanModeSubmit:E,onCancelSubagentRun:k}){const[T,R]=v.useState({}),A=v.useMemo(()=>f$(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}=pwe(mwe(e),M);return gwe(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(dF,{onOpenLocalLink:i,children:A.map(M=>{const D=M.kind==="single"&&M.message.kind==="tool"&&M.message.toolName===$2?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(p$,{row:M,toolGroupExpanded:M.kind==="tool-group"?T[M.id]??!1:void 0,onToolGroupExpandedChange:H,onAskUserQuestionSubmit:o,onExitPlanModeConfirm:a,onToolRequestAnswer:c,schedules:d,onAutoContinueAccept:m,onAutoContinueReschedule:f,onAutoContinueCancel:g,chatId:s}),z?m$(z,0,L,n??"",C,E,k):null]},M.id)})})}v.memo(Mwe);const Lwe=Object.freeze([]),bS=Oi((e,t)=>({sharesByChat:{},listForChat(n){return t().sharesByChat[n]??Lwe},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)}}))}})),Iwe=/^\/(\S*)$/;function v$(e){return e.replace(/^\/+/,"")}function Dwe(e){const{command:t,value:n,caret:r}=e,i=n.slice(0,r),s=n.slice(r),o=/^\/(\S*)$/.exec(i);if(!o)return{value:n,caret:r};const a=o[0].length,c=i.slice(0,i.length-a),d=v$(t.name),m=t.argumentHint?`/${d} `:`/${d}`,f=`${c}${m}${s}`,g=c.length+m.length;return{value:f,caret:g}}function Pwe(e,t){if(t<=0)return{open:!1,query:""};const n=e.slice(0,t),r=Iwe.exec(n);return r?{open:!0,query:r[1]??""}:{open:!1,query:""}}function Owe(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 zwe=4,_D=80;function Bwe(e){return e.length<=_D?e:`${e.slice(0,_D-1).trimEnd()}…`}function Fwe({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:zwe}).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:["/",v$(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:Bwe(o.description)}):null]},o.name))})}const $we=4;function Hwe({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:$we}).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,m=(d==null?void 0:d.kind)==="dir"?Q5:Ax;return u.jsxs("li",{role:"option","aria-selected":a===t,onMouseDown:f=>{f.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(oW,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),c?u.jsxs(u.Fragment,{children:[u.jsx(vu,{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(m,{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 zv={open:!1,query:"",tokenStart:-1};function Uwe(e,t){if(t<=0)return zv;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===`
2638
+ `),i=q0e(n,r),s=K0e(n,r,i);return Y0e(s)}function q0e(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 K0e(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 Y0e(e){return e.map(t=>{const n=t.type==="removed"?"-":t.type==="added"?"+":" ";return{type:t.type,content:`${n}${t.text}`}})}function Ov({content:e,isDiff:t=!1,oldString:n,newString:r}){const i=v.useMemo(()=>t&&n!==void 0&&r!==void 0?G0e(n,r):[],[t,n,r]),s=v.useMemo(()=>t?[]:V0e(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":"",m=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 ${m}`,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:W0e(a.content)})]},c))})})})})}function X0e(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 Z0e(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 J0e(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 e_e({status:e}){const t=X0e(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",Z0e(t))}),u.jsx("span",{className:J0e(t),children:Q0e(e)})]})}function t_e(){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 n_e({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(e_e,{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(t_e,{})]})]})}const e$=v.createContext(null);function r_e({children:e,value:t}){return u.jsx(e$.Provider,{value:t,children:e})}function i_e(){return v.useContext(e$)}function s_e(e,t){return t||e==="failed"||e==="error"?"destructive":e==="in_progress"||e==="running"?"active":"muted"}function o_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 a_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 l_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 c_e({subagentType:e,result:t,isError:n,localPath:r}){const i=e||"Agent",s=s_e(t==null?void 0:t.status,n),o=l_e(t==null?void 0:t.toolStats),a=i_e(),c=t==null?void 0:t.agentId,d=!!(a&&c),[m,f]=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=!m;f(A),A&&!y&&!g&&(b(!0),k(null),a(c).then(j=>{C(D2(j)),_(!0)}).catch(j=>k(j instanceof Error?j.message:"Failed to load subagent transcript")).finally(()=>b(!1)))},[a,c,m,y,g]),R=u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d?u.jsx(As,{className:de("size-4 text-muted-icon shrink-0 transition-transform",m&&"rotate-90"),"aria-hidden":!0}):u.jsx(Lx,{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",o_e(s))}),u.jsx("span",{className:a_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(Gd,{className:"size-3","aria-hidden":!0}),Mi(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:qs(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":m,className:"w-full text-left cursor-pointer",children:R}),m&&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(r$,{message:A,localPath:r??""},A.id))]})]}):R}function mD(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 u_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 fx({message:e,isLoading:t=!1,localPath:n,chatId:r=""}){var E;const i=e.result!==void 0,s=!i&&t,o=O2(hm(WF(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?G3(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"?`${s1(e.input.tool)} from ${s1(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]),m=e.toolKind==="bash",f=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=mD(k);if(T.length>0)return T}}return mD(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(Ka,{className:"w-full",children:u.jsx(x2,{expandedContent:u.jsx(ky,{className:"my-4 text-sm",children:u.jsxs("div",{className:"flex flex-col gap-2",children:[g?u.jsx(Ov,{content:"",isDiff:!0,oldString:e.input.oldString,newString:e.input.newString}):b?u.jsx(Ov,{content:e.input.content}):!y&&!f&&u.jsx(uC,{label:m?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"})]}):f?"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(u_e,{images:w})})]}):u.jsx(Ov,{content:_})),f&&!e.isError&&u.jsx(Ov,{content:e.input.content}),i&&!y&&!(f&&!e.isError)&&!(g&&!e.isError)&&!(b&&!e.isError)&&u.jsx(uC,{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(n_e,{name:e.input.name,description:e.input.description,run:R})})():e.toolKind==="subagent_task"&&e.result?u.jsx(c_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(Ds,{className:"size-4 text-destructive"}):c?u.jsx(Lx,{className:"size-4 text-muted-icon"}):e.toolKind==="workflow"?u.jsx(Na,{className:"size-4 text-muted-icon"}):u.jsx(mF,{icon:fF(e.toolName),className:"size-4 text-muted-icon"})}),u.jsx(lu,{className:"text-left transition-opacity duration-200 truncate",children:u.jsx(jp,{animate:s,shimmerWidth:Math.max(20,(((E=d||a)==null?void 0:E.length)??33)*3),children:d||a})})]})})})}function d_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 pD({durationMs:e,prefix:t="Worked for"}){return e<=0?null:u.jsxs(qbe,{children:[t," ",d_e(e)]})}const hS=/\[([^\]]+)\]\(\/chat\/([0-9a-fA-F][0-9a-fA-F-]{7,})\)/g;function t$(e,t){const n=[];let r=0,i=0;hS.lastIndex=0;for(let s=hS.exec(e);s!==null;s=hS.exec(e))s.index>r&&n.push(e.slice(r,s.index)),n.push(u.jsx(xk,{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 n$({message:e}){if(!e.success){const t=e.result??"",n=t.trim().length>0;return u.jsxs(u.Fragment,{children:[n?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:t$(t)}):null,e.durationMs>0?u.jsx(pD,{durationMs:e.durationMs,prefix:"Failed after"}):null]})}return u.jsx(pD,{durationMs:e.durationMs})}function h_e(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}function f_e(e){return typeof e=="string"?e:JSON.stringify(e,null,2)}function m_e(e){return e.replace(/<persisted-output>\n?/g,"").replace(/\n?<\/persisted-output>/g,"")}function r$({message:e,localPath:t,isRunning:n=!1}){if(e.kind==="tool"&&e.persisted){const i=m_e(f_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 (",h_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:c2(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(ZF,{message:e});break;case"assistant_thinking":r=u.jsx(JF,{message:e});break;case"tool":r=u.jsx(fx,{message:e,isLoading:n,localPath:t});break;case"result":r=u.jsx(n$,{message:e});break;default:return null}return u.jsx("div",{className:"animate-in fade-in-0 duration-200",children:r})}function p_e(e){switch(e){case"AUTH_REQUIRED":return"Auth required";case"UNKNOWN_SUBAGENT":return"Unknown subagent";case"MANUAL_ONLY":return"Manual only";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 g_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(ym,{className:"h-4 w-4"}),u.jsx("span",{children:p_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(DG,{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(Nq,{className:"h-3 w-3"})," Retry"]})]})]})}function v_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(_W,{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 gD({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 i$({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(rs,{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 b_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(gD,{label:e.label,description:e.description})}),u.jsx(i$,{selected:t,multiSelect:n})]})}):u.jsx("div",{className:de(s,o),children:u.jsx(gD,{label:e.label,description:e.description})})}function s$({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,m=(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 $?[$]:[]},f=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=>m(d(M),M).length>0),w=e[Math.min(r,e.length-1)],C=r>=e.length-1,E=m(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]=m(z,D)}t(M)},A=M=>{if(M.key==="Enter"&&E){if(M.preventDefault(),C){R();return}k()}},j=f(w),L=a[d(w)]||"";return u.jsxs("div",{className:"w-full space-y-3",children:[u.jsxs(v_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(b_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(i$,{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(Pe,{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(Pe,{size:"sm",onClick:k,children:"Next"}),C&&u.jsx(Pe,{size:"sm",onClick:R,disabled:!_,className:de(!_&&"opacity-50 cursor-not-allowed","rounded-full"),children:"Submit"})]})]})]})}function x_e(e){return e==null?void 0:e.answers}function fS(e){return e.id||e.question}function o$({message:e,onSubmit:t,isLatest:n}){var g;const r=Cy(),i=e.input.questions,s=!!e.result,o=x_e(e.result),a=((g=e.result)==null?void 0:g.discarded)===!0,[c,d]=v.useState(o??null),[m,f]=v.useState(s);if(m||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[fS(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"})})]},fS(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"})]},fS(b))})]})}):n?u.jsx(s$,{questions:i,onSubmit:b=>{d(b),f(!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(eO,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"Questions pending (newer question active)"})]})})}function a$({message:e,onConfirm:t,isLatest:n}){const r=Cy(),i=!!e.result,[s,o]=v.useState(!1),[a,c]=v.useState(!1),[d,m]=v.useState(!1),[f,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(Pe,{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(rs,{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(Pe,{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(fh,{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(zW,{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(Pe,{size:"sm",onClick:()=>t(e.toolId,!0,!0),className:"rounded-full bg-primary text-background pr-4 md:order-last",children:[u.jsx(pW,{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(Pe,{size:"sm",variant:"outline",onClick:()=>m(!0),className:"rounded-full border-border flex-1 md:flex-initial md:order-first",children:[u.jsx(mh,{className:"h-4 w-4 mr-1.5"}),"Suggest Edits"]}),u.jsxs(Pe,{size:"sm",variant:"outline",onClick:()=>t(e.toolId,!0),className:"rounded-full border-border flex-1 md:flex-initial",children:[u.jsx(rs,{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:f,onChange:E=>g(E.target.value),onKeyDown:E=>{E.key==="Enter"&&!E.shiftKey&&f.trim()&&(E.preventDefault(),t(e.toolId,!1,void 0,f.trim())),E.key==="Escape"&&(m(!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(Pe,{size:"sm",variant:"ghost",onClick:()=>{m(!1),g("")},className:"rounded-full text-muted-foreground",children:"Cancel"}),u.jsxs(Pe,{size:"sm",disabled:!f.trim(),onClick:()=>t(e.toolId,!1,void 0,f.trim()),className:"rounded-full bg-primary text-background disabled:opacity-50 disabled:pointer-events-none",children:[u.jsx(Iq,{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 l$({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(o$,{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(a$,{message:i,onConfirm:(s,o,a,c)=>n(s,{confirmed:o,clearContext:a,message:c}),isLatest:!0})]})}return null}const y_e=40;function gs(e,t=y_e){return e.length<=t?e:`${e.slice(0,t-1)}…`}function __e(e,t){switch(e.toolKind){case"bash":{const n=e.input.description||(e.input.command?G3(e.input.command):"");return n?`$ ${gs(n)}`:"running bash..."}case"read_file":{const n=Ul(e.input.filePath,t);return n?`reading ${gs(n)}`:"reading file..."}case"write_file":{const n=Ul(e.input.filePath,t);return n?`writing ${gs(n)}`:"writing file..."}case"edit_file":{const n=Ul(e.input.filePath,t);return n?`editing ${gs(n)}`:"editing file..."}case"delete_file":{const n=Ul(e.input.filePath,t);return n?`deleting ${gs(n)}`:"deleting file..."}case"glob":return e.input.pattern?`globbing ${gs(e.input.pattern)}`:"globbing...";case"grep":return e.input.pattern?`grepping ${gs(e.input.pattern)}`:"grepping...";case"web_search":return e.input.query?`searching: ${gs(e.input.query)}`:"searching web...";case"skill":return e.input.skill?`skill ${gs(e.input.skill)}`:"running skill...";case"todo_write":return"updating todos...";case"subagent_task":return e.input.subagentType?`delegating ${gs(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 gs(`${e.input.server}.${e.input.tool}`);case"unknown_tool":return`running ${gs(e.toolName)}`;default:return"running..."}}function w_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 __e(o.tool,t)}const i=n[n.length-1];return(i==null?void 0:i.kind)==="assistant_text"?"streaming...":"running..."}function c$({run:e,indentDepth:t,localPath:n,onOpenSettings:r,onRetry:i,onSubagentAskUserQuestionSubmit:s,onSubagentExitPlanModeSubmit:o,onCancelSubagentRun:a,suppressPendingTool:c=!1}){var b;const d=D2(e.entries),m=d.some(y=>y.kind==="assistant_text"),f=e.status==="running"&&m,g=e.status==="running"?w_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`},[wm]:"",children:[u.jsxs("header",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[u.jsx(vu,{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}`:""]}),((b=e.usage)==null?void 0:b.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:g}),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(Ds,{className:"h-3.5 w-3.5"})})]}),d.map(y=>u.jsx(r$,{message:y,localPath:n,isRunning:e.status==="running"},y.id)),!c&&e.pendingTool&&u.jsx(l$,{pendingTool:e.pendingTool,onAskUserQuestionSubmit:(y,_,w)=>s==null?void 0:s(e.runId,y,_,w),onExitPlanModeSubmit:(y,_)=>o==null?void 0:o(e.runId,y,_)}),d.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(g_e,{error:e.error,runId:e.runId,subagentId:e.subagentId,onOpenSettings:r,onRetry:i})})]})}function S_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 C_e=v.memo(function({content:t,attachments:n=[],steered:r=!1,autoContinue:i}){const[s,o]=v.useState(null),a=Cy(),c=v.useMemo(()=>S_e(t),[t]),d=!a.readonly,m=v.useMemo(()=>n.filter(_=>_.kind==="image"&&_.contentUrl),[n]),f=v.useMemo(()=>n.filter(_=>_.kind!=="image"||!_.contentUrl),[n]),g=n.find(_=>_.id===s)??null,b=g?Ap(g,"user_attachment"):null;function y(_){if(!d||!_.contentUrl)return;if(Th(_).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:[m.length>0?u.jsx("div",{className:"flex max-w-[85%] sm:max-w-[80%] flex-wrap justify-end gap-3",children:m.map(_=>u.jsx(_2,{attachment:_,onClick:d?()=>y(_):void 0},_.id))}):null,f.length>0?u.jsx("div",{className:"flex max-w-[85%] sm:max-w-[80%] flex-wrap justify-end gap-2",children:f.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(vK,{"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(jh,{source:b,open:b!==null,onOpenChange:_=>!_&&o(null)})]})});function k_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 u$({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(As,{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 mS({title:e,items:t,icon:n,getIcon:r}){return t.length===0?null:u.jsx(u$,{title:e,count:t.length,children:u.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.map(i=>u.jsx(gF,{icon:r?r(i):n,children:i},i))})})}function E_e(e){const t=e.match(/^mcp__([^_]+)__(.+)$/);return t?{server:t[1],tool:t[2]}:null}function d$({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 N_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 vD({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(As,{className:de("h-3 w-3 text-muted-foreground transition-transform duration-200",t&&"rotate-90")}),u.jsx(d$,{status:e.status}),u.jsx("span",{className:"text-muted-foreground font-medium",children:s1(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:N_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(gF,{icon:fF(`mcp__${e.name}__${i}`),children:i},i))})]})}function T_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(d$,{status:"failed"}),u.jsxs("span",{className:"text-muted-foreground/60",children:[n.length," disconnected"]})]}):null;return u.jsx(u$,{title:"MCP Servers",count:e.length,badge:r,children:u.jsxs("div",{className:"flex flex-col gap-2",children:[t.map(i=>u.jsx(vD,{server:i},i.name)),n.map(i=>u.jsx(vD,{server:i},i.name))]})})}function R_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(As,{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 A_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=E_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(Ka,{children:u.jsxs(x2,{expandedContent:u.jsx(ky,{className:"my-4 text-xs",children:u.jsxs("div",{className:"flex flex-col gap-3",children:[u.jsx(Gbe,{children:e.model}),u.jsx(mS,{title:"Tools",items:n,getIcon:i=>cC[i]??hF}),u.jsx(mS,{title:"Agents",items:e.agents,icon:Lx}),u.jsx(mS,{title:"Commands",items:e.slashCommands,icon:Uq}),u.jsx(T_e,{servers:r}),t&&u.jsx(R_e,{rawJson:t})]})}),children:[u.jsx(iW,{className:"h-5 w-5 text-logo"}),u.jsx(lu,{children:"Session Started"})]})})}const j_e={"kanna-oauth-pool":"Pool token","claude-pro":"Claude Pro","claude-max":"Claude Max",openrouter:"OpenRouter"};function M_e(e,t){return e?j_e[e]??e:t?`API key (${t})`:null}function L_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=M_e(n,r),[d,m]=v.useState(!1);return u.jsx(Ka,{children:u.jsxs("div",{className:"flex w-full flex-col",children:[u.jsxs("button",{type:"button",onClick:()=>m(f=>!f),"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(As,{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(ky,{className:"mt-3 mb-2 text-xs",children:u.jsxs("div",{className:"flex flex-col gap-3",children:[u.jsx(uC,{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 I_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 D_e(e){if(e!==0)return"https://status.claude.com"}function P_e({message:e}){const t=e.status>0?`${e.status} ${I_e(e.status)}`:"API Error",n=D_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(ym,{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 O_e="https://www.anthropic.com/legal/aup";function z_e(e){return e.replace(/^API Error:\s*/i,"")}function B_e({message:e}){const t=z_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(kk,{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:O_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 F_e={completed:{Icon:rs,iconClass:"text-success",textClass:"text-muted-foreground"},in_progress:{Icon:bn,iconClass:"text-foreground animate-spin",textClass:"text-foreground font-medium"},pending:{Icon:NW,iconClass:"text-muted-foreground",textClass:"text-muted-foreground"}};function $_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($G,{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}=F_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 H_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=Rh(a),d=gy(c,t.mimeType),m=t.size>0?Mh(t.size):null,f=u.jsxs(u.Fragment,{children:[d,m?u.jsxs(u.Fragment,{children:[" · ",u.jsx("span",{className:"tabular-nums",children:m})]}):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(!Th(a).openInNewTab){const _=`Preview ${a.displayName}, ${d}${m?`, ${m}`:""}`;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:f,ariaLabel:_})}),u.jsx(jh,{source:s?Ap(a,"offer_download"):null,open:s,onOpenChange:o})]})}const y=["Download",a.displayName,d,m].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:f,ariaLabel:y.join(", ")})})}const pS=new Map;function U_e(e){const{cacheKey:t,enabled:n,ref:r,fetcher:i,rootMargin:s}=e,o=pS.get(t),[a,c]=v.useState(o!==void 0?"ready":"idle"),[d,m]=v.useState(o!==void 0?o:null),[f,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=pS.get(t);c(C!==void 0?"ready":"idle"),m(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||(pS.set(k,L),m(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:f}),[a,d,f])}function V_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=Rh(r),s=gy(i,e.mimeType),o=e.size&&e.size>0?Mh(e.size):null;return i==="image"?u.jsx("button",{type:"button",onClick:t,"aria-label":`Preview ${e.displayName}`,className:"overflow-hidden rounded-xl border border-border bg-background",children:u.jsx("img",{src:e.contentUrl,alt:e.altText??e.displayName,loading:"lazy",className:"max-h-64 w-auto max-w-full object-contain"})}):n==="expanded"&&(i==="text"||i==="code"||i==="markdown"||i==="json"||i==="table")?u.jsx(W_e,{source:e,onOpen:t,friendlyType:s,sizeLabel:o}):u.jsx($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 W_e=function({source:t,onOpen:n,friendlyType:r,sizeLabel:i}){const s=v.useRef(null),o=t.contentUrl,a=v.useCallback(async m=>{const f=await t2(o,4096);if(m.aborted)throw new Error("aborted");return f.content.slice(0,200)},[o]),c=U_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 G_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(V_e,{source:c,onOpen:()=>a(!0),variant:"expanded"}),n?u.jsx("figcaption",{className:"text-xs text-muted-foreground italic",children:n}):null,u.jsx(jh,{source:o?c:null,open:o,onOpenChange:a})]})}function q_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(kW,{className:"h-4 w-4 ml-1.5"}),u.jsx("em",{children:"Interrupted"})]})})}function mx({size:e=4}){return u.jsxs("svg",{className:"flex-1",viewBox:`0 0 100 ${e}`,preserveAspectRatio:"none",style:{height:`${e}px`},children:[u.jsx("pattern",{id:"zigzag",width:e,height:e,patternUnits:"userSpaceOnUse",children:u.jsx("path",{d:`M0 ${e} L${e/2} 0 L${e} ${e}`,fill:"none",stroke:"currentColor",strokeWidth:"0.5",className:"text-muted-foreground/30",style:{stroke:"currentColor"}})}),u.jsx("rect",{width:"100%",height:e,fill:"url(#zigzag)",className:"text-muted-foreground/30"})]})}function K_e(){return u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx(mx,{}),u.jsx("span",{className:"text-[11px] tracking-widest text-muted-foreground uppercase flex-shrink-0",children:"Compacted"}),u.jsx(mx,{})]})}function Y_e(){return u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsx(mx,{}),u.jsx("span",{className:"text-[11px] tracking-widest text-muted-foreground uppercase flex-shrink-0",children:"Context Cleared"}),u.jsx(mx,{})]})}function X_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(Ax,{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 Q_e({message:e}){return u.jsx(Ka,{children:u.jsxs(x2,{expandedContent:u.jsx(ky,{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(tO,{className:"h-4.5 w-4.5 text-muted-foreground"})}),u.jsx(lu,{children:"Summarized"})]})})}const Z_e={compacting:"Compacting..."};function J_e({message:e}){const t=Z_e[e.status]||e.status;return u.jsxs(Ka,{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(tO,{className:"h-4.5 w-4.5 text-muted-foreground"})}),u.jsx(lu,{className:"text-left transition-opacity duration-200 truncate",children:t})]})}const ewe={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"}},twe={key:"other",singular:"tool call",plural:"tool calls"};function nwe(e){return ewe[e]??twe}function rwe(e){const t=new Map,n=[];for(const r of e){const i=r.toolKind,s=nwe(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 iwe({messages:e,isLoading:t,localPath:n,expanded:r,onExpandedChange:i,chatId:s}){const o=v.useMemo(()=>rwe(e),[e]),c=e.some(d=>d.result===void 0)&&t;return u.jsx(Ka,{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(As,{className:`h-4.5 w-4.5 text-muted-icon transition-all duration-200 ${r?"rotate-90":""}`})}),u.jsx(lu,{className:"text-left",children:u.jsx(jp,{animate:c,children:o})})]})}),r&&u.jsxs("div",{className:"my-4 flex flex-col gap-3",children:[e.map(d=>u.jsx(fx,{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(As,{className:"h-4.5 w-4.5 text-muted-icon -rotate-90"})}),u.jsx(lu,{className:"text-left",children:"Collapse"})]})})]})]})})}function swe(e){if(e!=="system")return e}function gS(e,t){const n=swe(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 owe=/^(\d{2})\/(\d{2})\/(\d{4}) (\d{2}):(\d{2})$/;function bD(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 awe(e,t){const n=owe.exec(e.trim());if(!n)return null;const[,r,i,s,o,a]=n,c=Number(r),d=Number(i),m=Number(s),f=Number(o),g=Number(a);if(d<1||d>12||c<1||c>31||f>23||g>59)return null;const b=Date.UTC(m,d-1,c,f,g),y=bD(t,b),_=b-y*6e4,w=bD(t,_);return _-(w-y)*6e4}const lwe={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"},cwe={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),m=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]),f=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",lwe[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(Pe,{type:"button",size:"sm",variant:cwe[g.variant??"ghost"],disabled:g.disabled||f&&!b,onClick:()=>{m(g)},className:"gap-1.5",children:[b?u.jsx(bn,{className:"size-3.5 animate-spin"}):null,g.label]},g.id)})}):null]})}function uwe({schedule:e,onAccept:t,onReschedule:n,onCancel:r}){const[i,s]=v.useState(()=>gS(e.scheduledAt??e.resetAt,e.tz)),[o,a]=v.useState(!1),c=v.useMemo(()=>awe(i,e.tz),[i,e.tz]),d=c!==null&&c>Date.now(),m=c===null?"Use format dd/mm/yyyy hh:mm":d?null:"Time must be in the future";if(e.state==="fired"){const y=gS(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(dn,{value:i,onChange:w=>s(w.target.value),placeholder:"dd/mm/yyyy hh:mm"}),m&&u.jsx("div",{className:"text-destructive text-xs",children:m})]}),actions:_})}const f=gS(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 ${f} (${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 ${f} (${g})`,body:u.jsxs("div",{className:"space-y-1",children:[u.jsx(dn,{value:i,onChange:y=>s(y.target.value),placeholder:"dd/mm/yyyy hh:mm"}),m&&u.jsx("div",{className:"text-destructive text-xs",children:m})]}),actions:b})}function dwe({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(Pe,{size:"sm",variant:"outline",className:"rounded-full",onClick:()=>n(e,{kind:"deny",reason:"user_canceled"}),children:"Edit"}),u.jsx(Pe,{size:"sm",className:"rounded-full",onClick:()=>n(e,{kind:"answer",payload:{confirmed:!0}}),children:"Confirm"})]})]})}function hwe({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(Pe,{variant:"ghost",size:"sm",onClick:()=>r(e,{kind:"deny",reason:"user_canceled"}),children:"Deny"}),u.jsx(Pe,{variant:"default",size:"sm",onClick:()=>r(e,{kind:"allow"}),children:"Allow"})]})]})}function fwe({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(s$,{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(dwe,{toolRequestId:n,plan:s,onAnswer:t})}return u.jsx(hwe,{toolRequestId:n,toolName:r,args:i,onAnswer:t})}const $2="mcp__kanna__delegate_subagent";function mwe(e){const t=[];for(const n of e){if(n.kind!=="tool"||n.toolKind!=="mcp_generic"||n.toolName!==$2)continue;const r=n.input.payload.subagent_id;typeof r=="string"&&t.push({toolId:n.toolId,subagentId:r})}return t}function pwe(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,m=c[d];m&&(r.set(a.toolId,m),i.add(m.runId),s.set(a.subagentId,d+1))}const o=t.filter(a=>!i.has(a.runId));return{matched:r,orphans:o}}function gwe(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 vwe=new Set(["AskUserQuestion","ExitPlanMode","TodoWrite",$2]);function xD(e){if(e.kind!=="tool")return!1;const t=e.toolName;return!vwe.has(t)}function bwe(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 xwe(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 bwe(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 ywe(e,t){const n=[];let r=0;for(;r<e.length;){const i=e[r],s=t[r];if(s!=null&&s.shouldRender&&xD(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(!xD(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 yD(e){var n;return e.type==="single"?e.message.id:`tool-group:${((n=e.messages[0])==null?void 0:n.id)??e.startIndex}`}function vS(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>n===t[r])}function _we(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 wwe(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>_we(n,t[r]))}function sh(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)&&wwe(e.attachments,t.attachments);case"system_init":return t.kind==="system_init"&&e.provider===t.provider&&e.model===t.model&&vS(e.tools,t.tools)&&vS(e.agents,t.agents)&&vS(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 Swe(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&&sh(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)=>sh(n,t.messages[r])):!1}function Cwe(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&&Swe(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 kwe(e){const t=v.useRef({byId:new Map,result:[]}),n=v.useMemo(()=>Cwe(e,t.current),[e]);return v.useLayoutEffect(()=>{t.current=n}),n.result}const h$=(e,t)=>{},Ewe=v.memo(function({message:t,index:n,isLoading:r,localPath:i,isFirstSystem:s,isFirstAccount:o,isLatestAskUserQuestion:a,isLatestExitPlanMode:c,isLatestTodoWrite:d,hideResult:m,isFinalStatus:f,onAskUserQuestionSubmit:g,onExitPlanModeConfirm:b,onToolRequestAnswer:y=h$,schedules:_,onAutoContinueAccept:w,onAutoContinueReschedule:C,onAutoContinueCancel:E,chatId:k}){let T=null;if(t.kind==="user_prompt")T=u.jsx(C_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(uwe,{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(k_e,{json:t.json},t.id);break;case"system_init":T=s?u.jsx(A_e,{message:t,rawJson:t.debugRaw},t.id):null;break;case"account_info":T=o?u.jsx(L_e,{message:t},t.id):null;break;case"assistant_text":T=u.jsx(ZF,{message:t},t.id);break;case"assistant_thinking":T=u.jsx(JF,{message:t},t.id);break;case"api_error":T=u.jsx(P_e,{message:t},t.id);break;case"policy_refusal":T=u.jsx(B_e,{message:t},t.id);break;case"tool":if(t.isError){T=u.jsx(fx,{message:t,isLoading:r,localPath:i,chatId:k},t.id);break}if(t.toolKind==="ask_user_question"){T=u.jsx(o$,{message:t,onSubmit:g,isLatest:a},t.id);break}if(t.toolKind==="exit_plan_mode"){T=u.jsx(a$,{message:t,onConfirm:b,isLatest:c},t.id);break}if(t.toolKind==="todo_write"){T=d?u.jsx($_e,{message:t},t.id):null;break}if(t.toolKind==="offer_download"&&t.result){T=u.jsx(H_e,{message:t},t.id);break}if(t.toolKind==="image_generation"){T=u.jsx(G_e,{message:t},t.id);break}T=u.jsx(fx,{message:t,isLoading:r,localPath:i,chatId:k},t.id);break;case"result":T=m?null:u.jsx(n$,{message:t},t.id);break;case"context_window_updated":T=null;break;case"interrupted":T=u.jsx(q_e,{message:t},t.id);break;case"compact_boundary":T=u.jsx(K_e,{},t.id);break;case"context_cleared":T=u.jsx(Y_e,{},t.id);break;case"memory_loaded":T=u.jsx(X_e,{message:t},t.id);break;case"compact_summary":T=u.jsx(Q_e,{message:t},t.id);break;case"status":T=f?u.jsx(J_e,{message:t},t.id):null;break;case"pending_tool_request":T=u.jsx(fwe,{entry:t,onAnswer:y},t.id);break}return T?u.jsx("div",{id:`msg-${t.id}`,className:"group relative","data-index":n,[wm]:"",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&&sh(e.message,t.message)),Nwe=v.memo(function({id:t,messages:n,isLoading:r,localPath:i,expanded:s,onExpandedChange:o,chatId:a}){return u.jsx("div",{className:"group relative",[wm]:"",children:u.jsx(iwe,{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)=>sh(n,t.messages[r])));function f$(e,{isLoading:t,localPath:n,latestToolIds:r}){const i=xwe(e,r),s=ywe(e,i),o=[];for(const a of s){if(a.type==="tool-group"){o.push({kind:"tool-group",id:yD(a),startIndex:a.startIndex,messages:a.messages,isLoading:t&&a.messages.some(m=>m.kind==="tool"&&m.result===void 0),localPath:n});continue}const c=i[a.index];if(!c)continue;const d={kind:"single",id:yD(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 Twe={};function m$(e,t,n,r,i,s,o){const a=n.get(e.runId)??[];return u.jsxs(_n.Fragment,{children:[u.jsx(c$,{run:e,indentDepth:t,localPath:r,onSubagentAskUserQuestionSubmit:i,onSubagentExitPlanModeSubmit:s,onCancelSubagentRun:o}),a.map(c=>m$(c,t+1,n,r,i,s,o))]},e.runId)}const p$=v.memo(function({row:t,toolGroupExpanded:n,onToolGroupExpandedChange:r,onAskUserQuestionSubmit:i,onExitPlanModeConfirm:s,onToolRequestAnswer:o,schedules:a,onAutoContinueAccept:c,onAutoContinueReschedule:d,onAutoContinueCancel:m,chatId:f}){return t.kind==="tool-group"?u.jsx(Nwe,{id:t.id,startIndex:t.startIndex,messages:t.messages,isLoading:t.isLoading,localPath:t.localPath,expanded:n??!1,onExpandedChange:r,chatId:f}):u.jsx(Ewe,{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:m,chatId:f})},(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)=>sh(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&&sh(e.row.message,t.row.message):!1}),g$={},Rwe=(e,t)=>{},Awe=(e,t)=>{},jwe=e=>{};function Mwe({messages:e,isLoading:t,localPath:n,latestToolIds:r,onOpenLocalLink:i,chatId:s,onAskUserQuestionSubmit:o,onExitPlanModeConfirm:a,onToolRequestAnswer:c=h$,schedules:d=g$,onAutoContinueAccept:m=Rwe,onAutoContinueReschedule:f=Awe,onAutoContinueCancel:g=jwe,onTunnelAccept:b,onTunnelStop:y,onTunnelRetry:_,subagentRuns:w=Twe,onSubagentAskUserQuestionSubmit:C,onSubagentExitPlanModeSubmit:E,onCancelSubagentRun:k}){const[T,R]=v.useState({}),A=v.useMemo(()=>f$(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}=pwe(mwe(e),M);return gwe(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(dF,{onOpenLocalLink:i,children:A.map(M=>{const D=M.kind==="single"&&M.message.kind==="tool"&&M.message.toolName===$2?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(p$,{row:M,toolGroupExpanded:M.kind==="tool-group"?T[M.id]??!1:void 0,onToolGroupExpandedChange:H,onAskUserQuestionSubmit:o,onExitPlanModeConfirm:a,onToolRequestAnswer:c,schedules:d,onAutoContinueAccept:m,onAutoContinueReschedule:f,onAutoContinueCancel:g,chatId:s}),z?m$(z,0,L,n??"",C,E,k):null]},M.id)})})}v.memo(Mwe);const Lwe=Object.freeze([]),bS=Oi((e,t)=>({sharesByChat:{},listForChat(n){return t().sharesByChat[n]??Lwe},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)}}))}})),Iwe=/^\/(\S*)$/;function v$(e){return e.replace(/^\/+/,"")}function Dwe(e){const{command:t,value:n,caret:r}=e,i=n.slice(0,r),s=n.slice(r),o=/^\/(\S*)$/.exec(i);if(!o)return{value:n,caret:r};const a=o[0].length,c=i.slice(0,i.length-a),d=v$(t.name),m=t.argumentHint?`/${d} `:`/${d}`,f=`${c}${m}${s}`,g=c.length+m.length;return{value:f,caret:g}}function Pwe(e,t){if(t<=0)return{open:!1,query:""};const n=e.slice(0,t),r=Iwe.exec(n);return r?{open:!0,query:r[1]??""}:{open:!1,query:""}}function Owe(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 zwe=4,_D=80;function Bwe(e){return e.length<=_D?e:`${e.slice(0,_D-1).trimEnd()}…`}function Fwe({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:zwe}).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:["/",v$(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:Bwe(o.description)}):null]},o.name))})}const $we=4;function Hwe({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:$we}).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,m=(d==null?void 0:d.kind)==="dir"?Q5:Ax;return u.jsxs("li",{role:"option","aria-selected":a===t,onMouseDown:f=>{f.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(oW,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),c?u.jsxs(u.Fragment,{children:[u.jsx(vu,{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(m,{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 zv={open:!1,query:"",tokenStart:-1};function Uwe(e,t){if(t<=0)return zv;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===`
2639
2639
  `||o===" ")return zv}if(r===-1)return zv;const i=r===0?"":n[r-1];return i!==""&&i!==" "&&i!==`
2640
2640
  `&&i!==" "?zv:{open:!0,query:n.slice(r+1),tokenStart:r}}function wD(e){const t=e.value.slice(0,e.tokenStart),n=e.value.slice(e.caret),r=e.mention.kind==="agent"?`@agent/${e.mention.name}`:`@${e.mention.path}`,i=`${t}${r}${n}`,s=t.length+r.length;return{value:i,caret:s}}const Vwe=120;async function Wwe(e){const t=new URLSearchParams({query:e.query});try{const n=await fetch(`/api/projects/${e.projectId}/paths?${t.toString()}`,{signal:e.signal});return n.ok?(await n.json()).paths??[]:[]}catch{return[]}}function Gwe(e){const[t,n]=v.useState({items:[],loading:!1,error:null}),r=v.useRef(null),i=v.useRef(null);return v.useEffect(()=>{var o;if(!e.enabled||!e.projectId){n({items:[],loading:!1,error:null});return}r.current&&clearTimeout(r.current),(o=i.current)==null||o.abort(),n(a=>({...a,loading:!0,error:null}));const s=new AbortController;return i.current=s,r.current=setTimeout(async()=>{const a=await Wwe({projectId:e.projectId,query:e.query,signal:s.signal});s.signal.aborted||n({items:a,loading:!1,error:null})},Vwe),()=>{r.current&&clearTimeout(r.current),s.abort()}},[e.enabled,e.projectId,e.query]),t}const qwe=[];function Kwe(e,t){const n=t.toLowerCase();if(n&&!("agent/".startsWith(n)||n.startsWith("agent/")))return[];const r=n.startsWith("agent/")?n.slice(6):"";return e.filter(i=>i.name.toLowerCase().includes(r)).sort((i,s)=>i.name.localeCompare(s.name)).map(i=>({kind:"agent",subagent:i}))}function Ywe(e){const t=ji(n=>{var r;return((r=n.settings)==null?void 0:r.subagents)??qwe});return v.useMemo(()=>({items:e.enabled?Kwe(t,e.query):[]}),[e.enabled,e.query,t])}const SD=[];function Xwe(e,t){return t?e.byChatId[t]??SD:SD}function Qwe(e,t){return t?e.loadingByChatId[t]??!1:!1}function Zwe(e){return I2(t=>Xwe(t,e))}function Jwe(e){return I2(t=>Qwe(t,e))}const b$=v.forwardRef(({className:e,children:t,...n},r)=>u.jsx("div",{ref:r,className:de("relative overflow-y-auto overscroll-contain touch-pan-y scrollbar-hide",e),style:{WebkitOverflowScrolling:"touch"},...n,children:t}));b$.displayName="ScrollArea";function eSe(){const[e,t]=v.useState(()=>{if(typeof window>"u")return!1;const n=navigator.standalone===!0,r=window.matchMedia("(display-mode: standalone)").matches;return n||r});return v.useEffect(()=>{const n=window.matchMedia("(display-mode: standalone)"),r=i=>{t(i.matches||navigator.standalone===!0)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function tSe({className:e,...t}){return u.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",className:de("shrink-0",e),...t,children:u.jsx("path",{d:"M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z"})})}function nSe({className:e,...t}){return u.jsx("svg",{viewBox:"0 0 158.7128 157.296",fill:"currentColor","aria-hidden":"true",className:de("shrink-0",e),...t,children:u.jsx("path",{d:"M60.8734 57.2556V42.3124c0-1.2586.4722-2.2029 1.5728-2.8314l30.0443-17.3023c4.0899-2.3593 8.9662-3.4599 13.9988-3.4599 18.8759 0 30.8307 14.6289 30.8307 30.2006 0 1.1007 0 2.3593-.158 3.6178l-31.1446-18.2467c-1.8872-1.1006-3.7754-1.1006-5.6629 0L60.8734 57.2556Zm70.1542 58.2005V79.7487c0-2.2028-.9446-3.7756-2.8318-4.8763l-39.481-22.9651 12.8982-7.3934c1.1007-.6285 2.0453-.6285 3.1458 0l30.0441 17.3024c8.6523 5.0341 14.4708 15.7296 14.4708 26.1107 0 11.9539-7.0769 22.965-18.2461 27.527ZM51.593 83.9964l-12.8982-7.5497c-1.1007-.6285-1.5728-1.5728-1.5728-2.8314V39.0105c0-16.8303 12.8982-29.5722 30.3585-29.5722 6.607 0 12.7403 2.2029 17.9324 6.1349l-30.987 17.9324c-1.8871 1.1007-2.8314 2.6735-2.8314 4.8764v45.6159ZM79.3562 100.0403 60.8733 89.6592V67.6383l18.4829-10.3811 18.4812 10.3811v22.0209l-18.4812 10.3811Zm11.8757 47.8188c-6.607 0-12.7403-2.2031-17.9324-6.1344l30.9866-17.9333c1.8872-1.1005 2.8318-2.6728 2.8318-4.8759v-45.616l13.0564 7.5498c1.1005.6285 1.5723 1.5728 1.5723 2.8314v34.6051c0 16.8297-13.0564 29.5723-30.5147 29.5723ZM53.9522 112.7822 23.9079 95.4798c-8.652-5.0343-14.471-15.7296-14.471-26.1107 0-12.1119 7.2356-22.9652 18.403-27.5272v35.8634c0 2.2028.9443 3.7756 2.8314 4.8763l39.3248 22.8068-12.8982 7.3938c-1.1007.6287-2.045.6287-3.1456 0ZM52.2229 138.5791c-17.7745 0-30.8306-13.3713-30.8306-29.8871 0-1.2585.1578-2.5169.3143-3.7754l30.987 17.9323c1.8871 1.1005 3.7757 1.1005 5.6628 0l39.4811-22.807v14.9435c0 1.2585-.4721 2.2021-1.5728 2.8308l-30.0443 17.3025c-4.0898 2.359-8.9662 3.4605-13.9989 3.4605h.0014ZM91.2319 157.296c19.0327 0 34.9188-13.5272 38.5383-31.4594 17.6164-4.562 28.9425-21.0779 28.9425-37.908 0-11.0112-4.719-21.7066-13.2133-29.4143.7867-3.3035 1.2595-6.607 1.2595-9.909 0-22.4929-18.2471-39.3247-39.3251-39.3247-4.2461 0-8.3363.6285-12.4262 2.045-7.0792-6.9213-16.8318-11.3254-27.5271-11.3254-19.0331 0-34.9191 13.5268-38.5384 31.4591C11.3255 36.0212 0 52.5373 0 69.3675c0 11.0112 4.7184 21.7065 13.2125 29.4142-.7865 3.3035-1.2586 6.6067-1.2586 9.9092 0 22.4923 18.2466 39.3241 39.3248 39.3241 4.2462 0 8.3362-.6277 12.426-2.0441 7.0776 6.921 16.8302 11.3251 27.5271 11.3251Z"})})}function rSe({className:e,...t}){return u.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",className:de("shrink-0",e),...t,children:[u.jsx("circle",{cx:"12",cy:"12",r:"3"}),u.jsx("path",{d:"M6.3 6.3a8 8 0 1 0 11.4 11.4"}),u.jsx("path",{d:"M17.7 6.3a8 8 0 0 1 0 11.4"}),u.jsx("path",{d:"M2 12h4"}),u.jsx("path",{d:"M18 12h4"})]})}const CD={claude:tSe,codex:nSe,openrouter:rSe};function No({onClick:e,selected:t,icon:n,label:r,description:i,disabled:s}){return u.jsxs("button",{onClick:e,disabled:s,className:de("w-full flex items-center gap-2 p-2 border border-border/0 rounded-lg text-left transition-opacity",t?"bg-muted border-border":"hover:opacity-60",s&&"opacity-40 cursor-not-allowed"),children:[n,u.jsxs("div",{children:[u.jsx("div",{className:"text-sm font-medium",children:r}),i?u.jsx("div",{className:"text-xs text-muted-foreground",children:i}):null]})]})}function yd({trigger:e,triggerClassName:t,disabled:n=!1,children:r}){const[i,s]=v.useState(!1);return n?u.jsx("button",{disabled:!0,className:de("flex min-h-[36px] items-center gap-1.5 px-2 py-1 text-sm rounded-md text-muted-foreground [&>svg]:shrink-0 opacity-70 cursor-default [&>span]:whitespace-nowrap",t),children:e}):u.jsxs(rc,{open:i,onOpenChange:s,children:[u.jsx(ic,{asChild:!0,children:u.jsx("button",{type:"button",className:de("flex min-h-[36px] cursor-pointer touch-manipulation items-center gap-1.5 px-2 py-1 text-sm rounded-md transition-colors text-muted-foreground [&>svg]:shrink-0 [&>span]:whitespace-nowrap","hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t),children:e})}),u.jsx(Ga,{align:"center",className:"w-64 p-1",children:u.jsx("div",{className:"space-y-1",children:typeof r=="function"?r(()=>s(!1)):r})})]})}function iSe({models:e,selectedModel:t,onSelect:n,ModelIcon:r}){var m;const[i,s]=v.useState(!1),[o,a]=v.useState(""),c=((m=e.find(f=>f.id===t))==null?void 0:m.label)??t,d=v.useMemo(()=>{const f=o.trim().toLowerCase();return f?e.filter(g=>g.id.toLowerCase().includes(f)||g.label.toLowerCase().includes(f)):e},[e,o]);return u.jsxs(rc,{open:i,onOpenChange:f=>{s(f),f||a("")},children:[u.jsx(ic,{asChild:!0,children:u.jsxs("button",{type:"button",className:de("flex min-h-[36px] cursor-pointer touch-manipulation items-center gap-1.5 px-2 py-1 text-sm rounded-md transition-colors text-muted-foreground [&>svg]:shrink-0 [&>span]:whitespace-nowrap","hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"),children:[u.jsx(r,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"max-w-[200px] truncate",children:c})]})}),u.jsxs(Ga,{align:"center",className:"w-80 p-1",children:[u.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 border-b border-border/50",children:[u.jsx(Ld,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),u.jsx("input",{type:"text",value:o,onChange:f=>a(f.target.value),placeholder:"Search models...",autoFocus:!0,className:"flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground"})]}),u.jsx("div",{className:"max-h-72 overflow-y-auto py-1 space-y-1",children:e.length===0?u.jsx("div",{className:"px-2 py-3 text-xs text-muted-foreground text-center",children:"Loading models… verify OpenRouter API key in Settings."}):d.length===0?u.jsx("div",{className:"px-2 py-3 text-xs text-muted-foreground text-center",children:"No matches"}):d.map(f=>u.jsx(No,{onClick:()=>{n(f.id),s(!1),a("")},selected:t===f.id,icon:u.jsx(qS,{className:"h-4 w-4 text-muted-foreground"}),label:f.label,description:f.id},f.id))})]})]})}function bC({availableProviders:e,selectedProvider:t,showProviderPicker:n=!0,showCodexCliRequirementHints:r=!1,model:i,modelOptions:s,onProviderChange:o,onModelChange:a,onModelOptionChange:c,planMode:d=!1,onPlanModeChange:m,includePlanMode:f=!0,className:g}){var A,j,L,H,M;const b=e.find(D=>D.id===t)??e[0],y=CD[t],_=qS,w=f&&(b==null?void 0:b.supportsPlanMode)&&m,C=t==="claude"?s:null,E=t==="codex"?s:null,k=((A=b.models.find(D=>D.id===i))==null?void 0:A.contextWindowOptions)??[],T=(C==null?void 0:C.contextWindow)??Wc[0].id,R=T==="1m"?hj:fj;return u.jsxs("div",{className:de("flex md:justify-center items-center gap-0.5",g),children:[n?u.jsx(yd,{disabled:!o,trigger:u.jsxs(u.Fragment,{children:[u.jsx(y,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:(b==null?void 0:b.label)??t})]}),children:D=>e.map(z=>{const O=CD[z.id];return u.jsx(No,{onClick:()=>{o==null||o(z.id),D()},selected:t===z.id,icon:u.jsx(O,{className:"h-4 w-4 text-muted-foreground"}),label:z.label},z.id)})}):null,t==="openrouter"?u.jsx(iSe,{models:b.models,selectedModel:i,onSelect:D=>a(t,D),ModelIcon:_}):u.jsx(yd,{trigger:u.jsxs(u.Fragment,{children:[u.jsx(_,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:((j=b.models.find(D=>D.id===i))==null?void 0:j.label)??i})]}),children:D=>b.models.map(z=>{const O=qS;return u.jsx(No,{onClick:()=>{a(t,z.id),D()},selected:i===z.id,icon:u.jsx(O,{className:"h-4 w-4 text-muted-foreground"}),label:r&&t==="codex"&&z.id==="gpt-5.5"?u.jsxs(u.Fragment,{children:[z.label," ",u.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"codex-cli >= 0.124"})]}):z.label},z.id)})}),t!=="openrouter"?u.jsx(yd,{trigger:u.jsxs(u.Fragment,{children:[u.jsx(tb,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:t==="claude"?((L=jm.find(D=>D.id===s.reasoningEffort))==null?void 0:L.label)??s.reasoningEffort:((H=qb.find(D=>D.id===s.reasoningEffort))==null?void 0:H.label)??s.reasoningEffort})]}),children:D=>t==="claude"?jm.map(z=>u.jsx(No,{onClick:()=>{c({type:"claudeReasoningEffort",effort:z.id}),D()},selected:s.reasoningEffort===z.id,icon:u.jsx(tb,{className:"h-4 w-4 text-muted-foreground"}),label:z.label,disabled:z.id==="max"&&!gz(i)},z.id)):qb.map(z=>u.jsx(No,{onClick:()=>{c({type:"codexReasoningEffort",effort:z.id}),D()},selected:s.reasoningEffort===z.id,icon:u.jsx(tb,{className:"h-4 w-4 text-muted-foreground"}),label:z.label},z.id))}):null,t==="claude"&&k.length>1?u.jsx(yd,{trigger:u.jsxs(u.Fragment,{children:[u.jsx(R,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:((M=k.find(D=>D.id===T))==null?void 0:M.label)??T})]}),children:D=>k.map(z=>u.jsx(No,{onClick:()=>{c({type:"contextWindow",contextWindow:z.id}),D()},selected:T===z.id,icon:z.id==="1m"?u.jsx(hj,{className:"h-4 w-4 text-muted-foreground"}):u.jsx(fj,{className:"h-4 w-4 text-muted-foreground"}),label:z.label,description:z.id==="1m"?"Expanded context window":"Standard context window"},z.id))}):null,t==="codex"?u.jsx(yd,{trigger:u.jsxs(u.Fragment,{children:[E!=null&&E.fastMode?u.jsx(Ug,{className:"h-3.5 w-3.5"}):u.jsx(Ug,{className:"h-3.5 w-3.5 -scale-x-100"}),u.jsx("span",{children:E!=null&&E.fastMode?"Fast Mode":"Standard"})]}),triggerClassName:E!=null&&E.fastMode?"text-success":void 0,children:D=>u.jsxs(u.Fragment,{children:[u.jsx(No,{onClick:()=>{c({type:"fastMode",fastMode:!1}),D()},selected:!(E!=null&&E.fastMode),icon:u.jsx(Ug,{className:"h-4 w-4 text-muted-foreground -scale-x-100"}),label:"Standard"}),u.jsx(No,{onClick:()=>{c({type:"fastMode",fastMode:!0}),D()},selected:!!(E!=null&&E.fastMode),icon:u.jsx(Ug,{className:"h-4 w-4 text-muted-foreground"}),label:"Fast Mode"})]})}):null,w?u.jsx(yd,{trigger:u.jsxs(u.Fragment,{children:[d?u.jsx(jb,{className:"h-3.5 w-3.5"}):u.jsx(lj,{className:"h-3.5 w-3.5"}),u.jsx("span",{children:d?"Plan Mode":"Full Access"})]}),triggerClassName:d?"text-info":void 0,children:D=>u.jsxs(u.Fragment,{children:[u.jsx(No,{onClick:()=>{m(!1),D()},selected:!d,icon:u.jsx(lj,{className:"h-4 w-4 text-muted-foreground"}),label:"Full Access",description:"Execution without approval"}),u.jsx(No,{onClick:()=>{m(!0),D()},selected:d,icon:u.jsx(jb,{className:"h-4 w-4 text-muted-foreground"}),label:"Plan Mode",description:"Review a plan before execution"})]})}):null]})}function sSe(e){return e===null||!Number.isFinite(e)?null:e<10?`${e.toFixed(1).replace(/\.0$/,"")}%`:`${Math.round(e)}%`}function kD({usage:e}){const t=sSe(e.usedPercentage),n=Math.max(0,Math.min(100,e.usedPercentage??0)),r=9.75,i=2*Math.PI*r,s=i-n/100*i;return u.jsxs(rc,{children:[u.jsx(ic,{asChild:!0,children:u.jsx("button",{type:"button",className:"group inline-flex h-9 w-9 cursor-pointer touch-manipulation items-center justify-center rounded-full transition-opacity hover:opacity-85 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":e.maxTokens!==void 0&&t?`Context window ${t} used`:`Context window ${Mi(e.usedTokens)} tokens used`,children:u.jsxs("span",{className:"relative flex h-6 w-6 items-center justify-center",children:[u.jsxs("svg",{viewBox:"0 0 24 24",className:"-rotate-90 absolute inset-0 h-full w-full transform-gpu","aria-hidden":"true",children:[u.jsx("circle",{cx:"12",cy:"12",r,fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-muted-foreground/20"}),u.jsx("circle",{cx:"12",cy:"12",r,fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeDasharray:i,strokeDashoffset:s,className:"text-muted-foreground transition-[stroke-dashoffset] duration-500 ease-out"})]}),u.jsx("span",{className:de("relative flex h-[15px] w-[15px] items-center justify-center rounded-full bg-background text-[9px] font-medium","text-muted-foreground"),children:e.usedPercentage!==null?Math.round(e.usedPercentage):Mi(e.usedTokens)})]})})}),u.jsx(Ga,{side:"top",align:"center",className:"w-max max-w-none px-3 py-2",children:u.jsx("div",{className:"space-y-1.5 leading-tight",children:e.maxTokens!==void 0&&t?u.jsxs("div",{className:"whitespace-nowrap text-xs font-medium text-foreground",children:[u.jsx("span",{children:t}),u.jsx("span",{className:"mx-1",children:"·"}),u.jsx("span",{children:Mi(e.usedTokens)}),u.jsx("span",{children:"/"}),u.jsxs("span",{children:[Mi(e.maxTokens)," context used"]})]}):u.jsxs("div",{className:"text-sm text-foreground",children:[Mi(e.usedTokens)," tokens used so far"]})})})]})}function ED({usage:e,className:t}){const n=Gxe(e);if(!n)return null;const r=n.cacheHitPercentage===null?null:oSe(n.cacheHitPercentage);return u.jsxs(rc,{children:[u.jsx(ic,{asChild:!0,children:u.jsxs("button",{type:"button","aria-label":aSe(n,r),className:de("inline-flex min-h-[36px] cursor-pointer touch-manipulation items-center gap-1.5 rounded-md bg-muted/30 px-2.5 py-1.5 text-xs tabular-nums text-muted-foreground transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t),children:[u.jsx(xS,{label:"in",value:Mi(n.input)}),u.jsx(ND,{}),u.jsx(xS,{label:"out",value:Mi(n.output)}),r!==null?u.jsxs(u.Fragment,{children:[u.jsx(ND,{}),u.jsx(xS,{label:"cache",value:r})]}):null]})}),u.jsx(Ga,{side:"top",align:"center",className:"w-max max-w-none px-3 py-2",children:u.jsxs("div",{className:"space-y-1 text-xs leading-tight",children:[u.jsx(Bv,{label:"Input",value:Mi(n.input)}),u.jsx(Bv,{label:"Output",value:Mi(n.output)}),u.jsx(Bv,{label:"Cache read",value:Mi(n.cached)}),r!==null?u.jsx(Bv,{label:"Cache hit",value:r}):null]})})]})}function xS({label:e,value:t}){return u.jsxs("span",{className:"inline-flex items-baseline gap-1 tabular-nums",children:[u.jsx("span",{className:"font-medium text-foreground",children:t}),u.jsx("span",{children:e})]})}function ND(){return u.jsx("span",{"aria-hidden":"true",className:"text-muted-foreground/50",children:"·"})}function Bv({label:e,value:t}){return u.jsxs("div",{className:"flex items-baseline justify-between gap-6 whitespace-nowrap",children:[u.jsx("span",{className:"text-muted-foreground",children:e}),u.jsx("span",{className:"font-medium tabular-nums text-foreground",children:t})]})}function oSe(e){const t=Math.max(0,Math.min(100,e));return t<10?`${t.toFixed(1).replace(/\.0$/,"")}%`:`${Math.round(t)}%`}function aSe(e,t){const n=[`Input ${Mi(e.input)}`,`Output ${Mi(e.output)}`,`Cache ${Mi(e.cached)}`];return t!==null&&n.push(`hit ${t}`),`Session tokens: ${n.join(", ")}`}class x$ extends Error{constructor(){super("Upload aborted"),this.name="UploadAbortedError"}}const lSe=80;function cSe(e){const t=e.XHR??XMLHttpRequest,n=new t;let r=!1,i=0,s=-1;return{promise:new Promise((a,c)=>{function d(f,g,b=!1){const y=g>0?g:e.file.size,_=y>0?Math.floor(f/y*100):0,w=Date.now(),C=w-i>=lSe;!b&&!C&&!(_!==s)||(i=w,s=_,e.onProgress({loaded:f,total:y}))}n.upload.addEventListener("progress",f=>{d(f.loaded,f.lengthComputable?f.total:e.file.size)}),n.upload.addEventListener("load",()=>{d(e.file.size,e.file.size,!0)}),n.addEventListener("load",()=>{if(r)return;let f;try{f=n.responseText?JSON.parse(n.responseText):null}catch{f=null}if(n.status>=200&&n.status<300){const b=f==null?void 0:f.attachments;if(!Array.isArray(b)){c(new Error("Upload failed: malformed response"));return}a({attachments:b});return}const g=f==null?void 0:f.error;c(new Error(typeof g=="string"?g:"Upload failed"))}),n.addEventListener("error",()=>{r||c(new Error("Upload failed"))}),n.addEventListener("abort",()=>{c(new x$)});const m=new FormData;m.append("files",e.file),n.open("POST",`/api/projects/${encodeURIComponent(e.projectId)}/uploads`),n.send(m)}),abort:()=>{if(!r){r=!0;try{n.abort()}catch{}}}}}const uSe="(^|[\\s\\n\\t])@agent/([a-z0-9_-]+)";function dSe(){return new RegExp(uSe,"gi")}const hSe=[],y$=50,fSe=3,mSe={"image/gif":"gif","image/jpeg":"jpg","image/png":"png","image/webp":"webp"};function pSe(){if(typeof window>"u")return!1;if("ontouchstart"in window)return!0;const e=typeof navigator<"u"?navigator:null;return((e==null?void 0:e.maxTouchPoints)??0)>0}function gSe(e){return!e}function vSe(e){const t=e.maxAttachments??y$;return e.currentAttachmentCount+e.queuedAttachmentCount+e.incomingAttachmentCount>t}function bSe(e){return e?e.types.includes("text/plain")||e.types.includes("text/html"):!1}function _$(e){return mSe[e.type]??"bin"}function xSe(e){const t=e.name.trim().toLowerCase();if(!t)return!0;const n=_$(e);return t===`image.${n}`||t==="image.png"}function ySe(e,t,n){if(e.name&&!xSe(e))return e;const r=_$(e),i=t===0?"":`-${t}`,s=`clipboard-${n}${i}.${r}`;return Object.defineProperty(e,"name",{configurable:!0,value:s}),e}function _Se(e,t){const n=[];for(const r of e){if(r.kind!=="file"||!r.type.startsWith("image/"))continue;const i=r.getAsFile();i&&n.push(ySe(i,n.length,t))}return n}function wSe(e){return e.replace(/(?:\r\n|\r|\n)+$/,"")}function SSe(e){return`${e.value.slice(0,e.selectionStart)}${e.insertedText}${e.value.slice(e.selectionEnd)}`}function CSe(e,t){return e.provider!=="claude"?{...e,model:t}:{...e,model:t,modelOptions:{...e.modelOptions,contextWindow:wE(t,e.modelOptions.contextWindow)}}}function kSe(e,t,n){return!t||e.provider===t?e:t==="claude"?{provider:"claude",model:n.claude.model,modelOptions:{...n.claude.modelOptions},planMode:e.planMode}:{provider:"codex",model:n.codex.model,modelOptions:{...n.codex.modelOptions},planMode:e.planMode}}const ESe=v.forwardRef(function({onSubmit:t,onLayoutChange:n,onCancel:r,disabled:i,canCancel:s,chatId:o,projectId:a,inputElementRef:c,activeProvider:d,availableProviders:m,contextWindowSnapshot:f=null,previousPrompt:g=null},b){var Er;const{getDraft:y,setDraft:_,clearDraft:w,getAttachmentDrafts:C,setAttachmentDrafts:E,clearAttachmentDrafts:k}=pC(),{providerDefaults:T,getComposerState:R,initializeComposerForChat:A,setChatComposerModel:j,setChatComposerPlanMode:L,resetChatComposerFromProvider:H}=mi(),M=o??fm,z=mi(K=>K.chatStates[M])??R(M),[O,F]=v.useState(()=>o?y(o):""),$=v.useRef(null),B=eSe(),[U,G]=v.useState(()=>TD(o?C(o):[])),[te,P]=v.useState(null),[Y,ee]=v.useState(null),V=v.useRef([]),ue=v.useRef(0),ge=v.useRef([]),J=v.useRef(0),ne=v.useRef(new Set),ie=v.useRef(a??null),le=v.useRef(o??null),oe=kSe(z,d,T),Ce=z.provider,ke=Zwe(o??null),ze=Jwe(o??null),Ze=v.useRef(null),[lt,Mt]=v.useState(0),[ye,ln]=v.useState(!1),[jt,_t]=v.useState(0),ft=v.useMemo(()=>pSe(),[]),Ot=v.useCallback(()=>{gSe(ft)&&_t(K=>K+1)},[ft]);v.useEffect(()=>{O.startsWith("/")||ln(!1)},[O]);const It=((Er=$.current)==null?void 0:Er.selectionStart)??O.length,it=v.useMemo(()=>Pwe(O,It),[O,It,jt]),Dt=v.useMemo(()=>it.open?Owe(ke,it.query):[],[it.open,it.query,ke]),fe=it.open&&(ke.length>0||ze)&&!ye&&Ce==="claude";v.useEffect(()=>{fe&&Mt(0)},[fe,it.query]);const[Ae,He]=v.useState(0),[Je,qe]=v.useState(!1),bt=v.useMemo(()=>Uwe(O,It),[O,It,jt]),wt=Gwe({projectId:a??null,query:bt.query,enabled:bt.open&&!Je}),Tt=Ywe({query:bt.query,enabled:bt.open&&!Je}),Ne=v.useMemo(()=>[...Tt.items,...wt.items.map(K=>({kind:"path",path:K}))],[wt.items,Tt.items]),De=ji(K=>{var xe;return((xe=K.settings)==null?void 0:xe.subagents)??hSe}),Be=v.useMemo(()=>{const K=new Map(De.map(Re=>[Re.name.toLowerCase(),Re]));return[...O.matchAll(dSe())].map(Re=>{const Qe=Re[2],ut=K.get(Qe.toLowerCase());return ut?{kind:"ok",label:ut.name,id:ut.id}:{kind:"missing",label:Qe}})},[O,De]),Ye=bt.open&&!Je&&!fe&&(Ne.length>0||wt.loading);v.useEffect(()=>{Ye&&He(0)},[Ye,bt.query]),v.useEffect(()=>{bt.open||qe(!1)},[bt.open,bt.tokenStart]);function ct(K){const{value:xe,caret:Re}=Dwe({value:O,caret:It,command:K});F(xe),o&&_(o,xe),ln(!0),requestAnimationFrame(()=>{const Qe=$.current;Qe&&(Qe.focus(),Qe.setSelectionRange(Re,Re))})}function nn(K){if(K.kind==="agent"){const{value:dt,caret:cn}=wD({value:O,caret:It,tokenStart:bt.tokenStart,mention:{kind:"agent",name:K.subagent.name}});F(dt),o&&_(o,dt),qe(!0),requestAnimationFrame(()=>{const yn=$.current;yn&&(yn.focus(),yn.setSelectionRange(cn,cn))});return}if(!a){qe(!0);return}const xe=K.path,{value:Re,caret:Qe}=wD({value:O,caret:It,tokenStart:bt.tokenStart,mention:{kind:"path",path:xe.path}});F(Re),o&&_(o,Re);const ut=xe.path.endsWith("/")?xe.path.slice(0,-1):xe.path;if(!U.some(dt=>dt.kind==="mention"&&dt.relativePath===`./${ut}`)){const dt=xe.kind==="file"?`/api/projects/${a}/files/${encodeURIComponent(ut)}/content`:"";G(cn=>[...cn,{id:crypto.randomUUID(),kind:"mention",displayName:ut,absolutePath:"",relativePath:`./${ut}`,contentUrl:dt,mimeType:"",size:0,status:"uploaded"}])}qe(!0),requestAnimationFrame(()=>{const dt=$.current;dt&&(dt.focus(),dt.setSelectionRange(Qe,Qe))})}const Qt=m.find(K=>K.id===Ce)??m[0],Ut=(Qt==null?void 0:Qt.supportsPlanMode)??!1,Rt=v.useMemo(()=>{if(oe.provider!=="claude")return f;const K=oe.modelOptions,xe=ore(wE(oe.model,K.contextWindow));return Wxe(f,xe)},[f,oe.model,oe.modelOptions,oe.provider]),xt=U.filter(K=>K.status==="uploaded"),mt=U.some(K=>K.status==="uploading"),Ct=O.trim().length>0,pt=O.trim().length>0||xt.length>0,$t=[...U].sort((K,xe)=>K.kind===xe.kind?0:K.kind==="image"?-1:1),nt=U.find(K=>K.id===te)??null,we=v.useCallback(K=>{K.previewUrl&&URL.revokeObjectURL(K.previewUrl)},[]),tt=v.useCallback(K=>{const xe=(K==null?void 0:K.cleanupPreviews)??!0;J.current+=1,ne.current.clear(),G(Re=>(xe&&Re.forEach(we),[])),V.current=[],ue.current=0,P(null),ee(null)},[we]),Ge=v.useCallback(()=>{const K=$.current;if(K){if(K.value.length===0){K.style.height="";return}K.style.height="auto",K.style.height=`${K.scrollHeight}px`}},[]),Xe=v.useCallback(K=>{$.current=K,c&&(typeof c=="function"?c(K):c.current=K)},[c]);v.useLayoutEffect(()=>{Ge(),n==null||n()},[Ge,n,O]),v.useEffect(()=>{const K=()=>{Ge(),n==null||n()};return window.addEventListener("resize",K),()=>window.removeEventListener("resize",K)},[Ge,n]),v.useLayoutEffect(()=>{n==null||n()},[U.length,n,Y]),v.useEffect(()=>{var K;(K=$.current)==null||K.focus()},[o]),v.useEffect(()=>{le.current=o??null},[o]),v.useEffect(()=>{A(M,{providerHint:d})},[M,A,d]),v.useEffect(()=>{J.current+=1,V.current=[],ue.current=0,ne.current.clear(),P(null),ee(null),G(K=>(K.forEach(we),TD(o?C(o):[])))},[o,we,C]),v.useEffect(()=>{const K=ie.current;ie.current=a??null,!(K===null||a===K)&&(tt(),o&&k(o))},[a,o,tt,k]),v.useEffect(()=>{ge.current=U},[U]),v.useEffect(()=>{if(!o)return;const K=U.filter(xe=>xe.status==="uploaded").map(({previewUrl:xe,status:Re,uploadProgress:Qe,cancelUpload:ut,...Ke})=>Ke);if(K.length===0){k(o);return}E(o,K)},[U,o,k,E]),v.useEffect(()=>()=>{ge.current.forEach(we)},[we]);function _e(K){mi.getState().setComposerState(M,K(oe))}function Oe(K){_e(xe=>({...xe,modelOptions:{...xe.modelOptions,reasoningEffort:K}}))}function Ue(K){_e(xe=>xe.provider!=="claude"?xe:CSe({...xe,modelOptions:{...xe.modelOptions,contextWindow:K}},xe.model))}function Ve(K){L(M,K)}function Vt(){Ve(!oe.planMode)}const Fe=v.useCallback(()=>{if(a)for(;ue.current<fSe&&V.current.length>0;){const K=V.current.shift();if(!K)break;ue.current+=1;const xe=crypto.randomUUID(),Re=K.type.startsWith("image/")?URL.createObjectURL(K):void 0,Qe=J.current,ut=cSe({projectId:a,file:K,onProgress:({loaded:Ke,total:dt})=>{if(Qe!==J.current)return;const cn=dt>0?Ke/dt:0;G(yn=>yn.map(or=>or.id===xe?{...or,uploadProgress:cn}:or))}});G(Ke=>[...Ke,{id:xe,kind:K.type.startsWith("image/")?"image":"file",displayName:K.name,absolutePath:"",relativePath:"",contentUrl:"",mimeType:K.type||"application/octet-stream",size:K.size,status:"uploading",previewUrl:Re,uploadProgress:0,cancelUpload:ut.abort}]),(async()=>{try{const{attachments:Ke}=await ut.promise,dt=Ke[0];if(!dt)throw new Error("Upload failed");if(Qe!==J.current){yS(dt),Re&&URL.revokeObjectURL(Re);return}if(ne.current.has(xe)){ne.current.delete(xe),Re&&URL.revokeObjectURL(Re),yS(dt);return}G(cn=>cn.map(yn=>yn.id!==xe?yn:{...yn,...dt,previewUrl:yn.previewUrl,status:"uploaded",uploadProgress:1,cancelUpload:void 0})),ee(null)}catch(Ke){if(Qe!==J.current){Re&&URL.revokeObjectURL(Re);return}if(Ke instanceof x$){G(dt=>dt.filter(cn=>cn.id!==xe)),ne.current.delete(xe),Re&&URL.revokeObjectURL(Re);return}G(dt=>dt.map(cn=>cn.id===xe?{...cn,status:"failed",cancelUpload:void 0}:cn)),ee(Ke instanceof Error?Ke.message:String(Ke))}finally{ue.current=Math.max(0,ue.current-1),Fe()}})()}},[a]),Ht=v.useCallback(K=>{if(!a){ee("Open a project before uploading files.");return}if(vSe({currentAttachmentCount:ge.current.length,queuedAttachmentCount:V.current.length,incomingAttachmentCount:K.length})){ee(`You can upload up to ${y$} files at a time.`);return}V.current.push(...K),ee(null),Fe()},[Fe,a]);v.useImperativeHandle(b,()=>({enqueueFiles:Ht}),[Ht]);async function Wt(){if(!pt||mt)return;const K=O,xe=ge.current,Re=te,Qe=Y,ut=xt.map(({previewUrl:cn,status:yn,uploadProgress:or,cancelUpload:si,...os})=>os);let Ke;oe.provider==="claude"?Ke={claude:{...oe.modelOptions}}:Ke={codex:{...oe.modelOptions}};const dt={provider:Ce,model:oe.model,modelOptions:Ke,planMode:Ut?oe.planMode:!1,attachments:ut};F(""),o&&w(o),$.current&&($.current.style.height="auto"),tt({cleanupPreviews:!1}),le.current&&k(le.current);try{await t(K,dt),xe.forEach(we)}catch(cn){console.error("[ChatInput] Submit failed:",cn),F(K),o&&_(o,K),G(xe),P(Re),ee(Qe)}}function wn(K){if(K.nativeEvent.isComposing||K.keyCode===229)return;if(Ye){if(K.key==="Escape"){K.preventDefault(),qe(!0);return}if(K.key==="ArrowDown"){K.preventDefault(),He(Re=>Math.min(Ne.length-1,Re+1));return}if(K.key==="ArrowUp"){K.preventDefault(),He(Re=>Math.max(0,Re-1));return}if(K.key==="Enter"||K.key==="Tab"){K.preventDefault();const Re=Ne[Ae];Re&&nn(Re);return}}if(fe){if(K.key==="Escape"){K.preventDefault(),ln(!0);return}if(K.key==="ArrowDown"){K.preventDefault(),Mt(Re=>Math.min(Dt.length-1,Re+1));return}if(K.key==="ArrowUp"){K.preventDefault(),Mt(Re=>Math.max(0,Re-1));return}if(K.key==="Enter"||K.key==="Tab"){K.preventDefault();const Re=Dt[lt];Re&&ct(Re);return}}if(K.key==="Tab"&&!K.shiftKey){K.preventDefault(),FX($.current,document);return}if(K.key==="Tab"&&K.shiftKey&&Ut){K.preventDefault(),Vt();return}if(K.key==="Escape"&&s){K.preventDefault(),r==null||r();return}if(K.key==="ArrowUp"&&!K.shiftKey&&!K.altKey&&!K.ctrlKey&&!K.metaKey&&O.length===0&&g){K.preventDefault(),F(g),o&&_(o,g);return}const xe="ontouchstart"in window||navigator.maxTouchPoints>0;K.key==="Enter"&&!K.shiftKey&&!xe&&!i&&Ct&&!mt&&(K.preventDefault(),Wt())}function pr(K){const xe=_Se(K.clipboardData.items,Date.now()),Re=K.clipboardData.getData("text/plain"),Qe=wSe(Re),ut=Re.length>0&&Qe!==Re;if(!(xe.length===0&&!ut)){if(xe.length>0&&Ht(xe),ut){K.preventDefault();const Ke=K.currentTarget,dt=SSe({value:O,insertedText:Qe,selectionStart:Ke.selectionStart,selectionEnd:Ke.selectionEnd}),cn=Ke.selectionStart+Qe.length;F(dt),o&&_(o,dt),Ge(),requestAnimationFrame(()=>{Ke.selectionStart=cn,Ke.selectionEnd=cn});return}bSe(K.clipboardData)||K.preventDefault()}}function Sn(K){if(Th(K).openInNewTab){typeof window<"u"&&window.open(new URL(K.contentUrl,window.location.origin).toString(),"_blank","noopener,noreferrer");return}P(K.id)}function Fn(K){var xe;K.status==="uploading"&&((xe=K.cancelUpload)==null||xe.call(K)),ne.current.add(K.id),G(Re=>{const Qe=Re.find(ut=>ut.id===K.id);return Qe&&we(Qe),Re.filter(ut=>ut.id!==K.id)}),te===K.id&&P(null),K.status==="uploaded"&&(ne.current.delete(K.id),yS(K))}return u.jsxs("div",{children:[u.jsxs("div",{className:de("px-3 pt-0",B&&"px-5"),children:[u.jsxs("div",{className:"max-w-[840px] mx-auto rounded-[32px]",children:[Be.length>0?u.jsx("div",{className:"flex flex-wrap gap-1 px-2 pt-2",children:Be.map((K,xe)=>u.jsxs("span",{className:de("inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs",K.kind==="ok"?"bg-accent text-accent-foreground":"bg-destructive/15 text-destructive"),children:[u.jsx(vu,{className:"h-3 w-3"}),"agent/",K.label,K.kind==="missing"&&u.jsx("span",{className:"ml-1 font-medium",children:"unknown"})]},`${K.kind}:${K.label}:${xe}`))}):null,U.length>0?u.jsx(b$,{className:"overflow-x-auto overflow-y-hidden whitespace-nowrap px-2 pb-2",children:u.jsx("div",{className:"flex items-end gap-2 pt-2",children:$t.map(K=>u.jsx("div",{className:de("flex shrink-0 flex-col justify-end",K.status==="failed"&&"text-destructive"),children:K.kind==="image"?u.jsx(_2,{attachment:K,previewUrl:K.previewUrl,size:"composer",onClick:K.status==="uploaded"?()=>Sn(K):void 0,onRemove:()=>Fn(K),uploadProgress:K.status==="uploading"?K.uploadProgress??null:void 0,onCancelUpload:K.status==="uploading"?()=>Fn(K):void 0}):u.jsx($o,{attachment:K,onClick:K.status==="uploaded"&&K.contentUrl?()=>Sn(K):void 0,onRemove:()=>Fn(K),uploadProgress:K.status==="uploading"?K.uploadProgress??null:void 0,onCancelUpload:K.status==="uploading"?()=>Fn(K):void 0})},K.id))})}):null,u.jsxs("div",{className:"relative flex items-end max-w-[840px] mx-auto border bg-background dark:bg-card/90 border-border rounded-[29px] pr-1.5 transition-colors focus-within:border-ring/60 focus-within:ring-2 focus-within:ring-ring/30",children:[fe&&u.jsx(Fwe,{items:Dt,activeIndex:lt,loading:ze,onSelect:ct,onHoverIndex:Mt}),Ye&&u.jsx(Hwe,{items:Ne,activeIndex:Ae,loading:wt.loading,onSelect:nn,onHoverIndex:He}),u.jsx(Pe,{type:"button",variant:"ghost",size:"icon","aria-label":"Add attachment",disabled:i,onPointerDown:K=>K.preventDefault(),onClick:()=>{var K;return(K=Ze.current)==null?void 0:K.click()},className:"relative flex-shrink-0 ml-1 mb-1 h-11 w-11 rounded-full text-muted-foreground hover:text-foreground",children:u.jsx(cq,{className:"h-5 w-5"})}),u.jsx("input",{ref:Ze,type:"file",multiple:!0,disabled:i,tabIndex:-1,"aria-hidden":"true",className:"sr-only",onChange:K=>{const xe=[...K.target.files??[]];xe.length>0&&Ht(xe),K.target.value=""}}),u.jsx(La,{ref:Xe,placeholder:"Build something...",value:O,autoFocus:!0,[Pk]:"",rows:1,onChange:K=>{F(K.target.value),o&&_(o,K.target.value),Ge(),_t(xe=>xe+1)},onSelect:Ot,onKeyUp:()=>_t(K=>K+1),onPaste:pr,onKeyDown:wn,disabled:i,className:"flex-1 text-base p-3 md:p-4 !pr-2 pl-0 md:pl-6 resize-none max-h-[200px] outline-none focus:outline-none focus-visible:outline-none focus-visible:ring-0 bg-transparent border-0 shadow-none"}),u.jsx(Pe,{type:"button",onPointerDown:K=>{K.preventDefault(),!i&&Ct&&!mt?Wt():s?r==null||r():!i&&pt&&!mt&&Wt()},disabled:i||!s&&!pt||mt,size:"icon","aria-label":s?"Stop":"Send message",className:"flex-shrink-0 bg-primary text-background rounded-full cursor-pointer h-11 w-11 mb-1 -mr-0.5 md:mr-0 md:mb-1.5 touch-manipulation disabled:opacity-50",children:Ct?u.jsx(Gd,{className:"h-5 w-5 md:h-6 md:w-6"}):s?u.jsx("div",{className:"w-3 h-3 md:w-4 md:h-4 rounded-xs bg-current"}):u.jsx(Gd,{className:"h-5 w-5 md:h-6 md:w-6"})})]})]}),Y?u.jsx("div",{className:"max-w-[840px] mx-auto mt-2 px-1 text-sm text-destructive",children:Y}):null]}),u.jsxs("div",{className:de("relative py-3 max-w-[840px] mx-auto",B&&"p-5 pt-3"),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("div",{className:"min-w-0 flex-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden flex flex-row",children:[u.jsx("div",{className:"min-w-3"}),u.jsx(bC,{availableProviders:m,selectedProvider:Ce,showCodexCliRequirementHints:!0,model:oe.model,modelOptions:oe.modelOptions,onProviderChange:K=>{H(M,K)},onModelChange:(K,xe)=>{j(M,xe)},onModelOptionChange:K=>{switch(K.type){case"claudeReasoningEffort":Oe(K.effort);break;case"codexReasoningEffort":Oe(K.effort);break;case"contextWindow":Ue(K.contextWindow);break;case"fastMode":_e(xe=>xe.provider==="claude"||xe.provider==="openrouter"?xe:{...xe,modelOptions:{...xe.modelOptions,fastMode:K.fastMode}});break}},planMode:oe.planMode,onPlanModeChange:Ve,includePlanMode:Ut,className:"max-w-[840px] mx-auto"}),u.jsx("div",{className:"min-w-3"})]}),Rt?u.jsxs("div",{className:"hidden shrink-0 items-center gap-2 pr-3 md:flex",children:[u.jsx(ED,{usage:Rt}),u.jsx(kD,{usage:Rt})]}):null]}),Rt?u.jsxs("div",{className:"flex md:hidden items-center justify-end gap-2 px-[13px] pt-2",children:[u.jsx(ED,{usage:Rt}),u.jsx(kD,{usage:Rt})]}):null]}),u.jsx(jh,{source:nt?Ap(nt,"user_attachment"):null,open:nt!==null,onOpenChange:K=>!K&&P(null)})]})}),NSe=v.memo(ESe);async function yS(e){if(!e.contentUrl)return;const t=e.contentUrl.replace(/\/content$/,"");await fetch(t,{method:"DELETE"}).catch(()=>{})}function TD(e){return e.map(t=>({...t,status:"uploaded"}))}const TSe=v.memo(function({inputRef:t,onLayoutChange:n,chatInputRef:r,chatInputElementRef:i,activeChatId:s,previousPrompt:o,hasSelectedProject:a,canCancel:c,projectId:d,activeProvider:m,availableProviders:f,contextWindowSnapshot:g,onSubmit:b,onCancel:y}){return u.jsx("div",{className:"absolute bottom-0 left-0 right-0 z-20 pointer-events-none",children:u.jsx("div",{className:"bg-gradient-to-t from-background via-background pointer-events-auto",ref:t,children:u.jsx(NSe,{ref:r,inputElementRef:i,onLayoutChange:n,onSubmit:b,onCancel:y,disabled:!a,canCancel:c,chatId:s,projectId:d,activeProvider:m,availableProviders:f,contextWindowSnapshot:g,previousPrompt:o},s??"new-chat")})})});var _S={exports:{}},wS={};/**
2641
2641
  * @license React