@kimiclaw/cli 1.0.42 → 1.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +19 -21
  2. package/bin/dscode.exe +4 -0
  3. package/install.cjs +15 -0
  4. package/package.json +9 -9
  5. package/web/dist/assets/AssistantsView-Y4TXobGE.js +1 -0
  6. package/web/dist/assets/AutomationView-DfAF2L92.js +3 -0
  7. package/web/dist/assets/Button-D-g7PgYh.js +1 -0
  8. package/web/dist/assets/ChannelConfigView-WJ-zUV8p.js +12 -0
  9. package/web/dist/assets/ChartsView-CSAfGqTC.js +1 -0
  10. package/web/dist/assets/ConnectorsView-DaHmxnGE.js +2 -0
  11. package/web/dist/assets/{MessageBubble-CVGXupVH.js → DiffPreview-D8tIj_aF.js} +64 -67
  12. package/web/dist/assets/FileContextMenu-C5WYeBNu.js +1 -0
  13. package/web/dist/assets/FileTreeView-B7IN0KmE.js +1 -0
  14. package/web/dist/assets/HookConfigView-9gqvrRhQ.js +2 -0
  15. package/web/dist/assets/InboxView-BcEfijbj.js +1 -0
  16. package/web/dist/assets/InputArea-D5F91Uwk.js +14 -0
  17. package/web/dist/assets/Install-Cuelo0If.js +2 -0
  18. package/web/dist/assets/MemoryView-BvZSh5-T.js +1 -0
  19. package/web/dist/assets/ModelsView-BgvMN8xv.js +1 -0
  20. package/web/dist/assets/PluginsView-C3d6e8vV.js +1 -0
  21. package/web/dist/assets/ProjectsView-CM7GOsoK.js +1 -0
  22. package/web/dist/assets/SessionGrid-BQSrCDqQ.js +4 -0
  23. package/web/dist/assets/SettingsModal-BvGXq5EE.js +4 -0
  24. package/web/dist/assets/SkillsView-87kGRliE.js +1 -0
  25. package/web/dist/assets/TemplatesTab-8MLwVNwV.js +1 -0
  26. package/web/dist/assets/ToolsView-CjdYiaNz.js +1 -0
  27. package/web/dist/assets/{agentIconSet-B5GUQwel.js → agentIconSet-CDeMxTHf.js} +1 -1
  28. package/web/dist/assets/api-ZQf0Ys8y.js +1 -0
  29. package/web/dist/assets/channelMeta-BO645sjD.js +1 -0
  30. package/web/dist/assets/common-CPZxdYLs.js +304 -0
  31. package/web/dist/assets/icons-B8Ngx6rM.js +1 -0
  32. package/web/dist/assets/imageUrl-CrQM4gmf.js +74 -0
  33. package/web/dist/assets/index-Bm7r92T3.css +1 -0
  34. package/web/dist/assets/index-STsyoFCk.js +145 -0
  35. package/web/dist/assets/installDiagnosis-ZYUVgJIJ.js +3 -0
  36. package/web/dist/assets/{markdown-N5__3T-w.js → markdown-Cps-36Z5.js} +1 -1
  37. package/web/dist/assets/{panels-CIPgN61N.js → panels-DCwx2Pbu.js} +1 -1
  38. package/web/dist/assets/{react-vendor-CB4cLN-6.js → react-vendor-CXI113IS.js} +1 -1
  39. package/web/dist/assets/sessionKind-CZ1kQQII.js +1 -0
  40. package/web/dist/assets/{settingsStore-Xqln0d91.js → settingsStore-BSdi9gNd.js} +1 -1
  41. package/web/dist/assets/src-BK8SoTFV.js +1 -0
  42. package/web/dist/assets/{state-CSZ50keL.js → state-pOTP5BEk.js} +1 -1
  43. package/web/dist/assets/statusAxesRefresh--2evRuAU.js +1 -0
  44. package/web/dist/assets/sttLanguages-BPcOF0nQ.js +2 -0
  45. package/web/dist/assets/{types-JssxRFJn.js → threads-lr33dwqg.js} +1 -1
  46. package/web/dist/assets/useConfirm-CQjBnYuP.js +1 -0
  47. package/web/dist/assets/{useTranslation-B-mfApCn.js → useTranslation-gGKZZfux.js} +1 -1
  48. package/web/dist/assets/websocket-CeKJTCdp.js +1 -0
  49. package/web/dist/assets/whatsNewStore-C0hbStfc.js +1 -0
  50. package/web/dist/assets/{workspaceSemantics-RaIRer76.js → workspaceSemantics-CW8ytHq2.js} +3 -3
  51. package/web/dist/favicon.svg +31 -14
  52. package/web/dist/icons/icon-1024.png +0 -0
  53. package/web/dist/icons/icon-180.png +0 -0
  54. package/web/dist/icons/icon-192.png +0 -0
  55. package/web/dist/icons/icon-512.png +0 -0
  56. package/web/dist/icons/icon-maskable-512.png +0 -0
  57. package/web/dist/index.html +38 -35
  58. package/web/dist/logo.svg +42 -20
  59. package/web/dist/manifest.webmanifest +2 -2
  60. package/web/dist/assets/AssistantsView-Ct3BBpYf.js +0 -1
  61. package/web/dist/assets/AutomationView-CO-jVhee.js +0 -3
  62. package/web/dist/assets/ChannelConfigView-Ct1W584x.js +0 -8
  63. package/web/dist/assets/ChartsView-CAc37Sam.js +0 -1
  64. package/web/dist/assets/ConnectorsView-DP4bbh58.js +0 -1
  65. package/web/dist/assets/FileTreeView-DwsYfssO.js +0 -1
  66. package/web/dist/assets/HookConfigView-uFsqieii.js +0 -2
  67. package/web/dist/assets/InputArea-BY8quOiH.js +0 -14
  68. package/web/dist/assets/MemoryView-Bgd_lcTf.js +0 -1
  69. package/web/dist/assets/ModelsView-B271UV9L.js +0 -1
  70. package/web/dist/assets/PluginsView-Dz4fqQR1.js +0 -2
  71. package/web/dist/assets/ProjectsView-DF-YCV8y.js +0 -1
  72. package/web/dist/assets/SessionGrid-BIREstN2.js +0 -4
  73. package/web/dist/assets/SettingsModal-ZJeoZcCd.js +0 -4
  74. package/web/dist/assets/SkillsView-CH2ghYL2.js +0 -1
  75. package/web/dist/assets/TemplatesTab-BGe7_67s.js +0 -1
  76. package/web/dist/assets/ThreadsView-XditIHZ4.js +0 -2
  77. package/web/dist/assets/ToolsView-BBzsFdVZ.js +0 -1
  78. package/web/dist/assets/api-plEYhRn0.js +0 -1
  79. package/web/dist/assets/channelMeta-BGQXQxgj.js +0 -1
  80. package/web/dist/assets/common-Bbatsa0-.js +0 -192
  81. package/web/dist/assets/icons-CYDRRPKW.js +0 -1
  82. package/web/dist/assets/index-CTbLW314.js +0 -133
  83. package/web/dist/assets/index-DdzVrZye.css +0 -1
  84. package/web/dist/assets/src-49LUQhkG.js +0 -1
  85. package/web/dist/assets/sttLanguages-CSNMgUTz.js +0 -2
  86. package/web/dist/assets/ttsSettings-BwXYpDnk.js +0 -2
  87. package/web/dist/assets/useConfirm-Da8iQ_DZ.js +0 -1
  88. package/web/dist/assets/websocket-BnDwh01e.js +0 -1
  89. package/web/dist/assets/whatsNewStore-LpdLRLGl.js +0 -1
  90. /package/web/dist/assets/{MessageBubble-CCTRbIMZ.css → DiffPreview-CCTRbIMZ.css} +0 -0
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{$t as t,A as n,Ar as r,Br as i,Dr as a,Dt as o,E as s,Er as c,G as l,Gn as u,Ht as d,Ir as f,It as p,Jn as m,Mr as ee,On as te,Ot as h,R as ne,Rt as re,Tn as ie,Un as ae,Ur as oe,W as se,Yn as g,Z as ce,_ as le,_r as ue,at as de,bn as fe,cn as pe,ct as _,d as v,ei as me,en as he,ft as ge,ir as _e,ln as ve,ni as ye,nn as be,nr as y,or as b,r as x,s as S,sn as C,sr as w,u as T,w as E,wn as D,zr as O}from"./icons-B8Ngx6rM.js";import{r as k}from"./react-vendor-CXI113IS.js";import{t as A}from"./useTranslation-gGKZZfux.js";import{i as j,n as M}from"./Button-D-g7PgYh.js";import{t as N}from"./api-ZQf0Ys8y.js";import{I as xe}from"./markdown-Cps-36Z5.js";var P=e(ye(),1),Se=k(),F=xe();function I(e){window.dispatchEvent(new CustomEvent(`preview-file`,{detail:{path:e}}))}var Ce=24,we=1.7;function L(e,t,n=1.15){return(0,F.jsx)(`circle`,{cx:e,cy:t,r:n,fill:`currentColor`,stroke:`none`})}function R(e,t,n=we){let r=(0,P.forwardRef)(function({size:e=Ce,strokeWidth:r=n,className:i,...a},o){let{absoluteStrokeWidth:s,nonScalingStroke:c,...l}=a;return(0,F.jsx)(`svg`,{ref:o,xmlns:`http://www.w3.org/2000/svg`,width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:r,strokeLinecap:`round`,strokeLinejoin:`round`,className:i,"aria-hidden":`true`,...l,children:t})});return r.displayName=`DomainGlyph(${e})`,r}var z={turn:R(`turn`,(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8.4`}),L(12,3.6,1.9),(0,F.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2.4`})]})),context:R(`context`,(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`path`,{d:`M8.2 4H5.6v16h2.6`}),(0,F.jsx)(`path`,{d:`M15.8 4h2.6v16h-2.6`}),L(12,8.4),L(12,12),L(12,15.6)]})),compact:R(`compact`,(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`path`,{d:`M12 3.4v6.2`}),(0,F.jsx)(`path`,{d:`M8.8 6.8 12 10 15.2 6.8`}),(0,F.jsx)(`path`,{d:`M12 20.6v-6.2`}),(0,F.jsx)(`path`,{d:`M8.8 17.2 12 14 15.2 17.2`}),(0,F.jsx)(`path`,{d:`M4.6 12h14.8`})]})),token:R(`token`,(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`path`,{d:`M12 3.4 20.6 12 12 20.6 3.4 12z`}),(0,F.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2.6`})]})),subagent:R(`subagent`,(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`circle`,{cx:`9.2`,cy:`15`,r:`5`}),(0,F.jsx)(`circle`,{cx:`18.3`,cy:`6.6`,r:`2.4`}),(0,F.jsx)(`path`,{d:`M12.9 11.6 16.5 8.2`})]})),workflow:R(`workflow`,(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`circle`,{cx:`5.4`,cy:`12`,r:`2.2`}),(0,F.jsx)(`circle`,{cx:`18.6`,cy:`6.4`,r:`2.2`}),(0,F.jsx)(`circle`,{cx:`18.6`,cy:`17.6`,r:`2.2`}),(0,F.jsx)(`path`,{d:`M7.6 12h6.4`}),(0,F.jsx)(`path`,{d:`M14 12V6.4h2.4`}),(0,F.jsx)(`path`,{d:`M14 12v5.6h2.4`})]})),gate:R(`gate`,(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`path`,{d:`M6.6 4.4v15.2`}),(0,F.jsx)(`path`,{d:`M17.4 4.4v15.2`}),(0,F.jsx)(`path`,{d:`M6.6 9.6h10.8`}),(0,F.jsx)(`path`,{d:`M6.6 14.4h10.8`})]})),router:R(`router`,(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`path`,{d:`M3.4 12h5.4`}),(0,F.jsx)(`path`,{d:`M8.8 12 12.4 6.2 17.6 6.2`}),(0,F.jsx)(`path`,{d:`M8.8 12h8.8`}),(0,F.jsx)(`path`,{d:`M8.8 12 12.4 17.8 17.6 17.8`}),(0,F.jsx)(`circle`,{cx:`19.4`,cy:`6.2`,r:`1.8`}),(0,F.jsx)(`circle`,{cx:`19.4`,cy:`12`,r:`1.8`}),(0,F.jsx)(`circle`,{cx:`19.4`,cy:`17.8`,r:`1.8`})]}))},Te=Object.keys(z),B={rating:s,difficulty:fe,distance:d,location:d,price:ue,time:w,duration:w,people:v,servings:v,tag:E,date:ee,level:be,heat:te,diet:t,food:T,drink:_e,stock:o,category:se},V={app:me,appFallback:oe,cart:ne,code:b,bookmark:i,prev:a,next:c,image:ve,sparkle:n,info:C,dot:g},H={chat:p,projects:ie,charts:r,assistants:O,templates:he,models:f,tools:x,skills:n,channels:de,connectors:ge,plugins:_,hooks:S,insights:le,inbox:pe,scheduled:w,memory:h,logs:ce,settings:l,pluginFallback:_},Ee={Activity:`insights`,BarChart3:`charts`,Bot:`assistants`,Brain:`models`,Clock:`scheduled`,Database:`memory`,FolderKanban:`projects`,Layers:`templates`,MessageSquare:`chat`,Plug:`connectors`,Puzzle:`plugins`,Radio:`channels`,ScrollText:`logs`,Settings:`settings`,Sparkles:`skills`,Webhook:`hooks`,Wrench:`tools`};function De(e){if(!e)return H.pluginFallback;if(e in H)return H[e];let t=Ee[e];return t?H[t]:H.pluginFallback}function Oe(e){return e?B[e]??ke(e)??g:g}function ke(e){return e in z?z[e]:void 0}[...Object.entries(B).map(([e,t])=>({name:e,icon:t})),...Object.entries(V).map(([e,t])=>({name:`ui.${e}`,icon:t})),...Object.entries(H).map(([e,t])=>({name:`nav.${e}`,icon:t})),...Te.map(e=>({name:`glyph.${e}`,icon:z[e]}))];var U=null;function Ae(e){U=e}var W=null;function je(e){W=e}function Me(e){W===e&&(W=null)}function Ne(e){return W?(W(e),!0):!1}function Pe(e){U===e&&(U=null)}function Fe(e){return U?(U(e),!0):!1}function Ie(e,t={}){let n=t.width??200,r=t.height??170;return{x:Math.max(4,Math.min(e.clientX,window.innerWidth-n)),y:Math.max(4,Math.min(e.clientY,window.innerHeight-r))}}var Le=28,Re=9,ze=8;function G(e,t=0){return e*Le+t*Re+ze}var K=1;function q(e){return e?e.getBoundingClientRect():null}function J(e,t,n){if(!t||!t.isConnected)return!1;let r=e.target;if(r instanceof Node&&!r.contains(t))return!0;if(n){let e=t.getBoundingClientRect();if(Math.abs(e.top-n.top)<K&&Math.abs(e.left-n.left)<K)return!0}return!1}var Y=(0,P.memo)(function({items:e,position:t,onClose:n,anchor:r,ariaLabel:i,minWidth:a=168}){let o=t!==null,{visible:s,phase:c}=M(o),l=(0,P.useRef)(t);t&&(l.current=t);let u=t??l.current,d=(0,P.useRef)(null);return(0,P.useLayoutEffect)(()=>{d.current=o?q(r):null},[o,r]),(0,P.useEffect)(()=>{if(!o)return;let e=()=>n(),t=e=>{e.key===`Escape`&&n()},i=e=>{J(e,r,d.current)||n()};return window.addEventListener(`click`,e),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,i,!0),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,i,!0),window.removeEventListener(`keydown`,t)}},[o,n,r]),!s||!u?null:(0,Se.createPortal)((0,F.jsx)(`div`,{role:`menu`,"aria-label":i,"data-phase":c,className:`fixed z-[9999] rounded-lg border border-dark-border bg-dark-overlay ui-surface-overlay py-1 shadow-[0_10px_32px_rgba(0,0,0,0.28)] ui-overlay-panel-fade`,style:{left:u.x,top:u.y,minWidth:a},onClick:e=>e.stopPropagation(),onContextMenu:e=>e.preventDefault(),children:e.map(e=>{if(e.kind===`separator`)return(0,F.jsx)(`div`,{role:`separator`,className:`my-1 h-px bg-dark-border/60`},e.id);let t=e.icon;return(0,F.jsxs)(`button`,{role:`menuitem`,disabled:e.disabled,onClick:()=>{n(),e.onSelect()},className:`flex w-full items-center gap-2 rounded-md px-2.5 py-1.5 text-start text-xs transition-colors ${e.disabled?`cursor-not-allowed text-dark-muted/35`:`text-dark-muted hover:bg-dark-hover hover:text-dark-text`}`,children:[t?(0,F.jsx)(t,{size:13,"aria-hidden":`true`,className:`shrink-0 opacity-70`}):null,(0,F.jsx)(`span`,{className:`truncate`,children:e.label})]},e.id)})}),document.body)});function Be(e){return typeof Element<`u`&&e instanceof Element?e:null}function X(){let[e,t]=(0,P.useState)(null),n=(0,P.useCallback)((e,n,r,i,a)=>{t({...Ie({clientX:e,clientY:n},i),data:r,anchor:a??null})},[]);return{state:e,open:(0,P.useCallback)((e,t,r,i)=>{e.preventDefault(),e.stopPropagation(),n(e.clientX,e.clientY,t,r,i??Be(e.target))},[n]),openAt:n,close:(0,P.useCallback)(()=>t(null),[])}}function Z(e){return e.success?{ok:!0}:{ok:!1,error:e.error||`unknown error`}}var Q={open:e=>N.fs.open(e,`open`).then(Z),reveal:e=>N.fs.open(e,`reveal`).then(Z),openFolder:e=>N.fs.openFolder(e).then(Z),download:e=>N.files.download(e).then(Z)},$=208,Ve=G(6,1);function He(){let{t:e}=A(),{state:t,open:n,close:r}=X(),i=t?.data??null,a=(0,P.useCallback)((e,t)=>n(e,t,{width:$,height:Ve}),[n]),o=(0,P.useCallback)((e,t)=>{e.then(e=>{e.ok||j.error(e.error||t)})},[]),s=(0,P.useMemo)(()=>i?[{id:`preview`,label:e(`fileMenu.preview`),icon:ae,onSelect:()=>I(i)},{id:`openExternal`,label:e(`fileMenu.openExternal`),icon:u,onSelect:()=>o(Q.open(i),e(`fileMenu.openFailed`))},{id:`reveal`,label:e(`fileMenu.reveal`),icon:D,onSelect:()=>o(Q.reveal(i),e(`fileMenu.revealFailed`))},{kind:`separator`,id:`sep-after-open`},{id:`addToChat`,label:e(`fileMenu.addToChat`),icon:re,onSelect:()=>{Fe(i)||j.warning(e(`fileMenu.noComposer`))}},{id:`copyPath`,label:e(`fileMenu.copyPath`),icon:y,onSelect:()=>{navigator.clipboard?.writeText(i).then(()=>j.success(e(`fileMenu.copied`)),()=>{})}},{id:`download`,label:e(`fileMenu.download`),icon:m,onSelect:()=>o(Q.download(i),e(`fileMenu.downloadFailed`))}]:[],[i,e,o]);return{openFileMenu:a,menuNode:(0,F.jsx)(Y,{items:s,position:t?{x:t.x,y:t.y}:null,anchor:t?.anchor??null,onClose:r,ariaLabel:e(`fileMenu.aria`),minWidth:$})}}export{q as a,Ne as c,Pe as d,Me as f,I as g,De as h,Y as i,Ae as l,Oe as m,Q as n,J as o,V as p,X as r,G as s,He as t,je as u};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{$ as t,Dr as n,Er as r,Jn as i,Or as ee,Y as a,dn as o,it as s,kn as c,m as l,ni as u,xn as te,yn as d}from"./icons-B8Ngx6rM.js";import{t as ne}from"./react-vendor-CXI113IS.js";import{t as re}from"./useTranslation-gGKZZfux.js";import{i as f,r as p}from"./Button-D-g7PgYh.js";import{t as m}from"./api-ZQf0Ys8y.js";import{I as h}from"./markdown-Cps-36Z5.js";import{t as g}from"./useConfirm-CQjBnYuP.js";import{Ct as _}from"./index-STsyoFCk.js";var v=e(u(),1),y=h();function b(e){return{ts:`typescript`,tsx:`typescript`,js:`javascript`,jsx:`javascript`,py:`python`,rs:`rust`,go:`go`,rb:`ruby`,json:`json`,xml:`xml`,html:`html`,css:`css`,scss:`scss`,md:`markdown`,yaml:`yaml`,yml:`yaml`,toml:`toml`,sql:`sql`,sh:`shell`,bat:`bat`,ps1:`powershell`,dockerfile:`dockerfile`,properties:`properties`,c:`c`,cpp:`cpp`,h:`c`,hpp:`cpp`,cs:`csharp`,vue:`html`,svelte:`html`,svg:`xml`}[e.split(`.`).pop()?.toLowerCase()||``]||`plaintext`}function x(){let{t:e}=re(),[u,h]=g(),[x,S]=(0,v.useState)([]),[C,w]=(0,v.useState)(null),[T,E]=(0,v.useState)(``),[ie,D]=(0,v.useState)(``),[ae,O]=(0,v.useState)(!1),[k,oe]=(0,v.useState)(``),[A,j]=(0,v.useState)(!1),[M,N]=(0,v.useState)(!1),[P,F]=(0,v.useState)(!1),[I,se]=(0,v.useState)(``),L=(0,v.useRef)(null),R=_(e=>e.status?.branch),z=_(e=>e.status?.available),[B,V]=(0,v.useState)(0),H=(0,v.useRef)(void 0);(0,v.useEffect)(()=>{C?(O(!0),m.files.read(C).then(t=>{if(t.success&&t.data){let e=typeof t.data==`string`?t.data:JSON.stringify(t.data);E(e),D(e)}else f.error(t.error||e(`fileTree.readFail`))}).catch(()=>f.error(e(`fileTree.readFail`))).finally(()=>O(!1))):(E(``),D(``))},[C,B]);let U=async e=>{j(!0);try{let t=await m.files.list(e);t.success&&Array.isArray(t.data)&&S(t.data.map(e=>({...e,expanded:!1})))}finally{j(!1)}};(0,v.useEffect)(()=>{H.current===void 0?H.current=R:R!==H.current&&(H.current=R,V(e=>e+1),U())},[R]);let W=async e=>{if(e.type===`directory`)try{let t=await m.files.list(e.path);if(t.success&&Array.isArray(t.data)){let n=t.data.map(e=>({...e,expanded:!1}));S(t=>G(t,e.id,n))}}catch{}},G=(e,t,n)=>e.map(e=>e.id===t?{...e,children:n,expanded:!0}:e.children?{...e,children:G(e.children,t,n)}:e);(0,v.useEffect)(()=>{U()},[]);let ce=e=>{let t=q(x,e);t&&t.type===`directory`&&!t.children?W(t):S(t=>K(t,e))},K=(e,t)=>e.map(e=>e.id===t&&e.type===`directory`?{...e,expanded:!e.expanded}:e.children?{...e,children:K(e.children,t)}:e),q=(e,t)=>{for(let n of e){if(n.id===t)return n;if(n.children){let e=q(n.children,t);if(e)return e}}return null},J=(e,t)=>t?e.reduce((e,n)=>{if(n.name.toLowerCase().includes(t.toLowerCase()))e.push(n);else if(n.children){let r=J(n.children,t);r.length>0&&e.push({...n,children:r,expanded:!0})}return e},[]):e,le=(0,v.useCallback)(async()=>{if(C){N(!0);try{let t=await m.files.update(C,T);t.success?(D(T),f.success(e(`fileTree.saved`))):f.error(t.error||e(`fileTree.saveFail`))}catch{f.error(e(`fileTree.saveFail`))}finally{N(!1)}}},[C,T,e]),Y=()=>{w(null),E(``),D(``)},X=(0,v.useCallback)(async t=>{let n=await m.files.download(t);n.success?f.success(e(`fileTree.downloadStarted`)):f.error(n.error||e(`fileTree.downloadFail`))},[e]),ue=()=>L.current?.click(),de=(0,v.useCallback)(async t=>{if(!t||t.length===0)return;let n=I||(C?C.replace(/[\\/][^\\/]+$/,``):``);F(!0);let r=0,i=0;for(let e of Array.from(t)){let t=n?`${n}/${e.name}`:e.name;(await m.files.upload(e,t)).success?r++:i++}F(!1),r>0&&f.success(e(`fileTree.uploadedCount`,{count:r})),i>0&&f.error(e(`fileTree.uploadFailedCount`,{count:i})),await U()},[I,C,e]),Z=T!==ie,Q=async()=>!Z||h({message:e(`fileTree.discardConfirm`,{file:C||``}),variant:`danger`}),fe=async()=>{await Q()&&Y()},$=(t,n=0)=>{let a=t.type===`directory`,o=C===t.path,s=I===t.path;return(0,y.jsxs)(`div`,{children:[(0,y.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-0.5 cursor-pointer rounded text-xs transition-colors max-md:w-max max-md:min-w-full ${o?`bg-accent-blue/20 text-accent-blue`:s?`bg-accent-blue/10`:`hover:bg-dark-hover`}`,style:{paddingLeft:`${n*14+6}px`},onClick:()=>a?(se(t.path),ce(t.id)):w(t.path),title:a?e(`fileTree.setUploadDirHint`):t.path,children:[a&&(0,y.jsx)(`span`,{className:`text-dark-muted shrink-0`,children:t.expanded?(0,y.jsx)(ee,{size:12}):(0,y.jsx)(r,{size:12})}),a?(0,y.jsx)(te,{size:12,className:`text-accent-yellow shrink-0`}):(0,y.jsx)(`span`,{className:`w-3`}),(0,y.jsx)(`span`,{className:`truncate flex-1`,children:t.name}),!a&&(0,y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),X(t.path)},className:`opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-dark-border text-dark-muted hover:text-dark-text shrink-0 max-md:opacity-100`,title:e(`fileTree.download`),children:(0,y.jsx)(i,{size:11})})]}),a&&t.expanded&&t.children?.map(e=>$(e,n+1))]},t.id)},pe=k?J(x,k):x;return(0,y.jsxs)(`div`,{className:`flex-1 flex overflow-hidden`,children:[u,(0,y.jsxs)(`div`,{className:p(`flex flex-col overflow-hidden flex-1 min-h-0`,C&&`hidden`),children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-dark-border`,children:[z&&R&&(0,y.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1 text-meta text-dark-muted`,title:R,children:[(0,y.jsx)(d,{size:12,className:`shrink-0 text-accent-blue/80`,"aria-hidden":`true`}),(0,y.jsx)(`span`,{className:`truncate font-mono`,children:R})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-0.5 ms-auto`,children:[(0,y.jsx)(`button`,{onClick:ue,disabled:P,className:`p-1 rounded hover:bg-dark-hover disabled:opacity-50`,title:I?e(`fileTree.uploadTo`,{dir:I}):e(`fileTree.uploadToRoot`),children:(0,y.jsx)(l,{size:12,className:P?`animate-pulse`:``})}),(0,y.jsx)(`button`,{onClick:()=>U(),disabled:A,className:`p-1 rounded hover:bg-dark-hover`,title:e(`fileTree.refresh`),children:(0,y.jsx)(s,{size:12,className:A?`animate-spin`:``})}),(0,y.jsx)(`button`,{onClick:()=>{(async()=>{await Q()&&(S(x.map(e=>({...e,expanded:!1}))),Y())})()},className:`p-1 rounded hover:bg-dark-hover`,title:e(`fileTree.collapse`),children:(0,y.jsx)(o,{size:12})})]})]}),(0,y.jsx)(`div`,{className:`p-1.5 border-b border-dark-border`,children:(0,y.jsxs)(`div`,{className:`relative`,children:[(0,y.jsx)(a,{size:12,className:`absolute start-2 top-1/2 -translate-y-1/2 text-dark-muted`}),(0,y.jsx)(`input`,{type:`text`,value:k,onChange:e=>oe(e.target.value),placeholder:e(`fileTree.searchPlaceholder`),className:`w-full ps-6 pe-2 py-1 text-xs bg-dark-bg border border-dark-border rounded focus:border-accent-blue focus:outline-none`})]})}),(0,y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar py-1 max-md:overflow-x-auto`,children:pe.map(e=>$(e))}),(0,y.jsx)(`input`,{ref:L,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{de(e.target.files),e.currentTarget.value=``}})]}),(0,y.jsx)(`div`,{className:p(`flex-1 flex flex-col min-w-0 bg-dark-bg`,!C&&`hidden`),children:C?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-dark-border bg-dark-surface max-md:gap-2`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs min-w-0`,children:[(0,y.jsx)(`button`,{onClick:()=>void fe(),className:`p-0.5 -ms-1 rounded hover:bg-dark-hover text-dark-muted hover:text-dark-text shrink-0`,title:e(`fileTree.backToList`),"aria-label":e(`fileTree.backToList`),"data-testid":`file-tree-back`,children:(0,y.jsx)(n,{size:13})}),(0,y.jsx)(c,{size:12,className:`text-dark-muted shrink-0`}),(0,y.jsx)(`span`,{className:`truncate`,children:C}),Z&&(0,y.jsxs)(`span`,{className:`text-accent-yellow text-badge shrink-0`,children:[`● `,e(`fileTree.modified`)]})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,y.jsxs)(`button`,{onClick:le,disabled:!Z||M,className:`px-2 py-0.5 text-badge rounded flex items-center gap-1 transition-colors ${Z?`bg-accent-green text-accent-fg hover:opacity-90`:`bg-dark-border text-dark-muted cursor-not-allowed`}`,children:[(0,y.jsx)(t,{size:10}),e(M?`fileTree.saving`:`fileTree.save`)]}),(0,y.jsx)(`button`,{onClick:()=>void X(C),className:`p-1 rounded hover:bg-dark-hover`,title:e(`fileTree.download`),children:(0,y.jsx)(i,{size:12})})]})]}),(0,y.jsx)(`div`,{className:`flex-1 min-h-0`,children:ae?(0,y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,y.jsx)(`div`,{className:`w-4 h-4 border-2 border-accent-blue border-t-transparent rounded-full animate-spin`})}):(0,y.jsx)(ne,{language:b(C),value:T,onChange:e=>E(e||``),theme:`vs-dark`,options:{fontSize:13,fontFamily:`"Cascadia Code", "Fira Code", Consolas, monospace`,minimap:{enabled:!0,renderCharacters:!1,maxColumn:80,showSlider:`mouseover`},lineNumbers:`on`,scrollBeyondLastLine:!1,wordWrap:`on`,automaticLayout:!0,tabSize:2}})})]}):(0,y.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,y.jsxs)(`div`,{className:`text-center`,children:[(0,y.jsx)(c,{size:32,className:`text-dark-muted mx-auto mb-2`}),(0,y.jsx)(`p`,{className:`text-sm text-dark-muted`,children:e(`fileTree.selectFileHint`)})]})})})]})}export{x as FileTreeView};
@@ -0,0 +1,2 @@
1
+ import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{A as t,D as n,Dr as r,Er as i,Jn as a,Or as o,Qt as s,V as c,Z as l,b as u,dt as d,it as f,k as p,m,n as h,ni as g,pt as _,v,vt as y,y as b}from"./icons-B8Ngx6rM.js";import{t as x}from"./useTranslation-gGKZZfux.js";import{n as S}from"./state-pOTP5BEk.js";import{n as C,t as w}from"./Button-D-g7PgYh.js";import{t as T}from"./api-ZQf0Ys8y.js";import{I as E}from"./markdown-Cps-36Z5.js";import{r as D,t as O}from"./useConfirm-CQjBnYuP.js";import"./common-CPZxdYLs.js";var k=e(g(),1),A=S((e,t)=>({rules:[],templates:[],stats:null,events:[],agents:[],loading:!1,error:null,fieldErrors:null,formOpen:!1,editingRule:null,draftRule:null,dryRunResult:null,loadRules:async()=>{let t=await T.hooks.list();t.success&&Array.isArray(t.data)?e({rules:t.data}):t.success&&t.data&&!Array.isArray(t.data)?e({error:`服务端返回的规则数据格式异常`}):e({error:t.error||`Failed to load rules`})},loadTemplates:async()=>{let t=await T.hooks.templates();t.success&&Array.isArray(t.data)?e({templates:t.data}):t.success&&t.data&&!Array.isArray(t.data)&&e({error:`服务端返回的模板数据格式异常`})},loadStats:async()=>{let t=await T.hooks.stats();t.success&&t.data&&e({stats:t.data})},loadEvents:async()=>{let t=await T.hooks.events();t.success&&Array.isArray(t.data)?e({events:t.data}):t.success&&t.data&&!Array.isArray(t.data)&&e({error:`服务端返回的事件数据格式异常`})},loadAgents:async()=>{let t=await T.hooks.agents();t.success&&Array.isArray(t.data)?e({agents:t.data}):t.success&&t.data&&!Array.isArray(t.data)&&e({error:`服务端返回的Agent数据格式异常`})},loadAll:async()=>{e({loading:!0,error:null});try{await Promise.all([t().loadRules(),t().loadTemplates(),t().loadStats(),t().loadEvents(),t().loadAgents()])}catch(t){e({error:String(t)})}finally{e({loading:!1})}},createRule:async n=>{e({fieldErrors:null});let r=await T.hooks.create(n);if(r.success)return await t().loadRules(),await t().loadStats(),e({formOpen:!1,editingRule:null}),!0;if(r.error){e({error:r.error});try{let t=JSON.parse(r.error);t.fieldErrors&&e({fieldErrors:t.fieldErrors})}catch{}}return!1},updateRule:async(n,r)=>{e({fieldErrors:null});let i=await T.hooks.update(n,r);return i.success?(await t().loadRules(),await t().loadStats(),e({formOpen:!1,editingRule:null}),!0):(e({error:i.error||`Update failed`}),!1)},deleteRule:async n=>{let r=await T.hooks.delete(n);return r.success?(await t().loadRules(),await t().loadStats(),!0):(e({error:r.error||`Delete failed`}),!1)},batchDelete:async n=>{let r=await T.hooks.batchDelete(n);return r.success?(await t().loadRules(),await t().loadStats(),!0):(e({error:r.error||`Batch delete failed`}),!1)},toggleRule:async(n,r)=>(await T.hooks.toggle(n,r)).success?(e(e=>({rules:e.rules.map(e=>e.name===n?{...e,enabled:r}:e)})),await t().loadStats(),!0):(await t().loadRules(),!1),batchToggle:async(n,r)=>(await T.hooks.batchToggle(n,r)).success?(e(e=>({rules:e.rules.map(e=>n.includes(e.name)?{...e,enabled:r}:e)})),await t().loadStats(),!0):(await t().loadRules(),!1),dryRun:async t=>{let n=await T.hooks.dryRun(t);return n.success&&n.data?(e({dryRunResult:n.data}),n.data):(e({error:n.error||`Dry-run failed`}),null)},openForm:t=>e({formOpen:!0,editingRule:t||null,draftRule:null,dryRunResult:null,fieldErrors:null}),openFormFromTemplate:(t,n)=>e({formOpen:!0,editingRule:null,draftRule:{...t.rule,description:n||t.rule.description},dryRunResult:null,fieldErrors:null}),closeForm:()=>e({formOpen:!1,editingRule:null,draftRule:null,dryRunResult:null,fieldErrors:null}),setDryRunResult:t=>e({dryRunResult:t}),clearError:()=>e({error:null}),clearFieldErrors:()=>e({fieldErrors:null})})),j=E(),M={SYSTEM:`bg-accent-red/15 text-accent-red`,SECURITY:`bg-accent-orange/15 text-accent-orange`,PROJECT:`bg-accent-blue/15 text-accent-blue`,USER:`bg-accent-green/15 text-accent-green`,PLUGIN:`bg-accent-purple/15 text-accent-purple`},N={SHELL:`bg-accent-yellow/15 text-accent-yellow`,HTTP:`bg-accent-cyan/15 text-accent-cyan`,PROMPT:`bg-accent-purple/15 text-accent-purple`,AGENT:`bg-accent-blue/15 text-accent-blue`};function P({rules:e,onEdit:t}){let{t:r}=x(),[i,a]=O(),{toggleRule:o,deleteRule:s,batchDelete:c,batchToggle:l}=A(),[u,d]=(0,k.useState)(new Set),[f,m]=(0,k.useState)(!1),h=Array.isArray(e)?e:[];if(h.length===0)return(0,j.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-3 py-16 text-dark-muted`,children:[(0,j.jsx)(`div`,{className:`text-4xl opacity-60`,children:`🪝`}),(0,j.jsx)(`p`,{className:`text-sm`,children:r(`hook.noRules`)}),(0,j.jsx)(`p`,{className:`text-xs text-dark-muted/70`,children:r(`hook.noRulesHint`)})]});let g=e=>{let t=new Set(u);t.has(e)?t.delete(e):t.add(e),d(t),m(t.size===h.length)},_=()=>{f?(d(new Set),m(!1)):(d(new Set(h.map(e=>e.name))),m(!0))},b=async()=>{u.size!==0&&await a({message:r(`hook.batchDeleteConfirm`,{n:u.size}),variant:`danger`})&&(c(Array.from(u)),d(new Set),m(!1))},S=e=>{u.size!==0&&(l(Array.from(u),e),d(new Set),m(!1))};return(0,j.jsxs)(`div`,{className:`flex flex-1 flex-col min-h-0`,children:[i,u.size>0&&(0,j.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-lg border border-accent-blue/30 bg-accent-blue/5 px-3 py-1.5 text-sm`,children:[(0,j.jsx)(`span`,{className:`text-dark-muted`,children:r(`hook.selectedItems`,{n:u.size})}),(0,j.jsx)(`button`,{onClick:()=>S(!0),className:`rounded bg-accent-green/15 px-2 py-0.5 text-accent-green transition-colors hover:bg-accent-green/25`,children:r(`hook.enableAll`)}),(0,j.jsx)(`button`,{onClick:()=>S(!1),className:`rounded bg-dark-hover px-2 py-0.5 text-dark-text transition-colors hover:bg-dark-border`,children:r(`hook.disableAll`)}),(0,j.jsx)(`button`,{onClick:()=>void b(),className:`rounded bg-accent-red/15 px-2 py-0.5 text-accent-red transition-colors hover:bg-accent-red/25`,children:r(`common.delete`)})]}),(0,j.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto custom-scrollbar rounded-xl border border-dark-border`,children:(0,j.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,j.jsx)(`thead`,{className:`sticky top-0 bg-dark-hover text-dark-muted`,children:(0,j.jsxs)(`tr`,{children:[(0,j.jsx)(`th`,{className:`w-8 p-2.5`,children:(0,j.jsx)(`button`,{onClick:_,children:f?(0,j.jsx)(p,{size:14}):(0,j.jsx)(n,{size:14})})}),(0,j.jsx)(`th`,{className:`p-2.5 text-start font-medium`,children:r(`hook.colName`)}),(0,j.jsx)(`th`,{className:`p-2.5 text-start font-medium`,children:r(`hook.colEvents`)}),(0,j.jsx)(`th`,{className:`p-2.5 text-start font-medium`,children:r(`hook.colType`)}),(0,j.jsx)(`th`,{className:`p-2.5 text-start font-medium`,children:r(`hook.fieldPriority`)}),(0,j.jsx)(`th`,{className:`p-2.5 text-start font-medium`,children:r(`hook.colStatus`)}),(0,j.jsx)(`th`,{className:`p-2.5 text-end font-medium`,children:r(`hook.colActions`)})]})}),(0,j.jsx)(`tbody`,{className:`divide-y divide-dark-border`,children:h.map(e=>(0,j.jsxs)(`tr`,{className:`transition-colors hover:bg-dark-hover/50`,children:[(0,j.jsx)(`td`,{className:`p-2.5`,children:(0,j.jsx)(`button`,{onClick:()=>g(e.name),children:u.has(e.name)?(0,j.jsx)(p,{size:14,className:`text-accent-blue`}):(0,j.jsx)(n,{size:14,className:`text-dark-muted`})})}),(0,j.jsxs)(`td`,{className:`p-2.5`,children:[(0,j.jsx)(`div`,{className:`font-medium text-dark-text`,children:e.name}),e.description&&(0,j.jsx)(`div`,{className:`mt-0.5 max-w-[220px] truncate text-xs text-dark-muted`,children:e.description})]}),(0,j.jsx)(`td`,{className:`p-2.5`,children:(0,j.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[Array.isArray(e.events)&&e.events.slice(0,3).map(e=>(0,j.jsx)(`span`,{className:`rounded bg-dark-hover px-1.5 py-0.5 text-xs text-dark-text`,children:e},e)),Array.isArray(e.events)&&e.events.length>3&&(0,j.jsxs)(`span`,{className:`px-1 py-0.5 text-xs text-dark-muted`,children:[`+`,e.events.length-3]})]})}),(0,j.jsx)(`td`,{className:`p-2.5`,children:(0,j.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-xs font-medium ${N[e.implementationType]||`bg-dark-hover text-dark-muted`}`,children:e.implementationType})}),(0,j.jsx)(`td`,{className:`p-2.5`,children:(0,j.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-xs font-medium ${M[e.priority]||`bg-dark-hover text-dark-muted`}`,children:e.priority})}),(0,j.jsx)(`td`,{className:`p-2.5`,children:(0,j.jsx)(`button`,{onClick:()=>o(e.name,!e.enabled),className:`relative h-5 w-9 rounded-full transition-colors ${e.enabled?`bg-accent-green`:`bg-dark-border`}`,title:e.enabled?r(`hook.clickToDisable`):r(`hook.clickToEnable`),children:(0,j.jsx)(`span`,{className:`absolute top-0.5 block h-3.5 w-3.5 rounded-full bg-white transition-all ${e.enabled?`start-[18px]`:`start-[2px]`}`})})}),(0,j.jsx)(`td`,{className:`p-2.5`,children:(0,j.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,j.jsx)(`button`,{onClick:()=>t(e),className:`rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-blue`,title:r(`hook.actionEdit`),children:(0,j.jsx)(y,{size:14})}),(0,j.jsx)(`button`,{onClick:()=>{(async()=>{await a({message:r(`hook.deleteRuleConfirm`,{name:e.name}),variant:`danger`})&&s(e.name)})()},className:`rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-red`,title:r(`common.delete`),children:(0,j.jsx)(v,{size:14})})]})})]},e.name))})]})})]})}var F={name:``,description:``,events:[],implementationType:`SHELL`,command:``,url:``,promptTemplate:``,agentName:``,priority:`USER`,tools:[],matcherToolNamePattern:``,matcherFromState:``,matcherToState:``,timeoutMs:3e4,enabled:!0,failOpen:!0,onFailure:`fail-open`,scope:`project`},I=[{value:`SYSTEM`,label:`SYSTEM (100)`},{value:`SECURITY`,label:`SECURITY (80)`},{value:`PROJECT`,label:`PROJECT (60)`},{value:`USER`,label:`USER (40)`},{value:`PLUGIN`,label:`PLUGIN (20)`}],L=e=>`w-full rounded-lg border bg-dark-bg px-3 py-2 text-sm text-dark-text placeholder-dark-muted/60 transition-colors focus:outline-none focus:ring-2 ${e?`border-accent-red focus:border-accent-red focus:ring-accent-red/20`:`border-dark-border focus:border-accent-blue focus:ring-accent-blue/20`}`,R=`mb-1 block text-xs font-medium text-dark-muted`;function z({isOpen:e,events:t,agents:n}){let{t:a}=x(),{editingRule:o,draftRule:s,fieldErrors:c,dryRunResult:l,createRule:u,updateRule:d,closeForm:f,dryRun:p,setDryRunResult:m,clearFieldErrors:g}=A(),{visible:v,phase:y}=C(e),b=[{value:`SHELL`,label:a(`hook.implShell`),desc:a(`hook.implShellDesc`)},{value:`HTTP`,label:a(`hook.implHttp`),desc:a(`hook.implHttpDesc`)},{value:`PROMPT`,label:`LLM Prompt`,desc:a(`hook.implPromptDesc`)},{value:`AGENT`,label:`AI Agent`,desc:a(`hook.implAgentDesc`)}],S=Array.isArray(t)?t:[],T=Array.isArray(n)?n:[],[E,D]=(0,k.useState)(0),[O,M]=(0,k.useState)(F),[N,P]=(0,k.useState)(``),[z,B]=(0,k.useState)(``),[V,H]=(0,k.useState)(``),U=o??s;(0,k.useEffect)(()=>{if(!e)return;D(0),P(``),M(U?{name:U.name,description:U.description||``,events:U.events,implementationType:U.implementationType,command:U.command||``,url:U.url||``,promptTemplate:U.promptTemplate||``,agentName:U.agentName||``,priority:U.priority,tools:U.tools||[],matcherToolNamePattern:U.matchers?.toolNamePattern||``,matcherFromState:U.matchers?.fromState||``,matcherToState:U.matchers?.toState||``,timeoutMs:U.timeoutMs,enabled:U.enabled,failOpen:U.failOpen,onFailure:U.onFailure||(U.failOpen?`fail-open`:`block`),scope:U.scope||`project`}:F);let t=(U?.matchers?.toolNamePattern||``).trim().replace(/^\^|\$$/g,``);B(/^[A-Za-z0-9_]+$/.test(t)?t:``),H(``)},[e,U]);let W=(e,t)=>{M(n=>({...n,[e]:t})),g()},G=e=>{M(t=>({...t,events:t.events.includes(e)?t.events.filter(t=>t!==e):[...t.events,e]}))},K=e=>{e.every(e=>O.events.includes(e))?M(t=>({...t,events:t.events.filter(t=>!e.includes(t))})):M(t=>({...t,events:[...new Set([...t.events,...e])]}))},q=async()=>{let e={};O.matcherToolNamePattern&&(e.toolNamePattern=O.matcherToolNamePattern),O.matcherFromState&&(e.fromState=O.matcherFromState),O.matcherToState&&(e.toState=O.matcherToState);let t={...O,tools:O.tools.length>0?O.tools:[]};t.matchers=e,delete t.matcherToolNamePattern,delete t.matcherFromState,delete t.matcherToState,o?await d(o.name,t):await u(t)},J=async()=>{m(null);let e={};O.matcherToolNamePattern&&(e.toolNamePattern=O.matcherToolNamePattern),await p({hook:{name:O.name||`dry-run`,description:O.description,events:O.events,implementationType:O.implementationType,command:O.command,url:O.url,promptTemplate:O.promptTemplate,agentName:O.agentName,priority:O.priority,tools:O.tools,matchers:e,timeoutMs:O.timeoutMs,enabled:!0,failOpen:O.failOpen,onFailure:O.onFailure,scope:O.scope},eventType:O.events[0]||`PRE_TOOL_USE`,toolName:z.trim(),toolInput:V.trim()})},Y=N?S.map(e=>({...e,events:Array.isArray(e.events)?e.events.filter(e=>e.name.toLowerCase().includes(N.toLowerCase())||e.summary.includes(N)):[]})).filter(e=>e.events.length>0):S,X=[{title:a(`hook.stepBasicTitle`),desc:a(`hook.stepBasicDesc`)},{title:a(`hook.stepImplTitle`),desc:a(`hook.stepImplDesc`)},{title:a(`hook.stepAdvancedTitle`),desc:a(`hook.stepAdvancedDesc`)}];return v?(0,j.jsxs)(`div`,{className:`fixed inset-0 z-50 flex justify-end`,children:[(0,j.jsx)(`div`,{className:`absolute inset-0 ui-scrim ui-overlay-backdrop`,"data-phase":y,onClick:f}),(0,j.jsxs)(`div`,{className:`relative flex h-full w-[560px] flex-col border-s border-dark-border bg-dark-bg shadow-2xl ui-overlay-panel-edge max-md:w-full`,"data-phase":y,children:[(0,j.jsxs)(`div`,{className:`flex flex-shrink-0 items-center justify-between border-b border-dark-border px-4 py-3.5`,children:[(0,j.jsx)(`h3`,{className:`text-base font-semibold text-dark-text`,children:o?a(`hook.editRule`,{name:o.name}):a(`hook.addRule`)}),(0,j.jsx)(`button`,{onClick:f,className:`rounded-lg p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,children:(0,j.jsx)(h,{size:18})})]}),(0,j.jsx)(`div`,{className:`flex flex-shrink-0 border-b border-dark-border`,children:X.map((e,t)=>{let n=t===E,r=t<E;return(0,j.jsxs)(`button`,{onClick:()=>D(t),className:`relative flex-1 border-b-2 px-2 py-2.5 text-center text-xs transition-colors ${n?`border-accent-blue bg-accent-blue/5 text-accent-blue`:r?`border-transparent text-dark-text`:`border-transparent text-dark-muted hover:text-dark-text`}`,children:[(0,j.jsx)(`span`,{className:`me-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-badge ${n?`bg-accent-blue text-accent-fg`:r?`bg-accent-green text-accent-fg`:`bg-dark-hover text-dark-muted`}`,children:r?`✓`:t+1}),(0,j.jsx)(`span`,{className:`font-medium`,children:e.title})]},e.title)})}),(0,j.jsxs)(`div`,{className:`flex-1 min-h-0 space-y-4 overflow-auto custom-scrollbar p-4`,children:[c&&Object.keys(c).length>0&&(0,j.jsx)(`div`,{className:`rounded-lg border border-accent-red/40 bg-accent-red/10 p-2.5 text-xs text-accent-red`,children:Object.entries(c).map(([e,t])=>(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`strong`,{children:[e,`:`]}),` `,t]},e))}),E===0&&(0,j.jsxs)(`div`,{className:`space-y-4`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:a(`hook.fieldName`)}),(0,j.jsx)(`input`,{value:O.name,onChange:e=>W(`name`,e.target.value),placeholder:`my-custom-hook`,className:L(c?.name)})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:a(`hook.fieldDescription`)}),(0,j.jsx)(`textarea`,{value:O.description,onChange:e=>W(`description`,e.target.value),placeholder:a(`hook.descriptionPlaceholder`),rows:2,className:L()})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:`Scope`}),(0,j.jsxs)(`select`,{value:O.scope,onChange:e=>W(`scope`,e.target.value),className:L(),children:[(0,j.jsx)(`option`,{value:`project`,children:`project (.agent/hooks.json)`}),(0,j.jsx)(`option`,{value:`user`,children:`user (~/.agent/hooks.json)`}),(0,j.jsx)(`option`,{value:`local`,children:`local (.agent/hooks.local.json)`})]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[(0,j.jsx)(`label`,{className:`text-xs font-medium text-dark-muted`,children:a(`hook.fieldEvents`)}),(0,j.jsx)(`span`,{className:`text-xs text-accent-blue`,children:a(`hook.eventsSelected`,{n:O.events.length})})]}),(0,j.jsx)(`input`,{value:N,onChange:e=>P(e.target.value),placeholder:a(`hook.searchEventsPlaceholder`),className:L()+` mb-2`}),(0,j.jsx)(`div`,{className:`max-h-[280px] space-y-2 overflow-auto custom-scrollbar rounded-lg border border-dark-border bg-dark-surface p-2`,children:Y.map(e=>(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`button`,{onClick:()=>K(e.events.map(e=>e.name)),className:`mb-1 text-xs font-medium text-dark-muted transition-colors hover:text-dark-text`,children:[e.category,` — `,a(`hook.toggleAllEvents`)]}),e.events.map(e=>{let t=O.events.includes(e.name);return(0,j.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-1 py-1 transition-colors hover:bg-dark-hover`,children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>G(e.name),className:`h-3.5 w-3.5 accent-accent-blue`}),(0,j.jsx)(`span`,{className:`text-xs text-dark-text`,children:e.name}),(0,j.jsxs)(`span`,{className:`truncate text-xs text-dark-muted`,children:[`— `,e.summary]})]},e.name)})]},e.category))})]})]}),E===1&&(0,j.jsxs)(`div`,{className:`space-y-4`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:a(`hook.fieldImplType`)}),(0,j.jsx)(`div`,{className:`grid grid-cols-2 gap-2 max-md:grid-cols-1`,children:b.map(e=>{let t=O.implementationType===e.value;return(0,j.jsxs)(`button`,{onClick:()=>W(`implementationType`,e.value),className:`rounded-lg border p-3 text-start transition-colors ${t?`border-accent-blue bg-accent-blue/10 ring-1 ring-accent-blue/30`:`border-dark-border bg-dark-surface hover:bg-dark-hover`}`,children:[(0,j.jsx)(`div`,{className:`text-sm font-medium ${t?`text-accent-blue`:`text-dark-text`}`,children:e.label}),(0,j.jsx)(`div`,{className:`mt-1 text-xs text-dark-muted`,children:e.desc})]},e.value)})})]}),O.implementationType===`SHELL`&&(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:a(`hook.fieldCommand`)}),(0,j.jsx)(`textarea`,{value:O.command,onChange:e=>W(`command`,e.target.value),placeholder:`python3 .agent/hooks/audit.py
2
+ 或 node -e "…"(WINDOWS 下命令内不要出现第二个双引号)`,rows:4,spellCheck:!1,className:`resize-y font-mono leading-relaxed ${L(c?.command)}`})]}),O.implementationType===`HTTP`&&(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:`URL *`}),(0,j.jsx)(`input`,{value:O.url,onChange:e=>W(`url`,e.target.value),placeholder:`https://example.com/hooks/audit`,className:L(c?.url)})]}),O.implementationType===`PROMPT`&&(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:a(`hook.fieldPromptTemplate`)}),(0,j.jsx)(`textarea`,{value:O.promptTemplate,onChange:e=>W(`promptTemplate`,e.target.value),placeholder:a(`hook.promptTemplatePlaceholder`),rows:5,className:`font-mono ${L(c?.promptTemplate)}`})]}),O.implementationType===`AGENT`&&(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:`Agent *`}),(0,j.jsxs)(`select`,{value:O.agentName,onChange:e=>W(`agentName`,e.target.value),className:L(c?.agentName),children:[(0,j.jsx)(`option`,{value:``,children:a(`hook.selectAgentPlaceholder`)}),T.map(e=>(0,j.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.description,`)`]},e.id))]}),(0,j.jsx)(`p`,{className:`mt-1 text-xs text-dark-muted`,children:a(`hook.agentReadOnlyHint`)})]})]}),E===2&&(0,j.jsxs)(`div`,{className:`space-y-4`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:a(`hook.fieldPriority`)}),(0,j.jsx)(`select`,{value:O.priority,onChange:e=>W(`priority`,e.target.value),className:L(),children:I.map(e=>(0,j.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,j.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 max-md:grid-cols-1`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:a(`hook.fieldTimeout`)}),(0,j.jsx)(`input`,{type:`number`,value:O.timeoutMs,onChange:e=>W(`timeoutMs`,parseInt(e.target.value)||3e4),min:100,max:3e5,step:1e3,className:L()})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,j.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-dark-text`,children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:O.enabled,onChange:e=>W(`enabled`,e.target.checked),className:`h-3.5 w-3.5 accent-accent-blue`}),a(`hook.labelEnabled`)]}),(0,j.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-dark-text`,children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:O.failOpen,onChange:e=>W(`failOpen`,e.target.checked),className:`h-3.5 w-3.5 accent-accent-blue`}),a(`hook.failOpenLabel`)]}),(0,j.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-dark-text`,title:a(`hook.onFailureHint`),children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:O.onFailure===`block`,onChange:e=>{let t=e.target.checked;M(e=>({...e,onFailure:t?`block`:`fail-open`,failOpen:!t&&e.failOpen})),g()},className:`h-3.5 w-3.5 accent-accent-blue`}),a(`hook.onFailureLabel`)]})]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:a(`hook.fieldToolFilter`)}),(0,j.jsx)(`input`,{value:O.matcherToolNamePattern,onChange:e=>W(`matcherToolNamePattern`,e.target.value),placeholder:`Bash.*|FileWrite.*`,className:`font-mono ${L()}`})]}),O.events.some(e=>e.includes(`STATE`))&&(0,j.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 max-md:grid-cols-1`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:`From State`}),(0,j.jsx)(`input`,{value:O.matcherFromState,onChange:e=>W(`matcherFromState`,e.target.value),className:L()})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:`To State`}),(0,j.jsx)(`input`,{value:O.matcherToState,onChange:e=>W(`matcherToState`,e.target.value),className:L()})]})]}),l&&(0,j.jsxs)(`div`,{className:`rounded-lg border border-dark-border bg-dark-surface p-3`,children:[(0,j.jsx)(`div`,{className:`mb-2 text-xs font-medium text-dark-text`,children:a(`hook.dryRunResultTitle`)}),(0,j.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`span`,{className:`text-dark-muted`,children:a(`hook.dryRunDecision`)}),(0,j.jsx)(`span`,{className:String(l.decision).toUpperCase()===`ALLOW`?`text-accent-green`:String(l.decision).toUpperCase()===`DENY`?`text-accent-red`:`text-accent-yellow`,children:l.decision}),typeof l.durationMs==`number`&&(0,j.jsxs)(`span`,{className:`ms-2 text-dark-muted`,children:[l.durationMs,`ms`]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`span`,{className:`text-dark-muted`,children:a(`hook.dryRunReason`)}),(0,j.jsx)(`span`,{className:`text-dark-text`,children:l.reason})]}),l.contextOutput&&(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`span`,{className:`text-dark-muted`,children:a(`hook.dryRunOutput`)}),(0,j.jsx)(`pre`,{className:`mt-1 max-h-40 overflow-auto whitespace-pre-wrap break-all font-mono text-meta text-dark-text`,children:l.contextOutput})]})]})]}),(0,j.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:a(`hook.dryRunSampleTool`)}),(0,j.jsx)(`input`,{value:z,onChange:e=>B(e.target.value),placeholder:`bash / write_file / apply_patch`,className:`font-mono ${L()}`})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:R,children:a(`hook.dryRunSampleInput`)}),(0,j.jsx)(`input`,{value:V,onChange:e=>H(e.target.value),placeholder:`{"command":"rm -rf /tmp/x"}`,className:`font-mono ${L()}`})]})]}),(0,j.jsxs)(`button`,{onClick:J,className:`inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-1.5 text-xs text-dark-text transition-colors hover:bg-dark-hover`,children:[(0,j.jsx)(_,{size:12}),` `,a(`hook.dryRunButton`)]})]})]}),(0,j.jsxs)(`div`,{className:`flex flex-shrink-0 items-center justify-between border-t border-dark-border px-4 py-3`,children:[(0,j.jsx)(`div`,{className:`flex gap-2`,children:E>0&&(0,j.jsx)(w,{size:`sm`,onClick:()=>D(E-1),leftIcon:(0,j.jsx)(r,{size:14}),children:a(`hook.prevStep`)})}),(0,j.jsxs)(`div`,{className:`flex gap-2`,children:[(0,j.jsx)(w,{size:`sm`,onClick:f,children:a(`common.cancel`)}),E<2?(0,j.jsx)(w,{size:`sm`,variant:`accent`,onClick:()=>D(E+1),rightIcon:(0,j.jsx)(i,{size:14}),children:a(`hook.nextStep`)}):(0,j.jsx)(w,{size:`sm`,variant:`accent`,onClick:q,children:a(o?`hook.saveChanges`:`hook.createRule`)})]})]})]})]}):null}function B({stats:e}){let{t}=x();if(!e)return null;let n=[{id:`total`,label:t(`hook.statTotal`),value:e.totalHooks,icon:s,iconWrap:`bg-accent-blue/15 text-accent-blue`},{id:`enabled`,label:t(`common.enabled`),value:e.enabledCount,icon:b,iconWrap:`bg-accent-green/15 text-accent-green`},{id:`disabled`,label:t(`common.disabled`),value:e.disabledCount,icon:u,iconWrap:`bg-dark-hover text-dark-muted`}];return(0,j.jsx)(`div`,{className:`grid grid-cols-3 gap-3 max-md:grid-cols-1`,children:n.map(e=>{let t=e.icon;return(0,j.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-dark-border bg-dark-surface px-4 py-3`,children:[(0,j.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg ${e.iconWrap}`,children:(0,j.jsx)(t,{size:18})}),(0,j.jsxs)(`div`,{className:`min-w-0`,children:[(0,j.jsx)(`div`,{className:`text-xl font-bold text-dark-text`,children:e.value}),(0,j.jsx)(`div`,{className:`text-xs text-dark-muted`,children:e.label})]})]},e.id)})})}var V={safety:{Icon:c,cls:`text-accent-red`},quality:{Icon:t,cls:`text-accent-blue`},audit:{Icon:l,cls:`text-accent-purple`}},H={Icon:l,cls:`text-dark-muted`},U=[`safety`,`quality`,`audit`];function W({templates:e,existingNames:t,onPick:n}){let{t:r}=x(),[a,s]=(0,k.useState)(!0),c=Array.isArray(e)?e:[],l=(0,k.useMemo)(()=>{let e=e=>{let t=U.indexOf(e);return t===-1?U.length:t};return[...c].sort((t,n)=>e(t.category)-e(n.category))},[c]);if(c.length===0)return null;let u=new Set(t);return(0,j.jsxs)(`section`,{className:`mt-4 min-w-0 rounded-xl border border-dark-border bg-dark-surface px-4 py-3`,children:[(0,j.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,j.jsxs)(`div`,{className:`min-w-0`,children:[(0,j.jsx)(`h3`,{className:`text-sm font-semibold text-dark-text`,children:r(`hook.templatesTitle`)}),(0,j.jsx)(`p`,{className:`mt-0.5 text-xs text-dark-muted`,children:r(`hook.templatesDesc`)})]}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>s(e=>!e),"aria-expanded":a,className:`shrink-0 rounded-lg p-1.5 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,title:r(a?`common.collapse`:`common.expand`),children:a?(0,j.jsx)(o,{size:16}):(0,j.jsx)(i,{size:16})})]}),a&&(0,j.jsx)(`div`,{className:`mt-3 grid grid-cols-1 gap-2 md:grid-cols-2 xl:grid-cols-3`,children:l.map(e=>{let{Icon:t,cls:i}=V[e.category]??H,a=r(`hook.template.${e.id}.title`),o=r(`hook.template.${e.id}.desc`),s=u.has(e.id);return(0,j.jsxs)(`button`,{type:`button`,onClick:()=>n(e),className:`group flex flex-col rounded-lg border border-dark-border bg-dark-bg p-2.5 text-start transition-colors hover:border-accent-blue/40 hover:bg-dark-hover`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,j.jsx)(t,{size:13,className:i}),(0,j.jsx)(`span`,{className:`text-meta uppercase tracking-wider text-dark-muted`,children:r(`hook.templateCategory.${e.category}`)}),s&&(0,j.jsx)(`span`,{className:`ms-auto rounded bg-dark-raised px-1.5 text-badge text-dark-muted`,children:r(`hook.templateExists`)})]}),(0,j.jsx)(`div`,{className:`mt-1 text-sm font-medium text-dark-text`,children:a}),(0,j.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs leading-relaxed text-dark-muted`,children:o}),(0,j.jsx)(`div`,{className:`mt-2 text-xs text-accent-blue/80 transition-colors group-hover:text-accent-blue`,children:r(`hook.templateUse`)})]},e.id)})})]})}function G(){let{t:e}=x(),[t,n]=(0,k.useState)(null),[r,i]=(0,k.useState)(!1),{rules:o,templates:s,stats:c,events:l,agents:u,loading:p,error:g,formOpen:_,loadAll:v,openForm:y,openFormFromTemplate:b,clearError:S}=A();(0,k.useEffect)(()=>{v()},[]);let C=(0,k.useCallback)(async()=>{let e=await T.hooks.export();if(e.success&&e.data){let t=new Blob([JSON.stringify(e.data,null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`hooks-export.json`,r.click(),URL.revokeObjectURL(n)}},[]),E=(0,k.useCallback)(()=>{let e=document.createElement(`input`);e.type=`file`,e.accept=`.json`,e.onchange=async e=>{let t=e.target.files?.[0];if(!t)return;let r=await t.text();try{let e=JSON.parse(r);n({fileName:t.name,data:e})}catch(e){console.error(`Import failed:`,e)}},e.click()},[]),O=(0,k.useCallback)(async e=>{if(t){i(!0);try{(await T.hooks.import({...t.data,mergeMode:e})).success&&(n(null),v())}catch(e){console.error(`Import failed:`,e)}finally{i(!1)}}},[t,v]);return(0,j.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-dark-bg text-dark-text`,children:[(0,j.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-3 border-b border-dark-border px-6 py-4 max-md:px-3 max-md:py-3`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`h2`,{className:`text-base font-semibold text-dark-text`,children:e(`hook.configTitle`)}),(0,j.jsx)(`p`,{className:`mt-0.5 text-xs text-dark-muted`,children:e(`hook.configDesc`)})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(`button`,{onClick:v,title:e(`common.refresh`),className:`rounded-lg p-2 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,children:(0,j.jsx)(f,{size:16,className:p?`animate-spin`:``})}),(0,j.jsx)(w,{onClick:E,leftIcon:(0,j.jsx)(m,{size:14}),children:e(`hook.import`)}),(0,j.jsx)(w,{onClick:C,leftIcon:(0,j.jsx)(a,{size:14}),children:e(`hook.export`)}),(0,j.jsx)(w,{variant:`accent`,onClick:()=>y(),leftIcon:(0,j.jsx)(d,{size:14}),children:e(`hook.newRule`)})]})]}),(0,j.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto custom-scrollbar px-6 py-4 max-md:px-3 max-md:py-3`,children:[g&&(0,j.jsxs)(`div`,{className:`mb-3 flex items-center justify-between rounded-lg border border-accent-red/40 bg-accent-red/10 px-4 py-2 text-sm text-accent-red`,children:[(0,j.jsx)(`span`,{children:g}),(0,j.jsx)(`button`,{onClick:S,className:`text-accent-red/70 transition-colors hover:text-accent-red`,children:(0,j.jsx)(h,{size:16})})]}),(0,j.jsx)(B,{stats:c}),(0,j.jsx)(W,{templates:s,existingNames:o.map(e=>e.name),onPick:t=>b(t,e(`hook.template.${t.id}.desc`))}),(0,j.jsxs)(`section`,{className:`mt-4 min-w-0 rounded-xl border border-dark-border bg-dark-surface p-4`,children:[(0,j.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,j.jsx)(`h3`,{className:`text-sm font-semibold text-dark-text`,children:e(`hook.ruleList`)}),(0,j.jsx)(`span`,{className:`text-xs text-dark-muted`,children:e(`hook.ruleCount`,{n:o.length})})]}),p&&o.length===0?(0,j.jsx)(`div`,{className:`flex h-[520px] items-center justify-center text-dark-muted`,children:e(`common.loading`)}):(0,j.jsx)(`div`,{className:`min-h-[520px]`,children:(0,j.jsx)(P,{rules:o,onEdit:e=>y(e)})})]})]}),(0,j.jsx)(z,{isOpen:_,events:l,agents:u}),(0,j.jsx)(D,{isOpen:t!==null,onClose:()=>{r||n(null)},title:e(`hook.importTitle`),size:`sm`,children:(0,j.jsxs)(`div`,{className:`space-y-4`,children:[t&&(0,j.jsxs)(`p`,{className:`text-sm leading-relaxed text-dark-muted`,children:[(0,j.jsx)(`span`,{className:`text-dark-text`,children:t.fileName}),(0,j.jsx)(`br`,{}),e(`hook.importDesc`)]}),(0,j.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,j.jsx)(w,{variant:`ghost`,disabled:r,onClick:()=>n(null),"data-autofocus":!0,children:e(`common.cancel`)}),(0,j.jsx)(w,{variant:`danger`,disabled:r,onClick:()=>void O(`replace`),children:e(`hook.importReplace`)}),(0,j.jsx)(w,{variant:`accent`,loading:r,onClick:()=>void O(`merge`),children:e(`hook.importMerge`)})]})]})})]})}export{G as HookConfigView};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{Gr as t,Ut as n,Wr as r,cn as i,it as a,ni as o,sr as s,t as c,v as l,vr as u}from"./icons-B8Ngx6rM.js";import{t as d}from"./useTranslation-gGKZZfux.js";import{I as f}from"./markdown-Cps-36Z5.js";import{at as p,ot as m}from"./index-STsyoFCk.js";var h=e(o(),1),g=f(),_={pending:`bg-amber-500/15 text-amber-600 dark:text-amber-400`,processing:`bg-blue-500/15 text-blue-600 dark:text-blue-400`,deferred:`bg-purple-500/15 text-purple-600 dark:text-purple-400`,done:`bg-green-500/15 text-green-600 dark:text-green-400`},v={critical:`bg-red-500/15 text-red-600 dark:text-red-400`,normal:`bg-gray-500/15 text-gray-600 dark:text-gray-400`,low:`bg-gray-500/10 text-gray-500 dark:text-gray-500`};function y({msg:e}){let{wakeup:n}=e;return n.mode===`now`?(0,g.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] ${v[n.urgency]||v.normal}`,children:[(0,g.jsx)(c,{size:10}),` now`]}):(0,g.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-gray-500/10 px-1.5 py-0.5 text-[10px] text-gray-500`,children:[(0,g.jsx)(t,{size:10}),` drain`]})}function b({msg:e,onDelete:t}){let{t:r}=d(),i=e.resultSummary||(e.wakeup.reason?`唤醒理由:${e.wakeup.reason}`:``);return(0,g.jsxs)(`div`,{className:`group flex items-start gap-3 rounded-lg border border-transparent px-3 py-2.5 hover:bg-black/5 dark:hover:bg-white/5`,children:[(0,g.jsx)(`div`,{className:`mt-0.5 shrink-0`,children:e.status===`done`?(0,g.jsx)(u,{size:16,className:`text-green-500`}):(0,g.jsx)(n,{size:16,className:`text-gray-400`})}),(0,g.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,g.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,g.jsx)(`span`,{className:`font-medium text-sm text-light-text dark:text-dark-text`,children:e.kind}),(0,g.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] ${_[e.status]||``}`,children:e.status}),e.status!==`done`&&(0,g.jsx)(y,{msg:e}),(0,g.jsx)(`span`,{className:`text-xs text-dark-muted`,children:e.from})]}),i&&(0,g.jsx)(`p`,{className:`mt-1 truncate text-xs text-dark-muted`,title:i,children:i}),(0,g.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-[10px] text-gray-400`,children:[(0,g.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,children:[(0,g.jsx)(s,{size:9}),` `,m(new Date(e.createdAt),`MM-dd HH:mm`)]}),e.deferCount>0&&(0,g.jsxs)(`span`,{children:[`defer ×`,e.deferCount]})]})]}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`shrink-0 rounded p-1 text-gray-400 opacity-0 transition-opacity hover:bg-red-500/10 hover:text-red-500 group-hover:opacity-100`,title:r(`common.delete`,`删除`),children:(0,g.jsx)(l,{size:14})})]})}function x(){let{t:e}=d(),{stats:t,messages:n,lastWake:o,loading:c,error:l,fetchInbox:f,removeMessage:m}=p();(0,h.useEffect)(()=>{f();let e=setInterval(()=>void f(),3e4);return()=>clearInterval(e)},[f]);let _=[{label:e(`inbox.pending`,`待消化`),value:t.pending,icon:r,accent:`text-amber-500`},{label:e(`inbox.deferred`,`已延后`),value:t.deferred,icon:s,accent:`text-purple-500`},{label:e(`inbox.done`,`已消化`),value:t.done,icon:u,accent:`text-green-500`}];return(0,g.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between border-b border-black/10 px-4 py-3 dark:border-white/10`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(i,{size:18,className:`text-dark-muted`}),(0,g.jsx)(`h2`,{className:`font-semibold text-sm`,children:e(`inbox.title`,`收件箱`)}),o&&(0,g.jsxs)(`span`,{className:`rounded bg-blue-500/10 px-1.5 py-0.5 text-[10px] text-blue-500`,children:[`wake: `,o.verdict]})]}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>void f(),className:`rounded p-1.5 text-dark-muted hover:bg-black/5 dark:hover:bg-white/5`,title:e(`common.refresh`,`刷新`),children:(0,g.jsx)(a,{size:14,className:c?`animate-spin`:``})})]}),(0,g.jsx)(`div`,{className:`flex gap-3 px-4 py-3`,children:_.map(e=>(0,g.jsxs)(`div`,{className:`flex flex-1 items-center gap-2 rounded-lg bg-black/5 px-3 py-2 dark:bg-white/5`,children:[(0,g.jsx)(e.icon,{size:16,className:e.accent}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`div`,{className:`font-semibold text-sm leading-none`,children:e.value}),(0,g.jsx)(`div`,{className:`mt-0.5 text-[10px] text-dark-muted`,children:e.label})]})]},e.label))}),l&&(0,g.jsx)(`div`,{className:`mx-4 mb-2 rounded bg-red-500/10 px-3 py-2 text-xs text-red-500`,children:l}),(0,g.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 pb-4`,children:n.length===0?(0,g.jsxs)(`div`,{className:`flex h-40 flex-col items-center justify-center gap-2 text-dark-muted`,children:[(0,g.jsx)(i,{size:28,className:`opacity-40`}),(0,g.jsx)(`p`,{className:`text-xs`,children:e(`inbox.empty`,`收件箱为空 —— 各传感器有变化时这里会出现消息`)})]}):n.map(e=>(0,g.jsx)(b,{msg:e,onDelete:e=>void m(e)},e.id))})]})}export{x as InboxView};
@@ -0,0 +1,14 @@
1
+ import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{A as t,Bn as n,D as r,Er as i,Ft as a,Gn as o,Gt as s,Kr as c,Kt as l,Mn as u,Nn as d,Or as f,Pt as p,Qn as m,Tr as h,Wt as g,Y as _,Yr as v,Yt as y,Zr as b,_t as x,bn as S,bt as C,d as w,dn as T,dt as E,it as D,jr as O,jt as k,kn as A,kr as ee,mt as j,n as te,ni as M,pt as ne,qr as re,sr as ie,t as ae,tr as oe,v as N,wn as se,xn as ce,xt as le,yn as P}from"./icons-B8Ngx6rM.js";import{r as ue}from"./react-vendor-CXI113IS.js";import{t as F}from"./useTranslation-gGKZZfux.js";import{T as I,a as de,m as fe,o as L,s as pe,u as R}from"./imageUrl-CrQM4gmf.js";import{i as z,n as me,r as B,t as he}from"./Button-D-g7PgYh.js";import"./src-BK8SoTFV.js";import{ht as V,l as ge,mt as _e,vt as H,yt as ve}from"./DiffPreview-D8tIj_aF.js";import{a as U,f as ye,l as be,n as xe,r as Se}from"./workspaceSemantics-CW8ytHq2.js";import{a as Ce,i as we,n as Te,o as Ee,r as De,s as Oe,t as ke}from"./sttLanguages-BPcOF0nQ.js";import{r as Ae,t as W}from"./api-ZQf0Ys8y.js";import{r as G,t as je}from"./settingsStore-BSdi9gNd.js";import{I as Me}from"./markdown-Cps-36Z5.js";import{d as Ne,f as Pe,l as Fe,u as Ie}from"./FileContextMenu-C5WYeBNu.js";import{r as Le}from"./useConfirm-CQjBnYuP.js";import{c as Re}from"./common-CPZxdYLs.js";import{A as ze,At as Be,Ct as Ve,D as He,Et as Ue,Mt as We,Nt as Ge,Ot as Ke,Pt as qe,Tt as K,a as Je,c as Ye,i as Xe,j as Ze,jt as Qe,k as $e,kt as et,n as tt,o as nt,s as q,t as rt}from"./index-STsyoFCk.js";var it=/\[Pasted text #(\d+)(?:\s*\+\d+ lines?)?\]/g,at=0,ot=new Map;function st(e){let t=++at;return ot.set(t,e.replace(/\r\n?/g,`
2
+ `)),t}function ct(e){return ot.get(e)}function lt(e){ot.delete(e)}function ut(e){return e.length>800||dt(e)>0}function dt(e){return(e.match(/\r\n|\r|\n/g)||[]).length}function ft(e){let t=st(e),n=dt(e);return n===0?{id:t,label:`[Pasted text #${t}]`}:{id:t,label:`[Pasted text #${t} +${n} lines]`}}function pt(e){return it.lastIndex=0,e.replace(it,(e,t)=>{let n=parseInt(t,10),r=ot.get(n);return r===void 0?e:r})}function mt(e){it.lastIndex=0;let t=[],n;for(;(n=it.exec(e))!==null;){let e=n[1];e!==void 0&&t.push(parseInt(e,10))}return it.lastIndex=0,t}function ht(e){for(let t of e)ot.delete(t)}function gt(e){let t=e.match(/\[Pasted text #\d+(?:\s*\+\d+ lines?)?\]$/);return t?t[0]:null}function _t(e){let t=e.match(/^\[Pasted text #\d+(?:\s*\+\d+ lines?)?\]/);return t?t[0]:null}function vt(e){let t=e.match(/#(\d+)/);t&&lt(parseInt(t[1]??``,10))}var J=e(M(),1),Y=Me();function yt(e,t=28){let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t)}…`:n}var bt=`cubic-bezier(0.34, 1.56, 0.64, 1)`,xt=14,St=7,Ct=.6,wt=160,X=440;function Tt(){let e=(0,J.useCallback)(()=>typeof window>`u`?X:Math.max(wt,Math.min(X,Math.round(window.innerHeight*Ct))),[]),[t,n]=(0,J.useState)(e);return(0,J.useEffect)(()=>{let t=()=>n(e());return window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[e]),t}var Et=`(hover: none), (pointer: coarse)`;function Dt(){let e=(0,J.useCallback)(()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(Et).matches,[]),[t,n]=(0,J.useState)(e);return(0,J.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(Et),t=()=>n(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),t}var Ot=(0,J.memo)(function({items:e,activeId:t,onJump:n}){let{t:r}=F(),[a,o]=(0,J.useState)(!1),s=(0,J.useRef)(null),c=Tt(),l=Dt(),u=(0,J.useRef)(null),d=(0,J.useCallback)(()=>{l||(s.current&&window.clearTimeout(s.current),o(!0))},[l]),f=(0,J.useCallback)(()=>{l||(s.current&&window.clearTimeout(s.current),s.current=window.setTimeout(()=>o(!1),180))},[l]),p=(0,J.useCallback)(e=>{n(e),l&&o(!1)},[n,l]);(0,J.useEffect)(()=>{if(!a||!l)return;let e=e=>{let t=u.current;t&&e.target instanceof Node&&t.contains(e.target)||o(!1)},t=e=>{e.key===`Escape`&&o(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[a,l]),(0,J.useEffect)(()=>()=>{s.current&&window.clearTimeout(s.current)},[]);let m=Math.max(St,Math.min(xt,Math.floor(c/Math.max(1,e.length)))),h=Math.max(1,Math.floor(c/St)),g=(0,J.useMemo)(()=>{let n=e.length,r=Math.min(n,h),i=n/r,a=t?e.findIndex(e=>e.id===t):-1;return Array.from({length:r},(e,t)=>{let r=Math.round(t*i),o=Math.min(n,Math.max(r+1,Math.round((t+1)*i)));return{start:r,end:o,active:a>=r&&a<o}}).flatMap(t=>{let n=e[t.start];return n?[{...t,key:n.id,first:n}]:[]})},[e,t,h]),_=m>=12?6:m>=9?5:4,v=Math.min(_+2,Math.max(4,m-2)),b=m>=12?`ring-2 ring-accent-blue/25`:`ring-1 ring-accent-blue/30`;return e.length===0?null:(0,Y.jsxs)(`div`,{ref:u,"data-testid":`rail-trigger`,"data-touch":l?`1`:`0`,role:`group`,"aria-label":r(`chat.messageRail`),onMouseEnter:d,onMouseLeave:f,className:B(`pointer-events-auto absolute z-30`,l?`bottom-16 end-3`:`end-4 top-1/2 -translate-y-1/2`),children:[l?(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`rail-fab`,"aria-expanded":a,"aria-label":r(`chat.messageIndex`),title:r(`chat.messageIndex`),onClick:()=>o(e=>!e),className:B(`relative grid h-10 w-10 place-items-center rounded-full border shadow-lg backdrop-blur transition-colors duration-200 active:scale-95`,a?`border-accent-blue/50 bg-accent-blue/15 text-accent-blue`:`border-dark-border/70 bg-dark-surface/90 text-dark-muted`),children:[(0,Y.jsx)(y,{size:16,"aria-hidden":`true`}),(0,Y.jsx)(`span`,{"data-testid":`rail-fab-count`,className:`pointer-events-none absolute -end-1 -top-1 grid h-4 min-w-4 place-items-center rounded-full bg-accent-blue px-1 text-[10px] font-semibold leading-none tabular-nums text-accent-fg`,children:e.length})]}):(0,Y.jsx)(`ul`,{"data-testid":`rail-dots`,"aria-label":r(`chat.messageIndex`),className:`flex flex-col items-end py-3`,style:{maxHeight:c},children:g.map(e=>{let{first:t}=e,n=e.end-e.start>1,r=n?`${e.start+1}–${e.end} (${e.end-e.start})`:`${e.start+1}. ${yt(t.content)}`;return(0,Y.jsx)(`li`,{children:(0,Y.jsx)(`button`,{type:`button`,onClick:()=>p(t.id),title:n?`${e.start+1}–${e.end}: ${t.content}`:t.content,"aria-label":r,"aria-current":e.active?`true`:void 0,className:`group/dot pointer-events-auto flex items-center justify-center rounded-full transition-colors duration-200 hover:bg-dark-surface/80`,style:{height:m,width:20},children:(0,Y.jsx)(`span`,{style:{height:e.active?v:_,width:e.active?v:_},className:e.active?`rounded-full bg-accent-blue transition-all duration-300 ease-out group-hover/dot:scale-125 ${b}`:`rounded-full bg-dark-muted/35 transition-all duration-300 ease-out group-hover/dot:scale-125 group-hover/dot:bg-dark-muted`})})},e.key)})}),(0,Y.jsx)(`div`,{"data-testid":`rail-panel`,"aria-hidden":!a,inert:!a,className:B(`absolute z-40`,l?`bottom-0 end-full me-2`:`top-1/2 end-full -translate-y-1/2`),children:(0,Y.jsxs)(`div`,{className:B(`flex flex-col overflow-hidden rounded-xl border border-dark-border/70 bg-dark-bg/90 shadow-pop backdrop-blur-xl transition-all duration-300`,l?`w-[min(18rem,calc(100vw-5.5rem))] max-h-[60vh] origin-bottom-right`:`w-72 max-h-[55vh] origin-right rtl:origin-left`,a?`scale-100 opacity-100`:`pointer-events-none scale-95 opacity-0`,a?l?`translate-y-0`:`translate-x-0`:l?`translate-y-2`:`translate-x-4 rtl:-translate-x-4`),style:{transitionTimingFunction:a?bt:`ease`},children:[(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-b border-dark-border/60 px-3 py-2`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5 text-meta font-semibold uppercase tracking-[0.08em] text-dark-muted`,children:[(0,Y.jsx)(y,{size:12,className:`text-accent-blue`,"aria-hidden":`true`}),r(`chat.messageIndex`)]}),(0,Y.jsx)(`span`,{className:`rounded-full bg-dark-hover px-1.5 py-0.5 text-badge font-medium tabular-nums text-dark-muted`,children:e.length})]}),(0,Y.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-1.5 custom-scrollbar`,children:e.map((e,n)=>{let r=e.id===t;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>p(e.id),title:e.content,"aria-current":r?`true`:void 0,tabIndex:a?0:-1,className:B(`group/item flex w-full items-start gap-2 rounded-lg px-2 text-start transition-all duration-200`,l?`py-2.5`:`py-1.5`,a?`translate-x-0 opacity-100`:`translate-x-2 rtl:-translate-x-2 opacity-0`,r?`bg-accent-blue/10`:`hover:bg-dark-hover`),style:{transitionDelay:a?`${Math.min(n*24,264)}ms`:`0ms`},children:[(0,Y.jsx)(`span`,{className:B(`mt-px flex h-4 w-4 shrink-0 items-center justify-center rounded text-badge font-semibold tabular-nums transition-colors duration-200`,r?`bg-accent-blue text-accent-fg`:`bg-dark-hover text-dark-muted group-hover/item:bg-dark-border/80 group-hover/item:text-dark-text`),children:n+1}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(`span`,{"data-testid":`rail-entry-content`,className:B(`block break-words text-xs leading-snug transition-colors duration-200`,l?`line-clamp-3`:`line-clamp-2 group-hover/item:line-clamp-none`,r?`font-medium text-accent-blue`:`text-dark-text/90`),children:e.content})}),!l&&(0,Y.jsx)(i,{size:12,"aria-hidden":`true`,className:`mt-0.5 shrink-0 -translate-x-1 rtl:translate-x-1 rtl:rotate-180 text-dark-muted/50 opacity-0 transition-all duration-200 group-hover/item:translate-x-0 group-hover/item:opacity-100`})]},e.id)})})]})})]})});function kt(e){let t=fe(e=>e.activeSessionId);return!(t&&e&&t!==e)}function At({sessionId:e,suppressSummary:t=!1}){let n=de(e=>e.compactionProgress),r=de(e=>e.lastCompactSummary);return kt(e)?n?(0,Y.jsx)(Nt,{progress:n}):r&&!t?(0,Y.jsx)(Pt,{summary:r,className:`chat-col px-4 pb-1.5 pt-1 sm:px-6`}):null:null}function jt(e){return e<1e4?`${(e/1e3).toFixed(1)}s`:`${Math.round(e/1e3)}s`}function Mt(e){return Math.max(0,Math.min(100,Math.round(e)))}function Nt({progress:e}){let t=e.percent>=100,n=Mt(e.percent),{tokensBefore:r,startedAt:i}=e,[a,o]=(0,J.useState)(()=>i===void 0?0:Date.now()-i);return(0,J.useEffect)(()=>{if(i===void 0||t)return;let e=()=>o(Date.now()-i);e();let n=window.setInterval(e,1e3);return()=>window.clearInterval(n)},[i,t]),(0,Y.jsx)(`div`,{"data-testid":`compaction-indicator`,className:`chat-col animate-fade-in px-4 py-1.5 text-xs text-dark-muted sm:px-6`,title:e.message||void 0,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,Y.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1.5 whitespace-nowrap text-dark-text`,children:[(0,Y.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full ${t?`bg-accent-green`:`compact-live-dot bg-accent-blue`}`}),`compact`]}),e.stage&&(0,Y.jsx)(`span`,{className:`hidden shrink-0 whitespace-nowrap text-meta uppercase tracking-wide text-dark-muted/80 sm:inline`,children:e.stage}),(0,Y.jsxs)(`span`,{className:`w-9 shrink-0 text-right tabular-nums whitespace-nowrap text-dark-text`,children:[n,`%`]}),(0,Y.jsx)(`span`,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":n,className:`relative h-2 min-w-0 flex-1 overflow-hidden rounded-full bg-dark-border/50`,children:(0,Y.jsxs)(`span`,{className:`compact-progress-fill absolute inset-y-0 left-0 overflow-hidden rounded-full ${t?`bg-accent-green`:`bg-gradient-to-r from-accent-blue/70 to-accent-blue`}`,style:{width:`${n}%`},children:[!t&&(0,Y.jsx)(`span`,{className:`compact-stripes absolute -inset-x-4 inset-y-0`}),!t&&(0,Y.jsx)(`span`,{className:`animate-compact-sheen absolute inset-y-0 left-0 w-1/3 rounded-full bg-gradient-to-r from-transparent via-white/60 to-transparent`})]})}),r!==void 0&&(0,Y.jsxs)(`span`,{className:`shrink-0 whitespace-nowrap tabular-nums text-dark-muted`,children:[be(r),` → …`]}),!t&&i!==void 0&&a>=1e3&&(0,Y.jsx)(`span`,{className:`w-8 shrink-0 text-right whitespace-nowrap tabular-nums text-dark-muted/80`,children:jt(a)})]})})}function Pt({summary:e,className:t=``}){let{tokensBefore:n,tokensAfter:r,tokensSaved:i,messagesBefore:a,messagesAfter:o,durationMs:s}=e,c=n!==void 0&&r!==void 0&&n>0,l=c?Math.max(0,Math.min(100,Math.round(i/n*100))):void 0,u=c?Math.max(0,Math.min(100,r/n*100)):0,[d,f]=(0,J.useState)(!1);(0,J.useEffect)(()=>{f(!1);let e=window.requestAnimationFrame(()=>f(!0));return()=>window.cancelAnimationFrame(e)},[e.at]);let p=[a!==void 0&&o!==void 0?`${a} → ${o} msgs`:o===void 0?a===void 0?``:`${a} msgs`:`${o} msgs`,s!==void 0&&s>=300?jt(s):``].filter(Boolean).join(` · `);return(0,Y.jsx)(`div`,{"data-testid":`compaction-summary`,className:`animate-fade-in-up ${t}`.trim(),children:(0,Y.jsxs)(`div`,{className:`rounded-lg border border-dark-border/60 bg-dark-surface/50 px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Y.jsx)(`span`,{className:`text-accent-green`,children:`✓`}),(0,Y.jsx)(`span`,{className:`whitespace-nowrap text-dark-text`,children:`compact`}),c?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`span`,{className:`tabular-nums whitespace-nowrap text-dark-muted`,children:[be(n),` → `,be(r)]}),l!==void 0&&l>0&&(0,Y.jsxs)(`span`,{className:`whitespace-nowrap rounded-full bg-accent-green/[0.12] px-1.5 text-accent-green`,children:[`−`,l,`%`]})]}):i>0&&(0,Y.jsxs)(`span`,{className:`tabular-nums whitespace-nowrap text-accent-green`,children:[`−`,be(i)]}),(0,Y.jsx)(`span`,{className:`flex-1`}),(0,Y.jsx)(`span`,{className:`whitespace-nowrap tabular-nums text-dark-muted`,children:p}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>de.getState().setCompactSummary(null),"aria-label":`hide compaction summary`,title:`hide`,className:`-me-1 flex h-4 w-4 shrink-0 items-center justify-center rounded text-dark-muted/60 transition-colors hover:text-dark-text`,children:(0,Y.jsx)(te,{size:12})})]}),c&&(0,Y.jsxs)(`div`,{className:`mt-1.5 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`h-1.5 min-w-0 flex-1 rounded-full bg-dark-muted/35`}),(0,Y.jsx)(`span`,{className:`min-w-10 shrink-0 text-right text-meta tabular-nums text-dark-muted`,children:be(n)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`relative h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-dark-border/40`,children:(0,Y.jsx)(`span`,{className:`compact-bar-collapse absolute inset-y-0 left-0 rounded-full bg-accent-green/80`,style:{width:`${d?u:100}%`}})}),(0,Y.jsx)(`span`,{className:`min-w-10 shrink-0 text-right text-meta tabular-nums text-accent-green`,children:be(r)})]})]})]})})}var Ft=24,It=2e3,Lt=150,Z=28;function Rt({label:e}){let t=(0,J.useRef)(Date.now()),n=(0,J.useRef)(null),[r,i]=(0,J.useState)(!1);return(0,J.useEffect)(()=>{let e=window.setTimeout(()=>i(!0),15e3);return()=>window.clearTimeout(e)},[]),(0,J.useEffect)(()=>{if(!r)return;let e=()=>{let e=n.current;if(!e)return;let r=Math.floor((Date.now()-t.current)/1e3);e.textContent=r>=60?`${Math.floor(r/60)}m ${r%60}s`:`${r}s`};e();let i=window.setInterval(e,1e3);return()=>window.clearInterval(i)},[r]),(0,Y.jsxs)(`div`,{className:`chat-col flex items-center gap-2 px-4 py-3 text-xs text-dark-muted sm:px-6`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-accent-blue animate-blink`}),(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-accent-blue animate-blink`,style:{animationDelay:`0.2s`}}),(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-accent-blue animate-blink`,style:{animationDelay:`0.4s`}})]}),(0,Y.jsx)(`span`,{className:`text-shimmer`,children:e}),r&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 tabular-nums text-dark-muted/70`,children:[(0,Y.jsx)(ie,{size:10}),(0,Y.jsx)(`span`,{ref:n,children:`15s`})]})]})}var zt=(0,J.memo)(function({messages:e,isGenerating:t,sessionId:n,onRegenerate:r,onRetryTurn:i,onDeleteMessage:a,onUndoLastUser:o,onOpenSidebarView:s}){let{t:c}=F(),l=(0,J.useRef)(null),u=de(e=>e.compactionProgress),d=de(e=>e.lastCompactSummary),p=(0,J.useRef)(new Map),[m,h]=(0,J.useState)(!0),[g,_]=(0,J.useState)(null),v=(0,J.useRef)(m),y=(0,J.useRef)(g),b=(0,J.useCallback)(e=>{v.current!==e&&(v.current=e,h(e))},[]),x=(0,J.useCallback)(e=>{y.current!==e&&(y.current=e,_(e))},[]),[S,C]=(0,J.useState)(null),[w,T]=(0,J.useState)(0),E=(0,J.useRef)(null),D=(0,J.useRef)(!1),O=(0,J.useRef)(null),k=(0,J.useRef)(!1),A=(0,J.useRef)(null),ee=(0,J.useRef)(!1),j=(0,J.useRef)(null),te=(0,J.useRef)(null),M=(0,J.useRef)(t);M.current=t;let ne=(0,J.useRef)(0),[re,ie]=(0,J.useState)({top:0,bottom:0}),ae=(0,J.useRef)(re),oe=(0,J.useCallback)((e,t)=>{(ae.current.top!==e||ae.current.bottom!==t)&&(ae.current={top:e,bottom:t},ie({top:e,bottom:t}))},[]),N=(0,J.useMemo)(()=>e.filter(e=>!e.deleted),[e]),se=(0,J.useMemo)(()=>{for(let e=N.length-1;e>=0;e--)if(N[e]?.type===`user`)return N[e].id},[N]),ce=kt(n),le=d?.anchorMessageId,P=(0,J.useMemo)(()=>ce&&!!le&&N.some(e=>e.id===le),[ce,le,N]),ue=(0,J.useMemo)(()=>{if(!t)return!1;let e=N[N.length-1];return!e||e.type!==`assistant`?!1:!e.content},[t,N]),fe=(0,J.useMemo)(()=>N.filter(e=>I(e)).map(e=>({id:e.id,content:e.content})),[N]),L=(0,J.useMemo)(()=>fe.map(e=>e.id),[fe]),pe=(0,J.useCallback)(e=>{if(e){let t=e.dataset.mid;t&&p.current.set(t,e)}},[]);(0,J.useEffect)(()=>{let e=new Set(L);for(let t of p.current.keys())e.has(t)||p.current.delete(t)},[L]);let R=(0,J.useCallback)(()=>{let e=l.current;if(!e||L.length===0){x(null);return}let t=e.getBoundingClientRect(),n=t.top+t.height*.35,r=L[0]??null;for(let e of L){let t=p.current.get(e);if(t&&t.isConnected){if(t.getBoundingClientRect().top<=n)r=e;else break}}e.scrollHeight-e.scrollTop-e.clientHeight<Ft&&(r=L[L.length-1]??r),x(r)},[L,x]),z=(0,J.useCallback)(()=>{let e=l.current;if(!e)return;let t=e.scrollTop<=2,n=e.scrollTop+e.clientHeight>=e.scrollHeight-2;oe(t?0:Z,n?0:Z)},[oe]),me=(0,J.useCallback)(()=>{let e=l.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=t<Ft;k.current?n&&(k.current=!1):D.current?t>=Ft&&(D.current=!1):b(n),R(),z()},[R,z,b]),B=(0,J.useCallback)(()=>{let e=l.current;if(!e||M.current||D.current||k.current)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight;b(t<Ft),z()},[b,z]);(0,J.useLayoutEffect)(()=>{ee.current=!0,j.current&&window.clearTimeout(j.current),j.current=window.setTimeout(()=>{ee.current=!1},It),O.current&&window.clearTimeout(O.current),D.current=!1,k.current=!1;let e=l.current;e&&(e.scrollTop=e.scrollHeight),b(!0),z()},[n,b,z]),(0,J.useEffect)(()=>{let e=l.current,t=te.current;if(!e||!t||typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>{ee.current&&v.current&&(e.scrollTop=e.scrollHeight)});return n.observe(t),()=>n.disconnect()},[]),(0,J.useEffect)(()=>{R(),z()},[e,R,z]),(0,J.useEffect)(()=>{let e=l.current;if(!e)return;let t=()=>{z(),B()},n=()=>{ne.current=performance.now(),k.current=!1,ee.current=!1},r=e=>{(e.key===`PageUp`||e.key===`PageDown`||e.key===`ArrowUp`||e.key===`ArrowDown`||e.key===`Home`||e.key===`End`)&&n()};return e.addEventListener(`wheel`,n,{passive:!0}),e.addEventListener(`touchmove`,n,{passive:!0}),e.addEventListener(`keydown`,r),window.addEventListener(`resize`,t),()=>{e.removeEventListener(`wheel`,n),e.removeEventListener(`touchmove`,n),e.removeEventListener(`keydown`,r),window.removeEventListener(`resize`,t)}},[z,B]);let he=(0,J.useCallback)(e=>{let t=l.current,n=p.current.get(e);if(!t||!n||!n.isConnected)return;b(!1),C(e),T(e=>e+1),E.current&&window.clearTimeout(E.current),E.current=window.setTimeout(()=>C(null),1600);let r=t.getBoundingClientRect(),i=n.getBoundingClientRect(),a=t.scrollTop+(i.top-r.top)-t.clientHeight/2+i.height/2;O.current&&window.clearTimeout(O.current),D.current=!0,t.scrollTo({top:Math.max(0,a),behavior:`smooth`}),`onscrollend`in t&&t.addEventListener(`scrollend`,()=>{D.current=!1},{once:!0}),O.current=window.setTimeout(()=>{D.current=!1},1500)},[b]);(0,J.useEffect)(()=>()=>{E.current&&window.clearTimeout(E.current),O.current&&window.clearTimeout(O.current),A.current&&window.clearTimeout(A.current),j.current&&window.clearTimeout(j.current)},[]);let V=(0,J.useCallback)(()=>{O.current&&window.clearTimeout(O.current),D.current=!1;let e=l.current;e&&(e.scrollTop=e.scrollHeight)},[]),ge=(0,J.useCallback)(()=>{O.current&&window.clearTimeout(O.current),D.current=!1,b(!0);let e=l.current;e&&(k.current=!0,A.current&&window.clearTimeout(A.current),A.current=window.setTimeout(()=>{k.current=!1},1e3),`onscrollend`in e&&e.addEventListener(`scrollend`,()=>{k.current=!1},{once:!0}),e.scrollTo({top:e.scrollHeight,behavior:`smooth`}))},[b]);(0,J.useEffect)(()=>{t&&(b(!0),V())},[t,V,b]);let _e=(0,J.useMemo)(()=>{let e=N[N.length-1],t=u?`c:${Math.round(u.percent)}`:d?`s:${d.at}`:``;return`${N.length}:${e?.id??``}:${e?.content?.length??0}:${e?.textBlocks?.length??0}:${e?.toolCalls?.length??0}:${e?.thinkingBlocks?.length??0}:${e?.thinking?.length??0}:${t}`},[N,u,d]),H=(0,J.useRef)(_e);return(0,J.useEffect)(()=>{m?_e!==H.current&&(H.current=_e,!(performance.now()-ne.current<=Lt)&&V()):H.current=_e},[_e,m,V]),(0,Y.jsxs)(`div`,{className:`relative flex-1 min-h-0`,children:[(0,Y.jsxs)(`div`,{ref:l,onScroll:me,style:{"--ui-fade-top":`${re.top}px`,"--ui-fade-bottom":`${re.bottom}px`},className:`fade-mask-y h-full overflow-y-auto custom-scrollbar`,children:[(0,Y.jsx)(`div`,{ref:te,className:`chat-stack flex flex-col pb-8 pt-5`,children:N.map((e,t)=>{let c=N[t-1],l=c?c.type===e.type?`mt-2`:`mt-5`:``;return(0,Y.jsxs)(J.Fragment,{children:[(0,Y.jsxs)(`div`,{"data-mid":e.id,ref:pe,className:`relative w-full ${l}`,children:[S===e.id&&(0,Y.jsx)(`div`,{className:`animate-rail-flash pointer-events-none absolute inset-0`},w),(0,Y.jsx)(He,{message:e,sessionId:n,onRegenerate:r,onRetryTurn:i,onDeleteMessage:a,onUndoLastUser:e.id===se&&o&&n?()=>o(n):void 0,onOpenSidebarView:s})]}),P&&d&&e.id===le&&(0,Y.jsx)(Pt,{summary:d,className:`pb-1.5 pt-1`})]},e.id)})}),(0,Y.jsx)(At,{sessionId:n,suppressSummary:P}),t&&!ue&&(0,Y.jsx)(Rt,{label:c(`chat.thinkingEllipsis`)},n)]}),fe.length>0&&(0,Y.jsx)(Ot,{items:fe,activeId:g,onJump:he}),!m&&N.length>0&&(0,Y.jsx)(`button`,{type:`button`,onClick:ge,title:c(`chat.backToBottom`),"aria-label":c(`chat.backToBottom`),className:`absolute bottom-5 end-5 z-20 flex h-8 w-8 animate-fade-in-up items-center justify-center rounded-full border border-dark-border/70 bg-dark-surface/90 text-dark-muted shadow-lg backdrop-blur transition-all duration-200 hover:scale-110 hover:text-dark-text hover:shadow-xl`,children:(0,Y.jsx)(f,{size:15})})]})}),Bt=(0,J.memo)(function(){let{t:e}=F(),t=K(e=>e.mode),n=K(e=>e.setAutoLevel),r=Ue(e=>e.autoLevel),i=t!==`normal`&&ye(t),a=Ge(i?r:0),o=(t===`normal`?`act`:U(t))===`chat`,s=We[a],[c,l]=(0,J.useState)(!1),[u,d]=(0,J.useState)(null),f=(0,J.useId)(),p=u??a,m=We[p],h=(0,J.useRef)(null),g=(0,J.useRef)(null),_=e=>{o||(l(!0),h.current?.contains(e.target)||d(null))},v=e=>{let t=e.relatedTarget;t&&g.current?.contains(t)||(l(!1),d(null))},y=(0,J.useCallback)(e=>{o||e!==a&&n(e)},[o,a,n]),b=(0,J.useRef)(0);(0,J.useEffect)(()=>{let e=g.current;if(!e||o)return;let t=e=>{let t=Math.abs(e.deltaY)>=Math.abs(e.deltaX)?e.deltaY:0;if(t===0||(e.preventDefault(),b.current+=t,Math.abs(b.current)<30))return;let n=b.current>0?1:-1;b.current=0,y(qe(a,n>0?-1:1))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[y,o,a]);let x=(0,J.useCallback)(e=>{if(o)return;let t=t=>{e.preventDefault(),y(qe(a,t))};switch(e.key){case`ArrowUp`:case`ArrowRight`:t(1);break;case`ArrowDown`:case`ArrowLeft`:t(-1);break;case`Home`:e.preventDefault(),y(0);break;case`End`:e.preventDefault(),y(4)}},[y,o,a]),S=t=>{let n=We[t];return`${t}/4 · ${n.label} — ${n.hint}\n${e(`plan.autoAllows`)}: ${n.allows}\n${e(`plan.autoAsks`)}: ${n.asks}`},C=`${e(`plan.autoApprove`)} ${S(a)}`;return(0,Y.jsxs)(`div`,{ref:g,role:`slider`,tabIndex:o?-1:0,"aria-label":e(`plan.autoApprove`),"aria-valuemin":0,"aria-valuemax":4,"aria-valuenow":a,"aria-valuetext":`${s.label} (${a}/4)`,"aria-describedby":c?f:void 0,"aria-disabled":o||void 0,onKeyDown:x,onMouseOver:_,onMouseOut:v,onFocus:()=>l(!o),onBlur:()=>{l(!1),d(null)},title:c?void 0:o?`${e(`plan.autoApprove`)} — chat · ${s.hint}`:C,className:B(`relative flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-xs whitespace-nowrap transition-colors select-none`,o?`border-dark-border text-dark-muted opacity-50 cursor-not-allowed`:B(`cursor-pointer outline-none focus-visible:ring-1 focus-visible:ring-accent-yellow/60`,i?`border-accent-yellow/40 bg-accent-yellow/10 text-accent-yellow`:`border-dark-border text-dark-muted hover:bg-dark-hover`)),children:[(0,Y.jsx)(`span`,{ref:h,className:`flex items-end gap-[2px]`,"aria-hidden":!0,children:Qe.map(e=>{let t=e>0&&a>=e;return(0,Y.jsx)(`span`,{title:c?void 0:S(e),onMouseOver:()=>d(e),onMouseDown:t=>{t.preventDefault(),y(e)},className:B(`w-[3px] rounded-sm transition-colors`,t?`bg-accent-yellow`:i?`bg-accent-yellow/25 hover:bg-accent-yellow/60`:`bg-dark-border`,!o&&(i?`hover:bg-accent-yellow/70`:`hover:bg-dark-muted/50`)),style:{height:4+e*2.5}},e)})}),(0,Y.jsx)(`span`,{className:`font-medium tabular-nums`,children:a}),(0,Y.jsx)(`span`,{className:`uppercase tracking-wide`,children:s.label}),c&&(0,Y.jsxs)(`div`,{id:f,role:`tooltip`,className:`pointer-events-none absolute bottom-full left-0 z-50 mb-2 w-max max-w-[min(80vw,30rem)] space-y-1 whitespace-normal break-words rounded-lg border border-dark-border bg-dark-surface px-2.5 py-2 text-start font-normal normal-case tracking-wide text-dark-text shadow-pop`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-1.5`,children:[(0,Y.jsx)(`span`,{className:`font-medium tabular-nums`,children:p}),(0,Y.jsx)(`span`,{className:`uppercase tracking-wide text-accent-yellow`,children:m.label}),(0,Y.jsx)(`span`,{className:`text-dark-muted`,children:m.hint})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-1.5 gap-y-0.5`,children:[(0,Y.jsx)(`span`,{className:`whitespace-nowrap text-accent-green`,children:e(`plan.autoAllows`)}),(0,Y.jsx)(`span`,{className:`text-dark-muted`,children:m.allows}),(0,Y.jsx)(`span`,{className:`whitespace-nowrap text-accent-yellow`,children:e(`plan.autoAsks`)}),(0,Y.jsx)(`span`,{className:`text-dark-muted`,children:m.asks})]})]})]})}),Q={act:`border-accent-green/30 text-accent-green bg-accent-green/10`,"auto-act":`border-accent-yellow/30 text-accent-yellow bg-accent-yellow/10`,goal:`border-accent-purple/30 text-accent-purple bg-accent-purple/10`,"auto-goal":`border-accent-red/30 text-accent-red bg-accent-red/10`,chat:`border-accent-cyan/30 text-accent-cyan bg-accent-cyan/10`,normal:`border-accent-green/30 text-accent-green`},Vt=(0,J.memo)(function(){let{t:e}=F(),t=K(e=>e.mode),n=K(e=>e.modeSource),r=K(e=>e.setBaseMode),i=U(t===`normal`?`act`:t),a=n===`user_override`;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[xe.map(n=>{let o=i===n,s=Se[n],c=t!==`normal`&&o?Q[t]??`border-dark-border text-dark-muted`:`border-dark-border text-dark-muted hover:bg-dark-hover`;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>r(n),className:B(`px-2 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors cursor-pointer`,c),title:e(`chat.clickToSwitchMode`),"aria-pressed":o,children:[s.label,o&&a&&(0,Y.jsx)(g,{size:10,className:`ms-1 inline-block -mt-px`,"aria-hidden":!0})]},n)}),a&&(0,Y.jsx)(`span`,{className:`flex items-center text-accent-yellow`,title:e(`plan.modeLocked`),"aria-label":e(`plan.modeLocked`),children:(0,Y.jsx)(g,{size:11,"aria-hidden":!0})}),(0,Y.jsx)(Bt,{})]})}),Ht=(0,J.memo)(function(){let{t:e}=F(),t=fe(e=>e.activeSessionId),n=K(e=>t?e.pendingSuggestionsBySession[t]:void 0),r=K(e=>e.clearPendingSuggestion),i=K(e=>e.setBaseMode);if(!n)return null;let a=n.suggestedMode;if(a!==`act`&&a!==`goal`)return null;let o=a,s=Se[o]?.label??o,c=Se[U(n.currentMode)]?.label??n.currentMode,l=typeof n.confidence==`number`?` · ${e(`plan.modeSuggestionConfidence`)} ${Math.round(n.confidence*100)}%`:``;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-accent-cyan/20 bg-accent-cyan/10 px-4 py-1.5 text-xs`,role:`status`,children:[(0,Y.jsx)(`span`,{className:`shrink-0 font-medium text-accent-cyan`,children:e(`plan.modeSuggestionTitle`)}),(0,Y.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1 text-dark-muted`,children:[(0,Y.jsx)(`span`,{className:`whitespace-nowrap`,children:c}),(0,Y.jsx)(v,{size:11,className:`shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{className:`whitespace-nowrap text-dark-text`,children:s}),(0,Y.jsx)(`span`,{className:`shrink-0`,children:l}),n.reason&&(0,Y.jsxs)(`span`,{className:`hidden min-w-0 truncate md:inline`,title:n.reason,children:[`· `,n.reason]})]}),(0,Y.jsxs)(`span`,{className:`ms-auto flex shrink-0 items-center gap-1.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{i(o),r(n.sessionId)},className:B(`flex items-center gap-1 rounded-full border border-accent-cyan/40 px-2.5 py-0.5`,`text-accent-cyan transition-colors hover:bg-accent-cyan/20 cursor-pointer`),children:[(0,Y.jsx)(ee,{size:11,"aria-hidden":!0}),e(`plan.modeSuggestionApply`,{mode:s})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>r(n.sessionId),className:B(`flex items-center gap-1 rounded-full border border-dark-border px-2.5 py-0.5`,`text-dark-muted transition-colors hover:bg-dark-hover cursor-pointer`),children:[(0,Y.jsx)(te,{size:11,"aria-hidden":!0}),e(`plan.modeSuggestionKeep`,{mode:c})]})]})]})}),Ut=ue();function Wt(){return Ae.get(`/api/models/cached`)}var Gt=(0,J.memo)(function(){let{t:e}=F(),t=de(e=>e.model),n=de(e=>e.modelRef),r=de(e=>e.setModel),i=de(e=>e.setModelRef),a=K(e=>e.mode),o=G(e=>e.effort),c=G(e=>e.setEffort),[l,u]=(0,J.useState)([]),[d,p]=(0,J.useState)(!1),{visible:h,phase:g}=me(d),v=(0,J.useRef)(null),y=(0,J.useRef)(null),[x,C]=(0,J.useState)(`session`),[w,T]=(0,J.useState)(`user`),E=Re(e=>e.kinds),D=Re(e=>e.load),O=fe(e=>e.activeSessionId),[k,A]=(0,J.useState)(`models`),[j,te]=(0,J.useState)(``),[M,ne]=(0,J.useState)(``),[re,ie]=(0,J.useState)({}),[ae,oe]=(0,J.useState)({}),[N,se]=(0,J.useState)(!1),[ce,le]=(0,J.useState)(null),[P,ue]=(0,J.useState)([]),I=(0,J.useMemo)(()=>q(Array.from(new Set(l.map(e=>e.provider).filter(Boolean))),l,P),[l,P]),L=(0,J.useCallback)(async()=>{try{let e=await W.models.list();e.success&&e.data&&Array.isArray(e.data.models)&&u(e.data.models.filter(e=>e.enabled!==!1))}catch{}},[]),pe=(0,J.useCallback)(async()=>{try{let e=await Wt();e.success&&e.data?.providers&&ie(e.data.providers)}catch{}},[]),R=(0,J.useCallback)(async t=>{if(t){se(!0),le(null);try{let n=await W.models.byProvider(t);if(n.success&&n.data){let e=n.data.models||[];oe(n=>({...n,[t]:e}))}else le(n.error||e(`chat.loadModelsFailed`))}catch{le(e(`chat.loadModelsFailed`))}finally{se(!1)}}},[e]);(0,J.useEffect)(()=>{L()},[L]);let[he,V]=(0,J.useState)(0);(0,J.useEffect)(()=>{let e=()=>{L(),pe(),V(e=>e+1)};return window.addEventListener(`models-updated`,e),()=>window.removeEventListener(`models-updated`,e)},[L,pe]);let[ge,_e]=(0,J.useState)(null),H=(0,J.useCallback)(()=>{let e=v.current;if(!e)return;let t=e.getBoundingClientRect();_e({left:Math.max(8,Math.min(t.left,window.innerWidth-400-8)),bottom:Math.max(8,window.innerHeight-t.top+6),maxHeight:Math.max(160,t.top-6-8)})},[]),ve=(0,J.useCallback)(()=>{let e=nt(n)||l.find(e=>e.isGlobalDefault)?.provider||I[0]||``;A(`models`),te(e),ne(``),le(null),H(),p(!0),pe()},[n,l,I,pe,H]);(0,J.useEffect)(()=>{d&&j&&R(j)},[d,j,he,R]),(0,J.useEffect)(()=>{d&&(j&&I.includes(j)||te(I[0]||``))},[d,j,I]),(0,J.useEffect)(()=>{d&&D()},[d,D]),(0,J.useEffect)(()=>{E.length!==0&&(E.some(e=>e.id===w)||T(E[0].id))},[E,w]);let ye=(0,J.useCallback)(()=>p(!1),[]);(0,J.useEffect)(()=>{if(d)return H(),window.addEventListener(`resize`,H),window.addEventListener(`scroll`,H,!0),()=>{window.removeEventListener(`resize`,H),window.removeEventListener(`scroll`,H,!0)}},[d,H]),(0,J.useEffect)(()=>{if(!d)return;let e=e=>{let t=e.target;v.current?.contains(t)||y.current?.contains(t)||ye()},t=e=>{e.key===`Escape`&&ye()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[d,ye]);let be=(0,J.useMemo)(()=>{let e=ae[j];return e&&e.length>0?e:re[j]?.models??[]},[ae,re,j]),xe=(0,J.useMemo)(()=>Ye(Xe(j,be,l),P,j),[j,be,l,P]),Se=(0,J.useMemo)(()=>{let e=M.trim().toLowerCase();return e?xe.filter(t=>t.id.toLowerCase().includes(e)||t.name.toLowerCase().includes(e)):xe},[xe,M]),Ce=e=>{ue(t=>[e,...t.filter(t=>t!==e)].slice(0,20))},we=async o=>{if(ye(),x===`session`&&!O){z.error(e(`chat.sessionModelNoSession`));return}let s=j,c=`${s}:${o.id}`,l=t,u=n;r(o.id),i(c);try{if(!o.configured){let t=await W.models.create({provider:s,model:{id:o.id,name:o.name||o.id}});if(!t.success){r(l),i(u),z.error(t.error||e(`chat.addModelFailed`));return}}if(x===`session`){let t=await W.models.setSessionModel(O,s,o.id);if(!t.success){r(l),i(u),z.error(t.error||e(`chat.switchModelFailed`));return}Ce(c),await L();return}if(x===`kind`){let t=Re.getState(),n=E.find(e=>e.id===w)?.labelKey?e(E.find(e=>e.id===w).labelKey):w;if(!await t.saveEntry(w,{...t.entries[w]??{},model:`${s}/${o.id}`,provider:s})){r(l),i(u),z.error(t.error||e(`chat.kindBindFailed`));return}if(O){let t=await W.models.setSessionModel(O,s,o.id);if(!t.success){r(l),i(u),z.error(t.error||e(`chat.switchModelFailed`));return}}Ce(c),z.success(e(`chat.kindBoundToast`,{kind:n,model:o.id})),await L();return}let t=U(a===`normal`?`act`:a)===`goal`?{goal:c}:{global:c,act:c},n=await W.models.setDefaults(t);if(!n.success){r(l),i(u),z.error(n.error||e(`chat.switchModelFailed`));return}Ce(c),await L()}catch{r(l),i(u),z.error(e(`chat.addModelFailed`))}},Te=U(a===`normal`?`act`:a),Ee=Te===`goal`?`isGoalDefault`:`isActDefault`,De=e=>{let r=`${j}:${e.id}`;return n?n===r:t===r||t===e.id},ke=l.some(e=>e[Ee]===!0),Ae=l.find(e=>e.isGlobalDefault),Me=async()=>{ye();let e=Te===`goal`?{goal:null}:{act:null};try{(await W.models.setDefaults(e)).success&&(Ae?(r(Ae.id),i(`${Ae.provider}:${Ae.id}`)):(r(``),i(``)),await L())}catch{}},Ne=Je(t,n),Pe=M.trim().toLowerCase();return(0,Y.jsxs)(`div`,{className:`relative min-w-0`,ref:v,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>d?ye():ve(),className:`flex w-full items-center gap-1 px-2 py-0.5 rounded-full border border-dark-border text-dark-muted whitespace-nowrap transition-colors hover:bg-dark-hover cursor-pointer`,title:Ne||e(`chat.clickToSelectModel`),"aria-haspopup":`listbox`,"aria-expanded":d,children:[(0,Y.jsx)(m,{size:12,className:`shrink-0`}),(0,Y.jsx)(`span`,{className:`font-medium max-w-[8rem] truncate`,children:Ne||e(`chat.selectModel`)}),(0,Y.jsx)(f,{size:12,className:B(`transition-transform`,d&&`rotate-180`)})]}),h&&(0,Ut.createPortal)((0,Y.jsxs)(`div`,{ref:y,role:`listbox`,"data-phase":g,"aria-label":e(`chat.selectModel`),style:ge?{left:ge.left,bottom:ge.bottom,maxHeight:ge.maxHeight}:void 0,className:`fixed z-50 flex w-[400px] max-w-[92vw] flex-col overflow-hidden rounded-lg border border-dark-border bg-dark-overlay ui-surface-overlay shadow-pop ui-overlay-panel-fade`,children:[(0,Y.jsx)(`div`,{role:`tablist`,"aria-label":e(`chat.selectModel`),className:`flex shrink-0 items-center gap-1 px-2 py-1.5 border-b border-dark-border`,children:[{key:`models`,label:e(`chat.selectModel`),Icon:m},{key:`effort`,label:e(`chat.effort`),Icon:S}].map(({key:e,label:t,Icon:n})=>(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":k===e,onClick:()=>A(e),className:B(`flex items-center gap-1 text-meta px-2 py-0.5 rounded-full border transition-colors cursor-pointer`,k===e?`border-accent-blue text-accent-blue bg-accent-blue/10 font-medium`:`border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover`),children:[(0,Y.jsx)(n,{size:11,className:`shrink-0`}),t]},e))}),k===`models`?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`flex shrink-0 items-center gap-1 px-2 py-1.5 border-b border-dark-border`,children:[{key:`session`,label:e(`chat.applyScopeSession`),hint:e(`chat.sessionScopeHint`)},{key:`kind`,label:e(`chat.applyScopeKind`),hint:e(`chat.kindScopeHint`)},{key:`global`,label:e(`chat.applyScopeGlobal`),hint:e(`chat.globalScopeHint`)}].map(({key:e,label:t,hint:n})=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>C(e),title:n,className:B(`text-meta px-2 py-0.5 rounded-full border transition-colors cursor-pointer`,x===e?`border-accent-blue text-accent-blue bg-accent-blue/10 font-medium`:`border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover`),children:t},e))}),x===`kind`&&(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5 px-2 py-1.5 border-b border-dark-border text-meta`,children:[(0,Y.jsx)(`span`,{className:`text-dark-muted`,children:e(`chat.kindSelectLabel`)}),(0,Y.jsx)(`select`,{value:w,onChange:e=>T(e.target.value),className:`rounded border border-dark-border bg-dark-surface px-1.5 py-0.5 text-meta text-dark-text`,children:E.map(t=>(0,Y.jsx)(`option`,{value:t.id,children:t.labelKey?e(t.labelKey):t.id},t.id))})]}),ke&&(0,Y.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":!1,onClick:Me,title:e(`chat.followGlobalDefaultHint`),className:`flex w-full shrink-0 items-center gap-2 px-3 py-2 text-start transition-colors hover:bg-dark-hover border-b border-dark-border/60`,children:[(0,Y.jsx)(b,{size:11,className:`shrink-0 text-accent-green`}),(0,Y.jsxs)(`span`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-semibold text-accent-green`,children:e(`chat.followGlobalDefault`)}),(0,Y.jsx)(`span`,{className:`block text-badge text-dark-muted mt-0.5 truncate`,children:Ae?Ae.name||Ae.id:e(`chat.noGlobalDefault`)})]})]}),I.length>0?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{role:`tablist`,"aria-label":e(`chat.selectProvider`),className:`flex shrink-0 items-center gap-1 px-2 py-1.5 border-b border-dark-border overflow-x-auto custom-scrollbar`,children:I.map(e=>{let t=e===j,n=ae[e]?.length||re[e]?.models.length||0;return(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":t,onClick:()=>{te(e),ne(``),le(null)},className:B(`shrink-0 flex items-center gap-1 text-meta px-2 py-0.5 rounded-full border transition-colors cursor-pointer`,t?`border-accent-blue text-accent-blue bg-accent-blue/10 font-medium`:`border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover`),children:[(0,Y.jsx)(`span`,{className:`max-w-[7rem] truncate`,children:e}),n>0&&(0,Y.jsx)(`span`,{className:`text-badge opacity-70`,children:n})]},e)})}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5 px-2 py-1.5 border-b border-dark-border`,children:[(0,Y.jsx)(_,{size:11,className:`shrink-0 text-dark-muted`}),(0,Y.jsx)(`input`,{value:M,onChange:e=>ne(e.target.value),placeholder:e(`chat.searchModels`),"aria-label":e(`chat.searchModels`),className:`flex-1 min-w-0 bg-dark-surface text-dark-text text-xs px-2 py-1 rounded border border-dark-border placeholder-dark-muted/60 focus:outline-none focus:border-accent-blue`})]}),(0,Y.jsxs)(`div`,{className:`min-h-0 overflow-y-auto py-1 custom-scrollbar`,style:{height:253},children:[N&&Se.length===0&&(0,Y.jsxs)(`div`,{className:`px-3 py-2 text-xs text-dark-muted flex items-center gap-1.5`,children:[(0,Y.jsx)(s,{size:11,className:`animate-spin`}),e(`chat.loadingModels`)]}),!N&&ce&&Se.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-xs text-accent-red`,children:ce}),Se.map(t=>{let n=De(t);return(0,Y.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":n,onClick:()=>{we(t)},className:B(`w-full shrink-0 flex items-center gap-2 px-3 py-2 text-start transition-colors`,n?`bg-dark-hover`:`hover:bg-dark-hover`),children:(0,Y.jsxs)(`span`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:B(`flex h-3.5 w-3.5 items-center justify-center rounded-full border transition-colors shrink-0`,n?`border-accent-green bg-accent-green/20 text-accent-green`:`border-dark-border text-transparent`),children:(0,Y.jsx)(ee,{size:10,strokeWidth:3})}),(0,Y.jsx)(`span`,{className:`text-xs font-semibold text-dark-text truncate`,children:t.name||t.id})]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 mt-0.5 flex-wrap ps-[1.375rem]`,children:[(0,Y.jsx)(`span`,{className:`text-badge text-dark-muted truncate`,children:t.id}),t.isGlobalDefault&&(0,Y.jsx)(`span`,{className:`text-badge px-1 rounded bg-accent-red/20 text-accent-red`,children:e(`chat.globalDefault`)}),t.isActDefault&&!t.isGlobalDefault&&(0,Y.jsx)(`span`,{className:`text-badge px-1 rounded bg-accent-yellow/20 text-accent-yellow`,children:e(`chat.actDefault`)}),t.isGoalDefault&&(0,Y.jsx)(`span`,{className:`text-badge px-1 rounded bg-accent-purple/20 text-accent-purple`,children:e(`chat.goalDefault`)})]})]})},t.id)}),!N&&!ce&&Se.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-xs text-dark-muted`,children:e(Pe?`chat.noModelsFound`:`chat.noProviderModels`)})]})]}):(0,Y.jsx)(`div`,{className:`px-3 py-2 text-xs text-dark-muted`,children:e(`chat.noConfiguredProviders`)})]}):(0,Y.jsx)(Y.Fragment,{children:(0,Y.jsx)(`div`,{className:`shrink-0 py-1`,children:je.map(t=>{let n=Oe[t],r=t===o;return(0,Y.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":r,onClick:()=>{c(t),ye()},className:B(`w-full flex items-center gap-2 px-3 py-1.5 text-start transition-colors`,r?`bg-dark-hover`:`hover:bg-dark-hover`),children:[(0,Y.jsx)(`span`,{className:B(`flex h-4 w-4 items-center justify-center rounded border transition-colors shrink-0`,r?`border-accent-green bg-accent-green/20 text-accent-green`:`border-dark-border text-transparent`),children:(0,Y.jsx)(ee,{size:11,strokeWidth:3})}),(0,Y.jsx)(`span`,{className:`text-xs font-medium ${r?n.color:`text-dark-text`}`,children:e(n.labelKey)})]},t)})})})]}),document.body)]})});function Kt(e){let t=(e??``).toLowerCase();return t?t.includes(`android`)?`android`:t.includes(`iphone`)||t.includes(`ipad`)||t.includes(`ipod`)?`ios`:t.includes(`mac`)||t.includes(`darwin`)?`macos`:t.includes(`win`)?`windows`:t.includes(`linux`)||t.includes(`x11`)||t.includes(`cros`)?`linux`:null:null}function qt(){if(typeof navigator>`u`)return`unknown`;let e=typeof navigator.userAgent==`string`?navigator.userAgent:``,t=Kt(e);if(t===`android`||t===`ios`)return t;let n=navigator.userAgentData,r=Kt(n?.platform);if(r)return r;let i=typeof navigator.platform==`string`?navigator.platform:``;return Kt(i)===`macos`&&(navigator.maxTouchPoints??0)>1?`ios`:Kt(i)??Kt(e)??`unknown`}function Jt(){if(typeof navigator>`u`)return`unknown`;let e=`${navigator.userAgentData?.architecture??``} ${navigator.userAgent??``} ${navigator.platform??``}`.toLowerCase();return/arm|aarch64|apple silicon/.test(e)?`arm64`:/x86_64|amd64|x64|win64|wow64|intel/.test(e)?`x64`:`unknown`}function Yt(){return typeof window<`u`&&window.__TAURI__!==void 0}var Xt={windows:`chat.desktopDownloadOsWindows`,macos:`chat.desktopDownloadOsMacos`,linux:`chat.desktopDownloadOsLinux`,android:`chat.desktopDownloadOsAndroid`,ios:`chat.desktopDownloadOsIos`,unknown:`chat.desktopDownloadOsUnknown`},Zt=[`windows`,`macos`,`linux`];function Qt(e){if(typeof e!=`number`||!Number.isFinite(e)||e<=0)return null;let t=e/1048576;return t>=10?`${Math.round(t)} MB`:`${t.toFixed(1)} MB`}function $t(e){try{return new URL(e).host}catch{return e}}function en(e){return e.url||e.mirrors[0]||``}function tn(e,t){let n=document.createElement(`a`);n.href=e,n.download=t,n.target=`_blank`,n.rel=`noopener`,n.style.display=`none`,document.body.appendChild(n),n.click(),n.remove()}var nn=(0,J.memo)(function({onHandoffToAi:e}){let{t:n}=F(),[r,i]=(0,J.useState)(`idle`),[a,s]=(0,J.useState)(null),[c,u]=(0,J.useState)(!1),d=(0,J.useRef)(null),f=(0,J.useRef)(!0),p=(0,J.useRef)(!1),m=(0,J.useRef)(!1);(0,J.useEffect)(()=>(f.current=!0,()=>{f.current=!1}),[]);let g=(0,J.useMemo)(()=>qt(),[]),_=(0,J.useMemo)(()=>Jt(),[]),v=(0,J.useMemo)(()=>Yt(),[]),y=n(Xt[g]),b=g===`android`||g===`ios`,x=v?n(`chat.desktopDownloadOtherPlatforms`):n(`chat.desktopDownloadTitle`,{os:y}),S=n(v?`chat.desktopDownloadOtherPlatforms`:`chat.desktopDownloadRecommend`),C=a?.artifacts??{},w=C[g]?.[0],T=a?.page||ve(),E=_===`arm64`&&(g===`windows`||g===`linux`),D=(0,J.useCallback)(()=>{p.current||(p.current=!0,i(`loading`),W.system.desktopDownload().then(e=>{f.current&&(e.success&&e.data?(s(e.data),i(`ready`)):i(`failed`))}).catch(()=>{f.current&&i(`failed`)}))},[]);(0,J.useEffect)(()=>{if(!c)return;let e=e=>{d.current?.contains(e.target)||u(!1)},t=e=>{e.key===`Escape`&&u(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[c]);let O=(0,J.useCallback)(()=>{window.open(T,`_blank`,`noopener`)},[T]),A=(0,J.useCallback)(e=>{let t=en(e);u(!1),t?(tn(t,e.name),e.url&&e.source===`mirror`&&z.info(n(`chat.desktopDownloadViaMirrorToast`))):(O(),z.warning(n(`chat.desktopDownloadUnavailable`)))},[O,n]),ee=(0,J.useCallback)(()=>{b?(O(),z.info(n(`chat.desktopDownloadMobileHint`))):r===`failed`?(O(),z.warning(n(`chat.desktopDownloadUnavailable`))):r===`ready`?w?A(w):(O(),z.warning(n(`chat.desktopDownloadUnavailable`))):(m.current=!0,D(),z.info(n(`chat.desktopDownloadFetching`)))},[A,b,O,w,D,r,n]);(0,J.useEffect)(()=>{(r===`ready`||r===`failed`)&&m.current&&(m.current=!1,ee())},[r,ee]);let j=(0,J.useCallback)(()=>{let t=w?en(w):T,r=(w?.mirrors??[]).slice(0,3).join(` `);e(n(`chat.desktopDownloadPrompt`,{os:y,url:t||T,mirrors:r||n(`chat.desktopDownloadPromptNoMirror`)})),u(!1),z.success(n(`chat.desktopDownloadHandToAiHint`))},[e,y,w,T,n]),te=(e,t,r)=>{let i=Qt(e.size),a=H(e.name);return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>A(e),className:`flex w-full items-center gap-2 px-3 py-1.5 text-start text-xs text-dark-text transition-colors hover:bg-dark-hover`,children:[(0,Y.jsx)(k,{size:12,className:`shrink-0 text-dark-muted`,"aria-hidden":`true`}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[(0,Y.jsxs)(`span`,{className:`font-medium`,children:[r?`${n(Xt[t])} · `:``,a]}),e.source===`mirror`&&(0,Y.jsx)(`span`,{className:`ms-1.5 rounded bg-accent-yellow/15 px-1 py-0.5 text-badge text-accent-yellow`,children:n(`chat.desktopDownloadFromMirror`)}),(0,Y.jsx)(`span`,{className:`mt-0.5 block truncate text-badge text-dark-muted`,children:e.name})]}),i&&(0,Y.jsx)(`span`,{className:`shrink-0 text-badge text-dark-muted`,children:n(`chat.desktopDownloadSize`,{size:i})})]},`${t}-${e.name}`)},M=Zt.filter(e=>e!==g&&(C[e]?.length??0)>0),ne=w?.mirrors??[];return(0,Y.jsxs)(`div`,{className:`relative flex shrink-0 items-center`,ref:d,onPointerEnter:D,onFocus:D,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:ee,className:`flex h-8 items-center gap-1.5 rounded-s-full ps-2.5 pe-1.5 text-meta font-medium text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,title:x,"aria-label":x,children:[(0,Y.jsx)(k,{size:14,className:`shrink-0`,"aria-hidden":`true`}),(0,Y.jsx)(`span`,{className:`hidden whitespace-nowrap sm:inline`,children:S})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{c||D(),u(!c)},className:`flex h-8 w-4 items-center justify-center rounded-e-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,title:n(`chat.desktopDownloadMenu`),"aria-label":n(`chat.desktopDownloadMenu`),"aria-haspopup":`menu`,"aria-expanded":c,children:(0,Y.jsx)(h,{size:11,className:B(`transition-transform`,c&&`rotate-180`),"aria-hidden":`true`})}),c&&(0,Y.jsxs)(`div`,{role:`menu`,"aria-label":n(`chat.desktopDownloadMenu`),className:`absolute bottom-full left-0 mb-1 z-50 w-72 overflow-hidden rounded-lg border border-dark-border bg-dark-overlay ui-surface-overlay shadow-pop`,children:[(0,Y.jsx)(`div`,{className:`border-b border-dark-border px-3 py-1.5 text-badge font-semibold uppercase tracking-wide text-dark-muted`,children:n(`chat.desktopDownloadYourSystem`,{os:y})}),(0,Y.jsx)(`div`,{className:`py-1`,children:(C[g]??[]).length>0?(C[g]??[]).map(e=>te(e,g,!1)):(0,Y.jsx)(`div`,{className:`px-3 py-1.5 text-meta leading-relaxed text-dark-muted`,children:n(b?`chat.desktopDownloadMobileMenuHint`:r===`failed`?`chat.desktopDownloadUnavailable`:`chat.desktopDownloadLoading`)})}),E&&(0,Y.jsx)(`div`,{className:`border-t border-dark-border px-3 py-1.5 text-badge leading-relaxed text-accent-yellow`,children:n(`chat.desktopDownloadArmHint`)}),M.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`border-y border-dark-border px-3 py-1.5 text-badge font-semibold uppercase tracking-wide text-dark-muted`,children:n(`chat.desktopDownloadOtherSystems`)}),(0,Y.jsx)(`div`,{className:`py-1`,children:[...M].flatMap(e=>(C[e]??[]).map(t=>te(t,e,!0)))})]}),(0,Y.jsx)(`div`,{className:`border-y border-dark-border px-3 py-1.5 text-badge font-semibold uppercase tracking-wide text-dark-muted`,children:n(`chat.desktopDownloadTrouble`)}),(0,Y.jsxs)(`div`,{className:`py-1`,children:[ne.slice(0,2).map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{u(!1),tn(e,w?.name??``)},className:`flex w-full items-center gap-2 px-3 py-1.5 text-start text-xs text-dark-text transition-colors hover:bg-dark-hover`,children:[(0,Y.jsx)(o,{size:12,className:`shrink-0 text-dark-muted`,"aria-hidden":`true`}),(0,Y.jsx)(`span`,{className:`truncate`,children:n(`chat.desktopDownloadViaMirror`,{host:$t(e)})})]},e)),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{u(!1),O()},className:`flex w-full items-center gap-2 px-3 py-1.5 text-start text-xs text-dark-text transition-colors hover:bg-dark-hover`,children:[(0,Y.jsx)(o,{size:12,className:`shrink-0 text-dark-muted`,"aria-hidden":`true`}),(0,Y.jsx)(`span`,{className:`truncate`,children:n(`chat.desktopDownloadOpenRelease`)})]})]}),(0,Y.jsx)(`div`,{className:`border-t border-dark-border`,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:j,className:`flex w-full items-center gap-2 px-3 py-2 text-start text-xs text-accent-blue transition-colors hover:bg-dark-hover`,children:[(0,Y.jsx)(t,{size:12,className:`shrink-0`,"aria-hidden":`true`}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:n(`chat.desktopDownloadHandToAi`)}),(0,Y.jsx)(`span`,{className:`mt-0.5 block text-badge text-dark-muted`,children:n(`chat.desktopDownloadHandToAiDesc`)})]})]})}),g===`macos`&&(0,Y.jsx)(`div`,{className:`border-t border-dark-border px-3 py-1.5 text-badge leading-relaxed text-dark-muted/80`,children:n(`chat.desktopDownloadMacUnsignedHint`)}),r!==`ready`&&r!==`failed`&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-dark-border px-3 py-1.5 text-badge text-dark-muted`,children:[(0,Y.jsx)(l,{size:10,className:`animate-spin`,"aria-hidden":`true`}),n(`chat.desktopDownloadFetching`)]})]})]})});function rn(e,t){if(!e)return t;let n=e.includes(`\\`)?`\\`:`/`;return e.endsWith(n)?e+t:e+n+t}function an(e,t=48){let n=e.replace(/[\\/]+$/,``);if(n.length<=t)return n;let r=n.includes(`\\`)?`\\`:`/`;return`…${r}${n.split(/[\\/]+/).filter(Boolean).slice(-2).join(r)}`}function on(e){return e.replace(/[\\/]+/g,`/`).replace(/\/+$/,``).toLowerCase()}function sn({isOpen:e,initial:t,onClose:n,onConfirm:r}){let{t:a}=F(),{visible:o,phase:s}=me(e),[u,d]=(0,J.useState)(t),[f,p]=(0,J.useState)(null),[m,h]=(0,J.useState)([]),[g,_]=(0,J.useState)(!1),[v,y]=(0,J.useState)(``),[b,x]=(0,J.useState)(t),S=(0,J.useRef)(null),C=(0,J.useCallback)(async e=>{_(!0),y(``);try{let t=await W.dirs.list(e);if(!t.success||!t.data){y(t.error||a(`chat.dirPickerLoadError`));return}d(t.data.path),p(t.data.parent),h(t.data.dirs||[]),x(t.data.path)}catch(e){y(e instanceof Error?e.message:a(`chat.dirPickerLoadError`))}finally{_(!1)}},[a]);(0,J.useEffect)(()=>{e&&C(t)},[e,t,C]),(0,J.useEffect)(()=>{S.current?.focus()},[]),(0,J.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),n())};return document.addEventListener(`keydown`,t),document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,t),document.body.style.overflow=``}},[e,n]);let w=(0,J.useCallback)(()=>{let e=b.trim();e&&C(e)},[b,C]),E=(0,J.useCallback)(()=>{f&&C(f)},[f,C]);return o?(0,Y.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center overflow-hidden p-4`,role:`dialog`,"aria-modal":`true`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 ui-scrim ui-overlay-backdrop`,"data-phase":s,onClick:n}),(0,Y.jsxs)(`div`,{className:`relative w-full max-w-lg mx-4 bg-dark-overlay ui-surface-overlay border border-dark-border rounded-xl shadow-pop flex flex-col max-h-[70vh] ui-overlay-panel`,"data-phase":s,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2.5 border-b border-dark-border shrink-0`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-2 text-compact font-semibold text-dark-text`,children:[(0,Y.jsx)(se,{size:15,className:`text-accent-blue`,"aria-hidden":`true`}),a(`chat.dirPickerTitle`)]}),(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-dark-muted hover:bg-dark-hover hover:text-dark-text transition-colors`,"aria-label":a(`a11y.close`),children:(0,Y.jsx)(te,{size:15,"aria-hidden":`true`})})]}),(0,Y.jsxs)(`div`,{className:`p-4 flex flex-col gap-3 min-h-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsx)(T,{size:13,className:`absolute start-2.5 top-1/2 -translate-y-1/2 text-dark-muted/60`,"aria-hidden":`true`}),(0,Y.jsx)(`input`,{ref:S,value:b,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&w()},placeholder:a(`chat.dirPickerEnterPath`),spellCheck:!1,className:`w-full rounded-lg border border-dark-border bg-dark-surface ps-8 pe-2.5 py-1.5 text-xs font-mono text-dark-text
3
+ placeholder-dark-muted/50 focus:outline-none focus:border-accent-blue/50 focus:ring-2 focus:ring-accent-blue/10`})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:w,disabled:g||!b.trim(),className:`shrink-0 rounded-lg border border-dark-border px-2.5 py-1.5 text-xs text-dark-muted
4
+ hover:bg-dark-hover hover:text-dark-text disabled:opacity-40 transition-colors`,children:a(`chat.dirPickerGo`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`flex-1 truncate font-mono text-meta text-dark-muted bg-dark-surface rounded-md px-2 py-1 border border-dark-border`,title:u,children:u||a(`chat.noWorkspaceDir`)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>void E(),disabled:g||!u,className:`shrink-0 flex items-center gap-1 rounded-md border border-dark-border px-2 py-1 text-meta text-dark-muted
5
+ hover:bg-dark-hover hover:text-dark-text disabled:opacity-40 transition-colors`,children:[(0,Y.jsx)(c,{size:12,"aria-hidden":`true`}),a(`chat.dirPickerUp`)]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar rounded-lg border border-dark-border bg-dark-surface divide-y divide-dark-border/60`,children:g?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-6 text-xs text-dark-muted`,children:[(0,Y.jsx)(l,{size:14,className:`animate-spin`,"aria-hidden":`true`}),a(`chat.loading`)]}):v?(0,Y.jsx)(`div`,{className:`px-3 py-4 text-xs text-accent-red`,children:v}):m.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-4 text-xs text-dark-muted/60 text-center`,children:a(`chat.dirPickerNoDirs`)}):m.map(e=>{let t=rn(u,e);return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>void C(t),className:`w-full flex items-center gap-2 px-3 py-1.5 text-start text-xs text-dark-text
6
+ hover:bg-dark-hover transition-colors group`,children:[(0,Y.jsx)(ce,{size:13,className:`shrink-0 text-accent-yellow/80 group-hover:text-accent-yellow`,"aria-hidden":`true`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e}),(0,Y.jsx)(i,{size:12,className:`shrink-0 ms-auto text-dark-muted/40`,"aria-hidden":`true`})]},e)})}),(0,Y.jsx)(he,{variant:`accent`,className:`w-full`,onClick:()=>r(u),disabled:!u,loading:g,children:a(`chat.dirPickerConfirm`)})]})]})]}):null}var cn=(0,J.memo)(function({workspaceDir:e,onSelect:t,onNewSessionInDir:n,compact:r=!1}){let{t:a}=F(),o=G(e=>e.recentDirs),s=V(e=>e.projects),c=V(e=>e.hidden),l=V(e=>e.sort),u=V(e=>e.disabled),d=V(e=>e.lastError),[p,m]=(0,J.useState)(!1),[h,g]=(0,J.useState)(!1),_=(0,J.useRef)(null);(0,J.useEffect)(()=>{if(!p)return;let e=V.getState();e.disabled||e.lastFetchedAt>0||e.refresh()},[p]),(0,J.useEffect)(()=>{if(!p)return;let e=e=>{_.current&&!_.current.contains(e.target)&&m(!1)},t=e=>{e.key===`Escape`&&m(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[p]);let v=(0,J.useCallback)(e=>{let n=e?.trim?.()||``;n&&(m(!1),g(!1),t(n))},[t]),y=(0,J.useCallback)(e=>{let t=e?.trim?.()||``;t&&n&&(m(!1),g(!1),n(t))},[n]),b=new Set(c),x=u?[]:_e(s.filter(e=>e.rootExists&&!b.has(e.projectId)),l),S=new Set(x.map(e=>on(e.root))),C=o.filter(e=>!S.has(on(e))),w=e?on(e):null,T=x.length>0||s.length===0&&!u&&d!==null;return(0,Y.jsxs)(`div`,{className:B(`min-w-0`,r?`w-full`:`relative max-w-[min(70%,26rem)]`),ref:_,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:B(`flex w-full items-center gap-1 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors cursor-pointer`,r?`px-1.5`:`px-2`,p?`border-accent-blue/40 text-accent-blue bg-accent-blue/10`:`border-dark-border text-dark-muted hover:bg-dark-hover hover:text-dark-text`),title:e?`${e}\n${a(`chat.clickToSwitchDir`)}`:a(`chat.clickToSwitchDir`),"aria-label":a(`chat.clickToSwitchDir`),"aria-expanded":p,"aria-haspopup":`menu`,children:[(0,Y.jsx)(se,{size:12,className:`shrink-0 text-accent-blue/80`,"aria-hidden":`true`}),(0,Y.jsx)(`span`,{className:B(`truncate font-mono text-meta`,r&&`max-sm:hidden`),children:e?an(e):a(`chat.noWorkspaceDir`)}),(0,Y.jsx)(f,{size:11,className:B(`shrink-0 transition-transform`,p&&`rotate-180`),"aria-hidden":`true`})]}),p&&(0,Y.jsxs)(`div`,{role:`menu`,className:`absolute bottom-full right-0 mb-2 w-72 max-w-[calc(100vw-1.5rem)] max-h-[70vh] overflow-y-auto custom-scrollbar rounded-xl border border-dark-border bg-dark-overlay ui-surface-overlay shadow-pop z-40 animate-fade-in`,children:[T&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`px-3 pt-2.5 pb-1 text-badge font-semibold uppercase tracking-wide text-dark-muted/50 select-none`,children:a(`chat.projectDirs`)}),x.length===0?(0,Y.jsx)(`div`,{className:`px-3 pb-2 text-meta text-accent-red/80 select-none`,children:a(`chat.projectsLoadFailed`)}):(0,Y.jsx)(`div`,{className:`max-h-44 overflow-y-auto custom-scrollbar`,"data-testid":`dir-picker-projects`,children:x.map(e=>{let t=w!==null&&on(e.root)===w;return(0,Y.jsxs)(`div`,{className:`flex items-stretch`,children:[(0,Y.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":`dir-picker-project-row`,"data-project-id":e.projectId,onClick:()=>v(e.root),className:B(`min-w-0 flex-1 flex items-center gap-2 px-3 py-1.5 text-start text-xs transition-colors group`,t?`text-accent-blue bg-accent-blue/5`:`text-dark-text hover:bg-dark-hover`),title:`${a(`chat.dirSwitchHere`)}\n${e.root}`,children:[(0,Y.jsx)(ce,{size:12,className:B(`shrink-0`,t?`text-accent-blue`:`text-accent-yellow/80 group-hover:text-accent-yellow`),"aria-hidden":`true`}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:`block truncate`,children:e.name}),(0,Y.jsx)(`span`,{className:`block truncate font-mono text-meta text-dark-muted/60`,children:e.root})]}),t&&(0,Y.jsx)(`span`,{className:`shrink-0 text-badge text-accent-blue`,children:`✓`})]}),n&&(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dir-picker-project-new-session`,"data-project-id":e.projectId,onClick:t=>{t.stopPropagation(),y(e.root)},className:`shrink-0 px-2 text-dark-muted hover:text-accent-blue hover:bg-dark-hover transition-colors`,title:a(`chat.dirNewSessionHere`),"aria-label":`${a(`chat.dirNewSessionHere`)}:${e.name}`,children:(0,Y.jsx)(E,{size:12,"aria-hidden":`true`})})]},e.projectId)})}),(0,Y.jsx)(`div`,{className:`border-t border-dark-border`})]}),(0,Y.jsx)(`div`,{className:`px-3 pt-2.5 pb-1 text-badge font-semibold uppercase tracking-wide text-dark-muted/50 select-none`,children:a(`chat.recentDirs`)}),C.length===0?(0,Y.jsx)(`div`,{className:`px-3 pb-2 text-meta text-dark-muted/50 select-none`,children:a(`chat.noRecentDirs`)}):(0,Y.jsx)(`div`,{className:`max-h-56 overflow-y-auto custom-scrollbar`,children:C.map(e=>{let t=w!==null&&on(e)===w;return(0,Y.jsxs)(`div`,{className:`flex items-stretch`,children:[(0,Y.jsxs)(`button`,{type:`button`,role:`menuitem`,"data-testid":`dir-picker-recent-row`,onClick:()=>v(e),className:B(`min-w-0 flex-1 flex items-center gap-2 px-3 py-1.5 text-start text-xs transition-colors group`,t?`text-accent-blue bg-accent-blue/5`:`text-dark-text hover:bg-dark-hover`),title:`${a(`chat.dirSwitchHere`)}\n${e}`,children:[(0,Y.jsx)(ce,{size:12,className:B(`shrink-0`,t?`text-accent-blue`:`text-accent-yellow/80 group-hover:text-accent-yellow`),"aria-hidden":`true`}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-meta`,children:e}),t&&(0,Y.jsx)(`span`,{className:`ms-auto shrink-0 text-badge text-accent-blue`,children:`✓`})]}),n&&(0,Y.jsx)(`button`,{type:`button`,"data-testid":`dir-picker-recent-new-session`,onClick:t=>{t.stopPropagation(),y(e)},className:`shrink-0 px-2 text-dark-muted hover:text-accent-blue hover:bg-dark-hover transition-colors`,title:a(`chat.dirNewSessionHere`),"aria-label":`${a(`chat.dirNewSessionHere`)}:${e}`,children:(0,Y.jsx)(E,{size:12,"aria-hidden":`true`})})]},e)})}),(0,Y.jsx)(`div`,{className:`border-t border-dark-border`}),(0,Y.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{m(!1),g(!0)},className:`w-full flex items-center gap-2 px-3 py-2 text-start text-xs text-accent-blue hover:bg-dark-hover transition-colors`,children:[(0,Y.jsx)(i,{size:13,"aria-hidden":`true`}),a(`chat.chooseOtherDir`)]})]}),(0,Ut.createPortal)((0,Y.jsx)(sn,{isOpen:h,initial:e||``,onClose:()=>g(!1),onConfirm:v}),document.body)]})});function ln(e){return e?.find(e=>e.current)??null}function un(e){let t=ln(e),n=e?.[0];return t&&n&&t.path!==n.path?t.path:null}function dn(e){let t=new Map;for(let n of e??[])!n.current&&n.branch&&t.set(n.branch,n.path);return t}var fn=(0,J.memo)(function({compact:e=!1,disabled:t=!1}){let{t:n}=F(),r=Ve(e=>e.status),i=Ve(e=>e.branches),a=Ve(e=>e.branchesLoading),o=Ve(e=>e.switchingTo),s=Ve(e=>e.fetching),c=Ve(e=>e.refreshBranches),l=Ve(e=>e.switchBranch),u=Ve(e=>e.fetchRemote),[d,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(``),g=(0,J.useRef)(null),v=(0,J.useRef)(null),y=r?.branch??i?.current;(0,J.useEffect)(()=>{if(!d)return;h(``),c();let e=window.setTimeout(()=>v.current?.focus(),0);return()=>window.clearTimeout(e)},[d,c]),(0,J.useEffect)(()=>{if(!d)return;let e=e=>{g.current&&!g.current.contains(e.target)&&p(!1)},t=e=>{e.key===`Escape`&&p(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[d]);let b=(0,J.useCallback)(async e=>{if(e===y){p(!1);return}let t=await l(e);t?z.error(t):p(!1)},[y,l]),x=(0,J.useCallback)(async()=>{let e=await u();e?z.error(e):z.success(n(`git.fetchDone`))},[u,n]),S=(0,J.useMemo)(()=>{let e=i?.branches??[],t=m.trim().toLowerCase();return t?e.filter(e=>e.toLowerCase().includes(t)):e},[i,m]),C=(0,J.useMemo)(()=>dn(i?.worktrees),[i]),w=un(r?.worktrees),T=i?un(i.worktrees):w;if(!r?.available||!y)return null;let E=o!==null,O=w?`${y}\n${n(`git.inWorktree`,{path:w})}\n${n(`git.clickToSwitchBranch`)}`:`${y}\n${n(`git.clickToSwitchBranch`)}`;return(0,Y.jsxs)(`div`,{className:B(`min-w-0`,e?`w-full`:`relative max-w-[min(40%,16rem)]`),ref:g,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{t||p(e=>!e)},className:B(`flex w-full items-center gap-1 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors`,e?`px-1.5`:`px-2`,t?`cursor-not-allowed opacity-60`:`cursor-pointer`,d?`border-accent-blue/40 text-accent-blue bg-accent-blue/10`:`border-dark-border text-dark-muted hover:bg-dark-hover hover:text-dark-text`),title:t?y:O,"aria-label":n(`git.clickToSwitchBranch`),"aria-expanded":d,"aria-haspopup":`menu`,disabled:t,children:[(0,Y.jsx)(P,{size:12,className:`shrink-0 text-accent-blue/80`,"aria-hidden":`true`}),(0,Y.jsx)(`span`,{className:B(`truncate font-mono text-meta`,e&&`max-sm:hidden`),children:y}),w&&(0,Y.jsx)(`span`,{title:n(`git.inWorktree`,{path:w}),className:B(`shrink-0 rounded-sm bg-dark-border/60 px-1 font-mono text-badge text-dark-text`,e&&`max-sm:hidden`),children:n(`git.worktreeBadge`)}),(0,Y.jsx)(f,{size:11,className:B(`shrink-0 transition-transform`,d&&`rotate-180`),"aria-hidden":`true`})]}),d&&(0,Y.jsxs)(`div`,{role:`menu`,className:`absolute bottom-full right-0 mb-2 w-72 max-w-[calc(100vw-1.5rem)] rounded-xl border border-dark-border bg-dark-overlay ui-surface-overlay shadow-pop z-40 animate-fade-in`,children:[(0,Y.jsxs)(`div`,{className:`relative p-2 border-b border-dark-border`,children:[(0,Y.jsx)(_,{size:12,className:`absolute start-4 top-1/2 -translate-y-1/2 text-dark-muted`,"aria-hidden":`true`}),(0,Y.jsx)(`input`,{ref:v,type:`text`,value:m,onChange:e=>h(e.target.value),placeholder:n(`git.searchBranch`),className:`w-full ps-6 pe-2 py-1 text-xs bg-dark-bg border border-dark-border rounded focus:border-accent-blue focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`max-h-[50vh] overflow-y-auto custom-scrollbar py-1`,children:[(0,Y.jsx)(`div`,{className:`px-3 pt-1 pb-1 text-badge font-semibold uppercase tracking-wide text-dark-muted/50 select-none`,children:n(`git.localBranches`)}),T&&(0,Y.jsx)(`div`,{className:`px-3 pb-1 font-mono text-badge text-dark-muted/70 truncate`,title:T,"data-testid":`branch-picker-worktree`,children:n(`git.inWorktree`,{path:T})}),S.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-2 text-xs text-dark-muted`,children:n(a?`git.loading`:`git.noBranchMatch`)}):S.map(e=>{let t=e===y,r=C.get(e);return(0,Y.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{b(e)},disabled:E||r!==void 0,title:r?n(`git.branchHeldByWorktree`,{path:r}):void 0,className:B(`flex w-full items-center gap-2 px-3 py-1.5 text-xs text-start transition-colors`,E?`cursor-wait opacity-60`:r?`cursor-not-allowed opacity-50`:`hover:bg-dark-hover`,t?`text-accent-blue`:r?`text-dark-muted`:`text-dark-text`),children:[(0,Y.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:e}),r&&(0,Y.jsx)(`span`,{className:`shrink-0 rounded border border-dark-border px-1 text-badge text-dark-muted`,children:n(`git.worktreeBadge`)}),o===e?(0,Y.jsx)(D,{size:12,className:`shrink-0 animate-spin`,"aria-hidden":`true`}):t?(0,Y.jsx)(ee,{size:12,className:`shrink-0`,"aria-hidden":`true`}):null]},e)})]}),(0,Y.jsx)(`div`,{className:`border-t border-dark-border p-1`,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{x()},disabled:s,className:`flex w-full items-center gap-2 rounded px-2 py-1.5 text-xs text-dark-muted hover:bg-dark-hover hover:text-dark-text disabled:cursor-wait disabled:opacity-60`,children:[(0,Y.jsx)(D,{size:12,className:B(`shrink-0`,s&&`animate-spin`),"aria-hidden":`true`}),(0,Y.jsx)(`span`,{children:n(`git.fetchAndRefresh`)})]})})]})]})}),pn=`__files__`,mn=`__sessions__`;function hn(e){return e===`enqueue`?`summarize`:e===`summarize`?`next-step`:e===`next-step`?`direct`:`enqueue`}function gn(e){return e.replace(/[\\/]+$/,``).replace(/\\/g,`/`).toLowerCase()}function _n(e){return[{key:pn,label:e.files},{key:mn,label:e.sessions}]}function vn(e){return e?gn(e):`￿`}function yn(e,t){return t===`__files__`?e.filter(e=>e.kind===`file`):[...e.filter(e=>e.kind===`session`)].sort((e,t)=>vn(e.kind===`session`?e.dir:``).localeCompare(vn(t.kind===`session`?t.dir:``)))}function bn(e,t,n){if(e.length===0)return t;let r=e.indexOf(t),i=r<0?-1:r;return n?e[(i+1)%e.length]:e[((i<0?e.length:i)-1+e.length)%e.length]}var xn=new Set([`running`]);function Sn(e){return xn.has(String(e.status||``))?!0:e.live===!0}function Cn(e,t){let n=[];for(let r of e){let e=String(r.id||r.sessionId||``);if(!e||e===t)continue;let i=String(r.title||e.slice(0,8));n.push({kind:`session`,key:e,label:i,detail:e.slice(0,8),dir:String(r.workspaceDir||``),status:r.status===void 0?void 0:String(r.status),updatedAt:r.updatedAt===void 0?void 0:String(r.updatedAt),messageCount:typeof r.messageCount==`number`?r.messageCount:void 0})}return n}function wn(e,t,n=`active`){let r=Cn(e,t);if(n===`all`)return r;let i=new Map(e.map(e=>[String(e.id||e.sessionId||``),e]));return r.filter(e=>{let t=i.get(e.key);return t?Sn(t):!1})}var Tn={enqueue:`chat.mentionDeliveryEnqueue`,summarize:`chat.mentionDeliverySummarize`,"next-step":`chat.mentionDeliveryNextStep`,direct:`chat.mentionDeliveryDirect`},En={enqueue:`text-dark-muted hover:text-dark-text hover:bg-dark-hover`,summarize:`text-dark-muted hover:text-dark-text hover:bg-dark-hover`,"next-step":`bg-accent-blue/20 text-accent-blue font-medium`,direct:`bg-accent-green/20 text-accent-green font-medium`};function Dn(e){return e===`running`?`bg-accent-green/15 text-accent-green`:e===`paused`||e===`interrupted`||e===`error`?`bg-accent-yellow/15 text-accent-yellow`:`bg-dark-hover text-dark-muted`}function On(e){return e===`running`?`chat.mentionStatusRunning`:e===`paused`||e===`interrupted`?`chat.mentionStatusPaused`:e===`error`?`chat.mentionStatusError`:e===`stopped`?`chat.mentionStatusStopped`:`chat.mentionStatusIdle`}function kn(e){return e?/^\d{12,}$/.test(e)?Number(e):e:0}function An({isOpen:e,items:t,selectedIndex:n,query:r,isSearching:i,onSelect:a,onHover:o,selectedCount:s=0,onFinish:c,tabs:u,activeTab:d,onTabChange:f,scope:p=`active`,onToggleScope:m,deliveryMode:h=`enqueue`,onToggleDelivery:g}){let{t:_}=F(),{visible:v,phase:y}=me(e);if(!v)return null;let b=!!(f&&u&&u.length>1);return(0,Y.jsxs)(`div`,{className:`absolute bottom-full left-0 right-0 mb-2 bg-dark-overlay ui-surface-overlay border border-dark-border rounded-lg shadow-pop overflow-hidden z-50 ui-overlay-panel-fade`,"data-phase":y,children:[(0,Y.jsxs)(`div`,{className:`max-h-60 overflow-y-auto custom-scrollbar`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 text-meta text-dark-muted border-b border-dark-border bg-dark-surface`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-dark-text`,children:r?`@${r}`:`@ ${_(`chat.mentionFilesGroup`)} / ${_(`chat.mentionSessionsGroup`)}`}),(0,Y.jsxs)(`span`,{className:`opacity-70 flex items-center gap-2`,children:[s>0&&(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full bg-accent-blue/20 text-accent-blue font-medium`,children:_(`chat.selectedCountShort`,{n:s})}),(0,Y.jsx)(`span`,{children:_(b?`chat.mentionTabHint`:`chat.fileMentionHelpMulti`)})]})]}),b&&(0,Y.jsx)(`div`,{className:`flex items-center gap-1 px-3 py-1.5 border-b border-dark-border bg-dark-surface overflow-x-auto custom-scrollbar`,children:u.map(e=>{let t=e.key===d;return(0,Y.jsx)(`button`,{type:`button`,onMouseDown:t=>{t.preventDefault(),f(e.key)},className:`px-2 py-0.5 rounded text-meta whitespace-nowrap transition-colors ${t?`bg-accent-blue/20 text-accent-blue font-medium`:`text-dark-muted hover:text-dark-text hover:bg-dark-hover`}`,children:e.label},e.key)})}),t.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-6 text-center text-dark-muted text-xs flex flex-col items-center gap-1`,children:i?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(l,{size:16,className:`animate-spin`}),(0,Y.jsx)(`span`,{children:_(`chat.searchingFiles`)})]}):(0,Y.jsx)(`span`,{children:_(b&&d!==`__files__`?`chat.mentionEmptySessions`:`chat.noMatchingFiles`)})}):t.map((e,r)=>{let i=t[r-1],s=i&&i.kind===`session`?i.dir||``:null,c=e.kind===`session`?e.dir||``:null,l=!i||i.kind!==e.kind||c!==null&&s!==c,u=c===null?_(`chat.mentionFilesGroup`):`📁 ${c||_(`chat.mentionTabUnknownDir`)}`;return(0,Y.jsxs)(`div`,{children:[l&&(0,Y.jsx)(`div`,{className:`px-3 pt-2 pb-1 text-badge uppercase tracking-wide text-dark-muted/70 bg-dark-surface/40 truncate`,title:u,children:u}),(0,Y.jsxs)(`button`,{onClick:()=>a(e),onMouseEnter:()=>o(r),className:`w-full px-3 py-1.5 flex items-center gap-2 text-start text-xs transition-colors border-s-2 ${r===n?`bg-accent-blue/20 text-accent-blue border-accent-blue`:`hover:bg-dark-hover text-dark-text border-transparent`}`,children:[e.kind===`session`?(0,Y.jsx)(w,{size:12,className:`text-accent-blue shrink-0`}):e.isDir?(0,Y.jsx)(ce,{size:12,className:`text-accent-yellow shrink-0`}):(0,Y.jsx)(A,{size:12,className:`text-dark-muted shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.label}),e.kind===`session`?(0,Y.jsxs)(`span`,{className:`ms-auto flex shrink-0 items-center gap-1.5`,children:[e.detail&&(0,Y.jsx)(`span`,{className:`text-badge text-dark-muted truncate`,children:e.detail}),e.updatedAt&&(0,Y.jsx)(`span`,{className:`text-badge text-dark-muted/70`,children:ge(kn(e.updatedAt),Date.now(),_)}),e.messageCount!==void 0&&(0,Y.jsx)(`span`,{className:`text-badge text-dark-muted/70`,children:_(`chat.mentionMsgCount`,{count:e.messageCount})}),(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full text-badge whitespace-nowrap ${Dn(e.status)}`,children:_(On(e.status))})]}):e.detail&&(0,Y.jsx)(`span`,{className:`text-badge text-dark-muted truncate ms-auto`,children:e.detail})]})]},e.key)})]}),c&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-t border-dark-border bg-dark-surface`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-2 text-badge text-dark-muted`,children:[b&&m&&(0,Y.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:m,className:`px-1.5 py-0.5 rounded text-badge transition-colors ${p===`all`?`bg-accent-blue/20 text-accent-blue font-medium`:`text-dark-muted hover:text-dark-text hover:bg-dark-hover`}`,title:_(`chat.mentionScopeHint`),children:[_(`chat.mentionScopeLabel`),_(p===`all`?`chat.mentionScopeAll`:`chat.mentionScopeActive`)]}),b&&g&&(0,Y.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:g,className:`px-1.5 py-0.5 rounded text-badge transition-colors ${En[h]}`,title:_(`chat.mentionDeliveryHint`),children:[_(`chat.mentionDeliveryLabel`),_(Tn[h])]}),(0,Y.jsx)(`span`,{children:s>0?_(`chat.selectedFilesCount`,{n:s}):_(`chat.enterInsertMulti`)})]}),(0,Y.jsx)(he,{variant:`accent`,size:`sm`,onClick:c,children:_(`chat.finishMention`)})]})]})}function jn({open:e,onClose:t,onSelect:n}){let{t:r}=F(),[i,a]=(0,J.useState)([]),[o,s]=(0,J.useState)(!1),[c,l]=(0,J.useState)(``);(0,J.useEffect)(()=>{e&&(l(``),s(!0),W.skills.list().then(e=>{let t=Array.isArray(e.data)?e.data:[];a(t.filter(e=>e.enabled!==!1))}).catch(()=>a([])).finally(()=>s(!1)))},[e]);let u=(0,J.useMemo)(()=>{let e=c.trim().toLowerCase();return e?i.filter(t=>[t.id,t.name,t.description,t.category,...t.tags||[]].join(` `).toLowerCase().includes(e)):i},[i,c]);return(0,Y.jsx)(Le,{isOpen:e,onClose:t,title:r(`skills.pickTitle`),size:`lg`,children:(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-dark-bg border border-dark-border focus-within:border-accent-blue`,children:[(0,Y.jsx)(_,{size:14,className:`text-dark-muted shrink-0`}),(0,Y.jsx)(`input`,{value:c,onChange:e=>l(e.target.value),placeholder:r(`skills.pickPlaceholder`),autoFocus:!0,className:`flex-1 bg-transparent outline-none text-sm placeholder-dark-muted/60`}),o&&(0,Y.jsx)(D,{size:13,className:`animate-spin text-dark-muted`})]}),o?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,Y.jsx)(D,{size:20,className:`animate-spin text-accent-blue`})}):u.length===0?(0,Y.jsx)(`div`,{className:`text-center py-12 text-sm text-dark-muted`,children:r(`skills.pickEmpty`)}):(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:u.map(e=>(0,Y.jsxs)(`button`,{onClick:()=>n(e),className:`text-start rounded-lg border border-dark-border p-3 flex flex-col gap-1 transition-colors hover:border-accent-blue/50 hover:bg-dark-hover`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 min-w-0`,children:[(0,Y.jsxs)(`span`,{className:`font-medium text-sm truncate`,children:[e.icon||`⭐`,` `,e.name]}),(0,Y.jsx)(`span`,{className:`text-badge px-1.5 py-0.5 rounded bg-dark-bg border border-dark-border text-dark-muted shrink-0`,children:e.injection||`lazy`})]}),(0,Y.jsxs)(`div`,{className:`text-xs text-dark-muted truncate font-mono`,children:[`$`,e.id]}),e.description&&(0,Y.jsx)(`div`,{className:`text-xs text-dark-muted line-clamp-2`,children:e.description}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mt-1`,children:[(0,Y.jsx)(`span`,{className:`text-badge px-1.5 py-0.5 rounded bg-dark-bg border border-dark-border text-dark-muted truncate`,children:e.category||`—`}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-meta text-accent-blue shrink-0`,children:[(0,Y.jsx)(ae,{size:11}),r(`skills.pickUse`)]})]})]},e.id))})]})})}function Mn({isOpen:e,items:n,selectedIndex:r,query:i,isLoading:a,onSelect:o,onHover:s}){let{t:c}=F(),{visible:u,phase:d}=me(e);return u?(0,Y.jsx)(`div`,{className:`absolute bottom-full left-0 right-0 mb-2 bg-dark-overlay ui-surface-overlay border border-dark-border rounded-lg shadow-pop overflow-hidden z-50 ui-overlay-panel-fade`,"data-phase":d,children:(0,Y.jsxs)(`div`,{className:`max-h-60 overflow-y-auto custom-scrollbar`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 text-meta text-dark-muted border-b border-dark-border bg-dark-surface`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-dark-text truncate`,children:i?`$${i}`:c(`chat.skillMenuTitle`)}),(0,Y.jsx)(`span`,{className:`opacity-70 shrink-0`,children:c(`chat.skillMenuHint`)})]}),n.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-6 text-center text-dark-muted text-xs flex flex-col items-center gap-1`,children:a?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(l,{size:16,className:`animate-spin`}),(0,Y.jsx)(`span`,{children:c(`chat.skillMenuLoading`)})]}):(0,Y.jsx)(`span`,{children:c(`chat.skillMenuEmpty`)})}):n.map((e,n)=>(0,Y.jsxs)(`button`,{onClick:()=>o(e),onMouseEnter:()=>s(n),className:`w-full px-3 py-1.5 flex items-center gap-2 text-start text-xs transition-colors border-s-2 ${n===r?`bg-accent-blue/20 text-accent-blue border-accent-blue`:`hover:bg-dark-hover text-dark-text border-transparent`}`,children:[(0,Y.jsx)(`span`,{className:`shrink-0`,"aria-hidden":`true`,children:e.icon||(0,Y.jsx)(t,{size:12,className:`text-accent-blue`})}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.name||e.id}),(0,Y.jsxs)(`span`,{className:`text-badge font-mono text-dark-muted shrink-0`,children:[`$`,e.id]}),e.description&&(0,Y.jsx)(`span`,{className:`text-badge text-dark-muted truncate ms-auto`,children:e.description})]},e.id))]})}):null}function Nn(e){for(let t=e.length-1;t>=0;t--)if(e[t]===`$`){if(t>0&&/\w/.test(e.charAt(t-1)))continue;return t}return-1}function Pn(e,t){let n=t.filter(e=>e.enabled!==!1);if(!e)return`prefix`;for(let t of n)if(t.id.toLowerCase()===e)return`exact`;for(let t of n)if(t.id.toLowerCase().startsWith(e))return`prefix`;return null}function Fn(e,t,n){let r=e.slice(0,t),i=Nn(r);if(i===-1)return{active:!1,query:``,start:-1};let a=r.slice(i+1);if(a.length>=200||!/^[\w.\-\\/\s]*$/.test(a))return{active:!1,query:``,start:-1};let o=(a.split(/[\s/\\]/)[0]??``).toLowerCase();return(n.length===0?`prefix`:Pn(o,n))===`prefix`?{active:!0,query:a,start:i}:{active:!1,query:``,start:-1}}function In(e,t){let n=t.trim().toLowerCase();if(!n)return 1;let r=e.id.toLowerCase(),i=(e.name||``).toLowerCase(),a=(e.description||``).toLowerCase(),o=(e.tags||[]).join(` `).toLowerCase();return r===n||i===n?100:r.startsWith(n)?90:i.startsWith(n)?80:r.includes(n)?60:i.includes(n)?55:o.includes(n)?40:a.includes(n)?30:0}function Ln(e,t){let n=t.replace(/^\$/,``).trim().split(/\s+/)[0]??``;return e.filter(e=>e.enabled!==!1).map(e=>({skill:e,score:In(e,n)})).filter(e=>e.score>0).sort((e,t)=>t.score-e.score||e.skill.id.localeCompare(t.skill.id)).map(e=>e.skill)}var Rn=class extends Error{code;constructor(e,t){super(t??e),this.code=e,this.name=`ScreenshotError`}};function zn(e){let t=document.createElement(`canvas`);t.width=e.videoWidth,t.height=e.videoHeight;let n=t.getContext(`2d`);if(!n)throw new Rn(`failed`,`Canvas 2D context unavailable`);return n.drawImage(e,0,0,t.width,t.height),new Promise((e,n)=>{t.toBlob(t=>t?e(t):n(new Rn(`failed`,`canvas.toBlob returned null`)),`image/png`)})}async function Bn(){if(!navigator.mediaDevices?.getDisplayMedia)throw new Rn(`unsupported`,`Screen capture is not supported in this browser`);let e=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1}).catch(e=>{let t=e instanceof DOMException?e.name:``;throw t===`NotAllowedError`||t===`AbortError`?new Rn(`cancelled`,`User dismissed the screen picker`):new Rn(`failed`,e instanceof Error?e.message:String(e))}),t=e.getTracks();try{let t=document.createElement(`video`);t.srcObject=e,t.muted=!0,t.playsInline=!0,await t.play().catch(()=>void 0),t.readyState<2&&await new Promise(e=>{let n=()=>e();t.addEventListener(`loadeddata`,n,{once:!0}),setTimeout(n,1e3)}),await new Promise(e=>requestAnimationFrame(()=>e()));let n=t.videoWidth,r=t.videoHeight;if(!n||!r)throw new Rn(`failed`,`Captured video frame has no pixels`);let i=await zn(t);t.srcObject=null;let a=new Date().toISOString().replace(/[:.]/g,`-`).slice(0,19);return new File([i],`screenshot-${a}.png`,{type:`image/png`})}finally{for(let e of t)e.stop()}}var Vn=16e3;function Hn(){let e=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`];if(typeof MediaRecorder>`u`)return``;for(let t of e)if(MediaRecorder.isTypeSupported(t))return t;return``}async function Un(e){if(e.sampleRate===Vn&&e.numberOfChannels===1)return e.getChannelData(0);let t=Math.max(1,Math.ceil(e.length*Vn/e.sampleRate)),n=new OfflineAudioContext(1,t,Vn),r=n.createBufferSource();return r.buffer=e,r.connect(n.destination),r.start(0),(await n.startRendering()).getChannelData(0)}function Wn(e,t){let n=new ArrayBuffer(44+e.length*2),r=new DataView(n),i=(e,t)=>{for(let n=0;n<t.length;n++)r.setUint8(e+n,t.charCodeAt(n))};i(0,`RIFF`),r.setUint32(4,36+e.length*2,!0),i(8,`WAVE`),i(12,`fmt `),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,t,!0),r.setUint32(28,t*2,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),i(36,`data`),r.setUint32(40,e.length*2,!0);let a=44;for(let t=0;t<e.length;t++){let n=Math.max(-1,Math.min(1,e[t]??0));r.setInt16(a,n<0?n*32768:n*32767,!0),a+=2}return n}function Gn(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let e=String(r.result||``),n=e.indexOf(`,`);t(n>=0?e.slice(n+1):e)},r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function Kn(e){let[t,n]=(0,J.useState)(`idle`),[r,i]=(0,J.useState)(0),a=(0,J.useRef)(null),o=(0,J.useRef)(null),s=(0,J.useRef)([]),c=(0,J.useRef)(null),l=(0,J.useRef)(0),u=(0,J.useCallback)(()=>{o.current?.getTracks().forEach(e=>e.stop()),o.current=null},[]),d=(0,J.useCallback)(()=>{c.current&&=(clearInterval(c.current),null)},[]);return(0,J.useEffect)(()=>()=>{d(),a.current&&a.current.state!==`inactive`&&a.current.stop(),u()},[d,u]),{state:t,elapsedMs:r,start:(0,J.useCallback)(async()=>{if(t!==`idle`)return;if(typeof MediaRecorder>`u`)throw Error(`当前浏览器不支持语音输入(需要 MediaRecorder)。请使用 Chrome/Edge/Firefox 或桌面版。`);let e;try{e=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}})}catch(e){throw e instanceof DOMException&&e.name===`NotAllowedError`?Error(`麦克风权限被拒绝。请在浏览器地址栏允许麦克风权限后重试。`):Error(`无法访问麦克风:`+(e instanceof Error?e.message:String(e)))}o.current=e,s.current=[];let r=new MediaRecorder(e,Hn()?{mimeType:Hn()}:void 0);r.ondataavailable=e=>{e.data&&e.data.size>0&&s.current.push(e.data)},a.current=r,r.start(),l.current=Date.now(),i(0),n(`recording`),c.current=setInterval(()=>i(Date.now()-l.current),100)},[t]),stop:(0,J.useCallback)(async()=>{let t=a.current;if(!t||t.state===`inactive`)throw Error(`当前没有进行中的录音。`);let r=new Promise(e=>{t.onstop=()=>e()});t.stop(),await r,d(),u(),a.current=null,n(`transcribing`);try{let t=new Blob(s.current,{type:Hn()||`audio/webm`});s.current=[];let r=await t.arrayBuffer(),i=new AudioContext,a;try{a=await i.decodeAudioData(r)}finally{i.close()}if(a.duration<.25)return n(`idle`),``;let o=Wn(await Un(a),Vn),c=await Gn(new Blob([o],{type:`audio/wav`})),l=await W.stt.transcribe(e,c,`wav`);if(!l.success)throw Error(l.error||`语音转写失败`);return l.data?.text??``}finally{n(`idle`)}},[e,d,u]),cancel:(0,J.useCallback)(()=>{let e=a.current;e&&e.state!==`inactive`&&e.stop(),a.current=null,s.current=[],d(),u(),n(`idle`)},[d,u])}}var qn=({isOpen:e,commands:t,selectedIndex:n,filter:r,onSelect:i,onHover:a,containerRef:o})=>{let{t:s}=F();return!e||t.length===0?null:(0,Y.jsxs)(`div`,{ref:o,className:`absolute bottom-full left-0 right-0 mb-2 bg-dark-overlay ui-surface-overlay border border-dark-border rounded-lg shadow-pop overflow-hidden z-50 max-h-72 overflow-y-auto custom-scrollbar`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 text-meta text-dark-muted border-b border-dark-border bg-dark-surface`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-dark-text`,children:r?`/${r}`:s(`slashCommands.quickCommands`)}),(0,Y.jsx)(`span`,{className:`opacity-70`,children:s(`slashCommands.help`)})]}),t.map((e,t)=>(0,Y.jsxs)(`button`,{"data-index":t,onClick:()=>i(e),onMouseEnter:()=>a(t),className:`w-full px-3 py-2 flex items-start gap-3 text-start transition-colors border-s-2 ${t===n?`bg-accent-blue/10 border-accent-blue`:`border-transparent hover:bg-dark-hover`}`,children:[(0,Y.jsx)(`span`,{className:`text-lg leading-none shrink-0`,"aria-hidden":`true`,children:e.icon}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`span`,{className:`text-sm font-medium text-dark-text`,children:[`/`,e.name]}),e.args&&(0,Y.jsx)(`span`,{className:`text-xs text-dark-muted`,children:e.args}),!e.local&&(0,Y.jsx)(`span`,{className:`text-badge px-1.5 py-0.5 rounded bg-accent-blue/20 text-accent-blue shrink-0`,children:s(`slashCommands.backend`)})]}),(0,Y.jsx)(`div`,{className:`text-xs text-dark-muted truncate`,children:e.description})]}),t===n&&(0,Y.jsx)(oe,{size:14,className:`text-dark-muted shrink-0 mt-0.5`,"aria-hidden":`true`})]},e.id))]})},Jn=`xlsx.xls.csv.docx.txt.md.mdx.rst.adoc.ts.tsx.js.jsx.mjs.cjs.mts.cts.json.jsonc.yaml.yml.toml.xml.html.css.scss.less.py.rb.go.rs.java.kt.swift.c.h.cpp.hpp.cc.cs.sh.bash.zsh.ps1.bat.cmd.sql.graphql.proto.vue.svelte.astro.env.gitignore.gitattributes.editorconfig`.split(`.`),Yn=RegExp(`(?:\\.(${Jn.join(`|`)})|dockerfile|makefile)$`,`i`),Xn=[`png`,`jpg`,`jpeg`,`webp`,`gif`,`bmp`,`svg`],Zn=Object.freeze([]),Qn=RegExp(`\\.(${Xn.join(`|`)})$`,`i`),$n=10485760,er=Jn.map(e=>`.${e}`).join(`,`)+`,.Dockerfile,.Makefile,`+Xn.map(e=>`.${e}`).join(`,`),tr=`.agent/attachments`,nr=52428800,rr=10,ir=`chat-col`,ar=72,or=.7,sr=`deepseekcode.composerPref`,cr=550;function lr(){try{let e=window.localStorage.getItem(sr);return e===`collapsed`||e===`expanded`?e:`auto`}catch{return`auto`}}function ur(){return typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(hover: hover) and (pointer: fine)`).matches}var dr=/["<>]/g;function fr(e){return`<image name="${(e||`image`).replace(dr,``)}" />`}var pr=e=>/\.xlsx?$/i.test(e)?d:/\.(csv|docx|txt|md|mdx|rst|adoc|json|jsonc|yaml|yml|toml|xml|html|css|scss|less|env|gitignore|gitattributes|editorconfig)$/i.test(e)?u:/\.(ts|tsx|js|jsx|mjs|cjs|mts|cts|py|rb|go|rs|java|kt|swift|c|h|cpp|hpp|cc|cs|sh|bash|zsh|ps1|bat|cmd|sql|graphql|proto|vue|svelte|astro|dockerfile|makefile)$/i.test(e)?n:A,mr=50,hr=5e3,gr={enqueue:`chat.mentionDeliveryEnqueue`,summarize:`chat.mentionDeliverySummarize`,"next-step":`chat.mentionDeliveryNextStep`,direct:`chat.mentionDeliveryDirect`},_r={enqueue:`text-dark-muted hover:bg-dark-hover hover:text-dark-text`,summarize:`text-dark-muted hover:bg-dark-hover hover:text-dark-text`,"next-step":`bg-accent-blue/10 text-accent-blue`,direct:`bg-accent-blue/10 text-accent-blue`};function vr(e,t){let n=e.slice(0,t),r=n.lastIndexOf(`@`);if(r===-1)return{active:!1,query:``,start:-1};let i=n.slice(r+1);return/^[\p{L}\p{N}_\-./]*$/u.test(i)?{active:!0,query:i,start:r}:{active:!1,query:``,start:-1}}function yr(e,t){let n=e.lastIndexOf(`
7
+ `,t-1)+1,r=e.slice(n,t);return!r.startsWith(`/`)||/\s/.test(r)?{active:!1,query:``}:{active:!0,query:r.slice(1)}}var br=(0,J.memo)(function({sessionId:e,onSend:n,onRunShell:i,onStop:o,onPause:s,onResume:u,slashOptions:d,workspaceDir:m,onWorkspaceSelect:g,onNewSessionInDir:_,focusRequest:v,inputDisabled:y,inputDisabledHint:b}){let{t:S}=F(),w=R(t=>t.sessionInputs?.[e]??``),T=R(e=>e.setSessionInput),E=R(t=>t.generatingSessions?.includes(e)??!1),D=R(t=>t.pausedSessions?.includes(e)??!1),k=R(t=>t.sessionSuggestions?.[e]),A=R(t=>t.sessionTurns?.[e]??``),M=R(e=>e.clearSessionSuggestion),ie=!w&&!E&&!y&&k&&(k.turnId??``)===A?k.text:``,oe=R(t=>t.pendingBySession?.[e])??Zn,se=oe.length,ce=R(t=>t.draftRestores?.[e]),P=(0,J.useRef)(null),[ue,I]=(0,J.useState)(null),fe=(0,J.useRef)(null),[me,he]=(0,J.useState)(!1),V=(0,J.useRef)(null),ge=(0,J.useRef)(!1),_e=(0,J.useRef)(0),H=et(t=>t.attachmentsBySession[e])??Ke,ve=(0,J.useRef)(e);ve.current=e;let U=(0,J.useCallback)(e=>et.getState().setSessionAttachments(ve.current,e),[]),[ye,be]=(0,J.useState)(!1),[xe,Se]=(0,J.useState)(!1),[Oe,Ae]=(0,J.useState)(!1),[G,je]=(0,J.useState)(!1),[Me,Le]=(0,J.useState)(``),[Re,Ve]=(0,J.useState)(0),[He,Ue]=(0,J.useState)([]),[We,Ge]=(0,J.useState)(!1),qe=(0,J.useRef)(-1),K=(0,J.useRef)([]);K.current=He;let Je=(0,J.useRef)(null),Ye=(0,J.useCallback)(()=>{let t=R.getState().clearPending(e);t>0&&z.info(S(`toast.queueRevoked`,{count:t}))},[e,S]),Xe=(0,J.useCallback)(t=>{let n=R.getState();n.promotePending(e,t),!n.isGenerating(e)&&!n.isPaused(e)?L(e):z.info(S(`toast.queuePromoted`))},[e,S]),Qe=(0,J.useCallback)(t=>{let n=R.getState(),r=n.removePending(e,t);r&&(pe(e,r)?z.info(S(`toast.queueSteered`)):n.enqueuePending(e,r.content,r.files,r.images,r.display,r.skipAddUserMessage,r.requeuedFromMessageId))},[e,S]),nt=(0,J.useCallback)(t=>{R.getState().removePending(e,t)&&z.info(S(`toast.queueRemoved`))},[e,S]),q=(0,J.useCallback)(t=>{T(e,t)},[e,T]),it=(0,J.useCallback)(()=>{let e=k?.text??``;e&&(q(e),requestAnimationFrame(()=>{let t=P.current;t&&(t.focus(),t.selectionStart=t.selectionEnd=e.length)}))},[q,k]),at=(0,J.useCallback)(t=>{let n=[],r=[],i=(t.display?.content??t.content).replace(/<attachment path="([^"]*)"\s*\/>/g,(e,t)=>(n.push(t),``)).replace(/<image name="([^"]*)"\s*\/>/g,(e,t)=>(r.push(t),``)).trim();if(t.display)for(let e of t.display.pastes){let t=st(e.content),n=dt(e.content),r=n>0?`[Pasted text #${t} +${n} lines]`:`[Pasted text #${t}]`;i=i.replace(RegExp(`\\[Pasted text #${e.id}(?:\\s*\\+\\d+ lines?)?\\]`,`g`),r)}for(let e of t.files??[])vn.current.add(e);let a=n.map((e,t)=>({id:`restored-att-${Date.now()}-${t}`,name:e.split(`/`).pop()||e,size:0,uploading:!1,path:e}));(t.images??[]).forEach((e,t)=>{a.push({id:`restored-img-${Date.now()}-${t}`,name:r[t]||`image-${t+1}.png`,size:Math.max(1,Math.round((e.length-e.indexOf(`,`)-1)*3/4)),uploading:!1,imageDataUri:e})}),a.length>0&&U(e=>[...e,...a].slice(-10));let o=R.getState().getSessionInput(e);q(o.trim()?`${o.trimEnd()}\n\n${i}`:i),requestAnimationFrame(()=>P.current?.focus())},[e,q]),ot=(0,J.useCallback)(t=>{let n=R.getState().removePending(e,t);n&&at({content:n.content,...n.display?{display:n.display}:{},...n.images?.length?{images:n.images}:{},...n.files?.length?{files:n.files}:{}})},[e,at]);(0,J.useEffect)(()=>{if(!ce)return;let t=R.getState().takeDraftRestore(e);t&&at(t)},[e,ce,at]);let lt=(0,J.useCallback)(e=>e.replace(/<attachment path="[^"]*"\s*\/>/g,``).replace(/<image name="[^"]*"\s*\/>/g,``).trim(),[]),[yt,bt]=(0,J.useState)(we),[xt,St]=(0,J.useState)(!1),Ct=(0,J.useRef)(null),wt=(0,J.useCallback)(e=>{bt(e),De(e),St(!1)},[]);(0,J.useEffect)(()=>{if(!xt)return;let e=e=>{Ct.current&&!Ct.current.contains(e.target)&&St(!1)},t=e=>{e.key===`Escape`&&St(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[xt]);let X=Kn(yt),Tt=(0,J.useRef)(null),Et=(0,J.useCallback)(async()=>{try{if(!Tt.current){let e=await W.stt.status();e.success&&e.data&&(Tt.current=e.data)}let e=Tt.current;if(!e)return!0;if(e.service!==`ok`&&e.service!==`stopped`)return z.warning(S(`stt.backendMissing`)),window.dispatchEvent(new CustomEvent(`switch-tab`,{detail:{tab:`settings`,section:`stt`}})),!1;let t=e.backends?.[yt];return t&&!t.installed?(z.warning(S(`stt.backendMissing`)),window.dispatchEvent(new CustomEvent(`switch-tab`,{detail:{tab:`settings`,section:`stt`}})),!1):!0}catch{return!0}},[S,yt]);(0,J.useEffect)(()=>{let e=()=>{Tt.current=null};return window.addEventListener(`stt-backends-changed`,e),()=>window.removeEventListener(`stt-backends-changed`,e)},[]),(0,J.useEffect)(()=>{let e=e=>{let t=Te(e.detail?.lang);bt(t)};return window.addEventListener(`stt-lang-changed`,e),()=>window.removeEventListener(`stt-lang-changed`,e)},[]);let Dt=(0,J.useCallback)(e=>{let t=P.current,n=t?.selectionStart??w.length,r=w.slice(0,n)+e+w.slice(n);q(r),requestAnimationFrame(()=>{t?.focus();let r=n+e.length;t&&(t.selectionStart=t.selectionEnd=r)})},[w,q]);(0,J.useEffect)(()=>{if(!v)return;let e=P.current;if(!e)return;e.focus();let t=e.value.length;e.selectionStart=t,e.selectionEnd=t},[v]);let Ot=(0,J.useCallback)(async()=>{if(E)z.info(S(`stt.generatingTitle`));else if(X.state===`recording`)try{let e=await X.stop();e?Dt(e):z.info(S(`stt.noSpeech`))}catch(e){z.error(e instanceof Error?e.message:String(e))}else if(X.state===`idle`&&await Et())try{await X.start()}catch(e){z.error(e instanceof Error?e.message:String(e))}},[X,Dt,Et,S,E]),{isOpen:kt,filter:At,filteredCommands:jt,selectedIndex:Mt,setSelectedIndex:Nt,selectNext:Pt,selectPrev:Ft,executeCommand:It,openMenu:Lt,closeMenu:Z,setFilter:Rt,allCommands:zt,containerRef:Bt}=tt(d),[Q,Ut]=(0,J.useState)(!1),[Wt,Kt]=(0,J.useState)(``),[qt,Jt]=(0,J.useState)([]),[Yt,Xt]=(0,J.useState)(0),[Zt,Qt]=(0,J.useState)(!1),[$t,en]=(0,J.useState)(0),tn=(0,J.useRef)(-1),[rn,an]=(0,J.useState)(`active`),on=(0,J.useRef)(`active`),[sn,ln]=(0,J.useState)(`summarize`),un=(0,J.useRef)(`summarize`);un.current=sn;let[dn,mn]=(0,J.useState)([]),gn=(0,J.useCallback)(()=>{mn(Array.from(xn.current.values()))},[]);on.current=rn;let vn=(0,J.useRef)(new Set),xn=(0,J.useRef)(new Map),Sn=(0,J.useRef)([]),Cn=(0,J.useRef)(0),Tn=(0,J.useRef)(!1);(0,J.useEffect)(()=>{let t=t=>{let n=R.getState().getSessionInput(e),r=`@${t} `,i=n.trim()?`${n.trimEnd()} ${r}`:r;vn.current.add(t),T(e,i),en(vn.current.size+xn.current.size),requestAnimationFrame(()=>P.current?.focus())};return Fe(t),()=>Ne(t)},[e,T]),(0,J.useEffect)(()=>{let t=t=>{let n=R.getState().getSessionInput(e),r=n.trim()?`${n.trimEnd()}\n\n${t}`:t;T(e,r),requestAnimationFrame(()=>P.current?.focus())};return Ie(t),()=>Pe(t)},[e,T]);let En=(0,J.useCallback)(t=>{let n=R.getState().getSessionInput(e),r=n.trim()?`${n.trimEnd()}\n\n${t}`:t;T(e,r),requestAnimationFrame(()=>P.current?.focus())},[e,T]),Dn=(0,J.useRef)([]),[On,kn]=(0,J.useState)(pn),Nn=(0,J.useRef)([]),Pn=(0,J.useRef)([]),In=(0,J.useRef)(0),zn=(0,J.useRef)(``);zn.current=Wt;let Vn=(0,J.useCallback)((e,t)=>{let n=e.map(e=>({kind:`file`,key:e.path,label:e.name,detail:e.path,isDir:e.type===`directory`})),r=Nn.current,i=t.toLowerCase(),a=(i?r.filter(e=>e.label.toLowerCase().includes(i)||e.key.toLowerCase().includes(i)):r).slice(0,mr);return[...n,...a]},[]),Hn=(0,J.useCallback)(async()=>{let e=Date.now();if(Pn.current.length>0&&e-In.current<hr)return Pn.current;try{let e=await W.sessions.list(),t=e.success&&e.data?e.data:[];(t.length>0||Pn.current.length===0)&&(Pn.current=t),In.current=Date.now()}catch{}return Pn.current},[]),Un=(0,J.useCallback)(async()=>{let t=await Hn();return Nn.current=wn(t,e,on.current),Nn.current},[Hn,e]),Wn=(0,J.useCallback)(e=>{Dn.current=e,Jt(e)},[]),Gn=(0,J.useCallback)((e,t)=>{Wn(Vn(e.slice(0,mr),t))},[Wn,Vn]),Jn=(0,J.useCallback)(()=>{let t=on.current===`active`?`all`:`active`;on.current=t,an(t),(async()=>{let n=await Hn();Nn.current=wn(n,e,t),Gn(Sn.current,zn.current.toLowerCase())})()},[Hn,e,Gn]),Xn=(0,J.useCallback)(()=>{let e=hn(un.current);(e===`direct`||e===`summarize`)&&vn.current.size>0&&(e=`enqueue`),un.current=e,ln(e)},[]),dr=(0,J.useMemo)(()=>_n({files:S(`chat.mentionTabFiles`),sessions:S(`chat.mentionTabSessions`)}),[S]),br=dr.some(e=>e.key===On)?On:pn,xr=(0,J.useMemo)(()=>yn(qt,br),[qt,br]);(0,J.useEffect)(()=>{vn.current=new Set,xn.current=new Map,gn(),Tn.current=!1,kn(pn),Nn.current=[],Pn.current=[],In.current=0,Cn.current++,Ut(!1),Kt(``),Jt([]),Dn.current=[],en(0),Z()},[e,Z,gn]);let Sr=(0,J.useDeferredValue)(w),Cr=de(e=>e.estimateTokens),wr=(0,J.useMemo)(()=>Cr(Sr),[Sr,Cr]),Tr=(0,J.useCallback)(()=>{let e=P.current;e&&(ue==null?(e.style.maxHeight=``,e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`):(e.style.maxHeight=`${ue}px`,e.style.height=`${ue}px`))},[ue]);(0,J.useEffect)(()=>{Tr()},[w,H.length,Tr]),(0,J.useEffect)(()=>()=>{document.body.style.userSelect=``},[]);let Er=(0,J.useCallback)(e=>{let t=P.current;t&&e.button===0&&(e.preventDefault(),fe.current={startY:e.clientY,startHeight:t.getBoundingClientRect().height,current:0},e.currentTarget.setPointerCapture(e.pointerId),document.body.style.userSelect=`none`,he(!0))},[]),Dr=(0,J.useCallback)(e=>{let t=fe.current,n=P.current;if(!t||!n)return;t.movedY=e.clientY-t.startY;let r=Math.max(ar,Math.min(Math.round(window.innerHeight*or),t.startHeight-(e.clientY-t.startY)));t.current=r,n.style.maxHeight=`${r}px`,n.style.height=`${r}px`},[]),Or=(0,J.useCallback)(e=>{let t=fe.current;if(fe.current=null,document.body.style.userSelect=``,he(!1),t){try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}t.current>0&&Math.abs(t.movedY??0)>3&&I(t.current)}},[]),kr=(0,J.useCallback)(()=>I(null),[]),Ar=(0,J.useCallback)(e=>{let t=P.current;if(!t)return;let n=ue??t.getBoundingClientRect().height,r=Math.max(ar,Math.min(Math.round(window.innerHeight*or),n+e));I(r)},[ue]),jr=(0,J.useCallback)(async e=>{let t=++Cn.current;Qt(!0);try{let n=await W.files.search(e);if(t!==Cn.current)return null;let r=(n.success&&n.data?n.data.files:[]).map(e=>({id:e,name:e.slice(e.lastIndexOf(`/`)+1),path:e,type:`file`}));return Sn.current=r,r}catch{return null}finally{t===Cn.current&&Qt(!1)}},[]),Mr=(0,J.useCallback)(async(e,t)=>{if(Tn.current){let n=tn.current;if(n<0||t<n){Tn.current=!1,Ut(!1);return}let r=e.slice(n,t);if(/\s/.test(r)){Tn.current=!1,Ut(!1);return}tn.current=n,Kt(r),Ut(!0),Xt(0);let i=r.toLowerCase(),[a]=await Promise.all([jr(i),Un()]);if(!a)return;Gn(a,i);return}let n=vr(e,t);if(!n.active){Q&&Ut(!1);return}tn.current=n.start,Kt(n.query),Ut(!0),Xt(0);let r=n.query.toLowerCase(),[i]=await Promise.all([jr(r),Un()]);i&&Gn(i,r)},[Q,jr,Un,Gn]),Nr=(0,J.useCallback)(async()=>{if(K.current.length>0)return K.current;if(Je.current)return Je.current;Ge(!0);let e=W.skills.list().then(e=>{let t=Array.isArray(e.data)?e.data:[];return Ue(t),t}).catch(()=>[]).finally(()=>{Je.current=null,Ge(!1)});return Je.current=e,e},[]),Pr=(0,J.useMemo)(()=>Ln(He,Me),[He,Me]),Fr=(0,J.useCallback)((e,t)=>{let n=Fn(e,t,K.current);n.active?(qe.current=n.start,Le(n.query),Ve(0),je(!0),K.current.length===0&&Nr()):G&&(je(!1),Le(``))},[G,Nr]);(0,J.useEffect)(()=>{if(!G||He.length===0)return;let e=P.current;if(!e)return;let t=Fn(e.value,e.selectionStart??e.value.length,He);t.active?(qe.current=t.start,Le(t.query)):(je(!1),Le(``))},[He,G]);let Ir=(0,J.useCallback)(e=>{let t=e.target.value,n=e.target.selectionStart??t.length;q(t),Mr(t,n),Fr(t,n);let r=yr(t,n);r.active?(kt||Lt(),Rt(r.query),Nt(0)):kt&&Z()},[q,Mr,Fr,kt,Lt,Rt,Nt,Z]),Lr=(0,J.useCallback)(e=>{let t=P.current,n=w,r=tn.current>=0?tn.current:t?.selectionStart??n.length,i=Math.min(n.length,r+1+Wt.length),a,o;if(e.kind===`session`){let t=e.label||e.key;a=/\s/.test(t)?e.key:t,xn.current.set(e.key,t),gn(),o=`@${a} `}else a=e.key,vn.current.add(a),o=`@${a} `;let s=n.slice(0,r)+o+n.slice(i);q(s),Ut(!0),Kt(``),(async()=>{let e=await jr(``);e&&Gn(e,``)})(),Xt(0),en(vn.current.size+xn.current.size),tn.current=r+o.length,Tn.current=!0,requestAnimationFrame(()=>{t?.focus(),t&&(t.selectionStart=t.selectionEnd=r+o.length)})},[w,Wt,q,jr,Gn]),Rr=(0,J.useCallback)(()=>{Tn.current=!1,Ut(!1),Kt(``),en(0),kn(pn)},[]),zr=(0,J.useCallback)(e=>{let t=P.current;if(!e.args){let n=It(e,``);if(n?.message&&(n.success?z.success(n.message):z.error(n.message)),n?.draft){q(n.draft),I(null),requestAnimationFrame(()=>{t?.focus(),t&&(t.selectionStart=t.selectionEnd=n.draft.length)});return}q(``),I(null);return}let n=t?.selectionStart??w.length,r=w.lastIndexOf(`
8
+ `,n-1)+1,i=w.slice(0,r)+`/${e.name} `+w.slice(n);q(i),Z(),requestAnimationFrame(()=>{t?.focus();let n=r+e.name.length+2;t&&(t.selectionStart=t.selectionEnd=n)})},[w,q,It,Z]),Br=(0,J.useCallback)(e=>{let t=P.current,n=qe.current>=0?qe.current:t?.selectionStart??w.length,r=Math.min(w.length,n+1+Me.length),i=`$${e.id} `,a=w.slice(0,n)+i+w.slice(r);q(a),je(!1),Le(``),qe.current=-1,requestAnimationFrame(()=>{t?.focus();let e=n+i.length;t&&(t.selectionStart=t.selectionEnd=e)})},[w,Me,q]),Vr=(0,J.useCallback)(()=>{je(!1),Le(``),qe.current=-1},[]),Hr=(0,J.useCallback)(e=>{let t=P.current,n=t?.selectionStart??w.length,r=`$${e.id} `,i=w.slice(0,n)+r+w.slice(n);q(i),Ae(!1),Tn.current=!1,Ut(!1),Kt(``),je(!1),Le(``),requestAnimationFrame(()=>{t?.focus();let e=n+r.length;t&&(t.selectionStart=t.selectionEnd=e)})},[w,q]),Ur=2048,Wr=(0,J.useCallback)(e=>new Promise((t,n)=>{let r=()=>{let r=new FileReader;r.onload=()=>t(String(r.result??``)),r.onerror=()=>n(Error(`Failed to read image`)),r.readAsDataURL(e)};(async()=>{let n=null;try{n=await createImageBitmap(e)}catch{r();return}try{let i=Math.max(n.width,n.height);if(i<=Ur){n.close(),r();return}let a=Ur/i,o=document.createElement(`canvas`);o.width=Math.max(1,Math.round(n.width*a)),o.height=Math.max(1,Math.round(n.height*a));let s=o.getContext(`2d`);if(!s){n.close(),r();return}s.drawImage(n,0,0,o.width,o.height),n.close();let c=e.type===`image/jpeg`?`image/jpeg`:`image/png`;t(o.toDataURL(c,c===`image/jpeg`?.9:void 0))}catch{n?.close(),r()}})()}),[]),Gr=(0,J.useCallback)(e=>{let t=Array.from(e);U(e=>{let n=rr-e.length,r=e.slice();for(let e of t.slice(0,n)){let t=Qn.test(e.name);if(!t&&!Yn.test(e.name)){z.warning(S(`fileJob.unsupportedType`,{name:e.name}));continue}if(e.size>(t?$n:nr)){z.error(S(`fileJob.fileTooLarge`,{name:e.name}));continue}if(r.some(t=>t.name===e.name&&t.size===e.size)){z.warning(S(`fileJob.duplicateFile`,{name:e.name}));continue}let n={id:`att-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,file:e,name:e.name,size:e.size,uploading:!1};t&&Wr(e).then(e=>{U(t=>t.map(t=>t.id===n.id?{...t,imageDataUri:e}:t))}).catch(()=>{U(e=>e.filter(e=>e.id!==n.id)),z.error(`${e.name}: ${S(`fileJob.uploadFailed`)}`)}),r.push(n)}return r.length>=rr&&z.warning(S(`fileJob.maxAttachments`,{n:rr})),r})},[S,Wr]),Kr=(0,J.useCallback)(e=>{e.target.files&&e.target.files.length>0&&(Gr(e.target.files),e.target.value=``)},[Gr]),qr=(0,J.useCallback)(()=>{V.current?.click()},[]),Jr=(0,J.useCallback)(async()=>{if(!(xe||E)){Se(!0);try{let e=await Bn();Gr([e])}catch(e){e instanceof Rn&&e.code===`cancelled`||z.error(S(`fileJob.screenshotFailed`))}finally{Se(!1)}}},[Gr,S,xe,E]),Yr=(0,J.useRef)(Jr);(0,J.useEffect)(()=>{Yr.current=Jr},[Jr]),(0,J.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.shiftKey&&(e.key===`s`||e.key===`S`)&&(e.preventDefault(),Yr.current())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let Xr=(0,J.useCallback)(e=>{U(t=>t.filter(t=>t.id!==e))},[]),Zr=(0,J.useCallback)(e=>{e.preventDefault(),be(!0)},[]),Qr=(0,J.useCallback)(e=>{e.preventDefault(),be(!1)},[]),$r=(0,J.useCallback)(e=>{e.preventDefault(),be(!1),e.dataTransfer.files&&e.dataTransfer.files.length>0&&Gr(e.dataTransfer.files)},[Gr]),ei=(0,J.useCallback)(async()=>{if(H.length===0)return``;let e=[];for(let t of H){if(t.imageDataUri)continue;if(t.path){e.push(`<attachment path="${t.path}" />`);continue}if(!t.file)continue;U(e=>e.map(e=>e.id===t.id?{...e,uploading:!0,error:void 0}:e));let n=`${tr}/${t.name}`,r=await W.files.upload(t.file,n);if(r.success&&r.data?.path){let n=r.data.path.replace(/\\/g,`/`);U(e=>e.map(e=>e.id===t.id?{...e,uploading:!1,path:n}:e)),e.push(`<attachment path="${n}" />`)}else U(e=>e.map(e=>e.id===t.id?{...e,uploading:!1,error:r.error||S(`fileJob.uploadFailed`)}:e)),z.error(`${t.name}: ${r.error||S(`fileJob.uploadFailed`)}`)}return e.length>0?`${e.join(`
9
+ `)}\n\n`:``},[H,S]),ti=(0,J.useCallback)(e=>{if(!e)return;let t=ut(e)?ft(e).label:e,n=P.current;if(!n)return;let r=n.selectionStart??n.value.length,i=n.selectionEnd??r;q(n.value.slice(0,r)+t+n.value.slice(i)),requestAnimationFrame(()=>{n.selectionStart=n.selectionEnd=r+t.length})},[q]),ni=(0,J.useCallback)(e=>{let t=e.clipboardData.getData(`text/plain`),n=$e(e.clipboardData.getData(`text/html`)),r=e.clipboardData.files?Array.from(e.clipboardData.files):[],i=n.length>0?n:r.filter(e=>e.type.startsWith(`image/`)),a=r.filter(e=>!e.type.startsWith(`image/`));i.length>0||a.length>0?(e.preventDefault(),Gr([...i,...a]),ti(t)):t&&ut(t)&&(e.preventDefault(),ti(t))},[Gr,ti]),ri=(0,J.useCallback)(async()=>{let t=w.trim()?w:ie,r=mt(t),a=r.map(e=>({id:e,content:ct(e)??``})).filter(e=>e.content!==``),o=pt(t);ht(r),Tn.current=!1,Ut(!1),Z();let s=o.trim(),c=H.length>0;if(!s&&!c)return;let l=o.trim();if(l.startsWith(`/`)&&!c){let e=rt(l);if(e){let t=zt.find(t=>t.name===e.command);if(t){let n=It(t,e.args);if(n?.message&&(n.success?z.success(n.message):z.error(n.message)),n?.draft){q(n.draft),I(null),requestAnimationFrame(()=>{let e=P.current;e&&(e.focus(),e.setSelectionRange(n.draft.length,n.draft.length))});return}q(``),I(null),U([]),vn.current=new Set,xn.current=new Map,gn(),en(0);return}z.error(S(`slashCommands.unknownCommand`,{cmd:`/${e.command}`}));return}}if(l.startsWith(`!`)&&!c){let t=l.slice(1).trim();if(!t)return;if(i){i(t),q(``),I(null),U([]),vn.current=new Set,xn.current=new Map,en(0),M(e);return}}let u=Array.from(vn.current).filter(e=>o.includes(`@${e}`)),d=Array.from(xn.current.entries()).map(([e,t])=>({id:e,title:t})).filter(e=>o.includes(`@${e.title}`)||o.includes(`@${e.id}`)),f=``;if(c){if(H.some(e=>e.uploading)){z.warning(S(`fileJob.stillUploading`));return}f=await ei()}let p=H.filter(e=>e.imageDataUri),m=p.map(e=>e.imageDataUri);if(p.length>0){let e=p.map(e=>fr(e.name)).join(`
10
+ `);f=f?`${f}${e}\n\n`:`${e}\n\n`}let h=(f+o).trim();if(!h&&!c)return;let g=a.length>0?{content:`${f}${w}`,pastes:a}:void 0;n(h||f.trim(),u.length>0?u:void 0,m.length>0?m:void 0,d.length>0?d:void 0,d.length>0?un.current:void 0,g),q(``),M(e),I(null),U([]),vn.current=new Set,xn.current=new Map,en(0),je(!1),Le(``)},[w,ie,H,n,i,q,M,e,ei,S,Z,zt,It]),ii=(0,J.useCallback)(e=>{if(!e.nativeEvent.isComposing){if((e.key===`Backspace`||e.key===`Delete`)&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&!e.shiftKey){let t=P.current;if(t&&t.selectionStart===t.selectionEnd){let n=t.selectionStart,r=t.value;if(e.key===`Backspace`&&n>0){let i=gt(r.slice(0,n));if(i){e.preventDefault(),q(r.slice(0,n-i.length)+r.slice(n)),vt(i),requestAnimationFrame(()=>{t.focus();let e=n-i.length;t.selectionStart=t.selectionEnd=e});return}}else if(e.key===`Delete`&&n<r.length){let i=_t(r.slice(n));if(i){e.preventDefault(),q(r.slice(0,n)+r.slice(n+i.length)),vt(i),requestAnimationFrame(()=>{t.focus(),t.selectionStart=t.selectionEnd=n});return}}}}if(e.key===`Backspace`&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&!e.shiftKey&&H.length>0){let t=P.current;if(t&&t.selectionStart===0&&t.selectionEnd===0){let t=H[H.length-1];if(t){e.preventDefault(),Xr(t.id);return}}}if(Q&&dr.length>1&&e.key===`Tab`){e.preventDefault();let t=dr.map(e=>e.key);kn(n=>bn(t,n,!e.shiftKey)),Xt(0)}else if(Q&&dr.length>1&&e.key===`S`&&!e.ctrlKey&&!e.metaKey&&!e.altKey)e.preventDefault(),Jn();else if(Q&&dr.length>1&&e.key===`M`&&!e.ctrlKey&&!e.metaKey&&!e.altKey)e.preventDefault(),Xn();else{if(Q&&xr.length>0){if(e.key===`ArrowDown`){e.preventDefault(),Xt(e=>(e+1)%xr.length);return}if(e.key===`ArrowUp`){e.preventDefault(),Xt(e=>(e-1+xr.length)%xr.length);return}if(e.key===`Enter`&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey){let t=xr[Yt];t&&(e.preventDefault(),Lr(t));return}if(e.key===`Escape`){e.preventDefault(),Rr();return}}else if(Q&&e.key===`Escape`){e.preventDefault(),Rr();return}if(G&&Pr.length>0){if(e.key===`ArrowDown`){e.preventDefault(),Ve(e=>(e+1)%Pr.length);return}if(e.key===`ArrowUp`){e.preventDefault(),Ve(e=>(e-1+Pr.length)%Pr.length);return}if(e.key===`Enter`&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey){let t=Pr[Re];t&&(e.preventDefault(),Br(t));return}if(e.key===`Escape`){e.preventDefault(),Vr();return}}else if(G&&e.key===`Escape`){e.preventDefault(),Vr();return}if(kt&&jt.length>0){if(e.key===`ArrowDown`){e.preventDefault(),Pt();return}if(e.key===`ArrowUp`){e.preventDefault(),Ft();return}if(e.key===`Enter`&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey){let t=jt[Mt];t&&(e.preventDefault(),zr(t));return}if(e.key===`Escape`){e.preventDefault(),Z();return}}else if(kt&&e.key===`Escape`){e.preventDefault(),Z();return}if(e.key===`Tab`&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&ie)e.preventDefault(),it();else if(e.key===`Escape`&&E){e.preventDefault();let t=Date.now(),n=Be(se,D,_e.current,t);_e.current=t,n===`revokeQueue`?(Ye(),_e.current=0):n===`stop`?o():s()}else(e.key===`Enter`&&(e.ctrlKey||e.metaKey)||e.key===`Enter`&&!e.shiftKey)&&(e.preventDefault(),ri())}}},[E,D,se,Ye,ri,s,u,o,Q,qt,Yt,Lr,Rr,dr,Jn,Xn,G,Pr,Re,Br,Vr,kt,jt,Mt,Pt,Ft,zr,Z,q,H,Xr,ie,it]),ai=(0,J.useCallback)(()=>{ge.current=!0},[]),oi=(0,J.useCallback)(()=>{ge.current=!1},[]),[si,ci]=(0,J.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: 767px)`).matches);(0,J.useEffect)(()=>{if(typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(max-width: 767px)`),t=()=>{ci(e.matches),e.matches||mi(!1)};return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let[li,ui]=(0,J.useState)(()=>lr()),[di,fi]=(0,J.useState)(()=>lr()===`collapsed`),[pi,mi]=(0,J.useState)(!1),[hi,gi]=(0,J.useState)(!1),_i=li===`expanded`,vi=(0,J.useCallback)(e=>{ui(e);try{e===`auto`?window.localStorage.removeItem(sr):window.localStorage.setItem(sr,e)}catch{}},[]),yi=(0,J.useRef)(null),$=(0,J.useCallback)(()=>{yi.current!==null&&(clearTimeout(yi.current),yi.current=null)},[]);(0,J.useEffect)(()=>$,[$]),(0,J.useEffect)(()=>{si&&E&&!_i&&mi(!0)},[si,E,_i]);let[bi,xi]=(0,J.useState)(()=>ur());(0,J.useEffect)(()=>{if(typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(hover: hover) and (pointer: fine)`),t=()=>xi(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let Si=ge.current||w.trim().length>0||H.length>0||se>0||y||ye||Q||kt||G,Ci=bi&&li===`auto`&&!di,wi=(0,J.useRef)(Si);wi.current=Si;let Ti=di||si&&pi||hi,Ei=hi&&!di&&!(si&&pi),Di=(0,J.useCallback)(()=>{$(),gi(!1),fi(!0),vi(`collapsed`)},[$,vi]),Oi=(0,J.useCallback)(()=>{$(),mi(!1),gi(!1),li===`collapsed`&&(fi(!1),vi(`auto`))},[$,li,vi]),ki=(0,J.useCallback)(()=>{$(),_i?vi(`auto`):(gi(!1),mi(!1),fi(!1),vi(`expanded`))},[$,_i,vi]),Ai=(0,J.useCallback)(()=>{$(),gi(!1)},[$]),ji=(0,J.useCallback)(()=>{Ci&&($(),yi.current=setTimeout(()=>{yi.current=null,!wi.current&&gi(!0)},cr))},[$,Ci]),Mi=(0,J.useCallback)(()=>{$(),gi(!1)},[$]),Ni=wr>8e3,Pi=!y&&(w.trim().length>0||H.length>0),Fi=E?S(`stt.generatingTitle`):X.state===`recording`?S(`stt.stopTitle`):S(`stt.title`),Ii=X.state===`transcribing`||E,Li=/mac/i.test(navigator.platform||``)?`⌘`:`Ctrl`;return(0,Y.jsxs)(`div`,{className:`chat-composer-shell shrink-0 pb-3 pt-2 max-md:order-4 max-md:mt-auto max-md:pb-5`,onMouseEnter:Ai,onMouseLeave:ji,onDragOver:Zr,onDragLeave:Qr,onDrop:$r,children:[oe.length>0&&(0,Y.jsxs)(`div`,{className:`${ir} mb-2 rounded-lg border border-dark-border bg-dark-surface px-2.5 py-1.5 text-xs text-dark-muted`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{"aria-hidden":`true`,children:`⏳`}),(0,Y.jsx)(`span`,{className:`font-medium text-dark-text`,children:S(`chat.queuedCount`,{count:oe.length})}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1`}),(0,Y.jsx)(`span`,{className:`shrink-0 text-badge text-dark-muted/60`,children:S(`chat.queuedEscHint`)}),(0,Y.jsx)(`button`,{onClick:Ye,className:`flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-red`,title:S(`chat.queuedRevoke`),"aria-label":S(`chat.queuedRevoke`),children:(0,Y.jsx)(te,{size:12,"aria-hidden":`true`})})]}),(0,Y.jsx)(`ul`,{className:`mt-1 max-h-40 space-y-0.5 overflow-y-auto`,children:oe.map((e,t)=>(0,Y.jsxs)(`li`,{className:`group flex items-center gap-2 rounded px-1 py-0.5 transition-colors hover:bg-dark-hover/60`,children:[(0,Y.jsx)(`span`,{className:`w-4 shrink-0 text-center text-badge tabular-nums text-dark-muted/60`,children:t+1}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-dark-muted/80`,title:lt(e.content),children:lt(e.content)||S(`chat.queuedEmptyPreview`)}),(0,Y.jsxs)(`span`,{className:`flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100`,children:[(0,Y.jsx)(`button`,{onClick:()=>Qe(e.id),className:`flex h-5 w-5 items-center justify-center rounded text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-blue`,title:S(`chat.queuedSteerNow`),"aria-label":S(`chat.queuedSteerNow`),children:(0,Y.jsx)(ae,{size:12,"aria-hidden":`true`})}),(0,Y.jsx)(`button`,{onClick:()=>Xe(e.id),className:`flex h-5 w-5 items-center justify-center rounded text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-blue`,title:S(`chat.queuedSendNow`),"aria-label":S(`chat.queuedSendNow`),children:(0,Y.jsx)(re,{size:12,"aria-hidden":`true`})}),(0,Y.jsx)(`button`,{onClick:()=>ot(e.id),className:`flex h-5 w-5 items-center justify-center rounded text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-blue`,title:S(`chat.queuedEdit`),"aria-label":S(`chat.queuedEdit`),children:(0,Y.jsx)(x,{size:12,"aria-hidden":`true`})}),(0,Y.jsx)(`button`,{onClick:()=>nt(e.id),className:`flex h-5 w-5 items-center justify-center rounded text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-red`,title:S(`chat.queuedDelete`),"aria-label":S(`chat.queuedDelete`),children:(0,Y.jsx)(N,{size:12,"aria-hidden":`true`})})]})]},e.id))})]}),H.length>0&&(0,Y.jsx)(`div`,{className:`${ir} mb-2 flex flex-wrap gap-1.5`,children:H.map(e=>{let t=pr(e.name),n=e.imageDataUri,r=(0,Y.jsxs)(Y.Fragment,{children:[n?(0,Y.jsx)(Ze,{src:n,name:e.name,size:13,hoverPreview:!1,thumb:!0}):e.uploading?(0,Y.jsx)(l,{size:13,className:`animate-spin`}):(0,Y.jsx)(t,{size:13}),(0,Y.jsx)(`span`,{className:`max-w-[140px] truncate`,children:e.name}),(0,Y.jsx)(`span`,{className:`text-badge text-dark-muted`,children:e.size>1048576?`${(e.size/1024/1024).toFixed(1)} MB`:`${Math.max(1,Math.round(e.size/1024))} KB`}),!e.uploading&&(0,Y.jsx)(`button`,{onClick:()=>Xr(e.id),className:`rounded p-0.5 text-dark-muted hover:text-accent-red hover:bg-accent-red/10 transition-colors`,"aria-label":S(`a11y.close`),children:(0,Y.jsx)(te,{size:11})})]}),i=B(`flex items-center gap-1.5 rounded-lg border text-xs transition-colors ${n?`p-1 pe-2`:`px-2 py-1`}`,e.error?`border-accent-red/40 bg-accent-red/5 text-accent-red`:e.uploading?`border-accent-blue/40 bg-accent-blue/5 text-accent-blue`:`border-dark-border bg-dark-surface text-dark-text`,n&&`cursor-zoom-in hover:border-accent-blue/40`);return n?(0,Y.jsx)(ze,{src:n,alt:e.name,className:`min-w-0`,children:(0,Y.jsx)(`div`,{className:i,children:r})},e.id):(0,Y.jsx)(`div`,{className:i,children:r},e.id)})}),ye&&(0,Y.jsx)(`div`,{className:`${ir} mb-2 rounded-xl border-2 border-dashed border-accent-blue/50 bg-accent-blue/5 py-3 text-center text-xs text-accent-blue`,children:S(`fileJob.dropHint`)}),(0,Y.jsx)(Ht,{}),(0,Y.jsxs)(`div`,{className:`chat-composer-card relative rounded-xl border ${me?``:`transition-all duration-150`} ${ir} ${Ti?`flex items-end gap-1 px-2 py-1.5`:``} ${Ei?`pointer-events-none opacity-0`:``}`,children:[!Ti&&(0,Y.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,"aria-label":S(`chat.resizeHint`),title:S(`chat.resizeHint`),tabIndex:0,onPointerDown:Er,onPointerMove:Dr,onPointerUp:Or,onPointerCancel:Or,onDoubleClick:kr,onKeyDown:e=>{e.key===`ArrowUp`?(e.preventDefault(),Ar(24)):e.key===`ArrowDown`&&(e.preventDefault(),Ar(-24))},className:`group absolute inset-x-0 top-0 z-10 flex h-2.5 cursor-row-resize touch-none items-center justify-center rounded-t-xl outline-none focus-visible:bg-accent-blue/10`,children:(0,Y.jsx)(`span`,{"aria-hidden":`true`,className:`h-1 w-9 rounded-full bg-dark-border transition-colors group-hover:bg-accent-blue/70 group-focus-visible:bg-accent-blue/70`})}),!Ti&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-3 pt-2.5`,children:[(0,Y.jsx)(fn,{disabled:y}),g&&(0,Y.jsx)(cn,{workspaceDir:m,onSelect:g,onNewSessionInDir:_})]}),Q&&(0,Y.jsx)(`div`,{onMouseDown:e=>e.preventDefault(),"aria-hidden":!Q,children:(0,Y.jsx)(An,{isOpen:Q,items:xr,selectedIndex:Yt,query:Wt,isSearching:Zt,onSelect:Lr,onHover:Xt,selectedCount:$t,onFinish:Rr,tabs:dr,activeTab:br,onTabChange:kn,scope:rn,onToggleScope:Jn,deliveryMode:sn,onToggleDelivery:Xn})}),G&&(0,Y.jsx)(`div`,{onMouseDown:e=>e.preventDefault(),"aria-hidden":!G,children:(0,Y.jsx)(Mn,{isOpen:G,items:Pr,selectedIndex:Re,query:Me,isLoading:We,onSelect:Br,onHover:Ve})}),kt&&(0,Y.jsx)(`div`,{onMouseDown:e=>e.preventDefault(),"aria-hidden":!kt,children:(0,Y.jsx)(qn,{isOpen:kt,commands:jt,selectedIndex:Mt,filter:At,onSelect:zr,onHover:Nt,containerRef:Bt})}),(0,Y.jsxs)(`div`,{className:Ti?`relative flex min-w-0 flex-1 items-start`:`relative`,children:[ie&&(0,Y.jsx)(`div`,{"aria-hidden":`true`,className:Ti?`pointer-events-none absolute inset-0 overflow-hidden px-1.5 py-1.5 text-sm leading-relaxed`:`pointer-events-none absolute inset-0 overflow-hidden px-4 pt-2 pb-3 text-sm leading-relaxed`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(`button`,{type:`button`,tabIndex:-1,onMouseDown:e=>e.preventDefault(),onClick:it,className:`pointer-events-auto relative z-20 min-w-0 cursor-pointer whitespace-pre-wrap break-words border-0 bg-transparent p-0 text-start text-dark-muted/70 transition-colors hover:text-dark-muted`,title:S(`chat.suggestionAccept`),"aria-label":S(`chat.suggestionAccept`),children:ie}),(0,Y.jsx)(`span`,{className:`mt-0.5 shrink-0 rounded border border-dark-border px-1.5 py-0.5 text-badge text-dark-muted/70`,"aria-hidden":`true`,children:S(`chat.suggestionAccept`)}),(0,Y.jsx)(`button`,{type:`button`,tabIndex:-1,onMouseDown:e=>e.preventDefault(),onClick:()=>M(e),className:`pointer-events-auto relative z-20 mt-0.5 shrink-0 rounded border border-dark-border px-1.5 py-0.5 text-badge text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,title:S(`chat.suggestionDismiss`),"aria-label":S(`chat.suggestionDismiss`),children:S(`chat.suggestionDismiss`)})]})}),(0,Y.jsx)(`textarea`,{ref:P,value:w,onChange:Ir,onKeyDown:ii,onPaste:ni,onFocus:Mi,onInput:Mi,onBlur:()=>{Q&&Rr(),Z(),G&&Vr()},onCompositionStart:ai,onCompositionEnd:oi,placeholder:ie?``:y&&b?b:S(Ti?`chat.inputPlaceholderCollapsed`:E?`chat.generatingPlaceholder`:`chat.inputPlaceholder`),rows:1,"aria-label":`Message input`,disabled:y,className:Ti?`w-full flex-1 bg-transparent px-1.5 py-1.5 text-sm text-dark-text placeholder-dark-muted/60 resize-none focus:outline-none min-h-[36px] max-h-[28vh] leading-relaxed${ie?` relative z-10`:``}`:`w-full bg-transparent px-4 pt-2 pb-3 text-sm text-dark-text placeholder-dark-muted/60
11
+ resize-none focus:outline-none min-h-[72px] max-h-[40vh] leading-relaxed${ie?` relative z-10`:``}`})]}),Ti&&(0,Y.jsxs)(`div`,{className:`flex min-w-0 max-w-[min(55%,16rem)] shrink items-center gap-1 pb-0.5`,children:[(0,Y.jsx)(fn,{compact:!0,disabled:y}),g&&(0,Y.jsx)(cn,{workspaceDir:m,onSelect:g,onNewSessionInDir:_,compact:!0})]}),Ti&&(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 pb-0.5`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:Oi,className:`flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,title:S(`chat.composerExpand`),"aria-label":S(`chat.composerExpand`),children:(0,Y.jsx)(h,{size:15,"aria-hidden":`true`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>void Ot(),disabled:Ii,className:B(`flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors`,X.state===`recording`?`bg-accent-red/15 text-accent-red animate-pulse`:`hover:bg-dark-hover hover:text-dark-text`,`disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent`),title:Fi,"aria-label":Fi,children:X.state===`transcribing`?(0,Y.jsx)(l,{size:15,className:`animate-spin`,"aria-hidden":`true`}):X.state===`recording`?(0,Y.jsx)(a,{size:15,"aria-hidden":`true`}):(0,Y.jsx)(p,{size:15,"aria-hidden":`true`})}),X.state===`recording`&&(0,Y.jsxs)(`span`,{className:`text-badge tabular-nums text-accent-red`,"aria-hidden":`true`,children:[(X.elapsedMs/1e3).toFixed(0),`s`]}),E&&(0,Y.jsx)(`button`,{onClick:o,className:`flex h-8 w-8 items-center justify-center rounded-full bg-accent-red/80 text-accent-fg transition-all hover:opacity-85 active:scale-95`,title:S(`chat.stopGen`),"aria-label":S(`chat.stopGen`),children:(0,Y.jsx)(r,{size:13,"aria-hidden":`true`})}),(0,Y.jsx)(`button`,{onClick:()=>void ri(),disabled:!Pi,className:`flex h-8 w-8 items-center justify-center rounded-full bg-dark-text text-dark-bg transition-all
12
+ hover:opacity-80 active:scale-95 disabled:opacity-25 disabled:cursor-not-allowed`,title:S(E?`chat.sendQueuedBtn`:`chat.sendBtn`),"aria-label":S(E?`chat.sendQueuedBtn`:`chat.sendBtn`),children:(0,Y.jsx)(c,{size:15,"aria-hidden":`true`})})]}),!Ti&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1.5 px-3 pb-3 lg:flex-nowrap`,children:[(0,Y.jsxs)(`div`,{className:`flex min-w-0 items-center gap-x-2`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:Di,className:`flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,title:S(`chat.composerCollapse`),"aria-label":S(`chat.composerCollapse`),children:(0,Y.jsx)(f,{size:15,"aria-hidden":`true`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:ki,"aria-pressed":_i,className:`flex h-8 w-8 items-center justify-center rounded-full transition-colors ${_i?`bg-accent-blue/15 text-accent-blue hover:bg-accent-blue/25`:`text-dark-muted hover:bg-dark-hover hover:text-dark-text`}`,title:S(_i?`chat.composerUnpin`:`chat.composerPin`),"aria-label":S(_i?`chat.composerUnpin`:`chat.composerPin`),children:(0,Y.jsx)(j,{size:15,"aria-hidden":`true`})}),(0,Y.jsx)(Vt,{}),(0,Y.jsx)(`span`,{className:`hidden min-w-0 sm:block`,children:(0,Y.jsx)(Gt,{})}),(0,Y.jsx)(Ee,{}),(0,Y.jsx)(nn,{onHandoffToAi:En}),dn.length>0&&(0,Y.jsx)(`button`,{type:`button`,onClick:Xn,className:B(`flex h-8 min-w-0 items-center rounded-full px-2.5 text-meta font-medium transition-colors`,_r[sn]),title:S(`chat.mentionDeliveryHint`),children:(0,Y.jsx)(`span`,{className:`max-w-[180px] truncate`,children:S(`chat.mentionDeliveryChip`,{titles:dn.join(`、`),mode:S(gr[sn])})})})]}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[wr>0&&w.length>0&&(0,Y.jsxs)(`span`,{className:`text-badge tabular-nums ${Ni?`text-accent-red font-medium`:`text-dark-muted/60`}`,children:[`~`,wr,` tokens`,Ni?` · ${S(`chat.nearLimit`)}`:``]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsxs)(`div`,{ref:Ct,className:`relative`,children:[(0,Y.jsxs)(`button`,{onClick:()=>St(e=>!e),disabled:X.state!==`idle`||E,className:`flex h-8 items-center justify-center gap-0.5 rounded-full px-2 text-meta font-semibold text-dark-muted transition-colors
13
+ hover:bg-dark-hover hover:text-dark-text disabled:opacity-40 disabled:hover:bg-transparent disabled:cursor-not-allowed`,title:S(E?`stt.generatingTitle`:`stt.langToggle`),"aria-label":S(E?`stt.generatingTitle`:`stt.langToggle`),"aria-haspopup":`listbox`,"aria-expanded":xt,children:[Ce(yt).short,(0,Y.jsx)(h,{size:11,"aria-hidden":`true`})]}),xt&&(0,Y.jsxs)(`div`,{role:`listbox`,"aria-label":S(`stt.langToggle`),className:`absolute bottom-full right-0 mb-2 z-50 w-44 rounded-lg border border-dark-border bg-dark-overlay ui-surface-overlay shadow-lg py-1 max-h-72 overflow-auto custom-scrollbar`,children:[ke.map(e=>(0,Y.jsxs)(`button`,{role:`option`,"aria-selected":e.code===yt,onClick:()=>wt(e.code),className:B(`flex w-full items-center justify-between gap-2 px-3 py-1.5 text-xs transition-colors`,e.code===yt?`text-accent-blue bg-accent-blue/10`:`text-dark-text hover:bg-dark-hover`),children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5 text-badge text-dark-muted`,children:[`Whisper`,e.code===yt&&(0,Y.jsx)(ee,{size:12,"aria-hidden":`true`})]})]},e.code)),(0,Y.jsx)(`div`,{className:`mt-1 border-t border-dark-border px-3 pt-1.5 pb-0.5 text-badge leading-relaxed text-dark-muted/70`,children:S(`stt.multiHint`)})]})]}),(0,Y.jsx)(`button`,{onClick:()=>void Ot(),disabled:Ii,className:B(`flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors`,X.state===`recording`?`bg-accent-red/15 text-accent-red animate-pulse`:`hover:bg-dark-hover hover:text-dark-text`,`disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent`),title:Fi,"aria-label":Fi,children:X.state===`transcribing`?(0,Y.jsx)(l,{size:15,className:`animate-spin`,"aria-hidden":`true`}):X.state===`recording`?(0,Y.jsx)(a,{size:15,"aria-hidden":`true`}):(0,Y.jsx)(p,{size:15,"aria-hidden":`true`})}),X.state===`recording`&&(0,Y.jsxs)(`span`,{className:`text-badge tabular-nums text-accent-red`,"aria-hidden":`true`,children:[(X.elapsedMs/1e3).toFixed(0),`s`]})]}),!E&&(0,Y.jsx)(`button`,{onClick:()=>Ae(!0),className:`flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,title:S(`skills.pickTitle`),"aria-label":S(`skills.pickTitle`),children:(0,Y.jsx)(t,{size:15,"aria-hidden":`true`})}),!E&&(0,Y.jsx)(`button`,{onClick:()=>void Jr(),disabled:xe,className:`flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text disabled:opacity-40 disabled:cursor-not-allowed`,title:`${S(`fileJob.screenshot`)} (${Li}+Shift+S)`,"aria-label":`${S(`fileJob.screenshot`)} (${Li}+Shift+S)`,children:xe?(0,Y.jsx)(l,{size:15,className:`animate-spin`,"aria-hidden":`true`}):(0,Y.jsx)(O,{size:15,"aria-hidden":`true`})}),!E&&(0,Y.jsx)(`button`,{onClick:()=>void qr(),className:`flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,title:S(`fileJob.attach`),"aria-label":S(`fileJob.attach`),children:(0,Y.jsx)(le,{size:15,"aria-hidden":`true`})}),(0,Y.jsx)(`input`,{ref:V,type:`file`,multiple:!0,accept:er,className:`hidden`,onChange:Kr}),E&&!Pi?(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[D?(0,Y.jsx)(`button`,{onClick:u,className:`flex h-8 w-8 items-center justify-center rounded-full bg-accent-green text-accent-fg transition-all hover:opacity-85 active:scale-95`,title:S(`chat.resumeGen`),"aria-label":S(`chat.resumeGen`),children:(0,Y.jsx)(ne,{size:14,"aria-hidden":`true`})}):(0,Y.jsx)(`button`,{onClick:s,className:`flex h-8 w-8 items-center justify-center rounded-full bg-accent-yellow text-accent-fg transition-all hover:opacity-85 active:scale-95`,title:S(`chat.pauseGen`),"aria-label":S(`chat.pauseGen`),children:(0,Y.jsx)(C,{size:14,"aria-hidden":`true`})}),(0,Y.jsx)(`button`,{onClick:o,className:`flex h-8 w-8 items-center justify-center rounded-full bg-accent-red text-accent-fg transition-all hover:opacity-85 active:scale-95`,title:S(`chat.stopGen`),"aria-label":S(`chat.stopGen`),children:(0,Y.jsx)(r,{size:13,"aria-hidden":`true`})})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[E&&(0,Y.jsx)(`button`,{onClick:o,className:`flex h-8 w-8 items-center justify-center rounded-full bg-accent-red/80 text-accent-fg transition-all hover:opacity-85 active:scale-95`,title:S(`chat.stopGen`),"aria-label":S(`chat.stopGen`),children:(0,Y.jsx)(r,{size:13,"aria-hidden":`true`})}),(0,Y.jsx)(`button`,{onClick:()=>void ri(),disabled:!Pi,className:`flex h-8 w-8 items-center justify-center rounded-full bg-dark-text text-dark-bg transition-all
14
+ hover:opacity-80 active:scale-95 disabled:opacity-25 disabled:cursor-not-allowed`,title:S(E?`chat.sendQueuedBtn`:`chat.sendBtn`),"aria-label":S(E?`chat.sendQueuedBtn`:`chat.sendBtn`),children:(0,Y.jsx)(c,{size:15,"aria-hidden":`true`})})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-1.5 hidden select-none items-center justify-center gap-3 text-badge text-dark-muted/55 transition-opacity duration-150 sm:flex ${Ei?`opacity-0`:``}`,children:[(0,Y.jsx)(`span`,{children:S(`chat.shiftEnter`)}),(0,Y.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,Y.jsx)(`span`,{children:S(`chat.escHint`)}),(0,Y.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,Y.jsx)(`span`,{children:`${Li}+Shift+S ${S(`shortcuts.screenshot`)}`}),(0,Y.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,Y.jsx)(`span`,{children:S(`chat.bangHint`)})]}),(0,Y.jsx)(jn,{open:Oe,onClose:()=>Ae(!1),onSelect:Hr})]})});export{sn as n,zt as r,br as t};
@@ -0,0 +1,2 @@
1
+ import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{A as t,S as n,g as r,kr as i,n as a,ni as o}from"./icons-B8Ngx6rM.js";import{t as s}from"./useTranslation-gGKZZfux.js";import{I as c}from"./markdown-Cps-36Z5.js";import{ft as l}from"./index-STsyoFCk.js";import{t as u}from"./installDiagnosis-ZYUVgJIJ.js";var d=e(o(),1),f=c(),p={queued:`queued`,resolve:`resolve`,fetch:`fetch`,verify:`verify`,load:`load`,register:`register`,activate:`activate`,done:`done`,error:`error`},m={queued:`Queued`,resolve:`Resolving market entry`,fetch:`Downloading package`,verify:`Verifying manifest`,load:`Loading plugin`,register:`Registering`,activate:`Activating`,done:`Done`,error:`Failed`};function h(e,t,n=`plugins`){let r=`${n}.installStages.${p[e]}`,i=t(r);return i===r?m[e]:i}function g({job:e,error:o,onClose:c,onRetry:p,stagesPrefix:m=`plugins`,diagnosis:g,testId:_=`install-console`}){let{t:v}=s(),y=(0,d.useRef)(null),b=e?.status===`running`,x=e?.status===`error`||!!o,S=Math.max(0,Math.min(100,e?.progress??0)),C=e?.stage??`error`,w=e?.logs??[],T=(e,t)=>{let n=`${m}.${e}`,r=v(n,t);if(r!==n)return r;let i=`plugins.${e}`,a=v(i,t);return a===i?e:a};(0,d.useEffect)(()=>{let e=y.current;e&&(e.scrollTop=e.scrollHeight)},[w.length]);let E=x?`bg-accent-red`:e?.status===`done`?`bg-accent-green`:`bg-accent-blue`;return(0,f.jsxs)(`div`,{"data-testid":_,className:`mt-2 rounded-md border border-dark-border bg-dark-bg px-2 py-1.5`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[x?(0,f.jsx)(r,{size:12,className:`shrink-0 text-accent-red`}):e?.status===`done`?(0,f.jsx)(i,{size:12,className:`shrink-0 text-accent-green`}):(0,f.jsx)(`div`,{className:`h-3 w-3 shrink-0 spin-slow rounded-full border-2 border-accent-blue border-t-transparent`}),(0,f.jsx)(`span`,{className:`text-meta text-dark-text truncate`,children:e?.alreadyInstalled&&b?T(`installAlreadyInstalled`):h(C,v,m)}),(0,f.jsx)(`div`,{className:`flex-1`}),e&&(0,f.jsxs)(`span`,{className:`text-meta tabular-nums text-dark-muted shrink-0`,children:[S,`%`]}),p&&x&&(0,f.jsx)(`button`,{type:`button`,onClick:p,className:`px-1.5 py-0.5 rounded border border-dark-border bg-dark-hover text-meta text-dark-muted hover:text-dark-text transition-colors`,children:T(`installRetry`)}),(0,f.jsx)(`button`,{type:`button`,onClick:c,title:T(`installClose`),className:`p-0.5 rounded text-dark-muted hover:text-dark-text transition-colors`,children:(0,f.jsx)(a,{size:12})})]}),e?(0,f.jsx)(`div`,{className:`mt-1 h-1 rounded-full bg-dark-hover overflow-hidden`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":S,"aria-label":h(C,v,m),children:(0,f.jsx)(`div`,{className:`h-full ${E} transition-[width] duration-300 ease-out`,style:{width:`${S}%`}})}):x?null:(0,f.jsx)(`div`,{className:`mt-1 h-1 rounded-full bg-dark-hover overflow-hidden`,role:`progressbar`,"aria-label":h(`queued`,v,m),children:(0,f.jsx)(`div`,{className:`h-full w-1/3 rounded-full bg-accent-blue animate-pulse`})}),(e?.error||o)&&(0,f.jsx)(`div`,{className:`mt-1 rounded border border-accent-red bg-accent-red/15 px-1.5 py-1 text-meta text-accent-red break-words`,children:e?.error||o}),x&&g&&(0,f.jsxs)(`button`,{type:`button`,"data-testid":`install-ask-ai`,onClick:()=>l(u({diagnosis:g,job:e,error:o??null})),className:`mt-1 inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-accent-blue/40 bg-accent-blue/10 text-meta text-accent-blue hover:bg-accent-blue/20 transition-colors`,children:[(0,f.jsx)(t,{size:11}),T(`installAskAi`)]}),e&&(0,f.jsxs)(`details`,{open:!0,className:`mt-1 group`,children:[(0,f.jsxs)(`summary`,{className:`flex items-center gap-1 cursor-pointer select-none text-meta text-dark-muted hover:text-dark-text transition-colors`,children:[(0,f.jsx)(n,{size:11}),T(`installLogs`,{count:w.length})]}),(0,f.jsx)(`pre`,{ref:y,className:`mt-1 max-h-32 overflow-auto rounded border border-dark-border bg-dark-surface px-1.5 py-1 font-mono text-meta text-dark-muted whitespace-pre-wrap break-all`,children:w.length?w.join(`
2
+ `):T(`installLogsEmpty`)})]})]})}export{h as n,g as t};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{Dr as t,Er as n,Or as r,Xn as i,it as a,ni as o,v as s}from"./icons-B8Ngx6rM.js";import{t as c}from"./useTranslation-gGKZZfux.js";import{r as l}from"./api-ZQf0Ys8y.js";import{n as u,r as d}from"./settingsStore-BSdi9gNd.js";import{I as f}from"./markdown-Cps-36Z5.js";var p=e(o(),1),m=f(),ee=[`fact`,`code_change`,`user_preference`,`error_fix`,`decision`,`convention`,`goal`,`interaction`],te=6e3,h=500;function ne(e){if(!Number.isFinite(e))return 50;let t=Math.floor(e);return t>=5&&t<=h?t:50}function g(e){if(!Number.isFinite(e)||e<=0)return`—`;try{return new Date(e).toLocaleString()}catch{return`—`}}function _(){let{t:e}=c(),t=ne(d(e=>e.memoryPageSize)),o=d(e=>e.setMemoryPageSize),s=(0,p.useMemo)(()=>u.includes(t)?u:[...u,t].sort((e,t)=>e-t),[t]),[f,g]=(0,p.useState)([]),[_,y]=(0,p.useState)(null),[b,x]=(0,p.useState)(null),[S,C]=(0,p.useState)(!1),[w,T]=(0,p.useState)(null),[E,ie]=(0,p.useState)(`all`),[D,ae]=(0,p.useState)(`all`),[O,oe]=(0,p.useState)(`time`),[k,A]=(0,p.useState)({}),[j,M]=(0,p.useState)(null),[N,P]=(0,p.useState)([]),[F,I]=(0,p.useState)([]),[L,R]=(0,p.useState)(1),z=(0,p.useRef)(null),B=(0,p.useRef)(null),V=(0,p.useRef)(null),[H,U]=(0,p.useState)(null),W=(0,p.useCallback)(e=>{R(e),V.current&&(V.current.scrollTop=0)},[]),G=(0,p.useCallback)(async()=>{C(!0),T(null);let[t,n]=await Promise.all([l.get(`/api/memory/status`),l.get(`/api/memory/list?limit=${h}`)]);t.success&&t.data?y(t.data):T(t.error??e(`memory.loadFailed`)),n.success&&n.data?(g(n.data.items??[]),x(n.data.stats??null),A(n.data.usage??{}),M(n.data.usageSummary??null),P([]),n.data.warnings?.length&&T(e(`memory.partialRead`,{reason:n.data.warnings[0]}))):T(n.error??e(`memory.loadFailed`)),C(!1)},[e]);(0,p.useEffect)(()=>{G()},[G]);let K=(0,p.useCallback)(async t=>{z.current!==null&&(window.clearTimeout(z.current),z.current=null),B.current=null,U(null);let n=await l.post(`/api/memory/delete`,{id:t});if(n.success&&n.data?.deleted===!0){T(e(`memory.deleted`));return}let r=n.success?n.data?.reason??e(`memory.deleteUnavailable`):n.error??``;P(e=>e.filter(e=>e!==t)),T(e(`memory.deleteFailed`,{reason:r}))},[e]),q=(0,p.useCallback)(e=>{B.current&&K(B.current.id),P(t=>t.includes(e.id)?t:[...t,e.id]);let t={id:e.id,content:e.content};B.current=t,U(t),z.current=window.setTimeout(()=>{K(e.id)},te)},[K]),se=(0,p.useCallback)(()=>{let t=B.current;t&&(z.current!==null&&(window.clearTimeout(z.current),z.current=null),B.current=null,U(null),P(e=>e.filter(e=>e!==t.id)),T(e(`memory.undoDone`)))},[e]);(0,p.useEffect)(()=>()=>{z.current!==null&&window.clearTimeout(z.current);let e=B.current;e&&l.post(`/api/memory/delete`,{id:e.id})},[]);let J=(0,p.useMemo)(()=>{let e=new Set(N);return f.filter(t=>!(e.has(t.id)||E!==`all`&&t.scope!==E||D!==`all`&&t.type!==D))},[f,N,E,D]),Y=(0,p.useMemo)(()=>{let e=new Map;for(let t of J){let n=t.subject?`s:${t.subject}|${t.layer??`fact`}`:`i:${t.id}`,r=e.get(n);r?r.push(t):e.set(n,[t])}let t=[];for(let[n,r]of e){let[e,...i]=[...r].sort((e,t)=>t.timestamp-e.timestamp);e&&t.push({key:n,head:e,rest:i})}return t.sort((e,t)=>{if(O===`usage`){let n=(k[t.head.id]?.count??0)-(k[e.head.id]?.count??0);if(n!==0)return n}return t.head.timestamp-e.head.timestamp})},[J,O,k]),X=Math.max(1,Math.ceil(Y.length/t)),Z=Math.min(L,X),ce=(0,p.useMemo)(()=>Y.slice((Z-1)*t,Z*t),[Y,Z,t]),le=e=>{I(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},Q=_!=null&&!_.tombstones,$=(0,p.useMemo)(()=>{let e=new Set(f.map(e=>e.scope));return[`global`,`workspace`].filter(t=>e.has(t))},[f]);return(0,m.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,m.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center gap-3 border-b border-dark-border px-4 max-md:gap-2 max-md:px-3`,children:[(0,m.jsx)(i,{size:16,className:`shrink-0 text-dark-muted`,"aria-hidden":`true`}),(0,m.jsx)(`span`,{className:`truncate text-sm font-medium text-dark-text`,children:e(`memory.title`)}),_?.workspaceHash?(0,m.jsx)(`span`,{className:`truncate text-meta text-dark-muted opacity-60`,children:_.workspaceHash}):null,(0,m.jsx)(`span`,{className:`ms-auto truncate text-meta text-dark-muted`,children:e(`memory.recallElsewhere`)})]}),_&&!_.active?(0,m.jsxs)(`div`,{className:`mx-4 mt-3 rounded border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-xs text-amber-200`,children:[(0,m.jsx)(`div`,{className:`font-medium`,children:e(`memory.disabled`)}),(0,m.jsx)(`div`,{className:`mt-1 text-amber-200/80`,children:_.reason??e(`memory.disabledHint`)}),(0,m.jsxs)(`div`,{className:`mt-1 text-amber-200/60`,children:[e(`memory.backendLabel`),`: `,_.backend,_.cause?` · ${_.cause}`:``]})]}):null,(0,m.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 border-b border-dark-border px-4 py-2 max-md:px-3`,children:[(0,m.jsxs)(`label`,{className:`flex items-center gap-1 text-xs text-dark-muted`,children:[e(`memory.filterScope`),(0,m.jsxs)(`select`,{value:E,onChange:e=>{ie(e.target.value),W(1)},className:`rounded border border-dark-border bg-dark-surface px-1.5 py-1 text-xs text-dark-text`,children:[(0,m.jsx)(`option`,{value:`all`,children:e(`memory.all`)}),($.length>0?$:[`global`,`workspace`]).map(t=>(0,m.jsx)(`option`,{value:t,children:e(t===`global`?`memory.scopeGlobal`:`memory.scopeWorkspace`)},t))]})]}),(0,m.jsxs)(`label`,{className:`flex items-center gap-1 text-xs text-dark-muted`,children:[e(`memory.filterCategory`),(0,m.jsxs)(`select`,{value:D,onChange:e=>{ae(e.target.value),W(1)},className:`rounded border border-dark-border bg-dark-surface px-1.5 py-1 text-xs text-dark-text`,children:[(0,m.jsx)(`option`,{value:`all`,children:e(`memory.all`)}),ee.map(t=>(0,m.jsx)(`option`,{value:t,children:e(`memory.category.${t}`)},t))]})]}),(0,m.jsxs)(`label`,{className:`flex items-center gap-1 text-xs text-dark-muted`,children:[e(`memory.sortBy`),(0,m.jsxs)(`select`,{value:O,onChange:e=>{oe(e.target.value),W(1)},className:`rounded border border-dark-border bg-dark-surface px-1.5 py-1 text-xs text-dark-text`,children:[(0,m.jsx)(`option`,{value:`time`,children:e(`memory.sortTime`)}),(0,m.jsx)(`option`,{value:`usage`,children:e(`memory.sortUsage`)})]})]}),(0,m.jsxs)(`label`,{className:`flex items-center gap-1 text-xs text-dark-muted`,children:[e(`memory.pageSize`),(0,m.jsx)(`select`,{"data-testid":`memory-page-size`,value:t,onChange:e=>{o(Number(e.target.value)),W(1)},className:`rounded border border-dark-border bg-dark-surface px-1.5 py-1 text-xs text-dark-text`,children:s.map(t=>(0,m.jsx)(`option`,{value:t,children:e(`memory.pageSizeOption`,{count:t})},t))})]}),(0,m.jsxs)(`span`,{className:`text-xs text-dark-muted`,children:[e(`memory.count`,{count:J.length}),b?` · ${e(`memory.totalCount`,{count:b.totalItems})}`:``,b?.truncated?` (${e(`memory.truncated`)})`:``]}),j?(0,m.jsx)(`span`,{className:`text-meta text-dark-muted opacity-70`,title:j.ledgerPath??void 0,children:j.enabled?e(`memory.usageSummary`,{events:j.totalEvents,ids:j.distinctIds}):e(`memory.usageOff`)}):null,(0,m.jsxs)(`button`,{type:`button`,onClick:()=>void G(),disabled:S,className:`ms-auto flex items-center gap-1 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-hover hover:text-dark-text disabled:opacity-50`,children:[(0,m.jsx)(a,{size:13,className:S?`animate-spin`:void 0,"aria-hidden":`true`}),e(`memory.refresh`)]})]}),Q?(0,m.jsxs)(`div`,{className:`mx-4 mt-2 rounded border border-dark-border bg-dark-surface px-3 py-2 text-xs text-dark-muted`,children:[(0,m.jsx)(`span`,{className:`text-dark-text`,children:e(`memory.localDeleteOff`)}),(0,m.jsx)(`span`,{className:`ms-1`,children:e(`memory.localDeleteOffHint`)})]}):null,w?(0,m.jsx)(`div`,{className:`mx-4 mt-2 rounded border border-dark-border bg-dark-surface px-3 py-2 text-xs text-dark-text`,children:w}):null,(0,m.jsx)(`div`,{ref:V,className:`flex-1 overflow-y-auto px-4 py-3 max-md:px-3`,children:S&&f.length===0?(0,m.jsx)(`div`,{className:`text-xs text-dark-muted`,children:e(`memory.loading`)}):Y.length===0?(0,m.jsxs)(`div`,{className:`text-xs text-dark-muted`,children:[(0,m.jsx)(`div`,{children:e(`memory.empty`)}),(0,m.jsx)(`div`,{className:`mt-1 text-dark-muted/70`,children:e(`memory.emptyHint`)})]}):(0,m.jsx)(`ul`,{className:`space-y-2`,children:ce.map(({key:t,head:i,rest:a})=>{let o=F.includes(t);return(0,m.jsxs)(`li`,{className:`rounded border border-dark-border bg-dark-surface p-3`,children:[(0,m.jsx)(v,{item:i,usage:k[i.id],onDelete:Q?void 0:q,muted:!1}),a.length>0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`button`,{type:`button`,onClick:()=>le(t),className:`mt-2 flex items-center gap-1 text-xs text-dark-muted hover:text-dark-text`,children:[o?(0,m.jsx)(r,{size:12,"aria-hidden":`true`}):(0,m.jsx)(n,{size:12,"aria-hidden":`true`}),e(`memory.collapsed`,{count:a.length})]}),o?(0,m.jsx)(`ul`,{className:`mt-2 space-y-2 border-s border-dark-border ps-3`,children:a.map(e=>(0,m.jsx)(`li`,{children:(0,m.jsx)(v,{item:e,usage:k[e.id],onDelete:Q?void 0:q,muted:!0})},e.id))}):null]}):null]},t)})})}),X>1?(0,m.jsx)(re,{page:Z,pageCount:X,onChange:W}):null,H?(0,m.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-t border-dark-border bg-dark-surface px-4 py-2 max-md:px-3`,children:[(0,m.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-dark-muted`,children:[e(`memory.pendingDelete`),`: `,H.content]}),(0,m.jsx)(`button`,{type:`button`,onClick:se,className:`shrink-0 rounded border border-dark-border px-2 py-1 text-xs text-dark-text hover:bg-dark-hover`,children:e(`memory.undo`)})]}):null]})}function v({item:e,usage:t,onDelete:n,muted:r}){let{t:i}=c();return(0,m.jsxs)(`div`,{className:r?`opacity-60`:void 0,children:[(0,m.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,m.jsx)(`p`,{className:`min-w-0 flex-1 whitespace-pre-wrap break-words text-sm text-dark-text`,children:e.content}),n?(0,m.jsx)(`button`,{type:`button`,onClick:()=>n(e),title:i(`memory.delete`),"aria-label":i(`memory.delete`),className:`shrink-0 rounded p-1 text-dark-muted hover:bg-dark-hover hover:text-red-400`,children:(0,m.jsx)(s,{size:13,"aria-hidden":`true`})}):null]}),(0,m.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-2 gap-y-1 text-meta text-dark-muted`,children:[(0,m.jsx)(`span`,{className:`rounded bg-dark-hover px-1.5 py-0.5`,children:i(e.scope===`global`?`memory.scopeGlobal`:e.scope===`session`?`memory.scopeSession`:`memory.scopeWorkspace`)}),(0,m.jsx)(`span`,{className:`rounded bg-dark-hover px-1.5 py-0.5`,children:i(`memory.category.${e.type}`,{defaultValue:e.type})}),e.layer===`experience`?(0,m.jsxs)(`span`,{className:`rounded bg-dark-hover px-1.5 py-0.5 text-amber-300/90`,children:[i(`memory.layerExperience`),e.boundaryEnvs?.length?`: ${e.boundaryEnvs.join(`, `)}`:``]}):null,e.subject?(0,m.jsxs)(`span`,{className:`rounded bg-dark-hover px-1.5 py-0.5`,children:[`#`,e.subject]}):null,(0,m.jsx)(`span`,{children:i(`memory.confidenceShort`,{value:Math.round((e.confidence??0)*100)})}),(0,m.jsx)(`span`,{className:t?.count?`text-emerald-300/90`:`opacity-70`,children:t?.count?i(`memory.usageUsed`,{count:t.count}):i(`memory.usageNever`)}),t?.lastUsedAt?(0,m.jsx)(`span`,{className:`opacity-70`,children:i(`memory.usageLastAt`,{time:g(t.lastUsedAt)})}):null,(0,m.jsx)(`span`,{children:g(e.timestamp)}),e.id?(0,m.jsx)(`span`,{className:`truncate opacity-60`,children:e.id}):null]})]})}function y(e,t){if(t<=7)return Array.from({length:t},(e,t)=>t+1);let n=[1],r=Math.max(2,e-1),i=Math.min(t-1,e+1);r>2&&n.push(null);for(let e=r;e<=i;e+=1)n.push(e);return i<t-1&&n.push(null),n.push(t),n}function re({page:e,pageCount:r,onChange:i}){let{t:a}=c(),o=`rounded border border-dark-border p-1 text-dark-muted hover:bg-dark-hover hover:text-dark-text disabled:cursor-not-allowed disabled:opacity-40`;return(0,m.jsxs)(`div`,{"data-testid":`memory-pager`,className:`flex shrink-0 items-center justify-end gap-1 border-t border-dark-border px-4 py-2 max-md:flex-wrap max-md:justify-start max-md:px-3`,children:[(0,m.jsx)(`button`,{type:`button`,onClick:()=>i(e-1),disabled:e<=1,"aria-label":a(`common.prevPage`),className:o,children:(0,m.jsx)(t,{size:13,"aria-hidden":`true`})}),y(e,r).map((t,n)=>t===null?(0,m.jsx)(`span`,{className:`px-1 text-xs text-dark-muted opacity-60`,children:`…`},`gap-${n}`):(0,m.jsx)(`button`,{type:`button`,"data-testid":`memory-page-${t}`,onClick:()=>i(t),"aria-current":t===e?`page`:void 0,className:t===e?`min-w-[1.75rem] rounded border border-accent-blue/60 bg-accent-blue/15 px-1.5 py-1 text-xs text-dark-text`:`min-w-[1.75rem] rounded border border-dark-border px-1.5 py-1 text-xs text-dark-muted hover:bg-dark-hover hover:text-dark-text`,children:t},t)),(0,m.jsx)(`button`,{type:`button`,onClick:()=>i(e+1),disabled:e>=r,"aria-label":a(`common.nextPage`),className:o,children:(0,m.jsx)(n,{size:13,"aria-hidden":`true`})})]})}export{_ as MemoryView};