wind-agent-cli 1.38.3 → 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-C9qFO6L8.js → CodeEditor-C8eMIGen.js} +1 -1
- package/dist/assets/{FileTree-0yJEzBi9.js → FileTree-D52nAPO4.js} +1 -1
- package/dist/assets/{GitPanel-BhbG7yVZ.js → GitPanel-DgeKbZsW.js} +1 -1
- package/dist/assets/{MarkdownPreview-C7pAt3xI.js → MarkdownPreview-B00VQTx6.js} +1 -1
- package/dist/assets/{Shell-CrjXAW4f.js → Shell-twzi9t5B.js} +7 -7
- package/dist/assets/{StandaloneShell-J5BR1g26.js → StandaloneShell-DH_GBJMj.js} +1 -1
- package/dist/assets/{TaskMasterPanel-B2wpEHWP.js → TaskMasterPanel-BY-pMPMl.js} +2 -2
- package/dist/assets/{abnfDiagram-N423BO3Z-DztbjsU0.js → abnfDiagram-N423BO3Z-BwBdstkH.js} +1 -1
- package/dist/assets/{arc-DRGumrCP.js → arc-C0IOpbFP.js} +1 -1
- package/dist/assets/{architectureDiagram-T3A2C74G-DnsczqwM.js → architectureDiagram-T3A2C74G-C-Wkj_AY.js} +1 -1
- package/dist/assets/{blockDiagram-VBNYF7ZC-CPsS5qw5.js → blockDiagram-VBNYF7ZC-_sXAZKku.js} +1 -1
- package/dist/assets/{c4Diagram-5PPSVZJV-DyjwDxYL.js → c4Diagram-5PPSVZJV-C0DUsZv8.js} +1 -1
- package/dist/assets/channel-B6xiB58V.js +1 -0
- package/dist/assets/{chunk-2GRJ4B5K-C794q4RK.js → chunk-2GRJ4B5K-D2TFB_6A.js} +1 -1
- package/dist/assets/{chunk-2Q5K7J3B-BfK76GMF.js → chunk-2Q5K7J3B-B_co_2bI.js} +1 -1
- package/dist/assets/{chunk-5RXB4S5H-Dmwk_KHT.js → chunk-5RXB4S5H-BcUSLq4H.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-DOeUnsxL.js → chunk-5VM5RSS4-0mQFBKSp.js} +1 -1
- package/dist/assets/{chunk-6Q2QTUOP-BrjdaybI.js → chunk-6Q2QTUOP-BAkqmW1M.js} +1 -1
- package/dist/assets/{chunk-GF5L2VYU-DCjoLr5D.js → chunk-GF5L2VYU-Cyz0Xl7f.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-TEJEfxQK.js → chunk-JWPE2WC7-DYO47aT-.js} +1 -1
- package/dist/assets/{chunk-KBJHAD2P-tbXW-dpx.js → chunk-KBJHAD2P-DvXEzV8J.js} +1 -1
- package/dist/assets/{chunk-RYQCIY6F-CX4Zsite.js → chunk-RYQCIY6F-Beut8dYt.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-DVJXNcFN.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-DLpXc-vJ.js → cose-bilkent-JH36ORCC-DynbO4dj.js} +1 -1
- package/dist/assets/{cynefin-VYW2F7L2-toFyL_eT.js → cynefin-VYW2F7L2-CYTJsH3o.js} +1 -1
- package/dist/assets/{cynefinDiagram-MW4NZA55-7KnX5nu-.js → cynefinDiagram-MW4NZA55-ftj-lAeE.js} +1 -1
- package/dist/assets/{dagre-VZM6K2ZE-C-QOFsDs.js → dagre-VZM6K2ZE-C1kSFboe.js} +1 -1
- package/dist/assets/{diagram-7IWD3JNH-26OmKaGK.js → diagram-7IWD3JNH-CqXHTFrY.js} +1 -1
- package/dist/assets/{diagram-B4RE2ZJO-0o9kK2uO.js → diagram-B4RE2ZJO-B84n3Zko.js} +1 -1
- package/dist/assets/{diagram-LBJQPF4R-CAgMu3zd.js → diagram-LBJQPF4R-B710SefS.js} +1 -1
- package/dist/assets/{diagram-Q27KOJAE-B0W-AePB.js → diagram-Q27KOJAE-CmVPl9pq.js} +1 -1
- package/dist/assets/{diagram-UB23O5K3-66AXZ7Mk.js → diagram-UB23O5K3-LozbeaFL.js} +1 -1
- package/dist/assets/{ebnfDiagram-BXEA7PRR-JlixVrAW.js → ebnfDiagram-BXEA7PRR-B321UBUA.js} +1 -1
- package/dist/assets/{erDiagram-JOGREHBK-ZxzuRr4f.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-u67vU32D.js → flowDiagram-UKHOOZJN-BWVKTWlw.js} +1 -1
- package/dist/assets/{ganttDiagram-PKOTCBZU-Crl9IPqX.js → ganttDiagram-PKOTCBZU-BAj9eeeX.js} +1 -1
- package/dist/assets/{gitGraphDiagram-DS77QQ5N-B2rTRd1W.js → gitGraphDiagram-DS77QQ5N-DcVMRU7N.js} +1 -1
- package/dist/assets/{index-YP8FmBZO.js → index-BYFstHFT.js} +1 -1
- package/dist/assets/index-BbBSplOU.js +35 -0
- package/dist/assets/{index-CPP7a6gU.js → index-BrWTp075.js} +1 -1
- package/dist/assets/index-CHukVVB2.css +1 -0
- package/dist/assets/{index-BTFkWJZe.js → index-k9M0VaFg.js} +1 -1
- package/dist/assets/{infoDiagram-6WML65LV-o9ZSr_ud.js → infoDiagram-6WML65LV-V6wz33B4.js} +1 -1
- package/dist/assets/{ishikawaDiagram-WSZJBQD7-DnrbX4Ui.js → ishikawaDiagram-WSZJBQD7-Dd-WNPyK.js} +1 -1
- package/dist/assets/{journeyDiagram-NVQOT4AX-CSfWpt5R.js → journeyDiagram-NVQOT4AX-D9VCuCeA.js} +1 -1
- package/dist/assets/{kanban-definition-27J2QSJJ-dj3PZxCQ.js → kanban-definition-27J2QSJJ-CUtwDOl-.js} +1 -1
- package/dist/assets/{linear-DieERJn8.js → linear-D_XGf1jO.js} +1 -1
- package/dist/assets/{mermaid.core-cq_VDJvZ.js → mermaid.core-DOnsXioB.js} +4 -4
- package/dist/assets/{mindmap-definition-FAOFIHXS-CHQ8W4LE.js → mindmap-definition-FAOFIHXS-DAYNL5ZV.js} +1 -1
- package/dist/assets/{pegDiagram-VL7TDLO6-CR2rMB3e.js → pegDiagram-VL7TDLO6-B5FX3-E6.js} +1 -1
- package/dist/assets/{pieDiagram-7S7Q4E2Y-Cs4NOlmu.js → pieDiagram-7S7Q4E2Y-EbnDBVd0.js} +1 -1
- package/dist/assets/{quadrantDiagram-CIZ2JOQS-CdHqIaj5.js → quadrantDiagram-CIZ2JOQS-C1koOtwT.js} +1 -1
- package/dist/assets/{railroadDiagram-AXF67PYL-BNPU0Q8Z.js → railroadDiagram-AXF67PYL-D52xmshj.js} +1 -1
- package/dist/assets/{requirementDiagram-LRYGKXZP-DwDQoirA.js → requirementDiagram-LRYGKXZP-B7VbfNnW.js} +1 -1
- package/dist/assets/{sankeyDiagram-W5VNT64P-DSDSpLjf.js → sankeyDiagram-W5VNT64P-CeRG1vHN.js} +1 -1
- package/dist/assets/{sequenceDiagram-SI44F4Z6-zfhext7x.js → sequenceDiagram-SI44F4Z6-CfKHnmSE.js} +1 -1
- package/dist/assets/{sizeCapture-X5ZJPWSS-C56q6k2T.js → sizeCapture-X5ZJPWSS-DJTzyd0S.js} +1 -1
- package/dist/assets/{stateDiagram-OKZ733FA-D2lhrHPg.js → stateDiagram-OKZ733FA-DN0c7IYD.js} +1 -1
- package/dist/assets/stateDiagram-v2-UEYNNEHI-DbihlVOQ.js +1 -0
- package/dist/assets/{swimlanes-SLNWSIFB-D1HyP0oO.js → swimlanes-SLNWSIFB-CaaJpBDA.js} +2 -2
- package/dist/assets/swimlanesDiagram-ULZ7WXOC-BBRevuGP.js +8 -0
- package/dist/assets/{timeline-definition-Z64GVDOM-R1zaf6JI.js → timeline-definition-Z64GVDOM-CrzHN7d2.js} +1 -1
- package/dist/assets/{vennDiagram-T6HMQDX7-BwlaSNYk.js → vennDiagram-T6HMQDX7-BTldHIjo.js} +1 -1
- package/dist/assets/{wardleyDiagram-T6FBY63Y-Dd9-WAib.js → wardleyDiagram-T6FBY63Y-D9Y50OsZ.js} +1 -1
- package/dist/assets/{xychartDiagram-ELKLHX3M-BVn4eBvu.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-Dj-iU3BT.js +0 -1
- package/dist/assets/classDiagram-JCYQIIEL-euwGMP6E.js +0 -1
- package/dist/assets/classDiagram-v2-OCEON4UE-euwGMP6E.js +0 -1
- package/dist/assets/feature-chat-CNYDDkFQ.js +0 -88
- package/dist/assets/feature-workspace-BMlv7Ust.js +0 -39
- package/dist/assets/index-Cr5MbHuj.css +0 -1
- package/dist/assets/index-uINlYqXe.js +0 -35
- package/dist/assets/stateDiagram-v2-UEYNNEHI-C3wzBtFn.js +0 -1
- package/dist/assets/swimlanesDiagram-ULZ7WXOC-Dts8yQMu.js +0 -8
- package/dist/icons/new-icon.png +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mermaid.core-DOnsXioB.js","assets/feature-workspace-FLomYkPq.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-twzi9t5B.js","assets/Shell-DrlLKa8f.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as o,j as t,d as er,b as Vt}from"./vendor-react-C2GTiUCy.js";import{a as $e,p as Br,b as Xn,c as jr,C as Ft,d as Et,e as Ut,f as Pe,g as Ht,u as Os,_ as Ps,h as Zn,Q as ea,i as ta,j as ra,k as sa,l as _s,m as na,n as aa,S as Nr,o as oa,q as la,B as Ye,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 ia,z as Mr,A as Tr,E as ca,F as da,G as ua,H as ma,J as pa,K as Wr,P as Xt,M as fa,N as xa,O as ha,T as ga,U as fr,W as ba,X as ya,Y as ka,Z as wa,$ as va,a0 as ja,a1 as Na,a2 as Ca,a3 as Sa}from"./feature-workspace-FLomYkPq.js";import{V as Ma,t as It,o as Bt,q as Us,$ as Rr,ap as Ta,X as ct,aa as Bs,aq as Ea,ar as Ia,as as qs,d as Vs,L as $t,ad as $a,at as La,au as Ra,av as Aa,C as rr,m as Hs,ag as Oa,n as Pa,aw as _a,ax as zs,U as Ar,h as qt,ay as Kr,S as Da,az as Fa,ae as Ua,a9 as Ba,Z as qa,aA as Va,aB as Ha,aC as Ws,r as za,aD as Wa,aE as Ka,aF as Ga,j as Ks,aG as Ja,F as Qa,a as Or,g as Ya,x as Xa,aj as Za,A as lr,aH as eo,T as to,aI as ro,v as so,aJ as no,aK as ao,aL as oo,aM as lo,aN as Gs,aO as Js,aP as io,aQ as Pr,aR as sr,aS as Qs,aT as co,aU as uo,O as mo,b as po,aV as fo}from"./vendor-ui-CAUHSABu.js";import{y as xo,t as ho,a as go,s as bo,b as yo,p as ko,c as wo,m as vo,d as jo,j as No,e as Co,f as So,g as Mo,h as To,i as Eo,k as Io,l as $o,n as Lo,o as Ro,S as dt,r as Gr,q as Jr,u as Ao,v as Oo,M as Po,w as _o,x as Do}from"./vendor-markdown-DkITEES2.js";import{u as ze,T as Fo}from"./vendor-i18n-B6HjLCnN.js";const Ys=o.createContext(null);function Uo(){return o.useContext(Ys)}const nt="default",Qr={claude:["low","medium","high","xhigh","max"],codex:["low","medium","high","xhigh","max","ultra"],opencode:["none","low","medium","high","xhigh","max"]},Bo=e=>e.map(r=>({value:r})),Ot={claude:"default",cursor:"gpt-5.3-codex",codex:"gpt-5.4",opencode:"anthropic/claude-sonnet-4-5",pi:""},Dt=["claude","cursor","codex","opencode","pi"],qo=()=>{const e=localStorage.getItem("selected-provider");return Dt.includes(e)?e:"claude"},Vo={claude:["default","auto","acceptEdits","bypassPermissions","plan"],cursor:["default","acceptEdits","bypassPermissions","plan"],codex:["default","acceptEdits","bypassPermissions"],opencode:["default","acceptEdits","bypassPermissions","plan"],pi:["default"]},Wt=(e,r)=>`${e}:${r}`;function Ho({selectedSession:e,selectedProject:r}){const[s,a]=o.useState("default"),[n,l]=o.useState([]),[i,c]=o.useState(qo),[d,u]=o.useState(()=>localStorage.getItem("cursor-model")||Ot.cursor),[h,j]=o.useState(()=>localStorage.getItem("claude-model")||Ot.claude),[g,y]=o.useState(()=>localStorage.getItem("codex-model")||Ot.codex),[C,k]=o.useState(()=>Dt.reduce((S,N)=>(S[N]=localStorage.getItem(`${N}-effort`)||nt,S),{})),[T,w]=o.useState(()=>localStorage.getItem("opencode-model")||Ot.opencode),[$,f]=o.useState(()=>localStorage.getItem("pi-model")||Ot.pi),[x,m]=o.useState(null),[p,b]=o.useState({}),[I,E]=o.useState(!0),v=o.useRef(0),A=o.useRef(0),D=o.useRef(0),q=o.useRef(0),M=o.useCallback((S,N)=>{if(S==="claude"){j(N),localStorage.setItem("claude-model",N);return}if(S==="cursor"){u(N),localStorage.setItem("cursor-model",N);return}if(S==="codex"){y(N),localStorage.setItem("codex-model",N);return}if(S==="pi"){f(N),localStorage.setItem("pi-model",N);return}w(N),localStorage.setItem("opencode-model",N)},[]),F=o.useCallback((S,N)=>{k(P=>P[S]===N?P:{...P,[S]:N}),localStorage.setItem(`${S}-effort`,N)},[]),R=o.useCallback(async()=>{const S=v.current+1;v.current=S,E(!0);try{const N=await Promise.all(Dt.map(async V=>{const se=await(await $e(`/api/providers/${V}/models`)).json();return!se.success||!se.data?.models?null:se.data.models}));if(v.current!==S)return;const P={};Dt.forEach((V,X)=>{const se=N[X];se&&(P[V]=se)}),b(P)}catch(N){console.error("Error loading provider models:",N)}finally{v.current===S&&E(!1)}},[]);o.useEffect(()=>{R()},[R]),o.useEffect(()=>{let S=!1;return(async()=>{try{const V=await(await $e("/api/providers/capabilities")).json();if(S||!V.success||!Array.isArray(V.data?.providers))return;const X={};for(const se of V.data.providers)X[se.provider]=se;m(X)}catch(P){console.error("Error loading provider capabilities:",P)}})(),()=>{S=!0}},[]);const U=o.useCallback(S=>{const N=x?.[S]?.permissionModes;return N&&N.length>0?N:Vo[S]??["default"]},[x]),W=o.useCallback(S=>{const N=U(S),P=x?.[S]?.defaultPermissionMode;return P&&N.includes(P)?P:N[0]??"default"},[U,x]),B=o.useCallback(S=>{const N=x?.[S]?.supportsEffort;return typeof N=="boolean"?N:!!Qr[S]?.length},[x]),O=(S,N,P)=>{const V=localStorage.getItem(S);return V&&P.OPTIONS.some(X=>X.value===V)?V:N&&P.OPTIONS.some(X=>X.value===N)?N:P.DEFAULT},z=o.useCallback((S,N)=>{const P=p[S];return P?P.OPTIONS.find(V=>V.value===N)??null:null},[p]),le=o.useCallback((S,N)=>{if(!B(S))return[];const P=z(S,N);return P?P.effort?.values??[]:Bo(Qr[S]??[])},[z,B]),oe=o.useCallback((S,N)=>le(S,N).map(P=>P.value),[le]),fe=o.useCallback((S,N,P)=>{const V=oe(S,N);return V.length===0||P===nt||!P?nt:V.includes(P)?P:nt},[oe]),ie=o.useMemo(()=>({claude:h,cursor:d,codex:g,opencode:T,pi:$}),[h,d,g,T,$]);o.useEffect(()=>{const S=p.claude;if(S){const N=O("claude-model",h,S);N!==h&&j(N),localStorage.getItem("claude-model")!==N&&localStorage.setItem("claude-model",N)}},[p.claude,h]),o.useEffect(()=>{const S=p.cursor;if(S){const N=O("cursor-model",d,S);N!==d&&u(N),localStorage.getItem("cursor-model")!==N&&localStorage.setItem("cursor-model",N)}},[p.cursor,d]),o.useEffect(()=>{const S=p.codex;if(S){const N=O("codex-model",g,S);N!==g&&y(N),localStorage.getItem("codex-model")!==N&&localStorage.setItem("codex-model",N)}},[p.codex,g]),o.useEffect(()=>{const S=p.opencode;if(S){const N=O("opencode-model",T,S);N!==T&&w(N),localStorage.getItem("opencode-model")!==N&&localStorage.setItem("opencode-model",N)}},[p.opencode,T]),o.useEffect(()=>{const S=p.pi;if(S){const N=O("pi-model",$,S);N!==$&&f(N),localStorage.getItem("pi-model")!==N&&localStorage.setItem("pi-model",N)}},[p.pi,$]),o.useEffect(()=>{const S={};let N=!1;for(const P of Dt){const V=C[P]??nt,X=fe(P,ie[P],V);X!==V&&(S[P]=X,localStorage.setItem(`${P}-effort`,X),N=!0)}N&&k(P=>({...P,...S}))},[C,ie,fe]),o.useEffect(()=>{const S=U(i),N=e?.id?localStorage.getItem(`permissionMode-${e.id}`):null,P=localStorage.getItem(`permissionMode-last-${i}`),V=[N,P].find(X=>!!(X&&S.includes(X)));a(V??W(i))},[e?.id,i,W,U]),o.useEffect(()=>{!e?.__provider||e.__provider===i||(c(e.__provider),localStorage.setItem("selected-provider",e.__provider))},[i,e]),o.useEffect(()=>{l(S=>S.filter(N=>!N.sessionId||N.sessionId===e?.id))},[e?.id]);const me=o.useCallback(S=>{a(S),localStorage.setItem(`permissionMode-last-${i}`,S),e?.id&&localStorage.setItem(`permissionMode-${e.id}`,S)},[i,e?.id]),Z=o.useCallback(()=>{const S=U(i),P=(S.indexOf(s)+1)%S.length;me(S[P])},[s,i,U,me]),Me=o.useMemo(()=>U(i),[U,i]),xe=o.useCallback((S,N)=>U(S).includes(N)?N:W(S),[W,U]),[K,ae]=o.useState(null),te=e?.id?.trim()||null,be=e?.__provider??i,Fe=te?Wt(be,te):null,he=o.useRef(Fe);he.current=Fe;const J=K&&te&&K.sessionId===te&&K.provider===be?K:null,ue=J?.model??null;o.useEffect(()=>{const S=A.current+1;if(A.current=S,!te){ae(null);return}let N=!1;const P=be,V=Wt(P,te);return(async()=>{try{const Ne=await(await $e(`/api/providers/${P}/sessions/${encodeURIComponent(te)}/active-model`)).json();if(N||A.current!==S||he.current!==V)return;const we=Ne.data?.model?.trim(),ye=Ne.data?.effort?.trim()||null;ae({provider:P,sessionId:te,model:Ne.success&&we&&Ne.data?.source!=="default"?we:null,effort:Ne.success?ye:null})}catch(se){!N&&A.current===S&&he.current===V&&(console.error("Error loading the session model and reasoning effort:",se),ae({provider:P,sessionId:te,model:null,effort:null}))}})(),()=>{N=!0}},[te,be]);const Te=o.useCallback(async(S,N,P)=>{M(S,N);const V=typeof P=="string"?P.trim():"";if(!V)return{scope:"default",model:N};A.current+=1;const X=D.current+1;D.current=X;const se=Wt(S,V),Ne=await $e(`/api/providers/${S}/sessions/${encodeURIComponent(V)}/active-model`,{method:"POST",body:JSON.stringify({model:N})}),we=await Ne.json();if(!Ne.ok||!we.success)throw new Error("Unable to change the active model for this session.");const ye=we.data?.model?.trim()||N;return D.current===X&&he.current===se&&ae(pe=>({provider:S,sessionId:V,model:ye,effort:pe?.provider===S&&pe.sessionId===V?pe.effort:we.data?.effort?.trim()||null})),{scope:"session",model:ye}},[M]),Ee=o.useCallback(async(S,N,P)=>{F(S,N);const V=typeof P=="string"?P.trim():"";if(!V)return{scope:"default",effort:N};A.current+=1;const X=q.current+1;q.current=X;const se=Wt(S,V),Ne=K?.provider===S&&K.sessionId===V?K:null;ae({provider:S,sessionId:V,model:Ne?.model??null,effort:N});try{const we=await $e(`/api/providers/${S}/sessions/${encodeURIComponent(V)}/active-effort`,{method:"POST",body:JSON.stringify({effort:N})}),ye=await we.json();if(!we.ok||!ye.success)throw new Error("Unable to change the reasoning effort for this session.");const pe=ye.data?.effort?.trim()||N;return q.current===X&&he.current===se&&ae(tt=>({provider:S,sessionId:V,model:tt?.provider===S&&tt.sessionId===V?tt.model:Ne?.model??null,effort:pe})),{scope:"session",effort:pe}}catch(we){throw q.current===X&&he.current===se&&ae(ye=>ye?.provider===S&&ye.sessionId===V&&ye.effort===N?Ne:ye),we}},[K,F]),Ae=ue??ie[i],ge=o.useMemo(()=>le(i,Ae),[Ae,le,i]),de=o.useMemo(()=>fe(i,Ae,J?.effort??C[i]??nt),[J?.effort,Ae,i,C,fe]),We=o.useMemo(()=>p[i]?.OPTIONS??[],[i,p]),Le=o.useCallback((S,N)=>{b(P=>({...P,[S]:N}))},[]),ce=o.useCallback(async S=>{const N=await S.json();if(!S.ok||!N.success||!N.data?.model||!N.data.models)throw new Error(N.error?.message||"Unable to save this model.");return{model:N.data.model,models:N.data.models}},[]),Re=o.useCallback(async(S,N)=>{const P=await $e(`/api/providers/${S}/models`,{method:"POST",body:JSON.stringify(N)}),V=await ce(P);Le(S,V.models)},[Le,ce]),Se=o.useCallback(async(S,N,P)=>{if(!N.recordId)throw new Error("This model cannot be edited.");const V=await $e(`/api/providers/${S}/models/${N.recordId}`,{method:"PATCH",body:JSON.stringify(P)}),X=await ce(V);Le(S,X.models),ie[S]===N.value&&M(S,X.model.value),i===S&&ue===N.value&&ae(se=>se&&{...se,model:X.model.value})},[Le,i,ie,ce,ue,M]),Ie=o.useCallback(async(S,N)=>{if(!N.recordId)throw new Error("This model cannot be deleted.");const P=await $e(`/api/providers/${S}/models/${N.recordId}`,{method:"DELETE"}),V=await ce(P);Le(S,V.models),ie[S]===N.value&&M(S,V.models.DEFAULT),i===S&&ue===N.value&&ae(X=>X&&{...X,model:V.models.DEFAULT})},[Le,i,ie,ce,ue,M]),et=o.useMemo(()=>({create:Re,update:Se,remove:Ie}),[Re,Ie,Se]);return{provider:i,setProvider:c,cursorModel:d,setCursorModel:u,claudeModel:h,setClaudeModel:j,codexModel:g,setCodexModel:y,currentProviderEffort:de,currentProviderEffortOptions:ge,currentProviderModel:Ae,currentProviderModelOptions:We,opencodeModel:T,setOpenCodeModel:w,piModel:$,setPiModel:f,permissionMode:s,setPermissionMode:a,pendingPermissionRequests:n,setPendingPermissionRequests:l,availablePermissionModes:Me,selectPermissionMode:me,cyclePermissionMode:Z,providerModelCatalog:p,providerModelsLoading:I,providerModelActions:et,selectProviderModel:Te,selectProviderEffort:Ee,resolvePermissionModeForProvider:xe}}const bt=20;function zo(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 Wo(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):bt;return{offset:r.length+n,limit:c}}function Ko(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 Go(e,r,s,a){return{offset:r,hasMore:(e===0||s)&&a}}function Jo(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 Qo=(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},Yo=()=>{const e=new Map;return(r,s)=>{const a=JSON.stringify([r,s]),n=e.get(a);if(n)return n;const l=Qo(r,s);if(e.set(a,l),e.size>100){const i=e.keys().next().value;i&&e.delete(i)}return l}};function Xo(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 Zo(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),h=d%60,j=`GMT${c}${u}${h?":"+String(h).padStart(2,"0"):""}`,C=((Intl.DateTimeFormat().resolvedOptions().timeZone||"").split("/").pop()||"").replace(/_/g," ").toLowerCase().replace(/\b\w/g,$=>$.toUpperCase()),k=C?`${j} (${C})`:j,T=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],w=`${n.getDate()} ${T[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 el(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 tl(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=el(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 h of n.subagentTools)d.push({toolId:h.toolId,toolName:h.toolName,toolInput:h.toolInput,toolResult:h.toolResult||null,timestamp:new Date(h.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 Pt=100,rl=[];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 sl({isActive:e,selectedProject:r,selectedSession:s,ws:a,sendMessage:n,externalMessageUpdate:l,newSessionTrigger:i,processingSessions:c,onSessionIdle:d,resetStreamingState:u,statusCheckSentAtRef:h,lastSeqRef:j,sessionStore:g}){const[y,C]=o.useState(s?.id||null),[k,T]=o.useState(!1),[w,$]=o.useState(!1),[f,x]=o.useState(!1),[m,p]=o.useState(0),[b,I]=o.useState(!1),[E,v]=o.useState(null),[A,D]=o.useState(Pt),[q,M]=o.useState(!1),[F,R]=o.useState(!1),[U,W]=o.useState(!1),[B,O]=o.useState(!1),[z,le]=o.useState(0),oe=o.useRef(null),fe=o.useRef(!1),[ie,me]=o.useState(null),Z=o.useRef(!1),Me=o.useRef(!1),xe=o.useRef(!1),K=o.useRef(!1),ae=o.useRef(null),te=o.useRef(!0),be=o.useRef(0),Fe=o.useRef({height:0,top:0}),he=o.useRef(null),J=o.useRef(null),ue=o.useRef(null),Te=o.useRef(0),Ee=o.useRef(i??0),Ae=o.useMemo(()=>Yo(),[]);o.useEffect(()=>{const L=i??0;L!==Ee.current&&(Ee.current=L,u(),C(null),V(null),be.current=0,x(!1),p(0),v(null),D(Pt),M(!1),xe.current=!1,R(!1),W(!1),O(!1),le(0),me(null),fe.current=!1,Z.current=!1,K.current=!1,ae.current=null,te.current=!0,ue.current=null,J.current&&(clearTimeout(J.current),J.current=null),he.current&&(clearTimeout(he.current),he.current=null))},[i,d,u]);const ge=s?.id??null,de=ge||y||null,We=de&&c?.get(de)||null,Le=We!==null,ce=Le&&We.canInterrupt,Re=o.useRef(c);Re.current=c;const Se=o.useRef(e),Ie=o.useRef(de);Se.current=e,Ie.current=de;const et=o.useRef(async()=>!0);et.current=async L=>{const G=await g.refreshLatestFromServer(L,{limit:bt,canRequest:()=>Se.current&&Ie.current===L}),ee=G.slot;return ee&&Ie.current===L&&(x(ee.hasMore),p(ee.total),be.current=ee.offset,ee.tokenUsage!==void 0&&v(ee.tokenUsage??null)),!G.deferred};const S=o.useRef(null);S.current||(S.current=Jo(L=>et.current(L),L=>Se.current&&Ie.current===L));const N=o.useCallback((L,G=Se.current)=>S.current?.request(L,G)??Promise.resolve(),[]),[P,V]=o.useState(null),X=o.useRef(null),se=e?de:null,Ne=o.useRef(null);se!==Ne.current&&(Ne.current=se,g.setActiveSession(se)),o.useEffect(()=>{if(!P){X.current=null;return}if(!de||X.current===P)return;const L=localStorage.getItem("selected-provider")||"claude",G=ts(P,de,L);G&&g.appendRealtime(de,G),X.current=P,V(null)},[de,P,g]);const we=de?g.getMessages(de):rl,ye=o.useRef(0);we.length!==ye.current&&(ye.current=we.length,z>0&&le(0));const pe=o.useMemo(()=>{const L=tl(we);return P&&L.length===0?[P]:z>0&&z<L.length?L.slice(0,-z):L},[we,z,P]),tt=o.useCallback(L=>{if(!de){V(L);return}const G=localStorage.getItem("selected-provider")||"claude",ee=ts(L,de,G);ee&&g.appendRealtime(de,ee)},[de,g]),ut=o.useCallback(()=>{de&&g.clearRealtime(de)},[de,g]),yt=o.useCallback(L=>le(L),[]),Ue=o.useCallback(()=>{const L=oe.current;L&&(L.scrollTop=L.scrollHeight)},[]),rt=o.useCallback(()=>{Ue(),q&&(D(Pt),M(!1),xe.current=!1)},[q,Ue]),Qe=o.useCallback(()=>{const L=oe.current;if(!L)return!1;const{scrollTop:G,scrollHeight:ee,clientHeight:ne}=L;return ee-G-ne<50},[]),Ke=o.useCallback(async L=>{if(!e||!L||Me.current||w||xe.current||!f||!s||!r)return!1;Me.current=!0,$(!0);const G=es(L);try{const ee=await g.fetchMore(s.id,{limit:bt,canRequest:()=>Se.current&&Ie.current===s.id}),{slot:ne,prependedCount:ve}=ee;return x(ne.hasMore),p(ne.total),be.current=ne.offset,ne.tokenUsage!==void 0&&v(ne.tokenUsage??null),ve===0?(ne.hasMore||(xe.current=!0,M(!0),J.current&&(clearTimeout(J.current),J.current=null),O(!1)),!1):(ae.current=G,D(Ce=>Ce+bt),ne.hasMore||(xe.current=!0,M(!0),J.current&&(clearTimeout(J.current),J.current=null),O(!1)),!0)}finally{Me.current=!1,$(!1)}},[f,e,w,r,s,g]),Q=o.useCallback(async()=>{if(!e)return;const L=oe.current;if(!L)return;const G=Qe();I(!G),Fe.current={height:L.scrollHeight,top:L.scrollTop};const ee=L.scrollTop<100;if(ee&&f&&!xe.current?fe.current||(fe.current=!0,J.current&&clearTimeout(J.current),O(!0),J.current=setTimeout(()=>{O(!1),J.current=null},2500)):ee||(fe.current=!1),!xe.current){if(!ee){K.current=!1;return}if(K.current){L.scrollTop>20&&(K.current=!1);return}await Ke(L)&&(K.current=!0)}},[f,e,Qe,Ke]),Oe=o.useRef(e);o.useLayoutEffect(()=>{const L=e&&!Oe.current;if(Oe.current=e,!e||!oe.current)return;const G=oe.current;if(ae.current){const{height:ee,top:ne,anchor:ve,anchorOffset:Ce}=ae.current;if(ve?.isConnected&&Ce!==null){const Be=ve.getBoundingClientRect().top-G.getBoundingClientRect().top;G.scrollTop+=Be-Ce}else G.scrollTop=ne+Math.max(G.scrollHeight-ee,0);ae.current=null;return}L&&(G.scrollTop=b?Fe.current.top:G.scrollHeight)},[pe.length,e,b]),o.useEffect(()=>{Z.current||(te.current=!0,D(Pt)),K.current=!1,ae.current=null,fe.current=!1,I(!1)},[r?.projectId,s?.id]),o.useEffect(()=>{if(!e||!te.current||!oe.current||k)return;if(pe.length===0){te.current=!1;return}if(Z.current){te.current=!1;return}const L=oe.current;let G=0,ee=0,ne=0,ve=0;const Ce=()=>{!te.current||!oe.current||(L.scrollTop=L.scrollHeight,L.scrollHeight===ee?ne++:(ne=0,ee=L.scrollHeight),G++,ne<3&&G<60?ve=requestAnimationFrame(Ce):te.current=!1)};return ve=requestAnimationFrame(Ce),()=>{ve&&cancelAnimationFrame(ve)}},[pe.length,e,k,Ue]),o.useEffect(()=>{!s||!r||!a||(h.current.set(s.id,Date.now()),n({type:"chat.subscribe",sessions:[{sessionId:s.id,lastSeq:j.current.get(s.id)??0}]}))},[j,r,s,n,h,a]),o.useEffect(()=>{if(!ge||!r){if(y&&Re.current?.has(y))return;u(),C(null),be.current=0,x(!1),p(0),v(null),ue.current=null,Te.current+=1,T(!1);return}if(!e){T(!1);return}const L=`${ge}:${r.projectId}`,G=g.getSessionSlot(ge),ee=ue.current===L&&G?.status==="loading",ne=ue.current===L&&!!G?.fetchedAt;if(ee)return;if(ne){g.isStale(ge)&&N(ge);return}const ve=y!==null&&y!==ge;ve&&u(),be.current=0,x(!1),p(0),D(Pt),M(!1),xe.current=!1,R(!1),W(!1),O(!1),le(0),fe.current=!1,J.current&&clearTimeout(J.current),he.current&&clearTimeout(he.current),ve&&v(null),C(ge),ue.current=L;const Ce=++Te.current;T(!0),g.fetchFromServer(ge,{limit:bt,offset:0,canRequest:()=>Se.current&&Ie.current===ge}).then(Be=>{Te.current!==Ce||Ie.current!==ge||Be&&(x(Be.hasMore),p(Be.total),be.current=Be.offset,Be.tokenUsage!==void 0&&v(Be.tokenUsage??null))}).catch(()=>{}).finally(()=>{Te.current===Ce&&Ie.current===ge&&T(!1)})},[e,y,u,N,r,ge,g]),o.useEffect(()=>{if(!e||!de)return;const L=g.getSessionSlot(de);if(!L?.fetchedAt||L.status==="loading"){S.current?.discardPending(de);return}S.current?.flushPending(de)},[de,e,g]),o.useEffect(()=>{if(!l||!s||!r)return;(async()=>{try{if(!Le){const G=Se.current&&Qe();await N(s.id),G&&setTimeout(()=>Ue(),200)}}catch(G){console.error("Error reloading messages from external update:",G)}})()},[l,Qe,N,Ue,r,s,Le]),o.useEffect(()=>{const L=s,G=L?.__searchTargetSnippet,ee=L?.__searchTargetTimestamp;typeof G=="string"&&G&&(Z.current=!0,me({snippet:G,timestamp:typeof ee=="string"?ee:void 0}))},[s]),o.useEffect(()=>{if(!e||!ie||pe.length===0||k)return;const L=ie;me(null),(async()=>{if(!xe.current&&s&&r)try{const ne=await g.fetchFromServer(s.id,{limit:null,offset:0,canRequest:()=>Se.current&&Ie.current===s.id});if(ne)x(!1),p(ne.total),be.current=ne.offset,D(1/0),M(!0),xe.current=!0,await new Promise(ve=>setTimeout(ve,300));else if(!Se.current){me(L);return}}catch{}D(1/0);const ee=ne=>{const ve=oe.current;if(!ve)return;let Ce=null;if(L.snippet){const pt=L.snippet.replace(/^\.{3}/,"").replace(/\.{3}$/,"").trim().slice(0,80).toLowerCase().trim();if(pt.length>=10){const ft=ve.querySelectorAll(".chat-message");for(const lt of ft)if((lt.textContent||"").toLowerCase().includes(pt)){Ce=lt;break}}}if(!Ce&&L.timestamp){const Be=new Date(L.timestamp).getTime(),pt=ve.querySelectorAll("[data-message-timestamp]");let ft=1/0;for(const lt of pt){const kt=lt.getAttribute("data-message-timestamp");if(!kt)continue;const _=Math.abs(new Date(kt).getTime()-Be);_<ft&&(ft=_,Ce=lt)}}Ce?(Ce.scrollIntoView({block:"center",behavior:"smooth"}),Ce.classList.add("search-highlight-flash"),setTimeout(()=>Ce?.classList.remove("search-highlight-flash"),4e3),Z.current=!1):ne>0?setTimeout(()=>ee(ne-1),200):Z.current=!1};setTimeout(()=>ee(15),150)})()},[pe.length,e,k,ie]),o.useEffect(()=>{if(!s?.id){v(null);return}let L=!1;return(async()=>{try{const ee=`/api/providers/sessions/${encodeURIComponent(s.id)}/token-usage`,ne=await $e(ee);if(L)return;if(ne.ok){const ve=await ne.json();if(L)return;v(ve.data??null)}else v(null)}catch(ee){L||console.error("Failed to fetch initial token usage:",ee)}})(),()=>{L=!0}},[s?.id]);const _e=o.useMemo(()=>pe.length<=A?pe:pe.slice(-A),[pe,A]);o.useEffect(()=>{if(!e)return;const L=oe.current;L&&(Fe.current={height:L.scrollHeight,top:L.scrollTop})}),o.useEffect(()=>{e&&(!oe.current||pe.length===0||Me.current||w||ae.current||Z.current||b||setTimeout(()=>Ue(),50))},[pe.length,e,w,b,Ue]),o.useEffect(()=>{const L=oe.current;if(L)return L.addEventListener("scroll",Q),()=>L.removeEventListener("scroll",Q)},[Q]);const mt=o.useCallback(async()=>{if(!e||!s||!r||F)return;const L=s.id;xe.current=!0,Me.current=!0,R(!0),O(!0),J.current&&(clearTimeout(J.current),J.current=null);const G=oe.current,ee=G?es(G):null;try{const ne=await g.fetchFromServer(L,{limit:null,offset:0,canRequest:()=>Se.current&&Ie.current===L});if(y!==L)return;ne?(ee&&(ae.current=ee),x(!1),p(ne.total),be.current=ne.offset,D(1/0),M(!0),W(!0),he.current&&clearTimeout(he.current),he.current=setTimeout(()=>{W(!1),O(!1),he.current=null},2500)):(xe.current=!1,O(!1))}catch(ne){console.error("Error loading all messages:",ne),xe.current=!1,O(!1)}finally{Me.current=!1,R(!1)}},[e,s,r,F,y,g]),ot=o.useCallback(()=>{D(L=>L+100)},[]);return{chatMessages:pe,addMessage:tt,clearMessages:ut,rewindMessages:yt,sessionActivity:We,isProcessing:Le,canAbortSession:ce,currentSessionId:y,setCurrentSessionId:C,isLoadingSessionMessages:k,isLoadingMoreMessages:w,hasMoreMessages:f,totalMessages:m,isUserScrolledUp:b,setIsUserScrolledUp:I,tokenBudget:E,setTokenBudget:v,visibleMessageCount:A,visibleMessages:_e,loadEarlierMessages:ot,loadAllMessages:mt,allMessagesLoaded:q,isLoadingAllMessages:F,loadAllJustFinished:U,showLoadAllOverlay:B,createDiff:Ae,scrollContainerRef:oe,scrollToBottom:Ue,scrollToBottomAndReset:rt,isNearBottom:Qe,handleScroll:Q,requestLatestMessages:N}}const nl="[Done]",al=2e3;let Ze=null,Lt=!1;const _r=()=>`${nl} `,rn=e=>{const r=_r();return e.startsWith(r)?e.slice(r.length):e},sn=()=>document.visibilityState==="visible"&&document.hasFocus(),ol=()=>{!Lt||typeof window>"u"||(document.removeEventListener("visibilitychange",it),window.removeEventListener("focus",it,!0),window.removeEventListener("click",it,!0),Lt=!1)},ll=()=>{Ze!==null&&(window.clearTimeout(Ze),Ze=null),ol(),nn(),document.title.startsWith(_r())&&(document.title=rn(document.title))},nn=()=>{document.removeEventListener("visibilitychange",on)},an=()=>{Ze!==null&&window.clearTimeout(Ze),Ze=window.setTimeout(()=>{ll()},al),nn(),document.addEventListener("visibilitychange",on,{once:!0})};function it(){sn()&&an()}function on(){document.visibilityState==="hidden"&&(Ze!==null&&(window.clearTimeout(Ze),Ze=null),Lt||(document.addEventListener("visibilitychange",it),window.addEventListener("focus",it,!0),window.addEventListener("click",it,!0),Lt=!0))}const il=()=>{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",it),window.addEventListener("focus",it,!0),window.addEventListener("click",it,!0),Lt=!0)},ln=e=>e?.toolName!=="ExitPlanMode"&&e?.toolName!=="exit_plan_mode",rs=e=>Array.isArray(e)&&e.some(r=>ln(r));function cl({isActive:e,subscribe:r,provider:s,selectedSession:a,currentSessionId:n,setTokenBudget:l,pendingPermissionRequests:i,setPendingPermissionRequests:c,streamTimerRef:d,accumulatedStreamRef:u,lastSeqRef:h,statusCheckSentAtRef:j,onSessionProcessing:g,onSessionIdle:y,onWebSocketReconnect:C,requestLatestMessages:k,sessionStore:T}){const w=o.useRef(a?.id||n||null);w.current=a?.id||n||null;const $=o.useRef(e);$.current=e;const f=o.useRef(i);o.useEffect(()=>{f.current=i},[i]),o.useEffect(()=>r(m=>{if(!m.kind)return;const p=w.current,b=typeof m.sessionId=="string"&&m.sessionId||p;if(b&&typeof m.seq=="number"){const E=h.current.get(b)??0;m.seq>E&&h.current.set(b,m.seq)}switch(m.kind){case"websocket_reconnected":C?.();return;case"chat_subscribed":{if(!b)return;if(m.isProcessing?g?.(b):y?.(b,{ifStartedBefore:j.current.get(b)}),b===p&&Array.isArray(m.pendingPermissions)){const v=m.pendingPermissions,A=rs(f.current),D=rs(v);f.current=v,c(v),D&&!A&&Br()}return}case"protocol_error":{console.error("[Chat] Protocol error:",m.code,m.error),b&&(y?.(b),T.appendRealtime(b,{id:`protocol_error_${Date.now()}`,sessionId:b,timestamp:new Date().toISOString(),provider:s,kind:"error",content:String(m.error||"Request failed")}));return}case"session_upserted":case"loading_progress":return}if(m.kind==="stream_delta"){const E=m.content||"";if(!E)return;u.current+=E,d.current||(d.current=window.setTimeout(()=>{d.current=null,b&&T.updateStreaming(b,u.current,s)},100)),b&&b!==p&&T.appendRealtime(b,m);return}if(m.kind==="stream_end"){d.current&&(clearTimeout(d.current),d.current=null),b&&(u.current&&T.updateStreaming(b,u.current,s),T.finalizeStreaming(b)),u.current="";return}const I=m.kind!=="complete"&&m.kind!=="status"&&m.kind!=="permission_request"&&m.kind!=="permission_cancelled";switch(b&&I&&T.appendRealtime(b,m),m.kind){case"complete":{if(d.current&&(clearTimeout(d.current),d.current=null),b&&u.current&&(T.updateStreaming(b,u.current,s),T.finalizeStreaming(b)),u.current="",y?.(b),b===p&&(f.current=[],c([])),m.aborted)break;m.success!==!1&&(il(),Xn()),b&&b===p&&k(b,$.current);break}case"permission_request":{if(!m.requestId)break;if(ln({toolName:m.toolName})&&Br(),b===p){const E=f.current;if(!E.some(v=>v.requestId===m.requestId)){const v=[...E,{requestId:m.requestId,toolName:m.toolName||"UnknownTool",provider:m.provider,input:m.input,context:m.context,sessionId:b||null,receivedAt:new Date}];f.current=v,c(v)}}b&&g?.(b);break}case"permission_cancelled":{if(m.requestId&&b===p){const E=f.current.filter(v=>v.requestId!==m.requestId);f.current=E,c(E)}break}case"status":{m.text==="token_budget"&&m.tokenBudget?l(m.tokenBudget):m.text&&b&&g?.(b,{statusText:m.text,canInterrupt:m.canInterrupt!==!1});break}}}),[r,s,a,n,l,i,c,d,u,h,j,g,y,C,k,T])}const cn="claude-settings",Je={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=Je.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){Je.setItem(Dr(e),JSON.stringify(r))}function ns(e){Je.removeItem(Dr(e))}function un(){const e=Je.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 dl(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 Je.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 ul({selectedProject:e,input:r,setInput:s,textareaRef:a}){const[n,l]=o.useState([]),[i,c]=o.useState([]),[d,u]=o.useState([]),[h,j]=o.useState(!1),[g,y]=o.useState(-1),[C,k]=o.useState(0),[T,w]=o.useState(-1);o.useEffect(()=>{const E=new AbortController;return(async()=>{const A=e?.projectId;if(l([]),u([]),!!A)try{const D=await jr.getMentionableFiles(A,{signal:E.signal});if(!D.ok)return;const q=await D.json();l(mn(q))}catch(D){if(D?.name==="AbortError")return;console.error("Error fetching files:",D)}})(),()=>{E.abort()}},[e?.projectId]),o.useEffect(()=>{const E=r.slice(0,C),v=E.lastIndexOf("@");if(v===-1){j(!1),w(-1);return}const A=E.slice(v+1);if(A.includes(" ")){j(!1),w(-1);return}w(v),j(!0),y(-1);const D=n.filter(q=>q.name.toLowerCase().includes(A.toLowerCase())||q.path.toLowerCase().includes(A.toLowerCase())).slice(0,10);u(D)},[r,C,n]);const $=o.useMemo(()=>!r||i.length===0?[]:i.filter(E=>r.includes(E)),[i,r]),f=o.useMemo(()=>$.length===0?[]:Array.from(new Set($)).sort((v,A)=>A.length-v.length),[$]),x=o.useMemo(()=>{if(f.length===0)return null;const E=f.map(tn).join("|");return new RegExp(`(${E})`,"g")},[f]),m=o.useMemo(()=>new Set(f),[f]),p=o.useCallback(E=>E?x?E.split(x).map((A,D)=>m.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-${D}`):t.jsx("span",{children:A},`text-${D}`)):E:"",[x,m]),b=o.useCallback(E=>{const v=r.slice(0,T),A=r.slice(T),D=A.indexOf(" "),q=D!==-1?A.slice(D):"",M=`${v}${E.path} ${q}`,F=v.length+E.path.length+1;a.current&&!a.current.matches(":focus")&&a.current.focus(),s(M),k(F),c(R=>R.includes(E.path)?R:[...R,E.path]),j(!1),w(-1),a.current&&requestAnimationFrame(()=>{a.current&&(a.current.setSelectionRange(F,F),a.current.matches(":focus")||a.current.focus())})},[r,T,a,s]),I=o.useCallback(E=>!h||d.length===0?!1:E.key==="ArrowDown"?(E.preventDefault(),y(v=>v<d.length-1?v+1:0),!0):E.key==="ArrowUp"?(E.preventDefault(),y(v=>v>0?v-1:d.length-1),!0):E.key==="Tab"||E.key==="Enter"?(E.preventDefault(),g>=0?b(d[g]):d.length>0&&b(d[0]),!0):E.key==="Escape"?(E.preventDefault(),j(!1),!0):!1,[h,d,g,b]);return{showFileDropdown:h,filteredFiles:d,selectedFileIndex:g,renderInputWithMentions:p,selectFile:b,setCursorPosition:k,handleFileMentionsKeyDown:I}}const ml=150,pn=e=>`command_history_${e}`,xr=e=>{const r=Je.getItem(pn(e));if(!r)return{};try{return JSON.parse(r)}catch(s){return console.error("Error parsing command history:",s),{}}},pl=(e,r)=>{Je.setItem(pn(e),JSON.stringify(r))},fl=e=>!!e&&typeof e.then=="function",xl=e=>e.type==="skill"||e.metadata?.type==="skill",ls=e=>xl(e)||e.metadata?.passthrough===!0,hl=e=>{const r=new Set;return e.filter(s=>{const a=s.command;return r.has(a)?!1:(r.add(a),!0)})},gl=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}}),bl=(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 yl({selectedProject:e,provider:r,input:s,setInput:a,textareaRef:n,onExecuteCommand:l}){const[i,c]=o.useState([]),[d,u]=o.useState([]),[h,j]=o.useState(!1),[g,y]=o.useState(""),[C,k]=o.useState(-1),[T,w]=o.useState(-1),$=o.useRef(null),f=o.useCallback(()=>{$.current!==null&&(window.clearTimeout($.current),$.current=null)},[]),x=o.useCallback(()=>{j(!1),w(-1),y(""),k(-1),f()},[f]);o.useEffect(()=>{let M=!1;return(async()=>{if(!e){c([]),u([]);return}try{const R=e.fullPath||e.path||"",U=await $e("/api/commands/list",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectPath:R||e.path,provider:r})});if(!U.ok)throw new Error("Failed to fetch commands");const W=await U.json(),B=new URLSearchParams;R&&B.set("workspacePath",R);const O=await $e(`/api/providers/${encodeURIComponent(r)}/skills${B.toString()?`?${B.toString()}`:""}`),z=O.ok?await O.json():null,le=hl(z?.data?.skills||[]).map(gl),oe=[...(W.builtIn||[]).map(me=>({...me,type:"built-in"})),...le,...(W.custom||[]).map(me=>({...me,type:"custom"}))],fe=xr(e.projectId),ie=[...oe].sort((me,Z)=>{const Me=fe[me.name]||0;return(fe[Z.name]||0)-Me});M||c(ie)}catch(R){console.error("Error fetching slash commands:",R),M||c([])}})(),()=>{M=!0}},[e,r]),o.useEffect(()=>{h||k(-1)},[h]),o.useEffect(()=>{u(bl(i,g))},[g,i]);const m=o.useMemo(()=>{if(!e||i.length===0)return[];const M=xr(e.projectId);return i.map(F=>({...F,usageCount:M[F.name]||0})).filter(F=>F.usageCount>0).sort((F,R)=>R.usageCount-F.usageCount).slice(0,5)},[e,i]),p=o.useCallback(M=>{if(!e)return;const F=xr(e.projectId);F[M.name]=(F[M.name]||0)+1,pl(e.projectId,F)},[e]),b=o.useCallback(M=>{const F=n.current,R=T>=0?T:F?.selectionStart??s.length,U=s.slice(0,R),W=s.slice(R),B=W.indexOf(" "),O=T>=0&&B!==-1?W.slice(B).trimStart():s.slice(F?.selectionEnd??R),z=U&&!/\s$/.test(U)?" ":"",le=`${U}${z}${M.name}${O?` ${O}`:" "}`;a(le),x(),window.requestAnimationFrame(()=>{F?.focus();const oe=`${U}${z}${M.name} `.length;F?.setSelectionRange(oe,oe)})},[s,x,a,T,n]),I=o.useCallback(M=>{const F=l(M);fl(F)?F.then(()=>{x()},()=>{x()}):x()},[l,x]),E=o.useCallback(M=>{if(ls(M)){b(M);return}I(M)},[I,b]),v=o.useCallback((M,F,R)=>{if(!(!M||!e)){if(R){k(F);return}if(p(M),ls(M)){b(M);return}I(M)}},[e,p,b,I]),A=o.useCallback(()=>{const M=!h;j(M),y(""),k(-1),M&&u(i),n.current?.focus()},[h,i,n]),D=o.useCallback((M,F)=>{if(!M.trim()){x();return}const R=M.slice(0,F);if((R.match(/```/g)||[]).length%2===1){x();return}const B=/(?:^|\s)(\/\S*)$/,O=R.match(B);if(!O){x();return}const z=O.index+(O[0].length-O[1].length),le=O[1].slice(1);w(z),j(!0),k(-1),f(),$.current=window.setTimeout(()=>{y(le)},ml)},[x,f]),q=o.useCallback(M=>h?d.length?M.key==="ArrowDown"?(M.preventDefault(),k(F=>F<d.length-1?F+1:0),!0):M.key==="ArrowUp"?(M.preventDefault(),k(F=>F>0?F-1:d.length-1),!0):M.key==="Tab"||M.key==="Enter"?(M.preventDefault(),C>=0?E(d[C]):d.length>0&&E(d[0]),!0):M.key==="Escape"?(M.preventDefault(),x(),!0):!1:M.key==="Escape"?(M.preventDefault(),x(),!0):!1:!1,[h,d,x,E,C]);return o.useEffect(()=>()=>{f()},[f]),{slashCommands:i,slashCommandsCount:i.length,filteredCommands:d,frequentCommands:m,commandQuery:g,showCommandMenu:h,selectedCommandIndex:C,resetCommandMenuState:x,handleCommandSelect:v,handleToggleCommandMenu:A,handleCommandInputChange:D,handleCommandMenuKeyDown:q}}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 kl({selectedProject:e,selectedSession:r,currentSessionId:s,provider:a,permissionMode:n,cyclePermissionMode:l,resolvePermissionModeForProvider:i,currentProviderModel:c,currentProviderEffort:d,isLoading:u,processingSessions:h,canAbortSession:j,tokenBudget:g,sendMessage:y,sendByCtrlEnter:C,onSessionProcessing:k,onSessionEstablished:T,onInputFocusChange:w,onFileOpen:$,onShowSettings:f,scrollToBottom:x,addMessage:m,setIsUserScrolledUp:p,setPendingPermissionRequests:b}){const[I,E]=o.useState(()=>typeof window<"u"&&e&&Je.getItem(`draft_input_${e.projectId}`)||""),[v,A]=o.useState([]),[D,q]=o.useState(new Map),[M,F]=o.useState(new Map),[R,U]=o.useState(!1),[W,B]=o.useState(null),O=o.useRef(null),z=o.useRef(null),le=o.useRef(null),oe=o.useRef(null),fe=o.useRef(null),ie=o.useRef(I),me=e?.projectId,Z=r?.id||s||null,Me=o.useRef(Z),xe=o.useRef(h);Me.current=Z,xe.current=h;const[K,ae]=o.useState(()=>typeof window>"u"||!Z?null:ms(Z)),te=o.useRef(Z),be=o.useCallback(_=>{const{action:Y,data:H}=_;switch(Y){case"help":B({kind:"help",data:H||{}});break;case"models":B({kind:"models",data:H||{}});break;case"cost":{B({kind:"cost",data:H||{}});break}case"status":{B({kind:"status",data:H||{}});break}case"memory":H.error?m({type:"assistant",content:`Warning: ${H.message}`,timestamp:Date.now()}):(m({type:"assistant",content:`${H.message}
|
|
5
|
+
|
|
6
|
+
Path: \`${H.path}\``,timestamp:Date.now()}),H.exists&&$&&$(H.path));break;case"config":f?.();break;default:console.warn("Unknown built-in command action:",Y)}},[$,f,m]),Fe=o.useCallback(()=>{B(null)},[]),he=o.useCallback(async _=>{const{content:Y,hasBashCommands:H}=_;if(H&&!window.confirm("This command contains bash commands that will be executed. Do you want to proceed?")){m({type:"assistant",content:"Command execution cancelled",timestamp:Date.now()});return}const re=Y||"";E(re),ie.current=re,setTimeout(()=>{fe.current&&fe.current(hr())},0)},[m]),J=o.useCallback(async(_,Y,H)=>{if(!(!_||!e))try{const ke=(Y??I).match(new RegExp(`${tn(_.name)}\\s*(.*)`)),qe=ke&&ke[1]?ke[1].trim().split(/\s+/):[],wt={projectPath:e.fullPath||e.path,projectId:e.projectId,sessionId:s||r?.id||null,provider:a,model:c,tokenUsage:g},at=await $e("/api/commands/execute",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commandName:_.name,commandPath:_.path,args:qe,context:wt})});if(!at.ok){let vt=`Failed to execute command (${at.status})`;try{const Nt=await at.json();vt=Nt?.message||Nt?.error||vt}catch{}throw new Error(vt)}const st=await at.json();st.type==="builtin"?(be(st),H?.preserveInput||(E(""),ie.current="")):st.type==="custom"&&await he(st)}catch(re){const ke=re instanceof Error?re.message:"Unknown error";console.error("Error executing command:",re),m({type:"assistant",content:`Error executing command: ${ke}`,timestamp:Date.now()})}},[c,s,be,he,I,a,e,r?.id,m,g]),ue=o.useCallback(()=>{J({name:"/cost",description:"Display token usage information",namespace:"builtin",metadata:{type:"builtin"}},"/cost",{preserveInput:!0})},[J]),{slashCommands:Te,slashCommandsCount:Ee,filteredCommands:Ae,frequentCommands:ge,commandQuery:de,showCommandMenu:We,selectedCommandIndex:Le,resetCommandMenuState:ce,handleCommandSelect:Re,handleToggleCommandMenu:Se,handleCommandInputChange:Ie,handleCommandMenuKeyDown:et}=yl({selectedProject:e,provider:a,input:I,setInput:E,textareaRef:O,onExecuteCommand:J}),{showFileDropdown:S,filteredFiles:N,selectedFileIndex:P,renderInputWithMentions:V,selectFile:X,setCursorPosition:se,handleFileMentionsKeyDown:Ne}=ul({selectedProject:e,input:I,setInput:E,textareaRef:O}),we=o.useCallback(_=>{!z.current||!_||(z.current.scrollTop=_.scrollTop,z.current.scrollLeft=_.scrollLeft)},[]),ye=o.useCallback(_=>{_.style.height="auto";const Y=Math.max(22,_.scrollHeight);_.style.height=`${Y}px`;let H=le.current;H||(H=parseInt(window.getComputedStyle(_).lineHeight),le.current=Number.isFinite(H)?H:24);const re=Y>(le.current||24)*2;U(ke=>ke===re?ke:re),oe.current=_.value},[]),pe=o.useCallback(_=>{const Y=_.filter(H=>{try{if(!H||typeof H!="object")return console.warn("Invalid file object:",H),!1;if(H.size>cs){const re=H.name||"Unknown file";return F(ke=>{const qe=new Map(ke);return qe.set(re,"File too large (max 10MB)"),qe}),!1}return!0}catch(re){return console.error("Error validating file:",re,H),!1}});Y.length>0&&A(H=>[...H,...Y].slice(0,is))},[]),tt=o.useCallback(_=>{const Y=Array.from(_.clipboardData.items);if(Y.forEach(H=>{if(!H.type.startsWith("image/"))return;const re=H.getAsFile();re&&pe([re])}),Y.length===0&&_.clipboardData.files.length>0){const re=Array.from(_.clipboardData.files).filter(ke=>ke.type.startsWith("image/"));re.length>0&&pe(re)}},[pe]),{getRootProps:ut,getInputProps:yt,isDragActive:Ue,open:rt}=Ma({maxSize:cs,maxFiles:is,onDrop:pe,noClick:!0,noKeyboard:!0}),Qe=o.useCallback(_=>{const H=(()=>{try{const re=a==="cursor"?"cursor-tools-settings":a==="codex"?"codex-settings":a==="opencode"?"opencode-settings":"claude-settings",ke=Je.getItem(re);if(ke)return JSON.parse(ke)}catch(re){console.error("Error loading tools settings:",re)}return{allowedTools:[],disallowedTools:[],skipPermissions:!1}})();return{model:c,effort:d,permissionMode:i(a,n),toolsSettings:H,skipPermissions:H?.skipPermissions||!1,sessionSummary:ps(r,_)}},[d,c,n,a,i,r]),Ke=o.useCallback(async(_,Y)=>{_.preventDefault();const H=Y?.content??ie.current,re=Y?.attachments??v,ke=Y?.uploadedAttachments??[];if(!H.trim()&&re.length===0&&ke.length===0||!e)return;if(u){if(Y){te.current=Z,ae(Y);return}const Ve=Qe(H),je=Z;let He=[];try{He=await us(re)}catch(At){const dr=At instanceof Error?At.message:"Unknown error";console.error("Queued file upload failed:",At),m({type:"error",content:`Failed to upload files: ${dr}`,timestamp:new Date});return}const Ge={content:H,attachments:re,uploadedAttachments:He,options:Ve};if(je&&ss(je,{content:Ge.content,options:Ge.options,attachments:Ge.uploadedAttachments}),je&&Me.current!==je){xe.current&&!xe.current.has(je)&&(ns(je),y({type:"chat.send",sessionId:je,content:Ge.content,options:{...Ge.options??{},attachments:Ge.uploadedAttachments??[]}}),k?.(je,{statusText:null,canInterrupt:!0}));return}te.current=je,ae(Ge),E(""),ie.current="",A([]),q(new Map),F(new Map),ce(),U(!1),O.current&&(O.current.style.height="auto"),Je.removeItem(`draft_input_${e.projectId}`);return}const qe=H.trimEnd(),wt=qe.trim().toLowerCase()==="help";if(qe.startsWith("/")||wt){const Ve=qe.indexOf(" "),je=wt?"/help":Ve>0?qe.slice(0,Ve):qe,He=Te.find(Ge=>Ge.name===je)||(je==="/help"?{name:"/help",description:"Show help documentation for Claude Code",namespace:"builtin",metadata:{type:"builtin"}}:void 0);if(He&&He.type!=="skill"&&He.metadata?.passthrough!==!0){J(He,wt?"/help":qe),E(""),ie.current="",A([]),q(new Map),F(new Map),ce(),U(!1),O.current&&(O.current.style.height="auto");return}}const at=H;let st=ke;if(st.length===0&&re.length>0)try{st=await us(re)}catch(Ve){const je=Ve instanceof Error?Ve.message:"Unknown error";console.error("File upload failed:",Ve),m({type:"error",content:`Failed to upload files: ${je}`,timestamp:new Date});return}const vt=e.fullPath||e.path||"",Nt=ps(r,H);let xt=r?.id||s||null;if(!xt){let Ve=Nt;try{const je=await $e("/api/providers/sessions",{method:"POST",body:JSON.stringify({provider:a,projectPath:vt,initialMessage:at})});if(!je.ok)throw new Error(`Failed to create session (${je.status})`);const He=await je.json();xt=He?.data?.sessionId||null;const Ge=typeof He?.data?.sessionName=="string"?He.data.sessionName.trim():"";Ge&&(Ve=Ge)}catch(je){const He=je instanceof Error?je.message:"Unknown error";console.error("Session creation failed:",je),m({type:"error",content:`Failed to start a new session: ${He}`,timestamp:new Date});return}if(!xt){m({type:"error",content:"Failed to start a new session: no session id returned.",timestamp:new Date});return}T?.(xt,{provider:a,project:e,summary:Ve})}const zt=st,cr={type:"user",content:H,images:zt.filter(ds),files:zt.filter(Ve=>!ds(Ve)),timestamp:new Date};m(cr),k?.(xt,{statusText:null,canInterrupt:!0}),p(!1),setTimeout(()=>x(),100),y({type:"chat.send",sessionId:xt,content:at,options:{...Y?.options??Qe(at),attachments:st}}),E(""),ie.current="",ce(),A([]),q(new Map),F(new Map),U(!1),O.current&&(O.current.style.height="auto"),Je.removeItem(`draft_input_${e.projectId}`)},[r,v,Qe,s,J,u,k,T,a,ce,x,e,y,Z,m,p,Te]);o.useEffect(()=>{fe.current=Ke},[Ke]);const Q=o.useRef(u),Oe=o.useRef(Z);o.useEffect(()=>{const _=Q.current;if(Q.current=u,Oe.current!==Z){Oe.current=Z;return}if(u||!K)return;const H=setTimeout(()=>{if(Z&&!dn(Z)){ae(null);return}ae(null),E(K.content),ie.current=K.content,A(K.attachments),fe.current?.(hr(),K)},_?0:750);return()=>clearTimeout(H)},[u,K,Z,E]);const _e=o.useCallback(()=>{K&&(ae(null),E(K.content),ie.current=K.content,A(K.attachments),O.current?.focus())},[K]),mt=o.useCallback(()=>{ae(null)},[]),ot=o.useCallback((_,Y)=>{const H=ie.current.trim(),re=H?`${H} ${_}`:_;E(re),ie.current=re,Y&&fe.current?.(hr())},[E]);o.useEffect(()=>{ie.current=I},[I]),o.useEffect(()=>{if(!me)return;const _=Je.getItem(`draft_input_${me}`)||"";E(Y=>{const H=Y===_?Y:_;return ie.current=H,H})},[me]),o.useEffect(()=>{me&&(I!==""?Je.setItem(`draft_input_${me}`,I):Je.removeItem(`draft_input_${me}`))},[I,me]),o.useEffect(()=>{!Z||te.current!==Z||(K&&(K.content.trim()||(K.uploadedAttachments?.length??0)>0)?ss(Z,{content:K.content,options:K.options,attachments:K.uploadedAttachments}):ns(Z))},[K,Z]),o.useEffect(()=>{if(te.current=Z,!Z){ae(null);return}ae(ms(Z))},[Z]),o.useEffect(()=>{O.current&&oe.current!==I&&ye(O.current)},[I,ye]),o.useEffect(()=>{!O.current||I.trim()||(O.current.style.height="auto",U(!1))},[I]);const L=o.useCallback(_=>{const Y=_.target.value,H=_.target.selectionStart;if(E(Y),ie.current=Y,se(H),!Y.trim()){_.target.style.height="auto",U(!1),ce();return}Ie(Y,H)},[Ie,ce,se]),G=o.useCallback(_=>{if(!et(_)&&!Ne(_)){if(_.key==="Tab"&&!S&&!We){_.preventDefault(),l();return}if(_.key==="Enter"){if(_.nativeEvent.isComposing)return;((_.ctrlKey||_.metaKey)&&!_.shiftKey||!_.shiftKey&&!_.ctrlKey&&!_.metaKey&&!C)&&(_.preventDefault(),Ke(_))}}},[l,et,Ne,Ke,C,We,S]),ee=o.useCallback(_=>{se(_.currentTarget.selectionStart)},[se]),ne=o.useCallback(_=>{const Y=_.currentTarget;ye(Y),se(Y.selectionStart),we(Y)},[ye,se,we]),ve=o.useCallback(()=>{E(""),ie.current="",ce(),O.current&&(O.current.style.height="auto",O.current.focus()),U(!1)},[ce]),Ce=o.useCallback(()=>{if(!j)return;const _=r?.id||s||null;if(!_){console.warn("Abort requested but no session ID is available.");return}y({type:"chat.abort",sessionId:_})},[j,s,r?.id,y]),Be=o.useCallback(_=>!_||a!=="claude"?{success:!1}:dl(_.entry),[a]),pt=o.useCallback((_,Y)=>{const re=(Array.isArray(_)?_:[_]).filter(Boolean);re.length!==0&&(re.forEach(ke=>{y({type:"chat.permission-response",requestId:ke,allow:!!Y?.allow,updatedInput:Y?.updatedInput,message:Y?.message,rememberEntry:Y?.rememberEntry})}),b(ke=>ke.filter(qe=>!re.includes(qe.requestId))))},[y,b]),[ft,lt]=o.useState(!1),kt=o.useCallback(_=>{lt(_),w?.(_)},[w]);return{input:I,setInput:E,textareaRef:O,inputHighlightRef:z,isTextareaExpanded:R,slashCommandsCount:Ee,filteredCommands:Ae,frequentCommands:ge,commandQuery:de,showCommandMenu:We,selectedCommandIndex:Le,resetCommandMenuState:ce,handleCommandSelect:Re,handleToggleCommandMenu:Se,showFileDropdown:S,filteredFiles:N,selectedFileIndex:P,renderInputWithMentions:V,selectFile:X,attachedFiles:v,setAttachedFiles:A,uploadingFiles:D,fileErrors:M,getRootProps:ut,getInputProps:yt,isDragActive:Ue,openAttachmentPicker:rt,handleSubmit:Ke,queuedDraft:K,editQueuedDraft:_e,deleteQueuedDraft:mt,handleVoiceTranscript:ot,handleInputChange:L,handleKeyDown:G,handlePaste:tt,handleTextareaClick:ee,handleTextareaInput:ne,syncInputOverlayScroll:we,handleClearInput:ve,handleAbortSession:Ce,handlePermissionDecision:pt,handleGrantToolPermission:Be,handleInputFocusChange:kt,isInputFocused:ft,commandModalPayload:W,closeCommandModal:Fe,showCostModal:ue}}const wl=300*1e3,vl=1e4,jl=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 Nl(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 Cl(e,r,s){const a=fs(e),n=xs(e);if(!a||n===null)return null;const l=a.text?wl:jl;let i=null,c=Number.POSITIVE_INFINITY;for(const d of r){if(s.has(d.id))continue;const u=fs(d);if(!u||!Nl(a,u))continue;const h=xs(d);if(h===null||h<n-vl||h-n>l)continue;const j=Math.abs(h-n);j<c&&(i=d,c=j)}return i}function fn(e,r){const s=new Set;return r.filter(a=>{if(!a.id.startsWith("local_"))return!0;const n=Cl(a,e,s);return n?(s.add(n.id),!1):!0})}const St=[],Sl=3e4;function Ml(){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(zo(e,r),{signal:AbortSignal.timeout(Sl)});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 Tl(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 El(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=Tl(e,r,s),l=El(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 Il(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 gt(e){return e.serverMessages===e._lastServerRef&&e.realtimeMessages===e._lastRealtimeRef?!1:(e._lastServerRef=e.serverMessages,e._lastRealtimeRef=e.realtimeMessages,e.merged=Il(e.serverMessages,e.realtimeMessages),!0)}function $l(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 j=c.messages,g=c,y=0,C=!1,k=Xr(n,j);for(;k.overlapLength===0&&!Ko(n,j);){const T=Wo(n,c.messages,l,c.total,y);if(!T)break;if(!a())return{applied:!1,changed:!1,deferred:!0};const w=await nr(e,T);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 $=en(j,w.messages);if($.overlapLength>0||!gn(w.messages,j))return console.warn(`[SessionStore] History shifted while bridging ${e}; retaining cached suffix.`),{applied:!1,changed:!1,deferred:!1};if(j=$.messages,g=w,y+=w.messages.length,k=Xr(n,j),!w.hasMore){C=!0;break}}C?(d=j,u=!1):k.overlapLength>0&&(d=k.messages,u=Go(n.length,d.length,i,g.hasMore).hasMore)}let h=!1;return c.tokenUsage!==void 0&&!$l(c.tokenUsage,r.tokenUsage)&&(r.tokenUsage=c.tokenUsage,h=!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),gt(r),{applied:!0,changed:!0,deferred:!1}):(console.warn(`[SessionStore] Could not bridge latest history for ${e}; retaining cached suffix.`),{applied:!1,changed:h,deferred:!1})}const Ll=3e4,Gt=500;function Rl(){const e=o.useRef(new Map),r=o.useRef(null),[,s]=o.useState(0),a=o.useCallback(f=>{f===r.current&&s(x=>x+1)},[]),n=o.useCallback(f=>{r.current=f},[]),l=o.useCallback(f=>{const x=e.current;return x.has(f)||x.set(f,Ml()),x.get(f)},[]),i=o.useCallback(f=>e.current.has(f),[]),c=o.useCallback(async(f,x={})=>{const m=l(f);return m.status="loading",a(f),gr(m,async()=>{const{canRequest:p=()=>!0,...b}=x;if(!p())return m.status="idle",a(f),null;try{const I=await nr(f,b);return m.serverMessages=I.messages,m.total=I.total,m.hasMore=I.hasMore,m.offset=(b.offset??0)+I.messages.length,m.fetchedAt=Date.now(),m.status="idle",m.realtimeMessages=hn(m.serverMessages,m.realtimeMessages),gt(m),I.tokenUsage!==void 0&&(m.tokenUsage=I.tokenUsage),a(f),m}catch(I){return console.error(`[SessionStore] fetch failed for ${f}:`,I),m.status="error",a(f),m}})},[l,a]),d=o.useCallback(async(f,x={})=>{const m=l(f);return gr(m,async()=>{let p=0,b=!1;const I=x.canRequest??(()=>!0);if(!m.hasMore||!I())return{slot:m,prependedCount:p};try{for(let E=0;E<2&&m.hasMore&&I();E++){const v=m.serverMessages,A=m.total,D=await nr(f,{limit:x.limit??bt,offset:m.offset}),q=en(v,D.messages);if(D.total!==A||q.overlapLength>0||!gn(D.messages,v)){if(E>0||!I())break;const F=await gs(f,m,bt,I);if(b=b||F.changed,!F.applied)break;continue}m.serverMessages=q.messages,m.hasMore=D.hasMore,m.total=D.total,m.offset=m.serverMessages.length,p=q.prependedCount,D.tokenUsage!==void 0&&(m.tokenUsage=D.tokenUsage),gt(m),b=!0;break}return b&&a(f),{slot:m,prependedCount:p}}catch(E){return console.error(`[SessionStore] fetchMore failed for ${f}:`,E),b&&a(f),{slot:m,prependedCount:p}}})},[l,a]),u=o.useCallback((f,x)=>{const m=l(f),p=x.sessionId===f?x:{...x,sessionId:f};let b=[...m.realtimeMessages,p];b.length>Gt&&(b=b.slice(-Gt)),m.realtimeMessages=b,gt(m),a(f)},[l,a]),h=o.useCallback((f,x)=>{if(x.length===0)return;const m=l(f),p=x.map(I=>I.sessionId===f?I:{...I,sessionId:f});let b=[...m.realtimeMessages,...p];b.length>Gt&&(b=b.slice(-Gt)),m.realtimeMessages=b,gt(m),a(f)},[l,a]),j=o.useCallback(async(f,x={})=>{const m=l(f);return gr(m,async()=>{try{const p=await gs(f,m,x.limit??bt,x.canRequest);return p.changed&&a(f),{slot:m,...p}}catch(p){return console.error(`[SessionStore] latest refresh failed for ${f}:`,p),{slot:m,applied:!1,changed:!1,deferred:!1}}})},[l,a]),g=o.useCallback((f,x)=>{const m=l(f);m.status=x,a(f)},[l,a]),y=o.useCallback(f=>{const x=e.current.get(f);return x?Date.now()-x.fetchedAt>Ll:!0},[]),C=o.useCallback((f,x,m)=>{const p=l(f),b=`__streaming_${f}`,I={id:b,sessionId:f,timestamp:new Date().toISOString(),provider:m,kind:"stream_delta",content:x},E=p.realtimeMessages.findIndex(v=>v.id===b);E>=0?(p.realtimeMessages=[...p.realtimeMessages],p.realtimeMessages[E]=I):p.realtimeMessages=[...p.realtimeMessages,I],gt(p),a(f)},[l,a]),k=o.useCallback(f=>{const x=e.current.get(f);if(!x)return;const m=`__streaming_${f}`,p=x.realtimeMessages.findIndex(b=>b.id===m);if(p>=0){const b=x.realtimeMessages[p];x.realtimeMessages=[...x.realtimeMessages],x.realtimeMessages[p]={...b,id:`text_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,kind:"text",role:"assistant"},gt(x),a(f)}},[a]),T=o.useCallback(f=>{const x=e.current.get(f);x&&(x.realtimeMessages=[],gt(x),a(f))},[a]),w=o.useCallback(f=>e.current.get(f)?.merged??St,[]),$=o.useCallback(f=>e.current.get(f),[]);return o.useMemo(()=>({getSlot:l,has:i,fetchFromServer:c,fetchMore:d,appendRealtime:u,appendRealtimeBatch:h,refreshLatestFromServer:j,setActiveSession:n,setStatus:g,isStale:y,updateStreaming:C,finalizeStreaming:k,clearRealtime:T,getMessages:w,getSessionSlot:$}),[l,i,c,d,u,h,j,n,g,y,C,k,T,w,$])}const Al=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=Al(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}`},Ol=2;function ys(e){return"_isGroup"in e&&e._isGroup===!0}function ks(e){return!!(e.isToolUse&&e.toolName&&!e.isSubagentContainer)}function Pl(e,r){return!!(e.isThinking&&!r)}function _l(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(Pl(c,r)){i+=1;continue}if(ks(c)&&c.toolName===n.toolName){l.push(c),i+=1;continue}break}l.length>=Ol?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 Dl(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(Ft,{defaultOpen:s,className:Pe("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(Ut,{children:t.jsx("div",{className:"mt-1.5 pl-[18px]",children:i})})]}),Fl=({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,h)=>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})]},h))})]})},Ul={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=Ul[e];return t.jsx("span",{className:Pe("inline-flex items-center rounded px-1.5 py-px text-[10px] font-medium",s.className,r),children:s.label})}const Bl=({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:h,toolId:j,status:g})=>{const[y,C]=o.useState(!1),k=c==="terminal",T=async()=>{if(l==="copy"&&a){if(!await Ht(a))return;C(!0),setTimeout(()=>C(!1),2e3)}else i&&i()},w=()=>t.jsx("button",{onClick:T,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:y?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 $=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:T,className:"truncate font-mono text-xs text-primary transition-colors hover:text-primary/80 hover:underline",title:a,children:$}),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}),h&&t.jsx("a",{href:`#tool-result-${j}`,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()]})},ql=({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",[h,j]=o.useState(!1),[g,y]=o.useState(!1),C=o.useRef(!1);o.useEffect(()=>{!C.current&&c&&l&&(C.current=!0,j(!0))},[c,l]);const k=()=>{c&&j(w=>!w)},T=async w=>{w.stopPropagation(),await Ht(e)&&(y(!0),setTimeout(()=>y(!1),2e3))};return t.jsxs("div",{className:Pe("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&&!h&&"hover:border-border hover:bg-muted/60",h&&"bg-muted/50 shadow-sm"),children:[t.jsxs("div",{role:c?"button":void 0,tabIndex:c?0:void 0,"aria-expanded":c?h:void 0,onClick:k,onKeyDown:w=>{c&&(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),k())},className:Pe("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:Pe("h-3.5 w-3.5 flex-shrink-0 text-muted-foreground/70 transition-transform duration-200",h&&"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:Pe("min-w-0 flex-1 font-mono text-xs text-foreground",h?"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"}),!h&&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:T,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(Bt,{className:"h-3.5 w-3.5 text-emerald-500"}):t.jsx(Us,{className:"h-3.5 w-3.5"})})]}),r&&!h&&t.jsx("div",{className:"truncate px-2.5 pb-1.5 pl-[2.4rem] text-[11px] italic text-muted-foreground/70",children:r}),h&&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:Pe("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})]})]})},Vl={bash:Ro,cpp:Lo,csharp:$o,css:Io,diff:Eo,go:To,java:Mo,javascript:So,json:Co,jsx:No,markdown:jo,markup:vo,powershell:wo,python:ko,rust:yo,sql:bo,tsx:go,typescript:ho,yaml:xo};Object.entries(Vl).forEach(([e,r])=>{dt.registerLanguage(e,r)});dt.alias("bash",["shell","sh"]);dt.alias("javascript","js");dt.alias("markup",["html","xml"]);dt.alias("powershell","ps1");dt.alias("python","py");dt.alias("typescript","ts");dt.alias("yaml","yml");let vs=null;const Hl=()=>(vs??=Ps(()=>import("./mermaid.core-DOnsXioB.js").then(e=>e.bo),__vite__mapDeps([0,1,2,3,4,5,6])).then(e=>e.default),vs);function zl({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 Hl().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 Wl=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}=ze("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 j=/language-(\w+)/.exec(r||""),g=j?j[1]:"text",y=g.charAt(0).toUpperCase()+g.slice(1);return g==="mermaid"?t.jsx(zl,{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:y}),t.jsx("button",{type:"button",onClick:()=>Ht(u).then(C=>{C&&(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(dt,{language:g,style:i?_o:Do,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})]})},Kl={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=Xo(String(e??"")),n=o.useMemo(()=>s?[Gr,[Jr,{singleDollarTextMath:!1}],Ao]:[Gr,[Jr,{singleDollarTextMath:!1}]],[s]),l=o.useMemo(()=>[Oo],[]),{openFileInEditor:i}=Zn(),c=o.useMemo(()=>({...Kl,a:({href:d,children:u})=>{const h=Ir(u),j=js(d)?d:js(h)?h:void 0;return j&&!Wl(d)?t.jsx("a",{href:d||j,className:"cursor-pointer text-blue-600 hover:underline dark:text-blue-400",onClick:g=>{g.preventDefault(),i(yn(j))},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(Po,{remarkPlugins:n,rehypePlugins:l,components:c,children:a})})}const Gl=({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:Pe("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:Pe("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:Pe("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"},Jl=({toolName:e,title:r,defaultOpen:s=!1,action:a,badge:n,onTitleClick:l,children:i,showRawParameters:c=!1,rawContent:d,className:u="",toolCategory:h})=>{const j=Ns[h||"default"]||Ns.default;return t.jsx("div",{className:`border-l-2 ${j} 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(Ft,{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(Ut,{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""}},Ql=({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,h=d>=0?c[d]:null,j=`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:j,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}),h&&!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:h.toolName}),Jt(h.toolName,h.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(h.toolName,h.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(Ft,{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(Ut,{children:t.jsx("div",{className:"mt-1 space-y-0.5 border-l border-border pl-3",children:c.map((g,y)=>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:[y+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 y=JSON.parse(g);if(Array.isArray(y)){const C=y.filter(k=>k.type==="text"&&k.text).map(k=>k.text);C.length>0&&(g=C.join(`
|
|
17
|
+
`))}}catch{}else if(Array.isArray(g)){const y=g.filter(C=>C.type==="text"&&C.text).map(C=>C.text);y.length>0&&(g=y.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}),Yl=({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)})})]}),Xl=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:Xl(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(ea,{children:s.map((a,n)=>t.jsxs(ta,{status:a.queueStatus,children:[t.jsx(ra,{}),t.jsx(sa,{children:a.content})]},a.id??`${a.content}-${n}`))})]})});wn.displayName="TodoList";const Zl=e=>{if(typeof e!="object"||e===null)return!1;const r=e;return typeof r.content=="string"&&typeof r.status=="string"},ei=o.memo(({todos:e,isResult:r=!1})=>{const s=o.useMemo(()=>Array.isArray(e)?e.filter(Zl):[],[e]);return s.length===0?null:t.jsx(wn,{todos:s,isResult:r})});function ti(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"}},ri=({content:e})=>{const r=ti(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)})})]})},si=({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})},ni=({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,h=r?.[u.question],j=typeof h=="string"?h.split(", "):[],g=!h,y=a===d,C=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(y?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 ${j.length>0?"bg-blue-100 dark:bg-blue-900/40":"bg-gray-100 dark:bg-gray-800"}`,children:j.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}),!y&&j.length>0&&t.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1",children:j.map(k=>{const T=!C.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,T&&t.jsx("span",{className:"text-[9px] font-normal text-blue-400 dark:text-blue-500",children:"(custom)"})]},k)})}),!y&&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 ${y?"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"})})]}),y&&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:[C.map(k=>{const T=j.includes(k.label);return t.jsxs("div",{className:`flex items-start gap-2 rounded-lg px-2.5 py-1.5 text-[12px] ${T?"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] ${T?"border-blue-500 bg-blue-500 dark:border-blue-400 dark:bg-blue-500":"border-gray-300 dark:border-gray-600"}`,children:T&&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:T?"font-medium text-gray-900 dark:text-gray-100":"",children:k.label}),k.description&&t.jsx("span",{className:`mt-0.5 block text-[11px] ${T?"text-blue-600/70 dark:text-blue-300/70":"text-gray-400 dark:text-gray-600"}`,children:k.description})]})]},k.label)}),j.filter(k=>!C.some(T=>T.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"})]})},ai={claude:"Claude",codex:"Codex",cursor:"Cursor",opencode:"OpenCode",pi:"Pi"};function oi(e){return ai[e||"claude"]}function li(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 ii=({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),[h,j]=o.useState(()=>new Map),[g,y]=o.useState(!1),C=o.useRef(null),k=o.useRef(null);o.useEffect(()=>{requestAnimationFrame(()=>y(!0))},[]),o.useEffect(()=>{h.get(n)||C.current?.focus()},[n,h]),o.useEffect(()=>{h.get(n)&&k.current?.focus()},[h,n]);const T=o.useCallback((R,U,W)=>{c(B=>{const O=new Map(B),z=new Set(O.get(R)||[]);return W?z.has(U)?z.delete(U):z.add(U):(z.clear(),z.add(U),j(le=>{const oe=new Map(le);return oe.set(R,!1),oe})),O.set(R,z),O})},[]),w=o.useCallback((R,U)=>{j(W=>{const B=new Map(W),O=B.get(R)||!1;return B.set(R,!O),!U&&!O&&c(z=>{const le=new Map(z);return le.set(R,new Set),le}),B})},[]),$=o.useCallback((R,U)=>{u(W=>{const B=new Map(W);return B.set(R,U),B})},[]),f=o.useCallback(()=>{const R=a.map((U,W)=>{const B=Array.from(i.get(W)||[]),O=h.get(W)||!1,z=(d.get(W)||"").trim();return O&&z&&B.push(z),{question:U,values:B}});return li(R,e.provider)},[a,i,h,d,e.provider]),x=o.useCallback(()=>{r(e.requestId,{allow:!0,updatedInput:{...s,answers:f()}})},[r,e.requestId,s,f]),m=o.useCallback(()=>{r(e.requestId,{allow:!0,updatedInput:{...s,answers:{}}})},[r,e.requestId,s]),p=o.useCallback(R=>{if(R.target instanceof HTMLInputElement)return;const U=a[n];if(!U)return;const W=U.multiSelect||!1,B=U.options.length,O=parseInt(R.key);if(!isNaN(O)&&O>=1&&O<=B){R.preventDefault(),T(n,U.options[O-1].label,W);return}if(R.key==="0"){R.preventDefault(),w(n,W);return}if(R.key==="Enter"){R.preventDefault(),n===a.length-1?x():l(le=>le+1);return}if(R.key==="Escape"){R.preventDefault(),m();return}},[n,a,T,w,x,m]);if(a.length===0)return null;const b=a.length,I=b===1,E=a[n],v=E.multiSelect||!1,A=i.get(n)||new Set,D=h.get(n)||!1,q=n===b-1,M=n===0,F=A.size>0||D&&(d.get(n)||"").trim().length>0;return t.jsx("div",{ref:C,tabIndex:-1,onKeyDown:p,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:[oi(e.provider)," needs your input"]}),E.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:E.header})]}),!I&&t.jsxs("span",{className:"flex-shrink-0 text-[10px] tabular-nums text-gray-400 dark:text-gray-500",children:[n+1,"/",b]})]}),!I&&t.jsx("div",{className:"mb-2 flex items-center gap-1",children:a.map((R,U)=>t.jsx("button",{type:"button",onClick:()=>l(U),className:`h-[3px] rounded-full transition-all duration-300 ${U===n?"w-5 bg-blue-500 dark:bg-blue-400":U<n?"w-2.5 bg-blue-300 dark:bg-blue-600":"w-2.5 bg-gray-200 dark:bg-gray-700"}`},U))}),t.jsx("p",{className:"text-[14px] font-medium leading-snug text-gray-900 dark:text-gray-100",children:E.question}),v&&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:v?"group":"radiogroup","aria-label":E.question,children:t.jsxs("div",{className:"space-y-1",children:[E.options.map((R,U)=>{const W=A.has(R.label);return t.jsxs("button",{type:"button",onClick:()=>T(n,R.label,v),className:`group flex w-full items-center gap-2.5 rounded-lg border px-3 py-2 text-left transition-all duration-150 ${W?"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 ${W?"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:U+1}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:`text-[13px] leading-tight transition-colors duration-150 ${W?"font-medium text-gray-900 dark:text-gray-100":"text-gray-700 dark:text-gray-300"}`,children:R.label}),R.description&&t.jsx("div",{className:`text-[11px] leading-snug transition-colors duration-150 ${W?"text-blue-600/70 dark:text-blue-300/70":"text-gray-400 dark:text-gray-500"}`,children:R.description})]}),W&&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"})})]},R.label)}),t.jsxs("button",{type:"button",onClick:()=>w(n,v),className:`group flex w-full items-center gap-2.5 rounded-lg border px-3 py-2 text-left transition-all duration-150 ${D?"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 ${D?"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 ${D?"font-medium text-gray-900 dark:text-gray-100":"text-gray-500 dark:text-gray-400"}`,children:"Other..."}),D&&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"})})]}),D&&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:R=>$(n,R.target.value),onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),q?x():l(U=>U+1)),R.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:m,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(R=>R-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"]}),q?t.jsxs("button",{type:"button",onClick:x,disabled:!F&&!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(R=>R+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"})]})]})]})]})})},ci=({title:e,content:r,defaultOpen:s=!1,isStreaming:a=!1,showRawParameters:n=!1,rawContent:l,toolName:i})=>{const c=Uo(),d=c?.pendingPermissionRequests.find(j=>j.toolName==="ExitPlanMode"||j.toolName==="exit_plan_mode"),u=()=>{d&&c&&c.handlePermissionDecision(d.requestId,{allow:!0})},h=()=>{d&&c&&c.handlePermissionDecision(d.requestId,{allow:!1,message:"User asked to revise the plan"})};return t.jsx(Ft,{defaultOpen:s,children:t.jsxs(_s,{className:"my-1 flex flex-col shadow-none",children:[t.jsxs(na,{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(aa,{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(Ta,{className:"h-4 w-4"}),t.jsx("span",{className:"sr-only",children:"Toggle plan"})]})]}),t.jsx(Ut,{children:t.jsxs(oa,{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(Ft,{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(Ut,{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(la,{className:"justify-end gap-2 border-t border-border/40 px-4 pb-3 pt-3",children:[t.jsx(Ye,{variant:"ghost",size:"sm",onClick:h,className:"text-muted-foreground",children:"Revise"}),t.jsxs(Ye,{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 di(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 ui=["user denied tool use","tool disallowed by settings","permission request timed out","permission request cancelled"];function mi(e){if(!e)return"running";if(e.isError){const r=String(e.content||"").toLowerCase().trim();return ui.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:h,subagentState:j})=>{const g=ir(e),y=n==="input"?g.input:g.result,C=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"?mi(s):void 0,[n,s]),T=o.useCallback(()=>{if(y?.action==="open-file"&&l){const w=y.getValue?.(C)||"";l(w)}},[y,C,l]);if(h&&j)return n==="result"?null:t.jsx(Ql,{toolInput:r,toolResult:s,subagentState:j});if(!y)return null;if(e==="Bash"&&n==="input"){const w=typeof C=="object"&&C!==null&&"command"in C?String(C.command||""):typeof r=="string"?r:typeof u=="string"?u:"",$=typeof C=="object"&&C!==null&&"description"in C?String(C.description||""):void 0,f=typeof s?.content=="string"?s.content:s?.content!=null?String(s.content):"";return t.jsx(ql,{command:w,description:$,output:f,isError:!!s?.isError,status:k!=="completed"?k:void 0,defaultOpen:!1})}if(y.type==="one-line"){const w=y.getValue?.(C)||"",$=y.getSecondary?.(C);return t.jsx(Bl,{toolName:e,toolResult:s,toolId:a,icon:y.icon,label:y.label,value:w,secondary:$,action:y.action,onAction:T,style:y.style,wrapText:y.wrapText,colorScheme:y.colorScheme,resultId:n==="input"?`tool-result-${a}`:void 0,status:k!=="completed"?k:void 0})}if(y.type==="plan"){const w=typeof y.title=="function"?y.title(C):y.title||"Plan",$=y.getContentProps?.(C,{selectedProject:c,createDiff:i,onFileOpen:l})||{},f=n==="input"&&!s;return t.jsx(ci,{title:w,content:$.content||"",defaultOpen:y.defaultOpen??!1,isStreaming:f,showRawParameters:n==="input"&&d,rawContent:u,toolName:e,toolId:a})}if(y.type==="collapsible"){const w=typeof y.title=="function"?y.title(C):y.title||"Details",$=y.defaultOpen!==void 0?y.defaultOpen:!1,f=y.getContentProps?.(C,{selectedProject:c,createDiff:i,onFileOpen:l})||{};let x=null;switch(y.contentType){case"diff":i&&(x=t.jsx(Fl,{...f,createDiff:i,onFileClick:()=>l?.(f.filePath)}));break;case"markdown":x=t.jsx(kn,{content:f.content||""});break;case"file-list":x=t.jsx(Yl,{files:f.files||[],onFileClick:l,title:f.title});break;case"todo-list":f.todos?.length>0&&(x=t.jsx(ei,{todos:f.todos,isResult:f.isResult}));break;case"task":x=t.jsx(ri,{content:f.content||""});break;case"question-answer":x=t.jsx(ni,{questions:f.questions||[],answers:f.answers||{}});break;case"text":x=t.jsx(si,{content:f.content||"",format:f.format||"plain"});break;case"success-message":{const b=y.getMessage?.(C)||"Success";x=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"})}),b]});break}}const m=(e==="Edit"||e==="Write"||e==="ApplyPatch")&&f.filePath&&l?()=>l(f.filePath,{old_string:f.oldContent,new_string:f.newContent}):void 0,p=k&&k!=="completed"?t.jsx(Mt,{status:k}):void 0;return t.jsx(Jl,{toolName:e,toolId:a,title:w,defaultOpen:$,onTitleClick:m,badge:p,showRawParameters:n==="input"&&d,rawContent:u,toolCategory:di(e),children:x})}return null});$r.displayName="ToolRenderer";function pi(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 h=new AbortController;return(async()=>{l(!1);for(const g of d)try{const y=await $e(g,{signal:h.signal});if(!y.ok)continue;const C=await y.blob();u=URL.createObjectURL(C),a(u);return}catch(y){if(y instanceof Error&&y.name==="AbortError")return}a(null),l(!0)})(),()=>{h.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]),Vt.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(ct,{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 fi({image:e,projectId:r}){const{src:s,failed:a}=pi(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 xi({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(fi,{image:s,projectId:r},s.path||s.name||a))})}const hi=e=>typeof e!="number"?null:e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`,gi=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)?Ea:/\.(js|jsx|ts|tsx|py|rb|go|rs|java|c|cpp|css|html|json|ya?ml)$/.test(r)?Ia:qs};function bi({file:e}){const[r,s]=o.useState(!1),a=e.name||e.path?.split(/[\\/]/).pop()||"Attached file",n=gi(e),l=hi(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()),h=document.createElement("a");h.href=u,h.download=a,h.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 yi({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(bi,{file:r},r.path||r.name||s))}):null}const ki=2e3,wi=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}=ze("chat"),a=r==="assistant",n=a?"markdown":"text",[l,i]=o.useState(n),[c,d]=o.useState(!1),[u,h]=o.useState(!1),[j,g]=o.useState({}),y=o.useRef(null),C=o.useRef(null),k=o.useRef(null),T=o.useRef(null),w=()=>{const v=C.current?.getBoundingClientRect();if(v){const D=v.bottom+84+8>window.innerHeight;g({position:"fixed",right:Math.max(8,window.innerWidth-v.right),zIndex:1e3,...D?{bottom:window.innerHeight-v.top+4}:{top:v.bottom+4}})}h(!0)},$=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"}),x=o.useMemo(()=>l==="markdown"?e:wi(e),[e,l]);o.useEffect(()=>{i(n),h(!1)},[n]),o.useEffect(()=>{if(!u)return;const v=D=>{const q=D.target;y.current?.contains(q)||k.current?.contains(q)||h(!1)},A=()=>h(!1);return window.addEventListener("mousedown",v),window.addEventListener("scroll",A,!0),window.addEventListener("resize",A),()=>{window.removeEventListener("mousedown",v),window.removeEventListener("scroll",A,!0),window.removeEventListener("resize",A)}},[u]),o.useEffect(()=>()=>{T.current&&clearTimeout(T.current)},[]);const m=async()=>{!x.trim()||!await Ht(x)||(d(!0),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{d(!1)},ki))},p=v=>{i(v),h(!1)},b=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"),E=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:y,className:E,children:[t.jsxs("button",{type:"button",onClick:m,title:I,"aria-label":I,className:`inline-flex items-center gap-1 rounded px-1 py-0.5 transition-colors ${b}`,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:C,type:"button",onClick:()=>u?h(!1):w(),className:`rounded px-1 py-0.5 transition-colors ${b}`,"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&&Vt.createPortal(t.jsx("div",{ref:k,style:j,className:"min-w-36 rounded-md border border-border bg-popover p-1 shadow-lg",children:$.map(v=>{const A=v.format===l;return t.jsx("button",{type:"button",onClick:()=>p(v.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:v.label})},v.format)})}),document.body)]})]})};function jn(e,r){return`${e.replace(/\/$/,"")}${r}`}function vi(){return JSON.stringify(or())}function ji(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 Ni(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 Ci={state:"idle",error:null},Si=24,Mi=33e4;function Nn(e,r=vi()){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 Ti{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?Ci:{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(),Mi),d=await Ni(s,i.signal).finally(()=>{clearTimeout(c),this.activeController===i&&(this.activeController=null)});if(n!==this.token)return;if(!d.ok){let h=`Read-aloud failed (${d.status})`;try{const j=await d.json();j?.error&&(h=String(j.error))}catch{}throw new Error(h)}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>Si;){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 _t=new Ti;function Ei(e){const r=e(),s=Nn(r),[a,n]=o.useState(()=>_t.getSnapshot(s));o.useEffect(()=>{const i=()=>n(c=>{const d=_t.getSnapshot(s);return c.state===d.state&&c.error===d.error?c:d});return i(),_t.subscribe(i)},[s]);const l=o.useCallback(()=>{_t.unlock(),_t.toggle(r)},[r]);return{state:a.state,toggle:l,error:a.error}}const Ii="uiPreferences",Ss="ui-preferences:sync";let Qt=null;function $i(){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(Ii);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 $i();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 Li=({content:e})=>{const{t:r}=ze("chat"),s=Cn(),{state:a,toggle:n,error:l}=Ei(()=>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($a,{className:"h-3.5 w-3.5"})})]})},Ri=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}=ze("chat"),u=r&&r.type===e.type&&(r.type==="assistant"||r.type==="user"||r.type==="tool"||r.type==="error"),h=o.useRef(null),j=String(e.content||""),g=o.useMemo(()=>{const f=Er(String(e.content||""));return c==="codex"&&e.type==="assistant"&&!e.isThinking?Zo(f):f},[e.content,e.isThinking,e.type,c]),y=e.isToolUse?String(e.displayText||e.content||""):g,C=!!(e.isToolUse&&Ri.has(String(e.toolName||""))),k=e.type==="user"&&j.trim().length>0,T=e.type==="assistant"&&y.trim().length>0&&!C&&!e.isThinking,w=o.useMemo(()=>new Date(e.timestamp).toLocaleTimeString(),[e.timestamp]);return e.isThinking&&!l?null:t.jsx("div",{ref:h,"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(xi,{images:e.images,projectId:i?.projectId}),e.files&&e.files.length>0&&t.jsx(yi,{files:e.files}),j.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:j,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"&&!Dl(e.toolName||"UnknownTool",e.toolResult)&&(e.toolResult.isError?t.jsx("div",{id:`tool-result-${e.toolId}`,className:"scroll-mt-4",children:t.jsx(Gl,{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(p=>p.trim()),x=f.find(p=>p.includes("?"))||f[0]||"",m=[];return f.forEach(p=>{const b=p.match(/[❯\s]*(\d+)\.\s+(.+)/);if(b){const I=p.includes("❯");m.push({number:b[1],text:b[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:x}),t.jsx("div",{className:"mb-4 space-y-2",children:m.map(p=>t.jsx("button",{className:`w-full rounded-lg border-2 px-4 py-3 text-left transition-all ${p.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 ${p.isSelected?"bg-white/20":"bg-amber-100 dark:bg-amber-800/50"}`,children:p.number}),t.jsx("span",{className:"flex-1 text-sm font-medium sm:text-base",children:p.text}),p.isSelected&&t.jsx("span",{className:"text-lg",children:"❯"})]})},p.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,x=f.trim();if((x.startsWith("{")||x.startsWith("["))&&(x.endsWith("}")||x.endsWith("]")))try{const m=JSON.parse(x),p=JSON.stringify(m,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:p})})})]})}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})})()]}),(T||!u)&&t.jsxs("div",{className:"mt-1 flex w-full items-center gap-2 text-[11px] text-gray-400 dark:text-gray-500",children:[T&&t.jsx(yr,{content:y,messageType:"assistant"}),T&&t.jsx(Li,{content:y}),!u&&t.jsx("span",{children:w})]})]})]})})}),Ai=[{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 Oi(e){return e==="done"?Hs:e==="in-progress"?Oa:e==="review"?Pa:e==="deferred"?_a:e==="cancelled"?ct:zs}function Pi(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 _i({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,h]=o.useState(!1),[j,g]=o.useState(!1),[y,C]=o.useState(!1),[k,T]=o.useState(!1),[w,$]=o.useState(e);o.useEffect(()=>{$(e),h(!1)},[e]);const f=o.useMemo(()=>Oi(e?.status),[e?.status]);if(!r||!e||!w)return null;const x=async()=>{if(!c?.name)return;const p={};if(w.title!==e.title&&(p.title=w.title),w.description!==e.description&&(p.description=w.description??""),w.details!==e.details&&(p.details=w.details??""),Object.keys(p).length===0){h(!1);return}g(!0);try{const b=await jr.taskmaster.updateTask(c.name,e.id,p);if(!b.ok){const I=await b.json();throw new Error(I.message??"Failed to update task")}h(!1),await d(),n?.(w)}catch(b){console.error("Failed to save task changes:",b),alert(b instanceof Error?b.message:"Failed to update task")}finally{g(!1)}},m=async p=>{if(!(!c?.name||p===e.status))try{const b=await jr.taskmaster.updateTask(c.name,e.id,{status:p});if(!b.ok){const I=await b.json();throw new Error(I.message??"Failed to update task status")}await d(),l?.(e.id,p)}catch(b){console.error("Failed to update task status:",b),alert(b instanceof Error?b.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:Pe("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:()=>Ht(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:p=>$({...w,title:p.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:x,disabled:j,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(La,{className:Pe("w-5 h-5",j&&"animate-spin")})}),t.jsx("button",{onClick:()=>{$(e),h(!1)},disabled:j,className:"rounded-md p-2 text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-800",title:"Cancel editing",children:t.jsx(ct,{className:"h-5 w-5"})})]}):t.jsx("button",{onClick:()=>h(!0),className:"rounded-md p-2 text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-800",title:"Edit task",children:t.jsx(Ra,{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(ct,{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:p=>{m(p.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:Ai.map(p=>t.jsx("option",{value:p.value,children:p.label},p.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:Pe("px-3 py-2 rounded-md text-sm font-medium capitalize",Pi(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(p=>t.jsxs("button",{onClick:()=>i?.({id:p}),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(Aa,{className:"mr-1 inline h-3 w-3"}),p]},String(p)))}):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:p=>$({...w,description:p.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:()=>C(p=>!p),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"}),y?t.jsx(rr,{className:"h-4 w-4"}):t.jsx(It,{className:"h-4 w-4"})]}),y&&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:()=>T(p=>!p),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 Di=o.lazy(()=>Ps(()=>import("./Shell-twzi9t5B.js").then(e=>e.a),__vite__mapDeps([7,2,1,3,4,5,6,8])));function Fi({isOpen:e,project:r,onClose:s,onAfterClose:a=null}){const{t:n}=ze("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(qt,{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(Di,{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:Pe("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 Ui({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(qa,{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(Va,{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(),[h,j]=o.useState(!1),[g,y]=o.useState(!1),[C,k]=o.useState(!1);if(!l||i)return null;const T=Array.isArray(n)&&n.length>0,w=!!(c?.hasTaskmaster||l.taskmaster?.hasTaskmaster),$=()=>{u(),d()};if(!T&&!w)return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:Pe("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:()=>y(!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(Da,{className:"h-3 w-3"}),C?"Hide details":"What is TaskMaster?"]}),C&&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(Fi,{isOpen:g,project:l,onClose:()=>y(!1),onAfterClose:$})]});if(a)return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:Pe("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(Fa,{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(Ui,{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(Ua,{className:"h-3 w-3"}),"Start Task"]}),t.jsx("button",{onClick:()=>j(!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(Ba,{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(_i,{task:a,isOpen:h,onClose:()=>j(!1),onStatusChange:()=>{d()}})]});if(T){const f=n.filter(x=>x.status==="done").length;return t.jsx("div",{className:Pe("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"},{id:"pi",label:"Pi"}];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(""),[h,j]=o.useState(""),[g,y]=o.useState(!1),[C,k]=o.useState(null),[T,w]=o.useState(null),[$,f]=o.useState(null),[x,m]=o.useState(null);o.useEffect(()=>{l(e)},[e]);const p=o.useMemo(()=>r[n]?.OPTIONS??[],[r,n]),b=o.useMemo(()=>p.filter(M=>M.isCustom),[p]),I=o.useMemo(()=>p.filter(M=>!M.isCustom),[p]),E=()=>{c(null),u(""),j(""),f(null)},v=M=>{l(M),w(null),m(null),E()},A=M=>{c(M),u(M.label),j(M.value),w(null),m(null),f(null)},D=async M=>{M.preventDefault();const F=d.trim(),R=h.trim();if(!F||!R){f("Enter both a model name and model ID.");return}if(/\s/.test(R)){f("Model IDs cannot contain spaces.");return}y(!0),f(null),m(null);try{i?(await s.update(n,i,{model:F,id:R}),m(`${F} was updated.`)):(await s.create(n,{model:F,id:R}),m(`${F} was added.`)),E()}catch(U){f(U instanceof Error?U.message:"Unable to save this model.")}finally{y(!1)}},q=async M=>{if(M.recordId){k(M.recordId),f(null),m(null);try{await s.remove(n,M),i?.recordId===M.recordId&&E(),w(null),m(`${M.label} was deleted.`)}catch(F){f(F instanceof Error?F.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(qt,{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(Ye,{type:"button",variant:"outline",size:"sm",onClick:a,className:"shrink-0 rounded-xl",children:[t.jsx(Ha,{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 F=M.id===n;return t.jsxs("button",{type:"button",onClick:()=>v(M.id),"aria-pressed":F,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 ${F?"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:D,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(Ye,{type:"button",variant:"ghost",size:"icon",onClick:E,className:"h-8 w-8 rounded-lg","aria-label":"Cancel editing",children:t.jsx(ct,{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:h,onChange:M=>j(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."}),$&&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:$}),x&&!$&&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(Bt,{className:"h-3.5 w-3.5"}),x]}),t.jsxs(Ye,{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(Bt,{className:"h-4 w-4"}):t.jsx(qt,{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:b.length})]}),b.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:b.map(M=>{const F=T===M.recordId,R=C===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})]}),!F&&t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsx(Ye,{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(Ye,{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(za,{className:"h-3.5 w-3.5"})})]})]}),F&&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(Ye,{type:"button",variant:"ghost",size:"sm",onClick:()=>w(null),className:"h-8 rounded-lg",children:"Cancel"}),t.jsxs(Ye,{type:"button",variant:"destructive",size:"sm",disabled:R,onClick:()=>{q(M)},className:"h-8 rounded-lg",children:[R&&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(Wa,{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 Bi=[{id:"claude",name:"Anthropic"},{id:"codex",name:"OpenAI"},{id:"cursor",name:"Cursor"},{id:"opencode",name:"OpenCode"},{id:"pi",name:"Pi"}],qi=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl";function Vi(e,r){const s=e.toLowerCase();return r.toLowerCase().split(/\s+/).filter(Boolean).every(n=>s.includes(n))?1:0}function Hi(e,r){return r[e]??{OPTIONS:[],DEFAULT:""}}function zi(e,r,s,a,n,l){return e==="claude"?r:e==="codex"?a:e==="opencode"?n:e==="pi"?l:s}function Wi(e){return e==="claude"?"Claude":e==="cursor"?"Cursor":e==="codex"?"Codex":e==="opencode"?"OpenCode":e==="pi"?"Pi":"Claude"}function Ki({selectedSession:e,currentSessionId:r,provider:s,setProvider:a,textareaRef:n,claudeModel:l,setClaudeModel:i,cursorModel:c,setCursorModel:d,codexModel:u,setCodexModel:h,opencodeModel:j,setOpenCodeModel:g,piModel:y,setPiModel:C,providerModelCatalog:k,providerModelActions:T,providerModelsLoading:w,tasksEnabled:$,isTaskMasterInstalled:f,onShowAllTasks:x,setInput:m}){const{t:p}=ze("chat"),[b,I]=o.useState(!1),[E,v]=o.useState(!1),A=o.useMemo(()=>Bi.map(B=>({id:B.id,name:B.name,models:k[B.id]?.OPTIONS??[]})),[k]),D=p("tasks.nextTaskPrompt",{defaultValue:"Start the next task"}),q=zi(s,l,c,u,j,y),M=o.useMemo(()=>Hi(s,k).OPTIONS.find(z=>z.value===q)?.label||q,[s,q,k]),F=o.useCallback((B,O)=>{B==="claude"?(i(O),localStorage.setItem("claude-model",O)):B==="codex"?(h(O),localStorage.setItem("codex-model",O)):B==="opencode"?(g(O),localStorage.setItem("opencode-model",O)):B==="pi"?(C(O),localStorage.setItem("pi-model",O)):(d(O),localStorage.setItem("cursor-model",O))},[i,d,h,g,C]),R=o.useCallback((B,O)=>{a(B),localStorage.setItem("selected-provider",B),F(B,O),I(!1),setTimeout(()=>n.current?.focus(),100)},[a,F,n]),U=()=>{I(!1),v(!0)},W=()=>{v(!1),I(!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:p("providerSelection.title")}),t.jsx("p",{className:"mt-1 text-[13px] text-muted-foreground",children:p("providerSelection.description")})]}),t.jsxs(Sr,{open:b,onOpenChange:I,children:[t.jsx(ia,{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:Wi(s)}),t.jsx("span",{className:"text-xs text-muted-foreground",children:"·"}),t.jsx("span",{className:"truncate text-xs text-foreground",children:M})]}),t.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:p("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:p("providerSelection.chooseModel",{defaultValue:"Choose a model"})}),t.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:p("providerSelection.chooseModelDescription",{defaultValue:"Built-in and custom models in one list"})})]}),t.jsxs(Ye,{type:"button",variant:"ghost",size:"sm",onClick:U,className:"h-8 shrink-0 rounded-lg px-2.5 text-xs",children:[t.jsx(qt,{className:"h-3.5 w-3.5"}),p("providerSelection.addModel",{defaultValue:"Add model"})]})]}),t.jsxs(ca,{filter:Vi,children:[t.jsx(da,{placeholder:p("providerSelection.searchModels",{defaultValue:"Search models..."})}),t.jsxs(ua,{className:"max-h-[350px]",children:[t.jsx(ma,{children:p("providerSelection.noModelsFound",{defaultValue:"No models found."})}),A.map((B,O)=>t.jsxs(pa,{className:O>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:B.id,className:"h-3.5 w-3.5 shrink-0"}),B.name]}),children:[B.models.length===0&&w?t.jsx(Wr,{disabled:!0,className:"ml-4 border-l border-border/40 pl-4 text-muted-foreground",children:p("providerSelection.loadingModels",{defaultValue:"Loading models…"})}):null,B.models.map(z=>{const le=s===B.id&&q===z.value;return t.jsxs(Wr,{value:`${B.name} ${z.label} ${z.description||""}`,onSelect:()=>R(B.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})]}),le&&t.jsx(Bt,{className:"ml-auto h-4 w-4 shrink-0 text-primary"})]},`${B.id}-${z.value}`)})]},B.id))]})]})]})]}),t.jsx(Sr,{open:E,onOpenChange:B=>{B?v(!0):W()},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:p("providerSelection.manageModels",{defaultValue:"Manage models"})}),t.jsx(Mn,{initialProvider:s,providerModelCatalog:k,actions:T,onDone:W})]})}),t.jsx("p",{className:"mt-4 text-center text-sm text-muted-foreground/70",children:{claude:p("providerSelection.readyPrompt.claude",{model:l}),cursor:p("providerSelection.readyPrompt.cursor",{model:c}),codex:p("providerSelection.readyPrompt.codex",{model:u}),opencode:p("providerSelection.readyPrompt.opencode",{model:j,defaultValue:"Ready with OpenCode {{model}}"}),pi:p("providerSelection.readyPrompt.pi",{model:y,defaultValue:"Ready with Pi {{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(Fo,{ns:"chat",i18nKey:"providerSelection.pressToSearch",values:{shortcut:qi==="⌘"?"⌘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&&$&&f&&t.jsx("div",{className:"mt-5",children:t.jsx(Ts,{onStartTask:()=>m(D),onShowAllTasks:x})})]})}):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:p("session.continue.title")}),t.jsx("p",{className:"text-sm leading-relaxed text-muted-foreground",children:p("session.continue.description")}),$&&f&&t.jsx("div",{className:"mt-5",children:t.jsx(Ts,{onStartTask:()=>m(D),onShowAllTasks:x})})]})}):null}function Gi(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function Ji(e){const r=ir(e.toolName||"UnknownTool").input,s=Gi(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 Qi(e,r){return e==="terminal"?"$":e||r.slice(0,1).toUpperCase()}function Yi({group:e,prevMessage:r,createDiff:s,getMessageKey:a,onFileOpen:n,onShowSettings:l,onGrantToolPermission:i,showRawParameters:c,showThinking:d,selectedProject:u,provider:h}){const[j,g]=o.useState(!1),y=ir(e.toolName).input,C=y.label||e.toolName,k=y.colorScheme?.border||"border-border",T=y.colorScheme?.icon||"text-muted-foreground",w=Qi(y.icon,e.toolName),$=o.useMemo(()=>{const f=e.messages.slice(0,2).map(Ji).filter(Boolean),x=e.messages.length-f.length,m=f.join(", ");return m?x>0?`${m}, +${x} more`:m:x>0?`+${x} 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":j,children:[t.jsx(It,{className:`h-3.5 w-3.5 flex-shrink-0 text-muted-foreground transition-transform ${j?"rotate-90":""}`,"aria-hidden":!0}),t.jsx("span",{className:`${T} 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:C}),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]}),$&&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:$})]})]}),j&&t.jsx("div",{className:"mt-2 space-y-3 sm:space-y-4",children:e.messages.map((f,x)=>t.jsx(Sn,{message:f,prevMessage:x>0?e.messages[x-1]:r,createDiff:s,onFileOpen:n,onShowSettings:l,onGrantToolPermission:i,showRawParameters:c,showThinking:d,selectedProject:u,provider:h},a(f)))})]})}const Xi=`
|
|
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 Zi({showLoadAllOverlay:e,isLoadingAllMessages:r,loadAllJustFinished:s,totalMessages:a,onLoadAllMessages:n}){const{t:l}=ze("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:Xi}),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 ec(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 tc(e,r="chat-export.md",s){const a=ec(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 rc(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 sc(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 nc=[{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 ac({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":tc(e,`${c}.md`,r);break;case"html":rc(e,`${c}.html`,r);break;case"pdf":sc(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:"}),nc.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(Ka,{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 oc({scrollContainerRef:e,onWheel:r,onTouchMove:s,isLoadingSessionMessages:a,isProcessing:n=!1,hasActivityIndicator:l=!1,chatMessages:i,selectedSession:c,currentSessionId:d,provider:u,setProvider:h,textareaRef:j,claudeModel:g,setClaudeModel:y,cursorModel:C,setCursorModel:k,codexModel:T,setCodexModel:w,opencodeModel:$,setOpenCodeModel:f,piModel:x,setPiModel:m,providerModelCatalog:p,providerModelActions:b,providerModelsLoading:I,tasksEnabled:E,isTaskMasterInstalled:v,onShowAllTasks:A,setInput:D,isLoadingMoreMessages:q,hasMoreMessages:M,totalMessages:F,sessionMessagesCount:R,visibleMessageCount:U,visibleMessages:W,loadEarlierMessages:B,loadAllMessages:O,allMessagesLoaded:z,isLoadingAllMessages:le,loadAllJustFinished:oe,showLoadAllOverlay:fe,createDiff:ie,onFileOpen:me,onShowSettings:Z,onGrantToolPermission:Me,showRawParameters:xe,showThinking:K,selectedProject:ae}){const{t:te}=ze("chat"),be=o.useMemo(()=>_l(W,!!K),[W,K]),Fe=o.useMemo(()=>{const J=new WeakMap,ue=new Map,Te=Ee=>{const Ae=bs(Ee)??"message-generated",ge=ue.get(Ae)??0;ue.set(Ae,ge+1),J.set(Ee,ge===0?Ae:`${Ae}__${ge}`)};for(const Ee of be)ys(Ee)?Ee.messages.forEach(Te):Te(Ee);return J},[be]),he=o.useCallback(J=>Fe.get(J)??bs(J)??"message-generated",[Fe]);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(ac,{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:te("session.loading.sessionMessages")})]})}):i.length===0?t.jsx(Ki,{selectedSession:c,currentSessionId:d,provider:u,setProvider:h,textareaRef:j,claudeModel:g,setClaudeModel:y,cursorModel:C,setCursorModel:k,codexModel:T,setCodexModel:w,opencodeModel:$,setOpenCodeModel:f,piModel:x,setPiModel:m,providerModelCatalog:p,providerModelActions:b,providerModelsLoading:I,tasksEnabled:E,isTaskMasterInstalled:v,onShowAllTasks:A,setInput:D}):t.jsxs(t.Fragment,{children:[q&&!le&&!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:te("session.loading.olderMessages")})]})}),M&&!q&&!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:F>0&&t.jsxs("span",{children:[te("session.messages.showingOf",{shown:R,total:F})," ",t.jsx("span",{className:"text-xs",children:te("session.messages.scrollToLoad")})]})}),t.jsx(Zi,{showLoadAllOverlay:fe,isLoadingAllMessages:le,loadAllJustFinished:oe,totalMessages:F,onLoadAllMessages:O}),!M&&i.length>U&&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:[te("session.messages.showingLast",{count:U,total:i.length})," |",t.jsx("button",{className:"ml-1 text-blue-600 underline hover:text-blue-700",onClick:B,children:te("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:O,children:te("session.messages.loadAll")})]}),(()=>{let J=null;return be.map(ue=>{if(ys(ue)){const Ee=J;return J=ue.messages[ue.messages.length-1]||J,t.jsx(Yi,{group:ue,prevMessage:Ee,createDiff:ie,getMessageKey:he,onFileOpen:me,onShowSettings:Z,onGrantToolPermission:Me,showRawParameters:xe,showThinking:K,selectedProject:ae,provider:u},`tool-group-${he(ue.messages[0])}`)}const Te=J;return J=ue,t.jsx(Sn,{message:ue,prevMessage:Te,createDiff:ie,onFileOpen:me,onShowSettings:Z,onGrantToolPermission:Me,showRawParameters:xe,showThinking:K,selectedProject:ae,provider:u},he(ue))})})()]})})]})}const lc=o.memo(oc),ic=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus","audio/ogg"];function cc(){for(const e of ic)try{if(typeof MediaRecorder<"u"&&MediaRecorder.isTypeSupported(e))return e}catch{}return""}function dc(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),h=()=>{i.current?.getTracks().forEach(C=>C.stop()),i.current=null};o.useEffect(()=>(c.current=!1,()=>{c.current=!0,d.current=!1,i.current?.getTracks().forEach(C=>C.stop()),i.current=null,n.current=null}),[]);const j=o.useCallback(async()=>{if(!(d.current||n.current&&n.current.state!=="inactive")){d.current=!0;try{const C=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0}});if(c.current){C.getTracks().forEach(w=>w.stop());return}i.current=C;const k=cc(),T=k?new MediaRecorder(C,{mimeType:k}):new MediaRecorder(C);n.current=T,l.current=[],T.ondataavailable=w=>{w.data.size>0&&l.current.push(w.data)},T.onstop=async()=>{if(h(),c.current)return;const w=u.current;u.current=!1;const $=T.mimeType||"audio/webm",f=new Blob(l.current,{type:$});if(f.size<800){a("idle"),r?.("Recording too short");return}a("transcribing");try{const x=$.includes("mp4")?"m4a":$.includes("ogg")?"ogg":"webm",m=await ji(f,`recording.${x}`);if(!m.ok)throw new Error(`transcribe ${m.status}`);const p=await m.json();if(c.current)return;const b=String(p?.text||"").trim();b?e(b,w):r?.("No speech detected")}catch(x){c.current||r?.(`Transcription failed: ${x instanceof Error?x.message:String(x)}`)}finally{c.current||a("idle")}},T.start(),a("recording")}catch(C){if(n.current=null,h(),c.current)return;const k=C;let T=`Mic error: ${k?.message||C}`;k?.name==="NotAllowedError"?T="Microphone access denied.":k?.name==="NotFoundError"&&(T="No microphone found."),r?.(T),a("idle")}finally{d.current=!1}}},[e,r]),g=o.useCallback(C=>{const k=n.current;k&&k.state!=="inactive"&&(u.current=C?.send??!1,k.stop())},[]),y=o.useCallback(()=>{s==="recording"?g():s==="idle"&&j()},[s,j,g]);return{state:s,toggle:y,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)"},uc={frequent:"Frequently Used",builtin:"Built-in Commands",skill:"Skills",project:"Project Commands",user:"User Commands",other:"Other Commands"},$s={frequent:Ya,builtin:Ar,skill:Or,project:Qa,user:Ja,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"},ht=16,mc=360,pc=160,Ct=e=>`${e.name}::${e.namespace||e.type||"other"}::${e.path||""}`,fc=e=>e.namespace||e.type||"other",xc=e=>$s[e]||$s.other,hc=e=>Ls[e]||Ls.other,gc=e=>{if(typeof window>"u")return{position:"fixed",top:"16px",left:"16px"};const r=Math.max(ht,window.innerHeight-ht-pc);if(window.innerWidth<640){const n=Math.min(Math.max(ht,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 - ${ht}px))`}}const s=Math.min(Math.max(ht,e.bottom??90),r),a=Math.max(ht,Math.min(e.left,window.innerWidth-440-ht));return{position:"fixed",bottom:`${s}px`,left:`${a}px`,width:"min(440px, calc(100vw - 32px))",maxWidth:"calc(100vw - 32px)",maxHeight:`min(${mc}px, calc(100vh - ${s}px - ${ht}px))`}};function bc({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=gc(n);if(o.useEffect(()=>{if(!l)return;const x=m=>{!c.current||!(m.target instanceof Node)||c.current.contains(m.target)||a()};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[l,a]),o.useEffect(()=>{if(!d.current||!c.current)return;const x=c.current.getBoundingClientRect(),m=d.current.getBoundingClientRect();(m.bottom>x.bottom||m.top<x.top)&&d.current.scrollIntoView({block:"nearest",behavior:"smooth"})},[r]),!l)return null;const h=i.length>0,j=new Set(i.map(Ct)),g=new Map;e.forEach((x,m)=>{const p=Ct(x),b=g.get(p)??[];b.push(m),g.set(p,b)});const y=new Map,C=x=>{const m=Ct(x),p=y.get(m)??0;y.set(m,p+1);const b=g.get(m)??[];return b[p]??b[0]??-1},k=e.reduce((x,m,p)=>{if(h&&j.has(Ct(m)))return x;const b=fc(m);return x[b]||(x[b]=[]),x[b].push({command:m,commandIndex:p,renderKey:`${b}-${p}-${Ct(m)}`}),x},{});h&&(k.frequent=i.map((x,m)=>{const p=C(x);return{command:x,commandIndex:p,renderKey:`frequent-${m}-${p}-${Ct(x)}`}}).filter(x=>x.commandIndex>=0));const T=h?["frequent","builtin","skill","project","user","other"]:["builtin","skill","project","user","other"],w=Object.keys(k).filter(x=>!T.includes(x)),$=[...T,...w].filter(x=>k[x]),f=x=>typeof document>"u"?x:Vt.createPortal(x,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:$.map(x=>t.jsxs("div",{className:"command-group",children:[$.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:uc[x]||x}),t.jsx("span",{className:"rounded border border-border bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground",children:(k[x]||[]).length})]}),(k[x]||[]).map(({command:m,commandIndex:p,renderKey:b})=>{const I=p===r,E=xc(x),v=hc(x);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&&p>=0&&s(m,p,!0),onClick:()=>s&&p>=0&&s(m,p,!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 ${v}`,children:t.jsx(E,{"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 ${m.description?"mb-1":"mb-0"}`,children:[t.jsx("span",{className:"min-w-0 truncate font-mono text-[13px] font-semibold text-foreground",title:m.name,children:m.name}),m.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:m.metadata.type})]}),m.description&&t.jsx("div",{className:"truncate whitespace-nowrap text-[12px] leading-4 text-muted-foreground",title:m.description,children:m.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(Ga,{"aria-hidden":"true",size:13,strokeWidth:2.2})})]},b)})]},x))}))}const yc=["claudeStatus.actions.thinking","claudeStatus.actions.processing","claudeStatus.actions.analyzing","claudeStatus.actions.working","claudeStatus.actions.computing","claudeStatus.actions.reasoning"],kc=["Thinking","Processing","Analyzing","Working","Computing","Reasoning"],wc=220;function vc({activity:e,onAbort:r,isInputFocused:s=!1}){const{t:a}=ze("chat"),[n,l]=o.useState(e),[i,c]=o.useState(!1),d=n?.startedAt??null,[u,h]=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)},wc);return()=>clearTimeout(w)},[e,n]),o.useEffect(()=>{if(d===null)return;const w=()=>h(Math.max(0,Math.floor((Date.now()-d)/1e3)));w();const $=setInterval(w,1e3);return()=>clearInterval($)},[d]),!n)return null;const j=yc.map((w,$)=>a(w,{defaultValue:kc[$]})),g=(n.statusText||j[Math.floor(u/4)%j.length]).replace(/\.+$/,""),y=Math.floor(u/60),C=u%60,k=y<1?a("claudeStatus.elapsed.seconds",{count:C,defaultValue:"{{count}}s"}):a("claudeStatus.elapsed.minutesSeconds",{minutes:y,seconds:C,defaultValue:"{{minutes}}m {{seconds}}s"}),T=["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:`${T} 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:`${T} 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 jc=e=>e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`,Nc=({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:jc(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(ct,{className:"h-3 w-3","aria-hidden":!0})}),i&&n&&t.jsx(vn,{src:n,alt:e.name,onClose:()=>c(!1)})]})};function Cc({state:e,onToggle:r,errorMsg:s}){const{t:a}=ze("chat"),n=e==="recording"?t.jsx(Vs,{className:"text-red-500"}):e==="transcribing"?t.jsx($t,{className:"animate-spin"}):t.jsx(Xa,{});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 Sc(e,r){In[e]=r}function Mc(e){return In[e]||null}Sc("AskUserQuestion",ii);function Tc({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=Mc(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,h=u?"Allow (saved)":"Allow & remember",j=c?e.filter(g=>as(g.toolName,os(g.input))===c).map(g=>g.requestId):[n.requestId];return t.jsxs(fa,{approval:"pending",children:[t.jsxs(xa,{className:"flex items-start gap-3",children:[t.jsx(Za,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),t.jsxs(ha,{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(ga,{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(j,{allow:!0,rememberEntry:c})},disabled:!c,children:h}),t.jsx(fr,{variant:"default",onClick:()=>r(n.requestId,{allow:!0}),children:"Allow once"})]})]},n.requestId)})}):null}const Ec=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 Ic({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:Ec(l)}),t.jsx("span",{className:"hidden text-muted-foreground/70 sm:inline",children:"tokens"})]})}function $c({content:e,attachmentCount:r=0,onEdit:s,onDelete:a}){const{t:n}=ze("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(ct,{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=h=>{const j=h.target;!a.current?.contains(j)&&!n.current?.contains(j)&&r()},u=h=>{h.key==="Escape"&&(h.preventDefault(),h.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 Lc(){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:Pe("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(Bt,{className:"h-3.5 w-3.5 text-foreground"}):null)})]})}function Rc({effort:e,effortOptions:r,onSelectEffort:s,model:a,modelOptions:n,onSelectModel:l,modelsLoading:i}){const{t:c}=ze("chat"),[d,u]=o.useState(!1),[h,j]=o.useState(!1),g=o.useCallback(()=>u(!1),[]),{triggerRef:y,menuRef:C,anchor:k,updateAnchor:T}=$n(d,g);o.useEffect(()=>{d||j(!1)},[d]);const w=c("composer.effortDefault",{defaultValue:"Default"}),$=o.useMemo(()=>r.length>0?[{value:nt},...r]:[],[r]),f=e===nt?w:e,m=o.useMemo(()=>n.find(v=>v.value===a)??null,[a,n])?.label||a,p=$.length>0,b=n.length>0||i;if(!p&&!b)return null;const I=b?m:f,E=c("composer.modelMenu",{defaultValue:"Select model and reasoning effort"});return t.jsxs(t.Fragment,{children:[t.jsxs("button",{ref:y,type:"button",onClick:()=>{T(),u(v=>!v)},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":E,title:E,children:[t.jsx("span",{className:"truncate",children:I}),b&&p&&e!==nt&&t.jsxs("span",{className:"hidden shrink-0 capitalize text-muted-foreground sm:inline",children:["· ",f]})]}),d&&k&&Vt.createPortal(t.jsxs(Ln,{anchor:k,menuRef:C,ariaLabel:E,children:[p&&t.jsxs(t.Fragment,{children:[t.jsx(Lr,{children:c("composer.reasoning",{defaultValue:"Reasoning"})}),$.map(v=>t.jsx(Zt,{label:v.value===nt?w:v.value,description:v.description,isSelected:v.value===e,onSelect:()=>{s(v.value),u(!1)},className:"capitalize"},v.value))]}),b&&t.jsxs(t.Fragment,{children:[p&&t.jsx(Lc,{}),t.jsx(Zt,{role:"menuitem",label:m,isSelected:!1,onSelect:()=>j(v=>!v),trailing:h?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"}),h&&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(v=>t.jsx(Zt,{label:v.label||v.value,isSelected:v.value===a,onSelect:()=>{l(v.value),u(!1)}},v.value))]})]})]}),document.body)]})}const Ac={default:{icon:no,trigger:"border-border/60 bg-muted/50 text-muted-foreground hover:bg-muted",item:"text-foreground"},auto:{icon:so,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:ro,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:to,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:eo,trigger:"border-primary/20 bg-primary/5 text-primary hover:bg-primary/10",item:"text-primary"}},Oc={icon:ao,trigger:"border-border/60 bg-muted/50 text-muted-foreground hover:bg-muted",item:"text-foreground"},As=e=>Ac[e]??Oc;function Pc({permissionMode:e,permissionModes:r,onSelectPermissionMode:s,providerLabel:a}){const{t:n}=ze("chat"),[l,i]=o.useState(!1),c=o.useCallback(()=>i(!1),[]),{triggerRef:d,menuRef:u,anchor:h,updateAnchor:j}=$n(l,c,352);if(r.length===0)return null;const g=As(e),y=g.icon,C=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:()=>{j(),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":C,title:n("input.clickToChangeMode"),children:t.jsx(y,{className:"h-4 w-4"})}),l&&h&&Vt.createPortal(t.jsxs(Ln,{anchor:h,menuRef:u,ariaLabel:C,children:[t.jsx(Lr,{children:C}),r.map(k=>{const T=As(k),w=T.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:T.item},k)})]}),document.body)]})}function _c({pendingPermissionRequests:e,handlePermissionDecision:r,handleGrantToolPermission:s,activity:a,isLoading:n,onAbortSession:l,permissionMode:i,availablePermissionModes:c,onSelectPermissionMode:d,providerLabel:u,effort:h,availableEffortOptions:j,onSelectEffort:g,model:y,availableModelOptions:C,onSelectModel:k,modelsLoading:T,tokenBudget:w,onShowTokenUsage:$,slashCommandsCount:f,onToggleCommandMenu:x,hasInput:m,onClearInput:p,onSubmit:b,isDragActive:I,queuedDraft:E,onEditQueuedDraft:v,onDeleteQueuedDraft:A,attachedFiles:D,onRemoveAttachment:q,uploadingFiles:M,fileErrors:F,showFileDropdown:R,filteredFiles:U,selectedFileIndex:W,onSelectFile:B,filteredCommands:O,selectedCommandIndex:z,onCommandSelect:le,onCloseCommandMenu:oe,isCommandMenuOpen:fe,frequentCommands:ie,getRootProps:me,getInputProps:Z,openAttachmentPicker:Me,inputHighlightRef:xe,renderInputWithMentions:K,textareaRef:ae,input:te,onVoiceTranscript:be,onInputChange:Fe,onTextareaClick:he,onTextareaKeyDown:J,onTextareaPaste:ue,onTextareaScrollSync:Te,onTextareaInput:Ee,isInputFocused:Ae=!1,onInputFocusChange:ge,placeholder:de,isTextareaExpanded:We,sendByCtrlEnter:Le}){const{t:ce}=ze("chat"),Re=o.useRef(null),Se=o.useRef(null),Ie=o.useMemo(()=>{if(!fe)return{top:0,left:16,bottom:90};const Q=ae.current?.getBoundingClientRect();return{top:Q?Math.max(16,Q.top-316):0,left:Q?Q.left:16,bottom:Q?window.innerHeight-Q.top+8:90}},[fe,ae]);o.useEffect(()=>{const Q=Re.current,Oe=Se.current;if(!R||!Q||!Oe)return;const _e=Oe.offsetTop,mt=_e+Oe.offsetHeight,ot=Q.scrollTop,L=ot+Q.clientHeight;_e<ot?Q.scrollTop=_e:mt>L&&(Q.scrollTop=mt-Q.clientHeight)},[W,R]);const et=Cn(),[S,N]=o.useState(null),P=o.useRef(null),V=o.useCallback(Q=>{N(Q),P.current&&clearTimeout(P.current),P.current=setTimeout(()=>N(null),4e3)},[]);o.useEffect(()=>()=>{P.current&&clearTimeout(P.current)},[]);const X=o.useCallback(()=>{},[]),{state:se,toggle:Ne,stop:we}=dc(be??X,V),ye=se==="recording",pe=se==="transcribing",tt=e.some(Q=>Q.toolName==="AskUserQuestion"),ut=e.length>0,yt=!!(a&&!ut),Ue=!!E,rt=n&&!!(te.trim()||D.length>0),Qe=rt?Ue?ce("input.hintText.updateQueued",{defaultValue:"Enter to update queued message"}):ce("input.hintText.queue",{defaultValue:"Enter to queue your next message"}):ce(Le?"input.hintText.ctrlEnter":"input.hintText.enter"),Ke=rt?Ue?ce("input.queue.update",{defaultValue:"Update queued message"}):ce("input.queue.sendNext",{defaultValue:"Queue next message"}):ce(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:[!ut&&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(vc,{activity:a,onAbort:l,isInputFocused:Ae})}),e.length>0&&t.jsx("div",{className:"mx-auto mb-3 max-w-[54.25rem]",children:t.jsx(Tc,{pendingPermissionRequests:e,handlePermissionDecision:r,handleGrantToolPermission:s})}),E&&t.jsx($c,{content:E.content,attachmentCount:E.uploadedAttachments?.length??E.attachments.length,onEdit:v,onDelete:A}),!tt&&t.jsxs("div",{className:"relative mx-auto max-w-[54.25rem]",children:[R&&U.length>0&&t.jsx("div",{ref:Re,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:U.map((Q,Oe)=>t.jsxs("div",{ref:Oe===W?Se:void 0,className:`cursor-pointer touch-manipulation border-b border-border/30 px-4 py-3 last:border-b-0 ${Oe===W?"bg-primary/8 text-primary":"text-foreground hover:bg-accent/50"}`,onMouseDown:_e=>{_e.preventDefault(),_e.stopPropagation()},onClick:_e=>{_e.preventDefault(),_e.stopPropagation(),B(Q)},children:[t.jsx("div",{className:"text-sm font-medium",children:Q.name}),t.jsx("div",{className:"font-mono text-xs text-muted-foreground",children:Q.path})]},Q.path))}),t.jsx(bc,{commands:O,selectedIndex:z,onSelect:le,onClose:oe,position:Ie,isOpen:fe,frequentCommands:ie}),t.jsxs(ba,{onSubmit:b,status:n?"streaming":"ready",className:[We?"chat-input-expanded":"",yt?"rounded-t-none":""].filter(Boolean).join(" "),...me(),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"})]})}),D.length>0&&t.jsx(ya,{children:t.jsx("div",{className:"rounded-xl bg-muted/40 p-2",children:t.jsx("div",{className:"flex flex-wrap gap-2",children:D.map((Q,Oe)=>t.jsx(Nc,{file:Q,onRemove:()=>q(Oe),uploadProgress:M.get(Q.name),error:F.get(Q.name)},`${Q.name}-${Q.lastModified}-${Oe}`))})})}),t.jsx("input",{...Z()}),t.jsxs(ka,{children:[t.jsx("div",{ref:xe,"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(te)})}),t.jsx(wa,{ref:ae,dir:"auto",value:te,onChange:Fe,onClick:he,onKeyDown:J,onPaste:ue,onScroll:Q=>Te(Q.target),onFocus:()=>ge?.(!0),onBlur:()=>ge?.(!1),onInput:Ee,placeholder:de})]}),t.jsxs(va,{children:[t.jsxs(ja,{className:"min-w-0",children:[t.jsx(Xt,{tooltip:{content:ce("input.attachFiles")},onClick:Me,"aria-label":ce("input.attachFiles"),children:t.jsx(oo,{})}),be&&et&&t.jsx(Cc,{state:se,onToggle:Ne,errorMsg:S}),t.jsx(Ic,{usage:w,onClick:$}),t.jsxs(Xt,{tooltip:{content:ce("input.showAllCommands")},onClick:x,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})]}),m&&t.jsx(Xt,{tooltip:{content:ce("input.clearInput",{defaultValue:"Clear input"})},onClick:p,className:"hidden sm:flex",children:t.jsx(ct,{})})]}),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 ${te.trim()&&!rt?"opacity-0":"opacity-100"}`,children:Qe}),t.jsx(Rc,{effort:h,effortOptions:j,onSelectEffort:g,model:y,modelOptions:C,onSelectModel:k,modelsLoading:T}),t.jsx(Pc,{permissionMode:i,permissionModes:c,onSelectPermissionMode:d,providerLabel:u}),t.jsx(Na,{onClick:rt?Q=>{Q.preventDefault(),b(Q)}:n?l:ye?Q=>{Q.preventDefault(),we({send:!0})}:void 0,disabled:n||ye?!1:pe?!0:!te.trim()&&D.length===0,"aria-label":Ke,title:Ke,className:"h-10 w-10 sm:h-10 sm:w-10",children:pe?t.jsx($t,{className:"h-4 w-4 animate-spin"}):rt?t.jsx(lo,{className:"h-4 w-4"}):void 0})]})]})]})]})]})}const Dc={claude:"Claude",cursor:"Cursor",codex:"Codex",opencode:"OpenCode"},Fc=[{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?Dc[e]||e:r,Yt=e=>Number.isFinite(e)?e.toLocaleString():"0";function Uc({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(po,{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 Bc({data:e}){const[r,s]=o.useState(""),a=Array.isArray(e.commands)&&e.commands.length>0?e.commands:Fc,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 qc({data:e,providerModelCatalog:r,providerModelActions:s,activeProvider:a,activeProviderModel:n,currentSessionId:l,onSelectProviderModel:i}){const[c,d]=o.useState(""),[u,h]=o.useState(null),[j,g]=o.useState(null),[y,C]=o.useState(null),[k,T]=o.useState(!1),w=e?.current?.provider||"claude",$=a===w?n:j??e?.current?.model??"Unknown",f=e?.current?.providerLabel||Fr(w),x=r[w],m=o.useMemo(()=>x?.OPTIONS&&x.OPTIONS.length>0?x.OPTIONS:Array.isArray(e?.availableOptions)&&e.availableOptions.length>0?e.availableOptions:(Array.isArray(e?.availableModels)?e.availableModels:[]).map(A=>({value:A,label:A})),[e,x]),p=o.useMemo(()=>{const v=c.trim().toLowerCase();return v?m.filter(A=>`${A.value} ${A.label||""} ${A.description||""}`.toLowerCase().includes(v)):m},[m,c]),b=typeof l=="string"&&l.trim().length>0,I=m.length>6,E=async v=>{h(v);try{const A=await i(w,v,l);if(A.scope==="session"){g(A.model),C(`This session now uses ${A.model}.`);return}g(null),C(`Default ${f} model set to ${A.model}.`)}catch(A){const D=A instanceof Error?A.message:"Unable to change the model right now.";C(D)}finally{h(null)}};return k?t.jsx(Mn,{initialProvider:w,providerModelCatalog:r,actions:s,onDone:()=>T(!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:$}),j&&j!==$&&t.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-[0.14em] text-emerald-500 dark:text-emerald-400",children:["→ ",j," next"]})]})]}),t.jsxs(Ye,{type:"button",variant:"outline",size:"sm",onClick:()=>T(!0),className:"h-9 shrink-0 rounded-xl bg-background px-3 text-xs",children:[t.jsx(qt,{className:"h-3.5 w-3.5"}),"Manage models"]})]}),I&&t.jsx(Rn,{value:c,onChange:d,placeholder:`Search ${f} models...`}),p.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:p.map((v,A)=>{const D=v.value===$,q=v.value===j,M=v.value===u;return t.jsxs("button",{type:"button",onClick:()=>E(v.value),disabled:!!u,"aria-label":`Select model ${v.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 ${D?"border-primary/45 bg-primary/10":q?"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:v.label||v.value}),t.jsxs("span",{className:"flex shrink-0 items-center gap-2",children:[v.isCustom&&t.jsx(jt,{className:"rounded-full px-2 py-0 text-[9px]",children:"Custom"}),D?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]})]}),v.label!==v.value&&t.jsx("span",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground",children:v.value}),v.description&&t.jsx("span",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:v.description}),D&&t.jsx("span",{className:"mt-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-primary",children:"Current selection"}),q&&!D&&t.jsx("span",{className:"mt-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-emerald-500 dark:text-emerald-400",children:"Session model"})]},v.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:y?t.jsx("span",{className:"text-foreground",children:y}):b?"Your choice is saved for this session and becomes the default for new chats.":"Your choice becomes the default model for new chats."})]})}function Vc({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 Hc({data:e}){const r=e.memoryUsage?.rssMb,s=[{label:"Package",value:e.packageName||"claude-code-ui",icon:co},{label:"Version",value:e.version||"Unknown",icon:Qs,tone:"success"},{label:"Uptime",value:e.uptime||"Unknown",icon:uo},{label:"Provider",value:Fr(e.provider,e.provider||"Unknown"),icon:mo,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(Uc,{label:a.label,value:String(a.value),icon:a.icon,tone:a.tone},a.label))})]})}function zc({payload:e,onClose:r,providerModelCatalog:s,providerModelActions:a,activeProvider:n,activeProviderModel:l,currentSessionId:i,onSelectProviderModel:c}){const d=!!e,u=e?.kind,h=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:io},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,y=g?.icon||Or;return t.jsx(Sr,{open:d,onOpenChange:C=>!C&&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 ${h?"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 ${h?"h-9 w-9":"h-10 w-10"}`,children:t.jsx(y,{className:h?"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(Ye,{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(ct,{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(Bc,{data:e.data}),e?.kind==="models"&&t.jsx(qc,{data:e.data,providerModelCatalog:s,providerModelActions:a,activeProvider:n,activeProviderModel:l,currentSessionId:i,onSelectProviderModel:c}),e?.kind==="cost"&&t.jsx(Vc,{data:e.data}),e?.kind==="status"&&t.jsx(Hc,{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(Ye,{type:"button",variant:"outline",size:"sm",onClick:r,className:"rounded-xl",children:"Close"})]})]})})}function Wc({isActive:e,selectedProject:r,selectedSession:s,ws:a,sendMessage:n,onFileOpen:l,onInputFocusChange:i,onSessionProcessing:c,onSessionIdle:d,processingSessions:u,onNavigateToSession:h,onSessionEstablished:j,onShowSettings:g,showRawParameters:y,showThinking:C,sendByCtrlEnter:k,externalMessageUpdate:T,newSessionTrigger:w,onShowAllTasks:$}){const{tasksEnabled:f,isTaskMasterInstalled:x}=Ca(),{subscribe:m}=Sa(),{t:p}=ze("chat"),b=Rl(),I=o.useRef(null),E=o.useRef(""),v=o.useRef(new Map),A=o.useRef(new Map),D=o.useCallback(()=>{I.current&&(clearTimeout(I.current),I.current=null),E.current=""},[]),{provider:q,setProvider:M,cursorModel:F,setCursorModel:R,claudeModel:U,setClaudeModel:W,codexModel:B,setCodexModel:O,currentProviderEffort:z,currentProviderEffortOptions:le,currentProviderModel:oe,currentProviderModelOptions:fe,opencodeModel:ie,setOpenCodeModel:me,piModel:Z,setPiModel:Me,permissionMode:xe,pendingPermissionRequests:K,setPendingPermissionRequests:ae,availablePermissionModes:te,selectPermissionMode:be,cyclePermissionMode:Fe,providerModelCatalog:he,providerModelsLoading:J,providerModelActions:ue,selectProviderModel:Te,selectProviderEffort:Ee,resolvePermissionModeForProvider:Ae}=Ho({selectedSession:s,selectedProject:r}),{chatMessages:ge,addMessage:de,sessionActivity:We,isProcessing:Le,canAbortSession:ce,currentSessionId:Re,setCurrentSessionId:Se,isLoadingSessionMessages:Ie,isLoadingMoreMessages:et,hasMoreMessages:S,totalMessages:N,isUserScrolledUp:P,setIsUserScrolledUp:V,tokenBudget:X,setTokenBudget:se,visibleMessageCount:Ne,visibleMessages:we,loadEarlierMessages:ye,loadAllMessages:pe,allMessagesLoaded:tt,isLoadingAllMessages:ut,loadAllJustFinished:yt,showLoadAllOverlay:Ue,createDiff:rt,scrollContainerRef:Qe,scrollToBottom:Ke,scrollToBottomAndReset:Q,handleScroll:Oe,requestLatestMessages:_e}=sl({isActive:e,selectedProject:r,selectedSession:s,ws:a,sendMessage:n,externalMessageUpdate:T,newSessionTrigger:w,processingSessions:u,onSessionIdle:d,resetStreamingState:D,statusCheckSentAtRef:v,lastSeqRef:A,sessionStore:b}),mt=o.useCallback((De,Xe)=>{Se(De),j?.(De,Xe),h?.(De)},[Se,j,h]),{input:ot,setInput:L,textareaRef:G,inputHighlightRef:ee,isTextareaExpanded:ne,slashCommandsCount:ve,filteredCommands:Ce,frequentCommands:Be,commandQuery:pt,showCommandMenu:ft,selectedCommandIndex:lt,resetCommandMenuState:kt,handleCommandSelect:_,handleToggleCommandMenu:Y,showFileDropdown:H,filteredFiles:re,selectedFileIndex:ke,renderInputWithMentions:qe,selectFile:wt,attachedFiles:at,setAttachedFiles:st,uploadingFiles:vt,fileErrors:Nt,getRootProps:xt,getInputProps:zt,isDragActive:cr,openAttachmentPicker:Ve,handleSubmit:je,queuedDraft:He,editQueuedDraft:Ge,deleteQueuedDraft:At,handleVoiceTranscript:dr,handleInputChange:An,handleKeyDown:On,handlePaste:Pn,handleTextareaClick:_n,handleTextareaInput:Dn,syncInputOverlayScroll:Fn,handleClearInput:Un,handleAbortSession:ur,handlePermissionDecision:mr,handleGrantToolPermission:Ur,handleInputFocusChange:Bn,isInputFocused:qn,commandModalPayload:Vn,closeCommandModal:Hn,showCostModal:zn}=kl({selectedProject:r,selectedSession:s,currentSessionId:Re,provider:q,permissionMode:xe,cyclePermissionMode:Fe,currentProviderModel:oe,currentProviderEffort:z,isLoading:Le,processingSessions:u,canAbortSession:ce,tokenBudget:X,sendMessage:n,sendByCtrlEnter:k,onSessionProcessing:c,onSessionEstablished:mt,onInputFocusChange:i,onFileOpen:l,onShowSettings:g,scrollToBottom:Ke,addMessage:de,setIsUserScrolledUp:V,setPendingPermissionRequests:ae,resolvePermissionModeForProvider:Ae}),Wn=o.useCallback(async()=>{!r||!s||(await _e(s.id,e),v.current.set(s.id,Date.now()),n({type:"chat.subscribe",sessions:[{sessionId:s.id,lastSeq:A.current.get(s.id)??0}]}))},[e,_e,r,s,n]);cl({isActive:e,subscribe:m,provider:q,selectedSession:s,currentSessionId:Re,setTokenBudget:se,pendingPermissionRequests:K,setPendingPermissionRequests:ae,streamTimerRef:I,accumulatedStreamRef:E,lastSeqRef:A,statusCheckSentAtRef:v,onSessionProcessing:c,onSessionIdle:d,onWebSocketReconnect:Wn,requestLatestMessages:_e,sessionStore:b}),o.useEffect(()=>{if(!ce)return;const De=Xe=>{Xe.key!=="Escape"||Xe.repeat||Xe.defaultPrevented||(Xe.preventDefault(),ur())};return document.addEventListener("keydown",De,{capture:!0}),()=>{document.removeEventListener("keydown",De,{capture:!0})}},[ce,ur]),o.useEffect(()=>()=>{D()},[D]);const Kn=o.useMemo(()=>({pendingPermissionRequests:K,handlePermissionDecision:mr}),[K,mr]),Gn=o.useCallback(async De=>{try{await Te(q,De,Re||s?.id||null)}catch(Xe){console.error("Error changing the active session model:",Xe)}},[Re,q,Te,s?.id]),Jn=o.useCallback(async De=>{try{await Ee(q,De,Re||s?.id||null)}catch(Xe){console.error("Error changing the active session reasoning effort:",Xe)}},[Re,q,Ee,s?.id]),Qn=!!(We&&K.length===0),pr=q==="cursor"?p("messageTypes.cursor"):q==="codex"?p("messageTypes.codex"):q==="opencode"?p("messageTypes.opencode",{defaultValue:"OpenCode"}):p("messageTypes.claude");return r?t.jsxs(Ys.Provider,{value:Kn,children:[t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[t.jsx(lc,{scrollContainerRef:Qe,onWheel:Oe,onTouchMove:Oe,isLoadingSessionMessages:Ie,isProcessing:Le,hasActivityIndicator:Qn,chatMessages:ge,selectedSession:s,currentSessionId:Re,provider:q,setProvider:De=>M(De),textareaRef:G,claudeModel:U,setClaudeModel:W,cursorModel:F,setCursorModel:R,codexModel:B,setCodexModel:O,opencodeModel:ie,setOpenCodeModel:me,piModel:Z,setPiModel:Me,providerModelCatalog:he,providerModelActions:ue,providerModelsLoading:J,tasksEnabled:f,isTaskMasterInstalled:x,onShowAllTasks:$,setInput:L,isLoadingMoreMessages:et,hasMoreMessages:S,totalMessages:N,sessionMessagesCount:ge.length,visibleMessageCount:Ne,visibleMessages:we,loadEarlierMessages:ye,loadAllMessages:pe,allMessagesLoaded:tt,isLoadingAllMessages:ut,loadAllJustFinished:yt,showLoadAllOverlay:Ue,createDiff:rt,onFileOpen:l,onShowSettings:g,onGrantToolPermission:Ur,showRawParameters:y,showThinking:C,selectedProject:r}),t.jsxs("div",{className:"relative flex-shrink-0",children:[P&&ge.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:Q,"aria-label":p("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:p("input.scrollToBottom",{defaultValue:"Scroll to bottom"}),children:t.jsx(fo,{className:"h-4 w-4","aria-hidden":!0})})}),t.jsx(_c,{pendingPermissionRequests:K,handlePermissionDecision:mr,handleGrantToolPermission:Ur,activity:We,isLoading:Le,onAbortSession:ur,permissionMode:xe,availablePermissionModes:te,onSelectPermissionMode:De=>be(De),providerLabel:pr,effort:z,availableEffortOptions:le,onSelectEffort:Jn,model:oe,availableModelOptions:fe,onSelectModel:Gn,modelsLoading:J,tokenBudget:X,onShowTokenUsage:zn,slashCommandsCount:ve,onToggleCommandMenu:Y,hasInput:!!ot.trim(),onClearInput:Un,onSubmit:je,isDragActive:cr,queuedDraft:He,onEditQueuedDraft:Ge,onDeleteQueuedDraft:At,attachedFiles:at,onRemoveAttachment:De=>st(Xe=>Xe.filter((Kc,Yn)=>Yn!==De)),uploadingFiles:vt,fileErrors:Nt,showFileDropdown:H,filteredFiles:re,selectedFileIndex:ke,onSelectFile:wt,filteredCommands:Ce,selectedCommandIndex:lt,onCommandSelect:_,onCloseCommandMenu:kt,isCommandMenuOpen:ft,frequentCommands:pt?[]:Be,getRootProps:xt,getInputProps:zt,openAttachmentPicker:Ve,inputHighlightRef:ee,renderInputWithMentions:qe,textareaRef:G,input:ot,onVoiceTranscript:dr,onInputChange:An,onTextareaClick:_n,onTextareaKeyDown:On,onTextareaPaste:Pn,onTextareaScrollSync:Fn,onTextareaInput:Dn,isInputFocused:qn,onInputFocusChange:Bn,placeholder:p("input.placeholder",{provider:pr}),isTextareaExpanded:ne,sendByCtrlEnter:k})]})]}),t.jsx(zc,{payload:Vn,onClose:Hn,providerModelCatalog:he,providerModelActions:ue,activeProvider:q,activeProviderModel:oe,currentSessionId:Re||s?.id||null,onSelectProviderModel:Te})]}):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:p("projectSelection.startChatWithProvider",{provider:pr,defaultValue:"Select a project to start chatting with {{provider}}"})})})})}const Zc=er.memo(Wc);export{Zc as C,zl as M,Fi as T,_i as a,ns as c,dn as r};
|