@deepseekcode/cli 1.0.37 → 1.0.38

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 (40) hide show
  1. package/README.md +10 -1
  2. package/package.json +9 -9
  3. package/web/dist/assets/AssistantsView-Bh6ajWIo.js +1 -0
  4. package/web/dist/assets/AutomationView-D2Z-_4qe.js +1 -0
  5. package/web/dist/assets/{ChannelConfigView-JDljUn42.js → ChannelConfigView-DlakOI5z.js} +5 -5
  6. package/web/dist/assets/ConnectorsView-ELXDmM9m.js +1 -0
  7. package/web/dist/assets/FileTreeView-Ciq1vhTf.js +11 -0
  8. package/web/dist/assets/HookConfigView-DR8TP3QG.js +1 -0
  9. package/web/dist/assets/ModelsView-BW6eRUwf.js +1 -0
  10. package/web/dist/assets/PluginsView-CrHGk_JC.js +1 -0
  11. package/web/dist/assets/SessionGrid-DYYsm2dT.js +52 -0
  12. package/web/dist/assets/SettingsModal-DNxIKsKC.js +10 -0
  13. package/web/dist/assets/SkillsView-DS0nnKig.js +1 -0
  14. package/web/dist/assets/TemplatesTab-pXElHCnz.js +1 -0
  15. package/web/dist/assets/{ThreeScene-CMqkpyKO.js → ThreeScene-DFL_qzB1.js} +1 -1
  16. package/web/dist/assets/ToolsView-Bk4hckku.js +1 -0
  17. package/web/dist/assets/{icons-f1hlMKvD.js → icons-YJcunJnw.js} +195 -140
  18. package/web/dist/assets/index-CtPliI0f.css +1 -0
  19. package/web/dist/assets/index-D1N4vQ9I.js +591 -0
  20. package/web/dist/assets/{markdown-DEtuzEyz.js → markdown-CrVimah5.js} +1 -1
  21. package/web/dist/assets/{panels-Bn-2wCur.js → panels-BykQW6E1.js} +1 -1
  22. package/web/dist/assets/{react-vendor-ClBKp0t-.js → react-vendor-DM-M1fu_.js} +1 -1
  23. package/web/dist/assets/{state-xD58vmym.js → state-D8omNTWe.js} +1 -1
  24. package/web/dist/assets/sttLanguages-D4JbRJc6.js +1 -0
  25. package/web/dist/index.html +7 -7
  26. package/web/dist/assets/AssistantsView-OMdgsTIj.js +0 -1
  27. package/web/dist/assets/AutomationView-BPwjLbkL.js +0 -1
  28. package/web/dist/assets/ConnectorsView-AemNT1Ae.js +0 -1
  29. package/web/dist/assets/FileTreeView-DYx-0jFV.js +0 -11
  30. package/web/dist/assets/HookConfigView-CS1QqgPx.js +0 -1
  31. package/web/dist/assets/ModelsView-B3nHezvJ.js +0 -1
  32. package/web/dist/assets/PluginsView-C4Xc70ec.js +0 -1
  33. package/web/dist/assets/SessionGrid-C9-LeJH0.js +0 -47
  34. package/web/dist/assets/SettingsModal-CjWT1C66.js +0 -4
  35. package/web/dist/assets/SkillsView-DTZyXald.js +0 -1
  36. package/web/dist/assets/TemplatesTab-CE-CfCf2.js +0 -1
  37. package/web/dist/assets/ToolsView-CrEHDTEO.js +0 -1
  38. package/web/dist/assets/index-BCHbHIbw.css +0 -1
  39. package/web/dist/assets/index-u1vYyqna.js +0 -592
  40. package/web/dist/assets/sttLanguages-BNRptAQA.js +0 -1
@@ -1,4 +1,4 @@
1
- import{g as Dt,c as Yn}from"./icons-f1hlMKvD.js";var nn={exports:{}},Re={};/**
1
+ import{g as Dt,c as Yn}from"./icons-YJcunJnw.js";var nn={exports:{}},Re={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.js
4
4
  *
@@ -1 +1 @@
1
- import{a as f,R as hn}from"./icons-f1hlMKvD.js";const we=f.createContext(null);we.displayName="PanelGroupContext";const k={group:"data-panel-group",groupDirection:"data-panel-group-direction",groupId:"data-panel-group-id",panel:"data-panel",panelCollapsible:"data-panel-collapsible",panelId:"data-panel-id",panelSize:"data-panel-size",resizeHandle:"data-resize-handle",resizeHandleActive:"data-resize-handle-active",resizeHandleEnabled:"data-panel-resize-handle-enabled",resizeHandleId:"data-panel-resize-handle-id",resizeHandleState:"data-resize-handle-state"},$e=10,ne=f.useLayoutEffect,Fe=hn.useId,zn=typeof Fe=="function"?Fe:()=>null;let yn=0;function Ne(e=null){const n=zn(),t=f.useRef(e||n||null);return t.current===null&&(t.current=""+yn++),e??t.current}function Je({children:e,className:n="",collapsedSize:t,collapsible:r,defaultSize:i,forwardedRef:o,id:l,maxSize:s,minSize:a,onCollapse:h,onExpand:w,onResize:p,order:u,style:v,tagName:z="div",...C}){const E=f.useContext(we);if(E===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:b,expandPanel:L,getPanelSize:M,getPanelStyle:$,groupId:O,isPanelCollapsed:R,reevaluatePanelConstraints:P,registerPanel:K,resizePanel:J,unregisterPanel:F}=E,G=Ne(l),D=f.useRef({callbacks:{onCollapse:h,onExpand:w,onResize:p},constraints:{collapsedSize:t,collapsible:r,defaultSize:i,maxSize:s,minSize:a},id:G,idIsFromProps:l!==void 0,order:u});f.useRef({didLogMissingDefaultSizeWarning:!1}),ne(()=>{const{callbacks:_,constraints:N}=D.current,B={...N};D.current.id=G,D.current.idIsFromProps=l!==void 0,D.current.order=u,_.onCollapse=h,_.onExpand=w,_.onResize=p,N.collapsedSize=t,N.collapsible=r,N.defaultSize=i,N.maxSize=s,N.minSize=a,(B.collapsedSize!==N.collapsedSize||B.collapsible!==N.collapsible||B.maxSize!==N.maxSize||B.minSize!==N.minSize)&&P(D.current,B)}),ne(()=>{const _=D.current;return K(_),()=>{F(_)}},[u,G,K,F]),f.useImperativeHandle(o,()=>({collapse:()=>{b(D.current)},expand:_=>{L(D.current,_)},getId(){return G},getSize(){return M(D.current)},isCollapsed(){return R(D.current)},isExpanded(){return!R(D.current)},resize:_=>{J(D.current,_)}}),[b,L,M,R,G,J]);const Z=$(D.current,i);return f.createElement(z,{...C,children:e,className:n,id:G,style:{...Z,...v},[k.groupId]:O,[k.panel]:"",[k.panelCollapsible]:r||void 0,[k.panelId]:G,[k.panelSize]:parseFloat(""+Z.flexGrow).toFixed(1)})}const xn=f.forwardRef((e,n)=>f.createElement(Je,{...e,forwardedRef:n}));Je.displayName="Panel";xn.displayName="forwardRef(Panel)";let He=null,Se=-1,Y=null;function vn(e,n){if(n){const t=(n&en)!==0,r=(n&nn)!==0,i=(n&tn)!==0,o=(n&rn)!==0;if(t)return i?"se-resize":o?"ne-resize":"e-resize";if(r)return i?"sw-resize":o?"nw-resize":"w-resize";if(i)return"s-resize";if(o)return"n-resize"}switch(e){case"horizontal":return"ew-resize";case"intersection":return"move";case"vertical":return"ns-resize"}}function Sn(){Y!==null&&(document.head.removeChild(Y),He=null,Y=null,Se=-1)}function Le(e,n){var t,r;const i=vn(e,n);if(He!==i){if(He=i,Y===null&&(Y=document.createElement("style"),document.head.appendChild(Y)),Se>=0){var o;(o=Y.sheet)===null||o===void 0||o.removeRule(Se)}Se=(t=(r=Y.sheet)===null||r===void 0?void 0:r.insertRule(`*{cursor: ${i} !important;}`))!==null&&t!==void 0?t:-1}}function je(e){return e.type==="keydown"}function Ye(e){return e.type.startsWith("pointer")}function Ze(e){return e.type.startsWith("mouse")}function Ee(e){if(Ye(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(Ze(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function bn(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function Pn(e,n,t){return e.x<n.x+n.width&&e.x+e.width>n.x&&e.y<n.y+n.height&&e.y+e.height>n.y}function wn(e,n){if(e===n)throw new Error("Cannot compare node with itself");const t={a:Ue(e),b:Ue(n)};let r;for(;t.a.at(-1)===t.b.at(-1);)e=t.a.pop(),n=t.b.pop(),r=e;x(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:Ke(We(t.a)),b:Ke(We(t.b))};if(i.a===i.b){const o=r.childNodes,l={a:t.a.at(-1),b:t.b.at(-1)};let s=o.length;for(;s--;){const a=o[s];if(a===l.a)return 1;if(a===l.b)return-1}}return Math.sign(i.a-i.b)}const En=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Cn(e){var n;const t=getComputedStyle((n=Qe(e))!==null&&n!==void 0?n:e).display;return t==="flex"||t==="inline-flex"}function In(e){const n=getComputedStyle(e);return!!(n.position==="fixed"||n.zIndex!=="auto"&&(n.position!=="static"||Cn(e))||+n.opacity<1||"transform"in n&&n.transform!=="none"||"webkitTransform"in n&&n.webkitTransform!=="none"||"mixBlendMode"in n&&n.mixBlendMode!=="normal"||"filter"in n&&n.filter!=="none"||"webkitFilter"in n&&n.webkitFilter!=="none"||"isolation"in n&&n.isolation==="isolate"||En.test(n.willChange)||n.webkitOverflowScrolling==="touch")}function We(e){let n=e.length;for(;n--;){const t=e[n];if(x(t,"Missing node"),In(t))return t}return null}function Ke(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Ue(e){const n=[];for(;e;)n.push(e),e=Qe(e);return n}function Qe(e){const{parentNode:n}=e;return n&&n instanceof ShadowRoot?n.host:n}const en=1,nn=2,tn=4,rn=8,Rn=bn()==="coarse";let V=[],se=!1,ee=new Map,Ce=new Map;const he=new Set;function Ln(e,n,t,r,i){var o;const{ownerDocument:l}=n,s={direction:t,element:n,hitAreaMargins:r,setResizeHandlerState:i},a=(o=ee.get(l))!==null&&o!==void 0?o:0;return ee.set(l,a+1),he.add(s),be(),function(){var w;Ce.delete(e),he.delete(s);const p=(w=ee.get(l))!==null&&w!==void 0?w:1;if(ee.set(l,p-1),be(),p===1&&ee.delete(l),V.includes(s)){const u=V.indexOf(s);u>=0&&V.splice(u,1),Ge(),i("up",!0,null)}}}function An(e){const{target:n}=e,{x:t,y:r}=Ee(e);se=!0,_e({target:n,x:t,y:r}),be(),V.length>0&&(Pe("down",e),e.preventDefault(),on(n)||e.stopImmediatePropagation())}function Ae(e){const{x:n,y:t}=Ee(e);if(se&&e.buttons===0&&(se=!1,Pe("up",e)),!se){const{target:r}=e;_e({target:r,x:n,y:t})}Pe("move",e),Ge(),V.length>0&&e.preventDefault()}function ke(e){const{target:n}=e,{x:t,y:r}=Ee(e);Ce.clear(),se=!1,V.length>0&&(e.preventDefault(),on(n)||e.stopImmediatePropagation()),Pe("up",e),_e({target:n,x:t,y:r}),Ge(),be()}function on(e){let n=e;for(;n;){if(n.hasAttribute(k.resizeHandle))return!0;n=n.parentElement}return!1}function _e({target:e,x:n,y:t}){V.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),he.forEach(i=>{const{element:o,hitAreaMargins:l}=i,s=o.getBoundingClientRect(),{bottom:a,left:h,right:w,top:p}=s,u=Rn?l.coarse:l.fine;if(n>=h-u&&n<=w+u&&t>=p-u&&t<=a+u){if(r!==null&&document.contains(r)&&o!==r&&!o.contains(r)&&!r.contains(o)&&wn(r,o)>0){let z=r,C=!1;for(;z&&!z.contains(o);){if(Pn(z.getBoundingClientRect(),s)){C=!0;break}z=z.parentElement}if(C)return}V.push(i)}})}function De(e,n){Ce.set(e,n)}function Ge(){let e=!1,n=!1;V.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:n=!0});let t=0;Ce.forEach(r=>{t|=r}),e&&n?Le("intersection",t):e?Le("horizontal",t):n?Le("vertical",t):Sn()}let Me=new AbortController;function be(){Me.abort(),Me=new AbortController;const e={capture:!0,signal:Me.signal};he.size&&(se?(V.length>0&&ee.forEach((n,t)=>{const{body:r}=t;n>0&&(r.addEventListener("contextmenu",ke,e),r.addEventListener("pointerleave",Ae,e),r.addEventListener("pointermove",Ae,e))}),window.addEventListener("pointerup",ke,e),window.addEventListener("pointercancel",ke,e)):ee.forEach((n,t)=>{const{body:r}=t;n>0&&(r.addEventListener("pointerdown",An,e),r.addEventListener("pointermove",Ae,e))}))}function Pe(e,n){he.forEach(t=>{const{setResizeHandlerState:r}=t,i=V.includes(t);r(e,i,n)})}function kn(){const[e,n]=f.useState(0);return f.useCallback(()=>n(t=>t+1),[])}function x(e,n){if(!e)throw console.error(n),Error(n)}function te(e,n,t=$e){return e.toFixed(t)===n.toFixed(t)?0:e>n?1:-1}function j(e,n,t=$e){return te(e,n,t)===0}function W(e,n,t){return te(e,n,t)===0}function Dn(e,n,t){if(e.length!==n.length)return!1;for(let r=0;r<e.length;r++){const i=e[r],o=n[r];if(!W(i,o,t))return!1}return!0}function le({panelConstraints:e,panelIndex:n,size:t}){const r=e[n];x(r!=null,`Panel constraints not found for index ${n}`);let{collapsedSize:i=0,collapsible:o,maxSize:l=100,minSize:s=0}=r;if(te(t,s)<0)if(o){const a=(i+s)/2;te(t,a)<0?t=i:t=s}else t=s;return t=Math.min(l,t),t=parseFloat(t.toFixed($e)),t}function ge({delta:e,initialLayout:n,panelConstraints:t,pivotIndices:r,prevLayout:i,trigger:o}){if(W(e,0))return n;const l=[...n],[s,a]=r;x(s!=null,"Invalid first pivot index"),x(a!=null,"Invalid second pivot index");let h=0;if(o==="keyboard"){{const p=e<0?a:s,u=t[p];x(u,`Panel constraints not found for index ${p}`);const{collapsedSize:v=0,collapsible:z,minSize:C=0}=u;if(z){const E=n[p];if(x(E!=null,`Previous layout not found for panel index ${p}`),W(E,v)){const b=C-E;te(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}{const p=e<0?s:a,u=t[p];x(u,`No panel constraints found for index ${p}`);const{collapsedSize:v=0,collapsible:z,minSize:C=0}=u;if(z){const E=n[p];if(x(E!=null,`Previous layout not found for panel index ${p}`),W(E,C)){const b=E-v;te(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}}{const p=e<0?1:-1;let u=e<0?a:s,v=0;for(;;){const C=n[u];x(C!=null,`Previous layout not found for panel index ${u}`);const b=le({panelConstraints:t,panelIndex:u,size:100})-C;if(v+=b,u+=p,u<0||u>=t.length)break}const z=Math.min(Math.abs(e),Math.abs(v));e=e<0?0-z:z}{let u=e<0?s:a;for(;u>=0&&u<t.length;){const v=Math.abs(e)-Math.abs(h),z=n[u];x(z!=null,`Previous layout not found for panel index ${u}`);const C=z-v,E=le({panelConstraints:t,panelIndex:u,size:C});if(!W(z,E)&&(h+=z-E,l[u]=E,h.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?u--:u++}}if(Dn(i,l))return i;{const p=e<0?a:s,u=n[p];x(u!=null,`Previous layout not found for panel index ${p}`);const v=u+h,z=le({panelConstraints:t,panelIndex:p,size:v});if(l[p]=z,!W(z,v)){let C=v-z,b=e<0?a:s;for(;b>=0&&b<t.length;){const L=l[b];x(L!=null,`Previous layout not found for panel index ${b}`);const M=L+C,$=le({panelConstraints:t,panelIndex:b,size:M});if(W(L,$)||(C-=$-L,l[b]=$),W(C,0))break;e>0?b--:b++}}}const w=l.reduce((p,u)=>u+p,0);return W(w,100)?l:i}function Mn({layout:e,panelsArray:n,pivotIndices:t}){let r=0,i=100,o=0,l=0;const s=t[0];x(s!=null,"No pivot index found"),n.forEach((p,u)=>{const{constraints:v}=p,{maxSize:z=100,minSize:C=0}=v;u===s?(r=C,i=z):(o+=C,l+=z)});const a=Math.min(i,100-o),h=Math.max(r,100-l),w=e[s];return{valueMax:a,valueMin:h,valueNow:w}}function ze(e,n=document){return Array.from(n.querySelectorAll(`[${k.resizeHandleId}][data-panel-group-id="${e}"]`))}function ln(e,n,t=document){const i=ze(e,t).findIndex(o=>o.getAttribute(k.resizeHandleId)===n);return i??null}function sn(e,n,t){const r=ln(e,n,t);return r!=null?[r,r+1]:[-1,-1]}function an(e,n=document){var t;if(n instanceof HTMLElement&&(n==null||(t=n.dataset)===null||t===void 0?void 0:t.panelGroupId)==e)return n;const r=n.querySelector(`[data-panel-group][data-panel-group-id="${e}"]`);return r||null}function Ie(e,n=document){const t=n.querySelector(`[${k.resizeHandleId}="${e}"]`);return t||null}function Hn(e,n,t,r=document){var i,o,l,s;const a=Ie(n,r),h=ze(e,r),w=a?h.indexOf(a):-1,p=(i=(o=t[w])===null||o===void 0?void 0:o.id)!==null&&i!==void 0?i:null,u=(l=(s=t[w+1])===null||s===void 0?void 0:s.id)!==null&&l!==void 0?l:null;return[p,u]}function $n({committedValuesRef:e,eagerValuesRef:n,groupId:t,layout:r,panelDataArray:i,panelGroupElement:o,setLayout:l}){f.useRef({didWarnAboutMissingResizeHandle:!1}),ne(()=>{if(!o)return;const s=ze(t,o);for(let a=0;a<i.length-1;a++){const{valueMax:h,valueMin:w,valueNow:p}=Mn({layout:r,panelsArray:i,pivotIndices:[a,a+1]}),u=s[a];if(u!=null){const v=i[a];x(v,`No panel data found for index "${a}"`),u.setAttribute("aria-controls",v.id),u.setAttribute("aria-valuemax",""+Math.round(h)),u.setAttribute("aria-valuemin",""+Math.round(w)),u.setAttribute("aria-valuenow",p!=null?""+Math.round(p):"")}}return()=>{s.forEach((a,h)=>{a.removeAttribute("aria-controls"),a.removeAttribute("aria-valuemax"),a.removeAttribute("aria-valuemin"),a.removeAttribute("aria-valuenow")})}},[t,r,i,o]),f.useEffect(()=>{if(!o)return;const s=n.current;x(s,"Eager values not found");const{panelDataArray:a}=s,h=an(t,o);x(h!=null,`No group found for id "${t}"`);const w=ze(t,o);x(w,`No resize handles found for group id "${t}"`);const p=w.map(u=>{const v=u.getAttribute(k.resizeHandleId);x(v,"Resize handle element has no handle id attribute");const[z,C]=Hn(t,v,a,o);if(z==null||C==null)return()=>{};const E=b=>{if(!b.defaultPrevented)switch(b.key){case"Enter":{b.preventDefault();const L=a.findIndex(M=>M.id===z);if(L>=0){const M=a[L];x(M,`No panel data found for index ${L}`);const $=r[L],{collapsedSize:O=0,collapsible:R,minSize:P=0}=M.constraints;if($!=null&&R){const K=ge({delta:W($,O)?P-O:O-$,initialLayout:r,panelConstraints:a.map(J=>J.constraints),pivotIndices:sn(t,v,o),prevLayout:r,trigger:"keyboard"});r!==K&&l(K)}}break}}};return u.addEventListener("keydown",E),()=>{u.removeEventListener("keydown",E)}});return()=>{p.forEach(u=>u())}},[o,e,n,t,r,i,l])}function Ve(e,n){if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;return!0}function un(e,n){const t=e==="horizontal",{x:r,y:i}=Ee(n);return t?r:i}function Nn(e,n,t,r,i){const o=t==="horizontal",l=Ie(n,i);x(l,`No resize handle element found for id "${n}"`);const s=l.getAttribute(k.groupId);x(s,"Resize handle element has no group id attribute");let{initialCursorPosition:a}=r;const h=un(t,e),w=an(s,i);x(w,`No group element found for id "${s}"`);const p=w.getBoundingClientRect(),u=o?p.width:p.height;return(h-a)/u*100}function _n(e,n,t,r,i,o){if(je(e)){const l=t==="horizontal";let s=0;e.shiftKey?s=100:i!=null?s=i:s=10;let a=0;switch(e.key){case"ArrowDown":a=l?0:s;break;case"ArrowLeft":a=l?-s:0;break;case"ArrowRight":a=l?s:0;break;case"ArrowUp":a=l?0:-s;break;case"End":a=100;break;case"Home":a=-100;break}return a}else return r==null?0:Nn(e,n,t,r,o)}function Gn({panelDataArray:e}){const n=Array(e.length),t=e.map(o=>o.constraints);let r=0,i=100;for(let o=0;o<e.length;o++){const l=t[o];x(l,`Panel constraints not found for index ${o}`);const{defaultSize:s}=l;s!=null&&(r++,n[o]=s,i-=s)}for(let o=0;o<e.length;o++){const l=t[o];x(l,`Panel constraints not found for index ${o}`);const{defaultSize:s}=l;if(s!=null)continue;const a=e.length-r,h=i/a;r++,n[o]=h,i-=h}return n}function oe(e,n,t){n.forEach((r,i)=>{const o=e[i];x(o,`Panel data not found for index ${i}`);const{callbacks:l,constraints:s,id:a}=o,{collapsedSize:h=0,collapsible:w}=s,p=t[a];if(p==null||r!==p){t[a]=r;const{onCollapse:u,onExpand:v,onResize:z}=l;z&&z(r,p),w&&(u||v)&&(v&&(p==null||j(p,h))&&!j(r,h)&&v(),u&&(p==null||!j(p,h))&&j(r,h)&&u())}})}function ve(e,n){if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!=n[t])return!1;return!0}function Bn({defaultSize:e,dragState:n,layout:t,panelData:r,panelIndex:i,precision:o=3}){const l=t[i];let s;return l==null?s=e!=null?e.toPrecision(o):"1":r.length===1?s="1":s=l.toPrecision(o),{flexBasis:0,flexGrow:s,flexShrink:1,overflow:"hidden",pointerEvents:n!==null?"none":void 0}}function Tn(e,n=10){let t=null;return(...i)=>{t!==null&&clearTimeout(t),t=setTimeout(()=>{e(...i)},n)}}function Oe(e){try{if(typeof localStorage<"u")e.getItem=n=>localStorage.getItem(n),e.setItem=(n,t)=>{localStorage.setItem(n,t)};else throw new Error("localStorage not supported in this environment")}catch(n){console.error(n),e.getItem=()=>null,e.setItem=()=>{}}}function cn(e){return`react-resizable-panels:${e}`}function fn(e){return e.map(n=>{const{constraints:t,id:r,idIsFromProps:i,order:o}=n;return i?r:o?`${o}:${JSON.stringify(t)}`:JSON.stringify(t)}).sort((n,t)=>n.localeCompare(t)).join(",")}function dn(e,n){try{const t=cn(e),r=n.getItem(t);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function Fn(e,n,t){var r,i;const o=(r=dn(e,t))!==null&&r!==void 0?r:{},l=fn(n);return(i=o[l])!==null&&i!==void 0?i:null}function Wn(e,n,t,r,i){var o;const l=cn(e),s=fn(n),a=(o=dn(e,i))!==null&&o!==void 0?o:{};a[s]={expandToSizes:Object.fromEntries(t.entries()),layout:r};try{i.setItem(l,JSON.stringify(a))}catch(h){console.error(h)}}function qe({layout:e,panelConstraints:n}){const t=[...e],r=t.reduce((o,l)=>o+l,0);if(t.length!==n.length)throw Error(`Invalid ${n.length} panel layout: ${t.map(o=>`${o}%`).join(", ")}`);if(!W(r,100)&&t.length>0)for(let o=0;o<n.length;o++){const l=t[o];x(l!=null,`No layout data found for index ${o}`);const s=100/r*l;t[o]=s}let i=0;for(let o=0;o<n.length;o++){const l=t[o];x(l!=null,`No layout data found for index ${o}`);const s=le({panelConstraints:n,panelIndex:o,size:l});l!=s&&(i+=l-s,t[o]=s)}if(!W(i,0))for(let o=0;o<n.length;o++){const l=t[o];x(l!=null,`No layout data found for index ${o}`);const s=l+i,a=le({panelConstraints:n,panelIndex:o,size:s});if(l!==a&&(i-=a-l,t[o]=a,W(i,0)))break}return t}const Kn=100,me={getItem:e=>(Oe(me),me.getItem(e)),setItem:(e,n)=>{Oe(me),me.setItem(e,n)}},Xe={};function pn({autoSaveId:e=null,children:n,className:t="",direction:r,forwardedRef:i,id:o=null,onLayout:l=null,keyboardResizeBy:s=null,storage:a=me,style:h,tagName:w="div",...p}){const u=Ne(o),v=f.useRef(null),[z,C]=f.useState(null),[E,b]=f.useState([]),L=kn(),M=f.useRef({}),$=f.useRef(new Map),O=f.useRef(0),R=f.useRef({autoSaveId:e,direction:r,dragState:z,id:u,keyboardResizeBy:s,onLayout:l,storage:a}),P=f.useRef({layout:E,panelDataArray:[],panelDataArrayChanged:!1});f.useRef({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),f.useImperativeHandle(i,()=>({getId:()=>R.current.id,getLayout:()=>{const{layout:c}=P.current;return c},setLayout:c=>{const{onLayout:m}=R.current,{layout:S,panelDataArray:g}=P.current,d=qe({layout:c,panelConstraints:g.map(y=>y.constraints)});Ve(S,d)||(b(d),P.current.layout=d,m&&m(d),oe(g,d,M.current))}}),[]),ne(()=>{R.current.autoSaveId=e,R.current.direction=r,R.current.dragState=z,R.current.id=u,R.current.onLayout=l,R.current.storage=a}),$n({committedValuesRef:R,eagerValuesRef:P,groupId:u,layout:E,panelDataArray:P.current.panelDataArray,setLayout:b,panelGroupElement:v.current}),f.useEffect(()=>{const{panelDataArray:c}=P.current;if(e){if(E.length===0||E.length!==c.length)return;let m=Xe[e];m==null&&(m=Tn(Wn,Kn),Xe[e]=m);const S=[...c],g=new Map($.current);m(e,S,g,E,a)}},[e,E,a]),f.useEffect(()=>{});const K=f.useCallback(c=>{const{onLayout:m}=R.current,{layout:S,panelDataArray:g}=P.current;if(c.constraints.collapsible){const d=g.map(q=>q.constraints),{collapsedSize:y=0,panelSize:I,pivotIndices:H}=Q(g,c,S);if(x(I!=null,`Panel size not found for panel "${c.id}"`),!j(I,y)){$.current.set(c.id,I);const X=ie(g,c)===g.length-1?I-y:y-I,A=ge({delta:X,initialLayout:S,panelConstraints:d,pivotIndices:H,prevLayout:S,trigger:"imperative-api"});ve(S,A)||(b(A),P.current.layout=A,m&&m(A),oe(g,A,M.current))}}},[]),J=f.useCallback((c,m)=>{const{onLayout:S}=R.current,{layout:g,panelDataArray:d}=P.current;if(c.constraints.collapsible){const y=d.map(U=>U.constraints),{collapsedSize:I=0,panelSize:H=0,minSize:q=0,pivotIndices:X}=Q(d,c,g),A=m??q;if(j(H,I)){const U=$.current.get(c.id),de=U!=null&&U>=A?U:A,Re=ie(d,c)===d.length-1?H-de:de-H,T=ge({delta:Re,initialLayout:g,panelConstraints:y,pivotIndices:X,prevLayout:g,trigger:"imperative-api"});ve(g,T)||(b(T),P.current.layout=T,S&&S(T),oe(d,T,M.current))}}},[]),F=f.useCallback(c=>{const{layout:m,panelDataArray:S}=P.current,{panelSize:g}=Q(S,c,m);return x(g!=null,`Panel size not found for panel "${c.id}"`),g},[]),G=f.useCallback((c,m)=>{const{panelDataArray:S}=P.current,g=ie(S,c);return Bn({defaultSize:m,dragState:z,layout:E,panelData:S,panelIndex:g})},[z,E]),D=f.useCallback(c=>{const{layout:m,panelDataArray:S}=P.current,{collapsedSize:g=0,collapsible:d,panelSize:y}=Q(S,c,m);return x(y!=null,`Panel size not found for panel "${c.id}"`),d===!0&&j(y,g)},[]),Z=f.useCallback(c=>{const{layout:m,panelDataArray:S}=P.current,{collapsedSize:g=0,collapsible:d,panelSize:y}=Q(S,c,m);return x(y!=null,`Panel size not found for panel "${c.id}"`),!d||te(y,g)>0},[]),_=f.useCallback(c=>{const{panelDataArray:m}=P.current;m.push(c),m.sort((S,g)=>{const d=S.order,y=g.order;return d==null&&y==null?0:d==null?-1:y==null?1:d-y}),P.current.panelDataArrayChanged=!0,L()},[L]);ne(()=>{if(P.current.panelDataArrayChanged){P.current.panelDataArrayChanged=!1;const{autoSaveId:c,onLayout:m,storage:S}=R.current,{layout:g,panelDataArray:d}=P.current;let y=null;if(c){const H=Fn(c,d,S);H&&($.current=new Map(Object.entries(H.expandToSizes)),y=H.layout)}y==null&&(y=Gn({panelDataArray:d}));const I=qe({layout:y,panelConstraints:d.map(H=>H.constraints)});Ve(g,I)||(b(I),P.current.layout=I,m&&m(I),oe(d,I,M.current))}}),ne(()=>{const c=P.current;return()=>{c.layout=[]}},[]);const N=f.useCallback(c=>{let m=!1;const S=v.current;return S&&window.getComputedStyle(S,null).getPropertyValue("direction")==="rtl"&&(m=!0),function(d){d.preventDefault();const y=v.current;if(!y)return()=>null;const{direction:I,dragState:H,id:q,keyboardResizeBy:X,onLayout:A}=R.current,{layout:U,panelDataArray:de}=P.current,{initialLayout:xe}=H??{},Re=sn(q,c,y);let T=_n(d,c,I,H,X,y);const Be=I==="horizontal";Be&&m&&(T=-T);const gn=de.map(mn=>mn.constraints),pe=ge({delta:T,initialLayout:xe??U,panelConstraints:gn,pivotIndices:Re,prevLayout:U,trigger:je(d)?"keyboard":"mouse-or-touch"}),Te=!ve(U,pe);(Ye(d)||Ze(d))&&O.current!=T&&(O.current=T,!Te&&T!==0?Be?De(c,T<0?en:nn):De(c,T<0?tn:rn):De(c,0)),Te&&(b(pe),P.current.layout=pe,A&&A(pe),oe(de,pe,M.current))}},[]),B=f.useCallback((c,m)=>{const{onLayout:S}=R.current,{layout:g,panelDataArray:d}=P.current,y=d.map(U=>U.constraints),{panelSize:I,pivotIndices:H}=Q(d,c,g);x(I!=null,`Panel size not found for panel "${c.id}"`);const X=ie(d,c)===d.length-1?I-m:m-I,A=ge({delta:X,initialLayout:g,panelConstraints:y,pivotIndices:H,prevLayout:g,trigger:"imperative-api"});ve(g,A)||(b(A),P.current.layout=A,S&&S(A),oe(d,A,M.current))},[]),ae=f.useCallback((c,m)=>{const{layout:S,panelDataArray:g}=P.current,{collapsedSize:d=0,collapsible:y}=m,{collapsedSize:I=0,collapsible:H,maxSize:q=100,minSize:X=0}=c.constraints,{panelSize:A}=Q(g,c,S);A!=null&&(y&&H&&j(A,d)?j(d,I)||B(c,I):A<X?B(c,X):A>q&&B(c,q))},[B]),ue=f.useCallback((c,m)=>{const{direction:S}=R.current,{layout:g}=P.current;if(!v.current)return;const d=Ie(c,v.current);x(d,`Drag handle element not found for id "${c}"`);const y=un(S,m);C({dragHandleId:c,dragHandleRect:d.getBoundingClientRect(),initialCursorPosition:y,initialLayout:g})},[]),ce=f.useCallback(()=>{C(null)},[]),ye=f.useCallback(c=>{const{panelDataArray:m}=P.current,S=ie(m,c);S>=0&&(m.splice(S,1),delete M.current[c.id],P.current.panelDataArrayChanged=!0,L())},[L]),re=f.useMemo(()=>({collapsePanel:K,direction:r,dragState:z,expandPanel:J,getPanelSize:F,getPanelStyle:G,groupId:u,isPanelCollapsed:D,isPanelExpanded:Z,reevaluatePanelConstraints:ae,registerPanel:_,registerResizeHandle:N,resizePanel:B,startDragging:ue,stopDragging:ce,unregisterPanel:ye,panelGroupElement:v.current}),[K,z,r,J,F,G,u,D,Z,ae,_,N,B,ue,ce,ye]),fe={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return f.createElement(we.Provider,{value:re},f.createElement(w,{...p,children:n,className:t,id:o,ref:v,style:{...fe,...h},[k.group]:"",[k.groupDirection]:r,[k.groupId]:u}))}const Un=f.forwardRef((e,n)=>f.createElement(pn,{...e,forwardedRef:n}));pn.displayName="PanelGroup";Un.displayName="forwardRef(PanelGroup)";function ie(e,n){return e.findIndex(t=>t===n||t.id===n.id)}function Q(e,n,t){const r=ie(e,n),o=r===e.length-1?[r-1,r]:[r,r+1],l=t[r];return{...n.constraints,panelSize:l,pivotIndices:o}}function Vn({disabled:e,handleId:n,resizeHandler:t,panelGroupElement:r}){f.useEffect(()=>{if(e||t==null||r==null)return;const i=Ie(n,r);if(i==null)return;const o=l=>{if(!l.defaultPrevented)switch(l.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{l.preventDefault(),t(l);break}case"F6":{l.preventDefault();const s=i.getAttribute(k.groupId);x(s,`No group element found for id "${s}"`);const a=ze(s,r),h=ln(s,n,r);x(h!==null,`No resize element found for id "${n}"`);const w=l.shiftKey?h>0?h-1:a.length-1:h+1<a.length?h+1:0;a[w].focus();break}}};return i.addEventListener("keydown",o),()=>{i.removeEventListener("keydown",o)}},[r,e,n,t])}function On({children:e=null,className:n="",disabled:t=!1,hitAreaMargins:r,id:i,onBlur:o,onClick:l,onDragging:s,onFocus:a,onPointerDown:h,onPointerUp:w,style:p={},tabIndex:u=0,tagName:v="div",...z}){var C,E;const b=f.useRef(null),L=f.useRef({onClick:l,onDragging:s,onPointerDown:h,onPointerUp:w});f.useEffect(()=>{L.current.onClick=l,L.current.onDragging=s,L.current.onPointerDown=h,L.current.onPointerUp=w});const M=f.useContext(we);if(M===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:$,groupId:O,registerResizeHandle:R,startDragging:P,stopDragging:K,panelGroupElement:J}=M,F=Ne(i),[G,D]=f.useState("inactive"),[Z,_]=f.useState(!1),[N,B]=f.useState(null),ae=f.useRef({state:G});ne(()=>{ae.current.state=G}),f.useEffect(()=>{if(t)B(null);else{const re=R(F);B(()=>re)}},[t,F,R]);const ue=(C=r==null?void 0:r.coarse)!==null&&C!==void 0?C:15,ce=(E=r==null?void 0:r.fine)!==null&&E!==void 0?E:5;f.useEffect(()=>{if(t||N==null)return;const re=b.current;x(re,"Element ref not attached");let fe=!1;return Ln(F,re,$,{coarse:ue,fine:ce},(m,S,g)=>{if(!S){D("inactive");return}switch(m){case"down":{D("drag"),fe=!1,x(g,'Expected event to be defined for "down" action'),P(F,g);const{onDragging:d,onPointerDown:y}=L.current;d==null||d(!0),y==null||y();break}case"move":{const{state:d}=ae.current;fe=!0,d!=="drag"&&D("hover"),x(g,'Expected event to be defined for "move" action'),N(g);break}case"up":{D("hover"),K();const{onClick:d,onDragging:y,onPointerUp:I}=L.current;y==null||y(!1),I==null||I(),fe||d==null||d();break}}})},[ue,$,t,ce,R,F,N,P,K]),Vn({disabled:t,handleId:F,resizeHandler:N,panelGroupElement:J});const ye={touchAction:"none",userSelect:"none"};return f.createElement(v,{...z,children:e,className:n,id:i,onBlur:()=>{_(!1),o==null||o()},onFocus:()=>{_(!0),a==null||a()},ref:b,role:"separator",style:{...ye,...p},tabIndex:u,[k.groupDirection]:$,[k.groupId]:O,[k.resizeHandle]:"",[k.resizeHandleActive]:G==="drag"?"pointer":Z?"keyboard":void 0,[k.resizeHandleEnabled]:!t,[k.resizeHandleId]:F,[k.resizeHandleState]:G})}On.displayName="PanelResizeHandle";export{Un as P,xn as a,On as b};
1
+ import{a as f,R as hn}from"./icons-YJcunJnw.js";const we=f.createContext(null);we.displayName="PanelGroupContext";const k={group:"data-panel-group",groupDirection:"data-panel-group-direction",groupId:"data-panel-group-id",panel:"data-panel",panelCollapsible:"data-panel-collapsible",panelId:"data-panel-id",panelSize:"data-panel-size",resizeHandle:"data-resize-handle",resizeHandleActive:"data-resize-handle-active",resizeHandleEnabled:"data-panel-resize-handle-enabled",resizeHandleId:"data-panel-resize-handle-id",resizeHandleState:"data-resize-handle-state"},$e=10,ne=f.useLayoutEffect,Fe=hn.useId,zn=typeof Fe=="function"?Fe:()=>null;let yn=0;function Ne(e=null){const n=zn(),t=f.useRef(e||n||null);return t.current===null&&(t.current=""+yn++),e??t.current}function Je({children:e,className:n="",collapsedSize:t,collapsible:r,defaultSize:i,forwardedRef:o,id:l,maxSize:s,minSize:a,onCollapse:h,onExpand:w,onResize:p,order:u,style:v,tagName:z="div",...C}){const E=f.useContext(we);if(E===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:b,expandPanel:L,getPanelSize:M,getPanelStyle:$,groupId:O,isPanelCollapsed:R,reevaluatePanelConstraints:P,registerPanel:K,resizePanel:J,unregisterPanel:F}=E,G=Ne(l),D=f.useRef({callbacks:{onCollapse:h,onExpand:w,onResize:p},constraints:{collapsedSize:t,collapsible:r,defaultSize:i,maxSize:s,minSize:a},id:G,idIsFromProps:l!==void 0,order:u});f.useRef({didLogMissingDefaultSizeWarning:!1}),ne(()=>{const{callbacks:_,constraints:N}=D.current,B={...N};D.current.id=G,D.current.idIsFromProps=l!==void 0,D.current.order=u,_.onCollapse=h,_.onExpand=w,_.onResize=p,N.collapsedSize=t,N.collapsible=r,N.defaultSize=i,N.maxSize=s,N.minSize=a,(B.collapsedSize!==N.collapsedSize||B.collapsible!==N.collapsible||B.maxSize!==N.maxSize||B.minSize!==N.minSize)&&P(D.current,B)}),ne(()=>{const _=D.current;return K(_),()=>{F(_)}},[u,G,K,F]),f.useImperativeHandle(o,()=>({collapse:()=>{b(D.current)},expand:_=>{L(D.current,_)},getId(){return G},getSize(){return M(D.current)},isCollapsed(){return R(D.current)},isExpanded(){return!R(D.current)},resize:_=>{J(D.current,_)}}),[b,L,M,R,G,J]);const Z=$(D.current,i);return f.createElement(z,{...C,children:e,className:n,id:G,style:{...Z,...v},[k.groupId]:O,[k.panel]:"",[k.panelCollapsible]:r||void 0,[k.panelId]:G,[k.panelSize]:parseFloat(""+Z.flexGrow).toFixed(1)})}const xn=f.forwardRef((e,n)=>f.createElement(Je,{...e,forwardedRef:n}));Je.displayName="Panel";xn.displayName="forwardRef(Panel)";let He=null,Se=-1,Y=null;function vn(e,n){if(n){const t=(n&en)!==0,r=(n&nn)!==0,i=(n&tn)!==0,o=(n&rn)!==0;if(t)return i?"se-resize":o?"ne-resize":"e-resize";if(r)return i?"sw-resize":o?"nw-resize":"w-resize";if(i)return"s-resize";if(o)return"n-resize"}switch(e){case"horizontal":return"ew-resize";case"intersection":return"move";case"vertical":return"ns-resize"}}function Sn(){Y!==null&&(document.head.removeChild(Y),He=null,Y=null,Se=-1)}function Le(e,n){var t,r;const i=vn(e,n);if(He!==i){if(He=i,Y===null&&(Y=document.createElement("style"),document.head.appendChild(Y)),Se>=0){var o;(o=Y.sheet)===null||o===void 0||o.removeRule(Se)}Se=(t=(r=Y.sheet)===null||r===void 0?void 0:r.insertRule(`*{cursor: ${i} !important;}`))!==null&&t!==void 0?t:-1}}function je(e){return e.type==="keydown"}function Ye(e){return e.type.startsWith("pointer")}function Ze(e){return e.type.startsWith("mouse")}function Ee(e){if(Ye(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(Ze(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function bn(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function Pn(e,n,t){return e.x<n.x+n.width&&e.x+e.width>n.x&&e.y<n.y+n.height&&e.y+e.height>n.y}function wn(e,n){if(e===n)throw new Error("Cannot compare node with itself");const t={a:Ue(e),b:Ue(n)};let r;for(;t.a.at(-1)===t.b.at(-1);)e=t.a.pop(),n=t.b.pop(),r=e;x(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:Ke(We(t.a)),b:Ke(We(t.b))};if(i.a===i.b){const o=r.childNodes,l={a:t.a.at(-1),b:t.b.at(-1)};let s=o.length;for(;s--;){const a=o[s];if(a===l.a)return 1;if(a===l.b)return-1}}return Math.sign(i.a-i.b)}const En=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Cn(e){var n;const t=getComputedStyle((n=Qe(e))!==null&&n!==void 0?n:e).display;return t==="flex"||t==="inline-flex"}function In(e){const n=getComputedStyle(e);return!!(n.position==="fixed"||n.zIndex!=="auto"&&(n.position!=="static"||Cn(e))||+n.opacity<1||"transform"in n&&n.transform!=="none"||"webkitTransform"in n&&n.webkitTransform!=="none"||"mixBlendMode"in n&&n.mixBlendMode!=="normal"||"filter"in n&&n.filter!=="none"||"webkitFilter"in n&&n.webkitFilter!=="none"||"isolation"in n&&n.isolation==="isolate"||En.test(n.willChange)||n.webkitOverflowScrolling==="touch")}function We(e){let n=e.length;for(;n--;){const t=e[n];if(x(t,"Missing node"),In(t))return t}return null}function Ke(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Ue(e){const n=[];for(;e;)n.push(e),e=Qe(e);return n}function Qe(e){const{parentNode:n}=e;return n&&n instanceof ShadowRoot?n.host:n}const en=1,nn=2,tn=4,rn=8,Rn=bn()==="coarse";let V=[],se=!1,ee=new Map,Ce=new Map;const he=new Set;function Ln(e,n,t,r,i){var o;const{ownerDocument:l}=n,s={direction:t,element:n,hitAreaMargins:r,setResizeHandlerState:i},a=(o=ee.get(l))!==null&&o!==void 0?o:0;return ee.set(l,a+1),he.add(s),be(),function(){var w;Ce.delete(e),he.delete(s);const p=(w=ee.get(l))!==null&&w!==void 0?w:1;if(ee.set(l,p-1),be(),p===1&&ee.delete(l),V.includes(s)){const u=V.indexOf(s);u>=0&&V.splice(u,1),Ge(),i("up",!0,null)}}}function An(e){const{target:n}=e,{x:t,y:r}=Ee(e);se=!0,_e({target:n,x:t,y:r}),be(),V.length>0&&(Pe("down",e),e.preventDefault(),on(n)||e.stopImmediatePropagation())}function Ae(e){const{x:n,y:t}=Ee(e);if(se&&e.buttons===0&&(se=!1,Pe("up",e)),!se){const{target:r}=e;_e({target:r,x:n,y:t})}Pe("move",e),Ge(),V.length>0&&e.preventDefault()}function ke(e){const{target:n}=e,{x:t,y:r}=Ee(e);Ce.clear(),se=!1,V.length>0&&(e.preventDefault(),on(n)||e.stopImmediatePropagation()),Pe("up",e),_e({target:n,x:t,y:r}),Ge(),be()}function on(e){let n=e;for(;n;){if(n.hasAttribute(k.resizeHandle))return!0;n=n.parentElement}return!1}function _e({target:e,x:n,y:t}){V.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),he.forEach(i=>{const{element:o,hitAreaMargins:l}=i,s=o.getBoundingClientRect(),{bottom:a,left:h,right:w,top:p}=s,u=Rn?l.coarse:l.fine;if(n>=h-u&&n<=w+u&&t>=p-u&&t<=a+u){if(r!==null&&document.contains(r)&&o!==r&&!o.contains(r)&&!r.contains(o)&&wn(r,o)>0){let z=r,C=!1;for(;z&&!z.contains(o);){if(Pn(z.getBoundingClientRect(),s)){C=!0;break}z=z.parentElement}if(C)return}V.push(i)}})}function De(e,n){Ce.set(e,n)}function Ge(){let e=!1,n=!1;V.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:n=!0});let t=0;Ce.forEach(r=>{t|=r}),e&&n?Le("intersection",t):e?Le("horizontal",t):n?Le("vertical",t):Sn()}let Me=new AbortController;function be(){Me.abort(),Me=new AbortController;const e={capture:!0,signal:Me.signal};he.size&&(se?(V.length>0&&ee.forEach((n,t)=>{const{body:r}=t;n>0&&(r.addEventListener("contextmenu",ke,e),r.addEventListener("pointerleave",Ae,e),r.addEventListener("pointermove",Ae,e))}),window.addEventListener("pointerup",ke,e),window.addEventListener("pointercancel",ke,e)):ee.forEach((n,t)=>{const{body:r}=t;n>0&&(r.addEventListener("pointerdown",An,e),r.addEventListener("pointermove",Ae,e))}))}function Pe(e,n){he.forEach(t=>{const{setResizeHandlerState:r}=t,i=V.includes(t);r(e,i,n)})}function kn(){const[e,n]=f.useState(0);return f.useCallback(()=>n(t=>t+1),[])}function x(e,n){if(!e)throw console.error(n),Error(n)}function te(e,n,t=$e){return e.toFixed(t)===n.toFixed(t)?0:e>n?1:-1}function j(e,n,t=$e){return te(e,n,t)===0}function W(e,n,t){return te(e,n,t)===0}function Dn(e,n,t){if(e.length!==n.length)return!1;for(let r=0;r<e.length;r++){const i=e[r],o=n[r];if(!W(i,o,t))return!1}return!0}function le({panelConstraints:e,panelIndex:n,size:t}){const r=e[n];x(r!=null,`Panel constraints not found for index ${n}`);let{collapsedSize:i=0,collapsible:o,maxSize:l=100,minSize:s=0}=r;if(te(t,s)<0)if(o){const a=(i+s)/2;te(t,a)<0?t=i:t=s}else t=s;return t=Math.min(l,t),t=parseFloat(t.toFixed($e)),t}function ge({delta:e,initialLayout:n,panelConstraints:t,pivotIndices:r,prevLayout:i,trigger:o}){if(W(e,0))return n;const l=[...n],[s,a]=r;x(s!=null,"Invalid first pivot index"),x(a!=null,"Invalid second pivot index");let h=0;if(o==="keyboard"){{const p=e<0?a:s,u=t[p];x(u,`Panel constraints not found for index ${p}`);const{collapsedSize:v=0,collapsible:z,minSize:C=0}=u;if(z){const E=n[p];if(x(E!=null,`Previous layout not found for panel index ${p}`),W(E,v)){const b=C-E;te(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}{const p=e<0?s:a,u=t[p];x(u,`No panel constraints found for index ${p}`);const{collapsedSize:v=0,collapsible:z,minSize:C=0}=u;if(z){const E=n[p];if(x(E!=null,`Previous layout not found for panel index ${p}`),W(E,C)){const b=E-v;te(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}}{const p=e<0?1:-1;let u=e<0?a:s,v=0;for(;;){const C=n[u];x(C!=null,`Previous layout not found for panel index ${u}`);const b=le({panelConstraints:t,panelIndex:u,size:100})-C;if(v+=b,u+=p,u<0||u>=t.length)break}const z=Math.min(Math.abs(e),Math.abs(v));e=e<0?0-z:z}{let u=e<0?s:a;for(;u>=0&&u<t.length;){const v=Math.abs(e)-Math.abs(h),z=n[u];x(z!=null,`Previous layout not found for panel index ${u}`);const C=z-v,E=le({panelConstraints:t,panelIndex:u,size:C});if(!W(z,E)&&(h+=z-E,l[u]=E,h.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?u--:u++}}if(Dn(i,l))return i;{const p=e<0?a:s,u=n[p];x(u!=null,`Previous layout not found for panel index ${p}`);const v=u+h,z=le({panelConstraints:t,panelIndex:p,size:v});if(l[p]=z,!W(z,v)){let C=v-z,b=e<0?a:s;for(;b>=0&&b<t.length;){const L=l[b];x(L!=null,`Previous layout not found for panel index ${b}`);const M=L+C,$=le({panelConstraints:t,panelIndex:b,size:M});if(W(L,$)||(C-=$-L,l[b]=$),W(C,0))break;e>0?b--:b++}}}const w=l.reduce((p,u)=>u+p,0);return W(w,100)?l:i}function Mn({layout:e,panelsArray:n,pivotIndices:t}){let r=0,i=100,o=0,l=0;const s=t[0];x(s!=null,"No pivot index found"),n.forEach((p,u)=>{const{constraints:v}=p,{maxSize:z=100,minSize:C=0}=v;u===s?(r=C,i=z):(o+=C,l+=z)});const a=Math.min(i,100-o),h=Math.max(r,100-l),w=e[s];return{valueMax:a,valueMin:h,valueNow:w}}function ze(e,n=document){return Array.from(n.querySelectorAll(`[${k.resizeHandleId}][data-panel-group-id="${e}"]`))}function ln(e,n,t=document){const i=ze(e,t).findIndex(o=>o.getAttribute(k.resizeHandleId)===n);return i??null}function sn(e,n,t){const r=ln(e,n,t);return r!=null?[r,r+1]:[-1,-1]}function an(e,n=document){var t;if(n instanceof HTMLElement&&(n==null||(t=n.dataset)===null||t===void 0?void 0:t.panelGroupId)==e)return n;const r=n.querySelector(`[data-panel-group][data-panel-group-id="${e}"]`);return r||null}function Ie(e,n=document){const t=n.querySelector(`[${k.resizeHandleId}="${e}"]`);return t||null}function Hn(e,n,t,r=document){var i,o,l,s;const a=Ie(n,r),h=ze(e,r),w=a?h.indexOf(a):-1,p=(i=(o=t[w])===null||o===void 0?void 0:o.id)!==null&&i!==void 0?i:null,u=(l=(s=t[w+1])===null||s===void 0?void 0:s.id)!==null&&l!==void 0?l:null;return[p,u]}function $n({committedValuesRef:e,eagerValuesRef:n,groupId:t,layout:r,panelDataArray:i,panelGroupElement:o,setLayout:l}){f.useRef({didWarnAboutMissingResizeHandle:!1}),ne(()=>{if(!o)return;const s=ze(t,o);for(let a=0;a<i.length-1;a++){const{valueMax:h,valueMin:w,valueNow:p}=Mn({layout:r,panelsArray:i,pivotIndices:[a,a+1]}),u=s[a];if(u!=null){const v=i[a];x(v,`No panel data found for index "${a}"`),u.setAttribute("aria-controls",v.id),u.setAttribute("aria-valuemax",""+Math.round(h)),u.setAttribute("aria-valuemin",""+Math.round(w)),u.setAttribute("aria-valuenow",p!=null?""+Math.round(p):"")}}return()=>{s.forEach((a,h)=>{a.removeAttribute("aria-controls"),a.removeAttribute("aria-valuemax"),a.removeAttribute("aria-valuemin"),a.removeAttribute("aria-valuenow")})}},[t,r,i,o]),f.useEffect(()=>{if(!o)return;const s=n.current;x(s,"Eager values not found");const{panelDataArray:a}=s,h=an(t,o);x(h!=null,`No group found for id "${t}"`);const w=ze(t,o);x(w,`No resize handles found for group id "${t}"`);const p=w.map(u=>{const v=u.getAttribute(k.resizeHandleId);x(v,"Resize handle element has no handle id attribute");const[z,C]=Hn(t,v,a,o);if(z==null||C==null)return()=>{};const E=b=>{if(!b.defaultPrevented)switch(b.key){case"Enter":{b.preventDefault();const L=a.findIndex(M=>M.id===z);if(L>=0){const M=a[L];x(M,`No panel data found for index ${L}`);const $=r[L],{collapsedSize:O=0,collapsible:R,minSize:P=0}=M.constraints;if($!=null&&R){const K=ge({delta:W($,O)?P-O:O-$,initialLayout:r,panelConstraints:a.map(J=>J.constraints),pivotIndices:sn(t,v,o),prevLayout:r,trigger:"keyboard"});r!==K&&l(K)}}break}}};return u.addEventListener("keydown",E),()=>{u.removeEventListener("keydown",E)}});return()=>{p.forEach(u=>u())}},[o,e,n,t,r,i,l])}function Ve(e,n){if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;return!0}function un(e,n){const t=e==="horizontal",{x:r,y:i}=Ee(n);return t?r:i}function Nn(e,n,t,r,i){const o=t==="horizontal",l=Ie(n,i);x(l,`No resize handle element found for id "${n}"`);const s=l.getAttribute(k.groupId);x(s,"Resize handle element has no group id attribute");let{initialCursorPosition:a}=r;const h=un(t,e),w=an(s,i);x(w,`No group element found for id "${s}"`);const p=w.getBoundingClientRect(),u=o?p.width:p.height;return(h-a)/u*100}function _n(e,n,t,r,i,o){if(je(e)){const l=t==="horizontal";let s=0;e.shiftKey?s=100:i!=null?s=i:s=10;let a=0;switch(e.key){case"ArrowDown":a=l?0:s;break;case"ArrowLeft":a=l?-s:0;break;case"ArrowRight":a=l?s:0;break;case"ArrowUp":a=l?0:-s;break;case"End":a=100;break;case"Home":a=-100;break}return a}else return r==null?0:Nn(e,n,t,r,o)}function Gn({panelDataArray:e}){const n=Array(e.length),t=e.map(o=>o.constraints);let r=0,i=100;for(let o=0;o<e.length;o++){const l=t[o];x(l,`Panel constraints not found for index ${o}`);const{defaultSize:s}=l;s!=null&&(r++,n[o]=s,i-=s)}for(let o=0;o<e.length;o++){const l=t[o];x(l,`Panel constraints not found for index ${o}`);const{defaultSize:s}=l;if(s!=null)continue;const a=e.length-r,h=i/a;r++,n[o]=h,i-=h}return n}function oe(e,n,t){n.forEach((r,i)=>{const o=e[i];x(o,`Panel data not found for index ${i}`);const{callbacks:l,constraints:s,id:a}=o,{collapsedSize:h=0,collapsible:w}=s,p=t[a];if(p==null||r!==p){t[a]=r;const{onCollapse:u,onExpand:v,onResize:z}=l;z&&z(r,p),w&&(u||v)&&(v&&(p==null||j(p,h))&&!j(r,h)&&v(),u&&(p==null||!j(p,h))&&j(r,h)&&u())}})}function ve(e,n){if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!=n[t])return!1;return!0}function Bn({defaultSize:e,dragState:n,layout:t,panelData:r,panelIndex:i,precision:o=3}){const l=t[i];let s;return l==null?s=e!=null?e.toPrecision(o):"1":r.length===1?s="1":s=l.toPrecision(o),{flexBasis:0,flexGrow:s,flexShrink:1,overflow:"hidden",pointerEvents:n!==null?"none":void 0}}function Tn(e,n=10){let t=null;return(...i)=>{t!==null&&clearTimeout(t),t=setTimeout(()=>{e(...i)},n)}}function Oe(e){try{if(typeof localStorage<"u")e.getItem=n=>localStorage.getItem(n),e.setItem=(n,t)=>{localStorage.setItem(n,t)};else throw new Error("localStorage not supported in this environment")}catch(n){console.error(n),e.getItem=()=>null,e.setItem=()=>{}}}function cn(e){return`react-resizable-panels:${e}`}function fn(e){return e.map(n=>{const{constraints:t,id:r,idIsFromProps:i,order:o}=n;return i?r:o?`${o}:${JSON.stringify(t)}`:JSON.stringify(t)}).sort((n,t)=>n.localeCompare(t)).join(",")}function dn(e,n){try{const t=cn(e),r=n.getItem(t);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function Fn(e,n,t){var r,i;const o=(r=dn(e,t))!==null&&r!==void 0?r:{},l=fn(n);return(i=o[l])!==null&&i!==void 0?i:null}function Wn(e,n,t,r,i){var o;const l=cn(e),s=fn(n),a=(o=dn(e,i))!==null&&o!==void 0?o:{};a[s]={expandToSizes:Object.fromEntries(t.entries()),layout:r};try{i.setItem(l,JSON.stringify(a))}catch(h){console.error(h)}}function qe({layout:e,panelConstraints:n}){const t=[...e],r=t.reduce((o,l)=>o+l,0);if(t.length!==n.length)throw Error(`Invalid ${n.length} panel layout: ${t.map(o=>`${o}%`).join(", ")}`);if(!W(r,100)&&t.length>0)for(let o=0;o<n.length;o++){const l=t[o];x(l!=null,`No layout data found for index ${o}`);const s=100/r*l;t[o]=s}let i=0;for(let o=0;o<n.length;o++){const l=t[o];x(l!=null,`No layout data found for index ${o}`);const s=le({panelConstraints:n,panelIndex:o,size:l});l!=s&&(i+=l-s,t[o]=s)}if(!W(i,0))for(let o=0;o<n.length;o++){const l=t[o];x(l!=null,`No layout data found for index ${o}`);const s=l+i,a=le({panelConstraints:n,panelIndex:o,size:s});if(l!==a&&(i-=a-l,t[o]=a,W(i,0)))break}return t}const Kn=100,me={getItem:e=>(Oe(me),me.getItem(e)),setItem:(e,n)=>{Oe(me),me.setItem(e,n)}},Xe={};function pn({autoSaveId:e=null,children:n,className:t="",direction:r,forwardedRef:i,id:o=null,onLayout:l=null,keyboardResizeBy:s=null,storage:a=me,style:h,tagName:w="div",...p}){const u=Ne(o),v=f.useRef(null),[z,C]=f.useState(null),[E,b]=f.useState([]),L=kn(),M=f.useRef({}),$=f.useRef(new Map),O=f.useRef(0),R=f.useRef({autoSaveId:e,direction:r,dragState:z,id:u,keyboardResizeBy:s,onLayout:l,storage:a}),P=f.useRef({layout:E,panelDataArray:[],panelDataArrayChanged:!1});f.useRef({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),f.useImperativeHandle(i,()=>({getId:()=>R.current.id,getLayout:()=>{const{layout:c}=P.current;return c},setLayout:c=>{const{onLayout:m}=R.current,{layout:S,panelDataArray:g}=P.current,d=qe({layout:c,panelConstraints:g.map(y=>y.constraints)});Ve(S,d)||(b(d),P.current.layout=d,m&&m(d),oe(g,d,M.current))}}),[]),ne(()=>{R.current.autoSaveId=e,R.current.direction=r,R.current.dragState=z,R.current.id=u,R.current.onLayout=l,R.current.storage=a}),$n({committedValuesRef:R,eagerValuesRef:P,groupId:u,layout:E,panelDataArray:P.current.panelDataArray,setLayout:b,panelGroupElement:v.current}),f.useEffect(()=>{const{panelDataArray:c}=P.current;if(e){if(E.length===0||E.length!==c.length)return;let m=Xe[e];m==null&&(m=Tn(Wn,Kn),Xe[e]=m);const S=[...c],g=new Map($.current);m(e,S,g,E,a)}},[e,E,a]),f.useEffect(()=>{});const K=f.useCallback(c=>{const{onLayout:m}=R.current,{layout:S,panelDataArray:g}=P.current;if(c.constraints.collapsible){const d=g.map(q=>q.constraints),{collapsedSize:y=0,panelSize:I,pivotIndices:H}=Q(g,c,S);if(x(I!=null,`Panel size not found for panel "${c.id}"`),!j(I,y)){$.current.set(c.id,I);const X=ie(g,c)===g.length-1?I-y:y-I,A=ge({delta:X,initialLayout:S,panelConstraints:d,pivotIndices:H,prevLayout:S,trigger:"imperative-api"});ve(S,A)||(b(A),P.current.layout=A,m&&m(A),oe(g,A,M.current))}}},[]),J=f.useCallback((c,m)=>{const{onLayout:S}=R.current,{layout:g,panelDataArray:d}=P.current;if(c.constraints.collapsible){const y=d.map(U=>U.constraints),{collapsedSize:I=0,panelSize:H=0,minSize:q=0,pivotIndices:X}=Q(d,c,g),A=m??q;if(j(H,I)){const U=$.current.get(c.id),de=U!=null&&U>=A?U:A,Re=ie(d,c)===d.length-1?H-de:de-H,T=ge({delta:Re,initialLayout:g,panelConstraints:y,pivotIndices:X,prevLayout:g,trigger:"imperative-api"});ve(g,T)||(b(T),P.current.layout=T,S&&S(T),oe(d,T,M.current))}}},[]),F=f.useCallback(c=>{const{layout:m,panelDataArray:S}=P.current,{panelSize:g}=Q(S,c,m);return x(g!=null,`Panel size not found for panel "${c.id}"`),g},[]),G=f.useCallback((c,m)=>{const{panelDataArray:S}=P.current,g=ie(S,c);return Bn({defaultSize:m,dragState:z,layout:E,panelData:S,panelIndex:g})},[z,E]),D=f.useCallback(c=>{const{layout:m,panelDataArray:S}=P.current,{collapsedSize:g=0,collapsible:d,panelSize:y}=Q(S,c,m);return x(y!=null,`Panel size not found for panel "${c.id}"`),d===!0&&j(y,g)},[]),Z=f.useCallback(c=>{const{layout:m,panelDataArray:S}=P.current,{collapsedSize:g=0,collapsible:d,panelSize:y}=Q(S,c,m);return x(y!=null,`Panel size not found for panel "${c.id}"`),!d||te(y,g)>0},[]),_=f.useCallback(c=>{const{panelDataArray:m}=P.current;m.push(c),m.sort((S,g)=>{const d=S.order,y=g.order;return d==null&&y==null?0:d==null?-1:y==null?1:d-y}),P.current.panelDataArrayChanged=!0,L()},[L]);ne(()=>{if(P.current.panelDataArrayChanged){P.current.panelDataArrayChanged=!1;const{autoSaveId:c,onLayout:m,storage:S}=R.current,{layout:g,panelDataArray:d}=P.current;let y=null;if(c){const H=Fn(c,d,S);H&&($.current=new Map(Object.entries(H.expandToSizes)),y=H.layout)}y==null&&(y=Gn({panelDataArray:d}));const I=qe({layout:y,panelConstraints:d.map(H=>H.constraints)});Ve(g,I)||(b(I),P.current.layout=I,m&&m(I),oe(d,I,M.current))}}),ne(()=>{const c=P.current;return()=>{c.layout=[]}},[]);const N=f.useCallback(c=>{let m=!1;const S=v.current;return S&&window.getComputedStyle(S,null).getPropertyValue("direction")==="rtl"&&(m=!0),function(d){d.preventDefault();const y=v.current;if(!y)return()=>null;const{direction:I,dragState:H,id:q,keyboardResizeBy:X,onLayout:A}=R.current,{layout:U,panelDataArray:de}=P.current,{initialLayout:xe}=H??{},Re=sn(q,c,y);let T=_n(d,c,I,H,X,y);const Be=I==="horizontal";Be&&m&&(T=-T);const gn=de.map(mn=>mn.constraints),pe=ge({delta:T,initialLayout:xe??U,panelConstraints:gn,pivotIndices:Re,prevLayout:U,trigger:je(d)?"keyboard":"mouse-or-touch"}),Te=!ve(U,pe);(Ye(d)||Ze(d))&&O.current!=T&&(O.current=T,!Te&&T!==0?Be?De(c,T<0?en:nn):De(c,T<0?tn:rn):De(c,0)),Te&&(b(pe),P.current.layout=pe,A&&A(pe),oe(de,pe,M.current))}},[]),B=f.useCallback((c,m)=>{const{onLayout:S}=R.current,{layout:g,panelDataArray:d}=P.current,y=d.map(U=>U.constraints),{panelSize:I,pivotIndices:H}=Q(d,c,g);x(I!=null,`Panel size not found for panel "${c.id}"`);const X=ie(d,c)===d.length-1?I-m:m-I,A=ge({delta:X,initialLayout:g,panelConstraints:y,pivotIndices:H,prevLayout:g,trigger:"imperative-api"});ve(g,A)||(b(A),P.current.layout=A,S&&S(A),oe(d,A,M.current))},[]),ae=f.useCallback((c,m)=>{const{layout:S,panelDataArray:g}=P.current,{collapsedSize:d=0,collapsible:y}=m,{collapsedSize:I=0,collapsible:H,maxSize:q=100,minSize:X=0}=c.constraints,{panelSize:A}=Q(g,c,S);A!=null&&(y&&H&&j(A,d)?j(d,I)||B(c,I):A<X?B(c,X):A>q&&B(c,q))},[B]),ue=f.useCallback((c,m)=>{const{direction:S}=R.current,{layout:g}=P.current;if(!v.current)return;const d=Ie(c,v.current);x(d,`Drag handle element not found for id "${c}"`);const y=un(S,m);C({dragHandleId:c,dragHandleRect:d.getBoundingClientRect(),initialCursorPosition:y,initialLayout:g})},[]),ce=f.useCallback(()=>{C(null)},[]),ye=f.useCallback(c=>{const{panelDataArray:m}=P.current,S=ie(m,c);S>=0&&(m.splice(S,1),delete M.current[c.id],P.current.panelDataArrayChanged=!0,L())},[L]),re=f.useMemo(()=>({collapsePanel:K,direction:r,dragState:z,expandPanel:J,getPanelSize:F,getPanelStyle:G,groupId:u,isPanelCollapsed:D,isPanelExpanded:Z,reevaluatePanelConstraints:ae,registerPanel:_,registerResizeHandle:N,resizePanel:B,startDragging:ue,stopDragging:ce,unregisterPanel:ye,panelGroupElement:v.current}),[K,z,r,J,F,G,u,D,Z,ae,_,N,B,ue,ce,ye]),fe={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return f.createElement(we.Provider,{value:re},f.createElement(w,{...p,children:n,className:t,id:o,ref:v,style:{...fe,...h},[k.group]:"",[k.groupDirection]:r,[k.groupId]:u}))}const Un=f.forwardRef((e,n)=>f.createElement(pn,{...e,forwardedRef:n}));pn.displayName="PanelGroup";Un.displayName="forwardRef(PanelGroup)";function ie(e,n){return e.findIndex(t=>t===n||t.id===n.id)}function Q(e,n,t){const r=ie(e,n),o=r===e.length-1?[r-1,r]:[r,r+1],l=t[r];return{...n.constraints,panelSize:l,pivotIndices:o}}function Vn({disabled:e,handleId:n,resizeHandler:t,panelGroupElement:r}){f.useEffect(()=>{if(e||t==null||r==null)return;const i=Ie(n,r);if(i==null)return;const o=l=>{if(!l.defaultPrevented)switch(l.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{l.preventDefault(),t(l);break}case"F6":{l.preventDefault();const s=i.getAttribute(k.groupId);x(s,`No group element found for id "${s}"`);const a=ze(s,r),h=ln(s,n,r);x(h!==null,`No resize element found for id "${n}"`);const w=l.shiftKey?h>0?h-1:a.length-1:h+1<a.length?h+1:0;a[w].focus();break}}};return i.addEventListener("keydown",o),()=>{i.removeEventListener("keydown",o)}},[r,e,n,t])}function On({children:e=null,className:n="",disabled:t=!1,hitAreaMargins:r,id:i,onBlur:o,onClick:l,onDragging:s,onFocus:a,onPointerDown:h,onPointerUp:w,style:p={},tabIndex:u=0,tagName:v="div",...z}){var C,E;const b=f.useRef(null),L=f.useRef({onClick:l,onDragging:s,onPointerDown:h,onPointerUp:w});f.useEffect(()=>{L.current.onClick=l,L.current.onDragging=s,L.current.onPointerDown=h,L.current.onPointerUp=w});const M=f.useContext(we);if(M===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:$,groupId:O,registerResizeHandle:R,startDragging:P,stopDragging:K,panelGroupElement:J}=M,F=Ne(i),[G,D]=f.useState("inactive"),[Z,_]=f.useState(!1),[N,B]=f.useState(null),ae=f.useRef({state:G});ne(()=>{ae.current.state=G}),f.useEffect(()=>{if(t)B(null);else{const re=R(F);B(()=>re)}},[t,F,R]);const ue=(C=r==null?void 0:r.coarse)!==null&&C!==void 0?C:15,ce=(E=r==null?void 0:r.fine)!==null&&E!==void 0?E:5;f.useEffect(()=>{if(t||N==null)return;const re=b.current;x(re,"Element ref not attached");let fe=!1;return Ln(F,re,$,{coarse:ue,fine:ce},(m,S,g)=>{if(!S){D("inactive");return}switch(m){case"down":{D("drag"),fe=!1,x(g,'Expected event to be defined for "down" action'),P(F,g);const{onDragging:d,onPointerDown:y}=L.current;d==null||d(!0),y==null||y();break}case"move":{const{state:d}=ae.current;fe=!0,d!=="drag"&&D("hover"),x(g,'Expected event to be defined for "move" action'),N(g);break}case"up":{D("hover"),K();const{onClick:d,onDragging:y,onPointerUp:I}=L.current;y==null||y(!1),I==null||I(),fe||d==null||d();break}}})},[ue,$,t,ce,R,F,N,P,K]),Vn({disabled:t,handleId:F,resizeHandler:N,panelGroupElement:J});const ye={touchAction:"none",userSelect:"none"};return f.createElement(v,{...z,children:e,className:n,id:i,onBlur:()=>{_(!1),o==null||o()},onFocus:()=>{_(!0),a==null||a()},ref:b,role:"separator",style:{...ye,...p},tabIndex:u,[k.groupDirection]:$,[k.groupId]:O,[k.resizeHandle]:"",[k.resizeHandleActive]:G==="drag"?"pointer":Z?"keyboard":void 0,[k.resizeHandleEnabled]:!t,[k.resizeHandleId]:F,[k.resizeHandleState]:G})}On.displayName="PanelResizeHandle";export{Un as P,xn as a,On as b};
@@ -1,4 +1,4 @@
1
- import{r as O}from"./icons-f1hlMKvD.js";var y={exports:{}},n={};/**
1
+ import{r as O}from"./icons-YJcunJnw.js";var y={exports:{}},n={};/**
2
2
  * @license React
3
3
  * react-dom.production.js
4
4
  *
@@ -1,4 +1,4 @@
1
- import{r as A,g as U,W as F}from"./icons-f1hlMKvD.js";var _={exports:{}},g={};/**
1
+ import{r as A,g as U,W as F}from"./icons-YJcunJnw.js";var _={exports:{}},g={};/**
2
2
  * @license React
3
3
  * use-sync-external-store-shim.production.js
4
4
  *
@@ -0,0 +1 @@
1
+ import{al as s,ah as r,F as l}from"./index-D1N4vQ9I.js";const o=[{code:"en",label:"English",short:"EN"},{code:"zh",label:"中文",short:"中"},{code:"ja",label:"日本語",short:"JA"},{code:"ko",label:"한국어",short:"KO"},{code:"fr",label:"Français",short:"FR"},{code:"de",label:"Deutsch",short:"DE"},{code:"es",label:"Español",short:"ES"},{code:"ru",label:"Русский",short:"RU"},{code:"pt",label:"Português",short:"PT"},{code:"it",label:"Italiano",short:"IT"}],a="dsc.stt.lang",c=new Set(o.map(t=>t.code));function n(t){const e=(t??"").trim().toLowerCase();return c.has(e)?e:null}function u(t){return n(t)??"en"}function g(t){return o.find(e=>e.code===t)??{code:"en",label:"English",short:"EN"}}function i(t){return(t??"").toLowerCase().startsWith("zh")?"zh":"en"}function d(){try{const e=n(localStorage.getItem(a));if(e)return e}catch{}let t=s;try{t=r(l.getState().language)}catch{}return i(t)}function S(t){try{localStorage.setItem(a,t)}catch{}}export{o as S,u as n,S as p,d as r,g as s};
@@ -12,13 +12,13 @@
12
12
  <meta name="theme-color" content="#0d1117" />
13
13
  <meta name="color-scheme" content="dark light" />
14
14
  <title>DeepSeekCode Web</title>
15
- <script type="module" crossorigin src="/assets/index-u1vYyqna.js"></script>
16
- <link rel="modulepreload" crossorigin href="/assets/icons-f1hlMKvD.js">
17
- <link rel="modulepreload" crossorigin href="/assets/markdown-DEtuzEyz.js">
18
- <link rel="modulepreload" crossorigin href="/assets/react-vendor-ClBKp0t-.js">
19
- <link rel="modulepreload" crossorigin href="/assets/state-xD58vmym.js">
20
- <link rel="modulepreload" crossorigin href="/assets/panels-Bn-2wCur.js">
21
- <link rel="stylesheet" crossorigin href="/assets/index-BCHbHIbw.css">
15
+ <script type="module" crossorigin src="/assets/index-D1N4vQ9I.js"></script>
16
+ <link rel="modulepreload" crossorigin href="/assets/icons-YJcunJnw.js">
17
+ <link rel="modulepreload" crossorigin href="/assets/markdown-CrVimah5.js">
18
+ <link rel="modulepreload" crossorigin href="/assets/react-vendor-DM-M1fu_.js">
19
+ <link rel="modulepreload" crossorigin href="/assets/state-D8omNTWe.js">
20
+ <link rel="modulepreload" crossorigin href="/assets/panels-BykQW6E1.js">
21
+ <link rel="stylesheet" crossorigin href="/assets/index-CtPliI0f.css">
22
22
  </head>
23
23
  <body>
24
24
  <div id="root"></div>
@@ -1 +0,0 @@
1
- import{j as e}from"./markdown-DEtuzEyz.js";import{a as r,au as j,h as N,L as v,be as w,b7 as S,b3 as k,aU as C,a9 as I,l as z}from"./icons-f1hlMKvD.js";import{u as g,a as y,a9 as A,aa as E}from"./index-u1vYyqna.js";import"./react-vendor-ClBKp0t-.js";import"./state-xD58vmym.js";import"./panels-Bn-2wCur.js";const R={idle:"bg-green-500",running:"bg-yellow-500 animate-pulse",paused:"bg-gray-500",error:"bg-red-500"};function q(d){return R[d]??"bg-gray-500"}const O=r.memo(function({onOpenSession:s,onNavigate:m}){const{t:a}=g(),[l,u]=r.useState([]),[n,c]=r.useState(!0),[p,h]=r.useState(null),[x,f]=r.useState(null),o=r.useCallback(async()=>{try{const t=await y.assistants.list();t.success&&Array.isArray(t.data)?(u(t.data),h(null)):h(t.error||a("assistants.loadFailed"))}catch(t){h(t instanceof Error?t.message:String(t))}finally{c(!1)}},[a]);r.useEffect(()=>{o();const t=window.setInterval(()=>{o()},8e3);return()=>window.clearInterval(t)},[o]);const b=r.useCallback(async(t,i)=>{(await y.assistants.update(t,i)).success&&o()},[o]);return e.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-dark-border px-4 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{size:16,className:"text-accent-blue","aria-hidden":"true"}),e.jsx("h2",{className:"text-sm font-semibold text-dark-text",children:a("assistants.title")}),!n&&e.jsx("span",{className:"rounded-full bg-dark-hover px-1.5 py-0.5 text-[10px] text-dark-muted",children:l.length})]}),e.jsxs("button",{type:"button",onClick:()=>void o(),className:"flex items-center gap-1 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-hover hover:text-dark-text",title:a("common.refresh"),children:[e.jsx(N,{size:12,className:n?"animate-spin":"","aria-hidden":"true"}),a("common.refresh")]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-3",children:n&&l.length===0?e.jsxs("div",{className:"flex items-center justify-center py-12 text-xs text-dark-muted",children:[e.jsx(v,{size:14,className:"mr-1.5 animate-spin","aria-hidden":"true"}),a("assistants.loading")]}):p&&l.length===0?e.jsx("div",{className:"py-8 text-center text-xs text-red-400",children:p}):l.length===0?e.jsxs("div",{className:"py-10 text-center text-xs text-dark-muted",children:[e.jsx(j,{size:24,className:"mx-auto mb-2 text-dark-muted","aria-hidden":"true"}),e.jsx("p",{children:a("assistants.empty")}),e.jsx("p",{className:"mt-1 text-[11px]",children:a("assistants.emptyHint")}),e.jsx("button",{type:"button",onClick:()=>m("channels"),className:"mt-3 rounded border border-dark-border px-2.5 py-1 text-[11px] text-dark-text hover:bg-dark-hover",children:a("assistants.goChannels")})]}):e.jsx("div",{className:"flex flex-col gap-2",children:l.map(t=>e.jsx(T,{assistant:t,expanded:x===t.sessionId,onToggleExpand:()=>f(x===t.sessionId?null:t.sessionId),onOpen:()=>s(t.sessionId,t.title),onUpdate:i=>void b(t.sessionId,i)},t.sessionId))})})]})}),T=r.memo(function({assistant:s,expanded:m,onToggleExpand:a,onOpen:l,onUpdate:u}){const{t:n}=g(),c=s.channel.peerKind==="group";return e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx("span",{className:"text-base leading-none","aria-hidden":"true",children:A(s.channel.type)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-dark-text",title:s.title,children:s.title}),e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${q(s.status)}`,title:n(`assistants.status.${s.status}`,{defaultValue:s.status})}),c?e.jsx(w,{size:11,className:"shrink-0 text-dark-muted","aria-label":n("assistants.group")}):e.jsx(S,{size:11,className:"shrink-0 text-dark-muted","aria-label":n("assistants.dm")})]}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-1.5 text-[10px] text-dark-muted",children:[e.jsx("span",{className:"shrink-0",children:E(s.channel.type)}),e.jsx("span",{className:"min-w-0 flex-1 truncate",title:s.channel.peerId,children:s.channel.peerId}),s.stats.unread>0&&e.jsx("span",{className:"shrink-0 rounded-full bg-red-500/80 px-1.5 text-[9px] font-medium text-white",children:s.stats.unread})]}),s.preview&&e.jsx("p",{className:"mt-1 line-clamp-2 text-[11px] leading-snug text-dark-muted",title:s.preview,children:s.preview})]}),e.jsx(U,{mode:s.mode}),s.trust.level==="owner"?e.jsx(k,{size:12,className:"shrink-0 text-green-500","aria-label":n("assistants.trust.owner")}):s.trust.level==="public"?e.jsx(C,{size:12,className:"shrink-0 text-yellow-600","aria-label":n("assistants.trust.public")}):e.jsx(k,{size:12,className:"shrink-0 text-accent-blue","aria-label":n("assistants.trust.team")})]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-t border-dark-border px-3 py-1.5",children:[e.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1 rounded px-2 py-0.5 text-[11px] text-accent-blue hover:bg-dark-hover",children:[e.jsx(I,{size:11,"aria-hidden":"true"}),n("assistants.openSession")]}),e.jsx("button",{type:"button",onClick:a,className:"flex items-center gap-1 rounded px-2 py-0.5 text-[11px] text-dark-muted hover:bg-dark-hover hover:text-dark-text",children:n("assistants.policy")}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-[10px] text-dark-muted",children:n("assistants.groupPolicy",{mention:String(c?s.policy.mentionRequired:!1)})})]}),m&&e.jsx(M,{assistant:s,isGroup:c,onUpdate:u})]})});function U({mode:d}){const{t:s}=g();return e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[9px] font-medium ${d==="delegate"?"bg-accent-blue/15 text-accent-blue":"bg-dark-hover text-dark-muted"}`,children:s(`assistants.mode.${d}`)})}function M({assistant:d,isGroup:s,onUpdate:m}){const{t:a}=g(),[l,u]=r.useState(d.mode),[n,c]=r.useState(d.policy.mentionRequired),[p,h]=r.useState(String(d.policy.cooldownSeconds)),[x,f]=r.useState((d.policy.keywords??[]).join(", ")),[o,b]=r.useState(!1),t=()=>{b(!0),m({mode:l,policy:{mentionRequired:s?n:!1,cooldownSeconds:Math.max(0,Number(p)||0),...x.trim()?{keywords:x.split(/[,,]/).map(i=>i.trim()).filter(Boolean)}:{}}}),window.setTimeout(()=>b(!1),600)};return e.jsxs("div",{className:"border-t border-dark-border px-3 py-2.5 text-[11px]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-dark-muted",children:[a("assistants.mode.label"),e.jsxs("select",{value:l,onChange:i=>u(i.target.value),className:"rounded border border-dark-border bg-dark-surface px-1.5 py-0.5 text-dark-text",children:[e.jsx("option",{value:"delegate",children:a("assistants.mode.delegate")}),e.jsx("option",{value:"direct",children:a("assistants.mode.direct")})]})]}),s&&e.jsxs("label",{className:"flex items-center gap-1.5 text-dark-muted",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:i=>c(i.target.checked)}),a("assistants.mentionRequired")]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-dark-muted",children:[a("assistants.cooldown"),e.jsx("input",{type:"number",min:0,value:p,onChange:i=>h(i.target.value),className:"w-14 rounded border border-dark-border bg-dark-surface px-1.5 py-0.5 text-dark-text"}),"s"]})]}),e.jsxs("label",{className:"mt-2 flex items-center gap-1.5 text-dark-muted",children:[a("assistants.keywords"),e.jsx("input",{type:"text",value:x,placeholder:a("assistants.keywordsPlaceholder")??"",onChange:i=>f(i.target.value),className:"min-w-0 flex-1 rounded border border-dark-border bg-dark-surface px-1.5 py-0.5 text-dark-text"})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsxs("button",{type:"button",onClick:t,disabled:o,className:"flex items-center gap-1 rounded bg-accent-blue px-2.5 py-1 text-[11px] font-medium text-white disabled:opacity-60",children:[o?e.jsx(v,{size:11,className:"animate-spin","aria-hidden":"true"}):e.jsx(z,{size:11,"aria-hidden":"true"}),a("common.save")]})})]})}export{O as AssistantsView};
@@ -1 +0,0 @@
1
- import{j as e}from"./markdown-DEtuzEyz.js";import{a as n,ay as v,h as $,aa as D,A as I,bp as L,f as O,aE as J,b2 as U,X as B}from"./icons-f1hlMKvD.js";import{u as M,ab as V}from"./index-u1vYyqna.js";import"./react-vendor-ClBKp0t-.js";import"./state-xD58vmym.js";import"./panels-Bn-2wCur.js";function Q(){const{t:a}=M(),{automations:r,runsByAutomation:d,fetchAutomations:o,createAutomation:N,deleteAutomation:y,toggleAutomation:w,runAutomation:C,fetchRuns:A,error:l}=V(),[S,x]=n.useState(!1),[m,P]=n.useState(null),[u,p]=n.useState(""),[h,b]=n.useState(""),[i,g]=n.useState("0 9 * * *"),[f,j]=n.useState("");n.useEffect(()=>{o()},[o]);const z=async t=>{const s=f.trim();if(!s)return;const[c,...T]=s.split(/\s+/),k=T.join(" ");c&&k&&(await fetch(`/api/automations/${encodeURIComponent(t)}/permissions`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tool:c,target:k})})).ok&&(j(""),await o())},E=async(t,s)=>{(await fetch(`/api/automations/${encodeURIComponent(t)}/permissions`,{method:"DELETE",headers:{"content-type":"application/json"},body:JSON.stringify({entry:s})})).ok&&await o()},R=async t=>{const s=m===t?null:t;P(s),s&&await A(t)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(v,{size:20,className:"text-accent-blue"}),a("automation.title"),e.jsxs("span",{className:"text-xs text-dark-muted font-normal",children:["(",r.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>void o(),className:"p-2 rounded-lg hover:bg-dark-hover text-dark-muted",title:a("automation.refresh"),children:e.jsx($,{size:16})}),e.jsxs("button",{onClick:()=>x(t=>!t),className:"flex items-center gap-1 px-3 py-1.5 rounded-lg bg-accent-blue/20 text-accent-blue hover:bg-accent-blue/30 text-sm font-medium",children:[e.jsx(D,{size:16})," ",a("automation.new")]})]})]}),l&&e.jsxs("div",{className:"mb-3 p-3 rounded-lg bg-accent-red/10 text-accent-red text-sm flex items-center gap-2",children:[e.jsx(I,{size:16})," ",l]}),S&&e.jsxs("div",{className:"mb-4 rounded-lg border border-dark-border bg-dark-surface p-4 space-y-3",children:[e.jsx("input",{value:u,onChange:t=>p(t.target.value),placeholder:a("automation.namePlaceholder"),className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue"}),e.jsx("textarea",{value:h,onChange:t=>b(t.target.value),placeholder:a("automation.instructionsPlaceholder"),rows:3,className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue resize-none"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:i,onChange:t=>g(t.target.value),placeholder:a("automation.cronPlaceholder"),className:"flex-1 px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue"}),e.jsx("button",{onClick:async()=>{await N({name:u,instructions:h,schedule:{kind:"cron",cron:i}})&&(p(""),b(""),x(!1))},className:"px-4 py-2 rounded-lg bg-accent-blue text-white text-sm font-medium hover:bg-accent-blue/80",children:a("automation.create")})]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:[["0 9 * * *",a("automation.cronDaily9")],["0 9 * * 1-5",a("automation.cronWeekday9")],["*/30 * * * *",a("automation.cronEvery30Min")]].map(([t,s])=>e.jsxs("button",{onClick:()=>g(t),className:`px-2 py-1 rounded text-xs ${i===t?"bg-accent-blue/20 text-accent-blue":"bg-dark-hover text-dark-muted hover:text-dark-text"}`,children:[s," (",t,")"]},t))})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2",children:[r.length===0&&e.jsx("p",{className:"text-dark-muted text-center py-8",children:a("automation.empty")}),r.map(t=>e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface",children:[e.jsxs("div",{className:"flex items-center justify-between p-3",children:[e.jsxs("button",{onClick:()=>void R(t.id),className:"flex items-center gap-2 min-w-0 text-left",children:[e.jsx(v,{size:16,className:"text-accent-blue shrink-0"}),e.jsx("span",{className:"font-medium text-sm truncate",children:t.name}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded shrink-0 ${t.status==="enabled"?"bg-accent-green/20 text-accent-green":"bg-dark-hover text-dark-muted"}`,children:t.status})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("span",{className:"text-xs text-dark-muted hidden lg:inline mr-1",children:[t.schedule.kind==="cron"?t.schedule.cron:t.schedule.fireAt,t.nextRunAt?` · ${new Date(t.nextRunAt).toLocaleString()}`:""]}),e.jsx("button",{onClick:()=>void w(t.id,t.status!=="enabled"),className:"p-1.5 rounded-lg hover:bg-dark-hover text-dark-muted",title:t.status==="enabled"?a("automation.disable"):a("automation.enable"),children:e.jsx(L,{size:15})}),e.jsx("button",{onClick:()=>void C(t.id),className:"p-1.5 rounded-lg hover:bg-dark-hover text-accent-green",title:a("automation.runNow"),children:e.jsx(O,{size:15})}),e.jsx("button",{onClick:()=>void y(t.id),className:"p-1.5 rounded-lg hover:bg-dark-hover text-accent-red",title:a("automation.delete"),children:e.jsx(J,{size:15})})]})]}),m===t.id&&e.jsxs("div",{className:"px-3 pb-3 space-y-3 border-t border-dark-border pt-3",children:[e.jsx("p",{className:"text-xs text-dark-muted whitespace-pre-wrap",children:t.instructions}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-semibold text-dark-muted mb-1 flex items-center gap-1",children:[e.jsx(U,{size:12})," ",a("automation.historyTitle")]}),(d[t.id]||[]).length===0&&e.jsx("p",{className:"text-xs text-dark-muted",children:a("automation.noRuns")}),(d[t.id]||[]).slice(0,10).map(s=>e.jsxs("div",{className:"flex items-center gap-2 text-xs py-1",children:[e.jsx("span",{className:`px-1.5 py-0.5 rounded ${s.status==="ok"?"bg-accent-green/20 text-accent-green":s.status==="error"?"bg-accent-red/20 text-accent-red":"bg-accent-yellow/20 text-accent-yellow"}`,children:s.status}),e.jsx("span",{className:"text-dark-muted",children:new Date(s.startedAt).toLocaleString()}),e.jsxs("span",{className:"text-dark-muted truncate flex-1",children:["#",s.id.slice(0,8)," · ",s.trigger]})]},s.id))]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-dark-muted mb-1",children:a("automation.permissionsTitle")}),t.permissions.length===0&&e.jsx("p",{className:"text-xs text-dark-muted",children:a("automation.permissionsEmpty")}),e.jsx("div",{className:"flex flex-wrap gap-1 mb-1",children:t.permissions.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded bg-accent-blue/10 text-accent-blue text-xs",children:[s,e.jsx("button",{onClick:()=>void E(t.id,s),className:"hover:text-accent-red",children:e.jsx(B,{size:12})})]},s))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:f,onChange:s=>j(s.target.value),placeholder:a("automation.permissionPlaceholder"),className:"flex-1 px-2 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-xs focus:outline-none focus:border-accent-blue"}),e.jsx("button",{onClick:()=>void z(t.id),className:"px-3 py-1.5 rounded-lg bg-dark-hover text-dark-muted hover:text-dark-text text-xs",children:a("automation.add")})]})]})]})]},t.id))]})]})}export{Q as AutomationView};
@@ -1 +0,0 @@
1
- import{j as s}from"./markdown-DEtuzEyz.js";import{a as c,L as w,A as q,ax as G,aa as pe,h as be,b1 as ge,bb as he,$ as I,at as fe,af as V,Q as H,S as M,am as je,b5 as D,aE as ve,a2 as Q,s as ke}from"./icons-f1hlMKvD.js";import{u as Ne,w as ye,a as p}from"./index-u1vYyqna.js";import"./react-vendor-ClBKp0t-.js";import"./state-xD58vmym.js";import"./panels-Bn-2wCur.js";const we={"code-intelligence":"🧠 代码智能",filesystem:"📂 文件系统",databases:"🗄️ 数据库","browser-automation":"🌐 浏览器自动化","knowledge-memory":"🧠 知识/记忆","search-web":"🔎 搜索/网页","cloud-platforms":"☁️ 云平台",communication:"💬 通讯","developer-tools":"🛠️ 开发者工具",security:"🔒 安全","test-demo":"🧪 测试/Demo",other:"📦 其他"};function Le({onNavigate:C}){const{t:n}=Ne(),[b,i]=c.useState([]),[Y,T]=c.useState(!0),[L,A]=c.useState(null),[S,m]=c.useState({}),[B,u]=c.useState(null),[E,W]=c.useState(""),[g,_]=c.useState(null),[z,J]=c.useState("all"),[X,j]=c.useState(null),[Z,P]=c.useState({}),[ee,$]=c.useState(!1),[o,x]=c.useState({name:"",command:"",args:"",env:"",transport:"stdio",url:"",headers:""}),[h,F]=c.useState(null),[R,v]=c.useState(!1),[U,f]=c.useState(null),se=async()=>{v(!0),f(null);try{const e=await p.tools.get("computer_use");F(e.success&&e.data?!!e.data.enabled:!1)}catch(e){f(e instanceof Error?e.message:String(e))}v(!1)},te=async()=>{if(h===null)return;const e=!h;v(!0),f(null);try{const t=await p.tools.toggle("computer_use",e);t.success?F(e):f(t.error||"切换 Computer Use 失败")}catch(t){f(t instanceof Error?t.message:String(t))}v(!1)},re=()=>x({name:"",command:"",args:"",env:"",transport:"stdio",url:"",headers:""}),K=e=>Object.fromEntries(e.split(",").map(t=>t.trim()).filter(Boolean).map(t=>{const a=t.indexOf("=");return a>0?[t.slice(0,a).trim(),t.slice(a+1).trim()]:[t,""]})),ae=async()=>{const e=o.transport!=="stdio";if(!o.name.trim()||!e&&!o.command.trim()||e&&!o.url.trim()){u(n("connectors.customFormRequired"));return}m(t=>({...t,__add:!0})),u(null);try{const t=await p.connectors.addCustom({name:o.name.trim(),command:e?void 0:o.command.trim(),args:e?void 0:o.args.split(/\s+/).filter(Boolean),env:K(o.env),url:e?o.url.trim():void 0,transport:e?o.transport:void 0,headers:e?K(o.headers):void 0});t.success&&t.data?(i(a=>[...a,t.data]),$(!1),re()):u(t.error||"添加失败")}catch(t){u(t instanceof Error?t.message:String(t))}finally{m(t=>({...t,__add:!1}))}},ne=async e=>{m(t=>({...t,[e.id]:!0}));try{const t=await p.connectors.removeCustom(e.id);t.success?i(a=>a.filter(r=>r.id!==e.id)):u(t.error||"删除失败")}finally{m(t=>({...t,[e.id]:!1}))}},k=async()=>{var t;T(!0),A(null);const e=await p.connectors.list();e.success&&Array.isArray((t=e.data)==null?void 0:t.connectors)?i(e.data.connectors):A(e.error||"加载连接器失败"),T(!1)};c.useEffect(()=>{k(),se()},[]),c.useEffect(()=>{let e=null;const t=r=>{if(!r||r.type!=="mcp_update")return;let l;try{l=typeof r.data=="string"?JSON.parse(r.data):r.data||{}}catch{return}const d=String(l.server||l.name||"");/^(managed|custom)-connector-/.test(d)&&(e&&clearTimeout(e),e=setTimeout(()=>{e=null,k()},150))},a=ye.onMessage(t);return()=>{e&&clearTimeout(e),a()}},[]);const N=(e,t,a,r)=>{u(a||null),i(l=>l.map(d=>d.id===e?{...d,enabled:!!r,status:"error"}:d))},le=async(e,t,a)=>{u(null),m(r=>({...r,[e.id]:!0})),i(r=>r.map(l=>l.id===e.id?{...l,enabled:t,status:t?"connecting":"installed"}:l));try{const r=await p.connectors.toggle(e.id,t,a);r.success&&r.data?i(l=>l.map(d=>d.id===e.id?r.data:d)):N(e.id,void 0,r.error||`切换 ${e.name} 失败`,!t)}catch(r){N(e.id,void 0,r instanceof Error?r.message:String(r),!t)}finally{m(r=>({...r,[e.id]:!1}))}},oe=e=>{var t,a;if(!e.enabled&&((t=e.requiresEnv)!=null&&t.length)&&((a=e.missingEnv)!=null&&a.length)){j(e.id);return}j(null),le(e,!e.enabled)},ce=async(e,t)=>{j(null),u(null),m(a=>({...a,[e.id]:!0})),i(a=>a.map(r=>r.id===e.id?{...r,enabled:!0,status:"connecting"}:r));try{const a=await p.connectors.connect(e.id,t);a.success&&a.data?(i(r=>r.map(l=>l.id===e.id?a.data:l)),P(r=>({...r,[e.id]:{}}))):N(e.id,void 0,a.error||`连接 ${e.name} 失败`,!1)}catch(a){N(e.id,void 0,a instanceof Error?a.message:String(a),!1)}finally{m(a=>({...a,[e.id]:!1}))}},de=e=>{const t="inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium";if(!e.installed)return s.jsxs("span",{className:`${t} bg-dark-hover text-dark-muted`,children:[s.jsx(Q,{size:12}),n("connectors.notInstalled")]});switch(e.status){case"ready":return s.jsxs("span",{className:`${t} bg-accent-green/15 text-accent-green`,children:[s.jsx(ke,{size:12}),n("connectors.ready")]});case"connecting":return s.jsxs("span",{className:`${t} bg-accent-blue/15 text-accent-blue`,children:[s.jsx(w,{size:12,className:"animate-spin"}),n("connectors.connecting")]});case"error":return s.jsxs("span",{className:`${t} bg-accent-red/15 text-accent-red`,children:[s.jsx(q,{size:12}),n("connectors.error")]});case"disabled":return s.jsx("span",{className:`${t} bg-dark-hover text-dark-muted`,children:n("connectors.disabled")});default:return s.jsx("span",{className:`${t} bg-dark-hover text-dark-muted`,children:n("connectors.installed")})}},y=b.filter(e=>z==="all"||e.kind===z),O=y.filter(e=>{if(E){const t=E.toLowerCase();if(![e.name,e.id,e.description,e.category??"",e.kind,...e.languages??[]].join(" ").toLowerCase().includes(t))return!1}return!(g&&e.category!==g)}).sort((e,t)=>e.enabled!==t.enabled?e.enabled?-1:1:e.name.localeCompare(t.name)),ie=[...new Set(y.map(e=>e.category).filter(Boolean))];if(Y)return s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx(w,{size:32,className:"animate-spin mx-auto mb-2 text-accent-blue"}),s.jsx("p",{className:"text-dark-muted",children:n("common.loading")})]})});if(L)return s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx(q,{size:32,className:"mx-auto mb-2 text-accent-red"}),s.jsx("p",{className:"text-accent-red mb-4",children:L}),s.jsx("button",{onClick:()=>void k(),className:"px-4 py-2 bg-accent-blue text-white rounded-lg",children:n("common.retry")})]})});const me=e=>{const t=Z[e.id]??{},a=(r,l)=>P(d=>({...d,[e.id]:{...d[e.id]??{},[r]:l}}));return s.jsxs("div",{className:"mt-3 pt-3 border-t border-dark-border",children:[s.jsxs("div",{className:"text-xs text-dark-muted mb-2 flex items-center gap-1",children:[s.jsx(D,{size:12}),n("connectors.needCredentials")]}),s.jsx("div",{className:"space-y-2",children:(e.requiresEnv??[]).map(r=>s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r.label}),s.jsx("input",{type:r.secret?"password":"text",value:t[r.key]??"",onChange:l=>a(r.key,l.target.value),placeholder:r.key,className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]},r.key))}),s.jsxs("div",{className:"flex gap-2 mt-2",children:[s.jsx("button",{onClick:()=>void ce(e,t),className:"px-3 py-1.5 bg-accent-blue text-white rounded-lg text-sm",children:n("connectors.connect")}),s.jsx("button",{onClick:()=>j(null),className:"px-3 py-1.5 bg-dark-surface border border-dark-border rounded-lg text-sm",children:n("common.cancel")})]})]})},ue=e=>{var r,l,d;const t=!!S[e.id],a=X===e.id;return s.jsxs("div",{className:`bg-dark-surface border border-dark-border rounded-lg p-4 transition-opacity ${e.enabled?"":"opacity-80"}`,children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[s.jsx("span",{className:`mt-0.5 shrink-0 px-2 py-1 rounded-md text-[11px] font-semibold uppercase ${e.kind==="lsp"?"bg-accent-purple/15 text-accent-purple":"bg-accent-green/15 text-accent-green"}`,children:e.kind==="lsp"?"LSP":"MCP"}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.jsx("span",{className:"font-medium text-sm truncate",children:e.name}),e.custom?s.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-purple/15 text-accent-purple",children:n("connectors.custom")}):null,e.official?s.jsxs("span",{title:"Official",className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-yellow/15 text-accent-yellow",children:["🎖️ ",n("connectors.official")]}):null,e.scope==="cloud"?s.jsxs("span",{title:"Cloud",className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/15 text-accent-blue",children:[s.jsx(H,{size:9}),n("connectors.cloud")]}):s.jsxs("span",{title:"Local",className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded bg-dark-hover text-dark-muted",children:[s.jsx(M,{size:9}),n("connectors.local")]}),e.language?s.jsx("span",{className:"text-[10px]",children:e.language}):null,de(e)]}),s.jsx("p",{className:"text-xs text-dark-muted mt-1 line-clamp-2",children:e.description}),s.jsxs("div",{className:"flex items-center gap-3 mt-2 text-[11px] text-dark-muted flex-wrap",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(M,{size:11}),s.jsx("code",{className:"text-[10px]",children:e.installHint})]}),e.transport&&e.transport!=="stdio"?s.jsxs("span",{className:"inline-flex items-center gap-1 text-accent-blue",children:[s.jsx(H,{size:11}),e.transport==="sse"?"SSE":"Streamable HTTP"]}):null,(r=e.languages)!=null&&r.length?s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(je,{size:11}),e.languages.join(", ")]}):null,e.kind==="mcp"&&e.toolCount!==void 0?s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(G,{size:11}),n("connectors.toolCount",{count:e.toolCount})]}):null,(l=e.requiresEnv)!=null&&l.length?s.jsxs("span",{className:"inline-flex items-center gap-1 text-accent-yellow",children:[s.jsx(D,{size:11}),(d=e.missingEnv)!=null&&d.length?`${e.missingEnv.join(", ")} ${n("connectors.missing")}`:n("connectors.envConfigured")]}):null,e.docsUrl?s.jsxs("a",{href:e.docsUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 hover:text-accent-blue",onClick:xe=>xe.stopPropagation(),children:[s.jsx(I,{size:11}),n("connectors.docs")]}):null]}),e.error?s.jsx("p",{className:"text-[11px] text-accent-red mt-1",children:e.error}):null]})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.custom?s.jsx("button",{onClick:()=>void ne(e),disabled:t,title:n("connectors.removeCustom"),className:"p-1.5 rounded-lg text-dark-muted hover:text-accent-red hover:bg-accent-red/10 transition-colors disabled:opacity-40",children:s.jsx(ve,{size:14})}):null,!e.installed&&e.enabled?s.jsxs("span",{className:"text-[11px] text-accent-blue flex items-center gap-1",children:[s.jsx(Q,{size:11,className:"animate-pulse"}),n("connectors.installing")]}):null,s.jsx("button",{role:"switch","aria-checked":e.enabled,disabled:t,onClick:()=>oe(e),className:`relative w-12 h-6 rounded-full transition-colors disabled:opacity-50 ${e.enabled?"bg-accent-green":"bg-dark-border"}`,children:s.jsx("span",{className:`absolute top-1 w-4 h-4 bg-white rounded-full transition-transform ${e.enabled?"left-7":"left-1"}`})})]})]}),a?me(e):null]},e.id)};return s.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[s.jsx(G,{size:20}),n("nav.connectors"),s.jsxs("span",{className:"text-sm font-normal text-dark-muted",children:["· ",b.filter(e=>e.enabled).length,"/",b.length]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("button",{onClick:()=>$(e=>!e),className:"flex items-center gap-2 px-3 py-1.5 bg-accent-blue text-white rounded hover:bg-accent-blue/90 transition-colors",children:[s.jsx(pe,{size:14}),n("connectors.addCustom")]}),s.jsxs("button",{onClick:()=>void k(),className:"flex items-center gap-2 px-3 py-1.5 bg-dark-surface border border-dark-border rounded hover:bg-dark-hover transition-colors",children:[s.jsx(be,{size:14}),n("common.refresh")]})]})]}),s.jsxs("div",{className:"mb-4 p-4 bg-dark-surface border border-dark-border rounded-lg space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-start gap-2",children:[s.jsx(ge,{size:16,className:"text-accent-blue mt-0.5 shrink-0"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-sm text-dark-text",children:"Computer Use"}),s.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:"GUI 截屏 + 鼠标键盘操控(Windows)。每次调用需审批;需要视觉模型读屏。"})]})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":!!h,disabled:R,onClick:()=>void te(),className:`relative w-9 h-5 rounded-full transition-colors shrink-0 disabled:opacity-50 ${h?"bg-accent-blue":"bg-dark-border"}`,children:R?s.jsx(w,{size:12,className:"absolute left-[7px] top-[3px] animate-spin text-white"}):s.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${h?"translate-x-[18px]":"translate-x-0.5"}`})})]}),s.jsxs("div",{className:"pt-3 border-t border-dark-border flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-start gap-2",children:[s.jsx(he,{size:16,className:"text-accent-yellow mt-0.5 shrink-0"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-sm text-dark-text",children:"xAI (Grok) API"}),s.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:"官方 OpenAI 兼容端点,支持 X 实时数据的 Grok 系列模型。"})]})]}),s.jsxs("button",{onClick:()=>C==null?void 0:C("models"),className:"flex items-center gap-1.5 px-3 py-1.5 bg-accent-blue/10 text-accent-blue border border-accent-blue/30 rounded-lg hover:bg-accent-blue/20 transition-colors text-xs shrink-0",children:["配置",s.jsx(I,{size:11})]})]}),U?s.jsx("div",{className:"text-xs text-accent-red bg-accent-red/10 border border-accent-red/30 rounded-lg px-3 py-2",children:U}):null]}),ee?s.jsxs("div",{className:"mb-4 p-4 bg-dark-surface border border-dark-border rounded-lg",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[s.jsx(fe,{size:15,className:"text-accent-purple"}),n("connectors.customTitle")]}),s.jsx("div",{className:"flex gap-1",children:[["stdio","🖥️ "+n("connectors.customLocal")],["http","🌐 HTTP"],["sse","📡 SSE"]].map(([e,t])=>s.jsx("button",{onClick:()=>x(a=>({...a,transport:e})),className:`px-3 py-1.5 rounded-lg text-xs transition-colors ${o.transport===e?"bg-accent-blue text-white":"bg-dark-bg border border-dark-border hover:bg-dark-hover"}`,children:t},e))})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:n("connectors.customName")}),s.jsx("input",{value:o.name,onChange:e=>x(t=>({...t,name:e.target.value})),placeholder:"my-server",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),o.transport==="stdio"?s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:n("connectors.customCommand")}),s.jsx("input",{value:o.command,onChange:e=>x(t=>({...t,command:e.target.value})),placeholder:"npx -y @some/mcp-server",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:n("connectors.customArgs")}),s.jsx("input",{value:o.args,onChange:e=>x(t=>({...t,args:e.target.value})),placeholder:"--arg value",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})]}):s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:n("connectors.customUrl")}),s.jsx("input",{value:o.url,onChange:e=>x(t=>({...t,url:e.target.value})),placeholder:"https://mcp.example.com/mcp",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),o.transport==="stdio"?s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:n("connectors.customEnv")}),s.jsx("input",{value:o.env,onChange:e=>x(t=>({...t,env:e.target.value})),placeholder:"KEY=value, KEY2=value2",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}):s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:n("connectors.customHeaders")}),s.jsx("input",{value:o.headers,onChange:e=>x(t=>({...t,headers:e.target.value})),placeholder:"Authorization=Bearer xxx",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})]}),s.jsxs("div",{className:"flex gap-2 mt-3",children:[s.jsx("button",{onClick:()=>void ae(),disabled:!!S.__add,className:"px-3 py-1.5 bg-accent-blue text-white rounded-lg text-sm disabled:opacity-50",children:S.__add?s.jsx(w,{size:14,className:"animate-spin"}):n("connectors.add")}),s.jsx("button",{onClick:()=>$(!1),className:"px-3 py-1.5 bg-dark-surface border border-dark-border rounded-lg text-sm",children:n("common.cancel")})]})]}):null,s.jsx("div",{className:"flex gap-1 mb-3",children:[["all",`${n("connectors.all")} (${b.length})`],["lsp",`LSP (${b.filter(e=>e.kind==="lsp").length})`],["mcp",`MCP (${b.filter(e=>e.kind==="mcp").length})`]].map(([e,t])=>s.jsx("button",{onClick:()=>J(e),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${z===e?"bg-accent-blue text-white":"bg-dark-surface border border-dark-border hover:bg-dark-hover"}`,children:t},e))}),s.jsx("div",{className:"flex gap-3 mb-3",children:s.jsxs("div",{className:"flex-1 relative",children:[s.jsx(V,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted"}),s.jsx("input",{type:"text",value:E,onChange:e=>W(e.target.value),placeholder:n("connectors.searchPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-dark-surface border border-dark-border rounded-lg text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})}),s.jsxs("div",{className:"flex gap-1 mb-4 flex-wrap",children:[s.jsxs("button",{onClick:()=>_(null),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${g?"bg-dark-surface border border-dark-border hover:bg-dark-hover":"bg-accent-blue text-white"}`,children:[n("connectors.all")," ",s.jsxs("span",{className:"opacity-70 text-xs",children:["(",y.length,")"]})]}),ie.map(e=>{const t=y.filter(a=>a.category===e).length;return s.jsxs("button",{onClick:()=>_(g===e?null:e),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${g===e?"bg-accent-blue text-white":"bg-dark-surface border border-dark-border hover:bg-dark-hover"}`,children:[we[e]??e," ",s.jsxs("span",{className:"opacity-70 text-xs",children:["(",t,")"]})]},e)})]}),B?s.jsx("div",{className:"mb-4 px-3 py-2 bg-accent-red/10 border border-accent-red/30 rounded-lg text-accent-red text-sm",children:B}):null,s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar",children:O.length===0?s.jsxs("div",{className:"text-center text-dark-muted text-sm py-10",children:[s.jsx(V,{size:24,className:"mx-auto mb-2 opacity-50"}),n("connectors.noResults")]}):s.jsx("div",{className:"space-y-2",children:O.map(ue)})})]})}export{Le as ConnectorsView};
@@ -1,11 +0,0 @@
1
- import{j as l}from"./markdown-DEtuzEyz.js";import{a as s,W as K,ar as Ce,aQ as Me,h as Ne,a_ as Te,af as ke,Z as le,l as Pe,a2 as ue,X as Ee,d as Re,ad as Fe,a$ as Le}from"./icons-f1hlMKvD.js";import{u as ze,a as B,t as F}from"./index-u1vYyqna.js";import"./react-vendor-ClBKp0t-.js";import"./state-xD58vmym.js";import"./panels-Bn-2wCur.js";function de(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Ae(e){if(Array.isArray(e))return e}function $e(e,t,r){return(t=We(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function De(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var n,o,u,p,v=[],g=!0,j=!1;try{if(u=(r=r.call(e)).next,t!==0)for(;!(g=(n=u.call(r)).done)&&(v.push(n.value),v.length!==t);g=!0);}catch(N){j=!0,o=N}finally{try{if(!g&&r.return!=null&&(p=r.return(),Object(p)!==p))return}finally{if(j)throw o}}return v}}function Ie(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
2
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function fe(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),r.push.apply(r,n)}return r}function pe(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?fe(Object(r),!0).forEach(function(n){$e(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):fe(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Ve(e,t){if(e==null)return{};var r,n,o=Ue(e,t);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)===-1&&{}.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function Ue(e,t){if(e==null)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(t.indexOf(n)!==-1)continue;r[n]=e[n]}return r}function He(e,t){return Ae(e)||De(e,t)||Be(e,t)||Ie()}function qe(e,t){if(typeof e!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var n=r.call(e,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function We(e){var t=qe(e,"string");return typeof t=="symbol"?t:t+""}function Be(e,t){if(e){if(typeof e=="string")return de(e,t);var r={}.toString.call(e).slice(8,-1);return r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set"?Array.from(e):r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?de(e,t):void 0}}function Qe(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function he(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),r.push.apply(r,n)}return r}function me(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?he(Object(r),!0).forEach(function(n){Qe(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):he(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Ke(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(n){return t.reduceRight(function(o,u){return u(o)},n)}}function G(e){return function t(){for(var r=this,n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];return o.length>=e.length?e.apply(this,o):function(){for(var p=arguments.length,v=new Array(p),g=0;g<p;g++)v[g]=arguments[g];return t.apply(r,[].concat(o,v))}}}function ne(e){return{}.toString.call(e).includes("Object")}function _e(e){return!Object.keys(e).length}function X(e){return typeof e=="function"}function Ge(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Je(e,t){return ne(t)||A("changeType"),Object.keys(t).some(function(r){return!Ge(e,r)})&&A("changeField"),t}function Xe(e){X(e)||A("selectorType")}function Ye(e){X(e)||ne(e)||A("handlerType"),ne(e)&&Object.values(e).some(function(t){return!X(t)})&&A("handlersType")}function Ze(e){e||A("initialIsRequired"),ne(e)||A("initialType"),_e(e)&&A("initialContent")}function et(e,t){throw new Error(e[t]||e.default)}var tt={initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"},A=G(et)(tt),te={changes:Je,selector:Xe,handler:Ye,initial:Ze};function rt(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};te.initial(e),te.handler(t);var r={current:e},n=G(it)(r,t),o=G(at)(r),u=G(te.changes)(e),p=G(nt)(r);function v(){var j=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(N){return N};return te.selector(j),j(r.current)}function g(j){Ke(n,o,u,p)(j)}return[v,g]}function nt(e,t){return X(t)?t(e.current):t}function at(e,t){return e.current=me(me({},e.current),t),t}function it(e,t,r){return X(t)?t(e.current):Object.keys(r).forEach(function(n){var o;return(o=t[n])===null||o===void 0?void 0:o.call(t,e.current[n])}),r}var ot={create:rt},st={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}};function ct(e){return function t(){for(var r=this,n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];return o.length>=e.length?e.apply(this,o):function(){for(var p=arguments.length,v=new Array(p),g=0;g<p;g++)v[g]=arguments[g];return t.apply(r,[].concat(o,v))}}}function lt(e){return{}.toString.call(e).includes("Object")}function ut(e){return e||ge("configIsRequired"),lt(e)||ge("configType"),e.urls?(dt(),{paths:{vs:e.urls.monacoBase}}):e}function dt(){console.warn(ve.deprecation)}function ft(e,t){throw new Error(e[t]||e.default)}var ve={configIsRequired:"the configuration object is required",configType:"the configuration object should be an object",default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
3
- You are using deprecated way of configuration.
4
-
5
- Instead of using
6
- monaco.config({ urls: { monacoBase: '...' } })
7
- use
8
- monaco.config({ paths: { vs: '...' } })
9
-
10
- For more please check the link https://github.com/suren-atoyan/monaco-loader#config
11
- `},ge=ct(ft)(ve),pt={config:ut},ht=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return function(o){return r.reduceRight(function(u,p){return p(u)},o)}};function be(e,t){return Object.keys(t).forEach(function(r){t[r]instanceof Object&&e[r]&&Object.assign(t[r],be(e[r],t[r]))}),pe(pe({},e),t)}var mt={type:"cancelation",msg:"operation is manually canceled"};function oe(e){var t=!1,r=new Promise(function(n,o){e.then(function(u){return t?o(mt):n(u)}),e.catch(o)});return r.cancel=function(){return t=!0},r}var gt=["monaco"],vt=ot.create({config:st,isInitialized:!1,resolve:null,reject:null,monaco:null}),ye=He(vt,2),Y=ye[0],ae=ye[1];function bt(e){var t=pt.config(e),r=t.monaco,n=Ve(t,gt);ae(function(o){return{config:be(o.config,n),monaco:r}})}function yt(){var e=Y(function(t){var r=t.monaco,n=t.isInitialized,o=t.resolve;return{monaco:r,isInitialized:n,resolve:o}});if(!e.isInitialized){if(ae({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),oe(se);if(window.monaco&&window.monaco.editor)return xe(window.monaco),e.resolve(window.monaco),oe(se);ht(xt,wt)(Ot)}return oe(se)}function xt(e){return document.body.appendChild(e)}function jt(e){var t=document.createElement("script");return e&&(t.src=e),t}function wt(e){var t=Y(function(n){var o=n.config,u=n.reject;return{config:o,reject:u}}),r=jt("".concat(t.config.paths.vs,"/loader.js"));return r.onload=function(){return e()},r.onerror=t.reject,r}function Ot(){var e=Y(function(r){var n=r.config,o=r.resolve,u=r.reject;return{config:n,resolve:o,reject:u}}),t=window.require;t.config(e.config),t(["vs/editor/editor.main"],function(r){var n=r.m||r;xe(n),e.resolve(n)},function(r){e.reject(r)})}function xe(e){Y().monaco||ae({monaco:e})}function St(){return Y(function(e){var t=e.monaco;return t})}var se=new Promise(function(e,t){return ae({resolve:e,reject:t})}),je={config:bt,init:yt,__getMonacoInstance:St},Ct={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},ce=Ct,Mt={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},Nt=Mt;function Tt({children:e}){return K.createElement("div",{style:Nt.container},e)}var kt=Tt,Pt=kt;function Et({width:e,height:t,isEditorReady:r,loading:n,_ref:o,className:u,wrapperProps:p}){return K.createElement("section",{style:{...ce.wrapper,width:e,height:t},...p},!r&&K.createElement(Pt,null,n),K.createElement("div",{ref:o,style:{...ce.fullWidth,...!r&&ce.hide},className:u}))}var Rt=Et,we=s.memo(Rt);function Ft(e){s.useEffect(e,[])}var Oe=Ft;function Lt(e,t,r=!0){let n=s.useRef(!0);s.useEffect(n.current||!r?()=>{n.current=!1}:e,t)}var M=Lt;function J(){}function Q(e,t,r,n){return zt(e,n)||At(e,t,r,n)}function zt(e,t){return e.editor.getModel(Se(e,t))}function At(e,t,r,n){return e.editor.createModel(t,r,n?Se(e,n):void 0)}function Se(e,t){return e.Uri.parse(t)}function $t({original:e,modified:t,language:r,originalLanguage:n,modifiedLanguage:o,originalModelPath:u,modifiedModelPath:p,keepCurrentOriginalModel:v=!1,keepCurrentModifiedModel:g=!1,theme:j="light",loading:N="Loading...",options:C={},height:_="100%",width:I="100%",className:V,wrapperProps:U={},beforeMount:H=J,onMount:q=J}){let[w,T]=s.useState(!1),[E,y]=s.useState(!0),x=s.useRef(null),b=s.useRef(null),L=s.useRef(null),O=s.useRef(q),h=s.useRef(H),R=s.useRef(!1);Oe(()=>{let d=je.init();return d.then(m=>(b.current=m)&&y(!1)).catch(m=>(m==null?void 0:m.type)!=="cancelation"&&console.error("Monaco initialization: error:",m)),()=>x.current?D():d.cancel()}),M(()=>{if(x.current&&b.current){let d=x.current.getOriginalEditor(),m=Q(b.current,e||"",n||r||"text",u||"");m!==d.getModel()&&d.setModel(m)}},[u],w),M(()=>{if(x.current&&b.current){let d=x.current.getModifiedEditor(),m=Q(b.current,t||"",o||r||"text",p||"");m!==d.getModel()&&d.setModel(m)}},[p],w),M(()=>{let d=x.current.getModifiedEditor();d.getOption(b.current.editor.EditorOption.readOnly)?d.setValue(t||""):t!==d.getValue()&&(d.executeEdits("",[{range:d.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),d.pushUndoStop())},[t],w),M(()=>{var d,m;(m=(d=x.current)==null?void 0:d.getModel())==null||m.original.setValue(e||"")},[e],w),M(()=>{let{original:d,modified:m}=x.current.getModel();b.current.editor.setModelLanguage(d,n||r||"text"),b.current.editor.setModelLanguage(m,o||r||"text")},[r,n,o],w),M(()=>{var d;(d=b.current)==null||d.editor.setTheme(j)},[j],w),M(()=>{var d;(d=x.current)==null||d.updateOptions(C)},[C],w);let $=s.useCallback(()=>{var k;if(!b.current)return;h.current(b.current);let d=Q(b.current,e||"",n||r||"text",u||""),m=Q(b.current,t||"",o||r||"text",p||"");(k=x.current)==null||k.setModel({original:d,modified:m})},[r,t,o,e,n,u,p]),W=s.useCallback(()=>{var d;!R.current&&L.current&&(x.current=b.current.editor.createDiffEditor(L.current,{automaticLayout:!0,...C}),$(),(d=b.current)==null||d.editor.setTheme(j),T(!0),R.current=!0)},[C,j,$]);s.useEffect(()=>{w&&O.current(x.current,b.current)},[w]),s.useEffect(()=>{!E&&!w&&W()},[E,w,W]);function D(){var m,k,P,z;let d=(m=x.current)==null?void 0:m.getModel();v||((k=d==null?void 0:d.original)==null||k.dispose()),g||((P=d==null?void 0:d.modified)==null||P.dispose()),(z=x.current)==null||z.dispose()}return K.createElement(we,{width:I,height:_,isEditorReady:w,loading:N,_ref:L,className:V,wrapperProps:U})}var Dt=$t;s.memo(Dt);function It(e){let t=s.useRef();return s.useEffect(()=>{t.current=e},[e]),t.current}var Vt=It,re=new Map;function Ut({defaultValue:e,defaultLanguage:t,defaultPath:r,value:n,language:o,path:u,theme:p="light",line:v,loading:g="Loading...",options:j={},overrideServices:N={},saveViewState:C=!0,keepCurrentModel:_=!1,width:I="100%",height:V="100%",className:U,wrapperProps:H={},beforeMount:q=J,onMount:w=J,onChange:T,onValidate:E=J}){let[y,x]=s.useState(!1),[b,L]=s.useState(!0),O=s.useRef(null),h=s.useRef(null),R=s.useRef(null),$=s.useRef(w),W=s.useRef(q),D=s.useRef(),d=s.useRef(n),m=Vt(u),k=s.useRef(!1),P=s.useRef(!1);Oe(()=>{let a=je.init();return a.then(i=>(O.current=i)&&L(!1)).catch(i=>(i==null?void 0:i.type)!=="cancelation"&&console.error("Monaco initialization: error:",i)),()=>h.current?ie():a.cancel()}),M(()=>{var i,c,f,S;let a=Q(O.current,e||n||"",t||o||"",u||r||"");a!==((i=h.current)==null?void 0:i.getModel())&&(C&&re.set(m,(c=h.current)==null?void 0:c.saveViewState()),(f=h.current)==null||f.setModel(a),C&&((S=h.current)==null||S.restoreViewState(re.get(u))))},[u],y),M(()=>{var a;(a=h.current)==null||a.updateOptions(j)},[j],y),M(()=>{!h.current||n===void 0||(h.current.getOption(O.current.editor.EditorOption.readOnly)?h.current.setValue(n):n!==h.current.getValue()&&(P.current=!0,h.current.executeEdits("",[{range:h.current.getModel().getFullModelRange(),text:n,forceMoveMarkers:!0}]),h.current.pushUndoStop(),P.current=!1))},[n],y),M(()=>{var i,c;let a=(i=h.current)==null?void 0:i.getModel();a&&o&&((c=O.current)==null||c.editor.setModelLanguage(a,o))},[o],y),M(()=>{var a;v!==void 0&&((a=h.current)==null||a.revealLine(v))},[v],y),M(()=>{var a;(a=O.current)==null||a.editor.setTheme(p)},[p],y);let z=s.useCallback(()=>{var a;if(!(!R.current||!O.current)&&!k.current){W.current(O.current);let i=u||r,c=Q(O.current,n||e||"",t||o||"",i||"");h.current=(a=O.current)==null?void 0:a.editor.create(R.current,{model:c,automaticLayout:!0,...j},N),C&&h.current.restoreViewState(re.get(i)),O.current.editor.setTheme(p),v!==void 0&&h.current.revealLine(v),x(!0),k.current=!0}},[e,t,r,n,o,u,j,N,C,p,v]);s.useEffect(()=>{y&&$.current(h.current,O.current)},[y]),s.useEffect(()=>{!b&&!y&&z()},[b,y,z]),d.current=n,s.useEffect(()=>{var a,i;y&&T&&((a=D.current)==null||a.dispose(),D.current=(i=h.current)==null?void 0:i.onDidChangeModelContent(c=>{P.current||T(h.current.getValue(),c)}))},[y,T]),s.useEffect(()=>{if(y){let a=O.current.editor.onDidChangeMarkers(i=>{var f;let c=(f=h.current.getModel())==null?void 0:f.uri;if(c&&i.find(S=>S.path===c.path)){let S=O.current.editor.getModelMarkers({resource:c});E==null||E(S)}});return()=>{a==null||a.dispose()}}return()=>{}},[y,E]);function ie(){var a,i;(a=D.current)==null||a.dispose(),_?C&&re.set(u,h.current.saveViewState()):(i=h.current.getModel())==null||i.dispose(),h.current.dispose()}return K.createElement(we,{width:I,height:V,isEditorReady:y,loading:g,_ref:R,className:U,wrapperProps:H})}var Ht=Ut,qt=s.memo(Ht),Wt=qt;function Bt(e){var n;const t=(n=e.split(".").pop())==null?void 0:n.toLowerCase();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"}[t||""]||"plaintext"}function Yt(){const{t:e}=ze(),[t,r]=s.useState([]),[n,o]=s.useState(null),[u,p]=s.useState(""),[v,g]=s.useState(""),[j,N]=s.useState(!1),[C,_]=s.useState(""),[I,V]=s.useState(!1),[U,H]=s.useState(!1),[q,w]=s.useState(!1),[T,E]=s.useState(""),y=s.useRef(null);s.useEffect(()=>{if(!n){p(""),g("");return}N(!0),B.files.read(n).then(a=>{if(a.success&&a.data){const i=typeof a.data=="string"?a.data:JSON.stringify(a.data);p(i),g(i)}else F.error(a.error||e("fileTree.readFail"))}).catch(()=>F.error(e("fileTree.readFail"))).finally(()=>N(!1))},[n]);const x=async a=>{V(!0);try{const i=await B.files.list(a);i.success&&Array.isArray(i.data)&&r(i.data.map(c=>({...c,expanded:!1})))}finally{V(!1)}},b=async a=>{if(a.type==="directory")try{const i=await B.files.list(a.path);if(i.success&&Array.isArray(i.data)){const c=i.data.map(f=>({...f,expanded:!1}));r(f=>L(f,a.id,c))}}catch{}},L=(a,i,c)=>a.map(f=>f.id===i?{...f,children:c,expanded:!0}:f.children?{...f,children:L(f.children,i,c)}:f);s.useEffect(()=>{x()},[]);const O=a=>{const i=R(t,a);if(i&&i.type==="directory"&&!i.children){b(i);return}r(c=>h(c,a))},h=(a,i)=>a.map(c=>c.id===i&&c.type==="directory"?{...c,expanded:!c.expanded}:c.children?{...c,children:h(c.children,i)}:c),R=(a,i)=>{for(const c of a){if(c.id===i)return c;if(c.children){const f=R(c.children,i);if(f)return f}}return null},$=(a,i)=>i?a.reduce((c,f)=>{if(f.name.toLowerCase().includes(i.toLowerCase()))c.push(f);else if(f.children){const S=$(f.children,i);S.length>0&&c.push({...f,children:S,expanded:!0})}return c},[]):a,W=s.useCallback(async()=>{if(n){H(!0);try{const a=await B.files.update(n,u);a.success?(g(u),F.success(e("fileTree.saved"))):F.error(a.error||e("fileTree.saveFail"))}catch{F.error(e("fileTree.saveFail"))}finally{H(!1)}}},[n,u,e]),D=()=>{o(null),p(""),g("")},d=s.useCallback(async a=>{const i=await B.files.download(a);i.success?F.success(e("fileTree.downloadStarted")):F.error(i.error||e("fileTree.downloadFail"))},[e]),m=()=>{var a;return(a=y.current)==null?void 0:a.click()},k=s.useCallback(async a=>{if(!a||a.length===0)return;const i=T||(n?n.replace(/[\\/][^\\/]+$/,""):"");w(!0);let c=0,f=0;for(const S of Array.from(a)){const Z=i?`${i}/${S.name}`:S.name;(await B.files.upload(S,Z)).success?c++:f++}w(!1),c>0&&F.success(e("fileTree.uploadedCount",{count:c})),f>0&&F.error(e("fileTree.uploadFailedCount",{count:f})),await x()},[T,n,e]),P=u!==v,z=(a,i=0)=>{var Z;const c=a.type==="directory",f=n===a.path,S=T===a.path;return l.jsxs("div",{children:[l.jsxs("div",{className:`group flex items-center gap-1 px-2 py-0.5 cursor-pointer rounded text-xs transition-colors ${f?"bg-accent-blue/20 text-accent-blue":S?"bg-accent-blue/10":"hover:bg-dark-hover"}`,style:{paddingLeft:`${i*14+6}px`},onClick:()=>c?(E(a.path),O(a.id)):o(a.path),title:c?e("fileTree.setUploadDirHint"):a.path,children:[c&&l.jsx("span",{className:"text-dark-muted shrink-0",children:a.expanded?l.jsx(Re,{size:12}):l.jsx(Fe,{size:12})}),c?l.jsx(Le,{size:12,className:"text-accent-yellow shrink-0"}):l.jsx("span",{className:"w-3"}),l.jsx("span",{className:"truncate flex-1",children:a.name}),!c&&l.jsx("button",{onClick:ee=>{ee.stopPropagation(),d(a.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",title:e("fileTree.download"),children:l.jsx(ue,{size:11})})]}),c&&a.expanded&&((Z=a.children)==null?void 0:Z.map(ee=>z(ee,i+1)))]},a.id)},ie=C?$(t,C):t;return l.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[l.jsxs("div",{className:"w-64 shrink-0 flex flex-col overflow-hidden border-r border-dark-border",children:[l.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-dark-border",children:[l.jsxs("h2",{className:"text-xs font-semibold flex items-center gap-1.5",children:[l.jsx(Ce,{size:14}),e("fileTree.title")]}),l.jsxs("div",{className:"flex items-center gap-0.5",children:[l.jsx("button",{onClick:m,disabled:q,className:"p-1 rounded hover:bg-dark-hover disabled:opacity-50",title:T?e("fileTree.uploadTo",{dir:T}):e("fileTree.uploadToRoot"),children:l.jsx(Me,{size:12,className:q?"animate-pulse":""})}),l.jsx("button",{onClick:()=>x(),disabled:I,className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.refresh"),children:l.jsx(Ne,{size:12,className:I?"animate-spin":""})}),l.jsx("button",{onClick:()=>{r(t.map(a=>({...a,expanded:!1}))),o(null)},className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.collapse"),children:l.jsx(Te,{size:12})})]})]}),l.jsx("div",{className:"p-1.5 border-b border-dark-border",children:l.jsxs("div",{className:"relative",children:[l.jsx(ke,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),l.jsx("input",{type:"text",value:C,onChange:a=>_(a.target.value),placeholder:e("fileTree.searchPlaceholder"),className:"w-full pl-6 pr-2 py-1 text-xs bg-dark-bg border border-dark-border rounded focus:border-accent-blue focus:outline-none"})]})}),l.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar py-1",children:ie.map(a=>z(a))}),l.jsx("input",{ref:y,type:"file",multiple:!0,className:"hidden",onChange:a=>{k(a.target.files),a.currentTarget.value=""}})]}),l.jsx("div",{className:"flex-1 flex flex-col min-w-0 bg-dark-bg",children:n?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-dark-border bg-dark-surface",children:[l.jsxs("div",{className:"flex items-center gap-2 text-xs min-w-0",children:[l.jsx(le,{size:12,className:"text-dark-muted shrink-0"}),l.jsx("span",{className:"truncate",children:n}),P&&l.jsxs("span",{className:"text-accent-yellow text-[10px] shrink-0",children:["● ",e("fileTree.modified")]})]}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsxs("button",{onClick:W,disabled:!P||U,className:`px-2 py-0.5 text-[10px] rounded flex items-center gap-1 transition-colors ${P?"bg-accent-green text-white hover:opacity-90":"bg-dark-border text-dark-muted cursor-not-allowed"}`,children:[l.jsx(Pe,{size:10}),e(U?"fileTree.saving":"fileTree.save")]}),l.jsx("button",{onClick:()=>void d(n),className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.download"),children:l.jsx(ue,{size:12})}),l.jsx("button",{onClick:D,className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.close"),children:l.jsx(Ee,{size:12})})]})]}),l.jsx("div",{className:"flex-1 min-h-0",children:j?l.jsx("div",{className:"flex items-center justify-center h-full",children:l.jsx("div",{className:"w-4 h-4 border-2 border-accent-blue border-t-transparent rounded-full animate-spin"})}):l.jsx(Wt,{language:Bt(n),value:u,onChange:a=>p(a||""),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}})})]}):l.jsx("div",{className:"flex-1 flex items-center justify-center",children:l.jsxs("div",{className:"text-center",children:[l.jsx(le,{size:32,className:"text-dark-muted mx-auto mb-2"}),l.jsx("p",{className:"text-sm text-dark-muted",children:e("fileTree.selectFileHint")})]})})})]})}export{Yt as FileTreeView,Yt as default};
@@ -1 +0,0 @@
1
- import{j as e}from"./markdown-DEtuzEyz.js";import{a as y,aX as L,p as D,aY as Y,aE as B,X as z,f as G,a4 as J,ad as W,aZ as _,aL as q,aM as X,h as Q,aQ as V,a2 as Z,aa as K}from"./icons-f1hlMKvD.js";import{c as ee}from"./state-xD58vmym.js";import{a as j,u as E}from"./index-u1vYyqna.js";import"./react-vendor-ClBKp0t-.js";import"./panels-Bn-2wCur.js";const P=ee((l,d)=>({rules:[],stats:null,events:[],agents:[],loading:!1,error:null,fieldErrors:null,formOpen:!1,editingRule:null,dryRunResult:null,loadRules:async()=>{const t=await j.hooks.list();t.success&&Array.isArray(t.data)?l({rules:t.data}):t.success&&t.data&&!Array.isArray(t.data)?l({error:"服务端返回的规则数据格式异常"}):l({error:t.error||"Failed to load rules"})},loadStats:async()=>{const t=await j.hooks.stats();t.success&&t.data&&l({stats:t.data})},loadEvents:async()=>{const t=await j.hooks.events();t.success&&Array.isArray(t.data)?l({events:t.data}):t.success&&t.data&&!Array.isArray(t.data)&&l({error:"服务端返回的事件数据格式异常"})},loadAgents:async()=>{const t=await j.hooks.agents();t.success&&Array.isArray(t.data)?l({agents:t.data}):t.success&&t.data&&!Array.isArray(t.data)&&l({error:"服务端返回的Agent数据格式异常"})},loadAll:async()=>{l({loading:!0,error:null});try{await Promise.all([d().loadRules(),d().loadStats(),d().loadEvents(),d().loadAgents()])}catch(t){l({error:String(t)})}finally{l({loading:!1})}},createRule:async t=>{l({fieldErrors:null});const r=await j.hooks.create(t);if(r.success)return await d().loadRules(),await d().loadStats(),l({formOpen:!1,editingRule:null}),!0;if(r.error){l({error:r.error});try{const c=JSON.parse(r.error);c.fieldErrors&&l({fieldErrors:c.fieldErrors})}catch{}}return!1},updateRule:async(t,r)=>{l({fieldErrors:null});const c=await j.hooks.update(t,r);return c.success?(await d().loadRules(),l({formOpen:!1,editingRule:null}),!0):(l({error:c.error||"Update failed"}),!1)},deleteRule:async t=>{const r=await j.hooks.delete(t);return r.success?(await d().loadRules(),await d().loadStats(),!0):(l({error:r.error||"Delete failed"}),!1)},batchDelete:async t=>{const r=await j.hooks.batchDelete(t);return r.success?(await d().loadRules(),await d().loadStats(),!0):(l({error:r.error||"Batch delete failed"}),!1)},toggleRule:async(t,r)=>(await j.hooks.toggle(t,r)).success?(l(x=>({rules:x.rules.map(p=>p.name===t?{...p,enabled:r}:p)})),!0):(await d().loadRules(),!1),batchToggle:async(t,r)=>(await j.hooks.batchToggle(t,r)).success?(l(x=>({rules:x.rules.map(p=>t.includes(p.name)?{...p,enabled:r}:p)})),!0):(await d().loadRules(),!1),dryRun:async t=>{const r=await j.hooks.dryRun(t);return r.success&&r.data?(l({dryRunResult:r.data}),r.data):(l({error:r.error||"Dry-run failed"}),null)},openForm:t=>l({formOpen:!0,editingRule:t||null,dryRunResult:null,fieldErrors:null}),closeForm:()=>l({formOpen:!1,editingRule:null,dryRunResult:null,fieldErrors:null}),setDryRunResult:t=>l({dryRunResult:t}),clearError:()=>l({error:null}),clearFieldErrors:()=>l({fieldErrors:null})})),te={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"},ae={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 se({rules:l,onEdit:d}){const{t}=E(),{toggleRule:r,deleteRule:c,batchDelete:x,batchToggle:p}=P(),[k,b]=y.useState(new Set),[R,v]=y.useState(!1),T=Array.isArray(l)?l:[];if(T.length===0)return e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 py-16 text-dark-muted",children:[e.jsx("div",{className:"text-4xl opacity-60",children:"🪝"}),e.jsx("p",{className:"text-sm",children:t("hook.noRules")}),e.jsx("p",{className:"text-xs text-dark-muted/70",children:t("hook.noRulesHint")})]});const C=n=>{const s=new Set(k);s.has(n)?s.delete(n):s.add(n),b(s),v(s.size===T.length)},h=()=>{R?(b(new Set),v(!1)):(b(new Set(T.map(n=>n.name))),v(!0))},w=()=>{k.size!==0&&confirm(t("hook.batchDeleteConfirm",{n:k.size}))&&(x(Array.from(k)),b(new Set),v(!1))},m=n=>{k.size!==0&&(p(Array.from(k),n),b(new Set),v(!1))};return e.jsxs("div",{className:"flex flex-1 flex-col min-h-0",children:[k.size>0&&e.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:[e.jsx("span",{className:"text-dark-muted",children:t("hook.selectedItems",{n:k.size})}),e.jsx("button",{onClick:()=>m(!0),className:"rounded bg-accent-green/15 px-2 py-0.5 text-accent-green transition-colors hover:bg-accent-green/25",children:t("hook.enableAll")}),e.jsx("button",{onClick:()=>m(!1),className:"rounded bg-dark-hover px-2 py-0.5 text-dark-text transition-colors hover:bg-dark-border",children:t("hook.disableAll")}),e.jsx("button",{onClick:w,className:"rounded bg-accent-red/15 px-2 py-0.5 text-accent-red transition-colors hover:bg-accent-red/25",children:t("common.delete")})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-auto custom-scrollbar rounded-xl border border-dark-border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"sticky top-0 bg-dark-hover text-dark-muted",children:e.jsxs("tr",{children:[e.jsx("th",{className:"w-8 p-2.5",children:e.jsx("button",{onClick:h,children:R?e.jsx(L,{size:14}):e.jsx(D,{size:14})})}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.colName")}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.colEvents")}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.colType")}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.fieldPriority")}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.colStatus")}),e.jsx("th",{className:"p-2.5 text-right font-medium",children:t("hook.colActions")})]})}),e.jsx("tbody",{className:"divide-y divide-dark-border",children:T.map(n=>e.jsxs("tr",{className:"transition-colors hover:bg-dark-hover/50",children:[e.jsx("td",{className:"p-2.5",children:e.jsx("button",{onClick:()=>C(n.name),children:k.has(n.name)?e.jsx(L,{size:14,className:"text-accent-blue"}):e.jsx(D,{size:14,className:"text-dark-muted"})})}),e.jsxs("td",{className:"p-2.5",children:[e.jsx("div",{className:"font-medium text-dark-text",children:n.name}),n.description&&e.jsx("div",{className:"mt-0.5 max-w-[220px] truncate text-xs text-dark-muted",children:n.description})]}),e.jsx("td",{className:"p-2.5",children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[Array.isArray(n.events)&&n.events.slice(0,3).map(s=>e.jsx("span",{className:"rounded bg-dark-hover px-1.5 py-0.5 text-xs text-dark-text",children:s},s)),Array.isArray(n.events)&&n.events.length>3&&e.jsxs("span",{className:"px-1 py-0.5 text-xs text-dark-muted",children:["+",n.events.length-3]})]})}),e.jsx("td",{className:"p-2.5",children:e.jsx("span",{className:`rounded px-1.5 py-0.5 text-xs font-medium ${ae[n.implementationType]||"bg-dark-hover text-dark-muted"}`,children:n.implementationType})}),e.jsx("td",{className:"p-2.5",children:e.jsx("span",{className:`rounded px-1.5 py-0.5 text-xs font-medium ${te[n.priority]||"bg-dark-hover text-dark-muted"}`,children:n.priority})}),e.jsx("td",{className:"p-2.5",children:e.jsx("button",{onClick:()=>r(n.name,!n.enabled),className:`relative h-5 w-9 rounded-full transition-colors ${n.enabled?"bg-accent-green":"bg-dark-border"}`,title:n.enabled?t("hook.clickToDisable"):t("hook.clickToEnable"),children:e.jsx("span",{className:`absolute top-0.5 block h-3.5 w-3.5 rounded-full bg-white transition-all ${n.enabled?"left-[18px]":"left-[2px]"}`})})}),e.jsx("td",{className:"p-2.5",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx("button",{onClick:()=>d(n),className:"rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-blue",title:t("hook.actionEdit"),children:e.jsx(Y,{size:14})}),e.jsx("button",{onClick:()=>{confirm(t("hook.deleteRuleConfirm",{name:n.name}))&&c(n.name)},className:"rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-red",title:t("common.delete"),children:e.jsx(B,{size:14})})]})})]},n.name))})]})})]})}const re={name:"",description:"",events:[],implementationType:"SHELL",command:"",url:"",promptTemplate:"",agentName:"",priority:"USER",tools:[],matcherToolNamePattern:"",matcherFromState:"",matcherToState:"",timeoutMs:3e4,enabled:!0,failOpen:!0,scope:"project"},le=[{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)"}],g=l=>`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 ${l?"border-accent-red focus:border-accent-red focus:ring-accent-red/20":"border-dark-border focus:border-accent-blue focus:ring-accent-blue/20"}`,f="mb-1 block text-xs font-medium text-dark-muted";function ne({events:l,agents:d}){const{t}=E(),{editingRule:r,fieldErrors:c,dryRunResult:x,createRule:p,updateRule:k,closeForm:b,dryRun:R,setDryRunResult:v,clearFieldErrors:T}=P(),C=[{value:"SHELL",label:t("hook.implShell"),desc:t("hook.implShellDesc")},{value:"HTTP",label:t("hook.implHttp"),desc:t("hook.implHttpDesc")},{value:"PROMPT",label:"LLM Prompt",desc:t("hook.implPromptDesc")},{value:"AGENT",label:"AI Agent",desc:t("hook.implAgentDesc")}],h=Array.isArray(l)?l:[],w=Array.isArray(d)?d:[],[m,n]=y.useState(0),[s,N]=y.useState(re),[S,O]=y.useState("");y.useEffect(()=>{var a,o,i;r&&N({name:r.name,description:r.description||"",events:r.events,implementationType:r.implementationType,command:r.command||"",url:r.url||"",promptTemplate:r.promptTemplate||"",agentName:r.agentName||"",priority:r.priority,tools:r.tools||[],matcherToolNamePattern:((a=r.matchers)==null?void 0:a.toolNamePattern)||"",matcherFromState:((o=r.matchers)==null?void 0:o.fromState)||"",matcherToState:((i=r.matchers)==null?void 0:i.toState)||"",timeoutMs:r.timeoutMs,enabled:r.enabled,failOpen:r.failOpen,scope:r.scope||"project"})},[r]);const u=(a,o)=>{N(i=>({...i,[a]:o})),T()},I=a=>{N(o=>({...o,events:o.events.includes(a)?o.events.filter(i=>i!==a):[...o.events,a]}))},F=a=>{const o=a.every(i=>s.events.includes(i));N(o?i=>({...i,events:i.events.filter(A=>!a.includes(A))}):i=>({...i,events:[...new Set([...i.events,...a])]}))},M=async()=>{const a={};s.matcherToolNamePattern&&(a.toolNamePattern=s.matcherToolNamePattern),s.matcherFromState&&(a.fromState=s.matcherFromState),s.matcherToState&&(a.toState=s.matcherToState);const i={...{...s,tools:s.tools.length>0?s.tools:[]}};i.matchers=a,delete i.matcherToolNamePattern,delete i.matcherFromState,delete i.matcherToState,r?await k(r.name,i):await p(i)},U=async()=>{v(null);const a={};s.matcherToolNamePattern&&(a.toolNamePattern=s.matcherToolNamePattern),await R({hook:{name:s.name||"dry-run",description:s.description,events:s.events,implementationType:s.implementationType,command:s.command,url:s.url,promptTemplate:s.promptTemplate,agentName:s.agentName,priority:s.priority,tools:s.tools,matchers:a,timeoutMs:s.timeoutMs,enabled:!0,failOpen:s.failOpen,scope:s.scope},eventType:s.events[0]||"PRE_TOOL_USE",toolName:"",toolInput:""})},H=S?h.map(a=>({...a,events:Array.isArray(a.events)?a.events.filter(o=>o.name.toLowerCase().includes(S.toLowerCase())||o.summary.includes(S)):[]})).filter(a=>a.events.length>0):h,$=[{title:t("hook.stepBasicTitle"),desc:t("hook.stepBasicDesc")},{title:t("hook.stepImplTitle"),desc:t("hook.stepImplDesc")},{title:t("hook.stepAdvancedTitle"),desc:t("hook.stepAdvancedDesc")}];return e.jsxs("div",{className:"fixed inset-0 z-50 flex justify-end",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:b}),e.jsxs("div",{className:"relative flex h-full w-[560px] flex-col border-l border-dark-border bg-dark-bg shadow-2xl animate-slide-in-right",children:[e.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between border-b border-dark-border px-4 py-3.5",children:[e.jsx("h3",{className:"text-base font-semibold text-dark-text",children:r?t("hook.editRule",{name:r.name}):t("hook.addRule")}),e.jsx("button",{onClick:b,className:"rounded-lg p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",children:e.jsx(z,{size:18})})]}),e.jsx("div",{className:"flex flex-shrink-0 border-b border-dark-border",children:$.map((a,o)=>{const i=o===m,A=o<m;return e.jsxs("button",{onClick:()=>n(o),className:`relative flex-1 border-b-2 px-2 py-2.5 text-center text-xs transition-colors ${i?"border-accent-blue bg-accent-blue/5 text-accent-blue":A?"border-transparent text-dark-text":"border-transparent text-dark-muted hover:text-dark-text"}`,children:[e.jsx("span",{className:`mr-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-[10px] ${i?"bg-accent-blue text-white":A?"bg-accent-green text-white":"bg-dark-hover text-dark-muted"}`,children:A?"✓":o+1}),e.jsx("span",{className:"font-medium",children:a.title})]},a.title)})}),e.jsxs("div",{className:"flex-1 min-h-0 space-y-4 overflow-auto custom-scrollbar p-4",children:[c&&Object.keys(c).length>0&&e.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(([a,o])=>e.jsxs("div",{children:[e.jsxs("strong",{children:[a,":"]})," ",o]},a))}),m===0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldName")}),e.jsx("input",{value:s.name,onChange:a=>u("name",a.target.value),placeholder:"my-custom-hook",className:g(c==null?void 0:c.name)})]}),e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldDescription")}),e.jsx("textarea",{value:s.description,onChange:a=>u("description",a.target.value),placeholder:t("hook.descriptionPlaceholder"),rows:2,className:g()})]}),e.jsxs("div",{children:[e.jsx("label",{className:f,children:"Scope"}),e.jsxs("select",{value:s.scope,onChange:a=>u("scope",a.target.value),className:g(),children:[e.jsx("option",{value:"project",children:"project (.agent/hooks.json)"}),e.jsx("option",{value:"user",children:"user (~/.agent/hooks.json)"}),e.jsx("option",{value:"local",children:"local (.agent/hooks.local.json)"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsx("label",{className:"text-xs font-medium text-dark-muted",children:t("hook.fieldEvents")}),e.jsx("span",{className:"text-xs text-accent-blue",children:t("hook.eventsSelected",{n:s.events.length})})]}),e.jsx("input",{value:S,onChange:a=>O(a.target.value),placeholder:t("hook.searchEventsPlaceholder"),className:g()+" mb-2"}),e.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:H.map(a=>e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>F(a.events.map(o=>o.name)),className:"mb-1 text-xs font-medium text-dark-muted transition-colors hover:text-dark-text",children:[a.category," — ",t("hook.toggleAllEvents")]}),a.events.map(o=>{const i=s.events.includes(o.name);return e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded px-1 py-1 transition-colors hover:bg-dark-hover",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:()=>I(o.name),className:"h-3.5 w-3.5 accent-accent-blue"}),e.jsx("span",{className:"text-xs text-dark-text",children:o.name}),e.jsxs("span",{className:"truncate text-xs text-dark-muted",children:["— ",o.summary]})]},o.name)})]},a.category))})]})]}),m===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldImplType")}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:C.map(a=>{const o=s.implementationType===a.value;return e.jsxs("button",{onClick:()=>u("implementationType",a.value),className:`rounded-lg border p-3 text-left transition-colors ${o?"border-accent-blue bg-accent-blue/10 ring-1 ring-accent-blue/30":"border-dark-border bg-dark-surface hover:bg-dark-hover"}`,children:[e.jsx("div",{className:`text-sm font-medium ${o?"text-accent-blue":"text-dark-text"}`,children:a.label}),e.jsx("div",{className:"mt-1 text-xs text-dark-muted",children:a.desc})]},a.value)})})]}),s.implementationType==="SHELL"&&e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldCommand")}),e.jsx("input",{value:s.command,onChange:a=>u("command",a.target.value),placeholder:"python3 .agent/hooks/audit.py",className:`font-mono ${g(c==null?void 0:c.command)}`})]}),s.implementationType==="HTTP"&&e.jsxs("div",{children:[e.jsx("label",{className:f,children:"URL *"}),e.jsx("input",{value:s.url,onChange:a=>u("url",a.target.value),placeholder:"https://example.com/hooks/audit",className:g(c==null?void 0:c.url)})]}),s.implementationType==="PROMPT"&&e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldPromptTemplate")}),e.jsx("textarea",{value:s.promptTemplate,onChange:a=>u("promptTemplate",a.target.value),placeholder:t("hook.promptTemplatePlaceholder"),rows:5,className:`font-mono ${g(c==null?void 0:c.promptTemplate)}`})]}),s.implementationType==="AGENT"&&e.jsxs("div",{children:[e.jsx("label",{className:f,children:"Agent *"}),e.jsxs("select",{value:s.agentName,onChange:a=>u("agentName",a.target.value),className:g(c==null?void 0:c.agentName),children:[e.jsx("option",{value:"",children:t("hook.selectAgentPlaceholder")}),w.map(a=>e.jsxs("option",{value:a.id,children:[a.name," (",a.description,")"]},a.id))]}),e.jsx("p",{className:"mt-1 text-xs text-dark-muted",children:t("hook.agentReadOnlyHint")})]})]}),m===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldPriority")}),e.jsx("select",{value:s.priority,onChange:a=>u("priority",a.target.value),className:g(),children:le.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldTimeout")}),e.jsx("input",{type:"number",value:s.timeoutMs,onChange:a=>u("timeoutMs",parseInt(a.target.value)||3e4),min:100,max:3e5,step:1e3,className:g()})]}),e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-text",children:[e.jsx("input",{type:"checkbox",checked:s.enabled,onChange:a=>u("enabled",a.target.checked),className:"h-3.5 w-3.5 accent-accent-blue"}),t("hook.labelEnabled")]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-text",children:[e.jsx("input",{type:"checkbox",checked:s.failOpen,onChange:a=>u("failOpen",a.target.checked),className:"h-3.5 w-3.5 accent-accent-blue"}),t("hook.failOpenLabel")]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldToolFilter")}),e.jsx("input",{value:s.matcherToolNamePattern,onChange:a=>u("matcherToolNamePattern",a.target.value),placeholder:"Bash.*|FileWrite.*",className:`font-mono ${g()}`})]}),s.events.some(a=>a.includes("STATE"))&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:"From State"}),e.jsx("input",{value:s.matcherFromState,onChange:a=>u("matcherFromState",a.target.value),className:g()})]}),e.jsxs("div",{children:[e.jsx("label",{className:f,children:"To State"}),e.jsx("input",{value:s.matcherToState,onChange:a=>u("matcherToState",a.target.value),className:g()})]})]}),x&&e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-dark-text",children:t("hook.dryRunResultTitle")}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:t("hook.dryRunDecision")}),e.jsx("span",{className:x.decision==="ALLOW"?"text-accent-green":x.decision==="DENY"?"text-accent-red":"text-accent-yellow",children:x.decision})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:t("hook.dryRunReason")}),e.jsx("span",{className:"text-dark-text",children:x.reason})]}),x.contextOutput&&e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:t("hook.dryRunOutput")}),e.jsx("span",{className:"text-dark-text",children:x.contextOutput})]})]})]}),e.jsxs("button",{onClick:U,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:[e.jsx(G,{size:12})," ",t("hook.dryRunButton")]})]})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between border-t border-dark-border px-4 py-3",children:[e.jsx("div",{className:"flex gap-2",children:m>0&&e.jsxs("button",{onClick:()=>n(m-1),className:"inline-flex items-center gap-1 rounded-lg border border-dark-border bg-dark-surface px-3 py-1.5 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(J,{size:14})," ",t("hook.prevStep")]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:b,className:"rounded-lg border border-dark-border bg-dark-surface px-4 py-1.5 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:t("common.cancel")}),m<2?e.jsxs("button",{onClick:()=>n(m+1),className:"inline-flex items-center gap-1 rounded-lg bg-accent-blue px-4 py-1.5 text-sm text-white transition-colors hover:bg-accent-blue/90",children:[t("hook.nextStep")," ",e.jsx(W,{size:14})]}):e.jsx("button",{onClick:M,className:"rounded-lg bg-accent-blue px-4 py-1.5 text-sm text-white transition-colors hover:bg-accent-blue/90",children:t(r?"hook.saveChanges":"hook.createRule")})]})]})]})]})}function oe({stats:l}){const{t:d}=E();if(!l)return null;const t=[{id:"total",label:d("hook.statTotal"),value:l.totalHooks,icon:_,iconWrap:"bg-accent-blue/15 text-accent-blue"},{id:"enabled",label:d("common.enabled"),value:l.enabledCount,icon:q,iconWrap:"bg-accent-green/15 text-accent-green"},{id:"disabled",label:d("common.disabled"),value:l.disabledCount,icon:X,iconWrap:"bg-dark-hover text-dark-muted"}];return e.jsx("div",{className:"grid grid-cols-3 gap-3",children:t.map(r=>{const c=r.icon;return e.jsxs("div",{className:"flex items-center gap-3 rounded-xl border border-dark-border bg-dark-surface px-4 py-3",children:[e.jsx("span",{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg ${r.iconWrap}`,children:e.jsx(c,{size:18})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xl font-bold text-dark-text",children:r.value}),e.jsx("div",{className:"text-xs text-dark-muted",children:r.label})]})]},r.id)})})}function ue(){const{t:l}=E(),{rules:d,stats:t,events:r,agents:c,loading:x,error:p,formOpen:k,loadAll:b,openForm:R,clearError:v}=P();y.useEffect(()=>{b()},[]);const T=y.useCallback(async()=>{const h=await j.hooks.export();if(h.success&&h.data){const w=new Blob([JSON.stringify(h.data,null,2)],{type:"application/json"}),m=URL.createObjectURL(w),n=document.createElement("a");n.href=m,n.download="hooks-export.json",n.click(),URL.revokeObjectURL(m)}},[]),C=y.useCallback(()=>{const h=document.createElement("input");h.type="file",h.accept=".json",h.onchange=async w=>{var s;const m=(s=w.target.files)==null?void 0:s[0];if(!m)return;const n=await m.text();try{const N=JSON.parse(n),S=confirm(l("hook.importMergeConfirm"))?"merge":"replace";(await j.hooks.import({...N,mergeMode:S})).success&&b()}catch(N){console.error("Import failed:",N)}},h.click()},[b,l]);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-dark-bg text-dark-text",children:[e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-between gap-3 border-b border-dark-border px-6 py-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-dark-text",children:l("hook.configTitle")}),e.jsx("p",{className:"mt-0.5 text-xs text-dark-muted",children:l("hook.configDesc")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:b,title:l("common.refresh"),className:"rounded-lg p-2 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",children:e.jsx(Q,{size:16,className:x?"animate-spin":""})}),e.jsxs("button",{onClick:C,className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-2 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(V,{size:14}),l("hook.import")]}),e.jsxs("button",{onClick:T,className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-2 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(Z,{size:14}),l("hook.export")]}),e.jsxs("button",{onClick:()=>R(),className:"inline-flex items-center gap-1.5 rounded-lg bg-accent-blue px-3 py-2 text-sm text-white transition-colors hover:bg-accent-blue/90",children:[e.jsx(K,{size:14}),l("hook.newRule")]})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto custom-scrollbar px-6 py-4",children:[p&&e.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:[e.jsx("span",{children:p}),e.jsx("button",{onClick:v,className:"text-accent-red/70 transition-colors hover:text-accent-red",children:e.jsx(z,{size:16})})]}),e.jsx(oe,{stats:t}),e.jsxs("section",{className:"mt-4 min-w-0 rounded-xl border border-dark-border bg-dark-surface p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold text-dark-text",children:l("hook.ruleList")}),e.jsx("span",{className:"text-xs text-dark-muted",children:l("hook.ruleCount",{n:d.length})})]}),x&&d.length===0?e.jsx("div",{className:"flex h-[520px] items-center justify-center text-dark-muted",children:l("common.loading")}):e.jsx("div",{className:"min-h-[520px]",children:e.jsx(se,{rules:d,onEdit:h=>R(h)})})]})]}),k&&e.jsx(ne,{events:r,agents:c})]})}export{ue as HookConfigView};
@@ -1 +0,0 @@
1
- import{j as e}from"./markdown-DEtuzEyz.js";import{a as o,h as re,an as Os,aa as ke,af as oe,X as Fe,aD as Bs,C as X,aE as $e,aF as us,as as Hs,j as Gs,aG as qs,aH as _s,a2 as Vs,ax as Ws,aI as ms,A as Ys,aJ as Qs}from"./icons-f1hlMKvD.js";import{a as j,u as Js,t as T,f as ne,M as xs,P as Xs}from"./index-u1vYyqna.js";import"./react-vendor-ClBKp0t-.js";import"./state-xD58vmym.js";import"./panels-Bn-2wCur.js";function Zs(){const[k,g]=o.useState([]),[C,t]=o.useState("1.0"),[P,Pe]=o.useState(!0),[b,de]=o.useState(!0),[Te,W]=o.useState(null),Y=o.useCallback(async()=>{de(!0),W(null);try{const w=await j.providers.presets();w.success&&w.data?(g(Array.isArray(w.data.providers)?w.data.providers:[]),t(w.data.version||"1.0"),Pe(w.data.customSupported!==!1)):W(w.error||"获取 Provider 列表失败")}catch(w){W(w instanceof Error?w.message:"未知错误")}finally{de(!1)}},[]);return o.useEffect(()=>{Y()},[Y]),{presets:k,loading:b,error:Te,version:C,customSupported:P,reload:Y}}const et=[{key:"global",labelKey:"chat.globalDefault",color:"text-accent-red",bg:"bg-accent-red/20"},{key:"plan",labelKey:"chat.planDefault",color:"text-accent-blue",bg:"bg-accent-blue/20"},{key:"goal",labelKey:"chat.goalDefault",color:"text-accent-purple",bg:"bg-accent-purple/20"}],st={providerKey:"",apiKeys:[],modelIds:"",baseUrl:"",apiType:"",fullPath:!1,setDefault:!1,modelOverrides:{}},ps=Xs,Ne={"openai-chat-completions":"OpenAI Chat","openai-completions":"OpenAI Compatible","openai-responses":"OpenAI Responses","anthropic-messages":"Anthropic Messages","codex-responses":"Codex (本机登录)","claude-code":"Claude Code (本机登录)"};function Z(k){return k.trim().split("|")[0].trim()}function tt(k){const g=k.toLowerCase();return g.startsWith("claude-code://")||g.includes("/backend-api/codex")?g.startsWith("claude-code://")?"claude-code":"codex-responses":g.includes("/anthropic")||g.includes("/coding")||g.includes("/claude")||g.includes("/messages")?"anthropic-messages":g.includes("/responses")?"openai-responses":"openai-completions"}function ze(k){if(!k)return{};const g={};for(const C of k.models){const t={};C.apiType&&C.apiType!==k.apiType&&(t.apiType=C.apiType),C.baseUrl&&(t.baseUrl=C.baseUrl),Object.keys(t).length>0&&(g[C.id]=t)}return g}const we={"opencode-free":5,deepseek:10,moonshotai:20,"moonshotai-cn":21,"kimi-for-coding":22,zhipuai:30,zai:31,"alibaba-cn":40,alibaba:41,minimax:50,"minimax-cn":51,moark:60,siliconflow:70,"siliconflow-cn":71,"stepfun-ai":80,stepfun:81,modelscope:90,openai:100,anthropic:110,google:120,"google-vertex":121,meta:130,mistral:140,groq:150,xai:160,cohere:170,openrouter:180,huggingface:190};function ct(){var ls,rs,os,ns,ds,cs,is;const{presets:k,loading:g,reload:C}=Zs(),{t}=Js(),[P,Pe]=o.useState([]),[b,de]=o.useState(null),[Te,W]=o.useState(!0),[Y,w]=o.useState(null),[Ee,Le]=o.useState(null),[n,hs]=o.useState(null),[I,bs]=o.useState([]),[fs,H]=o.useState(!1),[Re,G]=o.useState("select"),[D,L]=o.useState(null),[u,f]=o.useState(st),[gs,F]=o.useState(""),[Oe,Be]=o.useState(!1),[He,$]=o.useState(null),[Me,ee]=o.useState(!1),[ce,Ge]=o.useState(!1),[se,ie]=o.useState(""),[Se,qe]=o.useState(!1),[M,q]=o.useState([]),[ue,U]=o.useState(new Set),[_e,R]=o.useState(null),[me,te]=o.useState(""),[De,Ve]=o.useState(!1),[xe,O]=o.useState(null),We=o.useMemo(()=>{const s=me.trim().toLowerCase();return s?M.filter(a=>a.id.toLowerCase().includes(s)||a.name.toLowerCase().includes(s)):M},[M,me]),_=o.useCallback(async()=>{try{const s=await j.config.provider.get();s.success&&s.data&&(hs(s.data),bs(Array.isArray(s.data.entries)?s.data.entries:[]))}catch{}},[]),S=o.useCallback(async()=>{W(!0),w(null);try{const[s,a]=await Promise.all([j.models.list(),j.system.status()]);if(await _(),s.success&&s.data&&Array.isArray(s.data.models)&&Pe(s.data.models),a.success&&a.data){const l=a.data.models||{total:0,online:0,offline:0};de({overallStatus:l.offline===0?"healthy":l.online>0?"degraded":"unhealthy",healthRate:l.total>0?l.online/l.total:0,healthyInstances:l.online,totalInstances:l.total,totalRequests:0})}}catch{w(t("models.loadFailed"))}finally{W(!1)}},[_,t]);o.useEffect(()=>{S()},[S]),o.useEffect(()=>{const s=()=>{S(),_()};return window.addEventListener("models-updated",s),()=>window.removeEventListener("models-updated",s)},[S,_]);const pe=o.useCallback(s=>`${s.provider}:${s.id}`,[]),z=o.useMemo(()=>{const s=[...k];return s.find(a=>a.key==="custom")||s.push({key:"custom",name:"Custom",baseUrl:"",apiType:"openai-completions",defaultModel:"",isCustom:!0}),s},[k]),he=o.useMemo(()=>[...z].sort((s,a)=>{if(s.isCustom)return-1;if(a.isCustom)return 1;const l=we[s.key],c=we[a.key];return l!==void 0&&c!==void 0?l-c:l!==void 0?-1:c!==void 0?1:s.name.localeCompare(a.name)}),[z]),Ye=o.useMemo(()=>{const s=se.trim().toLowerCase();return s?he.filter(a=>a.name.toLowerCase().includes(s)||a.key.toLowerCase().includes(s)||(a.defaultModel||"").toLowerCase().includes(s)||(a.baseUrl||"").toLowerCase().includes(s)||(a.models||[]).some(l=>String(l).toLowerCase().includes(s))):he},[he,se]),E=o.useMemo(()=>{var c,r,d,i;const s=(n==null?void 0:n.providers)||{},a=new Set(z.map(m=>m.key)),l=Object.entries(s).filter(([m])=>!a.has(m));if(l.length!==0)return{keys:l.map(([m])=>m),modelCount:l.reduce((m,[,h])=>m+(h.modelCount||0),0),hasApiKey:l.some(([,m])=>m.hasApiKey),baseUrl:((r=(c=l.find(([,m])=>m.baseUrl))==null?void 0:c[1])==null?void 0:r.baseUrl)||"",apiType:((i=(d=l.find(([,m])=>m.apiType))==null?void 0:d[1])==null?void 0:i.apiType)||"openai-completions"}},[n,z]),V=D==="custom"?u.providerKey.trim():D||"",Ke=o.useMemo(()=>V?P.filter(s=>s.provider===V):[],[P,V]),vs=o.useMemo(()=>{const s=new Map;for(const l of P)s.has(l.provider)||s.set(l.provider,[]),s.get(l.provider).push(l);for(const l of I)s.has(l.key)||s.set(l.key,[]);const a=[...s.keys()];return a.sort((l,c)=>{const r=we[l],d=we[c];return r!==void 0&&d!==void 0?r-d:r!==void 0?-1:d!==void 0?1:l.localeCompare(c)}),a.map(l=>({provider:l,models:s.get(l)||[]}))},[P,I]),Qe=o.useCallback(s=>{var i,m;const a=(i=n==null?void 0:n.providers)==null?void 0:i[s.key],l=I.find(h=>h.key===s.key),c=P.filter(h=>h.provider===s.key).map(h=>h.id),r=((m=s.models)==null?void 0:m.slice(0,3).join(", "))||s.defaultModel,d=c.length>0?c.join(", "):r;L(s.key),F(""),f({providerKey:s.key,apiKeys:[""],modelIds:d,baseUrl:(a==null?void 0:a.baseUrl)||s.baseUrl,apiType:(a==null?void 0:a.apiType)||s.apiType,fullPath:(a==null?void 0:a.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s.key,modelOverrides:ze(l)}),G("form"),H(!0),$(null),ee(!1),q([]),U(new Set),R(null),te("")},[P,n,I]),ys=o.useCallback(s=>{var r;const a=(r=n==null?void 0:n.providers)==null?void 0:r[s],l=I.find(d=>d.key===s),c=P.filter(d=>d.provider===s).map(d=>d.id).join(", ");L("custom"),F(s),f({providerKey:s,apiKeys:[""],modelIds:c,baseUrl:(a==null?void 0:a.baseUrl)||"",apiType:(a==null?void 0:a.apiType)||"",fullPath:(a==null?void 0:a.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s,modelOverrides:ze(l)}),$(null),ee(!1),q([]),U(new Set),R(null),te("")},[n,P,I]),Ie=o.useCallback(()=>{L("custom"),F(""),f({providerKey:"",apiKeys:[""],modelIds:"",baseUrl:"",apiType:"",fullPath:!1,setDefault:!(n!=null&&n.configured),modelOverrides:{}}),G("form"),H(!0),$(null),ee(!1),q([]),U(new Set),R(null),te("")},[n]),js=o.useCallback(async()=>{var a;const s=u.baseUrl;if(!s){R(t("models.baseUrlRequired"));return}qe(!0),R(null),q([]),U(new Set);try{const l=(u.apiKeys||[]).map(d=>d.trim()).filter(Boolean)[0]||"",c=l.replace(/[^\x00-\xFF]/g,"");c!==l&&T.warning(t("models.apiKeySanitized"));const r=await j.models.fetch(s,c,u.fullPath===!0);if(r.success&&((a=r.data)!=null&&a.models)){const d=r.data.models;q(d);const i=new Set(d.map(v=>v.id)),m=u.modelIds.split(",").map(v=>v.trim()).filter(Boolean),h=m.filter(v=>i.has(v.split("|")[0].trim())),K=m.filter(v=>!i.has(v.split("|")[0].trim()));if(U(new Set(h.map(v=>v.split("|")[0].trim()))),K.length>0){const v=K.map(x=>x.split("|")[0].trim());f(x=>({...x,modelIds:h.join(", ")})),T.warning(t("models.autoRemovedMissingModels",{models:v.join(", ")}))}T.success(t("models.fetchedCount",{n:d.length}))}else R(r.error||t("models.fetchFailed"))}catch(l){R(l instanceof Error?l.message:t("models.requestFailed"))}finally{qe(!1)}},[u.baseUrl,u.apiKeys,u.modelIds,t]),ks=o.useCallback(async()=>{var a,l;const s=u.baseUrl;if(!s){O({ok:!1,message:t("models.baseUrlRequired")});return}Ve(!0),O(null);try{const c=(u.apiKeys||[]).map(i=>i.trim()).filter(Boolean)[0]||"",r=c.replace(/[^\x00-\xFF]/g,"");r!==c&&T.warning(t("models.apiKeySanitized"));const d=await j.providers.testConnection(s,r);if(d.success&&((a=d.data)!=null&&a.reachable)){const i=d.data,m={};i.resolvedBaseUrl&&i.resolvedBaseUrl!==u.baseUrl&&(m.baseUrl=i.resolvedBaseUrl),i.detectedApiType&&u.apiType===""&&(m.apiType=i.detectedApiType),Object.keys(m).length>0&&f(v=>({...v,...m}));const h=[];m.baseUrl&&h.push(t("models.baseUrlAutoCompleted",{url:m.baseUrl})),m.apiType&&h.push(t("models.apiTypeAutoSelected",{type:Ne[m.apiType]}));const K=i.message||t("models.connectionSuccess");O({ok:!0,message:h.length>0?t("models.connectionSuccessWithHints",{message:K,hints:h.join(t("models.hintJoiner"))}):K})}else O({ok:!1,message:((l=d.data)==null?void 0:l.message)||d.error||t("models.connectionFailed")})}catch(c){O({ok:!1,message:c instanceof Error?c.message:t("models.requestFailed")})}finally{Ve(!1)}},[u.baseUrl,u.apiKeys,u.apiType,t]),Ns=o.useCallback(s=>{const a=new Set(ue);a.has(s)?a.delete(s):a.add(s),U(a),f(l=>({...l,modelIds:Array.from(a).join(", ")}))},[ue]),ws=o.useCallback(s=>{const a=u.modelIds.split(",").map(d=>d.trim()).filter(Boolean),c=a.some(d=>Z(d)===s.id)?a.filter(d=>Z(d)!==s.id):[...a,s.name&&s.name!==s.id?`${s.id}|${s.name}`:s.id];f(d=>({...d,modelIds:c.join(", ")}));const r=new Set(M.map(d=>d.id));U(new Set(c.map(Z).filter(d=>r.has(d))))},[u.modelIds,M]),[Cs,Je]=o.useState(!1),[Ue,Xe]=o.useState(""),[Ze,be]=o.useState([]),[Ps,es]=o.useState(!1),[ss,fe]=o.useState(null),[ge,Ts]=o.useState(!1),[ve,Ms]=o.useState(!0),Ss=o.useCallback(()=>{Xe(""),be([]),fe(null),Je(!0),ae("",{reason:!1,tool:!0})},[]),ae=o.useCallback(async(s,a)=>{es(!0),fe(null);try{const l=await j.models.catalogSearch({q:s,reasoning:(a==null?void 0:a.reason)??!1,toolCall:(a==null?void 0:a.tool)??!0,limit:30});l.success&&l.data?be(l.data.hits||[]):(fe(l.error||t("models.catalogSearchFailed")),be([]))}catch(l){fe(l instanceof Error?l.message:t("models.requestFailed")),be([])}finally{es(!1)}},[t]),Ds=o.useCallback(s=>{f(a=>{const l=a.modelIds.split(",").map(c=>c.trim()).filter(Boolean);return l.includes(s.model.id)?a:{...a,modelIds:[...l,s.model.id].join(", ")}}),T.success(t("models.addedModel",{id:s.model.id}))},[t]),[Ae,Ks]=o.useState(null),Is=o.useCallback(s=>{Xe(s),Ae&&clearTimeout(Ae),Ks(setTimeout(()=>{ae(s,{reason:ge,tool:ve})},300))},[Ae,ge,ve,ae]),Us=async s=>{const a=s.provider,l=s.id,c=s.enabled!==!1,r=s.name||l,d=i=>c&&/default model/i.test(i);try{const i=await j.models.toggle(a,l);if(i.success){await S();return}const m=i.error||"";d(m)?T.error(t("models.defaultModelDisableBlocked",{name:r})):T.error(m||t("models.operationFailed"))}catch(i){const m=i instanceof Error?i.message:"";d(m)?T.error(t("models.defaultModelDisableBlocked",{name:r})):T.error(m||t("models.operationFailed"))}},As=async s=>{const a=pe(s);Le(a);try{await j.models.test(s.id),await S()}finally{Le(null)}},Fs=async(s,a)=>{if(confirm(t("models.deleteModelConfirm",{id:a})))try{(await j.models.delete(s,a)).success&&await S()}catch{}},ts=o.useCallback(s=>{var d;const a=I.find(i=>i.key===s),l=z.find(i=>i.key===s),c=!l||l.isCustom,r=(d=n==null?void 0:n.providers)==null?void 0:d[s];L(c?"custom":s),F(c?s:""),f({providerKey:s,apiKeys:[""],modelIds:(a==null?void 0:a.models.map(i=>i.name&&i.name!==i.id?`${i.id}|${i.name}`:i.id).join(", "))||"",baseUrl:(a==null?void 0:a.baseUrl)||(r==null?void 0:r.baseUrl)||(l==null?void 0:l.baseUrl)||"",apiType:(a==null?void 0:a.apiType)||(r==null?void 0:r.apiType)||(l==null?void 0:l.apiType)||"",fullPath:(a==null?void 0:a.fullPath)===!0||(r==null?void 0:r.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s,modelOverrides:ze(a)}),G("form"),H(!0),$(null),ee(!1),q([]),U(new Set),R(null),te("")},[I,z,n]),$s=s=>{ts(s.provider)},zs=async()=>{var ye,je;const s=z.find(p=>p.key===D)||null,a=D==="custom"?u.providerKey.trim():(s==null?void 0:s.key)||"";if(!a){$(t("models.providerNameRequired"));return}const l=(u.apiKeys||[]).map(p=>p.trim()).filter(Boolean),c=!!((je=(ye=n==null?void 0:n.providers)==null?void 0:ye[a])!=null&&je.hasApiKey);if(l.length===0&&!c){$(t("models.apiKeyRequired"));return}const r=s||{baseUrl:"",apiType:"openai-completions",defaultModel:""},d=l.map(p=>p.replace(/[^\x00-\xFF]/g,"")).filter(Boolean),i=M.length>0?new Set(M.map(p=>p.id)):null,m=(u.modelIds||r.defaultModel||"").split(",").map(p=>p.trim()).filter(Boolean),h=i?m.filter(p=>i.has(p.split("|")[0].trim())):m,K=i?m.filter(p=>!i.has(p.split("|")[0].trim())):[];K.length>0&&T.warning(t("models.autoSkippedMissingModels",{models:K.map(p=>p.split("|")[0].trim()).join(", ")}));const v=h.map(Z).filter(Boolean),x=new Set;for(const p of P)p.provider!==a||v.includes(p.id)||(p.isGlobalDefault&&x.add("global"),p.isPlanDefault&&x.add("plan"),p.isGoalDefault&&x.add("goal"));const le={provider:a,name:a,baseUrl:u.baseUrl||r.baseUrl,fullPath:u.fullPath===!0,apiType:u.apiType||tt(u.baseUrl||r.baseUrl)||r.apiType,models:h.map((p,J)=>{const N=p.trim().split("|").map(Rs=>Rs.trim()).filter(Boolean),A=N[0]||"",y=u.modelOverrides[A];return{id:A,name:N[1]||A,aliases:N.length>2?N.slice(2):void 0,enabled:!0,priority:10+J,...y!=null&&y.apiType?{apiType:y.apiType}:{},...y!=null&&y.baseUrl?{baseUrl:y.baseUrl}:{}}}).filter(p=>p.id.length>0)};d.length>0&&(le.apiKeys=d),(!(n!=null&&n.configured)||u.setDefault)&&(le.setDefault=!0),Be(!0),$(null);try{const p=await j.config.provider.save(le);if(p.success){if(x.size>0){const J=v[0]||"",N={};if(J){const A=`${a}:${J}`;for(const y of x)N[y]=A}else{const A=P.find(y=>y.provider!==a);for(const y of x)y==="plan"||y==="goal"?N[y]=null:A&&(N[y]=`${A.provider}:${A.id}`)}Object.keys(N).length>0&&(await j.models.setDefaults(N)).success&&T.success(t("models.defaultsAutoUpdated"))}H(!1),G("select"),L(null),F(""),await _(),await S()}else $(p.error||t("models.saveFailed"))}catch(p){$(p instanceof Error?p.message:t("models.unknownError"))}finally{Be(!1)}},as=async s=>{if(confirm(t("models.removeConfirm",{providerKey:s})))try{await j.config.provider.delete(s),await _(),await S()}catch{}},Es=s=>{switch(s){case"online":return"text-accent-green";case"offline":return"text-dark-muted";case"error":return"text-accent-red";default:return"text-dark-muted"}},Ls=s=>{switch(s){case"online":return e.jsx(Qs,{size:14});case"offline":return e.jsx(ms,{size:14});case"error":return e.jsx(Ys,{size:14});default:return e.jsx(ms,{size:14})}},Q=o.useMemo(()=>z.find(s=>s.key===D)||null,[D,z]);return Te?e.jsx("div",{className:"flex h-64 items-center justify-center text-dark-muted",children:t("models.loading")}):Y?e.jsx("div",{className:"flex h-64 items-center justify-center text-accent-red",children:Y}):e.jsx("div",{className:"ui-page flex-1 min-h-0",children:e.jsxs("div",{className:"ui-page-inner space-y-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-base font-semibold",children:t("models.providerConfig")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:async()=>{try{await j.providers.refresh(),T.success(t("models.providerListRefreshed")),Ge(!0),await C(),setTimeout(()=>{C()},3e3)}catch{T.error(t("models.refreshFailed"))}},className:"btn btn-secondary px-3 py-2 text-xs",title:t("models.refreshListTitle"),children:[e.jsx(re,{size:12}),t("models.refreshList")]}),e.jsxs("button",{onClick:()=>{ce&&ie(""),Ge(s=>!s)},className:"btn btn-accent px-3 py-2 text-xs",children:[ce?e.jsx(Os,{size:12}):e.jsx(ke,{size:12}),t(ce?"models.collapse":"models.addProvider")]})]})]}),ce&&e.jsxs("div",{children:[e.jsxs("div",{className:"relative mb-3 max-w-md",children:[e.jsx(oe,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:se,onChange:s=>ie(s.target.value),className:"w-full pl-8 pr-8 py-1.5 text-xs bg-dark-bg border border-dark-border rounded focus:outline-none focus:border-accent-blue",placeholder:t("models.providerSearchPlaceholder")}),se&&e.jsx("button",{onClick:()=>ie(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-dark-muted hover:text-white",title:t("models.clear"),"aria-label":t("models.clearSearch"),children:e.jsx(Fe,{size:13})})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3 max-h-[420px] overflow-y-auto custom-scrollbar pr-1",children:g?e.jsxs("div",{className:"col-span-full flex items-center justify-center py-4 text-dark-muted text-sm",children:[e.jsx(Bs,{size:14,className:"mr-2 animate-spin"}),t("models.loadingProviders")]}):Ye.length===0?e.jsxs("div",{className:"col-span-full border border-accent-red/30 bg-accent-red/10 rounded-lg p-4 text-center",children:[e.jsx("div",{className:"text-sm text-accent-red font-medium mb-1",children:t("models.noMatchingProviders")}),e.jsx("div",{className:"text-xs text-dark-muted mb-3",children:t("models.noMatchingProvidersHint",{query:se})}),e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsxs("button",{onClick:()=>ie(""),className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs border border-dark-border rounded hover:bg-dark-hover",children:[e.jsx(Fe,{size:12}),t("models.clearSearch")]}),e.jsxs("button",{onClick:Ie,className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs bg-accent-blue text-white rounded hover:opacity-90",children:[e.jsx(ke,{size:12}),t("models.addCustomProvider")]})]})]}):Ye.map(s=>{var d,i;const a=s.key==="custom",l=a?E:(d=n==null?void 0:n.providers)==null?void 0:d[s.key],c=l==null?void 0:l.hasApiKey,r=a?!!(n!=null&&n.defaultProvider)&&((E==null?void 0:E.keys)||[]).includes(n.defaultProvider):(n==null?void 0:n.defaultProvider)===s.key;return e.jsxs("div",{className:`ui-card-interactive text-left p-4 relative ${c?"border-accent-green/30 bg-dark-surface hover:border-accent-green/50":"border-dark-border bg-dark-surface hover:border-dark-hover"}`,children:[e.jsxs("div",{onClick:()=>s.key==="custom"?Ie():Qe(s),className:"cursor-pointer",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-sm font-medium",children:s.name}),c&&e.jsx(X,{size:14,className:"text-accent-green"})]}),e.jsxs("div",{className:"text-[10px] text-dark-muted space-y-0.5",children:[e.jsx("div",{className:"truncate",children:a?(l==null?void 0:l.baseUrl)||t("models.customBaseUrl"):s.baseUrl||t("models.customBaseUrl")}),e.jsx("div",{className:"truncate",children:a&&E?`${E.keys.join(", ")}`:s.defaultModel||t("models.noDefaultModel")}),e.jsxs("div",{children:[l?t("models.configuredCount",{n:l.modelCount}):t("models.availableCount",{n:((i=s.models)==null?void 0:i.length)||0}),s.models&&s.models.length>0&&!l&&e.jsx("span",{className:"text-accent-blue",children:" ✓"})]})]}),r&&e.jsx("div",{className:"mt-1 text-[10px] text-accent-red",children:t("models.defaultProviderBadge")})]}),c&&s.key!=="custom"&&e.jsx("button",{onClick:m=>{m.stopPropagation(),as(s.key)},className:"absolute top-1.5 right-1.5 p-1 rounded text-dark-muted hover:bg-accent-red/10 hover:text-accent-red transition-colors",title:t("models.deleteProvider"),"aria-label":t("models.deleteProviderNamed",{name:s.name}),children:e.jsx($e,{size:13})})]},s.key)})})]})]}),b&&e.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[e.jsx(Ce,{title:t("models.overallStatus"),value:b.totalInstances===0?t("models.notConfigured"):b.overallStatus==="healthy"?t("models.healthy"):b.overallStatus==="degraded"?t("models.degraded"):t("models.abnormal"),color:b.totalInstances===0?"blue":b.overallStatus==="healthy"?"green":b.overallStatus==="degraded"?"yellow":"red"}),e.jsx(Ce,{title:t("models.healthRate"),value:b.totalInstances===0?"N/A":`${(b.healthRate*100).toFixed(0)}%`,color:b.totalInstances===0?"blue":b.healthRate>.8?"green":b.healthRate>.5?"yellow":"red"}),e.jsx(Ce,{title:t("models.onlineInstances"),value:b.totalInstances===0?t("models.none"):`${b.healthyInstances}/${b.totalInstances}`,color:b.healthyInstances>0?"green":"red"}),e.jsx(Ce,{title:t("models.totalRequests"),value:b.totalRequests>0?b.totalRequests.toLocaleString():"0",color:"blue"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("models.configuredModels")}),e.jsx("span",{className:"text-[10px] text-dark-muted",title:t("models.actIsGlobalHint"),children:t("models.actIsGlobalHint")})]}),e.jsxs("div",{className:"space-y-4 max-h-[640px] overflow-y-auto custom-scrollbar pr-1",children:[vs.map(s=>{var c;const a=I.find(r=>r.key===s.provider),l=(c=n==null?void 0:n.providers)==null?void 0:c[s.provider];return e.jsxs("div",{className:"rounded-lg border border-dark-border overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2 bg-dark-bg border-b border-dark-border",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[e.jsx("span",{className:"text-xs font-semibold whitespace-nowrap text-accent-purple",children:s.provider}),(n==null?void 0:n.defaultProvider)===s.provider&&e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-accent-red/20 text-accent-red whitespace-nowrap",children:t("models.defaultShort")}),e.jsx("span",{className:"text-[10px] text-dark-muted truncate",children:(l==null?void 0:l.baseUrl)||(a==null?void 0:a.baseUrl)||""}),e.jsx("span",{className:"text-[10px] text-dark-muted whitespace-nowrap",children:(a==null?void 0:a.apiType)||(l==null?void 0:l.apiType)||""}),l!=null&&l.hasApiKey||a!=null&&a.hasApiKey?e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-accent-green/20 text-accent-green whitespace-nowrap",children:t("models.hasKey")}):e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-accent-red/20 text-accent-red whitespace-nowrap",children:t("models.noKey")})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>ts(s.provider),className:"p-1.5 rounded hover:bg-accent-blue/10 text-dark-muted hover:text-accent-blue",title:t("models.editProviderNamed",{name:s.provider}),children:e.jsx(us,{size:13})}),e.jsx("button",{onClick:()=>as(s.provider),className:"p-1.5 rounded hover:bg-accent-red/10 text-dark-muted hover:text-accent-red",title:t("models.deleteProviderNamed",{name:s.provider}),children:e.jsx($e,{size:13})})]})]}),e.jsxs("div",{className:"space-y-2 p-2 bg-dark-surface/40",children:[s.models.map(r=>{var m,h,K,v;const d=a==null?void 0:a.models.find(x=>x.id===r.id),i=!!(d!=null&&d.apiType&&d.apiType!==(a==null?void 0:a.apiType));return e.jsx("div",{className:`bg-dark-surface border rounded-lg p-3 ${r.status==="online"?"border-accent-green":"border-dark-border"} ${r.enabled===!1?"opacity-60":""}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx("span",{className:Es(r.status),children:Ls(r.status)}),e.jsx("span",{className:"font-medium text-sm text-accent-blue",children:r.name}),e.jsx("span",{className:"text-[10px] text-accent-purple px-1.5 py-0.5 bg-accent-purple/10 rounded",children:r.provider}),r.apiType&&e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${r.apiType==="anthropic-messages"||r.apiType==="openai-responses"?"bg-accent-purple/20 text-accent-purple":"bg-accent-blue/20 text-accent-blue"}`,children:Ne[r.apiType]||r.apiType}),i&&e.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded bg-accent-yellow/20 text-accent-yellow font-medium",title:t("models.overrideTitle"),children:t("models.overrideBadge")}),r.isGlobalDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-red/20 text-accent-red font-medium",title:t("models.globalDefaultUnsettable"),children:t("chat.globalDefault")}),r.isPlanDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/20 text-accent-blue font-medium",children:t("chat.planDefault")}),r.isActDefault&&!r.isGlobalDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-yellow/20 text-accent-yellow font-medium",children:t("chat.actDefault")}),r.isGoalDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-purple/20 text-accent-purple font-medium",children:t("chat.goalDefault")})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs",children:[e.jsx(B,{label:t("models.loadLabel"),value:`${r.load}/${r.maxLoad}`}),e.jsx(B,{label:t("models.tokenUsageLabel"),value:`${ne(r.tokens)}/${ne(r.maxTokens)}`}),e.jsx(B,{label:t("models.inputPrice"),value:`$${r.price.input}/M`}),e.jsx(B,{label:t("models.outputPrice"),value:`$${r.price.output}/M`})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs",children:[e.jsx(B,{label:t("models.inputTokensLabel"),value:ne(((m=r.usage)==null?void 0:m.input)??0)}),e.jsx(B,{label:t("models.outputTokensLabel"),value:ne(((h=r.usage)==null?void 0:h.output)??0)}),e.jsx(B,{label:t("models.totalTokensLabel"),value:ne(((K=r.usage)==null?void 0:K.total)??0)}),e.jsx(B,{label:t("models.usageRequestsLabel"),value:String(((v=r.usage)==null?void 0:v.requests)??0)})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[et.map(x=>{const le=x.key==="global"?r.isGlobalDefault:x.key==="plan"?r.isPlanDefault:r.isGoalDefault,ye=x.key==="global"?t("models.setGlobalDefaultTitle"):x.key==="plan"?t("models.setPlanDefaultTitle"):t("models.setGoalDefaultTitle"),je=x.key==="plan"?t("models.unsetPlanDefaultTitle"):t("models.unsetGoalDefaultTitle"),p=x.key==="plan"?t("models.unsetPlanDefaultFailed"):t("models.unsetGoalDefaultFailed"),J=x.key==="plan"?t("models.setPlanDefaultFailed"):t("models.setGoalDefaultFailed");return le?x.key==="global"?e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-1 rounded text-[10px] border ${x.bg} ${x.color} font-medium`,title:t("chat.globalDefault"),children:[e.jsx(X,{size:11}),t(x.labelKey)]},x.key):e.jsxs("button",{onClick:async()=>{try{await j.models.setDefaults({[x.key]:null}),await S()}catch(N){w(N instanceof Error?N.message:p)}},className:`inline-flex items-center gap-1 px-2 py-1 rounded text-[10px] border ${x.bg} ${x.color} font-medium cursor-pointer hover:opacity-80`,title:je,children:[e.jsx(X,{size:11}),t(x.labelKey)]},x.key):r.enabled===!1?null:e.jsx("button",{onClick:async()=>{try{await j.models.setDefaults({[x.key]:`${r.provider}:${r.id}`}),await S()}catch(N){w(N instanceof Error?N.message:J)}},className:"px-2 py-1 rounded text-[10px] border border-dark-border text-dark-muted hover:text-dark-text hover:border-dark-hover",title:ye,children:t(x.labelKey)},x.key)}),e.jsx("button",{onClick:()=>$s(r),className:"p-1.5 rounded hover:bg-accent-blue/10 text-dark-muted hover:text-accent-blue",title:t("models.editModel"),children:e.jsx(us,{size:13})}),e.jsx("button",{onClick:()=>Fs(r.provider,r.id),className:"p-1.5 rounded hover:bg-accent-red/10 text-dark-muted hover:text-accent-red",title:t("models.deleteModel"),children:e.jsx($e,{size:13})}),e.jsx("button",{onClick:()=>As(r),disabled:Ee===pe(r),className:"p-1.5 rounded hover:bg-dark-hover disabled:opacity-50",title:t("models.refresh"),children:e.jsx(re,{size:13,className:Ee===pe(r)?"animate-spin":""})}),e.jsx("button",{onClick:()=>Us(r),className:`px-2 py-0.5 rounded text-xs transition-colors ${r.enabled===!1?"bg-accent-green/20 text-accent-green hover:bg-accent-green/30":"bg-accent-red/20 text-accent-red hover:bg-accent-red/30"}`,children:r.enabled===!1?t("models.enable"):t("models.disable")})]})]})},pe(r))}),s.models.length===0&&e.jsx("div",{className:"text-center text-[11px] text-dark-muted py-3",children:t("models.noModelsInProvider")})]})]},s.provider)}),P.length===0&&I.length===0&&e.jsxs("div",{className:"text-center text-dark-muted py-6",children:[e.jsx(Hs,{size:36,className:"mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:t("models.emptyHint")})]})]})]}),e.jsx(xs,{isOpen:fs,onClose:()=>{H(!1),G("select"),L(null),F("")},title:Re==="select"?t("chat.selectProvider"):(Q==null?void 0:Q.name)||t("models.providerConfig"),size:"xl",children:Re==="select"?e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[he.filter(s=>s.key!=="custom").map(s=>e.jsxs("button",{onClick:()=>Qe(s),className:"text-left p-3 rounded-lg border border-dark-border bg-dark-bg hover:border-accent-blue transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(X,{size:14,className:"text-accent-blue"}),e.jsx("span",{className:"text-sm font-medium",children:s.name})]}),e.jsx("div",{className:"text-xs text-dark-muted",children:s.defaultModel})]},s.key)),e.jsxs("button",{onClick:Ie,className:"text-left p-3 rounded-lg border border-dashed border-dark-border bg-dark-bg hover:border-accent-blue transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Gs,{size:14,className:"text-accent-blue"}),e.jsx("span",{className:"text-sm font-medium",children:t("models.customProvider")})]}),e.jsx("div",{className:"text-xs text-dark-muted",children:t("models.customProviderDesc")})]})]})}):e.jsxs("div",{className:"space-y-3",children:[D==="custom"&&e.jsxs("div",{className:"space-y-3",children:[E&&E.keys.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.editExistingConfig")}),e.jsxs("select",{value:gs,onChange:s=>{const a=s.target.value;a?ys(a):(F(""),f(l=>({...l,providerKey:"",modelIds:"",baseUrl:"",apiType:"",apiKeys:[""]})))},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",children:[e.jsx("option",{value:"",children:t("models.newCustomProviderOption")}),E.keys.map(s=>e.jsx("option",{value:s,children:s},s))]}),e.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:t("models.editExistingConfigHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.providerNameLabel")}),e.jsx("input",{value:u.providerKey,onChange:s=>f(a=>({...a,providerKey:s.target.value})),className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:t("models.providerNamePlaceholder")})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-dark-muted mb-1",children:["API Keys",(rs=(ls=n==null?void 0:n.providers)==null?void 0:ls[D==="custom"?u.providerKey.trim():D||""])!=null&&rs.hasApiKey?"":" *",e.jsx("span",{className:"text-dark-muted/60 text-xs",children:(ns=(os=n==null?void 0:n.providers)==null?void 0:os[D==="custom"?u.providerKey.trim():D||""])!=null&&ns.hasApiKey?t("models.apiKeysHintConfigured"):t("models.apiKeysHintNew")})]}),e.jsx("div",{className:"space-y-1.5",children:((ds=u.apiKeys)!=null&&ds.length?u.apiKeys:[""]).map((s,a)=>e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{type:Me?"text":"password",value:s,autoComplete:"off",spellCheck:!1,onChange:l=>f(c=>({...c,apiKeys:c.apiKeys.map((r,d)=>d===a?l.target.value:r)})),className:"w-full px-3 py-2 pr-9 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:t("models.apiKeyDefaultPlaceholder")}),e.jsx("button",{type:"button",onClick:()=>ee(l=>!l),className:"absolute right-2 top-1/2 -translate-y-1/2 text-dark-muted hover:text-white",title:t(Me?"models.hideKeyTitle":"models.showKeyTitle"),children:Me?e.jsx(qs,{size:14}):e.jsx(_s,{size:14})})]}),a===0?e.jsxs("button",{type:"button",onClick:()=>f(l=>({...l,apiKeys:[...l.apiKeys,""]})),className:"shrink-0 inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-dashed border-dark-border text-dark-muted hover:text-accent-blue hover:border-accent-blue/50 transition-colors",title:t("models.addApiKeyTitle"),children:[e.jsx(ke,{size:14}),e.jsx("span",{className:"hidden sm:inline",children:t("models.addApiKey")})]}):e.jsx("button",{type:"button",onClick:()=>f(l=>({...l,apiKeys:l.apiKeys.filter((c,r)=>r!==a)})),className:"shrink-0 inline-flex items-center px-3 py-2 rounded text-sm text-dark-muted hover:text-accent-red hover:bg-accent-red/10 transition-colors",title:t("models.removeApiKeyTitle"),children:e.jsx(Fe,{size:14})})]},a))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.modelIdLabel")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:u.modelIds,onChange:s=>{const a=s.target.value;f(l=>({...l,modelIds:a})),U(()=>{const l=new Set;for(const c of a.split(",")){const r=c.trim().split("|")[0].trim();r&&M.some(d=>d.id===r)&&l.add(r)}return l})},className:"flex-1 px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:(Q==null?void 0:Q.defaultModel)||t("models.modelIdPlaceholder")}),e.jsxs("button",{onClick:js,disabled:Se||!u.baseUrl,className:"inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-accent-blue/30 text-accent-blue hover:bg-accent-blue/10 disabled:opacity-50 whitespace-nowrap",title:t("models.fetchModelsTitle"),children:[Se?e.jsx(re,{size:13,className:"animate-spin"}):e.jsx(Vs,{size:13}),t(Se?"models.fetchingModels":"models.fetchModels")]}),e.jsxs("button",{onClick:ks,disabled:De||!u.baseUrl,className:"inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-accent-yellow/30 text-accent-yellow hover:bg-accent-yellow/10 disabled:opacity-50 whitespace-nowrap",title:t("models.testConnectionTitle"),children:[De?e.jsx(re,{size:13,className:"animate-spin"}):e.jsx(Ws,{size:13}),t(De?"models.testingConnection":"models.testConnection")]}),e.jsxs("button",{onClick:Ss,className:"inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-accent-green/30 text-accent-green hover:bg-accent-green/10 whitespace-nowrap",title:t("models.catalogSearchTitle"),children:[e.jsx(oe,{size:13}),t("models.catalogSearch")]})]}),xe&&e.jsxs("div",{className:`mt-1 text-xs ${xe.ok?"text-accent-green":"text-accent-red"}`,children:[xe.ok?"✓ ":"✗ ",xe.message]}),_e&&e.jsx("div",{className:"mt-1 text-xs text-accent-red",children:_e}),M.length===0&&Ke.length>0&&e.jsxs("div",{className:"mt-2 border border-dark-border rounded-lg bg-dark-bg p-2",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("span",{className:"text-xs text-dark-muted",children:[t("models.configuredPanelPrefix"),e.jsx("strong",{className:"text-dark-text",children:Ke.length}),t("models.configuredPanelSuffix"),e.jsx("span",{className:"text-accent-green/70",children:t("models.configuredPanelHint")})]})}),e.jsx("div",{className:"max-h-48 overflow-y-auto custom-scrollbar grid grid-cols-2 sm:grid-cols-3 gap-1",children:Ke.map(s=>{const a=u.modelIds.split(",").map(Z).filter(Boolean).includes(s.id);return e.jsxs("div",{role:"checkbox","aria-checked":a,title:s.name&&s.name!==s.id?`${s.id} — ${s.name}`:s.name||s.id,tabIndex:-1,onMouseDown:l=>l.preventDefault(),onClick:()=>ws(s),className:`flex items-start gap-1.5 px-2 py-1 rounded cursor-pointer text-xs transition-colors select-none ${a?"bg-accent-green/20 text-accent-green border border-accent-green/30":"hover:bg-dark-hover border border-transparent"}`,children:[e.jsx("span",{className:"shrink-0 mt-[3px]",children:a?e.jsx(X,{size:10}):e.jsx("div",{className:"w-2.5 h-2.5 rounded border border-dark-border"})}),e.jsx("span",{className:"min-w-0 flex-1 break-words leading-snug",children:s.name||s.id}),s.isGlobalDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-red/20 text-accent-red shrink-0",children:t("models.globalShort")}),s.isPlanDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-blue/20 shrink-0",children:"Plan"}),s.isActDefault&&!s.isGlobalDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-yellow/20 shrink-0",children:"Act"}),s.isGoalDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-purple/20 shrink-0",children:"Goal"})]},s.id)})})]}),M.length>0&&e.jsxs("div",{className:"mt-2 border border-dark-border rounded-lg bg-dark-bg p-2",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-xs text-dark-muted",children:[t("models.fetchedPanelPrefix"),e.jsx("strong",{className:"text-dark-text",children:M.length}),t("models.fetchedPanelMiddle"),e.jsx("strong",{className:"text-accent-blue",children:ue.size}),t("models.fetchedPanelSuffix"),e.jsx("span",{className:"text-accent-blue/70",children:t("models.fetchedPanelHint")})]}),e.jsx("button",{onClick:()=>{q([]),U(new Set)},className:"px-2 py-0.5 text-[10px] border border-dark-border rounded hover:bg-dark-hover",children:t("models.close")})]}),e.jsxs("div",{className:"relative mb-2",children:[e.jsx(oe,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:me,onChange:s=>te(s.target.value),className:"w-full pl-7 pr-2 py-1 text-xs bg-dark-bg border border-dark-border rounded focus:outline-none focus:border-accent-blue",placeholder:t("models.modelSearchPlaceholder")})]}),me.trim()!==""&&e.jsxs("div",{className:"mb-1 text-[10px] text-dark-muted",children:[t("models.searchMatchPrefix"),e.jsx("strong",{className:"text-accent-blue",children:We.length}),t("models.searchMatchSuffix",{total:M.length})]}),e.jsx("div",{className:"max-h-72 overflow-y-auto custom-scrollbar grid grid-cols-1 sm:grid-cols-2 gap-1",children:We.map(s=>{const a=ue.has(s.id);return e.jsxs("div",{role:"checkbox","aria-checked":a,title:s.name&&s.name!==s.id?`${s.id} — ${s.name}`:s.id,tabIndex:-1,onMouseDown:l=>l.preventDefault(),onClick:()=>Ns(s.id),className:`flex items-start gap-1.5 px-2 py-1 rounded cursor-pointer text-xs transition-colors select-none ${a?"bg-accent-blue/20 text-accent-blue border border-accent-blue/30":"hover:bg-dark-hover border border-transparent"}`,children:[e.jsx("span",{className:"shrink-0 mt-[3px]",children:a?e.jsx(X,{size:10}):e.jsx("div",{className:"w-2.5 h-2.5 rounded border border-dark-border"})}),e.jsx("span",{className:"min-w-0 flex-1 break-all leading-snug",children:s.id})]},s.id)})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"Base URL"}),e.jsx("input",{value:u.baseUrl,onChange:s=>{f(a=>({...a,baseUrl:s.target.value})),O(null)},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:"https://api.example.com/v1"}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none mt-2",children:[e.jsx("button",{type:"button",role:"switch","aria-checked":u.fullPath,onClick:()=>{f(s=>({...s,fullPath:!s.fullPath})),O(null)},className:`relative w-9 h-5 rounded-full transition-colors shrink-0 ${u.fullPath?"bg-accent-green":"bg-dark-border"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${u.fullPath?"translate-x-[18px]":"translate-x-0.5"}`})}),e.jsx("span",{className:"text-sm text-dark-muted",children:t("models.fullPathLabel")})]}),e.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:t("models.fullPathHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.apiTypeLabel")}),e.jsxs("select",{value:u.apiType,onChange:s=>{f(a=>({...a,apiType:s.target.value})),O(null)},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",children:[e.jsx("option",{value:"",children:t("models.apiTypeAutoDetect")}),ps.map(s=>e.jsx("option",{value:s,children:Ne[s]},s))]}),e.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:t("models.apiTypeHint")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-dark-muted mb-1",children:[t("models.modelApiTypeLabel"),e.jsx("span",{className:"text-dark-muted/60 text-xs",children:t("models.modelApiTypeHint")})]}),e.jsx("div",{className:"border border-dark-border rounded-lg divide-y divide-dark-border max-h-40 overflow-y-auto custom-scrollbar",children:(()=>{const s=u.modelIds.split(",").map(Z).filter(Boolean);return s.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-dark-muted",children:t("models.modelApiTypeEmpty")}):s.map(a=>{var l;return e.jsxs("div",{className:"flex items-start justify-between gap-2 px-3 py-1.5",children:[e.jsx("span",{className:"text-xs min-w-0 flex-1 break-all leading-snug",title:a,children:a}),e.jsxs("select",{value:((l=u.modelOverrides[a])==null?void 0:l.apiType)||"",onChange:c=>f(r=>({...r,modelOverrides:{...r.modelOverrides,[a]:{...r.modelOverrides[a]||{},apiType:c.target.value}}})),className:"w-52 px-2 py-1 text-xs bg-dark-bg border border-dark-border rounded focus:outline-none focus:border-accent-blue",children:[e.jsx("option",{value:"",children:"继承 Provider(默认)"}),ps.map(c=>e.jsx("option",{value:c,children:Ne[c]},c))]})]},a)})})()})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:u.setDefault,onChange:s=>f(a=>({...a,setDefault:s.target.checked})),className:"accent-accent-blue"}),e.jsx("span",{className:"text-sm text-dark-muted",children:t("models.setDefaultProvider")})]}),He&&e.jsx("div",{className:"text-sm text-accent-red",children:He}),e.jsxs("div",{className:"flex justify-between gap-2 pt-2",children:[e.jsx("div",{children:V&&((is=(cs=n==null?void 0:n.providers)==null?void 0:cs[V])==null?void 0:is.hasApiKey)&&e.jsx("button",{onClick:async()=>{if(confirm(t("models.deleteProviderConfirm",{key:V})))try{await j.config.provider.delete(V),H(!1),G("select"),L(null),F(""),await _(),await S()}catch{}},className:"px-4 py-2 rounded border border-accent-red/30 text-accent-red hover:bg-accent-red/10 transition-colors text-sm",children:t("models.deleteProvider")})}),e.jsx("button",{onClick:()=>{G("select"),L(null),F(""),H(!1)},className:"px-4 py-2 rounded border border-dark-border hover:bg-dark-hover transition-colors text-sm",children:t("common.cancel")}),e.jsx("button",{onClick:zs,disabled:Oe,className:"px-4 py-2 bg-accent-blue text-white rounded hover:bg-accent-blue/80 transition-colors text-sm disabled:opacity-50",children:t(Oe?"common.saving":"common.save")})]})]})}),e.jsx(xs,{isOpen:Cs,onClose:()=>Je(!1),title:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(oe,{size:15,className:"text-accent-green"}),t("models.catalogTitle")]}),size:"2xl",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(oe,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:Ue,onChange:s=>Is(s.target.value),className:"w-full pl-9 pr-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-green",placeholder:t("models.catalogSearchPlaceholder"),autoFocus:!0})]}),e.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-dark-muted whitespace-nowrap cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:ve,onChange:s=>{const a=s.target.checked;Ms(a),ae(Ue,{reason:ge,tool:a})},className:"accent-accent-green"}),t("models.catalogOnlyToolCall")]}),e.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-dark-muted whitespace-nowrap cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:ge,onChange:s=>{const a=s.target.checked;Ts(a),ae(Ue,{reason:a,tool:ve})},className:"accent-accent-green"}),t("models.catalogOnlyReasoning")]})]}),ss&&e.jsx("div",{className:"text-xs text-accent-red bg-accent-red/10 p-2 rounded",children:ss}),Ps?e.jsxs("div",{className:"flex items-center justify-center py-10 text-dark-muted",children:[e.jsx(re,{size:18,className:"animate-spin mr-2"})," ",t("models.searching")]}):e.jsx("div",{className:"max-h-96 overflow-y-auto custom-scrollbar border border-dark-border rounded-lg divide-y divide-dark-border",children:Ze.length===0?e.jsx("div",{className:"py-10 text-center text-dark-muted text-sm",children:t("models.catalogNoResults")}):Ze.map(s=>{var a,l,c;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 hover:bg-dark-hover",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-dark-text truncate",children:s.model.name||s.model.id}),e.jsx("code",{className:"text-[10px] px-1.5 py-0.5 bg-dark-bg border border-dark-border rounded text-dark-muted truncate",children:s.model.id}),s.model.reasoning&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-yellow/10 text-accent-yellow rounded",children:t("models.badgeReasoning")}),s.model.tool_call&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-blue/10 text-accent-blue rounded",children:t("models.badgeToolCall")}),s.model.attachment&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-green/10 text-accent-green rounded",children:t("models.badgeMultimodal")})]}),e.jsxs("div",{className:"text-[11px] text-dark-muted mt-0.5",children:[s.providerName,(a=s.model.limit)!=null&&a.context?` · ${t("models.ctxLimit",{k:(s.model.limit.context/1e3).toFixed(0)})}`:"",(l=s.model.limit)!=null&&l.output?` · ${t("models.outLimit",{k:(s.model.limit.output/1e3).toFixed(0)})}`:"",((c=s.model.cost)==null?void 0:c.input)!==void 0?` · $${s.model.cost.input}/M in / $${s.model.cost.output}/M out`:""]})]}),e.jsxs("button",{onClick:()=>Ds(s),className:"shrink-0 inline-flex items-center gap-1 px-2.5 py-1 text-xs border border-accent-green/30 text-accent-green rounded hover:bg-accent-green/10 whitespace-nowrap",title:t("models.catalogAddTitle"),children:[e.jsx(ke,{size:12})," ",t("models.add")]})]},`${s.providerId}:${s.model.id}`)})}),e.jsx("div",{className:"text-[11px] text-dark-muted/60",children:t("models.catalogSourceHint")})]})})]})})}function Ce({title:k,value:g,color:C}){const t={green:"bg-accent-green/10 text-accent-green",yellow:"bg-accent-yellow/10 text-accent-yellow",red:"bg-accent-red/10 text-accent-red",blue:"bg-accent-blue/10 text-accent-blue"};return e.jsxs("div",{className:`${t[C]} rounded-lg p-3`,children:[e.jsx("div",{className:"text-xs opacity-70",children:k}),e.jsx("div",{className:"text-xl font-semibold",children:g})]})}function B({label:k,value:g}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-dark-muted",children:k}),e.jsx("div",{children:g})]})}export{ct as ModelsView,ct as default};