@vibedeckx/ui-dist 0.2.1 → 0.2.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.
- package/package.json +1 -1
- package/ui/404/index.html +2 -2
- package/ui/404.html +2 -2
- package/ui/__next.__PAGE__.txt +2 -2
- package/ui/__next._full.txt +3 -3
- package/ui/__next._head.txt +1 -1
- package/ui/__next._index.txt +2 -2
- package/ui/__next._tree.txt +2 -2
- package/ui/_next/static/chunks/{32563e2c41112e61.js → 6a08beb1331f8c79.js} +1 -1
- package/ui/_next/static/chunks/7c84b9d034308087.css +1 -0
- package/ui/_not-found/__next._full.txt +2 -2
- package/ui/_not-found/__next._head.txt +1 -1
- package/ui/_not-found/__next._index.txt +2 -2
- package/ui/_not-found/__next._not-found.__PAGE__.txt +1 -1
- package/ui/_not-found/__next._not-found.txt +1 -1
- package/ui/_not-found/__next._tree.txt +2 -2
- package/ui/_not-found/index.html +2 -2
- package/ui/_not-found/index.txt +2 -2
- package/ui/index.html +2 -2
- package/ui/index.txt +3 -3
- package/ui/_next/static/chunks/4abaaa378b7c9c65.css +0 -1
- /package/ui/_next/static/{D1VkAoZPc5KldxKNih7Me → wW8waPZaE3I7k8q_3nHc3}/_buildManifest.js +0 -0
- /package/ui/_next/static/{D1VkAoZPc5KldxKNih7Me → wW8waPZaE3I7k8q_3nHc3}/_clientMiddlewareManifest.json +0 -0
- /package/ui/_next/static/{D1VkAoZPc5KldxKNih7Me → wW8waPZaE3I7k8q_3nHc3}/_ssgManifest.js +0 -0
|
@@ -25,7 +25,7 @@ You can add a description to the \`${bc}\` by passing a \`${bg}\` component as a
|
|
|
25
25
|
|
|
26
26
|
Alternatively, you can use your own component as a description by assigning it an \`id\` and passing the same value to the \`aria-describedby\` prop in \`${bc}\`. If the description is confusing or duplicative for sighted users, you can use the \`@radix-ui/react-visually-hidden\` primitive as a wrapper around your description component.
|
|
27
27
|
|
|
28
|
-
For more information, see https://radix-ui.com/primitives/docs/components/alert-dialog`;return $.useEffect(()=>{document.getElementById(e.current?.getAttribute("aria-describedby"))||console.warn(r)},[r,e]),null};function bw({...e}){return(0,z.jsx)(bo,{"data-slot":"alert-dialog",...e})}function bS({...e}){return(0,z.jsx)(ba,{"data-slot":"alert-dialog-portal",...e})}function bC({className:e,...r}){return(0,z.jsx)(bl,{"data-slot":"alert-dialog-overlay",className:(0,ey.cn)("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...r})}function bj({className:e,...r}){return(0,z.jsxs)(bS,{children:[(0,z.jsx)(bC,{}),(0,z.jsx)(bf,{"data-slot":"alert-dialog-content",className:(0,ey.cn)("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",e),...r})]})}function bk({className:e,...r}){return(0,z.jsx)("div",{"data-slot":"alert-dialog-header",className:(0,ey.cn)("flex flex-col gap-2 text-center sm:text-left",e),...r})}function bN({className:e,...r}){return(0,z.jsx)("div",{"data-slot":"alert-dialog-footer",className:(0,ey.cn)("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",e),...r})}function bD({className:e,...r}){return(0,z.jsx)(bm,{"data-slot":"alert-dialog-title",className:(0,ey.cn)("text-lg font-semibold",e),...r})}function bE({className:e,...r}){return(0,z.jsx)(bx,{"data-slot":"alert-dialog-description",className:(0,ey.cn)("text-muted-foreground text-sm",e),...r})}function bR({className:e,...r}){return(0,z.jsx)(bv,{className:(0,ey.cn)((0,W.buttonVariants)(),e),...r})}function bA({className:e,...r}){return(0,z.jsx)(by,{className:(0,ey.cn)((0,W.buttonVariants)({variant:"outline"}),e),...r})}let bM=new Set(["ts","tsx","js","jsx","py","rb","go","rs","java","c","cpp","h","css","scss","html","vue","svelte","php","swift","kt","sh","bash","yaml","yml","toml","json","xml","sql","graphql","proto"]),bF=new Set(["md","txt","log","csv","env","gitignore","dockerignore","editorconfig"]);function bT(e){return Array.from(e.dataTransfer.types).includes("Files")}function bP(e){let r=e.dataTransfer.items;if(r&&r.length>0&&"function"==typeof r[0].webkitGetAsEntry){let e=[];for(let s of Array.from(r)){if("file"!==s.kind)continue;let r=s.webkitGetAsEntry();if(r?.isDirectory)continue;let i=s.getAsFile();i&&e.push(i)}return e}return Array.from(e.dataTransfer.files)}function bB({path:e}){let[r,s]=(0,$.useState)(!1),i=(0,$.useCallback)(r=>{r.stopPropagation(),navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),1500)},[e]);return(0,z.jsx)("button",{onClick:i,className:"p-0.5 rounded hover:bg-muted-foreground/20 transition-colors",title:`Copy path: ${e}`,children:r?(0,z.jsx)(rh.Check,{className:"h-3 w-3 text-green-500"}):(0,z.jsx)(dL.Copy,{className:"h-3 w-3 text-muted-foreground"})})}function bL({entryPath:e,type:r,deleting:s,onRequestDelete:i}){return s?(0,z.jsx)(rj,{className:"h-3 w-3 animate-spin text-muted-foreground"}):(0,z.jsx)("button",{onClick:s=>{s.stopPropagation(),i(e,r)},className:"p-0.5 rounded hover:bg-destructive/20 transition-colors",title:`Delete ${e}`,"aria-label":`Delete ${e}`,children:(0,z.jsx)(rl,{className:"h-3 w-3 text-muted-foreground hover:text-destructive"})})}function bI({entry:e,path:r,depth:s,expandedDirs:i,directoryContents:n,loadingDirs:o,selectedFile:a,uploadingDirs:l,dragOverPath:c,deletingPaths:d,onToggleDirectory:u,onSelectFile:h,onUploadFiles:f,onSetDragOverPath:p,onRequestDelete:m}){var g,x,v;let _,y,b,w,S,C=i.has(r),j=o.has(r),k=n.get(r),N=e.name.startsWith(".");if("directory"===e.type){let g=C?rv:as,x=c===r,v=l.has(r),_=d.has(r);return(0,z.jsxs)("div",{children:[(0,z.jsxs)("div",{className:(0,ey.cn)("group flex items-center w-full px-2 py-2 rounded-sm transition-colors cursor-pointer",x?"bg-primary/15 outline-2 -outline-offset-2 outline-dashed outline-primary/60":"hover:bg-accent"),style:{paddingLeft:`${16*s+8}px`},onClick:()=>u(r),onDragOver:e=>{bT(e)&&(e.preventDefault(),e.stopPropagation(),p(r))},onDrop:e=>{if(!bT(e))return;e.preventDefault(),e.stopPropagation(),p(null);let s=bP(e);s.length&&f(r,s)},children:[(0,z.jsxs)("div",{className:"flex items-center gap-1 min-w-0 flex-1",children:[v||j?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground"}):(0,z.jsx)(C?sb:oh,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,z.jsx)(g,{className:(0,ey.cn)("h-4 w-4 shrink-0 text-blue-500",N&&"opacity-60")}),(0,z.jsx)("span",{className:(0,ey.cn)("truncate",N&&"text-muted-foreground"),children:e.name})]}),(0,z.jsxs)("div",{className:(0,ey.cn)("shrink-0 ml-1 items-center gap-1",_?"flex":"hidden group-hover:flex"),children:[(0,z.jsx)(bB,{path:r}),(0,z.jsx)(bL,{entryPath:r,type:"directory",deleting:_,onRequestDelete:m})]})]}),C&&k&&(0,z.jsx)("div",{children:k.map(e=>{let g=r?`${r}/${e.name}`:e.name;return(0,z.jsx)(bI,{entry:e,path:g,depth:s+1,expandedDirs:i,directoryContents:n,loadingDirs:o,selectedFile:a,uploadingDirs:l,dragOverPath:c,deletingPaths:d,onToggleDirectory:u,onSelectFile:h,onUploadFiles:f,onSetDragOverPath:p,onRequestDelete:m},g)})})]})}let D=(g=e.name,_=g.split(".").pop()?.toLowerCase()??"",bM.has(_)?be:bF.has(_)?bt:y9),E=a===r,R=r.includes("/")?r.slice(0,r.lastIndexOf("/")):"",A=d.has(r);return(0,z.jsxs)("div",{className:(0,ey.cn)("group flex items-center w-full px-2 py-2 rounded-sm transition-colors cursor-pointer",E?"bg-accent text-accent-foreground":"hover:bg-accent/50"),style:{paddingLeft:`${16*s+8+18}px`},onClick:()=>h(r),onDragOver:e=>{bT(e)&&(e.preventDefault(),e.stopPropagation(),p(R))},onDrop:e=>{if(!bT(e))return;e.preventDefault(),e.stopPropagation(),p(null);let r=bP(e);r.length&&f(R,r)},children:[(0,z.jsxs)("div",{className:"flex items-center gap-1 min-w-0 flex-1",children:[(0,z.jsx)(D,{className:(0,ey.cn)("h-4 w-4 shrink-0 text-muted-foreground",N&&"opacity-60")}),(0,z.jsx)("span",{className:(0,ey.cn)("truncate",N&&"text-muted-foreground"),children:e.name})]}),(0,z.jsxs)("div",{className:"shrink-0 flex items-center gap-2 ml-1",children:[(0,z.jsx)("span",{className:"text-[11px] text-muted-foreground/70 group-hover:hidden whitespace-nowrap w-[52px] text-right tabular-nums",children:e.mtime&&(x=e.mtime,y=Date.now(),S=Math.floor((w=Math.floor((b=Math.floor(Math.floor((y-new Date(x).getTime())/1e3)/60))/60))/24),b<1?"just now":b<60?`${b}m ago`:w<24?`${w}h ago`:S<30?`${S}d ago`:new Date(x).toLocaleDateString(void 0,{month:"short",day:"numeric"}))}),(0,z.jsx)("span",{className:"text-[11px] text-muted-foreground/70 group-hover:hidden whitespace-nowrap w-[52px] text-right tabular-nums",children:null!=e.size&&((v=e.size)<1024?`${v} B`:v<1048576?`${(v/1024).toFixed(1)} KB`:`${(v/1048576).toFixed(1)} MB`)}),(0,z.jsxs)("div",{className:(0,ey.cn)("items-center gap-1",A?"flex":"hidden group-hover:flex"),children:[(0,z.jsx)(bB,{path:r}),(0,z.jsx)(bL,{entryPath:r,type:"file",deleting:A,onRequestDelete:m})]})]})]})}function bO({entries:e,expandedDirs:r,directoryContents:s,loadingDirs:i,selectedFile:n,uploadingDirs:o,rootLoading:a,deletingPaths:l,onToggleDirectory:c,onSelectFile:d,onUploadFiles:u,onDeleteEntry:h}){let[f,p]=(0,$.useState)(null),[m,g]=(0,$.useState)(null),x=""===f,v=o.has(""),_=(0,$.useCallback)((e,r)=>{g({path:e,type:r})},[]),y=m?m.path.includes("/")?m.path.slice(m.path.lastIndexOf("/")+1):m.path:"";return(0,z.jsxs)("div",{className:(0,ey.cn)("h-full transition-colors",x&&"bg-accent/30 outline-2 -outline-offset-2 outline-dashed outline-primary/50"),style:{fontSize:"var(--files-tree-font-size, 14px)"},onDragOver:e=>{bT(e)&&(e.preventDefault(),p(""))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||p(null)},onDrop:e=>{if(!bT(e))return;e.preventDefault(),p(null);let r=bP(e);r.length&&u("",r)},children:[(0,z.jsx)(at,{className:"h-full",children:(0,z.jsxs)("div",{className:"py-1",children:[v&&(0,z.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1 text-xs text-muted-foreground",children:[(0,z.jsx)(rj,{className:"h-3.5 w-3.5 animate-spin"}),"Uploading…"]}),a&&0===e.length?(0,z.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground text-sm",children:"Loading files..."}):0===e.length?(0,z.jsx)("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-sm",children:x?"Drop files to upload":"No files found. Drop files here to upload."}):e.map(e=>{let a=e.name;return(0,z.jsx)(bI,{entry:e,path:a,depth:0,expandedDirs:r,directoryContents:s,loadingDirs:i,selectedFile:n,uploadingDirs:o,dragOverPath:f,deletingPaths:l,onToggleDirectory:c,onSelectFile:d,onUploadFiles:u,onSetDragOverPath:p,onRequestDelete:_},a)})]})}),(0,z.jsx)(bw,{open:null!==m,onOpenChange:e=>{e||g(null)},children:(0,z.jsxs)(bj,{children:[(0,z.jsxs)(bk,{children:[(0,z.jsxs)(bD,{children:["Delete ",m?.type==="directory"?"folder":"file","?"]}),(0,z.jsx)(bE,{children:m?.type==="directory"?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)("span",{className:"font-medium text-foreground",children:y})," and all its contents will be permanently deleted. This can't be undone."]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)("span",{className:"font-medium text-foreground",children:y})," will be permanently deleted. This can't be undone."]})})]}),(0,z.jsxs)(bN,{children:[(0,z.jsx)(bA,{children:"Cancel"}),(0,z.jsx)(bR,{className:(0,ey.cn)((0,W.buttonVariants)({variant:"destructive"}),"border-transparent"),onClick:()=>{m&&h(m.path,m.type)},children:"Delete"})]})]})})]})}let bz=(0,ew.default)("download",[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]]),b$=(0,ew.default)("file-exclamation-point",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]),bW=(0,ew.default)("code",[["path",{d:"m16 18 6-6-6-6",key:"eg8j8"}],["path",{d:"m8 6-6 6 6 6",key:"ppft3o"}]]),bH=(0,ew.default)("list-collapse",[["path",{d:"M10 5h11",key:"1hkqpe"}],["path",{d:"M10 12h11",key:"6m4ad9"}],["path",{d:"M10 19h11",key:"14g2nv"}],["path",{d:"m3 10 3-3-3-3",key:"i7pm08"}],["path",{d:"m3 20 3-3-3-3",key:"20gx1n"}]]),bU=(0,ew.default)("list-tree",[["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"M3 10a2 2 0 0 0 2 2h3",key:"1npucw"}],["path",{d:"M3 5v12a2 2 0 0 0 2 2h3",key:"x1gjn2"}]]),bK=/[\0-\x1F!-,\.\/:-@\[-\^`\{-\xA9\xAB-\xB4\xB6-\xB9\xBB-\xBF\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u0378\u0379\u037E\u0380-\u0385\u0387\u038B\u038D\u03A2\u03F6\u0482\u0530\u0557\u0558\u055A-\u055F\u0589-\u0590\u05BE\u05C0\u05C3\u05C6\u05C8-\u05CF\u05EB-\u05EE\u05F3-\u060F\u061B-\u061F\u066A-\u066D\u06D4\u06DD\u06DE\u06E9\u06FD\u06FE\u0700-\u070F\u074B\u074C\u07B2-\u07BF\u07F6-\u07F9\u07FB\u07FC\u07FE\u07FF\u082E-\u083F\u085C-\u085F\u086B-\u089F\u08B5\u08C8-\u08D2\u08E2\u0964\u0965\u0970\u0984\u098D\u098E\u0991\u0992\u09A9\u09B1\u09B3-\u09B5\u09BA\u09BB\u09C5\u09C6\u09C9\u09CA\u09CF-\u09D6\u09D8-\u09DB\u09DE\u09E4\u09E5\u09F2-\u09FB\u09FD\u09FF\u0A00\u0A04\u0A0B-\u0A0E\u0A11\u0A12\u0A29\u0A31\u0A34\u0A37\u0A3A\u0A3B\u0A3D\u0A43-\u0A46\u0A49\u0A4A\u0A4E-\u0A50\u0A52-\u0A58\u0A5D\u0A5F-\u0A65\u0A76-\u0A80\u0A84\u0A8E\u0A92\u0AA9\u0AB1\u0AB4\u0ABA\u0ABB\u0AC6\u0ACA\u0ACE\u0ACF\u0AD1-\u0ADF\u0AE4\u0AE5\u0AF0-\u0AF8\u0B00\u0B04\u0B0D\u0B0E\u0B11\u0B12\u0B29\u0B31\u0B34\u0B3A\u0B3B\u0B45\u0B46\u0B49\u0B4A\u0B4E-\u0B54\u0B58-\u0B5B\u0B5E\u0B64\u0B65\u0B70\u0B72-\u0B81\u0B84\u0B8B-\u0B8D\u0B91\u0B96-\u0B98\u0B9B\u0B9D\u0BA0-\u0BA2\u0BA5-\u0BA7\u0BAB-\u0BAD\u0BBA-\u0BBD\u0BC3-\u0BC5\u0BC9\u0BCE\u0BCF\u0BD1-\u0BD6\u0BD8-\u0BE5\u0BF0-\u0BFF\u0C0D\u0C11\u0C29\u0C3A-\u0C3C\u0C45\u0C49\u0C4E-\u0C54\u0C57\u0C5B-\u0C5F\u0C64\u0C65\u0C70-\u0C7F\u0C84\u0C8D\u0C91\u0CA9\u0CB4\u0CBA\u0CBB\u0CC5\u0CC9\u0CCE-\u0CD4\u0CD7-\u0CDD\u0CDF\u0CE4\u0CE5\u0CF0\u0CF3-\u0CFF\u0D0D\u0D11\u0D45\u0D49\u0D4F-\u0D53\u0D58-\u0D5E\u0D64\u0D65\u0D70-\u0D79\u0D80\u0D84\u0D97-\u0D99\u0DB2\u0DBC\u0DBE\u0DBF\u0DC7-\u0DC9\u0DCB-\u0DCE\u0DD5\u0DD7\u0DE0-\u0DE5\u0DF0\u0DF1\u0DF4-\u0E00\u0E3B-\u0E3F\u0E4F\u0E5A-\u0E80\u0E83\u0E85\u0E8B\u0EA4\u0EA6\u0EBE\u0EBF\u0EC5\u0EC7\u0ECE\u0ECF\u0EDA\u0EDB\u0EE0-\u0EFF\u0F01-\u0F17\u0F1A-\u0F1F\u0F2A-\u0F34\u0F36\u0F38\u0F3A-\u0F3D\u0F48\u0F6D-\u0F70\u0F85\u0F98\u0FBD-\u0FC5\u0FC7-\u0FFF\u104A-\u104F\u109E\u109F\u10C6\u10C8-\u10CC\u10CE\u10CF\u10FB\u1249\u124E\u124F\u1257\u1259\u125E\u125F\u1289\u128E\u128F\u12B1\u12B6\u12B7\u12BF\u12C1\u12C6\u12C7\u12D7\u1311\u1316\u1317\u135B\u135C\u1360-\u137F\u1390-\u139F\u13F6\u13F7\u13FE-\u1400\u166D\u166E\u1680\u169B-\u169F\u16EB-\u16ED\u16F9-\u16FF\u170D\u1715-\u171F\u1735-\u173F\u1754-\u175F\u176D\u1771\u1774-\u177F\u17D4-\u17D6\u17D8-\u17DB\u17DE\u17DF\u17EA-\u180A\u180E\u180F\u181A-\u181F\u1879-\u187F\u18AB-\u18AF\u18F6-\u18FF\u191F\u192C-\u192F\u193C-\u1945\u196E\u196F\u1975-\u197F\u19AC-\u19AF\u19CA-\u19CF\u19DA-\u19FF\u1A1C-\u1A1F\u1A5F\u1A7D\u1A7E\u1A8A-\u1A8F\u1A9A-\u1AA6\u1AA8-\u1AAF\u1AC1-\u1AFF\u1B4C-\u1B4F\u1B5A-\u1B6A\u1B74-\u1B7F\u1BF4-\u1BFF\u1C38-\u1C3F\u1C4A-\u1C4C\u1C7E\u1C7F\u1C89-\u1C8F\u1CBB\u1CBC\u1CC0-\u1CCF\u1CD3\u1CFB-\u1CFF\u1DFA\u1F16\u1F17\u1F1E\u1F1F\u1F46\u1F47\u1F4E\u1F4F\u1F58\u1F5A\u1F5C\u1F5E\u1F7E\u1F7F\u1FB5\u1FBD\u1FBF-\u1FC1\u1FC5\u1FCD-\u1FCF\u1FD4\u1FD5\u1FDC-\u1FDF\u1FED-\u1FF1\u1FF5\u1FFD-\u203E\u2041-\u2053\u2055-\u2070\u2072-\u207E\u2080-\u208F\u209D-\u20CF\u20F1-\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F-\u215F\u2189-\u24B5\u24EA-\u2BFF\u2C2F\u2C5F\u2CE5-\u2CEA\u2CF4-\u2CFF\u2D26\u2D28-\u2D2C\u2D2E\u2D2F\u2D68-\u2D6E\u2D70-\u2D7E\u2D97-\u2D9F\u2DA7\u2DAF\u2DB7\u2DBF\u2DC7\u2DCF\u2DD7\u2DDF\u2E00-\u2E2E\u2E30-\u3004\u3008-\u3020\u3030\u3036\u3037\u303D-\u3040\u3097\u3098\u309B\u309C\u30A0\u30FB\u3100-\u3104\u3130\u318F-\u319F\u31C0-\u31EF\u3200-\u33FF\u4DC0-\u4DFF\u9FFD-\u9FFF\uA48D-\uA4CF\uA4FE\uA4FF\uA60D-\uA60F\uA62C-\uA63F\uA673\uA67E\uA6F2-\uA716\uA720\uA721\uA789\uA78A\uA7C0\uA7C1\uA7CB-\uA7F4\uA828-\uA82B\uA82D-\uA83F\uA874-\uA87F\uA8C6-\uA8CF\uA8DA-\uA8DF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA954-\uA95F\uA97D-\uA97F\uA9C1-\uA9CE\uA9DA-\uA9DF\uA9FF\uAA37-\uAA3F\uAA4E\uAA4F\uAA5A-\uAA5F\uAA77-\uAA79\uAAC3-\uAADA\uAADE\uAADF\uAAF0\uAAF1\uAAF7-\uAB00\uAB07\uAB08\uAB0F\uAB10\uAB17-\uAB1F\uAB27\uAB2F\uAB5B\uAB6A-\uAB6F\uABEB\uABEE\uABEF\uABFA-\uABFF\uD7A4-\uD7AF\uD7C7-\uD7CA\uD7FC-\uD7FF\uE000-\uF8FF\uFA6E\uFA6F\uFADA-\uFAFF\uFB07-\uFB12\uFB18-\uFB1C\uFB29\uFB37\uFB3D\uFB3F\uFB42\uFB45\uFBB2-\uFBD2\uFD3E-\uFD4F\uFD90\uFD91\uFDC8-\uFDEF\uFDFC-\uFDFF\uFE10-\uFE1F\uFE30-\uFE32\uFE35-\uFE4C\uFE50-\uFE6F\uFE75\uFEFD-\uFF0F\uFF1A-\uFF20\uFF3B-\uFF3E\uFF40\uFF5B-\uFF65\uFFBF-\uFFC1\uFFC8\uFFC9\uFFD0\uFFD1\uFFD8\uFFD9\uFFDD-\uFFFF]|\uD800[\uDC0C\uDC27\uDC3B\uDC3E\uDC4E\uDC4F\uDC5E-\uDC7F\uDCFB-\uDD3F\uDD75-\uDDFC\uDDFE-\uDE7F\uDE9D-\uDE9F\uDED1-\uDEDF\uDEE1-\uDEFF\uDF20-\uDF2C\uDF4B-\uDF4F\uDF7B-\uDF7F\uDF9E\uDF9F\uDFC4-\uDFC7\uDFD0\uDFD6-\uDFFF]|\uD801[\uDC9E\uDC9F\uDCAA-\uDCAF\uDCD4-\uDCD7\uDCFC-\uDCFF\uDD28-\uDD2F\uDD64-\uDDFF\uDF37-\uDF3F\uDF56-\uDF5F\uDF68-\uDFFF]|\uD802[\uDC06\uDC07\uDC09\uDC36\uDC39-\uDC3B\uDC3D\uDC3E\uDC56-\uDC5F\uDC77-\uDC7F\uDC9F-\uDCDF\uDCF3\uDCF6-\uDCFF\uDD16-\uDD1F\uDD3A-\uDD7F\uDDB8-\uDDBD\uDDC0-\uDDFF\uDE04\uDE07-\uDE0B\uDE14\uDE18\uDE36\uDE37\uDE3B-\uDE3E\uDE40-\uDE5F\uDE7D-\uDE7F\uDE9D-\uDEBF\uDEC8\uDEE7-\uDEFF\uDF36-\uDF3F\uDF56-\uDF5F\uDF73-\uDF7F\uDF92-\uDFFF]|\uD803[\uDC49-\uDC7F\uDCB3-\uDCBF\uDCF3-\uDCFF\uDD28-\uDD2F\uDD3A-\uDE7F\uDEAA\uDEAD-\uDEAF\uDEB2-\uDEFF\uDF1D-\uDF26\uDF28-\uDF2F\uDF51-\uDFAF\uDFC5-\uDFDF\uDFF7-\uDFFF]|\uD804[\uDC47-\uDC65\uDC70-\uDC7E\uDCBB-\uDCCF\uDCE9-\uDCEF\uDCFA-\uDCFF\uDD35\uDD40-\uDD43\uDD48-\uDD4F\uDD74\uDD75\uDD77-\uDD7F\uDDC5-\uDDC8\uDDCD\uDDDB\uDDDD-\uDDFF\uDE12\uDE38-\uDE3D\uDE3F-\uDE7F\uDE87\uDE89\uDE8E\uDE9E\uDEA9-\uDEAF\uDEEB-\uDEEF\uDEFA-\uDEFF\uDF04\uDF0D\uDF0E\uDF11\uDF12\uDF29\uDF31\uDF34\uDF3A\uDF45\uDF46\uDF49\uDF4A\uDF4E\uDF4F\uDF51-\uDF56\uDF58-\uDF5C\uDF64\uDF65\uDF6D-\uDF6F\uDF75-\uDFFF]|\uD805[\uDC4B-\uDC4F\uDC5A-\uDC5D\uDC62-\uDC7F\uDCC6\uDCC8-\uDCCF\uDCDA-\uDD7F\uDDB6\uDDB7\uDDC1-\uDDD7\uDDDE-\uDDFF\uDE41-\uDE43\uDE45-\uDE4F\uDE5A-\uDE7F\uDEB9-\uDEBF\uDECA-\uDEFF\uDF1B\uDF1C\uDF2C-\uDF2F\uDF3A-\uDFFF]|\uD806[\uDC3B-\uDC9F\uDCEA-\uDCFE\uDD07\uDD08\uDD0A\uDD0B\uDD14\uDD17\uDD36\uDD39\uDD3A\uDD44-\uDD4F\uDD5A-\uDD9F\uDDA8\uDDA9\uDDD8\uDDD9\uDDE2\uDDE5-\uDDFF\uDE3F-\uDE46\uDE48-\uDE4F\uDE9A-\uDE9C\uDE9E-\uDEBF\uDEF9-\uDFFF]|\uD807[\uDC09\uDC37\uDC41-\uDC4F\uDC5A-\uDC71\uDC90\uDC91\uDCA8\uDCB7-\uDCFF\uDD07\uDD0A\uDD37-\uDD39\uDD3B\uDD3E\uDD48-\uDD4F\uDD5A-\uDD5F\uDD66\uDD69\uDD8F\uDD92\uDD99-\uDD9F\uDDAA-\uDEDF\uDEF7-\uDFAF\uDFB1-\uDFFF]|\uD808[\uDF9A-\uDFFF]|\uD809[\uDC6F-\uDC7F\uDD44-\uDFFF]|[\uD80A\uD80B\uD80E-\uD810\uD812-\uD819\uD824-\uD82B\uD82D\uD82E\uD830-\uD833\uD837\uD839\uD83D\uD83F\uD87B-\uD87D\uD87F\uD885-\uDB3F\uDB41-\uDBFF][\uDC00-\uDFFF]|\uD80D[\uDC2F-\uDFFF]|\uD811[\uDE47-\uDFFF]|\uD81A[\uDE39-\uDE3F\uDE5F\uDE6A-\uDECF\uDEEE\uDEEF\uDEF5-\uDEFF\uDF37-\uDF3F\uDF44-\uDF4F\uDF5A-\uDF62\uDF78-\uDF7C\uDF90-\uDFFF]|\uD81B[\uDC00-\uDE3F\uDE80-\uDEFF\uDF4B-\uDF4E\uDF88-\uDF8E\uDFA0-\uDFDF\uDFE2\uDFE5-\uDFEF\uDFF2-\uDFFF]|\uD821[\uDFF8-\uDFFF]|\uD823[\uDCD6-\uDCFF\uDD09-\uDFFF]|\uD82C[\uDD1F-\uDD4F\uDD53-\uDD63\uDD68-\uDD6F\uDEFC-\uDFFF]|\uD82F[\uDC6B-\uDC6F\uDC7D-\uDC7F\uDC89-\uDC8F\uDC9A-\uDC9C\uDC9F-\uDFFF]|\uD834[\uDC00-\uDD64\uDD6A-\uDD6C\uDD73-\uDD7A\uDD83\uDD84\uDD8C-\uDDA9\uDDAE-\uDE41\uDE45-\uDFFF]|\uD835[\uDC55\uDC9D\uDCA0\uDCA1\uDCA3\uDCA4\uDCA7\uDCA8\uDCAD\uDCBA\uDCBC\uDCC4\uDD06\uDD0B\uDD0C\uDD15\uDD1D\uDD3A\uDD3F\uDD45\uDD47-\uDD49\uDD51\uDEA6\uDEA7\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3\uDFCC\uDFCD]|\uD836[\uDC00-\uDDFF\uDE37-\uDE3A\uDE6D-\uDE74\uDE76-\uDE83\uDE85-\uDE9A\uDEA0\uDEB0-\uDFFF]|\uD838[\uDC07\uDC19\uDC1A\uDC22\uDC25\uDC2B-\uDCFF\uDD2D-\uDD2F\uDD3E\uDD3F\uDD4A-\uDD4D\uDD4F-\uDEBF\uDEFA-\uDFFF]|\uD83A[\uDCC5-\uDCCF\uDCD7-\uDCFF\uDD4C-\uDD4F\uDD5A-\uDFFF]|\uD83B[\uDC00-\uDDFF\uDE04\uDE20\uDE23\uDE25\uDE26\uDE28\uDE33\uDE38\uDE3A\uDE3C-\uDE41\uDE43-\uDE46\uDE48\uDE4A\uDE4C\uDE50\uDE53\uDE55\uDE56\uDE58\uDE5A\uDE5C\uDE5E\uDE60\uDE63\uDE65\uDE66\uDE6B\uDE73\uDE78\uDE7D\uDE7F\uDE8A\uDE9C-\uDEA0\uDEA4\uDEAA\uDEBC-\uDFFF]|\uD83C[\uDC00-\uDD2F\uDD4A-\uDD4F\uDD6A-\uDD6F\uDD8A-\uDFFF]|\uD83E[\uDC00-\uDFEF\uDFFA-\uDFFF]|\uD869[\uDEDE-\uDEFF]|\uD86D[\uDF35-\uDF3F]|\uD86E[\uDC1E\uDC1F]|\uD873[\uDEA2-\uDEAF]|\uD87A[\uDFE1-\uDFFF]|\uD87E[\uDE1E-\uDFFF]|\uD884[\uDF4B-\uDFFF]|\uDB40[\uDC00-\uDCFF\uDDF0-\uDFFF]/g,bq=Object.hasOwnProperty;var bV=e.i(216920);let bY={},bG=new class{constructor(){this.occurrences,this.reset()}slug(e,r){var s,i;let n=(s=e,i=!0===r,"string"!=typeof s?"":(i||(s=s.toLowerCase()),s.replace(bK,"").replace(/ /g,"-"))),o=n;for(;bq.call(this.occurrences,n);)this.occurrences[o]++,n=o+"-"+this.occurrences[o];return this.occurrences[n]=0,n}reset(){this.occurrences=Object.create(null)}};function bX(e){let r=(e||bY).prefix||"";return function(e){bG.reset(),(0,bV.visit)(e,"element",function(e){let s,i;((i=2===(s="element"===e.type?e.tagName.toLowerCase():"").length&&104===s.charCodeAt(0)?s.charCodeAt(1):0)>48&&i<55?i-48:void 0)&&!e.properties.id&&(e.properties.id=r+bG.slug("children"in e?function e(r){let s=-1,i=[];for(;++s<r.children.length;){var n;i[s]="text"===(n=r.children[s]).type?n.value:"children"in n?e(n):""}return i.join("")}(e):"value"in e?e.value:""))})}}var bJ=aE,H=H,bZ=e.i(829692),bZ=bZ,bQ=e.i(615742);let b0=(0,$.createContext)({code:""}),b1={name:"line-data",line(e,r){e.properties["data-line"]=String(r)}},b2={name:"line-numbers",line(e,r){e.children.unshift({type:"element",tagName:"span",properties:{className:["inline-block","min-w-10","mr-2","text-right","select-none","text-muted-foreground"]},children:[{type:"text",value:String(r)}]})}};async function b5(e,r,s=!1,i){let n=[b1];return i&&i.size>0&&n.push({name:"fold-gutter",line(e,r){e.children.unshift({type:"element",tagName:"span",properties:i.has(r)?{className:["code-fold-toggle"],"data-fold-start":String(r)}:{className:["code-fold-spacer"]},children:[]})}}),s&&n.push(b2),await Promise.all([(0,bQ.codeToHtml)(e,{lang:r,theme:"one-light",transformers:n}),(0,bQ.codeToHtml)(e,{lang:r,theme:"one-dark-pro",transformers:n})])}let b3=(0,$.forwardRef)(function({code:e,language:r,showLineNumbers:s=!1,scrollToLine:i,scrollKey:n,foldable:o=!1,className:a,children:l,...c},d){let[u,h]=(0,$.useState)(""),[f,p]=(0,$.useState)(""),m=(0,$.useRef)(!1),g=(0,$.useRef)(null),x=(0,$.useMemo)(()=>o?function(e,r={}){return function(...e){let r=new Map;for(let s of e.flat())!(s.endLine<=s.startLine)&&(r.has(s.startLine)||r.set(s.startLine,s));let s=[...r.values()].sort((e,r)=>e.startLine-r.startLine||r.endLine-e.endLine),i=[],n=[];for(let e of s){for(;n.length&&n[n.length-1].endLine<e.startLine;)n.pop();let r=n[n.length-1];r&&e.endLine>r.endLine||(i.push(e),n.push(e))}return i}((r.tokenIndex,[]),function(e){let r=e.split("\n"),s=[],i=[],n=0,o=e=>{n>e.line&&s.push({startLine:e.line+1,endLine:n+1})};for(let e=0;e<r.length;e++){let s=function(e){let r=e.match(/^[ \t]*/),s=r?r[0].length:0;return s===e.length?null:s}(r[e]);if(null!==s){for(;i.length&&i[i.length-1].indent>=s;)o(i.pop());i.push({indent:s,line:e}),n=e}}for(;i.length;)o(i.pop());return s}(e))}(e):[],[o,e]),v=(0,$.useMemo)(()=>new Set(x.map(e=>e.startLine)),[x]),[_,y]=(0,$.useState)(new Set),[b,w]=(0,$.useState)(e),[S,C]=(0,$.useState)({line:i,key:n});if((0,$.useImperativeHandle)(d,()=>({foldAll:()=>y(new Set(x.map(e=>e.startLine))),expandAll:()=>y(new Set)}),[x]),(0,$.useEffect)(()=>(b5(e,r,s,v).then(([e,r])=>{m.current||(h(e),p(r),m.current=!0)}),()=>{m.current=!1}),[e,r,s,v]),(0,$.useEffect)(()=>{let e=g.current;if(!e)return;let r=new Map(x.map(e=>[e.startLine,e])),s=new Set;for(let e of _){let i=r.get(e);if(i)for(let e=i.startLine+1;e<=i.endLine;e++)s.add(e)}for(let r of e.querySelectorAll("[data-line]")){let e=Number(r.getAttribute("data-line"));r.style.display=s.has(e)?"none":"",r.classList.toggle("code-line-collapsed",_.has(e))}},[_,x,u,f]),(0,$.useEffect)(()=>{if(!o)return;let e=g.current;if(!e)return;let r=e=>{let r=e.target?.closest?.("[data-fold-start]");if(!r)return;e.stopPropagation(),e.preventDefault();let s=Number(r.getAttribute("data-fold-start"));y(e=>{let r=new Set(e);return r.has(s)?r.delete(s):r.add(s),r})};return e.addEventListener("click",r),()=>e.removeEventListener("click",r)},[o]),(0,$.useEffect)(()=>{if(null==i)return;let e=g.current;if(!e||!u&&!f)return;let r=Array.from(e.querySelectorAll(`[data-line="${i}"]`));if(0===r.length)return;let s=r.find(e=>null!==e.offsetParent)??r[0],n=requestAnimationFrame(()=>{s.scrollIntoView({block:"center",behavior:"auto"}),r.forEach(e=>e.classList.add("code-line-highlight"))}),o=window.setTimeout(()=>r.forEach(e=>e.classList.remove("code-line-highlight")),1600);return()=>{cancelAnimationFrame(n),window.clearTimeout(o),r.forEach(e=>e.classList.remove("code-line-highlight"))}},[i,n,u,f]),e!==b&&(w(e),y(new Set)),(S.line!==i||S.key!==n)&&(C({line:i,key:n}),null!=i&&_.size>0)){let e=!1,r=new Set(_);for(let s of x)r.has(s.startLine)&&i>s.startLine&&i<=s.endLine&&(r.delete(s.startLine),e=!0);e&&y(r)}return(0,z.jsx)(b0.Provider,{value:{code:e},children:(0,z.jsx)("div",{ref:g,className:(0,ey.cn)("group relative w-full overflow-hidden rounded-md border bg-background text-foreground",a),...c,children:(0,z.jsxs)("div",{className:"relative",children:[(0,z.jsx)("div",{className:"overflow-auto dark:hidden [&>pre]:m-0 [&>pre]:bg-background! [&>pre]:p-4 [&>pre]:text-foreground! [&>pre]:text-sm [&_code]:grid [&_code]:font-mono [&_code]:text-sm",dangerouslySetInnerHTML:{__html:u}}),(0,z.jsx)("div",{className:"hidden overflow-auto dark:block [&>pre]:m-0 [&>pre]:bg-background! [&>pre]:p-4 [&>pre]:text-foreground! [&>pre]:text-sm [&_code]:grid [&_code]:font-mono [&_code]:text-sm",dangerouslySetInnerHTML:{__html:f}}),l&&(0,z.jsx)("div",{className:"absolute top-2 right-2 flex items-center gap-2",children:l})]})})})}),b4=({onCopy:e,onError:r,timeout:s=2e3,children:i,className:n,...o})=>{let[a,l]=(0,$.useState)(!1),{code:c}=(0,$.useContext)(b0),d=async()=>{if(!navigator?.clipboard?.writeText)return void r?.(Error("Clipboard API not available"));try{await navigator.clipboard.writeText(c),l(!0),e?.(),setTimeout(()=>l(!1),s)}catch(e){r?.(e)}},u=a?H.default:bZ.default;return(0,z.jsx)(W.Button,{className:(0,ey.cn)("shrink-0",n),onClick:d,size:"icon",variant:"ghost",...o,children:i??(0,z.jsx)(u,{size:14})})};var b6="horizontal",b8=["horizontal","vertical"],b7=$.forwardRef((e,r)=>{var s;let{decorative:i,orientation:n=b6,...o}=e,a=(s=n,b8.includes(s))?n:b6;return(0,z.jsx)(er.div,{"data-orientation":a,...i?{role:"none"}:{"aria-orientation":"vertical"===a?a:void 0,role:"separator"},...o,ref:r})});b7.displayName="Separator",e.s(["Root",()=>b7,"Separator",()=>b7],691102),e.i(691102),(0,sv.cva)("flex w-fit items-stretch [&>*]:focus-visible:z-10 [&>*]:focus-visible:relative [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md has-[>[data-slot=button-group]]:gap-2",{variants:{orientation:{horizontal:"[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",vertical:"flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none"}},defaultVariants:{orientation:"horizontal"}}),(0,ew.default)("chevron-left",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);var aR=aE;let b9=({className:e,from:r,...s})=>(0,z.jsx)("div",{className:(0,ey.cn)("group flex w-full max-w-[95%] flex-col gap-2","user"===r?"is-user ml-auto justify-end":"is-assistant",e),...s}),we=({children:e,className:r,...s})=>(0,z.jsx)("div",{className:(0,ey.cn)("is-user:dark flex w-fit max-w-full min-w-0 flex-col gap-2 overflow-hidden text-sm","group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground","group-[.is-assistant]:text-foreground",r),...s,children:e}),wt=(0,$.memo)(({className:e,...r})=>(0,z.jsx)(aR.i,{className:(0,ey.cn)("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",e),...r}),(e,r)=>e.children===r.children);function wr({className:e,...r}){return(0,z.jsx)("div",{"data-slot":"skeleton",className:(0,ey.cn)("bg-accent animate-pulse rounded-md",e),...r})}function ws({projectId:e,symbol:r,branch:s,target:i,currentFile:n,anchor:o,onJump:a,onClose:l}){let[c,d]=(0,$.useState)(!0),[u,h]=(0,$.useState)([]),[f,p]=(0,$.useState)(!1),m=(0,$.useRef)(null);(0,$.useEffect)(()=>{let n=!0;return d(!0),rx.api.searchSymbol(e,r,s,i).then(e=>{n&&(h(e.hits),p(e.truncated))}).catch(()=>{n&&h([])}).finally(()=>{n&&d(!1)}),()=>{n=!1}},[e,r,s,i]),(0,$.useEffect)(()=>{let e=e=>{e.detail>=2||m.current&&!m.current.contains(e.target)&&l()},s=e=>{if("Escape"===e.key)return void l();if((e.metaKey||e.ctrlKey)&&("c"===e.key||"C"===e.key)){let s=window.getSelection();if(s&&s.rangeCount>0&&!s.isCollapsed)return;e.preventDefault(),navigator.clipboard?.writeText(r)}};return document.addEventListener("mousedown",e),document.addEventListener("keydown",s),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",s)}},[l,r]);let g=(e,r)=>Number(r.file===n)-Number(e.file===n),x=u.filter(e=>"definition"===e.kind).sort(g),v=u.filter(e=>"reference"===e.kind).sort(g),_=Math.max(8,Math.min(o.x,window.innerWidth-440-8)),y=window.innerHeight-8-(o.y+18),b=o.y-18-8,w=y>=340||y>=b,S=Math.max(120,Math.min(340,w?y:b)),C=w?{top:o.y+18}:{bottom:window.innerHeight-(o.y-18)},j=({hit:e})=>(0,z.jsxs)("button",{type:"button",onClick:()=>{a(e.file,e.line),l()},className:"flex w-full flex-col items-start gap-0.5 rounded px-2 py-1.5 text-left hover:bg-accent",children:[(0,z.jsxs)("span",{className:"flex w-full items-baseline justify-between gap-2",children:[(0,z.jsxs)("span",{className:"truncate font-mono text-xs",children:[e.file.split("/").pop(),(0,z.jsxs)("span",{className:"text-muted-foreground",children:[":",e.line]})]}),e.file===n&&(0,z.jsx)("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:"this file"})]}),(0,z.jsx)("code",{className:"w-full truncate text-xs text-muted-foreground",children:e.text.trim()})]}),k=({title:e,children:r})=>(0,z.jsxs)("div",{className:"mb-1",children:[(0,z.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:e}),r]});return(0,ee.createPortal)((0,z.jsxs)("div",{ref:m,style:{left:_,...C,width:440,maxHeight:S},className:"fixed z-50 flex flex-col overflow-hidden rounded-lg border bg-popover text-popover-foreground shadow-lg select-none",children:[(0,z.jsx)("div",{className:"border-b px-3 py-1.5 text-xs font-medium",children:(0,z.jsx)("span",{className:"font-mono",children:r})}),(0,z.jsx)("div",{className:"flex-1 overflow-auto p-1",children:c?(0,z.jsxs)("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[(0,z.jsx)(rj,{className:"h-4 w-4 animate-spin"})," Searching…"]}):0===u.length?(0,z.jsx)("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"No results."}):(0,z.jsxs)(z.Fragment,{children:[x.length>0&&(0,z.jsx)(k,{title:`Definitions (${x.length})`,children:x.map((e,r)=>(0,z.jsx)(j,{hit:e},`d-${r}`))}),v.length>0&&(0,z.jsx)(k,{title:`References (${v.length})`,children:v.map((e,r)=>(0,z.jsx)(j,{hit:e},`r-${r}`))}),f&&(0,z.jsx)("div",{className:"px-2 py-1.5 text-[11px] text-muted-foreground",children:"Showing first matches — results truncated."})]})})]}),document.body)}wt.displayName="MessageResponse";let wi=(0,ew.default)("image-off",[["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}],["path",{d:"M10.41 10.41a2 2 0 1 1-2.83-2.83",key:"1bzlo9"}],["line",{x1:"13.5",x2:"6",y1:"13.5",y2:"21",key:"1q0aeu"}],["line",{x1:"18",x2:"21",y1:"12",y2:"15",key:"5mozeu"}],["path",{d:"M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59",key:"mmje98"}],["path",{d:"M21 15V5a2 2 0 0 0-2-2H9",key:"43el77"}]]);function wn({projectId:e,filePath:r,branch:s,target:i,onDownload:n}){let[o,a]=(0,$.useState)(null),[l,c]=(0,$.useState)(!1);return((0,$.useEffect)(()=>{let n=null,o=!1;return rx.api.getFileBlob(e,r,s,i).then(e=>{o||a(n=URL.createObjectURL(e))}).catch(()=>{o||c(!0)}),()=>{o=!0,n&&URL.revokeObjectURL(n)}},[e,r,s,i]),l)?(0,z.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-3 text-muted-foreground",children:[(0,z.jsx)(wi,{className:"h-10 w-10"}),(0,z.jsx)("p",{className:"text-sm",children:"Couldn't load image"}),(0,z.jsxs)(W.Button,{variant:"outline",size:"sm",onClick:n,children:[(0,z.jsx)(bz,{className:"h-4 w-4 mr-2"}),"Download"]})]}):o?(0,z.jsx)("div",{className:"flex items-center justify-center h-full p-4 bg-muted/30",children:(0,z.jsx)("img",{src:o,alt:r.split("/").pop()??"image",className:"max-w-full max-h-full object-contain",onError:()=>c(!0)})}):(0,z.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:(0,z.jsx)(rj,{className:"h-6 w-6 animate-spin"})})}async function wo(e,r){let s=await (0,bQ.codeToTokensBase)(e,{lang:r,theme:"one-light",includeExplanation:"scopeName"}),i=new Map;return s.forEach((e,r)=>{let s=0,n=[];for(let r of e){let e=(r.explanation??[]).flatMap(e=>e.scopes.map(e=>e.scopeName)),i=s+r.content.length;n.push({start:s,end:i,kind:e.some(e=>e.startsWith("comment"))?"comment":e.some(e=>e.startsWith("string")||e.startsWith("constant.character"))?"string":e.some(e=>e.startsWith("keyword")||e.startsWith("storage")||e.startsWith("constant.language")||e.startsWith("variable.language"))?"keyword":"code"}),s=i}i.set(r+1,n)}),i}let wa=new Set(["png","jpg","jpeg","gif","webp","bmp","ico","avif","svg"]);function wl(e){let r=e.split("/").pop()?.split(".").pop()?.toLowerCase()??"";return wa.has(r)}let wc=/^[A-Za-z_$][A-Za-z0-9_$]*$/,wd="symbol-nav";function wu(e,r,s){let i=document.createRange();return i.selectNodeContents(e),i.setEnd(r,s),i.toString().length}function wh(e,r){let s,i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),n=0;for(;s=i.nextNode();){let e=(s.textContent??"").length;if(r<=n+e)return{node:s,offset:r-n};n+=e}return null}function wf(e){let r=Array.from(document.querySelectorAll(`[data-line="${CSS.escape(e.line)}"]`)),s=r.find(e=>null!==e.offsetParent)??r[0];if(!s)return null;let i=wh(s,e.start),n=wh(s,e.end);if(!i||!n)return null;let o=document.createRange();return o.setStart(i.node,i.offset),o.setEnd(n.node,n.offset),o}let wp=/[A-Za-z0-9_$]/;function wm(e,r,s){let i=document,n=null,o=0;if(i.caretRangeFromPoint){let s=i.caretRangeFromPoint(e,r);s&&(n=s.startContainer,o=s.startOffset)}else if(i.caretPositionFromPoint){let s=i.caretPositionFromPoint(e,r);s&&(n=s.offsetNode,o=s.offset)}if(!n||n.nodeType!==Node.TEXT_NODE)return null;let a=n.textContent??"",l=o,c=o;for(;l>0&&wp.test(a[l-1]);)l--;for(;c<a.length&&wp.test(a[c]);)c++;if(l>=c)return null;let d=a.slice(l,c);if(!wc.test(d))return null;let u=document.createRange();u.setStart(n,l),u.setEnd(n,c);let h=function(e){let r=e.startContainer.nodeType===Node.ELEMENT_NODE?e.startContainer:e.startContainer.parentElement,s=r?.closest("[data-line]");if(!s||!s.contains(e.endContainer))return null;let i=s.getAttribute("data-line");if(null===i)return null;let n=wu(s,e.startContainer,e.startOffset),o=wu(s,e.endContainer,e.endOffset);return n>=o?null:{line:i,start:n,end:o}}(u);if(!h)return null;if(s){let e=h.start-h.line.length,r=function(e,r,s){let i=e.get(r);if(!i)return null;for(let e of i)if(s>=e.start&&s<e.end)return e.kind;return null}(s,Number(h.line),e);if(r&&"code"!==r)return null}return{word:d,anchor:h}}function wg(){return"undefined"!=typeof CSS&&"highlights"in CSS&&"undefined"!=typeof Highlight}let wx=!1;function wv(){wg()&&CSS.highlights.delete(wd)}let w_={ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",cs:"csharp",css:"css",scss:"scss",html:"html",vue:"vue",svelte:"svelte",php:"php",swift:"swift",kt:"kotlin",sh:"bash",bash:"bash",zsh:"bash",yaml:"yaml",yml:"yaml",toml:"toml",json:"json",xml:"xml",sql:"sql",graphql:"graphql",md:"markdown",mdx:"mdx",dockerfile:"dockerfile",makefile:"makefile",lua:"lua",r:"r",scala:"scala",zig:"zig"};function wy(e){let r=e.split("/").pop()?.toLowerCase()??"";return"dockerfile"===r?"dockerfile":"makefile"===r?"makefile":w_[r.split(".").pop()?.toLowerCase()??""]??"text"}function wb(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function ww({filePath:e,fileContent:r,loading:s,downloadUrl:i,projectId:n,branch:o,target:a,scrollToLine:l,scrollKey:c,onJump:d,restoreScrollTop:u,restoreScrollKey:h,onScroll:f}){let p,[m,g]=(0,$.useState)("rendered"),[x,v]=(0,$.useState)(e),[_,y]=(0,$.useState)(null),b=(0,$.useRef)(null),w=(0,$.useRef)(null),S=(0,$.useRef)(!1);(0,$.useEffect)(()=>{S.current=null!==_},[_]);let C=(0,$.useCallback)(e=>{if(e.detail>=2){let r=window.getSelection();if(S.current){r?.removeAllRanges(),y(e=>e?{...e,selectWord:!0}:e);return}let s=wm(e.clientX,e.clientY),i=s?wf(s.anchor):null;i&&(r?.removeAllRanges(),r?.addRange(i));return}let r=window.getSelection();if(r&&!r.isCollapsed)return;let s=wm(e.clientX,e.clientY,b.current);s&&(r?.removeAllRanges(),y({symbol:s.word,x:e.clientX,y:e.clientY,anchor:s.anchor,selectWord:!1}))},[]),j=(0,$.useCallback)(e=>{e.detail>=2&&e.preventDefault()},[]);(0,$.useEffect)(()=>{if(!_?.anchor)return void wv();let e=wf(_.anchor);if(!e)return void wv();if(_.selectWord){wv();let r=window.getSelection();r?.removeAllRanges(),r?.addRange(e);return}return wg()?(!function(){if(wx||"undefined"==typeof document)return;wx=!0;let e=document.createElement("style");e.textContent=`::highlight(${wd}){background-color:rgba(255, 196, 0, 0.32);}`,document.head.appendChild(e)}(),CSS.highlights.set(wd,new Highlight(e)),wv):void wv()},[_]),(0,$.useEffect)(()=>{b.current=null;let s=r?.content;if(!e||null==s||r?.binary||r?.tooLarge)return;let i=!1;return wo(s,wy(e)).then(e=>{i||(b.current=e)}).catch(()=>{}),()=>{i=!0}},[e,r]);let k=(0,$.useRef)(null),N=(0,$.useRef)(null),D=(0,$.useCallback)(e=>{let r=k.current;if(!r)return;let s=r.querySelector(`[id="${CSS.escape(e)}"]`);if(!s)return;N.current?.();let i=()=>s.scrollIntoView({block:"start",behavior:"auto"});i();let n=new ResizeObserver(i);n.observe(r);let o=()=>{n.disconnect(),window.clearTimeout(a),window.removeEventListener("wheel",o),window.removeEventListener("touchmove",o),window.removeEventListener("keydown",o),N.current=null},a=window.setTimeout(o,1e3);window.addEventListener("wheel",o,{passive:!0}),window.addEventListener("touchmove",o,{passive:!0}),window.addEventListener("keydown",o),N.current=o},[]);(0,$.useEffect)(()=>()=>N.current?.(),[]);let E=(0,$.useRef)(null),R=(0,$.useRef)(!1),A=(0,$.useRef)(f);A.current=f;let M=(0,$.useRef)(null),F=(0,$.useRef)(null),T=(0,$.useCallback)(e=>{if(R.current)return;let r=e.currentTarget.scrollTop;M.current&&clearTimeout(M.current),M.current=setTimeout(()=>A.current?.(r),200)},[]);(0,$.useEffect)(()=>{void 0!==h&&(F.current=u??0)},[h,u]),(0,$.useEffect)(()=>{let e=E.current;e&&(e.scrollTop=0)},[e]),(0,$.useEffect)(()=>{let e=F.current;if(null==e)return;let r=E.current;if(!r||(F.current=null,!e))return;R.current=!0;let s=()=>{r.scrollTop=e};s();let i=new ResizeObserver(s);i.observe(r.firstElementChild??r);let n=()=>{R.current=!1,i.disconnect(),window.clearTimeout(o),r.removeEventListener("wheel",n),r.removeEventListener("touchmove",n),r.removeEventListener("keydown",n)},o=window.setTimeout(n,1500);return r.addEventListener("wheel",n,{passive:!0}),r.addEventListener("touchmove",n,{passive:!0}),r.addEventListener("keydown",n),n},[r]);let P=(0,$.useMemo)(()=>[...Object.values(bJ.e),bX],[]),B=(0,$.useMemo)(()=>({a:({href:e,children:r,className:s,node:i,...n})=>{let o="string"==typeof e&&e.startsWith("#");return(0,z.jsx)("a",{href:e,className:(0,ey.cn)("wrap-anywhere font-medium text-primary underline",s),"data-streamdown":"link",...o?{onClick:r=>{r.preventDefault(),D(decodeURIComponent(e.slice(1)))}}:{target:"_blank",rel:"noreferrer"},...n,children:r})}}),[D]);if(e!==x&&(v(e),g("rendered"),y(null)),!e)return(0,z.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:"Select a file to preview."});if(s)return(0,z.jsxs)("div",{className:"flex flex-col h-full",children:[(0,z.jsx)("div",{className:"flex items-center justify-between px-4 py-2 border-b flex-shrink-0",children:(0,z.jsx)(wr,{className:"h-4 w-48"})}),(0,z.jsxs)("div",{className:"flex-1 p-4",children:[(0,z.jsx)(wr,{className:"h-4 w-full mb-2"}),(0,z.jsx)(wr,{className:"h-4 w-3/4 mb-2"}),(0,z.jsx)(wr,{className:"h-4 w-5/6 mb-2"}),(0,z.jsx)(wr,{className:"h-4 w-2/3"})]})]});if(!r)return(0,z.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:"Failed to load file."});let L=()=>{e&&rx.api.downloadFile(n,e,o,a).catch(e=>{console.error("Failed to download file",e)})},I=("markdown"===(p=wy(e))||"mdx"===p)&&!r.tooLarge&&!r.binary&&!!r.content,O=I&&"rendered"===m,H=!r.tooLarge&&!r.binary&&!O&&null!==r.content;return(0,z.jsxs)("div",{className:"flex flex-col h-full",children:[(0,z.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b flex-shrink-0 gap-2",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,z.jsx)("span",{className:"text-sm font-mono truncate",children:e}),(0,z.jsx)("span",{className:"text-xs text-muted-foreground shrink-0",children:wb(r.size)})]}),(0,z.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[I&&(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>g(e=>"rendered"===e?"source":"rendered"),title:O?"View source":"View rendered",children:O?(0,z.jsx)(bW,{className:"h-3.5 w-3.5"}):(0,z.jsx)(_i,{className:"h-3.5 w-3.5"})}),H&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>w.current?.foldAll(),title:"Fold all",children:(0,z.jsx)(bH,{className:"h-3.5 w-3.5"})}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>w.current?.expandAll(),title:"Expand all",children:(0,z.jsx)(bU,{className:"h-3.5 w-3.5"})})]}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>{navigator.clipboard.writeText(e)},title:"Copy path",children:(0,z.jsx)(dL.Copy,{className:"h-3.5 w-3.5"})}),i&&(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:L,title:"Download",children:(0,z.jsx)(bz,{className:"h-3.5 w-3.5"})})]})]}),(0,z.jsx)("div",{className:"flex-1 overflow-auto",ref:E,onScroll:T,children:r.tooLarge?(0,z.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-3 text-muted-foreground",children:[(0,z.jsx)(b$,{className:"h-10 w-10"}),(0,z.jsxs)("p",{className:"text-sm",children:["File too large to preview (",wb(r.size),")"]}),i&&(0,z.jsxs)(W.Button,{variant:"outline",size:"sm",onClick:L,children:[(0,z.jsx)(bz,{className:"h-4 w-4 mr-2"}),"Download"]})]}):r.binary&&wl(e)&&r.size<=0xa00000?(0,z.jsx)(wn,{projectId:n,filePath:e,branch:o,target:a,onDownload:L},e):r.binary?(0,z.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-3 text-muted-foreground",children:[(0,z.jsx)(b$,{className:"h-10 w-10"}),(0,z.jsx)("p",{className:"text-sm",children:wl(e)?`Image too large to preview (${wb(r.size)})`:`Binary file (${wb(r.size)})`}),i&&(0,z.jsxs)(W.Button,{variant:"outline",size:"sm",onClick:L,children:[(0,z.jsx)(bz,{className:"h-4 w-4 mr-2"}),"Download"]})]}):O?(0,z.jsx)("div",{className:"p-4",style:{fontSize:"var(--files-content-font-size, 14px)"},ref:k,children:(0,z.jsx)(wt,{components:B,rehypePlugins:P,children:r.content??""})}):null!==r.content?(0,z.jsx)("div",{className:"h-full [&_pre]:text-[length:var(--files-content-font-size,14px)]! [&_code]:text-[length:var(--files-content-font-size,14px)]!",onMouseDown:j,onClick:C,children:(0,z.jsx)(b3,{ref:w,code:r.content,language:wy(e),showLineNumbers:!0,foldable:!0,scrollToLine:l,scrollKey:c,className:"border-0 rounded-none",children:(0,z.jsx)(b4,{})})}):(0,z.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:"Empty file."})}),_&&(0,z.jsx)(ws,{projectId:n,symbol:_.symbol,branch:o,target:a,currentFile:e,anchor:{x:_.x,y:_.y},onJump:d,onClose:()=>y(null)})]})}class wS{capacity;map;constructor(e){if(this.capacity=e,this.map=new Map,e<1)throw Error("LRUCache capacity must be at least 1")}get(e){if(!this.map.has(e))return;let r=this.map.get(e);return this.map.delete(e),this.map.set(e,r),r}has(e){return this.map.has(e)}set(e,r){for(this.map.has(e)&&this.map.delete(e),this.map.set(e,r);this.map.size>this.capacity;){let e=this.map.keys().next().value;if(void 0===e)break;this.map.delete(e)}}delete(e){return this.map.delete(e)}deleteWhere(e){for(let r of[...this.map.keys()])e(r)&&this.map.delete(r)}clear(){this.map.clear()}get size(){return this.map.size}}let wC="vibedeckx:files:views";function wj(){return{v:1,views:{}}}function wk(){try{let e=localStorage.getItem(wC);if(!e)return wj();let r=JSON.parse(e);if(!r||1!==r.v||!r.views||"object"!=typeof r.views)return wj();return r}catch{return wj()}}function wN(e){try{localStorage.setItem(wC,JSON.stringify(e))}catch{}}function wD(e){return e.slice(e.lastIndexOf("\0")+1)}let wE=new Set(["/","-","_","."," "]);function wR({projectId:e,project:r,selectedBranch:s,navRequest:i}){let n=r&&!r.path?"remote":void 0,[o,a]=(0,$.useState)(!1),{settings:l}=(0,cz.useConversationSettings)(),c=(0,$.useRef)(null),[d,u]=(0,$.useState)(!1),h=(0,$.useCallback)(()=>{let e=c.current;e&&(e.isCollapsed()?e.expand():e.collapse())},[]),{rootEntries:f,directoryContents:p,expandedDirs:m,selectedFile:g,fileContent:x,fileLoading:v,rootLoading:_,loadingDirs:y,uploadingDirs:b,deletingPaths:w,jumpTarget:S,canGoBack:C,canGoForward:j,fetchRoot:k,refresh:N,reportScroll:D,restoreScroll:E,toggleDirectory:R,navigate:A,jumpTo:M,goBack:F,goForward:T,uploadFiles:P,deleteEntry:B}=function({projectId:e,branch:r,target:s,showHidden:i=!1}){let[n,o]=(0,$.useState)([]),[a,l]=(0,$.useState)(new Map),[c,d]=(0,$.useState)(new Set),[u,h]=(0,$.useState)(null),[f,p]=(0,$.useState)(null),[m,g]=(0,$.useState)(null),x=(0,$.useRef)(0),[v,_]=(0,$.useState)({entries:[],index:-1}),y=(0,$.useRef)(v);y.current=v;let[b,w]=(0,$.useState)(!1),[S,C]=(0,$.useState)(!1),[j,k]=(0,$.useState)(new Set),[N,D]=(0,$.useState)(new Set),[E,R]=(0,$.useState)(new Set),A=(0,$.useRef)(0),M=(0,$.useRef)(0),F=(0,$.useRef)(new wS(50)),T=e?[e,r??"",s??""].join("|"):null,P=(0,$.useRef)(T);P.current=T;let B=(0,$.useRef)(u);B.current=u;let L=(0,$.useRef)(0),I=(0,$.useRef)(null),O=(0,$.useRef)(0),[z,W]=(0,$.useState)(null),H=(0,$.useRef)(null),U=(0,$.useCallback)(i=>[e,r??"",s??"",i].join("\0"),[e,r,s]),K=(0,$.useCallback)(()=>{let e,r,s=P.current;if(!s||I.current!==s)return;let i={selectedFile:B.current,history:y.current,scrollTop:L.current};(e=wk()).views[s]={...i,updatedAt:Date.now()},(r=Object.keys(e.views)).length>30&&r.sort((r,s)=>e.views[r].updatedAt-e.views[s].updatedAt).slice(0,r.length-30).forEach(r=>delete e.views[r]),wN(e)},[]),q=(0,$.useCallback)(()=>{H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{H.current=null,K()},300)},[K]),V=(0,$.useCallback)(e=>{L.current=e,q()},[q]);(0,$.useEffect)(()=>{q()},[u,v,q]);let Y=(0,$.useCallback)(async n=>{if(e&&(d(e=>{let r=new Set(e);return r.has(n)?r.delete(n):r.add(n),r}),!a.has(n))){k(e=>new Set(e).add(n));try{let o=await rx.api.browseProjectDirectory(e,n,r,s,i);l(e=>{let r=new Map(e);return r.set(n,o.items),r})}catch(e){console.error("Failed to browse directory:",e),gK.toast.error(`Failed to open ${n}`,{description:e instanceof Error?e.message:String(e)})}finally{k(e=>{let r=new Set(e);return r.delete(n),r})}}},[e,r,s,i,a]),G=(0,$.useCallback)(async i=>{if(!e)return"failed";let n=U(i),o=F.current.get(n);if(o)return p(o),w(!1),"loaded";let a=++M.current;w(!0),p(null);try{let o=await rx.api.getFileContent(e,i,r,s);if(a!==M.current)return"stale";return F.current.set(n,o),p(o),"loaded"}catch(e){if(a!==M.current)return"stale";return console.error("Failed to get file content:",e),p(null),"failed"}finally{a===M.current&&w(!1)}},[e,r,s,U]),X=(0,$.useCallback)(async r=>{e&&(h(r),await G(r))},[e,G]),J=(0,$.useCallback)(async()=>{if(!e)return!1;C(!0);let n=++A.current;try{let a=await rx.api.browseProjectDirectory(e,void 0,r,s,i);if(n!==A.current)return!1;return o(a.items),l(new Map),d(new Set),!0}catch(e){if(console.error("Failed to browse root directory:",e),n!==A.current)return!1;return o([]),gK.toast.error("Failed to browse files",{description:e instanceof Error?e.message:String(e)}),!1}finally{n===A.current&&C(!1)}},[e,r,s,i]),Z=(0,$.useCallback)(async()=>{let r;if(!e||!await J())return;let s=P.current,i=s?(r=wk().views[s])&&"object"==typeof r&&(null===r.selectedFile||"string"==typeof r.selectedFile)&&r.history&&"object"==typeof r.history&&Array.isArray(r.history.entries)&&"number"==typeof r.history.index?{selectedFile:r.selectedFile,history:r.history,scrollTop:"number"==typeof r.scrollTop&&Number.isFinite(r.scrollTop)?r.scrollTop:0}:null:null;if(s&&i&&i.selectedFile){if(_(i.history.entries.length?i.history:{entries:[{path:i.selectedFile,line:null}],index:0}),L.current=i.scrollTop,W({top:i.scrollTop,nonce:++O.current}),h(i.selectedFile),I.current=s,"failed"===await G(i.selectedFile)){let e;h(null),_({entries:[],index:-1}),L.current=0,(e=wk()).views[s]&&(delete e.views[s],wN(e))}}else h(null),p(null),_({entries:[],index:-1}),L.current=0,I.current=s},[e,J,G]),Q=(0,$.useCallback)(async()=>{if(!e||(F.current.clear(),!await J()))return;let r=B.current;r&&await G(r)},[e,J,G]),ee=(0,$.useCallback)(async(e,r=null)=>{_(({entries:s,index:i})=>{let n=s[i];if(n&&n.path===e){let n=s.slice();return n[i]={path:e,line:r},{entries:n,index:i}}let o=s.slice(0,i+1);return{entries:[...o,{path:e,line:r}],index:o.length}}),await X(e),null!=r&&g({line:r,nonce:++x.current})},[X]),et=(0,$.useCallback)((e,r)=>ee(e,r),[ee]),er=(0,$.useCallback)(()=>{let{entries:e,index:r}=y.current;if(r<=0)return;let s=e[r-1];_(e=>({...e,index:e.index-1})),X(s.path),null!=s.line&&g({line:s.line,nonce:++x.current})},[X]),es=(0,$.useCallback)(()=>{let{entries:e,index:r}=y.current;if(r>=e.length-1)return;let s=e[r+1];_(e=>({...e,index:e.index+1})),X(s.path),null!=s.line&&g({line:s.line,nonce:++x.current})},[X]),ei=(0,$.useCallback)(async n=>{if(e)if(""===n)o((await rx.api.browseProjectDirectory(e,void 0,r,s,i)).items);else{let o=await rx.api.browseProjectDirectory(e,n,r,s,i);l(e=>{let r=new Map(e);return r.set(n,o.items),r})}},[e,r,s,i]),en=(0,$.useCallback)(async(i,n)=>{if(e&&0!==n.length){D(e=>new Set(e).add(i));try{let{uploaded:o}=await rx.api.uploadFiles(e,n,i,r,s),a=new Set(o.map(e=>i?`${i}/${e}`:e));F.current.deleteWhere(e=>a.has(wD(e))),""!==i&&d(e=>new Set(e).add(i)),await ei(i),gK.toast.success(`Uploaded ${o.length} file${1===o.length?"":"s"}`)}catch(e){console.error("Failed to upload files:",e),gK.toast.error("Upload failed",{description:e instanceof Error?e.message:String(e)})}finally{D(e=>{let r=new Set(e);return r.delete(i),r})}}},[e,r,s,ei]),eo=(0,$.useCallback)(async i=>{if(e&&i){R(e=>new Set(e).add(i));try{await rx.api.deleteFile(e,i,r,s),F.current.deleteWhere(e=>{let r=wD(e);return r===i||r.startsWith(`${i}/`)}),h(e=>e===i||e&&e.startsWith(`${i}/`)?(p(null),null):e);let n=i.includes("/")?i.slice(0,i.lastIndexOf("/")):"";await ei(n),gK.toast.success("Deleted")}catch(e){console.error("Failed to delete:",e),gK.toast.error("Delete failed",{description:e instanceof Error?e.message:String(e)})}finally{R(e=>{let r=new Set(e);return r.delete(i),r})}}},[e,r,s,ei]);return{rootEntries:n,directoryContents:a,expandedDirs:c,selectedFile:u,fileContent:f,fileLoading:b,rootLoading:S,loadingDirs:j,uploadingDirs:N,deletingPaths:E,jumpTarget:m,canGoBack:v.index>0,canGoForward:v.index<v.entries.length-1,fetchRoot:Z,refresh:Q,reportScroll:V,restoreScroll:z,toggleDirectory:Y,selectFile:X,navigate:ee,jumpTo:et,goBack:er,goForward:es,uploadFiles:en,refreshDirectory:ei,deleteEntry:eo}}({projectId:e,branch:s,target:n,showHidden:o}),L=function({projectId:e,branch:r,target:s}){let[i,n]=(0,$.useState)([]),[o,a]=(0,$.useState)(!1),[l,c]=(0,$.useState)(!1),[d,u]=(0,$.useState)(!1),[h,f]=(0,$.useState)(""),p=(0,$.useRef)(0);(0,$.useEffect)(()=>{n([]),a(!1),u(!1),c(!1),f(""),p.current++},[e,r,s]);let m=(0,$.useCallback)(async()=>{if(!e)return;c(!0);let i=++p.current;try{let o=await rx.api.listProjectFiles(e,r,s);if(i!==p.current)return;n(o.files),a(o.truncated),u(!0)}catch(e){if(i!==p.current)return;n([]),u(!1),gK.toast.error("Failed to load file list",{description:e instanceof Error?e.message:String(e)})}finally{i===p.current&&c(!1)}},[e,r,s]),g=(0,$.useCallback)(()=>{d||l||m()},[d,l,m]),x=(0,$.useCallback)(()=>{u(!1),p.current++,h&&m()},[h,m]),v=(0,$.useDeferredValue)(h);return{query:h,setQuery:f,results:(0,$.useMemo)(()=>(function(e,r,s){if(!r.trim())return[];let i=[];for(let s of e){let e=function(e,r){let s=e.toLowerCase().replace(/\s+/g,"");if(!s)return null;let i=r.toLowerCase(),n=r.lastIndexOf("/")+1,o=0,a=0,l=-2;for(let e=0;e<s.length;e++){let c=s[e],d=-1;for(;a<i.length;a++)if(i[a]===c){d=a;break}if(-1===d)return null;let u=1;d===l+1&&(u+=5),d>=n&&(u+=3);let h=d>0?r[d-1]:"/";(0===d||d===n||wE.has(h))&&(u+=4),o+=u,l=d,a=d+1}return o+.1*Math.max(0,40-r.length)}(r,s);null!==e&&i.push({path:s,score:e})}return i.sort((e,r)=>r.score-e.score||e.path.length-r.path.length),i.slice(0,50)})(i,v,0),[i,v]),truncated:o,loading:l,loaded:d,ensureLoaded:g,refresh:x}}({projectId:e,branch:s,target:n});(0,$.useEffect)(()=>{k()},[k]),(0,$.useEffect)(()=>{i&&(null!=i.line?M(i.path,i.line):A(i.path))},[i?.nonce]);let I=(0,$.useCallback)(()=>{N(),L.refresh()},[N,L]),O=(0,$.useCallback)(e=>{A(e),L.setQuery("")},[A,L]);if(!e)return(0,z.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:(0,z.jsxs)("div",{className:"text-center",children:[(0,z.jsx)("div",{className:"mx-auto w-10 h-10 rounded-xl bg-muted flex items-center justify-center mb-3",children:(0,z.jsx)(vV,{className:"h-5 w-5 text-muted-foreground/50"})}),(0,z.jsx)("p",{className:"text-sm",children:"Select a project to browse files."})]})});let H=g&&e?rx.api.getFileDownloadUrl(e,g,s,n):null;return(0,z.jsxs)("div",{className:"flex flex-col h-full",style:{"--files-tree-font-size":`${l.filesTreeFontSize}px`,"--files-content-font-size":`${l.filesContentFontSize}px`},children:[(0,z.jsx)(lx,{title:"Files",actions:(0,z.jsxs)("div",{className:"flex items-center gap-1",children:[(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:h,title:d?"Show file tree":"Hide file tree","aria-pressed":!d,children:d?(0,z.jsx)(_l,{className:"h-3.5 w-3.5"}):(0,z.jsx)(_a,{className:"h-3.5 w-3.5"})}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:`h-7 w-7 hover:text-foreground ${o?"text-foreground":"text-muted-foreground"}`,onClick:()=>a(e=>!e),title:o?"Hide hidden files":"Show hidden files","aria-pressed":o,children:o?(0,z.jsx)(_i,{className:"h-3.5 w-3.5"}):(0,z.jsx)(_n,{className:"h-3.5 w-3.5"})}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:F,disabled:!C,title:"Back",children:(0,z.jsx)(_c.ArrowLeft,{className:"h-3.5 w-3.5"})}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:T,disabled:!j,title:"Forward",children:(0,z.jsx)(_d,{className:"h-3.5 w-3.5"})}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:I,title:"Refresh",children:(0,z.jsx)(vV,{className:`h-3.5 w-3.5 ${_?"animate-spin":""}`})})]})}),(0,z.jsxs)(y_,{direction:"horizontal",autoSaveId:"files-panels",className:"flex-1",children:[(0,z.jsx)(_w,{ref:c,collapsible:!0,collapsedSize:0,defaultSize:33,minSize:20,onCollapse:()=>u(!0),onExpand:()=>u(!1),children:(0,z.jsxs)(y6,{shouldFilter:!1,className:"flex h-full flex-col bg-transparent",children:[(0,z.jsx)("div",{className:"border-b p-2",children:(0,z.jsxs)(yb,{children:[(0,z.jsx)(yS,{children:(0,z.jsx)(_o,{className:"h-3.5 w-3.5"})}),(0,z.jsx)(yk,{type:"search",name:"files-search",autoComplete:"off","data-1p-ignore":!0,"data-lpignore":"true","data-form-type":"other",readOnly:!0,onFocus:e=>{e.currentTarget.removeAttribute("readonly"),L.ensureLoaded()},placeholder:"Search files...",value:L.query,onChange:e=>L.setQuery(e.target.value)}),L.query&&(0,z.jsx)(yS,{align:"inline-end",children:(0,z.jsx)(yj,{size:"icon-xs","aria-label":"Clear search",onClick:()=>L.setQuery(""),children:(0,z.jsx)(t8,{className:"h-3.5 w-3.5"})})})]})}),L.query?(0,z.jsx)(y8,{className:"max-h-none flex-1",children:L.loading&&0===L.results.length?(0,z.jsxs)("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[(0,z.jsx)(rj,{className:"h-4 w-4 animate-spin"}),"Loading files…"]}):0===L.results.length?(0,z.jsx)("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"No matching files."}):(0,z.jsxs)(z.Fragment,{children:[L.results.map(e=>{let r=e.path.lastIndexOf("/"),s=r>=0?e.path.slice(0,r+1):"",i=r>=0?e.path.slice(r+1):e.path;return(0,z.jsxs)(y7,{value:e.path,onSelect:()=>O(e.path),className:"flex-col items-start gap-0 text-[length:var(--files-tree-font-size,14px)]!",children:[(0,z.jsx)("span",{className:"font-medium",children:i}),s&&(0,z.jsx)("span",{className:"w-full truncate text-xs text-muted-foreground",children:s})]},e.path)}),L.truncated&&(0,z.jsx)("div",{className:"px-2 py-2 text-xs text-muted-foreground",children:"Showing first 50,000 files — refine your search to narrow results."})]})}):(0,z.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,z.jsx)(bO,{entries:f,expandedDirs:m,directoryContents:p,loadingDirs:y,selectedFile:g,uploadingDirs:b,rootLoading:_,deletingPaths:w,onToggleDirectory:R,onSelectFile:A,onUploadFiles:P,onDeleteEntry:B})})]})}),(0,z.jsx)(yy,{withHandle:!0}),(0,z.jsx)(_w,{defaultSize:67,minSize:25,children:(0,z.jsx)("div",{className:"h-full overflow-hidden",children:(0,z.jsx)(ww,{filePath:g,fileContent:x,loading:v,downloadUrl:H,projectId:e,branch:s,target:n,scrollToLine:S?.line??null,scrollKey:S?.nonce,onJump:M,restoreScrollTop:E?.top??null,restoreScrollKey:E?.nonce,onScroll:D})})})]})]})}let wA=(0,$.createContext)(null),wM={openFile:()=>{},index:null};function wF(){return(0,$.useContext)(wA)??wM}let wT=wA.Provider,wP=0;function wB(e){let r=e.lastIndexOf("/");return r>=0?e.slice(r+1):e}let wL=[500,1e3,2e3,4e3,8e3];async function wI(e,r={}){let s=r.delaysMs??wL,i=r.sleep??(e=>new Promise(r=>setTimeout(r,e))),n=r.cancelled??(()=>!1);for(let r=0;;r++){if(n())return null;let o=null;try{o=await e()}catch{o=null}if(n())return null;if(o&&o.files.length>0||r>=s.length)return o;await i(s[r])}}function wO({projectId:e,selectedBranch:r,onMergeRequest:s,project:i,onExecutorModeChange:n,agentSlot:o,activateAgentTabNonce:a,diffCompareNonce:l,mergeTarget:c,active:d=!0}){let[u,h]=function(e,r){let s=`vibedeckx:activeTab:${e??"none"}:${r??"main"}`,[i,n]=(0,$.useState)(()=>localStorage.getItem(s)??"agent");return(0,$.useEffect)(()=>{n(localStorage.getItem(s)??"agent")},[s]),[i,(0,$.useCallback)(e=>{n(e),localStorage.setItem(s,e)},[s])]}(e,r),f=(0,$.useRef)(a);(0,$.useEffect)(()=>{void 0===a||f.current!==a&&(f.current=a,h("agent"))},[a,h]);let p=(0,$.useRef)(l);(0,$.useEffect)(()=>{void 0===l||p.current!==l&&(p.current=l,h("diff"))},[l,h]);let m=function({projectId:e,branch:r,target:s,enabled:i=!0}){let[n,o]=(0,$.useState)(null),a=(0,$.useRef)(0);return(0,$.useEffect)(()=>{if(o(null),!i||!e)return;let n=++a.current;wI(()=>rx.api.listProjectFiles(e,r,s),{cancelled:()=>n!==a.current}).then(e=>{n===a.current&&e&&o(function(e){let r=`idx-${++wP}`,s=new Set(e),i=new Map;for(let r of e){let e=wB(r),s=i.get(e);s?s.push(r):i.set(e,[r])}return{version:r,resolve(e){if(!e)return[];let r=e.replace(/^\/+/,"");if(!r)return[];if(r.includes("/")){if(s.has(r))return[r];let e=wB(r);return(i.get(e)??[]).filter(e=>e===r||e.endsWith("/"+r)||r.endsWith("/"+e))}return i.get(r)??[]}}}(e.files))})},[e,r,s,i]),n}({projectId:e,branch:r,target:i&&!i.path?"remote":void 0,enabled:d}),g=(0,$.useRef)(0),[x,v]=(0,$.useState)(null),_=(0,$.useCallback)((e,r=null)=>{h("files"),v({path:e,line:r,nonce:++g.current})},[h]),y=(0,$.useMemo)(()=>({openFile:_,index:m}),[_,m]);return(0,z.jsx)(wT,{value:y,children:(0,z.jsxs)("div",{className:"h-full flex flex-col",children:[(0,z.jsx)("div",{className:"flex items-center px-3 gap-4 border-b border-border",children:[{id:"agent",icon:oN,label:"Agent"},{id:"executors",icon:ok,label:"Executors"},{id:"diff",icon:rb,label:"Diff"},{id:"terminal",icon:cB,label:"Terminal"},{id:"preview",icon:r_,label:"Browser"},{id:"files",icon:rv,label:"Files"}].map(({id:e,icon:r,label:s})=>(0,z.jsxs)($.Fragment,{children:[(0,z.jsxs)("button",{onClick:()=>h(e),className:(0,ey.cn)("flex items-center gap-0.5 py-2.5 text-xs font-medium border-b-2 transition-colors",u===e?"text-foreground border-primary":"text-muted-foreground border-transparent hover:text-foreground/70"),children:[(0,z.jsx)(r,{className:"h-3.5 w-3.5"}),s]}),"agent"===e&&(0,z.jsx)("span",{className:"h-4 w-px bg-border/60 mx-1.5","aria-hidden":!0})]},e))}),(0,z.jsxs)("div",{className:"relative flex-1 overflow-hidden",children:[(0,z.jsx)("div",{className:(0,ey.cn)("absolute inset-0 overflow-hidden","agent"!==u&&"invisible pointer-events-none"),children:o}),(0,z.jsx)("div",{className:(0,ey.cn)("absolute inset-0 overflow-hidden","executors"!==u&&"hidden"),children:(0,z.jsx)(vq,{projectId:e,selectedBranch:r,project:i,onExecutorModeChange:n})}),(0,z.jsx)("div",{className:(0,ey.cn)("absolute inset-0 overflow-hidden","diff"!==u&&"hidden"),children:(0,z.jsx)(v5,{projectId:e,selectedBranch:r,onMergeRequest:s,project:i,mergeTarget:c,compareRequestNonce:l})}),(0,z.jsx)("div",{className:(0,ey.cn)("absolute inset-0 overflow-hidden","terminal"!==u&&"hidden"),children:(0,z.jsx)(v4,{projectId:e,selectedBranch:r,project:i})}),(0,z.jsx)("div",{className:(0,ey.cn)("absolute inset-0 overflow-hidden","preview"!==u&&"hidden"),children:(0,z.jsx)(_s,{projectId:e,selectedBranch:r,project:i})}),(0,z.jsx)("div",{className:(0,ey.cn)("absolute inset-0 overflow-hidden","files"!==u&&"hidden"),children:(0,z.jsx)(wR,{projectId:e,project:i,selectedBranch:r,navRequest:x})})]})]})})}var wz=Symbol.for("immer-nothing"),w$=Symbol.for("immer-draftable"),wW=Symbol.for("immer-state");function wH(e){throw Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var wU=Object.getPrototypeOf;function wK(e){return!!e&&!!e[wW]}function wq(e){return!!e&&(wG(e)||Array.isArray(e)||!!e[w$]||!!e.constructor?.[w$]||w0(e)||w1(e))}var wV=Object.prototype.constructor.toString(),wY=new WeakMap;function wG(e){if(!e||"object"!=typeof e)return!1;let r=Object.getPrototypeOf(e);if(null===r||r===Object.prototype)return!0;let s=Object.hasOwnProperty.call(r,"constructor")&&r.constructor;if(s===Object)return!0;if("function"!=typeof s)return!1;let i=wY.get(s);return void 0===i&&(i=Function.toString.call(s),wY.set(s,i)),i===wV}function wX(e,r,s=!0){0===wJ(e)?(s?Reflect.ownKeys(e):Object.keys(e)).forEach(s=>{r(s,e[s],e)}):e.forEach((s,i)=>r(i,s,e))}function wJ(e){let r=e[wW];return r?r.type_:Array.isArray(e)?1:w0(e)?2:3*!!w1(e)}function wZ(e,r){return 2===wJ(e)?e.has(r):Object.prototype.hasOwnProperty.call(e,r)}function wQ(e,r,s){let i=wJ(e);2===i?e.set(r,s):3===i?e.add(s):e[r]=s}function w0(e){return e instanceof Map}function w1(e){return e instanceof Set}function w2(e){return e.copy_||e.base_}function w5(e,r){if(w0(e))return new Map(e);if(w1(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let s=wG(e);if(!0!==r&&("class_only"!==r||s)){let r=wU(e);return null!==r&&s?{...e}:Object.assign(Object.create(r),e)}{let r=Object.getOwnPropertyDescriptors(e);delete r[wW];let s=Reflect.ownKeys(r);for(let i=0;i<s.length;i++){let n=s[i],o=r[n];!1===o.writable&&(o.writable=!0,o.configurable=!0),(o.get||o.set)&&(r[n]={configurable:!0,writable:!0,enumerable:o.enumerable,value:e[n]})}return Object.create(wU(e),r)}}function w3(e,r=!1){return w6(e)||wK(e)||!wq(e)||(wJ(e)>1&&Object.defineProperties(e,{set:w4,add:w4,clear:w4,delete:w4}),Object.freeze(e),r&&Object.values(e).forEach(e=>w3(e,!0))),e}var w4={value:function(){wH(2)}};function w6(e){return null===e||"object"!=typeof e||Object.isFrozen(e)}var w8={};function w7(e){let r=w8[e];return r||wH(0,e),r}function w9(e,r){r&&(w7("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=r)}function Se(e){St(e),e.drafts_.forEach(Ss),e.drafts_=null}function St(e){e===I&&(I=e.parent_)}function Sr(e){return I={drafts_:[],parent_:I,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Ss(e){let r=e[wW];0===r.type_||1===r.type_?r.revoke_():r.revoked_=!0}function Si(e,r){r.unfinalizedDrafts_=r.drafts_.length;let s=r.drafts_[0];return void 0!==e&&e!==s?(s[wW].modified_&&(Se(r),wH(4)),wq(e)&&(e=Sn(r,e),r.parent_||Sa(r,e)),r.patches_&&w7("Patches").generateReplacementPatches_(s[wW].base_,e,r.patches_,r.inversePatches_)):e=Sn(r,s,[]),Se(r),r.patches_&&r.patchListener_(r.patches_,r.inversePatches_),e!==wz?e:void 0}function Sn(e,r,s){if(w6(r))return r;let i=e.immer_.shouldUseStrictIteration(),n=r[wW];if(!n)return wX(r,(i,o)=>So(e,n,r,i,o,s),i),r;if(n.scope_!==e)return r;if(!n.modified_)return Sa(e,n.base_,!0),n.base_;if(!n.finalized_){n.finalized_=!0,n.scope_.unfinalizedDrafts_--;let r=n.copy_,o=r,a=!1;3===n.type_&&(o=new Set(r),r.clear(),a=!0),wX(o,(i,o)=>So(e,n,r,i,o,s,a),i),Sa(e,r,!1),s&&e.patches_&&w7("Patches").generatePatches_(n,s,e.patches_,e.inversePatches_)}return n.copy_}function So(e,r,s,i,n,o,a){if(null==n||"object"!=typeof n&&!a)return;let l=w6(n);if(!l||a){if(wK(n)){let a=Sn(e,n,o&&r&&3!==r.type_&&!wZ(r.assigned_,i)?o.concat(i):void 0);if(wQ(s,i,a),!wK(a))return;e.canAutoFreeze_=!1}else a&&s.add(n);if(wq(n)&&!l){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1||r&&r.base_&&r.base_[i]===n&&l)return;Sn(e,n),(!r||!r.scope_.parent_)&&"symbol"!=typeof i&&(w0(s)?s.has(i):Object.prototype.propertyIsEnumerable.call(s,i))&&Sa(e,n)}}}function Sa(e,r,s=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&w3(r,s)}var Sl={get(e,r){if(r===wW)return e;let s=w2(e);if(!wZ(s,r)){var i;let n;return i=e,(n=Su(s,r))?"value"in n?n.value:n.get?.call(i.draft_):void 0}let n=s[r];return e.finalized_||!wq(n)?n:n===Sd(e.base_,r)?(Sf(e),e.copy_[r]=Sp(n,e)):n},has:(e,r)=>r in w2(e),ownKeys:e=>Reflect.ownKeys(w2(e)),set(e,r,s){let i=Su(w2(e),r);if(i?.set)return i.set.call(e.draft_,s),!0;if(!e.modified_){let i=Sd(w2(e),r),n=i?.[wW];if(n&&n.base_===s)return e.copy_[r]=s,e.assigned_[r]=!1,!0;if((s===i?0!==s||1/s==1/i:s!=s&&i!=i)&&(void 0!==s||wZ(e.base_,r)))return!0;Sf(e),Sh(e)}return!!(e.copy_[r]===s&&(void 0!==s||r in e.copy_)||Number.isNaN(s)&&Number.isNaN(e.copy_[r]))||(e.copy_[r]=s,e.assigned_[r]=!0,!0)},deleteProperty:(e,r)=>(void 0!==Sd(e.base_,r)||r in e.base_?(e.assigned_[r]=!1,Sf(e),Sh(e)):delete e.assigned_[r],e.copy_&&delete e.copy_[r],!0),getOwnPropertyDescriptor(e,r){let s=w2(e),i=Reflect.getOwnPropertyDescriptor(s,r);return i?{writable:!0,configurable:1!==e.type_||"length"!==r,enumerable:i.enumerable,value:s[r]}:i},defineProperty(){wH(11)},getPrototypeOf:e=>wU(e.base_),setPrototypeOf(){wH(12)}},Sc={};function Sd(e,r){let s=e[wW];return(s?w2(s):e)[r]}function Su(e,r){if(!(r in e))return;let s=wU(e);for(;s;){let e=Object.getOwnPropertyDescriptor(s,r);if(e)return e;s=wU(s)}}function Sh(e){!e.modified_&&(e.modified_=!0,e.parent_&&Sh(e.parent_))}function Sf(e){e.copy_||(e.copy_=w5(e.base_,e.scope_.immer_.useStrictShallowCopy_))}function Sp(e,r){let s=w0(e)?w7("MapSet").proxyMap_(e,r):w1(e)?w7("MapSet").proxySet_(e,r):function(e,r){let s=Array.isArray(e),i={type_:+!!s,scope_:r?r.scope_:I,modified_:!1,finalized_:!1,assigned_:{},parent_:r,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},n=i,o=Sl;s&&(n=[i],o=Sc);let{revoke:a,proxy:l}=Proxy.revocable(n,o);return i.draft_=l,i.revoke_=a,l}(e,r);return(r?r.scope_:I).drafts_.push(s),s}wX(Sl,(e,r)=>{Sc[e]=function(){return arguments[0]=arguments[0][0],r.apply(this,arguments)}}),Sc.deleteProperty=function(e,r){return Sc.set.call(this,e,r,void 0)},Sc.set=function(e,r,s){return Sl.set.call(this,e[0],r,s,e[0])};var Sm=new class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(e,r,s)=>{let i;if("function"==typeof e&&"function"!=typeof r){let s=r;r=e;let i=this;return function(e=s,...n){return i.produce(e,e=>r.call(this,e,...n))}}if("function"!=typeof r&&wH(6),void 0!==s&&"function"!=typeof s&&wH(7),wq(e)){let n=Sr(this),o=Sp(e,void 0),a=!0;try{i=r(o),a=!1}finally{a?Se(n):St(n)}return w9(n,s),Si(i,n)}if(e&&"object"==typeof e)wH(1,e);else{if(void 0===(i=r(e))&&(i=e),i===wz&&(i=void 0),this.autoFreeze_&&w3(i,!0),s){let r=[],n=[];w7("Patches").generateReplacementPatches_(e,i,r,n),s(r,n)}return i}},this.produceWithPatches=(e,r)=>{let s,i;return"function"==typeof e?(r,...s)=>this.produceWithPatches(r,r=>e(r,...s)):[this.produce(e,r,(e,r)=>{s=e,i=r}),s,i]},"boolean"==typeof e?.autoFreeze&&this.setAutoFreeze(e.autoFreeze),"boolean"==typeof e?.useStrictShallowCopy&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),"boolean"==typeof e?.useStrictIteration&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){var r;wq(e)||wH(8),wK(e)&&(wK(r=e)||wH(10,r),e=function e(r){let s;if(!wq(r)||w6(r))return r;let i=r[wW],n=!0;if(i){if(!i.modified_)return i.base_;i.finalized_=!0,s=w5(r,i.scope_.immer_.useStrictShallowCopy_),n=i.scope_.immer_.shouldUseStrictIteration()}else s=w5(r,!0);return wX(s,(r,i)=>{wQ(s,r,e(i))},n),i&&(i.finalized_=!1),s}(r));let s=Sr(this),i=Sp(e,void 0);return i[wW].isManual_=!0,St(s),i}finishDraft(e,r){let s=e&&e[wW];s&&s.isManual_||wH(9);let{scope_:i}=s;return w9(i,r),Si(void 0,i)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,r){let s;for(s=r.length-1;s>=0;s--){let i=r[s];if(0===i.path.length&&"replace"===i.op){e=i.value;break}}s>-1&&(r=r.slice(s+1));let i=w7("Patches").applyPatches_;return wK(e)?i(e,r):this.produce(e,e=>i(e,r))}}().produce;let Sg="vibedeckx:placeholder-workspaces";function Sx(e){try{window.localStorage.setItem(Sg,JSON.stringify([...e]))}catch{}}let Sv=function(){try{let e=window.localStorage.getItem(Sg);if(!e)return new Map;let r=JSON.parse(e);if(!Array.isArray(r))return new Map;let s=new Map;for(let e of r)Array.isArray(e)&&"string"==typeof e[0]&&"number"==typeof e[1]?s.set(e[0],e[1]):"string"==typeof e&&s.set(e,Date.now());return s}catch{return new Map}}(),S_=new Set,Sy=new Map;function Sb(){for(let e of S_)e()}function Sw(e){return S_.add(e),()=>{S_.delete(e)}}function SS(){return Sv}function SC(){return Sy}function Sj(e,r,s){return`${e}:${r??""}:${s??""}`}function Sk(e){if(!Sv.has(e))return!1;let r=new Map(Sv);return r.delete(e),Sx(Sv=r),Sb(),!0}function SN(){return"localhost"===window.location.hostname&&"3000"===window.location.port?"http://localhost:5173":""}async function SD(e,r,s,i){let n=await (0,rx.authFetch)(`${SN()}/api/projects/${e}/agent-sessions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branch:r,permissionMode:s,agentType:i})});if(!n.ok)throw Error("Failed to load session");return n.json()}async function SE(e,r){let s=await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}/message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:r})});if(!s.ok){let r="";try{let e=await s.json();if(e.errorCode){let s=[`${e.errorCode}`];e.attempts&&s.push(`${e.attempts} attempts`),e.totalDurationMs&&s.push(`${(e.totalDurationMs/1e3).toFixed(1)}s`),r=` (${s.join(", ")})`}else e.error&&(r=` — ${e.error}`)}catch{}throw console.error(`[AgentSession] /message failed: status=${s.status}, sessionId=${e}, detail=${r}`),Error(`Failed to send message [${s.status}]${r}`)}}async function SR(e,r){let s=await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}/paste`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:r})});if(!s.ok){let r="";try{let e=await s.json();if(e.errorCode){let s=[`${e.errorCode}`];e.attempts&&s.push(`${e.attempts} attempts`),e.totalDurationMs&&s.push(`${(e.totalDurationMs/1e3).toFixed(1)}s`),r=` (${s.join(", ")})`}else e.error&&(r=` — ${e.error}`)}catch{}throw console.error(`[AgentSession] /paste failed: status=${s.status}, sessionId=${e}, detail=${r}`),Error(`Failed to upload paste [${s.status}]${r}`)}return s.json()}async function SA(e,r){if(!(await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}/restart`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentType:r})})).ok)throw Error("Failed to restart session")}async function SM(e,r){let s=await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}/agent-type`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentType:r})});if(!s.ok){let e="";try{let r=await s.json();r.error&&(e=r.error)}catch{}throw Error(e||`Failed to switch agent [${s.status}]`)}}async function SF(e){if(!(await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}/stop`,{method:"POST"})).ok)throw Error("Failed to stop session")}async function ST(e,r){if(!(await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}/switch-mode`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:r})})).ok)throw Error("Failed to switch mode")}async function SP(e,r){if(!(await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}/accept-plan`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planContent:r})})).ok)throw Error("Failed to accept plan")}let SB=new Map;function SL(e,r,s){return`${e}:${r??""}:${s??"latest"}`}async function SI(e){let r=await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}`);if(!r.ok)throw Error(`Session ${e} not found`);return r.json()}let SO=(0,ew.default)("user",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]),Sz=(0,ew.default)("wrench",[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]]),S$=(0,ew.default)("brain",[["path",{d:"M12 18V5",key:"adv99a"}],["path",{d:"M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4",key:"1e3is1"}],["path",{d:"M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5",key:"1gqd8o"}],["path",{d:"M17.997 5.125a4 4 0 0 1 2.526 5.77",key:"iwvgf7"}],["path",{d:"M18 18a4 4 0 0 0 2-7.464",key:"efp6ie"}],["path",{d:"M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517",key:"1gq6am"}],["path",{d:"M6 18a4 4 0 0 1-2-7.464",key:"k1g0md"}],["path",{d:"M6.003 5.125a4 4 0 0 0-2.526 5.77",key:"q97ue3"}]]),SW=(0,ew.default)("circle-alert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]),SH=(0,ew.default)("circle-question-mark",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]),SU=(0,ew.default)("file-check",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m9 15 2 2 4-4",key:"1grp1n"}]]),SK=(0,ew.default)("folder-search",[["path",{d:"M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1",key:"1bw5m7"}],["path",{d:"m21 21-1.9-1.9",key:"1g2n9r"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}]]),Sq=(0,ew.default)("workflow",[["rect",{width:"8",height:"8",x:"3",y:"3",rx:"2",key:"by2w9f"}],["path",{d:"M7 11v4a2 2 0 0 0 2 2h4",key:"xkn7yn"}],["rect",{width:"8",height:"8",x:"13",y:"13",rx:"2",key:"1cgmvn"}]]),SV=(0,ew.default)("file-pen-line",[["path",{d:"m18.226 5.226-2.52-2.52A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-.351",key:"1k2beg"}],["path",{d:"M21.378 12.626a1 1 0 0 0-3.004-3.004l-4.01 4.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z",key:"2t3380"}],["path",{d:"M8 18h1",key:"13wk12"}]]),SY=(0,ew.default)("file-plus-corner",[["path",{d:"M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35",key:"17jvcc"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M14 19h6",key:"bvotb8"}],["path",{d:"M17 16v6",key:"18yu1i"}]]),SG=(0,ew.default)("earth",[["path",{d:"M21.54 15H17a2 2 0 0 0-2 2v4.54",key:"1djwo0"}],["path",{d:"M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17",key:"1tzkfa"}],["path",{d:"M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05",key:"14pb5j"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]),SX=(0,ew.default)("shield-alert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);var aR=aE,bJ=aE;let SJ=RegExp("(?<![\\w./-])([\\w-]+(?:[./][\\w-]+)+)(?::(\\d+)(?::\\d+)?|#L(\\d+)(?:-L?\\d+)?)?","g"),SZ=/\[([^\]\n]*)\]\(\s*([^)\s]+?)\s*\)/g;function SQ(e){return e.includes("/")||/\.[A-Za-z0-9]+$/.test(e)}function S0(e){let r=e.trim();if(!r)return null;let s=/^(.*?)(?::(\d+)(?::\d+)?|#L(\d+)(?:-L?\d+)?)?$/.exec(r);if(!s||!s[1])return null;let i=s[1];return/^[a-z][a-z0-9+.-]*:/i.test(i)||i.startsWith("//")||i.startsWith("#")?null:{rawPath:i,line:s[2]?Number(s[2]):s[3]?Number(s[3]):null}}function S1(e){let r=r=>e.index?e.index.resolve(r):[];function s(e,r,s){return{type:"element",tagName:"a",properties:{className:["file-ref"],href:"#file-ref",dataFilePaths:JSON.stringify(e),...null!=r?{dataFileLine:String(r)}:{}},children:s}}return e=>{!function e(i,n=!1){if(!i.children)return;let o=n||"pre"===i.tagName,a=[];for(let n of i.children)"text"===n.type?o?a.push(n):a.push(...function(e){let i=function(e){let r,s=[],i=[];for(SZ.lastIndex=0;null!==(r=SZ.exec(e));){let e=S0(r[2]);if(!e||!SQ(e.rawPath))continue;let n=r.index,o=r.index+r[0].length;s.push({start:n,end:o,rawPath:e.rawPath,line:e.line,display:r[1]||void 0}),i.push([n,o])}for(SJ.lastIndex=0;null!==(r=SJ.exec(e));){let e=r.index;if(i.some(([r,s])=>e>=r&&e<s))continue;let n=r[1];if(!SQ(n))continue;let o=r[2]?Number(r[2]):r[3]?Number(r[3]):null;s.push({start:e,end:e+r[0].length,rawPath:n,line:o})}return s.sort((e,r)=>e.start-r.start),s}(e);if(0===i.length)return[{type:"text",value:e}];let n=[],o=0,a=!1;for(let l of i){let i=r(l.rawPath);if(0===i.length)continue;l.start>o&&n.push({type:"text",value:e.slice(o,l.start)});let c=l.display??e.slice(l.start,l.end);n.push(s(i,l.line,[{type:"text",value:c}])),o=l.end,a=!0}return a?(o<e.length&&n.push({type:"text",value:e.slice(o)}),n):[{type:"text",value:e}]}(n.value??"")):"element"===n.type&&"pre"===n.tagName?(e(n,!0),a.push(n)):"element"!==n.type||"a"!==n.tagName||o?(e(n,o),a.push(n)):a.push(...function(e){let i=S0(String(e.properties?.href??""));if(!i)return[e];let n=r(i.rawPath);return 0===n.length?e.children??[]:[s(n,i.line,e.children??[])]}(n));i.children=a}(e)}}let S2="text-primary underline decoration-dotted underline-offset-2 cursor-pointer hover:decoration-solid";function S5({node:e,children:r,href:s,...i}){let{openFile:n}=wF(),o=e?.properties?.dataFilePaths;if(!o)return"string"==typeof s&&s.startsWith("#")?(0,z.jsx)("a",{href:s,...i,children:r}):(0,z.jsx)("a",{href:s,target:"_blank",rel:"noreferrer noopener",...i,children:r});let a=[];try{a=JSON.parse(o)}catch{a=[]}let l=e?.properties?.dataFileLine,c=null!=l?Number(l):null;return a.length<=1?(0,z.jsx)("a",{href:"#",className:S2,onClick:e=>{e.preventDefault(),a[0]&&n(a[0],c)},children:r}):(0,z.jsx)(S3,{paths:a,line:c,children:r})}function S3({paths:e,line:r,children:s}){let{openFile:i}=wF();return(0,z.jsxs)(of,{children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsx)("a",{href:"#",className:S2,onClick:e=>e.preventDefault(),children:s})}),(0,z.jsxs)(om,{align:"start",className:"max-w-md",children:[(0,z.jsxs)(oy,{children:[e.length," matching files"]}),e.map(e=>(0,z.jsx)(og,{className:"font-mono text-xs",onSelect:()=>i(e,r),children:e},e))]})]})}let S4=(0,$.memo)(function({children:e}){let{index:r}=wF(),{harden:s,...i}=bJ.e,n=[...Object.values(i),[S1,{index:r}],...s?[s]:[]];return(0,z.jsx)(aR.i,{className:"size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",rehypePlugins:n,components:{a:S5},children:e},r?.version??"no-file-ref-index")});function S6({input:e,messageIndex:r}){let{sendMessage:s,messages:i}=ke(),n=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&Array.isArray(r.questions)&&r.questions.length>0&&r.questions.every(e=>"string"==typeof e.question&&"string"==typeof e.header&&Array.isArray(e.options)))return r}catch{}return null}(e),o=i[r+1],a=o?.type==="user",l=a?o.content:"",c="string"==typeof l?l:l.filter(e=>"text"===e.type).map(e=>e.text).join("\n");if(!n){let r="string"==typeof e?e:JSON.stringify(e,null,2);return(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:r.length>500?r.substring(0,500)+"...":r})}return a?(0,z.jsx)(S8,{questions:n.questions,answeredText:c}):(0,z.jsx)(S7,{questions:n.questions,sendMessage:s})}function S8({questions:e,answeredText:r}){return(0,z.jsx)("div",{className:"space-y-3 mt-2",children:e.map((e,s)=>(0,z.jsxs)("div",{className:"rounded-lg border bg-muted/30 p-3",children:[(0,z.jsx)("div",{className:"flex items-center gap-2 mb-1.5",children:(0,z.jsx)(sy,{variant:"secondary",className:"text-[10px]",children:e.header})}),(0,z.jsx)("p",{className:"text-sm text-muted-foreground mb-2",children:e.question}),(0,z.jsxs)("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-400",children:[(0,z.jsx)(rS,{className:"h-4 w-4"}),(0,z.jsx)("span",{className:"font-medium",children:r})]})]},s))})}function S7({questions:e,sendMessage:r}){let[s,i]=(0,$.useState)(new Map),[n,o]=(0,$.useState)(new Map),[a,l]=(0,$.useState)(new Set),[c,d]=(0,$.useState)(!1);async function u(){let i=[];for(let r=0;r<e.length;r++)if(a.has(r)){let e=n.get(r)?.trim();e&&i.push(e)}else{let e=s.get(r);e&&e.size>0&&i.push(Array.from(e).join(", "))}if(i.length>0){d(!0);try{await r(i.join("\n"))}finally{d(!1)}}}let h=e.some((e,r)=>{if(a.has(r))return!!n.get(r)?.trim();let i=s.get(r);return i&&i.size>0});return(0,z.jsxs)("div",{className:"space-y-4 mt-2",children:[e.map((e,r)=>{let c=s.get(r)||new Set,d=n.get(r)||"",u=a.has(r);return(0,z.jsxs)("div",{className:"rounded-lg border bg-card p-3",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,z.jsx)(SH,{className:"h-3.5 w-3.5 text-violet-500"}),(0,z.jsx)(sy,{variant:"secondary",className:"text-[10px]",children:e.header})]}),(0,z.jsx)("p",{className:"text-sm font-medium mb-3",children:e.question}),(0,z.jsxs)("div",{className:"grid gap-2",children:[e.options.map(s=>{let n=c.has(s.label)&&!u;return(0,z.jsx)(W.Button,{variant:n?"default":"outline",className:(0,ey.cn)("h-auto py-2 px-3 justify-start text-left whitespace-normal",n&&"ring-2 ring-primary/50"),onClick:()=>{var n,o;return n=s.label,o=e.multiSelect,void(i(e=>{let s=new Map(e),i=new Set(s.get(r)||[]);return o?i.has(n)?i.delete(n):i.add(n):i.has(n)?i.clear():(i.clear(),i.add(n)),s.set(r,i),s}),l(e=>{let s=new Set(e);return s.delete(r),s}))},children:(0,z.jsxs)("div",{children:[(0,z.jsx)("span",{className:"font-medium text-sm",children:s.label}),s.description&&(0,z.jsx)("span",{className:"block text-xs text-muted-foreground mt-0.5",children:s.description})]})},s.label)}),(0,z.jsx)("div",{className:"flex items-center gap-2 mt-1",children:(0,z.jsx)(ro,{placeholder:"Other...",value:d,onChange:e=>{var s;return s=e.target.value,void(o(e=>new Map(e).set(r,s)),s&&(i(e=>{let s=new Map(e);return s.set(r,new Set),s}),l(e=>new Set(e).add(r))))},className:"text-sm"})})]})]},r)}),(0,z.jsxs)(W.Button,{onClick:u,disabled:!h||c,size:"sm",className:"active:scale-95 transition-transform",children:[c&&(0,z.jsx)(rj,{className:"h-3.5 w-3.5 animate-spin"}),c?"Submitting...":"Submit"]})]})}function S9(e){try{return JSON.parse(e)}catch{return null}}function Ce({input:e,messageIndex:r}){let{messages:s,acceptPlan:i,permissionMode:n,agentType:o}=ke(),[a,l]=(0,$.useState)(!0),[c,d]=(0,$.useState)(!1),u=function(e,r,s){let i="string"==typeof e?S9(e):e;if(i&&"object"==typeof i&&"plan"in i){let e=i.plan;if(e)return e}if("claude-code"===s)for(let e=r.length-1;e>=0;e--){let s=r[e];if("tool_use"===s.type&&"Write"===s.tool){let e="string"==typeof s.input?S9(s.input):s.input;if(e&&"object"==typeof e&&e.file_path?.includes(".claude/plans/")&&e.content)return e.content}}return"Plan written to file"}(e,s,o),h=(0,$.useCallback)(async()=>{d(!0);try{await i(u)}catch{d(!1)}},[i,u]),f="edit"===n,p=!1,m="";for(let e=r+1;e<s.length;e++){let r=s[e];if(r?.type==="user"){p=!0;let e=r.content??"";m="string"==typeof e?e:e.filter(e=>"text"===e.type).map(e=>e.text).join("\n");break}}return(f&&!p&&(p=!0),f||p)?(0,z.jsxs)("div",{className:"space-y-2 mt-2",children:[f?(0,z.jsxs)(sy,{variant:"default",className:"bg-green-600 hover:bg-green-700 text-white",children:[(0,z.jsx)(rS,{className:"h-3 w-3 mr-1"}),"Plan Accepted"]}):(0,z.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,z.jsx)(gY,{className:"h-3.5 w-3.5"}),(0,z.jsxs)("span",{children:["Feedback sent: ",m.length>100?m.substring(0,100)+"...":m]})]}),(0,z.jsxs)("details",{open:!f,children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"View Plan"}),(0,z.jsx)("div",{className:"mt-2 rounded-lg border p-3 bg-muted/30",children:(0,z.jsx)("div",{className:"prose prose-sm dark:prose-invert max-w-none break-words [&_pre]:overflow-x-auto [&_pre]:max-w-full [&_code]:break-all [&_p]:break-words",style:{fontSize:"var(--conv-font-size, 14px)"},children:(0,z.jsx)(wt,{children:u})})})]})]}):(0,z.jsxs)("div",{className:"space-y-3 mt-2",children:[(0,z.jsxs)("div",{className:"rounded-lg border p-3 bg-card",children:[(0,z.jsxs)("button",{onClick:()=>l(!a),className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground mb-2 block",children:[a?"Collapse":"Expand"," Plan"]}),a&&(0,z.jsx)("div",{className:"prose prose-sm dark:prose-invert max-w-none break-words [&_pre]:overflow-x-auto [&_pre]:max-w-full [&_code]:break-all [&_p]:break-words max-h-96 overflow-y-auto",style:{fontSize:"var(--conv-font-size, 14px)"},children:(0,z.jsx)(wt,{children:u})})]}),(0,z.jsxs)(W.Button,{onClick:h,disabled:c,className:"bg-green-600 hover:bg-green-700 text-white",size:"sm",children:[c?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):(0,z.jsx)(ru,{className:"h-3.5 w-3.5 mr-1.5"}),c?"Accepting Plan...":"Accept Plan & Start Editing"]})]})}function Ct({requestId:e,command:r,cwd:s,messageIndex:i}){let{messages:n,sessionId:o}=ke(),[a,l]=(0,$.useState)(!1),[c,d]=(0,$.useState)(null),u=!1;for(let e=i+1;e<n.length;e++)if(n[e]?.type==="user"){u=!0;break}c&&(u=!0);let h=(0,$.useCallback)(async r=>{if(o){l(!0),d(r);try{await (0,rx.sendApprovalResponse)(o,e,r)}catch{d(null),l(!1)}}},[o,e]);return u?(0,z.jsxs)("div",{className:"space-y-2 mt-2",children:[(0,z.jsxs)("div",{className:"rounded-lg border bg-muted/30 p-3",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,z.jsx)(ok,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,z.jsx)("span",{className:"text-xs text-muted-foreground",children:"Command"})]}),(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:r||"(empty)"}),s&&(0,z.jsxs)("p",{className:"text-xs text-muted-foreground mt-1",children:["cwd: ",s]})]}),(0,z.jsxs)(sy,{variant:"default",className:"decline"===c?"bg-red-600 hover:bg-red-700 text-white":"bg-green-600 hover:bg-green-700 text-white",children:[(0,z.jsx)(rS,{className:"h-3 w-3 mr-1"}),"decline"===c?"Denied":"Allowed"]})]}):(0,z.jsxs)("div",{className:"space-y-2 mt-2",children:[(0,z.jsxs)("div",{className:"rounded-lg border bg-card p-3",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,z.jsx)(ok,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,z.jsx)("span",{className:"text-xs text-muted-foreground",children:"Command"})]}),(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:r||"(empty)"}),s&&(0,z.jsxs)("p",{className:"text-xs text-muted-foreground mt-1",children:["cwd: ",s]})]}),(0,z.jsxs)("div",{className:"flex gap-2",children:[(0,z.jsxs)(W.Button,{onClick:()=>h("accept"),disabled:a,className:"bg-green-600 hover:bg-green-700 text-white",size:"sm",children:[a&&"accept"===c?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,z.jsx)(rS,{className:"h-3.5 w-3.5 mr-1"}),"Allow"]}),(0,z.jsxs)(W.Button,{onClick:()=>h("decline"),disabled:a,variant:"destructive",size:"sm",children:[a&&"decline"===c?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,z.jsx)(rC,{className:"h-3.5 w-3.5 mr-1"}),"Deny"]})]})]})}function Cr({requestId:e,changes:r,messageIndex:s}){let{messages:i,sessionId:n}=ke(),[o,a]=(0,$.useState)(!1),[l,c]=(0,$.useState)(null),d=!1;for(let e=s+1;e<i.length;e++)if(i[e]?.type==="user"){d=!0;break}l&&(d=!0);let u=(0,$.useCallback)(async r=>{if(n){a(!0),c(r);try{await (0,rx.sendApprovalResponse)(n,e,r)}catch{c(null),a(!1)}}},[n,e]),h=r??[],f=()=>(0,z.jsx)("div",{className:"rounded-lg border bg-muted/30 p-3 space-y-2",children:0===h.length?(0,z.jsx)("p",{className:"text-xs text-muted-foreground",children:"No file changes"}):h.map((e,r)=>(0,z.jsxs)("div",{children:[(0,z.jsxs)("div",{className:"flex items-center gap-2",children:[(0,z.jsx)(bt,{className:"h-3 w-3 text-muted-foreground flex-shrink-0"}),(0,z.jsx)("code",{className:"text-xs break-all",children:e.path}),(0,z.jsx)(sy,{variant:"secondary",className:`text-[10px] ${function(e){switch(e){case"added":case"add":return"bg-green-500/10 text-green-600";case"deleted":case"delete":return"bg-red-500/10 text-red-600";default:return"bg-blue-500/10 text-blue-600"}}(e.kind)}`,children:function(e){switch(e){case"added":case"add":return"added";case"deleted":case"delete":return"deleted";default:return"modified"}}(e.kind)})]}),e.diff&&(0,z.jsxs)("details",{className:"mt-1",children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"View diff"}),(0,z.jsx)("pre",{className:"mt-1 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.diff.split("\n").map((e,r)=>{let s="";return e.startsWith("+")?s="bg-green-500/10 text-green-700 dark:text-green-400":e.startsWith("-")&&(s="bg-red-500/10 text-red-700 dark:text-red-400"),(0,z.jsx)("div",{className:s,children:e},r)})})]})]},r))});return d?(0,z.jsxs)("div",{className:"space-y-2 mt-2",children:[f(),(0,z.jsxs)(sy,{variant:"default",className:"decline"===l?"bg-red-600 hover:bg-red-700 text-white":"bg-green-600 hover:bg-green-700 text-white",children:[(0,z.jsx)(rS,{className:"h-3 w-3 mr-1"}),"decline"===l?"Denied":"Allowed"]})]}):(0,z.jsxs)("div",{className:"space-y-2 mt-2",children:[f(),(0,z.jsxs)("div",{className:"flex gap-2",children:[(0,z.jsxs)(W.Button,{onClick:()=>u("accept"),disabled:o,className:"bg-green-600 hover:bg-green-700 text-white",size:"sm",children:[o&&"accept"===l?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,z.jsx)(rS,{className:"h-3.5 w-3.5 mr-1"}),"Allow"]}),(0,z.jsxs)(W.Button,{onClick:()=>u("decline"),disabled:o,variant:"destructive",size:"sm",children:[o&&"decline"===l?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,z.jsx)(rC,{className:"h-3.5 w-3.5 mr-1"}),"Deny"]})]})]})}let Cs=(0,ew.default)("circle-plus",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"M12 8v8",key:"napkw2"}]]),Ci=(0,ew.default)("badge",[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}]]);function Cn({status:e,className:r}){switch(e){case"completed":return(0,z.jsx)(rS,{className:(0,ey.cn)("h-4 w-4 text-green-500",r)});case"in_progress":return(0,z.jsx)(rj,{className:(0,ey.cn)("h-4 w-4 text-cyan-500 animate-spin",r)});case"pending":default:return(0,z.jsx)(rw,{className:(0,ey.cn)("h-4 w-4 text-muted-foreground",r)});case"deleted":return(0,z.jsx)(rC,{className:(0,ey.cn)("h-4 w-4 text-red-400",r)})}}function Co(e,r){try{let s="string"==typeof e?JSON.parse(e):e;if(s&&"object"==typeof s&&r(s))return s}catch{}return null}function Ca({input:e}){let r="string"==typeof e?e:JSON.stringify(e,null,2);return(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:r.length>500?r.substring(0,500)+"...":r})}function Cl({input:e}){let r=Co(e,e=>Array.isArray(e.todos)&&e.todos.length>0);return r?(0,z.jsx)("div",{className:"mt-2 space-y-1",children:r.todos.map((e,r)=>(0,z.jsxs)("div",{className:"flex items-start gap-2 py-0.5",children:[(0,z.jsx)(Cn,{status:e.status,className:"mt-0.5 flex-shrink-0"}),(0,z.jsxs)("div",{className:"min-w-0",children:[(0,z.jsx)("span",{className:(0,ey.cn)("text-sm break-words","completed"===e.status&&"line-through text-muted-foreground"),children:e.subject??e.content??"Untitled task"}),"in_progress"===e.status&&e.activeForm&&(0,z.jsx)("span",{className:"block text-xs italic text-cyan-500",children:e.activeForm})]})]},e.id??r))}):(0,z.jsx)(Ca,{input:e})}function Cc({input:e}){let r=Co(e,e=>"string"==typeof e.subject);return r?(0,z.jsxs)("div",{className:"mt-2 flex items-start gap-2",children:[(0,z.jsx)(Cs,{className:"h-4 w-4 text-cyan-500 mt-0.5 flex-shrink-0"}),(0,z.jsxs)("div",{className:"min-w-0",children:[(0,z.jsx)("span",{className:"text-sm font-medium break-words",children:r.subject}),r.description&&(0,z.jsx)("span",{className:"block text-xs text-muted-foreground mt-0.5 break-words",children:r.description.length>200?r.description.substring(0,200)+"...":r.description})]})]}):(0,z.jsx)(Ca,{input:e})}function Cd({input:e}){let r=Co(e,e=>"string"==typeof e.taskId);return r?(0,z.jsxs)("div",{className:"mt-2 flex items-start gap-2 flex-wrap",children:[r.status?(0,z.jsx)(Cn,{status:r.status,className:"mt-0.5 flex-shrink-0"}):(0,z.jsx)(_d,{className:"h-4 w-4 text-cyan-500 mt-0.5 flex-shrink-0"}),(0,z.jsxs)("span",{className:"text-sm break-words",children:["Task #",r.taskId,r.status&&(0,z.jsxs)(z.Fragment,{children:[" ",(0,z.jsx)(_d,{className:"inline h-3 w-3 text-muted-foreground mx-0.5"})," ",r.status]}),r.subject&&(0,z.jsxs)("span",{className:"text-muted-foreground",children:[" — ",r.subject]})]}),r.addBlockedBy&&r.addBlockedBy.length>0&&(0,z.jsx)("div",{className:"flex gap-1 mt-1 w-full pl-6",children:r.addBlockedBy.map(e=>(0,z.jsxs)(sy,{variant:"outline",className:"text-[10px]",children:[(0,z.jsx)(Ci,{className:"h-2.5 w-2.5 mr-0.5"}),"blocked by #",e]},e))}),r.addBlocks&&r.addBlocks.length>0&&(0,z.jsx)("div",{className:"flex gap-1 mt-1 w-full pl-6",children:r.addBlocks.map(e=>(0,z.jsxs)(sy,{variant:"outline",className:"text-[10px]",children:[(0,z.jsx)(Ci,{className:"h-2.5 w-2.5 mr-0.5"}),"blocks #",e]},e))})]}):(0,z.jsx)(Ca,{input:e})}function Cu(){return(0,z.jsxs)("div",{className:"mt-2 flex items-center gap-2 text-sm text-muted-foreground",children:[(0,z.jsx)(rj,{className:"h-4 w-4 animate-spin text-cyan-500"}),(0,z.jsx)("span",{children:"Listing tasks..."})]})}function Ch({input:e}){let r=Co(e,e=>"string"==typeof e.taskId);return r?(0,z.jsxs)("div",{className:"mt-2 flex items-center gap-2 text-sm text-muted-foreground",children:[(0,z.jsx)(rj,{className:"h-4 w-4 animate-spin text-cyan-500"}),(0,z.jsxs)("span",{children:["Fetching task #",r.taskId,"..."]})]}):(0,z.jsx)(Ca,{input:e})}function Cf({output:e}){let r=function(e){try{let r=JSON.parse(e);if(Array.isArray(r))return r.filter(e=>e.id&&e.subject).map(e=>({id:String(e.id),subject:String(e.subject),status:e.status||"pending",owner:e.owner?String(e.owner):void 0,blockedBy:Array.isArray(e.blockedBy)?e.blockedBy.map(String):void 0}));let s=r.tasks??r.items??r.data;if(Array.isArray(s))return s.filter(e=>e.id&&e.subject).map(e=>({id:String(e.id),subject:String(e.subject),status:e.status||"pending",owner:e.owner?String(e.owner):void 0,blockedBy:Array.isArray(e.blockedBy)?e.blockedBy.map(String):void 0}))}catch{let r=e.trim().split("\n").filter(Boolean),s=[];for(let e of r){let r=e.match(/^#?(\d+)[\s.:\-]+\[?(completed|in_progress|pending|deleted)\]?\s+(.+)/i);r&&s.push({id:r[1],status:r[2].toLowerCase(),subject:r[3].trim()})}if(s.length>0)return s}return null}(e);return r?(0,z.jsx)("div",{className:"mt-1 space-y-1",children:r.map(e=>(0,z.jsxs)("div",{className:"flex items-start gap-2 py-0.5",children:[(0,z.jsx)(Cn,{status:e.status,className:"mt-0.5 flex-shrink-0"}),(0,z.jsxs)("div",{className:"min-w-0 flex items-center gap-1.5 flex-wrap",children:[(0,z.jsxs)("span",{className:"text-xs text-muted-foreground",children:["#",e.id]}),(0,z.jsx)("span",{className:(0,ey.cn)("text-sm break-words","completed"===e.status&&"line-through text-muted-foreground"),children:e.subject}),e.blockedBy&&e.blockedBy.length>0&&(0,z.jsx)(sy,{variant:"outline",className:"text-[10px]",children:"blocked"})]})]},e.id))}):null}function Cp({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.file_path)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let{file_path:s,offset:i,limit:n}=r,o=s.split("/"),a=o.pop()||s,l=o.join("/"),c=null!=i||null!=n,d="";if(c){let e=i??1;d=null!=n?`Lines ${e}\u2013${e+n-1}`:`From line ${e}`}return(0,z.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,z.jsxs)("div",{className:"min-w-0",children:[(0,z.jsx)("span",{className:"text-sm font-medium break-all",children:a}),l&&(0,z.jsx)("p",{className:"text-xs text-muted-foreground truncate",title:s,children:l})]}),c&&(0,z.jsx)(sy,{variant:"outline",className:"text-xs shrink-0",children:d})]})}function Cm({output:e}){let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["File contents (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function Cg({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.file_path)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let{file_path:s,content:i}=r,n=s.split("/"),o=n.pop()||s,a=n.join("/"),l=i.split("\n").length;return(0,z.jsxs)("div",{className:"space-y-1",children:[(0,z.jsxs)("div",{className:"min-w-0",children:[(0,z.jsx)("span",{className:"text-sm font-medium break-all",children:o}),a&&(0,z.jsx)("p",{className:"text-xs text-muted-foreground truncate",title:s,children:a})]}),(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Content (",l," ",1===l?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:i.length>1e3?i.substring(0,1e3)+"...":i})]})]})}function Cx({output:e}){return e&&""!==e.trim()?(0,z.jsxs)("details",{children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"Result"}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]}):(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"File written"})}function Cv({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.command)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let{command:s,description:i,timeout:n}=r;return(0,z.jsxs)("div",{className:"space-y-1",children:[i&&(0,z.jsx)("p",{className:"text-xs text-muted-foreground",children:i}),(0,z.jsxs)("div",{className:"flex items-start gap-2",children:[(0,z.jsxs)("pre",{className:"flex-1 min-w-0 bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:[(0,z.jsx)("span",{className:"text-muted-foreground select-none",children:"$ "}),s]}),null!=n&&(0,z.jsx)(sy,{variant:"outline",className:"text-xs shrink-0 mt-1",children:function(e){if(e>=6e4){let r=e/6e4;return`${r%1==0?r:r.toFixed(1)}m`}return`${e/1e3}s`}(n)})]})]})}function C_({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No output"});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Output (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function Cy({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.pattern)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let s=[];return r.path&&s.push({label:r.path}),r.glob&&s.push({label:r.glob}),r.type&&s.push({label:`.${r.type}`}),r.output_mode&&"files_with_matches"!==r.output_mode&&s.push({label:r.output_mode}),null!=r.context&&s.push({label:`context: ${r.context}`}),null!=r["-C"]&&s.push({label:`context: ${r["-C"]}`}),null!=r["-B"]&&s.push({label:`before: ${r["-B"]}`}),null!=r["-A"]&&s.push({label:`after: ${r["-A"]}`}),r["-i"]&&s.push({label:"case-insensitive"}),r.multiline&&s.push({label:"multiline"}),null!=r.head_limit&&s.push({label:`limit: ${r.head_limit}`}),null!=r.offset&&s.push({label:`offset: ${r.offset}`}),(0,z.jsxs)("div",{className:"space-y-1",children:[(0,z.jsx)("div",{className:"flex items-start gap-2",children:(0,z.jsxs)("pre",{className:"flex-1 min-w-0 bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:[(0,z.jsx)("span",{className:"text-muted-foreground select-none",children:"/ "}),r.pattern]})}),s.length>0&&(0,z.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap",children:s.map((e,r)=>(0,z.jsx)(sy,{variant:"outline",className:"text-xs",children:e.label},r))})]})}function Cb({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No matches"});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Results (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function Cw({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.pattern)return r;return null}catch{return null}}(e);return r?(0,z.jsxs)("div",{className:"space-y-1",children:[(0,z.jsx)("div",{className:"flex items-start gap-2",children:(0,z.jsx)("pre",{className:"flex-1 min-w-0 bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:r.pattern})}),r.path&&(0,z.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap",children:(0,z.jsx)(sy,{variant:"outline",className:"text-xs",children:r.path})})]}):(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)})}function CS({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No matches"});let r=e.trim().split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:[r," ",1===r?"file":"files"," found"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}let CC={Explore:"Explore",Bash:"Bash",Plan:"Plan","general-purpose":"General","code-simplifier":"Simplify","superpowers:code-reviewer":"Review","memory-leak-detector":"Memory","directory-structure-validator":"Structure","tech-docs-finder":"Docs","claude-code-guide":"Guide","statusline-setup":"Status"};function Cj({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.description&&"string"==typeof r.subagent_type)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let{description:s,subagent_type:i,prompt:n,model:o,max_turns:a,resume:l,run_in_background:c}=r,d=[];return d.push({label:CC[i]||i}),o&&d.push({label:o}),null!=a&&d.push({label:`${a} turns`}),c&&d.push({label:"background"}),l&&d.push({label:"resume"}),(0,z.jsxs)("div",{className:"space-y-1",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,z.jsx)("span",{className:"text-sm",children:s}),d.map((e,r)=>(0,z.jsx)(sy,{variant:"outline",className:"text-xs shrink-0",children:e.label},r))]}),n&&(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Prompt (",n.length>1e3?`${Math.round(n.length/1e3)}k chars`:`${n.length} chars`,")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:n.length>1e3?n.substring(0,1e3)+"...":n})]})]})}function Ck({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No output"});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Agent result (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function CN(e,r){return e.length>r?e.substring(0,r)+"...":e}function CD({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.file_path&&"string"==typeof r.old_string&&"string"==typeof r.new_string)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let{file_path:s,old_string:i,new_string:n,replace_all:o}=r,a=s.split("/"),l=a.pop()||s,c=a.join("/"),d=i.split("\n").length,u=n.split("\n").length;return(0,z.jsxs)("div",{className:"space-y-1",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,z.jsxs)("div",{className:"min-w-0",children:[(0,z.jsx)("span",{className:"text-sm font-medium break-all",children:l}),c&&(0,z.jsx)("p",{className:"text-xs text-muted-foreground truncate",title:s,children:c})]}),(0,z.jsx)(sy,{variant:"outline",className:"text-xs shrink-0",children:d===u?`${d} ${1===d?"line":"lines"}`:`${d}\u2192${u} lines`}),o&&(0,z.jsx)(sy,{variant:"outline",className:"text-xs shrink-0",children:"replace all"})]}),(0,z.jsxs)("details",{children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"Diff"}),(0,z.jsxs)("div",{className:"mt-1 text-xs rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full",children:[(0,z.jsxs)("pre",{className:"bg-red-500/10 p-1.5 rounded-t whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:[(0,z.jsx)("span",{className:"text-red-500 select-none",children:"- "}),CN(i,500)]}),(0,z.jsxs)("pre",{className:"bg-green-500/10 p-1.5 rounded-b whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:[(0,z.jsx)("span",{className:"text-green-500 select-none",children:"+ "}),CN(n,500)]})]})]})]})}function CE({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No output"});if(e.length<=200)return(0,z.jsx)("p",{className:"text-xs text-muted-foreground",children:e});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Result (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function CR({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.url&&"string"==typeof r.prompt)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let{display:s,href:i}=function(e){try{let r=new URL(e),s="/"===r.pathname?"":r.pathname,i=r.hostname+s;return{display:i.length>80?i.substring(0,77)+"...":i,href:e}}catch{return{display:e.length>80?e.substring(0,77)+"...":e,href:e}}}(r.url),n=r.prompt.length>150?r.prompt.substring(0,147)+"...":r.prompt;return(0,z.jsxs)("div",{className:"space-y-1",children:[(0,z.jsx)("a",{href:i,target:"_blank",rel:"noopener noreferrer",className:"block text-xs font-mono text-blue-500 hover:underline truncate",children:s}),(0,z.jsxs)("p",{className:"text-xs text-muted-foreground",children:['"',n,'"']})]})}function CA({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No content fetched"});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Response (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function CM({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.query)return r;return null}catch{return null}}(e);return r?(0,z.jsxs)("div",{className:"space-y-1.5",children:[(0,z.jsx)("p",{className:"text-xs font-mono bg-muted/50 px-2 py-1 rounded break-words",children:r.query}),r.allowed_domains&&r.allowed_domains.length>0&&(0,z.jsxs)("div",{className:"flex items-center gap-1 flex-wrap",children:[(0,z.jsx)("span",{className:"text-xs text-muted-foreground",children:"only:"}),r.allowed_domains.map(e=>(0,z.jsx)(sy,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:e},e))]}),r.blocked_domains&&r.blocked_domains.length>0&&(0,z.jsxs)("div",{className:"flex items-center gap-1 flex-wrap",children:[(0,z.jsx)("span",{className:"text-xs text-muted-foreground",children:"exclude:"}),r.blocked_domains.map(e=>(0,z.jsx)(sy,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:e},e))]})]}):(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)})}function CF({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No search results"});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Results (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function CT({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.skill)return r;return null}catch{return null}}(e);return r?(0,z.jsxs)("div",{className:"space-y-1",children:[(0,z.jsx)("p",{className:"text-xs font-mono text-pink-500",children:r.skill}),r.args&&(0,z.jsxs)("p",{className:"text-xs text-muted-foreground truncate",children:["args: ",r.args]})]}):(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)})}function CP({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No output"});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Loaded (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function CB({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.task_id)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let{task_id:s,block:i,timeout:n}=r,o=[];return o.push({label:!1===i?"non-blocking":"blocking"}),null!=n&&o.push({label:`${Math.round(n/1e3)}s`}),(0,z.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,z.jsx)("code",{className:"text-sm bg-muted/50 px-1.5 py-0.5 rounded",children:s}),o.map((e,r)=>(0,z.jsx)(sy,{variant:"outline",className:"text-xs shrink-0",children:e.label},r))]})}function CL({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No output"});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Task output (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function CI({input:e}){let r="string"==typeof e?function(e){try{return JSON.parse(e)}catch{return null}}(e):e,s=r?.changes??[];return 0===s.length?(0,z.jsx)("p",{className:"text-xs text-muted-foreground",children:"No file changes"}):(0,z.jsx)("div",{className:"space-y-2 mt-1",children:s.map((e,r)=>(0,z.jsxs)("div",{children:[(0,z.jsxs)("div",{className:"flex items-center gap-2",children:[(0,z.jsx)(bt,{className:"h-3 w-3 text-muted-foreground flex-shrink-0"}),(0,z.jsx)("code",{className:"text-xs break-all",children:e.path}),(0,z.jsx)(sy,{variant:"secondary",className:`text-[10px] ${function(e){switch(e){case"added":case"add":return"bg-green-500/10 text-green-600";case"deleted":case"delete":return"bg-red-500/10 text-red-600";default:return"bg-blue-500/10 text-blue-600"}}(e.kind)}`,children:function(e){switch(e){case"added":case"add":return"added";case"deleted":case"delete":return"deleted";default:return"modified"}}(e.kind)})]}),e.diff&&(0,z.jsxs)("details",{className:"mt-1",children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"View diff"}),(0,z.jsx)("pre",{className:"mt-1 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.diff.split("\n").map((e,r)=>{let s="";return e.startsWith("+")?s="bg-green-500/10 text-green-700 dark:text-green-400":e.startsWith("-")&&(s="bg-red-500/10 text-red-700 dark:text-red-400"),(0,z.jsx)("div",{className:s,children:e},r)})})]})]},r))})}function CO({output:e}){let r=e.toLowerCase(),s="text-muted-foreground";return r.includes("completed")||r.includes("success")?s="text-green-600 dark:text-green-400":r.includes("failed")||r.includes("error")?s="text-red-600 dark:text-red-400":(r.includes("declined")||r.includes("denied"))&&(s="text-amber-600 dark:text-amber-400"),(0,z.jsx)("p",{className:`text-xs ${s}`,children:e})}function Cz({path:e,size:r}){let s;return(0,z.jsxs)("span",{className:"inline-flex items-center gap-1.5 rounded-md border border-border bg-muted/60 px-1.5 py-0.5 text-xs font-mono align-baseline",title:e,children:[(0,z.jsx)(bt,{className:"w-3 h-3 text-muted-foreground shrink-0"}),(0,z.jsx)("span",{className:"truncate max-w-[18ch]",children:(s=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\")))>=0?e.slice(s+1):e}),(0,z.jsx)("span",{className:"text-muted-foreground",children:function(e){if(e<1024)return`${e} B`;let r=e/1024;return r<10?`${r.toFixed(1)} KB`:r<1024?`${Math.round(r)} KB`:`${(r/1024).toFixed(1)} MB`}(r)})]})}let C$=/<vpaste path="([^"]+)" size="(\d+)" \/>/g;function CW({message:e,messageIndex:r}){let s=function(e,r){switch(e.type){case"user":return(0,z.jsx)(CU,{content:e.content});case"assistant":return(0,z.jsx)(CK,{content:e.content,agentType:e.agentType});case"tool_use":return(0,z.jsx)(Cq,{tool:e.tool,input:e.input,messageIndex:r});case"tool_result":return(0,z.jsx)(CV,{tool:e.tool,output:e.output});case"thinking":return(0,z.jsx)(CY,{content:e.content});case"error":return(0,z.jsx)(CG,{message:e.message});case"system":return(0,z.jsx)(CX,{content:e.content});case"approval_request":return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-amber-500/10 flex items-center justify-center",children:(0,z.jsx)(SX,{className:"w-4 h-4 text-amber-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-amber-500 mb-1",children:"command"===e.requestType?"Command Approval":"File Change Approval"}),"command"===e.requestType?(0,z.jsx)(Ct,{requestId:e.requestId,command:e.command,cwd:e.cwd,messageIndex:r}):(0,z.jsx)(Cr,{requestId:e.requestId,changes:e.changes,messageIndex:r})]})]});default:return null}}(e,r);return s?(0,z.jsxs)("div",{className:"group relative",children:[s,(0,z.jsx)("span",{className:"pointer-events-none absolute right-0 top-3 text-xs tabular-nums text-muted-foreground opacity-0 transition-opacity duration-150 group-hover:opacity-100",children:function(e){let r=new Date(e),s=new Date,i=r.getFullYear()===s.getFullYear()&&r.getMonth()===s.getMonth()&&r.getDate()===s.getDate(),n=r.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1});if(i)return n;let o=r.toLocaleDateString(void 0,{year:"numeric",month:"2-digit",day:"2-digit"});return`${o} ${n}`}(e.timestamp)})]}):null}function CH(e){let r=function(e){let r,s=[],i=0,n=RegExp(C$.source,"g");for(;null!==(r=n.exec(e));)r.index>i&&s.push({kind:"text",text:e.slice(i,r.index)}),s.push({kind:"chip",path:r[1],size:Number(r[2])}),i=r.index+r[0].length;return i<e.length&&s.push({kind:"text",text:e.slice(i)}),s}(e);return 1===r.length&&"text"===r[0].kind?(0,z.jsx)("span",{className:"whitespace-pre-wrap break-words",children:e??""}):(0,z.jsx)("div",{className:"text-foreground max-w-none break-words",style:{fontSize:"var(--conv-font-size, 14px)"},children:r.map((e,r)=>"text"===e.kind?(0,z.jsx)("span",{className:"whitespace-pre-wrap break-words",children:e.text},r):(0,z.jsx)(Cz,{path:e.path,size:e.size},r))})}function CU({content:e}){return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-primary/10 flex items-center justify-center",children:(0,z.jsx)(SO,{className:"w-3.5 h-3.5 text-primary"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-foreground mb-1",children:"You"}),(0,z.jsx)("div",{className:"text-foreground max-w-none break-words",style:{fontSize:"var(--conv-font-size, 14px)"},children:"string"==typeof e?CH(e):e.map((e,r)=>"text"===e.type?(0,z.jsx)($.Fragment,{children:CH(e.text)},r):(0,z.jsx)("img",{src:`data:${e.mediaType};base64,${e.data}`,alt:"Attached image",className:"max-w-sm rounded-lg mt-2"},r))})]})]})}function CK({content:e,agentType:r}){let s=function(){try{return ke().agentType}catch{return"claude-code"}}(),i="codex"===(r??s),[n,o]=(0,$.useState)(!1);return(0,z.jsxs)("div",{className:"group flex gap-3 py-3",children:[(0,z.jsx)("div",{className:`flex-shrink-0 w-7 h-7 rounded-lg ${i?"bg-green-500/10":"bg-violet-500/10"} flex items-center justify-center`,children:(0,z.jsx)(oN,{className:`w-3.5 h-3.5 ${i?"text-green-500":"text-violet-500"}`})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,z.jsx)("p",{className:`text-sm font-medium ${i?"text-green-500":"text-violet-500"}`,children:i?"Codex":"Claude"}),(0,z.jsx)("button",{type:"button",onClick:()=>o(e=>!e),title:n?"View rendered":"View source","aria-label":n?"View rendered":"View source","aria-pressed":n,className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity text-muted-foreground hover:text-foreground",children:n?(0,z.jsx)(_i,{className:"w-3.5 h-3.5"}):(0,z.jsx)(bW,{className:"w-3.5 h-3.5"})})]}),n?(0,z.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words bg-muted/50 rounded-md p-3 overflow-x-auto text-foreground select-text",children:e??""}):(0,z.jsx)("div",{className:"text-foreground prose prose-sm dark:prose-invert max-w-none break-words [&_pre]:overflow-x-auto [&_pre]:max-w-full [&_code]:break-all [&_p]:break-words",style:{fontSize:"var(--conv-font-size, 14px)"},children:(0,z.jsx)(S4,{children:e??""})})]})]})}function Cq({tool:e,input:r,messageIndex:s}){if("AskUserQuestion"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-violet-500/10 flex items-center justify-center",children:(0,z.jsx)(SH,{className:"w-4 h-4 text-violet-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-violet-500 mb-1",children:"Question"}),(0,z.jsx)(S6,{input:r,messageIndex:s})]})]});if("ExitPlanMode"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-green-500/10 flex items-center justify-center",children:(0,z.jsx)(SU,{className:"w-4 h-4 text-green-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-green-500 mb-1",children:"Plan Ready"}),(0,z.jsx)(Ce,{input:r,messageIndex:s})]})]});let i={TodoWrite:{label:"Tasks",ui:(0,z.jsx)(Cl,{input:r})},TaskCreate:{label:"Create Task",ui:(0,z.jsx)(Cc,{input:r})},TaskUpdate:{label:"Update Task",ui:(0,z.jsx)(Cd,{input:r})},TaskList:{label:"Task List",ui:(0,z.jsx)(Cu,{})},TaskGet:{label:"Get Task",ui:(0,z.jsx)(Ch,{input:r})}}[e];if(i)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-cyan-500/10 flex items-center justify-center",children:(0,z.jsx)(aM,{className:"w-4 h-4 text-cyan-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-cyan-500 mb-1",children:i.label}),i.ui]})]});if("Read"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-sky-500/10 flex items-center justify-center",children:(0,z.jsx)(bt,{className:"w-4 h-4 text-sky-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-sky-500 mb-1",children:"Read File"}),(0,z.jsx)(Cp,{input:r})]})]});if("Edit"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-sky-500/10 flex items-center justify-center",children:(0,z.jsx)(SV,{className:"w-4 h-4 text-sky-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-sky-500 mb-1",children:"Edit File"}),(0,z.jsx)(CD,{input:r})]})]});if("Write"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-sky-500/10 flex items-center justify-center",children:(0,z.jsx)(SY,{className:"w-4 h-4 text-sky-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-sky-500 mb-1",children:"Write File"}),(0,z.jsx)(Cg,{input:r})]})]});if("Bash"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-emerald-500/10 flex items-center justify-center",children:(0,z.jsx)(ok,{className:"w-4 h-4 text-emerald-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-emerald-500 mb-1",children:"Run Command"}),(0,z.jsx)(Cv,{input:r})]})]});if("Grep"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-orange-500/10 flex items-center justify-center",children:(0,z.jsx)(_o,{className:"w-4 h-4 text-orange-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-orange-500 mb-1",children:"Search"}),(0,z.jsx)(Cy,{input:r})]})]});if("Glob"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-teal-500/10 flex items-center justify-center",children:(0,z.jsx)(SK,{className:"w-4 h-4 text-teal-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-teal-500 mb-1",children:"Glob"}),(0,z.jsx)(Cw,{input:r})]})]});if("Task"===e||"Agent"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-purple-500/10 flex items-center justify-center",children:(0,z.jsx)(Sq,{className:"w-4 h-4 text-purple-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-purple-500 mb-1",children:"Agent"}),(0,z.jsx)(Cj,{input:r})]})]});if("TaskOutput"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-purple-500/10 flex items-center justify-center",children:(0,z.jsx)(Sq,{className:"w-4 h-4 text-purple-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-purple-500 mb-1",children:"Task Output"}),(0,z.jsx)(CB,{input:r})]})]});if("WebFetch"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-blue-500/10 flex items-center justify-center",children:(0,z.jsx)(r_,{className:"w-4 h-4 text-blue-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-blue-500 mb-1",children:"Fetch Web Page"}),(0,z.jsx)(CR,{input:r})]})]});if("WebSearch"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-indigo-500/10 flex items-center justify-center",children:(0,z.jsx)(SG,{className:"w-4 h-4 text-indigo-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-indigo-500 mb-1",children:"Web Search"}),(0,z.jsx)(CM,{input:r})]})]});if("Skill"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-pink-500/10 flex items-center justify-center",children:(0,z.jsx)(cP,{className:"w-4 h-4 text-pink-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-pink-500 mb-1",children:"Skill"}),(0,z.jsx)(CT,{input:r})]})]});if("FileChange"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-sky-500/10 flex items-center justify-center",children:(0,z.jsx)(SV,{className:"w-4 h-4 text-sky-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-sky-500 mb-1",children:"File Changes"}),(0,z.jsx)(CI,{input:r})]})]});let n="string"==typeof r?r:JSON.stringify(r,null,2);return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-amber-500/10 flex items-center justify-center",children:(0,z.jsx)(Sz,{className:"w-4 h-4 text-amber-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsxs)("p",{className:"text-sm font-medium text-amber-500 mb-1 break-words",children:["Tool: ",e]}),(0,z.jsxs)("details",{open:!0,children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"Input"}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:n.length>500?n.substring(0,500)+"...":n})]})]})]})}function CV({tool:e,output:r}){if(["TodoWrite","TaskCreate","TaskUpdate","TaskList","TaskGet"].includes(e)){let s="TaskList"===e?(0,z.jsx)(Cf,{output:r}):null;return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsxs)("p",{className:"text-xs text-muted-foreground mb-1",children:["Result (",e,")"]}),s||(0,z.jsxs)("details",{children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"Output"}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:r.length>1e3?r.substring(0,1e3)+"...":r})]})]})})}if("Read"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(Cm,{output:r})})});if("Edit"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(CE,{output:r})})});if("Write"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(Cx,{output:r})})});if("Bash"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(C_,{output:r})})});if("Grep"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(Cb,{output:r})})});if("Glob"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(CS,{output:r})})});if("Task"===e||"Agent"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(Ck,{output:r})})});if("TaskOutput"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(CL,{output:r})})});if("WebFetch"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(CA,{output:r})})});if("WebSearch"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(CF,{output:r})})});if("Skill"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(CP,{output:r})})});if("FileChange"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(CO,{output:r})})});let s=r.length>200;return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsxs)("p",{className:"text-xs text-muted-foreground mb-1",children:["Result",e?` (${e})`:""]}),(0,z.jsxs)("details",{className:(0,ey.cn)(!s&&"open"),children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"Output"}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:r.length>1e3?r.substring(0,1e3)+"...":r})]})]})})}function CY({content:e}){let r=e??"",s=r.trim().length>0,i=s?r.length>500?r.substring(0,500)+"...":r:"Reasoning unavailable — this model does not expose its thinking content.";return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-blue-500/10 flex items-center justify-center",children:(0,z.jsx)(S$,{className:"w-3.5 h-3.5 text-blue-500"})}),(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsxs)("details",{children:[(0,z.jsx)("summary",{className:"text-xs font-medium text-blue-500 cursor-pointer hover:underline",children:"Thinking..."}),(0,z.jsx)("div",{className:`mt-2 whitespace-pre-wrap break-words bg-blue-500/5 p-2 rounded-md overflow-hidden ${s?"text-muted-foreground":"text-muted-foreground/70 italic"}`,style:{fontSize:"var(--conv-font-size, 12px)"},children:i})]})})]})}function CG({message:e}){return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-red-500/10 flex items-center justify-center",children:(0,z.jsx)(SW,{className:"w-3.5 h-3.5 text-red-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-red-500 mb-1",children:"Error"}),(0,z.jsx)("p",{className:"text-red-500/80 break-words whitespace-pre-wrap",style:{fontSize:"var(--conv-font-size, 14px)"},children:e})]})]})}function CX({content:e}){return(0,z.jsxs)("div",{className:"flex gap-3 py-2",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-gray-500/10 flex items-center justify-center",children:(0,z.jsx)(gU,{className:"w-3.5 h-3.5 text-gray-500"})}),(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)("p",{className:"text-muted-foreground break-words",style:{fontSize:"var(--conv-font-size, 12px)"},children:e??""})})]})}let CJ=(0,ew.default)("arrow-down",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]),CZ={damping:.7,stiffness:.05,mass:1.25},CQ=1e3/60,C0=!1;function C1(e,r){let s=(0,$.useCallback)(r=>(s.current=r,e(r)),r);return s}globalThis.document?.addEventListener("mousedown",()=>{C0=!0}),globalThis.document?.addEventListener("mouseup",()=>{C0=!1}),globalThis.document?.addEventListener("click",()=>{C0=!1});let C2=new Map;function C5(...e){let r={...CZ},s=!1;for(let i of e){if("instant"===i){s=!0;continue}"object"==typeof i&&(s=!1,r.damping=i.damping??r.damping,r.stiffness=i.stiffness??r.stiffness,r.mass=i.mass??r.mass)}let i=JSON.stringify(r);return C2.has(i)||C2.set(i,Object.freeze(r)),s?"instant":C2.get(i)}let C3=(0,$.createContext)(null),C4="undefined"!=typeof window?$.useLayoutEffect:$.useEffect;function C6({instance:e,children:r,resize:s,initial:i,mass:n,damping:o,stiffness:a,targetScrollTop:l,contextRef:c,...d}){let u=(0,$.useRef)(null),h=((e={})=>{let[r,s]=(0,$.useState)(!1),[i,n]=(0,$.useState)(!1!==e.initial),[o,a]=(0,$.useState)(!1),l=(0,$.useRef)(null);l.current=e;let c=(0,$.useCallback)(()=>{if(!C0)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let r=e.getRangeAt(0);return r.commonAncestorContainer.contains(x.current)||x.current?.contains(r.commonAncestorContainer)},[]),d=(0,$.useCallback)(e=>{h.isAtBottom=e,n(e)},[]),u=(0,$.useCallback)(e=>{h.escapedFromLock=e,s(e)},[]),h=(0,$.useMemo)(()=>{let s;return{escapedFromLock:r,isAtBottom:i,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return x.current?.scrollTop??0},set scrollTop(scrollTop){x.current&&(x.current.scrollTop=scrollTop,h.ignoreScrollToTop=x.current.scrollTop)},get targetScrollTop(){if(!x.current||!v.current)return 0;return x.current.scrollHeight-1-x.current.clientHeight},get calculatedTargetScrollTop(){if(!x.current||!v.current)return 0;let{targetScrollTop:r}=this;if(!e.targetScrollTop)return r;if(s?.targetScrollTop===r)return s.calculatedScrollTop;let i=Math.max(Math.min(e.targetScrollTop(r,{scrollElement:x.current,contentElement:v.current}),r),0);return s={targetScrollTop:r,calculatedScrollTop:i},requestAnimationFrame(()=>{s=void 0}),i},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=70}}},[]),f=(0,$.useCallback)((e={})=>{let r;"string"==typeof e&&(e={animation:e}),e.preserveScrollPosition||d(!0);let s=Date.now()+(Number(e.wait)||0),i=C5(l.current,e.animation),{ignoreEscapes:n=!1}=e,o=h.calculatedTargetScrollTop;e.duration instanceof Promise?e.duration.finally(()=>{r=Date.now()}):r=s+(e.duration??0);let a=async()=>{let e=new Promise(requestAnimationFrame).then(()=>{if(!h.isAtBottom)return h.animation=void 0,!1;let{scrollTop:d}=h,u=performance.now(),p=(u-(h.lastTick??u))/CQ;if(h.animation||(h.animation={behavior:i,promise:e,ignoreEscapes:n}),h.animation.behavior===i&&(h.lastTick=u),c()||s>Date.now())return a();if(d<Math.min(o,h.calculatedTargetScrollTop)){if(h.animation?.behavior===i){if("instant"===i)return h.scrollTop=h.calculatedTargetScrollTop,a();h.velocity=(i.damping*h.velocity+i.stiffness*h.scrollDifference)/i.mass,h.accumulated+=h.velocity*p,h.scrollTop+=h.accumulated,h.scrollTop!==d&&(h.accumulated=0)}return a()}return r>Date.now()?(o=h.calculatedTargetScrollTop,a()):(h.animation=void 0,h.scrollTop<h.calculatedTargetScrollTop)?f({animation:C5(l.current,l.current.resize),ignoreEscapes:n,duration:Math.max(0,r-Date.now())||void 0}):h.isAtBottom});return e.then(e=>(requestAnimationFrame(()=>{h.animation||(h.lastTick=void 0,h.velocity=0)}),e))};return(!0!==e.wait&&(h.animation=void 0),h.animation?.behavior===i)?h.animation.promise:a()},[d,c,h]),p=(0,$.useCallback)(()=>{u(!0),d(!1)},[u,d]),m=(0,$.useCallback)(({target:e})=>{if(e!==x.current)return;let{scrollTop:r,ignoreScrollToTop:s}=h,{lastScrollTop:i=r}=h;h.lastScrollTop=r,h.ignoreScrollToTop=void 0,s&&s>r&&(i=s),a(h.isNearBottom),setTimeout(()=>{if(h.resizeDifference||r===s)return;if(c()){u(!0),d(!1);return}let e=r>i,n=r<i;if(h.animation?.ignoreEscapes){h.scrollTop=i;return}n&&(u(!0),d(!1)),e&&u(!1),!h.escapedFromLock&&h.isNearBottom&&d(!0)},1)},[u,d,c,h]),g=(0,$.useCallback)(({target:e,deltaY:r})=>{let s=e;for(;!["scroll","auto"].includes(getComputedStyle(s).overflow);){if(!s.parentElement)return;s=s.parentElement}s===x.current&&r<0&&x.current.scrollHeight>x.current.clientHeight&&!h.animation?.ignoreEscapes&&(u(!0),d(!1))},[u,d,h]),x=C1(e=>{x.current?.removeEventListener("scroll",m),x.current?.removeEventListener("wheel",g),e?.addEventListener("scroll",m,{passive:!0}),e?.addEventListener("wheel",g,{passive:!0})},[]),v=C1(e=>{let r;h.resizeObserver?.disconnect(),e&&(h.resizeObserver=new ResizeObserver(([e])=>{let{height:s}=e.contentRect,i=s-(r??s);if(h.resizeDifference=i,h.scrollTop>h.targetScrollTop&&(h.scrollTop=h.targetScrollTop),a(h.isNearBottom),i>=0){let e=C5(l.current,r?l.current.resize:l.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:"instant"===e?void 0:350})}else h.isNearBottom&&(u(!1),d(!0));r=s,requestAnimationFrame(()=>{setTimeout(()=>{h.resizeDifference===i&&(h.resizeDifference=0)},1)})}),h.resizeObserver?.observe(e))},[]);return{contentRef:v,scrollRef:x,scrollToBottom:f,stopScroll:p,isAtBottom:i||o,isNearBottom:o,escapedFromLock:r,state:h}})({mass:n,damping:o,stiffness:a,resize:s,initial:i,targetScrollTop:$.useCallback((e,r)=>{let s=y?.targetScrollTop??l;return s?.(e,r)??e},[l])}),{scrollRef:f,contentRef:p,scrollToBottom:m,stopScroll:g,isAtBottom:x,escapedFromLock:v,state:_}=e??h,y=(0,$.useMemo)(()=>({scrollToBottom:m,stopScroll:g,scrollRef:f,isAtBottom:x,escapedFromLock:v,contentRef:p,state:_,get targetScrollTop(){return u.current},set targetScrollTop(targetScrollTop){u.current=targetScrollTop}}),[m,x,p,f,g,v,_]);return(0,$.useImperativeHandle)(c,()=>y,[y]),C4(()=>{f.current&&"visible"===getComputedStyle(f.current).overflow&&(f.current.style.overflow="auto")},[]),$.createElement(C3.Provider,{value:y},$.createElement("div",{...d},"function"==typeof r?r(y):r))}function C8(){let e=(0,$.useContext)(C3);if(!e)throw Error("use-stick-to-bottom component context must be used within a StickToBottom component");return e}(C6||(C6={})).Content=function({children:e,scrollClassName:r,...s}){let i=C8();return $.createElement("div",{ref:i.scrollRef,style:{height:"100%",width:"100%",scrollbarGutter:"stable both-edges"},className:r},$.createElement("div",{...s,ref:i.contentRef},"function"==typeof e?e(i):e))};let C7=({className:e,...r})=>(0,z.jsx)(C6,{className:(0,ey.cn)("relative flex-1 overflow-y-hidden",e),initial:"smooth",resize:"smooth",role:"log",...r}),C9=({className:e,...r})=>(0,z.jsx)(C6.Content,{className:(0,ey.cn)("flex flex-col gap-8 p-4",e),...r}),je=({className:e,...r})=>{let{isAtBottom:s,scrollToBottom:i}=C8(),n=(0,$.useCallback)(()=>{i()},[i]);return!s&&(0,z.jsx)(W.Button,{className:(0,ey.cn)("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",e),onClick:n,size:"icon",type:"button",variant:"outline",...r,children:(0,z.jsx)(CJ,{className:"size-4"})})};var jt="HoverCard",[jr,js]=K(jt,[iz]),ji=iz(),[jn,jo]=jr(jt),ja=e=>{let{__scopeHoverCard:r,children:s,open:i,defaultOpen:n,onOpenChange:o,openDelay:a=700,closeDelay:l=300}=e,c=ji(r),d=$.useRef(0),u=$.useRef(0),h=$.useRef(!1),f=$.useRef(!1),[p,m]=G({prop:i,defaultProp:n??!1,onChange:o,caller:jt}),g=$.useCallback(()=>{clearTimeout(u.current),d.current=window.setTimeout(()=>m(!0),a)},[a,m]),x=$.useCallback(()=>{clearTimeout(d.current),h.current||f.current||(u.current=window.setTimeout(()=>m(!1),l))},[l,m]),v=$.useCallback(()=>m(!1),[m]);return $.useEffect(()=>()=>{clearTimeout(d.current),clearTimeout(u.current)},[]),(0,z.jsx)(jn,{scope:r,open:p,onOpenChange:m,onOpen:g,onClose:x,onDismiss:v,hasSelectionRef:h,isPointerDownOnContentRef:f,children:(0,z.jsx)(iH,{...c,children:s})})};ja.displayName=jt;var jl="HoverCardTrigger",jc=$.forwardRef((e,r)=>{let{__scopeHoverCard:s,...i}=e,n=jo(jl,s),o=ji(s);return(0,z.jsx)(iK,{asChild:!0,...o,children:(0,z.jsx)(er.a,{"data-state":n.open?"open":"closed",...i,ref:r,onPointerEnter:q(e.onPointerEnter,jx(n.onOpen)),onPointerLeave:q(e.onPointerLeave,jx(n.onClose)),onFocus:q(e.onFocus,n.onOpen),onBlur:q(e.onBlur,n.onClose),onTouchStart:q(e.onTouchStart,e=>e.preventDefault())})})});jc.displayName=jl;var jd="HoverCardPortal",[ju,jh]=jr(jd,{forceMount:void 0}),jf=e=>{let{__scopeHoverCard:r,forceMount:s,children:i,container:n}=e,o=jo(jd,r);return(0,z.jsx)(ju,{scope:r,forceMount:s,children:(0,z.jsx)(Z,{present:s||o.open,children:(0,z.jsx)(eW,{asChild:!0,container:n,children:i})})})};jf.displayName=jd;var jp="HoverCardContent",jm=$.forwardRef((e,r)=>{let s=jh(jp,e.__scopeHoverCard),{forceMount:i=s.forceMount,...n}=e,o=jo(jp,e.__scopeHoverCard);return(0,z.jsx)(Z,{present:i||o.open,children:(0,z.jsx)(jg,{"data-state":o.open?"open":"closed",...n,onPointerEnter:q(e.onPointerEnter,jx(o.onOpen)),onPointerLeave:q(e.onPointerLeave,jx(o.onClose)),ref:r})})});jm.displayName=jp;var jg=$.forwardRef((e,r)=>{let{__scopeHoverCard:s,onEscapeKeyDown:i,onPointerDownOutside:n,onFocusOutside:o,onInteractOutside:a,...l}=e,c=jo(jp,s),d=ji(s),u=$.useRef(null),h=(0,U.useComposedRefs)(r,u),[f,p]=$.useState(!1);return $.useEffect(()=>{if(f){let e=document.body;return O=e.style.userSelect||e.style.webkitUserSelect,e.style.userSelect="none",e.style.webkitUserSelect="none",()=>{e.style.userSelect=O,e.style.webkitUserSelect=O}}},[f]),$.useEffect(()=>{if(u.current){let e=()=>{p(!1),c.isPointerDownOnContentRef.current=!1,setTimeout(()=>{document.getSelection()?.toString()!==""&&(c.hasSelectionRef.current=!0)})};return document.addEventListener("pointerup",e),()=>{document.removeEventListener("pointerup",e),c.hasSelectionRef.current=!1,c.isPointerDownOnContentRef.current=!1}}},[c.isPointerDownOnContentRef,c.hasSelectionRef]),$.useEffect(()=>{u.current&&(function(e){let r=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});for(;s.nextNode();)r.push(s.currentNode);return r})(u.current).forEach(e=>e.setAttribute("tabindex","-1"))}),(0,z.jsx)(eR,{asChild:!0,disableOutsidePointerEvents:!1,onInteractOutside:a,onEscapeKeyDown:i,onPointerDownOutside:n,onFocusOutside:q(o,e=>{e.preventDefault()}),onDismiss:c.onDismiss,children:(0,z.jsx)(iG,{...d,...l,onPointerDown:q(l.onPointerDown,e=>{e.currentTarget.contains(e.target)&&p(!0),c.hasSelectionRef.current=!1,c.isPointerDownOnContentRef.current=!0}),ref:h,style:{...l.style,userSelect:f?"text":void 0,WebkitUserSelect:f?"text":void 0,"--radix-hover-card-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-hover-card-content-available-width":"var(--radix-popper-available-width)","--radix-hover-card-content-available-height":"var(--radix-popper-available-height)","--radix-hover-card-trigger-width":"var(--radix-popper-anchor-width)","--radix-hover-card-trigger-height":"var(--radix-popper-anchor-height)"}})})});function jx(e){return r=>"touch"===r.pointerType?void 0:e()}function jv({...e}){return(0,z.jsx)(ja,{"data-slot":"hover-card",...e})}function j_({...e}){return(0,z.jsx)(jc,{"data-slot":"hover-card-trigger",...e})}function jy({className:e,align:r="center",sideOffset:s=4,...i}){return(0,z.jsx)(jf,{"data-slot":"hover-card-portal",children:(0,z.jsx)(jm,{"data-slot":"hover-card-content",align:r,sideOffset:s,className:(0,ey.cn)("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[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 z-50 w-64 origin-(--radix-hover-card-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",e),...i})})}$.forwardRef((e,r)=>{let{__scopeHoverCard:s,...i}=e,n=ji(s);return(0,z.jsx)(iZ,{...n,...i,ref:r})}).displayName="HoverCardArrow";let jb=(0,ew.default)("corner-down-left",[["path",{d:"M20 4v7a4 4 0 0 1-4 4H4",key:"6o5b7l"}],["path",{d:"m9 10-5 5 5 5",key:"1kshq7"}]]),jw=(0,ew.default)("image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]);(0,ew.default)("mic",[["path",{d:"M12 19v3",key:"npa21l"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["rect",{x:"9",y:"2",width:"6",height:"13",rx:"3",key:"s6n7sd"}]]);let jS=(0,ew.default)("paperclip",[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]]),jC=(e=21)=>{let r="",s=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)r+="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[63&s[e]];return r},jj=(0,$.createContext)(null),jk=(0,$.createContext)(null),jN=()=>(0,$.useContext)(jj),jD=(0,$.createContext)(null),jE=()=>{let e=(0,$.useContext)(jk),r=(0,$.useContext)(jD),s=e??r;if(!s)throw Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return s};function jR({data:e,className:r,...s}){let i=jE(),n=e.filename||"",o="image"==(e.mediaType?.startsWith("image/")&&e.url?"image":"file"),a=n||(o?"Image":"Attachment");return(0,z.jsxs)(jW,{children:[(0,z.jsx)(j_,{asChild:!0,children:(0,z.jsxs)("div",{className:(0,ey.cn)("group relative flex h-8 cursor-pointer select-none items-center gap-1.5 rounded-md border border-border px-1.5 font-medium text-sm transition-all hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",r),...s,children:[(0,z.jsxs)("div",{className:"relative size-5 shrink-0",children:[(0,z.jsx)("div",{className:"absolute inset-0 flex size-5 items-center justify-center overflow-hidden rounded bg-background transition-opacity group-hover:opacity-0",children:o?(0,z.jsx)("img",{alt:n||"attachment",className:"size-5 object-cover",height:20,src:e.url,width:20}):(0,z.jsx)("div",{className:"flex size-5 items-center justify-center text-muted-foreground",children:(0,z.jsx)(jS,{className:"size-3"})})}),(0,z.jsxs)(W.Button,{"aria-label":"Remove attachment",className:"absolute inset-0 size-5 cursor-pointer rounded p-0 opacity-0 transition-opacity group-hover:pointer-events-auto group-hover:opacity-100 [&>svg]:size-2.5",onClick:r=>{r.stopPropagation(),i.remove(e.id)},type:"button",variant:"ghost",children:[(0,z.jsx)(t8,{}),(0,z.jsx)("span",{className:"sr-only",children:"Remove"})]})]}),(0,z.jsx)("span",{className:"flex-1 truncate",children:a})]},e.id)}),(0,z.jsx)(jH,{className:"w-auto p-2",children:(0,z.jsxs)("div",{className:"w-auto space-y-3",children:[o&&(0,z.jsx)("div",{className:"flex max-h-96 w-96 items-center justify-center overflow-hidden rounded-md border",children:(0,z.jsx)("img",{alt:n||"attachment preview",className:"max-h-full max-w-full object-contain",height:384,src:e.url,width:448})}),(0,z.jsx)("div",{className:"flex items-center gap-2.5",children:(0,z.jsxs)("div",{className:"min-w-0 flex-1 space-y-1 px-0.5",children:[(0,z.jsx)("h4",{className:"truncate font-semibold text-sm leading-none",children:n||(o?"Image":"Attachment")}),e.mediaType&&(0,z.jsx)("p",{className:"truncate font-mono text-muted-foreground text-xs",children:e.mediaType})]})})]})})]})}function jA({children:e,className:r,...s}){let i=jE();return i.files.length?(0,z.jsx)("div",{className:(0,ey.cn)("flex flex-wrap items-center gap-2 p-3 w-full",r),...s,children:i.files.map(r=>(0,z.jsx)($.Fragment,{children:e(r)},r.id))}):null}let jM=({label:e="Add photos or files",...r})=>{let s=jE();return(0,z.jsxs)(og,{...r,onSelect:e=>{e.preventDefault(),s.openFileDialog()},children:[(0,z.jsx)(jw,{className:"mr-2 size-4"})," ",e]})},jF=({className:e,accept:r,multiple:s,globalDrop:i,syncHiddenInput:n,maxFiles:o,maxFileSize:a,onError:l,onSubmit:c,children:d,...u})=>{let h=jN(),f=!!h,p=(0,$.useRef)(null),m=(0,$.useRef)(null),[g,x]=(0,$.useState)([]),v=f?h.attachments.files:g,_=(0,$.useRef)(v);_.current=v;let y=(0,$.useCallback)(()=>{p.current?.click()},[]),b=(0,$.useCallback)(e=>!r||""===r.trim()||r.split(",").map(e=>e.trim()).filter(Boolean).some(r=>{if(r.endsWith("/*")){let s=r.slice(0,-1);return e.type.startsWith(s)}return e.type===r}),[r]),w=(0,$.useCallback)(e=>{let r=Array.from(e),s=r.filter(e=>b(e));if(r.length&&0===s.length)return void l?.({code:"accept",message:"No files match the accepted types."});let i=s.filter(e=>!a||e.size<=a);s.length>0&&0===i.length?l?.({code:"max_file_size",message:"All files exceed the maximum size."}):x(e=>{let r="number"==typeof o?Math.max(0,o-e.length):void 0,s="number"==typeof r?i.slice(0,r):i;"number"==typeof r&&i.length>r&&l?.({code:"max_files",message:"Too many files. Some were not added."});let n=[];for(let e of s)n.push({id:jC(),type:"file",url:URL.createObjectURL(e),mediaType:e.type,filename:e.name});return e.concat(n)})},[b,o,a,l]),S=(0,$.useCallback)(e=>x(r=>{let s=r.find(r=>r.id===e);return s?.url&&URL.revokeObjectURL(s.url),r.filter(r=>r.id!==e)}),[]),C=(0,$.useCallback)(()=>x(e=>{for(let r of e)r.url&&URL.revokeObjectURL(r.url);return[]}),[]),j=f?h.attachments.add:w,k=f?h.attachments.remove:S,N=f?h.attachments.clear:C,D=f?h.attachments.openFileDialog:y;(0,$.useEffect)(()=>{f&&h.__registerFileInput(p,()=>p.current?.click())},[f,h]),(0,$.useEffect)(()=>{n&&p.current&&0===v.length&&(p.current.value="")},[v,n]),(0,$.useEffect)(()=>{let e=m.current;if(!e||i)return;let r=e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault()},s=e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault(),e.dataTransfer?.files&&e.dataTransfer.files.length>0&&j(e.dataTransfer.files)};return e.addEventListener("dragover",r),e.addEventListener("drop",s),()=>{e.removeEventListener("dragover",r),e.removeEventListener("drop",s)}},[j,i]),(0,$.useEffect)(()=>{if(!i)return;let e=e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault()},r=e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault(),e.dataTransfer?.files&&e.dataTransfer.files.length>0&&j(e.dataTransfer.files)};return document.addEventListener("dragover",e),document.addEventListener("drop",r),()=>{document.removeEventListener("dragover",e),document.removeEventListener("drop",r)}},[j,i]),(0,$.useEffect)(()=>()=>{if(!f)for(let e of _.current)e.url&&URL.revokeObjectURL(e.url)},[f]);let E=async e=>{try{let r=await fetch(e),s=await r.blob();return new Promise(e=>{let r=new FileReader;r.onloadend=()=>e(r.result),r.onerror=()=>e(null),r.readAsDataURL(s)})}catch{return null}},R=(0,$.useMemo)(()=>({files:v.map(e=>({...e,id:e.id})),add:j,remove:k,clear:N,openFileDialog:D,fileInputRef:p}),[v,j,k,N,D]),A=(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)("input",{accept:r,"aria-label":"Upload files",className:"hidden",multiple:s,onChange:e=>{e.currentTarget.files&&j(e.currentTarget.files),e.currentTarget.value=""},ref:p,title:"Upload files",type:"file"}),(0,z.jsx)("form",{className:(0,ey.cn)("w-full",e),onSubmit:e=>{e.preventDefault();let r=e.currentTarget,s=f?h.textInput.value:new FormData(r).get("message")||"";f||r.reset(),Promise.all(v.map(async({id:e,...r})=>{if(r.url&&r.url.startsWith("blob:")){let e=await E(r.url);return{...r,url:e??r.url}}return r})).then(r=>{try{let i=c({text:s,files:r},e);i instanceof Promise?i.then(()=>{N(),f&&h.textInput.clear()}).catch(()=>{}):(N(),f&&h.textInput.clear())}catch{}}).catch(()=>{})},ref:m,...u,children:(0,z.jsx)(yb,{className:"overflow-hidden",children:d})})]});return f?A:(0,z.jsx)(jD.Provider,{value:R,children:A})},jT=({onChange:e,onKeyDown:r,onPasteText:s,className:i,placeholder:n="What would you like to know?",...o})=>{let a=jN(),l=jE(),[c,d]=(0,$.useState)(!1),u=a?{value:a.textInput.value,onChange:r=>{a.textInput.setInput(r.currentTarget.value),e?.(r)}}:{onChange:e};return(0,z.jsx)(yN,{className:(0,ey.cn)("field-sizing-content max-h-48 min-h-9",i),name:"message",onCompositionEnd:()=>d(!1),onCompositionStart:()=>d(!0),onKeyDown:e=>{if(r?.(e),!e.defaultPrevented){if("Enter"===e.key){if(c||e.nativeEvent.isComposing||e.shiftKey)return;e.preventDefault();let r=e.currentTarget.form,s=r?.querySelector('button[type="submit"]');if(s?.disabled)return;r?.requestSubmit()}if("Backspace"===e.key&&""===e.currentTarget.value&&l.files.length>0){e.preventDefault();let r=l.files.at(-1);r&&l.remove(r.id)}}},onPaste:e=>{let r=e.clipboardData?.items;if(!r)return;let i=[];for(let e of r)if("file"===e.kind){let r=e.getAsFile();r&&i.push(r)}if(i.length>0){e.preventDefault(),l.add(i);return}if(s){let r=e.clipboardData.getData("text");r.length>0&&s(e,r)}},placeholder:n,...o,...u})},jP=({className:e,...r})=>(0,z.jsx)(yS,{align:"block-end",className:(0,ey.cn)("order-first flex-wrap gap-1",e),...r}),jB=({variant:e="ghost",className:r,size:s,...i})=>{let n=s??($.Children.count(i.children)>1?"sm":"icon-sm");return(0,z.jsx)(yj,{className:(0,ey.cn)(r),size:n,type:"button",variant:e,...i})},jL=e=>(0,z.jsx)(of,{...e}),jI=({className:e,children:r,...s})=>(0,z.jsx)(op,{asChild:!0,children:(0,z.jsx)(jB,{className:e,...s,children:r??(0,z.jsx)(eS,{className:"size-4"})})}),jO=({className:e,...r})=>(0,z.jsx)(om,{align:"start",className:(0,ey.cn)(e),...r}),jz=({className:e,...r})=>(0,z.jsx)(og,{className:(0,ey.cn)(e),...r}),j$=({className:e,variant:r="default",size:s="icon-sm",status:i,children:n,...o})=>{let a=(0,z.jsx)(jb,{className:"size-4"});return"submitted"===i?a=(0,z.jsx)(rj,{className:"size-4 animate-spin"}):"streaming"===i?a=(0,z.jsx)(d6,{className:"size-4"}):"error"===i&&(a=(0,z.jsx)(t8,{className:"size-4"})),(0,z.jsx)(yj,{"aria-label":"Submit",className:(0,ey.cn)(e),size:s,type:"submit",variant:r,...o,children:n??a})},jW=({openDelay:e=0,closeDelay:r=0,...s})=>(0,z.jsx)(jv,{closeDelay:r,openDelay:e,...s}),jH=({align:e="start",...r})=>(0,z.jsx)(jy,{align:e,...r}),jU=({size:e=16})=>(0,z.jsxs)("svg",{height:e,strokeLinejoin:"round",style:{color:"currentcolor"},viewBox:"0 0 16 16",width:e,children:[(0,z.jsx)("title",{children:"Loader"}),(0,z.jsxs)("g",{clipPath:"url(#clip0_2393_1490)",children:[(0,z.jsx)("path",{d:"M8 0V4",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M8 16V12",opacity:"0.5",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M3.29773 1.52783L5.64887 4.7639",opacity:"0.9",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M12.7023 1.52783L10.3511 4.7639",opacity:"0.1",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M12.7023 14.472L10.3511 11.236",opacity:"0.4",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M3.29773 14.472L5.64887 11.236",opacity:"0.6",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M15.6085 5.52783L11.8043 6.7639",opacity:"0.2",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M0.391602 10.472L4.19583 9.23598",opacity:"0.7",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M15.6085 10.4722L11.8043 9.2361",opacity:"0.3",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M0.391602 5.52783L4.19583 6.7639",opacity:"0.8",stroke:"currentColor",strokeWidth:"1.5"})]}),(0,z.jsx)("defs",{children:(0,z.jsx)("clipPath",{id:"clip0_2393_1490",children:(0,z.jsx)("rect",{fill:"white",height:"16",width:"16"})})})]}),jK=({className:e,size:r=16,...s})=>(0,z.jsx)("div",{className:(0,ey.cn)("inline-flex animate-spin items-center justify-center",e),...s,children:(0,z.jsx)(jU,{size:r})}),jq=(0,ew.default)("wifi",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]]),jV=(0,ew.default)("wifi-off",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]),jY=(0,ew.default)("square-pen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]),jG=(0,ew.default)("languages",[["path",{d:"m5 8 6 6",key:"1wu5hv"}],["path",{d:"m4 14 6-6 2-3",key:"1k1g8d"}],["path",{d:"M2 5h12",key:"or177f"}],["path",{d:"M7 2h1",key:"1t2jsx"}],["path",{d:"m22 22-5-10-5 10",key:"don7ne"}],["path",{d:"M14 18h6",key:"1m8k6r"}]]),jX=(0,ew.default)("split",[["path",{d:"M16 3h5v5",key:"1806ms"}],["path",{d:"M8 3H3v5",key:"15dfkv"}],["path",{d:"M12 22v-8.3a4 4 0 0 0-1.172-2.872L3 3",key:"1qrqzj"}],["path",{d:"m15 9 6-6",key:"ko1vev"}]]),jJ=(0,ew.default)("clipboard-list",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"M12 11h4",key:"1jrz19"}],["path",{d:"M12 16h4",key:"n85exb"}],["path",{d:"M8 11h.01",key:"1dfujw"}],["path",{d:"M8 16h.01",key:"18s6g9"}]]);function jZ({mode:e,onModeChange:r,disabled:s}){return(0,z.jsxs)("div",{className:"inline-flex items-center rounded-md border bg-muted/50 px-0.5 text-xs",children:[(0,z.jsxs)("button",{onClick:()=>r("plan"),disabled:s,className:(0,ey.cn)("inline-flex items-center gap-1 rounded-sm px-2 py-0.5 transition-colors","plan"===e?"bg-primary text-primary-foreground font-medium shadow-sm":"text-muted-foreground hover:text-foreground",s&&"opacity-50 cursor-not-allowed"),children:[(0,z.jsx)(jJ,{className:"h-3 w-3"}),"Plan"]}),(0,z.jsxs)("button",{onClick:()=>r("edit"),disabled:s,className:(0,ey.cn)("inline-flex items-center gap-1 rounded-sm px-2 py-0.5 transition-colors","edit"===e?"bg-primary text-primary-foreground font-medium shadow-sm":"text-muted-foreground hover:text-foreground",s&&"opacity-50 cursor-not-allowed"),children:[(0,z.jsx)(rm,{className:"h-3 w-3"}),"Edit"]})]})}function jQ(e){if(!e)return[];try{let r=window.localStorage.getItem(e);if(!r)return[];let s=JSON.parse(r);if(!Array.isArray(s))return[];return s.filter(e=>"string"==typeof e)}catch{return[]}}function j0(e){if(!e)return"";try{return window.localStorage.getItem(e)??""}catch{return""}}function j1(e){let r=e.parentElement;for(;r;){let{overflowY:e}=getComputedStyle(r);if("auto"===e||"scroll"===e)return r;r=r.parentElement}return null}function j2({messages:e,contentRef:r}){let[s,i]=(0,$.useState)([]),[n,o]=(0,$.useState)(!1),[a,l]=(0,$.useState)(null),c=(0,$.useRef)(null),d=(0,$.useCallback)(()=>{let s=r.current;if(!s)return;c.current||(c.current=j1(s));let n=c.current;if(!n)return;let a=n.scrollHeight>n.clientHeight;if(o(a),!a)return void i([]);let l=s.querySelectorAll("[data-user-msg-idx]"),d=n.getBoundingClientRect(),u=[];l.forEach(r=>{let s=parseInt(r.dataset.userMsgIdx,10),i=e[s];if(!i)return;let o=(r.getBoundingClientRect().top-d.top+n.scrollTop)/n.scrollHeight;u.push({index:s,position:Math.max(0,Math.min(1,o)),preview:function(e){if("user"!==e.type)return"";let r=e.content,s="string"==typeof r?r:r.filter(e=>"text"===e.type).map(e=>e.text).join(" "),i="string"!=typeof r&&r.some(e=>"image"===e.type),n=s.split("\n")[0]??"";return(n.length>80?n.slice(0,77)+"...":n)||(i?"(Image)":"")}(i)})}),i(u)},[e,r]);(0,$.useEffect)(()=>{let e=r.current;if(!e){c.current=null,i([]),o(!1);return}let s=j1(e);if(!s)return;c.current=s,d();let n=new ResizeObserver(d);return n.observe(s),n.observe(e),()=>{n.disconnect()}},[e,d,r]);let u=(0,$.useCallback)(e=>{let s=r.current;if(!s)return;let i=s.querySelector(`[data-user-msg-idx="${e}"]`);i&&i.scrollIntoView({block:"start",behavior:"smooth"})},[r]);return n&&0!==s.length?(0,z.jsx)("div",{className:"absolute right-0 top-0 bottom-0 w-6 z-20 pointer-events-none",children:s.map(e=>(0,z.jsxs)("div",{className:"absolute right-0.5 -translate-y-1/2 pointer-events-auto",style:{top:`${100*e.position}%`},children:[(0,z.jsx)("div",{className:"w-3 h-[3px] rounded-sm bg-primary/50 hover:bg-primary cursor-pointer transition-colors",onClick:()=>u(e.index),onMouseEnter:()=>l(e.index),onMouseLeave:()=>l(null)}),a===e.index&&e.preview&&(0,z.jsxs)("div",{className:"absolute right-full mr-2 top-1/2 -translate-y-1/2 max-w-64 px-2.5 py-1.5 bg-popover border border-border rounded-md shadow-md text-xs text-popover-foreground whitespace-nowrap overflow-hidden text-ellipsis pointer-events-none",children:[e.preview,(0,z.jsx)("div",{className:"absolute top-1/2 -translate-y-1/2 -right-1 w-2 h-2 bg-popover border-r border-t border-border rotate-45"})]})]},e.index))}):null}let j5=(0,ew.default)("star",[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]);function j3({projectId:e,branch:r,currentSessionId:s,refreshKey:i,pendingTitleSessionId:n,aiTitleOverride:o,onSwitch:a,onDelete:l}){let[c,d]=(0,$.useState)([]),[u,h]=(0,$.useState)(null),[f,p]=(0,$.useState)(""),[m,g]=(0,$.useState)(!1),[x,v]=(0,$.useState)(null),[_,y]=(0,$.useState)(0),b=(0,$.useCallback)(()=>y(e=>e+1),[]);(0,$.useEffect)(()=>{let s=!1;return(0,rx.listBranchSessions)(e,r).then(e=>{s||d(e.sessions)}).catch(e=>{s||console.error("[SessionHistoryDropdown] refresh failed:",e)}),()=>{s=!0}},[e,r,i,_]);let w=(0,$.useRef)(null);(0,$.useEffect)(()=>{if(!s)return;if(c.some(e=>e.id===s)){w.current=null;return}if(w.current===s)return;w.current=s;let i=!1;return(0,rx.listBranchSessions)(e,r).then(e=>{if(i)return;d(e.sessions);let r=e.sessions.find(e=>e.id===s),n=!!r&&(o?.sessionId===r.id||!!(r.title&&r.title.trim().length>0));r&&!n&&v(s)}).catch(e=>{i||console.error("[SessionHistoryDropdown] missing-session refresh failed:",e)}),()=>{i=!0}},[s,c,e,r,o]),(0,$.useEffect)(()=>{if(!x)return;let e=setTimeout(()=>{v(e=>e===x?null:e)},3e4);return()=>clearTimeout(e)},[x]),(0,$.useEffect)(()=>{if(!x)return;let e=setTimeout(()=>{v(e=>e===x?null:e)},3e4);return()=>clearTimeout(e)},[x]);let S=async(e,r)=>{let s=r.trim().length>0?r.trim():null;try{await (0,rx.renameSession)(e,s),d(r=>r.map(r=>r.id===e?{...r,title:s}:r)),h(null),gK.toast.success("Renamed")}catch(e){gK.toast.error("Rename failed"),console.error(e)}},C=async(e,r)=>{let s=null==r,i=s?Date.now():null;d(r=>r.map(r=>r.id===e?{...r,favorited_at:i}:r));try{await (0,rx.setSessionFavorited)(e,s)}catch(i){d(s=>s.map(s=>s.id===e?{...s,favorited_at:r}:s)),gK.toast.error(s?"Favorite failed":"Unfavorite failed"),console.error(i)}},j=async e=>{if(window.confirm("Delete this conversation? This cannot be undone."))try{await (0,rx.deleteSession)(e);let r=c.filter(r=>r.id!==e);d(r),l?.(e,r),gK.toast.success("Deleted")}catch(e){gK.toast.error("Delete failed"),console.error(e)}},k=e=>o&&o.sessionId===e.id?o.title:e.title&&e.title.trim().length>0?e.title:e.updated_at?new Date(e.updated_at).toLocaleString():new Date(e.created_at).toLocaleString(),N=e=>{let r;return o?.sessionId!==e.id&&(!e.title||!(e.title.trim().length>0))&&(r=e.id,null!==n&&n===r||x===e.id)},D=c.find(e=>e.id===s),E=null!==s&&(!D||N(D)),R=D?k(D):null===s?"New Session":"History",A=E?"Generating title…":R;return(0,z.jsxs)(of,{open:m,onOpenChange:e=>{g(e),e&&b()},children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsxs)(W.Button,{variant:"ghost",size:"sm",className:"h-7 text-xs gap-1 w-[200px] justify-start",title:A,children:[E?(0,z.jsx)("span",{className:"block h-3 flex-1 rounded-sm bg-accent animate-pulse",role:"status","aria-label":"Generating title"}):(0,z.jsx)("span",{className:"truncate flex-1 text-left",children:R}),(0,z.jsx)(sb,{className:"h-3 w-3 flex-shrink-0"})]})}),(0,z.jsxs)(om,{align:"start",className:"w-80 max-h-96 overflow-y-auto",children:[0===c.length&&(0,z.jsx)("div",{className:"px-2 py-3 text-xs text-muted-foreground",children:"No history yet."}),c.map(e=>{let r=e.id===s,i=u===e.id;return(0,z.jsxs)(og,{onSelect:s=>{i?s.preventDefault():r||a(e.id)},className:`flex items-center gap-2 group ${r?"bg-accent text-accent-foreground":""}`,children:[(0,z.jsx)("div",{className:"flex-1 min-w-0",children:i?(0,z.jsxs)("div",{className:"flex items-center gap-1",children:[(0,z.jsx)(ro,{value:f,onChange:e=>p(e.target.value),onKeyDown:r=>{"Enter"===r.key&&S(e.id,f),"Escape"===r.key&&h(null)},autoFocus:!0,className:"h-6 text-xs"}),(0,z.jsx)("button",{type:"button","aria-label":"Save rename",onClick:r=>{r.stopPropagation(),S(e.id,f)},children:(0,z.jsx)(rh.Check,{className:"h-3 w-3"})}),(0,z.jsx)("button",{type:"button","aria-label":"Cancel rename",onClick:e=>{e.stopPropagation(),h(null)},children:(0,z.jsx)(t8,{className:"h-3 w-3"})})]}):N(e)?(0,z.jsx)("div",{className:"py-0.5",title:"Generating title…",children:(0,z.jsx)("span",{className:"block h-3 w-40 rounded-sm bg-accent animate-pulse",role:"status","aria-label":"Generating title"})}):(0,z.jsx)("div",{className:"truncate text-xs",title:`${e.updated_at?new Date(e.updated_at).toLocaleString():new Date(e.created_at).toLocaleString()} • ${e.entry_count??0} messages • status: ${e.status}`,children:k(e)})}),!i&&(0,z.jsxs)("div",{className:"flex items-center gap-1",children:[(0,z.jsxs)("div",{className:"opacity-0 group-hover:opacity-100 flex items-center gap-1",children:[(0,z.jsx)("button",{type:"button","aria-label":"Rename conversation",onClick:r=>{r.stopPropagation(),h(e.id),p(e.title??"")},className:"p-1 hover:bg-muted rounded",children:(0,z.jsx)(rm,{className:"h-3 w-3"})}),(0,z.jsx)("button",{type:"button","aria-label":"Delete conversation",onClick:r=>{r.stopPropagation(),j(e.id)},className:"p-1 hover:bg-muted rounded text-destructive",children:(0,z.jsx)(rl,{className:"h-3 w-3"})})]}),(0,z.jsx)("button",{type:"button","aria-label":null!=e.favorited_at?"Unfavorite conversation":"Favorite conversation",title:null!=e.favorited_at?"Unfavorite":"Favorite",onClick:r=>{r.stopPropagation(),C(e.id,e.favorited_at??null)},className:`p-1 hover:bg-muted rounded ${null!=e.favorited_at?"opacity-100 text-yellow-500":"opacity-0 group-hover:opacity-100 text-muted-foreground"}`,children:(0,z.jsx)(j5,{className:`h-3 w-3 ${null!=e.favorited_at?"fill-current":""}`})})]})]},e.id)}),c.length>0&&(0,z.jsx)(ob,{}),(0,z.jsx)(og,{onSelect:()=>b(),className:"text-xs text-muted-foreground",children:"Refresh"})]})]})}let j4=(0,ew.default)("quote",[["path",{d:"M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z",key:"rib7q0"}],["path",{d:"M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z",key:"1ymkrd"}]]);function j6(e,r){let s=e;for(;s&&s!==r;){if(s.nodeType===Node.ELEMENT_NODE){let e=s.getAttribute("data-message-idx");if(null!==e)return e}s=s.parentNode}return null}function j8({containerRef:e,onQuote:r}){let[s,i]=(0,$.useState)(null);if((0,$.useEffect)(()=>{function r(){let r=e.current;if(!r)return void i(null);let s=window.getSelection();if(!s||s.isCollapsed||0===s.rangeCount)return void i(null);let n=s.toString();if(!n.trim())return void i(null);let{anchorNode:o,focusNode:a}=s;if(!o||!a||!r.contains(o)||!r.contains(a))return void i(null);let l=j6(o,r),c=j6(a,r);if(null===l||null===c||l!==c)return void i(null);let d=s.getRangeAt(0).getBoundingClientRect();0===d.width&&0===d.height?i(null):i({text:n,rect:{top:d.top,bottom:d.bottom,left:d.left,width:d.width}})}function s(){let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||i(null)}return document.addEventListener("mouseup",r),document.addEventListener("keyup",r),document.addEventListener("touchend",r),document.addEventListener("selectionchange",s),window.addEventListener("scroll",r,!0),window.addEventListener("resize",r),()=>{document.removeEventListener("mouseup",r),document.removeEventListener("keyup",r),document.removeEventListener("touchend",r),document.removeEventListener("selectionchange",s),window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",r)}},[e]),!s||"undefined"==typeof document)return null;let n=s.rect.top-8-30<8?s.rect.bottom+8:s.rect.top-8-30,o=s.rect.left+s.rect.width/2,a=Math.max(8,Math.min(window.innerWidth-8,o));return(0,ee.createPortal)((0,z.jsxs)("button",{type:"button",onMouseDown:e=>{e.preventDefault(),r(s.text),window.getSelection()?.removeAllRanges(),i(null)},style:{position:"fixed",top:n,left:a,transform:"translateX(-50%)",zIndex:50},className:"inline-flex items-center gap-1.5 rounded-md border border-border bg-popover px-3 py-1.5 text-xs font-medium text-popover-foreground shadow-2xl hover:bg-accent",children:[(0,z.jsx)(j4,{className:"h-3 w-3"}),"Quote"]}),document.body)}function j7(){return 0===jE().files.length?null:(0,z.jsx)(jP,{children:(0,z.jsx)(jA,{children:e=>(0,z.jsx)(jR,{data:e})})})}let j9=(0,$.createContext)(null);function ke(){let e=(0,$.useContext)(j9);if(!e)throw Error("useAgentConversation must be used within AgentConversationContext");return e}let kt=/\[📎 paste #(\d+) \([^)]+\)\]/g;function kr(e,r){return`[📎 paste #${e} (${function(e){if(e<1024)return`${e}B`;let r=e/1024;return r<10?`${r.toFixed(1)}KB`:`${Math.round(r)}KB`}(r)})]`}let ks=(0,$.forwardRef)(function({projectId:e,branch:r,sessionId:s,setSessionUrlParam:i,project:n,onAgentModeChange:o,onTaskCompleted:a,onSessionStarted:l,onSessionTitleUpdated:c,onStatusChange:d,onNewConversation:u},h){var f;let p,m,g,x,[v,_]=function(e,r){let s=e&&r?`vibedeckx:agent-draft:${e}:${r}`:null,[i,n]=(0,$.useState)(()=>j0(s)),[o,a]=(0,$.useState)(s);return o!==s&&(a(s),n(j0(s))),[i,(0,$.useCallback)(e=>{n(e);if(s)try{e?window.localStorage.setItem(s,e):window.localStorage.removeItem(s)}catch{}},[s])]}(e,r),[y,b]=(0,$.useState)([]),[w,S]=(0,$.useState)(1),[C,j]=(0,$.useState)("edit"),[k,N]=(0,$.useState)(!1),[D,E]=(0,$.useState)(!1),[R,A]=(0,$.useState)(!1),[M,F]=(0,$.useState)("claude-code"),[T,P]=(0,$.useState)([]),[B,L]=(0,$.useState)(0),[I,O]=(0,$.useState)(null),[H,U]=(0,$.useState)(null),K=(0,$.useRef)(null),q=(0,$.useCallback)(e=>{if("ArrowUp"!==e.key&&"ArrowDown"!==e.key||!e.shiftKey||e.ctrlKey||e.metaKey||e.altKey)return;let r=K.current;if(!r)return;let s=j1(r);if(!s)return;let i=s.getBoundingClientRect(),n=s.scrollTop,o="ArrowUp"===e.key,a=null,l=o?-1/0:1/0;r.querySelectorAll("[data-user-msg-idx]").forEach(e=>{let r=e.getBoundingClientRect().top-i.top+s.scrollTop;o?r<n-12&&r>l&&(l=r,a=e):r>n+12&&r<l&&(l=r,a=e)}),a&&(e.preventDefault(),a.scrollIntoView({block:"start",behavior:"smooth"}))},[K]),V=(0,$.useRef)(null),Y=function(e,r,s){let i=r&&s?`vibedeckx:agent-input-history:${r}:${s}`:null,n=(0,$.useRef)(jQ(i)),o=(0,$.useRef)(-1),a=(0,$.useRef)(""),[l,c]=(0,$.useState)(i);return l!==i&&(c(i),n.current=jQ(i),o.current=-1,a.current=""),{push:(0,$.useCallback)(e=>{let r=e.trim();if(!r)return;let s=n.current;if(s.length>0&&s[s.length-1]===r){o.current=-1;return}s.push(r),s.length>50&&s.shift(),o.current=-1;if(i)try{0===s.length?window.localStorage.removeItem(i):window.localStorage.setItem(i,JSON.stringify(s))}catch{}},[i]),handleKeyDown:(0,$.useCallback)(r=>{let s=r.currentTarget,i=n.current;if(0!==i.length)if("ArrowUp"===r.key){if(0!==s.selectionStart||0!==s.selectionEnd)return;if(r.preventDefault(),-1===o.current)a.current=s.value,o.current=i.length-1;else{if(!(o.current>0))return;o.current--}e(i[o.current])}else if("ArrowDown"===r.key){if(-1===o.current)return;let n=s.value.length;if(s.selectionStart!==n||s.selectionEnd!==n)return;r.preventDefault(),o.current<i.length-1?(o.current++,e(i[o.current])):(o.current=-1,e(a.current))}else -1!==o.current&&(o.current=-1)},[e])}}(_,e,r),{remotes:G}=vU(),X=[];for(let e of(n?.path&&X.push({id:"local",label:"Local",icon:oD}),G))X.push({id:e.remote_server_id,label:e.server_name,icon:sc(e)});let{session:J,messages:Z,status:Q,isConnected:ee,isInitialized:et,isLoading:er,error:es,remoteStatus:ei,sendMessage:en,uploadPaste:eo,stopSession:ea,switchAgentType:el,startNewConversation:ec,ensureSession:ed,switchMode:eu,acceptPlan:eh}=function(e,r,s,i,n){let o=n?.sessionId??null,[a,l]=(0,$.useState)(null),[c,d]=(0,$.useState)([]),[u,h]=(0,$.useState)("stopped"),[f,p]=(0,$.useState)(!1),[m,g]=(0,$.useState)(!1),[x,v]=(0,$.useState)(!1),[_,y]=(0,$.useState)(null),[b,w]=(0,$.useState)(null),S=(0,$.useRef)(null),C=(0,$.useRef)(null),j=(0,$.useRef)(()=>{}),k=(0,$.useRef)(null),N=(0,$.useRef)(0),D=(0,$.useRef)({entries:[],status:"stopped"}),E=(0,$.useRef)(!1),R=(0,$.useRef)(!0),A=(0,$.useRef)(null),M=(0,$.useRef)(null),F=(0,$.useRef)(0),T=(0,$.useRef)(!1),P=(0,$.useRef)(0),B=(0,$.useRef)(!1),L=(0,$.useRef)(!1),I=(0,$.useRef)(n?.onTaskCompleted),O=(0,$.useRef)(n?.onSessionStarted),z=(0,$.useRef)(n?.onTitleUpdated),W=(0,$.useRef)(e),H=(0,$.useRef)(r),U=(0,$.useRef)(o);(0,$.useEffect)(()=>{I.current=n?.onTaskCompleted,O.current=n?.onSessionStarted,z.current=n?.onTitleUpdated,W.current=e,H.current=r,U.current=o});let K=(0,$.useCallback)((e,r=!1)=>{(0,rx.getFreshToken)(r?{skipCache:!0}:void 0).then(()=>j.current(e))},[]),q=(0,$.useCallback)(e=>{let r=()=>{let e=W.current;if(!e)return;let r=H.current;SB.delete(SL(e,r,U.current));let s=C.current;s&&SB.delete(SL(e,r,s))};if(S.current&&C.current!==e&&(console.log(`[AgentSession] Closing stale WS for ${C.current}, switching to ${e}`),S.current.close(1e3,"session-switch"),S.current=null,C.current=null),S.current?.readyState===WebSocket.OPEN||S.current?.readyState===WebSocket.CONNECTING)return;0===D.current.entries.filter(Boolean).length&&(D.current={entries:[],status:"running"}),E.current=!1,T.current=!0;let s=(0,rx.getWebSocketUrl)(`/api/agent-sessions/${e}/stream`);console.log("[AgentSession] Connecting to WebSocket:",s);let i=new WebSocket(s);S.current=i,C.current=e,i.onopen=()=>{console.log("[AgentSession] WebSocket connected"),p(!0),y(null),w(null),A.current=Date.now(),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{console.log("[AgentSession] Connection stable, resetting backoff counter"),N.current=0,F.current=0},5e3)},i.onmessage=e=>{try{let n=JSON.parse(e.data);if("JsonPatch"in n){var s;let e=n.JsonPatch;s=D.current,D.current=Sm(s,r=>{for(let s of e){let{op:e,path:i,value:n}=s;if("/entries"===i&&"replace"===e&&n?.type==="ENTRY"&&n.content?.type==="system"&&n.content?.content==="__CLEAR_ALL__"){console.log("[JsonPatch] Received clearAll signal - clearing all entries"),r.entries=[];continue}if(i.startsWith("/entries/")){let s=parseInt(i.replace("/entries/",""),10);if(isNaN(s)){console.warn(`[JsonPatch] Invalid index in path: ${i}`);continue}if(n?.type!=="ENTRY"){console.warn("[JsonPatch] Expected ENTRY type for entries path");continue}switch(e){case"add":for(;r.entries.length<=s;)r.entries.push(null);r.entries[s]=n.content;break;case"replace":s<r.entries.length?r.entries[s]=n.content:console.warn(`[JsonPatch] Replace index out of bounds: ${s}`);break;case"remove":s<r.entries.length&&r.entries.splice(s,1)}}else"/status"===i&&n?.type==="STATUS"&&(console.log("[AgentSession] /status patch →",n.content),r.status=n.content)}}),T.current?console.log("[AgentSession] /status patch applied during replay (no setStatus), container.status =",D.current.status):(d([...D.current.entries.filter(Boolean)]),console.log("[AgentSession] setStatus(live) →",D.current.status),h(D.current.status),("stopped"===D.current.status||"error"===D.current.status)&&r());return}if("Ready"in n){console.log("[AgentSession] Received Ready signal - history complete, status=",D.current.status),T.current=!1,d([...D.current.entries.filter(Boolean)]),h(D.current.status),g(!0);return}if("finished"in n){console.log("[AgentSession] Received finished signal, invalidating cache"),E.current=!0,r(),i.close(1e3,"finished");return}if("taskCompleted"in n){let{duration_ms:e,cost_usd:r,input_tokens:s,output_tokens:i}=n.taskCompleted,o=[];if(null!=e){let r=(e/1e3).toFixed(1);o.push(`${r}s`)}if(null!=r)o.push(`$${r.toFixed(4)}`);else if(null!=s||null!=i){let e=(s??0)+(i??0),r=e>1e3?`${(e/1e3).toFixed(1)}K`:String(e);o.push(`${r} tokens`)}gK.toast.success("Task completed",{description:o.length>0?o.join(" · "):void 0}),I.current?.();return}if("remoteStatus"in n)return void w(n.remoteStatus);if("titleUpdated"in n)return void z.current?.(n.titleUpdated.title,C.current);if("error"in n){console.error("[AgentSession] Server error:",n.error),y(n.error),"Session not found"===n.error&&(console.log("[AgentSession] Session invalid, invalidating cache, will create new session"),r(),E.current=!0,l(null),h("stopped"),g(!1),R.current=!0);return}}catch(e){console.error("[AgentSession] Failed to parse message:",e)}},i.onclose=e=>{let s,i;console.log("[AgentSession] WebSocket disconnected",e.code,e.reason),p(!1),M.current&&(clearTimeout(M.current),M.current=null);let n=A.current?Date.now()-A.current:0;if(A.current=null,n>0&&n<5e3){if(F.current++,console.log(`[AgentSession] Short-lived connection (${n}ms), count: ${F.current}, backoff attempt: ${N.current}`),F.current>=3){if(console.log("[AgentSession] Multiple short-lived connections detected, session likely invalid - will recreate"),B.current){console.log("[AgentSession] Skipping auto-restart: last session creation failed"),y("Unable to connect to remote server. Please check the server configuration.");return}r(),l(null),y(null),N.current=0,F.current=0,R.current=!0;return}}else n>=5e3&&(F.current=0);if(E.current||1e3===e.code)return;if(N.current>=10){console.log("[AgentSession] Max reconnect attempts reached"),y("Unable to connect to server. Please check if the backend is running.");return}let o=(i=(s=Math.min(3e4,1e3*Math.pow(2,N.current)))*Math.random()*.25,s+i);console.log(`[AgentSession] Reconnecting in ${Math.round(o)}ms (attempt ${N.current+1})`),N.current++,k.current=setTimeout(()=>{let e=C.current;e&&!E.current&&K(e,!0)},o)},i.onerror=e=>{console.error("[AgentSession] WebSocket error:",e)}},[K]);(0,$.useEffect)(()=>{j.current=q},[q]);let V=(0,$.useCallback)(async s=>{if(!e)return null;if(L.current)return console.log("[AgentSession] startSession already in progress, skipping"),null;L.current=!0;let n=P.current;y(null),w(null),g(!1),B.current=!1;let a=SL(e,r,o),c=SB.get(a);if(c)return console.log(`[AgentSession] Cache hit for ${a}, reconnecting WebSocket directly`),l(c),h(c.status),K(c.id),O.current?.(c),L.current=!1,c;v(!0);try{console.log(`[AgentSession] Starting REST call: projectId=${e}, branch=${r}, sessionId=${o??"latest"}, agentType=${i}, generation=${n}`);let{session:c,messages:u}=o?await SI(o):await SD(e,r,s,i);if(P.current!==n)return console.log("[AgentSession] Discarding stale session response (generation mismatch)"),null;if(!c)return console.log(`[AgentSession] No existing session for ${e}/${r??"<null>"} — placeholder`),l(null),h("stopped"),d([]),D.current={entries:[],status:"stopped"},g(!0),null;return console.log(`[AgentSession] REST response: sessionId=${c.id}, msgCount=${u?.length??0}, status=${c.status}, explicitSessionIdRequested=${o??"<null>"}`),SB.set(a,c),o&&SB.set(SL(e,r,c.id),c),l(c),h(c.status),u&&u.length>0&&(d(u),D.current={entries:[...u],status:c.status}),K(c.id),O.current?.(c),c}catch(e){if(console.error("[AgentSession] startSession error:",e),P.current!==n)return console.log("[AgentSession] Discarding error (generation mismatch)"),null;return y(e instanceof Error?e.message:"Failed to start session"),B.current=!0,null}finally{L.current=!1,P.current===n&&v(!1)}},[e,r,i,o,K]),Y=(0,$.useCallback)(async(s,i)=>{let n=i||a?.id;if(!n)return void console.warn("[AgentSession] sendMessage: no session ID available (sessionId param:",i,", session?.id:",a?.id,")");if(("string"!=typeof s||s.trim())&&(!Array.isArray(s)||0!==s.length)){console.log(`[AgentSession] sendMessage: targetSessionId=${n}, source=${i?"explicit":"state"}`);try{let e="string"==typeof s?s.trim():s;await SE(n,e)}catch(i){let s=i instanceof Error?i.message:"Failed to send message";console.error("[AgentSession] Failed to send message:",s),s.includes("[404]")&&(e&&(SB.delete(SL(e,r,o)),a?.id&&SB.delete(SL(e,r,a.id))),l(null),h("stopped"),g(!1),R.current=!0),y(s),gK.toast.error("Failed to send message",{description:s})}}},[a?.id,e,r,o]),G=(0,$.useCallback)(async(e,r)=>{let s=r||a?.id;if(!s)throw Error("No session id available for paste upload");return SR(s,e)},[a?.id]),X=(0,$.useCallback)(async()=>{if(a?.id)try{await SF(a.id)}catch(e){e instanceof Error&&e.message,console.error("[AgentSession] Failed to stop session:",e),gK.toast.error("Failed to stop session")}},[a?.id]),J=(0,$.useCallback)(async s=>{if(a?.id){e&&(SB.delete(SL(e,r,o)),SB.delete(SL(e,r,a.id))),v(!0),y(null);try{await SA(a.id,s),s&&l(e=>e?{...e,agentType:s}:null)}catch(e){y(e instanceof Error?e.message:"Failed to restart session"),console.error("[AgentSession] Failed to restart session:",e)}finally{v(!1)}}},[a?.id,e,r,o]),Z=(0,$.useCallback)(async s=>{if(!a?.id)return"No active session";y(null);try{return await SM(a.id,s),l(i=>{if(!i)return i;let n={...i,agentType:s};return e&&(SB.set(SL(e,r,o),n),SB.set(SL(e,r,n.id),n)),n}),null}catch(r){let e=r instanceof Error?r.message:"Failed to switch agent";return console.error("[AgentSession] Failed to switch agent:",r),e}},[a?.id,e,r,o]),Q=(0,$.useCallback)(async s=>{if(a?.id){y(null);try{await ST(a.id,s),l(i=>{if(!i)return i;let n={...i,permissionMode:s};return e&&(SB.set(SL(e,r,o),n),SB.set(SL(e,r,n.id),n)),n})}catch(e){y(e instanceof Error?e.message:"Failed to switch mode"),console.error("[AgentSession] Failed to switch mode:",e)}}},[a?.id,e,r,o]),ee=(0,$.useCallback)(async s=>{if(a?.id){y(null);try{await SP(a.id,s),l(s=>{if(!s)return s;let i={...s,permissionMode:"edit"};return e&&(SB.set(SL(e,r,o),i),SB.set(SL(e,r,i.id),i)),i})}catch(e){y(e instanceof Error?e.message:"Failed to accept plan"),console.error("[AgentSession] Failed to accept plan:",e)}}},[a?.id,e,r,o]),et=(0,$.useCallback)(async()=>{var i;let n;return e?(a?.id&&SB.delete(SL(e,r,a.id)),SB.delete(SL(e,r,o)),S.current&&(S.current.close(1e3,"new-conversation"),S.current=null,C.current=null),k.current&&(clearTimeout(k.current),k.current=null),M.current&&(clearTimeout(M.current),M.current=null),E.current=!1,T.current=!1,p(!1),l(null),h("stopped"),g(!0),y(null),w(null),d([]),D.current={entries:[],status:"stopped"},i=Sj(e,r,s),(n=new Map(Sv)).set(i,Date.now()),Sx(Sv=n),Sb(),null):null},[e,r,s,a?.id,o]),er=(0,$.useCallback)(async n=>{if(!e)return null;if(a)return a;v(!0),y(null);try{let a;try{a=await (0,rx.createNewAgentSession)(e,r,n,i)}catch(s){if(s instanceof rx.ResidentLimitError){if(!window.confirm(`All ${s.maxResidentAgentProcesses} resident agent processes for this workspace branch are running. Stop the least recently active running session in this branch and start a new conversation?`))throw s;a=await (0,rx.createNewAgentSession)(e,r,n,i,!0)}else throw s}let c={id:a.session.id,projectId:a.session.projectId,branch:a.session.branch,status:a.session.status,permissionMode:a.session.permissionMode??"edit",agentType:a.session.agentType??"claude-code",processAlive:a.session.processAlive??!0};return SB.set(SL(e,r,o),c),SB.set(SL(e,r,c.id),c),l(c),h(c.status),g(!0),Sk(Sj(e,r,s)),K(c.id),O.current?.(c),c}catch(e){return y(e instanceof Error?e.message:"Failed to create session"),console.error("[AgentSession] ensureSession:",e),null}finally{v(!1)}},[e,r,s,i,a,o,K]);return(0,$.useEffect)(()=>()=>{S.current&&(E.current=!0,S.current.close(),C.current=null),k.current&&clearTimeout(k.current),M.current&&clearTimeout(M.current)},[]),(0,$.useEffect)(()=>{S.current&&(S.current.close(1e3,"branch-switch"),S.current=null,C.current=null),k.current&&(clearTimeout(k.current),k.current=null),M.current&&(clearTimeout(M.current),M.current=null),P.current+=1;let i=e?Sj(e,r,s):null;i&&o&&Sk(i);let n=!o&&null!==i&&Sv.has(i);l(null),h("stopped"),p(!1),g(n),y(null),v(!1),w(null),d([]),D.current={entries:[],status:"stopped"},E.current=!1,N.current=0,A.current=null,F.current=0,B.current=!1,L.current=!1,R.current=!n,e&&SB.delete(SL(e,r,o))},[e,r,s,o]),(0,$.useEffect)(()=>{var i;let n=null!==e&&(i=Sj(e,r,s),Sv.has(i));!R.current||!e||a||x||B.current||n||(R.current=!1,console.log(`[AgentSession] Auto-start: projectId=${e}, branch=${r}, agentMode=${s}`),V())},[e,r,s,a,x,V]),(0,$.useEffect)(()=>{let e=()=>{if("visible"===document.visibilityState&&a?.id&&!E.current){let e=S.current;e&&e.readyState!==WebSocket.CLOSED&&e.readyState!==WebSocket.CLOSING||(console.log("[AgentSession] Tab visible, WebSocket disconnected - reconnecting"),N.current=0,F.current=0,k.current&&(clearTimeout(k.current),k.current=null),K(a.id))}};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[a?.id,K]),(0,$.useEffect)(()=>{a?.id&&!E.current&&K(a.id)},[a?.id,K]),{session:a,messages:c,status:u,isConnected:f,isInitialized:m,isLoading:x,error:_,remoteStatus:b,startSession:V,sendMessage:Y,uploadPaste:G,stopSession:X,restartSession:J,switchAgentType:Z,startNewConversation:et,ensureSession:er,switchMode:Q,acceptPlan:ee}}(e,r,n?.agent_mode,M,{sessionId:s,onTaskCompleted:a,onSessionStarted:l,onTitleUpdated:(e,r)=>{let s=r??J?.id;s&&e&&(U({sessionId:s,title:e}),c?.(s,e)),L(e=>e+1),O(null)}});f=J?.id??null,(0,aj.useGlobalEventStream)(s=>{"session:status"!==s.type||"running"!==s.status||!e||s.projectId!==e||(s.branch??null)!==(r??null)||s.sessionId&&s.sessionId!==f&&(e=>i?.(e))(s.sessionId)}),(0,$.useEffect)(()=>{(0,rx.getAgentProviders)().then(P).catch(()=>{})},[]),(0,$.useEffect)(()=>{J?.permissionMode&&j(J.permissionMode)},[J?.permissionMode]),(0,$.useEffect)(()=>{J?.agentType&&F(J.agentType)},[J?.agentType]),(0,$.useEffect)(()=>{b([]),S(1)},[e,r]);let ef=(0,$.useRef)({sessionId:null,count:0});(0,$.useEffect)(()=>{let e=J?.id??null,r=ef.current;e&&r.sessionId===e&&0===r.count&&Z.length>0&&O(e),ef.current={sessionId:e,count:Z.length}},[J?.id,Z.length]),(0,$.useEffect)(()=>{I&&J?.id!==I&&O(null)},[J?.id,I]),(0,$.useEffect)(()=>{H&&J?.id!==H.sessionId&&U(null)},[J?.id,H]),(0,$.useEffect)(()=>{if(!H)return;let e=setTimeout(()=>{U(e=>e===H?null:e)},5e3);return()=>clearTimeout(e)},[H]),(0,$.useEffect)(()=>{if(!I)return;let e=setTimeout(()=>{O(e=>e===I?null:e)},3e4);return()=>clearTimeout(e)},[I]);let[ep,em]=(0,$.useState)(!1);(0,$.useEffect)(()=>{em(!1)},[J?.id]),(0,$.useEffect)(()=>{ee&&em(!0)},[ee]);let eg=async e=>{j(e),J&&await eu(e)},ex=async e=>{await eh(e),j("edit"),d?.()},[ev,e_]=(0,$.useState)(!1),eb=async e=>{if(J&&!ev){e_(!0);try{let r=await (0,rx.branchAgentSession)(J.id,e);L(e=>e+1),i?.(r.session.id)}catch(r){let e=r instanceof Error?r.message:"Failed to branch conversation";gK.toast.error("Branch failed",{description:e})}finally{e_(!1)}}},ew=T.find(e=>e.type===M)?.displayName??("codex"===M?"Codex":"Claude Code"),eS=T.filter(e=>e.available).filter(e=>e.type!==M),eC=(0,$.useCallback)(e=>{var r,s;let i;_((r=v,s=e,i=0===r.length||r.endsWith("\n\n")?"":r.endsWith("\n")?"\n":"\n\n",r+i+(s.replace(/\r?\n/g,"\n").split("\n").map(e=>`> ${e}`).join("\n")+"\n\n"))),requestAnimationFrame(()=>{let e=V.current?.querySelector("textarea");if(!e)return;e.focus();let r=e.value.length;try{e.setSelectionRange(r,r)}catch{}})},[_,v]);(0,$.useImperativeHandle)(h,()=>({submitMessage:async e=>{if(d?.(),J)en(e);else{let r=await ed(C);r&&(O(r.id),en(e,r.id))}}}),[J,ed,en,C,d]);let ej=(0,$.useCallback)((e,r)=>{if(r.length<=2e3)return;e.preventDefault();let s=e.currentTarget,i=s.selectionStart??v.length,n=s.selectionEnd??v.length,o=new TextEncoder().encode(r).length,a=kr(w,o);_(v.slice(0,i)+a+v.slice(n)),b(e=>[...e,{id:w,content:r,size:o}]),S(w+1);let l=i+a.length;requestAnimationFrame(()=>{try{s.setSelectionRange(l,l)}catch{}})},[v,w,_]);async function ek(e,r,s,i){let n=new Set;for(let r of e.matchAll(kt))n.add(Number(r[1]));let o=r.filter(e=>n.has(e.id));if(0===o.length)return e;let a=e;for(let e of o){let r=await s(e.content,i),n=kr(e.id,e.size),o=`<vpaste path="${r.path}" size="${r.size}" />`;a=a.split(n).join(o)}return a}let eN=async e=>{let r=e.text,s=e.files.length>0,i=y.length>0,n=r.trim();if(n||s){A(!0);try{let o;_(""),Y.push(n),d?.();let a=J?.id,l=null;if(!J){if(!(l=await ed(C)))return void _(r);a=l.id,O(l.id)}let c=n;if(i)try{c=(await ek(r,y,eo,a)).trim()}catch(s){let e=s instanceof Error?s.message:"Failed to upload paste";gK.toast.error("Paste upload failed",{description:e}),_(r);return}if(c.length>2e3)try{let e=await eo(c,a);c=`<vpaste path="${e.path}" size="${e.size}" />`}catch(s){let e=s instanceof Error?s.message:"Failed to upload paste";gK.toast.error("Paste upload failed",{description:e}),_(r);return}if(b([]),S(1),s){let r=[];for(let s of(c&&r.push({type:"text",text:c}),e.files))if(s.mediaType&&s.url){let e=s.url.match(/^data:[^;]+;base64,(.+)$/);e&&r.push({type:"image",mediaType:s.mediaType,data:e[1]})}o=r}else o=c;if(k){let e="string"==typeof o?o:o.filter(e=>"text"===e.type).map(e=>e.text).join("\n");if(e.trim()){E(!0);try{let s=await (0,rx.translateText)(e);if(s.error){_(r),b(y),S(w),gK.toast.error("Translation failed",{description:"Disable translation to send the original text."});return}o="string"==typeof o?s.translatedText:o.map(e=>"text"===e.type?{...e,text:s.translatedText}:e)}catch{_(r),b(y),S(w),gK.toast.error("Translation failed",{description:"Disable translation to send the original text."});return}finally{E(!1)}}}l?(console.log(`[AgentConversation] handleSubmit: using freshly started session ${l.id}`),await en(o,l.id)):(console.log(`[AgentConversation] handleSubmit: existing session ${J.id}, status=${Q}`),await en(o))}finally{A(!1)}}},{settings:eD}=(0,cz.useConversationSettings)();return e?(0,z.jsxs)("div",{className:"h-full flex flex-col min-h-0",style:{"--conv-font-size":`${eD.agentFontSize}px`},children:[(0,z.jsxs)("div",{className:"flex-shrink-0 flex items-center justify-between px-4 h-10 border-b border-border/60 bg-muted/20",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2",children:[T.length>1?(0,z.jsxs)(of,{children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsxs)("button",{disabled:er||"running"===Q&&Z.length>0,className:(0,ey.cn)("inline-flex items-center gap-1 rounded-md border bg-muted/50 px-2 py-0.5 text-xs font-medium transition-colors hover:bg-muted",(er||"running"===Q&&Z.length>0)&&"opacity-50 cursor-not-allowed"),children:[T.find(e=>e.type===M)?.displayName??("codex"===M?"Codex":"Claude Code"),(0,z.jsx)(sb,{className:"h-3 w-3 text-muted-foreground"})]})}),(0,z.jsx)(om,{align:"start",children:(0,z.jsx)(ov,{value:M,onValueChange:async e=>{if(!J)return void F(e);let r=await el(e);r?gK.toast.error("Failed to switch agent",{description:r}):F(e)},children:T.map(e=>(0,z.jsx)(o_,{value:e.type,disabled:!e.available,className:"text-xs pl-2 [&>span:first-child]:hidden data-[state=checked]:bg-accent data-[state=checked]:text-accent-foreground",children:e.displayName},e.type))})})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(oN,{className:`h-4 w-4 ${"codex"===M?"text-green-500":"text-violet-500"}`}),(0,z.jsx)("span",{className:"text-sm font-medium",children:"codex"===M?"Codex":"Claude Code"})]}),(0,z.jsx)(jZ,{mode:C,onModeChange:eg}),X.length>=1&&o&&(0,z.jsx)(oj,{targets:X,activeTarget:n?.agent_mode??"local",onTargetChange:o}),J&&(p=J.id.startsWith("remote-"),m="text-muted-foreground",g=(0,z.jsx)(jV,{className:"h-3 w-3"}),x="Disconnected",ee?p&&"connected"!==ei&&null!==ei?"reconnecting"===ei?(m="text-amber-500",g=(0,z.jsx)(jq,{className:"h-3 w-3 animate-pulse"}),x="Reconnecting..."):"disconnected"===ei&&(m="text-red-500",g=(0,z.jsx)(jV,{className:"h-3 w-3"}),x="Remote disconnected"):(m="text-green-500",g=(0,z.jsx)(jq,{className:"h-3 w-3"}),x="Connected"):ep||(m="text-amber-500",g=(0,z.jsx)(jq,{className:"h-3 w-3 animate-pulse"}),x="Connecting..."),(0,z.jsxs)("span",{className:`flex items-center gap-1 text-xs ${m}`,children:[g,x]}))]}),(0,z.jsxs)("div",{className:"flex items-center gap-1",children:[e&&(0,z.jsx)(j3,{projectId:e,branch:r,currentSessionId:J?.id??null,refreshKey:B,pendingTitleSessionId:I,aiTitleOverride:H,onSwitch:e=>{i?.(e)},onDelete:(e,r)=>{if(e===J?.id){let e=r[0];i?.(e?e.id:null)}}}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",onClick:async()=>{console.log("[NewConv] click",{liveStatus:Q,sessionStatus:J?.status,sessionId:J?.id}),("running"!==Q||window.confirm("Current conversation is running. Stop it and start a new conversation?"))&&(await ec(),u?.(),i?.(null))},disabled:er||!J,className:"h-7 w-7",title:"New Conversation",children:(0,z.jsx)(jY,{className:"h-3.5 w-3.5"})}),(0,z.jsxs)(W.Button,{variant:"ghost",size:"sm",onClick:()=>ea(),disabled:"running"!==Q,className:"h-7 text-xs",children:[(0,z.jsx)(d6,{className:"h-3 w-3 mr-1"}),"Stop"]})]})]}),(0,z.jsxs)("div",{className:"flex-1 min-h-0 relative",children:[(0,z.jsxs)(C7,{className:"h-full",initial:"instant",children:[(0,z.jsxs)(C9,{className:"gap-1 p-4",scrollClassName:"edge-scrollbar",children:[J||0!==Z.length?(0,z.jsxs)(j9.Provider,{value:{sendMessage:en,messages:Z,acceptPlan:ex,permissionMode:J?.permissionMode??C,agentType:J?.agentType??M,sessionId:J?.id??null},children:[(0,z.jsxs)("div",{className:"space-y-1 outline-none",ref:K,tabIndex:-1,onKeyDown:q,children:[Z.map((e,r)=>(0,z.jsx)("div",{"data-message-idx":r,..."user"===e.type?{"data-user-msg-idx":r}:{},className:"scroll-mt-2",children:(0,z.jsx)(CW,{message:e,messageIndex:r})},r)),er&&(0,z.jsxs)("div",{className:"flex items-center gap-2 py-4 text-muted-foreground",children:[(0,z.jsx)(jK,{className:"h-4 w-4"}),(0,z.jsx)("span",{className:"text-sm",children:"Connecting to agent..."})]})]}),J&&"running"!==Q&&!er&&Z.length>0&&(0,z.jsx)("div",{className:"mt-3 border-t border-border/50 pt-1.5 pb-1",children:(0,z.jsxs)(of,{children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:(0,ey.cn)("h-7 w-7 rounded-md text-muted-foreground transition-colors","hover:bg-muted hover:text-foreground"),disabled:ev,"aria-label":"Branch conversation",children:ev?(0,z.jsx)(rj,{className:"h-4 w-4 animate-spin"}):(0,z.jsx)(jX,{className:"h-4 w-4"})})}),(0,z.jsxs)(om,{align:"start",className:"w-44 p-1.5",children:[(0,z.jsx)(oy,{className:"px-2 py-1.5",children:(0,z.jsx)("div",{className:"text-xs font-medium",children:"Branch conversation"})}),(0,z.jsxs)(og,{className:"h-8 cursor-pointer items-center gap-2 rounded-md px-2 text-xs",onSelect:()=>eb(),children:[(0,z.jsx)("div",{className:(0,ey.cn)("flex h-5 w-5 shrink-0 items-center justify-center rounded-full","codex"===M?"bg-emerald-500/10 text-emerald-600":"bg-violet-500/10 text-violet-600"),children:(0,z.jsx)(oN,{className:"h-3 w-3"})}),(0,z.jsx)("span",{className:"min-w-0 flex-1 truncate",children:ew}),(0,z.jsx)("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:"current"})]}),eS.length>0&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(ob,{className:"my-1"}),eS.map(e=>(0,z.jsxs)(og,{className:"h-8 cursor-pointer items-center gap-2 rounded-md px-2 text-xs",onSelect:()=>eb(e.type),children:[(0,z.jsx)("div",{className:(0,ey.cn)("flex h-5 w-5 shrink-0 items-center justify-center rounded-full","codex"===e.type?"bg-emerald-500/10 text-emerald-600":"bg-violet-500/10 text-violet-600"),children:(0,z.jsx)(oN,{className:"h-3 w-3"})}),(0,z.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.displayName})]},e.type))]})]})]})})]}):(0,z.jsx)("div",{className:"text-center py-16",children:er||e&&!et?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(jK,{className:"h-6 w-6 mx-auto mb-4"}),(0,z.jsx)("h3",{className:"text-sm font-semibold mb-1 text-foreground",children:"Connecting to agent..."}),(0,z.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:"Setting up the session for this worktree"})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)("div",{className:"mx-auto w-12 h-12 rounded-xl bg-primary/10 flex items-center justify-center mb-4",children:(0,z.jsx)(oN,{className:"h-6 w-6 text-primary/60"})}),(0,z.jsx)("h3",{className:"text-sm font-semibold mb-1 text-foreground",children:"Start a conversation"}),(0,z.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:"Ask the agent to help you with coding tasks in this worktree"})]})}),es&&(0,z.jsxs)("div",{className:"flex items-center gap-2 p-3 bg-red-500/10 rounded-lg text-red-500 text-sm mt-4",children:[(0,z.jsx)(SW,{className:"h-4 w-4"}),es]})]}),(0,z.jsx)(je,{})]}),(0,z.jsx)(j2,{messages:Z,contentRef:K}),(0,z.jsx)(j8,{containerRef:K,onQuote:eC})]}),(0,z.jsx)("div",{className:"flex-shrink-0 border-t border-border/60 p-3",children:(0,z.jsxs)(jF,{onSubmit:eN,accept:"image/*",className:"w-full",children:[(0,z.jsx)(j7,{}),(0,z.jsxs)("div",{className:"relative flex w-full flex-col",children:[k&&(0,z.jsx)("div",{className:"flex items-center pl-12 pr-2 pt-1.5 pb-0.5",children:(0,z.jsxs)("button",{type:"button",onClick:()=>N(!1),className:"inline-flex shrink-0 items-center gap-1.5 rounded-full bg-blue-500/10 text-blue-600 dark:text-blue-400 px-2.5 py-0.5 text-xs font-medium hover:bg-blue-500/20 transition-colors",children:[D?(0,z.jsx)(rj,{className:"size-3 animate-spin"}):(0,z.jsx)(jG,{className:"size-3"}),"Translate",(0,z.jsx)(t8,{className:"size-3"})]})}),(0,z.jsxs)("div",{className:"flex w-full items-center",children:[(0,z.jsxs)(jL,{children:[(0,z.jsx)(jI,{className:"ml-1"}),(0,z.jsxs)(jO,{children:[(0,z.jsx)(jM,{label:"Add images"}),(0,z.jsxs)(jz,{onSelect:()=>{N(!k)},children:[(0,z.jsx)(jG,{className:"mr-2 size-4"}),k?"Disable translation":"Translate"]})]})]}),(0,z.jsx)("div",{ref:V,className:"contents",children:(0,z.jsx)(jT,{value:v,onChange:e=>_(e.target.value),onPasteText:ej,onKeyDown:Y.handleKeyDown,placeholder:J?"Ask the agent to help with your code...":"Type your first message to start...",className:"pr-12"})}),(0,z.jsx)(j$,{className:"absolute bottom-1 right-1",disabled:!v.trim()&&!er||D||R,status:R||D?"submitted":er?"streaming":"ready"})]})]})]})})]}):(0,z.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,z.jsxs)("div",{className:"text-center",children:[(0,z.jsx)("div",{className:"mx-auto w-10 h-10 rounded-xl bg-muted flex items-center justify-center mb-3",children:(0,z.jsx)(oN,{className:"h-5 w-5 text-muted-foreground/50"})}),(0,z.jsx)("p",{className:"text-sm",children:"Select a project to start coding"})]})})});function ki(){return"localhost"===window.location.hostname&&"3000"===window.location.port?"http://localhost:5173":""}async function kn(e,r){let s=await (0,rx.authFetch)(`${ki()}/api/projects/${e}/chat-sessions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branch:r})});if(!s.ok)throw Error("Failed to create chat session");return s.json()}async function ko(e,r){if(!(await (0,rx.authFetch)(`${ki()}/api/chat-sessions/${e}/message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:r})})).ok)throw Error("Failed to send message")}async function ka(e){if(!(await (0,rx.authFetch)(`${ki()}/api/chat-sessions/${e}/stop`,{method:"POST"})).ok)throw Error("Failed to stop generation")}let kl=new Map;function kc(e,r){return`chat:${e}:${r??""}`}function kd({sessionId:e,approvalId:r,tool:s,input:i,resolved:n}){let[o,a]=(0,$.useState)(null),l=function(e){if(null!==e&&"object"==typeof e){if("string"==typeof e.message)return e.message;if("string"==typeof e.prompt)return e.prompt}return JSON.stringify(e)}(i),c=async s=>{if(!o&&!n){a(s?"approve":"deny");try{await rx.api.chatToolApproval(e,r,s)}finally{a(null)}}};return(0,z.jsx)("div",{className:"mx-4 my-1",children:(0,z.jsxs)("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 space-y-2",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2",children:[(0,z.jsx)(oN,{className:"h-3.5 w-3.5 text-amber-500 shrink-0"}),(0,z.jsxs)("span",{className:"text-xs font-medium text-amber-600 dark:text-amber-400",children:["Approval needed · ","spawnAgentSession"===s?"Start a new coding agent":"Send to the coding agent"]})]}),(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all text-foreground/80",style:{fontSize:"var(--conv-font-size, 12px)"},children:l}),n?(0,z.jsxs)(sy,{variant:"default",className:"approved"===n?"bg-green-600 hover:bg-green-700 text-white":"bg-red-600 hover:bg-red-700 text-white",children:["approved"===n?(0,z.jsx)(rS,{className:"h-3 w-3 mr-1"}):(0,z.jsx)(rC,{className:"h-3 w-3 mr-1"}),"approved"===n?"Approved — sent.":"Denied — not sent."]}):(0,z.jsxs)("div",{className:"flex gap-2",children:[(0,z.jsxs)(W.Button,{onClick:()=>c(!0),disabled:null!==o,className:"bg-green-600 hover:bg-green-700 text-white",size:"sm",children:["approve"===o?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,z.jsx)(rS,{className:"h-3.5 w-3.5 mr-1"}),"Approve"]}),(0,z.jsxs)(W.Button,{onClick:()=>c(!1),disabled:null!==o,variant:"destructive",size:"sm",children:["deny"===o?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,z.jsx)(rC,{className:"h-3.5 w-3.5 mr-1"}),"Deny"]})]})]})})}let ku=(0,ew.default)("radio",[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]),kh=(0,ew.default)("triangle-alert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);function kf({messages:e}){let{scrollToBottom:r}=C8(),s=(0,$.useRef)(e.length);return(0,$.useEffect)(()=>{let i=s.current;if(s.current=e.length,!(e.length<=i))for(let s=i;s<e.length;s++){let i=e[s];if("user"===i.type&&i.content.startsWith("[Executor Event:"))return void r({animation:"instant"})}},[e,r]),null}let kp=(0,$.forwardRef)(function({projectId:e,branch:r},s){let{session:i,messages:n,status:o,isInitialized:a,isLoading:l,error:c,sendMessage:d,stopGeneration:u,restartSession:h}=function(e,r){let[s,i]=(0,$.useState)(null),[n,o]=(0,$.useState)([]),[a,l]=(0,$.useState)("stopped"),[c,d]=(0,$.useState)(!1),[u,h]=(0,$.useState)(!1),[f,p]=(0,$.useState)(!1),[m,g]=(0,$.useState)(null),x=(0,$.useRef)(null),v=(0,$.useRef)(()=>{}),_=(0,$.useRef)(null),y=(0,$.useRef)(0),b=(0,$.useRef)({entries:[],status:"stopped"}),w=(0,$.useRef)(!1),S=(0,$.useRef)(!0),C=(0,$.useRef)(!1),j=(0,$.useRef)(0),k=(0,$.useRef)(null),N=(0,$.useRef)(null),D=(0,$.useRef)(0),E=(0,$.useRef)(!1),R=(0,$.useCallback)((e,r=!1)=>{x.current?.readyState!==WebSocket.OPEN&&x.current?.readyState!==WebSocket.CONNECTING&&(0,rx.getFreshToken)(r?{skipCache:!0}:void 0).then(()=>v.current(e))},[]),A=(0,$.useCallback)(n=>{if(x.current?.readyState===WebSocket.OPEN||x.current?.readyState===WebSocket.CONNECTING)return;b.current={entries:[],status:"stopped"},w.current=!1,C.current=!0;let a=new WebSocket((0,rx.getWebSocketUrl)(`/api/chat-sessions/${n}/stream`));x.current=a;let c=j.current;a.onopen=()=>{d(!0),g(null),k.current=Date.now(),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{y.current=0,D.current=0},5e3)},a.onmessage=s=>{if(c===j.current)try{let c=JSON.parse(s.data);if("JsonPatch"in c){var i,n;let e=b.current.entries.filter(Boolean).length;i=b.current,n=c.JsonPatch,b.current=Sm(i,e=>{for(let r of n){let{op:s,path:i,value:n}=r;if("/entries"===i&&"replace"===s&&n?.type==="ENTRY"&&n.content?.type==="system"&&n.content?.content==="__CLEAR_ALL__"){e.entries=[];continue}if(i.startsWith("/entries/")){let r=parseInt(i.replace("/entries/",""),10);if(isNaN(r)||n?.type!=="ENTRY")continue;switch(s){case"add":for(;e.entries.length<=r;)e.entries.push(null);e.entries[r]=n.content;break;case"replace":r<e.entries.length&&(e.entries[r]=n.content);break;case"remove":r<e.entries.length&&e.entries.splice(r,1)}}else"/status"===i&&n?.type==="STATUS"&&(e.status=n.content)}});let r=b.current.entries.filter(Boolean).length;C.current?r!==e&&console.log(`[ChatSession] WS patch added message (${e} → ${r}) but isReplaying=true, state NOT updated`):(r!==e&&console.log(`[ChatSession] New message via WS patch (${e} → ${r}), calling setMessages`),o([...b.current.entries.filter(Boolean)]),l(b.current.status));return}if("Ready"in c){C.current=!1;let e=b.current.entries.filter(Boolean).length;console.log(`[ChatSession] Ready received, isReplaying → false, ${e} messages`),o([...b.current.entries.filter(Boolean)]),l(b.current.status),h(!0);return}if("finished"in c){w.current=!0,a.close(1e3,"finished");return}if("openPreviewFrame"in c)return void(0,_r.openPreviewFrame)(c.openPreviewFrame.projectId,c.openPreviewFrame.url);if("browserCommand"in c){let r=c.browserCommand;e&&(0,_r.sendCommandToIframe)(e,{type:"vibedeckx-command",...r}).then(e=>{e&&a.readyState===WebSocket.OPEN&&a.send(JSON.stringify({type:"browser_result",result:{id:r.id,success:e.success??!1,error:e.error,content:e.content,found:e.found,tag:e.tag,text:e.text}}))});return}if("error"in c){g(c.error),"Session not found"===c.error&&(e&&kl.delete(kc(e,r)),w.current=!0);return}}catch(e){console.error("[ChatSession] Failed to parse message:",e)}},a.onclose=n=>{let o,a;if(c!==j.current)return;d(!1),x.current=null,N.current&&(clearTimeout(N.current),N.current=null);let l=4e3===n.code,u=k.current?Date.now()-k.current:0;if(k.current=null,!l&&u>0&&u<5e3){if(D.current++,D.current>=3)return E.current?void g("Unable to connect to remote server. Please check the server configuration."):(e&&kl.delete(kc(e,r)),i(null),g(null),y.current=0,D.current=0,void(S.current=!0))}else u>=5e3&&(D.current=0);if(w.current||1e3===n.code)return;if(y.current>=10)return void g("Unable to connect to server.");let h=(a=(o=Math.min(3e4,1e3*Math.pow(2,y.current)))*Math.random()*.25,o+a);y.current++,_.current=setTimeout(()=>{s?.id&&!w.current&&R(s.id,!0)},h)},a.onerror=()=>{}},[s?.id,R]);(0,$.useEffect)(()=>{v.current=A},[A]);let M=(0,$.useCallback)(async()=>{if(!e)return null;let s=j.current;g(null),h(!1),E.current=!1;let n=kc(e,r),a=kl.get(n);if(a)return i(a),l(a.status),R(a.id),a;p(!0);try{let{session:a,messages:c}=await kn(e,r);if(j.current!==s)return null;return kl.set(n,a),i(a),l(a.status),c&&c.length>0&&o(c),R(a.id),a}catch(e){if(j.current!==s)return null;return g(e instanceof Error?e.message:"Failed to start session"),E.current=!0,null}finally{j.current===s&&p(!1)}},[e,r,R]),F=(0,$.useCallback)(async e=>{let r=s?.id;if(r&&e.trim())try{await ko(r,e.trim())}catch(r){let e=r instanceof Error?r.message:"Failed to send message";g(e),gK.toast.error("Failed to send message",{description:e})}},[s?.id]),T=(0,$.useCallback)(async()=>{if(s?.id)try{await ka(s.id)}catch(e){console.error("[ChatSession] Failed to stop generation:",e)}},[s?.id]),P=(0,$.useCallback)(async()=>{if(s?.id)try{await rx.api.resetChatSession(s.id),o([]),l("stopped"),b.current={entries:[],status:"stopped"}}catch(e){console.error("[ChatSession] Failed to reset session:",e),gK.toast.error("Failed to start new conversation")}},[s?.id]);return(0,$.useEffect)(()=>()=>{x.current&&(w.current=!0,x.current.close()),_.current&&clearTimeout(_.current),N.current&&clearTimeout(N.current)},[]),(0,$.useEffect)(()=>{x.current&&(x.current.close(1e3,"branch-switch"),x.current=null),_.current&&(clearTimeout(_.current),_.current=null),N.current&&(clearTimeout(N.current),N.current=null),j.current+=1,i(null),l("stopped"),d(!1),h(!1),g(null),p(!1),b.current={entries:[],status:"stopped"},w.current=!1,y.current=0,k.current=null,D.current=0,E.current=!1,S.current=!0},[e,r]),(0,$.useEffect)(()=>{!S.current||!e||s||f||E.current||(S.current=!1,M())},[e,s,f,M]),(0,$.useEffect)(()=>{!s?.id||c||w.current||R(s.id)},[s?.id,c,R]),(0,$.useEffect)(()=>{let e=()=>{if("visible"!==document.visibilityState||!s?.id||w.current)return;let e=x.current,r=b.current.entries.filter(Boolean).length;console.log(`[ChatSession] Tab visible: ws.readyState=${e?.readyState??"null"}, isReplaying=${C.current}, messages=${r}`),e&&e.readyState===WebSocket.OPEN&&e.close(4e3,"visibility-recovery")};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[s?.id]),{session:s,messages:n,status:a,isConnected:c,isInitialized:u,isLoading:f,error:m,sendMessage:F,stopGeneration:T,restartSession:P}}(e,r),{settings:f}=(0,cz.useConversationSettings)();(0,$.useImperativeHandle)(s,()=>({sendMessage:async e=>{let r=e.trim();r&&await d(r)}}),[d]);let[p,m]=(0,$.useState)(""),[g,x]=(0,$.useState)(!1);(0,$.useEffect)(()=>{i?.eventListeningEnabled!=null&&x(i.eventListeningEnabled)},[i?.eventListeningEnabled]);let v="running"===o,_=(0,$.useCallback)(async e=>{let r=e.text.trim();r&&(m(""),await d(r))},[d]);return e?(0,z.jsxs)("div",{className:"h-full flex flex-col min-h-0",style:{"--conv-font-size":`${f.chatFontSize}px`},children:[(0,z.jsxs)("div",{className:"flex-shrink-0 flex items-center justify-between px-4 h-10 border-b border-border/60 bg-muted/20",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2",children:[(0,z.jsx)(gY,{className:"h-3.5 w-3.5 text-primary"}),(0,z.jsx)("span",{className:"text-xs font-medium text-foreground",children:"Main Chat"}),v&&(0,z.jsx)(rj,{className:"h-3 w-3 animate-spin text-primary/60"})]}),i&&(0,z.jsxs)("div",{className:"flex items-center gap-1",children:[(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",onClick:async()=>{let e=!g;try{await rx.api.setChatEventListening(i.id,e),x(e)}catch{gK.toast.error("Failed to toggle event listening")}},className:`h-7 w-7 ${g?"text-amber-500":""}`,title:g?"Listening to executor events (click to disable)":"Listen to executor events (click to enable)",children:(0,z.jsx)(ku,{className:"h-3.5 w-3.5"})}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",onClick:()=>h(),disabled:v,className:"h-7 w-7",title:"New Conversation",children:(0,z.jsx)(jY,{className:"h-3.5 w-3.5"})})]})]}),(0,z.jsxs)(C7,{className:"flex-1 min-h-0",initial:"instant",children:[(0,z.jsx)(kf,{messages:n}),(0,z.jsxs)(C9,{className:"gap-4 p-4",children:[l&&0===n.length&&(0,z.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,z.jsx)(rj,{className:"h-6 w-6 animate-spin text-muted-foreground"})}),!l&&a&&0===n.length&&(0,z.jsxs)("div",{className:"text-center py-16",children:[(0,z.jsx)("div",{className:"mx-auto w-12 h-12 rounded-xl bg-primary/10 flex items-center justify-center mb-4",children:(0,z.jsx)(gY,{className:"h-6 w-6 text-primary/60"})}),(0,z.jsx)("h3",{className:"text-sm font-semibold mb-1 text-foreground",children:"Start a conversation"}),(0,z.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:"Chat with the AI assistant about your project"})]}),n.map((e,r)=>{if("turn_end"===e.type)return(0,z.jsxs)("div",{className:"mx-4 my-3 flex items-center gap-2","aria-hidden":!0,children:[(0,z.jsx)("div",{className:"h-px flex-1 bg-border"}),(0,z.jsx)("div",{className:"h-1 w-1 shrink-0 rounded-full bg-border"}),(0,z.jsx)("div",{className:"h-px flex-1 bg-border"})]},r);if("user"===e.type&&e.content.startsWith("[System Invariant Violation]")){let s=e.content.replace(/^\[System Invariant Violation\]\n?/,"");return(0,z.jsxs)("div",{className:"mx-4 my-2 flex gap-2 rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2",children:[(0,z.jsx)(kh,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-500"}),(0,z.jsxs)("div",{className:"min-w-0",children:[(0,z.jsx)("div",{className:"text-xs font-medium text-amber-600 dark:text-amber-400",children:"System invariant correction"}),(0,z.jsx)("div",{className:"mt-0.5 whitespace-pre-wrap text-muted-foreground",style:{fontSize:"var(--conv-font-size, 12px)"},children:s})]})]},r)}return"user"===e.type?(0,z.jsx)(b9,{from:"user",children:(0,z.jsx)(we,{style:{fontSize:"var(--conv-font-size, 14px)"},children:e.content})},r):"assistant"===e.type?(0,z.jsx)(b9,{from:"assistant",children:(0,z.jsx)(we,{style:{fontSize:"var(--conv-font-size, 14px)"},children:(0,z.jsx)(wt,{children:e.content})})},r):"tool_use"===e.type?(0,z.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 text-xs text-muted-foreground",children:[(0,z.jsx)(_o,{className:"w-3.5 h-3.5 animate-pulse"}),(0,z.jsx)("span",{children:function(e){switch(e){case"getExecutorStatus":return"Checking executor status...";case"getAgentConversation":return"Checking agent conversation...";case"listTerminals":return"Listing terminals...";case"runInTerminal":return"Sending command to terminal...";case"spawnAgentSession":return"Starting a coding agent...";case"sendToAgentSession":return"Sending a message to the agent...";default:return`Running ${e}...`}}(e.tool)})]},r):"tool_result"===e.type?(0,z.jsx)("div",{className:"px-4 py-2",children:(0,z.jsxs)("details",{className:"text-xs text-muted-foreground",children:[(0,z.jsx)("summary",{className:"cursor-pointer hover:text-foreground",children:"Tool result"}),(0,z.jsx)("pre",{className:"mt-1 p-2 bg-muted/50 rounded overflow-x-auto whitespace-pre-wrap",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.output})]})},r):"tool_approval_request"===e.type?i?(0,z.jsx)(kd,{sessionId:i.id,approvalId:e.approvalId,tool:e.tool,input:e.input,resolved:e.resolved},r):null:"error"===e.type?(0,z.jsx)("div",{className:"mx-auto max-w-[90%] rounded-lg border border-destructive/50 bg-destructive/10 px-4 py-3 text-destructive",style:{fontSize:"var(--conv-font-size, 14px)"},children:e.message},r):null}),c&&(0,z.jsx)("div",{className:"mx-auto max-w-[90%] rounded-lg border border-destructive/50 bg-destructive/10 px-4 py-3 text-sm text-destructive",children:c})]}),(0,z.jsx)(je,{})]}),(0,z.jsxs)("div",{className:"flex-shrink-0 border-t border-border/60 p-3",children:[v&&(0,z.jsx)("div",{className:"flex justify-center mb-2",children:(0,z.jsxs)(W.Button,{variant:"outline",size:"sm",onClick:u,className:"gap-1.5",children:[(0,z.jsx)(d6,{className:"h-3 w-3"}),"Stop generating"]})}),(0,z.jsxs)(jF,{onSubmit:_,className:"w-full",children:[(0,z.jsx)(jT,{disabled:!a||v,placeholder:a?v?"Waiting for response...":"Type a message...":"Connecting...",className:"pr-12",value:p,onChange:e=>m(e.currentTarget.value)}),(0,z.jsx)(j$,{className:"absolute bottom-1 right-1",disabled:!a||v||!p.trim()})]})]})]}):(0,z.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,z.jsxs)("div",{className:"text-center",children:[(0,z.jsx)("div",{className:"mx-auto w-10 h-10 rounded-xl bg-muted flex items-center justify-center mb-3",children:(0,z.jsx)(gY,{className:"h-5 w-5 text-muted-foreground/50"})}),(0,z.jsx)("p",{className:"text-sm",children:"Select a project to start chatting"})]})})}),km=(0,ew.default)("archive",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]),kg=(0,ew.default)("archive-restore",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]]);function kx({task:e,onUpdate:r,onDelete:s,onArchive:i,onUnarchive:n,archivedView:o,onClick:a,worktrees:l,assignedBranches:c,onAssign:d}){let[u,h]=(0,$.useState)(!1),[f,p]=(0,$.useState)(e.title),m=(0,$.useRef)(null);(0,$.useEffect)(()=>{u&&(m.current?.focus(),m.current?.select())},[u]),(0,$.useEffect)(()=>{p(e.title)},[e.title]);let g=()=>{h(!1);let s=f.trim();s&&s!==e.title?r(e.id,{title:s}):p(e.title)},x="done"===e.status||"cancelled"===e.status;return(0,z.jsxs)(lS,{className:"group cursor-pointer",onClick:()=>a?.(e),children:[(0,z.jsx)(lj,{className:"w-10",onClick:e=>e.stopPropagation(),children:(0,z.jsx)(eb,{checked:"done"===e.status,onCheckedChange:s=>{r(e.id,{status:s?"done":"todo"})}})}),(0,z.jsx)(lj,{className:"font-medium",children:u?(0,z.jsx)("input",{ref:m,className:"w-full bg-transparent border-b border-primary outline-none text-sm py-0.5",value:f,onChange:e=>p(e.target.value),onBlur:g,onClick:e=>e.stopPropagation(),onKeyDown:r=>{"Enter"===r.key&&g(),"Escape"===r.key&&(p(e.title),h(!1))}}):(0,z.jsxs)("div",{children:[(0,z.jsx)("span",{className:`cursor-pointer hover:underline text-sm ${x?"line-through text-muted-foreground":""}`,onClick:e=>{e.stopPropagation(),h(!0)},children:e.title}),e.description&&(0,z.jsx)("p",{className:"text-xs text-muted-foreground truncate max-w-[400px] mt-0.5",children:e.description.length>80?e.description.slice(0,80)+"...":e.description})]})}),(0,z.jsx)(lj,{onClick:e=>e.stopPropagation(),children:(0,z.jsxs)(of,{children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsx)("button",{className:"focus:outline-none",children:(0,z.jsx)(sy,{variant:"outline",className:`cursor-pointer text-xs ${af[e.status].color}`,children:af[e.status].label})})}),(0,z.jsx)(om,{align:"start",children:am.map(s=>(0,z.jsxs)(og,{onClick:()=>r(e.id,{status:s}),children:[(0,z.jsx)("span",{className:`inline-block w-2 h-2 rounded-full mr-2 ${af[s].color}`}),af[s].label]},s))})]})}),(0,z.jsx)(lj,{onClick:e=>e.stopPropagation(),children:(0,z.jsxs)(of,{children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsx)("button",{className:"focus:outline-none",children:(0,z.jsx)(sy,{variant:"outline",className:`cursor-pointer text-xs ${ap[e.priority].color}`,children:ap[e.priority].label})})}),(0,z.jsx)(om,{align:"start",children:ag.map(s=>(0,z.jsxs)(og,{onClick:()=>r(e.id,{priority:s}),children:[(0,z.jsx)("span",{className:`inline-block w-2 h-2 rounded-full mr-2 ${ap[s].color}`}),ap[s].label]},s))})]})}),(0,z.jsx)(lj,{onClick:e=>e.stopPropagation(),children:(0,z.jsxs)(of,{children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsx)("button",{className:"focus:outline-none",children:(0,z.jsxs)(sy,{variant:"outline",className:`cursor-pointer text-xs font-mono ${null!==e.assigned_branch?"bg-accent text-accent-foreground border-transparent":"text-muted-foreground"}`,children:[(0,z.jsx)(rb,{className:"h-3 w-3 mr-1"}),null!==e.assigned_branch?""===e.assigned_branch?"main":e.assigned_branch:"Unassigned"]})})}),(0,z.jsxs)(om,{align:"start",children:[null!==e.assigned_branch&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(og,{onClick:()=>d(e.id,null),children:"Unassign"}),(0,z.jsx)(ob,{})]}),l.filter(r=>{let s=null===r.branch?"":r.branch;return!(e.assigned_branch===s||c.has(s))}).map(r=>{let s=null===r.branch?"":r.branch,i=r.branch??"main";return(0,z.jsxs)(og,{onClick:()=>d(e.id,s),children:[(0,z.jsx)(rb,{className:"h-3 w-3 mr-2"}),i]},s)})]})]})}),(0,z.jsx)(lj,{className:"text-muted-foreground text-[10.5px] font-mono",children:new Date(e.created_at).toLocaleDateString()}),(0,z.jsx)(lj,{className:"w-10",onClick:e=>e.stopPropagation(),children:(0,z.jsxs)("div",{className:"flex items-center gap-0.5",children:[o?(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",title:"Unarchive",onClick:()=>n(e.id),children:(0,z.jsx)(kg,{className:"h-3.5 w-3.5 text-muted-foreground"})}):(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",title:"Archive",onClick:()=>i(e.id),children:(0,z.jsx)(km,{className:"h-3.5 w-3.5 text-muted-foreground"})}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",title:"Delete",onClick:()=>s(e.id),children:(0,z.jsx)(rl,{className:"h-3.5 w-3.5 text-muted-foreground"})})]})})]})}let kv={todo:0,in_progress:1,done:2,cancelled:3},k_={urgent:0,high:1,medium:2,low:3};function ky({tasks:e,onUpdate:r,onDelete:s,onArchive:i,onUnarchive:n,archivedView:o,worktrees:a,onAssign:l}){let[c,d]=(0,$.useState)(null),[u,h]=(0,$.useState)("asc"),[f,p]=(0,$.useState)(null),[m,g]=(0,$.useState)(!1),x=e=>{c===e?h(e=>"asc"===e?"desc":"asc"):(d(e),h("asc"))},v=(0,$.useMemo)(()=>{if(!c)return e;let r="asc"===u?1:-1;return[...e].sort((e,s)=>{switch(c){case"title":return r*e.title.localeCompare(s.title);case"status":return r*(kv[e.status]-kv[s.status]);case"priority":return r*(k_[e.priority]-k_[s.priority]);case"created_at":return r*(new Date(e.created_at).getTime()-new Date(s.created_at).getTime());default:return 0}})},[e,c,u]),_=e=>c!==e?null:"asc"===u?" ↑":" ↓",y=(0,$.useMemo)(()=>new Set(e.filter(e=>null!==e.assigned_branch).map(e=>e.assigned_branch)),[e]);return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(ly,{children:[(0,z.jsx)(lb,{children:(0,z.jsxs)(lS,{children:[(0,z.jsx)(lC,{className:"w-10"}),(0,z.jsxs)(lC,{className:"cursor-pointer select-none",onClick:()=>x("title"),children:["Title",_("title")]}),(0,z.jsxs)(lC,{className:"cursor-pointer select-none w-32",onClick:()=>x("status"),children:["Status",_("status")]}),(0,z.jsxs)(lC,{className:"cursor-pointer select-none w-28",onClick:()=>x("priority"),children:["Priority",_("priority")]}),(0,z.jsx)(lC,{className:"w-32",children:"Assign"}),(0,z.jsxs)(lC,{className:"cursor-pointer select-none w-28",onClick:()=>x("created_at"),children:["Created",_("created_at")]}),(0,z.jsx)(lC,{className:"w-10"})]})}),(0,z.jsxs)(lw,{children:[v.map(e=>(0,z.jsx)(kx,{task:e,onUpdate:r,onDelete:s,onArchive:i,onUnarchive:n,archivedView:o,onClick:e=>{p(e),g(!0)},worktrees:a,assignedBranches:y,onAssign:l},e.id)),0===e.length&&(0,z.jsx)(lS,{children:(0,z.jsx)("td",{colSpan:7,className:"text-center text-muted-foreground py-12 text-sm",children:(0,z.jsxs)("div",{className:"flex flex-col items-center gap-1",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-foreground/60",children:"No tasks yet"}),(0,z.jsx)("p",{className:"text-xs text-muted-foreground",children:"Create one to get started."})]})})})]})]}),(0,z.jsx)(ax,{task:f,open:m,onOpenChange:g})]})}function kb({open:e,onOpenChange:r,onSubmit:s}){let[i,n]=(0,$.useState)(""),[o,a]=(0,$.useState)("todo"),[l,c]=(0,$.useState)("medium");return(0,z.jsx)(t7,{open:e,onOpenChange:r,children:(0,z.jsxs)(rt,{className:"sm:max-w-md max-h-[85vh] flex flex-col",children:[(0,z.jsx)(rr,{children:(0,z.jsx)(ri,{children:"Create Task"})}),(0,z.jsxs)("form",{onSubmit:e=>{e.preventDefault(),i.trim()&&(s({description:i.trim(),status:o,priority:l}),n(""),a("todo"),c("medium"),r(!1))},className:"space-y-4 overflow-y-auto min-h-0 px-0.5",children:[(0,z.jsx)("div",{className:"space-y-2",children:(0,z.jsx)(ra,{placeholder:"Describe the task...",value:i,onChange:e=>n(e.target.value),className:"max-h-[40vh] focus-visible:border-input focus-visible:ring-0",rows:3,autoFocus:!0})}),(0,z.jsxs)("div",{className:"flex gap-3",children:[(0,z.jsxs)("div",{className:"flex-1 space-y-1",children:[(0,z.jsx)("label",{className:"text-xs text-muted-foreground",children:"Status"}),(0,z.jsxs)(cg,{value:o,onValueChange:e=>a(e),children:[(0,z.jsx)(cv,{children:(0,z.jsx)(cx,{})}),(0,z.jsx)(c_,{children:am.map(e=>(0,z.jsx)(cy,{value:e,children:af[e].label},e))})]})]}),(0,z.jsxs)("div",{className:"flex-1 space-y-1",children:[(0,z.jsx)("label",{className:"text-xs text-muted-foreground",children:"Priority"}),(0,z.jsxs)(cg,{value:l,onValueChange:e=>c(e),children:[(0,z.jsx)(cv,{children:(0,z.jsx)(cx,{})}),(0,z.jsx)(c_,{children:ag.map(e=>(0,z.jsx)(cy,{value:e,children:ap[e].label},e))})]})]})]}),(0,z.jsxs)(rs,{children:[(0,z.jsx)(W.Button,{type:"button",variant:"outline",onClick:()=>r(!1),children:"Cancel"}),(0,z.jsx)(W.Button,{type:"submit",disabled:!i.trim(),children:"Create"})]})]})]})})}let kw=[{value:"all",label:"All"},{value:"todo",label:"Todo"},{value:"in_progress",label:"Doing"},{value:"done",label:"Done"},{value:"cancelled",label:"Cancelled"},{value:"archived",label:"Archived"}];function kS({projectId:e,tasks:r,loading:s,worktrees:i,onCreateTask:n,onUpdateTask:o,onDeleteTask:a,onArchiveTask:l,onUnarchiveTask:c}){let[d,u]=(0,$.useState)(!1),[h,f]=(0,$.useState)("all"),p=(0,$.useMemo)(()=>r.filter(e=>null===e.archived_at),[r]),m=(0,$.useMemo)(()=>r.filter(e=>null!==e.archived_at),[r]),g=(0,$.useMemo)(()=>{let e={all:p.length,todo:0,in_progress:0,done:0,cancelled:0,archived:m.length};for(let r of p)e[r.status]++;return e},[p,m]),x=(0,$.useMemo)(()=>"archived"===h?m:"all"===h?p:p.filter(e=>e.status===h),[p,m,h]),v="archived"===h;return e?(0,z.jsxs)("div",{className:"flex flex-col h-full",children:[(0,z.jsx)(lx,{title:"Tasks",count:p.length,actions:(0,z.jsxs)(W.Button,{size:"sm",onClick:()=>u(!0),className:"shadow-sm",children:[(0,z.jsx)(eS,{className:"h-3.5 w-3.5 mr-1.5"}),"New Task"]})}),(0,z.jsx)(lv,{children:kw.map(e=>(0,z.jsx)(l_,{active:h===e.value,count:g[e.value],onClick:()=>f(e.value),children:e.label},e.value))}),(0,z.jsx)("div",{className:"flex-1 overflow-auto px-5 edge-scrollbar",children:s?(0,z.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground text-sm",children:"Loading tasks..."}):(0,z.jsx)(ky,{tasks:x,onUpdate:o,onDelete:a,onArchive:l,onUnarchive:c,archivedView:v,worktrees:i,onAssign:(e,r)=>{o(e,{assigned_branch:r})}})}),(0,z.jsx)(kb,{open:d,onOpenChange:u,onSubmit:n})]}):(0,z.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:(0,z.jsxs)("div",{className:"text-center",children:[(0,z.jsx)("div",{className:"mx-auto w-10 h-10 rounded-xl bg-muted flex items-center justify-center mb-3",children:(0,z.jsx)(eS,{className:"h-5 w-5 text-muted-foreground/50"})}),(0,z.jsx)("p",{className:"text-sm",children:"Select a project to view tasks."})]})})}let kC={completed:"/sounds/sound1.mp3","main-completed":"/sounds/sound2.mp3"};function kj(e,r){return`${e}:${r??""}`}let kk="vibedeckx:completion-notifications";function kN(e){return"object"==typeof e&&null!==e&&"string"==typeof e.id&&"string"==typeof e.projectId&&("string"==typeof e.branch||null===e.branch)&&("string"==typeof e.sessionId||null===e.sessionId||void 0===e.sessionId)&&("completed"===e.type||"main-completed"===e.type)&&"number"==typeof e.at&&"boolean"==typeof e.read}let kD=new Map,kE=new Set,kR=(0,ew.default)("bell",[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]]),kA={completed:{label:"Agent finished",dot:"bg-lime-400"},"main-completed":{label:"Chat finished",dot:"bg-emerald-500"}};function kM({notifications:e,unreadCount:r,projects:s,onNavigate:i,markRead:n,markAllRead:o,remove:a,clear:l}){return(0,z.jsxs)(of,{children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsxs)(W.Button,{variant:"ghost",size:"icon-sm",className:"relative","aria-label":r>0?`${r} unread completion notifications`:"Completion notifications",children:[(0,z.jsx)(kR,{className:"h-4 w-4"}),r>0&&(0,z.jsx)("span",{className:"absolute -top-0.5 -right-0.5 flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[9px] font-semibold leading-none text-primary-foreground",children:r>9?"9+":r})]})}),(0,z.jsxs)(om,{align:"end",className:"w-80 p-0",children:[(0,z.jsxs)("div",{className:"flex items-center justify-between px-3 py-2",children:[(0,z.jsx)("span",{className:"text-[12.5px] font-semibold text-foreground",children:"Notifications"}),e.length>0&&(0,z.jsxs)("div",{className:"flex items-center gap-1",children:[(0,z.jsxs)("button",{onClick:o,disabled:0===r,className:"flex items-center gap-1 rounded px-1.5 py-0.5 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:pointer-events-none disabled:opacity-40",title:"Mark all read",children:[(0,z.jsx)(li,{className:"h-3 w-3"}),"Mark all read"]}),(0,z.jsx)("button",{onClick:l,className:"rounded px-1.5 py-0.5 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",title:"Clear all",children:"Clear"})]})]}),(0,z.jsx)("div",{className:"max-h-[60vh] overflow-y-auto border-t border-border",children:0===e.length?(0,z.jsx)("div",{className:"px-3 py-8 text-center text-[12px] text-muted-foreground/70",children:"No completions yet."}):e.map(e=>{let r,o=kA[e.type];return(0,z.jsxs)(og,{onSelect:()=>{n(e.id),i(e.projectId,e.branch,e.sessionId)},className:(0,ey.cn)("group flex flex-col items-start gap-0.5 rounded-none px-3 py-2",!e.read&&"bg-primary/[0.08]"),children:[(0,z.jsxs)("div",{className:"flex w-full items-center gap-2",children:[(0,z.jsx)("span",{className:(0,ey.cn)("h-[7px] w-[7px] shrink-0 rounded-full",o.dot)}),(0,z.jsx)("span",{className:(0,ey.cn)("min-w-0 flex-1 truncate text-[12.5px]",e.read?"text-foreground/70":"font-medium text-foreground"),children:(r=e.projectId,s.find(e=>e.id===r)?.name??"Unknown project")}),(0,z.jsx)("span",{className:"shrink-0 text-[10.5px] text-muted-foreground/70",children:function(e){let r=Math.max(0,Math.round((Date.now()-e)/1e3));if(r<60)return"just now";let s=Math.round(r/60);if(s<60)return`${s}m ago`;let i=Math.round(s/60);if(i<24)return`${i}h ago`;let n=Math.round(i/24);return`${n}d ago`}(e.at)}),(0,z.jsx)("button",{onClick:r=>{r.stopPropagation(),a(e.id)},className:"shrink-0 rounded p-0.5 text-muted-foreground/60 opacity-0 transition-all hover:bg-muted hover:text-foreground group-hover:opacity-100",title:"Dismiss",children:(0,z.jsx)(t8,{className:"h-3 w-3"})})]}),(0,z.jsxs)("div",{className:"flex w-full items-center gap-1.5 pl-[15px] text-[11px] text-muted-foreground",children:[(0,z.jsx)("span",{className:"font-mono truncate",children:e.branch??"main"}),(0,z.jsx)("span",{className:"text-muted-foreground/50",children:"·"}),(0,z.jsx)("span",{className:"shrink-0",children:o.label})]})]},e.id)})})]})]})}function kF(e){if(null===e)return"尚未连接";let r=Math.max(0,Math.round((Date.now()-e)/1e3));if(r<60)return`${r} 秒前`;let s=Math.floor(r/60);return s<60?`${s} 分钟前`:`${Math.floor(s/60)} 小时前`}function kT(){let{state:e,lastEventAt:r,reconnect:s}=(0,aj.useConnectionStatus)(),[,i]=(0,$.useState)(0);if((0,$.useEffect)(()=>{let e=setInterval(()=>i(e=>e+1),5e3);return()=>clearInterval(e)},[]),"stale"===e)return(0,z.jsxs)("button",{type:"button",onClick:s,title:`实时更新已断开 \xb7 上次更新 ${kF(r)} \xb7 点击重新连接`,className:"flex items-center gap-1.5 rounded-full border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[11px] font-medium text-amber-600 transition-colors hover:bg-amber-500/20",children:[(0,z.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500"}),"实时更新已断开"]});let n="live"===e;return(0,z.jsx)("span",{title:n?`实时更新正常 \xb7 上次更新 ${kF(r)}`:"正在连接实时更新…",className:"flex items-center px-1","aria-label":n?"实时更新正常":"正在连接实时更新",children:(0,z.jsx)("span",{className:n?"h-1.5 w-1.5 rounded-full bg-emerald-500":"h-1.5 w-1.5 animate-pulse rounded-full bg-muted-foreground/40"})})}let kP=new Set(["workspace","tasks","schedules","remote-servers","settings","project-info"]),kB="tasks";function kL(){let e=window.location.pathname,r=new URLSearchParams(window.location.search),s=r.get("project");if(s){let e=r.get("tab");return{projectId:s,tab:e&&kP.has(e)?e:kB,branch:r.get("branch")}}let i=e.split("/").filter(Boolean);if(1===i.length&&kP.has(i[0])){let e=i[0];if("remote-servers"===e||"settings"===e)return{projectId:null,tab:e,branch:null}}let n=null,o=kB;if("p"===i[0]&&i[1]){n=i[1];let e=i[2];e&&kP.has(e)&&(o=e)}return{projectId:n,tab:o,branch:r.get("branch")}}function kI(e){let{projectId:r,tab:s,branch:i}=e;if("remote-servers"===s||"settings"===s)return`/${s}`;if(!r)return"/";let n=`/p/${r}/${s??kB}`;return i&&(n+=`?branch=${encodeURIComponent(i)}`),n}function kO(e,r,s,i){return!!e&&e.projectId===r&&e.branch===s&&e.sessionId===i}function kz(){var e,r,s,i,n;let o,a,l,c,d,{projectId:u,tab:h,branch:f}=function(){let[e,r]=(0,$.useState)(kL);return(0,$.useEffect)(()=>{let e=()=>r(kL());return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[]),e}(),[p,m]=(0,$.useState)(()=>new URLSearchParams(window.location.search).get("session")),[g,x]=(0,$.useState)(null),v=(0,$.useCallback)(e=>{m(e);let r=new URL(window.location.href);e?r.searchParams.set("session",e):r.searchParams.delete("session"),window.history.replaceState(null,"",r.toString())},[]);(0,$.useEffect)(()=>{let e=()=>{m(new URLSearchParams(window.location.search).get("session"))};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[]),(0,$.useEffect)(()=>{if(new URLSearchParams(window.location.search).has("project")){let e=kI({projectId:u,tab:h,branch:f});window.history.replaceState(null,"",e)}},[]);let[_,y]=(0,$.useState)(!1),[b,w]=(0,$.useState)(!1),[S,C]=(0,$.useState)(!1),[j,k]=(0,$.useState)(null),[N,D]=(0,$.useState)(f),[E,R]=(0,$.useState)(h),[A,M]=(0,$.useState)(0),[F,T]=(0,$.useState)(0),P=(0,$.useRef)(null),[B,L]=(0,$.useState)(void 0),[I,O]=(0,$.useTransition)(),{projects:H,currentProject:U,loading:K,addProject:q,createProject:V,updateProject:Y,deleteProject:G,selectProject:X}=function(e){let[r,s]=(0,$.useState)([]),[i,n]=(0,$.useState)(null),[o,a]=(0,$.useState)(!0),l=(0,$.useCallback)(async()=>{a(!0);try{let r=await rx.api.getProjects();if(s(r),r.length>0&&!i){let s=e?r.find(r=>r.id===e):null;n(s??r[0])}}finally{a(!1)}},[i,e]);(0,$.useEffect)(()=>{l()},[]);let c=async(e,r)=>{let o=await rx.api.updateProject(e,r);return s(r=>r.map(r=>r.id===e?o:r)),i?.id===e&&n(o),o},d=async e=>{await rx.api.deleteProject(e),s(r=>r.filter(r=>r.id!==e)),i?.id===e&&n(r.find(r=>r.id!==e)??null)};return{projects:r,currentProject:i,loading:o,addProject:e=>{s(r=>[e,...r]),n(e)},createProject:async e=>{let r=await rx.api.createProject(e);return s(e=>[r,...e]),n(r),r},updateProject:c,deleteProject:d,selectProject:e=>{n(e)},refresh:l}}(u);U?.id!==B&&(void 0!==B&&D(null),L(U?.id));let{worktrees:J,loading:Z,refetch:Q}=function(e){let[r,s]=(0,$.useState)([]),[i,n]=(0,$.useState)(!0),[o,a]=(0,$.useState)(null),l=(0,$.useCallback)(async()=>{if(!e){s([]),a(null),n(!1);return}n(!0);try{let r=await rx.api.getProjectWorktrees(e);s(r)}catch(e){console.error("Failed to fetch worktrees:",e),s([{branch:null}])}finally{a(e),n(!1)}},[e]);return(0,$.useEffect)(()=>{l()},[l]),{worktrees:r,loading:i||o!==e,refetch:l}}(U?.id??null),{statuses:ee,defaultTarget:et,repositoryLabel:er,setTarget:es,refetch:ei}=function(e,r){let[s,i]=(0,$.useState)(new Map),[n,o]=(0,$.useState)(null),[a,l]=(0,$.useState)(null),[c,d]=(0,$.useState)(0),[u,h]=(0,$.useState)(e);e!==u&&(h(e),i(new Map),o(null),l(null));let f=(0,$.useCallback)(()=>d(e=>e+1),[]);return(0,$.useEffect)(()=>{let s=r.map(e=>e.branch).filter(e=>null!==e),n=!1;return(async()=>{var r,a;let c;if(!e||0===s.length){n||(i(new Map),o(null),l(null));return}let d=(r=r=>localStorage.getItem(ak(e,r)),s.map(e=>{let s=r(e);return s?{branch:e,target:s}:{branch:e}})),u=await rx.api.getMergeStatus(e,d);if(n||!u.ok)return;let h=new Map;for(let e of u.entries)!e.error&&e.target&&e.status&&h.set(e.branch,{branch:e.branch,status:e.status,unmergedCount:e.unmergedCount??0,dirty:e.dirty??!1,target:e.target});let p=(a=u.entries,c=new Set(d.filter(e=>void 0!==e.target).map(e=>e.branch)),a.filter(e=>"target-not-found"===e.error&&c.has(e.branch)).map(e=>e.branch));for(let r of p)try{localStorage.removeItem(ak(e,r))}catch{}i(h),o(function(e,r){let s=new Set(e.filter(e=>void 0!==e.target).map(e=>e.branch));for(let e of r)if(!s.has(e.branch)&&e.target)return e.target;return null}(d,u.entries)),l(u.repository.label),p.length>0&&f()})(),()=>{n=!0}},[e,r,c,f]),{statuses:s,defaultTarget:n,repositoryLabel:a,setTarget:(0,$.useCallback)((r,s)=>{if(e){try{s?localStorage.setItem(ak(e,r),s):localStorage.removeItem(ak(e,r))}catch{}f()}},[e,f]),refetch:f}}(U?.id??null,J),en=function(e,r,s){let i=(0,$.useMemo)(()=>r?.map(e=>e.branch)??[],[r]),[n,o]=(0,$.useState)([]),a=(0,$.useCallback)(async()=>{e&&0!==i.length?o((await Promise.all(i.map(async r=>(await (0,rx.listBranchSessions)(e,r)).sessions.filter(e=>e.processAlive).map(s=>({id:s.id,projectId:e,branch:r,title:s.title?.trim()||"New Session",status:s.status,processAlive:!0,updated_at:s.updated_at}))))).flat()):o([])},[i,e]);return(0,$.useEffect)(()=>{let e=!1;return a().catch(r=>{e||console.warn("[ResidentSessions] refresh failed:",r)}),()=>{e=!0}},[a]),(0,$.useEffect)(()=>{s&&s.processAlive&&e&&s.projectId===e&&o(e=>(function(e,r){let s=e.findIndex(e=>e.id===r.id);if(-1===s)return[r,...e];let i=e[s],n="New Session"===r.title&&"New Session"!==i.title?i.title:r.title,o=[...e];return o[s]={...r,title:n},o})(e,s))},[e,s]),(0,aj.useGlobalEventStream)(r=>{if(e&&r.projectId===e){if("session:process"===r.type){let e="string"==typeof r.sessionId?r.sessionId:null,s="boolean"==typeof r.alive?r.alive:null,i="string"==typeof r.branch?r.branch:null;if(!e||null===s)return;if(!s)return void o(r=>r.filter(r=>r.id!==e));a().catch(e=>console.warn("[ResidentSessions] process refresh failed:",e)),null!==i&&o(r=>r.map(r=>r.id===e?{...r,branch:i}:r))}if("session:status"===r.type){let e="string"==typeof r.sessionId?r.sessionId:null,s="string"==typeof r.status?r.status:null;if(!e||!s)return;o(r=>r.map(r=>r.id===e?{...r,status:s}:r))}}}),(0,$.useMemo)(()=>{let e=new Map;for(let r of n){let s=r.branch??"",i=e.get(s)??[];i.push(r),e.set(s,i)}for(let r of e.values())r.sort((e,r)=>(r.updated_at??"").localeCompare(e.updated_at??""));return e},[n])}(U?.id??null,J,g),{tasks:eo,loading:ea,createTask:el,updateTask:ec,deleteTask:ed,archive:eu,unarchive:eh,refetch:ef}=function(e){let[r,s]=(0,$.useState)([]),[i,n]=(0,$.useState)(!0),o=(0,$.useCallback)(async()=>{if(!e){s([]),n(!1);return}try{let r=await rx.api.getTasks(e,{includeArchived:!0});s(r)}catch(e){console.error("Failed to fetch tasks:",e)}finally{n(!1)}},[e]);(0,$.useEffect)(()=>{o()},[o]);let a=(0,$.useCallback)(async r=>{if(!e)return null;try{let i=await rx.api.createTask(e,r);return s(e=>[...e,i]),i}catch(e){return console.error("Failed to create task:",e),null}},[e]),l=(0,$.useCallback)(async(e,i)=>{s(r=>r.map(r=>r.id===e?{...r,...i,updated_at:new Date().toISOString()}:r));try{let r=await rx.api.updateTask(e,i);return s(s=>s.map(s=>s.id===e?r:s)),r}catch(e){return console.error("Failed to update task:",e),s(r),null}},[r]),c=(0,$.useCallback)(async e=>{s(r=>r.filter(r=>r.id!==e));try{await rx.api.deleteTask(e)}catch(e){console.error("Failed to delete task:",e),s(r)}},[r]),d=(0,$.useCallback)(async e=>{s(r=>r.map(r=>r.id===e?{...r,archived_at:Date.now()}:r));try{let r=await rx.api.archiveTask(e);s(s=>s.map(s=>s.id===e?r:s))}catch(e){console.error("Failed to archive task:",e),s(r)}},[r]),u=(0,$.useCallback)(async e=>{s(r=>r.map(r=>r.id===e?{...r,archived_at:null}:r));try{let r=await rx.api.unarchiveTask(e);s(s=>s.map(s=>s.id===e?r:s))}catch(e){console.error("Failed to unarchive task:",e),s(r)}},[r]),h=(0,$.useCallback)(async i=>{if(e){s(i.map(e=>r.find(r=>r.id===e)).filter(e=>void 0!==e));try{await rx.api.reorderTasks(e,i)}catch(e){console.error("Failed to reorder tasks:",e),s(r)}}},[e,r]);return{tasks:r,loading:i,createTask:a,updateTask:l,deleteTask:c,archive:d,unarchive:u,reorderTasks:h,refetch:o}}(U?.id??null),{schedules:ep,loading:em,createSchedule:eg,updateSchedule:ex,deleteSchedule:ev,runNow:e_}=function(e){let[r,s]=(0,$.useState)([]),[i,n]=(0,$.useState)(!1),o=(0,$.useRef)(e),a=(0,$.useRef)(0),l=(0,$.useCallback)(async(e,r,i)=>{if(!e){a.current===r&&(s([]),n(!1));return}i&&n(!0);try{let i=await rx.api.getSchedules(e);a.current===r&&s(i)}catch(e){console.error("Failed to fetch schedules:",e)}finally{i&&a.current===r&&n(!1)}},[]);(0,$.useEffect)(()=>{o.current=e,a.current+=1,l(e,a.current,!0)},[e,l]);let c=(0,$.useCallback)(async()=>{let e=o.current;e&&await l(e,a.current,!1)},[l]),d=(0,$.useRef)(c);(0,$.useEffect)(()=>{d.current=c},[c]),(0,aj.useGlobalEventStream)(e=>{!e.type?.startsWith("schedule:")||o.current&&e.projectId===o.current&&d.current()});let u=(0,$.useCallback)(async r=>{if(!e)throw Error("No project selected");let s=await rx.api.createSchedule(e,r);return await c(),s},[e,c]),h=(0,$.useCallback)(async(e,r)=>{let s=await rx.api.updateSchedule(e,r);return await c(),s},[c]),f=(0,$.useCallback)(async e=>{await rx.api.deleteSchedule(e),await c()},[c]),p=(0,$.useCallback)(async e=>{let r=await rx.api.runScheduleNow(e);return await c(),r},[c]);return{schedules:r,loading:i,refetch:c,createSchedule:u,updateSchedule:h,deleteSchedule:f,runNow:p}}(U?.id??null),[ey,eb]=(0,$.useState)(null),[ew,eC]=(0,$.useState)(!1),{activity:ej,since:ek,refetch:eN,setOptimisticActivity:eD}=function(e){let[r,s]=(0,$.useState)(new Map),[i,n]=(0,$.useState)(new Map),o=(0,$.useRef)(new Map),a=(0,$.useRef)(new Map),l=(0,$.useRef)(null),c=(0,$.useCallback)(async()=>{if(!e){s(new Map),n(new Map),a.current=new Map,l.current=null,o.current=new Map;return}try{let r=await (0,rx.authFetch)(`${"localhost"===window.location.hostname&&"3000"===window.location.port?"http://localhost:5173":""}/api/projects/${e}/branches/activity`);if(!r.ok)return;let i=await r.json(),c=l.current!==e,{nextActivity:d,nextSince:u}=function(e,r,s,i){let n=new Map,o=new Map,a=[];for(let l of e){let e=l.branch??"",c=s.get(e)??0;if(!i&&l.since<c){let s=r.get(e);if(void 0!==s){n.set(e,s),o.set(e,c);continue}}n.set(e,l.activity),o.set(e,l.since),i||r.get(e)===l.activity||a.push(l.branch)}return{nextActivity:n,nextSince:o,transitions:a}}(i.branches,a.current,o.current,c);s(d),n(u),a.current=d,l.current=e,o.current=u}catch{}},[e]);return(0,$.useEffect)(()=>{c()},[c]),(0,aj.useGlobalEventStream)(r=>{var i,l,c;let d,u;if("branch:activity"!==r.type||!e||r.projectId!==e)return;let h=(i=r,l=a.current,c=o.current,d=i.branch??"",u=c.get(d)??0,i.since<u?{kind:"stale"}:l.get(d)===i.activity?{kind:"redundant",key:d}:{kind:"transition",key:d});"stale"===h.kind||(o.current.set(h.key,r.since),n(new Map(o.current)),"redundant"!==h.kind&&s(e=>{let s=new Map(e);return s.set(h.key,r.activity),a.current=s,s}))}),{activity:r,since:i,refetch:c,setOptimisticActivity:(0,$.useCallback)((e,r)=>{s(s=>{let i=function(e,r,s){let i=r??"";if(e.get(i)===s)return e;let n=new Map(e);return n.set(i,s),n}(s,e,r);return a.current=i,i})},[])}}(U?.id??null),{rules:eE,createRule:eR,updateRule:eA,deleteRule:eM}=function(e,r){let[s,i]=(0,$.useState)([]),[n,o]=(0,$.useState)(!0),a=(0,$.useCallback)(async()=>{if(!e){i([]),o(!1);return}try{let s=await rx.api.getRules(e,r);i(s)}catch(e){console.error("Failed to fetch rules:",e)}finally{o(!1)}},[e,r]);(0,$.useEffect)(()=>{a()},[a]);let l=(0,$.useCallback)(async s=>{if(!e)return null;try{let n=await rx.api.createRule(e,{...s,branch:r});return i(e=>[...e,n]),n}catch(e){return console.error("Failed to create rule:",e),null}},[e,r]),c=(0,$.useCallback)(async(e,r)=>{i(s=>s.map(s=>s.id===e?{...s,...r,enabled:void 0!==r.enabled?+!!r.enabled:s.enabled,updated_at:new Date().toISOString()}:s));try{let s=await rx.api.updateRule(e,r);return i(r=>r.map(r=>r.id===e?s:r)),s}catch(e){return console.error("Failed to update rule:",e),i(s),null}},[s]),d=(0,$.useCallback)(async e=>{i(r=>r.filter(r=>r.id!==e));try{await rx.api.deleteRule(e)}catch(e){console.error("Failed to delete rule:",e),i(s)}},[s]);return{rules:s,loading:n,createRule:l,updateRule:c,deleteRule:d,refetch:a}}(U?.id??null,N),{commands:eF,createCommand:eT,updateCommand:eP,deleteCommand:eB}=function(e,r){let[s,i]=(0,$.useState)([]),[n,o]=(0,$.useState)(!0),a=(0,$.useCallback)(async()=>{if(!e){i([]),o(!1);return}try{let s=await rx.api.getCommands(e,r);i(s)}catch(e){console.error("Failed to fetch commands:",e)}finally{o(!1)}},[e,r]);(0,$.useEffect)(()=>{a()},[a]);let l=(0,$.useCallback)(async s=>{if(!e)return null;try{let n=await rx.api.createCommand(e,{...s,branch:r});return i(e=>[...e,n]),n}catch(e){return console.error("Failed to create command:",e),null}},[e,r]),c=(0,$.useCallback)(async(e,r)=>{i(s=>s.map(s=>s.id===e?{...s,...r,updated_at:new Date().toISOString()}:s));try{let s=await rx.api.updateCommand(e,r);return i(r=>r.map(r=>r.id===e?s:r)),s}catch(e){return console.error("Failed to update command:",e),i(s),null}},[s]),d=(0,$.useCallback)(async e=>{i(r=>r.filter(r=>r.id!==e));try{await rx.api.deleteCommand(e)}catch(e){console.error("Failed to delete command:",e),i(s)}},[s]);return{commands:s,loading:n,createCommand:l,updateCommand:c,deleteCommand:d,refetch:a}}(U?.id??null,N),eL=(0,$.useRef)(null),eI=(0,$.useSyncExternalStore)(Sw,SS,SC),eO=U?.id??null,ez=U?.agent_mode??null,e$=(0,$.useCallback)(e=>!!eO&&eI.has(Sj(eO,e,ez)),[eI,eO,ez]),eW=(0,$.useCallback)(e=>{if(eO)return eI.get(Sj(eO,e,ez))},[eI,eO,ez]),eH=(0,$.useCallback)(e=>ek.get(sd(e)),[ek]),eU=(0,$.useMemo)(()=>(function(e,r,s,i){let n=new Map;if(!e)return n;for(let o of e){let e=sd(o.branch),a=r.get(e);if(!s?.(o.branch)){n.set(e,a??"idle");continue}if("main-running"===a)n.set(e,"main-running");else if("main-completed"===a){let r=i?.backendSince?.(o.branch)??0,s=i?.placeholderSince?.(o.branch)??0;n.set(e,s>r?"idle":"main-completed")}else n.set(e,"idle")}return n})(J,ej,e$,{backendSince:eH,placeholderSince:eW}),[J,ej,e$,eH,eW]);s=ei,i=eU,n=U?.id??null,o=(0,$.useRef)(new Set),l=(a=function(e){let r=new Set;if(!e)return r;for(let[s,i]of e)aN.has(i)&&r.add(s);return r}(i)).size>0,c=JSON.stringify(Array.from(a).sort()),(0,$.useEffect)(()=>{let e=new Set(JSON.parse(c)),r=o.current;o.current=e,function(e,r){for(let s of e)if(!r.has(s))return!0;return!1}(r,e)&&s()},[c,s]),(0,$.useEffect)(()=>{let e=()=>s();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[s]),(0,aj.useGlobalEventStream)(e=>{"executor:stopped"===e.type&&e.projectId===n&&s()}),(0,$.useEffect)(()=>{let e=null,r=()=>{null!==e&&(clearInterval(e),e=null)},i=()=>{r(),e=setInterval(s,l?3e4:6e4)},n=()=>{"visible"===document.visibilityState?i():r()};return"visible"===document.visibilityState&&i(),document.addEventListener("visibilitychange",n),()=>{r(),document.removeEventListener("visibilitychange",n)}},[s,l]);let{notifications:eK,unreadCount:eq,markRead:eV,markAllRead:eY,remove:eG,clear:eX}=function(e){let[r,s]=(0,$.useState)([]),i=(0,$.useRef)(new Map);(0,$.useEffect)(()=>{for(let e of Object.values(kC))kD.has(e)||kE.has(e)||(kE.add(e),(async()=>{try{let r=await fetch(e),s=await r.blob(),i=new Audio(URL.createObjectURL(s));i.preload="auto",i.load(),kD.set(e,i),console.log(`[sound-preload-debug] warmed ${e} bytes=${s.size}`)}catch(r){console.log(`[sound-preload-debug] warm failed ${e}`,r)}finally{kE.delete(e)}})())},[]);let n=(0,$.useRef)(e);(0,$.useEffect)(()=>{n.current=e},[e]),(0,$.useEffect)(()=>{e&&s(r=>r.some(r=>r.id===e&&!r.read)?r.map(r=>r.id===e?{...r,read:!0}:r):r)},[e,r]),(0,aj.useGlobalEventStream)(e=>{var r,o;let a;if("branch:activity"!==e.type)return;let l=kj(e.projectId,e.branch),c=i.current.get(l)!==e.activity;if(i.current.set(l,e.activity),!c||"completed"!==(r=e.activity)&&"main-completed"!==r)return;let d=e.activity;o=kC[d],(a=kD.get(o))||((a=new Audio(o)).preload="auto",kD.set(o,a)),a.currentTime=0,console.log(`[sound-preload-debug] play ${o} readyState=${a.readyState}`),a.play().catch(()=>{});let u=n.current===l;s(r=>{var s;return[(s={...e,activity:d},{id:kj(s.projectId,s.branch),projectId:s.projectId,branch:s.branch,sessionId:s.sessionId??null,type:s.activity,at:s.since,read:u}),...r.filter(e=>e.id!==l)].slice(0,50)})}),(0,$.useEffect)(()=>{let e=function(){try{var e=window.localStorage.getItem(kk);if(!e)return[];try{let r=JSON.parse(e);if(!Array.isArray(r))return[];return r.filter(kN).map(e=>({...e,sessionId:e.sessionId??null})).slice(0,50)}catch{return[]}}catch{return[]}}();0!==e.length&&s(r=>{if(0===r.length)return e;let s=new Set(r.map(e=>e.id));return[...r,...e.filter(e=>!s.has(e.id))].slice(0,50)})},[]);let o=(0,$.useRef)(!1);(0,$.useEffect)(()=>{if(!o.current){o.current=!0;return}try{window.localStorage.setItem(kk,JSON.stringify(r))}catch{}},[r]);let a=(0,$.useCallback)(e=>{s(r=>r.map(r=>r.id===e?{...r,read:!0}:r))},[]),l=(0,$.useCallback)(()=>{s(e=>e.some(e=>!e.read)?e.map(e=>({...e,read:!0})):e)},[]),c=(0,$.useCallback)(e=>{s(r=>r.filter(r=>r.id!==e))},[]),d=(0,$.useCallback)(()=>{s(e=>e.length?[]:e)},[]),u=r.reduce((e,r)=>e+ +!r.read,0);return{notifications:r,unreadCount:u,markRead:a,markAllRead:l,remove:c,clear:d}}(U&&"workspace"===E?`${U.id}:${N??""}`:null),eJ=(0,$.useCallback)(()=>{eD(N,"working")},[N,eD]),eZ=(0,$.useRef)(null),eQ=(0,$.useCallback)(()=>{ef()},[ef]),e0=(0,$.useCallback)((e,r)=>{eZ.current={projectId:U?.id,branch:e,sessionId:r},D(e),v(r),M(e=>e+1)},[U?.id,v]),e1=(0,$.useCallback)(e=>{e0(e.branch,e.id),R("workspace")},[e0]),e2=(0,$.useCallback)(e=>{eN(),!1!==e.processAlive&&x({id:e.id,projectId:e.projectId,branch:e.branch,title:"New Session",status:e.status,processAlive:!0,updated_at:new Date().toISOString()})},[eN]),e5=(0,$.useCallback)((e,r)=>{U?.id&&r.trim()&&x(s=>({id:e,projectId:U.id,branch:s?.id===e?s.branch:N,title:r,status:s?.id===e?s.status:"running",processAlive:!0,updated_at:s?.id===e?s.updated_at:new Date().toISOString()}))},[U?.id,N]),e3=(0,$.useCallback)(()=>{eD(N,"idle")},[N,eD]),e4=(0,$.useCallback)(()=>{ef()},[ef]);e=U?.id??null,r={onTaskChanged:e4},d=(0,$.useRef)(r.onTaskChanged),(0,$.useEffect)(()=>{d.current=r.onTaskChanged}),(0,aj.useGlobalEventStream)(r=>{e&&r.projectId===e&&("task:created"===r.type||"task:updated"===r.type||"task:deleted"===r.type)&&d.current?.()});let e6=(0,$.useMemo)(()=>{let e=sd(N);return eo.find(r=>r.assigned_branch===e)??null},[eo,N]);(0,$.useCallback)(e=>{O(async()=>{await P.current?.submitMessage(e.description??e.title)})},[]),(0,$.useCallback)(e=>{ec(e,{assigned_branch:null})},[ec]);let e8=(0,$.useRef)(void 0);(0,$.useEffect)(()=>{if(Z||0===J.length)return;let e=e8.current;if(void 0!==e){if(J.some(r=>r.branch===e.branch)){e8.current=void 0,e.sessionId?e0(e.branch,e.sessionId):D(e.branch);return}e8.current=void 0}J.some(e=>e.branch===N)||D(J[0].branch)},[J,Z,N,e0]);let e7=(0,$.useCallback)((e,r,s=null)=>{if(R("workspace"),e===U?.id)return void(s?e0(r,s):D(r));let i=H.find(r=>r.id===e);i&&(e8.current={branch:r,sessionId:s},X(i))},[U?.id,H,X,e0]),e9=(0,$.useRef)(N),te=(0,$.useRef)(U?.id),tt=(0,$.useRef)(!1);(0,$.useEffect)(()=>{if(K)return;let e=!tt.current,r=!e&&e9.current!==N,s=!e&&te.current!==U?.id;e9.current=N,te.current=U?.id,tt.current=!0;let i=eZ.current;if(kO(i,U?.id,N,p)&&(eZ.current=null),function({branchChanged:e,projectChanged:r,urlSessionId:s,pendingSessionSelection:i,currentProjectId:n,selectedBranch:o}){return(!!e||!!r)&&!!s&&!kO(i,n,o,s)}({branchChanged:r,projectChanged:s,urlSessionId:p,pendingSessionSelection:i,currentProjectId:U?.id,selectedBranch:N})){eZ.current=null,v(null);return}let n=kI({projectId:U?.id,tab:E,branch:N});if(p){let e=new URL(n,window.location.origin);e.searchParams.set("session",p),window.history.replaceState(null,"",e.pathname+e.search)}else window.history.replaceState(null,"",n)},[U?.id,E,N,K,p,v]);let tr=(0,$.useCallback)(e=>{Q(),D(e)},[Q]);(0,$.useCallback)((e,r)=>{U&&r!==U.agent_mode?Y(U.id,{agentMode:r}).then(()=>{P.current?.submitMessage(e)}):P.current?.submitMessage(e)},[U,Y]);let ts=(0,$.useRef)({content:"",at:0}),ti=(0,$.useCallback)(e=>{let r=Date.now(),s=ts.current;s.content===e&&r-s.at<600||(ts.current={content:e,at:r},eL.current?.sendMessage(e))},[]),tn=(0,$.useCallback)(()=>{let e=`Please perform the following git operations for this worktree:
|
|
28
|
+
For more information, see https://radix-ui.com/primitives/docs/components/alert-dialog`;return $.useEffect(()=>{document.getElementById(e.current?.getAttribute("aria-describedby"))||console.warn(r)},[r,e]),null};function bw({...e}){return(0,z.jsx)(bo,{"data-slot":"alert-dialog",...e})}function bS({...e}){return(0,z.jsx)(ba,{"data-slot":"alert-dialog-portal",...e})}function bC({className:e,...r}){return(0,z.jsx)(bl,{"data-slot":"alert-dialog-overlay",className:(0,ey.cn)("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...r})}function bj({className:e,...r}){return(0,z.jsxs)(bS,{children:[(0,z.jsx)(bC,{}),(0,z.jsx)(bf,{"data-slot":"alert-dialog-content",className:(0,ey.cn)("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",e),...r})]})}function bk({className:e,...r}){return(0,z.jsx)("div",{"data-slot":"alert-dialog-header",className:(0,ey.cn)("flex flex-col gap-2 text-center sm:text-left",e),...r})}function bN({className:e,...r}){return(0,z.jsx)("div",{"data-slot":"alert-dialog-footer",className:(0,ey.cn)("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",e),...r})}function bD({className:e,...r}){return(0,z.jsx)(bm,{"data-slot":"alert-dialog-title",className:(0,ey.cn)("text-lg font-semibold",e),...r})}function bE({className:e,...r}){return(0,z.jsx)(bx,{"data-slot":"alert-dialog-description",className:(0,ey.cn)("text-muted-foreground text-sm",e),...r})}function bR({className:e,...r}){return(0,z.jsx)(bv,{className:(0,ey.cn)((0,W.buttonVariants)(),e),...r})}function bA({className:e,...r}){return(0,z.jsx)(by,{className:(0,ey.cn)((0,W.buttonVariants)({variant:"outline"}),e),...r})}let bM=new Set(["ts","tsx","js","jsx","py","rb","go","rs","java","c","cpp","h","css","scss","html","vue","svelte","php","swift","kt","sh","bash","yaml","yml","toml","json","xml","sql","graphql","proto"]),bF=new Set(["md","txt","log","csv","env","gitignore","dockerignore","editorconfig"]);function bT(e){return Array.from(e.dataTransfer.types).includes("Files")}function bP(e){let r=e.dataTransfer.items;if(r&&r.length>0&&"function"==typeof r[0].webkitGetAsEntry){let e=[];for(let s of Array.from(r)){if("file"!==s.kind)continue;let r=s.webkitGetAsEntry();if(r?.isDirectory)continue;let i=s.getAsFile();i&&e.push(i)}return e}return Array.from(e.dataTransfer.files)}function bB({path:e}){let[r,s]=(0,$.useState)(!1),i=(0,$.useCallback)(r=>{r.stopPropagation(),navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),1500)},[e]);return(0,z.jsx)("button",{onClick:i,className:"p-0.5 rounded hover:bg-muted-foreground/20 transition-colors",title:`Copy path: ${e}`,children:r?(0,z.jsx)(rh.Check,{className:"h-3 w-3 text-green-500"}):(0,z.jsx)(dL.Copy,{className:"h-3 w-3 text-muted-foreground"})})}function bL({entryPath:e,type:r,deleting:s,onRequestDelete:i}){return s?(0,z.jsx)(rj,{className:"h-3 w-3 animate-spin text-muted-foreground"}):(0,z.jsx)("button",{onClick:s=>{s.stopPropagation(),i(e,r)},className:"p-0.5 rounded hover:bg-destructive/20 transition-colors",title:`Delete ${e}`,"aria-label":`Delete ${e}`,children:(0,z.jsx)(rl,{className:"h-3 w-3 text-muted-foreground hover:text-destructive"})})}function bI({entry:e,path:r,depth:s,expandedDirs:i,directoryContents:n,loadingDirs:o,selectedFile:a,uploadingDirs:l,dragOverPath:c,deletingPaths:d,onToggleDirectory:u,onSelectFile:h,onUploadFiles:f,onSetDragOverPath:p,onRequestDelete:m}){var g,x,v;let _,y,b,w,S,C=i.has(r),j=o.has(r),k=n.get(r),N=e.name.startsWith(".");if("directory"===e.type){let g=C?rv:as,x=c===r,v=l.has(r),_=d.has(r);return(0,z.jsxs)("div",{children:[(0,z.jsxs)("div",{className:(0,ey.cn)("group flex items-center w-full px-2 py-2 rounded-sm transition-colors cursor-pointer",x?"bg-primary/15 outline-2 -outline-offset-2 outline-dashed outline-primary/60":"hover:bg-accent"),style:{paddingLeft:`${16*s+8}px`},onClick:()=>u(r),onDragOver:e=>{bT(e)&&(e.preventDefault(),e.stopPropagation(),p(r))},onDrop:e=>{if(!bT(e))return;e.preventDefault(),e.stopPropagation(),p(null);let s=bP(e);s.length&&f(r,s)},children:[(0,z.jsxs)("div",{className:"flex items-center gap-1 min-w-0 flex-1",children:[v||j?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground"}):(0,z.jsx)(C?sb:oh,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,z.jsx)(g,{className:(0,ey.cn)("h-4 w-4 shrink-0 text-blue-500",N&&"opacity-60")}),(0,z.jsx)("span",{className:(0,ey.cn)("truncate",N&&"text-muted-foreground"),children:e.name})]}),(0,z.jsxs)("div",{className:(0,ey.cn)("shrink-0 ml-1 items-center gap-1",_?"flex":"hidden group-hover:flex"),children:[(0,z.jsx)(bB,{path:r}),(0,z.jsx)(bL,{entryPath:r,type:"directory",deleting:_,onRequestDelete:m})]})]}),C&&k&&(0,z.jsx)("div",{children:k.map(e=>{let g=r?`${r}/${e.name}`:e.name;return(0,z.jsx)(bI,{entry:e,path:g,depth:s+1,expandedDirs:i,directoryContents:n,loadingDirs:o,selectedFile:a,uploadingDirs:l,dragOverPath:c,deletingPaths:d,onToggleDirectory:u,onSelectFile:h,onUploadFiles:f,onSetDragOverPath:p,onRequestDelete:m},g)})})]})}let D=(g=e.name,_=g.split(".").pop()?.toLowerCase()??"",bM.has(_)?be:bF.has(_)?bt:y9),E=a===r,R=r.includes("/")?r.slice(0,r.lastIndexOf("/")):"",A=d.has(r);return(0,z.jsxs)("div",{className:(0,ey.cn)("group flex items-center w-full px-2 py-2 rounded-sm transition-colors cursor-pointer",E?"bg-accent text-accent-foreground":"hover:bg-accent/50"),style:{paddingLeft:`${16*s+8+18}px`},onClick:()=>h(r),onDragOver:e=>{bT(e)&&(e.preventDefault(),e.stopPropagation(),p(R))},onDrop:e=>{if(!bT(e))return;e.preventDefault(),e.stopPropagation(),p(null);let r=bP(e);r.length&&f(R,r)},children:[(0,z.jsxs)("div",{className:"flex items-center gap-1 min-w-0 flex-1",children:[(0,z.jsx)(D,{className:(0,ey.cn)("h-4 w-4 shrink-0 text-muted-foreground",N&&"opacity-60")}),(0,z.jsx)("span",{className:(0,ey.cn)("truncate",N&&"text-muted-foreground"),children:e.name})]}),(0,z.jsxs)("div",{className:"shrink-0 flex items-center gap-2 ml-1",children:[(0,z.jsx)("span",{className:"text-[11px] text-muted-foreground/70 group-hover:hidden whitespace-nowrap w-[52px] text-right tabular-nums",children:e.mtime&&(x=e.mtime,y=Date.now(),S=Math.floor((w=Math.floor((b=Math.floor(Math.floor((y-new Date(x).getTime())/1e3)/60))/60))/24),b<1?"just now":b<60?`${b}m ago`:w<24?`${w}h ago`:S<30?`${S}d ago`:new Date(x).toLocaleDateString(void 0,{month:"short",day:"numeric"}))}),(0,z.jsx)("span",{className:"text-[11px] text-muted-foreground/70 group-hover:hidden whitespace-nowrap w-[52px] text-right tabular-nums",children:null!=e.size&&((v=e.size)<1024?`${v} B`:v<1048576?`${(v/1024).toFixed(1)} KB`:`${(v/1048576).toFixed(1)} MB`)}),(0,z.jsxs)("div",{className:(0,ey.cn)("items-center gap-1",A?"flex":"hidden group-hover:flex"),children:[(0,z.jsx)(bB,{path:r}),(0,z.jsx)(bL,{entryPath:r,type:"file",deleting:A,onRequestDelete:m})]})]})]})}function bO({entries:e,expandedDirs:r,directoryContents:s,loadingDirs:i,selectedFile:n,uploadingDirs:o,rootLoading:a,deletingPaths:l,onToggleDirectory:c,onSelectFile:d,onUploadFiles:u,onDeleteEntry:h}){let[f,p]=(0,$.useState)(null),[m,g]=(0,$.useState)(null),x=""===f,v=o.has(""),_=(0,$.useCallback)((e,r)=>{g({path:e,type:r})},[]),y=m?m.path.includes("/")?m.path.slice(m.path.lastIndexOf("/")+1):m.path:"";return(0,z.jsxs)("div",{className:(0,ey.cn)("h-full transition-colors",x&&"bg-accent/30 outline-2 -outline-offset-2 outline-dashed outline-primary/50"),style:{fontSize:"var(--files-tree-font-size, 14px)"},onDragOver:e=>{bT(e)&&(e.preventDefault(),p(""))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||p(null)},onDrop:e=>{if(!bT(e))return;e.preventDefault(),p(null);let r=bP(e);r.length&&u("",r)},children:[(0,z.jsx)(at,{className:"h-full",children:(0,z.jsxs)("div",{className:"py-1",children:[v&&(0,z.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1 text-xs text-muted-foreground",children:[(0,z.jsx)(rj,{className:"h-3.5 w-3.5 animate-spin"}),"Uploading…"]}),a&&0===e.length?(0,z.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground text-sm",children:"Loading files..."}):0===e.length?(0,z.jsx)("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-sm",children:x?"Drop files to upload":"No files found. Drop files here to upload."}):e.map(e=>{let a=e.name;return(0,z.jsx)(bI,{entry:e,path:a,depth:0,expandedDirs:r,directoryContents:s,loadingDirs:i,selectedFile:n,uploadingDirs:o,dragOverPath:f,deletingPaths:l,onToggleDirectory:c,onSelectFile:d,onUploadFiles:u,onSetDragOverPath:p,onRequestDelete:_},a)})]})}),(0,z.jsx)(bw,{open:null!==m,onOpenChange:e=>{e||g(null)},children:(0,z.jsxs)(bj,{children:[(0,z.jsxs)(bk,{children:[(0,z.jsxs)(bD,{children:["Delete ",m?.type==="directory"?"folder":"file","?"]}),(0,z.jsx)(bE,{children:m?.type==="directory"?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)("span",{className:"font-medium text-foreground",children:y})," and all its contents will be permanently deleted. This can't be undone."]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)("span",{className:"font-medium text-foreground",children:y})," will be permanently deleted. This can't be undone."]})})]}),(0,z.jsxs)(bN,{children:[(0,z.jsx)(bA,{children:"Cancel"}),(0,z.jsx)(bR,{className:(0,ey.cn)((0,W.buttonVariants)({variant:"destructive"}),"border-transparent"),onClick:()=>{m&&h(m.path,m.type)},children:"Delete"})]})]})})]})}let bz=(0,ew.default)("download",[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]]),b$=(0,ew.default)("file-exclamation-point",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]),bW=(0,ew.default)("code",[["path",{d:"m16 18 6-6-6-6",key:"eg8j8"}],["path",{d:"m8 6-6 6 6 6",key:"ppft3o"}]]),bH=(0,ew.default)("list-collapse",[["path",{d:"M10 5h11",key:"1hkqpe"}],["path",{d:"M10 12h11",key:"6m4ad9"}],["path",{d:"M10 19h11",key:"14g2nv"}],["path",{d:"m3 10 3-3-3-3",key:"i7pm08"}],["path",{d:"m3 20 3-3-3-3",key:"20gx1n"}]]),bU=(0,ew.default)("list-tree",[["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"M3 10a2 2 0 0 0 2 2h3",key:"1npucw"}],["path",{d:"M3 5v12a2 2 0 0 0 2 2h3",key:"x1gjn2"}]]),bK=/[\0-\x1F!-,\.\/:-@\[-\^`\{-\xA9\xAB-\xB4\xB6-\xB9\xBB-\xBF\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u0378\u0379\u037E\u0380-\u0385\u0387\u038B\u038D\u03A2\u03F6\u0482\u0530\u0557\u0558\u055A-\u055F\u0589-\u0590\u05BE\u05C0\u05C3\u05C6\u05C8-\u05CF\u05EB-\u05EE\u05F3-\u060F\u061B-\u061F\u066A-\u066D\u06D4\u06DD\u06DE\u06E9\u06FD\u06FE\u0700-\u070F\u074B\u074C\u07B2-\u07BF\u07F6-\u07F9\u07FB\u07FC\u07FE\u07FF\u082E-\u083F\u085C-\u085F\u086B-\u089F\u08B5\u08C8-\u08D2\u08E2\u0964\u0965\u0970\u0984\u098D\u098E\u0991\u0992\u09A9\u09B1\u09B3-\u09B5\u09BA\u09BB\u09C5\u09C6\u09C9\u09CA\u09CF-\u09D6\u09D8-\u09DB\u09DE\u09E4\u09E5\u09F2-\u09FB\u09FD\u09FF\u0A00\u0A04\u0A0B-\u0A0E\u0A11\u0A12\u0A29\u0A31\u0A34\u0A37\u0A3A\u0A3B\u0A3D\u0A43-\u0A46\u0A49\u0A4A\u0A4E-\u0A50\u0A52-\u0A58\u0A5D\u0A5F-\u0A65\u0A76-\u0A80\u0A84\u0A8E\u0A92\u0AA9\u0AB1\u0AB4\u0ABA\u0ABB\u0AC6\u0ACA\u0ACE\u0ACF\u0AD1-\u0ADF\u0AE4\u0AE5\u0AF0-\u0AF8\u0B00\u0B04\u0B0D\u0B0E\u0B11\u0B12\u0B29\u0B31\u0B34\u0B3A\u0B3B\u0B45\u0B46\u0B49\u0B4A\u0B4E-\u0B54\u0B58-\u0B5B\u0B5E\u0B64\u0B65\u0B70\u0B72-\u0B81\u0B84\u0B8B-\u0B8D\u0B91\u0B96-\u0B98\u0B9B\u0B9D\u0BA0-\u0BA2\u0BA5-\u0BA7\u0BAB-\u0BAD\u0BBA-\u0BBD\u0BC3-\u0BC5\u0BC9\u0BCE\u0BCF\u0BD1-\u0BD6\u0BD8-\u0BE5\u0BF0-\u0BFF\u0C0D\u0C11\u0C29\u0C3A-\u0C3C\u0C45\u0C49\u0C4E-\u0C54\u0C57\u0C5B-\u0C5F\u0C64\u0C65\u0C70-\u0C7F\u0C84\u0C8D\u0C91\u0CA9\u0CB4\u0CBA\u0CBB\u0CC5\u0CC9\u0CCE-\u0CD4\u0CD7-\u0CDD\u0CDF\u0CE4\u0CE5\u0CF0\u0CF3-\u0CFF\u0D0D\u0D11\u0D45\u0D49\u0D4F-\u0D53\u0D58-\u0D5E\u0D64\u0D65\u0D70-\u0D79\u0D80\u0D84\u0D97-\u0D99\u0DB2\u0DBC\u0DBE\u0DBF\u0DC7-\u0DC9\u0DCB-\u0DCE\u0DD5\u0DD7\u0DE0-\u0DE5\u0DF0\u0DF1\u0DF4-\u0E00\u0E3B-\u0E3F\u0E4F\u0E5A-\u0E80\u0E83\u0E85\u0E8B\u0EA4\u0EA6\u0EBE\u0EBF\u0EC5\u0EC7\u0ECE\u0ECF\u0EDA\u0EDB\u0EE0-\u0EFF\u0F01-\u0F17\u0F1A-\u0F1F\u0F2A-\u0F34\u0F36\u0F38\u0F3A-\u0F3D\u0F48\u0F6D-\u0F70\u0F85\u0F98\u0FBD-\u0FC5\u0FC7-\u0FFF\u104A-\u104F\u109E\u109F\u10C6\u10C8-\u10CC\u10CE\u10CF\u10FB\u1249\u124E\u124F\u1257\u1259\u125E\u125F\u1289\u128E\u128F\u12B1\u12B6\u12B7\u12BF\u12C1\u12C6\u12C7\u12D7\u1311\u1316\u1317\u135B\u135C\u1360-\u137F\u1390-\u139F\u13F6\u13F7\u13FE-\u1400\u166D\u166E\u1680\u169B-\u169F\u16EB-\u16ED\u16F9-\u16FF\u170D\u1715-\u171F\u1735-\u173F\u1754-\u175F\u176D\u1771\u1774-\u177F\u17D4-\u17D6\u17D8-\u17DB\u17DE\u17DF\u17EA-\u180A\u180E\u180F\u181A-\u181F\u1879-\u187F\u18AB-\u18AF\u18F6-\u18FF\u191F\u192C-\u192F\u193C-\u1945\u196E\u196F\u1975-\u197F\u19AC-\u19AF\u19CA-\u19CF\u19DA-\u19FF\u1A1C-\u1A1F\u1A5F\u1A7D\u1A7E\u1A8A-\u1A8F\u1A9A-\u1AA6\u1AA8-\u1AAF\u1AC1-\u1AFF\u1B4C-\u1B4F\u1B5A-\u1B6A\u1B74-\u1B7F\u1BF4-\u1BFF\u1C38-\u1C3F\u1C4A-\u1C4C\u1C7E\u1C7F\u1C89-\u1C8F\u1CBB\u1CBC\u1CC0-\u1CCF\u1CD3\u1CFB-\u1CFF\u1DFA\u1F16\u1F17\u1F1E\u1F1F\u1F46\u1F47\u1F4E\u1F4F\u1F58\u1F5A\u1F5C\u1F5E\u1F7E\u1F7F\u1FB5\u1FBD\u1FBF-\u1FC1\u1FC5\u1FCD-\u1FCF\u1FD4\u1FD5\u1FDC-\u1FDF\u1FED-\u1FF1\u1FF5\u1FFD-\u203E\u2041-\u2053\u2055-\u2070\u2072-\u207E\u2080-\u208F\u209D-\u20CF\u20F1-\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F-\u215F\u2189-\u24B5\u24EA-\u2BFF\u2C2F\u2C5F\u2CE5-\u2CEA\u2CF4-\u2CFF\u2D26\u2D28-\u2D2C\u2D2E\u2D2F\u2D68-\u2D6E\u2D70-\u2D7E\u2D97-\u2D9F\u2DA7\u2DAF\u2DB7\u2DBF\u2DC7\u2DCF\u2DD7\u2DDF\u2E00-\u2E2E\u2E30-\u3004\u3008-\u3020\u3030\u3036\u3037\u303D-\u3040\u3097\u3098\u309B\u309C\u30A0\u30FB\u3100-\u3104\u3130\u318F-\u319F\u31C0-\u31EF\u3200-\u33FF\u4DC0-\u4DFF\u9FFD-\u9FFF\uA48D-\uA4CF\uA4FE\uA4FF\uA60D-\uA60F\uA62C-\uA63F\uA673\uA67E\uA6F2-\uA716\uA720\uA721\uA789\uA78A\uA7C0\uA7C1\uA7CB-\uA7F4\uA828-\uA82B\uA82D-\uA83F\uA874-\uA87F\uA8C6-\uA8CF\uA8DA-\uA8DF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA954-\uA95F\uA97D-\uA97F\uA9C1-\uA9CE\uA9DA-\uA9DF\uA9FF\uAA37-\uAA3F\uAA4E\uAA4F\uAA5A-\uAA5F\uAA77-\uAA79\uAAC3-\uAADA\uAADE\uAADF\uAAF0\uAAF1\uAAF7-\uAB00\uAB07\uAB08\uAB0F\uAB10\uAB17-\uAB1F\uAB27\uAB2F\uAB5B\uAB6A-\uAB6F\uABEB\uABEE\uABEF\uABFA-\uABFF\uD7A4-\uD7AF\uD7C7-\uD7CA\uD7FC-\uD7FF\uE000-\uF8FF\uFA6E\uFA6F\uFADA-\uFAFF\uFB07-\uFB12\uFB18-\uFB1C\uFB29\uFB37\uFB3D\uFB3F\uFB42\uFB45\uFBB2-\uFBD2\uFD3E-\uFD4F\uFD90\uFD91\uFDC8-\uFDEF\uFDFC-\uFDFF\uFE10-\uFE1F\uFE30-\uFE32\uFE35-\uFE4C\uFE50-\uFE6F\uFE75\uFEFD-\uFF0F\uFF1A-\uFF20\uFF3B-\uFF3E\uFF40\uFF5B-\uFF65\uFFBF-\uFFC1\uFFC8\uFFC9\uFFD0\uFFD1\uFFD8\uFFD9\uFFDD-\uFFFF]|\uD800[\uDC0C\uDC27\uDC3B\uDC3E\uDC4E\uDC4F\uDC5E-\uDC7F\uDCFB-\uDD3F\uDD75-\uDDFC\uDDFE-\uDE7F\uDE9D-\uDE9F\uDED1-\uDEDF\uDEE1-\uDEFF\uDF20-\uDF2C\uDF4B-\uDF4F\uDF7B-\uDF7F\uDF9E\uDF9F\uDFC4-\uDFC7\uDFD0\uDFD6-\uDFFF]|\uD801[\uDC9E\uDC9F\uDCAA-\uDCAF\uDCD4-\uDCD7\uDCFC-\uDCFF\uDD28-\uDD2F\uDD64-\uDDFF\uDF37-\uDF3F\uDF56-\uDF5F\uDF68-\uDFFF]|\uD802[\uDC06\uDC07\uDC09\uDC36\uDC39-\uDC3B\uDC3D\uDC3E\uDC56-\uDC5F\uDC77-\uDC7F\uDC9F-\uDCDF\uDCF3\uDCF6-\uDCFF\uDD16-\uDD1F\uDD3A-\uDD7F\uDDB8-\uDDBD\uDDC0-\uDDFF\uDE04\uDE07-\uDE0B\uDE14\uDE18\uDE36\uDE37\uDE3B-\uDE3E\uDE40-\uDE5F\uDE7D-\uDE7F\uDE9D-\uDEBF\uDEC8\uDEE7-\uDEFF\uDF36-\uDF3F\uDF56-\uDF5F\uDF73-\uDF7F\uDF92-\uDFFF]|\uD803[\uDC49-\uDC7F\uDCB3-\uDCBF\uDCF3-\uDCFF\uDD28-\uDD2F\uDD3A-\uDE7F\uDEAA\uDEAD-\uDEAF\uDEB2-\uDEFF\uDF1D-\uDF26\uDF28-\uDF2F\uDF51-\uDFAF\uDFC5-\uDFDF\uDFF7-\uDFFF]|\uD804[\uDC47-\uDC65\uDC70-\uDC7E\uDCBB-\uDCCF\uDCE9-\uDCEF\uDCFA-\uDCFF\uDD35\uDD40-\uDD43\uDD48-\uDD4F\uDD74\uDD75\uDD77-\uDD7F\uDDC5-\uDDC8\uDDCD\uDDDB\uDDDD-\uDDFF\uDE12\uDE38-\uDE3D\uDE3F-\uDE7F\uDE87\uDE89\uDE8E\uDE9E\uDEA9-\uDEAF\uDEEB-\uDEEF\uDEFA-\uDEFF\uDF04\uDF0D\uDF0E\uDF11\uDF12\uDF29\uDF31\uDF34\uDF3A\uDF45\uDF46\uDF49\uDF4A\uDF4E\uDF4F\uDF51-\uDF56\uDF58-\uDF5C\uDF64\uDF65\uDF6D-\uDF6F\uDF75-\uDFFF]|\uD805[\uDC4B-\uDC4F\uDC5A-\uDC5D\uDC62-\uDC7F\uDCC6\uDCC8-\uDCCF\uDCDA-\uDD7F\uDDB6\uDDB7\uDDC1-\uDDD7\uDDDE-\uDDFF\uDE41-\uDE43\uDE45-\uDE4F\uDE5A-\uDE7F\uDEB9-\uDEBF\uDECA-\uDEFF\uDF1B\uDF1C\uDF2C-\uDF2F\uDF3A-\uDFFF]|\uD806[\uDC3B-\uDC9F\uDCEA-\uDCFE\uDD07\uDD08\uDD0A\uDD0B\uDD14\uDD17\uDD36\uDD39\uDD3A\uDD44-\uDD4F\uDD5A-\uDD9F\uDDA8\uDDA9\uDDD8\uDDD9\uDDE2\uDDE5-\uDDFF\uDE3F-\uDE46\uDE48-\uDE4F\uDE9A-\uDE9C\uDE9E-\uDEBF\uDEF9-\uDFFF]|\uD807[\uDC09\uDC37\uDC41-\uDC4F\uDC5A-\uDC71\uDC90\uDC91\uDCA8\uDCB7-\uDCFF\uDD07\uDD0A\uDD37-\uDD39\uDD3B\uDD3E\uDD48-\uDD4F\uDD5A-\uDD5F\uDD66\uDD69\uDD8F\uDD92\uDD99-\uDD9F\uDDAA-\uDEDF\uDEF7-\uDFAF\uDFB1-\uDFFF]|\uD808[\uDF9A-\uDFFF]|\uD809[\uDC6F-\uDC7F\uDD44-\uDFFF]|[\uD80A\uD80B\uD80E-\uD810\uD812-\uD819\uD824-\uD82B\uD82D\uD82E\uD830-\uD833\uD837\uD839\uD83D\uD83F\uD87B-\uD87D\uD87F\uD885-\uDB3F\uDB41-\uDBFF][\uDC00-\uDFFF]|\uD80D[\uDC2F-\uDFFF]|\uD811[\uDE47-\uDFFF]|\uD81A[\uDE39-\uDE3F\uDE5F\uDE6A-\uDECF\uDEEE\uDEEF\uDEF5-\uDEFF\uDF37-\uDF3F\uDF44-\uDF4F\uDF5A-\uDF62\uDF78-\uDF7C\uDF90-\uDFFF]|\uD81B[\uDC00-\uDE3F\uDE80-\uDEFF\uDF4B-\uDF4E\uDF88-\uDF8E\uDFA0-\uDFDF\uDFE2\uDFE5-\uDFEF\uDFF2-\uDFFF]|\uD821[\uDFF8-\uDFFF]|\uD823[\uDCD6-\uDCFF\uDD09-\uDFFF]|\uD82C[\uDD1F-\uDD4F\uDD53-\uDD63\uDD68-\uDD6F\uDEFC-\uDFFF]|\uD82F[\uDC6B-\uDC6F\uDC7D-\uDC7F\uDC89-\uDC8F\uDC9A-\uDC9C\uDC9F-\uDFFF]|\uD834[\uDC00-\uDD64\uDD6A-\uDD6C\uDD73-\uDD7A\uDD83\uDD84\uDD8C-\uDDA9\uDDAE-\uDE41\uDE45-\uDFFF]|\uD835[\uDC55\uDC9D\uDCA0\uDCA1\uDCA3\uDCA4\uDCA7\uDCA8\uDCAD\uDCBA\uDCBC\uDCC4\uDD06\uDD0B\uDD0C\uDD15\uDD1D\uDD3A\uDD3F\uDD45\uDD47-\uDD49\uDD51\uDEA6\uDEA7\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3\uDFCC\uDFCD]|\uD836[\uDC00-\uDDFF\uDE37-\uDE3A\uDE6D-\uDE74\uDE76-\uDE83\uDE85-\uDE9A\uDEA0\uDEB0-\uDFFF]|\uD838[\uDC07\uDC19\uDC1A\uDC22\uDC25\uDC2B-\uDCFF\uDD2D-\uDD2F\uDD3E\uDD3F\uDD4A-\uDD4D\uDD4F-\uDEBF\uDEFA-\uDFFF]|\uD83A[\uDCC5-\uDCCF\uDCD7-\uDCFF\uDD4C-\uDD4F\uDD5A-\uDFFF]|\uD83B[\uDC00-\uDDFF\uDE04\uDE20\uDE23\uDE25\uDE26\uDE28\uDE33\uDE38\uDE3A\uDE3C-\uDE41\uDE43-\uDE46\uDE48\uDE4A\uDE4C\uDE50\uDE53\uDE55\uDE56\uDE58\uDE5A\uDE5C\uDE5E\uDE60\uDE63\uDE65\uDE66\uDE6B\uDE73\uDE78\uDE7D\uDE7F\uDE8A\uDE9C-\uDEA0\uDEA4\uDEAA\uDEBC-\uDFFF]|\uD83C[\uDC00-\uDD2F\uDD4A-\uDD4F\uDD6A-\uDD6F\uDD8A-\uDFFF]|\uD83E[\uDC00-\uDFEF\uDFFA-\uDFFF]|\uD869[\uDEDE-\uDEFF]|\uD86D[\uDF35-\uDF3F]|\uD86E[\uDC1E\uDC1F]|\uD873[\uDEA2-\uDEAF]|\uD87A[\uDFE1-\uDFFF]|\uD87E[\uDE1E-\uDFFF]|\uD884[\uDF4B-\uDFFF]|\uDB40[\uDC00-\uDCFF\uDDF0-\uDFFF]/g,bq=Object.hasOwnProperty;var bV=e.i(216920);let bY={},bG=new class{constructor(){this.occurrences,this.reset()}slug(e,r){var s,i;let n=(s=e,i=!0===r,"string"!=typeof s?"":(i||(s=s.toLowerCase()),s.replace(bK,"").replace(/ /g,"-"))),o=n;for(;bq.call(this.occurrences,n);)this.occurrences[o]++,n=o+"-"+this.occurrences[o];return this.occurrences[n]=0,n}reset(){this.occurrences=Object.create(null)}};function bX(e){let r=(e||bY).prefix||"";return function(e){bG.reset(),(0,bV.visit)(e,"element",function(e){let s,i;((i=2===(s="element"===e.type?e.tagName.toLowerCase():"").length&&104===s.charCodeAt(0)?s.charCodeAt(1):0)>48&&i<55?i-48:void 0)&&!e.properties.id&&(e.properties.id=r+bG.slug("children"in e?function e(r){let s=-1,i=[];for(;++s<r.children.length;){var n;i[s]="text"===(n=r.children[s]).type?n.value:"children"in n?e(n):""}return i.join("")}(e):"value"in e?e.value:""))})}}var bJ=aE,H=H,bZ=e.i(829692),bZ=bZ,bQ=e.i(615742);let b0=(0,$.createContext)({code:""}),b1={name:"line-data",line(e,r){e.properties["data-line"]=String(r)}},b2={name:"line-numbers",line(e,r){e.children.unshift({type:"element",tagName:"span",properties:{className:["inline-block","min-w-10","mr-2","text-right","select-none","text-muted-foreground"]},children:[{type:"text",value:String(r)}]})}};async function b5(e,r,s=!1,i){let n=[b1];return i&&i.size>0&&n.push({name:"fold-gutter",line(e,r){e.children.unshift({type:"element",tagName:"span",properties:i.has(r)?{className:["code-fold-toggle"],"data-fold-start":String(r)}:{className:["code-fold-spacer"]},children:[]})}}),s&&n.push(b2),await Promise.all([(0,bQ.codeToHtml)(e,{lang:r,theme:"one-light",transformers:n}),(0,bQ.codeToHtml)(e,{lang:r,theme:"one-dark-pro",transformers:n})])}let b3=(0,$.forwardRef)(function({code:e,language:r,showLineNumbers:s=!1,scrollToLine:i,scrollKey:n,foldable:o=!1,className:a,children:l,...c},d){let[u,h]=(0,$.useState)(""),[f,p]=(0,$.useState)(""),m=(0,$.useRef)(!1),g=(0,$.useRef)(null),x=(0,$.useMemo)(()=>o?function(e,r={}){return function(...e){let r=new Map;for(let s of e.flat())!(s.endLine<=s.startLine)&&(r.has(s.startLine)||r.set(s.startLine,s));let s=[...r.values()].sort((e,r)=>e.startLine-r.startLine||r.endLine-e.endLine),i=[],n=[];for(let e of s){for(;n.length&&n[n.length-1].endLine<e.startLine;)n.pop();let r=n[n.length-1];r&&e.endLine>r.endLine||(i.push(e),n.push(e))}return i}((r.tokenIndex,[]),function(e){let r=e.split("\n"),s=[],i=[],n=0,o=e=>{n>e.line&&s.push({startLine:e.line+1,endLine:n+1})};for(let e=0;e<r.length;e++){let s=function(e){let r=e.match(/^[ \t]*/),s=r?r[0].length:0;return s===e.length?null:s}(r[e]);if(null!==s){for(;i.length&&i[i.length-1].indent>=s;)o(i.pop());i.push({indent:s,line:e}),n=e}}for(;i.length;)o(i.pop());return s}(e))}(e):[],[o,e]),v=(0,$.useMemo)(()=>new Set(x.map(e=>e.startLine)),[x]),[_,y]=(0,$.useState)(new Set),[b,w]=(0,$.useState)(e),[S,C]=(0,$.useState)({line:i,key:n});if((0,$.useImperativeHandle)(d,()=>({foldAll:()=>y(new Set(x.map(e=>e.startLine))),expandAll:()=>y(new Set)}),[x]),(0,$.useEffect)(()=>(b5(e,r,s,v).then(([e,r])=>{m.current||(h(e),p(r),m.current=!0)}),()=>{m.current=!1}),[e,r,s,v]),(0,$.useEffect)(()=>{let e=g.current;if(!e)return;let r=new Map(x.map(e=>[e.startLine,e])),s=new Set;for(let e of _){let i=r.get(e);if(i)for(let e=i.startLine+1;e<=i.endLine;e++)s.add(e)}for(let r of e.querySelectorAll("[data-line]")){let e=Number(r.getAttribute("data-line"));r.style.display=s.has(e)?"none":"",r.classList.toggle("code-line-collapsed",_.has(e))}},[_,x,u,f]),(0,$.useEffect)(()=>{if(!o)return;let e=g.current;if(!e)return;let r=e=>{let r=e.target?.closest?.("[data-fold-start]");if(!r)return;e.stopPropagation(),e.preventDefault();let s=Number(r.getAttribute("data-fold-start"));y(e=>{let r=new Set(e);return r.has(s)?r.delete(s):r.add(s),r})};return e.addEventListener("click",r),()=>e.removeEventListener("click",r)},[o]),(0,$.useEffect)(()=>{if(null==i)return;let e=g.current;if(!e||!u&&!f)return;let r=Array.from(e.querySelectorAll(`[data-line="${i}"]`));if(0===r.length)return;let s=r.find(e=>null!==e.offsetParent)??r[0],n=requestAnimationFrame(()=>{s.scrollIntoView({block:"center",behavior:"auto"}),r.forEach(e=>e.classList.add("code-line-highlight"))}),o=window.setTimeout(()=>r.forEach(e=>e.classList.remove("code-line-highlight")),1600);return()=>{cancelAnimationFrame(n),window.clearTimeout(o),r.forEach(e=>e.classList.remove("code-line-highlight"))}},[i,n,u,f]),e!==b&&(w(e),y(new Set)),(S.line!==i||S.key!==n)&&(C({line:i,key:n}),null!=i&&_.size>0)){let e=!1,r=new Set(_);for(let s of x)r.has(s.startLine)&&i>s.startLine&&i<=s.endLine&&(r.delete(s.startLine),e=!0);e&&y(r)}return(0,z.jsx)(b0.Provider,{value:{code:e},children:(0,z.jsx)("div",{ref:g,className:(0,ey.cn)("group relative w-full overflow-hidden rounded-md border bg-background text-foreground",a),...c,children:(0,z.jsxs)("div",{className:"relative",children:[(0,z.jsx)("div",{className:"overflow-auto dark:hidden [&>pre]:m-0 [&>pre]:bg-background! [&>pre]:p-4 [&>pre]:text-foreground! [&>pre]:text-sm [&_code]:grid [&_code]:font-mono [&_code]:text-sm",dangerouslySetInnerHTML:{__html:u}}),(0,z.jsx)("div",{className:"hidden overflow-auto dark:block [&>pre]:m-0 [&>pre]:bg-background! [&>pre]:p-4 [&>pre]:text-foreground! [&>pre]:text-sm [&_code]:grid [&_code]:font-mono [&_code]:text-sm",dangerouslySetInnerHTML:{__html:f}}),l&&(0,z.jsx)("div",{className:"absolute top-2 right-2 flex items-center gap-2",children:l})]})})})}),b4=({onCopy:e,onError:r,timeout:s=2e3,children:i,className:n,...o})=>{let[a,l]=(0,$.useState)(!1),{code:c}=(0,$.useContext)(b0),d=async()=>{if(!navigator?.clipboard?.writeText)return void r?.(Error("Clipboard API not available"));try{await navigator.clipboard.writeText(c),l(!0),e?.(),setTimeout(()=>l(!1),s)}catch(e){r?.(e)}},u=a?H.default:bZ.default;return(0,z.jsx)(W.Button,{className:(0,ey.cn)("shrink-0",n),onClick:d,size:"icon",variant:"ghost",...o,children:i??(0,z.jsx)(u,{size:14})})};var b6="horizontal",b8=["horizontal","vertical"],b7=$.forwardRef((e,r)=>{var s;let{decorative:i,orientation:n=b6,...o}=e,a=(s=n,b8.includes(s))?n:b6;return(0,z.jsx)(er.div,{"data-orientation":a,...i?{role:"none"}:{"aria-orientation":"vertical"===a?a:void 0,role:"separator"},...o,ref:r})});b7.displayName="Separator",e.s(["Root",()=>b7,"Separator",()=>b7],691102),e.i(691102),(0,sv.cva)("flex w-fit items-stretch [&>*]:focus-visible:z-10 [&>*]:focus-visible:relative [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md has-[>[data-slot=button-group]]:gap-2",{variants:{orientation:{horizontal:"[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",vertical:"flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none"}},defaultVariants:{orientation:"horizontal"}}),(0,ew.default)("chevron-left",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);var aR=aE;let b9=({className:e,from:r,...s})=>(0,z.jsx)("div",{className:(0,ey.cn)("group flex w-full max-w-[95%] flex-col gap-2","user"===r?"is-user ml-auto justify-end":"is-assistant",e),...s}),we=({children:e,className:r,...s})=>(0,z.jsx)("div",{className:(0,ey.cn)("is-user:dark flex w-fit max-w-full min-w-0 flex-col gap-2 overflow-hidden text-sm","group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground","group-[.is-assistant]:text-foreground",r),...s,children:e}),wt=(0,$.memo)(({className:e,...r})=>(0,z.jsx)(aR.i,{className:(0,ey.cn)("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",e),...r}),(e,r)=>e.children===r.children);function wr({className:e,...r}){return(0,z.jsx)("div",{"data-slot":"skeleton",className:(0,ey.cn)("bg-accent animate-pulse rounded-md",e),...r})}function ws({projectId:e,symbol:r,branch:s,target:i,currentFile:n,anchor:o,onJump:a,onClose:l}){let[c,d]=(0,$.useState)(!0),[u,h]=(0,$.useState)([]),[f,p]=(0,$.useState)(!1),m=(0,$.useRef)(null);(0,$.useEffect)(()=>{let n=!0;return d(!0),rx.api.searchSymbol(e,r,s,i).then(e=>{n&&(h(e.hits),p(e.truncated))}).catch(()=>{n&&h([])}).finally(()=>{n&&d(!1)}),()=>{n=!1}},[e,r,s,i]),(0,$.useEffect)(()=>{let e=e=>{e.detail>=2||m.current&&!m.current.contains(e.target)&&l()},s=e=>{if("Escape"===e.key)return void l();if((e.metaKey||e.ctrlKey)&&("c"===e.key||"C"===e.key)){let s=window.getSelection();if(s&&s.rangeCount>0&&!s.isCollapsed)return;e.preventDefault(),navigator.clipboard?.writeText(r)}};return document.addEventListener("mousedown",e),document.addEventListener("keydown",s),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",s)}},[l,r]);let g=(e,r)=>Number(r.file===n)-Number(e.file===n),x=u.filter(e=>"definition"===e.kind).sort(g),v=u.filter(e=>"reference"===e.kind).sort(g),_=Math.max(8,Math.min(o.x,window.innerWidth-440-8)),y=window.innerHeight-8-(o.y+18),b=o.y-18-8,w=y>=340||y>=b,S=Math.max(120,Math.min(340,w?y:b)),C=w?{top:o.y+18}:{bottom:window.innerHeight-(o.y-18)},j=({hit:e})=>(0,z.jsxs)("button",{type:"button",onClick:()=>{a(e.file,e.line),l()},className:"flex w-full flex-col items-start gap-0.5 rounded px-2 py-1.5 text-left hover:bg-accent",children:[(0,z.jsxs)("span",{className:"flex w-full items-baseline justify-between gap-2",children:[(0,z.jsxs)("span",{className:"truncate font-mono text-xs",children:[e.file.split("/").pop(),(0,z.jsxs)("span",{className:"text-muted-foreground",children:[":",e.line]})]}),e.file===n&&(0,z.jsx)("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:"this file"})]}),(0,z.jsx)("code",{className:"w-full truncate text-xs text-muted-foreground",children:e.text.trim()})]}),k=({title:e,children:r})=>(0,z.jsxs)("div",{className:"mb-1",children:[(0,z.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:e}),r]});return(0,ee.createPortal)((0,z.jsxs)("div",{ref:m,style:{left:_,...C,width:440,maxHeight:S},className:"fixed z-50 flex flex-col overflow-hidden rounded-lg border bg-popover text-popover-foreground shadow-lg select-none",children:[(0,z.jsx)("div",{className:"border-b px-3 py-1.5 text-xs font-medium",children:(0,z.jsx)("span",{className:"font-mono",children:r})}),(0,z.jsx)("div",{className:"flex-1 overflow-auto p-1",children:c?(0,z.jsxs)("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[(0,z.jsx)(rj,{className:"h-4 w-4 animate-spin"})," Searching…"]}):0===u.length?(0,z.jsx)("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"No results."}):(0,z.jsxs)(z.Fragment,{children:[x.length>0&&(0,z.jsx)(k,{title:`Definitions (${x.length})`,children:x.map((e,r)=>(0,z.jsx)(j,{hit:e},`d-${r}`))}),v.length>0&&(0,z.jsx)(k,{title:`References (${v.length})`,children:v.map((e,r)=>(0,z.jsx)(j,{hit:e},`r-${r}`))}),f&&(0,z.jsx)("div",{className:"px-2 py-1.5 text-[11px] text-muted-foreground",children:"Showing first matches — results truncated."})]})})]}),document.body)}wt.displayName="MessageResponse";let wi=(0,ew.default)("image-off",[["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}],["path",{d:"M10.41 10.41a2 2 0 1 1-2.83-2.83",key:"1bzlo9"}],["line",{x1:"13.5",x2:"6",y1:"13.5",y2:"21",key:"1q0aeu"}],["line",{x1:"18",x2:"21",y1:"12",y2:"15",key:"5mozeu"}],["path",{d:"M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59",key:"mmje98"}],["path",{d:"M21 15V5a2 2 0 0 0-2-2H9",key:"43el77"}]]);function wn({projectId:e,filePath:r,branch:s,target:i,onDownload:n}){let[o,a]=(0,$.useState)(null),[l,c]=(0,$.useState)(!1);return((0,$.useEffect)(()=>{let n=null,o=!1;return rx.api.getFileBlob(e,r,s,i).then(e=>{o||a(n=URL.createObjectURL(e))}).catch(()=>{o||c(!0)}),()=>{o=!0,n&&URL.revokeObjectURL(n)}},[e,r,s,i]),l)?(0,z.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-3 text-muted-foreground",children:[(0,z.jsx)(wi,{className:"h-10 w-10"}),(0,z.jsx)("p",{className:"text-sm",children:"Couldn't load image"}),(0,z.jsxs)(W.Button,{variant:"outline",size:"sm",onClick:n,children:[(0,z.jsx)(bz,{className:"h-4 w-4 mr-2"}),"Download"]})]}):o?(0,z.jsx)("div",{className:"flex items-center justify-center h-full p-4 bg-muted/30",children:(0,z.jsx)("img",{src:o,alt:r.split("/").pop()??"image",className:"max-w-full max-h-full object-contain",onError:()=>c(!0)})}):(0,z.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:(0,z.jsx)(rj,{className:"h-6 w-6 animate-spin"})})}async function wo(e,r){let s=await (0,bQ.codeToTokensBase)(e,{lang:r,theme:"one-light",includeExplanation:"scopeName"}),i=new Map;return s.forEach((e,r)=>{let s=0,n=[];for(let r of e){let e=(r.explanation??[]).flatMap(e=>e.scopes.map(e=>e.scopeName)),i=s+r.content.length;n.push({start:s,end:i,kind:e.some(e=>e.startsWith("comment"))?"comment":e.some(e=>e.startsWith("string")||e.startsWith("constant.character"))?"string":e.some(e=>e.startsWith("keyword")||e.startsWith("storage")||e.startsWith("constant.language")||e.startsWith("variable.language"))?"keyword":"code"}),s=i}i.set(r+1,n)}),i}let wa=new Set(["png","jpg","jpeg","gif","webp","bmp","ico","avif","svg"]);function wl(e){let r=e.split("/").pop()?.split(".").pop()?.toLowerCase()??"";return wa.has(r)}let wc=/^[A-Za-z_$][A-Za-z0-9_$]*$/,wd="symbol-nav";function wu(e,r,s){let i=document.createRange();return i.selectNodeContents(e),i.setEnd(r,s),i.toString().length}function wh(e,r){let s,i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),n=0;for(;s=i.nextNode();){let e=(s.textContent??"").length;if(r<=n+e)return{node:s,offset:r-n};n+=e}return null}function wf(e){let r=Array.from(document.querySelectorAll(`[data-line="${CSS.escape(e.line)}"]`)),s=r.find(e=>null!==e.offsetParent)??r[0];if(!s)return null;let i=wh(s,e.start),n=wh(s,e.end);if(!i||!n)return null;let o=document.createRange();return o.setStart(i.node,i.offset),o.setEnd(n.node,n.offset),o}let wp=/[A-Za-z0-9_$]/;function wm(e,r,s){let i=document,n=null,o=0;if(i.caretRangeFromPoint){let s=i.caretRangeFromPoint(e,r);s&&(n=s.startContainer,o=s.startOffset)}else if(i.caretPositionFromPoint){let s=i.caretPositionFromPoint(e,r);s&&(n=s.offsetNode,o=s.offset)}if(!n||n.nodeType!==Node.TEXT_NODE)return null;let a=n.textContent??"",l=o,c=o;for(;l>0&&wp.test(a[l-1]);)l--;for(;c<a.length&&wp.test(a[c]);)c++;if(l>=c)return null;let d=a.slice(l,c);if(!wc.test(d))return null;let u=document.createRange();u.setStart(n,l),u.setEnd(n,c);let h=function(e){let r=e.startContainer.nodeType===Node.ELEMENT_NODE?e.startContainer:e.startContainer.parentElement,s=r?.closest("[data-line]");if(!s||!s.contains(e.endContainer))return null;let i=s.getAttribute("data-line");if(null===i)return null;let n=wu(s,e.startContainer,e.startOffset),o=wu(s,e.endContainer,e.endOffset);return n>=o?null:{line:i,start:n,end:o}}(u);if(!h)return null;if(s){let e=h.start-h.line.length,r=function(e,r,s){let i=e.get(r);if(!i)return null;for(let e of i)if(s>=e.start&&s<e.end)return e.kind;return null}(s,Number(h.line),e);if(r&&"code"!==r)return null}return{word:d,anchor:h}}function wg(){return"undefined"!=typeof CSS&&"highlights"in CSS&&"undefined"!=typeof Highlight}let wx=!1;function wv(){wg()&&CSS.highlights.delete(wd)}let w_={ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",cs:"csharp",css:"css",scss:"scss",html:"html",vue:"vue",svelte:"svelte",php:"php",swift:"swift",kt:"kotlin",sh:"bash",bash:"bash",zsh:"bash",yaml:"yaml",yml:"yaml",toml:"toml",json:"json",xml:"xml",sql:"sql",graphql:"graphql",md:"markdown",mdx:"mdx",dockerfile:"dockerfile",makefile:"makefile",lua:"lua",r:"r",scala:"scala",zig:"zig"};function wy(e){let r=e.split("/").pop()?.toLowerCase()??"";return"dockerfile"===r?"dockerfile":"makefile"===r?"makefile":w_[r.split(".").pop()?.toLowerCase()??""]??"text"}function wb(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function ww({filePath:e,fileContent:r,loading:s,downloadUrl:i,projectId:n,branch:o,target:a,scrollToLine:l,scrollKey:c,onJump:d,restoreScrollTop:u,restoreScrollKey:h,onScroll:f}){let p,[m,g]=(0,$.useState)("rendered"),[x,v]=(0,$.useState)(e),[_,y]=(0,$.useState)(null),b=(0,$.useRef)(null),w=(0,$.useRef)(null),S=(0,$.useRef)(!1);(0,$.useEffect)(()=>{S.current=null!==_},[_]);let C=(0,$.useCallback)(e=>{if(e.detail>=2){let r=window.getSelection();if(S.current){r?.removeAllRanges(),y(e=>e?{...e,selectWord:!0}:e);return}let s=wm(e.clientX,e.clientY),i=s?wf(s.anchor):null;i&&(r?.removeAllRanges(),r?.addRange(i));return}let r=window.getSelection();if(r&&!r.isCollapsed)return;let s=wm(e.clientX,e.clientY,b.current);s&&(r?.removeAllRanges(),y({symbol:s.word,x:e.clientX,y:e.clientY,anchor:s.anchor,selectWord:!1}))},[]),j=(0,$.useCallback)(e=>{e.detail>=2&&e.preventDefault()},[]);(0,$.useEffect)(()=>{if(!_?.anchor)return void wv();let e=wf(_.anchor);if(!e)return void wv();if(_.selectWord){wv();let r=window.getSelection();r?.removeAllRanges(),r?.addRange(e);return}return wg()?(!function(){if(wx||"undefined"==typeof document)return;wx=!0;let e=document.createElement("style");e.textContent=`::highlight(${wd}){background-color:rgba(255, 196, 0, 0.32);}`,document.head.appendChild(e)}(),CSS.highlights.set(wd,new Highlight(e)),wv):void wv()},[_]),(0,$.useEffect)(()=>{b.current=null;let s=r?.content;if(!e||null==s||r?.binary||r?.tooLarge)return;let i=!1;return wo(s,wy(e)).then(e=>{i||(b.current=e)}).catch(()=>{}),()=>{i=!0}},[e,r]);let k=(0,$.useRef)(null),N=(0,$.useRef)(null),D=(0,$.useCallback)(e=>{let r=k.current;if(!r)return;let s=r.querySelector(`[id="${CSS.escape(e)}"]`);if(!s)return;N.current?.();let i=()=>s.scrollIntoView({block:"start",behavior:"auto"});i();let n=new ResizeObserver(i);n.observe(r);let o=()=>{n.disconnect(),window.clearTimeout(a),window.removeEventListener("wheel",o),window.removeEventListener("touchmove",o),window.removeEventListener("keydown",o),N.current=null},a=window.setTimeout(o,1e3);window.addEventListener("wheel",o,{passive:!0}),window.addEventListener("touchmove",o,{passive:!0}),window.addEventListener("keydown",o),N.current=o},[]);(0,$.useEffect)(()=>()=>N.current?.(),[]);let E=(0,$.useRef)(null),R=(0,$.useRef)(!1),A=(0,$.useRef)(f);A.current=f;let M=(0,$.useRef)(null),F=(0,$.useRef)(null),T=(0,$.useCallback)(e=>{if(R.current)return;let r=e.currentTarget.scrollTop;M.current&&clearTimeout(M.current),M.current=setTimeout(()=>A.current?.(r),200)},[]);(0,$.useEffect)(()=>{void 0!==h&&(F.current=u??0)},[h,u]),(0,$.useEffect)(()=>{let e=E.current;e&&(e.scrollTop=0)},[e]),(0,$.useEffect)(()=>{let e=F.current;if(null==e)return;let r=E.current;if(!r||(F.current=null,!e))return;R.current=!0;let s=()=>{r.scrollTop=e};s();let i=new ResizeObserver(s);i.observe(r.firstElementChild??r);let n=()=>{R.current=!1,i.disconnect(),window.clearTimeout(o),r.removeEventListener("wheel",n),r.removeEventListener("touchmove",n),r.removeEventListener("keydown",n)},o=window.setTimeout(n,1500);return r.addEventListener("wheel",n,{passive:!0}),r.addEventListener("touchmove",n,{passive:!0}),r.addEventListener("keydown",n),n},[r]);let P=(0,$.useMemo)(()=>[...Object.values(bJ.e),bX],[]),B=(0,$.useMemo)(()=>({a:({href:e,children:r,className:s,node:i,...n})=>{let o="string"==typeof e&&e.startsWith("#");return(0,z.jsx)("a",{href:e,className:(0,ey.cn)("wrap-anywhere font-medium text-primary underline",s),"data-streamdown":"link",...o?{onClick:r=>{r.preventDefault(),D(decodeURIComponent(e.slice(1)))}}:{target:"_blank",rel:"noreferrer"},...n,children:r})}}),[D]);if(e!==x&&(v(e),g("rendered"),y(null)),!e)return(0,z.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:"Select a file to preview."});if(s)return(0,z.jsxs)("div",{className:"flex flex-col h-full",children:[(0,z.jsx)("div",{className:"flex items-center justify-between px-4 py-2 border-b flex-shrink-0",children:(0,z.jsx)(wr,{className:"h-4 w-48"})}),(0,z.jsxs)("div",{className:"flex-1 p-4",children:[(0,z.jsx)(wr,{className:"h-4 w-full mb-2"}),(0,z.jsx)(wr,{className:"h-4 w-3/4 mb-2"}),(0,z.jsx)(wr,{className:"h-4 w-5/6 mb-2"}),(0,z.jsx)(wr,{className:"h-4 w-2/3"})]})]});if(!r)return(0,z.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:"Failed to load file."});let L=()=>{e&&rx.api.downloadFile(n,e,o,a).catch(e=>{console.error("Failed to download file",e)})},I=("markdown"===(p=wy(e))||"mdx"===p)&&!r.tooLarge&&!r.binary&&!!r.content,O=I&&"rendered"===m,H=!r.tooLarge&&!r.binary&&!O&&null!==r.content;return(0,z.jsxs)("div",{className:"flex flex-col h-full",children:[(0,z.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b flex-shrink-0 gap-2",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,z.jsx)("span",{className:"text-sm font-mono truncate",children:e}),(0,z.jsx)("span",{className:"text-xs text-muted-foreground shrink-0",children:wb(r.size)})]}),(0,z.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[I&&(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>g(e=>"rendered"===e?"source":"rendered"),title:O?"View source":"View rendered",children:O?(0,z.jsx)(bW,{className:"h-3.5 w-3.5"}):(0,z.jsx)(_i,{className:"h-3.5 w-3.5"})}),H&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>w.current?.foldAll(),title:"Fold all",children:(0,z.jsx)(bH,{className:"h-3.5 w-3.5"})}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>w.current?.expandAll(),title:"Expand all",children:(0,z.jsx)(bU,{className:"h-3.5 w-3.5"})})]}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>{navigator.clipboard.writeText(e)},title:"Copy path",children:(0,z.jsx)(dL.Copy,{className:"h-3.5 w-3.5"})}),i&&(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:L,title:"Download",children:(0,z.jsx)(bz,{className:"h-3.5 w-3.5"})})]})]}),(0,z.jsx)("div",{className:"flex-1 overflow-auto",ref:E,onScroll:T,children:r.tooLarge?(0,z.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-3 text-muted-foreground",children:[(0,z.jsx)(b$,{className:"h-10 w-10"}),(0,z.jsxs)("p",{className:"text-sm",children:["File too large to preview (",wb(r.size),")"]}),i&&(0,z.jsxs)(W.Button,{variant:"outline",size:"sm",onClick:L,children:[(0,z.jsx)(bz,{className:"h-4 w-4 mr-2"}),"Download"]})]}):r.binary&&wl(e)&&r.size<=0xa00000?(0,z.jsx)(wn,{projectId:n,filePath:e,branch:o,target:a,onDownload:L},e):r.binary?(0,z.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-3 text-muted-foreground",children:[(0,z.jsx)(b$,{className:"h-10 w-10"}),(0,z.jsx)("p",{className:"text-sm",children:wl(e)?`Image too large to preview (${wb(r.size)})`:`Binary file (${wb(r.size)})`}),i&&(0,z.jsxs)(W.Button,{variant:"outline",size:"sm",onClick:L,children:[(0,z.jsx)(bz,{className:"h-4 w-4 mr-2"}),"Download"]})]}):O?(0,z.jsx)("div",{className:"p-4",style:{fontSize:"var(--files-content-font-size, 14px)"},ref:k,children:(0,z.jsx)(wt,{components:B,rehypePlugins:P,children:r.content??""})}):null!==r.content?(0,z.jsx)("div",{className:"h-full [&_pre]:text-[length:var(--files-content-font-size,14px)]! [&_code]:text-[length:var(--files-content-font-size,14px)]!",onMouseDown:j,onClick:C,children:(0,z.jsx)(b3,{ref:w,code:r.content,language:wy(e),showLineNumbers:!0,foldable:!0,scrollToLine:l,scrollKey:c,className:"border-0 rounded-none",children:(0,z.jsx)(b4,{})})}):(0,z.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:"Empty file."})}),_&&(0,z.jsx)(ws,{projectId:n,symbol:_.symbol,branch:o,target:a,currentFile:e,anchor:{x:_.x,y:_.y},onJump:d,onClose:()=>y(null)})]})}class wS{capacity;map;constructor(e){if(this.capacity=e,this.map=new Map,e<1)throw Error("LRUCache capacity must be at least 1")}get(e){if(!this.map.has(e))return;let r=this.map.get(e);return this.map.delete(e),this.map.set(e,r),r}has(e){return this.map.has(e)}set(e,r){for(this.map.has(e)&&this.map.delete(e),this.map.set(e,r);this.map.size>this.capacity;){let e=this.map.keys().next().value;if(void 0===e)break;this.map.delete(e)}}delete(e){return this.map.delete(e)}deleteWhere(e){for(let r of[...this.map.keys()])e(r)&&this.map.delete(r)}clear(){this.map.clear()}get size(){return this.map.size}}let wC="vibedeckx:files:views";function wj(){return{v:1,views:{}}}function wk(){try{let e=localStorage.getItem(wC);if(!e)return wj();let r=JSON.parse(e);if(!r||1!==r.v||!r.views||"object"!=typeof r.views)return wj();return r}catch{return wj()}}function wN(e){try{localStorage.setItem(wC,JSON.stringify(e))}catch{}}function wD(e){return e.slice(e.lastIndexOf("\0")+1)}let wE=new Set(["/","-","_","."," "]);function wR({projectId:e,project:r,selectedBranch:s,navRequest:i}){let n=r&&!r.path?"remote":void 0,[o,a]=(0,$.useState)(!1),{settings:l}=(0,cz.useConversationSettings)(),c=(0,$.useRef)(null),[d,u]=(0,$.useState)(!1),h=(0,$.useCallback)(()=>{let e=c.current;e&&(e.isCollapsed()?e.expand():e.collapse())},[]),{rootEntries:f,directoryContents:p,expandedDirs:m,selectedFile:g,fileContent:x,fileLoading:v,rootLoading:_,loadingDirs:y,uploadingDirs:b,deletingPaths:w,jumpTarget:S,canGoBack:C,canGoForward:j,fetchRoot:k,refresh:N,reportScroll:D,restoreScroll:E,toggleDirectory:R,navigate:A,jumpTo:M,goBack:F,goForward:T,uploadFiles:P,deleteEntry:B}=function({projectId:e,branch:r,target:s,showHidden:i=!1}){let[n,o]=(0,$.useState)([]),[a,l]=(0,$.useState)(new Map),[c,d]=(0,$.useState)(new Set),[u,h]=(0,$.useState)(null),[f,p]=(0,$.useState)(null),[m,g]=(0,$.useState)(null),x=(0,$.useRef)(0),[v,_]=(0,$.useState)({entries:[],index:-1}),y=(0,$.useRef)(v);y.current=v;let[b,w]=(0,$.useState)(!1),[S,C]=(0,$.useState)(!1),[j,k]=(0,$.useState)(new Set),[N,D]=(0,$.useState)(new Set),[E,R]=(0,$.useState)(new Set),A=(0,$.useRef)(0),M=(0,$.useRef)(0),F=(0,$.useRef)(new wS(50)),T=e?[e,r??"",s??""].join("|"):null,P=(0,$.useRef)(T);P.current=T;let B=(0,$.useRef)(u);B.current=u;let L=(0,$.useRef)(0),I=(0,$.useRef)(null),O=(0,$.useRef)(0),[z,W]=(0,$.useState)(null),H=(0,$.useRef)(null),U=(0,$.useCallback)(i=>[e,r??"",s??"",i].join("\0"),[e,r,s]),K=(0,$.useCallback)(()=>{let e,r,s=P.current;if(!s||I.current!==s)return;let i={selectedFile:B.current,history:y.current,scrollTop:L.current};(e=wk()).views[s]={...i,updatedAt:Date.now()},(r=Object.keys(e.views)).length>30&&r.sort((r,s)=>e.views[r].updatedAt-e.views[s].updatedAt).slice(0,r.length-30).forEach(r=>delete e.views[r]),wN(e)},[]),q=(0,$.useCallback)(()=>{H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{H.current=null,K()},300)},[K]),V=(0,$.useCallback)(e=>{L.current=e,q()},[q]);(0,$.useEffect)(()=>{q()},[u,v,q]);let Y=(0,$.useCallback)(async n=>{if(e&&(d(e=>{let r=new Set(e);return r.has(n)?r.delete(n):r.add(n),r}),!a.has(n))){k(e=>new Set(e).add(n));try{let o=await rx.api.browseProjectDirectory(e,n,r,s,i);l(e=>{let r=new Map(e);return r.set(n,o.items),r})}catch(e){console.error("Failed to browse directory:",e),gK.toast.error(`Failed to open ${n}`,{description:e instanceof Error?e.message:String(e)})}finally{k(e=>{let r=new Set(e);return r.delete(n),r})}}},[e,r,s,i,a]),G=(0,$.useCallback)(async i=>{if(!e)return"failed";let n=U(i),o=F.current.get(n);if(o)return p(o),w(!1),"loaded";let a=++M.current;w(!0),p(null);try{let o=await rx.api.getFileContent(e,i,r,s);if(a!==M.current)return"stale";return F.current.set(n,o),p(o),"loaded"}catch(e){if(a!==M.current)return"stale";return console.error("Failed to get file content:",e),p(null),"failed"}finally{a===M.current&&w(!1)}},[e,r,s,U]),X=(0,$.useCallback)(async r=>{e&&(h(r),await G(r))},[e,G]),J=(0,$.useCallback)(async()=>{if(!e)return!1;C(!0);let n=++A.current;try{let a=await rx.api.browseProjectDirectory(e,void 0,r,s,i);if(n!==A.current)return!1;return o(a.items),l(new Map),d(new Set),!0}catch(e){if(console.error("Failed to browse root directory:",e),n!==A.current)return!1;return o([]),gK.toast.error("Failed to browse files",{description:e instanceof Error?e.message:String(e)}),!1}finally{n===A.current&&C(!1)}},[e,r,s,i]),Z=(0,$.useCallback)(async()=>{let r;if(!e||!await J())return;let s=P.current,i=s?(r=wk().views[s])&&"object"==typeof r&&(null===r.selectedFile||"string"==typeof r.selectedFile)&&r.history&&"object"==typeof r.history&&Array.isArray(r.history.entries)&&"number"==typeof r.history.index?{selectedFile:r.selectedFile,history:r.history,scrollTop:"number"==typeof r.scrollTop&&Number.isFinite(r.scrollTop)?r.scrollTop:0}:null:null;if(s&&i&&i.selectedFile){if(_(i.history.entries.length?i.history:{entries:[{path:i.selectedFile,line:null}],index:0}),L.current=i.scrollTop,W({top:i.scrollTop,nonce:++O.current}),h(i.selectedFile),I.current=s,"failed"===await G(i.selectedFile)){let e;h(null),_({entries:[],index:-1}),L.current=0,(e=wk()).views[s]&&(delete e.views[s],wN(e))}}else h(null),p(null),_({entries:[],index:-1}),L.current=0,I.current=s},[e,J,G]),Q=(0,$.useCallback)(async()=>{if(!e||(F.current.clear(),!await J()))return;let r=B.current;r&&await G(r)},[e,J,G]),ee=(0,$.useCallback)(async(e,r=null)=>{_(({entries:s,index:i})=>{let n=s[i];if(n&&n.path===e){let n=s.slice();return n[i]={path:e,line:r},{entries:n,index:i}}let o=s.slice(0,i+1);return{entries:[...o,{path:e,line:r}],index:o.length}}),await X(e),null!=r&&g({line:r,nonce:++x.current})},[X]),et=(0,$.useCallback)((e,r)=>ee(e,r),[ee]),er=(0,$.useCallback)(()=>{let{entries:e,index:r}=y.current;if(r<=0)return;let s=e[r-1];_(e=>({...e,index:e.index-1})),X(s.path),null!=s.line&&g({line:s.line,nonce:++x.current})},[X]),es=(0,$.useCallback)(()=>{let{entries:e,index:r}=y.current;if(r>=e.length-1)return;let s=e[r+1];_(e=>({...e,index:e.index+1})),X(s.path),null!=s.line&&g({line:s.line,nonce:++x.current})},[X]),ei=(0,$.useCallback)(async n=>{if(e)if(""===n)o((await rx.api.browseProjectDirectory(e,void 0,r,s,i)).items);else{let o=await rx.api.browseProjectDirectory(e,n,r,s,i);l(e=>{let r=new Map(e);return r.set(n,o.items),r})}},[e,r,s,i]),en=(0,$.useCallback)(async(i,n)=>{if(e&&0!==n.length){D(e=>new Set(e).add(i));try{let{uploaded:o}=await rx.api.uploadFiles(e,n,i,r,s),a=new Set(o.map(e=>i?`${i}/${e}`:e));F.current.deleteWhere(e=>a.has(wD(e))),""!==i&&d(e=>new Set(e).add(i)),await ei(i),gK.toast.success(`Uploaded ${o.length} file${1===o.length?"":"s"}`)}catch(e){console.error("Failed to upload files:",e),gK.toast.error("Upload failed",{description:e instanceof Error?e.message:String(e)})}finally{D(e=>{let r=new Set(e);return r.delete(i),r})}}},[e,r,s,ei]),eo=(0,$.useCallback)(async i=>{if(e&&i){R(e=>new Set(e).add(i));try{await rx.api.deleteFile(e,i,r,s),F.current.deleteWhere(e=>{let r=wD(e);return r===i||r.startsWith(`${i}/`)}),h(e=>e===i||e&&e.startsWith(`${i}/`)?(p(null),null):e);let n=i.includes("/")?i.slice(0,i.lastIndexOf("/")):"";await ei(n),gK.toast.success("Deleted")}catch(e){console.error("Failed to delete:",e),gK.toast.error("Delete failed",{description:e instanceof Error?e.message:String(e)})}finally{R(e=>{let r=new Set(e);return r.delete(i),r})}}},[e,r,s,ei]);return{rootEntries:n,directoryContents:a,expandedDirs:c,selectedFile:u,fileContent:f,fileLoading:b,rootLoading:S,loadingDirs:j,uploadingDirs:N,deletingPaths:E,jumpTarget:m,canGoBack:v.index>0,canGoForward:v.index<v.entries.length-1,fetchRoot:Z,refresh:Q,reportScroll:V,restoreScroll:z,toggleDirectory:Y,selectFile:X,navigate:ee,jumpTo:et,goBack:er,goForward:es,uploadFiles:en,refreshDirectory:ei,deleteEntry:eo}}({projectId:e,branch:s,target:n,showHidden:o}),L=function({projectId:e,branch:r,target:s}){let[i,n]=(0,$.useState)([]),[o,a]=(0,$.useState)(!1),[l,c]=(0,$.useState)(!1),[d,u]=(0,$.useState)(!1),[h,f]=(0,$.useState)(""),p=(0,$.useRef)(0);(0,$.useEffect)(()=>{n([]),a(!1),u(!1),c(!1),f(""),p.current++},[e,r,s]);let m=(0,$.useCallback)(async()=>{if(!e)return;c(!0);let i=++p.current;try{let o=await rx.api.listProjectFiles(e,r,s);if(i!==p.current)return;n(o.files),a(o.truncated),u(!0)}catch(e){if(i!==p.current)return;n([]),u(!1),gK.toast.error("Failed to load file list",{description:e instanceof Error?e.message:String(e)})}finally{i===p.current&&c(!1)}},[e,r,s]),g=(0,$.useCallback)(()=>{d||l||m()},[d,l,m]),x=(0,$.useCallback)(()=>{u(!1),p.current++,h&&m()},[h,m]),v=(0,$.useDeferredValue)(h);return{query:h,setQuery:f,results:(0,$.useMemo)(()=>(function(e,r,s){if(!r.trim())return[];let i=[];for(let s of e){let e=function(e,r){let s=e.toLowerCase().replace(/\s+/g,"");if(!s)return null;let i=r.toLowerCase(),n=r.lastIndexOf("/")+1,o=0,a=0,l=-2;for(let e=0;e<s.length;e++){let c=s[e],d=-1;for(;a<i.length;a++)if(i[a]===c){d=a;break}if(-1===d)return null;let u=1;d===l+1&&(u+=5),d>=n&&(u+=3);let h=d>0?r[d-1]:"/";(0===d||d===n||wE.has(h))&&(u+=4),o+=u,l=d,a=d+1}return o+.1*Math.max(0,40-r.length)}(r,s);null!==e&&i.push({path:s,score:e})}return i.sort((e,r)=>r.score-e.score||e.path.length-r.path.length),i.slice(0,50)})(i,v,0),[i,v]),truncated:o,loading:l,loaded:d,ensureLoaded:g,refresh:x}}({projectId:e,branch:s,target:n});(0,$.useEffect)(()=>{k()},[k]),(0,$.useEffect)(()=>{i&&(null!=i.line?M(i.path,i.line):A(i.path))},[i?.nonce]);let I=(0,$.useCallback)(()=>{N(),L.refresh()},[N,L]),O=(0,$.useCallback)(e=>{A(e),L.setQuery("")},[A,L]);if(!e)return(0,z.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:(0,z.jsxs)("div",{className:"text-center",children:[(0,z.jsx)("div",{className:"mx-auto w-10 h-10 rounded-xl bg-muted flex items-center justify-center mb-3",children:(0,z.jsx)(vV,{className:"h-5 w-5 text-muted-foreground/50"})}),(0,z.jsx)("p",{className:"text-sm",children:"Select a project to browse files."})]})});let H=g&&e?rx.api.getFileDownloadUrl(e,g,s,n):null;return(0,z.jsxs)("div",{className:"flex flex-col h-full",style:{"--files-tree-font-size":`${l.filesTreeFontSize}px`,"--files-content-font-size":`${l.filesContentFontSize}px`},children:[(0,z.jsx)(lx,{title:"Files",actions:(0,z.jsxs)("div",{className:"flex items-center gap-1",children:[(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:h,title:d?"Show file tree":"Hide file tree","aria-pressed":!d,children:d?(0,z.jsx)(_l,{className:"h-3.5 w-3.5"}):(0,z.jsx)(_a,{className:"h-3.5 w-3.5"})}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:`h-7 w-7 hover:text-foreground ${o?"text-foreground":"text-muted-foreground"}`,onClick:()=>a(e=>!e),title:o?"Hide hidden files":"Show hidden files","aria-pressed":o,children:o?(0,z.jsx)(_i,{className:"h-3.5 w-3.5"}):(0,z.jsx)(_n,{className:"h-3.5 w-3.5"})}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:F,disabled:!C,title:"Back",children:(0,z.jsx)(_c.ArrowLeft,{className:"h-3.5 w-3.5"})}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:T,disabled:!j,title:"Forward",children:(0,z.jsx)(_d,{className:"h-3.5 w-3.5"})}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:I,title:"Refresh",children:(0,z.jsx)(vV,{className:`h-3.5 w-3.5 ${_?"animate-spin":""}`})})]})}),(0,z.jsxs)(y_,{direction:"horizontal",autoSaveId:"files-panels",className:"flex-1",children:[(0,z.jsx)(_w,{ref:c,collapsible:!0,collapsedSize:0,defaultSize:33,minSize:20,onCollapse:()=>u(!0),onExpand:()=>u(!1),children:(0,z.jsxs)(y6,{shouldFilter:!1,className:"flex h-full flex-col bg-transparent",children:[(0,z.jsx)("div",{className:"border-b p-2",children:(0,z.jsxs)(yb,{children:[(0,z.jsx)(yS,{children:(0,z.jsx)(_o,{className:"h-3.5 w-3.5"})}),(0,z.jsx)(yk,{type:"search",name:"files-search",autoComplete:"off","data-1p-ignore":!0,"data-lpignore":"true","data-form-type":"other",readOnly:!0,onFocus:e=>{e.currentTarget.removeAttribute("readonly"),L.ensureLoaded()},placeholder:"Search files...",value:L.query,onChange:e=>L.setQuery(e.target.value)}),L.query&&(0,z.jsx)(yS,{align:"inline-end",children:(0,z.jsx)(yj,{size:"icon-xs","aria-label":"Clear search",onClick:()=>L.setQuery(""),children:(0,z.jsx)(t8,{className:"h-3.5 w-3.5"})})})]})}),L.query?(0,z.jsx)(y8,{className:"max-h-none flex-1",children:L.loading&&0===L.results.length?(0,z.jsxs)("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[(0,z.jsx)(rj,{className:"h-4 w-4 animate-spin"}),"Loading files…"]}):0===L.results.length?(0,z.jsx)("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"No matching files."}):(0,z.jsxs)(z.Fragment,{children:[L.results.map(e=>{let r=e.path.lastIndexOf("/"),s=r>=0?e.path.slice(0,r+1):"",i=r>=0?e.path.slice(r+1):e.path;return(0,z.jsxs)(y7,{value:e.path,onSelect:()=>O(e.path),className:"flex-col items-start gap-0 text-[length:var(--files-tree-font-size,14px)]!",children:[(0,z.jsx)("span",{className:"font-medium",children:i}),s&&(0,z.jsx)("span",{className:"w-full truncate text-xs text-muted-foreground",children:s})]},e.path)}),L.truncated&&(0,z.jsx)("div",{className:"px-2 py-2 text-xs text-muted-foreground",children:"Showing first 50,000 files — refine your search to narrow results."})]})}):(0,z.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,z.jsx)(bO,{entries:f,expandedDirs:m,directoryContents:p,loadingDirs:y,selectedFile:g,uploadingDirs:b,rootLoading:_,deletingPaths:w,onToggleDirectory:R,onSelectFile:A,onUploadFiles:P,onDeleteEntry:B})})]})}),(0,z.jsx)(yy,{withHandle:!0}),(0,z.jsx)(_w,{defaultSize:67,minSize:25,children:(0,z.jsx)("div",{className:"h-full overflow-hidden",children:(0,z.jsx)(ww,{filePath:g,fileContent:x,loading:v,downloadUrl:H,projectId:e,branch:s,target:n,scrollToLine:S?.line??null,scrollKey:S?.nonce,onJump:M,restoreScrollTop:E?.top??null,restoreScrollKey:E?.nonce,onScroll:D})})})]})]})}let wA=(0,$.createContext)(null),wM={openFile:()=>{},index:null};function wF(){return(0,$.useContext)(wA)??wM}let wT=wA.Provider,wP=0;function wB(e){let r=e.lastIndexOf("/");return r>=0?e.slice(r+1):e}let wL=[500,1e3,2e3,4e3,8e3];async function wI(e,r={}){let s=r.delaysMs??wL,i=r.sleep??(e=>new Promise(r=>setTimeout(r,e))),n=r.cancelled??(()=>!1);for(let r=0;;r++){if(n())return null;let o=null;try{o=await e()}catch{o=null}if(n())return null;if(o&&o.files.length>0||r>=s.length)return o;await i(s[r])}}function wO({projectId:e,selectedBranch:r,onMergeRequest:s,project:i,onExecutorModeChange:n,agentSlot:o,activateAgentTabNonce:a,diffCompareNonce:l,mergeTarget:c,active:d=!0}){let[u,h]=function(e,r){let s=`vibedeckx:activeTab:${e??"none"}:${r??"main"}`,[i,n]=(0,$.useState)(()=>localStorage.getItem(s)??"agent");return(0,$.useEffect)(()=>{n(localStorage.getItem(s)??"agent")},[s]),[i,(0,$.useCallback)(e=>{n(e),localStorage.setItem(s,e)},[s])]}(e,r),f=(0,$.useRef)(a);(0,$.useEffect)(()=>{void 0===a||f.current!==a&&(f.current=a,h("agent"))},[a,h]);let p=(0,$.useRef)(l);(0,$.useEffect)(()=>{void 0===l||p.current!==l&&(p.current=l,h("diff"))},[l,h]);let m=function({projectId:e,branch:r,target:s,enabled:i=!0}){let[n,o]=(0,$.useState)(null),a=(0,$.useRef)(0);return(0,$.useEffect)(()=>{if(o(null),!i||!e)return;let n=++a.current;wI(()=>rx.api.listProjectFiles(e,r,s),{cancelled:()=>n!==a.current}).then(e=>{n===a.current&&e&&o(function(e){let r=`idx-${++wP}`,s=new Set(e),i=new Map;for(let r of e){let e=wB(r),s=i.get(e);s?s.push(r):i.set(e,[r])}return{version:r,resolve(e){if(!e)return[];let r=e.replace(/^\/+/,"");if(!r)return[];if(r.includes("/")){if(s.has(r))return[r];let e=wB(r);return(i.get(e)??[]).filter(e=>e===r||e.endsWith("/"+r)||r.endsWith("/"+e))}return i.get(r)??[]}}}(e.files))})},[e,r,s,i]),n}({projectId:e,branch:r,target:i&&!i.path?"remote":void 0,enabled:d}),g=(0,$.useRef)(0),[x,v]=(0,$.useState)(null),_=(0,$.useCallback)((e,r=null)=>{h("files"),v({path:e,line:r,nonce:++g.current})},[h]),y=(0,$.useMemo)(()=>({openFile:_,index:m}),[_,m]);return(0,z.jsx)(wT,{value:y,children:(0,z.jsxs)("div",{className:"h-full flex flex-col",children:[(0,z.jsx)("div",{className:"flex items-center px-3 gap-4 border-b border-border",children:[{id:"agent",icon:oN,label:"Agent"},{id:"executors",icon:ok,label:"Executors"},{id:"diff",icon:rb,label:"Diff"},{id:"terminal",icon:cB,label:"Terminal"},{id:"preview",icon:r_,label:"Browser"},{id:"files",icon:rv,label:"Files"}].map(({id:e,icon:r,label:s})=>(0,z.jsxs)($.Fragment,{children:[(0,z.jsxs)("button",{onClick:()=>h(e),className:(0,ey.cn)("flex items-center gap-0.5 py-2.5 text-xs font-medium border-b-2 transition-colors",u===e?"text-foreground border-primary":"text-muted-foreground border-transparent hover:text-foreground/70"),children:[(0,z.jsx)(r,{className:"h-3.5 w-3.5"}),s]}),"agent"===e&&(0,z.jsx)("span",{className:"h-4 w-px bg-border/60 mx-1.5","aria-hidden":!0})]},e))}),(0,z.jsxs)("div",{className:"relative flex-1 overflow-hidden",children:[(0,z.jsx)("div",{className:(0,ey.cn)("absolute inset-0 overflow-hidden","agent"!==u&&"invisible pointer-events-none"),children:o}),(0,z.jsx)("div",{className:(0,ey.cn)("absolute inset-0 overflow-hidden","executors"!==u&&"hidden"),children:(0,z.jsx)(vq,{projectId:e,selectedBranch:r,project:i,onExecutorModeChange:n})}),(0,z.jsx)("div",{className:(0,ey.cn)("absolute inset-0 overflow-hidden","diff"!==u&&"hidden"),children:(0,z.jsx)(v5,{projectId:e,selectedBranch:r,onMergeRequest:s,project:i,mergeTarget:c,compareRequestNonce:l})}),(0,z.jsx)("div",{className:(0,ey.cn)("absolute inset-0 overflow-hidden","terminal"!==u&&"hidden"),children:(0,z.jsx)(v4,{projectId:e,selectedBranch:r,project:i})}),(0,z.jsx)("div",{className:(0,ey.cn)("absolute inset-0 overflow-hidden","preview"!==u&&"hidden"),children:(0,z.jsx)(_s,{projectId:e,selectedBranch:r,project:i})}),(0,z.jsx)("div",{className:(0,ey.cn)("absolute inset-0 overflow-hidden","files"!==u&&"hidden"),children:(0,z.jsx)(wR,{projectId:e,project:i,selectedBranch:r,navRequest:x})})]})]})})}var wz=Symbol.for("immer-nothing"),w$=Symbol.for("immer-draftable"),wW=Symbol.for("immer-state");function wH(e){throw Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var wU=Object.getPrototypeOf;function wK(e){return!!e&&!!e[wW]}function wq(e){return!!e&&(wG(e)||Array.isArray(e)||!!e[w$]||!!e.constructor?.[w$]||w0(e)||w1(e))}var wV=Object.prototype.constructor.toString(),wY=new WeakMap;function wG(e){if(!e||"object"!=typeof e)return!1;let r=Object.getPrototypeOf(e);if(null===r||r===Object.prototype)return!0;let s=Object.hasOwnProperty.call(r,"constructor")&&r.constructor;if(s===Object)return!0;if("function"!=typeof s)return!1;let i=wY.get(s);return void 0===i&&(i=Function.toString.call(s),wY.set(s,i)),i===wV}function wX(e,r,s=!0){0===wJ(e)?(s?Reflect.ownKeys(e):Object.keys(e)).forEach(s=>{r(s,e[s],e)}):e.forEach((s,i)=>r(i,s,e))}function wJ(e){let r=e[wW];return r?r.type_:Array.isArray(e)?1:w0(e)?2:3*!!w1(e)}function wZ(e,r){return 2===wJ(e)?e.has(r):Object.prototype.hasOwnProperty.call(e,r)}function wQ(e,r,s){let i=wJ(e);2===i?e.set(r,s):3===i?e.add(s):e[r]=s}function w0(e){return e instanceof Map}function w1(e){return e instanceof Set}function w2(e){return e.copy_||e.base_}function w5(e,r){if(w0(e))return new Map(e);if(w1(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let s=wG(e);if(!0!==r&&("class_only"!==r||s)){let r=wU(e);return null!==r&&s?{...e}:Object.assign(Object.create(r),e)}{let r=Object.getOwnPropertyDescriptors(e);delete r[wW];let s=Reflect.ownKeys(r);for(let i=0;i<s.length;i++){let n=s[i],o=r[n];!1===o.writable&&(o.writable=!0,o.configurable=!0),(o.get||o.set)&&(r[n]={configurable:!0,writable:!0,enumerable:o.enumerable,value:e[n]})}return Object.create(wU(e),r)}}function w3(e,r=!1){return w6(e)||wK(e)||!wq(e)||(wJ(e)>1&&Object.defineProperties(e,{set:w4,add:w4,clear:w4,delete:w4}),Object.freeze(e),r&&Object.values(e).forEach(e=>w3(e,!0))),e}var w4={value:function(){wH(2)}};function w6(e){return null===e||"object"!=typeof e||Object.isFrozen(e)}var w8={};function w7(e){let r=w8[e];return r||wH(0,e),r}function w9(e,r){r&&(w7("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=r)}function Se(e){St(e),e.drafts_.forEach(Ss),e.drafts_=null}function St(e){e===I&&(I=e.parent_)}function Sr(e){return I={drafts_:[],parent_:I,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Ss(e){let r=e[wW];0===r.type_||1===r.type_?r.revoke_():r.revoked_=!0}function Si(e,r){r.unfinalizedDrafts_=r.drafts_.length;let s=r.drafts_[0];return void 0!==e&&e!==s?(s[wW].modified_&&(Se(r),wH(4)),wq(e)&&(e=Sn(r,e),r.parent_||Sa(r,e)),r.patches_&&w7("Patches").generateReplacementPatches_(s[wW].base_,e,r.patches_,r.inversePatches_)):e=Sn(r,s,[]),Se(r),r.patches_&&r.patchListener_(r.patches_,r.inversePatches_),e!==wz?e:void 0}function Sn(e,r,s){if(w6(r))return r;let i=e.immer_.shouldUseStrictIteration(),n=r[wW];if(!n)return wX(r,(i,o)=>So(e,n,r,i,o,s),i),r;if(n.scope_!==e)return r;if(!n.modified_)return Sa(e,n.base_,!0),n.base_;if(!n.finalized_){n.finalized_=!0,n.scope_.unfinalizedDrafts_--;let r=n.copy_,o=r,a=!1;3===n.type_&&(o=new Set(r),r.clear(),a=!0),wX(o,(i,o)=>So(e,n,r,i,o,s,a),i),Sa(e,r,!1),s&&e.patches_&&w7("Patches").generatePatches_(n,s,e.patches_,e.inversePatches_)}return n.copy_}function So(e,r,s,i,n,o,a){if(null==n||"object"!=typeof n&&!a)return;let l=w6(n);if(!l||a){if(wK(n)){let a=Sn(e,n,o&&r&&3!==r.type_&&!wZ(r.assigned_,i)?o.concat(i):void 0);if(wQ(s,i,a),!wK(a))return;e.canAutoFreeze_=!1}else a&&s.add(n);if(wq(n)&&!l){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1||r&&r.base_&&r.base_[i]===n&&l)return;Sn(e,n),(!r||!r.scope_.parent_)&&"symbol"!=typeof i&&(w0(s)?s.has(i):Object.prototype.propertyIsEnumerable.call(s,i))&&Sa(e,n)}}}function Sa(e,r,s=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&w3(r,s)}var Sl={get(e,r){if(r===wW)return e;let s=w2(e);if(!wZ(s,r)){var i;let n;return i=e,(n=Su(s,r))?"value"in n?n.value:n.get?.call(i.draft_):void 0}let n=s[r];return e.finalized_||!wq(n)?n:n===Sd(e.base_,r)?(Sf(e),e.copy_[r]=Sp(n,e)):n},has:(e,r)=>r in w2(e),ownKeys:e=>Reflect.ownKeys(w2(e)),set(e,r,s){let i=Su(w2(e),r);if(i?.set)return i.set.call(e.draft_,s),!0;if(!e.modified_){let i=Sd(w2(e),r),n=i?.[wW];if(n&&n.base_===s)return e.copy_[r]=s,e.assigned_[r]=!1,!0;if((s===i?0!==s||1/s==1/i:s!=s&&i!=i)&&(void 0!==s||wZ(e.base_,r)))return!0;Sf(e),Sh(e)}return!!(e.copy_[r]===s&&(void 0!==s||r in e.copy_)||Number.isNaN(s)&&Number.isNaN(e.copy_[r]))||(e.copy_[r]=s,e.assigned_[r]=!0,!0)},deleteProperty:(e,r)=>(void 0!==Sd(e.base_,r)||r in e.base_?(e.assigned_[r]=!1,Sf(e),Sh(e)):delete e.assigned_[r],e.copy_&&delete e.copy_[r],!0),getOwnPropertyDescriptor(e,r){let s=w2(e),i=Reflect.getOwnPropertyDescriptor(s,r);return i?{writable:!0,configurable:1!==e.type_||"length"!==r,enumerable:i.enumerable,value:s[r]}:i},defineProperty(){wH(11)},getPrototypeOf:e=>wU(e.base_),setPrototypeOf(){wH(12)}},Sc={};function Sd(e,r){let s=e[wW];return(s?w2(s):e)[r]}function Su(e,r){if(!(r in e))return;let s=wU(e);for(;s;){let e=Object.getOwnPropertyDescriptor(s,r);if(e)return e;s=wU(s)}}function Sh(e){!e.modified_&&(e.modified_=!0,e.parent_&&Sh(e.parent_))}function Sf(e){e.copy_||(e.copy_=w5(e.base_,e.scope_.immer_.useStrictShallowCopy_))}function Sp(e,r){let s=w0(e)?w7("MapSet").proxyMap_(e,r):w1(e)?w7("MapSet").proxySet_(e,r):function(e,r){let s=Array.isArray(e),i={type_:+!!s,scope_:r?r.scope_:I,modified_:!1,finalized_:!1,assigned_:{},parent_:r,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},n=i,o=Sl;s&&(n=[i],o=Sc);let{revoke:a,proxy:l}=Proxy.revocable(n,o);return i.draft_=l,i.revoke_=a,l}(e,r);return(r?r.scope_:I).drafts_.push(s),s}wX(Sl,(e,r)=>{Sc[e]=function(){return arguments[0]=arguments[0][0],r.apply(this,arguments)}}),Sc.deleteProperty=function(e,r){return Sc.set.call(this,e,r,void 0)},Sc.set=function(e,r,s){return Sl.set.call(this,e[0],r,s,e[0])};var Sm=new class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(e,r,s)=>{let i;if("function"==typeof e&&"function"!=typeof r){let s=r;r=e;let i=this;return function(e=s,...n){return i.produce(e,e=>r.call(this,e,...n))}}if("function"!=typeof r&&wH(6),void 0!==s&&"function"!=typeof s&&wH(7),wq(e)){let n=Sr(this),o=Sp(e,void 0),a=!0;try{i=r(o),a=!1}finally{a?Se(n):St(n)}return w9(n,s),Si(i,n)}if(e&&"object"==typeof e)wH(1,e);else{if(void 0===(i=r(e))&&(i=e),i===wz&&(i=void 0),this.autoFreeze_&&w3(i,!0),s){let r=[],n=[];w7("Patches").generateReplacementPatches_(e,i,r,n),s(r,n)}return i}},this.produceWithPatches=(e,r)=>{let s,i;return"function"==typeof e?(r,...s)=>this.produceWithPatches(r,r=>e(r,...s)):[this.produce(e,r,(e,r)=>{s=e,i=r}),s,i]},"boolean"==typeof e?.autoFreeze&&this.setAutoFreeze(e.autoFreeze),"boolean"==typeof e?.useStrictShallowCopy&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),"boolean"==typeof e?.useStrictIteration&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){var r;wq(e)||wH(8),wK(e)&&(wK(r=e)||wH(10,r),e=function e(r){let s;if(!wq(r)||w6(r))return r;let i=r[wW],n=!0;if(i){if(!i.modified_)return i.base_;i.finalized_=!0,s=w5(r,i.scope_.immer_.useStrictShallowCopy_),n=i.scope_.immer_.shouldUseStrictIteration()}else s=w5(r,!0);return wX(s,(r,i)=>{wQ(s,r,e(i))},n),i&&(i.finalized_=!1),s}(r));let s=Sr(this),i=Sp(e,void 0);return i[wW].isManual_=!0,St(s),i}finishDraft(e,r){let s=e&&e[wW];s&&s.isManual_||wH(9);let{scope_:i}=s;return w9(i,r),Si(void 0,i)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,r){let s;for(s=r.length-1;s>=0;s--){let i=r[s];if(0===i.path.length&&"replace"===i.op){e=i.value;break}}s>-1&&(r=r.slice(s+1));let i=w7("Patches").applyPatches_;return wK(e)?i(e,r):this.produce(e,e=>i(e,r))}}().produce;let Sg="vibedeckx:placeholder-workspaces";function Sx(e){try{window.localStorage.setItem(Sg,JSON.stringify([...e]))}catch{}}let Sv=function(){try{let e=window.localStorage.getItem(Sg);if(!e)return new Map;let r=JSON.parse(e);if(!Array.isArray(r))return new Map;let s=new Map;for(let e of r)Array.isArray(e)&&"string"==typeof e[0]&&"number"==typeof e[1]?s.set(e[0],e[1]):"string"==typeof e&&s.set(e,Date.now());return s}catch{return new Map}}(),S_=new Set,Sy=new Map;function Sb(){for(let e of S_)e()}function Sw(e){return S_.add(e),()=>{S_.delete(e)}}function SS(){return Sv}function SC(){return Sy}function Sj(e,r,s){return`${e}:${r??""}:${s??""}`}function Sk(e){if(!Sv.has(e))return!1;let r=new Map(Sv);return r.delete(e),Sx(Sv=r),Sb(),!0}function SN(){return"localhost"===window.location.hostname&&"3000"===window.location.port?"http://localhost:5173":""}async function SD(e,r,s,i){let n=await (0,rx.authFetch)(`${SN()}/api/projects/${e}/agent-sessions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branch:r,permissionMode:s,agentType:i})});if(!n.ok)throw Error("Failed to load session");return n.json()}async function SE(e,r){let s=await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}/message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:r})});if(!s.ok){let r="";try{let e=await s.json();if(e.errorCode){let s=[`${e.errorCode}`];e.attempts&&s.push(`${e.attempts} attempts`),e.totalDurationMs&&s.push(`${(e.totalDurationMs/1e3).toFixed(1)}s`),r=` (${s.join(", ")})`}else e.error&&(r=` — ${e.error}`)}catch{}throw console.error(`[AgentSession] /message failed: status=${s.status}, sessionId=${e}, detail=${r}`),Error(`Failed to send message [${s.status}]${r}`)}}async function SR(e,r){let s=await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}/paste`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:r})});if(!s.ok){let r="";try{let e=await s.json();if(e.errorCode){let s=[`${e.errorCode}`];e.attempts&&s.push(`${e.attempts} attempts`),e.totalDurationMs&&s.push(`${(e.totalDurationMs/1e3).toFixed(1)}s`),r=` (${s.join(", ")})`}else e.error&&(r=` — ${e.error}`)}catch{}throw console.error(`[AgentSession] /paste failed: status=${s.status}, sessionId=${e}, detail=${r}`),Error(`Failed to upload paste [${s.status}]${r}`)}return s.json()}async function SA(e,r){if(!(await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}/restart`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentType:r})})).ok)throw Error("Failed to restart session")}async function SM(e,r){let s=await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}/agent-type`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentType:r})});if(!s.ok){let e="";try{let r=await s.json();r.error&&(e=r.error)}catch{}throw Error(e||`Failed to switch agent [${s.status}]`)}}async function SF(e){if(!(await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}/stop`,{method:"POST"})).ok)throw Error("Failed to stop session")}async function ST(e,r){if(!(await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}/switch-mode`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:r})})).ok)throw Error("Failed to switch mode")}async function SP(e,r){if(!(await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}/accept-plan`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planContent:r})})).ok)throw Error("Failed to accept plan")}let SB=new Map;function SL(e,r,s){return`${e}:${r??""}:${s??"latest"}`}async function SI(e){let r=await (0,rx.authFetch)(`${SN()}/api/agent-sessions/${e}`);if(!r.ok)throw Error(`Session ${e} not found`);return r.json()}let SO=(0,ew.default)("user",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]),Sz=(0,ew.default)("wrench",[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]]),S$=(0,ew.default)("brain",[["path",{d:"M12 18V5",key:"adv99a"}],["path",{d:"M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4",key:"1e3is1"}],["path",{d:"M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5",key:"1gqd8o"}],["path",{d:"M17.997 5.125a4 4 0 0 1 2.526 5.77",key:"iwvgf7"}],["path",{d:"M18 18a4 4 0 0 0 2-7.464",key:"efp6ie"}],["path",{d:"M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517",key:"1gq6am"}],["path",{d:"M6 18a4 4 0 0 1-2-7.464",key:"k1g0md"}],["path",{d:"M6.003 5.125a4 4 0 0 0-2.526 5.77",key:"q97ue3"}]]),SW=(0,ew.default)("circle-alert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]),SH=(0,ew.default)("circle-question-mark",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]),SU=(0,ew.default)("file-check",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m9 15 2 2 4-4",key:"1grp1n"}]]),SK=(0,ew.default)("folder-search",[["path",{d:"M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1",key:"1bw5m7"}],["path",{d:"m21 21-1.9-1.9",key:"1g2n9r"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}]]),Sq=(0,ew.default)("workflow",[["rect",{width:"8",height:"8",x:"3",y:"3",rx:"2",key:"by2w9f"}],["path",{d:"M7 11v4a2 2 0 0 0 2 2h4",key:"xkn7yn"}],["rect",{width:"8",height:"8",x:"13",y:"13",rx:"2",key:"1cgmvn"}]]),SV=(0,ew.default)("file-pen-line",[["path",{d:"m18.226 5.226-2.52-2.52A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-.351",key:"1k2beg"}],["path",{d:"M21.378 12.626a1 1 0 0 0-3.004-3.004l-4.01 4.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z",key:"2t3380"}],["path",{d:"M8 18h1",key:"13wk12"}]]),SY=(0,ew.default)("file-plus-corner",[["path",{d:"M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35",key:"17jvcc"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M14 19h6",key:"bvotb8"}],["path",{d:"M17 16v6",key:"18yu1i"}]]),SG=(0,ew.default)("earth",[["path",{d:"M21.54 15H17a2 2 0 0 0-2 2v4.54",key:"1djwo0"}],["path",{d:"M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17",key:"1tzkfa"}],["path",{d:"M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05",key:"14pb5j"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]),SX=(0,ew.default)("shield-alert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);var aR=aE,bJ=aE;let SJ=RegExp("(?<![\\w./-])([\\w-]+(?:[./][\\w-]+)+)(?::(\\d+)(?::\\d+)?|#L(\\d+)(?:-L?\\d+)?)?","g"),SZ=/\[([^\]\n]*)\]\(\s*([^)\s]+?)\s*\)/g;function SQ(e){return e.includes("/")||/\.[A-Za-z0-9]+$/.test(e)}function S0(e){let r=e.trim();if(!r)return null;let s=/^(.*?)(?::(\d+)(?::\d+)?|#L(\d+)(?:-L?\d+)?)?$/.exec(r);if(!s||!s[1])return null;let i=s[1];return/^[a-z][a-z0-9+.-]*:/i.test(i)||i.startsWith("//")||i.startsWith("#")?null:{rawPath:i,line:s[2]?Number(s[2]):s[3]?Number(s[3]):null}}function S1(e){let r=r=>e.index?e.index.resolve(r):[];function s(e,r,s){return{type:"element",tagName:"a",properties:{className:["file-ref"],href:"#file-ref",dataFilePaths:JSON.stringify(e),...null!=r?{dataFileLine:String(r)}:{}},children:s}}return e=>{!function e(i,n=!1){if(!i.children)return;let o=n||"pre"===i.tagName,a=[];for(let n of i.children)"text"===n.type?o?a.push(n):a.push(...function(e){let i=function(e){let r,s=[],i=[];for(SZ.lastIndex=0;null!==(r=SZ.exec(e));){let e=S0(r[2]);if(!e||!SQ(e.rawPath))continue;let n=r.index,o=r.index+r[0].length;s.push({start:n,end:o,rawPath:e.rawPath,line:e.line,display:r[1]||void 0}),i.push([n,o])}for(SJ.lastIndex=0;null!==(r=SJ.exec(e));){let e=r.index;if(i.some(([r,s])=>e>=r&&e<s))continue;let n=r[1];if(!SQ(n))continue;let o=r[2]?Number(r[2]):r[3]?Number(r[3]):null;s.push({start:e,end:e+r[0].length,rawPath:n,line:o})}return s.sort((e,r)=>e.start-r.start),s}(e);if(0===i.length)return[{type:"text",value:e}];let n=[],o=0,a=!1;for(let l of i){let i=r(l.rawPath);if(0===i.length)continue;l.start>o&&n.push({type:"text",value:e.slice(o,l.start)});let c=l.display??e.slice(l.start,l.end);n.push(s(i,l.line,[{type:"text",value:c}])),o=l.end,a=!0}return a?(o<e.length&&n.push({type:"text",value:e.slice(o)}),n):[{type:"text",value:e}]}(n.value??"")):"element"===n.type&&"pre"===n.tagName?(e(n,!0),a.push(n)):"element"!==n.type||"a"!==n.tagName||o?(e(n,o),a.push(n)):a.push(...function(e){let i=S0(String(e.properties?.href??""));if(!i)return[e];let n=r(i.rawPath);return 0===n.length?e.children??[]:[s(n,i.line,e.children??[])]}(n));i.children=a}(e)}}let S2="text-primary underline decoration-dotted underline-offset-2 cursor-pointer hover:decoration-solid";function S5({node:e,children:r,href:s,...i}){let{openFile:n}=wF(),o=e?.properties?.dataFilePaths;if(!o)return"string"==typeof s&&s.startsWith("#")?(0,z.jsx)("a",{href:s,...i,children:r}):(0,z.jsx)("a",{href:s,target:"_blank",rel:"noreferrer noopener",...i,children:r});let a=[];try{a=JSON.parse(o)}catch{a=[]}let l=e?.properties?.dataFileLine,c=null!=l?Number(l):null;return a.length<=1?(0,z.jsx)("a",{href:"#",className:S2,onClick:e=>{e.preventDefault(),a[0]&&n(a[0],c)},children:r}):(0,z.jsx)(S3,{paths:a,line:c,children:r})}function S3({paths:e,line:r,children:s}){let{openFile:i}=wF();return(0,z.jsxs)(of,{children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsx)("a",{href:"#",className:S2,onClick:e=>e.preventDefault(),children:s})}),(0,z.jsxs)(om,{align:"start",className:"max-w-md",children:[(0,z.jsxs)(oy,{children:[e.length," matching files"]}),e.map(e=>(0,z.jsx)(og,{className:"font-mono text-xs",onSelect:()=>i(e,r),children:e},e))]})]})}let S4=(0,$.memo)(function({children:e}){let{index:r}=wF(),{harden:s,...i}=bJ.e,n=[...Object.values(i),[S1,{index:r}],...s?[s]:[]];return(0,z.jsx)(aR.i,{className:"size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",rehypePlugins:n,components:{a:S5},children:e},r?.version??"no-file-ref-index")});function S6({input:e,messageIndex:r}){let{sendMessage:s,messages:i}=ke(),n=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&Array.isArray(r.questions)&&r.questions.length>0&&r.questions.every(e=>"string"==typeof e.question&&"string"==typeof e.header&&Array.isArray(e.options)))return r}catch{}return null}(e),o=i[r+1],a=o?.type==="user",l=a?o.content:"",c="string"==typeof l?l:l.filter(e=>"text"===e.type).map(e=>e.text).join("\n");if(!n){let r="string"==typeof e?e:JSON.stringify(e,null,2);return(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:r.length>500?r.substring(0,500)+"...":r})}return a?(0,z.jsx)(S8,{questions:n.questions,answeredText:c}):(0,z.jsx)(S7,{questions:n.questions,sendMessage:s})}function S8({questions:e,answeredText:r}){return(0,z.jsx)("div",{className:"space-y-3 mt-2",children:e.map((e,s)=>(0,z.jsxs)("div",{className:"rounded-lg border bg-muted/30 p-3",children:[(0,z.jsx)("div",{className:"flex items-center gap-2 mb-1.5",children:(0,z.jsx)(sy,{variant:"secondary",className:"text-[10px]",children:e.header})}),(0,z.jsx)("p",{className:"text-sm text-muted-foreground mb-2",children:e.question}),(0,z.jsxs)("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-400",children:[(0,z.jsx)(rS,{className:"h-4 w-4"}),(0,z.jsx)("span",{className:"font-medium",children:r})]})]},s))})}function S7({questions:e,sendMessage:r}){let[s,i]=(0,$.useState)(new Map),[n,o]=(0,$.useState)(new Map),[a,l]=(0,$.useState)(new Set),[c,d]=(0,$.useState)(!1);async function u(){let i=[];for(let r=0;r<e.length;r++)if(a.has(r)){let e=n.get(r)?.trim();e&&i.push(e)}else{let e=s.get(r);e&&e.size>0&&i.push(Array.from(e).join(", "))}if(i.length>0){d(!0);try{await r(i.join("\n"))}finally{d(!1)}}}let h=e.some((e,r)=>{if(a.has(r))return!!n.get(r)?.trim();let i=s.get(r);return i&&i.size>0});return(0,z.jsxs)("div",{className:"space-y-4 mt-2",children:[e.map((e,r)=>{let c=s.get(r)||new Set,d=n.get(r)||"",u=a.has(r);return(0,z.jsxs)("div",{className:"rounded-lg border bg-card p-3",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,z.jsx)(SH,{className:"h-3.5 w-3.5 text-violet-500"}),(0,z.jsx)(sy,{variant:"secondary",className:"text-[10px]",children:e.header})]}),(0,z.jsx)("p",{className:"text-sm font-medium mb-3",children:e.question}),(0,z.jsxs)("div",{className:"grid gap-2",children:[e.options.map(s=>{let n=c.has(s.label)&&!u;return(0,z.jsx)(W.Button,{variant:n?"default":"outline",className:(0,ey.cn)("h-auto py-2 px-3 justify-start text-left whitespace-normal",n&&"ring-2 ring-primary/50"),onClick:()=>{var n,o;return n=s.label,o=e.multiSelect,void(i(e=>{let s=new Map(e),i=new Set(s.get(r)||[]);return o?i.has(n)?i.delete(n):i.add(n):i.has(n)?i.clear():(i.clear(),i.add(n)),s.set(r,i),s}),l(e=>{let s=new Set(e);return s.delete(r),s}))},children:(0,z.jsxs)("div",{children:[(0,z.jsx)("span",{className:"font-medium text-sm",children:s.label}),s.description&&(0,z.jsx)("span",{className:"block text-xs text-muted-foreground mt-0.5",children:s.description})]})},s.label)}),(0,z.jsx)("div",{className:"flex items-center gap-2 mt-1",children:(0,z.jsx)(ro,{placeholder:"Other...",value:d,onChange:e=>{var s;return s=e.target.value,void(o(e=>new Map(e).set(r,s)),s&&(i(e=>{let s=new Map(e);return s.set(r,new Set),s}),l(e=>new Set(e).add(r))))},className:"text-sm"})})]})]},r)}),(0,z.jsxs)(W.Button,{onClick:u,disabled:!h||c,size:"sm",className:"active:scale-95 transition-transform",children:[c&&(0,z.jsx)(rj,{className:"h-3.5 w-3.5 animate-spin"}),c?"Submitting...":"Submit"]})]})}function S9(e){try{return JSON.parse(e)}catch{return null}}function Ce({input:e,messageIndex:r}){let{messages:s,acceptPlan:i,permissionMode:n,agentType:o}=ke(),[a,l]=(0,$.useState)(!0),[c,d]=(0,$.useState)(!1),u=function(e,r,s){let i="string"==typeof e?S9(e):e;if(i&&"object"==typeof i&&"plan"in i){let e=i.plan;if(e)return e}if("claude-code"===s)for(let e=r.length-1;e>=0;e--){let s=r[e];if("tool_use"===s.type&&"Write"===s.tool){let e="string"==typeof s.input?S9(s.input):s.input;if(e&&"object"==typeof e&&e.file_path?.includes(".claude/plans/")&&e.content)return e.content}}return"Plan written to file"}(e,s,o),h=(0,$.useCallback)(async()=>{d(!0);try{await i(u)}catch{d(!1)}},[i,u]),f="edit"===n,p=!1,m="";for(let e=r+1;e<s.length;e++){let r=s[e];if(r?.type==="user"){p=!0;let e=r.content??"";m="string"==typeof e?e:e.filter(e=>"text"===e.type).map(e=>e.text).join("\n");break}}return(f&&!p&&(p=!0),f||p)?(0,z.jsxs)("div",{className:"space-y-2 mt-2",children:[f?(0,z.jsxs)(sy,{variant:"default",className:"bg-green-600 hover:bg-green-700 text-white",children:[(0,z.jsx)(rS,{className:"h-3 w-3 mr-1"}),"Plan Accepted"]}):(0,z.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,z.jsx)(gY,{className:"h-3.5 w-3.5"}),(0,z.jsxs)("span",{children:["Feedback sent: ",m.length>100?m.substring(0,100)+"...":m]})]}),(0,z.jsxs)("details",{open:!f,children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"View Plan"}),(0,z.jsx)("div",{className:"mt-2 rounded-lg border p-3 bg-muted/30",children:(0,z.jsx)("div",{className:"prose prose-sm dark:prose-invert max-w-none break-words [&_pre]:overflow-x-auto [&_pre]:max-w-full [&_code]:break-all [&_p]:break-words",style:{fontSize:"var(--conv-font-size, 14px)"},children:(0,z.jsx)(wt,{children:u})})})]})]}):(0,z.jsxs)("div",{className:"space-y-3 mt-2",children:[(0,z.jsxs)("div",{className:"rounded-lg border p-3 bg-card",children:[(0,z.jsxs)("button",{onClick:()=>l(!a),className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground mb-2 block",children:[a?"Collapse":"Expand"," Plan"]}),a&&(0,z.jsx)("div",{className:"prose prose-sm dark:prose-invert max-w-none break-words [&_pre]:overflow-x-auto [&_pre]:max-w-full [&_code]:break-all [&_p]:break-words max-h-96 overflow-y-auto",style:{fontSize:"var(--conv-font-size, 14px)"},children:(0,z.jsx)(wt,{children:u})})]}),(0,z.jsxs)(W.Button,{onClick:h,disabled:c,className:"bg-green-600 hover:bg-green-700 text-white",size:"sm",children:[c?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):(0,z.jsx)(ru,{className:"h-3.5 w-3.5 mr-1.5"}),c?"Accepting Plan...":"Accept Plan & Start Editing"]})]})}function Ct({requestId:e,command:r,cwd:s,messageIndex:i}){let{messages:n,sessionId:o}=ke(),[a,l]=(0,$.useState)(!1),[c,d]=(0,$.useState)(null),u=!1;for(let e=i+1;e<n.length;e++)if(n[e]?.type==="user"){u=!0;break}c&&(u=!0);let h=(0,$.useCallback)(async r=>{if(o){l(!0),d(r);try{await (0,rx.sendApprovalResponse)(o,e,r)}catch{d(null),l(!1)}}},[o,e]);return u?(0,z.jsxs)("div",{className:"space-y-2 mt-2",children:[(0,z.jsxs)("div",{className:"rounded-lg border bg-muted/30 p-3",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,z.jsx)(ok,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,z.jsx)("span",{className:"text-xs text-muted-foreground",children:"Command"})]}),(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:r||"(empty)"}),s&&(0,z.jsxs)("p",{className:"text-xs text-muted-foreground mt-1",children:["cwd: ",s]})]}),(0,z.jsxs)(sy,{variant:"default",className:"decline"===c?"bg-red-600 hover:bg-red-700 text-white":"bg-green-600 hover:bg-green-700 text-white",children:[(0,z.jsx)(rS,{className:"h-3 w-3 mr-1"}),"decline"===c?"Denied":"Allowed"]})]}):(0,z.jsxs)("div",{className:"space-y-2 mt-2",children:[(0,z.jsxs)("div",{className:"rounded-lg border bg-card p-3",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,z.jsx)(ok,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,z.jsx)("span",{className:"text-xs text-muted-foreground",children:"Command"})]}),(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:r||"(empty)"}),s&&(0,z.jsxs)("p",{className:"text-xs text-muted-foreground mt-1",children:["cwd: ",s]})]}),(0,z.jsxs)("div",{className:"flex gap-2",children:[(0,z.jsxs)(W.Button,{onClick:()=>h("accept"),disabled:a,className:"bg-green-600 hover:bg-green-700 text-white",size:"sm",children:[a&&"accept"===c?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,z.jsx)(rS,{className:"h-3.5 w-3.5 mr-1"}),"Allow"]}),(0,z.jsxs)(W.Button,{onClick:()=>h("decline"),disabled:a,variant:"destructive",size:"sm",children:[a&&"decline"===c?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,z.jsx)(rC,{className:"h-3.5 w-3.5 mr-1"}),"Deny"]})]})]})}function Cr({requestId:e,changes:r,messageIndex:s}){let{messages:i,sessionId:n}=ke(),[o,a]=(0,$.useState)(!1),[l,c]=(0,$.useState)(null),d=!1;for(let e=s+1;e<i.length;e++)if(i[e]?.type==="user"){d=!0;break}l&&(d=!0);let u=(0,$.useCallback)(async r=>{if(n){a(!0),c(r);try{await (0,rx.sendApprovalResponse)(n,e,r)}catch{c(null),a(!1)}}},[n,e]),h=r??[],f=()=>(0,z.jsx)("div",{className:"rounded-lg border bg-muted/30 p-3 space-y-2",children:0===h.length?(0,z.jsx)("p",{className:"text-xs text-muted-foreground",children:"No file changes"}):h.map((e,r)=>(0,z.jsxs)("div",{children:[(0,z.jsxs)("div",{className:"flex items-center gap-2",children:[(0,z.jsx)(bt,{className:"h-3 w-3 text-muted-foreground flex-shrink-0"}),(0,z.jsx)("code",{className:"text-xs break-all",children:e.path}),(0,z.jsx)(sy,{variant:"secondary",className:`text-[10px] ${function(e){switch(e){case"added":case"add":return"bg-green-500/10 text-green-600";case"deleted":case"delete":return"bg-red-500/10 text-red-600";default:return"bg-blue-500/10 text-blue-600"}}(e.kind)}`,children:function(e){switch(e){case"added":case"add":return"added";case"deleted":case"delete":return"deleted";default:return"modified"}}(e.kind)})]}),e.diff&&(0,z.jsxs)("details",{className:"mt-1",children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"View diff"}),(0,z.jsx)("pre",{className:"mt-1 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.diff.split("\n").map((e,r)=>{let s="";return e.startsWith("+")?s="bg-green-500/10 text-green-700 dark:text-green-400":e.startsWith("-")&&(s="bg-red-500/10 text-red-700 dark:text-red-400"),(0,z.jsx)("div",{className:s,children:e},r)})})]})]},r))});return d?(0,z.jsxs)("div",{className:"space-y-2 mt-2",children:[f(),(0,z.jsxs)(sy,{variant:"default",className:"decline"===l?"bg-red-600 hover:bg-red-700 text-white":"bg-green-600 hover:bg-green-700 text-white",children:[(0,z.jsx)(rS,{className:"h-3 w-3 mr-1"}),"decline"===l?"Denied":"Allowed"]})]}):(0,z.jsxs)("div",{className:"space-y-2 mt-2",children:[f(),(0,z.jsxs)("div",{className:"flex gap-2",children:[(0,z.jsxs)(W.Button,{onClick:()=>u("accept"),disabled:o,className:"bg-green-600 hover:bg-green-700 text-white",size:"sm",children:[o&&"accept"===l?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,z.jsx)(rS,{className:"h-3.5 w-3.5 mr-1"}),"Allow"]}),(0,z.jsxs)(W.Button,{onClick:()=>u("decline"),disabled:o,variant:"destructive",size:"sm",children:[o&&"decline"===l?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,z.jsx)(rC,{className:"h-3.5 w-3.5 mr-1"}),"Deny"]})]})]})}let Cs=(0,ew.default)("circle-plus",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"M12 8v8",key:"napkw2"}]]),Ci=(0,ew.default)("badge",[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}]]);function Cn({status:e,className:r}){switch(e){case"completed":return(0,z.jsx)(rS,{className:(0,ey.cn)("h-4 w-4 text-green-500",r)});case"in_progress":return(0,z.jsx)(rj,{className:(0,ey.cn)("h-4 w-4 text-cyan-500 animate-spin",r)});case"pending":default:return(0,z.jsx)(rw,{className:(0,ey.cn)("h-4 w-4 text-muted-foreground",r)});case"deleted":return(0,z.jsx)(rC,{className:(0,ey.cn)("h-4 w-4 text-red-400",r)})}}function Co(e,r){try{let s="string"==typeof e?JSON.parse(e):e;if(s&&"object"==typeof s&&r(s))return s}catch{}return null}function Ca({input:e}){let r="string"==typeof e?e:JSON.stringify(e,null,2);return(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:r.length>500?r.substring(0,500)+"...":r})}function Cl({input:e}){let r=Co(e,e=>Array.isArray(e.todos)&&e.todos.length>0);return r?(0,z.jsx)("div",{className:"mt-2 space-y-1",children:r.todos.map((e,r)=>(0,z.jsxs)("div",{className:"flex items-start gap-2 py-0.5",children:[(0,z.jsx)(Cn,{status:e.status,className:"mt-0.5 flex-shrink-0"}),(0,z.jsxs)("div",{className:"min-w-0",children:[(0,z.jsx)("span",{className:(0,ey.cn)("text-sm break-words","completed"===e.status&&"line-through text-muted-foreground"),children:e.subject??e.content??"Untitled task"}),"in_progress"===e.status&&e.activeForm&&(0,z.jsx)("span",{className:"block text-xs italic text-cyan-500",children:e.activeForm})]})]},e.id??r))}):(0,z.jsx)(Ca,{input:e})}function Cc({input:e}){let r=Co(e,e=>"string"==typeof e.subject);return r?(0,z.jsxs)("div",{className:"mt-2 flex items-start gap-2",children:[(0,z.jsx)(Cs,{className:"h-4 w-4 text-cyan-500 mt-0.5 flex-shrink-0"}),(0,z.jsxs)("div",{className:"min-w-0",children:[(0,z.jsx)("span",{className:"text-sm font-medium break-words",children:r.subject}),r.description&&(0,z.jsx)("span",{className:"block text-xs text-muted-foreground mt-0.5 break-words",children:r.description.length>200?r.description.substring(0,200)+"...":r.description})]})]}):(0,z.jsx)(Ca,{input:e})}function Cd({input:e}){let r=Co(e,e=>"string"==typeof e.taskId);return r?(0,z.jsxs)("div",{className:"mt-2 flex items-start gap-2 flex-wrap",children:[r.status?(0,z.jsx)(Cn,{status:r.status,className:"mt-0.5 flex-shrink-0"}):(0,z.jsx)(_d,{className:"h-4 w-4 text-cyan-500 mt-0.5 flex-shrink-0"}),(0,z.jsxs)("span",{className:"text-sm break-words",children:["Task #",r.taskId,r.status&&(0,z.jsxs)(z.Fragment,{children:[" ",(0,z.jsx)(_d,{className:"inline h-3 w-3 text-muted-foreground mx-0.5"})," ",r.status]}),r.subject&&(0,z.jsxs)("span",{className:"text-muted-foreground",children:[" — ",r.subject]})]}),r.addBlockedBy&&r.addBlockedBy.length>0&&(0,z.jsx)("div",{className:"flex gap-1 mt-1 w-full pl-6",children:r.addBlockedBy.map(e=>(0,z.jsxs)(sy,{variant:"outline",className:"text-[10px]",children:[(0,z.jsx)(Ci,{className:"h-2.5 w-2.5 mr-0.5"}),"blocked by #",e]},e))}),r.addBlocks&&r.addBlocks.length>0&&(0,z.jsx)("div",{className:"flex gap-1 mt-1 w-full pl-6",children:r.addBlocks.map(e=>(0,z.jsxs)(sy,{variant:"outline",className:"text-[10px]",children:[(0,z.jsx)(Ci,{className:"h-2.5 w-2.5 mr-0.5"}),"blocks #",e]},e))})]}):(0,z.jsx)(Ca,{input:e})}function Cu(){return(0,z.jsxs)("div",{className:"mt-2 flex items-center gap-2 text-sm text-muted-foreground",children:[(0,z.jsx)(rj,{className:"h-4 w-4 animate-spin text-cyan-500"}),(0,z.jsx)("span",{children:"Listing tasks..."})]})}function Ch({input:e}){let r=Co(e,e=>"string"==typeof e.taskId);return r?(0,z.jsxs)("div",{className:"mt-2 flex items-center gap-2 text-sm text-muted-foreground",children:[(0,z.jsx)(rj,{className:"h-4 w-4 animate-spin text-cyan-500"}),(0,z.jsxs)("span",{children:["Fetching task #",r.taskId,"..."]})]}):(0,z.jsx)(Ca,{input:e})}function Cf({output:e}){let r=function(e){try{let r=JSON.parse(e);if(Array.isArray(r))return r.filter(e=>e.id&&e.subject).map(e=>({id:String(e.id),subject:String(e.subject),status:e.status||"pending",owner:e.owner?String(e.owner):void 0,blockedBy:Array.isArray(e.blockedBy)?e.blockedBy.map(String):void 0}));let s=r.tasks??r.items??r.data;if(Array.isArray(s))return s.filter(e=>e.id&&e.subject).map(e=>({id:String(e.id),subject:String(e.subject),status:e.status||"pending",owner:e.owner?String(e.owner):void 0,blockedBy:Array.isArray(e.blockedBy)?e.blockedBy.map(String):void 0}))}catch{let r=e.trim().split("\n").filter(Boolean),s=[];for(let e of r){let r=e.match(/^#?(\d+)[\s.:\-]+\[?(completed|in_progress|pending|deleted)\]?\s+(.+)/i);r&&s.push({id:r[1],status:r[2].toLowerCase(),subject:r[3].trim()})}if(s.length>0)return s}return null}(e);return r?(0,z.jsx)("div",{className:"mt-1 space-y-1",children:r.map(e=>(0,z.jsxs)("div",{className:"flex items-start gap-2 py-0.5",children:[(0,z.jsx)(Cn,{status:e.status,className:"mt-0.5 flex-shrink-0"}),(0,z.jsxs)("div",{className:"min-w-0 flex items-center gap-1.5 flex-wrap",children:[(0,z.jsxs)("span",{className:"text-xs text-muted-foreground",children:["#",e.id]}),(0,z.jsx)("span",{className:(0,ey.cn)("text-sm break-words","completed"===e.status&&"line-through text-muted-foreground"),children:e.subject}),e.blockedBy&&e.blockedBy.length>0&&(0,z.jsx)(sy,{variant:"outline",className:"text-[10px]",children:"blocked"})]})]},e.id))}):null}function Cp({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.file_path)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let{file_path:s,offset:i,limit:n}=r,o=s.split("/"),a=o.pop()||s,l=o.join("/"),c=null!=i||null!=n,d="";if(c){let e=i??1;d=null!=n?`Lines ${e}\u2013${e+n-1}`:`From line ${e}`}return(0,z.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,z.jsxs)("div",{className:"min-w-0",children:[(0,z.jsx)("span",{className:"text-sm font-medium break-all",children:a}),l&&(0,z.jsx)("p",{className:"text-xs text-muted-foreground truncate",title:s,children:l})]}),c&&(0,z.jsx)(sy,{variant:"outline",className:"text-xs shrink-0",children:d})]})}function Cm({output:e}){let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["File contents (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function Cg({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.file_path)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let{file_path:s,content:i}=r,n=s.split("/"),o=n.pop()||s,a=n.join("/"),l=i.split("\n").length;return(0,z.jsxs)("div",{className:"space-y-1",children:[(0,z.jsxs)("div",{className:"min-w-0",children:[(0,z.jsx)("span",{className:"text-sm font-medium break-all",children:o}),a&&(0,z.jsx)("p",{className:"text-xs text-muted-foreground truncate",title:s,children:a})]}),(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Content (",l," ",1===l?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:i.length>1e3?i.substring(0,1e3)+"...":i})]})]})}function Cx({output:e}){return e&&""!==e.trim()?(0,z.jsxs)("details",{children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"Result"}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]}):(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"File written"})}function Cv({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.command)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let{command:s,description:i,timeout:n}=r;return(0,z.jsxs)("div",{className:"space-y-1",children:[i&&(0,z.jsx)("p",{className:"text-xs text-muted-foreground",children:i}),(0,z.jsxs)("div",{className:"flex items-start gap-2",children:[(0,z.jsxs)("pre",{className:"flex-1 min-w-0 bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:[(0,z.jsx)("span",{className:"text-muted-foreground select-none",children:"$ "}),s]}),null!=n&&(0,z.jsx)(sy,{variant:"outline",className:"text-xs shrink-0 mt-1",children:function(e){if(e>=6e4){let r=e/6e4;return`${r%1==0?r:r.toFixed(1)}m`}return`${e/1e3}s`}(n)})]})]})}function C_({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No output"});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Output (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function Cy({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.pattern)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let s=[];return r.path&&s.push({label:r.path}),r.glob&&s.push({label:r.glob}),r.type&&s.push({label:`.${r.type}`}),r.output_mode&&"files_with_matches"!==r.output_mode&&s.push({label:r.output_mode}),null!=r.context&&s.push({label:`context: ${r.context}`}),null!=r["-C"]&&s.push({label:`context: ${r["-C"]}`}),null!=r["-B"]&&s.push({label:`before: ${r["-B"]}`}),null!=r["-A"]&&s.push({label:`after: ${r["-A"]}`}),r["-i"]&&s.push({label:"case-insensitive"}),r.multiline&&s.push({label:"multiline"}),null!=r.head_limit&&s.push({label:`limit: ${r.head_limit}`}),null!=r.offset&&s.push({label:`offset: ${r.offset}`}),(0,z.jsxs)("div",{className:"space-y-1",children:[(0,z.jsx)("div",{className:"flex items-start gap-2",children:(0,z.jsxs)("pre",{className:"flex-1 min-w-0 bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:[(0,z.jsx)("span",{className:"text-muted-foreground select-none",children:"/ "}),r.pattern]})}),s.length>0&&(0,z.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap",children:s.map((e,r)=>(0,z.jsx)(sy,{variant:"outline",className:"text-xs",children:e.label},r))})]})}function Cb({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No matches"});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Results (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function Cw({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.pattern)return r;return null}catch{return null}}(e);return r?(0,z.jsxs)("div",{className:"space-y-1",children:[(0,z.jsx)("div",{className:"flex items-start gap-2",children:(0,z.jsx)("pre",{className:"flex-1 min-w-0 bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:r.pattern})}),r.path&&(0,z.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap",children:(0,z.jsx)(sy,{variant:"outline",className:"text-xs",children:r.path})})]}):(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)})}function CS({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No matches"});let r=e.trim().split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:[r," ",1===r?"file":"files"," found"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}let CC={Explore:"Explore",Bash:"Bash",Plan:"Plan","general-purpose":"General","code-simplifier":"Simplify","superpowers:code-reviewer":"Review","memory-leak-detector":"Memory","directory-structure-validator":"Structure","tech-docs-finder":"Docs","claude-code-guide":"Guide","statusline-setup":"Status"};function Cj({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.description&&"string"==typeof r.subagent_type)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let{description:s,subagent_type:i,prompt:n,model:o,max_turns:a,resume:l,run_in_background:c}=r,d=[];return d.push({label:CC[i]||i}),o&&d.push({label:o}),null!=a&&d.push({label:`${a} turns`}),c&&d.push({label:"background"}),l&&d.push({label:"resume"}),(0,z.jsxs)("div",{className:"space-y-1",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,z.jsx)("span",{className:"text-sm",children:s}),d.map((e,r)=>(0,z.jsx)(sy,{variant:"outline",className:"text-xs shrink-0",children:e.label},r))]}),n&&(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Prompt (",n.length>1e3?`${Math.round(n.length/1e3)}k chars`:`${n.length} chars`,")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:n.length>1e3?n.substring(0,1e3)+"...":n})]})]})}function Ck({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No output"});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Agent result (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function CN(e,r){return e.length>r?e.substring(0,r)+"...":e}function CD({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.file_path&&"string"==typeof r.old_string&&"string"==typeof r.new_string)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let{file_path:s,old_string:i,new_string:n,replace_all:o}=r,a=s.split("/"),l=a.pop()||s,c=a.join("/"),d=i.split("\n").length,u=n.split("\n").length;return(0,z.jsxs)("div",{className:"space-y-1",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,z.jsxs)("div",{className:"min-w-0",children:[(0,z.jsx)("span",{className:"text-sm font-medium break-all",children:l}),c&&(0,z.jsx)("p",{className:"text-xs text-muted-foreground truncate",title:s,children:c})]}),(0,z.jsx)(sy,{variant:"outline",className:"text-xs shrink-0",children:d===u?`${d} ${1===d?"line":"lines"}`:`${d}\u2192${u} lines`}),o&&(0,z.jsx)(sy,{variant:"outline",className:"text-xs shrink-0",children:"replace all"})]}),(0,z.jsxs)("details",{children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"Diff"}),(0,z.jsxs)("div",{className:"mt-1 text-xs rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full",children:[(0,z.jsxs)("pre",{className:"bg-red-500/10 p-1.5 rounded-t whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:[(0,z.jsx)("span",{className:"text-red-500 select-none",children:"- "}),CN(i,500)]}),(0,z.jsxs)("pre",{className:"bg-green-500/10 p-1.5 rounded-b whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:[(0,z.jsx)("span",{className:"text-green-500 select-none",children:"+ "}),CN(n,500)]})]})]})]})}function CE({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No output"});if(e.length<=200)return(0,z.jsx)("p",{className:"text-xs text-muted-foreground",children:e});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Result (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function CR({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.url&&"string"==typeof r.prompt)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let{display:s,href:i}=function(e){try{let r=new URL(e),s="/"===r.pathname?"":r.pathname,i=r.hostname+s;return{display:i.length>80?i.substring(0,77)+"...":i,href:e}}catch{return{display:e.length>80?e.substring(0,77)+"...":e,href:e}}}(r.url),n=r.prompt.length>150?r.prompt.substring(0,147)+"...":r.prompt;return(0,z.jsxs)("div",{className:"space-y-1",children:[(0,z.jsx)("a",{href:i,target:"_blank",rel:"noopener noreferrer",className:"block text-xs font-mono text-blue-500 hover:underline truncate",children:s}),(0,z.jsxs)("p",{className:"text-xs text-muted-foreground",children:['"',n,'"']})]})}function CA({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No content fetched"});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Response (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function CM({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.query)return r;return null}catch{return null}}(e);return r?(0,z.jsxs)("div",{className:"space-y-1.5",children:[(0,z.jsx)("p",{className:"text-xs font-mono bg-muted/50 px-2 py-1 rounded break-words",children:r.query}),r.allowed_domains&&r.allowed_domains.length>0&&(0,z.jsxs)("div",{className:"flex items-center gap-1 flex-wrap",children:[(0,z.jsx)("span",{className:"text-xs text-muted-foreground",children:"only:"}),r.allowed_domains.map(e=>(0,z.jsx)(sy,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:e},e))]}),r.blocked_domains&&r.blocked_domains.length>0&&(0,z.jsxs)("div",{className:"flex items-center gap-1 flex-wrap",children:[(0,z.jsx)("span",{className:"text-xs text-muted-foreground",children:"exclude:"}),r.blocked_domains.map(e=>(0,z.jsx)(sy,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:e},e))]})]}):(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)})}function CF({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No search results"});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Results (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function CT({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.skill)return r;return null}catch{return null}}(e);return r?(0,z.jsxs)("div",{className:"space-y-1",children:[(0,z.jsx)("p",{className:"text-xs font-mono text-pink-500",children:r.skill}),r.args&&(0,z.jsxs)("p",{className:"text-xs text-muted-foreground truncate",children:["args: ",r.args]})]}):(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)})}function CP({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No output"});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Loaded (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function CB({input:e}){let r=function(e){try{let r="string"==typeof e?JSON.parse(e):e;if(r&&"object"==typeof r&&"string"==typeof r.task_id)return r;return null}catch{return null}}(e);if(!r)return(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:"string"==typeof e?e:JSON.stringify(e,null,2)});let{task_id:s,block:i,timeout:n}=r,o=[];return o.push({label:!1===i?"non-blocking":"blocking"}),null!=n&&o.push({label:`${Math.round(n/1e3)}s`}),(0,z.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,z.jsx)("code",{className:"text-sm bg-muted/50 px-1.5 py-0.5 rounded",children:s}),o.map((e,r)=>(0,z.jsx)(sy,{variant:"outline",className:"text-xs shrink-0",children:e.label},r))]})}function CL({output:e}){if(!e||""===e.trim())return(0,z.jsx)("p",{className:"text-xs text-muted-foreground italic",children:"No output"});let r=e.split("\n").length;return(0,z.jsxs)("details",{children:[(0,z.jsxs)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:["Task output (",r," ",1===r?"line":"lines",")"]}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.length>1e3?e.substring(0,1e3)+"...":e})]})}function CI({input:e}){let r="string"==typeof e?function(e){try{return JSON.parse(e)}catch{return null}}(e):e,s=r?.changes??[];return 0===s.length?(0,z.jsx)("p",{className:"text-xs text-muted-foreground",children:"No file changes"}):(0,z.jsx)("div",{className:"space-y-2 mt-1",children:s.map((e,r)=>(0,z.jsxs)("div",{children:[(0,z.jsxs)("div",{className:"flex items-center gap-2",children:[(0,z.jsx)(bt,{className:"h-3 w-3 text-muted-foreground flex-shrink-0"}),(0,z.jsx)("code",{className:"text-xs break-all",children:e.path}),(0,z.jsx)(sy,{variant:"secondary",className:`text-[10px] ${function(e){switch(e){case"added":case"add":return"bg-green-500/10 text-green-600";case"deleted":case"delete":return"bg-red-500/10 text-red-600";default:return"bg-blue-500/10 text-blue-600"}}(e.kind)}`,children:function(e){switch(e){case"added":case"add":return"added";case"deleted":case"delete":return"deleted";default:return"modified"}}(e.kind)})]}),e.diff&&(0,z.jsxs)("details",{className:"mt-1",children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"View diff"}),(0,z.jsx)("pre",{className:"mt-1 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.diff.split("\n").map((e,r)=>{let s="";return e.startsWith("+")?s="bg-green-500/10 text-green-700 dark:text-green-400":e.startsWith("-")&&(s="bg-red-500/10 text-red-700 dark:text-red-400"),(0,z.jsx)("div",{className:s,children:e},r)})})]})]},r))})}function CO({output:e}){let r=e.toLowerCase(),s="text-muted-foreground";return r.includes("completed")||r.includes("success")?s="text-green-600 dark:text-green-400":r.includes("failed")||r.includes("error")?s="text-red-600 dark:text-red-400":(r.includes("declined")||r.includes("denied"))&&(s="text-amber-600 dark:text-amber-400"),(0,z.jsx)("p",{className:`text-xs ${s}`,children:e})}function Cz({path:e,size:r}){let s;return(0,z.jsxs)("span",{className:"inline-flex items-center gap-1.5 rounded-md border border-border bg-muted/60 px-1.5 py-0.5 text-xs font-mono align-baseline",title:e,children:[(0,z.jsx)(bt,{className:"w-3 h-3 text-muted-foreground shrink-0"}),(0,z.jsx)("span",{className:"truncate max-w-[18ch]",children:(s=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\")))>=0?e.slice(s+1):e}),(0,z.jsx)("span",{className:"text-muted-foreground",children:function(e){if(e<1024)return`${e} B`;let r=e/1024;return r<10?`${r.toFixed(1)} KB`:r<1024?`${Math.round(r)} KB`:`${(r/1024).toFixed(1)} MB`}(r)})]})}let C$=/<vpaste path="([^"]+)" size="(\d+)" \/>/g;function CW({message:e,messageIndex:r}){let s=function(e,r){switch(e.type){case"user":return(0,z.jsx)(CU,{content:e.content});case"assistant":return(0,z.jsx)(CK,{content:e.content,agentType:e.agentType});case"tool_use":return(0,z.jsx)(Cq,{tool:e.tool,input:e.input,messageIndex:r});case"tool_result":return(0,z.jsx)(CV,{tool:e.tool,output:e.output});case"thinking":return(0,z.jsx)(CY,{content:e.content});case"error":return(0,z.jsx)(CG,{message:e.message});case"system":return(0,z.jsx)(CX,{content:e.content});case"approval_request":return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-amber-500/10 flex items-center justify-center",children:(0,z.jsx)(SX,{className:"w-4 h-4 text-amber-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-amber-500 mb-1",children:"command"===e.requestType?"Command Approval":"File Change Approval"}),"command"===e.requestType?(0,z.jsx)(Ct,{requestId:e.requestId,command:e.command,cwd:e.cwd,messageIndex:r}):(0,z.jsx)(Cr,{requestId:e.requestId,changes:e.changes,messageIndex:r})]})]});default:return null}}(e,r);return s?(0,z.jsxs)("div",{className:"group relative",children:[s,(0,z.jsx)("span",{className:"pointer-events-none absolute right-0 top-3 text-xs tabular-nums text-muted-foreground opacity-0 transition-opacity duration-150 group-hover:opacity-100",children:function(e){let r=new Date(e),s=new Date,i=r.getFullYear()===s.getFullYear()&&r.getMonth()===s.getMonth()&&r.getDate()===s.getDate(),n=r.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1});if(i)return n;let o=r.toLocaleDateString(void 0,{year:"numeric",month:"2-digit",day:"2-digit"});return`${o} ${n}`}(e.timestamp)})]}):null}function CH(e){let r=function(e){let r,s=[],i=0,n=RegExp(C$.source,"g");for(;null!==(r=n.exec(e));)r.index>i&&s.push({kind:"text",text:e.slice(i,r.index)}),s.push({kind:"chip",path:r[1],size:Number(r[2])}),i=r.index+r[0].length;return i<e.length&&s.push({kind:"text",text:e.slice(i)}),s}(e);return 1===r.length&&"text"===r[0].kind?(0,z.jsx)("span",{className:"whitespace-pre-wrap break-words",children:e??""}):(0,z.jsx)("div",{className:"text-foreground max-w-none break-words",style:{fontSize:"var(--conv-font-size, 14px)"},children:r.map((e,r)=>"text"===e.kind?(0,z.jsx)("span",{className:"whitespace-pre-wrap break-words",children:e.text},r):(0,z.jsx)(Cz,{path:e.path,size:e.size},r))})}function CU({content:e}){return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-primary/10 flex items-center justify-center",children:(0,z.jsx)(SO,{className:"w-3.5 h-3.5 text-primary"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-foreground mb-1",children:"You"}),(0,z.jsx)("div",{className:"text-foreground max-w-none break-words",style:{fontSize:"var(--conv-font-size, 14px)"},children:"string"==typeof e?CH(e):e.map((e,r)=>"text"===e.type?(0,z.jsx)($.Fragment,{children:CH(e.text)},r):(0,z.jsx)("img",{src:`data:${e.mediaType};base64,${e.data}`,alt:"Attached image",className:"max-w-sm rounded-lg mt-2"},r))})]})]})}function CK({content:e,agentType:r}){let s=function(){try{return ke().agentType}catch{return"claude-code"}}(),i="codex"===(r??s),[n,o]=(0,$.useState)(!1);return(0,z.jsxs)("div",{className:"group flex gap-3 py-3",children:[(0,z.jsx)("div",{className:`flex-shrink-0 w-7 h-7 rounded-lg ${i?"bg-green-500/10":"bg-violet-500/10"} flex items-center justify-center`,children:(0,z.jsx)(oN,{className:`w-3.5 h-3.5 ${i?"text-green-500":"text-violet-500"}`})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,z.jsx)("p",{className:`text-sm font-medium ${i?"text-green-500":"text-violet-500"}`,children:i?"Codex":"Claude"}),(0,z.jsx)("button",{type:"button",onClick:()=>o(e=>!e),title:n?"View rendered":"View source","aria-label":n?"View rendered":"View source","aria-pressed":n,className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity text-muted-foreground hover:text-foreground",children:n?(0,z.jsx)(_i,{className:"w-3.5 h-3.5"}):(0,z.jsx)(bW,{className:"w-3.5 h-3.5"})})]}),n?(0,z.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words bg-muted/50 rounded-md p-3 overflow-x-auto text-foreground select-text",children:e??""}):(0,z.jsx)("div",{className:"text-foreground prose prose-sm dark:prose-invert max-w-none break-words [&_pre]:overflow-x-auto [&_pre]:max-w-full [&_code]:break-all [&_p]:break-words",style:{fontSize:"var(--conv-font-size, 14px)"},children:(0,z.jsx)(S4,{children:e??""})})]})]})}function Cq({tool:e,input:r,messageIndex:s}){if("AskUserQuestion"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-violet-500/10 flex items-center justify-center",children:(0,z.jsx)(SH,{className:"w-4 h-4 text-violet-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-violet-500 mb-1",children:"Question"}),(0,z.jsx)(S6,{input:r,messageIndex:s})]})]});if("ExitPlanMode"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-green-500/10 flex items-center justify-center",children:(0,z.jsx)(SU,{className:"w-4 h-4 text-green-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-green-500 mb-1",children:"Plan Ready"}),(0,z.jsx)(Ce,{input:r,messageIndex:s})]})]});let i={TodoWrite:{label:"Tasks",ui:(0,z.jsx)(Cl,{input:r})},TaskCreate:{label:"Create Task",ui:(0,z.jsx)(Cc,{input:r})},TaskUpdate:{label:"Update Task",ui:(0,z.jsx)(Cd,{input:r})},TaskList:{label:"Task List",ui:(0,z.jsx)(Cu,{})},TaskGet:{label:"Get Task",ui:(0,z.jsx)(Ch,{input:r})}}[e];if(i)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-cyan-500/10 flex items-center justify-center",children:(0,z.jsx)(aM,{className:"w-4 h-4 text-cyan-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-cyan-500 mb-1",children:i.label}),i.ui]})]});if("Read"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-sky-500/10 flex items-center justify-center",children:(0,z.jsx)(bt,{className:"w-4 h-4 text-sky-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-sky-500 mb-1",children:"Read File"}),(0,z.jsx)(Cp,{input:r})]})]});if("Edit"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-sky-500/10 flex items-center justify-center",children:(0,z.jsx)(SV,{className:"w-4 h-4 text-sky-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-sky-500 mb-1",children:"Edit File"}),(0,z.jsx)(CD,{input:r})]})]});if("Write"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-sky-500/10 flex items-center justify-center",children:(0,z.jsx)(SY,{className:"w-4 h-4 text-sky-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-sky-500 mb-1",children:"Write File"}),(0,z.jsx)(Cg,{input:r})]})]});if("Bash"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-emerald-500/10 flex items-center justify-center",children:(0,z.jsx)(ok,{className:"w-4 h-4 text-emerald-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-emerald-500 mb-1",children:"Run Command"}),(0,z.jsx)(Cv,{input:r})]})]});if("Grep"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-orange-500/10 flex items-center justify-center",children:(0,z.jsx)(_o,{className:"w-4 h-4 text-orange-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-orange-500 mb-1",children:"Search"}),(0,z.jsx)(Cy,{input:r})]})]});if("Glob"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-teal-500/10 flex items-center justify-center",children:(0,z.jsx)(SK,{className:"w-4 h-4 text-teal-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-teal-500 mb-1",children:"Glob"}),(0,z.jsx)(Cw,{input:r})]})]});if("Task"===e||"Agent"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-purple-500/10 flex items-center justify-center",children:(0,z.jsx)(Sq,{className:"w-4 h-4 text-purple-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-purple-500 mb-1",children:"Agent"}),(0,z.jsx)(Cj,{input:r})]})]});if("TaskOutput"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-purple-500/10 flex items-center justify-center",children:(0,z.jsx)(Sq,{className:"w-4 h-4 text-purple-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-purple-500 mb-1",children:"Task Output"}),(0,z.jsx)(CB,{input:r})]})]});if("WebFetch"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-blue-500/10 flex items-center justify-center",children:(0,z.jsx)(r_,{className:"w-4 h-4 text-blue-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-blue-500 mb-1",children:"Fetch Web Page"}),(0,z.jsx)(CR,{input:r})]})]});if("WebSearch"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-indigo-500/10 flex items-center justify-center",children:(0,z.jsx)(SG,{className:"w-4 h-4 text-indigo-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-indigo-500 mb-1",children:"Web Search"}),(0,z.jsx)(CM,{input:r})]})]});if("Skill"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-pink-500/10 flex items-center justify-center",children:(0,z.jsx)(cP,{className:"w-4 h-4 text-pink-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-pink-500 mb-1",children:"Skill"}),(0,z.jsx)(CT,{input:r})]})]});if("FileChange"===e)return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-sky-500/10 flex items-center justify-center",children:(0,z.jsx)(SV,{className:"w-4 h-4 text-sky-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-sky-500 mb-1",children:"File Changes"}),(0,z.jsx)(CI,{input:r})]})]});let n="string"==typeof r?r:JSON.stringify(r,null,2);return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-amber-500/10 flex items-center justify-center",children:(0,z.jsx)(Sz,{className:"w-4 h-4 text-amber-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsxs)("p",{className:"text-sm font-medium text-amber-500 mb-1 break-words",children:["Tool: ",e]}),(0,z.jsxs)("details",{open:!0,children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"Input"}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:n.length>500?n.substring(0,500)+"...":n})]})]})]})}function CV({tool:e,output:r}){if(["TodoWrite","TaskCreate","TaskUpdate","TaskList","TaskGet"].includes(e)){let s="TaskList"===e?(0,z.jsx)(Cf,{output:r}):null;return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsxs)("p",{className:"text-xs text-muted-foreground mb-1",children:["Result (",e,")"]}),s||(0,z.jsxs)("details",{children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"Output"}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:r.length>1e3?r.substring(0,1e3)+"...":r})]})]})})}if("Read"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(Cm,{output:r})})});if("Edit"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(CE,{output:r})})});if("Write"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(Cx,{output:r})})});if("Bash"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(C_,{output:r})})});if("Grep"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(Cb,{output:r})})});if("Glob"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(CS,{output:r})})});if("Task"===e||"Agent"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(Ck,{output:r})})});if("TaskOutput"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(CL,{output:r})})});if("WebFetch"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(CA,{output:r})})});if("WebSearch"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(CF,{output:r})})});if("Skill"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(CP,{output:r})})});if("FileChange"===e)return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)(CO,{output:r})})});let s=r.length>200;return(0,z.jsx)("div",{className:"flex gap-3 py-3 pl-11",children:(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsxs)("p",{className:"text-xs text-muted-foreground mb-1",children:["Result",e?` (${e})`:""]}),(0,z.jsxs)("details",{className:(0,ey.cn)(!s&&"open"),children:[(0,z.jsx)("summary",{className:"text-xs text-muted-foreground cursor-pointer hover:text-foreground",children:"Output"}),(0,z.jsx)("pre",{className:"mt-1 bg-muted/50 p-2 rounded overflow-x-auto max-h-48 overflow-y-auto max-w-full whitespace-pre-wrap break-all",style:{fontSize:"var(--conv-font-size, 12px)"},children:r.length>1e3?r.substring(0,1e3)+"...":r})]})]})})}function CY({content:e}){let r=e??"",s=r.trim().length>0,i=s?r.length>500?r.substring(0,500)+"...":r:"Reasoning unavailable — this model does not expose its thinking content.";return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-blue-500/10 flex items-center justify-center",children:(0,z.jsx)(S$,{className:"w-3.5 h-3.5 text-blue-500"})}),(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsxs)("details",{children:[(0,z.jsx)("summary",{className:"text-xs font-medium text-blue-500 cursor-pointer hover:underline",children:"Thinking..."}),(0,z.jsx)("div",{className:`mt-2 whitespace-pre-wrap break-words bg-blue-500/5 p-2 rounded-md overflow-hidden ${s?"text-muted-foreground":"text-muted-foreground/70 italic"}`,style:{fontSize:"var(--conv-font-size, 12px)"},children:i})]})})]})}function CG({message:e}){return(0,z.jsxs)("div",{className:"flex gap-3 py-3",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-red-500/10 flex items-center justify-center",children:(0,z.jsx)(SW,{className:"w-3.5 h-3.5 text-red-500"})}),(0,z.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-red-500 mb-1",children:"Error"}),(0,z.jsx)("p",{className:"text-red-500/80 break-words whitespace-pre-wrap",style:{fontSize:"var(--conv-font-size, 14px)"},children:e})]})]})}function CX({content:e}){return(0,z.jsxs)("div",{className:"flex gap-3 py-2",children:[(0,z.jsx)("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-gray-500/10 flex items-center justify-center",children:(0,z.jsx)(gU,{className:"w-3.5 h-3.5 text-gray-500"})}),(0,z.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,z.jsx)("p",{className:"text-muted-foreground break-words",style:{fontSize:"var(--conv-font-size, 12px)"},children:e??""})})]})}let CJ=(0,ew.default)("arrow-down",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]),CZ={damping:.7,stiffness:.05,mass:1.25},CQ=1e3/60,C0=!1;function C1(e,r){let s=(0,$.useCallback)(r=>(s.current=r,e(r)),r);return s}globalThis.document?.addEventListener("mousedown",()=>{C0=!0}),globalThis.document?.addEventListener("mouseup",()=>{C0=!1}),globalThis.document?.addEventListener("click",()=>{C0=!1});let C2=new Map;function C5(...e){let r={...CZ},s=!1;for(let i of e){if("instant"===i){s=!0;continue}"object"==typeof i&&(s=!1,r.damping=i.damping??r.damping,r.stiffness=i.stiffness??r.stiffness,r.mass=i.mass??r.mass)}let i=JSON.stringify(r);return C2.has(i)||C2.set(i,Object.freeze(r)),s?"instant":C2.get(i)}let C3=(0,$.createContext)(null),C4="undefined"!=typeof window?$.useLayoutEffect:$.useEffect;function C6({instance:e,children:r,resize:s,initial:i,mass:n,damping:o,stiffness:a,targetScrollTop:l,contextRef:c,...d}){let u=(0,$.useRef)(null),h=((e={})=>{let[r,s]=(0,$.useState)(!1),[i,n]=(0,$.useState)(!1!==e.initial),[o,a]=(0,$.useState)(!1),l=(0,$.useRef)(null);l.current=e;let c=(0,$.useCallback)(()=>{if(!C0)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let r=e.getRangeAt(0);return r.commonAncestorContainer.contains(x.current)||x.current?.contains(r.commonAncestorContainer)},[]),d=(0,$.useCallback)(e=>{h.isAtBottom=e,n(e)},[]),u=(0,$.useCallback)(e=>{h.escapedFromLock=e,s(e)},[]),h=(0,$.useMemo)(()=>{let s;return{escapedFromLock:r,isAtBottom:i,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return x.current?.scrollTop??0},set scrollTop(scrollTop){x.current&&(x.current.scrollTop=scrollTop,h.ignoreScrollToTop=x.current.scrollTop)},get targetScrollTop(){if(!x.current||!v.current)return 0;return x.current.scrollHeight-1-x.current.clientHeight},get calculatedTargetScrollTop(){if(!x.current||!v.current)return 0;let{targetScrollTop:r}=this;if(!e.targetScrollTop)return r;if(s?.targetScrollTop===r)return s.calculatedScrollTop;let i=Math.max(Math.min(e.targetScrollTop(r,{scrollElement:x.current,contentElement:v.current}),r),0);return s={targetScrollTop:r,calculatedScrollTop:i},requestAnimationFrame(()=>{s=void 0}),i},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=70}}},[]),f=(0,$.useCallback)((e={})=>{let r;"string"==typeof e&&(e={animation:e}),e.preserveScrollPosition||d(!0);let s=Date.now()+(Number(e.wait)||0),i=C5(l.current,e.animation),{ignoreEscapes:n=!1}=e,o=h.calculatedTargetScrollTop;e.duration instanceof Promise?e.duration.finally(()=>{r=Date.now()}):r=s+(e.duration??0);let a=async()=>{let e=new Promise(requestAnimationFrame).then(()=>{if(!h.isAtBottom)return h.animation=void 0,!1;let{scrollTop:d}=h,u=performance.now(),p=(u-(h.lastTick??u))/CQ;if(h.animation||(h.animation={behavior:i,promise:e,ignoreEscapes:n}),h.animation.behavior===i&&(h.lastTick=u),c()||s>Date.now())return a();if(d<Math.min(o,h.calculatedTargetScrollTop)){if(h.animation?.behavior===i){if("instant"===i)return h.scrollTop=h.calculatedTargetScrollTop,a();h.velocity=(i.damping*h.velocity+i.stiffness*h.scrollDifference)/i.mass,h.accumulated+=h.velocity*p,h.scrollTop+=h.accumulated,h.scrollTop!==d&&(h.accumulated=0)}return a()}return r>Date.now()?(o=h.calculatedTargetScrollTop,a()):(h.animation=void 0,h.scrollTop<h.calculatedTargetScrollTop)?f({animation:C5(l.current,l.current.resize),ignoreEscapes:n,duration:Math.max(0,r-Date.now())||void 0}):h.isAtBottom});return e.then(e=>(requestAnimationFrame(()=>{h.animation||(h.lastTick=void 0,h.velocity=0)}),e))};return(!0!==e.wait&&(h.animation=void 0),h.animation?.behavior===i)?h.animation.promise:a()},[d,c,h]),p=(0,$.useCallback)(()=>{u(!0),d(!1)},[u,d]),m=(0,$.useCallback)(({target:e})=>{if(e!==x.current)return;let{scrollTop:r,ignoreScrollToTop:s}=h,{lastScrollTop:i=r}=h;h.lastScrollTop=r,h.ignoreScrollToTop=void 0,s&&s>r&&(i=s),a(h.isNearBottom),setTimeout(()=>{if(h.resizeDifference||r===s)return;if(c()){u(!0),d(!1);return}let e=r>i,n=r<i;if(h.animation?.ignoreEscapes){h.scrollTop=i;return}n&&(u(!0),d(!1)),e&&u(!1),!h.escapedFromLock&&h.isNearBottom&&d(!0)},1)},[u,d,c,h]),g=(0,$.useCallback)(({target:e,deltaY:r})=>{let s=e;for(;!["scroll","auto"].includes(getComputedStyle(s).overflow);){if(!s.parentElement)return;s=s.parentElement}s===x.current&&r<0&&x.current.scrollHeight>x.current.clientHeight&&!h.animation?.ignoreEscapes&&(u(!0),d(!1))},[u,d,h]),x=C1(e=>{x.current?.removeEventListener("scroll",m),x.current?.removeEventListener("wheel",g),e?.addEventListener("scroll",m,{passive:!0}),e?.addEventListener("wheel",g,{passive:!0})},[]),v=C1(e=>{let r;h.resizeObserver?.disconnect(),e&&(h.resizeObserver=new ResizeObserver(([e])=>{let{height:s}=e.contentRect,i=s-(r??s);if(h.resizeDifference=i,h.scrollTop>h.targetScrollTop&&(h.scrollTop=h.targetScrollTop),a(h.isNearBottom),i>=0){let e=C5(l.current,r?l.current.resize:l.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:"instant"===e?void 0:350})}else h.isNearBottom&&(u(!1),d(!0));r=s,requestAnimationFrame(()=>{setTimeout(()=>{h.resizeDifference===i&&(h.resizeDifference=0)},1)})}),h.resizeObserver?.observe(e))},[]);return{contentRef:v,scrollRef:x,scrollToBottom:f,stopScroll:p,isAtBottom:i||o,isNearBottom:o,escapedFromLock:r,state:h}})({mass:n,damping:o,stiffness:a,resize:s,initial:i,targetScrollTop:$.useCallback((e,r)=>{let s=y?.targetScrollTop??l;return s?.(e,r)??e},[l])}),{scrollRef:f,contentRef:p,scrollToBottom:m,stopScroll:g,isAtBottom:x,escapedFromLock:v,state:_}=e??h,y=(0,$.useMemo)(()=>({scrollToBottom:m,stopScroll:g,scrollRef:f,isAtBottom:x,escapedFromLock:v,contentRef:p,state:_,get targetScrollTop(){return u.current},set targetScrollTop(targetScrollTop){u.current=targetScrollTop}}),[m,x,p,f,g,v,_]);return(0,$.useImperativeHandle)(c,()=>y,[y]),C4(()=>{f.current&&"visible"===getComputedStyle(f.current).overflow&&(f.current.style.overflow="auto")},[]),$.createElement(C3.Provider,{value:y},$.createElement("div",{...d},"function"==typeof r?r(y):r))}function C8(){let e=(0,$.useContext)(C3);if(!e)throw Error("use-stick-to-bottom component context must be used within a StickToBottom component");return e}(C6||(C6={})).Content=function({children:e,scrollClassName:r,...s}){let i=C8();return $.createElement("div",{ref:i.scrollRef,style:{height:"100%",width:"100%",scrollbarGutter:"stable both-edges"},className:r},$.createElement("div",{...s,ref:i.contentRef},"function"==typeof e?e(i):e))};let C7=({className:e,...r})=>(0,z.jsx)(C6,{className:(0,ey.cn)("relative flex-1 overflow-y-hidden",e),initial:"smooth",resize:"smooth",role:"log",...r}),C9=({className:e,...r})=>(0,z.jsx)(C6.Content,{className:(0,ey.cn)("flex flex-col gap-8 p-4",e),...r}),je=({className:e,...r})=>{let{isAtBottom:s,scrollToBottom:i}=C8(),n=(0,$.useCallback)(()=>{i()},[i]);return!s&&(0,z.jsx)(W.Button,{className:(0,ey.cn)("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",e),onClick:n,size:"icon",type:"button",variant:"outline",...r,children:(0,z.jsx)(CJ,{className:"size-4"})})};var jt="HoverCard",[jr,js]=K(jt,[iz]),ji=iz(),[jn,jo]=jr(jt),ja=e=>{let{__scopeHoverCard:r,children:s,open:i,defaultOpen:n,onOpenChange:o,openDelay:a=700,closeDelay:l=300}=e,c=ji(r),d=$.useRef(0),u=$.useRef(0),h=$.useRef(!1),f=$.useRef(!1),[p,m]=G({prop:i,defaultProp:n??!1,onChange:o,caller:jt}),g=$.useCallback(()=>{clearTimeout(u.current),d.current=window.setTimeout(()=>m(!0),a)},[a,m]),x=$.useCallback(()=>{clearTimeout(d.current),h.current||f.current||(u.current=window.setTimeout(()=>m(!1),l))},[l,m]),v=$.useCallback(()=>m(!1),[m]);return $.useEffect(()=>()=>{clearTimeout(d.current),clearTimeout(u.current)},[]),(0,z.jsx)(jn,{scope:r,open:p,onOpenChange:m,onOpen:g,onClose:x,onDismiss:v,hasSelectionRef:h,isPointerDownOnContentRef:f,children:(0,z.jsx)(iH,{...c,children:s})})};ja.displayName=jt;var jl="HoverCardTrigger",jc=$.forwardRef((e,r)=>{let{__scopeHoverCard:s,...i}=e,n=jo(jl,s),o=ji(s);return(0,z.jsx)(iK,{asChild:!0,...o,children:(0,z.jsx)(er.a,{"data-state":n.open?"open":"closed",...i,ref:r,onPointerEnter:q(e.onPointerEnter,jx(n.onOpen)),onPointerLeave:q(e.onPointerLeave,jx(n.onClose)),onFocus:q(e.onFocus,n.onOpen),onBlur:q(e.onBlur,n.onClose),onTouchStart:q(e.onTouchStart,e=>e.preventDefault())})})});jc.displayName=jl;var jd="HoverCardPortal",[ju,jh]=jr(jd,{forceMount:void 0}),jf=e=>{let{__scopeHoverCard:r,forceMount:s,children:i,container:n}=e,o=jo(jd,r);return(0,z.jsx)(ju,{scope:r,forceMount:s,children:(0,z.jsx)(Z,{present:s||o.open,children:(0,z.jsx)(eW,{asChild:!0,container:n,children:i})})})};jf.displayName=jd;var jp="HoverCardContent",jm=$.forwardRef((e,r)=>{let s=jh(jp,e.__scopeHoverCard),{forceMount:i=s.forceMount,...n}=e,o=jo(jp,e.__scopeHoverCard);return(0,z.jsx)(Z,{present:i||o.open,children:(0,z.jsx)(jg,{"data-state":o.open?"open":"closed",...n,onPointerEnter:q(e.onPointerEnter,jx(o.onOpen)),onPointerLeave:q(e.onPointerLeave,jx(o.onClose)),ref:r})})});jm.displayName=jp;var jg=$.forwardRef((e,r)=>{let{__scopeHoverCard:s,onEscapeKeyDown:i,onPointerDownOutside:n,onFocusOutside:o,onInteractOutside:a,...l}=e,c=jo(jp,s),d=ji(s),u=$.useRef(null),h=(0,U.useComposedRefs)(r,u),[f,p]=$.useState(!1);return $.useEffect(()=>{if(f){let e=document.body;return O=e.style.userSelect||e.style.webkitUserSelect,e.style.userSelect="none",e.style.webkitUserSelect="none",()=>{e.style.userSelect=O,e.style.webkitUserSelect=O}}},[f]),$.useEffect(()=>{if(u.current){let e=()=>{p(!1),c.isPointerDownOnContentRef.current=!1,setTimeout(()=>{document.getSelection()?.toString()!==""&&(c.hasSelectionRef.current=!0)})};return document.addEventListener("pointerup",e),()=>{document.removeEventListener("pointerup",e),c.hasSelectionRef.current=!1,c.isPointerDownOnContentRef.current=!1}}},[c.isPointerDownOnContentRef,c.hasSelectionRef]),$.useEffect(()=>{u.current&&(function(e){let r=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});for(;s.nextNode();)r.push(s.currentNode);return r})(u.current).forEach(e=>e.setAttribute("tabindex","-1"))}),(0,z.jsx)(eR,{asChild:!0,disableOutsidePointerEvents:!1,onInteractOutside:a,onEscapeKeyDown:i,onPointerDownOutside:n,onFocusOutside:q(o,e=>{e.preventDefault()}),onDismiss:c.onDismiss,children:(0,z.jsx)(iG,{...d,...l,onPointerDown:q(l.onPointerDown,e=>{e.currentTarget.contains(e.target)&&p(!0),c.hasSelectionRef.current=!1,c.isPointerDownOnContentRef.current=!0}),ref:h,style:{...l.style,userSelect:f?"text":void 0,WebkitUserSelect:f?"text":void 0,"--radix-hover-card-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-hover-card-content-available-width":"var(--radix-popper-available-width)","--radix-hover-card-content-available-height":"var(--radix-popper-available-height)","--radix-hover-card-trigger-width":"var(--radix-popper-anchor-width)","--radix-hover-card-trigger-height":"var(--radix-popper-anchor-height)"}})})});function jx(e){return r=>"touch"===r.pointerType?void 0:e()}function jv({...e}){return(0,z.jsx)(ja,{"data-slot":"hover-card",...e})}function j_({...e}){return(0,z.jsx)(jc,{"data-slot":"hover-card-trigger",...e})}function jy({className:e,align:r="center",sideOffset:s=4,...i}){return(0,z.jsx)(jf,{"data-slot":"hover-card-portal",children:(0,z.jsx)(jm,{"data-slot":"hover-card-content",align:r,sideOffset:s,className:(0,ey.cn)("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[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 z-50 w-64 origin-(--radix-hover-card-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",e),...i})})}$.forwardRef((e,r)=>{let{__scopeHoverCard:s,...i}=e,n=ji(s);return(0,z.jsx)(iZ,{...n,...i,ref:r})}).displayName="HoverCardArrow";let jb=(0,ew.default)("corner-down-left",[["path",{d:"M20 4v7a4 4 0 0 1-4 4H4",key:"6o5b7l"}],["path",{d:"m9 10-5 5 5 5",key:"1kshq7"}]]),jw=(0,ew.default)("image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]);(0,ew.default)("mic",[["path",{d:"M12 19v3",key:"npa21l"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["rect",{x:"9",y:"2",width:"6",height:"13",rx:"3",key:"s6n7sd"}]]);let jS=(0,ew.default)("paperclip",[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]]),jC=(e=21)=>{let r="",s=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)r+="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[63&s[e]];return r},jj=(0,$.createContext)(null),jk=(0,$.createContext)(null),jN=()=>(0,$.useContext)(jj),jD=(0,$.createContext)(null),jE=()=>{let e=(0,$.useContext)(jk),r=(0,$.useContext)(jD),s=e??r;if(!s)throw Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return s};function jR({data:e,className:r,...s}){let i=jE(),n=e.filename||"",o="image"==(e.mediaType?.startsWith("image/")&&e.url?"image":"file"),a=n||(o?"Image":"Attachment");return(0,z.jsxs)(jW,{children:[(0,z.jsx)(j_,{asChild:!0,children:(0,z.jsxs)("div",{className:(0,ey.cn)("group relative flex h-8 cursor-pointer select-none items-center gap-1.5 rounded-md border border-border px-1.5 font-medium text-sm transition-all hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",r),...s,children:[(0,z.jsxs)("div",{className:"relative size-5 shrink-0",children:[(0,z.jsx)("div",{className:"absolute inset-0 flex size-5 items-center justify-center overflow-hidden rounded bg-background transition-opacity group-hover:opacity-0",children:o?(0,z.jsx)("img",{alt:n||"attachment",className:"size-5 object-cover",height:20,src:e.url,width:20}):(0,z.jsx)("div",{className:"flex size-5 items-center justify-center text-muted-foreground",children:(0,z.jsx)(jS,{className:"size-3"})})}),(0,z.jsxs)(W.Button,{"aria-label":"Remove attachment",className:"absolute inset-0 size-5 cursor-pointer rounded p-0 opacity-0 transition-opacity group-hover:pointer-events-auto group-hover:opacity-100 [&>svg]:size-2.5",onClick:r=>{r.stopPropagation(),i.remove(e.id)},type:"button",variant:"ghost",children:[(0,z.jsx)(t8,{}),(0,z.jsx)("span",{className:"sr-only",children:"Remove"})]})]}),(0,z.jsx)("span",{className:"flex-1 truncate",children:a})]},e.id)}),(0,z.jsx)(jH,{className:"w-auto p-2",children:(0,z.jsxs)("div",{className:"w-auto space-y-3",children:[o&&(0,z.jsx)("div",{className:"flex max-h-96 w-96 items-center justify-center overflow-hidden rounded-md border",children:(0,z.jsx)("img",{alt:n||"attachment preview",className:"max-h-full max-w-full object-contain",height:384,src:e.url,width:448})}),(0,z.jsx)("div",{className:"flex items-center gap-2.5",children:(0,z.jsxs)("div",{className:"min-w-0 flex-1 space-y-1 px-0.5",children:[(0,z.jsx)("h4",{className:"truncate font-semibold text-sm leading-none",children:n||(o?"Image":"Attachment")}),e.mediaType&&(0,z.jsx)("p",{className:"truncate font-mono text-muted-foreground text-xs",children:e.mediaType})]})})]})})]})}function jA({children:e,className:r,...s}){let i=jE();return i.files.length?(0,z.jsx)("div",{className:(0,ey.cn)("flex flex-wrap items-center gap-2 p-3 w-full",r),...s,children:i.files.map(r=>(0,z.jsx)($.Fragment,{children:e(r)},r.id))}):null}let jM=({label:e="Add photos or files",...r})=>{let s=jE();return(0,z.jsxs)(og,{...r,onSelect:e=>{e.preventDefault(),s.openFileDialog()},children:[(0,z.jsx)(jw,{className:"mr-2 size-4"})," ",e]})},jF=({className:e,accept:r,multiple:s,globalDrop:i,syncHiddenInput:n,maxFiles:o,maxFileSize:a,onError:l,onSubmit:c,children:d,...u})=>{let h=jN(),f=!!h,p=(0,$.useRef)(null),m=(0,$.useRef)(null),[g,x]=(0,$.useState)([]),v=f?h.attachments.files:g,_=(0,$.useRef)(v);_.current=v;let y=(0,$.useCallback)(()=>{p.current?.click()},[]),b=(0,$.useCallback)(e=>!r||""===r.trim()||r.split(",").map(e=>e.trim()).filter(Boolean).some(r=>{if(r.endsWith("/*")){let s=r.slice(0,-1);return e.type.startsWith(s)}return e.type===r}),[r]),w=(0,$.useCallback)(e=>{let r=Array.from(e),s=r.filter(e=>b(e));if(r.length&&0===s.length)return void l?.({code:"accept",message:"No files match the accepted types."});let i=s.filter(e=>!a||e.size<=a);s.length>0&&0===i.length?l?.({code:"max_file_size",message:"All files exceed the maximum size."}):x(e=>{let r="number"==typeof o?Math.max(0,o-e.length):void 0,s="number"==typeof r?i.slice(0,r):i;"number"==typeof r&&i.length>r&&l?.({code:"max_files",message:"Too many files. Some were not added."});let n=[];for(let e of s)n.push({id:jC(),type:"file",url:URL.createObjectURL(e),mediaType:e.type,filename:e.name});return e.concat(n)})},[b,o,a,l]),S=(0,$.useCallback)(e=>x(r=>{let s=r.find(r=>r.id===e);return s?.url&&URL.revokeObjectURL(s.url),r.filter(r=>r.id!==e)}),[]),C=(0,$.useCallback)(()=>x(e=>{for(let r of e)r.url&&URL.revokeObjectURL(r.url);return[]}),[]),j=f?h.attachments.add:w,k=f?h.attachments.remove:S,N=f?h.attachments.clear:C,D=f?h.attachments.openFileDialog:y;(0,$.useEffect)(()=>{f&&h.__registerFileInput(p,()=>p.current?.click())},[f,h]),(0,$.useEffect)(()=>{n&&p.current&&0===v.length&&(p.current.value="")},[v,n]),(0,$.useEffect)(()=>{let e=m.current;if(!e||i)return;let r=e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault()},s=e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault(),e.dataTransfer?.files&&e.dataTransfer.files.length>0&&j(e.dataTransfer.files)};return e.addEventListener("dragover",r),e.addEventListener("drop",s),()=>{e.removeEventListener("dragover",r),e.removeEventListener("drop",s)}},[j,i]),(0,$.useEffect)(()=>{if(!i)return;let e=e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault()},r=e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault(),e.dataTransfer?.files&&e.dataTransfer.files.length>0&&j(e.dataTransfer.files)};return document.addEventListener("dragover",e),document.addEventListener("drop",r),()=>{document.removeEventListener("dragover",e),document.removeEventListener("drop",r)}},[j,i]),(0,$.useEffect)(()=>()=>{if(!f)for(let e of _.current)e.url&&URL.revokeObjectURL(e.url)},[f]);let E=async e=>{try{let r=await fetch(e),s=await r.blob();return new Promise(e=>{let r=new FileReader;r.onloadend=()=>e(r.result),r.onerror=()=>e(null),r.readAsDataURL(s)})}catch{return null}},R=(0,$.useMemo)(()=>({files:v.map(e=>({...e,id:e.id})),add:j,remove:k,clear:N,openFileDialog:D,fileInputRef:p}),[v,j,k,N,D]),A=(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)("input",{accept:r,"aria-label":"Upload files",className:"hidden",multiple:s,onChange:e=>{e.currentTarget.files&&j(e.currentTarget.files),e.currentTarget.value=""},ref:p,title:"Upload files",type:"file"}),(0,z.jsx)("form",{className:(0,ey.cn)("w-full",e),onSubmit:e=>{e.preventDefault();let r=e.currentTarget,s=f?h.textInput.value:new FormData(r).get("message")||"";f||r.reset(),Promise.all(v.map(async({id:e,...r})=>{if(r.url&&r.url.startsWith("blob:")){let e=await E(r.url);return{...r,url:e??r.url}}return r})).then(r=>{try{let i=c({text:s,files:r},e);i instanceof Promise?i.then(()=>{N(),f&&h.textInput.clear()}).catch(()=>{}):(N(),f&&h.textInput.clear())}catch{}}).catch(()=>{})},ref:m,...u,children:(0,z.jsx)(yb,{className:"overflow-hidden",children:d})})]});return f?A:(0,z.jsx)(jD.Provider,{value:R,children:A})},jT=({onChange:e,onKeyDown:r,onPasteText:s,className:i,placeholder:n="What would you like to know?",...o})=>{let a=jN(),l=jE(),[c,d]=(0,$.useState)(!1),u=a?{value:a.textInput.value,onChange:r=>{a.textInput.setInput(r.currentTarget.value),e?.(r)}}:{onChange:e};return(0,z.jsx)(yN,{className:(0,ey.cn)("field-sizing-content max-h-48 min-h-9",i),name:"message",onCompositionEnd:()=>d(!1),onCompositionStart:()=>d(!0),onKeyDown:e=>{if(r?.(e),!e.defaultPrevented){if("Enter"===e.key){if(c||e.nativeEvent.isComposing||e.shiftKey)return;e.preventDefault();let r=e.currentTarget.form,s=r?.querySelector('button[type="submit"]');if(s?.disabled)return;r?.requestSubmit()}if("Backspace"===e.key&&""===e.currentTarget.value&&l.files.length>0){e.preventDefault();let r=l.files.at(-1);r&&l.remove(r.id)}}},onPaste:e=>{let r=e.clipboardData?.items;if(!r)return;let i=[];for(let e of r)if("file"===e.kind){let r=e.getAsFile();r&&i.push(r)}if(i.length>0){e.preventDefault(),l.add(i);return}if(s){let r=e.clipboardData.getData("text");r.length>0&&s(e,r)}},placeholder:n,...o,...u})},jP=({className:e,...r})=>(0,z.jsx)(yS,{align:"block-end",className:(0,ey.cn)("order-first flex-wrap gap-1",e),...r}),jB=({variant:e="ghost",className:r,size:s,...i})=>{let n=s??($.Children.count(i.children)>1?"sm":"icon-sm");return(0,z.jsx)(yj,{className:(0,ey.cn)(r),size:n,type:"button",variant:e,...i})},jL=e=>(0,z.jsx)(of,{...e}),jI=({className:e,children:r,...s})=>(0,z.jsx)(op,{asChild:!0,children:(0,z.jsx)(jB,{className:e,...s,children:r??(0,z.jsx)(eS,{className:"size-4"})})}),jO=({className:e,...r})=>(0,z.jsx)(om,{align:"start",className:(0,ey.cn)(e),...r}),jz=({className:e,...r})=>(0,z.jsx)(og,{className:(0,ey.cn)(e),...r}),j$=({className:e,variant:r="default",size:s="icon-sm",status:i,children:n,...o})=>{let a=(0,z.jsx)(jb,{className:"size-4"});return"submitted"===i?a=(0,z.jsx)(rj,{className:"size-4 animate-spin"}):"streaming"===i?a=(0,z.jsx)(d6,{className:"size-4"}):"error"===i&&(a=(0,z.jsx)(t8,{className:"size-4"})),(0,z.jsx)(yj,{"aria-label":"Submit",className:(0,ey.cn)(e),size:s,type:"submit",variant:r,...o,children:n??a})},jW=({openDelay:e=0,closeDelay:r=0,...s})=>(0,z.jsx)(jv,{closeDelay:r,openDelay:e,...s}),jH=({align:e="start",...r})=>(0,z.jsx)(jy,{align:e,...r}),jU=({size:e=16})=>(0,z.jsxs)("svg",{height:e,strokeLinejoin:"round",style:{color:"currentcolor"},viewBox:"0 0 16 16",width:e,children:[(0,z.jsx)("title",{children:"Loader"}),(0,z.jsxs)("g",{clipPath:"url(#clip0_2393_1490)",children:[(0,z.jsx)("path",{d:"M8 0V4",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M8 16V12",opacity:"0.5",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M3.29773 1.52783L5.64887 4.7639",opacity:"0.9",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M12.7023 1.52783L10.3511 4.7639",opacity:"0.1",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M12.7023 14.472L10.3511 11.236",opacity:"0.4",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M3.29773 14.472L5.64887 11.236",opacity:"0.6",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M15.6085 5.52783L11.8043 6.7639",opacity:"0.2",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M0.391602 10.472L4.19583 9.23598",opacity:"0.7",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M15.6085 10.4722L11.8043 9.2361",opacity:"0.3",stroke:"currentColor",strokeWidth:"1.5"}),(0,z.jsx)("path",{d:"M0.391602 5.52783L4.19583 6.7639",opacity:"0.8",stroke:"currentColor",strokeWidth:"1.5"})]}),(0,z.jsx)("defs",{children:(0,z.jsx)("clipPath",{id:"clip0_2393_1490",children:(0,z.jsx)("rect",{fill:"white",height:"16",width:"16"})})})]}),jK=({className:e,size:r=16,...s})=>(0,z.jsx)("div",{className:(0,ey.cn)("inline-flex animate-spin items-center justify-center",e),...s,children:(0,z.jsx)(jU,{size:r})}),jq=(0,ew.default)("wifi",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]]),jV=(0,ew.default)("wifi-off",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]),jY=(0,ew.default)("square-pen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]),jG=(0,ew.default)("languages",[["path",{d:"m5 8 6 6",key:"1wu5hv"}],["path",{d:"m4 14 6-6 2-3",key:"1k1g8d"}],["path",{d:"M2 5h12",key:"or177f"}],["path",{d:"M7 2h1",key:"1t2jsx"}],["path",{d:"m22 22-5-10-5 10",key:"don7ne"}],["path",{d:"M14 18h6",key:"1m8k6r"}]]),jX=(0,ew.default)("split",[["path",{d:"M16 3h5v5",key:"1806ms"}],["path",{d:"M8 3H3v5",key:"15dfkv"}],["path",{d:"M12 22v-8.3a4 4 0 0 0-1.172-2.872L3 3",key:"1qrqzj"}],["path",{d:"m15 9 6-6",key:"ko1vev"}]]),jJ=(0,ew.default)("clipboard-list",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"M12 11h4",key:"1jrz19"}],["path",{d:"M12 16h4",key:"n85exb"}],["path",{d:"M8 11h.01",key:"1dfujw"}],["path",{d:"M8 16h.01",key:"18s6g9"}]]);function jZ({mode:e,onModeChange:r,disabled:s}){return(0,z.jsxs)("div",{className:"inline-flex items-center rounded-md border bg-muted/50 px-0.5 text-xs",children:[(0,z.jsxs)("button",{onClick:()=>r("plan"),disabled:s,className:(0,ey.cn)("inline-flex items-center gap-1 rounded-sm px-2 py-0.5 transition-colors","plan"===e?"bg-primary text-primary-foreground font-medium shadow-sm":"text-muted-foreground hover:text-foreground",s&&"opacity-50 cursor-not-allowed"),children:[(0,z.jsx)(jJ,{className:"h-3 w-3"}),"Plan"]}),(0,z.jsxs)("button",{onClick:()=>r("edit"),disabled:s,className:(0,ey.cn)("inline-flex items-center gap-1 rounded-sm px-2 py-0.5 transition-colors","edit"===e?"bg-primary text-primary-foreground font-medium shadow-sm":"text-muted-foreground hover:text-foreground",s&&"opacity-50 cursor-not-allowed"),children:[(0,z.jsx)(rm,{className:"h-3 w-3"}),"Edit"]})]})}function jQ(e){if(!e)return[];try{let r=window.localStorage.getItem(e);if(!r)return[];let s=JSON.parse(r);if(!Array.isArray(s))return[];return s.filter(e=>"string"==typeof e)}catch{return[]}}function j0(e){if(!e)return"";try{return window.localStorage.getItem(e)??""}catch{return""}}function j1(e){let r=e.parentElement;for(;r;){let{overflowY:e}=getComputedStyle(r);if("auto"===e||"scroll"===e)return r;r=r.parentElement}return null}function j2({messages:e,contentRef:r}){let[s,i]=(0,$.useState)([]),[n,o]=(0,$.useState)(!1),[a,l]=(0,$.useState)(null),c=(0,$.useRef)(null),d=(0,$.useCallback)(()=>{let s=r.current;if(!s)return;c.current||(c.current=j1(s));let n=c.current;if(!n)return;let a=n.scrollHeight>n.clientHeight;if(o(a),!a)return void i([]);let l=s.querySelectorAll("[data-user-msg-idx]"),d=n.getBoundingClientRect(),u=[];l.forEach(r=>{let s=parseInt(r.dataset.userMsgIdx,10),i=e[s];if(!i)return;let o=(r.getBoundingClientRect().top-d.top+n.scrollTop)/n.scrollHeight;u.push({index:s,position:Math.max(0,Math.min(1,o)),preview:function(e){if("user"!==e.type)return"";let r=e.content,s="string"==typeof r?r:r.filter(e=>"text"===e.type).map(e=>e.text).join(" "),i="string"!=typeof r&&r.some(e=>"image"===e.type),n=s.split("\n")[0]??"";return(n.length>80?n.slice(0,77)+"...":n)||(i?"(Image)":"")}(i)})}),i(u)},[e,r]);(0,$.useEffect)(()=>{let e=r.current;if(!e){c.current=null,i([]),o(!1);return}let s=j1(e);if(!s)return;c.current=s,d();let n=new ResizeObserver(d);return n.observe(s),n.observe(e),()=>{n.disconnect()}},[e,d,r]);let u=(0,$.useCallback)(e=>{let s=r.current;if(!s)return;let i=s.querySelector(`[data-user-msg-idx="${e}"]`);i&&i.scrollIntoView({block:"start",behavior:"smooth"})},[r]);return n&&0!==s.length?(0,z.jsx)("div",{className:"absolute right-0 top-0 bottom-0 w-6 z-20 pointer-events-none",children:s.map(e=>(0,z.jsxs)("div",{className:"absolute right-0.5 -translate-y-1/2 pointer-events-auto",style:{top:`${100*e.position}%`},children:[(0,z.jsx)("div",{className:"w-3 h-[3px] rounded-sm bg-primary/50 hover:bg-primary cursor-pointer transition-colors",onClick:()=>u(e.index),onMouseEnter:()=>l(e.index),onMouseLeave:()=>l(null)}),a===e.index&&e.preview&&(0,z.jsxs)("div",{className:"absolute right-full mr-2 top-1/2 -translate-y-1/2 max-w-64 px-2.5 py-1.5 bg-popover border border-border rounded-md shadow-md text-xs text-popover-foreground whitespace-nowrap overflow-hidden text-ellipsis pointer-events-none",children:[e.preview,(0,z.jsx)("div",{className:"absolute top-1/2 -translate-y-1/2 -right-1 w-2 h-2 bg-popover border-r border-t border-border rotate-45"})]})]},e.index))}):null}let j5=(0,ew.default)("star",[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]);function j3({projectId:e,branch:r,currentSessionId:s,refreshKey:i,pendingTitleSessionId:n,aiTitleOverride:o,onSwitch:a,onDelete:l}){let[c,d]=(0,$.useState)([]),[u,h]=(0,$.useState)(null),[f,p]=(0,$.useState)(""),[m,g]=(0,$.useState)(!1),[x,v]=(0,$.useState)(null),[_,y]=(0,$.useState)(0),b=(0,$.useCallback)(()=>y(e=>e+1),[]);(0,$.useEffect)(()=>{let s=!1;return(0,rx.listBranchSessions)(e,r).then(e=>{s||d(e.sessions)}).catch(e=>{s||console.error("[SessionHistoryDropdown] refresh failed:",e)}),()=>{s=!0}},[e,r,i,_]);let w=(0,$.useRef)(null);(0,$.useEffect)(()=>{if(!s)return;if(c.some(e=>e.id===s)){w.current=null;return}if(w.current===s)return;w.current=s;let i=!1;return(0,rx.listBranchSessions)(e,r).then(e=>{if(i)return;d(e.sessions);let r=e.sessions.find(e=>e.id===s),n=!!r&&(o?.sessionId===r.id||!!(r.title&&r.title.trim().length>0));r&&!n&&v(s)}).catch(e=>{i||console.error("[SessionHistoryDropdown] missing-session refresh failed:",e)}),()=>{i=!0}},[s,c,e,r,o]),(0,$.useEffect)(()=>{if(!x)return;let e=setTimeout(()=>{v(e=>e===x?null:e)},3e4);return()=>clearTimeout(e)},[x]),(0,$.useEffect)(()=>{if(!x)return;let e=setTimeout(()=>{v(e=>e===x?null:e)},3e4);return()=>clearTimeout(e)},[x]);let S=async(e,r)=>{let s=r.trim().length>0?r.trim():null;try{await (0,rx.renameSession)(e,s),d(r=>r.map(r=>r.id===e?{...r,title:s}:r)),h(null),gK.toast.success("Renamed")}catch(e){gK.toast.error("Rename failed"),console.error(e)}},C=async(e,r)=>{let s=null==r,i=s?Date.now():null;d(r=>r.map(r=>r.id===e?{...r,favorited_at:i}:r));try{await (0,rx.setSessionFavorited)(e,s)}catch(i){d(s=>s.map(s=>s.id===e?{...s,favorited_at:r}:s)),gK.toast.error(s?"Favorite failed":"Unfavorite failed"),console.error(i)}},j=async e=>{if(window.confirm("Delete this conversation? This cannot be undone."))try{await (0,rx.deleteSession)(e);let r=c.filter(r=>r.id!==e);d(r),l?.(e,r),gK.toast.success("Deleted")}catch(e){gK.toast.error("Delete failed"),console.error(e)}},k=e=>o&&o.sessionId===e.id?o.title:e.title&&e.title.trim().length>0?e.title:e.updated_at?new Date(e.updated_at).toLocaleString():new Date(e.created_at).toLocaleString(),N=e=>{let r;return o?.sessionId!==e.id&&(!e.title||!(e.title.trim().length>0))&&(r=e.id,null!==n&&n===r||x===e.id)},D=c.find(e=>e.id===s),E=null!==s&&(!D||N(D)),R=D?k(D):null===s?"New Session":"History",A=E?"Generating title…":R;return(0,z.jsxs)(of,{open:m,onOpenChange:e=>{g(e),e&&b()},children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsxs)(W.Button,{variant:"ghost",size:"sm",className:"h-7 text-xs gap-1 w-[200px] justify-start",title:A,children:[E?(0,z.jsx)("span",{className:"block h-3 flex-1 rounded-sm bg-accent animate-pulse",role:"status","aria-label":"Generating title"}):(0,z.jsx)("span",{className:"truncate flex-1 text-left",children:R}),(0,z.jsx)(sb,{className:"h-3 w-3 flex-shrink-0"})]})}),(0,z.jsxs)(om,{align:"start",className:"w-80 max-h-96 overflow-y-auto",children:[0===c.length&&(0,z.jsx)("div",{className:"px-2 py-3 text-xs text-muted-foreground",children:"No history yet."}),c.map(e=>{let r=e.id===s,i=u===e.id;return(0,z.jsxs)(og,{onSelect:s=>{i?s.preventDefault():r||a(e.id)},onPointerMove:null!==u?e=>e.preventDefault():void 0,className:`flex items-center gap-2 group ${r?"bg-accent text-accent-foreground":""}`,children:[(0,z.jsx)("div",{className:"flex-1 min-w-0",children:i?(0,z.jsxs)("div",{className:"flex items-center gap-1",children:[(0,z.jsx)(ro,{value:f,onChange:e=>p(e.target.value),onKeyDown:r=>{r.stopPropagation(),"Enter"===r.key&&S(e.id,f),"Escape"===r.key&&h(null)},autoFocus:!0,className:"h-6 text-xs"}),(0,z.jsx)("button",{type:"button","aria-label":"Save rename",onClick:r=>{r.stopPropagation(),S(e.id,f)},children:(0,z.jsx)(rh.Check,{className:"h-3 w-3"})}),(0,z.jsx)("button",{type:"button","aria-label":"Cancel rename",onClick:e=>{e.stopPropagation(),h(null)},children:(0,z.jsx)(t8,{className:"h-3 w-3"})})]}):N(e)?(0,z.jsx)("div",{className:"py-0.5",title:"Generating title…",children:(0,z.jsx)("span",{className:"block h-3 w-40 rounded-sm bg-accent animate-pulse",role:"status","aria-label":"Generating title"})}):(0,z.jsx)("div",{className:"truncate text-xs",title:`${e.updated_at?new Date(e.updated_at).toLocaleString():new Date(e.created_at).toLocaleString()} • ${e.entry_count??0} messages • status: ${e.status}`,children:k(e)})}),!i&&(0,z.jsxs)("div",{className:"flex items-center gap-1",children:[(0,z.jsxs)("div",{className:"opacity-0 group-hover:opacity-100 flex items-center gap-1",children:[(0,z.jsx)("button",{type:"button","aria-label":"Rename conversation",onClick:r=>{r.stopPropagation(),h(e.id),p(e.title??"")},className:"p-1 hover:bg-muted rounded",children:(0,z.jsx)(rm,{className:"h-3 w-3"})}),(0,z.jsx)("button",{type:"button","aria-label":"Delete conversation",onClick:r=>{r.stopPropagation(),j(e.id)},className:"p-1 hover:bg-muted rounded text-destructive",children:(0,z.jsx)(rl,{className:"h-3 w-3"})})]}),(0,z.jsx)("button",{type:"button","aria-label":null!=e.favorited_at?"Unfavorite conversation":"Favorite conversation",title:null!=e.favorited_at?"Unfavorite":"Favorite",onClick:r=>{r.stopPropagation(),C(e.id,e.favorited_at??null)},className:`p-1 hover:bg-muted rounded ${null!=e.favorited_at?"opacity-100 text-yellow-500":"opacity-0 group-hover:opacity-100 text-muted-foreground"}`,children:(0,z.jsx)(j5,{className:`h-3 w-3 ${null!=e.favorited_at?"fill-current":""}`})})]})]},e.id)}),c.length>0&&(0,z.jsx)(ob,{}),(0,z.jsx)(og,{onSelect:()=>b(),className:"text-xs text-muted-foreground",children:"Refresh"})]})]})}let j4=(0,ew.default)("quote",[["path",{d:"M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z",key:"rib7q0"}],["path",{d:"M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z",key:"1ymkrd"}]]);function j6(e,r){let s=e;for(;s&&s!==r;){if(s.nodeType===Node.ELEMENT_NODE){let e=s.getAttribute("data-message-idx");if(null!==e)return e}s=s.parentNode}return null}function j8({containerRef:e,onQuote:r}){let[s,i]=(0,$.useState)(null);if((0,$.useEffect)(()=>{function r(){let r=e.current;if(!r)return void i(null);let s=window.getSelection();if(!s||s.isCollapsed||0===s.rangeCount)return void i(null);let n=s.toString();if(!n.trim())return void i(null);let{anchorNode:o,focusNode:a}=s;if(!o||!a||!r.contains(o)||!r.contains(a))return void i(null);let l=j6(o,r),c=j6(a,r);if(null===l||null===c||l!==c)return void i(null);let d=s.getRangeAt(0).getBoundingClientRect();0===d.width&&0===d.height?i(null):i({text:n,rect:{top:d.top,bottom:d.bottom,left:d.left,width:d.width}})}function s(){let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||i(null)}return document.addEventListener("mouseup",r),document.addEventListener("keyup",r),document.addEventListener("touchend",r),document.addEventListener("selectionchange",s),window.addEventListener("scroll",r,!0),window.addEventListener("resize",r),()=>{document.removeEventListener("mouseup",r),document.removeEventListener("keyup",r),document.removeEventListener("touchend",r),document.removeEventListener("selectionchange",s),window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",r)}},[e]),!s||"undefined"==typeof document)return null;let n=s.rect.top-8-30<8?s.rect.bottom+8:s.rect.top-8-30,o=s.rect.left+s.rect.width/2,a=Math.max(8,Math.min(window.innerWidth-8,o));return(0,ee.createPortal)((0,z.jsxs)("button",{type:"button",onMouseDown:e=>{e.preventDefault(),r(s.text),window.getSelection()?.removeAllRanges(),i(null)},style:{position:"fixed",top:n,left:a,transform:"translateX(-50%)",zIndex:50},className:"inline-flex items-center gap-1.5 rounded-md border border-border bg-popover px-3 py-1.5 text-xs font-medium text-popover-foreground shadow-2xl hover:bg-accent",children:[(0,z.jsx)(j4,{className:"h-3 w-3"}),"Quote"]}),document.body)}function j7(){return 0===jE().files.length?null:(0,z.jsx)(jP,{children:(0,z.jsx)(jA,{children:e=>(0,z.jsx)(jR,{data:e})})})}let j9=(0,$.createContext)(null);function ke(){let e=(0,$.useContext)(j9);if(!e)throw Error("useAgentConversation must be used within AgentConversationContext");return e}let kt=/\[📎 paste #(\d+) \([^)]+\)\]/g;function kr(e,r){return`[📎 paste #${e} (${function(e){if(e<1024)return`${e}B`;let r=e/1024;return r<10?`${r.toFixed(1)}KB`:`${Math.round(r)}KB`}(r)})]`}let ks=(0,$.forwardRef)(function({projectId:e,branch:r,sessionId:s,setSessionUrlParam:i,project:n,onAgentModeChange:o,onTaskCompleted:a,onSessionStarted:l,onSessionTitleUpdated:c,onStatusChange:d,onNewConversation:u},h){var f;let p,m,g,x,[v,_]=function(e,r){let s=e&&r?`vibedeckx:agent-draft:${e}:${r}`:null,[i,n]=(0,$.useState)(()=>j0(s)),[o,a]=(0,$.useState)(s);return o!==s&&(a(s),n(j0(s))),[i,(0,$.useCallback)(e=>{n(e);if(s)try{e?window.localStorage.setItem(s,e):window.localStorage.removeItem(s)}catch{}},[s])]}(e,r),[y,b]=(0,$.useState)([]),[w,S]=(0,$.useState)(1),[C,j]=(0,$.useState)("edit"),[k,N]=(0,$.useState)(!1),[D,E]=(0,$.useState)(!1),[R,A]=(0,$.useState)(!1),[M,F]=(0,$.useState)("claude-code"),[T,P]=(0,$.useState)([]),[B,L]=(0,$.useState)(0),[I,O]=(0,$.useState)(null),[H,U]=(0,$.useState)(null),K=(0,$.useRef)(null),q=(0,$.useCallback)(e=>{if("ArrowUp"!==e.key&&"ArrowDown"!==e.key||!e.shiftKey||e.ctrlKey||e.metaKey||e.altKey)return;let r=K.current;if(!r)return;let s=j1(r);if(!s)return;let i=s.getBoundingClientRect(),n=s.scrollTop,o="ArrowUp"===e.key,a=null,l=o?-1/0:1/0;r.querySelectorAll("[data-user-msg-idx]").forEach(e=>{let r=e.getBoundingClientRect().top-i.top+s.scrollTop;o?r<n-12&&r>l&&(l=r,a=e):r>n+12&&r<l&&(l=r,a=e)}),a&&(e.preventDefault(),a.scrollIntoView({block:"start",behavior:"smooth"}))},[K]),V=(0,$.useRef)(null),Y=function(e,r,s){let i=r&&s?`vibedeckx:agent-input-history:${r}:${s}`:null,n=(0,$.useRef)(jQ(i)),o=(0,$.useRef)(-1),a=(0,$.useRef)(""),[l,c]=(0,$.useState)(i);return l!==i&&(c(i),n.current=jQ(i),o.current=-1,a.current=""),{push:(0,$.useCallback)(e=>{let r=e.trim();if(!r)return;let s=n.current;if(s.length>0&&s[s.length-1]===r){o.current=-1;return}s.push(r),s.length>50&&s.shift(),o.current=-1;if(i)try{0===s.length?window.localStorage.removeItem(i):window.localStorage.setItem(i,JSON.stringify(s))}catch{}},[i]),handleKeyDown:(0,$.useCallback)(r=>{let s=r.currentTarget,i=n.current;if(0!==i.length)if("ArrowUp"===r.key){if(0!==s.selectionStart||0!==s.selectionEnd)return;if(r.preventDefault(),-1===o.current)a.current=s.value,o.current=i.length-1;else{if(!(o.current>0))return;o.current--}e(i[o.current])}else if("ArrowDown"===r.key){if(-1===o.current)return;let n=s.value.length;if(s.selectionStart!==n||s.selectionEnd!==n)return;r.preventDefault(),o.current<i.length-1?(o.current++,e(i[o.current])):(o.current=-1,e(a.current))}else -1!==o.current&&(o.current=-1)},[e])}}(_,e,r),{remotes:G}=vU(),X=[];for(let e of(n?.path&&X.push({id:"local",label:"Local",icon:oD}),G))X.push({id:e.remote_server_id,label:e.server_name,icon:sc(e)});let{session:J,messages:Z,status:Q,isConnected:ee,isInitialized:et,isLoading:er,error:es,remoteStatus:ei,sendMessage:en,uploadPaste:eo,stopSession:ea,switchAgentType:el,startNewConversation:ec,ensureSession:ed,switchMode:eu,acceptPlan:eh}=function(e,r,s,i,n){let o=n?.sessionId??null,[a,l]=(0,$.useState)(null),[c,d]=(0,$.useState)([]),[u,h]=(0,$.useState)("stopped"),[f,p]=(0,$.useState)(!1),[m,g]=(0,$.useState)(!1),[x,v]=(0,$.useState)(!1),[_,y]=(0,$.useState)(null),[b,w]=(0,$.useState)(null),S=(0,$.useRef)(null),C=(0,$.useRef)(null),j=(0,$.useRef)(()=>{}),k=(0,$.useRef)(null),N=(0,$.useRef)(0),D=(0,$.useRef)({entries:[],status:"stopped"}),E=(0,$.useRef)(!1),R=(0,$.useRef)(!0),A=(0,$.useRef)(null),M=(0,$.useRef)(null),F=(0,$.useRef)(0),T=(0,$.useRef)(!1),P=(0,$.useRef)(0),B=(0,$.useRef)(!1),L=(0,$.useRef)(!1),I=(0,$.useRef)(n?.onTaskCompleted),O=(0,$.useRef)(n?.onSessionStarted),z=(0,$.useRef)(n?.onTitleUpdated),W=(0,$.useRef)(e),H=(0,$.useRef)(r),U=(0,$.useRef)(o);(0,$.useEffect)(()=>{I.current=n?.onTaskCompleted,O.current=n?.onSessionStarted,z.current=n?.onTitleUpdated,W.current=e,H.current=r,U.current=o});let K=(0,$.useCallback)((e,r=!1)=>{(0,rx.getFreshToken)(r?{skipCache:!0}:void 0).then(()=>j.current(e))},[]),q=(0,$.useCallback)(e=>{let r=()=>{let e=W.current;if(!e)return;let r=H.current;SB.delete(SL(e,r,U.current));let s=C.current;s&&SB.delete(SL(e,r,s))};if(S.current&&C.current!==e&&(console.log(`[AgentSession] Closing stale WS for ${C.current}, switching to ${e}`),S.current.close(1e3,"session-switch"),S.current=null,C.current=null),S.current?.readyState===WebSocket.OPEN||S.current?.readyState===WebSocket.CONNECTING)return;0===D.current.entries.filter(Boolean).length&&(D.current={entries:[],status:"running"}),E.current=!1,T.current=!0;let s=(0,rx.getWebSocketUrl)(`/api/agent-sessions/${e}/stream`);console.log("[AgentSession] Connecting to WebSocket:",s);let i=new WebSocket(s);S.current=i,C.current=e,i.onopen=()=>{console.log("[AgentSession] WebSocket connected"),p(!0),y(null),w(null),A.current=Date.now(),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{console.log("[AgentSession] Connection stable, resetting backoff counter"),N.current=0,F.current=0},5e3)},i.onmessage=e=>{try{let n=JSON.parse(e.data);if("JsonPatch"in n){var s;let e=n.JsonPatch;s=D.current,D.current=Sm(s,r=>{for(let s of e){let{op:e,path:i,value:n}=s;if("/entries"===i&&"replace"===e&&n?.type==="ENTRY"&&n.content?.type==="system"&&n.content?.content==="__CLEAR_ALL__"){console.log("[JsonPatch] Received clearAll signal - clearing all entries"),r.entries=[];continue}if(i.startsWith("/entries/")){let s=parseInt(i.replace("/entries/",""),10);if(isNaN(s)){console.warn(`[JsonPatch] Invalid index in path: ${i}`);continue}if(n?.type!=="ENTRY"){console.warn("[JsonPatch] Expected ENTRY type for entries path");continue}switch(e){case"add":for(;r.entries.length<=s;)r.entries.push(null);r.entries[s]=n.content;break;case"replace":s<r.entries.length?r.entries[s]=n.content:console.warn(`[JsonPatch] Replace index out of bounds: ${s}`);break;case"remove":s<r.entries.length&&r.entries.splice(s,1)}}else"/status"===i&&n?.type==="STATUS"&&(console.log("[AgentSession] /status patch →",n.content),r.status=n.content)}}),T.current?console.log("[AgentSession] /status patch applied during replay (no setStatus), container.status =",D.current.status):(d([...D.current.entries.filter(Boolean)]),console.log("[AgentSession] setStatus(live) →",D.current.status),h(D.current.status),("stopped"===D.current.status||"error"===D.current.status)&&r());return}if("Ready"in n){console.log("[AgentSession] Received Ready signal - history complete, status=",D.current.status),T.current=!1,d([...D.current.entries.filter(Boolean)]),h(D.current.status),g(!0);return}if("finished"in n){console.log("[AgentSession] Received finished signal, invalidating cache"),E.current=!0,r(),i.close(1e3,"finished");return}if("taskCompleted"in n){let{duration_ms:e,cost_usd:r,input_tokens:s,output_tokens:i}=n.taskCompleted,o=[];if(null!=e){let r=(e/1e3).toFixed(1);o.push(`${r}s`)}if(null!=r)o.push(`$${r.toFixed(4)}`);else if(null!=s||null!=i){let e=(s??0)+(i??0),r=e>1e3?`${(e/1e3).toFixed(1)}K`:String(e);o.push(`${r} tokens`)}gK.toast.success("Task completed",{description:o.length>0?o.join(" · "):void 0}),I.current?.();return}if("remoteStatus"in n)return void w(n.remoteStatus);if("titleUpdated"in n)return void z.current?.(n.titleUpdated.title,C.current);if("error"in n){console.error("[AgentSession] Server error:",n.error),y(n.error),"Session not found"===n.error&&(console.log("[AgentSession] Session invalid, invalidating cache, will create new session"),r(),E.current=!0,l(null),h("stopped"),g(!1),R.current=!0);return}}catch(e){console.error("[AgentSession] Failed to parse message:",e)}},i.onclose=e=>{let s,i;console.log("[AgentSession] WebSocket disconnected",e.code,e.reason),p(!1),M.current&&(clearTimeout(M.current),M.current=null);let n=A.current?Date.now()-A.current:0;if(A.current=null,n>0&&n<5e3){if(F.current++,console.log(`[AgentSession] Short-lived connection (${n}ms), count: ${F.current}, backoff attempt: ${N.current}`),F.current>=3){if(console.log("[AgentSession] Multiple short-lived connections detected, session likely invalid - will recreate"),B.current){console.log("[AgentSession] Skipping auto-restart: last session creation failed"),y("Unable to connect to remote server. Please check the server configuration.");return}r(),l(null),y(null),N.current=0,F.current=0,R.current=!0;return}}else n>=5e3&&(F.current=0);if(E.current||1e3===e.code)return;if(N.current>=10){console.log("[AgentSession] Max reconnect attempts reached"),y("Unable to connect to server. Please check if the backend is running.");return}let o=(i=(s=Math.min(3e4,1e3*Math.pow(2,N.current)))*Math.random()*.25,s+i);console.log(`[AgentSession] Reconnecting in ${Math.round(o)}ms (attempt ${N.current+1})`),N.current++,k.current=setTimeout(()=>{let e=C.current;e&&!E.current&&K(e,!0)},o)},i.onerror=e=>{console.error("[AgentSession] WebSocket error:",e)}},[K]);(0,$.useEffect)(()=>{j.current=q},[q]);let V=(0,$.useCallback)(async s=>{if(!e)return null;if(L.current)return console.log("[AgentSession] startSession already in progress, skipping"),null;L.current=!0;let n=P.current;y(null),w(null),g(!1),B.current=!1;let a=SL(e,r,o),c=SB.get(a);if(c)return console.log(`[AgentSession] Cache hit for ${a}, reconnecting WebSocket directly`),l(c),h(c.status),K(c.id),O.current?.(c),L.current=!1,c;v(!0);try{console.log(`[AgentSession] Starting REST call: projectId=${e}, branch=${r}, sessionId=${o??"latest"}, agentType=${i}, generation=${n}`);let{session:c,messages:u}=o?await SI(o):await SD(e,r,s,i);if(P.current!==n)return console.log("[AgentSession] Discarding stale session response (generation mismatch)"),null;if(!c)return console.log(`[AgentSession] No existing session for ${e}/${r??"<null>"} — placeholder`),l(null),h("stopped"),d([]),D.current={entries:[],status:"stopped"},g(!0),null;return console.log(`[AgentSession] REST response: sessionId=${c.id}, msgCount=${u?.length??0}, status=${c.status}, explicitSessionIdRequested=${o??"<null>"}`),SB.set(a,c),o&&SB.set(SL(e,r,c.id),c),l(c),h(c.status),u&&u.length>0&&(d(u),D.current={entries:[...u],status:c.status}),K(c.id),O.current?.(c),c}catch(e){if(console.error("[AgentSession] startSession error:",e),P.current!==n)return console.log("[AgentSession] Discarding error (generation mismatch)"),null;return y(e instanceof Error?e.message:"Failed to start session"),B.current=!0,null}finally{L.current=!1,P.current===n&&v(!1)}},[e,r,i,o,K]),Y=(0,$.useCallback)(async(s,i)=>{let n=i||a?.id;if(!n)return void console.warn("[AgentSession] sendMessage: no session ID available (sessionId param:",i,", session?.id:",a?.id,")");if(("string"!=typeof s||s.trim())&&(!Array.isArray(s)||0!==s.length)){console.log(`[AgentSession] sendMessage: targetSessionId=${n}, source=${i?"explicit":"state"}`);try{let e="string"==typeof s?s.trim():s;await SE(n,e)}catch(i){let s=i instanceof Error?i.message:"Failed to send message";console.error("[AgentSession] Failed to send message:",s),s.includes("[404]")&&(e&&(SB.delete(SL(e,r,o)),a?.id&&SB.delete(SL(e,r,a.id))),l(null),h("stopped"),g(!1),R.current=!0),y(s),gK.toast.error("Failed to send message",{description:s})}}},[a?.id,e,r,o]),G=(0,$.useCallback)(async(e,r)=>{let s=r||a?.id;if(!s)throw Error("No session id available for paste upload");return SR(s,e)},[a?.id]),X=(0,$.useCallback)(async()=>{if(a?.id)try{await SF(a.id)}catch(e){e instanceof Error&&e.message,console.error("[AgentSession] Failed to stop session:",e),gK.toast.error("Failed to stop session")}},[a?.id]),J=(0,$.useCallback)(async s=>{if(a?.id){e&&(SB.delete(SL(e,r,o)),SB.delete(SL(e,r,a.id))),v(!0),y(null);try{await SA(a.id,s),s&&l(e=>e?{...e,agentType:s}:null)}catch(e){y(e instanceof Error?e.message:"Failed to restart session"),console.error("[AgentSession] Failed to restart session:",e)}finally{v(!1)}}},[a?.id,e,r,o]),Z=(0,$.useCallback)(async s=>{if(!a?.id)return"No active session";y(null);try{return await SM(a.id,s),l(i=>{if(!i)return i;let n={...i,agentType:s};return e&&(SB.set(SL(e,r,o),n),SB.set(SL(e,r,n.id),n)),n}),null}catch(r){let e=r instanceof Error?r.message:"Failed to switch agent";return console.error("[AgentSession] Failed to switch agent:",r),e}},[a?.id,e,r,o]),Q=(0,$.useCallback)(async s=>{if(a?.id){y(null);try{await ST(a.id,s),l(i=>{if(!i)return i;let n={...i,permissionMode:s};return e&&(SB.set(SL(e,r,o),n),SB.set(SL(e,r,n.id),n)),n})}catch(e){y(e instanceof Error?e.message:"Failed to switch mode"),console.error("[AgentSession] Failed to switch mode:",e)}}},[a?.id,e,r,o]),ee=(0,$.useCallback)(async s=>{if(a?.id){y(null);try{await SP(a.id,s),l(s=>{if(!s)return s;let i={...s,permissionMode:"edit"};return e&&(SB.set(SL(e,r,o),i),SB.set(SL(e,r,i.id),i)),i})}catch(e){y(e instanceof Error?e.message:"Failed to accept plan"),console.error("[AgentSession] Failed to accept plan:",e)}}},[a?.id,e,r,o]),et=(0,$.useCallback)(async()=>{var i;let n;return e?(a?.id&&SB.delete(SL(e,r,a.id)),SB.delete(SL(e,r,o)),S.current&&(S.current.close(1e3,"new-conversation"),S.current=null,C.current=null),k.current&&(clearTimeout(k.current),k.current=null),M.current&&(clearTimeout(M.current),M.current=null),E.current=!1,T.current=!1,p(!1),l(null),h("stopped"),g(!0),y(null),w(null),d([]),D.current={entries:[],status:"stopped"},i=Sj(e,r,s),(n=new Map(Sv)).set(i,Date.now()),Sx(Sv=n),Sb(),null):null},[e,r,s,a?.id,o]),er=(0,$.useCallback)(async n=>{if(!e)return null;if(a)return a;v(!0),y(null);try{let a;try{a=await (0,rx.createNewAgentSession)(e,r,n,i)}catch(s){if(s instanceof rx.ResidentLimitError){if(!window.confirm(`All ${s.maxResidentAgentProcesses} resident agent processes for this workspace branch are running. Stop the least recently active running session in this branch and start a new conversation?`))throw s;a=await (0,rx.createNewAgentSession)(e,r,n,i,!0)}else throw s}let c={id:a.session.id,projectId:a.session.projectId,branch:a.session.branch,status:a.session.status,permissionMode:a.session.permissionMode??"edit",agentType:a.session.agentType??"claude-code",processAlive:a.session.processAlive??!0};return SB.set(SL(e,r,o),c),SB.set(SL(e,r,c.id),c),l(c),h(c.status),g(!0),Sk(Sj(e,r,s)),K(c.id),O.current?.(c),c}catch(e){return y(e instanceof Error?e.message:"Failed to create session"),console.error("[AgentSession] ensureSession:",e),null}finally{v(!1)}},[e,r,s,i,a,o,K]);return(0,$.useEffect)(()=>()=>{S.current&&(E.current=!0,S.current.close(),C.current=null),k.current&&clearTimeout(k.current),M.current&&clearTimeout(M.current)},[]),(0,$.useEffect)(()=>{S.current&&(S.current.close(1e3,"branch-switch"),S.current=null,C.current=null),k.current&&(clearTimeout(k.current),k.current=null),M.current&&(clearTimeout(M.current),M.current=null),P.current+=1;let i=e?Sj(e,r,s):null;i&&o&&Sk(i);let n=!o&&null!==i&&Sv.has(i);l(null),h("stopped"),p(!1),g(n),y(null),v(!1),w(null),d([]),D.current={entries:[],status:"stopped"},E.current=!1,N.current=0,A.current=null,F.current=0,B.current=!1,L.current=!1,R.current=!n,e&&SB.delete(SL(e,r,o))},[e,r,s,o]),(0,$.useEffect)(()=>{var i;let n=null!==e&&(i=Sj(e,r,s),Sv.has(i));!R.current||!e||a||x||B.current||n||(R.current=!1,console.log(`[AgentSession] Auto-start: projectId=${e}, branch=${r}, agentMode=${s}`),V())},[e,r,s,a,x,V]),(0,$.useEffect)(()=>{let e=()=>{if("visible"===document.visibilityState&&a?.id&&!E.current){let e=S.current;e&&e.readyState!==WebSocket.CLOSED&&e.readyState!==WebSocket.CLOSING||(console.log("[AgentSession] Tab visible, WebSocket disconnected - reconnecting"),N.current=0,F.current=0,k.current&&(clearTimeout(k.current),k.current=null),K(a.id))}};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[a?.id,K]),(0,$.useEffect)(()=>{a?.id&&!E.current&&K(a.id)},[a?.id,K]),{session:a,messages:c,status:u,isConnected:f,isInitialized:m,isLoading:x,error:_,remoteStatus:b,startSession:V,sendMessage:Y,uploadPaste:G,stopSession:X,restartSession:J,switchAgentType:Z,startNewConversation:et,ensureSession:er,switchMode:Q,acceptPlan:ee}}(e,r,n?.agent_mode,M,{sessionId:s,onTaskCompleted:a,onSessionStarted:l,onTitleUpdated:(e,r)=>{let s=r??J?.id;s&&e&&(U({sessionId:s,title:e}),c?.(s,e)),L(e=>e+1),O(null)}});f=J?.id??null,(0,aj.useGlobalEventStream)(s=>{"session:status"!==s.type||"running"!==s.status||!e||s.projectId!==e||(s.branch??null)!==(r??null)||s.sessionId&&s.sessionId!==f&&(e=>i?.(e))(s.sessionId)}),(0,$.useEffect)(()=>{(0,rx.getAgentProviders)().then(P).catch(()=>{})},[]),(0,$.useEffect)(()=>{J?.permissionMode&&j(J.permissionMode)},[J?.permissionMode]),(0,$.useEffect)(()=>{J?.agentType&&F(J.agentType)},[J?.agentType]),(0,$.useEffect)(()=>{b([]),S(1)},[e,r]);let ef=(0,$.useRef)({sessionId:null,count:0});(0,$.useEffect)(()=>{let e=J?.id??null,r=ef.current;e&&r.sessionId===e&&0===r.count&&Z.length>0&&O(e),ef.current={sessionId:e,count:Z.length}},[J?.id,Z.length]),(0,$.useEffect)(()=>{I&&J?.id!==I&&O(null)},[J?.id,I]),(0,$.useEffect)(()=>{H&&J?.id!==H.sessionId&&U(null)},[J?.id,H]),(0,$.useEffect)(()=>{if(!H)return;let e=setTimeout(()=>{U(e=>e===H?null:e)},5e3);return()=>clearTimeout(e)},[H]),(0,$.useEffect)(()=>{if(!I)return;let e=setTimeout(()=>{O(e=>e===I?null:e)},3e4);return()=>clearTimeout(e)},[I]);let[ep,em]=(0,$.useState)(!1);(0,$.useEffect)(()=>{em(!1)},[J?.id]),(0,$.useEffect)(()=>{ee&&em(!0)},[ee]);let eg=async e=>{j(e),J&&await eu(e)},ex=async e=>{await eh(e),j("edit"),d?.()},[ev,e_]=(0,$.useState)(!1),eb=async e=>{if(J&&!ev){e_(!0);try{let r=await (0,rx.branchAgentSession)(J.id,e);L(e=>e+1),i?.(r.session.id)}catch(r){let e=r instanceof Error?r.message:"Failed to branch conversation";gK.toast.error("Branch failed",{description:e})}finally{e_(!1)}}},ew=T.find(e=>e.type===M)?.displayName??("codex"===M?"Codex":"Claude Code"),eS=T.filter(e=>e.available).filter(e=>e.type!==M),eC=(0,$.useCallback)(e=>{var r,s;let i;_((r=v,s=e,i=0===r.length||r.endsWith("\n\n")?"":r.endsWith("\n")?"\n":"\n\n",r+i+(s.replace(/\r?\n/g,"\n").split("\n").map(e=>`> ${e}`).join("\n")+"\n\n"))),requestAnimationFrame(()=>{let e=V.current?.querySelector("textarea");if(!e)return;e.focus();let r=e.value.length;try{e.setSelectionRange(r,r)}catch{}})},[_,v]);(0,$.useImperativeHandle)(h,()=>({submitMessage:async e=>{if(d?.(),J)en(e);else{let r=await ed(C);r&&(O(r.id),en(e,r.id))}}}),[J,ed,en,C,d]);let ej=(0,$.useCallback)((e,r)=>{if(r.length<=2e3)return;e.preventDefault();let s=e.currentTarget,i=s.selectionStart??v.length,n=s.selectionEnd??v.length,o=new TextEncoder().encode(r).length,a=kr(w,o);_(v.slice(0,i)+a+v.slice(n)),b(e=>[...e,{id:w,content:r,size:o}]),S(w+1);let l=i+a.length;requestAnimationFrame(()=>{try{s.setSelectionRange(l,l)}catch{}})},[v,w,_]);async function ek(e,r,s,i){let n=new Set;for(let r of e.matchAll(kt))n.add(Number(r[1]));let o=r.filter(e=>n.has(e.id));if(0===o.length)return e;let a=e;for(let e of o){let r=await s(e.content,i),n=kr(e.id,e.size),o=`<vpaste path="${r.path}" size="${r.size}" />`;a=a.split(n).join(o)}return a}let eN=async e=>{let r=e.text,s=e.files.length>0,i=y.length>0,n=r.trim();if(n||s){A(!0);try{let o;_(""),Y.push(n),d?.();let a=J?.id,l=null;if(!J){if(!(l=await ed(C)))return void _(r);a=l.id,O(l.id)}let c=n;if(i)try{c=(await ek(r,y,eo,a)).trim()}catch(s){let e=s instanceof Error?s.message:"Failed to upload paste";gK.toast.error("Paste upload failed",{description:e}),_(r);return}if(c.length>2e3)try{let e=await eo(c,a);c=`<vpaste path="${e.path}" size="${e.size}" />`}catch(s){let e=s instanceof Error?s.message:"Failed to upload paste";gK.toast.error("Paste upload failed",{description:e}),_(r);return}if(b([]),S(1),s){let r=[];for(let s of(c&&r.push({type:"text",text:c}),e.files))if(s.mediaType&&s.url){let e=s.url.match(/^data:[^;]+;base64,(.+)$/);e&&r.push({type:"image",mediaType:s.mediaType,data:e[1]})}o=r}else o=c;if(k){let e="string"==typeof o?o:o.filter(e=>"text"===e.type).map(e=>e.text).join("\n");if(e.trim()){E(!0);try{let s=await (0,rx.translateText)(e);if(s.error){_(r),b(y),S(w),gK.toast.error("Translation failed",{description:"Disable translation to send the original text."});return}o="string"==typeof o?s.translatedText:o.map(e=>"text"===e.type?{...e,text:s.translatedText}:e)}catch{_(r),b(y),S(w),gK.toast.error("Translation failed",{description:"Disable translation to send the original text."});return}finally{E(!1)}}}l?(console.log(`[AgentConversation] handleSubmit: using freshly started session ${l.id}`),await en(o,l.id)):(console.log(`[AgentConversation] handleSubmit: existing session ${J.id}, status=${Q}`),await en(o))}finally{A(!1)}}},{settings:eD}=(0,cz.useConversationSettings)();return e?(0,z.jsxs)("div",{className:"h-full flex flex-col min-h-0",style:{"--conv-font-size":`${eD.agentFontSize}px`},children:[(0,z.jsxs)("div",{className:"flex-shrink-0 flex items-center justify-between px-4 h-10 border-b border-border/60 bg-muted/20",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2",children:[T.length>1?(0,z.jsxs)(of,{children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsxs)("button",{disabled:er||"running"===Q&&Z.length>0,className:(0,ey.cn)("inline-flex items-center gap-1 rounded-md border bg-muted/50 px-2 py-0.5 text-xs font-medium transition-colors hover:bg-muted",(er||"running"===Q&&Z.length>0)&&"opacity-50 cursor-not-allowed"),children:[T.find(e=>e.type===M)?.displayName??("codex"===M?"Codex":"Claude Code"),(0,z.jsx)(sb,{className:"h-3 w-3 text-muted-foreground"})]})}),(0,z.jsx)(om,{align:"start",children:(0,z.jsx)(ov,{value:M,onValueChange:async e=>{if(!J)return void F(e);let r=await el(e);r?gK.toast.error("Failed to switch agent",{description:r}):F(e)},children:T.map(e=>(0,z.jsx)(o_,{value:e.type,disabled:!e.available,className:"text-xs pl-2 [&>span:first-child]:hidden data-[state=checked]:bg-accent data-[state=checked]:text-accent-foreground",children:e.displayName},e.type))})})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(oN,{className:`h-4 w-4 ${"codex"===M?"text-green-500":"text-violet-500"}`}),(0,z.jsx)("span",{className:"text-sm font-medium",children:"codex"===M?"Codex":"Claude Code"})]}),(0,z.jsx)(jZ,{mode:C,onModeChange:eg}),X.length>=1&&o&&(0,z.jsx)(oj,{targets:X,activeTarget:n?.agent_mode??"local",onTargetChange:o}),J&&(p=J.id.startsWith("remote-"),m="text-muted-foreground",g=(0,z.jsx)(jV,{className:"h-3 w-3"}),x="Disconnected",ee?p&&"connected"!==ei&&null!==ei?"reconnecting"===ei?(m="text-amber-500",g=(0,z.jsx)(jq,{className:"h-3 w-3 animate-pulse"}),x="Reconnecting..."):"disconnected"===ei&&(m="text-red-500",g=(0,z.jsx)(jV,{className:"h-3 w-3"}),x="Remote disconnected"):(m="text-green-500",g=(0,z.jsx)(jq,{className:"h-3 w-3"}),x="Connected"):ep||(m="text-amber-500",g=(0,z.jsx)(jq,{className:"h-3 w-3 animate-pulse"}),x="Connecting..."),(0,z.jsxs)("span",{className:`flex items-center gap-1 text-xs ${m}`,children:[g,x]}))]}),(0,z.jsxs)("div",{className:"flex items-center gap-1",children:[e&&(0,z.jsx)(j3,{projectId:e,branch:r,currentSessionId:J?.id??null,refreshKey:B,pendingTitleSessionId:I,aiTitleOverride:H,onSwitch:e=>{i?.(e)},onDelete:(e,r)=>{if(e===J?.id){let e=r[0];i?.(e?e.id:null)}}}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",onClick:async()=>{await ec(),u?.(),i?.(null)},disabled:er||!J,className:"h-7 w-7",title:"New Conversation",children:(0,z.jsx)(jY,{className:"h-3.5 w-3.5"})}),(0,z.jsxs)(W.Button,{variant:"ghost",size:"sm",onClick:()=>ea(),disabled:"running"!==Q,className:"h-7 text-xs",children:[(0,z.jsx)(d6,{className:"h-3 w-3 mr-1"}),"Stop"]})]})]}),(0,z.jsxs)("div",{className:"flex-1 min-h-0 relative",children:[(0,z.jsxs)(C7,{className:"h-full",initial:"instant",children:[(0,z.jsxs)(C9,{className:"gap-1 p-4",scrollClassName:"edge-scrollbar",children:[J||0!==Z.length?(0,z.jsxs)(j9.Provider,{value:{sendMessage:en,messages:Z,acceptPlan:ex,permissionMode:J?.permissionMode??C,agentType:J?.agentType??M,sessionId:J?.id??null},children:[(0,z.jsxs)("div",{className:"space-y-1 outline-none",ref:K,tabIndex:-1,onKeyDown:q,children:[Z.map((e,r)=>(0,z.jsx)("div",{"data-message-idx":r,..."user"===e.type?{"data-user-msg-idx":r}:{},className:"scroll-mt-2",children:(0,z.jsx)(CW,{message:e,messageIndex:r})},r)),er&&(0,z.jsxs)("div",{className:"flex items-center gap-2 py-4 text-muted-foreground",children:[(0,z.jsx)(jK,{className:"h-4 w-4"}),(0,z.jsx)("span",{className:"text-sm",children:"Connecting to agent..."})]})]}),J&&"running"!==Q&&!er&&Z.length>0&&(0,z.jsx)("div",{className:"mt-3 border-t border-border/50 pt-1.5 pb-1",children:(0,z.jsxs)(of,{children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:(0,ey.cn)("h-7 w-7 rounded-md text-muted-foreground transition-colors","hover:bg-muted hover:text-foreground"),disabled:ev,"aria-label":"Branch conversation",children:ev?(0,z.jsx)(rj,{className:"h-4 w-4 animate-spin"}):(0,z.jsx)(jX,{className:"h-4 w-4"})})}),(0,z.jsxs)(om,{align:"start",className:"w-44 p-1.5",children:[(0,z.jsx)(oy,{className:"px-2 py-1.5",children:(0,z.jsx)("div",{className:"text-xs font-medium",children:"Branch conversation"})}),(0,z.jsxs)(og,{className:"h-8 cursor-pointer items-center gap-2 rounded-md px-2 text-xs",onSelect:()=>eb(),children:[(0,z.jsx)("div",{className:(0,ey.cn)("flex h-5 w-5 shrink-0 items-center justify-center rounded-full","codex"===M?"bg-emerald-500/10 text-emerald-600":"bg-violet-500/10 text-violet-600"),children:(0,z.jsx)(oN,{className:"h-3 w-3"})}),(0,z.jsx)("span",{className:"min-w-0 flex-1 truncate",children:ew}),(0,z.jsx)("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:"current"})]}),eS.length>0&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(ob,{className:"my-1"}),eS.map(e=>(0,z.jsxs)(og,{className:"h-8 cursor-pointer items-center gap-2 rounded-md px-2 text-xs",onSelect:()=>eb(e.type),children:[(0,z.jsx)("div",{className:(0,ey.cn)("flex h-5 w-5 shrink-0 items-center justify-center rounded-full","codex"===e.type?"bg-emerald-500/10 text-emerald-600":"bg-violet-500/10 text-violet-600"),children:(0,z.jsx)(oN,{className:"h-3 w-3"})}),(0,z.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.displayName})]},e.type))]})]})]})})]}):(0,z.jsx)("div",{className:"text-center py-16",children:er||e&&!et?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(jK,{className:"h-6 w-6 mx-auto mb-4"}),(0,z.jsx)("h3",{className:"text-sm font-semibold mb-1 text-foreground",children:"Connecting to agent..."}),(0,z.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:"Setting up the session for this worktree"})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)("div",{className:"mx-auto w-12 h-12 rounded-xl bg-primary/10 flex items-center justify-center mb-4",children:(0,z.jsx)(oN,{className:"h-6 w-6 text-primary/60"})}),(0,z.jsx)("h3",{className:"text-sm font-semibold mb-1 text-foreground",children:"Start a conversation"}),(0,z.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:"Ask the agent to help you with coding tasks in this worktree"})]})}),es&&(0,z.jsxs)("div",{className:"flex items-center gap-2 p-3 bg-red-500/10 rounded-lg text-red-500 text-sm mt-4",children:[(0,z.jsx)(SW,{className:"h-4 w-4"}),es]})]}),(0,z.jsx)(je,{})]}),(0,z.jsx)(j2,{messages:Z,contentRef:K}),(0,z.jsx)(j8,{containerRef:K,onQuote:eC})]}),(0,z.jsx)("div",{className:"flex-shrink-0 border-t border-border/60 p-3",children:(0,z.jsxs)(jF,{onSubmit:eN,accept:"image/*",className:"w-full",children:[(0,z.jsx)(j7,{}),(0,z.jsxs)("div",{className:"relative flex w-full flex-col",children:[k&&(0,z.jsx)("div",{className:"flex items-center pl-12 pr-2 pt-1.5 pb-0.5",children:(0,z.jsxs)("button",{type:"button",onClick:()=>N(!1),className:"inline-flex shrink-0 items-center gap-1.5 rounded-full bg-blue-500/10 text-blue-600 dark:text-blue-400 px-2.5 py-0.5 text-xs font-medium hover:bg-blue-500/20 transition-colors",children:[D?(0,z.jsx)(rj,{className:"size-3 animate-spin"}):(0,z.jsx)(jG,{className:"size-3"}),"Translate",(0,z.jsx)(t8,{className:"size-3"})]})}),(0,z.jsxs)("div",{className:"flex w-full items-center",children:[(0,z.jsxs)(jL,{children:[(0,z.jsx)(jI,{className:"ml-1"}),(0,z.jsxs)(jO,{children:[(0,z.jsx)(jM,{label:"Add images"}),(0,z.jsxs)(jz,{onSelect:()=>{N(!k)},children:[(0,z.jsx)(jG,{className:"mr-2 size-4"}),k?"Disable translation":"Translate"]})]})]}),(0,z.jsx)("div",{ref:V,className:"contents",children:(0,z.jsx)(jT,{value:v,onChange:e=>_(e.target.value),onPasteText:ej,onKeyDown:Y.handleKeyDown,placeholder:J?"Ask the agent to help with your code...":"Type your first message to start...",className:"pr-12"})}),(0,z.jsx)(j$,{className:"absolute bottom-1 right-1",disabled:!v.trim()&&!er||D||R,status:R||D?"submitted":er?"streaming":"ready"})]})]})]})})]}):(0,z.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,z.jsxs)("div",{className:"text-center",children:[(0,z.jsx)("div",{className:"mx-auto w-10 h-10 rounded-xl bg-muted flex items-center justify-center mb-3",children:(0,z.jsx)(oN,{className:"h-5 w-5 text-muted-foreground/50"})}),(0,z.jsx)("p",{className:"text-sm",children:"Select a project to start coding"})]})})});function ki(){return"localhost"===window.location.hostname&&"3000"===window.location.port?"http://localhost:5173":""}async function kn(e,r){let s=await (0,rx.authFetch)(`${ki()}/api/projects/${e}/chat-sessions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branch:r})});if(!s.ok)throw Error("Failed to create chat session");return s.json()}async function ko(e,r){if(!(await (0,rx.authFetch)(`${ki()}/api/chat-sessions/${e}/message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:r})})).ok)throw Error("Failed to send message")}async function ka(e){if(!(await (0,rx.authFetch)(`${ki()}/api/chat-sessions/${e}/stop`,{method:"POST"})).ok)throw Error("Failed to stop generation")}let kl=new Map;function kc(e,r){return`chat:${e}:${r??""}`}function kd({sessionId:e,approvalId:r,tool:s,input:i,resolved:n}){let[o,a]=(0,$.useState)(null),l=function(e){if(null!==e&&"object"==typeof e){if("string"==typeof e.message)return e.message;if("string"==typeof e.prompt)return e.prompt}return JSON.stringify(e)}(i),c=async s=>{if(!o&&!n){a(s?"approve":"deny");try{await rx.api.chatToolApproval(e,r,s)}finally{a(null)}}};return(0,z.jsx)("div",{className:"mx-4 my-1",children:(0,z.jsxs)("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 space-y-2",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2",children:[(0,z.jsx)(oN,{className:"h-3.5 w-3.5 text-amber-500 shrink-0"}),(0,z.jsxs)("span",{className:"text-xs font-medium text-amber-600 dark:text-amber-400",children:["Approval needed · ","spawnAgentSession"===s?"Start a new coding agent":"Send to the coding agent"]})]}),(0,z.jsx)("pre",{className:"bg-muted/50 p-2 rounded overflow-x-auto max-w-full whitespace-pre-wrap break-all text-foreground/80",style:{fontSize:"var(--conv-font-size, 12px)"},children:l}),n?(0,z.jsxs)(sy,{variant:"default",className:"approved"===n?"bg-green-600 hover:bg-green-700 text-white":"bg-red-600 hover:bg-red-700 text-white",children:["approved"===n?(0,z.jsx)(rS,{className:"h-3 w-3 mr-1"}):(0,z.jsx)(rC,{className:"h-3 w-3 mr-1"}),"approved"===n?"Approved — sent.":"Denied — not sent."]}):(0,z.jsxs)("div",{className:"flex gap-2",children:[(0,z.jsxs)(W.Button,{onClick:()=>c(!0),disabled:null!==o,className:"bg-green-600 hover:bg-green-700 text-white",size:"sm",children:["approve"===o?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,z.jsx)(rS,{className:"h-3.5 w-3.5 mr-1"}),"Approve"]}),(0,z.jsxs)(W.Button,{onClick:()=>c(!1),disabled:null!==o,variant:"destructive",size:"sm",children:["deny"===o?(0,z.jsx)(rj,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):(0,z.jsx)(rC,{className:"h-3.5 w-3.5 mr-1"}),"Deny"]})]})]})})}let ku=(0,ew.default)("radio",[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]),kh=(0,ew.default)("triangle-alert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);function kf({messages:e}){let{scrollToBottom:r}=C8(),s=(0,$.useRef)(e.length);return(0,$.useEffect)(()=>{let i=s.current;if(s.current=e.length,!(e.length<=i))for(let s=i;s<e.length;s++){let i=e[s];if("user"===i.type&&i.content.startsWith("[Executor Event:"))return void r({animation:"instant"})}},[e,r]),null}let kp=(0,$.forwardRef)(function({projectId:e,branch:r},s){let{session:i,messages:n,status:o,isInitialized:a,isLoading:l,error:c,sendMessage:d,stopGeneration:u,restartSession:h}=function(e,r){let[s,i]=(0,$.useState)(null),[n,o]=(0,$.useState)([]),[a,l]=(0,$.useState)("stopped"),[c,d]=(0,$.useState)(!1),[u,h]=(0,$.useState)(!1),[f,p]=(0,$.useState)(!1),[m,g]=(0,$.useState)(null),x=(0,$.useRef)(null),v=(0,$.useRef)(()=>{}),_=(0,$.useRef)(null),y=(0,$.useRef)(0),b=(0,$.useRef)({entries:[],status:"stopped"}),w=(0,$.useRef)(!1),S=(0,$.useRef)(!0),C=(0,$.useRef)(!1),j=(0,$.useRef)(0),k=(0,$.useRef)(null),N=(0,$.useRef)(null),D=(0,$.useRef)(0),E=(0,$.useRef)(!1),R=(0,$.useCallback)((e,r=!1)=>{x.current?.readyState!==WebSocket.OPEN&&x.current?.readyState!==WebSocket.CONNECTING&&(0,rx.getFreshToken)(r?{skipCache:!0}:void 0).then(()=>v.current(e))},[]),A=(0,$.useCallback)(n=>{if(x.current?.readyState===WebSocket.OPEN||x.current?.readyState===WebSocket.CONNECTING)return;b.current={entries:[],status:"stopped"},w.current=!1,C.current=!0;let a=new WebSocket((0,rx.getWebSocketUrl)(`/api/chat-sessions/${n}/stream`));x.current=a;let c=j.current;a.onopen=()=>{d(!0),g(null),k.current=Date.now(),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{y.current=0,D.current=0},5e3)},a.onmessage=s=>{if(c===j.current)try{let c=JSON.parse(s.data);if("JsonPatch"in c){var i,n;let e=b.current.entries.filter(Boolean).length;i=b.current,n=c.JsonPatch,b.current=Sm(i,e=>{for(let r of n){let{op:s,path:i,value:n}=r;if("/entries"===i&&"replace"===s&&n?.type==="ENTRY"&&n.content?.type==="system"&&n.content?.content==="__CLEAR_ALL__"){e.entries=[];continue}if(i.startsWith("/entries/")){let r=parseInt(i.replace("/entries/",""),10);if(isNaN(r)||n?.type!=="ENTRY")continue;switch(s){case"add":for(;e.entries.length<=r;)e.entries.push(null);e.entries[r]=n.content;break;case"replace":r<e.entries.length&&(e.entries[r]=n.content);break;case"remove":r<e.entries.length&&e.entries.splice(r,1)}}else"/status"===i&&n?.type==="STATUS"&&(e.status=n.content)}});let r=b.current.entries.filter(Boolean).length;C.current?r!==e&&console.log(`[ChatSession] WS patch added message (${e} → ${r}) but isReplaying=true, state NOT updated`):(r!==e&&console.log(`[ChatSession] New message via WS patch (${e} → ${r}), calling setMessages`),o([...b.current.entries.filter(Boolean)]),l(b.current.status));return}if("Ready"in c){C.current=!1;let e=b.current.entries.filter(Boolean).length;console.log(`[ChatSession] Ready received, isReplaying → false, ${e} messages`),o([...b.current.entries.filter(Boolean)]),l(b.current.status),h(!0);return}if("finished"in c){w.current=!0,a.close(1e3,"finished");return}if("openPreviewFrame"in c)return void(0,_r.openPreviewFrame)(c.openPreviewFrame.projectId,c.openPreviewFrame.url);if("browserCommand"in c){let r=c.browserCommand;e&&(0,_r.sendCommandToIframe)(e,{type:"vibedeckx-command",...r}).then(e=>{e&&a.readyState===WebSocket.OPEN&&a.send(JSON.stringify({type:"browser_result",result:{id:r.id,success:e.success??!1,error:e.error,content:e.content,found:e.found,tag:e.tag,text:e.text}}))});return}if("error"in c){g(c.error),"Session not found"===c.error&&(e&&kl.delete(kc(e,r)),w.current=!0);return}}catch(e){console.error("[ChatSession] Failed to parse message:",e)}},a.onclose=n=>{let o,a;if(c!==j.current)return;d(!1),x.current=null,N.current&&(clearTimeout(N.current),N.current=null);let l=4e3===n.code,u=k.current?Date.now()-k.current:0;if(k.current=null,!l&&u>0&&u<5e3){if(D.current++,D.current>=3)return E.current?void g("Unable to connect to remote server. Please check the server configuration."):(e&&kl.delete(kc(e,r)),i(null),g(null),y.current=0,D.current=0,void(S.current=!0))}else u>=5e3&&(D.current=0);if(w.current||1e3===n.code)return;if(y.current>=10)return void g("Unable to connect to server.");let h=(a=(o=Math.min(3e4,1e3*Math.pow(2,y.current)))*Math.random()*.25,o+a);y.current++,_.current=setTimeout(()=>{s?.id&&!w.current&&R(s.id,!0)},h)},a.onerror=()=>{}},[s?.id,R]);(0,$.useEffect)(()=>{v.current=A},[A]);let M=(0,$.useCallback)(async()=>{if(!e)return null;let s=j.current;g(null),h(!1),E.current=!1;let n=kc(e,r),a=kl.get(n);if(a)return i(a),l(a.status),R(a.id),a;p(!0);try{let{session:a,messages:c}=await kn(e,r);if(j.current!==s)return null;return kl.set(n,a),i(a),l(a.status),c&&c.length>0&&o(c),R(a.id),a}catch(e){if(j.current!==s)return null;return g(e instanceof Error?e.message:"Failed to start session"),E.current=!0,null}finally{j.current===s&&p(!1)}},[e,r,R]),F=(0,$.useCallback)(async e=>{let r=s?.id;if(r&&e.trim())try{await ko(r,e.trim())}catch(r){let e=r instanceof Error?r.message:"Failed to send message";g(e),gK.toast.error("Failed to send message",{description:e})}},[s?.id]),T=(0,$.useCallback)(async()=>{if(s?.id)try{await ka(s.id)}catch(e){console.error("[ChatSession] Failed to stop generation:",e)}},[s?.id]),P=(0,$.useCallback)(async()=>{if(s?.id)try{await rx.api.resetChatSession(s.id),o([]),l("stopped"),b.current={entries:[],status:"stopped"}}catch(e){console.error("[ChatSession] Failed to reset session:",e),gK.toast.error("Failed to start new conversation")}},[s?.id]);return(0,$.useEffect)(()=>()=>{x.current&&(w.current=!0,x.current.close()),_.current&&clearTimeout(_.current),N.current&&clearTimeout(N.current)},[]),(0,$.useEffect)(()=>{x.current&&(x.current.close(1e3,"branch-switch"),x.current=null),_.current&&(clearTimeout(_.current),_.current=null),N.current&&(clearTimeout(N.current),N.current=null),j.current+=1,i(null),l("stopped"),d(!1),h(!1),g(null),p(!1),b.current={entries:[],status:"stopped"},w.current=!1,y.current=0,k.current=null,D.current=0,E.current=!1,S.current=!0},[e,r]),(0,$.useEffect)(()=>{!S.current||!e||s||f||E.current||(S.current=!1,M())},[e,s,f,M]),(0,$.useEffect)(()=>{!s?.id||c||w.current||R(s.id)},[s?.id,c,R]),(0,$.useEffect)(()=>{let e=()=>{if("visible"!==document.visibilityState||!s?.id||w.current)return;let e=x.current,r=b.current.entries.filter(Boolean).length;console.log(`[ChatSession] Tab visible: ws.readyState=${e?.readyState??"null"}, isReplaying=${C.current}, messages=${r}`),e&&e.readyState===WebSocket.OPEN&&e.close(4e3,"visibility-recovery")};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[s?.id]),{session:s,messages:n,status:a,isConnected:c,isInitialized:u,isLoading:f,error:m,sendMessage:F,stopGeneration:T,restartSession:P}}(e,r),{settings:f}=(0,cz.useConversationSettings)();(0,$.useImperativeHandle)(s,()=>({sendMessage:async e=>{let r=e.trim();r&&await d(r)}}),[d]);let[p,m]=(0,$.useState)(""),[g,x]=(0,$.useState)(!1);(0,$.useEffect)(()=>{i?.eventListeningEnabled!=null&&x(i.eventListeningEnabled)},[i?.eventListeningEnabled]);let v="running"===o,_=(0,$.useCallback)(async e=>{let r=e.text.trim();r&&(m(""),await d(r))},[d]);return e?(0,z.jsxs)("div",{className:"h-full flex flex-col min-h-0",style:{"--conv-font-size":`${f.chatFontSize}px`},children:[(0,z.jsxs)("div",{className:"flex-shrink-0 flex items-center justify-between px-4 h-10 border-b border-border/60 bg-muted/20",children:[(0,z.jsxs)("div",{className:"flex items-center gap-2",children:[(0,z.jsx)(gY,{className:"h-3.5 w-3.5 text-primary"}),(0,z.jsx)("span",{className:"text-xs font-medium text-foreground",children:"Main Chat"}),v&&(0,z.jsx)(rj,{className:"h-3 w-3 animate-spin text-primary/60"})]}),i&&(0,z.jsxs)("div",{className:"flex items-center gap-1",children:[(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",onClick:async()=>{let e=!g;try{await rx.api.setChatEventListening(i.id,e),x(e)}catch{gK.toast.error("Failed to toggle event listening")}},className:`h-7 w-7 ${g?"text-amber-500":""}`,title:g?"Listening to executor events (click to disable)":"Listen to executor events (click to enable)",children:(0,z.jsx)(ku,{className:"h-3.5 w-3.5"})}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",onClick:()=>h(),disabled:v,className:"h-7 w-7",title:"New Conversation",children:(0,z.jsx)(jY,{className:"h-3.5 w-3.5"})})]})]}),(0,z.jsxs)(C7,{className:"flex-1 min-h-0",initial:"instant",children:[(0,z.jsx)(kf,{messages:n}),(0,z.jsxs)(C9,{className:"gap-4 p-4",children:[l&&0===n.length&&(0,z.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,z.jsx)(rj,{className:"h-6 w-6 animate-spin text-muted-foreground"})}),!l&&a&&0===n.length&&(0,z.jsxs)("div",{className:"text-center py-16",children:[(0,z.jsx)("div",{className:"mx-auto w-12 h-12 rounded-xl bg-primary/10 flex items-center justify-center mb-4",children:(0,z.jsx)(gY,{className:"h-6 w-6 text-primary/60"})}),(0,z.jsx)("h3",{className:"text-sm font-semibold mb-1 text-foreground",children:"Start a conversation"}),(0,z.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:"Chat with the AI assistant about your project"})]}),n.map((e,r)=>{if("turn_end"===e.type)return(0,z.jsxs)("div",{className:"mx-4 my-3 flex items-center gap-2","aria-hidden":!0,children:[(0,z.jsx)("div",{className:"h-px flex-1 bg-border"}),(0,z.jsx)("div",{className:"h-1 w-1 shrink-0 rounded-full bg-border"}),(0,z.jsx)("div",{className:"h-px flex-1 bg-border"})]},r);if("user"===e.type&&e.content.startsWith("[System Invariant Violation]")){let s=e.content.replace(/^\[System Invariant Violation\]\n?/,"");return(0,z.jsxs)("div",{className:"mx-4 my-2 flex gap-2 rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2",children:[(0,z.jsx)(kh,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-500"}),(0,z.jsxs)("div",{className:"min-w-0",children:[(0,z.jsx)("div",{className:"text-xs font-medium text-amber-600 dark:text-amber-400",children:"System invariant correction"}),(0,z.jsx)("div",{className:"mt-0.5 whitespace-pre-wrap text-muted-foreground",style:{fontSize:"var(--conv-font-size, 12px)"},children:s})]})]},r)}return"user"===e.type?(0,z.jsx)(b9,{from:"user",children:(0,z.jsx)(we,{style:{fontSize:"var(--conv-font-size, 14px)"},children:e.content})},r):"assistant"===e.type?(0,z.jsx)(b9,{from:"assistant",children:(0,z.jsx)(we,{style:{fontSize:"var(--conv-font-size, 14px)"},children:(0,z.jsx)(wt,{children:e.content})})},r):"tool_use"===e.type?(0,z.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 text-xs text-muted-foreground",children:[(0,z.jsx)(_o,{className:"w-3.5 h-3.5 animate-pulse"}),(0,z.jsx)("span",{children:function(e){switch(e){case"getExecutorStatus":return"Checking executor status...";case"getAgentConversation":return"Checking agent conversation...";case"listTerminals":return"Listing terminals...";case"runInTerminal":return"Sending command to terminal...";case"spawnAgentSession":return"Starting a coding agent...";case"sendToAgentSession":return"Sending a message to the agent...";default:return`Running ${e}...`}}(e.tool)})]},r):"tool_result"===e.type?(0,z.jsx)("div",{className:"px-4 py-2",children:(0,z.jsxs)("details",{className:"text-xs text-muted-foreground",children:[(0,z.jsx)("summary",{className:"cursor-pointer hover:text-foreground",children:"Tool result"}),(0,z.jsx)("pre",{className:"mt-1 p-2 bg-muted/50 rounded overflow-x-auto whitespace-pre-wrap",style:{fontSize:"var(--conv-font-size, 12px)"},children:e.output})]})},r):"tool_approval_request"===e.type?i?(0,z.jsx)(kd,{sessionId:i.id,approvalId:e.approvalId,tool:e.tool,input:e.input,resolved:e.resolved},r):null:"error"===e.type?(0,z.jsx)("div",{className:"mx-auto max-w-[90%] rounded-lg border border-destructive/50 bg-destructive/10 px-4 py-3 text-destructive",style:{fontSize:"var(--conv-font-size, 14px)"},children:e.message},r):null}),c&&(0,z.jsx)("div",{className:"mx-auto max-w-[90%] rounded-lg border border-destructive/50 bg-destructive/10 px-4 py-3 text-sm text-destructive",children:c})]}),(0,z.jsx)(je,{})]}),(0,z.jsxs)("div",{className:"flex-shrink-0 border-t border-border/60 p-3",children:[v&&(0,z.jsx)("div",{className:"flex justify-center mb-2",children:(0,z.jsxs)(W.Button,{variant:"outline",size:"sm",onClick:u,className:"gap-1.5",children:[(0,z.jsx)(d6,{className:"h-3 w-3"}),"Stop generating"]})}),(0,z.jsxs)(jF,{onSubmit:_,className:"w-full",children:[(0,z.jsx)(jT,{disabled:!a||v,placeholder:a?v?"Waiting for response...":"Type a message...":"Connecting...",className:"pr-12",value:p,onChange:e=>m(e.currentTarget.value)}),(0,z.jsx)(j$,{className:"absolute bottom-1 right-1",disabled:!a||v||!p.trim()})]})]})]}):(0,z.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,z.jsxs)("div",{className:"text-center",children:[(0,z.jsx)("div",{className:"mx-auto w-10 h-10 rounded-xl bg-muted flex items-center justify-center mb-3",children:(0,z.jsx)(gY,{className:"h-5 w-5 text-muted-foreground/50"})}),(0,z.jsx)("p",{className:"text-sm",children:"Select a project to start chatting"})]})})}),km=(0,ew.default)("archive",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]),kg=(0,ew.default)("archive-restore",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]]);function kx({task:e,onUpdate:r,onDelete:s,onArchive:i,onUnarchive:n,archivedView:o,onClick:a,worktrees:l,assignedBranches:c,onAssign:d}){let[u,h]=(0,$.useState)(!1),[f,p]=(0,$.useState)(e.title),m=(0,$.useRef)(null);(0,$.useEffect)(()=>{u&&(m.current?.focus(),m.current?.select())},[u]),(0,$.useEffect)(()=>{p(e.title)},[e.title]);let g=()=>{h(!1);let s=f.trim();s&&s!==e.title?r(e.id,{title:s}):p(e.title)},x="done"===e.status||"cancelled"===e.status;return(0,z.jsxs)(lS,{className:"group cursor-pointer",onClick:()=>a?.(e),children:[(0,z.jsx)(lj,{className:"w-10",onClick:e=>e.stopPropagation(),children:(0,z.jsx)(eb,{checked:"done"===e.status,onCheckedChange:s=>{r(e.id,{status:s?"done":"todo"})}})}),(0,z.jsx)(lj,{className:"font-medium",children:u?(0,z.jsx)("input",{ref:m,className:"w-full bg-transparent border-b border-primary outline-none text-sm py-0.5",value:f,onChange:e=>p(e.target.value),onBlur:g,onClick:e=>e.stopPropagation(),onKeyDown:r=>{"Enter"===r.key&&g(),"Escape"===r.key&&(p(e.title),h(!1))}}):(0,z.jsxs)("div",{children:[(0,z.jsx)("span",{className:`cursor-pointer hover:underline text-sm ${x?"line-through text-muted-foreground":""}`,onClick:e=>{e.stopPropagation(),h(!0)},children:e.title}),e.description&&(0,z.jsx)("p",{className:"text-xs text-muted-foreground truncate max-w-[400px] mt-0.5",children:e.description.length>80?e.description.slice(0,80)+"...":e.description})]})}),(0,z.jsx)(lj,{onClick:e=>e.stopPropagation(),children:(0,z.jsxs)(of,{children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsx)("button",{className:"focus:outline-none",children:(0,z.jsx)(sy,{variant:"outline",className:`cursor-pointer text-xs ${af[e.status].color}`,children:af[e.status].label})})}),(0,z.jsx)(om,{align:"start",children:am.map(s=>(0,z.jsxs)(og,{onClick:()=>r(e.id,{status:s}),children:[(0,z.jsx)("span",{className:`inline-block w-2 h-2 rounded-full mr-2 ${af[s].color}`}),af[s].label]},s))})]})}),(0,z.jsx)(lj,{onClick:e=>e.stopPropagation(),children:(0,z.jsxs)(of,{children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsx)("button",{className:"focus:outline-none",children:(0,z.jsx)(sy,{variant:"outline",className:`cursor-pointer text-xs ${ap[e.priority].color}`,children:ap[e.priority].label})})}),(0,z.jsx)(om,{align:"start",children:ag.map(s=>(0,z.jsxs)(og,{onClick:()=>r(e.id,{priority:s}),children:[(0,z.jsx)("span",{className:`inline-block w-2 h-2 rounded-full mr-2 ${ap[s].color}`}),ap[s].label]},s))})]})}),(0,z.jsx)(lj,{onClick:e=>e.stopPropagation(),children:(0,z.jsxs)(of,{children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsx)("button",{className:"focus:outline-none",children:(0,z.jsxs)(sy,{variant:"outline",className:`cursor-pointer text-xs font-mono ${null!==e.assigned_branch?"bg-accent text-accent-foreground border-transparent":"text-muted-foreground"}`,children:[(0,z.jsx)(rb,{className:"h-3 w-3 mr-1"}),null!==e.assigned_branch?""===e.assigned_branch?"main":e.assigned_branch:"Unassigned"]})})}),(0,z.jsxs)(om,{align:"start",children:[null!==e.assigned_branch&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(og,{onClick:()=>d(e.id,null),children:"Unassign"}),(0,z.jsx)(ob,{})]}),l.filter(r=>{let s=null===r.branch?"":r.branch;return!(e.assigned_branch===s||c.has(s))}).map(r=>{let s=null===r.branch?"":r.branch,i=r.branch??"main";return(0,z.jsxs)(og,{onClick:()=>d(e.id,s),children:[(0,z.jsx)(rb,{className:"h-3 w-3 mr-2"}),i]},s)})]})]})}),(0,z.jsx)(lj,{className:"text-muted-foreground text-[10.5px] font-mono",children:new Date(e.created_at).toLocaleDateString()}),(0,z.jsx)(lj,{className:"w-10",onClick:e=>e.stopPropagation(),children:(0,z.jsxs)("div",{className:"flex items-center gap-0.5",children:[o?(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",title:"Unarchive",onClick:()=>n(e.id),children:(0,z.jsx)(kg,{className:"h-3.5 w-3.5 text-muted-foreground"})}):(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",title:"Archive",onClick:()=>i(e.id),children:(0,z.jsx)(km,{className:"h-3.5 w-3.5 text-muted-foreground"})}),(0,z.jsx)(W.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",title:"Delete",onClick:()=>s(e.id),children:(0,z.jsx)(rl,{className:"h-3.5 w-3.5 text-muted-foreground"})})]})})]})}let kv={todo:0,in_progress:1,done:2,cancelled:3},k_={urgent:0,high:1,medium:2,low:3};function ky({tasks:e,onUpdate:r,onDelete:s,onArchive:i,onUnarchive:n,archivedView:o,worktrees:a,onAssign:l}){let[c,d]=(0,$.useState)(null),[u,h]=(0,$.useState)("asc"),[f,p]=(0,$.useState)(null),[m,g]=(0,$.useState)(!1),x=e=>{c===e?h(e=>"asc"===e?"desc":"asc"):(d(e),h("asc"))},v=(0,$.useMemo)(()=>{if(!c)return e;let r="asc"===u?1:-1;return[...e].sort((e,s)=>{switch(c){case"title":return r*e.title.localeCompare(s.title);case"status":return r*(kv[e.status]-kv[s.status]);case"priority":return r*(k_[e.priority]-k_[s.priority]);case"created_at":return r*(new Date(e.created_at).getTime()-new Date(s.created_at).getTime());default:return 0}})},[e,c,u]),_=e=>c!==e?null:"asc"===u?" ↑":" ↓",y=(0,$.useMemo)(()=>new Set(e.filter(e=>null!==e.assigned_branch).map(e=>e.assigned_branch)),[e]);return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(ly,{children:[(0,z.jsx)(lb,{children:(0,z.jsxs)(lS,{children:[(0,z.jsx)(lC,{className:"w-10"}),(0,z.jsxs)(lC,{className:"cursor-pointer select-none",onClick:()=>x("title"),children:["Title",_("title")]}),(0,z.jsxs)(lC,{className:"cursor-pointer select-none w-32",onClick:()=>x("status"),children:["Status",_("status")]}),(0,z.jsxs)(lC,{className:"cursor-pointer select-none w-28",onClick:()=>x("priority"),children:["Priority",_("priority")]}),(0,z.jsx)(lC,{className:"w-32",children:"Assign"}),(0,z.jsxs)(lC,{className:"cursor-pointer select-none w-28",onClick:()=>x("created_at"),children:["Created",_("created_at")]}),(0,z.jsx)(lC,{className:"w-10"})]})}),(0,z.jsxs)(lw,{children:[v.map(e=>(0,z.jsx)(kx,{task:e,onUpdate:r,onDelete:s,onArchive:i,onUnarchive:n,archivedView:o,onClick:e=>{p(e),g(!0)},worktrees:a,assignedBranches:y,onAssign:l},e.id)),0===e.length&&(0,z.jsx)(lS,{children:(0,z.jsx)("td",{colSpan:7,className:"text-center text-muted-foreground py-12 text-sm",children:(0,z.jsxs)("div",{className:"flex flex-col items-center gap-1",children:[(0,z.jsx)("p",{className:"text-sm font-medium text-foreground/60",children:"No tasks yet"}),(0,z.jsx)("p",{className:"text-xs text-muted-foreground",children:"Create one to get started."})]})})})]})]}),(0,z.jsx)(ax,{task:f,open:m,onOpenChange:g})]})}function kb({open:e,onOpenChange:r,onSubmit:s}){let[i,n]=(0,$.useState)(""),[o,a]=(0,$.useState)("todo"),[l,c]=(0,$.useState)("medium");return(0,z.jsx)(t7,{open:e,onOpenChange:r,children:(0,z.jsxs)(rt,{className:"sm:max-w-md max-h-[85vh] flex flex-col",children:[(0,z.jsx)(rr,{children:(0,z.jsx)(ri,{children:"Create Task"})}),(0,z.jsxs)("form",{onSubmit:e=>{e.preventDefault(),i.trim()&&(s({description:i.trim(),status:o,priority:l}),n(""),a("todo"),c("medium"),r(!1))},className:"space-y-4 overflow-y-auto min-h-0 px-0.5",children:[(0,z.jsx)("div",{className:"space-y-2",children:(0,z.jsx)(ra,{placeholder:"Describe the task...",value:i,onChange:e=>n(e.target.value),className:"max-h-[40vh] focus-visible:border-input focus-visible:ring-0",rows:3,autoFocus:!0})}),(0,z.jsxs)("div",{className:"flex gap-3",children:[(0,z.jsxs)("div",{className:"flex-1 space-y-1",children:[(0,z.jsx)("label",{className:"text-xs text-muted-foreground",children:"Status"}),(0,z.jsxs)(cg,{value:o,onValueChange:e=>a(e),children:[(0,z.jsx)(cv,{children:(0,z.jsx)(cx,{})}),(0,z.jsx)(c_,{children:am.map(e=>(0,z.jsx)(cy,{value:e,children:af[e].label},e))})]})]}),(0,z.jsxs)("div",{className:"flex-1 space-y-1",children:[(0,z.jsx)("label",{className:"text-xs text-muted-foreground",children:"Priority"}),(0,z.jsxs)(cg,{value:l,onValueChange:e=>c(e),children:[(0,z.jsx)(cv,{children:(0,z.jsx)(cx,{})}),(0,z.jsx)(c_,{children:ag.map(e=>(0,z.jsx)(cy,{value:e,children:ap[e].label},e))})]})]})]}),(0,z.jsxs)(rs,{children:[(0,z.jsx)(W.Button,{type:"button",variant:"outline",onClick:()=>r(!1),children:"Cancel"}),(0,z.jsx)(W.Button,{type:"submit",disabled:!i.trim(),children:"Create"})]})]})]})})}let kw=[{value:"all",label:"All"},{value:"todo",label:"Todo"},{value:"in_progress",label:"Doing"},{value:"done",label:"Done"},{value:"cancelled",label:"Cancelled"},{value:"archived",label:"Archived"}];function kS({projectId:e,tasks:r,loading:s,worktrees:i,onCreateTask:n,onUpdateTask:o,onDeleteTask:a,onArchiveTask:l,onUnarchiveTask:c}){let[d,u]=(0,$.useState)(!1),[h,f]=(0,$.useState)("all"),p=(0,$.useMemo)(()=>r.filter(e=>null===e.archived_at),[r]),m=(0,$.useMemo)(()=>r.filter(e=>null!==e.archived_at),[r]),g=(0,$.useMemo)(()=>{let e={all:p.length,todo:0,in_progress:0,done:0,cancelled:0,archived:m.length};for(let r of p)e[r.status]++;return e},[p,m]),x=(0,$.useMemo)(()=>"archived"===h?m:"all"===h?p:p.filter(e=>e.status===h),[p,m,h]),v="archived"===h;return e?(0,z.jsxs)("div",{className:"flex flex-col h-full",children:[(0,z.jsx)(lx,{title:"Tasks",count:p.length,actions:(0,z.jsxs)(W.Button,{size:"sm",onClick:()=>u(!0),className:"shadow-sm",children:[(0,z.jsx)(eS,{className:"h-3.5 w-3.5 mr-1.5"}),"New Task"]})}),(0,z.jsx)(lv,{children:kw.map(e=>(0,z.jsx)(l_,{active:h===e.value,count:g[e.value],onClick:()=>f(e.value),children:e.label},e.value))}),(0,z.jsx)("div",{className:"flex-1 overflow-auto px-5 edge-scrollbar",children:s?(0,z.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground text-sm",children:"Loading tasks..."}):(0,z.jsx)(ky,{tasks:x,onUpdate:o,onDelete:a,onArchive:l,onUnarchive:c,archivedView:v,worktrees:i,onAssign:(e,r)=>{o(e,{assigned_branch:r})}})}),(0,z.jsx)(kb,{open:d,onOpenChange:u,onSubmit:n})]}):(0,z.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:(0,z.jsxs)("div",{className:"text-center",children:[(0,z.jsx)("div",{className:"mx-auto w-10 h-10 rounded-xl bg-muted flex items-center justify-center mb-3",children:(0,z.jsx)(eS,{className:"h-5 w-5 text-muted-foreground/50"})}),(0,z.jsx)("p",{className:"text-sm",children:"Select a project to view tasks."})]})})}let kC={completed:"/sounds/sound1.mp3","main-completed":"/sounds/sound2.mp3"};function kj(e,r){return`${e}:${r??""}`}let kk="vibedeckx:completion-notifications";function kN(e){return"object"==typeof e&&null!==e&&"string"==typeof e.id&&"string"==typeof e.projectId&&("string"==typeof e.branch||null===e.branch)&&("string"==typeof e.sessionId||null===e.sessionId||void 0===e.sessionId)&&("completed"===e.type||"main-completed"===e.type)&&"number"==typeof e.at&&"boolean"==typeof e.read}let kD=new Map,kE=new Set,kR=(0,ew.default)("bell",[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]]),kA={completed:{label:"Agent finished",dot:"bg-lime-400"},"main-completed":{label:"Chat finished",dot:"bg-emerald-500"}};function kM({notifications:e,unreadCount:r,projects:s,onNavigate:i,markRead:n,markAllRead:o,remove:a,clear:l}){return(0,z.jsxs)(of,{children:[(0,z.jsx)(op,{asChild:!0,children:(0,z.jsxs)(W.Button,{variant:"ghost",size:"icon-sm",className:"relative","aria-label":r>0?`${r} unread completion notifications`:"Completion notifications",children:[(0,z.jsx)(kR,{className:"h-4 w-4"}),r>0&&(0,z.jsx)("span",{className:"absolute -top-0.5 -right-0.5 flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[9px] font-semibold leading-none text-primary-foreground",children:r>9?"9+":r})]})}),(0,z.jsxs)(om,{align:"end",className:"w-80 p-0",children:[(0,z.jsxs)("div",{className:"flex items-center justify-between px-3 py-2",children:[(0,z.jsx)("span",{className:"text-[12.5px] font-semibold text-foreground",children:"Notifications"}),e.length>0&&(0,z.jsxs)("div",{className:"flex items-center gap-1",children:[(0,z.jsxs)("button",{onClick:o,disabled:0===r,className:"flex items-center gap-1 rounded px-1.5 py-0.5 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:pointer-events-none disabled:opacity-40",title:"Mark all read",children:[(0,z.jsx)(li,{className:"h-3 w-3"}),"Mark all read"]}),(0,z.jsx)("button",{onClick:l,className:"rounded px-1.5 py-0.5 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",title:"Clear all",children:"Clear"})]})]}),(0,z.jsx)("div",{className:"max-h-[60vh] overflow-y-auto border-t border-border",children:0===e.length?(0,z.jsx)("div",{className:"px-3 py-8 text-center text-[12px] text-muted-foreground/70",children:"No completions yet."}):e.map(e=>{let r,o=kA[e.type];return(0,z.jsxs)(og,{onSelect:()=>{n(e.id),i(e.projectId,e.branch,e.sessionId)},className:(0,ey.cn)("group flex flex-col items-start gap-0.5 rounded-none px-3 py-2",!e.read&&"bg-primary/[0.08]"),children:[(0,z.jsxs)("div",{className:"flex w-full items-center gap-2",children:[(0,z.jsx)("span",{className:(0,ey.cn)("h-[7px] w-[7px] shrink-0 rounded-full",o.dot)}),(0,z.jsx)("span",{className:(0,ey.cn)("min-w-0 flex-1 truncate text-[12.5px]",e.read?"text-foreground/70":"font-medium text-foreground"),children:(r=e.projectId,s.find(e=>e.id===r)?.name??"Unknown project")}),(0,z.jsx)("span",{className:"shrink-0 text-[10.5px] text-muted-foreground/70",children:function(e){let r=Math.max(0,Math.round((Date.now()-e)/1e3));if(r<60)return"just now";let s=Math.round(r/60);if(s<60)return`${s}m ago`;let i=Math.round(s/60);if(i<24)return`${i}h ago`;let n=Math.round(i/24);return`${n}d ago`}(e.at)}),(0,z.jsx)("button",{onClick:r=>{r.stopPropagation(),a(e.id)},className:"shrink-0 rounded p-0.5 text-muted-foreground/60 opacity-0 transition-all hover:bg-muted hover:text-foreground group-hover:opacity-100",title:"Dismiss",children:(0,z.jsx)(t8,{className:"h-3 w-3"})})]}),(0,z.jsxs)("div",{className:"flex w-full items-center gap-1.5 pl-[15px] text-[11px] text-muted-foreground",children:[(0,z.jsx)("span",{className:"font-mono truncate",children:e.branch??"main"}),(0,z.jsx)("span",{className:"text-muted-foreground/50",children:"·"}),(0,z.jsx)("span",{className:"shrink-0",children:o.label})]})]},e.id)})})]})]})}function kF(e){if(null===e)return"尚未连接";let r=Math.max(0,Math.round((Date.now()-e)/1e3));if(r<60)return`${r} 秒前`;let s=Math.floor(r/60);return s<60?`${s} 分钟前`:`${Math.floor(s/60)} 小时前`}function kT(){let{state:e,lastEventAt:r,reconnect:s}=(0,aj.useConnectionStatus)(),[,i]=(0,$.useState)(0);if((0,$.useEffect)(()=>{let e=setInterval(()=>i(e=>e+1),5e3);return()=>clearInterval(e)},[]),"stale"===e)return(0,z.jsxs)("button",{type:"button",onClick:s,title:`实时更新已断开 \xb7 上次更新 ${kF(r)} \xb7 点击重新连接`,className:"flex items-center gap-1.5 rounded-full border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[11px] font-medium text-amber-600 transition-colors hover:bg-amber-500/20",children:[(0,z.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500"}),"实时更新已断开"]});let n="live"===e;return(0,z.jsx)("span",{title:n?`实时更新正常 \xb7 上次更新 ${kF(r)}`:"正在连接实时更新…",className:"flex items-center px-1","aria-label":n?"实时更新正常":"正在连接实时更新",children:(0,z.jsx)("span",{className:n?"h-1.5 w-1.5 rounded-full bg-emerald-500":"h-1.5 w-1.5 animate-pulse rounded-full bg-muted-foreground/40"})})}let kP=new Set(["workspace","tasks","schedules","remote-servers","settings","project-info"]),kB="tasks";function kL(){let e=window.location.pathname,r=new URLSearchParams(window.location.search),s=r.get("project");if(s){let e=r.get("tab");return{projectId:s,tab:e&&kP.has(e)?e:kB,branch:r.get("branch")}}let i=e.split("/").filter(Boolean);if(1===i.length&&kP.has(i[0])){let e=i[0];if("remote-servers"===e||"settings"===e)return{projectId:null,tab:e,branch:null}}let n=null,o=kB;if("p"===i[0]&&i[1]){n=i[1];let e=i[2];e&&kP.has(e)&&(o=e)}return{projectId:n,tab:o,branch:r.get("branch")}}function kI(e){let{projectId:r,tab:s,branch:i}=e;if("remote-servers"===s||"settings"===s)return`/${s}`;if(!r)return"/";let n=`/p/${r}/${s??kB}`;return i&&(n+=`?branch=${encodeURIComponent(i)}`),n}function kO(e,r,s,i){return!!e&&e.projectId===r&&e.branch===s&&e.sessionId===i}function kz(){var e,r,s,i,n;let o,a,l,c,d,{projectId:u,tab:h,branch:f}=function(){let[e,r]=(0,$.useState)(kL);return(0,$.useEffect)(()=>{let e=()=>r(kL());return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[]),e}(),[p,m]=(0,$.useState)(()=>new URLSearchParams(window.location.search).get("session")),[g,x]=(0,$.useState)(null),v=(0,$.useCallback)(e=>{m(e);let r=new URL(window.location.href);e?r.searchParams.set("session",e):r.searchParams.delete("session"),window.history.replaceState(null,"",r.toString())},[]);(0,$.useEffect)(()=>{let e=()=>{m(new URLSearchParams(window.location.search).get("session"))};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[]),(0,$.useEffect)(()=>{if(new URLSearchParams(window.location.search).has("project")){let e=kI({projectId:u,tab:h,branch:f});window.history.replaceState(null,"",e)}},[]);let[_,y]=(0,$.useState)(!1),[b,w]=(0,$.useState)(!1),[S,C]=(0,$.useState)(!1),[j,k]=(0,$.useState)(null),[N,D]=(0,$.useState)(f),[E,R]=(0,$.useState)(h),[A,M]=(0,$.useState)(0),[F,T]=(0,$.useState)(0),P=(0,$.useRef)(null),[B,L]=(0,$.useState)(void 0),[I,O]=(0,$.useTransition)(),{projects:H,currentProject:U,loading:K,addProject:q,createProject:V,updateProject:Y,deleteProject:G,selectProject:X}=function(e){let[r,s]=(0,$.useState)([]),[i,n]=(0,$.useState)(null),[o,a]=(0,$.useState)(!0),l=(0,$.useCallback)(async()=>{a(!0);try{let r=await rx.api.getProjects();if(s(r),r.length>0&&!i){let s=e?r.find(r=>r.id===e):null;n(s??r[0])}}finally{a(!1)}},[i,e]);(0,$.useEffect)(()=>{l()},[]);let c=async(e,r)=>{let o=await rx.api.updateProject(e,r);return s(r=>r.map(r=>r.id===e?o:r)),i?.id===e&&n(o),o},d=async e=>{await rx.api.deleteProject(e),s(r=>r.filter(r=>r.id!==e)),i?.id===e&&n(r.find(r=>r.id!==e)??null)};return{projects:r,currentProject:i,loading:o,addProject:e=>{s(r=>[e,...r]),n(e)},createProject:async e=>{let r=await rx.api.createProject(e);return s(e=>[r,...e]),n(r),r},updateProject:c,deleteProject:d,selectProject:e=>{n(e)},refresh:l}}(u);U?.id!==B&&(void 0!==B&&D(null),L(U?.id));let{worktrees:J,loading:Z,refetch:Q}=function(e){let[r,s]=(0,$.useState)([]),[i,n]=(0,$.useState)(!0),[o,a]=(0,$.useState)(null),l=(0,$.useCallback)(async()=>{if(!e){s([]),a(null),n(!1);return}n(!0);try{let r=await rx.api.getProjectWorktrees(e);s(r)}catch(e){console.error("Failed to fetch worktrees:",e),s([{branch:null}])}finally{a(e),n(!1)}},[e]);return(0,$.useEffect)(()=>{l()},[l]),{worktrees:r,loading:i||o!==e,refetch:l}}(U?.id??null),{statuses:ee,defaultTarget:et,repositoryLabel:er,setTarget:es,refetch:ei}=function(e,r){let[s,i]=(0,$.useState)(new Map),[n,o]=(0,$.useState)(null),[a,l]=(0,$.useState)(null),[c,d]=(0,$.useState)(0),[u,h]=(0,$.useState)(e);e!==u&&(h(e),i(new Map),o(null),l(null));let f=(0,$.useCallback)(()=>d(e=>e+1),[]);return(0,$.useEffect)(()=>{let s=r.map(e=>e.branch).filter(e=>null!==e),n=!1;return(async()=>{var r,a;let c;if(!e||0===s.length){n||(i(new Map),o(null),l(null));return}let d=(r=r=>localStorage.getItem(ak(e,r)),s.map(e=>{let s=r(e);return s?{branch:e,target:s}:{branch:e}})),u=await rx.api.getMergeStatus(e,d);if(n||!u.ok)return;let h=new Map;for(let e of u.entries)!e.error&&e.target&&e.status&&h.set(e.branch,{branch:e.branch,status:e.status,unmergedCount:e.unmergedCount??0,dirty:e.dirty??!1,target:e.target});let p=(a=u.entries,c=new Set(d.filter(e=>void 0!==e.target).map(e=>e.branch)),a.filter(e=>"target-not-found"===e.error&&c.has(e.branch)).map(e=>e.branch));for(let r of p)try{localStorage.removeItem(ak(e,r))}catch{}i(h),o(function(e,r){let s=new Set(e.filter(e=>void 0!==e.target).map(e=>e.branch));for(let e of r)if(!s.has(e.branch)&&e.target)return e.target;return null}(d,u.entries)),l(u.repository.label),p.length>0&&f()})(),()=>{n=!0}},[e,r,c,f]),{statuses:s,defaultTarget:n,repositoryLabel:a,setTarget:(0,$.useCallback)((r,s)=>{if(e){try{s?localStorage.setItem(ak(e,r),s):localStorage.removeItem(ak(e,r))}catch{}f()}},[e,f]),refetch:f}}(U?.id??null,J),en=function(e,r,s){let i=(0,$.useMemo)(()=>r?.map(e=>e.branch)??[],[r]),[n,o]=(0,$.useState)([]),a=(0,$.useCallback)(async()=>{if(!e||0===i.length)return void o([]);let r=await Promise.all(i.map(async r=>(await (0,rx.listBranchSessions)(e,r)).sessions.filter(e=>e.processAlive).map(s=>({id:s.id,projectId:e,branch:r,title:s.title?.trim()||"New Session",status:s.status,processAlive:!0,updated_at:s.updated_at}))));o(e=>{var s;let i;return s=r.flat(),i=new Map(e.map(e=>[e.id,e])),s.map(e=>{let r=i.get(e.id);return r&&"New Session"===e.title&&"New Session"!==r.title?{...e,title:r.title}:e})})},[i,e]);(0,$.useEffect)(()=>{let e=!1;return a().catch(r=>{e||console.warn("[ResidentSessions] refresh failed:",r)}),()=>{e=!0}},[a]);let{state:l}=(0,aj.useConnectionStatus)(),c=(0,$.useRef)(null),d=(0,$.useRef)(!1);return(0,$.useEffect)(()=>{var e;let r=c.current;c.current=l;let s=(e=d.current,"live"===l&&e&&"live"!==r);"live"===l&&(d.current=!0),s&&a().catch(e=>console.warn("[ResidentSessions] reconnect refresh failed:",e))},[l,a]),(0,$.useEffect)(()=>{s&&s.processAlive&&e&&s.projectId===e&&o(e=>(function(e,r){let s=e.findIndex(e=>e.id===r.id);if(-1===s)return[r,...e];let i=e[s],n="New Session"===r.title&&"New Session"!==i.title?i.title:r.title,o=[...e];return o[s]={...r,title:n},o})(e,s))},[e,s]),(0,aj.useGlobalEventStream)(r=>{if(e&&r.projectId===e){if("session:process"===r.type){let e="string"==typeof r.sessionId?r.sessionId:null,s="boolean"==typeof r.alive?r.alive:null,i="string"==typeof r.branch?r.branch:null;if(!e||null===s)return;if(!s)return void o(r=>r.filter(r=>r.id!==e));a().catch(e=>console.warn("[ResidentSessions] process refresh failed:",e)),null!==i&&o(r=>r.map(r=>r.id===e?{...r,branch:i}:r))}if("session:status"===r.type){let e="string"==typeof r.sessionId?r.sessionId:null,s="string"==typeof r.status?r.status:null;if(!e||!s)return;o(r=>r.map(r=>r.id===e?{...r,status:s}:r))}if("session:title"===r.type){let e="string"==typeof r.sessionId?r.sessionId:null;if(!e)return;o(s=>{var i,n;return n=("string"==typeof(i=r.title)?i.trim():"")||"New Session",s.map(r=>r.id===e?{...r,title:n}:r)})}}}),(0,$.useMemo)(()=>{let e=new Map;for(let r of n){let s=r.branch??"",i=e.get(s)??[];i.push(r),e.set(s,i)}for(let r of e.values())r.sort((e,r)=>(r.updated_at??"").localeCompare(e.updated_at??""));return e},[n])}(U?.id??null,J,g),{tasks:eo,loading:ea,createTask:el,updateTask:ec,deleteTask:ed,archive:eu,unarchive:eh,refetch:ef}=function(e){let[r,s]=(0,$.useState)([]),[i,n]=(0,$.useState)(!0),o=(0,$.useCallback)(async()=>{if(!e){s([]),n(!1);return}try{let r=await rx.api.getTasks(e,{includeArchived:!0});s(r)}catch(e){console.error("Failed to fetch tasks:",e)}finally{n(!1)}},[e]);(0,$.useEffect)(()=>{o()},[o]);let a=(0,$.useCallback)(async r=>{if(!e)return null;try{let i=await rx.api.createTask(e,r);return s(e=>[...e,i]),i}catch(e){return console.error("Failed to create task:",e),null}},[e]),l=(0,$.useCallback)(async(e,i)=>{s(r=>r.map(r=>r.id===e?{...r,...i,updated_at:new Date().toISOString()}:r));try{let r=await rx.api.updateTask(e,i);return s(s=>s.map(s=>s.id===e?r:s)),r}catch(e){return console.error("Failed to update task:",e),s(r),null}},[r]),c=(0,$.useCallback)(async e=>{s(r=>r.filter(r=>r.id!==e));try{await rx.api.deleteTask(e)}catch(e){console.error("Failed to delete task:",e),s(r)}},[r]),d=(0,$.useCallback)(async e=>{s(r=>r.map(r=>r.id===e?{...r,archived_at:Date.now()}:r));try{let r=await rx.api.archiveTask(e);s(s=>s.map(s=>s.id===e?r:s))}catch(e){console.error("Failed to archive task:",e),s(r)}},[r]),u=(0,$.useCallback)(async e=>{s(r=>r.map(r=>r.id===e?{...r,archived_at:null}:r));try{let r=await rx.api.unarchiveTask(e);s(s=>s.map(s=>s.id===e?r:s))}catch(e){console.error("Failed to unarchive task:",e),s(r)}},[r]),h=(0,$.useCallback)(async i=>{if(e){s(i.map(e=>r.find(r=>r.id===e)).filter(e=>void 0!==e));try{await rx.api.reorderTasks(e,i)}catch(e){console.error("Failed to reorder tasks:",e),s(r)}}},[e,r]);return{tasks:r,loading:i,createTask:a,updateTask:l,deleteTask:c,archive:d,unarchive:u,reorderTasks:h,refetch:o}}(U?.id??null),{schedules:ep,loading:em,createSchedule:eg,updateSchedule:ex,deleteSchedule:ev,runNow:e_}=function(e){let[r,s]=(0,$.useState)([]),[i,n]=(0,$.useState)(!1),o=(0,$.useRef)(e),a=(0,$.useRef)(0),l=(0,$.useCallback)(async(e,r,i)=>{if(!e){a.current===r&&(s([]),n(!1));return}i&&n(!0);try{let i=await rx.api.getSchedules(e);a.current===r&&s(i)}catch(e){console.error("Failed to fetch schedules:",e)}finally{i&&a.current===r&&n(!1)}},[]);(0,$.useEffect)(()=>{o.current=e,a.current+=1,l(e,a.current,!0)},[e,l]);let c=(0,$.useCallback)(async()=>{let e=o.current;e&&await l(e,a.current,!1)},[l]),d=(0,$.useRef)(c);(0,$.useEffect)(()=>{d.current=c},[c]),(0,aj.useGlobalEventStream)(e=>{!e.type?.startsWith("schedule:")||o.current&&e.projectId===o.current&&d.current()});let u=(0,$.useCallback)(async r=>{if(!e)throw Error("No project selected");let s=await rx.api.createSchedule(e,r);return await c(),s},[e,c]),h=(0,$.useCallback)(async(e,r)=>{let s=await rx.api.updateSchedule(e,r);return await c(),s},[c]),f=(0,$.useCallback)(async e=>{await rx.api.deleteSchedule(e),await c()},[c]),p=(0,$.useCallback)(async e=>{let r=await rx.api.runScheduleNow(e);return await c(),r},[c]);return{schedules:r,loading:i,refetch:c,createSchedule:u,updateSchedule:h,deleteSchedule:f,runNow:p}}(U?.id??null),[ey,eb]=(0,$.useState)(null),[ew,eC]=(0,$.useState)(!1),{activity:ej,since:ek,refetch:eN,setOptimisticActivity:eD}=function(e){let[r,s]=(0,$.useState)(new Map),[i,n]=(0,$.useState)(new Map),o=(0,$.useRef)(new Map),a=(0,$.useRef)(new Map),l=(0,$.useRef)(null),c=(0,$.useCallback)(async()=>{if(!e){s(new Map),n(new Map),a.current=new Map,l.current=null,o.current=new Map;return}try{let r=await (0,rx.authFetch)(`${"localhost"===window.location.hostname&&"3000"===window.location.port?"http://localhost:5173":""}/api/projects/${e}/branches/activity`);if(!r.ok)return;let i=await r.json(),c=l.current!==e,{nextActivity:d,nextSince:u}=function(e,r,s,i){let n=new Map,o=new Map,a=[];for(let l of e){let e=l.branch??"",c=s.get(e)??0;if(!i&&l.since<c){let s=r.get(e);if(void 0!==s){n.set(e,s),o.set(e,c);continue}}n.set(e,l.activity),o.set(e,l.since),i||r.get(e)===l.activity||a.push(l.branch)}return{nextActivity:n,nextSince:o,transitions:a}}(i.branches,a.current,o.current,c);s(d),n(u),a.current=d,l.current=e,o.current=u}catch{}},[e]);return(0,$.useEffect)(()=>{c()},[c]),(0,aj.useGlobalEventStream)(r=>{var i,l,c;let d,u;if("branch:activity"!==r.type||!e||r.projectId!==e)return;let h=(i=r,l=a.current,c=o.current,d=i.branch??"",u=c.get(d)??0,i.since<u?{kind:"stale"}:l.get(d)===i.activity?{kind:"redundant",key:d}:{kind:"transition",key:d});"stale"===h.kind||(o.current.set(h.key,r.since),n(new Map(o.current)),"redundant"!==h.kind&&s(e=>{let s=new Map(e);return s.set(h.key,r.activity),a.current=s,s}))}),{activity:r,since:i,refetch:c,setOptimisticActivity:(0,$.useCallback)((e,r)=>{s(s=>{let i=function(e,r,s){let i=r??"";if(e.get(i)===s)return e;let n=new Map(e);return n.set(i,s),n}(s,e,r);return a.current=i,i})},[])}}(U?.id??null),{rules:eE,createRule:eR,updateRule:eA,deleteRule:eM}=function(e,r){let[s,i]=(0,$.useState)([]),[n,o]=(0,$.useState)(!0),a=(0,$.useCallback)(async()=>{if(!e){i([]),o(!1);return}try{let s=await rx.api.getRules(e,r);i(s)}catch(e){console.error("Failed to fetch rules:",e)}finally{o(!1)}},[e,r]);(0,$.useEffect)(()=>{a()},[a]);let l=(0,$.useCallback)(async s=>{if(!e)return null;try{let n=await rx.api.createRule(e,{...s,branch:r});return i(e=>[...e,n]),n}catch(e){return console.error("Failed to create rule:",e),null}},[e,r]),c=(0,$.useCallback)(async(e,r)=>{i(s=>s.map(s=>s.id===e?{...s,...r,enabled:void 0!==r.enabled?+!!r.enabled:s.enabled,updated_at:new Date().toISOString()}:s));try{let s=await rx.api.updateRule(e,r);return i(r=>r.map(r=>r.id===e?s:r)),s}catch(e){return console.error("Failed to update rule:",e),i(s),null}},[s]),d=(0,$.useCallback)(async e=>{i(r=>r.filter(r=>r.id!==e));try{await rx.api.deleteRule(e)}catch(e){console.error("Failed to delete rule:",e),i(s)}},[s]);return{rules:s,loading:n,createRule:l,updateRule:c,deleteRule:d,refetch:a}}(U?.id??null,N),{commands:eF,createCommand:eT,updateCommand:eP,deleteCommand:eB}=function(e,r){let[s,i]=(0,$.useState)([]),[n,o]=(0,$.useState)(!0),a=(0,$.useCallback)(async()=>{if(!e){i([]),o(!1);return}try{let s=await rx.api.getCommands(e,r);i(s)}catch(e){console.error("Failed to fetch commands:",e)}finally{o(!1)}},[e,r]);(0,$.useEffect)(()=>{a()},[a]);let l=(0,$.useCallback)(async s=>{if(!e)return null;try{let n=await rx.api.createCommand(e,{...s,branch:r});return i(e=>[...e,n]),n}catch(e){return console.error("Failed to create command:",e),null}},[e,r]),c=(0,$.useCallback)(async(e,r)=>{i(s=>s.map(s=>s.id===e?{...s,...r,updated_at:new Date().toISOString()}:s));try{let s=await rx.api.updateCommand(e,r);return i(r=>r.map(r=>r.id===e?s:r)),s}catch(e){return console.error("Failed to update command:",e),i(s),null}},[s]),d=(0,$.useCallback)(async e=>{i(r=>r.filter(r=>r.id!==e));try{await rx.api.deleteCommand(e)}catch(e){console.error("Failed to delete command:",e),i(s)}},[s]);return{commands:s,loading:n,createCommand:l,updateCommand:c,deleteCommand:d,refetch:a}}(U?.id??null,N),eL=(0,$.useRef)(null),eI=(0,$.useSyncExternalStore)(Sw,SS,SC),eO=U?.id??null,ez=U?.agent_mode??null,e$=(0,$.useCallback)(e=>!!eO&&eI.has(Sj(eO,e,ez)),[eI,eO,ez]),eW=(0,$.useCallback)(e=>{if(eO)return eI.get(Sj(eO,e,ez))},[eI,eO,ez]),eH=(0,$.useCallback)(e=>ek.get(sd(e)),[ek]),eU=(0,$.useMemo)(()=>(function(e,r,s,i){let n=new Map;if(!e)return n;for(let o of e){let e=sd(o.branch),a=r.get(e);if(!s?.(o.branch)){n.set(e,a??"idle");continue}if("main-running"===a)n.set(e,"main-running");else if("main-completed"===a){let r=i?.backendSince?.(o.branch)??0,s=i?.placeholderSince?.(o.branch)??0;n.set(e,s>r?"idle":"main-completed")}else n.set(e,"idle")}return n})(J,ej,e$,{backendSince:eH,placeholderSince:eW}),[J,ej,e$,eH,eW]);s=ei,i=eU,n=U?.id??null,o=(0,$.useRef)(new Set),l=(a=function(e){let r=new Set;if(!e)return r;for(let[s,i]of e)aN.has(i)&&r.add(s);return r}(i)).size>0,c=JSON.stringify(Array.from(a).sort()),(0,$.useEffect)(()=>{let e=new Set(JSON.parse(c)),r=o.current;o.current=e,function(e,r){for(let s of e)if(!r.has(s))return!0;return!1}(r,e)&&s()},[c,s]),(0,$.useEffect)(()=>{let e=()=>s();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[s]),(0,aj.useGlobalEventStream)(e=>{"executor:stopped"===e.type&&e.projectId===n&&s()}),(0,$.useEffect)(()=>{let e=null,r=()=>{null!==e&&(clearInterval(e),e=null)},i=()=>{r(),e=setInterval(s,l?3e4:6e4)},n=()=>{"visible"===document.visibilityState?i():r()};return"visible"===document.visibilityState&&i(),document.addEventListener("visibilitychange",n),()=>{r(),document.removeEventListener("visibilitychange",n)}},[s,l]);let{notifications:eK,unreadCount:eq,markRead:eV,markAllRead:eY,remove:eG,clear:eX}=function(e){let[r,s]=(0,$.useState)([]),i=(0,$.useRef)(new Map);(0,$.useEffect)(()=>{for(let e of Object.values(kC))kD.has(e)||kE.has(e)||(kE.add(e),(async()=>{try{let r=await fetch(e),s=await r.blob(),i=new Audio(URL.createObjectURL(s));i.preload="auto",i.load(),kD.set(e,i),console.log(`[sound-preload-debug] warmed ${e} bytes=${s.size}`)}catch(r){console.log(`[sound-preload-debug] warm failed ${e}`,r)}finally{kE.delete(e)}})())},[]);let n=(0,$.useRef)(e);(0,$.useEffect)(()=>{n.current=e},[e]),(0,$.useEffect)(()=>{e&&s(r=>r.some(r=>r.id===e&&!r.read)?r.map(r=>r.id===e?{...r,read:!0}:r):r)},[e,r]),(0,aj.useGlobalEventStream)(e=>{var r,o;let a;if("branch:activity"!==e.type)return;let l=kj(e.projectId,e.branch),c=i.current.get(l)!==e.activity;if(i.current.set(l,e.activity),!c||"completed"!==(r=e.activity)&&"main-completed"!==r)return;let d=e.activity;o=kC[d],(a=kD.get(o))||((a=new Audio(o)).preload="auto",kD.set(o,a)),a.currentTime=0,console.log(`[sound-preload-debug] play ${o} readyState=${a.readyState}`),a.play().catch(()=>{});let u=n.current===l;s(r=>{var s;return[(s={...e,activity:d},{id:kj(s.projectId,s.branch),projectId:s.projectId,branch:s.branch,sessionId:s.sessionId??null,type:s.activity,at:s.since,read:u}),...r.filter(e=>e.id!==l)].slice(0,50)})}),(0,$.useEffect)(()=>{let e=function(){try{var e=window.localStorage.getItem(kk);if(!e)return[];try{let r=JSON.parse(e);if(!Array.isArray(r))return[];return r.filter(kN).map(e=>({...e,sessionId:e.sessionId??null})).slice(0,50)}catch{return[]}}catch{return[]}}();0!==e.length&&s(r=>{if(0===r.length)return e;let s=new Set(r.map(e=>e.id));return[...r,...e.filter(e=>!s.has(e.id))].slice(0,50)})},[]);let o=(0,$.useRef)(!1);(0,$.useEffect)(()=>{if(!o.current){o.current=!0;return}try{window.localStorage.setItem(kk,JSON.stringify(r))}catch{}},[r]);let a=(0,$.useCallback)(e=>{s(r=>r.map(r=>r.id===e?{...r,read:!0}:r))},[]),l=(0,$.useCallback)(()=>{s(e=>e.some(e=>!e.read)?e.map(e=>({...e,read:!0})):e)},[]),c=(0,$.useCallback)(e=>{s(r=>r.filter(r=>r.id!==e))},[]),d=(0,$.useCallback)(()=>{s(e=>e.length?[]:e)},[]),u=r.reduce((e,r)=>e+ +!r.read,0);return{notifications:r,unreadCount:u,markRead:a,markAllRead:l,remove:c,clear:d}}(U&&"workspace"===E?`${U.id}:${N??""}`:null),eJ=(0,$.useCallback)(()=>{eD(N,"working")},[N,eD]),eZ=(0,$.useRef)(null),eQ=(0,$.useCallback)(()=>{ef()},[ef]),e0=(0,$.useCallback)((e,r)=>{eZ.current={projectId:U?.id,branch:e,sessionId:r},D(e),v(r),M(e=>e+1)},[U?.id,v]),e1=(0,$.useCallback)(e=>{e0(e.branch,e.id),R("workspace")},[e0]),e2=(0,$.useCallback)(e=>{eN(),!1!==e.processAlive&&x({id:e.id,projectId:e.projectId,branch:e.branch,title:"New Session",status:e.status,processAlive:!0,updated_at:new Date().toISOString()})},[eN]),e5=(0,$.useCallback)((e,r)=>{U?.id&&r.trim()&&x(s=>({id:e,projectId:U.id,branch:s?.id===e?s.branch:N,title:r,status:s?.id===e?s.status:"running",processAlive:!0,updated_at:s?.id===e?s.updated_at:new Date().toISOString()}))},[U?.id,N]),e3=(0,$.useCallback)(()=>{eD(N,"idle")},[N,eD]),e4=(0,$.useCallback)(()=>{ef()},[ef]);e=U?.id??null,r={onTaskChanged:e4},d=(0,$.useRef)(r.onTaskChanged),(0,$.useEffect)(()=>{d.current=r.onTaskChanged}),(0,aj.useGlobalEventStream)(r=>{e&&r.projectId===e&&("task:created"===r.type||"task:updated"===r.type||"task:deleted"===r.type)&&d.current?.()});let e6=(0,$.useMemo)(()=>{let e=sd(N);return eo.find(r=>r.assigned_branch===e)??null},[eo,N]);(0,$.useCallback)(e=>{O(async()=>{await P.current?.submitMessage(e.description??e.title)})},[]),(0,$.useCallback)(e=>{ec(e,{assigned_branch:null})},[ec]);let e8=(0,$.useRef)(void 0);(0,$.useEffect)(()=>{if(Z||0===J.length)return;let e=e8.current;if(void 0!==e){if(J.some(r=>r.branch===e.branch)){e8.current=void 0,e.sessionId?e0(e.branch,e.sessionId):D(e.branch);return}e8.current=void 0}J.some(e=>e.branch===N)||D(J[0].branch)},[J,Z,N,e0]);let e7=(0,$.useCallback)((e,r,s=null)=>{if(R("workspace"),e===U?.id)return void(s?e0(r,s):D(r));let i=H.find(r=>r.id===e);i&&(e8.current={branch:r,sessionId:s},X(i))},[U?.id,H,X,e0]),e9=(0,$.useRef)(N),te=(0,$.useRef)(U?.id),tt=(0,$.useRef)(!1);(0,$.useEffect)(()=>{if(K)return;let e=!tt.current,r=!e&&e9.current!==N,s=!e&&te.current!==U?.id;e9.current=N,te.current=U?.id,tt.current=!0;let i=eZ.current;if(kO(i,U?.id,N,p)&&(eZ.current=null),function({branchChanged:e,projectChanged:r,urlSessionId:s,pendingSessionSelection:i,currentProjectId:n,selectedBranch:o}){return(!!e||!!r)&&!!s&&!kO(i,n,o,s)}({branchChanged:r,projectChanged:s,urlSessionId:p,pendingSessionSelection:i,currentProjectId:U?.id,selectedBranch:N})){eZ.current=null,v(null);return}let n=kI({projectId:U?.id,tab:E,branch:N});if(p){let e=new URL(n,window.location.origin);e.searchParams.set("session",p),window.history.replaceState(null,"",e.pathname+e.search)}else window.history.replaceState(null,"",n)},[U?.id,E,N,K,p,v]);let tr=(0,$.useCallback)(e=>{Q(),D(e)},[Q]);(0,$.useCallback)((e,r)=>{U&&r!==U.agent_mode?Y(U.id,{agentMode:r}).then(()=>{P.current?.submitMessage(e)}):P.current?.submitMessage(e)},[U,Y]);let ts=(0,$.useRef)({content:"",at:0}),ti=(0,$.useCallback)(e=>{let r=Date.now(),s=ts.current;s.content===e&&r-s.at<600||(ts.current={content:e,at:r},eL.current?.sendMessage(e))},[]),tn=(0,$.useCallback)(()=>{let e=`Please perform the following git operations for this worktree:
|
|
29
29
|
|
|
30
30
|
1. Commit all current uncommitted changes with an appropriate commit message
|
|
31
31
|
2. Fetch the latest changes from the remote main branch
|