wind-agent-cli 1.38.2 → 1.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/dist/api-docs.html +4 -3
- package/dist/assets/{CodeEditor-C6BtLdoC.js → CodeEditor-C8eMIGen.js} +1 -1
- package/dist/assets/{FileTree-CGxNFZda.js → FileTree-D52nAPO4.js} +1 -1
- package/dist/assets/{GitPanel-BV-IAyEC.js → GitPanel-DgeKbZsW.js} +1 -1
- package/dist/assets/{MarkdownPreview-DVoEzpoc.js → MarkdownPreview-B00VQTx6.js} +1 -1
- package/dist/assets/{Shell-CUTO-THd.js → Shell-twzi9t5B.js} +7 -7
- package/dist/assets/{StandaloneShell-BKM1qxUc.js → StandaloneShell-DH_GBJMj.js} +1 -1
- package/dist/assets/{TaskMasterPanel-DDDCVF6M.js → TaskMasterPanel-BY-pMPMl.js} +2 -2
- package/dist/assets/{abnfDiagram-N423BO3Z-Crubtav6.js → abnfDiagram-N423BO3Z-BwBdstkH.js} +1 -1
- package/dist/assets/{arc-h9xb7EWA.js → arc-C0IOpbFP.js} +1 -1
- package/dist/assets/{architectureDiagram-T3A2C74G-BmMQp4MC.js → architectureDiagram-T3A2C74G-C-Wkj_AY.js} +1 -1
- package/dist/assets/{blockDiagram-VBNYF7ZC-BtD-zDnJ.js → blockDiagram-VBNYF7ZC-_sXAZKku.js} +1 -1
- package/dist/assets/{c4Diagram-5PPSVZJV-D18s6J-v.js → c4Diagram-5PPSVZJV-C0DUsZv8.js} +1 -1
- package/dist/assets/channel-B6xiB58V.js +1 -0
- package/dist/assets/{chunk-2GRJ4B5K-BHIcCvB_.js → chunk-2GRJ4B5K-D2TFB_6A.js} +1 -1
- package/dist/assets/{chunk-2Q5K7J3B-DcX4AeRe.js → chunk-2Q5K7J3B-B_co_2bI.js} +1 -1
- package/dist/assets/{chunk-5RXB4S5H-CZwYDv9K.js → chunk-5RXB4S5H-BcUSLq4H.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-CR-F7R13.js → chunk-5VM5RSS4-0mQFBKSp.js} +1 -1
- package/dist/assets/{chunk-6Q2QTUOP-BPP216SB.js → chunk-6Q2QTUOP-BAkqmW1M.js} +1 -1
- package/dist/assets/{chunk-GF5L2VYU-CcFeSmHe.js → chunk-GF5L2VYU-Cyz0Xl7f.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-C5T_9-OI.js → chunk-JWPE2WC7-DYO47aT-.js} +1 -1
- package/dist/assets/{chunk-KBJHAD2P-g5eR5X5h.js → chunk-KBJHAD2P-DvXEzV8J.js} +1 -1
- package/dist/assets/{chunk-RYQCIY6F-76WBDsoZ.js → chunk-RYQCIY6F-Beut8dYt.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-DGuy3LLn.js → chunk-XXDRQBXY-DLIy1GFl.js} +1 -1
- package/dist/assets/classDiagram-JCYQIIEL-C7xIPTll.js +1 -0
- package/dist/assets/classDiagram-v2-OCEON4UE-C7xIPTll.js +1 -0
- package/dist/assets/{cose-bilkent-JH36ORCC-Cg4R1M0H.js → cose-bilkent-JH36ORCC-DynbO4dj.js} +1 -1
- package/dist/assets/{cynefin-VYW2F7L2-Cbmals-o.js → cynefin-VYW2F7L2-CYTJsH3o.js} +1 -1
- package/dist/assets/{cynefinDiagram-MW4NZA55-CI79hpHc.js → cynefinDiagram-MW4NZA55-ftj-lAeE.js} +1 -1
- package/dist/assets/{dagre-VZM6K2ZE-r3Uz8Fhv.js → dagre-VZM6K2ZE-C1kSFboe.js} +1 -1
- package/dist/assets/{diagram-7IWD3JNH-ClRIkmQw.js → diagram-7IWD3JNH-CqXHTFrY.js} +1 -1
- package/dist/assets/{diagram-B4RE2ZJO-C71qkNlS.js → diagram-B4RE2ZJO-B84n3Zko.js} +1 -1
- package/dist/assets/{diagram-LBJQPF4R-CC7ShhCC.js → diagram-LBJQPF4R-B710SefS.js} +1 -1
- package/dist/assets/{diagram-Q27KOJAE-DPHL4vnP.js → diagram-Q27KOJAE-CmVPl9pq.js} +1 -1
- package/dist/assets/{diagram-UB23O5K3-CP_My5E9.js → diagram-UB23O5K3-LozbeaFL.js} +1 -1
- package/dist/assets/{ebnfDiagram-BXEA7PRR-BQe4AU9Z.js → ebnfDiagram-BXEA7PRR-B321UBUA.js} +1 -1
- package/dist/assets/{erDiagram-JOGREHBK-CFidQ-d5.js → erDiagram-JOGREHBK-CTbw676k.js} +1 -1
- package/dist/assets/feature-chat-pY0kOrz2.js +88 -0
- package/dist/assets/feature-workspace-FLomYkPq.js +39 -0
- package/dist/assets/{flowDiagram-UKHOOZJN-X5fPFxbp.js → flowDiagram-UKHOOZJN-BWVKTWlw.js} +1 -1
- package/dist/assets/{ganttDiagram-PKOTCBZU-CILFHjP8.js → ganttDiagram-PKOTCBZU-BAj9eeeX.js} +1 -1
- package/dist/assets/{gitGraphDiagram-DS77QQ5N-DCQCtC_g.js → gitGraphDiagram-DS77QQ5N-DcVMRU7N.js} +1 -1
- package/dist/assets/{index-cNARKAN2.js → index-BYFstHFT.js} +1 -1
- package/dist/assets/index-BbBSplOU.js +35 -0
- package/dist/assets/{index-D0vbG70l.js → index-BrWTp075.js} +1 -1
- package/dist/assets/index-CHukVVB2.css +1 -0
- package/dist/assets/{index-Bo9nFrtn.js → index-k9M0VaFg.js} +1 -1
- package/dist/assets/{infoDiagram-6WML65LV-Da145n1G.js → infoDiagram-6WML65LV-V6wz33B4.js} +1 -1
- package/dist/assets/{ishikawaDiagram-WSZJBQD7-DGUP61eq.js → ishikawaDiagram-WSZJBQD7-Dd-WNPyK.js} +1 -1
- package/dist/assets/{journeyDiagram-NVQOT4AX-BqfnKWDJ.js → journeyDiagram-NVQOT4AX-D9VCuCeA.js} +1 -1
- package/dist/assets/{kanban-definition-27J2QSJJ-US6pQfNy.js → kanban-definition-27J2QSJJ-CUtwDOl-.js} +1 -1
- package/dist/assets/{linear-d91wK5kZ.js → linear-D_XGf1jO.js} +1 -1
- package/dist/assets/{mermaid.core-BsWqrIaW.js → mermaid.core-DOnsXioB.js} +4 -4
- package/dist/assets/{mindmap-definition-FAOFIHXS-CXWD2UbS.js → mindmap-definition-FAOFIHXS-DAYNL5ZV.js} +1 -1
- package/dist/assets/{pegDiagram-VL7TDLO6-BVzfDR-8.js → pegDiagram-VL7TDLO6-B5FX3-E6.js} +1 -1
- package/dist/assets/{pieDiagram-7S7Q4E2Y-PNpHZnJ9.js → pieDiagram-7S7Q4E2Y-EbnDBVd0.js} +1 -1
- package/dist/assets/{quadrantDiagram-CIZ2JOQS-DxCI4i3K.js → quadrantDiagram-CIZ2JOQS-C1koOtwT.js} +1 -1
- package/dist/assets/{railroadDiagram-AXF67PYL-BYkvo3om.js → railroadDiagram-AXF67PYL-D52xmshj.js} +1 -1
- package/dist/assets/{requirementDiagram-LRYGKXZP-LUtvOYtV.js → requirementDiagram-LRYGKXZP-B7VbfNnW.js} +1 -1
- package/dist/assets/{sankeyDiagram-W5VNT64P-CVyI8YeM.js → sankeyDiagram-W5VNT64P-CeRG1vHN.js} +1 -1
- package/dist/assets/{sequenceDiagram-SI44F4Z6-1vuRFolM.js → sequenceDiagram-SI44F4Z6-CfKHnmSE.js} +1 -1
- package/dist/assets/{sizeCapture-X5ZJPWSS-o4oVZXe8.js → sizeCapture-X5ZJPWSS-DJTzyd0S.js} +1 -1
- package/dist/assets/{stateDiagram-OKZ733FA-WedLIlXF.js → stateDiagram-OKZ733FA-DN0c7IYD.js} +1 -1
- package/dist/assets/stateDiagram-v2-UEYNNEHI-DbihlVOQ.js +1 -0
- package/dist/assets/{swimlanes-SLNWSIFB-CpeXuk67.js → swimlanes-SLNWSIFB-CaaJpBDA.js} +2 -2
- package/dist/assets/swimlanesDiagram-ULZ7WXOC-BBRevuGP.js +8 -0
- package/dist/assets/{timeline-definition-Z64GVDOM-DFcPWe47.js → timeline-definition-Z64GVDOM-CrzHN7d2.js} +1 -1
- package/dist/assets/{vennDiagram-T6HMQDX7-BH8C1C49.js → vennDiagram-T6HMQDX7-BTldHIjo.js} +1 -1
- package/dist/assets/{wardleyDiagram-T6FBY63Y-K1Ew0uit.js → wardleyDiagram-T6FBY63Y-D9Y50OsZ.js} +1 -1
- package/dist/assets/{xychartDiagram-ELKLHX3M-CQHlqWY2.js → xychartDiagram-ELKLHX3M-DjxSJ3aF.js} +1 -1
- package/dist/favicon.png +0 -0
- package/dist/icons/icon-128x128.png +0 -0
- package/dist/icons/icon-144x144.png +0 -0
- package/dist/icons/icon-152x152.png +0 -0
- package/dist/icons/icon-180x180.png +0 -0
- package/dist/icons/icon-192x192.png +0 -0
- package/dist/icons/icon-384x384.png +0 -0
- package/dist/icons/icon-512x512.png +0 -0
- package/dist/icons/icon-72x72.png +0 -0
- package/dist/icons/icon-96x96.png +0 -0
- package/dist/icons/icon-maskable-192x192.png +0 -0
- package/dist/icons/icon-maskable-512x512.png +0 -0
- package/dist/icons/new.png +0 -0
- package/dist/index.html +4 -4
- package/dist/logo-128.png +0 -0
- package/dist/logo-256.png +0 -0
- package/dist/sw.js +1 -1
- package/dist-server/server/index.js +2 -0
- package/dist-server/server/index.js.map +1 -1
- package/dist-server/server/modules/agent/agent.routes.js +14 -2
- package/dist-server/server/modules/agent/agent.routes.js.map +1 -1
- package/dist-server/server/modules/agent/tests/agent.routes.test.js +1 -0
- package/dist-server/server/modules/agent/tests/agent.routes.test.js.map +1 -1
- package/dist-server/server/modules/commands/commands.routes.js +2 -1
- package/dist-server/server/modules/commands/commands.routes.js.map +1 -1
- package/dist-server/server/modules/database/migrations.js +43 -0
- package/dist-server/server/modules/database/migrations.js.map +1 -1
- package/dist-server/server/modules/database/tests/projects.db.integration.test.js +24 -1
- package/dist-server/server/modules/database/tests/projects.db.integration.test.js.map +1 -1
- package/dist-server/server/modules/notifications/services/notification-orchestrator.service.js +2 -0
- package/dist-server/server/modules/notifications/services/notification-orchestrator.service.js.map +1 -1
- package/dist-server/server/modules/providers/list/opencode/opencode-session-synchronizer.provider.js +10 -1
- package/dist-server/server/modules/providers/list/opencode/opencode-session-synchronizer.provider.js.map +1 -1
- package/dist-server/server/modules/providers/list/pi/index.js +5 -0
- package/dist-server/server/modules/providers/list/pi/index.js.map +1 -0
- package/dist-server/server/modules/providers/list/pi/pi-auth.provider.js +55 -0
- package/dist-server/server/modules/providers/list/pi/pi-auth.provider.js.map +1 -0
- package/dist-server/server/modules/providers/list/pi/pi-mcp.provider.js +23 -0
- package/dist-server/server/modules/providers/list/pi/pi-mcp.provider.js.map +1 -0
- package/dist-server/server/modules/providers/list/pi/pi-models.provider.js +99 -0
- package/dist-server/server/modules/providers/list/pi/pi-models.provider.js.map +1 -0
- package/dist-server/server/modules/providers/list/pi/pi-runtime.provider.js +262 -0
- package/dist-server/server/modules/providers/list/pi/pi-runtime.provider.js.map +1 -0
- package/dist-server/server/modules/providers/list/pi/pi-session-synchronizer.provider.js +136 -0
- package/dist-server/server/modules/providers/list/pi/pi-session-synchronizer.provider.js.map +1 -0
- package/dist-server/server/modules/providers/list/pi/pi-sessions.provider.js +225 -0
- package/dist-server/server/modules/providers/list/pi/pi-sessions.provider.js.map +1 -0
- package/dist-server/server/modules/providers/list/pi/pi-skills.provider.js +31 -0
- package/dist-server/server/modules/providers/list/pi/pi-skills.provider.js.map +1 -0
- package/dist-server/server/modules/providers/list/pi/pi.provider.js +22 -0
- package/dist-server/server/modules/providers/list/pi/pi.provider.js.map +1 -0
- package/dist-server/server/modules/providers/provider.registry.js +2 -0
- package/dist-server/server/modules/providers/provider.registry.js.map +1 -1
- package/dist-server/server/modules/providers/provider.routes.js +2 -1
- package/dist-server/server/modules/providers/provider.routes.js.map +1 -1
- package/dist-server/server/modules/providers/services/provider-capabilities.service.js +26 -0
- package/dist-server/server/modules/providers/services/provider-capabilities.service.js.map +1 -1
- package/dist-server/server/modules/providers/services/session-synchronizer.service.js +1 -0
- package/dist-server/server/modules/providers/services/session-synchronizer.service.js.map +1 -1
- package/dist-server/server/modules/providers/services/sessions-watcher.service.js +5 -0
- package/dist-server/server/modules/providers/services/sessions-watcher.service.js.map +1 -1
- package/dist-server/server/modules/providers/tests/mcp.test.js +4 -2
- package/dist-server/server/modules/providers/tests/mcp.test.js.map +1 -1
- package/dist-server/server/modules/providers/tests/opencode-sessions.test.js +56 -5
- package/dist-server/server/modules/providers/tests/opencode-sessions.test.js.map +1 -1
- package/dist-server/server/modules/providers/tests/pi-provider.test.js +244 -0
- package/dist-server/server/modules/providers/tests/pi-provider.test.js.map +1 -0
- package/dist-server/server/modules/providers/tests/provider-runtime.service.test.js +9 -0
- package/dist-server/server/modules/providers/tests/provider-runtime.service.test.js.map +1 -1
- package/dist-server/server/shared/utils.js +19 -0
- package/dist-server/server/shared/utils.js.map +1 -1
- package/package.json +1 -1
- package/public/api-docs.html +4 -3
- package/scripts/generate-pwa-icons.ps1 +1 -1
- package/server/index.ts +2 -0
- package/server/modules/agent/agent.module.ts +1 -1
- package/server/modules/agent/agent.routes.ts +15 -2
- package/server/modules/agent/tests/agent.routes.test.ts +1 -0
- package/server/modules/commands/commands.routes.ts +2 -1
- package/server/modules/database/migrations.ts +52 -0
- package/server/modules/database/tests/projects.db.integration.test.ts +28 -1
- package/server/modules/notifications/services/notification-orchestrator.service.js +2 -0
- package/server/modules/providers/README.md +5 -1
- package/server/modules/providers/list/opencode/opencode-session-synchronizer.provider.ts +18 -0
- package/server/modules/providers/list/pi/index.ts +4 -0
- package/server/modules/providers/list/pi/pi-auth.provider.ts +58 -0
- package/server/modules/providers/list/pi/pi-mcp.provider.ts +33 -0
- package/server/modules/providers/list/pi/pi-models.provider.ts +114 -0
- package/server/modules/providers/list/pi/pi-runtime.provider.ts +271 -0
- package/server/modules/providers/list/pi/pi-session-synchronizer.provider.ts +134 -0
- package/server/modules/providers/list/pi/pi-sessions.provider.ts +206 -0
- package/server/modules/providers/list/pi/pi-skills.provider.ts +37 -0
- package/server/modules/providers/list/pi/pi.provider.ts +33 -0
- package/server/modules/providers/provider.registry.ts +2 -0
- package/server/modules/providers/provider.routes.ts +1 -0
- package/server/modules/providers/services/provider-capabilities.service.ts +32 -0
- package/server/modules/providers/services/session-synchronizer.service.ts +1 -0
- package/server/modules/providers/services/sessions-watcher.service.ts +5 -0
- package/server/modules/providers/tests/mcp.test.ts +4 -2
- package/server/modules/providers/tests/opencode-sessions.test.ts +81 -6
- package/server/modules/providers/tests/pi-provider.test.ts +244 -0
- package/server/modules/providers/tests/provider-runtime.service.test.ts +10 -0
- package/server/shared/types.ts +1 -1
- package/server/shared/utils.ts +23 -0
- package/dist/assets/channel-CuR3zGvy.js +0 -1
- package/dist/assets/classDiagram-JCYQIIEL-BWpl-4NG.js +0 -1
- package/dist/assets/classDiagram-v2-OCEON4UE-BWpl-4NG.js +0 -1
- package/dist/assets/feature-chat-CHKsDTs-.js +0 -88
- package/dist/assets/feature-workspace-BodovOw6.js +0 -39
- package/dist/assets/index-Bn37f1jp.js +0 -35
- package/dist/assets/index-Cr5MbHuj.css +0 -1
- package/dist/assets/stateDiagram-v2-UEYNNEHI-BqzvLVVB.js +0 -1
- package/dist/assets/swimlanesDiagram-ULZ7WXOC-CeI6fByR.js +0 -8
- package/dist/icons/new-icon.png +0 -0
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mermaid.core-BsWqrIaW.js","assets/feature-workspace-BodovOw6.js","assets/vendor-react-C2GTiUCy.js","assets/vendor-ui-CAUHSABu.js","assets/vendor-i18n-B6HjLCnN.js","assets/vendor-data-DsEZeNPr.js","assets/vendor-markdown-DkITEES2.js","assets/Shell-CUTO-THd.js","assets/Shell-DrlLKa8f.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as o,j as t,d as er,b as qt}from"./vendor-react-C2GTiUCy.js";import{a as $e,p as Br,b as Qn,c as jr,C as Dt,d as Et,e as Ft,f as Ae,g as Vt,u as Os,_ as Ps,h as Yn,Q as Xn,i as Zn,j as ea,k as ta,l as _s,m as ra,n as sa,S as Nr,o as na,q as aa,B as Qe,r as or,v as Ds,V as qr,L as tr,R as Vr,s as Hr,t as zr,w as Fs,I as Cr,x as jt,D as Sr,y as oa,z as Mr,A as Tr,E as la,F as ia,G as ca,H as da,J as ua,K as Wr,P as Xt,M as ma,N as pa,O as fa,T as xa,U as fr,W as ha,X as ga,Y as ba,Z as ya,$ as ka,a0 as wa,a1 as va,a2 as ja,a3 as Na}from"./feature-workspace-BodovOw6.js";import{V as Ca,t as It,o as Ut,q as Us,$ as Rr,ap as Sa,X as it,aa as Bs,aq as Ma,ar as Ta,as as qs,d as Vs,L as $t,ad as Ea,at as Ia,au as $a,av as La,C as rr,m as Hs,ag as Ra,n as Aa,aw as Oa,ax as zs,U as Ar,h as Bt,ay as Kr,S as Pa,az as _a,ae as Da,a9 as Fa,Z as Ua,aA as Ba,aB as qa,aC as Ws,r as Va,aD as Ha,aE as za,aF as Wa,j as Ks,aG as Ka,F as Ga,a as Or,g as Ja,x as Qa,aj as Ya,A as lr,aH as Xa,T as Za,aI as eo,v as to,aJ as ro,aK as so,aL as no,aM as ao,aN as Gs,aO as Js,aP as oo,aQ as Pr,aR as sr,aS as Qs,aT as lo,aU as io,O as co,b as uo,aV as mo}from"./vendor-ui-CAUHSABu.js";import{y as po,t as fo,a as xo,s as ho,b as go,p as bo,c as yo,m as ko,d as wo,j as vo,e as jo,f as No,g as Co,h as So,i as Mo,k as To,l as Eo,n as Io,o as $o,S as ct,r as Gr,q as Jr,u as Lo,v as Ro,M as Ao,w as Oo,x as Po}from"./vendor-markdown-DkITEES2.js";import{u as We,T as _o}from"./vendor-i18n-B6HjLCnN.js";const Ys=o.createContext(null);function Do(){return o.useContext(Ys)}const rt="default",Qr={claude:["low","medium","high","xhigh","max"],codex:["low","medium","high","xhigh","max","ultra"],opencode:["none","low","medium","high","xhigh","max"]},Fo=e=>e.map(r=>({value:r})),zt={claude:"default",cursor:"gpt-5.3-codex",codex:"gpt-5.4",opencode:"anthropic/claude-sonnet-4-5"},_t=["claude","cursor","codex","opencode"],Uo=()=>{const e=localStorage.getItem("selected-provider");return _t.includes(e)?e:"claude"},Bo={claude:["default","auto","acceptEdits","bypassPermissions","plan"],cursor:["default","acceptEdits","bypassPermissions","plan"],codex:["default","acceptEdits","bypassPermissions"],opencode:["default","acceptEdits","bypassPermissions","plan"]},Wt=(e,r)=>`${e}:${r}`;function qo({selectedSession:e,selectedProject:r}){const[s,a]=o.useState("default"),[n,l]=o.useState([]),[i,c]=o.useState(Uo),[d,u]=o.useState(()=>localStorage.getItem("cursor-model")||zt.cursor),[x,v]=o.useState(()=>localStorage.getItem("claude-model")||zt.claude),[g,b]=o.useState(()=>localStorage.getItem("codex-model")||zt.codex),[N,k]=o.useState(()=>_t.reduce((C,S)=>(C[S]=localStorage.getItem(`${S}-effort`)||rt,C),{})),[E,w]=o.useState(()=>localStorage.getItem("opencode-model")||zt.opencode),[L,f]=o.useState(null),[m,p]=o.useState({}),[h,y]=o.useState(!0),I=o.useRef(0),T=o.useRef(0),j=o.useRef(0),A=o.useRef(0),_=o.useCallback((C,S)=>{if(C==="claude"){v(S),localStorage.setItem("claude-model",S);return}if(C==="cursor"){u(S),localStorage.setItem("cursor-model",S);return}if(C==="codex"){b(S),localStorage.setItem("codex-model",S);return}w(S),localStorage.setItem("opencode-model",S)},[]),H=o.useCallback((C,S)=>{k(F=>F[C]===S?F:{...F,[C]:S}),localStorage.setItem(`${C}-effort`,S)},[]),M=o.useCallback(async()=>{const C=I.current+1;I.current=C,y(!0);try{const S=await Promise.all(_t.map(async q=>{const de=await(await $e(`/api/providers/${q}/models`)).json();return!de.success||!de.data?.models?null:de.data.models}));if(I.current!==C)return;const F={};_t.forEach((q,W)=>{const de=S[W];de&&(F[q]=de)}),p(F)}catch(S){console.error("Error loading provider models:",S)}finally{I.current===C&&y(!1)}},[]);o.useEffect(()=>{M()},[M]),o.useEffect(()=>{let C=!1;return(async()=>{try{const q=await(await $e("/api/providers/capabilities")).json();if(C||!q.success||!Array.isArray(q.data?.providers))return;const W={};for(const de of q.data.providers)W[de.provider]=de;f(W)}catch(F){console.error("Error loading provider capabilities:",F)}})(),()=>{C=!0}},[]);const O=o.useCallback(C=>{const S=L?.[C]?.permissionModes;return S&&S.length>0?S:Bo[C]??["default"]},[L]),$=o.useCallback(C=>{const S=O(C),F=L?.[C]?.defaultPermissionMode;return F&&S.includes(F)?F:S[0]??"default"},[O,L]),P=o.useCallback(C=>{const S=L?.[C]?.supportsEffort;return typeof S=="boolean"?S:!!Qr[C]?.length},[L]),B=(C,S,F)=>{const q=localStorage.getItem(C);return q&&F.OPTIONS.some(W=>W.value===q)?q:S&&F.OPTIONS.some(W=>W.value===S)?S:F.DEFAULT},z=o.useCallback((C,S)=>{const F=m[C];return F?F.OPTIONS.find(q=>q.value===S)??null:null},[m]),U=o.useCallback((C,S)=>{if(!P(C))return[];const F=z(C,S);return F?F.effort?.values??[]:Fo(Qr[C]??[])},[z,P]),ee=o.useCallback((C,S)=>U(C,S).map(F=>F.value),[U]),ie=o.useCallback((C,S,F)=>{const q=ee(C,S);return q.length===0||F===rt||!F?rt:q.includes(F)?F:rt},[ee]),X=o.useMemo(()=>({claude:x,cursor:d,codex:g,opencode:E}),[x,d,g,E]);o.useEffect(()=>{const C=m.claude;if(C){const S=B("claude-model",x,C);S!==x&&v(S),localStorage.getItem("claude-model")!==S&&localStorage.setItem("claude-model",S)}},[m.claude,x]),o.useEffect(()=>{const C=m.cursor;if(C){const S=B("cursor-model",d,C);S!==d&&u(S),localStorage.getItem("cursor-model")!==S&&localStorage.setItem("cursor-model",S)}},[m.cursor,d]),o.useEffect(()=>{const C=m.codex;if(C){const S=B("codex-model",g,C);S!==g&&b(S),localStorage.getItem("codex-model")!==S&&localStorage.setItem("codex-model",S)}},[m.codex,g]),o.useEffect(()=>{const C=m.opencode;if(C){const S=B("opencode-model",E,C);S!==E&&w(S),localStorage.getItem("opencode-model")!==S&&localStorage.setItem("opencode-model",S)}},[m.opencode,E]),o.useEffect(()=>{const C={};let S=!1;for(const F of _t){const q=N[F]??rt,W=ie(F,X[F],q);W!==q&&(C[F]=W,localStorage.setItem(`${F}-effort`,W),S=!0)}S&&k(F=>({...F,...C}))},[N,X,ie]),o.useEffect(()=>{const C=O(i),S=e?.id?localStorage.getItem(`permissionMode-${e.id}`):null,F=localStorage.getItem(`permissionMode-last-${i}`),q=[S,F].find(W=>!!(W&&C.includes(W)));a(q??$(i))},[e?.id,i,$,O]),o.useEffect(()=>{!e?.__provider||e.__provider===i||(c(e.__provider),localStorage.setItem("selected-provider",e.__provider))},[i,e]),o.useEffect(()=>{l(C=>C.filter(S=>!S.sessionId||S.sessionId===e?.id))},[e?.id]);const pe=o.useCallback(C=>{a(C),localStorage.setItem(`permissionMode-last-${i}`,C),e?.id&&localStorage.setItem(`permissionMode-${e.id}`,C)},[i,e?.id]),me=o.useCallback(()=>{const C=O(i),F=(C.indexOf(s)+1)%C.length;pe(C[F])},[s,i,O,pe]),he=o.useMemo(()=>O(i),[O,i]),Y=o.useCallback((C,S)=>O(C).includes(S)?S:$(C),[$,O]),[le,ae]=o.useState(null),K=e?.id?.trim()||null,ce=e?.__provider??i,ge=K?Wt(ce,K):null,fe=o.useRef(ge);fe.current=ge;const be=le&&K&&le.sessionId===K&&le.provider===ce?le:null,oe=be?.model??null;o.useEffect(()=>{const C=T.current+1;if(T.current=C,!K){ae(null);return}let S=!1;const F=ce,q=Wt(F,K);return(async()=>{try{const Ce=await(await $e(`/api/providers/${F}/sessions/${encodeURIComponent(K)}/active-model`)).json();if(S||T.current!==C||fe.current!==q)return;const xe=Ce.data?.model?.trim(),Se=Ce.data?.effort?.trim()||null;ae({provider:F,sessionId:K,model:Ce.success&&xe&&Ce.data?.source!=="default"?xe:null,effort:Ce.success?Se:null})}catch(de){!S&&T.current===C&&fe.current===q&&(console.error("Error loading the session model and reasoning effort:",de),ae({provider:F,sessionId:K,model:null,effort:null}))}})(),()=>{S=!0}},[K,ce]);const ne=o.useCallback(async(C,S,F)=>{_(C,S);const q=typeof F=="string"?F.trim():"";if(!q)return{scope:"default",model:S};T.current+=1;const W=j.current+1;j.current=W;const de=Wt(C,q),Ce=await $e(`/api/providers/${C}/sessions/${encodeURIComponent(q)}/active-model`,{method:"POST",body:JSON.stringify({model:S})}),xe=await Ce.json();if(!Ce.ok||!xe.success)throw new Error("Unable to change the active model for this session.");const Se=xe.data?.model?.trim()||S;return j.current===W&&fe.current===de&&ae(Re=>({provider:C,sessionId:q,model:Se,effort:Re?.provider===C&&Re.sessionId===q?Re.effort:xe.data?.effort?.trim()||null})),{scope:"session",model:Se}},[_]),ve=o.useCallback(async(C,S,F)=>{H(C,S);const q=typeof F=="string"?F.trim():"";if(!q)return{scope:"default",effort:S};T.current+=1;const W=A.current+1;A.current=W;const de=Wt(C,q),Ce=le?.provider===C&&le.sessionId===q?le:null;ae({provider:C,sessionId:q,model:Ce?.model??null,effort:S});try{const xe=await $e(`/api/providers/${C}/sessions/${encodeURIComponent(q)}/active-effort`,{method:"POST",body:JSON.stringify({effort:S})}),Se=await xe.json();if(!xe.ok||!Se.success)throw new Error("Unable to change the reasoning effort for this session.");const Re=Se.data?.effort?.trim()||S;return A.current===W&&fe.current===de&&ae(_e=>({provider:C,sessionId:q,model:_e?.provider===C&&_e.sessionId===q?_e.model:Ce?.model??null,effort:Re})),{scope:"session",effort:Re}}catch(xe){throw A.current===W&&fe.current===de&&ae(Se=>Se?.provider===C&&Se.sessionId===q&&Se.effort===S?Ce:Se),xe}},[le,H]),Ne=oe??X[i],Pe=o.useMemo(()=>U(i,Ne),[Ne,U,i]),nt=o.useMemo(()=>ie(i,Ne,be?.effort??N[i]??rt),[be?.effort,Ne,i,N,ie]),je=o.useMemo(()=>m[i]?.OPTIONS??[],[i,m]),re=o.useCallback((C,S)=>{p(F=>({...F,[C]:S}))},[]),Ee=o.useCallback(async C=>{const S=await C.json();if(!C.ok||!S.success||!S.data?.model||!S.data.models)throw new Error(S.error?.message||"Unable to save this model.");return{model:S.data.model,models:S.data.models}},[]),Ie=o.useCallback(async(C,S)=>{const F=await $e(`/api/providers/${C}/models`,{method:"POST",body:JSON.stringify(S)}),q=await Ee(F);re(C,q.models)},[re,Ee]),ue=o.useCallback(async(C,S,F)=>{if(!S.recordId)throw new Error("This model cannot be edited.");const q=await $e(`/api/providers/${C}/models/${S.recordId}`,{method:"PATCH",body:JSON.stringify(F)}),W=await Ee(q);re(C,W.models),X[C]===S.value&&_(C,W.model.value),i===C&&oe===S.value&&ae(de=>de&&{...de,model:W.model.value})},[re,i,X,Ee,oe,_]),Ye=o.useCallback(async(C,S)=>{if(!S.recordId)throw new Error("This model cannot be deleted.");const F=await $e(`/api/providers/${C}/models/${S.recordId}`,{method:"DELETE"}),q=await Ee(F);re(C,q.models),X[C]===S.value&&_(C,q.models.DEFAULT),i===C&&oe===S.value&&ae(W=>W&&{...W,model:q.models.DEFAULT})},[re,i,X,Ee,oe,_]),Le=o.useMemo(()=>({create:Ie,update:ue,remove:Ye}),[Ie,Ye,ue]);return{provider:i,setProvider:c,cursorModel:d,setCursorModel:u,claudeModel:x,setClaudeModel:v,codexModel:g,setCodexModel:b,currentProviderEffort:nt,currentProviderEffortOptions:Pe,currentProviderModel:Ne,currentProviderModelOptions:je,opencodeModel:E,setOpenCodeModel:w,permissionMode:s,setPermissionMode:a,pendingPermissionRequests:n,setPendingPermissionRequests:l,availablePermissionModes:he,selectPermissionMode:pe,cyclePermissionMode:me,providerModelCatalog:m,providerModelsLoading:h,providerModelActions:Le,selectProviderModel:ne,selectProviderEffort:ve,resolvePermissionModeForProvider:Y}}const gt=20;function Vo(e,r={}){const s=new URLSearchParams;r.limit!==null&&r.limit!==void 0&&(s.set("limit",String(r.limit)),s.set("offset",String(r.offset??0)));const a=s.toString(),n=`/api/providers/sessions/${encodeURIComponent(e)}/messages`;return a?`${n}?${a}`:n}function Yr(e){if(e===void 0)return"";try{return JSON.stringify(e)}catch{return String(e)}}function Xs(e,r){return e.id===r.id?!0:e.provider!==r.provider||e.kind!==r.kind||e.timestamp!==r.timestamp||e.role!==r.role?!1:e.toolId||r.toolId?e.toolId===r.toolId:e.rowid!==void 0||r.rowid!==void 0?e.rowid===r.rowid:e.sequence!==void 0||r.sequence!==void 0?e.sequence===r.sequence:(e.content??"")===(r.content??"")&&(e.text??"")===(r.text??"")&&(e.toolName??"")===(r.toolName??"")&&(e.commandName??"")===(r.commandName??"")&&(e.parentToolUseId??"")===(r.parentToolUseId??"")&&Yr(e.toolInput)===Yr(r.toolInput)}function Zs(e,r){const s=Math.min(e.length,r.length);for(let a=s;a>0;a--){const n=e.length-a;let l=!0;for(let i=0;i<a;i++)if(!Xs(e[n+i],r[i])){l=!1;break}if(l)return a}return 0}function Ho(e,r,s,a,n=0){if(e.length===0||r.length===0||Zs(e,r)>0)return null;const l=Math.max(0,a-s),i=Math.max(0,l-r.length-n),c=n===0?Math.max(1,i+1):gt;return{offset:r.length+n,limit:c}}function zo(e,r){const s=e[e.length-1],a=r[0];if(!s||!a)return!1;const n=Date.parse(s.timestamp),l=Date.parse(a.timestamp);return!Number.isFinite(n)||!Number.isFinite(l)?!1:l<=n}function Xr(e,r){if(e.length===0)return{messages:r,overlapLength:0};if(r.length===0)return{messages:e,overlapLength:0};const s=Zs(e,r);return s===0?{messages:e,overlapLength:0}:{messages:[...e.slice(0,e.length-s),...r],overlapLength:s}}function en(e,r){const s=Math.min(e.length,r.length);let a=0;for(let l=s;l>0;l--){const i=r.length-l;let c=!0;for(let d=0;d<l;d++)if(!Xs(r[i+d],e[d])){c=!1;break}if(c){a=l;break}}const n=r.length-a;return{messages:[...r.slice(0,n),...e],overlapLength:a,prependedCount:n}}function Wo(e,r,s,a){return{offset:r,hasMore:(e===0||s)&&a}}function Ko(e,r){const s=new Set,a=new Map,n=l=>{const i=a.get(l);if(i)return s.add(l),i;const c=(async()=>{try{do if(s.delete(l),await e(l)===!1){s.add(l);break}while(s.has(l)&&r(l))}catch{s.add(l)}})().finally(()=>{a.delete(l)});return a.set(l,c),c};return{request(l,i=!0){return!i||!r(l)?(s.add(l),Promise.resolve()):n(l)},flushPending(l){return!s.has(l)||!r(l)?Promise.resolve():n(l)},discardPending(l){s.delete(l)},hasPending(l){return s.has(l)}}}const Go=(e,r)=>{const s=e.split(`
|
|
3
|
-
`),a=r.split(`
|
|
4
|
-
`),n=Array.from({length:s.length+1},()=>new Array(a.length+1).fill(0));for(let d=s.length-1;d>=0;d-=1)for(let u=a.length-1;u>=0;u-=1)s[d]===a[u]?n[d][u]=n[d+1][u+1]+1:n[d][u]=Math.max(n[d+1][u],n[d][u+1]);const l=[];let i=0,c=0;for(;i<s.length&&c<a.length;){const d=s[i],u=a[c];if(d===u){i+=1,c+=1;continue}if(n[i+1][c]>=n[i][c+1]){l.push({type:"removed",content:d,lineNum:i+1}),i+=1;continue}l.push({type:"added",content:u,lineNum:c+1}),c+=1}for(;i<s.length;)l.push({type:"removed",content:s[i],lineNum:i+1}),i+=1;for(;c<a.length;)l.push({type:"added",content:a[c],lineNum:c+1}),c+=1;return l},Jo=()=>{const e=new Map;return(r,s)=>{const a=JSON.stringify([r,s]),n=e.get(a);if(n)return n;const l=Go(r,s);if(e.set(a,l),e.size>100){const i=e.keys().next().value;i&&e.delete(i)}return l}};function Qo(e){if(!e||typeof e!="string")return e;try{return e.replace(/```[ \t]*([^\n\r]+?)[ \t]*```/g,"`$1`")}catch{return e}}function tn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Yo(e){if(!e||typeof e!="string")return e;const r=/^\s*<proposed_plan>[ \t]*(?:\r?\n)?/i;return r.test(e)?e.replace(r,"").replace(/(?:\r?\n)?[ \t]*<\/proposed_plan>\s*$/i,""):e}function Er(e){try{return typeof e!="string"?e:e.replace(/Claude AI usage limit reached\|(\d{10,13})/g,(r,s)=>{let a=parseInt(s,10);if(!Number.isFinite(a))return r;a<1e12&&(a*=1e3);const n=new Date(a),l=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1}).format(n),i=-n.getTimezoneOffset(),c=i>=0?"+":"-",d=Math.abs(i),u=Math.floor(d/60),x=d%60,v=`GMT${c}${u}${x?":"+String(x).padStart(2,"0"):""}`,N=((Intl.DateTimeFormat().resolvedOptions().timeZone||"").split("/").pop()||"").replace(/_/g," ").toLowerCase().replace(/\b\w/g,L=>L.toUpperCase()),k=N?`${v} (${N})`:v,E=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],w=`${n.getDate()} ${E[n.getMonth()]} ${n.getFullYear()}`;return`Claude usage limit reached. Your limit will reset at **${l} ${k}** - ${w}`})}catch{return e}}function Zr(e){const r=typeof e=="string"?e:JSON.stringify(e),s=/^<tool_use_error>([\s\S]*)<\/tool_use_error>$/.exec(r.trim());return s?s[1]:r}function Xo(e){if(!e.trimStart().startsWith("<task-notification>"))return null;const r=/<status>([\s\S]*?)<\/status>/.exec(e),s=/<summary>([\s\S]*?)<\/summary>/.exec(e);let a="";const n=e.indexOf("<result>");if(n!==-1){const l=e.slice(n+8),i=l.indexOf("</result>");a=i===-1?l.replace(/<\/task-notification>\s*$/,"").trim():l.slice(0,i).trim()}return{status:r?.[1]?.trim()||"completed",summary:s?.[1]?.trim()||"Background task finished",result:a}}function Zo(e){const r=[],s=new Map,a=new Set;for(const n of e)n.kind==="tool_use"&&n.toolId&&a.add(n.toolId),n.kind==="tool_result"&&n.toolId&&s.set(n.toolId,n);for(const n of e){const l={displayText:n.displayText,commandName:n.commandName,commandMessage:n.commandMessage,commandArgs:n.commandArgs,isLocalCommand:n.isLocalCommand,isLocalCommandStdout:n.isLocalCommandStdout,isCompactSummary:n.isCompactSummary};switch(n.kind){case"text":{const i=n.content||"",c=Array.isArray(n.images)&&n.images.length>0?n.images:void 0,d=Array.isArray(n.files)&&n.files.length>0?n.files:void 0;if(!i.trim()&&!c&&!d)continue;if(n.role==="user"){const u=Xo(i);u?(r.push({type:"assistant",content:u.summary,timestamp:n.timestamp,isTaskNotification:!0,taskStatus:u.status,...l}),u.result&&r.push({type:"assistant",content:Er(u.result),timestamp:n.timestamp,...l})):r.push({type:"user",content:i,timestamp:n.timestamp,images:c,files:d,...l})}else{const u=Er(i);r.push({type:"assistant",content:u,timestamp:n.timestamp,...l})}break}case"tool_use":{const i=n.toolResult||(n.toolId?s.get(n.toolId):null),c=n.toolName==="Task",d=[];if(c&&n.subagentTools&&Array.isArray(n.subagentTools))for(const x of n.subagentTools)d.push({toolId:x.toolId,toolName:x.toolName,toolInput:x.toolInput,toolResult:x.toolResult||null,timestamp:new Date(x.timestamp||Date.now())});const u=i?{content:Zr(i.content),isError:!!i.isError,toolUseResult:i.toolUseResult}:null;r.push({type:"assistant",content:"",timestamp:n.timestamp,isToolUse:!0,toolName:n.toolName,toolInput:typeof n.toolInput=="string"?n.toolInput:JSON.stringify(n.toolInput??"",null,2),toolId:n.toolId,toolResult:u,isSubagentContainer:c,subagentState:c?{childTools:d,currentToolIndex:d.length>0?d.length-1:-1,isComplete:!!u}:void 0,...l});break}case"thinking":n.content?.trim()&&r.push({type:"assistant",content:n.content,timestamp:n.timestamp,isThinking:!0,...l});break;case"error":r.push({type:"error",content:n.content||"Unknown error",timestamp:n.timestamp,...l});break;case"interactive_prompt":r.push({type:"assistant",content:n.content||"",timestamp:n.timestamp,isInteractivePrompt:!0,...l});break;case"task_notification":r.push({type:"assistant",content:n.summary||"Background task update",timestamp:n.timestamp,isTaskNotification:!0,taskStatus:n.status||"completed",...l});break;case"stream_delta":n.content&&r.push({type:"assistant",content:n.content,timestamp:n.timestamp,isStreaming:!0,...l});break;case"stream_end":case"complete":case"status":case"permission_request":case"permission_cancelled":case"session_created":break;case"tool_result":{if(n.toolId&&a.has(n.toolId)||n.toolId)break;const i=Zr(n.content||"");if(!i.trim())break;r.push({type:n.isError?"error":"assistant",content:i,timestamp:n.timestamp,toolId:n.toolId,...l});break}}}return r}const Ot=100,el=[];function es(e){const r=e.getBoundingClientRect(),s=Array.from(e.querySelectorAll(".chat-message")).find(a=>a.getBoundingClientRect().bottom>=r.top)??null;return{height:e.scrollHeight,top:e.scrollTop,anchor:s,anchorOffset:s?s.getBoundingClientRect().top-r.top:null}}function ts(e,r,s){const a=`local_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,n=e.timestamp instanceof Date?e.timestamp.toISOString():typeof e.timestamp=="number"?new Date(e.timestamp).toISOString():String(e.timestamp),l={id:a,sessionId:r,timestamp:n,provider:s};return e.isToolUse?{...l,kind:"tool_use",toolName:e.toolName,toolInput:e.toolInput,toolId:e.toolId||a}:e.isThinking?{...l,kind:"thinking",content:e.content||""}:e.isInteractivePrompt?{...l,kind:"interactive_prompt",content:e.content||""}:e.isTaskNotification?{...l,kind:"task_notification",status:e.taskStatus||"completed",summary:e.content||""}:e.type==="error"?{...l,kind:"error",content:e.content||""}:{...l,kind:"text",role:e.type==="user"?"user":"assistant",content:e.content||"",images:Array.isArray(e.images)&&e.images.length>0?e.images:void 0,files:Array.isArray(e.files)&&e.files.length>0?e.files:void 0}}function tl({isActive:e,selectedProject:r,selectedSession:s,ws:a,sendMessage:n,externalMessageUpdate:l,newSessionTrigger:i,processingSessions:c,onSessionIdle:d,resetStreamingState:u,statusCheckSentAtRef:x,lastSeqRef:v,sessionStore:g}){const[b,N]=o.useState(s?.id||null),[k,E]=o.useState(!1),[w,L]=o.useState(!1),[f,m]=o.useState(!1),[p,h]=o.useState(0),[y,I]=o.useState(!1),[T,j]=o.useState(null),[A,_]=o.useState(Ot),[H,M]=o.useState(!1),[O,$]=o.useState(!1),[P,B]=o.useState(!1),[z,U]=o.useState(!1),[ee,ie]=o.useState(0),X=o.useRef(null),pe=o.useRef(!1),[me,he]=o.useState(null),Y=o.useRef(!1),le=o.useRef(!1),ae=o.useRef(!1),K=o.useRef(!1),ce=o.useRef(null),ge=o.useRef(!0),fe=o.useRef(0),be=o.useRef({height:0,top:0}),oe=o.useRef(null),ne=o.useRef(null),ve=o.useRef(null),Ne=o.useRef(0),Pe=o.useRef(i??0),nt=o.useMemo(()=>Jo(),[]);o.useEffect(()=>{const R=i??0;R!==Pe.current&&(Pe.current=R,u(),N(null),de(null),fe.current=0,m(!1),h(0),j(null),_(Ot),M(!1),ae.current=!1,$(!1),B(!1),U(!1),ie(0),he(null),pe.current=!1,Y.current=!1,K.current=!1,ce.current=null,ge.current=!0,ve.current=null,ne.current&&(clearTimeout(ne.current),ne.current=null),oe.current&&(clearTimeout(oe.current),oe.current=null))},[i,d,u]);const je=s?.id??null,re=je||b||null,Ee=re&&c?.get(re)||null,Ie=Ee!==null,ue=Ie&&Ee.canInterrupt,Ye=o.useRef(c);Ye.current=c;const Le=o.useRef(e),C=o.useRef(re);Le.current=e,C.current=re;const S=o.useRef(async()=>!0);S.current=async R=>{const J=await g.refreshLatestFromServer(R,{limit:gt,canRequest:()=>Le.current&&C.current===R}),Z=J.slot;return Z&&C.current===R&&(m(Z.hasMore),h(Z.total),fe.current=Z.offset,Z.tokenUsage!==void 0&&j(Z.tokenUsage??null)),!J.deferred};const F=o.useRef(null);F.current||(F.current=Ko(R=>S.current(R),R=>Le.current&&C.current===R));const q=o.useCallback((R,J=Le.current)=>F.current?.request(R,J)??Promise.resolve(),[]),[W,de]=o.useState(null),Ce=o.useRef(null),xe=e?re:null,Se=o.useRef(null);xe!==Se.current&&(Se.current=xe,g.setActiveSession(xe)),o.useEffect(()=>{if(!W){Ce.current=null;return}if(!re||Ce.current===W)return;const R=localStorage.getItem("selected-provider")||"claude",J=ts(W,re,R);J&&g.appendRealtime(re,J),Ce.current=W,de(null)},[re,W,g]);const Re=re?g.getMessages(re):el,_e=o.useRef(0);Re.length!==_e.current&&(_e.current=Re.length,ee>0&&ie(0));const Me=o.useMemo(()=>{const R=Zo(Re);return W&&R.length===0?[W]:ee>0&&ee<R.length?R.slice(0,-ee):R},[Re,ee,W]),bt=o.useCallback(R=>{if(!re){de(R);return}const J=localStorage.getItem("selected-provider")||"claude",Z=ts(R,re,J);Z&&g.appendRealtime(re,Z)},[re,g]),dt=o.useCallback(()=>{re&&g.clearRealtime(re)},[re,g]),yt=o.useCallback(R=>ie(R),[]),Ue=o.useCallback(()=>{const R=X.current;R&&(R.scrollTop=R.scrollHeight)},[]),et=o.useCallback(()=>{Ue(),H&&(_(Ot),M(!1),ae.current=!1)},[H,Ue]),Je=o.useCallback(()=>{const R=X.current;if(!R)return!1;const{scrollTop:J,scrollHeight:Z,clientHeight:se}=R;return Z-J-se<50},[]),Be=o.useCallback(async R=>{if(!e||!R||le.current||w||ae.current||!f||!s||!r)return!1;le.current=!0,L(!0);const J=es(R);try{const Z=await g.fetchMore(s.id,{limit:gt,canRequest:()=>Le.current&&C.current===s.id}),{slot:se,prependedCount:ke}=Z;return m(se.hasMore),h(se.total),fe.current=se.offset,se.tokenUsage!==void 0&&j(se.tokenUsage??null),ke===0?(se.hasMore||(ae.current=!0,M(!0),ne.current&&(clearTimeout(ne.current),ne.current=null),U(!1)),!1):(ce.current=J,_(Te=>Te+gt),se.hasMore||(ae.current=!0,M(!0),ne.current&&(clearTimeout(ne.current),ne.current=null),U(!1)),!0)}finally{le.current=!1,L(!1)}},[f,e,w,r,s,g]),G=o.useCallback(async()=>{if(!e)return;const R=X.current;if(!R)return;const J=Je();I(!J),be.current={height:R.scrollHeight,top:R.scrollTop};const Z=R.scrollTop<100;if(Z&&f&&!ae.current?pe.current||(pe.current=!0,ne.current&&clearTimeout(ne.current),U(!0),ne.current=setTimeout(()=>{U(!1),ne.current=null},2500)):Z||(pe.current=!1),!ae.current){if(!Z){K.current=!1;return}if(K.current){R.scrollTop>20&&(K.current=!1);return}await Be(R)&&(K.current=!0)}},[f,e,Je,Be]),Oe=o.useRef(e);o.useLayoutEffect(()=>{const R=e&&!Oe.current;if(Oe.current=e,!e||!X.current)return;const J=X.current;if(ce.current){const{height:Z,top:se,anchor:ke,anchorOffset:Te}=ce.current;if(ke?.isConnected&&Te!==null){const qe=ke.getBoundingClientRect().top-J.getBoundingClientRect().top;J.scrollTop+=qe-Te}else J.scrollTop=se+Math.max(J.scrollHeight-Z,0);ce.current=null;return}R&&(J.scrollTop=y?be.current.top:J.scrollHeight)},[Me.length,e,y]),o.useEffect(()=>{Y.current||(ge.current=!0,_(Ot)),K.current=!1,ce.current=null,pe.current=!1,I(!1)},[r?.projectId,s?.id]),o.useEffect(()=>{if(!e||!ge.current||!X.current||k)return;if(Me.length===0){ge.current=!1;return}if(Y.current){ge.current=!1;return}const R=X.current;let J=0,Z=0,se=0,ke=0;const Te=()=>{!ge.current||!X.current||(R.scrollTop=R.scrollHeight,R.scrollHeight===Z?se++:(se=0,Z=R.scrollHeight),J++,se<3&&J<60?ke=requestAnimationFrame(Te):ge.current=!1)};return ke=requestAnimationFrame(Te),()=>{ke&&cancelAnimationFrame(ke)}},[Me.length,e,k,Ue]),o.useEffect(()=>{!s||!r||!a||(x.current.set(s.id,Date.now()),n({type:"chat.subscribe",sessions:[{sessionId:s.id,lastSeq:v.current.get(s.id)??0}]}))},[v,r,s,n,x,a]),o.useEffect(()=>{if(!je||!r){if(b&&Ye.current?.has(b))return;u(),N(null),fe.current=0,m(!1),h(0),j(null),ve.current=null,Ne.current+=1,E(!1);return}if(!e){E(!1);return}const R=`${je}:${r.projectId}`,J=g.getSessionSlot(je),Z=ve.current===R&&J?.status==="loading",se=ve.current===R&&!!J?.fetchedAt;if(Z)return;if(se){g.isStale(je)&&q(je);return}const ke=b!==null&&b!==je;ke&&u(),fe.current=0,m(!1),h(0),_(Ot),M(!1),ae.current=!1,$(!1),B(!1),U(!1),ie(0),pe.current=!1,ne.current&&clearTimeout(ne.current),oe.current&&clearTimeout(oe.current),ke&&j(null),N(je),ve.current=R;const Te=++Ne.current;E(!0),g.fetchFromServer(je,{limit:gt,offset:0,canRequest:()=>Le.current&&C.current===je}).then(qe=>{Ne.current!==Te||C.current!==je||qe&&(m(qe.hasMore),h(qe.total),fe.current=qe.offset,qe.tokenUsage!==void 0&&j(qe.tokenUsage??null))}).catch(()=>{}).finally(()=>{Ne.current===Te&&C.current===je&&E(!1)})},[e,b,u,q,r,je,g]),o.useEffect(()=>{if(!e||!re)return;const R=g.getSessionSlot(re);if(!R?.fetchedAt||R.status==="loading"){F.current?.discardPending(re);return}F.current?.flushPending(re)},[re,e,g]),o.useEffect(()=>{if(!l||!s||!r)return;(async()=>{try{if(!Ie){const J=Le.current&&Je();await q(s.id),J&&setTimeout(()=>Ue(),200)}}catch(J){console.error("Error reloading messages from external update:",J)}})()},[l,Je,q,Ue,r,s,Ie]),o.useEffect(()=>{const R=s,J=R?.__searchTargetSnippet,Z=R?.__searchTargetTimestamp;typeof J=="string"&&J&&(Y.current=!0,he({snippet:J,timestamp:typeof Z=="string"?Z:void 0}))},[s]),o.useEffect(()=>{if(!e||!me||Me.length===0||k)return;const R=me;he(null),(async()=>{if(!ae.current&&s&&r)try{const se=await g.fetchFromServer(s.id,{limit:null,offset:0,canRequest:()=>Le.current&&C.current===s.id});if(se)m(!1),h(se.total),fe.current=se.offset,_(1/0),M(!0),ae.current=!0,await new Promise(ke=>setTimeout(ke,300));else if(!Le.current){he(R);return}}catch{}_(1/0);const Z=se=>{const ke=X.current;if(!ke)return;let Te=null;if(R.snippet){const mt=R.snippet.replace(/^\.{3}/,"").replace(/\.{3}$/,"").trim().slice(0,80).toLowerCase().trim();if(mt.length>=10){const pt=ke.querySelectorAll(".chat-message");for(const ot of pt)if((ot.textContent||"").toLowerCase().includes(mt)){Te=ot;break}}}if(!Te&&R.timestamp){const qe=new Date(R.timestamp).getTime(),mt=ke.querySelectorAll("[data-message-timestamp]");let pt=1/0;for(const ot of mt){const kt=ot.getAttribute("data-message-timestamp");if(!kt)continue;const D=Math.abs(new Date(kt).getTime()-qe);D<pt&&(pt=D,Te=ot)}}Te?(Te.scrollIntoView({block:"center",behavior:"smooth"}),Te.classList.add("search-highlight-flash"),setTimeout(()=>Te?.classList.remove("search-highlight-flash"),4e3),Y.current=!1):se>0?setTimeout(()=>Z(se-1),200):Y.current=!1};setTimeout(()=>Z(15),150)})()},[Me.length,e,k,me]),o.useEffect(()=>{if(!s?.id){j(null);return}let R=!1;return(async()=>{try{const Z=`/api/providers/sessions/${encodeURIComponent(s.id)}/token-usage`,se=await $e(Z);if(R)return;if(se.ok){const ke=await se.json();if(R)return;j(ke.data??null)}else j(null)}catch(Z){R||console.error("Failed to fetch initial token usage:",Z)}})(),()=>{R=!0}},[s?.id]);const De=o.useMemo(()=>Me.length<=A?Me:Me.slice(-A),[Me,A]);o.useEffect(()=>{if(!e)return;const R=X.current;R&&(be.current={height:R.scrollHeight,top:R.scrollTop})}),o.useEffect(()=>{e&&(!X.current||Me.length===0||le.current||w||ce.current||Y.current||y||setTimeout(()=>Ue(),50))},[Me.length,e,w,y,Ue]),o.useEffect(()=>{const R=X.current;if(R)return R.addEventListener("scroll",G),()=>R.removeEventListener("scroll",G)},[G]);const ut=o.useCallback(async()=>{if(!e||!s||!r||O)return;const R=s.id;ae.current=!0,le.current=!0,$(!0),U(!0),ne.current&&(clearTimeout(ne.current),ne.current=null);const J=X.current,Z=J?es(J):null;try{const se=await g.fetchFromServer(R,{limit:null,offset:0,canRequest:()=>Le.current&&C.current===R});if(b!==R)return;se?(Z&&(ce.current=Z),m(!1),h(se.total),fe.current=se.offset,_(1/0),M(!0),B(!0),oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{B(!1),U(!1),oe.current=null},2500)):(ae.current=!1,U(!1))}catch(se){console.error("Error loading all messages:",se),ae.current=!1,U(!1)}finally{le.current=!1,$(!1)}},[e,s,r,O,b,g]),at=o.useCallback(()=>{_(R=>R+100)},[]);return{chatMessages:Me,addMessage:bt,clearMessages:dt,rewindMessages:yt,sessionActivity:Ee,isProcessing:Ie,canAbortSession:ue,currentSessionId:b,setCurrentSessionId:N,isLoadingSessionMessages:k,isLoadingMoreMessages:w,hasMoreMessages:f,totalMessages:p,isUserScrolledUp:y,setIsUserScrolledUp:I,tokenBudget:T,setTokenBudget:j,visibleMessageCount:A,visibleMessages:De,loadEarlierMessages:at,loadAllMessages:ut,allMessagesLoaded:H,isLoadingAllMessages:O,loadAllJustFinished:P,showLoadAllOverlay:z,createDiff:nt,scrollContainerRef:X,scrollToBottom:Ue,scrollToBottomAndReset:et,isNearBottom:Je,handleScroll:G,requestLatestMessages:q}}const rl="[Done]",sl=2e3;let Ze=null,Lt=!1;const _r=()=>`${rl} `,rn=e=>{const r=_r();return e.startsWith(r)?e.slice(r.length):e},sn=()=>document.visibilityState==="visible"&&document.hasFocus(),nl=()=>{!Lt||typeof window>"u"||(document.removeEventListener("visibilitychange",lt),window.removeEventListener("focus",lt,!0),window.removeEventListener("click",lt,!0),Lt=!1)},al=()=>{Ze!==null&&(window.clearTimeout(Ze),Ze=null),nl(),nn(),document.title.startsWith(_r())&&(document.title=rn(document.title))},nn=()=>{document.removeEventListener("visibilitychange",on)},an=()=>{Ze!==null&&window.clearTimeout(Ze),Ze=window.setTimeout(()=>{al()},sl),nn(),document.addEventListener("visibilitychange",on,{once:!0})};function lt(){sn()&&an()}function on(){document.visibilityState==="hidden"&&(Ze!==null&&(window.clearTimeout(Ze),Ze=null),Lt||(document.addEventListener("visibilitychange",lt),window.addEventListener("focus",lt,!0),window.addEventListener("click",lt,!0),Lt=!0))}const ol=()=>{if(typeof document>"u"||typeof window>"u")return;const e=rn(document.title||"WindCli");if(document.title=`${_r()}${e}`,sn()){an();return}Ze!==null&&(window.clearTimeout(Ze),Ze=null),Lt||(document.addEventListener("visibilitychange",lt),window.addEventListener("focus",lt,!0),window.addEventListener("click",lt,!0),Lt=!0)},ln=e=>e?.toolName!=="ExitPlanMode"&&e?.toolName!=="exit_plan_mode",rs=e=>Array.isArray(e)&&e.some(r=>ln(r));function ll({isActive:e,subscribe:r,provider:s,selectedSession:a,currentSessionId:n,setTokenBudget:l,pendingPermissionRequests:i,setPendingPermissionRequests:c,streamTimerRef:d,accumulatedStreamRef:u,lastSeqRef:x,statusCheckSentAtRef:v,onSessionProcessing:g,onSessionIdle:b,onWebSocketReconnect:N,requestLatestMessages:k,sessionStore:E}){const w=o.useRef(a?.id||n||null);w.current=a?.id||n||null;const L=o.useRef(e);L.current=e;const f=o.useRef(i);o.useEffect(()=>{f.current=i},[i]),o.useEffect(()=>r(p=>{if(!p.kind)return;const h=w.current,y=typeof p.sessionId=="string"&&p.sessionId||h;if(y&&typeof p.seq=="number"){const T=x.current.get(y)??0;p.seq>T&&x.current.set(y,p.seq)}switch(p.kind){case"websocket_reconnected":N?.();return;case"chat_subscribed":{if(!y)return;if(p.isProcessing?g?.(y):b?.(y,{ifStartedBefore:v.current.get(y)}),y===h&&Array.isArray(p.pendingPermissions)){const j=p.pendingPermissions,A=rs(f.current),_=rs(j);f.current=j,c(j),_&&!A&&Br()}return}case"protocol_error":{console.error("[Chat] Protocol error:",p.code,p.error),y&&(b?.(y),E.appendRealtime(y,{id:`protocol_error_${Date.now()}`,sessionId:y,timestamp:new Date().toISOString(),provider:s,kind:"error",content:String(p.error||"Request failed")}));return}case"session_upserted":case"loading_progress":return}if(p.kind==="stream_delta"){const T=p.content||"";if(!T)return;u.current+=T,d.current||(d.current=window.setTimeout(()=>{d.current=null,y&&E.updateStreaming(y,u.current,s)},100)),y&&y!==h&&E.appendRealtime(y,p);return}if(p.kind==="stream_end"){d.current&&(clearTimeout(d.current),d.current=null),y&&(u.current&&E.updateStreaming(y,u.current,s),E.finalizeStreaming(y)),u.current="";return}const I=p.kind!=="complete"&&p.kind!=="status"&&p.kind!=="permission_request"&&p.kind!=="permission_cancelled";switch(y&&I&&E.appendRealtime(y,p),p.kind){case"complete":{if(d.current&&(clearTimeout(d.current),d.current=null),y&&u.current&&(E.updateStreaming(y,u.current,s),E.finalizeStreaming(y)),u.current="",b?.(y),y===h&&(f.current=[],c([])),p.aborted)break;p.success!==!1&&(ol(),Qn()),y&&y===h&&k(y,L.current);break}case"permission_request":{if(!p.requestId)break;if(ln({toolName:p.toolName})&&Br(),y===h){const T=f.current;if(!T.some(j=>j.requestId===p.requestId)){const j=[...T,{requestId:p.requestId,toolName:p.toolName||"UnknownTool",provider:p.provider,input:p.input,context:p.context,sessionId:y||null,receivedAt:new Date}];f.current=j,c(j)}}y&&g?.(y);break}case"permission_cancelled":{if(p.requestId&&y===h){const T=f.current.filter(j=>j.requestId!==p.requestId);f.current=T,c(T)}break}case"status":{p.text==="token_budget"&&p.tokenBudget?l(p.tokenBudget):p.text&&y&&g?.(y,{statusText:p.text,canInterrupt:p.canInterrupt!==!1});break}}}),[r,s,a,n,l,i,c,d,u,x,v,g,b,N,k,E])}const cn="claude-settings",Ge={setItem:(e,r)=>{try{localStorage.setItem(e,r)}catch(s){if(s?.name==="QuotaExceededError"){console.warn("localStorage quota exceeded, clearing old data"),Object.keys(localStorage).filter(l=>l.startsWith("draft_input_")||l.startsWith("queued_message_")).forEach(l=>{localStorage.removeItem(l)});try{localStorage.setItem(e,r)}catch(l){console.error("Failed to save to localStorage even after cleanup:",l)}}else console.error("localStorage error:",s)}},getItem:e=>{try{return localStorage.getItem(e)}catch(r){return console.error("localStorage getItem error:",r),null}},removeItem:e=>{try{localStorage.removeItem(e)}catch(r){console.error("localStorage removeItem error:",r)}}},Dr=e=>`queued_message_${e}`;function dn(e){const r=Ge.getItem(Dr(e));if(!r)return null;try{const s=JSON.parse(r);if(s&&typeof s=="object"&&typeof s.content=="string"){const{content:a,options:n,images:l,attachments:i}=s,c=Array.isArray(i)?i:Array.isArray(l)?l:[];return a.trim()||c.length>0?{content:a,options:n,attachments:c}:null}}catch{}return r.trim()?{content:r}:null}function ss(e,r){Ge.setItem(Dr(e),JSON.stringify(r))}function ns(e){Ge.removeItem(Dr(e))}function un(){const e=Ge.getItem(cn);if(!e)return{allowedTools:[],disallowedTools:[],skipPermissions:!1,projectSortOrder:"name"};try{const r=JSON.parse(e);return{...r,allowedTools:Array.isArray(r.allowedTools)?r.allowedTools:[],disallowedTools:Array.isArray(r.disallowedTools)?r.disallowedTools:[],skipPermissions:!!r.skipPermissions,projectSortOrder:r.projectSortOrder||"name"}}catch{return{allowedTools:[],disallowedTools:[],skipPermissions:!1,projectSortOrder:"name"}}}function as(e,r){if(!e)return null;if(e!=="Bash")return e;let s=r;if(typeof r=="string")try{s=JSON.parse(r)}catch{return e}const a=s&&typeof s=="object"&&"command"in s&&typeof s.command=="string"?s.command.trim():"";if(!a)return e;const n=a.split(/\s+/);return n.length===0?e:n[0]==="git"&&n[1]?`Bash(${n[0]} ${n[1]}:*)`:`Bash(${n[0]}:*)`}function os(e){if(e==null)return"";if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function il(e){if(!e)return{success:!1};const r=un(),s=r.allowedTools.includes(e),a=s?r.allowedTools:[...r.allowedTools,e],n=r.disallowedTools.filter(i=>i!==e),l={...r,allowedTools:a,disallowedTools:n,lastUpdated:new Date().toISOString()};return Ge.setItem(cn,JSON.stringify(l)),{success:!0,alreadyAllowed:s,updatedSettings:l}}const mn=(e,r="")=>{let s=[];return e.forEach(a=>{const n=r?`${r}/${a.name}`:a.name;if(a.type==="directory"&&a.children){s=s.concat(mn(a.children,n));return}a.type==="file"&&s.push({name:a.name,path:n,relativePath:a.path})}),s};function cl({selectedProject:e,input:r,setInput:s,textareaRef:a}){const[n,l]=o.useState([]),[i,c]=o.useState([]),[d,u]=o.useState([]),[x,v]=o.useState(!1),[g,b]=o.useState(-1),[N,k]=o.useState(0),[E,w]=o.useState(-1);o.useEffect(()=>{const T=new AbortController;return(async()=>{const A=e?.projectId;if(l([]),u([]),!!A)try{const _=await jr.getMentionableFiles(A,{signal:T.signal});if(!_.ok)return;const H=await _.json();l(mn(H))}catch(_){if(_?.name==="AbortError")return;console.error("Error fetching files:",_)}})(),()=>{T.abort()}},[e?.projectId]),o.useEffect(()=>{const T=r.slice(0,N),j=T.lastIndexOf("@");if(j===-1){v(!1),w(-1);return}const A=T.slice(j+1);if(A.includes(" ")){v(!1),w(-1);return}w(j),v(!0),b(-1);const _=n.filter(H=>H.name.toLowerCase().includes(A.toLowerCase())||H.path.toLowerCase().includes(A.toLowerCase())).slice(0,10);u(_)},[r,N,n]);const L=o.useMemo(()=>!r||i.length===0?[]:i.filter(T=>r.includes(T)),[i,r]),f=o.useMemo(()=>L.length===0?[]:Array.from(new Set(L)).sort((j,A)=>A.length-j.length),[L]),m=o.useMemo(()=>{if(f.length===0)return null;const T=f.map(tn).join("|");return new RegExp(`(${T})`,"g")},[f]),p=o.useMemo(()=>new Set(f),[f]),h=o.useCallback(T=>T?m?T.split(m).map((A,_)=>p.has(A)?t.jsx("span",{className:"-ml-0.5 rounded-md bg-blue-200/70 box-decoration-clone px-0.5 text-transparent dark:bg-blue-300/40",children:A},`mention-${_}`):t.jsx("span",{children:A},`text-${_}`)):T:"",[m,p]),y=o.useCallback(T=>{const j=r.slice(0,E),A=r.slice(E),_=A.indexOf(" "),H=_!==-1?A.slice(_):"",M=`${j}${T.path} ${H}`,O=j.length+T.path.length+1;a.current&&!a.current.matches(":focus")&&a.current.focus(),s(M),k(O),c($=>$.includes(T.path)?$:[...$,T.path]),v(!1),w(-1),a.current&&requestAnimationFrame(()=>{a.current&&(a.current.setSelectionRange(O,O),a.current.matches(":focus")||a.current.focus())})},[r,E,a,s]),I=o.useCallback(T=>!x||d.length===0?!1:T.key==="ArrowDown"?(T.preventDefault(),b(j=>j<d.length-1?j+1:0),!0):T.key==="ArrowUp"?(T.preventDefault(),b(j=>j>0?j-1:d.length-1),!0):T.key==="Tab"||T.key==="Enter"?(T.preventDefault(),g>=0?y(d[g]):d.length>0&&y(d[0]),!0):T.key==="Escape"?(T.preventDefault(),v(!1),!0):!1,[x,d,g,y]);return{showFileDropdown:x,filteredFiles:d,selectedFileIndex:g,renderInputWithMentions:h,selectFile:y,setCursorPosition:k,handleFileMentionsKeyDown:I}}const dl=150,pn=e=>`command_history_${e}`,xr=e=>{const r=Ge.getItem(pn(e));if(!r)return{};try{return JSON.parse(r)}catch(s){return console.error("Error parsing command history:",s),{}}},ul=(e,r)=>{Ge.setItem(pn(e),JSON.stringify(r))},ml=e=>!!e&&typeof e.then=="function",pl=e=>e.type==="skill"||e.metadata?.type==="skill",ls=e=>pl(e)||e.metadata?.passthrough===!0,fl=e=>{const r=new Set;return e.filter(s=>{const a=s.command;return r.has(a)?!1:(r.add(a),!0)})},xl=e=>({name:e.command,description:e.description,namespace:"skill",path:e.sourcePath,type:"skill",metadata:{type:e.scope,scope:e.scope,sourcePath:e.sourcePath,pluginName:e.pluginName,pluginId:e.pluginId,skillName:e.name}}),hl=(e,r)=>{const s=r.trim().toLowerCase();if(!s)return e;const a=s.startsWith("/")?s:`/${s}`,n=e.filter(i=>i.name.toLowerCase().startsWith(a));if(s.includes(":")||n.length>0)return n;const l=e.filter(i=>i.name.toLowerCase().includes(s));return l.length>0?l:e.filter(i=>i.description?.toLowerCase().includes(s))};function gl({selectedProject:e,provider:r,input:s,setInput:a,textareaRef:n,onExecuteCommand:l}){const[i,c]=o.useState([]),[d,u]=o.useState([]),[x,v]=o.useState(!1),[g,b]=o.useState(""),[N,k]=o.useState(-1),[E,w]=o.useState(-1),L=o.useRef(null),f=o.useCallback(()=>{L.current!==null&&(window.clearTimeout(L.current),L.current=null)},[]),m=o.useCallback(()=>{v(!1),w(-1),b(""),k(-1),f()},[f]);o.useEffect(()=>{let M=!1;return(async()=>{if(!e){c([]),u([]);return}try{const $=e.fullPath||e.path||"",P=await $e("/api/commands/list",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectPath:$||e.path,provider:r})});if(!P.ok)throw new Error("Failed to fetch commands");const B=await P.json(),z=new URLSearchParams;$&&z.set("workspacePath",$);const U=await $e(`/api/providers/${encodeURIComponent(r)}/skills${z.toString()?`?${z.toString()}`:""}`),ee=U.ok?await U.json():null,ie=fl(ee?.data?.skills||[]).map(xl),X=[...(B.builtIn||[]).map(he=>({...he,type:"built-in"})),...ie,...(B.custom||[]).map(he=>({...he,type:"custom"}))],pe=xr(e.projectId),me=[...X].sort((he,Y)=>{const le=pe[he.name]||0;return(pe[Y.name]||0)-le});M||c(me)}catch($){console.error("Error fetching slash commands:",$),M||c([])}})(),()=>{M=!0}},[e,r]),o.useEffect(()=>{x||k(-1)},[x]),o.useEffect(()=>{u(hl(i,g))},[g,i]);const p=o.useMemo(()=>{if(!e||i.length===0)return[];const M=xr(e.projectId);return i.map(O=>({...O,usageCount:M[O.name]||0})).filter(O=>O.usageCount>0).sort((O,$)=>$.usageCount-O.usageCount).slice(0,5)},[e,i]),h=o.useCallback(M=>{if(!e)return;const O=xr(e.projectId);O[M.name]=(O[M.name]||0)+1,ul(e.projectId,O)},[e]),y=o.useCallback(M=>{const O=n.current,$=E>=0?E:O?.selectionStart??s.length,P=s.slice(0,$),B=s.slice($),z=B.indexOf(" "),U=E>=0&&z!==-1?B.slice(z).trimStart():s.slice(O?.selectionEnd??$),ee=P&&!/\s$/.test(P)?" ":"",ie=`${P}${ee}${M.name}${U?` ${U}`:" "}`;a(ie),m(),window.requestAnimationFrame(()=>{O?.focus();const X=`${P}${ee}${M.name} `.length;O?.setSelectionRange(X,X)})},[s,m,a,E,n]),I=o.useCallback(M=>{const O=l(M);ml(O)?O.then(()=>{m()},()=>{m()}):m()},[l,m]),T=o.useCallback(M=>{if(ls(M)){y(M);return}I(M)},[I,y]),j=o.useCallback((M,O,$)=>{if(!(!M||!e)){if($){k(O);return}if(h(M),ls(M)){y(M);return}I(M)}},[e,h,y,I]),A=o.useCallback(()=>{const M=!x;v(M),b(""),k(-1),M&&u(i),n.current?.focus()},[x,i,n]),_=o.useCallback((M,O)=>{if(!M.trim()){m();return}const $=M.slice(0,O);if(($.match(/```/g)||[]).length%2===1){m();return}const z=/(?:^|\s)(\/\S*)$/,U=$.match(z);if(!U){m();return}const ee=U.index+(U[0].length-U[1].length),ie=U[1].slice(1);w(ee),v(!0),k(-1),f(),L.current=window.setTimeout(()=>{b(ie)},dl)},[m,f]),H=o.useCallback(M=>x?d.length?M.key==="ArrowDown"?(M.preventDefault(),k(O=>O<d.length-1?O+1:0),!0):M.key==="ArrowUp"?(M.preventDefault(),k(O=>O>0?O-1:d.length-1),!0):M.key==="Tab"||M.key==="Enter"?(M.preventDefault(),N>=0?T(d[N]):d.length>0&&T(d[0]),!0):M.key==="Escape"?(M.preventDefault(),m(),!0):!1:M.key==="Escape"?(M.preventDefault(),m(),!0):!1:!1,[x,d,m,T,N]);return o.useEffect(()=>()=>{f()},[f]),{slashCommands:i,slashCommandsCount:i.length,filteredCommands:d,frequentCommands:p,commandQuery:g,showCommandMenu:x,selectedCommandIndex:N,resetCommandMenuState:m,handleCommandSelect:j,handleToggleCommandMenu:A,handleCommandInputChange:_,handleCommandMenuKeyDown:H}}const hr=()=>({preventDefault:()=>{}}),is=10,cs=10*1024*1024,ds=e=>e.mimeType?.startsWith("image/")?!0:/\.(gif|jpe?g|png|svg|webp)$/i.test(e.path||e.name||""),us=async e=>{if(e.length===0)return[];const r=new FormData;e.forEach(n=>{r.append("files",n)});const s=await $e("/api/assets/files",{method:"POST",headers:{},body:r});if(!s.ok){const n=await s.json().catch(()=>null);throw new Error(n?.error||"Failed to upload files")}const a=await s.json();if(!Array.isArray(a.attachments)||a.attachments.length!==e.length)throw new Error("File upload returned an incomplete result");return a.attachments},ms=e=>{const r=dn(e);return r?{content:r.content,attachments:[],uploadedAttachments:r.attachments??r.images,options:r.options}:null},ps=(e,r)=>{const s=e?.summary||e?.name||e?.title;if(typeof s=="string"&&s.trim()){const n=s.replace(/\s+/g," ").trim();return n.length>80?`${n.slice(0,77)}...`:n}const a=r.replace(/\s+/g," ").trim();return a?a.length>80?`${a.slice(0,77)}...`:a:null};function bl({selectedProject:e,selectedSession:r,currentSessionId:s,provider:a,permissionMode:n,cyclePermissionMode:l,resolvePermissionModeForProvider:i,currentProviderModel:c,currentProviderEffort:d,isLoading:u,processingSessions:x,canAbortSession:v,tokenBudget:g,sendMessage:b,sendByCtrlEnter:N,onSessionProcessing:k,onSessionEstablished:E,onInputFocusChange:w,onFileOpen:L,onShowSettings:f,scrollToBottom:m,addMessage:p,setIsUserScrolledUp:h,setPendingPermissionRequests:y}){const[I,T]=o.useState(()=>typeof window<"u"&&e&&Ge.getItem(`draft_input_${e.projectId}`)||""),[j,A]=o.useState([]),[_,H]=o.useState(new Map),[M,O]=o.useState(new Map),[$,P]=o.useState(!1),[B,z]=o.useState(null),U=o.useRef(null),ee=o.useRef(null),ie=o.useRef(null),X=o.useRef(null),pe=o.useRef(null),me=o.useRef(I),he=e?.projectId,Y=r?.id||s||null,le=o.useRef(Y),ae=o.useRef(x);le.current=Y,ae.current=x;const[K,ce]=o.useState(()=>typeof window>"u"||!Y?null:ms(Y)),ge=o.useRef(Y),fe=o.useCallback(D=>{const{action:Q,data:V}=D;switch(Q){case"help":z({kind:"help",data:V||{}});break;case"models":z({kind:"models",data:V||{}});break;case"cost":{z({kind:"cost",data:V||{}});break}case"status":{z({kind:"status",data:V||{}});break}case"memory":V.error?p({type:"assistant",content:`Warning: ${V.message}`,timestamp:Date.now()}):(p({type:"assistant",content:`${V.message}
|
|
5
|
-
|
|
6
|
-
Path: \`${V.path}\``,timestamp:Date.now()}),V.exists&&L&&L(V.path));break;case"config":f?.();break;default:console.warn("Unknown built-in command action:",Q)}},[L,f,p]),be=o.useCallback(()=>{z(null)},[]),oe=o.useCallback(async D=>{const{content:Q,hasBashCommands:V}=D;if(V&&!window.confirm("This command contains bash commands that will be executed. Do you want to proceed?")){p({type:"assistant",content:"Command execution cancelled",timestamp:Date.now()});return}const te=Q||"";T(te),me.current=te,setTimeout(()=>{pe.current&&pe.current(hr())},0)},[p]),ne=o.useCallback(async(D,Q,V)=>{if(!(!D||!e))try{const ye=(Q??I).match(new RegExp(`${tn(D.name)}\\s*(.*)`)),Ve=ye&&ye[1]?ye[1].trim().split(/\s+/):[],wt={projectPath:e.fullPath||e.path,projectId:e.projectId,sessionId:s||r?.id||null,provider:a,model:c,tokenUsage:g},st=await $e("/api/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commandName:D.name,commandPath:D.path,args:Ve,context:wt})});if(!st.ok){let vt=`Failed to execute command (${st.status})`;try{const Nt=await st.json();vt=Nt?.message||Nt?.error||vt}catch{}throw new Error(vt)}const tt=await st.json();tt.type==="builtin"?(fe(tt),V?.preserveInput||(T(""),me.current="")):tt.type==="custom"&&await oe(tt)}catch(te){const ye=te instanceof Error?te.message:"Unknown error";console.error("Error executing command:",te),p({type:"assistant",content:`Error executing command: ${ye}`,timestamp:Date.now()})}},[c,s,fe,oe,I,a,e,r?.id,p,g]),ve=o.useCallback(()=>{ne({name:"/cost",description:"Display token usage information",namespace:"builtin",metadata:{type:"builtin"}},"/cost",{preserveInput:!0})},[ne]),{slashCommands:Ne,slashCommandsCount:Pe,filteredCommands:nt,frequentCommands:je,commandQuery:re,showCommandMenu:Ee,selectedCommandIndex:Ie,resetCommandMenuState:ue,handleCommandSelect:Ye,handleToggleCommandMenu:Le,handleCommandInputChange:C,handleCommandMenuKeyDown:S}=gl({selectedProject:e,provider:a,input:I,setInput:T,textareaRef:U,onExecuteCommand:ne}),{showFileDropdown:F,filteredFiles:q,selectedFileIndex:W,renderInputWithMentions:de,selectFile:Ce,setCursorPosition:xe,handleFileMentionsKeyDown:Se}=cl({selectedProject:e,input:I,setInput:T,textareaRef:U}),Re=o.useCallback(D=>{!ee.current||!D||(ee.current.scrollTop=D.scrollTop,ee.current.scrollLeft=D.scrollLeft)},[]),_e=o.useCallback(D=>{D.style.height="auto";const Q=Math.max(22,D.scrollHeight);D.style.height=`${Q}px`;let V=ie.current;V||(V=parseInt(window.getComputedStyle(D).lineHeight),ie.current=Number.isFinite(V)?V:24);const te=Q>(ie.current||24)*2;P(ye=>ye===te?ye:te),X.current=D.value},[]),Me=o.useCallback(D=>{const Q=D.filter(V=>{try{if(!V||typeof V!="object")return console.warn("Invalid file object:",V),!1;if(V.size>cs){const te=V.name||"Unknown file";return O(ye=>{const Ve=new Map(ye);return Ve.set(te,"File too large (max 10MB)"),Ve}),!1}return!0}catch(te){return console.error("Error validating file:",te,V),!1}});Q.length>0&&A(V=>[...V,...Q].slice(0,is))},[]),bt=o.useCallback(D=>{const Q=Array.from(D.clipboardData.items);if(Q.forEach(V=>{if(!V.type.startsWith("image/"))return;const te=V.getAsFile();te&&Me([te])}),Q.length===0&&D.clipboardData.files.length>0){const te=Array.from(D.clipboardData.files).filter(ye=>ye.type.startsWith("image/"));te.length>0&&Me(te)}},[Me]),{getRootProps:dt,getInputProps:yt,isDragActive:Ue,open:et}=Ca({maxSize:cs,maxFiles:is,onDrop:Me,noClick:!0,noKeyboard:!0}),Je=o.useCallback(D=>{const V=(()=>{try{const te=a==="cursor"?"cursor-tools-settings":a==="codex"?"codex-settings":a==="opencode"?"opencode-settings":"claude-settings",ye=Ge.getItem(te);if(ye)return JSON.parse(ye)}catch(te){console.error("Error loading tools settings:",te)}return{allowedTools:[],disallowedTools:[],skipPermissions:!1}})();return{model:c,effort:d,permissionMode:i(a,n),toolsSettings:V,skipPermissions:V?.skipPermissions||!1,sessionSummary:ps(r,D)}},[d,c,n,a,i,r]),Be=o.useCallback(async(D,Q)=>{D.preventDefault();const V=Q?.content??me.current,te=Q?.attachments??j,ye=Q?.uploadedAttachments??[];if(!V.trim()&&te.length===0&&ye.length===0||!e)return;if(u){if(Q){ge.current=Y,ce(Q);return}const He=Je(V),we=Y;let ze=[];try{ze=await us(te)}catch(At){const dr=At instanceof Error?At.message:"Unknown error";console.error("Queued file upload failed:",At),p({type:"error",content:`Failed to upload files: ${dr}`,timestamp:new Date});return}const Ke={content:V,attachments:te,uploadedAttachments:ze,options:He};if(we&&ss(we,{content:Ke.content,options:Ke.options,attachments:Ke.uploadedAttachments}),we&&le.current!==we){ae.current&&!ae.current.has(we)&&(ns(we),b({type:"chat.send",sessionId:we,content:Ke.content,options:{...Ke.options??{},attachments:Ke.uploadedAttachments??[]}}),k?.(we,{statusText:null,canInterrupt:!0}));return}ge.current=we,ce(Ke),T(""),me.current="",A([]),H(new Map),O(new Map),ue(),P(!1),U.current&&(U.current.style.height="auto"),Ge.removeItem(`draft_input_${e.projectId}`);return}const Ve=V.trimEnd(),wt=Ve.trim().toLowerCase()==="help";if(Ve.startsWith("/")||wt){const He=Ve.indexOf(" "),we=wt?"/help":He>0?Ve.slice(0,He):Ve,ze=Ne.find(Ke=>Ke.name===we)||(we==="/help"?{name:"/help",description:"Show help documentation for Claude Code",namespace:"builtin",metadata:{type:"builtin"}}:void 0);if(ze&&ze.type!=="skill"&&ze.metadata?.passthrough!==!0){ne(ze,wt?"/help":Ve),T(""),me.current="",A([]),H(new Map),O(new Map),ue(),P(!1),U.current&&(U.current.style.height="auto");return}}const st=V;let tt=ye;if(tt.length===0&&te.length>0)try{tt=await us(te)}catch(He){const we=He instanceof Error?He.message:"Unknown error";console.error("File upload failed:",He),p({type:"error",content:`Failed to upload files: ${we}`,timestamp:new Date});return}const vt=e.fullPath||e.path||"",Nt=ps(r,V);let ft=r?.id||s||null;if(!ft){let He=Nt;try{const we=await $e("/api/providers/sessions",{method:"POST",body:JSON.stringify({provider:a,projectPath:vt,initialMessage:st})});if(!we.ok)throw new Error(`Failed to create session (${we.status})`);const ze=await we.json();ft=ze?.data?.sessionId||null;const Ke=typeof ze?.data?.sessionName=="string"?ze.data.sessionName.trim():"";Ke&&(He=Ke)}catch(we){const ze=we instanceof Error?we.message:"Unknown error";console.error("Session creation failed:",we),p({type:"error",content:`Failed to start a new session: ${ze}`,timestamp:new Date});return}if(!ft){p({type:"error",content:"Failed to start a new session: no session id returned.",timestamp:new Date});return}E?.(ft,{provider:a,project:e,summary:He})}const Ht=tt,cr={type:"user",content:V,images:Ht.filter(ds),files:Ht.filter(He=>!ds(He)),timestamp:new Date};p(cr),k?.(ft,{statusText:null,canInterrupt:!0}),h(!1),setTimeout(()=>m(),100),b({type:"chat.send",sessionId:ft,content:st,options:{...Q?.options??Je(st),attachments:tt}}),T(""),me.current="",ue(),A([]),H(new Map),O(new Map),P(!1),U.current&&(U.current.style.height="auto"),Ge.removeItem(`draft_input_${e.projectId}`)},[r,j,Je,s,ne,u,k,E,a,ue,m,e,b,Y,p,h,Ne]);o.useEffect(()=>{pe.current=Be},[Be]);const G=o.useRef(u),Oe=o.useRef(Y);o.useEffect(()=>{const D=G.current;if(G.current=u,Oe.current!==Y){Oe.current=Y;return}if(u||!K)return;const V=setTimeout(()=>{if(Y&&!dn(Y)){ce(null);return}ce(null),T(K.content),me.current=K.content,A(K.attachments),pe.current?.(hr(),K)},D?0:750);return()=>clearTimeout(V)},[u,K,Y,T]);const De=o.useCallback(()=>{K&&(ce(null),T(K.content),me.current=K.content,A(K.attachments),U.current?.focus())},[K]),ut=o.useCallback(()=>{ce(null)},[]),at=o.useCallback((D,Q)=>{const V=me.current.trim(),te=V?`${V} ${D}`:D;T(te),me.current=te,Q&&pe.current?.(hr())},[T]);o.useEffect(()=>{me.current=I},[I]),o.useEffect(()=>{if(!he)return;const D=Ge.getItem(`draft_input_${he}`)||"";T(Q=>{const V=Q===D?Q:D;return me.current=V,V})},[he]),o.useEffect(()=>{he&&(I!==""?Ge.setItem(`draft_input_${he}`,I):Ge.removeItem(`draft_input_${he}`))},[I,he]),o.useEffect(()=>{!Y||ge.current!==Y||(K&&(K.content.trim()||(K.uploadedAttachments?.length??0)>0)?ss(Y,{content:K.content,options:K.options,attachments:K.uploadedAttachments}):ns(Y))},[K,Y]),o.useEffect(()=>{if(ge.current=Y,!Y){ce(null);return}ce(ms(Y))},[Y]),o.useEffect(()=>{U.current&&X.current!==I&&_e(U.current)},[I,_e]),o.useEffect(()=>{!U.current||I.trim()||(U.current.style.height="auto",P(!1))},[I]);const R=o.useCallback(D=>{const Q=D.target.value,V=D.target.selectionStart;if(T(Q),me.current=Q,xe(V),!Q.trim()){D.target.style.height="auto",P(!1),ue();return}C(Q,V)},[C,ue,xe]),J=o.useCallback(D=>{if(!S(D)&&!Se(D)){if(D.key==="Tab"&&!F&&!Ee){D.preventDefault(),l();return}if(D.key==="Enter"){if(D.nativeEvent.isComposing)return;((D.ctrlKey||D.metaKey)&&!D.shiftKey||!D.shiftKey&&!D.ctrlKey&&!D.metaKey&&!N)&&(D.preventDefault(),Be(D))}}},[l,S,Se,Be,N,Ee,F]),Z=o.useCallback(D=>{xe(D.currentTarget.selectionStart)},[xe]),se=o.useCallback(D=>{const Q=D.currentTarget;_e(Q),xe(Q.selectionStart),Re(Q)},[_e,xe,Re]),ke=o.useCallback(()=>{T(""),me.current="",ue(),U.current&&(U.current.style.height="auto",U.current.focus()),P(!1)},[ue]),Te=o.useCallback(()=>{if(!v)return;const D=r?.id||s||null;if(!D){console.warn("Abort requested but no session ID is available.");return}b({type:"chat.abort",sessionId:D})},[v,s,r?.id,b]),qe=o.useCallback(D=>!D||a!=="claude"?{success:!1}:il(D.entry),[a]),mt=o.useCallback((D,Q)=>{const te=(Array.isArray(D)?D:[D]).filter(Boolean);te.length!==0&&(te.forEach(ye=>{b({type:"chat.permission-response",requestId:ye,allow:!!Q?.allow,updatedInput:Q?.updatedInput,message:Q?.message,rememberEntry:Q?.rememberEntry})}),y(ye=>ye.filter(Ve=>!te.includes(Ve.requestId))))},[b,y]),[pt,ot]=o.useState(!1),kt=o.useCallback(D=>{ot(D),w?.(D)},[w]);return{input:I,setInput:T,textareaRef:U,inputHighlightRef:ee,isTextareaExpanded:$,slashCommandsCount:Pe,filteredCommands:nt,frequentCommands:je,commandQuery:re,showCommandMenu:Ee,selectedCommandIndex:Ie,resetCommandMenuState:ue,handleCommandSelect:Ye,handleToggleCommandMenu:Le,showFileDropdown:F,filteredFiles:q,selectedFileIndex:W,renderInputWithMentions:de,selectFile:Ce,attachedFiles:j,setAttachedFiles:A,uploadingFiles:_,fileErrors:M,getRootProps:dt,getInputProps:yt,isDragActive:Ue,openAttachmentPicker:et,handleSubmit:Be,queuedDraft:K,editQueuedDraft:De,deleteQueuedDraft:ut,handleVoiceTranscript:at,handleInputChange:R,handleKeyDown:J,handlePaste:bt,handleTextareaClick:Z,handleTextareaInput:se,syncInputOverlayScroll:Re,handleClearInput:ke,handleAbortSession:Te,handlePermissionDecision:mt,handleGrantToolPermission:qe,handleInputFocusChange:kt,isInputFocused:pt,commandModalPayload:B,closeCommandModal:be,showCostModal:ve}}const yl=300*1e3,kl=1e4,wl=3e4;function fs(e){if(e.kind!=="text"||e.role!=="user")return null;const r=(e.content||"").trim(),s=Array.isArray(e.images)?e.images.length:0,a=Array.isArray(e.files)?e.files.length:0;return!r&&s===0&&a===0?null:{text:r,imageCount:s,fileCount:a}}function vl(e,r){return e.text===r.text&&e.imageCount===r.imageCount&&e.fileCount===r.fileCount}function xs(e){const r=Date.parse(e.timestamp);return Number.isFinite(r)?r:null}function jl(e,r,s){const a=fs(e),n=xs(e);if(!a||n===null)return null;const l=a.text?yl:wl;let i=null,c=Number.POSITIVE_INFINITY;for(const d of r){if(s.has(d.id))continue;const u=fs(d);if(!u||!vl(a,u))continue;const x=xs(d);if(x===null||x<n-kl||x-n>l)continue;const v=Math.abs(x-n);v<c&&(i=d,c=v)}return i}function fn(e,r){const s=new Set;return r.filter(a=>{if(!a.id.startsWith("local_"))return!0;const n=jl(a,e,s);return n?(s.add(n.id),!1):!0})}const St=[],Nl=3e4;function Cl(){return{serverMessages:St,realtimeMessages:St,merged:St,_lastServerRef:St,_lastRealtimeRef:St,status:"idle",fetchedAt:0,total:0,hasMore:!1,offset:0,tokenUsage:null,_historyMutationQueue:Promise.resolve()}}function gr(e,r){const s=e._historyMutationQueue.then(r);return e._historyMutationQueue=s.then(()=>{},()=>{}),s}async function nr(e,r){const s=await $e(Vo(e,r),{signal:AbortSignal.timeout(Nl)});if(!s.ok)throw new Error(`HTTP ${s.status}`);const a=await s.json(),n=a?.data??a,l=Array.isArray(n.messages)?n.messages:[];return{messages:l,total:typeof n.total=="number"?n.total:l.length,hasMore:!!n.hasMore,...n&&typeof n=="object"&&"tokenUsage"in n?{tokenUsage:n.tokenUsage}:{}}}function Rt(e){const r=Date.parse(e.timestamp);return Number.isFinite(r)?r:null}function xn(e,r){const s=Rt(e)??0,a=Rt(r)??0;return s!==a?s-a:0}function Sl(e,r,s){const a=Rt(e);let n=0;for(const l of[...r,...s].sort(xn)){if(l.id===e.id)break;const i=Rt(l);if(a!==null&&i!==null&&i>a)break;l.kind==="text"&&l.role==="user"&&n++}return Math.max(0,n-1)}function Ml(e,r){let s=-1,a=-1;for(let l=0;l<e.length;l++){const i=e[l];if(i.kind==="text"&&i.role==="user"&&(s++,s===r)){a=l;break}}if(a<0)return null;let n=e.length;for(let l=a+1;l<e.length;l++)if(e[l].kind==="text"&&e[l].role==="user"){n=l;break}return{start:a,end:n}}function hs(e,r,s){const a=(e.content||"").trim();if(!a)return!1;const n=Sl(e,r,s),l=Ml(r,n);return l?r.slice(l.start+1,l.end).some(i=>i.kind==="text"&&i.role==="assistant"&&(i.content||"").trim()===a):!1}function Kt(e){const r=[];for(const s of e){const a=r[r.length-1];if(a){if(a.kind==="stream_delta"&&s.kind==="text"&&s.role==="assistant"){const n=(a.content||"").trim(),l=(s.content||"").trim();if(n.length>0&&n===l){r[r.length-1]=s;continue}}if(a.kind==="text"&&s.kind==="text"&&a.role==="assistant"&&s.role==="assistant"){const n=(s.content||"").trim();if(n.length>0&&n===(a.content||"").trim())continue}}r.push(s)}return r}function hn(e,r){if(r.length===0)return r;const s=new Set(e.map(n=>n.id));return fn(e,r).filter(n=>s.has(n.id)?!1:n.kind==="stream_delta"||n.id===`__streaming_${n.sessionId}`||n.kind==="text"&&n.role==="assistant"?!hs(n,e,r):n.kind==="text"&&n.role==="user"?!0:!(n.kind==="tool_use"&&n.toolId&&e.some(l=>l.kind==="tool_use"&&l.toolId===n.toolId)))}function Tl(e,r){if(r.length===0)return Kt(e);if(e.length===0)return Kt(r);const s=new Set(e.map(l=>l.id)),n=fn(e,r).filter(l=>!s.has(l.id));return n.length===0?Kt(e):Kt([...e,...n].sort(xn))}function ht(e){return e.serverMessages===e._lastServerRef&&e.realtimeMessages===e._lastRealtimeRef?!1:(e._lastServerRef=e.serverMessages,e._lastRealtimeRef=e.realtimeMessages,e.merged=Tl(e.serverMessages,e.realtimeMessages),!0)}function El(e,r){return Object.is(e,r)||JSON.stringify(e)===JSON.stringify(r)}function gn(e,r){const s=e[e.length-1],a=r[0];if(!s||!a)return!0;const n=Rt(s),l=Rt(a);return n===null||l===null||n<=l}async function gs(e,r,s,a=()=>!0){if(!a())return{applied:!1,changed:!1,deferred:!0};const n=r.serverMessages,l=r.total,i=r.hasMore,c=await nr(e,{limit:s,offset:0});let d=null,u=i;if(!c.hasMore)d=c.messages,u=!1;else if(n.length===0)d=c.messages,u=!0;else{let v=c.messages,g=c,b=0,N=!1,k=Xr(n,v);for(;k.overlapLength===0&&!zo(n,v);){const E=Ho(n,c.messages,l,c.total,b);if(!E)break;if(!a())return{applied:!1,changed:!1,deferred:!0};const w=await nr(e,E);if(w.total!==c.total)return console.warn(`[SessionStore] History changed while bridging ${e}; retaining cached suffix.`),{applied:!1,changed:!1,deferred:!1};if(w.messages.length===0)break;const L=en(v,w.messages);if(L.overlapLength>0||!gn(w.messages,v))return console.warn(`[SessionStore] History shifted while bridging ${e}; retaining cached suffix.`),{applied:!1,changed:!1,deferred:!1};if(v=L.messages,g=w,b+=w.messages.length,k=Xr(n,v),!w.hasMore){N=!0;break}}N?(d=v,u=!1):k.overlapLength>0&&(d=k.messages,u=Wo(n.length,d.length,i,g.hasMore).hasMore)}let x=!1;return c.tokenUsage!==void 0&&!El(c.tokenUsage,r.tokenUsage)&&(r.tokenUsage=c.tokenUsage,x=!0),d?(r.serverMessages=d,r.total=c.total,r.offset=d.length,r.hasMore=u,r.fetchedAt=Date.now(),r.realtimeMessages=hn(r.serverMessages,r.realtimeMessages),ht(r),{applied:!0,changed:!0,deferred:!1}):(console.warn(`[SessionStore] Could not bridge latest history for ${e}; retaining cached suffix.`),{applied:!1,changed:x,deferred:!1})}const Il=3e4,Gt=500;function $l(){const e=o.useRef(new Map),r=o.useRef(null),[,s]=o.useState(0),a=o.useCallback(f=>{f===r.current&&s(m=>m+1)},[]),n=o.useCallback(f=>{r.current=f},[]),l=o.useCallback(f=>{const m=e.current;return m.has(f)||m.set(f,Cl()),m.get(f)},[]),i=o.useCallback(f=>e.current.has(f),[]),c=o.useCallback(async(f,m={})=>{const p=l(f);return p.status="loading",a(f),gr(p,async()=>{const{canRequest:h=()=>!0,...y}=m;if(!h())return p.status="idle",a(f),null;try{const I=await nr(f,y);return p.serverMessages=I.messages,p.total=I.total,p.hasMore=I.hasMore,p.offset=(y.offset??0)+I.messages.length,p.fetchedAt=Date.now(),p.status="idle",p.realtimeMessages=hn(p.serverMessages,p.realtimeMessages),ht(p),I.tokenUsage!==void 0&&(p.tokenUsage=I.tokenUsage),a(f),p}catch(I){return console.error(`[SessionStore] fetch failed for ${f}:`,I),p.status="error",a(f),p}})},[l,a]),d=o.useCallback(async(f,m={})=>{const p=l(f);return gr(p,async()=>{let h=0,y=!1;const I=m.canRequest??(()=>!0);if(!p.hasMore||!I())return{slot:p,prependedCount:h};try{for(let T=0;T<2&&p.hasMore&&I();T++){const j=p.serverMessages,A=p.total,_=await nr(f,{limit:m.limit??gt,offset:p.offset}),H=en(j,_.messages);if(_.total!==A||H.overlapLength>0||!gn(_.messages,j)){if(T>0||!I())break;const O=await gs(f,p,gt,I);if(y=y||O.changed,!O.applied)break;continue}p.serverMessages=H.messages,p.hasMore=_.hasMore,p.total=_.total,p.offset=p.serverMessages.length,h=H.prependedCount,_.tokenUsage!==void 0&&(p.tokenUsage=_.tokenUsage),ht(p),y=!0;break}return y&&a(f),{slot:p,prependedCount:h}}catch(T){return console.error(`[SessionStore] fetchMore failed for ${f}:`,T),y&&a(f),{slot:p,prependedCount:h}}})},[l,a]),u=o.useCallback((f,m)=>{const p=l(f),h=m.sessionId===f?m:{...m,sessionId:f};let y=[...p.realtimeMessages,h];y.length>Gt&&(y=y.slice(-Gt)),p.realtimeMessages=y,ht(p),a(f)},[l,a]),x=o.useCallback((f,m)=>{if(m.length===0)return;const p=l(f),h=m.map(I=>I.sessionId===f?I:{...I,sessionId:f});let y=[...p.realtimeMessages,...h];y.length>Gt&&(y=y.slice(-Gt)),p.realtimeMessages=y,ht(p),a(f)},[l,a]),v=o.useCallback(async(f,m={})=>{const p=l(f);return gr(p,async()=>{try{const h=await gs(f,p,m.limit??gt,m.canRequest);return h.changed&&a(f),{slot:p,...h}}catch(h){return console.error(`[SessionStore] latest refresh failed for ${f}:`,h),{slot:p,applied:!1,changed:!1,deferred:!1}}})},[l,a]),g=o.useCallback((f,m)=>{const p=l(f);p.status=m,a(f)},[l,a]),b=o.useCallback(f=>{const m=e.current.get(f);return m?Date.now()-m.fetchedAt>Il:!0},[]),N=o.useCallback((f,m,p)=>{const h=l(f),y=`__streaming_${f}`,I={id:y,sessionId:f,timestamp:new Date().toISOString(),provider:p,kind:"stream_delta",content:m},T=h.realtimeMessages.findIndex(j=>j.id===y);T>=0?(h.realtimeMessages=[...h.realtimeMessages],h.realtimeMessages[T]=I):h.realtimeMessages=[...h.realtimeMessages,I],ht(h),a(f)},[l,a]),k=o.useCallback(f=>{const m=e.current.get(f);if(!m)return;const p=`__streaming_${f}`,h=m.realtimeMessages.findIndex(y=>y.id===p);if(h>=0){const y=m.realtimeMessages[h];m.realtimeMessages=[...m.realtimeMessages],m.realtimeMessages[h]={...y,id:`text_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,kind:"text",role:"assistant"},ht(m),a(f)}},[a]),E=o.useCallback(f=>{const m=e.current.get(f);m&&(m.realtimeMessages=[],ht(m),a(f))},[a]),w=o.useCallback(f=>e.current.get(f)?.merged??St,[]),L=o.useCallback(f=>e.current.get(f),[]);return o.useMemo(()=>({getSlot:l,has:i,fetchFromServer:c,fetchMore:d,appendRealtime:u,appendRealtimeBatch:x,refreshLatestFromServer:v,setActiveSession:n,setStatus:g,isStale:b,updateStreaming:N,finalizeStreaming:k,clearRealtime:E,getMessages:w,getSessionSlot:L}),[l,i,c,d,u,x,v,n,g,b,N,k,E,w,L])}const Ll=e=>{if(typeof e!="string"&&typeof e!="number")return null;const r=String(e).trim();return r.length>0?r:null},bs=e=>{const r=[e.id,e.messageId,e.toolId,e.toolCallId,e.blobId,e.rowid,e.sequence];for(const l of r){const i=Ll(l);if(i)return`message-${e.type}-${i}`}const s=new Date(e.timestamp).getTime();if(!Number.isFinite(s))return null;const a=typeof e.content=="string"?e.content.slice(0,48):"",n=typeof e.toolName=="string"?e.toolName:"";return`message-${e.type}-${s}-${n}-${a}`},Rl=2;function ys(e){return"_isGroup"in e&&e._isGroup===!0}function ks(e){return!!(e.isToolUse&&e.toolName&&!e.isSubagentContainer)}function Al(e,r){return!!(e.isThinking&&!r)}function Ol(e,r=!0){const s=[];let a=0;for(;a<e.length;){const n=e[a];if(!ks(n)){s.push(n),a+=1;continue}const l=[n];let i=a+1;for(;i<e.length;){const c=e[i];if(Al(c,r)){i+=1;continue}if(ks(c)&&c.toolName===n.toolName){l.push(c),i+=1;continue}break}l.length>=Rl?s.push({_isGroup:!0,toolName:n.toolName,messages:l,timestamp:n.timestamp}):s.push(...l),a=i}return s}const ws={Bash:{input:{type:"one-line",icon:"terminal",getValue:e=>e.command,getSecondary:e=>e.description,action:"copy",style:"terminal",wrapText:!0,colorScheme:{primary:"text-green-400 font-mono",secondary:"text-gray-400",background:"",border:"border-green-500 dark:border-green-400",icon:"text-green-500 dark:text-green-400"}},result:{hideOnSuccess:!0,type:"special"}},Read:{input:{type:"one-line",label:"Read",getValue:e=>e.file_path||"",action:"open-file",colorScheme:{primary:"text-gray-700 dark:text-gray-300",background:"",border:"border-gray-300 dark:border-gray-600",icon:"text-gray-500 dark:text-gray-400"}},result:{hidden:!0}},Edit:{input:{type:"collapsible",title:e=>`${e.file_path?.split("/").pop()||e.file_path||"file"}`,defaultOpen:!1,contentType:"diff",actionButton:"none",getContentProps:e=>({oldContent:e.old_string,newContent:e.new_string,filePath:e.file_path,badge:"Edit",badgeColor:"gray"})},result:{hideOnSuccess:!0}},Write:{input:{type:"collapsible",title:e=>`${e.file_path?.split("/").pop()||e.file_path||"file"}`,defaultOpen:!1,contentType:"diff",actionButton:"none",getContentProps:e=>({oldContent:"",newContent:e.content,filePath:e.file_path,badge:"New",badgeColor:"green"})},result:{hideOnSuccess:!0}},ApplyPatch:{input:{type:"collapsible",title:e=>`${e.file_path?.split("/").pop()||e.file_path||"file"}`,defaultOpen:!1,contentType:"diff",actionButton:"none",getContentProps:e=>({oldContent:e.old_string,newContent:e.new_string,filePath:e.file_path,badge:"Patch",badgeColor:"gray"})},result:{hideOnSuccess:!0}},Grep:{input:{type:"one-line",label:"Grep",getValue:e=>e.pattern,getSecondary:e=>e.path?`in ${e.path}`:void 0,action:"jump-to-results",colorScheme:{primary:"text-gray-700 dark:text-gray-300",secondary:"text-gray-500 dark:text-gray-400",background:"",border:"border-gray-400 dark:border-gray-500",icon:"text-gray-500 dark:text-gray-400"}},result:{type:"collapsible",defaultOpen:!1,title:e=>{const r=e.toolUseResult||{},s=r.numFiles||r.filenames?.length||0;return`Found ${s} ${s===1?"file":"files"}`},contentType:"file-list",getContentProps:e=>({files:(e.toolUseResult||{}).filenames||[]})}},Glob:{input:{type:"one-line",label:"Glob",getValue:e=>e.pattern,getSecondary:e=>e.path?`in ${e.path}`:void 0,action:"jump-to-results",colorScheme:{primary:"text-gray-700 dark:text-gray-300",secondary:"text-gray-500 dark:text-gray-400",background:"",border:"border-gray-400 dark:border-gray-500",icon:"text-gray-500 dark:text-gray-400"}},result:{type:"collapsible",defaultOpen:!1,title:e=>{const r=e.toolUseResult||{},s=r.numFiles||r.filenames?.length||0;return`Found ${s} ${s===1?"file":"files"}`},contentType:"file-list",getContentProps:e=>({files:(e.toolUseResult||{}).filenames||[]})}},TodoWrite:{input:{type:"collapsible",title:"Updating todo list",defaultOpen:!1,contentType:"todo-list",getContentProps:e=>({todos:e.todos})},result:{type:"collapsible",contentType:"success-message",getMessage:()=>"Todo list updated"}},TodoRead:{input:{type:"one-line",label:"TodoRead",getValue:()=>"reading list",action:"none",colorScheme:{primary:"text-gray-500 dark:text-gray-400",border:"border-violet-400 dark:border-violet-500"}},result:{type:"collapsible",contentType:"todo-list",getContentProps:e=>{try{const r=String(e.content||"");let s=null;return r.startsWith("[")&&(s=JSON.parse(r)),{todos:s,isResult:!0}}catch(r){return console.warn("Failed to parse todo list content:",r),{todos:[],isResult:!0}}}}},TaskCreate:{input:{type:"one-line",label:"Task",getValue:e=>e.subject||"Creating task",getSecondary:e=>e.status||void 0,action:"none",colorScheme:{primary:"text-gray-700 dark:text-gray-300",border:"border-violet-400 dark:border-violet-500",icon:"text-violet-500 dark:text-violet-400"}},result:{hideOnSuccess:!0}},TaskUpdate:{input:{type:"one-line",label:"Task",getValue:e=>{const r=[];return e.taskId&&r.push(`#${e.taskId}`),e.status&&r.push(e.status),e.subject&&r.push(`"${e.subject}"`),r.join(" → ")||"updating"},action:"none",colorScheme:{primary:"text-gray-700 dark:text-gray-300",border:"border-violet-400 dark:border-violet-500",icon:"text-violet-500 dark:text-violet-400"}},result:{hideOnSuccess:!0}},TaskList:{input:{type:"one-line",label:"Tasks",getValue:()=>"listing tasks",action:"none",colorScheme:{primary:"text-gray-500 dark:text-gray-400",border:"border-violet-400 dark:border-violet-500",icon:"text-violet-500 dark:text-violet-400"}},result:{type:"collapsible",defaultOpen:!0,title:"Task list",contentType:"task",getContentProps:e=>({content:String(e?.content||"")})}},TaskGet:{input:{type:"one-line",label:"Task",getValue:e=>e.taskId?`#${e.taskId}`:"fetching",action:"none",colorScheme:{primary:"text-gray-700 dark:text-gray-300",border:"border-violet-400 dark:border-violet-500",icon:"text-violet-500 dark:text-violet-400"}},result:{type:"collapsible",defaultOpen:!0,title:"Task details",contentType:"task",getContentProps:e=>({content:String(e?.content||"")})}},Task:{input:{type:"collapsible",title:e=>{const r=e.subagent_type||"Agent",s=e.description||"Running task";return`Subagent / ${r}: ${s}`},defaultOpen:!1,contentType:"markdown",getContentProps:e=>{if(e.prompt&&!e.model&&!e.resume)return{content:e.prompt||""};const s=[];return e.model&&s.push(`**Model:** ${e.model}`),e.prompt&&s.push(`**Prompt:**
|
|
7
|
-
${e.prompt}`),e.resume&&s.push(`**Resuming from:** ${e.resume}`),{content:s.join(`
|
|
8
|
-
|
|
9
|
-
`)}},colorScheme:{border:"border-purple-500 dark:border-purple-400",icon:"text-purple-500 dark:text-purple-400"}},result:{type:"collapsible",title:"Subagent result",defaultOpen:!1,contentType:"markdown",getContentProps:e=>{if(e&&e.content){let r=e.content;if(typeof r=="string")try{const s=JSON.parse(r);Array.isArray(s)&&(r=s)}catch{return{content:r}}return Array.isArray(r)?{content:r.filter(a=>a.type==="text").map(a=>a.text).join(`
|
|
10
|
-
|
|
11
|
-
`)||"No response text"}:{content:String(r)}}return{content:String(e||"No response")}}}},AskUserQuestion:{input:{type:"collapsible",title:e=>{const r=e.questions?.length||0,s=e.answers&&Object.keys(e.answers).length>0;if(r===1){const a=e.questions[0]?.header||"Question";return s?`${a} — answered`:a}return s?`${r} questions — answered`:`${r} questions`},defaultOpen:!0,contentType:"question-answer",getContentProps:e=>({questions:e.questions||[],answers:e.answers||{}})},result:{hideOnSuccess:!0}},exit_plan_mode:{input:{type:"plan",title:"Implementation plan",defaultOpen:!0,contentType:"markdown",getContentProps:e=>({content:e.plan?.replace(/\\n/g,`
|
|
12
|
-
`)||e.plan})},result:{hidden:!0}},ExitPlanMode:{input:{type:"plan",title:"Implementation plan",defaultOpen:!0,contentType:"markdown",getContentProps:e=>({content:e.plan?.replace(/\\n/g,`
|
|
13
|
-
`)||e.plan})},result:{hidden:!0}},Default:{input:{type:"collapsible",title:"Parameters",defaultOpen:!1,contentType:"text",getContentProps:e=>({content:typeof e=="string"?e:JSON.stringify(e,null,2),format:"code"})},result:{type:"collapsible",contentType:"text",getContentProps:e=>{let r=e?.content||"";if(typeof r=="string")try{const s=JSON.parse(r);if(Array.isArray(s)){const a=s.filter(n=>n.type==="text"&&n.text).map(n=>n.text);a.length>0&&(r=a.join(`
|
|
14
|
-
`))}}catch{}else if(Array.isArray(r)){const s=r.filter(a=>a.type==="text"&&a.text).map(a=>a.text);s.length>0?r=s.join(`
|
|
15
|
-
`):r=JSON.stringify(r,null,2)}else typeof r=="object"&&r!==null&&(r=JSON.stringify(r,null,2));return{content:String(r),format:"plain"}}}}};function ir(e){return ws[e]||ws.Default}function Pl(e,r){const s=ir(e);return!s.result||r?.isError?!1:!!(s.result.hidden||s.result.hideOnSuccess&&r)}const bn=({title:e,toolName:r,open:s=!1,action:a,badge:n,onTitleClick:l,children:i,className:c=""})=>t.jsxs(Dt,{defaultOpen:s,className:Ae("group/section",c),children:[l?t.jsxs("div",{className:"flex cursor-default select-none items-center gap-1.5 py-0.5 text-xs group-data-[state=open]/section:sticky group-data-[state=open]/section:top-0 group-data-[state=open]/section:z-10 group-data-[state=open]/section:-mx-1 group-data-[state=open]/section:bg-background group-data-[state=open]/section:px-1",children:[t.jsx(Et,{className:"flex flex-shrink-0 items-center p-0.5 text-muted-foreground hover:text-foreground",children:t.jsx("svg",{className:"h-3 w-3 transition-transform duration-150 group-data-[state=open]/section:rotate-90",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})}),r&&t.jsx("span",{className:"flex-shrink-0 font-medium text-muted-foreground",children:r}),r&&t.jsx("span",{className:"flex-shrink-0 text-[10px] text-muted-foreground/40",children:"/"}),t.jsx("button",{onClick:l,className:"flex-1 truncate text-left font-mono text-primary transition-colors hover:text-primary/80 hover:underline",children:e}),n&&t.jsx("span",{className:"ml-auto flex-shrink-0",children:n}),a&&t.jsx("span",{className:"ml-1 flex-shrink-0",children:a})]}):t.jsxs(Et,{className:"flex w-full select-none items-center gap-1.5 py-0.5 text-xs text-muted-foreground transition-colors hover:text-foreground group-data-[state=open]/section:sticky group-data-[state=open]/section:top-0 group-data-[state=open]/section:z-10 group-data-[state=open]/section:-mx-1 group-data-[state=open]/section:bg-background group-data-[state=open]/section:px-1",children:[t.jsx("svg",{className:"h-3 w-3 flex-shrink-0 transition-transform duration-150 group-data-[state=open]/section:rotate-90",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),r&&t.jsx("span",{className:"flex-shrink-0 font-medium",children:r}),r&&t.jsx("span",{className:"flex-shrink-0 text-[10px] text-muted-foreground/40",children:"/"}),t.jsx("span",{className:"flex-1 truncate text-left",children:e}),n&&t.jsx("span",{className:"ml-auto flex-shrink-0",children:n}),a&&t.jsx("span",{className:"ml-1 flex-shrink-0",children:a})]}),t.jsx(Ft,{children:t.jsx("div",{className:"mt-1.5 pl-[18px]",children:i})})]}),_l=({oldContent:e,newContent:r,filePath:s,createDiff:a,onFileClick:n,badge:l="Diff",badgeColor:i="gray"})=>{const c=i==="green"?"bg-green-100 dark:bg-green-900/30 text-green-600 dark:text-green-400":"bg-gray-100 dark:bg-gray-800 text-gray-500 dark:text-gray-400",d=o.useMemo(()=>e===void 0||r===void 0?[]:a(e,r),[a,e,r]);return t.jsxs("div",{className:"overflow-hidden rounded border border-gray-200/60 dark:border-gray-700/50",children:[t.jsxs("div",{className:"flex items-center justify-between border-b border-gray-200/60 bg-gray-50/80 px-2.5 py-1 dark:border-gray-700/50 dark:bg-gray-800/40",children:[n?t.jsx("button",{onClick:n,className:"cursor-pointer truncate font-mono text-[11px] text-blue-600 transition-colors hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300",children:s}):t.jsx("span",{className:"truncate font-mono text-[11px] text-gray-600 dark:text-gray-400",children:s}),t.jsx("span",{className:`rounded px-1.5 py-px text-[10px] font-medium ${c} ml-2 flex-shrink-0`,children:l})]}),t.jsx("div",{className:"font-mono text-[11px] leading-[18px]",children:d.map((u,x)=>t.jsxs("div",{className:"flex",children:[t.jsx("span",{className:`w-6 flex-shrink-0 select-none text-center ${u.type==="removed"?"bg-red-50 text-red-400 dark:bg-red-950/30 dark:text-red-500":"bg-green-50 text-green-400 dark:bg-green-950/30 dark:text-green-500"}`,children:u.type==="removed"?"-":"+"}),t.jsx("span",{className:`flex-1 whitespace-pre-wrap px-2 ${u.type==="removed"?"bg-red-50/50 text-red-800 dark:bg-red-950/20 dark:text-red-200":"bg-green-50/50 text-green-800 dark:bg-green-950/20 dark:text-green-200"}`,children:u.content})]},x))})]})},Dl={running:{label:"Running",className:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300"},completed:{label:"Completed",className:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-300"},error:{label:"Error",className:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-300"},denied:{label:"Denied",className:"bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-300"}};function Mt({status:e,className:r}){const s=Dl[e];return t.jsx("span",{className:Ae("inline-flex items-center rounded px-1.5 py-px text-[10px] font-medium",s.className,r),children:s.label})}const Fl=({toolName:e,icon:r,label:s,value:a,secondary:n,action:l="none",onAction:i,style:c,wrapText:d=!1,colorScheme:u={primary:"text-foreground",secondary:"text-muted-foreground",background:"",border:"border-border",icon:"text-muted-foreground"},toolResult:x,toolId:v,status:g})=>{const[b,N]=o.useState(!1),k=c==="terminal",E=async()=>{if(l==="copy"&&a){if(!await Vt(a))return;N(!0),setTimeout(()=>N(!1),2e3)}else i&&i()},w=()=>t.jsx("button",{onClick:E,className:"ml-1 flex-shrink-0 text-muted-foreground/40 opacity-0 transition-all hover:text-muted-foreground group-hover:opacity-100",title:"Copy to clipboard","aria-label":"Copy to clipboard",children:b?t.jsx("svg",{className:"h-3 w-3 text-green-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):t.jsx("svg",{className:"h-3 w-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})});if(k)return t.jsxs("div",{className:"group my-1",children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("div",{className:"flex flex-shrink-0 items-center gap-1.5 pt-0.5",children:t.jsx("svg",{className:"h-3 w-3 text-green-500 dark:text-green-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-2",children:[t.jsx("div",{className:"min-w-0 flex-1 rounded bg-gray-900 px-2.5 py-1 dark:bg-black",children:t.jsxs("code",{className:`font-mono text-xs text-green-400 ${d?"whitespace-pre-wrap break-all":"block truncate"}`,children:[t.jsx("span",{className:"select-none text-green-600 dark:text-green-500",children:"$ "}),a]})}),g&&t.jsx(Mt,{status:g,className:"mt-0.5"}),l==="copy"&&w()]})]}),n&&t.jsx("div",{className:"ml-7 mt-1",children:t.jsx("span",{className:"text-[11px] italic text-muted-foreground/60",children:n})})]});if(l==="open-file"){const L=a.split("/").pop()||a;return t.jsxs("div",{className:`group flex items-center gap-1.5 border-l-2 ${u.border} my-0.5 py-0.5 pl-3`,children:[t.jsx("span",{className:"flex-shrink-0 text-xs text-muted-foreground",children:s||e}),t.jsx("span",{className:"text-[10px] text-muted-foreground/40",children:"/"}),t.jsx("button",{onClick:E,className:"truncate font-mono text-xs text-primary transition-colors hover:text-primary/80 hover:underline",title:a,children:L}),g&&t.jsx(Mt,{status:g,className:"ml-auto"})]})}return l==="jump-to-results"?t.jsxs("div",{className:`group flex items-center gap-1.5 border-l-2 ${u.border} my-0.5 py-0.5 pl-3`,children:[t.jsx("span",{className:"flex-shrink-0 text-xs text-muted-foreground",children:s||e}),t.jsx("span",{className:"text-[10px] text-muted-foreground/40",children:"/"}),t.jsx("span",{className:`min-w-0 flex-1 truncate font-mono text-xs ${u.primary}`,children:a}),n&&t.jsx("span",{className:"flex-shrink-0 text-[11px] italic text-muted-foreground/60",children:n}),g&&t.jsx(Mt,{status:g}),x&&t.jsx("a",{href:`#tool-result-${v}`,className:"flex flex-shrink-0 items-center gap-0.5 text-[11px] text-primary transition-colors hover:text-primary/80",children:t.jsx("svg",{className:"h-3 w-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})})]}):t.jsxs("div",{className:`group flex items-center gap-1.5 ${u.background||""} border-l-2 ${u.border} my-0.5 py-0.5 pl-3`,children:[r&&r!=="terminal"&&t.jsx("span",{className:`${u.icon} flex-shrink-0 text-xs`,children:r}),!r&&(s||e)&&t.jsx("span",{className:"flex-shrink-0 text-xs text-muted-foreground",children:s||e}),(r||s||e)&&t.jsx("span",{className:"text-[10px] text-muted-foreground/40",children:"/"}),t.jsx("span",{className:`font-mono text-xs ${d?"whitespace-pre-wrap break-all":"truncate"} min-w-0 flex-1 ${u.primary}`,children:a}),n&&t.jsx("span",{className:`text-[11px] ${u.secondary} flex-shrink-0 italic`,children:n}),g&&t.jsx(Mt,{status:g}),l==="copy"&&w()]})},Ul=({command:e,description:r,output:s,isError:a=!1,status:n,defaultOpen:l=!1})=>{const i=(s||"").replace(/\s+$/,""),c=i.length>0,d=c?i.split(`
|
|
16
|
-
`).length:0,u=n==="running",[x,v]=o.useState(!1),[g,b]=o.useState(!1),N=o.useRef(!1);o.useEffect(()=>{!N.current&&c&&l&&(N.current=!0,v(!0))},[c,l]);const k=()=>{c&&v(w=>!w)},E=async w=>{w.stopPropagation(),await Vt(e)&&(b(!0),setTimeout(()=>b(!1),2e3))};return t.jsxs("div",{className:Ae("group/cmd overflow-hidden rounded-lg border bg-muted/40 backdrop-blur-sm transition-all duration-200",a?"border-red-500/30":"border-border/60",c&&!x&&"hover:border-border hover:bg-muted/60",x&&"bg-muted/50 shadow-sm"),children:[t.jsxs("div",{role:c?"button":void 0,tabIndex:c?0:void 0,"aria-expanded":c?x:void 0,onClick:k,onKeyDown:w=>{c&&(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),k())},className:Ae("flex items-center gap-2 px-2.5 py-1.5 outline-none",c&&"cursor-pointer focus-visible:ring-1 focus-visible:ring-ring"),children:[t.jsx(It,{className:Ae("h-3.5 w-3.5 flex-shrink-0 text-muted-foreground/70 transition-transform duration-200",x&&"rotate-90",!c&&"opacity-0")}),t.jsx("span",{className:"flex-shrink-0 select-none font-mono text-xs font-semibold text-emerald-500 dark:text-emerald-400",children:"$"}),t.jsx("span",{className:Ae("min-w-0 flex-1 font-mono text-xs text-foreground",x?"whitespace-pre-wrap break-all":"truncate"),children:e}),u&&t.jsx("span",{className:"h-2.5 w-2.5 flex-shrink-0 animate-spin rounded-full border-[1.5px] border-muted-foreground/30 border-t-emerald-400"}),n&&n!=="running"&&t.jsx(Mt,{status:n,className:"flex-shrink-0"}),!x&&c&&!u&&t.jsxs("span",{className:"flex-shrink-0 text-[10px] tabular-nums text-muted-foreground/70 transition-opacity group-hover/cmd:opacity-0",children:[d," ",d===1?"line":"lines"]}),t.jsx("button",{onClick:E,onKeyDown:w=>w.stopPropagation(),className:"flex-shrink-0 rounded p-0.5 text-muted-foreground/60 opacity-0 transition-all hover:bg-foreground/10 hover:text-foreground focus:opacity-100 group-hover/cmd:opacity-100",title:"Copy command","aria-label":"Copy command",children:g?t.jsx(Ut,{className:"h-3.5 w-3.5 text-emerald-500"}):t.jsx(Us,{className:"h-3.5 w-3.5"})})]}),r&&!x&&t.jsx("div",{className:"truncate px-2.5 pb-1.5 pl-[2.4rem] text-[11px] italic text-muted-foreground/70",children:r}),x&&c&&t.jsxs("div",{className:"settings-content-enter border-t border-border/50 bg-background/50",children:[r&&t.jsx("div",{className:"px-3 pt-2 text-[11px] italic text-muted-foreground/70",children:r}),t.jsx("pre",{className:Ae("max-h-80 overflow-auto whitespace-pre-wrap break-all px-3 py-2 font-mono text-xs leading-relaxed",a?"text-red-600 dark:text-red-400":"text-muted-foreground"),children:i})]})]})},Bl={bash:$o,cpp:Io,csharp:Eo,css:To,diff:Mo,go:So,java:Co,javascript:No,json:jo,jsx:vo,markdown:wo,markup:ko,powershell:yo,python:bo,rust:go,sql:ho,tsx:xo,typescript:fo,yaml:po};Object.entries(Bl).forEach(([e,r])=>{ct.registerLanguage(e,r)});ct.alias("bash",["shell","sh"]);ct.alias("javascript","js");ct.alias("markup",["html","xml"]);ct.alias("powershell","ps1");ct.alias("python","py");ct.alias("typescript","ts");ct.alias("yaml","yml");let vs=null;const ql=()=>(vs??=Ps(()=>import("./mermaid.core-BsWqrIaW.js").then(e=>e.bo),__vite__mapDeps([0,1,2,3,4,5,6])).then(e=>e.default),vs);function Vl({code:e}){const{isDarkMode:r}=Os(),s=o.useId(),[a,n]=o.useState(null);return o.useEffect(()=>{let l=!1;const i=`mermaid-${s.replace(/[^a-zA-Z0-9]/g,"")}`;return ql().then(c=>(c.initialize({startOnLoad:!1,securityLevel:"strict",theme:r?"dark":"default",suppressErrorRendering:!0}),c.render(i,e.trim()))).then(c=>{l||n(c.svg)}).catch(()=>{l||n(null),document.getElementById(`d${i}`)?.remove()}),()=>{l=!0}},[e,r,s]),a?t.jsx("div",{className:"my-3 flex justify-center overflow-x-auto rounded-xl border border-border bg-white p-4 dark:bg-zinc-900 [&_svg]:h-auto [&_svg]:max-w-full",dangerouslySetInnerHTML:{__html:a}}):t.jsx("pre",{className:"my-3 overflow-x-auto rounded-xl border border-border bg-muted/50 p-4 font-mono text-[0.8125rem] leading-relaxed text-muted-foreground dark:bg-zinc-900",children:e.trim()})}const Hl=e=>!!e&&(/^(https?:|mailto:|tel:|data:)/i.test(e)||e.startsWith("#")),yn=e=>e.replace(/:\d+(?::\d+)?$/,""),js=e=>{if(!e)return!1;const r=yn(e.trim());return!r||r==="#"?!1:/[\\/]/.test(r)||/\.[a-z0-9]+$/i.test(r)},Ir=e=>typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(Ir).join(""):er.isValidElement(e)?Ir(e.props.children):"",br=({node:e,className:r,children:s,forceBlock:a,...n})=>{const{t:l}=We("chat"),{isDarkMode:i}=Os(),[c,d]=o.useState(!1),u=(Array.isArray(s)?s.join(""):String(s??"")).replace(/\n$/,"");if(!a&&!/[\r\n]/.test(u))return t.jsx("code",{className:`whitespace-pre-wrap break-words rounded-md border border-border/70 bg-muted px-1.5 py-0.5 font-mono text-[0.875em] text-foreground ${r||""}`,...n,children:s});const v=/language-(\w+)/.exec(r||""),g=v?v[1]:"text",b=g.charAt(0).toUpperCase()+g.slice(1);return g==="mermaid"?t.jsx(Vl,{code:u}):t.jsxs("div",{className:"group my-3 overflow-hidden rounded-xl border border-border bg-muted/50 shadow-sm dark:bg-zinc-900",children:[t.jsxs("div",{className:"flex items-center justify-between px-4 pt-2",children:[t.jsx("span",{className:"select-none text-xs text-muted-foreground",children:b}),t.jsx("button",{type:"button",onClick:()=>Vt(u).then(N=>{N&&(d(!0),setTimeout(()=>d(!1),2e3))}),className:`rounded-md p-1 transition-opacity focus-visible:opacity-100 ${c?"text-green-600 opacity-100 dark:text-green-500":"text-muted-foreground opacity-0 hover:text-foreground group-hover:opacity-100"}`,title:l(c?"codeBlock.copied":"codeBlock.copyCode"),"aria-label":l(c?"codeBlock.copied":"codeBlock.copyCode"),children:c?t.jsx("svg",{className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}):t.jsxs("svg",{className:"h-4 w-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),t.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})]}),t.jsx(ct,{language:g,style:i?Oo:Po,customStyle:{margin:0,borderRadius:0,fontSize:"0.8125rem",lineHeight:1.6,padding:"0.5rem 1rem 1rem",background:"transparent"},codeTagProps:{style:{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',background:"transparent"}},children:u})]})},zl={code:br,pre:({children:e})=>{const r=Array.isArray(e)?e.find(er.isValidElement):e;return er.isValidElement(r)&&r.type===br?t.jsx(br,{...r.props,forceBlock:!0}):t.jsx(t.Fragment,{children:e})},blockquote:({children:e})=>t.jsx("blockquote",{className:"my-3 border-l-2 border-primary/50 pl-4 italic text-muted-foreground",children:e}),hr:()=>t.jsx("hr",{className:"my-4 border-t border-border"}),p:({children:e})=>t.jsx("div",{className:"mb-2 last:mb-0",children:e}),ul:({children:e})=>t.jsx("ul",{className:"mb-2 list-outside list-disc space-y-1 pl-5 marker:text-current last:mb-0",children:e}),ol:({children:e})=>t.jsx("ol",{className:"mb-2 list-outside list-decimal space-y-1 pl-5 marker:text-current last:mb-0",children:e}),li:({children:e})=>t.jsx("li",{className:"[&>div:last-child]:mb-0 [&>div]:mb-1",children:e}),table:({children:e})=>t.jsx("div",{className:"my-3 overflow-x-auto rounded-lg border border-border",children:t.jsx("table",{className:"my-0 min-w-full border-collapse text-sm",children:e})}),thead:({children:e})=>t.jsx("thead",{className:"bg-muted/60",children:e}),tr:({children:e})=>t.jsx("tr",{className:"[&:last-child>td]:border-b-0",children:e}),th:({children:e})=>t.jsx("th",{className:"border-b border-border px-3 py-2 text-left font-semibold text-foreground",children:e}),td:({children:e})=>t.jsx("td",{className:"border-b border-border/60 px-3 py-2 align-top",children:e})};function Tt({children:e,className:r,breaks:s=!1}){const a=Qo(String(e??"")),n=o.useMemo(()=>s?[Gr,[Jr,{singleDollarTextMath:!1}],Lo]:[Gr,[Jr,{singleDollarTextMath:!1}]],[s]),l=o.useMemo(()=>[Ro],[]),{openFileInEditor:i}=Yn(),c=o.useMemo(()=>({...zl,a:({href:d,children:u})=>{const x=Ir(u),v=js(d)?d:js(x)?x:void 0;return v&&!Hl(d)?t.jsx("a",{href:d||v,className:"cursor-pointer text-blue-600 hover:underline dark:text-blue-400",onClick:g=>{g.preventDefault(),i(yn(v))},children:u}):t.jsx("a",{href:d,className:"text-blue-600 hover:underline dark:text-blue-400",target:"_blank",rel:"noopener noreferrer",children:u})}}),[i]);return t.jsx("div",{className:r,children:t.jsx(Ao,{remarkPlugins:n,rehypePlugins:l,components:c,children:a})})}const Wl=({content:e,label:r})=>{const s=e.trim(),a=s.length>0,[n,l]=o.useState(!1),i=()=>{a&&l(c=>!c)};return t.jsxs("div",{className:Ae("mt-2 overflow-hidden rounded-lg border border-red-500/30 bg-red-50/50 transition-all duration-200 dark:bg-red-950/10",n&&"shadow-sm"),children:[t.jsxs("div",{role:a?"button":void 0,tabIndex:a?0:void 0,"aria-expanded":a?n:void 0,onClick:i,onKeyDown:c=>{a&&(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),i())},className:Ae("flex items-center gap-2 px-2.5 py-1.5 outline-none",a&&"cursor-pointer focus-visible:ring-1 focus-visible:ring-ring"),children:[t.jsx(It,{className:Ae("h-3.5 w-3.5 flex-shrink-0 text-red-500/70 transition-transform duration-200 dark:text-red-400/70",n&&"rotate-90",!a&&"opacity-0")}),t.jsx("svg",{className:"h-3.5 w-3.5 flex-shrink-0 text-red-500 dark:text-red-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),t.jsx("span",{className:"flex-shrink-0 text-xs font-medium text-red-700 dark:text-red-300",children:r}),!n&&a&&t.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-red-900/70 dark:text-red-100/70",children:s})]}),n&&a&&t.jsx("div",{className:"settings-content-enter border-t border-red-500/20 px-3 py-2 text-sm text-red-900 dark:text-red-100",children:t.jsx(Tt,{className:"prose prose-sm prose-red max-w-none font-serif dark:prose-invert",children:s})})]})},Ns={edit:"border-l-amber-500 dark:border-l-amber-400",search:"border-l-muted-foreground/40",bash:"border-l-green-500 dark:border-l-green-400",todo:"border-l-violet-500 dark:border-l-violet-400",task:"border-l-violet-500 dark:border-l-violet-400",agent:"border-l-purple-500 dark:border-l-purple-400",plan:"border-l-indigo-500 dark:border-l-indigo-400",question:"border-l-blue-500 dark:border-l-blue-400",default:"border-l-border"},Kl=({toolName:e,title:r,defaultOpen:s=!1,action:a,badge:n,onTitleClick:l,children:i,showRawParameters:c=!1,rawContent:d,className:u="",toolCategory:x})=>{const v=Ns[x||"default"]||Ns.default;return t.jsx("div",{className:`border-l-2 ${v} my-1 py-0.5 pl-3 ${u}`,children:t.jsxs(bn,{title:r,toolName:e,open:s,action:a,badge:n,onTitleClick:l,children:[i,c&&d&&t.jsxs(Dt,{className:"mt-2",children:[t.jsxs(Et,{className:"flex items-center gap-1.5 py-0.5 text-[11px] text-muted-foreground hover:text-foreground",children:[t.jsx("svg",{className:"h-2.5 w-2.5 flex-shrink-0 transition-transform duration-150 data-[state=open]:rotate-90",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),"raw params"]}),t.jsx(Ft,{children:t.jsx("pre",{className:"mt-1 overflow-hidden whitespace-pre-wrap break-words rounded border border-border/40 bg-muted p-2 font-mono text-[11px] text-muted-foreground",children:d})})]})]})})},Jt=(e,r)=>{const s=typeof r=="string"?(()=>{try{return JSON.parse(r)}catch{return{}}})():r||{};switch(e){case"Read":case"Write":case"Edit":case"ApplyPatch":return s.file_path?.split("/").pop()||s.file_path||"";case"Grep":case"Glob":return s.pattern||"";case"Bash":const a=s.command||"";return a.length>40?`${a.slice(0,40)}...`:a;case"Task":return s.description||s.subagent_type||"";case"WebFetch":case"WebSearch":return s.url||s.query||"";default:return""}},Gl=({toolInput:e,toolResult:r,subagentState:s})=>{const a=typeof e=="string"?(()=>{try{return JSON.parse(e)}catch{return{}}})():e||{},n=a?.subagent_type||"Agent",l=a?.description||"Running task",i=a?.prompt||"",{childTools:c,currentToolIndex:d,isComplete:u}=s,x=d>=0?c[d]:null,v=`Subagent / ${n}: ${l}`;return t.jsx("div",{className:"my-1 border-l-2 border-l-purple-500 py-0.5 pl-3 dark:border-l-purple-400",children:t.jsxs(bn,{title:v,toolName:"Task",open:!1,children:[i&&t.jsx("div",{className:"mb-2 line-clamp-4 whitespace-pre-wrap break-words text-xs text-muted-foreground",children:i}),x&&!u&&t.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-xs text-muted-foreground",children:[t.jsx("span",{className:"h-1.5 w-1.5 flex-shrink-0 animate-pulse rounded-full bg-purple-500 dark:bg-purple-400"}),t.jsx("span",{className:"text-muted-foreground/60",children:"Currently:"}),t.jsx("span",{className:"font-medium text-foreground",children:x.toolName}),Jt(x.toolName,x.toolInput)&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-muted-foreground/40",children:"/"}),t.jsx("span",{className:"truncate font-mono text-muted-foreground",children:Jt(x.toolName,x.toolInput)})]})]}),u&&t.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-xs text-green-600 dark:text-green-400",children:[t.jsx("svg",{className:"h-3 w-3 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),t.jsxs("span",{children:["Completed (",c.length," ",c.length===1?"tool":"tools",")"]})]}),c.length>0&&t.jsxs(Dt,{className:"mt-2",children:[t.jsxs(Et,{className:"flex items-center gap-1 text-[11px] text-muted-foreground hover:text-foreground",children:[t.jsx("svg",{className:"h-2.5 w-2.5 flex-shrink-0 transition-transform duration-150 data-[state=open]:rotate-90",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),t.jsxs("span",{children:["View tool history (",c.length,")"]})]}),t.jsx(Ft,{children:t.jsx("div",{className:"mt-1 space-y-0.5 border-l border-border pl-3",children:c.map((g,b)=>t.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[t.jsxs("span",{className:"w-4 flex-shrink-0 text-right text-muted-foreground/60",children:[b+1,"."]}),t.jsx("span",{className:"font-medium text-foreground",children:g.toolName}),Jt(g.toolName,g.toolInput)&&t.jsx("span",{className:"truncate font-mono text-muted-foreground/70",children:Jt(g.toolName,g.toolInput)}),g.toolResult?.isError&&t.jsx("span",{className:"flex-shrink-0 text-red-500",children:"(error)"})]},g.toolId))})})]}),u&&r&&t.jsx("div",{className:"mt-2 text-xs text-muted-foreground",children:(()=>{let g=r.content;if(typeof g=="string")try{const b=JSON.parse(g);if(Array.isArray(b)){const N=b.filter(k=>k.type==="text"&&k.text).map(k=>k.text);N.length>0&&(g=N.join(`
|
|
17
|
-
`))}}catch{}else if(Array.isArray(g)){const b=g.filter(N=>N.type==="text"&&N.text).map(N=>N.text);b.length>0&&(g=b.join(`
|
|
18
|
-
`))}return typeof g=="string"?t.jsx("div",{className:"line-clamp-6 whitespace-pre-wrap break-words",children:g}):g?t.jsx("pre",{className:"line-clamp-6 whitespace-pre-wrap break-words font-mono text-[11px]",children:JSON.stringify(g,null,2)}):null})()})]})})},kn=({content:e,className:r="mt-1 prose prose-sm max-w-none dark:prose-invert"})=>t.jsx(Tt,{className:r,children:e}),Jl=({files:e,onFileClick:r,title:s})=>t.jsxs("div",{children:[s&&t.jsx("div",{className:"mb-1 text-[11px] text-gray-500 dark:text-gray-400",children:s}),t.jsx("div",{className:"flex max-h-48 flex-wrap gap-x-1 gap-y-0.5 overflow-y-auto",children:e.map((a,n)=>{const l=typeof a=="string"?a:a.path,i=l.split("/").pop()||l,c=typeof a=="string"?()=>r?.(a):a.onClick;return t.jsxs("span",{className:"inline-flex items-center",children:[t.jsx("button",{onClick:c,className:"font-mono text-[11px] text-blue-600 transition-colors hover:text-blue-700 hover:underline dark:text-blue-400 dark:hover:text-blue-300",title:l,children:i}),n<e.length-1&&t.jsx("span",{className:"ml-1 text-[10px] text-gray-300 dark:text-gray-600",children:","})]},n)})})]}),Ql=e=>e==="completed"?"completed":e==="in_progress"?"in_progress":"pending",wn=o.memo(({todos:e,isResult:r=!1})=>{const s=o.useMemo(()=>e.map(a=>({...a,queueStatus:Ql(a.status)})),[e]);return s.length===0?null:t.jsxs("div",{children:[r&&t.jsxs("div",{className:"mb-1.5 text-xs font-medium text-muted-foreground",children:["Todo List (",s.length," ",s.length===1?"item":"items",")"]}),t.jsx(Xn,{children:s.map((a,n)=>t.jsxs(Zn,{status:a.queueStatus,children:[t.jsx(ea,{}),t.jsx(ta,{children:a.content})]},a.id??`${a.content}-${n}`))})]})});wn.displayName="TodoList";const Yl=e=>{if(typeof e!="object"||e===null)return!1;const r=e;return typeof r.content=="string"&&typeof r.status=="string"},Xl=o.memo(({todos:e,isResult:r=!1})=>{const s=o.useMemo(()=>Array.isArray(e)?e.filter(Yl):[],[e]);return s.length===0?null:t.jsx(wn,{todos:s,isResult:r})});function Zl(e){const r=[],s=e.split(`
|
|
19
|
-
`);for(const a of s){const n=a.match(/#(\d+)\.?\s*(?:\[(\w+)\]\s*)?(.+?)(?:\s*\((?:owner:\s*\w+)?\))?$/);if(n){const[,l,i,c]=n,d=a.match(/blockedBy:\s*\[([^\]]*)\]/);r.push({id:l,subject:c.trim(),status:i||"pending",blockedBy:d?d[1].split(",").map(u=>u.trim()).filter(Boolean):void 0})}}return r}const Cs={completed:{icon:t.jsx("svg",{className:"h-3.5 w-3.5 text-green-500 dark:text-green-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),textClass:"line-through text-gray-400 dark:text-gray-500",badgeClass:"bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300 border-green-200 dark:border-green-800"},in_progress:{icon:t.jsx("svg",{className:"h-3.5 w-3.5 text-blue-500 dark:text-blue-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),textClass:"text-gray-900 dark:text-gray-100",badgeClass:"bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 border-blue-200 dark:border-blue-800"},pending:{icon:t.jsx("svg",{className:"h-3.5 w-3.5 text-gray-400 dark:text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("circle",{cx:"12",cy:"12",r:"9",strokeWidth:2})}),textClass:"text-gray-700 dark:text-gray-300",badgeClass:"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 border-gray-200 dark:border-gray-700"}},ei=({content:e})=>{const r=Zl(e);if(r.length===0)return t.jsx("pre",{className:"whitespace-pre-wrap font-mono text-[11px] text-gray-600 dark:text-gray-400",children:e});const s=r.filter(n=>n.status==="completed").length,a=r.length;return t.jsxs("div",{children:[t.jsxs("div",{className:"mb-1.5 flex items-center gap-2",children:[t.jsxs("span",{className:"text-[11px] text-gray-500 dark:text-gray-400",children:[s,"/",a," completed"]}),t.jsx("div",{className:"h-1 flex-1 overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700",children:t.jsx("div",{className:"h-full rounded-full bg-green-500 transition-all dark:bg-green-400",style:{width:`${a>0?s/a*100:0}%`}})})]}),t.jsx("div",{className:"space-y-px",children:r.map(n=>{const l=Cs[n.status]||Cs.pending;return t.jsxs("div",{className:"group flex items-center gap-1.5 py-0.5",children:[t.jsx("span",{className:"flex-shrink-0",children:l.icon}),t.jsxs("span",{className:"flex-shrink-0 font-mono text-[11px] text-gray-400 dark:text-gray-500",children:["#",n.id]}),t.jsx("span",{className:`flex-1 truncate text-xs ${l.textClass}`,children:n.subject}),t.jsx("span",{className:`flex-shrink-0 rounded border px-1 py-px text-[10px] ${l.badgeClass}`,children:n.status.replace("_"," ")})]},n.id)})})]})},ti=({content:e,format:r="plain",className:s=""})=>{if(r==="json"){let a=e;try{const n=JSON.parse(e);a=JSON.stringify(n,null,2)}catch(n){console.warn("Failed to parse JSON content:",n)}return t.jsx("pre",{className:`mt-1 overflow-x-auto rounded bg-gray-900 p-2.5 font-mono text-xs text-gray-100 dark:bg-gray-950 ${s}`,children:a})}return r==="code"?t.jsx("pre",{className:`mt-1 overflow-hidden whitespace-pre-wrap break-words rounded border border-gray-200/50 bg-gray-50 p-2 font-mono text-xs text-gray-700 dark:border-gray-700/50 dark:bg-gray-800/50 dark:text-gray-300 ${s}`,children:e}):t.jsx("div",{className:`mt-1 whitespace-pre-wrap text-sm text-gray-700 dark:text-gray-300 ${s}`,children:e})},ri=({questions:e,answers:r,className:s=""})=>{const[a,n]=o.useState(null);if(!Array.isArray(e)||e.length===0)return null;const l=Object.keys(r||{}).length>0,i=e.length;return t.jsxs("div",{className:`space-y-2 ${s}`,children:[e.map((c,d)=>{if(!c||typeof c!="object"||typeof c.question!="string")return null;const u=c,x=r?.[u.question],v=typeof x=="string"?x.split(", "):[],g=!x,b=a===d,N=Array.isArray(u.options)?u.options.filter(k=>k&&typeof k=="object"&&typeof k.label=="string"):[];return t.jsxs("div",{className:"border-gray-150 overflow-hidden rounded-lg border bg-gray-50/50 dark:border-gray-700/50 dark:bg-gray-800/30",children:[t.jsxs("button",{type:"button",onClick:()=>n(b?null:d),className:"flex w-full items-start gap-2.5 px-3 py-2 text-left transition-colors hover:bg-gray-50 dark:hover:bg-gray-800/50",children:[t.jsx("div",{className:`mt-0.5 flex h-4 w-4 flex-shrink-0 items-center justify-center rounded-full ${v.length>0?"bg-blue-100 dark:bg-blue-900/40":"bg-gray-100 dark:bg-gray-800"}`,children:v.length>0?t.jsx("svg",{className:"h-2.5 w-2.5 text-blue-600 dark:text-blue-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:3,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):t.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-gray-300 dark:bg-gray-600"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[u.header&&t.jsx("span",{className:"inline-flex items-center rounded border border-blue-100/80 bg-blue-50 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wider text-blue-600 dark:border-blue-800/40 dark:bg-blue-900/30 dark:text-blue-400",children:u.header}),i>1&&t.jsxs("span",{className:"text-[10px] tabular-nums text-gray-400 dark:text-gray-500",children:[d+1,"/",i]})]}),t.jsx("div",{className:"mt-0.5 text-xs leading-snug text-gray-600 dark:text-gray-400",children:u.question}),!b&&v.length>0&&t.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1",children:v.map(k=>{const E=!N.some(w=>w.label===k);return t.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-blue-50 px-1.5 py-0.5 text-[11px] font-medium text-blue-700 dark:bg-blue-900/30 dark:text-blue-300",children:[k,E&&t.jsx("span",{className:"text-[9px] font-normal text-blue-400 dark:text-blue-500",children:"(custom)"})]},k)})}),!b&&g&&l&&t.jsx("span",{className:"mt-1 inline-block text-[10px] italic text-gray-400 dark:text-gray-500",children:"Skipped"})]}),t.jsx("svg",{className:`mt-0.5 h-3.5 w-3.5 flex-shrink-0 text-gray-400 transition-transform duration-200 dark:text-gray-500 ${b?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:2,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]}),b&&t.jsx("div",{className:"border-t border-gray-100 px-3 pb-2.5 pt-0.5 dark:border-gray-700/40",children:t.jsxs("div",{className:"ml-6.5 space-y-1",children:[N.map(k=>{const E=v.includes(k.label);return t.jsxs("div",{className:`flex items-start gap-2 rounded-lg px-2.5 py-1.5 text-[12px] ${E?"border border-blue-200/60 bg-blue-50/80 dark:border-blue-800/40 dark:bg-blue-900/20":"text-gray-400 dark:text-gray-500"}`,children:[t.jsx("div",{className:`mt-0.5 h-3.5 w-3.5 flex-shrink-0 ${u.multiSelect?"rounded-[3px]":"rounded-full"} flex items-center justify-center border-[1.5px] ${E?"border-blue-500 bg-blue-500 dark:border-blue-400 dark:bg-blue-500":"border-gray-300 dark:border-gray-600"}`,children:E&&t.jsx("svg",{className:"h-2 w-2 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:3,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:E?"font-medium text-gray-900 dark:text-gray-100":"",children:k.label}),k.description&&t.jsx("span",{className:`mt-0.5 block text-[11px] ${E?"text-blue-600/70 dark:text-blue-300/70":"text-gray-400 dark:text-gray-600"}`,children:k.description})]})]},k.label)}),v.filter(k=>!N.some(E=>E.label===k)).map(k=>t.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-blue-200/60 bg-blue-50/80 px-2.5 py-1.5 text-[12px] dark:border-blue-800/40 dark:bg-blue-900/20",children:[t.jsx("div",{className:`mt-0.5 h-3.5 w-3.5 flex-shrink-0 ${u.multiSelect?"rounded-[3px]":"rounded-full"} flex items-center justify-center border-[1.5px] border-blue-500 bg-blue-500 dark:border-blue-400 dark:bg-blue-500`,children:t.jsx("svg",{className:"h-2 w-2 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:3,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"font-medium text-gray-900 dark:text-gray-100",children:k}),t.jsx("span",{className:"ml-1 text-[10px] text-blue-500 dark:text-blue-400",children:"(custom)"})]})]},k)),g&&l&&t.jsx("div",{className:"px-2.5 py-1 text-[11px] italic text-gray-400 dark:text-gray-500",children:"No answer provided"})]})})]},d)}),!l&&i===1&&t.jsx("div",{className:"text-[11px] italic text-gray-400 dark:text-gray-500",children:"Skipped"})]})},si={claude:"Claude",codex:"Codex",cursor:"Cursor",opencode:"OpenCode"};function ni(e){return si[e||"claude"]}function ai(e,r){const s={};return e.forEach(({question:a,values:n})=>{if(n.length===0){r==="codex"&&a.id&&(s[a.id]={answers:[]});return}if(r==="codex"){s[a.id||a.question]={answers:n};return}s[a.question]=n.join(", ")}),s}const oi=({request:e,onDecision:r})=>{const s=e.input,a=o.useMemo(()=>s?.questions||[],[s?.questions]),[n,l]=o.useState(0),[i,c]=o.useState(()=>new Map),[d,u]=o.useState(()=>new Map),[x,v]=o.useState(()=>new Map),[g,b]=o.useState(!1),N=o.useRef(null),k=o.useRef(null);o.useEffect(()=>{requestAnimationFrame(()=>b(!0))},[]),o.useEffect(()=>{x.get(n)||N.current?.focus()},[n,x]),o.useEffect(()=>{x.get(n)&&k.current?.focus()},[x,n]);const E=o.useCallback(($,P,B)=>{c(z=>{const U=new Map(z),ee=new Set(U.get($)||[]);return B?ee.has(P)?ee.delete(P):ee.add(P):(ee.clear(),ee.add(P),v(ie=>{const X=new Map(ie);return X.set($,!1),X})),U.set($,ee),U})},[]),w=o.useCallback(($,P)=>{v(B=>{const z=new Map(B),U=z.get($)||!1;return z.set($,!U),!P&&!U&&c(ee=>{const ie=new Map(ee);return ie.set($,new Set),ie}),z})},[]),L=o.useCallback(($,P)=>{u(B=>{const z=new Map(B);return z.set($,P),z})},[]),f=o.useCallback(()=>{const $=a.map((P,B)=>{const z=Array.from(i.get(B)||[]),U=x.get(B)||!1,ee=(d.get(B)||"").trim();return U&&ee&&z.push(ee),{question:P,values:z}});return ai($,e.provider)},[a,i,x,d,e.provider]),m=o.useCallback(()=>{r(e.requestId,{allow:!0,updatedInput:{...s,answers:f()}})},[r,e.requestId,s,f]),p=o.useCallback(()=>{r(e.requestId,{allow:!0,updatedInput:{...s,answers:{}}})},[r,e.requestId,s]),h=o.useCallback($=>{if($.target instanceof HTMLInputElement)return;const P=a[n];if(!P)return;const B=P.multiSelect||!1,z=P.options.length,U=parseInt($.key);if(!isNaN(U)&&U>=1&&U<=z){$.preventDefault(),E(n,P.options[U-1].label,B);return}if($.key==="0"){$.preventDefault(),w(n,B);return}if($.key==="Enter"){$.preventDefault(),n===a.length-1?m():l(ie=>ie+1);return}if($.key==="Escape"){$.preventDefault(),p();return}},[n,a,E,w,m,p]);if(a.length===0)return null;const y=a.length,I=y===1,T=a[n],j=T.multiSelect||!1,A=i.get(n)||new Set,_=x.get(n)||!1,H=n===y-1,M=n===0,O=A.size>0||_&&(d.get(n)||"").trim().length>0;return t.jsx("div",{ref:N,tabIndex:-1,onKeyDown:h,className:`w-full outline-none transition-all duration-500 ease-out ${g?"translate-y-0 opacity-100":"translate-y-3 opacity-0"}`,children:t.jsxs("div",{className:"relative overflow-hidden rounded-2xl border border-gray-200/80 bg-white shadow-lg dark:border-gray-700/50 dark:bg-gray-800/90 dark:shadow-2xl",children:[t.jsx("div",{className:"absolute left-0 right-0 top-0 h-[2px] bg-gradient-to-r from-blue-500 via-cyan-400 to-teal-400"}),t.jsxs("div",{className:"px-4 pb-2 pt-3.5",children:[t.jsxs("div",{className:"mb-1.5 flex items-center gap-2.5",children:[t.jsxs("div",{className:"relative flex-shrink-0",children:[t.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-lg bg-gradient-to-br from-blue-500/10 to-cyan-500/10 dark:from-blue-400/15 dark:to-cyan-400/15",children:t.jsx("svg",{className:"h-3.5 w-3.5 text-blue-600 dark:text-blue-400",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.75,stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.879 7.519c1.171-1.025 3.071-1.025 4.242 0 1.172 1.025 1.172 2.687 0 3.712-.203.179-.43.326-.67.442-.745.361-1.45.999-1.45 1.827m0 3h.01"})})}),t.jsx("div",{className:"absolute -right-0.5 -top-0.5 h-2 w-2 animate-pulse rounded-full bg-cyan-400 dark:bg-cyan-500"})]}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[t.jsxs("span",{className:"text-[10px] font-medium uppercase tracking-wide text-gray-400 dark:text-gray-500",children:[ni(e.provider)," needs your input"]}),T.header&&t.jsx("span",{className:"inline-flex items-center rounded border border-blue-100 bg-blue-50 px-1.5 py-px text-[9px] font-semibold uppercase tracking-wider text-blue-600 dark:border-blue-800/50 dark:bg-blue-900/30 dark:text-blue-400",children:T.header})]}),!I&&t.jsxs("span",{className:"flex-shrink-0 text-[10px] tabular-nums text-gray-400 dark:text-gray-500",children:[n+1,"/",y]})]}),!I&&t.jsx("div",{className:"mb-2 flex items-center gap-1",children:a.map(($,P)=>t.jsx("button",{type:"button",onClick:()=>l(P),className:`h-[3px] rounded-full transition-all duration-300 ${P===n?"w-5 bg-blue-500 dark:bg-blue-400":P<n?"w-2.5 bg-blue-300 dark:bg-blue-600":"w-2.5 bg-gray-200 dark:bg-gray-700"}`},P))}),t.jsx("p",{className:"text-[14px] font-medium leading-snug text-gray-900 dark:text-gray-100",children:T.question}),j&&t.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500",children:"Select all that apply"})]}),t.jsx("div",{className:"scrollbar-thin max-h-48 overflow-y-auto px-4 pb-2",role:j?"group":"radiogroup","aria-label":T.question,children:t.jsxs("div",{className:"space-y-1",children:[T.options.map(($,P)=>{const B=A.has($.label);return t.jsxs("button",{type:"button",onClick:()=>E(n,$.label,j),className:`group flex w-full items-center gap-2.5 rounded-lg border px-3 py-2 text-left transition-all duration-150 ${B?"border-blue-300 bg-blue-50/80 ring-1 ring-blue-200/50 dark:border-blue-600 dark:bg-blue-900/25 dark:ring-blue-700/30":"border-gray-200 hover:border-gray-300 hover:bg-gray-50/60 dark:border-gray-700/60 dark:hover:border-gray-600 dark:hover:bg-gray-700/40"}`,children:[t.jsx("kbd",{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded font-mono text-[10px] transition-all duration-150 ${B?"bg-blue-500 font-semibold text-white dark:bg-blue-500":"border border-gray-200 bg-gray-100 text-gray-400 group-hover:border-gray-300 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-500 dark:group-hover:border-gray-600"}`,children:P+1}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:`text-[13px] leading-tight transition-colors duration-150 ${B?"font-medium text-gray-900 dark:text-gray-100":"text-gray-700 dark:text-gray-300"}`,children:$.label}),$.description&&t.jsx("div",{className:`text-[11px] leading-snug transition-colors duration-150 ${B?"text-blue-600/70 dark:text-blue-300/70":"text-gray-400 dark:text-gray-500"}`,children:$.description})]}),B&&t.jsx("svg",{className:"h-4 w-4 flex-shrink-0 text-blue-500 dark:text-blue-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:2.5,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.5 12.75l6 6 9-13.5"})})]},$.label)}),t.jsxs("button",{type:"button",onClick:()=>w(n,j),className:`group flex w-full items-center gap-2.5 rounded-lg border px-3 py-2 text-left transition-all duration-150 ${_?"border-blue-300 bg-blue-50/80 ring-1 ring-blue-200/50 dark:border-blue-600 dark:bg-blue-900/25 dark:ring-blue-700/30":"border-dashed border-gray-200 hover:border-gray-300 hover:bg-gray-50/60 dark:border-gray-700/60 dark:hover:border-gray-600 dark:hover:bg-gray-700/40"}`,children:[t.jsx("kbd",{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded font-mono text-[10px] transition-all duration-150 ${_?"bg-blue-500 font-semibold text-white dark:bg-blue-500":"border border-gray-200 bg-gray-100 text-gray-400 group-hover:border-gray-300 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-500 dark:group-hover:border-gray-600"}`,children:"0"}),t.jsx("span",{className:`text-[13px] leading-tight transition-colors ${_?"font-medium text-gray-900 dark:text-gray-100":"text-gray-500 dark:text-gray-400"}`,children:"Other..."}),_&&t.jsx("svg",{className:"ml-auto h-4 w-4 flex-shrink-0 text-blue-500 dark:text-blue-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:2.5,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.5 12.75l6 6 9-13.5"})})]}),_&&t.jsx("div",{className:"pl-[30px] pr-0.5",children:t.jsxs("div",{className:"relative",children:[t.jsx("input",{ref:k,type:"text",value:d.get(n)||"",onChange:$=>L(n,$.target.value),onKeyDown:$=>{$.key==="Enter"&&($.preventDefault(),H?m():l(P=>P+1)),$.stopPropagation()},placeholder:"Type your answer...",className:"w-full rounded-lg border-0 bg-gray-50 px-3 py-1.5 text-[13px] text-gray-900 outline-none ring-1 ring-gray-200 transition-shadow duration-200 placeholder:text-gray-400 focus:ring-2 focus:ring-blue-400 dark:bg-gray-900/60 dark:text-gray-100 dark:ring-gray-700 dark:placeholder:text-gray-600 dark:focus:ring-blue-500"}),t.jsx("kbd",{className:"absolute right-2 top-1/2 -translate-y-1/2 rounded border border-gray-200 bg-gray-100 px-1 py-0.5 font-mono text-[9px] text-gray-300 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-600",children:"Enter"})]})})]})}),t.jsxs("div",{className:"flex items-center justify-between gap-2 border-t border-gray-100 bg-gray-50/50 px-4 py-2 dark:border-gray-700/50 dark:bg-gray-800/50",children:[t.jsxs("button",{type:"button",onClick:p,className:"text-[11px] text-gray-400 transition-colors hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300",children:[I?"Skip":"Skip all",t.jsx("span",{className:"ml-1 text-[9px] text-gray-300 dark:text-gray-600",children:"Esc"})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[!I&&!M&&t.jsxs("button",{type:"button",onClick:()=>l($=>$-1),className:"inline-flex items-center gap-0.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium text-gray-600 transition-all duration-150 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-700/60",children:[t.jsx("svg",{className:"h-3 w-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:2,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 19l-7-7 7-7"})}),"Back"]}),H?t.jsxs("button",{type:"button",onClick:m,disabled:!O&&!Object.keys(f()).length,className:"inline-flex items-center gap-1 rounded-lg bg-gradient-to-r from-blue-600 to-blue-500 px-3.5 py-1.5 text-[11px] font-semibold text-white shadow-sm transition-all duration-200 hover:shadow-md disabled:cursor-not-allowed disabled:opacity-30 disabled:shadow-none dark:from-blue-500 dark:to-blue-600",children:["Submit",t.jsx("span",{className:"ml-0.5 font-mono text-[9px] opacity-70",children:"Enter"})]}):t.jsxs("button",{type:"button",onClick:()=>l($=>$+1),className:"inline-flex items-center gap-1 rounded-lg bg-gradient-to-r from-blue-600 to-blue-500 px-3.5 py-1.5 text-[11px] font-semibold text-white shadow-sm transition-all duration-200 hover:shadow-md dark:from-blue-500 dark:to-blue-600",children:["Next",t.jsx("span",{className:"ml-0.5 font-mono text-[9px] opacity-70",children:"Enter"})]})]})]})]})})},li=({title:e,content:r,defaultOpen:s=!1,isStreaming:a=!1,showRawParameters:n=!1,rawContent:l,toolName:i})=>{const c=Do(),d=c?.pendingPermissionRequests.find(v=>v.toolName==="ExitPlanMode"||v.toolName==="exit_plan_mode"),u=()=>{d&&c&&c.handlePermissionDecision(d.requestId,{allow:!0})},x=()=>{d&&c&&c.handlePermissionDecision(d.requestId,{allow:!1,message:"User asked to revise the plan"})};return t.jsx(Dt,{defaultOpen:s,children:t.jsxs(_s,{className:"my-1 flex flex-col shadow-none",children:[t.jsxs(ra,{className:"flex flex-row items-start justify-between space-y-0 px-4 pb-0 pt-4",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Rr,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),t.jsx(sa,{className:"text-sm font-semibold",children:a?t.jsx(Nr,{children:e}):e})]}),t.jsxs(Et,{className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground",children:[t.jsx(Sa,{className:"h-4 w-4"}),t.jsx("span",{className:"sr-only",children:"Toggle plan"})]})]}),t.jsx(Ft,{children:t.jsxs(na,{className:"px-4 pb-4 pt-3",children:[r?t.jsx(kn,{content:r,className:"prose prose-sm max-w-none dark:prose-invert"}):a?t.jsx("div",{className:"py-2",children:t.jsx(Nr,{children:"Generating plan..."})}):null,n&&l&&t.jsxs(Dt,{className:"mt-3",children:[t.jsxs(Et,{className:"flex items-center gap-1.5 py-0.5 text-[11px] text-muted-foreground hover:text-foreground",children:[t.jsx("svg",{className:"h-2.5 w-2.5 flex-shrink-0 transition-transform duration-150 data-[state=open]:rotate-90",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),"raw params"]}),t.jsx(Ft,{children:t.jsx("pre",{className:"mt-1 overflow-hidden whitespace-pre-wrap break-words rounded border border-border/40 bg-muted p-2 font-mono text-[11px] text-muted-foreground",children:l})})]})]})}),d&&t.jsxs(aa,{className:"justify-end gap-2 border-t border-border/40 px-4 pb-3 pt-3",children:[t.jsx(Qe,{variant:"ghost",size:"sm",onClick:x,className:"text-muted-foreground",children:"Revise"}),t.jsxs(Qe,{size:"sm",onClick:u,children:["Build"," ",t.jsx("kbd",{className:"ml-1 rounded bg-primary-foreground/20 px-1 py-0.5 font-mono text-[10px]",children:"⌘↩"})]})]})]})})};function ii(e){return["Edit","Write","ApplyPatch"].includes(e)?"edit":["Grep","Glob"].includes(e)?"search":e==="Bash"?"bash":["TodoWrite","TodoRead"].includes(e)?"todo":["TaskCreate","TaskUpdate","TaskList","TaskGet"].includes(e)?"task":e==="Task"?"agent":e==="exit_plan_mode"||e==="ExitPlanMode"?"plan":e==="AskUserQuestion"?"question":"default"}const ci=["user denied tool use","tool disallowed by settings","permission request timed out","permission request cancelled"];function di(e){if(!e)return"running";if(e.isError){const r=String(e.content||"").toLowerCase().trim();return ci.some(s=>r.includes(s))?"denied":"error"}return"completed"}const $r=o.memo(({toolName:e,toolInput:r,toolResult:s,toolId:a,mode:n,onFileOpen:l,createDiff:i,selectedProject:c,showRawParameters:d=!1,rawToolInput:u,isSubagentContainer:x,subagentState:v})=>{const g=ir(e),b=n==="input"?g.input:g.result,N=o.useMemo(()=>{try{const w=n==="input"?r:s;return typeof w=="string"?JSON.parse(w):w}catch{return n==="input"?r:s}},[n,r,s]),k=o.useMemo(()=>n==="input"?di(s):void 0,[n,s]),E=o.useCallback(()=>{if(b?.action==="open-file"&&l){const w=b.getValue?.(N)||"";l(w)}},[b,N,l]);if(x&&v)return n==="result"?null:t.jsx(Gl,{toolInput:r,toolResult:s,subagentState:v});if(!b)return null;if(e==="Bash"&&n==="input"){const w=typeof N=="object"&&N!==null&&"command"in N?String(N.command||""):typeof r=="string"?r:typeof u=="string"?u:"",L=typeof N=="object"&&N!==null&&"description"in N?String(N.description||""):void 0,f=typeof s?.content=="string"?s.content:s?.content!=null?String(s.content):"";return t.jsx(Ul,{command:w,description:L,output:f,isError:!!s?.isError,status:k!=="completed"?k:void 0,defaultOpen:!1})}if(b.type==="one-line"){const w=b.getValue?.(N)||"",L=b.getSecondary?.(N);return t.jsx(Fl,{toolName:e,toolResult:s,toolId:a,icon:b.icon,label:b.label,value:w,secondary:L,action:b.action,onAction:E,style:b.style,wrapText:b.wrapText,colorScheme:b.colorScheme,resultId:n==="input"?`tool-result-${a}`:void 0,status:k!=="completed"?k:void 0})}if(b.type==="plan"){const w=typeof b.title=="function"?b.title(N):b.title||"Plan",L=b.getContentProps?.(N,{selectedProject:c,createDiff:i,onFileOpen:l})||{},f=n==="input"&&!s;return t.jsx(li,{title:w,content:L.content||"",defaultOpen:b.defaultOpen??!1,isStreaming:f,showRawParameters:n==="input"&&d,rawContent:u,toolName:e,toolId:a})}if(b.type==="collapsible"){const w=typeof b.title=="function"?b.title(N):b.title||"Details",L=b.defaultOpen!==void 0?b.defaultOpen:!1,f=b.getContentProps?.(N,{selectedProject:c,createDiff:i,onFileOpen:l})||{};let m=null;switch(b.contentType){case"diff":i&&(m=t.jsx(_l,{...f,createDiff:i,onFileClick:()=>l?.(f.filePath)}));break;case"markdown":m=t.jsx(kn,{content:f.content||""});break;case"file-list":m=t.jsx(Jl,{files:f.files||[],onFileClick:l,title:f.title});break;case"todo-list":f.todos?.length>0&&(m=t.jsx(Xl,{todos:f.todos,isResult:f.isResult}));break;case"task":m=t.jsx(ei,{content:f.content||""});break;case"question-answer":m=t.jsx(ri,{questions:f.questions||[],answers:f.answers||{}});break;case"text":m=t.jsx(ti,{content:f.content||"",format:f.format||"plain"});break;case"success-message":{const y=b.getMessage?.(N)||"Success";m=t.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-600 dark:text-green-400",children:[t.jsx("svg",{className:"h-3 w-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),y]});break}}const p=(e==="Edit"||e==="Write"||e==="ApplyPatch")&&f.filePath&&l?()=>l(f.filePath,{old_string:f.oldContent,new_string:f.newContent}):void 0,h=k&&k!=="completed"?t.jsx(Mt,{status:k}):void 0;return t.jsx(Kl,{toolName:e,toolId:a,title:w,defaultOpen:L,onTitleClick:p,badge:h,showRawParameters:n==="input"&&d,rawContent:u,toolCategory:ii(e),children:m})}return null});$r.displayName="ToolRenderer";function ui(e,r){const[s,a]=o.useState(e.data||null),[n,l]=o.useState(!1);return o.useEffect(()=>{if(e.data){a(e.data),l(!1);return}const i=e.path;if(!i){a(null),l(!0);return}const c=i.split(/[\\/]/).pop()||"",d=[`/api/assets/images/${encodeURIComponent(c)}`,...r?[`/api/file-tree/projects/${r}/files/content?path=${encodeURIComponent(i)}`]:[]];let u=null;const x=new AbortController;return(async()=>{l(!1);for(const g of d)try{const b=await $e(g,{signal:x.signal});if(!b.ok)continue;const N=await b.blob();u=URL.createObjectURL(N),a(u);return}catch(b){if(b instanceof Error&&b.name==="AbortError")return}a(null),l(!0)})(),()=>{x.abort(),u&&URL.revokeObjectURL(u)}},[e.data,e.path,r]),{src:s,failed:n}}function vn({src:e,alt:r,onClose:s}){return o.useEffect(()=>{const a=n=>{n.key==="Escape"&&(n.stopPropagation(),s())};return document.addEventListener("keydown",a,!0),()=>document.removeEventListener("keydown",a,!0)},[s]),qt.createPortal(t.jsxs("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/80 backdrop-blur-sm",onClick:s,role:"dialog","aria-modal":"true","aria-label":r,children:[t.jsx("button",{type:"button",onClick:s,"aria-label":"Close image preview",className:"absolute right-4 top-4 rounded-full bg-white/10 p-2 text-white transition-colors hover:bg-white/20",children:t.jsx(it,{className:"h-5 w-5"})}),t.jsx("img",{src:e,alt:r,onClick:a=>a.stopPropagation(),className:"max-h-[90vh] max-w-[92vw] rounded-lg object-contain shadow-2xl"})]}),document.body)}function mi({image:e,projectId:r}){const{src:s,failed:a}=ui(e,r),[n,l]=o.useState(!1),i=e.name||"Attached image";return a?t.jsx("div",{className:"flex h-28 w-28 items-center justify-center rounded-xl border border-border/50 bg-muted px-2 text-center text-[10px] text-muted-foreground",children:i}):s?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>l(!0),"aria-label":`Expand ${i}`,className:"block overflow-hidden rounded-xl border border-border/50 shadow-sm focus:outline-none focus:ring-2 focus:ring-primary/60",children:t.jsx("img",{src:s,alt:i,className:"h-28 w-28 cursor-zoom-in object-cover transition-transform duration-200 hover:scale-105"})}),n&&t.jsx(vn,{src:s,alt:i,onClose:()=>l(!1)})]}):t.jsx("div",{className:"h-28 w-28 animate-pulse rounded-xl border border-border/50 bg-muted"})}function pi({images:e,projectId:r}){return!e||e.length===0?null:t.jsx("div",{className:"flex flex-wrap justify-end gap-2",children:e.map((s,a)=>t.jsx(mi,{image:s,projectId:r},s.path||s.name||a))})}const fi=e=>typeof e!="number"?null:e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`,xi=e=>{const r=(e.name||e.path||"").toLowerCase();return(e.mimeType||"").startsWith("text/")||/\.(md|txt|pdf|docx?)$/.test(r)?Rr:/\.(zip|rar|7z|tar|gz)$/.test(r)?Ma:/\.(js|jsx|ts|tsx|py|rb|go|rs|java|c|cpp|css|html|json|ya?ml)$/.test(r)?Ta:qs};function hi({file:e}){const[r,s]=o.useState(!1),a=e.name||e.path?.split(/[\\/]/).pop()||"Attached file",n=xi(e),l=fi(e.size),i=async()=>{if(!e.path||r)return;const c=e.path.split(/[\\/]/).pop();if(c){s(!0);try{const d=await $e(`/api/assets/files/${encodeURIComponent(c)}`);if(!d.ok)return;const u=URL.createObjectURL(await d.blob()),x=document.createElement("a");x.href=u,x.download=a,x.click(),window.setTimeout(()=>URL.revokeObjectURL(u),0)}catch(d){console.error(`Failed to download attachment "${a}":`,d)}finally{s(!1)}}};return t.jsxs("button",{type:"button",onClick:()=>{i()},disabled:!e.path||r,className:"group/file flex w-64 max-w-full items-center gap-3 rounded-xl border border-border/50 bg-card px-3 py-2.5 text-left shadow-sm transition-colors hover:bg-accent/60 disabled:cursor-default disabled:hover:bg-card","aria-label":`Download ${a}`,children:[t.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary",children:t.jsx(n,{className:"h-5 w-5","aria-hidden":!0})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"truncate text-sm font-medium text-foreground",title:a,children:a}),t.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:l||"File attachment"})]}),t.jsx(Bs,{className:`h-4 w-4 shrink-0 text-muted-foreground transition-colors group-hover/file:text-foreground ${r?"animate-pulse":""}`,"aria-hidden":!0})]})}function gi({files:e}){return e?.length?t.jsx("div",{className:"flex max-w-full flex-wrap justify-end gap-2",children:e.map((r,s)=>t.jsx(hi,{file:r},r.path||r.name||s))}):null}const bi=2e3,yi=e=>{let r=e.replace(/\r\n/g,`
|
|
20
|
-
`);const s=[];return r=r.replace(/```[\w-]*\n([\s\S]*?)```/g,(a,n)=>{const l=`@@CODEBLOCK${s.length}@@`;return s.push(n.replace(/\n$/,"")),l}),r=r.replace(/`([^`]+)`/g,"$1"),r=r.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,"$1"),r=r.replace(/\[([^\]]+)\]\(([^)]+)\)/g,"$1"),r=r.replace(/^>\s?/gm,""),r=r.replace(/^#{1,6}\s+/gm,""),r=r.replace(/^[-*+]\s+/gm,""),r=r.replace(/^\d+\.\s+/gm,""),r=r.replace(/(\*\*|__)(.*?)\1/g,"$2"),r=r.replace(/(\*|_)(.*?)\1/g,"$2"),r=r.replace(/~~(.*?)~~/g,"$1"),r=r.replace(/<\/?[^>]+(>|$)/g,""),r=r.replace(/\n{3,}/g,`
|
|
21
|
-
|
|
22
|
-
`),r=r.replace(/@@CODEBLOCK(\d+)@@/g,(a,n)=>s[Number(n)]??""),r.trim()},yr=({content:e,messageType:r})=>{const{t:s}=We("chat"),a=r==="assistant",n=a?"markdown":"text",[l,i]=o.useState(n),[c,d]=o.useState(!1),[u,x]=o.useState(!1),[v,g]=o.useState({}),b=o.useRef(null),N=o.useRef(null),k=o.useRef(null),E=o.useRef(null),w=()=>{const j=N.current?.getBoundingClientRect();if(j){const _=j.bottom+84+8>window.innerHeight;g({position:"fixed",right:Math.max(8,window.innerWidth-j.right),zIndex:1e3,..._?{bottom:window.innerHeight-j.top+4}:{top:j.bottom+4}})}x(!0)},L=o.useMemo(()=>[{format:"markdown",label:s("copyMessage.copyAsMarkdown",{defaultValue:"Copy as markdown"})},{format:"text",label:s("copyMessage.copyAsText",{defaultValue:"Copy as text"})}],[s]),f=l==="markdown"?s("copyMessage.markdownShort",{defaultValue:"MD"}):s("copyMessage.textShort",{defaultValue:"TXT"}),m=o.useMemo(()=>l==="markdown"?e:yi(e),[e,l]);o.useEffect(()=>{i(n),x(!1)},[n]),o.useEffect(()=>{if(!u)return;const j=_=>{const H=_.target;b.current?.contains(H)||k.current?.contains(H)||x(!1)},A=()=>x(!1);return window.addEventListener("mousedown",j),window.addEventListener("scroll",A,!0),window.addEventListener("resize",A),()=>{window.removeEventListener("mousedown",j),window.removeEventListener("scroll",A,!0),window.removeEventListener("resize",A)}},[u]),o.useEffect(()=>()=>{E.current&&clearTimeout(E.current)},[]);const p=async()=>{!m.trim()||!await Vt(m)||(d(!0),E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{d(!1)},bi))},h=j=>{i(j),x(!1)},y=r==="user"?"text-muted-foreground hover:text-foreground":"text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300",I=s(c?"copyMessage.copied":"copyMessage.copy"),T=a?"relative flex min-w-0 flex-1 items-center gap-0.5 sm:min-w-max sm:flex-none sm:w-auto":"relative flex items-center gap-0.5";return t.jsxs("div",{ref:b,className:T,children:[t.jsxs("button",{type:"button",onClick:p,title:I,"aria-label":I,className:`inline-flex items-center gap-1 rounded px-1 py-0.5 transition-colors ${y}`,children:[c?t.jsx("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}):t.jsxs("svg",{className:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),t.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]}),t.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide",children:f})]}),a&&t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:N,type:"button",onClick:()=>u?x(!1):w(),className:`rounded px-1 py-0.5 transition-colors ${y}`,"aria-label":s("copyMessage.selectFormat",{defaultValue:"Select copy format"}),title:s("copyMessage.selectFormat",{defaultValue:"Select copy format"}),children:t.jsx("svg",{className:`h-3 w-3 transition-transform ${u?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),u&&qt.createPortal(t.jsx("div",{ref:k,style:v,className:"min-w-36 rounded-md border border-border bg-popover p-1 shadow-lg",children:L.map(j=>{const A=j.format===l;return t.jsx("button",{type:"button",onClick:()=>h(j.format),className:`block w-full rounded px-2 py-1.5 text-left transition-colors ${A?"bg-accent text-foreground":"text-foreground hover:bg-accent"}`,children:t.jsx("span",{className:"block text-xs font-medium",children:j.label})},j.format)})}),document.body)]})]})};function jn(e,r){return`${e.replace(/\/$/,"")}${r}`}function ki(){return JSON.stringify(or())}function wi(e,r){const s=or(),a=new FormData;return s.baseUrl.trim()?(a.append("file",e,r),a.append("model",s.sttModel||"whisper-1"),fetch(jn(s.baseUrl.trim(),"/audio/transcriptions"),{method:"POST",headers:s.apiKey?{Authorization:`Bearer ${s.apiKey}`}:{},body:a})):(a.append("audio",e,r),$e("/api/voice/transcribe",{method:"POST",headers:Ds(),body:a}))}function vi(e,r){const s=or();return s.baseUrl.trim()?fetch(jn(s.baseUrl.trim(),"/audio/speech"),{method:"POST",headers:{"Content-Type":"application/json",...s.apiKey?{Authorization:`Bearer ${s.apiKey}`}:{}},body:JSON.stringify({model:s.ttsModel||"tts-1",voice:s.ttsVoice||"alloy",input:e,...s.ttsFormat.trim()?{response_format:s.ttsFormat.trim()}:{}}),signal:r}):$e("/api/voice/tts",{method:"POST",body:JSON.stringify({text:e}),headers:Ds(),signal:r})}const ji={state:"idle",error:null},Ni=24,Ci=33e4;function Nn(e,r=ki()){const s=JSON.stringify([e,r]);let a=5381;for(let n=0;n<s.length;n++)a=(a<<5)+a+s.charCodeAt(n)|0;return(a>>>0).toString(36)}class Si{audio=null;unlocked=!1;cache=new Map;currentId=null;state="idle";errorId=null;errorMsg=null;token=0;activeController=null;errorTimer=null;listeners=new Set;subscribe(r){return this.listeners.add(r),()=>{this.listeners.delete(r)}}emit(){this.listeners.forEach(r=>r())}getSnapshot(r){const s=this.currentId===r?this.state:"idle",a=this.errorId===r?this.errorMsg:null;return s==="idle"&&a===null?ji:{state:s,error:a}}ensureAudio(){if(!this.audio){const r=new Audio;r.addEventListener("ended",()=>this.onEnded()),r.addEventListener("error",()=>{this.state==="playing"&&this.onEnded()}),this.audio=r}return this.audio}unlock(){if(this.unlocked)return;const r=this.ensureAudio();try{const s=r.play();s&&typeof s.catch=="function"&&s.catch(()=>{}),r.pause()}catch{}this.unlocked=!0}toggle(r){const s=Nn(r);if(this.currentId===s&&(this.state==="playing"||this.state==="loading")){this.stop();return}this.play(s,r)}stop(){this.token++,this.abortActive(),this.audio&&this.audio.pause(),this.state="idle",this.currentId=null,this.emit()}abortActive(){this.activeController&&(this.activeController.abort(),this.activeController=null)}onEnded(){this.state="idle",this.currentId=null,this.emit()}setError(r,s){this.state="idle",this.currentId=r,this.errorId=r,this.errorMsg=s,this.emit(),this.errorTimer&&clearTimeout(this.errorTimer),this.errorTimer=setTimeout(()=>{this.errorId===r&&(this.errorId=null,this.errorMsg=null,this.currentId===r&&(this.currentId=null),this.emit())},6e3)}async play(r,s){const a=this.ensureAudio();a.pause(),this.currentId=r,this.errorId=null,this.errorMsg=null,this.state="loading",this.emit();const n=++this.token;this.abortActive();try{let l=this.cache.get(r);if(!l){const i=new AbortController;this.activeController=i;const c=setTimeout(()=>i.abort(),Ci),d=await vi(s,i.signal).finally(()=>{clearTimeout(c),this.activeController===i&&(this.activeController=null)});if(n!==this.token)return;if(!d.ok){let x=`Read-aloud failed (${d.status})`;try{const v=await d.json();v?.error&&(x=String(v.error))}catch{}throw new Error(x)}const u=await d.blob();if(n!==this.token)return;l=URL.createObjectURL(u),this.cacheSet(r,l)}if(n!==this.token||(a.src=l,a.load(),await a.play(),n!==this.token))return;this.state="playing",this.emit()}catch(l){if(n!==this.token)return;const i=l instanceof Error&&l.name==="AbortError";this.setError(r,i?"Read-aloud timed out.":l instanceof Error?l.message:"Read-aloud failed")}}cacheSet(r,s){for(this.cache.set(r,s);this.cache.size>Ni;){const a=this.cache.keys().next().value;if(a===void 0)break;const n=this.cache.get(a);this.cache.delete(a),n&&n!==this.audio?.src&&URL.revokeObjectURL(n)}}}const Pt=new Si;function Mi(e){const r=e(),s=Nn(r),[a,n]=o.useState(()=>Pt.getSnapshot(s));o.useEffect(()=>{const i=()=>n(c=>{const d=Pt.getSnapshot(s);return c.state===d.state&&c.error===d.error?c:d});return i(),Pt.subscribe(i)},[s]);const l=o.useCallback(()=>{Pt.unlock(),Pt.toggle(r)},[r]);return{state:a.state,toggle:l,error:a.error}}const Ti="uiPreferences",Ss="ui-preferences:sync";let Qt=null;function Ei(){if(Qt)return Qt;const e=$e("/api/voice/health").then(async r=>{if(!r.ok)throw new Error(`Voice health check failed (${r.status})`);return(await r.json())?.configured===!0}).finally(()=>{Qt=null});return Qt=e,e}function Ms(){try{const e=localStorage.getItem(Ti);if(!e)return!1;const r=JSON.parse(e);return r?.voiceEnabled===!0||r?.voiceEnabled==="true"}catch{return!1}}function Cn(){const[e,r]=o.useState(()=>typeof window>"u"?!1:Ms()),[s,a]=o.useState(!1);return o.useEffect(()=>{const n=()=>r(Ms());return window.addEventListener("storage",n),window.addEventListener(Ss,n),()=>{window.removeEventListener("storage",n),window.removeEventListener(Ss,n)}},[]),o.useEffect(()=>{let n=!0,l=0;const i=async()=>{if(!e){a(!1);return}if(or().baseUrl.trim()){a(!0);return}const c=++l;try{const d=await Ei();n&&c===l&&a(d)}catch{n&&c===l&&a(!1)}};return i(),window.addEventListener(qr,i),()=>{n=!1,window.removeEventListener(qr,i)}},[e]),e&&s}const Ii=({content:e})=>{const{t:r}=We("chat"),s=Cn(),{state:a,toggle:n,error:l}=Mi(()=>e);if(!s)return null;const i=r(a==="playing"?"voice.stopSpeaking":a==="loading"?"voice.loading":"voice.speak");return t.jsxs("span",{className:"relative inline-flex",children:[l&&t.jsx("span",{className:"absolute bottom-full left-1/2 z-10 mb-1 max-w-[240px] -translate-x-1/2 whitespace-normal rounded bg-red-600 px-2 py-1 text-center text-xs text-white shadow-lg",children:l}),t.jsx("button",{type:"button",onClick:n,title:i,"aria-label":i,className:"inline-flex items-center gap-1 rounded px-1 py-0.5 text-gray-400 transition-colors hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300",children:a==="playing"?t.jsx(Vs,{className:"h-3.5 w-3.5"}):a==="loading"?t.jsx($t,{className:"h-3.5 w-3.5 animate-spin"}):t.jsx(Ea,{className:"h-3.5 w-3.5"})})]})},$i=new Set(["Bash","Edit","Write","ApplyPatch"]),Sn=o.memo(({message:e,prevMessage:r,createDiff:s,onFileOpen:a,showRawParameters:n,showThinking:l,selectedProject:i,provider:c})=>{const{t:d}=We("chat"),u=r&&r.type===e.type&&(r.type==="assistant"||r.type==="user"||r.type==="tool"||r.type==="error"),x=o.useRef(null),v=String(e.content||""),g=o.useMemo(()=>{const f=Er(String(e.content||""));return c==="codex"&&e.type==="assistant"&&!e.isThinking?Yo(f):f},[e.content,e.isThinking,e.type,c]),b=e.isToolUse?String(e.displayText||e.content||""):g,N=!!(e.isToolUse&&$i.has(String(e.toolName||""))),k=e.type==="user"&&v.trim().length>0,E=e.type==="assistant"&&b.trim().length>0&&!N&&!e.isThinking,w=o.useMemo(()=>new Date(e.timestamp).toLocaleTimeString(),[e.timestamp]);return e.isThinking&&!l?null:t.jsx("div",{ref:x,"data-message-timestamp":e.timestamp||void 0,className:`chat-message ${e.type} ${u?"grouped":""} ${e.type==="user"?"flex justify-end px-3 sm:px-0":"px-3 sm:px-0"}`,children:e.type==="user"?t.jsxs("div",{className:"flex w-full items-end space-x-0 sm:w-auto sm:max-w-[85%] sm:space-x-3 md:max-w-md lg:max-w-lg xl:max-w-xl",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 flex-col items-end gap-2 sm:flex-initial",children:[e.images&&e.images.length>0&&t.jsx(pi,{images:e.images,projectId:i?.projectId}),e.files&&e.files.length>0&&t.jsx(gi,{files:e.files}),v.trim().length>0||!e.images?.length&&!e.files?.length?t.jsxs("div",{className:"group max-w-full rounded-2xl rounded-br-md border border-border/60 bg-muted/60 px-3 py-2 text-foreground shadow-sm dark:bg-gray-800/60 sm:px-4",children:[t.jsx("div",{dir:"auto",className:"break-words font-serif text-sm",children:t.jsx(Tt,{breaks:!0,className:"prose prose-sm max-w-none font-serif dark:prose-invert",children:e.content})}),t.jsxs("div",{className:"mt-1 flex items-center justify-end gap-1 text-xs text-muted-foreground",children:[k&&t.jsx(yr,{content:v,messageType:"user"}),t.jsx("span",{children:w})]})]}):t.jsx("div",{className:"flex items-center justify-end gap-1 text-xs text-muted-foreground",children:t.jsx("span",{children:w})})]}),!u&&t.jsx("div",{className:"hidden h-8 w-8 flex-shrink-0 items-center justify-center rounded-full bg-blue-600 text-sm text-white sm:flex",children:"U"})]}):e.isTaskNotification?t.jsx("div",{className:"w-full",children:t.jsxs("div",{className:"flex items-center gap-2 py-0.5",children:[t.jsx("span",{className:`inline-block h-1.5 w-1.5 flex-shrink-0 rounded-full ${e.taskStatus==="completed"?"bg-green-400 dark:bg-green-500":"bg-amber-400 dark:bg-amber-500"}`}),t.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:e.content})]})}):t.jsxs("div",{className:"w-full",children:[!u&&t.jsxs("div",{className:"mb-2 flex items-center space-x-3",children:[e.type==="error"?t.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full bg-red-600 text-sm text-white",children:"!"}):e.type==="tool"?t.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full bg-gray-600 text-sm text-white dark:bg-gray-700",children:"🔧"}):t.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full p-1 text-sm text-foreground",children:t.jsx(tr,{provider:c,className:"h-full w-full"})}),t.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-white",children:e.type==="error"?d("messageTypes.error"):e.type==="tool"?d("messageTypes.tool"):c==="cursor"?d("messageTypes.cursor"):c==="codex"?d("messageTypes.codex"):c==="opencode"?d("messageTypes.opencode",{defaultValue:"OpenCode"}):d("messageTypes.claude")})]}),t.jsxs("div",{className:"w-full",children:[e.isToolUse?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex flex-col",children:t.jsx("div",{className:"flex flex-col",children:t.jsx(Tt,{className:"prose prose-sm max-w-none font-serif dark:prose-invert",children:String(e.displayText||"")})})}),e.toolInput&&t.jsx($r,{toolName:e.toolName||"UnknownTool",toolInput:e.toolInput,toolResult:e.toolResult,toolId:e.toolId,mode:"input",onFileOpen:a,createDiff:s,selectedProject:i,showRawParameters:n,rawToolInput:typeof e.toolInput=="string"?e.toolInput:void 0,isSubagentContainer:e.isSubagentContainer,subagentState:e.subagentState}),e.toolResult&&e.toolName!=="Bash"&&!Pl(e.toolName||"UnknownTool",e.toolResult)&&(e.toolResult.isError?t.jsx("div",{id:`tool-result-${e.toolId}`,className:"scroll-mt-4",children:t.jsx(Wl,{label:d("messageTypes.error"),content:String(e.toolResult.content||"")})}):t.jsx("div",{id:`tool-result-${e.toolId}`,className:"scroll-mt-4",children:t.jsx($r,{toolName:e.toolName||"UnknownTool",toolInput:e.toolInput,toolResult:e.toolResult,toolId:e.toolId,mode:"result",onFileOpen:a,createDiff:s,selectedProject:i})}))]}):e.isInteractivePrompt?t.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 dark:border-amber-800 dark:bg-amber-900/20",children:t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx("div",{className:"mt-0.5 flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full bg-amber-500",children:t.jsx("svg",{className:"h-5 w-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),t.jsxs("div",{className:"flex-1",children:[t.jsx("h4",{className:"mb-3 text-base font-semibold text-amber-900 dark:text-amber-100",children:d("interactive.title")}),(()=>{const f=(e.content||"").split(`
|
|
23
|
-
`).filter(h=>h.trim()),m=f.find(h=>h.includes("?"))||f[0]||"",p=[];return f.forEach(h=>{const y=h.match(/[❯\s]*(\d+)\.\s+(.+)/);if(y){const I=h.includes("❯");p.push({number:y[1],text:y[2].trim(),isSelected:I})}}),t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"mb-4 text-sm text-amber-800 dark:text-amber-200",children:m}),t.jsx("div",{className:"mb-4 space-y-2",children:p.map(h=>t.jsx("button",{className:`w-full rounded-lg border-2 px-4 py-3 text-left transition-all ${h.isSelected?"border-amber-600 bg-amber-600 text-white shadow-md dark:border-amber-700 dark:bg-amber-700":"border-amber-300 bg-white text-amber-900 dark:border-amber-700 dark:bg-gray-800 dark:text-amber-100"} cursor-not-allowed opacity-75`,disabled:!0,children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:`flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full text-sm font-bold ${h.isSelected?"bg-white/20":"bg-amber-100 dark:bg-amber-800/50"}`,children:h.number}),t.jsx("span",{className:"flex-1 text-sm font-medium sm:text-base",children:h.text}),h.isSelected&&t.jsx("span",{className:"text-lg",children:"❯"})]})},h.number))}),t.jsxs("div",{className:"rounded-lg bg-amber-100 p-3 dark:bg-amber-800/30",children:[t.jsx("p",{className:"mb-1 text-sm font-medium text-amber-900 dark:text-amber-100",children:d("interactive.waiting")}),t.jsx("p",{className:"text-xs text-amber-800 dark:text-amber-200",children:d("interactive.instruction")})]})]})})()]})]})}):e.isThinking?t.jsxs(Vr,{defaultOpen:!1,children:[t.jsx(Hr,{}),t.jsxs(zr,{children:[t.jsx(Tt,{className:"prose prose-sm prose-gray max-w-none font-serif dark:prose-invert",children:e.content}),t.jsx("div",{className:"mt-3 flex items-center text-[11px]",children:t.jsx(yr,{content:String(e.content||""),messageType:"assistant"})})]})]}):t.jsxs("div",{dir:"auto",className:"text-sm text-gray-700 dark:text-gray-300",children:[l&&e.reasoning&&t.jsxs(Vr,{className:"mb-3",defaultOpen:!1,children:[t.jsx(Hr,{}),t.jsx(zr,{children:t.jsx("div",{className:"whitespace-pre-wrap",children:e.reasoning})})]}),(()=>{const f=g,m=f.trim();if((m.startsWith("{")||m.startsWith("["))&&(m.endsWith("}")||m.endsWith("]")))try{const p=JSON.parse(m),h=JSON.stringify(p,null,2);return t.jsxs("div",{className:"my-2",children:[t.jsxs("div",{className:"mb-2 flex items-center gap-2 text-sm text-muted-foreground",children:[t.jsx("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"})}),t.jsx("span",{className:"font-medium",children:d("json.response")})]}),t.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-muted",children:t.jsx("pre",{className:"overflow-x-auto p-4",children:t.jsx("code",{className:"block whitespace-pre font-mono text-sm text-foreground",children:h})})})]})}catch{}return e.type==="assistant"?t.jsx(Tt,{className:"prose prose-sm prose-gray max-w-none font-serif dark:prose-invert",children:f}):t.jsx("div",{className:"whitespace-pre-wrap",children:f})})()]}),(E||!u)&&t.jsxs("div",{className:"mt-1 flex w-full items-center gap-2 text-[11px] text-gray-400 dark:text-gray-500",children:[E&&t.jsx(yr,{content:b,messageType:"assistant"}),E&&t.jsx(Ii,{content:b}),!u&&t.jsx("span",{children:w})]})]})]})})}),Li=[{value:"pending",label:"Pending"},{value:"in-progress",label:"In Progress"},{value:"review",label:"Review"},{value:"done",label:"Done"},{value:"deferred",label:"Deferred"},{value:"cancelled",label:"Cancelled"}];function Ri(e){return e==="done"?Hs:e==="in-progress"?Ra:e==="review"?Aa:e==="deferred"?Oa:e==="cancelled"?it:zs}function Ai(e){return e==="high"?"text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-950":e==="medium"?"text-yellow-600 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-950":e==="low"?"text-blue-600 dark:text-blue-400 bg-blue-50 dark:bg-blue-950":"text-gray-600 dark:text-gray-400 bg-gray-50 dark:bg-gray-800"}function Oi({task:e,isOpen:r=!0,className:s="",onClose:a,onEdit:n=null,onStatusChange:l=null,onTaskClick:i=null}){const{currentProject:c,refreshTasks:d}=Fs(),[u,x]=o.useState(!1),[v,g]=o.useState(!1),[b,N]=o.useState(!1),[k,E]=o.useState(!1),[w,L]=o.useState(e);o.useEffect(()=>{L(e),x(!1)},[e]);const f=o.useMemo(()=>Ri(e?.status),[e?.status]);if(!r||!e||!w)return null;const m=async()=>{if(!c?.name)return;const h={};if(w.title!==e.title&&(h.title=w.title),w.description!==e.description&&(h.description=w.description??""),w.details!==e.details&&(h.details=w.details??""),Object.keys(h).length===0){x(!1);return}g(!0);try{const y=await jr.taskmaster.updateTask(c.name,e.id,h);if(!y.ok){const I=await y.json();throw new Error(I.message??"Failed to update task")}x(!1),await d(),n?.(w)}catch(y){console.error("Failed to save task changes:",y),alert(y instanceof Error?y.message:"Failed to update task")}finally{g(!1)}},p=async h=>{if(!(!c?.name||h===e.status))try{const y=await jr.taskmaster.updateTask(c.name,e.id,{status:h});if(!y.ok){const I=await y.json();throw new Error(I.message??"Failed to update task status")}await d(),l?.(e.id,h)}catch(y){console.error("Failed to update task status:",y),alert(y instanceof Error?y.message:"Failed to update task status")}};return t.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/50 md:p-4",children:t.jsxs("div",{className:Ae("w-full md:max-w-4xl h-full md:h-[90vh] bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 md:rounded-lg shadow-xl flex flex-col",s),children:[t.jsxs("div",{className:"flex items-center justify-between border-b border-gray-200 p-4 dark:border-gray-700 md:p-6",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[t.jsx(f,{className:"h-6 w-6 text-blue-600 dark:text-blue-400"}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("button",{onClick:()=>Vt(String(e.id)),className:"mb-2 inline-flex items-center gap-1 rounded bg-gray-100 px-2 py-1 text-xs text-gray-600 hover:bg-gray-200 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700",title:"Copy task ID",children:[t.jsxs("span",{children:["Task ",e.id]}),t.jsx(Us,{className:"h-3 w-3"})]}),u?t.jsx("input",{type:"text",value:w.title,onChange:h=>L({...w,title:h.target.value}),className:"w-full border-b-2 border-blue-500 bg-transparent text-lg font-semibold text-gray-900 focus:outline-none dark:text-white"}):t.jsx("h1",{className:"line-clamp-2 text-lg font-semibold text-gray-900 dark:text-white md:text-xl",children:e.title})]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[u?t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:m,disabled:v,className:"rounded-md p-2 text-green-600 hover:bg-green-50 disabled:opacity-50 dark:hover:bg-green-950",title:"Save",children:t.jsx(Ia,{className:Ae("w-5 h-5",v&&"animate-spin")})}),t.jsx("button",{onClick:()=>{L(e),x(!1)},disabled:v,className:"rounded-md p-2 text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-800",title:"Cancel editing",children:t.jsx(it,{className:"h-5 w-5"})})]}):t.jsx("button",{onClick:()=>x(!0),className:"rounded-md p-2 text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-800",title:"Edit task",children:t.jsx($a,{className:"h-5 w-5"})}),t.jsx("button",{onClick:a,className:"rounded-md p-2 text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-800",title:"Close",children:t.jsx(it,{className:"h-5 w-5"})})]})]}),t.jsxs("div",{className:"flex-1 space-y-6 overflow-y-auto p-4 md:p-6",children:[t.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Status"}),t.jsx("select",{value:e.status??"pending",onChange:h=>{p(h.target.value)},className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-gray-900 dark:border-gray-600 dark:bg-gray-800 dark:text-white",children:Li.map(h=>t.jsx("option",{value:h.value,children:h.label},h.value))})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Priority"}),t.jsx("div",{className:Ae("px-3 py-2 rounded-md text-sm font-medium capitalize",Ai(e.priority)),children:e.priority??"Not set"})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Dependencies"}),Array.isArray(e.dependencies)&&e.dependencies.length>0?t.jsx("div",{className:"flex flex-wrap gap-1",children:e.dependencies.map(h=>t.jsxs("button",{onClick:()=>i?.({id:h}),className:"rounded bg-blue-100 px-2 py-1 text-sm text-blue-700 hover:bg-blue-200 dark:bg-blue-900 dark:text-blue-300 dark:hover:bg-blue-800",children:[t.jsx(La,{className:"mr-1 inline h-3 w-3"}),h]},String(h)))}):t.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:"No dependencies"})]})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Description"}),u?t.jsx("textarea",{rows:4,value:w.description??"",onChange:h=>L({...w,description:h.target.value}),className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 dark:border-gray-600 dark:bg-gray-800"}):t.jsx("p",{className:"whitespace-pre-wrap text-gray-700 dark:text-gray-300",children:e.description||"No description provided"})]}),e.details&&t.jsxs("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700",children:[t.jsxs("button",{onClick:()=>N(h=>!h),className:"flex w-full items-center justify-between p-4 text-left hover:bg-gray-50 dark:hover:bg-gray-800",children:[t.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Implementation Details"}),b?t.jsx(rr,{className:"h-4 w-4"}):t.jsx(It,{className:"h-4 w-4"})]}),b&&t.jsx("div",{className:"border-t border-gray-200 p-4 dark:border-gray-700",children:t.jsx("p",{className:"whitespace-pre-wrap text-gray-700 dark:text-gray-300",children:e.details})})]}),e.testStrategy&&t.jsxs("div",{className:"rounded-lg border border-gray-200 dark:border-gray-700",children:[t.jsxs("button",{onClick:()=>E(h=>!h),className:"flex w-full items-center justify-between p-4 text-left hover:bg-gray-50 dark:hover:bg-gray-800",children:[t.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Test Strategy"}),k?t.jsx(rr,{className:"h-4 w-4"}):t.jsx(It,{className:"h-4 w-4"})]}),k&&t.jsx("div",{className:"border-t border-gray-200 bg-blue-50 p-4 dark:border-gray-700 dark:bg-blue-950/30",children:t.jsx("p",{className:"whitespace-pre-wrap text-gray-700 dark:text-gray-300",children:e.testStrategy})})]})]})]})})}const Pi=o.lazy(()=>Ps(()=>import("./Shell-CUTO-THd.js").then(e=>e.a),__vite__mapDeps([7,2,1,3,4,5,6,8])));function _i({isOpen:e,project:r,onClose:s,onAfterClose:a=null}){const{t:n}=We("tasks"),[l,i]=o.useState(!1);if(!e||!r)return null;const c=()=>{s(),i(!1),window.setTimeout(()=>{a?.()},800)};return t.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/50 p-4 pt-16 backdrop-blur-sm",children:t.jsxs("div",{className:"flex h-[600px] w-full max-w-4xl flex-col rounded-lg border border-gray-200 bg-white shadow-xl dark:border-gray-700 dark:bg-gray-900",children:[t.jsxs("div",{className:"flex items-center justify-between border-b border-gray-200 p-4 dark:border-gray-700",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-blue-100 dark:bg-blue-900/50",children:t.jsx(Ar,{className:"h-4 w-4 text-blue-600 dark:text-blue-400"})}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:n("setupModal.title")}),t.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:n("setupModal.subtitle",{projectName:r.displayName})})]})]}),t.jsx("button",{onClick:c,className:"rounded-md p-2 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",title:"Close",children:t.jsx(Bt,{className:"h-5 w-5 rotate-45"})})]}),t.jsx("div",{className:"flex-1 p-4",children:t.jsx("div",{className:"h-full overflow-hidden rounded-lg bg-black",children:t.jsx(o.Suspense,{fallback:t.jsx("div",{className:"h-full bg-black",role:"status","aria-label":"Loading terminal"}),children:t.jsx(Pi,{selectedProject:r,selectedSession:null,initialCommand:"npx task-master init",isPlainShell:!0,isActive:!0,onProcessComplete:d=>{d===0&&i(!0)}})})})}),t.jsx("div",{className:"border-t border-gray-200 bg-gray-50 p-4 dark:border-gray-700 dark:bg-gray-800/50",children:t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:l?t.jsxs("span",{className:"flex items-center gap-2 text-green-600 dark:text-green-400",children:[t.jsx("span",{className:"h-2 w-2 rounded-full bg-green-500"}),n("setupModal.completed")]}):n("setupModal.willStart")}),t.jsx("button",{onClick:c,className:Ae("px-4 py-2 text-sm font-medium rounded-md transition-colors",l?"bg-green-600 hover:bg-green-700 text-white":"text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 hover:bg-gray-50 dark:hover:bg-gray-600"),children:n(l?"setupModal.closeContinueButton":"setupModal.closeButton")})]})})]})})}function Di({priority:e}){return e==="high"?t.jsx("div",{className:"flex h-4 w-4 items-center justify-center rounded bg-red-100 dark:bg-red-900/50",title:"High Priority",children:t.jsx(Ua,{className:"h-2.5 w-2.5 text-red-600 dark:text-red-400"})}):e==="medium"?t.jsx("div",{className:"flex h-4 w-4 items-center justify-center rounded bg-amber-100 dark:bg-amber-900/50",title:"Medium Priority",children:t.jsx(Ba,{className:"h-2.5 w-2.5 text-amber-600 dark:text-amber-400"})}):t.jsx("div",{className:"flex h-4 w-4 items-center justify-center rounded bg-gray-100 dark:bg-gray-800",title:"Low Priority",children:t.jsx(zs,{className:"h-2.5 w-2.5 text-gray-400 dark:text-gray-500"})})}function Ts({onShowAllTasks:e=null,onStartTask:r=null,className:s=""}){const{nextTask:a,tasks:n,currentProject:l,isLoadingTasks:i,projectTaskMaster:c,refreshTasks:d,refreshProjectTaskMaster:u}=Fs(),[x,v]=o.useState(!1),[g,b]=o.useState(!1),[N,k]=o.useState(!1);if(!l||i)return null;const E=Array.isArray(n)&&n.length>0,w=!!(c?.hasTaskmaster||l.taskmaster?.hasTaskmaster),L=()=>{u(),d()};if(!E&&!w)return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:Ae("bg-blue-50 dark:bg-blue-950 border border-blue-200 dark:border-blue-800 rounded-lg p-3 mb-4",s),children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx(Kr,{className:"h-4 w-4 text-blue-600 dark:text-blue-400"}),t.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-white",children:"TaskMaster AI is not configured"})]}),t.jsxs("button",{onClick:()=>b(!0),className:"flex items-center gap-1 rounded bg-blue-600 px-2 py-1 text-xs text-white transition-colors hover:bg-blue-700",children:[t.jsx(Ar,{className:"h-3 w-3"}),"Initialize"]})]}),t.jsxs("button",{onClick:()=>k(f=>!f),className:"mt-2 flex items-center gap-1 text-xs text-blue-700 hover:underline dark:text-blue-300",children:[t.jsx(Pa,{className:"h-3 w-3"}),N?"Hide details":"What is TaskMaster?"]}),N&&t.jsxs("div",{className:"mt-3 space-y-1 text-xs text-blue-900 dark:text-blue-100",children:[t.jsx("p",{children:"- AI-powered task management with dependencies and subtasks."}),t.jsx("p",{children:"- PRD-driven task generation for faster project bootstrapping."}),t.jsx("p",{children:"- Kanban and list views for day-to-day execution."})]})]}),t.jsx(_i,{isOpen:g,project:l,onClose:()=>b(!1),onAfterClose:L})]});if(a)return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:Ae("bg-slate-50 dark:bg-slate-900/30 border border-slate-200 dark:border-slate-700 rounded-lg p-3 mb-4",s),children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[t.jsx("div",{className:"flex h-5 w-5 items-center justify-center rounded-full bg-blue-100 dark:bg-blue-900/50",children:t.jsx(_a,{className:"h-3 w-3 text-blue-600 dark:text-blue-400"})}),t.jsxs("span",{className:"text-xs font-medium text-slate-600 dark:text-slate-400",children:["Task ",a.id]}),t.jsx(Di,{priority:a.priority})]}),t.jsx("p",{className:"line-clamp-1 text-sm font-medium text-slate-900 dark:text-slate-100",children:a.title})]}),t.jsxs("div",{className:"flex flex-shrink-0 items-center gap-1",children:[t.jsxs("button",{onClick:()=>r?.(),className:"flex items-center gap-1 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-blue-700",children:[t.jsx(Da,{className:"h-3 w-3"}),"Start Task"]}),t.jsx("button",{onClick:()=>v(!0),className:"rounded-md border border-slate-300 px-2 py-1.5 text-xs text-slate-600 hover:bg-slate-100 dark:border-slate-600 dark:text-slate-300 dark:hover:bg-slate-800",title:"View task details",children:t.jsx(Fa,{className:"h-3 w-3"})}),e&&t.jsx("button",{onClick:e,className:"rounded-md border border-slate-300 px-2 py-1.5 text-xs text-slate-600 hover:bg-slate-100 dark:border-slate-600 dark:text-slate-300 dark:hover:bg-slate-800",title:"View all tasks",children:t.jsx(Kr,{className:"h-3 w-3"})})]})]})}),t.jsx(Oi,{task:a,isOpen:x,onClose:()=>v(!1),onStatusChange:()=>{d()}})]});if(E){const f=n.filter(m=>m.status==="done").length;return t.jsx("div",{className:Ae("bg-purple-50 dark:bg-purple-950 border border-purple-200 dark:border-purple-800 rounded-lg p-3 mb-4",s),children:t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Hs,{className:"h-4 w-4 text-purple-600 dark:text-purple-400"}),t.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-white",children:f===n.length?"All tasks complete":"No pending tasks"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"text-xs text-gray-600 dark:text-gray-400",children:[f,"/",n.length]}),e&&t.jsx("button",{onClick:e,className:"rounded bg-purple-600 px-2 py-1 text-xs text-white transition-colors hover:bg-purple-700",children:"Review"})]})]})})}return null}const Es=[{id:"claude",label:"Claude"},{id:"codex",label:"Codex"},{id:"cursor",label:"Cursor"},{id:"opencode",label:"OpenCode"}];function Mn({initialProvider:e,providerModelCatalog:r,actions:s,onDone:a}){const[n,l]=o.useState(e),[i,c]=o.useState(null),[d,u]=o.useState(""),[x,v]=o.useState(""),[g,b]=o.useState(!1),[N,k]=o.useState(null),[E,w]=o.useState(null),[L,f]=o.useState(null),[m,p]=o.useState(null);o.useEffect(()=>{l(e)},[e]);const h=o.useMemo(()=>r[n]?.OPTIONS??[],[r,n]),y=o.useMemo(()=>h.filter(M=>M.isCustom),[h]),I=o.useMemo(()=>h.filter(M=>!M.isCustom),[h]),T=()=>{c(null),u(""),v(""),f(null)},j=M=>{l(M),w(null),p(null),T()},A=M=>{c(M),u(M.label),v(M.value),w(null),p(null),f(null)},_=async M=>{M.preventDefault();const O=d.trim(),$=x.trim();if(!O||!$){f("Enter both a model name and model ID.");return}if(/\s/.test($)){f("Model IDs cannot contain spaces.");return}b(!0),f(null),p(null);try{i?(await s.update(n,i,{model:O,id:$}),p(`${O} was updated.`)):(await s.create(n,{model:O,id:$}),p(`${O} was added.`)),T()}catch(P){f(P instanceof Error?P.message:"Unable to save this model.")}finally{b(!1)}},H=async M=>{if(M.recordId){k(M.recordId),f(null),p(null);try{await s.remove(n,M),i?.recordId===M.recordId&&T(),w(null),p(`${M.label} was deleted.`)}catch(O){f(O instanceof Error?O.message:"Unable to delete this model.")}finally{k(null)}}};return t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-4",children:[t.jsxs("div",{className:"flex shrink-0 flex-col gap-3 border-b border-border/70 pb-4 sm:flex-row sm:items-start sm:justify-between",children:[t.jsx("div",{className:"min-w-0",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"grid h-9 w-9 shrink-0 place-items-center rounded-xl border border-primary/25 bg-primary/10 text-primary",children:t.jsx(Bt,{className:"h-4 w-4"})}),t.jsxs("div",{children:[t.jsx("p",{className:"text-base font-semibold tracking-tight text-foreground",children:"Model library"}),t.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:"Add model IDs supported by your provider. Built-in models stay locked."})]})]})}),a&&t.jsxs(Qe,{type:"button",variant:"outline",size:"sm",onClick:a,className:"shrink-0 rounded-xl",children:[t.jsx(qa,{className:"h-3.5 w-3.5"}),"Back to models"]})]}),t.jsx("div",{className:"scrollbar-thin flex shrink-0 gap-1 overflow-x-auto rounded-xl border border-border/70 bg-muted/25 p-1",children:Es.map(M=>{const O=M.id===n;return t.jsxs("button",{type:"button",onClick:()=>j(M.id),"aria-pressed":O,className:`flex min-w-fit flex-1 items-center justify-center gap-2 rounded-lg px-3 py-2 text-xs font-semibold transition-all ${O?"bg-background text-foreground shadow-sm ring-1 ring-border/70":"text-muted-foreground hover:bg-background/60 hover:text-foreground"}`,children:[t.jsx(tr,{provider:M.id,className:"h-4 w-4"}),M.label]},M.id)})}),t.jsxs("div",{className:"scrollbar-thin grid min-h-0 flex-1 items-start gap-4 overflow-y-auto pr-1 lg:grid-cols-[minmax(16rem,0.8fr)_minmax(20rem,1.2fr)]",children:[t.jsxs("form",{onSubmit:_,className:"h-fit rounded-2xl border border-border/70 bg-muted/20 p-4 shadow-sm",children:[t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-semibold text-foreground",children:i?"Edit custom model":"Add a custom model"}),t.jsxs("p",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:["The ID is sent to ",Es.find(M=>M.id===n)?.label," exactly as written."]})]}),i&&t.jsx(Qe,{type:"button",variant:"ghost",size:"icon",onClick:T,className:"h-8 w-8 rounded-lg","aria-label":"Cancel editing",children:t.jsx(it,{className:"h-4 w-4"})})]}),t.jsx("label",{className:"mt-4 block text-xs font-semibold text-foreground",htmlFor:"custom-model-name",children:"Model name"}),t.jsx(Cr,{id:"custom-model-name",value:d,onChange:M=>u(M.target.value),maxLength:80,placeholder:"e.g. GPT-5.5 Pro",autoComplete:"off",className:"mt-1.5 h-10 rounded-xl bg-background"}),t.jsx("label",{className:"mt-4 block text-xs font-semibold text-foreground",htmlFor:"custom-model-id",children:"Model ID"}),t.jsx(Cr,{id:"custom-model-id",value:x,onChange:M=>v(M.target.value),maxLength:200,placeholder:"e.g. gpt-5.5-pro",autoComplete:"off",spellCheck:!1,className:"mt-1.5 h-10 rounded-xl bg-background font-mono"}),t.jsx("p",{className:"mt-1.5 text-[11px] leading-4 text-muted-foreground",children:"Use the exact identifier accepted by the provider CLI. IDs cannot contain spaces."}),L&&t.jsx("div",{role:"alert",className:"mt-3 rounded-xl border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:L}),m&&!L&&t.jsxs("div",{className:"mt-3 flex items-center gap-2 rounded-xl border border-emerald-500/25 bg-emerald-500/10 px-3 py-2 text-xs text-emerald-700 dark:text-emerald-300",children:[t.jsx(Ut,{className:"h-3.5 w-3.5"}),m]}),t.jsxs(Qe,{type:"submit",disabled:g,className:"mt-4 w-full rounded-xl",children:[g?t.jsx($t,{className:"h-4 w-4 animate-spin"}):i?t.jsx(Ut,{className:"h-4 w-4"}):t.jsx(Bt,{className:"h-4 w-4"}),g?"Saving…":i?"Save changes":"Add model"]})]}),t.jsxs("div",{className:"min-h-0 space-y-4",children:[t.jsxs("section",{children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3 px-1",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.14em] text-foreground",children:"Your models"}),t.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"Editable and stored in auth.db"})]}),t.jsx(jt,{variant:"secondary",className:"rounded-full text-[10px]",children:y.length})]}),y.length===0?t.jsxs("div",{className:"rounded-2xl border border-dashed border-border bg-background/60 px-4 py-7 text-center",children:[t.jsx("p",{className:"text-sm font-medium text-foreground",children:"No custom models yet"}),t.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Add one with the form and it will appear in every model picker."})]}):t.jsx("div",{className:"space-y-2",children:y.map(M=>{const O=E===M.recordId,$=N===M.recordId;return t.jsxs("div",{className:"rounded-2xl border border-primary/20 bg-primary/[0.04] p-3",children:[t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("p",{className:"truncate text-sm font-semibold text-foreground",children:M.label}),t.jsx(jt,{className:"rounded-full px-2 py-0 text-[9px]",children:"Custom"})]}),t.jsx("p",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground",children:M.value})]}),!O&&t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsx(Qe,{type:"button",variant:"ghost",size:"icon",onClick:()=>A(M),className:"h-8 w-8 rounded-lg","aria-label":`Edit ${M.label}`,children:t.jsx(Ws,{className:"h-3.5 w-3.5"})}),t.jsx(Qe,{type:"button",variant:"ghost",size:"icon",onClick:()=>w(M.recordId??null),className:"h-8 w-8 rounded-lg text-muted-foreground hover:bg-destructive/10 hover:text-destructive","aria-label":`Delete ${M.label}`,children:t.jsx(Va,{className:"h-3.5 w-3.5"})})]})]}),O&&t.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-2 border-t border-border/60 pt-3",children:[t.jsx("p",{className:"text-xs text-muted-foreground",children:"Delete this model from all pickers?"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Qe,{type:"button",variant:"ghost",size:"sm",onClick:()=>w(null),className:"h-8 rounded-lg",children:"Cancel"}),t.jsxs(Qe,{type:"button",variant:"destructive",size:"sm",disabled:$,onClick:()=>{H(M)},className:"h-8 rounded-lg",children:[$&&t.jsx($t,{className:"h-3.5 w-3.5 animate-spin"}),"Delete"]})]})]})]},M.recordId??M.value)})})]}),t.jsxs("section",{children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3 px-1",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.14em] text-foreground",children:"Built-in models"}),t.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"Maintained by WindCli and read-only"})]}),t.jsx(jt,{variant:"secondary",className:"rounded-full text-[10px]",children:I.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-background/70",children:I.map(M=>t.jsxs("div",{className:"flex items-center gap-3 border-b border-border/60 px-3 py-2.5 last:border-b-0",children:[t.jsx(Ha,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/70"}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"truncate text-xs font-medium text-foreground",children:M.label}),t.jsx("p",{className:"truncate font-mono text-[10px] text-muted-foreground",children:M.value})]})]},M.recordId??M.value))})]})]})]})]})}const Fi=[{id:"claude",name:"Anthropic"},{id:"codex",name:"OpenAI"},{id:"cursor",name:"Cursor"},{id:"opencode",name:"OpenCode"}],Ui=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl";function Bi(e,r){const s=e.toLowerCase();return r.toLowerCase().split(/\s+/).filter(Boolean).every(n=>s.includes(n))?1:0}function qi(e,r){return r[e]??{OPTIONS:[],DEFAULT:""}}function Vi(e,r,s,a,n){return e==="claude"?r:e==="codex"?a:e==="opencode"?n:s}function Hi(e){return e==="claude"?"Claude":e==="cursor"?"Cursor":e==="codex"?"Codex":e==="opencode"?"OpenCode":"Claude"}function zi({selectedSession:e,currentSessionId:r,provider:s,setProvider:a,textareaRef:n,claudeModel:l,setClaudeModel:i,cursorModel:c,setCursorModel:d,codexModel:u,setCodexModel:x,opencodeModel:v,setOpenCodeModel:g,providerModelCatalog:b,providerModelActions:N,providerModelsLoading:k,tasksEnabled:E,isTaskMasterInstalled:w,onShowAllTasks:L,setInput:f}){const{t:m}=We("chat"),[p,h]=o.useState(!1),[y,I]=o.useState(!1),T=o.useMemo(()=>Fi.map(P=>({id:P.id,name:P.name,models:b[P.id]?.OPTIONS??[]})),[b]),j=m("tasks.nextTaskPrompt",{defaultValue:"Start the next task"}),A=Vi(s,l,c,u,v),_=o.useMemo(()=>qi(s,b).OPTIONS.find(z=>z.value===A)?.label||A,[s,A,b]),H=o.useCallback((P,B)=>{P==="claude"?(i(B),localStorage.setItem("claude-model",B)):P==="codex"?(x(B),localStorage.setItem("codex-model",B)):P==="opencode"?(g(B),localStorage.setItem("opencode-model",B)):(d(B),localStorage.setItem("cursor-model",B))},[i,d,x,g]),M=o.useCallback((P,B)=>{a(P),localStorage.setItem("selected-provider",P),H(P,B),h(!1),setTimeout(()=>n.current?.focus(),100)},[a,H,n]),O=()=>{h(!1),I(!0)},$=()=>{I(!1),h(!0)};return!e&&!r?t.jsx("div",{className:"flex h-full items-center justify-center px-4",children:t.jsxs("div",{className:"w-full max-w-[34.25rem]",children:[t.jsxs("div",{className:"mb-8 text-center",children:[t.jsx("h2",{className:"text-lg font-semibold tracking-tight text-foreground sm:text-xl",children:m("providerSelection.title")}),t.jsx("p",{className:"mt-1 text-[13px] text-muted-foreground",children:m("providerSelection.description")})]}),t.jsxs(Sr,{open:p,onOpenChange:h,children:[t.jsx(oa,{asChild:!0,children:t.jsx(_s,{className:"group mx-auto max-w-xs cursor-pointer border-border/60 transition-all duration-150 hover:border-border hover:shadow-md active:scale-[0.99]",role:"button",tabIndex:0,children:t.jsxs("div",{className:"flex items-center gap-2 p-3",children:[t.jsx(tr,{provider:s,className:"h-5 w-5 shrink-0"}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("span",{className:"text-xs font-semibold text-foreground",children:Hi(s)}),t.jsx("span",{className:"text-xs text-muted-foreground",children:"·"}),t.jsx("span",{className:"truncate text-xs text-foreground",children:_})]}),t.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:m("providerSelection.clickToChange",{defaultValue:"Click to change model"})})]}),t.jsx(rr,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform group-hover:translate-y-0.5"})]})})}),t.jsxs(Mr,{className:"max-w-md overflow-hidden p-0",children:[t.jsx(Tr,{children:"Model Selector"}),t.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border/60 bg-muted/20 px-4 py-3",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-semibold text-foreground",children:m("providerSelection.chooseModel",{defaultValue:"Choose a model"})}),t.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:m("providerSelection.chooseModelDescription",{defaultValue:"Built-in and custom models in one list"})})]}),t.jsxs(Qe,{type:"button",variant:"ghost",size:"sm",onClick:O,className:"h-8 shrink-0 rounded-lg px-2.5 text-xs",children:[t.jsx(Bt,{className:"h-3.5 w-3.5"}),m("providerSelection.addModel",{defaultValue:"Add model"})]})]}),t.jsxs(la,{filter:Bi,children:[t.jsx(ia,{placeholder:m("providerSelection.searchModels",{defaultValue:"Search models..."})}),t.jsxs(ca,{className:"max-h-[350px]",children:[t.jsx(da,{children:m("providerSelection.noModelsFound",{defaultValue:"No models found."})}),T.map((P,B)=>t.jsxs(ua,{className:B>0?"border-t border-border/40 [&_[cmdk-group-heading]]:mt-1 [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wider":"[&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wider",heading:t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx(tr,{provider:P.id,className:"h-3.5 w-3.5 shrink-0"}),P.name]}),children:[P.models.length===0&&k?t.jsx(Wr,{disabled:!0,className:"ml-4 border-l border-border/40 pl-4 text-muted-foreground",children:m("providerSelection.loadingModels",{defaultValue:"Loading models…"})}):null,P.models.map(z=>{const U=s===P.id&&A===z.value;return t.jsxs(Wr,{value:`${P.name} ${z.label} ${z.description||""}`,onSelect:()=>M(P.id,z.value),className:"ml-4 border-l border-border/40 pl-4",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[t.jsx("span",{className:"truncate",children:z.label}),z.isCustom&&t.jsx(jt,{className:"h-4 shrink-0 rounded-full px-1.5 text-[8px]",children:"Custom"})]}),z.label!==z.value&&t.jsx("div",{className:"truncate font-mono text-[10px] text-muted-foreground",children:z.value})]}),U&&t.jsx(Ut,{className:"ml-auto h-4 w-4 shrink-0 text-primary"})]},`${P.id}-${z.value}`)})]},P.id))]})]})]})]}),t.jsx(Sr,{open:y,onOpenChange:P=>{P?I(!0):$()},children:t.jsxs(Mr,{className:"flex h-[min(90dvh,46rem)] w-[calc(100vw-1rem)] max-w-4xl flex-col overflow-hidden rounded-3xl p-4 sm:p-5",children:[t.jsx(Tr,{children:m("providerSelection.manageModels",{defaultValue:"Manage models"})}),t.jsx(Mn,{initialProvider:s,providerModelCatalog:b,actions:N,onDone:$})]})}),t.jsx("p",{className:"mt-4 text-center text-sm text-muted-foreground/70",children:{claude:m("providerSelection.readyPrompt.claude",{model:l}),cursor:m("providerSelection.readyPrompt.cursor",{model:c}),codex:m("providerSelection.readyPrompt.codex",{model:u}),opencode:m("providerSelection.readyPrompt.opencode",{model:v,defaultValue:"Ready with OpenCode {{model}}"})}[s]}),t.jsx("p",{className:"mt-3 flex items-center justify-center gap-1.5 text-center text-xs text-muted-foreground/60",children:t.jsx(_o,{ns:"chat",i18nKey:"providerSelection.pressToSearch",values:{shortcut:Ui==="⌘"?"⌘K":"Ctrl+K"},components:{kbd:t.jsx("kbd",{className:"inline-flex items-center gap-0.5 rounded border border-border/60 bg-muted/40 px-1.5 py-0.5 font-mono text-[10px]"})}})}),s&&E&&w&&t.jsx("div",{className:"mt-5",children:t.jsx(Ts,{onStartTask:()=>f(j),onShowAllTasks:L})})]})}):e?t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"max-w-[34.25rem] px-6 text-center",children:[t.jsx("p",{className:"mb-1.5 text-lg font-semibold text-foreground",children:m("session.continue.title")}),t.jsx("p",{className:"text-sm leading-relaxed text-muted-foreground",children:m("session.continue.description")}),E&&w&&t.jsx("div",{className:"mt-5",children:t.jsx(Ts,{onStartTask:()=>f(j),onShowAllTasks:L})})]})}):null}function Wi(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function Ki(e){const r=ir(e.toolName||"UnknownTool").input,s=Wi(e.toolInput),a=typeof r.title=="function"?r.title(s):r.title,n=r.getValue?.(s);return String(n||a||e.displayText||e.content||"").trim()}function Gi(e,r){return e==="terminal"?"$":e||r.slice(0,1).toUpperCase()}function Ji({group:e,prevMessage:r,createDiff:s,getMessageKey:a,onFileOpen:n,onShowSettings:l,onGrantToolPermission:i,showRawParameters:c,showThinking:d,selectedProject:u,provider:x}){const[v,g]=o.useState(!1),b=ir(e.toolName).input,N=b.label||e.toolName,k=b.colorScheme?.border||"border-border",E=b.colorScheme?.icon||"text-muted-foreground",w=Gi(b.icon,e.toolName),L=o.useMemo(()=>{const f=e.messages.slice(0,2).map(Ki).filter(Boolean),m=e.messages.length-f.length,p=f.join(", ");return p?m>0?`${p}, +${m} more`:p:m>0?`+${m} more`:""},[e.messages]);return t.jsxs("div",{className:"chat-message tool px-3 sm:px-0","data-message-timestamp":e.timestamp||void 0,children:[t.jsxs("button",{type:"button",className:`group flex w-full items-center gap-2 border-l-2 ${k} rounded-r-md bg-muted/25 px-3 py-2 text-left transition-colors hover:bg-muted/40 dark:bg-muted/10 dark:hover:bg-muted/20`,onClick:()=>g(f=>!f),"aria-expanded":v,children:[t.jsx(It,{className:`h-3.5 w-3.5 flex-shrink-0 text-muted-foreground transition-transform ${v?"rotate-90":""}`,"aria-hidden":!0}),t.jsx("span",{className:`${E} flex h-5 w-5 flex-shrink-0 items-center justify-center rounded bg-background/80 text-xs font-medium`,children:w}),t.jsx("span",{className:"min-w-0 flex-shrink-0 text-xs font-medium text-foreground",children:N}),t.jsxs("span",{className:"flex-shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground",children:["x",e.messages.length]}),L&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-[10px] text-muted-foreground/40",children:"/"}),t.jsx("span",{className:"min-w-0 truncate font-mono text-xs text-muted-foreground",children:L})]})]}),v&&t.jsx("div",{className:"mt-2 space-y-3 sm:space-y-4",children:e.messages.map((f,m)=>t.jsx(Sn,{message:f,prevMessage:m>0?e.messages[m-1]:r,createDiff:s,onFileOpen:n,onShowSettings:l,onGrantToolPermission:i,showRawParameters:c,showThinking:d,selectedProject:u,provider:x},a(f)))})]})}const Qi=`
|
|
24
|
-
@keyframes loadAllOverlayAutoFade {
|
|
25
|
-
0%, 80% { opacity: 1; }
|
|
26
|
-
100% { opacity: 0; }
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@media (prefers-reduced-motion: reduce) {
|
|
30
|
-
.load-all-overlay-auto-fade {
|
|
31
|
-
animation: none !important;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
`;function Yi({showLoadAllOverlay:e,isLoadingAllMessages:r,loadAllJustFinished:s,totalMessages:a,onLoadAllMessages:n}){const{t:l}=We("chat");return!e&&!r&&!s?null:t.jsxs("div",{className:`pointer-events-none sticky top-2 z-20 flex justify-center ${r?"":"load-all-overlay-auto-fade"}`,style:r?void 0:{animation:"loadAllOverlayAutoFade 2500ms ease forwards"},children:[t.jsx("style",{children:Qi}),s?t.jsxs("div",{className:"flex items-center space-x-2 rounded-full bg-green-600 px-4 py-1.5 text-xs font-medium text-white shadow-lg dark:bg-green-500",children:[t.jsx("svg",{className:"h-3 w-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M5 13l4 4L19 7"})}),t.jsx("span",{children:l("session.messages.allLoaded")})]}):t.jsxs("button",{className:"pointer-events-auto flex items-center space-x-2 rounded-full bg-blue-600 px-4 py-1.5 text-xs font-medium text-white shadow-lg transition-all duration-200 hover:scale-105 hover:bg-blue-700 disabled:cursor-wait disabled:opacity-75 dark:bg-blue-500 dark:hover:bg-blue-600",onClick:n,disabled:r,children:[r&&t.jsx("div",{className:"h-3 w-3 animate-spin rounded-full border-2 border-white/30 border-t-white"}),t.jsx("span",{children:r?l("session.messages.loadingAll"):t.jsxs(t.Fragment,{children:[l("session.messages.loadAll")," ",a>0&&`(${a})`]})})]})]})}function ar(e){const r=typeof e=="string"||typeof e=="number"?new Date(e):e;return new Intl.DateTimeFormat("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(r)}function kr(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Xi(e,r,s={}){const a=s.includeMeta??!0;let n="";a&&(n+=`# ${r||"Chat Export"}
|
|
35
|
-
|
|
36
|
-
`,n+=`**Exported:** ${ar(new Date)}
|
|
37
|
-
|
|
38
|
-
`,n+=`---
|
|
39
|
-
|
|
40
|
-
`);for(const l of e){if(l.type==="user")n+=`## You
|
|
41
|
-
|
|
42
|
-
`;else if(l.type==="assistant")n+=`## Claude
|
|
43
|
-
|
|
44
|
-
`;else if(l.type==="error")n+=`## ⚠️ Error
|
|
45
|
-
|
|
46
|
-
`;else if(l.type==="tool")n+=`## 🔧 Tool
|
|
47
|
-
|
|
48
|
-
`;else continue;const i=typeof l.content=="string"?l.content:String(l.content??"");n+=`${i}
|
|
49
|
-
|
|
50
|
-
`,a&&l.timestamp&&(n+=`<small>${ar(l.timestamp)}</small>
|
|
51
|
-
|
|
52
|
-
`),n+=`---
|
|
53
|
-
|
|
54
|
-
`}return n}function Zi(e,r="chat-export.md",s){const a=Xi(e,s),n=new Blob([a],{type:"text/markdown"});En(n,r)}function Tn(e,r,s={}){const a=s.includeMeta??!0,n=e.map(l=>{const i=l.type==="user"?"👤 You":l.type==="assistant"?"🤖 Claude":`${l.type}`,c=a&&l.timestamp?`<p style="font-size: 12px; color: #999; margin-top: 8px;">${ar(l.timestamp)}</p>`:"",d=typeof l.content=="string"?l.content:String(l.content??""),u=kr(d);return`
|
|
55
|
-
<div style="margin-bottom: 24px; padding: 16px; border-radius: 8px; background-color: ${l.type==="user"?"#e3f2fd":"#f5f5f5"};">
|
|
56
|
-
<h3 style="margin: 0 0 12px 0; font-size: 14px; font-weight: 600; color: #333;">${i}</h3>
|
|
57
|
-
<p style="margin: 0; white-space: pre-wrap; word-wrap: break-word; color: #555; font-size: 14px; line-height: 1.6;">${u}</p>
|
|
58
|
-
${c}
|
|
59
|
-
</div>
|
|
60
|
-
`}).join("");return`
|
|
61
|
-
<!DOCTYPE html>
|
|
62
|
-
<html>
|
|
63
|
-
<head>
|
|
64
|
-
<meta charset="UTF-8">
|
|
65
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
66
|
-
<title>${kr(r||"Chat Export")}</title>
|
|
67
|
-
<style>
|
|
68
|
-
body {
|
|
69
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
70
|
-
max-width: 800px;
|
|
71
|
-
margin: 0 auto;
|
|
72
|
-
padding: 24px;
|
|
73
|
-
background-color: #fafafa;
|
|
74
|
-
color: #333;
|
|
75
|
-
}
|
|
76
|
-
h1 { margin: 0 0 8px 0; }
|
|
77
|
-
.meta { color: #999; font-size: 13px; margin-bottom: 24px; }
|
|
78
|
-
.divider { border-top: 1px solid #ddd; margin: 24px 0; }
|
|
79
|
-
</style>
|
|
80
|
-
</head>
|
|
81
|
-
<body>
|
|
82
|
-
<h1>${kr(r||"Chat Export")}</h1>
|
|
83
|
-
<div class="meta">Exported on ${ar(new Date)}</div>
|
|
84
|
-
<div class="divider"></div>
|
|
85
|
-
${n}
|
|
86
|
-
</body>
|
|
87
|
-
</html>
|
|
88
|
-
`}function ec(e,r="chat-export.html",s){const a=Tn(e,s),n=new Blob([a],{type:"text/html;charset=utf-8"});En(n,r)}function tc(e,r="chat-export",s){const a=Tn(e,s),n=window.open("","","width=800,height=600");if(!n){window.alert("PDF export could not start because the browser blocked the popup. Allow popups and try again.");return}n.document.write(a),n.document.close(),setTimeout(()=>{n.print()},250)}function En(e,r){const s=URL.createObjectURL(e),a=document.createElement("a");a.href=s,a.download=r,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(s)}const rc=[{id:"markdown",label:"Markdown (.md)",ext:".md"},{id:"html",label:"Web Page (.html)",ext:".html"},{id:"pdf",label:"PDF (Print to File)",ext:".pdf"}];function sc({messages:e,sessionTitle:r}){const[s,a]=o.useState(!1);if(e.length===0)return null;const n=l=>{const i=new Date().toISOString().split("T")[0],c=`${r||"chat"}-${i}`;switch(l){case"markdown":Zi(e,`${c}.md`,r);break;case"html":ec(e,`${c}.html`,r);break;case"pdf":tc(e,c,r);break}a(!1)};return t.jsxs("div",{className:"relative",children:[t.jsx("button",{type:"button",onClick:()=>a(l=>!l),"aria-label":"Export chat",title:"Export chat",className:"flex h-8 w-8 items-center justify-center rounded-lg border border-border/50 text-muted-foreground transition-all hover:bg-accent hover:text-foreground",children:t.jsx(Bs,{className:"h-4 w-4"})}),s&&t.jsx("div",{className:"absolute right-0 top-full z-50 mt-2 w-48 rounded-lg border border-border/50 bg-card shadow-lg",children:t.jsxs("div",{className:"p-2",children:[t.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground",children:"Export as:"}),rc.map(l=>t.jsxs("button",{type:"button",onClick:()=>n(l.id),className:"flex w-full items-center gap-2 rounded-md px-3 py-2 text-sm text-foreground transition-colors hover:bg-muted",children:[l.id==="markdown"?t.jsx(Rr,{className:"h-4 w-4"}):t.jsx(za,{className:"h-4 w-4"}),t.jsx("span",{children:l.label})]},l.id))]})}),s&&t.jsx("div",{className:"fixed inset-0",onClick:()=>a(!1)})]})}function nc({scrollContainerRef:e,onWheel:r,onTouchMove:s,isLoadingSessionMessages:a,isProcessing:n=!1,hasActivityIndicator:l=!1,chatMessages:i,selectedSession:c,currentSessionId:d,provider:u,setProvider:x,textareaRef:v,claudeModel:g,setClaudeModel:b,cursorModel:N,setCursorModel:k,codexModel:E,setCodexModel:w,opencodeModel:L,setOpenCodeModel:f,providerModelCatalog:m,providerModelActions:p,providerModelsLoading:h,tasksEnabled:y,isTaskMasterInstalled:I,onShowAllTasks:T,setInput:j,isLoadingMoreMessages:A,hasMoreMessages:_,totalMessages:H,sessionMessagesCount:M,visibleMessageCount:O,visibleMessages:$,loadEarlierMessages:P,loadAllMessages:B,allMessagesLoaded:z,isLoadingAllMessages:U,loadAllJustFinished:ee,showLoadAllOverlay:ie,createDiff:X,onFileOpen:pe,onShowSettings:me,onGrantToolPermission:he,showRawParameters:Y,showThinking:le,selectedProject:ae}){const{t:K}=We("chat"),ce=o.useMemo(()=>Ol($,!!le),[$,le]),ge=o.useMemo(()=>{const be=new WeakMap,oe=new Map,ne=ve=>{const Ne=bs(ve)??"message-generated",Pe=oe.get(Ne)??0;oe.set(Ne,Pe+1),be.set(ve,Pe===0?Ne:`${Ne}__${Pe}`)};for(const ve of ce)ys(ve)?ve.messages.forEach(ne):ne(ve);return be},[ce]),fe=o.useCallback(be=>ge.get(be)??bs(be)??"message-generated",[ge]);return t.jsxs("div",{ref:e,onWheel:r,onTouchMove:s,className:`chat-messages-pane relative min-h-0 flex-1 overflow-y-auto overflow-x-hidden pt-3 sm:pt-4 ${l?"pb-12 sm:pb-14":"pb-3 sm:pb-4"}`,children:[i.length>0&&t.jsx("div",{className:"pointer-events-none sticky right-4 top-3 z-10 mb-2 flex justify-end sm:px-4",children:t.jsx("div",{className:"pointer-events-auto",children:t.jsx(sc,{messages:i,sessionTitle:c?.title})})}),t.jsx("div",{className:"mx-auto w-full max-w-[54.25rem] space-y-3 px-4 sm:space-y-4",children:(a||n)&&i.length===0?t.jsx("div",{className:"mt-8 text-center text-gray-500 dark:text-gray-400",children:t.jsxs("div",{className:"flex items-center justify-center space-x-2",children:[t.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-b-2 border-gray-400"}),t.jsx("p",{children:K("session.loading.sessionMessages")})]})}):i.length===0?t.jsx(zi,{selectedSession:c,currentSessionId:d,provider:u,setProvider:x,textareaRef:v,claudeModel:g,setClaudeModel:b,cursorModel:N,setCursorModel:k,codexModel:E,setCodexModel:w,opencodeModel:L,setOpenCodeModel:f,providerModelCatalog:m,providerModelActions:p,providerModelsLoading:h,tasksEnabled:y,isTaskMasterInstalled:I,onShowAllTasks:T,setInput:j}):t.jsxs(t.Fragment,{children:[A&&!U&&!z&&t.jsx("div",{className:"py-3 text-center text-gray-500 dark:text-gray-400",children:t.jsxs("div",{className:"flex items-center justify-center space-x-2",children:[t.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-b-2 border-gray-400"}),t.jsx("p",{className:"text-sm",children:K("session.loading.olderMessages")})]})}),_&&!A&&!z&&t.jsx("div",{className:"border-b border-gray-200 py-2 text-center text-sm text-gray-500 dark:border-gray-700 dark:text-gray-400",children:H>0&&t.jsxs("span",{children:[K("session.messages.showingOf",{shown:M,total:H})," ",t.jsx("span",{className:"text-xs",children:K("session.messages.scrollToLoad")})]})}),t.jsx(Yi,{showLoadAllOverlay:ie,isLoadingAllMessages:U,loadAllJustFinished:ee,totalMessages:H,onLoadAllMessages:B}),!_&&i.length>O&&t.jsxs("div",{className:"border-b border-gray-200 py-2 text-center text-sm text-gray-500 dark:border-gray-700 dark:text-gray-400",children:[K("session.messages.showingLast",{count:O,total:i.length})," |",t.jsx("button",{className:"ml-1 text-blue-600 underline hover:text-blue-700",onClick:P,children:K("session.messages.loadEarlier")})," | ",t.jsx("button",{className:"text-blue-600 underline hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300",onClick:B,children:K("session.messages.loadAll")})]}),(()=>{let be=null;return ce.map(oe=>{if(ys(oe)){const ve=be;return be=oe.messages[oe.messages.length-1]||be,t.jsx(Ji,{group:oe,prevMessage:ve,createDiff:X,getMessageKey:fe,onFileOpen:pe,onShowSettings:me,onGrantToolPermission:he,showRawParameters:Y,showThinking:le,selectedProject:ae,provider:u},`tool-group-${fe(oe.messages[0])}`)}const ne=be;return be=oe,t.jsx(Sn,{message:oe,prevMessage:ne,createDiff:X,onFileOpen:pe,onShowSettings:me,onGrantToolPermission:he,showRawParameters:Y,showThinking:le,selectedProject:ae,provider:u},fe(oe))})})()]})})]})}const ac=o.memo(nc),oc=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus","audio/ogg"];function lc(){for(const e of oc)try{if(typeof MediaRecorder<"u"&&MediaRecorder.isTypeSupported(e))return e}catch{}return""}function ic(e,r){const[s,a]=o.useState("idle"),n=o.useRef(null),l=o.useRef([]),i=o.useRef(null),c=o.useRef(!1),d=o.useRef(!1),u=o.useRef(!1),x=()=>{i.current?.getTracks().forEach(N=>N.stop()),i.current=null};o.useEffect(()=>(c.current=!1,()=>{c.current=!0,d.current=!1,i.current?.getTracks().forEach(N=>N.stop()),i.current=null,n.current=null}),[]);const v=o.useCallback(async()=>{if(!(d.current||n.current&&n.current.state!=="inactive")){d.current=!0;try{const N=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0}});if(c.current){N.getTracks().forEach(w=>w.stop());return}i.current=N;const k=lc(),E=k?new MediaRecorder(N,{mimeType:k}):new MediaRecorder(N);n.current=E,l.current=[],E.ondataavailable=w=>{w.data.size>0&&l.current.push(w.data)},E.onstop=async()=>{if(x(),c.current)return;const w=u.current;u.current=!1;const L=E.mimeType||"audio/webm",f=new Blob(l.current,{type:L});if(f.size<800){a("idle"),r?.("Recording too short");return}a("transcribing");try{const m=L.includes("mp4")?"m4a":L.includes("ogg")?"ogg":"webm",p=await wi(f,`recording.${m}`);if(!p.ok)throw new Error(`transcribe ${p.status}`);const h=await p.json();if(c.current)return;const y=String(h?.text||"").trim();y?e(y,w):r?.("No speech detected")}catch(m){c.current||r?.(`Transcription failed: ${m instanceof Error?m.message:String(m)}`)}finally{c.current||a("idle")}},E.start(),a("recording")}catch(N){if(n.current=null,x(),c.current)return;const k=N;let E=`Mic error: ${k?.message||N}`;k?.name==="NotAllowedError"?E="Microphone access denied.":k?.name==="NotFoundError"&&(E="No microphone found."),r?.(E),a("idle")}finally{d.current=!1}}},[e,r]),g=o.useCallback(N=>{const k=n.current;k&&k.state!=="inactive"&&(u.current=N?.send??!1,k.stop())},[]),b=o.useCallback(()=>{s==="recording"?g():s==="idle"&&v()},[s,v,g]);return{state:s,toggle:b,stop:g}}const Is={maxHeight:"360px",overflowY:"auto",borderRadius:"8px",boxShadow:"0 24px 60px rgba(2, 6, 23, 0.38), 0 0 0 1px rgba(148, 163, 184, 0.12)",zIndex:1e3,padding:"6px",transition:"opacity 150ms ease-in-out, transform 150ms ease-in-out",backdropFilter:"blur(12px)"},cc={frequent:"Frequently Used",builtin:"Built-in Commands",skill:"Skills",project:"Project Commands",user:"User Commands",other:"Other Commands"},$s={frequent:Ja,builtin:Ar,skill:Or,project:Ga,user:Ka,other:Ks},Ls={frequent:"border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-400/20 dark:bg-amber-400/10 dark:text-amber-200",builtin:"border-sky-200 bg-sky-50 text-sky-700 dark:border-sky-400/20 dark:bg-sky-400/10 dark:text-sky-200",skill:"border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-400/20 dark:bg-emerald-400/10 dark:text-emerald-200",project:"border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-400/20 dark:bg-indigo-400/10 dark:text-indigo-200",user:"border-rose-200 bg-rose-50 text-rose-700 dark:border-rose-400/20 dark:bg-rose-400/10 dark:text-rose-200",other:"border-gray-200 bg-gray-50 text-gray-600 dark:border-gray-500/20 dark:bg-gray-500/10 dark:text-gray-200"},xt=16,dc=360,uc=160,Ct=e=>`${e.name}::${e.namespace||e.type||"other"}::${e.path||""}`,mc=e=>e.namespace||e.type||"other",pc=e=>$s[e]||$s.other,fc=e=>Ls[e]||Ls.other,xc=e=>{if(typeof window>"u")return{position:"fixed",top:"16px",left:"16px"};const r=Math.max(xt,window.innerHeight-xt-uc);if(window.innerWidth<640){const n=Math.min(Math.max(xt,e.bottom??90),r);return{position:"fixed",bottom:`${n}px`,left:"16px",right:"16px",width:"auto",maxWidth:"calc(100vw - 32px)",maxHeight:`min(54vh, calc(100vh - ${n}px - ${xt}px))`}}const s=Math.min(Math.max(xt,e.bottom??90),r),a=Math.max(xt,Math.min(e.left,window.innerWidth-440-xt));return{position:"fixed",bottom:`${s}px`,left:`${a}px`,width:"min(440px, calc(100vw - 32px))",maxWidth:"calc(100vw - 32px)",maxHeight:`min(${dc}px, calc(100vh - ${s}px - ${xt}px))`}};function hc({commands:e=[],selectedIndex:r=-1,onSelect:s,onClose:a,position:n={top:0,left:0},isOpen:l=!1,frequentCommands:i=[]}){const c=o.useRef(null),d=o.useRef(null),u=xc(n);if(o.useEffect(()=>{if(!l)return;const m=p=>{!c.current||!(p.target instanceof Node)||c.current.contains(p.target)||a()};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[l,a]),o.useEffect(()=>{if(!d.current||!c.current)return;const m=c.current.getBoundingClientRect(),p=d.current.getBoundingClientRect();(p.bottom>m.bottom||p.top<m.top)&&d.current.scrollIntoView({block:"nearest",behavior:"smooth"})},[r]),!l)return null;const x=i.length>0,v=new Set(i.map(Ct)),g=new Map;e.forEach((m,p)=>{const h=Ct(m),y=g.get(h)??[];y.push(p),g.set(h,y)});const b=new Map,N=m=>{const p=Ct(m),h=b.get(p)??0;b.set(p,h+1);const y=g.get(p)??[];return y[h]??y[0]??-1},k=e.reduce((m,p,h)=>{if(x&&v.has(Ct(p)))return m;const y=mc(p);return m[y]||(m[y]=[]),m[y].push({command:p,commandIndex:h,renderKey:`${y}-${h}-${Ct(p)}`}),m},{});x&&(k.frequent=i.map((m,p)=>{const h=N(m);return{command:m,commandIndex:h,renderKey:`frequent-${p}-${h}-${Ct(m)}`}}).filter(m=>m.commandIndex>=0));const E=x?["frequent","builtin","skill","project","user","other"]:["builtin","skill","project","user","other"],w=Object.keys(k).filter(m=>!E.includes(m)),L=[...E,...w].filter(m=>k[m]),f=m=>typeof document>"u"?m:qt.createPortal(m,document.body);return e.length===0?f(t.jsx("div",{ref:c,className:"command-menu command-menu-empty border border-border bg-popover/95 text-sm text-muted-foreground",style:{...Is,...u,overflowY:"hidden",padding:"20px",opacity:1,transform:"translateY(0)",textAlign:"center"},children:"No commands available"})):f(t.jsx("div",{ref:c,role:"listbox","aria-label":"Available commands",className:"command-menu border border-border bg-popover/95 text-popover-foreground",style:{...Is,...u,opacity:1,transform:"translateY(0)"},children:L.map(m=>t.jsxs("div",{className:"command-group",children:[L.length>1&&t.jsxs("div",{className:"flex items-center justify-between px-2 pb-1.5 pt-2 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:[t.jsx("span",{children:cc[m]||m}),t.jsx("span",{className:"rounded border border-border bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground",children:(k[m]||[]).length})]}),(k[m]||[]).map(({command:p,commandIndex:h,renderKey:y})=>{const I=h===r,T=pc(m),j=fc(m);return t.jsxs("div",{ref:I?d:null,role:"option","aria-selected":I,className:`command-item group relative mb-1 flex cursor-pointer items-start gap-2 rounded-md border px-2.5 py-2 transition-all ${I?"border-primary/30 bg-primary/10 shadow-sm":"border-transparent bg-transparent hover:border-border hover:bg-accent"}`,onMouseEnter:()=>s&&h>=0&&s(p,h,!0),onClick:()=>s&&h>=0&&s(p,h,!1),onMouseDown:A=>A.preventDefault(),children:[I&&t.jsx("span",{className:"absolute bottom-1.5 left-1.5 top-1.5 w-0.5 rounded-full bg-primary"}),t.jsx("span",{className:`mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-md border ${j}`,children:t.jsx(T,{"aria-hidden":"true",size:14,strokeWidth:2.2})}),t.jsxs("div",{className:"min-w-0 flex-1 pr-1",children:[t.jsxs("div",{className:`flex min-w-0 items-center gap-2 ${p.description?"mb-1":"mb-0"}`,children:[t.jsx("span",{className:"min-w-0 truncate font-mono text-[13px] font-semibold text-foreground",title:p.name,children:p.name}),p.metadata?.type&&t.jsx("span",{className:"command-metadata-badge shrink-0 rounded border border-border bg-muted px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground shadow-sm",children:p.metadata.type})]}),p.description&&t.jsx("div",{className:"truncate whitespace-nowrap text-[12px] leading-4 text-muted-foreground",title:p.description,children:p.description})]}),I&&t.jsx("span",{className:"mt-1 flex h-6 w-6 shrink-0 items-center justify-center rounded border border-primary/30 bg-card text-primary shadow-sm",children:t.jsx(Wa,{"aria-hidden":"true",size:13,strokeWidth:2.2})})]},y)})]},m))}))}const gc=["claudeStatus.actions.thinking","claudeStatus.actions.processing","claudeStatus.actions.analyzing","claudeStatus.actions.working","claudeStatus.actions.computing","claudeStatus.actions.reasoning"],bc=["Thinking","Processing","Analyzing","Working","Computing","Reasoning"],yc=220;function kc({activity:e,onAbort:r,isInputFocused:s=!1}){const{t:a}=We("chat"),[n,l]=o.useState(e),[i,c]=o.useState(!1),d=n?.startedAt??null,[u,x]=o.useState(0);if(o.useEffect(()=>{if(e){l(e),c(!1);return}if(!n)return;c(!0);const w=setTimeout(()=>{l(null),c(!1)},yc);return()=>clearTimeout(w)},[e,n]),o.useEffect(()=>{if(d===null)return;const w=()=>x(Math.max(0,Math.floor((Date.now()-d)/1e3)));w();const L=setInterval(w,1e3);return()=>clearInterval(L)},[d]),!n)return null;const v=gc.map((w,L)=>a(w,{defaultValue:bc[L]})),g=(n.statusText||v[Math.floor(u/4)%v.length]).replace(/\.+$/,""),b=Math.floor(u/60),N=u%60,k=b<1?a("claudeStatus.elapsed.seconds",{count:N,defaultValue:"{{count}}s"}):a("claudeStatus.elapsed.minutesSeconds",{minutes:b,seconds:N,defaultValue:"{{minutes}}m {{seconds}}s"}),E=["chat-activity-tab inline-flex h-8 items-center rounded-b-none rounded-t-lg border border-b-0 bg-card px-3 text-xs transition-all duration-200",s?"border-primary/30 shadow-[0_-1px_2px_hsl(var(--foreground)/0.08),1px_0_2px_hsl(var(--foreground)/0.06),-1px_0_2px_hsl(var(--foreground)/0.06)]":"border-border/50 shadow-[0_-1px_1px_hsl(var(--foreground)/0.04),1px_0_1px_hsl(var(--foreground)/0.03),-1px_0_1px_hsl(var(--foreground)/0.03)]"].join(" ");return t.jsx("div",{className:`pointer-events-none bg-transparent ${i?"chat-activity-exit":"chat-activity-enter"}`,children:t.jsxs("div",{className:"flex items-end justify-between gap-2",children:[t.jsxs("div",{className:`${E} gap-2`,children:[t.jsx("span",{className:"h-1.5 w-1.5 shrink-0 animate-pulse rounded-full bg-primary","aria-hidden":!0}),t.jsx(Nr,{className:"font-medium",children:`${g}…`}),t.jsx("span",{className:"tabular-nums text-muted-foreground/60",children:k})]}),n.canInterrupt&&r&&t.jsxs("button",{type:"button",onClick:r,className:`${E} pointer-events-auto gap-1.5 text-muted-foreground hover:bg-card hover:text-destructive`,"aria-label":a("claudeStatus.stop",{defaultValue:"Stop"}),children:[t.jsx("svg",{className:"h-2.5 w-2.5 fill-current",viewBox:"0 0 24 24","aria-hidden":!0,children:t.jsx("rect",{x:"5",y:"5",width:"14",height:"14",rx:"2"})}),t.jsx("span",{children:a("claudeStatus.stop",{defaultValue:"Stop"})}),t.jsx("kbd",{className:"hidden rounded border border-border/60 px-1 text-[10px] text-muted-foreground/70 sm:inline-block",children:"esc"})]})]})})}const wc=e=>e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`,vc=({file:e,onRemove:r,uploadProgress:s,error:a})=>{const[n,l]=o.useState(void 0),[i,c]=o.useState(!1),d=e.type.startsWith("image/");return o.useEffect(()=>{if(!d){l(void 0);return}const u=URL.createObjectURL(e);return l(u),()=>URL.revokeObjectURL(u)},[e,d]),t.jsxs("div",{className:"group relative max-w-full",children:[d?t.jsx("button",{type:"button",onClick:()=>n&&c(!0),"aria-label":`Expand ${e.name}`,className:"block overflow-hidden rounded-xl border border-border/50 shadow-sm focus:outline-none focus:ring-2 focus:ring-primary/60",children:n?t.jsx("img",{src:n,alt:e.name,className:"h-20 w-20 cursor-zoom-in object-cover"}):t.jsx("div",{className:"h-20 w-20 animate-pulse bg-muted"})}):t.jsxs("div",{className:"flex h-20 w-56 max-w-full items-center gap-3 rounded-xl border border-border/50 bg-background/80 px-3 shadow-sm",children:[t.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary",children:t.jsx(qs,{className:"h-5 w-5","aria-hidden":!0})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate text-sm font-medium text-foreground",title:e.name,children:e.name}),t.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:wc(e.size)})]})]}),s!==void 0&&s<100&&t.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center rounded-xl bg-black/50",children:t.jsxs("div",{className:"text-xs text-white",children:[s,"%"]})}),a&&t.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center rounded-xl bg-red-500/50",children:t.jsx("svg",{className:"h-6 w-6 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),t.jsx("button",{type:"button",onClick:r,className:"absolute -right-1.5 -top-1.5 rounded-full border border-border/40 bg-background/90 p-1 text-foreground shadow-sm backdrop-blur transition-opacity hover:bg-background focus:opacity-100 sm:opacity-0 sm:group-hover:opacity-100","aria-label":`Remove ${e.name}`,children:t.jsx(it,{className:"h-3 w-3","aria-hidden":!0})}),i&&n&&t.jsx(vn,{src:n,alt:e.name,onClose:()=>c(!1)})]})};function jc({state:e,onToggle:r,errorMsg:s}){const{t:a}=We("chat"),n=e==="recording"?t.jsx(Vs,{className:"text-red-500"}):e==="transcribing"?t.jsx($t,{className:"animate-spin"}):t.jsx(Qa,{});return t.jsxs("span",{className:"relative inline-flex",children:[s&&t.jsx("span",{className:"absolute bottom-full left-1/2 mb-1 -translate-x-1/2 whitespace-nowrap rounded bg-red-600 px-2 py-1 text-xs text-white shadow-lg",children:s}),t.jsx(Xt,{tooltip:{content:a(e==="recording"?"voice.stopRecording":"voice.input")},onClick:l=>{l.preventDefault(),r()},children:n})]})}const In={};function Nc(e,r){In[e]=r}function Cc(e){return In[e]||null}Nc("AskUserQuestion",oi);function Sc({pendingPermissionRequests:e,handlePermissionDecision:r,handleGrantToolPermission:s}){const a=e.filter(n=>n.toolName!=="ExitPlanMode"&&n.toolName!=="exit_plan_mode");return a.length?t.jsx("div",{className:"mb-3 space-y-2",children:a.map(n=>{const l=Cc(n.toolName);if(l)return t.jsx(l,{request:n,onDecision:r},n.requestId);const i=os(n.input),c=as(n.toolName,i),d=un(),u=c?d.allowedTools.includes(c):!1,x=u?"Allow (saved)":"Allow & remember",v=c?e.filter(g=>as(g.toolName,os(g.input))===c).map(g=>g.requestId):[n.requestId];return t.jsxs(ma,{approval:"pending",children:[t.jsxs(pa,{className:"flex items-start gap-3",children:[t.jsx(Ya,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),t.jsxs(fa,{children:[t.jsxs("div",{children:[t.jsx("span",{className:"font-medium text-foreground",children:"Permission required"}),t.jsxs("span",{className:"ml-2 text-muted-foreground",children:["Tool: ",t.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs",children:n.toolName})]})]}),c&&t.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:["Allow rule: ",t.jsx("code",{className:"rounded bg-muted px-1 py-0.5 text-xs",children:c})]})]})]}),i&&t.jsxs("details",{className:"mt-2",children:[t.jsx("summary",{className:"cursor-pointer text-xs text-muted-foreground hover:text-foreground",children:"View tool input"}),t.jsx("pre",{className:"mt-2 max-h-40 overflow-auto whitespace-pre-wrap rounded-md border bg-muted/50 p-2 text-xs text-muted-foreground",children:i})]}),t.jsxs(xa,{children:[t.jsx(fr,{variant:"outline",onClick:()=>r(n.requestId,{allow:!1,message:"User denied tool use"}),children:"Deny"}),t.jsx(fr,{variant:"outline",onClick:()=>{c&&!u&&s({entry:c,toolName:n.toolName}),r(v,{allow:!0,rememberEntry:c})},disabled:!c,children:x}),t.jsx(fr,{variant:"default",onClick:()=>r(n.requestId,{allow:!0}),children:"Allow once"})]})]},n.requestId)})}):null}const Mc=e=>!Number.isFinite(e)||e<=0?"0":e>=1e6?`${(e/1e6).toFixed(e>=1e7?0:1)}M`:e>=1e4?`${Math.round(e/1e3)}K`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString(),wr=e=>{const r=Number(e);return Number.isFinite(r)?r:0};function Tc({usage:e,onClick:r}){const s=e?.breakdown&&typeof e.breakdown=="object"?e.breakdown:null,a=wr(e?.inputTokens??s?.input),n=wr(e?.outputTokens??s?.output),l=wr(e?.used)||a+n;return t.jsxs("button",{type:"button",onClick:r,className:"inline-flex h-8 items-center gap-1.5 rounded-lg border border-border/70 bg-background/70 px-2 text-xs text-muted-foreground shadow-sm transition-colors hover:border-primary/25 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 sm:gap-2 sm:px-2.5",title:`${l.toLocaleString()} tokens used`,"aria-label":"Show token usage",children:[t.jsx("span",{className:"grid h-5 w-5 place-items-center rounded-md bg-primary/10 text-primary",children:t.jsx(lr,{className:"h-3.5 w-3.5"})}),t.jsx("span",{className:"font-medium text-foreground",children:Mc(l)}),t.jsx("span",{className:"hidden text-muted-foreground/70 sm:inline",children:"tokens"})]})}function Ec({content:e,attachmentCount:r=0,onEdit:s,onDelete:a}){const{t:n}=We("chat");return t.jsx("div",{className:"settings-content-enter mx-auto mb-2 max-w-[54.25rem] rounded-xl rounded-t-none border border-dashed border-primary/25 bg-primary/[0.04] px-3 py-2",children:t.jsxs("div",{className:"flex items-start gap-2.5",children:[t.jsx("span",{className:"mt-1.5 h-1.5 w-1.5 shrink-0 rounded-full bg-primary/60","aria-hidden":!0}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-primary/70",children:[t.jsx("span",{children:n("input.queue.label",{defaultValue:"Queued"})}),t.jsxs("span",{className:"normal-case text-muted-foreground/60",children:["· ",n("input.queue.willSend",{defaultValue:"Will send when this finishes"})]})]}),t.jsx("p",{className:"mt-0.5 line-clamp-2 break-words text-sm text-foreground/90",children:e}),r>0&&t.jsxs("p",{className:"mt-0.5 text-xs text-muted-foreground",children:[r," ",r===1?"file":"files"," attached"]})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[t.jsx("button",{type:"button",onClick:s,"aria-label":n("input.queue.edit",{defaultValue:"Edit queued message"}),title:n("input.queue.edit",{defaultValue:"Edit queued message"}),className:"rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:t.jsx(Ws,{className:"h-3.5 w-3.5"})}),t.jsx("button",{type:"button",onClick:a,"aria-label":n("input.queue.delete",{defaultValue:"Delete queued message"}),title:n("input.queue.delete",{defaultValue:"Delete queued message"}),className:"rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive",children:t.jsx(it,{className:"h-3.5 w-3.5"})})]})]})})}const vr=8,Rs=8;function $n(e,r,s=320){const a=o.useRef(null),n=o.useRef(null),[l,i]=o.useState(null),c=o.useCallback(()=>{const d=a.current?.getBoundingClientRect();if(!d)return;const u=Math.max(vr,window.innerWidth-d.right);i({right:u,bottom:window.innerHeight-d.top+Rs,maxHeight:Math.max(160,d.top-Rs-vr),maxWidth:Math.max(200,Math.min(s,window.innerWidth-u-vr))})},[s]);return o.useEffect(()=>{if(!e)return;const d=x=>{const v=x.target;!a.current?.contains(v)&&!n.current?.contains(v)&&r()},u=x=>{x.key==="Escape"&&(x.preventDefault(),x.stopPropagation(),r(),a.current?.focus())};return document.addEventListener("pointerdown",d),window.addEventListener("resize",c),window.addEventListener("scroll",c,!0),window.addEventListener("keydown",u,{capture:!0}),c(),()=>{document.removeEventListener("pointerdown",d),window.removeEventListener("resize",c),window.removeEventListener("scroll",c,!0),window.removeEventListener("keydown",u,{capture:!0})}},[e,r,c]),{triggerRef:a,menuRef:n,anchor:l,updateAnchor:c}}function Ln({anchor:e,menuRef:r,ariaLabel:s,children:a}){return t.jsx("div",{ref:r,role:"menu","aria-label":s,className:"fixed z-[100] min-w-48 overflow-y-auto overscroll-contain rounded-xl border border-border bg-popover p-1 text-popover-foreground shadow-xl",style:{right:e.right,bottom:e.bottom,maxHeight:e.maxHeight,maxWidth:e.maxWidth},children:a})}function Lr({children:e}){return t.jsx("p",{className:"px-2.5 pb-1 pt-1.5 text-[11px] font-medium text-muted-foreground",children:e})}function Ic(){return t.jsx("div",{className:"my-1 h-px bg-border","aria-hidden":!0})}function Zt({label:e,description:r,icon:s,isSelected:a,onSelect:n,role:l="menuitemradio",trailing:i,className:c}){return t.jsxs("button",{type:"button",role:l,"aria-checked":l==="menuitemradio"?a:void 0,onClick:n,className:Ae("flex w-full items-start gap-2.5 rounded-lg px-2.5 py-1.5 text-left text-sm transition-colors","hover:bg-accent focus-visible:bg-accent focus-visible:outline-none",a?"text-foreground":"text-foreground/90",c),children:[s&&t.jsx("span",{className:"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center",children:s}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate leading-5",children:e}),r&&t.jsx("span",{className:"mt-0.5 block text-xs leading-4 text-muted-foreground",children:r})]}),t.jsx("span",{className:"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center",children:i??(a?t.jsx(Ut,{className:"h-3.5 w-3.5 text-foreground"}):null)})]})}function $c({effort:e,effortOptions:r,onSelectEffort:s,model:a,modelOptions:n,onSelectModel:l,modelsLoading:i}){const{t:c}=We("chat"),[d,u]=o.useState(!1),[x,v]=o.useState(!1),g=o.useCallback(()=>u(!1),[]),{triggerRef:b,menuRef:N,anchor:k,updateAnchor:E}=$n(d,g);o.useEffect(()=>{d||v(!1)},[d]);const w=c("composer.effortDefault",{defaultValue:"Default"}),L=o.useMemo(()=>r.length>0?[{value:rt},...r]:[],[r]),f=e===rt?w:e,p=o.useMemo(()=>n.find(j=>j.value===a)??null,[a,n])?.label||a,h=L.length>0,y=n.length>0||i;if(!h&&!y)return null;const I=y?p:f,T=c("composer.modelMenu",{defaultValue:"Select model and reasoning effort"});return t.jsxs(t.Fragment,{children:[t.jsxs("button",{ref:b,type:"button",onClick:()=>{E(),u(j=>!j)},className:"flex h-8 max-w-20 shrink-0 items-center gap-1 rounded-lg border border-border/60 bg-muted/40 px-2 text-xs font-medium text-foreground transition-colors hover:bg-muted sm:max-w-56","aria-haspopup":"menu","aria-expanded":d,"aria-label":T,title:T,children:[t.jsx("span",{className:"truncate",children:I}),y&&h&&e!==rt&&t.jsxs("span",{className:"hidden shrink-0 capitalize text-muted-foreground sm:inline",children:["· ",f]})]}),d&&k&&qt.createPortal(t.jsxs(Ln,{anchor:k,menuRef:N,ariaLabel:T,children:[h&&t.jsxs(t.Fragment,{children:[t.jsx(Lr,{children:c("composer.reasoning",{defaultValue:"Reasoning"})}),L.map(j=>t.jsx(Zt,{label:j.value===rt?w:j.value,description:j.description,isSelected:j.value===e,onSelect:()=>{s(j.value),u(!1)},className:"capitalize"},j.value))]}),y&&t.jsxs(t.Fragment,{children:[h&&t.jsx(Ic,{}),t.jsx(Zt,{role:"menuitem",label:p,isSelected:!1,onSelect:()=>v(j=>!j),trailing:x?t.jsx(rr,{className:"h-3.5 w-3.5 text-muted-foreground"}):t.jsx(It,{className:"h-3.5 w-3.5 text-muted-foreground"}),className:"text-muted-foreground"}),x&&t.jsxs(t.Fragment,{children:[t.jsx(Lr,{children:c("composer.model",{defaultValue:"Model"})}),n.length===0&&i&&t.jsx("p",{className:"px-2.5 py-1.5 text-sm text-muted-foreground",children:c("composer.loadingModels",{defaultValue:"Loading models…"})}),n.map(j=>t.jsx(Zt,{label:j.label||j.value,isSelected:j.value===a,onSelect:()=>{l(j.value),u(!1)}},j.value))]})]})]}),document.body)]})}const Lc={default:{icon:ro,trigger:"border-border/60 bg-muted/50 text-muted-foreground hover:bg-muted",item:"text-foreground"},auto:{icon:to,trigger:"border-blue-300/60 bg-blue-50 text-blue-700 hover:bg-blue-100 dark:border-blue-600/40 dark:bg-blue-900/15 dark:text-blue-300 dark:hover:bg-blue-900/25",item:"text-blue-700 dark:text-blue-300"},acceptEdits:{icon:eo,trigger:"border-green-300/60 bg-green-50 text-green-700 hover:bg-green-100 dark:border-green-600/40 dark:bg-green-900/15 dark:text-green-300 dark:hover:bg-green-900/25",item:"text-green-700 dark:text-green-300"},bypassPermissions:{icon:Za,trigger:"border-orange-300/60 bg-orange-50 text-orange-700 hover:bg-orange-100 dark:border-orange-600/40 dark:bg-orange-900/15 dark:text-orange-300 dark:hover:bg-orange-900/25",item:"text-orange-600 dark:text-orange-400"},plan:{icon:Xa,trigger:"border-primary/20 bg-primary/5 text-primary hover:bg-primary/10",item:"text-primary"}},Rc={icon:so,trigger:"border-border/60 bg-muted/50 text-muted-foreground hover:bg-muted",item:"text-foreground"},As=e=>Lc[e]??Rc;function Ac({permissionMode:e,permissionModes:r,onSelectPermissionMode:s,providerLabel:a}){const{t:n}=We("chat"),[l,i]=o.useState(!1),c=o.useCallback(()=>i(!1),[]),{triggerRef:d,menuRef:u,anchor:x,updateAnchor:v}=$n(l,c,352);if(r.length===0)return null;const g=As(e),b=g.icon,N=n("composer.permissionHeading",{provider:a,defaultValue:"How should {{provider}} actions be approved?"});return t.jsxs(t.Fragment,{children:[t.jsx("button",{ref:d,type:"button",onClick:()=>{v(),i(k=>!k)},className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg border transition-colors ${g.trigger}`,"aria-haspopup":"menu","aria-expanded":l,"aria-label":N,title:n("input.clickToChangeMode"),children:t.jsx(b,{className:"h-4 w-4"})}),l&&x&&qt.createPortal(t.jsxs(Ln,{anchor:x,menuRef:u,ariaLabel:N,children:[t.jsx(Lr,{children:N}),r.map(k=>{const E=As(k),w=E.icon;return t.jsx(Zt,{icon:t.jsx(w,{className:"h-4 w-4"}),label:n(`codex.modes.${k}`,{defaultValue:k}),description:n(`codex.descriptions.${k}`,{defaultValue:""})||void 0,isSelected:k===e,onSelect:()=>{s(k),i(!1)},className:E.item},k)})]}),document.body)]})}function Oc({pendingPermissionRequests:e,handlePermissionDecision:r,handleGrantToolPermission:s,activity:a,isLoading:n,onAbortSession:l,permissionMode:i,availablePermissionModes:c,onSelectPermissionMode:d,providerLabel:u,effort:x,availableEffortOptions:v,onSelectEffort:g,model:b,availableModelOptions:N,onSelectModel:k,modelsLoading:E,tokenBudget:w,onShowTokenUsage:L,slashCommandsCount:f,onToggleCommandMenu:m,hasInput:p,onClearInput:h,onSubmit:y,isDragActive:I,queuedDraft:T,onEditQueuedDraft:j,onDeleteQueuedDraft:A,attachedFiles:_,onRemoveAttachment:H,uploadingFiles:M,fileErrors:O,showFileDropdown:$,filteredFiles:P,selectedFileIndex:B,onSelectFile:z,filteredCommands:U,selectedCommandIndex:ee,onCommandSelect:ie,onCloseCommandMenu:X,isCommandMenuOpen:pe,frequentCommands:me,getRootProps:he,getInputProps:Y,openAttachmentPicker:le,inputHighlightRef:ae,renderInputWithMentions:K,textareaRef:ce,input:ge,onVoiceTranscript:fe,onInputChange:be,onTextareaClick:oe,onTextareaKeyDown:ne,onTextareaPaste:ve,onTextareaScrollSync:Ne,onTextareaInput:Pe,isInputFocused:nt=!1,onInputFocusChange:je,placeholder:re,isTextareaExpanded:Ee,sendByCtrlEnter:Ie}){const{t:ue}=We("chat"),Ye=o.useRef(null),Le=o.useRef(null),C=o.useMemo(()=>{if(!pe)return{top:0,left:16,bottom:90};const G=ce.current?.getBoundingClientRect();return{top:G?Math.max(16,G.top-316):0,left:G?G.left:16,bottom:G?window.innerHeight-G.top+8:90}},[pe,ce]);o.useEffect(()=>{const G=Ye.current,Oe=Le.current;if(!$||!G||!Oe)return;const De=Oe.offsetTop,ut=De+Oe.offsetHeight,at=G.scrollTop,R=at+G.clientHeight;De<at?G.scrollTop=De:ut>R&&(G.scrollTop=ut-G.clientHeight)},[B,$]);const S=Cn(),[F,q]=o.useState(null),W=o.useRef(null),de=o.useCallback(G=>{q(G),W.current&&clearTimeout(W.current),W.current=setTimeout(()=>q(null),4e3)},[]);o.useEffect(()=>()=>{W.current&&clearTimeout(W.current)},[]);const Ce=o.useCallback(()=>{},[]),{state:xe,toggle:Se,stop:Re}=ic(fe??Ce,de),_e=xe==="recording",Me=xe==="transcribing",bt=e.some(G=>G.toolName==="AskUserQuestion"),dt=e.length>0,yt=!!(a&&!dt),Ue=!!T,et=n&&!!(ge.trim()||_.length>0),Je=et?Ue?ue("input.hintText.updateQueued",{defaultValue:"Enter to update queued message"}):ue("input.hintText.queue",{defaultValue:"Enter to queue your next message"}):ue(Ie?"input.hintText.ctrlEnter":"input.hintText.enter"),Be=et?Ue?ue("input.queue.update",{defaultValue:"Update queued message"}):ue("input.queue.sendNext",{defaultValue:"Queue next message"}):ue(n?"input.stop":"input.send");return t.jsxs("div",{className:"chat-composer-shell relative flex-shrink-0 px-2 pb-2 pt-0 sm:px-4 sm:pb-4 md:px-4 md:pb-6",children:[!dt&&t.jsx("div",{className:"pointer-events-none absolute bottom-full left-1/2 z-10 w-[calc(100%-1rem)] max-w-[54.25rem] -translate-x-1/2 translate-y-px bg-transparent sm:w-[calc(100%-2rem)]",children:t.jsx(kc,{activity:a,onAbort:l,isInputFocused:nt})}),e.length>0&&t.jsx("div",{className:"mx-auto mb-3 max-w-[54.25rem]",children:t.jsx(Sc,{pendingPermissionRequests:e,handlePermissionDecision:r,handleGrantToolPermission:s})}),T&&t.jsx(Ec,{content:T.content,attachmentCount:T.uploadedAttachments?.length??T.attachments.length,onEdit:j,onDelete:A}),!bt&&t.jsxs("div",{className:"relative mx-auto max-w-[54.25rem]",children:[$&&P.length>0&&t.jsx("div",{ref:Ye,className:"absolute bottom-full left-0 right-0 z-50 mb-2 max-h-48 overflow-y-auto rounded-xl border border-border/50 bg-card/95 shadow-lg backdrop-blur-md",children:P.map((G,Oe)=>t.jsxs("div",{ref:Oe===B?Le:void 0,className:`cursor-pointer touch-manipulation border-b border-border/30 px-4 py-3 last:border-b-0 ${Oe===B?"bg-primary/8 text-primary":"text-foreground hover:bg-accent/50"}`,onMouseDown:De=>{De.preventDefault(),De.stopPropagation()},onClick:De=>{De.preventDefault(),De.stopPropagation(),z(G)},children:[t.jsx("div",{className:"text-sm font-medium",children:G.name}),t.jsx("div",{className:"font-mono text-xs text-muted-foreground",children:G.path})]},G.path))}),t.jsx(hc,{commands:U,selectedIndex:ee,onSelect:ie,onClose:X,position:C,isOpen:pe,frequentCommands:me}),t.jsxs(ha,{onSubmit:y,status:n?"streaming":"ready",className:[Ee?"chat-input-expanded":"",yt?"rounded-t-none":""].filter(Boolean).join(" "),...he(),children:[I&&t.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center rounded-2xl border-2 border-dashed border-primary/50 bg-primary/15",children:t.jsxs("div",{className:"rounded-xl border border-border/30 bg-card p-4 shadow-lg",children:[t.jsx("svg",{className:"mx-auto mb-2 h-8 w-8 text-primary",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"})}),t.jsx("p",{className:"text-sm font-medium",children:"Drop files here"})]})}),_.length>0&&t.jsx(ga,{children:t.jsx("div",{className:"rounded-xl bg-muted/40 p-2",children:t.jsx("div",{className:"flex flex-wrap gap-2",children:_.map((G,Oe)=>t.jsx(vc,{file:G,onRemove:()=>H(Oe),uploadProgress:M.get(G.name),error:O.get(G.name)},`${G.name}-${G.lastModified}-${Oe}`))})})}),t.jsx("input",{...Y()}),t.jsxs(ba,{children:[t.jsx("div",{ref:ae,"aria-hidden":"true",className:"pointer-events-none absolute inset-0 overflow-hidden rounded-xl",children:t.jsx("div",{className:"chat-input-placeholder block w-full whitespace-pre-wrap break-words px-4 py-2 text-sm leading-6 text-transparent",children:K(ge)})}),t.jsx(ya,{ref:ce,dir:"auto",value:ge,onChange:be,onClick:oe,onKeyDown:ne,onPaste:ve,onScroll:G=>Ne(G.target),onFocus:()=>je?.(!0),onBlur:()=>je?.(!1),onInput:Pe,placeholder:re})]}),t.jsxs(ka,{children:[t.jsxs(wa,{className:"min-w-0",children:[t.jsx(Xt,{tooltip:{content:ue("input.attachFiles")},onClick:le,"aria-label":ue("input.attachFiles"),children:t.jsx(no,{})}),fe&&S&&t.jsx(jc,{state:xe,onToggle:Se,errorMsg:F}),t.jsx(Tc,{usage:w,onClick:L}),t.jsxs(Xt,{tooltip:{content:ue("input.showAllCommands")},onClick:m,className:"relative",children:[t.jsx(Ks,{}),f>0&&t.jsx("span",{className:"absolute -right-1 -top-1 flex h-4 w-4 items-center justify-center rounded-full bg-primary text-[10px] font-bold text-primary-foreground",children:f})]}),p&&t.jsx(Xt,{tooltip:{content:ue("input.clearInput",{defaultValue:"Clear input"})},onClick:h,className:"hidden sm:flex",children:t.jsx(it,{})})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1.5 sm:gap-2",children:[t.jsx("div",{className:`hidden text-xs text-muted-foreground/50 transition-opacity duration-200 lg:block ${ge.trim()&&!et?"opacity-0":"opacity-100"}`,children:Je}),t.jsx($c,{effort:x,effortOptions:v,onSelectEffort:g,model:b,modelOptions:N,onSelectModel:k,modelsLoading:E}),t.jsx(Ac,{permissionMode:i,permissionModes:c,onSelectPermissionMode:d,providerLabel:u}),t.jsx(va,{onClick:et?G=>{G.preventDefault(),y(G)}:n?l:_e?G=>{G.preventDefault(),Re({send:!0})}:void 0,disabled:n||_e?!1:Me?!0:!ge.trim()&&_.length===0,"aria-label":Be,title:Be,className:"h-10 w-10 sm:h-10 sm:w-10",children:Me?t.jsx($t,{className:"h-4 w-4 animate-spin"}):et?t.jsx(ao,{className:"h-4 w-4"}):void 0})]})]})]})]})]})}const Pc={claude:"Claude",cursor:"Cursor",codex:"Codex",opencode:"OpenCode"},_c=[{name:"/models",description:"Browse available models for the active provider."},{name:"/cost",description:"Review token usage for the active session."},{name:"/status",description:"Inspect runtime, version, provider, and environment status."},{name:"/memory",description:"Open the project CLAUDE.md memory file."},{name:"/config",description:"Open settings and configuration."},{name:"/help",description:"Show command documentation and syntax."}],Fr=(e,r="Unknown")=>e?Pc[e]||e:r,Yt=e=>Number.isFinite(e)?e.toLocaleString():"0";function Dc({label:e,value:r,icon:s,tone:a="neutral",compact:n=!1}){const l=a==="primary"?"border-primary/35 bg-primary/10 text-primary":a==="success"?"border-emerald-500/30 bg-emerald-500/10 text-emerald-600 dark:text-emerald-300":"border-border/70 bg-background/75 text-muted-foreground";return t.jsxs("div",{className:`group rounded-2xl border border-border/70 bg-background/75 shadow-sm transition-all duration-200 hover:-translate-y-0.5 hover:border-primary/25 hover:shadow-md ${n?"p-3":"p-4"}`,children:[t.jsx("div",{className:`inline-flex rounded-xl border ${n?"mb-2 p-1.5":"mb-3 p-2"} ${l}`,children:t.jsx(s,{className:n?"h-3.5 w-3.5":"h-4 w-4"})}),t.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:e}),t.jsx("p",{className:`${n?"mt-0.5 text-[13px]":"mt-1 text-sm"} break-all font-semibold text-foreground`,children:r})]})}function Rn({value:e,onChange:r,placeholder:s}){return t.jsxs("div",{className:"relative",children:[t.jsx(uo,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(Cr,{value:e,onChange:a=>r(a.target.value),placeholder:s,className:"h-10 rounded-xl border-border/70 bg-background/75 pl-9 pr-3 shadow-none focus-visible:ring-primary/40"})]})}function Fc({data:e}){const[r,s]=o.useState(""),a=Array.isArray(e.commands)&&e.commands.length>0?e.commands:_c,n=o.useMemo(()=>{const l=r.trim().toLowerCase();return l?a.filter(i=>`${i.name} ${i.description||""} ${i.namespace||""}`.toLowerCase().includes(l)):a},[a,r]);return t.jsxs("div",{className:"grid h-full min-h-0 gap-4 lg:grid-cols-[minmax(0,1fr)_18rem]",children:[t.jsxs("div",{className:"flex min-h-0 flex-col gap-3",children:[t.jsx(Rn,{value:r,onChange:s,placeholder:"Filter commands..."}),t.jsxs("div",{className:"scrollbar-thin min-h-0 flex-1 overflow-y-auto pr-1",children:[t.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:n.map((l,i)=>t.jsxs("div",{className:"settings-content-enter rounded-2xl border border-border/70 bg-background/75 p-3 shadow-sm transition-all duration-200 hover:-translate-y-0.5 hover:border-primary/30 hover:bg-muted/25",style:{animationDelay:`${Math.min(i*18,160)}ms`},children:[t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsx("code",{className:"rounded-lg border border-primary/20 bg-primary/10 px-2 py-1 text-xs font-semibold text-primary",children:l.name}),t.jsx(jt,{variant:"secondary",className:"shrink-0 text-[10px] capitalize",children:l.namespace||"builtin"})]}),t.jsx("p",{className:"mt-3 text-sm leading-5 text-muted-foreground",children:l.description||"No description available."})]},`${l.namespace||"builtin"}-${l.name}`))}),n.length===0&&t.jsx("div",{className:"rounded-2xl border border-dashed border-border bg-muted/20 px-4 py-10 text-center text-sm text-muted-foreground",children:"No commands match that filter."})]})]}),t.jsxs("aside",{className:"space-y-3",children:[t.jsxs("div",{className:"rounded-2xl border border-border/70 bg-muted/20 p-4",children:[t.jsxs("div",{className:"mb-3 flex items-center gap-2 text-sm font-semibold text-foreground",children:[t.jsx(sr,{className:"h-4 w-4 text-primary"}),"Syntax"]}),t.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[t.jsx("p",{children:t.jsx("code",{className:"text-foreground",children:"/command arg1 arg2"})}),t.jsxs("p",{children:[t.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," passes all args."]}),t.jsxs("p",{children:[t.jsx("code",{className:"text-foreground",children:"$1"}),", ",t.jsx("code",{className:"text-foreground",children:"$2"})," pass positional args."]}),t.jsxs("p",{children:[t.jsx("code",{className:"text-foreground",children:"@file"})," includes file contents."]})]})]}),t.jsxs("div",{className:"rounded-2xl border border-primary/25 bg-primary/10 p-4",children:[t.jsxs("div",{className:"mb-2 flex items-center gap-2 text-sm font-semibold text-foreground",children:[t.jsx(Or,{className:"h-4 w-4 text-primary"}),"Quick tip"]}),t.jsxs("p",{className:"text-sm leading-5 text-muted-foreground",children:["Type ",t.jsx("code",{className:"text-foreground",children:"/"})," in the composer to open the command palette, then use arrows and Enter to run a command."]})]})]})]})}function Uc({data:e,providerModelCatalog:r,providerModelActions:s,activeProvider:a,activeProviderModel:n,currentSessionId:l,onSelectProviderModel:i}){const[c,d]=o.useState(""),[u,x]=o.useState(null),[v,g]=o.useState(null),[b,N]=o.useState(null),[k,E]=o.useState(!1),w=e?.current?.provider||"claude",L=a===w?n:v??e?.current?.model??"Unknown",f=e?.current?.providerLabel||Fr(w),m=r[w],p=o.useMemo(()=>m?.OPTIONS&&m.OPTIONS.length>0?m.OPTIONS:Array.isArray(e?.availableOptions)&&e.availableOptions.length>0?e.availableOptions:(Array.isArray(e?.availableModels)?e.availableModels:[]).map(A=>({value:A,label:A})),[e,m]),h=o.useMemo(()=>{const j=c.trim().toLowerCase();return j?p.filter(A=>`${A.value} ${A.label||""} ${A.description||""}`.toLowerCase().includes(j)):p},[p,c]),y=typeof l=="string"&&l.trim().length>0,I=p.length>6,T=async j=>{x(j);try{const A=await i(w,j,l);if(A.scope==="session"){g(A.model),N(`This session now uses ${A.model}.`);return}g(null),N(`Default ${f} model set to ${A.model}.`)}catch(A){const _=A instanceof Error?A.message:"Unable to change the model right now.";N(_)}finally{x(null)}};return k?t.jsx(Mn,{initialProvider:w,providerModelCatalog:r,actions:s,onDone:()=>E(!1)}):t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-2xl border border-border/70 bg-muted/20 px-3.5 py-2.5",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("p",{className:"text-[10px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:["Active model · ",f]}),t.jsxs("p",{className:"mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5",children:[t.jsx("span",{className:"break-all font-mono text-sm font-semibold text-foreground",children:L}),v&&v!==L&&t.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-[0.14em] text-emerald-500 dark:text-emerald-400",children:["→ ",v," next"]})]})]}),t.jsxs(Qe,{type:"button",variant:"outline",size:"sm",onClick:()=>E(!0),className:"h-9 shrink-0 rounded-xl bg-background px-3 text-xs",children:[t.jsx(Bt,{className:"h-3.5 w-3.5"}),"Manage models"]})]}),I&&t.jsx(Rn,{value:c,onChange:d,placeholder:`Search ${f} models...`}),h.length>0?t.jsx("div",{className:"scrollbar-thin -mr-1 min-h-0 flex-1 overflow-y-auto pr-1",children:t.jsx("div",{className:"grid gap-2 md:grid-cols-2",children:h.map((j,A)=>{const _=j.value===L,H=j.value===v,M=j.value===u;return t.jsxs("button",{type:"button",onClick:()=>T(j.value),disabled:!!u,"aria-label":`Select model ${j.value}`,className:`settings-content-enter group flex min-h-16 flex-col rounded-2xl border p-3 text-left shadow-sm transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-default disabled:opacity-60 ${_?"border-primary/45 bg-primary/10":H?"border-emerald-500/35 bg-emerald-500/10":"border-border/70 bg-background/80 hover:border-primary/30 hover:bg-background"}`,style:{animationDelay:`${Math.min(A*14,180)}ms`},children:[t.jsxs("span",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"break-words text-sm font-semibold text-foreground",children:j.label||j.value}),t.jsxs("span",{className:"flex shrink-0 items-center gap-2",children:[j.isCustom&&t.jsx(jt,{className:"rounded-full px-2 py-0 text-[9px]",children:"Custom"}),_?t.jsx(Qs,{className:"h-4 w-4 shrink-0 text-primary"}):M?t.jsx($t,{className:"h-4 w-4 shrink-0 animate-spin text-primary"}):null]})]}),j.label!==j.value&&t.jsx("span",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground",children:j.value}),j.description&&t.jsx("span",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:j.description}),_&&t.jsx("span",{className:"mt-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-primary",children:"Current selection"}),H&&!_&&t.jsx("span",{className:"mt-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-emerald-500 dark:text-emerald-400",children:"Session model"})]},j.value)})})}):t.jsx("div",{className:"rounded-2xl border border-dashed border-border bg-background/60 px-4 py-10 text-center text-sm text-muted-foreground",children:"No models match that search."}),t.jsx("p",{className:"shrink-0 text-[11px] leading-4 text-muted-foreground",children:b?t.jsx("span",{className:"text-foreground",children:b}):y?"Your choice is saved for this session and becomes the default for new chats.":"Your choice becomes the default model for new chats."})]})}function Bc({data:e}){const r=Number(e.tokenUsage?.used??0),s=Number(e.tokenUsage?.total??0),a=e.model||"Unknown",n=Fr(e.provider,e.provider||"Unknown"),l=typeof e.tokenBreakdown?.input=="number"||typeof e.tokenBreakdown?.output=="number",i=[{label:"Total tokens used",value:Yt(r),icon:lr},...l?[{label:"Input tokens",value:Yt(Number(e.tokenBreakdown?.input??0)),icon:sr},{label:"Output tokens",value:Yt(Number(e.tokenBreakdown?.output??0)),icon:Gs}]:[{label:"Breakdown",value:"Unavailable",icon:sr}],...s>0?[{label:"Context window",value:Yt(s),icon:Pr}]:[]];return t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-background/75",children:i.map(c=>{const d=c.icon;return t.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border/60 px-4 py-3 last:border-b-0",children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[t.jsx("span",{className:"grid h-9 w-9 shrink-0 place-items-center rounded-xl border border-primary/20 bg-primary/10 text-primary",children:t.jsx(d,{className:"h-4 w-4"})}),t.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:c.label})]}),t.jsx("span",{className:"shrink-0 font-mono text-sm font-semibold text-foreground",children:c.value})]},c.label)})}),t.jsx("div",{className:"rounded-2xl border border-border/70 bg-muted/20 p-4",children:t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:"Provider"}),t.jsx("p",{className:"mt-1 text-sm font-semibold text-foreground",children:n})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:"Model"}),t.jsx("p",{className:"mt-1 break-all font-mono text-sm text-foreground",children:a})]})]})})]})}function qc({data:e}){const r=e.memoryUsage?.rssMb,s=[{label:"Package",value:e.packageName||"claude-code-ui",icon:lo},{label:"Version",value:e.version||"Unknown",icon:Qs,tone:"success"},{label:"Uptime",value:e.uptime||"Unknown",icon:io},{label:"Provider",value:Fr(e.provider,e.provider||"Unknown"),icon:co,tone:"primary"},{label:"Model",value:e.model||"Unknown",icon:Js},{label:"Node.js",value:e.nodeVersion||"Unknown",icon:sr},{label:"Platform",value:e.platform||"Unknown",icon:lr},{label:"Memory",value:typeof r=="number"?`${r} MB RSS`:"Unknown",icon:Pr}];return t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"flex items-center justify-between rounded-3xl border border-emerald-500/25 bg-emerald-500/10 p-4",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("span",{className:"relative flex h-3 w-3",children:[t.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-emerald-400 opacity-75"}),t.jsx("span",{className:"relative inline-flex h-3 w-3 rounded-full bg-emerald-500"})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Runtime online"}),t.jsxs("p",{className:"text-xs text-muted-foreground",children:["Process ",e.pid?`#${e.pid}`:"status"," is responding."]})]})]}),t.jsx(jt,{className:"rounded-full bg-emerald-500 text-white hover:bg-emerald-500",children:"Healthy"})]}),t.jsx("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-4",children:s.map(a=>t.jsx(Dc,{label:a.label,value:String(a.value),icon:a.icon,tone:a.tone},a.label))})]})}function Vc({payload:e,onClose:r,providerModelCatalog:s,providerModelActions:a,activeProvider:n,activeProviderModel:l,currentSessionId:i,onSelectProviderModel:c}){const d=!!e,u=e?.kind,x=u==="models",g=u?{help:{eyebrow:"Command center",title:"Help & Shortcuts",subtitle:"Search built-ins, syntax patterns, and command usage without leaving the chat.",icon:oo},models:{eyebrow:"Model selection",title:"Choose a Model",subtitle:"Pick the model this provider should use.",icon:Js},cost:{eyebrow:"Session telemetry",title:"Token Usage",subtitle:"Input, output, and total token counts for this session.",icon:Gs},status:{eyebrow:"Runtime health",title:"System Status",subtitle:"Version, provider, runtime, and environment details in one place.",icon:lr}}[u]:null,b=g?.icon||Or;return t.jsx(Sr,{open:d,onOpenChange:N=>!N&&r(),children:t.jsxs(Mr,{className:"flex h-[min(92dvh,48rem)] w-[calc(100vw-1rem)] max-w-5xl flex-col overflow-hidden rounded-3xl border-border/80 bg-popover/95 p-0 shadow-2xl backdrop-blur-xl sm:w-[min(94vw,64rem)]",children:[t.jsx(Tr,{children:g?.title||"Command Result"}),t.jsxs("div",{className:`flex shrink-0 items-start justify-between gap-3 border-b border-border bg-popover ${x?"px-4 py-3 sm:px-5 sm:py-4":"px-4 py-4 sm:px-6 sm:py-5"}`,children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[t.jsx("div",{className:`flex shrink-0 items-center justify-center rounded-xl border border-border bg-muted text-foreground ${x?"h-9 w-9":"h-10 w-10"}`,children:t.jsx(b,{className:x?"h-4 w-4":"h-5 w-5"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:g?.eyebrow}),t.jsx("p",{className:"mt-0.5 text-lg font-semibold tracking-tight text-foreground sm:text-xl",children:g?.title}),t.jsx("p",{className:"mt-0.5 max-w-2xl text-sm leading-5 text-muted-foreground",children:g?.subtitle})]})]}),t.jsx(Qe,{type:"button",variant:"ghost",size:"icon",onClick:r,className:"h-8 w-8 shrink-0 rounded-lg text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Close command result modal",children:t.jsx(it,{className:"h-4 w-4"})})]}),t.jsxs("div",{className:"settings-content-enter min-h-0 flex-1 overflow-hidden px-4 py-4 sm:px-6 sm:py-5",children:[e?.kind==="help"&&t.jsx(Fc,{data:e.data}),e?.kind==="models"&&t.jsx(Uc,{data:e.data,providerModelCatalog:s,providerModelActions:a,activeProvider:n,activeProviderModel:l,currentSessionId:i,onSelectProviderModel:c}),e?.kind==="cost"&&t.jsx(Bc,{data:e.data}),e?.kind==="status"&&t.jsx(qc,{data:e.data})]}),t.jsxs("div",{className:"flex shrink-0 flex-col gap-3 border-t border-border/70 bg-muted/20 px-4 py-3 text-xs text-muted-foreground sm:flex-row sm:items-center sm:justify-between sm:px-6",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Pr,{className:"h-3.5 w-3.5"}),t.jsx("span",{children:"Esc closes the modal."})]}),t.jsx(Qe,{type:"button",variant:"outline",size:"sm",onClick:r,className:"rounded-xl",children:"Close"})]})]})})}function Hc({isActive:e,selectedProject:r,selectedSession:s,ws:a,sendMessage:n,onFileOpen:l,onInputFocusChange:i,onSessionProcessing:c,onSessionIdle:d,processingSessions:u,onNavigateToSession:x,onSessionEstablished:v,onShowSettings:g,showRawParameters:b,showThinking:N,sendByCtrlEnter:k,externalMessageUpdate:E,newSessionTrigger:w,onShowAllTasks:L}){const{tasksEnabled:f,isTaskMasterInstalled:m}=ja(),{subscribe:p}=Na(),{t:h}=We("chat"),y=$l(),I=o.useRef(null),T=o.useRef(""),j=o.useRef(new Map),A=o.useRef(new Map),_=o.useCallback(()=>{I.current&&(clearTimeout(I.current),I.current=null),T.current=""},[]),{provider:H,setProvider:M,cursorModel:O,setCursorModel:$,claudeModel:P,setClaudeModel:B,codexModel:z,setCodexModel:U,currentProviderEffort:ee,currentProviderEffortOptions:ie,currentProviderModel:X,currentProviderModelOptions:pe,opencodeModel:me,setOpenCodeModel:he,permissionMode:Y,pendingPermissionRequests:le,setPendingPermissionRequests:ae,availablePermissionModes:K,selectPermissionMode:ce,cyclePermissionMode:ge,providerModelCatalog:fe,providerModelsLoading:be,providerModelActions:oe,selectProviderModel:ne,selectProviderEffort:ve,resolvePermissionModeForProvider:Ne}=qo({selectedSession:s,selectedProject:r}),{chatMessages:Pe,addMessage:nt,sessionActivity:je,isProcessing:re,canAbortSession:Ee,currentSessionId:Ie,setCurrentSessionId:ue,isLoadingSessionMessages:Ye,isLoadingMoreMessages:Le,hasMoreMessages:C,totalMessages:S,isUserScrolledUp:F,setIsUserScrolledUp:q,tokenBudget:W,setTokenBudget:de,visibleMessageCount:Ce,visibleMessages:xe,loadEarlierMessages:Se,loadAllMessages:Re,allMessagesLoaded:_e,isLoadingAllMessages:Me,loadAllJustFinished:bt,showLoadAllOverlay:dt,createDiff:yt,scrollContainerRef:Ue,scrollToBottom:et,scrollToBottomAndReset:Je,handleScroll:Be,requestLatestMessages:G}=tl({isActive:e,selectedProject:r,selectedSession:s,ws:a,sendMessage:n,externalMessageUpdate:E,newSessionTrigger:w,processingSessions:u,onSessionIdle:d,resetStreamingState:_,statusCheckSentAtRef:j,lastSeqRef:A,sessionStore:y}),Oe=o.useCallback((Fe,Xe)=>{ue(Fe),v?.(Fe,Xe),x?.(Fe)},[ue,v,x]),{input:De,setInput:ut,textareaRef:at,inputHighlightRef:R,isTextareaExpanded:J,slashCommandsCount:Z,filteredCommands:se,frequentCommands:ke,commandQuery:Te,showCommandMenu:qe,selectedCommandIndex:mt,resetCommandMenuState:pt,handleCommandSelect:ot,handleToggleCommandMenu:kt,showFileDropdown:D,filteredFiles:Q,selectedFileIndex:V,renderInputWithMentions:te,selectFile:ye,attachedFiles:Ve,setAttachedFiles:wt,uploadingFiles:st,fileErrors:tt,getRootProps:vt,getInputProps:Nt,isDragActive:ft,openAttachmentPicker:Ht,handleSubmit:cr,queuedDraft:He,editQueuedDraft:we,deleteQueuedDraft:ze,handleVoiceTranscript:Ke,handleInputChange:At,handleKeyDown:dr,handlePaste:An,handleTextareaClick:On,handleTextareaInput:Pn,syncInputOverlayScroll:_n,handleClearInput:Dn,handleAbortSession:ur,handlePermissionDecision:mr,handleGrantToolPermission:Ur,handleInputFocusChange:Fn,isInputFocused:Un,commandModalPayload:Bn,closeCommandModal:qn,showCostModal:Vn}=bl({selectedProject:r,selectedSession:s,currentSessionId:Ie,provider:H,permissionMode:Y,cyclePermissionMode:ge,currentProviderModel:X,currentProviderEffort:ee,isLoading:re,processingSessions:u,canAbortSession:Ee,tokenBudget:W,sendMessage:n,sendByCtrlEnter:k,onSessionProcessing:c,onSessionEstablished:Oe,onInputFocusChange:i,onFileOpen:l,onShowSettings:g,scrollToBottom:et,addMessage:nt,setIsUserScrolledUp:q,setPendingPermissionRequests:ae,resolvePermissionModeForProvider:Ne}),Hn=o.useCallback(async()=>{!r||!s||(await G(s.id,e),j.current.set(s.id,Date.now()),n({type:"chat.subscribe",sessions:[{sessionId:s.id,lastSeq:A.current.get(s.id)??0}]}))},[e,G,r,s,n]);ll({isActive:e,subscribe:p,provider:H,selectedSession:s,currentSessionId:Ie,setTokenBudget:de,pendingPermissionRequests:le,setPendingPermissionRequests:ae,streamTimerRef:I,accumulatedStreamRef:T,lastSeqRef:A,statusCheckSentAtRef:j,onSessionProcessing:c,onSessionIdle:d,onWebSocketReconnect:Hn,requestLatestMessages:G,sessionStore:y}),o.useEffect(()=>{if(!Ee)return;const Fe=Xe=>{Xe.key!=="Escape"||Xe.repeat||Xe.defaultPrevented||(Xe.preventDefault(),ur())};return document.addEventListener("keydown",Fe,{capture:!0}),()=>{document.removeEventListener("keydown",Fe,{capture:!0})}},[Ee,ur]),o.useEffect(()=>()=>{_()},[_]);const zn=o.useMemo(()=>({pendingPermissionRequests:le,handlePermissionDecision:mr}),[le,mr]),Wn=o.useCallback(async Fe=>{try{await ne(H,Fe,Ie||s?.id||null)}catch(Xe){console.error("Error changing the active session model:",Xe)}},[Ie,H,ne,s?.id]),Kn=o.useCallback(async Fe=>{try{await ve(H,Fe,Ie||s?.id||null)}catch(Xe){console.error("Error changing the active session reasoning effort:",Xe)}},[Ie,H,ve,s?.id]),Gn=!!(je&&le.length===0),pr=H==="cursor"?h("messageTypes.cursor"):H==="codex"?h("messageTypes.codex"):H==="opencode"?h("messageTypes.opencode",{defaultValue:"OpenCode"}):h("messageTypes.claude");return r?t.jsxs(Ys.Provider,{value:zn,children:[t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[t.jsx(ac,{scrollContainerRef:Ue,onWheel:Be,onTouchMove:Be,isLoadingSessionMessages:Ye,isProcessing:re,hasActivityIndicator:Gn,chatMessages:Pe,selectedSession:s,currentSessionId:Ie,provider:H,setProvider:Fe=>M(Fe),textareaRef:at,claudeModel:P,setClaudeModel:B,cursorModel:O,setCursorModel:$,codexModel:z,setCodexModel:U,opencodeModel:me,setOpenCodeModel:he,providerModelCatalog:fe,providerModelActions:oe,providerModelsLoading:be,tasksEnabled:f,isTaskMasterInstalled:m,onShowAllTasks:L,setInput:ut,isLoadingMoreMessages:Le,hasMoreMessages:C,totalMessages:S,sessionMessagesCount:Pe.length,visibleMessageCount:Ce,visibleMessages:xe,loadEarlierMessages:Se,loadAllMessages:Re,allMessagesLoaded:_e,isLoadingAllMessages:Me,loadAllJustFinished:bt,showLoadAllOverlay:dt,createDiff:yt,onFileOpen:l,onShowSettings:g,onGrantToolPermission:Ur,showRawParameters:b,showThinking:N,selectedProject:r}),t.jsxs("div",{className:"relative flex-shrink-0",children:[F&&Pe.length>0&&t.jsx("div",{className:"pointer-events-none absolute -top-11 left-0 right-0 z-20 flex justify-center",children:t.jsx("button",{type:"button",onClick:Je,"aria-label":h("input.scrollToBottom",{defaultValue:"Scroll to bottom"}),className:"pointer-events-auto flex h-8 w-8 items-center justify-center rounded-full border border-border/50 bg-card text-muted-foreground shadow-sm transition-all duration-200 hover:bg-accent hover:text-foreground",title:h("input.scrollToBottom",{defaultValue:"Scroll to bottom"}),children:t.jsx(mo,{className:"h-4 w-4","aria-hidden":!0})})}),t.jsx(Oc,{pendingPermissionRequests:le,handlePermissionDecision:mr,handleGrantToolPermission:Ur,activity:je,isLoading:re,onAbortSession:ur,permissionMode:Y,availablePermissionModes:K,onSelectPermissionMode:Fe=>ce(Fe),providerLabel:pr,effort:ee,availableEffortOptions:ie,onSelectEffort:Kn,model:X,availableModelOptions:pe,onSelectModel:Wn,modelsLoading:be,tokenBudget:W,onShowTokenUsage:Vn,slashCommandsCount:Z,onToggleCommandMenu:kt,hasInput:!!De.trim(),onClearInput:Dn,onSubmit:cr,isDragActive:ft,queuedDraft:He,onEditQueuedDraft:we,onDeleteQueuedDraft:ze,attachedFiles:Ve,onRemoveAttachment:Fe=>wt(Xe=>Xe.filter((zc,Jn)=>Jn!==Fe)),uploadingFiles:st,fileErrors:tt,showFileDropdown:D,filteredFiles:Q,selectedFileIndex:V,onSelectFile:ye,filteredCommands:se,selectedCommandIndex:mt,onCommandSelect:ot,onCloseCommandMenu:pt,isCommandMenuOpen:qe,frequentCommands:Te?[]:ke,getRootProps:vt,getInputProps:Nt,openAttachmentPicker:Ht,inputHighlightRef:R,renderInputWithMentions:te,textareaRef:at,input:De,onVoiceTranscript:Ke,onInputChange:At,onTextareaClick:On,onTextareaKeyDown:dr,onTextareaPaste:An,onTextareaScrollSync:_n,onTextareaInput:Pn,isInputFocused:Un,onInputFocusChange:Fn,placeholder:h("input.placeholder",{provider:pr}),isTextareaExpanded:J,sendByCtrlEnter:k})]})]}),t.jsx(Vc,{payload:Bn,onClose:qn,providerModelCatalog:fe,providerModelActions:oe,activeProvider:H,activeProviderModel:X,currentSessionId:Ie||s?.id||null,onSelectProviderModel:ne})]}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsx("div",{className:"text-center text-muted-foreground",children:t.jsx("p",{className:"text-sm",children:h("projectSelection.startChatWithProvider",{provider:pr,defaultValue:"Select a project to start chatting with {{provider}}"})})})})}const Yc=er.memo(Hc);export{Yc as C,Vl as M,_i as T,Oi as a,ns as c,dn as r};
|