@wrongstack/webui 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/index-CJmc6zwr.js +94 -0
- package/dist/assets/{index-CRAjL4S_.css → index-TCwASaz8.css} +1 -1
- package/dist/assets/vendor-Dff2jyfM.js +521 -0
- package/dist/index.css +14 -0
- package/dist/index.css.map +1 -1
- package/dist/index.html +3 -2
- package/dist/index.js +1054 -899
- package/dist/index.js.map +1 -1
- package/dist/server/entry.js +135 -49
- package/dist/server/entry.js.map +1 -1
- package/dist/server/index.js +135 -49
- package/dist/server/index.js.map +1 -1
- package/package.json +21 -14
- package/dist/assets/index-C1jTV4WR.js +0 -609
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
var fs=Object.defineProperty;var gs=(o,t,s)=>t in o?fs(o,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[t]=s;var ce=(o,t,s)=>gs(o,typeof t!="symbol"?t+"":t,s);import{t as bs,c as ys,a as Re,j as e,r as d,X as $e,C as Ce,b as pt,T as xt,I as vs,p as Be,H as ws,W as He,B as Ot,S as Pt,d as js,e as Ns,f as Oe,R as Fe,D as at,g as it,h as lt,i as ht,k as Pe,l as ft,M as gt,m as bt,n as ks,V as Ss,o as Cs,A as Ft,q as Ee,F as $s,s as Ts,u as Ms,v as Es,P as _t,w as Ds,x as Ls,y as Kt,L as we,z as yt,G as Rs,E as _e,J as vt,K as wt,N as As,O as Is,U as Os,Q as De,Y as Wt,Z as Ut,_ as Ps,$ as Fs,a0 as _s,a1 as Ks,a2 as zt,a3 as Ws,a4 as Ht,a5 as qt,a6 as jt,a7 as Us,a8 as Bt,a9 as zs,aa as Vt,ab as Qt,ac as Hs,ad as qs,ae as Gt,af as Bs,ag as Vs,ah as Qs,ai as Gs,aj as Js,ak as Jt,al as Ys,am as Yt,an as Xs,ao as Xt,ap as Zt,aq as Zs,ar as en,as as tn,at as Ie,au as Nt,av as es,aw as ts,ax as ss,ay as sn,az as nn,aA as on,aB as et,aC as rn,aD as $t,aE as an,aF as ln,aG as cn,aH as dn,aI as un,aJ as mn,aK as pn,aL as Tt,aM as xn,aN as hn}from"./vendor-Dff2jyfM.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))a(n);new MutationObserver(n=>{for(const r of n)if(r.type==="childList")for(const i of r.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&a(i)}).observe(document,{childList:!0,subtree:!0});function s(n){const r={};return n.integrity&&(r.integrity=n.integrity),n.referrerPolicy&&(r.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?r.credentials="include":n.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function a(n){if(n.ep)return;n.ep=!0;const r=s(n);fetch(n.href,r)}})();function $(...o){return bs(ys(o))}const Ne=Re(o=>({toasts:[],push:t=>{const s=`toast_${Date.now()}_${Math.random().toString(36).slice(2,7)}`;return o(a=>({toasts:[...a.toasts,{...t,id:s}]})),s},dismiss:t=>o(s=>({toasts:s.toasts.filter(a=>a.id!==t)}))})),We={success:(o,t=3500)=>Ne.getState().push({message:o,variant:"success",ttl:t}),error:(o,t=6e3)=>Ne.getState().push({message:o,variant:"error",ttl:t}),warn:(o,t=4500)=>Ne.getState().push({message:o,variant:"warn",ttl:t}),info:(o,t=3500)=>Ne.getState().push({message:o,variant:"info",ttl:t}),dismiss:o=>Ne.getState().dismiss(o)};function fn({variant:o}){return o==="success"?e.jsx(Ce,{className:"h-4 w-4 text-green-500"}):o==="error"?e.jsx(pt,{className:"h-4 w-4 text-destructive"}):o==="warn"?e.jsx(xt,{className:"h-4 w-4 text-amber-500"}):e.jsx(vs,{className:"h-4 w-4 text-blue-500"})}function gn({entry:o}){const t=Ne(s=>s.dismiss);return d.useEffect(()=>{const s=setTimeout(()=>t(o.id),o.ttl);return()=>clearTimeout(s)},[o.id,o.ttl,t]),e.jsxs("div",{className:$("flex items-start gap-2 rounded-lg border bg-popover shadow-lg px-3 py-2 text-sm max-w-sm","animate-message",o.variant==="error"&&"border-destructive/40",o.variant==="warn"&&"border-amber-500/40",o.variant==="success"&&"border-green-500/40"),children:[e.jsx(fn,{variant:o.variant}),e.jsx("div",{className:"flex-1 min-w-0 whitespace-pre-wrap break-words leading-snug",children:o.message}),e.jsx("button",{type:"button",onClick:()=>t(o.id),className:"text-muted-foreground hover:text-foreground",title:"Dismiss",children:e.jsx($e,{className:"h-3.5 w-3.5"})})]})}function bn(){const o=Ne(t=>t.toasts);return o.length===0?null:e.jsx("div",{className:"fixed bottom-4 right-4 z-[60] flex flex-col gap-2 pointer-events-auto",children:o.map(t=>e.jsx(gn,{entry:t},t.id))})}let Ue=null;function yn(){if(typeof window>"u")return null;if(Ue)return Ue;const o=window.AudioContext||window.webkitAudioContext;if(!o)return null;try{Ue=new o}catch{return null}return Ue}function Mt(o,t,s){const a=yn();if(!a)return;const n=a.currentTime+t,r=a.createOscillator(),i=a.createGain();r.type="sine",r.frequency.value=o,i.gain.setValueAtTime(0,n),i.gain.linearRampToValueAtTime(.18,n+.01),i.gain.exponentialRampToValueAtTime(1e-4,n+s),r.connect(i).connect(a.destination),r.start(n),r.stop(n+s+.02)}function kt(){Mt(659.25,0,.18),Mt(880,.12,.24)}const vn="#4f46e5";function wn(o){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
|
|
2
|
+
<rect x="2" y="2" width="60" height="60" rx="14" fill="${vn}" />
|
|
3
|
+
<text x="32" y="44" text-anchor="middle" font-family="-apple-system,Segoe UI,Roboto,sans-serif" font-size="38" font-weight="700" fill="#fff">W</text>
|
|
4
|
+
${o==="ready"?'<circle cx="50" cy="14" r="14" fill="#22c55e" stroke="#fff" stroke-width="3" />':o==="error"?'<circle cx="50" cy="14" r="14" fill="#ef4444" stroke="#fff" stroke-width="3" />':o==="running"?'<circle cx="50" cy="14" r="14" fill="#f59e0b" stroke="#fff" stroke-width="3" />':""}
|
|
5
|
+
</svg>`}function jn(o){return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(o)}`}function Nn(){if(typeof document>"u")return null;let o=document.querySelector('link[rel="icon"]');return o||(o=document.createElement("link"),o.rel="icon",o.type="image/svg+xml",document.head.appendChild(o)),o}let ct="idle";function ze(o){ct=o;const t=Nn();t&&(t.href=jn(wn(o)))}let Et=!1;function kn(){Et||typeof document>"u"||(Et=!0,document.addEventListener("visibilitychange",()=>{!document.hidden&&(ct==="ready"||ct==="error")&&ze("idle")}))}let ve="default";typeof window<"u"&&"Notification"in window?ve=Notification.permission:ve="unsupported";async function Sn(){if(ve==="unsupported"||ve==="granted"||ve==="denied")return ve;try{const o=await Notification.requestPermission();return ve=o,o}catch{return"denied"}}function Dt(o,t){if(!(typeof document>"u"||!document.hidden)&&ve==="granted")try{const s=new Notification(o,{body:t,icon:"/favicon.ico",tag:"wrongstack-run"});s.onclick=()=>{window.focus(),s.close()}}catch{}}class Cn{constructor(t){ce(this,"ws",null);ce(this,"url");ce(this,"handlers",new Map);ce(this,"reconnectAttempts",0);ce(this,"maxReconnectAttempts",10);ce(this,"reconnectDelay",1e3);ce(this,"shouldReconnect",!0);ce(this,"reconnectTimer",null);ce(this,"messageQueue",[]);ce(this,"pendingConfirms",new Map);ce(this,"sessionId",null);ce(this,"lastErrorText");ce(this,"statusListeners",new Set);ce(this,"currentStatus",{state:"connecting"});this.url=t??$n()}onStatus(t){return this.statusListeners.add(t),t(this.currentStatus),()=>this.statusListeners.delete(t)}get status(){return this.currentStatus}setStatus(t){this.currentStatus=t;for(const s of this.statusListeners)try{s(t)}catch{}}async connect(){return new Promise((t,s)=>{var a;if(((a=this.ws)==null?void 0:a.readyState)===WebSocket.OPEN){t();return}this.setStatus({state:"connecting"});try{this.ws=new WebSocket(this.url),this.ws.binaryType="arraybuffer";const n=setTimeout(()=>{s(new Error("Connection timeout"))},1e4);let r=!1;this.ws.onopen=()=>{clearTimeout(n),r=!0,console.log("[WS Client] Connected"),this.reconnectAttempts=0,this.lastErrorText=void 0,this.setStatus({state:"open"}),this.flushMessageQueue(),t()},this.ws.onmessage=i=>{try{const c=JSON.parse(i.data);this.handleMessage(c)}catch(c){console.error("[WS Client] Failed to parse message",c)}},this.ws.onerror=i=>{console.error("[WS Client] Error",i),this.lastErrorText="Connection error (see browser devtools)",r||(clearTimeout(n),s(new Error(this.lastErrorText)))},this.ws.onclose=i=>{if(console.log("[WS Client] Disconnected",i.code,i.reason),!r){clearTimeout(n);const c=i.reason||`Closed with code ${i.code}`;this.lastErrorText=c,s(new Error(c));return}i.reason&&!this.lastErrorText?this.lastErrorText=`${i.reason} (code ${i.code})`:!this.lastErrorText&&i.code!==1e3&&(this.lastErrorText=`Closed with code ${i.code}`),this.attemptReconnect()}}catch(n){this.lastErrorText=n instanceof Error?n.message:String(n),this.setStatus({state:"closed",error:this.lastErrorText}),s(n)}})}attemptReconnect(){if(!this.shouldReconnect||this.reconnectAttempts>=this.maxReconnectAttempts){console.log("[WS Client] Not reconnecting"),this.reconnectTimer=null,this.setStatus({state:"closed",error:this.lastErrorText??"Disconnected"});return}this.reconnectAttempts++;const t=Math.min(this.reconnectDelay*2**(this.reconnectAttempts-1),3e4),s=Date.now()+t;console.log(`[WS Client] Reconnecting in ${t}ms (attempt ${this.reconnectAttempts})`),this.setStatus({state:"reconnecting",attempt:this.reconnectAttempts,nextRetryAt:s,lastError:this.lastErrorText}),this.reconnectTimer=setTimeout(async()=>{if(this.shouldReconnect)try{await this.connect()}catch(a){console.error("[WS Client] Reconnect failed",a)}},t)}retryNow(){this.currentStatus.state!=="open"&&(this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.reconnectAttempts=0,this.connect().catch(()=>{}))}flushMessageQueue(){for(;this.messageQueue.length>0;){const t=this.messageQueue.shift();t&&this.send(t)}}handleMessage(t){if(t.type==="tool.confirm_needed"){const s=t.payload;this.pendingConfirms.set(s.id,{resolve:s.resolve});const a={...t,payload:{...s,resolve:()=>{}}};this.emit(a);return}if(t.type==="session.start"){const s=t.payload;this.sessionId=s.sessionId}this.emit(t)}emit(t){const s=this.handlers.get(t.type);if(s)for(const a of s)try{a(t)}catch(n){console.error(`[WS Client] Handler error for ${t.type}`,n)}}send(t){var s;((s=this.ws)==null?void 0:s.readyState)===WebSocket.OPEN?this.ws.send(JSON.stringify(t)):this.messageQueue.push(t)}on(t,s){let a=this.handlers.get(t);return a||(a=new Set,this.handlers.set(t,a)),a.add(s),()=>a==null?void 0:a.delete(s)}off(t,s){var a;(a=this.handlers.get(t))==null||a.delete(s)}sendMessage(t){const s=`msg_${Date.now()}_${crypto.randomUUID().slice(0,8)}`;return this.send({type:"user_message",payload:{id:s,content:t,timestamp:Date.now()}}),s}sendAbort(){this.send({type:"abort",payload:{}})}sendConfirm(t,s){const a=this.pendingConfirms.get(t);a&&(a.resolve(s),this.pendingConfirms.delete(t)),this.send({type:"tool.confirm_result",payload:{id:t,decision:s}})}switchModel(t,s){this.send({type:"model.switch",payload:{provider:t,model:s}})}listProviders(){this.send({type:"providers.list"})}listProviderModels(t){this.send({type:"provider.models",payload:{providerId:t}})}listSavedProviders(){this.send({type:"providers.saved"})}addKey(t,s,a){this.send({type:"key.add",payload:{providerId:t,label:s,apiKey:a}})}updateKey(t,s,a){this.send({type:"key.update",payload:{providerId:t,label:s,apiKey:a}})}deleteKey(t,s){this.send({type:"key.delete",payload:{providerId:t,label:s}})}setActiveKey(t,s){this.send({type:"key.set_active",payload:{providerId:t,label:s}})}addProvider(t,s,a,n){this.send({type:"provider.add",payload:{id:t,family:s,baseUrl:a,apiKey:n}})}removeProvider(t){this.send({type:"provider.remove",payload:{providerId:t}})}newSession(){this.send({type:"session.new"})}clearContext(){this.send({type:"context.clear"})}compactContext(t=!1){this.send({type:"context.compact",payload:{aggressive:t}})}repairContext(){this.send({type:"context.repair"})}debugContext(){this.send({type:"context.debug"})}listContextModes(){this.send({type:"context.modes.list"})}switchContextMode(t){this.send({type:"context.mode.switch",payload:{id:t}})}listTools(){this.send({type:"tools.list"})}listMemory(){this.send({type:"memory.list"})}remember(t,s){this.send({type:"memory.remember",payload:{text:t,scope:s}})}forget(t,s){this.send({type:"memory.forget",payload:{text:t,scope:s}})}listSkills(){this.send({type:"skills.list"})}getDiag(){this.send({type:"diag.get"})}getStats(){this.send({type:"stats.get"})}saveSession(){this.send({type:"session.save"})}resumeSessionById(t){this.send({type:"session.resume",payload:{id:t}})}listModes(){this.send({type:"modes.list"})}switchMode(t){this.send({type:"mode.switch",payload:{id:t}})}listFiles(t,s){this.send({type:"files.list",payload:{query:t,limit:s}})}getTodos(){this.send({type:"todos.get"})}clearTodos(){this.send({type:"todos.clear"})}listSessions(t=50){this.send({type:"sessions.list",payload:{limit:t}})}deleteSession(t){this.send({type:"session.delete",payload:{id:t}})}resumeSession(t){this.send({type:"session.resume",payload:{id:t}})}ping(){this.send({type:"ping"})}disconnect(){var t;this.shouldReconnect=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),(t=this.ws)==null||t.close(),this.ws=null}get isConnected(){var t;return((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN}get currentSessionId(){return this.sessionId}}let tt=null;function $n(){var s;if(typeof window>"u"||!((s=window.location)!=null&&s.hostname))return"ws://127.0.0.1:3457";const t=window.location.hostname.toLowerCase();return t==="localhost"||t==="127.0.0.1"||t==="[::1]"||t==="::1"?"ws://127.0.0.1:3457":`ws://${window.location.hostname}:3457`}function xe(o){return tt||(tt=new Cn(o)),tt}function Tn(o){if(!o)return o;const t=o.split(/\n{2,}/),s=[];for(const n of t)s.length>0&&s[s.length-1].trim()===n.trim()||s.push(n);return s.map(n=>{const r=n.split(`
|
|
6
|
+
`),i=[];for(const c of r)i.length>0&&c.trim().length>0&&i[i.length-1].trim()===c.trim()||i.push(c);return i.join(`
|
|
7
|
+
`)}).join(`
|
|
8
|
+
|
|
9
|
+
`)}const T=Re()(Be((o,t)=>({messages:[],currentAssistantMessageId:null,currentToolId:null,isLoading:!1,abortController:null,executions:new Map,queue:[],runStart:null,thinkingBuffer:"",thinkingStartedAt:null,addMessage:s=>{const a=`msg_${Date.now()}_${crypto.randomUUID().slice(0,8)}`,n={...s,id:a,timestamp:Date.now()};return o(r=>({messages:[...r.messages,n],currentAssistantMessageId:s.role==="assistant"?a:r.currentAssistantMessageId})),a},updateMessage:(s,a)=>{o(n=>({messages:n.messages.map(r=>r.id===s?{...r,...a}:r)}))},appendToMessage:(s,a)=>{o(n=>({messages:n.messages.map(r=>r.id===s?{...r,content:r.content+a}:r)}))},finalizeMessage:s=>{o(a=>({messages:a.messages.map(n=>n.id===s?{...n,content:Tn(n.content),streaming:!1}:n)}))},setToolResult:(s,a,n)=>{o(r=>({messages:r.messages.map(i=>i.id===s?{...i,toolResult:a,isError:!n,progressLines:void 0}:i)}))},appendToolProgress:(s,a)=>{o(n=>({messages:n.messages.map(r=>{if(r.id!==s)return r;const c=[...r.progressLines??[],a],l=c.length>30?c.slice(c.length-30):c;return{...r,progressLines:l}})}))},setLoading:s=>o({isLoading:s}),setAbortController:s=>o({abortController:s}),clearMessages:()=>o({messages:[],currentAssistantMessageId:null,currentToolId:null,executions:new Map}),setCurrentAssistantMessage:s=>o({currentAssistantMessageId:s}),setCurrentToolId:s=>o({currentToolId:s}),truncateAfter:s=>o(a=>{const n=a.messages.findIndex(r=>r.id===s);return n===-1?a:{messages:a.messages.slice(0,n),currentAssistantMessageId:null,currentToolId:null}}),addExecution:s=>{o(a=>{const n=new Map(a.executions);return n.set(s.id,s),{executions:n}})},updateExecution:(s,a)=>{o(n=>{const r=new Map(n.executions),i=r.get(s);return i&&r.set(s,{...i,...a}),{executions:r}})},enqueue:s=>o(a=>({queue:[...a.queue,s]})),dequeue:()=>{const s=t().queue;if(s.length===0)return null;const[a,...n]=s;return o({queue:n}),a},removeQueued:s=>o(a=>({queue:a.queue.filter((n,r)=>r!==s)})),clearQueue:()=>o({queue:[]}),setRunStart:s=>o({runStart:s}),appendThinking:s=>o(a=>({thinkingBuffer:a.thinkingBuffer+s,thinkingStartedAt:a.thinkingStartedAt??Date.now()})),clearThinking:()=>o({thinkingBuffer:"",thinkingStartedAt:null})}),{name:"wrongstack-chat",partialize:()=>({})})),Q=Re()(Be(o=>({provider:"anthropic",model:"claude-sonnet-4-20250514",wsUrl:(()=>{var s;if(typeof window>"u"||!((s=window.location)!=null&&s.hostname))return"ws://127.0.0.1:3457";const t=window.location.hostname.toLowerCase();return t==="localhost"||t==="127.0.0.1"||t==="[::1]"||t==="::1"?"ws://127.0.0.1:3457":`ws://${window.location.hostname}:3457`})(),wsConnected:!1,wsStatus:{state:"connecting"},theme:"system",autoConnect:!0,soundOnComplete:!1,setProvider:t=>o({provider:t}),setModel:t=>o({model:t}),setConfig:t=>o(t),setTheme:t=>o({theme:t}),setWsConnected:t=>o({wsConnected:t}),setWsStatus:t=>o({wsStatus:t,wsConnected:t.state==="open"}),setSoundOnComplete:t=>o({soundOnComplete:t})}),{name:"wrongstack-config"})),H=Re()(Be(o=>({session:null,totalTokens:{input:0,output:0,cacheRead:0,cacheWrite:0},lastInputTokens:0,cost:0,startTime:null,maxContext:0,inputCost:0,outputCost:0,cacheReadCost:0,projectName:"",mode:"default",modes:[],contextMode:"balanced",contextModes:[],iteration:null,todos:[],setSession:t=>o({session:t}),updateUsage:t=>o(s=>{const a=(t.input??0)+(t.cacheRead??0)+(t.cacheWrite??0);return{totalTokens:{input:s.totalTokens.input+t.input,output:s.totalTokens.output+t.output,cacheRead:(s.totalTokens.cacheRead??0)+(t.cacheRead??0),cacheWrite:(s.totalTokens.cacheWrite??0)+(t.cacheWrite??0)},lastInputTokens:a||s.lastInputTokens}}),addCost:t=>o(s=>({cost:s.cost+t})),startSession:t=>o({session:t,startTime:Date.now(),iteration:null,lastInputTokens:0,totalTokens:{input:0,output:0,cacheRead:0,cacheWrite:0},cost:0}),endSession:()=>o({session:null,startTime:null,iteration:null}),setEnv:t=>o(s=>({maxContext:t.maxContext??s.maxContext,projectName:t.projectName??s.projectName,mode:t.mode??s.mode,contextMode:t.contextMode??s.contextMode,inputCost:t.inputCost??s.inputCost,outputCost:t.outputCost??s.outputCost,cacheReadCost:t.cacheReadCost??s.cacheReadCost})),setIteration:t=>o({iteration:t}),setModes:t=>o({modes:t}),setContextModes:t=>o({contextModes:t}),setTodos:t=>o({todos:t})}),{name:"wrongstack-session",partialize:()=>({})})),I=Re()(Be(o=>({sidebarOpen:!0,settingsOpen:!1,currentView:"chat",showConfirmDialog:!1,confirmInfo:null,paletteOpen:!1,shortcutsOpen:!1,searchOpen:!1,searchQuery:"",promptHistory:[],sidebarWidth:288,pinnedIds:[],compactMode:!1,modelSwitcherOpen:!1,favoriteSessionIds:[],sessionNicknames:{},toggleSidebar:()=>o(t=>({sidebarOpen:!t.sidebarOpen})),setSidebarOpen:t=>o({sidebarOpen:t}),setSettingsOpen:t=>o({settingsOpen:t}),setCurrentView:t=>o({currentView:t}),showConfirm:t=>o({showConfirmDialog:!0,confirmInfo:t}),hideConfirm:()=>o({showConfirmDialog:!1,confirmInfo:null}),setPaletteOpen:t=>o({paletteOpen:t}),setShortcutsOpen:t=>o({shortcutsOpen:t}),setSearchOpen:t=>o({searchOpen:t,searchQuery:""}),setSearchQuery:t=>o({searchQuery:t}),pushPrompt:t=>o(s=>{const a=t.trim();if(!a)return s;const n=s.promptHistory.filter(r=>r!==a);return{promptHistory:[a,...n].slice(0,50)}}),setSidebarWidth:t=>o({sidebarWidth:Math.max(200,Math.min(480,Math.round(t)))}),togglePin:t=>o(s=>({pinnedIds:s.pinnedIds.includes(t)?s.pinnedIds.filter(n=>n!==t):[...s.pinnedIds,t]})),unpinAll:()=>o({pinnedIds:[]}),toggleCompactMode:()=>o(t=>({compactMode:!t.compactMode})),setModelSwitcherOpen:t=>o({modelSwitcherOpen:t}),toggleFavoriteSession:t=>o(s=>({favoriteSessionIds:s.favoriteSessionIds.includes(t)?s.favoriteSessionIds.filter(n=>n!==t):[...s.favoriteSessionIds,t]})),setSessionNickname:(t,s)=>o(a=>{const n=s.trim(),r={...a.sessionNicknames};return n?r[t]=n:delete r[t],{sessionNicknames:r}})}),{name:"wrongstack-ui",partialize:o=>({sidebarOpen:o.sidebarOpen,sidebarWidth:o.sidebarWidth,promptHistory:o.promptHistory,pinnedIds:o.pinnedIds,compactMode:o.compactMode,favoriteSessionIds:o.favoriteSessionIds,sessionNicknames:o.sessionNicknames})})),Le=Re()(o=>({entries:[],loading:!1,error:null,setEntries:(t,s=null)=>o({entries:t,error:s,loading:!1}),setLoading:t=>o({loading:t}),removeEntry:t=>o(s=>({entries:s.entries.filter(a=>a.id!==t)})),clearHistory:()=>o({entries:[]})}));function Mn(o){const t=[],s=(a,n)=>{t.push(o.on(a,n))};return s("session.start",a=>{var l;const n=a.payload,r=(l=H.getState().session)==null?void 0:l.id,i=!r||r!==n.sessionId;H.getState().startSession({id:n.sessionId,startedAt:Date.now(),model:n.model,provider:n.provider}),H.getState().setEnv({maxContext:n.maxContext,projectName:n.projectName,mode:n.mode,contextMode:n.contextMode,inputCost:n.inputCost,outputCost:n.outputCost,cacheReadCost:n.cacheReadCost}),Q.getState().setConfig({provider:n.provider,model:n.model}),(i||n.reset)&&T.getState().clearMessages();const c=n.replayMessages;if(c&&c.length>0){const u=T.getState();for(const x of c)if(x.role==="user"||x.role==="assistant"||x.role==="system"){let p="";if(typeof x.content=="string")p=x.content;else if(Array.isArray(x.content)){for(const m of x.content)if(m.type==="text"&&typeof m.text=="string")p+=(p?`
|
|
10
|
+
`:"")+m.text;else if(m.type==="tool_use")u.addMessage({role:"tool",content:"",toolName:String(m.name??"tool"),toolInput:m.input,toolUseId:String(m.id??"")}),p="";else if(m.type==="tool_result"){const f=T.getState().messages;let b;for(let w=f.length-1;w>=0;w--)if(f[w].toolUseId===String(m.tool_use_id??"")){b=f[w];break}b&&u.setToolResult(b.id,typeof m.content=="string"?m.content:JSON.stringify(m.content),!m.is_error)}}p&&u.addMessage({role:x.role,content:p})}}}),s("context.debug",a=>{const n=a.payload,r=u=>u.toLocaleString(),i=[...n.tools.breakdown].sort((u,x)=>x.tokens-u.tokens).slice(0,8),c=[...n.messages.breakdown].sort((u,x)=>x.tokens-u.tokens).slice(0,8),l=["📊 **Context breakdown** (heuristic — 4 chars/token)","",`**Total estimate:** ${r(n.total)} tokens`,`• System prompt: ${r(n.systemPrompt)}`,`• Tool schemas: ${r(n.tools.total)} (${n.tools.count} tools)`,`• Messages: ${r(n.messages.total)} (${n.messages.count} messages)`,"","**Top tool schemas:**",...i.map(u=>` · ${u.name}: ${r(u.tokens)}`),"","**Top messages:**",...c.map(u=>` · #${u.index} ${u.role}: ${r(u.tokens)} — ${u.preview||"(empty)"}`)];T.getState().addMessage({role:"assistant",content:l.join(`
|
|
11
|
+
`)})}),s("key.operation_result",a=>{const n=a.payload;n.success?We.success(n.message):We.error(n.message)}),s("context.compacted",a=>{const n=a.payload;let r=n.reductions.length?n.reductions.map(i=>`${i.phase}: ${i.saved}`).join(", "):"no-op";n.repaired&&(r+=`; repaired ${n.repaired.removedToolUses.length} tool_use, ${n.repaired.removedToolResults.length} tool_result, ${n.repaired.removedMessages} empty messages`),T.getState().addMessage({role:"assistant",content:`🗜️ Context compacted: ${n.before} → ${n.after} tokens (saved ~${n.saved}). ${r}`}),H.setState({lastInputTokens:n.after})}),s("context.repaired",a=>{const n=a.payload,r=n.removedToolUses.length+n.removedToolResults.length+n.removedMessages,i=n.beforeMessages!==void 0&&n.afterMessages!==void 0?` Messages: ${n.beforeMessages} -> ${n.afterMessages}.`:"";T.getState().addMessage({role:"assistant",content:`Context repaired: removed ${r} orphan protocol item(s).${i} tool_use ${n.removedToolUses.length}, tool_result ${n.removedToolResults.length}.`})}),s("session.end",()=>{Q.getState().setWsConnected(!1)}),s("iteration.started",a=>{const n=a.payload;H.getState().setIteration({index:n.index,max:n.maxIterations??0}),T.getState().setLoading(!0),typeof document<"u"&&document.hidden&&ze("running"),T.getState().runStart===null&&T.getState().setRunStart({at:Date.now(),cost:H.getState().cost}),T.getState().setCurrentAssistantMessage(null)}),s("provider.text_delta",a=>{const n=a.payload;T.getState().clearThinking();let r=T.getState().currentAssistantMessageId;r||(r=T.getState().addMessage({role:"assistant",content:"",streaming:!0}),T.getState().setCurrentAssistantMessage(r)),T.getState().appendToMessage(r,n.text)}),s("provider.thinking_delta",a=>{const n=a.payload;n.text&&T.getState().appendThinking(n.text)}),s("tool.started",a=>{const n=a.payload,r=T.getState().messages.find(c=>c.toolUseId===n.id);if(r){T.getState().setCurrentToolId(r.id);return}T.getState().clearThinking(),T.getState().setCurrentAssistantMessage(null);const i=T.getState().addMessage({role:"tool",content:"",toolName:n.name,toolInput:n.input,toolUseId:n.id});T.getState().setCurrentToolId(i),T.getState().addExecution({id:n.id,name:n.name,input:n.input,ok:!0,startedAt:Date.now()})}),s("tool.progress",a=>{const n=a.payload,r=(n.text??"").trim();if(!r)return;const c=T.getState().messages.find(u=>u.toolUseId===n.id);if(!c)return;const l=n.eventType==="warning"?"⚠ ":"";T.getState().appendToolProgress(c.id,l+r)}),s("tool.executed",a=>{const n=a.payload,{messages:r,currentToolId:i}=T.getState(),c=n.id?r.find(l=>l.toolUseId===n.id):i?r.find(l=>l.id===i):void 0;c&&(T.getState().setToolResult(c.id,n.output??"",n.ok),T.getState().updateMessage(c.id,{toolDurationMs:n.durationMs})),n.id&&T.getState().updateExecution(n.id,{completedAt:Date.now(),durationMs:n.durationMs,output:n.output,ok:n.ok}),i&&c&&c.id===i&&T.getState().setCurrentToolId(null)}),s("provider.response",a=>{const n=a.payload;H.getState().updateUsage(n.usage);const{inputCost:r,outputCost:i,cacheReadCost:c}=H.getState(),l=(n.usage.input*r+n.usage.output*i+(n.usage.cacheRead??0)*c)/1e6;l>0&&H.getState().addCost(l),n.stopReason!=="tool_use"&&n.stopReason!=="tool_call"&&T.getState().setLoading(!1);const u=T.getState().currentAssistantMessageId;u&&(T.getState().finalizeMessage(u),n.usage.output>0&&T.getState().updateMessage(u,{usage:n.usage})),T.getState().setCurrentAssistantMessage(null),T.getState().clearThinking()}),s("tool.confirm_needed",a=>{const n=a.payload;I.getState().showConfirm({id:n.id,toolName:n.toolName,input:n.input,suggestedPattern:n.suggestedPattern})}),s("run.result",a=>{const n=a.payload;H.getState().setIteration(null),T.getState().setLoading(!1),T.getState().setCurrentAssistantMessage(null),T.getState().clearThinking();const r=T.getState().runStart;if(r&&n.status==="done"){const c=T.getState().messages;let l=-1,u=0;for(let x=c.length-1;x>=0;x--){const p=c[x];if(p.role==="assistant"&&l===-1&&p.content&&(l=x),p.role==="tool"&&p.timestamp>=r.at&&(u+=1),p.role==="user"&&p.timestamp<=r.at)break}if(l!==-1){const x=H.getState().cost;T.getState().updateMessage(c[l].id,{runSummary:{iterations:n.iterations,tools:u,durationMs:Date.now()-r.at,costDelta:Math.max(0,x-r.cost)}})}}if(T.getState().setRunStart(null),n.status!=="done"&&n.error)T.getState().addMessage({role:"assistant",content:`Error: ${n.error.message}`,isError:!0}),We.error(`Run ended: ${n.error.message}`),Dt("WrongStack run failed",n.error.message),typeof document<"u"&&document.hidden&&ze("error");else if(n.status==="done"&&(typeof document<"u"&&document.hidden&&(We.success(`Run completed in ${n.iterations} iteration${n.iterations===1?"":"s"}`),Dt("WrongStack run finished",`Completed in ${n.iterations} iteration${n.iterations===1?"":"s"}.`),ze("ready")),Sn(),Q.getState().soundOnComplete))try{kt()}catch{}const i=T.getState().dequeue();if(i){const c=xe(Q.getState().wsUrl);T.getState().addMessage({role:"user",content:i}),T.getState().setLoading(!0),c.sendMessage(i)}}),s("tools.list",a=>{const n=a.payload,r=[`🛠️ **Registered tools** (${n.tools.length})`,"",...n.tools.map(i=>`• \`${i.name}\`${i.params.length?` (${i.params.join(", ")})`:""} — ${i.description||"_no description_"}`)];T.getState().addMessage({role:"assistant",content:r.join(`
|
|
12
|
+
`)})}),s("memory.list",a=>{var i;const n=a.payload,r=(i=n.text)==null?void 0:i.trim();T.getState().addMessage({role:"assistant",content:n.error?`Memory read failed: ${n.error}`:r?`🧠 **Memory**
|
|
13
|
+
|
|
14
|
+
${r}`:`🧠 **Memory**
|
|
15
|
+
|
|
16
|
+
_empty — nothing remembered yet_`})}),s("skills.list",a=>{const n=a.payload;if(!n.enabled){T.getState().addMessage({role:"assistant",content:`🎯 **Skills**
|
|
17
|
+
|
|
18
|
+
_disabled (config.features.skills = false)_`});return}const r=[`🎯 **Skills** (${n.skills.length})`,"",...n.skills.length===0?["_none registered_"]:n.skills.map(i=>`• \`${i.name}\`${i.version?` v${i.version}`:""} _(${i.source})_ — ${i.description||i.trigger||"_no description_"}`)];n.error&&r.push("",`⚠ ${n.error}`),T.getState().addMessage({role:"assistant",content:r.join(`
|
|
19
|
+
`)})}),s("diag.get",a=>{const n=a.payload,r=["🩺 **Runtime diagnostics**","",`**Provider:** \`${n.provider}\` / \`${n.model}\``,`**Mode:** \`${n.mode}\``,`**Session:** \`${n.sessionId}\``,`**CWD:** \`${n.cwd}\``,"",`**Tools:** ${n.tools.count}`,`**Messages:** ${n.messages} · **Todos:** ${n.todos}`,`**Usage:** ${n.usage.input.toLocaleString()} in · ${n.usage.output.toLocaleString()} out${n.usage.cacheRead?` · ${n.usage.cacheRead.toLocaleString()} cache`:""}`,"",`**Features:** memory=${n.features.memory?"✓":"✗"} · skills=${n.features.skills?"✓":"✗"} · modelsRegistry=${n.features.modelsRegistry?"✓":"✗"}`];T.getState().addMessage({role:"assistant",content:r.join(`
|
|
20
|
+
`)})}),s("stats.get",a=>{const n=a.payload,r=Math.floor(n.elapsedMs/1e3),i=r<60?`${r}s`:r<3600?`${Math.floor(r/60)}m ${r%60}s`:`${Math.floor(r/3600)}h ${Math.floor(r%3600/60)}m`,c=["📈 **Session stats**","",`**Session:** \`${n.sessionId}\``,`**Provider/Model:** \`${n.provider}\` / \`${n.model}\``,`**Elapsed:** ${i}`,"",`**Usage:** ${n.usage.input.toLocaleString()} in · ${n.usage.output.toLocaleString()} out`,...n.cache&&n.cache.readTokens>0?[`**Cache:** ${n.cache.readTokens.toLocaleString()} read · ${n.cache.writeTokens.toLocaleString()} write · hit ratio ${(n.cache.hitRatio*100).toFixed(1)}%`]:[],`**Cost:** $${n.cost.toFixed(4)}`,"",`**Messages:** ${n.messages} · **Files read:** ${n.readFiles} · **Tools available:** ${n.tools}`];T.getState().addMessage({role:"assistant",content:c.join(`
|
|
21
|
+
`)})}),s("todos.updated",a=>{const n=a.payload;H.getState().setTodos(n.todos??[])}),s("modes.list",a=>{const n=a.payload;H.getState().setModes(n.modes.map(r=>({id:r.id,name:r.name,description:r.description}))),H.getState().setEnv({mode:n.activeId})}),s("context.modes.list",a=>{const n=a.payload;H.getState().setContextModes(n.modes.map(r=>({id:r.id,name:r.name,description:r.description,thresholds:r.thresholds,preserveK:r.preserveK,eliseThreshold:r.eliseThreshold}))),H.getState().setEnv({contextMode:n.activeId})}),s("context.mode.changed",a=>{const n=a.payload;H.getState().setEnv({contextMode:n.id})}),s("sessions.list",a=>{const n=a.payload;Le.getState().setEntries(n.sessions??[],n.error??null)}),s("error",a=>{const n=a.payload;T.getState().addMessage({role:"assistant",content:`[${n.phase}] ${n.message}`,isError:!0}),T.getState().setLoading(!1)}),()=>{for(const a of t)a()}}function En(){const{autoConnect:o,wsUrl:t}=Q(),s=Q(n=>n.setWsStatus),a=d.useRef(!1);d.useEffect(()=>{if(!o)return;kn();const n=xe(t),r=n.onStatus(c=>s(c));if(n.connect().catch(c=>{console.error("[WS] Connection failed:",c)}),a.current)return()=>{r()};a.current=!0;const i=Mn(n);return()=>{i(),r(),a.current=!1}},[o,t,s])}function ge(){const{wsUrl:o}=Q(),t=xe(o),s=d.useCallback(A=>t.isConnected?t.sendMessage(A):null,[t]),a=d.useCallback(()=>t.sendAbort(),[t]),{hideConfirm:n}=I(),r=d.useCallback((A,_)=>{t.sendConfirm(A,_),n()},[t,n]),i=d.useCallback((A,_)=>t.switchModel(A,_),[t]),c=d.useCallback(()=>t.listProviders(),[t]),l=d.useCallback(A=>t.listProviderModels(A),[t]),u=d.useCallback(()=>t.listSavedProviders(),[t]),x=d.useCallback((A,_,N)=>t.addKey(A,_,N),[t]),p=d.useCallback((A,_,N)=>t.updateKey(A,_,N),[t]),m=d.useCallback((A,_)=>t.deleteKey(A,_),[t]),f=d.useCallback((A,_)=>t.setActiveKey(A,_),[t]),b=d.useCallback((A,_,N,Z)=>t.addProvider(A,_,N,Z),[t]),w=d.useCallback(A=>t.removeProvider(A),[t]),S=d.useCallback(A=>{Le.getState().setLoading(!0),t.listSessions(A)},[t]),y=d.useCallback(A=>{Le.getState().removeEntry(A),t.deleteSession(A)},[t]),g=d.useCallback(A=>t.resumeSessionById(A),[t]),R=d.useCallback(()=>t.saveSession(),[t]),ee=d.useCallback(()=>t.listTools(),[t]),K=d.useCallback(()=>t.listMemory(),[t]),U=d.useCallback(()=>t.listSkills(),[t]),G=d.useCallback(()=>t.getDiag(),[t]),z=d.useCallback(()=>t.getStats(),[t]),Y=d.useCallback(()=>t.listModes(),[t]),te=d.useCallback(A=>t.switchMode(A),[t]),re=d.useCallback(()=>t.listContextModes(),[t]),X=d.useCallback(A=>t.switchContextMode(A),[t]),B=d.useCallback(()=>t.repairContext(),[t]);return{client:t,sendMessage:s,sendAbort:a,sendConfirm:r,switchModel:i,listProviders:c,listProviderModels:l,listSavedProviders:u,addKey:x,updateKey:p,deleteKey:m,setActiveKey:f,addProvider:b,removeProvider:w,listSessions:S,deleteSession:y,resumeSession:g,saveSession:R,listTools:ee,listMemory:K,listSkills:U,getDiag:G,getStats:z,listModes:Y,switchMode:te,listContextModes:re,switchContextMode:X,repairContext:B}}function Dn(){const o=I(S=>S.paletteOpen),t=I(S=>S.setPaletteOpen),s=I(S=>S.setCurrentView),a=Q(S=>S.setTheme),{entries:n}=Le(),{addMessage:r,clearMessages:i}=T(),c=ge(),[l,u]=d.useState(""),[x,p]=d.useState(0),m=d.useRef(null);d.useEffect(()=>{o&&(u(""),p(0),requestAnimationFrame(()=>{var S;return(S=m.current)==null?void 0:S.focus()}))},[o]),d.useEffect(()=>{const S=y=>{if((y.ctrlKey||y.metaKey)&&y.key.toLowerCase()==="k"){y.preventDefault(),t(!I.getState().paletteOpen);return}y.key==="Escape"&&I.getState().paletteOpen&&(y.preventDefault(),t(!1))};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[t]);const f=d.useMemo(()=>{const S=[{id:"help",category:"Command",label:"Show slash commands",icon:ws,keywords:["help","commands","?"],run:()=>{r({role:"assistant",content:"Type `/` in the message box to see every slash command."})}},{id:"tools",category:"Command",label:"List tools",icon:He,keywords:["tools","list"],run:()=>c.listTools()},{id:"memory",category:"Command",label:"Show memory",icon:Ot,keywords:["memory","remember","notes"],run:()=>c.listMemory()},{id:"skills",category:"Command",label:"List skills",icon:Pt,keywords:["skills"],run:()=>c.listSkills()},{id:"diag",category:"Command",label:"Runtime diagnostics",icon:js,keywords:["diag","diagnostics","debug"],run:()=>c.getDiag()},{id:"stats",category:"Command",label:"Session stats (tokens, cache, cost)",icon:Ns,keywords:["stats","tokens","cost","cache"],run:()=>c.getStats()},{id:"clear",category:"Session",label:"Clear context",hint:"Wipe in-memory context, keep session id",icon:Oe,keywords:["clear","reset","wipe"],run:()=>{var y,g;i(),(g=(y=c.client)==null?void 0:y.clearContext)==null||g.call(y)}},{id:"new",category:"Session",label:"New session",hint:"Brand-new on disk + memory",icon:Fe,keywords:["new","fresh","session"],run:()=>{var y,g;return(g=(y=c.client)==null?void 0:y.newSession)==null?void 0:g.call(y)}},{id:"compact",category:"Session",label:"Compact context",icon:at,keywords:["compact","shrink","context"],run:()=>{var y,g;return(g=(y=c.client)==null?void 0:y.compactContext)==null?void 0:g.call(y)}},{id:"repair-context",category:"Session",label:"Repair context",hint:"Remove orphan tool protocol blocks",icon:He,keywords:["repair","context","tool_use","tool_result"],run:()=>{var y,g;return(g=(y=c.client)==null?void 0:y.repairContext)==null?void 0:g.call(y)}},{id:"export",category:"Session",label:"Export chat as markdown",icon:it,keywords:["export","save","markdown","download"],run:()=>St()},{id:"export-html",category:"Session",label:"Export chat as HTML",hint:"Self-contained, opens in any browser",icon:it,keywords:["export","html","download","archive"],run:()=>Rn()},{id:"history",category:"Command",label:"Open history",icon:lt,keywords:["history","sessions"],run:()=>s("history")},{id:"settings",category:"Command",label:"Open settings",icon:ht,keywords:["settings","config"],run:()=>s("settings")},{id:"model",category:"Command",label:"Change provider/model",icon:Pe,keywords:["model","provider","change"],run:()=>s("settings")},{id:"theme-light",category:"Theme",label:"Theme: Light",icon:ft,keywords:["theme","light","mode"],run:()=>a("light")},{id:"theme-dark",category:"Theme",label:"Theme: Dark",icon:gt,keywords:["theme","dark","mode"],run:()=>a("dark")},{id:"theme-system",category:"Theme",label:"Theme: Follow system",icon:bt,keywords:["theme","system","auto"],run:()=>a("system")},{id:"compact-toggle",category:"Command",label:"Toggle compact density",icon:ks,hint:"Ctrl+Shift+D",keywords:["compact","dense","density","size"],run:()=>I.getState().toggleCompactMode()},{id:"sound-toggle",category:"Command",label:Q.getState().soundOnComplete?"Sound on completion: ON — turn off":"Sound on completion: OFF — turn on",icon:Q.getState().soundOnComplete?Ss:Cs,hint:"Chime when a run finishes",keywords:["sound","audio","chime","notify","beep"],run:()=>{const y=!Q.getState().soundOnComplete;Q.getState().setSoundOnComplete(y),y&&kt()}}];for(const y of n.slice(0,10))y.isCurrent||S.push({id:`resume-${y.id}`,category:"Session",label:`Resume: ${y.title||"(empty)"}`,hint:`${y.provider}/${y.model}`,icon:Ft,keywords:["resume",y.title,y.id,y.provider,y.model],run:()=>c.resumeSession(y.id)});return S},[n,c,s,a,r,i]),b=d.useMemo(()=>{const S=l.toLowerCase().trim();return S?f.filter(y=>[y.label,y.hint??"",y.category,...y.keywords??[]].join(" ").toLowerCase().includes(S)):f},[f,l]);if(d.useEffect(()=>{x>=b.length&&p(0)},[b.length,x]),!o)return null;const w=S=>{S&&(t(!1),S.run())};return e.jsx("div",{className:"fixed inset-0 z-50 bg-background/60 backdrop-blur-sm flex items-start justify-center pt-[14vh] px-4",onClick:()=>t(!1),onKeyDown:S=>{S.key==="Escape"&&t(!1)},children:e.jsxs("div",{onClick:S=>S.stopPropagation(),onKeyDown:S=>S.stopPropagation(),className:"w-full max-w-2xl rounded-xl border bg-popover shadow-2xl overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b",children:[e.jsx(Ee,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("input",{ref:m,value:l,onChange:S=>u(S.target.value),placeholder:"Search commands, sessions, settings…",className:"flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground",onKeyDown:S=>{S.key==="ArrowDown"?(S.preventDefault(),p(y=>(y+1)%Math.max(1,b.length))):S.key==="ArrowUp"?(S.preventDefault(),p(y=>(y-1+Math.max(1,b.length))%Math.max(1,b.length))):S.key==="Enter"&&(S.preventDefault(),w(b[x]))}}),e.jsx("kbd",{className:"text-[10px] text-muted-foreground border rounded px-1.5 py-0.5",children:"Esc"})]}),e.jsx("div",{className:"max-h-[60vh] overflow-y-auto",children:b.length===0?e.jsxs("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:['No matches for "',l,'"']}):Ln(b,x,w,p)}),e.jsxs("div",{className:"border-t px-4 py-2 text-[10px] uppercase tracking-wider text-muted-foreground flex items-center gap-3",children:[e.jsx("span",{children:"↑↓ navigate"}),e.jsx("span",{children:"↵ select"}),e.jsx("span",{children:"Esc dismiss"})]})]})})}function Ln(o,t,s,a){const n={};return o.forEach((r,i)=>{n[r.category]||(n[r.category]=[]),n[r.category].push({item:r,globalIdx:i})}),e.jsx("div",{className:"p-1",children:Object.entries(n).map(([r,i])=>e.jsxs("div",{children:[e.jsx("div",{className:"px-3 pt-2 pb-1 text-[10px] uppercase tracking-wider text-muted-foreground",children:r}),i.map(({item:c,globalIdx:l})=>{const u=c.icon,x=l===t;return e.jsxs("button",{type:"button",onMouseEnter:()=>a(l),onClick:()=>s(c),className:$("w-full flex items-center gap-3 px-3 py-2 rounded text-left text-sm transition-colors",x?"bg-accent text-accent-foreground":"hover:bg-accent/40"),children:[e.jsx(u,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"truncate",children:c.label}),c.hint&&e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:c.hint})]}),x&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"↵"})]},c.id)})]},r))})}function St(){const o=T.getState().messages;T.getState();const t=[],s=new Date().toISOString().slice(0,19).replace(/[:T]/g,"-");t.push("# WrongStack chat export"),t.push(`*Exported: ${new Date().toISOString()}*`),t.push("");for(const i of o)if(i.role==="user")t.push("## 👤 User"),t.push(""),t.push(i.content),t.push("");else if(i.role==="assistant")t.push("## 🤖 Assistant"),t.push(""),t.push(i.content),t.push("");else if(i.role==="tool"){const c=i.isError?"❌":i.toolResult!==void 0?"✅":"⏳";t.push(`### 🔧 Tool: \`${i.toolName??"unknown"}\` ${c}`),i.toolInput!==void 0&&(t.push("```json"),t.push(JSON.stringify(i.toolInput,null,2)),t.push("```")),i.toolResult&&(t.push("<details><summary>Output</summary>"),t.push(""),t.push("```"),t.push(i.toolResult),t.push("```"),t.push("</details>")),t.push("")}const a=new Blob([t.join(`
|
|
22
|
+
`)],{type:"text/markdown"}),n=URL.createObjectURL(a),r=document.createElement("a");r.href=n,r.download=`wrongstack-chat-${s}.md`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}function Rn(){var u,x,p;const o=T.getState().messages,t=H.getState(),s=new Date().toISOString().slice(0,19).replace(/[:T]/g,"-"),a=m=>m.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),n=o.map(m=>{if(m.role==="tool"){const S=m.isError?"❌":m.toolResult!==void 0?"✅":"⏳";return`
|
|
23
|
+
<section class="bubble tool ${m.isError?"error":""}">
|
|
24
|
+
<header><span class="icon">🔧</span><code>${a(m.toolName??"tool")}</code> ${S}</header>
|
|
25
|
+
${m.toolInput!==void 0?`<details><summary>Input</summary><pre>${a(JSON.stringify(m.toolInput,null,2))}</pre></details>`:""}
|
|
26
|
+
${m.toolResult?`<details><summary>Output</summary><pre>${a(m.toolResult)}</pre></details>`:""}
|
|
27
|
+
</section>`}const f=m.role==="user"?"user":"assistant",b=m.role==="user"?"👤":"🤖",w=m.role==="user"?"User":"Assistant";return`
|
|
28
|
+
<section class="bubble ${f}">
|
|
29
|
+
<header><span class="icon">${b}</span><strong>${w}</strong></header>
|
|
30
|
+
<pre class="content">${escape(m.content)}</pre>
|
|
31
|
+
</section>`}),r=`<!doctype html>
|
|
32
|
+
<html lang="en"><head>
|
|
33
|
+
<meta charset="utf-8">
|
|
34
|
+
<title>WrongStack chat — ${escape(((u=t.session)==null?void 0:u.title)||t.projectName||"export")}</title>
|
|
35
|
+
<style>
|
|
36
|
+
:root { color-scheme: light dark; }
|
|
37
|
+
body { font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; max-width: 920px; margin: 24px auto; padding: 0 16px; }
|
|
38
|
+
h1 { font-size: 20px; margin-bottom: 4px; }
|
|
39
|
+
.meta { color: #666; font-size: 12px; margin-bottom: 24px; }
|
|
40
|
+
.bubble { margin: 12px 0; padding: 10px 14px; border-radius: 10px; border: 1px solid #ddd; }
|
|
41
|
+
.bubble header { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #666; margin-bottom: 6px; }
|
|
42
|
+
.bubble header .icon { margin-right: 4px; }
|
|
43
|
+
.bubble.user { background: #eef4ff; border-color: #c8d8f5; }
|
|
44
|
+
.bubble.assistant { background: #fff; }
|
|
45
|
+
.bubble.tool { background: #fafafa; }
|
|
46
|
+
.bubble.tool.error { background: #fff5f5; border-color: #f5c8c8; }
|
|
47
|
+
pre.content, .bubble pre { white-space: pre-wrap; word-break: break-word; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; margin: 0; }
|
|
48
|
+
details summary { cursor: pointer; color: #555; font-size: 12px; }
|
|
49
|
+
details pre { margin-top: 6px; background: #f4f4f4; padding: 8px; border-radius: 6px; max-height: 360px; overflow: auto; }
|
|
50
|
+
@media (prefers-color-scheme: dark) {
|
|
51
|
+
body { background: #0d0d0f; color: #e6e6e6; }
|
|
52
|
+
.bubble { border-color: #2a2a2e; }
|
|
53
|
+
.bubble.user { background: #16213a; border-color: #2a3d6b; }
|
|
54
|
+
.bubble.assistant { background: #161618; }
|
|
55
|
+
.bubble.tool { background: #131315; }
|
|
56
|
+
.bubble.tool.error { background: #2a1717; border-color: #5c2a2a; }
|
|
57
|
+
details pre { background: #1a1a1c; }
|
|
58
|
+
.meta, .bubble header, details summary { color: #999; }
|
|
59
|
+
}
|
|
60
|
+
</style>
|
|
61
|
+
</head><body>
|
|
62
|
+
<h1>WrongStack chat — ${escape(((x=t.session)==null?void 0:x.title)||t.projectName||"export")}</h1>
|
|
63
|
+
<div class="meta">
|
|
64
|
+
Exported ${new Date().toISOString()}${(p=t.session)!=null&&p.provider?` · ${escape(t.session.provider)}/${escape(t.session.model)}`:""} · ${o.length} message${o.length===1?"":"s"}
|
|
65
|
+
</div>
|
|
66
|
+
${n.join("")}
|
|
67
|
+
</body></html>`,i=new Blob([r],{type:"text/html;charset=utf-8"}),c=URL.createObjectURL(i),l=document.createElement("a");l.href=c,l.download=`wrongstack-chat-${s}.html`,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(c)}function An({query:o,onPick:t,onClose:s}){const a=ge(),n=Q(p=>p.wsUrl),[r,i]=d.useState([]),[c,l]=d.useState(0),u=d.useRef(null),x=d.useRef(null);return d.useEffect(()=>{const m=xe(n).on("files.list",f=>{var w;const b=f.payload;i(b.files??[]),l(0),(w=x.current)==null||w.resolve(b.files??[]),x.current=null});return()=>m()},[n]),d.useEffect(()=>(u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{a.client.listFiles(o,50)},80),()=>{u.current&&clearTimeout(u.current)}),[o,a.client]),d.useEffect(()=>{const p=m=>{if(m.key==="ArrowDown")m.preventDefault(),l(f=>(f+1)%Math.max(1,r.length));else if(m.key==="ArrowUp")m.preventDefault(),l(f=>(f-1+Math.max(1,r.length))%Math.max(1,r.length));else if(m.key==="Enter"||m.key==="Tab"){if(r.length===0)return;m.preventDefault(),t(r[c])}else m.key==="Escape"&&(m.preventDefault(),s())};return window.addEventListener("keydown",p,!0),()=>window.removeEventListener("keydown",p,!0)},[r,c,t,s]),e.jsxs("div",{className:"absolute bottom-full left-0 right-0 mb-2 rounded-lg border bg-popover shadow-md p-1 text-sm max-h-72 overflow-auto",children:[e.jsxs("div",{className:"px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground border-b mb-1 flex items-center justify-between",children:[e.jsxs("span",{children:["@ Files ",o&&`· "${o}"`]}),e.jsx("span",{children:"↑/↓ select · ↵ insert · Esc dismiss"})]}),r.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground italic",children:o?`No files match "${o}"`:"Searching project…"}):r.map((p,m)=>e.jsxs("button",{type:"button",onClick:()=>t(p),onMouseEnter:()=>l(m),className:$("w-full text-left px-3 py-1.5 rounded transition-colors flex items-center gap-2 font-mono text-xs",m===c?"bg-accent text-accent-foreground":"hover:bg-accent/40"),children:[p.includes("/")?e.jsx($s,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}):e.jsx(Ts,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),e.jsx("span",{className:"truncate",children:p})]},p))]})}const In=Es("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",{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"}}),q=d.forwardRef(({className:o,variant:t,size:s,asChild:a=!1,...n},r)=>{const i=a?Ms:"button";return e.jsx(i,{className:$(In({variant:t,size:s,className:o})),ref:r,...n})});q.displayName="Button";const dt=[{name:"/help",category:"App",description:"Show every slash command and what it does"},{name:"/export",category:"Session",description:"Download the current chat as markdown"},{name:"/todos",category:"Inspect",description:"List current todos (try `/todos clear` to reset)"},{name:"/clear",category:"Session",description:"Wipe current context (keeps session id, disk record stays)"},{name:"/new",category:"Session",description:"Start a brand-new session (fresh on disk and in memory)"},{name:"/compact",category:"Session",description:"Shrink context — elide ancient tool output"},{name:"/repair",category:"Session",description:"Repair orphan tool_use/tool_result blocks in context"},{name:"/debug",category:"Inspect",aliases:["/context"],description:"Per-section context size breakdown"},{name:"/tools",category:"Inspect",description:"List every registered tool the model can call"},{name:"/memory",category:"Inspect",description:"Show all remembered notes (project + user scope)"},{name:"/skill",category:"Inspect",aliases:["/skills"],description:"List active skills"},{name:"/diag",category:"Inspect",description:"Runtime diagnostics (provider, tools, features, mode, usage)"},{name:"/stats",category:"Inspect",description:"Session stats: tokens, cache hit ratio, cost, elapsed"},{name:"/save",category:"Session",description:"Force-flush the session (auto-saved already)"},{name:"/abort",category:"Run",aliases:["/stop"],description:"Abort the current run"},{name:"/settings",category:"App",aliases:["/model"],description:"Open settings (provider/model/keys)"}],On=["Run","Session","Inspect","App"];function Lt(o,t){let s=t-1;for(;s>=0;){const a=o[s];if(a==="@"){const n=s>0?o[s-1]:"";return s===0||/\s/.test(n??"")?{start:s,query:o.slice(s+1,t)}:null}if(/\s/.test(a))return null;s--}return null}function Pn(o){const t=o.toLowerCase();return t==="/"||t===""?dt:dt.filter(s=>{var a;return s.name.startsWith(t)||(((a=s.aliases)==null?void 0:a.some(n=>n.startsWith(t)))??!1)})}function Fn(){const{isLoading:o,setLoading:t,addMessage:s,clearMessages:a}=T(),n=T(v=>v.queue),r=T(v=>v.enqueue),i=T(v=>v.removeQueued),c=T(v=>v.clearQueue),{setCurrentView:l}=I(),u=I(v=>v.pushPrompt),x=I(v=>v.promptHistory),p=ge(),{sendMessage:m,sendAbort:f,client:b}=p,w=H(v=>v.lastInputTokens),S=H(v=>v.maxContext),[y,g]=d.useState(""),[R,ee]=d.useState(0),[K,U]=d.useState(-1),[G,z]=d.useState(null),[Y,te]=d.useState(null),[re,X]=d.useState(!1),B=d.useRef(null),A=d.useCallback(v=>{var j,W,ae,J,me,de;const C=v.trim(),L=C.indexOf(" "),h=(L===-1?C:C.slice(0,L)).toLowerCase(),M=L===-1?"":C.slice(L+1).trim(),E=h;switch(E){case"/help":{const ne=["📖 **Slash commands**","",...dt.map(D=>{var O;return`• \`${D.name}\`${(O=D.aliases)!=null&&O.length?` (${D.aliases.map(V=>`\`${V}\``).join(", ")})`:""} — ${D.description}`})];return s({role:"assistant",content:ne.join(`
|
|
68
|
+
`)}),!0}case"/clear":return a(),(j=b==null?void 0:b.clearContext)==null||j.call(b),!0;case"/new":return(W=b==null?void 0:b.newSession)==null||W.call(b),!0;case"/compact":case"/compact!":return(ae=b==null?void 0:b.compactContext)==null||ae.call(b,E==="/compact!"),!0;case"/repair":return(J=b==null?void 0:b.repairContext)==null||J.call(b),!0;case"/debug":case"/context":return(me=b==null?void 0:b.debugContext)==null||me.call(b),!0;case"/tools":return p.listTools(),!0;case"/memory":return p.listMemory(),!0;case"/skill":case"/skills":return p.listSkills(),!0;case"/diag":return p.getDiag(),!0;case"/stats":return p.getStats(),!0;case"/save":return p.saveSession(),!0;case"/todos":{if(M.toLowerCase()==="clear")return(de=b==null?void 0:b.clearTodos)==null||de.call(b),!0;const D=H.getState().todos;if(D.length===0)return s({role:"assistant",content:"✅ **Todos** — _empty. Ask the agent to plan something and they'll show up here._"}),!0;const O=[`✅ **Todos** (${D.filter(V=>V.status==="completed").length}/${D.length} done)`,""];for(const V of D){const ie=V.status==="completed"?"[x]":V.status==="in_progress"?"[~]":"[ ]",pe=V.status==="in_progress"&&V.activeForm?V.activeForm:V.content;O.push(`- ${ie} ${pe}`)}return O.push("","_Use `/todos clear` to wipe the list._"),s({role:"assistant",content:O.join(`
|
|
69
|
+
`)}),!0}case"/export":return St(),s({role:"assistant",content:"📥 Chat exported to your downloads folder."}),!0;case"/abort":case"/stop":return f(),t(!1),!0;case"/settings":case"/model":return l("settings"),!0;default:return!1}},[s,a,b,f,t,l,p]),_=y.startsWith("/")&&!y.includes(" ")?Pn(y):[];d.useEffect(()=>{R>=_.length&&ee(0)},[_.length,R]);const N=d.useCallback(async v=>{if(v.preventDefault(),!y.trim())return;const C=y.trim();if(C.startsWith("/")&&A(C)){u(C),g(""),U(-1);return}if(g(""),U(-1),u(C),o){r(C);return}try{b!=null&&b.isConnected?(s({role:"user",content:C}),t(!0),m(C)):console.error("WebSocket not connected")}catch(L){console.error("Failed to send:",L),t(!1)}},[y,o,r,b,m,t,s,A,u]),Z=d.useCallback(()=>{f(),t(!1)},[f,t]),P=d.useCallback(()=>{f(),t(!1);const v=T.getState().messages;for(let C=v.length-1;C>=0;C--){const L=v[C];if(L.role==="user"&&L.content){g(L.content),requestAnimationFrame(()=>{const h=B.current;h&&(h.style.height="auto",h.style.height=`${Math.min(h.scrollHeight,200)}px`,h.focus(),h.setSelectionRange(L.content.length,L.content.length))});return}}},[f,t]),se=v=>{if(_.length===0&&!G&&x.length>0){if(v.key==="ArrowUp"){const C=v.currentTarget,L=C.value.slice(0,C.selectionStart);if(K>=0||L.indexOf(`
|
|
70
|
+
`)===-1){v.preventDefault();const h=Math.min(x.length-1,K+1);U(h);const M=x[h]??"";g(M),requestAnimationFrame(()=>{const E=B.current;E&&(E.style.height="auto",E.style.height=`${Math.min(E.scrollHeight,200)}px`,E.setSelectionRange(M.length,M.length))});return}}if(v.key==="ArrowDown"&&K>=0){v.preventDefault();const C=K-1;if(C<0)U(-1),g("");else{U(C);const L=x[C]??"";g(L),requestAnimationFrame(()=>{const h=B.current;h&&(h.style.height="auto",h.style.height=`${Math.min(h.scrollHeight,200)}px`,h.setSelectionRange(L.length,L.length))})}return}}if(_.length>0){if(v.key==="ArrowDown"){v.preventDefault(),ee(C=>(C+1)%_.length);return}if(v.key==="ArrowUp"){v.preventDefault(),ee(C=>(C-1+_.length)%_.length);return}if(v.key==="Tab"){v.preventDefault();const C=_[R];C&&(g(C.name+" "),ee(0));return}if(v.key==="Enter"&&!v.shiftKey){const C=_[R];if(C&&C.name!==y.toLowerCase().trim()){v.preventDefault(),g(""),A(C.name);return}}if(v.key==="Escape"){v.preventDefault(),g("");return}}v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),N(v))},ue=()=>{const v=B.current;v&&(v.style.height="auto",v.style.height=`${Math.min(v.scrollHeight,200)}px`)};return e.jsxs("div",{className:"flex flex-col gap-2",children:[Y&&e.jsxs("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/5 text-amber-700 dark:text-amber-300 px-2.5 py-1.5 text-xs flex items-center justify-between gap-2 animate-message",children:[e.jsxs("span",{children:["Pasted"," ",e.jsx("span",{className:"font-mono tabular-nums",children:Y.chars.toLocaleString()})," chars (",e.jsx("span",{className:"font-mono tabular-nums",children:Y.lines})," lines) — fenced code blocks render best with ",e.jsx("span",{className:"font-mono",children:"```"}),"."]}),e.jsx("button",{type:"button",onClick:()=>te(null),className:"text-amber-600/70 hover:text-amber-600 dark:text-amber-300/70 dark:hover:text-amber-300 shrink-0",title:"Dismiss",children:"×"})]}),n.length>0&&e.jsxs("div",{className:"rounded-lg border bg-muted/30 p-2 text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-medium",children:["Queued (",n.length,")"]}),e.jsx("button",{type:"button",onClick:c,className:"text-muted-foreground hover:text-destructive text-xs",children:"Clear all"})]}),e.jsx("ul",{className:"space-y-1",children:n.map((v,C)=>e.jsxs("li",{className:"flex items-start justify-between gap-2 rounded bg-background/60 border px-2 py-1",children:[e.jsx("span",{className:"truncate flex-1 min-w-0",children:v}),e.jsx("button",{type:"button",onClick:()=>i(C),className:"text-muted-foreground hover:text-destructive shrink-0",title:"Remove from queue",children:"×"})]},C))})]}),e.jsxs("form",{onSubmit:N,onDragEnter:v=>{!v.dataTransfer||!Array.from(v.dataTransfer.types).includes("Files")||(v.preventDefault(),X(!0))},onDragOver:v=>{!v.dataTransfer||!Array.from(v.dataTransfer.types).includes("Files")||(v.preventDefault(),v.dataTransfer.dropEffect="copy")},onDragLeave:v=>{v.currentTarget.contains(v.relatedTarget)||X(!1)},onDrop:v=>{if(!v.dataTransfer)return;const C=Array.from(v.dataTransfer.files??[]);if(C.length===0){X(!1);return}v.preventDefault(),X(!1);const L=B.current,h=(L==null?void 0:L.selectionStart)??y.length,M=y.slice(0,h),E=y.slice(h),W=M.length>0&&!/\s$/.test(M)?" ":"",ae=C.map(ie=>`@${ie.name}`),J=ae.join(" "),de=E.length===0||!/^\s/.test(E)?" ":"",ne=`${W}${J}${de}`,D=M+ne+E;g(D);const O=M.length+W.length+ae.slice(0,-1).join(" ").length+(ae.length>1?1:0),V=C[C.length-1].name;requestAnimationFrame(()=>{if(L){const ie=M.length+ne.length-de.length;L.focus(),L.setSelectionRange(ie,ie),L.style.height="auto",L.style.height=`${Math.min(L.scrollHeight,200)}px`}z({start:O,query:V})})},className:$("flex items-end gap-2 relative rounded-lg transition-colors",re&&"ring-2 ring-primary ring-offset-2 ring-offset-background bg-primary/5"),children:[re&&e.jsxs("div",{className:"absolute inset-0 z-20 flex items-center justify-center pointer-events-none rounded-lg bg-primary/10 text-primary text-sm font-medium",children:["Drop file","(s)"," to attach as @-mention"]}),e.jsxs("div",{className:"relative flex-1",children:[G&&e.jsx(An,{query:G.query,onClose:()=>z(null),onPick:v=>{const C=y.slice(0,G.start),L=y.slice(G.start+1+G.query.length),h=`@${v} `,M=C+h+L;g(M),z(null),requestAnimationFrame(()=>{const E=B.current;if(E){const j=C.length+h.length;E.focus(),E.setSelectionRange(j,j),E.style.height="auto",E.style.height=`${Math.min(E.scrollHeight,200)}px`}})}}),!G&&_.length>0&&(()=>{const v={};_.forEach((L,h)=>{v[L.category]||(v[L.category]=[]),v[L.category].push({cmd:L,idx:h})});const C=On.filter(L=>{var h;return(h=v[L])==null?void 0:h.length});return e.jsxs("div",{className:"absolute bottom-full left-0 right-0 mb-2 rounded-lg border bg-popover shadow-md p-1 text-sm max-h-72 overflow-auto",children:[e.jsx("div",{className:"px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground border-b mb-1",children:"↑/↓ select · Tab complete · Enter dispatch · Esc dismiss"}),C.map(L=>e.jsxs("div",{className:"mb-1",children:[e.jsx("div",{className:"px-3 pt-1 pb-0.5 text-[10px] uppercase tracking-wider text-muted-foreground/70 font-semibold",children:L}),v[L].map(({cmd:h,idx:M})=>{var E;return e.jsxs("button",{type:"button",onClick:()=>{g(""),A(h.name)},onMouseEnter:()=>ee(M),className:$("w-full text-left px-3 py-1.5 rounded transition-colors flex items-center gap-3",M===R?"bg-accent text-accent-foreground":"hover:bg-accent/40"),children:[e.jsx("span",{className:"font-mono shrink-0",children:h.name}),(E=h.aliases)!=null&&E.length?e.jsxs("span",{className:"text-xs text-muted-foreground/70 font-mono shrink-0",children:["(",h.aliases.join(", "),")"]}):null,e.jsxs("span",{className:"text-xs text-muted-foreground truncate",children:["— ",h.description]})]},h.name)})]},L))]})})(),e.jsx("textarea",{ref:B,value:y,onChange:v=>{const C=v.target.value;g(C),ue(),K>=0&&U(-1);const L=v.target.selectionStart??C.length;z(Lt(C,L))},onSelect:v=>{const C=v.currentTarget;z(Lt(C.value,C.selectionStart))},onKeyDown:se,onPaste:v=>{var L;const C=((L=v.clipboardData)==null?void 0:L.getData("text"))??"";if(C.length>800){const h=C.split(`
|
|
71
|
+
`).length;te({chars:C.length,lines:h}),setTimeout(()=>te(null),4e3)}},placeholder:b!=null&&b.isConnected?o?"Agent is running — type to queue a follow-up…":"Message WrongStack… (type / for commands, @ for files)":"Connect to server first…",className:$("flex min-h-[44px] w-full resize-none rounded-lg border border-input bg-background px-4 py-3 pr-12","text-sm 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","scrollbar-thin"),rows:1,disabled:!(b!=null&&b.isConnected)}),y.length>0&&(()=>{const v=y.length>=400,C=Math.ceil(y.length/4);let L="text-muted-foreground",h;if(S>0&&v){const E=(w+C+64)/S*100;E>=100?(L="text-red-600 dark:text-red-400 font-medium",h=`Projected ${Math.round(E)}% of ${S.toLocaleString()} ctx — will likely error or compact.`):E>=85?(L="text-amber-600 dark:text-amber-400 font-medium",h=`Projected ${Math.round(E)}% of ${S.toLocaleString()} ctx — getting tight.`):h=`≈ ${C.toLocaleString()} tokens · projected ${Math.round(E)}% of ${S.toLocaleString()} ctx.`}else v&&(h=`≈ ${C.toLocaleString()} tokens (4-char heuristic)`);return e.jsxs("span",{className:$("absolute bottom-1.5 right-12 text-xs tabular-nums",L),title:h,children:[y.length,v&&e.jsxs("span",{className:"ml-1 opacity-70",children:["· ≈",C>=1e3?`${(C/1e3).toFixed(1)}k`:C,"t"]})]})})()]}),e.jsx("div",{className:"flex gap-1",children:o?e.jsxs(e.Fragment,{children:[e.jsx(q,{type:"button",size:"icon",variant:"outline",onClick:P,className:"h-[44px] w-[44px] rounded-lg",title:"Stop run and edit the last prompt (reuse + rewrite)",children:e.jsx(_t,{className:"h-4 w-4"})}),e.jsx(q,{type:"button",size:"icon",variant:"destructive",onClick:Z,className:"h-[44px] w-[44px] rounded-lg",title:"Abort the current run",children:e.jsx(Ds,{className:"h-4 w-4 fill-current"})})]}):e.jsx(q,{type:"submit",size:"icon",disabled:!y.trim()||!(b!=null&&b.isConnected),className:"h-[44px] w-[44px] rounded-lg",children:e.jsx(Ls,{className:"h-4 w-4"})})})]})]})}function _n({wsStatus:o,wsConnected:t}){const s=Q(i=>i.wsUrl),[a,n]=d.useState(Date.now());d.useEffect(()=>{if(o.state!=="reconnecting")return;const i=setInterval(()=>n(Date.now()),500);return()=>clearInterval(i)},[o.state]);const r=()=>xe(s).retryNow();if(o.state==="open"&&t)return e.jsx("div",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 bg-green-500/10 text-green-600 dark:text-green-400",title:"Backend connected",children:e.jsx(Kt,{className:"h-3 w-3"})});if(o.state==="connecting")return e.jsxs("div",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 bg-yellow-500/10 text-yellow-600 dark:text-yellow-400",title:"Connecting to backend",children:[e.jsx(we,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"connecting"})]});if(o.state==="reconnecting"){const i=Math.max(0,Math.ceil((o.nextRetryAt-a)/1e3));return e.jsxs("button",{type:"button",onClick:r,className:$("flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0","bg-orange-500/10 text-orange-600 dark:text-orange-400 hover:bg-orange-500/20","transition-colors"),title:o.lastError?`Reconnecting — last error: ${o.lastError}. Click to retry now.`:"Reconnecting — click to retry now.",children:[e.jsx(we,{className:"h-3 w-3 animate-spin"}),e.jsxs("span",{children:["retry #",o.attempt," in ",i,"s"]})]})}return e.jsxs("button",{type:"button",onClick:r,className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 bg-red-500/10 text-red-600 dark:text-red-400 hover:bg-red-500/20 transition-colors",title:o.state==="closed"&&o.error?`Disconnected: ${o.error}. Click to retry.`:"Disconnected. Click to retry.",children:[e.jsx(yt,{className:"h-3 w-3"}),e.jsxs("span",{className:"flex items-center gap-0.5",children:["offline",e.jsx(Fe,{className:"h-3 w-3 opacity-70"})]})]})}const Kn=[{id:"balanced",name:"Balanced",description:"Default rolling compaction",thresholds:{warn:.6,soft:.75,hard:.9},preserveK:10,eliseThreshold:2e3}];function Wn(){const o=H(u=>u.contextMode),t=H(u=>u.contextModes),{listContextModes:s,switchContextMode:a}=ge(),[n,r]=d.useState(!1),i=d.useRef(null);d.useEffect(()=>{n&&s()},[n,s]),d.useEffect(()=>{if(!n)return;const u=p=>{var m;(m=i.current)!=null&&m.contains(p.target)||r(!1)},x=p=>{p.key==="Escape"&&r(!1)};return document.addEventListener("mousedown",u),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",x)}},[n]);const c=t.length>0?t:Kn,l=c.find(u=>u.id===o)??c[0];return e.jsxs("div",{ref:i,className:"relative shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>r(u=>!u),className:$("flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium","bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 hover:bg-emerald-500/15 transition-colors border border-transparent hover:border-emerald-500/30"),title:"Context-window mode",children:[e.jsx(Rs,{className:"h-3 w-3"}),"ctx: ",e.jsx("span",{className:"font-mono",children:o||l.id}),e.jsx(_e,{className:"h-3 w-3 opacity-60"})]}),n&&e.jsxs("div",{className:"absolute top-full left-0 mt-1 w-80 rounded-md border bg-popover shadow-lg z-30 py-1",children:[e.jsx("div",{className:"px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b",children:"Context Window"}),c.map(u=>e.jsxs("button",{type:"button",onClick:()=>{a(u.id),r(!1)},className:$("w-full text-left px-3 py-2 hover:bg-accent/40 flex items-start gap-2",u.id===o&&"bg-accent/30"),children:[e.jsx(vt,{className:$("h-3.5 w-3.5 mt-0.5 shrink-0",u.id===o?"opacity-100 text-primary":"opacity-0")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-mono",children:u.id}),u.thresholds&&e.jsxs("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:[Math.round(u.thresholds.warn*100),"/",Math.round(u.thresholds.soft*100),"/",Math.round(u.thresholds.hard*100),"%"]})]}),e.jsx("div",{className:"text-[11px] text-muted-foreground leading-snug",children:u.description}),(u.preserveK||u.eliseThreshold)&&e.jsxs("div",{className:"mt-1 text-[10px] text-muted-foreground/80",children:["keep ",u.preserveK??"-"," recent · elide ",u.eliseThreshold??"-","+ tokens"]})]})]},u.id))]})]})}function Un(){const o=H(p=>p.cost),t=H(p=>p.inputCost),s=H(p=>p.outputCost),a=H(p=>p.cacheReadCost),n=T(p=>p.messages),[r,i]=d.useState(!1),c=d.useRef(null);d.useEffect(()=>{if(!r)return;const p=f=>{var b;(b=c.current)!=null&&b.contains(f.target)||i(!1)},m=f=>{f.key==="Escape"&&i(!1)};return document.addEventListener("mousedown",p),document.addEventListener("keydown",m),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",m)}},[r]);const l=(()=>{const p=[];for(const m of n)m.role==="assistant"&&m.runSummary&&m.runSummary.costDelta>0&&p.push({id:m.id,preview:m.content.slice(0,80).replace(/\s+/g," ").trim()||"(empty)",cost:m.runSummary.costDelta,tools:m.runSummary.tools,ms:m.runSummary.durationMs,ts:m.timestamp});return p.sort((m,f)=>f.cost-m.cost),p.slice(0,5)})(),u=p=>p>=.01?`$${p.toFixed(4)}`:p>0?`$${p.toFixed(6).replace(/0+$/,"").replace(/\.$/,"")}`:"$0",x=t>0||s>0;return e.jsxs("div",{ref:c,className:"relative inline-block",children:[e.jsxs("button",{type:"button",onClick:()=>i(p=>!p),className:$("font-medium text-green-600 dark:text-green-400 hover:underline tabular-nums"),title:"Click for per-turn cost breakdown",children:["$",o.toFixed(4)]}),r&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-30 w-80 rounded-md border bg-popover shadow-lg p-3 text-foreground",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium",children:"Cost breakdown"}),e.jsx("span",{className:"font-mono tabular-nums text-sm font-semibold text-green-600 dark:text-green-400",children:u(o)})]}),x?e.jsxs("div",{className:"text-[11px] text-muted-foreground font-mono mb-3 border-b pb-2",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"input /1M"}),e.jsxs("span",{children:["$",t.toFixed(2)]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"output /1M"}),e.jsxs("span",{children:["$",s.toFixed(2)]})]}),a>0&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"cache /1M"}),e.jsxs("span",{children:["$",a.toFixed(2)]})]})]}):e.jsx("div",{className:"text-[11px] text-muted-foreground italic mb-3 border-b pb-2",children:"No pricing for the current model — cost figures are zero."}),l.length===0?e.jsx("div",{className:"text-xs text-muted-foreground italic",children:"No completed turns yet. Run a prompt to see per-turn cost here."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground/80 mb-1",children:["Top ",l.length," expensive turn",l.length===1?"":"s"]}),e.jsx("ul",{className:"space-y-1",children:l.map(p=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>{const m=document.querySelector(`[data-message-id="${p.id}"]`);m&&m.scrollIntoView({behavior:"smooth",block:"center"}),i(!1)},className:"w-full text-left rounded px-2 py-1.5 hover:bg-accent/40 transition-colors",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("span",{className:"text-xs truncate",children:p.preview}),e.jsx("span",{className:"text-xs font-mono tabular-nums text-green-600 dark:text-green-400 shrink-0",children:u(p.cost)})]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground font-mono mt-0.5",children:[p.tools," tool",p.tools===1?"":"s"," · ",(p.ms/1e3).toFixed(1),"s"]})]})},p.id))})]})]})]})}const zn=["path","file_path","pattern","command","cmd","url","query","description","content"];function Hn(o,t){if(t==null)return"";if(typeof t!="object")return be(String(t),120);const s=t,a=(o??"").toLowerCase();if(/^todo(_?write)?$|^todos$/i.test(a)||Array.isArray(s.todos)){const r=s.todos??[];if(Array.isArray(r)){const i=r.filter(u=>u.status==="completed").length,c=r.filter(u=>u.status==="in_progress").length,l=[`${r.length} todo${r.length===1?"":"s"}`];return i>0&&l.push(`${i} done`),c>0&&l.push(`${c} in-progress`),l.join(" · ")}}if(/batch|parallel/.test(a)||Array.isArray(s.tool_uses)||Array.isArray(s.calls)){const r=s.tool_uses??s.calls??s.batch;if(Array.isArray(r)){const i=new Set;for(const u of r)u&&typeof u=="object"&&"name"in u&&i.add(String(u.name));const c=[...i].slice(0,3).join(", "),l=i.size>3?` +${i.size-3}`:"";return`${r.length} sub-tool${r.length===1?"":"s"}${c?` · ${c}${l}`:""}`}}if(/^(edit|str_replace|edit_file|patch)$/.test(a)){const r=st(s),i=typeof s.old_string=="string"?s.old_string:"",c=typeof s.new_string=="string"?s.new_string:"",l=i?i.split(`
|
|
72
|
+
`).length:0,u=c?c.split(`
|
|
73
|
+
`).length:0;return`edit ${r||"(file)"}${l||u?` (${l} → ${u} lines)`:""}`}if(/^(write|write_file|create_file|new_file)$/.test(a)){const r=st(s),i=typeof s.content=="string"?s.content:"",c=i?i.split(`
|
|
74
|
+
`).length:0;return`write ${r||"(file)"}${c?` · ${c} lines`:""}`}if(/^(bash|shell|exec|run|run_command|run_shell)$/.test(a)){const r=s.command??s.cmd??s.script;if(typeof r=="string")return`$ ${be(r,110)}`}if(/^(fetch|http|web|webfetch|curl|request)$/.test(a)){const r=s.url;if(typeof r=="string")return`${(s.method??"GET").toUpperCase()} ${be(r,100)}`}if(/^(grep|search|ripgrep)$/.test(a)){const r=s.pattern,i=s.path??s.glob??s.type;if(typeof r=="string")return i?`grep ${be(r,60)} in ${i}`:`grep ${be(r,100)}`}if(/^(glob|find)$/.test(a)){const r=s.pattern??s.glob;if(typeof r=="string")return`glob ${be(r,100)}`}if(/^(read|read_file|cat)$/.test(a)){const r=st(s),i=s.offset,c=s.limit;if(r&&(typeof i=="number"||typeof c=="number")){const l=i??0,u=typeof c=="number"?l+c:"";return`read ${r} (${l}…${u})`}if(r)return`read ${r}`}for(const r of zn){const i=s[r];if(typeof i=="string"&&i.length>0)return`${r}: ${be(i,100)}`}const n=qn(t);return be(n,120)}function be(o,t){return o.length>t?`${o.slice(0,t-1)}…`:o}function st(o){const t=o.file_path??o.path??o.filepath;return typeof t=="string"?t:""}function qn(o){try{return JSON.stringify(o)}catch{return String(o)}}const ns=d.memo(function({oldText:t,newText:s,caption:a}){const n=d.useMemo(()=>Bn(t,s),[t,s]);if(n===null)return e.jsx("div",{className:"text-xs text-muted-foreground italic px-3 py-2",children:"Diff omitted (file too large to render inline)."});const r=n.filter(c=>c.kind==="add").length,i=n.filter(c=>c.kind==="del").length;return e.jsxs("div",{className:"rounded-lg border bg-background/40 overflow-hidden text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b bg-muted/40",children:[e.jsx("span",{className:"font-mono text-muted-foreground truncate",children:a??"diff"}),e.jsxs("span",{className:"font-mono shrink-0",children:[e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["+",r]}),e.jsx("span",{className:"text-muted-foreground mx-1",children:"·"}),e.jsxs("span",{className:"text-rose-600 dark:text-rose-400",children:["-",i]})]})]}),e.jsx("div",{className:"font-mono leading-relaxed max-h-96 overflow-auto",children:n.map((c,l)=>e.jsxs("div",{className:$("flex",c.kind==="add"&&"bg-emerald-500/10",c.kind==="del"&&"bg-rose-500/10"),children:[e.jsx("span",{className:$("w-6 shrink-0 text-center select-none",c.kind==="add"&&"text-emerald-600 dark:text-emerald-400",c.kind==="del"&&"text-rose-600 dark:text-rose-400",c.kind==="ctx"&&"text-muted-foreground/40"),children:c.kind==="add"?"+":c.kind==="del"?"-":" "}),e.jsx("pre",{className:$("whitespace-pre-wrap break-all flex-1 px-2",c.kind==="ctx"&&"text-muted-foreground/70"),children:c.text||" "})]},l))})]})}),Rt=5e3;function Bn(o,t){const s=o.split(`
|
|
75
|
+
`),a=t.split(`
|
|
76
|
+
`);if(s.length>Rt||a.length>Rt)return null;const n=s.length,r=a.length,i=Array.from({length:n+1},()=>new Array(r+1).fill(0));for(let x=n-1;x>=0;x--)for(let p=r-1;p>=0;p--)s[x]===a[p]?i[x][p]=i[x+1][p+1]+1:i[x][p]=Math.max(i[x+1][p],i[x][p+1]);const c=[];let l=0,u=0;for(;l<n&&u<r;)s[l]===a[u]?(c.push({kind:"ctx",text:s[l]}),l++,u++):i[l+1][u]>=i[l][u+1]?(c.push({kind:"del",text:s[l]}),l++):(c.push({kind:"add",text:a[u]}),u++);for(;l<n;)c.push({kind:"del",text:s[l++]});for(;u<r;)c.push({kind:"add",text:a[u++]});return c}function os(o,t){if(!o||typeof t!="object"||t===null)return null;const s=t,a=String(s.file_path??s.path??"");switch(o){case"edit":case"str_replace":case"edit_file":{const n=typeof s.old_string=="string"?s.old_string:"",r=typeof s.new_string=="string"?s.new_string:"";return!n&&!r?null:{oldText:n,newText:r,caption:`edit ${a}`}}case"write":case"write_file":case"create_file":return{oldText:"",newText:typeof s.content=="string"?s.content:"",caption:`write ${a} (new)`};default:return null}}const Vn=25,nt=12;function ot({text:o,isError:t,className:s,wrapClass:a,showLineNumbers:n}){const r=d.useMemo(()=>o.split(`
|
|
77
|
+
`),[o]),i=r.length>Vn,[c,l]=d.useState(!i),u=c?o:r.slice(0,nt).join(`
|
|
78
|
+
`),x=!!n&&i&&c;return e.jsxs("div",{className:$("rounded-md border bg-background/40 overflow-hidden",s),children:[x?e.jsxs("div",{className:"flex max-h-96 overflow-auto",children:[e.jsx("pre",{"aria-hidden":!0,className:"text-xs font-mono leading-[1.4] py-2 pl-2 pr-2 text-muted-foreground/50 select-none border-r border-border/40 bg-muted/20 tabular-nums text-right whitespace-pre shrink-0",children:r.map((p,m)=>`${m+1}`).join(`
|
|
79
|
+
`)}),e.jsx("pre",{className:$("text-xs font-mono leading-[1.4] py-2 px-2 flex-1 whitespace-pre",t?"text-destructive":"text-foreground"),children:u})]}):e.jsx("pre",{className:$("text-xs font-mono p-2 max-h-96 overflow-auto",a,t?"text-destructive":"text-foreground"),children:u}),i&&e.jsx("button",{type:"button",onClick:()=>l(p=>!p),className:"w-full flex items-center justify-center gap-1 px-2 py-1 border-t bg-muted/30 text-[11px] text-muted-foreground hover:text-foreground transition-colors",children:c?e.jsxs(e.Fragment,{children:[e.jsx(As,{className:"h-3 w-3"}),"Collapse to first ",nt," lines"]}):e.jsxs(e.Fragment,{children:[e.jsx(Is,{className:"h-3 w-3"}),"Show all ",r.length," lines (",r.length-nt," more)"]})})]})}const Qn=d.memo(function({toolName:t,result:s,isError:a,className:n}){const r=d.useMemo(()=>Gn(t,s),[t,s]);return r.kind==="json"?e.jsx(Jn,{value:r.value,isError:a,className:n}):r.kind==="numbered"?e.jsx(ot,{text:s,isError:a,className:n,wrapClass:"whitespace-pre"}):r.kind==="bash"?e.jsxs("div",{className:$("rounded-md border bg-background/40 overflow-hidden",n),children:[r.stdout&&e.jsx(ot,{text:r.stdout,isError:a,className:"border-0 rounded-none bg-transparent",wrapClass:"whitespace-pre-wrap break-all",showLineNumbers:!0}),(r.exitCode!==void 0||r.duration)&&e.jsxs("div",{className:$("flex items-center gap-3 text-[11px] px-2 py-1 border-t bg-muted/30 tabular-nums",r.exitCode&&r.exitCode!==0?"text-destructive":"text-muted-foreground"),children:[r.exitCode!==void 0&&e.jsxs("span",{children:["exit code: ",e.jsx("span",{className:"font-mono",children:r.exitCode})]}),r.duration&&e.jsx("span",{children:r.duration})]})]}):e.jsx(ot,{text:s,isError:a,className:n,wrapClass:"whitespace-pre-wrap break-all",showLineNumbers:!0})});function Gn(o,t){const s=t.trim();if(/^\s*\d+→/m.test(t.slice(0,200)))return{kind:"numbered"};if(s.startsWith("{")&&s.endsWith("}")||s.startsWith("[")&&s.endsWith("]"))try{const i=JSON.parse(s);if(typeof i=="object"&&i!==null)return{kind:"json",value:i}}catch{}const a=!!o&&/^(bash|shell|exec|run)/i.test(o),n=t.match(/(?:^|\n)\s*(?:\[?exit(?:\s*code)?\]?\s*[:=]?\s*)(\d+)\s*$/i),r=t.match(/(?:^|\s)(\d+\s*ms|\d+\.\d+s)\s*$/i);if(a||n){let i=t;return n&&(i=t.slice(0,n.index).trimEnd()),{kind:"bash",stdout:i,exitCode:n?Number(n[1]):void 0,duration:r==null?void 0:r[1]}}return{kind:"plain"}}function Jn({value:o,isError:t,className:s}){const a=d.useMemo(()=>{try{return JSON.stringify(o,null,2)}catch{return String(o)}},[o]),n=a.split(`
|
|
80
|
+
`).length,[r,i]=d.useState(n<30);return e.jsxs("div",{className:$("rounded-md border bg-background/40 overflow-hidden",t&&"border-destructive/40",s),children:[e.jsxs("button",{type:"button",onClick:()=>i(c=>!c),className:"w-full flex items-center justify-between px-2 py-1 border-b bg-muted/30 text-[11px] text-muted-foreground hover:text-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[r?e.jsx(_e,{className:"h-3 w-3"}):e.jsx(wt,{className:"h-3 w-3"}),e.jsxs("span",{className:"font-mono",children:["JSON · ",n," lines"]})]}),e.jsx("span",{children:r?"collapse":"expand"})]}),r&&e.jsx("pre",{className:$("text-xs font-mono whitespace-pre p-2 max-h-96 overflow-auto",t?"text-destructive":"text-foreground"),children:a})]})}async function Yn(o){var t;try{if(typeof navigator<"u"&&((t=navigator.clipboard)!=null&&t.writeText))return await navigator.clipboard.writeText(o),!0}catch{}try{const s=document.createElement("textarea");s.value=o,s.style.position="fixed",s.style.opacity="0",document.body.appendChild(s),s.select();const a=document.execCommand("copy");return document.body.removeChild(s),a}catch{return!1}}const Xn={code({inline:o,className:t,children:s,...a}){const n=/language-(\w+)/.exec(t??""),r=String(s??"").replace(/\n$/,"");return o||!n?e.jsx("code",{className:$("rounded bg-muted/60 px-1.5 py-0.5 text-[0.85em] font-mono",t),...a,children:s}):e.jsxs("div",{className:"not-prose relative my-3 rounded-lg border bg-muted/30 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b bg-muted/40 text-xs",children:[e.jsx("span",{className:"font-mono text-muted-foreground",children:n[1]}),e.jsx(ut,{text:r,label:""})]}),e.jsx("pre",{className:"overflow-x-auto p-3 text-xs leading-relaxed font-mono max-h-[40rem]",children:e.jsx("code",{children:r})})]})}};function ut({text:o,className:t,label:s="Copy"}){const[a,n]=d.useState(!1);return e.jsx("button",{type:"button",onClick:async r=>{r.stopPropagation(),await Yn(o)&&(n(!0),setTimeout(()=>n(!1),1400))},className:$("inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors",t),title:s,children:a?e.jsxs(e.Fragment,{children:[e.jsx(vt,{className:"h-3 w-3 text-green-500"}),e.jsx("span",{children:"Copied"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ws,{className:"h-3 w-3"}),e.jsx("span",{children:s})]})})}function Zn(o,t){if(typeof document>"u")return;const s=new Blob([t],{type:"text/plain;charset=utf-8"}),a=URL.createObjectURL(s),n=document.createElement("a");n.href=a,n.download=o,document.body.appendChild(n),n.click(),document.body.removeChild(n),setTimeout(()=>URL.revokeObjectURL(a),1e3)}function eo(o){const t=(o??"").toLowerCase();return/bash|shell|exec|run/.test(t)?"log":(/grep|search|find/.test(t),"txt")}function to(o){const t=o.split(`
|
|
81
|
+
`);for(let s=0;s<t.length;s++){const a=t[s];if(/^\s*at\s+\S+.*\(.*:\d+:\d+\)\s*$/.test(a)||/^\s*at\s+\S+\.\S+\(\S+\.java:\d+\)\s*$/.test(a)||/^\s+File "[^"]+", line \d+/.test(a))return s}return-1}function so({text:o}){const t=to(o),[s,a]=d.useState(!1);if(t===-1)return e.jsx("pre",{className:"whitespace-pre-wrap break-words font-mono text-xs leading-relaxed",children:o});const n=o.split(`
|
|
82
|
+
`),r=n.slice(0,t).join(`
|
|
83
|
+
`).trim(),i=n.slice(t).join(`
|
|
84
|
+
`),c=i.split(`
|
|
85
|
+
`).filter(l=>l.trim().length>0).length;return e.jsxs("div",{className:"space-y-2",children:[r&&e.jsx("pre",{className:"whitespace-pre-wrap break-words font-mono text-xs leading-relaxed",children:r}),e.jsxs("button",{type:"button",onClick:()=>a(l=>!l),className:"inline-flex items-center gap-1 text-xs text-destructive hover:text-destructive/80 font-medium",children:[s?"▾":"▸"," ",s?"Hide":"Show"," stack trace (",c," frame",c===1?"":"s",")"]}),s&&e.jsx("pre",{className:"whitespace-pre-wrap break-words font-mono text-[11px] leading-snug bg-destructive/5 border border-destructive/20 rounded p-2 max-h-80 overflow-auto",children:i})]})}function no({input:o}){const[t,s]=d.useState({});if(o==null||typeof o!="object"||Array.isArray(o))return e.jsx("pre",{className:"whitespace-pre-wrap break-all text-xs font-mono",children:JSON.stringify(o,null,2)});const a=Object.entries(o);return a.length===0?e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"(no params)"}):e.jsx("div",{className:"text-xs font-mono",children:a.map(([n,r])=>{if(r==null||typeof r=="string"||typeof r=="number"||typeof r=="boolean"){const u=r===null?"null":r===void 0?"undefined":typeof r=="string"?r:String(r),x=typeof r=="string"&&(u.length>80||u.includes(`
|
|
86
|
+
`));return e.jsxs("div",{className:$("py-0.5",x?"flex flex-col gap-0.5":"flex items-baseline gap-2"),children:[e.jsxs("span",{className:"text-muted-foreground shrink-0",children:[n,":"]}),e.jsx("span",{className:$("text-foreground",x?"whitespace-pre-wrap break-all bg-muted/40 rounded px-1.5 py-1":"truncate",typeof r=="string"?"":"text-amber-600 dark:text-amber-400"),title:typeof r=="string"&&!x?u:void 0,children:u})]},n)}const c=!!t[n],l=Array.isArray(r)?`[${r.length} item${r.length===1?"":"s"}]`:`{${Object.keys(r).length} key${Object.keys(r).length===1?"":"s"}}`;return e.jsxs("div",{className:"py-0.5",children:[e.jsxs("button",{type:"button",onClick:()=>s(u=>({...u,[n]:!u[n]})),className:"flex items-baseline gap-2 hover:bg-muted/30 rounded px-1 -mx-1",children:[e.jsx("span",{className:"text-muted-foreground/60 text-[10px]",children:c?"▾":"▸"}),e.jsxs("span",{className:"text-muted-foreground",children:[n,":"]}),e.jsx("span",{className:"text-violet-600 dark:text-violet-400",children:l})]}),c&&e.jsx("pre",{className:"ml-3 mt-1 whitespace-pre-wrap break-all text-[11px] bg-muted/40 rounded px-2 py-1.5",children:JSON.stringify(r,null,2)})]},n)})})}function oo(o){if(o<1e3)return`${o} ms`;if(o<6e4)return`${(o/1e3).toFixed(o<1e4?2:1)}s`;const t=Math.floor(o/6e4),s=Math.floor(o%6e4/1e3);return`${t}m ${s}s`}const qe=d.memo(function({message:t,isFirst:s=!1,isContinuation:a=!1}){const[n,r]=d.useState({}),[i,c]=d.useState(!1),[l,u]=d.useState(""),[x,p]=d.useState(!1),m=t.role==="user",f=t.role==="tool";t.role;const b=T(N=>N.truncateAfter),w=T(N=>N.addMessage),S=T(N=>N.setLoading),y=T(N=>N.isLoading),g=Q(N=>N.wsUrl),R=I(N=>N.pinnedIds),ee=I(N=>N.togglePin),K=I(N=>N.compactMode),U=R.includes(t.id),G=H(N=>N.inputCost),z=H(N=>N.outputCost),Y=H(N=>N.cacheReadCost),te=(()=>{if(t.role!=="assistant"||y)return!1;const N=T.getState().messages;for(let Z=N.length-1;Z>=0;Z--){const P=N[Z];if(P.role==="assistant")return P.id===t.id}return!1})(),re=()=>{const N=T.getState().messages,Z=N.findIndex(v=>v.id===t.id);if(Z===-1)return;let P=-1;for(let v=Z-1;v>=0;v--)if(N[v].role==="user"){P=v;break}if(P===-1)return;const se=N[P];b(se.id),w({role:"user",content:se.content}),S(!0),xe(g).sendMessage(se.content)},X=N=>{r(Z=>({...Z,[N]:!Z[N]}))},B=()=>{u(t.content),c(!0)},A=()=>{c(!1),u("")},_=()=>{const N=l.trim();if(!N){A();return}b(t.id),w({role:"user",content:N}),S(!0),xe(g).sendMessage(N),c(!1),u("")};return e.jsxs("div",{"data-message-id":t.id,"data-pinned":U?"1":void 0,className:$("group flex animate-message rounded-lg transition-shadow",K?"gap-2":"gap-3",m?"flex-row-reverse":"flex-row",U&&"ring-1 ring-amber-500/30 bg-amber-500/[0.02] px-1 -mx-1"),children:[a?e.jsx("div",{className:"flex-shrink-0 w-8 h-8","aria-hidden":!0}):e.jsx("div",{className:$("flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center","ring-2 ring-offset-2 ring-offset-background",m?"bg-primary text-primary-foreground ring-primary/20":f?"bg-secondary text-secondary-foreground ring-secondary/20":"bg-accent text-accent-foreground ring-accent/20"),children:m?e.jsx(Os,{className:"h-4 w-4"}):f?e.jsx(De,{className:"h-4 w-4"}):e.jsx(Wt,{className:"h-4 w-4"})}),e.jsxs("div",{className:$("flex flex-col gap-1.5 max-w-[85%]",m&&"items-end"),children:[s&&!a&&e.jsx("span",{className:$("text-xs font-medium px-1",m?"text-primary":f?"text-secondary":"text-muted-foreground"),children:m?"You":f?"Tool":"Assistant"}),f&&t.toolName&&e.jsxs("button",{type:"button",onClick:()=>X(t.id),className:$("flex items-center gap-2 text-sm font-medium cursor-pointer select-none","hover:bg-muted/50 rounded-lg px-2 py-1 -mx-2 transition-colors",t.isError?"text-destructive":"text-foreground"),children:[e.jsx("span",{className:"text-muted-foreground/50",children:n[t.id]?e.jsx(_e,{className:"h-3 w-3"}):e.jsx(wt,{className:"h-3 w-3"})}),e.jsx(De,{className:"h-3 w-3"}),e.jsx("span",{className:"font-mono",children:t.toolName}),t.toolResult===void 0?e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500 animate-pulse","aria-hidden":!0}):t.isError?e.jsx(pt,{className:"h-3 w-3 text-destructive"}):e.jsx(Ce,{className:"h-3 w-3 text-green-500"}),typeof t.toolDurationMs=="number"&&e.jsx("span",{className:"text-xs text-muted-foreground tabular-nums font-normal",children:oo(t.toolDurationMs)})]}),e.jsx("div",{className:$("rounded-2xl",K?"px-3 py-1.5":"px-4 py-3",m?"bg-primary text-primary-foreground rounded-br-md":f?t.isError?"bg-destructive/5 border border-destructive/20 text-destructive":"bg-muted/80 text-foreground":"bg-card border text-foreground",t.isError&&!f&&"border-destructive/20"),children:f?(()=>{const N=!!n[t.id],Z=t.toolInput!==void 0?Hn(t.toolName,t.toolInput):"",P=t.toolResult?t.toolResult.split(`
|
|
87
|
+
`).length:0;return e.jsxs("div",{className:"space-y-1",children:[Z&&!N&&e.jsx("div",{className:"text-xs text-muted-foreground font-mono truncate",children:Z}),t.toolResult===void 0&&t.progressLines&&t.progressLines.length>0&&e.jsx("div",{className:"mt-1 rounded-md border border-amber-500/20 bg-amber-500/5 p-1.5 text-[11px] font-mono leading-snug max-h-32 overflow-auto",children:t.progressLines.slice(-6).map((se,ue)=>e.jsx("div",{className:"truncate text-muted-foreground",children:se},ue))}),N&&t.toolInput!==void 0&&(()=>{const se=os(t.toolName,t.toolInput);return se?e.jsx(ns,{oldText:se.oldText,newText:se.newText,caption:se.caption}):e.jsxs("div",{className:"p-3 bg-muted/50 rounded-lg overflow-x-auto",children:[e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground mb-2 text-xs",children:[e.jsx(Ut,{className:"h-3 w-3"}),e.jsx("span",{children:"Input"})]}),e.jsx(no,{input:t.toolInput})]})})(),N&&t.toolResult!==void 0&&t.toolResult.length>0&&e.jsxs("div",{className:"relative group/tool",children:[e.jsx(Qn,{toolName:t.toolName,result:t.toolResult,isError:t.isError}),e.jsxs("div",{className:"absolute top-1.5 right-1.5 flex items-center gap-1 opacity-0 group-hover/tool:opacity-100 transition-opacity",children:[e.jsx(ut,{text:t.toolResult,label:"",className:"bg-background/80 border rounded px-1.5 py-0.5"}),t.toolResult.split(`
|
|
88
|
+
`).length>5&&e.jsx("button",{type:"button",onClick:se=>{se.stopPropagation();const ue=eo(t.toolName),v=(t.toolName??"output").replace(/[^a-z0-9_-]+/gi,"-").toLowerCase();Zn(`${v}-${new Date().toISOString().replace(/[:.]/g,"-")}.${ue}`,t.toolResult??"")},className:"inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground bg-background/80 border rounded px-1.5 py-0.5",title:"Download as file",children:e.jsx(it,{className:"h-3 w-3"})})]})]}),N&&t.toolResult!==void 0&&t.toolResult.length===0&&e.jsx("span",{className:"text-xs text-muted-foreground italic",children:"(empty)"}),!N&&t.isError&&t.toolResult&&e.jsx("div",{className:"text-xs font-mono text-destructive truncate",children:t.toolResult.split(`
|
|
89
|
+
`)[0]}),(t.toolResult!==void 0&&t.toolResult.length>0||t.toolInput!==void 0&&Object.keys(t.toolInput??{}).length>0)&&e.jsx("button",{type:"button",onClick:()=>X(t.id),className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:N?"Hide details":`Show details${P>0?` (${P} line${P===1?"":"s"})`:""}`})]})})():i&&m?e.jsxs("div",{className:"flex flex-col gap-2 min-w-[280px]",children:[e.jsx("textarea",{value:l,onChange:N=>u(N.target.value),onKeyDown:N=>{N.key==="Escape"?(N.preventDefault(),A()):N.key==="Enter"&&(N.metaKey||N.ctrlKey)&&(N.preventDefault(),_())},rows:Math.min(8,Math.max(2,l.split(`
|
|
90
|
+
`).length)),className:"w-full resize-none rounded-md border bg-background text-foreground px-2 py-1.5 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-ring"}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] text-primary-foreground/60",children:"⌘/Ctrl+Enter to save · Esc to cancel"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{type:"button",onClick:A,className:"text-xs px-2 py-0.5 rounded border border-primary-foreground/30 hover:bg-primary-foreground/10",children:"Cancel"}),e.jsx("button",{type:"button",onClick:_,disabled:!l.trim(),className:"text-xs px-2 py-0.5 rounded bg-primary-foreground text-primary disabled:opacity-50",children:"Save & resend"})]})]})]}):e.jsx("div",{className:"text-sm leading-relaxed markdown-content",children:t.content?x&&t.role==="assistant"?e.jsx("pre",{className:"whitespace-pre-wrap break-words font-mono text-xs leading-relaxed text-foreground/90 max-h-[40rem] overflow-auto",children:t.content}):t.role==="assistant"&&t.isError?e.jsx(so,{text:t.content}):e.jsx(Ps,{remarkPlugins:[Fs],components:Xn,children:t.content}):t.streaming?e.jsx("span",{className:"inline-block animate-pulse text-muted-foreground",children:"Typing..."}):e.jsx("span",{className:"text-muted-foreground italic",children:"No content"})})}),e.jsxs("div",{className:$("flex items-center gap-2 px-1",m?"flex-row-reverse":"flex-row"),children:[e.jsx("span",{className:"text-xs text-muted-foreground/50",children:new Date(t.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),t.runSummary&&e.jsxs("span",{className:"text-[10px] text-muted-foreground/60 font-mono tabular-nums",title:[`Iterations: ${t.runSummary.iterations}`,`Tool calls: ${t.runSummary.tools}`,`Elapsed: ${(t.runSummary.durationMs/1e3).toFixed(2)}s`,t.runSummary.costDelta>0?`Cost: $${t.runSummary.costDelta.toFixed(4)}`:""].filter(Boolean).join(" · "),children:[t.runSummary.iterations," iter",t.runSummary.tools>0?` · ${t.runSummary.tools} tool${t.runSummary.tools===1?"":"s"}`:""," · ",t.runSummary.durationMs<6e4?`${(t.runSummary.durationMs/1e3).toFixed(1)}s`:`${Math.floor(t.runSummary.durationMs/6e4)}m ${Math.floor(t.runSummary.durationMs%6e4/1e3)}s`,t.runSummary.costDelta>0?` · $${t.runSummary.costDelta>=.01?t.runSummary.costDelta.toFixed(4):t.runSummary.costDelta.toFixed(6).replace(/0+$/,"").replace(/\.$/,"")}`:""]}),t.usage&&(t.usage.input>0||t.usage.output>0)&&(()=>{const N=t.usage,Z=(N.input*G+N.output*z+(N.cacheRead??0)*Y)/1e6,P=G>0||z>0,se=Z>=.01?`$${Z.toFixed(4)}`:Z>0?`$${Z.toFixed(6).replace(/0+$/,"").replace(/\.$/,"")}`:"";return e.jsxs("span",{className:"text-[10px] text-muted-foreground/60 font-mono tabular-nums",title:[`Input: ${N.input.toLocaleString()}`,`Output: ${N.output.toLocaleString()}`,N.cacheRead?`Cache read: ${N.cacheRead.toLocaleString()}`:"",P?`Cost: ${se}`:""].filter(Boolean).join(" · "),children:[N.input.toLocaleString(),"→",N.output.toLocaleString(),N.cacheRead?` · ${N.cacheRead.toLocaleString()} ↺`:"",P&&se?` · ${se}`:""]})})(),!f&&t.content&&!t.streaming&&e.jsx(ut,{text:t.content,label:"",className:"opacity-0 group-hover:opacity-100 transition-opacity"}),t.role==="assistant"&&t.content&&!t.streaming&&e.jsxs("button",{type:"button",onClick:()=>p(N=>!N),title:x?"Show rendered markdown":"Show raw markdown source",className:$("text-xs inline-flex items-center gap-1 transition-opacity",x?"text-primary hover:text-primary/80 opacity-100":"opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-foreground"),children:[e.jsx(_s,{className:"h-3 w-3"}),e.jsx("span",{children:x?"Rendered":"Raw"})]}),m&&!i&&!y&&t.content&&e.jsxs("button",{type:"button",onClick:B,title:"Edit & resend this prompt",className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1",children:[e.jsx(_t,{className:"h-3 w-3"}),e.jsx("span",{children:"Edit"})]}),t.role==="assistant"&&t.content&&!t.streaming&&e.jsxs("button",{type:"button",onClick:()=>ee(t.id),title:U?"Unpin":"Pin this answer",className:$("text-xs inline-flex items-center gap-1 transition-opacity",U?"text-amber-500 hover:text-amber-600 opacity-100":"opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-foreground"),children:[U?e.jsx(Ks,{className:"h-3 w-3"}):e.jsx(zt,{className:"h-3 w-3"}),e.jsx("span",{children:U?"Pinned":"Pin"})]}),te&&t.content&&!t.streaming&&e.jsxs("button",{type:"button",onClick:re,title:"Regenerate this response",className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1",children:[e.jsx(Fe,{className:"h-3 w-3"}),e.jsx("span",{children:"Retry"})]})]})]})]})});function ro(){const o=H(l=>l.mode),t=H(l=>l.modes),{listModes:s,switchMode:a}=ge(),[n,r]=d.useState(!1),i=d.useRef(null);d.useEffect(()=>{n&&s()},[n,s]),d.useEffect(()=>{if(!n)return;const l=x=>{var p;(p=i.current)!=null&&p.contains(x.target)||r(!1)},u=x=>{x.key==="Escape"&&r(!1)};return document.addEventListener("mousedown",l),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",l),document.removeEventListener("keydown",u)}},[n]);const c=t.length>0?t:[{id:"default",name:"Default",description:"Standard agent behaviour"}];return e.jsxs("div",{ref:i,className:"relative shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>r(l=>!l),className:$("flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium","bg-accent/40 text-foreground hover:bg-accent transition-colors border border-transparent hover:border-primary/30"),title:"Active mode",children:["mode: ",e.jsx("span",{className:"font-mono",children:o||"default"}),e.jsx(_e,{className:"h-3 w-3 opacity-60"})]}),n&&e.jsxs("div",{className:"absolute top-full left-0 mt-1 w-64 rounded-md border bg-popover shadow-lg z-30 py-1",children:[e.jsx("div",{className:"px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b",children:"Mode"}),c.map(l=>e.jsxs("button",{type:"button",onClick:()=>{a(l.id),r(!1)},className:$("w-full text-left px-3 py-2 hover:bg-accent/40 flex items-start gap-2",l.id===o&&"bg-accent/30"),children:[e.jsx(vt,{className:$("h-3.5 w-3.5 mt-0.5 shrink-0",l.id===o?"opacity-100 text-primary":"opacity-0")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs font-mono",children:l.id}),l.description&&e.jsx("div",{className:"text-[11px] text-muted-foreground leading-snug",children:l.description})]})]},l.id))]})]})}function ao(){const o=I(x=>x.searchOpen),t=I(x=>x.setSearchOpen),s=I(x=>x.searchQuery),a=I(x=>x.setSearchQuery),n=T(x=>x.messages),r=d.useRef(null),[i,c]=d.useState(0);d.useEffect(()=>{o&&requestAnimationFrame(()=>{var x;return(x=r.current)==null?void 0:x.focus()})},[o]);const l=d.useMemo(()=>{const x=s.trim().toLowerCase();return x?n.filter(p=>p.role==="tool"?(p.toolName??"").toLowerCase().includes(x)||(p.toolResult??"").toLowerCase().includes(x)||JSON.stringify(p.toolInput??"").toLowerCase().includes(x):p.content.toLowerCase().includes(x)).map(p=>p.id):[]},[n,s]);if(d.useEffect(()=>{i>=l.length&&c(0)},[l,i]),d.useEffect(()=>{var R;const x=window,p=(R=x.CSS)==null?void 0:R.highlights,m=x.Highlight;if(!p||!m)return;const f=()=>{p.delete("chat-search"),p.delete("chat-search-active")},b=s.trim();if(!b||!o){f();return}const w=b.toLowerCase(),S=[],y=[],g=l[i];for(const ee of document.querySelectorAll("[data-message-id]")){const U=ee.dataset.messageId===g,G=document.createTreeWalker(ee,NodeFilter.SHOW_TEXT);let z=G.nextNode();for(;z;){const Y=z.nodeValue??"";if(Y.length>0){const te=Y.toLowerCase();let re=0;for(;re<=te.length-w.length;){const X=te.indexOf(w,re);if(X===-1)break;const B=document.createRange();B.setStart(z,X),B.setEnd(z,X+w.length),S.push(B),U&&y.push(B),re=X+w.length}}z=G.nextNode()}}return S.length>0?p.set("chat-search",new m(...S)):p.delete("chat-search"),y.length>0?p.set("chat-search-active",new m(...y)):p.delete("chat-search-active"),f},[s,l,i,o]),d.useEffect(()=>{const x=l[i];if(!x)return;const p=document.querySelector(`[data-message-id="${x}"]`);p&&p.scrollIntoView({behavior:"smooth",block:"center"})},[l,i]),!o)return null;const u=x=>{l.length!==0&&c(p=>(p+x+l.length)%l.length)};return e.jsx("div",{className:"absolute top-2 right-4 z-30 w-[28rem] max-w-[calc(100%-2rem)] rounded-lg border bg-popover shadow-xl",children:e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(Ee,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("input",{ref:r,value:s,onChange:x=>a(x.target.value),onKeyDown:x=>{x.key==="Escape"?(x.preventDefault(),t(!1)):x.key==="Enter"?(x.preventDefault(),u(x.shiftKey?-1:1)):x.key==="ArrowDown"?(x.preventDefault(),u(1)):x.key==="ArrowUp"&&(x.preventDefault(),u(-1))},placeholder:"Search in chat…",className:"flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground tabular-nums shrink-0",children:l.length===0?s?"0":"":`${i+1} / ${l.length}`}),e.jsx("button",{type:"button",onClick:()=>u(-1),disabled:l.length===0,className:$("p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed"),title:"Previous hit",children:e.jsx(Ht,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>u(1),disabled:l.length===0,className:$("p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed"),title:"Next hit",children:e.jsx(qt,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>t(!1),className:"p-1 rounded hover:bg-muted text-muted-foreground",title:"Close (Esc)",children:e.jsx($e,{className:"h-3.5 w-3.5"})})]})})}function io(o){if(o<1e3)return`${o}ms`;if(o<6e4)return`${(o/1e3).toFixed(o<1e4?2:1)}s`;const t=Math.floor(o/6e4),s=Math.floor(o%6e4/1e3);return`${t}m${s}s`}const lo=d.memo(function({tools:t,defaultOpen:s=!1,isContinuation:a=!1}){const[n,r]=d.useState(s);if(t.length===1)return e.jsx(qe,{message:t[0],isFirst:!0,isContinuation:a});const i=t.filter(m=>m.toolResult===void 0).length,c=t.filter(m=>m.isError).length,l=t.reduce((m,f)=>m+(f.toolDurationMs??0),0),u=Array.from(new Set(t.map(m=>m.toolName).filter(Boolean))),x=u.slice(0,3).join(", "),p=u.length>3?` +${u.length-3}`:"";return e.jsxs("div",{className:"flex gap-3 animate-message",children:[a?e.jsx("div",{className:"flex-shrink-0 w-8 h-8","aria-hidden":!0}):e.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-secondary text-secondary-foreground ring-2 ring-offset-2 ring-offset-background ring-secondary/20",children:e.jsx(De,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex flex-col gap-1.5 max-w-[85%] flex-1 min-w-0",children:[e.jsxs("button",{type:"button",onClick:()=>r(m=>!m),className:$("flex items-center gap-2 text-sm font-medium cursor-pointer select-none","hover:bg-muted/50 rounded-lg px-2 py-1.5 -mx-2 transition-colors","border border-border/40 bg-muted/30"),children:[n?e.jsx(_e,{className:"h-3.5 w-3.5 text-muted-foreground"}):e.jsx(wt,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx(De,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsxs("span",{className:"font-mono text-xs",children:[t.length," tool call",t.length===1?"":"s"]}),i>0?e.jsx(we,{className:"h-3 w-3 animate-spin text-amber-500"}):c>0?e.jsx(pt,{className:"h-3 w-3 text-destructive"}):e.jsx(Ce,{className:"h-3 w-3 text-green-500"}),l>0&&e.jsx("span",{className:"text-xs text-muted-foreground tabular-nums font-normal",children:io(l)}),x&&e.jsxs("span",{className:"text-xs text-muted-foreground/80 font-mono truncate",children:["· ",x,p]})]}),n&&e.jsx("div",{className:"space-y-2 pl-3 border-l-2 border-border/40 ml-2",children:t.map(m=>e.jsx(qe,{message:m,isFirst:!1},m.id))})]})]})}),co=[{icon:Ee,title:"Explore",hint:"Understand the code before changing it",tone:"text-blue-600 dark:text-blue-400 bg-blue-500/10 border-blue-500/20",prompts:["Walk me through this codebase: list the top-level packages, the role of each, and how they depend on one another. Highlight any cross-cutting abstractions I should understand first.","Find every place where the WebSocket protocol is defined or consumed (server handlers, client send/receive, type contracts). Show me the message-type table and any gaps where the type isn't enforced.","Locate the entrypoint that boots the agent for normal runs. Trace the call chain from CLI launch all the way to the first model call — what middleware, hooks, and tools are wired along the way?"]},{icon:He,title:"Build",hint:"Add a feature end-to-end",tone:"text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 border-emerald-500/20",prompts:["Add a slash command `/export` that dumps the current chat (messages + tool calls + usage) as a markdown file to ~/.wrongstack/exports/ and surfaces a 'saved to X' toast. Wire backend + ws-client + slash menu entry.","Create a notification toast system (Zustand store + portal-rendered <Toast/> component) and migrate every existing `key.operation_result` success/failure message to use it instead of dropping into chat.","Add structured JSON logging to the WebSocket server: each handler logs `{ts, level, type, payload}` to ~/.wrongstack/logs/webui.jsonl. Make it tail-friendly and respect the existing log.level config."]},{icon:zs,title:"Debug",hint:"Track a problem to its root cause",tone:"text-amber-600 dark:text-amber-400 bg-amber-500/10 border-amber-500/20",prompts:["Something feels off with token accounting — the cost chip and the per-message tally drift apart over a long session. Reproduce locally if you can, then propose a fix. Start by reading the TokenCounter + provider.response handler.","The WebSocket sometimes silently stops streaming text mid-response on lossy networks. Check the reconnect logic, message queue, and how we handle a half-completed text_delta stream after a reconnect.","I want to know why ctx % climbs so fast in long sessions. Use the existing /debug context breakdown to identify the largest contributors and propose three concrete pruning strategies (with token savings estimates)."]},{icon:Pt,title:"Refactor",hint:"Clean up without breaking behavior",tone:"text-violet-600 dark:text-violet-400 bg-violet-500/10 border-violet-500/20",prompts:["Find duplicated logic between packages/cli/src/webui-server.ts and packages/webui/src/server/index.ts. Extract the shared bits into a single source of truth (likely the webui package) and update the CLI to import it.","Look at the Zustand stores in packages/webui/src/stores/index.ts — anything that should be a derived selector instead of stored state? Anything persisted that shouldn't be? Propose a leaner shape and migration plan.","Audit the slash command dispatcher: pull each command's run logic into its own module under packages/webui/src/commands/, make the registry data-driven, and ensure /help auto-generates from the registry (not a hardcoded list)."]}],uo=[{name:"/help",hint:"list every slash command"},{name:"/diag",hint:"runtime diagnostics"},{name:"/stats",hint:"tokens · cache · cost · elapsed"},{name:"/tools",hint:"show registered tools"},{name:"/memory",hint:"show remembered notes"},{name:"/compact",hint:"shrink context"},{name:"/clear",hint:"wipe current context"},{name:"/new",hint:"fresh session"}];function rt(o){var a;const t=document.querySelector("textarea");if(!t)return;const s=(a=Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,"value"))==null?void 0:a.set;s==null||s.call(t,o),t.dispatchEvent(new Event("input",{bubbles:!0})),t.focus()}function mo(){const{projectName:o}=H(),{provider:t,model:s}=Q(),a=Q(w=>w.wsConnected),n=Q(w=>w.wsUrl),r=I(w=>w.setCurrentView),[i,c]=d.useState(void 0);d.useEffect(()=>{if(!a)return;const w=xe(n),S=w.on("providers.saved",y=>{var R;const g=y.payload;c(((R=g.providers)==null?void 0:R.length)??0)});return w.listSavedProviders(),()=>{S()}},[a,n]);const u=I(w=>w.promptHistory).slice(0,6),{listSessions:x,resumeSession:p}=ge(),m=Le(w=>w.entries);d.useEffect(()=>{a&&m.length===0&&x(10)},[a]);const f=I(w=>w.sessionNicknames),b=m.filter(w=>!w.isCurrent).slice(0,4);return e.jsxs("div",{className:"flex flex-col gap-8 py-8 px-2 max-w-5xl mx-auto w-full",children:[e.jsxs("div",{className:"flex flex-col items-center text-center gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-gradient-to-br from-primary via-primary to-primary/60 flex items-center justify-center shadow-lg shadow-primary/20",children:e.jsx(jt,{className:"h-7 w-7 text-primary-foreground"})}),e.jsx("div",{className:"absolute -inset-3 bg-gradient-to-r from-transparent via-primary/10 to-transparent animate-pulse rounded-full -z-10"})]}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-2xl font-semibold tracking-tight",children:["Where do you want to start",o?e.jsxs(e.Fragment,{children:[" in ",e.jsx("span",{className:"text-primary",children:o})]}):"","?"]}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-2 max-w-2xl mx-auto leading-relaxed",children:["WrongStack is connected to your project and ready to read, edit, run commands, search the codebase, track todos, and remember context across sessions. Pick a starting prompt below, write your own, or type ",e.jsx("span",{className:"font-mono text-foreground/80",children:"/"})," ","for the full command palette."]}),t&&s&&e.jsxs("p",{className:"text-xs text-muted-foreground/70 mt-2 font-mono",children:[t," / ",s]})]})]}),a&&i===0&&e.jsxs("button",{type:"button",onClick:()=>r("settings"),className:$("group rounded-xl border bg-gradient-to-br from-amber-500/10 via-amber-500/5 to-transparent","border-amber-500/30 hover:border-amber-500/50 transition-colors","p-4 flex items-center gap-4 text-left"),children:[e.jsx("span",{className:"flex items-center justify-center w-12 h-12 rounded-lg bg-amber-500/15 text-amber-600 dark:text-amber-400 shrink-0",children:e.jsx(Us,{className:"h-6 w-6"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-base font-semibold mb-1",children:"No API key configured yet"}),e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed",children:"Register a provider in Settings before sending a message — otherwise the agent has nothing to talk to. Anthropic, OpenAI, Google, and any OpenAI-compatible endpoint all work."})]}),e.jsxs("span",{className:"flex items-center gap-1 text-xs text-amber-600 dark:text-amber-400 font-medium shrink-0 group-hover:translate-x-0.5 transition-transform",children:["Open Settings ",e.jsx(Bt,{className:"h-3.5 w-3.5"})]})]}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:co.map(w=>{const S=w.icon;return e.jsxs("div",{className:"rounded-xl border bg-card/40 backdrop-blur-sm p-4 flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:$("flex items-center justify-center w-8 h-8 rounded-lg border",w.tone),children:e.jsx(S,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:w.title}),e.jsx("p",{className:"text-xs text-muted-foreground",children:w.hint})]})]}),e.jsx("div",{className:"flex flex-col gap-1.5",children:w.prompts.map((y,g)=>e.jsx("button",{type:"button",onClick:()=>rt(y),className:"text-left text-xs leading-relaxed text-foreground/80 hover:text-foreground border border-transparent hover:border-border/60 rounded-lg px-3 py-2 hover:bg-muted/40 transition-colors line-clamp-3",title:y,children:y},g))})]},w.title)})}),b.length>0&&e.jsxs("div",{className:"rounded-xl border bg-muted/20 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Ft,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium",children:"Pick back up"})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:b.map(w=>e.jsxs("button",{type:"button",onClick:()=>p(w.id),className:"text-left rounded-lg border border-border/40 bg-background/60 hover:border-primary/40 hover:bg-accent/30 px-3 py-2 transition-colors group/sess",title:w.title,children:[e.jsx("div",{className:"text-sm font-medium truncate text-foreground group-hover/sess:text-primary",children:f[w.id]||w.title||"(empty)"}),e.jsxs("div",{className:"text-[10px] text-muted-foreground font-mono truncate mt-0.5",children:[w.provider,"/",w.model,w.tokenTotal>0&&e.jsxs("span",{className:"ml-2",children:["· ",w.tokenTotal.toLocaleString()," tok"]})]})]},w.id))})]}),u.length>0&&e.jsxs("div",{className:"rounded-xl border bg-muted/20 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Ut,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium",children:"Recent prompts"})]}),e.jsx("div",{className:"flex flex-col gap-1.5",children:u.filter(w=>!w.startsWith("/")).slice(0,5).map((w,S)=>e.jsx("button",{type:"button",onClick:()=>rt(w),className:"text-left text-xs leading-relaxed text-muted-foreground hover:text-foreground border border-transparent hover:border-border/60 rounded-lg px-3 py-2 hover:bg-background/60 transition-colors line-clamp-2",title:w,children:w},S))})]}),e.jsxs("div",{className:"rounded-xl border bg-muted/20 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Vt,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-xs uppercase tracking-wider text-muted-foreground font-medium",children:"Quick commands"})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:uo.map(w=>e.jsxs("button",{type:"button",onClick:()=>rt(w.name),className:"text-left flex flex-col gap-0.5 rounded-md border border-border/40 bg-background/60 px-3 py-2 hover:border-primary/40 hover:bg-accent/40 transition-colors",children:[e.jsx("span",{className:"font-mono text-xs text-foreground",children:w.name}),e.jsx("span",{className:"text-[11px] text-muted-foreground truncate",children:w.hint})]},w.name))})]})]})}const Ve=d.forwardRef(({className:o,children:t,...s},a)=>e.jsxs(Qt,{ref:a,className:$("relative overflow-hidden",o),...s,children:[e.jsx(Hs,{className:"h-full w-full rounded-[inherit]",children:t}),e.jsx(rs,{}),e.jsx(qs,{})]}));Ve.displayName=Qt.displayName;const rs=d.forwardRef(({className:o,orientation:t="vertical",...s},a)=>e.jsx(Gt,{ref:a,orientation:t,className:$("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",o),...s,children:e.jsx(Bs,{className:"relative flex-1 rounded-full bg-border"})}));rs.displayName=Gt.displayName;function Ae(o){return o>=1e6?`${(o/1e6).toFixed(1)}M`:o>=1e3?`${(o/1e3).toFixed(o>=1e4?0:1)}k`:String(o)}function po(){const o=T(a=>a.thinkingBuffer);if(!o)return null;const s=o.split(`
|
|
91
|
+
`).slice(-6).join(`
|
|
92
|
+
`).trim();return e.jsxs("div",{className:"flex gap-3 animate-message",children:[e.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-violet-500/10 text-violet-600 dark:text-violet-400 ring-2 ring-offset-2 ring-offset-background ring-violet-500/20",children:e.jsx(Ot,{className:"h-4 w-4 animate-pulse"})}),e.jsxs("div",{className:"flex flex-col gap-1 max-w-[85%] min-w-0",children:[e.jsx("span",{className:"text-xs font-medium text-violet-600 dark:text-violet-400 px-1",children:"Thinking…"}),e.jsx("div",{className:"rounded-2xl rounded-bl-md px-3 py-2 bg-violet-500/[0.04] border border-violet-500/20 text-foreground/80",children:e.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-xs leading-relaxed italic max-h-32 overflow-hidden",children:s||"…"})})]})]})}function xo(){const{messages:o,isLoading:t}=T(),s=I(j=>j.setPaletteOpen),a=I(j=>j.setShortcutsOpen),n=I(j=>j.sidebarOpen),r=I(j=>j.toggleSidebar),i=I(j=>j.compactMode),c=Q(j=>j.setTheme),l=Q(j=>j.theme),{totalTokens:u,cost:x,startTime:p,lastInputTokens:m,maxContext:f,projectName:b,iteration:w}=H(),{wsConnected:S,wsStatus:y,provider:g,model:R}=Q(),{setCurrentView:ee}=I(),K=d.useRef(null),U=f>0&&m>0?Math.min(100,Math.round(m/f*100)):0,G=U>=85?"bg-red-500/15 text-red-600 dark:text-red-400":U>=70?"bg-amber-500/15 text-amber-600 dark:text-amber-400":"bg-muted text-muted-foreground",[z,Y]=d.useState(!0),[te,re]=d.useState(0),[X,B]=d.useState(!1),A=d.useRef(o.length),_=d.useCallback(()=>{var j;return((j=K.current)==null?void 0:j.querySelector("[data-radix-scroll-area-viewport]"))??null},[]);d.useEffect(()=>{const j=_();if(!j)return;const W=()=>{const J=j.scrollHeight-j.scrollTop-j.clientHeight<120;Y(J),J&&(re(0),A.current=o.length);const me=j.scrollTop>j.clientHeight&&j.scrollHeight>j.clientHeight*2.5;B(me)};return j.addEventListener("scroll",W,{passive:!0}),()=>j.removeEventListener("scroll",W)},[_,o.length]),d.useEffect(()=>{const j=_();if(j)if(z)j.scrollTop=j.scrollHeight,A.current=o.length;else{const W=o.length-A.current;W>0&&re(W)}},[o,z,_]);const N=d.useCallback(()=>{const j=_();j&&(j.scrollTo({top:j.scrollHeight,behavior:"smooth"}),Y(!0),re(0),A.current=o.length)},[_,o.length]),Z=d.useCallback(()=>{const j=_();j&&j.scrollTo({top:0,behavior:"smooth"})},[_]),[P,se]=d.useState(null),[ue,v]=d.useState(()=>Date.now()),C=d.useRef(null);d.useEffect(()=>{t&&P===null&&se(Date.now()),!t&&P!==null&&se(null)},[t,P]),d.useEffect(()=>{if(!t)return;const j=setInterval(()=>v(Date.now()),500);return()=>clearInterval(j)},[t]);const L=j=>{if(!j)return"--";const W=Math.floor((Date.now()-j)/1e3);if(W<60)return`${W}s`;const ae=Math.floor(W/60),J=W%60;return`${ae}m ${J}s`},h=(()=>{if(!t)return"idle";const j=o[o.length-1];return(j==null?void 0:j.role)==="assistant"&&!!j.content&&j.streaming?"streaming":"thinking"})(),M=h==="idle"?"bg-muted text-muted-foreground":h==="streaming"?"bg-blue-500/10 text-blue-600 dark:text-blue-400":"bg-amber-500/10 text-amber-600 dark:text-amber-400",E=f>0&&m>0||u.input>0||!!p;return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("header",{className:"flex flex-col border-b bg-card shrink-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 flex-1",children:[!n&&e.jsx(q,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:r,title:"Open sidebar (Ctrl+\\\\)",children:e.jsx(Vs,{className:"h-4 w-4"})}),!n&&e.jsx("div",{className:"flex items-center gap-1.5 shrink-0 mr-1",children:e.jsx("div",{className:"w-5 h-5 rounded bg-primary flex items-center justify-center",children:e.jsx(jt,{className:"h-3 w-3 text-primary-foreground"})})}),e.jsx(_n,{wsStatus:y,wsConnected:S}),e.jsxs("span",{className:$("flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 tabular-nums",M),title:`Agent state: ${h}`,children:[h!=="idle"&&e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-pulse"}),e.jsx("span",{children:h})]}),b&&e.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-muted-foreground shrink-0 min-w-0",title:`Project: ${b}`,children:[e.jsx(Qs,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"truncate max-w-[12rem]",children:b})]}),e.jsxs("button",{type:"button",onClick:()=>I.getState().setModelSwitcherOpen(!0),className:"group flex items-center gap-1 px-2 py-0.5 rounded-md border bg-background/50 hover:bg-accent hover:border-primary/40 transition-colors text-[11px] min-w-0 shrink-0",title:"Change provider / model (Ctrl+M)",children:[e.jsx(Pe,{className:"h-3 w-3 text-muted-foreground group-hover:text-foreground shrink-0"}),e.jsxs("span",{className:"font-mono truncate max-w-[16rem]",children:[e.jsx("span",{className:"text-muted-foreground",children:g||"no-provider"}),e.jsx("span",{className:"text-muted-foreground/40 mx-0.5",children:"/"}),e.jsx("span",{className:"font-medium",children:R||"no-model"})]})]}),e.jsx(ro,{}),e.jsx(Wn,{}),w&&e.jsxs("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium bg-primary/10 text-primary shrink-0",title:"Agent iteration",children:[e.jsx(Gs,{className:"h-3 w-3 animate-pulse"}),"iter ",w.index,w.max>0?`/${w.max}`:""]})]}),e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx(q,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>s(!0),title:"Command palette (Ctrl+K)",children:e.jsx(Js,{className:"h-4 w-4"})}),e.jsx(q,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>{c(l==="light"?"dark":l==="dark"?"system":"light")},title:`Theme: ${l} (click to cycle)`,children:l==="light"?e.jsx(ft,{className:"h-4 w-4"}):l==="dark"?e.jsx(gt,{className:"h-4 w-4"}):e.jsx(bt,{className:"h-4 w-4"})}),e.jsx(q,{variant:"ghost",size:"icon",className:"h-7 w-7 font-mono text-xs",onClick:()=>a(!0),title:"Keyboard shortcuts (?)",children:"?"}),e.jsx(q,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>ee("settings"),title:"Settings",children:e.jsx(ht,{className:"h-4 w-4"})})]})]}),E&&e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-1 border-t bg-muted/20 text-[11px] text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1 tabular-nums",children:[f>0&&m>0&&e.jsxs("span",{className:$("flex items-center gap-1 px-1.5 py-0.5 rounded-full font-medium shrink-0",G),title:`Last input: ${m.toLocaleString()} / ${f.toLocaleString()} tokens`,children:["ctx ",U,"% · ",Ae(m),"/",Ae(f)]}),u.input>0&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium text-foreground",children:Ae(u.input)}),e.jsx("span",{children:"in"})]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium text-foreground",children:Ae(u.output)}),e.jsx("span",{children:"out"})]}),u.cacheRead&&u.cacheRead>0&&(()=>{const j=(u.cacheRead??0)+u.input,W=j>0?Math.round((u.cacheRead??0)/j*100):0;return e.jsxs("span",{className:"flex items-center gap-1",title:`Cache hit ratio: ${W}%`,children:[e.jsx("span",{className:"font-medium text-foreground",children:Ae(u.cacheRead)}),e.jsxs("span",{children:["cache (",W,"%)"]})]})})(),e.jsx(Un,{})]})]}),p&&e.jsx("span",{className:"text-muted-foreground/70 tabular-nums shrink-0",children:L(p)})]})]}),e.jsxs("div",{className:"flex-1 relative overflow-hidden",children:[e.jsx(ao,{}),!z&&e.jsxs("button",{type:"button",onClick:N,className:$("absolute bottom-4 left-1/2 -translate-x-1/2 z-10","flex items-center gap-2 px-4 py-2 rounded-full shadow-lg","bg-primary text-primary-foreground text-xs font-medium","hover:bg-primary/90 transition-colors animate-message"),children:[e.jsx(qt,{className:"h-3.5 w-3.5"}),te>0?`${te} new message${te===1?"":"s"}`:"Jump to latest"]}),X&&e.jsxs("button",{type:"button",onClick:Z,title:"Scroll to top (oldest)",className:$("absolute top-3 right-3 z-10","flex items-center gap-1 px-2.5 py-1 rounded-full shadow-md border","bg-background/90 backdrop-blur-sm text-[11px] text-muted-foreground","hover:text-foreground hover:bg-background transition-colors animate-message"),children:[e.jsx(Ht,{className:"h-3 w-3"}),e.jsx("span",{children:"Top"})]}),e.jsx(Ve,{className:"h-full",ref:K,children:e.jsxs("div",{className:$("mx-auto pb-8",i?"max-w-5xl p-3 space-y-3":"max-w-5xl p-4 space-y-6"),children:[o.length===0&&!t&&e.jsx(mo,{}),(()=>{const j=[];for(let D=0;D<o.length;D++){const O=o[D];if(O.role==="tool"){const V=j[j.length-1];V&&V.kind==="tools"?V.tools.push(O):j.push({kind:"tools",tools:[O],key:O.id})}else{const V=o[D-1];j.push({kind:"msg",message:O,isFirst:!V||V.role!==O.role})}}const W=[];for(const D of j){if(D.kind==="msg"&&D.message.role==="user"){W.push({kind:"user",message:D.message,key:D.message.id});continue}const O=W[W.length-1];if(O&&O.kind==="agent")O.items.push(D);else{const V=D.kind==="msg"?D.message.id:D.key;W.push({kind:"agent",items:[D],key:V})}}let ae=null;const J=D=>{const O=new Date(D);return`${O.getFullYear()}-${O.getMonth()}-${O.getDate()}`},me=D=>{const O=new Date(D),V=new Date,ie=new Date(Date.now()-864e5);return J(D)===J(V.getTime())?"Today":J(D)===J(ie.getTime())?"Yesterday":O.toLocaleDateString(void 0,{weekday:"short",month:"short",day:"numeric",year:O.getFullYear()===V.getFullYear()?void 0:"numeric"})},de=D=>{if(D.kind==="user")return D.message.timestamp;const O=D.items[0];return O.kind==="msg"?O.message.timestamp:O.tools[0].timestamp},ne=[];for(let D=0;D<W.length;D++){const O=W[D],V=de(O),ie=J(V);if(ie!==ae&&(ne.push(e.jsxs("div",{className:"flex items-center gap-3 py-1 text-[11px] text-muted-foreground/70 uppercase tracking-wider font-medium",children:[e.jsx("div",{className:"flex-1 h-px bg-border/50"}),e.jsx("span",{children:me(V)}),e.jsx("div",{className:"flex-1 h-px bg-border/50"})]},`day-${ie}-${D}`)),ae=ie),O.kind==="user"){ne.push(e.jsx(qe,{message:O.message,isFirst:!0},O.key));continue}const pe=D===W.length-1;ne.push(e.jsx("div",{className:$(i?"space-y-1":"space-y-1.5"),children:O.items.map((oe,he)=>{const Te=he>0;if(oe.kind==="msg")return e.jsx(qe,{message:oe.message,isFirst:!Te&&oe.isFirst,isContinuation:Te},oe.message.id);const Qe=pe&&he===O.items.length-1&&t&&oe.tools.some(Ke=>Ke.toolResult===void 0);return e.jsx(lo,{tools:oe.tools,defaultOpen:Qe,isContinuation:Te},oe.key)})},O.key))}return ne})(),e.jsx(po,{}),t&&(()=>{const j=o[o.length-1],W=o.filter(D=>D.role==="tool"&&D.toolResult===void 0);let ae="Thinking…";if(W.length>0){const D=Array.from(new Set(W.map(ie=>ie.toolName).filter(Boolean))),O=D.slice(0,2).join(", "),V=D.length>2?` +${D.length-2}`:"";ae=W.length===1?`Running ${O||"tool"}…`:`Running ${W.length} tools (${O}${V})…`}else(j==null?void 0:j.role)==="assistant"&&j.content?ae="Writing reply…":(j==null?void 0:j.role)==="tool"&&j.toolResult!==void 0&&(ae="Thinking about the next step…");const J=P?Math.max(0,Math.floor((ue-P)/1e3)):0,me=J<60?`${J}s`:`${Math.floor(J/60)}m ${J%60}s`;let de="";const ne=(j==null?void 0:j.role)==="assistant"&&j.streaming&&j.content?j:null;if(ne){const D=C.current;if(!D||D.id!==ne.id)C.current={id:ne.id,at:Date.now(),len:ne.content.length};else{const O=Math.max(1,ue-D.at),V=Math.max(0,ne.content.length-D.len);if(O>500&&V>0){const ie=V*1e3/O;de=ie>=1e3?`${(ie/1e3).toFixed(1)}k ch/s`:`${Math.round(ie)} ch/s`}}}else C.current&&(C.current=null);return e.jsxs("div",{className:"flex gap-3 animate-message",children:[e.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-accent text-accent-foreground ring-2 ring-offset-2 ring-offset-background ring-accent/20",children:e.jsx(Wt,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex flex-col gap-1.5",children:e.jsx("div",{className:"rounded-2xl px-4 py-3 bg-card border text-foreground",children:e.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[e.jsxs("span",{className:"flex gap-1",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.3s]"}),e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.15s]"}),e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce"})]}),e.jsx("span",{className:"text-foreground/90",children:ae}),e.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:me}),w&&e.jsxs("span",{className:"text-xs text-muted-foreground tabular-nums",children:["· iter ",w.index,w.max>0?`/${w.max}`:""]}),de&&e.jsxs("span",{className:"text-xs text-muted-foreground/80 tabular-nums",children:["· ",de]})]})})})]})})()]})})]}),e.jsx("div",{className:"border-t bg-card/50 backdrop-blur supports-[backdrop-filter]:bg-card/50 p-4 shrink-0",children:e.jsxs("div",{className:"max-w-5xl mx-auto",children:[e.jsx(Fn,{}),e.jsx("p",{className:"text-xs text-center text-muted-foreground/50 mt-2",children:"Press Enter to send, Shift+Enter for new line"})]})})]})}const At=Zs,ho=Ys,as=d.forwardRef(({className:o,...t},s)=>e.jsx(Jt,{ref:s,className:$("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",o),...t}));as.displayName=Jt.displayName;const mt=d.forwardRef(({className:o,children:t,...s},a)=>e.jsxs(ho,{children:[e.jsx(as,{}),e.jsxs(Yt,{ref:a,className:$("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",o),...s,children:[t,e.jsxs(Xs,{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:[e.jsx($e,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));mt.displayName=Yt.displayName;const is=({className:o,...t})=>e.jsx("div",{className:$("flex flex-col space-y-1.5 text-center sm:text-left",o),...t});is.displayName="DialogHeader";const ls=({className:o,...t})=>e.jsx("div",{className:$("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",o),...t});ls.displayName="DialogFooter";const cs=d.forwardRef(({className:o,...t},s)=>e.jsx(Xt,{ref:s,className:$("text-lg font-semibold leading-none tracking-tight",o),...t}));cs.displayName=Xt.displayName;const ds=d.forwardRef(({className:o,...t},s)=>e.jsx(Zt,{ref:s,className:$("text-sm text-muted-foreground",o),...t}));ds.displayName=Zt.displayName;function fo(o){return/edit|write|create|patch/i.test(o)?tn:/bash|shell|exec|run|command/i.test(o)?De:/fetch|http|web|curl|request/i.test(o)?Ie:He}function go({toolName:o,input:t}){const s=os(o,t);if(s)return e.jsx("div",{className:"rounded-lg overflow-hidden border",children:e.jsx(ns,{oldText:s.oldText,newText:s.newText,caption:s.caption})});if(typeof t=="object"&&t!==null){const a=t,n=a.command??a.cmd??a.script;if(typeof n=="string"&&n.trim().length>0)return e.jsxs("div",{className:"rounded-lg border bg-background/40 overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b bg-muted/40 flex items-center gap-1.5",children:[e.jsx(De,{className:"h-3 w-3"}),e.jsx("span",{children:"Command"})]}),e.jsxs("pre",{className:"px-3 py-2 text-xs font-mono whitespace-pre-wrap break-all max-h-40 overflow-auto",children:["$",n]})]});const r=a.url;if(typeof r=="string"){const i=a.method??"GET";return e.jsxs("div",{className:"rounded-lg border bg-background/40 px-3 py-2 text-xs font-mono",children:[e.jsx("span",{className:"text-muted-foreground",children:i.toUpperCase()})," ",e.jsx("span",{className:"break-all",children:r})]})}}return e.jsxs("div",{className:"p-3 rounded-lg bg-muted/50 border text-xs font-mono",children:[e.jsx("div",{className:"text-muted-foreground mb-2",children:"Input:"}),e.jsx("pre",{className:"whitespace-pre-wrap break-all max-h-60 overflow-auto",children:JSON.stringify(t,null,2)})]})}function bo(){const{showConfirmDialog:o,confirmInfo:t,hideConfirm:s}=I(),{sendConfirm:a}=ge(),n=c=>{t&&a(t.id,c),s()};if(d.useEffect(()=>{if(!o)return;const c=l=>{var p;const u=l.target,x=(p=u==null?void 0:u.tagName)==null?void 0:p.toLowerCase();x==="input"||x==="textarea"||(l.key==="y"||l.key==="Y"?(l.preventDefault(),n("yes")):l.key==="n"||l.key==="N"||l.key==="Escape"?(l.preventDefault(),n("no")):(l.key==="a"||l.key==="A")&&(l.preventDefault(),n("always")))};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[o,t==null?void 0:t.id]),!t)return e.jsx(At,{open:o,onOpenChange:()=>s(),children:e.jsx(mt,{})});const r=fo(t.toolName),i=/edit|write/i.test(t.toolName);return e.jsx(At,{open:o,onOpenChange:()=>s(),children:e.jsxs(mt,{className:"sm:max-w-2xl",children:[e.jsxs(is,{children:[e.jsxs(cs,{className:"flex items-center gap-2",children:[e.jsx(en,{className:"h-5 w-5 text-yellow-500"}),"Confirm: ",t.toolName]}),e.jsxs(ds,{children:["The agent wants to ",i?"modify a file":"run this tool",". Review the request below and decide whether to proceed."]})]}),e.jsxs("div",{className:"py-2 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-muted",children:[e.jsx(r,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium font-mono truncate",children:t.toolName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[i?"File modification":"Tool execution"," — preview below"]})]})]}),t.input!==void 0&&e.jsx(go,{toolName:t.toolName,input:t.input}),t.suggestedPattern&&e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/20",children:[e.jsx(xt,{className:"h-4 w-4 text-yellow-600 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-sm min-w-0",children:[e.jsx("div",{className:"font-medium text-yellow-800 dark:text-yellow-200",children:"Trust pattern suggestion"}),e.jsx("div",{className:"font-mono text-xs mt-1 break-all",children:t.suggestedPattern}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Picking ",e.jsx("span",{className:"font-medium",children:"Always"})," will whitelist matching calls for this project."]})]})]})]}),e.jsxs(ls,{className:"gap-2 sm:gap-2 flex-wrap",children:[e.jsx(q,{variant:"outline",size:"sm",onClick:()=>n("deny"),title:"Reject this and all future calls matching the pattern",children:"Deny always"}),e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>n("no"),title:"Reject this single call (Esc / n)",children:["No ",e.jsx("kbd",{className:"ml-1 text-[10px] border rounded px-1 bg-background",children:"n"})]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>n("always"),title:"Approve and remember the pattern for the project (a)",children:["Always ",e.jsx("kbd",{className:"ml-1 text-[10px] border rounded px-1 bg-background",children:"a"})]}),e.jsxs(q,{size:"sm",onClick:()=>n("yes"),title:"Approve this single call (y)",children:["Yes ",e.jsx("kbd",{className:"ml-1 text-[10px] border rounded px-1 bg-background/80",children:"y"})]})]})]})})}function yo(){const o=Q(x=>x.wsStatus),t=Q(x=>x.wsUrl),[s,a]=d.useState(!1),[n,r]=d.useState(Date.now());if(d.useEffect(()=>{if(o.state!=="reconnecting")return;const x=setInterval(()=>r(Date.now()),500);return()=>clearInterval(x)},[o.state]),d.useEffect(()=>{o.state==="open"&&a(!1)},[o.state]),o.state==="open"||o.state==="connecting"||s)return null;const i=()=>xe(t).retryNow(),c=o.state==="reconnecting",l=o.state==="closed"?o.error:o.state==="reconnecting"?o.lastError:void 0,u=c?Math.max(0,Math.ceil((o.nextRetryAt-n)/1e3)):0;return e.jsxs("div",{className:$("flex items-center gap-3 px-4 py-2 border-b text-sm",c?"bg-orange-500/10 text-orange-700 dark:text-orange-300 border-orange-500/30":"bg-red-500/10 text-red-700 dark:text-red-300 border-red-500/30"),children:[c?e.jsx(we,{className:"h-4 w-4 animate-spin shrink-0"}):e.jsx(yt,{className:"h-4 w-4 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium",children:c?`Reconnecting to backend (attempt ${o.attempt}) — retrying in ${u}s`:"Disconnected from backend"}),l&&e.jsx("div",{className:"text-xs opacity-80 truncate",children:l})]}),e.jsxs("button",{type:"button",onClick:i,className:$("inline-flex items-center gap-1 px-2.5 py-1 rounded-md border text-xs font-medium","hover:bg-background/30 transition-colors shrink-0",c?"border-orange-500/40":"border-red-500/40"),title:"Retry connection now",children:[e.jsx(Fe,{className:"h-3 w-3"}),"Retry now"]}),e.jsx("button",{type:"button",onClick:()=>a(!0),className:"text-current/60 hover:text-current shrink-0",title:"Dismiss (chip in topbar still shows status)",children:e.jsx($e,{className:"h-4 w-4"})})]})}class vo extends d.Component{constructor(){super(...arguments);ce(this,"state",{error:null});ce(this,"handleReset",()=>{this.setState({error:null})})}static getDerivedStateFromError(s){return{error:s}}componentDidCatch(s,a){var n,r;console.error("[ErrorBoundary]",s,a.componentStack),(r=(n=this.props).onError)==null||r.call(n,s,a)}render(){return this.state.error?e.jsx("div",{className:"flex items-center justify-center h-screen bg-background",children:e.jsxs("div",{className:"flex flex-col items-center gap-4 p-8 max-w-md text-center",children:[e.jsx(xt,{className:"h-12 w-12 text-destructive"}),e.jsx("h1",{className:"text-lg font-semibold",children:"Something went wrong"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"A rendering error occurred. Your session is still active on the server — reloading will pick up where you left off."}),e.jsx("pre",{className:"text-xs font-mono text-muted-foreground bg-muted/50 rounded p-3 max-h-32 overflow-auto w-full text-left",children:this.state.error.message}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(q,{size:"sm",variant:"outline",onClick:()=>window.location.reload(),children:[e.jsx(Nt,{className:"h-4 w-4 mr-1"}),"Reload page"]}),e.jsx(q,{size:"sm",onClick:this.handleReset,children:"Try again"})]})]})}):this.props.children}}function wo(){const o=I(g=>g.modelSwitcherOpen),t=I(g=>g.setModelSwitcherOpen),[s,a]=d.useState(""),[n,r]=d.useState(0),[i,c]=d.useState([]),[l,u]=d.useState({}),x=d.useRef(null),p=Q(g=>g.wsUrl),m=Q(g=>g.provider),f=Q(g=>g.model),b=I(g=>g.paletteOpen),w=ge();d.useEffect(()=>{const g=R=>{if((R.ctrlKey||R.metaKey)&&R.key.toLowerCase()==="m"&&!R.shiftKey&&!R.altKey){if(b)return;R.preventDefault(),t(!o);return}R.key==="Escape"&&o&&(R.preventDefault(),t(!1))};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[o,b]),d.useEffect(()=>{const g=xe(p),R=g.on("providers.saved",K=>{const U=K.payload;c(U.providers??[])}),ee=g.on("provider.models",K=>{const U=K.payload;u(G=>({...G,[U.provider]:U.models}))});return()=>{R(),ee()}},[p]),d.useEffect(()=>{o&&(a(""),r(0),w.listSavedProviders(),requestAnimationFrame(()=>{var g;return(g=x.current)==null?void 0:g.focus()}))},[o,w]),d.useEffect(()=>{if(o)for(const g of i)l[g.id]||w.listProviderModels(g.id)},[o,i,l,w]);const S=d.useMemo(()=>{const g=[];for(const K of i){const U=l[K.id]??[];for(const G of U)g.push({provider:K.id,model:G.id,modelName:G.name||G.id,contextWindow:G.contextWindow,isCurrent:K.id===m&&G.id===f})}const R=s.toLowerCase().trim();return(R?g.filter(K=>K.provider.toLowerCase().includes(R)||K.model.toLowerCase().includes(R)||K.modelName.toLowerCase().includes(R)):g).sort((K,U)=>K.isCurrent!==U.isCurrent?K.isCurrent?-1:1:K.provider.localeCompare(U.provider)||K.model.localeCompare(U.model))},[i,l,s,m,f]);d.useEffect(()=>{n>=S.length&&r(0)},[S.length,n]);const y=g=>{const R=S[g];R&&(w.switchModel(R.provider,R.model),t(!1))};return o?e.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-background/60 backdrop-blur-sm pt-[15vh]",onClick:g=>{g.target===g.currentTarget&&t(!1)},onKeyDown:g=>{g.key==="Escape"&&t(!1)},children:e.jsxs("div",{className:"w-full max-w-xl rounded-xl border bg-popover shadow-2xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b px-3 py-2",children:[e.jsx(Ee,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("input",{ref:x,value:s,onChange:g=>{a(g.target.value),r(0)},onKeyDown:g=>{g.key==="ArrowDown"?(g.preventDefault(),r(R=>Math.min(S.length-1,R+1))):g.key==="ArrowUp"?(g.preventDefault(),r(R=>Math.max(0,R-1))):g.key==="Enter"?(g.preventDefault(),y(n)):g.key==="Escape"&&(g.preventDefault(),t(!1))},placeholder:"Filter providers and models…",className:"flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground"}),e.jsx("span",{className:"text-[10px] text-muted-foreground font-mono",children:"↑↓ · Enter · Esc"})]}),e.jsx("div",{className:"max-h-[50vh] overflow-y-auto py-1",children:S.length===0?e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:i.length===0?"No saved providers — register a key in Settings first.":"Loading models…"}):S.map((g,R)=>e.jsxs("button",{type:"button",onClick:()=>y(R),onMouseEnter:()=>r(R),className:$("w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors",R===n?"bg-accent text-accent-foreground":"hover:bg-accent/40",g.isCurrent&&"font-medium"),children:[e.jsx(Pe,{className:$("h-4 w-4 shrink-0",g.isCurrent?"text-primary":"text-muted-foreground")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"truncate",children:[e.jsx("span",{className:"text-muted-foreground",children:g.provider}),e.jsx("span",{className:"mx-1 text-muted-foreground/40",children:"·"}),e.jsx("span",{children:g.modelName})]}),g.contextWindow&&e.jsxs("div",{className:"text-[10px] text-muted-foreground font-mono",children:[g.model," · ctx ",g.contextWindow.toLocaleString()]})]}),g.isCurrent?e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-primary font-semibold",children:"active"}):e.jsx(Bt,{className:"h-3.5 w-3.5 text-muted-foreground opacity-0 group-hover:opacity-100"})]},`${g.provider}:${g.model}`))})]})}):null}const us=d.createContext(void 0);function jo({children:o,defaultTheme:t="system",storageKey:s="wrongstack-theme"}){const{theme:a,setTheme:n}=Q(),[r,i]=d.useState(()=>typeof window<"u"&&localStorage.getItem(s)||t);d.useEffect(()=>{const l=window.document.documentElement;if(l.classList.remove("light","dark"),r==="system"){const u=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";l.classList.add(u)}else l.classList.add(r)},[r]);const c={theme:r,setTheme:l=>{localStorage.setItem(s,l),i(l),n(l)}};return e.jsx(us.Provider,{value:c,children:o})}function ms(){const o=d.useContext(us);if(o===void 0)throw new Error("useTheme must be used within a ThemeProvider");return o}const ye=d.forwardRef(({className:o,type:t,...s},a)=>e.jsx("input",{type:t,className:$("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium 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",o),ref:a,...s}));ye.displayName="Input";const ps=sn,Ct=d.forwardRef(({className:o,...t},s)=>e.jsx(es,{ref:s,className:$("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",o),...t}));Ct.displayName=es.displayName;const ke=d.forwardRef(({className:o,...t},s)=>e.jsx(ts,{ref:s,className:$("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all 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=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",o),...t}));ke.displayName=ts.displayName;const Se=d.forwardRef(({className:o,...t},s)=>e.jsx(ss,{ref:s,className:$("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",o),...t}));Se.displayName=ss.displayName;function No(){var Ke;const{setCurrentView:o}=I(),{provider:t,model:s,setProvider:a,setModel:n,wsConnected:r}=Q(),{theme:i,setTheme:c}=ms(),l=ge(),u=l.client,x=l.listProviders,p=l.listSavedProviders,[m,f]=d.useState([]),[b,w]=d.useState({}),[S,y]=d.useState([]),[g,R]=d.useState(!1),[ee,K]=d.useState(!1),[U,G]=d.useState(!1),[z,Y]=d.useState(null),[te,re]=d.useState("catalog"),[X,B]=d.useState(null),[A,_]=d.useState(""),[N,Z]=d.useState(""),[P,se]=d.useState(!1),[ue,v]=d.useState(!1),[C,L]=d.useState(""),[h,M]=d.useState("openai-compatible"),[E,j]=d.useState(""),[W,ae]=d.useState(""),J=m.find(k=>k.id===t);d.useEffect(()=>{const k=fe=>{if(fe.type==="provider.catalog"){const je=fe.payload;f(je.providers.sort((Me,Ze)=>Me.id.localeCompare(Ze.id))),R(!1)}},F=fe=>{if(fe.type==="provider.models"){const je=fe.payload;w(Me=>({...Me,[je.provider]:je.models})),K(!1)}},le=fe=>{if(fe.type==="providers.saved"){const Me=fe.payload.providers.sort((Ze,hs)=>Ze.id.localeCompare(hs.id));y(Me),G(!1),Me.length>0&&re("saved")}},xs=fe=>{if(fe.type==="key.operation_result"){const je=fe.payload;Y(je),setTimeout(()=>Y(null),3e3),p==null||p()}};if(!r||!u)return;const Ge=u.on("provider.catalog",k),Je=u.on("provider.models",F),Ye=u.on("providers.saved",le),Xe=u.on("key.operation_result",xs);return R(!0),G(!0),x==null||x(),p==null||p(),()=>{Ge==null||Ge(),Je==null||Je(),Ye==null||Ye(),Xe==null||Xe()}},[r,u,x,p]);const me=d.useCallback(k=>{var F;a(k),b[k]||(K(!0),(F=l.listProviderModels)==null||F.call(l,k))},[b,a,l]),de=d.useCallback(k=>{var F;n(k),(F=l.switchModel)==null||F.call(l,t,k),Y({success:!0,message:`Switching to ${t} / ${k}…`})},[n,l,t]),ne=d.useCallback(k=>{var F;!A.trim()||!N.trim()||((F=l.addKey)==null||F.call(l,k,A.trim(),N.trim()),_(""),Z(""),B(null))},[l,A,N]),D=d.useCallback((k,F)=>{var le;(le=l.deleteKey)==null||le.call(l,k,F)},[l]),O=d.useCallback((k,F)=>{var le;(le=l.setActiveKey)==null||le.call(l,k,F)},[l]),V=d.useCallback(()=>{var k;C.trim()&&((k=l.addProvider)==null||k.call(l,C.trim(),h,E||void 0,W||void 0),L(""),M("openai-compatible"),j(""),ae(""),v(!1))},[l,C,h,E,W]),ie=d.useCallback(k=>{var F;(F=l.removeProvider)==null||F.call(l,k)},[l]),[pe,oe]=d.useState(""),he=["anthropic","openai","google","openai-compatible"],Te=pe.trim()?m.filter(k=>{const F=pe.trim().toLowerCase();return k.id.toLowerCase().includes(F)||k.name.toLowerCase().includes(F)||k.family.toLowerCase().includes(F)}):m,Qe=Te.reduce((k,F)=>(k[F.family]||(k[F.family]=[]),k[F.family].push(F),k),{});return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("header",{className:"flex items-center justify-between px-4 py-3 border-b bg-card shrink-0",children:[e.jsx("h1",{className:"text-lg font-semibold",children:"Settings"}),e.jsx(q,{variant:"ghost",size:"icon",onClick:()=>o("chat"),children:e.jsx($e,{className:"h-4 w-4"})})]}),e.jsx(Ve,{className:"flex-1",children:e.jsx("div",{className:"p-6 max-w-2xl mx-auto",children:e.jsxs(ps,{defaultValue:"provider",children:[e.jsxs(Ct,{className:"w-full justify-start mb-6 grid grid-cols-4",children:[e.jsxs(ke,{value:"provider",className:"gap-2",children:[e.jsx(nn,{className:"h-4 w-4"}),"Provider"]}),e.jsxs(ke,{value:"model",className:"gap-2",children:[e.jsx(Pe,{className:"h-4 w-4"}),"Model"]}),e.jsxs(ke,{value:"connection",className:"gap-2",children:[e.jsx(Ie,{className:"h-4 w-4"}),"Connection"]}),e.jsxs(ke,{value:"appearance",className:"gap-2",children:[e.jsx(on,{className:"h-4 w-4"}),"Appearance"]})]}),e.jsxs(Se,{value:"provider",className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsxs(q,{variant:te==="catalog"?"default":"outline",size:"sm",onClick:()=>re("catalog"),children:[e.jsx(Ie,{className:"h-4 w-4 mr-1"}),"Catalog"]}),e.jsxs(q,{variant:te==="saved"?"default":"outline",size:"sm",onClick:()=>re("saved"),children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),"Saved (",S.length,")"]})]}),z&&e.jsxs("div",{className:$("p-3 rounded-lg mb-4 flex items-center gap-2",z.success?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"),children:[z.success?e.jsx(Ce,{className:"h-4 w-4"}):e.jsx(rn,{className:"h-4 w-4"}),z.message]}),te==="catalog"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(ye,{placeholder:`Search ${m.length} providers (name / id / family)…`,value:pe,onChange:k=>oe(k.target.value),className:"text-sm"}),g&&m.length===0?e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx(we,{className:"h-6 w-6 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-2 text-muted-foreground",children:"Loading catalog..."})]}):Te.length===0&&pe?e.jsxs("div",{className:"text-center py-8 text-muted-foreground text-sm",children:['No providers match "',e.jsx("span",{className:"font-mono",children:pe}),'".']}):e.jsx(e.Fragment,{children:he.map(k=>{const F=Qe[k];return F!=null&&F.length?e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wider",children:k}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:F.map(le=>e.jsxs("button",{type:"button",onClick:()=>me(le.id),className:$("flex flex-col items-start p-3 rounded-lg border text-left transition-all",t===le.id?"border-primary bg-primary/5 ring-2 ring-primary/20":"border-border hover:bg-muted"),children:[e.jsxs("div",{className:"flex w-full justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:le.name}),e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",le.id,")"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[le.hasApiKey&&e.jsxs("span",{className:"text-xs bg-green-500/10 text-green-600 px-2 py-0.5 rounded",children:[e.jsx(et,{className:"h-3 w-3 inline mr-1"}),"Configured"]}),le.envVars[0]&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["ENV: ",le.envVars[0]]}),t===le.id&&e.jsx(Ce,{className:"h-4 w-4 text-primary"})]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:[le.modelCount," models",le.apiBase&&` · ${le.apiBase}`]})]},le.id))})]},k):null})})]}),te==="saved"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage your API keys and provider configurations"}),e.jsxs(q,{size:"sm",variant:"outline",onClick:()=>v(!ue),children:[e.jsx($t,{className:"h-4 w-4 mr-1"}),"Add Provider"]})]}),ue&&e.jsxs("div",{className:"p-4 border rounded-lg space-y-3 bg-muted/50",children:[e.jsx("h4",{className:"font-medium",children:"Add Custom Provider"}),e.jsx(ye,{placeholder:"Provider ID (e.g. my-llm-server)",value:C,onChange:k=>L(k.target.value)}),e.jsxs("select",{className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:h,onChange:k=>M(k.target.value),children:[e.jsx("option",{value:"anthropic",children:"Anthropic"}),e.jsx("option",{value:"openai",children:"OpenAI"}),e.jsx("option",{value:"openai-compatible",children:"OpenAI Compatible"}),e.jsx("option",{value:"google",children:"Google"})]}),e.jsx(ye,{placeholder:"Base URL (optional, e.g. http://localhost:11434/v1)",value:E,onChange:k=>j(k.target.value)}),e.jsx(ye,{type:"password",placeholder:"API Key (optional)",value:W,onChange:k=>ae(k.target.value)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(q,{size:"sm",onClick:V,disabled:!C.trim(),children:"Add"}),e.jsx(q,{size:"sm",variant:"ghost",onClick:()=>v(!1),children:"Cancel"})]})]}),U?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(we,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):S.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(et,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"No saved providers yet"}),e.jsx("p",{className:"text-sm",children:"Add a provider to get started"})]}):S.map(k=>e.jsxs("div",{className:"border rounded-lg p-4 space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium",children:k.id}),k.family&&e.jsx("span",{className:"text-xs text-muted-foreground",children:k.family})]}),e.jsx("div",{className:"flex gap-2",children:e.jsx(q,{size:"icon",variant:"ghost",onClick:()=>ie(k.id),children:e.jsx(Oe,{className:"h-4 w-4 text-destructive"})})})]}),k.baseUrl&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsx(Ie,{className:"h-3 w-3 inline mr-1"}),k.baseUrl]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm font-medium",children:"API Keys"}),e.jsxs(q,{size:"sm",variant:"ghost",onClick:()=>B(X===k.id?null:k.id),children:[e.jsx($t,{className:"h-3 w-3 mr-1"}),"Add Key"]})]}),k.apiKeys.length===0&&!X&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No keys configured"}),k.apiKeys.map(F=>e.jsxs("div",{className:"flex items-center justify-between p-2 bg-muted/50 rounded",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:F.label}),F.isActive&&e.jsx("span",{className:"ml-2 text-xs bg-green-500/10 text-green-600 px-1.5 py-0.5 rounded",children:"Active"}),e.jsx("div",{className:"text-xs text-muted-foreground font-mono",children:F.maskedKey})]}),e.jsxs("div",{className:"flex gap-1",children:[!F.isActive&&e.jsx(q,{size:"sm",variant:"ghost",onClick:()=>O(k.id,F.label),children:"Set Active"}),e.jsx(q,{size:"icon",variant:"ghost",onClick:()=>D(k.id,F.label),children:e.jsx(Oe,{className:"h-3 w-3 text-destructive"})})]})]},F.label)),X===k.id&&e.jsxs("div",{className:"p-3 border rounded space-y-2 bg-background",children:[e.jsx(ye,{placeholder:"Key label (e.g. default, production)",value:A,onChange:F=>_(F.target.value)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ye,{type:P?"text":"password",placeholder:"API key",value:N,onChange:F=>Z(F.target.value)}),e.jsx(q,{size:"icon",variant:"ghost",onClick:()=>se(!P),children:P?e.jsx(an,{className:"h-4 w-4"}):e.jsx(ln,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(q,{size:"sm",onClick:()=>ne(k.id),disabled:!A.trim()||!N.trim(),children:"Save Key"}),e.jsx(q,{size:"sm",variant:"ghost",onClick:()=>{B(null),_(""),Z("")},children:"Cancel"})]})]})]})]},k.id))]})]}),e.jsx(Se,{value:"model",className:"space-y-4",children:t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:(J==null?void 0:J.name)||t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]}),e.jsx(q,{variant:"ghost",size:"sm",onClick:()=>{var k;K(!0),(k=l.listProviderModels)==null||k.call(l,t)},children:e.jsx(Nt,{className:$("h-4 w-4",ee&&"animate-spin")})})]}),ee&&!b[t]?e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx(we,{className:"h-6 w-6 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-2 text-muted-foreground",children:"Loading models..."})]}):e.jsxs("div",{className:"space-y-1",children:[(b[t]||[]).map(k=>e.jsxs("button",{type:"button",onClick:()=>de(k.id),className:$("w-full flex items-center justify-between p-3 rounded-lg border text-left transition-all",s===k.id?"border-primary bg-primary/5 ring-2 ring-primary/20":"border-border hover:bg-muted"),children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:k.name||k.id}),e.jsx("div",{className:"flex gap-2 mt-1",children:k.capabilities.map(F=>e.jsx("span",{className:"text-xs bg-muted px-1.5 py-0.5 rounded",children:F},F))})]}),e.jsxs("div",{className:"text-right text-xs text-muted-foreground",children:[k.contextWindow&&e.jsxs("div",{children:[k.contextWindow/1e3,"k context"]}),k.inputCost&&k.outputCost&&e.jsxs("div",{children:["$",k.inputCost,"/$",k.outputCost]}),s===k.id&&e.jsx(Ce,{className:"h-4 w-4 text-primary mt-1"})]})]},k.id)),((Ke=b[t])==null?void 0:Ke.length)===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No models found for this provider. The catalog might be empty or still loading."})]})]}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Pe,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"Select a provider first"})]})}),e.jsxs(Se,{value:"connection",className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{htmlFor:"websocket-url",className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Ie,{className:"h-4 w-4 text-muted-foreground"}),"WebSocket Server URL"]}),e.jsx(ye,{id:"websocket-url",value:Q.getState().wsUrl,onChange:k=>Q.getState().setConfig({wsUrl:k.target.value}),placeholder:"ws://localhost:3457",className:"font-mono text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"URL of the WrongStack WebSocket server. The server runs alongside the CLI."})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/50",children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"Starting the WebSocket Server"}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-3",children:["Standalone: run ",e.jsx("code",{className:"bg-muted px-1 py-0.5 rounded",children:"./dev.ps1"})," ","from the repo root, or set WS_HOST/WS_PORT before launching"," ",e.jsx("code",{className:"bg-muted px-1 py-0.5 rounded",children:"node packages/webui/dist/server/entry.js"}),". Or alongside the CLI:"," ",e.jsx("code",{className:"bg-muted px-1 py-0.5 rounded",children:"wstack --webui"}),"."]})]})]}),e.jsxs(Se,{value:"appearance",className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold mb-3",children:"Theme"}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 max-w-md",children:[e.jsxs(q,{variant:i==="light"?"default":"outline",size:"sm",onClick:()=>c("light"),children:[e.jsx(ft,{className:"h-4 w-4 mr-1"}),"Light"]}),e.jsxs(q,{variant:i==="dark"?"default":"outline",size:"sm",onClick:()=>c("dark"),children:[e.jsx(gt,{className:"h-4 w-4 mr-1"}),"Dark"]}),e.jsxs(q,{variant:i==="system"?"default":"outline",size:"sm",onClick:()=>c("system"),children:[e.jsx(bt,{className:"h-4 w-4 mr-1"}),"System"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"System follows your OS-level light/dark preference."})]}),e.jsxs("div",{className:"pt-2 border-t",children:[e.jsx("h3",{className:"text-sm font-semibold mb-3 mt-3",children:"Preferences"}),e.jsx(It,{label:"Compact density",hint:"Tighter spacing throughout the chat. Toggle anywhere with Ctrl+Shift+D.",selector:k=>k.compactMode,onChange:()=>I.getState().toggleCompactMode()}),e.jsx(It,{label:"Sound on completion",hint:"Play a soft chime when a run finishes — useful when working in another tab.",selector:null,configKey:"soundOnComplete"})]})]})]})})})]})}function It({label:o,hint:t,selector:s,onChange:a,configKey:n}){const r=I(u=>s?s(u):!1),i=Q(u=>n?u[n]:!1),c=s?r:i,l=()=>{if(s)a==null||a();else if(n==="soundOnComplete"){const u=!Q.getState().soundOnComplete;Q.getState().setSoundOnComplete(u),u&&kt()}};return e.jsxs("div",{className:"flex items-start justify-between gap-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium",children:o}),t&&e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:t})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":c,onClick:l,className:$("shrink-0 relative inline-flex h-5 w-9 rounded-full border transition-colors",c?"bg-primary border-primary":"bg-muted border-input hover:bg-muted/80"),children:e.jsx("span",{className:$("absolute top-0.5 left-0.5 h-3.5 w-3.5 rounded-full bg-background shadow transition-transform",c&&"translate-x-4")})})]})}const ko=[{section:"Global",items:[{keys:["Ctrl","K"],description:"Open command palette"},{keys:["?"],description:"Show this shortcuts overlay"},{keys:["Ctrl","\\"],description:"Toggle sidebar"},{keys:["Ctrl","/"],description:"Focus the message input"}]},{section:"Chat input",items:[{keys:["Enter"],description:"Send message"},{keys:["Shift","Enter"],description:"Insert a newline"},{keys:["↑"],description:"Recall previous prompt (in empty input)"},{keys:["↓"],description:"Recall next prompt"},{keys:["/"],description:"Open slash command popup"},{keys:["Tab"],description:"Autocomplete highlighted command"},{keys:["Esc"],description:"Dismiss popup / clear input"}]},{section:"Chat",items:[{keys:["Ctrl","F"],description:"Search within current chat"},{keys:["Ctrl","L"],description:"Clear context (same as /clear)"},{keys:["Ctrl","N"],description:"Start a new session (same as /new)"},{keys:["Ctrl","E"],description:"Export chat as markdown"},{keys:["Ctrl","M"],description:"Quick model switcher overlay"},{keys:["Ctrl","Shift","D"],description:"Toggle compact UI density"},{keys:["Esc"],description:"Abort the current run (when running)"}]},{section:"Chat navigation (when not typing)",items:[{keys:["j"],description:"Focus next message (alias: ↓)"},{keys:["k"],description:"Focus previous message (alias: ↑)"},{keys:["g"],description:"Jump to first message"},{keys:["Shift","G"],description:"Jump to last message"},{keys:["c"],description:"Copy focused message text"},{keys:["Esc"],description:"Clear focused message"}]}];function So(){const o=I(s=>s.shortcutsOpen),t=I(s=>s.setShortcutsOpen);return d.useEffect(()=>{const s=a=>{var c;const n=a.target,r=(c=n==null?void 0:n.tagName)==null?void 0:c.toLowerCase();if(!(r==="input"||r==="textarea"||(n==null?void 0:n.isContentEditable))&&a.key==="?"&&!a.ctrlKey&&!a.metaKey&&!a.altKey){a.preventDefault(),t(!I.getState().shortcutsOpen);return}a.key==="Escape"&&I.getState().shortcutsOpen&&(a.preventDefault(),t(!1))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[t]),o?e.jsx("div",{className:"fixed inset-0 z-50 bg-background/60 backdrop-blur-sm flex items-center justify-center px-4",onClick:()=>t(!1),onKeyDown:s=>{s.key==="Escape"&&t(!1)},children:e.jsxs("div",{onClick:s=>s.stopPropagation(),onKeyDown:s=>s.stopPropagation(),className:"w-full max-w-2xl rounded-xl border bg-popover shadow-2xl overflow-hidden flex flex-col max-h-[80vh]",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Vt,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h2",{className:"text-sm font-semibold",children:"Keyboard shortcuts"})]}),e.jsx("button",{type:"button",onClick:()=>t(!1),className:"text-muted-foreground hover:text-foreground p-1 rounded hover:bg-muted",children:e.jsx($e,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"overflow-y-auto px-5 py-4 space-y-6",children:ko.map(s=>e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground mb-2",children:s.section}),e.jsx("div",{className:"grid grid-cols-1 gap-1.5",children:s.items.map(a=>e.jsxs("div",{className:"flex items-center justify-between gap-3 text-sm px-2 py-1.5 rounded hover:bg-muted/40",children:[e.jsx("span",{className:"text-foreground/80",children:a.description}),e.jsx("span",{className:"flex items-center gap-1 shrink-0",children:a.keys.map((n,r)=>e.jsxs("span",{className:"flex items-center gap-1",children:[r>0&&e.jsx("span",{className:"text-muted-foreground/40 text-xs",children:"+"}),e.jsx("kbd",{className:"font-mono text-[10px] border rounded px-1.5 py-0.5 bg-background",children:n})]},n))})]},a.description))})]},s.section))}),e.jsxs("div",{className:"border-t px-5 py-3 text-xs text-muted-foreground",children:["Press"," ",e.jsx("kbd",{className:"font-mono text-[10px] border rounded px-1 py-0.5 bg-background",children:"?"})," ","any time to reopen this list."]})]})}):null}function Co(){const{toggleSidebar:o,currentView:t,setCurrentView:s}=I(),a=I(h=>h.sidebarWidth),n=I(h=>h.setSidebarWidth),{totalTokens:r,cost:i,session:c,todos:l}=H(),{messages:u,clearMessages:x}=T(),p=I(h=>h.pinnedIds),m=I(h=>h.unpinAll),[f,b]=d.useState(""),w=I(h=>h.favoriteSessionIds),S=I(h=>h.toggleFavoriteSession),y=I(h=>h.sessionNicknames),g=I(h=>h.setSessionNickname),[R,ee]=d.useState(null),[K,U]=d.useState(""),G=p.map(h=>u.find(M=>M.id===h)).filter(h=>!!h&&h.content.length>0),{wsConnected:z,wsUrl:Y,provider:te,model:re}=Q(),{entries:X,loading:B,error:A}=Le(),{listSessions:_,deleteSession:N,resumeSession:Z,client:P}=ge();d.useEffect(()=>{var h;z&&((h=P==null?void 0:P.getTodos)==null||h.call(P))},[z,P]);const se=c==null?void 0:c.id;d.useEffect(()=>{t==="history"&&z&&_(50)},[t,z,se,_]);const ue=h=>{if(!h)return"--";const M=Math.floor((Date.now()-h)/1e3);return M<60?`${M}s`:`${Math.floor(M/60)}m`},v=h=>{const M=Date.parse(h);if(Number.isNaN(M))return"";const E=Date.now()-M;if(E<6e4)return"just now";if(E<36e5)return`${Math.floor(E/6e4)}m ago`;if(E<864e5)return`${Math.floor(E/36e5)}h ago`;const j=Math.floor(E/864e5);return j<7?`${j}d ago`:new Date(M).toLocaleDateString()},C=(()=>{const h=f.trim().toLowerCase(),M=h?X.filter(oe=>oe.title.toLowerCase().includes(h)||oe.model.toLowerCase().includes(h)||oe.provider.toLowerCase().includes(h)||oe.id.toLowerCase().includes(h)):X,E=new Date;E.setHours(0,0,0,0);const j=E.getTime(),W=j-864e5,ae=j-6*864e5,J={today:[],yesterday:[],week:[],older:[]};for(const oe of M){const he=Date.parse(oe.startedAt);if(Number.isNaN(he)){J.older.push(oe);continue}he>=j?J.today.push(oe):he>=W?J.yesterday.push(oe):he>=ae?J.week.push(oe):J.older.push(oe)}const me=new Set(w),de=M.filter(oe=>me.has(oe.id)),ne=[];de.length&&ne.push({label:"Favorites",rows:de,star:!0});const D=oe=>oe.filter(he=>!me.has(he.id)),O=D(J.today),V=D(J.yesterday),ie=D(J.week),pe=D(J.older);return O.length&&ne.push({label:"Today",rows:O}),V.length&&ne.push({label:"Yesterday",rows:V}),ie.length&&ne.push({label:"This week",rows:ie}),pe.length&&ne.push({label:"Earlier",rows:pe}),ne})(),L=h=>{h.preventDefault();const M=h.clientX,E=a,j=ae=>{n(E+(ae.clientX-M))},W=()=>{window.removeEventListener("mousemove",j),window.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};window.addEventListener("mousemove",j),window.addEventListener("mouseup",W),document.body.style.cursor="col-resize",document.body.style.userSelect="none"};return e.jsxs("aside",{style:{width:`${a}px`},className:"relative border-r bg-card flex flex-col shrink-0",children:[e.jsxs("div",{onMouseDown:L,onDoubleClick:()=>n(288),className:"group/handle absolute top-0 right-0 h-full w-2 cursor-col-resize z-10 flex items-center justify-end",title:"Drag to resize · double-click to reset",children:[e.jsx("div",{className:"h-full w-px bg-border group-hover/handle:bg-primary/60 group-hover/handle:w-0.5 transition-all"}),e.jsxs("div",{className:"absolute right-0 top-1/2 -translate-y-1/2 flex flex-col gap-0.5 opacity-0 group-hover/handle:opacity-100 transition-opacity pr-0.5",children:[e.jsx("span",{className:"h-1 w-1 rounded-full bg-primary/70"}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-primary/70"}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-primary/70"})]})]}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-primary flex items-center justify-center",children:e.jsx(jt,{className:"h-4 w-4 text-primary-foreground"})}),e.jsx("span",{className:"text-sm font-semibold tracking-tight",children:"WrongStack"})]}),e.jsx(q,{variant:"ghost",size:"icon",onClick:o,children:e.jsx(cn,{className:"h-4 w-4"})})]}),e.jsxs(ps,{value:t==="settings"?"chat":t,onValueChange:h=>s(h),className:"flex-1 flex flex-col",children:[e.jsxs(Ct,{className:"w-full rounded-none bg-transparent p-2 h-auto grid grid-cols-2",children:[e.jsxs(ke,{value:"chat",className:"flex-col gap-1.5 py-2 data-[state=active]:bg-primary/10",children:[e.jsx(dn,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Chat"})]}),e.jsxs(ke,{value:"history",className:"flex-col gap-1.5 py-2 data-[state=active]:bg-primary/10",children:[e.jsx(lt,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"History"})]})]}),e.jsxs(Se,{value:"chat",className:"flex-1 flex flex-col m-0 overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b",children:[e.jsxs("div",{className:$("flex items-center gap-2 px-3 py-2 rounded-lg text-sm",z?"bg-green-500/10 text-green-600 dark:text-green-400":"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400"),children:[z?e.jsx(Kt,{className:"h-4 w-4"}):e.jsx(yt,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:z?"Connected":"Disconnected"})]}),e.jsx("div",{className:"text-xs text-muted-foreground mt-2 px-1 font-mono",children:Y})]}),e.jsxs("button",{type:"button",onClick:()=>s("settings"),className:"px-4 py-3 border-b text-left hover:bg-muted/40 transition-colors",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground mb-1",children:"Active model"}),e.jsxs("div",{className:"font-mono text-xs truncate",children:[e.jsx("span",{className:"text-muted-foreground",children:te||"—"}),e.jsx("span",{className:"text-muted-foreground/40 mx-1",children:"/"}),e.jsx("span",{className:"font-medium",children:re||"—"})]})]}),e.jsxs("div",{className:"px-4 py-3 border-b space-y-3",children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(at,{className:"h-4 w-4 text-muted-foreground"}),"Session"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[e.jsxs("div",{className:"flex flex-col p-2 rounded-lg bg-muted/50",children:[e.jsx("span",{className:"text-muted-foreground",children:"Messages"}),e.jsx("span",{className:"text-lg font-semibold",children:u.length})]}),e.jsxs("div",{className:"flex flex-col p-2 rounded-lg bg-muted/50",children:[e.jsx("span",{className:"text-muted-foreground",children:"Duration"}),e.jsx("span",{className:"text-lg font-semibold",children:ue((c==null?void 0:c.startedAt)??null)})]}),e.jsxs("div",{className:"flex flex-col p-2 rounded-lg bg-muted/50",children:[e.jsx("span",{className:"text-muted-foreground",children:"Input"}),e.jsx("span",{className:"text-lg font-semibold",children:r.input.toLocaleString()})]}),e.jsxs("div",{className:"flex flex-col p-2 rounded-lg bg-muted/50",children:[e.jsx("span",{className:"text-muted-foreground",children:"Output"}),e.jsx("span",{className:"text-lg font-semibold",children:r.output.toLocaleString()})]})]}),i>0&&e.jsxs("div",{className:"flex justify-between items-center p-2 rounded-lg bg-green-500/10",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Cost"}),e.jsxs("span",{className:"text-lg font-semibold text-green-600 dark:text-green-400",children:["$",i.toFixed(4)]})]})]}),l.length>0&&e.jsxs("div",{className:"px-4 py-3 border-b space-y-2",children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center justify-between",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(un,{className:"h-4 w-4 text-muted-foreground"}),"Todos"]}),e.jsxs("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:[l.filter(h=>h.status==="completed").length,"/",l.length]})]}),e.jsx("ul",{className:"space-y-1 max-h-48 overflow-y-auto pr-1",children:l.map(h=>{const M=h.status==="completed"?Ce:h.status==="in_progress"?mn:pn,E=h.status==="completed"?"text-green-600 dark:text-green-400 line-through opacity-70":h.status==="in_progress"?"text-amber-600 dark:text-amber-400":"text-muted-foreground";return e.jsxs("li",{className:$("flex items-start gap-2 text-xs leading-snug",E),children:[e.jsx(M,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:h.status==="in_progress"&&h.activeForm?h.activeForm:h.content})]},h.id)})})]}),G.length>0&&e.jsxs("div",{className:"px-4 py-3 border-b space-y-2",children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center justify-between",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(zt,{className:"h-4 w-4 text-amber-500"}),"Pinned"]}),e.jsx("button",{type:"button",onClick:m,className:"text-[10px] text-muted-foreground hover:text-destructive",children:"Clear"})]}),e.jsx("ul",{className:"space-y-1 max-h-48 overflow-y-auto pr-1",children:G.map(h=>{const M=h.content.replace(/\s+/g," ").slice(0,80);return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>{const E=document.querySelector(`[data-message-id="${h.id}"]`);E&&(E.scrollIntoView({behavior:"smooth",block:"center"}),E.classList.add("ring-2","ring-amber-500/60"),setTimeout(()=>{E.classList.remove("ring-2","ring-amber-500/60")},1600))},className:"w-full text-left text-xs px-2 py-1.5 rounded bg-muted/40 hover:bg-muted/70 border border-amber-500/20 leading-snug",title:h.content.slice(0,400),children:[M,h.content.length>80?"…":""]})},h.id)})})]}),e.jsxs("div",{className:"px-4 py-3 border-b space-y-2",children:[e.jsxs(q,{variant:"outline",size:"sm",className:"w-full justify-start text-destructive hover:text-destructive",onClick:()=>{var h;x(),(h=P==null?void 0:P.clearContext)==null||h.call(P)},children:[e.jsx(Oe,{className:"h-4 w-4 mr-2"}),"Clear context"]}),e.jsxs(q,{variant:"outline",size:"sm",className:"w-full justify-start",onClick:()=>{var h;return(h=P==null?void 0:P.newSession)==null?void 0:h.call(P)},disabled:!z,children:[e.jsx(Fe,{className:"h-4 w-4 mr-2"}),"New session"]}),e.jsxs(q,{variant:"outline",size:"sm",className:"w-full justify-start",onClick:()=>{var h;return(h=P==null?void 0:P.compactContext)==null?void 0:h.call(P)},disabled:!z,children:[e.jsx(at,{className:"h-4 w-4 mr-2"}),"Compact context"]})]}),e.jsx("div",{className:"flex-1"}),e.jsx("div",{className:"px-3 py-3 border-t",children:e.jsxs(q,{variant:"ghost",size:"sm",className:"w-full justify-start",onClick:()=>s("settings"),children:[e.jsx(ht,{className:"h-4 w-4 mr-2"}),"Settings"]})})]}),e.jsxs(Se,{value:"history",className:"flex-1 m-0 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b",children:[e.jsx("span",{className:"text-xs uppercase tracking-wider text-muted-foreground",children:"Recent sessions"}),e.jsx(q,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>_(50),disabled:!z,title:"Refresh",children:B?e.jsx(we,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Nt,{className:"h-3.5 w-3.5"})})]}),X.length>3&&e.jsx("div",{className:"px-3 py-2 border-b",children:e.jsxs("div",{className:"relative",children:[e.jsx(Ee,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground/60"}),e.jsx("input",{type:"text",value:f,onChange:h=>b(h.target.value),placeholder:"Filter title, model, provider…",className:"w-full pl-7 pr-7 py-1 text-xs rounded-md bg-muted/40 border border-transparent focus:bg-background focus:border-input focus:outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50"}),f&&e.jsx("button",{type:"button",onClick:()=>b(""),className:"absolute right-1 top-1/2 -translate-y-1/2 text-muted-foreground/60 hover:text-foreground p-0.5",title:"Clear filter",children:e.jsx($e,{className:"h-3 w-3"})})]})}),A&&e.jsx("div",{className:"px-4 py-2 text-xs text-destructive bg-destructive/5 border-b",children:A}),e.jsx(Ve,{className:"flex-1",children:X.length===0&&!B?e.jsxs("div",{className:"text-center text-muted-foreground py-8 px-4",children:[e.jsx(lt,{className:"h-8 w-8 mx-auto mb-3 opacity-20"}),e.jsx("p",{className:"text-sm font-medium",children:"No history yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Your conversations will appear here"})]}):C.length===0?e.jsxs("div",{className:"text-center text-muted-foreground py-8 px-4",children:[e.jsx(Ee,{className:"h-8 w-8 mx-auto mb-3 opacity-20"}),e.jsx("p",{className:"text-sm font-medium",children:"No matches"}),e.jsx("p",{className:"text-xs mt-1",children:"Try a different filter"})]}):e.jsx("div",{className:"p-2 space-y-3",children:C.map(h=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:$("sticky top-0 z-[1] px-1 pb-1 text-[10px] uppercase tracking-wider font-semibold bg-card/90 backdrop-blur-sm flex items-center gap-1",h.star?"text-amber-500":"text-muted-foreground/80"),children:[h.star&&e.jsx(Tt,{className:"h-3 w-3 fill-current"}),h.label," ",e.jsxs("span",{className:"text-muted-foreground/50 font-normal normal-case ml-1",children:["(",h.rows.length,")"]})]}),h.rows.map(M=>e.jsxs("div",{className:$("group relative rounded-md border text-sm transition-colors",M.isCurrent?"bg-primary/5 border-primary/40":"bg-card border-border/60 hover:bg-muted/40 hover:border-primary/40"),children:[e.jsx("button",{type:"button",disabled:M.isCurrent||R===M.id,onClick:()=>Z(M.id),onDoubleClick:E=>{E.stopPropagation(),ee(M.id),U(y[M.id]??M.title??"")},className:"block w-full rounded-md px-3 py-2 pr-16 text-left disabled:cursor-default focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[R===M.id?e.jsx("input",{value:K,onChange:E=>U(E.target.value),onClick:E=>E.stopPropagation(),onBlur:()=>{g(M.id,K),ee(null)},onKeyDown:E=>{E.key==="Enter"?(E.preventDefault(),g(M.id,K),ee(null)):E.key==="Escape"&&(E.preventDefault(),ee(null))},placeholder:M.title||"Nickname",className:"w-full text-sm bg-background border border-input rounded px-1.5 py-0.5 focus:outline-none focus:ring-1 focus:ring-ring"}):e.jsx("div",{className:"font-medium truncate text-foreground",title:y[M.id]?`${y[M.id]} — original: ${M.title}`:`${M.title}
|
|
93
|
+
|
|
94
|
+
Double-click to rename`,children:y[M.id]||M.title||"(empty)"}),e.jsxs("div",{className:"text-[10px] text-muted-foreground font-mono truncate mt-0.5",children:[M.provider,"/",M.model]}),e.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-muted-foreground/80 mt-0.5",children:[e.jsx("span",{children:v(M.startedAt)}),M.tokenTotal>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsxs("span",{className:"tabular-nums",children:[M.tokenTotal.toLocaleString()," tok"]})]}),M.isCurrent&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx("span",{className:"text-primary font-medium",children:"active"})]})]})]})}),e.jsxs("div",{className:"absolute right-2 top-2 flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>S(M.id),className:$("transition-opacity hover:text-amber-500",w.includes(M.id)?"opacity-100 text-amber-500":"opacity-0 group-hover:opacity-100 text-muted-foreground"),title:w.includes(M.id)?"Unfavorite":"Mark as favorite",children:e.jsx(Tt,{className:$("h-3.5 w-3.5",w.includes(M.id)&&"fill-current")})}),!M.isCurrent&&e.jsx("button",{type:"button",onClick:()=>{window.confirm(`Delete session "${M.title}"?`)&&N(M.id)},className:"opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-destructive",title:"Delete session",children:e.jsx(Oe,{className:"h-3.5 w-3.5"})})]})]},M.id))]},h.label))})})]})]})]})}function $o(){const{theme:o}=ms(),{currentView:t,sidebarOpen:s,toggleSidebar:a,setSearchOpen:n,setSidebarOpen:r}=I(),i=T(m=>m.isLoading),c=H(m=>m.iteration),l=H(m=>m.projectName),u=H(m=>{var f;return(f=m.session)==null?void 0:f.title}),x=H(m=>{var f;return(f=m.session)==null?void 0:f.id}),p=I(m=>x?m.sessionNicknames[x]:void 0);return d.useEffect(()=>{if(typeof window>"u")return;const m=window.matchMedia("(max-width: 768px)"),f=()=>{m.matches&&I.getState().sidebarOpen&&r(!1)};return f(),m.addEventListener("change",f),()=>m.removeEventListener("change",f)},[r]),En(),d.useEffect(()=>{const m=[];if(i){const S=c?` iter ${c.index}${c.max?`/${c.max}`:""}`:"";m.push(`●${S}`)}const f=(p==null?void 0:p.trim())||(u==null?void 0:u.trim()),b=l==null?void 0:l.trim();f&&m.push(f),b&&m.push(b),m.push("WrongStack");const w=m.filter(Boolean).join(" · ");return document.title=w,()=>{document.title="WrongStack"}},[i,c,l,u,p]),d.useEffect(()=>{const m=f=>{var g,R,ee,K,U,G,z;const b=f.target,w=(g=b==null?void 0:b.tagName)==null?void 0:g.toLowerCase(),S=w==="input"||w==="textarea"||(b==null?void 0:b.isContentEditable),y=f.ctrlKey||f.metaKey;if(y&&f.key==="\\"){f.preventDefault(),a();return}if(y&&f.key.toLowerCase()==="f"){f.preventDefault(),n(!0);return}if(y&&f.key.toLowerCase()==="/"){f.preventDefault();const Y=document.querySelector("textarea");Y==null||Y.focus();return}if(y&&!S&&(f.key.toLowerCase()==="l"?(f.preventDefault(),T.getState().clearMessages(),(ee=(R=xe(Q.getState().wsUrl))==null?void 0:R.clearContext)==null||ee.call(R)):f.key.toLowerCase()==="n"?(f.preventDefault(),(U=(K=xe(Q.getState().wsUrl))==null?void 0:K.newSession)==null||U.call(K)):f.key.toLowerCase()==="e"&&(f.preventDefault(),St())),y&&f.shiftKey&&f.key.toLowerCase()==="d"&&(f.preventDefault(),I.getState().toggleCompactMode()),!S&&!y&&!f.altKey){const Y=Array.from(document.querySelectorAll("[data-message-id]"));if(Y.length===0)return;const te=document.querySelector('[data-message-id][data-focused="true"]'),re=te?Y.indexOf(te):-1,X=B=>{for(const A of Y)A.removeAttribute("data-focused");B.setAttribute("data-focused","true"),B.scrollIntoView({behavior:"smooth",block:"center"})};if(f.key==="j"||f.key==="ArrowDown"){const B=Y[Math.min(Y.length-1,Math.max(0,re+1))];B&&(f.preventDefault(),X(B));return}if(f.key==="k"||f.key==="ArrowUp"){const B=Y[Math.max(0,re<=0?0:re-1)];B&&(f.preventDefault(),X(B));return}if(f.key==="g"&&!f.shiftKey){f.preventDefault(),X(Y[0]);return}if(f.key==="G"||f.key==="g"&&f.shiftKey){f.preventDefault(),X(Y[Y.length-1]);return}if(f.key==="Escape"&&te){f.preventDefault(),te.removeAttribute("data-focused");return}if(f.key==="c"&&te){const B=((G=te.querySelector(".markdown-content"))==null?void 0:G.innerText)??te.innerText;B&&((z=navigator.clipboard)==null||z.writeText(B).catch(()=>{}),f.preventDefault());return}}};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[a,n]),e.jsxs("div",{className:$("flex h-screen",o),children:[s&&e.jsx(Co,{}),e.jsxs("main",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(yo,{}),t==="chat"&&e.jsx(xo,{}),t==="settings"&&e.jsx(No,{})]}),e.jsx(bo,{}),e.jsx(Dn,{}),e.jsx(So,{}),e.jsx(wo,{}),e.jsx(bn,{})]})}function To(){return e.jsx(vo,{children:e.jsx(jo,{defaultTheme:"system",children:e.jsx($o,{})})})}xn.createRoot(document.getElementById("root")).render(e.jsx(hn.StrictMode,{children:e.jsx(To,{})}));
|