tarsk 0.5.41 → 0.5.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/dist/bundled-skills/skill-creator/LICENSE.txt +202 -0
  2. package/dist/bundled-skills/skill-creator/SKILL.md +510 -0
  3. package/dist/bundled-skills/skill-creator/agents/analyzer.md +283 -0
  4. package/dist/bundled-skills/skill-creator/agents/comparator.md +203 -0
  5. package/dist/bundled-skills/skill-creator/agents/grader.md +227 -0
  6. package/dist/bundled-skills/skill-creator/assets/eval_review.html +292 -0
  7. package/dist/bundled-skills/skill-creator/eval-viewer/generate_review.js +544 -0
  8. package/dist/bundled-skills/skill-creator/eval-viewer/viewer.html +1478 -0
  9. package/dist/bundled-skills/skill-creator/package.json +3 -0
  10. package/dist/bundled-skills/skill-creator/references/schemas.md +423 -0
  11. package/dist/bundled-skills/skill-creator/scripts/aggregate_benchmark.js +377 -0
  12. package/dist/bundled-skills/skill-creator/scripts/generate_report.js +345 -0
  13. package/dist/bundled-skills/skill-creator/scripts/improve_description.js +263 -0
  14. package/dist/bundled-skills/skill-creator/scripts/package_skill.js +147 -0
  15. package/dist/bundled-skills/skill-creator/scripts/quick_validate.js +132 -0
  16. package/dist/bundled-skills/skill-creator/scripts/run_eval.js +345 -0
  17. package/dist/bundled-skills/skill-creator/scripts/run_loop.js +411 -0
  18. package/dist/bundled-skills/skill-creator/scripts/utils.js +60 -0
  19. package/dist/index.js +8817 -6340
  20. package/dist/public/assets/{account-view-D-dJ0y-D.js → account-view-xKotpUyx.js} +1 -1
  21. package/dist/public/assets/api-D6uLdHBQ.js +1 -0
  22. package/dist/public/assets/browser-tab-DxigYzoT.js +1 -0
  23. package/dist/public/assets/commit-dialog-CLQM9ah3.js +1 -0
  24. package/dist/public/assets/context-menu-rC7iWcty.js +1 -0
  25. package/dist/public/assets/create-repo-dialog-C6k5wZPW.js +1 -0
  26. package/dist/public/assets/{dialogs-config-B-LZ4nOb.js → dialogs-config-CjKh5Rl2.js} +14 -14
  27. package/dist/public/assets/diff-view-DWDWI5nl.js +3 -0
  28. package/dist/public/assets/explorer-tab-view-B0kT8Hl6.js +2 -0
  29. package/dist/public/assets/explorer-tree-BC4fBpxi.js +1 -0
  30. package/dist/public/assets/explorer-view-DIM08sdy.js +1 -0
  31. package/dist/public/assets/git-history-dialog-CuxOTngT.js +1 -0
  32. package/dist/public/assets/git-ops-button-C04zFAnF.js +2 -0
  33. package/dist/public/assets/history-view-ar7GLZ-R.js +9 -0
  34. package/dist/public/assets/index--HY4BbcM.js +90 -0
  35. package/dist/public/assets/index-DKOXV50p.css +1 -0
  36. package/dist/public/assets/mcp-server-card-Cy4RU2_Q.js +1 -0
  37. package/dist/public/assets/merged-pr-dialog-Bo07VouF.js +1 -0
  38. package/dist/public/assets/model-star-rating-BmkpdXfr.js +1 -0
  39. package/dist/public/assets/onboarding-ClZrOxX7.js +1 -0
  40. package/dist/public/assets/project-settings-view-Dm9pQAp_.js +1 -0
  41. package/dist/public/assets/providers-list-view-D5gHsjl_.js +1 -0
  42. package/dist/public/assets/pull-request-dialog-8AYlOUNX.js +1 -0
  43. package/dist/public/assets/pull-with-changes-dialog-CSa5OE-d.js +1 -0
  44. package/dist/public/assets/push-before-pr-dialog-D5W_xsqv.js +1 -0
  45. package/dist/public/assets/radio-group-CbatNaj1.js +1 -0
  46. package/dist/public/assets/react-vendor-DwQYi7es.js +16 -0
  47. package/dist/public/assets/settings-general-view-BP5ULy9A.js +1 -0
  48. package/dist/public/assets/settings-instructions-view-DMAjbi6E.js +1 -0
  49. package/dist/public/assets/settings-list-B8hiBkBz.js +1 -0
  50. package/dist/public/assets/settings-mcp-servers-view-OimQz-Rd.js +5 -0
  51. package/dist/public/assets/{settings-models-skeleton-ClrbJy_p.js → settings-models-skeleton-DPnYbg69.js} +1 -1
  52. package/dist/public/assets/settings-models-view-Fq3WtdKG.js +1 -0
  53. package/dist/public/assets/settings-rules-view-DBk7DzV2.js +8 -0
  54. package/dist/public/assets/settings-skills-view-CmOw-WMM.js +2 -0
  55. package/dist/public/assets/settings-slash-commands-view-FsrF5FkK.js +1 -0
  56. package/dist/public/assets/settings-subagents-view-D98Nxoly.js +2 -0
  57. package/dist/public/assets/{settings-system-prompt-view-Dl66VFaj.js → settings-system-prompt-view-B6Hy9ZyK.js} +1 -1
  58. package/dist/public/assets/settings-view-J-rjoRcU.js +2 -0
  59. package/dist/public/assets/skeleton-BHhGML7J.js +1 -0
  60. package/dist/public/assets/slug-utils-DyRUJ1NS.js +1 -0
  61. package/dist/public/assets/terminal-panel-DTOx74_o.js +1 -0
  62. package/dist/public/assets/{ui-components-C4RrfJEJ.js → ui-components-Jc6oi6bz.js} +1 -1
  63. package/dist/public/assets/use-deferred-search-B7EdyRbt.js +1 -0
  64. package/dist/public/assets/{utils-B7FQXlI6.js → utils-tgi5ym_d.js} +1 -1
  65. package/dist/public/assets/web-C3vJZ_3_.js +1 -0
  66. package/dist/public/assets/web-CUAWBWPy.js +1 -0
  67. package/dist/public/assets/{whisper-wasm-EGutPGND.js → whisper-wasm-CWcbC1MB.js} +1 -1
  68. package/dist/public/browser-preview-rpc.js +484 -0
  69. package/dist/public/index.html +8 -8
  70. package/package.json +4 -3
  71. package/dist/public/assets/api-DJaJqkc6.js +0 -1
  72. package/dist/public/assets/browser-tab-D7wEj-BD.js +0 -1
  73. package/dist/public/assets/commit-dialog-DdhGDH4F.js +0 -1
  74. package/dist/public/assets/context-menu-asf2g-KX.js +0 -1
  75. package/dist/public/assets/create-repo-dialog-Bltp6PKZ.js +0 -1
  76. package/dist/public/assets/diff-view-Bi545EPj.js +0 -3
  77. package/dist/public/assets/explorer-tab-view-B-P555GE.js +0 -2
  78. package/dist/public/assets/explorer-tree-CyXhVrI7.js +0 -1
  79. package/dist/public/assets/explorer-view-BAHDhIGN.js +0 -1
  80. package/dist/public/assets/git-history-dialog-Bci_iQmi.js +0 -1
  81. package/dist/public/assets/git-ops-button-1lum9QXI.js +0 -2
  82. package/dist/public/assets/history-view-CAkN8PCo.js +0 -9
  83. package/dist/public/assets/index-BLO68CQl.js +0 -69
  84. package/dist/public/assets/index-jIBJk8xl.css +0 -1
  85. package/dist/public/assets/mcp-server-card-DQUpkDFV.js +0 -1
  86. package/dist/public/assets/merged-pr-dialog-tHPrJ2CK.js +0 -1
  87. package/dist/public/assets/onboarding-Bbvb7kO4.js +0 -1
  88. package/dist/public/assets/project-settings-view-BRkHOq_q.js +0 -1
  89. package/dist/public/assets/providers-list-view-Dex879vv.js +0 -1
  90. package/dist/public/assets/pull-request-dialog-WHdmrW83.js +0 -1
  91. package/dist/public/assets/pull-with-changes-dialog-Ck3OwINV.js +0 -1
  92. package/dist/public/assets/push-before-pr-dialog-Bvqvz04U.js +0 -1
  93. package/dist/public/assets/radio-group-B0xvu5B9.js +0 -1
  94. package/dist/public/assets/react-vendor-D8PTA4EX.js +0 -16
  95. package/dist/public/assets/settings-general-view-lUxshNA9.js +0 -1
  96. package/dist/public/assets/settings-instructions-view-C57XGLha.js +0 -1
  97. package/dist/public/assets/settings-list-CHGKmGl_.js +0 -1
  98. package/dist/public/assets/settings-mcp-servers-view-DpqkhrgB.js +0 -5
  99. package/dist/public/assets/settings-models-view-QPEdnibD.js +0 -1
  100. package/dist/public/assets/settings-rules-view-WJU--cRq.js +0 -8
  101. package/dist/public/assets/settings-skills-view-mgHy4G_g.js +0 -2
  102. package/dist/public/assets/settings-slash-commands-view-LB5tVqy1.js +0 -1
  103. package/dist/public/assets/settings-subagents-view-QR2qlA_y.js +0 -2
  104. package/dist/public/assets/settings-view-BlVJv4Pz.js +0 -2
  105. package/dist/public/assets/skeleton-K-fVduHt.js +0 -1
  106. package/dist/public/assets/terminal-panel-BGQxckfH.js +0 -2
@@ -1,69 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-oojFghRi.js","assets/rolldown-runtime-aKtaBQYM.js","assets/git-ops-button-1lum9QXI.js","assets/monaco-CZnIWXyV.js","assets/monaco-Br_kD0ds.css","assets/dialogs-config-B-LZ4nOb.js","assets/diff-view-Bi545EPj.js","assets/history-view-CAkN8PCo.js","assets/onboarding-Bbvb7kO4.js","assets/context-menu-asf2g-KX.js","assets/react-vendor-D8PTA4EX.js","assets/utils-B7FQXlI6.js","assets/terminal-panel-BGQxckfH.js","assets/explorer-tab-view-B-P555GE.js","assets/browser-tab-D7wEj-BD.js","assets/settings-view-BlVJv4Pz.js","assets/settings-models-skeleton-ClrbJy_p.js","assets/skeleton-K-fVduHt.js"])))=>i.map(i=>d[i]);
2
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{$ as t,$i as n,$n as r,A as i,Aa as a,An as o,Ar as s,Ba as c,Bn as l,Bt as u,Ca as d,D as f,Da as p,Di as m,Dn as h,Dr as g,Ea as _,Ei as v,En as y,Er as b,Fi as x,Fn as S,Ft as C,Ga as w,Gi as T,Gn as E,Ha as D,Hi as O,Hn as k,I as A,Ii as j,Ja as M,Jn as N,Kn as P,Kt as F,La as I,Ln as L,Lt as R,Ma as ee,Mn as te,Mr as z,Mt as ne,N as B,Na as re,Nn as V,Nt as ie,Oa as ae,Oi as oe,Or as H,Ot as se,Pa as ce,Pi as le,Pn as ue,Pt as de,Q as fe,Qa as pe,Qi as me,Qn as he,Qt as ge,R as _e,Rn as ve,S as ye,Sa as be,Si as xe,St as Se,T as Ce,Ta as we,Ti as Te,Tt as Ee,Ui as De,Un as Oe,Va as ke,Vi as Ae,Vn as je,Wa as Me,Wi as Ne,Wn as Pe,Xt as Fe,Ya as Ie,Yi as Le,Yt as Re,Z as ze,Zn as Be,Zt as Ve,_n as He,an as Ue,b as We,ba as Ge,bi as Ke,bn as qe,bo as Je,bt as Ye,c as Xe,ca as Ze,ci as U,d as Qe,da as $e,di as et,dn as tt,do as nt,ea as rt,eo as it,et as at,fi as ot,fn as st,fr as W,g as ct,ga as lt,gn as ut,gt as dt,ha as ft,hn as pt,ho as mt,hr as G,ia as ht,in as gt,io as _t,j as vt,ji as yt,jn as bt,jr as xt,kn as St,kr as Ct,kt as wt,lo as Tt,lr as Et,lt as Dt,m as Ot,ma as kt,mi as At,mn as jt,mo as Mt,mr as Nt,na as Pt,no as Ft,nr as It,nt as Lt,oo as Rt,or as zt,ot as Bt,p as Vt,pa as Ht,pi as Ut,pn as Wt,pr as K,q as Gt,qi as Kt,qn as qt,qt as Jt,ra as Yt,rn as Xt,ro as Zt,rr as Qt,sa as $t,so as en,sr as tn,tn as nn,to as rn,tr as an,tt as on,ua as sn,ui as q,un as cn,uo as ln,ur as un,ut as dn,v as fn,va as pn,vn as mn,vo as hn,w as gn,wa as _n,wi as J,wn as vn,wr as yn,wt as bn,x as xn,xi as Sn,xo as Cn,yn as wn,yo as Tn,za as En}from"./dialogs-config-B-LZ4nOb.js";import{$ as Dn,A as On,B as kn,D as An,E as jn,F as Mn,G as Nn,H as Pn,I as Fn,J as In,K as Ln,L as Rn,M as zn,N as Bn,O as Vn,P as Hn,Q as Un,R as Wn,T as Gn,U as Kn,V as qn,W as Jn,X as Yn,Y as Xn,Z as Zn,at as Qn,ct as $n,et as er,it as tr,j as nr,k as rr,nt as ir,ot as ar,q as or,rt as sr,st as cr,tt as lr,ut as ur,w as dr,z as fr}from"./react-vendor-D8PTA4EX.js";import{r as pr}from"./monaco-CZnIWXyV.js";import{c as mr,o as hr,r as gr,s as _r}from"./onboarding-Bbvb7kO4.js";import{A as vr,F as yr,I as br,M as xr,N as Sr,O as Cr,P as wr,a as Tr,j as Er,k as Dr,l as Or,n as kr,o as Ar,s as jr,x as Mr}from"./history-view-CAkN8PCo.js";import{a as Nr,i as Pr,n as Fr,o as Ir,r as Lr,t as Rr}from"./whisper-wasm-EGutPGND.js";import{n as zr,t as Br}from"./utils-B7FQXlI6.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var Y=e(Cn(),1),Vr=ur(),X=Tn(),Hr=1e10,Ur=1e3;function Wr(e,t){let n=e.map(e=>`"${e}"`).join(`, `);return Error(`This RPC instance cannot ${t} because the transport did not provide one or more of these methods: ${n}`)}function Gr(e={}){let t={},n={},r;function i(e){n.unregisterHandler&&n.unregisterHandler(),n=e,n.registerHandler?.(x)}function a(e){if(typeof e==`function`){r=e;return}r=(t,n)=>{let r=e[t];if(r)return r(n);let i=e._;if(!i)throw Error(`The requested method has no handler: ${String(t)}`);return i(t,n)}}let{maxRequestTime:o=Ur}=e;e.transport&&i(e.transport),e.requestHandler&&a(e.requestHandler),e._debugHooks&&(t=e._debugHooks);let s=0;function c(){return s<=Hr?++s:s=0}let l=new Map,u=new Map;function d(e,...r){let i=r[0];return new Promise((r,a)=>{if(!n.send)throw Wr([`send`],`make requests`);let s=c(),d={type:`request`,id:s,method:e,params:i};l.set(s,{resolve:r,reject:a}),o!==1/0&&u.set(s,setTimeout(()=>{u.delete(s),l.delete(s),a(Error(`RPC request timed out.`))},o)),t.onSend?.(d),n.send(d)})}let f=new Proxy(d,{get:(e,t,n)=>t in e?Reflect.get(e,t,n):e=>d(t,e)}),p=f;function m(e,...r){let i=r[0];if(!n.send)throw Wr([`send`],`send messages`);let a={type:`message`,id:e,payload:i};t.onSend?.(a),n.send(a)}let h=new Proxy(m,{get:(e,t,n)=>t in e?Reflect.get(e,t,n):e=>m(t,e)}),g=h,_=new Map,v=new Set;function y(e,t){if(!n.registerHandler)throw Wr([`registerHandler`],`register message listeners`);if(e===`*`){v.add(t);return}_.has(e)||_.set(e,new Set),_.get(e).add(t)}function b(e,t){if(e===`*`){v.delete(t);return}_.get(e)?.delete(t),_.get(e)?.size===0&&_.delete(e)}async function x(e){if(t.onReceive?.(e),!(`type`in e))throw Error(`Message does not contain a type.`);if(e.type===`request`){if(!n.send||!r)throw Wr([`send`,`requestHandler`],`handle requests`);let{id:i,method:a,params:o}=e,s;try{s={type:`response`,id:i,success:!0,payload:await r(a,o)}}catch(e){if(!(e instanceof Error))throw e;s={type:`response`,id:i,success:!1,error:e.message}}t.onSend?.(s),n.send(s);return}if(e.type===`response`){let t=u.get(e.id);t!=null&&clearTimeout(t),u.delete(e.id);let{resolve:n,reject:r}=l.get(e.id)??{};l.delete(e.id),e.success?n?.(e.payload):r?.(Error(e.error));return}if(e.type===`message`){for(let t of v)t(e.id,e.payload);let t=_.get(e.id);if(!t)return;for(let n of t)n(e.payload);return}throw Error(`Unexpected RPC message type: ${e.type}`)}return{setTransport:i,setRequestHandler:a,request:f,requestProxy:p,send:h,sendProxy:g,addMessageListener:y,removeMessageListener:b,proxy:{send:g,request:p}}}function Kr(e,t){let n=Gr({maxRequestTime:t.maxRequestTime,requestHandler:{...t.handlers.requests,...t.extraRequestHandlers},transport:{registerHandler:()=>{}}}),r=t.handlers.messages;return r&&n.addMessageListener(`*`,((e,t)=>{let n=r[`*`];n&&n(e,t);let i=r[e];i&&i(t)})),n}var qr=window.__electrobunWebviewId,Jr=window.__electrobunRpcSocketPort,Yr=class{bunSocket;rpc;rpcHandler;constructor(e){this.rpc=e.rpc,this.init()}init(){this.initSocketToBun(),window.__electrobun.receiveMessageFromBun=this.receiveMessageFromBun.bind(this),this.rpc&&this.rpc.setTransport(this.createTransport())}initSocketToBun(){let e=new WebSocket(`ws://localhost:${Jr}/socket?webviewId=${qr}`);this.bunSocket=e,e.addEventListener(`open`,()=>{}),e.addEventListener(`message`,async e=>{let t=e.data;if(typeof t==`string`)try{let e=JSON.parse(t),n=await window.__electrobun_decrypt(e.encryptedData,e.iv,e.tag);this.rpcHandler?.(JSON.parse(n))}catch(e){console.error(`Error parsing bun message:`,e)}else t instanceof Blob||console.error(`UNKNOWN DATA TYPE RECEIVED:`,e.data)}),e.addEventListener(`error`,e=>{console.error(`Socket error:`,e)}),e.addEventListener(`close`,e=>{})}createTransport(){let e=this;return{send(t){try{let n=JSON.stringify(t);e.bunBridge(n)}catch(e){console.error(`bun: failed to serialize message to webview`,e)}},registerHandler(t){e.rpcHandler=t}}}async bunBridge(e){if(this.bunSocket?.readyState===WebSocket.OPEN)try{let{encryptedData:t,iv:n,tag:r}=await window.__electrobun_encrypt(e),i=JSON.stringify({encryptedData:t,iv:n,tag:r});this.bunSocket.send(i);return}catch(e){console.error(`Error sending message to bun via socket:`,e)}window.__electrobunBunBridge?.postMessage(e)}receiveMessageFromBun(e){this.rpcHandler&&this.rpcHandler(e)}static defineRPC(e){return Kr(`webview`,{...e,extraRequestHandlers:{evaluateJavascriptWithResponse:({script:e})=>new Promise(t=>{try{let n=Function(e)();n instanceof Promise?n.then(e=>{t(e)}).catch(e=>{console.error(`bun: async script execution failed`,e),t(String(e))}):t(n)}catch(e){console.error(`bun: failed to eval script`,e),t(String(e))}})}})}};function Xr(e){return typeof e==`string`?e.replace(/\\n/g,`
3
- `).replace(/✅/g,`✓`):``}function Zr(e){if(!e||typeof e!=`string`)return null;let t=e.trim();if(!t)return null;let n=/\[([A-Za-z]+)\]\s*/g,r,i=0;for(let e of t.matchAll(n))r=e[1],i=e.index+e[0].length;let a=r,o=a?t.slice(i):t;if(a&&o)return[{type:`reasoning`,text:o,label:a}];let s=[],c=0;for(;c<t.length;){let e=t.indexOf(`[`,c);if(e===-1){let e=t.slice(c).trim();e&&s.push({type:`reasoning`,text:e});break}let n=t.slice(c,e).trim();n&&s.push({type:`reasoning`,text:n});let r=0,i=-1;for(let n=e;n<t.length;n++)if(t[n]===`[`)r++;else if(t[n]===`]`&&(r--,r===0)){i=n;break}if(i===-1){let n=t.slice(e).trim();n&&s.push({type:`reasoning`,text:n});break}try{let n=JSON.parse(t.slice(e,i+1));if(Array.isArray(n)){for(let e of n)if(e&&typeof e==`object`&&`type`in e){let t=e.type;(t===`tool-result`||t===`tool_use`)&&s.push(e)}}}catch{let n=t.slice(e,i+1).trim();n&&s.push({type:`reasoning`,text:n})}c=i+1}return s.length>0?s:null}function Qr(e){return e.map(e=>{if(typeof e==`object`&&e&&!(`type`in e)){let t=e;if(t.reasoning)return{type:`reasoning`,text:typeof t.reasoning==`string`?t.reasoning:JSON.stringify(t.reasoning)};let n=t.text??t.content??t.answer;if(n)return{type:`text`,text:typeof n==`string`?n:JSON.stringify(n)}}return e})}function $r(e){let t=[];if(e.type===`long_running_confirmation`&&typeof e.prompt==`object`&&e.prompt!==null&&typeof e.prompt.question==`string`&&Array.isArray(e.prompt.options)){let n=e.prompt;return t.push({type:`long_running_confirmation`,prompt:{toolCallId:typeof n.toolCallId==`string`?n.toolCallId:void 0,question:n.question,options:n.options.filter(e=>typeof e==`string`),context:typeof n.context==`string`?n.context:void 0}}),t}if(e.type===`shell_permission`&&typeof e.shellPermission==`object`&&e.shellPermission!==null&&typeof e.shellPermission.command==`string`){let n=e.shellPermission;return t.push({type:`shell_permission`,prompt:{toolCallId:typeof n.toolCallId==`string`?n.toolCallId:`shell-permission`,command:n.command,source:n.source===`bash`||n.source===`skill_script`||n.source===`browser_js`?n.source:`bash`,wildcardOptions:Array.isArray(n.wildcardOptions)?n.wildcardOptions.filter(e=>typeof e==`object`&&!!e&&typeof e.label==`string`&&typeof e.pattern==`string`&&(e.scope===`session`||e.scope===`project`)):[]}}),t}if(e.type===`web_fetch_permission`&&typeof e.webFetchPermission==`object`&&e.webFetchPermission!==null&&typeof e.webFetchPermission.hostname==`string`){let n=e.webFetchPermission;return t.push({type:`web_fetch_permission`,prompt:{toolCallId:typeof n.toolCallId==`string`?n.toolCallId:`web-fetch-permission`,hostname:n.hostname,url:typeof n.url==`string`?n.url:``,wildcardOptions:Array.isArray(n.wildcardOptions)?n.wildcardOptions.filter(e=>typeof e==`object`&&!!e&&typeof e.label==`string`&&typeof e.pattern==`string`&&(e.scope===`session`||e.scope===`project`)):[]}}),t}e.reasoning&&typeof e.reasoning==`string`&&t.push({type:`reasoning`,text:e.reasoning});let n=(typeof e.text==`string`?e.text:null)??(typeof e.content==`string`?e.content:null)??(typeof e.answer==`string`?e.answer:null);return n&&t.push({type:`text`,text:n}),t.length===0&&Object.keys(e).length>0&&t.push({type:`text`,text:JSON.stringify(e,null,2)}),t}function ei(e){if(!e)return null;let t=e.trim();if(t.startsWith(`{`)||t.startsWith(`[`))try{let e=JSON.parse(t);if(Array.isArray(e))return Qr(e);if(typeof e==`object`&&e)return $r(e)}catch{}let n=[],r=e.indexOf(`{`),i=e.indexOf(`[`),a=r===-1?i:i===-1?r:Math.min(r,i);if(a!==-1){let t=e.slice(a),r=Math.max(t.lastIndexOf(`]`),t.lastIndexOf(`}`));if(r!==-1){let e=t.substring(0,r+1);try{let i=JSON.parse(e);Array.isArray(i)?n.push(...Qr(i)):n.push(...$r(i));let a=t.substring(r+1).trim();return a&&n.push({type:`text`,text:a}),n}catch{}}}return null}function ti(e,t,n){let r=e[e.length-1];return r?.type===t?[...e.slice(0,-1),{type:t,chunks:[...r.chunks,n]}]:[...e,{type:t,chunks:[n]}]}function ni(e,t){return e[e.length-1]?.type===`content`?[...e.slice(0,-1),{type:`content`,chunks:[t]}]:[...e,{type:`content`,chunks:[t]}]}function ri(e,t){return[...e,{type:`long_running_confirmation`,prompt:t}]}function ii(e,t){return[...e,{type:`shell_permission`,prompt:t}]}function ai(e,t){return[...e,{type:`web_fetch_permission`,prompt:t}]}function oi(e){let t=[];for(let n of e){if(n.type===`long_running_confirmation`){t.push({type:`long_running_confirmation`,prompt:n.prompt});continue}if(n.type===`shell_permission`){t.push({type:`shell_permission`,prompt:n.prompt});continue}if(n.type===`web_fetch_permission`){t.push({type:`web_fetch_permission`,prompt:n.prompt});continue}let e=n.chunks.join(``);if(n.type===`thinking`){let n=Zr(e)??[];t.push(...n)}else{let n=ei(e)??(e.trim()?[{type:`text`,text:e}]:[]);t.push(...n)}}return t}function si(e,t=!1){let n=[],r=[],i,a=()=>{r.length>0&&(n.push({type:`thinking-group`,text:r.join(`
4
-
5
- `),label:i,isCurrentlyStreaming:!1}),r=[],i=void 0)};for(let t of e)if(t.type===`reasoning`&&`text`in t){let e=t;r.push(e.text),e.label&&(i=e.label)}else a(),n.push(t);if(a(),t&&n.length>0){let e=n[n.length-1];if(e.type===`thinking-group`){let t=e;t.label!==`Validated`&&(t.isCurrentlyStreaming=!0)}}return n}function ci(e){let t=oi(e);return t.length===0?`...`:t.length===1&&t[0]?.type===`text`&&`text`in t[0]?t[0].text:JSON.stringify(t)}var Z=function(e){return e.SetProjects=`SET_PROJECTS`,e.SetProjectsLoading=`SET_PROJECTS_LOADING`,e.SelectThread=`SELECT_THREAD`,e.SetMessages=`SET_MESSAGES`,e.AddMessage=`ADD_MESSAGE`,e.EnqueueChatMessage=`ENQUEUE_CHAT_MESSAGE`,e.RemoveQueuedChatMessage=`REMOVE_QUEUED_CHAT_MESSAGE`,e.SetStreaming=`SET_STREAMING`,e.AppendStreamContent=`APPEND_STREAM_CONTENT`,e.SetStreamContent=`SET_STREAM_CONTENT`,e.AppendStreamThinking=`APPEND_STREAM_THINKING`,e.AppendStreamChunk=`APPEND_STREAM_CHUNK`,e.SetStreamModel=`SET_STREAM_MODEL`,e.SetProjectModel=`SET_PROJECT_MODEL`,e.ResetStream=`RESET_STREAM`,e.StopStream=`STOP_STREAM`,e.ToggleSidebar=`TOGGLE_SIDEBAR`,e.CloseSidebar=`CLOSE_SIDEBAR`,e.SetCreatingProject=`SET_CREATING_PROJECT`,e.ConfigUpdated=`CONFIG_UPDATED`,e.SetProcessingThreads=`SET_PROCESSING_THREADS`,e.AddProcessingThread=`ADD_PROCESSING_THREAD`,e.RemoveProcessingThread=`REMOVE_PROCESSING_THREAD`,e.AddCreatingProject=`ADD_CREATING_PROJECT`,e.AddCreatingThread=`ADD_CREATING_THREAD`,e.RemoveCreatingProject=`REMOVE_CREATING_PROJECT`,e.RemoveCreatingThread=`REMOVE_CREATING_THREAD`,e.MarkThreadCompleted=`MARK_THREAD_COMPLETED`,e.ClearThreadCompleted=`CLEAR_THREAD_COMPLETED`,e.AddDeletingThread=`ADD_DELETING_THREAD`,e.RemoveDeletingThread=`REMOVE_DELETING_THREAD`,e.AddDeletingProject=`ADD_DELETING_PROJECT`,e.RemoveDeletingProject=`REMOVE_DELETING_PROJECT`,e.AppendCommandOutput=`APPEND_COMMAND_OUTPUT`,e.SetRunningCommand=`SET_RUNNING_COMMAND`,e.ClearCommandOutput=`CLEAR_COMMAND_OUTPUT`,e.ToggleTerminal=`TOGGLE_TERMINAL`,e.SetTerminalOpen=`SET_TERMINAL_OPEN`,e.QueueTerminalCommand=`QUEUE_TERMINAL_COMMAND`,e.ClearQueuedTerminalCommand=`CLEAR_QUEUED_TERMINAL_COMMAND`,e.AppendTerminalLine=`APPEND_TERMINAL_LINE`,e.ClearTerminalOutput=`CLEAR_TERMINAL_OUTPUT`,e.SetTerminalHeight=`SET_TERMINAL_HEIGHT`,e.SetTerminalCwd=`SET_TERMINAL_CWD`,e.SetTerminalRunning=`SET_TERMINAL_RUNNING`,e.SetTerminalHistory=`SET_TERMINAL_HISTORY`,e.SetTerminalHistoryIndex=`SET_TERMINAL_HISTORY_INDEX`,e.UpdateThreadTitle=`UPDATE_THREAD_TITLE`,e.ClearFocusChatInput=`CLEAR_FOCUS_CHAT_INPUT`,e.ClearMessages=`CLEAR_MESSAGES`,e.UpdateToolCallProgress=`UPDATE_TOOL_CALL_PROGRESS`,e.UpdateToolExecutionOutput=`UPDATE_TOOL_EXECUTION_OUTPUT`,e.AppendToolExecutionOutput=`APPEND_TOOL_EXECUTION_OUTPUT`,e.ClearToolCallProgress=`CLEAR_TOOL_CALL_PROGRESS`,e.SetPendingChatMessage=`SET_PENDING_CHAT_MESSAGE`,e.ClearPendingChatMessage=`CLEAR_PENDING_CHAT_MESSAGE`,e.IncrementStreamEventCount=`INCREMENT_STREAM_EVENT_COUNT`,e.SetDiffComments=`SET_DIFF_COMMENTS`,e.ClearSelection=`CLEAR_SELECTION`,e.SetChatInputDraft=`SET_CHAT_INPUT_DRAFT`,e.ClearChatInputDraft=`CLEAR_CHAT_INPUT_DRAFT`,e}({}),li={isStreaming:!1,streamingContent:``,streamingThinking:``,streamingSegments:[],streamingModel:``,streamingEventCount:0};function ui(){return{...li,streamingSegments:[]}}function di(e,t){return t?e[t]??ui():ui()}function fi(e,t){return t.threadId??e.selectedThreadId}function pi(e,t,n,r=!1){if(!t)return{...e,...n,toolCallProgress:r?{}:e.toolCallProgress};let i={...e.threadStreamingStates,[t]:n};return t===e.selectedThreadId?{...e,...n,threadStreamingStates:i,toolCallProgress:r?{}:e.toolCallProgress}:{...e,threadStreamingStates:i}}var mi={projects:[],projectsLoading:!0,selectedThreadId:null,selectedProjectId:null,messages:[],messagesLoaded:!1,queuedChatMessages:[],isStreaming:!1,streamingContent:``,streamingThinking:``,streamingSegments:[],streamingModel:``,streamingEventCount:0,threadStreamingStates:{},projectModelSelections:{},sidebarOpen:!0,isCreatingProject:!1,configUpdatedAt:0,processingThreadIds:[],completedThreadIds:[],deletingThreadIds:[],deletingProjectIds:[],commandOutput:``,isRunningCommand:!1,terminalStates:{},focusChatInput:!1,toolCallProgress:{},pendingChatMessage:null,diffComments:{},chatInputDrafts:{}};function hi(e,t){switch(t.type){case`SET_PROJECTS`:{let n={...e.projectModelSelections};for(let e of t.projects)for(let t of e.threads){if(!t.model)continue;let e=n[t.threadId];n[t.threadId]={id:t.model,provider:t.modelProvider,name:e?.name??t.model,description:e?.description??``,context_length:e?.context_length,contextWindow:e?.contextWindow,features:e?.features,input_modalities:e?.input_modalities,max_output:e?.max_output,pricing:e?.pricing,tarsk_use:e?.tarsk_use,coding_index:e?.coding_index,supportsImages:e?.supportsImages}}return{...e,projects:t.projects,projectModelSelections:n}}case`SET_PROJECTS_LOADING`:return{...e,projectsLoading:t.projectsLoading};case`SELECT_THREAD`:{let n=di(e.threadStreamingStates,t.threadId);return{...e,...n,selectedThreadId:t.threadId,selectedProjectId:t.projectId,messages:t.initialMessages??[],messagesLoaded:!1,focusChatInput:t.focusInput??!1}}case`CLEAR_SELECTION`:return{...e,...ui(),selectedThreadId:null,selectedProjectId:null,messages:[],messagesLoaded:!1};case`SET_MESSAGES`:return{...e,messages:t.messages,messagesLoaded:!0};case`ADD_MESSAGE`:return t.threadId&&t.threadId!==e.selectedThreadId?e:{...e,messages:[...e.messages,t.message]};case`ENQUEUE_CHAT_MESSAGE`:return{...e,queuedChatMessages:[...e.queuedChatMessages,t.message]};case`REMOVE_QUEUED_CHAT_MESSAGE`:return{...e,queuedChatMessages:e.queuedChatMessages.filter(e=>e.id!==t.queuedMessageId)};case`SET_STREAMING`:{let n=fi(e,t);return pi(e,n,{...di(e.threadStreamingStates,n),isStreaming:t.isStreaming})}case`APPEND_STREAM_CONTENT`:{let n=fi(e,t),r=di(e.threadStreamingStates,n);return pi(e,n,{...r,streamingContent:r.streamingContent+t.content})}case`SET_STREAM_CONTENT`:{let n=fi(e,t),r=di(e.threadStreamingStates,n),i=ni(r.streamingSegments,t.content);return pi(e,n,{...r,streamingContent:t.content,streamingSegments:i})}case`APPEND_STREAM_THINKING`:{let n=fi(e,t),r=di(e.threadStreamingStates,n);return pi(e,n,{...r,streamingThinking:r.streamingThinking+t.content})}case`INCREMENT_STREAM_EVENT_COUNT`:{let n=fi(e,t),r=di(e.threadStreamingStates,n);return pi(e,n,{...r,streamingEventCount:r.streamingEventCount+1})}case`APPEND_STREAM_CHUNK`:{let n=fi(e,t),r=di(e.threadStreamingStates,n);return pi(e,n,{...r,streamingSegments:t.segments,streamingContent:t.chunkType===`content`?r.streamingContent+t.content:r.streamingContent,streamingThinking:t.chunkType===`thinking`?r.streamingThinking+t.content:r.streamingThinking})}case`SET_STREAM_MODEL`:{let n=fi(e,t);return pi(e,n,{...di(e.threadStreamingStates,n),streamingModel:t.model})}case`SET_PROJECT_MODEL`:return console.log(`[Store] SetProjectModel action:`,{threadId:t.threadId,model:{id:t.model.id,provider:t.model.provider}}),{...e,projects:e.projects.map(e=>({...e,threads:e.threads.map(e=>e.threadId===t.threadId?{...e,model:t.model.id,modelProvider:t.model.provider}:e)})),projectModelSelections:{...e.projectModelSelections,[t.threadId]:t.model}};case`RESET_STREAM`:return pi(e,fi(e,t),ui(),!0);case`STOP_STREAM`:{let n=fi(e,t);return pi(e,n,{...di(e.threadStreamingStates,n),isStreaming:!1})}case`TOGGLE_SIDEBAR`:return{...e,sidebarOpen:!e.sidebarOpen};case`CLOSE_SIDEBAR`:return e.sidebarOpen?{...e,sidebarOpen:!1}:e;case`SET_CREATING_PROJECT`:return{...e,isCreatingProject:t.isCreating};case`CONFIG_UPDATED`:return{...e,configUpdatedAt:Date.now()};case`SET_PROCESSING_THREADS`:return{...e,processingThreadIds:t.threadIds};case`ADD_PROCESSING_THREAD`:return{...e,processingThreadIds:e.processingThreadIds.includes(t.threadId)?e.processingThreadIds:[...e.processingThreadIds,t.threadId]};case`REMOVE_PROCESSING_THREAD`:return{...e,processingThreadIds:e.processingThreadIds.filter(e=>e!==t.threadId)};case`ADD_CREATING_PROJECT`:return{...e,projects:[...e.projects,{projectId:t.projectId,name:t.projectName,gitUrl:t.gitUrl,threads:[{threadId:t.threadId,title:`thread-1`,path:``,currentBranch:``}]}]};case`ADD_CREATING_THREAD`:return{...e,projects:e.projects.map(e=>e.projectId===t.projectId?{...e,threads:[...e.threads,{threadId:t.threadId,title:t.title,path:``,currentBranch:``}]}:e)};case`REMOVE_CREATING_PROJECT`:return{...e,projects:e.projects.filter(e=>e.projectId!==t.projectId)};case`REMOVE_CREATING_THREAD`:return{...e,projects:e.projects.map(e=>e.projectId===t.projectId?{...e,threads:e.threads.filter(e=>e.threadId!==t.threadId)}:e)};case`MARK_THREAD_COMPLETED`:return{...e,completedThreadIds:e.completedThreadIds.includes(t.threadId)?e.completedThreadIds:[...e.completedThreadIds,t.threadId]};case`CLEAR_THREAD_COMPLETED`:return{...e,completedThreadIds:e.completedThreadIds.filter(e=>e!==t.threadId)};case`ADD_DELETING_THREAD`:return{...e,deletingThreadIds:e.deletingThreadIds.includes(t.threadId)?e.deletingThreadIds:[...e.deletingThreadIds,t.threadId]};case`REMOVE_DELETING_THREAD`:return{...e,deletingThreadIds:e.deletingThreadIds.filter(e=>e!==t.threadId)};case`ADD_DELETING_PROJECT`:return{...e,deletingProjectIds:e.deletingProjectIds.includes(t.projectId)?e.deletingProjectIds:[...e.deletingProjectIds,t.projectId]};case`REMOVE_DELETING_PROJECT`:return{...e,deletingProjectIds:e.deletingProjectIds.filter(e=>e!==t.projectId)};case`APPEND_COMMAND_OUTPUT`:return{...e,commandOutput:e.commandOutput+t.content};case`SET_RUNNING_COMMAND`:return{...e,isRunningCommand:t.isRunning};case`CLEAR_COMMAND_OUTPUT`:return{...e,commandOutput:``};case`TOGGLE_TERMINAL`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,open:!r.open}}}}case`SET_TERMINAL_OPEN`:{let n=t.threadId??`default`,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,open:t.open}}}}case`QUEUE_TERMINAL_COMMAND`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,queuedRelativeFolder:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,queuedCommand:t.command,queuedRelativeFolder:t.relativeFolder??null,open:!0}}}}case`CLEAR_QUEUED_TERMINAL_COMMAND`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,queuedCommand:null}}}}case`APPEND_TERMINAL_LINE`:{let n=t.threadId??`default`,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,outputLines:[...r.outputLines,t.line]}}}}case`CLEAR_TERMINAL_OUTPUT`:{let n=t.threadId??`default`,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,outputLines:[]}}}}case`SET_TERMINAL_HEIGHT`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,height:t.height}}}}case`SET_TERMINAL_CWD`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,cwd:t.cwd}}}}case`SET_TERMINAL_RUNNING`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,isRunning:t.isRunning}}}}case`SET_TERMINAL_HISTORY`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,history:t.history}}}}case`SET_TERMINAL_HISTORY_INDEX`:{let n=t.threadId,r=e.terminalStates[n]??{open:!1,queuedCommand:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};return{...e,terminalStates:{...e.terminalStates,[n]:{...r,historyIndex:t.index}}}}case`UPDATE_THREAD_TITLE`:return{...e,projects:e.projects.map(e=>e.projectId===t.projectId?{...e,threads:e.threads.map(e=>e.threadId===t.threadId?{...e,title:t.title}:e)}:e)};case`CLEAR_FOCUS_CHAT_INPUT`:return{...e,focusChatInput:!1};case`CLEAR_MESSAGES`:return{...e,messages:[]};case`UPDATE_TOOL_CALL_PROGRESS`:{let n=e.toolCallProgress[t.toolCallId];return{...e,toolCallProgress:{...e.toolCallProgress,[t.toolCallId]:{...n,...t.progress}}}}case`UPDATE_TOOL_EXECUTION_OUTPUT`:{let n=e.toolCallProgress[t.toolCallId];return{...e,toolCallProgress:{...e.toolCallProgress,[t.toolCallId]:{toolCallId:t.toolCallId,toolName:t.toolName??n?.toolName??``,delta:n?.delta??``,partial:n?.partial??{role:`tool`,content:[]},executionOutput:t.executionOutput}}}}case`APPEND_TOOL_EXECUTION_OUTPUT`:{let n=e.toolCallProgress[t.toolCallId],r=n?.executionOutput??``;return{...e,toolCallProgress:{...e.toolCallProgress,[t.toolCallId]:{toolCallId:t.toolCallId,toolName:t.toolName??n?.toolName??`agent`,delta:n?.delta??``,partial:n?.partial??{role:`tool`,content:[]},executionOutput:r+t.delta}}}}case`CLEAR_TOOL_CALL_PROGRESS`:{if(!t.toolCallId)return{...e,toolCallProgress:{}};let{[t.toolCallId]:n,...r}=e.toolCallProgress;return{...e,toolCallProgress:r}}case`SET_PENDING_CHAT_MESSAGE`:return{...e,pendingChatMessage:t.message};case`CLEAR_PENDING_CHAT_MESSAGE`:return{...e,pendingChatMessage:null};case`SET_DIFF_COMMENTS`:return{...e,diffComments:{...e.diffComments,[t.threadId]:t.comments}};case`SET_CHAT_INPUT_DRAFT`:return{...e,chatInputDrafts:{...e.chatInputDrafts,[t.threadId]:t.draft}};case`CLEAR_CHAT_INPUT_DRAFT`:{let{[t.threadId]:n,...r}=e.chatInputDrafts;return{...e,chatInputDrafts:r}}default:return e}}function gi(e=mi){let t=e,n=new Set;function r(){return t}function i(e){let r=hi(t,e);if(r!==t){t=r;for(let e of n)e()}}function a(e){return n.add(e),function(){n.delete(e)}}return{getState:r,dispatch:i,subscribe:a}}var _i=(0,Y.createContext)(null);function vi(){let e=(0,Y.useContext)(_i);if(!e)throw Error(`useAppStore must be used within an AppStoreContext.Provider`);return e}function Q(e){let t=(0,X.c)(3),n=vi(),r;t[0]!==e||t[1]!==n?(r=function(){return e(n.getState())},t[0]=e,t[1]=n,t[2]=r):r=t[2];let i=r;return(0,Y.useSyncExternalStore)(n.subscribe,i,i)}function yi(){return vi().dispatch}var bi={open:!1,queuedCommand:null,queuedRelativeFolder:null,outputLines:[],height:300,history:[],historyIndex:-1,cwd:`.`,isRunning:!1};function xi(e){let t=(0,X.c)(8),n=yi(),r;t[0]===e?r=t[1]:(r=t=>(e?t.terminalStates[e]:void 0)??bi,t[0]=e,t[1]=r);let i=Q(r),a;t[2]!==n||t[3]!==e?(a=t=>{e&&n({...t,threadId:e})},t[2]=n,t[3]=e,t[4]=a):a=t[4];let o=a,s;return t[5]!==o||t[6]!==i?(s={terminalState:i,dispatch:o},t[5]=o,t[6]=i,t[7]=s):s=t[7],s}var $=yt(),Si=Y.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(`textarea`,{className:a,ref:t,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Si.displayName=`Textarea`;function Ci(e){let t=(0,X.c)(47),{open:n,onOpenChange:r,feedbackName:i,onFeedbackNameChange:a,feedbackEmail:o,onFeedbackEmailChange:c,feedbackText:l,onFeedbackTextChange:u,loadingFeedbackUser:d,submittingFeedback:f,onSubmit:p}=e,m;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsxs)(xt,{children:[(0,$.jsx)(z,{children:`Send Feedback`}),(0,$.jsx)(Ct,{children:`Share feedback about Tarsk.`})]}),t[0]=m):m=t[0];let h;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(yn,{htmlFor:`feedback-name`,children:`Name`}),t[1]=h):h=t[1];let v;t[2]===a?v=t[3]:(v=e=>a(e.target.value),t[2]=a,t[3]=v);let y=f||d,x;t[4]!==i||t[5]!==v||t[6]!==y?(x=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[h,(0,$.jsx)(b,{id:`feedback-name`,value:i,onChange:v,placeholder:`Your name`,disabled:y})]}),t[4]=i,t[5]=v,t[6]=y,t[7]=x):x=t[7];let S;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(yn,{htmlFor:`feedback-email`,children:`Email`}),t[8]=S):S=t[8];let C;t[9]===c?C=t[10]:(C=e=>c(e.target.value),t[9]=c,t[10]=C);let w=f||d,T;t[11]!==o||t[12]!==C||t[13]!==w?(T=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[S,(0,$.jsx)(b,{id:`feedback-email`,type:`email`,value:o,onChange:C,placeholder:`you@example.com`,disabled:w})]}),t[11]=o,t[12]=C,t[13]=w,t[14]=T):T=t[14];let E;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,$.jsx)(yn,{htmlFor:`feedback-text`,children:`Feedback`}),t[15]=E):E=t[15];let D;t[16]===u?D=t[17]:(D=e=>u(e.target.value),t[16]=u,t[17]=D);let O;t[18]!==l||t[19]!==f||t[20]!==D?(O=(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[E,(0,$.jsx)(Si,{id:`feedback-text`,value:l,onChange:D,placeholder:`Tell us what you think...`,className:`min-h-32`,disabled:f})]}),t[18]=l,t[19]=f,t[20]=D,t[21]=O):O=t[21];let k;t[22]!==O||t[23]!==x||t[24]!==T?(k=(0,$.jsxs)(`div`,{className:`grid gap-4 py-2`,children:[x,T,O]}),t[22]=O,t[23]=x,t[24]=T,t[25]=k):k=t[25];let A;t[26]===r?A=t[27]:(A=()=>r(!1),t[26]=r,t[27]=A);let j;t[28]!==f||t[29]!==A?(j=(0,$.jsx)(U,{variant:`outline`,onClick:A,disabled:f,children:`Cancel`}),t[28]=f,t[29]=A,t[30]=j):j=t[30];let M;t[31]===f?M=t[32]:(M=f?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{className:`mr-2 h-4 w-4 animate-spin`}),`Sending...`]}):`Send`,t[31]=f,t[32]=M);let N;t[33]!==p||t[34]!==f||t[35]!==M?(N=(0,$.jsx)(U,{onClick:p,disabled:f,children:M}),t[33]=p,t[34]=f,t[35]=M,t[36]=N):N=t[36];let P;t[37]!==j||t[38]!==N?(P=(0,$.jsxs)(s,{children:[j,N]}),t[37]=j,t[38]=N,t[39]=P):P=t[39];let F;t[40]!==k||t[41]!==P?(F=(0,$.jsxs)(H,{className:`max-w-xl`,children:[m,k,P]}),t[40]=k,t[41]=P,t[42]=F):F=t[42];let I;return t[43]!==r||t[44]!==n||t[45]!==F?(I=(0,$.jsx)(g,{open:n,onOpenChange:r,children:F}),t[43]=r,t[44]=n,t[45]=F,t[46]=I):I=t[46],I}function wi(e){let t=(0,X.c)(30),{node:n,level:r,renderNode:i,defaultOpen:a,indent:o,childContainerClassName:s,openState:c,onToggle:l,forceOpenIds:u}=e,d=!!(n.children&&n.children.length>0),f,p,m;if(t[0]!==a||t[1]!==u||t[2]!==d||t[3]!==r||t[4]!==n||t[5]!==l||t[6]!==c||t[7]!==i){f=u?.has(n.id)||(c[n.id]??a);let e;t[11]!==n.id||t[12]!==l?(e=()=>l(n.id),t[11]=n.id,t[12]=l,t[13]=e):e=t[13];let o=e;p=`min-w-0`,m=i(n,{isOpen:f,level:r,toggle:o,hasChildren:d}),t[0]=a,t[1]=u,t[2]=d,t[3]=r,t[4]=n,t[5]=l,t[6]=c,t[7]=i,t[8]=f,t[9]=p,t[10]=m}else f=t[8],p=t[9],m=t[10];let h;t[14]!==s||t[15]!==a||t[16]!==u||t[17]!==d||t[18]!==o||t[19]!==f||t[20]!==r||t[21]!==n.children||t[22]!==l||t[23]!==c||t[24]!==i?(h=d&&f&&(0,$.jsx)(`div`,{style:{paddingLeft:o},className:s,children:n.children.map(e=>(0,$.jsx)(wi,{node:e,level:r+1,renderNode:i,defaultOpen:a,indent:o,childContainerClassName:s,openState:c,onToggle:l,forceOpenIds:u},e.id))}),t[14]=s,t[15]=a,t[16]=u,t[17]=d,t[18]=o,t[19]=f,t[20]=r,t[21]=n.children,t[22]=l,t[23]=c,t[24]=i,t[25]=h):h=t[25];let g;return t[26]!==p||t[27]!==m||t[28]!==h?(g=(0,$.jsxs)(`div`,{className:p,children:[m,h]}),t[26]=p,t[27]=m,t[28]=h,t[29]=g):g=t[29],g}function Ti(e){let t=(0,X.c)(27),{nodes:n,renderNode:r,resetKey:i,defaultOpen:a,forceOpenIds:o,indent:s,childContainerClassName:c,className:l}=e,u=a===void 0?!1:a,d=s===void 0?16:s,f;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f={},t[0]=f):f=t[0];let[p,m]=(0,Y.useState)(f),[h,g]=(0,Y.useState)(i);i!==h&&(g(i),m({}));let _;t[1]===o?_=t[2]:(_=o?new Set(o):void 0,t[1]=o,t[2]=_);let v=_,y;t[3]===u?y=t[4]:(y=e=>{m(t=>({...t,[e]:!(t[e]??u)}))},t[3]=u,t[4]=y);let b=y,x;t[5]===l?x=t[6]:(x=q(`min-w-0`,l),t[5]=l,t[6]=x);let S;if(t[7]!==c||t[8]!==u||t[9]!==v||t[10]!==b||t[11]!==d||t[12]!==n||t[13]!==p||t[14]!==r){let e;t[16]!==c||t[17]!==u||t[18]!==v||t[19]!==b||t[20]!==d||t[21]!==p||t[22]!==r?(e=e=>(0,$.jsx)(wi,{node:e,level:0,renderNode:r,defaultOpen:u,indent:d,childContainerClassName:c,openState:p,onToggle:b,forceOpenIds:v},e.id),t[16]=c,t[17]=u,t[18]=v,t[19]=b,t[20]=d,t[21]=p,t[22]=r,t[23]=e):e=t[23],S=n.map(e),t[7]=c,t[8]=u,t[9]=v,t[10]=b,t[11]=d,t[12]=n,t[13]=p,t[14]=r,t[15]=S}else S=t[15];let C;return t[24]!==x||t[25]!==S?(C=(0,$.jsx)(`div`,{className:x,children:S}),t[24]=x,t[25]=S,t[26]=C):C=t[26],C}var Ei=1,Di=1e6,Oi=0;function ki(){return Oi=(Oi+1)%(2**53-1),Oi.toString()}var Ai=new Map,ji=e=>{if(Ai.has(e))return;let t=setTimeout(()=>{Ai.delete(e),Fi({type:`REMOVE_TOAST`,toastId:e})},Di);Ai.set(e,t)},Mi=(e,t)=>{switch(t.type){case`ADD_TOAST`:return{...e,toasts:[t.toast,...e.toasts].slice(0,Ei)};case`UPDATE_TOAST`:return{...e,toasts:e.toasts.map(e=>e.id===t.toast.id?{...e,...t.toast}:e)};case`DISMISS_TOAST`:{let{toastId:n}=t;return n?ji(n):e.toasts.forEach(e=>{ji(e.id)}),{...e,toasts:e.toasts.map(e=>e.id===n||n===void 0?{...e,open:!1}:e)}}case`REMOVE_TOAST`:return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(e=>e.id!==t.toastId)}}},Ni=[],Pi={toasts:[]};function Fi(e){Pi=Mi(Pi,e),Ni.forEach(e=>{e(Pi)})}function Ii({...e}){let t=ki(),n=e=>Fi({type:`UPDATE_TOAST`,toast:{...e,id:t}}),r=()=>Fi({type:`DISMISS_TOAST`,toastId:t});return Fi({type:`ADD_TOAST`,toast:{...e,id:t,open:!0,onOpenChange:e=>{e||r()}}}),{id:t,dismiss:r,update:n}}function Li(){let e=(0,X.c)(4),[t,n]=Y.useState(Pi),r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>(Ni.push(n),()=>{let e=Ni.indexOf(n);e>-1&&Ni.splice(e,1)}),i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Y.useEffect(r,i);let a;return e[2]===t?a=e[3]:(a={...t,toast:Ii,dismiss:Ri},e[2]=t,e[3]=a),a}function Ri(e){return Fi({type:`DISMISS_TOAST`,toastId:e})}function zi(){let[e,t]=(0,Y.useState)(!1),[n,r]=(0,Y.useState)(``),[i,a]=(0,Y.useState)(``),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{if(!e)return;let t=!0;return l(!0),Bt().then(e=>{t&&(r(t=>t||e.name),a(t=>t||e.email))}).catch(()=>{t&&Ii({title:`Could not load git details`,description:`You can still submit feedback by entering your name and email manually.`,variant:`destructive`})}).finally(()=>{t&&l(!1)}),()=>{t=!1}},[e]),{showFeedback:e,feedbackName:n,setFeedbackName:r,feedbackEmail:i,setFeedbackEmail:a,feedbackText:o,setFeedbackText:s,loadingFeedbackUser:c,submittingFeedback:u,handleFeedbackDialogChange:e=>{t(e),e||s(``)},handleSubmitFeedback:async()=>{let e=o.trim();if(!e){Ii({title:`Feedback required`,description:`Please enter your feedback before submitting.`,variant:`destructive`});return}d(!0);try{await ve(`api/feedback`,{name:n.trim(),email:i.trim(),feedback:e}),Ii({title:`Feedback sent`,description:`Thanks for sharing your feedback.`}),s(``),t(!1)}catch(e){Ii({title:`Failed to send feedback`,description:e instanceof Error?e.message:`Please try again.`,variant:`destructive`})}finally{d(!1)}}}}var Bi=Cr(e=>(0,$.jsxs)(`div`,{className:e.v0,style:e.v1,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-sidebar-border px-4 py-3 h-[61px]`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`flex h-7 w-7 items-center justify-center overflow-hidden rounded-md border border-sidebar-border shadow-sm`,children:(0,$.jsx)(`img`,{src:`/tarsk.svg`,alt:`Tarsk`,className:e.v2,onClick:e.v3})}),e.v4]}),e.v5]}),e.v6,e.v7]}),{name:`SidePanelContainer_1`,portals:[`v4`,`v5`,`v6`,`v7`]}),Vi=function(e){let t=(0,X.c)(25),{children:n,collapsed:r,title:i,onTitleClose:a,subtitle:s,headerAction:c,footer:l,onLogoClick:u}=e,d,f,p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f=o(),d=Bi,p=q(`flex flex-col select-none bg-sidebar text-sidebar-foreground mx-2.5 md:mr-10 rounded-3xl shadow-2xl overflow-hidden`,f&&`mt-8`),t[0]=d,t[1]=f,t[2]=p):(d=t[0],f=t[1],p=t[2]);let m;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(m={containerType:`inline-size`,height:f?`calc(100% - 42px)`:`calc(100% - 12px)`},t[3]=m):m=t[3];let h=u&&`cursor-pointer`,g;t[4]===h?g=t[5]:(g=q(`h-full w-full`,h),t[4]=h,t[5]=g);let _;t[6]!==r||t[7]!==s?(_=!r&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(`span`,{className:J.sectionTitle,children:`Tarsk`}),s&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(en,{className:`h-3 w-3 text-sidebar-foreground/60`}),(0,$.jsx)(`span`,{className:q(J.label,`text-sidebar-foreground/80`),children:s})]})]}),t[6]=r,t[7]=s,t[8]=_):_=t[8];let v;t[9]!==r||t[10]!==c||t[11]!==a||t[12]!==i?(v=(i??a??c)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 ml-auto`,children:[c&&!r&&c,i&&(0,$.jsx)(`span`,{className:q(J.compact,`font-medium text-sidebar-foreground/80`),children:i}),a&&(0,$.jsxs)(U,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-sidebar-foreground`,onClick:a,children:[(0,$.jsx)(j,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]}),t[9]=r,t[10]=c,t[11]=a,t[12]=i,t[13]=v):v=t[13];let y;t[14]===n?y=t[15]:(y=(0,$.jsx)(Xe,{className:`flex-1`,children:n}),t[14]=n,t[15]=y);let b;t[16]===l?b=t[17]:(b=l&&(0,$.jsx)(`div`,{className:`border-t border-sidebar-border`,children:l}),t[16]=l,t[17]=b);let x;return t[18]!==u||t[19]!==g||t[20]!==_||t[21]!==v||t[22]!==y||t[23]!==b?(x=(0,$.jsx)(d,{v0:p,v1:m,v2:g,v3:u,v4:_,v5:v,v6:y,v7:b}),t[18]=u,t[19]=g,t[20]=_,t[21]=v,t[22]=y,t[23]=b,t[24]=x):x=t[24],x};function Hi(e){let t=(0,X.c)(80),{projects:r,selectedThreadId:i,selectedProjectId:a,processingThreadIds:o,completedThreadIds:s,deletingThreadIds:c,deletingProjectIds:l,onSelectThread:u,onCreateProject:f,onCreateThread:p,onDeleteThread:m,onDeleteProject:h,onDeselect:g,collapsed:v,updateAvailable:y,updatingApp:b,onUpdateApp:x,expandProjectId:S}=e,C=$n(),{showFeedback:w,feedbackName:T,setFeedbackName:E,feedbackEmail:D,setFeedbackEmail:O,feedbackText:k,setFeedbackText:A,loadingFeedbackUser:j,submittingFeedback:M,handleFeedbackDialogChange:N,handleSubmitFeedback:P}=zi(),F;t[0]===r?F=t[1]:(F=r.map(Ui),t[0]=r,t[1]=F);let I=F,L;t[2]!==v||t[3]!==f?(L=!v&&(0,$.jsxs)(U,{variant:`outline`,size:`sm`,className:`gap-2`,onClick:f,children:[(0,$.jsx)(sn,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:`New Project`})]}),t[2]=v,t[3]=f,t[4]=L):L=t[4];let R;t[5]!==v||t[6]!==x||t[7]!==y||t[8]!==b?(R=y&&(0,$.jsxs)(U,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2 text-emerald-600 dark:text-emerald-400`,onClick:x,disabled:b,children:[b?(0,$.jsx)(_,{className:`h-4 w-4 animate-spin`}):(0,$.jsx)(Ie,{className:`h-4 w-4`}),!v&&(0,$.jsx)(`span`,{className:`truncate`,children:b?`Updating...`:`Update to Latest`})]}),t[5]=v,t[6]=x,t[7]=y,t[8]=b,t[9]=R):R=t[9];let ee;t[10]===C?ee=t[11]:(ee=()=>void C(`/settings/general`),t[10]=C,t[11]=ee);let te;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(te=(0,$.jsx)(n,{className:`h-4 w-4`}),t[12]=te):te=t[12];let z;t[13]===v?z=t[14]:(z=!v&&(0,$.jsx)(`span`,{className:`truncate`,children:`Settings`}),t[13]=v,t[14]=z);let ne;t[15]!==ee||t[16]!==z?(ne=(0,$.jsxs)(U,{variant:`ghost`,size:`sm`,className:`flex-1 justify-start gap-2 text-sidebar-foreground`,onClick:ee,children:[te,z]}),t[15]=ee,t[16]=z,t[17]=ne):ne=t[17];let B;t[18]===N?B=t[19]:(B=()=>N(!0),t[18]=N,t[19]=B);let re,V;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(V=(0,$.jsx)(d,{className:`h-4 w-4`}),re=(0,$.jsx)(`span`,{className:`sr-only`,children:`Feedback`}),t[20]=re,t[21]=V):(re=t[20],V=t[21]);let ie;t[22]===B?ie=t[23]:(ie=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(U,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,onClick:B,children:[V,re]})}),t[22]=B,t[23]=ie);let ae;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(ae=(0,$.jsx)(K,{children:`Send feedback to the Tarsk team`}),t[24]=ae):ae=t[24];let oe;t[25]===ie?oe=t[26]:(oe=(0,$.jsx)(Nt,{children:(0,$.jsxs)(W,{children:[ie,ae]})}),t[25]=ie,t[26]=oe);let H;t[27]!==oe||t[28]!==ne?(H=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[ne,oe]}),t[27]=oe,t[28]=ne,t[29]=H):H=t[29];let se;t[30]!==H||t[31]!==R?(se=(0,$.jsxs)(`div`,{className:`px-3 py-2 flex flex-col gap-1`,children:[R,H]}),t[30]=H,t[31]=R,t[32]=se):se=t[32];let ce;t[33]===r.length?ce=t[34]:(ce=r.length===0&&(0,$.jsx)(`p`,{className:q(J.compact,`px-3 py-6 text-center text-muted-foreground`),children:`No projects yet. Clone a repository to get started.`}),t[33]=r.length,t[34]=ce);let le;t[35]===S?le=t[36]:(le=S?[S]:void 0,t[35]=S,t[36]=le);let ue;t[37]!==s||t[38]!==l||t[39]!==c||t[40]!==C||t[41]!==p||t[42]!==h||t[43]!==m||t[44]!==u||t[45]!==o||t[46]!==r||t[47]!==a||t[48]!==i?(ue=(e,t)=>{let{isOpen:n,toggle:d}=t;return e.kind===`project`?(0,$.jsx)(Wi,{project:e.project,isOpen:n,onToggle:d,isDeletingProject:l.includes(e.project.projectId),isSelected:a?e.project.projectId===a:!1,onCreateThread:p,onDeleteProject:h,onProjectSettings:e=>void C(`/settings/project/${e}`),hasSelectedThread:e.project.threads.some(e=>e.threadId===i)}):(0,$.jsx)(Gi,{thread:e.thread,projectId:e.projectId,selectedThreadId:i,isProcessing:o.includes(e.thread.threadId),isDeleting:c.includes(e.thread.threadId),isCompleted:s.includes(e.thread.threadId),projectTitlePrefix:`${ot(r.find(t=>t.projectId===e.projectId))} - `,onSelectThread:u,onDeleteThread:m})},t[37]=s,t[38]=l,t[39]=c,t[40]=C,t[41]=p,t[42]=h,t[43]=m,t[44]=u,t[45]=o,t[46]=r,t[47]=a,t[48]=i,t[49]=ue):ue=t[49];let de;t[50]!==I||t[51]!==le||t[52]!==ue?(de=(0,$.jsx)(Ti,{nodes:I,defaultOpen:!0,forceOpenIds:le,childContainerClassName:`ml-4 border-l border-sidebar-border pl-2`,renderNode:ue}),t[50]=I,t[51]=le,t[52]=ue,t[53]=de):de=t[53];let fe;t[54]!==ce||t[55]!==de?(fe=(0,$.jsx)(`div`,{className:`flex-1 w-full`,children:(0,$.jsxs)(`div`,{className:`px-2 py-2 w-full max-w-full overflow-hidden`,children:[ce,de]})}),t[54]=ce,t[55]=de,t[56]=fe):fe=t[56];let pe;t[57]!==v||t[58]!==g||t[59]!==se||t[60]!==L||t[61]!==fe?(pe=(0,$.jsx)(Vi,{collapsed:v,onLogoClick:g,headerAction:L,footer:se,children:fe}),t[57]=v,t[58]=g,t[59]=se,t[60]=L,t[61]=fe,t[62]=pe):pe=t[62];let me;t[63]===P?me=t[64]:(me=()=>void P(),t[63]=P,t[64]=me);let he;t[65]!==D||t[66]!==T||t[67]!==k||t[68]!==N||t[69]!==j||t[70]!==O||t[71]!==E||t[72]!==A||t[73]!==w||t[74]!==M||t[75]!==me?(he=(0,$.jsx)(Ci,{open:w,onOpenChange:N,feedbackName:T,onFeedbackNameChange:E,feedbackEmail:D,onFeedbackEmailChange:O,feedbackText:k,onFeedbackTextChange:A,loadingFeedbackUser:j,submittingFeedback:M,onSubmit:me}),t[65]=D,t[66]=T,t[67]=k,t[68]=N,t[69]=j,t[70]=O,t[71]=E,t[72]=A,t[73]=w,t[74]=M,t[75]=me,t[76]=he):he=t[76];let ge;return t[77]!==pe||t[78]!==he?(ge=(0,$.jsxs)($.Fragment,{children:[pe,he]}),t[77]=pe,t[78]=he,t[79]=ge):ge=t[79],ge}function Ui(e,t){return{id:e.projectId||e.gitUrl||`project-${t}`,kind:`project`,project:e,children:e.threads.map((t,n)=>({id:t.threadId||`${e.projectId}-${t.title||n}`,kind:`thread`,thread:t,projectId:e.projectId}))}}function Wi(e){let t=(0,X.c)(33),{project:r,isOpen:i,onToggle:a,isDeletingProject:o,hasSelectedThread:s,isSelected:l,onCreateThread:u,onDeleteProject:d,onProjectSettings:f}=e,p;t[0]===r?p=t[1]:(p=ot(r),t[0]=r,t[1]=p);let m=p,h=s||l,g=i&&`rotate-90`,v;t[2]===g?v=t[3]:(v=q(`h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform`,g),t[2]=g,t[3]=v);let y;t[4]===v?y=t[5]:(y=(0,$.jsx)(en,{className:v}),t[4]=v,t[5]=y);let b;t[6]===r.gitUrl?b=t[7]:(b=r.gitUrl?(0,$.jsx)(D,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}):(0,$.jsx)(c,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),t[6]=r.gitUrl,t[7]=b);let x=(s||l)&&`font-bold text-foreground`,S;t[8]===x?S=t[9]:(S=q(`min-w-0 truncate transition-all block`,x),t[8]=x,t[9]=S);let C;t[10]!==m||t[11]!==S?(C=(0,$.jsx)(`span`,{className:S,children:m}),t[10]=m,t[11]=S,t[12]=C):C=t[12];let w;t[13]!==y||t[14]!==b||t[15]!==C?(w=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5 w-0`,children:[y,b,C]}),t[13]=y,t[14]=b,t[15]=C,t[16]=w):w=t[16];let T;t[17]!==a||t[18]!==w?(T=(0,$.jsx)(`button`,{type:`button`,className:`min-w-0`,onClick:a,children:w}),t[17]=a,t[18]=w,t[19]=T):T=t[19];let E;t[20]!==T||t[21]!==h?(E=(0,$.jsx)(mr,{selected:h,noBackground:!0,className:`h-9 min-w-0 flex-1`,asChild:!0,children:T}),t[20]=T,t[21]=h,t[22]=E):E=t[22];let O;t[23]!==o||t[24]!==u||t[25]!==d||t[26]!==f||t[27]!==r.projectId||t[28]!==r.threads?(O=(0,$.jsx)(`div`,{className:`flex shrink-0 items-center`,children:o?(0,$.jsx)(_,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground mr-1`}):(0,$.jsxs)(Nt,{children:[(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(U,{variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0 hidden can-hover:group-hover:flex items-center justify-center`,onClick:()=>f(r.projectId),children:[(0,$.jsx)(n,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Project settings`})]})}),(0,$.jsx)(K,{side:`right`,children:`Project settings`})]}),(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(U,{variant:`action`,size:`icon-sm`,className:`shrink-0 hidden can-hover:group-hover:flex items-center justify-center`,onClick:()=>u(r.projectId),children:[(0,$.jsx)(sn,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Add thread`})]})}),(0,$.jsx)(K,{side:`right`,children:`Add thread`})]}),r.threads.length===0&&(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(U,{variant:`ghost`,size:`icon-sm`,className:`shrink-0 hidden can-hover:group-hover:flex items-center justify-center text-muted-foreground can-hover:hover:bg-destructive can-hover:hover:text-destructive-foreground transition-colors`,onClick:()=>d(r.projectId),children:[(0,$.jsx)(De,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Delete project`})]})}),(0,$.jsx)(K,{side:`right`,children:`Delete project`})]})]})}),t[23]=o,t[24]=u,t[25]=d,t[26]=f,t[27]=r.projectId,t[28]=r.threads,t[29]=O):O=t[29];let k;return t[30]!==E||t[31]!==O?(k=(0,$.jsxs)(`div`,{className:`group mb-1 flex min-w-0 items-center`,children:[E,O]}),t[30]=E,t[31]=O,t[32]=k):k=t[32],k}function Gi(e){let t=(0,X.c)(58),{thread:n,projectId:r,selectedThreadId:i,isProcessing:a,isDeleting:o,isCompleted:s,projectTitlePrefix:c,onSelectThread:l,onDeleteThread:u}=e,[d,f]=(0,Y.useState)(!1),p=(0,Y.useRef)(null),m=n.threadId===i,h,g;t[0]===a?(h=t[1],g=t[2]):(h=()=>{a&&p.current&&p.current.scrollIntoView({behavior:`smooth`,block:`nearest`})},g=[a],t[0]=a,t[1]=h,t[2]=g),(0,Y.useEffect)(h,g);let v;t[3]!==u||t[4]!==r||t[5]!==n.gitStatusDot||t[6]!==n.threadId?(v=e=>{e.stopPropagation(),n.gitStatusDot?f(!0):u(r,n.threadId)},t[3]=u,t[4]=r,t[5]=n.gitStatusDot,t[6]=n.threadId,t[7]=v):v=t[7];let y=v,b;t[8]!==c||t[9]!==n.threadId||t[10]!==n.title?(b=n.title?.startsWith(c)?n.title.slice(c.length):n.title??n.threadId,t[8]=c,t[9]=n.threadId,t[10]=n.title,t[11]=b):b=t[11];let x=b,S;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(br,{children:`Delete Thread`}),t[12]=S):S=t[12];let C;t[13]===x?C=t[14]:(C=(0,$.jsxs)(Sr,{children:[`Are you sure you want to delete "`,x,`" and all its files? This action cannot be undone.`]}),t[13]=x,t[14]=C);let w;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(Er,{children:`Cancel`}),t[15]=w):w=t[15];let T;t[16]!==u||t[17]!==r||t[18]!==n.threadId?(T=(0,$.jsxs)(`div`,{className:`flex gap-3 justify-end`,children:[w,(0,$.jsx)(vr,{onClick:()=>{f(!1),u(r,n.threadId)},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]}),t[16]=u,t[17]=r,t[18]=n.threadId,t[19]=T):T=t[19];let E;t[20]!==C||t[21]!==T?(E=(0,$.jsxs)(xr,{children:[S,C,T]}),t[20]=C,t[21]=T,t[22]=E):E=t[22];let D;t[23]!==d||t[24]!==E?(D=(0,$.jsx)(Dr,{open:d,onOpenChange:f,children:E}),t[23]=d,t[24]=E,t[25]=D):D=t[25];let O;t[26]!==l||t[27]!==r||t[28]!==n.threadId?(O=()=>l(r,n.threadId),t[26]=l,t[27]=r,t[28]=n.threadId,t[29]=O):O=t[29];let k;t[30]===n.gitStatusDot?k=t[31]:(k=n.gitStatusDot?(0,$.jsx)(`svg`,{className:`h-3 w-3 shrink-0`,viewBox:`0 0 12 12`,fill:`hsl(var(--brand))`,xmlns:`http://www.w3.org/2000/svg`,children:(0,$.jsx)(`circle`,{cx:`6`,cy:`6`,r:`5`})}):(0,$.jsx)(`svg`,{className:`h-3 w-3 shrink-0 text-muted-foreground`,viewBox:`0 0 12 12`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.0`,xmlns:`http://www.w3.org/2000/svg`,children:(0,$.jsx)(`circle`,{cx:`6`,cy:`6`,r:`4.5`})}),t[30]=n.gitStatusDot,t[31]=k);let A;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(A=q(J.body,`truncate block`),t[32]=A):A=t[32];let j;t[33]===x?j=t[34]:(j=(0,$.jsx)(`div`,{className:`flex-1 min-w-0 w-0`,children:(0,$.jsx)(`span`,{className:A,children:x})}),t[33]=x,t[34]=j);let M;t[35]!==s||t[36]!==o||t[37]!==a?(M=a||o?(0,$.jsx)(_,{className:`ml-auto h-3 w-3 shrink-0 animate-spin text-muted-foreground`}):s?(0,$.jsx)(ln,{className:`ml-auto h-3 w-3 shrink-0 text-green-500`}):null,t[35]=s,t[36]=o,t[37]=a,t[38]=M):M=t[38];let N;t[39]!==O||t[40]!==k||t[41]!==j||t[42]!==M?(N=(0,$.jsxs)(`button`,{type:`button`,className:`min-w-0 w-full`,onClick:O,children:[k,j,M]}),t[39]=O,t[40]=k,t[41]=j,t[42]=M,t[43]=N):N=t[43];let P;t[44]!==m||t[45]!==N?(P=(0,$.jsx)(mr,{selected:m,className:`min-w-0 flex-1`,asChild:!0,children:N}),t[44]=m,t[45]=N,t[46]=P):P=t[46];let F;t[47]!==y||t[48]!==s||t[49]!==o||t[50]!==a?(F=!a&&!o&&!s&&(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(U,{variant:`ghost`,size:`icon-sm`,className:`hidden can-hover:group-hover:flex shrink-0 items-center justify-center text-muted-foreground can-hover:hover:bg-destructive can-hover:hover:text-destructive-foreground transition-colors`,onClick:y,children:[(0,$.jsx)(De,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Delete thread`})]})}),(0,$.jsx)(K,{side:`right`,children:`Delete thread and files from the repo`})]}),t[47]=y,t[48]=s,t[49]=o,t[50]=a,t[51]=F):F=t[51];let I;t[52]!==P||t[53]!==F?(I=(0,$.jsxs)(`div`,{ref:p,className:`group flex min-w-0 items-center`,children:[P,F]}),t[52]=P,t[53]=F,t[54]=I):I=t[54];let L;return t[55]!==D||t[56]!==I?(L=(0,$.jsxs)($.Fragment,{children:[D,I]}),t[55]=D,t[56]=I,t[57]=L):L=t[57],L}var Ki=e(Je(),1),qi=.1,Ji=10,Yi=1.25,Xi=.001;function Zi(){let e=(0,X.c)(15),[t,n]=(0,Y.useState)(1),r;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r={x:0,y:0},e[0]=r):r=e[0];let[i,a]=(0,Y.useState)(r),[o,s]=(0,Y.useState)(!1),c=(0,Y.useRef)(null),l=Qi,u;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>n(e=>l(e*Yi)),e[1]=u):u=e[1];let d=u,f;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>n(e=>l(e/Yi)),e[2]=f):f=e[2];let p=f,m;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(m=()=>{n(1),a({x:0,y:0})},e[3]=m):m=e[3];let h=m,g;e[4]===i?g=e[5]:(g=e=>{e.preventDefault(),s(!0),c.current={x:e.clientX,y:e.clientY,ox:i.x,oy:i.y}},e[4]=i,e[5]=g);let _=g,v;e[6]===Symbol.for(`react.memo_cache_sentinel`)?(v=e=>{c.current&&a({x:c.current.ox+(e.clientX-c.current.x),y:c.current.oy+(e.clientY-c.current.y)})},e[6]=v):v=e[6];let y=v,b;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(b=()=>{s(!1),c.current=null},e[7]=b):b=e[7];let x=b,S=(0,Y.useRef)(null),C,w;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(C=()=>{let e=S.current;if(!e)return;let t=function(e){e.preventDefault();let t=-e.deltaY*Xi;n(e=>l(e*(1+t)))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},w=[],e[8]=C,e[9]=w):(C=e[8],w=e[9]),(0,Y.useEffect)(C,w);let T;return e[10]!==o||e[11]!==i||e[12]!==_||e[13]!==t?(T={scale:t,offset:i,isDragging:o,containerRef:S,zoomIn:d,zoomOut:p,reset:h,onMouseDown:_,onMouseMove:y,onMouseUp:x},e[10]=o,e[11]=i,e[12]=_,e[13]=t,e[14]=T):T=e[14],T}function Qi(e){return Math.min(Math.max(e,qi),Ji)}var $i=Cr(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border bg-muted/80 px-4 py-2`,children:[(0,$.jsx)(`span`,{className:e.v0,children:e.v1}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[e.v2,e.v3]})]}),{name:`JSX_header_1`,portals:[`v1`,`v2`,`v3`]}),ea=Cr(e=>(0,$.jsxs)(`div`,{className:e.v0,children:[e.v1,(0,$.jsx)(`pre`,{className:`overflow-x-auto p-4 max-w-full`,children:(0,$.jsx)(`code`,{className:e.v2,children:e.v3})})]}),{name:`MermaidRenderer_1`,portals:[`v1`,`v3`]}),ta=Cr(e=>(0,$.jsxs)(`div`,{className:e.v0,children:[e.v1,(0,$.jsx)(`div`,{className:e.v2,children:`Rendering diagram…`})]}),{name:`MermaidRenderer_2`,portals:[`v1`]}),na=Cr(e=>e.v0,{name:`MermaidRenderer_3`,portals:[`v0`]}),ra=function(e){let t=(0,X.c)(47),{content:n,className:r}=e,[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(!1),{svgOutput:c,renderError:l}=aa(n,ia()),u;t[0]===n?u=t[1]:(u=async function(){await navigator.clipboard.writeText(n),a(!0),setTimeout(()=>a(!1),2e3)},t[0]=n,t[1]=u);let d=u,f;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=q(J.compact,`font-mono text-muted-foreground`),t[2]=f):f=t[2];let p=l?`mermaid (render error)`:`mermaid diagram`,m;t[3]!==l||t[4]!==c?(m=c&&!l&&(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(U,{variant:`action`,size:`icon-xs`,onClick:()=>s(!0),children:[(0,$.jsx)(we,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:`View fullscreen`})]})}),(0,$.jsx)(K,{children:`View fullscreen`})]}),t[3]=l,t[4]=c,t[5]=m):m=t[5];let h;t[6]===i?h=t[7]:(h=i?(0,$.jsx)(ln,{}):(0,$.jsx)(it,{}),t[6]=i,t[7]=h);let g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(`span`,{className:`sr-only`,children:`Copy mermaid code`}),t[8]=g):g=t[8];let _;t[9]!==d||t[10]!==h?(_=(0,$.jsxs)(U,{variant:`action`,size:`icon-xs`,onClick:d,children:[h,g]}),t[9]=d,t[10]=h,t[11]=_):_=t[11];let v;t[12]!==p||t[13]!==m||t[14]!==_?(v=(0,$.jsx)($i,{v0:f,v1:p,v2:m,v3:_}),t[12]=p,t[13]=m,t[14]=_,t[15]=v):v=t[15];let y=v;if(l){let e;t[16]===r?e=t[17]:(e=q(`group relative overflow-hidden rounded-lg border border-border bg-muted`,r),t[16]=r,t[17]=e);let i;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(i=q(J.compact,`font-mono text-foreground leading-relaxed`),t[18]=i):i=t[18];let a;return t[19]!==n||t[20]!==y||t[21]!==e?(a=(0,$.jsx)(ea,{v0:e,v1:y,v2:i,v3:n}),t[19]=n,t[20]=y,t[21]=e,t[22]=a):a=t[22],a}if(!c){let e;t[23]===r?e=t[24]:(e=q(`group relative overflow-hidden rounded-lg border border-border bg-muted`,r),t[23]=r,t[24]=e);let n;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(n=q(J.compact,`p-4 text-muted-foreground`),t[25]=n):n=t[25];let i;return t[26]!==y||t[27]!==e?(i=(0,$.jsx)(ta,{v0:e,v1:y,v2:n}),t[26]=y,t[27]=e,t[28]=i):i=t[28],i}let b;t[29]===r?b=t[30]:(b=q(`group relative overflow-hidden rounded-lg border border-border bg-muted`,r),t[29]=r,t[30]=b);let x;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>s(!0),t[31]=x):x=t[31];let S;t[32]===c?S=t[33]:(S=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`block w-full text-left cursor-zoom-in p-4 max-w-full overflow-hidden [&_svg]:max-w-full [&_svg]:h-auto hover:bg-muted/70 transition-colors`,onClick:x,dangerouslySetInnerHTML:{__html:c}})}),t[32]=c,t[33]=S);let C;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(K,{children:`Click to view fullscreen`}),t[34]=C):C=t[34];let w;t[35]===S?w=t[36]:(w=(0,$.jsxs)(W,{children:[S,C]}),t[35]=S,t[36]=w);let T;t[37]!==y||t[38]!==w||t[39]!==b?(T=(0,$.jsxs)(`div`,{className:b,children:[y,w]}),t[37]=y,t[38]=w,t[39]=b,t[40]=T):T=t[40];let E;t[41]!==o||t[42]!==c?(E=o&&(0,$.jsx)(oa,{svgOutput:c,onClose:()=>s(!1)}),t[41]=o,t[42]=c,t[43]=E):E=t[43];let D;return t[44]!==T||t[45]!==E?(D=(0,$.jsx)(na,{v0:(0,$.jsxs)(Nt,{children:[T,E]})}),t[44]=T,t[45]=E,t[46]=D):D=t[46],D};function ia(){let e=(0,X.c)(2),[t,n]=(0,Y.useState)(!1),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=function(){n(document.documentElement.classList.contains(`dark`))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),(0,Y.useEffect)(r,i),t}function aa(e,t){let[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let n=!1;async function i(){try{let{renderMermaidSVG:i}=await pr(async()=>{let{renderMermaidSVG:e}=await import(`./dist-oojFghRi.js`);return{renderMermaidSVG:e}},__vite__mapDeps([0,1])),o=i(e,{bg:t?`#18181B`:`#FFFFFF`,fg:t?`#FAFAFA`:`#27272A`,transparent:!1,padding:32});n||(r(o),a(!1))}catch(e){console.error(`Mermaid render error:`,e),n||a(!0)}}return i(),()=>{n=!0}},[e,t]),{svgOutput:n,renderError:i}}function oa(e){let t=(0,X.c)(70),{svgOutput:n,onClose:r}=e,{scale:i,offset:a,isDragging:o,containerRef:s,zoomIn:c,zoomOut:l,reset:u,onMouseDown:d,onMouseMove:f,onMouseUp:p}=Zi(),m,h;t[0]===r?(m=t[1],h=t[2]):(m=()=>{let e=function(e){e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},h=[r],t[0]=r,t[1]=m,t[2]=h),(0,Y.useEffect)(m,h);let g;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(g=[],t[3]=g):g=t[3],(0,Y.useEffect)(sa,g);let _;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(`span`,{className:q(J.compact,`font-mono text-muted-foreground`),children:`mermaid diagram`}),t[4]=_):_=t[4];let v,y;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(Ge,{className:`h-3.5 w-3.5`}),y=(0,$.jsx)(`span`,{className:`sr-only`,children:`Zoom out`}),t[5]=v,t[6]=y):(v=t[5],y=t[6]);let b;t[7]===l?b=t[8]:(b=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(U,{variant:`ghost`,size:`icon-xs`,onClick:l,children:[v,y]})}),t[7]=l,t[8]=b);let x;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(K,{children:`Zoom out`}),t[9]=x):x=t[9];let S;t[10]===b?S=t[11]:(S=(0,$.jsxs)(W,{children:[b,x]}),t[10]=b,t[11]=S);let C;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(C=q(J.compact,`min-w-[3rem] px-2 py-1 font-mono text-muted-foreground hover:text-foreground hover:bg-muted rounded transition-colors`),t[12]=C):C=t[12];let w;t[13]===i?w=t[14]:(w=Math.round(i*100),t[13]=i,t[14]=w);let T;t[15]!==u||t[16]!==w?(T=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:u,className:C,children:[w,`%`]})}),t[15]=u,t[16]=w,t[17]=T):T=t[17];let E;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,$.jsx)(K,{children:`Reset zoom`}),t[18]=E):E=t[18];let D;t[19]===T?D=t[20]:(D=(0,$.jsxs)(W,{children:[T,E]}),t[19]=T,t[20]=D);let O,k;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(sn,{className:`h-3.5 w-3.5`}),k=(0,$.jsx)(`span`,{className:`sr-only`,children:`Zoom in`}),t[21]=O,t[22]=k):(O=t[21],k=t[22]);let A;t[23]===c?A=t[24]:(A=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(U,{variant:`ghost`,size:`icon-xs`,onClick:c,children:[O,k]})}),t[23]=c,t[24]=A);let M;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,$.jsx)(K,{children:`Zoom in`}),t[25]=M):M=t[25];let N;t[26]===A?N=t[27]:(N=(0,$.jsxs)(W,{children:[A,M]}),t[26]=A,t[27]=N);let P,F;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(P=(0,$.jsx)($t,{className:`h-3.5 w-3.5`}),F=(0,$.jsx)(`span`,{className:`sr-only`,children:`Reset view`}),t[28]=P,t[29]=F):(P=t[28],F=t[29]);let I;t[30]===u?I=t[31]:(I=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(U,{variant:`ghost`,size:`icon-xs`,onClick:u,children:[P,F]})}),t[30]=u,t[31]=I);let L;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsx)(K,{children:`Reset view`}),t[32]=L):L=t[32];let R;t[33]===I?R=t[34]:(R=(0,$.jsxs)(W,{children:[I,L]}),t[33]=I,t[34]=R);let ee;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,$.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),t[35]=ee):ee=t[35];let te,z;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(te=(0,$.jsx)(j,{className:`h-3.5 w-3.5`}),z=(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`}),t[36]=te,t[37]=z):(te=t[36],z=t[37]);let ne;t[38]===r?ne=t[39]:(ne=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(U,{variant:`ghost`,size:`icon-xs`,onClick:r,children:[te,z]})}),t[38]=r,t[39]=ne);let B;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(B=(0,$.jsx)(K,{children:`Close (Esc)`}),t[40]=B):B=t[40];let re;t[41]===ne?re=t[42]:(re=(0,$.jsxs)(W,{children:[ne,B]}),t[41]=ne,t[42]=re);let V;t[43]!==D||t[44]!==N||t[45]!==R||t[46]!==re||t[47]!==S?(V=(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 bg-background/90 border-b border-border shrink-0`,children:[_,(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[S,D,N,R,ee,re]})]}),t[43]=D,t[44]=N,t[45]=R,t[46]=re,t[47]=S,t[48]=V):V=t[48];let ie=o?`cursor-grabbing`:`cursor-grab`,ae;t[49]===ie?ae=t[50]:(ae=q(`flex-1 overflow-hidden select-none`,ie),t[49]=ie,t[50]=ae);let oe=`translate(${a.x}px, ${a.y}px) scale(${i})`,H=o?`none`:`transform 0.1s ease-out`,se;t[51]!==oe||t[52]!==H?(se={transform:oe,transformOrigin:`center center`,transition:H},t[51]=oe,t[52]=H,t[53]=se):se=t[53];let ce;t[54]===n?ce=t[55]:(ce={__html:n},t[54]=n,t[55]=ce);let le;t[56]!==se||t[57]!==ce?(le=(0,$.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,style:se,dangerouslySetInnerHTML:ce}),t[56]=se,t[57]=ce,t[58]=le):le=t[58];let ue;t[59]!==s||t[60]!==d||t[61]!==f||t[62]!==p||t[63]!==ae||t[64]!==le?(ue=(0,$.jsx)(`div`,{ref:s,className:ae,onMouseDown:d,onMouseMove:f,onMouseUp:p,onMouseLeave:p,children:le}),t[59]=s,t[60]=d,t[61]=f,t[62]=p,t[63]=ae,t[64]=le,t[65]=ue):ue=t[65];let de;t[66]===Symbol.for(`react.memo_cache_sentinel`)?(de=(0,$.jsx)(`div`,{className:q(J.compact,`shrink-0 px-4 py-2 text-center text-muted-foreground/60 bg-background/60 border-t border-border`),children:`Scroll to zoom · Drag to pan · Esc to close`}),t[66]=de):de=t[66];let fe;return t[67]!==V||t[68]!==ue?(fe=(0,Ki.createPortal)((0,$.jsx)(Nt,{children:(0,$.jsxs)(`div`,{className:`fixed inset-0 z-50 flex flex-col bg-black/85 backdrop-blur-sm`,role:`dialog`,"aria-modal":`true`,"aria-label":`Diagram fullscreen view`,children:[V,ue,de]})}),document.body),t[67]=V,t[68]=ue,t[69]=fe):fe=t[69],fe}function sa(){return document.body.style.overflow=`hidden`,ca}function ca(){document.body.style.overflow=``}var la=`graph.flowchart.sequenceDiagram.classDiagram.stateDiagram.erDiagram.journey.gantt.pie.quadrantChart.requirementDiagram.gitgraph.mindmap.timeline.zenuml.sankey.block.architecture.c4.packet.circuit.flowchart LR.flowchart TD.flowchart BT.flowchart RL.graph LR.graph TD.graph BT.graph RL`.split(`.`),ua=[/-->/,/--\./,/-\./,/==>/,/--\|/,/\w+\[\w+\]/,/\w+\(\w+\)/,/\w+\{\w+\}/,/\w+>\w+\]/,/\w+\(\w+\)/,/\w+\[\(\w+\)\]/,/participant\s+\w+/,/actor\s+\w+/,/Note over \w+/,/loop\s+/,/alt\s+/,/opt\s+/,/class\s+\w+/,/interface\s+\w+/,/enum\s+\w+/,/\[\*\]/,/\[\*\]/,/title\s+/,/direction\s+/,/subgraph\s+/];function da(e){if(!e||typeof e!=`string`)return!1;let t=e.split(`
6
- `).map(e=>e.trim()).filter(e=>e.length>0);if(t.length===0)return!1;if(/```mermaid\s*\n([\s\S]*?)\n```/.test(e))return!0;let n=t[0].toLowerCase();if(la.some(e=>n===e.toLowerCase()||n.startsWith(e.toLowerCase()+` `)))return!0;let r=0;for(let t of ua)t.test(e)&&r++;return r>=2}function fa(e){if(!da(e))return null;let t=/```mermaid\s*\n([\s\S]*?)\n```/.exec(e);if(t)return t[1].trim();let n=e.split(`
7
- `).map(e=>e.trim()).filter(e=>e.length>0)[0].toLowerCase();return la.some(e=>n===e.toLowerCase()||n.startsWith(e.toLowerCase()+` `))?e.trim():null}var pa=Cr(e=>(0,$.jsxs)(`div`,{className:`group relative overflow-hidden rounded-lg border border-border bg-muted`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border bg-muted/80 px-4 py-2`,children:[(0,$.jsx)(`span`,{className:e.v0,children:e.v1}),e.v2]}),(0,$.jsx)(`pre`,{className:`overflow-x-auto p-4 max-w-full`,children:(0,$.jsx)(`code`,{className:e.v3,children:e.v4})})]}),{name:`CodeBlock_1`,portals:[`v1`,`v2`,`v4`]}),ma=function(e){let t=(0,X.c)(14),{language:n,code:r}=e,[i,a]=(0,Y.useState)(!1),o;t[0]===r?o=t[1]:(o=async()=>{await navigator.clipboard.writeText(r),a(!0),setTimeout(()=>a(!1),2e3)},t[0]=r,t[1]=o);let s=o,c;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=q(J.compact,`text-muted-foreground font-mono`),t[2]=c):c=t[2];let l=n||`text`,u;t[3]===i?u=t[4]:(u=i?(0,$.jsx)(ln,{}):(0,$.jsx)(it,{}),t[3]=i,t[4]=u);let d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(`span`,{className:`sr-only`,children:`Copy code`}),t[5]=d):d=t[5];let f;t[6]!==s||t[7]!==u?(f=(0,$.jsxs)(U,{variant:`action`,size:`icon-xs`,onClick:s,children:[u,d]}),t[6]=s,t[7]=u,t[8]=f):f=t[8];let p;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(p=q(J.mono,`text-foreground leading-relaxed`),t[9]=p):p=t[9];let m;return t[10]!==r||t[11]!==l||t[12]!==f?(m=(0,$.jsx)(pa,{v0:c,v1:l,v2:f,v3:p,v4:r}),t[10]=r,t[11]=l,t[12]=f,t[13]=m):m=t[13],m},ha=(0,Y.memo)(function({content:e,className:t,enableMermaid:n=!1}){let r=(0,Y.useMemo)(()=>!e||typeof e!=`string`?[]:ga(e,n),[e,n]),i=(0,Y.useMemo)(()=>{let e=0;return r.map(t=>{if(t.type===`list`&&t.ordered){let n=e+1;return e+=t.items.length,n}else if(t.type===`list`&&!t.ordered)return 1;else return e=0,1})},[r]);return r.length===0?null:(0,$.jsx)(`div`,{className:q(`prose-custom space-y-3 min-w-0 break-words`,t),children:r.map((e,t)=>(0,$.jsx)(Ea,{block:e,start:i[t]},t))})});function ga(e,t=!1){let n=e.split(`
8
- `),r=[],i=0;for(;i<n.length;){let e=n[i];if(e.trimStart().startsWith("```")){let a=e.trimStart().slice(3).trim(),o=[];for(i++;i<n.length&&!n[i].trimStart().startsWith("```");)o.push(n[i]),i++;t&&(a===`mermaid`||da(o.join(`
9
- `)))?r.push({type:`mermaid`,code:o.join(`
10
- `)}):r.push({type:`code`,language:a,code:o.join(`
11
- `)}),i++;continue}let a=e.match(/^(#{1,6})(\s.*)?$/);if(a){r.push({type:`heading`,level:a[1].length,text:a[2]?a[2].trim():``}),i++;continue}if(/^(---|\*\*\*|___)/.test(e.trim())){r.push({type:`hr`}),i++;continue}if(e.includes(`|`)&&i+1<n.length&&n[i+1].match(/^\|?\s*[-:]+/)){let t=e.split(`|`).map(e=>e.trim()).filter(Boolean);i+=2;let a=[];for(;i<n.length&&n[i].includes(`|`);)a.push(n[i].split(`|`).map(e=>e.trim()).filter(Boolean)),i++;r.push({type:`table`,headers:t,rows:a});continue}if(e.startsWith(`> `)){let e=[];for(;i<n.length&&n[i].startsWith(`> `);)e.push(n[i].slice(2)),i++;r.push({type:`blockquote`,text:e.join(`
12
- `)});continue}if(/^\s*[-*+]\s/.test(e)){let e=[];for(;i<n.length&&/^\s*[-*+]\s/.test(n[i]);)e.push(n[i].replace(/^\s*[-*+]\s/,``)),i++;r.push({type:`list`,ordered:!1,items:e});continue}if(/^\s*\d+\.\s/.test(e)){let e=[];for(;i<n.length&&/^\s*\d+\.\s/.test(n[i]);)e.push(n[i].replace(/^\s*\d+\.\s/,``)),i++;r.push({type:`list`,ordered:!0,items:e});continue}if(e.trim()===``){i++;continue}let o=[];for(;i<n.length&&n[i].trim()!==``&&!n[i].startsWith(`#`)&&!n[i].startsWith("```")&&!n[i].startsWith(`> `)&&!/^\s*[-*+]\s/.test(n[i])&&!/^\s*\d+\.\s/.test(n[i]);)o.push(n[i]),i++;if(o.length>0){let e=o.join(`
13
- `);if(t&&da(e)){let t=fa(e);t?r.push({type:`mermaid`,code:t}):r.push({type:`paragraph`,text:e})}else r.push({type:`paragraph`,text:e})}}return r}var _a=Cr(e=>e.v0,{name:`MarkdownBlock_2`,portals:[`v0`]}),va=Cr(e=>e.v0,{name:`MarkdownBlock_3`,portals:[`v0`]}),ya=Cr(e=>(0,$.jsx)(`blockquote`,{className:`border-l-2 border-border pl-4 text-muted-foreground italic`,children:e.v0}),{name:`MarkdownBlock_4`,portals:[`v0`]}),ba=Cr(e=>(0,$.jsx)(`ol`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_5`,portals:[`v1`]}),xa=Cr(e=>(0,$.jsx)(`ul`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_6`,portals:[`v1`]}),Sa=Cr(e=>(0,$.jsx)(`p`,{className:e.v0,children:e.v1}),{name:`MarkdownBlock_7`,portals:[`v1`]}),Ca=Cr(()=>(0,$.jsx)(`hr`,{className:`border-border`}),{name:`MarkdownBlock_8`}),wa=Cr(e=>(0,$.jsx)(`div`,{className:`overflow-x-auto rounded-md border border-border max-w-full`,children:(0,$.jsxs)(`table`,{className:e.v0,children:[(0,$.jsx)(`thead`,{children:(0,$.jsx)(`tr`,{className:`border-b border-border bg-muted/50`,children:e.v1})}),(0,$.jsx)(`tbody`,{children:e.v2})]})}),{name:`MarkdownBlock_9`,portals:[`v1`,`v2`]}),Ta=Cr(e=>e.v0,{name:`MarkdownBlock_10`,portals:[`v0`]}),Ea=(0,Y.memo)(function(e){let t=(0,X.c)(46),{block:n,start:r}=e,i=r===void 0?1:r;switch(n.type){case`heading`:{let e=`h${n.level}`,r,i,a;if(t[0]!==e||t[1]!==n.level){let o={1:J.sectionTitle,2:q(J.body,`font-semibold`),3:q(J.body,`font-semibold`),4:J.sectionSubtitle,5:J.sectionSubtitle,6:J.sectionSubtitle};i=_a,r=e,a=q(o[n.level]),t[0]=e,t[1]=n.level,t[2]=r,t[3]=i,t[4]=a}else r=t[2],i=t[3],a=t[4];let o;t[5]===n.text?o=t[6]:(o=(0,$.jsx)(Da,{text:n.text}),t[5]=n.text,t[6]=o);let s;t[7]!==r||t[8]!==a||t[9]!==o?(s=(0,$.jsx)(r,{className:a,children:o}),t[7]=r,t[8]=a,t[9]=o,t[10]=s):s=t[10];let c;return t[11]!==i||t[12]!==s?(c=(0,$.jsx)(i,{v0:s}),t[11]=i,t[12]=s,t[13]=c):c=t[13],c}case`code`:{let e;return t[14]!==n.code||t[15]!==n.language?(e=(0,$.jsx)(va,{v0:(0,$.jsx)(ma,{language:n.language,code:n.code})}),t[14]=n.code,t[15]=n.language,t[16]=e):e=t[16],e}case`blockquote`:{let e;return t[17]===n.text?e=t[18]:(e=(0,$.jsx)(ya,{v0:(0,$.jsx)(Da,{text:n.text})}),t[17]=n.text,t[18]=e),e}case`list`:{if(n.ordered){let e;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(e=q(J.body,`space-y-1`),t[19]=e):e=t[19];let r;if(t[20]!==n.items||t[21]!==i){let e;t[23]===i?e=t[24]:(e=(e,t)=>(0,$.jsxs)(`li`,{className:`flex gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`shrink-0 select-none tabular-nums`,children:[i+t,`.`]}),(0,$.jsx)(`span`,{children:(0,$.jsx)(Da,{text:e})})]},t),t[23]=i,t[24]=e),r=n.items.map(e),t[20]=n.items,t[21]=i,t[22]=r}else r=t[22];let a;return t[25]===r?a=t[26]:(a=(0,$.jsx)(ba,{v0:e,v1:r}),t[25]=r,t[26]=a),a}let e;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(e=q(J.body,`space-y-1 pl-5 list-outside overflow-visible list-disc`),t[27]=e):e=t[27];let r;t[28]===n.items?r=t[29]:(r=n.items.map(ka),t[28]=n.items,t[29]=r);let a;return t[30]===r?a=t[31]:(a=(0,$.jsx)(xa,{v0:e,v1:r}),t[30]=r,t[31]=a),a}case`paragraph`:{let e;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(e=q(J.body,`leading-relaxed whitespace-pre-wrap break-words`),t[32]=e):e=t[32];let r;return t[33]===n.text?r=t[34]:(r=(0,$.jsx)(Sa,{v0:e,v1:(0,$.jsx)(Da,{text:n.text})}),t[33]=n.text,t[34]=r),r}case`hr`:{let e;return t[35]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Ca,{}),t[35]=e):e=t[35],e}case`table`:{let e;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(e=q(J.body,`w-full`),t[36]=e):e=t[36];let r;t[37]===n.headers?r=t[38]:(r=n.headers.map(Aa),t[37]=n.headers,t[38]=r);let i;t[39]===n.rows?i=t[40]:(i=n.rows.map(Ma),t[39]=n.rows,t[40]=i);let a;return t[41]!==r||t[42]!==i?(a=(0,$.jsx)(wa,{v0:e,v1:r,v2:i}),t[41]=r,t[42]=i,t[43]=a):a=t[43],a}case`mermaid`:{let e;return t[44]===n.code?e=t[45]:(e=(0,$.jsx)(Ta,{v0:(0,$.jsx)(ra,{content:n.code})}),t[44]=n.code,t[45]=e),e}default:return null}}),Da=(0,Y.memo)(function(e){let t=(0,X.c)(6),{text:n}=e,r;t[0]===n?r=t[1]:(r=Oa(n),t[0]=n,t[1]=r);let i=r,a;t[2]===i?a=t[3]:(a=i.map(Na),t[2]=i,t[3]=a);let o;return t[4]===a?o=t[5]:(o=(0,$.jsx)($.Fragment,{children:a}),t[4]=a,t[5]=o),o});function Oa(e){let t=[],n=/(`[^`]+`)|(\*\*[^*]+\*\*)|(\*[^*]+\*)|(__[^_]+__)|(_[^_]+_)|(~~[^~]+~~)|(\[[^\]]+\]\([^)]+\))/g,r=0,i;for(;(i=n.exec(e))!==null;){i.index>r&&t.push({type:`text`,text:e.slice(r,i.index)});let n=i[0];if(n.startsWith("`"))t.push({type:`code`,text:n.slice(1,-1)});else if(n.startsWith(`**`))t.push({type:`bold`,text:n.slice(2,-2)});else if(n.startsWith(`__`))t.push({type:`bold`,text:n.slice(2,-2)});else if(n.startsWith(`~~`))t.push({type:`strikethrough`,text:n.slice(2,-2)});else if(n.startsWith(`*`)||n.startsWith(`_`))t.push({type:`italic`,text:n.slice(1,-1)});else if(n.startsWith(`[`)){let e=n.match(/\[([^\]]+)\]\(([^)]+)\)/);e&&t.push({type:`link`,text:e[1],href:e[2]})}r=i.index+n.length}return r<e.length&&t.push({type:`text`,text:e.slice(r)}),t.length>0?t:[{type:`text`,text:e}]}function ka(e,t){return(0,$.jsx)(`li`,{children:(0,$.jsx)(Da,{text:e})},t)}function Aa(e,t){return(0,$.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,children:(0,$.jsx)(Da,{text:e})},t)}function ja(e,t){return(0,$.jsx)(`td`,{className:`px-3 py-2`,children:(0,$.jsx)(Da,{text:e})},t)}function Ma(e,t){return(0,$.jsx)(`tr`,{className:`border-b border-border last:border-0`,children:e.map(ja)},t)}function Na(e,t){switch(e.type){case`bold`:return(0,$.jsx)(`strong`,{className:`font-semibold`,children:e.text},t);case`italic`:return(0,$.jsx)(`em`,{children:e.text},t);case`strikethrough`:return(0,$.jsx)(`del`,{className:`text-muted-foreground`,children:e.text},t);case`code`:return(0,$.jsx)(`code`,{className:q(J.mono,`rounded bg-muted/20 px-1.5 py-0.5`),children:e.text},t);case`link`:return(0,$.jsx)(`a`,{href:e.href,className:`text-primary underline underline-offset-2 hover:text-primary/80`,target:`_blank`,rel:`noopener noreferrer`,children:e.text},t);default:return(0,$.jsx)(`span`,{children:e.text},t)}}var Pa=(0,Y.createContext)({activeMainTab:`chat`,setActiveMainTab:()=>{},devServerUrl:null,setDevServerUrl:()=>{},devServerRunning:!1,setDevServerRunning:()=>{},devServerLoading:!1,setDevServerLoading:()=>{},terminalNotification:!1,setTerminalNotification:()=>{},pendingExplorerPath:null,setPendingExplorerPath:()=>{},explorerRefreshTick:0,triggerExplorerRefresh:()=>{},explorerClearPath:null,setExplorerClearPath:()=>{},browserResetTrigger:0,triggerBrowserReset:()=>{}});function Fa(){return(0,Y.useContext)(Pa)}var Ia=new RegExp(String.raw`\x1B\[[0-?]*[ -/]*[@-~]`,`g`),La=new RegExp(String.raw`\x1B\].*?(?:\x07|\x1B\\)`,`g`),Ra=new RegExp(String.raw`\x1B[@-_]`,`g`),za=/\r(?!\n)/g,Ba=/\\n/g;function Va(e){return e.replace(La,``).replace(Ia,``).replace(Ra,``)}function Ha(e){return Va(e).replace(Ba,`
14
- `).replace(za,`
15
- `)}function Ua(e){return Sn(e)}function Wa(e,t){if(!t||!e||typeof e!=`string`)return e;try{let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return e.replace(new RegExp(n,`g`),`.`)}catch{return e}}function Ga(e){return typeof e==`string`?e:typeof e==`object`&&e?JSON.stringify(e,null,2):String(e)}function Ka(e){let t=e.trim();if(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`))try{return JSON.parse(t)}catch{return e}return e}function qa(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(qa);let t={};for(let[n,r]of Object.entries(e))if(typeof r==`string`){let e=Ka(r);t[n]=typeof e==`object`?qa(e):r}else t[n]=qa(r);return t}function Ja(e){if(e==null||typeof e!=`string`)return``;let t=e;return t=t.replace(/\\\\n/g,`
16
- `),t=t.replace(/\\\\"/g,`"`),t=t.replace(/\\n/g,`
17
- `),t=t.replace(/\\"/g,`"`),t}function Ya(e){if(e==null)return``;let t=typeof e==`object`&&e?qa(e):e;return Ha(Ja(typeof t==`string`?t:t==null?``:JSON.stringify(t,null,2)))}function Xa(e,t){let n=e.name??`Unknown Tool`,r=e.id??`unknown`,i=e.input,a=i&&typeof i==`object`?i:null,o=i&&typeof i==`object`&&`description`in i,s=o?i.subagent_type:void 0,c=s==null?null:JSON.stringify(s),l=n===`agent`&&a&&typeof a.agentName==`string`?a.agentName:null,u=o?null:Wa(Ga(i),t),d=Wa(o?String(i.prompt):null,t),f=Wa(a&&typeof a.command==`string`?a.command:null,t),p=n===`fetch`&&a&&typeof a.url==`string`?a.url:null,m=a&&typeof a.pattern==`string`?a.pattern:null,h=n===`web_search`&&a&&typeof a.query==`string`?a.query:null,g=a&&typeof a.lang==`string`?a.lang:null,_=n===`code_search`,v=_&&a&&typeof a.query==`string`?a.query:null,y=_&&a&&typeof a.filePath==`string`?a.filePath:null,b=_&&a&&typeof a.fileGlob==`string`?a.fileGlob:null,x=Wa(a&&typeof a.path==`string`?a.path:null,t),S=a&&typeof a.offset==`number`?a.offset:null,C=a&&typeof a.limit==`number`?a.limit:null,w=n.toLowerCase(),T=w.includes(`read`)||w.includes(`write`)||w.includes(`edit`),E=w.includes(`edit`),D=T&&a&&typeof a.path==`string`?a.path:null,O=D?D.split(`/`).pop()??D:null,k=E&&a&&typeof a.oldText==`string`?a.oldText:null,A=E&&a&&typeof a.newText==`string`?a.newText:null,j=k===null?null:k.split(`
18
- `).length,M=A===null?null:A.split(`
19
- `).length,N=k!==null&&A!==null,P=n===`generate_image`&&a&&typeof a.prompt==`string`?a.prompt:null,F=n===`todo`&&a?a.status:void 0,I=e.displayName??Sn(n),L=e.activeDisplayName??Ke(n),R=`default`;return w===`bash`||w.includes(`terminal`)||w.includes(`shell`)?R=`bash`:w===`fetch`?R=`fetch`:T?R=`file`:_||w===`find`||w===`web_search`||w.includes(`search`)||w.includes(`grep`)?R=`search`:w===`agent`||w.includes(`subagent`)||o?R=`agent`:w===`todo`?R=`todo`:w===`generate_image`&&(R=`imageGen`),{toolType:R,toolName:n,toolId:r,displayName:I,activeDisplayName:L,inputObj:a,toolInput:u,command:f,fetchUrl:p,pattern:m,webSearchQuery:h,codeSearchQuery:v,codeSearchFilePath:y,codeSearchFileGlob:b,isFileTool:T,isEditTool:E,filePath:D,fileDisplayName:O,editOldText:k,editNewText:A,editDeletedLineCount:j,editAddedLineCount:M,hasEditDiff:N,path:x,offset:S,limit:C,prompt:d,agentName:l,subagentType:c,lang:g,imageGenPrompt:P,todoStatus:F}}var Za=new Map;function Qa(e){return e.trim()}function $a(){let e=It(qt.BASH_COMMAND_DURATIONS);if(!e)return{};try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))return{};let n={};for(let[e,r]of Object.entries(t))typeof r==`number`&&Number.isFinite(r)&&r>0&&(n[Qa(e)]=r);return n}catch{return{}}}function eo(e){un(qt.BASH_COMMAND_DURATIONS,JSON.stringify(e))}function to(e){return $a()[Qa(e)]??null}function no(e,t){let n=Qa(e);if(!n||!Number.isFinite(t)||t<=0)return;let r=$a();r[n]=Math.round(t),eo(r)}function ro(e,t){!t?.trim()||Za.has(e)||Za.set(e,{command:Qa(t),startedAt:Date.now()})}function io(e){let t=Za.get(e);if(!t)return;let n=Date.now()-t.startedAt;no(t.command,n),Za.delete(e)}function ao(e){let t=Math.max(0,Math.floor(e/1e3)),n=Math.floor(t/60),r=t%60;return`${n}:${String(r).padStart(2,`0`)}`}function oo(e,t){return t!==null&&t>0?`${Math.min(99,Math.round(e/t*100))}% complete`:ao(e)}var so=1e3;function co(e,t,n){let[r,i]=(0,Y.useState)(0),[a,o]=(0,Y.useState)(null),s=(0,Y.useRef)(null),c=(0,Y.useRef)(!1),l=(0,Y.useRef)(n);return l.current=n,(0,Y.useEffect)(()=>{if(n&&!c.current){let n=e?.trim()??``;o(n?to(n):null),ro(t,e),s.current=Date.now(),i(0)}else !n&&c.current&&(io(t),s.current=null,i(0),o(null));c.current=n},[n,e,t]),(0,Y.useEffect)(()=>()=>{l.current&&io(t)},[t]),(0,Y.useEffect)(()=>{if(!n)return;let e=()=>{s.current===null&&(s.current=Date.now()),i(Date.now()-s.current)};e();let t=setInterval(e,so);return()=>clearInterval(t)},[n]),n?oo(r,a):null}function lo(e){let{maxHeight:t=`48`,padding:n=`2`,leading:r=!1,className:i}=e??{};return q(J.mono,n===`3`?`p-3`:`p-2`,`bg-muted rounded whitespace-pre-wrap overflow-auto text-foreground`,t===`64`?`max-h-64`:`max-h-48`,r&&`leading-relaxed`,i)}function uo(e){let t=(0,X.c)(12),{open:n,onOpenChange:r,title:i,content:a}=e,o;t[0]===i?o=t[1]:(o=(0,$.jsx)(xt,{children:(0,$.jsx)(z,{children:(0,$.jsx)(`code`,{className:J.mono,children:i})})}),t[0]=i,t[1]=o);let s;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(s=lo({padding:`3`,className:`flex-1 max-h-none`}),t[2]=s):s=t[2];let c;t[3]===a?c=t[4]:(c=(0,$.jsx)(`pre`,{className:s,children:a}),t[3]=a,t[4]=c);let l;t[5]!==o||t[6]!==c?(l=(0,$.jsxs)(H,{className:`max-w-3xl h-[80vh] flex flex-col`,children:[o,c]}),t[5]=o,t[6]=c,t[7]=l):l=t[7];let u;return t[8]!==r||t[9]!==n||t[10]!==l?(u=(0,$.jsx)(g,{open:n,onOpenChange:r,children:l}),t[8]=r,t[9]=n,t[10]=l,t[11]=u):u=t[11],u}function fo(e){let t=(0,X.c)(10),{oldText:n,newText:r}=e,i,a,o;if(t[0]!==r||t[1]!==n){let e=n.split(`
20
- `),s=r.split(`
21
- `);t[5]===Symbol.for(`react.memo_cache_sentinel`)?(i=q(J.caption,`font-mono whitespace-pre-wrap overflow-auto`),t[5]=i):i=t[5],a=e.map(mo),o=s.map(po),t[0]=r,t[1]=n,t[2]=i,t[3]=a,t[4]=o}else i=t[2],a=t[3],o=t[4];let s;return t[6]!==i||t[7]!==a||t[8]!==o?(s=(0,$.jsxs)(`pre`,{className:i,children:[a,o]}),t[6]=i,t[7]=a,t[8]=o,t[9]=s):s=t[9],s}function po(e,t){return(0,$.jsxs)(`div`,{className:`bg-green-500/10 text-green-600 dark:text-green-400`,children:[(0,$.jsx)(`span`,{className:`select-none opacity-50 mr-2`,children:`+`}),e]},`new-${t}`)}function mo(e,t){return(0,$.jsxs)(`div`,{className:`bg-red-500/10 text-red-600 dark:text-red-400`,children:[(0,$.jsx)(`span`,{className:`select-none opacity-50 mr-2`,children:`-`}),e]},`old-${t}`)}function ho(e){let t=(0,X.c)(3),{name:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=q(J.caption,`px-1.5 py-0.5 rounded bg-muted font-mono`),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`span`,{className:r,children:n}),t[1]=n,t[2]=i),i}function go(e){let t=(0,X.c)(3),{type:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=q(J.caption,`px-2 py-0.5 rounded bg-muted`),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`span`,{className:r,children:n}),t[1]=n,t[2]=i),i}function _o(e){let t=(0,X.c)(3),{children:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=q(J.caption,`font-mono break-all rounded bg-muted/60 px-1 py-0.5`),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i=(0,$.jsx)(`code`,{className:r,children:n}),t[1]=n,t[2]=i),i}function vo(e){let t=(0,X.c)(5),{className:n,size:r}=e,i=(r===void 0?`sm`:r)===`sm`?`h-7 w-7`:`h-8 w-8`,a;t[0]!==n||t[1]!==i?(a=q(`shrink-0`,i,n),t[0]=n,t[1]=i,t[2]=a):a=t[2];let o;return t[3]===a?o=t[4]:(o=(0,$.jsx)(`img`,{src:`/busy.svg`,alt:``,className:a,"aria-hidden":!0}),t[3]=a,t[4]=o),o}function yo(e){let t=(0,X.c)(15),{toolName:n,displayName:r,muted:i,size:a,className:o}=e,s=i===void 0?!0:i,c;t[0]===o?c=t[1]:(c=q(`inline-flex items-center gap-1`,o),t[0]=o,t[1]=c);let l=!s&&`text-foreground`,u;t[2]===l?u=t[3]:(u=q(J.caption,l),t[2]=l,t[3]=u);let d;t[4]!==r||t[5]!==u?(d=(0,$.jsx)(`span`,{className:u,children:r}),t[4]=r,t[5]=u,t[6]=d):d=t[6];let f;t[7]!==c||t[8]!==d?(f=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`span`,{className:c,children:d})}),t[7]=c,t[8]=d,t[9]=f):f=t[9];let p;t[10]===n?p=t[11]:(p=(0,$.jsx)(K,{children:n}),t[10]=n,t[11]=p);let m;return t[12]!==f||t[13]!==p?(m=(0,$.jsxs)(W,{children:[f,p]}),t[12]=f,t[13]=p,t[14]=m):m=t[14],m}function bo(e){let t=(0,X.c)(102),{data:n,inline:r,resultContent:i,isActive:a}=e,o=(0,Y.useRef)(null),[s,c]=(0,Y.useState)(!!a),[l,u]=(0,Y.useState)(!1),d=(0,Y.useRef)(!!a),f;t[0]===n.toolId?f=t[1]:(f=e=>e.toolCallProgress[n.toolId]?.executionOutput,t[0]=n.toolId,t[1]=f);let p=Q(f),m=a?p??i??``:i??``,h;t[2]===m?h=t[3]:(h=m?Ha(m):``,t[2]=m,t[3]=h);let g=h,_=a?g:``,v=co(n.command,n.toolId,!!a),y,b;t[4]===a?(y=t[5],b=t[6]):(y=()=>{a&&!d.current?c(!0):!a&&d.current&&c(!1),d.current=!!a},b=[a],t[4]=a,t[5]=y,t[6]=b),(0,Y.useEffect)(y,b);let x;t[7]!==a||t[8]!==s?(x=()=>{s&&a&&o.current&&(o.current.scrollTop=o.current.scrollHeight)},t[7]=a,t[8]=s,t[9]=x):x=t[9];let S;if(t[10]!==a||t[11]!==s||t[12]!==_?(S=[s,a,_],t[10]=a,t[11]=s,t[12]=_,t[13]=S):S=t[13],(0,Y.useEffect)(x,S),r){if(a){let e;t[14]===s?e=t[15]:(e=()=>c(!s),t[14]=s,t[15]=e);let r;t[16]!==n.activeDisplayName||t[17]!==n.toolName?(r=(0,$.jsx)(yo,{toolName:n.toolName,displayName:n.activeDisplayName,isActive:!1}),t[16]=n.activeDisplayName,t[17]=n.toolName,t[18]=r):r=t[18];let i;t[19]===n.command?i=t[20]:(i=n.command!==null&&(0,$.jsx)(`span`,{className:q(J.caption,`break-all`),children:n.command}),t[19]=n.command,t[20]=i);let a;t[21]===v?a=t[22]:(a=v&&(0,$.jsx)(`span`,{className:q(J.caption,`tabular-nums shrink-0`),children:v}),t[21]=v,t[22]=a);let l;t[23]===s?l=t[24]:(l=s?(0,$.jsx)(Tt,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(en,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[23]=s,t[24]=l);let u;t[25]!==s||t[26]!==a||t[27]!==l||t[28]!==e||t[29]!==r||t[30]!==i?(u=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full`,onClick:e,"aria-expanded":s,children:[r,i,a,l]}),t[25]=s,t[26]=a,t[27]=l,t[28]=e,t[29]=r,t[30]=i,t[31]=u):u=t[31];let d=s?`grid-rows-[1fr]`:`grid-rows-[0fr]`,f;t[32]===d?f=t[33]:(f=q(`grid transition-[grid-template-rows] duration-200 ease-in-out`,d),t[32]=d,t[33]=f);let p,m;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(p=q(J.caption,`ml-5 text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto font-mono`),m={maxHeight:`7.5em`},t[34]=p,t[35]=m):(p=t[34],m=t[35]);let h;t[36]===_?h=t[37]:(h=(0,$.jsx)(`div`,{className:`overflow-hidden`,children:(0,$.jsx)(`div`,{ref:o,className:p,style:m,children:_})}),t[36]=_,t[37]=h);let g;t[38]!==f||t[39]!==h?(g=(0,$.jsx)(`div`,{className:f,children:h}),t[38]=f,t[39]=h,t[40]=g):g=t[40];let y;return t[41]!==u||t[42]!==g?(y=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[u,g]}),t[41]=u,t[42]=g,t[43]=y):y=t[43],y}if(n.command!==null&&g){let e;t[44]!==n.displayName||t[45]!==n.toolName?(e=(0,$.jsx)(yo,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[44]=n.displayName,t[45]=n.toolName,t[46]=e):e=t[46];let r,i;t[47]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>u(!0),i=q(J.caption,`font-mono hover:underline break-all cursor-pointer`),t[47]=r,t[48]=i):(r=t[47],i=t[48]);let a;t[49]===n.command?a=t[50]:(a=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:r,className:i,children:n.command})}),t[49]=n.command,t[50]=a);let o;t[51]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(K,{children:`View output`}),t[51]=o):o=t[51];let s;t[52]===a?s=t[53]:(s=(0,$.jsxs)(W,{children:[a,o]}),t[52]=a,t[53]=s);let c;t[54]!==s||t[55]!==e?(c=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,s]}),t[54]=s,t[55]=e,t[56]=c):c=t[56];let d;t[57]!==n.command||t[58]!==l||t[59]!==g?(d=(0,$.jsx)(uo,{open:l,onOpenChange:u,title:n.command,content:g}),t[57]=n.command,t[58]=l,t[59]=g,t[60]=d):d=t[60];let f;return t[61]!==c||t[62]!==d?(f=(0,$.jsxs)($.Fragment,{children:[c,d]}),t[61]=c,t[62]=d,t[63]=f):f=t[63],f}let e;t[64]!==n.displayName||t[65]!==n.toolName?(e=(0,$.jsx)(yo,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[64]=n.displayName,t[65]=n.toolName,t[66]=e):e=t[66];let r;t[67]===n.command?r=t[68]:(r=n.command!==null&&(0,$.jsx)(`code`,{className:q(J.caption,`font-mono break-all rounded bg-muted/60 px-1 py-0.5`),children:n.command}),t[67]=n.command,t[68]=r);let i;return t[69]!==e||t[70]!==r?(i=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,r]}),t[69]=e,t[70]=r,t[71]=i):i=t[71],i}let C;t[72]===s?C=t[73]:(C=()=>c(!s),t[72]=s,t[73]=C);let w;t[74]===Symbol.for(`react.memo_cache_sentinel`)?(w=q(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[74]=w):w=t[74];let T;t[75]!==n.activeDisplayName||t[76]!==n.displayName||t[77]!==a||t[78]!==v?(T=a?(0,$.jsxs)($.Fragment,{children:[n.activeDisplayName,v&&(0,$.jsx)(`span`,{className:`ml-2 text-muted-foreground tabular-nums`,children:v})]}):n.displayName,t[75]=n.activeDisplayName,t[76]=n.displayName,t[77]=a,t[78]=v,t[79]=T):T=t[79];let E;t[80]===T?E=t[81]:(E=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:T}),t[80]=T,t[81]=E);let D;t[82]===s?D=t[83]:(D=s?(0,$.jsx)(Tt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(en,{className:`h-4 w-4 shrink-0`}),t[82]=s,t[83]=D);let O;t[84]!==E||t[85]!==D||t[86]!==C?(O=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:C,className:w,children:[E,D]})}),t[84]=E,t[85]=D,t[86]=C,t[87]=O):O=t[87];let k;t[88]===n.toolName?k=t[89]:(k=(0,$.jsx)(K,{children:n.toolName}),t[88]=n.toolName,t[89]=k);let A;t[90]!==O||t[91]!==k?(A=(0,$.jsxs)(W,{children:[O,k]}),t[90]=O,t[91]=k,t[92]=A):A=t[92];let j;t[93]!==n.toolId||t[94]!==n.toolInput||t[95]!==a||t[96]!==s||t[97]!==_?(j=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:q(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),a?(0,$.jsx)(`div`,{ref:o,className:q(J.caption,`text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto font-mono`),style:{maxHeight:`7.5em`},children:_}):n.toolInput?(0,$.jsx)(`pre`,{className:lo(),children:n.toolInput}):null]}),t[93]=n.toolId,t[94]=n.toolInput,t[95]=a,t[96]=s,t[97]=_,t[98]=j):j=t[98];let M;return t[99]!==A||t[100]!==j?(M=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[A,j]}),t[99]=A,t[100]=j,t[101]=M):M=t[101],M}function xo(e){let t=(0,X.c)(50),{data:n,inline:r,resultContent:i,isActive:a}=e,[o,s]=(0,Y.useState)(!!a),[c,l]=(0,Y.useState)(!1),u=n.fetchUrl,d;t[0]===i?d=t[1]:(d=i?So(i):null,t[0]=i,t[1]=d);let f=d;if(r){let e;t[2]===o?e=t[3]:(e=()=>s(!o),t[2]=o,t[3]=e);let r=n.toolName,c=n.activeDisplayName,l=!!a,d;t[4]!==n.activeDisplayName||t[5]!==n.toolName||t[6]!==l?(d=(0,$.jsx)(yo,{toolName:r,displayName:c,isActive:l}),t[4]=n.activeDisplayName,t[5]=n.toolName,t[6]=l,t[7]=d):d=t[7];let p;t[8]===u?p=t[9]:(p=u!==null&&(0,$.jsx)(`span`,{className:q(J.caption,`break-all`),children:u}),t[8]=u,t[9]=p);let m;t[10]===f?m=t[11]:(m=f&&(0,$.jsxs)(`span`,{className:q(J.caption,`text-muted-foreground shrink-0`),children:[f.bytes,` bytes · HTTP `,f.code]}),t[10]=f,t[11]=m);let h;t[12]===o?h=t[13]:(h=o?(0,$.jsx)(Tt,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(en,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[12]=o,t[13]=h);let g;t[14]!==o||t[15]!==e||t[16]!==d||t[17]!==p||t[18]!==m||t[19]!==h?(g=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full`,onClick:e,"aria-expanded":o,children:[d,p,m,h]}),t[14]=o,t[15]=e,t[16]=d,t[17]=p,t[18]=m,t[19]=h,t[20]=g):g=t[20];let _;t[21]!==o||t[22]!==i?(_=o&&i&&(0,$.jsx)(`pre`,{className:q(J.mono,J.caption,`whitespace-pre-wrap break-all rounded bg-muted/40 p-2 max-h-48 overflow-auto`),children:Co(i)}),t[21]=o,t[22]=i,t[23]=_):_=t[23];let v;return t[24]!==g||t[25]!==_?(v=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[g,_]}),t[24]=g,t[25]=_,t[26]=v):v=t[26],v}let p=n.toolName,m=n.displayName,h=!!a,g;t[27]!==n.displayName||t[28]!==n.toolName||t[29]!==h?(g=(0,$.jsx)(yo,{toolName:p,displayName:m,isActive:h}),t[27]=n.displayName,t[28]=n.toolName,t[29]=h,t[30]=g):g=t[30];let _;t[31]===u?_=t[32]:(_=u!==null&&(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`code`,{className:q(J.mono,J.caption,`break-all`),children:u})}),(0,$.jsx)(K,{children:u})]}),t[31]=u,t[32]=_);let v;t[33]===f?v=t[34]:(v=f&&(0,$.jsxs)(`span`,{className:q(J.caption,`text-muted-foreground`),children:[f.bytes,` bytes · HTTP `,f.code,` · `,f.durationMs,`ms`]}),t[33]=f,t[34]=v);let y;t[35]===i?y=t[36]:(y=i&&(0,$.jsx)(`button`,{type:`button`,className:q(J.caption,`text-brand hover:underline ml-auto`),onClick:()=>l(!0),children:`View result`}),t[35]=i,t[36]=y);let b;t[37]!==g||t[38]!==_||t[39]!==v||t[40]!==y?(b=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[g,_,v,y]}),t[37]=g,t[38]=_,t[39]=v,t[40]=y,t[41]=b):b=t[41];let x;t[42]===i?x=t[43]:(x=i?Co(i):``,t[42]=i,t[43]=x);let S;t[44]!==c||t[45]!==x?(S=(0,$.jsx)(uo,{open:c,onOpenChange:l,title:`Fetch result`,content:x}),t[44]=c,t[45]=x,t[46]=S):S=t[46];let C;return t[47]!==S||t[48]!==b?(C=(0,$.jsxs)(`div`,{className:`rounded-lg border border-border p-3 my-1`,children:[b,S]}),t[47]=S,t[48]=b,t[49]=C):C=t[49],C}function So(e){try{let t=JSON.parse(e);if(typeof t.bytes==`number`&&typeof t.code==`number`)return{bytes:t.bytes,code:t.code,durationMs:typeof t.durationMs==`number`?t.durationMs:0}}catch{}return null}function Co(e){try{let t=JSON.parse(e);if(typeof t.result==`string`)return t.result}catch{}return e}var wo=lr,To=ir,Eo=Y.forwardRef((e,t)=>{let n=(0,X.c)(13),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:r,align:a,sideOffset:o,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s=a===void 0?`center`:a,c=o===void 0?4:o,l;n[5]===r?l=n[6]:(l=q(`z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,r),n[5]=r,n[6]=l);let u;return n[7]!==s||n[8]!==i||n[9]!==t||n[10]!==c||n[11]!==l?(u=(0,$.jsx)(er,{children:(0,$.jsx)(Dn,{ref:t,align:s,sideOffset:c,className:l,...i})}),n[7]=s,n[8]=i,n[9]=t,n[10]=c,n[11]=l,n[12]=u):u=n[12],u});Eo.displayName=Dn.displayName;function Do(e){let t=(0,X.c)(6),{type:n,count:r}=e,i=n===`added`?`text-green-600 dark:text-green-400`:`text-red-600 dark:text-red-400`,a;t[0]===i?a=t[1]:(a=q(J.compact,`font-mono tabular-nums`,i),t[0]=i,t[1]=a);let o=n===`added`?`+`:`-`,s;return t[2]!==r||t[3]!==a||t[4]!==o?(s=(0,$.jsxs)(`span`,{className:a,children:[o,r]}),t[2]=r,t[3]=a,t[4]=o,t[5]=s):s=t[5],s}function Oo(e){let t=(0,X.c)(3),{offset:n,limit:r}=e;if(n===null&&r===null)return null;let i;i=n!==null&&r!==null?`${n}-${n+r}`:n===null?`${r}`:`${n}-`;let a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=q(J.compact,`font-mono tabular-nums text-muted-foreground`),t[0]=a):a=t[0];let o;return t[1]===i?o=t[2]:(o=(0,$.jsx)(`span`,{className:a,children:i}),t[1]=i,t[2]=o),o}function ko(e){let t=(0,X.c)(51),{data:n,inline:r,rootPath:i,onOpenFile:a}=e,[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(!1),u;t[0]!==n.filePath||t[1]!==a||t[2]!==i?(u=function(){!n.filePath||!a||a(i&&n.filePath.startsWith(i)?n.filePath.slice(i.length+1):n.filePath)},t[0]=n.filePath,t[1]=a,t[2]=i,t[3]=u):u=t[3];let d=u;if(r){let e=!!(n.toolInput&&!n.command&&!n.path&&!n.pattern&&!n.fileDisplayName),r;t[4]!==n.displayName||t[5]!==n.toolId||t[6]!==n.toolInput||t[7]!==n.toolName||t[8]!==e?(r=e?(0,$.jsxs)(wo,{children:[(0,$.jsx)(To,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex shrink-0 items-center gap-1 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Show tool details`,children:(0,$.jsx)(yo,{toolName:n.toolName,displayName:n.displayName,isActive:!1,muted:!1})})})}),(0,$.jsx)(Eo,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:q(J.caption,`space-y-2`),children:[(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),(0,$.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:n.toolInput})]})})]}):(0,$.jsx)(yo,{toolName:n.toolName,displayName:n.displayName,isActive:!1}),t[4]=n.displayName,t[5]=n.toolId,t[6]=n.toolInput,t[7]=n.toolName,t[8]=e,t[9]=r):r=t[9];let a;t[10]!==n.editAddedLineCount||t[11]!==n.editDeletedLineCount||t[12]!==n.editNewText||t[13]!==n.editOldText||t[14]!==n.fileDisplayName||t[15]!==n.filePath||t[16]!==n.hasEditDiff||t[17]!==n.limit||t[18]!==n.offset||t[19]!==n.path||t[20]!==n.toolName||t[21]!==c||t[22]!==d||t[23]!==i?(a=n.fileDisplayName?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,onClick:n.hasEditDiff?()=>l(!0):d,className:q(`inline-flex max-w-full items-center gap-2 cursor-pointer`,J.caption,`font-mono hover:underline`),children:[(0,$.jsx)(`span`,{className:`truncate max-w-[200px] sm:max-w-[320px]`,children:n.fileDisplayName}),n.toolName===`read`?(0,$.jsx)(Oo,{offset:n.offset,limit:n.limit}):null,n.hasEditDiff?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 shrink-0`,children:[n.editAddedLineCount===null?null:(0,$.jsx)(Do,{type:`added`,count:n.editAddedLineCount}),n.editDeletedLineCount===null?null:(0,$.jsx)(Do,{type:`deleted`,count:n.editDeletedLineCount})]}):null]})}),(0,$.jsx)(K,{children:n.hasEditDiff?`View diff`:n.filePath?Wa(n.filePath,i)??n.filePath:n.fileDisplayName})]}),n.hasEditDiff&&(0,$.jsx)(g,{open:c,onOpenChange:l,children:(0,$.jsxs)(H,{className:`max-w-2xl h-[80vh] flex flex-col`,children:[(0,$.jsx)(xt,{children:(0,$.jsx)(z,{children:(0,$.jsx)(`code`,{className:q(J.caption,`font-mono`),children:Wa(n.filePath,i)??n.filePath})})}),(0,$.jsx)(`div`,{className:`overflow-auto flex-1 rounded border border-border bg-muted/30 p-3`,children:(0,$.jsx)(fo,{oldText:n.editOldText,newText:n.editNewText})})]})})]}):n.path===null?null:(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`span`,{className:q(J.caption,`font-mono truncate max-w-[200px] sm:max-w-[320px]`),children:n.path})}),(0,$.jsx)(K,{children:n.path})]}),t[10]=n.editAddedLineCount,t[11]=n.editDeletedLineCount,t[12]=n.editNewText,t[13]=n.editOldText,t[14]=n.fileDisplayName,t[15]=n.filePath,t[16]=n.hasEditDiff,t[17]=n.limit,t[18]=n.offset,t[19]=n.path,t[20]=n.toolName,t[21]=c,t[22]=d,t[23]=i,t[24]=a):a=t[24];let o;return t[25]!==r||t[26]!==a?(o=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[r,a]}),t[25]=r,t[26]=a,t[27]=o):o=t[27],o}let f;t[28]===o?f=t[29]:(f=()=>s(!o),t[28]=o,t[29]=f);let p;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(p=q(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[30]=p):p=t[30];let m;t[31]===n.displayName?m=t[32]:(m=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[31]=n.displayName,t[32]=m);let h;t[33]===o?h=t[34]:(h=o?(0,$.jsx)(Tt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(en,{className:`h-4 w-4 shrink-0`}),t[33]=o,t[34]=h);let _;t[35]!==f||t[36]!==m||t[37]!==h?(_=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:f,className:p,children:[m,h]})}),t[35]=f,t[36]=m,t[37]=h,t[38]=_):_=t[38];let v;t[39]===n.toolName?v=t[40]:(v=(0,$.jsx)(K,{children:n.toolName}),t[39]=n.toolName,t[40]=v);let y;t[41]!==_||t[42]!==v?(y=(0,$.jsxs)(W,{children:[_,v]}),t[41]=_,t[42]=v,t[43]=y):y=t[43];let b;t[44]!==n.toolId||t[45]!==n.toolInput||t[46]!==o?(b=o&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:q(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:lo(),children:n.toolInput}):null]}),t[44]=n.toolId,t[45]=n.toolInput,t[46]=o,t[47]=b):b=t[47];let x;return t[48]!==y||t[49]!==b?(x=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[y,b]}),t[48]=y,t[49]=b,t[50]=x):x=t[50],x}function Ao(e){let t=(0,X.c)(7),{data:n}=e,r=n.toolName===`code_search`,i;return t[0]!==n.codeSearchFileGlob||t[1]!==n.codeSearchFilePath||t[2]!==n.codeSearchQuery||t[3]!==n.pattern||t[4]!==n.webSearchQuery||t[5]!==r?(i=(0,$.jsx)($.Fragment,{children:r?(0,$.jsxs)($.Fragment,{children:[n.codeSearchQuery!==null&&(0,$.jsx)(_o,{children:n.codeSearchQuery}),n.pattern!==null&&(0,$.jsxs)(_o,{children:[`/`,n.pattern,`/`]}),n.codeSearchFilePath!==null&&(0,$.jsx)(_o,{children:n.codeSearchFilePath}),n.codeSearchFileGlob!==null&&(0,$.jsx)(_o,{children:n.codeSearchFileGlob})]}):(0,$.jsxs)($.Fragment,{children:[n.webSearchQuery!==null&&(0,$.jsx)(_o,{children:n.webSearchQuery}),n.pattern!==null&&(0,$.jsx)(_o,{children:n.pattern})]})}),t[0]=n.codeSearchFileGlob,t[1]=n.codeSearchFilePath,t[2]=n.codeSearchQuery,t[3]=n.pattern,t[4]=n.webSearchQuery,t[5]=r,t[6]=i):i=t[6],i}function jo(e){let t=(0,X.c)(68),{data:n,inline:r,resultContent:i,isActive:a}=e,[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(!1),u=n.toolName===`code_search`,d=n.webSearchQuery??n.codeSearchQuery??n.pattern??n.codeSearchFilePath??n.codeSearchFileGlob??`search`;if(r){if(i&&(u||n.toolName===`find`||n.webSearchQuery!==null||n.pattern!==null)){let e;t[0]!==n.displayName||t[1]!==n.toolName||t[2]!==a?(e=(0,$.jsx)(yo,{toolName:n.toolName,displayName:n.displayName,isActive:a}),t[0]=n.displayName,t[1]=n.toolName,t[2]=a,t[3]=e):e=t[3];let r,o;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>l(!0),o=q(J.caption,`font-mono hover:underline break-all cursor-pointer`),t[4]=r,t[5]=o):(r=t[4],o=t[5]);let s;t[6]===d?s=t[7]:(s=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:r,className:o,children:d})}),t[6]=d,t[7]=s);let u;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(K,{children:`View results`}),t[8]=u):u=t[8];let f;t[9]===s?f=t[10]:(f=(0,$.jsxs)(W,{children:[s,u]}),t[9]=s,t[10]=f);let p;t[11]!==e||t[12]!==f?(p=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,f]}),t[11]=e,t[12]=f,t[13]=p):p=t[13];let m;t[14]!==c||t[15]!==i||t[16]!==d?(m=(0,$.jsx)(uo,{open:c,onOpenChange:l,title:d,content:i}),t[14]=c,t[15]=i,t[16]=d,t[17]=m):m=t[17];let h;return t[18]!==p||t[19]!==m?(h=(0,$.jsxs)($.Fragment,{children:[p,m]}),t[18]=p,t[19]=m,t[20]=h):h=t[20],h}let e;t[21]!==n.displayName||t[22]!==n.toolName||t[23]!==a?(e=(0,$.jsx)(yo,{toolName:n.toolName,displayName:n.displayName,isActive:a}),t[21]=n.displayName,t[22]=n.toolName,t[23]=a,t[24]=e):e=t[24];let r;t[25]===n?r=t[26]:(r=(0,$.jsx)(Ao,{data:n}),t[25]=n,t[26]=r);let o;t[27]===n.lang?o=t[28]:(o=n.lang!==null&&(0,$.jsx)(`span`,{className:q(J.caption,`px-1.5 py-0.5 rounded bg-muted`),children:n.lang}),t[27]=n.lang,t[28]=o);let s;return t[29]!==e||t[30]!==r||t[31]!==o?(s=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,r,o]}),t[29]=e,t[30]=r,t[31]=o,t[32]=s):s=t[32],s}let f;t[33]===o?f=t[34]:(f=()=>s(!o),t[33]=o,t[34]=f);let p;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(p=q(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[35]=p):p=t[35];let m;t[36]===a?m=t[37]:(m=a&&(0,$.jsx)(vo,{size:`md`}),t[36]=a,t[37]=m);let h;t[38]===n.displayName?h=t[39]:(h=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[38]=n.displayName,t[39]=h);let g;t[40]!==n.codeSearchFileGlob||t[41]!==n.codeSearchFilePath||t[42]!==n.codeSearchQuery||t[43]!==n.pattern||t[44]!==u?(g=u&&(0,$.jsxs)($.Fragment,{children:[n.codeSearchQuery!==null&&(0,$.jsx)(`code`,{className:q(J.caption,`font-mono bg-muted rounded px-1 py-0.5 truncate max-w-[150px]`),children:n.codeSearchQuery}),n.pattern!==null&&(0,$.jsxs)(`code`,{className:q(J.caption,`font-mono bg-muted rounded px-1 py-0.5 truncate max-w-[150px]`),children:[`/`,n.pattern,`/`]}),n.codeSearchFilePath!==null&&(0,$.jsx)(`code`,{className:q(J.caption,`font-mono bg-muted rounded px-1 py-0.5 truncate max-w-[150px]`),children:n.codeSearchFilePath}),n.codeSearchFileGlob!==null&&(0,$.jsx)(`code`,{className:q(J.caption,`font-mono bg-muted rounded px-1 py-0.5 truncate max-w-[150px]`),children:n.codeSearchFileGlob})]}),t[40]=n.codeSearchFileGlob,t[41]=n.codeSearchFilePath,t[42]=n.codeSearchQuery,t[43]=n.pattern,t[44]=u,t[45]=g):g=t[45];let _;t[46]===o?_=t[47]:(_=o?(0,$.jsx)(Tt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(en,{className:`h-4 w-4 shrink-0`}),t[46]=o,t[47]=_);let v;t[48]!==f||t[49]!==m||t[50]!==h||t[51]!==g||t[52]!==_?(v=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:f,className:p,children:[m,h,g,_]})}),t[48]=f,t[49]=m,t[50]=h,t[51]=g,t[52]=_,t[53]=v):v=t[53];let y;t[54]===n.toolName?y=t[55]:(y=(0,$.jsx)(K,{children:n.toolName}),t[54]=n.toolName,t[55]=y);let b;t[56]!==v||t[57]!==y?(b=(0,$.jsxs)(W,{children:[v,y]}),t[56]=v,t[57]=y,t[58]=b):b=t[58];let x;t[59]!==n.toolId||t[60]!==n.toolInput||t[61]!==o||t[62]!==u||t[63]!==i?(x=o&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:q(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:lo(),children:n.toolInput}):null,u&&i&&(0,$.jsx)(`pre`,{className:lo({maxHeight:`64`,className:`mt-2`}),children:i})]}),t[59]=n.toolId,t[60]=n.toolInput,t[61]=o,t[62]=u,t[63]=i,t[64]=x):x=t[64];let S;return t[65]!==x||t[66]!==b?(S=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[b,x]}),t[65]=x,t[66]=b,t[67]=S):S=t[67],S}function Mo(e){let t=(0,X.c)(134),{data:n,inline:r,resultContent:i,isActive:a}=e,o=(0,Y.useRef)(null),[s,c]=(0,Y.useState)(!!a),[l,u]=(0,Y.useState)(!1),d=(0,Y.useRef)(!!a),f;t[0]===n.toolId?f=t[1]:(f=e=>e.toolCallProgress[n.toolId]?.executionOutput,t[0]=n.toolId,t[1]=f);let p=Q(f),m=a?p??i??``:i??p??``,h;t[2]===m?h=t[3]:(h=m?Ha(m):``,t[2]=m,t[3]=h);let g=h,_=a?g:``,v,y;t[4]===a?(v=t[5],y=t[6]):(v=()=>{a&&!d.current?c(!0):!a&&d.current&&c(!1),d.current=!!a},y=[a],t[4]=a,t[5]=v,t[6]=y),(0,Y.useEffect)(v,y);let b;t[7]!==s||t[8]!==a?(b=()=>{s&&a&&o.current&&(o.current.scrollTop=o.current.scrollHeight)},t[7]=s,t[8]=a,t[9]=b):b=t[9];let x;if(t[10]!==s||t[11]!==a||t[12]!==_?(x=[s,a,_],t[10]=s,t[11]=a,t[12]=_,t[13]=x):x=t[13],(0,Y.useEffect)(b,x),r){if(a){let e;t[14]===s?e=t[15]:(e=()=>c(!s),t[14]=s,t[15]=e);let r;t[16]!==n.activeDisplayName||t[17]!==n.toolName?(r=(0,$.jsx)(yo,{toolName:n.toolName,displayName:n.activeDisplayName,isActive:!0}),t[16]=n.activeDisplayName,t[17]=n.toolName,t[18]=r):r=t[18];let i;t[19]===n.agentName?i=t[20]:(i=n.agentName&&(0,$.jsx)(ho,{name:n.agentName}),t[19]=n.agentName,t[20]=i);let a;t[21]===n.subagentType?a=t[22]:(a=n.subagentType&&(0,$.jsx)(go,{type:n.subagentType}),t[21]=n.subagentType,t[22]=a);let l;t[23]===s?l=t[24]:(l=s?(0,$.jsx)(Tt,{className:`h-3 w-3 text-muted-foreground shrink-0`}):(0,$.jsx)(en,{className:`h-3 w-3 text-muted-foreground shrink-0`}),t[23]=s,t[24]=l);let u;t[25]!==s||t[26]!==a||t[27]!==l||t[28]!==e||t[29]!==r||t[30]!==i?(u=(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full`,onClick:e,"aria-expanded":s,children:[r,i,a,l]}),t[25]=s,t[26]=a,t[27]=l,t[28]=e,t[29]=r,t[30]=i,t[31]=u):u=t[31];let d=s?`grid-rows-[1fr]`:`grid-rows-[0fr]`,f;t[32]===d?f=t[33]:(f=q(`grid transition-[grid-template-rows] duration-200 ease-in-out`,d),t[32]=d,t[33]=f);let p,m;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(p=q(J.caption,`ml-5 text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto`),m={maxHeight:`7.5em`},t[34]=p,t[35]=m):(p=t[34],m=t[35]);let h=_||`Running subagent...`,g;t[36]===h?g=t[37]:(g=(0,$.jsx)(`div`,{className:`overflow-hidden`,children:(0,$.jsx)(`div`,{ref:o,className:p,style:m,children:h})}),t[36]=h,t[37]=g);let v;t[38]!==f||t[39]!==g?(v=(0,$.jsx)(`div`,{className:f,children:g}),t[38]=f,t[39]=g,t[40]=v):v=t[40];let y;return t[41]!==u||t[42]!==v?(y=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[u,v]}),t[41]=u,t[42]=v,t[43]=y):y=t[43],y}if(g){let e;t[44]!==n.displayName||t[45]!==n.toolName?(e=(0,$.jsx)(To,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex shrink-0 items-center gap-1 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Show tool details`,children:(0,$.jsx)(yo,{toolName:n.toolName,displayName:n.displayName,isActive:!1})})})}),t[44]=n.displayName,t[45]=n.toolName,t[46]=e):e=t[46];let r;t[47]===Symbol.for(`react.memo_cache_sentinel`)?(r=q(J.caption,`space-y-2`),t[47]=r):r=t[47];let i;t[48]===n.toolId?i=t[49]:(i=(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),t[48]=n.toolId,t[49]=i);let a;t[50]!==n.prompt||t[51]!==n.toolInput?(a=n.prompt?(0,$.jsx)(`div`,{className:`whitespace-pre-wrap leading-relaxed`,children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:n.toolInput}):null,t[50]=n.prompt,t[51]=n.toolInput,t[52]=a):a=t[52];let o;t[53]!==a||t[54]!==i?(o=(0,$.jsx)(Eo,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:r,children:[i,a]})}),t[53]=a,t[54]=i,t[55]=o):o=t[55];let s;t[56]!==o||t[57]!==e?(s=(0,$.jsxs)(wo,{children:[e,o]}),t[56]=o,t[57]=e,t[58]=s):s=t[58];let c;t[59]===n.agentName?c=t[60]:(c=n.agentName&&(0,$.jsx)(ho,{name:n.agentName}),t[59]=n.agentName,t[60]=c);let d;t[61]===n.subagentType?d=t[62]:(d=n.subagentType&&(0,$.jsx)(go,{type:n.subagentType}),t[61]=n.subagentType,t[62]=d);let f;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>u(!0),className:q(J.caption,`text-muted-foreground hover:underline`),children:`View output`})}),(0,$.jsx)(K,{children:`View subagent output`})]}),t[63]=f):f=t[63];let p;t[64]!==s||t[65]!==c||t[66]!==d?(p=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[s,c,d,f]}),t[64]=s,t[65]=c,t[66]=d,t[67]=p):p=t[67];let m;t[68]!==n.displayName||t[69]!==l||t[70]!==g?(m=(0,$.jsx)(uo,{open:l,onOpenChange:u,title:n.displayName,content:g}),t[68]=n.displayName,t[69]=l,t[70]=g,t[71]=m):m=t[71];let h;return t[72]!==p||t[73]!==m?(h=(0,$.jsxs)($.Fragment,{children:[p,m]}),t[72]=p,t[73]=m,t[74]=h):h=t[74],h}let e;t[75]!==n.displayName||t[76]!==n.toolName?(e=(0,$.jsx)(To,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex shrink-0 items-center gap-1 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Show tool details`,children:(0,$.jsx)(yo,{toolName:n.toolName,displayName:n.displayName,isActive:!1,muted:!1})})})}),t[75]=n.displayName,t[76]=n.toolName,t[77]=e):e=t[77];let r;t[78]===Symbol.for(`react.memo_cache_sentinel`)?(r=q(J.caption,`space-y-2`),t[78]=r):r=t[78];let i;t[79]===n.toolId?i=t[80]:(i=(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),t[79]=n.toolId,t[80]=i);let d;t[81]!==n.prompt||t[82]!==n.toolInput?(d=n.prompt?(0,$.jsx)(`div`,{className:`whitespace-pre-wrap leading-relaxed`,children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:n.toolInput}):null,t[81]=n.prompt,t[82]=n.toolInput,t[83]=d):d=t[83];let f;t[84]!==d||t[85]!==i?(f=(0,$.jsx)(Eo,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:r,children:[i,d]})}),t[84]=d,t[85]=i,t[86]=f):f=t[86];let p;t[87]!==f||t[88]!==e?(p=(0,$.jsxs)(wo,{children:[e,f]}),t[87]=f,t[88]=e,t[89]=p):p=t[89];let m;t[90]===n.agentName?m=t[91]:(m=n.agentName&&(0,$.jsx)(ho,{name:n.agentName}),t[90]=n.agentName,t[91]=m);let h;t[92]===n.subagentType?h=t[93]:(h=n.subagentType&&(0,$.jsx)(go,{type:n.subagentType}),t[92]=n.subagentType,t[93]=h);let v;return t[94]!==p||t[95]!==m||t[96]!==h?(v=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[p,m,h]}),t[94]=p,t[95]=m,t[96]=h,t[97]=v):v=t[97],v}let S;t[98]===s?S=t[99]:(S=()=>c(!s),t[98]=s,t[99]=S);let C;t[100]===Symbol.for(`react.memo_cache_sentinel`)?(C=q(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[100]=C):C=t[100];let w;t[101]===a?w=t[102]:(w=a&&(0,$.jsx)(vo,{size:`md`}),t[101]=a,t[102]=w);let T=a?n.activeDisplayName:n.displayName,E;t[103]===T?E=t[104]:(E=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:T}),t[103]=T,t[104]=E);let D;t[105]===n.agentName?D=t[106]:(D=n.agentName&&(0,$.jsx)(ho,{name:n.agentName}),t[105]=n.agentName,t[106]=D);let O;t[107]===n.subagentType?O=t[108]:(O=n.subagentType&&(0,$.jsx)(go,{type:n.subagentType}),t[107]=n.subagentType,t[108]=O);let k;t[109]===s?k=t[110]:(k=s?(0,$.jsx)(Tt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(en,{className:`h-4 w-4 shrink-0`}),t[109]=s,t[110]=k);let A;t[111]!==E||t[112]!==D||t[113]!==O||t[114]!==k||t[115]!==S||t[116]!==w?(A=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:S,className:C,children:[w,E,D,O,k]})}),t[111]=E,t[112]=D,t[113]=O,t[114]=k,t[115]=S,t[116]=w,t[117]=A):A=t[117];let j;t[118]===n.toolName?j=t[119]:(j=(0,$.jsx)(K,{children:n.toolName}),t[118]=n.toolName,t[119]=j);let M;t[120]!==A||t[121]!==j?(M=(0,$.jsxs)(W,{children:[A,j]}),t[120]=A,t[121]=j,t[122]=M):M=t[122];let N;t[123]!==n.prompt||t[124]!==n.toolId||t[125]!==n.toolInput||t[126]!==g||t[127]!==s||t[128]!==a||t[129]!==_?(N=s&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:q(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),a?(0,$.jsx)(`div`,{ref:o,className:q(J.caption,`text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto`),style:{maxHeight:`7.5em`},children:_||`Running subagent...`}):n.prompt?(0,$.jsx)(`div`,{className:lo({maxHeight:`64`,padding:`3`,leading:!0}),children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:lo(),children:n.toolInput}):g?(0,$.jsx)(`div`,{className:lo({maxHeight:`64`,padding:`3`,leading:!0}),children:g}):null]}),t[123]=n.prompt,t[124]=n.toolId,t[125]=n.toolInput,t[126]=g,t[127]=s,t[128]=a,t[129]=_,t[130]=N):N=t[130];let P;return t[131]!==M||t[132]!==N?(P=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[M,N]}),t[131]=M,t[132]=N,t[133]=P):P=t[133],P}function No(e){let t=(0,X.c)(26),{data:n,inline:r,isActive:i}=e,[a,o]=(0,Y.useState)(!1);if(r)return null;let s;t[0]===a?s=t[1]:(s=()=>o(!a),t[0]=a,t[1]=s);let c;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=q(J.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),t[2]=c):c=t[2];let l;t[3]===i?l=t[4]:(l=i&&(0,$.jsx)(vo,{size:`md`}),t[3]=i,t[4]=l);let u;t[5]===n.displayName?u=t[6]:(u=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[5]=n.displayName,t[6]=u);let d;t[7]===a?d=t[8]:(d=a?(0,$.jsx)(Tt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(en,{className:`h-4 w-4 shrink-0`}),t[7]=a,t[8]=d);let f;t[9]!==s||t[10]!==l||t[11]!==u||t[12]!==d?(f=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:s,className:c,children:[l,u,d]})}),t[9]=s,t[10]=l,t[11]=u,t[12]=d,t[13]=f):f=t[13];let p;t[14]===n.toolName?p=t[15]:(p=(0,$.jsx)(K,{children:n.toolName}),t[14]=n.toolName,t[15]=p);let m;t[16]!==f||t[17]!==p?(m=(0,$.jsxs)(W,{children:[f,p]}),t[16]=f,t[17]=p,t[18]=m):m=t[18];let h;t[19]!==n.toolId||t[20]!==n.toolInput||t[21]!==a?(h=a&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:q(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:lo(),children:n.toolInput}):null]}),t[19]=n.toolId,t[20]=n.toolInput,t[21]=a,t[22]=h):h=t[22];let g;return t[23]!==m||t[24]!==h?(g=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[m,h]}),t[23]=m,t[24]=h,t[25]=g):g=t[25],g}function Po(e){let t=(0,X.c)(35),{data:n,inline:r,isActive:i}=e,[a,o]=(0,Y.useState)(!1);if(r){let e;t[0]!==n.displayName||t[1]!==n.toolName||t[2]!==i?(e=(0,$.jsx)(yo,{toolName:n.toolName,displayName:n.displayName,isActive:i}),t[0]=n.displayName,t[1]=n.toolName,t[2]=i,t[3]=e):e=t[3];let r;t[4]===n.imageGenPrompt?r=t[5]:(r=n.imageGenPrompt!==null&&(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`span`,{className:q(J.caption,`truncate max-w-[200px] sm:max-w-[320px]`),children:n.imageGenPrompt})}),(0,$.jsx)(K,{children:n.imageGenPrompt})]}),t[4]=n.imageGenPrompt,t[5]=r);let a;return t[6]!==e||t[7]!==r?(a=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[e,r]}),t[6]=e,t[7]=r,t[8]=a):a=t[8],a}let s;t[9]===a?s=t[10]:(s=()=>o(!a),t[9]=a,t[10]=s);let c;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(c=q(J.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),t[11]=c):c=t[11];let l;t[12]===i?l=t[13]:(l=i&&(0,$.jsx)(vo,{size:`md`}),t[12]=i,t[13]=l);let u;t[14]===n.displayName?u=t[15]:(u=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[14]=n.displayName,t[15]=u);let d;t[16]===a?d=t[17]:(d=a?(0,$.jsx)(Tt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(en,{className:`h-4 w-4 shrink-0`}),t[16]=a,t[17]=d);let f;t[18]!==s||t[19]!==l||t[20]!==u||t[21]!==d?(f=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:s,className:c,children:[l,u,d]})}),t[18]=s,t[19]=l,t[20]=u,t[21]=d,t[22]=f):f=t[22];let p;t[23]===n.toolName?p=t[24]:(p=(0,$.jsx)(K,{children:n.toolName}),t[23]=n.toolName,t[24]=p);let m;t[25]!==f||t[26]!==p?(m=(0,$.jsxs)(W,{children:[f,p]}),t[25]=f,t[26]=p,t[27]=m):m=t[27];let h;t[28]!==n.toolId||t[29]!==n.toolInput||t[30]!==a?(h=a&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:q(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.toolInput?(0,$.jsx)(`pre`,{className:lo(),children:n.toolInput}):null]}),t[28]=n.toolId,t[29]=n.toolInput,t[30]=a,t[31]=h):h=t[31];let g;return t[32]!==m||t[33]!==h?(g=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[m,h]}),t[32]=m,t[33]=h,t[34]=g):g=t[34],g}function Fo(e){let t=(0,X.c)(40),{data:n,inline:r,isActive:i}=e,[a,o]=(0,Y.useState)(!1);if(r){let e=!!(n.prompt??(n.toolInput&&!n.command&&!n.path&&!n.pattern&&!n.fileDisplayName)),r;t[0]!==n.displayName||t[1]!==n.prompt||t[2]!==n.toolId||t[3]!==n.toolInput||t[4]!==n.toolName||t[5]!==e||t[6]!==i?(r=e?(0,$.jsxs)(wo,{children:[(0,$.jsx)(To,{asChild:!0,children:(0,$.jsx)(`span`,{className:`inline-flex`,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex shrink-0 items-center gap-1 rounded p-0.5 text-muted-foreground hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":`Show tool details`,children:(0,$.jsx)(yo,{toolName:n.toolName,displayName:n.displayName,isActive:i,muted:!1})})})}),(0,$.jsx)(Eo,{className:`w-80 max-h-80 overflow-auto`,align:`start`,children:(0,$.jsxs)(`div`,{className:q(J.bodyMuted,`space-y-2`),children:[(0,$.jsxs)(`div`,{className:`font-mono`,children:[`ID: `,n.toolId]}),n.prompt?(0,$.jsx)(`div`,{className:`whitespace-pre-wrap leading-relaxed`,children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:`font-mono whitespace-pre-wrap overflow-auto max-h-48`,children:n.toolInput}):null]})})]}):(0,$.jsx)(yo,{toolName:n.toolName,displayName:n.displayName,isActive:i}),t[0]=n.displayName,t[1]=n.prompt,t[2]=n.toolId,t[3]=n.toolInput,t[4]=n.toolName,t[5]=e,t[6]=i,t[7]=r):r=t[7];let a;t[8]===n.path?a=t[9]:(a=n.path!==null&&(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`span`,{className:q(J.caption,`font-mono truncate max-w-[200px] sm:max-w-[320px]`),children:n.path})}),(0,$.jsx)(K,{children:n.path})]}),t[8]=n.path,t[9]=a);let o;return t[10]!==r||t[11]!==a?(o=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[r,a]}),t[10]=r,t[11]=a,t[12]=o):o=t[12],o}let s;t[13]===a?s=t[14]:(s=()=>o(!a),t[13]=a,t[14]=s);let c;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(c=q(J.body,`w-full py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted/50 transition-colors text-left`),t[15]=c):c=t[15];let l;t[16]===i?l=t[17]:(l=i&&(0,$.jsx)(vo,{size:`md`}),t[16]=i,t[17]=l);let u;t[18]===n.displayName?u=t[19]:(u=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:n.displayName}),t[18]=n.displayName,t[19]=u);let d;t[20]===a?d=t[21]:(d=a?(0,$.jsx)(Tt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(en,{className:`h-4 w-4 shrink-0`}),t[20]=a,t[21]=d);let f;t[22]!==s||t[23]!==l||t[24]!==u||t[25]!==d?(f=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:s,className:c,children:[l,u,d]})}),t[22]=s,t[23]=l,t[24]=u,t[25]=d,t[26]=f):f=t[26];let p;t[27]===n.toolName?p=t[28]:(p=(0,$.jsx)(K,{children:n.toolName}),t[27]=n.toolName,t[28]=p);let m;t[29]!==f||t[30]!==p?(m=(0,$.jsxs)(W,{children:[f,p]}),t[29]=f,t[30]=p,t[31]=m):m=t[31];let h;t[32]!==n.prompt||t[33]!==n.toolId||t[34]!==n.toolInput||t[35]!==a?(h=a&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border`,children:[(0,$.jsxs)(`div`,{className:q(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`ID: `,n.toolId]}),n.prompt?(0,$.jsx)(`div`,{className:lo({maxHeight:`64`,padding:`3`,leading:!0}),children:n.prompt}):n.toolInput?(0,$.jsx)(`pre`,{className:lo(),children:n.toolInput}):null]}),t[32]=n.prompt,t[33]=n.toolId,t[34]=n.toolInput,t[35]=a,t[36]=h):h=t[36];let g;return t[37]!==m||t[38]!==h?(g=(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[m,h]}),t[37]=m,t[38]=h,t[39]=g):g=t[39],g}function Io(e){let t=(0,X.c)(41),{block:n,inline:r,resultContent:i,isActive:a}=e,{setPendingExplorerPath:o,setActiveMainTab:s}=Fa(),c=Q(Lo),l=Xa(n,c),u=!!a,d;t[0]!==s||t[1]!==o?(d=function(e){o(e),s(`explorer`)},t[0]=s,t[1]=o,t[2]=d):d=t[2];let f=d;switch(l.toolType){case`bash`:{let e;return t[3]!==l||t[4]!==r||t[5]!==u||t[6]!==i?(e=(0,$.jsx)(bo,{data:l,inline:r,resultContent:i,isActive:u}),t[3]=l,t[4]=r,t[5]=u,t[6]=i,t[7]=e):e=t[7],e}case`fetch`:{let e;return t[8]!==l||t[9]!==r||t[10]!==u||t[11]!==i?(e=(0,$.jsx)(xo,{data:l,inline:r,resultContent:i,isActive:u}),t[8]=l,t[9]=r,t[10]=u,t[11]=i,t[12]=e):e=t[12],e}case`file`:{let e;return t[13]!==l||t[14]!==f||t[15]!==r||t[16]!==u||t[17]!==c?(e=(0,$.jsx)(ko,{data:l,inline:r,rootPath:c,onOpenFile:f,isActive:u}),t[13]=l,t[14]=f,t[15]=r,t[16]=u,t[17]=c,t[18]=e):e=t[18],e}case`search`:{let e;return t[19]!==l||t[20]!==r||t[21]!==u||t[22]!==i?(e=(0,$.jsx)(jo,{data:l,inline:r,resultContent:i,isActive:u}),t[19]=l,t[20]=r,t[21]=u,t[22]=i,t[23]=e):e=t[23],e}case`agent`:{let e;return t[24]!==l||t[25]!==r||t[26]!==u||t[27]!==i?(e=(0,$.jsx)(Mo,{data:l,inline:r,resultContent:i,isActive:u}),t[24]=l,t[25]=r,t[26]=u,t[27]=i,t[28]=e):e=t[28],e}case`todo`:{let e;return t[29]!==l||t[30]!==r||t[31]!==u?(e=(0,$.jsx)(No,{data:l,inline:r,isActive:u}),t[29]=l,t[30]=r,t[31]=u,t[32]=e):e=t[32],e}case`imageGen`:{let e;return t[33]!==l||t[34]!==r||t[35]!==u?(e=(0,$.jsx)(Po,{data:l,inline:r,isActive:u}),t[33]=l,t[34]=r,t[35]=u,t[36]=e):e=t[36],e}default:{let e;return t[37]!==l||t[38]!==r||t[39]!==u?(e=(0,$.jsx)(Fo,{data:l,inline:r,isActive:u}),t[37]=l,t[38]=r,t[39]=u,t[40]=e):e=t[40],e}}}function Lo(e){return e.projects.find(t=>t.projectId===e.selectedProjectId)?.threads.find(t=>t.threadId===e.selectedThreadId)?.path}var Ro=(0,Y.createContext)({todos:[],setTodos:()=>{}});function zo(e){let t=(0,X.c)(10),{children:n,threadId:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=[],t[0]=i):i=t[0];let[a,o]=(0,Y.useState)(i),s=(0,Y.useRef)(-1),c;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(c=(e,t)=>{t>=s.current&&(s.current=t,o(e))},t[1]=c):c=t[1];let l=c,u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>{s.current=-1,o([])},t[2]=u):u=t[2];let d;t[3]===r?d=t[4]:(d=[r],t[3]=r,t[4]=d),(0,Y.useEffect)(u,d);let f;t[5]===a?f=t[6]:(f={todos:a,setTodos:l},t[5]=a,t[6]=f);let p;return t[7]!==n||t[8]!==f?(p=(0,$.jsx)(Ro.Provider,{value:f,children:n}),t[7]=n,t[8]=f,t[9]=p):p=t[9],p}function Bo(e){let t=[e.result,e.content],n=[];for(let e of t)if(typeof e==`string`)n.push(e);else if(Array.isArray(e))for(let t of e)typeof t==`object`&&t&&`text`in t&&typeof t.text==`string`&&n.push(t.text);for(let e of n){let t=e.trim();if(t.startsWith(`{`))try{let e=JSON.parse(t);if(e&&Array.isArray(e.todos))return e.todos}catch(e){console.error(`Failed to parse todo JSON:`,e)}}return null}function Vo(e){let t=(0,X.c)(5),{todos:n,sequence:r}=e,{setTodos:i}=(0,Y.useContext)(Ro),a,o;return t[0]!==r||t[1]!==i||t[2]!==n?(a=()=>{i(n,r)},o=[n,i,r],t[0]=r,t[1]=i,t[2]=n,t[3]=a,t[4]=o):(a=t[3],o=t[4]),(0,Y.useEffect)(a,o),null}var Ho=Cr(e=>(0,$.jsxs)(`div`,{className:`mb-3 relative group/img inline-block max-w-full`,children:[(0,$.jsx)(`img`,{src:e.v0,alt:`Generated image`,className:`max-w-full rounded-lg block`,style:e.v1}),(0,$.jsx)(`div`,{className:`absolute top-2 right-2 flex gap-1 opacity-0 group-hover/img:opacity-100 transition-opacity`,children:e.v2})]}),{name:`GeneratedImageResult_1`,portals:[`v2`]}),Uo=function(e){let t=(0,X.c)(27),{imageUrl:n,imageData:r}=e,[i,a]=(0,Y.useState)(!1),o=r?`data:image/png;base64,${r}`:n??``,s;t[0]===o?s=t[1]:(s=async()=>{let e=`generated-image-${Date.now()}.png`,{path:t}=await Ue(o.startsWith(`data:`)?{imageData:o.replace(/^data:[^;]+;base64,/,``),filename:e}:{imageUrl:o,filename:e});Ii({title:`Saved to downloads: ${t.split(`/`).pop()}`})},t[0]=o,t[1]=s);let c=s,l;t[2]===o?l=t[3]:(l=async()=>{await We(o.startsWith(`data:`)?{imageData:o.replace(/^data:[^;]+;base64,/,``)}:{imageUrl:o}),a(!0),setTimeout(()=>a(!1),2e3)},t[2]=o,t[3]=l);let u=l;if(!o)return null;let d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d={maxHeight:`512px`},t[4]=d):d=t[4];let f;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(Ie,{className:`h-3.5 w-3.5`}),t[5]=f):f=t[5];let p;t[6]===c?p=t[7]:(p=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:c,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:f})}),t[6]=c,t[7]=p);let m;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(K,{children:`Save image`}),t[8]=m):m=t[8];let h;t[9]===p?h=t[10]:(h=(0,$.jsxs)(W,{children:[p,m]}),t[9]=p,t[10]=h);let g;t[11]===i?g=t[12]:(g=i?(0,$.jsx)(ln,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(it,{className:`h-3.5 w-3.5`}),t[11]=i,t[12]=g);let _;t[13]!==u||t[14]!==g?(_=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:u,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:g})}),t[13]=u,t[14]=g,t[15]=_):_=t[15];let v=i?`Copied!`:`Copy to clipboard`,y;t[16]===v?y=t[17]:(y=(0,$.jsx)(K,{children:v}),t[16]=v,t[17]=y);let b;t[18]!==y||t[19]!==_?(b=(0,$.jsxs)(W,{children:[_,y]}),t[18]=y,t[19]=_,t[20]=b):b=t[20];let x;t[21]!==b||t[22]!==h?(x=(0,$.jsxs)(Nt,{children:[h,b]}),t[21]=b,t[22]=h,t[23]=x):x=t[23];let S;return t[24]!==o||t[25]!==x?(S=(0,$.jsx)(Ho,{v0:o,v1:d,v2:x}),t[24]=o,t[25]=x,t[26]=S):S=t[26],S};function Wo(e){let t=Te(e);if(!t?.imageUrl&&!t?.imageData)return null;let n;if(typeof e==`object`&&e){let t=e;if(typeof t.model==`string`)n=t.model;else if(typeof t.content==`string`)try{let e=JSON.parse(t.content);typeof e.model==`string`&&(n=e.model)}catch{}}else if(typeof e==`string`)try{let t=JSON.parse(e.trim());typeof t.model==`string`&&(n=t.model)}catch{}return{imageUrl:t.imageUrl,imageData:t.imageData,model:n}}function Go(e){let t=(0,X.c)(79),{block:n,inline:r,sequence:i}=e,a=i===void 0?0:i,[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(!1),u=Q(Ko),d=n.toolName??`Unknown Tool`,f=n.toolCallId??`unknown`,p=n,m=n.result??p.content,h;t[0]!==p||t[1]!==d?(h=d===`todo`?Bo(p):null,t[0]=p,t[1]=d,t[2]=h):h=t[2];let _=h,v,y,b,x,S,C;if(t[3]!==p||t[4]!==r||t[5]!==m||t[6]!==u||t[7]!==a||t[8]!==_||t[9]!==d){C=Symbol.for(`react.early_return_sentinel`);bb0:{if(b=Wa(Ya(m),u),!(b.length>0)&&_===null){C=null;break bb0}let e;if(t[16]!==m||t[17]!==u||t[18]!==d){if(v=Ua(d),typeof m==`object`&&m){let e=m,n=e.returnDisplay??e.return_display;if(typeof n==`string`&&n.trim()){let e;t[21]===n?e=t[22]:(e=n.trim(),t[21]=n,t[22]=e),v=e}else if(d===`read`||d===`file_read`){let n=e.filePath??e.file_path??e.path??``;if(n){let e;t[23]===n?e=t[24]:(e=n.split(`/`).pop()??n,t[23]=n,t[24]=e),v=`Completed ${e}`}}}else if(m==null){let e;t[25]===d?e=t[26]:(e=Ua(d),t[25]=d,t[26]=e),v=`${e} (no result)`}e=Wa(v,u),t[16]=m,t[17]=u,t[18]=d,t[19]=v,t[20]=e}else v=t[19],e=t[20];if(v=e,_!==null){let e;t[27]!==a||t[28]!==_?(e=(0,$.jsx)(Vo,{todos:_,sequence:a}),t[27]=a,t[28]=_,t[29]=e):e=t[29],C=e;break bb0}if(d===`generate_image`){let e;t[30]!==p||t[31]!==m?(e=Wo(m)??Wo(p),t[30]=p,t[31]=m,t[32]=e):e=t[32];let n=e;if(n&&(n.imageUrl||n.imageData)){let e;t[33]!==n.imageData||t[34]!==n.imageUrl?(e=(0,$.jsx)(Uo,{imageUrl:n.imageUrl,imageData:n.imageData}),t[33]=n.imageData,t[34]=n.imageUrl,t[35]=e):e=t[35],C=e;break bb0}}if(r){C=null;break bb0}let n;t[36]===d?n=t[37]:(n=d.toLowerCase().includes(`bash`),t[36]=d,t[37]=n),y=n,x=b?b.split(`
22
- `):[],S=y?x.slice(0,3).join(`
23
- `):b}t[3]=p,t[4]=r,t[5]=m,t[6]=u,t[7]=a,t[8]=_,t[9]=d,t[10]=v,t[11]=y,t[12]=b,t[13]=x,t[14]=S,t[15]=C}else v=t[10],y=t[11],b=t[12],x=t[13],S=t[14],C=t[15];if(C!==Symbol.for(`react.early_return_sentinel`))return C;let w=S,T=y&&x.length>3;if(y){let e;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(e=q(J.body,`px-3 py-2 flex items-center gap-2 font-medium text-foreground`),t[38]=e):e=t[38];let n;t[39]===v?n=t[40]:(n=(0,$.jsx)(`div`,{className:e,children:(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:v})}),t[39]=v,t[40]=n);let r;t[41]!==T||t[42]!==w||t[43]!==b||t[44]!==x?(r=b&&(0,$.jsxs)(`div`,{className:`px-3 pb-2 bg-background border-t border-border`,children:[T?(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(`pre`,{className:q(J.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto text-foreground text-left mt-2 cursor-pointer hover:bg-muted/80`),onClick:()=>l(!0),children:[w,(0,$.jsxs)(`span`,{className:`text-muted-foreground`,children:[`
24
- `,`...`]})]})}),(0,$.jsx)(K,{children:`Click to see full output`})]}):(0,$.jsx)(`pre`,{className:q(J.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto text-foreground text-left mt-2`),children:w}),T&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>l(!0),className:q(J.caption,`mt-1 text-brand hover:underline`),children:[`Show full output (`,x.length,` lines)`]})]}),t[41]=T,t[42]=w,t[43]=b,t[44]=x,t[45]=r):r=t[45];let i;t[46]!==n||t[47]!==r?(i=(0,$.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[n,r]}),t[46]=n,t[47]=r,t[48]=i):i=t[48];let a;t[49]!==c||t[50]!==T||t[51]!==b?(a=T&&(0,$.jsx)(g,{open:c,onOpenChange:l,children:(0,$.jsxs)(H,{className:`max-w-3xl max-h-[80vh] flex flex-col`,children:[(0,$.jsx)(xt,{children:(0,$.jsx)(z,{children:`Full Output`})}),(0,$.jsx)(`pre`,{className:q(J.caption,`bg-muted p-3 rounded font-mono whitespace-pre-wrap overflow-auto flex-1 text-foreground`),children:b})]})}),t[49]=c,t[50]=T,t[51]=b,t[52]=a):a=t[52];let o;return t[53]!==i||t[54]!==a?(o=(0,$.jsxs)($.Fragment,{children:[i,a]}),t[53]=i,t[54]=a,t[55]=o):o=t[55],o}let E;t[56]===o?E=t[57]:(E=()=>s(!o),t[56]=o,t[57]=E);let D;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(D=q(J.body,`w-full px-3 py-2 flex items-center gap-2 font-medium text-foreground hover:bg-muted transition-colors text-left`),t[58]=D):D=t[58];let O;t[59]===v?O=t[60]:(O=(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:v}),t[59]=v,t[60]=O);let k;t[61]===o?k=t[62]:(k=o?(0,$.jsx)(Tt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(en,{className:`h-4 w-4 shrink-0`}),t[61]=o,t[62]=k);let A;t[63]!==E||t[64]!==O||t[65]!==k?(A=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(`button`,{onClick:E,className:D,children:[O,k]})}),t[63]=E,t[64]=O,t[65]=k,t[66]=A):A=t[66];let j=`${d} result`,M;t[67]===j?M=t[68]:(M=(0,$.jsx)(K,{children:j}),t[67]=j,t[68]=M);let N;t[69]!==M||t[70]!==A?(N=(0,$.jsxs)(W,{children:[A,M]}),t[69]=M,t[70]=A,t[71]=N):N=t[71];let P;t[72]!==o||t[73]!==b||t[74]!==f?(P=o&&(0,$.jsxs)(`div`,{className:`px-3 py-2 bg-background border-t border-border`,children:[(0,$.jsxs)(`div`,{className:q(J.compact,`text-muted-foreground mb-2 font-mono`),children:[`Call ID: `,f]}),b&&(0,$.jsx)(`pre`,{className:q(J.caption,`bg-muted p-2 rounded font-mono whitespace-pre-wrap overflow-auto max-h-48 text-foreground text-left`),children:b})]}),t[72]=o,t[73]=b,t[74]=f,t[75]=P):P=t[75];let F;return t[76]!==N||t[77]!==P?(F=(0,$.jsxs)(`div`,{className:`mb-3 rounded-lg border border-border bg-muted/50 overflow-hidden`,children:[N,P]}),t[76]=N,t[77]=P,t[78]=F):F=t[78],F}function Ko(e){return e.projects.find(t=>t.projectId===e.selectedProjectId)?.threads.find(t=>t.threadId===e.selectedThreadId)?.path}var qo=Cr(e=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 cursor-pointer select-none text-left w-full`,onClick:e.v0,"aria-expanded":e.v1,children:[e.v2,(0,$.jsx)(`span`,{className:e.v3,children:e.v4})]}),(0,$.jsx)(`div`,{className:e.v5,children:(0,$.jsx)(`div`,{className:`overflow-hidden`,children:e.v6})})]}),{name:`ThinkingBlock_1`,portals:[`v2`,`v4`,`v6`]}),Jo=function(e){let t=(0,X.c)(34),{text:n,isStreaming:r,label:i}=e,a=n===void 0?``:n,o=r===void 0?!1:r,s=(0,Y.useRef)(null),c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=Date.now(),t[0]=c):c=t[0];let l=(0,Y.useRef)(c),[u,d]=(0,Y.useState)(0),[f,p]=(0,Y.useState)(o),m=(0,Y.useRef)(o),h,g;t[1]===o?(h=t[2],g=t[3]):(h=()=>{o&&!m.current?(l.current=Date.now(),d(0),p(!0)):o?p(!0):m.current&&!o&&(d(Date.now()-l.current),p(!1)),m.current=o},g=[o],t[1]=o,t[2]=h,t[3]=g),(0,Y.useEffect)(h,g);let _;t[4]!==f||t[5]!==o?(_=()=>{f&&o&&s.current&&(s.current.scrollTop=s.current.scrollHeight)},t[4]=f,t[5]=o,t[6]=_):_=t[6];let v;if(t[7]!==f||t[8]!==o||t[9]!==a?(v=[a,f,o],t[7]=f,t[8]=o,t[9]=a,t[10]=v):v=t[10],(0,Y.useEffect)(_,v),!a&&!o)return null;let y=!o&&i===`Validated`,b;t[11]!==u||t[12]!==o||t[13]!==i?(b=Xo(o,i,u),t[11]=u,t[12]=o,t[13]=i,t[14]=b):b=t[14];let x=b,S;t[15]===a?S=t[16]:(S=a?Ha(a):``,t[15]=a,t[16]=S);let C=S,w;t[17]===f?w=t[18]:(w=()=>p(!f),t[17]=f,t[18]=w);let T;t[19]===y?T=t[20]:(T=y?(0,$.jsx)(_t,{className:`h-3.5 w-3.5 shrink-0 text-green-600`}):null,t[19]=y,t[20]=T);let E=f?`grid-rows-[1fr]`:`grid-rows-[0fr]`,D;t[21]===E?D=t[22]:(D=[`grid transition-[grid-template-rows] duration-200 ease-in-out`,E],t[21]=E,t[22]=D);let O=D.join(` `),k,A;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(k=q(J.caption,`ml-5 text-muted-foreground/60 whitespace-pre-wrap overflow-y-auto`),A={maxHeight:`7.5em`},t[23]=k,t[24]=A):(k=t[23],A=t[24]);let j;t[25]===C?j=t[26]:(j=(0,$.jsx)(`div`,{ref:s,className:k,style:A,children:C}),t[25]=C,t[26]=j);let M;return t[27]!==f||t[28]!==x||t[29]!==w||t[30]!==T||t[31]!==O||t[32]!==j?(M=(0,$.jsx)(qo,{v0:w,v1:f,v2:T,v3:J.caption,v4:x,v5:O,v6:j}),t[27]=f,t[28]=x,t[29]=w,t[30]=T,t[31]=O,t[32]=j,t[33]=M):M=t[33],M};function Yo(e){if(e<1e3){let t=Math.max(1,Math.round(e));return`${t} millisecond${t===1?``:`s`}`}let t=Math.max(1,Math.round(e/1e3));if(t<60)return`${t} second${t===1?``:`s`}`;let n=Math.floor(t/60),r=t%60;return r===0?`${n} minute${n===1?``:`s`}`:`${n} minute${n===1?``:`s`} ${r} second${r===1?``:`s`}`}function Xo(e,t,n){return e?t===`MCP`?`Connecting MCP servers...`:t===`Validating`?`Validating...`:`Thinking...`:t===`MCP`?`MCP setup complete.`:t===`Validated`?`Validated`:n<=0?`Thought complete.`:`Thought for ${Yo(n)}.`}function Zo(e){let t=(0,X.c)(67),{toolCall:n,className:r}=e,i=yi(),[a,o]=(0,Y.useState)(!1),s;t[0]===n.id?s=t[1]:(s=e=>e.toolCallProgress[n.id],t[0]=n.id,t[1]=s);let c=Q(s),l=Q(ts),u=Q(es),d;t[2]!==n.activeDisplayName||t[3]!==n.name?(d=n.activeDisplayName??Ke(n.name),t[2]=n.activeDisplayName,t[3]=n.name,t[4]=d):d=t[4];let f=d;if(!l)return null;let p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(p=()=>{o($o)},t[5]=p):p=t[5];let m=p,h;t[6]!==i||t[7]!==u||t[8]!==n.id||t[9]!==n.name?(h=()=>{i({type:Z.StopStream});let e={type:`tool-result`,toolCallId:n.id,toolName:n.name,result:`Tool execution was cancelled by the user. The command was taking too long or required user approval.`,isError:!0,content:`Tool execution was cancelled by the user. The command was taking too long or required user approval.`};i({type:Z.AppendStreamChunk,chunkType:`content`,content:JSON.stringify([e]),segments:u})},t[6]=i,t[7]=u,t[8]=n.id,t[9]=n.name,t[10]=h):h=t[10];let g=h,_=Qo,v=n.name===`bash`&&typeof n.input?.command==`string`?n.input.command:null,y=n.name===`fetch`&&typeof n.input?.url==`string`?n.input.url:null,b=n.name===`web_search`&&typeof n.input?.query==`string`?n.input.query:null,x=!v&&typeof n.input?.description==`string`?n.input.description:null,S;t[11]===r?S=t[12]:(S=q(`overflow-hidden mb-2`,r),t[11]=r,t[12]=S);let C;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(vo,{}),t[13]=C):C=t[13];let w;t[14]===f?w=t[15]:(w=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[C,(0,$.jsx)(`span`,{className:J.bodyMuted,children:f})]})}),t[14]=f,t[15]=w);let T;t[16]===n.name?T=t[17]:(T=(0,$.jsx)(K,{children:n.name}),t[16]=n.name,t[17]=T);let E;t[18]!==w||t[19]!==T?(E=(0,$.jsxs)(W,{children:[w,T]}),t[18]=w,t[19]=T,t[20]=E):E=t[20];let D;t[21]===v?D=t[22]:(D=v!==null&&(0,$.jsx)(`code`,{className:q(J.mono,J.bodyMuted,`break-all rounded bg-muted/60 px-1 py-0.5`),children:v}),t[21]=v,t[22]=D);let O;t[23]===y?O=t[24]:(O=y!==null&&(0,$.jsx)(`code`,{className:q(J.mono,J.bodyMuted,`break-all rounded bg-muted/60 px-1 py-0.5`),children:y.length>60?`${y.slice(0,59)}…`:y}),t[23]=y,t[24]=O);let k;t[25]===b?k=t[26]:(k=b!==null&&(0,$.jsx)(`code`,{className:q(J.mono,J.bodyMuted,`break-all rounded bg-muted/60 px-1 py-0.5`),children:b.length>60?`${b.slice(0,59)}…`:b}),t[25]=b,t[26]=k);let A;t[27]===x?A=t[28]:(A=x!==null&&(0,$.jsx)(`span`,{className:J.bodyMuted,children:x}),t[27]=x,t[28]=A);let M;t[29]!==v||t[30]!==x||t[31]!==y||t[32]!==b?(M=!v&&!y&&!b&&!x&&(0,$.jsx)(`span`,{className:J.bodyMuted,children:`running`}),t[29]=v,t[30]=x,t[31]=y,t[32]=b,t[33]=M):M=t[33];let N;t[34]===a?N=t[35]:(N=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:m,className:`p-1 hover:bg-muted/50 rounded transition-colors`,children:a?(0,$.jsx)(Rt,{className:`h-3 w-3`}):(0,$.jsx)(Tt,{className:`h-3 w-3`})})}),t[34]=a,t[35]=N);let P=a?`Collapse`:`Expand`,F;t[36]===P?F=t[37]:(F=(0,$.jsx)(K,{children:P}),t[36]=P,t[37]=F);let I;t[38]!==N||t[39]!==F?(I=(0,$.jsxs)(W,{children:[N,F]}),t[38]=N,t[39]=F,t[40]=I):I=t[40];let L;t[41]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsx)(j,{className:`h-3 w-3`}),t[41]=L):L=t[41];let R;t[42]===g?R=t[43]:(R=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:g,className:`p-1 hover:bg-red-200 dark:hover:bg-red-800 rounded transition-colors text-red-600 dark:text-red-400`,children:L})}),t[42]=g,t[43]=R);let ee;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,$.jsx)(K,{className:`bg-red-600 text-white border-red-600`,children:`Stop this process`}),t[44]=ee):ee=t[44];let te;t[45]===R?te=t[46]:(te=(0,$.jsxs)(W,{children:[R,ee]}),t[45]=R,t[46]=te);let z;t[47]!==I||t[48]!==te?(z=(0,$.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto shrink-0`,children:[I,te]}),t[47]=I,t[48]=te,t[49]=z):z=t[49];let ne;t[50]!==D||t[51]!==O||t[52]!==k||t[53]!==A||t[54]!==M||t[55]!==z||t[56]!==E?(ne=(0,$.jsxs)(`div`,{className:`py-0.5 flex items-center gap-2 flex-wrap`,children:[E,D,O,k,A,M,z]}),t[50]=D,t[51]=O,t[52]=k,t[53]=A,t[54]=M,t[55]=z,t[56]=E,t[57]=ne):ne=t[57];let B;t[58]!==a||t[59]!==n.id||t[60]!==n.input||t[61]!==c?(B=a&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border min-h-[8rem] overflow-auto`,children:[(0,$.jsxs)(`div`,{className:q(J.compact,J.bodyMuted,`mb-2 font-mono`),children:[`ID: `,n.id]}),(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:q(J.compact,J.label,`text-muted-foreground mb-1`),children:`Input:`}),(0,$.jsx)(`pre`,{className:lo({className:`border border-border`}),children:_(n.input)})]}),c&&(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`div`,{className:q(J.compact,J.label,`text-muted-foreground mb-1`),children:`Progress:`}),(0,$.jsxs)(`div`,{className:q(J.body,`bg-green-50 dark:bg-green-900/20 p-2 rounded border border-green-200 dark:border-green-800`),children:[(0,$.jsx)(`div`,{className:q(J.mono,`text-green-700 dark:text-green-300`),children:c.delta}),c.partial?.content?.[0]?.arguments&&typeof c.partial.content[0].arguments==`object`&&`content`in c.partial.content[0].arguments&&typeof c.partial.content[0].arguments.content==`string`&&(0,$.jsxs)(`div`,{className:q(J.mono,`mt-1 text-green-600 dark:text-green-400`),children:[`Building: `,c.partial.content[0].arguments.content.slice(-50),c.partial.content[0].arguments.content.length>50&&`...`]})]})]}),(0,$.jsxs)(`div`,{className:q(J.compact,`flex items-center gap-1.5 text-muted-foreground`),children:[(0,$.jsx)(vo,{}),`Executing`,c&&` with progress`,`...`]})]}),t[58]=a,t[59]=n.id,t[60]=n.input,t[61]=c,t[62]=B):B=t[62];let re;return t[63]!==ne||t[64]!==B||t[65]!==S?(re=(0,$.jsxs)(`div`,{className:S,children:[ne,B]}),t[63]=ne,t[64]=B,t[65]=S,t[66]=re):re=t[66],re}function Qo(e){return JSON.stringify(e,null,2)}function $o(e){return!e}function es(e){return e.streamingSegments}function ts(e){return e.isStreaming}function ns(e,t){let n=e.toLowerCase();return n===`agent`||n.includes(`subagent`)?!0:!!(t&&typeof t==`object`&&`description`in t&&(`prompt`in t||`agentName`in t))}function rs(e){return e.type!==`subagent_event`||!e.subagentEvent?null:is(e.subagentEvent)}function is(e){switch(e.type){case`message`:return e.content&&e.isThinking||e.content&&!e.isThinking&&e.role!==`tool`?e.content:e.role===`tool`&&e.content?as(e.content):null;case`shell_permission`:{let t=e.shellPermission?.command?.trim();return t?`\n⏳ Waiting for shell approval: ${t}\n`:`
25
- ⏳ Waiting for shell approval…
26
- `}case`web_fetch_permission`:{let t=e.webFetchPermission?.hostname?.trim();return t?`\n⏳ Waiting for approval to fetch ${t}\n`:`
27
- ⏳ Waiting for web fetch approval…
28
- `}case`error`:return e.content?`\n${e.content}`:null;default:return null}}function as(e){try{let t=JSON.parse(e);if(!Array.isArray(t))return null;let n=[];for(let e of t)if(e.type===`tool_use`&&e.name)n.push(`\n→ ${e.name}\n`);else if(e.type===`tool-result`&&e.content){let t=typeof e.content==`string`?e.content.trim().slice(0,120):JSON.stringify(e.content).slice(0,120);t&&n.push(`✓ ${t}${t.length>=120?`…`:``}\n`)}return n.length>0?n.join(``):null}catch{return null}}var os=Cr(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border-t border-border p-4 my-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-2`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:e.v2}),e.v3]})]}),(0,$.jsxs)(`div`,{className:e.v4,children:[(0,$.jsxs)(`span`,{className:`font-medium`,children:[e.v5,`:`]}),` `,(0,$.jsx)(`span`,{children:e.v6})]})]}),{name:`AskUserBlock_1`,portals:[`v0`,`v2`,`v3`,`v5`,`v6`]}),ss=Cr(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border-t border-border p-4 my-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-3`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:e.v2}),e.v3]})]}),e.v4,(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`input`,{type:`text`,value:e.v5,onChange:e.v6,onKeyDown:e.v7,placeholder:e.v8,disabled:e.v9,className:`flex-1 rounded-md border border-border bg-background px-3 py-1.5 text-base text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`}),(0,$.jsx)(`button`,{type:`button`,onClick:e.v10,disabled:e.v11,className:`h-7 w-7 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50 flex items-center justify-center shrink-0`,children:e.v12})]})]}),{name:`AskUserBlock_2`,portals:[`v0`,`v2`,`v3`,`v4`,`v12`]}),cs=function(e){let t=(0,X.c)(54),{toolCallId:n,question:r,options:i,context:a,answeredText:o,answeredLabel:s}=e,[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(!!o),[f,p]=(0,Y.useState)(o??``),[m,h]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(null),v,y;t[0]===o?(v=t[1],y=t[2]):(v=()=>{let e=o?.trim();if(e){d(!0),p(e),h(!1),_(null);return}d(!1),p(``)},y=[o],t[0]=o,t[1]=v,t[2]=y),(0,Y.useEffect)(v,y);let b;t[3]!==m||t[4]!==n?(b=async e=>{if(!(!e.trim()||m)){h(!0);try{await ut(n,e.trim()),p(e.trim()),d(!0)}catch(e){console.error(`Failed to submit answer:`,e),h(!1),_(null)}}},t[3]=m,t[4]=n,t[5]=b):b=t[5];let x=b,S;t[6]!==x||t[7]!==m||t[8]!==u?(S=e=>{u||m||(_(e),x(e))},t[6]=x,t[7]=m,t[8]=u,t[9]=S):S=t[9];let C=S,w;t[10]!==c||t[11]!==x||t[12]!==m||t[13]!==u?(w=()=>{if(u||m)return;let e=c.trim();e&&x(e)},t[10]=c,t[11]=x,t[12]=m,t[13]=u,t[14]=w):w=t[14];let T=w,E;t[15]===T?E=t[16]:(E=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),T())},t[15]=T,t[16]=E);let D=E;if(u){let e,n;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(ln,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),n=q(J.label,`text-foreground`),t[17]=e,t[18]=n):(e=t[17],n=t[18]);let i;t[19]===r?i=t[20]:(i=(0,$.jsx)(ha,{content:r}),t[19]=r,t[20]=i);let o;t[21]===a?o=t[22]:(o=a&&(0,$.jsx)(`p`,{className:q(J.bodyMuted,`mt-1`),children:a}),t[21]=a,t[22]=o);let c=s??`You answered`,l;return t[23]!==f||t[24]!==o||t[25]!==c||t[26]!==i?(l=(0,$.jsx)(os,{v0:e,v1:n,v2:i,v3:o,v4:J.bodyMuted,v5:c,v6:f}),t[23]=f,t[24]=o,t[25]=c,t[26]=i,t[27]=l):l=t[27],l}let O,k;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(Zt,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),k=q(J.label,`text-foreground`),t[28]=O,t[29]=k):(O=t[28],k=t[29]);let A;t[30]===r?A=t[31]:(A=(0,$.jsx)(ha,{content:r}),t[30]=r,t[31]=A);let j;t[32]===a?j=t[33]:(j=a&&(0,$.jsx)(`p`,{className:q(J.bodyMuted,`mt-1`),children:a}),t[32]=a,t[33]=j);let M;t[34]!==C||t[35]!==m||t[36]!==i||t[37]!==g?(M=i&&i.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2 mb-3`,children:i.map(e=>{let t=g===e;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>C(e),disabled:m,className:q(`rounded-md border px-3 py-1.5 transition-colors disabled:opacity-50 flex items-center gap-1.5`,J.label,t?`border-foreground/20 bg-accent text-accent-foreground`:`border-foreground/20 bg-background text-foreground hover:bg-accent hover:text-accent-foreground`),children:[t&&(0,$.jsx)(ln,{className:`h-3.5 w-3.5 text-foreground`}),e]},e)})}),t[34]=C,t[35]=m,t[36]=i,t[37]=g,t[38]=M):M=t[38];let N;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(N=e=>l(e.target.value),t[39]=N):N=t[39];let P=i?.length?`Or type a custom answer...`:`Type your answer...`,F;t[40]!==c||t[41]!==m?(F=m||!c.trim(),t[40]=c,t[41]=m,t[42]=F):F=t[42];let I;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(mt,{className:`h-3 w-3`}),t[43]=I):I=t[43];let L;return t[44]!==c||t[45]!==T||t[46]!==D||t[47]!==m||t[48]!==j||t[49]!==M||t[50]!==P||t[51]!==F||t[52]!==A?(L=(0,$.jsx)(ss,{v0:O,v1:k,v2:A,v3:j,v4:M,v5:c,v6:N,v7:D,v8:P,v9:m,v10:T,v11:F,v12:I}),t[44]=c,t[45]=T,t[46]=D,t[47]=m,t[48]=j,t[49]=M,t[50]=P,t[51]=F,t[52]=A,t[53]=L):L=t[53],L},ls=or,us=Un,ds=Xn,fs=Y.forwardRef((e,t)=>{let n=(0,X.c)(14),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:i,inset:a,children:r,...o}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s;n[5]!==i||n[6]!==a?(s=q(q(J.body,`flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`),a&&`pl-8`,i),n[5]=i,n[6]=a,n[7]=s):s=n[7];let c;n[8]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(en,{className:`ml-auto`}),n[8]=c):c=n[8];let l;return n[9]!==r||n[10]!==o||n[11]!==t||n[12]!==s?(l=(0,$.jsxs)(Zn,{ref:t,className:s,...o,children:[r,c]}),n[9]=r,n[10]=o,n[11]=t,n[12]=s,n[13]=l):l=n[13],l});fs.displayName=Zn.displayName;var ps=Y.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(Yn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});ps.displayName=Yn.displayName;var ms=Y.forwardRef((e,t)=>{let n=(0,X.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,sideOffset:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=a===void 0?4:a,s;n[4]===r?s=n[5]:(s=q(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,r),n[4]=r,n[5]=s);let c;return n[6]!==i||n[7]!==t||n[8]!==o||n[9]!==s?(c=(0,$.jsx)(Nn,{children:(0,$.jsx)(qn,{ref:t,sideOffset:o,className:s,...i})}),n[6]=i,n[7]=t,n[8]=o,n[9]=s,n[10]=c):c=n[10],c});ms.displayName=qn.displayName;var hs=Y.forwardRef((e,t)=>{let n=(0,X.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,inset:i,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]!==r||n[5]!==i?(o=q(q(J.body,`relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`),i&&`pl-8`,r),n[4]=r,n[5]=i,n[6]=o):o=n[6];let s;return n[7]!==a||n[8]!==t||n[9]!==o?(s=(0,$.jsx)(Pn,{ref:t,className:o,...a}),n[7]=a,n[8]=t,n[9]=o,n[10]=s):s=n[10],s});hs.displayName=Pn.displayName;var gs=Y.forwardRef((e,t)=>{let n=(0,X.c)(14),r,i,a,o;n[0]===e?(r=n[1],i=n[2],a=n[3],o=n[4]):({className:a,children:i,checked:r,...o}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a,n[4]=o);let s;n[5]===a?s=n[6]:(s=q(q(J.body,`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`),a),n[5]=a,n[6]=s);let c;n[7]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,$.jsx)(Kn,{children:(0,$.jsx)(ln,{className:`h-4 w-4`})})}),n[7]=c):c=n[7];let l;return n[8]!==r||n[9]!==i||n[10]!==o||n[11]!==t||n[12]!==s?(l=(0,$.jsxs)(kn,{ref:t,className:s,checked:r,...o,children:[c,i]}),n[8]=r,n[9]=i,n[10]=o,n[11]=t,n[12]=s,n[13]=l):l=n[13],l});gs.displayName=kn.displayName;var _s=Y.forwardRef((e,t)=>{let n=(0,X.c)(12),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:i,children:r,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]===i?o=n[5]:(o=q(q(J.body,`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`),i),n[4]=i,n[5]=o);let s;n[6]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,$.jsx)(Kn,{children:(0,$.jsx)(Ft,{className:`h-2 w-2 fill-current`})})}),n[6]=s):s=n[6];let c;return n[7]!==r||n[8]!==a||n[9]!==t||n[10]!==o?(c=(0,$.jsxs)(Ln,{ref:t,className:o,...a,children:[s,r]}),n[7]=r,n[8]=a,n[9]=t,n[10]=o,n[11]=c):c=n[11],c});_s.displayName=Ln.displayName;var vs=Y.forwardRef((e,t)=>{let n=(0,X.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,inset:i,...a}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o=i&&`pl-8`,s;n[4]!==r||n[5]!==o?(s=q(J.body,`px-2 py-1.5 font-semibold`,o,r),n[4]=r,n[5]=o,n[6]=s):s=n[6];let c;return n[7]!==a||n[8]!==t||n[9]!==s?(c=(0,$.jsx)(Jn,{ref:t,className:s,...a}),n[7]=a,n[8]=t,n[9]=s,n[10]=c):c=n[10],c});vs.displayName=Jn.displayName;var ys=Y.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`-mx-1 my-1 h-px bg-muted`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(In,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});ys.displayName=In.displayName;var bs=e=>{let t=(0,X.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=q(J.compact,`ml-auto tracking-widest opacity-60`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`span`,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a};bs.displayName=`DropdownMenuShortcut`;var xs=Cr(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-border p-4 my-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-2`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:`Shell command permission`}),(0,$.jsx)(`code`,{className:e.v2,children:e.v3})]})]}),(0,$.jsx)(`div`,{className:e.v4,children:`Skipped`})]}),{name:`ShellPermissionBlock_1`,portals:[`v0`,`v3`]}),Ss=Cr(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-border p-4 my-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-3`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:`Allow the agent to run this command?`}),(0,$.jsx)(`code`,{className:e.v2,children:e.v3})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`inline-flex rounded-md shadow-sm`,children:[e.v4,e.v5]}),e.v6]})]}),{name:`ShellPermissionBlock_2`,portals:[`v0`,`v3`,`v4`,`v5`,`v6`]}),Cs=function({toolCallId:e,command:t,projectId:n,wildcardOptions:r,resolvedDecision:i}){let[a,o]=(0,Y.useState)(!!i),[s,c]=(0,Y.useState)(i??null),[l,u]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{i&&(o(!0),c(i),u(!1))},[i]);async function d(t,r){if(!(l||a)){u(!0);try{await mn(e,t,{pattern:r,projectId:n??void 0}),o(!0),c(t===`skip`?`skipped`:`allowed`)}catch(e){console.error(`Failed to submit shell permission response:`,e),u(!1)}}}return a&&s!==`skipped`?null:a?(0,$.jsx)(xs,{v0:(0,$.jsx)(ln,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),v1:J.label,v2:q(J.mono,J.bodyMuted,`mt-2 block break-all rounded bg-muted/60 px-2 py-1`),v3:t,v4:J.bodyMuted}):(0,$.jsx)(Ss,{v0:(0,$.jsx)(me,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),v1:J.label,v2:q(J.mono,J.bodyMuted,`mt-2 block break-all rounded bg-muted/60 px-2 py-1`),v3:t,v4:(0,$.jsx)(U,{type:`button`,size:`sm`,disabled:l,onClick:()=>void d(`allow_once`),className:`rounded-r-none`,children:`Allow`}),v5:r.length>0&&(0,$.jsxs)(ls,{children:[(0,$.jsx)(us,{asChild:!0,children:(0,$.jsx)(U,{type:`button`,size:`sm`,disabled:l,className:q(`rounded-l-none border-l border-primary-foreground/20 px-2`),"aria-label":`More allow options`,children:(0,$.jsx)(Tt,{className:`h-4 w-4`})})}),(0,$.jsx)(ms,{align:`end`,className:`max-w-md`,children:r.map(e=>(0,$.jsx)(hs,{onClick:()=>void d(e.scope===`project`?`allow_pattern_project`:`allow_pattern_session`,e.pattern),children:e.label},`${e.scope}-${e.pattern}`))})]}),v6:(0,$.jsx)(U,{type:`button`,size:`sm`,variant:`outline`,disabled:l,onClick:()=>void d(`skip`),children:`Skip`})})},ws=Cr(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-border p-4 my-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-2`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:`Web fetch permission`}),(0,$.jsx)(`code`,{className:e.v2,children:e.v3})]})]}),(0,$.jsx)(`div`,{className:e.v4,children:`Skipped`})]}),{name:`WebFetchPermissionBlock_1`,portals:[`v0`,`v3`]}),Ts=Cr(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-border p-4 my-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2 mb-3`,children:[e.v0,(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:e.v1,children:`Allow the agent to fetch from this domain?`}),(0,$.jsx)(`code`,{className:e.v2,children:e.v3}),(0,$.jsx)(`div`,{className:e.v4,children:e.v5})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`inline-flex rounded-md shadow-sm`,children:[e.v6,e.v7]}),e.v8]})]}),{name:`WebFetchPermissionBlock_2`,portals:[`v0`,`v3`,`v5`,`v6`,`v7`,`v8`]}),Es=function({toolCallId:e,hostname:t,url:n,wildcardOptions:r,resolvedDecision:i}){let[a,o]=(0,Y.useState)(!!i),[s,c]=(0,Y.useState)(i??null),[l,u]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{i&&(o(!0),c(i),u(!1))},[i]);async function d(t){if(!(l||a)){u(!0);try{await wn(e,t),o(!0),c(t===`skip`?`skipped`:`allowed`)}catch(e){console.error(`Failed to submit web fetch permission response:`,e),u(!1)}}}return a&&s!==`skipped`?null:a?(0,$.jsx)(ws,{v0:(0,$.jsx)(ln,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),v1:J.label,v2:q(J.mono,J.bodyMuted,`mt-2 block break-all rounded bg-muted/60 px-2 py-1`),v3:t,v4:J.bodyMuted}):(0,$.jsx)(Ts,{v0:(0,$.jsx)(ce,{className:`h-5 w-5 text-brand shrink-0 mt-0.5`}),v1:J.label,v2:q(J.mono,J.bodyMuted,`mt-2 block break-all rounded bg-muted/60 px-2 py-1`),v3:t,v4:q(J.caption,J.bodyMuted,`mt-1 break-all`),v5:n,v6:(0,$.jsx)(U,{type:`button`,size:`sm`,disabled:l,onClick:()=>void d(`allow_once`),className:`rounded-r-none`,children:`Allow`}),v7:r.length>0&&(0,$.jsxs)(ls,{children:[(0,$.jsx)(us,{asChild:!0,children:(0,$.jsx)(U,{type:`button`,size:`sm`,disabled:l,className:q(`rounded-l-none border-l border-primary-foreground/20 px-2`),"aria-label":`More allow options`,children:(0,$.jsx)(Tt,{className:`h-4 w-4`})})}),(0,$.jsx)(ms,{align:`end`,className:`max-w-md`,children:r.map(e=>(0,$.jsx)(hs,{onClick:()=>void d(e.scope===`project`?`allow_domain_project`:`allow_domain_session`),children:e.label},`${e.scope}-${e.pattern}`))})]}),v8:(0,$.jsx)(U,{type:`button`,size:`sm`,variant:`outline`,disabled:l,onClick:()=>void d(`skip`),children:`Deny`})})},Ds=new Map,Os=new Map;function ks(e){return Ds.get(e)}function As(e,t){let n=Os.get(e);return n||(n=new Set,Os.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&Os.delete(e)}}function js(e){let t=Os.get(e);if(t)for(let e of t)e()}function Ms(e,t){return async function(n,r){let i=await fetch(e+`/api/browser-js/execute-tool`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({threadId:t,toolName:n,params:r})});if(!i.ok){let e=await i.text();try{let t=JSON.parse(e).error||{};e=t.details||t.message||e}catch{}return{text:null,error:`Tool `+n+` failed: `+e}}let a=await i.json();return{text:a.content&&a.content[0]?a.content[0].text:null,error:null}}}function Ns(e,t,n){if(Ds.has(e))return;Ds.set(e,{status:`running`}),js(e);let r=S();(async()=>{try{let i=Ms(r,n),a=Object.getPrototypeOf(async function(){}).constructor,o=await new a(`callTool`,t)(i),s=o===void 0?null:o;Ds.set(e,{status:`success`,result:s}),js(e),await He(e,s)}catch(t){let n=t instanceof Error?t.stack||t.message:String(t);Ds.set(e,{status:`error`,error:n}),js(e);try{await He(e,{error:n})}catch(e){console.error(`[browser-js-executor] failed to submit error result`,e)}}})()}var Ps=Cr(e=>(0,$.jsx)(`div`,{className:`overflow-hidden`,children:(0,$.jsxs)(`div`,{className:e.v0,children:[e.v1,(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:e.v2})]})}),{name:`RunWebWorkerBlock_1`,portals:[`v1`,`v2`]}),Fs=Cr(e=>(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[(0,$.jsxs)(`button`,{onClick:e.v0,className:e.v1,children:[e.v2,(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:e.v3}),e.v4]}),e.v5]}),{name:`RunWebWorkerBlock_2`,portals:[`v2`,`v3`,`v4`,`v5`]}),Is=Cr(e=>(0,$.jsxs)(`div`,{className:`overflow-hidden`,children:[(0,$.jsxs)(`button`,{onClick:e.v0,className:e.v1,children:[e.v2,(0,$.jsx)(`span`,{className:`flex-1 text-left min-w-0 truncate`,children:e.v3}),e.v4]}),e.v5]}),{name:`RunWebWorkerBlock_3`,portals:[`v2`,`v3`,`v4`,`v5`]}),Ls=function(e){let t=(0,X.c)(41),{toolCallId:n,intention:r,code:i}=e,a=Q(Rs),o;t[0]===n?o=t[1]:(o=ks(n),t[0]=n,t[1]=o);let s=o,[c,l]=(0,Y.useState)(s?.status??`running`),u;t[2]===s?u=t[3]:(u=()=>{if(!s||s.status!==`success`)return null;let e=s.result;return e==null?null:typeof e==`string`?e:JSON.stringify(e,null,2)},t[2]=s,t[3]=u);let[d,f]=(0,Y.useState)(u),[p,m]=(0,Y.useState)(s?.error??null),h,g;t[4]===n?(h=t[5],g=t[6]):(h=()=>As(n,()=>{let e=ks(n);if(e)if(l(e.status),e.status===`success`){let t=e.result;f(t==null?null:typeof t==`string`?t:JSON.stringify(t,null,2))}else e.status===`error`&&m(e.error??null)}),g=[n],t[4]=n,t[5]=h,t[6]=g),(0,Y.useEffect)(h,g);let _,v;t[7]!==i||t[8]!==a||t[9]!==n?(_=()=>{a&&Ns(n,i,a)},v=[n,i,a],t[7]=i,t[8]=a,t[9]=n,t[10]=_,t[11]=v):(_=t[10],v=t[11]),(0,Y.useEffect)(_,v);let[y,b]=(0,Y.useState)(!1),x;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(x=()=>b(zs),t[12]=x):x=t[12];let S=x;if(c===`running`){let e,n;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(e=q(J.label,`w-full py-2 flex items-center gap-2`),n=(0,$.jsx)(pe,{className:`h-4 w-4 shrink-0 text-brand animate-pulse`}),t[13]=e,t[14]=n):(e=t[13],n=t[14]);let i=r||`Executing Browser JS...`,a;return t[15]===i?a=t[16]:(a=(0,$.jsx)(Ps,{v0:e,v1:n,v2:i}),t[15]=i,t[16]=a),a}if(c===`success`){let e,n;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(e=q(J.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),n=(0,$.jsx)(pe,{className:`h-4 w-4 shrink-0 text-brand`}),t[17]=e,t[18]=n):(e=t[17],n=t[18]);let a=r||`Browser JS Executed Successfully`,o;t[19]===y?o=t[20]:(o=y?(0,$.jsx)(Tt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(en,{className:`h-4 w-4 shrink-0`}),t[19]=y,t[20]=o);let s;t[21]!==i||t[22]!==y||t[23]!==d?(s=y&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border flex flex-col gap-2`,children:[(0,$.jsx)(`pre`,{className:q(J.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:i}),d!=null&&(0,$.jsx)(`pre`,{className:q(J.body,`leading-relaxed whitespace-pre-wrap border-t border-border pt-2`),children:d})]}),t[21]=i,t[22]=y,t[23]=d,t[24]=s):s=t[24];let c;return t[25]!==a||t[26]!==o||t[27]!==s?(c=(0,$.jsx)(Fs,{v0:S,v1:e,v2:n,v3:a,v4:o,v5:s}),t[25]=a,t[26]=o,t[27]=s,t[28]=c):c=t[28],c}let C,w;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(C=q(J.label,`w-full py-2 flex items-center gap-2 hover:bg-muted/50 transition-colors text-left`),w=(0,$.jsx)(pe,{className:`h-4 w-4 shrink-0 text-destructive`}),t[29]=C,t[30]=w):(C=t[29],w=t[30]);let T=r||`Browser JS Execution Failed`,E;t[31]===y?E=t[32]:(E=y?(0,$.jsx)(Tt,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(en,{className:`h-4 w-4 shrink-0`}),t[31]=y,t[32]=E);let D;t[33]!==i||t[34]!==p||t[35]!==y?(D=y&&(0,$.jsxs)(`div`,{className:`py-2 border-t border-border flex flex-col gap-2`,children:[(0,$.jsx)(`pre`,{className:q(J.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:p}),(0,$.jsx)(`pre`,{className:q(J.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:i})]}),t[33]=i,t[34]=p,t[35]=y,t[36]=D):D=t[36];let O;return t[37]!==T||t[38]!==E||t[39]!==D?(O=(0,$.jsx)(Is,{v0:S,v1:C,v2:w,v3:T,v4:E,v5:D}),t[37]=T,t[38]=E,t[39]=D,t[40]=O):O=t[40],O};function Rs(e){return e.selectedThreadId}function zs(e){return!e}var Bs=Cr(e=>(0,$.jsx)(`div`,{className:e.v0,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:e.v1,children:`Agent`}),e.v2]}),e.v3]})}),{name:`StreamingMessageComponent_1`,portals:[`v2`,`v3`]}),Vs=function(e){let t=(0,X.c)(24),{segments:n,model:r,projectId:i,isCreatingProject:a,isProcessingThread:o,totalMessages:s,showProcessingLine:c}=e,l=s===void 0?0:s,u=c===void 0?!1:c,d=Q(ec),f,p,m,h,g;if(t[0]!==a||t[1]!==o||t[2]!==r||t[3]!==i||t[4]!==n||t[5]!==u||t[6]!==d||t[7]!==l){let e=oi(n);f=Bs;let s=u?`pb-0`:`pb-4`;t[13]===s?p=t[14]:(p=q(`group px-4 pt-4`,s),t[13]=s,t[14]=p),t[15]===Symbol.for(`react.memo_cache_sentinel`)?(m=q(J.compact,`font-medium text-foreground`),t[15]=m):m=t[15],t[16]===r?h=t[17]:(h=r&&(0,$.jsxs)(`span`,{className:q(J.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(pe,{className:`h-2.5 w-2.5`}),_r(r)]}),t[16]=r,t[17]=h),g=e.length>0?(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5 min-w-0 text-base`,children:si(e,!0).map((t,n)=>{if(t.type===`thinking-group`){let e=t;return(0,$.jsx)(Jo,{text:e.text,label:e.label,isStreaming:e.isCurrentlyStreaming},`tg-${n}`)}let r=t;if(r.type===`tool_use`&&r.name===`todo`||r.type===`tool-result`&&r.toolName===`todo`)return r.type===`tool-result`?(0,$.jsx)(Go,{inline:!0,sequence:l,block:r},`b-${n}`):null;if(r.type===`tool-result`&&r.toolName===`ask_user`)return null;if(r.type===`long_running_confirmation`){let t=r.prompt;return Js(t,`stream-${n}`,qs(e,t.toolCallId))}if(r.type===`shell_permission`){let e=r.prompt;return Ys(e,`stream-${n}`,i)}if(r.type===`web_fetch_permission`){let e=r.prompt;return Xs(e,`stream-${n}`,i)}return(0,$.jsx)(`div`,{children:r.type===`text`&&`text`in r?(0,$.jsx)(ha,{content:Xr(r.text),enableMermaid:!0}):r.type===`tool_use`?(()=>{let t=r.id,n=Gs(e,t),i=Ws(d[t]??{});return Zs(r,void 0,!Ks(e,t),n,i)})():r.type===`tool-result`?(0,$.jsx)(Go,{inline:!0,block:r}):null},`b-${n}`)})}):a||o?(0,$.jsx)(`div`,{className:`min-w-0`,children:(0,$.jsx)(Jo,{isStreaming:!0})}):null,t[0]=a,t[1]=o,t[2]=r,t[3]=i,t[4]=n,t[5]=u,t[6]=d,t[7]=l,t[8]=f,t[9]=p,t[10]=m,t[11]=h,t[12]=g}else f=t[8],p=t[9],m=t[10],h=t[11],g=t[12];let _;return t[18]!==f||t[19]!==p||t[20]!==m||t[21]!==h||t[22]!==g?(_=(0,$.jsx)(f,{v0:p,v1:m,v2:h,v3:g}),t[18]=f,t[19]=p,t[20]=m,t[21]=h,t[22]=g,t[23]=_):_=t[23],_},Hs=Cr(e=>(0,$.jsxs)(`div`,{className:`mt-2 relative group/img inline-block max-w-full`,children:[(0,$.jsx)(`img`,{src:e.v0,alt:`Generated image`,className:`max-w-full rounded-lg border border-border block`,style:e.v1}),(0,$.jsx)(`div`,{className:`absolute top-2 right-2 flex gap-1 opacity-0 group-hover/img:opacity-100 transition-opacity`,children:e.v2})]}),{name:`GeneratedImagePreview_1`,portals:[`v2`]}),Us=function(e){let t=(0,X.c)(27),{src:n}=e,[r,i]=(0,Y.useState)(!1),a;t[0]===n?a=t[1]:(a=async()=>{let e=`generated-image-${Date.now()}.png`,{path:t}=await Ue(n.startsWith(`data:`)?{imageData:n.replace(/^data:[^;]+;base64,/,``),filename:e}:{imageUrl:n,filename:e});Ii({title:`Saved to downloads: ${t.split(`/`).pop()}`})},t[0]=n,t[1]=a);let o=a,s;t[2]===n?s=t[3]:(s=async()=>{await We(n.startsWith(`data:`)?{imageData:n.replace(/^data:[^;]+;base64,/,``)}:{imageUrl:n}),i(!0),setTimeout(()=>i(!1),2e3)},t[2]=n,t[3]=s);let c=s,l;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(l={maxHeight:`512px`},t[4]=l):l=t[4];let u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(Ie,{className:`h-3.5 w-3.5`}),t[5]=u):u=t[5];let d;t[6]===o?d=t[7]:(d=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:o,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:u})}),t[6]=o,t[7]=d);let f;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(K,{children:`Save image`}),t[8]=f):f=t[8];let p;t[9]===d?p=t[10]:(p=(0,$.jsxs)(W,{children:[d,f]}),t[9]=d,t[10]=p);let m;t[11]===r?m=t[12]:(m=r?(0,$.jsx)(ln,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(it,{className:`h-3.5 w-3.5`}),t[11]=r,t[12]=m);let h;t[13]!==c||t[14]!==m?(h=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`button`,{onClick:c,className:`flex items-center justify-center h-7 w-7 rounded-md bg-background/80 backdrop-blur-sm border border-border text-foreground hover:bg-background transition-colors`,children:m})}),t[13]=c,t[14]=m,t[15]=h):h=t[15];let g=r?`Copied!`:`Copy to clipboard`,_;t[16]===g?_=t[17]:(_=(0,$.jsx)(K,{children:g}),t[16]=g,t[17]=_);let v;t[18]!==_||t[19]!==h?(v=(0,$.jsxs)(W,{children:[h,_]}),t[18]=_,t[19]=h,t[20]=v):v=t[20];let y;t[21]!==v||t[22]!==p?(y=(0,$.jsxs)(Nt,{children:[p,v]}),t[21]=v,t[22]=p,t[23]=y):y=t[23];let b;return t[24]!==n||t[25]!==y?(b=(0,$.jsx)(Hs,{v0:n,v1:l,v2:y}),t[24]=n,t[25]=y,t[26]=b):b=t[26],b};function Ws(e){if(typeof e.executionOutput==`string`)return e.executionOutput;let t=e.partial?.content?.[0]?.arguments;if(!(!t||typeof t!=`object`)&&`content`in t&&typeof t.content==`string`)return t.content}function Gs(e,t){let n=e.find(e=>e.type===`tool-result`&&e.toolCallId===t);if(!n)return;let r=n,i=r.result??r.content;if(i!=null)return typeof i==`string`?i:JSON.stringify(i,null,2)}function Ks(e,t){return e.some(e=>e.type===`tool-result`&&e.toolCallId===t)}function qs(e,t){if(t)return Gs(e,t)}function Js(e,t,n){return(0,$.jsx)(cs,{toolCallId:e.toolCallId??`long-running-confirmation`,question:e.question,options:e.options,context:e.context,answeredText:n,answeredLabel:`You answered`},t)}function Ys(e,t,n){return(0,$.jsx)(Cs,{toolCallId:e.toolCallId,command:e.command,projectId:n,wildcardOptions:e.wildcardOptions},t)}function Xs(e,t,n){return(0,$.jsx)(Es,{toolCallId:e.toolCallId,hostname:e.hostname,url:e.url,projectId:n,wildcardOptions:e.wildcardOptions},t)}function Zs(e,t,n,r,i){if(e.name===`ask_user`)return(0,$.jsx)(cs,{toolCallId:e.id,question:typeof e.input?.question==`string`?e.input.question:``,options:e.input?.options,context:e.input?.context,answeredText:r},t);if(e.name===`run_js`||e.name===`run_web_worker`)return(0,$.jsx)(Ls,{toolCallId:e.id,intention:e.input?.intention??``,code:e.input?.code??``},t);let a=n===!0&&r===void 0,o=e.name===`bash`||e.name===`read`||e.name===`file_read`||ns(e.name,e.input);return a&&!o?(0,$.jsx)(Zo,{toolCall:e},t):(0,$.jsx)(Io,{inline:!0,block:e,resultContent:a?i:r,isActive:a},t)}function Qs({message:e,threadId:t,messageIndex:n=0,showCheckpointRestore:r=!1,checkpointRestoreTooltip:i}){let a=e.sender===`user`,o=a?null:ei(e.content),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),d=a&&(r||!!i),f=e.timestamp?new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):``;async function p(){if(!(!e.checkpointRef||!t||s)){c(!0);try{let n=await nn(t,e.checkpointRef);n.success?Ii({title:`Checkpoint restored`,description:`Working tree restored to before this agent run.`}):Ii({title:`Restore failed`,description:n.error??`Could not restore checkpoint.`,variant:`destructive`})}catch(e){Ii({title:`Restore failed`,description:e instanceof Error?e.message:`Unknown error`,variant:`destructive`})}finally{c(!1)}}}async function m(){try{await navigator.clipboard.writeText(e.content),u(!0),setTimeout(()=>u(!1),2e3)}catch(e){Ii({title:`Copy failed`,description:e instanceof Error?e.message:`Could not copy prompt.`,variant:`destructive`})}}return(0,$.jsx)(`div`,{className:q(`group px-4 py-4`,a&&`flex justify-end`),children:(0,$.jsxs)(`div`,{className:q(`flex flex-col gap-1 min-w-0 max-w-full`,a&&`items-end`),children:[(0,$.jsxs)(`div`,{className:q(`flex items-center gap-2`,a&&`flex-row-reverse`),children:[(0,$.jsx)(`span`,{className:q(J.compact,`font-medium text-foreground`),children:a?`You`:`Agent`}),a&&(0,$.jsx)(Nt,{children:(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`span`,{tabIndex:0,className:`inline-flex`,children:(0,$.jsx)(`button`,{onClick:m,"aria-label":l?`Prompt copied`:`Copy prompt`,className:`flex items-center justify-center h-5 w-5 rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-muted`,children:l?(0,$.jsx)(ln,{className:`h-3 w-3 text-green-500`}):(0,$.jsx)(it,{className:`h-3 w-3`})})})}),(0,$.jsx)(K,{side:`left`,children:l?`Copied prompt`:`Copy prompt`})]}),d&&(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`span`,{tabIndex:0,className:`inline-flex`,children:(0,$.jsx)(`button`,{onClick:r?p:void 0,disabled:!r||s,"aria-label":i??`Restore checkpoint`,className:`flex items-center justify-center h-5 w-5 rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-muted disabled:opacity-50 disabled:hover:text-muted-foreground disabled:hover:bg-transparent`,children:(0,$.jsx)($t,{className:q(`h-3 w-3`,s&&`animate-spin`)})})})}),(0,$.jsx)(K,{side:`left`,children:i??`Restore checkpoint`})]})]})}),f&&(0,$.jsxs)(`span`,{className:q(J.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(rn,{className:`h-2.5 w-2.5`}),f]}),e.model&&(0,$.jsxs)(`span`,{className:q(J.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(pe,{className:`h-2.5 w-2.5`}),_r(e.model)]}),e.metadata?.processingTimeMs&&(0,$.jsxs)(`span`,{className:q(J.compact,`flex items-center gap-1 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[(0,$.jsx)(Ne,{className:`h-2.5 w-2.5`}),e.metadata.processingTimeMs>=6e4?`${Math.floor(e.metadata.processingTimeMs/6e4)}m ${Math.round(e.metadata.processingTimeMs%6e4/1e3)}s`:`${Math.round(e.metadata.processingTimeMs/1e3)}s`]}),(e.metadata?.tokenCount||e.metadata?.estimatedCost)&&(0,$.jsxs)(`span`,{className:q(J.compact,`text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity`),children:[e.metadata.tokenCount?`${e.metadata.tokenCount.toLocaleString()} tokens`:null,e.metadata.tokenCount&&e.metadata.estimatedCost?` · `:null,e.metadata.estimatedCost?oe(e.metadata.estimatedCost):null]})]}),(0,$.jsx)(`div`,{className:q(`flex flex-col gap-0.5 min-w-0 text-base`,a&&`rounded-xl px-4 py-3 bg-foreground text-background`),children:e.isThinking?(()=>{let t=Zr(e.content);return t?.length?(0,$.jsx)($.Fragment,{children:si(t,!1).map((e,n)=>{if(e.type===`thinking-group`){let t=e;return(0,$.jsx)(Jo,{text:t.text,label:t.label,isStreaming:!1},`tg-${n}`)}let r=e;if(r.type===`tool_use`)return Zs(r,n,!1,Gs(t,r.id));if(r.type===`long_running_confirmation`){let e=r.prompt;return Js(e,n,qs(t,e.toolCallId))}if(r.type===`shell_permission`){let e=r.prompt;return Ys(e,n)}if(r.type===`web_fetch_permission`){let e=r.prompt;return Xs(e,n)}return r.type===`tool-result`?(0,$.jsx)(Go,{inline:!0,block:r},n):null})}):(0,$.jsx)(`div`,{className:q(J.bodyMuted,`leading-relaxed whitespace-pre-wrap`),children:(0,$.jsx)(ha,{content:Xr(e.content),enableMermaid:!0})})})():o?(0,$.jsx)($.Fragment,{children:si(o,!1).map((e,t)=>{if(e.type===`thinking-group`){let n=e;return(0,$.jsx)(Jo,{text:n.text,label:n.label,isStreaming:!1},`tg-${t}`)}let r=e;if(r.type===`tool_use`&&r.name===`todo`||r.type===`tool-result`&&r.toolName===`todo`)return r.type===`tool-result`?(0,$.jsx)(Go,{inline:!0,sequence:n,block:r},t):null;if(r.type===`tool-result`&&r.toolName===`ask_user`)return null;if(r.type===`long_running_confirmation`){let e=r.prompt;return Js(e,t,qs(o,e.toolCallId))}return(0,$.jsx)(`div`,{children:r.type===`text`&&`text`in r?(0,$.jsx)(ha,{content:Xr(r.text),enableMermaid:!0}):r.type===`tool_use`?Zs(r,void 0,!1,Gs(o,r.id)):r.type===`tool-result`?(0,$.jsx)(Go,{inline:!0,block:r}):null},t)})}):(0,$.jsx)(ha,{content:Xr(e.content),enableMermaid:!0,className:J.body})}),(e.generatedImageUrl||e.generatedImageData)&&(0,$.jsx)(Us,{src:e.generatedImageData?`data:image/png;base64,${e.generatedImageData}`:e.generatedImageUrl}),e.attachments&&e.attachments.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:e.attachments.map((e,t)=>(0,$.jsxs)(`span`,{className:q(J.compact,`flex items-center gap-1 rounded-md bg-muted px-2 py-1 text-muted-foreground`),children:[(0,$.jsx)(kt,{className:`h-2.5 w-2.5`}),e.fileName]},t))})]})})}var $s=(0,Y.memo)(Vs,(e,t)=>{if(e.model!==t.model||e.isCreatingProject!==t.isCreatingProject||e.isProcessingThread!==t.isProcessingThread||e.showProcessingLine!==t.showProcessingLine||e.totalMessages!==t.totalMessages||e.segments.length!==t.segments.length)return!1;for(let n=0;n<e.segments.length;n++){let r=e.segments[n],i=t.segments[n];if(r.type!==i.type)return!1;if(r.type===`long_running_confirmation`){if(i.type!==`long_running_confirmation`||JSON.stringify(r.prompt)!==JSON.stringify(i.prompt))return!1;continue}if(r.type===`shell_permission`){if(i.type!==`shell_permission`||JSON.stringify(r.prompt)!==JSON.stringify(i.prompt))return!1;continue}if(r.type===`web_fetch_permission`){if(i.type!==`web_fetch_permission`||JSON.stringify(r.prompt)!==JSON.stringify(i.prompt))return!1;continue}if(i.type===`long_running_confirmation`||i.type===`shell_permission`||i.type===`web_fetch_permission`||r.chunks.length!==i.chunks.length)return!1;for(let e=0;e<r.chunks.length;e++)if(r.chunks[e]!==i.chunks[e])return!1}return!0});function ec(e){return e.toolCallProgress}var tc=3e3;function nc(e){let t=[...m],n=e?t.filter(t=>t!==e):t;return n[Math.floor(Math.random()*n.length)]}function rc(e){let t=(0,X.c)(3),[n,r]=(0,Y.useState)(v),i=(0,Y.useRef)(v),a,o;return t[0]===e?(a=t[1],o=t[2]):(a=()=>{if(!e){r(v),i.current=v;return}let t=setInterval(()=>{let e=i.current===`Processing...`?nc():nc(i.current);i.current=e,r(e)},tc);return()=>clearInterval(t)},o=[e],t[0]=e,t[1]=a,t[2]=o),(0,Y.useEffect)(a,o),n}var ic=`w-7`,ac=`-ml-9`;function oc(e){let t=(0,X.c)(11),{active:n,className:r}=e,i=n===void 0?!0:n,a=rc(i),o;t[0]===r?o=t[1]:(o=q(`flex items-center gap-2`,ac,r),t[0]=r,t[1]=o);let s;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(vo,{className:ic}),t[2]=s):s=t[2];let c=i?`animate-shimmer`:void 0,l;t[3]===c?l=t[4]:(l=q(J.caption,c),t[3]=c,t[4]=l);let u;t[5]!==a||t[6]!==l?(u=(0,$.jsx)(`span`,{className:l,children:a}),t[5]=a,t[6]=l,t[7]=u):u=t[7];let d;return t[8]!==o||t[9]!==u?(d=(0,$.jsxs)(`div`,{className:o,"aria-live":`polite`,"aria-busy":`true`,children:[s,u]}),t[8]=o,t[9]=u,t[10]=d):d=t[10],d}var sc=Cr(e=>(0,$.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-1 flex-col items-center justify-center gap-8 px-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,$.jsx)(`img`,{src:`/tarsk-color.svg`,alt:`Tarsk`,className:`h-16 w-16 rounded-lg`}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`h1`,{className:e.v0,children:`Let's build it!`}),(0,$.jsx)(`p`,{className:e.v1,children:e.v2})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-3`,children:[e.v3,(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:e.v4,children:[e.v5,(0,$.jsx)(`span`,{className:e.v6,children:`Connect a repo`}),(0,$.jsx)(`span`,{className:e.v7,children:`Clone an existing repository`})]}),(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:e.v8,children:[e.v9,(0,$.jsx)(`span`,{className:e.v10,children:`New App`}),(0,$.jsx)(`span`,{className:e.v11,children:`Create a new project from template`})]}),(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:e.v12,children:[e.v13,(0,$.jsx)(`span`,{className:e.v14,children:`Open Folder`}),(0,$.jsx)(`span`,{className:e.v15,children:`Use an existing local folder`})]})]})]}),{name:`WelcomeScreen_1`,portals:[`v2`,`v3`,`v5`,`v9`,`v13`]}),cc=function(e){let t=(0,X.c)(17),{projects:n,onSelectProject:r,onCreateThread:i,onConnectRepo:a,onNewApp:o,onOpenFolder:s}=e,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=q(J.pageTitle,`tracking-tight text-balance`),t[0]=c):c=t[0];let l=n.length===0?`Start or connect your first project`:`Select a project to start coding`,u;if(t[1]!==i||t[2]!==r||t[3]!==n){let e;t[5]!==i||t[6]!==r?(e=e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex w-56 flex-col gap-2 rounded-xl border border-border bg-background p-4 text-left shadow-sm transition-colors hover:bg-muted`,onClick:()=>{e.threads.length===0?i(e.projectId):r(e.projectId,e.threads[0].threadId)},children:[(0,$.jsx)(D,{className:`h-5 w-5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`${J.body} text-foreground leading-snug font-medium`,children:e.name}),(0,$.jsxs)(`span`,{className:J.caption,children:[e.threads.length,` thread`,e.threads.length===1?``:`s`]})]},e.projectId),t[5]=i,t[6]=r,t[7]=e):e=t[7],u=n.map(e),t[1]=i,t[2]=r,t[3]=n,t[4]=u}else u=t[4];let d;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(En,{className:`h-5 w-5 text-muted-foreground`}),t[8]=d):d=t[8];let f;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(Ht,{className:`h-5 w-5 text-muted-foreground`}),t[9]=f):f=t[9];let p;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(ke,{className:`h-5 w-5 text-muted-foreground`}),t[10]=p):p=t[10];let m;return t[11]!==a||t[12]!==o||t[13]!==s||t[14]!==l||t[15]!==u?(m=(0,$.jsx)(sc,{v0:c,v1:`mt-1 ${J.pageSubtitle}`,v2:l,v3:u,v4:a,v5:d,v6:`${J.body} text-foreground leading-snug font-medium`,v7:J.caption,v8:o,v9:f,v10:`${J.body} text-foreground leading-snug font-medium`,v11:J.caption,v12:s,v13:p,v14:`${J.body} text-foreground leading-snug font-medium`,v15:J.caption}),t[11]=a,t[12]=o,t[13]=s,t[14]=l,t[15]=u,t[16]=m):m=t[16],m};function lc(){let e=Q(e=>e.selectedThreadId),{dispatch:t}=xi(e),{setActiveMainTab:n,setDevServerUrl:r,setDevServerRunning:i,setDevServerLoading:a}=Fa();return{startServer:async o=>{if(!o?.runCommand||!o?.projectId)return;a(!0),t({type:Z.ClearTerminalOutput}),t({type:Z.SetTerminalOpen,open:!1}),t({type:Z.AppendTerminalLine,line:{type:`system`,content:`Starting dev server: ${o.runCommand}`}});let s=!1,c=setTimeout(()=>{s=!0,t({type:Z.SetTerminalOpen,open:!0})},3e3);try{let l=await st(o.projectId,e??void 0);if(!l){clearTimeout(c),t({type:Z.AppendTerminalLine,line:{type:`error`,content:`Failed to start dev server`}}),a(!1);return}let u=l.getReader(),d=new TextDecoder;i(!0),a(!1);let f=!1,p=!1;for(;;){let{done:e,value:i}=await u.read();if(e)break;let o=d.decode(i,{stream:!0});try{let e=o.split(`
29
- `).filter(e=>e.trim());for(let i of e)try{let e=JSON.parse(i);p||(p=!0,a(!1)),e.type===`url`&&e.url&&(clearTimeout(c),t({type:Z.AppendTerminalLine,line:{type:`system`,content:`✓ Server running at: ${e.url}`}}),r(e.url),n(`browser`),s&&setTimeout(()=>{t({type:Z.SetTerminalOpen,open:!1})},100),f=!0)}catch{}}catch{}}f||t({type:Z.AppendTerminalLine,line:{type:`system`,content:`Server is running but URL could not be detected`}})}catch(e){console.error(`Failed to start dev server:`,e),a(!1),t({type:Z.AppendTerminalLine,line:{type:`error`,content:`Failed to start dev server`}})}},setServerUrl:r}}var uc=Cr(e=>(0,$.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 px-4`,children:[(0,$.jsx)(`img`,{src:`/tarsk-color.svg`,alt:`Tarsk`,className:`h-16 w-16 rounded-lg`}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`h1`,{className:e.v0,children:e.v1}),(0,$.jsx)(`p`,{className:e.v2,children:e.v3})]}),e.v4]})}),{name:`ChatMessagesPlaceholder_1`,portals:[`v1`,`v3`,`v4`]}),dc=function(e){let t=(0,X.c)(19),{project:n}=e,{setDevServerRunning:r}=Fa(),[i,a]=(0,Y.useState)(!1),{startServer:o}=lc(),s;t[0]!==n||t[1]!==r?(s=()=>{if(!n?.projectId)return;let e=async()=>{try{let e=await Jt(n.projectId);a(e.isRunning),r(e.isRunning)}catch{a(!1),r(!1)}};e();let t=setInterval(e,2e3);return()=>clearInterval(t)},t[0]=n,t[1]=r,t[2]=s):s=t[2];let c=n?.projectId,l;t[3]===c?l=t[4]:(l=[c],t[3]=c,t[4]=l),(0,Y.useEffect)(s,l),n?.name;let u=n?.name??`your project`,d;t[5]===u?d=t[6]:(d=fc(u),t[5]=u,t[6]=d);let f=d,p=!i&&n?.runCommand,m;t[7]!==n||t[8]!==o?(m=()=>{n&&o(n)},t[7]=n,t[8]=o,t[9]=m):m=t[9];let h=m,g;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(g=q(J.pageTitle,`tracking-tight text-foreground text-balance`),t[10]=g):g=t[10];let _=n?.name??`Project`,v;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(v=q(J.pageSubtitle,`mt-2`),t[11]=v):v=t[11];let y;t[12]!==h||t[13]!==p?(y=p&&(0,$.jsx)(`button`,{type:`button`,onClick:h,className:q(J.label,`inline-flex items-center gap-2 rounded-full bg-primary px-4 py-2 text-primary-foreground hover:bg-primary/90 transition-colors`),children:`Start App`}),t[12]=h,t[13]=p,t[14]=y):y=t[14];let b;return t[15]!==f||t[16]!==y||t[17]!==_?(b=(0,$.jsx)(uc,{v0:g,v1:_,v2:v,v3:f,v4:y}),t[15]=f,t[16]=y,t[17]=_,t[18]=b):b=t[18],b};function fc(e){let t=[`What would you like to add to ${e}?`,`What should we build in ${e}?`,`What changes do you want to make to ${e}?`,`What feature should we add to ${e}?`,`What would you like to fix in ${e}?`,`What are we working on in ${e}?`,`What's next for ${e}?`,`What should we improve in ${e}?`,`How can we make ${e} better?`,`What would you like to change in ${e}?`,`What should we ship in ${e} next?`];return t[Math.floor(Math.random()*t.length)]}var pc=(0,Y.forwardRef)((e,t)=>{let n=(0,X.c)(9),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({style:a,children:r,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;return n[4]!==r||n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(`div`,{ref:t,style:a,...i,className:`mx-auto max-w-3xl w-full min-w-0`,children:r}),n[4]=r,n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});pc.displayName=`MessageList`;function mc(e){let t=(0,X.c)(23),{context:n}=e;if(!n)return null;let{bottomInset:r,isStreaming:i,isCreatingProject:a,isProcessingThread:o,hasPendingMessage:s,hasActiveBlockingPrompt:c,selectedProjectId:l,streamingSegments:u,streamingModel:d,totalMessages:f,error:p,onClearError:m}=n,h=u.length>0||a||o&&(i||s),g=(i||s)&&!c,_;t[0]===r?_=t[1]:(_={paddingBottom:r},t[0]=r,t[1]=_);let v;t[2]!==h||t[3]!==a||t[4]!==o||t[5]!==i||t[6]!==l||t[7]!==g||t[8]!==d||t[9]!==u||t[10]!==f?(v=h&&(i||a||o)&&(0,$.jsx)($s,{segments:u,model:d,projectId:l,isCreatingProject:a,isProcessingThread:o,totalMessages:f,showProcessingLine:g}),t[2]=h,t[3]=a,t[4]=o,t[5]=i,t[6]=l,t[7]=g,t[8]=d,t[9]=u,t[10]=f,t[11]=v):v=t[11];let y;t[12]!==h||t[13]!==g?(y=g&&(0,$.jsx)(`div`,{className:q(`px-4 pb-4`,h?`pt-0`:`pt-2`),children:(0,$.jsx)(oc,{active:g})}),t[12]=h,t[13]=g,t[14]=y):y=t[14];let b;t[15]!==p||t[16]!==m?(b=p&&(0,$.jsxs)(`div`,{className:`mx-4 my-2`,children:[(0,$.jsx)(Mr,{variant:`error`,className:`mb-0`,children:p}),(0,$.jsx)(`button`,{type:`button`,className:q(J.compact,`mt-1 text-destructive underline underline-offset-2 hover:text-destructive/80`),onClick:m,children:`Dismiss`})]}),t[15]=p,t[16]=m,t[17]=b):b=t[17];let x;return t[18]!==_||t[19]!==v||t[20]!==y||t[21]!==b?(x=(0,$.jsxs)(`div`,{className:`mx-auto max-w-3xl w-full min-w-0`,style:_,children:[v,y,b]}),t[18]=_,t[19]=v,t[20]=y,t[21]=b,t[22]=x):x=t[22],x}var hc={List:pc,Footer:mc};function gc(e){if(e.isUser)return e.hasCheckpointRef?e.isStreaming||e.hasPendingMessage||e.isCreatingProject||e.isProcessingThread?`Restore unavailable while this thread is still processing.`:`Restore checkpoint`:`Restore unavailable: no checkpoint was created for this prompt.`}function _c(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.type===`long_running_confirmation`||n.type===`shell_permission`||n.type===`web_fetch_permission`)return t}return-1}function vc(e){let t=e.some(e=>e.type!==`long_running_confirmation`&&e.type!==`shell_permission`&&e.type!==`web_fetch_permission`&&`chunks`in e&&e.chunks.some(e=>e.includes(`"type":"tool_use"`)&&e.includes(`"name":"ask_user"`))),n=e.some(e=>e.type!==`long_running_confirmation`&&e.type!==`shell_permission`&&e.type!==`web_fetch_permission`&&`chunks`in e&&e.chunks.some(e=>e.includes(`"type":"tool-result"`)&&e.includes(`"toolName":"ask_user"`)));if(t&&!n)return!0;let r=_c(e);return r===-1?!1:!e.slice(r+1).some(e=>e.type===`content`||e.type===`thinking`?e.chunks.some(e=>e.trim().length>0):!1)}var yc=(0,Y.forwardRef)(function(e,t){let n=(0,X.c)(71),{bottomInset:r,messages:i,isStreaming:a,streamingSegments:o,streamingModel:s,isCreatingProject:c,isProcessingThread:l,hasPendingMessage:u,selectedThreadId:d,selectedProjectId:f,projects:p,projectsLoading:m,messagesLoaded:h,onSelectThread:g,onCreateThread:_,onConnectRepo:v,onNewApp:y,onOpenFolder:b,error:x,onClearError:S,onAtBottomChange:C}=e,w=r===void 0?0:r,T=(0,Y.useRef)(null),E=(0,Y.useRef)(0),D=(0,Y.useRef)(!1),O=(0,Y.useRef)(!1),k;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(k=()=>({scrollToBottom:()=>{T.current?.scrollTo({top:2**53-1,behavior:`smooth`})}}),n[0]=k):k=n[0],(0,Y.useImperativeHandle)(t,k);let A;n[1]===d?A=n[2]:(A=()=>{d&&T.current?.getState(e=>{Et(d,e.scrollTop)})},n[1]=d,n[2]=A);let j=A,M,N;n[3]===j?(M=n[4],N=n[5]):(M=()=>{let e=()=>{j()};return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e),j()}},N=[j],n[3]=j,n[4]=M,n[5]=N),(0,Y.useEffect)(M,N);let P,F;n[6]===j?(P=n[7],F=n[8]):(P=()=>{let e=setInterval(()=>{j()},5e3);return()=>clearInterval(e)},F=[j],n[6]=j,n[7]=P,n[8]=F),(0,Y.useEffect)(P,F);let I,L;n[9]!==i.length||n[10]!==h||n[11]!==d?(I=()=>{if(!d||!h||O.current||(O.current=!0,i.length===0))return;let e=an(d);e!==null&&e>0&&requestAnimationFrame(()=>{T.current?.scrollTo({top:e})})},L=[d,h,i.length],n[9]=i.length,n[10]=h,n[11]=d,n[12]=I,n[13]=L):(I=n[12],L=n[13]),(0,Y.useEffect)(I,L);let R;n[14]===Symbol.for(`react.memo_cache_sentinel`)?(R=()=>{O.current=!1,E.current=0},n[14]=R):R=n[14];let ee;n[15]===d?ee=n[16]:(ee=[d],n[15]=d,n[16]=ee),(0,Y.useEffect)(R,ee);let te;n[17]!==u||n[18]!==a||n[19]!==i.length?(te=()=>{if(!O.current)return;let e=i.length>E.current,t=D.current&&!a;(a||u||e||t)&&requestAnimationFrame(()=>{T.current?.scrollTo({top:2**53-1,behavior:`smooth`})}),E.current=i.length,D.current=a},n[17]=u,n[18]=a,n[19]=i.length,n[20]=te):te=n[20];let z;n[21]!==u||n[22]!==a||n[23]!==i||n[24]!==o.length?(z=[a,u,i,o.length],n[21]=u,n[22]=a,n[23]=i,n[24]=o.length,n[25]=z):z=n[25],(0,Y.useEffect)(te,z);let ne=i.length===0&&!a&&!c&&!d,B=h&&i.length===0&&!a&&!c&&!l&&!u&&d,re;if(n[26]!==p||n[27]!==f){let e;n[29]===f?e=n[30]:(e=e=>e.projectId===f,n[29]=f,n[30]=e),re=p.find(e),n[26]=p,n[27]=f,n[28]=re}else re=n[28];let V=re;if(ne){let e=`transition-opacity duration-500 ease-in-out ${m?`opacity-0`:`opacity-100`}`,t;n[31]!==v||n[32]!==_||n[33]!==y||n[34]!==b||n[35]!==g||n[36]!==p?(t=(0,$.jsx)(cc,{projects:p,onSelectProject:g,onCreateThread:_,onConnectRepo:v,onNewApp:y,onOpenFolder:b}),n[31]=v,n[32]=_,n[33]=y,n[34]=b,n[35]=g,n[36]=p,n[37]=t):t=n[37];let r;return n[38]!==e||n[39]!==t?(r=(0,$.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:(0,$.jsx)(`div`,{className:e,children:t})}),n[38]=e,n[39]=t,n[40]=r):r=n[40],r}if(B){let e;return n[41]===V?e=n[42]:(e=(0,$.jsx)(dc,{project:V}),n[41]=V,n[42]=e),e}let ie;n[43]===o?ie=n[44]:(ie=vc(o),n[43]=o,n[44]=ie);let ae;n[45]!==w||n[46]!==x||n[47]!==u||n[48]!==c||n[49]!==l||n[50]!==a||n[51]!==i.length||n[52]!==S||n[53]!==f||n[54]!==s||n[55]!==o||n[56]!==ie?(ae={bottomInset:w,isStreaming:a,isCreatingProject:c,isProcessingThread:l,hasPendingMessage:u,hasActiveBlockingPrompt:ie,selectedProjectId:f,streamingSegments:o,streamingModel:s,totalMessages:i.length,error:x,onClearError:S},n[45]=w,n[46]=x,n[47]=u,n[48]=c,n[49]=l,n[50]=a,n[51]=i.length,n[52]=S,n[53]=f,n[54]=s,n[55]=o,n[56]=ie,n[57]=ae):ae=n[57];let oe=ae,H;n[58]===Symbol.for(`react.memo_cache_sentinel`)?(H=q(`h-full overflow-hidden`),n[58]=H):H=n[58];let se;n[59]===Symbol.for(`react.memo_cache_sentinel`)?(se={height:`100%`},n[59]=se):se=n[59];let ce;n[60]!==u||n[61]!==c||n[62]!==l||n[63]!==a||n[64]!==d?(ce=(e,t)=>{let n=gc({isUser:t.sender===`user`,hasCheckpointRef:!!t.checkpointRef,isStreaming:a,hasPendingMessage:u,isCreatingProject:c,isProcessingThread:l});return(0,$.jsx)(Qs,{message:t,threadId:d,messageIndex:e,showCheckpointRestore:t.sender===`user`&&!!t.checkpointRef&&!a&&!u&&!c&&!l,checkpointRestoreTooltip:n})},n[60]=u,n[61]=c,n[62]=l,n[63]=a,n[64]=d,n[65]=ce):ce=n[65];let le;return n[66]!==oe||n[67]!==i||n[68]!==C||n[69]!==ce?(le=(0,$.jsx)(`div`,{className:H,children:(0,$.jsx)(sr,{ref:T,style:se,data:i,context:oe,itemContent:ce,overscan:500,components:hc,atBottomStateChange:C})}),n[66]=oe,n[67]=i,n[68]=C,n[69]=ce,n[70]=le):le=n[70],le});function bc(e,t){return e?`linear-gradient(to right, transparent 0, transparent 40px, ${t} 40px)`:`linear-gradient(to right, ${t}, ${t})`}function xc(e){return bc(e,`hsl(var(--background))`)}function Sc(e){let t=bc(e,`hsl(var(--background))`);return e?`linear-gradient(to top, hsl(var(--background)) 0, hsl(var(--background)) calc(100% - 40px), transparent calc(100% - 40px), transparent 100%), ${t}`:`linear-gradient(to top, hsl(var(--background)) 0, transparent 100%), ${t}`}function Cc(e,t){return bc(e,t?`hsl(var(--background) / 0.8)`:`hsl(var(--background))`)}function wc({initialValue:e}={}){let t=yi(),n=Q(e=>e.selectedThreadId),r=Q(e=>e.selectedProjectId),i=Q(e=>e.projects),a=Q(e=>e.projectModelSelections),o=Q(e=>e.chatInputDrafts),s=Q(e=>e.configUpdatedAt),c=Q(e=>e.focusChatInput),l=Q(e=>e.isStreaming),[u,d]=(0,Y.useState)(()=>n&&o[n]?o[n]:e??``),[f,p]=(0,Y.useState)(-1),[m,h]=(0,Y.useState)(``),[g,_]=(0,Y.useState)(0),v=(0,Y.useRef)(u);(0,Y.useEffect)(()=>{v.current=u},[u]);let y=(0,Y.useRef)(o);(0,Y.useEffect)(()=>{y.current=o},[o]);let b=(0,Y.useRef)(!0);(0,Y.useEffect)(()=>(b.current=!0,()=>{b.current=!1}),[]);let[x,S]=(0,Y.useState)([]),[C,w]=(0,Y.useState)(()=>(n?a[n]:void 0)??null),T=(0,Y.useRef)(C?.id??``),E=(0,Y.useRef)(C?.provider??``),D=(0,Y.useRef)(null),[O,k]=(0,Y.useState)(!1),[A,j]=(0,Y.useState)(!1),[M,N]=(0,Y.useState)([]),[P,F]=(0,Y.useState)(!1),[I,L]=(0,Y.useState)(!1),[R,ee]=(0,Y.useState)(!1),[te,z]=(0,Y.useState)([]),[ne,B]=(0,Y.useState)(null),[re,V]=(0,Y.useState)([]),[ie,ae]=(0,Y.useState)(!1),[oe,H]=(0,Y.useState)(``),[ce,le]=(0,Y.useState)(0),[ue,de]=(0,Y.useState)([]),[pe,me]=(0,Y.useState)([]),[he,ge]=(0,Y.useState)(!1),[_e,ve]=(0,Y.useState)(``),ye=(0,Y.useRef)(null),be=(0,Y.useRef)(null),xe=(0,Y.useRef)(null),Se=(0,Y.useRef)(null),Ce=(0,Y.useRef)(null),we=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{T.current=C?.id??``,E.current=C?.provider??``},[C?.id,C?.provider]);let Te=(0,Y.useCallback)((e,r)=>{w(e);let i=n;if(!i||(t({type:Z.SetProjectModel,threadId:i,model:e}),r?.persist===!1))return;let a=`${i}:${e.provider??``}:${e.id}`;D.current!==a&&(D.current=a,console.log(`[useChatInputState] Persisting model to thread:`,{threadId:i,model:{id:e.id,provider:e.provider}}),St(i,{model:e.id,modelProvider:e.provider}).then(()=>{D.current===a&&(D.current=null),console.log(`[useChatInputState] Model persisted successfully`)}).catch(e=>{D.current===a&&(D.current=null),console.error(`Failed to save model to thread:`,e)}))},[n,t]);(0,Y.useEffect)(()=>{(async()=>{let e=r?i.find(e=>e.projectId===r)?.threads.find(e=>e.threadId===n):void 0,t=n?a[n]:void 0,o=e?.model??t?.id??null,s=e?.modelProvider??t?.provider??null;console.log(`[useChatInputState] Loading models for thread:`,{threadId:n,projectId:r,currentThread:e?{model:e.model,modelProvider:e.modelProvider}:void 0,storedModel:t?{id:t.id,provider:t.provider}:void 0,savedModelId:o,savedModelProvider:s});try{let e=await fe(),t=Object.values(e).flat();if(t.length===0){S([]),w(null);return}S(t);let n=o&&s?t.find(e=>e.id===o&&e.provider===s)??null:null,r=t[0],i=n??r,a=!n&&!!(o||s),c=T.current===i.id&&E.current===i.provider;console.log(`[useChatInputState] Model selection decision:`,{matchedSavedModel:n?{id:n.id}:null,fallbackModel:{id:r.id},modelToSelect:{id:i.id},shouldPersistFallback:a,hasSameSelection:c,currentSelected:{id:T.current,provider:E.current}}),c||Te(i,{persist:a})}catch(e){console.error(`Failed to load enabled models:`,e)}})()},[n,r,i,a,Te]);let Ee=(0,Y.useRef)(Te);(0,Y.useEffect)(()=>{Ee.current=Te},[Te]),(0,Y.useEffect)(()=>{s!==0&&(async()=>{try{let e=await fe(),t=Object.values(e).flat();if(t.length>0){S(t);let e=T.current,n=E.current;t.some(t=>t.id===e&&t.provider===n)||Ee.current(t[0],{persist:!0})}}catch(e){console.error(`Failed to reload enabled models:`,e)}})()},[s]),(0,Y.useEffect)(()=>{!R||te.length>0||(async()=>{try{let e=await ze(),t=Object.values(e).flat();t.length>0&&(z(t),B(e=>e??t[0]))}catch(e){console.error(`Failed to load image models:`,e)}})()},[R,te.length]);let[De,Oe]=(0,Y.useState)(n);(0,Y.useEffect)(()=>{if(n!==De){De&&v.current.trim()&&y.current[De]!==v.current&&t({type:Z.SetChatInputDraft,threadId:De,draft:v.current});let e=!1;return queueMicrotask(()=>{e||!b.current||(Oe(n),d(n?y.current[n]??``:``),V([]),ae(!1),de([]),me([]),ge(!1),F(!1),ee(!1),L(!1))}),()=>{e=!0}}},[n,De]),(0,Y.useEffect)(()=>{n&&se(n).then(({commands:e,skills:t})=>{console.log(`Loaded slash commands:`,e,`skills:`,t),de(e),me(t)}).catch(e=>console.error(`Failed to load slash commands and skills:`,e))},[n]);let ke=n?o[n]??``:``;return(0,Y.useEffect)(()=>{n&&d(ke)},[n,ke]),(0,Y.useLayoutEffect)(()=>{let e=be.current;if(!e)return;e.style.height=`auto`;let t=Math.max(e.scrollHeight,e.offsetHeight);e.style.height=`${Math.min(t,160)}px`},[u]),(0,Y.useEffect)(()=>{c&&n&&!l&&(be.current?.focus(),t({type:Z.ClearFocusChatInput}))},[c,n,l,t]),(0,Y.useEffect)(()=>{let e=n;return()=>{e&&v.current.trim()&&y.current[e]!==v.current&&t({type:Z.SetChatInputDraft,threadId:e,draft:v.current})}},[n,t]),(0,Y.useEffect)(()=>{let e=e=>{xe.current&&!xe.current.contains(e.target)&&k(!1),Se.current&&!Se.current.contains(e.target)&&j(!1)};if(O||A)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[O,A]),{message:u,setMessage:d,historyIndex:f,setHistoryIndex:p,draftMessage:m,setDraftMessage:h,cursorPosition:g,setCursorPosition:_,availableModels:x,setAvailableModels:S,selectedModel:C,setSelectedModel:Te,selectedModelIdRef:T,showModelMenu:O,setShowModelMenu:k,showPlusMenu:A,setShowPlusMenu:j,attachments:M,setAttachments:N,planMode:P,setPlanMode:F,ralphMode:I,setRalphMode:L,imageMode:R,setImageMode:ee,availableImageModels:te,setAvailableImageModels:z,selectedImageModel:ne,setSelectedImageModel:B,allFiles:re,setAllFiles:V,showSuggestions:ie,setShowSuggestions:ae,suggestionQuery:oe,setSuggestionQuery:H,selectedIndex:ce,setSelectedIndex:le,slashCommands:ue,setSlashCommands:de,skills:pe,setSkills:me,showCommandSuggestions:he,setShowCommandSuggestions:ge,commandQuery:_e,setCommandQuery:ve,fileInputRef:ye,textareaRef:be,modelMenuRef:xe,plusMenuRef:Se,suggestionsRef:Ce,commandSuggestionsRef:we,handleNewChat:async()=>{if(n)try{let e=await ct(n);t({type:Z.ClearMessages}),console.log(`New conversation started:`,e);let r=await at(n);t({type:Z.SetMessages,messages:r.messages})}catch(e){console.error(`Failed to start new chat:`,e)}},selectedThreadId:n,dispatch:t}}var Tc=e=>{N(e)};function Ec(e){let t=(0,X.c)(107),{message:n,setMessage:r,userTasks:i,onMatchedUserTaskSend:a,attachments:o,selectedModel:s,onSend:c,isStreaming:l,selectedThreadId:u,isListening:d,stopListening:f,resetTranscript:p,dispatch:m,historyIndex:h,setHistoryIndex:g,draftMessage:_,setDraftMessage:v,cursorPosition:y,setCursorPosition:b,showSuggestions:x,setShowSuggestions:S,suggestionQuery:C,setSuggestionQuery:w,allFiles:T,setAllFiles:E,selectedIndex:D,setSelectedIndex:O,showCommandSuggestions:k,setShowCommandSuggestions:A,commandQuery:j,setCommandQuery:M,slashCommands:N,skills:P,textareaRef:F,setAttachments:I,planMode:L,setPlanMode:R,ralphMode:ee,setRalphMode:te,imageMode:z,setImageMode:B,selectedImageModel:re,hasConversationMessages:V}=e,ie;t[0]!==o||t[1]!==m||t[2]!==z||t[3]!==d||t[4]!==l||t[5]!==n||t[6]!==a||t[7]!==c||t[8]!==L||t[9]!==ee||t[10]!==p||t[11]!==re||t[12]!==s||t[13]!==u||t[14]!==I||t[15]!==v||t[16]!==g||t[17]!==r||t[18]!==f||t[19]!==F||t[20]!==i?(ie=()=>{if(!n.trim()&&o.length===0||!u)return;let e=z?re:s;if(!e)return;d&&(f(),p()),l?m({type:Z.EnqueueChatMessage,message:{id:`queued-${Date.now()}`,threadId:u,message:n,model:e.id,attachments:o,provider:e.provider,planMode:L,imageMode:z,ralphMode:ee}}):c(n,e.id,o,e.provider,L,z,ee);let t=n,h=i.find(e=>e.content===t);Tc(n),r(``),I([]),h&&a?.(h),g(-1),v(``),u&&m({type:Z.ClearChatInputDraft,threadId:u}),F.current&&(F.current.style.height=`auto`)},t[0]=o,t[1]=m,t[2]=z,t[3]=d,t[4]=l,t[5]=n,t[6]=a,t[7]=c,t[8]=L,t[9]=ee,t[10]=p,t[11]=re,t[12]=s,t[13]=u,t[14]=I,t[15]=v,t[16]=g,t[17]=r,t[18]=f,t[19]=F,t[20]=i,t[21]=ie):ie=t[21];let ae=ie,oe;t[22]!==y||t[23]!==n||t[24]!==r||t[25]!==S||t[26]!==C||t[27]!==F?(oe=e=>{let t=n.substring(0,y-C.length-1);r(`${t}${e} ${n.substring(y)}`),S(!1),setTimeout(()=>{if(F.current){F.current.focus();let n=t.length+e.length+1;F.current.setSelectionRange(n,n)}},0)},t[22]=y,t[23]=n,t[24]=r,t[25]=S,t[26]=C,t[27]=F,t[28]=oe):oe=t[28];let H=oe,se;t[29]!==j||t[30]!==y||t[31]!==n||t[32]!==B||t[33]!==r||t[34]!==R||t[35]!==te||t[36]!==A||t[37]!==F?(se=e=>{let t=e.metadata.action===`compact`?`/compact`:e.content,i=n.substring(0,y-j.length-1);r(`${i}${t}${n.substring(y)}`),A(!1),setTimeout(()=>{if(F.current){F.current.focus();let e=i.length+t.length;F.current.setSelectionRange(e,e)}},0),e.metadata.mode===`plan`?(R(!0),te(!1),B(!1)):e.metadata.mode===`ralph`&&(te(!0),R(!1),B(!1))},t[29]=j,t[30]=y,t[31]=n,t[32]=B,t[33]=r,t[34]=R,t[35]=te,t[36]=A,t[37]=F,t[38]=se):se=t[38];let ce=se,le;t[39]!==j||t[40]!==y||t[41]!==n||t[42]!==r||t[43]!==A||t[44]!==F?(le=e=>{let t=n.substring(0,y-j.length-1),i=n.substring(y),a=e.name.includes(` `)?`/"${e.name}"`:`/${e.name}`;r(`${t}${a}${i}`),A(!1),setTimeout(()=>{if(F.current){F.current.focus();let e=t.length+a.length;F.current.setSelectionRange(e,e)}},0)},t[39]=j,t[40]=y,t[41]=n,t[42]=r,t[43]=A,t[44]=F,t[45]=le):le=t[45];let ue=le,de,fe,pe,me;if(t[46]!==T||t[47]!==j||t[48]!==_||t[49]!==ae||t[50]!==V||t[51]!==h||t[52]!==ce||t[53]!==H||t[54]!==ue||t[55]!==n||t[56]!==D||t[57]!==u||t[58]!==E||t[59]!==M||t[60]!==b||t[61]!==v||t[62]!==g||t[63]!==r||t[64]!==O||t[65]!==A||t[66]!==S||t[67]!==w||t[68]!==k||t[69]!==x||t[70]!==P||t[71]!==N||t[72]!==C){pe=e=>{if(k){if(e.key===`ArrowDown`){e.preventDefault(),O((D+1)%de.length);return}if(e.key===`ArrowUp`){e.preventDefault(),O((D-1+de.length)%de.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault();let t=de[D];t&&(t.type===`command`?ce(t.data):ue(t.data));return}if(e.key===`Escape`){A(!1);return}}if(x){let t=fe.length>0;if(e.key===`ArrowDown`&&t){e.preventDefault(),O((D+1)%fe.length);return}if(e.key===`ArrowUp`&&t){e.preventDefault(),O((D-1+fe.length)%fe.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault(),fe[D]&&H(fe[D]);return}if(e.key===`Escape`){S(!1);return}}if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),ae();return}let t=he();t.length!==0&&(e.key===`ArrowUp`?(e.preventDefault(),h===-1?(v(n),g(t.length-1),r(t[t.length-1])):h>0&&(g(h-1),r(t[h-1]))):e.key===`ArrowDown`&&(e.preventDefault(),h>0?(g(h-1),r(t[h-1])):h===0&&(g(-1),r(_))))};let e;t[77]!==T||t[78]!==u||t[79]!==E||t[80]!==M||t[81]!==b||t[82]!==r||t[83]!==O||t[84]!==A||t[85]!==S||t[86]!==w?(e=e=>{let t=e.target.value,n=e.target.selectionStart;r(t),b(n);let i=t.substring(0,n),a=i.lastIndexOf(`/`);if(a!==-1){let e=a>0?i[a-1]:``;if(a===0||/\s/.test(e)){let e=i.substring(a+1);e.includes(` `)?A(!1):(M(e),A(!0),S(!1),O(0))}else A(!1)}else{A(!1);let e=i.lastIndexOf(`#`);if(e!==-1){let t=e>0?i[e-1]:``;if(e===0||/\s/.test(t)){let t=i.substring(e+1);t.includes(` `)?S(!1):(w(t),S(!0),O(0),T.length===0&&u&&ne(u).then(e=>{E(e)}).catch(kc))}else S(!1)}else S(!1)}let o=e.target;o.style.height=`auto`,o.style.height=`${Math.min(o.scrollHeight,160)}px`},t[77]=T,t[78]=u,t[79]=E,t[80]=M,t[81]=b,t[82]=r,t[83]=O,t[84]=A,t[85]=S,t[86]=w,t[87]=e):e=t[87],me=e;let i;if(t[88]!==j||t[89]!==V||t[90]!==P||t[91]!==N){let e;t[93]!==j||t[94]!==V?(e=e=>e.metadata.action===`compact`&&!V?!1:e.name.toLowerCase().includes(j.toLowerCase()),t[93]=j,t[94]=V,t[95]=e):e=t[95];let n=N.filter(e),r;t[96]===j?r=t[97]:(r=e=>e.name.toLowerCase().includes(j.toLowerCase()),t[96]=j,t[97]=r);let a=P.filter(r);i=[...n.map(Oc),...a.map(Dc)],t[88]=j,t[89]=V,t[90]=P,t[91]=N,t[92]=i}else i=t[92];de=i.slice(0,10),fe=x?T.filter(e=>e.toLowerCase().includes(C.toLowerCase())).slice(0,10):[],t[46]=T,t[47]=j,t[48]=_,t[49]=ae,t[50]=V,t[51]=h,t[52]=ce,t[53]=H,t[54]=ue,t[55]=n,t[56]=D,t[57]=u,t[58]=E,t[59]=M,t[60]=b,t[61]=v,t[62]=g,t[63]=r,t[64]=O,t[65]=A,t[66]=S,t[67]=w,t[68]=k,t[69]=x,t[70]=P,t[71]=N,t[72]=C,t[73]=de,t[74]=fe,t[75]=pe,t[76]=me}else de=t[73],fe=t[74],pe=t[75],me=t[76];let ge;return t[98]!==de||t[99]!==fe||t[100]!==pe||t[101]!==ae||t[102]!==me||t[103]!==ce||t[104]!==H||t[105]!==ue?(ge={handleSend:ae,handleKeyDown:pe,handleTextareaInput:me,insertFileReference:H,insertCommand:ce,insertSkill:ue,allSuggestions:de,fileSuggestions:fe},t[98]=de,t[99]=fe,t[100]=pe,t[101]=ae,t[102]=me,t[103]=ce,t[104]=H,t[105]=ue,t[106]=ge):ge=t[106],ge}function Dc(e){return{type:`skill`,data:e}}function Oc(e){return{type:`command`,data:e}}function kc(e){return console.error(`Failed to fetch files:`,e)}var Ac=768;function jc(){let e=(0,X.c)(2),[t,n]=Y.useState(Mc),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=window.matchMedia(`(max-width: ${Ac-1}px)`),t=()=>{n(window.innerWidth<Ac)};return e.addEventListener(`change`,t),n(window.innerWidth<Ac),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Y.useEffect(r,i),t}function Mc(){return typeof window>`u`?!1:window.innerWidth<Ac}function Nc(e){let t=(0,X.c)(22),{visible:n,commands:r,skills:i,query:a,selectedIndex:o,onSelectCommand:s,onSelectSkill:c,onMouseEnterSuggestion:l,containerRef:u}=e;if(!n)return null;let d;if(t[0]!==r||t[1]!==a||t[2]!==i){let e;t[4]===a?e=t[5]:(e=e=>e.name.toLowerCase().includes(a.toLowerCase()),t[4]=a,t[5]=e);let n=r.filter(e),o;t[6]===a?o=t[7]:(o=e=>e.name.toLowerCase().includes(a.toLowerCase()),t[6]=a,t[7]=o);let s=i.filter(o);d=[...n.map(Fc),...s.map(Pc)].slice(0,10),t[0]=r,t[1]=a,t[2]=i,t[3]=d}else d=t[3];let f=d,p,m;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(p=q(J.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),m=(0,$.jsx)(T,{className:`h-3 w-3`}),t[8]=p,t[9]=m):(p=t[8],m=t[9]);let h=a&&` matching "${a}"`,g;t[10]===h?g=t[11]:(g=(0,$.jsxs)(`div`,{className:p,children:[m,`Commands & Skills`,h]}),t[10]=h,t[11]=g);let _;t[12]!==f||t[13]!==l||t[14]!==s||t[15]!==c||t[16]!==o?(_=f.length>0?f.map((e,t)=>{let n=t===o;if(e.type===`command`){let r=e.data;return(0,$.jsxs)(`button`,{type:`button`,className:q(`flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors`,n?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>s(r),onMouseEnter:()=>l(t),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(T,{className:`h-3 w-3 text-muted-foreground`}),(0,$.jsxs)(`span`,{className:`font-medium`,children:[`/`,r.name]}),r.metadata.argumentHint&&(0,$.jsx)(`span`,{className:J.compact,children:r.metadata.argumentHint}),r.scope===`project`&&(0,$.jsx)(`span`,{className:q(J.compact,`ml-auto rounded-full bg-primary/10 px-1.5 py-0.5 text-primary`),children:`project`})]}),r.metadata.description&&(0,$.jsx)(`span`,{className:J.compact,children:r.metadata.description})]},`cmd-${r.name}`)}else{let r=e.data;return(0,$.jsxs)(`button`,{type:`button`,className:q(`flex w-full flex-col gap-1 rounded-lg px-3 py-2 text-left transition-colors`,n?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>c(r),onMouseEnter:()=>l(t),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(x,{className:`h-3 w-3 text-amber-500`}),(0,$.jsxs)(`span`,{className:`font-medium`,children:[`/`,r.name]}),(0,$.jsx)(`span`,{className:q(J.compact,`ml-auto rounded-full bg-amber-500/10 px-1.5 py-0.5 text-amber-700 dark:text-amber-400`),children:`skill`}),r.scope===`project`&&(0,$.jsx)(`span`,{className:q(J.compact,`rounded-full bg-primary/10 px-1.5 py-0.5 text-primary`),children:`project`})]}),(0,$.jsx)(`span`,{className:J.compact,children:r.description})]},`skill-${r.name}`)}}):(0,$.jsxs)(`div`,{className:q(J.compact,`px-3 py-4 text-center text-muted-foreground`),children:[`No commands or skills found.`,(0,$.jsx)(`br`,{}),(0,$.jsxs)(`span`,{className:J.compact,children:[`Create commands in `,(0,$.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`.agents/commands/`}),` or skills in `,(0,$.jsx)(`code`,{className:`bg-muted px-1 rounded`,children:`.agents/skills/`})]})]}),t[12]=f,t[13]=l,t[14]=s,t[15]=c,t[16]=o,t[17]=_):_=t[17];let v;return t[18]!==u||t[19]!==g||t[20]!==_?(v=(0,$.jsxs)(`div`,{ref:u,className:`absolute bottom-full left-0 mb-2 w-full max-h-64 overflow-y-auto rounded-xl border border-border bg-popover p-1 shadow-lg z-50 animate-in fade-in slide-in-from-bottom-2`,children:[g,_]}),t[18]=u,t[19]=g,t[20]=_,t[21]=v):v=t[21],v}function Pc(e){return{type:`skill`,data:e}}function Fc(e){return{type:`command`,data:e}}function Ic(e){return e.startsWith(`image/`)}function Lc(e){let t=(0,X.c)(7),{attachments:n,onRemove:r}=e;if(n.length===0)return null;let i;if(t[0]!==n||t[1]!==r){let e;t[3]===r?e=t[4]:(e=(e,t)=>(0,$.jsx)(`div`,{className:q(J.compact,`group relative flex items-center gap-1 rounded-md bg-muted text-muted-foreground`),children:Ic(e.mimeType)?(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.content}`,alt:e.fileName,className:`h-16 w-16 rounded-md object-cover`}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(t),className:`absolute -right-1.5 -top-1.5 flex h-4 w-4 items-center justify-center rounded-full bg-foreground text-background opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,$.jsx)(j,{className:`h-2.5 w-2.5`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]}):(0,$.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,$.jsx)(kt,{className:`h-3 w-3`}),e.fileName,(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(t),className:`ml-1 hover:text-foreground`,children:[(0,$.jsx)(j,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove attachment`})]})]})},t),t[3]=r,t[4]=e),i=n.map(e),t[0]=n,t[1]=r,t[2]=i}else i=t[2];let a;return t[5]===i?a=t[6]:(a=(0,$.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-1.5`,children:i}),t[5]=i,t[6]=a),a}function Rc(e,t){let n=e.target.files;if(!n||n.length===0)return;let r=Array.from(n),i=r.length,a=Array.from({length:i}),o=0;e.target.value=``,r.forEach((e,n)=>{let r=new FileReader;r.onload=()=>{let s=r.result.split(`,`)[1];a[n]={fileName:e.name,content:s,mimeType:e.type||`application/octet-stream`},o+=1,o===i&&t(a)},r.readAsDataURL(e)})}function zc(e){let t=(0,X.c)(17),{showSuggestions:n,fileSuggestions:r,suggestionQuery:i,selectedIndex:a,onSelectFile:o,onMouseEnterSuggestion:s,containerRef:c}=e;if(!n||r.length===0)return null;let l,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=q(J.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),u=(0,$.jsx)(Yt,{className:`h-3 w-3`}),t[0]=l,t[1]=u):(l=t[0],u=t[1]);let d;t[2]===i?d=t[3]:(d=(0,$.jsxs)(`div`,{className:l,children:[u,`Files matching "`,i,`"`]}),t[2]=i,t[3]=d);let f;if(t[4]!==r||t[5]!==s||t[6]!==o||t[7]!==a){let e;t[9]!==s||t[10]!==o||t[11]!==a?(e=(e,t)=>{let n=e.split(`/`).pop()??e,r=t===a;return(0,$.jsxs)(`button`,{type:`button`,className:q(J.body,`flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left transition-colors`,r?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>o(e),onMouseEnter:()=>s(t),children:[e.endsWith(`.ts`)||e.endsWith(`.tsx`)||e.endsWith(`.js`)||e.endsWith(`.jsx`)?(0,$.jsx)(w,{className:`h-4 w-4 text-blue-500`}):(0,$.jsx)(Me,{className:`h-4 w-4 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`flex flex-col overflow-hidden`,children:[(0,$.jsx)(`span`,{className:`truncate font-medium`,children:n}),(0,$.jsx)(`span`,{className:q(J.compact,`truncate text-muted-foreground opacity-70`),children:e})]})]},e)},t[9]=s,t[10]=o,t[11]=a,t[12]=e):e=t[12],f=r.map(e),t[4]=r,t[5]=s,t[6]=o,t[7]=a,t[8]=f}else f=t[8];let p;return t[13]!==c||t[14]!==d||t[15]!==f?(p=(0,$.jsxs)(`div`,{ref:c,className:`absolute bottom-full left-0 mb-2 w-full max-h-64 overflow-y-auto rounded-xl border border-border bg-popover p-1 shadow-lg z-50 animate-in fade-in slide-in-from-bottom-2`,children:[d,f]}),t[13]=c,t[14]=d,t[15]=f,t[16]=p):p=t[16],p}function Bc(e){let t=(0,X.c)(5),{providerSlug:n}=e;if(!n)return null;let r;t[0]===n?r=t[1]:(r=bn(n),t[0]=n,t[1]=r);let i=`${n} logo`,a;return t[2]!==r||t[3]!==i?(a=(0,$.jsx)(`img`,{src:r,alt:i,className:`h-3.5 w-3.5 flex-shrink-0 dark:invert`,onError:Vc}),t[2]=r,t[3]=i,t[4]=a):a=t[4],a}function Vc(e){e.currentTarget.style.visibility=`hidden`}function Hc(e){let t=(0,X.c)(9),{providerSlug:n,providerData:r}=e,i=r?.name??n,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=q(J.dropdownGroupHeading,`flex items-center gap-1.5 px-3 py-1.5 uppercase tracking-wide`),t[0]=a):a=t[0];let o;t[1]===n?o=t[2]:(o=(0,$.jsx)(Bc,{providerSlug:n}),t[1]=n,t[2]=o);let s;t[3]!==i||t[4]!==r?(s=r?.url?(0,$.jsx)(gr,{url:r.url,showIcon:!1,variant:`inline`,children:i}):i,t[3]=i,t[4]=r,t[5]=s):s=t[5];let c;return t[6]!==o||t[7]!==s?(c=(0,$.jsxs)(`div`,{className:a,children:[o,s]}),t[6]=o,t[7]=s,t[8]=c):c=t[8],c}function Uc(e){let t=e.pricing?.prompt;return t==null?null:Math.ceil(t*3)}function Wc(e){return`$${et(e)}`}function Gc(e,t){return e.pricing?(0,$.jsxs)(`div`,{className:`max-w-64 whitespace-normal break-words text-left leading-relaxed`,children:[(0,$.jsx)(`div`,{children:`${Wc(e.pricing.prompt??0)} input per million tokens`}),(0,$.jsx)(`div`,{children:`${Wc(e.pricing.completion??0)} output per million tokens`}),(0,$.jsx)(`div`,{children:`Displayed value of ${t} is a relative price.`})]}):null}function Kc(e,t){return[...e].sort((e,n)=>{let r=(e.provider??`Other`).localeCompare(n.provider??`Other`);if(r!==0)return r;if(t===`relative-price`){let t=(Uc(e)??2**53-1)-(Uc(n)??2**53-1);if(t!==0)return t}return _r(e.id).localeCompare(_r(n.id))})}function qc(e){let t=(0,X.c)(37),{availableModels:n,selectedModel:r,onModelSelect:i}=e,[a,o]=Y.useState(!1),[s,c]=Y.useState(`relative-price`),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=new Map,t[0]=l):l=t[0];let[u,d]=Y.useState(l),f=Y.useRef(null),p,m;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(p=()=>{Ee().then(function(e){d(new Map(e.map(Yc)))})},m=[],t[1]=p,t[2]=m):(p=t[1],m=t[2]),Y.useEffect(p,m);let h,g;t[3]===a?(h=t[4],g=t[5]):(h=()=>{let e=e=>{f.current&&!f.current.contains(e.target)&&o(!1)};if(a)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},g=[a],t[3]=a,t[4]=h,t[5]=g),Y.useEffect(h,g);let _;t[6]===i?_=t[7]:(_=e=>{i(e),o(!1)},t[6]=i,t[7]=_);let v=_,y;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(y=()=>{c(function(e){return e===`relative-price`?`alphabetical`:`relative-price`})},t[8]=y):y=t[8];let b=y,x;t[9]!==n||t[10]!==s?(x=Kc(n,s),t[9]=n,t[10]=s,t[11]=x):x=t[11];let S=x,C=s===`relative-price`?Mt:hn,w=s===`relative-price`?`Sort by relative price`:`Sort alphabetically`,T;t[12]===a?T=t[13]:(T=()=>o(!a),t[12]=a,t[13]=T);let E=r?.provider,D;t[14]===E?D=t[15]:(D=(0,$.jsx)(Bc,{providerSlug:E}),t[14]=E,t[15]=D);let O;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(O=q(J.body,`font-normal`),t[16]=O):O=t[16];let k;t[17]===r?k=t[18]:(k=r?_r(r.id):`No model`,t[17]=r,t[18]=k);let A;t[19]===k?A=t[20]:(A=(0,$.jsx)(`span`,{className:O,children:k}),t[19]=k,t[20]=A);let j;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsx)(Rt,{className:`h-3 w-3`}),t[21]=j):j=t[21];let M;t[22]!==D||t[23]!==A||t[24]!==T?(M=(0,$.jsxs)(U,{variant:`action`,size:`icon-sm`,className:`gap-1 w-auto px-2`,onClick:T,children:[D,A,j]}),t[22]=D,t[23]=A,t[24]=T,t[25]=M):M=t[25];let N;t[26]!==C||t[27]!==v||t[28]!==u||t[29]!==r?.id||t[30]!==a||t[31]!==w||t[32]!==S?(N=a&&(0,$.jsx)(`div`,{className:`absolute bottom-full left-0 mb-1 w-80 max-h-80 overflow-y-auto rounded-lg border border-border bg-popover p-1 shadow-md z-50`,children:(0,$.jsxs)(Nt,{children:[(0,$.jsx)(`div`,{className:`-mb-3 flex justify-end px-1 pb-1`,children:(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":w,className:`rounded-md p-1 text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground`,onClick:b,children:(0,$.jsx)(C,{className:`h-3.5 w-3.5`})})}),(0,$.jsx)(K,{side:`left`,align:`start`,sideOffset:8,children:w})]})}),Object.entries(S.reduce(Jc,{})).map((e,t)=>{let[n,i]=e;return(0,$.jsxs)(`div`,{children:[t>0&&(0,$.jsx)(hr,{className:`my-1`}),(0,$.jsx)(Hc,{providerSlug:n,providerData:u.get(n)}),i.map(e=>{let t=Uc(e),n=t==null?null:Gc(e,t);return(0,$.jsx)(`div`,{children:(0,$.jsx)(`div`,{children:(0,$.jsxs)(`button`,{type:`button`,className:q(J.body,`flex w-full items-center justify-between gap-3 whitespace-nowrap rounded-md px-3 py-1.5 pl-8 text-popover-foreground hover:bg-accent`,e.id===r?.id&&`bg-accent font-medium`),onClick:()=>v(e),children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:_r(e.id)}),t!=null&&n&&(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:t})}),(0,$.jsx)(K,{side:`left`,align:`end`,sideOffset:8,className:`max-w-64`,children:n})]})]})})},e.id)})]},n)})]})}),t[26]=C,t[27]=v,t[28]=u,t[29]=r?.id,t[30]=a,t[31]=w,t[32]=S,t[33]=N):N=t[33];let P;return t[34]!==M||t[35]!==N?(P=(0,$.jsxs)(`div`,{className:`relative`,ref:f,children:[M,N]}),t[34]=M,t[35]=N,t[36]=P):P=t[36],P}function Jc(e,t){let n=t.provider??`Other`;return e[n]||(e[n]=[]),e[n].push(t),e}function Yc(e){return[e.slug,e]}var Xc=[{value:`build`,label:`Build`,icon:ee},{value:`plan`,label:`Plan`,icon:ae},{value:`image`,label:`Image`,icon:a},{value:`ralph`,label:`Ralph`,icon:Ze}];function Zc(e,t,n){return n?`ralph`:e?`plan`:t?`image`:`build`}function Qc({planMode:e,imageMode:t,ralphMode:n,setPlanMode:r,setImageMode:i,setRalphMode:a,projectId:o}){let s=yi(),c=Q(function(e){if(o)return e.projects.find(e=>e.projectId===o)}),[l,u]=Y.useState(!0),[d,f]=Y.useState(!1),p=Zc(e,t,n),m=Xc.find(e=>e.value===p);Y.useEffect(()=>{c&&u(c.allowAllCommands===!1)},[c]);async function h(){if(!o||d)return;let e=!l;u(e),f(!0);try{await vn(o,{allowAllCommands:!e}),F(o);let t=await Se();s({type:Z.SetProjects,projects:t.projects})}catch(t){u(!e),console.error(`Failed to update command confirmation setting:`,t)}finally{f(!1)}}function g(e){r(e===`plan`),i(e===`image`),a(e===`ralph`)}return{chatModes:Xc,confirmCommands:l,currentConfig:m,currentMode:p,isUpdatingConfirmCommands:d,selectMode:g,toggleConfirmCommands:h}}function $c(e){let t=(0,X.c)(37),{planMode:n,imageMode:r,ralphMode:i,setPlanMode:a,setImageMode:o,setRalphMode:s,projectId:c}=e,[l,u]=Y.useState(!1),d=Y.useRef(null),f;t[0]!==r||t[1]!==n||t[2]!==c||t[3]!==i||t[4]!==o||t[5]!==a||t[6]!==s?(f={planMode:n,imageMode:r,ralphMode:i,setPlanMode:a,setImageMode:o,setRalphMode:s,projectId:c},t[0]=r,t[1]=n,t[2]=c,t[3]=i,t[4]=o,t[5]=a,t[6]=s,t[7]=f):f=t[7];let{chatModes:p,confirmCommands:m,currentConfig:h,currentMode:g,isUpdatingConfirmCommands:_,selectMode:v,toggleConfirmCommands:y}=Qc(f),b=h.icon,x,S;t[8]===l?(x=t[9],S=t[10]):(x=()=>{let e=function(e){d.current&&!d.current.contains(e.target)&&u(!1)};if(l)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},S=[l],t[8]=l,t[9]=x,t[10]=S),Y.useEffect(x,S);let C;t[11]===v?C=t[12]:(C=function(e){v(e),u(!1)},t[11]=v,t[12]=C);let w=C,T;t[13]===l?T=t[14]:(T=()=>u(!l),t[13]=l,t[14]=T);let E;t[15]===b?E=t[16]:(E=(0,$.jsx)(b,{className:`h-3.5 w-3.5`}),t[15]=b,t[16]=E);let D;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(D=q(J.body,`font-normal`),t[17]=D):D=t[17];let O;t[18]===h.label?O=t[19]:(O=(0,$.jsx)(`span`,{className:D,children:h.label}),t[18]=h.label,t[19]=O);let k;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(Rt,{className:`h-3 w-3`}),t[20]=k):k=t[20];let A;t[21]!==T||t[22]!==E||t[23]!==O?(A=(0,$.jsxs)(U,{variant:`action`,size:`icon-sm`,className:`gap-1 w-auto px-2`,onClick:T,children:[E,O,k]}),t[21]=T,t[22]=E,t[23]=O,t[24]=A):A=t[24];let j;t[25]!==p||t[26]!==m||t[27]!==g||t[28]!==w||t[29]!==_||t[30]!==l||t[31]!==c||t[32]!==y?(j=l&&(0,$.jsxs)(`div`,{className:`absolute bottom-full right-0 z-50 mb-1 w-56 rounded-lg border border-border bg-popover p-1 shadow-md`,children:[c&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,className:q(J.body,`flex w-full items-center gap-2 rounded-md px-3 py-2 text-popover-foreground hover:bg-accent disabled:opacity-50`),onClick:()=>{y()},disabled:_,children:[`Confirm Commands`,m&&(0,$.jsx)(ln,{className:`ml-auto h-3.5 w-3.5`})]}),(0,$.jsx)(`div`,{className:`my-1 h-px bg-border`})]}),p.map(e=>{let t=e.icon,n=e.value===g;return(0,$.jsxs)(`button`,{type:`button`,className:q(J.body,`flex w-full items-center gap-2 rounded-md px-3 py-2 text-popover-foreground hover:bg-accent`),onClick:()=>w(e.value),children:[(0,$.jsx)(t,{className:`h-3.5 w-3.5`}),e.label,n&&(0,$.jsx)(ln,{className:`ml-auto h-3.5 w-3.5`})]},e.value)})]}),t[25]=p,t[26]=m,t[27]=g,t[28]=w,t[29]=_,t[30]=l,t[31]=c,t[32]=y,t[33]=j):j=t[33];let M;return t[34]!==A||t[35]!==j?(M=(0,$.jsxs)(`div`,{className:`relative hidden md:block`,ref:d,children:[A,j]}),t[34]=A,t[35]=j,t[36]=M):M=t[36],M}function el(e){let t=(0,X.c)(32),{disabled:n,canAddTask:r,onFileAttach:i,onAddTask:a,showModes:o,planMode:s,imageMode:c,ralphMode:l,setPlanMode:u,setImageMode:d,setRalphMode:f,projectId:m}=e,h=n===void 0?!1:n,g=o===void 0?!1:o,_=s===void 0?!1:s,v=c===void 0?!1:c,y=l===void 0?!1:l,b=u??rl,x=d??nl,S=f??tl,C;t[0]!==v||t[1]!==_||t[2]!==m||t[3]!==y||t[4]!==b||t[5]!==x||t[6]!==S?(C={planMode:_,imageMode:v,ralphMode:y,setPlanMode:b,setImageMode:x,setRalphMode:S,projectId:m},t[0]=v,t[1]=_,t[2]=m,t[3]=y,t[4]=b,t[5]=x,t[6]=S,t[7]=C):C=t[7];let w=Qc(C),T;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(T=function(e){e()},t[8]=T):T=t[8];let E=T,D,O;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(sn,{}),O=(0,$.jsx)(`span`,{className:`sr-only`,children:`More options`}),t[9]=D,t[10]=O):(D=t[9],O=t[10]);let k;t[11]===h?k=t[12]:(k=(0,$.jsx)(us,{asChild:!0,children:(0,$.jsxs)(U,{variant:`action`,size:`icon-sm`,disabled:h,children:[D,O]})}),t[11]=h,t[12]=k);let A;t[13]===i?A=t[14]:(A=()=>E(i),t[13]=i,t[14]=A);let j;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsx)(kt,{className:`mr-2 h-3.5 w-3.5`}),t[15]=j):j=t[15];let M;t[16]===A?M=t[17]:(M=(0,$.jsxs)(hs,{onClick:A,children:[j,`Attach File`]}),t[16]=A,t[17]=M);let N;t[18]!==r||t[19]!==a?(N=r&&(0,$.jsxs)(hs,{onClick:()=>E(a),children:[(0,$.jsx)(p,{className:`mr-2 h-3.5 w-3.5`}),`Add to Pending Tasks`]}),t[18]=r,t[19]=a,t[20]=N):N=t[20];let P;t[21]!==w||t[22]!==m||t[23]!==g?(P=g&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ys,{}),m&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(hs,{onClick:()=>{w.toggleConfirmCommands()},disabled:w.isUpdatingConfirmCommands,children:[`Confirm Commands`,w.confirmCommands&&(0,$.jsx)(ln,{className:`ml-auto h-3.5 w-3.5`})]}),(0,$.jsx)(ys,{})]}),w.chatModes.map(e=>{let t=e.icon,n=e.value===w.currentMode;return(0,$.jsxs)(hs,{onClick:()=>w.selectMode(e.value),className:q(n&&`bg-accent`),children:[(0,$.jsx)(t,{className:`mr-2 h-3.5 w-3.5`}),e.label,n&&(0,$.jsx)(ln,{className:`ml-auto h-3.5 w-3.5`})]},e.value)})]}),t[21]=w,t[22]=m,t[23]=g,t[24]=P):P=t[24];let F;t[25]!==M||t[26]!==N||t[27]!==P?(F=(0,$.jsxs)(ms,{align:`start`,side:`top`,className:`w-56`,children:[M,N,P]}),t[25]=M,t[26]=N,t[27]=P,t[28]=F):F=t[28];let I;return t[29]!==k||t[30]!==F?(I=(0,$.jsxs)(ls,{children:[k,F]}),t[29]=k,t[30]=F,t[31]=I):I=t[31],I}function tl(){}function nl(){}function rl(){}var il=Pr(`useWebSpeech`);function al(e){switch(e){case`not-allowed`:return`Microphone access was denied. Please allow microphone access to use voice input.`;case`service-not-allowed`:return`Speech recognition is not allowed in this environment.`;case`audio-capture`:return`No microphone was found. Please connect a microphone to use voice input.`;case`network`:return`Speech recognition requires a network connection.`;case`no-speech`:case`aborted`:return null;default:return`Speech recognition error: ${e}`}}function ol(e){let t=``;for(let n=0;n<e.results.length;n+=1)t+=e.results[n][0]?.transcript??``;return t}function sl(){let[e,t]=(0,Y.useState)(`idle`),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(``),[o,s]=(0,Y.useState)(null),c=(0,Y.useRef)(null),l=(0,Y.useRef)(!1);(0,Y.useEffect)(()=>()=>{l.current=!1,c.current?.abort(),c.current=null},[]);let u=(0,Y.useCallback)(()=>{let e=Nr();if(!e){l.current=!1,t(`error`),r(!1),s(`Speech recognition is not supported in this environment.`);return}e.continuous=!0,e.interimResults=!0,e.lang=`en-US`,e.onresult=e=>{let t=ol(e).trim();t&&a(t)},e.onerror=e=>{let t=al(e.error);il.error(`Web Speech recognition error`,{error:e.error,message:e.message}),t&&s(t)},e.onend=()=>{if(c.current=null,!l.current){t(`ready`);return}il.info(`Web Speech recognition ended — restarting`),u()},c.current=e;try{e.start(),t(`recording`),il.info(`Web Speech recognition started`)}catch(e){c.current=null,l.current=!1;let n=e instanceof Error?e.message:`Unknown error`;il.error(`Failed to start Web Speech recognition`,{error:n}),t(`ready`),s(`Failed to start speech recognition: ${n}`)}},[]),d=(0,Y.useCallback)(async()=>{if(e===`ready`||e===`error`)return e;t(`checking-support`),s(null),il.info(`Checking Web Speech API support`,{userAgent:navigator.userAgent,platform:navigator.platform});let n=Ir();return r(n),n?(il.info(`Web Speech API available — ready`),t(`ready`),`ready`):(il.error(`Web Speech API not available`),t(`error`),s(`Speech recognition is not supported in this environment.`),`error`)},[e]);return{state:e,isSupported:n,transcript:i,error:o,downloadProgress:0,startListening:(0,Y.useCallback)(async()=>{l.current=!0,s(null),a(``),il.info(`Starting Web Speech recognition`),u()},[u]),stopListening:(0,Y.useCallback)(async()=>{l.current=!1,c.current?.stop(),c.current=null,t(`ready`),il.info(`Web Speech recognition stopped`)},[]),requestModelDownload:(0,Y.useCallback)(async()=>{},[]),ensureReady:d,resetTranscript:(0,Y.useCallback)(()=>{a(``),s(null)},[])}}var cl=Pr(`useWhisperSpeech`),ll=150;function ul(e){let t=new URLSearchParams;return t.set(`model`,e),`/api/voice-model/download?${t.toString()}`}function dl(){if(typeof SharedArrayBuffer>`u`)return 1;let e=navigator.hardwareConcurrency;return!e||e<=2?1:e<=4?2:Math.min(4,e-2)}function fl(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now()}function pl(){let[e,t]=(0,Y.useState)(`idle`),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(0),[m,h]=(0,Y.useState)(()=>Qt()),g=(0,Y.useRef)(null),_=(0,Y.useRef)(null),v=(0,Y.useRef)(null),y=(0,Y.useRef)(null),b=(0,Y.useRef)(null),x=(0,Y.useRef)(!1),S=(0,Y.useRef)(null),C=(0,Y.useRef)(null),w=(0,Y.useRef)(!1),T=(0,Y.useCallback)(e=>{w.current=e,a(e)},[]);(0,Y.useEffect)(()=>{if(typeof window>`u`)return;function e(e){e.key===`tarsk.general.voiceModel`&&h(Qt())}function t(){h(Qt())}return window.addEventListener(`storage`,e),window.addEventListener(`tarsk:voice-model-changed`,t),()=>{window.removeEventListener(`storage`,e),window.removeEventListener(`tarsk:voice-model-changed`,t)}},[]),(0,Y.useEffect)(()=>{g.current=null,_.current=null,C.current=null,T(!1),p(0),d(null),t(`idle`)},[m,T]),(0,Y.useEffect)(()=>()=>{S.current!==null&&window.clearTimeout(S.current),v.current&&v.current.getTracks().forEach(e=>e.stop())},[]);let E=(0,Y.useCallback)(async()=>{if(e===`ready`||e===`needs-model`||e===`error`)return e;if(C.current)return C.current;let n=ul(m);async function i(){t(`checking-support`),T(!1),p(0),d(null),cl.separator(`VOICE SESSION START`),cl.info(`Checking WASM support`,{userAgent:navigator.userAgent,platform:navigator.platform,model:m,url:n});try{let e=new Lr;g.current=e;let i=await e.checkWasmSupport();if(cl.info(`WASM SIMD support check result`,{supported:i}),r(i),!i)return cl.error(`WASM SIMD not supported — voice input disabled`),t(`error`),d(`WebAssembly SIMD is not supported in this environment.`),`error`;let a=new Fr;_.current=a,cl.info(`Checking IndexedDB model cache`,{url:n});try{let r=await a.loadModelByUrl(n);return cl.info(`Cached model found — initializing WASM`,{sizeBytes:r.byteLength,sizeMB:(r.byteLength/1024/1024).toFixed(2),model:m}),T(!0),t(`initializing`),await e.initModel(r),cl.info(`WASM model initialized from cache — ready`),t(`ready`),`ready`}catch(e){return cl.info(`Model not in cache — download required`,{reason:e instanceof Error?e.message:String(e),model:m}),t(`needs-model`),`needs-model`}}catch(e){let n=e instanceof Error?e.message:`Unknown error`;return cl.error(`Failed to check speech recognition support`,{error:n}),t(`error`),d(`Failed to check speech recognition support: ${n}`),`error`}}let a=i();C.current=a;try{return await a}finally{C.current=null}},[e,m,T]),D=(0,Y.useCallback)(async()=>{if(!g.current||!_.current)return;let e=ul(m);t(`downloading-model`),p(0),d(null),cl.info(`Model download requested`,{url:e,model:m});try{let n=await _.current.loadModelByUrl(e,e=>{p(e),e%10==0&&cl.debug(`Model download progress`,{progress:e,model:m})});cl.info(`Model download complete — initializing WASM`,{sizeBytes:n.byteLength,sizeMB:(n.byteLength/1024/1024).toFixed(2),model:m}),t(`initializing`),await g.current.initModel(n),cl.info(`WASM model initialized after download — ready`),T(!0),t(`ready`)}catch(e){let n=e instanceof Error?e.message:`An unknown error occurred.`;cl.error(`Model download or initialization failed`,{error:n,model:m}),t(`needs-model`),d(n)}},[m,T]),O=(0,Y.useCallback)(async()=>{if(!(!g.current||!w.current)){if(x.current=!1,t(`requesting-mic`),d(null),l(``),cl.separator(`RECORDING START`),cl.info(`Requesting microphone access`),!navigator.mediaDevices?.getUserMedia){cl.error(`navigator.mediaDevices.getUserMedia not available in this environment`),t(`ready`),s(!1),d(`Microphone is not available in this environment.`);return}try{let e=fl(),n=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0}}),r=n.getAudioTracks();cl.info(`Microphone access granted`,{durationMs:Math.round(fl()-e),trackCount:r.length,tracks:r.map(e=>({label:e.label,readyState:e.readyState,settings:e.getSettings()}))}),v.current=n,s(!0);let i=new AbortController;y.current=i,t(`recording`),cl.info(`Recording started`),b.current=Rr(n,{signal:i.signal,recordingDurationMs:12e4,logLevel:0},{onError:e=>{cl.error(`Audio conversion error during recording`,{error:e instanceof Error?e.message:String(e)})}})}catch(e){if(t(`ready`),e instanceof DOMException&&e.name===`NotAllowedError`)cl.error(`Microphone access denied (NotAllowedError)`),s(!1),d(`Microphone access was denied. Please allow microphone access to use voice input.`);else if(e instanceof DOMException&&e.name===`NotFoundError`)cl.error(`No microphone found (NotFoundError)`),s(!1),d(`No microphone was found. Please connect a microphone to use voice input.`);else{let t=e instanceof Error?e.message:`Unknown error`;cl.error(`Microphone error`,{error:t,type:e instanceof DOMException?e.name:typeof e}),d(`Microphone error: ${t}`)}}}},[]),k=(0,Y.useCallback)(async()=>{if(!b.current){cl.info(`stopListening called but no active recording`),v.current&&=(v.current.getTracks().forEach(e=>e.stop()),null),w.current&&t(`ready`);return}cl.info(`Stopping recording — waiting for audio data`);let e=fl();y.current?.abort(),t(`transcribing`);try{let n=fl(),r=await b.current;if(x.current){cl.info(`Transcription cancelled by user`),t(`ready`);return}let i=(r.audioData.length/16e3).toFixed(2),a=Math.round(fl()-n);cl.info(`Audio capture complete — starting transcription`,{sampleCount:r.audioData.length,durationSec:i,sampleRate:16e3,conversionDurationMs:a,stopToConversionReadyMs:Math.round(fl()-e)}),v.current&&=(v.current.getTracks().forEach(e=>e.stop()),null);let o=fl(),s=dl(),c=g.current.createSession(),u=``,d=``,f=null;function p(e=!1){if(!d)return;let t=d.trim();if(e){S.current!==null&&(window.clearTimeout(S.current),S.current=null),d=``,l(t);return}S.current===null&&(S.current=window.setTimeout(()=>{S.current=null;let e=d.trim();d=``,e&&l(e)},ll))}let m=c.streaming(r.audioData,{language:`en`,threads:s,translate:!1}),h=``,_=0;for await(let e of m){if(x.current)break;_++,f===null&&(f=Math.round(fl()-o)),u+=e.text.trim()+` `,h=u,d=h,cl.debug(`Transcription segment received`,{index:_,text:e.text,timeStart:e.timeStart,timeEnd:e.timeEnd}),p()}p(!0),cl.info(`Transcription complete`,{segmentCount:_,durationMs:Math.round(fl()-o),timeToFirstSegmentMs:f,threadCount:s,totalStopToReadyMs:Math.round(fl()-e),textLength:h.trim().length,text:h.trim().slice(0,100)}),t(`ready`)}catch(e){if(x.current){t(`ready`);return}let n=e instanceof Error?e.message:`Unknown transcription error`;if(cl.error(`Transcription failed`,{error:n,errorType:e instanceof Error?e.constructor.name:typeof e,stack:e instanceof Error?e.stack?.split(`
30
- `).slice(0,5).join(` | `):void 0}),g.current&&n.includes(`Aborted`)){cl.info(`WASM aborted — reinitializing model for next attempt`),t(`initializing`);try{await g.current.restartModel(),cl.info(`WASM reinitialized successfully`)}catch(e){cl.error(`WASM reinitialization failed`,{error:e instanceof Error?e.message:String(e)})}}t(`ready`),d(`Transcription failed: ${n}`)}finally{S.current!==null&&(window.clearTimeout(S.current),S.current=null),b.current=null,y.current=null}},[]),A=(0,Y.useCallback)(()=>{l(``),d(null)},[]);return{state:e,isSupported:n===!0,isWasmSupported:n,isModelLoaded:i,isMicrophoneAvailable:o,transcript:c,error:u,downloadProgress:f,startListening:O,stopListening:k,requestModelDownload:D,ensureReady:E,resetTranscript:A}}function ml(){let e=(0,X.c)(22),t=pl(),n=sl();if(!E()){let n;return e[0]!==t.downloadProgress||e[1]!==t.ensureReady||e[2]!==t.error||e[3]!==t.isWasmSupported||e[4]!==t.requestModelDownload||e[5]!==t.resetTranscript||e[6]!==t.startListening||e[7]!==t.state||e[8]!==t.stopListening||e[9]!==t.transcript?(n={state:t.state,isSupported:t.isWasmSupported,usesLocalModel:!0,transcript:t.transcript,error:t.error,downloadProgress:t.downloadProgress,startListening:t.startListening,stopListening:t.stopListening,requestModelDownload:t.requestModelDownload,ensureReady:t.ensureReady,resetTranscript:t.resetTranscript},e[0]=t.downloadProgress,e[1]=t.ensureReady,e[2]=t.error,e[3]=t.isWasmSupported,e[4]=t.requestModelDownload,e[5]=t.resetTranscript,e[6]=t.startListening,e[7]=t.state,e[8]=t.stopListening,e[9]=t.transcript,e[10]=n):n=e[10],n}let r;return e[11]!==n.downloadProgress||e[12]!==n.ensureReady||e[13]!==n.error||e[14]!==n.isSupported||e[15]!==n.requestModelDownload||e[16]!==n.resetTranscript||e[17]!==n.startListening||e[18]!==n.state||e[19]!==n.stopListening||e[20]!==n.transcript?(r={state:n.state,isSupported:n.isSupported,usesLocalModel:!1,transcript:n.transcript,error:n.error,downloadProgress:n.downloadProgress,startListening:n.startListening,stopListening:n.stopListening,requestModelDownload:n.requestModelDownload,ensureReady:n.ensureReady,resetTranscript:n.resetTranscript},e[11]=n.downloadProgress,e[12]=n.ensureReady,e[13]=n.error,e[14]=n.isSupported,e[15]=n.requestModelDownload,e[16]=n.resetTranscript,e[17]=n.startListening,e[18]=n.state,e[19]=n.stopListening,e[20]=n.transcript,e[21]=r):r=e[21],r}var hl=Y.forwardRef((e,t)=>{let n=(0,X.c)(13),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,value:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]===r?o=n[5]:(o=q(`relative h-4 w-full overflow-hidden rounded-full bg-secondary`,r),n[4]=r,n[5]=o);let s=`translateX(-${100-(a||0)}%)`,c;n[6]===s?c=n[7]:(c=(0,$.jsx)(Wn,{className:`h-full w-full flex-1 bg-primary transition-all`,style:{transform:s}}),n[6]=s,n[7]=c);let l;return n[8]!==i||n[9]!==t||n[10]!==o||n[11]!==c?(l=(0,$.jsx)(fr,{ref:t,className:o,...i,children:c}),n[8]=i,n[9]=t,n[10]=o,n[11]=c,n[12]=l):l=n[12],l});hl.displayName=fr.displayName;var gl=75;function _l(e){let t=(0,X.c)(11),{open:n,onOpenChange:r,onConfirm:i,downloading:a,progress:o,error:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsxs)(xt,{children:[(0,$.jsx)(z,{children:`Download Voice Model`}),(0,$.jsxs)(Ct,{children:[`To enable voice-to-text, a voice model needs to be downloaded. This is a one-time download of approximately `,gl,`MB. The model will be cached locally for future use.`]})]}),t[0]=l):l=t[0];let u;t[1]!==a||t[2]!==c||t[3]!==i||t[4]!==r||t[5]!==o?(u=(0,$.jsxs)(H,{children:[l,a?(0,$.jsxs)(`div`,{className:`space-y-3 py-4`,children:[(0,$.jsx)(hl,{value:o,className:`w-full`}),(0,$.jsx)(`p`,{className:q(J.bodyMuted,`text-center`),children:o<100?`Downloading model... ${o}%`:`Initializing model...`})]}):c?(0,$.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,$.jsx)(Mr,{variant:`error`,className:`mb-0`,children:c}),(0,$.jsxs)(s,{children:[(0,$.jsx)(U,{variant:`outline`,onClick:()=>r(!1),children:`Cancel`}),(0,$.jsx)(U,{onClick:i,children:`Try Again`})]})]}):(0,$.jsxs)(s,{children:[(0,$.jsx)(U,{variant:`outline`,onClick:()=>r(!1),children:`Cancel`}),(0,$.jsx)(U,{onClick:i,children:`Download Model`})]})]}),t[1]=a,t[2]=c,t[3]=i,t[4]=r,t[5]=o,t[6]=u):u=t[6];let d;return t[7]!==r||t[8]!==n||t[9]!==u?(d=(0,$.jsx)(g,{open:n,onOpenChange:r,children:u}),t[7]=r,t[8]=n,t[9]=u,t[10]=d):d=t[10],d}var vl=Cr(e=>(0,$.jsxs)(`slot`,{children:[(0,$.jsx)(`style`,{children:`
31
- .recording-waveform {
32
- display: flex;
33
- align-items: center;
34
- gap: 2px;
35
- height: 16px;
36
- }
37
- .recording-waveform-bar {
38
- display: block;
39
- width: 3px;
40
- height: 4px;
41
- border-radius: 2px;
42
- background: currentColor;
43
- animation: waveform-bounce 0.7s ease-in-out infinite alternate;
44
- }
45
- @keyframes waveform-bounce {
46
- from { height: 3px; }
47
- to { height: 14px; }
48
- }
49
- `}),e.v0,e.v1]}),{name:`SpeechInput_1`,portals:[`v0`,`v1`]}),yl=function(e){let t=(0,X.c)(67),{onTranscript:n,children:r}=e,{state:i,isSupported:a,usesLocalModel:o,transcript:s,error:c,downloadProgress:l,startListening:u,stopListening:d,requestModelDownload:f,ensureReady:p,resetTranscript:m}=ml(),{toast:h}=Li(),[g,v]=(0,Y.useState)(!1),y=(0,Y.useRef)(``),b=(0,Y.useRef)(null),x=i===`recording`,S=i===`transcribing`,C=x||S,w=i===`needs-model`,T=i===`downloading-model`||i===`initializing`,E=i===`checking-support`,D,O;t[0]!==g||t[1]!==c||t[2]!==h?(D=()=>{c&&c!==b.current&&!g&&h({title:`Voice Input Error`,description:c,variant:`destructive`}),b.current=c},O=[c,g,h],t[0]=g,t[1]=c,t[2]=h,t[3]=D,t[4]=O):(D=t[3],O=t[4]),(0,Y.useEffect)(D,O);let k,A;t[5]!==n||t[6]!==s?(k=()=>{if(s&&s!==y.current){let e=s.substring(y.current.length);y.current=s,n(e)}},A=[s,n],t[5]=n,t[6]=s,t[7]=k,t[8]=A):(k=t[7],A=t[8]),(0,Y.useEffect)(k,A);let j,M;t[9]===s?(j=t[10],M=t[11]):(j=()=>{s||(y.current=``)},M=[s],t[9]=s,t[10]=j,t[11]=M),(0,Y.useEffect)(j,M);let N;t[12]!==p||t[13]!==C||t[14]!==w||t[15]!==m||t[16]!==u||t[17]!==i||t[18]!==d?(N=async()=>{if(C){d();return}if(w){v(!0);return}if(i===`ready`){m(),u();return}if(i===`idle`){let e=await p();e===`needs-model`?v(!0):e===`ready`&&(m(),u())}},t[12]=p,t[13]=C,t[14]=w,t[15]=m,t[16]=u,t[17]=i,t[18]=d,t[19]=N):N=t[19];let P=N,F;t[20]===f?F=t[21]:(F=()=>{f()},t[20]=f,t[21]=F);let I=F,L,R;t[22]!==g||t[23]!==i?(R=()=>{i===`ready`&&g&&v(!1)},L=[i,g],t[22]=g,t[23]=i,t[24]=L,t[25]=R):(L=t[24],R=t[25]),(0,Y.useEffect)(R,L);let ee;t[26]!==c||t[27]!==E||t[28]!==T||t[29]!==x||t[30]!==a||t[31]!==S||t[32]!==w?(ee=()=>E?`Checking voice input support...`:a===!1?`Voice input not supported in this browser`:c||(T?`Downloading speech model...`:S?`Transcribing...`:x?`Stop listening`:w?`Click to download speech model`:`Start listening`),t[26]=c,t[27]=E,t[28]=T,t[29]=x,t[30]=a,t[31]=S,t[32]=w,t[33]=ee):ee=t[33];let te=ee,z;t[34]!==T||t[35]!==x||t[36]!==S?(z=()=>T||S?(0,$.jsx)(_,{className:`h-3 w-3 animate-spin`}):x?(0,$.jsxs)(`span`,{className:`recording-waveform`,"aria-hidden":!0,children:[(0,$.jsx)(`span`,{className:`recording-waveform-bar`,style:{animationDelay:`0ms`}}),(0,$.jsx)(`span`,{className:`recording-waveform-bar`,style:{animationDelay:`150ms`}}),(0,$.jsx)(`span`,{className:`recording-waveform-bar`,style:{animationDelay:`75ms`}}),(0,$.jsx)(`span`,{className:`recording-waveform-bar`,style:{animationDelay:`225ms`}})]}):(0,$.jsx)(be,{className:`h-3 w-3`}),t[34]=T,t[35]=x,t[36]=S,t[37]=z):z=t[37];let ne=z,B,re;t[38]!==r||t[39]!==ne||t[40]!==te||t[41]!==P||t[42]!==E||t[43]!==T||t[44]!==x||t[45]!==a||t[46]!==S||t[47]!==w?(B=te(),re=r({onClick:P,disabled:E||T||S||a===!1,icon:ne(),label:B,isRecording:x,isTranscribing:S,isDownloading:T,needsModel:w,isSupported:a!==!1}),t[38]=r,t[39]=ne,t[40]=te,t[41]=P,t[42]=E,t[43]=T,t[44]=x,t[45]=a,t[46]=S,t[47]=w,t[48]=B,t[49]=re):(B=t[48],re=t[49]);let V=re,ie;t[50]===V?ie=t[51]:(ie=(0,$.jsx)(G,{asChild:!0,children:V}),t[50]=V,t[51]=ie);let ae;t[52]===B?ae=t[53]:(ae=(0,$.jsx)(K,{side:`top`,className:`bg-popover text-popover-foreground max-w-64`,children:B}),t[52]=B,t[53]=ae);let oe;t[54]!==ie||t[55]!==ae?(oe=(0,$.jsxs)(W,{children:[ie,ae]}),t[54]=ie,t[55]=ae,t[56]=oe):oe=t[56];let H;t[57]!==g||t[58]!==l||t[59]!==c||t[60]!==I||t[61]!==T||t[62]!==o?(H=o?(0,$.jsx)(_l,{open:g,onOpenChange:v,onConfirm:I,downloading:T,progress:l,error:c}):null,t[57]=g,t[58]=l,t[59]=c,t[60]=I,t[61]=T,t[62]=o,t[63]=H):H=t[63];let se;return t[64]!==oe||t[65]!==H?(se=(0,$.jsx)(vl,{v0:oe,v1:H}),t[64]=oe,t[65]=H,t[66]=se):se=t[66],se};function bl(e){let t=(0,X.c)(8),{queuedMessages:n,onRemoveQueuedMessage:r}=e;if(n.length===0)return null;let i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(`div`,{className:q(J.compact,J.label,`text-muted-foreground`),children:`Queued messages`}),t[0]=i):i=t[0];let a;if(t[1]!==r||t[2]!==n){let e;t[4]===r?e=t[5]:(e=e=>(0,$.jsxs)(`div`,{className:q(J.body,`flex items-start justify-between gap-3 rounded-md border border-border/60 bg-background px-3 py-2`),children:[(0,$.jsx)(`p`,{className:`flex-1 whitespace-pre-wrap text-foreground`,children:e.message}),(0,$.jsx)(`button`,{type:`button`,className:`rounded-full p-1 text-muted-foreground transition-colors hover:bg-foreground hover:text-background`,onClick:()=>r(e.id),"aria-label":`Remove queued message`,children:(0,$.jsx)(j,{className:`h-3.5 w-3.5`})})]},e.id),t[4]=r,t[5]=e),a=n.map(e),t[1]=r,t[2]=n,t[3]=a}else a=t[3];let o;return t[6]===a?o=t[7]:(o=(0,$.jsxs)(Mr,{className:`mb-3 border border-border/60 bg-muted/30 px-4 py-3`,children:[i,(0,$.jsx)(`div`,{className:`mt-2 flex flex-col gap-2`,children:a})]}),t[6]=a,t[7]=o),o}function xl(e){let t=(0,X.c)(27),{onSpeechClick:n,speechDisabled:r,icon:i,label:a,isRecording:o,isTranscribing:s,isDownloading:c,isSupported:l,hasMessageText:u,setIsVoiceActive:d,isStreaming:f,disabled:p,canSubmitMessage:m,attachmentsLength:h,effectiveModel:g,onStop:_,onSend:v}=e,y=o||s||c,b,x;t[0]!==y||t[1]!==d?(b=()=>{d(y)},x=[y,d],t[0]=y,t[1]=d,t[2]=b,t[3]=x):(b=t[2],x=t[3]),(0,Y.useEffect)(b,x);let S=!f&&!y&&((p??!1)||!m&&r||!u&&h>0&&!g||u&&!g),C;t[4]!==m||t[5]!==f||t[6]!==y||t[7]!==v||t[8]!==n||t[9]!==_?(C=function(){if(f){_?.();return}if(y){n();return}if(m){v();return}n()},t[4]=m,t[5]=f,t[6]=y,t[7]=v,t[8]=n,t[9]=_,t[10]=C):C=t[10];let w=C,T=f?`Stop generation`:y?a:m?`Send message`:a,E=`relative h-7 w-7 rounded-full ${o?`bg-primary text-primary-foreground hover:bg-primary/90`:``} ${f?`before:absolute before:inset-[-1px] before:rounded-full before:border before:border-primary/60 before:animate-ping-subtle before:content-['']`:``}`,D;t[11]!==m||t[12]!==i||t[13]!==f||t[14]!==y?(D=f?(0,$.jsx)(`span`,{className:`block h-3 w-3 shrink-0 rounded-[2px] bg-current`,"aria-hidden":`true`}):y||!m?i:(0,$.jsx)(mt,{className:`h-3 w-3`}),t[11]=m,t[12]=i,t[13]=f,t[14]=y,t[15]=D):D=t[15];let O;t[16]===T?O=t[17]:(O=(0,$.jsx)(`span`,{className:`sr-only`,children:T}),t[16]=T,t[17]=O);let k;t[18]===l?k=t[19]:(k=!l&&(0,$.jsx)(`span`,{className:`sr-only`,children:`Voice input not supported`}),t[18]=l,t[19]=k);let A;return t[20]!==w||t[21]!==S||t[22]!==E||t[23]!==D||t[24]!==O||t[25]!==k?(A=(0,$.jsxs)(U,{size:`icon`,className:E,onClick:w,disabled:S,children:[D,O,k]}),t[20]=w,t[21]=S,t[22]=E,t[23]=D,t[24]=O,t[25]=k,t[26]=A):A=t[26],A}function Sl(e){let t=(0,X.c)(168),{onSend:n,onStop:r,isStreaming:a,disabled:o,initialValue:s,queuedMessages:c,onRemoveQueuedMessage:l,isOverlay:u,userTasks:d,onMatchedUserTaskSend:f,onUserTaskCreated:p}=e,m=a===void 0?!1:a,h=u===void 0?!1:u,g;t[0]===d?g=t[1]:(g=d===void 0?[]:d,t[0]=d,t[1]=g);let _=g,v=Q(jl),y;t[2]===s?y=t[3]:(y={initialValue:s},t[2]=s,t[3]=y);let{message:b,setMessage:x,historyIndex:S,setHistoryIndex:C,draftMessage:w,setDraftMessage:T,cursorPosition:E,setCursorPosition:D,availableModels:O,selectedModel:k,setSelectedModel:A,attachments:j,setAttachments:M,planMode:N,setPlanMode:P,ralphMode:F,setRalphMode:I,imageMode:L,setImageMode:R,availableImageModels:ee,selectedImageModel:te,setSelectedImageModel:z,allFiles:ne,setAllFiles:B,showSuggestions:re,setShowSuggestions:V,suggestionQuery:ie,setSuggestionQuery:ae,selectedIndex:oe,setSelectedIndex:H,slashCommands:se,skills:ce,showCommandSuggestions:le,setShowCommandSuggestions:ue,commandQuery:de,setCommandQuery:fe,fileInputRef:pe,textareaRef:me,suggestionsRef:he,commandSuggestionsRef:ge,selectedThreadId:_e,dispatch:ve}=wc(y),ye=Q(Al),be=Q(kl),xe;t[4]===ye?xe=t[5]:(xe=ye.some(Ol),t[4]=ye,t[5]=xe);let Se=xe,Ce=L?te:k,we=L?ee:O,Te;t[6]===b?Te=t[7]:(Te=b.trim(),t[6]=b,t[7]=Te);let Ee=Te.length>0,De=Ee||j.length>0,[Oe,ke]=Y.useState(!1),je=jc(),Me=_e??void 0,Ne;t[8]!==ne||t[9]!==j||t[10]!==de||t[11]!==E||t[12]!==ve||t[13]!==w||t[14]!==Se||t[15]!==S||t[16]!==L||t[17]!==m||t[18]!==b||t[19]!==f||t[20]!==n||t[21]!==N||t[22]!==F||t[23]!==te||t[24]!==oe||t[25]!==k||t[26]!==B||t[27]!==M||t[28]!==fe||t[29]!==D||t[30]!==T||t[31]!==C||t[32]!==R||t[33]!==x||t[34]!==P||t[35]!==I||t[36]!==H||t[37]!==ue||t[38]!==V||t[39]!==ae||t[40]!==le||t[41]!==re||t[42]!==ce||t[43]!==se||t[44]!==ie||t[45]!==Me||t[46]!==me||t[47]!==_?(Ne={message:b,setMessage:x,userTasks:_,onMatchedUserTaskSend:f,attachments:j,selectedModel:k,onSend:n,isStreaming:m,selectedThreadId:Me,isListening:!1,stopListening:Dl,resetTranscript:El,dispatch:ve,historyIndex:S,setHistoryIndex:C,draftMessage:w,setDraftMessage:T,cursorPosition:E,setCursorPosition:D,showSuggestions:re,setShowSuggestions:V,suggestionQuery:ie,setSuggestionQuery:ae,allFiles:ne,setAllFiles:B,selectedIndex:oe,setSelectedIndex:H,showCommandSuggestions:le,setShowCommandSuggestions:ue,commandQuery:de,setCommandQuery:fe,slashCommands:se,skills:ce,textareaRef:me,setAttachments:M,planMode:N,setPlanMode:P,ralphMode:F,setRalphMode:I,imageMode:L,setImageMode:R,selectedImageModel:te,hasConversationMessages:Se},t[8]=ne,t[9]=j,t[10]=de,t[11]=E,t[12]=ve,t[13]=w,t[14]=Se,t[15]=S,t[16]=L,t[17]=m,t[18]=b,t[19]=f,t[20]=n,t[21]=N,t[22]=F,t[23]=te,t[24]=oe,t[25]=k,t[26]=B,t[27]=M,t[28]=fe,t[29]=D,t[30]=T,t[31]=C,t[32]=R,t[33]=x,t[34]=P,t[35]=I,t[36]=H,t[37]=ue,t[38]=V,t[39]=ae,t[40]=le,t[41]=re,t[42]=ce,t[43]=se,t[44]=ie,t[45]=Me,t[46]=me,t[47]=_,t[48]=Ne):Ne=t[48];let{handleSend:Pe,handleKeyDown:Fe,handleTextareaInput:Ie,insertFileReference:Le,insertCommand:Re,insertSkill:ze,fileSuggestions:Be}=Ec(Ne),Ve;t[49]===x?Ve=t[50]:(Ve=e=>{x(t=>(t.endsWith(` `),t+e))},t[49]=x,t[50]=Ve);let He=Ve,Ue;t[51]===M?Ue=t[52]:(Ue=e=>{let t=e.clipboardData?.items;if(!t)return;let n=Array.from(t).filter(Tl);if(n.length!==0){e.preventDefault();for(let e of n){let t=e.getAsFile();if(!t)continue;let n=new FileReader;n.onload=()=>{let e=n.result.split(`,`)[1];M(n=>[...n,{fileName:t.name||`pasted-image.${t.type.split(`/`)[1]||`png`}`,content:e,mimeType:t.type}])},n.readAsDataURL(t)}}},t[51]=M,t[52]=Ue);let We=Ue,Ge=h?`absolute inset-x-0 bottom-0 mx-auto w-full max-w-3xl max-md:px-2 px-4 pb-4 pointer-events-none`:`relative mx-auto w-full max-w-3xl max-md:px-0 pb-2 md:px-4 md:pb-4 md:-mx-[6px]`,Ke=`flex flex-col rounded-2xl border focus-within:ring-2 focus-within:ring-brand pointer-events-auto ${h?`border-border/50 shadow-lg backdrop-blur-sm`:`border-border shadow-2xl`}`,qe;t[53]!==h||t[54]!==v?(qe=Cc(v,h),t[53]=h,t[54]=v,t[55]=qe):qe=t[55];let Je;t[56]===qe?Je=t[57]:(Je={backgroundImage:qe},t[56]=qe,t[57]=Je);let Ye;t[58]!==l||t[59]!==c?(Ye=(0,$.jsx)(bl,{queuedMessages:c,onRemoveQueuedMessage:l}),t[58]=l,t[59]=c,t[60]=Ye):Ye=t[60];let Xe=F?`Describe stories for Ralph to implement autonomously...`:N?`Describe what you want Tarsk to plan...`:L?`Describe the image you want to generate...`:Oe?`Dictate your message...`:`Ask Tarsk anything, # for files, / for commands & skills`,Ze;t[61]===Symbol.for(`react.memo_cache_sentinel`)?(Ze=q(J.body,`min-h-[4.5rem] w-full resize-none bg-transparent px-6 pt-4 pb-4 text-foreground placeholder:text-muted-foreground focus:outline-none`),t[61]=Ze):Ze=t[61];let U;t[62]!==o||t[63]!==Fe||t[64]!==We||t[65]!==Ie||t[66]!==b||t[67]!==Xe||t[68]!==me?(U=(0,$.jsx)(`textarea`,{ref:me,value:b,onChange:Ie,onKeyDown:Fe,onPaste:We,placeholder:Xe,rows:1,className:Ze,disabled:o}),t[62]=o,t[63]=Fe,t[64]=We,t[65]=Ie,t[66]=b,t[67]=Xe,t[68]=me,t[69]=U):U=t[69];let Qe;t[70]!==de||t[71]!==ge||t[72]!==Re||t[73]!==ze||t[74]!==oe||t[75]!==H||t[76]!==le||t[77]!==ce||t[78]!==se?(Qe=(0,$.jsx)(Nc,{visible:le,commands:se,skills:ce,query:de,selectedIndex:oe,onSelectCommand:Re,onSelectSkill:ze,onMouseEnterSuggestion:H,containerRef:ge}),t[70]=de,t[71]=ge,t[72]=Re,t[73]=ze,t[74]=oe,t[75]=H,t[76]=le,t[77]=ce,t[78]=se,t[79]=Qe):Qe=t[79];let $e;t[80]!==Be||t[81]!==Le||t[82]!==oe||t[83]!==H||t[84]!==re||t[85]!==ie||t[86]!==he?($e=(0,$.jsx)(zc,{showSuggestions:re,fileSuggestions:Be,suggestionQuery:ie,selectedIndex:oe,onSelectFile:Le,onMouseEnterSuggestion:H,containerRef:he}),t[80]=Be,t[81]=Le,t[82]=oe,t[83]=H,t[84]=re,t[85]=ie,t[86]=he,t[87]=$e):$e=t[87];let et;t[88]!==j||t[89]!==k?.id||t[90]!==k?.name||t[91]!==k?.supportsImages||t[92]!==M?(et=j.length>0&&(0,$.jsxs)(`div`,{className:`px-4`,children:[(0,$.jsx)(Lc,{attachments:j,onRemove:e=>M(t=>t.filter((t,n)=>n!==e))}),j.some(wl)&&k?.supportsImages===!1&&(0,$.jsxs)(`div`,{className:q(J.compact,`mb-2 flex items-center gap-1.5 text-amber-500`),children:[(0,$.jsx)(Ae,{className:`h-3 w-3 shrink-0`}),(0,$.jsxs)(`span`,{children:[`Images are not supported by `,k?.name||k?.id]})]})]}),t[88]=j,t[89]=k?.id,t[90]=k?.name,t[91]=k?.supportsImages,t[92]=M,t[93]=et):et=t[93];let tt;t[94]===pe?tt=t[95]:(tt=()=>pe.current?.click(),t[94]=pe,t[95]=tt);let nt;t[96]!==ve||t[97]!==b||t[98]!==p||t[99]!==M||t[100]!==x||t[101]!==_e||t[102]!==me?(nt=()=>{let e=_e;if(!e)return;let t=b.trim();t&&i(e,t).then(t=>{p?.(t),x(``),M([]),ve({type:Z.ClearChatInputDraft,threadId:e}),me.current&&(me.current.style.height=`auto`)}).catch(Cl)},t[96]=ve,t[97]=b,t[98]=p,t[99]=M,t[100]=x,t[101]=_e,t[102]=me,t[103]=nt):nt=t[103];let rt;t[104]!==o||t[105]!==Ee||t[106]!==L||t[107]!==je||t[108]!==N||t[109]!==F||t[110]!==be||t[111]!==R||t[112]!==P||t[113]!==I||t[114]!==tt||t[115]!==nt?(rt=(0,$.jsx)(el,{disabled:o,canAddTask:Ee,showModes:je,planMode:N,imageMode:L,ralphMode:F,setPlanMode:P,setImageMode:R,setRalphMode:I,projectId:be,onFileAttach:tt,onAddTask:nt}),t[104]=o,t[105]=Ee,t[106]=L,t[107]=je,t[108]=N,t[109]=F,t[110]=be,t[111]=R,t[112]=P,t[113]=I,t[114]=tt,t[115]=nt,t[116]=rt):rt=t[116];let it=L?z:A,at;t[117]!==we||t[118]!==Ce||t[119]!==it?(at=(0,$.jsx)(qc,{availableModels:we,selectedModel:Ce,onModelSelect:it}),t[117]=we,t[118]=Ce,t[119]=it,t[120]=at):at=t[120];let ot;t[121]!==rt||t[122]!==at?(ot=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[rt,at]}),t[121]=rt,t[122]=at,t[123]=ot):ot=t[123];let st;t[124]!==L||t[125]!==N||t[126]!==F||t[127]!==be||t[128]!==R||t[129]!==P||t[130]!==I?(st=(0,$.jsx)($c,{planMode:N,imageMode:L,ralphMode:F,setPlanMode:P,setImageMode:R,setRalphMode:I,projectId:be}),t[124]=L,t[125]=N,t[126]=F,t[127]=be,t[128]=R,t[129]=P,t[130]=I,t[131]=st):st=t[131];let W;t[132]!==j.length||t[133]!==De||t[134]!==o||t[135]!==Ce||t[136]!==Pe||t[137]!==Ee||t[138]!==m||t[139]!==r?(W=e=>{let{onClick:t,disabled:n,icon:i,label:a,isRecording:s,isTranscribing:c,isDownloading:l,isSupported:u}=e;return(0,$.jsx)(xl,{onSpeechClick:t,speechDisabled:n,icon:i,label:a,isRecording:s,isTranscribing:c,isDownloading:l,isSupported:u,hasMessageText:Ee,setIsVoiceActive:ke,isStreaming:m,disabled:o,canSubmitMessage:De,attachmentsLength:j.length,effectiveModel:Ce,onStop:r,onSend:Pe})},t[132]=j.length,t[133]=De,t[134]=o,t[135]=Ce,t[136]=Pe,t[137]=Ee,t[138]=m,t[139]=r,t[140]=W):W=t[140];let ct;t[141]!==He||t[142]!==W?(ct=(0,$.jsx)(yl,{onTranscript:He,children:W}),t[141]=He,t[142]=W,t[143]=ct):ct=t[143];let lt;t[144]!==st||t[145]!==ct?(lt=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[st,ct]}),t[144]=st,t[145]=ct,t[146]=lt):lt=t[146];let ut;t[147]!==ot||t[148]!==lt?(ut=(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[ot,lt]}),t[147]=ot,t[148]=lt,t[149]=ut):ut=t[149];let dt;t[150]!==Ke||t[151]!==Je||t[152]!==Ye||t[153]!==U||t[154]!==Qe||t[155]!==$e||t[156]!==et||t[157]!==ut?(dt=(0,$.jsxs)(`div`,{className:Ke,style:Je,children:[Ye,U,Qe,$e,et,ut]}),t[150]=Ke,t[151]=Je,t[152]=Ye,t[153]=U,t[154]=Qe,t[155]=$e,t[156]=et,t[157]=ut,t[158]=dt):dt=t[158];let ft;t[159]===M?ft=t[160]:(ft=e=>Rc(e,e=>M(t=>[...t,...e])),t[159]=M,t[160]=ft);let pt;t[161]!==pe||t[162]!==ft?(pt=(0,$.jsx)(`input`,{ref:pe,type:`file`,multiple:!0,className:`hidden`,onChange:ft}),t[161]=pe,t[162]=ft,t[163]=pt):pt=t[163];let mt;return t[164]!==Ge||t[165]!==dt||t[166]!==pt?(mt=(0,$.jsxs)(`div`,{className:Ge,children:[dt,pt]}),t[164]=Ge,t[165]=dt,t[166]=pt,t[167]=mt):mt=t[167],mt}function Cl(e){console.error(`Failed to create user task:`,e)}function wl(e){return e.mimeType.startsWith(`image/`)}function Tl(e){return e.type.startsWith(`image/`)}function El(){}function Dl(){}function Ol(e){return e.sender===`agent`}function kl(e){return e.selectedProjectId}function Al(e){return e.messages}function jl(e){return e.sidebarOpen}function Ml(e){let t=(0,X.c)(25),{currentBranch:n,availableBranches:r,isLoadingBranches:i,isCheckingOut:a,onLoadBranches:o,onCheckoutBranch:s,onCreateBranch:c}=e,l;t[0]===o?l=t[1]:(l=e=>{e&&o()},t[0]=o,t[1]=l);let u,d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=q(J.compact,`h-7 px-2 bg-background gap-1.5 border-none text-muted-foreground hover:bg-accent hover:text-accent-foreground`),d=(0,$.jsx)(En,{className:`h-3.5 w-3.5 shrink-0`}),t[2]=u,t[3]=d):(u=t[2],d=t[3]);let f=n||`Unknown`,p;t[4]===f?p=t[5]:(p=(0,$.jsx)(us,{asChild:!0,children:(0,$.jsxs)(U,{variant:`outline`,size:`sm`,className:u,children:[d,f]})}),t[4]=f,t[5]=p);let m,h;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(sn,{className:`h-3.5 w-3.5 mr-2 shrink-0`}),h=(0,$.jsx)(`span`,{children:`Create branch`}),t[6]=m,t[7]=h):(m=t[6],h=t[7]);let g;t[8]!==a||t[9]!==c?(g=(0,$.jsxs)(hs,{onClick:c,disabled:a,children:[m,h]}),t[8]=a,t[9]=c,t[10]=g):g=t[10];let v;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(ys,{}),t[11]=v):v=t[11];let y;t[12]!==r||t[13]!==n||t[14]!==a||t[15]!==i||t[16]!==s?(y=i?(0,$.jsxs)(`div`,{className:q(J.compact,`px-2 py-1.5 text-muted-foreground flex items-center gap-2`),children:[(0,$.jsx)(_,{className:`h-3 w-3 animate-spin`}),`Loading branches...`]}):r.length===0?(0,$.jsx)(`div`,{className:q(J.compact,`px-2 py-1.5 text-muted-foreground`),children:`No branches found`}):r.map(e=>(0,$.jsxs)(hs,{disabled:e===n||a,onClick:()=>s(e),children:[(0,$.jsx)(En,{className:`h-3.5 w-3.5 mr-2 shrink-0`}),(0,$.jsx)(`span`,{className:e===n?`font-semibold text-foreground`:``,children:e}),e===n&&(0,$.jsx)(`span`,{className:q(J.compact,`ml-auto text-muted-foreground`),children:`current`})]},e)),t[12]=r,t[13]=n,t[14]=a,t[15]=i,t[16]=s,t[17]=y):y=t[17];let b;t[18]!==y||t[19]!==g?(b=(0,$.jsxs)(ms,{align:`start`,children:[g,v,y]}),t[18]=y,t[19]=g,t[20]=b):b=t[20];let x;return t[21]!==l||t[22]!==b||t[23]!==p?(x=(0,$.jsxs)(ls,{onOpenChange:l,children:[p,b]}),t[21]=l,t[22]=b,t[23]=p,t[24]=x):x=t[24],x}function Nl(e){let t=(0,X.c)(35),{open:n,onOpenChange:r,branchName:i,onBranchNameChange:a,isLoading:o,onCreateBranch:c}=e,l;t[0]!==i||t[1]!==o||t[2]!==c?(l=e=>{e.key===`Enter`&&i.trim()&&!o&&c()},t[0]=i,t[1]=o,t[2]=c,t[3]=l):l=t[3];let u=l,d;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsxs)(xt,{children:[(0,$.jsx)(z,{children:`New Branch`}),(0,$.jsx)(Ct,{children:`Enter a name for the new branch. It will be created from the default branch.`})]}),t[4]=d):d=t[4];let f;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(yn,{htmlFor:`branch-name`,children:`Branch Name`}),t[5]=f):f=t[5];let p;t[6]===a?p=t[7]:(p=e=>a(e.target.value),t[6]=a,t[7]=p);let m;t[8]!==i||t[9]!==u||t[10]!==o||t[11]!==p?(m=(0,$.jsx)(`div`,{className:`grid gap-4 py-4`,children:(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[f,(0,$.jsx)(b,{id:`branch-name`,placeholder:`e.g. feature/my-feature`,value:i,onChange:p,onKeyDown:u,disabled:o,autoFocus:!0})]})}),t[8]=i,t[9]=u,t[10]=o,t[11]=p,t[12]=m):m=t[12];let h;t[13]===r?h=t[14]:(h=()=>r(!1),t[13]=r,t[14]=h);let _;t[15]!==o||t[16]!==h?(_=(0,$.jsx)(U,{variant:`outline`,onClick:h,disabled:o,children:`Cancel`}),t[15]=o,t[16]=h,t[17]=_):_=t[17];let v;t[18]!==i||t[19]!==o?(v=o||!i.trim(),t[18]=i,t[19]=o,t[20]=v):v=t[20];let y=o?`Creating...`:`Create Branch`,x;t[21]!==c||t[22]!==v||t[23]!==y?(x=(0,$.jsx)(U,{onClick:c,disabled:v,children:y}),t[21]=c,t[22]=v,t[23]=y,t[24]=x):x=t[24];let S;t[25]!==x||t[26]!==_?(S=(0,$.jsxs)(s,{children:[_,x]}),t[25]=x,t[26]=_,t[27]=S):S=t[27];let C;t[28]!==S||t[29]!==m?(C=(0,$.jsxs)(H,{children:[d,m,S]}),t[28]=S,t[29]=m,t[30]=C):C=t[30];let w;return t[31]!==r||t[32]!==n||t[33]!==C?(w=(0,$.jsx)(g,{open:n,onOpenChange:r,children:C}),t[31]=r,t[32]=n,t[33]=C,t[34]=w):w=t[34],w}function Pl(e){let t=(0,X.c)(8),{collapsed:n}=e,{theme:r,setTheme:i}=zr();if(n)return null;let a;t[0]!==i||t[1]!==r?(a=()=>i(r===`dark`?`light`:`dark`),t[0]=i,t[1]=r,t[2]=a):a=t[2];let o,s,c;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(Kt,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),s=(0,$.jsx)(pn,{className:`absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100`}),c=(0,$.jsx)(`span`,{className:`sr-only`,children:`Toggle theme`}),t[3]=o,t[4]=s,t[5]=c):(o=t[3],s=t[4],c=t[5]);let l;return t[6]===a?l=t[7]:(l=(0,$.jsxs)(U,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,onClick:a,children:[o,s,c]}),t[6]=a,t[7]=l),l}var Fl=Cr(e=>(0,$.jsxs)(`div`,{className:`w-72 space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h3`,{className:e.v0,children:`Context`}),e.v1]}),(0,$.jsxs)(`div`,{className:e.v2,children:[(0,$.jsxs)(`span`,{children:[e.v3,`% Full`]}),(0,$.jsxs)(`span`,{children:[`~`,e.v4,` / `,e.v5,` Tokens`]})]}),(0,$.jsx)(`div`,{className:`h-2 w-full overflow-hidden rounded-full bg-muted/60`,children:(0,$.jsx)(`div`,{className:`flex h-full w-full`,children:e.v6})}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:e.v7})]}),{name:`ContextUsagePanel_1`,portals:[`v1`,`v3`,`v4`,`v5`,`v6`,`v7`]}),Il=function(e){let t=(0,X.c)(37),{breakdown:n,onClose:r}=e,{categories:i,totalTokens:a,contextWindow:o,percentageFull:s}=n,c,l,u,d,f,p,m,h;if(t[0]!==i||t[1]!==o||t[2]!==r||t[3]!==s||t[4]!==a){let e;t[13]===i?e=t[14]:(e=e=>i[e.key]>0,t[13]=i,t[14]=e);let n=Ll.filter(e);c=Fl,l=J.label,t[15]===r?u=t[16]:(u=r&&(0,$.jsxs)(U,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,onClick:r,children:[(0,$.jsx)(j,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Close`})]}),t[15]=r,t[16]=u),t[17]===Symbol.for(`react.memo_cache_sentinel`)?(d=q(J.compact,`flex items-center justify-between text-muted-foreground`),t[17]=d):d=t[17],f=s,t[18]===a?p=t[19]:(p=Rl(a),t[18]=a,t[19]=p),t[20]===o?m=t[21]:(m=zl(o),t[20]=o,t[21]=m);let g;t[22]!==i||t[23]!==o?(g=e=>{let t=i[e.key],n=o>0?t/o*100:0;return(0,$.jsx)(`div`,{style:{width:`${Math.max(n,t>0?.5:0)}%`,backgroundColor:e.color}},e.key)},t[22]=i,t[23]=o,t[24]=g):g=t[24],h=n.map(g),t[0]=i,t[1]=o,t[2]=r,t[3]=s,t[4]=a,t[5]=c,t[6]=l,t[7]=u,t[8]=d,t[9]=f,t[10]=p,t[11]=m,t[12]=h}else c=t[5],l=t[6],u=t[7],d=t[8],f=t[9],p=t[10],m=t[11],h=t[12];let g;t[25]===i?g=t[26]:(g=Ll.map(e=>(0,$.jsxs)(`div`,{className:q(J.compact,`flex items-center justify-between text-muted-foreground`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{backgroundColor:e.color}}),(0,$.jsx)(`span`,{children:e.label})]}),(0,$.jsx)(`span`,{className:`tabular-nums`,children:Rl(i[e.key])})]},e.key)),t[25]=i,t[26]=g);let _;return t[27]!==c||t[28]!==l||t[29]!==u||t[30]!==d||t[31]!==f||t[32]!==p||t[33]!==m||t[34]!==h||t[35]!==g?(_=(0,$.jsx)(c,{v0:l,v1:u,v2:d,v3:f,v4:p,v5:m,v6:h,v7:g}),t[27]=c,t[28]=l,t[29]=u,t[30]=d,t[31]=f,t[32]=p,t[33]=m,t[34]=h,t[35]=g,t[36]=_):_=t[36],_},Ll=[{key:`systemPrompt`,label:`System prompt`,color:`#9CA3AF`},{key:`toolDefinitions`,label:`Tool definitions`,color:`#B088F0`},{key:`rules`,label:`Rules`,color:`#88D088`},{key:`skills`,label:`Skills`,color:`#D0A000`},{key:`subagentDefinitions`,label:`Subagent definitions`,color:`#2080D0`},{key:`conversation`,label:`Conversation`,color:`#E09030`}];function Rl(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function zl(e){return e>=1e6?`${Math.round(e/1e6)}M`:e>=1e3?`${Math.round(e/1e3)}K`:e.toString()}function Bl({threadId:e,currentConversationId:t,initialBreakdown:n,refreshKey:r,children:i}){let[a,o]=(0,Y.useState)(n??null),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)(n?t:void 0);return(0,Y.useEffect)(()=>{if(n){o(n),m(t),u(null);return}t!==p&&(o(null),m(void 0),u(null))},[n,t,p,r]),(0,Y.useEffect)(()=>{if(!d||!e||!t||p===t)return;let n=!1;async function r(){let r=t;if(r){c(!0),u(null);try{let t=await on(e,r);if(n)return;o(t),m(r)}catch(e){if(console.error(`[TokenUsageTooltip] Failed to load context data:`,e),n)return;o(e=>(e||u(`Failed to load context data`),e))}finally{n||c(!1)}}}return r(),()=>{n=!0}},[d,e,t,p]),!e||e===``?(0,$.jsx)($.Fragment,{children:i}):(0,$.jsxs)(wo,{open:d,onOpenChange:f,children:[(0,$.jsx)(To,{asChild:!0,children:i}),(0,$.jsxs)(Eo,{side:`top`,align:`end`,className:`w-auto p-4`,children:[s&&(0,$.jsxs)(`div`,{className:q(J.compact,`flex w-72 items-center gap-2 text-muted-foreground`),children:[(0,$.jsx)(nt,{className:`h-3 w-3 animate-pulse`}),(0,$.jsx)(`span`,{children:`Loading context...`})]}),l&&!s&&(0,$.jsxs)(`div`,{className:q(J.compact,`flex w-72 items-center gap-2 text-muted-foreground`),children:[(0,$.jsx)(nt,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:l})]}),!s&&!l&&a&&(0,$.jsx)(Il,{breakdown:a,onClose:()=>f(!1)})]})]})}var Vl=Cr(e=>(0,$.jsxs)(`svg`,{className:e.v0,viewBox:`0 0 20 20`,"aria-hidden":`true`,children:[(0,$.jsx)(`circle`,{className:`text-muted-foreground/25`,cx:`10`,cy:`10`,r:e.v1,fill:`none`,stroke:`currentColor`,strokeWidth:`3`}),(0,$.jsx)(`circle`,{cx:`10`,cy:`10`,r:e.v2,fill:`none`,stroke:`currentColor`,strokeWidth:`3`,strokeLinecap:`round`,strokeDasharray:e.v3,strokeDashoffset:e.v4,transform:`rotate(-90 10 10)`})]}),{name:`ContextUsageRing_1`,svg:!0}),Hl=function(e){let t=(0,X.c)(5),{percentage:n}=e,r=2*Math.PI*7,i=r*(1-Math.min(n,100)/100),a;t[0]===n?a=t[1]:(a=Wl(n),t[0]=n,t[1]=a);let o=`h-4 w-4 ${a}`,s;return t[2]!==i||t[3]!==o?(s=(0,$.jsx)(Vl,{v0:o,v1:7,v2:7,v3:r,v4:i}),t[2]=i,t[3]=o,t[4]=s):s=t[4],s};function Ul(e){return e.filter(e=>e.sender===`agent`).length}function Wl(e){return e>75?`text-red-500`:e>50?`text-orange-500`:`text-muted-foreground`}function Gl(e){let t=(0,X.c)(21),{threadId:n,messages:r}=e,i;t[0]===r?i=t[1]:(i=r===void 0?[]:r,t[0]=r,t[1]=i);let a=i,[o,s]=(0,Y.useState)(),[c,l]=(0,Y.useState)(),u;t[2]===a?u=t[3]:(u=Ul(a),t[2]=a,t[3]=u);let d=u,f;t[4]===n?f=t[5]:(f=()=>{(async function(){if(!n){s(void 0),l(void 0);return}try{let e=(await wt(n)).currentConversationId;if(s(e),!e){l(void 0);return}l(await on(n,e))}catch(e){console.error(`Failed to fetch thread usage data:`,e)}})()},t[4]=n,t[5]=f);let p;if(t[6]!==n||t[7]!==d?(p=[n,d],t[6]=n,t[7]=d,t[8]=p):p=t[8],(0,Y.useEffect)(f,p),!n||n===``)return null;let m=c?.percentageFull,h=typeof m==`number`&&m>25,g=String(d),_;t[9]!==m||t[10]!==h?(_=h?(0,$.jsx)(Hl,{percentage:m}):(0,$.jsx)(O,{className:`h-4 w-4`}),t[9]=m,t[10]=h,t[11]=_):_=t[11];let v;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(`span`,{className:`sr-only`,children:`View token usage`}),t[12]=v):v=t[12];let y;t[13]===_?y=t[14]:(y=(0,$.jsxs)(U,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,children:[_,v]}),t[13]=_,t[14]=y);let b;return t[15]!==c||t[16]!==o||t[17]!==g||t[18]!==y||t[19]!==n?(b=(0,$.jsx)(Bl,{threadId:n,currentConversationId:o,initialBreakdown:c,refreshKey:g,children:y}),t[15]=c,t[16]=o,t[17]=g,t[18]=y,t[19]=n,t[20]=b):b=t[20],b}var Kl=`[gitops-timing]`;function ql(e){let t=[],n=performance.now();async function r(n,r){let i=performance.now();try{return await r()}finally{let r=Math.round(performance.now()-i);t.push({step:n,ms:r}),console.log(`${Kl} ${e} step=${n} ${r}ms`)}}function i(n,r,i){t.push({step:n,ms:r}),console.log(`${Kl} ${e} step=${n} ${r}ms${i?` ${i}`:``}`)}function a(r){let i=Math.round(performance.now()-n),a=t.reduce((e,t)=>t.ms>=e.ms?t:e,{step:`none`,ms:0}),o=t.map(e=>`${e.step}:${e.ms}`).join(` `);console.log(`${Kl} ${e} summary total=${i}ms slowest=${a.step}@${a.ms}ms breakdown=[${o}]${r?` ${r}`:``}`)}return{step:r,record:i,summary:a}}var Jl=3e4,Yl={hasChanges:!1,changedFilesCount:0,hasUnpushedCommits:!1,currentBranch:``,hasRemoteBranch:!1,isOnGitHub:!1,remoteUrl:``,canCreateRepo:!1,repoUrl:void 0,status:`Up to date`,defaultBranch:null,prExists:!1,prUrl:void 0,prState:void 0,commitsAheadOfDefault:!1},Xl=new Map,Zl=new Map;function Ql(e,t){let n=Xl.get(e);if(n)for(let e of n)e(t)}function $l(e,t){let n=Xl.get(e);return n||(n=new Set,Xl.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&Xl.delete(e)}}function eu(e){return`unified-git-status-${e}`}function tu(e){return bt.getSync(eu(e))}function nu(e){let[t,n]=(0,Y.useState)(Yl),[r,i]=(0,Y.useState)(!1),a=(0,Y.useRef)(void 0),o=(0,Y.useRef)(0),s=(0,Y.useCallback)(e=>{(0,Y.startTransition)(()=>{n(e)})},[]),c=(0,Y.useRef)(s);c.current=s;let l=(0,Y.useCallback)(async(t=!1)=>{if(!e)return;let n=++o.current,r=ql(`hook fetch thread=${e} force=${t}`),a=setTimeout(()=>{o.current===n&&i(!0)},100);try{let i=eu(e),a=performance.now(),c=tu(e);r.record(`local-cache-check`,Math.round(performance.now()-a),`result=${c?`hit`:`miss`}`),t&&(bt.invalidate(i),r.record(`invalidate-local-cache`,0));let l=await r.step(`ttl-cache-get`,()=>bt.get(i,()=>ie(e,t,!1),Jl));if(o.current!==n){r.summary(`stale-request`);return}await r.step(`update-state`,async()=>{s(l),Ql(e,l)}),r.summary(`branch=${l.currentBranch} changes=${l.changedFilesCount} prExists=${l.prExists}`)}catch(e){if(o.current!==n)return;console.error(`Failed to fetch unified git status:`,e),r.summary(`error`)}finally{clearTimeout(a),o.current===n&&i(!1)}},[e,s]),u=(0,Y.useRef)(l);return u.current=l,(0,Y.useEffect)(()=>{if(e)return $l(e,e=>{c.current(e)})},[e]),(0,Y.useEffect)(()=>{if(!e)return;let t=e;function n(){document.visibilityState===`visible`&&(bt.invalidate(eu(t)),u.current(!1))}return document.addEventListener(`visibilitychange`,n),window.addEventListener(`focus`,n),()=>{document.removeEventListener(`visibilitychange`,n),window.removeEventListener(`focus`,n)}},[e]),(0,Y.useEffect)(()=>{if(o.current+=1,i(!1),!e){a.current=void 0,(0,Y.startTransition)(()=>{n(Yl)});return}let t=a.current!==e,r=tu(e);t&&(console.log(`[gitops-timing] hook thread changed ${a.current??`none`} -> ${e}`),a.current=e,bt.invalidate(eu(e))),(0,Y.startTransition)(()=>{n(r??Yl)}),console.log(r?`[gitops-timing] hook load thread=${e} local cache=hit`:`[gitops-timing] hook load thread=${e} local cache=miss`);let s=e,l=!1;function d(){if(l)return;let e=Zl.get(s);if(e){console.log(`[gitops-timing] hook initial fetch already in flight thread=${s}`),e.then(()=>{if(l)return;let e=tu(s);e&&c.current(e)});return}console.log(`[gitops-timing] hook starting initial fetch thread=${s}`);let t=u.current(!1).finally(()=>{console.log(`[gitops-timing] hook initial fetch settled thread=${s}`),Zl.delete(s)});Zl.set(s,t)}return d(),()=>{l=!0}},[e]),{hasChanges:t.hasChanges,changedFilesCount:t.changedFilesCount,hasUnpushedCommits:t.hasUnpushedCommits,hasRemoteBranch:t.hasRemoteBranch,currentBranch:t.currentBranch,isOnGitHub:t.isOnGitHub,remoteUrl:t.remoteUrl,canCreateRepo:t.canCreateRepo,repoUrl:t.repoUrl,status:t.status,defaultBranch:t.defaultBranch,prExists:t.prExists,prUrl:t.prUrl,prState:t.prState,commitsAheadOfDefault:t.commitsAheadOfDefault,isRefreshing:r,fetchUnifiedStatus:l}}var ru=(0,Y.createContext)(void 0);function iu(e){let t=(0,X.c)(8),{threadId:n,fetchUnifiedStatus:r}=e,i=yi(),a=Q(su),o=Q(ou),s=Q(au),c,l;return t[0]!==o||t[1]!==i||t[2]!==r||t[3]!==a||t[4]!==s||t[5]!==n?(c=()=>{if(!(!n||n!==s)&&!a&&o.includes(n)){let e=setTimeout(()=>{r(!0),i({type:Z.ClearThreadCompleted,threadId:n})},1e3);return()=>clearTimeout(e)}},l=[n,s,a,o,r,i],t[0]=o,t[1]=i,t[2]=r,t[3]=a,t[4]=s,t[5]=n,t[6]=c,t[7]=l):(c=t[6],l=t[7]),(0,Y.useEffect)(c,l),null}function au(e){return e.selectedThreadId}function ou(e){return e.completedThreadIds}function su(e){return e.isStreaming}function cu(e){let t=(0,X.c)(7),{threadId:n,children:r}=e,i=nu(n),a;t[0]!==n||t[1]!==i.fetchUnifiedStatus?(a=(0,$.jsx)(iu,{threadId:n,fetchUnifiedStatus:i.fetchUnifiedStatus}),t[0]=n,t[1]=i.fetchUnifiedStatus,t[2]=a):a=t[2];let o;return t[3]!==r||t[4]!==a||t[5]!==i?(o=(0,$.jsxs)(ru.Provider,{value:i,children:[a,r]}),t[3]=r,t[4]=a,t[5]=i,t[6]=o):o=t[6],o}function lu(){let e=(0,Y.useContext)(ru);if(e===void 0)throw Error(`useGitStatus must be used within a GitStatusProvider`);return e}var uu=`panda.koala.penguin.bunny.kitten.puppy.hamster.otter.hedgehog.sloth.dolphin.owl.fox.deer.koala.walrus.bouncy.sparkly.fluffy.jolly.zesty.peppy.snappy.perky.breezy.chirpy.dizzy.fizzy.glossy.groggy.loopy.quirky.umbrella.taco.pickle.waffle.bubble.puzzle.rocket.tornado.volcano.rainbow.diamond.crystal.lantern.treasure.whisper.echo.boing.splat.whoosh.crunch.splash.jingle.wiggle.giggle.scramble.tumble.fumble.jumble.rumble.mumble.stumble.hustle.castle.island.mountain.forest.meadow.lagoon.canyon.geyser.oasis.glacier.waterfall.volcano.tundra.savanna.jungle.desert.magic.dream.wonder.spark.glow.shimmer.twinkle.radiance.harmony.melody.rhythm.symphony.adventure.journey.quest.odyssey`.split(`.`);function du(){return uu[Math.floor(Math.random()*uu.length)]??`branch`}function fu(){let e=du(),t=du();for(;t===e;)t=du();return`${e}-${t}`}function pu(e){let[t,n]=(0,Y.useState)([]),[r,i]=(0,Y.useState)(!1),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(!1),[l,d]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)(`main`),g=lu();(0,Y.useEffect)(()=>{if(!s){d(``);return}d(fu())},[s]),(0,Y.useEffect)(()=>{g.defaultBranch&&h(g.defaultBranch)},[g.defaultBranch]);async function _(){if(!(!e||r)){i(!0);try{n((await u(e)).branches)}catch{n([])}finally{i(!1)}}}async function v(t){if(!(!e||t===g.currentBranch)){o(!0);try{await C(e,t),await g.fetchUnifiedStatus(!0),Ii({title:`Switched to branch "${t}"`})}catch(e){Ii({title:`Failed to switch branch`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}finally{o(!1)}}}function y(){c(!0)}async function b(){if(!(!e||!l.trim()||f)){p(!0);try{let t=await R(e,m,l);c(!1),await _(),await g.fetchUnifiedStatus(!0),Ii({title:`Branch created`,description:`Created branch "${t.branchName}" from ${m}`})}catch(e){Ii({title:`Failed to create branch`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}finally{p(!1)}}}return{currentBranch:g.currentBranch,availableBranches:t,isLoadingBranches:r,isCheckingOut:a,loadBranches:_,checkoutBranch:v,fetchUnifiedStatus:g.fetchUnifiedStatus,isCreateDialogOpen:s,setIsCreateDialogOpen:c,newBranchName:l,setNewBranchName:d,isCreatingBranch:f,createBranch:b,openCreateBranchDialog:y,defaultBranch:m}}function mu({threadId:e,messages:t=[]}){let[n,r]=(0,Y.useState)(!1),[i,a]=(0,Y.useState)(null),o=pu(e);return(0,Y.useEffect)(()=>{e&&Lt(e).then(a).catch(()=>{})},[e]),(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-8 py-2 mt-[-1rem] min-h-[2.25rem]`,children:[e&&(0,$.jsx)(Ml,{currentBranch:o.currentBranch,availableBranches:o.availableBranches,isLoadingBranches:o.isLoadingBranches,isCheckingOut:o.isCheckingOut,onLoadBranches:o.loadBranches,onCheckoutBranch:o.checkoutBranch,onCreateBranch:o.openCreateBranchDialog}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Pl,{collapsed:!1}),(0,$.jsx)(Gl,{threadId:e,messages:t}),e&&(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(U,{variant:`ghost`,size:`icon-sm`,className:`text-muted-foreground hover:text-background`,onClick:async()=>{if(!(!e||n)){r(!0);try{let t=await Lt(e);await navigator.clipboard.writeText(t)}finally{r(!1)}}},disabled:n,"aria-label":`Copy repository folder path`,children:(0,$.jsx)(ke,{className:`h-4 w-4`})})}),(0,$.jsxs)(K,{side:`top`,className:`bg-slate-900 text-white`,children:[(0,$.jsx)(`div`,{children:`Copy repository folder path`}),i&&(0,$.jsx)(`div`,{className:q(J.compact,`opacity-70`),children:i})]})]})]})]}),(0,$.jsx)(Nl,{open:o.isCreateDialogOpen,onOpenChange:o.setIsCreateDialogOpen,branchName:o.newBranchName,onBranchNameChange:o.setNewBranchName,isLoading:o.isCreatingBranch,onCreateBranch:()=>void o.createBranch()})]})}var hu=Cr(e=>(0,$.jsxs)(`svg`,{"aria-hidden":`true`,width:e.v0,height:e.v1,viewBox:e.v2,className:`size-10 shrink-0`,children:[(0,$.jsx)(`circle`,{cx:e.v3,cy:e.v4,r:e.v5,fill:`none`,stroke:`currentColor`,strokeOpacity:`0.2`,strokeWidth:e.v6}),(0,$.jsx)(`circle`,{cx:e.v7,cy:e.v8,r:e.v9,fill:`none`,stroke:`currentColor`,strokeWidth:e.v10,strokeDasharray:e.v11,strokeDashoffset:e.v12,strokeLinecap:`round`,transform:e.v13,className:`transition-[stroke-dashoffset] duration-300 ease-out`})]}),{name:`TodoProgressRing_1`,svg:!0}),gu=function(e){let t=(0,X.c)(2),{completedCount:n,totalCount:r}=e,i=bu*(1-(r>0?n/r:0)),a=_u/2,o;return t[0]===i?o=t[1]:(o=(0,$.jsx)(hu,{v0:_u,v1:_u,v2:`0 0 ${_u} ${_u}`,v3:a,v4:a,v5:yu,v6:vu,v7:a,v8:a,v9:yu,v10:vu,v11:bu,v12:i,v13:`rotate(-90 ${a} ${a})`}),t[0]=i,t[1]=o),o},_u=40,vu=4,yu=10,bu=2*Math.PI*yu;function xu(e){let t=(0,X.c)(13),{todos:n}=e,r;t[0]===n?r=t[1]:(r=n.filter(Cu),t[0]=n,t[1]=r);let i=r.length,a;t[2]===n.length?a=t[3]:(a=n.length===0&&(0,$.jsx)(`p`,{className:J.compact,children:`No todo items.`}),t[2]=n.length,t[3]=a);let o;t[4]===n?o=t[5]:(o=n.map(Su),t[4]=n,t[5]=o);let s;t[6]!==i||t[7]!==n.length?(s=n.length>0&&(0,$.jsxs)(`p`,{className:q(J.compact,`pt-1`),children:[i,`/`,n.length,` completed`]}),t[6]=i,t[7]=n.length,t[8]=s):s=t[8];let c;return t[9]!==a||t[10]!==o||t[11]!==s?(c=(0,$.jsxs)(`div`,{className:`space-y-1`,children:[a,o,s]}),t[9]=a,t[10]=o,t[11]=s,t[12]=c):c=t[12],c}function Su(e){return(0,$.jsxs)(`div`,{className:q(J.caption,`flex items-start gap-2`),children:[e.status===`done`?(0,$.jsx)(_t,{className:`h-4 w-4 shrink-0 mt-0.5 text-brand`}):e.status===`working`?(0,$.jsx)(rn,{className:`h-4 w-4 shrink-0 mt-0.5 text-yellow-500`}):(0,$.jsx)(Ft,{className:`h-4 w-4 shrink-0 mt-0.5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:e.status===`done`?`line-through text-muted-foreground`:`text-foreground`,children:e.description})]},e.id)}function Cu(e){return e.status===`done`}function wu(e){let t=(0,X.c)(43),{layout:n}=e,r=n===void 0?`bar`:n,{todos:i}=(0,Y.useContext)(Ro),[a,o]=(0,Y.useState)(!1),s;t[0]===i?s=t[1]:(s=i.filter(Tu),t[0]=i,t[1]=s);let c=s.length,l=i.length-c,u=`${c} of ${i.length} complete`;if(l<=0)return null;if(r===`menu`){let e;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>o(!0),t[2]=e):e=t[2];let n;t[3]!==c||t[4]!==i.length?(n=(0,$.jsx)(gu,{completedCount:c,totalCount:i.length}),t[3]=c,t[4]=i.length,t[5]=n):n=t[5];let r;t[6]===u?r=t[7]:(r=(0,$.jsx)(`span`,{children:u}),t[6]=u,t[7]=r);let s;t[8]!==n||t[9]!==r?(s=(0,$.jsxs)(U,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,onClick:e,children:[n,r]}),t[8]=n,t[9]=r,t[10]=s):s=t[10];let l;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(xt,{children:(0,$.jsx)(z,{children:`Agent Todos`})}),t[11]=l):l=t[11];let d;t[12]===i?d=t[13]:(d=(0,$.jsxs)(H,{className:`max-w-md`,children:[l,(0,$.jsx)(xu,{todos:i})]}),t[12]=i,t[13]=d);let f;t[14]!==a||t[15]!==d?(f=(0,$.jsx)(g,{open:a,onOpenChange:o,children:d}),t[14]=a,t[15]=d,t[16]=f):f=t[16];let p;return t[17]!==s||t[18]!==f?(p=(0,$.jsxs)($.Fragment,{children:[s,f]}),t[17]=s,t[18]=f,t[19]=p):p=t[19],p}let d;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(d=()=>o(!0),t[20]=d):d=t[20];let f;t[21]!==c||t[22]!==i.length?(f=(0,$.jsx)(gu,{completedCount:c,totalCount:i.length}),t[21]=c,t[22]=i.length,t[23]=f):f=t[23];let p;t[24]===u?p=t[25]:(p=(0,$.jsx)(`span`,{className:`sr-only`,children:u}),t[24]=u,t[25]=p);let m;t[26]!==f||t[27]!==p?(m=(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(U,{variant:`ghost`,size:`icon`,className:`ml-2 rounded-full [&_svg]:!size-10`,onClick:d,children:[f,p]})}),t[26]=f,t[27]=p,t[28]=m):m=t[28];let h;t[29]===u?h=t[30]:(h=(0,$.jsx)(K,{children:u}),t[29]=u,t[30]=h);let _;t[31]!==m||t[32]!==h?(_=(0,$.jsx)(Nt,{children:(0,$.jsxs)(W,{children:[m,h]})}),t[31]=m,t[32]=h,t[33]=_):_=t[33];let v;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(xt,{children:(0,$.jsx)(z,{children:`Agent Todos`})}),t[34]=v):v=t[34];let y;t[35]===i?y=t[36]:(y=(0,$.jsxs)(H,{className:`max-w-md`,children:[v,(0,$.jsx)(xu,{todos:i})]}),t[35]=i,t[36]=y);let b;t[37]!==a||t[38]!==y?(b=(0,$.jsx)(g,{open:a,onOpenChange:o,children:y}),t[37]=a,t[38]=y,t[39]=b):b=t[39];let x;return t[40]!==b||t[41]!==_?(x=(0,$.jsxs)($.Fragment,{children:[_,b]}),t[40]=b,t[41]=_,t[42]=x):x=t[42],x}function Tu(e){return e.status===`done`}function Eu(e){let t=(0,X.c)(30),{tasks:n,disabled:r,onSelectTask:i,onRemoveTask:a,layout:o}=e,s=r===void 0?!1:r,c=o===void 0?`bar`:o,[l,u]=(0,Y.useState)(!1),d=n.length,f=`${d} Pending ${d===1?`Task`:`Tasks`}`;if(d===0)return null;let p;t[0]===i?p=t[1]:(p=function(e){i(e),u(!1)},t[0]=i,t[1]=p);let m=p,h;t[2]!==a||t[3]!==d?(h=function(e){a(e),d===1&&u(!1)},t[2]=a,t[3]=d,t[4]=h):h=t[4];let g=h,_=c===`menu`?`ghost`:`outline`,v=c===`bar`&&`bg-background`,y=c===`menu`&&`w-full justify-start`,b;t[5]!==v||t[6]!==y?(b=q(`gap-2`,v,y),t[5]=v,t[6]=y,t[7]=b):b=t[7];let x;t[8]===f?x=t[9]:(x=(0,$.jsx)(`span`,{children:f}),t[8]=f,t[9]=x);let S;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(Rt,{className:`h-4 w-4 shrink-0`}),t[10]=S):S=t[10];let C;t[11]!==s||t[12]!==_||t[13]!==b||t[14]!==x?(C=(0,$.jsx)(To,{asChild:!0,children:(0,$.jsxs)(U,{variant:_,size:`sm`,className:b,disabled:s,children:[x,S]})}),t[11]=s,t[12]=_,t[13]=b,t[14]=x,t[15]=C):C=t[15];let w;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(`div`,{className:q(J.compact,J.label,`px-2 pb-1 pt-1 text-muted-foreground`),children:`Tasks`}),t[16]=w):w=t[16];let T;if(t[17]!==g||t[18]!==m||t[19]!==n){let e;t[21]!==g||t[22]!==m?(e=e=>(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-transparent px-2 py-2 hover:bg-accent`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-start gap-2 text-left`,onClick:()=>m(e),children:[(0,$.jsx)(Pt,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:q(J.body,`line-clamp-3 text-foreground`),children:e.content})]}),(0,$.jsxs)(U,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:()=>g(e.id),children:[(0,$.jsx)(j,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Remove task`})]})]},e.id),t[21]=g,t[22]=m,t[23]=e):e=t[23],T=n.map(e),t[17]=g,t[18]=m,t[19]=n,t[20]=T}else T=t[20];let E;t[24]===T?E=t[25]:(E=(0,$.jsx)(Eo,{align:`start`,className:`w-96 p-2`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[w,T]})}),t[24]=T,t[25]=E);let D;return t[26]!==l||t[27]!==C||t[28]!==E?(D=(0,$.jsxs)(wo,{open:l,onOpenChange:u,children:[C,E]}),t[26]=l,t[27]=C,t[28]=E,t[29]=D):D=t[29],D}var Du=(0,Y.createContext)(void 0);function Ou(e){let t=(0,X.c)(24),{children:n}=e,r=yi(),i=Q(Mu),a=Q(ju),o=Q(Au),s=Q(ku),{toast:c}=Li(),l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=[],t[0]=l):l=t[0];let[u,d]=(0,Y.useState)(l),f=s?.threadId===i,p=o||f,m,h;t[1]!==i||t[2]!==c?(m=()=>{if(!i){d([]);return}let e=!1;return(async function(){try{let t=await de(i);e||d(t)}catch(t){e||(console.error(`Failed to load user tasks:`,t),c({title:`Could not load tasks`,description:`Failed to load UserTasks for this thread.`,variant:`destructive`}))}})(),()=>{e=!0}},h=[i,c],t[1]=i,t[2]=c,t[3]=m,t[4]=h):(m=t[3],h=t[4]),(0,Y.useEffect)(m,h);let g;t[5]!==r||t[6]!==i?(g=async function(){if(i)try{let e=await ct(i);r({type:Z.ClearMessages}),console.log(`New conversation started:`,e),setTimeout(()=>{(async()=>{try{let e=await at(i);r({type:Z.SetMessages,messages:e.messages})}catch(e){console.error(`Failed to refresh chat history after starting new chat:`,e)}})()},0)}catch(e){console.error(`Failed to start new chat:`,e)}},t[5]=r,t[6]=i,t[7]=g):g=t[7];let _=g,v;t[8]!==i||t[9]!==c?(v=async function(e){if(i)try{await _e(i,e),d(t=>t.filter(t=>t.id!==e))}catch(e){console.error(`Failed to delete user task:`,e),c({title:`Could not remove task`,description:`Failed to delete the selected task.`,variant:`destructive`})}},t[8]=i,t[9]=c,t[10]=v):v=t[10];let y=v,b;t[11]!==r||t[12]!==i?(b=function(e){i&&r({type:Z.SetChatInputDraft,threadId:i,draft:e.content})},t[11]=r,t[12]=i,t[13]=b):b=t[13];let x=b,S;t[14]!==p||t[15]!==_||t[16]!==y||t[17]!==x||t[18]!==a||t[19]!==u?(S={userTasks:u,setUserTasks:d,handleNewChat:_,handleSelectUserTask:x,handleRemoveUserTask:y,effectiveIsStreaming:p,isCreatingProject:a},t[14]=p,t[15]=_,t[16]=y,t[17]=x,t[18]=a,t[19]=u,t[20]=S):S=t[20];let C;return t[21]!==n||t[22]!==S?(C=(0,$.jsx)(Du.Provider,{value:S,children:n}),t[21]=n,t[22]=S,t[23]=C):C=t[23],C}function ku(e){return e.pendingChatMessage}function Au(e){return e.isStreaming}function ju(e){return e.isCreatingProject}function Mu(e){return e.selectedThreadId}function Nu(){let e=(0,Y.useContext)(Du);if(e===void 0)throw Error(`useChatInputToolbar must be used within a ChatInputToolbarProvider`);return e}var Pu=function({workspaceEntries:e,hasMultipleWorkspaces:t,runningScripts:n,onScriptClick:r}){return t?e.map(([e,t])=>(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`div`,{className:`px-2 py-1 text-xs font-medium text-muted-foreground`,children:e}),t.map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent`,onClick:()=>{r(e)},children:[n.has(e.name)?(0,$.jsx)(_,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))]},e)):e[0]?.[1].map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent`,onClick:()=>{r(e)},children:[n.has(e.name)?(0,$.jsx)(_,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))};function Fu({workspaceEntries:e,hasMultipleWorkspaces:t,runningScripts:n,onScriptClick:r}){return t?e.map(([e,t])=>(0,$.jsxs)(ds,{children:[(0,$.jsx)(fs,{children:e}),(0,$.jsx)(ps,{className:`max-h-[min(400px,80vh)] overflow-y-auto`,children:t.map(e=>(0,$.jsxs)(hs,{onClick:()=>{r(e)},className:`gap-2`,children:[n.has(e.name)?(0,$.jsx)(_,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))})]},e)):e[0]?.[1].map(e=>(0,$.jsxs)(hs,{onClick:()=>{r(e)},className:`gap-2`,children:[n.has(e.name)?(0,$.jsx)(_,{className:`h-3 w-3 animate-spin shrink-0`}):(0,$.jsx)(`div`,{className:`h-3 w-3 shrink-0`}),e.friendlyName]},e.name))}function Iu({threadId:e,layout:t=`bar`}){let n=yi(),{setTerminalNotification:r}=Fa(),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(new Set),c=(0,Y.useRef)(new Map);(0,Y.useEffect)(()=>((async()=>{try{let t=await Ye(e);if(t.length===0){a(null);return}a(t),s(new Set(t.filter(e=>e.isRunning).map(e=>e.name)))}catch{a(null)}})(),()=>{for(let e of c.current.values())e.abort();c.current.clear()}),[e]);let l=async t=>{if(o.has(t.name)){let r=c.current.get(t.name);r&&(r.abort(),c.current.delete(t.name));try{await pt(e,t.name)}catch{}n({type:Z.AppendTerminalLine,threadId:e,line:{type:`system`,content:`■ ${t.friendlyName} stopped`}}),s(e=>{let n=new Set(e);return n.delete(t.name),n})}else{let i=new AbortController;c.current.set(t.name,i),s(e=>new Set([...e,t.name])),r(!0),n({type:Z.AppendTerminalLine,threadId:e,line:{type:`system`,content:`▶ ${t.friendlyName}`}});try{let r=await Xt(e,t.name,t.command,{signal:i.signal});if(r){let t=r.getReader(),i=new TextDecoder,a=``;try{for(;;){let{done:r,value:o}=await t.read();if(r)break;a+=i.decode(o,{stream:!0});let s=a.split(`
50
- `);a=s.pop()??``;for(let t of s)if(t.trim())try{let r=JSON.parse(t);typeof r==`string`?n({type:Z.AppendTerminalLine,threadId:e,line:{type:`output`,content:r}}):r.type===`error`&&n({type:Z.AppendTerminalLine,threadId:e,line:{type:`error`,content:r.message}})}catch{n({type:Z.AppendTerminalLine,threadId:e,line:{type:`output`,content:t}})}}if(a.trim())try{let t=JSON.parse(a);typeof t==`string`?n({type:Z.AppendTerminalLine,threadId:e,line:{type:`output`,content:t}}):t.type===`error`&&n({type:Z.AppendTerminalLine,threadId:e,line:{type:`error`,content:t.message}})}catch{n({type:Z.AppendTerminalLine,threadId:e,line:{type:`output`,content:a}})}}finally{t.releaseLock()}}n({type:Z.AppendTerminalLine,threadId:e,line:{type:`system`,content:`✓ ${t.friendlyName} done`}})}catch{}finally{c.current.delete(t.name),s(e=>{let n=new Set(e);return n.delete(t.name),n})}}};if(!i)return null;let u=i.reduce((e,t)=>(e[t.workspace]||(e[t.workspace]=[]),e[t.workspace].push(t),e),{}),d=Object.entries(u).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,[...t].sort((e,t)=>e.friendlyName.localeCompare(t.friendlyName))]),f=d.length>1;function p(e){l(e)}return t===`menu`?(0,$.jsxs)(wo,{children:[(0,$.jsx)(To,{asChild:!0,children:(0,$.jsxs)(U,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,children:[(0,$.jsx)(ht,{className:`h-4 w-4 shrink-0`}),`Project Scripts`]})}),(0,$.jsx)(Eo,{align:`start`,className:`w-56 p-1`,children:(0,$.jsx)(Pu,{workspaceEntries:d,hasMultipleWorkspaces:f,runningScripts:o,onScriptClick:p})})]}):(0,$.jsxs)(ls,{children:[(0,$.jsx)(Nt,{children:(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(us,{asChild:!0,children:(0,$.jsx)(U,{variant:`action`,size:`icon-md`,children:(0,$.jsx)(ht,{})})})}),(0,$.jsx)(K,{children:`Project Scripts`})]})}),(0,$.jsx)(ms,{align:`end`,className:`min-w-[180px]`,children:(0,$.jsx)(Fu,{workspaceEntries:d,hasMultipleWorkspaces:f,runningScripts:o,onScriptClick:p})})]})}var Lu=`Play.Square.RotateCcw.Terminal.Bug.TestTube.FlaskConical.Wrench.Hammer.Zap.Search.FileCode.Code2.History.Settings.Activity.Cpu.Server.Database.Package.Box.GitBranch.Layers.ExternalLink.Eye.Shield.Flag.Star.Monitor.Smartphone`.split(`.`);function Ru({open:e,onOpenChange:t,projectId:n,commands:r,onRefresh:i}){let[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)([]),[p,m]=(0,Y.useState)(0),[h,_]=(0,Y.useState)(!1),v=(0,Y.useRef)(null),y=(0,Y.useRef)(null),x=()=>{o({id:crypto.randomUUID(),name:``,icon:`Play`,commandLine:``}),u(!1),f([])},S=e=>{o({...e}),u(!1),f([])},C=async()=>{try{_(!0);let e=await dn(n);f(e.scripts),m(0),u(e.scripts.length>0)}catch(e){console.error(`Failed to load package scripts:`,e),Ii({title:`Error`,description:`Failed to load package scripts`,variant:`destructive`})}finally{_(!1)}},w=e=>{o(t=>t?{...t,name:e.name,commandLine:e.commandLine,relativeFolder:e.relativePath||``}:null),u(!1),f([]),v.current?.focus()},T=e=>{l&&(e.key===`ArrowDown`?(e.preventDefault(),m(e=>e<d.length-1?e+1:e)):e.key===`ArrowUp`?(e.preventDefault(),m(e=>e>0?e-1:0)):e.key===`Enter`?(e.preventDefault(),p<d.length&&w(d[p])):e.key===`Escape`&&(e.preventDefault(),u(!1),f([])))};(0,Y.useEffect)(()=>{let e=e=>{y.current&&!y.current.contains(e.target)&&(u(!1),f([]))};return l&&document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[l]);let E=async e=>{try{await vt(n,e),Ii({title:`Success`,description:`Command deleted`}),i()}catch{Ii({title:`Error`,description:`Failed to delete command`,variant:`destructive`})}};return(0,$.jsx)(g,{open:e,onOpenChange:t,children:(0,$.jsxs)(H,{className:`sm:max-w-[500px]`,children:[(0,$.jsxs)(xt,{children:[(0,$.jsx)(z,{children:`Project Commands`}),(0,$.jsx)(Ct,{children:`Manage custom commands for this project.`})]}),(0,$.jsx)(`div`,{className:`py-4 flex flex-col gap-4`,children:a?(0,$.jsxs)(`div`,{className:`p-4 border rounded-lg bg-muted/30 flex flex-col gap-4 animate-in slide-in-from-top-2`,children:[(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(yn,{htmlFor:`name`,children:`Command Name`}),(0,$.jsx)(b,{id:`name`,value:a.name,onChange:e=>o({...a,name:e.target.value}),placeholder:`e.g. Run Tests`,autoComplete:`off`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2 relative`,children:[(0,$.jsx)(yn,{htmlFor:`commandLine`,children:`Command Line`}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Si,{ref:v,id:`commandLine`,value:a.commandLine,onChange:e=>o({...a,commandLine:e.target.value}),onKeyDown:T,placeholder:`e.g. npm test`,className:`font-mono text-base min-h-[100px] resize-none pr-10`}),(0,$.jsx)(Nt,{children:(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(U,{type:`button`,variant:`ghost`,size:`icon`,className:`absolute right-2 top-2 h-6 w-6 text-muted-foreground transition-colors`,onClick:()=>void C(),disabled:h,children:(0,$.jsx)(Tt,{className:`h-4 w-4`})})}),(0,$.jsx)(K,{children:(0,$.jsx)(`p`,{children:`Discover package scripts`})})]})})]}),l&&(0,$.jsx)(`div`,{ref:y,className:`absolute bottom-full left-0 right-0 mb-2 max-h-60 overflow-y-auto rounded-lg border border-border bg-popover shadow-lg z-50`,children:(0,$.jsxs)(`div`,{className:`p-2`,children:[(0,$.jsxs)(`div`,{className:q(J.dropdownGroupHeading,`px-2 py-1.5 border-b border-border/50 mb-1 flex items-center gap-2`),children:[(0,$.jsx)(Tt,{className:`h-3 w-3`}),`Available Scripts `,h&&`(loading...)`]}),d.length>0?(()=>{let e={};d.forEach(t=>{e[t.relativePath]||(e[t.relativePath]=[]),e[t.relativePath].push(t)});let t=Object.keys(e).sort(),n=0;return t.map(t=>{let r=e[t].sort((e,t)=>e.name.localeCompare(t.name));return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:q(J.dropdownGroupHeading,`px-3 py-1.5 text-muted-foreground/70 bg-muted/30`),children:t}),r.map(e=>{let t=n===p;return n++,(0,$.jsxs)(`button`,{type:`button`,className:q(`flex w-full flex-col gap-1 rounded-lg mx-1 px-3 py-2 text-left transition-colors`,t?`bg-accent text-accent-foreground`:`text-popover-foreground hover:bg-accent/50`),onClick:()=>w(e),onMouseEnter:()=>m(n-1),children:[(0,$.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:q(J.caption,`font-mono`),children:e.commandLine})]},e.commandLine)})]},t)})})():(0,$.jsx)(`div`,{className:q(J.caption,`px-3 py-4 text-center`),children:h?`Loading scripts...`:`No package scripts found`})]})})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(yn,{htmlFor:`relativeFolder`,children:`Relative Folder`}),(0,$.jsx)(b,{id:`relativeFolder`,value:a.relativeFolder??``,onChange:e=>o({...a,relativeFolder:e.target.value}),placeholder:`e.g. frontend, packages/api (optional)`,autoComplete:`off`}),(0,$.jsx)(`p`,{className:J.bodyMuted,children:`Folder path relative to project root where the command will be executed. Leave empty to run from project root.`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(yn,{children:`Icon`}),(0,$.jsx)(Nt,{children:(0,$.jsx)(`div`,{className:`grid grid-cols-10 gap-1 p-2 bg-background rounded-md border border-border`,children:Lu.map(e=>{let t=le[e]||Zt;return(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(U,{variant:a.icon===e?`default`:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>o({...a,icon:e}),children:(0,$.jsx)(t,{className:`h-4 w-4`})})}),(0,$.jsx)(K,{children:e})]},e)})})})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2 mt-2`,children:[(0,$.jsxs)(U,{variant:`ghost`,size:`sm`,onClick:()=>o(null),children:[(0,$.jsx)(j,{className:`h-4 w-4 mr-2`}),` Cancel`]}),(0,$.jsxs)(U,{size:`sm`,onClick:async()=>{if(!a?.name||!a?.commandLine){Ii({title:`Error`,description:`Name and Command Line are required`,variant:`destructive`});return}try{c(!0),await gt(n,a),Ii({title:`Success`,description:`Command saved`}),o(null),i()}catch{Ii({title:`Error`,description:`Failed to save command`,variant:`destructive`})}finally{c(!1)}},disabled:s,children:[(0,$.jsx)(ln,{className:`h-4 w-4 mr-2`}),` `,s?`Saving...`:`Save Command`]})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 max-h-[400px] overflow-y-auto pr-2`,children:[r.length===0&&(0,$.jsx)(`div`,{className:`text-center py-8 text-muted-foreground border-2 border-dashed rounded-lg`,children:`No commands defined yet.`}),r.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-3 rounded-md border border-border bg-card hover:bg-muted/50 cursor-pointer group transition-colors`,onClick:()=>S(e),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`p-2 bg-muted rounded`,children:(0,$.jsx)(le[e.icon]||$e,{className:`h-4 w-4`})}),(0,$.jsxs)(`div`,{className:`flex flex-col`,children:[(0,$.jsx)(`span`,{className:J.label,children:e.name}),(0,$.jsx)(`span`,{className:q(J.caption,`line-clamp-1 font-mono`),children:e.commandLine})]})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,$.jsx)(U,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground hover:bg-destructive hover:text-destructive-foreground transition-colors`,onClick:t=>{t.stopPropagation(),E(e.id)},children:(0,$.jsx)(De,{className:`h-4 w-4`})})})]},e.id))]}),(0,$.jsxs)(U,{variant:`outline`,className:`w-full border-dashed`,onClick:x,children:[(0,$.jsx)(sn,{className:`h-4 w-4 mr-2`}),` Add New Command`]})]})})]})})}function zu(e){let t=(0,X.c)(36),{layout:n}=e,r=n===void 0?`bar`:n,i=Q(Uu),a=Q(Hu),o=Q(Vu),s=Q(Bu),{dispatch:c}=xi(a),[l,u]=(0,Y.useState)(!1),d,f,p,m,h;if(t[0]!==c||t[1]!==s||t[2]!==r||t[3]!==o||t[4]!==i||t[5]!==a||t[6]!==l){h=Symbol.for(`react.early_return_sentinel`);bb0:{let e;t[12]===i?e=t[13]:(e=e=>e.projectId===i,t[12]=i,t[13]=e),d=o.find(e)?.commands??[];let n;t[14]!==c||t[15]!==i||t[16]!==a?(n=e=>{!i||!a||c({type:Z.QueueTerminalCommand,threadId:a,command:e.commandLine,relativeFolder:e.relativeFolder})},t[14]=c,t[15]=i,t[16]=a,t[17]=n):n=t[17];let g=n,_;if(t[18]===c?_=t[19]:(_=async()=>{c({type:Z.ConfigUpdated})},t[18]=c,t[19]=_),f=_,!i){h=null;break bb0}if(r===`menu`){let e;t[20]!==g||t[21]!==s?(e=e=>(0,$.jsxs)(U,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,onClick:()=>g({commandLine:e.commandLine,relativeFolder:e.relativeFolder}),disabled:s,children:[(0,$.jsx)(le[e.icon]||$e,{className:`h-4 w-4 shrink-0`}),e.name]},e.id),t[20]=g,t[21]=s,t[22]=e):e=t[22];let n,r;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>u(!0),n=(0,$.jsx)(rt,{className:`h-4 w-4 shrink-0`}),t[23]=n,t[24]=r):(n=t[23],r=t[24]);let a=d.length===0?`Project Commands`:`Manage commands`,o;t[25]===a?o=t[26]:(o=(0,$.jsxs)(U,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,onClick:r,children:[n,a]}),t[25]=a,t[26]=o),h=(0,$.jsxs)($.Fragment,{children:[d.map(e),o,(0,$.jsx)(Ru,{open:l,onOpenChange:u,projectId:i,commands:d,onRefresh:f})]});break bb0}p=`flex items-center gap-1`,m=d.length===0?(0,$.jsx)(Nt,{children:(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(U,{variant:`action`,size:`icon-md`,onClick:()=>u(!0),children:(0,$.jsx)(rt,{})})}),(0,$.jsx)(K,{children:`Manage commands`})]})}):(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(Nt,{children:[d.map(e=>(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(U,{variant:`action`,size:`icon-md`,onClick:()=>g({commandLine:e.commandLine,relativeFolder:e.relativeFolder}),disabled:s,children:(0,$.jsx)(le[e.icon]||$e,{})})}),(0,$.jsx)(K,{children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 font-mono whitespace-pre-wrap max-w-[300px] max-h-[100px] overflow-y-auto`,children:e.commandLine})]})})]},e.id)),(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(U,{variant:`action`,size:`icon-md`,className:`ml-1`,onClick:()=>u(!0),children:(0,$.jsx)(rt,{})})}),(0,$.jsx)(K,{children:`Manage commands`})]})]})})}t[0]=c,t[1]=s,t[2]=r,t[3]=o,t[4]=i,t[5]=a,t[6]=l,t[7]=d,t[8]=f,t[9]=p,t[10]=m,t[11]=h}else d=t[7],f=t[8],p=t[9],m=t[10],h=t[11];if(h!==Symbol.for(`react.early_return_sentinel`))return h;let g;t[27]!==d||t[28]!==f||t[29]!==i||t[30]!==l?(g=(0,$.jsx)(Ru,{open:l,onOpenChange:u,projectId:i,commands:d,onRefresh:f}),t[27]=d,t[28]=f,t[29]=i,t[30]=l,t[31]=g):g=t[31];let _;return t[32]!==p||t[33]!==m||t[34]!==g?(_=(0,$.jsxs)(`div`,{className:p,children:[m,g]}),t[32]=p,t[33]=m,t[34]=g,t[35]=_):_=t[35],_}function Bu(e){return e.isRunningCommand}function Vu(e){return e.projects}function Hu(e){return e.selectedThreadId}function Uu(e){return e.selectedProjectId}var Wu=`VS Code`;function Gu(e){return e||r(Wu)}var Ku={"VS Code":`vscode`,Antigravity:`antigravity`,Cursor:`cursor`,"Devin Desktop":`devin`,Windsurf:`windsurf`,Xcode:`xcode`,"Android Studio":`android-studio`,Kiro:`kiro`,Terminal:`terminal`};function qu({projectId:e,threadId:n,openWith:i,layout:a=`bar`}){let[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)([]),[u,d]=(0,Y.useState)(()=>Gu(i)),[f,p]=(0,Y.useState)(!0);(0,Y.useEffect)(()=>{(async()=>{try{let e=await t();l(e);let n=Gu(i);e.includes(n)?d(n):e.length>0&&d(e[0])}catch(e){console.error(`Failed to fetch available programs:`,e),l([Wu])}finally{p(!1)}})()},[]),(0,Y.useEffect)(()=>{if(i&&c.includes(i)){d(i);return}let e=r(Wu);!i&&c.includes(e)&&d(e)},[i,c]);async function m(t){d(t),tn(t),await y(e,t)}let h=async t=>{try{s(!0),await m(t),n?await Ve(n,t):await Fe(e,t),Ii({title:`Success`,description:`Opened project in ${t}`})}catch(e){console.error(`Failed to open project in ${t}:`,e);let n=`Failed to open project in ${t}`;if(e instanceof Error){let t=e;n=t.details?t.details:e.message}Ii({title:`Error`,description:n,variant:`destructive`})}finally{s(!1)}};async function g(e){try{await m(e)}catch(t){console.error(`Failed to save preferred IDE (${e}):`,t),Ii({title:`Error`,description:`Failed to save IDE preference`,variant:`destructive`})}}let _=async()=>{await h(u)};return f?(0,$.jsx)(U,{variant:`outline`,size:`sm`,className:`h-8`,disabled:!0,children:(0,$.jsx)(`div`,{className:`h-4 w-4 animate-pulse bg-muted rounded`})}):a===`menu`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(U,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,disabled:o,onClick:()=>{_()},children:[(0,$.jsx)(`img`,{src:`/ide/${Ku[u]||Ku[Wu]}.svg`,alt:u,className:`h-4 w-4 shrink-0`}),`Open in `,u]}),(0,$.jsxs)(wo,{children:[(0,$.jsx)(To,{asChild:!0,children:(0,$.jsxs)(U,{variant:`ghost`,size:`sm`,className:`w-full justify-start gap-2`,children:[(0,$.jsx)(Tt,{className:`h-4 w-4 shrink-0`}),`Change IDE`]})}),(0,$.jsx)(Eo,{align:`start`,className:`w-56 p-1`,children:c.map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent disabled:opacity-50`,onClick:()=>{g(e)},disabled:o,children:[(0,$.jsx)(`img`,{src:`/ide/${Ku[e]||Ku[Wu]}.svg`,alt:e,className:`h-4 w-4 shrink-0`}),e]},e))})]})]}):(0,$.jsxs)(`div`,{className:`flex items-center gap-0`,children:[(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(U,{variant:`outline`,size:`sm`,className:`h-8 rounded-r-none border-r-0 border-transparent`,disabled:o,onClick:_,children:(0,$.jsx)(`img`,{src:`/ide/${Ku[u]||Ku[Wu]}.svg`,alt:u,className:`h-4 w-4`})})}),(0,$.jsx)(K,{children:`Open in ${u}`})]}),(0,$.jsxs)(ls,{children:[(0,$.jsx)(us,{asChild:!0,children:(0,$.jsx)(U,{variant:`outline`,size:`sm`,className:`h-8 w-8 rounded-l-none px-1 border-transparent`,disabled:o,children:(0,$.jsx)(Tt,{className:`h-3.5 w-3.5`})})}),(0,$.jsx)(ms,{align:`end`,children:c.map(e=>(0,$.jsxs)(hs,{onClick:()=>void g(e),disabled:o,className:`flex items-center gap-2`,children:[(0,$.jsx)(`img`,{src:`/ide/${Ku[e]||Ku[Wu]}.svg`,alt:e,className:`h-4 w-4`}),e]},e))})]})]})}var Ju=Cr(e=>(0,$.jsxs)(`button`,{onClick:e.v0,disabled:e.v1,className:e.v2,children:[e.v3,(0,$.jsx)(`span`,{className:e.v4,children:e.v5})]}),{name:`RunStopButton_1`,portals:[`v3`,`v5`]}),Yu=Cr(e=>e.v0,{name:`RunStopButton_2`,portals:[`v0`]}),Xu=Cr(e=>(0,$.jsx)(`slot`,{children:e.v0}),{name:`RunStopButton_3`,portals:[`v0`]}),Zu=function({projectId:e,runCommand:t,large:n,layout:r=`bar`}){let{dispatch:i}=xi(Q(e=>e.selectedThreadId)),{setDevServerUrl:a,devServerRunning:o,setDevServerRunning:s,devServerLoading:c,setDevServerLoading:l}=Fa(),{startServer:u}=lc(),d=(0,Y.useRef)(!1);(0,Y.useEffect)(()=>{(async()=>{try{s((await Jt(e)).isRunning)}catch{s(!1)}})()},[e]);let f=()=>{u({projectId:e,runCommand:t||``})},p=async()=>{d.current=!0,l(!0);try{await jt(e),s(!1),a(null),i({type:Z.AppendTerminalLine,line:{type:`system`,content:`Server stopped`}})}catch(e){let t=e instanceof Error?e.message:`Failed to stop dev server`;i({type:Z.AppendTerminalLine,line:{type:`error`,content:t}}),Ii({title:`Error`,description:t,variant:`destructive`})}finally{l(!1)}},m=!!t,h=c?`Starting...`:o?`Stop dev server`:`Start dev server`;return n?(0,$.jsx)(Ju,{v0:o?p:f,v1:c||!o&&!m,v2:`flex flex-col items-center gap-3 group disabled:opacity-40 disabled:cursor-not-allowed ${o?`text-orange-500`:`text-muted-foreground`}`,v3:c?(0,$.jsx)(_,{className:`h-10 w-10 animate-spin`}):o?(0,$.jsx)(Le,{className:`h-10 w-10 fill-current`}):(0,$.jsx)($e,{className:`h-10 w-10 fill-current group-hover:text-foreground transition-colors`}),v4:q(J.body,`group-hover:text-foreground transition-colors`),v5:h}):r===`menu`?(0,$.jsx)(Yu,{v0:(0,$.jsxs)(U,{variant:`ghost`,size:`sm`,className:q(`w-full justify-start gap-2`,o&&`text-orange-500`),onClick:o?p:f,disabled:c||!o&&!m,children:[c?(0,$.jsx)(_,{className:`h-4 w-4 shrink-0 animate-spin`}):o?(0,$.jsx)(Le,{className:`h-4 w-4 shrink-0 fill-current`}):(0,$.jsx)($e,{className:`h-4 w-4 shrink-0`}),h]})}):(0,$.jsx)(Xu,{v0:(0,$.jsx)(Nt,{children:(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(U,{variant:`ghost`,size:`icon`,className:`h-8 w-8 ${o?`text-orange-500 bg-orange-500/10`:`text-muted-foreground`}`,onClick:o?p:f,disabled:c||!o&&!m,children:[c?(0,$.jsx)(_,{className:`h-4 w-4 animate-spin`}):o?(0,$.jsx)(Le,{className:`h-4 w-4 fill-current`}):(0,$.jsx)($e,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:o?`Stop dev server`:`Start dev server`})]})}),(0,$.jsx)(K,{children:o?`Stop dev server`:m?`Start dev server: ${t}`:`Set run command in project settings`})]})})})},Qu=(0,Y.lazy)(()=>pr(()=>import(`./git-ops-button-1lum9QXI.js`).then(e=>({default:e.GitOpsButton})),__vite__mapDeps([2,1,3,4,5])));function $u(e){return e===`menu`?`w-full justify-start gap-2`:`gap-2`}function ed(e){let t=(0,X.c)(4),{threadId:n,projectId:r,messages:i,userTasks:a}=e,{hasChanges:o}=lu(),s=i.length>0,c=!!n&&(s||o||a.length>0||!!(n&&r)),l;return t[0]!==o||t[1]!==s||t[2]!==c?(l={isVisible:c,hasMessages:s,hasChanges:o},t[0]=o,t[1]=s,t[2]=c,t[3]=l):l=t[3],l}function td(e){let t=(0,X.c)(60),{threadId:n,projectId:r,messages:i,userTasks:a,effectiveIsStreaming:o,isCreatingProject:s,onNewChat:c,onSelectUserTask:l,onRemoveUserTask:u,layout:d}=e,f=d===void 0?`bar`:d,{setActiveMainTab:p}=Fa(),m;t[0]!==i||t[1]!==r||t[2]!==n||t[3]!==a?(m={threadId:n,projectId:r,messages:i,userTasks:a},t[0]=i,t[1]=r,t[2]=n,t[3]=a,t[4]=m):m=t[4];let{hasMessages:h,hasChanges:g,isVisible:_}=ed(m),{changedFilesCount:v}=lu(),y;t[5]===f?y=t[6]:(y=$u(f),t[5]=f,t[6]=y);let b=y,x=Q(nd),S;if(t[7]!==r||t[8]!==x){let e;t[10]===r?e=t[11]:(e=e=>e.projectId===r,t[10]=r,t[11]=e),S=x.find(e),t[7]=r,t[8]=x,t[9]=S}else S=t[9];let C=S,w=f===`menu`&&!!n&&!!r,T=h||g||a.length>0||!!(n&&r);if(!_)return null;let E=f===`bar`&&`absolute -top-12 left-0 z-10 ml-8 flex flex-wrap items-center gap-2`,D=f===`menu`&&`flex flex-col items-stretch gap-1 p-1 min-w-[220px]`,O;t[12]!==E||t[13]!==D?(O=q(E,D),t[12]=E,t[13]=D,t[14]=O):O=t[14];let k=f===`bar`?!0:void 0,A;t[15]!==h||t[16]!==f||t[17]!==c||t[18]!==b?(A=h&&(0,$.jsxs)(U,{variant:f===`menu`?`ghost`:`outline`,size:`sm`,className:b,onClick:c,children:[(0,$.jsx)(sn,{className:`h-4 w-4 shrink-0`}),`New Chat`]}),t[15]=h,t[16]=f,t[17]=c,t[18]=b,t[19]=A):A=t[19];let j;t[20]!==v||t[21]!==g||t[22]!==f||t[23]!==p||t[24]!==b?(j=g&&(0,$.jsxs)(U,{variant:f===`menu`?`ghost`:`outline`,size:`sm`,className:b,onClick:()=>p(`review`),children:[(0,$.jsx)(I,{className:`h-4 w-4 shrink-0`}),v,` `,v===1?`File`:`Files`,` Changed`]}),t[20]=v,t[21]=g,t[22]=f,t[23]=p,t[24]=b,t[25]=j):j=t[25];let M;t[26]!==o||t[27]!==s||t[28]!==f||t[29]!==u||t[30]!==l||t[31]!==n||t[32]!==a?(M=a.length>0&&(0,$.jsx)(Eu,{tasks:a,disabled:o||!n&&!s,onSelectTask:l,onRemoveTask:u,layout:f}),t[26]=o,t[27]=s,t[28]=f,t[29]=u,t[30]=l,t[31]=n,t[32]=a,t[33]=M):M=t[33];let N;t[34]!==f||t[35]!==r||t[36]!==n?(N=n&&r&&(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Qu,{projectId:r,threadId:n,layout:f},n)}),t[34]=f,t[35]=r,t[36]=n,t[37]=N):N=t[37];let P;t[38]!==h||t[39]!==f?(P=h&&(0,$.jsx)(wu,{layout:f}),t[38]=h,t[39]=f,t[40]=P):P=t[40];let F;t[41]!==T||t[42]!==w?(F=w&&T&&(0,$.jsx)(ys,{className:`my-1`}),t[41]=T,t[42]=w,t[43]=F):F=t[43];let L;t[44]!==r||t[45]!==C?.openWith||t[46]!==C?.runCommand||t[47]!==w||t[48]!==n?(L=w&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Zu,{projectId:r,runCommand:C?.runCommand,layout:`menu`}),(0,$.jsx)(Iu,{threadId:n,layout:`menu`}),(0,$.jsx)(zu,{layout:`menu`}),(0,$.jsx)(qu,{projectId:r,threadId:n,openWith:C?.openWith,layout:`menu`})]}),t[44]=r,t[45]=C?.openWith,t[46]=C?.runCommand,t[47]=w,t[48]=n,t[49]=L):L=t[49];let R;return t[50]!==j||t[51]!==M||t[52]!==N||t[53]!==P||t[54]!==F||t[55]!==L||t[56]!==O||t[57]!==k||t[58]!==A?(R=(0,$.jsxs)(`div`,{className:O,"data-chat-toolbar":k,children:[A,j,M,N,P,F,L]}),t[50]=j,t[51]=M,t[52]=N,t[53]=P,t[54]=F,t[55]=L,t[56]=O,t[57]=k,t[58]=A,t[59]=R):R=t[59],R}function nd(e){return e.projects}function rd(e){let t=(0,X.c)(2),n;return t[0]===e?n=t[1]:(n=(0,$.jsx)(td,{...e}),t[0]=e,t[1]=n),n}function id(){let e=(0,X.c)(20),t=Q(sd),n=Q(od),r=Q(ad),{userTasks:i,handleNewChat:a,handleSelectUserTask:o,handleRemoveUserTask:s,effectiveIsStreaming:c,isCreatingProject:l}=Nu(),u;e[0]!==r||e[1]!==n||e[2]!==t||e[3]!==i?(u={threadId:t,projectId:n,messages:r,userTasks:i},e[0]=r,e[1]=n,e[2]=t,e[3]=i,e[4]=u):u=e[4];let{isVisible:d}=ed(u);if(!t||!d)return null;let f;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(us,{asChild:!0,children:(0,$.jsxs)(U,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground shrink-0 md:hidden electrobun-webkit-app-region-no-drag`,children:[(0,$.jsx)(_n,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Chat actions`})]})}),e[5]=f):f=e[5];let p=n??``,m;e[6]===a?m=e[7]:(m=()=>{a()},e[6]=a,e[7]=m);let h;e[8]===s?h=e[9]:(h=e=>{s(e)},e[8]=s,e[9]=h);let g;return e[10]!==c||e[11]!==o||e[12]!==l||e[13]!==r||e[14]!==t||e[15]!==p||e[16]!==m||e[17]!==h||e[18]!==i?(g=(0,$.jsxs)(ls,{children:[f,(0,$.jsx)(ms,{align:`end`,className:`electrobun-webkit-app-region-no-drag`,children:(0,$.jsx)(td,{threadId:t,projectId:p,messages:r,userTasks:i,effectiveIsStreaming:c,isCreatingProject:l,onNewChat:m,onSelectUserTask:o,onRemoveUserTask:h,layout:`menu`})})]}),e[10]=c,e[11]=o,e[12]=l,e[13]=r,e[14]=t,e[15]=p,e[16]=m,e[17]=h,e[18]=i,e[19]=g):g=e[19],g}function ad(e){return e.messages}function od(e){return e.selectedProjectId}function sd(e){return e.selectedThreadId}function cd(e){let t=(0,X.c)(3),{threadId:n,children:r}=e,i;return t[0]!==r||t[1]!==n?(i=(0,$.jsx)(cu,{threadId:n,children:r}),t[0]=r,t[1]=n,t[2]=i):i=t[2],i}var ld=new Set,ud=new Map,dd=5e3;function fd(e){ld.add(e);let t=ud.get(e);t&&clearTimeout(t),ud.set(e,setTimeout(()=>{ld.delete(e),ud.delete(e)},dd))}function pd(e){return ld.has(e)}function md(e){return e.filter(e=>!ld.has(e))}function hd(e,t){if(!(!t||!e.includes(`"run_js"`)))try{let n=JSON.parse(e.trim());if(!Array.isArray(n))return;for(let e of n)e?.type===`tool_use`&&e?.name===`run_js`&&e?.id&&e?.input?.code&&Ns(e.id,e.input.code,t)}catch{}}function gd(e){if(!(!e.includes(`"tool_use"`)||!e.includes(`"bash"`)))try{let t=JSON.parse(e.trim());if(!Array.isArray(t))return;for(let e of t)e?.type===`tool_use`&&e?.id&&typeof e.name==`string`&&e.name.toLowerCase()===`bash`&&typeof e.input?.command==`string`&&ro(e.id,e.input.command)}catch{}}function _d(e){if(!(!e.includes(`"tool-result"`)||!e.includes(`"bash"`)))try{let t=JSON.parse(e.trim());if(!Array.isArray(t))return;for(let e of t)e?.type===`tool-result`&&e?.toolCallId&&typeof e.toolName==`string`&&e.toolName.toLowerCase()===`bash`&&io(e.toolCallId)}catch{}}function vd(e,t,n){let r={type:`thinking`,content:bd,model:n};e({type:Z.SetStreaming,isStreaming:!0,threadId:t}),e({type:Z.SetStreamModel,model:n,threadId:t}),e({type:Z.AppendStreamChunk,chunkType:`thinking`,content:r.content??``,segments:ti([],`thinking`,r.content??``),threadId:t})}var yd=/^\/compact(?:\s+(.*))?$/i,bd=`[Compact] Compaction in progress...`;function xd(){let e=yi(),{toast:t}=Li(),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(null),c=(0,Y.useRef)(null),l=(0,Y.useRef)(new Map),u=Q(e=>e.selectedThreadId),d=Q(e=>e.selectedProjectId),f=Q(e=>e.messages),p=Q(e=>e.queuedChatMessages),m=Q(e=>e.isStreaming),h=Q(e=>e.processingThreadIds),g=Q(e=>e.streamingModel),_=Q(e=>e.threadStreamingStates),v=Q(e=>e.pendingChatMessage);c.current=u;let y=(0,Y.useCallback)((t,n,r)=>{if(l.current.get(t)!==r){l.current.has(t)||(fd(t),e({type:Z.ResetStream,threadId:t}),e({type:Z.RemoveProcessingThread,threadId:t}));return}if(l.current.delete(t),e({type:Z.ClearToolCallProgress}),r.stopHandled)return;if(fd(t),r.error){let i={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Error: ${r.error}`,contentType:`text`,timestamp:new Date().toISOString(),model:n||`default`,isThinking:!1};e({type:Z.AddMessage,message:i,threadId:t}),e({type:Z.ResetStream,threadId:t}),e({type:Z.RemoveProcessingThread,threadId:t});return}let i=ci(r.segments)||`...`,a={messageId:`msg-${Date.now()}-agent`,sender:`agent`,content:i,contentType:`markdown`,timestamp:new Date().toISOString(),model:n||`default`,isThinking:!1};async function o(){for(let n=0;n<4;n++){n>0&&await new Promise(e=>setTimeout(e,150*n));try{let n=await at(t);if(t===c.current){e({type:Z.SetMessages,messages:n.messages});return}}catch(e){console.error(`Failed to reload chat history after stream:`,e);break}}e({type:Z.AddMessage,message:a,threadId:t})}o(),e({type:Z.ResetStream,threadId:t}),e({type:Z.MarkThreadCompleted,threadId:t}),e({type:Z.RemoveProcessingThread,threadId:t})},[e]),b=(0,Y.useCallback)(()=>{if(!u)return;s(u);let t=l.current.get(u);t&&(t.stopHandled=!0,t.controller.abort(),t.cancel?.(),l.current.delete(u)),Wt(u);let n={messageId:`msg-${Date.now()}-stopped`,sender:`agent`,content:`I've stopped working on your request.`,contentType:`text`,timestamp:new Date().toISOString(),model:g||`default`,isThinking:!1};e({type:Z.AddMessage,message:n,threadId:u}),e({type:Z.ClearToolCallProgress}),e({type:Z.ResetStream,threadId:u}),e({type:Z.MarkThreadCompleted,threadId:u}),e({type:Z.RemoveProcessingThread,threadId:u}),fd(u)},[u,e,g]);(0,Y.useEffect)(()=>()=>{for(let[t,n]of l.current.entries())n.controller.abort(),n.cancel?.(),e({type:Z.ResetStream,threadId:t});l.current.clear()},[e]);let x=(0,Y.useCallback)((t,n,i)=>{let o=l.current.get(t);o&&(o.controller.abort(),o.cancel?.());let s=new AbortController,u={controller:s,cancel:null,segments:[],assistantMessage:``,assistantThinking:``,hasStructuredContent:!1,error:null,stopHandled:!1,activeSubagentToolCallId:null};return l.current.set(t,u),e({type:Z.ResetStream,threadId:t}),e({type:Z.SetStreaming,isStreaming:!0,threadId:t}),n(s.signal).then(n=>{if(!n||s.signal.aborted){y(t,i,u);return}u.cancel=ge(n,n=>{if(e({type:Z.IncrementStreamEventCount,threadId:t}),n.type===`error`){let e=n.content?.trim()||n.error?.message?.trim()||n.message?.trim()||`Unknown error occurred`;u.error=e,t===c.current&&r(e);return}if(n.type!==`message`){if(n.type===`long_running_confirmation`){let r=n.prompt;if(!r)return;u.segments=ri(u.segments,r),e({type:Z.AppendStreamChunk,chunkType:`content`,content:``,segments:u.segments,threadId:t});return}if(n.type===`shell_permission`){let r=n.shellPermission;if(!r)return;u.activeSubagentToolCallId&&e({type:Z.AppendToolExecutionOutput,toolCallId:u.activeSubagentToolCallId,toolName:`agent`,delta:`\n⏳ Waiting for shell approval: ${r.command}\n`}),u.segments=ii(u.segments,r),e({type:Z.AppendStreamChunk,chunkType:`content`,content:``,segments:u.segments,threadId:t});return}if(n.type===`web_fetch_permission`){let r=n.webFetchPermission;if(!r)return;u.activeSubagentToolCallId&&e({type:Z.AppendToolExecutionOutput,toolCallId:u.activeSubagentToolCallId,toolName:`agent`,delta:`\n⏳ Waiting for approval to fetch ${r.hostname}\n`}),u.segments=ai(u.segments,r),e({type:Z.AppendStreamChunk,chunkType:`content`,content:``,segments:u.segments,threadId:t});return}if(n.type===`toolcall_delta`){n.partial?.content?.[0]?.id&&n.delta&&e({type:Z.UpdateToolCallProgress,toolCallId:n.partial.content[0].id,progress:{toolCallId:n.partial.content[0].id,toolName:n.partial.content[0].name,delta:n.delta,partial:n.partial}});return}if(n.type===`tool_execution_update`){n.toolCallId&&n.executionOutput!==void 0&&e({type:Z.UpdateToolExecutionOutput,toolCallId:n.toolCallId,toolName:n.toolName,executionOutput:n.executionOutput});return}if(n.type===`subagent_start`){if(n.toolCallId){u.activeSubagentToolCallId=n.toolCallId;let t=n.subagentName?.trim()||`subagent`;e({type:Z.UpdateToolExecutionOutput,toolCallId:n.toolCallId,toolName:`agent`,executionOutput:`Running ${t}…\n`})}return}if(n.type===`subagent_event`){if(n.toolCallId){let t=rs(n);t&&e({type:Z.AppendToolExecutionOutput,toolCallId:n.toolCallId,toolName:`agent`,delta:t})}return}if(n.type===`subagent_complete`){n.toolCallId&&(u.activeSubagentToolCallId=null,n.subagentResult&&e({type:Z.UpdateToolExecutionOutput,toolCallId:n.toolCallId,toolName:`agent`,executionOutput:n.subagentResult}));return}if(n.model&&e({type:Z.SetStreamModel,model:n.model,threadId:t}),n.type===`thinking`||n.isThinking){let r=n.content??``;hd(r,t),u.assistantThinking+=r,u.segments=ti(u.segments,`thinking`,r),e({type:Z.AppendStreamChunk,chunkType:`thinking`,content:r,segments:u.segments,threadId:t})}else if(n.type===`result`){u.hasStructuredContent=!0;let r=n.content??``;u.assistantMessage=r,u.segments=ni(u.segments,r),e({type:Z.SetStreamContent,content:r,threadId:t}),typeof r==`string`&&hd(r,t)}else{if(u.hasStructuredContent)return;let r=n.content??``;u.assistantMessage+=r,u.segments=ti(u.segments,`content`,r),e({type:Z.AppendStreamChunk,chunkType:`content`,content:r,segments:u.segments,threadId:t})}}},()=>{y(t,i,u)},e=>{if(e.includes(`AbortError`)||e.includes(`canceled`)||e.includes(`BodyStreamBuffer was aborted`)){y(t,i,u);return}u.error=e,t===c.current&&r(e)},n=>{if(e({type:Z.IncrementStreamEventCount,threadId:t}),n.role===`assistant`){let r=n.content??``,i=typeof r==`string`?r:JSON.stringify(r);if(n.isThinking??!1){u.assistantThinking+=i,u.segments=ti(u.segments,`thinking`,i),e({type:Z.AppendStreamChunk,chunkType:`thinking`,content:i,segments:u.segments,threadId:t});return}let a=!1;if(typeof r==`object`&&Array.isArray(r)&&r.length>0)a=!0;else if(typeof i==`string`&&i.trim().startsWith(`[`))try{let e=JSON.parse(i);a=Array.isArray(e)&&e.length>0}catch{}a?(u.hasStructuredContent=!0,u.assistantMessage=i,u.segments=ni(u.segments,i),e({type:Z.SetStreamContent,content:i,threadId:t}),hd(i,t)):(u.assistantMessage+=i,u.segments=ti(u.segments,`content`,i),e({type:Z.AppendStreamChunk,chunkType:`content`,content:i,segments:u.segments,threadId:t}))}else if(n.role===`tool`){let r=n.content??``,i=typeof r==`string`?r:JSON.stringify(r);i&&(gd(i),_d(i),u.assistantMessage+=i,u.segments=ti(u.segments,`content`,i),e({type:Z.AppendStreamChunk,chunkType:`content`,content:i,segments:u.segments,threadId:t}))}})}).catch(n=>{if(l.current.delete(t),n instanceof Error&&n.name===`AbortError`){e({type:Z.ResetStream,threadId:t});return}if(n instanceof Qe){e({type:Z.ResetStream,threadId:t}),a(!0);return}if(n instanceof Error&&n.message.includes(`not currently processing`)){e({type:Z.ResetStream,threadId:t});return}let i=n instanceof Error?n.message:`Failed to send message. Please ensure the CLI server is running on localhost:641`;t===c.current&&r(i),console.error(`Failed to subscribe to chat stream:`,n),e({type:Z.ResetStream,threadId:t})}),s},[e,y]);(0,Y.useEffect)(()=>{for(let e of h)l.current.has(e)||_[e]?.isStreaming||pd(e)||x(e,t=>qe(e,t),`default`)},[x,h,_]);let S=(0,Y.useCallback)(async(n,i,a,o,c,l,p)=>{if(!u)return;let g=u;r(null),s(null);let _=n.trim().match(yd);if(_){if(f.filter(e=>e.sender===`agent`).length<2){t({title:`Nothing to compact`,description:`Start a conversation with at least two exchanges first.`});return}if(h.includes(g)||m&&u===g){t({title:`Agent is busy`,description:`Wait for the agent to finish before compacting.`});return}let n=_[1]?.trim();vd(e,g,i);try{let r=await fn(g,{model:i,provider:o,instructions:n});e({type:Z.SetMessages,messages:r.messages}),e({type:Z.ResetStream,threadId:g}),t({title:`Conversation compacted`,description:`${r.messagesBefore} messages → ${r.messagesAfter} summary`})}catch(n){e({type:Z.ResetStream,threadId:g}),t({title:`Compaction failed`,description:n instanceof Error?n.message:`Failed to compact conversation`,variant:`destructive`})}return}let v=`msg-${Date.now()}`,y;try{let e=await ye(g,v);e.success&&e.stashed&&e.checkpointRef&&(y=e.checkpointRef)}catch{}let b={messageId:v,sender:`user`,content:n,contentType:`text`,timestamp:new Date().toISOString(),model:i,attachments:a.map(e=>({fileName:e.fileName,content:e.content,mimeType:e.mimeType})),checkpointRef:y};e({type:Z.AddMessage,message:b,threadId:g});let S=n.trim().replace(/\n/g,` `).slice(0,100);if(d&&(St(g,{title:S}).catch(e=>{console.error(`Failed to update thread title:`,e)}),e({type:Z.UpdateThreadTitle,projectId:d,threadId:g,title:S})),l){let t=o??void 0;if(!t&&typeof i==`string`){let e=i.split(/[:/]/)[0]?.trim();e&&(t=e)}if(!t){let t={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Image generation is not available because no provider is configured for the selected model.`,contentType:`text`,timestamp:new Date().toISOString(),model:i,isThinking:!1};e({type:Z.AddMessage,message:t,threadId:g}),e({type:Z.ResetStream,threadId:g});return}e({type:Z.SetStreaming,isStreaming:!0,threadId:g});try{let r=await Gt(n,i,t,g),a={messageId:`msg-${Date.now()}-agent`,sender:`agent`,content:n,contentType:`text`,timestamp:new Date().toISOString(),model:i,isThinking:!1,generatedImageUrl:r.imageUrl,generatedImageData:r.imageData};e({type:Z.AddMessage,message:a,threadId:g})}catch(t){let n=t instanceof Error?t.message:`Image generation failed`,r={messageId:`msg-${Date.now()}-error`,sender:`agent`,content:`Error: ${n}`,contentType:`text`,timestamp:new Date().toISOString(),model:i,isThinking:!1};e({type:Z.AddMessage,message:r,threadId:g})}finally{e({type:Z.ResetStream,threadId:g})}return}x(g,e=>tt(g,n,i,a,e,o,c,p,y),i)},[u,d,e,x,f,h,m,t]);(0,Y.useEffect)(()=>{let t=v;if(!t||m||t.threadId!==u)return;let n=setTimeout(()=>{e({type:Z.ClearPendingChatMessage}),S(t.message,t.model,[],t.provider)},100);return()=>clearTimeout(n)},[v,m,u,e,S]);let C=(0,Y.useMemo)(()=>u?p.filter(e=>e.threadId===u):[],[u,p]),w=(0,Y.useRef)(!1);return(0,Y.useEffect)(()=>{if(m||!u||C.length===0||w.current)return;let[t]=C;w.current=!0,e({type:Z.RemoveQueuedChatMessage,queuedMessageId:t.id});let n=setTimeout(()=>{S(t.message,t.model,t.attachments,t.provider,t.planMode,t.imageMode,t.ralphMode),w.current=!1},0);return()=>{clearTimeout(n),w.current=!1}},[e,S,m,C,u]),{error:n,setError:r,handleSend:S,handleStop:b,isStreaming:m,selectedThreadId:u,queuedMessagesForThread:C,handleRemoveQueuedMessage:(0,Y.useCallback)(t=>{let n=C.find(e=>e.id===t);e({type:Z.RemoveQueuedChatMessage,queuedMessageId:t}),!(!n||m||f.length>0||!u)&&S(n.message,n.model,n.attachments,n.provider,n.planMode,n.imageMode,n.ralphMode)},[e,S,m,f.length,C,u]),showEmptyBalanceDialog:i,setShowEmptyBalanceDialog:a}}function Sd(e){let t=(0,X.c)(10),{open:n,onClose:r}=e,i=$n(),a;t[0]===r?a=t[1]:(a=e=>{e||r()},t[0]=r,t[1]=a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsxs)(yr,{children:[(0,$.jsx)(br,{children:`Balance empty`}),(0,$.jsx)(Sr,{children:`You have no prompts remaining. Purchase additional prompts to continue.`})]}),t[2]=o):o=t[2];let s;t[3]!==i||t[4]!==r?(s=(0,$.jsxs)(xr,{children:[o,(0,$.jsx)(wr,{children:(0,$.jsx)(U,{onClick:()=>{r(),i(`/settings/account`)},children:`Go to Account`})})]}),t[3]=i,t[4]=r,t[5]=s):s=t[5];let c;return t[6]!==n||t[7]!==a||t[8]!==s?(c=(0,$.jsx)(Dr,{open:n,onOpenChange:a,children:s}),t[6]=n,t[7]=a,t[8]=s,t[9]=c):c=t[9],c}function Cd(e){let t=(0,X.c)(4),{messages:n}=e,r;t[0]===n?r=t[1]:(r=n===void 0?[]:n,t[0]=n,t[1]=r);let i=r,a;return t[2]===i?a=t[3]:(a=(0,$.jsx)(wd,{messages:i}),t[2]=i,t[3]=a),a}function wd(e){let t=(0,X.c)(44),{messages:n}=e,r=Q(Dd),i=Q(Ed),a=Q(Td),{handleSend:o,handleStop:s,queuedMessagesForThread:c,handleRemoveQueuedMessage:l,showEmptyBalanceDialog:u,setShowEmptyBalanceDialog:d}=xd(),{userTasks:f,setUserTasks:p,handleNewChat:m,handleSelectUserTask:h,handleRemoveUserTask:g,effectiveIsStreaming:_}=Nu(),v=jc()||E(),y;t[0]===d?y=t[1]:(y=()=>d(!1),t[0]=d,t[1]=y);let b;t[2]!==u||t[3]!==y?(b=(0,$.jsx)(Sd,{open:u,onClose:y}),t[2]=u,t[3]=y,t[4]=b):b=t[4];let x=v?`w-full min-w-0`:`w-[90vw] min-w-[400px]`,S;t[5]===x?S=t[6]:(S=q(`relative mx-auto max-w-3xl`,x),t[5]=x,t[6]=S);let C;t[7]!==_||t[8]!==m||t[9]!==g||t[10]!==h||t[11]!==r||t[12]!==n||t[13]!==a||t[14]!==i||t[15]!==f?(C=i&&(a||n.length>0||f.length>0)&&(0,$.jsx)(`div`,{className:`max-md:hidden`,children:(0,$.jsx)(rd,{threadId:i,projectId:a??``,messages:n,userTasks:f,effectiveIsStreaming:_,isCreatingProject:r,onNewChat:()=>{m()},onSelectUserTask:h,onRemoveUserTask:e=>{g(e)}})}),t[7]=_,t[8]=m,t[9]=g,t[10]=h,t[11]=r,t[12]=n,t[13]=a,t[14]=i,t[15]=f,t[16]=C):C=t[16];let w=!i&&!r,T;t[17]===g?T=t[18]:(T=e=>{g(e.id)},t[17]=g,t[18]=T);let D;t[19]===p?D=t[20]:(D=e=>{p(t=>[...t,e])},t[19]=p,t[20]=D);let O;t[21]!==_||t[22]!==l||t[23]!==o||t[24]!==s||t[25]!==c||t[26]!==w||t[27]!==T||t[28]!==D||t[29]!==f?(O=(0,$.jsx)(Sl,{onSend:o,onStop:s,isStreaming:_,disabled:w,initialValue:``,queuedMessages:c,onRemoveQueuedMessage:l,isOverlay:!1,userTasks:f,onMatchedUserTaskSend:T,onUserTaskCreated:D}),t[21]=_,t[22]=l,t[23]=o,t[24]=s,t[25]=c,t[26]=w,t[27]=T,t[28]=D,t[29]=f,t[30]=O):O=t[30];let k;t[31]!==C||t[32]!==O?(k=(0,$.jsxs)(`div`,{className:`relative`,children:[C,O]}),t[31]=C,t[32]=O,t[33]=k):k=t[33];let A=i??void 0,j;t[34]!==n||t[35]!==A?(j=(0,$.jsx)(`div`,{className:`max-md:hidden`,children:(0,$.jsx)(mu,{threadId:A,messages:n})}),t[34]=n,t[35]=A,t[36]=j):j=t[36];let M;t[37]!==k||t[38]!==j||t[39]!==S?(M=(0,$.jsxs)(`div`,{className:S,children:[k,j]}),t[37]=k,t[38]=j,t[39]=S,t[40]=M):M=t[40];let N;return t[41]!==M||t[42]!==b?(N=(0,$.jsxs)($.Fragment,{children:[b,M]}),t[41]=M,t[42]=b,t[43]=N):N=t[43],N}function Td(e){return e.selectedProjectId}function Ed(e){return e.selectedThreadId}function Dd(e){return e.isCreatingProject}var Od=768;function kd(){let e=(0,X.c)(2),[t,n]=Y.useState(void 0),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=window.matchMedia(`(max-width: ${Od-1}px)`),t=()=>{n(window.innerWidth<Od)};return e.addEventListener(`change`,t),n(window.innerWidth<Od),()=>e.removeEventListener(`change`,t)},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),Y.useEffect(r,i),!!t}function Ad(){let e=(0,X.c)(7),t=yi(),n=Q(Md),r=Q(jd),i;e[0]!==t||e[1]!==n?(i=()=>{if(!n)return;let e=n,r=!1;return(async function(){try{let n=await at(e);r||t({type:Z.SetMessages,messages:n.messages})}catch(e){console.error(`Failed to load chat history:`,e),r||t({type:Z.SetMessages,messages:[]})}})(),()=>{r=!0}},e[0]=t,e[1]=n,e[2]=i):i=e[2];let a;e[3]!==t||e[4]!==r||e[5]!==n?(a=[n,r,t],e[3]=t,e[4]=r,e[5]=n,e[6]=a):a=e[6],(0,Y.useEffect)(i,a)}function jd(e){return e.selectedProjectId}function Md(e){return e.selectedThreadId}async function Nd(e){return ue(`api/projects/${V(e)}/todos`)}async function Pd(e,t){return ve(`api/projects/${V(e)}/todos`,{description:t})}async function Fd(e,t,n){return L(`api/projects/${V(e)}/todos/${V(t)}`,n)}async function Id(e,t){await te(`api/projects/${V(e)}/todos/${V(t)}`)}var Ld=Cr(e=>(0,$.jsxs)(`div`,{className:e.v0,onClick:e.v1,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`p`,{className:e.v2,children:e.v3}),e.v4]}),e.v5]}),{name:`KanbanTodoCard_1`,portals:[`v3`,`v4`,`v5`]}),Rd=function({todo:e,projectId:t,onUpdate:n,onEdit:r,onAction:i,onThreadSelect:a}){let[o,s]=(0,Y.useState)(!1),c=zd[e.status]??[];function l(t){t.stopPropagation(),e.threadId&&a&&a(e.threadId)}async function u(r,a){r.stopPropagation(),s(!0);try{i?await i(e,a):n(await Fd(t,e.id,{status:a,working:a!==`Done`}))}finally{s(!1)}}return(0,$.jsx)(Ld,{v0:q(`rounded-lg border bg-card p-3 shadow-sm space-y-2 cursor-pointer hover:bg-accent/50 transition-colors`,e.working&&`border-primary/50 bg-primary/5`),v1:t=>{t.stopPropagation(),r(e)},v2:q(J.label,`leading-tight`),v3:e.title,v4:e.working&&(0,$.jsx)(_,{className:`h-3 w-3 animate-spin text-primary shrink-0`}),v5:(c.length>0||e.status!==`Ready`&&e.threadId&&a)&&(0,$.jsxs)(`div`,{className:`flex gap-1.5 flex-wrap items-center pt-1`,children:[c.map(t=>(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsx)(U,{size:`sm`,variant:`outline`,className:`h-6 px-2 text-base`,onClick:e=>void u(e,t.target),disabled:o||e.working,children:t.label})}),(0,$.jsx)(K,{side:`top`,children:e.status===`Ready`&&t.target===`Build`?`Implement this on a new branch of the project`:t.target===`Review`?`Review the code changes for this task`:t.target===`Done`?`Mark the task as done`:t.label})]},t.target)),e.status!==`Ready`&&e.threadId&&a&&(0,$.jsxs)(W,{children:[(0,$.jsx)(G,{asChild:!0,children:(0,$.jsxs)(U,{size:`icon`,variant:`ghost`,className:`h-7 w-7 shrink-0 group-hover:flex items-center justify-center`,onClick:l,children:[(0,$.jsx)(M,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Open thread`})]})}),(0,$.jsx)(K,{side:`right`,children:`Open thread`})]})]})})},zd={Ready:[{label:`Plan`,target:`Plan`},{label:`Build`,target:`Build`}],Plan:[{label:`Build`,target:`Build`}],Build:[{label:`Test`,target:`Test`},{label:`Review`,target:`Review`}],Test:[{label:`Review`,target:`Review`}],Review:[{label:`Done`,target:`Done`}],Done:[]},Bd=`Please analyze this task and create a detailed implementation plan.
51
-
52
- Task description:
53
- {description}`,Vd="\nWrite your complete plan to the file `{todoId}-plan.md` in the current directory.",Hd=`Act as a Quality Assurance Manager. Rephrase the task into a rigorous test case: {description}`,Ud=`Code review: The systematic examination of code to find mistakes, ensure it follows best practices, and identify areas for improvement
54
- Directions:
55
- Carefully read through the list of code changes creating a todo list of code to review.
56
- Analyze the code structure, variable names, functions, and logic flow
57
- Look for any syntax errors, bugs, or inefficiencies
58
- Consider best practices for the specific programming language used
59
- Provide clear and constructive feedback on areas that could be improved
60
- If applicable, include examples of how to refactor problematic code
61
- Offer praise for portions of the code that are well-written and follow best practices
62
-
63
- Task description:
64
- {description}`,Wd={plan:Bd,test:Hd,review:Ud},Gd={plan:`planPrompt`,test:`testPrompt`,review:`reviewPrompt`};function Kd(e,t){let n=e?.[Gd[t]];return n&&n.trim()?n:Wd[t]}function qd(e,t,n,r){let i=e.replace(/\{description\}/g,r);return t===`plan`&&(i+=Vd.replace(/\{todoId\}/g,n)),i}var Jd=[`Ready`,`Plan`,`Build`,`Test`,`Review`,`Done`],Yd={Ready:`border-t-slate-400`,Plan:`border-t-blue-400`,Build:`border-t-orange-400`,Test:`border-t-yellow-400`,Review:`border-t-purple-400`,Done:`border-t-green-400`};async function Xd(e,t){let n=e.getReader(),r=new TextDecoder,i=``,a=null;try{for(;;){let{done:e,value:o}=await n.read();if(e)break;i+=r.decode(o,{stream:!0});let s=i.split(`
65
- `);i=s.pop()??``;for(let e of s){let n=e.trim();if(n)try{let e=JSON.parse(n);e.type===`progress`&&typeof e.threadId==`string`&&!a&&(a=e.threadId,t(a))}catch{}}}}catch{}return a}async function Zd(e){let t=e.getReader();try{for(;;){let{done:e}=await t.read();if(e)break}}catch{}}async function Qd(e){let t=e.getReader(),n=new TextDecoder,r=``,i=``;try{for(;;){let{done:e,value:a}=await t.read();if(e)break;r+=n.decode(a,{stream:!0});let o=r.split(`
66
- `);r=o.pop()??``;for(let e of o){let t=e.trim();if(t)try{let e=JSON.parse(t);e.type===`token`&&e.content?i+=e.content:e.type===`result`&&e.content&&(i=e.content)}catch{}}}}catch{}return i}async function $d(e){let t=await Nd(e),n=t.filter(e=>e.threadId&&e.status!==`Done`),r=[...t];return await Promise.all(n.map(async t=>{try{await wt(t.threadId)}catch(n){if(n instanceof Error&&n.message.includes(`not found`)){let n=await Fd(e,t.id,{status:`Done`}),i=r.findIndex(e=>e.id===t.id);i!==-1&&(r[i]=n)}}})),r}function ef(e,t){return`project-todos:${e}:${t}`}function tf({projectId:e,addOpen:t,onAddOpenChange:n,onThreadSelect:r,initialTodos:i}){let a=yi(),o=Q(e=>e.selectedThreadId),c=Q(e=>e.projectModelSelections),l=Q(e=>e.projects),[u,d]=(0,Y.useState)(i),[p,m]=(0,Y.useState)(null),[h,v]=(0,Y.useState)(``),[y,b]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(!1),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(``),[D,O]=(0,Y.useState)(!1),[k,j]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{if(!u.some(e=>e.working))return;let t=setInterval(async()=>{try{let n=await Nd(e);d(n),n.some(e=>e.working)||clearInterval(t)}catch(e){console.error(`Failed to poll project todos:`,e)}},2e3);return()=>clearInterval(t)},[u,e]),(0,Y.useEffect)(()=>{t&&v(``)},[t]);function M(e){v(e.description),m({todo:e})}function N(){m(null),v(``)}async function P(){if(h.trim()){b(!0);try{let t=await Pd(e,h);d(e=>[...e,t]),n(!1),v(``)}finally{b(!1)}}}async function F(){if(!(!h.trim()||!p)){b(!0);try{let t=await Fd(e,p.todo.id,{description:h});d(e=>e.map(e=>e.id===t.id?t:e)),N()}finally{b(!1)}}}async function I(){if(p){b(!0);try{await Id(e,p.todo.id),d(e=>e.filter(e=>e.id!==p.todo.id)),N()}finally{b(!1)}}}function L(e){d(t=>t.map(t=>t.id===e.id?e:t))}async function R(t){let n=o?c[o]:void 0,r=l.find(t=>t.projectId===e),i=r?.threads.find(e=>e.threadId===o),s=n?.id??i?.model,u=n?.provider??i?.modelProvider;if(!s||!u)throw console.error(`No model or provider found for project`,e,i),Error(`No model configuration found. Please configure a model and provider for this project first.`);let d=await f(e);if(!d)return;let p=null,m=await Xd(d,n=>{Fd(e,t.id,{status:`Plan`,working:!0,threadId:n}).then(e=>{p=e,L(e)})});if(!m)return;p||L(await Fd(e,t.id,{status:`Plan`,working:!0,threadId:m}));let h=n??{id:s,provider:u,name:s,description:``};a({type:Z.SetProjectModel,threadId:m,model:h}),St(m,{model:s,modelProvider:u});let g=await tt(m,qd(Kd(r,`plan`),`plan`,t.id,t.description),s,[],void 0,u);g&&Zd(g)}async function ee(t){let n=await f(e);if(!n)return;let r=null,i=await Xd(n,n=>{Fd(e,t.id,{status:`Build`,working:!0,threadId:n}).then(e=>{r=e,L(e)})});if(!i)return;r||L(await Fd(e,t.id,{status:`Build`,working:!0,threadId:i}));let o=await wt(i),s=o.model,c=o.modelProvider;if(!s||!c)try{let t=(await ue(`api/threads?projectId=${encodeURIComponent(e)}`)||[]).map(e=>{let t=e;return{threadId:t.threadId??t.id,model:t.model??void 0,modelProvider:t.modelProvider??void 0}}).find(e=>e.model&&e.modelProvider);t&&(s=t.model,c=t.modelProvider)}catch(e){console.error(`Failed to get project threads:`,e)}if(!s||!c)throw Error(`No model configuration found. Please configure a model and provider for this project first.`);a({type:Z.SetProjectModel,threadId:i,model:{id:s,provider:c,name:s,description:``}}),St(i,{model:s,modelProvider:c}),console.log(`Sending chat message with provider:`,i,t.description,c);let l=await tt(i,t.description,s,[],void 0,c);l&&Zd(l)}async function te(t){try{let n=await f(e);if(!n){S(!1),w(null);return}let r=null;if(r=await Xd(n,e=>{r=e}),!r){S(!1),w(null);return}let i=await wt(r),a=i.model,o=i.modelProvider;if(!a||!o)try{let t=(await ue(`api/threads?projectId=${encodeURIComponent(e)}`)||[]).map(e=>{let t=e;return{model:t.model??void 0,modelProvider:t.modelProvider??void 0}}).find(e=>e.model&&e.modelProvider);t&&(a=t.model,o=t.modelProvider)}catch(e){console.error(`Failed to get project threads:`,e)}if(!a||!o){A(e,r),S(!1),w(null);return}let s=qd(Kd(l.find(t=>t.projectId===e),`test`),`test`,t.id,t.description),c=await tt(r,s,a,[],void 0,o);c&&E(await Qd(c)),A(e,r)}catch(e){console.error(`Failed to generate test case:`,e),S(!1),w(null)}finally{O(!1)}}function ne(e){w(e),E(``),O(!0),S(!0),te(e)}function B(){S(!1),w(null),E(``)}async function re(){if(!C||!T.trim())return;let t=C,n=T;B(),j(!0);try{let r=await f(e);if(!r)return;let i=null,o=await Xd(r,n=>{Fd(e,t.id,{status:`Test`,working:!0,threadId:n}).then(e=>{i=e,L(e)})});if(!o)return;i||L(await Fd(e,t.id,{status:`Test`,working:!0,threadId:o}));let s=await wt(o),c=s.model,l=s.modelProvider;if(!c||!l)try{let t=(await ue(`api/threads?projectId=${encodeURIComponent(e)}`)||[]).map(e=>{let t=e;return{model:t.model??void 0,modelProvider:t.modelProvider??void 0}}).find(e=>e.model&&e.modelProvider);t&&(c=t.model,l=t.modelProvider)}catch(e){console.error(`Failed to get project threads:`,e)}if(!c||!l)throw Error(`No model configuration found. Please configure a model and provider for this project first.`);a({type:Z.SetProjectModel,threadId:o,model:{id:c,provider:l,name:c,description:``}}),St(o,{model:c,modelProvider:l});let u=await tt(o,n,c,[],void 0,l);u&&Zd(u)}finally{j(!1)}}async function V(t){let n=await f(e);if(!n)return;let r=null,i=await Xd(n,n=>{Fd(e,t.id,{status:`Review`,working:!0,threadId:n}).then(e=>{r=e,L(e)})});if(!i)return;r||L(await Fd(e,t.id,{status:`Review`,working:!0,threadId:i}));let o=await wt(i),s=o.model,c=o.modelProvider;if(!s||!c)try{let t=(await ue(`api/threads?projectId=${encodeURIComponent(e)}`)||[]).map(e=>{let t=e;return{threadId:t.threadId??t.id,model:t.model??void 0,modelProvider:t.modelProvider??void 0}}).find(e=>e.model&&e.modelProvider);t&&(s=t.model,c=t.modelProvider)}catch(e){console.error(`Failed to get project threads:`,e)}if(!s||!c)throw Error(`No model configuration found. Please configure a model and provider for this project first.`);a({type:Z.SetProjectModel,threadId:i,model:{id:s,provider:c,name:s,description:``}}),St(i,{model:s,modelProvider:c});let u=await tt(i,qd(Kd(l.find(t=>t.projectId===e),`review`),`review`,t.id,t.description),s,[],void 0,c);u&&Zd(u)}async function ie(t,n){n===`Plan`?await R(t):n===`Build`?await ee(t):n===`Test`?ne(t):n===`Review`?await V(t):L(await Fd(e,t.id,{status:n,working:n!==`Done`}))}return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,$.jsx)(`div`,{className:`flex gap-3 overflow-x-auto pb-8 flex-1 min-h-0`,children:Jd.map(t=>{let i=u.filter(e=>e.status===t),a=t===`Ready`;return(0,$.jsxs)(`div`,{className:q(`flex flex-col rounded-lg border border-t-4 bg-muted/30 min-w-[200px] w-[200px] shrink-0`,Yd[t]),children:[(0,$.jsxs)(`div`,{className:`px-3 py-2 flex items-center justify-between`,children:[(0,$.jsx)(`h3`,{className:q(J.dropdownGroupHeading,`uppercase tracking-wide`),children:t}),(0,$.jsx)(`span`,{className:q(J.compact,`text-muted-foreground bg-muted rounded-full px-1.5 py-0.5`),children:i.length})]}),(0,$.jsx)(Xe,{className:`flex-1 px-2 pb-2`,children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[a&&(0,$.jsxs)(U,{variant:`outline`,size:`sm`,className:`w-full h-8 border-dashed text-muted-foreground hover:text-foreground`,onClick:()=>n(!0),children:[(0,$.jsx)(sn,{className:`h-3 w-3 mr-1`}),`Add Task`]}),i.map(t=>(0,$.jsx)(Rd,{todo:t,projectId:e,onUpdate:L,onEdit:M,onAction:ie,onThreadSelect:r},t.id))]})})]},t)})}),(0,$.jsx)(g,{open:t,onOpenChange:n,children:(0,$.jsxs)(H,{className:`sm:max-w-2xl`,children:[(0,$.jsx)(xt,{children:(0,$.jsx)(z,{children:`Add Task`})}),(0,$.jsxs)(`div`,{className:`py-2`,children:[(0,$.jsx)(Si,{placeholder:`Describe what needs to be done...`,value:h,onChange:e=>v(e.target.value),rows:12,className:`resize-none text-base`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&P()}}),(0,$.jsx)(`p`,{className:q(J.caption,`mt-1.5`),children:`A title will be generated automatically from your description.`})]}),(0,$.jsx)(s,{children:(0,$.jsx)(U,{onClick:()=>void P(),disabled:y||!h.trim(),children:y?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{className:`h-3 w-3 animate-spin mr-1`}),`Generating title...`]}):`Add`})})]})}),(0,$.jsx)(g,{open:x,onOpenChange:e=>!e&&B(),children:(0,$.jsxs)(H,{className:`sm:max-w-2xl`,children:[(0,$.jsx)(xt,{children:(0,$.jsx)(z,{children:`Test Case`})}),(0,$.jsx)(`div`,{className:`py-2`,children:D?(0,$.jsxs)(`div`,{className:`flex items-center justify-center h-32 gap-2 text-muted-foreground`,children:[(0,$.jsx)(_,{className:`h-4 w-4 animate-spin`}),(0,$.jsx)(`span`,{className:J.body,children:`Generating test case...`})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Si,{value:T,onChange:e=>E(e.target.value),rows:12,className:`resize-none text-base`,autoFocus:!0}),(0,$.jsx)(`p`,{className:q(J.caption,`mt-1.5`),children:`Review or edit the test case before confirming.`})]})}),(0,$.jsxs)(s,{children:[(0,$.jsx)(U,{variant:`outline`,onClick:B,disabled:D,children:`Cancel`}),(0,$.jsx)(U,{onClick:()=>void re(),disabled:D||!T.trim()||k,children:k?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{className:`h-3 w-3 animate-spin mr-1`}),`Starting...`]}):`Confirm`})]})]})}),(0,$.jsx)(g,{open:p!==null,onOpenChange:e=>!e&&N(),children:(0,$.jsxs)(H,{className:`sm:max-w-2xl`,children:[(0,$.jsx)(xt,{children:(0,$.jsx)(z,{children:`Edit Task`})}),(0,$.jsx)(`div`,{className:`py-2`,children:(0,$.jsx)(Si,{placeholder:`Describe what needs to be done...`,value:h,onChange:e=>v(e.target.value),rows:12,className:`resize-none text-base`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&F()}})}),(0,$.jsxs)(s,{className:`gap-2 sm:gap-0`,children:[(0,$.jsx)(U,{variant:`destructive`,onClick:()=>void I(),disabled:y,className:`mr-auto`,children:`Delete`}),(0,$.jsx)(U,{onClick:()=>void F(),disabled:y||!h.trim(),children:y?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{className:`h-3 w-3 animate-spin mr-1`}),`Saving...`]}):`Save`})]})]})})]})}function nf(e){let t=(0,X.c)(13),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({projectId:r,loadVersion:n,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]!==n||t[5]!==r?(a=ef(r,n),t[4]=n,t[5]=r,t[6]=a):a=t[6];let o;t[7]===r?o=t[8]:(o=()=>$d(r),t[7]=r,t[8]=o);let s=Tr(a,o),c;return t[9]!==s||t[10]!==r||t[11]!==i?(c=(0,$.jsx)(tf,{projectId:r,initialTodos:s,...i}),t[9]=s,t[10]=r,t[11]=i,t[12]=c):c=t[12],c}function rf(e){let t=(0,X.c)(11),[n,r]=(0,Y.useState)(0),i;t[0]!==n||t[1]!==e.projectId?(i=function(){Ar(ef(e.projectId,n)),r(af)},t[0]=n,t[1]=e.projectId,t[2]=i):i=t[2];let a=i,o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(Or,{className:`h-64`}),t[3]=o):o=t[3];let s=`${e.projectId}:${n}`,c;t[4]!==n||t[5]!==e||t[6]!==s?(c=(0,$.jsx)(Y.Suspense,{fallback:o,children:(0,$.jsx)(nf,{...e,loadVersion:n},s)}),t[4]=n,t[5]=e,t[6]=s,t[7]=c):c=t[7];let l;return t[8]!==a||t[9]!==c?(l=(0,$.jsx)(kr,{fallbackTitle:`Failed to load tasks`,onRetry:a,children:c}),t[8]=a,t[9]=c,t[10]=l):l=t[10],l}function af(e){return e+1}var of=Fn,sf=Y.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(Mn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});sf.displayName=Mn.displayName;var cf=Y.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-base 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`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(Rn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});cf.displayName=Rn.displayName;var lf=Y.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(Hn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});lf.displayName=Hn.displayName;var uf=[{value:`plan`,label:`Plan`,field:`planPrompt`,defaultPrompt:Bd},{value:`review`,label:`Code Review`,field:`reviewPrompt`,defaultPrompt:Ud},{value:`test`,label:`Test`,field:`testPrompt`,defaultPrompt:Hd}];function df({open:e,onOpenChange:t,projectId:n}){let r=Q(e=>e.projects),[i,a]=(0,Y.useState)({plan:``,review:``,test:``}),[o,c]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{if(!e)return;let t=r.find(e=>e.projectId===n);a({plan:t?.planPrompt??``,review:t?.reviewPrompt??``,test:t?.testPrompt??``})},[e,n,r]);async function l(){c(!0);try{await vn(n,{planPrompt:i.plan.trim()===Bd?null:i.plan.trim()||null,testPrompt:i.test.trim()===Hd?null:i.test.trim()||null,reviewPrompt:i.review.trim()===Ud?null:i.review.trim()||null}),F(),Ii({title:`AI prompt settings saved`}),t(!1)}catch(e){Ii({title:`Error`,description:e instanceof Error?e.message:`Failed to save prompt settings`,variant:`destructive`})}finally{c(!1)}}function u(e,t){a(n=>({...n,[e]:t}))}return(0,$.jsx)(g,{open:e,onOpenChange:t,children:(0,$.jsxs)(H,{className:`max-w-2xl`,children:[(0,$.jsxs)(xt,{children:[(0,$.jsx)(z,{children:`AI Prompt Settings`}),(0,$.jsx)(Ct,{children:`Customize the prompts used when running Plan, Code Review, and Test actions from the task board. Leave empty to use the default prompt.`})]}),(0,$.jsxs)(of,{defaultValue:`plan`,className:`w-full`,children:[(0,$.jsx)(sf,{className:`w-full`,children:uf.map(e=>(0,$.jsx)(cf,{value:e.value,className:`flex-1`,children:e.label},e.value))}),uf.map(e=>(0,$.jsxs)(lf,{value:e.value,children:[(0,$.jsx)(Si,{value:i[e.value]||e.defaultPrompt,onChange:t=>u(e.value,t.target.value),className:`min-h-[250px] font-mono resize-none`,placeholder:e.defaultPrompt,disabled:o}),(0,$.jsxs)(`p`,{className:q(J.bodyMuted,`mt-1.5`),children:[`Use `,(0,$.jsx)(`code`,{className:J.mono,children:`{description}`}),` for the task description. Leave empty to use the default.`]})]},e.value))]}),(0,$.jsx)(s,{children:(0,$.jsx)(U,{onClick:()=>void l(),disabled:o,children:o?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{className:`mr-2 h-4 w-4 animate-spin`}),`Saving...`]}):`Save`})})]})})}function ff({projectId:e}){let t=yi(),r=Q(e=>e.projects),i=Q(e=>e.selectedThreadId),a=Q(e=>e.selectedProjectId),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(!1),u=$n(),{setActiveMainTab:d}=Fa();async function f(n){if(r.find(t=>t.projectId===e)){u(`/`),d(`chat`);try{let{getProjects:r,invalidateProjectsCache:o}=await pr(async()=>{let{getProjects:e,invalidateProjectsCache:t}=await import(`./dialogs-config-B-LZ4nOb.js`).then(e=>e.f);return{getProjects:e,invalidateProjectsCache:t}},__vite__mapDeps([5,1]));o();let s=await r();t({type:Z.SetProjects,projects:s.projects});let c=s.projects.find(t=>t.projectId===e);if(c&&c.threads.find(e=>e.threadId===n)){(i!==n||a!==e)&&t({type:Z.SelectThread,threadId:n,projectId:e});try{let e=await dt();t({type:Z.SetProcessingThreads,threadIds:e})}catch(e){console.error(`Failed to fetch processing threads after thread selection:`,e)}}}catch(r){console.error(`Failed to refresh projects for thread selection:`,r),(i!==n||a!==e)&&t({type:Z.SelectThread,threadId:n,projectId:e});try{let e=await dt();t({type:Z.SetProcessingThreads,threadIds:e})}catch(e){console.error(`Failed to fetch processing threads after fallback thread selection:`,e)}}}}return(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col overflow-hidden`,children:[(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden pt-8 pl-4`,children:(0,$.jsx)(rf,{projectId:e,addOpen:o,onAddOpenChange:s,onThreadSelect:f})}),(0,$.jsx)(U,{variant:`outline`,size:`icon`,className:`absolute bottom-8 right-4`,onClick:()=>l(!0),children:(0,$.jsx)(n,{className:`h-4 w-4`})}),(0,$.jsx)(df,{open:c,onOpenChange:l,projectId:e})]})}var pf=4,mf=`(max-width: 767px)`;function hf(e,t){let n=e.getBoundingClientRect().bottom,r=t.getBoundingClientRect().top,i=t.querySelector(`[data-chat-toolbar]`);return i&&i.getBoundingClientRect().height>0&&(r=Math.min(r,i.getBoundingClientRect().top)),Math.max(0,Math.ceil(n-r))+(window.matchMedia(mf).matches?pf:0)}function gf(e,t,n){let r=(0,X.c)(5),[i,a]=(0,Y.useState)(0),o,s;return r[0]!==t||r[1]!==e||r[2]!==n?(o=()=>{if(!n){a(0);return}let r=e.current,i=t.current;if(!r||!i){a(0);return}let o=function(){let n=e.current,r=t.current;!n||!r||a(hf(n,r))};o();let s=new ResizeObserver(o);s.observe(r),s.observe(i);let c=i.querySelector(`[data-chat-toolbar]`);c&&s.observe(c);let l=new MutationObserver(o);l.observe(i,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`class`,`style`,`hidden`]}),window.addEventListener(`resize`,o);let u=window.visualViewport;return u?.addEventListener(`resize`,o),u?.addEventListener(`scroll`,o),()=>{s.disconnect(),l.disconnect(),window.removeEventListener(`resize`,o),u?.removeEventListener(`resize`,o),u?.removeEventListener(`scroll`,o)}},s=[e,t,n],r[0]=t,r[1]=e,r[2]=n,r[3]=o,r[4]=s):(o=r[3],s=r[4]),(0,Y.useEffect)(o,s),i}var _f;(function(e){e.Unimplemented=`UNIMPLEMENTED`,e.Unavailable=`UNAVAILABLE`})(_f||={});var vf=class extends Error{constructor(e,t,n){super(e),this.message=e,this.code=t,this.data=n}},yf=e=>e?.androidBridge?`android`:e?.webkit?.messageHandlers?.bridge?`ios`:`web`,bf=e=>{let t=e.CapacitorCustomPlatform||null,n=e.Capacitor||{},r=n.Plugins=n.Plugins||{},i=()=>t===null?yf(e):t.name,a=()=>i()!==`web`,o=e=>!!(l.get(e)?.platforms.has(i())||s(e)),s=e=>n.PluginHeaders?.find(t=>t.name===e),c=t=>e.console.error(t),l=new Map;return n.convertFileSrc||=e=>e,n.getPlatform=i,n.handleError=c,n.isNativePlatform=a,n.isPluginAvailable=o,n.registerPlugin=(e,a={})=>{let o=l.get(e);if(o)return console.warn(`Capacitor plugin "${e}" already registered. Cannot register plugins twice.`),o.proxy;let c=i(),u=s(e),d,f=async()=>(!d&&c in a?d=d=typeof a[c]==`function`?await a[c]():a[c]:t!==null&&!d&&`web`in a&&(d=d=typeof a.web==`function`?await a.web():a.web),d),p=(t,r)=>{if(u){let i=u?.methods.find(e=>r===e.name);if(i)return i.rtype===`promise`?t=>n.nativePromise(e,r.toString(),t):(t,i)=>n.nativeCallback(e,r.toString(),t,i);if(t)return t[r]?.bind(t)}else if(t)return t[r]?.bind(t);else throw new vf(`"${e}" plugin is not implemented on ${c}`,_f.Unimplemented)},m=t=>{let n,r=(...r)=>{let i=f().then(i=>{let a=p(i,t);if(a){let e=a(...r);return n=e?.remove,e}else throw new vf(`"${e}.${t}()" is not implemented on ${c}`,_f.Unimplemented)});return t===`addListener`&&(i.remove=async()=>n()),i};return r.toString=()=>`${t.toString()}() { [capacitor code] }`,Object.defineProperty(r,"name",{value:t,writable:!1,configurable:!1}),r},h=m(`addListener`),g=m(`removeListener`),_=(e,t)=>{let n=h({eventName:e},t),r=async()=>{g({eventName:e,callbackId:await n},t)},i=new Promise(e=>n.then(()=>e({remove:r})));return i.remove=async()=>{console.warn(`Using addListener() without 'await' is deprecated.`),await r()},i},v=new Proxy({},{get(e,t){switch(t){case`$$typeof`:return;case`toJSON`:return()=>({});case`addListener`:return u?_:h;case`removeListener`:return g;default:return m(t)}}});return r[e]=v,l.set(e,{name:e,proxy:v,platforms:new Set([...Object.keys(a),...u?[c]:[]])}),v},n.Exception=vf,n.DEBUG=!!n.DEBUG,n.isLoggingEnabled=!!n.isLoggingEnabled,n},xf=(e=>e.Capacitor=bf(e))(typeof globalThis<`u`?globalThis:typeof self<`u`?self:typeof window<`u`?window:typeof global<`u`?global:{}),Sf=xf.registerPlugin,Cf=class{constructor(){this.listeners={},this.retainedEventArguments={},this.windowListeners={}}addListener(e,t){let n=!1;this.listeners[e]||(this.listeners[e]=[],n=!0),this.listeners[e].push(t);let r=this.windowListeners[e];return r&&!r.registered&&this.addWindowListener(r),n&&this.sendRetainedArgumentsForEvent(e),Promise.resolve({remove:async()=>this.removeListener(e,t)})}async removeAllListeners(){this.listeners={};for(let e in this.windowListeners)this.removeWindowListener(this.windowListeners[e]);this.windowListeners={}}notifyListeners(e,t,n){let r=this.listeners[e];if(!r){if(n){let n=this.retainedEventArguments[e];n||=[],n.push(t),this.retainedEventArguments[e]=n}return}r.forEach(e=>e(t))}hasListeners(e){return!!this.listeners[e]?.length}registerWindowListener(e,t){this.windowListeners[t]={registered:!1,windowEventName:e,pluginEventName:t,handler:e=>{this.notifyListeners(t,e)}}}unimplemented(e=`not implemented`){return new xf.Exception(e,_f.Unimplemented)}unavailable(e=`not available`){return new xf.Exception(e,_f.Unavailable)}async removeListener(e,t){let n=this.listeners[e];if(!n)return;let r=n.indexOf(t);this.listeners[e].splice(r,1),this.listeners[e].length||this.removeWindowListener(this.windowListeners[e])}addWindowListener(e){window.addEventListener(e.windowEventName,e.handler),e.registered=!0}removeWindowListener(e){e&&(window.removeEventListener(e.windowEventName,e.handler),e.registered=!1)}sendRetainedArgumentsForEvent(e){let t=this.retainedEventArguments[e];t&&(delete this.retainedEventArguments[e],t.forEach(t=>{this.notifyListeners(e,t)}))}},wf=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),Tf=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent),Ef=class extends Cf{async getCookies(){let e=document.cookie,t={};return e.split(`;`).forEach(e=>{if(e.length<=0)return;let[n,r]=e.replace(/=/,`CAP_COOKIE`).split(`CAP_COOKIE`);n=Tf(n).trim(),r=Tf(r).trim(),t[n]=r}),t}async setCookie(e){try{let t=wf(e.key),n=wf(e.value),r=e.expires?`; expires=${e.expires.replace(`expires=`,``)}`:``,i=(e.path||`/`).replace(`path=`,``),a=e.url!=null&&e.url.length>0?`domain=${e.url}`:``;document.cookie=`${t}=${n||``}${r}; path=${i}; ${a};`}catch(e){return Promise.reject(e)}}async deleteCookie(e){try{document.cookie=`${e.key}=; Max-Age=0`}catch(e){return Promise.reject(e)}}async clearCookies(){try{let e=document.cookie.split(`;`)||[];for(let t of e)document.cookie=t.replace(/^ +/,``).replace(/=.*/,`=;expires=${new Date().toUTCString()};path=/`)}catch(e){return Promise.reject(e)}}async clearAllCookies(){try{await this.clearCookies()}catch(e){return Promise.reject(e)}}};Sf(`CapacitorCookies`,{web:()=>new Ef});var Df=async e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let e=r.result;t(e.indexOf(`,`)>=0?e.split(`,`)[1]:e)},r.onerror=e=>n(e),r.readAsDataURL(e)}),Of=(e={})=>{let t=Object.keys(e);return Object.keys(e).map(e=>e.toLocaleLowerCase()).reduce((n,r,i)=>(n[r]=e[t[i]],n),{})},kf=(e,t=!0)=>e?Object.entries(e).reduce((e,n)=>{let[r,i]=n,a,o;return Array.isArray(i)?(o=``,i.forEach(e=>{a=t?encodeURIComponent(e):e,o+=`${r}=${a}&`}),o.slice(0,-1)):(a=t?encodeURIComponent(i):i,o=`${r}=${a}`),`${e}&${o}`},``).substr(1):null,Af=(e,t={})=>{let n=Object.assign({method:e.method||`GET`,headers:e.headers},t),r=Of(e.headers)[`content-type`]||``;if(typeof e.data==`string`)n.body=e.data;else if(r.includes(`application/x-www-form-urlencoded`)){let t=new URLSearchParams;for(let[n,r]of Object.entries(e.data||{}))t.set(n,r);n.body=t.toString()}else if(r.includes(`multipart/form-data`)||e.data instanceof FormData){let t=new FormData;if(e.data instanceof FormData)e.data.forEach((e,n)=>{t.append(n,e)});else for(let n of Object.keys(e.data))t.append(n,e.data[n]);n.body=t;let r=new Headers(n.headers);r.delete(`content-type`),n.headers=r}else (r.includes(`application/json`)||typeof e.data==`object`)&&(n.body=JSON.stringify(e.data));return n},jf=class extends Cf{async request(e){let t=Af(e,e.webFetchExtra),n=kf(e.params,e.shouldEncodeUrlParams),r=n?`${e.url}?${n}`:e.url,i=await fetch(r,t),a=i.headers.get(`content-type`)||``,{responseType:o=`text`}=i.ok?e:{};a.includes(`application/json`)&&(o=`json`);let s,c;switch(o){case`arraybuffer`:case`blob`:c=await i.blob(),s=await Df(c);break;case`json`:s=await i.json();break;default:s=await i.text()}let l={};return i.headers.forEach((e,t)=>{l[t]=e}),{data:s,headers:l,status:i.status,url:i.url}}async get(e){return this.request(Object.assign(Object.assign({},e),{method:`GET`}))}async post(e){return this.request(Object.assign(Object.assign({},e),{method:`POST`}))}async put(e){return this.request(Object.assign(Object.assign({},e),{method:`PUT`}))}async patch(e){return this.request(Object.assign(Object.assign({},e),{method:`PATCH`}))}async delete(e){return this.request(Object.assign(Object.assign({},e),{method:`DELETE`}))}};Sf(`CapacitorHttp`,{web:()=>new jf});var Mf;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(Mf||={});var Nf;(function(e){e.StatusBar=`StatusBar`,e.NavigationBar=`NavigationBar`})(Nf||={});var Pf=class extends Cf{async setStyle(){this.unavailable(`not available for web`)}async setAnimation(){this.unavailable(`not available for web`)}async show(){this.unavailable(`not available for web`)}async hide(){this.unavailable(`not available for web`)}};Sf(`SystemBars`,{web:()=>new Pf});var Ff;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(Ff||={});var If;(function(e){e.Body=`body`,e.Ionic=`ionic`,e.Native=`native`,e.None=`none`})(If||={});var Lf=Sf(`Keyboard`);function Rf(e){let t=window.visualViewport;if(!e||!t)return 0;let n=t.height+t.offsetTop,r=e.getBoundingClientRect().bottom;return Math.max(0,Math.round(r-n))}function zf(e,t){return Pe()?t:e>0?e:t}function Bf(e){let t=(0,X.c)(6),[n,r]=(0,Y.useState)(0),[i,a]=(0,Y.useState)(0),o,s;t[0]===e?(o=t[1],s=t[2]):(o=()=>{let t=function(){r(Rf(e.current))},n=function(){t(),requestAnimationFrame(t)};n();let i=window.visualViewport;i?.addEventListener(`resize`,n),i?.addEventListener(`scroll`,n),window.addEventListener(`resize`,n);let o=[];return E()&&o.push(Lf.addListener(`keyboardWillShow`,e=>{a(e.keyboardHeight)}),Lf.addListener(`keyboardDidShow`,e=>{a(e.keyboardHeight)}),Lf.addListener(`keyboardWillHide`,()=>{a(0)}),Lf.addListener(`keyboardDidHide`,()=>{a(0)})),()=>{i?.removeEventListener(`resize`,n),i?.removeEventListener(`scroll`,n),window.removeEventListener(`resize`,n);for(let e of o)e.then(Vf)}},s=[e],t[0]=e,t[1]=o,t[2]=s),(0,Y.useEffect)(o,s);let c;return t[3]!==n||t[4]!==i?(c=zf(n,i),t[3]=n,t[4]=i,t[5]=c):c=t[5],c}function Vf(e){e.remove()}var Hf=(0,Y.lazy)(()=>pr(()=>import(`./diff-view-Bi545EPj.js`),__vite__mapDeps([6,1,3,4,7,5,8,9,10,11]))),Uf=(0,Y.lazy)(()=>pr(()=>import(`./dialogs-config-B-LZ4nOb.js`).then(e=>e.t),__vite__mapDeps([5,1])));function Wf(e){let t=(0,X.c)(61),{onCreateThread:n}=e,r=yi(),i=$n(),a=cr(),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(null),u=Q(ip),d=Q(rp),f=Q(np),p=Q(tp),m=Q(ep),h=Q($f),g=Q(Qf),_=Q(Zf),v=Q(Xf),y=Q(Yf),b=Q(Jf),x=Q(qf),S=Q(Kf),C;t[0]!==p||t[1]!==u?(C=u&&p.includes(u),t[0]=p,t[1]=u,t[2]=C):C=t[2];let w=!!C,T=b?.threadId===u,E;t[3]===r?E=t[4]:(E=()=>{r({type:Z.CloseSidebar})},t[3]=r,t[4]=E);let D=E,O;t[5]===D?O=t[6]:(O=()=>{D(),l(`clone`),s(!0)},t[5]=D,t[6]=O);let k=O,A;t[7]===D?A=t[8]:(A=()=>{D(),l(`webapp`),s(!0)},t[7]=D,t[8]=A);let j=A,M;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(M=async(e,t)=>{try{await gn(e,t),s(!1),l(null)}catch(e){console.error(`Failed to clone repository:`,e)}},t[9]=M):M=t[9];let N=M,P;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(P=async(e,t,n)=>{try{await Ce(e,t,n),s(!1),l(null)}catch(e){console.error(`Failed to create project:`,e)}},t[10]=P):P=t[10];let F=P,I;t[11]===D?I=t[12]:(I=async()=>{D();try{await Re(),s(!1),l(null)}catch(e){console.error(`Failed to open folder:`,e)}},t[11]=D,t[12]=I);let L=I,R;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(R=async e=>{try{await xn(e),s(!1),l(null)}catch(e){console.error(`Failed to create folder:`,e)}},t[13]=R):R=t[13];let ee=R,te=a.pathname===`/review`,z=a.pathname===`/todos`,ne;t[14]===i?ne=t[15]:(ne=()=>{i(`/`)},t[14]=i,t[15]=ne);let B=ne;Ad();let re;t[16]===x?re=t[17]:(re=xc(x),t[16]=x,t[17]=re);let V=re,ie;t[18]===x?ie=t[19]:(ie=Sc(x),t[18]=x,t[19]=ie);let ae=ie,oe=(0,Y.useRef)(null),H=(0,Y.useRef)(null),se=(0,Y.useRef)(null),ce=kd(),[le,ue]=(0,Y.useState)(!0),de=!te&&!z&&!!u,fe=ce&&de&&!le,pe=gf(oe,H,de),me=Bf(H),he;t[20]!==pe||t[21]!==D||t[22]!==r||t[23]!==k||t[24]!==B||t[25]!==j||t[26]!==L||t[27]!==T||t[28]!==f||t[29]!==w||t[30]!==_||t[31]!==d||t[32]!==g||t[33]!==n||t[34]!==m||t[35]!==h||t[36]!==te||t[37]!==S||t[38]!==u||t[39]!==y||t[40]!==v||t[41]!==z?(he=z&&S?(0,$.jsx)(ff,{projectId:S}):te&&u?(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(Or,{}),children:(0,$.jsx)(Hf,{threadId:u,onExit:B})}):(0,$.jsx)(yc,{ref:se,bottomInset:pe,messages:d,isStreaming:_,streamingSegments:v,streamingModel:y,isCreatingProject:f,isProcessingThread:w,hasPendingMessage:T,selectedThreadId:u,selectedProjectId:S,projects:m,projectsLoading:h,messagesLoaded:g,onSelectThread:(e,t)=>{D(),r({type:Z.SelectThread,projectId:e,threadId:t})},onCreateThread:n,onConnectRepo:k,onNewApp:j,onOpenFolder:L,error:null,onClearError:Gf,onAtBottomChange:ue}),t[20]=pe,t[21]=D,t[22]=r,t[23]=k,t[24]=B,t[25]=j,t[26]=L,t[27]=T,t[28]=f,t[29]=w,t[30]=_,t[31]=d,t[32]=g,t[33]=n,t[34]=m,t[35]=h,t[36]=te,t[37]=S,t[38]=u,t[39]=y,t[40]=v,t[41]=z,t[42]=he):he=t[42];let ge;t[43]!==V||t[44]!==ae||t[45]!==me||t[46]!==d||t[47]!==de||t[48]!==fe?(ge=de&&(0,$.jsxs)(`div`,{ref:H,className:`absolute left-0 right-0 z-10 max-md:px-2`,style:{bottom:me},children:[(0,$.jsx)(`div`,{className:`h-0 md:h-6`,style:{backgroundImage:ae}}),(0,$.jsx)(`div`,{className:`h-0 md:h-8`,style:{backgroundImage:V}}),fe&&(0,$.jsx)(`div`,{className:`mb-1 flex justify-center`,children:(0,$.jsx)(`button`,{type:`button`,onClick:()=>se.current?.scrollToBottom(),className:`flex h-8 w-8 items-center justify-center rounded-full border border-border bg-background shadow-md transition-colors hover:bg-accent active:bg-accent`,"aria-label":`Scroll to bottom`,children:(0,$.jsx)(Tt,{className:`h-4 w-4`})})}),(0,$.jsx)(`div`,{style:{backgroundImage:V},children:(0,$.jsx)(Cd,{messages:d})})]}),t[43]=V,t[44]=ae,t[45]=me,t[46]=d,t[47]=de,t[48]=fe,t[49]=ge):ge=t[49];let _e=c??void 0,ve;t[50]!==o||t[51]!==L||t[52]!==_e?(ve=(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Uf,{open:o,onOpenChange:s,initialMode:_e,onSubmitClone:N,onSubmitWebApp:F,onSubmitFolder:ee,onOpenFolder:L})}),t[50]=o,t[51]=L,t[52]=_e,t[53]=ve):ve=t[53];let ye;t[54]!==he||t[55]!==ge||t[56]!==ve?(ye=(0,$.jsxs)(`div`,{ref:oe,className:`relative flex h-full flex-col`,children:[he,ge,ve]}),t[54]=he,t[55]=ge,t[56]=ve,t[57]=ye):ye=t[57];let be;return t[58]!==u||t[59]!==ye?(be=(0,$.jsx)(zo,{threadId:u,children:ye}),t[58]=u,t[59]=ye,t[60]=be):be=t[60],be}function Gf(){}function Kf(e){return e.selectedProjectId}function qf(e){return e.sidebarOpen}function Jf(e){return e.pendingChatMessage}function Yf(e){return e.streamingModel}function Xf(e){return e.streamingSegments}function Zf(e){return e.isStreaming}function Qf(e){return e.messagesLoaded}function $f(e){return e.projectsLoading}function ep(e){return e.projects}function tp(e){return e.processingThreadIds}function np(e){return e.isCreatingProject}function rp(e){return e.messages}function ip(e){return e.selectedThreadId}function ap(e){let t=(0,X.c)(5),{children:n,className:r}=e,i;t[0]===r?i=t[1]:(i=q(`flex min-h-[71px] shrink-0 items-center gap-2 px-4 py-2 electrobun-webkit-app-region-drag`,r),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,$.jsx)(`header`,{className:i,children:n}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a}function op(e){let t=(0,X.c)(3),{children:n,className:r}=e,i=`flex items-center gap-2 rounded-full shadow-md ${r===void 0?``:r}`,a;return t[0]!==n||t[1]!==i?(a=(0,$.jsx)(`div`,{className:i,children:n}),t[0]=n,t[1]=i,t[2]=a):a=t[2],a}function sp(){let e=(0,X.c)(44),t=yi(),n=Q(dp),r=Q(up),i=Q(lp),a=Q(cp),s;if(e[0]!==i||e[1]!==r){let t;e[3]===r?t=e[4]:(t=e=>e.projectId===r,e[3]=r,e[4]=t),s=i.find(t),e[0]=i,e[1]=r,e[2]=s}else s=e[2];let c=s,l=!a,u,d;if(e[5]!==l){let t=o();u=ap,d=q(t&&`pt-8 md:min-h-[103px]`,l&&t&&`max-md:pb-2 md:h-auto md:pb-3 md:h-[103px] md:pb-0`),e[5]=l,e[6]=u,e[7]=d}else u=e[6],d=e[7];let f;e[8]===t?f=e[9]:(f=()=>t({type:Z.ToggleSidebar}),e[8]=t,e[9]=f);let p;e[10]===a?p=e[11]:(p=a?(0,$.jsx)(lt,{className:`h-4 w-4`}):(0,$.jsx)(ft,{className:`h-4 w-4`}),e[10]=a,e[11]=p);let m;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(`span`,{className:`sr-only`,children:`Toggle sidebar`}),e[12]=m):m=e[12];let h;e[13]!==f||e[14]!==p?(h=(0,$.jsxs)(U,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-muted-foreground shrink-0 electrobun-webkit-app-region-no-drag`,onClick:f,children:[p,m]}),e[13]=f,e[14]=p,e[15]=h):h=e[15];let g;e[16]!==i||e[17]!==r||e[18]!==n?(g=n&&(0,$.jsx)(`span`,{className:q(J.sectionTitle,`text-foreground truncate min-w-0`),children:Ut(i,r)}),e[16]=i,e[17]=r,e[18]=n,e[19]=g):g=e[19];let _;e[20]!==h||e[21]!==g?(_=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[h,g]}),e[20]=h,e[21]=g,e[22]=_):_=e[22];let v;e[23]===n?v=e[24]:(v=n&&(0,$.jsx)(id,{}),e[23]=n,e[24]=v);let y;e[25]!==c?.runCommand||e[26]!==r||e[27]!==n?(y=r&&(0,$.jsxs)(op,{className:`electrobun-webkit-app-region-no-drag`,children:[(0,$.jsx)(Zu,{projectId:r,runCommand:c?.runCommand}),n&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Iu,{threadId:n}),(0,$.jsx)(zu,{})]})]}),e[25]=c?.runCommand,e[26]=r,e[27]=n,e[28]=y):y=e[28];let b;e[29]!==c?.openWith||e[30]!==r||e[31]!==n?(b=n&&r&&(0,$.jsx)(op,{className:`electrobun-webkit-app-region-no-drag`,children:(0,$.jsx)(qu,{projectId:r,threadId:n,openWith:c?.openWith})}),e[29]=c?.openWith,e[30]=r,e[31]=n,e[32]=b):b=e[32];let x;e[33]!==b||e[34]!==y?(x=(0,$.jsxs)(`div`,{className:`hidden md:flex flex-wrap items-center justify-end gap-2`,children:[y,b]}),e[33]=b,e[34]=y,e[35]=x):x=e[35];let S;e[36]!==x||e[37]!==v?(S=(0,$.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:[v,x]}),e[36]=x,e[37]=v,e[38]=S):S=e[38];let C;return e[39]!==u||e[40]!==d||e[41]!==S||e[42]!==_?(C=(0,$.jsxs)(u,{className:d,children:[_,S]}),e[39]=u,e[40]=d,e[41]=S,e[42]=_,e[43]=C):C=e[43],C}function cp(e){return e.sidebarOpen}function lp(e){return e.projects}function up(e){return e.selectedProjectId}function dp(e){return e.selectedThreadId}function fp(e){let t=(0,X.c)(14),{open:n,projectName:r,onOpenChange:i,onConfirm:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(br,{children:`Delete Project`}),t[0]=o):o=t[0];let s;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(s=q(J.body,`font-semibold text-foreground`),t[1]=s):s=t[1];let c;t[2]===r?c=t[3]:(c=(0,$.jsxs)(yr,{children:[o,(0,$.jsxs)(Sr,{children:[`Are you sure you want to delete`,` `,(0,$.jsxs)(`span`,{className:s,children:[`"`,r,`"`]}),`? This will remove the project and all its data. This action cannot be undone.`]})]}),t[2]=r,t[3]=c);let l;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(Er,{children:`Cancel`}),t[4]=l):l=t[4];let u;t[5]===a?u=t[6]:(u=(0,$.jsxs)(wr,{children:[l,(0,$.jsx)(vr,{onClick:a,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]}),t[5]=a,t[6]=u);let d;t[7]!==c||t[8]!==u?(d=(0,$.jsxs)(xr,{children:[c,u]}),t[7]=c,t[8]=u,t[9]=d):d=t[9];let f;return t[10]!==i||t[11]!==n||t[12]!==d?(f=(0,$.jsx)(Dr,{open:n,onOpenChange:i,children:d}),t[10]=i,t[11]=n,t[12]=d,t[13]=f):f=t[13],f}function pp(e){let t=(0,X.c)(28),{open:n,setupScripts:r,onConfirm:i}=e;if(r.length===0)return null;let a;t[0]===i?a=t[1]:(a=e=>{e||i(!1)},t[0]=i,t[1]=a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(br,{children:`Install dependencies?`}),t[2]=o):o=t[2];let s=r.length===1?``:`s`,c;t[3]!==r.length||t[4]!==s?(c=(0,$.jsxs)(yr,{children:[o,(0,$.jsxs)(Sr,{children:[`Found `,r.length,` package`,s,` with dependencies to install:`]})]}),t[3]=r.length,t[4]=s,t[5]=c):c=t[5];let l;t[6]===r?l=t[7]:(l=r.map(mp),t[6]=r,t[7]=l);let u;t[8]===l?u=t[9]:(u=(0,$.jsx)(`div`,{className:`my-4 max-h-60 overflow-y-auto`,children:(0,$.jsx)(`div`,{className:`space-y-2`,children:l})}),t[8]=l,t[9]=u);let d;t[10]===i?d=t[11]:(d=(0,$.jsx)(Er,{onClick:()=>i(!1),children:`No`}),t[10]=i,t[11]=d);let f;t[12]===i?f=t[13]:(f=()=>i(!0),t[12]=i,t[13]=f);let p;t[14]!==r.length||t[15]!==f?(p=(0,$.jsxs)(vr,{onClick:f,children:[`Install All (`,r.length,`)`]}),t[14]=r.length,t[15]=f,t[16]=p):p=t[16];let m;t[17]!==d||t[18]!==p?(m=(0,$.jsxs)(wr,{children:[d,p]}),t[17]=d,t[18]=p,t[19]=m):m=t[19];let h;t[20]!==m||t[21]!==c||t[22]!==u?(h=(0,$.jsxs)(xr,{className:`max-w-2xl`,children:[c,u,m]}),t[20]=m,t[21]=c,t[22]=u,t[23]=h):h=t[23];let g;return t[24]!==n||t[25]!==a||t[26]!==h?(g=(0,$.jsx)(Dr,{open:n,onOpenChange:a,children:h}),t[24]=n,t[25]=a,t[26]=h,t[27]=g):g=t[27],g}function mp(e,t){let n=e.match(/^cd "([^"]+)" && (.+)$/),r=n?n[1]:`root`,i=n?n[2]:e;return(0,$.jsx)(`div`,{className:`flex items-center justify-between p-3 rounded-lg border bg-muted/50`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-blue-500`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:J.label,children:r||`root`}),(0,$.jsx)(`div`,{className:J.bodyMuted,children:i})]})]})},t)}function hp(){let[e,t]=(0,Y.useState)(!0),[n,r]=(0,Y.useState)(k),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{let e=!0;return(async()=>{try{let n=await fetch(`${S()}/health`,{method:`GET`});e&&t(n.ok)}catch{e&&t(!1)}})(),()=>{e=!1}},[]);let c=(0,Y.useCallback)(async()=>{let e=l(n);if(e){a(null),s(!0);try{if(!await P(e)){a(e);return}je(n)}finally{s(!1)}}},[n]);return e?null:(0,$.jsx)(Dr,{open:!0,children:(0,$.jsxs)(xr,{children:[(0,$.jsxs)(yr,{children:[(0,$.jsx)(`img`,{src:`/tarsk-color.svg`,alt:`Tarsk`,className:`mx-auto h-16 w-16 rounded-lg`}),(0,$.jsx)(br,{children:`Connect to Tarsk`}),(0,$.jsx)(Sr,{children:`Connect to the Tarsk server running on your local network by entering the IP Address or domain name below.`})]}),(0,$.jsx)(b,{value:n,onChange:e=>{r(e.target.value),a(null)},onKeyDown:e=>{e.key===`Enter`&&!o&&c()},placeholder:`192.168.1.100`,autoComplete:`off`,spellCheck:!1,disabled:o}),i&&(0,$.jsxs)(Mr,{variant:`error`,className:`mb-0 flex items-start gap-3`,children:[(0,$.jsxs)(`p`,{className:`flex-1`,children:[`Unable to connect to `,i,`. Please check that you are on the same network and that the Tarsk server is running and accessible on the network.`]}),(0,$.jsx)(U,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Dismiss error`,onClick:()=>a(null),children:(0,$.jsx)(j,{className:`h-4 w-4`})})]}),(0,$.jsx)(wr,{children:(0,$.jsx)(U,{onClick:()=>void c(),disabled:!n.trim()||o,children:o?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{className:`mr-2 h-4 w-4 animate-spin`}),`Connecting...`]}):`Connect`})}),(0,$.jsxs)(Mr,{variant:`hint`,className:`mb-0`,children:[(0,$.jsx)(`p`,{className:J.bodyMuted,children:`Start the Tarsk server on your local machine by running:`}),(0,$.jsx)(`code`,{className:q(J.mono,`mt-2 block rounded bg-background/60 px-2 py-1 text-foreground`),children:`npx tarsk --server`})]})]})})}var gp=e=>{let t=(0,X.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=q(`flex h-full w-full data-[panel-group-direction=vertical]:flex-col`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(zn,{className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a},_p=nr,vp=e=>{let t=(0,X.c)(12),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({withHandle:i,className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===n?a=t[5]:(a=q(`relative flex w-px items-center justify-center bg-transparent after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90`,n),t[4]=n,t[5]=a);let o;t[6]===i?o=t[7]:(o=i&&(0,$.jsx)(`div`,{className:`hidden z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border`,children:(0,$.jsx)(re,{className:`h-2.5 w-2.5`})}),t[6]=i,t[7]=o);let s;return t[8]!==r||t[9]!==a||t[10]!==o?(s=(0,$.jsx)(Bn,{className:a,...r,children:o}),t[8]=r,t[9]=a,t[10]=o,t[11]=s):s=t[11],s},yp=An,bp=Y.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(On,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});bp.displayName=On.displayName;var xp=At(`group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full`,{variants:{variant:{default:`border bg-background text-foreground`,destructive:`destructive group border-destructive bg-destructive text-destructive-foreground`}},defaultVariants:{variant:`default`}}),Sp=Y.forwardRef((e,t)=>{let n=(0,X.c)(11),r,i,a;n[0]===e?(r=n[1],i=n[2],a=n[3]):({className:r,variant:a,...i}=e,n[0]=e,n[1]=r,n[2]=i,n[3]=a);let o;n[4]!==r||n[5]!==a?(o=q(xp({variant:a}),r),n[4]=r,n[5]=a,n[6]=o):o=n[6];let s;return n[7]!==i||n[8]!==t||n[9]!==o?(s=(0,$.jsx)(Vn,{ref:t,className:o,...i}),n[7]=i,n[8]=t,n[9]=o,n[10]=s):s=n[10],s});Sp.displayName=Vn.displayName;var Cp=Y.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive`,J.body,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(dr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Cp.displayName=dr.displayName;var wp=Y.forwardRef((e,t)=>{let n=(0,X.c)(10),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(`absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600`,r),n[3]=r,n[4]=a);let o;n[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(j,{className:`h-4 w-4`}),n[5]=o):o=n[5];let s;return n[6]!==i||n[7]!==t||n[8]!==a?(s=(0,$.jsx)(Gn,{ref:t,className:a,"toast-close":``,...i,children:o}),n[6]=i,n[7]=t,n[8]=a,n[9]=s):s=n[9],s});wp.displayName=Gn.displayName;var Tp=Y.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(J.dialogTitle,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(rr,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Tp.displayName=rr.displayName;var Ep=Y.forwardRef((e,t)=>{let n=(0,X.c)(9),r,i;n[0]===e?(r=n[1],i=n[2]):({className:r,...i}=e,n[0]=e,n[1]=r,n[2]=i);let a;n[3]===r?a=n[4]:(a=q(J.body,`opacity-90 text-muted-foreground group-[.destructive]:text-destructive-foreground`,r),n[3]=r,n[4]=a);let o;return n[5]!==i||n[6]!==t||n[7]!==a?(o=(0,$.jsx)(jn,{ref:t,className:a,...i}),n[5]=i,n[6]=t,n[7]=a,n[8]=o):o=n[8],o});Ep.displayName=jn.displayName;function Dp(){let e=(0,X.c)(5),{toasts:t}=Li(),n;e[0]===t?n=e[1]:(n=t.map(Op),e[0]=t,e[1]=n);let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(bp,{}),e[2]=r):r=e[2];let i;return e[3]===n?i=e[4]:(i=(0,$.jsxs)(yp,{children:[n,r]}),e[3]=n,e[4]=i),i}function Op(e){let{id:t,title:n,description:r,action:i,...a}=e;return(0,$.jsxs)(Sp,{...a,children:[(0,$.jsxs)(`div`,{className:`grid gap-1`,children:[n&&(0,$.jsx)(Tp,{children:n}),r&&(0,$.jsx)(Ep,{children:r})]}),i,(0,$.jsx)(wp,{})]},t)}function kp(){let e=(0,X.c)(4),{resolvedTheme:t,theme:n}=zr(),r,i;return e[0]!==t||e[1]!==n?(r=()=>{if(window.tarsk?.setNativeTheme){let e=n===`system`?`system`:t||`system`;window.tarsk.setNativeTheme(e)}},i=[t,n],e[0]=t,e[1]=n,e[2]=r,e[3]=i):(r=e[2],i=e[3]),(0,Y.useEffect)(r,i),null}function Ap(e){let t=(0,X.c)(7),n,r;t[0]===e?(n=t[1],r=t[2]):({children:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(kp,{}),t[3]=i):i=t[3];let a;return t[4]!==n||t[5]!==r?(a=(0,$.jsxs)(Br,{...r,children:[i,n]}),t[4]=n,t[5]=r,t[6]=a):a=t[6],a}function jp(){let e=(0,X.c)(14),t=yi(),n=Q(Pp),r=Tr(`projects:bootstrap:${Q(Np)}`,Se),i;e[0]!==r.projects||e[1]!==t?(i=()=>{t({type:Z.SetProjects,projects:r.projects}),t({type:Z.SetProjectsLoading,projectsLoading:!1})},e[0]=r.projects,e[1]=t,e[2]=i):i=e[2];let a;e[3]!==r||e[4]!==t?(a=[r,t],e[3]=r,e[4]=t,e[5]=a):a=e[5],(0,Y.useLayoutEffect)(i,a);let o;e[6]!==r.projects||e[7]!==t||e[8]!==n?(o=()=>{if(!n)for(let e of r.projects){let n=e.threads.find(Mp);if(n){t({type:Z.SelectThread,threadId:n.threadId,projectId:e.projectId});break}}},e[6]=r.projects,e[7]=t,e[8]=n,e[9]=o):o=e[9];let s;return e[10]!==r||e[11]!==t||e[12]!==n?(s=[r,t,n],e[10]=r,e[11]=t,e[12]=n,e[13]=s):s=e[13],(0,Y.useLayoutEffect)(o,s),null}function Mp(e){return e.isSelected}function Np(e){return e.configUpdatedAt}function Pp(e){return e.selectedThreadId}function Fp(e){let t=yi(),n=Q(e=>e.projects),r=Q(e=>e.selectedProjectId),i=Q(e=>e.selectedThreadId),{toast:a}=Li(),o=xi(`project-creation`).dispatch,[s,c]=(0,Y.useState)(null),l=(0,Y.useCallback)(async()=>{try{t({type:Z.SetProjectsLoading,projectsLoading:!0}),F(),jr(`projects:bootstrap:`);let e=await Se();t({type:Z.SetProjects,projects:e.projects})}catch(e){console.error(`Failed to refresh projects:`,e)}finally{t({type:Z.SetProjectsLoading,projectsLoading:!1})}},[t]),u=(0,Y.useCallback)((e,n)=>{(i!==n||r!==e)&&t({type:Z.SelectThread,threadId:n,projectId:e}),cn(e,n).catch(e=>{console.error(`Failed to select thread:`,e)})},[t,i,r]),d=(0,Y.useCallback)(async n=>{t({type:Z.SetCreatingProject,isCreating:!0});try{let r=await n.apiCall();if(!r){t({type:Z.SetCreatingProject,isCreating:!1}),await l();return}let i=n.useTerminalDispatch?o:t;i({type:Z.ClearTerminalOutput}),i({type:Z.SetTerminalOpen,open:!0}),i({type:Z.AppendTerminalLine,line:{type:`system`,content:n.initialMessage}});let a=r.getReader(),s=new TextDecoder,u=``,d=null,f=!1,p=null,m=null;for(;;){let{done:e,value:r}=await a.read();if(e)break;u+=s.decode(r,{stream:!0});let o=u.split(`
67
- `);u=o.pop()??``;for(let e of o){let r=e.trim();if(r)try{let e=JSON.parse(r);if(e.type===`progress`)!f&&e.threadId&&e.projectId&&(f=!0,p=e.projectId,m=e.threadId,t({type:Z.AddCreatingProject,projectId:e.projectId,threadId:e.threadId,projectName:n.optimisticProjectName,gitUrl:n.gitUrl??``}),t({type:Z.AddProcessingThread,threadId:e.threadId})),t({type:Z.AppendTerminalLine,...n.useTerminalDispatch?{threadId:m??`project-creation`}:{},line:{type:`output`,content:e.message}});else if(e.type===`complete`){if(e.project){d=e.project.id;let r=n.includeThreadPath&&e.project.threads?.length>0?`${e.project.path}/${e.project.threads[0]}`:e.project.path;i({type:Z.AppendTerminalLine,line:{type:`system`,content:`Project created successfully at: ${r}`}}),t({type:Z.SetTerminalOpen,open:!1}),n.handleSetupScript&&e.suggestedSetupScript&&c({projectId:e.project.id,command:e.suggestedSetupScript,remainingScripts:e.project.pendingSetupScripts??[]})}}else e.type===`error`&&(f&&p&&(t({type:Z.RemoveCreatingProject,projectId:p}),m&&t({type:Z.RemoveProcessingThread,threadId:m})),t({type:Z.AppendTerminalLine,...n.useTerminalDispatch?{threadId:m??`project-creation`}:{},line:{type:`error`,content:`Error: ${e.message}`}}))}catch(e){console.error(`Failed to parse ${n.logTag} event`,e)}}}t({type:Z.SetCreatingProject,isCreating:!1}),f&&m&&t({type:Z.RemoveProcessingThread,threadId:m}),F();let h=await Se();if(t({type:Z.SetProjects,projects:h.projects}),t({type:Z.SetProjectsLoading,projectsLoading:!1}),d){let n=h.projects.find(e=>e.projectId===d);if(n&&n.threads.length>0){let e=n.threads[0].threadId;t({type:Z.SelectThread,threadId:e,projectId:d,focusInput:!0})}e?.onProjectCreated?.(d)}}catch(e){console.error(`Failed to ${n.logTag}:`,e),t({type:Z.SetCreatingProject,isCreating:!1}),(n.useTerminalDispatch?o:t)({type:Z.AppendTerminalLine,line:{type:`error`,content:`${n.catchErrorPrefix}: ${e instanceof Error?e.message:`Unknown error`}`}})}},[t,l,o,e?.onProjectCreated]),p=(0,Y.useCallback)(async(e,t)=>{let n=e.split(`/`).pop()?.replace(`.git`,``)??`project`;await d({apiCall:()=>gn(e,t),initialMessage:`Cloning repository: ${e}...`,optimisticProjectName:n,gitUrl:e,useTerminalDispatch:!0,includeThreadPath:!0,handleSetupScript:!0,logTag:`create project`,catchErrorPrefix:`Failed to create project`})},[d]),m=(0,Y.useCallback)(async(e,t,n)=>{await d({apiCall:()=>Ce(e,t,n),initialMessage:`Creating app "${e}"...`,optimisticProjectName:e,useTerminalDispatch:!0,handleSetupScript:!1,logTag:`create web app`,catchErrorPrefix:`Failed to create web app`})},[d]),g=(0,Y.useCallback)(async e=>{await d({apiCall:()=>xn(e),initialMessage:`Creating folder "${e}"...`,optimisticProjectName:e,useTerminalDispatch:!0,handleSetupScript:!1,logTag:`create folder`,catchErrorPrefix:`Failed to create folder`})},[d]),_=(0,Y.useCallback)(async(e,r)=>{try{let i=r??(()=>{let t=n.find(t=>t.projectId===e)?.threads.map(e=>e.title)??[],r=/^thread-(\d+)$/i,i=0;for(let e of t){let t=e.match(r);t&&(i=Math.max(i,parseInt(t[1],10)))}return`thread-${i+1}`})(),o=await f(e,r);if(!o){await l();return}let s=o.getReader(),c=new TextDecoder,u=``,d=!1,p=null,m=!0,h=[{type:`system`,content:`Creating thread "${i}"...`}];try{for(;;){let{done:n,value:r}=await s.read();if(n)break;u+=c.decode(r,{stream:!0});let o=u.split(`
68
- `);u=o.pop()??``;for(let n of o){let r=n.trim();if(r)try{let n=JSON.parse(r);if(n.type===`progress`){if(!d&&n.threadId){d=!0,p=n.threadId,t({type:Z.AddCreatingThread,projectId:e,threadId:n.threadId,title:i}),t({type:Z.AddProcessingThread,threadId:n.threadId}),t({type:Z.ClearTerminalOutput,threadId:p});for(let e of h)t({type:Z.AppendTerminalLine,threadId:p,line:e});h.length=0}let r={type:`output`,content:n.message};p?t({type:Z.AppendTerminalLine,threadId:p,line:r}):h.push(r)}else if(n.type===`error`){d&&p&&(t({type:Z.RemoveCreatingThread,projectId:e,threadId:p}),t({type:Z.RemoveProcessingThread,threadId:p}));let r={type:`error`,content:`Error: ${n.message}`};p?t({type:Z.AppendTerminalLine,threadId:p,line:r}):h.push(r),console.error(`Thread creation error:`,n.message),a({title:`Thread Creation Failed`,description:n.message,variant:`destructive`}),m=!1}}catch(e){console.error(`Failed to parse thread event`,e)}}}d&&p&&t({type:Z.RemoveProcessingThread,threadId:p}),F(),await l(),p&&m&&t({type:Z.SelectThread,threadId:p,projectId:e,focusInput:!0})}catch(n){throw d&&p&&(t({type:Z.RemoveCreatingThread,projectId:e,threadId:p}),t({type:Z.RemoveProcessingThread,threadId:p})),a({title:`Thread Creation Failed`,description:n instanceof Error?n.message:String(n),variant:`destructive`}),n}}catch(e){console.error(`Failed to create thread:`,e);let n=`Failed to create thread: ${e instanceof Error?e.message:`Unknown error`}`;throw t({type:Z.AppendTerminalLine,line:{type:`error`,content:n}}),a({variant:`destructive`,title:`Thread Creation Failed`,description:n}),e}},[l,t,n,a]),v=(0,Y.useCallback)(async(e,n)=>{t({type:Z.AddDeletingThread,threadId:n}),t({type:Z.ClearChatInputDraft,threadId:n});try{await A(e,n),i===n&&t({type:Z.SelectThread,threadId:``,projectId:``}),await l(),t({type:Z.ConfigUpdated})}catch(e){console.error(`Failed to delete thread:`,e),a({variant:`destructive`,title:`Failed to delete thread`,description:e instanceof Error?e.message:`Unknown error`})}finally{t({type:Z.RemoveDeletingThread,threadId:n})}},[l,i,t,a]),y=(0,Y.useCallback)(async e=>{t({type:Z.AddDeletingProject,projectId:e});let i=n.find(t=>t.projectId===e)?.threads.map(e=>e.threadId)??[];for(let e of i)t({type:Z.AddDeletingThread,threadId:e}),t({type:Z.ClearChatInputDraft,threadId:e});try{await B(e),r===e&&t({type:Z.SelectThread,threadId:``,projectId:``}),await l(),t({type:Z.ConfigUpdated})}catch(e){console.error(`Failed to delete project:`,e)}finally{t({type:Z.RemoveDeletingProject,projectId:e});for(let e of i)t({type:Z.RemoveDeletingThread,threadId:e})}},[l,r,n,t]),b=(0,Y.useCallback)(async e=>{let n=s;if(c(null),!n||!e)return;let{projectId:r,command:i,remainingScripts:a}=n,o=[i,...a||[]];try{t({type:Z.SetCreatingProject,isCreating:!0}),t({type:Z.SetTerminalOpen,open:!0}),t({type:Z.AppendTerminalLine,line:{type:`system`,content:`Installing dependencies for ${o.length} package${o.length===1?``:`s`}...`}});for(let e=0;e<o.length;e++){let n=o[e],i=n.match(/^cd "([^"]+)" && (.+)$/),a=i?i[1]:`root`;t({type:Z.AppendTerminalLine,line:{type:`system`,content:`Installing package ${e+1}/${o.length} in ${a}...`}}),t({type:Z.AppendTerminalLine,line:{type:`output`,content:`📦 Installing dependencies in ${a}: ${n}`}});let s=await h(r,n,!0);if(s){let e=s.getReader(),n=new TextDecoder,r=``;for(;;){let{done:i,value:a}=await e.read();if(i)break;r+=n.decode(a,{stream:!0});let o=r.split(`
69
- `);r=o.pop()??``;for(let e of o)if(e.trim())try{let n=JSON.parse(e);typeof n==`string`?t({type:Z.AppendTerminalLine,line:{type:`output`,content:n}}):n.type===`error`&&t({type:Z.AppendTerminalLine,line:{type:`error`,content:n.message}})}catch{t({type:Z.AppendTerminalLine,line:{type:`output`,content:e}})}}if(r.trim())try{let e=JSON.parse(r);typeof e==`string`?t({type:Z.AppendTerminalLine,line:{type:`output`,content:e}}):e.type===`error`&&t({type:Z.AppendTerminalLine,line:{type:`error`,content:e.message}})}catch{t({type:Z.AppendTerminalLine,line:{type:`output`,content:r}})}}e<o.length-1&&(t({type:Z.AppendTerminalLine,line:{type:`system`,content:``}}),t({type:Z.AppendTerminalLine,line:{type:`system`,content:`---`}}),t({type:Z.AppendTerminalLine,line:{type:`system`,content:``}}))}t({type:Z.AppendTerminalLine,line:{type:`system`,content:`All dependencies installed successfully!`}}),t({type:Z.SetCreatingProject,isCreating:!1}),await l()}catch(e){t({type:Z.SetCreatingProject,isCreating:!1}),console.error(`Failed to run setup script:`,e),t({type:Z.AppendTerminalLine,line:{type:`error`,content:`Failed to run setup script: ${e instanceof Error?e.message:`Unknown error`}`}})}},[s,t,l]);return{projects:n,selectedProjectId:r,selectedThreadId:i,refreshProjects:l,handleSelectThread:u,handleCreateProject:p,handleCreateWebApp:m,handleCreateFolder:g,handleOpenFolder:(0,Y.useCallback)(async()=>{await d({apiCall:Re,initialMessage:`Opening folder...`,optimisticProjectName:`Opening folder...`,useTerminalDispatch:!0,handleSetupScript:!0,logTag:`open folder`,catchErrorPrefix:`Failed to open folder`})},[d]),handleCreateThread:_,handleDeleteThread:v,confirmDeleteProject:y,pendingSetupScriptConfirmation:s,resolveSetupScriptConfirmation:b}}function Ip(){let e=(0,X.c)(2),[t,n]=(0,Y.useState)(Lp),r,i;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=()=>{let e=()=>n(!0),t=()=>n(!1);return window.addEventListener(`focus`,e),window.addEventListener(`blur`,t),()=>{window.removeEventListener(`focus`,e),window.removeEventListener(`blur`,t)}},i=[],e[0]=r,e[1]=i):(r=e[0],i=e[1]),(0,Y.useEffect)(r,i),t}function Lp(){return document.hasFocus()}var Rp=null;function zp(){Rp??=new Audio(`/pop.wav`),Rp.currentTime=0,Rp.play().catch(e=>{console.debug(`Could not play completion sound:`,e)})}function Bp(){let e=yi(),t=vi(),n=Q(e=>e.processingThreadIds),r=Q(e=>e.completedThreadIds),i=Q(e=>e.isCreatingProject),a=Q(e=>Object.values(e.threadStreamingStates).some(e=>e.isStreaming)),o=Ip(),s=(0,Y.useRef)(null),c=(0,Y.useRef)(!1),l=(0,Y.useRef)([]),u=(0,Y.useRef)(o);(0,Y.useEffect)(()=>{u.current=o},[o]);let d=(0,Y.useCallback)(async()=>{try{let n=md(await dt()),r=l.current.filter(e=>!n.includes(e));for(let n of r)n!==t.getState().selectedThreadId&&e({type:Z.MarkThreadCompleted,threadId:n});return r.length>0&&!u.current&&zp(),l.current=n,e({type:Z.SetProcessingThreads,threadIds:n}),n}catch(e){return console.error(`Failed to fetch processing threads:`,e),[]}},[e,t]);return(0,Y.useEffect)(()=>{let e=()=>{if(s.current||c.current)return;c.current=!0;let e=async()=>{let n=await d(),r=t.getState(),i=Object.values(r.threadStreamingStates).some(e=>e.isStreaming);n.length>0||i||r.isCreatingProject?s.current=setTimeout(e,1e3):(s.current=null,c.current=!1)};e()},n=()=>{s.current&&=(clearTimeout(s.current),null),c.current=!1};return e(),()=>{n()}},[n.length,a,i,d]),{processingThreadIds:n,completedThreadIds:r,isThreadProcessing:e=>n.includes(e),isThreadCompleted:e=>r.includes(e),clearCompleted:(0,Y.useCallback)(t=>{e({type:Z.ClearThreadCompleted,threadId:t})},[e])}}var Vp=(0,Y.lazy)(()=>pr(()=>import(`./terminal-panel-BGQxckfH.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([12,1,5]))),Hp=(0,Y.lazy)(()=>pr(()=>import(`./diff-view-Bi545EPj.js`),__vite__mapDeps([6,1,3,4,7,5,8,9,10,11]))),Up=(0,Y.lazy)(()=>pr(()=>import(`./explorer-tab-view-B-P555GE.js`),__vite__mapDeps([13,1,3,4,7,5]))),Wp=(0,Y.lazy)(()=>pr(()=>import(`./browser-tab-D7wEj-BD.js`).then(e=>({default:e.BrowserTab})),__vite__mapDeps([14,1,5]))),Gp=(0,Y.lazy)(()=>pr(()=>import(`./dialogs-config-B-LZ4nOb.js`).then(e=>e.t),__vite__mapDeps([5,1]))),Kp=(0,Y.lazy)(()=>pr(()=>import(`./onboarding-Bbvb7kO4.js`).then(e=>e.t),__vite__mapDeps([8,1,7,5]))),qp=(0,Y.lazy)(()=>pr(()=>import(`./settings-view-BlVJv4Pz.js`),__vite__mapDeps([15,1,3,4,7,5,8,16,17,10])));function Jp(e){return e.startsWith(`/settings`)||e===`/review`}function Yp(){let e=(0,X.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center bg-background`,children:(0,$.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-2 border-muted border-t-primary`})}),e[0]=t):t=e[0],t}function Xp(){let e=yi(),t=Q(e=>e.selectedThreadId),n=Q(e=>e.selectedProjectId),r=Q(e=>e.sidebarOpen),i=Q(e=>e.deletingThreadIds),a=Q(e=>e.deletingProjectIds);(0,Y.useEffect)(()=>{window.__electrobunWebviewId&&new Yr({})},[]);let o=$n(),s=cr(),c=jc(),l=c||E(),[u,d]=(0,Y.useState)(null),{projects:f,handleSelectThread:p,handleCreateProject:m,handleCreateWebApp:h,handleCreateFolder:g,handleOpenFolder:_,handleCreateThread:v,handleDeleteThread:y,confirmDeleteProject:b,refreshProjects:x,pendingSetupScriptConfirmation:S,resolveSetupScriptConfirmation:C}=Fp({onProjectCreated:d}),{processingThreadIds:w,completedThreadIds:T,clearCompleted:D}=Bp(),[O,k]=(0,Y.useState)(`chat`),[A,j]=(0,Y.useState)(null),[M,N]=(0,Y.useState)(!1),[P,F]=(0,Y.useState)(!1),[I,L]=(0,Y.useState)(!1),[R,ee]=(0,Y.useState)(null),[te,z]=(0,Y.useState)(0),[ne,B]=(0,Y.useState)(null),[re,V]=(0,Y.useState)(0),{terminalState:ie}=xi(t),ae=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{ie.open&&t===ae.current&&!Jp(s.pathname)&&k(`terminal`),ae.current=t},[ie.open,t,s.pathname]);let[oe,H]=(0,Y.useState)(!1),[se,ce]=(0,Y.useState)(!1),[le,ue]=(0,Y.useState)(!1),[de,fe]=(0,Y.useState)(null),[pe,me]=(0,Y.useState)(!1),[he,ge]=(0,Y.useState)(!1),_e=(0,Y.useRef)(null),ve=(0,Y.useRef)(null),ye=s.pathname.startsWith(`/settings`),be=s.pathname===`/review`;(0,Y.useEffect)(()=>{c&&(ve.current?.querySelector(`[data-tab="${O}"]`))?.scrollIntoView({inline:`nearest`,block:`nearest`})},[O,c]);let xe=(0,Y.useRef)(O),Se=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{if(ye){if(Se.current===null){Se.current=Date.now(),xe.current=O;return}xe.current!==O&&o(`/`)}else Se.current=null;xe.current=O},[O,ye,o]);let Ce=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{let t=ye||be;if(t&&Ce.current===null)Ce.current=r,r&&e({type:Z.ToggleSidebar});else if(!t&&Ce.current!==null){let t=Ce.current;Ce.current=null,t&&!r&&e({type:Z.ToggleSidebar})}},[ye,be]),(0,Y.useEffect)(()=>{(async()=>{try{(await Ot()).updateAvailable&&me(!0)}catch{}})()},[]);let we=(0,Y.useCallback)(async()=>{ge(!0);try{await Vt()}catch{ge(!1)}},[]);(0,Y.useEffect)(()=>{le||(async()=>{try{(await Dt()).onboardingCompleted||ce(!0)}catch(e){console.error(`Failed to check onboarding status:`,e)}finally{ue(!0)}})()},[le]),(0,Y.useEffect)(()=>{se||e({type:Z.ConfigUpdated})},[se,e]);let Te=(0,Y.useCallback)(e=>{let t=f.find(t=>t.projectId===e);t&&fe({id:t.projectId,name:ot(t)})},[f]),Ee=(0,Y.useCallback)(e=>{d(e),v(e,void 0)},[v]);(0,Y.useEffect)(()=>{u&&n===u&&t&&d(null)},[u,n,t]);let De=(0,Y.useCallback)(async(n,r)=>{d(null),D(r),s.pathname!==`/`&&o(`/`),k(`chat`),t!==r&&V(e=>e+1),p(n,r),l&&e({type:Z.CloseSidebar})},[p,l,t,e,D,s.pathname,o]);(0,Y.useEffect)(()=>{r?_e.current?.expand():_e.current?.collapse()},[r]);let Oe={activeMainTab:O,setActiveMainTab:k,devServerUrl:A,setDevServerUrl:j,devServerRunning:M,setDevServerRunning:N,devServerLoading:P,setDevServerLoading:F,terminalNotification:I,setTerminalNotification:L,pendingExplorerPath:R,setPendingExplorerPath:ee,explorerRefreshTick:te,triggerExplorerRefresh:()=>z(e=>e+1),explorerClearPath:ne,setExplorerClearPath:B,browserResetTrigger:re,triggerBrowserReset:()=>V(e=>e+1)};return(0,$.jsxs)(Pa.Provider,{value:Oe,children:[(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(jp,{})}),(0,$.jsxs)(Nt,{delayDuration:200,children:[(0,$.jsxs)(gp,{direction:`horizontal`,className:`h-screen bg-background`,children:[(0,$.jsx)(_p,{ref:_e,defaultSize:l?100:25,minSize:l?50:12,maxSize:l?100:32,collapsible:!0,collapsedSize:0,className:q(`border-r border-transparent`,l&&!r&&`hidden`),children:(0,$.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,$.jsx)(Hi,{projects:f,selectedThreadId:t,selectedProjectId:n,processingThreadIds:w,completedThreadIds:T,deletingThreadIds:i,deletingProjectIds:a,onSelectThread:De,onCreateProject:()=>H(!0),onCreateThread:Ee,onDeleteThread:y,onDeleteProject:Te,onDeselect:()=>e({type:Z.ClearSelection}),collapsed:!r,updateAvailable:pe,updatingApp:he,onUpdateApp:we,expandProjectId:u})})}),!l&&(0,$.jsx)(vp,{withHandle:!0,className:r?`ml-[-40px]`:``}),(0,$.jsx)(_p,{minSize:40,className:q(`overflow-hidden`,l&&r&&`hidden`),children:(0,$.jsx)(cd,{threadId:t??void 0,children:(0,$.jsx)(Ou,{children:(0,$.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[!be&&!ye&&(0,$.jsx)(sp,{}),!be&&!ye&&t&&(0,$.jsx)(`div`,{ref:ve,className:`flex shrink-0 select-none overflow-x-auto overflow-y-hidden border-b border-border`,children:[`Chat`,`Explorer`,`Review`,`Browser`,`Terminal`].map(e=>{let t=e.toLowerCase();return(0,$.jsxs)(`button`,{"data-tab":t,onClick:()=>{k(t),t===`terminal`&&L(!1)},className:`relative shrink-0 px-4 py-2 text-base font-medium transition-colors ${O===t?`border-b-2 border-primary text-foreground -mb-px`:`text-muted-foreground hover:text-foreground`}`,children:[e,t===`terminal`&&I&&O!==`terminal`&&(0,$.jsx)(`span`,{className:`absolute top-1.5 right-1 h-1.5 w-1.5 rounded-full bg-brand`})]},t)})}),(0,$.jsx)(`main`,{className:`flex-1 overflow-hidden${!be&&!ye&&O!==`chat`?` hidden`:``}`,children:(0,$.jsxs)(ar,{children:[(0,$.jsx)(Qn,{path:`/settings/providers/:providerSlug`,element:(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(Yp,{}),children:(0,$.jsx)(qp,{})})}),(0,$.jsx)(Qn,{path:`/settings/project/:projectId`,element:(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(Yp,{}),children:(0,$.jsx)(qp,{})})}),(0,$.jsx)(Qn,{path:`/settings/:tab?`,element:(0,$.jsx)(Y.Suspense,{fallback:(0,$.jsx)(Yp,{}),children:(0,$.jsx)(qp,{})})}),(0,$.jsx)(Qn,{path:`*`,element:(0,$.jsx)(Wf,{onCreateThread:Ee})})]})}),(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden${O===`terminal`&&!be&&!ye?``:` hidden`}`,children:(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Vp,{})})}),(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden${O===`browser`&&!be&&!ye?``:` hidden`}`,children:(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Wp,{})})}),!be&&!ye&&O!==`chat`&&O!==`terminal`&&O!==`browser`&&(O===`explorer`?(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Up,{})}):O===`review`&&t?(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Hp,{threadId:t,onExit:()=>k(`chat`)})}):(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden`}))]})})})}),(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Gp,{open:oe,onOpenChange:H,onSubmitClone:m,onSubmitWebApp:h,onSubmitFolder:g,onOpenFolder:_})}),(0,$.jsx)(fp,{open:de!==null,projectName:de?.name,onOpenChange:e=>!e&&fe(null),onConfirm:()=>{de&&(b(de.id),fe(null))}}),(0,$.jsx)(pp,{open:S!==null,setupScripts:S?[S.command,...S.remainingScripts||[]]:[],onConfirm:C}),(0,$.jsx)(Y.Suspense,{fallback:null,children:(0,$.jsx)(Kp,{open:se,onOpenChange:ce,onComplete:()=>{ue(!0),x()}})}),(0,$.jsx)(hp,{})]}),(0,$.jsx)(Dp,{})]})]})}function Zp(){let e=(0,X.c)(3),[t]=(0,Y.useState)(gi),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(Xp,{}),e[0]=n):n=e[0];let r;return e[1]===t?r=e[2]:(r=(0,$.jsx)(Ap,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,storageKey:`tarsk-theme`,children:(0,$.jsx)(_i.Provider,{value:t,children:n})}),e[1]=t,e[2]=r),r}var Qp=75,$p=125,em=100;function tm(){return window.matchMedia(`(max-width: 767px)`).matches}function nm(e){let t=xe(e,tm());document.documentElement.style.fontSize=`${t}%`}var rm=!1;function im(){rm||(rm=!0,window.matchMedia(`(max-width: 767px)`).addEventListener(`change`,()=>{nm(Be(em))}))}function am(){let[e,t]=(0,Y.useState)(()=>Be(em));(0,Y.useEffect)(()=>{im(),nm(e)},[e]);function n(e){let n=Math.max(Qp,Math.min($p,Math.round(e)));t(n),zt(n)}return{scale:e,updateScale:n,resetScale:(0,Y.useCallback)(()=>{n(em)},[]),min:Qp,max:$p,default:em}}function om(){im(),nm(Be(em))}var sm;(function(e){e.Dark=`DARK`,e.Light=`LIGHT`,e.Default=`DEFAULT`})(sm||={});var cm;(function(e){e.None=`NONE`,e.Slide=`SLIDE`,e.Fade=`FADE`})(cm||={});var lm=Sf(`StatusBar`),um=`--app-viewport-height`;function dm(){let e=window.visualViewport,t=Math.round(Oe()===`ios`?window.innerHeight:e?.height??window.innerHeight);document.documentElement.style.setProperty(um,`${t}px`)}function fm(){dm(),requestAnimationFrame(dm)}function pm(){document.documentElement.dataset.nativeShell=`true`,fm(),window.addEventListener(`resize`,dm),window.addEventListener(`orientationchange`,fm);let e=window.visualViewport;e?.addEventListener(`resize`,dm),e?.addEventListener(`scroll`,dm)}async function mm(){try{await lm.hide(),fm()}catch{}}async function hm(){try{let e=Oe()===`ios`?If.None:If.Body;await Lf.setResizeMode({mode:e})}catch{}}function gm(){E()&&(pm(),mm(),hm(),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&(fm(),mm())}))}om(),gm();var _m=!1;window.addEventListener(`resize`,()=>{_m||=(window.__electrobunWebviewId&&(document.body.style.height=`calc(100%)`),!0)}),(0,Vr.createRoot)(document.getElementById(`root`)).render((0,$.jsx)(Y.StrictMode,{children:(0,$.jsx)(tr,{children:(0,$.jsx)(Zp,{})})}));export{yi as A,Fa as C,Ti as D,Ii as E,xi as M,Si as O,Ha as S,Vi as T,ys as _,ap as a,Eo as b,sf as c,Zu as d,lu as f,hs as g,ms as h,gp as i,Q as j,Z as k,cf as l,ls as m,vp as n,of as o,jc as p,_p as r,lf as s,am as t,Cd as u,us as v,ha as w,To as x,wo as y};