tarsk 0.3.41 → 0.3.43

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.
@@ -0,0 +1,18 @@
1
+ import{r as m,c as F,j as n,S as Sa,R as On,a as Fn,b as Ca,V as Ta,C as Ia,d as ka,e as Ra,f as Ea,g as Gn,P as _a,h as Pa,T as Ma,i as Da,M as Aa,k as Hn,l as gs,m as Un,L as ve,n as nn,o as Js,p as Qs,q as Mt,F as zn,G as xs,s as Je,t as ds,Z as rn,u as an,X as mt,v as Es,w as La,x as $a,y as Tt,z as It,A as Bn,B as Oa,D as Fa,E as Ga,H as qn,I as Wn,J as Ha,K as Vn,N as Ua,O as za,Q as Ba,U as qa,W as Kn,Y as Wa,_ as Cs,$ as Va,a0 as Ka,a1 as ln,a2 as bn,a3 as Ja,a4 as Jn,a5 as Qn,a6 as Qa,a7 as on,a8 as Ya,a9 as Yn,aa as Xn,ab as Xa,ac as Za,ad as el,ae as tl,af as sl,ag as Zn,ah as nl,ai as er,aj as tr,ak as sr,al as rl,am as al,an as nr,ao as rr,ap as ar,aq as lr,ar as js,as as or,at as ir,au as ll,av as cr,aw as dr,ax as ur,ay as mr,az as fr,aA as pr,aB as hr,aC as ol,aD as il,aE as cl,aF as dl,aG as gr,aH as xr,aI as ul,aJ as ml,aK as fl,aL as pl,aM as hl,aN as gl,aO as Ys,aP as cn,aQ as xl,aR as jl,aS as jr,aT as yl,aU as yr,aV as br,aW as vr,aX as Nr,aY as wr,aZ as bl,a_ as Sr,a$ as Cr,b0 as Tr,b1 as vl,b2 as Ir,b3 as kr,b4 as Rr,b5 as Er,b6 as Nl,b7 as wl,b8 as Sl,b9 as Cl,ba as Tl,bb as Il,bc as _r,bd as Pr,be as Mr,bf as Dr,bg as vn,bh as kl,bi as Rl,bj as El,bk as _l,bl as Pl,bm as Ar,bn as Lr,bo as $r,bp as Or,bq as Fr,br as Gr,bs as Ml,bt as Dl}from"./react-vendor-B6JfXZmN.js";import{t as Al,c as Ll,a as ys}from"./ui-styling-CyCIFleB.js";import{z as $l,J as Ol}from"./utils-Dd_itR7L.js";import"./radix-ui-e1yigncZ.js";import"./monaco-w6PwaWGP.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))r(a);new MutationObserver(a=>{for(const l of a)if(l.type==="childList")for(const o of l.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function t(a){const l={};return a.integrity&&(l.integrity=a.integrity),a.referrerPolicy&&(l.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?l.credentials="include":a.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function r(a){if(a.ep)return;a.ep=!0;const l=t(a);fetch(a.href,l)}})();function es(s){return typeof s!="string"?"":s.replace(/\\n/g,`
2
+ `)}function Hr(s){if(!s||typeof s!="string")return null;const e=s.trim();if(!e.startsWith("[")){if(!e.startsWith("{"))return null;try{const a=JSON.parse(e);if(a&&typeof a=="object"&&(a.type==="tool-result"||a.type==="tool_use"))return[a]}catch{}return null}const t=[];let r=0;for(;r<e.length;){const a=e.indexOf("[",r);if(a===-1)break;let l=0,o=-1;for(let i=a;i<e.length;i++)if(e[i]==="[")l++;else if(e[i]==="]"&&(l--,l===0)){o=i;break}if(o===-1)break;try{const i=JSON.parse(e.slice(a,o+1));if(Array.isArray(i)){for(const c of i)if(c&&typeof c=="object"&&"type"in c){const d=c.type;(d==="tool-result"||d==="tool_use")&&t.push(c)}}}catch{}r=o+1}return t.length>0?t:null}function Nn(s){return s.map(e=>{if(typeof e=="object"&&e!==null&&!("type"in e)){const t=e;if(t.reasoning)return{type:"reasoning",text:String(t.reasoning)};const r=t.text||t.content||t.answer;if(r)return{type:"text",text:String(r)}}return e})}function wn(s){const e=[];s.reasoning&&typeof s.reasoning=="string"&&e.push({type:"reasoning",text:s.reasoning});const t=(typeof s.text=="string"?s.text:null)||(typeof s.content=="string"?s.content:null)||(typeof s.answer=="string"?s.answer:null);return t&&e.push({type:"text",text:t}),e.length===0&&Object.keys(s).length>0&&e.push({type:"text",text:JSON.stringify(s,null,2)}),e}function Ur(s){if(!s)return null;const e=s.trim();if(e.startsWith("{")||e.startsWith("["))try{const i=JSON.parse(e);if(Array.isArray(i))return Nn(i);if(typeof i=="object"&&i!==null)return wn(i)}catch{}const r=[],a=s.indexOf("{"),l=s.indexOf("["),o=a===-1?l:l===-1?a:Math.min(a,l);if(o!==-1){const i=s.slice(o),c=Math.max(i.lastIndexOf("]"),i.lastIndexOf("}"));if(c!==-1){const d=i.substring(0,c+1);try{const u=JSON.parse(d);Array.isArray(u)?r.push(...Nn(u)):r.push(...wn(u));const f=i.substring(c+1).trim();return f&&r.push({type:"text",text:f}),r}catch{}}}return null}function Bs(s,e,t){const r=s[s.length-1];return r?.type===e?[...s.slice(0,-1),{type:e,chunks:[...r.chunks,t]}]:[...s,{type:e,chunks:[t]}]}function Xs(s,e){return s[s.length-1]?.type==="content"?[...s.slice(0,-1),{type:"content",chunks:[e]}]:[...s,{type:"content",chunks:[e]}]}function zr(s){const e=[];for(const t of s){const r=t.chunks.join("");if(t.type==="thinking"){const a=Hr(r)??[];e.push(...a)}else{const a=Ur(r)??(r.trim()?[{type:"text",text:r}]:[]);e.push(...a)}}return e}function Fl(s){const e=zr(s);return e.length===0?"...":e.length===1&&e[0]?.type==="text"&&"text"in e[0]?e[0].text:JSON.stringify(e)}var P=(s=>(s.SetProjects="SET_PROJECTS",s.SelectThread="SELECT_THREAD",s.SetMessages="SET_MESSAGES",s.AddMessage="ADD_MESSAGE",s.EnqueueChatMessage="ENQUEUE_CHAT_MESSAGE",s.RemoveQueuedChatMessage="REMOVE_QUEUED_CHAT_MESSAGE",s.SetStreaming="SET_STREAMING",s.AppendStreamContent="APPEND_STREAM_CONTENT",s.SetStreamContent="SET_STREAM_CONTENT",s.AppendStreamThinking="APPEND_STREAM_THINKING",s.AppendStreamChunk="APPEND_STREAM_CHUNK",s.SetStreamModel="SET_STREAM_MODEL",s.SetProjectModel="SET_PROJECT_MODEL",s.ResetStream="RESET_STREAM",s.StopStream="STOP_STREAM",s.ToggleSidebar="TOGGLE_SIDEBAR",s.SetCreatingProject="SET_CREATING_PROJECT",s.ConfigUpdated="CONFIG_UPDATED",s.SetProcessingThreads="SET_PROCESSING_THREADS",s.AddProcessingThread="ADD_PROCESSING_THREAD",s.RemoveProcessingThread="REMOVE_PROCESSING_THREAD",s.AddCreatingProject="ADD_CREATING_PROJECT",s.AddCreatingThread="ADD_CREATING_THREAD",s.RemoveCreatingProject="REMOVE_CREATING_PROJECT",s.RemoveCreatingThread="REMOVE_CREATING_THREAD",s.MarkThreadCompleted="MARK_THREAD_COMPLETED",s.ClearThreadCompleted="CLEAR_THREAD_COMPLETED",s.AddDeletingThread="ADD_DELETING_THREAD",s.RemoveDeletingThread="REMOVE_DELETING_THREAD",s.AddDeletingProject="ADD_DELETING_PROJECT",s.RemoveDeletingProject="REMOVE_DELETING_PROJECT",s.AppendCommandOutput="APPEND_COMMAND_OUTPUT",s.SetRunningCommand="SET_RUNNING_COMMAND",s.ClearCommandOutput="CLEAR_COMMAND_OUTPUT",s.ToggleTerminal="TOGGLE_TERMINAL",s.SetTerminalOpen="SET_TERMINAL_OPEN",s.QueueTerminalCommand="QUEUE_TERMINAL_COMMAND",s.ClearQueuedTerminalCommand="CLEAR_QUEUED_TERMINAL_COMMAND",s.AppendTerminalLine="APPEND_TERMINAL_LINE",s.ClearTerminalOutput="CLEAR_TERMINAL_OUTPUT",s.SetTerminalHeight="SET_TERMINAL_HEIGHT",s.SetTerminalCwd="SET_TERMINAL_CWD",s.SetTerminalRunning="SET_TERMINAL_RUNNING",s.SetTerminalHistory="SET_TERMINAL_HISTORY",s.SetTerminalHistoryIndex="SET_TERMINAL_HISTORY_INDEX",s.UpdateThreadTitle="UPDATE_THREAD_TITLE",s.ClearFocusChatInput="CLEAR_FOCUS_CHAT_INPUT",s.ToggleReviewMode="TOGGLE_REVIEW_MODE",s.SetReviewMode="SET_REVIEW_MODE",s.ClearMessages="CLEAR_MESSAGES",s.UpdateToolCallProgress="UPDATE_TOOL_CALL_PROGRESS",s.OpenHistoryView="OPEN_HISTORY_VIEW",s.CloseHistoryView="CLOSE_HISTORY_VIEW",s))(P||{});const Br={projects:[],selectedThreadId:null,selectedProjectId:null,messages:[],queuedChatMessages:[],isStreaming:!1,streamingContent:"",streamingThinking:"",streamingSegments:[],streamingModel:"",projectModelSelections:{},sidebarOpen:!0,isCreatingProject:!1,configUpdatedAt:0,processingThreadIds:[],completedThreadIds:[],deletingThreadIds:[],deletingProjectIds:[],commandOutput:"",isRunningCommand:!1,terminalStates:{},focusChatInput:!1,reviewMode:!1,toolCallProgress:{},historyView:{isOpen:!1}};function Gl(s,e){switch(e.type){case"SET_PROJECTS":return{...s,projects:e.projects};case"SELECT_THREAD":return{...s,selectedThreadId:e.threadId,selectedProjectId:e.projectId,messages:e.initialMessages||[],focusChatInput:e.focusInput??!1};case"SET_MESSAGES":return{...s,messages:e.messages};case"ADD_MESSAGE":return{...s,messages:[...s.messages,e.message]};case"ENQUEUE_CHAT_MESSAGE":return{...s,queuedChatMessages:[...s.queuedChatMessages,e.message]};case"REMOVE_QUEUED_CHAT_MESSAGE":return{...s,queuedChatMessages:s.queuedChatMessages.filter(t=>t.id!==e.queuedMessageId)};case"SET_STREAMING":return{...s,isStreaming:e.isStreaming};case"APPEND_STREAM_CONTENT":return{...s,streamingContent:s.streamingContent+e.content};case"SET_STREAM_CONTENT":{const t=Xs(s.streamingSegments,e.content);return{...s,streamingContent:e.content,streamingSegments:t}}case"APPEND_STREAM_THINKING":return{...s,streamingThinking:s.streamingThinking+e.content};case"APPEND_STREAM_CHUNK":return{...s,streamingSegments:e.segments,streamingContent:e.chunkType==="content"?s.streamingContent+e.content:s.streamingContent,streamingThinking:e.chunkType==="thinking"?s.streamingThinking+e.content:s.streamingThinking};case"SET_STREAM_MODEL":return{...s,streamingModel:e.model};case"SET_PROJECT_MODEL":return{...s,projectModelSelections:{...s.projectModelSelections,[e.projectId]:e.modelId}};case"RESET_STREAM":return{...s,streamingContent:"",streamingThinking:"",streamingSegments:[],streamingModel:"",isStreaming:!1,toolCallProgress:{}};case"STOP_STREAM":return{...s,isStreaming:!1};case"TOGGLE_SIDEBAR":return{...s,sidebarOpen:!s.sidebarOpen};case"SET_CREATING_PROJECT":return{...s,isCreatingProject:e.isCreating};case"CONFIG_UPDATED":return{...s,configUpdatedAt:Date.now()};case"SET_PROCESSING_THREADS":return{...s,processingThreadIds:e.threadIds};case"ADD_PROCESSING_THREAD":return{...s,processingThreadIds:s.processingThreadIds.includes(e.threadId)?s.processingThreadIds:[...s.processingThreadIds,e.threadId]};case"REMOVE_PROCESSING_THREAD":return{...s,processingThreadIds:s.processingThreadIds.filter(t=>t!==e.threadId)};case"ADD_CREATING_PROJECT":return{...s,projects:[...s.projects,{projectId:e.projectId,name:e.projectName,gitUrl:e.gitUrl,threads:[{threadId:e.threadId,title:"thread-1",path:"",currentBranch:""}]}]};case"ADD_CREATING_THREAD":return{...s,projects:s.projects.map(t=>t.projectId===e.projectId?{...t,threads:[...t.threads,{threadId:e.threadId,title:e.title,path:"",currentBranch:""}]}:t)};case"REMOVE_CREATING_PROJECT":return{...s,projects:s.projects.filter(t=>t.projectId!==e.projectId)};case"REMOVE_CREATING_THREAD":return{...s,projects:s.projects.map(t=>t.projectId===e.projectId?{...t,threads:t.threads.filter(r=>r.threadId!==e.threadId)}:t)};case"MARK_THREAD_COMPLETED":return{...s,completedThreadIds:s.completedThreadIds.includes(e.threadId)?s.completedThreadIds:[...s.completedThreadIds,e.threadId]};case"CLEAR_THREAD_COMPLETED":return{...s,completedThreadIds:s.completedThreadIds.filter(t=>t!==e.threadId)};case"ADD_DELETING_THREAD":return{...s,deletingThreadIds:s.deletingThreadIds.includes(e.threadId)?s.deletingThreadIds:[...s.deletingThreadIds,e.threadId]};case"REMOVE_DELETING_THREAD":return{...s,deletingThreadIds:s.deletingThreadIds.filter(t=>t!==e.threadId)};case"ADD_DELETING_PROJECT":return{...s,deletingProjectIds:s.deletingProjectIds.includes(e.projectId)?s.deletingProjectIds:[...s.deletingProjectIds,e.projectId]};case"REMOVE_DELETING_PROJECT":return{...s,deletingProjectIds:s.deletingProjectIds.filter(t=>t!==e.projectId)};case"APPEND_COMMAND_OUTPUT":return{...s,commandOutput:s.commandOutput+e.content};case"SET_RUNNING_COMMAND":return{...s,isRunningCommand:e.isRunning};case"CLEAR_COMMAND_OUTPUT":return{...s,commandOutput:""};case"TOGGLE_TERMINAL":{const t=e.threadId,r=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...r,open:!r.open}}}}case"SET_TERMINAL_OPEN":{const t=e.threadId||"default",r=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...r,open:e.open}}}}case"QUEUE_TERMINAL_COMMAND":{const t=e.threadId,r=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...r,queuedCommand:e.command,open:!0}}}}case"CLEAR_QUEUED_TERMINAL_COMMAND":{const t=e.threadId,r=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...r,queuedCommand:null}}}}case"APPEND_TERMINAL_LINE":{const t=e.threadId||"default",r=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...r,outputLines:[...r.outputLines,e.line]}}}}case"CLEAR_TERMINAL_OUTPUT":{const t=e.threadId||"default",r=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...r,outputLines:[]}}}}case"SET_TERMINAL_HEIGHT":{const t=e.threadId,r=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...r,height:e.height}}}}case"SET_TERMINAL_CWD":{const t=e.threadId,r=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...r,cwd:e.cwd}}}}case"SET_TERMINAL_RUNNING":{const t=e.threadId,r=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...r,isRunning:e.isRunning}}}}case"SET_TERMINAL_HISTORY":{const t=e.threadId,r=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...r,history:e.history}}}}case"SET_TERMINAL_HISTORY_INDEX":{const t=e.threadId,r=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...r,historyIndex:e.index}}}}case"UPDATE_THREAD_TITLE":return{...s,projects:s.projects.map(t=>t.projectId===e.projectId?{...t,threads:t.threads.map(r=>r.threadId===e.threadId?{...r,title:e.title}:r)}:t)};case"CLEAR_FOCUS_CHAT_INPUT":return{...s,focusChatInput:!1};case"TOGGLE_REVIEW_MODE":return{...s,reviewMode:!s.reviewMode};case"SET_REVIEW_MODE":return{...s,reviewMode:e.reviewMode};case"CLEAR_MESSAGES":return{...s,messages:[]};case"UPDATE_TOOL_CALL_PROGRESS":return{...s,toolCallProgress:{...s.toolCallProgress,[e.toolCallId]:e.progress}};case"OPEN_HISTORY_VIEW":return{...s,historyView:{isOpen:!0,initialFilter:e.initialFilter}};case"CLOSE_HISTORY_VIEW":return{...s,historyView:{isOpen:!1}};default:return s}}const qr=m.createContext({state:Br,dispatch:()=>{}});function Ce(){return m.useContext(qr)}function bs(s){const e=F.c(11),{state:t,dispatch:r}=Ce();if(!s){let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=[],e[0]=d):d=e[0];let u;return e[1]===Symbol.for("react.memo_cache_sentinel")?(u={terminalState:{open:!1,queuedCommand:null,outputLines:d,height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1},dispatch:Hl},e[1]=u):u=e[1],u}let a;e[2]!==t.terminalStates||e[3]!==s?(a=t.terminalStates[s]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1},e[2]=t.terminalStates,e[3]=s,e[4]=a):a=e[4];const l=a;let o;e[5]!==r||e[6]!==s?(o=d=>{r({...d,threadId:s})},e[5]=r,e[6]=s,e[7]=o):o=e[7];const i=o;let c;return e[8]!==i||e[9]!==l?(c={terminalState:l,dispatch:i},e[8]=i,e[9]=l,e[10]=c):c=e[10],c}function Hl(){}function B(...s){return Al(Ll(s))}function _s(s){return s.name?s.name:s.gitUrl?.split("/").pop()?.replace(".git","")||s.projectId}function Ul(s,e){if(!e)return"";for(const t of s){const r=t.threads.find(a=>a.threadId===e);if(r)return r.title}return""}function zl(s,e){if(!e)return"";const t=s.find(r=>r.projectId===e);return t?_s(t):""}function is(s){return s.toFixed(2).replace(/\.00$/,"")}const dn=ys("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),J=m.forwardRef((s,e)=>{const t=F.c(15);let r,a,l,o,i;t[0]!==s?({className:r,variant:i,size:l,asChild:o,...a}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l,t[4]=o,t[5]=i):(r=t[1],a=t[2],l=t[3],o=t[4],i=t[5]);const d=(o===void 0?!1:o)?Sa:"button";let u;t[6]!==r||t[7]!==l||t[8]!==i?(u=B(dn({variant:i,size:l,className:r})),t[6]=r,t[7]=l,t[8]=i,t[9]=u):u=t[9];let f;return t[10]!==d||t[11]!==a||t[12]!==e||t[13]!==u?(f=n.jsx(d,{className:u,ref:e,...a}),t[10]=d,t[11]=a,t[12]=e,t[13]=u,t[14]=f):f=t[14],f});J.displayName="Button";const Ke=m.forwardRef((s,e)=>{const t=F.c(15);let r,a,l;t[0]!==s?({className:a,children:r,...l}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l):(r=t[1],a=t[2],l=t[3]);let o;t[4]!==a?(o=B("relative overflow-hidden",a),t[4]=a,t[5]=o):o=t[5];let i;t[6]!==r?(i=n.jsx(Ta,{className:"h-full w-full rounded-[inherit]",children:r}),t[6]=r,t[7]=i):i=t[7];let c,d;t[8]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(Wr,{}),d=n.jsx(Ia,{}),t[8]=c,t[9]=d):(c=t[8],d=t[9]);let u;return t[10]!==l||t[11]!==e||t[12]!==o||t[13]!==i?(u=n.jsxs(On,{ref:e,className:o,...l,children:[i,c,d]}),t[10]=l,t[11]=e,t[12]=o,t[13]=i,t[14]=u):u=t[14],u});Ke.displayName=On.displayName;const Wr=m.forwardRef((s,e)=>{const t=F.c(14);let r,a,l;t[0]!==s?({className:r,orientation:l,...a}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l):(r=t[1],a=t[2],l=t[3]);const o=l===void 0?"vertical":l,i=o==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",c=o==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]";let d;t[4]!==r||t[5]!==i||t[6]!==c?(d=B("flex touch-none select-none transition-colors",i,c,r),t[4]=r,t[5]=i,t[6]=c,t[7]=d):d=t[7];let u;t[8]===Symbol.for("react.memo_cache_sentinel")?(u=n.jsx(Ca,{className:"relative flex-1 rounded-full bg-border"}),t[8]=u):u=t[8];let f;return t[9]!==o||t[10]!==a||t[11]!==e||t[12]!==d?(f=n.jsx(Fn,{ref:e,orientation:o,className:d,...a,children:u}),t[9]=o,t[10]=a,t[11]=e,t[12]=d,t[13]=f):f=t[13],f});Wr.displayName=Fn.displayName;const Bl=ka,ql=Ra,Wl=Ea,we=_a,fe=Pa,pe=Ma,me=m.forwardRef((s,e)=>{const t=F.c(11);let r,a,l;t[0]!==s?({className:r,sideOffset:l,...a}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l):(r=t[1],a=t[2],l=t[3]);const o=l===void 0?4:l;let i;t[4]!==r?(i=B("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",r),t[4]=r,t[5]=i):i=t[5];let c;return t[6]!==a||t[7]!==e||t[8]!==o||t[9]!==i?(c=n.jsx(Gn,{ref:e,sideOffset:o,className:i,...a}),t[6]=a,t[7]=e,t[8]=o,t[9]=i,t[10]=c):c=t[10],c});me.displayName=Gn.displayName;function Vl(){const s=F.c(8),{theme:e,setTheme:t}=$l();let r;s[0]!==t||s[1]!==e?(r=()=>t(e==="dark"?"light":"dark"),s[0]=t,s[1]=e,s[2]=r):r=s[2];let a,l,o;s[3]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx(Da,{className:"h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),l=n.jsx(Aa,{className:"absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100"}),o=n.jsx("span",{className:"sr-only",children:"Toggle theme"}),s[3]=a,s[4]=l,s[5]=o):(a=s[3],l=s[4],o=s[5]);let i;return s[6]!==r?(i=n.jsxs(J,{variant:"ghost",size:"icon",className:"h-8 w-8 text-sidebar-foreground hover:bg-sidebar-accent",onClick:r,children:[a,l,o]}),s[6]=r,s[7]=i):i=s[7],i}function Kl(s){const e=F.c(65),{projects:t,selectedThreadId:r,processingThreadIds:a,completedThreadIds:l,deletingThreadIds:o,deletingProjectIds:i,onSelectThread:c,onCreateProject:d,onCreateThread:u,onDeleteThread:f,onDeleteProject:h,onOpenConfiguration:g,onProjectSettings:p,onCollapseSidebar:j,onViewHistory:v,isMobile:b,collapsed:I}=s;let T;e[0]===Symbol.for("react.memo_cache_sentinel")?(T={containerType:"inline-size"},e[0]=T):T=e[0];let x;e[1]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx("div",{className:"flex h-7 w-7 items-center justify-center overflow-hidden rounded-md border border-sidebar-border shadow-sm",children:n.jsx("img",{src:"/tarsk.svg",alt:"Tarsk",className:"h-full w-full"})}),e[1]=x):x=e[1];let C;e[2]!==I?(C=!I&&n.jsx("span",{className:"text-sm font-semibold tracking-tight",children:"Tarsk"}),e[2]=I,e[3]=C):C=e[3];let _;e[4]!==C?(_=n.jsxs("div",{className:"flex items-center gap-2",children:[x,C]}),e[4]=C,e[5]=_):_=e[5];let w;e[6]!==I||e[7]!==b||e[8]!==j?(w=!I&&b&&n.jsxs(J,{variant:"ghost",size:"icon",className:"h-7 w-7 text-sidebar-foreground hover:bg-sidebar-accent",onClick:j,children:[n.jsx(Hn,{className:"h-4 w-4"}),n.jsx("span",{className:"sr-only",children:"Collapse sidebar"})]}),e[6]=I,e[7]=b,e[8]=j,e[9]=w):w=e[9];let k;e[10]!==w?(k=n.jsx("div",{className:"flex items-center gap-1",children:w}),e[10]=w,e[11]=k):k=e[11];let N;e[12]!==_||e[13]!==k?(N=n.jsxs("div",{className:"flex items-center justify-between border-b border-sidebar-border px-4 py-3",children:[_,k]}),e[12]=_,e[13]=k,e[14]=N):N=e[14];let y;e[15]===Symbol.for("react.memo_cache_sentinel")?(y=n.jsx(gs,{className:"h-4 w-4"}),e[15]=y):y=e[15];let S;e[16]!==I?(S=!I&&n.jsx("span",{children:"New Project"}),e[16]=I,e[17]=S):S=e[17];let R;e[18]!==d||e[19]!==S?(R=n.jsx("div",{className:"border-b border-sidebar-border px-3 py-2",children:n.jsxs(J,{variant:"ghost",size:"sm",className:"w-full justify-start gap-2 text-sidebar-foreground hover:bg-sidebar-accent",onClick:d,children:[y,S]})}),e[18]=d,e[19]=S,e[20]=R):R=e[20];let E;e[21]!==t.length?(E=t.length===0&&n.jsx("p",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:"No projects yet. Clone a repository to get started."}),e[21]=t.length,e[22]=E):E=e[22];let A;if(e[23]!==l||e[24]!==i||e[25]!==o||e[26]!==u||e[27]!==h||e[28]!==f||e[29]!==p||e[30]!==c||e[31]!==v||e[32]!==a||e[33]!==t||e[34]!==r){let K;e[36]!==l||e[37]!==i||e[38]!==o||e[39]!==u||e[40]!==h||e[41]!==f||e[42]!==p||e[43]!==c||e[44]!==v||e[45]!==a||e[46]!==r?(K=(X,de)=>n.jsx(Jl,{project:X,selectedThreadId:r,processingThreadIds:a,completedThreadIds:l,deletingThreadIds:o,deletingProjectIds:i,onSelectThread:c,onCreateThread:u,onDeleteThread:f,onDeleteProject:h,onProjectSettings:p,onViewHistory:v},X.projectId||X.gitUrl||`project-${de}`),e[36]=l,e[37]=i,e[38]=o,e[39]=u,e[40]=h,e[41]=f,e[42]=p,e[43]=c,e[44]=v,e[45]=a,e[46]=r,e[47]=K):K=e[47],A=t.map(K),e[23]=l,e[24]=i,e[25]=o,e[26]=u,e[27]=h,e[28]=f,e[29]=p,e[30]=c,e[31]=v,e[32]=a,e[33]=t,e[34]=r,e[35]=A}else A=e[35];let M;e[48]!==E||e[49]!==A?(M=n.jsx(Ke,{className:"flex-1",children:n.jsxs("div",{className:"px-2 py-2",children:[E,A]})}),e[48]=E,e[49]=A,e[50]=M):M=e[50];let z;e[51]===Symbol.for("react.memo_cache_sentinel")?(z=n.jsx(Un,{className:"h-4 w-4"}),e[51]=z):z=e[51];let O;e[52]!==I?(O=!I&&n.jsx("span",{children:"Settings"}),e[52]=I,e[53]=O):O=e[53];let L;e[54]!==g||e[55]!==O?(L=n.jsxs(J,{variant:"ghost",size:"sm",className:"flex-1 justify-start gap-2 text-sidebar-foreground hover:bg-sidebar-accent",onClick:g,children:[z,O]}),e[54]=g,e[55]=O,e[56]=L):L=e[56];let $;e[57]===Symbol.for("react.memo_cache_sentinel")?($=n.jsx(Vl,{}),e[57]=$):$=e[57];let q;e[58]!==L?(q=n.jsxs("div",{className:"border-t border-sidebar-border px-3 py-2 flex items-center gap-1",children:[L,$]}),e[58]=L,e[59]=q):q=e[59];let G;return e[60]!==R||e[61]!==M||e[62]!==q||e[63]!==N?(G=n.jsxs("div",{className:"flex h-full flex-col bg-sidebar text-sidebar-foreground",style:T,children:[N,R,M,q]}),e[60]=R,e[61]=M,e[62]=q,e[63]=N,e[64]=G):G=e[64],G}function Jl(s){const e=F.c(78),{project:t,selectedThreadId:r,processingThreadIds:a,completedThreadIds:l,deletingThreadIds:o,deletingProjectIds:i,onSelectThread:c,onCreateThread:d,onDeleteThread:u,onDeleteProject:f,onProjectSettings:h,onViewHistory:g}=s,[p,j]=m.useState(!0);let v;e[0]!==i||e[1]!==t.projectId?(v=i.includes(t.projectId),e[0]=i,e[1]=t.projectId,e[2]=v):v=e[2];const b=v;let I;e[3]!==t?(I=_s(t),e[3]=t,e[4]=I):I=e[4];const T=I,x=`${T} - `;let C,_,w,k,N,y,S,R,E;if(e[5]!==p||e[6]!==t.threads||e[7]!==r){let ae;e[17]!==r?(ae=ce=>ce.threadId===r,e[17]=r,e[18]=ae):ae=e[18];const le=t.threads.some(ae);_=Bl,S=p,R=j,E="mb-1",y="group flex min-w-0 items-center",C=ql,N=!0,w="button",k=B("flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-sm transition-colors hover:bg-sidebar-accent",le&&"text-sidebar-foreground font-medium"),e[5]=p,e[6]=t.threads,e[7]=r,e[8]=C,e[9]=_,e[10]=w,e[11]=k,e[12]=N,e[13]=y,e[14]=S,e[15]=R,e[16]=E}else C=e[8],_=e[9],w=e[10],k=e[11],N=e[12],y=e[13],S=e[14],R=e[15],E=e[16];const A=p&&"rotate-90";let M;e[19]!==A?(M=B("h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform",A),e[19]=A,e[20]=M):M=e[20];let z;e[21]!==M?(z=n.jsx(Mt,{className:M}),e[21]=M,e[22]=z):z=e[22];let O;e[23]===Symbol.for("react.memo_cache_sentinel")?(O=n.jsx(zn,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e[23]=O):O=e[23];let L;e[24]!==T?(L=n.jsx("span",{className:"min-w-0 truncate",children:T}),e[24]=T,e[25]=L):L=e[25];let $;e[26]!==z||e[27]!==L||e[28]!==w||e[29]!==k?($=n.jsxs("button",{type:w,className:k,children:[z,O,L]}),e[26]=z,e[27]=L,e[28]=w,e[29]=k,e[30]=$):$=e[30];let q;e[31]!==C||e[32]!==$||e[33]!==N?(q=n.jsx(C,{asChild:N,children:$}),e[31]=C,e[32]=$,e[33]=N,e[34]=q):q=e[34];let G;e[35]!==b||e[36]!==d||e[37]!==f||e[38]!==h||e[39]!==g||e[40]!==t.projectId||e[41]!==t.threads.length?(G=n.jsx("div",{className:"flex shrink-0 items-center",children:b?n.jsx(ve,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground mr-1"}):n.jsxs(we,{children:[n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsxs(J,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 group-hover:opacity-100",onClick:()=>g({type:"project",id:t.projectId}),children:[n.jsx(nn,{className:"h-3 w-3"}),n.jsx("span",{className:"sr-only",children:"View project history"})]})}),n.jsx(me,{side:"right",children:"View project history"})]}),n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsxs(J,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 group-hover:opacity-100",onClick:()=>h(t.projectId),children:[n.jsx(Js,{className:"h-3 w-3"}),n.jsx("span",{className:"sr-only",children:"Project settings"})]})}),n.jsx(me,{side:"right",children:"Project settings"})]}),n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsxs(J,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 group-hover:opacity-100",onClick:()=>d(t.projectId),children:[n.jsx(gs,{className:"h-3 w-3"}),n.jsx("span",{className:"sr-only",children:"Add thread"})]})}),n.jsx(me,{side:"right",children:"Add thread"})]}),t.threads.length===0&&n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsxs(J,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-destructive",onClick:()=>f(t.projectId),children:[n.jsx(Qs,{className:"h-3 w-3"}),n.jsx("span",{className:"sr-only",children:"Delete project"})]})}),n.jsx(me,{side:"right",children:"Delete project"})]})]})}),e[35]=b,e[36]=d,e[37]=f,e[38]=h,e[39]=g,e[40]=t.projectId,e[41]=t.threads.length,e[42]=G):G=e[42];let K;e[43]!==q||e[44]!==G||e[45]!==y?(K=n.jsxs("div",{className:y,children:[q,G]}),e[43]=q,e[44]=G,e[45]=y,e[46]=K):K=e[46];let X;if(e[47]!==l||e[48]!==o||e[49]!==u||e[50]!==c||e[51]!==a||e[52]!==t.projectId||e[53]!==t.threads||e[54]!==x||e[55]!==r){let ae;e[57]!==l||e[58]!==o||e[59]!==u||e[60]!==c||e[61]!==a||e[62]!==t.projectId||e[63]!==x||e[64]!==r?(ae=(le,ce)=>{const te=a.includes(le.threadId),se=o.includes(le.threadId),D=l.includes(le.threadId);return n.jsxs("div",{className:B("group/thread flex min-w-0 items-center gap-1.5 rounded-md px-2 py-1 text-sm transition-colors hover:bg-sidebar-accent cursor-pointer",le.threadId===r&&"bg-sidebar-accent text-sidebar-accent-foreground font-medium"),onClick:()=>c(t.projectId,le.threadId),onKeyDown:U=>{(U.key==="Enter"||U.key===" ")&&c(t.projectId,le.threadId)},role:"button",tabIndex:0,children:[n.jsx(xs,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"min-w-0 text-xs",style:{display:"block",textOverflow:"ellipsis"},children:le.title?.startsWith(x)?le.title.slice(x.length):le.title||le.threadId}),te||se?n.jsx(ve,{className:"ml-auto h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):D?n.jsx(Je,{className:"ml-auto h-3 w-3 shrink-0 text-green-500"}):n.jsx("div",{className:"ml-auto flex items-center gap-1",children:n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsxs(J,{variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 opacity-0 group-hover/thread:opacity-100 text-muted-foreground hover:text-destructive",onClick:U=>{U.stopPropagation(),u(t.projectId,le.threadId)},children:[n.jsx(Qs,{className:"h-3 w-3"}),n.jsx("span",{className:"sr-only",children:"Delete thread"})]})}),n.jsx(me,{side:"right",children:"Delete thread and files from the repo"})]})})]},le.threadId||`${t.projectId}-${le.title||ce}`)},e[57]=l,e[58]=o,e[59]=u,e[60]=c,e[61]=a,e[62]=t.projectId,e[63]=x,e[64]=r,e[65]=ae):ae=e[65],X=t.threads.map(ae),e[47]=l,e[48]=o,e[49]=u,e[50]=c,e[51]=a,e[52]=t.projectId,e[53]=t.threads,e[54]=x,e[55]=r,e[56]=X}else X=e[56];let de;e[66]!==t.threads.length?(de=t.threads.length===0&&n.jsx("p",{className:"px-2 py-1 text-xs text-muted-foreground",children:"No threads"}),e[66]=t.threads.length,e[67]=de):de=e[67];let ie;e[68]!==X||e[69]!==de?(ie=n.jsx(Wl,{children:n.jsxs("div",{className:"ml-4 border-l border-sidebar-border pl-2",children:[X,de]})}),e[68]=X,e[69]=de,e[70]=ie):ie=e[70];let re;return e[71]!==_||e[72]!==K||e[73]!==ie||e[74]!==S||e[75]!==R||e[76]!==E?(re=n.jsxs(_,{open:S,onOpenChange:R,className:E,children:[K,ie]}),e[71]=_,e[72]=K,e[73]=ie,e[74]=S,e[75]=R,e[76]=E,e[77]=re):re=e[77],re}const Ql=()=>{if(typeof window>"u")return null;const s=window.SpeechRecognition||window.webkitSpeechRecognition;return s?new s:null};function Vr(){const s=F.c(14),[e,t]=m.useState(!1),[r,a]=m.useState(""),[l,o]=m.useState(null),[i,c]=m.useState(!1),d=m.useRef(null),u=m.useRef("");let f,h;s[0]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{try{const x=Ql();x?(x.continuous=!0,x.interimResults=!0,x.lang="en-US",x.onstart=()=>{t(!0),o(null),u.current=""},x.onresult=C=>{let _="";for(let w=C.resultIndex;w<C.results.length;w++){const k=C.results[w][0].transcript;C.results[w].isFinal?a(N=>N+k+" "):_=_+k}u.current=_},x.onerror=C=>{console.error("Speech recognition error:",C.error),o(C.error||"An error occurred during speech recognition")},x.onend=()=>{t(!1)},d.current=x,c(!0)):(c(!1),o("Speech Recognition API is not supported in your browser"))}catch(x){console.error("Failed to initialize speech recognition:",x),c(!1),o("Failed to initialize speech recognition")}return()=>{d.current&&d.current.abort()}},h=[],s[0]=f,s[1]=h):(f=s[0],h=s[1]),m.useEffect(f,h);let g;s[2]!==e?(g=()=>{d.current&&!e&&d.current.start()},s[2]=e,s[3]=g):g=s[3];const p=g;let j;s[4]!==e?(j=()=>{d.current&&e&&d.current.stop()},s[4]=e,s[5]=j):j=s[5];const v=j;let b;s[6]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{a(""),u.current=""},s[6]=b):b=s[6];const I=b;let T;return s[7]!==l||s[8]!==e||s[9]!==i||s[10]!==p||s[11]!==v||s[12]!==r?(T={isListening:e,transcript:r,error:l,startListening:p,stopListening:v,resetTranscript:I,isSupported:i},s[7]=l,s[8]=e,s[9]=i,s[10]=p,s[11]=v,s[12]=r,s[13]=T):T=s[13],T}const ls=[{id:"openrouter/minimax/minimax-m2",name:"Minimax M2",description:"Minimax model optimized for chat",provider:"openrouter",pricing:{prompt:.15,completion:.15}},{id:"openrouter/google/gemini-3-flash-preview",name:"Gemini 3 Flash",description:"Google Gemini 3 Flash model",provider:"openrouter",pricing:{prompt:.075,completion:.3}}];function At(s){if(!s)return"Unknown Model";const t=(s.split("/").filter(Boolean).pop()||s).replace(/[-_]+/g," ").trim();return t?t.split(/\s+/g).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" "):s}const Kr=["462","8100"].includes(document.location.port)?"http://localhost:462":"http://localhost:641";function Sn(){return Kr}function kt(s){const e=s.startsWith("/")?s:`/${s}`;return`${Kr}${e}`}async function Rt(s){try{const e=await s.json();if(typeof e.error=="string")return e.error;if(e.error&&typeof e.error=="object")return e.error.details||e.error.message||"Unknown error"}catch{}return s.statusText||"Unknown error"}function Jr(s,e,t){const r=new Error(s);return t?.error&&typeof t.error=="object"&&(r.details=t.error.details,r.code=t.error.code),r}async function ye(s,e){const t=await fetch(kt(s),{...e,method:"GET"});if(!t.ok){const r=await Rt(t);throw new Error(r)}return t.json()}async function Se(s,e,t){const r=await fetch(kt(s),{...t,method:"POST",headers:{"Content-Type":"application/json",...t?.headers},body:e?JSON.stringify(e):void 0});if(!r.ok){const a=await Rt(r);throw new Error(a)}return r.json()}async function Yl(s,e,t){const r=await fetch(kt(s),{...t,method:"PATCH",headers:{"Content-Type":"application/json",...t?.headers},body:e?JSON.stringify(e):void 0});if(!r.ok){const a=await Rt(r);throw new Error(a)}return r.json()}async function Xl(s,e,t){const r=await fetch(kt(s),{...t,method:"PUT",headers:{"Content-Type":"application/json",...t?.headers},body:e?JSON.stringify(e):void 0});if(!r.ok){const a=await Rt(r);throw new Error(a)}return r.body}async function Ds(s,e){const t=await fetch(kt(s),{...e,method:"DELETE"});if(!t.ok){const r=await Rt(t);throw new Error(r)}if(t.status!==204)return t.json()}async function ts(s,e,t){const r=await fetch(kt(s),{...t,method:"POST",headers:{"Content-Type":"application/json",...t?.headers},body:e?JSON.stringify(e):void 0});if(!r.ok){const a=await Rt(r);throw new Error(a)}return r.body}async function Qr(s,e,t){const r=await fetch(kt(s),{...t,method:"POST",headers:{"Content-Type":"application/json",...t?.headers},body:e?JSON.stringify(e):void 0});if(!r.ok){let a;try{a=await r.json()}catch{}const l=await Rt(r);throw Jr(l,r,a)}return r.json()}async function Zl(s,e,t){const r=await fetch(kt(s),{...t,method:"PUT",headers:{"Content-Type":"application/json",...t?.headers},body:e?JSON.stringify(e):void 0});if(!r.ok){let a;try{a=await r.json()}catch{}const l=await Rt(r);throw Jr(l,r,a)}return r.json()}function ue(...s){return s.map(e=>encodeURIComponent(String(e))).join("/")}async function Cn(){return ye("api/scaffold/templates")}async function Yr(s,e,t){return ts("api/scaffold",{projectName:s,templateId:e,packageManager:t})}async function un(){return ye("api/providers")}async function eo(s){return ye(`api/providers/${ue(s)}/credits`)}async function to(s,e){await Se("api/providers/keys",{providerName:s,apiKey:e})}async function so(s){await Se("api/providers/bulk-keys",{keys:s})}async function no(){return(await ye("api/programs")).programs||[]}async function ro(){return(await ye("api/threads/processing")).processingThreadIds||[]}async function ao(){try{return(await ye("api/git/username")).name||""}catch{return""}}async function ws(){const e=(await ye("api/projects")||[]).map(r=>{const a=r;return{projectId:a.projectId??a.id,name:a.name,gitUrl:a.gitUrl,projectPath:a.projectPath??a.path,threads:a.threads||[],commands:a.commands||[],setupScript:a.setupScript,runCommand:a.runCommand}});return{projects:await Promise.all(e.map(async r=>{try{const l=(await ye(`api/threads?projectId=${encodeURIComponent(String(r.projectId))}`)||[]).map(o=>{const i=o,c=i.threadId??i.id;return{threadId:c,title:i.title||c,path:i.path||"",currentBranch:i.currentBranch||"",isSelected:!!i.isSelected}});return{...r,threads:l}}catch{return{...r,threads:(r.threads||[]).map(a=>({threadId:a,title:a,path:"",currentBranch:"",isSelected:!1}))}}}))}}async function Xr(s,e){return ts("api/projects",{gitUrl:s,commitMethod:e})}async function lo(s){return ye(`api/projects/${ue(s)}`)}async function oo(s){await Ds(`api/projects/${ue(s)}`)}async function io(s,e){return ts("api/threads",{projectId:s,title:e})}async function co(s,e){await Ds(`api/threads/${ue(e)}`)}async function uo(s,e){await Yl(`api/threads/${ue(s)}`,e)}async function mo(s,e){await Se(`api/threads/${ue(e)}/select`)}async function fo(s){const e=await ye(`api/threads/${ue(s)}/messages`);return{threadId:s,messages:e}}async function po(s){return(await ye(`api/threads/${ue(s)}/conversation-folder-path`)).path}async function ho(s,e,t,r=[],a,l){const o={threadId:s,content:e,model:t,provider:l,attachments:r.map(i=>({name:i.fileName,content:i.content.split(",")[1]||i.content,size:0,mimeType:"application/octet-stream"}))};return ts("api/chat",o,{signal:a})}async function go(s){return(await Ds(`api/chat/${ue(s)}`))?.conversationId||""}function xo(s,e,t,r,a){const l=s.getReader();let o=!1;const i=()=>{o=!0,l.cancel().catch(()=>{})},c=new TextDecoder;let d="";const u=h=>h?[/^Cannot read properties/i,/^Error:/i,/^TypeError:/i,/^ReferenceError:/i,/^SyntaxError:/i,/^failed to/i,/^error:/i,/forbidden/i,/unauthorized/i].some(p=>p.test(h.trim())):!1;async function f(){try{for(;!o;){const{done:h,value:g}=await l.read();if(h||o){if(!o&&h){if(d.trim())try{const j=JSON.parse(d);j.type==="error"?r(j.content||"Unknown error"):j.type==="message"?a?.({role:j.role||"assistant",content:j.content||""}):j.type==="complete"||(j.type==="result"&&u(j.content)?r(j.content||"Unknown error"):e(j))}catch{d.trim()&&e({type:"result",content:d})}t()}break}d+=c.decode(g,{stream:!0});const p=d.split(`
3
+ `);d=p.pop()||"";for(const j of p){const v=j.trim();if(v)try{const b=JSON.parse(v);if(b.type==="error"){r(b.content||"Unknown error"),t();return}else if(b.type==="message")a?.({role:b.role||"assistant",content:b.content||""});else if(b.type==="complete"){t();return}else if(b.type==="result"&&u(b.content)){r(b.content||"Unknown error"),t();return}else e(b)}catch{}}}}catch(h){r(h instanceof Error?h.message:"Stream error")}}return f(),i}async function vs(s,e){return e.runNow&&e.setupScript?Xl(`api/projects/${ue(s)}`,e):(await Zl(`api/projects/${ue(s)}`,e),null)}async function jo(s,e){await Qr(`api/projects/${ue(s)}/open`,{program:e})}async function yo(s,e){await Qr(`api/threads/${ue(s)}/open`,{program:e})}async function bo(s,e){await vs(s,{program:e})}async function Zr(s,e,t){return vs(s,{setupScript:e,runNow:t})}async function vo(s,e){await vs(s,{name:e})}async function mn(s,e){const t=new URLSearchParams({provider:s});return((await ye(`api/models?${t.toString()}`)).models||[]).filter(l=>{const o=l.name.toLowerCase().trim(),i=At(l.id).toLowerCase().trim();return o!=="free"&&o!=="auto"&&i!=="free"&&i!=="auto"})}async function ea(s,e){await Se(`api/models/${ue(s,e)}/enable`)}async function No(s,e){await Se(`api/models/${ue(s,e)}/disable`)}async function Ps(){const e=(await ye("api/models/enabled")).enabledModels||{},t={};for(const[r,a]of Object.entries(e))t[r]=a.filter(l=>{const o=l.name.toLowerCase().trim(),i=At(l.id).toLowerCase().trim();return o!=="free"&&o!=="auto"&&i!=="free"&&i!=="auto"});return t}async function wo(s){return ye(`api/git/status/${ue(s)}`)}async function So(s,e,t){return(await Se(`api/git/generate-commit-message/${ue(s)}`,{model:e,provider:t})).message}async function Co(s,e){await Se(`api/git/commit/${ue(s)}`,{message:e})}async function Tn(s){await Se(`api/git/push/${ue(s)}`)}async function To(s,e,t){return Se(`api/git/generate-pr-info/${ue(s)}`,{model:e,provider:t})}async function In(s,e,t){return Se(`api/git/create-pr/${ue(s)}`,{title:e,description:t})}async function Io(s){await Se(`api/git/fetch/${ue(s)}`)}async function ko(s,e=50){return(await ye(`api/git/log/${ue(s)}?limit=${e}`)).commits}async function Ro(s){return ye(`api/git/github-status/${ue(s)}`)}async function Eo(s,e,t,r){return Se(`api/git/create-repo/${ue(s)}`,{repoName:e,description:t,isPrivate:r})}async function _o(s,e){await Se(`api/projects/${ue(s)}/commands`,e)}async function Po(s,e){await Ds(`api/projects/${ue(s)}/commands/${ue(e)}`)}async function Mo(s,e,t,r){return ts(`api/projects/${ue(s)}/threads/${ue(e)}/commands/run`,{commandLine:t,cwd:r})}async function Do(s){return ye(`api/threads/${ue(s)}/files`)}async function Ao(s){return Se(`api/projects/${ue(s)}/run-suggest`,{})}async function Lo(s){return ts(`api/projects/${ue(s)}/run`,{})}async function $o(s){return Se(`api/projects/${ue(s)}/stop`,{})}async function Oo(s){return ye(`api/projects/${ue(s)}/running`)}async function Fo(s,e){await vs(s,{runCommand:e})}async function Go(s){return ye(`api/git/diff/${ue(s)}`)}async function Ho(){return ye("api/onboarding/status")}async function Uo(){return ye("api/onboarding/git-check")}async function kn(){return Se("api/onboarding/complete",{})}async function zo(){return Se("api/onboarding/reset",{})}async function Bo(s){const e=await ye(`api/slash-commands?threadId=${ue(s)}`);return{commands:e.commands||[],skills:e.skills||[]}}async function ta(s){return ye(`api/conversations/${ue(s)}`)}async function qo(s,e){await Se("api/ask-user/respond",{toolCallId:s,answer:e})}function ss(s){return typeof localStorage>"u"?null:localStorage.getItem(s)}function ns(s,e){typeof localStorage>"u"||localStorage.setItem(s,e)}function Wo(s){return typeof sessionStorage>"u"?null:sessionStorage.getItem(s)}function Vo(s,e){typeof sessionStorage>"u"||sessionStorage.setItem(s,e)}function Ko(s="npm"){return ss("tarsk.create-project.packageManager")||s}function Jo(s){ns("tarsk.create-project.packageManager",s)}function Qo(s="pull-request"){return ss("tarsk.create-project.commitMethod")||s}function Rn(s){ns("tarsk.create-project.commitMethod",s)}function Yo(s=""){return ss("tarsk.create-project.templateId")||s}function Xo(s){ns("tarsk.create-project.templateId",s)}function Zo(s=!1){const e=ss("autoGenerateCommitMessage");return e!==null?e==="true":s}function ei(s){ns("autoGenerateCommitMessage",s.toString())}function ti(s=!1){const e=ss("privateRepositoryDefault");return e!==null?e==="true":s}function si(s){ns("privateRepositoryDefault",s.toString())}function En(s){const e="selected-model-"+s;return ss(e)}function ni(s,e){const t="selected-model-"+s;ns(t,e)}function sa(){const s=Wo("chat_message_history");return s?JSON.parse(s):[]}function ri(s){const e=sa();s.trim()&&e[e.length-1]!==s&&(e.push(s),Vo("chat_message_history",JSON.stringify(e)))}function ai({initialValue:s}={}){const{state:e,dispatch:t}=Ce(),[r,a]=m.useState(s||""),[l,o]=m.useState(-1),[i,c]=m.useState(""),[d,u]=m.useState(0),[f,h]=m.useState(ls),[g,p]=m.useState(ls[0]),j=m.useRef(g.id),[v,b]=m.useState(!1),[I,T]=m.useState(!1),[x,C]=m.useState([]),[_,w]=m.useState(!1),[k,N]=m.useState([]),[y,S]=m.useState(!1),[R,E]=m.useState(""),[A,M]=m.useState(0),[z,O]=m.useState([]),[L,$]=m.useState([]),[q,G]=m.useState(!1),[K,X]=m.useState(""),de=m.useRef(null),ie=m.useRef(null),re=m.useRef(null),ae=m.useRef(null),le=m.useRef(null),ce=m.useRef(null);m.useEffect(()=>{j.current=g.id},[g.id]),m.useEffect(()=>{(async()=>{try{const H=await Ps(),V=Object.values(H).flat();if(V.length>0){h(V);const Z=e.selectedProjectId?En(e.selectedProjectId):null,Y=(Z?V.find(W=>W.id===Z):null)||V[0];Y.id!==g.id&&p(Y)}}catch(H){console.error("Failed to load enabled models:",H),h(ls);const V=e.selectedProjectId?En(e.selectedProjectId):null,ee=(V?ls.find(Y=>Y.id===V):null)||ls[0];ee.id!==g.id&&p(ee)}})()},[e.selectedProjectId,g.id]),m.useEffect(()=>{if(e.configUpdatedAt===0)return;(async()=>{try{const H=await Ps(),V=Object.values(H).flat();if(V.length>0){h(V);const Z=j.current;V.some(Y=>Y.id===Z)||p(V[0])}}catch(H){console.error("Failed to reload enabled models:",H)}})()},[e.configUpdatedAt,e.selectedProjectId]);const[te,se]=m.useState(e.selectedThreadId);return m.useEffect(()=>{e.selectedThreadId!==te&&setTimeout(()=>{se(e.selectedThreadId),N([]),S(!1),O([]),$([]),G(!1)},0)},[e.selectedThreadId,te]),m.useEffect(()=>{e.selectedThreadId&&Bo(e.selectedThreadId).then(({commands:U,skills:H})=>{console.log("Loaded slash commands:",U,"skills:",H),O(U),$(H)}).catch(U=>console.error("Failed to load slash commands and skills:",U))},[e.selectedThreadId]),m.useEffect(()=>{e.focusChatInput&&e.selectedThreadId&&!e.isStreaming&&(ie.current?.focus(),t({type:P.ClearFocusChatInput}))},[e.focusChatInput,e.selectedThreadId,e.isStreaming,t]),m.useEffect(()=>{const U=H=>{re.current&&!re.current.contains(H.target)&&b(!1),ae.current&&!ae.current.contains(H.target)&&T(!1)};if(v||I)return document.addEventListener("mousedown",U),()=>{document.removeEventListener("mousedown",U)}},[v,I]),{message:r,setMessage:a,historyIndex:l,setHistoryIndex:o,draftMessage:i,setDraftMessage:c,cursorPosition:d,setCursorPosition:u,availableModels:f,setAvailableModels:h,selectedModel:g,setSelectedModel:p,selectedModelIdRef:j,showModelMenu:v,setShowModelMenu:b,showPlusMenu:I,setShowPlusMenu:T,attachments:x,setAttachments:C,planMode:_,setPlanMode:w,allFiles:k,setAllFiles:N,showSuggestions:y,setShowSuggestions:S,suggestionQuery:R,setSuggestionQuery:E,selectedIndex:A,setSelectedIndex:M,slashCommands:z,setSlashCommands:O,skills:L,setSkills:$,showCommandSuggestions:q,setShowCommandSuggestions:G,commandQuery:K,setCommandQuery:X,fileInputRef:de,textareaRef:ie,modelMenuRef:re,plusMenuRef:ae,suggestionsRef:le,commandSuggestionsRef:ce,handleNewChat:async()=>{if(e.selectedThreadId)try{const U=await go(e.selectedThreadId);t({type:P.ClearMessages}),console.log("New conversation started:",U)}catch(U){console.error("Failed to start new chat:",U)}},state:e,dispatch:t}}const li=s=>{ri(s)};function oi(s){const e=F.c(95),{message:t,setMessage:r,attachments:a,selectedModel:l,onSend:o,isStreaming:i,selectedThreadId:c,isListening:d,stopListening:u,resetTranscript:f,dispatch:h,historyIndex:g,setHistoryIndex:p,draftMessage:j,setDraftMessage:v,cursorPosition:b,setCursorPosition:I,showSuggestions:T,setShowSuggestions:x,suggestionQuery:C,setSuggestionQuery:_,allFiles:w,setAllFiles:k,selectedIndex:N,setSelectedIndex:y,showCommandSuggestions:S,setShowCommandSuggestions:R,commandQuery:E,setCommandQuery:A,slashCommands:M,skills:z,textareaRef:O,setPlanMode:L}=s;let $;e[0]!==a||e[1]!==h||e[2]!==d||e[3]!==i||e[4]!==t||e[5]!==o||e[6]!==f||e[7]!==l||e[8]!==c||e[9]!==v||e[10]!==p||e[11]!==r||e[12]!==u||e[13]!==O?($=()=>{!t.trim()&&a.length===0||c&&(d&&(u(),f()),i?h({type:P.EnqueueChatMessage,message:{id:`queued-${Date.now()}`,threadId:c,message:t,model:l.id,attachments:a,provider:l.provider}}):o(t,l.id,a,l.provider),li(t),r(""),p(-1),v(""),O.current&&(O.current.style.height="auto"))},e[0]=a,e[1]=h,e[2]=d,e[3]=i,e[4]=t,e[5]=o,e[6]=f,e[7]=l,e[8]=c,e[9]=v,e[10]=p,e[11]=r,e[12]=u,e[13]=O,e[14]=$):$=e[14];const q=$;let G;e[15]!==b||e[16]!==t||e[17]!==r||e[18]!==x||e[19]!==C||e[20]!==O?(G=D=>{const U=t.substring(0,b-C.length-1),H=t.substring(b),V=`${U}${D} ${H}`;r(V),x(!1),setTimeout(()=>{if(O.current){O.current.focus();const Z=U.length+D.length+1;O.current.setSelectionRange(Z,Z)}},0)},e[15]=b,e[16]=t,e[17]=r,e[18]=x,e[19]=C,e[20]=O,e[21]=G):G=e[21];const K=G;let X;e[22]!==E||e[23]!==b||e[24]!==t||e[25]!==r||e[26]!==L||e[27]!==R||e[28]!==O?(X=D=>{const U=t.substring(0,b-E.length-1),H=t.substring(b),V=`${U}${D.content}${H}`;r(V),R(!1),setTimeout(()=>{if(O.current){O.current.focus();const Z=U.length+D.content.length;O.current.setSelectionRange(Z,Z)}},0),D.metadata.mode==="plan"&&L(!0)},e[22]=E,e[23]=b,e[24]=t,e[25]=r,e[26]=L,e[27]=R,e[28]=O,e[29]=X):X=e[29];const de=X;let ie;e[30]!==E||e[31]!==b||e[32]!==t||e[33]!==r||e[34]!==R||e[35]!==O?(ie=D=>{const U=t.substring(0,b-E.length-1),H=t.substring(b),V=`Use the "${D.name}" skill to help with this task.`,Z=`${U}${V}${H}`;r(Z),R(!1),setTimeout(()=>{if(O.current){O.current.focus();const ee=U.length+V.length;O.current.setSelectionRange(ee,ee)}},0)},e[30]=E,e[31]=b,e[32]=t,e[33]=r,e[34]=R,e[35]=O,e[36]=ie):ie=e[36];const re=ie;let ae,le,ce,te;if(e[37]!==w||e[38]!==E||e[39]!==j||e[40]!==q||e[41]!==g||e[42]!==de||e[43]!==K||e[44]!==re||e[45]!==t||e[46]!==N||e[47]!==c||e[48]!==k||e[49]!==A||e[50]!==I||e[51]!==v||e[52]!==p||e[53]!==r||e[54]!==y||e[55]!==R||e[56]!==x||e[57]!==_||e[58]!==S||e[59]!==T||e[60]!==z||e[61]!==M||e[62]!==C){ce=H=>{if(S){if(H.key==="ArrowDown"){H.preventDefault(),y((N+1)%ae.length);return}if(H.key==="ArrowUp"){H.preventDefault(),y((N-1+ae.length)%ae.length);return}if(H.key==="Enter"||H.key==="Tab"){H.preventDefault();const Z=ae[N];Z&&(Z.type==="command"?de(Z.data):re(Z.data));return}if(H.key==="Escape"){R(!1);return}}if(T){const Z=le.length>0;if(H.key==="ArrowDown"&&Z){H.preventDefault(),y((N+1)%le.length);return}if(H.key==="ArrowUp"&&Z){H.preventDefault(),y((N-1+le.length)%le.length);return}if(H.key==="Enter"||H.key==="Tab"){H.preventDefault(),le[N]&&K(le[N]);return}if(H.key==="Escape"){x(!1);return}}if(H.key==="Enter"&&!H.shiftKey){H.preventDefault(),q();return}const V=sa();V.length!==0&&(H.key==="ArrowUp"?(H.preventDefault(),g===-1?(v(t),p(V.length-1),r(V[V.length-1])):g>0&&(p(g-1),r(V[g-1]))):H.key==="ArrowDown"&&(H.preventDefault(),g>0?(p(g-1),r(V[g-1])):g===0&&(p(-1),r(j))))};let D;e[67]!==w||e[68]!==c||e[69]!==k||e[70]!==A||e[71]!==I||e[72]!==r||e[73]!==y||e[74]!==R||e[75]!==x||e[76]!==_?(D=H=>{const V=H.target.value,Z=H.target.selectionStart;r(V),I(Z);const ee=V.substring(0,Z),Y=ee.lastIndexOf("/");if(Y!==-1){const oe=Y>0?ee[Y-1]:"";if(Y===0||/\s/.test(oe)){const Ne=ee.substring(Y+1);Ne.includes(" ")?R(!1):(A(Ne),R(!0),x(!1),y(0))}else R(!1)}else{R(!1);const oe=ee.lastIndexOf("#");if(oe!==-1){const Te=oe>0?ee[oe-1]:"";if(oe===0||/\s/.test(Te)){const Be=ee.substring(oe+1);Be.includes(" ")?x(!1):(_(Be),x(!0),y(0),w.length===0&&c&&Do(c).then(Ze=>{k(Ze)}).catch(di))}else x(!1)}else x(!1)}const W=H.target;W.style.height="auto",W.style.height=`${Math.min(W.scrollHeight,160)}px`},e[67]=w,e[68]=c,e[69]=k,e[70]=A,e[71]=I,e[72]=r,e[73]=y,e[74]=R,e[75]=x,e[76]=_,e[77]=D):D=e[77],te=D;let U;if(e[78]!==E||e[79]!==z||e[80]!==M){let H;e[82]!==E?(H=Y=>Y.name.toLowerCase().includes(E.toLowerCase()),e[82]=E,e[83]=H):H=e[83];const V=M.filter(H);let Z;e[84]!==E?(Z=Y=>Y.name.toLowerCase().includes(E.toLowerCase()),e[84]=E,e[85]=Z):Z=e[85];const ee=z.filter(Z);U=[...V.map(ci),...ee.map(ii)],e[78]=E,e[79]=z,e[80]=M,e[81]=U}else U=e[81];ae=U.slice(0,10),le=T?w.filter(H=>H.toLowerCase().includes(C.toLowerCase())).slice(0,10):[],e[37]=w,e[38]=E,e[39]=j,e[40]=q,e[41]=g,e[42]=de,e[43]=K,e[44]=re,e[45]=t,e[46]=N,e[47]=c,e[48]=k,e[49]=A,e[50]=I,e[51]=v,e[52]=p,e[53]=r,e[54]=y,e[55]=R,e[56]=x,e[57]=_,e[58]=S,e[59]=T,e[60]=z,e[61]=M,e[62]=C,e[63]=ae,e[64]=le,e[65]=ce,e[66]=te}else ae=e[63],le=e[64],ce=e[65],te=e[66];let se;return e[86]!==ae||e[87]!==le||e[88]!==ce||e[89]!==q||e[90]!==te||e[91]!==de||e[92]!==K||e[93]!==re?(se={handleSend:q,handleKeyDown:ce,handleTextareaInput:te,insertFileReference:K,insertCommand:de,insertSkill:re,allSuggestions:ae,fileSuggestions:le},e[86]=ae,e[87]=le,e[88]=ce,e[89]=q,e[90]=te,e[91]=de,e[92]=K,e[93]=re,e[94]=se):se=e[94],se}function ii(s){return{type:"skill",data:s}}function ci(s){return{type:"command",data:s}}function di(s){return console.error("Failed to fetch files:",s)}function ui(s){const e=F.c(21),{visible:t,commands:r,skills:a,query:l,selectedIndex:o,onSelectCommand:i,onSelectSkill:c,onMouseEnterSuggestion:d,containerRef:u}=s;if(!t)return null;let f;if(e[0]!==r||e[1]!==l||e[2]!==a){let I;e[4]!==l?(I=_=>_.name.toLowerCase().includes(l.toLowerCase()),e[4]=l,e[5]=I):I=e[5];const T=r.filter(I);let x;e[6]!==l?(x=_=>_.name.toLowerCase().includes(l.toLowerCase()),e[6]=l,e[7]=x):x=e[7];const C=a.filter(x);f=[...T.map(fi),...C.map(mi)].slice(0,10),e[0]=r,e[1]=l,e[2]=a,e[3]=f}else f=e[3];const h=f;let g;e[8]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx(ds,{className:"h-3 w-3"}),e[8]=g):g=e[8];const p=l&&` matching "${l}"`;let j;e[9]!==p?(j=n.jsxs("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground border-b border-border/50 mb-1 flex items-center gap-2",children:[g,"Commands & Skills",p]}),e[9]=p,e[10]=j):j=e[10];let v;e[11]!==h||e[12]!==d||e[13]!==i||e[14]!==c||e[15]!==o?(v=h.length>0?h.map((I,T)=>{const x=T===o;if(I.type==="command"){const C=I.data;return n.jsxs("button",{type:"button",className:B("flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors",x?"bg-accent text-accent-foreground":"text-popover-foreground hover:bg-accent/50"),onClick:()=>i(C),onMouseEnter:()=>d(T),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(ds,{className:"h-3 w-3 text-muted-foreground"}),n.jsxs("span",{className:"font-medium",children:["/",C.name]}),C.metadata.argumentHint&&n.jsx("span",{className:"text-xs text-muted-foreground",children:C.metadata.argumentHint}),C.scope==="project"&&n.jsx("span",{className:"ml-auto text-[10px] rounded-full bg-primary/10 px-1.5 py-0.5 text-primary",children:"project"})]}),C.metadata.description&&n.jsx("span",{className:"text-xs text-muted-foreground",children:C.metadata.description})]},`cmd-${C.name}`)}else{const C=I.data;return n.jsxs("button",{type:"button",className:B("flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors",x?"bg-accent text-accent-foreground":"text-popover-foreground hover:bg-accent/50"),onClick:()=>c(C),onMouseEnter:()=>d(T),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(rn,{className:"h-3 w-3 text-amber-500"}),n.jsxs("span",{className:"font-medium",children:["/",C.name]}),n.jsx("span",{className:"ml-auto text-[10px] rounded-full bg-amber-500/10 px-1.5 py-0.5 text-amber-700 dark:text-amber-400",children:"skill"}),C.scope==="project"&&n.jsx("span",{className:"text-[10px] rounded-full bg-primary/10 px-1.5 py-0.5 text-primary",children:"project"})]}),n.jsx("span",{className:"text-xs text-muted-foreground",children:C.description})]},`skill-${C.name}`)}}):n.jsxs("div",{className:"px-3 py-4 text-center text-xs text-muted-foreground",children:["No commands or skills found.",n.jsx("br",{}),n.jsxs("span",{className:"text-[10px]",children:["Create commands in ",n.jsx("code",{className:"bg-muted px-1 rounded",children:"~/.tarsk/commands/"})," or skills in ",n.jsx("code",{className:"bg-muted px-1 rounded",children:"~/.tarsk/skills/"})]})]}),e[11]=h,e[12]=d,e[13]=i,e[14]=c,e[15]=o,e[16]=v):v=e[16];let b;return e[17]!==u||e[18]!==j||e[19]!==v?(b=n.jsxs("div",{ref:u,className:"absolute bottom-full left-0 mb-2 w-full max-h-64 overflow-y-auto rounded-xl border border-border bg-popover p-1 shadow-lg z-50 animate-in fade-in slide-in-from-bottom-2",children:[j,v]}),e[17]=u,e[18]=j,e[19]=v,e[20]=b):b=e[20],b}function mi(s){return{type:"skill",data:s}}function fi(s){return{type:"command",data:s}}function pi(s){const e=F.c(7),{attachments:t,onRemove:r}=s;if(t.length===0)return null;let a;if(e[0]!==t||e[1]!==r){let o;e[3]!==r?(o=(i,c)=>n.jsxs("span",{className:"flex items-center gap-1 rounded-md bg-muted px-2 py-1 text-xs text-muted-foreground",children:[n.jsx(an,{className:"h-3 w-3"}),i.fileName,n.jsxs("button",{type:"button",onClick:()=>r(c),className:"ml-1 hover:text-foreground",children:[n.jsx(mt,{className:"h-3 w-3"}),n.jsx("span",{className:"sr-only",children:"Remove attachment"})]})]},c),e[3]=r,e[4]=o):o=e[4],a=t.map(o),e[0]=t,e[1]=r,e[2]=a}else a=e[2];let l;return e[5]!==a?(l=n.jsx("div",{className:"mb-2 flex flex-wrap gap-1.5",children:a}),e[5]=a,e[6]=l):l=e[6],l}function hi(s,e){const t=s.target.files;if(!t)return;const r=[];Array.from(t).forEach(a=>{const l=new FileReader;l.onload=()=>{const o=l.result.split(",")[1];r.push({fileName:a.name,content:o}),r.length===t.length&&e(r)},l.readAsDataURL(a)}),s.target.value=""}function gi(s){const e=F.c(16),{showSuggestions:t,fileSuggestions:r,suggestionQuery:a,selectedIndex:l,onSelectFile:o,onMouseEnterSuggestion:i,containerRef:c}=s;if(!t||r.length===0)return null;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(Es,{className:"h-3 w-3"}),e[0]=d):d=e[0];let u;e[1]!==a?(u=n.jsxs("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground border-b border-border/50 mb-1 flex items-center gap-2",children:[d,'Files matching "',a,'"']}),e[1]=a,e[2]=u):u=e[2];let f;if(e[3]!==r||e[4]!==i||e[5]!==o||e[6]!==l){let g;e[8]!==i||e[9]!==o||e[10]!==l?(g=(p,j)=>{const v=p.split("/").pop()||p,b=j===l;return n.jsxs("button",{type:"button",className:B("flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-left transition-colors",b?"bg-accent text-accent-foreground":"text-popover-foreground hover:bg-accent/50"),onClick:()=>o(p),onMouseEnter:()=>i(j),children:[p.endsWith(".ts")||p.endsWith(".tsx")||p.endsWith(".js")||p.endsWith(".jsx")?n.jsx(La,{className:"h-4 w-4 text-blue-500"}):n.jsx($a,{className:"h-4 w-4 text-muted-foreground"}),n.jsxs("div",{className:"flex flex-col overflow-hidden",children:[n.jsx("span",{className:"truncate font-medium",children:v}),n.jsx("span",{className:"truncate text-[10px] text-muted-foreground opacity-70",children:p})]})]},p)},e[8]=i,e[9]=o,e[10]=l,e[11]=g):g=e[11],f=r.map(g),e[3]=r,e[4]=i,e[5]=o,e[6]=l,e[7]=f}else f=e[7];let h;return e[12]!==c||e[13]!==u||e[14]!==f?(h=n.jsxs("div",{ref:c,className:"absolute bottom-full left-0 mb-2 w-full max-h-64 overflow-y-auto rounded-xl border border-border bg-popover p-1 shadow-lg z-50 animate-in fade-in slide-in-from-bottom-2",children:[u,f]}),e[12]=c,e[13]=u,e[14]=f,e[15]=h):h=e[15],h}function xi(s){const e=F.c(22),{availableModels:t,selectedModel:r,onModelSelect:a,selectedProjectId:l}=s,[o,i]=Tt.useState(!1),c=Tt.useRef(null),d=ji;let u,f;e[0]!==o?(u=()=>{const x=C=>{c.current&&!c.current.contains(C.target)&&i(!1)};if(o)return document.addEventListener("mousedown",x),()=>{document.removeEventListener("mousedown",x)}},f=[o],e[0]=o,e[1]=u,e[2]=f):(u=e[1],f=e[2]),Tt.useEffect(u,f);let h;e[3]!==a||e[4]!==l?(h=x=>{a(x),l&&ni(l,x.id),i(!1)},e[3]=a,e[4]=l,e[5]=h):h=e[5];const g=h;let p;e[6]!==o?(p=()=>i(!o),e[6]=o,e[7]=p):p=e[7];let j;e[8]!==r?(j=d(r),e[8]=r,e[9]=j):j=e[9];let v;e[10]===Symbol.for("react.memo_cache_sentinel")?(v=n.jsx(It,{className:"h-3 w-3"}),e[10]=v):v=e[10];let b;e[11]!==p||e[12]!==j?(b=n.jsxs("button",{type:"button",className:"flex items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",onClick:p,children:[j,v]}),e[11]=p,e[12]=j,e[13]=b):b=e[13];let I;e[14]!==t||e[15]!==g||e[16]!==r||e[17]!==o?(I=o&&n.jsx("div",{className:"absolute bottom-full left-0 mb-1 w-80 rounded-lg border border-border bg-popover p-1 shadow-md z-50 overflow-hidden",children:t.map(x=>n.jsx("button",{type:"button",className:`flex w-full items-center whitespace-nowrap rounded-md px-3 py-2 text-sm text-popover-foreground hover:bg-accent ${x.id===r.id?"bg-accent font-medium":""}`,onClick:()=>g(x),children:d(x)},x.id))}),e[14]=t,e[15]=g,e[16]=r,e[17]=o,e[18]=I):I=e[18];let T;return e[19]!==b||e[20]!==I?(T=n.jsxs("div",{className:"relative",ref:c,children:[b,I]}),e[19]=b,e[20]=I,e[21]=T):T=e[21],T}function ji(s){const e=At(s.id);return s.provider?`${e} (${s.provider})`:e}function yi(s){const e=F.c(23),{onFileAttach:t,onPlanModeToggle:r,onNewChat:a}=s,[l,o]=Tt.useState(!1),i=Tt.useRef(null);let c,d;e[0]!==l?(c=()=>{const _=w=>{i.current&&!i.current.contains(w.target)&&o(!1)};if(l)return document.addEventListener("mousedown",_),()=>{document.removeEventListener("mousedown",_)}},d=[l],e[0]=l,e[1]=c,e[2]=d):(c=e[1],d=e[2]),Tt.useEffect(c,d);let u;e[3]!==t?(u=()=>{t(),o(!1)},e[3]=t,e[4]=u):u=e[4];const f=u;let h;e[5]!==r?(h=()=>{r(),o(!1)},e[5]=r,e[6]=h):h=e[6];const g=h;let p;e[7]!==a?(p=()=>{o(!1),a()},e[7]=a,e[8]=p):p=e[8];const j=p;let v;e[9]!==l?(v=()=>o(!l),e[9]=l,e[10]=v):v=e[10];let b,I;e[11]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsx(gs,{className:"h-4 w-4"}),I=n.jsx("span",{className:"sr-only",children:"More options"}),e[11]=b,e[12]=I):(b=e[11],I=e[12]);let T;e[13]!==v?(T=n.jsxs(J,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:v,children:[b,I]}),e[13]=v,e[14]=T):T=e[14];let x;e[15]!==f||e[16]!==j||e[17]!==g||e[18]!==l?(x=l&&n.jsxs("div",{className:"absolute bottom-full left-0 mb-1 w-48 rounded-lg border border-border bg-popover p-1 shadow-md z-50",children:[n.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 rounded-md px-3 py-2 text-sm text-popover-foreground hover:bg-accent",onClick:f,children:[n.jsx(an,{className:"h-3.5 w-3.5"}),"Attach File"]}),n.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 rounded-md px-3 py-2 text-sm text-popover-foreground hover:bg-accent",onClick:g,children:[n.jsx(Bn,{className:"h-3.5 w-3.5"}),"Plan Mode"]}),n.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 rounded-md px-3 py-2 text-sm text-popover-foreground hover:bg-accent",onClick:j,children:[n.jsx(Oa,{className:"h-3.5 w-3.5"}),"New Chat"]})]}),e[15]=f,e[16]=j,e[17]=g,e[18]=l,e[19]=x):x=e[19];let C;return e[20]!==x||e[21]!==T?(C=n.jsxs("div",{className:"relative",ref:i,children:[T,x]}),e[20]=x,e[21]=T,e[22]=C):C=e[22],C}function bi(s){const e=F.c(14),{onToggleSpeech:t}=s,{isListening:r,isSupported:a}=Vr();if(!a)return null;const l=`h-7 w-7 ${r?"bg-red-500/20 text-red-500 hover:bg-red-500/30":"text-muted-foreground hover:text-foreground"}`;let o;e[0]!==r?(o=r?n.jsx(Fa,{className:"h-4 w-4"}):n.jsx(Ga,{className:"h-4 w-4"}),e[0]=r,e[1]=o):o=e[1];const i=r?"Stop listening":"Start listening";let c;e[2]!==i?(c=n.jsx("span",{className:"sr-only",children:i}),e[2]=i,e[3]=c):c=e[3];let d;e[4]!==t||e[5]!==l||e[6]!==o||e[7]!==c?(d=n.jsx(pe,{asChild:!0,children:n.jsxs(J,{variant:"ghost",size:"icon",className:l,onClick:t,children:[o,c]})}),e[4]=t,e[5]=l,e[6]=o,e[7]=c,e[8]=d):d=e[8];const u=r?"Stop listening":"Start listening";let f;e[9]!==u?(f=n.jsx(me,{side:"top",className:"bg-popover text-popover-foreground",children:u}),e[9]=u,e[10]=f):f=e[10];let h;return e[11]!==d||e[12]!==f?(h=n.jsxs(fe,{children:[d,f]}),e[11]=d,e[12]=f,e[13]=h):h=e[13],h}function vi(s){const e=F.c(8),{queuedMessages:t,onRemoveQueuedMessage:r}=s;if(t.length===0)return null;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Queued messages"}),e[0]=a):a=e[0];let l;if(e[1]!==r||e[2]!==t){let i;e[4]!==r?(i=c=>n.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-md border border-border/60 bg-background px-3 py-2 text-sm",children:[n.jsx("p",{className:"flex-1 whitespace-pre-wrap text-foreground",children:c.message}),n.jsx("button",{type:"button",className:"rounded-full p-1 text-muted-foreground hover:text-foreground",onClick:()=>r(c.id),"aria-label":"Remove queued message",children:n.jsx(mt,{className:"h-3.5 w-3.5"})})]},c.id),e[4]=r,e[5]=i):i=e[5],l=t.map(i),e[1]=r,e[2]=t,e[3]=l}else l=e[3];let o;return e[6]!==l?(o=n.jsxs("div",{className:"mb-3 rounded-lg border border-border/60 bg-muted/30 px-4 py-3",children:[a,n.jsx("div",{className:"mt-2 flex flex-col gap-2",children:l})]}),e[6]=l,e[7]=o):o=e[7],o}function Ni(s){const e=F.c(141),{onSend:t,onStop:r,isStreaming:a,disabled:l,initialValue:o,queuedMessages:i,onRemoveQueuedMessage:c}=s,d=a===void 0?!1:a,{isListening:u,transcript:f,startListening:h,stopListening:g,resetTranscript:p}=Vr();let j;e[0]!==o?(j={initialValue:o},e[0]=o,e[1]=j):j=e[1];const v=ai(j),{message:b,setMessage:I,historyIndex:T,setHistoryIndex:x,draftMessage:C,setDraftMessage:_,cursorPosition:w,setCursorPosition:k,availableModels:N,selectedModel:y,setSelectedModel:S,attachments:R,setAttachments:E,planMode:A,setPlanMode:M,allFiles:z,setAllFiles:O,showSuggestions:L,setShowSuggestions:$,suggestionQuery:q,setSuggestionQuery:G,selectedIndex:K,setSelectedIndex:X,slashCommands:de,skills:ie,showCommandSuggestions:re,setShowCommandSuggestions:ae,commandQuery:le,setCommandQuery:ce,fileInputRef:te,textareaRef:se,suggestionsRef:D,commandSuggestionsRef:U,handleNewChat:H,state:V,dispatch:Z}=v,ee=V.selectedThreadId||void 0;let Y;e[2]!==z||e[3]!==R||e[4]!==le||e[5]!==w||e[6]!==Z||e[7]!==C||e[8]!==T||e[9]!==u||e[10]!==d||e[11]!==b||e[12]!==t||e[13]!==A||e[14]!==p||e[15]!==K||e[16]!==y||e[17]!==O||e[18]!==ce||e[19]!==k||e[20]!==_||e[21]!==x||e[22]!==I||e[23]!==M||e[24]!==X||e[25]!==ae||e[26]!==$||e[27]!==G||e[28]!==re||e[29]!==L||e[30]!==ie||e[31]!==de||e[32]!==g||e[33]!==q||e[34]!==ee||e[35]!==se?(Y={message:b,setMessage:I,attachments:R,selectedModel:y,onSend:t,isStreaming:d,selectedThreadId:ee,isListening:u,stopListening:g,resetTranscript:p,dispatch:Z,historyIndex:T,setHistoryIndex:x,draftMessage:C,setDraftMessage:_,cursorPosition:w,setCursorPosition:k,showSuggestions:L,setShowSuggestions:$,suggestionQuery:q,setSuggestionQuery:G,allFiles:z,setAllFiles:O,selectedIndex:K,setSelectedIndex:X,showCommandSuggestions:re,setShowCommandSuggestions:ae,commandQuery:le,setCommandQuery:ce,slashCommands:de,skills:ie,textareaRef:se,planMode:A,setPlanMode:M},e[2]=z,e[3]=R,e[4]=le,e[5]=w,e[6]=Z,e[7]=C,e[8]=T,e[9]=u,e[10]=d,e[11]=b,e[12]=t,e[13]=A,e[14]=p,e[15]=K,e[16]=y,e[17]=O,e[18]=ce,e[19]=k,e[20]=_,e[21]=x,e[22]=I,e[23]=M,e[24]=X,e[25]=ae,e[26]=$,e[27]=G,e[28]=re,e[29]=L,e[30]=ie,e[31]=de,e[32]=g,e[33]=q,e[34]=ee,e[35]=se,e[36]=Y):Y=e[36];const W=oi(Y),{handleSend:oe,handleKeyDown:Te,handleTextareaInput:Ne,insertFileReference:Be,insertCommand:Ze,insertSkill:gt,fileSuggestions:Lt}=W,xt=Tt.useRef("");let jt,pt;e[37]!==I||e[38]!==f?(jt=()=>{if(f&&f!==xt.current){const dt=f.substring(xt.current.length);I(Ue=>(Ue.endsWith(" ")||Ue==="",Ue+dt)),xt.current=f}},pt=[f,I],e[37]=I,e[38]=f,e[39]=jt,e[40]=pt):(jt=e[39],pt=e[40]),Tt.useEffect(jt,pt);let yt;e[41]!==u||e[42]!==p||e[43]!==h||e[44]!==g?(yt=()=>{u?(g(),p()):(p(),h())},e[41]=u,e[42]=p,e[43]=h,e[44]=g,e[45]=yt):yt=e[45];const bt=yt;let Ie;e[46]!==E?(Ie=dt=>E(Ue=>Ue.filter((ht,as)=>as!==dt)),e[46]=E,e[47]=Ie):Ie=e[47];let qe;e[48]!==R||e[49]!==Ie?(qe=n.jsx(pi,{attachments:R,onRemove:Ie}),e[48]=R,e[49]=Ie,e[50]=qe):qe=e[50];let et;e[51]!==A||e[52]!==M?(et=A&&n.jsxs("div",{className:"mb-2 flex items-center gap-2 rounded-md bg-accent px-3 py-1.5",children:[n.jsx(Bn,{className:"h-3.5 w-3.5 text-accent-foreground"}),n.jsx("span",{className:"text-xs text-accent-foreground font-medium",children:"Plan Mode"}),n.jsxs("button",{type:"button",onClick:()=>M(!1),className:"ml-auto",children:[n.jsx(mt,{className:"h-3 w-3 text-accent-foreground"}),n.jsx("span",{className:"sr-only",children:"Exit plan mode"})]})]}),e[51]=A,e[52]=M,e[53]=et):et=e[53];let Re;e[54]!==c||e[55]!==i?(Re=n.jsx(vi,{queuedMessages:i,onRemoveQueuedMessage:c}),e[54]=c,e[55]=i,e[56]=Re):Re=e[56];let ne;e[57]!==l||e[58]!==Te||e[59]!==Ne||e[60]!==b||e[61]!==se?(ne=n.jsx("textarea",{ref:se,value:b,onChange:Ne,onKeyDown:Te,placeholder:"Ask Tarsk anything, # for files, / for commands & skills",rows:1,className:"w-full resize-none bg-transparent px-4 pt-3 pb-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none",disabled:l}),e[57]=l,e[58]=Te,e[59]=Ne,e[60]=b,e[61]=se,e[62]=ne):ne=e[62];let We;e[63]!==le||e[64]!==U||e[65]!==Ze||e[66]!==gt||e[67]!==K||e[68]!==X||e[69]!==re||e[70]!==ie||e[71]!==de?(We=n.jsx(ui,{visible:re,commands:de,skills:ie,query:le,selectedIndex:K,onSelectCommand:Ze,onSelectSkill:gt,onMouseEnterSuggestion:X,containerRef:U}),e[63]=le,e[64]=U,e[65]=Ze,e[66]=gt,e[67]=K,e[68]=X,e[69]=re,e[70]=ie,e[71]=de,e[72]=We):We=e[72];let ge;e[73]!==Lt||e[74]!==Be||e[75]!==K||e[76]!==X||e[77]!==L||e[78]!==q||e[79]!==D?(ge=n.jsx(gi,{showSuggestions:L,fileSuggestions:Lt,suggestionQuery:q,selectedIndex:K,onSelectFile:Be,onMouseEnterSuggestion:X,containerRef:D}),e[73]=Lt,e[74]=Be,e[75]=K,e[76]=X,e[77]=L,e[78]=q,e[79]=D,e[80]=ge):ge=e[80];let Ve;e[81]!==te?(Ve=()=>te.current?.click(),e[81]=te,e[82]=Ve):Ve=e[82];let tt;e[83]!==M?(tt=()=>M(!0),e[83]=M,e[84]=tt):tt=e[84];let Ee;e[85]!==H||e[86]!==Ve||e[87]!==tt?(Ee=n.jsx(yi,{onFileAttach:Ve,onPlanModeToggle:tt,onNewChat:H}),e[85]=H,e[86]=Ve,e[87]=tt,e[88]=Ee):Ee=e[88];let _e;e[89]!==bt?(_e=n.jsx(bi,{onToggleSpeech:bt}),e[89]=bt,e[90]=_e):_e=e[90];const Et=V.selectedProjectId||void 0;let Pe;e[91]!==N||e[92]!==y||e[93]!==S||e[94]!==Et?(Pe=n.jsx(xi,{availableModels:N,selectedModel:y,onModelSelect:S,selectedProjectId:Et}),e[91]=N,e[92]=y,e[93]=S,e[94]=Et,e[95]=Pe):Pe=e[95];let Me;e[96]!==Ee||e[97]!==_e||e[98]!==Pe?(Me=n.jsxs("div",{className:"flex items-center gap-1",children:[Ee,_e,Pe]}),e[96]=Ee,e[97]=_e,e[98]=Pe,e[99]=Me):Me=e[99];const _t=!d&&"bg-[url('/tarsk-color.svg')] bg-cover bg-center hover:opacity-80";let De;e[100]!==_t?(De=B("h-7 w-7 rounded-full",_t),e[100]=_t,e[101]=De):De=e[101];const st=d?r:oe;let nt;e[102]!==R||e[103]!==l||e[104]!==d||e[105]!==b?(nt=!d&&(l||!b.trim()&&R.length===0),e[102]=R,e[103]=l,e[104]=d,e[105]=b,e[106]=nt):nt=e[106];let Ae;e[107]!==d?(Ae=d&&n.jsx(qn,{className:"h-3 w-3 fill-current"}),e[107]=d,e[108]=Ae):Ae=e[108];const rt=d?"Stop generation":"Send message";let at;e[109]!==rt?(at=n.jsx("span",{className:"sr-only",children:rt}),e[109]=rt,e[110]=at):at=e[110];let Le;e[111]!==De||e[112]!==st||e[113]!==nt||e[114]!==Ae||e[115]!==at?(Le=n.jsx(pe,{asChild:!0,children:n.jsxs(J,{size:"icon",className:De,onClick:st,disabled:nt,children:[Ae,at]})}),e[111]=De,e[112]=st,e[113]=nt,e[114]=Ae,e[115]=at,e[116]=Le):Le=e[116];const lt=d?"Stop":"Send";let ot;e[117]!==lt?(ot=n.jsx(me,{side:"top",className:"bg-popover text-popover-foreground",children:lt}),e[117]=lt,e[118]=ot):ot=e[118];let $e;e[119]!==Le||e[120]!==ot?($e=n.jsxs(fe,{children:[Le,ot]}),e[119]=Le,e[120]=ot,e[121]=$e):$e=e[121];let Oe;e[122]!==Me||e[123]!==$e?(Oe=n.jsxs("div",{className:"flex items-center justify-between px-3 pb-2",children:[Me,$e]}),e[122]=Me,e[123]=$e,e[124]=Oe):Oe=e[124];let Fe;e[125]!==Re||e[126]!==ne||e[127]!==We||e[128]!==ge||e[129]!==Oe?(Fe=n.jsxs("div",{className:"flex flex-col rounded-2xl border border-border bg-background shadow-sm focus-within:ring-2 focus-within:ring-brand",children:[Re,ne,We,ge,Oe]}),e[125]=Re,e[126]=ne,e[127]=We,e[128]=ge,e[129]=Oe,e[130]=Fe):Fe=e[130];let it;e[131]!==E?(it=dt=>hi(dt,Ue=>E(ht=>[...ht,...Ue])),e[131]=E,e[132]=it):it=e[132];let ct;e[133]!==te||e[134]!==it?(ct=n.jsx("input",{ref:te,type:"file",multiple:!0,className:"hidden",onChange:it}),e[133]=te,e[134]=it,e[135]=ct):ct=e[135];let vt;return e[136]!==et||e[137]!==Fe||e[138]!==ct||e[139]!==qe?(vt=n.jsxs("div",{className:"relative mx-auto w-full max-w-3xl px-4 pb-4",children:[qe,et,Fe,ct]}),e[136]=et,e[137]=Fe,e[138]=ct,e[139]=qe,e[140]=vt):vt=e[140],vt}function us(s){const e=F.c(10),{content:t,className:r}=s;let a;e:{if(!t||typeof t!="string"){let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=[],e[0]=u):u=e[0],a=u;break e}let d;e[1]!==t?(d=Si(t),e[1]=t,e[2]=d):d=e[2],a=d}const l=a;if(l.length===0)return null;let o;e[3]!==r?(o=B("prose-custom space-y-3 min-w-0 break-words",r),e[3]=r,e[4]=o):o=e[4];let i;e[5]!==l?(i=l.map(wi),e[5]=l,e[6]=i):i=e[6];let c;return e[7]!==o||e[8]!==i?(c=n.jsx("div",{className:o,children:i}),e[7]=o,e[8]=i,e[9]=c):c=e[9],c}function wi(s,e){return n.jsx(Ci,{block:s},e)}function Si(s){const e=s.split(`
4
+ `),t=[];let r=0;for(;r<e.length;){const a=e[r];if(a.trimStart().startsWith("```")){const i=a.trimStart().slice(3).trim(),c=[];for(r++;r<e.length&&!e[r].trimStart().startsWith("```");)c.push(e[r]),r++;t.push({type:"code",language:i,code:c.join(`
5
+ `)}),r++;continue}const l=a.match(/^(#{1,6})(\s.*)?$/);if(l){t.push({type:"heading",level:l[1].length,text:l[2]?l[2].trim():""}),r++;continue}if(/^(---|\*\*\*|___)/.test(a.trim())){t.push({type:"hr"}),r++;continue}if(a.includes("|")&&r+1<e.length&&e[r+1].match(/^\|?\s*[-:]+/)){const i=a.split("|").map(d=>d.trim()).filter(Boolean);r+=2;const c=[];for(;r<e.length&&e[r].includes("|");)c.push(e[r].split("|").map(d=>d.trim()).filter(Boolean)),r++;t.push({type:"table",headers:i,rows:c});continue}if(a.startsWith("> ")){const i=[];for(;r<e.length&&e[r].startsWith("> ");)i.push(e[r].slice(2)),r++;t.push({type:"blockquote",text:i.join(`
6
+ `)});continue}if(/^\s*[-*+]\s/.test(a)){const i=[];for(;r<e.length&&/^\s*[-*+]\s/.test(e[r]);)i.push(e[r].replace(/^\s*[-*+]\s/,"")),r++;t.push({type:"list",ordered:!1,items:i});continue}if(/^\s*\d+\.\s/.test(a)){const i=[];for(;r<e.length&&/^\s*\d+\.\s/.test(e[r]);)i.push(e[r].replace(/^\s*\d+\.\s/,"")),r++;t.push({type:"list",ordered:!0,items:i});continue}if(a.trim()===""){r++;continue}const o=[];for(;r<e.length&&e[r].trim()!==""&&!e[r].startsWith("#")&&!e[r].startsWith("```")&&!e[r].startsWith("> ")&&!/^\s*[-*+]\s/.test(e[r])&&!/^\s*\d+\.\s/.test(e[r]);)o.push(e[r]),r++;o.length>0&&t.push({type:"paragraph",text:o.join(`
7
+ `)})}return t}function Ci(s){const e=F.c(37),{block:t}=s;switch(t.type){case"heading":{const r=`h${t.level}`;let a,l;if(e[0]!==r||e[1]!==t.level){const c={1:"text-xl font-bold",2:"text-lg font-semibold",3:"text-base font-semibold",4:"text-sm font-semibold",5:"text-sm font-medium",6:"text-xs font-medium"};a=r,l=B(c[t.level],"text-foreground"),e[0]=r,e[1]=t.level,e[2]=a,e[3]=l}else a=e[2],l=e[3];let o;e[4]!==t.text?(o=n.jsx(Ts,{text:t.text}),e[4]=t.text,e[5]=o):o=e[5];let i;return e[6]!==a||e[7]!==l||e[8]!==o?(i=n.jsx(a,{className:l,children:o}),e[6]=a,e[7]=l,e[8]=o,e[9]=i):i=e[9],i}case"code":{let r;return e[10]!==t.code||e[11]!==t.language?(r=n.jsx(Pi,{language:t.language,code:t.code}),e[10]=t.code,e[11]=t.language,e[12]=r):r=e[12],r}case"blockquote":{let r;return e[13]!==t.text?(r=n.jsx("blockquote",{className:"border-l-2 border-border pl-4 text-muted-foreground italic",children:n.jsx(Ts,{text:t.text})}),e[13]=t.text,e[14]=r):r=e[14],r}case"list":{const r=t.ordered?"ol":"ul",a=t.ordered?"list-decimal":"list-disc";let l;e[15]!==a?(l=B("space-y-1 pl-5 text-sm text-foreground",a),e[15]=a,e[16]=l):l=e[16];let o;e[17]!==t.items?(o=t.items.map(Ri),e[17]=t.items,e[18]=o):o=e[18];let i;return e[19]!==r||e[20]!==l||e[21]!==o?(i=n.jsx(r,{className:l,children:o}),e[19]=r,e[20]=l,e[21]=o,e[22]=i):i=e[22],i}case"paragraph":{let r;return e[23]!==t.text?(r=n.jsx("p",{className:"text-sm leading-relaxed text-foreground whitespace-pre-wrap break-words",children:n.jsx(Ts,{text:t.text})}),e[23]=t.text,e[24]=r):r=e[24],r}case"hr":{let r;return e[25]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx("hr",{className:"border-border"}),e[25]=r):r=e[25],r}case"table":{let r;e[26]!==t.headers?(r=t.headers.map(ki),e[26]=t.headers,e[27]=r):r=e[27];let a;e[28]!==r?(a=n.jsx("thead",{children:n.jsx("tr",{className:"border-b border-border bg-muted/50",children:r})}),e[28]=r,e[29]=a):a=e[29];let l;e[30]!==t.rows?(l=t.rows.map(Ti),e[30]=t.rows,e[31]=l):l=e[31];let o;e[32]!==l?(o=n.jsx("tbody",{children:l}),e[32]=l,e[33]=o):o=e[33];let i;return e[34]!==a||e[35]!==o?(i=n.jsx("div",{className:"overflow-x-auto rounded-md border border-border max-w-full",children:n.jsxs("table",{className:"w-full text-sm",children:[a,o]})}),e[34]=a,e[35]=o,e[36]=i):i=e[36],i}default:return null}}function Ti(s,e){return n.jsx("tr",{className:"border-b border-border last:border-0",children:s.map(Ii)},e)}function Ii(s,e){return n.jsx("td",{className:"px-3 py-2 text-foreground",children:s},e)}function ki(s,e){return n.jsx("th",{className:"px-3 py-2 text-left font-medium text-foreground",children:s},e)}function Ri(s,e){return n.jsx("li",{children:n.jsx(Ts,{text:s})},e)}function Ts(s){const e=F.c(4),{text:t}=s;let r;e[0]!==t?(r=_i(t).map(Ei),e[0]=t,e[1]=r):r=e[1];let a;return e[2]!==r?(a=n.jsx(n.Fragment,{children:r}),e[2]=r,e[3]=a):a=e[3],a}function Ei(s,e){switch(s.type){case"bold":return n.jsx("strong",{className:"font-semibold",children:s.text},e);case"italic":return n.jsx("em",{children:s.text},e);case"strikethrough":return n.jsx("del",{className:"text-muted-foreground",children:s.text},e);case"code":return n.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs font-mono text-foreground",children:s.text},e);case"link":return n.jsx("a",{href:s.href,className:"text-primary underline underline-offset-2 hover:text-primary/80",target:"_blank",rel:"noopener noreferrer",children:s.text},e);default:return n.jsx("span",{children:s.text},e)}}function _i(s){const e=[],t=/(`[^`]+`)|(\*\*[^*]+\*\*)|(\*[^*]+\*)|(__[^_]+__)|(_[^_]+_)|(~~[^~]+~~)|(\[[^\]]+\]\([^)]+\))/g;let r=0,a;for(;(a=t.exec(s))!==null;){a.index>r&&e.push({type:"text",text:s.slice(r,a.index)});const l=a[0];if(l.startsWith("`"))e.push({type:"code",text:l.slice(1,-1)});else if(l.startsWith("**"))e.push({type:"bold",text:l.slice(2,-2)});else if(l.startsWith("__"))e.push({type:"bold",text:l.slice(2,-2)});else if(l.startsWith("~~"))e.push({type:"strikethrough",text:l.slice(2,-2)});else if(l.startsWith("*")||l.startsWith("_"))e.push({type:"italic",text:l.slice(1,-1)});else if(l.startsWith("[")){const o=l.match(/\[([^\]]+)\]\(([^)]+)\)/);o&&e.push({type:"link",text:o[1],href:o[2]})}r=a.index+l.length}return r<s.length&&e.push({type:"text",text:s.slice(r)}),e.length>0?e:[{type:"text",text:s}]}function Pi(s){const e=F.c(18),{language:t,code:r}=s,[a,l]=m.useState(!1);let o;e[0]!==r?(o=async()=>{await navigator.clipboard.writeText(r),l(!0),setTimeout(()=>l(!1),2e3)},e[0]=r,e[1]=o):o=e[1];const i=o,c=t||"text";let d;e[2]!==c?(d=n.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:c}),e[2]=c,e[3]=d):d=e[3];let u;e[4]!==a?(u=a?n.jsx(Je,{className:"h-3 w-3"}):n.jsx(Wn,{className:"h-3 w-3"}),e[4]=a,e[5]=u):u=e[5];let f;e[6]===Symbol.for("react.memo_cache_sentinel")?(f=n.jsx("span",{className:"sr-only",children:"Copy code"}),e[6]=f):f=e[6];let h;e[7]!==i||e[8]!==u?(h=n.jsxs(J,{variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",onClick:i,children:[u,f]}),e[7]=i,e[8]=u,e[9]=h):h=e[9];let g;e[10]!==d||e[11]!==h?(g=n.jsxs("div",{className:"flex items-center justify-between border-b border-border bg-muted/80 px-4 py-2",children:[d,h]}),e[10]=d,e[11]=h,e[12]=g):g=e[12];let p;e[13]!==r?(p=n.jsx("pre",{className:"overflow-x-auto p-4 max-w-full",children:n.jsx("code",{className:"text-xs font-mono text-foreground leading-relaxed",children:r})}),e[13]=r,e[14]=p):p=e[14];let j;return e[15]!==g||e[16]!==p?(j=n.jsxs("div",{className:"group relative overflow-hidden rounded-lg border border-border bg-muted",children:[g,p]}),e[15]=g,e[16]=p,e[17]=j):j=e[17],j}const na=Ua,ra=za,fn=m.forwardRef((s,e)=>{const t=F.c(13);let r,a,l,o;t[0]!==s?({className:r,align:l,sideOffset:o,...a}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l,t[4]=o):(r=t[1],a=t[2],l=t[3],o=t[4]);const i=l===void 0?"center":l,c=o===void 0?4:o;let d;t[5]!==r?(d=B("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none 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",r),t[5]=r,t[6]=d):d=t[6];let u;return t[7]!==i||t[8]!==a||t[9]!==e||t[10]!==c||t[11]!==d?(u=n.jsx(Ha,{children:n.jsx(Vn,{ref:e,align:i,sideOffset:c,className:d,...a})}),t[7]=i,t[8]=a,t[9]=e,t[10]=c,t[11]=d,t[12]=u):u=t[12],u});fn.displayName=Vn.displayName;function Mi(s){const e=s.toLowerCase();return e.includes("read")||e.includes("file")?Ba:e.includes("create")?gs:e.includes("replace")||e.includes("edit")?qa:e.includes("delete")?Kn:e.includes("terminal")||e.includes("bash")||e.includes("shell")?ds:e.includes("run")?rn:e.includes("git")||e.includes("branch")?xs:e.includes("search")||e.includes("grep")||e.includes("find")?Es:e.includes("code")||e.includes("debug")?Wa:e.includes("test")?Cs:e.includes("agent")||e.includes("subagent")?Va:e.includes("copy")?Wn:e.includes("dir")||e.includes("list")||e.includes("ls")?Ka:e.includes("view")||e.includes("show")?ln:e.includes("config")||e.includes("setting")?Un:e.includes("chat")||e.includes("message")?bn:e.includes("ask")?bn:Ja}function Zs(s){const e=s.toLowerCase();return e.includes("bash")||e.includes("terminal")||e.includes("shell")?"Ran":e.includes("read")||e.includes("file")?"Read":s}function Zt(s,e){if(!e||!s||typeof s!="string")return s;try{const t=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return s.replace(new RegExp(t,"g"),".")}catch{return s}}function Di(s){return typeof s=="string"?s:typeof s=="object"&&s!==null?JSON.stringify(s,null,2):String(s)}function Ai(s){const e=s.trim();if(e.startsWith("{")&&e.endsWith("}")||e.startsWith("[")&&e.endsWith("]"))try{return JSON.parse(e)}catch{return s}return s}function Is(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return s.map(Is);const e={};for(const[t,r]of Object.entries(s))if(typeof r=="string"){const a=Ai(r);e[t]=typeof a=="object"?Is(a):r}else e[t]=Is(r);return e}function Li(s){if(s==null||typeof s!="string")return"";let e=s;return e=e.replace(/\\\\n/g,`
8
+ `),e=e.replace(/\\\\"/g,'"'),e=e.replace(/\\n/g,`
9
+ `),e=e.replace(/\\"/g,'"'),e}function $i(s){if(s==null)return"";const e=typeof s=="object"&&s!==null?Is(s):s,t=typeof e=="string"?e:e==null?"":JSON.stringify(e,null,2);return Li(t)}function _n(s){const e=F.c(75),{block:t,inline:r}=s,[a,l]=m.useState(!1),{state:o}=Ce();let i,c,d,u,f,h,g,p;if(e[0]!==t.id||e[1]!==t.input||e[2]!==t.name||e[3]!==o.projects||e[4]!==o.selectedProjectId||e[5]!==o.selectedThreadId){let M;e[14]!==o.selectedProjectId?(M=G=>G.projectId===o.selectedProjectId,e[14]=o.selectedProjectId,e[15]=M):M=e[15];const L=o.projects.find(M)?.threads.find(G=>G.threadId===o.selectedThreadId)?.path;p=t.name||"Unknown Tool",h=t.id||"unknown";const $=t.input,q=$&&typeof $=="object"&&"description"in $;u=q?String($.subagent_type):null,c=$&&typeof $=="object"?$:null,g=q?null:Zt(Di($),L),d=Zt(q?String($.prompt):null,L),i=Zt(c&&typeof c.command=="string"?c.command:null,L),f=Zt(c&&typeof c.path=="string"?c.path:null,L),e[0]=t.id,e[1]=t.input,e[2]=t.name,e[3]=o.projects,e[4]=o.selectedProjectId,e[5]=o.selectedThreadId,e[6]=i,e[7]=c,e[8]=d,e[9]=u,e[10]=f,e[11]=h,e[12]=g,e[13]=p}else i=e[6],c=e[7],d=e[8],u=e[9],f=e[10],h=e[11],g=e[12],p=e[13];const j=f,v=c&&typeof c.offset=="number"?c.offset:null,b=c&&typeof c.limit=="number"?c.limit:null;let I,T,x,C,_,w;if(e[16]!==i||e[17]!==a||e[18]!==r||e[19]!==b||e[20]!==v||e[21]!==j||e[22]!==d||e[23]!==u||e[24]!==h||e[25]!==g||e[26]!==p){w=Symbol.for("react.early_return_sentinel");e:{const M=Mi(p);let z;e[33]!==b||e[34]!==v||e[35]!==p?(z=()=>{let L=p.charAt(0).toUpperCase()+p.slice(1);if(p.toLowerCase()==="bash"&&(L="Ran"),p.toLowerCase().includes("read")&&(v!==null||b!==null)){const $=v!==null?v+1:1,q=b!==null&&v!==null?$+b-1:null;L=L+` lines ${$}${q?` to ${q}`:"+"}`}return L},e[33]=b,e[34]=v,e[35]=p,e[36]=z):z=e[36];const O=z;if(r){const $=!!(d||g&&!i&&!j)?n.jsxs(na,{children:[n.jsx(ra,{asChild:!0,children:n.jsx("span",{title:p,className:"inline-flex",children:n.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center gap-1 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":"Show tool details",children:[m.createElement(M,{className:"h-3.5 w-3.5 text-brand"}),n.jsx("span",{className:"text-xs",children:O()})]})})}),n.jsx(fn,{className:"w-80 max-h-80 overflow-auto",align:"start",children:n.jsxs("div",{className:"text-xs text-muted-foreground space-y-2",children:[n.jsxs("div",{className:"font-mono",children:["ID: ",h]}),d?n.jsx("div",{className:"whitespace-pre-wrap leading-relaxed",children:d}):g?n.jsx("pre",{className:"font-mono whitespace-pre-wrap overflow-auto max-h-48",children:g}):null]})})]}):n.jsxs("span",{title:p,className:"inline-flex items-center gap-1",children:[m.createElement(M,{className:"h-3.5 w-3.5 shrink-0 text-brand"}),n.jsx("span",{className:"text-xs text-muted-foreground",children:O()})]});let q;e[37]!==i?(q=i!==null&&n.jsx("code",{className:"text-xs font-mono text-muted-foreground break-all rounded bg-muted/60 px-1 py-0.5",children:i}),e[37]=i,e[38]=q):q=e[38];let G;e[39]!==j?(G=j!==null&&n.jsx("span",{className:"text-xs font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]",title:j,children:j}),e[39]=j,e[40]=G):G=e[40];let K;e[41]!==u?(K=u&&n.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-muted text-muted-foreground",children:u}),e[41]=u,e[42]=K):K=e[42];let X;e[43]!==q||e[44]!==G||e[45]!==K||e[46]!==$?(X=n.jsxs("div",{className:"py-1 flex items-center gap-2 flex-wrap",children:[$,q,G,K]}),e[43]=q,e[44]=G,e[45]=K,e[46]=$,e[47]=X):X=e[47],w=X;break e}_="mb-3 rounded-lg border border-blue-200 dark:border-blue-800 bg-blue-50 dark:bg-blue-900/20 overflow-hidden",e[48]!==a?(I=()=>l(!a),e[48]=a,e[49]=I):I=e[49],T="w-full px-3 py-2 flex items-center gap-2 text-sm font-medium text-blue-900 dark:text-blue-100 hover:bg-blue-100 dark:hover:bg-blue-900/40 transition-colors",x=p,C=m.createElement(M,{className:"h-4 w-4 text-brand"})}e[16]=i,e[17]=a,e[18]=r,e[19]=b,e[20]=v,e[21]=j,e[22]=d,e[23]=u,e[24]=h,e[25]=g,e[26]=p,e[27]=I,e[28]=T,e[29]=x,e[30]=C,e[31]=_,e[32]=w}else I=e[27],T=e[28],x=e[29],C=e[30],_=e[31],w=e[32];if(w!==Symbol.for("react.early_return_sentinel"))return w;let k;e[50]!==p?(k=Zs(p),e[50]=p,e[51]=k):k=e[51];let N;e[52]!==k?(N=n.jsx("span",{className:"flex-1 text-left min-w-0 truncate",children:k}),e[52]=k,e[53]=N):N=e[53];let y;e[54]!==u?(y=u&&n.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-blue-200 dark:bg-blue-800 text-blue-800 dark:text-blue-200",children:u}),e[54]=u,e[55]=y):y=e[55];let S;e[56]!==a?(S=a?n.jsx(It,{className:"h-4 w-4 shrink-0"}):n.jsx(Mt,{className:"h-4 w-4 shrink-0"}),e[56]=a,e[57]=S):S=e[57];let R;e[58]!==y||e[59]!==S||e[60]!==I||e[61]!==T||e[62]!==x||e[63]!==C||e[64]!==N?(R=n.jsxs("button",{onClick:I,className:T,title:x,children:[C,N,y,S]}),e[58]=y,e[59]=S,e[60]=I,e[61]=T,e[62]=x,e[63]=C,e[64]=N,e[65]=R):R=e[65];let E;e[66]!==a||e[67]!==d||e[68]!==h||e[69]!==g?(E=a&&n.jsxs("div",{className:"px-3 py-2 bg-white dark:bg-slate-950 border-t border-blue-200 dark:border-blue-800",children:[n.jsxs("div",{className:"text-xs text-muted-foreground mb-2 font-mono text-blue-700 dark:text-blue-300",children:["ID: ",h]}),d?n.jsx("div",{className:"text-xs bg-slate-100 dark:bg-slate-900 p-3 rounded whitespace-pre-wrap overflow-auto max-h-64 leading-relaxed",children:d}):g?n.jsx("pre",{className:"text-xs bg-slate-100 dark:bg-slate-900 p-2 rounded font-mono whitespace-pre-wrap overflow-auto max-h-48",children:g}):null]}),e[66]=a,e[67]=d,e[68]=h,e[69]=g,e[70]=E):E=e[70];let A;return e[71]!==R||e[72]!==E||e[73]!==_?(A=n.jsxs("div",{className:_,children:[R,E]}),e[71]=R,e[72]=E,e[73]=_,e[74]=A):A=e[74],A}function pn(s){const e=F.c(45),{block:t,inline:r}=s,[a,l]=m.useState(!1),{state:o}=Ce(),i=o.projects;let c,d,u,f,h,g,p;if(e[0]!==t.result||e[1]!==t.toolCallId||e[2]!==t.toolName||e[3]!==o.projects||e[4]!==o.selectedProjectId||e[5]!==o.selectedThreadId){h=Symbol.for("react.early_return_sentinel");e:{let w;e[13]!==o.selectedProjectId?(w=R=>R.projectId===o.selectedProjectId,e[13]=o.selectedProjectId,e[14]=w):w=e[14];const y=i.find(w)?.threads.find(R=>R.threadId===o.selectedThreadId)?.path;p=t.toolName||"Unknown Tool",g=t.toolCallId||"unknown";const S=t.result;if(u=Zt($i(S),y),d=u.length>0,!d){h=null;break e}if(c=Zs(p),typeof S=="object"&&S!==null){const R=S,E=R.returnDisplay??R.return_display;if(typeof E=="string"&&E.trim()){let A;e[15]!==E?(A=E.trim(),e[15]=E,e[16]=A):A=e[16],c=A}else if(p==="read"||p==="file_read"){const A=R.filePath||R.file_path||R.path||"";if(A){let M;e[17]!==A?(M=A.split("/").pop()||A,e[17]=A,e[18]=M):M=e[18],c=`Completed ${M}`}}}else if(S==null){let R;e[19]!==p?(R=Zs(p),e[19]=p,e[20]=R):R=e[20],c=`${R} (no result)`}f=Zt(c,y)}e[0]=t.result,e[1]=t.toolCallId,e[2]=t.toolName,e[3]=o.projects,e[4]=o.selectedProjectId,e[5]=o.selectedThreadId,e[6]=c,e[7]=d,e[8]=u,e[9]=f,e[10]=h,e[11]=g,e[12]=p}else c=e[6],d=e[7],u=e[8],f=e[9],h=e[10],g=e[11],p=e[12];if(h!==Symbol.for("react.early_return_sentinel"))return h;if(c=f,r){let w;return e[21]!==d||e[22]!==u||e[23]!==g||e[24]!==p?(w=n.jsx("div",{className:"py-1 flex items-center gap-2",children:d?n.jsxs(na,{children:[n.jsx(ra,{asChild:!0,children:n.jsx("button",{type:"button",className:"inline-flex shrink-0 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring","aria-label":"Show result details",title:`${p} result`,children:n.jsx(Cs,{className:"h-3.5 w-3.5"})})}),n.jsx(fn,{className:"w-80 max-h-80 overflow-auto",align:"start",children:n.jsxs("div",{className:"text-xs space-y-2",children:[n.jsxs("div",{className:"text-muted-foreground font-mono",children:["Call ID: ",g]}),n.jsx("pre",{className:"font-mono whitespace-pre-wrap overflow-auto max-h-48 text-foreground text-left",children:u})]})})]}):n.jsx("span",{title:`${p} result`,children:n.jsx(Cs,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"})})}),e[21]=d,e[22]=u,e[23]=g,e[24]=p,e[25]=w):w=e[25],w}let j;e[26]!==a?(j=()=>l(!a),e[26]=a,e[27]=j):j=e[27];const v=`${p} result`;let b;e[28]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsx(Cs,{className:"h-4 w-4 shrink-0"}),e[28]=b):b=e[28];let I;e[29]!==c?(I=n.jsx("span",{className:"flex-1 text-left min-w-0 truncate",children:c}),e[29]=c,e[30]=I):I=e[30];let T;e[31]!==a?(T=a?n.jsx(It,{className:"h-4 w-4 shrink-0"}):n.jsx(Mt,{className:"h-4 w-4 shrink-0"}),e[31]=a,e[32]=T):T=e[32];let x;e[33]!==j||e[34]!==v||e[35]!==I||e[36]!==T?(x=n.jsxs("button",{onClick:j,className:"w-full px-3 py-2 flex items-center gap-2 text-sm font-medium text-foreground hover:bg-muted transition-colors text-left",title:v,children:[b,I,T]}),e[33]=j,e[34]=v,e[35]=I,e[36]=T,e[37]=x):x=e[37];let C;e[38]!==a||e[39]!==u||e[40]!==g?(C=a&&n.jsxs("div",{className:"px-3 py-2 bg-background border-t border-border",children:[n.jsxs("div",{className:"text-xs text-muted-foreground mb-2 font-mono",children:["Call ID: ",g]}),u&&n.jsx("pre",{className:"text-xs bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto max-h-48 text-foreground text-left",children:u})]}),e[38]=a,e[39]=u,e[40]=g,e[41]=C):C=e[41];let _;return e[42]!==C||e[43]!==x?(_=n.jsxs("div",{className:"mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden",children:[x,C]}),e[42]=C,e[43]=x,e[44]=_):_=e[44],_}function Oi({toolCall:s,className:e}){const{state:t,dispatch:r}=Ce(),[a,l]=m.useState(!1),o=t.toolCallProgress[s.id];if(!m.useMemo(()=>{if(!t.isStreaming)return{isActive:!1,isCompleted:!0};let f=!1,h=!1;for(const g of t.streamingSegments)if(g.type==="thinking"){for(const p of g.chunks)if(p.includes(s.id))try{const j=JSON.parse(p);if(Array.isArray(j))for(const v of j)v.type==="tool_use"&&v.id===s.id&&(f=!0),v.type==="tool-result"&&v.toolCallId===s.id&&(h=!0,f=!1)}catch{}}return f&&!t.isStreaming&&(h=!0,f=!1),{isActive:f,isCompleted:h}},[t.isStreaming,t.streamingSegments,s.id]).isActive)return null;const c=()=>{l(f=>!f)},d=()=>{r({type:P.StopStream});const f={type:"tool-result",toolCallId:s.id,toolName:s.name,result:"Tool execution was cancelled by the user. The command was taking too long or required user approval.",isError:!0,content:"Tool execution was cancelled by the user. The command was taking too long or required user approval."};r({type:P.AppendStreamChunk,chunkType:"content",content:JSON.stringify([f]),segments:t.streamingSegments})},u=f=>JSON.stringify(f,null,2);return n.jsxs("div",{className:B("border border-blue-200 dark:border-blue-800 bg-blue-50 dark:bg-blue-900/20 rounded-lg overflow-hidden mb-2",e),children:[n.jsxs("div",{className:"px-3 py-2 flex items-center gap-2",children:[n.jsxs("div",{className:"flex items-center gap-1.5 flex-1",children:[n.jsx(ve,{className:"h-3.5 w-3.5 animate-spin"}),n.jsx("span",{className:"text-sm font-medium text-blue-900 dark:text-blue-100",children:s.name}),n.jsx("span",{className:"text-xs text-blue-700 dark:text-blue-300",children:"running"})]}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("button",{onClick:c,className:"p-1 hover:bg-blue-200 dark:hover:bg-blue-800 rounded transition-colors",title:a?"Collapse":"Expand",children:a?n.jsx(Jn,{className:"h-3.5 w-3.5"}):n.jsx(It,{className:"h-3.5 w-3.5"})}),n.jsx("button",{onClick:d,className:"p-1 hover:bg-red-200 dark:hover:bg-red-800 rounded transition-colors text-red-600 dark:text-red-400",title:"Stop tool execution",children:n.jsx(mt,{className:"h-3.5 w-3.5"})})]})]}),a&&n.jsxs("div",{className:"px-3 py-2 bg-white dark:bg-slate-950 border-t border-blue-200 dark:border-blue-800 min-h-[8rem] overflow-auto",children:[n.jsxs("div",{className:"text-xs text-muted-foreground mb-2 font-mono text-blue-700 dark:text-blue-300",children:["ID: ",s.id]}),n.jsxs("div",{className:"mb-2",children:[n.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Input:"}),n.jsx("pre",{className:"text-xs bg-slate-100 dark:bg-slate-900 p-2 rounded font-mono whitespace-pre-wrap overflow-auto max-h-48 border border-slate-200 dark:border-slate-700",children:u(s.input)})]}),o&&n.jsxs("div",{className:"mb-2",children:[n.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Progress:"}),n.jsxs("div",{className:"text-xs bg-green-50 dark:bg-green-900/20 p-2 rounded border border-green-200 dark:border-green-800",children:[n.jsx("div",{className:"text-green-700 dark:text-green-300 font-mono",children:o.delta}),o.partial?.content?.[0]?.arguments&&typeof o.partial.content[0].arguments=="object"&&"content"in o.partial.content[0].arguments&&typeof o.partial.content[0].arguments.content=="string"&&n.jsxs("div",{className:"mt-1 text-green-600 dark:text-green-400 font-mono text-xs",children:["Building: ",o.partial.content[0].arguments.content.slice(-50),o.partial.content[0].arguments.content.length>50&&"..."]})]})]}),n.jsxs("div",{className:"flex items-center gap-2 text-xs text-blue-600 dark:text-blue-400",children:[n.jsx(ve,{className:"h-3 w-3 animate-spin"}),"Executing",o&&" with progress","..."]})]})]})}function Fi(s){const e=F.c(51),{toolCallId:t,question:r,options:a,context:l}=s,[o,i]=m.useState(""),[c,d]=m.useState(!1),[u,f]=m.useState(""),[h,g]=m.useState(!1),[p,j]=m.useState(null);let v;e[0]!==h||e[1]!==t?(v=async G=>{if(!(!G.trim()||h)){g(!0);try{await qo(t,G.trim()),f(G.trim()),d(!0)}catch(K){console.error("Failed to submit answer:",K),g(!1),j(null)}}},e[0]=h,e[1]=t,e[2]=v):v=e[2];const b=v;let I;e[3]!==b||e[4]!==h||e[5]!==c?(I=G=>{c||h||(j(G),b(G))},e[3]=b,e[4]=h,e[5]=c,e[6]=I):I=e[6];const T=I;let x;e[7]!==o||e[8]!==b||e[9]!==h||e[10]!==c?(x=()=>{if(c||h)return;const G=o.trim();G&&b(G)},e[7]=o,e[8]=b,e[9]=h,e[10]=c,e[11]=x):x=e[11];const C=x;let _;e[12]!==C?(_=G=>{G.key==="Enter"&&!G.shiftKey&&(G.preventDefault(),C())},e[12]=C,e[13]=_):_=e[13];const w=_;if(c){let G,K;e[14]===Symbol.for("react.memo_cache_sentinel")?(G=n.jsx(Je,{className:"h-4 w-4"}),K=n.jsx("span",{className:"font-medium",children:"Answered:"}),e[14]=G,e[15]=K):(G=e[14],K=e[15]);let X;return e[16]!==u?(X=n.jsx("div",{className:"rounded-lg border border-green-200 dark:border-green-800 bg-green-50 dark:bg-green-900/20 p-3 my-2",children:n.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-800 dark:text-green-200",children:[G,K,n.jsx("span",{children:u})]})}),e[16]=u,e[17]=X):X=e[17],X}let k;e[18]===Symbol.for("react.memo_cache_sentinel")?(k=n.jsx(Qn,{className:"h-5 w-5 text-brand dark:text-brand shrink-0 mt-0.5"}),e[18]=k):k=e[18];let N;e[19]!==r?(N=n.jsx("div",{className:"text-sm font-medium text-foreground",children:n.jsx(us,{content:r})}),e[19]=r,e[20]=N):N=e[20];let y;e[21]!==l?(y=l&&n.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:l}),e[21]=l,e[22]=y):y=e[22];let S;e[23]!==N||e[24]!==y?(S=n.jsxs("div",{className:"flex items-start gap-2 mb-3",children:[k,n.jsxs("div",{className:"flex-1 min-w-0",children:[N,y]})]}),e[23]=N,e[24]=y,e[25]=S):S=e[25];let R;e[26]!==T||e[27]!==h||e[28]!==a||e[29]!==p?(R=a&&a.length>0&&n.jsx("div",{className:"flex flex-wrap gap-2 mb-3",children:a.map(G=>{const K=p===G;return n.jsxs("button",{type:"button",onClick:()=>T(G),disabled:h,className:B("rounded-md border px-3 py-1.5 text-sm transition-colors disabled:opacity-50 flex items-center gap-1.5",K?"border-brand bg-brand/20 dark:bg-brand/30 text-foreground font-medium":"border-brand/30 dark:border-brand/40 bg-background text-foreground hover:bg-brand/10 dark:hover:bg-brand/20"),children:[K&&n.jsx(Je,{className:"h-3.5 w-3.5 text-brand"}),G]},G)})}),e[26]=T,e[27]=h,e[28]=a,e[29]=p,e[30]=R):R=e[30];let E;e[31]===Symbol.for("react.memo_cache_sentinel")?(E=G=>i(G.target.value),e[31]=E):E=e[31];const A=a?.length?"Or type a custom answer...":"Type your answer...";let M;e[32]!==o||e[33]!==w||e[34]!==h||e[35]!==A?(M=n.jsx("input",{type:"text",value:o,onChange:E,onKeyDown:w,placeholder:A,disabled:h,className:"flex-1 rounded-md border border-brand/30 dark:border-brand/40 bg-background px-3 py-1.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-brand dark:focus:ring-brand disabled:opacity-50"}),e[32]=o,e[33]=w,e[34]=h,e[35]=A,e[36]=M):M=e[36];let z;e[37]!==o||e[38]!==h?(z=h||!o.trim(),e[37]=o,e[38]=h,e[39]=z):z=e[39];let O;e[40]===Symbol.for("react.memo_cache_sentinel")?(O=n.jsx(Qa,{className:"h-4 w-4"}),e[40]=O):O=e[40];let L;e[41]!==C||e[42]!==z?(L=n.jsx("button",{type:"button",onClick:C,disabled:z,className:"rounded-md bg-brand px-3 py-1.5 text-sm text-white hover:bg-brand/90 transition-colors disabled:opacity-50",children:O}),e[41]=C,e[42]=z,e[43]=L):L=e[43];let $;e[44]!==M||e[45]!==L?($=n.jsxs("div",{className:"flex gap-2",children:[M,L]}),e[44]=M,e[45]=L,e[46]=$):$=e[46];let q;return e[47]!==$||e[48]!==S||e[49]!==R?(q=n.jsxs("div",{className:"rounded-lg border border-brand/20 dark:border-brand/30 bg-brand/5 dark:bg-brand/10 p-4 my-2",children:[S,R,$]}),e[47]=$,e[48]=S,e[49]=R,e[50]=q):q=e[50],q}function hn(s,e,t){return s.name==="ask_user"?n.jsx(Fi,{toolCallId:s.id,question:String(s.input?.question||""),options:s.input?.options,context:s.input?.context},e):t?n.jsxs("span",{children:[n.jsx(Oi,{toolCall:s}),n.jsx(_n,{inline:!0,block:s})]},e):n.jsx(_n,{inline:!0,block:s},e)}function Gi(s){const e=F.c(59),{message:t}=s,r=t.sender==="user";let a,l,o,i,c,d;if(e[0]!==r||e[1]!==t.content||e[2]!==t.contentType||e[3]!==t.isThinking||e[4]!==t.metadata||e[5]!==t.model||e[6]!==t.sender||e[7]!==t.timestamp){const p=r?null:Ur(t.content);let j;e[14]!==t.timestamp?(j=t.timestamp?new Date(t.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):"",e[14]=t.timestamp,e[15]=j):j=e[15];const v=j,b=r?"flex-row-reverse":"flex-row";e[16]!==b?(c=B("group flex gap-3 px-4 py-4",b),e[16]=b,e[17]=c):c=e[17];const I=r?"bg-foreground":"bg-muted";let T;e[18]!==I?(T=B("flex h-7 w-7 shrink-0 items-center justify-center rounded-full",I),e[18]=I,e[19]=T):T=e[19];let x;e[20]!==r?(x=r?n.jsx(Ya,{className:"h-3.5 w-3.5 text-background"}):n.jsx(Yn,{className:"h-3.5 w-3.5 text-muted-foreground"}),e[20]=r,e[21]=x):x=e[21],e[22]!==T||e[23]!==x?(d=n.jsx("div",{className:T,children:x}),e[22]=T,e[23]=x,e[24]=d):d=e[24];const C=r&&"items-end";e[25]!==C?(o=B("flex flex-1 flex-col gap-1 min-w-0",C),e[25]=C,e[26]=o):o=e[26];const _=r&&"flex-row-reverse";let w;e[27]!==_?(w=B("flex items-center gap-2",_),e[27]=_,e[28]=w):w=e[28];const k=r?"You":"Agent";let N;e[29]!==k?(N=n.jsx("span",{className:"text-xs font-medium text-foreground",children:k}),e[29]=k,e[30]=N):N=e[30];let y;e[31]!==v?(y=v&&n.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity",children:[n.jsx(nn,{className:"h-2.5 w-2.5"}),v]}),e[31]=v,e[32]=y):y=e[32];let S;e[33]!==t.model?(S=t.model&&n.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity",children:[n.jsx(on,{className:"h-2.5 w-2.5"}),At(t.model)]}),e[33]=t.model,e[34]=S):S=e[34];let R;e[35]!==t.metadata?(R=t.metadata?.tokenCount&&n.jsxs("span",{className:"text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity",children:[t.metadata.tokenCount," tokens"]}),e[35]=t.metadata,e[36]=R):R=e[36],e[37]!==w||e[38]!==N||e[39]!==y||e[40]!==S||e[41]!==R?(i=n.jsxs("div",{className:w,children:[N,y,S,R]}),e[37]=w,e[38]=N,e[39]=y,e[40]=S,e[41]=R,e[42]=i):i=e[42];const E=r?"bg-foreground text-background":"bg-muted text-foreground";e[43]!==E?(a=B("rounded-xl px-4 py-3 flex flex-col gap-2 min-w-0",E),e[43]=E,e[44]=a):a=e[44],l=t.isThinking?(()=>{const A=Hr(t.content);return A?.length?A.map(zi):n.jsx("div",{className:"text-xs text-muted-foreground leading-relaxed whitespace-pre-wrap",children:n.jsx(us,{content:es(t.content)})})})():p?n.jsx(n.Fragment,{children:p.map(Ui)}):t.contentType==="markdown"||t.sender==="agent"?n.jsx(us,{content:es(t.content)}):n.jsx("p",{className:"text-sm whitespace-pre-wrap",children:t.content}),e[0]=r,e[1]=t.content,e[2]=t.contentType,e[3]=t.isThinking,e[4]=t.metadata,e[5]=t.model,e[6]=t.sender,e[7]=t.timestamp,e[8]=a,e[9]=l,e[10]=o,e[11]=i,e[12]=c,e[13]=d}else a=e[8],l=e[9],o=e[10],i=e[11],c=e[12],d=e[13];let u;e[45]!==a||e[46]!==l?(u=n.jsx("div",{className:a,children:l}),e[45]=a,e[46]=l,e[47]=u):u=e[47];let f;e[48]!==t.attachments?(f=t.attachments&&t.attachments.length>0&&n.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1",children:t.attachments.map(Hi)}),e[48]=t.attachments,e[49]=f):f=e[49];let h;e[50]!==o||e[51]!==i||e[52]!==u||e[53]!==f?(h=n.jsxs("div",{className:o,children:[i,u,f]}),e[50]=o,e[51]=i,e[52]=u,e[53]=f,e[54]=h):h=e[54];let g;return e[55]!==c||e[56]!==d||e[57]!==h?(g=n.jsxs("div",{className:c,children:[d,h]}),e[55]=c,e[56]=d,e[57]=h,e[58]=g):g=e[58],g}function Hi(s,e){return n.jsxs("span",{className:"flex items-center gap-1 rounded-md bg-muted px-2 py-1 text-[10px] text-muted-foreground",children:[n.jsx(an,{className:"h-2.5 w-2.5"}),s.fileName]},e)}function Ui(s,e){return n.jsx("div",{children:s.type==="reasoning"&&"text"in s?n.jsx("div",{className:"text-xs text-muted-foreground leading-relaxed whitespace-pre-wrap",children:es(s.text)}):s.type==="text"&&"text"in s?n.jsx(us,{content:es(s.text)}):s.type==="tool_use"?hn(s):s.type==="tool-result"?n.jsx(pn,{inline:!0,block:s}):null},e)}function zi(s,e){return s.type==="tool_use"?hn(s,e):s.type==="tool-result"?n.jsx(pn,{inline:!0,block:s},e):null}function Bi(s){const e=F.c(21),{segments:t,model:r}=s;let a,l,o,i,c;if(e[0]!==r||e[1]!==t){const f=zr(t);i="group flex gap-3 px-4 py-4",e[7]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx("div",{className:"flex h-7 w-7 shrink-0 self-end items-center justify-center rounded-full bg-brand animate-radial-pulse-brand",children:n.jsx(Yn,{className:"h-3.5 w-3.5 text-white"})}),e[7]=c):c=e[7],a="flex flex-1 flex-col gap-1 min-w-0";let h;e[8]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx("span",{className:"text-xs font-medium text-foreground",children:"Agent"}),e[8]=h):h=e[8];let g;e[9]!==r?(g=r&&n.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity",children:[n.jsx(on,{className:"h-2.5 w-2.5"}),At(r)]}),e[9]=r,e[10]=g):g=e[10],e[11]!==g?(l=n.jsxs("div",{className:"flex items-center gap-2",children:[h,g]}),e[11]=g,e[12]=l):l=e[12],o=f.length>0?n.jsx("div",{className:"rounded-xl bg-muted px-4 py-3 text-foreground flex flex-col gap-2 min-w-0",children:f.map(qi)}):n.jsx("div",{className:"rounded-xl bg-muted px-4 py-3 min-w-0",children:n.jsxs("div",{className:"flex items-center justify-center gap-1.5",children:[n.jsx("div",{className:"h-2 w-2 rounded-full bg-muted-foreground/40 animate-bounce [animation-delay:0ms]"}),n.jsx("div",{className:"h-2 w-2 rounded-full bg-muted-foreground/40 animate-bounce [animation-delay:150ms]"}),n.jsx("div",{className:"h-2 w-2 rounded-full bg-muted-foreground/40 animate-bounce [animation-delay:300ms]"})]})}),e[0]=r,e[1]=t,e[2]=a,e[3]=l,e[4]=o,e[5]=i,e[6]=c}else a=e[2],l=e[3],o=e[4],i=e[5],c=e[6];let d;e[13]!==a||e[14]!==l||e[15]!==o?(d=n.jsxs("div",{className:a,children:[l,o]}),e[13]=a,e[14]=l,e[15]=o,e[16]=d):d=e[16];let u;return e[17]!==i||e[18]!==c||e[19]!==d?(u=n.jsxs("div",{className:i,children:[c,d]}),e[17]=i,e[18]=c,e[19]=d,e[20]=u):u=e[20],u}function qi(s,e){return n.jsx("div",{children:s.type==="reasoning"&&"text"in s?n.jsx("div",{className:"text-xs text-muted-foreground leading-relaxed whitespace-pre-wrap",children:es(s.text)}):s.type==="text"&&"text"in s?n.jsx(us,{content:es(s.text)}):s.type==="tool_use"?hn(s,void 0,!0):s.type==="tool-result"?n.jsx(pn,{inline:!0,block:s}):null},`b-${e}`)}const Wi=m.memo(Bi,(s,e)=>{if(s.model!==e.model||s.segments.length!==e.segments.length)return!1;for(let t=0;t<s.segments.length;t++){if(s.segments[t].type!==e.segments[t].type||s.segments[t].chunks.length!==e.segments[t].chunks.length)return!1;for(let r=0;r<s.segments[t].chunks.length;r++)if(s.segments[t].chunks[r]!==e.segments[t].chunks[r])return!1}return!0});function Vi(s){const e=F.c(28),{projects:t,onSelectProject:r,onCreateThread:a,onConnectRepo:l,onNewApp:o}=s;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx("div",{className:"flex h-14 w-14 items-center justify-center rounded-2xl border border-border bg-background shadow-sm",children:n.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 28 28",fill:"none",className:"text-foreground",children:[n.jsx("path",{d:"M14 4C8.477 4 4 8.477 4 14s4.477 10 10 10 10-4.477 10-10S19.523 4 14 4z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),n.jsx("path",{d:"M10 12.5c0-.828.672-1.5 1.5-1.5s1.5.672 1.5 1.5M15 12.5c0-.828.672-1.5 1.5-1.5s1.5.672 1.5 1.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),n.jsx("path",{d:"M10.5 17c.833 1 2.167 1.5 3.5 1.5s2.667-.5 3.5-1.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}),e[0]=i):i=e[0];let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx("h1",{className:"text-2xl font-semibold tracking-tight text-foreground text-balance",children:"Let's build"}),e[1]=c):c=e[1];const d=t.length===0?"Start or connect your first project":"Select a project to start coding";let u;e[2]!==d?(u=n.jsxs("div",{className:"flex flex-col items-center gap-3",children:[i,n.jsxs("div",{className:"text-center",children:[c,n.jsx("p",{className:"mt-1 text-base text-muted-foreground",children:d})]})]}),e[2]=d,e[3]=u):u=e[3];let f;if(e[4]!==a||e[5]!==r||e[6]!==t){let _;e[8]!==a||e[9]!==r?(_=w=>n.jsxs("button",{type:"button",className:"flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted",onClick:()=>{w.threads.length===0?a(w.projectId):r(w.projectId,w.threads[0].threadId)},children:[n.jsx(zn,{className:"h-5 w-5 text-muted-foreground"}),n.jsx("span",{className:"text-sm text-foreground leading-snug font-medium",children:w.name}),n.jsxs("span",{className:"text-xs text-muted-foreground",children:[w.threads.length," thread",w.threads.length!==1?"s":""]})]},w.projectId),e[8]=a,e[9]=r,e[10]=_):_=e[10],f=t.map(_),e[4]=a,e[5]=r,e[6]=t,e[7]=f}else f=e[7];let h,g,p;e[11]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(xs,{className:"h-5 w-5 text-muted-foreground"}),g=n.jsx("span",{className:"text-sm text-foreground leading-snug font-medium",children:"Connect a repo"}),p=n.jsx("span",{className:"text-xs text-muted-foreground",children:"Clone an existing repository"}),e[11]=h,e[12]=g,e[13]=p):(h=e[11],g=e[12],p=e[13]);let j;e[14]!==l?(j=n.jsxs("button",{type:"button",className:"flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted",onClick:l,children:[h,g,p]}),e[14]=l,e[15]=j):j=e[15];let v,b,I;e[16]===Symbol.for("react.memo_cache_sentinel")?(v=n.jsx(Xn,{className:"h-5 w-5 text-muted-foreground"}),b=n.jsx("span",{className:"text-sm text-foreground leading-snug font-medium",children:"New App"}),I=n.jsx("span",{className:"text-xs text-muted-foreground",children:"Create a new project from template"}),e[16]=v,e[17]=b,e[18]=I):(v=e[16],b=e[17],I=e[18]);let T;e[19]!==o?(T=n.jsxs("button",{type:"button",className:"flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted",onClick:o,children:[v,b,I]}),e[19]=o,e[20]=T):T=e[20];let x;e[21]!==T||e[22]!==f||e[23]!==j?(x=n.jsxs("div",{className:"flex flex-wrap justify-center gap-3",children:[f,j,T]}),e[21]=T,e[22]=f,e[23]=j,e[24]=x):x=e[24];let C;return e[25]!==x||e[26]!==u?(C=n.jsxs("div",{className:"mx-auto flex max-w-3xl flex-1 flex-col items-center justify-center gap-8 px-4",children:[u,x]}),e[25]=x,e[26]=u,e[27]=C):C=e[27],C}function Ki(s){const e=F.c(32),{messages:t,isStreaming:r,streamingSegments:a,streamingModel:l,isCreatingProject:o,isProcessingThread:i,selectedThreadId:c,projects:d,onSelectThread:u,onCreateThread:f,onConnectRepo:h,onNewApp:g,error:p,onClearError:j}=s,v=m.useRef(null);let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{v.current&&(v.current.scrollTop=v.current.scrollHeight)},e[0]=b):b=e[0];let I;e[1]!==t||e[2]!==a?(I=[t,a],e[1]=t,e[2]=a,e[3]=I):I=e[3],m.useEffect(b,I);const T=t.length===0&&!r&&!o&&!c,x=T&&"flex flex-col items-center justify-center";let C;e[4]!==x?(C=B("flex-1 overflow-y-auto",x),e[4]=x,e[5]=C):C=e[5];let _;e[6]!==h||e[7]!==f||e[8]!==g||e[9]!==u||e[10]!==d||e[11]!==T?(_=T&&n.jsx(Vi,{projects:d,onSelectProject:u,onCreateThread:f,onConnectRepo:h,onNewApp:g}),e[6]=h,e[7]=f,e[8]=g,e[9]=u,e[10]=d,e[11]=T,e[12]=_):_=e[12];let w;e[13]!==t?(w=t.map(Ji),e[13]=t,e[14]=w):w=e[14];let k;e[15]!==o||e[16]!==i||e[17]!==r||e[18]!==l||e[19]!==a?(k=(r||o||i)&&n.jsx(Wi,{segments:a,model:l}),e[15]=o,e[16]=i,e[17]=r,e[18]=l,e[19]=a,e[20]=k):k=e[20];let N;e[21]!==p||e[22]!==j?(N=p&&n.jsxs("div",{className:"mx-4 my-2 rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3",children:[n.jsx("p",{className:"text-sm text-destructive",children:p}),n.jsx("button",{type:"button",className:"mt-1 text-xs text-destructive underline underline-offset-2 hover:text-destructive/80",onClick:j,children:"Dismiss"})]}),e[21]=p,e[22]=j,e[23]=N):N=e[23];let y;e[24]!==w||e[25]!==k||e[26]!==N?(y=n.jsxs("div",{className:"mx-auto max-w-3xl pb-4 w-full min-w-0",children:[w,k,N]}),e[24]=w,e[25]=k,e[26]=N,e[27]=y):y=e[27];let S;return e[28]!==C||e[29]!==_||e[30]!==y?(S=n.jsxs("div",{ref:v,className:C,children:[_,y]}),e[28]=C,e[29]=_,e[30]=y,e[31]=S):S=e[31],S}function Ji(s){return n.jsx(Gi,{message:s},s.messageId)}function Qi({branchName:s,threadId:e}){const[t,r]=m.useState(""),[a,l]=m.useState(!1);m.useEffect(()=>{let i=!0;if(s)return ao().then(c=>{i&&r(c)}).catch(()=>{}),()=>{i=!1}},[s]);const o=async()=>{if(!(!e||a)){l(!0);try{const i=await po(e);await navigator.clipboard.writeText(i)}finally{l(!1)}}};return n.jsxs("div",{className:"flex items-center justify-end gap-2 px-8 py-2 mt-[-1rem] min-h-[2.25rem]",children:[e&&n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsx(J,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-50 hover:opacity-80",onClick:o,disabled:a,"aria-label":"Copy repository folder path",children:n.jsx(Xa,{className:"h-3 w-3"})})}),n.jsx(me,{side:"top",className:"bg-slate-900 text-white",children:"Copy repository folder path"})]}),s&&n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsxs("div",{className:"flex items-center gap-1.5 opacity-50 cursor-help",children:[n.jsx(xs,{className:"h-3 w-3"}),n.jsx("span",{className:"text-[11px] font-medium tracking-tight",children:s})]})}),t&&n.jsxs(me,{side:"top",className:"bg-slate-900 text-white",children:["User: ",t]})]})]})}function Yi(){const s=Ce().state,{selectedProjectId:e,selectedThreadId:t}=s,{terminalState:r,dispatch:a}=bs(t),{open:l,queuedCommand:o,outputLines:i,height:c,history:d,historyIndex:u,cwd:f,isRunning:h}=r,[g,p]=m.useState(""),[j,v]=m.useState([]),[b,I]=m.useState(!1),[T,x]=m.useState(!1),C=s.projects.flatMap(L=>L.threads).find(L=>L.threadId===t)?.path??null,_=!f||f==="."||f==="./"?C:f,w=m.useCallback(()=>{navigator.clipboard.writeText("terminal").then(()=>{x(!0),setTimeout(()=>x(!1),1500)})},[]),k=!_||_===C,N=m.useRef(null),y=m.useRef(null),S=m.useRef(null),R=m.useRef(0),E=m.useCallback(L=>{L.preventDefault(),I(!0)},[]),A=m.useCallback(()=>{I(!1)},[]),M=m.useCallback(L=>{if(b&&S.current){const q=S.current.getBoundingClientRect().bottom-L.clientY;q>=150&&q<=window.innerHeight*.8&&a({type:P.SetTerminalHeight,height:q})}},[b,a]);m.useEffect(()=>(b?(window.addEventListener("mousemove",M),window.addEventListener("mouseup",A),document.body.style.cursor="ns-resize",document.body.style.userSelect="none"):(window.removeEventListener("mousemove",M),window.removeEventListener("mouseup",A),document.body.style.cursor="",document.body.style.userSelect=""),()=>{window.removeEventListener("mousemove",M),window.removeEventListener("mouseup",A)}),[b,M,A]),m.useEffect(()=>{N.current&&(N.current.scrollTop=N.current.scrollHeight)},[j]),m.useEffect(()=>{v(i),R.current=i.length},[t,i]),m.useEffect(()=>{if(i.length===0)v([]),R.current=0;else if(i.length>R.current){const L=i.slice(R.current);v($=>[...$,...L]),R.current=i.length}},[i]),m.useEffect(()=>{l&&!h&&y.current?.focus()},[l,h]);const z=m.useCallback(async L=>{if(!(!e||!t||!L.trim())){a({type:P.AppendTerminalLine,line:{type:"input",content:L}}),a({type:P.SetTerminalHistory,history:[L,...d.filter($=>$!==L)].slice(0,50)}),a({type:P.SetTerminalHistoryIndex,index:-1}),p(""),a({type:P.SetTerminalRunning,isRunning:!0});try{const $=await Mo(e,t,L,f);if(!$){a({type:P.AppendTerminalLine,line:{type:"system",content:"Command started but no output stream received."}}),a({type:P.SetTerminalRunning,isRunning:!1});return}const q=$.getReader(),G=new TextDecoder;let K="";for(;;){const{done:X,value:de}=await q.read();if(X)break;K+=G.decode(de,{stream:!0});const ie=K.split(`
10
+ `);K=ie.pop()||"";for(const re of ie)if(re.trim())try{const ae=JSON.parse(re);typeof ae=="string"?a({type:P.AppendTerminalLine,line:{type:"output",content:ae}}):ae.type==="error"?a({type:P.AppendTerminalLine,line:{type:"error",content:ae.message}}):ae.type==="cwd"&&a({type:P.SetTerminalCwd,cwd:ae.path})}catch{a({type:P.AppendTerminalLine,line:{type:"output",content:re}})}}if(K.trim())try{const X=JSON.parse(K);typeof X=="string"?a({type:P.AppendTerminalLine,line:{type:"output",content:X}}):X.type==="error"?a({type:P.AppendTerminalLine,line:{type:"error",content:X.message}}):X.type==="cwd"&&a({type:P.SetTerminalCwd,cwd:X.path})}catch{a({type:P.AppendTerminalLine,line:{type:"output",content:K}})}}catch($){a({type:P.AppendTerminalLine,line:{type:"error",content:$ instanceof Error?$.message:"Failed to run command"}})}finally{a({type:P.SetTerminalRunning,isRunning:!1})}}},[e,t,f,a,d]);m.useEffect(()=>{o&&!h&&(z(o),a({type:P.ClearQueuedTerminalCommand}))},[o,h,a,z]);const O=L=>{if(L.key==="Enter")z(g);else if(L.key==="ArrowUp"){L.preventDefault();const $=u+1;$<d.length&&(a({type:P.SetTerminalHistoryIndex,index:$}),p(d[$]))}else if(L.key==="ArrowDown"){L.preventDefault();const $=u-1;$>=0?(a({type:P.SetTerminalHistoryIndex,index:$}),p(d[$])):(a({type:P.SetTerminalHistoryIndex,index:-1}),p(""))}};return l?n.jsxs("div",{ref:S,className:"flex flex-col border-t border-border bg-neutral-950 text-neutral-200 font-mono text-sm overflow-hidden animate-in slide-in-from-bottom-2 relative",style:{height:`${c}px`},children:[n.jsx("div",{className:"absolute top-0 left-0 right-0 h-1 cursor-ns-resize hover:bg-primary/50 transition-colors z-50",onMouseDown:E}),n.jsxs("div",{className:"flex items-center justify-between px-4 py-1.5 border-b border-white/10 bg-white/5",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(ds,{className:"h-3.5 w-3.5 text-neutral-400"}),n.jsx(we,{children:n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsx("span",{className:"text-xs font-medium text-neutral-400 cursor-pointer hover:text-neutral-200 transition-colors select-none",onClick:w,children:T?"Copied!":"Terminal"})}),n.jsx(me,{side:"bottom",children:n.jsx("span",{className:"font-mono text-xs",children:_||"/"})})]})}),!k&&n.jsx("span",{className:"text-[10px] text-neutral-500 font-mono bg-white/5 px-1.5 py-0.5 rounded border border-white/5",children:_}),h&&n.jsxs("div",{className:"flex gap-1 items-center ml-2",children:[n.jsx("div",{className:"h-1 w-1 rounded-full bg-primary animate-pulse"}),n.jsx("span",{className:"text-[10px] text-neutral-500 italic",children:"processing..."})]})]}),n.jsx("div",{className:"flex items-center gap-1",children:n.jsx(J,{variant:"ghost",size:"icon",className:"h-6 w-6 text-neutral-500 hover:text-neutral-200 hover:bg-white/10",onClick:()=>a({type:P.ToggleTerminal}),children:n.jsx(mt,{className:"h-3.5 w-3.5"})})})]}),n.jsxs("div",{ref:N,className:"flex-1 overflow-y-auto p-4 space-y-0.5 terminal-scrollbar",onClick:L=>{L.target===L.currentTarget&&y.current?.focus()},children:[j.length===0&&!h&&n.jsx("div",{className:"text-neutral-600 italic text-xs",children:"Enter your commands below..."}),j.map((L,$)=>n.jsxs("div",{className:`whitespace-pre-wrap break-all leading-6 ${L.type==="input"?"flex items-start gap-2 text-neutral-200":L.type==="error"?"text-red-400":L.type==="system"?"text-blue-400":""}`,children:[L.type==="input"&&n.jsx(Mt,{className:"h-4 w-4 mt-1 shrink-0 text-blue-400/70"}),n.jsx("span",{children:L.content})]},$))]}),n.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-t border-white/5 bg-white/5",children:[!k&&n.jsx("span",{className:"text-blue-400 text-xs font-bold whitespace-nowrap",children:_.split("/").pop()}),n.jsx(Mt,{className:`h-4 w-4 text-blue-400 ${k?"":"-ml-1"}`}),n.jsx("input",{ref:y,type:"text",className:"flex-1 bg-transparent border-none outline-none text-neutral-200 placeholder:text-neutral-700 h-6",placeholder:h?"Running...":"Type a command...",value:g,onChange:L=>p(L.target.value),onKeyDown:O,disabled:h}),n.jsxs("div",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded border border-white/10 bg-white/5",children:[n.jsx(Za,{className:"h-3 w-3 text-neutral-600"}),n.jsx("span",{className:"text-[10px] text-neutral-600 uppercase font-bold",children:"Enter"})]})]})]}):null}function Xi({threadId:s,onExit:e}){const{state:t}=Ce(),[r,a]=m.useState([]),[l,o]=m.useState(!0),[i,c]=m.useState(null),[d,u]=m.useState(0),[f,h]=m.useState(!1),g=m.useCallback(async()=>{if(s){o(!0),c(null);try{const N=await Go(s);a(N.files||[]),u(0)}catch(N){c(N instanceof Error?N.message:"Failed to load diff")}finally{o(!1)}}},[s]);m.useEffect(()=>{g()},[g]);const p=N=>{if(N.hunks.length===0)return null;let y=1/0,S=0;return N.hunks.forEach(R=>{const E=Math.min(R.oldStart,R.newStart),A=R.oldStart+R.oldLines,M=R.newStart+R.newLines,z=Math.max(A,M);y=Math.min(y,E),S=Math.max(S,z)}),y===1/0?null:{startLine:Math.max(1,y-2),endLine:S+2}},j=(N,y,S)=>N.split(`
11
+ `).slice(y-1,S).join(`
12
+ `),v=N=>{const y=p(N);return y?y.startLine<=1:!0},b=N=>{const y=N.split(".").pop()||"";return{ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",json:"json",md:"markdown",css:"css",scss:"scss",html:"html",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",kt:"kotlin",swift:"swift",c:"c",cpp:"cpp",h:"c",hpp:"cpp",sh:"shell",yaml:"yaml",yml:"yaml",xml:"xml",sql:"sql"}[y]||"plaintext"},I=N=>{switch(N){case"added":return n.jsx("span",{className:"status-badge font-mono text-xs font-semibold text-green-500",children:"A"});case"deleted":return n.jsx("span",{className:"status-badge font-mono text-xs font-semibold text-red-500",children:"D"});case"untracked":return n.jsx("span",{className:"status-badge font-mono text-xs font-semibold text-green-500",children:"U"});case"renamed":return n.jsx("span",{className:"status-badge font-mono text-xs font-semibold text-blue-500",children:"R"});default:return n.jsx("span",{className:"status-badge font-mono text-xs font-semibold text-orange-500",children:"M"})}},T=m.useMemo(()=>r.map(N=>{let y=0,S=0;return N.hunks.forEach(R=>{R.changes.forEach(E=>{E.type==="add"&&y++,E.type==="delete"&&S++})}),{additions:y,deletions:S}}),[r]),x=r[d],C=x?f?x.oldContent:(()=>{const N=p(x);return N?j(x.oldContent,N.startLine,N.endLine):x.oldContent})():"",_=x?f?x.newContent:(()=>{const N=p(x);return N?j(x.newContent,N.startLine,N.endLine):x.newContent})():"",w=m.useMemo(()=>T.reduce((N,y)=>N+y.additions,0),[T]),k=m.useMemo(()=>T.reduce((N,y)=>N+y.deletions,0),[T]);return l?n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsx(ve,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):i?n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-4",children:[n.jsx("p",{className:"text-destructive",children:i}),n.jsx(J,{variant:"outline",onClick:e,children:"Go Back"})]}):r.length===0?n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-4",children:[n.jsx("p",{className:"text-muted-foreground",children:"No changes to review"}),n.jsx(J,{variant:"outline",onClick:e,children:"Go Back"})]}):n.jsxs("div",{className:"diff-view-root flex h-full flex-col",children:[n.jsxs("div",{className:"diff-toolbar flex h-12 shrink-0 items-center justify-between border-b border-border bg-background px-4",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(J,{variant:"ghost",size:"icon",onClick:e,className:"h-8 w-8",children:n.jsx(mt,{className:"h-4 w-4"})}),n.jsx("span",{className:"text-sm font-medium",children:"Review Changes"}),n.jsxs("span",{className:"text-xs text-muted-foreground",children:[r.length," file",r.length!==1?"s":""]}),n.jsxs("span",{className:"text-xs text-green-500",children:["+",w]}),n.jsxs("span",{className:"text-xs text-red-500",children:["-",k]})]}),x&&n.jsx(J,{variant:"ghost",size:"sm",onClick:()=>h(N=>!N),className:"h-8 gap-1 px-2 text-xs",children:f?n.jsxs(n.Fragment,{children:[n.jsx(el,{className:"h-3 w-3"})," Show changes only"]}):n.jsxs(n.Fragment,{children:[n.jsx(tl,{className:"h-3 w-3"})," Show full file"]})})]}),n.jsxs("div",{className:"diff-body flex flex-1 overflow-hidden",children:[n.jsx("div",{className:"diff-file-list flex w-64 shrink-0 flex-col border-r border-border",children:n.jsx(Ke,{className:"flex-1",children:n.jsx("div",{className:"p-2 space-y-0.5",children:r.map((N,y)=>n.jsx("button",{onClick:()=>u(y),className:B("file-list-item w-full rounded-md px-2 py-2 text-left transition-colors hover:bg-accent",d===y&&"bg-accent"),children:n.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[n.jsx("span",{className:"file-name truncate text-xs font-medium flex-1 min-w-0",children:N.path}),I(N.status)]})},N.path))})})}),n.jsx("div",{className:"diff-editor-panel flex flex-1 flex-col overflow-hidden",children:x?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"diff-editor-header flex h-9 shrink-0 items-center border-b border-border bg-muted/40 px-4 gap-2",children:[I(x.status),n.jsx("span",{className:"text-xs font-medium truncate",children:x.path}),x.oldPath&&n.jsxs("span",{className:"text-xs text-muted-foreground truncate",children:["← ",x.oldPath]})]}),n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsx(sl,{original:C,modified:_,language:b(x.path),theme:t.sidebarOpen?"vs":"vs-dark",options:{readOnly:!0,renderSideBySide:!0,ignoreTrimWhitespace:!1,renderOverviewRuler:!0,scrollBeyondLastLine:!1,minimap:{enabled:!1},folding:!1,lineNumbers:f||v(x)?"on":"off",diffWordWrap:"on",originalEditable:!1,automaticLayout:!0}})})]}):null})]})]})}const ms=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("rounded-lg border bg-card text-card-foreground shadow-sm",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("div",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});ms.displayName="Card";const en=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("flex flex-col space-y-1.5 p-6",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("div",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});en.displayName="CardHeader";const tn=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("text-2xl font-semibold leading-none tracking-tight",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("div",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});tn.displayName="CardTitle";const Zi=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("text-sm text-muted-foreground",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("div",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Zi.displayName="CardDescription";const fs=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("p-6 pt-0",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("div",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});fs.displayName="CardContent";const ec=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("flex items-center p-6 pt-0",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("div",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});ec.displayName="CardFooter";const ze=m.forwardRef((s,e)=>{const t=F.c(11);let r,a,l;t[0]!==s?({className:r,type:l,...a}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l):(r=t[1],a=t[2],l=t[3]);let o;t[4]!==r?(o=B("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",r),t[4]=r,t[5]=o):o=t[5];let i;return t[6]!==a||t[7]!==e||t[8]!==o||t[9]!==l?(i=n.jsx("input",{type:l,className:o,ref:e,...a}),t[6]=a,t[7]=e,t[8]=o,t[9]=l,t[10]=i):i=t[10],i});ze.displayName="Input";const ft=al,tc=nl,aa=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(Zn,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});aa.displayName=Zn.displayName;const Qe=m.forwardRef((s,e)=>{const t=F.c(13);let r,a,l;t[0]!==s?({className:a,children:r,...l}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l):(r=t[1],a=t[2],l=t[3]);let o;t[4]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(aa,{}),t[4]=o):o=t[4];let i;t[5]!==a?(i=B("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",a),t[5]=a,t[6]=i):i=t[6];let c;t[7]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsxs(rl,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[n.jsx(mt,{className:"h-4 w-4"}),n.jsx("span",{className:"sr-only",children:"Close"})]}),t[7]=c):c=t[7];let d;return t[8]!==r||t[9]!==l||t[10]!==e||t[11]!==i?(d=n.jsxs(tc,{children:[o,n.jsxs(er,{ref:e,className:i,...l,children:[r,c]})]}),t[8]=r,t[9]=l,t[10]=e,t[11]=i,t[12]=d):d=t[12],d});Qe.displayName=er.displayName;const Ye=s=>{const e=F.c(8);let t,r;e[0]!==s?({className:t,...r}=s,e[0]=s,e[1]=t,e[2]=r):(t=e[1],r=e[2]);let a;e[3]!==t?(a=B("flex flex-col space-y-1.5 text-center sm:text-left",t),e[3]=t,e[4]=a):a=e[4];let l;return e[5]!==r||e[6]!==a?(l=n.jsx("div",{className:a,...r}),e[5]=r,e[6]=a,e[7]=l):l=e[7],l};Ye.displayName="DialogHeader";const Xe=s=>{const e=F.c(8);let t,r;e[0]!==s?({className:t,...r}=s,e[0]=s,e[1]=t,e[2]=r):(t=e[1],r=e[2]);let a;e[3]!==t?(a=B("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),e[3]=t,e[4]=a):a=e[4];let l;return e[5]!==r||e[6]!==a?(l=n.jsx("div",{className:a,...r}),e[5]=r,e[6]=a,e[7]=l):l=e[7],l};Xe.displayName="DialogFooter";const Ge=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("text-lg font-semibold leading-none tracking-tight",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(tr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Ge.displayName=tr.displayName;const He=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("text-sm text-muted-foreground",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(sr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});He.displayName=sr.displayName;const sc=ys("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),be=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B(sc(),r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(nr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});be.displayName=nr.displayName;const la=ys("inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 gap-2",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground"},size:{default:"h-10 px-3 min-w-10",sm:"h-9 px-2.5 min-w-9",lg:"h-11 px-5 min-w-11"}},defaultVariants:{variant:"default",size:"default"}}),nc=m.forwardRef((s,e)=>{const t=F.c(13);let r,a,l,o;t[0]!==s?({className:r,variant:o,size:l,...a}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l,t[4]=o):(r=t[1],a=t[2],l=t[3],o=t[4]);let i;t[5]!==r||t[6]!==l||t[7]!==o?(i=B(la({variant:o,size:l,className:r})),t[5]=r,t[6]=l,t[7]=o,t[8]=i):i=t[8];let c;return t[9]!==a||t[10]!==e||t[11]!==i?(c=n.jsx(rr,{ref:e,className:i,...a}),t[9]=a,t[10]=e,t[11]=i,t[12]=c):c=t[12],c});nc.displayName=rr.displayName;const oa=m.createContext({size:"default",variant:"default"}),os=m.forwardRef((s,e)=>{const t=F.c(19);let r,a,l,o,i;t[0]!==s?({className:a,variant:i,size:o,children:r,...l}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l,t[4]=o,t[5]=i):(r=t[1],a=t[2],l=t[3],o=t[4],i=t[5]);let c;t[6]!==a?(c=B("flex items-center justify-center gap-1",a),t[6]=a,t[7]=c):c=t[7];let d;t[8]!==o||t[9]!==i?(d={variant:i,size:o},t[8]=o,t[9]=i,t[10]=d):d=t[10];let u;t[11]!==r||t[12]!==d?(u=n.jsx(oa.Provider,{value:d,children:r}),t[11]=r,t[12]=d,t[13]=u):u=t[13];let f;return t[14]!==l||t[15]!==e||t[16]!==c||t[17]!==u?(f=n.jsx(ar,{ref:e,className:c,...l,children:u}),t[14]=l,t[15]=e,t[16]=c,t[17]=u,t[18]=f):f=t[18],f});os.displayName=ar.displayName;const Pt=m.forwardRef((s,e)=>{const t=F.c(17);let r,a,l,o,i;t[0]!==s?({className:a,children:r,variant:i,size:o,...l}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l,t[4]=o,t[5]=i):(r=t[1],a=t[2],l=t[3],o=t[4],i=t[5]);const c=m.useContext(oa);let d;t[6]!==a||t[7]!==c.size||t[8]!==c.variant||t[9]!==o||t[10]!==i?(d=B(la({variant:c.variant||i,size:c.size||o}),a),t[6]=a,t[7]=c.size,t[8]=c.variant,t[9]=o,t[10]=i,t[11]=d):d=t[11];let u;return t[12]!==r||t[13]!==l||t[14]!==e||t[15]!==d?(u=n.jsx(lr,{ref:e,className:d,...l,children:r}),t[12]=r,t[13]=l,t[14]=e,t[15]=d,t[16]=u):u=t[16],u});Pt.displayName=lr.displayName;const rc={"VS Code":{name:"VS Code",appName:["Visual Studio Code","code"]},Cursor:{name:"Cursor",appName:["Cursor","cursor"]},Windsurf:{name:"Windsurf",appName:["Windsurf","windsurf"]},Xcode:{name:"Xcode",appName:"Xcode"},"Android Studio":{name:"Android Studio",appName:["Android Studio","studio"]},Kiro:{name:"Kiro",appName:["Kiro","kiro"]},Terminal:{name:"Terminal",appName:"Terminal"}};Object.entries(rc).reduce((s,[e,t])=>(s[e]=t.appName,s),{});var he;(function(s){s.PullRequest="pull-request",s.Direct="direct"})(he||(he={}));he.PullRequest+"",he.PullRequest,he.Direct+"",he.Direct;const ac={bun:{id:"bun",label:"bun"},npm:{id:"npm",label:"npm"},yarn:{id:"yarn",label:"yarn"},pnpm:{id:"pnpm",label:"pnpm"}},lc={"angular-standalone":"logo-angular.svg","custom-angular":"logo-angular.svg",react:"logo-react.svg","vite-react":"logo-react.svg",vue:"logo-vue.svg","vite-vue":"logo-vue.svg","custom-svelte":"logo-svelte.svg","custom-ionic-svelte":"logo-svelte.svg","vite-svelte":"logo-svelte.svg","vite-solid":"logo-solid.svg",astro:"logo-astro.svg",nextjs:"logo-nextjs.svg",nuxt:"logo-nuxt.svg","vite-qwik":"logo-qwik.svg","vite-preact":"logo-preact.svg","vite-lit":"logo-lit.svg","vite-web":"logo-web.svg","tanstack-start":"logo-vite.svg",waku:"logo-waku.svg",hydrogen:"logo-hydrogen.svg",plugin:"logo-capacitor.svg"};function ia(s){const e=F.c(184),{open:t,onOpenChange:r,initialMode:a,onSubmitClone:l,onSubmitWebApp:o}=s,[i,c]=m.useState(a||"choice"),[d,u]=m.useState(1),[f,h]=m.useState("");let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=Qo(he.PullRequest),e[0]=g):g=e[0];const[p,j]=m.useState(g),[v,b]=m.useState("My App"),[I,T]=m.useState(!1);let x;e[1]===Symbol.for("react.memo_cache_sentinel")?(x=Yo(),e[1]=x):x=e[1];const[C,_]=m.useState(x);let w;e[2]===Symbol.for("react.memo_cache_sentinel")?(w=Ko(),e[2]=w):w=e[2];const[k,N]=m.useState(w);let y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=[],e[3]=y):y=e[3];const[S,R]=m.useState(y),[E,A]=m.useState(!1);let M;e[4]===Symbol.for("react.memo_cache_sentinel")?(M=new Set,e[4]=M):M=e[4];const[z,O]=m.useState(M);let L;e[5]===Symbol.for("react.memo_cache_sentinel")?(L=Q=>{O(xe=>new Set(xe).add(Q))},e[5]=L):L=e[5];const $=L;let q,G;if(e[6]!==S){if(q={},Array.isArray(S))for(const Q of S){const xe=Q.typeName;q[xe]||(q[xe]=[]),q[xe].push(Q)}G=Object.keys(q).sort(),e[6]=S,e[7]=q,e[8]=G}else q=e[7],G=e[8];const K=G;let X;e[9]!==q||e[10]!==K?(X={typeNames:K,templatesByTypeName:q},e[9]=q,e[10]=K,e[11]=X):X=e[11];const{typeNames:de,templatesByTypeName:ie}=X;let re;if(e[12]!==ie){re={};for(const Q of Object.keys(ie)){const xe=ie[Q]??[];if(xe.length===0)continue;const ke=xe.find(xc),Nt=xe.filter(gc),Yt=ke?[ke,...Nt]:xe;re[Q]=Yt[0].id}e[12]=ie,e[13]=re}else re=e[13];const ae=re;let le;e:{if(!Array.isArray(S)){le=C;break e}if(S.find(wa=>wa.id===C)){le=C;break e}if(S.length===0){le=C;break e}const xe=de[0];let ke;e[14]!==xe||e[15]!==ie?(ke=xe?ie[xe]??[]:[],e[14]=xe,e[15]=ie,e[16]=ke):ke=e[16];const Nt=ke;let Yt;e[17]!==Nt?(Yt=Nt.find(hc),e[17]=Nt,e[18]=Yt):Yt=e[18],le=(Yt??Nt[0])?.id??C}const ce=le;let te;e:{if(!ce||!Array.isArray(S)||S.length===0){te=null;break e}let Q;e[19]!==ce||e[20]!==S?(Q=S.find(xe=>xe.id===ce)?.typeName??null,e[19]=ce,e[20]=S,e[21]=Q):Q=e[21],te=Q}const se=te;let D;if(e[22]!==se||e[23]!==ie){e:{const Q=se?ie[se]??[]:[];if(Q.length<=1){D=Q;break e}const xe=Q.find(pc),ke=Q.filter(fc);D=xe?[xe,...ke]:Q}e[22]=se,e[23]=ie,e[24]=D}else D=e[24];const U=D;let H,V;e[25]!==ce?(H=()=>{ce&&Xo(ce)},V=[ce],e[25]=ce,e[26]=H,e[27]=V):(H=e[26],V=e[27]),m.useEffect(H,V);let Z,ee;e[28]!==a||e[29]!==t?(Z=()=>{t&&a&&setTimeout(()=>{c(a),u(2),a==="webapp"&&(b("My App"),T(!1),O(new Set))},0)},ee=[t,a],e[28]=a,e[29]=t,e[30]=Z,e[31]=ee):(Z=e[30],ee=e[31]),m.useEffect(Z,ee);let Y,W;e[32]!==i||e[33]!==t||e[34]!==S?(Y=()=>{i==="webapp"&&t&&(!Array.isArray(S)||S.length===0)&&setTimeout(()=>{A(!0),Cn().then(Q=>R(Q?.templates||[])).catch(()=>R([])).finally(()=>A(!1))},0)},W=[i,t,S],e[32]=i,e[33]=t,e[34]=S,e[35]=Y,e[36]=W):(Y=e[35],W=e[36]),m.useEffect(Y,W);const oe=I?v:se?`My ${se} App`:"My App";let Te;e[37]!==ce||e[38]!==S?(Te=ce&&Array.isArray(S)?S.find(Q=>Q.id===ce):null,e[37]=ce,e[38]=S,e[39]=Te):Te=e[39];const Ne=Te;let Be;e[40]!==S?(Be=()=>{c("webapp"),u(2),b("My App"),T(!1),O(new Set),(!Array.isArray(S)||S.length===0)&&(A(!0),Cn().then(Q=>R(Q?.templates||[])).catch(()=>R([])).finally(()=>A(!1)))},e[40]=S,e[41]=Be):Be=e[41];const Ze=Be;let gt;e[42]===Symbol.for("react.memo_cache_sentinel")?(gt=()=>{c("clone"),u(2)},e[42]=gt):gt=e[42];const Lt=gt;let xt;e[43]!==r?(xt=()=>{c("choice"),u(1),h(""),b("My App"),T(!1),O(new Set),r(!1)},e[43]=r,e[44]=xt):xt=e[44];const jt=xt;let pt;e[45]!==d?(pt=()=>{d===2?(c("choice"),u(1),h(""),b("My App"),T(!1)):u(mc)},e[45]=d,e[46]=pt):pt=e[46];const yt=pt;let bt;e[47]!==f||e[48]!==i||e[49]!==se?(bt=i==="clone"?f.trim().length>0:se!==null,e[47]=f,e[48]=i,e[49]=se,e[50]=bt):bt=e[50];const Ie=bt;let qe;e[51]!==p||e[52]!==f||e[53]!==r||e[54]!==l?(qe=()=>{if(!f.trim())return;const Q=f.trim();h(""),u(1),r(!1),c("choice"),l(Q,p).catch(uc)},e[51]=p,e[52]=f,e[53]=r,e[54]=l,e[55]=qe):qe=e[55];const et=qe;let Re;if(e[56]!==ce||e[57]!==r||e[58]!==o||e[59]!==k||e[60]!==oe){Re=()=>{if(!oe.trim()||!ce||!Q(oe))return;const xe=oe.trim();b(""),T(!1),u(1),r(!1),c("choice"),o(xe,ce,k).catch(dc)};const Q=cc;e[56]=ce,e[57]=r,e[58]=o,e[59]=k,e[60]=oe,e[61]=Re}else Re=e[61];const ne=i==="choice"?1:d;let We;e[62]!==Ie||e[63]!==f||e[64]!==i||e[65]!==ne?(We=Q=>Q===1?ne>1:Q===2?ne>=2:Q===3?ne>=2&&(i==="clone"?f.trim().length>0:Ie):!1,e[62]=Ie,e[63]=f,e[64]=i,e[65]=ne,e[66]=We):We=e[66];const ge=We;let Ve;e[67]===Symbol.for("react.memo_cache_sentinel")?(Ve=Q=>{Q===1?(c("choice"),u(1),h(""),b("")):u(Q)},e[67]=Ve):Ve=e[67];const tt=Ve;let Ee;e[68]!==jt?(Ee=Q=>!Q&&jt(),e[68]=jt,e[69]=Ee):Ee=e[69];let _e;e[70]!==ge?(_e=()=>ge(1)&&tt(1),e[70]=ge,e[71]=_e):_e=e[71];const Et=ne===1?"bg-primary text-primary-foreground scale-110":ne>1?"bg-brand text-brand-foreground":"bg-muted text-muted-foreground";let Pe;e[72]!==ge||e[73]!==Et?(Pe=B("flex items-center justify-center h-8 w-8 rounded-full text-sm font-medium shrink-0 transition-colors transition-transform duration-300 ease-out",Et,ge(1)&&"cursor-pointer hover:opacity-90"),e[72]=ge,e[73]=Et,e[74]=Pe):Pe=e[74];let Me;e[75]!==_e||e[76]!==Pe?(Me=n.jsx("button",{type:"button",onClick:_e,className:Pe,"aria-label":"Go to step 1",children:"1"}),e[75]=_e,e[76]=Pe,e[77]=Me):Me=e[77];const _t=ne>=2?"100%":"0%";let De;e[78]!==_t?(De=n.jsx("div",{className:"h-0.5 flex-1 min-w-0 relative rounded-full overflow-hidden bg-muted",children:n.jsx("div",{className:"absolute inset-y-0 left-0 bg-brand transition-[width] duration-300 ease-out rounded-full",style:{width:_t}})}),e[78]=_t,e[79]=De):De=e[79];let st;e[80]!==ge?(st=()=>ge(2)&&tt(2),e[80]=ge,e[81]=st):st=e[81];const nt=ne===2?"bg-primary text-primary-foreground scale-110":ne>2?"bg-brand text-brand-foreground":"bg-muted text-muted-foreground";let Ae;e[82]!==ge||e[83]!==nt?(Ae=B("flex items-center justify-center h-8 w-8 rounded-full text-sm font-medium shrink-0 transition-colors transition-transform duration-300 ease-out",nt,ge(2)&&"cursor-pointer hover:opacity-90"),e[82]=ge,e[83]=nt,e[84]=Ae):Ae=e[84];let rt;e[85]!==st||e[86]!==Ae?(rt=n.jsx("button",{type:"button",onClick:st,className:Ae,"aria-label":"Go to step 2",children:"2"}),e[85]=st,e[86]=Ae,e[87]=rt):rt=e[87];const at=ne>=3?"100%":"0%";let Le;e[88]!==at?(Le=n.jsx("div",{className:"h-0.5 flex-1 min-w-0 relative rounded-full overflow-hidden bg-muted",children:n.jsx("div",{className:"absolute inset-y-0 left-0 bg-brand transition-[width] duration-300 ease-out rounded-full",style:{width:at}})}),e[88]=at,e[89]=Le):Le=e[89];let lt;e[90]!==ge?(lt=()=>ge(3)&&tt(3),e[90]=ge,e[91]=lt):lt=e[91];const ot=ne===3?"bg-primary text-primary-foreground scale-110":"bg-muted text-muted-foreground";let $e;e[92]!==ge||e[93]!==ot?($e=B("flex items-center justify-center h-8 w-8 rounded-full text-sm font-medium shrink-0 transition-colors transition-transform duration-300 ease-out",ot,ge(3)&&"cursor-pointer hover:opacity-90"),e[92]=ge,e[93]=ot,e[94]=$e):$e=e[94];let Oe;e[95]!==lt||e[96]!==$e?(Oe=n.jsx("button",{type:"button",onClick:lt,className:$e,"aria-label":"Go to step 3",children:"3"}),e[95]=lt,e[96]=$e,e[97]=Oe):Oe=e[97];let Fe;e[98]!==Me||e[99]!==De||e[100]!==rt||e[101]!==Le||e[102]!==Oe?(Fe=n.jsxs("div",{className:"mx-auto flex items-center gap-1 mb-6 w-2/3",children:[Me,De,rt,Le,Oe]}),e[98]=Me,e[99]=De,e[100]=rt,e[101]=Le,e[102]=Oe,e[103]=Fe):Fe=e[103];const it=ne===1&&"New Project",ct=ne===2&&i==="clone"&&"Clone Repository",vt=ne===2&&i==="webapp"&&"Create App",dt=ne===3&&i==="clone"&&"Clone Repository",Ue=ne===3&&i==="webapp"&&(se==="Capacitor Plugin"?"Create Capacitor Plugin":se?`Create ${se} App`:"Create App");let ht;e[104]!==it||e[105]!==ct||e[106]!==vt||e[107]!==dt||e[108]!==Ue?(ht=n.jsxs(Ge,{children:[it,ct,vt,dt,Ue]}),e[104]=it,e[105]=ct,e[106]=vt,e[107]=dt,e[108]=Ue,e[109]=ht):ht=e[109];const as=ne===1&&"Choose how to add a new project.",Gs=ne===2&&i==="clone"&&"Enter a git repository URL to clone.",Hs=ne===2&&i==="webapp"&&"Choose a template type.",Us=ne===3&&i==="clone"&&"Choose commit workflow.",zs=ne===3&&i==="webapp"&&"Name your project and choose variation, package manager, and commit workflow.";let $t;e[110]!==as||e[111]!==Gs||e[112]!==Hs||e[113]!==Us||e[114]!==zs?($t=n.jsxs(He,{children:[as,Gs,Hs,Us,zs]}),e[110]=as,e[111]=Gs,e[112]=Hs,e[113]=Us,e[114]=zs,e[115]=$t):$t=e[115];let Ot;e[116]!==ht||e[117]!==$t?(Ot=n.jsxs(Ye,{children:[ht,$t]}),e[116]=ht,e[117]=$t,e[118]=Ot):Ot=e[118];let Ft;e[119]!==Fe||e[120]!==Ot?(Ft=n.jsxs("div",{className:"px-6 pt-6 pb-2",children:[Fe,Ot]}),e[119]=Fe,e[120]=Ot,e[121]=Ft):Ft=e[121];let Gt;e[122]!==Ze||e[123]!==ne?(Gt=ne===1&&n.jsx(Ke,{className:"flex-1 min-h-0 overflow-hidden",children:n.jsx("div",{className:"px-6 py-4",children:n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx(ms,{role:"button",tabIndex:0,className:"cursor-pointer transition-colors hover:border-primary/50 hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:Lt,onKeyDown:Q=>Q.key==="Enter"&&Lt(),children:n.jsxs(fs,{className:"flex items-start gap-4 p-4",children:[n.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-lg bg-brand text-brand-foreground",children:n.jsx(xs,{className:"h-6 w-6"})}),n.jsxs("div",{className:"min-w-0 flex-1 space-y-0.5",children:[n.jsx("p",{className:"font-semibold",children:"Clone repo"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Connect an existing repository by URL"})]})]})}),n.jsx(ms,{role:"button",tabIndex:0,className:"cursor-pointer transition-colors hover:border-primary/50 hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:Ze,onKeyDown:Q=>Q.key==="Enter"&&Ze(),children:n.jsxs(fs,{className:"flex items-start gap-4 p-4",children:[n.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-lg bg-brand text-brand-foreground",children:n.jsx(Xn,{className:"h-6 w-6"})}),n.jsxs("div",{className:"min-w-0 flex-1 space-y-0.5",children:[n.jsx("p",{className:"font-semibold",children:"Create App"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Scaffold a new React, Vue, Next.js, or other template"})]})]})})]})})}),e[122]=Ze,e[123]=ne,e[124]=Gt):Gt=e[124];let Ht;e[125]!==Ie||e[126]!==f||e[127]!==i||e[128]!==ne?(Ht=ne===2&&i==="clone"&&n.jsx(Ke,{className:"flex-1 min-h-0 overflow-hidden",children:n.jsx("div",{className:"px-6 py-4",children:n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx(be,{htmlFor:"gitUrl",children:"Repository URL"}),n.jsx(ze,{id:"gitUrl",placeholder:"https://github.com/user/repo.git",value:f,onChange:Q=>h(Q.target.value),onKeyDown:Q=>Q.key==="Enter"&&Ie&&u(3)})]})})}),e[125]=Ie,e[126]=f,e[127]=i,e[128]=ne,e[129]=Ht):Ht=e[129];let Ut;e[130]!==ae||e[131]!==z||e[132]!==i||e[133]!==se||e[134]!==ne||e[135]!==ie||e[136]!==E||e[137]!==de?(Ut=ne===2&&i==="webapp"&&n.jsx("div",{className:"flex flex-col flex-1 min-h-0 px-6 pb-4",children:n.jsx("div",{className:"flex-1 min-h-0 flex flex-col py-2",children:n.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto -mx-1",children:n.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-2 p-1 mr-2",children:E?n.jsx("p",{className:"col-span-full p-4 text-sm text-muted-foreground",children:"Loading…"}):de.map(Q=>{const xe=ie[Q]?.[0]?.type,ke=xe?lc[xe]:null,Nt=se===Q;return n.jsxs("button",{type:"button",onClick:()=>_(ae[Q]??""),onDoubleClick:()=>{_(ae[Q]??""),u(3)},className:B("flex flex-col items-center gap-2 rounded-lg border px-3 py-3 text-center transition-colors",Nt?"border-primary bg-accent text-accent-foreground":"border-border bg-card hover:bg-muted/50 hover:border-muted-foreground/30 shadow-sm"),children:[ke?n.jsx("img",{src:`/template-types/${ke}`,alt:"",className:B("size-8 shrink-0 transition-opacity duration-300",z.has(ke)?"opacity-100":"opacity-0"),onLoad:()=>$(ke),"aria-hidden":!0}):null,n.jsx("span",{className:"font-medium text-sm truncate w-full",children:Q})]},Q)})})})})}),e[130]=ae,e[131]=z,e[132]=i,e[133]=se,e[134]=ne,e[135]=ie,e[136]=E,e[137]=de,e[138]=Ut):Ut=e[138];let zt;e[139]!==p||e[140]!==ce||e[141]!==i||e[142]!==k||e[143]!==oe||e[144]!==Ne||e[145]!==ne||e[146]!==U?(zt=ne===3&&i==="webapp"&&n.jsx(Ke,{className:"flex-1 min-h-0 overflow-hidden",children:n.jsxs("div",{className:"px-6 py-4 flex flex-col gap-6",children:[n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx(be,{htmlFor:"projectName",children:"Project name"}),n.jsx(ze,{id:"projectName",placeholder:"My App",value:oe,onChange:Q=>{b(Q.target.value),T(!0)},className:"max-w-xs"})]}),n.jsxs("div",{className:"flex flex-col gap-3",children:[U.length>1&&n.jsxs(n.Fragment,{children:[n.jsx(be,{className:"text-sm font-medium",children:"Variation"}),n.jsx(os,{type:"single",value:ce,onValueChange:Q=>Q&&_(Q),variant:"outline",className:"flex flex-wrap gap-0 justify-start [&>button]:rounded-none [&>button:first-child]:rounded-l-md [&>button:last-child]:rounded-r-md [&>button:not(:first-child)]:-ml-px",children:U.map(ic)})]}),n.jsxs("p",{className:"text-xs text-muted-foreground",children:[Ne?.description??U[0]?.description??"",Ne?.url&&n.jsxs(n.Fragment,{children:[" ",n.jsxs("a",{href:Ne.url,target:"_blank",rel:"noreferrer",className:"text-brand hover:underline hover:text-brand/80 inline-flex items-center gap-0.5",children:["Documentation ",n.jsx(js,{className:"h-3 w-3"})]})]})]})]}),n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx(be,{className:"text-sm font-medium",children:"Package manager"}),n.jsx(os,{type:"single",value:k,onValueChange:Q=>{Q&&(N(Q),Jo(Q))},variant:"outline",className:"flex flex-wrap gap-0 justify-start [&>button]:rounded-none [&>button:first-child]:rounded-l-md [&>button:last-child]:rounded-r-md [&>button:not(:first-child)]:-ml-px",children:Object.values(ac).map(oc)})]}),n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx(be,{className:"text-sm font-medium",children:"Commit method"}),n.jsxs(os,{type:"single",value:p,onValueChange:Q=>{(Q===he.PullRequest||Q===he.Direct)&&(j(Q),Rn(Q))},variant:"outline",className:"flex flex-wrap gap-0 justify-start [&>button]:rounded-none [&>button:first-child]:rounded-l-md [&>button:last-child]:rounded-r-md [&>button:not(:first-child)]:-ml-px",children:[n.jsx(Pt,{value:he.PullRequest,className:"text-sm",children:"Pull Requests"}),n.jsx(Pt,{value:he.Direct,className:"text-sm",children:"Direct Commits"})]}),n.jsx("p",{className:"text-xs text-slate-600 dark:text-slate-400",children:p===he.PullRequest?"Creates a feature branch and allows you to create pull requests.":"Commits directly to the main branch without creating feature branches."})]})]})}),e[139]=p,e[140]=ce,e[141]=i,e[142]=k,e[143]=oe,e[144]=Ne,e[145]=ne,e[146]=U,e[147]=zt):zt=e[147];let Bt;e[148]!==p||e[149]!==i||e[150]!==ne?(Bt=ne===3&&i==="clone"&&n.jsx(Ke,{className:"flex-1 min-h-0 overflow-hidden",children:n.jsx("div",{className:"px-6 py-4 flex flex-col gap-6",children:n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx(be,{className:"text-sm font-medium",children:"Commit method"}),n.jsxs(os,{type:"single",value:p,onValueChange:Q=>{(Q===he.PullRequest||Q===he.Direct)&&(j(Q),Rn(Q))},variant:"outline",className:"flex flex-wrap gap-0 justify-start [&>button]:rounded-none [&>button:first-child]:rounded-l-md [&>button:last-child]:rounded-r-md [&>button:not(:first-child)]:-ml-px",children:[n.jsx(Pt,{value:he.PullRequest,className:"text-sm",children:"Pull Requests"}),n.jsx(Pt,{value:he.Direct,className:"text-sm",children:"Direct Commits"})]}),n.jsx("p",{className:"text-xs text-slate-600 dark:text-slate-400",children:p===he.PullRequest?"Creates a feature branch and allows you to create pull requests.":"Commits directly to the main branch without creating feature branches."})]})})}),e[148]=p,e[149]=i,e[150]=ne,e[151]=Bt):Bt=e[151];let qt;e[152]!==yt||e[153]!==ne?(qt=ne>1&&n.jsx(J,{variant:"ghost",onClick:yt,children:"Back"}),e[152]=yt,e[153]=ne,e[154]=qt):qt=e[154];let Wt;e[155]!==Ie||e[156]!==ne?(Wt=ne===2&&n.jsx(J,{onClick:()=>u(3),disabled:!Ie,children:"Next"}),e[155]=Ie,e[156]=ne,e[157]=Wt):Wt=e[157];let Vt;e[158]!==et||e[159]!==i||e[160]!==ne?(Vt=ne===3&&i==="clone"&&n.jsx(J,{onClick:et,children:"Clone Repository"}),e[158]=et,e[159]=i,e[160]=ne,e[161]=Vt):Vt=e[161];let Kt;e[162]!==Re||e[163]!==i||e[164]!==oe||e[165]!==ne?(Kt=ne===3&&i==="webapp"&&n.jsx(J,{onClick:Re,disabled:!oe.trim(),children:"Create App"}),e[162]=Re,e[163]=i,e[164]=oe,e[165]=ne,e[166]=Kt):Kt=e[166];let Jt;e[167]!==qt||e[168]!==Wt||e[169]!==Vt||e[170]!==Kt?(Jt=n.jsx("div",{className:"px-6 py-4 border-t border-border bg-muted/10 min-h-[4.5rem] flex flex-col justify-end",children:n.jsxs(Xe,{children:[qt,Wt,Vt,Kt]})}),e[167]=qt,e[168]=Wt,e[169]=Vt,e[170]=Kt,e[171]=Jt):Jt=e[171];let Qt;e[172]!==Ft||e[173]!==Gt||e[174]!==Ht||e[175]!==Ut||e[176]!==zt||e[177]!==Bt||e[178]!==Jt?(Qt=n.jsxs(Qe,{className:"max-w-2xl h-[min(42rem,90dvh)] flex flex-col p-0 overflow-hidden",children:[Ft,Gt,Ht,Ut,zt,Bt,Jt]}),e[172]=Ft,e[173]=Gt,e[174]=Ht,e[175]=Ut,e[176]=zt,e[177]=Bt,e[178]=Jt,e[179]=Qt):Qt=e[179];let Ns;return e[180]!==t||e[181]!==Ee||e[182]!==Qt?(Ns=n.jsx(ft,{open:t,onOpenChange:Ee,children:Qt}),e[180]=t,e[181]=Ee,e[182]=Qt,e[183]=Ns):Ns=e[183],Ns}function oc(s){return n.jsx(Pt,{value:s.id,className:"text-sm",children:s.label},s.id)}function ic(s){return n.jsx(Pt,{value:s.id,className:"text-sm",children:s.variationName},s.id)}function cc(s){return s.trim().toLowerCase().replace(/\s+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function dc(){}function uc(){}function mc(s){return s-1}function fc(s){return s.variationName!=="Starter"}function pc(s){return s.variationName==="Starter"}function hc(s){return s.variationName==="Starter"}function gc(s){return s.variationName!=="Starter"}function xc(s){return s.variationName==="Starter"}function jc({onCreateThread:s}){const{state:e,dispatch:t}=Ce(),[r,a]=m.useState(null),[l,o]=m.useState(!1),[i,c]=m.useState(null),d=m.useRef(""),u=m.useRef(""),f=m.useRef([]),h=m.useRef(!1),g=m.useRef(null),p=m.useRef(null),j=m.useRef(()=>{}),[v,b]=m.useState(null),I=m.useRef(!1),T=m.useRef(null),{selectedThreadId:x,selectedProjectId:C,messages:_,queuedChatMessages:w,isStreaming:k,streamingSegments:N,streamingModel:y,isCreatingProject:S,processingThreadIds:R,projects:E}=e,z=!!(x&&R.includes(x))&&!(v===x&&!k),O=C&&x?E.find(te=>te.projectId===C)?.threads.find(te=>te.threadId===x):void 0,L=m.useCallback(te=>{g.current=null,p.current=null;const se=f.current,D=Fl(se)||"...";if(T.current&&se.length===0){const H={messageId:`msg-${Date.now()}-error`,sender:"agent",content:`Error: ${T.current}`,contentType:"text",timestamp:new Date().toISOString(),model:e.streamingModel||te,isThinking:!1};t({type:P.AddMessage,message:H}),t({type:P.ResetStream}),T.current=null;return}const U={messageId:`msg-${Date.now()}-agent`,sender:"agent",content:D,contentType:"markdown",timestamp:new Date().toISOString(),model:e.streamingModel||te,isThinking:!1};d.current="",u.current="",f.current=[],T.current=null,t({type:P.AddMessage,message:U}),t({type:P.ResetStream}),x&&t({type:P.MarkThreadCompleted,threadId:x})},[e.streamingModel,t,x]);m.useEffect(()=>{j.current=L},[L]);const $=m.useCallback(()=>{x&&b(x),g.current&&(g.current.abort(),g.current=null),p.current&&(p.current(),p.current=null),L(e.streamingModel||"default")},[x,L,e.streamingModel]);m.useEffect(()=>{I.current&&!k&&g.current&&(g.current.abort(),g.current=null,p.current&&(p.current(),p.current=null),j.current(y||"default")),I.current=k},[k,y]),m.useEffect(()=>()=>{g.current&&(g.current.abort(),g.current=null),p.current&&(p.current(),p.current=null),t({type:P.ResetStream})},[x,t]),m.useEffect(()=>{if(!x)return;let te=!1;async function se(){try{const D=await fo(x);te||t({type:P.SetMessages,messages:D.messages})}catch(D){console.error("Failed to load chat history:",D),te||t({type:P.SetMessages,messages:[]})}}return se(),()=>{te=!0}},[x,C,t]);const q=m.useCallback(async(te,se,D,U)=>{if(!x)return;a(null),b(null),g.current&&g.current.abort(),p.current&&p.current();const H={messageId:`msg-${Date.now()}`,sender:"user",content:te,contentType:"text",timestamp:new Date().toISOString(),model:se,attachments:D.map(ee=>({fileName:ee.fileName,content:ee.content}))};t({type:P.AddMessage,message:H});const V=te.trim().replace(/\n/g," ").slice(0,100);C&&x&&(uo(x,{title:V}).catch(ee=>{console.error("Failed to update thread title:",ee)}),t({type:P.UpdateThreadTitle,projectId:C,threadId:x,title:V})),t({type:P.ResetStream}),t({type:P.SetStreaming,isStreaming:!0}),d.current="",h.current=!1;const Z=new AbortController;g.current=Z;try{const ee=await ho(x,te,se,D,Z.signal,U);ee&&(p.current=xo(ee,Y=>{if(Y.type!=="message"){if(Y.type==="toolcall_delta"){if(Y.partial?.content?.[0]?.id&&Y.delta){const W=Y.partial.content[0].id,oe=Y.partial.content[0].name;t({type:P.UpdateToolCallProgress,toolCallId:W,progress:{toolCallId:W,toolName:oe,delta:Y.delta,partial:Y.partial}})}return}if(Y.model&&t({type:P.SetStreamModel,model:Y.model}),Y.type==="thinking"||Y.isThinking){u.current+=Y.content||"";const W=Bs(f.current,"thinking",Y.content||"");f.current=W,t({type:P.AppendStreamChunk,chunkType:"thinking",content:Y.content||"",segments:W})}else if(Y.type==="result"){h.current=!0,d.current=Y.content||"";const W=Xs(f.current,Y.content||"");f.current=W,t({type:P.SetStreamContent,content:Y.content||""})}else{if(h.current)return;d.current+=Y.content||"";const W=Bs(f.current,"content",Y.content||"");f.current=W,t({type:P.AppendStreamChunk,chunkType:"content",content:Y.content||"",segments:W})}}},()=>{j.current(se)},Y=>{Y.includes("AbortError")||Y.includes("canceled")||Y.includes("BodyStreamBuffer was aborted")||(T.current=Y,a(Y))},Y=>{if(Y.role==="assistant"){const W=Y.content??"",oe=typeof W=="string"?W:JSON.stringify(W);let Te=!1;if(typeof W=="object"&&Array.isArray(W)&&W.length>0)Te=!0;else if(typeof oe=="string"&&oe.trim().startsWith("["))try{const Ne=JSON.parse(oe);Te=Array.isArray(Ne)&&Ne.length>0}catch{}if(Te)h.current=!0,d.current=oe,f.current=Xs(f.current,oe),t({type:P.SetStreamContent,content:oe});else{d.current+=oe;const Ne=Bs(f.current,"content",oe);f.current=Ne,t({type:P.AppendStreamChunk,chunkType:"content",content:oe,segments:Ne})}}}))}catch(ee){if(ee instanceof Error&&ee.name==="AbortError"||ee instanceof Error&&ee.message.includes("BodyStreamBuffer was aborted"))return;a(ee instanceof Error?ee.message:"Failed to send message. Please ensure the CLI server is running on localhost:641"),T.current=ee instanceof Error?ee.message:"Failed to send message. Please ensure the CLI server is running on localhost:641",t({type:P.ResetStream})}},[x,C,t]),G=m.useMemo(()=>x?w.filter(te=>te.threadId===x):[],[x,w]),K=m.useRef(!1);m.useEffect(()=>{if(k||!x||G.length===0||K.current)return;const[te]=G;K.current=!0,t({type:P.RemoveQueuedChatMessage,queuedMessageId:te.id});const se=setTimeout(()=>{q(te.message,te.model,te.attachments,te.provider),K.current=!1},0);return()=>{clearTimeout(se),K.current=!1}},[t,q,k,G,x]);const X=m.useCallback(te=>{const se=G.find(D=>D.id===te);t({type:P.RemoveQueuedChatMessage,queuedMessageId:te}),!(!se||k||_.length>0||!x)&&q(se.message,se.model,se.attachments,se.provider)},[t,q,k,_.length,G,x]),de=()=>{c("clone"),o(!0)},ie=()=>{c("webapp"),o(!0)},re=async(te,se)=>{try{await Xr(te,se),o(!1),c(null)}catch(D){a(D instanceof Error?D.message:"Failed to clone repository")}},ae=async(te,se,D)=>{try{await Yr(te,se,D),o(!1),c(null)}catch(U){a(U instanceof Error?U.message:"Failed to create project")}},le=()=>{t({type:P.SetReviewMode,reviewMode:!1})},{reviewMode:ce}=e;return n.jsxs("div",{className:"flex h-full flex-col",children:[ce&&x?n.jsx(Xi,{threadId:x,onExit:le}):n.jsx(Ki,{messages:_,isStreaming:k,streamingSegments:N,streamingModel:y,isCreatingProject:S,isProcessingThread:z,selectedThreadId:x,projects:E,onSelectThread:(te,se)=>{t({type:P.SelectThread,projectId:te,threadId:se})},onCreateThread:s,onConnectRepo:de,onNewApp:ie,error:r,onClearError:()=>a(null)}),n.jsxs("div",{className:"relative mx-auto w-full max-w-3xl",children:[n.jsx(Ni,{onSend:q,onStop:$,isStreaming:k,disabled:!x&&!S,initialValue:"",queuedMessages:G,onRemoveQueuedMessage:X}),n.jsx(Qi,{branchName:O?.currentBranch,threadId:x??void 0})]}),n.jsx(Yi,{}),n.jsx(ia,{open:l,onOpenChange:o,initialMode:i||void 0,onSubmitClone:re,onSubmitWebApp:ae})]})}const ca=il,da=cl,yc=m.forwardRef((s,e)=>{const t=F.c(14);let r,a,l,o;t[0]!==s?({className:a,inset:l,children:r,...o}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l,t[4]=o):(r=t[1],a=t[2],l=t[3],o=t[4]);const i=l&&"pl-8";let c;t[5]!==a||t[6]!==i?(c=B("flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",i,a),t[5]=a,t[6]=i,t[7]=c):c=t[7];let d;t[8]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(Mt,{className:"ml-auto"}),t[8]=d):d=t[8];let u;return t[9]!==r||t[10]!==o||t[11]!==e||t[12]!==c?(u=n.jsxs(or,{ref:e,className:c,...o,children:[r,d]}),t[9]=r,t[10]=o,t[11]=e,t[12]=c,t[13]=u):u=t[13],u});yc.displayName=or.displayName;const bc=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg 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",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(ir,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});bc.displayName=ir.displayName;const gn=m.forwardRef((s,e)=>{const t=F.c(11);let r,a,l;t[0]!==s?({className:r,sideOffset:l,...a}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l):(r=t[1],a=t[2],l=t[3]);const o=l===void 0?4:l;let i;t[4]!==r?(i=B("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md 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",r),t[4]=r,t[5]=i):i=t[5];let c;return t[6]!==a||t[7]!==e||t[8]!==o||t[9]!==i?(c=n.jsx(ll,{children:n.jsx(cr,{ref:e,sideOffset:o,className:i,...a})}),t[6]=a,t[7]=e,t[8]=o,t[9]=i,t[10]=c):c=t[10],c});gn.displayName=cr.displayName;const Ct=m.forwardRef((s,e)=>{const t=F.c(11);let r,a,l;t[0]!==s?({className:r,inset:a,...l}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l):(r=t[1],a=t[2],l=t[3]);const o=a&&"pl-8";let i;t[4]!==r||t[5]!==o?(i=B("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",o,r),t[4]=r,t[5]=o,t[6]=i):i=t[6];let c;return t[7]!==l||t[8]!==e||t[9]!==i?(c=n.jsx(dr,{ref:e,className:i,...l}),t[7]=l,t[8]=e,t[9]=i,t[10]=c):c=t[10],c});Ct.displayName=dr.displayName;const vc=m.forwardRef((s,e)=>{const t=F.c(14);let r,a,l,o;t[0]!==s?({className:l,children:a,checked:r,...o}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l,t[4]=o):(r=t[1],a=t[2],l=t[3],o=t[4]);let i;t[5]!==l?(i=B("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",l),t[5]=l,t[6]=i):i=t[6];let c;t[7]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:n.jsx(hr,{children:n.jsx(Je,{className:"h-4 w-4"})})}),t[7]=c):c=t[7];let d;return t[8]!==r||t[9]!==a||t[10]!==o||t[11]!==e||t[12]!==i?(d=n.jsxs(ur,{ref:e,className:i,checked:r,...o,children:[c,a]}),t[8]=r,t[9]=a,t[10]=o,t[11]=e,t[12]=i,t[13]=d):d=t[13],d});vc.displayName=ur.displayName;const Nc=m.forwardRef((s,e)=>{const t=F.c(12);let r,a,l;t[0]!==s?({className:a,children:r,...l}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l):(r=t[1],a=t[2],l=t[3]);let o;t[4]!==a?(o=B("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),t[4]=a,t[5]=o):o=t[5];let i;t[6]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:n.jsx(hr,{children:n.jsx(ol,{className:"h-2 w-2 fill-current"})})}),t[6]=i):i=t[6];let c;return t[7]!==r||t[8]!==l||t[9]!==e||t[10]!==o?(c=n.jsxs(mr,{ref:e,className:o,...l,children:[i,r]}),t[7]=r,t[8]=l,t[9]=e,t[10]=o,t[11]=c):c=t[11],c});Nc.displayName=mr.displayName;const wc=m.forwardRef((s,e)=>{const t=F.c(11);let r,a,l;t[0]!==s?({className:r,inset:a,...l}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l):(r=t[1],a=t[2],l=t[3]);const o=a&&"pl-8";let i;t[4]!==r||t[5]!==o?(i=B("px-2 py-1.5 text-sm font-semibold",o,r),t[4]=r,t[5]=o,t[6]=i):i=t[6];let c;return t[7]!==l||t[8]!==e||t[9]!==i?(c=n.jsx(fr,{ref:e,className:i,...l}),t[7]=l,t[8]=e,t[9]=i,t[10]=c):c=t[10],c});wc.displayName=fr.displayName;const Sc=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("-mx-1 my-1 h-px bg-muted",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(pr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Sc.displayName=pr.displayName;const Cc=1,Tc=1e6;let qs=0;function Ic(){return qs=(qs+1)%Number.MAX_SAFE_INTEGER,qs.toString()}const Ws=new Map,Pn=s=>{if(Ws.has(s))return;const e=setTimeout(()=>{Ws.delete(s),cs({type:"REMOVE_TOAST",toastId:s})},Tc);Ws.set(s,e)},kc=(s,e)=>{switch(e.type){case"ADD_TOAST":return{...s,toasts:[e.toast,...s.toasts].slice(0,Cc)};case"UPDATE_TOAST":return{...s,toasts:s.toasts.map(t=>t.id===e.toast.id?{...t,...e.toast}:t)};case"DISMISS_TOAST":{const{toastId:t}=e;return t?Pn(t):s.toasts.forEach(r=>{Pn(r.id)}),{...s,toasts:s.toasts.map(r=>r.id===t||t===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return e.toastId===void 0?{...s,toasts:[]}:{...s,toasts:s.toasts.filter(t=>t.id!==e.toastId)}}},ks=[];let Rs={toasts:[]};function cs(s){Rs=kc(Rs,s),ks.forEach(e=>{e(Rs)})}function je({...s}){const e=Ic(),t=a=>cs({type:"UPDATE_TOAST",toast:{...a,id:e}}),r=()=>cs({type:"DISMISS_TOAST",toastId:e});return cs({type:"ADD_TOAST",toast:{...s,id:e,open:!0,onOpenChange:a=>{a||r()}}}),{id:e,dismiss:r,update:t}}function ua(){const s=F.c(5),[e,t]=m.useState(Rs);let r;s[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>(ks.push(t),()=>{const o=ks.indexOf(t);o>-1&&ks.splice(o,1)}),s[0]=r):r=s[0];let a;s[1]!==e?(a=[e],s[1]=e,s[2]=a):a=s[2],m.useEffect(r,a);let l;return s[3]!==e?(l={...e,toast:je,dismiss:Rc},s[3]=e,s[4]=l):l=s[4],l}function Rc(s){return cs({type:"DISMISS_TOAST",toastId:s})}const Mn="VS Code";function Ec({projectId:s,threadId:e,openWith:t}){const[r,a]=m.useState(!1),[l,o]=m.useState([]),[i,c]=m.useState(t||Mn),[d,u]=m.useState(!0);m.useEffect(()=>{(async()=>{try{const p=await no();o(p),!i&&p.length>0&&c(p[0])}catch(p){console.error("Failed to fetch available programs:",p),o([Mn])}finally{u(!1)}})()},[]),m.useEffect(()=>{t&&l.includes(t)&&c(t)},[t,l,c]);const f=async g=>{try{a(!0),c(g),await bo(s,g),e?await yo(e,g):await jo(s,g),je({title:"Success",description:`Opened project in ${g}`})}catch(p){console.error(`Failed to open project in ${g}:`,p);let j=`Failed to open project in ${g}`;if(p instanceof Error){const v=p;v.details?j=v.details:j=p.message}je({title:"Error",description:j,variant:"destructive"})}finally{a(!1)}},h=async()=>{await f(i)};return d?n.jsx(J,{variant:"outline",size:"sm",className:"h-8",disabled:!0,children:"Loading..."}):n.jsxs("div",{className:"flex items-center gap-0",children:[n.jsxs(J,{variant:"outline",size:"sm",className:"h-8 rounded-r-none border-r-0",disabled:r,onClick:h,children:["Open in ",i]}),n.jsxs(ca,{children:[n.jsx(da,{asChild:!0,children:n.jsx(J,{variant:"outline",size:"sm",className:"h-8 w-8 rounded-l-none px-1",disabled:r,children:n.jsx(It,{className:"h-3.5 w-3.5"})})}),n.jsx(gn,{align:"end",children:l.map(g=>n.jsx(Ct,{onClick:()=>f(g),disabled:r,children:g},g))})]})]})}const _c=ys("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Pc(s){const e=F.c(10);let t,r,a;e[0]!==s?({className:t,variant:a,...r}=s,e[0]=s,e[1]=t,e[2]=r,e[3]=a):(t=e[1],r=e[2],a=e[3]);let l;e[4]!==t||e[5]!==a?(l=B(_c({variant:a}),t),e[4]=t,e[5]=a,e[6]=l):l=e[6];let o;return e[7]!==r||e[8]!==l?(o=n.jsx("div",{className:l,...r}),e[7]=r,e[8]=l,e[9]=o):o=e[9],o}function Mc(){return{autoGenerateCommitMessage:Zo(),privateRepositoryDefault:ti()}}function Dc(s){s.autoGenerateCommitMessage!==void 0&&ei(s.autoGenerateCommitMessage),s.privateRepositoryDefault!==void 0&&si(s.privateRepositoryDefault)}function Xt(s){return s?!0:(je({title:"Error",description:"No thread selected",variant:"destructive"}),!1)}const Dt=m.forwardRef((s,e)=>{const t=F.c(10);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",r),t[3]=r,t[4]=l):l=t[4];let o;t[5]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(dl,{className:B("flex items-center justify-center text-current"),children:n.jsx(Je,{className:"h-4 w-4"})}),t[5]=o):o=t[5];let i;return t[6]!==a||t[7]!==e||t[8]!==l?(i=n.jsx(gr,{ref:e,className:l,...a,children:o}),t[6]=a,t[7]=e,t[8]=l,t[9]=i):i=t[9],i});Dt.displayName=gr.displayName;const rs=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("textarea",{className:l,ref:e,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});rs.displayName="Textarea";function Ac(s){const e=F.c(57),{open:t,onOpenChange:r,commitMessage:a,onCommitMessageChange:l,autoGenerateCommitMessage:o,onAutoGenerateChange:i,isGeneratingMessage:c,isLoading:d,onGenerateMessage:u,onCommit:f,currentBranch:h}=s;let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx(Ge,{children:"Commit Changes"}),e[0]=g):g=e[0];let p;e[1]!==h?(p=n.jsxs(Ye,{children:[g,n.jsxs(He,{children:["Enter a commit message for your changes on branch ",h]})]}),e[1]=h,e[2]=p):p=e[2];let j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=n.jsx(be,{htmlFor:"commit-message",children:"Commit Message"}),e[3]=j):j=e[3];let v;e[4]!==l?(v=K=>l(K.target.value),e[4]=l,e[5]=v):v=e[5];let b;e[6]!==a||e[7]!==v?(b=n.jsx(rs,{id:"commit-message",placeholder:"Enter commit message...",value:a,onChange:v,rows:4,className:"pr-10"}),e[6]=a,e[7]=v,e[8]=b):b=e[8];const I=c||d;let T;e[9]!==c?(T=c?n.jsx(ve,{className:"h-3.5 w-3.5 animate-spin"}):n.jsx(xr,{className:"h-3.5 w-3.5"}),e[9]=c,e[10]=T):T=e[10];let x;e[11]!==u||e[12]!==I||e[13]!==T?(x=n.jsx(pe,{asChild:!0,children:n.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"absolute top-2 right-2 h-6 w-6",onClick:u,disabled:I,children:T})}),e[11]=u,e[12]=I,e[13]=T,e[14]=x):x=e[14];const C=c?"Generating commit message...":"Generate commit message with AI";let _;e[15]!==C?(_=n.jsx(me,{children:C}),e[15]=C,e[16]=_):_=e[16];let w;e[17]!==_||e[18]!==x?(w=n.jsx(we,{children:n.jsxs(fe,{children:[x,_]})}),e[17]=_,e[18]=x,e[19]=w):w=e[19];let k;e[20]!==w||e[21]!==b?(k=n.jsxs("div",{className:"grid gap-2",children:[j,n.jsxs("div",{className:"relative",children:[b,w]})]}),e[20]=w,e[21]=b,e[22]=k):k=e[22];let N;e[23]!==i?(N=K=>i(K===!0),e[23]=i,e[24]=N):N=e[24];let y;e[25]!==o||e[26]!==N?(y=n.jsx(Dt,{id:"auto-generate",checked:o,onCheckedChange:N}),e[25]=o,e[26]=N,e[27]=y):y=e[27];let S;e[28]===Symbol.for("react.memo_cache_sentinel")?(S=n.jsx(be,{htmlFor:"auto-generate",className:"text-sm font-normal",children:"Auto generate commit messages"}),e[28]=S):S=e[28];let R;e[29]!==y?(R=n.jsxs("div",{className:"flex items-center gap-2",children:[y,S]}),e[29]=y,e[30]=R):R=e[30];let E;e[31]!==k||e[32]!==R?(E=n.jsxs("div",{className:"grid gap-4 py-4",children:[k,R]}),e[31]=k,e[32]=R,e[33]=E):E=e[33];let A;e[34]!==r?(A=()=>r(!1),e[34]=r,e[35]=A):A=e[35];let M;e[36]!==d||e[37]!==A?(M=n.jsx(J,{variant:"outline",onClick:A,disabled:d,children:"Cancel"}),e[36]=d,e[37]=A,e[38]=M):M=e[38];let z;e[39]!==a||e[40]!==d?(z=d||!a.trim(),e[39]=a,e[40]=d,e[41]=z):z=e[41];const O=d?"Committing...":"Commit";let L;e[42]!==f||e[43]!==z||e[44]!==O?(L=n.jsx(J,{onClick:f,disabled:z,children:O}),e[42]=f,e[43]=z,e[44]=O,e[45]=L):L=e[45];let $;e[46]!==M||e[47]!==L?($=n.jsxs(Xe,{children:[M,L]}),e[46]=M,e[47]=L,e[48]=$):$=e[48];let q;e[49]!==E||e[50]!==p||e[51]!==$?(q=n.jsxs(Qe,{children:[p,E,$]}),e[49]=E,e[50]=p,e[51]=$,e[52]=q):q=e[52];let G;return e[53]!==r||e[54]!==t||e[55]!==q?(G=n.jsx(ft,{open:t,onOpenChange:r,children:q}),e[53]=r,e[54]=t,e[55]=q,e[56]=G):G=e[56],G}function Lc(s){const e=F.c(53),{open:t,onOpenChange:r,prTitle:a,onPrTitleChange:l,prDescription:o,onPrDescriptionChange:i,isGeneratingPRInfo:c,isLoading:d,onGeneratePRInfo:u,onCreatePR:f,currentBranch:h}=s;let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx(Ge,{children:"Create Pull Request"}),e[0]=g):g=e[0];let p;e[1]!==h?(p=n.jsxs(Ye,{children:[g,n.jsxs(He,{children:["Create a pull request for branch ",h]})]}),e[1]=h,e[2]=p):p=e[2];let j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=n.jsx(be,{htmlFor:"pr-title",children:"Title (optional)"}),e[3]=j):j=e[3];const v=h||"Enter PR title...";let b;e[4]!==l?(b=G=>l(G.target.value),e[4]=l,e[5]=b):b=e[5];let I;e[6]!==a||e[7]!==v||e[8]!==b?(I=n.jsxs("div",{className:"grid gap-2",children:[j,n.jsx(ze,{id:"pr-title",placeholder:v,value:a,onChange:b})]}),e[6]=a,e[7]=v,e[8]=b,e[9]=I):I=e[9];let T;e[10]===Symbol.for("react.memo_cache_sentinel")?(T=n.jsx(be,{htmlFor:"pr-description",children:"Description (optional)"}),e[10]=T):T=e[10];let x;e[11]!==i?(x=G=>i(G.target.value),e[11]=i,e[12]=x):x=e[12];let C;e[13]!==o||e[14]!==x?(C=n.jsx(rs,{id:"pr-description",placeholder:"Enter PR description...",value:o,onChange:x,rows:4,className:"pr-10"}),e[13]=o,e[14]=x,e[15]=C):C=e[15];const _=c||d;let w;e[16]!==c?(w=c?n.jsx(ve,{className:"h-3.5 w-3.5 animate-spin"}):n.jsx(xr,{className:"h-3.5 w-3.5"}),e[16]=c,e[17]=w):w=e[17];let k;e[18]!==u||e[19]!==_||e[20]!==w?(k=n.jsx(pe,{asChild:!0,children:n.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"absolute top-2 right-2 h-6 w-6",onClick:u,disabled:_,children:w})}),e[18]=u,e[19]=_,e[20]=w,e[21]=k):k=e[21];const N=c?"Generating PR description...":"Generate PR title and description with AI";let y;e[22]!==N?(y=n.jsx(me,{children:N}),e[22]=N,e[23]=y):y=e[23];let S;e[24]!==k||e[25]!==y?(S=n.jsx(we,{children:n.jsxs(fe,{children:[k,y]})}),e[24]=k,e[25]=y,e[26]=S):S=e[26];let R;e[27]!==S||e[28]!==C?(R=n.jsxs("div",{className:"grid gap-2",children:[T,n.jsxs("div",{className:"relative",children:[C,S]})]}),e[27]=S,e[28]=C,e[29]=R):R=e[29];let E;e[30]!==R||e[31]!==I?(E=n.jsxs("div",{className:"grid gap-4 py-4",children:[I,R]}),e[30]=R,e[31]=I,e[32]=E):E=e[32];let A;e[33]!==r?(A=()=>r(!1),e[33]=r,e[34]=A):A=e[34];let M;e[35]!==d||e[36]!==A?(M=n.jsx(J,{variant:"outline",onClick:A,disabled:d,children:"Cancel"}),e[35]=d,e[36]=A,e[37]=M):M=e[37];const z=d?"Creating...":"Create PR";let O;e[38]!==d||e[39]!==f||e[40]!==z?(O=n.jsx(J,{onClick:f,disabled:d,children:z}),e[38]=d,e[39]=f,e[40]=z,e[41]=O):O=e[41];let L;e[42]!==M||e[43]!==O?(L=n.jsxs(Xe,{children:[M,O]}),e[42]=M,e[43]=O,e[44]=L):L=e[44];let $;e[45]!==E||e[46]!==p||e[47]!==L?($=n.jsxs(Qe,{children:[p,E,L]}),e[45]=E,e[46]=p,e[47]=L,e[48]=$):$=e[48];let q;return e[49]!==r||e[50]!==t||e[51]!==$?(q=n.jsx(ft,{open:t,onOpenChange:r,children:$}),e[49]=r,e[50]=t,e[51]=$,e[52]=q):q=e[52],q}function $c(s){const e=F.c(48),{open:t,onOpenChange:r,repoName:a,onRepoNameChange:l,repoDescription:o,onRepoDescriptionChange:i,isPrivateRepo:c,onPrivateRepoChange:d,isLoading:u,onCreateRepo:f}=s;let h;e[0]!==r||e[1]!==i||e[2]!==l?(h=z=>{z||(l(""),i("")),r(z)},e[0]=r,e[1]=i,e[2]=l,e[3]=h):h=e[3];let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsxs(Ye,{children:[n.jsx(Ge,{children:"Create GitHub Repository"}),n.jsx(He,{children:"Create a new GitHub repository and push your local repository"})]}),e[4]=g):g=e[4];let p;e[5]===Symbol.for("react.memo_cache_sentinel")?(p=n.jsx(be,{htmlFor:"repo-name",children:"Repository Name (optional)"}),e[5]=p):p=e[5];let j;e[6]!==l?(j=z=>l(z.target.value),e[6]=l,e[7]=j):j=e[7];let v;e[8]!==a||e[9]!==j?(v=n.jsxs("div",{className:"grid gap-2",children:[p,n.jsx(ze,{id:"repo-name",placeholder:"Leave empty to use current folder name",value:a,onChange:j})]}),e[8]=a,e[9]=j,e[10]=v):v=e[10];let b;e[11]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsx(be,{htmlFor:"repo-description",children:"Description (optional)"}),e[11]=b):b=e[11];let I;e[12]!==i?(I=z=>i(z.target.value),e[12]=i,e[13]=I):I=e[13];let T;e[14]!==o||e[15]!==I?(T=n.jsxs("div",{className:"grid gap-2",children:[b,n.jsx(rs,{id:"repo-description",placeholder:"Enter repository description...",value:o,onChange:I,rows:3})]}),e[14]=o,e[15]=I,e[16]=T):T=e[16];let x;e[17]!==d?(x=z=>d(z===!0),e[17]=d,e[18]=x):x=e[18];let C;e[19]!==c||e[20]!==x?(C=n.jsx(Dt,{id:"repo-private",checked:c,onCheckedChange:x}),e[19]=c,e[20]=x,e[21]=C):C=e[21];let _;e[22]===Symbol.for("react.memo_cache_sentinel")?(_=n.jsx(be,{htmlFor:"repo-private",className:"text-sm font-normal",children:"Private repository"}),e[22]=_):_=e[22];let w;e[23]!==C?(w=n.jsxs("div",{className:"flex items-center gap-2",children:[C,_]}),e[23]=C,e[24]=w):w=e[24];let k;e[25]!==w||e[26]!==v||e[27]!==T?(k=n.jsxs("div",{className:"grid gap-4 py-4",children:[v,T,w]}),e[25]=w,e[26]=v,e[27]=T,e[28]=k):k=e[28];let N;e[29]!==r?(N=()=>r(!1),e[29]=r,e[30]=N):N=e[30];let y;e[31]!==u||e[32]!==N?(y=n.jsx(J,{variant:"outline",onClick:N,disabled:u,children:"Cancel"}),e[31]=u,e[32]=N,e[33]=y):y=e[33];const S=u?"Creating...":"Create & Push";let R;e[34]!==u||e[35]!==f||e[36]!==S?(R=n.jsx(J,{onClick:f,disabled:u,children:S}),e[34]=u,e[35]=f,e[36]=S,e[37]=R):R=e[37];let E;e[38]!==y||e[39]!==R?(E=n.jsxs(Xe,{children:[y,R]}),e[38]=y,e[39]=R,e[40]=E):E=e[40];let A;e[41]!==k||e[42]!==E?(A=n.jsxs(Qe,{children:[g,k,E]}),e[41]=k,e[42]=E,e[43]=A):A=e[43];let M;return e[44]!==t||e[45]!==h||e[46]!==A?(M=n.jsx(ft,{open:t,onOpenChange:h,children:A}),e[44]=t,e[45]=h,e[46]=A,e[47]=M):M=e[47],M}function Oc(s){const e=F.c(28),{open:t,onOpenChange:r,commits:a,displayedCommits:l,isLoadingMore:o,onScroll:i,currentBranch:c}=s;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(Ge,{children:"Commit History"}),e[0]=d):d=e[0];let u;e[1]!==c?(u=n.jsxs(Ye,{children:[d,n.jsxs(He,{children:["Recent commits on branch ",c]})]}),e[1]=c,e[2]=u):u=e[2];let f;e[3]!==l?(f=l.length>0?l.map(Fc):n.jsx("p",{className:"text-sm text-slate-500 text-center py-8",children:"No commits found"}),e[3]=l,e[4]=f):f=e[4];let h;e[5]!==o?(h=o&&n.jsx("div",{className:"p-3 text-center",children:n.jsx(ve,{className:"h-4 w-4 animate-spin inline"})}),e[5]=o,e[6]=h):h=e[6];let g;e[7]!==a.length||e[8]!==l.length||e[9]!==o?(g=l.length<a.length&&!o&&n.jsx("div",{className:"p-3 text-center text-xs text-slate-500",children:"Scroll to load more"}),e[7]=a.length,e[8]=l.length,e[9]=o,e[10]=g):g=e[10];let p;e[11]!==f||e[12]!==h||e[13]!==g?(p=n.jsxs("div",{className:"divide-y",children:[f,h,g]}),e[11]=f,e[12]=h,e[13]=g,e[14]=p):p=e[14];let j;e[15]!==i||e[16]!==p?(j=n.jsx("div",{className:"flex-1 overflow-y-auto border rounded-lg",onScroll:i,children:p}),e[15]=i,e[16]=p,e[17]=j):j=e[17];let v;e[18]!==r?(v=n.jsx(Xe,{children:n.jsx(J,{onClick:()=>r(!1),children:"Close"})}),e[18]=r,e[19]=v):v=e[19];let b;e[20]!==u||e[21]!==j||e[22]!==v?(b=n.jsxs(Qe,{className:"max-w-2xl max-h-[80vh] flex flex-col",children:[u,j,v]}),e[20]=u,e[21]=j,e[22]=v,e[23]=b):b=e[23];let I;return e[24]!==r||e[25]!==t||e[26]!==b?(I=n.jsx(ft,{open:t,onOpenChange:r,children:b}),e[24]=r,e[25]=t,e[26]=b,e[27]=I):I=e[27],I}function Fc(s){return n.jsxs("div",{className:"p-3 hover:bg-slate-50 dark:hover:bg-slate-900 transition-colors",children:[n.jsx("p",{className:"text-sm font-medium break-words",children:s.message}),n.jsxs("p",{className:"text-xs text-slate-600 dark:text-slate-400 mt-1",children:[n.jsx("span",{className:"font-mono",children:s.hash.substring(0,7)})," • ",s.author," • ",new Date(s.date).toLocaleDateString()]})]},s.hash)}function Gc(s){const e=F.c(15),{open:t,onOpenChange:r,isLoading:a,onPushAndCreatePR:l,onCancel:o}=s;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsxs(Ye,{children:[n.jsx(Ge,{children:"Push Branch First"}),n.jsx(He,{children:"Your branch needs to be pushed to the remote before creating a pull request. Would you like to push it now?"})]}),e[0]=i):i=e[0];let c;e[1]!==a||e[2]!==o?(c=n.jsx(J,{variant:"outline",onClick:o,disabled:a,children:"Cancel"}),e[1]=a,e[2]=o,e[3]=c):c=e[3];const d=a?"Pushing...":"Push & Create PR";let u;e[4]!==a||e[5]!==l||e[6]!==d?(u=n.jsx(J,{onClick:l,disabled:a,children:d}),e[4]=a,e[5]=l,e[6]=d,e[7]=u):u=e[7];let f;e[8]!==c||e[9]!==u?(f=n.jsxs(Qe,{children:[i,n.jsxs(Xe,{children:[c,u]})]}),e[8]=c,e[9]=u,e[10]=f):f=e[10];let h;return e[11]!==r||e[12]!==t||e[13]!==f?(h=n.jsx(ft,{open:t,onOpenChange:r,children:f}),e[11]=r,e[12]=t,e[13]=f,e[14]=h):h=e[14],h}function Hc(s){const e=F.c(11),[t,r]=m.useState(!1),[a,l]=m.useState(0),[o,i]=m.useState(!1),[c,d]=m.useState("");let u;e[0]!==s?(u=async()=>{if(s)try{const j=await wo(s);r(j.hasChanges),l(j.changedFilesCount),i(j.hasUnpushedCommits),d(j.currentBranch)}catch(j){console.error("Failed to fetch git status:",j)}},e[0]=s,e[1]=u):u=e[1];const f=u;let h,g;e[2]!==f?(h=()=>{(async()=>await f())()},g=[f],e[2]=f,e[3]=h,e[4]=g):(h=e[3],g=e[4]),m.useEffect(h,g);let p;return e[5]!==a||e[6]!==c||e[7]!==f||e[8]!==t||e[9]!==o?(p={hasChanges:t,changedFilesCount:a,hasUnpushedCommits:o,currentBranch:c,fetchGitStatus:f},e[5]=a,e[6]=c,e[7]=f,e[8]=t,e[9]=o,e[10]=p):p=e[10],p}function Uc(s){const[e,t]=m.useState(!1),[r,a]=m.useState(null),l=m.useCallback(async()=>{if(s)try{const o=await Ro(s);t(o.canCreateRepo),a(o.repoUrl||null)}catch(o){console.error("Failed to fetch GitHub status:",o)}},[s]);return m.useEffect(()=>{(async()=>await l())()},[l]),{canCreateRepo:e,gitHubUrl:r,fetchGitHubStatus:l}}function zc(s){const e=s.split("/");return e.length>=2?{provider:e[0],model:e.slice(1).join("/")}:{provider:void 0,model:s}}function Bc(s,e,t){const[r,a]=m.useState(!1),[l,o]=m.useState(!1),i=()=>{const u=t[e];return u?zc(u):{provider:void 0,model:void 0}};return{isGeneratingMessage:r,isGeneratingPRInfo:l,generateCommitMessageWithAI:async()=>{if(!s)return null;try{a(!0);const{provider:u,model:f}=i();return await So(s,f,u)}catch(u){console.error("Failed to generate commit message:",u);const f=u instanceof Error?u.message:"Failed to generate commit message";return je({title:"Error",description:f,variant:"destructive"}),null}finally{a(!1)}},generatePRInfoWithAI:async()=>{if(!s)return null;try{o(!0);const{provider:u,model:f}=i(),h=await To(s,f,u);return je({title:"Success",description:"PR title and description generated"}),h}catch(u){console.error("Failed to generate PR info:",u);const f=u instanceof Error?u.message:"Failed to generate PR info";return je({title:"Error",description:f,variant:"destructive"}),null}finally{o(!1)}}}}function qc({projectId:s,threadId:e}){const{state:t,dispatch:r}=Ce(),[a,l]=m.useState(!1),[o,i]=m.useState(!1),[c,d]=m.useState(!1),[u,f]=m.useState(""),[h,g]=m.useState(""),[p,j]=m.useState(""),[v,b]=m.useState(!1),[I,T]=m.useState(null),[x,C]=m.useState(!1),[_,w]=m.useState([]),[k,N]=m.useState(!1),[y,S]=m.useState([]),[R,E]=m.useState(!1),A=10,[M,z]=m.useState(!1),[O,L]=m.useState(""),[$,q]=m.useState(""),G=Hc(e),K=Uc(e),X=Bc(e,s,t.projectModelSelections),[de,ie]=m.useState(()=>Mc()),re=t.projects.find(W=>W.projectId===s),ae=re?.commitMethod===he.Direct;m.useEffect(()=>{M&&re?.name&&!O&&L(re.name)},[M,re?.name,O]),m.useEffect(()=>{Dc(de)},[de]),m.useEffect(()=>{o&&de.autoGenerateCommitMessage&&!u.trim()&&e&&(async()=>{const oe=await X.generateCommitMessageWithAI();oe&&f(oe)})()},[o,de.autoGenerateCommitMessage,u,e,X]),m.useEffect(()=>{!t.isStreaming&&t.completedThreadIds.includes(t.selectedThreadId||"")&&(G.fetchGitStatus(),K.fetchGitHubStatus(),r({type:P.ClearThreadCompleted,threadId:t.selectedThreadId||""}))},[t.isStreaming,t.completedThreadIds,t.selectedThreadId,G,K,r]);const le=async()=>{if(u.trim()&&Xt(e))try{l(!0),await Co(e,u),f(""),i(!1),await G.fetchGitStatus()}catch(W){console.error("Failed to commit:",W)}finally{l(!1)}},ce=async()=>{const W=await X.generateCommitMessageWithAI();W&&f(W)},te=async()=>{if(Xt(e))try{l(!0),await Io(e),await G.fetchGitStatus()}catch(W){console.error("Failed to fetch:",W)}finally{l(!1)}},se=async()=>{if(Xt(e))try{l(!0),await Tn(e),await G.fetchGitStatus()}catch(W){console.error("Failed to push:",W)}finally{l(!1)}},D=async()=>{if(Xt(e))try{l(!0);const W=await In(e,h,p);W.prUrl&&window.open(W.prUrl,"_blank"),g(""),j(""),d(!1),await G.fetchGitStatus()}catch(W){console.error("Failed to create PR:",W);const oe=W instanceof Error?W.message:"Failed to create PR";(oe.includes("push the current branch")||oe.includes("--head flag"))&&(T({title:h,description:p}),d(!1),b(!0))}finally{l(!1)}},U=async()=>{if(Xt(e))try{l(!0);const W=await Eo(e,O,$,de.privateRepositoryDefault);W.repoUrl&&setTimeout(()=>{window.open(W.repoUrl,"_blank")},3e3),L(""),q(""),z(!1),await K.fetchGitHubStatus(),await G.fetchGitStatus()}catch(W){console.error("Failed to create repo:",W)}finally{l(!1)}},H=async()=>{const W=await X.generatePRInfoWithAI();W&&(g(W.title),j(W.description))},V=async()=>{if(!(!e||!I))try{l(!0),await Tn(e);const W=await In(e,I.title,I.description);W.prUrl&&window.open(W.prUrl,"_blank"),g(""),j(""),T(null),b(!1),await G.fetchGitStatus()}catch(W){console.error("Failed to push and create PR:",W)}finally{l(!1)}},Z=async()=>{if(Xt(e))try{N(!0);const W=await ko(e,100);w(W),S(W.slice(0,A)),C(!0)}catch(W){console.error("Failed to fetch git history:",W)}finally{N(!1)}},ee=()=>{R||(E(!0),setTimeout(()=>{const W=y.length+A,oe=_.slice(0,W);S(oe),E(!1)},300))},Y=W=>{const oe=W.currentTarget;oe.scrollHeight-oe.scrollTop-oe.clientHeight<100&&y.length<_.length&&!R&&ee()};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-0",children:[n.jsx(we,{children:n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsxs(J,{variant:"outline",size:"sm",className:"h-8 rounded-r-none border-r-0 gap-1.5",disabled:!G.hasChanges||a,onClick:()=>i(!0),children:[n.jsx(ul,{className:"h-3.5 w-3.5"}),"Commit",G.hasChanges&&G.changedFilesCount>0&&n.jsx(Pc,{variant:"secondary",className:"h-4 px-1 text-[10px] font-medium",children:G.changedFilesCount})]})}),n.jsx(me,{children:G.hasChanges?`Commit ${G.changedFilesCount} changed file${G.changedFilesCount!==1?"s":""}`:"No changes to commit"})]})}),n.jsxs(ca,{children:[n.jsx(da,{asChild:!0,children:n.jsx(J,{variant:"outline",size:"sm",className:"h-8 w-8 rounded-l-none px-1",disabled:a,children:n.jsx(It,{className:"h-3.5 w-3.5"})})}),n.jsxs(gn,{align:"end",children:[n.jsxs(Ct,{onClick:te,disabled:a,children:[n.jsx(ml,{className:"h-3.5 w-3.5 mr-2"}),"Fetch"]}),n.jsxs(Ct,{onClick:se,disabled:!G.hasUnpushedCommits||a,children:[n.jsx(fl,{className:"h-3.5 w-3.5 mr-2"}),"Push Commits"]}),n.jsxs(Ct,{onClick:Z,disabled:a||k,children:[n.jsx(pl,{className:"h-3.5 w-3.5 mr-2"}),"History"]}),!ae&&n.jsxs(Ct,{onClick:()=>d(!0),disabled:a,children:[n.jsx(hl,{className:"h-3.5 w-3.5 mr-2"}),"Create Pull Request"]}),K.canCreateRepo&&n.jsxs(Ct,{onClick:()=>z(!0),disabled:a,children:[n.jsx(gl,{className:"h-3.5 w-3.5 mr-2"}),"Create Repo"]}),K.gitHubUrl&&n.jsxs(Ct,{onClick:()=>K.gitHubUrl&&window.open(K.gitHubUrl,"_blank"),disabled:a,children:[n.jsx(js,{className:"h-3.5 w-3.5 mr-2"}),"View in GitHub"]})]})]})]}),n.jsx(Ac,{open:o,onOpenChange:i,commitMessage:u,onCommitMessageChange:f,autoGenerateCommitMessage:de.autoGenerateCommitMessage,onAutoGenerateChange:W=>ie(oe=>({...oe,autoGenerateCommitMessage:W})),isGeneratingMessage:X.isGeneratingMessage,isLoading:a,onGenerateMessage:ce,onCommit:le,currentBranch:G.currentBranch}),n.jsx(Lc,{open:c,onOpenChange:d,prTitle:h,onPrTitleChange:g,prDescription:p,onPrDescriptionChange:j,isGeneratingPRInfo:X.isGeneratingPRInfo,isLoading:a,onGeneratePRInfo:H,onCreatePR:D,currentBranch:G.currentBranch}),n.jsx(Gc,{open:v,onOpenChange:b,isLoading:a,onPushAndCreatePR:V,onCancel:()=>{b(!1),T(null)}}),n.jsx($c,{open:M,onOpenChange:z,repoName:O,onRepoNameChange:L,repoDescription:$,onRepoDescriptionChange:q,isPrivateRepo:de.privateRepositoryDefault,onPrivateRepoChange:W=>ie(oe=>({...oe,privateRepositoryDefault:W})),isLoading:a,onCreateRepo:U}),n.jsx(Oc,{open:x,onOpenChange:C,commits:_,displayedCommits:y,isLoadingMore:R,onScroll:Y,currentBranch:G.currentBranch})]})}const Wc=["Play","Square","RotateCcw","Terminal","Bug","TestTube","FlaskConical","Wrench","Hammer","Zap","Search","FileCode","Code2","History","Settings","Activity","Cpu","Server","Database","Package","Box","GitBranch","Layers","ExternalLink","Eye","Shield","Flag","Star","Monitor","Smartphone"];function Vc({open:s,onOpenChange:e,projectId:t,commands:r,onRefresh:a}){const[l,o]=m.useState(null),[i,c]=m.useState(!1),d=()=>{o({id:crypto.randomUUID(),name:"",icon:"Play",commandLine:""})},u=g=>{o({...g})},f=async g=>{try{await Po(t,g),je({title:"Success",description:"Command deleted"}),a()}catch{je({title:"Error",description:"Failed to delete command",variant:"destructive"})}},h=async()=>{if(!l?.name||!l?.commandLine){je({title:"Error",description:"Name and Command Line are required",variant:"destructive"});return}try{c(!0),await _o(t,l),je({title:"Success",description:"Command saved"}),o(null),a()}catch{je({title:"Error",description:"Failed to save command",variant:"destructive"})}finally{c(!1)}};return n.jsx(ft,{open:s,onOpenChange:e,children:n.jsxs(Qe,{className:"sm:max-w-[500px]",children:[n.jsxs(Ye,{children:[n.jsx(Ge,{children:"Project Commands"}),n.jsx(He,{children:"Manage custom commands for this project. These commands will be available in the toolbar for all threads."})]}),n.jsx("div",{className:"py-4 flex flex-col gap-4",children:l?n.jsxs("div",{className:"p-4 border rounded-lg bg-muted/30 flex flex-col gap-4 animate-in slide-in-from-top-2",children:[n.jsxs("div",{className:"grid gap-2",children:[n.jsx(be,{htmlFor:"name",children:"Command Name"}),n.jsx(ze,{id:"name",value:l.name,onChange:g=>o({...l,name:g.target.value}),placeholder:"e.g. Run Tests",autoComplete:"off"})]}),n.jsxs("div",{className:"grid gap-2",children:[n.jsx(be,{htmlFor:"commandLine",children:"Command Line"}),n.jsx(rs,{id:"commandLine",value:l.commandLine,onChange:g=>o({...l,commandLine:g.target.value}),placeholder:"e.g. npm test",className:"font-mono text-xs min-h-[100px] resize-none"})]}),n.jsxs("div",{className:"grid gap-2",children:[n.jsx(be,{children:"Icon"}),n.jsx("div",{className:"grid grid-cols-10 gap-1 p-2 bg-background rounded-md border border-border",children:Wc.map(g=>{const p=Ys[g]||Qn,j=l.icon===g;return n.jsx(J,{variant:j?"default":"ghost",size:"icon",className:"h-8 w-8",onClick:()=>o({...l,icon:g}),title:g,children:n.jsx(p,{className:"h-4 w-4"})},g)})})]}),n.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[n.jsxs(J,{variant:"ghost",size:"sm",onClick:()=>o(null),children:[n.jsx(mt,{className:"h-4 w-4 mr-2"})," Cancel"]}),n.jsxs(J,{size:"sm",onClick:h,disabled:i,children:[n.jsx(Je,{className:"h-4 w-4 mr-2"})," ",i?"Saving...":"Save Command"]})]})]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex flex-col gap-2 max-h-[400px] overflow-y-auto pr-2",children:[r.length===0&&n.jsx("div",{className:"text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg",children:"No commands defined yet."}),r.map(g=>n.jsxs("div",{className:"flex items-center justify-between p-3 rounded-md border border-border bg-card hover:bg-muted/50 cursor-pointer group transition-colors",onClick:()=>u(g),children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("div",{className:"p-2 bg-muted rounded",children:(()=>{const p=Ys[g.icon]||cn;return n.jsx(p,{className:"h-4 w-4"})})()}),n.jsxs("div",{className:"flex flex-col",children:[n.jsx("span",{className:"text-sm font-medium",children:g.name}),n.jsx("span",{className:"text-xs text-muted-foreground line-clamp-1 font-mono",children:g.commandLine})]})]}),n.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:n.jsx(J,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10",onClick:p=>{p.stopPropagation(),f(g.id)},children:n.jsx(Qs,{className:"h-4 w-4"})})})]},g.id))]}),n.jsxs(J,{variant:"outline",className:"w-full border-dashed",onClick:d,children:[n.jsx(gs,{className:"h-4 w-4 mr-2"})," Add New Command"]})]})}),n.jsx(Xe,{children:n.jsx(J,{variant:"ghost",onClick:()=>e(!1),children:"Close"})})]})})}function Kc(){const s=F.c(27),{state:e}=Ce(),{selectedProjectId:t,selectedThreadId:r,projects:a}=e,{dispatch:l}=bs(r),[o,i]=m.useState(!1);let c,d,u,f,h;if(s[0]!==l||s[1]!==a||s[2]!==t||s[3]!==r||s[4]!==e.isRunningCommand){h=Symbol.for("react.early_return_sentinel");e:{let j;s[10]!==t?(j=x=>x.projectId===t,s[10]=t,s[11]=j):j=s[11],c=a.find(j)?.commands||[];let b;s[12]!==l||s[13]!==t||s[14]!==r?(b=x=>{!t||!r||l({type:P.QueueTerminalCommand,command:x})},s[12]=l,s[13]=t,s[14]=r,s[15]=b):b=s[15];const I=b;let T;if(s[16]!==l?(T=async()=>{l({type:P.ConfigUpdated})},s[16]=l,s[17]=T):T=s[17],d=T,!t){h=null;break e}u="flex items-center gap-1 mr-2",f=c.length===0?n.jsx(we,{children:n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsxs(J,{variant:"ghost",size:"sm",className:"h-8 gap-1.5 text-muted-foreground hover:text-foreground",onClick:()=>i(!0),children:[n.jsx(Js,{className:"h-4 w-4"}),n.jsx("span",{className:"text-xs font-medium",children:"Commands"})]})}),n.jsx(me,{children:"Manage project commands"})]})}):n.jsx(n.Fragment,{children:n.jsxs(we,{children:[c.map(x=>{const C=Ys[x.icon]||cn;return n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsx(J,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground",onClick:()=>I(x.commandLine),disabled:e.isRunningCommand,children:n.jsx(C,{className:"h-4 w-4"})})}),n.jsx(me,{children:n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsx("span",{className:"font-medium",children:x.name}),n.jsx("span",{className:"text-[10px] opacity-70 font-mono whitespace-pre-wrap max-w-[300px] max-h-[100px] overflow-y-auto",children:x.commandLine})]})})]},x.id)}),n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsx(J,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground ml-1",onClick:()=>i(!0),children:n.jsx(Js,{className:"h-4 w-4"})})}),n.jsx(me,{children:"Manage commands"})]})]})})}s[0]=l,s[1]=a,s[2]=t,s[3]=r,s[4]=e.isRunningCommand,s[5]=c,s[6]=d,s[7]=u,s[8]=f,s[9]=h}else c=s[5],d=s[6],u=s[7],f=s[8],h=s[9];if(h!==Symbol.for("react.early_return_sentinel"))return h;let g;s[18]!==c||s[19]!==d||s[20]!==t||s[21]!==o?(g=n.jsx(Vc,{open:o,onOpenChange:i,projectId:t,commands:c,onRefresh:d}),s[18]=c,s[19]=d,s[20]=t,s[21]=o,s[22]=g):g=s[22];let p;return s[23]!==u||s[24]!==f||s[25]!==g?(p=n.jsxs("div",{className:u,children:[f,g]}),s[23]=u,s[24]=f,s[25]=g,s[26]=p):p=s[26],p}function Jc({projectId:s,runCommand:e}){const{state:t}=Ce(),{selectedThreadId:r}=t,{dispatch:a}=bs(r),[l,o]=m.useState(!1),[i,c]=m.useState(!1);m.useEffect(()=>{(async()=>{try{const g=await Oo(s);o(g.isRunning)}catch{o(!1)}})()},[s]);const d=async()=>{if(!e)return;c(!0),a({type:P.ClearTerminalOutput}),a({type:P.SetTerminalOpen,open:!1}),a({type:P.AppendTerminalLine,line:{type:"system",content:`Starting dev server: ${e}`}});let h=!1;const g=setTimeout(()=>{h=!0,a({type:P.SetTerminalOpen,open:!0})},3e3);try{const p=await Lo(s);if(!p){clearTimeout(g),je({title:"Error",description:"Failed to start dev server",variant:"destructive"}),a({type:P.AppendTerminalLine,line:{type:"error",content:"Failed to start dev server"}}),c(!1);return}const j=p.getReader(),v=new TextDecoder;o(!0);let b=!1,I=!1,T=null;for(T=setTimeout(()=>{I||c(!1)},3e3);;){const{done:x,value:C}=await j.read();if(x)break;const _=v.decode(C,{stream:!0});try{const w=_.split(`
13
+ `).filter(k=>k.trim());for(const k of w)try{const N=JSON.parse(k);I||(I=!0,c(!1),T&&clearTimeout(T)),(N.type==="stdout"||N.type==="stderr")&&a({type:P.AppendTerminalLine,line:{type:"output",content:N.content}}),N.type==="url"&&N.url&&(clearTimeout(g),a({type:P.AppendTerminalLine,line:{type:"system",content:`✓ Server running at: ${N.url}`}}),window.open(N.url,"_blank"),h&&setTimeout(()=>{a({type:P.SetTerminalOpen,open:!1})},100),je({title:"Dev server started",description:`Server running at ${N.url}`}),b=!0),N.type==="error"&&N.content&&a({type:P.AppendTerminalLine,line:{type:"error",content:N.content}})}catch{_.trim()&&a({type:P.AppendTerminalLine,line:{type:"output",content:_}})}}catch{_.trim()&&a({type:P.AppendTerminalLine,line:{type:"output",content:_}})}}clearTimeout(g),T&&clearTimeout(T),c(!1),b||(a({type:P.AppendTerminalLine,line:{type:"system",content:"Server is running but URL could not be detected"}}),je({title:"Dev server started",description:"Server is running but URL could not be detected"}))}catch(p){clearTimeout(g),o(!1),c(!1);const j=p instanceof Error?p.message:"Failed to start dev server";a({type:P.AppendTerminalLine,line:{type:"error",content:j}}),je({title:"Error",description:j,variant:"destructive"})}},u=async()=>{c(!0);try{await $o(s),o(!1),a({type:P.AppendTerminalLine,line:{type:"system",content:"Server stopped"}})}catch(h){const g=h instanceof Error?h.message:"Failed to stop dev server";a({type:P.AppendTerminalLine,line:{type:"error",content:g}}),je({title:"Error",description:g,variant:"destructive"})}finally{c(!1)}},f=!!e;return n.jsx(n.Fragment,{children:n.jsx(we,{children:n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsxs(J,{variant:"ghost",size:"icon",className:`h-8 w-8 ${l?"text-orange-500 hover:text-orange-600 bg-orange-500/10":"text-muted-foreground hover:text-foreground"}`,onClick:l?u:d,disabled:i||!l&&!f,children:[i?n.jsx(ve,{className:"h-4 w-4 animate-spin"}):l?n.jsx(qn,{className:"h-4 w-4 fill-current"}):n.jsx(cn,{className:"h-4 w-4"}),n.jsx("span",{className:"sr-only",children:l?"Stop dev server":"Start dev server"})]})}),n.jsx(me,{children:l?"Stop dev server":f?`Start dev server: ${e}`:"Set run command in project settings"})]})})})}function Qc(){const s=F.c(10),{state:e}=Ce(),{selectedThreadId:t}=e,{terminalState:r,dispatch:a}=bs(t),{open:l}=r,o=`h-8 w-8 ${l?"text-primary bg-primary/10":"text-muted-foreground"}`;let i;s[0]!==a?(i=()=>a({type:P.ToggleTerminal}),s[0]=a,s[1]=i):i=s[1];let c,d;s[2]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(ds,{className:"h-4 w-4"}),d=n.jsx("span",{className:"sr-only",children:"Toggle terminal"}),s[2]=c,s[3]=d):(c=s[2],d=s[3]);let u;s[4]!==o||s[5]!==i?(u=n.jsx(pe,{asChild:!0,children:n.jsxs(J,{variant:"ghost",size:"icon",className:o,onClick:i,children:[c,d]})}),s[4]=o,s[5]=i,s[6]=u):u=s[6];let f;s[7]===Symbol.for("react.memo_cache_sentinel")?(f=n.jsx(me,{children:"Show Terminal"}),s[7]=f):f=s[7];let h;return s[8]!==u?(h=n.jsx(we,{children:n.jsxs(fe,{children:[u,f]})}),s[8]=u,s[9]=h):h=s[9],h}function Yc(){const s=F.c(10),{state:e,dispatch:t}=Ce(),r=`h-8 w-8 ${e.reviewMode?"text-primary bg-primary/10":"text-muted-foreground"}`;let a;s[0]!==t?(a=()=>t({type:P.ToggleReviewMode}),s[0]=t,s[1]=a):a=s[1];let l,o;s[2]===Symbol.for("react.memo_cache_sentinel")?(l=n.jsx(xl,{className:"h-4 w-4"}),o=n.jsx("span",{className:"sr-only",children:"Review changes"}),s[2]=l,s[3]=o):(l=s[2],o=s[3]);let i;s[4]!==r||s[5]!==a?(i=n.jsx(pe,{asChild:!0,children:n.jsxs(J,{variant:"ghost",size:"icon",className:r,onClick:a,children:[l,o]})}),s[4]=r,s[5]=a,s[6]=i):i=s[6];let c;s[7]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(me,{children:"Review Changes"}),s[7]=c):c=s[7];let d;return s[8]!==i?(d=n.jsx(we,{children:n.jsxs(fe,{children:[i,c]})}),s[8]=i,s[9]=d):d=s[9],d}function Xc(){const s=F.c(28),{state:e,dispatch:t}=Ce(),{selectedThreadId:r,selectedProjectId:a,projects:l,sidebarOpen:o}=e;let i;if(s[0]!==l||s[1]!==a){let b;s[3]!==a?(b=I=>I.projectId===a,s[3]=a,s[4]=b):b=s[4],i=l.find(b),s[0]=l,s[1]=a,s[2]=i}else i=s[2];const c=i;let d;s[5]!==t?(d=()=>t({type:P.ToggleSidebar}),s[5]=t,s[6]=d):d=s[6];let u;s[7]!==o?(u=o?n.jsx(Hn,{className:"h-4 w-4"}):n.jsx(jl,{className:"h-4 w-4"}),s[7]=o,s[8]=u):u=s[8];let f;s[9]===Symbol.for("react.memo_cache_sentinel")?(f=n.jsx("span",{className:"sr-only",children:"Toggle sidebar"}),s[9]=f):f=s[9];let h;s[10]!==d||s[11]!==u?(h=n.jsxs(J,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground",onClick:d,children:[u,f]}),s[10]=d,s[11]=u,s[12]=h):h=s[12];let g;s[13]!==l||s[14]!==a||s[15]!==r?(g=r&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-sm font-medium text-foreground",children:Ul(l,r)}),n.jsx("span",{className:"text-xs text-muted-foreground",children:zl(l,a)})]}),s[13]=l,s[14]=a,s[15]=r,s[16]=g):g=s[16];let p;s[17]!==c?.openWith||s[18]!==c?.runCommand||s[19]!==a||s[20]!==r?(p=a&&n.jsxs(n.Fragment,{children:[r&&n.jsxs(n.Fragment,{children:[n.jsx(Yc,{}),n.jsx(Qc,{})]}),n.jsx(Jc,{projectId:a,runCommand:c?.runCommand}),r&&n.jsxs(n.Fragment,{children:[n.jsx(Kc,{}),n.jsx(qc,{projectId:a,threadId:r}),n.jsx(Ec,{projectId:a,threadId:r,openWith:c?.openWith})]})]}),s[17]=c?.openWith,s[18]=c?.runCommand,s[19]=a,s[20]=r,s[21]=p):p=s[21];let j;s[22]!==p?(j=n.jsx("div",{className:"ml-auto flex items-center gap-2",children:p}),s[22]=p,s[23]=j):j=s[23];let v;return s[24]!==h||s[25]!==g||s[26]!==j?(v=n.jsxs("header",{className:"flex h-12 shrink-0 items-center gap-2 border-b border-border px-4",children:[h,g,j]}),s[24]=h,s[25]=g,s[26]=j,s[27]=v):v=s[27],v}const xn=bl,Zc=yl,ma=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(jr,{className:l,...a,ref:e}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});ma.displayName=jr.displayName;const As=m.forwardRef((s,e)=>{const t=F.c(10);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]===Symbol.for("react.memo_cache_sentinel")?(l=n.jsx(ma,{}),t[3]=l):l=t[3];let o;t[4]!==r?(o=B("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",r),t[4]=r,t[5]=o):o=t[5];let i;return t[6]!==a||t[7]!==e||t[8]!==o?(i=n.jsxs(Zc,{children:[l,n.jsx(yr,{ref:e,className:o,...a})]}),t[6]=a,t[7]=e,t[8]=o,t[9]=i):i=t[9],i});As.displayName=yr.displayName;const Ls=s=>{const e=F.c(8);let t,r;e[0]!==s?({className:t,...r}=s,e[0]=s,e[1]=t,e[2]=r):(t=e[1],r=e[2]);let a;e[3]!==t?(a=B("flex flex-col space-y-2 text-center sm:text-left",t),e[3]=t,e[4]=a):a=e[4];let l;return e[5]!==r||e[6]!==a?(l=n.jsx("div",{className:a,...r}),e[5]=r,e[6]=a,e[7]=l):l=e[7],l};Ls.displayName="AlertDialogHeader";const $s=s=>{const e=F.c(8);let t,r;e[0]!==s?({className:t,...r}=s,e[0]=s,e[1]=t,e[2]=r):(t=e[1],r=e[2]);let a;e[3]!==t?(a=B("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),e[3]=t,e[4]=a):a=e[4];let l;return e[5]!==r||e[6]!==a?(l=n.jsx("div",{className:a,...r}),e[5]=r,e[6]=a,e[7]=l):l=e[7],l};$s.displayName="AlertDialogFooter";const Os=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("text-lg font-semibold",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(br,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Os.displayName=br.displayName;const Fs=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("text-sm text-muted-foreground",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(vr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Fs.displayName=vr.displayName;const jn=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B(dn(),r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(Nr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});jn.displayName=Nr.displayName;const yn=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B(dn({variant:"outline"}),"mt-2 sm:mt-0",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(wr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});yn.displayName=wr.displayName;function ed(s){const e=F.c(13),{open:t,projectName:r,onOpenChange:a,onConfirm:l}=s;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(Os,{children:"Delete Project"}),e[0]=o):o=e[0];let i;e[1]!==r?(i=n.jsxs(Ls,{children:[o,n.jsxs(Fs,{children:["Are you sure you want to delete ",n.jsxs("span",{className:"font-semibold text-foreground",children:['"',r,'"']}),"? This will remove the project and all its data. This action cannot be undone."]})]}),e[1]=r,e[2]=i):i=e[2];let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(yn,{children:"Cancel"}),e[3]=c):c=e[3];let d;e[4]!==l?(d=n.jsxs($s,{children:[c,n.jsx(jn,{onClick:l,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]}),e[4]=l,e[5]=d):d=e[5];let u;e[6]!==i||e[7]!==d?(u=n.jsxs(As,{children:[i,d]}),e[6]=i,e[7]=d,e[8]=u):u=e[8];let f;return e[9]!==a||e[10]!==t||e[11]!==u?(f=n.jsx(xn,{open:t,onOpenChange:a,children:u}),e[9]=a,e[10]=t,e[11]=u,e[12]=f):f=e[12],f}function td({open:s,onOpenChange:e,projectId:t,onRefresh:r}){const[a,l]=m.useState(""),[o,i]=m.useState(""),[c,d]=m.useState(""),[u,f]=m.useState(he.PullRequest),[h,g]=m.useState(!1),[p,j]=m.useState(!1),[v,b]=m.useState(!1),[I,T]=m.useState(""),[x,C]=m.useState(""),[_,w]=m.useState(""),[k,N]=m.useState(he.PullRequest),y=m.useCallback(async()=>{b(!0);try{const E=await lo(t),A=E.name||"",M=E.setupScript||"",z=E.runCommand||"",O=E.commitMethod||he.PullRequest;l(A),i(M),d(z),f(O),T(A),C(M),w(z),N(O)}catch(E){je({title:"Error",description:E instanceof Error?E.message:"Failed to load project settings",variant:"destructive"})}finally{b(!1)}},[t]);m.useEffect(()=>{s&&y()},[s,t,y]);const S=async()=>{j(!0);try{const E=await Ao(t);E.runCommand?(d(E.runCommand),je({title:"Success",description:`Suggested: ${E.runCommand}`})):je({title:"No command found",description:"Could not detect a dev script in package.json"})}catch(E){je({title:"Error",description:E instanceof Error?E.message:"Failed to suggest command",variant:"destructive"})}finally{j(!1)}},R=async()=>{g(!0);try{if(a!==I&&await vo(t,a),o!==x){const E=o.trim()||null;await Zr(t,E,!1)}if(c!==_){const E=c.trim()||null;await Fo(t,E)}u!==k&&await vs(t,{commitMethod:u}),je({title:"Success",description:"Project settings saved"}),await r(),e(!1)}catch(E){je({title:"Error",description:E instanceof Error?E.message:"Failed to save settings",variant:"destructive"})}finally{g(!1)}};return n.jsx(ft,{open:s,onOpenChange:e,children:n.jsxs(Qe,{className:"sm:max-w-[500px]",children:[n.jsxs(Ye,{children:[n.jsx(Ge,{children:"Project Settings"}),n.jsx(He,{children:"Configure settings for your project."})]}),n.jsxs("div",{className:"grid gap-4 py-4",children:[n.jsxs("div",{className:"grid gap-2",children:[n.jsx(be,{htmlFor:"projectName",children:"Project Name"}),n.jsx(ze,{id:"projectName",value:a,onChange:E=>l(E.target.value),placeholder:"Enter project name",className:"text-sm",disabled:v})]}),n.jsxs("div",{className:"grid gap-2",children:[n.jsx(be,{htmlFor:"setupScript",children:"Setup Script"}),n.jsx(rs,{id:"setupScript",value:o,onChange:E=>i(E.target.value),placeholder:"e.g. npm install",className:"font-mono text-sm min-h-[80px] resize-none",disabled:v}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"This script runs automatically after cloning the repo for new threads."})]}),n.jsxs("div",{className:"grid gap-2",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(be,{htmlFor:"runCommand",children:"Run Command"}),n.jsx(J,{variant:"ghost",size:"sm",onClick:S,disabled:p||v,className:"text-xs h-6 px-2 gap-1",children:p?n.jsxs(n.Fragment,{children:[n.jsx(ve,{className:"h-3 w-3 animate-spin"}),"Suggesting..."]}):n.jsxs(n.Fragment,{children:[n.jsx(rn,{className:"h-3 w-3"}),"Suggest"]})})]}),n.jsx(ze,{id:"runCommand",value:c,onChange:E=>d(E.target.value),placeholder:"e.g. npm run dev",className:"font-mono text-sm",disabled:v}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"The command to start the dev server. Leave empty to disable run functionality."})]}),n.jsxs("div",{className:"grid gap-2",children:[n.jsx(be,{children:"Commit Method"}),n.jsxs("div",{className:"flex gap-4",children:[n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"radio",name:"commitMethod",value:he.PullRequest,checked:u===he.PullRequest,onChange:E=>f(E.target.value),disabled:v}),n.jsx("span",{className:"text-sm",children:"Pull Requests"})]}),n.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[n.jsx("input",{type:"radio",name:"commitMethod",value:he.Direct,checked:u===he.Direct,onChange:E=>f(E.target.value),disabled:v}),n.jsx("span",{className:"text-sm",children:"Direct Commits"})]})]}),n.jsx("p",{className:"text-xs text-muted-foreground",children:u===he.PullRequest?"Feature branches are created and pull requests can be created.":"Commits are made directly to the main branch without feature branches."})]})]}),n.jsxs(Xe,{children:[n.jsx(J,{variant:"ghost",onClick:()=>e(!1),disabled:v||h,children:"Cancel"}),n.jsx(J,{onClick:R,disabled:h||v,children:h?n.jsxs(n.Fragment,{children:[n.jsx(ve,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):v?n.jsxs(n.Fragment,{children:[n.jsx(ve,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading..."]}):"Save"})]})]})})}function sd(s){const e=F.c(19),{open:t,suggestedCommand:r,onConfirm:a}=s;let l;e[0]!==a?(l=p=>{p||a(!1)},e[0]=a,e[1]=l):l=e[1];let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(Os,{children:"Install dependencies?"}),e[2]=o):o=e[2];const i=r??"";let c;e[3]!==i?(c=n.jsxs(Ls,{children:[o,n.jsxs(Fs,{children:["Install dependencies with"," ",n.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-sm",children:i}),"?"]})]}),e[3]=i,e[4]=c):c=e[4];let d;e[5]!==a?(d=n.jsx(yn,{onClick:()=>a(!1),children:"No"}),e[5]=a,e[6]=d):d=e[6];let u;e[7]!==a?(u=n.jsx(jn,{onClick:()=>a(!0),children:"Yes"}),e[7]=a,e[8]=u):u=e[8];let f;e[9]!==d||e[10]!==u?(f=n.jsxs($s,{children:[d,u]}),e[9]=d,e[10]=u,e[11]=f):f=e[11];let h;e[12]!==c||e[13]!==f?(h=n.jsxs(As,{children:[c,f]}),e[12]=c,e[13]=f,e[14]=h):h=e[14];let g;return e[15]!==t||e[16]!==l||e[17]!==h?(g=n.jsx(xn,{open:t,onOpenChange:l,children:h}),e[15]=t,e[16]=l,e[17]=h,e[18]=g):g=e[18],g}const Ms=Tl,Dn=Il,ps=m.forwardRef((s,e)=>{const t=F.c(12);let r,a,l;t[0]!==s?({className:a,children:r,...l}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l):(r=t[1],a=t[2],l=t[3]);let o;t[4]!==a?(o=B("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",a),t[4]=a,t[5]=o):o=t[5];let i;t[6]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx(Nl,{asChild:!0,children:n.jsx(It,{className:"h-4 w-4 opacity-50"})}),t[6]=i):i=t[6];let c;return t[7]!==r||t[8]!==l||t[9]!==e||t[10]!==o?(c=n.jsxs(Sr,{ref:e,className:o,...l,children:[r,i]}),t[7]=r,t[8]=l,t[9]=e,t[10]=o,t[11]=c):c=t[11],c});ps.displayName=Sr.displayName;const fa=m.forwardRef((s,e)=>{const t=F.c(10);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("flex cursor-default items-center justify-center py-1",r),t[3]=r,t[4]=l):l=t[4];let o;t[5]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(Jn,{className:"h-4 w-4"}),t[5]=o):o=t[5];let i;return t[6]!==a||t[7]!==e||t[8]!==l?(i=n.jsx(Cr,{ref:e,className:l,...a,children:o}),t[6]=a,t[7]=e,t[8]=l,t[9]=i):i=t[9],i});fa.displayName=Cr.displayName;const pa=m.forwardRef((s,e)=>{const t=F.c(10);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("flex cursor-default items-center justify-center py-1",r),t[3]=r,t[4]=l):l=t[4];let o;t[5]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(It,{className:"h-4 w-4"}),t[5]=o):o=t[5];let i;return t[6]!==a||t[7]!==e||t[8]!==l?(i=n.jsx(Tr,{ref:e,className:l,...a,children:o}),t[6]=a,t[7]=e,t[8]=l,t[9]=i):i=t[9],i});pa.displayName=Tr.displayName;const hs=m.forwardRef((s,e)=>{const t=F.c(21);let r,a,l,o;t[0]!==s?({className:a,children:r,position:o,...l}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l,t[4]=o):(r=t[1],a=t[2],l=t[3],o=t[4]);const i=o===void 0?"popper":o,c=i==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1";let d;t[5]!==a||t[6]!==c?(d=B("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md 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",c,a),t[5]=a,t[6]=c,t[7]=d):d=t[7];let u;t[8]===Symbol.for("react.memo_cache_sentinel")?(u=n.jsx(fa,{}),t[8]=u):u=t[8];const f=i==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]";let h;t[9]!==f?(h=B("p-1",f),t[9]=f,t[10]=h):h=t[10];let g;t[11]!==r||t[12]!==h?(g=n.jsx(wl,{className:h,children:r}),t[11]=r,t[12]=h,t[13]=g):g=t[13];let p;t[14]===Symbol.for("react.memo_cache_sentinel")?(p=n.jsx(pa,{}),t[14]=p):p=t[14];let j;return t[15]!==i||t[16]!==l||t[17]!==e||t[18]!==d||t[19]!==g?(j=n.jsx(vl,{children:n.jsxs(Ir,{ref:e,className:d,position:i,...l,children:[u,g,p]})}),t[15]=i,t[16]=l,t[17]=e,t[18]=d,t[19]=g,t[20]=j):j=t[20],j});hs.displayName=Ir.displayName;const nd=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("py-1.5 pl-8 pr-2 text-sm font-semibold",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(kr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});nd.displayName=kr.displayName;const ut=m.forwardRef((s,e)=>{const t=F.c(14);let r,a,l;t[0]!==s?({className:a,children:r,...l}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l):(r=t[1],a=t[2],l=t[3]);let o;t[4]!==a?(o=B("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),t[4]=a,t[5]=o):o=t[5];let i;t[6]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:n.jsx(Sl,{children:n.jsx(Je,{className:"h-4 w-4"})})}),t[6]=i):i=t[6];let c;t[7]!==r?(c=n.jsx(Cl,{children:r}),t[7]=r,t[8]=c):c=t[8];let d;return t[9]!==l||t[10]!==e||t[11]!==o||t[12]!==c?(d=n.jsxs(Rr,{ref:e,className:o,...l,children:[i,c]}),t[9]=l,t[10]=e,t[11]=o,t[12]=c,t[13]=d):d=t[13],d});ut.displayName=Rr.displayName;const rd=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("-mx-1 my-1 h-px bg-muted",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(Er,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});rd.displayName=Er.displayName;function ad({open:s,onOpenChange:e,onRestartOnboarding:t}){const[r,a]=m.useState([]),[l,o]=m.useState(null),[i,c]=m.useState(!1),[d,u]=m.useState(!1),[f,h]=m.useState(null),[g,p]=m.useState(!1),[j,v]=m.useState(""),[b,I]=m.useState([]),[T,x]=m.useState(new Set),[C,_]=m.useState(new Map),[w,k]=m.useState(""),[N,y]=m.useState("alphabetical"),[S,R]=m.useState("all"),[E,A]=m.useState(!1),M=m.useRef(0),z=m.useRef(null);m.useEffect(()=>{s&&O()},[s]),m.useEffect(()=>()=>{z.current&&clearTimeout(z.current)},[]),m.useEffect(()=>{s&&l&&($(l),L(l))},[l,s]);const O=async()=>{c(!0),v("");try{const D=await un();a(D),D.length>0&&!l&&o(D[0].name)}catch(D){v(D instanceof Error?D.message:"Failed to load providers")}finally{c(!1)}},L=async D=>{h(null),p(!0);try{const U=await eo(D);U.status==="success"&&h(U.balance)}catch(U){console.error(`Failed to load balance for ${D}:`,U)}finally{p(!1)}},$=async D=>{u(!0),k(""),y("alphabetical"),R("all");try{const U=await mn(D);console.log(`Loaded ${U.length} models for ${D}`),I(U);const H=await Ps();console.log("Enabled models by provider:",H);const V=H[D]||[];console.log(`Found ${V.length} enabled models for ${D}:`,V.map(ee=>ee.id));const Z=new Set(V.map(ee=>ee.id));x(Z),_(new Map)}catch(U){console.error(`Failed to load models for ${D}:`,U),I([]),x(new Set)}finally{u(!1)}},q=(D,U)=>{a(H=>H.map(V=>V.name===D?{...V,apiKey:U}:V))},G=D=>{_(U=>{const H=new Map(U),V=T.has(D),Z=H.has(D),ee=H.get(D),W=!(Z?ee:V);return W===V?H.delete(D):H.set(D,W),H})},K=D=>{_(U=>{const H=new Map(U);return b.forEach(V=>{const Z=T.has(V.id);D?Z?H.delete(V.id):H.set(V.id,!0):Z?H.set(V.id,!1):H.delete(V.id)}),H})},X=async()=>{const D={};if(r.forEach(U=>{U.apiKey!==void 0&&(D[U.name]=U.apiKey)}),Object.keys(D).length!==0)try{await so(D)}catch(U){console.error("Failed to save keys on close:",U)}},de=async()=>{if(!(C.size===0||!l))try{for(const[D,U]of C.entries())U?(await ea(l,D),x(H=>new Set([...H,D]))):(await No(l,D),x(H=>{const V=new Set(H);return V.delete(D),V}));_(new Map)}catch(D){console.error("Failed to save model changes:",D)}},ie=async D=>{D||(await de(),X()),e(D)},re=r.find(D=>D.name===l),ae=re?.apiKey&&re.apiKey.trim().length>0,le=(D,U)=>`${D==="all"?"All":"Free"} • ${U==="alphabetical"?"A-Z":U==="price-low"?"Price ↑":U==="price-high"?"Price ↓":U}`,ce=D=>At(D.id),te=b.filter(D=>{const U=w.toLowerCase(),H=ce(D),V=D.name.toLowerCase().includes(U)||D.id.toLowerCase().includes(U)||H.toLowerCase().includes(U);if(S==="tools"){const Z=D.supportedParameters?.tools===!0;return V&&Z}if(S==="free"){const Z=D.pricing?.prompt===0&&D.pricing?.completion===0;return V&&Z}return V}).sort((D,U)=>{const H=T.has(D.id)?0:1,V=T.has(U.id)?0:1;if(H!==V)return H-V;if(N==="price-low"){const Z=!!D.pricing,ee=!!U.pricing;if(Z!==ee)return Z?-1:1;if(!D.pricing||!U.pricing)return 0;const Y=(D.pricing.prompt+D.pricing.completion)/2,W=(U.pricing.prompt+U.pricing.completion)/2;return Y-W}if(N==="price-high"){const Z=!!D.pricing,ee=!!U.pricing;if(Z!==ee)return Z?-1:1;if(!D.pricing||!U.pricing)return 0;const Y=(D.pricing.prompt+D.pricing.completion)/2;return(U.pricing.prompt+U.pricing.completion)/2-Y}return ce(D).localeCompare(ce(U))}),se=[...r].sort((D,U)=>{const H=!!D.apiKey,V=!!U.apiKey;return H&&!V?-1:!H&&V?1:D.name.localeCompare(U.name)});return n.jsx(ft,{open:s,onOpenChange:ie,children:n.jsxs(Qe,{className:"max-w-3xl h-[600px] flex flex-col p-0 overflow-hidden",children:[n.jsx("div",{className:"p-6 pb-2",children:n.jsxs(Ye,{children:[n.jsx(Ge,{children:"Settings"}),n.jsx(He,{asChild:!0,children:n.jsx("span",{role:t?"button":void 0,tabIndex:t?0:void 0,onClick:t?()=>{z.current&&(clearTimeout(z.current),z.current=null),M.current+=1,M.current>=3?(M.current=0,t()):z.current=setTimeout(()=>{M.current=0,z.current=null},500)}:void 0,onKeyDown:t?D=>{(D.key==="Enter"||D.key===" ")&&D.currentTarget.click()}:void 0,className:t?"cursor-default select-none":void 0,children:"Manage your AI providers, API keys, and models."})})]})}),i?n.jsx("div",{className:"flex flex-1 items-center justify-center",children:n.jsx(ve,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):j?n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-2",children:[n.jsx("p",{className:"text-sm text-destructive",children:j}),n.jsx(J,{variant:"outline",size:"sm",onClick:O,children:"Retry"})]}):n.jsxs("div",{className:"flex flex-1 overflow-hidden border-t border-border",children:[n.jsx("div",{className:"w-64 border-r border-border bg-muted/30",children:n.jsx(Ke,{className:"h-full",children:n.jsx("div",{className:"flex flex-col p-2 gap-1",children:se.map(D=>n.jsxs("button",{onClick:()=>o(D.name),className:B("flex items-center justify-between px-3 py-2 text-sm font-medium rounded-md transition-colors text-left",l===D.name?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-muted-foreground hover:text-foreground"),children:[n.jsx("span",{className:B(D.apiKey&&"font-bold text-foreground"),children:D.name}),D.apiKey&&n.jsx(Je,{className:"h-3.5 w-3.5 text-green-500"})]},D.name))})})}),n.jsx("div",{className:"flex-1 flex flex-col overflow-hidden bg-background",children:re?n.jsx(Ke,{className:"flex-1",children:n.jsxs("div",{className:"p-6 flex flex-col gap-8",children:[n.jsx("div",{className:"flex flex-col gap-2",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("h3",{className:"text-lg font-semibold",children:re.name}),f!==null&&n.jsxs("span",{className:"text-xs font-medium text-green-600 bg-green-50 px-2.5 py-1 rounded-full border border-green-100 flex items-center gap-1.5",children:[n.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-green-500"}),"$",is(f)," balance"]}),g&&n.jsx(ve,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"})]}),re.url&&n.jsxs("a",{href:re.url,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 text-xs text-brand hover:underline hover:text-brand/80",children:["Visit provider website ",n.jsx(js,{className:"h-3 w-3"})]})]})}),n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("div",{className:"flex items-center justify-between",children:n.jsx(we,{children:n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsx("span",{className:"text-sm font-medium cursor-help",children:"API Key"})}),n.jsx(me,{children:"Your API key is stored locally and never shared."})]})})}),re.authType==="APIKey"?n.jsxs("div",{className:"relative",children:[n.jsx(_r,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),n.jsx(ze,{type:E?"text":"password",placeholder:re.keyName||"Enter API Key",className:"pl-10 pr-10",value:re.apiKey||"",onChange:D=>{q(re.name,D.target.value)}}),n.jsx(J,{type:"button",variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 -translate-y-1/2 h-8 w-8 p-0",onClick:()=>A(!E),disabled:!re.apiKey,children:E?n.jsx(Pr,{className:"h-4 w-4 text-muted-foreground"}):n.jsx(ln,{className:"h-4 w-4 text-muted-foreground"})})]}):n.jsxs("div",{className:"rounded-md bg-muted/30 p-4 text-center",children:[n.jsx("p",{className:"text-sm text-muted-foreground",children:"This provider uses OAuth for authentication."}),n.jsxs(J,{variant:"outline",size:"sm",className:"mt-2",disabled:!0,children:["Sign in with ",re.name]})]})]}),n.jsxs("div",{className:"flex flex-col gap-4",children:[!d&&b.length>0&&n.jsxs("div",{className:B("flex items-center justify-between gap-3",!ae&&"opacity-25"),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Dt,{id:"select-all-models",disabled:!ae,checked:b.every(D=>{const U=C.has(D.id),H=C.get(D.id);return U?H:T.has(D.id)}),onCheckedChange:D=>K(D===!0)}),n.jsx("label",{htmlFor:"select-all-models",className:"text-sm cursor-pointer whitespace-nowrap",children:"Select all models"})]}),n.jsxs("div",{className:"flex-1 relative",children:[n.jsx(Es,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground pointer-events-none"}),n.jsx(ze,{placeholder:"Search models...",className:"pl-10 h-8",value:w,onChange:D=>k(D.target.value),disabled:!ae})]}),n.jsx(we,{children:n.jsxs("div",{className:"flex items-center rounded-md border border-border p-0.5",children:[n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsx(J,{type:"button",variant:N==="alphabetical"?"secondary":"ghost",size:"icon",className:"h-8 w-8",onClick:()=>y("alphabetical"),children:n.jsx(Mr,{className:"h-4 w-4"})})}),n.jsx(me,{children:"Sort A–Z"})]}),n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsx(J,{type:"button",variant:N==="price-low"||N==="price-high"?"secondary":"ghost",size:"icon",className:"h-8 w-8",onClick:()=>y("price-low"),children:n.jsx(Dr,{className:"h-4 w-4"})})}),n.jsx(me,{children:"Sort by price"})]})]})})]}),d?n.jsx("div",{className:"flex items-center justify-center py-8",children:n.jsx(ve,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):b.length===0?n.jsx("div",{className:"text-center py-8",children:n.jsx("p",{className:"text-sm text-muted-foreground",children:"No models available for this provider."})}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex gap-3 mb-2 hidden",children:[n.jsxs("div",{className:"flex-1 relative",children:[n.jsx(Es,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),n.jsx(ze,{placeholder:"Search models...",className:"pl-10",value:w,onChange:D=>k(D.target.value)})]}),n.jsxs(Ms,{value:`${S}:${N}`,onValueChange:D=>{const[U,H]=D.split(":");R(U),y(H)},children:[n.jsx(ps,{className:"w-48",children:n.jsx("span",{className:"text-sm",children:le(S,N)})}),n.jsxs(hs,{children:[n.jsxs("div",{className:"px-2 py-2",children:[n.jsx("div",{className:"text-xs font-medium text-muted-foreground px-2 py-1",children:"Filter"}),n.jsx(ut,{value:`all:${N}`,children:"All models"}),n.jsx(ut,{value:`free:${N}`,children:"Free"})]}),n.jsxs("div",{className:"px-2 py-2 border-t border-border",children:[n.jsx("div",{className:"text-xs font-medium text-muted-foreground px-2 py-1",children:"Sort by"}),n.jsx(ut,{value:`${S}:alphabetical`,children:"Alphabetical"}),n.jsx(ut,{value:`${S}:price-low`,children:"Price - Low to High"}),n.jsx(ut,{value:`${S}:price-high`,children:"Price - High to Low"})]})]})]})]}),n.jsx(we,{children:n.jsx("div",{className:"grid grid-cols-1 gap-0 border border-border rounded-md overflow-hidden",children:te.length===0?n.jsx("div",{className:"text-center py-8",children:n.jsx("p",{className:"text-sm text-muted-foreground",children:"No models matching your filters. Try adjusting the filter or search criteria."})}):te.map(D=>{const U=T.has(D.id),H=C.has(D.id),V=C.get(D.id),Z=H?V:U,ee=D.pricing;return n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsxs("div",{className:`flex items-center space-x-3 p-3 hover:bg-muted/30 transition-colors cursor-default border-b border-border last:border-b-0 ${ae?"":"opacity-25"}`,children:[n.jsx(Dt,{id:D.id,disabled:!ae,checked:Z??!1,onCheckedChange:()=>G(D.id),className:"mt-0"}),n.jsxs("div",{className:"flex-1 flex items-center justify-between gap-3 leading-none",children:[n.jsx("label",{htmlFor:D.id,className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer truncate flex-1 w-0",children:ce(D)}),ee&&n.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap flex-shrink-0",children:ee.prompt<=0&&ee.completion<=0?"Free":`$${is(ee.prompt*1e6)} in | $${is(ee.completion*1e6)} out`})]})]})}),D.description&&n.jsx(me,{side:"top",className:"max-w-xs",children:n.jsx("p",{className:"text-sm",children:D.description})})]},D.id)})})})]})]})]})}):n.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:"Select a provider to configure"})})]}),n.jsx("div",{className:"p-4 border-t border-border bg-muted/10",children:n.jsx(Xe,{children:n.jsx(J,{onClick:()=>ie(!1),children:"Done"})})})]})})}function ld({selectedProvider:s,onProviderChange:e,showApiKeyInput:t=!0,onApiKeyChange:r,isLoading:a,error:l,variant:o="dropdown"}){const[i,c]=m.useState([]),[d,u]=m.useState(!1);return m.useEffect(()=>{(async()=>{u(!0);try{const h=await un();c(h),h.length>0&&!s&&e(h[0])}catch(h){console.error("Failed to load providers:",h)}finally{u(!1)}})()},[s,e]),d?n.jsx("div",{className:"flex items-center justify-center py-4",children:n.jsx(ve,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):o==="dropdown"?n.jsxs("div",{className:"flex flex-col gap-4",children:[l&&n.jsx("p",{className:"text-sm text-destructive",children:l}),n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx("label",{className:"text-sm font-medium",children:"AI Provider"}),n.jsxs(Ms,{value:s?.name||"",onValueChange:f=>{const h=i.find(g=>g.name===f);h&&e(h)},children:[n.jsx(ps,{children:s?s.name:"Select a provider"}),n.jsx(hs,{children:i.map(f=>n.jsx(ut,{value:f.name,children:f.name},f.name))})]})]}),s&&s.url&&n.jsxs("a",{href:s.url,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 text-sm text-brand hover:underline hover:text-brand/80",children:["Visit provider website ",n.jsx(js,{className:"h-3.5 w-3.5"})]}),t&&s&&n.jsx(od,{provider:s,value:s.apiKey||"",onChange:r,isLoading:a})]}):null}function od(s){const e=F.c(24),{provider:t,value:r,onChange:a,isLoading:l}=s,[o,i]=m.useState(!1);if(t.authType!=="APIKey"){let T;e[0]===Symbol.for("react.memo_cache_sentinel")?(T=n.jsx("p",{className:"text-sm text-muted-foreground",children:"This provider uses OAuth for authentication."}),e[0]=T):T=e[0];let x;return e[1]!==t.name?(x=n.jsxs("div",{className:"rounded-md bg-muted/30 p-4 text-center",children:[T,n.jsxs(J,{variant:"outline",size:"sm",className:"mt-2",disabled:!0,children:["Sign in with ",t.name]})]}),e[1]=t.name,e[2]=x):x=e[2],x}let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx("div",{className:"flex items-center justify-between",children:n.jsx(we,{children:n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsx("label",{htmlFor:"api-key",className:"text-sm font-medium cursor-help",children:"API Key"})}),n.jsx(me,{children:"Your API key is stored locally and never shared."})]})})}),e[3]=c):c=e[3];let d;e[4]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(_r,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e[4]=d):d=e[4];const u=o?"text":"password",f=t.keyName||"Enter API Key";let h;e[5]!==a?(h=T=>a?.(T.target.value),e[5]=a,e[6]=h):h=e[6];let g;e[7]!==l||e[8]!==u||e[9]!==f||e[10]!==h||e[11]!==r?(g=n.jsx(ze,{id:"api-key",type:u,placeholder:f,className:"pl-10 pr-10",value:r,onChange:h,disabled:l}),e[7]=l,e[8]=u,e[9]=f,e[10]=h,e[11]=r,e[12]=g):g=e[12];let p;e[13]!==o?(p=()=>i(!o),e[13]=o,e[14]=p):p=e[14];const j=l||!r;let v;e[15]!==o?(v=o?n.jsx(Pr,{className:"h-4 w-4 text-muted-foreground"}):n.jsx(ln,{className:"h-4 w-4 text-muted-foreground"}),e[15]=o,e[16]=v):v=e[16];let b;e[17]!==p||e[18]!==j||e[19]!==v?(b=n.jsx(J,{type:"button",variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 -translate-y-1/2 h-8 w-8 p-0",onClick:p,disabled:j,children:v}),e[17]=p,e[18]=j,e[19]=v,e[20]=b):b=e[20];let I;return e[21]!==b||e[22]!==g?(I=n.jsxs("div",{className:"flex flex-col gap-3",children:[c,n.jsxs("div",{className:"relative",children:[d,g,b]})]}),e[21]=b,e[22]=g,e[23]=I):I=e[23],I}function id({provider:s,onModelsChange:e,isLoading:t,disabled:r,displayMode:a="grid"}){const[l,o]=m.useState([]),[i,c]=m.useState(new Set),[d,u]=m.useState(new Map),[f,h]=m.useState(!1),[g,p]=m.useState(""),[j,v]=m.useState("alphabetical");m.useEffect(()=>{b()},[s]);const b=async()=>{h(!0),p(""),v("alphabetical");try{const w=await mn(s);o(w);const N=(await Ps())[s]||[],y=new Set(N.map(S=>S.id));c(y),u(new Map)}catch(w){console.error(`Failed to load models for ${s}:`,w),o([]),c(new Set)}finally{h(!1)}},I=(w,k)=>{const N=new Set(w);l.forEach(y=>{k.has(y.id)&&(k.get(y.id)?N.add(y.id):N.delete(y.id))}),e?.(N)},T=w=>{u(k=>{const N=new Map(k),y=i.has(w),S=N.has(w),R=N.get(w),A=!(S?R:y);return A===y?N.delete(w):N.set(w,A),I(i,N),N})},x=w=>{u(k=>{const N=new Map(k);return l.forEach(y=>{const S=i.has(y.id);w?S?N.delete(y.id):N.set(y.id,!0):S?N.set(y.id,!1):N.delete(y.id)}),I(i,N),N})},C=w=>At(w.id),_=l.filter(w=>{const k=g.toLowerCase(),N=C(w);return w.name.toLowerCase().includes(k)||w.id.toLowerCase().includes(k)||N.toLowerCase().includes(k)}).sort((w,k)=>{const N=i.has(w.id)?0:1,y=i.has(k.id)?0:1;if(N!==y)return N-y;if(j==="price-low"){const S=!!w.pricing,R=!!k.pricing;if(S!==R)return S?-1:1;if(!w.pricing||!k.pricing)return 0;const E=(w.pricing.prompt+w.pricing.completion)/2,A=(k.pricing.prompt+k.pricing.completion)/2;return E-A}if(j==="price-high"){const S=!!w.pricing,R=!!k.pricing;if(S!==R)return S?-1:1;if(!w.pricing||!k.pricing)return 0;const E=(w.pricing.prompt+w.pricing.completion)/2;return(k.pricing.prompt+k.pricing.completion)/2-E}return C(w).localeCompare(C(k))});return f||t?n.jsx("div",{className:"flex items-center justify-center py-8",children:n.jsx(ve,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):l.length===0?n.jsx("div",{className:"text-center py-8",children:n.jsx("p",{className:"text-sm text-muted-foreground",children:"No models available for this provider."})}):a==="compact"?n.jsxs("div",{className:"flex flex-col gap-4",children:[n.jsxs("div",{className:B("flex items-center justify-between",r&&"opacity-25"),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Dt,{id:"select-all-models",disabled:r,checked:l.every(w=>{const k=d.has(w.id),N=d.get(w.id);return k?N:i.has(w.id)}),onCheckedChange:w=>x(w===!0)}),n.jsx("label",{htmlFor:"select-all-models",className:"text-sm cursor-pointer",children:"Select all models"})]}),n.jsx(we,{children:n.jsxs("div",{className:"flex items-center rounded-md border border-border p-0.5",children:[n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsx(J,{type:"button",variant:j==="alphabetical"?"secondary":"ghost",size:"icon",className:"h-8 w-8",onClick:()=>v("alphabetical"),disabled:r,children:n.jsx(Mr,{className:"h-4 w-4"})})}),n.jsx(me,{children:"Sort A–Z"})]}),n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsx(J,{type:"button",variant:j==="price-low"||j==="price-high"?"secondary":"ghost",size:"icon",className:"h-8 w-8",onClick:()=>{v(j==="price-low"?"price-high":"price-low")},disabled:r,children:n.jsx(Dr,{className:"h-4 w-4"})})}),n.jsx(me,{children:"Sort by price"})]})]})})]}),n.jsx(we,{children:n.jsx("div",{className:"grid grid-cols-1 gap-0 border border-border rounded-md overflow-hidden",children:_.length===0?n.jsx("div",{className:"text-center py-4",children:n.jsx("p",{className:"text-sm text-muted-foreground",children:"No models available."})}):_.map(w=>{const k=i.has(w.id),N=d.has(w.id),y=d.get(w.id),S=N?y:k,R=w.pricing;return n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsxs("div",{className:B("flex items-center space-x-3 p-3 hover:bg-muted/30 transition-colors cursor-default border-b border-border last:border-b-0",r&&"opacity-25"),children:[n.jsx(Dt,{id:w.id,disabled:r,checked:S??!1,onCheckedChange:()=>T(w.id),className:"mt-0"}),n.jsxs("div",{className:"flex-1 flex items-center justify-between gap-3 leading-none",children:[n.jsx("label",{htmlFor:w.id,className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer truncate flex-1 w-0",children:C(w)}),R&&n.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap flex-shrink-0",children:R.prompt<=0&&R.completion<=0?"Free":`${is(R.prompt*1e6)} in | ${is(R.completion*1e6)} out`})]})]})}),w.description&&n.jsx(me,{side:"top",className:"max-w-xs",children:n.jsx("p",{className:"text-sm",children:w.description})})]},w.id)})})})]}):null}function cd({open:s,onOpenChange:e,onComplete:t}){const[r,a]=m.useState("git-check"),[l,o]=m.useState(null),[i,c]=m.useState(!1),[d,u]=m.useState([]),[f,h]=m.useState(null),[g,p]=m.useState(""),[j,v]=m.useState(!1),[b,I]=m.useState(""),[T,x]=m.useState(new Set),[C,_]=m.useState(!1),[w,k]=m.useState(!1);m.useEffect(()=>{s&&r==="git-check"&&N()},[s,r]),m.useEffect(()=>{s&&r==="provider-selection"&&d.length===0&&y()},[s,r,d.length]),m.useEffect(()=>{s&&r==="model-selection"&&f&&S()},[s,r,f]);const N=async()=>{c(!0);try{const O=await Uo();o(O.gitInstalled)}catch(O){console.error("Failed to check git installation:",O),o(!1)}finally{c(!1)}},y=async()=>{try{const O=await un();u(O),O.length>0&&!f&&h(O[0])}catch(O){console.error("Failed to load providers:",O)}},S=async()=>{if(f){_(!0);try{await mn(f.name),x(new Set)}catch(O){console.error("Failed to load models:",O)}finally{_(!1)}}},R=async()=>{if(!f||!g.trim()){I("Please enter an API key");return}v(!0),I("");try{await to(f.name,g),a("model-selection")}catch(O){I(O instanceof Error?O.message:"Failed to validate API key")}finally{v(!1)}},E=async()=>{if(f){k(!0);try{for(const O of T)await ea(f.name,O);await kn(),t?.(),e(!1)}catch(O){console.error("Failed to complete onboarding:",O)}finally{k(!1)}}},A=async()=>{k(!0);try{await kn(),t?.(),e(!1)}catch(O){console.error("Failed to skip onboarding:",O)}finally{k(!1)}},M=O=>{h(O),p(O.apiKey||""),I("")},z=()=>{a("provider-selection")};return n.jsx(ft,{open:s,onOpenChange:e,children:n.jsxs(Qe,{className:"max-w-2xl h-[min(42rem,90dvh)] flex flex-col p-0 overflow-hidden",children:[n.jsxs("div",{className:"px-6 pt-6 pb-2",children:[n.jsxs("div",{className:"w-1/2 mx-auto flex items-center gap-2 mb-6",children:[n.jsx("div",{className:B("flex items-center justify-center h-8 w-8 rounded-full text-sm font-medium",r==="git-check"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"),children:"1"}),n.jsx("div",{className:B("h-0.5 flex-1",r==="provider-selection"||r==="model-selection"?"bg-primary":"bg-muted")}),n.jsx("div",{className:B("flex items-center justify-center h-8 w-8 rounded-full text-sm font-medium",r==="provider-selection"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"),children:"2"}),n.jsx("div",{className:B("h-0.5 flex-1",r==="model-selection"?"bg-primary":"bg-muted")}),n.jsx("div",{className:B("flex items-center justify-center h-8 w-8 rounded-full text-sm font-medium",r==="model-selection"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"),children:"3"})]}),n.jsxs(Ye,{children:[r==="git-check"&&n.jsxs(n.Fragment,{children:[n.jsx(Ge,{children:"Let's get started"}),n.jsx(He,{children:"First, we need to check that Git is installed on your system."})]}),r==="provider-selection"&&n.jsxs(n.Fragment,{children:[n.jsx(Ge,{children:"Select an AI Provider"}),n.jsx(He,{children:"Choose your preferred AI provider and enter your API key."})]}),r==="model-selection"&&n.jsxs(n.Fragment,{children:[n.jsx(Ge,{children:"Select Models"}),n.jsx(He,{children:"Choose which models you want to use with this provider."})]})]})]}),n.jsx(Ke,{className:"flex-1 min-h-0 overflow-hidden",children:n.jsxs("div",{className:"px-6 py-4",children:[r==="git-check"&&n.jsx("div",{className:"space-y-4",children:i?n.jsx("div",{className:"flex items-center justify-center py-8",children:n.jsx(ve,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):l?n.jsxs("div",{className:"rounded-lg border border-green-200 bg-green-50 p-4 flex items-start gap-3",children:[n.jsx(Je,{className:"h-5 w-5 text-green-600 flex-shrink-0 mt-0.5"}),n.jsxs("div",{children:[n.jsx("h4",{className:"font-medium text-green-900",children:"Git is installed"}),n.jsx("p",{className:"text-sm text-green-800",children:"You're all set to use Git features in Tarsk."})]})]}):n.jsxs("div",{className:"rounded-lg border border-yellow-200 bg-yellow-50 p-4 flex items-start gap-3",children:[n.jsx(Kn,{className:"h-5 w-5 text-yellow-600 flex-shrink-0 mt-0.5"}),n.jsxs("div",{className:"flex-1",children:[n.jsx("h4",{className:"font-medium text-yellow-900",children:"Git is not installed"}),n.jsx("p",{className:"text-sm text-yellow-800 mt-1",children:"Git is required for some features in Tarsk. You can continue without it, but we recommend installing it."}),n.jsxs("a",{href:"https://git-scm.com/downloads",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-sm text-blue-600 hover:underline mt-2",children:["Download Git ",n.jsx(js,{className:"h-3 w-3"})]})]})]})}),r==="provider-selection"&&n.jsx("div",{className:"space-y-4",children:f&&n.jsxs(n.Fragment,{children:[n.jsx(ld,{selectedProvider:f,onProviderChange:M,showApiKeyInput:!0,variant:"dropdown",isLoading:j}),b&&n.jsx("div",{className:"rounded-md bg-destructive/10 p-3 text-sm text-destructive",children:b})]})}),r==="model-selection"&&f&&n.jsx("div",{className:"space-y-4",children:n.jsx(id,{provider:f.name,isLoading:C,displayMode:"compact",disabled:!1,onModelsChange:x})})]})}),n.jsx("div",{className:"px-6 py-4 border-t border-border bg-muted/10",children:n.jsxs(Xe,{className:"flex items-center justify-between",children:[n.jsx("div",{children:r==="provider-selection"&&n.jsx(J,{variant:"ghost",onClick:()=>A(),disabled:w,children:"Skip for now"})}),n.jsxs("div",{className:"flex gap-3",children:[r!=="git-check"&&n.jsx(J,{variant:"outline",onClick:()=>{r==="provider-selection"?a("git-check"):r==="model-selection"&&a("provider-selection")},disabled:w,children:"Back"}),r==="git-check"&&n.jsxs(J,{onClick:z,disabled:i,className:"gap-2",children:["Continue ",n.jsx(vn,{className:"h-4 w-4"})]}),r==="provider-selection"&&n.jsx(J,{onClick:R,disabled:j||!g.trim()||!f,className:"gap-2",children:j?n.jsxs(n.Fragment,{children:[n.jsx(ve,{className:"h-4 w-4 animate-spin"}),"Validating..."]}):n.jsxs(n.Fragment,{children:["Next ",n.jsx(vn,{className:"h-4 w-4"})]})}),r==="model-selection"&&n.jsx(J,{onClick:E,disabled:w,className:"gap-2",children:w?n.jsxs(n.Fragment,{children:[n.jsx(ve,{className:"h-4 w-4 animate-spin"}),"Finishing..."]}):n.jsxs(n.Fragment,{children:["Finish ",n.jsx(Je,{className:"h-4 w-4"})]})})]})]})})]})})}const ha=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("w-full caption-bottom text-sm",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("div",{className:"relative w-full overflow-auto",children:n.jsx("table",{ref:e,className:l,...a})}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});ha.displayName="Table";const ga=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("[&_tr]:border-b",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("thead",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});ga.displayName="TableHeader";const xa=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("[&_tr:last-child]:border-0",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("tbody",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});xa.displayName="TableBody";const dd=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("tfoot",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});dd.displayName="TableFooter";const sn=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("tr",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});sn.displayName="TableRow";const wt=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("th",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});wt.displayName="TableHead";const St=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("p-4 align-middle [&:has([role=checkbox])]:pr-0",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("td",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});St.displayName="TableCell";const ud=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("mt-4 text-sm text-muted-foreground",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx("caption",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});ud.displayName="TableCaption";const Vs="__ALL_PROJECTS__";function An(s){const e=F.c(8),{text:t,maxLength:r}=s,a=r===void 0?100:r;if(t.length<=a){let c;return e[0]!==t?(c=n.jsx(n.Fragment,{children:t}),e[0]=t,e[1]=c):c=e[1],c}let l;e[2]!==a||e[3]!==t?(l=t.substring(0,a),e[2]=a,e[3]=t,e[4]=l):l=e[4];let o;e[5]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx("span",{className:"text-muted-foreground ml-2",children:"..."}),e[5]=o):o=e[5];let i;return e[6]!==l?(i=n.jsxs(n.Fragment,{children:[l,o]}),e[6]=l,e[7]=i):i=e[7],i}function md(s,e){const t=`${e} - `,r=s.title||s.threadId;return r.startsWith(t)?r.slice(t.length):r}async function Ln(s){const e=[],t=new Set;let r="";for(const a of s)try{const l=await ta(a.threadId);l&&l.messages&&(e.push(...l.messages),l.conversationIds&&l.conversationIds.forEach(o=>t.add(o)),l.lastUpdated>r&&(r=l.lastUpdated))}catch(l){console.warn(`Failed to load history for thread ${a.threadId}:`,l)}return e.sort((a,l)=>new Date(l.timestamp).getTime()-new Date(a.timestamp).getTime()),{messages:e,conversationIds:Array.from(t),lastUpdated:r||new Date().toISOString()}}function fd({isOpen:s,onClose:e,initialFilter:t,projects:r}){const[a,l]=m.useState(null),[o,i]=m.useState(!1),[c,d]=m.useState(null),[u,f]=m.useState(0),[h,g]=m.useState(""),[p,j]=m.useState(""),v=m.useCallback(async y=>{i(!0),d(null);try{const S=await ta(y);l(S)}catch(S){d(S instanceof Error?S.message:"Failed to load conversation history")}finally{i(!1)}},[]),b=m.useCallback(async y=>{if(y){i(!0),d(null);try{const S=r.find(E=>E.projectId===y);if(!S||S.threads.length===0){l({threadId:y,messages:[],lastUpdated:new Date().toISOString(),conversationIds:[]});return}const R=await Ln(S.threads);l({threadId:y,...R})}catch(S){d(S instanceof Error?S.message:"Failed to load project history")}finally{i(!1)}}},[r]),I=m.useCallback(async()=>{i(!0),d(null);try{const y=r.flatMap(R=>R.threads),S=await Ln(y);l({threadId:Vs,...S})}catch(y){d(y instanceof Error?y.message:"Failed to load all projects history")}finally{i(!1)}},[r]);m.useEffect(()=>{s&&t?t.type==="thread"?(j(t.id),g(""),f(0),v(t.id)):t.type==="project"&&(g(t.id),j(""),f(0),b(t.id)):s||(l(null),j(""),g(""),f(0),d(null))},[s,t,v,b]);const T=y=>{j(y),g(""),f(0),v(y)},x=y=>{g(y),j(""),f(0),y===Vs?I():b(y)},C=y=>new Date(y).toLocaleString(),_=(y,S)=>{const R=new Date(y),A=new Date(S).getTime()-R.getTime();if(A<0)return{display:"0:00",tooltip:"0 seconds"};const M=Math.floor(A/1e3),z=Math.floor(M/60),O=M%60,L=`${z}:${O.toString().padStart(2,"0")}`;let $;return z===0?$=`${O} second${O!==1?"s":""}`:O===0?$=`${z} minute${z!==1?"s":""}`:$=`${z} minute${z!==1?"s":""} ${O} second${O!==1?"s":""}`,{display:L,tooltip:$}},w=y=>({inputTokens:y.inputTokens||0,outputTokens:y.outputTokens||0}),k=()=>{a&&u<a.messages.length-1&&f(u+1)},N=()=>{u>0&&f(u-1)};return s?n.jsx("div",{className:"fixed inset-0 z-50 bg-background",children:n.jsxs("div",{className:"flex h-full flex-col",children:[n.jsxs("div",{className:"flex items-center justify-between border-b p-4",children:[n.jsxs("div",{className:"flex items-center gap-4",children:[n.jsx("h2",{className:"text-lg font-semibold",children:"Conversation History"}),t?.type==="thread"&&n.jsxs(Ms,{value:p,onValueChange:T,children:[n.jsx(ps,{className:"w-48",children:n.jsx(Dn,{placeholder:"Select thread"})}),n.jsx(hs,{children:r.flatMap(y=>y.threads.map(S=>n.jsx(ut,{value:S.threadId,children:md(S,y.name||y.projectId)},S.threadId)))})]}),n.jsxs(Ms,{value:h,onValueChange:x,children:[n.jsx(ps,{className:"w-48",children:n.jsx(Dn,{placeholder:"Select project"})}),n.jsxs(hs,{children:[n.jsx(ut,{value:Vs,children:"All Projects"}),r.map(y=>n.jsx(ut,{value:y.projectId,children:y.name||y.projectId},y.projectId))]})]})]}),n.jsx(J,{variant:"ghost",size:"icon",onClick:e,children:n.jsx(mt,{className:"h-4 w-4"})})]}),a&&a.messages.length>0&&n.jsxs("div",{className:"flex items-center justify-between border-b p-4",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(J,{variant:"outline",size:"sm",onClick:N,disabled:u===0,children:n.jsx(kl,{className:"h-4 w-4 mr-1"})}),n.jsx(J,{variant:"outline",size:"sm",onClick:k,disabled:!a||u>=a.messages.length-1,children:n.jsx(Mt,{className:"h-4 w-4 ml-1"})})]}),n.jsxs("div",{className:"text-sm text-muted-foreground",children:[u+1," of ",a?.messages.length||0," messages"]})]}),n.jsx("div",{className:"flex-1 overflow-hidden",children:o?n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsxs("div",{className:"text-center",children:[n.jsx(nn,{className:"h-8 w-8 animate-spin mx-auto mb-2"}),n.jsx("p",{children:"Loading conversation history..."})]})}):c?n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsxs(ms,{className:"max-w-md",children:[n.jsx(en,{children:n.jsx(tn,{className:"text-destructive",children:"Error"})}),n.jsxs(fs,{children:[n.jsx("p",{children:c}),n.jsx(J,{onClick:e,className:"mt-4",children:"Close"})]})]})}):a&&a.messages&&a.messages.length>0?n.jsx(Ke,{className:"h-full",children:n.jsx("div",{className:"p-4",children:n.jsxs(ha,{children:[n.jsx(ga,{children:n.jsxs(sn,{children:[n.jsx(wt,{children:"Prompt"}),n.jsx(wt,{children:"Answer"}),n.jsx(wt,{className:"w-24",children:"Model"}),n.jsx(wt,{className:"w-24 text-right",children:"Duration"}),n.jsx(wt,{className:"w-20 text-right",children:"Input Tokens"}),n.jsx(wt,{className:"w-20 text-right",children:"Output Tokens"}),n.jsx(wt,{className:"w-32 text-right",children:"Timestamp"})]})}),n.jsx(xa,{children:a.messages.map((y,S)=>{const{inputTokens:R,outputTokens:E}=w(y);return n.jsxs(sn,{className:S===u?"bg-muted/50":"",children:[n.jsx(St,{className:"max-w-md",children:n.jsx("div",{className:"text-sm",children:n.jsx(An,{text:y.request.message})})}),n.jsx(St,{className:"max-w-md",children:y.response?n.jsx("div",{className:"text-sm",children:n.jsx(An,{text:y.response.content})}):n.jsx("span",{className:"text-muted-foreground italic",children:"No response"})}),n.jsx(St,{className:"text-sm",children:n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(on,{className:"h-3 w-3 text-muted-foreground"}),n.jsx("span",{className:"text-muted-foreground",children:y.request.model})]})}),n.jsx(St,{className:"text-sm text-right",children:y.response?n.jsx(we,{children:n.jsxs(fe,{children:[n.jsx(pe,{asChild:!0,children:n.jsx("div",{className:"cursor-help",children:_(y.timestamp,y.response.completedAt).display})}),n.jsx(me,{children:n.jsx("p",{children:_(y.timestamp,y.response.completedAt).tooltip})})]})}):n.jsx("span",{className:"text-muted-foreground italic",children:"-"})}),n.jsx(St,{className:"text-sm text-muted-foreground text-right",children:R>0?R.toLocaleString():"-"}),n.jsx(St,{className:"text-sm text-muted-foreground text-right",children:E>0?E.toLocaleString():"-"}),n.jsx(St,{className:"text-sm text-muted-foreground text-right",children:C(y.timestamp)})]},y.id)})})]})})}):n.jsx("div",{className:"flex h-full items-center justify-center",children:n.jsxs(ms,{className:"max-w-md",children:[n.jsx(en,{children:n.jsx(tn,{children:"No History"})}),n.jsxs(fs,{children:[n.jsx("p",{children:"No conversation history found for this thread."}),n.jsx(J,{onClick:e,className:"mt-4",children:"Close"})]})]})})})]})}):null}function pd(){const s=F.c(6),[e,t]=m.useState(!0);let r,a;s[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{let f=!0;return(async()=>{try{const g=await fetch(`${Sn()}/health`,{method:"GET"});f&&t(g.ok)}catch{f&&t(!1)}})(),()=>{f=!1}},a=[],s[0]=r,s[1]=a):(r=s[0],a=s[1]),m.useEffect(r,a);const l=hd;if(e)return null;let o;s[2]===Symbol.for("react.memo_cache_sentinel")?(o=Sn(),s[2]=o):o=s[2];const i=o;let c,d;s[3]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsxs(Ls,{children:[n.jsx(Os,{children:"Service unavailable"}),n.jsx(Fs,{children:"Service is not currently up. Please ensure the backend is running at the address below, then retry."})]}),d=n.jsx("div",{className:"rounded-md bg-muted px-3 py-2 text-xs font-mono text-muted-foreground",children:i}),s[3]=c,s[4]=d):(c=s[3],d=s[4]);let u;return s[5]===Symbol.for("react.memo_cache_sentinel")?(u=n.jsx(xn,{open:!0,children:n.jsxs(As,{children:[c,d,n.jsx($s,{children:n.jsx(J,{onClick:l,children:"Retry"})})]})}),s[5]=u):u=s[5],u}function hd(){window.location.assign(window.location.href)}const gd=s=>{const e=F.c(8);let t,r;e[0]!==s?({className:t,...r}=s,e[0]=s,e[1]=t,e[2]=r):(t=e[1],r=e[2]);let a;e[3]!==t?(a=B("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",t),e[3]=t,e[4]=a):a=e[4];let l;return e[5]!==r||e[6]!==a?(l=n.jsx(El,{className:a,...r}),e[5]=r,e[6]=a,e[7]=l):l=e[7],l},$n=Rl,xd=s=>{const e=F.c(12);let t,r,a;e[0]!==s?({withHandle:a,className:t,...r}=s,e[0]=s,e[1]=t,e[2]=r,e[3]=a):(t=e[1],r=e[2],a=e[3]);let l;e[4]!==t?(l=B("relative flex w-px items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",t),e[4]=t,e[5]=l):l=e[5];let o;e[6]!==a?(o=a&&n.jsx("div",{className:"z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border",children:n.jsx(Pl,{className:"h-2.5 w-2.5"})}),e[6]=a,e[7]=o):o=e[7];let i;return e[8]!==r||e[9]!==l||e[10]!==o?(i=n.jsx(_l,{className:l,...r,children:o}),e[8]=r,e[9]=l,e[10]=o,e[11]=i):i=e[11],i},jd=Ml,ja=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(Ar,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});ja.displayName=Ar.displayName;const yd=ys("group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",{variants:{variant:{default:"border bg-background text-foreground",destructive:"destructive group border-destructive bg-destructive text-destructive-foreground"}},defaultVariants:{variant:"default"}}),ya=m.forwardRef((s,e)=>{const t=F.c(11);let r,a,l;t[0]!==s?({className:r,variant:l,...a}=s,t[0]=s,t[1]=r,t[2]=a,t[3]=l):(r=t[1],a=t[2],l=t[3]);let o;t[4]!==r||t[5]!==l?(o=B(yd({variant:l}),r),t[4]=r,t[5]=l,t[6]=o):o=t[6];let i;return t[7]!==a||t[8]!==e||t[9]!==o?(i=n.jsx(Lr,{ref:e,className:o,...a}),t[7]=a,t[8]=e,t[9]=o,t[10]=i):i=t[10],i});ya.displayName=Lr.displayName;const bd=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx($r,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});bd.displayName=$r.displayName;const ba=m.forwardRef((s,e)=>{const t=F.c(10);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",r),t[3]=r,t[4]=l):l=t[4];let o;t[5]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(mt,{className:"h-4 w-4"}),t[5]=o):o=t[5];let i;return t[6]!==a||t[7]!==e||t[8]!==l?(i=n.jsx(Or,{ref:e,className:l,"toast-close":"",...a,children:o}),t[6]=a,t[7]=e,t[8]=l,t[9]=i):i=t[9],i});ba.displayName=Or.displayName;const va=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("text-sm font-semibold",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(Fr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});va.displayName=Fr.displayName;const Na=m.forwardRef((s,e)=>{const t=F.c(9);let r,a;t[0]!==s?({className:r,...a}=s,t[0]=s,t[1]=r,t[2]=a):(r=t[1],a=t[2]);let l;t[3]!==r?(l=B("text-sm opacity-90",r),t[3]=r,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=n.jsx(Gr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Na.displayName=Gr.displayName;function vd(){const s=F.c(5),{toasts:e}=ua();let t;s[0]!==e?(t=e.map(Nd),s[0]=e,s[1]=t):t=s[1];let r;s[2]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx(ja,{}),s[2]=r):r=s[2];let a;return s[3]!==t?(a=n.jsxs(jd,{children:[t,r]}),s[3]=t,s[4]=a):a=s[4],a}function Nd(s){const{id:e,title:t,description:r,action:a,...l}=s;return n.jsxs(ya,{...l,children:[n.jsxs("div",{className:"grid gap-1",children:[t&&n.jsx(va,{children:t}),r&&n.jsx(Na,{children:r})]}),a,n.jsx(ba,{})]},e)}function wd(s){const e=F.c(6);let t,r;e[0]!==s?({children:t,...r}=s,e[0]=s,e[1]=t,e[2]=r):(t=e[1],r=e[2]);let a;return e[3]!==t||e[4]!==r?(a=n.jsx(Ol,{...r,children:t}),e[3]=t,e[4]=r,e[5]=a):a=e[5],a}function Sd(){const{state:s,dispatch:e}=Ce(),{toast:t}=ua(),r=bs("project-creation").dispatch,[a,l]=m.useState(null),o=m.useCallback(async()=>{try{const p=await ws();e({type:P.SetProjects,projects:p.projects})}catch(p){console.error("Failed to refresh projects:",p)}},[e]),i=m.useCallback(async(p,j)=>{try{await mo(p,j)}catch(v){console.error("Failed to select thread:",v)}(s.selectedThreadId!==j||s.selectedProjectId!==p)&&e({type:P.SelectThread,threadId:j,projectId:p})},[e,s.selectedThreadId,s.selectedProjectId]),c=m.useCallback(async(p,j)=>{e({type:P.SetCreatingProject,isCreating:!0});try{const v=await Xr(p,j);if(!v){e({type:P.SetCreatingProject,isCreating:!1}),await o();return}r({type:P.ClearTerminalOutput}),r({type:P.SetTerminalOpen,open:!0});const b=`Cloning repository: ${p}...
14
+ `;r({type:P.AppendTerminalLine,line:{type:"system",content:b.trim()}});const I=v.getReader(),T=new TextDecoder;let x="",C=null,_=!1,w=null,k=null;for(;;){const{done:y,value:S}=await I.read();if(y)break;x+=T.decode(S,{stream:!0});const R=x.split(`
15
+ `);x=R.pop()||"";for(const E of R){const A=E.trim();if(A)try{const M=JSON.parse(A);if(M.type==="progress"){if(!_&&M.threadId&&M.projectId){_=!0,w=M.projectId,k=M.threadId;const z=p.split("/").pop()?.replace(".git","")||"project";e({type:P.AddCreatingProject,projectId:M.projectId,threadId:M.threadId,projectName:z,gitUrl:p}),e({type:P.AddProcessingThread,threadId:M.threadId})}e({type:P.AppendTerminalLine,threadId:k||"project-creation",line:{type:"output",content:M.message}})}else if(M.type==="complete"){if(M.project){C=M.project.id;const z=M.project.threads&&M.project.threads.length>0?`${M.project.path}/${M.project.threads[0]}`:M.project.path;r({type:P.AppendTerminalLine,line:{type:"system",content:`Project created successfully at: ${z}`}}),e({type:P.SetTerminalOpen,open:!1}),M.suggestedSetupScript&&l({projectId:M.project.id,command:M.suggestedSetupScript})}}else M.type==="error"&&(_&&w&&(e({type:P.RemoveCreatingProject,projectId:w}),k&&e({type:P.RemoveProcessingThread,threadId:k})),e({type:P.AppendTerminalLine,threadId:k||"project-creation",line:{type:"error",content:`Error: ${M.message}`}}))}catch(M){console.error("Failed to parse project event",M)}}}e({type:P.SetCreatingProject,isCreating:!1}),_&&k&&e({type:P.RemoveProcessingThread,threadId:k});const N=await ws();if(e({type:P.SetProjects,projects:N.projects}),C){const y=N.projects.find(S=>S.projectId===C);if(y&&y.threads.length>0){const S=y.threads[0].threadId;e({type:P.SelectThread,threadId:S,projectId:C,focusInput:!0})}}}catch(v){console.error("Failed to create project:",v),e({type:P.SetCreatingProject,isCreating:!1}),r({type:P.AppendTerminalLine,line:{type:"error",content:`Failed to create project: ${v instanceof Error?v.message:"Unknown error"}`}})}},[e,o,r]),d=m.useCallback(async(p,j,v)=>{e({type:P.SetCreatingProject,isCreating:!0});try{const b=await Yr(p,j,v);if(!b){e({type:P.SetCreatingProject,isCreating:!1}),await o();return}e({type:P.ClearTerminalOutput}),e({type:P.SetTerminalOpen,open:!0}),e({type:P.AppendTerminalLine,line:{type:"system",content:`Creating app "${p}"...`}});const I=b.getReader(),T=new TextDecoder;let x="",C=null,_=!1,w=null,k=null;for(;;){const{done:y,value:S}=await I.read();if(y)break;x+=T.decode(S,{stream:!0});const R=x.split(`
16
+ `);x=R.pop()||"";for(const E of R){const A=E.trim();if(A)try{const M=JSON.parse(A);M.type==="progress"?(!_&&M.threadId&&M.projectId&&(_=!0,w=M.projectId,k=M.threadId,e({type:P.AddCreatingProject,projectId:M.projectId,threadId:M.threadId,projectName:p,gitUrl:""}),e({type:P.AddProcessingThread,threadId:M.threadId})),e({type:P.AppendTerminalLine,line:{type:"output",content:M.message}})):M.type==="complete"?M.project&&(C=M.project.id,e({type:P.AppendTerminalLine,line:{type:"system",content:`Project created successfully at: ${M.project.path}`}}),e({type:P.SetTerminalOpen,open:!1})):M.type==="error"&&(_&&w&&(e({type:P.RemoveCreatingProject,projectId:w}),k&&e({type:P.RemoveProcessingThread,threadId:k})),e({type:P.AppendTerminalLine,line:{type:"error",content:`Error: ${M.message}`}}))}catch(M){console.error("Failed to parse scaffold event",M)}}}e({type:P.SetCreatingProject,isCreating:!1}),_&&k&&e({type:P.RemoveProcessingThread,threadId:k});const N=await ws();if(e({type:P.SetProjects,projects:N.projects}),C){const y=N.projects.find(S=>S.projectId===C);if(y&&y.threads.length>0){const S=y.threads[0].threadId;e({type:P.SelectThread,threadId:S,projectId:C,focusInput:!0})}}}catch(b){console.error("Failed to create web app:",b),e({type:P.SetCreatingProject,isCreating:!1}),e({type:P.AppendTerminalLine,line:{type:"error",content:`Failed to create web app: ${b instanceof Error?b.message:"Unknown error"}`}})}},[e,o]),u=m.useCallback(async(p,j)=>{try{const v=j||(()=>{const y=s.projects.find(E=>E.projectId===p)?.threads.map(E=>E.title)||[],S=/^thread-(\d+)$/i;let R=0;for(const E of y){const A=E.match(S);A&&(R=Math.max(R,parseInt(A[1],10)))}return`thread-${R+1}`})(),b=await io(p,j);if(!b){await o();return}const I=b.getReader(),T=new TextDecoder;let x="",C=!1,_=null,w=!0;const k=[{type:"system",content:`Creating thread "${v}"...`}];try{for(;;){const{done:N,value:y}=await I.read();if(N)break;x+=T.decode(y,{stream:!0});const S=x.split(`
17
+ `);x=S.pop()||"";for(const R of S){const E=R.trim();if(E)try{const A=JSON.parse(E);if(A.type==="progress"){if(!C&&A.threadId){C=!0,_=A.threadId,e({type:P.AddCreatingThread,projectId:p,threadId:A.threadId,title:v}),e({type:P.AddProcessingThread,threadId:A.threadId}),e({type:P.ClearTerminalOutput,threadId:_});for(const z of k)e({type:P.AppendTerminalLine,threadId:_,line:z});k.length=0}const M={type:"output",content:A.message};_?e({type:P.AppendTerminalLine,threadId:_,line:M}):k.push(M)}else if(A.type==="error"){C&&_&&(e({type:P.RemoveCreatingThread,projectId:p,threadId:_}),e({type:P.RemoveProcessingThread,threadId:_}));const M={type:"error",content:`Error: ${A.message}`};_?e({type:P.AppendTerminalLine,threadId:_,line:M}):k.push(M),console.error("Thread creation error:",A.message),t({title:"Thread Creation Failed",description:A.message,variant:"destructive"}),w=!1}}catch(A){console.error("Failed to parse thread event",A)}}}C&&_&&e({type:P.RemoveProcessingThread,threadId:_}),await o(),_&&w&&e({type:P.SelectThread,threadId:_,projectId:p,focusInput:!0})}catch(N){C&&_&&(e({type:P.RemoveCreatingThread,projectId:p,threadId:_}),e({type:P.RemoveProcessingThread,threadId:_}));const y=N instanceof Error?N.message:String(N);throw t({title:"Thread Creation Failed",description:y,variant:"destructive"}),N}}catch(v){console.error("Failed to create thread:",v);const b=`Failed to create thread: ${v instanceof Error?v.message:"Unknown error"}`;throw e({type:P.AppendTerminalLine,line:{type:"error",content:b}}),t({variant:"destructive",title:"Thread Creation Failed",description:b}),v}},[o,e,s.projects,t]),f=m.useCallback(async(p,j)=>{e({type:P.AddDeletingThread,threadId:j});try{await co(p,j),await o(),s.selectedThreadId===j&&e({type:P.SelectThread,threadId:"",projectId:""})}catch(v){console.error("Failed to delete thread:",v)}finally{e({type:P.RemoveDeletingThread,threadId:j})}},[o,s.selectedThreadId,e]),h=m.useCallback(async p=>{e({type:P.AddDeletingProject,projectId:p});const v=s.projects.find(b=>b.projectId===p)?.threads.map(b=>b.threadId)||[];for(const b of v)e({type:P.AddDeletingThread,threadId:b});try{await oo(p),await o(),s.selectedProjectId===p&&e({type:P.SelectThread,threadId:"",projectId:""})}catch(b){console.error("Failed to delete project:",b)}finally{e({type:P.RemoveDeletingProject,projectId:p});for(const b of v)e({type:P.RemoveDeletingThread,threadId:b})}},[o,s.selectedProjectId,s.projects,e]),g=m.useCallback(async p=>{const j=a;if(l(null),!(!j||!p))try{e({type:P.SetCreatingProject,isCreating:!0}),e({type:P.AppendTerminalLine,line:{type:"system",content:`Running setup script: ${j.command}`}});const v=await Zr(j.projectId,j.command,!0);if(v){const b=v.getReader(),I=new TextDecoder;let T="";for(;;){const{done:x,value:C}=await b.read();if(x)break;T+=I.decode(C,{stream:!0});const _=T.split(`
18
+ `);T=_.pop()||"";for(const w of _)if(w.trim())try{const k=JSON.parse(w);typeof k=="string"?e({type:P.AppendTerminalLine,line:{type:"output",content:k}}):k.type==="error"&&e({type:P.AppendTerminalLine,line:{type:"error",content:k.message}})}catch{e({type:P.AppendTerminalLine,line:{type:"output",content:w}})}}if(T.trim())try{const x=JSON.parse(T);typeof x=="string"?e({type:P.AppendTerminalLine,line:{type:"output",content:x}}):x.type==="error"&&e({type:P.AppendTerminalLine,line:{type:"error",content:x.message}})}catch{e({type:P.AppendTerminalLine,line:{type:"output",content:T}})}}e({type:P.SetCreatingProject,isCreating:!1}),await o()}catch(v){e({type:P.SetCreatingProject,isCreating:!1}),console.error("Failed to run setup script:",v),e({type:P.AppendTerminalLine,line:{type:"error",content:`Failed to run setup script: ${v instanceof Error?v.message:"Unknown error"}`}})}},[a,e,o]);return m.useEffect(()=>{let p=!0;async function j(){try{const v=await ws();if(!p)return;if(e({type:P.SetProjects,projects:v.projects}),!s.selectedThreadId)for(const b of v.projects){const I=b.threads.find(T=>T.isSelected);if(I){e({type:P.SelectThread,threadId:I.threadId,projectId:b.projectId});break}}}catch(v){console.error("Failed to load projects:",v)}}return j(),()=>{p=!1}},[e,s.selectedThreadId,s.configUpdatedAt]),{projects:s.projects,selectedProjectId:s.selectedProjectId,selectedThreadId:s.selectedThreadId,refreshProjects:o,handleSelectThread:i,handleCreateProject:c,handleCreateWebApp:d,handleCreateThread:u,handleDeleteThread:f,confirmDeleteProject:h,pendingSetupScriptConfirmation:a,resolveSetupScriptConfirmation:g}}function Cd(){const s=F.c(2),[e,t]=m.useState(Td);let r,a;return s[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{const l=()=>t(!0),o=()=>t(!1);return window.addEventListener("focus",l),window.addEventListener("blur",o),()=>{window.removeEventListener("focus",l),window.removeEventListener("blur",o)}},a=[],s[0]=r,s[1]=a):(r=s[0],a=s[1]),m.useEffect(r,a),e}function Td(){return document.hasFocus()}let Ss=null;function Id(){Ss||(Ss=new Audio("/pop.wav")),Ss.currentTime=0,Ss.play().catch(s=>{console.debug("Could not play completion sound:",s)})}function kd(){const{state:s,dispatch:e}=Ce(),t=Cd(),r=m.useRef(null),a=m.useRef(!1),l=m.useRef([]),o=m.useRef(s),i=m.useRef(t);m.useEffect(()=>{o.current=s},[s]),m.useEffect(()=>{i.current=t},[t]);const c=m.useCallback(async()=>{try{const u=await ro(),f=l.current.filter(h=>!u.includes(h));for(const h of f)h!==o.current.selectedThreadId&&e({type:P.MarkThreadCompleted,threadId:h});return f.length>0&&!i.current&&Id(),l.current=u,e({type:P.SetProcessingThreads,threadIds:u}),u}catch(u){return console.error("Failed to fetch processing threads:",u),[]}},[e]);m.useEffect(()=>{const u=()=>{if(r.current||a.current)return;a.current=!0;const h=async()=>{(await c()).length>0||o.current.isStreaming||o.current.isCreatingProject?r.current=setTimeout(h,1e3):(r.current=null,a.current=!1)};h()},f=()=>{r.current&&(clearTimeout(r.current),r.current=null),a.current=!1};return(s.isStreaming||s.isCreatingProject||s.processingThreadIds.length>0)&&u(),()=>{f()}},[s.isStreaming,s.isCreatingProject,s.processingThreadIds.length,c]),m.useEffect(()=>{(s.isStreaming||s.isCreatingProject)&&c()},[s.isStreaming,s.isCreatingProject,c]);const d=m.useCallback(u=>{e({type:P.ClearThreadCompleted,threadId:u})},[e]);return{processingThreadIds:s.processingThreadIds,completedThreadIds:s.completedThreadIds,isThreadProcessing:u=>s.processingThreadIds.includes(u),isThreadCompleted:u=>s.completedThreadIds.includes(u),clearCompleted:d}}const Ks=768;function Rd(){const s=F.c(2),[e,t]=m.useState(void 0);let r,a;return s[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{const l=window.matchMedia(`(max-width: ${Ks-1}px)`),o=()=>{t(window.innerWidth<Ks)};return l.addEventListener("change",o),t(window.innerWidth<Ks),()=>l.removeEventListener("change",o)},a=[],s[0]=r,s[1]=a):(r=s[0],a=s[1]),m.useEffect(r,a),!!e}function Ed(){const{state:s,dispatch:e}=Ce(),t=Rd(),{projects:r,handleSelectThread:a,handleCreateProject:l,handleCreateWebApp:o,handleCreateThread:i,handleDeleteThread:c,confirmDeleteProject:d,refreshProjects:u,pendingSetupScriptConfirmation:f,resolveSetupScriptConfirmation:h}=Sd(),{processingThreadIds:g,completedThreadIds:p,clearCompleted:j}=kd(),[v,b]=m.useState(!1),[I,T]=m.useState(!1),[x,C]=m.useState(!1),[_,w]=m.useState(!1),[k,N]=m.useState(null),[y,S]=m.useState(null),R=m.useRef(null);m.useEffect(()=>{_||(async()=>{try{(await Ho()).onboardingCompleted||C(!0)}catch($){console.error("Failed to check onboarding status:",$)}finally{w(!0)}})()},[_]),m.useEffect(()=>{I||e({type:P.ConfigUpdated})},[I,e]),m.useEffect(()=>{x||e({type:P.ConfigUpdated})},[x,e]);const E=m.useCallback(L=>{const $=r.find(q=>q.projectId===L);$&&N({id:$.projectId,name:_s($)})},[r]),A=m.useCallback(L=>{i(L,"")},[i]),M=m.useCallback(L=>{const $=r.find(q=>q.projectId===L);$&&S({id:$.projectId,name:_s($),setupScript:$.setupScript,runCommand:$.runCommand})},[r]),z=m.useCallback(L=>{e({type:P.OpenHistoryView,initialFilter:L})},[e]),O=m.useCallback(async(L,$)=>{j($),await a(L,$),t&&s.sidebarOpen&&e({type:P.ToggleSidebar})},[a,t,s.sidebarOpen,e,j]);return m.useEffect(()=>{s.sidebarOpen?R.current?.expand():R.current?.collapse()},[s.sidebarOpen]),n.jsxs(we,{delayDuration:200,children:[n.jsxs(gd,{direction:"horizontal",className:"h-screen bg-background",children:[n.jsx($n,{ref:R,defaultSize:t?100:20,minSize:t?50:12,maxSize:t?100:32,collapsible:!0,collapsedSize:0,className:"border-r border-border",children:n.jsx("div",{className:"h-full overflow-hidden",children:n.jsx(Kl,{projects:r,selectedThreadId:s.selectedThreadId,processingThreadIds:g,completedThreadIds:p,deletingThreadIds:s.deletingThreadIds,deletingProjectIds:s.deletingProjectIds,onSelectThread:O,onCreateProject:()=>b(!0),onCreateThread:A,onDeleteThread:c,onDeleteProject:E,onOpenConfiguration:()=>T(!0),onProjectSettings:M,onViewHistory:z,onCollapseSidebar:()=>e({type:P.ToggleSidebar}),isMobile:t})})}),!t&&n.jsx(xd,{withHandle:!0}),n.jsx($n,{minSize:40,className:`overflow-hidden ${t&&s.sidebarOpen?"hidden":""}`,children:n.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[n.jsx(Xc,{}),n.jsx("main",{className:"flex-1 overflow-hidden",children:n.jsx(jc,{onCreateThread:A})})]})}),n.jsx(ia,{open:v,onOpenChange:b,onSubmitClone:l,onSubmitWebApp:o}),n.jsx(ed,{open:k!==null,projectName:k?.name,onOpenChange:L=>!L&&N(null),onConfirm:()=>{k&&(d(k.id),N(null))}}),n.jsx(td,{open:y!==null,onOpenChange:L=>!L&&S(null),projectId:y?.id??"",onRefresh:u}),n.jsx(sd,{open:f!==null,suggestedCommand:f?.command??null,onConfirm:h}),n.jsx(ad,{open:I,onOpenChange:T,onRestartOnboarding:async()=>{try{await zo(),T(!1),C(!0)}catch(L){console.error("Failed to restart onboarding:",L)}}}),n.jsx(cd,{open:x,onOpenChange:C,onComplete:()=>{w(!0),u()}}),n.jsx(pd,{}),n.jsx(fd,{isOpen:s.historyView.isOpen,onClose:()=>e({type:P.CloseHistoryView}),initialFilter:s.historyView.initialFilter,projects:r})]}),n.jsx(vd,{})]})}function _d(){const s=F.c(5),[e,t]=m.useReducer(Gl,Br);let r;s[0]!==e?(r={state:e,dispatch:t},s[0]=e,s[1]=r):r=s[1];let a;s[2]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx(Ed,{}),s[2]=a):a=s[2];let l;return s[3]!==r?(l=n.jsx(wd,{attribute:"class",defaultTheme:"system",enableSystem:!0,storageKey:"tarsk-theme",children:n.jsx(qr.Provider,{value:r,children:a})}),s[3]=r,s[4]=l):l=s[4],l}Dl.createRoot(document.getElementById("root")).render(n.jsx(m.StrictMode,{children:n.jsx(_d,{})}));