tarsk 0.3.39 → 0.3.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3082 -1945
- package/dist/public/assets/index-C8DaiKKI.css +1 -0
- package/dist/public/assets/index-DJSuepMX.js +18 -0
- package/dist/public/assets/monaco-w6PwaWGP.js +11 -0
- package/dist/public/assets/radix-ui-e1yigncZ.js +1 -0
- package/dist/public/assets/react-vendor-Dj_SFteF.js +59 -0
- package/dist/public/assets/ui-styling-CyCIFleB.js +1 -0
- package/dist/public/assets/utils-DJ3F8oDs.js +1 -0
- package/dist/public/index.html +7 -2
- package/package.json +5 -4
- package/dist/public/assets/index-C85yPisA.js +0 -86
- package/dist/public/assets/index-CfhNkIT6.css +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import{r as c,c as F,j as r,S as Jn,R as yr,a as br,b as Qn,V as Yn,C as Xn,d as Zn,e as ea,f as ta,g as vr,P as sa,h as ra,T as na,i as aa,M as la,k as Nr,l as ds,m as oa,L as Te,n as Ms,o as Ds,p as Gt,F as ia,G as Gs,q as et,s as ls,Z as wr,t as As,X as tt,u as tr,v as Sr,w as ca,x as Cr,y as da,z as ua,A as ma,B as ct,D as Tr,E as fa,H as pa,I as Ir,J as ha,K as ga,W as Is,N as Es,O as Er,Q as kr,U as xa,Y as _r,_ as ja,$ as ya,a0 as ba,a1 as va,a2 as Na,a3 as wa,a4 as Sa,a5 as Ca,a6 as Rr,a7 as Pr,a8 as Ta,a9 as Mr,aa as Dr,ab as Ar,ac as Lr,ad as Or,ae as $r,af as Fr,ag as Ia,ah as Ea,ai as ka,aj as _a,ak as Gr,al as zr,am as Ra,an as Ur,ao as Br,ap as Hr,aq as Pa,ar as Ma,as as qr,at as Da,au as Aa,av as La,aw as Oa,ax as $a,ay as Fa,az as Jt,aA as sr,aB as Ls,aC as zs,aD as Ga,aE as za,aF as Ua,aG as Wr,aH as Vr,aI as Kr,aJ as Ba,aK as Jr,aL as Ha,aM as Qr,aN as Yr,aO as Xr,aP as Zr,aQ as en,aR as qa,aS as tn,aT as sn,aU as rn,aV as Wa,aW as nn,aX as an,aY as ln,aZ as on,a_ as Va,a$ as Ka,b0 as Ja,b1 as Qa,b2 as Ya,b3 as cn,b4 as dn,b5 as un,b6 as mn,b7 as fn,b8 as Xa,b9 as rr,ba as Za,bb as el,bc as tl,bd as sl,be as pn,bf as hn,bg as gn,bh as xn,bi as jn,bj as yn,bk as rl,bl as nl}from"./react-vendor-Dj_SFteF.js";import{t as al,c as ll,a as Qt}from"./ui-styling-CyCIFleB.js";import{z as ol,J as il}from"./utils-DJ3F8oDs.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"]'))n(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"&&n(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 n(a){if(a.ep)return;a.ep=!0;const l=t(a);fetch(a.href,l)}})();function zt(s){return typeof s!="string"?"":s.replace(/\\n/g,`
|
|
2
|
+
`)}function bn(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 n=0;for(;n<e.length;){const a=e.indexOf("[",n);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 d of i)if(d&&typeof d=="object"&&"type"in d){const u=d.type;(u==="tool-result"||u==="tool_use")&&t.push(d)}}}catch{}n=o+1}return t.length>0?t:null}function nr(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 n=t.text||t.content||t.answer;if(n)return{type:"text",text:String(n)}}return e})}function ar(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 vn(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 nr(i);if(typeof i=="object"&&i!==null)return ar(i)}catch{}const n=[],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),d=Math.max(i.lastIndexOf("]"),i.lastIndexOf("}"));if(d!==-1){const u=i.substring(0,d+1);try{const m=JSON.parse(u);Array.isArray(m)?n.push(...nr(m)):n.push(...ar(m));const f=i.substring(d+1).trim();return f&&n.push({type:"text",text:f}),n}catch{}}}return null}function ks(s,e,t){const n=s[s.length-1];return n?.type===e?[...s.slice(0,-1),{type:e,chunks:[...n.chunks,t]}]:[...s,{type:e,chunks:[t]}]}function Os(s,e){return s[s.length-1]?.type==="content"?[...s.slice(0,-1),{type:"content",chunks:[e]}]:[...s,{type:"content",chunks:[e]}]}function Us(s){const e=[];for(const t of s){const n=t.chunks.join("");if(t.type==="thinking"){const a=bn(n)??[];e.push(...a)}else{const a=vn(n)??(n.trim()?[{type:"text",text:n}]:[]);e.push(...a)}}return e}function cl(s){const e=Us(s);return e.length===0?"...":e.length===1&&e[0]?.type==="text"&&"text"in e[0]?e[0].text:JSON.stringify(e)}var N=(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))(N||{});const Nn={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:{}};function dl(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=Os(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(n=>n.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,n=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...n,open:!n.open}}}}case"SET_TERMINAL_OPEN":{const t=e.threadId||"default",n=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...n,open:e.open}}}}case"QUEUE_TERMINAL_COMMAND":{const t=e.threadId,n=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...n,queuedCommand:e.command,open:!0}}}}case"CLEAR_QUEUED_TERMINAL_COMMAND":{const t=e.threadId,n=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...n,queuedCommand:null}}}}case"APPEND_TERMINAL_LINE":{const t=e.threadId||"default",n=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...n,outputLines:[...n.outputLines,e.line]}}}}case"CLEAR_TERMINAL_OUTPUT":{const t=e.threadId||"default",n=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...n,outputLines:[]}}}}case"SET_TERMINAL_HEIGHT":{const t=e.threadId,n=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...n,height:e.height}}}}case"SET_TERMINAL_CWD":{const t=e.threadId,n=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...n,cwd:e.cwd}}}}case"SET_TERMINAL_RUNNING":{const t=e.threadId,n=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...n,isRunning:e.isRunning}}}}case"SET_TERMINAL_HISTORY":{const t=e.threadId,n=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...n,history:e.history}}}}case"SET_TERMINAL_HISTORY_INDEX":{const t=e.threadId,n=s.terminalStates[t]||{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1};return{...s,terminalStates:{...s.terminalStates,[t]:{...n,historyIndex:e.index}}}}case"UPDATE_THREAD_TITLE":return{...s,projects:s.projects.map(t=>t.projectId===e.projectId?{...t,threads:t.threads.map(n=>n.threadId===e.threadId?{...n,title:e.title}:n)}: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}};default:return s}}const wn=c.createContext({state:Nn,dispatch:()=>{}});function Pe(){return c.useContext(wn)}function Yt(s){const e=F.c(11),{state:t,dispatch:n}=Pe();if(!s){let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=[],e[0]=u):u=e[0];let m;return e[1]===Symbol.for("react.memo_cache_sentinel")?(m={terminalState:{open:!1,queuedCommand:null,outputLines:u,height:300,history:[],historyIndex:-1,cwd:".",isRunning:!1},dispatch:ul},e[1]=m):m=e[1],m}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]!==n||e[6]!==s?(o=u=>{n({...u,threadId:s})},e[5]=n,e[6]=s,e[7]=o):o=e[7];const i=o;let d;return e[8]!==i||e[9]!==l?(d={terminalState:l,dispatch:i},e[8]=i,e[9]=l,e[10]=d):d=e[10],d}function ul(){}function O(...s){return al(ll(s))}function os(s){return s.name?s.name:s.gitUrl?.split("/").pop()?.replace(".git","")||s.projectId}function ml(s,e){if(!e)return"";for(const t of s){const n=t.threads.find(a=>a.threadId===e);if(n)return n.title}return""}function fl(s,e){if(!e)return"";const t=s.find(n=>n.projectId===e);return t?os(t):""}function Vt(s){return s.toFixed(2).replace(/\.00$/,"")}const Bs=Qt("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"}}),B=c.forwardRef((s,e)=>{const t=F.c(15);let n,a,l,o,i;t[0]!==s?({className:n,variant:i,size:l,asChild:o,...a}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l,t[4]=o,t[5]=i):(n=t[1],a=t[2],l=t[3],o=t[4],i=t[5]);const u=(o===void 0?!1:o)?Jn:"button";let m;t[6]!==n||t[7]!==l||t[8]!==i?(m=O(Bs({variant:i,size:l,className:n})),t[6]=n,t[7]=l,t[8]=i,t[9]=m):m=t[9];let f;return t[10]!==u||t[11]!==a||t[12]!==e||t[13]!==m?(f=r.jsx(u,{className:m,ref:e,...a}),t[10]=u,t[11]=a,t[12]=e,t[13]=m,t[14]=f):f=t[14],f});B.displayName="Button";const Qe=c.forwardRef((s,e)=>{const t=F.c(15);let n,a,l;t[0]!==s?({className:a,children:n,...l}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l):(n=t[1],a=t[2],l=t[3]);let o;t[4]!==a?(o=O("relative overflow-hidden",a),t[4]=a,t[5]=o):o=t[5];let i;t[6]!==n?(i=r.jsx(Yn,{className:"h-full w-full rounded-[inherit]",children:n}),t[6]=n,t[7]=i):i=t[7];let d,u;t[8]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx(Sn,{}),u=r.jsx(Xn,{}),t[8]=d,t[9]=u):(d=t[8],u=t[9]);let m;return t[10]!==l||t[11]!==e||t[12]!==o||t[13]!==i?(m=r.jsxs(yr,{ref:e,className:o,...l,children:[i,d,u]}),t[10]=l,t[11]=e,t[12]=o,t[13]=i,t[14]=m):m=t[14],m});Qe.displayName=yr.displayName;const Sn=c.forwardRef((s,e)=>{const t=F.c(14);let n,a,l;t[0]!==s?({className:n,orientation:l,...a}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l):(n=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]",d=o==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]";let u;t[4]!==n||t[5]!==i||t[6]!==d?(u=O("flex touch-none select-none transition-colors",i,d,n),t[4]=n,t[5]=i,t[6]=d,t[7]=u):u=t[7];let m;t[8]===Symbol.for("react.memo_cache_sentinel")?(m=r.jsx(Qn,{className:"relative flex-1 rounded-full bg-border"}),t[8]=m):m=t[8];let f;return t[9]!==o||t[10]!==a||t[11]!==e||t[12]!==u?(f=r.jsx(br,{ref:e,orientation:o,className:u,...a,children:m}),t[9]=o,t[10]=a,t[11]=e,t[12]=u,t[13]=f):f=t[13],f});Sn.displayName=br.displayName;const pl=Zn,hl=ea,gl=ta,Re=sa,xe=ra,je=na,he=c.forwardRef((s,e)=>{const t=F.c(11);let n,a,l;t[0]!==s?({className:n,sideOffset:l,...a}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l):(n=t[1],a=t[2],l=t[3]);const o=l===void 0?4:l;let i;t[4]!==n?(i=O("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",n),t[4]=n,t[5]=i):i=t[5];let d;return t[6]!==a||t[7]!==e||t[8]!==o||t[9]!==i?(d=r.jsx(vr,{ref:e,sideOffset:o,className:i,...a}),t[6]=a,t[7]=e,t[8]=o,t[9]=i,t[10]=d):d=t[10],d});he.displayName=vr.displayName;function xl(){const s=F.c(8),{theme:e,setTheme:t}=ol();let n;s[0]!==t||s[1]!==e?(n=()=>t(e==="dark"?"light":"dark"),s[0]=t,s[1]=e,s[2]=n):n=s[2];let a,l,o;s[3]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx(aa,{className:"h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),l=r.jsx(la,{className:"absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100"}),o=r.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]!==n?(i=r.jsxs(B,{variant:"ghost",size:"icon",className:"h-8 w-8 text-sidebar-foreground hover:bg-sidebar-accent",onClick:n,children:[a,l,o]}),s[6]=n,s[7]=i):i=s[7],i}function jl(s){const e=F.c(63),{projects:t,selectedThreadId:n,processingThreadIds:a,completedThreadIds:l,deletingThreadIds:o,deletingProjectIds:i,onSelectThread:d,onCreateProject:u,onCreateThread:m,onDeleteThread:f,onDeleteProject:p,onOpenConfiguration:h,onProjectSettings:x,onCollapseSidebar:j,isMobile:b,collapsed:g}=s;let R;e[0]===Symbol.for("react.memo_cache_sentinel")?(R={containerType:"inline-size"},e[0]=R):R=e[0];let I;e[1]===Symbol.for("react.memo_cache_sentinel")?(I=r.jsx("div",{className:"flex h-7 w-7 items-center justify-center overflow-hidden rounded-md border border-sidebar-border shadow-sm",children:r.jsx("img",{src:"/tarsk.svg",alt:"Tarsk",className:"h-full w-full"})}),e[1]=I):I=e[1];let w;e[2]!==g?(w=!g&&r.jsx("span",{className:"text-sm font-semibold tracking-tight",children:"Tarsk"}),e[2]=g,e[3]=w):w=e[3];let S;e[4]!==w?(S=r.jsxs("div",{className:"flex items-center gap-2",children:[I,w]}),e[4]=w,e[5]=S):S=e[5];let E;e[6]!==g||e[7]!==b||e[8]!==j?(E=!g&&b&&r.jsxs(B,{variant:"ghost",size:"icon",className:"h-7 w-7 text-sidebar-foreground hover:bg-sidebar-accent",onClick:j,children:[r.jsx(Nr,{className:"h-4 w-4"}),r.jsx("span",{className:"sr-only",children:"Collapse sidebar"})]}),e[6]=g,e[7]=b,e[8]=j,e[9]=E):E=e[9];let T;e[10]!==E?(T=r.jsx("div",{className:"flex items-center gap-1",children:E}),e[10]=E,e[11]=T):T=e[11];let k;e[12]!==S||e[13]!==T?(k=r.jsxs("div",{className:"flex items-center justify-between border-b border-sidebar-border px-4 py-3",children:[S,T]}),e[12]=S,e[13]=T,e[14]=k):k=e[14];let y;e[15]===Symbol.for("react.memo_cache_sentinel")?(y=r.jsx(ds,{className:"h-4 w-4"}),e[15]=y):y=e[15];let C;e[16]!==g?(C=!g&&r.jsx("span",{children:"New Project"}),e[16]=g,e[17]=C):C=e[17];let _;e[18]!==u||e[19]!==C?(_=r.jsx("div",{className:"border-b border-sidebar-border px-3 py-2",children:r.jsxs(B,{variant:"ghost",size:"sm",className:"w-full justify-start gap-2 text-sidebar-foreground hover:bg-sidebar-accent",onClick:u,children:[y,C]})}),e[18]=u,e[19]=C,e[20]=_):_=e[20];let D;e[21]!==t.length?(D=t.length===0&&r.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]=D):D=e[22];let P;if(e[23]!==l||e[24]!==i||e[25]!==o||e[26]!==m||e[27]!==p||e[28]!==f||e[29]!==x||e[30]!==d||e[31]!==a||e[32]!==t||e[33]!==n){let fe;e[35]!==l||e[36]!==i||e[37]!==o||e[38]!==m||e[39]!==p||e[40]!==f||e[41]!==x||e[42]!==d||e[43]!==a||e[44]!==n?(fe=(ae,ce)=>r.jsx(yl,{project:ae,selectedThreadId:n,processingThreadIds:a,completedThreadIds:l,deletingThreadIds:o,deletingProjectIds:i,onSelectThread:d,onCreateThread:m,onDeleteThread:f,onDeleteProject:p,onProjectSettings:x},ae.projectId||ae.gitUrl||`project-${ce}`),e[35]=l,e[36]=i,e[37]=o,e[38]=m,e[39]=p,e[40]=f,e[41]=x,e[42]=d,e[43]=a,e[44]=n,e[45]=fe):fe=e[45],P=t.map(fe),e[23]=l,e[24]=i,e[25]=o,e[26]=m,e[27]=p,e[28]=f,e[29]=x,e[30]=d,e[31]=a,e[32]=t,e[33]=n,e[34]=P}else P=e[34];let z;e[46]!==D||e[47]!==P?(z=r.jsx(Qe,{className:"flex-1",children:r.jsxs("div",{className:"px-2 py-2",children:[D,P]})}),e[46]=D,e[47]=P,e[48]=z):z=e[48];let L;e[49]===Symbol.for("react.memo_cache_sentinel")?(L=r.jsx(oa,{className:"h-4 w-4"}),e[49]=L):L=e[49];let W;e[50]!==g?(W=!g&&r.jsx("span",{children:"Settings"}),e[50]=g,e[51]=W):W=e[51];let G;e[52]!==h||e[53]!==W?(G=r.jsxs(B,{variant:"ghost",size:"sm",className:"flex-1 justify-start gap-2 text-sidebar-foreground hover:bg-sidebar-accent",onClick:h,children:[L,W]}),e[52]=h,e[53]=W,e[54]=G):G=e[54];let U;e[55]===Symbol.for("react.memo_cache_sentinel")?(U=r.jsx(xl,{}),e[55]=U):U=e[55];let q;e[56]!==G?(q=r.jsxs("div",{className:"border-t border-sidebar-border px-3 py-2 flex items-center gap-1",children:[G,U]}),e[56]=G,e[57]=q):q=e[57];let le;return e[58]!==_||e[59]!==z||e[60]!==q||e[61]!==k?(le=r.jsxs("div",{className:"flex h-full flex-col bg-sidebar text-sidebar-foreground",style:R,children:[k,_,z,q]}),e[58]=_,e[59]=z,e[60]=q,e[61]=k,e[62]=le):le=e[62],le}function yl(s){const e=F.c(77),{project:t,selectedThreadId:n,processingThreadIds:a,completedThreadIds:l,deletingThreadIds:o,deletingProjectIds:i,onSelectThread:d,onCreateThread:u,onDeleteThread:m,onDeleteProject:f,onProjectSettings:p}=s,[h,x]=c.useState(!0);let j;e[0]!==i||e[1]!==t.projectId?(j=i.includes(t.projectId),e[0]=i,e[1]=t.projectId,e[2]=j):j=e[2];const b=j;let g;e[3]!==t?(g=os(t),e[3]=t,e[4]=g):g=e[4];const R=g,I=`${R} - `;let w,S,E,T,k,y,C,_,D;if(e[5]!==h||e[6]!==t.threads||e[7]!==n){let ee;e[17]!==n?(ee=ie=>ie.threadId===n,e[17]=n,e[18]=ee):ee=e[18];const ne=t.threads.some(ee);S=pl,C=h,_=x,D="mb-1",y="group flex min-w-0 items-center",w=hl,k=!0,E="button",T=O("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",ne&&"text-sidebar-foreground font-medium"),e[5]=h,e[6]=t.threads,e[7]=n,e[8]=w,e[9]=S,e[10]=E,e[11]=T,e[12]=k,e[13]=y,e[14]=C,e[15]=_,e[16]=D}else w=e[8],S=e[9],E=e[10],T=e[11],k=e[12],y=e[13],C=e[14],_=e[15],D=e[16];const P=h&&"rotate-90";let z;e[19]!==P?(z=O("h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform",P),e[19]=P,e[20]=z):z=e[20];let L;e[21]!==z?(L=r.jsx(Gt,{className:z}),e[21]=z,e[22]=L):L=e[22];let W;e[23]===Symbol.for("react.memo_cache_sentinel")?(W=r.jsx(ia,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e[23]=W):W=e[23];let G;e[24]!==R?(G=r.jsx("span",{className:"min-w-0 truncate",children:R}),e[24]=R,e[25]=G):G=e[25];let U;e[26]!==L||e[27]!==G||e[28]!==E||e[29]!==T?(U=r.jsxs("button",{type:E,className:T,children:[L,W,G]}),e[26]=L,e[27]=G,e[28]=E,e[29]=T,e[30]=U):U=e[30];let q;e[31]!==w||e[32]!==U||e[33]!==k?(q=r.jsx(w,{asChild:k,children:U}),e[31]=w,e[32]=U,e[33]=k,e[34]=q):q=e[34];let le;e[35]!==b||e[36]!==u||e[37]!==f||e[38]!==p||e[39]!==t.projectId||e[40]!==t.threads.length?(le=r.jsx("div",{className:"flex shrink-0 items-center",children:b?r.jsx(Te,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground mr-1"}):r.jsxs(Re,{children:[r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsxs(B,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 group-hover:opacity-100",onClick:()=>p(t.projectId),children:[r.jsx(Ms,{className:"h-3 w-3"}),r.jsx("span",{className:"sr-only",children:"Project settings"})]})}),r.jsx(he,{side:"right",children:"Project settings"})]}),r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsxs(B,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 group-hover:opacity-100",onClick:()=>u(t.projectId),children:[r.jsx(ds,{className:"h-3 w-3"}),r.jsx("span",{className:"sr-only",children:"Add thread"})]})}),r.jsx(he,{side:"right",children:"Add thread"})]}),t.threads.length===0&&r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsxs(B,{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:[r.jsx(Ds,{className:"h-3 w-3"}),r.jsx("span",{className:"sr-only",children:"Delete project"})]})}),r.jsx(he,{side:"right",children:"Delete project"})]})]})}),e[35]=b,e[36]=u,e[37]=f,e[38]=p,e[39]=t.projectId,e[40]=t.threads.length,e[41]=le):le=e[41];let fe;e[42]!==q||e[43]!==le||e[44]!==y?(fe=r.jsxs("div",{className:y,children:[q,le]}),e[42]=q,e[43]=le,e[44]=y,e[45]=fe):fe=e[45];let ae;if(e[46]!==l||e[47]!==o||e[48]!==m||e[49]!==d||e[50]!==a||e[51]!==t.projectId||e[52]!==t.threads||e[53]!==I||e[54]!==n){let ee;e[56]!==l||e[57]!==o||e[58]!==m||e[59]!==d||e[60]!==a||e[61]!==t.projectId||e[62]!==I||e[63]!==n?(ee=(ne,ie)=>{const Ie=a.includes(ne.threadId),pe=o.includes(ne.threadId),ue=l.includes(ne.threadId);return r.jsxs("div",{className:O("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",ne.threadId===n&&"bg-sidebar-accent text-sidebar-accent-foreground font-medium"),onClick:()=>d(t.projectId,ne.threadId),onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&d(t.projectId,ne.threadId)},role:"button",tabIndex:0,children:[r.jsx(Gs,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),r.jsx("span",{className:"min-w-0 text-xs",style:{display:"block",textOverflow:"ellipsis"},children:ne.title?.startsWith(I)?ne.title.slice(I.length):ne.title||ne.threadId}),Ie||pe?r.jsx(Te,{className:"ml-auto h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):ue?r.jsx(et,{className:"ml-auto h-3 w-3 shrink-0 text-green-500"}):r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsxs(B,{variant:"ghost",size:"icon",className:"ml-auto h-5 w-5 shrink-0 opacity-0 group-hover/thread:opacity-100 text-muted-foreground hover:text-destructive",onClick:v=>{v.stopPropagation(),m(t.projectId,ne.threadId)},children:[r.jsx(Ds,{className:"h-3 w-3"}),r.jsx("span",{className:"sr-only",children:"Delete thread"})]})}),r.jsx(he,{side:"right",children:"Delete thread and files from the repo"})]})]},ne.threadId||`${t.projectId}-${ne.title||ie}`)},e[56]=l,e[57]=o,e[58]=m,e[59]=d,e[60]=a,e[61]=t.projectId,e[62]=I,e[63]=n,e[64]=ee):ee=e[64],ae=t.threads.map(ee),e[46]=l,e[47]=o,e[48]=m,e[49]=d,e[50]=a,e[51]=t.projectId,e[52]=t.threads,e[53]=I,e[54]=n,e[55]=ae}else ae=e[55];let ce;e[65]!==t.threads.length?(ce=t.threads.length===0&&r.jsx("p",{className:"px-2 py-1 text-xs text-muted-foreground",children:"No threads"}),e[65]=t.threads.length,e[66]=ce):ce=e[66];let V;e[67]!==ae||e[68]!==ce?(V=r.jsx(gl,{children:r.jsxs("div",{className:"ml-4 border-l border-sidebar-border pl-2",children:[ae,ce]})}),e[67]=ae,e[68]=ce,e[69]=V):V=e[69];let se;return e[70]!==S||e[71]!==fe||e[72]!==V||e[73]!==C||e[74]!==_||e[75]!==D?(se=r.jsxs(S,{open:C,onOpenChange:_,className:D,children:[fe,V]}),e[70]=S,e[71]=fe,e[72]=V,e[73]=C,e[74]=_,e[75]=D,e[76]=se):se=e[76],se}const qt=[{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 jt(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(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):s}function Ut(s){return typeof localStorage>"u"?null:localStorage.getItem(s)}function Bt(s,e){typeof localStorage>"u"||localStorage.setItem(s,e)}function bl(s){return typeof sessionStorage>"u"?null:sessionStorage.getItem(s)}function vl(s,e){typeof sessionStorage>"u"||sessionStorage.setItem(s,e)}function Nl(s="npm"){return Ut("tarsk.create-project.packageManager")||s}function wl(s){Bt("tarsk.create-project.packageManager",s)}function Sl(s="pull-request"){return Ut("tarsk.create-project.commitMethod")||s}function lr(s){Bt("tarsk.create-project.commitMethod",s)}function Cl(s=""){return Ut("tarsk.create-project.templateId")||s}function Tl(s){Bt("tarsk.create-project.templateId",s)}function or(s=!1){const e=Ut("autoGenerateCommitMessage");return e!==null?e==="true":s}function Il(s){Bt("autoGenerateCommitMessage",s.toString())}function ir(s=!1){const e=Ut("privateRepositoryDefault");return e!==null?e==="true":s}function El(s){Bt("privateRepositoryDefault",s.toString())}function cr(s){const e="selected-model-"+s;return Ut(e)}function dr(s,e){const t="selected-model-"+s;Bt(t,e)}function Cn(){const s=bl("chat_message_history");return s?JSON.parse(s):[]}function kl(s){const e=Cn();s.trim()&&e[e.length-1]!==s&&(e.push(s),vl("chat_message_history",JSON.stringify(e)))}const _l=s=>{kl(s)},Tn=["462","8100"].includes(document.location.port)?"http://localhost:462":"http://localhost:641";function ur(){return Tn}function dt(s){const e=s.startsWith("/")?s:`/${s}`;return`${Tn}${e}`}async function ut(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 In(s,e,t){const n=new Error(s);return t?.error&&typeof t.error=="object"&&(n.details=t.error.details,n.code=t.error.code),n}async function we(s,e){const t=await fetch(dt(s),{...e,method:"GET"});if(!t.ok){const n=await ut(t);throw new Error(n)}return t.json()}async function Me(s,e,t){const n=await fetch(dt(s),{...t,method:"POST",headers:{"Content-Type":"application/json",...t?.headers},body:e?JSON.stringify(e):void 0});if(!n.ok){const a=await ut(n);throw new Error(a)}return n.json()}async function Rl(s,e,t){const n=await fetch(dt(s),{...t,method:"PATCH",headers:{"Content-Type":"application/json",...t?.headers},body:e?JSON.stringify(e):void 0});if(!n.ok){const a=await ut(n);throw new Error(a)}return n.json()}async function Pl(s,e,t){const n=await fetch(dt(s),{...t,method:"PUT",headers:{"Content-Type":"application/json",...t?.headers},body:e?JSON.stringify(e):void 0});if(!n.ok){const a=await ut(n);throw new Error(a)}return n.body}async function us(s,e){const t=await fetch(dt(s),{...e,method:"DELETE"});if(!t.ok){const n=await ut(t);throw new Error(n)}if(t.status!==204)return t.json()}async function Ht(s,e,t){const n=await fetch(dt(s),{...t,method:"POST",headers:{"Content-Type":"application/json",...t?.headers},body:e?JSON.stringify(e):void 0});if(!n.ok){const a=await ut(n);throw new Error(a)}return n.body}async function En(s,e,t){const n=await fetch(dt(s),{...t,method:"POST",headers:{"Content-Type":"application/json",...t?.headers},body:e?JSON.stringify(e):void 0});if(!n.ok){let a;try{a=await n.json()}catch{}const l=await ut(n);throw In(l,n,a)}return n.json()}async function Ml(s,e,t){const n=await fetch(dt(s),{...t,method:"PUT",headers:{"Content-Type":"application/json",...t?.headers},body:e?JSON.stringify(e):void 0});if(!n.ok){let a;try{a=await n.json()}catch{}const l=await ut(n);throw In(l,n,a)}return n.json()}function oe(...s){return s.map(e=>encodeURIComponent(String(e))).join("/")}async function Dl(){return we("api/scaffold/templates")}async function Al(s,e,t){return Ht("api/scaffold",{projectName:s,templateId:e,packageManager:t})}async function Hs(){return we("api/providers")}async function Ll(s){return we(`api/providers/${oe(s)}/credits`)}async function Ol(s,e){await Me("api/providers/keys",{providerName:s,apiKey:e})}async function $l(s){await Me("api/providers/bulk-keys",{keys:s})}async function Fl(){return(await we("api/programs")).programs||[]}async function Gl(){return(await we("api/threads/processing")).processingThreadIds||[]}async function zl(){try{return(await we("api/git/username")).name||""}catch{return""}}async function es(){const e=(await we("api/projects")||[]).map(n=>{const a=n;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 n=>{try{const l=(await we(`api/threads?projectId=${encodeURIComponent(String(n.projectId))}`)||[]).map(o=>{const i=o,d=i.threadId??i.id;return{threadId:d,title:i.title||d,path:i.path||"",currentBranch:i.currentBranch||"",isSelected:!!i.isSelected}});return{...n,threads:l}}catch{return{...n,threads:(n.threads||[]).map(a=>({threadId:a,title:a,path:"",currentBranch:"",isSelected:!1}))}}}))}}async function Ul(s,e){return Ht("api/projects",{gitUrl:s,commitMethod:e})}async function Bl(s){return we(`api/projects/${oe(s)}`)}async function Hl(s){await us(`api/projects/${oe(s)}`)}async function ql(s,e){return Ht("api/threads",{projectId:s,title:e})}async function Wl(s,e){await us(`api/threads/${oe(e)}`)}async function Vl(s,e){await Rl(`api/threads/${oe(s)}`,e)}async function Kl(s,e){await Me(`api/threads/${oe(e)}/select`)}async function Jl(s){const e=await we(`api/threads/${oe(s)}/messages`);return{threadId:s,messages:e}}async function Ql(s){return(await we(`api/threads/${oe(s)}/conversation-folder-path`)).path}async function Yl(s,e,t,n=[],a,l){const o={threadId:s,content:e,model:t,provider:l,attachments:n.map(i=>({name:i.fileName,content:i.content.split(",")[1]||i.content,size:0,mimeType:"application/octet-stream"}))};return Ht("api/chat",o,{signal:a})}async function Xl(s){return(await us(`api/chat/${oe(s)}`))?.conversationId||""}function Zl(s,e,t,n,a){const l=s.getReader();let o=!1;const i=()=>{o=!0,l.cancel().catch(()=>{})},d=new TextDecoder;let u="";const m=p=>p?[/^Cannot read properties/i,/^Error:/i,/^TypeError:/i,/^ReferenceError:/i,/^SyntaxError:/i,/^failed to/i,/^error:/i,/forbidden/i,/unauthorized/i].some(x=>x.test(p.trim())):!1;async function f(){try{for(;!o;){const{done:p,value:h}=await l.read();if(p||o){if(!o&&p){if(u.trim())try{const j=JSON.parse(u);j.type==="error"?n(j.content||"Unknown error"):j.type==="message"?a?.({role:j.role||"assistant",content:j.content||""}):j.type==="complete"||(j.type==="result"&&m(j.content)?n(j.content||"Unknown error"):e(j))}catch{u.trim()&&e({type:"result",content:u})}t()}break}u+=d.decode(h,{stream:!0});const x=u.split(`
|
|
3
|
+
`);u=x.pop()||"";for(const j of x){const b=j.trim();if(b)try{const g=JSON.parse(b);if(g.type==="error"){n(g.content||"Unknown error"),t();return}else if(g.type==="message")a?.({role:g.role||"assistant",content:g.content||""});else if(g.type==="complete"){t();return}else if(g.type==="result"&&m(g.content)){n(g.content||"Unknown error"),t();return}else e(g)}catch{}}}}catch(p){n(p instanceof Error?p.message:"Stream error")}}return f(),i}async function Xt(s,e){return e.runNow&&e.setupScript?Pl(`api/projects/${oe(s)}`,e):(await Ml(`api/projects/${oe(s)}`,e),null)}async function eo(s,e){await En(`api/projects/${oe(s)}/open`,{program:e})}async function to(s,e){await En(`api/threads/${oe(s)}/open`,{program:e})}async function so(s,e){await Xt(s,{program:e})}async function kn(s,e,t){return Xt(s,{setupScript:e,runNow:t})}async function ro(s,e){await Xt(s,{name:e})}async function qs(s,e){const t=new URLSearchParams({provider:s});return((await we(`api/models?${t.toString()}`)).models||[]).filter(l=>{const o=l.name.toLowerCase().trim(),i=jt(l.id).toLowerCase().trim();return o!=="free"&&o!=="auto"&&i!=="free"&&i!=="auto"})}async function _n(s,e){await Me(`api/models/${oe(s,e)}/enable`)}async function no(s,e){await Me(`api/models/${oe(s,e)}/disable`)}async function is(){const e=(await we("api/models/enabled")).enabledModels||{},t={};for(const[n,a]of Object.entries(e))t[n]=a.filter(l=>{const o=l.name.toLowerCase().trim(),i=jt(l.id).toLowerCase().trim();return o!=="free"&&o!=="auto"&&i!=="free"&&i!=="auto"});return t}async function ao(s){return we(`api/git/status/${oe(s)}`)}async function mr(s,e,t){return(await Me(`api/git/generate-commit-message/${oe(s)}`,{model:e,provider:t})).message}async function lo(s,e){await Me(`api/git/commit/${oe(s)}`,{message:e})}async function fr(s){await Me(`api/git/push/${oe(s)}`)}async function oo(s,e,t){return Me(`api/git/generate-pr-info/${oe(s)}`,{model:e,provider:t})}async function pr(s,e,t){return Me(`api/git/create-pr/${oe(s)}`,{title:e,description:t})}async function io(s){await Me(`api/git/fetch/${oe(s)}`)}async function co(s,e=50){return(await we(`api/git/log/${oe(s)}?limit=${e}`)).commits}async function uo(s){return we(`api/git/github-status/${oe(s)}`)}async function mo(s,e,t,n){return Me(`api/git/create-repo/${oe(s)}`,{repoName:e,description:t,isPrivate:n})}async function fo(s,e){await Me(`api/projects/${oe(s)}/commands`,e)}async function po(s,e){await us(`api/projects/${oe(s)}/commands/${oe(e)}`)}async function ho(s,e,t,n){return Ht(`api/projects/${oe(s)}/threads/${oe(e)}/commands/run`,{commandLine:t,cwd:n})}async function go(s){return we(`api/threads/${oe(s)}/files`)}async function xo(s){return Me(`api/projects/${oe(s)}/run-suggest`,{})}async function jo(s){return Ht(`api/projects/${oe(s)}/run`,{})}async function yo(s){return Me(`api/projects/${oe(s)}/stop`,{})}async function bo(s){return we(`api/projects/${oe(s)}/running`)}async function vo(s,e){await Xt(s,{runCommand:e})}async function No(s){return we(`api/git/diff/${oe(s)}`)}async function wo(){return we("api/onboarding/status")}async function So(){return we("api/onboarding/git-check")}async function hr(){return Me("api/onboarding/complete",{})}async function Co(){return Me("api/onboarding/reset",{})}async function To(s){const e=await we(`api/slash-commands?threadId=${oe(s)}`);return{commands:e.commands||[],skills:e.skills||[]}}const Io=()=>{if(typeof window>"u")return null;const s=window.SpeechRecognition||window.webkitSpeechRecognition;return s?new s:null};function Eo(){const s=F.c(14),[e,t]=c.useState(!1),[n,a]=c.useState(""),[l,o]=c.useState(null),[i,d]=c.useState(!1),u=c.useRef(null),m=c.useRef("");let f,p;s[0]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{try{const w=Io();w?(w.continuous=!0,w.interimResults=!0,w.lang="en-US",w.onstart=()=>{t(!0),o(null),m.current=""},w.onresult=S=>{let E="";for(let T=S.resultIndex;T<S.results.length;T++){const k=S.results[T][0].transcript;S.results[T].isFinal?a(y=>y+k+" "):E=E+k}m.current=E},w.onerror=S=>{console.error("Speech recognition error:",S.error),o(S.error||"An error occurred during speech recognition")},w.onend=()=>{t(!1)},u.current=w,d(!0)):(d(!1),o("Speech Recognition API is not supported in your browser"))}catch(w){console.error("Failed to initialize speech recognition:",w),d(!1),o("Failed to initialize speech recognition")}return()=>{u.current&&u.current.abort()}},p=[],s[0]=f,s[1]=p):(f=s[0],p=s[1]),c.useEffect(f,p);let h;s[2]!==e?(h=()=>{u.current&&!e&&u.current.start()},s[2]=e,s[3]=h):h=s[3];const x=h;let j;s[4]!==e?(j=()=>{u.current&&e&&u.current.stop()},s[4]=e,s[5]=j):j=s[5];const b=j;let g;s[6]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{a(""),m.current=""},s[6]=g):g=s[6];const R=g;let I;return s[7]!==l||s[8]!==e||s[9]!==i||s[10]!==x||s[11]!==b||s[12]!==n?(I={isListening:e,transcript:n,error:l,startListening:x,stopListening:b,resetTranscript:R,isSupported:i},s[7]=l,s[8]=e,s[9]=i,s[10]=x,s[11]=b,s[12]=n,s[13]=I):I=s[13],I}function ko(s){const e=F.c(21),{visible:t,commands:n,skills:a,query:l,selectedIndex:o,onSelectCommand:i,onSelectSkill:d,onMouseEnterSuggestion:u,containerRef:m}=s;if(!t)return null;let f;if(e[0]!==n||e[1]!==l||e[2]!==a){let R;e[4]!==l?(R=E=>E.name.toLowerCase().includes(l.toLowerCase()),e[4]=l,e[5]=R):R=e[5];const I=n.filter(R);let w;e[6]!==l?(w=E=>E.name.toLowerCase().includes(l.toLowerCase()),e[6]=l,e[7]=w):w=e[7];const S=a.filter(w);f=[...I.map(Ro),...S.map(_o)].slice(0,10),e[0]=n,e[1]=l,e[2]=a,e[3]=f}else f=e[3];const p=f;let h;e[8]===Symbol.for("react.memo_cache_sentinel")?(h=r.jsx(ls,{className:"h-3 w-3"}),e[8]=h):h=e[8];const x=l&&` matching "${l}"`;let j;e[9]!==x?(j=r.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:[h,"Commands & Skills",x]}),e[9]=x,e[10]=j):j=e[10];let b;e[11]!==p||e[12]!==u||e[13]!==i||e[14]!==d||e[15]!==o?(b=p.length>0?p.map((R,I)=>{const w=I===o;if(R.type==="command"){const S=R.data;return r.jsxs("button",{type:"button",className:O("flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors",w?"bg-accent text-accent-foreground":"text-popover-foreground hover:bg-accent/50"),onClick:()=>i(S),onMouseEnter:()=>u(I),children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ls,{className:"h-3 w-3 text-muted-foreground"}),r.jsxs("span",{className:"font-medium",children:["/",S.name]}),S.metadata.argumentHint&&r.jsx("span",{className:"text-xs text-muted-foreground",children:S.metadata.argumentHint}),S.scope==="project"&&r.jsx("span",{className:"ml-auto text-[10px] rounded-full bg-primary/10 px-1.5 py-0.5 text-primary",children:"project"})]}),S.metadata.description&&r.jsx("span",{className:"text-xs text-muted-foreground",children:S.metadata.description})]},`cmd-${S.name}`)}else{const S=R.data;return r.jsxs("button",{type:"button",className:O("flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors",w?"bg-accent text-accent-foreground":"text-popover-foreground hover:bg-accent/50"),onClick:()=>d(S),onMouseEnter:()=>u(I),children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(wr,{className:"h-3 w-3 text-amber-500"}),r.jsxs("span",{className:"font-medium",children:["/",S.name]}),r.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"}),S.scope==="project"&&r.jsx("span",{className:"text-[10px] rounded-full bg-primary/10 px-1.5 py-0.5 text-primary",children:"project"})]}),r.jsx("span",{className:"text-xs text-muted-foreground",children:S.description})]},`skill-${S.name}`)}}):r.jsxs("div",{className:"px-3 py-4 text-center text-xs text-muted-foreground",children:["No commands or skills found.",r.jsx("br",{}),r.jsxs("span",{className:"text-[10px]",children:["Create commands in ",r.jsx("code",{className:"bg-muted px-1 rounded",children:"~/.tarsk/commands/"})," or skills in ",r.jsx("code",{className:"bg-muted px-1 rounded",children:"~/.tarsk/skills/"})]})]}),e[11]=p,e[12]=u,e[13]=i,e[14]=d,e[15]=o,e[16]=b):b=e[16];let g;return e[17]!==m||e[18]!==j||e[19]!==b?(g=r.jsxs("div",{ref:m,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,b]}),e[17]=m,e[18]=j,e[19]=b,e[20]=g):g=e[20],g}function _o(s){return{type:"skill",data:s}}function Ro(s){return{type:"command",data:s}}function Po(s){const e=F.c(8),{queuedMessages:t,onRemoveQueuedMessage:n}=s;if(t.length===0)return null;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Queued messages"}),e[0]=a):a=e[0];let l;if(e[1]!==n||e[2]!==t){let i;e[4]!==n?(i=d=>r.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:[r.jsx("p",{className:"flex-1 whitespace-pre-wrap text-foreground",children:d.message}),r.jsx("button",{type:"button",className:"rounded-full p-1 text-muted-foreground hover:text-foreground",onClick:()=>n(d.id),"aria-label":"Remove queued message",children:r.jsx(tt,{className:"h-3.5 w-3.5"})})]},d.id),e[4]=n,e[5]=i):i=e[5],l=t.map(i),e[1]=n,e[2]=t,e[3]=l}else l=e[3];let o;return e[6]!==l?(o=r.jsxs("div",{className:"mb-3 rounded-lg border border-border/60 bg-muted/30 px-4 py-3",children:[a,r.jsx("div",{className:"mt-2 flex flex-col gap-2",children:l})]}),e[6]=l,e[7]=o):o=e[7],o}function Mo({onSend:s,onStop:e,isStreaming:t=!1,disabled:n,initialValue:a,queuedMessages:l,onRemoveQueuedMessage:o}){const{state:i,dispatch:d}=Pe(),{isListening:u,transcript:m,startListening:f,stopListening:p,resetTranscript:h,isSupported:x}=Eo(),[j,b]=c.useState(a||""),[g,R]=c.useState(qt),[I,w]=c.useState(qt[0]),[S,E]=c.useState(-1),[T,k]=c.useState(""),[y,C]=c.useState(!1),[_,D]=c.useState(!1),[P,z]=c.useState([]),[L,W]=c.useState(!1),[G,U]=c.useState([]),[q,le]=c.useState(0),[fe,ae]=c.useState(!1),[ce,V]=c.useState(""),[se,ee]=c.useState(0),[ne,ie]=c.useState([]),[Ie,pe]=c.useState([]),[ue,v]=c.useState(!1),[$,K]=c.useState(""),Q=c.useRef(null),te=c.useRef(null),me=c.useRef(null),_e=c.useRef(null),ke=c.useRef(null),Ye=c.useRef(null),We=c.useRef(I.id);c.useEffect(()=>{We.current=I.id},[I.id]);const Xe=c.useCallback(A=>{const J=jt(A.id);return A.provider?`${J} (${A.provider})`:J},[]),De=async()=>{if(i.selectedThreadId)try{const A=await Xl(i.selectedThreadId);d({type:N.ClearMessages}),console.log("New conversation started:",A)}catch(A){console.error("Failed to start new chat:",A)}};c.useEffect(()=>{(async()=>{try{const J=await is(),Z=Object.values(J).flat();if(Z.length>0){R(Z);const de=i.selectedProjectId?cr(i.selectedProjectId):null,Ne=(de?Z.find(Ae=>Ae.id===de):null)||Z[0];Ne.id!==I.id&&w(Ne)}}catch(J){console.error("Failed to load enabled models:",J),R(qt);const Z=i.selectedProjectId?cr(i.selectedProjectId):null,be=(Z?qt.find(Ne=>Ne.id===Z):null)||qt[0];be.id!==I.id&&w(be)}})()},[i.selectedProjectId,I.id]),c.useEffect(()=>{if(i.configUpdatedAt===0)return;(async()=>{try{const J=await is(),Z=Object.values(J).flat();if(Z.length>0){R(Z);const de=We.current;Z.some(Ne=>Ne.id===de)||(w(Z[0]),i.selectedProjectId&&dr(i.selectedProjectId,Z[0].id))}}catch(J){console.error("Failed to reload enabled models:",J)}})()},[i.configUpdatedAt,i.selectedProjectId]);const[Ve,mt]=c.useState(i.selectedThreadId);i.selectedThreadId!==Ve&&(mt(i.selectedThreadId),U([]),ae(!1),ie([]),pe([]),v(!1)),c.useEffect(()=>{i.selectedThreadId&&To(i.selectedThreadId).then(({commands:A,skills:J})=>{console.log("Loaded slash commands:",A,"skills:",J),ie(A),pe(J)}).catch(A=>console.error("Failed to load slash commands and skills:",A))},[i.selectedThreadId]),c.useEffect(()=>{i.focusChatInput&&i.selectedThreadId&&!i.isStreaming&&(te.current?.focus(),d({type:N.ClearFocusChatInput}))},[i.focusChatInput,i.selectedThreadId,i.isStreaming,d]),c.useEffect(()=>{const A=J=>{me.current&&!me.current.contains(J.target)&&C(!1),_e.current&&!_e.current.contains(J.target)&&D(!1)};if(y||_)return document.addEventListener("mousedown",A),()=>{document.removeEventListener("mousedown",A)}},[y,_]);const Ke=c.useRef("");c.useEffect(()=>{if(m&&m!==Ke.current){const A=m.substring(Ke.current.length);b(J=>(J.endsWith(" ")||J==="",J+A)),Ke.current=m}},[m]);const Le=c.useCallback(()=>{!j.trim()&&P.length===0||i.selectedThreadId&&(u&&(p(),h()),t?d({type:N.EnqueueChatMessage,message:{id:`queued-${Date.now()}`,threadId:i.selectedThreadId,message:j,model:I.id,attachments:P,provider:I.provider}}):s(j,I.id,P,I.provider),_l(j),b(""),z([]),E(-1),k(""),te.current&&(te.current.style.height="auto"))},[j,P,I,s,u,p,h,t,d,i.selectedThreadId]),st=c.useCallback(()=>{u?(p(),h()):(h(),f())},[u,f,p,h]),rt=c.useCallback(A=>{const J=j.substring(0,se-ce.length-1),Z=j.substring(se),de=`${J}${A} ${Z}`;b(de),ae(!1),setTimeout(()=>{if(te.current){te.current.focus();const be=J.length+A.length+1;te.current.setSelectionRange(be,be)}},0)},[j,se,ce]),Ge=c.useCallback(A=>{const J=j.substring(0,se-$.length-1),Z=j.substring(se),de=`${J}${A.content}${Z}`;b(de),v(!1),setTimeout(()=>{if(te.current){te.current.focus();const be=J.length+A.content.length;te.current.setSelectionRange(be,be)}},0),A.metadata.mode==="plan"&&W(!0)},[j,se,$]),Y=c.useCallback(A=>{const J=j.substring(0,se-$.length-1),Z=j.substring(se),de=`Use the "${A.name}" skill to help with this task.`,be=`${J}${de}${Z}`;b(be),v(!1),setTimeout(()=>{if(te.current){te.current.focus();const Ne=J.length+de.length;te.current.setSelectionRange(Ne,Ne)}},0)},[j,se,$]),nt=A=>{if(ue){if(A.key==="ArrowDown"){A.preventDefault(),le(Z=>(Z+1)%Ce.length);return}if(A.key==="ArrowUp"){A.preventDefault(),le(Z=>(Z-1+Ce.length)%Ce.length);return}if(A.key==="Enter"||A.key==="Tab"){A.preventDefault();const Z=Ce[q];Z&&(Z.type==="command"?Ge(Z.data):Y(Z.data));return}if(A.key==="Escape"){v(!1);return}}if(fe){if(A.key==="ArrowDown"){A.preventDefault(),le(Z=>(Z+1)%M.length);return}if(A.key==="ArrowUp"){A.preventDefault(),le(Z=>(Z-1+M.length)%M.length);return}if(A.key==="Enter"||A.key==="Tab"){A.preventDefault(),M[q]&&rt(M[q]);return}if(A.key==="Escape"){ae(!1);return}}if(A.key==="Enter"&&!A.shiftKey){A.preventDefault(),Le();return}const J=Cn();J.length!==0&&(A.key==="ArrowUp"?(A.preventDefault(),S===-1?(k(j),E(J.length-1),b(J[J.length-1])):S>0&&(E(S-1),b(J[S-1]))):A.key==="ArrowDown"&&(A.preventDefault(),S>0?(E(S-1),b(J[S-1])):S===0&&(E(-1),b(T))))},ve=A=>{const J=A.target.files;J&&(Array.from(J).forEach(Z=>{const de=new FileReader;de.onload=()=>{const be=de.result.split(",")[1];z(Ne=>[...Ne,{fileName:Z.name,content:be}])},de.readAsDataURL(Z)}),A.target.value="")},at=A=>{z(J=>J.filter((Z,de)=>de!==A))},ft=A=>{const J=A.target.value,Z=A.target.selectionStart;b(J),ee(Z);const de=J.substring(0,Z),be=de.lastIndexOf("/");if(be!==-1){const Ae=be>0?de[be-1]:"";if(be===0||/\s/.test(Ae)){const ze=de.substring(be+1);ze.includes(" ")?v(!1):(K(ze),v(!0),ae(!1),le(0),console.log("Showing slash commands, query:",ze,"commands:",ne))}else v(!1)}else{v(!1);const Ae=de.lastIndexOf("#");if(Ae!==-1){const yt=Ae>0?de[Ae-1]:"";if(Ae===0||/\s/.test(yt)){const Ze=de.substring(Ae+1);Ze.includes(" ")?ae(!1):(V(Ze),ae(!0),le(0),G.length===0&&i.selectedThreadId&&go(i.selectedThreadId).then(pt=>{U(pt)}).catch(pt=>console.error("Failed to fetch files:",pt)))}else ae(!1)}else ae(!1)}const Ne=A.target;Ne.style.height="auto",Ne.style.height=`${Math.min(Ne.scrollHeight,160)}px`},M=fe?G.filter(A=>A.toLowerCase().includes(ce.toLowerCase())).slice(0,10):[],X=ne.filter(A=>A.name.toLowerCase().includes($.toLowerCase())),Ee=Ie.filter(A=>A.name.toLowerCase().includes($.toLowerCase())),Ce=[...X.map(A=>({type:"command",data:A})),...Ee.map(A=>({type:"skill",data:A}))].slice(0,10);return r.jsxs("div",{className:"relative mx-auto w-full max-w-3xl px-4 pb-4",children:[P.length>0&&r.jsx("div",{className:"mb-2 flex flex-wrap gap-1.5",children:P.map((A,J)=>r.jsxs("span",{className:"flex items-center gap-1 rounded-md bg-muted px-2 py-1 text-xs text-muted-foreground",children:[r.jsx(As,{className:"h-3 w-3"}),A.fileName,r.jsxs("button",{type:"button",onClick:()=>at(J),className:"ml-1 hover:text-foreground",children:[r.jsx(tt,{className:"h-3 w-3"}),r.jsx("span",{className:"sr-only",children:"Remove attachment"})]})]},J))}),L&&r.jsxs("div",{className:"mb-2 flex items-center gap-2 rounded-md bg-accent px-3 py-1.5",children:[r.jsx(tr,{className:"h-3.5 w-3.5 text-accent-foreground"}),r.jsx("span",{className:"text-xs text-accent-foreground font-medium",children:"Plan Mode"}),r.jsxs("button",{type:"button",onClick:()=>W(!1),className:"ml-auto",children:[r.jsx(tt,{className:"h-3 w-3 text-accent-foreground"}),r.jsx("span",{className:"sr-only",children:"Exit plan mode"})]})]}),r.jsxs("div",{className:"flex flex-col rounded-2xl border border-border bg-background shadow-sm focus-within:ring-1 focus-within:ring-ring/20",children:[r.jsx(Po,{queuedMessages:l,onRemoveQueuedMessage:o}),r.jsx("textarea",{ref:te,value:j,onChange:ft,onKeyDown:nt,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:n}),r.jsx(ko,{visible:ue,commands:ne,skills:Ie,query:$,selectedIndex:q,onSelectCommand:Ge,onSelectSkill:Y,onMouseEnterSuggestion:le,containerRef:Ye}),fe&&M.length>0&&r.jsxs("div",{ref:ke,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:[r.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:[r.jsx(Sr,{className:"h-3 w-3"}),'Files matching "',ce,'"']}),M.map((A,J)=>{const Z=A.split("/").pop()||A,de=J===q;return r.jsxs("button",{type:"button",className:O("flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-left transition-colors",de?"bg-accent text-accent-foreground":"text-popover-foreground hover:bg-accent/50"),onClick:()=>rt(A),onMouseEnter:()=>le(J),children:[A.endsWith(".ts")||A.endsWith(".tsx")||A.endsWith(".js")||A.endsWith(".jsx")?r.jsx(ca,{className:"h-4 w-4 text-blue-500"}):r.jsx(Cr,{className:"h-4 w-4 text-muted-foreground"}),r.jsxs("div",{className:"flex flex-col overflow-hidden",children:[r.jsx("span",{className:"truncate font-medium",children:Z}),r.jsx("span",{className:"truncate text-[10px] text-muted-foreground opacity-70",children:A})]})]},A)})]}),r.jsxs("div",{className:"flex items-center justify-between px-3 pb-2",children:[r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsxs("div",{className:"relative",ref:_e,children:[r.jsxs(B,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:()=>D(!_),children:[r.jsx(ds,{className:"h-4 w-4"}),r.jsx("span",{className:"sr-only",children:"More options"})]}),_&&r.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:[r.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:()=>{Q.current?.click(),D(!1)},children:[r.jsx(As,{className:"h-3.5 w-3.5"}),"Attach File"]}),r.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:()=>{W(!0),D(!1)},children:[r.jsx(tr,{className:"h-3.5 w-3.5"}),"Plan Mode"]}),r.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:()=>{D(!1),De()},children:[r.jsx(da,{className:"h-3.5 w-3.5"}),"New Chat"]})]})]}),x&&r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsxs(B,{variant:"ghost",size:"icon",className:O("h-7 w-7",u?"bg-red-500/20 text-red-500 hover:bg-red-500/30":"text-muted-foreground hover:text-foreground"),onClick:st,children:[u?r.jsx(ua,{className:"h-4 w-4"}):r.jsx(ma,{className:"h-4 w-4"}),r.jsx("span",{className:"sr-only",children:u?"Stop listening":"Start listening"})]})}),r.jsx(he,{side:"top",className:"bg-popover text-popover-foreground",children:u?"Stop listening":"Start listening"})]}),r.jsxs("div",{className:"relative",ref:me,children:[r.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:()=>C(!y),children:[Xe(I),r.jsx(ct,{className:"h-3 w-3"})]}),y&&r.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:g.map(A=>r.jsx("button",{type:"button",className:O("flex w-full items-center whitespace-nowrap rounded-md px-3 py-2 text-sm text-popover-foreground hover:bg-accent",A.id===I.id&&"bg-accent font-medium"),onClick:()=>{w(A),i.selectedProjectId&&dr(i.selectedProjectId,A.id),C(!1)},children:Xe(A)},A.id))})]})]}),r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsxs(B,{size:"icon",className:O("h-7 w-7 rounded-full",!t&&"bg-[url('/tarsk-color.svg')] bg-cover bg-center hover:opacity-80"),onClick:t?e:Le,disabled:!t&&(n||!j.trim()&&P.length===0),children:[t&&r.jsx(Tr,{className:"h-3 w-3 fill-current"}),r.jsx("span",{className:"sr-only",children:t?"Stop generation":"Send message"})]})}),r.jsx(he,{side:"top",className:"bg-popover text-popover-foreground",children:t?"Stop":"Send"})]})]})]}),r.jsx("input",{ref:Q,type:"file",multiple:!0,className:"hidden",onChange:ve})]})}function cs(s){const e=F.c(10),{content:t,className:n}=s;let a;e:{if(!t||typeof t!="string"){let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=[],e[0]=m):m=e[0],a=m;break e}let u;e[1]!==t?(u=Ao(t),e[1]=t,e[2]=u):u=e[2],a=u}const l=a;if(l.length===0)return null;let o;e[3]!==n?(o=O("prose-custom space-y-3",n),e[3]=n,e[4]=o):o=e[4];let i;e[5]!==l?(i=l.map(Do),e[5]=l,e[6]=i):i=e[6];let d;return e[7]!==o||e[8]!==i?(d=r.jsx("div",{className:o,children:i}),e[7]=o,e[8]=i,e[9]=d):d=e[9],d}function Do(s,e){return r.jsx(Lo,{block:s},e)}function Ao(s){const e=s.split(`
|
|
4
|
+
`),t=[];let n=0;for(;n<e.length;){const a=e[n];if(a.trimStart().startsWith("```")){const i=a.trimStart().slice(3).trim(),d=[];for(n++;n<e.length&&!e[n].trimStart().startsWith("```");)d.push(e[n]),n++;t.push({type:"code",language:i,code:d.join(`
|
|
5
|
+
`)}),n++;continue}const l=a.match(/^(#{1,6})\s+(.+)/);if(l){t.push({type:"heading",level:l[1].length,text:l[2]}),n++;continue}if(/^(---|\*\*\*|___)/.test(a.trim())){t.push({type:"hr"}),n++;continue}if(a.includes("|")&&n+1<e.length&&e[n+1].match(/^\|?\s*[-:]+/)){const i=a.split("|").map(u=>u.trim()).filter(Boolean);n+=2;const d=[];for(;n<e.length&&e[n].includes("|");)d.push(e[n].split("|").map(u=>u.trim()).filter(Boolean)),n++;t.push({type:"table",headers:i,rows:d});continue}if(a.startsWith("> ")){const i=[];for(;n<e.length&&e[n].startsWith("> ");)i.push(e[n].slice(2)),n++;t.push({type:"blockquote",text:i.join(`
|
|
6
|
+
`)});continue}if(/^\s*[-*+]\s/.test(a)){const i=[];for(;n<e.length&&/^\s*[-*+]\s/.test(e[n]);)i.push(e[n].replace(/^\s*[-*+]\s/,"")),n++;t.push({type:"list",ordered:!1,items:i});continue}if(/^\s*\d+\.\s/.test(a)){const i=[];for(;n<e.length&&/^\s*\d+\.\s/.test(e[n]);)i.push(e[n].replace(/^\s*\d+\.\s/,"")),n++;t.push({type:"list",ordered:!0,items:i});continue}if(a.trim()===""){n++;continue}const o=[];for(;n<e.length&&e[n].trim()!==""&&!e[n].startsWith("#")&&!e[n].startsWith("```")&&!e[n].startsWith("> ")&&!/^\s*[-*+]\s/.test(e[n])&&!/^\s*\d+\.\s/.test(e[n]);)o.push(e[n]),n++;o.length>0&&t.push({type:"paragraph",text:o.join(`
|
|
7
|
+
`)})}return t}function Lo(s){const e=F.c(37),{block:t}=s;switch(t.type){case"heading":{const n=`h${t.level}`;let a,l;if(e[0]!==n||e[1]!==t.level){const d={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=n,l=O(d[t.level],"text-foreground"),e[0]=n,e[1]=t.level,e[2]=a,e[3]=l}else a=e[2],l=e[3];let o;e[4]!==t.text?(o=r.jsx(ss,{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=r.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 n;return e[10]!==t.code||e[11]!==t.language?(n=r.jsx(Bo,{language:t.language,code:t.code}),e[10]=t.code,e[11]=t.language,e[12]=n):n=e[12],n}case"blockquote":{let n;return e[13]!==t.text?(n=r.jsx("blockquote",{className:"border-l-2 border-border pl-4 text-muted-foreground italic",children:r.jsx(ss,{text:t.text})}),e[13]=t.text,e[14]=n):n=e[14],n}case"list":{const n=t.ordered?"ol":"ul",a=t.ordered?"list-decimal":"list-disc";let l;e[15]!==a?(l=O("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(Go),e[17]=t.items,e[18]=o):o=e[18];let i;return e[19]!==n||e[20]!==l||e[21]!==o?(i=r.jsx(n,{className:l,children:o}),e[19]=n,e[20]=l,e[21]=o,e[22]=i):i=e[22],i}case"paragraph":{let n;return e[23]!==t.text?(n=r.jsx("p",{className:"text-sm leading-relaxed text-foreground whitespace-pre-wrap",children:r.jsx(ss,{text:t.text})}),e[23]=t.text,e[24]=n):n=e[24],n}case"hr":{let n;return e[25]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx("hr",{className:"border-border"}),e[25]=n):n=e[25],n}case"table":{let n;e[26]!==t.headers?(n=t.headers.map(Fo),e[26]=t.headers,e[27]=n):n=e[27];let a;e[28]!==n?(a=r.jsx("thead",{children:r.jsx("tr",{className:"border-b border-border bg-muted/50",children:n})}),e[28]=n,e[29]=a):a=e[29];let l;e[30]!==t.rows?(l=t.rows.map(Oo),e[30]=t.rows,e[31]=l):l=e[31];let o;e[32]!==l?(o=r.jsx("tbody",{children:l}),e[32]=l,e[33]=o):o=e[33];let i;return e[34]!==a||e[35]!==o?(i=r.jsx("div",{className:"overflow-x-auto rounded-md border border-border",children:r.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 Oo(s,e){return r.jsx("tr",{className:"border-b border-border last:border-0",children:s.map($o)},e)}function $o(s,e){return r.jsx("td",{className:"px-3 py-2 text-foreground",children:s},e)}function Fo(s,e){return r.jsx("th",{className:"px-3 py-2 text-left font-medium text-foreground",children:s},e)}function Go(s,e){return r.jsx("li",{children:r.jsx(ss,{text:s})},e)}function ss(s){const e=F.c(4),{text:t}=s;let n;e[0]!==t?(n=Uo(t).map(zo),e[0]=t,e[1]=n):n=e[1];let a;return e[2]!==n?(a=r.jsx(r.Fragment,{children:n}),e[2]=n,e[3]=a):a=e[3],a}function zo(s,e){switch(s.type){case"bold":return r.jsx("strong",{className:"font-semibold",children:s.text},e);case"italic":return r.jsx("em",{children:s.text},e);case"strikethrough":return r.jsx("del",{className:"text-muted-foreground",children:s.text},e);case"code":return r.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 r.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 r.jsx("span",{children:s.text},e)}}function Uo(s){const e=[],t=/(`[^`]+`)|(\*\*[^*]+\*\*)|(\*[^*]+\*)|(__[^_]+__)|(_[^_]+_)|(~~[^~]+~~)|(\[[^\]]+\]\([^)]+\))/g;let n=0,a;for(;(a=t.exec(s))!==null;){a.index>n&&e.push({type:"text",text:s.slice(n,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]})}n=a.index+l.length}return n<s.length&&e.push({type:"text",text:s.slice(n)}),e.length>0?e:[{type:"text",text:s}]}function Bo(s){const e=F.c(18),{language:t,code:n}=s,[a,l]=c.useState(!1);let o;e[0]!==n?(o=async()=>{await navigator.clipboard.writeText(n),l(!0),setTimeout(()=>l(!1),2e3)},e[0]=n,e[1]=o):o=e[1];const i=o,d=t||"text";let u;e[2]!==d?(u=r.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:d}),e[2]=d,e[3]=u):u=e[3];let m;e[4]!==a?(m=a?r.jsx(et,{className:"h-3 w-3"}):r.jsx(fa,{className:"h-3 w-3"}),e[4]=a,e[5]=m):m=e[5];let f;e[6]===Symbol.for("react.memo_cache_sentinel")?(f=r.jsx("span",{className:"sr-only",children:"Copy code"}),e[6]=f):f=e[6];let p;e[7]!==i||e[8]!==m?(p=r.jsxs(B,{variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",onClick:i,children:[m,f]}),e[7]=i,e[8]=m,e[9]=p):p=e[9];let h;e[10]!==u||e[11]!==p?(h=r.jsxs("div",{className:"flex items-center justify-between border-b border-border bg-muted/80 px-4 py-2",children:[u,p]}),e[10]=u,e[11]=p,e[12]=h):h=e[12];let x;e[13]!==n?(x=r.jsx("pre",{className:"overflow-x-auto p-4",children:r.jsx("code",{className:"text-xs font-mono text-foreground leading-relaxed",children:n})}),e[13]=n,e[14]=x):x=e[14];let j;return e[15]!==h||e[16]!==x?(j=r.jsxs("div",{className:"group relative overflow-hidden rounded-lg border border-border bg-muted",children:[h,x]}),e[15]=h,e[16]=x,e[17]=j):j=e[17],j}const Rn=ha,Pn=ga,Ws=c.forwardRef((s,e)=>{const t=F.c(13);let n,a,l,o;t[0]!==s?({className:n,align:l,sideOffset:o,...a}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l,t[4]=o):(n=t[1],a=t[2],l=t[3],o=t[4]);const i=l===void 0?"center":l,d=o===void 0?4:o;let u;t[5]!==n?(u=O("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",n),t[5]=n,t[6]=u):u=t[6];let m;return t[7]!==i||t[8]!==a||t[9]!==e||t[10]!==d||t[11]!==u?(m=r.jsx(pa,{children:r.jsx(Ir,{ref:e,align:i,sideOffset:d,className:u,...a})}),t[7]=i,t[8]=a,t[9]=e,t[10]=d,t[11]=u,t[12]=m):m=t[12],m});Ws.displayName=Ir.displayName;function ot(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 Ho(s){return typeof s=="string"?s:typeof s=="object"&&s!==null?JSON.stringify(s,null,2):String(s)}function qo(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 rs(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return s.map(rs);const e={};for(const[t,n]of Object.entries(s))if(typeof n=="string"){const a=qo(n);e[t]=typeof a=="object"?rs(a):n}else e[t]=rs(n);return e}function Wo(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 Vo(s){if(s==null)return"";const e=typeof s=="object"&&s!==null?rs(s):s,t=typeof e=="string"?e:e==null?"":JSON.stringify(e,null,2);return Wo(t)}function Vs(s){const e=F.c(58),{block:t,inline:n}=s,[a,l]=c.useState(!1),{state:o}=Pe();let i,d,u,m,f,p,h;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 T;e[13]!==o.selectedProjectId?(T=W=>W.projectId===o.selectedProjectId,e[13]=o.selectedProjectId,e[14]=T):T=e[14];const C=o.projects.find(T)?.threads.find(W=>W.threadId===o.selectedThreadId)?.path,_=t.name||"Unknown Tool";p=t.id||"unknown";const D=t.input,P=D&&typeof D=="object"&&"description"in D,z=P?String(D.description):null;m=P?String(D.subagent_type):null;const L=D&&typeof D=="object"?D:null;if(d=_,z)d=ot(z,C);else if(_==="read"||_==="file_read"){const W=L?.file_path??L?.filePath??L?.path??"";if(W){let G;e[15]!==W?(G=W.split("/").pop()||W,e[15]=W,e[16]=G):G=e[16],d=`Read ${G}`}}else d=ot(_,C);h=P?null:ot(Ho(D),C),u=ot(P?String(D.prompt):null,C),i=ot(L&&typeof L.command=="string"?L.command:null,C),f=ot(L&&typeof L.path=="string"?L.path:null,C),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]=d,e[8]=u,e[9]=m,e[10]=f,e[11]=p,e[12]=h}else i=e[6],d=e[7],u=e[8],m=e[9],f=e[10],p=e[11],h=e[12];const x=f;if(n){const T=!!(u||h&&!i&&!x);let k;e[17]!==T||e[18]!==u||e[19]!==p||e[20]!==h?(k=T?r.jsxs(Rn,{children:[r.jsx(Pn,{asChild:!0,children:r.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 tool details",children:r.jsx(Is,{className:"h-3.5 w-3.5"})})}),r.jsx(Ws,{className:"w-80 max-h-80 overflow-auto",align:"start",children:r.jsxs("div",{className:"text-xs text-muted-foreground space-y-2",children:[r.jsxs("div",{className:"font-mono",children:["ID: ",p]}),u?r.jsx("div",{className:"whitespace-pre-wrap leading-relaxed",children:u}):h?r.jsx("pre",{className:"font-mono whitespace-pre-wrap overflow-auto max-h-48",children:h}):null]})})]}):r.jsx(Is,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e[17]=T,e[18]=u,e[19]=p,e[20]=h,e[21]=k):k=e[21];let y;e[22]!==d?(y=r.jsx("span",{className:"text-sm text-foreground shrink-0",children:d}),e[22]=d,e[23]=y):y=e[23];let C;e[24]!==i?(C=i!==null&&r.jsx("code",{className:"text-xs font-mono text-muted-foreground break-all rounded bg-muted/60 px-1 py-0.5",children:i}),e[24]=i,e[25]=C):C=e[25];let _;e[26]!==x?(_=x!==null&&r.jsx("span",{className:"text-xs font-mono text-muted-foreground truncate max-w-[200px] sm:max-w-[320px]",title:x,children:x}),e[26]=x,e[27]=_):_=e[27];let D;e[28]!==m?(D=m&&r.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-muted text-muted-foreground",children:m}),e[28]=m,e[29]=D):D=e[29];let P;return e[30]!==k||e[31]!==y||e[32]!==C||e[33]!==_||e[34]!==D?(P=r.jsxs("div",{className:"py-1 flex items-center gap-2 flex-wrap",children:[k,y,C,_,D]}),e[30]=k,e[31]=y,e[32]=C,e[33]=_,e[34]=D,e[35]=P):P=e[35],P}let j;e[36]!==a?(j=()=>l(!a),e[36]=a,e[37]=j):j=e[37];let b;e[38]===Symbol.for("react.memo_cache_sentinel")?(b=r.jsx(Is,{className:"h-4 w-4"}),e[38]=b):b=e[38];let g;e[39]!==d?(g=r.jsx("span",{className:"flex-1 text-left animate-shimmer",children:d}),e[39]=d,e[40]=g):g=e[40];let R;e[41]!==m?(R=m&&r.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:m}),e[41]=m,e[42]=R):R=e[42];let I;e[43]!==a?(I=a?r.jsx(ct,{className:"h-4 w-4 shrink-0"}):r.jsx(Gt,{className:"h-4 w-4 shrink-0"}),e[43]=a,e[44]=I):I=e[44];let w;e[45]!==j||e[46]!==g||e[47]!==R||e[48]!==I?(w=r.jsxs("button",{onClick:j,className:"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",children:[b,g,R,I]}),e[45]=j,e[46]=g,e[47]=R,e[48]=I,e[49]=w):w=e[49];let S;e[50]!==a||e[51]!==u||e[52]!==p||e[53]!==h?(S=a&&r.jsxs("div",{className:"px-3 py-2 bg-white dark:bg-slate-950 border-t border-blue-200 dark:border-blue-800",children:[r.jsxs("div",{className:"text-xs text-muted-foreground mb-2 font-mono text-blue-700 dark:text-blue-300",children:["ID: ",p]}),u?r.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:u}):h?r.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:h}):null]}),e[50]=a,e[51]=u,e[52]=p,e[53]=h,e[54]=S):S=e[54];let E;return e[55]!==w||e[56]!==S?(E=r.jsxs("div",{className:"mb-3 rounded-lg border border-blue-200 dark:border-blue-800 bg-blue-50 dark:bg-blue-900/20 overflow-hidden",children:[w,S]}),e[55]=w,e[56]=S,e[57]=E):E=e[57],E}function Ks(s){const e=F.c(43),{block:t,inline:n}=s,[a,l]=c.useState(!1),{state:o}=Pe(),i=o.projects;let d,u,m,f,p,h;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){p=Symbol.for("react.early_return_sentinel");e:{let S;e[12]!==o.selectedProjectId?(S=_=>_.projectId===o.selectedProjectId,e[12]=o.selectedProjectId,e[13]=S):S=e[13];const k=i.find(S)?.threads.find(_=>_.threadId===o.selectedThreadId)?.path,y=t.toolName||"Unknown Tool";h=t.toolCallId||"unknown";const C=t.result;if(m=ot(Vo(C),k),u=m.length>0,!u){p=null;break e}if(d=C==null?`${y} (no result)`:`${y} Result`,typeof C=="object"&&C!==null){const _=C,D=_.returnDisplay??_.return_display;if(typeof D=="string"&&D.trim())d=D.trim();else if(y==="read"||y==="file_read"){const P=_.filePath||_.file_path||_.path||"";if(P){let z;e[14]!==P?(z=P.split("/").pop()||P,e[14]=P,e[15]=z):z=e[15],d=`Completed ${z}`}}}f=ot(d,k)}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]=d,e[7]=u,e[8]=m,e[9]=f,e[10]=p,e[11]=h}else d=e[6],u=e[7],m=e[8],f=e[9],p=e[10],h=e[11];if(p!==Symbol.for("react.early_return_sentinel"))return p;if(d=f,n){let S;e[16]!==u||e[17]!==m||e[18]!==h?(S=u?r.jsxs(Rn,{children:[r.jsx(Pn,{asChild:!0,children:r.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",children:r.jsx(Es,{className:"h-3.5 w-3.5"})})}),r.jsx(Ws,{className:"w-80 max-h-80 overflow-auto",align:"start",children:r.jsxs("div",{className:"text-xs space-y-2",children:[r.jsxs("div",{className:"text-muted-foreground font-mono",children:["Call ID: ",h]}),r.jsx("pre",{className:"font-mono whitespace-pre-wrap overflow-auto max-h-48 text-foreground text-left",children:m})]})})]}):r.jsx(Es,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e[16]=u,e[17]=m,e[18]=h,e[19]=S):S=e[19];let E;e[20]!==d?(E=r.jsx("span",{className:"text-sm text-foreground",children:d}),e[20]=d,e[21]=E):E=e[21];let T;return e[22]!==S||e[23]!==E?(T=r.jsxs("div",{className:"py-1 flex items-center gap-2",children:[S,E]}),e[22]=S,e[23]=E,e[24]=T):T=e[24],T}let x;e[25]!==a?(x=()=>l(!a),e[25]=a,e[26]=x):x=e[26];let j;e[27]===Symbol.for("react.memo_cache_sentinel")?(j=r.jsx(Es,{className:"h-4 w-4 shrink-0"}),e[27]=j):j=e[27];let b;e[28]!==d?(b=r.jsx("span",{className:"flex-1 text-left min-w-0 truncate",children:d}),e[28]=d,e[29]=b):b=e[29];let g;e[30]!==a?(g=a?r.jsx(ct,{className:"h-4 w-4 shrink-0"}):r.jsx(Gt,{className:"h-4 w-4 shrink-0"}),e[30]=a,e[31]=g):g=e[31];let R;e[32]!==x||e[33]!==b||e[34]!==g?(R=r.jsxs("button",{onClick:x,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",children:[j,b,g]}),e[32]=x,e[33]=b,e[34]=g,e[35]=R):R=e[35];let I;e[36]!==a||e[37]!==m||e[38]!==h?(I=a&&r.jsxs("div",{className:"px-3 py-2 bg-background border-t border-border",children:[r.jsxs("div",{className:"text-xs text-muted-foreground mb-2 font-mono",children:["Call ID: ",h]}),m&&r.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:m})]}),e[36]=a,e[37]=m,e[38]=h,e[39]=I):I=e[39];let w;return e[40]!==R||e[41]!==I?(w=r.jsxs("div",{className:"mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden",children:[R,I]}),e[40]=R,e[41]=I,e[42]=w):w=e[42],w}function Ko({toolCall:s,className:e}){const{state:t,dispatch:n}=Pe(),[a,l]=c.useState(!1),o=t.toolCallProgress[s.id];if(!c.useMemo(()=>{if(!t.isStreaming)return{isActive:!1,isCompleted:!0};let f=!1,p=!1;for(const x of t.streamingSegments)if(x.type==="thinking")for(const j of x.chunks)try{const b=JSON.parse(j);if(Array.isArray(b))for(const g of b)g.type==="tool_use"&&g.id===s.id&&(f=!0),g.type==="tool-result"&&g.toolCallId===s.id&&(p=!0,f=!1)}catch{}const h=Us(t.streamingSegments);for(const x of h)if(x.type==="tool-result"&&("toolCallId"in x&&x.toolCallId===s.id||"tool_call_id"in x&&x.tool_call_id===s.id||"id"in x&&x.id===s.id)){p=!0,f=!1;break}return f&&!t.isStreaming&&(p=!0,f=!1),{isActive:f,isCompleted:p}},[t.isStreaming,t.streamingSegments,s.id]).isActive)return null;const d=()=>{l(f=>!f)},u=()=>{n({type:N.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."};n({type:N.AppendStreamChunk,chunkType:"content",content:JSON.stringify([f]),segments:t.streamingSegments})},m=f=>JSON.stringify(f,null,2);return r.jsxs("div",{className:O("border border-blue-200 dark:border-blue-800 bg-blue-50 dark:bg-blue-900/20 rounded-lg overflow-hidden mb-2",e),children:[r.jsxs("div",{className:"px-3 py-2 flex items-center gap-2",children:[r.jsxs("div",{className:"flex items-center gap-1.5 flex-1",children:[r.jsx(Te,{className:"h-3.5 w-3.5 animate-spin"}),r.jsx("span",{className:"text-sm font-medium text-blue-900 dark:text-blue-100",children:s.name}),r.jsx("span",{className:"text-xs text-blue-700 dark:text-blue-300",children:"running"})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("button",{onClick:d,className:"p-1 hover:bg-blue-200 dark:hover:bg-blue-800 rounded transition-colors",title:a?"Collapse":"Expand",children:a?r.jsx(Er,{className:"h-3.5 w-3.5"}):r.jsx(ct,{className:"h-3.5 w-3.5"})}),r.jsx("button",{onClick:u,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:r.jsx(tt,{className:"h-3.5 w-3.5"})})]})]}),a&&r.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:[r.jsxs("div",{className:"text-xs text-muted-foreground mb-2 font-mono text-blue-700 dark:text-blue-300",children:["ID: ",s.id]}),r.jsxs("div",{className:"mb-2",children:[r.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Input:"}),r.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:m(s.input)})]}),o&&r.jsxs("div",{className:"mb-2",children:[r.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Progress:"}),r.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:[r.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"&&r.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&&"..."]})]})]}),r.jsxs("div",{className:"flex items-center gap-2 text-xs text-blue-600 dark:text-blue-400",children:[r.jsx(Te,{className:"h-3 w-3 animate-spin"}),"Executing",o&&" with progress","..."]})]})]})}function Jo(s){const e=F.c(59),{message:t}=s,n=t.sender==="user";let a,l,o,i,d,u;if(e[0]!==n||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 x=n?null:vn(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 b=j,g=n?"flex-row-reverse":"flex-row";e[16]!==g?(d=O("group flex gap-3 px-4 py-4",g),e[16]=g,e[17]=d):d=e[17];const R=n?"bg-foreground":"bg-muted";let I;e[18]!==R?(I=O("flex h-7 w-7 shrink-0 items-center justify-center rounded-full",R),e[18]=R,e[19]=I):I=e[19];let w;e[20]!==n?(w=n?r.jsx(xa,{className:"h-3.5 w-3.5 text-background"}):r.jsx(_r,{className:"h-3.5 w-3.5 text-muted-foreground"}),e[20]=n,e[21]=w):w=e[21],e[22]!==I||e[23]!==w?(u=r.jsx("div",{className:I,children:w}),e[22]=I,e[23]=w,e[24]=u):u=e[24];const S=n&&"items-end";e[25]!==S?(o=O("flex max-w-[75%] flex-col gap-1",S),e[25]=S,e[26]=o):o=e[26];const E=n&&"flex-row-reverse";let T;e[27]!==E?(T=O("flex items-center gap-2",E),e[27]=E,e[28]=T):T=e[28];const k=n?"You":"Agent";let y;e[29]!==k?(y=r.jsx("span",{className:"text-xs font-medium text-foreground",children:k}),e[29]=k,e[30]=y):y=e[30];let C;e[31]!==b?(C=b&&r.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity",children:[r.jsx(ja,{className:"h-2.5 w-2.5"}),b]}),e[31]=b,e[32]=C):C=e[32];let _;e[33]!==t.model?(_=t.model&&r.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity",children:[r.jsx(kr,{className:"h-2.5 w-2.5"}),jt(t.model)]}),e[33]=t.model,e[34]=_):_=e[34];let D;e[35]!==t.metadata?(D=t.metadata?.tokenCount&&r.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]=D):D=e[36],e[37]!==T||e[38]!==y||e[39]!==C||e[40]!==_||e[41]!==D?(i=r.jsxs("div",{className:T,children:[y,C,_,D]}),e[37]=T,e[38]=y,e[39]=C,e[40]=_,e[41]=D,e[42]=i):i=e[42];const P=n?"bg-foreground text-background":"bg-muted text-foreground";e[43]!==P?(a=O("rounded-xl px-4 py-3 flex flex-col gap-2",P),e[43]=P,e[44]=a):a=e[44],l=t.isThinking?(()=>{const z=bn(t.content);return z?.length?z.map(Xo):r.jsx("div",{className:"text-xs text-muted-foreground leading-relaxed whitespace-pre-wrap",children:r.jsx(cs,{content:zt(t.content)})})})():x?r.jsx(r.Fragment,{children:x.map(Yo)}):t.contentType==="markdown"||t.sender==="agent"?r.jsx(cs,{content:zt(t.content)}):r.jsx("p",{className:"text-sm whitespace-pre-wrap",children:t.content}),e[0]=n,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]=d,e[13]=u}else a=e[8],l=e[9],o=e[10],i=e[11],d=e[12],u=e[13];let m;e[45]!==a||e[46]!==l?(m=r.jsx("div",{className:a,children:l}),e[45]=a,e[46]=l,e[47]=m):m=e[47];let f;e[48]!==t.attachments?(f=t.attachments&&t.attachments.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1",children:t.attachments.map(Qo)}),e[48]=t.attachments,e[49]=f):f=e[49];let p;e[50]!==o||e[51]!==i||e[52]!==m||e[53]!==f?(p=r.jsxs("div",{className:o,children:[i,m,f]}),e[50]=o,e[51]=i,e[52]=m,e[53]=f,e[54]=p):p=e[54];let h;return e[55]!==d||e[56]!==u||e[57]!==p?(h=r.jsxs("div",{className:d,children:[u,p]}),e[55]=d,e[56]=u,e[57]=p,e[58]=h):h=e[58],h}function Qo(s,e){return r.jsxs("span",{className:"flex items-center gap-1 rounded-md bg-muted px-2 py-1 text-[10px] text-muted-foreground",children:[r.jsx(As,{className:"h-2.5 w-2.5"}),s.fileName]},e)}function Yo(s,e){return r.jsx("div",{children:s.type==="reasoning"&&"text"in s?r.jsx("div",{className:"text-xs text-muted-foreground leading-relaxed whitespace-pre-wrap",children:zt(s.text)}):s.type==="text"&&"text"in s?r.jsx(cs,{content:zt(s.text)}):s.type==="tool_use"?r.jsx(Vs,{inline:!0,block:s}):s.type==="tool-result"?r.jsx(Ks,{inline:!0,block:s}):null},e)}function Xo(s,e){return s.type==="tool_use"?r.jsx(Vs,{inline:!0,block:s},e):s.type==="tool-result"?r.jsx(Ks,{inline:!0,block:s},e):null}function Zo(s){const e=F.c(21),{segments:t,model:n}=s;let a,l,o,i,d;if(e[0]!==n||e[1]!==t){const f=Us(t);console.log(JSON.stringify(t)),i="group flex gap-3 px-4 py-4",e[7]===Symbol.for("react.memo_cache_sentinel")?(d=r.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:r.jsx(_r,{className:"h-3.5 w-3.5 text-white"})}),e[7]=d):d=e[7],a="flex max-w-[75%] flex-col gap-1";let p;e[8]===Symbol.for("react.memo_cache_sentinel")?(p=r.jsx("span",{className:"text-xs font-medium text-foreground",children:"Agent"}),e[8]=p):p=e[8];let h;e[9]!==n?(h=n&&r.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity",children:[r.jsx(kr,{className:"h-2.5 w-2.5"}),jt(n)]}),e[9]=n,e[10]=h):h=e[10],e[11]!==h?(l=r.jsxs("div",{className:"flex items-center gap-2",children:[p,h]}),e[11]=h,e[12]=l):l=e[12],o=f.length>0?r.jsx("div",{className:"rounded-xl bg-muted px-4 py-3 text-foreground flex flex-col gap-2",children:f.map(ei)}):r.jsx("div",{className:"rounded-xl bg-muted px-4 py-3",children:r.jsxs("div",{className:"flex items-center justify-center gap-1.5",children:[r.jsx("div",{className:"h-2 w-2 rounded-full bg-muted-foreground/40 animate-bounce [animation-delay:0ms]"}),r.jsx("div",{className:"h-2 w-2 rounded-full bg-muted-foreground/40 animate-bounce [animation-delay:150ms]"}),r.jsx("div",{className:"h-2 w-2 rounded-full bg-muted-foreground/40 animate-bounce [animation-delay:300ms]"})]})}),e[0]=n,e[1]=t,e[2]=a,e[3]=l,e[4]=o,e[5]=i,e[6]=d}else a=e[2],l=e[3],o=e[4],i=e[5],d=e[6];let u;e[13]!==a||e[14]!==l||e[15]!==o?(u=r.jsxs("div",{className:a,children:[l,o]}),e[13]=a,e[14]=l,e[15]=o,e[16]=u):u=e[16];let m;return e[17]!==i||e[18]!==d||e[19]!==u?(m=r.jsxs("div",{className:i,children:[d,u]}),e[17]=i,e[18]=d,e[19]=u,e[20]=m):m=e[20],m}function ei(s,e){return r.jsx("div",{children:s.type==="reasoning"&&"text"in s?r.jsx("div",{className:"text-xs text-muted-foreground leading-relaxed whitespace-pre-wrap",children:zt(s.text)}):s.type==="text"&&"text"in s?r.jsx(cs,{content:zt(s.text)}):s.type==="tool_use"?r.jsxs(r.Fragment,{children:[r.jsx(Ko,{toolCall:s}),r.jsx(Vs,{inline:!0,block:s})]}):s.type==="tool-result"?r.jsx(Ks,{inline:!0,block:s}):null},`b-${e}`)}const ti=[{icon:ya,text:"Scaffold a REST API with authentication"},{icon:ba,text:"Find and fix bugs in my code"},{icon:Cr,text:"Refactor this module for better performance"}];function si(s){const e=F.c(6),{onSuggestionClick:t}=s;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx("div",{className:"flex h-14 w-14 items-center justify-center rounded-2xl border border-border bg-background shadow-sm",children:r.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 28 28",fill:"none",className:"text-foreground",children:[r.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"}),r.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"}),r.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]=n):n=e[0];let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsxs("div",{className:"flex flex-col items-center gap-3",children:[n,r.jsxs("div",{className:"text-center",children:[r.jsx("h1",{className:"text-2xl font-semibold tracking-tight text-foreground text-balance",children:"Let's build"}),r.jsx("p",{className:"mt-1 text-base text-muted-foreground",children:"Select a thread to start coding"})]})]}),e[1]=a):a=e[1];let l;e[2]!==t?(l=ti.map(i=>r.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:()=>t(i.text),children:[r.jsx(i.icon,{className:"h-5 w-5 text-muted-foreground"}),r.jsx("span",{className:"text-sm text-foreground leading-snug",children:i.text})]},i.text)),e[2]=t,e[3]=l):l=e[3];let o;return e[4]!==l?(o=r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-8 px-4",children:[a,r.jsx("div",{className:"flex flex-wrap justify-center gap-3",children:l})]}),e[4]=l,e[5]=o):o=e[5],o}function ri(s){const e=F.c(28),{messages:t,isStreaming:n,streamingSegments:a,streamingModel:l,isCreatingProject:o,isProcessingThread:i,error:d,onClearError:u,onSuggestionClick:m}=s,f=c.useRef(null);let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{f.current&&(f.current.scrollTop=f.current.scrollHeight)},e[0]=p):p=e[0];let h;e[1]!==t||e[2]!==a?(h=[t,a],e[1]=t,e[2]=a,e[3]=h):h=e[3],c.useEffect(p,h);const x=t.length===0&&!n&&!o,j=x&&"flex flex-col items-center justify-center";let b;e[4]!==j?(b=O("flex-1 overflow-y-auto",j),e[4]=j,e[5]=b):b=e[5];let g;e[6]!==m||e[7]!==x?(g=x&&r.jsx(si,{onSuggestionClick:m}),e[6]=m,e[7]=x,e[8]=g):g=e[8];let R;e[9]!==t?(R=t.map(ni),e[9]=t,e[10]=R):R=e[10];let I;e[11]!==o||e[12]!==i||e[13]!==n||e[14]!==l||e[15]!==a?(I=(n||o||i)&&r.jsx(Zo,{segments:a,model:l}),e[11]=o,e[12]=i,e[13]=n,e[14]=l,e[15]=a,e[16]=I):I=e[16];let w;e[17]!==d||e[18]!==u?(w=d&&r.jsxs("div",{className:"mx-4 my-2 rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3",children:[r.jsx("p",{className:"text-sm text-destructive",children:d}),r.jsx("button",{type:"button",className:"mt-1 text-xs text-destructive underline underline-offset-2 hover:text-destructive/80",onClick:u,children:"Dismiss"})]}),e[17]=d,e[18]=u,e[19]=w):w=e[19];let S;e[20]!==R||e[21]!==I||e[22]!==w?(S=r.jsxs("div",{className:"mx-auto max-w-3xl pb-4",children:[R,I,w]}),e[20]=R,e[21]=I,e[22]=w,e[23]=S):S=e[23];let E;return e[24]!==b||e[25]!==g||e[26]!==S?(E=r.jsxs("div",{ref:f,className:b,children:[g,S]}),e[24]=b,e[25]=g,e[26]=S,e[27]=E):E=e[27],E}function ni(s){return r.jsx(Jo,{message:s},s.messageId)}function ai({branchName:s,threadId:e}){const[t,n]=c.useState(""),[a,l]=c.useState(!1);c.useEffect(()=>{let i=!0;if(s)return zl().then(d=>{i&&n(d)}).catch(()=>{}),()=>{i=!1}},[s]);const o=async()=>{if(!(!e||a)){l(!0);try{const i=await Ql(e);await navigator.clipboard.writeText(i)}finally{l(!1)}}};return r.jsxs("div",{className:"flex items-center justify-end gap-2 px-8 py-2 mt-[-1rem] min-h-[2.25rem]",children:[e&&r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsx(B,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-50 hover:opacity-80",onClick:o,disabled:a,"aria-label":"Copy conversation folder path",children:r.jsx(va,{className:"h-3 w-3"})})}),r.jsx(he,{side:"top",className:"bg-slate-900 text-white",children:"Copy path to conversation history folder"})]}),s&&r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsxs("div",{className:"flex items-center gap-1.5 opacity-50 cursor-help",children:[r.jsx(Gs,{className:"h-3 w-3"}),r.jsx("span",{className:"text-[11px] font-medium tracking-tight",children:s})]})}),t&&r.jsxs(he,{side:"top",className:"bg-slate-900 text-white",children:["User: ",t]})]})]})}function li(){const s=Pe().state,{selectedProjectId:e,selectedThreadId:t}=s,{terminalState:n,dispatch:a}=Yt(t),{open:l,queuedCommand:o,outputLines:i,height:d,history:u,historyIndex:m,cwd:f,isRunning:p}=n,[h,x]=c.useState(""),[j,b]=c.useState([]),[g,R]=c.useState(!1),[I,w]=c.useState(!1),S=s.projects.flatMap(U=>U.threads).find(U=>U.threadId===t)?.path??null,E=!f||f==="."||f==="./"?S:f,T=c.useCallback(()=>{navigator.clipboard.writeText("terminal").then(()=>{w(!0),setTimeout(()=>w(!1),1500)})},[]),k=!E||E===S,y=c.useRef(null),C=c.useRef(null),_=c.useRef(null),D=c.useRef(0),P=c.useCallback(U=>{U.preventDefault(),R(!0)},[]),z=c.useCallback(()=>{R(!1)},[]),L=c.useCallback(U=>{if(g&&_.current){const le=_.current.getBoundingClientRect().bottom-U.clientY;le>=150&&le<=window.innerHeight*.8&&a({type:N.SetTerminalHeight,height:le})}},[g]);c.useEffect(()=>(g?(window.addEventListener("mousemove",L),window.addEventListener("mouseup",z),document.body.style.cursor="ns-resize",document.body.style.userSelect="none"):(window.removeEventListener("mousemove",L),window.removeEventListener("mouseup",z),document.body.style.cursor="",document.body.style.userSelect=""),()=>{window.removeEventListener("mousemove",L),window.removeEventListener("mouseup",z)}),[g,L,z]),c.useEffect(()=>{y.current&&(y.current.scrollTop=y.current.scrollHeight)},[j]),c.useEffect(()=>{b(i),D.current=i.length},[t]),c.useEffect(()=>{if(i.length===0)b([]),D.current=0;else if(i.length>D.current){const U=i.slice(D.current);b(q=>[...q,...U]),D.current=i.length}},[i]),c.useEffect(()=>{l&&!p&&C.current?.focus()},[l,p]);const W=c.useCallback(async U=>{if(!(!e||!t||!U.trim())){a({type:N.AppendTerminalLine,line:{type:"input",content:U}}),a({type:N.SetTerminalHistory,history:[U,...u.filter(q=>q!==U)].slice(0,50)}),a({type:N.SetTerminalHistoryIndex,index:-1}),x(""),a({type:N.SetTerminalRunning,isRunning:!0});try{const q=await ho(e,t,U,f);if(!q){a({type:N.AppendTerminalLine,line:{type:"system",content:"Command started but no output stream received."}}),a({type:N.SetTerminalRunning,isRunning:!1});return}const le=q.getReader(),fe=new TextDecoder;let ae="";for(;;){const{done:ce,value:V}=await le.read();if(ce)break;ae+=fe.decode(V,{stream:!0});const se=ae.split(`
|
|
10
|
+
`);ae=se.pop()||"";for(const ee of se)if(ee.trim())try{const ne=JSON.parse(ee);typeof ne=="string"?a({type:N.AppendTerminalLine,line:{type:"output",content:ne}}):ne.type==="error"?a({type:N.AppendTerminalLine,line:{type:"error",content:ne.message}}):ne.type==="cwd"&&a({type:N.SetTerminalCwd,cwd:ne.path})}catch{a({type:N.AppendTerminalLine,line:{type:"output",content:ee}})}}if(ae.trim())try{const ce=JSON.parse(ae);typeof ce=="string"?a({type:N.AppendTerminalLine,line:{type:"output",content:ce}}):ce.type==="error"?a({type:N.AppendTerminalLine,line:{type:"error",content:ce.message}}):ce.type==="cwd"&&a({type:N.SetTerminalCwd,cwd:ce.path})}catch{a({type:N.AppendTerminalLine,line:{type:"output",content:ae}})}}catch(q){a({type:N.AppendTerminalLine,line:{type:"error",content:q instanceof Error?q.message:"Failed to run command"}})}finally{a({type:N.SetTerminalRunning,isRunning:!1})}}},[e,t,f]);c.useEffect(()=>{o&&!p&&(W(o),a({type:N.ClearQueuedTerminalCommand}))},[o,p,a,W]);const G=U=>{if(U.key==="Enter")W(h);else if(U.key==="ArrowUp"){U.preventDefault();const q=m+1;q<u.length&&(a({type:N.SetTerminalHistoryIndex,index:q}),x(u[q]))}else if(U.key==="ArrowDown"){U.preventDefault();const q=m-1;q>=0?(a({type:N.SetTerminalHistoryIndex,index:q}),x(u[q])):(a({type:N.SetTerminalHistoryIndex,index:-1}),x(""))}};return l?r.jsxs("div",{ref:_,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:`${d}px`},children:[r.jsx("div",{className:"absolute top-0 left-0 right-0 h-1 cursor-ns-resize hover:bg-primary/50 transition-colors z-50",onMouseDown:P}),r.jsxs("div",{className:"flex items-center justify-between px-4 py-1.5 border-b border-white/10 bg-white/5",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ls,{className:"h-3.5 w-3.5 text-neutral-400"}),r.jsx(Re,{children:r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsx("span",{className:"text-xs font-medium text-neutral-400 cursor-pointer hover:text-neutral-200 transition-colors select-none",onClick:T,children:I?"Copied!":"Terminal"})}),r.jsx(he,{side:"bottom",children:r.jsx("span",{className:"font-mono text-xs",children:E||"/"})})]})}),!k&&r.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:E}),p&&r.jsxs("div",{className:"flex gap-1 items-center ml-2",children:[r.jsx("div",{className:"h-1 w-1 rounded-full bg-primary animate-pulse"}),r.jsx("span",{className:"text-[10px] text-neutral-500 italic",children:"processing..."})]})]}),r.jsx("div",{className:"flex items-center gap-1",children:r.jsx(B,{variant:"ghost",size:"icon",className:"h-6 w-6 text-neutral-500 hover:text-neutral-200 hover:bg-white/10",onClick:()=>a({type:N.ToggleTerminal}),children:r.jsx(tt,{className:"h-3.5 w-3.5"})})})]}),r.jsxs("div",{ref:y,className:"flex-1 overflow-y-auto p-4 space-y-0.5 terminal-scrollbar",onClick:U=>{U.target===U.currentTarget&&C.current?.focus()},children:[j.length===0&&!p&&r.jsx("div",{className:"text-neutral-600 italic text-xs",children:"Enter your commands below..."}),j.map((U,q)=>r.jsxs("div",{className:`whitespace-pre-wrap break-all leading-6 ${U.type==="input"?"flex items-start gap-2 text-neutral-200":U.type==="error"?"text-red-400":U.type==="system"?"text-blue-400":""}`,children:[U.type==="input"&&r.jsx(Gt,{className:"h-4 w-4 mt-1 shrink-0 text-blue-400/70"}),r.jsx("span",{children:U.content})]},q))]}),r.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-t border-white/5 bg-white/5",children:[!k&&r.jsx("span",{className:"text-blue-400 text-xs font-bold whitespace-nowrap",children:E.split("/").pop()}),r.jsx(Gt,{className:`h-4 w-4 text-blue-400 ${k?"":"-ml-1"}`}),r.jsx("input",{ref:C,type:"text",className:"flex-1 bg-transparent border-none outline-none text-neutral-200 placeholder:text-neutral-700 h-6",placeholder:p?"Running...":"Type a command...",value:h,onChange:U=>x(U.target.value),onKeyDown:G,disabled:p}),r.jsxs("div",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded border border-white/10 bg-white/5",children:[r.jsx(Na,{className:"h-3 w-3 text-neutral-600"}),r.jsx("span",{className:"text-[10px] text-neutral-600 uppercase font-bold",children:"Enter"})]})]})]}):null}function oi({threadId:s,onExit:e}){const{state:t}=Pe(),[n,a]=c.useState([]),[l,o]=c.useState(!0),[i,d]=c.useState(null),[u,m]=c.useState(0),[f,p]=c.useState(!1),h=c.useCallback(async()=>{if(s){o(!0),d(null);try{const y=await No(s);a(y.files||[]),m(0)}catch(y){d(y instanceof Error?y.message:"Failed to load diff")}finally{o(!1)}}},[s]);c.useEffect(()=>{h()},[h]);const x=y=>{if(y.hunks.length===0)return null;let C=1/0,_=0;return y.hunks.forEach(D=>{const P=Math.min(D.oldStart,D.newStart),z=D.oldStart+D.oldLines,L=D.newStart+D.newLines,W=Math.max(z,L);C=Math.min(C,P),_=Math.max(_,W)}),C===1/0?null:{startLine:Math.max(1,C-2),endLine:_+2}},j=(y,C,_)=>y.split(`
|
|
11
|
+
`).slice(C-1,_).join(`
|
|
12
|
+
`),b=y=>{const C=x(y);return C?C.startLine<=1:!0},g=y=>{const C=y.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"}[C]||"plaintext"},R=y=>{switch(y){case"added":return r.jsx("span",{className:"status-badge font-mono text-xs font-semibold text-green-500",children:"A"});case"deleted":return r.jsx("span",{className:"status-badge font-mono text-xs font-semibold text-red-500",children:"D"});case"untracked":return r.jsx("span",{className:"status-badge font-mono text-xs font-semibold text-green-500",children:"U"});case"renamed":return r.jsx("span",{className:"status-badge font-mono text-xs font-semibold text-blue-500",children:"R"});default:return r.jsx("span",{className:"status-badge font-mono text-xs font-semibold text-orange-500",children:"M"})}},I=c.useMemo(()=>n.map(y=>{let C=0,_=0;return y.hunks.forEach(D=>{D.changes.forEach(P=>{P.type==="add"&&C++,P.type==="delete"&&_++})}),{additions:C,deletions:_}}),[n]),w=n[u],S=w?f?w.oldContent:(()=>{const y=x(w);return y?j(w.oldContent,y.startLine,y.endLine):w.oldContent})():"",E=w?f?w.newContent:(()=>{const y=x(w);return y?j(w.newContent,y.startLine,y.endLine):w.newContent})():"",T=c.useMemo(()=>I.reduce((y,C)=>y+C.additions,0),[I]),k=c.useMemo(()=>I.reduce((y,C)=>y+C.deletions,0),[I]);return l?r.jsx("div",{className:"flex h-full items-center justify-center",children:r.jsx(Te,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):i?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-4",children:[r.jsx("p",{className:"text-destructive",children:i}),r.jsx(B,{variant:"outline",onClick:e,children:"Go Back"})]}):n.length===0?r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-4",children:[r.jsx("p",{className:"text-muted-foreground",children:"No changes to review"}),r.jsx(B,{variant:"outline",onClick:e,children:"Go Back"})]}):r.jsxs("div",{className:"diff-view-root flex h-full flex-col",children:[r.jsxs("div",{className:"diff-toolbar flex h-12 shrink-0 items-center justify-between border-b border-border bg-background px-4",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(B,{variant:"ghost",size:"icon",onClick:e,className:"h-8 w-8",children:r.jsx(tt,{className:"h-4 w-4"})}),r.jsx("span",{className:"text-sm font-medium",children:"Review Changes"}),r.jsxs("span",{className:"text-xs text-muted-foreground",children:[n.length," file",n.length!==1?"s":""]}),r.jsxs("span",{className:"text-xs text-green-500",children:["+",T]}),r.jsxs("span",{className:"text-xs text-red-500",children:["-",k]})]}),w&&r.jsx(B,{variant:"ghost",size:"sm",onClick:()=>p(y=>!y),className:"h-8 gap-1 px-2 text-xs",children:f?r.jsxs(r.Fragment,{children:[r.jsx(wa,{className:"h-3 w-3"})," Show changes only"]}):r.jsxs(r.Fragment,{children:[r.jsx(Sa,{className:"h-3 w-3"})," Show full file"]})})]}),r.jsxs("div",{className:"diff-body flex flex-1 overflow-hidden",children:[r.jsx("div",{className:"diff-file-list flex w-64 shrink-0 flex-col border-r border-border",children:r.jsx(Qe,{className:"flex-1",children:r.jsx("div",{className:"p-2 space-y-0.5",children:n.map((y,C)=>r.jsx("button",{onClick:()=>m(C),className:O("file-list-item w-full rounded-md px-2 py-2 text-left transition-colors hover:bg-accent",u===C&&"bg-accent"),children:r.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[r.jsx("span",{className:"file-name truncate text-xs font-medium flex-1 min-w-0",children:y.path}),R(y.status)]})},y.path))})})}),r.jsx("div",{className:"diff-editor-panel flex flex-1 flex-col overflow-hidden",children:w?r.jsxs(r.Fragment,{children:[r.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:[R(w.status),r.jsx("span",{className:"text-xs font-medium truncate",children:w.path}),w.oldPath&&r.jsxs("span",{className:"text-xs text-muted-foreground truncate",children:["← ",w.oldPath]})]}),r.jsx("div",{className:"flex-1 overflow-hidden",children:r.jsx(Ca,{original:S,modified:E,language:g(w.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||b(w)?"on":"off",diffWordWrap:"on",originalEditable:!1,automaticLayout:!0}})})]}):null})]})]})}function ii(){const{state:s,dispatch:e}=Pe(),[t,n]=c.useState(null),[a,l]=c.useState(""),o=c.useRef(""),i=c.useRef(""),d=c.useRef([]),u=c.useRef(!1),m=c.useRef(null),f=c.useRef(null),p=c.useRef(()=>{}),[h,x]=c.useState(null),j=c.useRef(!1),b=c.useRef(null),{selectedThreadId:g,selectedProjectId:R,messages:I,queuedChatMessages:w,isStreaming:S,streamingSegments:E,streamingModel:T,isCreatingProject:k,processingThreadIds:y,projects:C}=s,P=!!(g&&y.includes(g))&&!(h===g&&!S),z=R&&g?C.find(V=>V.projectId===R)?.threads.find(V=>V.threadId===g):void 0,L=c.useCallback(V=>{m.current=null,f.current=null;const se=d.current,ee=cl(se)||"...";if(b.current&&se.length===0){const ie={messageId:`msg-${Date.now()}-error`,sender:"agent",content:`Error: ${b.current}`,contentType:"text",timestamp:new Date().toISOString(),model:s.streamingModel||V,isThinking:!1};e({type:N.AddMessage,message:ie}),e({type:N.ResetStream}),b.current=null;return}const ne={messageId:`msg-${Date.now()}-agent`,sender:"agent",content:ee,contentType:"markdown",timestamp:new Date().toISOString(),model:s.streamingModel||V,isThinking:!1};o.current="",i.current="",d.current=[],b.current=null,e({type:N.AddMessage,message:ne}),e({type:N.ResetStream}),g&&e({type:N.MarkThreadCompleted,threadId:g})},[s.streamingModel,e,g]);c.useEffect(()=>{p.current=L},[L]);const W=c.useCallback(()=>{g&&x(g),m.current&&(m.current.abort(),m.current=null),f.current&&(f.current(),f.current=null),L(s.streamingModel||"default")},[g,L,s.streamingModel]);c.useEffect(()=>{j.current&&!S&&m.current&&(m.current.abort(),m.current=null,f.current&&(f.current(),f.current=null),p.current(T||"default")),j.current=S},[S,T]),c.useEffect(()=>()=>{m.current&&(m.current.abort(),m.current=null),f.current&&(f.current(),f.current=null),e({type:N.ResetStream})},[g,e]),c.useEffect(()=>{if(!g)return;let V=!1;async function se(){try{const ee=await Jl(g);V||e({type:N.SetMessages,messages:ee.messages})}catch(ee){console.error("Failed to load chat history:",ee),V||e({type:N.SetMessages,messages:[]})}}return se(),()=>{V=!0}},[g,R,e]);const G=c.useCallback(async(V,se,ee,ne)=>{if(!g)return;n(null),x(null),m.current&&m.current.abort(),f.current&&f.current();const ie={messageId:`msg-${Date.now()}`,sender:"user",content:V,contentType:"text",timestamp:new Date().toISOString(),model:se,attachments:ee.map(ue=>({fileName:ue.fileName,content:ue.content}))};e({type:N.AddMessage,message:ie});const Ie=V.trim().replace(/\n/g," ").slice(0,100);R&&g&&(Vl(g,{title:Ie}).catch(ue=>{console.error("Failed to update thread title:",ue)}),e({type:N.UpdateThreadTitle,projectId:R,threadId:g,title:Ie})),e({type:N.ResetStream}),e({type:N.SetStreaming,isStreaming:!0}),o.current="",u.current=!1;const pe=new AbortController;m.current=pe;try{const ue=await Yl(g,V,se,ee,pe.signal,ne);ue&&(f.current=Zl(ue,v=>{if(v.type!=="message"){if(v.type==="toolcall_delta"){if(v.partial?.content?.[0]?.id&&v.delta){const $=v.partial.content[0].id,K=v.partial.content[0].name;e({type:N.UpdateToolCallProgress,toolCallId:$,progress:{toolCallId:$,toolName:K,delta:v.delta,partial:v.partial}})}return}if(v.model&&e({type:N.SetStreamModel,model:v.model}),v.type==="thinking"||v.isThinking){i.current+=v.content||"";const $=ks(d.current,"thinking",v.content||"");d.current=$,e({type:N.AppendStreamChunk,chunkType:"thinking",content:v.content||"",segments:$})}else if(v.type==="result"){u.current=!0,o.current=v.content||"";const $=Os(d.current,v.content||"");d.current=$,e({type:N.SetStreamContent,content:v.content||""})}else{if(u.current)return;o.current+=v.content||"";const $=ks(d.current,"content",v.content||"");d.current=$,e({type:N.AppendStreamChunk,chunkType:"content",content:v.content||"",segments:$})}}},()=>{p.current(se)},v=>{v.includes("AbortError")||v.includes("canceled")||v.includes("BodyStreamBuffer was aborted")||(b.current=v,n(v))},v=>{if(v.role==="assistant"){const $=v.content??"",K=typeof $=="string"?$:JSON.stringify($);let Q=!1;if(typeof $=="object"&&Array.isArray($)&&$.length>0)Q=!0;else if(typeof K=="string"&&K.trim().startsWith("["))try{const te=JSON.parse(K);Q=Array.isArray(te)&&te.length>0}catch{}if(Q)u.current=!0,o.current=K,d.current=Os(d.current,K),e({type:N.SetStreamContent,content:K});else{o.current+=K;const te=ks(d.current,"content",K);d.current=te,e({type:N.AppendStreamChunk,chunkType:"content",content:K,segments:te})}}}))}catch(ue){if(ue instanceof Error&&ue.name==="AbortError"||ue instanceof Error&&ue.message.includes("BodyStreamBuffer was aborted"))return;n(ue instanceof Error?ue.message:"Failed to send message. Please ensure the CLI server is running on localhost:641"),b.current=ue instanceof Error?ue.message:"Failed to send message. Please ensure the CLI server is running on localhost:641",e({type:N.ResetStream})}},[g,R,e]),U=c.useMemo(()=>g?w.filter(V=>V.threadId===g):[],[g,w]),q=c.useRef(!1);c.useEffect(()=>{if(S||!g||U.length===0||q.current)return;const[V]=U;q.current=!0,e({type:N.RemoveQueuedChatMessage,queuedMessageId:V.id});const se=setTimeout(()=>{G(V.message,V.model,V.attachments,V.provider),q.current=!1},0);return()=>{clearTimeout(se),q.current=!1}},[e,G,S,U,g]);const le=c.useCallback(V=>{const se=U.find(ee=>ee.id===V);e({type:N.RemoveQueuedChatMessage,queuedMessageId:V}),!(!se||S||I.length>0||!g)&&G(se.message,se.model,se.attachments,se.provider)},[e,G,S,I.length,U,g]),fe=V=>{l(V)},ae=()=>{e({type:N.SetReviewMode,reviewMode:!1})},{reviewMode:ce}=s;return r.jsxs("div",{className:"flex h-full flex-col",children:[ce&&g?r.jsx(oi,{threadId:g,onExit:ae}):r.jsx(ri,{messages:I,isStreaming:S,streamingSegments:E,streamingModel:T,isCreatingProject:k,isProcessingThread:P,error:t,onClearError:()=>n(null),onSuggestionClick:fe}),r.jsxs("div",{className:"relative mx-auto w-full max-w-3xl",children:[r.jsx(Mo,{onSend:G,onStop:W,isStreaming:S,disabled:!g&&!k,initialValue:a,queuedMessages:U,onRemoveQueuedMessage:le}),r.jsx(ai,{branchName:z?.currentBranch,threadId:g??void 0})]}),r.jsx(li,{})]})}const Mn=Ea,Dn=ka,ci=c.forwardRef((s,e)=>{const t=F.c(14);let n,a,l,o;t[0]!==s?({className:a,inset:l,children:n,...o}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l,t[4]=o):(n=t[1],a=t[2],l=t[3],o=t[4]);const i=l&&"pl-8";let d;t[5]!==a||t[6]!==i?(d=O("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]=d):d=t[7];let u;t[8]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx(Gt,{className:"ml-auto"}),t[8]=u):u=t[8];let m;return t[9]!==n||t[10]!==o||t[11]!==e||t[12]!==d?(m=r.jsxs(Rr,{ref:e,className:d,...o,children:[n,u]}),t[9]=n,t[10]=o,t[11]=e,t[12]=d,t[13]=m):m=t[13],m});ci.displayName=Rr.displayName;const di=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("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",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(Pr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});di.displayName=Pr.displayName;const Js=c.forwardRef((s,e)=>{const t=F.c(11);let n,a,l;t[0]!==s?({className:n,sideOffset:l,...a}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l):(n=t[1],a=t[2],l=t[3]);const o=l===void 0?4:l;let i;t[4]!==n?(i=O("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",n),t[4]=n,t[5]=i):i=t[5];let d;return t[6]!==a||t[7]!==e||t[8]!==o||t[9]!==i?(d=r.jsx(Ta,{children:r.jsx(Mr,{ref:e,sideOffset:o,className:i,...a})}),t[6]=a,t[7]=e,t[8]=o,t[9]=i,t[10]=d):d=t[10],d});Js.displayName=Mr.displayName;const it=c.forwardRef((s,e)=>{const t=F.c(11);let n,a,l;t[0]!==s?({className:n,inset:a,...l}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l):(n=t[1],a=t[2],l=t[3]);const o=a&&"pl-8";let i;t[4]!==n||t[5]!==o?(i=O("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,n),t[4]=n,t[5]=o,t[6]=i):i=t[6];let d;return t[7]!==l||t[8]!==e||t[9]!==i?(d=r.jsx(Dr,{ref:e,className:i,...l}),t[7]=l,t[8]=e,t[9]=i,t[10]=d):d=t[10],d});it.displayName=Dr.displayName;const ui=c.forwardRef((s,e)=>{const t=F.c(14);let n,a,l,o;t[0]!==s?({className:l,children:a,checked:n,...o}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l,t[4]=o):(n=t[1],a=t[2],l=t[3],o=t[4]);let i;t[5]!==l?(i=O("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 d;t[7]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:r.jsx(Fr,{children:r.jsx(et,{className:"h-4 w-4"})})}),t[7]=d):d=t[7];let u;return t[8]!==n||t[9]!==a||t[10]!==o||t[11]!==e||t[12]!==i?(u=r.jsxs(Ar,{ref:e,className:i,checked:n,...o,children:[d,a]}),t[8]=n,t[9]=a,t[10]=o,t[11]=e,t[12]=i,t[13]=u):u=t[13],u});ui.displayName=Ar.displayName;const mi=c.forwardRef((s,e)=>{const t=F.c(12);let n,a,l;t[0]!==s?({className:a,children:n,...l}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l):(n=t[1],a=t[2],l=t[3]);let o;t[4]!==a?(o=O("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=r.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:r.jsx(Fr,{children:r.jsx(Ia,{className:"h-2 w-2 fill-current"})})}),t[6]=i):i=t[6];let d;return t[7]!==n||t[8]!==l||t[9]!==e||t[10]!==o?(d=r.jsxs(Lr,{ref:e,className:o,...l,children:[i,n]}),t[7]=n,t[8]=l,t[9]=e,t[10]=o,t[11]=d):d=t[11],d});mi.displayName=Lr.displayName;const fi=c.forwardRef((s,e)=>{const t=F.c(11);let n,a,l;t[0]!==s?({className:n,inset:a,...l}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l):(n=t[1],a=t[2],l=t[3]);const o=a&&"pl-8";let i;t[4]!==n||t[5]!==o?(i=O("px-2 py-1.5 text-sm font-semibold",o,n),t[4]=n,t[5]=o,t[6]=i):i=t[6];let d;return t[7]!==l||t[8]!==e||t[9]!==i?(d=r.jsx(Or,{ref:e,className:i,...l}),t[7]=l,t[8]=e,t[9]=i,t[10]=d):d=t[10],d});fi.displayName=Or.displayName;const pi=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("-mx-1 my-1 h-px bg-muted",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx($r,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});pi.displayName=$r.displayName;const hi=1,gi=1e6;let _s=0;function xi(){return _s=(_s+1)%Number.MAX_SAFE_INTEGER,_s.toString()}const Rs=new Map,gr=s=>{if(Rs.has(s))return;const e=setTimeout(()=>{Rs.delete(s),Kt({type:"REMOVE_TOAST",toastId:s})},gi);Rs.set(s,e)},ji=(s,e)=>{switch(e.type){case"ADD_TOAST":return{...s,toasts:[e.toast,...s.toasts].slice(0,hi)};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?gr(t):s.toasts.forEach(n=>{gr(n.id)}),{...s,toasts:s.toasts.map(n=>n.id===t||t===void 0?{...n,open:!1}:n)}}case"REMOVE_TOAST":return e.toastId===void 0?{...s,toasts:[]}:{...s,toasts:s.toasts.filter(t=>t.id!==e.toastId)}}},ns=[];let as={toasts:[]};function Kt(s){as=ji(as,s),ns.forEach(e=>{e(as)})}function re({...s}){const e=xi(),t=a=>Kt({type:"UPDATE_TOAST",toast:{...a,id:e}}),n=()=>Kt({type:"DISMISS_TOAST",toastId:e});return Kt({type:"ADD_TOAST",toast:{...s,id:e,open:!0,onOpenChange:a=>{a||n()}}}),{id:e,dismiss:n,update:t}}function An(){const s=F.c(5),[e,t]=c.useState(as);let n;s[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>(ns.push(t),()=>{const o=ns.indexOf(t);o>-1&&ns.splice(o,1)}),s[0]=n):n=s[0];let a;s[1]!==e?(a=[e],s[1]=e,s[2]=a):a=s[2],c.useEffect(n,a);let l;return s[3]!==e?(l={...e,toast:re,dismiss:yi},s[3]=e,s[4]=l):l=s[4],l}function yi(s){return Kt({type:"DISMISS_TOAST",toastId:s})}const xr="VS Code";function bi({projectId:s,threadId:e,openWith:t}){const[n,a]=c.useState(!1),[l,o]=c.useState([]),[i,d]=c.useState(t||xr),[u,m]=c.useState(!0);c.useEffect(()=>{(async()=>{try{const x=await Fl();o(x),!i&&x.length>0&&d(x[0])}catch(x){console.error("Failed to fetch available programs:",x),o([xr])}finally{m(!1)}})()},[]),c.useEffect(()=>{t&&l.includes(t)&&d(t)},[t,l,d]);const f=async h=>{try{a(!0),d(h),await so(s,h),e?await to(e,h):await eo(s,h),re({title:"Success",description:`Opened project in ${h}`})}catch(x){console.error(`Failed to open project in ${h}:`,x);let j=`Failed to open project in ${h}`;if(x instanceof Error){const b=x;b.details?j=b.details:j=x.message}re({title:"Error",description:j,variant:"destructive"})}finally{a(!1)}},p=async()=>{await f(i)};return u?r.jsx(B,{variant:"outline",size:"sm",className:"h-8",disabled:!0,children:"Loading..."}):r.jsxs("div",{className:"flex items-center gap-0",children:[r.jsxs(B,{variant:"outline",size:"sm",className:"h-8 rounded-r-none border-r-0",disabled:n,onClick:p,children:["Open in ",i]}),r.jsxs(Mn,{children:[r.jsx(Dn,{asChild:!0,children:r.jsx(B,{variant:"outline",size:"sm",className:"h-8 w-8 rounded-l-none px-1",disabled:n,children:r.jsx(ct,{className:"h-3.5 w-3.5"})})}),r.jsx(Js,{align:"end",children:l.map(h=>r.jsx(it,{onClick:()=>f(h),disabled:n,children:h},h))})]})]})}const vi=Qt("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 Ni(s){const e=F.c(10);let t,n,a;e[0]!==s?({className:t,variant:a,...n}=s,e[0]=s,e[1]=t,e[2]=n,e[3]=a):(t=e[1],n=e[2],a=e[3]);let l;e[4]!==t||e[5]!==a?(l=O(vi({variant:a}),t),e[4]=t,e[5]=a,e[6]=l):l=e[6];let o;return e[7]!==n||e[8]!==l?(o=r.jsx("div",{className:l,...n}),e[7]=n,e[8]=l,e[9]=o):o=e[9],o}const xt=c.forwardRef((s,e)=>{const t=F.c(10);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("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",n),t[3]=n,t[4]=l):l=t[4];let o;t[5]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx(_a,{className:O("flex items-center justify-center text-current"),children:r.jsx(et,{className:"h-4 w-4"})}),t[5]=o):o=t[5];let i;return t[6]!==a||t[7]!==e||t[8]!==l?(i=r.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});xt.displayName=Gr.displayName;const wi={"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(wi).reduce((s,[e,t])=>(s[e]=t.appName,s),{});var ge;(function(s){s.PullRequest="pull-request",s.Direct="direct"})(ge||(ge={}));ge.PullRequest+"",ge.PullRequest,ge.Direct+"",ge.Direct;const Si={bun:{id:"bun",label:"bun"},npm:{id:"npm",label:"npm"},yarn:{id:"yarn",label:"yarn"},pnpm:{id:"pnpm",label:"pnpm"}},Je=Ma,Ci=Ra,Ln=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("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",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(zr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Ln.displayName=zr.displayName;const Ue=c.forwardRef((s,e)=>{const t=F.c(13);let n,a,l;t[0]!==s?({className:a,children:n,...l}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l):(n=t[1],a=t[2],l=t[3]);let o;t[4]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx(Ln,{}),t[4]=o):o=t[4];let i;t[5]!==a?(i=O("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 d;t[7]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsxs(Pa,{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:[r.jsx(tt,{className:"h-4 w-4"}),r.jsx("span",{className:"sr-only",children:"Close"})]}),t[7]=d):d=t[7];let u;return t[8]!==n||t[9]!==l||t[10]!==e||t[11]!==i?(u=r.jsxs(Ci,{children:[o,r.jsxs(Ur,{ref:e,className:i,...l,children:[n,d]})]}),t[8]=n,t[9]=l,t[10]=e,t[11]=i,t[12]=u):u=t[12],u});Ue.displayName=Ur.displayName;const Be=s=>{const e=F.c(8);let t,n;e[0]!==s?({className:t,...n}=s,e[0]=s,e[1]=t,e[2]=n):(t=e[1],n=e[2]);let a;e[3]!==t?(a=O("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]!==n||e[6]!==a?(l=r.jsx("div",{className:a,...n}),e[5]=n,e[6]=a,e[7]=l):l=e[7],l};Be.displayName="DialogHeader";const He=s=>{const e=F.c(8);let t,n;e[0]!==s?({className:t,...n}=s,e[0]=s,e[1]=t,e[2]=n):(t=e[1],n=e[2]);let a;e[3]!==t?(a=O("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]!==n||e[6]!==a?(l=r.jsx("div",{className:a,...n}),e[5]=n,e[6]=a,e[7]=l):l=e[7],l};He.displayName="DialogFooter";const $e=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("text-lg font-semibold leading-none tracking-tight",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(Br,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});$e.displayName=Br.displayName;const Fe=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("text-sm text-muted-foreground",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(Hr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Fe.displayName=Hr.displayName;const qe=c.forwardRef((s,e)=>{const t=F.c(11);let n,a,l;t[0]!==s?({className:n,type:l,...a}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l):(n=t[1],a=t[2],l=t[3]);let o;t[4]!==n?(o=O("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",n),t[4]=n,t[5]=o):o=t[5];let i;return t[6]!==a||t[7]!==e||t[8]!==o||t[9]!==l?(i=r.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});qe.displayName="Input";const Ti=Qt("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Se=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O(Ti(),n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(qr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Se.displayName=qr.displayName;const Ft=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("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",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx("textarea",{className:l,ref:e,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Ft.displayName="Textarea";function Ii({projectId:s,threadId:e}){const{state:t,dispatch:n}=Pe(),[a,l]=c.useState(!1),[o,i]=c.useState(0),[d,u]=c.useState(!1),[m,f]=c.useState(""),[p,h]=c.useState(!1),[x,j]=c.useState(!1),[b,g]=c.useState(!1),[R,I]=c.useState(""),[w,S]=c.useState(""),[E,T]=c.useState(""),[k,y]=c.useState(!1),[C,_]=c.useState(!1),[D,P]=c.useState(null),[z,L]=c.useState(!1),[W,G]=c.useState(!1),[U,q]=c.useState([]),[le,fe]=c.useState(!1),[ae,ce]=c.useState([]),[V,se]=c.useState(!1),ee=10,[ne,ie]=c.useState(!1),[Ie,pe]=c.useState(null),[ue,v]=c.useState(!1),[$,K]=c.useState(""),[Q,te]=c.useState(""),[me,_e]=c.useState(ir()),[ke,Ye]=c.useState(or()),We=t.projects.find(M=>M.projectId===s),Xe=We?.commitMethod===ge.Direct,De=c.useCallback(async()=>{if(e)try{const M=await ao(e);l(M.hasChanges),i(M.changedFilesCount),u(M.hasUnpushedCommits),f(M.currentBranch)}catch(M){console.error("Failed to fetch git status:",M)}},[e]),Ve=c.useCallback(async()=>{if(e)try{const M=await uo(e);ie(M.canCreateRepo),pe(M.repoUrl||null)}catch(M){console.error("Failed to fetch GitHub status:",M)}},[e]);c.useEffect(()=>{De()},[De]),c.useEffect(()=>{Ve()},[Ve]),c.useEffect(()=>{ue&&We?.name&&!$&&K(We.name)},[ue,We?.name,$]),c.useEffect(()=>{Ye(or())},[]),c.useEffect(()=>{Il(ke)},[ke]),c.useEffect(()=>{_e(ir())},[]),c.useEffect(()=>{El(me)},[me]),c.useEffect(()=>{x&&ke&&!R.trim()&&e&&(async()=>{if(e)try{y(!0);const X=t.projectModelSelections[s];let Ee,Ce;if(X){const J=X.split("/");J.length>=2?(Ee=J[0],Ce=J.slice(1).join("/")):Ce=X}const A=await mr(e,Ce,Ee);I(A)}catch(X){console.error("Failed to generate commit message:",X);const Ee=X instanceof Error?X.message:"Failed to generate commit message";re({title:"Error",description:Ee,variant:"destructive"})}finally{y(!1)}})()},[x,ke,R,e,s,t.projectModelSelections]),c.useEffect(()=>{!t.isStreaming&&t.completedThreadIds.includes(t.selectedThreadId||"")&&(De(),n({type:N.ClearThreadCompleted,threadId:t.selectedThreadId||""}))},[t.isStreaming,t.completedThreadIds,t.selectedThreadId,De,n]);const mt=async()=>{if(!R.trim()){re({title:"Error",description:"Commit message is required",variant:"destructive"});return}if(!e){re({title:"Error",description:"No thread selected",variant:"destructive"});return}try{h(!0),await lo(e,R),re({title:"Success",description:"Changes committed successfully"}),I(""),j(!1),await De()}catch(M){console.error("Failed to commit:",M);const X=M instanceof Error?M.message:"Failed to commit changes";re({title:"Error",description:X,variant:"destructive"})}finally{h(!1)}},Ke=async()=>{if(!e){re({title:"Error",description:"No thread selected",variant:"destructive"});return}try{y(!0);const M=t.projectModelSelections[s];let X,Ee;if(M){const A=M.split("/");A.length>=2?(X=A[0],Ee=A.slice(1).join("/")):Ee=M}const Ce=await mr(e,Ee,X);I(Ce)}catch(M){console.error("Failed to generate commit message:",M);const X=M instanceof Error?M.message:"Failed to generate commit message";re({title:"Error",description:X,variant:"destructive"})}finally{y(!1)}},Le=async()=>{if(!e){re({title:"Error",description:"No thread selected",variant:"destructive"});return}try{h(!0),await io(e),re({title:"Success",description:"Fetched latest changes from origin"}),await De()}catch(M){console.error("Failed to fetch:",M);const X=M instanceof Error?M.message:"Failed to fetch from origin";re({title:"Error",description:X,variant:"destructive"})}finally{h(!1)}},st=async()=>{if(!e){re({title:"Error",description:"No thread selected",variant:"destructive"});return}try{h(!0),await fr(e),re({title:"Success",description:"Changes pushed successfully"}),await De()}catch(M){console.error("Failed to push:",M);const X=M instanceof Error?M.message:"Failed to push changes";re({title:"Error",description:X,variant:"destructive"})}finally{h(!1)}},rt=async()=>{if(!e){re({title:"Error",description:"No thread selected",variant:"destructive"});return}try{h(!0);const M=await pr(e,w,E);re({title:"Success",description:"Pull request created successfully"}),M.prUrl&&window.open(M.prUrl,"_blank"),S(""),T(""),g(!1),await De()}catch(M){console.error("Failed to create PR:",M);const X=M instanceof Error?M.message:"Failed to create PR";X.includes("push the current branch")||X.includes("--head flag")?(P({title:w,description:E}),g(!1),_(!0)):re({title:"Error",description:X,variant:"destructive"})}finally{h(!1)}},Ge=async()=>{if(!e){re({title:"Error",description:"No thread selected",variant:"destructive"});return}try{h(!0);const M=await mo(e,$,Q,me);re({title:"Success",description:"GitHub repository created successfully"}),M.repoUrl&&setTimeout(()=>{window.open(M.repoUrl,"_blank")},3e3),K(""),te(""),_e(!1),v(!1),await Ve(),await De()}catch(M){console.error("Failed to create repo:",M);const X=M instanceof Error?M.message:"Failed to create repository";re({title:"Error",description:X,variant:"destructive"})}finally{h(!1)}},Y=async()=>{if(!e){re({title:"Error",description:"No thread selected",variant:"destructive"});return}try{L(!0);const M=t.projectModelSelections[s];let X,Ee;if(M){const A=M.split("/");A.length>=2?(X=A[0],Ee=A.slice(1).join("/")):Ee=M}const Ce=await oo(e,Ee,X);S(Ce.title),T(Ce.description),re({title:"Success",description:"PR title and description generated"})}catch(M){console.error("Failed to generate PR info:",M);const X=M instanceof Error?M.message:"Failed to generate PR info";re({title:"Error",description:X,variant:"destructive"})}finally{L(!1)}},nt=async()=>{if(!(!e||!D))try{h(!0),await fr(e),re({title:"Success",description:"Branch pushed successfully"});const M=await pr(e,D.title,D.description);re({title:"Success",description:"Pull request created successfully"}),M.prUrl&&window.open(M.prUrl,"_blank"),S(""),T(""),P(null),_(!1),await De()}catch(M){console.error("Failed to push and create PR:",M);const X=M instanceof Error?M.message:"Failed to complete operation";re({title:"Error",description:X,variant:"destructive"})}finally{h(!1)}},ve=async()=>{if(!e){re({title:"Error",description:"No thread selected",variant:"destructive"});return}try{fe(!0);const M=await co(e,100);q(M),ce(M.slice(0,ee)),G(!0)}catch(M){console.error("Failed to fetch git history:",M);const X=M instanceof Error?M.message:"Failed to fetch git history";re({title:"Error",description:X,variant:"destructive"})}finally{fe(!1)}},at=()=>{V||(se(!0),setTimeout(()=>{const M=ae.length+ee,X=U.slice(0,M);ce(X),se(!1)},300))},ft=M=>{const X=M.currentTarget;X.scrollHeight-X.scrollTop-X.clientHeight<100&&ae.length<U.length&&!V&&at()};return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center gap-0",children:[r.jsx(Re,{children:r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsxs(B,{variant:"outline",size:"sm",className:"h-8 rounded-r-none border-r-0 gap-1.5",disabled:!a||p,onClick:()=>j(!0),children:[r.jsx(Da,{className:"h-3.5 w-3.5"}),"Commit",a&&o>0&&r.jsx(Ni,{variant:"secondary",className:"h-4 px-1 text-[10px] font-medium",children:o})]})}),r.jsx(he,{children:a?`Commit ${o} changed file${o!==1?"s":""}`:"No changes to commit"})]})}),r.jsxs(Mn,{children:[r.jsx(Dn,{asChild:!0,children:r.jsx(B,{variant:"outline",size:"sm",className:"h-8 w-8 rounded-l-none px-1",disabled:p,children:r.jsx(ct,{className:"h-3.5 w-3.5"})})}),r.jsxs(Js,{align:"end",children:[r.jsxs(it,{onClick:Le,disabled:p,children:[r.jsx(Aa,{className:"h-3.5 w-3.5 mr-2"}),"Fetch"]}),r.jsxs(it,{onClick:st,disabled:!d||p,children:[r.jsx(La,{className:"h-3.5 w-3.5 mr-2"}),"Push Commits"]}),r.jsxs(it,{onClick:ve,disabled:p||le,children:[r.jsx(Oa,{className:"h-3.5 w-3.5 mr-2"}),"History"]}),!Xe&&r.jsxs(it,{onClick:()=>g(!0),disabled:p,children:[r.jsx($a,{className:"h-3.5 w-3.5 mr-2"}),"Create Pull Request"]}),ne&&r.jsxs(it,{onClick:()=>v(!0),disabled:p,children:[r.jsx(Fa,{className:"h-3.5 w-3.5 mr-2"}),"Create Repo"]}),Ie&&r.jsxs(it,{onClick:()=>window.open(Ie,"_blank"),disabled:p,children:[r.jsx(Jt,{className:"h-3.5 w-3.5 mr-2"}),"View in GitHub"]})]})]})]}),r.jsx(Je,{open:x,onOpenChange:j,children:r.jsxs(Ue,{children:[r.jsxs(Be,{children:[r.jsx($e,{children:"Commit Changes"}),r.jsxs(Fe,{children:["Enter a commit message for your changes on branch ",m]})]}),r.jsxs("div",{className:"grid gap-4 py-4",children:[r.jsxs("div",{className:"grid gap-2",children:[r.jsx(Se,{htmlFor:"commit-message",children:"Commit Message"}),r.jsxs("div",{className:"relative",children:[r.jsx(Ft,{id:"commit-message",placeholder:"Enter commit message...",value:R,onChange:M=>I(M.target.value),rows:4,className:"pr-10"}),r.jsx(Re,{children:r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsx(B,{type:"button",variant:"ghost",size:"icon",className:"absolute top-2 right-2 h-6 w-6",onClick:Ke,disabled:k||p,children:k?r.jsx(Te,{className:"h-3.5 w-3.5 animate-spin"}):r.jsx(sr,{className:"h-3.5 w-3.5"})})}),r.jsx(he,{children:k?"Generating commit message...":"Generate commit message with AI"})]})})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(xt,{id:"auto-generate",checked:ke,onCheckedChange:M=>Ye(M===!0)}),r.jsx(Se,{htmlFor:"auto-generate",className:"text-sm font-normal",children:"Auto generate commit messages"})]})]}),r.jsxs(He,{children:[r.jsx(B,{variant:"outline",onClick:()=>j(!1),disabled:p,children:"Cancel"}),r.jsx(B,{onClick:mt,disabled:p||!R.trim(),children:p?"Committing...":"Commit"})]})]})}),r.jsx(Je,{open:b,onOpenChange:g,children:r.jsxs(Ue,{children:[r.jsxs(Be,{children:[r.jsx($e,{children:"Create Pull Request"}),r.jsxs(Fe,{children:["Create a pull request for branch ",m]})]}),r.jsxs("div",{className:"grid gap-4 py-4",children:[r.jsxs("div",{className:"grid gap-2",children:[r.jsx(Se,{htmlFor:"pr-title",children:"Title (optional)"}),r.jsx(qe,{id:"pr-title",placeholder:m||"Enter PR title...",value:w,onChange:M=>S(M.target.value)})]}),r.jsxs("div",{className:"grid gap-2",children:[r.jsx(Se,{htmlFor:"pr-description",children:"Description (optional)"}),r.jsxs("div",{className:"relative",children:[r.jsx(Ft,{id:"pr-description",placeholder:"Enter PR description...",value:E,onChange:M=>T(M.target.value),rows:4,className:"pr-10"}),r.jsx(Re,{children:r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsx(B,{type:"button",variant:"ghost",size:"icon",className:"absolute top-2 right-2 h-6 w-6",onClick:Y,disabled:z||p,children:z?r.jsx(Te,{className:"h-3.5 w-3.5 animate-spin"}):r.jsx(sr,{className:"h-3.5 w-3.5"})})}),r.jsx(he,{children:z?"Generating PR description...":"Generate PR title and description with AI"})]})})]})]})]}),r.jsxs(He,{children:[r.jsx(B,{variant:"outline",onClick:()=>g(!1),disabled:p,children:"Cancel"}),r.jsx(B,{onClick:rt,disabled:p,children:p?"Creating...":"Create PR"})]})]})}),r.jsx(Je,{open:C,onOpenChange:_,children:r.jsxs(Ue,{children:[r.jsxs(Be,{children:[r.jsx($e,{children:"Push Branch First"}),r.jsx(Fe,{children:"Your branch needs to be pushed to the remote before creating a pull request. Would you like to push it now?"})]}),r.jsxs(He,{children:[r.jsx(B,{variant:"outline",onClick:()=>{_(!1),P(null)},disabled:p,children:"Cancel"}),r.jsx(B,{onClick:nt,disabled:p,children:p?"Pushing...":"Push & Create PR"})]})]})}),r.jsx(Je,{open:ue,onOpenChange:M=>{M||(K(""),te("")),v(M)},children:r.jsxs(Ue,{children:[r.jsxs(Be,{children:[r.jsx($e,{children:"Create GitHub Repository"}),r.jsx(Fe,{children:"Create a new GitHub repository and push your local repository"})]}),r.jsxs("div",{className:"grid gap-4 py-4",children:[r.jsxs("div",{className:"grid gap-2",children:[r.jsx(Se,{htmlFor:"repo-name",children:"Repository Name (optional)"}),r.jsx(qe,{id:"repo-name",placeholder:"Leave empty to use current folder name",value:$,onChange:M=>K(M.target.value)})]}),r.jsxs("div",{className:"grid gap-2",children:[r.jsx(Se,{htmlFor:"repo-description",children:"Description (optional)"}),r.jsx(Ft,{id:"repo-description",placeholder:"Enter repository description...",value:Q,onChange:M=>te(M.target.value),rows:3})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(xt,{id:"repo-private",checked:me,onCheckedChange:M=>_e(M===!0)}),r.jsx(Se,{htmlFor:"repo-private",className:"text-sm font-normal",children:"Private repository"})]})]}),r.jsxs(He,{children:[r.jsx(B,{variant:"outline",onClick:()=>v(!1),disabled:p,children:"Cancel"}),r.jsx(B,{onClick:Ge,disabled:p,children:p?"Creating...":"Create & Push"})]})]})}),r.jsx(Je,{open:W,onOpenChange:G,children:r.jsxs(Ue,{className:"max-w-2xl max-h-[80vh] flex flex-col",children:[r.jsxs(Be,{children:[r.jsx($e,{children:"Commit History"}),r.jsxs(Fe,{children:["Recent commits on branch ",m]})]}),r.jsx("div",{className:"flex-1 overflow-y-auto border rounded-lg",onScroll:ft,children:r.jsxs("div",{className:"divide-y",children:[ae.length>0?ae.map(M=>r.jsxs("div",{className:"p-3 hover:bg-slate-50 dark:hover:bg-slate-900 transition-colors",children:[r.jsx("p",{className:"text-sm font-medium break-words",children:M.message}),r.jsxs("p",{className:"text-xs text-slate-600 dark:text-slate-400 mt-1",children:[r.jsx("span",{className:"font-mono",children:M.hash.substring(0,7)})," • ",M.author," • ",new Date(M.date).toLocaleDateString()]})]},M.hash)):r.jsx("p",{className:"text-sm text-slate-500 text-center py-8",children:"No commits found"}),V&&r.jsx("div",{className:"p-3 text-center",children:r.jsx(Te,{className:"h-4 w-4 animate-spin inline"})}),ae.length<U.length&&!V&&r.jsx("div",{className:"p-3 text-center text-xs text-slate-500",children:"Scroll to load more"})]})}),r.jsx(He,{children:r.jsx(B,{variant:"outline",onClick:()=>G(!1),children:"Close"})})]})})]})}const Ei=["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 ki({open:s,onOpenChange:e,projectId:t,commands:n,onRefresh:a}){const[l,o]=c.useState(null),[i,d]=c.useState(!1),u=()=>{o({id:crypto.randomUUID(),name:"",icon:"Play",commandLine:""})},m=h=>{o({...h})},f=async h=>{try{await po(t,h),re({title:"Success",description:"Command deleted"}),a()}catch{re({title:"Error",description:"Failed to delete command",variant:"destructive"})}},p=async()=>{if(!l?.name||!l?.commandLine){re({title:"Error",description:"Name and Command Line are required",variant:"destructive"});return}try{d(!0),await fo(t,l),re({title:"Success",description:"Command saved"}),o(null),a()}catch{re({title:"Error",description:"Failed to save command",variant:"destructive"})}finally{d(!1)}};return r.jsx(Je,{open:s,onOpenChange:e,children:r.jsxs(Ue,{className:"sm:max-w-[500px]",children:[r.jsxs(Be,{children:[r.jsx($e,{children:"Project Commands"}),r.jsx(Fe,{children:"Manage custom commands for this project. These commands will be available in the toolbar for all threads."})]}),r.jsx("div",{className:"py-4 flex flex-col gap-4",children:l?r.jsxs("div",{className:"p-4 border rounded-lg bg-muted/30 flex flex-col gap-4 animate-in slide-in-from-top-2",children:[r.jsxs("div",{className:"grid gap-2",children:[r.jsx(Se,{htmlFor:"name",children:"Command Name"}),r.jsx(qe,{id:"name",value:l.name,onChange:h=>o({...l,name:h.target.value}),placeholder:"e.g. Run Tests",autoComplete:"off"})]}),r.jsxs("div",{className:"grid gap-2",children:[r.jsx(Se,{htmlFor:"commandLine",children:"Command Line"}),r.jsx(Ft,{id:"commandLine",value:l.commandLine,onChange:h=>o({...l,commandLine:h.target.value}),placeholder:"e.g. npm test",className:"font-mono text-xs min-h-[100px] resize-none"})]}),r.jsxs("div",{className:"grid gap-2",children:[r.jsx(Se,{children:"Icon"}),r.jsx("div",{className:"grid grid-cols-10 gap-1 p-2 bg-background rounded-md border border-border",children:Ei.map(h=>{const x=Ls[h]||Ga,j=l.icon===h;return r.jsx(B,{variant:j?"default":"ghost",size:"icon",className:"h-8 w-8",onClick:()=>o({...l,icon:h}),title:h,children:r.jsx(x,{className:"h-4 w-4"})},h)})})]}),r.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[r.jsxs(B,{variant:"ghost",size:"sm",onClick:()=>o(null),children:[r.jsx(tt,{className:"h-4 w-4 mr-2"})," Cancel"]}),r.jsxs(B,{size:"sm",onClick:p,disabled:i,children:[r.jsx(et,{className:"h-4 w-4 mr-2"})," ",i?"Saving...":"Save Command"]})]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex flex-col gap-2 max-h-[400px] overflow-y-auto pr-2",children:[n.length===0&&r.jsx("div",{className:"text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg",children:"No commands defined yet."}),n.map(h=>r.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:()=>m(h),children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"p-2 bg-muted rounded",children:(()=>{const x=Ls[h.icon]||zs;return r.jsx(x,{className:"h-4 w-4"})})()}),r.jsxs("div",{className:"flex flex-col",children:[r.jsx("span",{className:"text-sm font-medium",children:h.name}),r.jsx("span",{className:"text-xs text-muted-foreground line-clamp-1 font-mono",children:h.commandLine})]})]}),r.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:r.jsx(B,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10",onClick:x=>{x.stopPropagation(),f(h.id)},children:r.jsx(Ds,{className:"h-4 w-4"})})})]},h.id))]}),r.jsxs(B,{variant:"outline",className:"w-full border-dashed",onClick:u,children:[r.jsx(ds,{className:"h-4 w-4 mr-2"})," Add New Command"]})]})}),r.jsx(He,{children:r.jsx(B,{variant:"ghost",onClick:()=>e(!1),children:"Close"})})]})})}function _i(){const s=F.c(27),{state:e}=Pe(),{selectedProjectId:t,selectedThreadId:n,projects:a}=e,{dispatch:l}=Yt(n),[o,i]=c.useState(!1);let d,u,m,f,p;if(s[0]!==l||s[1]!==a||s[2]!==t||s[3]!==n||s[4]!==e.isRunningCommand){p=Symbol.for("react.early_return_sentinel");e:{let j;s[10]!==t?(j=w=>w.projectId===t,s[10]=t,s[11]=j):j=s[11],d=a.find(j)?.commands||[];let g;s[12]!==l||s[13]!==t||s[14]!==n?(g=w=>{!t||!n||l({type:N.QueueTerminalCommand,command:w})},s[12]=l,s[13]=t,s[14]=n,s[15]=g):g=s[15];const R=g;let I;if(s[16]!==l?(I=async()=>{l({type:N.ConfigUpdated})},s[16]=l,s[17]=I):I=s[17],u=I,!t){p=null;break e}m="flex items-center gap-1 mr-2",f=d.length===0?r.jsx(Re,{children:r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsxs(B,{variant:"ghost",size:"sm",className:"h-8 gap-1.5 text-muted-foreground hover:text-foreground",onClick:()=>i(!0),children:[r.jsx(Ms,{className:"h-4 w-4"}),r.jsx("span",{className:"text-xs font-medium",children:"Commands"})]})}),r.jsx(he,{children:"Manage project commands"})]})}):r.jsx(r.Fragment,{children:r.jsxs(Re,{children:[d.map(w=>{const S=Ls[w.icon]||zs;return r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsx(B,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground",onClick:()=>R(w.commandLine),disabled:e.isRunningCommand,children:r.jsx(S,{className:"h-4 w-4"})})}),r.jsx(he,{children:r.jsxs("div",{className:"flex flex-col gap-0.5",children:[r.jsx("span",{className:"font-medium",children:w.name}),r.jsx("span",{className:"text-[10px] opacity-70 font-mono whitespace-pre-wrap max-w-[300px] max-h-[100px] overflow-y-auto",children:w.commandLine})]})})]},w.id)}),r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsx(B,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground ml-1",onClick:()=>i(!0),children:r.jsx(Ms,{className:"h-4 w-4"})})}),r.jsx(he,{children:"Manage commands"})]})]})})}s[0]=l,s[1]=a,s[2]=t,s[3]=n,s[4]=e.isRunningCommand,s[5]=d,s[6]=u,s[7]=m,s[8]=f,s[9]=p}else d=s[5],u=s[6],m=s[7],f=s[8],p=s[9];if(p!==Symbol.for("react.early_return_sentinel"))return p;let h;s[18]!==d||s[19]!==u||s[20]!==t||s[21]!==o?(h=r.jsx(ki,{open:o,onOpenChange:i,projectId:t,commands:d,onRefresh:u}),s[18]=d,s[19]=u,s[20]=t,s[21]=o,s[22]=h):h=s[22];let x;return s[23]!==m||s[24]!==f||s[25]!==h?(x=r.jsxs("div",{className:m,children:[f,h]}),s[23]=m,s[24]=f,s[25]=h,s[26]=x):x=s[26],x}function Ri({projectId:s,runCommand:e}){const{state:t}=Pe(),{selectedThreadId:n}=t,{dispatch:a}=Yt(n),[l,o]=c.useState(!1),[i,d]=c.useState(!1);c.useEffect(()=>{(async()=>{try{const h=await bo(s);o(h.isRunning)}catch{o(!1)}})()},[s]);const u=async()=>{if(!e)return;d(!0),a({type:N.ClearTerminalOutput}),a({type:N.SetTerminalOpen,open:!1}),a({type:N.AppendTerminalLine,line:{type:"system",content:`Starting dev server: ${e}`}});let p=!1;const h=setTimeout(()=>{p=!0,a({type:N.SetTerminalOpen,open:!0})},3e3);try{const x=await jo(s);if(!x){clearTimeout(h),re({title:"Error",description:"Failed to start dev server",variant:"destructive"}),a({type:N.AppendTerminalLine,line:{type:"error",content:"Failed to start dev server"}}),d(!1);return}const j=x.getReader(),b=new TextDecoder;o(!0);let g=!1,R=!1,I=null;for(I=setTimeout(()=>{R||d(!1)},3e3);;){const{done:w,value:S}=await j.read();if(w)break;const E=b.decode(S,{stream:!0});try{const T=E.split(`
|
|
13
|
+
`).filter(k=>k.trim());for(const k of T)try{const y=JSON.parse(k);R||(R=!0,d(!1),I&&clearTimeout(I)),(y.type==="stdout"||y.type==="stderr")&&a({type:N.AppendTerminalLine,line:{type:"output",content:y.content}}),y.type==="url"&&y.url&&(clearTimeout(h),a({type:N.AppendTerminalLine,line:{type:"system",content:`✓ Server running at: ${y.url}`}}),window.open(y.url,"_blank"),p&&setTimeout(()=>{a({type:N.SetTerminalOpen,open:!1})},100),re({title:"Dev server started",description:`Server running at ${y.url}`}),g=!0),y.type==="error"&&y.content&&a({type:N.AppendTerminalLine,line:{type:"error",content:y.content}})}catch{E.trim()&&a({type:N.AppendTerminalLine,line:{type:"output",content:E}})}}catch{E.trim()&&a({type:N.AppendTerminalLine,line:{type:"output",content:E}})}}clearTimeout(h),I&&clearTimeout(I),d(!1),g||(a({type:N.AppendTerminalLine,line:{type:"system",content:"Server is running but URL could not be detected"}}),re({title:"Dev server started",description:"Server is running but URL could not be detected"}))}catch(x){clearTimeout(h),o(!1),d(!1);const j=x instanceof Error?x.message:"Failed to start dev server";a({type:N.AppendTerminalLine,line:{type:"error",content:j}}),re({title:"Error",description:j,variant:"destructive"})}},m=async()=>{d(!0);try{await yo(s),o(!1),a({type:N.AppendTerminalLine,line:{type:"system",content:"Server stopped"}})}catch(p){const h=p instanceof Error?p.message:"Failed to stop dev server";a({type:N.AppendTerminalLine,line:{type:"error",content:h}}),re({title:"Error",description:h,variant:"destructive"})}finally{d(!1)}},f=!!e;return r.jsx(r.Fragment,{children:r.jsx(Re,{children:r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsxs(B,{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?m:u,disabled:i||!l&&!f,children:[i?r.jsx(Te,{className:"h-4 w-4 animate-spin"}):l?r.jsx(Tr,{className:"h-4 w-4 fill-current"}):r.jsx(zs,{className:"h-4 w-4"}),r.jsx("span",{className:"sr-only",children:l?"Stop dev server":"Start dev server"})]})}),r.jsx(he,{children:l?"Stop dev server":f?`Start dev server: ${e}`:"Set run command in project settings"})]})})})}function Pi(){const s=F.c(10),{state:e}=Pe(),{selectedThreadId:t}=e,{terminalState:n,dispatch:a}=Yt(t),{open:l}=n,o=`h-8 w-8 ${l?"text-primary bg-primary/10":"text-muted-foreground"}`;let i;s[0]!==a?(i=()=>a({type:N.ToggleTerminal}),s[0]=a,s[1]=i):i=s[1];let d,u;s[2]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx(ls,{className:"h-4 w-4"}),u=r.jsx("span",{className:"sr-only",children:"Toggle terminal"}),s[2]=d,s[3]=u):(d=s[2],u=s[3]);let m;s[4]!==o||s[5]!==i?(m=r.jsx(je,{asChild:!0,children:r.jsxs(B,{variant:"ghost",size:"icon",className:o,onClick:i,children:[d,u]})}),s[4]=o,s[5]=i,s[6]=m):m=s[6];let f;s[7]===Symbol.for("react.memo_cache_sentinel")?(f=r.jsx(he,{children:"Show Terminal"}),s[7]=f):f=s[7];let p;return s[8]!==m?(p=r.jsx(Re,{children:r.jsxs(xe,{children:[m,f]})}),s[8]=m,s[9]=p):p=s[9],p}function Mi(){const s=F.c(10),{state:e,dispatch:t}=Pe(),n=`h-8 w-8 ${e.reviewMode?"text-primary bg-primary/10":"text-muted-foreground"}`;let a;s[0]!==t?(a=()=>t({type:N.ToggleReviewMode}),s[0]=t,s[1]=a):a=s[1];let l,o;s[2]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsx(za,{className:"h-4 w-4"}),o=r.jsx("span",{className:"sr-only",children:"Review changes"}),s[2]=l,s[3]=o):(l=s[2],o=s[3]);let i;s[4]!==n||s[5]!==a?(i=r.jsx(je,{asChild:!0,children:r.jsxs(B,{variant:"ghost",size:"icon",className:n,onClick:a,children:[l,o]})}),s[4]=n,s[5]=a,s[6]=i):i=s[6];let d;s[7]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx(he,{children:"Review Changes"}),s[7]=d):d=s[7];let u;return s[8]!==i?(u=r.jsx(Re,{children:r.jsxs(xe,{children:[i,d]})}),s[8]=i,s[9]=u):u=s[9],u}function Di(){const s=F.c(28),{state:e,dispatch:t}=Pe(),{selectedThreadId:n,selectedProjectId:a,projects:l,sidebarOpen:o}=e;let i;if(s[0]!==l||s[1]!==a){let g;s[3]!==a?(g=R=>R.projectId===a,s[3]=a,s[4]=g):g=s[4],i=l.find(g),s[0]=l,s[1]=a,s[2]=i}else i=s[2];const d=i;let u;s[5]!==t?(u=()=>t({type:N.ToggleSidebar}),s[5]=t,s[6]=u):u=s[6];let m;s[7]!==o?(m=o?r.jsx(Nr,{className:"h-4 w-4"}):r.jsx(Ua,{className:"h-4 w-4"}),s[7]=o,s[8]=m):m=s[8];let f;s[9]===Symbol.for("react.memo_cache_sentinel")?(f=r.jsx("span",{className:"sr-only",children:"Toggle sidebar"}),s[9]=f):f=s[9];let p;s[10]!==u||s[11]!==m?(p=r.jsxs(B,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground",onClick:u,children:[m,f]}),s[10]=u,s[11]=m,s[12]=p):p=s[12];let h;s[13]!==l||s[14]!==a||s[15]!==n?(h=n&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm font-medium text-foreground",children:ml(l,n)}),r.jsx("span",{className:"text-xs text-muted-foreground",children:fl(l,a)})]}),s[13]=l,s[14]=a,s[15]=n,s[16]=h):h=s[16];let x;s[17]!==d?.openWith||s[18]!==d?.runCommand||s[19]!==a||s[20]!==n?(x=a&&r.jsxs(r.Fragment,{children:[n&&r.jsxs(r.Fragment,{children:[r.jsx(Mi,{}),r.jsx(Pi,{})]}),r.jsx(Ri,{projectId:a,runCommand:d?.runCommand}),n&&r.jsxs(r.Fragment,{children:[r.jsx(_i,{}),r.jsx(Ii,{projectId:a,threadId:n}),r.jsx(bi,{projectId:a,threadId:n,openWith:d?.openWith})]})]}),s[17]=d?.openWith,s[18]=d?.runCommand,s[19]=a,s[20]=n,s[21]=x):x=s[21];let j;s[22]!==x?(j=r.jsx("div",{className:"ml-auto flex items-center gap-2",children:x}),s[22]=x,s[23]=j):j=s[23];let b;return s[24]!==p||s[25]!==h||s[26]!==j?(b=r.jsxs("header",{className:"flex h-12 shrink-0 items-center gap-2 border-b border-border px-4",children:[p,h,j]}),s[24]=p,s[25]=h,s[26]=j,s[27]=b):b=s[27],b}const $s=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("rounded-lg border bg-card text-card-foreground shadow-sm",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx("div",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});$s.displayName="Card";const Ai=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("flex flex-col space-y-1.5 p-6",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx("div",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Ai.displayName="CardHeader";const Li=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("text-2xl font-semibold leading-none tracking-tight",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx("div",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Li.displayName="CardTitle";const Oi=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("text-sm text-muted-foreground",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx("div",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Oi.displayName="CardDescription";const Fs=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("p-6 pt-0",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.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 $i=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("flex items-center p-6 pt-0",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx("div",{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});$i.displayName="CardFooter";const On=Qt("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"}}),Fi=c.forwardRef((s,e)=>{const t=F.c(13);let n,a,l,o;t[0]!==s?({className:n,variant:o,size:l,...a}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l,t[4]=o):(n=t[1],a=t[2],l=t[3],o=t[4]);let i;t[5]!==n||t[6]!==l||t[7]!==o?(i=O(On({variant:o,size:l,className:n})),t[5]=n,t[6]=l,t[7]=o,t[8]=i):i=t[8];let d;return t[9]!==a||t[10]!==e||t[11]!==i?(d=r.jsx(Wr,{ref:e,className:i,...a}),t[9]=a,t[10]=e,t[11]=i,t[12]=d):d=t[12],d});Fi.displayName=Wr.displayName;const $n=c.createContext({size:"default",variant:"default"}),Wt=c.forwardRef((s,e)=>{const t=F.c(19);let n,a,l,o,i;t[0]!==s?({className:a,variant:i,size:o,children:n,...l}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l,t[4]=o,t[5]=i):(n=t[1],a=t[2],l=t[3],o=t[4],i=t[5]);let d;t[6]!==a?(d=O("flex items-center justify-center gap-1",a),t[6]=a,t[7]=d):d=t[7];let u;t[8]!==o||t[9]!==i?(u={variant:i,size:o},t[8]=o,t[9]=i,t[10]=u):u=t[10];let m;t[11]!==n||t[12]!==u?(m=r.jsx($n.Provider,{value:u,children:n}),t[11]=n,t[12]=u,t[13]=m):m=t[13];let f;return t[14]!==l||t[15]!==e||t[16]!==d||t[17]!==m?(f=r.jsx(Vr,{ref:e,className:d,...l,children:m}),t[14]=l,t[15]=e,t[16]=d,t[17]=m,t[18]=f):f=t[18],f});Wt.displayName=Vr.displayName;const gt=c.forwardRef((s,e)=>{const t=F.c(17);let n,a,l,o,i;t[0]!==s?({className:a,children:n,variant:i,size:o,...l}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l,t[4]=o,t[5]=i):(n=t[1],a=t[2],l=t[3],o=t[4],i=t[5]);const d=c.useContext($n);let u;t[6]!==a||t[7]!==d.size||t[8]!==d.variant||t[9]!==o||t[10]!==i?(u=O(On({variant:d.variant||i,size:d.size||o}),a),t[6]=a,t[7]=d.size,t[8]=d.variant,t[9]=o,t[10]=i,t[11]=u):u=t[11];let m;return t[12]!==n||t[13]!==l||t[14]!==e||t[15]!==u?(m=r.jsx(Kr,{ref:e,className:u,...l,children:n}),t[12]=n,t[13]=l,t[14]=e,t[15]=u,t[16]=m):m=t[16],m});gt.displayName=Kr.displayName;const Gi={"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 zi(s){const e=F.c(175),{open:t,onOpenChange:n,onSubmitClone:a,onSubmitWebApp:l}=s,[o,i]=c.useState("choice"),[d,u]=c.useState(1),[m,f]=c.useState("");let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=Sl(ge.PullRequest),e[0]=p):p=e[0];const[h,x]=c.useState(p),[j,b]=c.useState("My App"),[g,R]=c.useState(!1);let I;e[1]===Symbol.for("react.memo_cache_sentinel")?(I=Cl(),e[1]=I):I=e[1];const[w,S]=c.useState(I);let E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=Nl(),e[2]=E):E=e[2];const[T,k]=c.useState(E);let y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=[],e[3]=y):y=e[3];const[C,_]=c.useState(y),[D,P]=c.useState(!1);let z;e[4]===Symbol.for("react.memo_cache_sentinel")?(z=new Set,e[4]=z):z=e[4];const[L,W]=c.useState(z);let G;e[5]===Symbol.for("react.memo_cache_sentinel")?(G=H=>{W(ye=>new Set(ye).add(H))},e[5]=G):G=e[5];const U=G;let q,le;if(e[6]!==C){q={};for(const H of C){const ye=H.typeName;q[ye]||(q[ye]=[]),q[ye].push(H)}le=Object.keys(q).sort(),e[6]=C,e[7]=q,e[8]=le}else q=e[7],le=e[8];const fe=le;let ae;e[9]!==q||e[10]!==fe?(ae={typeNames:fe,templatesByTypeName:q},e[9]=q,e[10]=fe,e[11]=ae):ae=e[11];const{typeNames:ce,templatesByTypeName:V}=ae;let se;if(e[12]!==V){se={};for(const H of Object.keys(V)){const ye=V[H]??[];if(ye.length===0)continue;const Oe=ye.find(Xi),lt=ye.filter(Yi),$t=Oe?[Oe,...lt]:ye;se[H]=$t[0].id}e[12]=V,e[13]=se}else se=e[13];const ee=se;let ne;e:{if(C.find(Kn=>Kn.id===w)){ne=w;break e}if(C.length===0){ne=w;break e}const ye=ce[0];let Oe;e[14]!==ye||e[15]!==V?(Oe=ye?V[ye]??[]:[],e[14]=ye,e[15]=V,e[16]=Oe):Oe=e[16];const lt=Oe;let $t;e[17]!==lt?($t=lt.find(Qi),e[17]=lt,e[18]=$t):$t=e[18],ne=($t??lt[0])?.id??w}const ie=ne;let Ie;e:{if(!ie||C.length===0){Ie=null;break e}let H;e[19]!==ie||e[20]!==C?(H=C.find(ye=>ye.id===ie)?.typeName??null,e[19]=ie,e[20]=C,e[21]=H):H=e[21],Ie=H}const pe=Ie;let ue;if(e[22]!==pe||e[23]!==V){e:{const H=pe?V[pe]??[]:[];if(H.length<=1){ue=H;break e}const ye=H.find(Ji),Oe=H.filter(Ki);ue=ye?[ye,...Oe]:H}e[22]=pe,e[23]=V,e[24]=ue}else ue=e[24];const v=ue;let $,K;e[25]!==ie?($=()=>{ie&&Tl(ie)},K=[ie],e[25]=ie,e[26]=$,e[27]=K):($=e[26],K=e[27]),c.useEffect($,K);const Q=g?j:pe?`My ${pe} App`:"My App";let te;e[28]!==ie||e[29]!==C?(te=ie?C.find(H=>H.id===ie):null,e[28]=ie,e[29]=C,e[30]=te):te=e[30];const me=te;let _e;e[31]!==C.length?(_e=()=>{i("webapp"),u(2),b("My App"),R(!1),W(new Set),C.length===0&&(P(!0),Dl().then(H=>_(H.templates||[])).catch(()=>_([])).finally(()=>P(!1)))},e[31]=C.length,e[32]=_e):_e=e[32];const ke=_e;let Ye;e[33]===Symbol.for("react.memo_cache_sentinel")?(Ye=()=>{i("clone"),u(2)},e[33]=Ye):Ye=e[33];const We=Ye;let Xe;e[34]!==n?(Xe=()=>{i("choice"),u(1),f(""),b("My App"),R(!1),W(new Set),n(!1)},e[34]=n,e[35]=Xe):Xe=e[35];const De=Xe;let Ve;e[36]!==d?(Ve=()=>{d===2?(i("choice"),u(1),f(""),b("My App"),R(!1)):u(Vi)},e[36]=d,e[37]=Ve):Ve=e[37];const mt=Ve;let Ke;e[38]!==m||e[39]!==o||e[40]!==pe?(Ke=o==="clone"?m.trim().length>0:pe!==null,e[38]=m,e[39]=o,e[40]=pe,e[41]=Ke):Ke=e[41];const Le=Ke;let st;e[42]!==h||e[43]!==m||e[44]!==n||e[45]!==a?(st=()=>{if(!m.trim())return;const H=m.trim();f(""),u(1),n(!1),i("choice"),a(H,h).catch(Wi)},e[42]=h,e[43]=m,e[44]=n,e[45]=a,e[46]=st):st=e[46];const rt=st;let Ge;if(e[47]!==ie||e[48]!==n||e[49]!==l||e[50]!==T||e[51]!==Q){Ge=()=>{if(!Q.trim()||!ie||!H(Q))return;const ye=Q.trim();b(""),R(!1),u(1),n(!1),i("choice"),l(ye,ie,T).catch(qi)};const H=Hi;e[47]=ie,e[48]=n,e[49]=l,e[50]=T,e[51]=Q,e[52]=Ge}else Ge=e[52];const Y=o==="choice"?1:d;let nt;e[53]!==Le||e[54]!==m||e[55]!==o||e[56]!==Y?(nt=H=>H===1?Y>1:H===2?Y>=2:H===3?Y>=2&&(o==="clone"?m.trim().length>0:Le):!1,e[53]=Le,e[54]=m,e[55]=o,e[56]=Y,e[57]=nt):nt=e[57];const ve=nt;let at;e[58]===Symbol.for("react.memo_cache_sentinel")?(at=H=>{H===1?(i("choice"),u(1),f(""),b("")):u(H)},e[58]=at):at=e[58];const ft=at;let M;e[59]!==De?(M=H=>!H&&De(),e[59]=De,e[60]=M):M=e[60];let X;e[61]!==ve?(X=()=>ve(1)&&ft(1),e[61]=ve,e[62]=X):X=e[62];const Ee=Y===1?"bg-primary text-primary-foreground scale-110":Y>1?"bg-brand text-brand-foreground":"bg-muted text-muted-foreground";let Ce;e[63]!==ve||e[64]!==Ee?(Ce=O("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",Ee,ve(1)&&"cursor-pointer hover:opacity-90"),e[63]=ve,e[64]=Ee,e[65]=Ce):Ce=e[65];let A;e[66]!==X||e[67]!==Ce?(A=r.jsx("button",{type:"button",onClick:X,className:Ce,"aria-label":"Go to step 1",children:"1"}),e[66]=X,e[67]=Ce,e[68]=A):A=e[68];const J=Y>=2?"100%":"0%";let Z;e[69]!==J?(Z=r.jsx("div",{className:"h-0.5 flex-1 min-w-0 relative rounded-full overflow-hidden bg-muted",children:r.jsx("div",{className:"absolute inset-y-0 left-0 bg-brand transition-[width] duration-300 ease-out rounded-full",style:{width:J}})}),e[69]=J,e[70]=Z):Z=e[70];let de;e[71]!==ve?(de=()=>ve(2)&&ft(2),e[71]=ve,e[72]=de):de=e[72];const be=Y===2?"bg-primary text-primary-foreground scale-110":Y>2?"bg-brand text-brand-foreground":"bg-muted text-muted-foreground";let Ne;e[73]!==ve||e[74]!==be?(Ne=O("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",be,ve(2)&&"cursor-pointer hover:opacity-90"),e[73]=ve,e[74]=be,e[75]=Ne):Ne=e[75];let Ae;e[76]!==de||e[77]!==Ne?(Ae=r.jsx("button",{type:"button",onClick:de,className:Ne,"aria-label":"Go to step 2",children:"2"}),e[76]=de,e[77]=Ne,e[78]=Ae):Ae=e[78];const yt=Y>=3?"100%":"0%";let ze;e[79]!==yt?(ze=r.jsx("div",{className:"h-0.5 flex-1 min-w-0 relative rounded-full overflow-hidden bg-muted",children:r.jsx("div",{className:"absolute inset-y-0 left-0 bg-brand transition-[width] duration-300 ease-out rounded-full",style:{width:yt}})}),e[79]=yt,e[80]=ze):ze=e[80];let Ze;e[81]!==ve?(Ze=()=>ve(3)&&ft(3),e[81]=ve,e[82]=Ze):Ze=e[82];const pt=Y===3?"bg-primary text-primary-foreground scale-110":"bg-muted text-muted-foreground";let bt;e[83]!==ve||e[84]!==pt?(bt=O("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",pt,ve(3)&&"cursor-pointer hover:opacity-90"),e[83]=ve,e[84]=pt,e[85]=bt):bt=e[85];let vt;e[86]!==Ze||e[87]!==bt?(vt=r.jsx("button",{type:"button",onClick:Ze,className:bt,"aria-label":"Go to step 3",children:"3"}),e[86]=Ze,e[87]=bt,e[88]=vt):vt=e[88];let Nt;e[89]!==A||e[90]!==Z||e[91]!==Ae||e[92]!==ze||e[93]!==vt?(Nt=r.jsxs("div",{className:"mx-auto flex items-center gap-1 mb-6 w-2/3",children:[A,Z,Ae,ze,vt]}),e[89]=A,e[90]=Z,e[91]=Ae,e[92]=ze,e[93]=vt,e[94]=Nt):Nt=e[94];const xs=Y===1&&"New Project",js=Y===2&&o==="clone"&&"Clone Repository",ys=Y===2&&o==="webapp"&&"Create App",bs=Y===3&&o==="clone"&&"Clone Repository",vs=Y===3&&o==="webapp"&&(pe==="Capacitor Plugin"?"Create Capacitor Plugin":pe?`Create ${pe} App`:"Create App");let wt;e[95]!==xs||e[96]!==js||e[97]!==ys||e[98]!==bs||e[99]!==vs?(wt=r.jsxs($e,{children:[xs,js,ys,bs,vs]}),e[95]=xs,e[96]=js,e[97]=ys,e[98]=bs,e[99]=vs,e[100]=wt):wt=e[100];const Ns=Y===1&&"Choose how to add a new project.",ws=Y===2&&o==="clone"&&"Enter a git repository URL to clone.",Ss=Y===2&&o==="webapp"&&"Choose a template type.",Cs=Y===3&&o==="clone"&&"Choose commit workflow.",Ts=Y===3&&o==="webapp"&&"Name your project and choose variation, package manager, and commit workflow.";let St;e[101]!==Ns||e[102]!==ws||e[103]!==Ss||e[104]!==Cs||e[105]!==Ts?(St=r.jsxs(Fe,{children:[Ns,ws,Ss,Cs,Ts]}),e[101]=Ns,e[102]=ws,e[103]=Ss,e[104]=Cs,e[105]=Ts,e[106]=St):St=e[106];let Ct;e[107]!==wt||e[108]!==St?(Ct=r.jsxs(Be,{children:[wt,St]}),e[107]=wt,e[108]=St,e[109]=Ct):Ct=e[109];let Tt;e[110]!==Nt||e[111]!==Ct?(Tt=r.jsxs("div",{className:"px-6 pt-6 pb-2",children:[Nt,Ct]}),e[110]=Nt,e[111]=Ct,e[112]=Tt):Tt=e[112];let It;e[113]!==ke||e[114]!==Y?(It=Y===1&&r.jsx(Qe,{className:"flex-1 min-h-0 overflow-hidden",children:r.jsx("div",{className:"px-6 py-4",children:r.jsxs("div",{className:"flex flex-col gap-3",children:[r.jsx($s,{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:We,onKeyDown:H=>H.key==="Enter"&&We(),children:r.jsxs(Fs,{className:"flex items-start gap-4 p-4",children:[r.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-lg bg-brand text-brand-foreground",children:r.jsx(Gs,{className:"h-6 w-6"})}),r.jsxs("div",{className:"min-w-0 flex-1 space-y-0.5",children:[r.jsx("p",{className:"font-semibold",children:"Clone repo"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:"Connect an existing repository by URL"})]})]})}),r.jsx($s,{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:ke,onKeyDown:H=>H.key==="Enter"&&ke(),children:r.jsxs(Fs,{className:"flex items-start gap-4 p-4",children:[r.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-lg bg-brand text-brand-foreground",children:r.jsx(Ba,{className:"h-6 w-6"})}),r.jsxs("div",{className:"min-w-0 flex-1 space-y-0.5",children:[r.jsx("p",{className:"font-semibold",children:"Create App"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:"Scaffold a new React, Vue, Next.js, or other template"})]})]})})]})})}),e[113]=ke,e[114]=Y,e[115]=It):It=e[115];let Et;e[116]!==Le||e[117]!==m||e[118]!==o||e[119]!==Y?(Et=Y===2&&o==="clone"&&r.jsx(Qe,{className:"flex-1 min-h-0 overflow-hidden",children:r.jsx("div",{className:"px-6 py-4",children:r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx(Se,{htmlFor:"gitUrl",children:"Repository URL"}),r.jsx(qe,{id:"gitUrl",placeholder:"https://github.com/user/repo.git",value:m,onChange:H=>f(H.target.value),onKeyDown:H=>H.key==="Enter"&&Le&&u(3)})]})})}),e[116]=Le,e[117]=m,e[118]=o,e[119]=Y,e[120]=Et):Et=e[120];let kt;e[121]!==ee||e[122]!==L||e[123]!==o||e[124]!==pe||e[125]!==Y||e[126]!==V||e[127]!==D||e[128]!==ce?(kt=Y===2&&o==="webapp"&&r.jsx("div",{className:"flex flex-col flex-1 min-h-0 px-6 pb-4",children:r.jsx("div",{className:"flex-1 min-h-0 flex flex-col py-2",children:r.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto -mx-1",children:r.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:D?r.jsx("p",{className:"col-span-full p-4 text-sm text-muted-foreground",children:"Loading…"}):ce.map(H=>{const ye=V[H]?.[0]?.type,Oe=ye?Gi[ye]:null,lt=pe===H;return r.jsxs("button",{type:"button",onClick:()=>S(ee[H]??""),onDoubleClick:()=>{S(ee[H]??""),u(3)},className:O("flex flex-col items-center gap-2 rounded-lg border px-3 py-3 text-center transition-colors",lt?"border-primary bg-accent text-accent-foreground":"border-border bg-card hover:bg-muted/50 hover:border-muted-foreground/30 shadow-sm"),children:[Oe?r.jsx("img",{src:`/template-types/${Oe}`,alt:"",className:O("size-8 shrink-0 transition-opacity duration-300",L.has(Oe)?"opacity-100":"opacity-0"),onLoad:()=>U(Oe),"aria-hidden":!0}):null,r.jsx("span",{className:"font-medium text-sm truncate w-full",children:H})]},H)})})})})}),e[121]=ee,e[122]=L,e[123]=o,e[124]=pe,e[125]=Y,e[126]=V,e[127]=D,e[128]=ce,e[129]=kt):kt=e[129];let _t;e[130]!==h||e[131]!==ie||e[132]!==o||e[133]!==T||e[134]!==Q||e[135]!==me||e[136]!==Y||e[137]!==v?(_t=Y===3&&o==="webapp"&&r.jsx(Qe,{className:"flex-1 min-h-0 overflow-hidden",children:r.jsxs("div",{className:"px-6 py-4 flex flex-col gap-6",children:[r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx(Se,{htmlFor:"projectName",children:"Project name"}),r.jsx(qe,{id:"projectName",placeholder:"My App",value:Q,onChange:H=>{b(H.target.value),R(!0)},className:"max-w-xs"})]}),r.jsxs("div",{className:"flex flex-col gap-3",children:[v.length>1&&r.jsxs(r.Fragment,{children:[r.jsx(Se,{className:"text-sm font-medium",children:"Variation"}),r.jsx(Wt,{type:"single",value:ie,onValueChange:H=>H&&S(H),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:v.map(Bi)})]}),r.jsxs("p",{className:"text-xs text-muted-foreground",children:[me?.description??v[0]?.description??"",me?.url&&r.jsxs(r.Fragment,{children:[" ",r.jsxs("a",{href:me.url,target:"_blank",rel:"noreferrer",className:"text-brand hover:underline hover:text-brand/80 inline-flex items-center gap-0.5",children:["Documentation ",r.jsx(Jt,{className:"h-3 w-3"})]})]})]})]}),r.jsxs("div",{className:"flex flex-col gap-3",children:[r.jsx(Se,{className:"text-sm font-medium",children:"Package manager"}),r.jsx(Wt,{type:"single",value:T,onValueChange:H=>{H&&(k(H),wl(H))},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(Si).map(Ui)})]}),r.jsxs("div",{className:"flex flex-col gap-3",children:[r.jsx(Se,{className:"text-sm font-medium",children:"Commit method"}),r.jsxs(Wt,{type:"single",value:h,onValueChange:H=>{(H===ge.PullRequest||H===ge.Direct)&&(x(H),lr(H))},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:[r.jsx(gt,{value:ge.PullRequest,className:"text-sm",children:"Pull Requests"}),r.jsx(gt,{value:ge.Direct,className:"text-sm",children:"Direct Commits"})]}),r.jsx("p",{className:"text-xs text-slate-600 dark:text-slate-400",children:h===ge.PullRequest?"Creates a feature branch and allows you to create pull requests.":"Commits directly to the main branch without creating feature branches."})]})]})}),e[130]=h,e[131]=ie,e[132]=o,e[133]=T,e[134]=Q,e[135]=me,e[136]=Y,e[137]=v,e[138]=_t):_t=e[138];let Rt;e[139]!==h||e[140]!==o||e[141]!==Y?(Rt=Y===3&&o==="clone"&&r.jsx(Qe,{className:"flex-1 min-h-0 overflow-hidden",children:r.jsx("div",{className:"px-6 py-4 flex flex-col gap-6",children:r.jsxs("div",{className:"flex flex-col gap-3",children:[r.jsx(Se,{className:"text-sm font-medium",children:"Commit method"}),r.jsxs(Wt,{type:"single",value:h,onValueChange:H=>{(H===ge.PullRequest||H===ge.Direct)&&(x(H),lr(H))},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:[r.jsx(gt,{value:ge.PullRequest,className:"text-sm",children:"Pull Requests"}),r.jsx(gt,{value:ge.Direct,className:"text-sm",children:"Direct Commits"})]}),r.jsx("p",{className:"text-xs text-slate-600 dark:text-slate-400",children:h===ge.PullRequest?"Creates a feature branch and allows you to create pull requests.":"Commits directly to the main branch without creating feature branches."})]})})}),e[139]=h,e[140]=o,e[141]=Y,e[142]=Rt):Rt=e[142];let Pt;e[143]!==mt||e[144]!==Y?(Pt=Y>1&&r.jsx(B,{variant:"ghost",onClick:mt,children:"Back"}),e[143]=mt,e[144]=Y,e[145]=Pt):Pt=e[145];let Mt;e[146]!==Le||e[147]!==Y?(Mt=Y===2&&r.jsx(B,{onClick:()=>u(3),disabled:!Le,children:"Next"}),e[146]=Le,e[147]=Y,e[148]=Mt):Mt=e[148];let Dt;e[149]!==rt||e[150]!==o||e[151]!==Y?(Dt=Y===3&&o==="clone"&&r.jsx(B,{onClick:rt,children:"Clone Repository"}),e[149]=rt,e[150]=o,e[151]=Y,e[152]=Dt):Dt=e[152];let At;e[153]!==Ge||e[154]!==o||e[155]!==Q||e[156]!==Y?(At=Y===3&&o==="webapp"&&r.jsx(B,{onClick:Ge,disabled:!Q.trim(),children:"Create App"}),e[153]=Ge,e[154]=o,e[155]=Q,e[156]=Y,e[157]=At):At=e[157];let Lt;e[158]!==Pt||e[159]!==Mt||e[160]!==Dt||e[161]!==At?(Lt=r.jsx("div",{className:"px-6 py-4 border-t border-border bg-muted/10 min-h-[4.5rem] flex flex-col justify-end",children:r.jsxs(He,{children:[Pt,Mt,Dt,At]})}),e[158]=Pt,e[159]=Mt,e[160]=Dt,e[161]=At,e[162]=Lt):Lt=e[162];let Ot;e[163]!==Tt||e[164]!==It||e[165]!==Et||e[166]!==kt||e[167]!==_t||e[168]!==Rt||e[169]!==Lt?(Ot=r.jsxs(Ue,{className:"max-w-2xl h-[min(42rem,90dvh)] flex flex-col p-0 overflow-hidden",children:[Tt,It,Et,kt,_t,Rt,Lt]}),e[163]=Tt,e[164]=It,e[165]=Et,e[166]=kt,e[167]=_t,e[168]=Rt,e[169]=Lt,e[170]=Ot):Ot=e[170];let Zt;return e[171]!==t||e[172]!==M||e[173]!==Ot?(Zt=r.jsx(Je,{open:t,onOpenChange:M,children:Ot}),e[171]=t,e[172]=M,e[173]=Ot,e[174]=Zt):Zt=e[174],Zt}function Ui(s){return r.jsx(gt,{value:s.id,className:"text-sm",children:s.label},s.id)}function Bi(s){return r.jsx(gt,{value:s.id,className:"text-sm",children:s.variationName},s.id)}function Hi(s){return s.trim().toLowerCase().replace(/\s+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function qi(){}function Wi(){}function Vi(s){return s-1}function Ki(s){return s.variationName!=="Starter"}function Ji(s){return s.variationName==="Starter"}function Qi(s){return s.variationName==="Starter"}function Yi(s){return s.variationName!=="Starter"}function Xi(s){return s.variationName==="Starter"}const Qs=qa,Zi=Ha,Fn=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("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",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(Jr,{className:l,...a,ref:e}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Fn.displayName=Jr.displayName;const ms=c.forwardRef((s,e)=>{const t=F.c(10);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsx(Fn,{}),t[3]=l):l=t[3];let o;t[4]!==n?(o=O("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",n),t[4]=n,t[5]=o):o=t[5];let i;return t[6]!==a||t[7]!==e||t[8]!==o?(i=r.jsxs(Zi,{children:[l,r.jsx(Qr,{ref:e,className:o,...a})]}),t[6]=a,t[7]=e,t[8]=o,t[9]=i):i=t[9],i});ms.displayName=Qr.displayName;const fs=s=>{const e=F.c(8);let t,n;e[0]!==s?({className:t,...n}=s,e[0]=s,e[1]=t,e[2]=n):(t=e[1],n=e[2]);let a;e[3]!==t?(a=O("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]!==n||e[6]!==a?(l=r.jsx("div",{className:a,...n}),e[5]=n,e[6]=a,e[7]=l):l=e[7],l};fs.displayName="AlertDialogHeader";const ps=s=>{const e=F.c(8);let t,n;e[0]!==s?({className:t,...n}=s,e[0]=s,e[1]=t,e[2]=n):(t=e[1],n=e[2]);let a;e[3]!==t?(a=O("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]!==n||e[6]!==a?(l=r.jsx("div",{className:a,...n}),e[5]=n,e[6]=a,e[7]=l):l=e[7],l};ps.displayName="AlertDialogFooter";const hs=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("text-lg font-semibold",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(Yr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});hs.displayName=Yr.displayName;const gs=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("text-sm text-muted-foreground",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(Xr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});gs.displayName=Xr.displayName;const Ys=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O(Bs(),n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(Zr,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Ys.displayName=Zr.displayName;const Xs=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O(Bs({variant:"outline"}),"mt-2 sm:mt-0",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(en,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Xs.displayName=en.displayName;function ec(s){const e=F.c(13),{open:t,projectName:n,onOpenChange:a,onConfirm:l}=s;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx(hs,{children:"Delete Project"}),e[0]=o):o=e[0];let i;e[1]!==n?(i=r.jsxs(fs,{children:[o,r.jsxs(gs,{children:["Are you sure you want to delete ",r.jsxs("span",{className:"font-semibold text-foreground",children:['"',n,'"']}),"? This will remove the project and all its data. This action cannot be undone."]})]}),e[1]=n,e[2]=i):i=e[2];let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx(Xs,{children:"Cancel"}),e[3]=d):d=e[3];let u;e[4]!==l?(u=r.jsxs(ps,{children:[d,r.jsx(Ys,{onClick:l,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]}),e[4]=l,e[5]=u):u=e[5];let m;e[6]!==i||e[7]!==u?(m=r.jsxs(ms,{children:[i,u]}),e[6]=i,e[7]=u,e[8]=m):m=e[8];let f;return e[9]!==a||e[10]!==t||e[11]!==m?(f=r.jsx(Qs,{open:t,onOpenChange:a,children:m}),e[9]=a,e[10]=t,e[11]=m,e[12]=f):f=e[12],f}function tc({open:s,onOpenChange:e,projectId:t,onRefresh:n}){const[a,l]=c.useState(""),[o,i]=c.useState(""),[d,u]=c.useState(""),[m,f]=c.useState(ge.PullRequest),[p,h]=c.useState(!1),[x,j]=c.useState(!1),[b,g]=c.useState(!1),[R,I]=c.useState(""),[w,S]=c.useState(""),[E,T]=c.useState(""),[k,y]=c.useState(ge.PullRequest),C=c.useCallback(async()=>{g(!0);try{const P=await Bl(t),z=P.name||"",L=P.setupScript||"",W=P.runCommand||"",G=P.commitMethod||ge.PullRequest;l(z),i(L),u(W),f(G),I(z),S(L),T(W),y(G)}catch(P){re({title:"Error",description:P instanceof Error?P.message:"Failed to load project settings",variant:"destructive"})}finally{g(!1)}},[t]);c.useEffect(()=>{s&&C()},[s,t,C]);const _=async()=>{j(!0);try{const P=await xo(t);P.runCommand?(u(P.runCommand),re({title:"Success",description:`Suggested: ${P.runCommand}`})):re({title:"No command found",description:"Could not detect a dev script in package.json"})}catch(P){re({title:"Error",description:P instanceof Error?P.message:"Failed to suggest command",variant:"destructive"})}finally{j(!1)}},D=async()=>{h(!0);try{if(a!==R&&await ro(t,a),o!==w){const P=o.trim()||null;await kn(t,P,!1)}if(d!==E){const P=d.trim()||null;await vo(t,P)}m!==k&&await Xt(t,{commitMethod:m}),re({title:"Success",description:"Project settings saved"}),await n(),e(!1)}catch(P){re({title:"Error",description:P instanceof Error?P.message:"Failed to save settings",variant:"destructive"})}finally{h(!1)}};return r.jsx(Je,{open:s,onOpenChange:e,children:r.jsxs(Ue,{className:"sm:max-w-[500px]",children:[r.jsxs(Be,{children:[r.jsx($e,{children:"Project Settings"}),r.jsx(Fe,{children:"Configure settings for your project."})]}),r.jsxs("div",{className:"grid gap-4 py-4",children:[r.jsxs("div",{className:"grid gap-2",children:[r.jsx(Se,{htmlFor:"projectName",children:"Project Name"}),r.jsx(qe,{id:"projectName",value:a,onChange:P=>l(P.target.value),placeholder:"Enter project name",className:"text-sm",disabled:b})]}),r.jsxs("div",{className:"grid gap-2",children:[r.jsx(Se,{htmlFor:"setupScript",children:"Setup Script"}),r.jsx(Ft,{id:"setupScript",value:o,onChange:P=>i(P.target.value),placeholder:"e.g. npm install",className:"font-mono text-sm min-h-[80px] resize-none",disabled:b}),r.jsx("p",{className:"text-xs text-muted-foreground",children:"This script runs automatically after cloning the repo for new threads."})]}),r.jsxs("div",{className:"grid gap-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx(Se,{htmlFor:"runCommand",children:"Run Command"}),r.jsx(B,{variant:"ghost",size:"sm",onClick:_,disabled:x||b,className:"text-xs h-6 px-2 gap-1",children:x?r.jsxs(r.Fragment,{children:[r.jsx(Te,{className:"h-3 w-3 animate-spin"}),"Suggesting..."]}):r.jsxs(r.Fragment,{children:[r.jsx(wr,{className:"h-3 w-3"}),"Suggest"]})})]}),r.jsx(qe,{id:"runCommand",value:d,onChange:P=>u(P.target.value),placeholder:"e.g. npm run dev",className:"font-mono text-sm",disabled:b}),r.jsx("p",{className:"text-xs text-muted-foreground",children:"The command to start the dev server. Leave empty to disable run functionality."})]}),r.jsxs("div",{className:"grid gap-2",children:[r.jsx(Se,{children:"Commit Method"}),r.jsxs("div",{className:"flex gap-4",children:[r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"radio",name:"commitMethod",value:ge.PullRequest,checked:m===ge.PullRequest,onChange:P=>f(P.target.value),disabled:b}),r.jsx("span",{className:"text-sm",children:"Pull Requests"})]}),r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"radio",name:"commitMethod",value:ge.Direct,checked:m===ge.Direct,onChange:P=>f(P.target.value),disabled:b}),r.jsx("span",{className:"text-sm",children:"Direct Commits"})]})]}),r.jsx("p",{className:"text-xs text-muted-foreground",children:m===ge.PullRequest?"Feature branches are created and pull requests can be created.":"Commits are made directly to the main branch without feature branches."})]})]}),r.jsxs(He,{children:[r.jsx(B,{variant:"ghost",onClick:()=>e(!1),disabled:b||p,children:"Cancel"}),r.jsx(B,{onClick:D,disabled:p||b,children:p?r.jsxs(r.Fragment,{children:[r.jsx(Te,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):b?r.jsxs(r.Fragment,{children:[r.jsx(Te,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading..."]}):"Save"})]})]})})}function sc(s){const e=F.c(19),{open:t,suggestedCommand:n,onConfirm:a}=s;let l;e[0]!==a?(l=x=>{x||a(!1)},e[0]=a,e[1]=l):l=e[1];let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx(hs,{children:"Install dependencies?"}),e[2]=o):o=e[2];const i=n??"";let d;e[3]!==i?(d=r.jsxs(fs,{children:[o,r.jsxs(gs,{children:["Install dependencies with"," ",r.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-sm",children:i}),"?"]})]}),e[3]=i,e[4]=d):d=e[4];let u;e[5]!==a?(u=r.jsx(Xs,{onClick:()=>a(!1),children:"No"}),e[5]=a,e[6]=u):u=e[6];let m;e[7]!==a?(m=r.jsx(Ys,{onClick:()=>a(!0),children:"Yes"}),e[7]=a,e[8]=m):m=e[8];let f;e[9]!==u||e[10]!==m?(f=r.jsxs(ps,{children:[u,m]}),e[9]=u,e[10]=m,e[11]=f):f=e[11];let p;e[12]!==d||e[13]!==f?(p=r.jsxs(ms,{children:[d,f]}),e[12]=d,e[13]=f,e[14]=p):p=e[14];let h;return e[15]!==t||e[16]!==l||e[17]!==p?(h=r.jsx(Qs,{open:t,onOpenChange:l,children:p}),e[15]=t,e[16]=l,e[17]=p,e[18]=h):h=e[18],h}const Gn=Ya,Zs=c.forwardRef((s,e)=>{const t=F.c(12);let n,a,l;t[0]!==s?({className:a,children:n,...l}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l):(n=t[1],a=t[2],l=t[3]);let o;t[4]!==a?(o=O("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=r.jsx(Va,{asChild:!0,children:r.jsx(ct,{className:"h-4 w-4 opacity-50"})}),t[6]=i):i=t[6];let d;return t[7]!==n||t[8]!==l||t[9]!==e||t[10]!==o?(d=r.jsxs(tn,{ref:e,className:o,...l,children:[n,i]}),t[7]=n,t[8]=l,t[9]=e,t[10]=o,t[11]=d):d=t[11],d});Zs.displayName=tn.displayName;const zn=c.forwardRef((s,e)=>{const t=F.c(10);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("flex cursor-default items-center justify-center py-1",n),t[3]=n,t[4]=l):l=t[4];let o;t[5]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx(Er,{className:"h-4 w-4"}),t[5]=o):o=t[5];let i;return t[6]!==a||t[7]!==e||t[8]!==l?(i=r.jsx(sn,{ref:e,className:l,...a,children:o}),t[6]=a,t[7]=e,t[8]=l,t[9]=i):i=t[9],i});zn.displayName=sn.displayName;const Un=c.forwardRef((s,e)=>{const t=F.c(10);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("flex cursor-default items-center justify-center py-1",n),t[3]=n,t[4]=l):l=t[4];let o;t[5]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx(ct,{className:"h-4 w-4"}),t[5]=o):o=t[5];let i;return t[6]!==a||t[7]!==e||t[8]!==l?(i=r.jsx(rn,{ref:e,className:l,...a,children:o}),t[6]=a,t[7]=e,t[8]=l,t[9]=i):i=t[9],i});Un.displayName=rn.displayName;const er=c.forwardRef((s,e)=>{const t=F.c(21);let n,a,l,o;t[0]!==s?({className:a,children:n,position:o,...l}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l,t[4]=o):(n=t[1],a=t[2],l=t[3],o=t[4]);const i=o===void 0?"popper":o,d=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 u;t[5]!==a||t[6]!==d?(u=O("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",d,a),t[5]=a,t[6]=d,t[7]=u):u=t[7];let m;t[8]===Symbol.for("react.memo_cache_sentinel")?(m=r.jsx(zn,{}),t[8]=m):m=t[8];const f=i==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]";let p;t[9]!==f?(p=O("p-1",f),t[9]=f,t[10]=p):p=t[10];let h;t[11]!==n||t[12]!==p?(h=r.jsx(Ka,{className:p,children:n}),t[11]=n,t[12]=p,t[13]=h):h=t[13];let x;t[14]===Symbol.for("react.memo_cache_sentinel")?(x=r.jsx(Un,{}),t[14]=x):x=t[14];let j;return t[15]!==i||t[16]!==l||t[17]!==e||t[18]!==u||t[19]!==h?(j=r.jsx(Wa,{children:r.jsxs(nn,{ref:e,className:u,position:i,...l,children:[m,h,x]})}),t[15]=i,t[16]=l,t[17]=e,t[18]=u,t[19]=h,t[20]=j):j=t[20],j});er.displayName=nn.displayName;const rc=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("py-1.5 pl-8 pr-2 text-sm font-semibold",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(an,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});rc.displayName=an.displayName;const ht=c.forwardRef((s,e)=>{const t=F.c(14);let n,a,l;t[0]!==s?({className:a,children:n,...l}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l):(n=t[1],a=t[2],l=t[3]);let o;t[4]!==a?(o=O("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=r.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:r.jsx(Ja,{children:r.jsx(et,{className:"h-4 w-4"})})}),t[6]=i):i=t[6];let d;t[7]!==n?(d=r.jsx(Qa,{children:n}),t[7]=n,t[8]=d):d=t[8];let u;return t[9]!==l||t[10]!==e||t[11]!==o||t[12]!==d?(u=r.jsxs(ln,{ref:e,className:o,...l,children:[i,d]}),t[9]=l,t[10]=e,t[11]=o,t[12]=d,t[13]=u):u=t[13],u});ht.displayName=ln.displayName;const nc=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("-mx-1 my-1 h-px bg-muted",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(on,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});nc.displayName=on.displayName;function ac({open:s,onOpenChange:e,onRestartOnboarding:t}){const[n,a]=c.useState([]),[l,o]=c.useState(null),[i,d]=c.useState(!1),[u,m]=c.useState(!1),[f,p]=c.useState(null),[h,x]=c.useState(!1),[j,b]=c.useState(""),[g,R]=c.useState([]),[I,w]=c.useState(new Set),[S,E]=c.useState(new Map),[T,k]=c.useState(""),[y,C]=c.useState("alphabetical"),[_,D]=c.useState("all"),[P,z]=c.useState(!1),L=c.useRef(0),W=c.useRef(null);c.useEffect(()=>{s&&G()},[s]),c.useEffect(()=>()=>{W.current&&clearTimeout(W.current)},[]),c.useEffect(()=>{s&&l&&(q(l),U(l))},[l,s]);const G=async()=>{d(!0),b("");try{const v=await Hs();a(v),v.length>0&&!l&&o(v[0].name)}catch(v){b(v instanceof Error?v.message:"Failed to load providers")}finally{d(!1)}},U=async v=>{p(null),x(!0);try{const $=await Ll(v);$.status==="success"&&p($.balance)}catch($){console.error(`Failed to load balance for ${v}:`,$)}finally{x(!1)}},q=async v=>{m(!0),k(""),C("alphabetical"),D("all");try{const $=await qs(v);console.log(`Loaded ${$.length} models for ${v}`),R($);const K=await is();console.log("Enabled models by provider:",K);const Q=K[v]||[];console.log(`Found ${Q.length} enabled models for ${v}:`,Q.map(me=>me.id));const te=new Set(Q.map(me=>me.id));w(te),E(new Map)}catch($){console.error(`Failed to load models for ${v}:`,$),R([]),w(new Set)}finally{m(!1)}},le=(v,$)=>{a(K=>K.map(Q=>Q.name===v?{...Q,apiKey:$}:Q))},fe=v=>{E($=>{const K=new Map($),Q=I.has(v),te=K.has(v),me=K.get(v),ke=!(te?me:Q);return ke===Q?K.delete(v):K.set(v,ke),K})},ae=v=>{E($=>{const K=new Map($);return g.forEach(Q=>{const te=I.has(Q.id);v?te?K.delete(Q.id):K.set(Q.id,!0):te?K.set(Q.id,!1):K.delete(Q.id)}),K})},ce=async()=>{const v={};if(n.forEach($=>{$.apiKey!==void 0&&(v[$.name]=$.apiKey)}),Object.keys(v).length!==0)try{await $l(v)}catch($){console.error("Failed to save keys on close:",$)}},V=async()=>{if(!(S.size===0||!l))try{for(const[v,$]of S.entries())$?(await _n(l,v),w(K=>new Set([...K,v]))):(await no(l,v),w(K=>{const Q=new Set(K);return Q.delete(v),Q}));E(new Map)}catch(v){console.error("Failed to save model changes:",v)}},se=async v=>{v||(await V(),ce()),e(v)},ee=n.find(v=>v.name===l),ne=ee?.apiKey&&ee.apiKey.trim().length>0,ie=(v,$)=>`${v==="all"?"All":"Free"} • ${$==="alphabetical"?"A-Z":$==="price-low"?"Price ↑":$==="price-high"?"Price ↓":$}`,Ie=v=>jt(v.id),pe=g.filter(v=>{const $=T.toLowerCase(),K=Ie(v),Q=v.name.toLowerCase().includes($)||v.id.toLowerCase().includes($)||K.toLowerCase().includes($);if(_==="tools"){const te=v.supportedParameters?.tools===!0;return Q&&te}if(_==="free"){const te=v.pricing?.prompt===0&&v.pricing?.completion===0;return Q&&te}return Q}).sort((v,$)=>{const K=I.has(v.id)?0:1,Q=I.has($.id)?0:1;if(K!==Q)return K-Q;if(y==="price-low"){const te=!!v.pricing,me=!!$.pricing;if(te!==me)return te?-1:1;if(!v.pricing||!$.pricing)return 0;const _e=(v.pricing.prompt+v.pricing.completion)/2,ke=($.pricing.prompt+$.pricing.completion)/2;return _e-ke}if(y==="price-high"){const te=!!v.pricing,me=!!$.pricing;if(te!==me)return te?-1:1;if(!v.pricing||!$.pricing)return 0;const _e=(v.pricing.prompt+v.pricing.completion)/2;return($.pricing.prompt+$.pricing.completion)/2-_e}return Ie(v).localeCompare(Ie($))}),ue=[...n].sort((v,$)=>{const K=!!v.apiKey,Q=!!$.apiKey;return K&&!Q?-1:!K&&Q?1:v.name.localeCompare($.name)});return r.jsx(Je,{open:s,onOpenChange:se,children:r.jsxs(Ue,{className:"max-w-3xl h-[600px] flex flex-col p-0 overflow-hidden",children:[r.jsx("div",{className:"p-6 pb-2",children:r.jsxs(Be,{children:[r.jsx($e,{children:"Settings"}),r.jsx(Fe,{asChild:!0,children:r.jsx("span",{role:t?"button":void 0,tabIndex:t?0:void 0,onClick:t?()=>{W.current&&(clearTimeout(W.current),W.current=null),L.current+=1,L.current>=3?(L.current=0,t()):W.current=setTimeout(()=>{L.current=0,W.current=null},500)}:void 0,onKeyDown:t?v=>{(v.key==="Enter"||v.key===" ")&&v.currentTarget.click()}:void 0,className:t?"cursor-default select-none":void 0,children:"Manage your AI providers, API keys, and models."})})]})}),i?r.jsx("div",{className:"flex flex-1 items-center justify-center",children:r.jsx(Te,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):j?r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-2",children:[r.jsx("p",{className:"text-sm text-destructive",children:j}),r.jsx(B,{variant:"outline",size:"sm",onClick:G,children:"Retry"})]}):r.jsxs("div",{className:"flex flex-1 overflow-hidden border-t border-border",children:[r.jsx("div",{className:"w-64 border-r border-border bg-muted/30",children:r.jsx(Qe,{className:"h-full",children:r.jsx("div",{className:"flex flex-col p-2 gap-1",children:ue.map(v=>r.jsxs("button",{onClick:()=>o(v.name),className:O("flex items-center justify-between px-3 py-2 text-sm font-medium rounded-md transition-colors text-left",l===v.name?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-muted-foreground hover:text-foreground"),children:[r.jsx("span",{className:O(v.apiKey&&"font-bold text-foreground"),children:v.name}),v.apiKey&&r.jsx(et,{className:"h-3.5 w-3.5 text-green-500"})]},v.name))})})}),r.jsx("div",{className:"flex-1 flex flex-col overflow-hidden bg-background",children:ee?r.jsx(Qe,{className:"flex-1",children:r.jsxs("div",{className:"p-6 flex flex-col gap-8",children:[r.jsx("div",{className:"flex flex-col gap-2",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("h3",{className:"text-lg font-semibold",children:ee.name}),f!==null&&r.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:[r.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-green-500"}),"$",Vt(f)," balance"]}),h&&r.jsx(Te,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"})]}),ee.url&&r.jsxs("a",{href:ee.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 ",r.jsx(Jt,{className:"h-3 w-3"})]})]})}),r.jsxs("div",{className:"flex flex-col gap-3",children:[r.jsx("div",{className:"flex items-center justify-between",children:r.jsx(Re,{children:r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsx("span",{className:"text-sm font-medium cursor-help",children:"API Key"})}),r.jsx(he,{children:"Your API key is stored locally and never shared."})]})})}),ee.authType==="APIKey"?r.jsxs("div",{className:"relative",children:[r.jsx(cn,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),r.jsx(qe,{type:P?"text":"password",placeholder:ee.keyName||"Enter API Key",className:"pl-10 pr-10",value:ee.apiKey||"",onChange:v=>{le(ee.name,v.target.value)}}),r.jsx(B,{type:"button",variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 -translate-y-1/2 h-8 w-8 p-0",onClick:()=>z(!P),disabled:!ee.apiKey,children:P?r.jsx(dn,{className:"h-4 w-4 text-muted-foreground"}):r.jsx(un,{className:"h-4 w-4 text-muted-foreground"})})]}):r.jsxs("div",{className:"rounded-md bg-muted/30 p-4 text-center",children:[r.jsx("p",{className:"text-sm text-muted-foreground",children:"This provider uses OAuth for authentication."}),r.jsxs(B,{variant:"outline",size:"sm",className:"mt-2",disabled:!0,children:["Sign in with ",ee.name]})]})]}),r.jsxs("div",{className:"flex flex-col gap-4",children:[!u&&g.length>0&&r.jsxs("div",{className:O("flex items-center justify-between",!ne&&"opacity-25"),children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(xt,{id:"select-all-models",disabled:!ne,checked:g.every(v=>{const $=S.has(v.id),K=S.get(v.id);return $?K:I.has(v.id)}),onCheckedChange:v=>ae(v===!0)}),r.jsx("label",{htmlFor:"select-all-models",className:"text-sm cursor-pointer",children:"Select all models"})]}),r.jsx(Re,{children:r.jsxs("div",{className:"flex items-center rounded-md border border-border p-0.5",children:[r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsx(B,{type:"button",variant:y==="alphabetical"?"secondary":"ghost",size:"icon",className:"h-8 w-8",onClick:()=>C("alphabetical"),children:r.jsx(mn,{className:"h-4 w-4"})})}),r.jsx(he,{children:"Sort A–Z"})]}),r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsx(B,{type:"button",variant:y==="price-low"||y==="price-high"?"secondary":"ghost",size:"icon",className:"h-8 w-8",onClick:()=>C("price-low"),children:r.jsx(fn,{className:"h-4 w-4"})})}),r.jsx(he,{children:"Sort by price"})]})]})})]}),u?r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(Te,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):g.length===0?r.jsx("div",{className:"text-center py-8",children:r.jsx("p",{className:"text-sm text-muted-foreground",children:"No models available for this provider."})}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex gap-3 mb-2 hidden",children:[r.jsxs("div",{className:"flex-1 relative",children:[r.jsx(Sr,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),r.jsx(qe,{placeholder:"Search models...",className:"pl-10",value:T,onChange:v=>k(v.target.value)})]}),r.jsxs(Gn,{value:`${_}:${y}`,onValueChange:v=>{const[$,K]=v.split(":");D($),C(K)},children:[r.jsx(Zs,{className:"w-48",children:r.jsx("span",{className:"text-sm",children:ie(_,y)})}),r.jsxs(er,{children:[r.jsxs("div",{className:"px-2 py-2",children:[r.jsx("div",{className:"text-xs font-medium text-muted-foreground px-2 py-1",children:"Filter"}),r.jsx(ht,{value:`all:${y}`,children:"All models"}),r.jsx(ht,{value:`free:${y}`,children:"Free"})]}),r.jsxs("div",{className:"px-2 py-2 border-t border-border",children:[r.jsx("div",{className:"text-xs font-medium text-muted-foreground px-2 py-1",children:"Sort by"}),r.jsx(ht,{value:`${_}:alphabetical`,children:"Alphabetical"}),r.jsx(ht,{value:`${_}:price-low`,children:"Price - Low to High"}),r.jsx(ht,{value:`${_}:price-high`,children:"Price - High to Low"})]})]})]})]}),r.jsx(Re,{children:r.jsx("div",{className:"grid grid-cols-1 gap-0 border border-border rounded-md overflow-hidden",children:pe.length===0?r.jsx("div",{className:"text-center py-8",children:r.jsx("p",{className:"text-sm text-muted-foreground",children:"No models matching your filters. Try adjusting the filter or search criteria."})}):pe.map(v=>{const $=I.has(v.id),K=S.has(v.id),Q=S.get(v.id),te=K?Q:$,me=v.pricing;return r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.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 ${ne?"":"opacity-25"}`,children:[r.jsx(xt,{id:v.id,disabled:!ne,checked:te??!1,onCheckedChange:()=>fe(v.id),className:"mt-0"}),r.jsxs("div",{className:"flex-1 flex items-center justify-between gap-3 leading-none",children:[r.jsx("label",{htmlFor:v.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:Ie(v)}),me&&r.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap flex-shrink-0",children:me.prompt<=0&&me.completion<=0?"Free":`$${Vt(me.prompt*1e6)} in | $${Vt(me.completion*1e6)} out`})]})]})}),v.description&&r.jsx(he,{side:"left",className:"max-w-xs",children:r.jsx("p",{className:"text-sm",children:v.description})})]},v.id)})})})]})]})]})}):r.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:"Select a provider to configure"})})]}),r.jsx("div",{className:"p-4 border-t border-border bg-muted/10",children:r.jsx(He,{children:r.jsx(B,{onClick:()=>se(!1),children:"Done"})})})]})})}function lc({selectedProvider:s,onProviderChange:e,showApiKeyInput:t=!0,onApiKeyChange:n,isLoading:a,error:l,variant:o="dropdown"}){const[i,d]=c.useState([]),[u,m]=c.useState(!1);return c.useEffect(()=>{(async()=>{m(!0);try{const p=await Hs();d(p),p.length>0&&!s&&e(p[0])}catch(p){console.error("Failed to load providers:",p)}finally{m(!1)}})()},[s,e]),u?r.jsx("div",{className:"flex items-center justify-center py-4",children:r.jsx(Te,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):o==="dropdown"?r.jsxs("div",{className:"flex flex-col gap-4",children:[l&&r.jsx("p",{className:"text-sm text-destructive",children:l}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx("label",{className:"text-sm font-medium",children:"AI Provider"}),r.jsxs(Gn,{value:s?.name||"",onValueChange:f=>{const p=i.find(h=>h.name===f);p&&e(p)},children:[r.jsx(Zs,{children:s?s.name:"Select a provider"}),r.jsx(er,{children:i.map(f=>r.jsx(ht,{value:f.name,children:f.name},f.name))})]})]}),s&&s.url&&r.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 ",r.jsx(Jt,{className:"h-3.5 w-3.5"})]}),t&&s&&r.jsx(oc,{provider:s,value:s.apiKey||"",onChange:n,isLoading:a})]}):null}function oc(s){const e=F.c(24),{provider:t,value:n,onChange:a,isLoading:l}=s,[o,i]=c.useState(!1);if(t.authType!=="APIKey"){let I;e[0]===Symbol.for("react.memo_cache_sentinel")?(I=r.jsx("p",{className:"text-sm text-muted-foreground",children:"This provider uses OAuth for authentication."}),e[0]=I):I=e[0];let w;return e[1]!==t.name?(w=r.jsxs("div",{className:"rounded-md bg-muted/30 p-4 text-center",children:[I,r.jsxs(B,{variant:"outline",size:"sm",className:"mt-2",disabled:!0,children:["Sign in with ",t.name]})]}),e[1]=t.name,e[2]=w):w=e[2],w}let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx("div",{className:"flex items-center justify-between",children:r.jsx(Re,{children:r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsx("label",{htmlFor:"api-key",className:"text-sm font-medium cursor-help",children:"API Key"})}),r.jsx(he,{children:"Your API key is stored locally and never shared."})]})})}),e[3]=d):d=e[3];let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx(cn,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e[4]=u):u=e[4];const m=o?"text":"password",f=t.keyName||"Enter API Key";let p;e[5]!==a?(p=I=>a?.(I.target.value),e[5]=a,e[6]=p):p=e[6];let h;e[7]!==l||e[8]!==m||e[9]!==f||e[10]!==p||e[11]!==n?(h=r.jsx(qe,{id:"api-key",type:m,placeholder:f,className:"pl-10 pr-10",value:n,onChange:p,disabled:l}),e[7]=l,e[8]=m,e[9]=f,e[10]=p,e[11]=n,e[12]=h):h=e[12];let x;e[13]!==o?(x=()=>i(!o),e[13]=o,e[14]=x):x=e[14];const j=l||!n;let b;e[15]!==o?(b=o?r.jsx(dn,{className:"h-4 w-4 text-muted-foreground"}):r.jsx(un,{className:"h-4 w-4 text-muted-foreground"}),e[15]=o,e[16]=b):b=e[16];let g;e[17]!==x||e[18]!==j||e[19]!==b?(g=r.jsx(B,{type:"button",variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 -translate-y-1/2 h-8 w-8 p-0",onClick:x,disabled:j,children:b}),e[17]=x,e[18]=j,e[19]=b,e[20]=g):g=e[20];let R;return e[21]!==g||e[22]!==h?(R=r.jsxs("div",{className:"flex flex-col gap-3",children:[d,r.jsxs("div",{className:"relative",children:[u,h,g]})]}),e[21]=g,e[22]=h,e[23]=R):R=e[23],R}function ic({provider:s,onModelsChange:e,isLoading:t,disabled:n,displayMode:a="grid"}){const[l,o]=c.useState([]),[i,d]=c.useState(new Set),[u,m]=c.useState(new Map),[f,p]=c.useState(!1),[h,x]=c.useState(""),[j,b]=c.useState("alphabetical");c.useEffect(()=>{g()},[s]);const g=async()=>{p(!0),x(""),b("alphabetical");try{const T=await qs(s);o(T);const y=(await is())[s]||[],C=new Set(y.map(_=>_.id));d(C),m(new Map)}catch(T){console.error(`Failed to load models for ${s}:`,T),o([]),d(new Set)}finally{p(!1)}},R=(T,k)=>{const y=new Set(T);l.forEach(C=>{k.has(C.id)&&(k.get(C.id)?y.add(C.id):y.delete(C.id))}),e?.(y)},I=T=>{m(k=>{const y=new Map(k),C=i.has(T),_=y.has(T),D=y.get(T),z=!(_?D:C);return z===C?y.delete(T):y.set(T,z),R(i,y),y})},w=T=>{m(k=>{const y=new Map(k);return l.forEach(C=>{const _=i.has(C.id);T?_?y.delete(C.id):y.set(C.id,!0):_?y.set(C.id,!1):y.delete(C.id)}),R(i,y),y})},S=T=>jt(T.id),E=l.filter(T=>{const k=h.toLowerCase(),y=S(T);return T.name.toLowerCase().includes(k)||T.id.toLowerCase().includes(k)||y.toLowerCase().includes(k)}).sort((T,k)=>{const y=i.has(T.id)?0:1,C=i.has(k.id)?0:1;if(y!==C)return y-C;if(j==="price-low"){const _=!!T.pricing,D=!!k.pricing;if(_!==D)return _?-1:1;if(!T.pricing||!k.pricing)return 0;const P=(T.pricing.prompt+T.pricing.completion)/2,z=(k.pricing.prompt+k.pricing.completion)/2;return P-z}if(j==="price-high"){const _=!!T.pricing,D=!!k.pricing;if(_!==D)return _?-1:1;if(!T.pricing||!k.pricing)return 0;const P=(T.pricing.prompt+T.pricing.completion)/2;return(k.pricing.prompt+k.pricing.completion)/2-P}return S(T).localeCompare(S(k))});return f||t?r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(Te,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):l.length===0?r.jsx("div",{className:"text-center py-8",children:r.jsx("p",{className:"text-sm text-muted-foreground",children:"No models available for this provider."})}):a==="compact"?r.jsxs("div",{className:"flex flex-col gap-4",children:[r.jsxs("div",{className:O("flex items-center justify-between",n&&"opacity-25"),children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(xt,{id:"select-all-models",disabled:n,checked:l.every(T=>{const k=u.has(T.id),y=u.get(T.id);return k?y:i.has(T.id)}),onCheckedChange:T=>w(T===!0)}),r.jsx("label",{htmlFor:"select-all-models",className:"text-sm cursor-pointer",children:"Select all models"})]}),r.jsx(Re,{children:r.jsxs("div",{className:"flex items-center rounded-md border border-border p-0.5",children:[r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsx(B,{type:"button",variant:j==="alphabetical"?"secondary":"ghost",size:"icon",className:"h-8 w-8",onClick:()=>b("alphabetical"),disabled:n,children:r.jsx(mn,{className:"h-4 w-4"})})}),r.jsx(he,{children:"Sort A–Z"})]}),r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsx(B,{type:"button",variant:j==="price-low"||j==="price-high"?"secondary":"ghost",size:"icon",className:"h-8 w-8",onClick:()=>{b(j==="price-low"?"price-high":"price-low")},disabled:n,children:r.jsx(fn,{className:"h-4 w-4"})})}),r.jsx(he,{children:"Sort by price"})]})]})})]}),r.jsx(Re,{children:r.jsx("div",{className:"grid grid-cols-1 gap-0 border border-border rounded-md overflow-hidden",children:E.length===0?r.jsx("div",{className:"text-center py-4",children:r.jsx("p",{className:"text-sm text-muted-foreground",children:"No models available."})}):E.map(T=>{const k=i.has(T.id),y=u.has(T.id),C=u.get(T.id),_=y?C:k,D=T.pricing;return r.jsxs(xe,{children:[r.jsx(je,{asChild:!0,children:r.jsxs("div",{className:O("flex items-center space-x-3 p-3 hover:bg-muted/30 transition-colors cursor-default border-b border-border last:border-b-0",n&&"opacity-25"),children:[r.jsx(xt,{id:T.id,disabled:n,checked:_??!1,onCheckedChange:()=>I(T.id),className:"mt-0"}),r.jsxs("div",{className:"flex-1 flex items-center justify-between gap-3 leading-none",children:[r.jsx("label",{htmlFor:T.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:S(T)}),D&&r.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap flex-shrink-0",children:D.prompt<=0&&D.completion<=0?"Free":`${Vt(D.prompt*1e6)} in | ${Vt(D.completion*1e6)} out`})]})]})}),T.description&&r.jsx(he,{side:"left",className:"max-w-xs",children:r.jsx("p",{className:"text-sm",children:T.description})})]},T.id)})})})]}):null}function cc({open:s,onOpenChange:e,onComplete:t}){const[n,a]=c.useState("git-check"),[l,o]=c.useState(null),[i,d]=c.useState(!1),[u,m]=c.useState([]),[f,p]=c.useState(null),[h,x]=c.useState(""),[j,b]=c.useState(!1),[g,R]=c.useState(""),[I,w]=c.useState(new Set),[S,E]=c.useState(!1),[T,k]=c.useState(!1);c.useEffect(()=>{s&&n==="git-check"&&y()},[s,n]),c.useEffect(()=>{s&&n==="provider-selection"&&u.length===0&&C()},[s,n,u.length]),c.useEffect(()=>{s&&n==="model-selection"&&f&&_()},[s,n,f]);const y=async()=>{d(!0);try{const G=await So();o(G.gitInstalled)}catch(G){console.error("Failed to check git installation:",G),o(!1)}finally{d(!1)}},C=async()=>{try{const G=await Hs();m(G),G.length>0&&!f&&p(G[0])}catch(G){console.error("Failed to load providers:",G)}},_=async()=>{if(f){E(!0);try{await qs(f.name),w(new Set)}catch(G){console.error("Failed to load models:",G)}finally{E(!1)}}},D=async()=>{if(!f||!h.trim()){R("Please enter an API key");return}b(!0),R("");try{await Ol(f.name,h),a("model-selection")}catch(G){R(G instanceof Error?G.message:"Failed to validate API key")}finally{b(!1)}},P=async()=>{if(f){k(!0);try{for(const G of I)await _n(f.name,G);await hr(),t?.(),e(!1)}catch(G){console.error("Failed to complete onboarding:",G)}finally{k(!1)}}},z=async()=>{k(!0);try{await hr(),t?.(),e(!1)}catch(G){console.error("Failed to skip onboarding:",G)}finally{k(!1)}},L=G=>{p(G),x(G.apiKey||""),R("")},W=()=>{a("provider-selection")};return r.jsx(Je,{open:s,onOpenChange:e,children:r.jsxs(Ue,{className:"max-w-2xl h-[min(42rem,90dvh)] flex flex-col p-0 overflow-hidden",children:[r.jsxs("div",{className:"px-6 pt-6 pb-2",children:[r.jsxs("div",{className:"w-1/2 mx-auto flex items-center gap-2 mb-6",children:[r.jsx("div",{className:O("flex items-center justify-center h-8 w-8 rounded-full text-sm font-medium",n==="git-check"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"),children:"1"}),r.jsx("div",{className:O("h-0.5 flex-1",n==="provider-selection"||n==="model-selection"?"bg-primary":"bg-muted")}),r.jsx("div",{className:O("flex items-center justify-center h-8 w-8 rounded-full text-sm font-medium",n==="provider-selection"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"),children:"2"}),r.jsx("div",{className:O("h-0.5 flex-1",n==="model-selection"?"bg-primary":"bg-muted")}),r.jsx("div",{className:O("flex items-center justify-center h-8 w-8 rounded-full text-sm font-medium",n==="model-selection"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"),children:"3"})]}),r.jsxs(Be,{children:[n==="git-check"&&r.jsxs(r.Fragment,{children:[r.jsx($e,{children:"Let's get started"}),r.jsx(Fe,{children:"First, we need to check that Git is installed on your system."})]}),n==="provider-selection"&&r.jsxs(r.Fragment,{children:[r.jsx($e,{children:"Select an AI Provider"}),r.jsx(Fe,{children:"Choose your preferred AI provider and enter your API key."})]}),n==="model-selection"&&r.jsxs(r.Fragment,{children:[r.jsx($e,{children:"Select Models"}),r.jsx(Fe,{children:"Choose which models you want to use with this provider."})]})]})]}),r.jsx(Qe,{className:"flex-1 min-h-0 overflow-hidden",children:r.jsxs("div",{className:"px-6 py-4",children:[n==="git-check"&&r.jsx("div",{className:"space-y-4",children:i?r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(Te,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):l?r.jsxs("div",{className:"rounded-lg border border-green-200 bg-green-50 p-4 flex items-start gap-3",children:[r.jsx(et,{className:"h-5 w-5 text-green-600 flex-shrink-0 mt-0.5"}),r.jsxs("div",{children:[r.jsx("h4",{className:"font-medium text-green-900",children:"Git is installed"}),r.jsx("p",{className:"text-sm text-green-800",children:"You're all set to use Git features in Tarsk."})]})]}):r.jsxs("div",{className:"rounded-lg border border-yellow-200 bg-yellow-50 p-4 flex items-start gap-3",children:[r.jsx(Xa,{className:"h-5 w-5 text-yellow-600 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("h4",{className:"font-medium text-yellow-900",children:"Git is not installed"}),r.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."}),r.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 ",r.jsx(Jt,{className:"h-3 w-3"})]})]})]})}),n==="provider-selection"&&r.jsx("div",{className:"space-y-4",children:f&&r.jsxs(r.Fragment,{children:[r.jsx(lc,{selectedProvider:f,onProviderChange:L,showApiKeyInput:!0,variant:"dropdown",isLoading:j}),g&&r.jsx("div",{className:"rounded-md bg-destructive/10 p-3 text-sm text-destructive",children:g})]})}),n==="model-selection"&&f&&r.jsx("div",{className:"space-y-4",children:r.jsx(ic,{provider:f.name,isLoading:S,displayMode:"compact",disabled:!1,onModelsChange:w})})]})}),r.jsx("div",{className:"px-6 py-4 border-t border-border bg-muted/10",children:r.jsxs(He,{className:"flex items-center justify-between",children:[r.jsx("div",{children:n==="provider-selection"&&r.jsx(B,{variant:"ghost",onClick:()=>z(),disabled:T,children:"Skip for now"})}),r.jsxs("div",{className:"flex gap-3",children:[n!=="git-check"&&r.jsx(B,{variant:"outline",onClick:()=>{n==="provider-selection"?a("git-check"):n==="model-selection"&&a("provider-selection")},disabled:T,children:"Back"}),n==="git-check"&&r.jsxs(B,{onClick:W,disabled:i,className:"gap-2",children:["Continue ",r.jsx(rr,{className:"h-4 w-4"})]}),n==="provider-selection"&&r.jsx(B,{onClick:D,disabled:j||!h.trim()||!f,className:"gap-2",children:j?r.jsxs(r.Fragment,{children:[r.jsx(Te,{className:"h-4 w-4 animate-spin"}),"Validating..."]}):r.jsxs(r.Fragment,{children:["Next ",r.jsx(rr,{className:"h-4 w-4"})]})}),n==="model-selection"&&r.jsx(B,{onClick:P,disabled:T,className:"gap-2",children:T?r.jsxs(r.Fragment,{children:[r.jsx(Te,{className:"h-4 w-4 animate-spin"}),"Finishing..."]}):r.jsxs(r.Fragment,{children:["Finish ",r.jsx(et,{className:"h-4 w-4"})]})})]})]})})]})})}function dc(){const s=F.c(6),[e,t]=c.useState(!0);let n,a;s[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>{let f=!0;return(async()=>{try{const h=await fetch(`${ur()}/health`,{method:"GET"});f&&t(h.ok)}catch{f&&t(!1)}})(),()=>{f=!1}},a=[],s[0]=n,s[1]=a):(n=s[0],a=s[1]),c.useEffect(n,a);const l=uc;if(e)return null;let o;s[2]===Symbol.for("react.memo_cache_sentinel")?(o=ur(),s[2]=o):o=s[2];const i=o;let d,u;s[3]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsxs(fs,{children:[r.jsx(hs,{children:"Service unavailable"}),r.jsx(gs,{children:"Service is not currently up. Please ensure the backend is running at the address below, then retry."})]}),u=r.jsx("div",{className:"rounded-md bg-muted px-3 py-2 text-xs font-mono text-muted-foreground",children:i}),s[3]=d,s[4]=u):(d=s[3],u=s[4]);let m;return s[5]===Symbol.for("react.memo_cache_sentinel")?(m=r.jsx(Qs,{open:!0,children:r.jsxs(ms,{children:[d,u,r.jsx(ps,{children:r.jsx(B,{onClick:l,children:"Retry"})})]})}),s[5]=m):m=s[5],m}function uc(){window.location.assign(window.location.href)}const mc=s=>{const e=F.c(8);let t,n;e[0]!==s?({className:t,...n}=s,e[0]=s,e[1]=t,e[2]=n):(t=e[1],n=e[2]);let a;e[3]!==t?(a=O("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]!==n||e[6]!==a?(l=r.jsx(el,{className:a,...n}),e[5]=n,e[6]=a,e[7]=l):l=e[7],l},jr=Za,fc=s=>{const e=F.c(12);let t,n,a;e[0]!==s?({withHandle:a,className:t,...n}=s,e[0]=s,e[1]=t,e[2]=n,e[3]=a):(t=e[1],n=e[2],a=e[3]);let l;e[4]!==t?(l=O("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&&r.jsx("div",{className:"z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border",children:r.jsx(sl,{className:"h-2.5 w-2.5"})}),e[6]=a,e[7]=o):o=e[7];let i;return e[8]!==n||e[9]!==l||e[10]!==o?(i=r.jsx(tl,{className:l,...n,children:o}),e[8]=n,e[9]=l,e[10]=o,e[11]=i):i=e[11],i},pc=rl,Bn=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("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]",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(pn,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Bn.displayName=pn.displayName;const hc=Qt("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"}}),Hn=c.forwardRef((s,e)=>{const t=F.c(11);let n,a,l;t[0]!==s?({className:n,variant:l,...a}=s,t[0]=s,t[1]=n,t[2]=a,t[3]=l):(n=t[1],a=t[2],l=t[3]);let o;t[4]!==n||t[5]!==l?(o=O(hc({variant:l}),n),t[4]=n,t[5]=l,t[6]=o):o=t[6];let i;return t[7]!==a||t[8]!==e||t[9]!==o?(i=r.jsx(hn,{ref:e,className:o,...a}),t[7]=a,t[8]=e,t[9]=o,t[10]=i):i=t[10],i});Hn.displayName=hn.displayName;const gc=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("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",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(gn,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});gc.displayName=gn.displayName;const qn=c.forwardRef((s,e)=>{const t=F.c(10);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("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",n),t[3]=n,t[4]=l):l=t[4];let o;t[5]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx(tt,{className:"h-4 w-4"}),t[5]=o):o=t[5];let i;return t[6]!==a||t[7]!==e||t[8]!==l?(i=r.jsx(xn,{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});qn.displayName=xn.displayName;const Wn=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("text-sm font-semibold",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(jn,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Wn.displayName=jn.displayName;const Vn=c.forwardRef((s,e)=>{const t=F.c(9);let n,a;t[0]!==s?({className:n,...a}=s,t[0]=s,t[1]=n,t[2]=a):(n=t[1],a=t[2]);let l;t[3]!==n?(l=O("text-sm opacity-90",n),t[3]=n,t[4]=l):l=t[4];let o;return t[5]!==a||t[6]!==e||t[7]!==l?(o=r.jsx(yn,{ref:e,className:l,...a}),t[5]=a,t[6]=e,t[7]=l,t[8]=o):o=t[8],o});Vn.displayName=yn.displayName;function xc(){const s=F.c(5),{toasts:e}=An();let t;s[0]!==e?(t=e.map(jc),s[0]=e,s[1]=t):t=s[1];let n;s[2]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx(Bn,{}),s[2]=n):n=s[2];let a;return s[3]!==t?(a=r.jsxs(pc,{children:[t,n]}),s[3]=t,s[4]=a):a=s[4],a}function jc(s){const{id:e,title:t,description:n,action:a,...l}=s;return r.jsxs(Hn,{...l,children:[r.jsxs("div",{className:"grid gap-1",children:[t&&r.jsx(Wn,{children:t}),n&&r.jsx(Vn,{children:n})]}),a,r.jsx(qn,{})]},e)}function yc(s){const e=F.c(6);let t,n;e[0]!==s?({children:t,...n}=s,e[0]=s,e[1]=t,e[2]=n):(t=e[1],n=e[2]);let a;return e[3]!==t||e[4]!==n?(a=r.jsx(il,{...n,children:t}),e[3]=t,e[4]=n,e[5]=a):a=e[5],a}function bc(){const{state:s,dispatch:e}=Pe(),{toast:t}=An(),n=Yt("project-creation").dispatch,[a,l]=c.useState(null),o=c.useCallback(async()=>{try{const x=await es();e({type:N.SetProjects,projects:x.projects})}catch(x){console.error("Failed to refresh projects:",x)}},[e]),i=c.useCallback(async(x,j)=>{try{await Kl(x,j)}catch(b){console.error("Failed to select thread:",b)}(s.selectedThreadId!==j||s.selectedProjectId!==x)&&e({type:N.SelectThread,threadId:j,projectId:x})},[e,s.selectedThreadId,s.selectedProjectId]),d=c.useCallback(async(x,j)=>{e({type:N.SetCreatingProject,isCreating:!0});try{const b=await Ul(x,j);if(!b){e({type:N.SetCreatingProject,isCreating:!1}),await o();return}n({type:N.ClearTerminalOutput}),n({type:N.SetTerminalOpen,open:!0});const g=`Cloning repository: ${x}...
|
|
14
|
+
`;n({type:N.AppendTerminalLine,line:{type:"system",content:g.trim()}});const R=b.getReader(),I=new TextDecoder;let w="",S=null,E=!1,T=null,k=null;for(;;){const{done:C,value:_}=await R.read();if(C)break;w+=I.decode(_,{stream:!0});const D=w.split(`
|
|
15
|
+
`);w=D.pop()||"";for(const P of D){const z=P.trim();if(z)try{const L=JSON.parse(z);if(L.type==="progress"){if(!E&&L.threadId&&L.projectId){E=!0,T=L.projectId,k=L.threadId;const W=x.split("/").pop()?.replace(".git","")||"project";e({type:N.AddCreatingProject,projectId:L.projectId,threadId:L.threadId,projectName:W,gitUrl:x}),e({type:N.AddProcessingThread,threadId:L.threadId})}e({type:N.AppendTerminalLine,threadId:k||"project-creation",line:{type:"output",content:L.message}})}else if(L.type==="complete"){if(L.project){S=L.project.id;const W=L.project.threads&&L.project.threads.length>0?`${L.project.path}/${L.project.threads[0]}`:L.project.path;n({type:N.AppendTerminalLine,line:{type:"system",content:`Project created successfully at: ${W}`}}),e({type:N.SetTerminalOpen,open:!1}),L.suggestedSetupScript&&l({projectId:L.project.id,command:L.suggestedSetupScript})}}else L.type==="error"&&(E&&T&&(e({type:N.RemoveCreatingProject,projectId:T}),k&&e({type:N.RemoveProcessingThread,threadId:k})),e({type:N.AppendTerminalLine,threadId:k||"project-creation",line:{type:"error",content:`Error: ${L.message}`}}))}catch(L){console.error("Failed to parse project event",L)}}}e({type:N.SetCreatingProject,isCreating:!1}),E&&k&&e({type:N.RemoveProcessingThread,threadId:k});const y=await es();if(e({type:N.SetProjects,projects:y.projects}),S){const C=y.projects.find(_=>_.projectId===S);if(C&&C.threads.length>0){const _=C.threads[0].threadId;e({type:N.SelectThread,threadId:_,projectId:S,focusInput:!0})}}}catch(b){console.error("Failed to create project:",b),e({type:N.SetCreatingProject,isCreating:!1}),n({type:N.AppendTerminalLine,line:{type:"error",content:`Failed to create project: ${b instanceof Error?b.message:"Unknown error"}`}})}},[e,o]),u=c.useCallback(async(x,j,b)=>{e({type:N.SetCreatingProject,isCreating:!0});try{const g=await Al(x,j,b);if(!g){e({type:N.SetCreatingProject,isCreating:!1}),await o();return}e({type:N.ClearTerminalOutput}),e({type:N.SetTerminalOpen,open:!0}),e({type:N.AppendTerminalLine,line:{type:"system",content:`Creating app "${x}"...`}});const R=g.getReader(),I=new TextDecoder;let w="",S=null,E=!1,T=null,k=null;for(;;){const{done:C,value:_}=await R.read();if(C)break;w+=I.decode(_,{stream:!0});const D=w.split(`
|
|
16
|
+
`);w=D.pop()||"";for(const P of D){const z=P.trim();if(z)try{const L=JSON.parse(z);L.type==="progress"?(!E&&L.threadId&&L.projectId&&(E=!0,T=L.projectId,k=L.threadId,e({type:N.AddCreatingProject,projectId:L.projectId,threadId:L.threadId,projectName:x,gitUrl:""}),e({type:N.AddProcessingThread,threadId:L.threadId})),e({type:N.AppendTerminalLine,line:{type:"output",content:L.message}})):L.type==="complete"?L.project&&(S=L.project.id,e({type:N.AppendTerminalLine,line:{type:"system",content:`Project created successfully at: ${L.project.path}`}}),e({type:N.SetTerminalOpen,open:!1})):L.type==="error"&&(E&&T&&(e({type:N.RemoveCreatingProject,projectId:T}),k&&e({type:N.RemoveProcessingThread,threadId:k})),e({type:N.AppendTerminalLine,line:{type:"error",content:`Error: ${L.message}`}}))}catch(L){console.error("Failed to parse scaffold event",L)}}}e({type:N.SetCreatingProject,isCreating:!1}),E&&k&&e({type:N.RemoveProcessingThread,threadId:k});const y=await es();if(e({type:N.SetProjects,projects:y.projects}),S){const C=y.projects.find(_=>_.projectId===S);if(C&&C.threads.length>0){const _=C.threads[0].threadId;e({type:N.SelectThread,threadId:_,projectId:S,focusInput:!0})}}}catch(g){console.error("Failed to create web app:",g),e({type:N.SetCreatingProject,isCreating:!1}),e({type:N.AppendTerminalLine,line:{type:"error",content:`Failed to create web app: ${g instanceof Error?g.message:"Unknown error"}`}})}},[e,o]),m=c.useCallback(async(x,j)=>{try{const b=j||(()=>{const C=s.projects.find(P=>P.projectId===x)?.threads.map(P=>P.title)||[],_=/^thread-(\d+)$/i;let D=0;for(const P of C){const z=P.match(_);z&&(D=Math.max(D,parseInt(z[1],10)))}return`thread-${D+1}`})(),g=await ql(x,j);if(!g){await o();return}const R=g.getReader(),I=new TextDecoder;let w="",S=!1,E=null,T=!0;const k=[{type:"system",content:`Creating thread "${b}"...`}];try{for(;;){const{done:y,value:C}=await R.read();if(y)break;w+=I.decode(C,{stream:!0});const _=w.split(`
|
|
17
|
+
`);w=_.pop()||"";for(const D of _){const P=D.trim();if(P)try{const z=JSON.parse(P);if(z.type==="progress"){if(!S&&z.threadId){S=!0,E=z.threadId,e({type:N.AddCreatingThread,projectId:x,threadId:z.threadId,title:b}),e({type:N.AddProcessingThread,threadId:z.threadId}),e({type:N.ClearTerminalOutput,threadId:E});for(const W of k)e({type:N.AppendTerminalLine,threadId:E,line:W});k.length=0}const L={type:"output",content:z.message};E?e({type:N.AppendTerminalLine,threadId:E,line:L}):k.push(L)}else if(z.type==="error"){S&&E&&(e({type:N.RemoveCreatingThread,projectId:x,threadId:E}),e({type:N.RemoveProcessingThread,threadId:E}));const L={type:"error",content:`Error: ${z.message}`};E?e({type:N.AppendTerminalLine,threadId:E,line:L}):k.push(L),console.error("Thread creation error:",z.message),T=!1}}catch(z){console.error("Failed to parse thread event",z)}}}S&&E&&e({type:N.RemoveProcessingThread,threadId:E}),await o(),E&&T&&e({type:N.SelectThread,threadId:E,projectId:x,focusInput:!0})}catch(y){throw S&&E&&(e({type:N.RemoveCreatingThread,projectId:x,threadId:E}),e({type:N.RemoveProcessingThread,threadId:E})),y}}catch(b){console.error("Failed to create thread:",b);const g=`Failed to create thread: ${b instanceof Error?b.message:"Unknown error"}`;throw e({type:N.AppendTerminalLine,line:{type:"error",content:g}}),t({variant:"destructive",title:"Thread Creation Failed",description:g}),b}},[o,e,s.projects,t]),f=c.useCallback(async(x,j)=>{e({type:N.AddDeletingThread,threadId:j});try{await Wl(x,j),await o(),s.selectedThreadId===j&&e({type:N.SelectThread,threadId:"",projectId:""})}catch(b){console.error("Failed to delete thread:",b)}finally{e({type:N.RemoveDeletingThread,threadId:j})}},[o,s.selectedThreadId,e]),p=c.useCallback(async x=>{e({type:N.AddDeletingProject,projectId:x});const b=s.projects.find(g=>g.projectId===x)?.threads.map(g=>g.threadId)||[];for(const g of b)e({type:N.AddDeletingThread,threadId:g});try{await Hl(x),await o(),s.selectedProjectId===x&&e({type:N.SelectThread,threadId:"",projectId:""})}catch(g){console.error("Failed to delete project:",g)}finally{e({type:N.RemoveDeletingProject,projectId:x});for(const g of b)e({type:N.RemoveDeletingThread,threadId:g})}},[o,s.selectedProjectId,s.projects,e]),h=c.useCallback(async x=>{const j=a;if(l(null),!(!j||!x))try{e({type:N.SetCreatingProject,isCreating:!0}),e({type:N.AppendTerminalLine,line:{type:"system",content:`Running setup script: ${j.command}`}});const b=await kn(j.projectId,j.command,!0);if(b){const g=b.getReader(),R=new TextDecoder;let I="";for(;;){const{done:w,value:S}=await g.read();if(w)break;I+=R.decode(S,{stream:!0});const E=I.split(`
|
|
18
|
+
`);I=E.pop()||"";for(const T of E)if(T.trim())try{const k=JSON.parse(T);typeof k=="string"?e({type:N.AppendTerminalLine,line:{type:"output",content:k}}):k.type==="error"&&e({type:N.AppendTerminalLine,line:{type:"error",content:k.message}})}catch{e({type:N.AppendTerminalLine,line:{type:"output",content:T}})}}if(I.trim())try{const w=JSON.parse(I);typeof w=="string"?e({type:N.AppendTerminalLine,line:{type:"output",content:w}}):w.type==="error"&&e({type:N.AppendTerminalLine,line:{type:"error",content:w.message}})}catch{e({type:N.AppendTerminalLine,line:{type:"output",content:I}})}}e({type:N.SetCreatingProject,isCreating:!1}),await o()}catch(b){e({type:N.SetCreatingProject,isCreating:!1}),console.error("Failed to run setup script:",b),e({type:N.AppendTerminalLine,line:{type:"error",content:`Failed to run setup script: ${b instanceof Error?b.message:"Unknown error"}`}})}},[a,e,o]);return c.useEffect(()=>{let x=!0;async function j(){try{const b=await es();if(!x)return;if(e({type:N.SetProjects,projects:b.projects}),!s.selectedThreadId)for(const g of b.projects){const R=g.threads.find(I=>I.isSelected);if(R){e({type:N.SelectThread,threadId:R.threadId,projectId:g.projectId});break}}}catch(b){console.error("Failed to load projects:",b)}}return j(),()=>{x=!1}},[e,s.selectedThreadId,s.configUpdatedAt]),{projects:s.projects,selectedProjectId:s.selectedProjectId,selectedThreadId:s.selectedThreadId,refreshProjects:o,handleSelectThread:i,handleCreateProject:d,handleCreateWebApp:u,handleCreateThread:m,handleDeleteThread:f,confirmDeleteProject:p,pendingSetupScriptConfirmation:a,resolveSetupScriptConfirmation:h}}function vc(){const s=F.c(2),[e,t]=c.useState(Nc);let n,a;return s[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>{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]=n,s[1]=a):(n=s[0],a=s[1]),c.useEffect(n,a),e}function Nc(){return document.hasFocus()}let ts=null;function wc(){ts||(ts=new Audio("/pop.wav")),ts.currentTime=0,ts.play().catch(s=>{console.debug("Could not play completion sound:",s)})}function Sc(){const{state:s,dispatch:e}=Pe(),t=vc(),n=c.useRef(null),a=c.useRef(!1),l=c.useRef([]),o=c.useRef(s),i=c.useRef(t);c.useEffect(()=>{o.current=s},[s]),c.useEffect(()=>{i.current=t},[t]);const d=c.useCallback(async()=>{try{const m=await Gl(),f=l.current.filter(p=>!m.includes(p));for(const p of f)p!==o.current.selectedThreadId&&e({type:N.MarkThreadCompleted,threadId:p});return f.length>0&&!i.current&&wc(),l.current=m,e({type:N.SetProcessingThreads,threadIds:m}),m}catch(m){return console.error("Failed to fetch processing threads:",m),[]}},[e]);c.useEffect(()=>{const m=()=>{if(n.current||a.current)return;a.current=!0;const p=async()=>{(await d()).length>0||o.current.isStreaming||o.current.isCreatingProject?n.current=setTimeout(p,1e3):(n.current=null,a.current=!1)};p()},f=()=>{n.current&&(clearTimeout(n.current),n.current=null),a.current=!1};return(s.isStreaming||s.isCreatingProject||s.processingThreadIds.length>0)&&m(),()=>{f()}},[s.isStreaming,s.isCreatingProject,s.processingThreadIds.length,d]),c.useEffect(()=>{(s.isStreaming||s.isCreatingProject)&&d()},[s.isStreaming,s.isCreatingProject,d]);const u=c.useCallback(m=>{e({type:N.ClearThreadCompleted,threadId:m})},[e]);return{processingThreadIds:s.processingThreadIds,completedThreadIds:s.completedThreadIds,isThreadProcessing:m=>s.processingThreadIds.includes(m),isThreadCompleted:m=>s.completedThreadIds.includes(m),clearCompleted:u}}const Ps=768;function Cc(){const s=F.c(2),[e,t]=c.useState(void 0);let n,a;return s[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>{const l=window.matchMedia(`(max-width: ${Ps-1}px)`),o=()=>{t(window.innerWidth<Ps)};return l.addEventListener("change",o),t(window.innerWidth<Ps),()=>l.removeEventListener("change",o)},a=[],s[0]=n,s[1]=a):(n=s[0],a=s[1]),c.useEffect(n,a),!!e}function Tc(){const{state:s,dispatch:e}=Pe(),t=Cc(),{projects:n,handleSelectThread:a,handleCreateProject:l,handleCreateWebApp:o,handleCreateThread:i,handleDeleteThread:d,confirmDeleteProject:u,refreshProjects:m,pendingSetupScriptConfirmation:f,resolveSetupScriptConfirmation:p}=bc(),{processingThreadIds:h,completedThreadIds:x,clearCompleted:j}=Sc(),[b,g]=c.useState(!1),[R,I]=c.useState(!1),[w,S]=c.useState(!1),[E,T]=c.useState(!1),[k,y]=c.useState(null),[C,_]=c.useState(null),D=c.useRef(null);c.useEffect(()=>{E||(async()=>{try{(await wo()).onboardingCompleted||S(!0)}catch(U){console.error("Failed to check onboarding status:",U)}finally{T(!0)}})()},[E]),c.useEffect(()=>{R||e({type:N.ConfigUpdated})},[R,e]),c.useEffect(()=>{w||e({type:N.ConfigUpdated})},[w,e]);const P=c.useCallback(G=>{const U=n.find(q=>q.projectId===G);U&&y({id:U.projectId,name:os(U)})},[n]),z=c.useCallback(G=>{i(G,"")},[i]),L=c.useCallback(G=>{const U=n.find(q=>q.projectId===G);U&&_({id:U.projectId,name:os(U),setupScript:U.setupScript,runCommand:U.runCommand})},[n]),W=c.useCallback(async(G,U)=>{j(U),await a(G,U),t&&s.sidebarOpen&&e({type:N.ToggleSidebar})},[a,t,s.sidebarOpen,e,j]);return c.useEffect(()=>{s.sidebarOpen?D.current?.expand():D.current?.collapse()},[s.sidebarOpen]),r.jsxs(Re,{delayDuration:200,children:[r.jsxs(mc,{direction:"horizontal",className:"h-screen bg-background",children:[r.jsx(jr,{ref:D,defaultSize:t?100:20,minSize:t?50:12,maxSize:t?100:32,collapsible:!0,collapsedSize:0,className:"border-r border-border",children:r.jsx("div",{className:"h-full overflow-hidden",children:r.jsx(jl,{projects:n,selectedThreadId:s.selectedThreadId,processingThreadIds:h,completedThreadIds:x,deletingThreadIds:s.deletingThreadIds,deletingProjectIds:s.deletingProjectIds,onSelectThread:W,onCreateProject:()=>g(!0),onCreateThread:z,onDeleteThread:d,onDeleteProject:P,onOpenConfiguration:()=>I(!0),onProjectSettings:L,onCollapseSidebar:()=>e({type:N.ToggleSidebar}),isMobile:t})})}),!t&&r.jsx(fc,{withHandle:!0}),r.jsx(jr,{minSize:40,className:`overflow-hidden ${t&&s.sidebarOpen?"hidden":""}`,children:r.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[r.jsx(Di,{}),r.jsx("main",{className:"flex-1 overflow-hidden",children:r.jsx(ii,{})})]})}),r.jsx(zi,{open:b,onOpenChange:g,onSubmitClone:l,onSubmitWebApp:o}),r.jsx(ec,{open:k!==null,projectName:k?.name,onOpenChange:G=>!G&&y(null),onConfirm:()=>{k&&(u(k.id),y(null))}}),r.jsx(tc,{open:C!==null,onOpenChange:G=>!G&&_(null),projectId:C?.id??"",onRefresh:m}),r.jsx(sc,{open:f!==null,suggestedCommand:f?.command??null,onConfirm:p}),r.jsx(ac,{open:R,onOpenChange:I,onRestartOnboarding:async()=>{try{await Co(),I(!1),S(!0)}catch(G){console.error("Failed to restart onboarding:",G)}}}),r.jsx(cc,{open:w,onOpenChange:S,onComplete:()=>{T(!0),m()}}),r.jsx(dc,{})]}),r.jsx(xc,{})]})}function Ic(){const s=F.c(5),[e,t]=c.useReducer(dl,Nn);let n;s[0]!==e?(n={state:e,dispatch:t},s[0]=e,s[1]=n):n=s[1];let a;s[2]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx(Tc,{}),s[2]=a):a=s[2];let l;return s[3]!==n?(l=r.jsx(yc,{attribute:"class",defaultTheme:"system",enableSystem:!0,storageKey:"tarsk-theme",children:r.jsx(wn.Provider,{value:n,children:a})}),s[3]=n,s[4]=l):l=s[4],l}nl.createRoot(document.getElementById("root")).render(r.jsx(c.StrictMode,{children:r.jsx(Ic,{})}));
|