@deepseekcode/cli 1.0.38 → 1.0.39

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 (47) hide show
  1. package/package.json +9 -9
  2. package/web/dist/assets/{AssistantsView-Bh6ajWIo.js → AssistantsView-0aLB_cG6.js} +1 -1
  3. package/web/dist/assets/AutomationView-CAMjPhJ2.js +1 -0
  4. package/web/dist/assets/{ChannelConfigView-DlakOI5z.js → ChannelConfigView-FcioeeYb.js} +6 -6
  5. package/web/dist/assets/ConnectorsView-DERP7zAW.js +1 -0
  6. package/web/dist/assets/{FileTreeView-Ciq1vhTf.js → FileTreeView-hBtHBbAV.js} +3 -3
  7. package/web/dist/assets/HookConfigView-NModtSB8.js +1 -0
  8. package/web/dist/assets/ModelsView-BPpO50C_.js +1 -0
  9. package/web/dist/assets/PluginsView-D0NE7zrt.js +1 -0
  10. package/web/dist/assets/ProjectsView-PIv7Gx4q.js +1 -0
  11. package/web/dist/assets/SessionGrid-BsDL3lov.js +47 -0
  12. package/web/dist/assets/SettingsModal-DdebvEmv.js +10 -0
  13. package/web/dist/assets/SkillsView-BNoigImJ.js +1 -0
  14. package/web/dist/assets/TemplatesTab-D8Pa68fj.js +1 -0
  15. package/web/dist/assets/ToolsView-NY-yk5YX.js +1 -0
  16. package/web/dist/assets/WorkspaceDirPicker-C5knnArH.js +6 -0
  17. package/web/dist/assets/{icons-YJcunJnw.js → icons-BxNxyk-c.js} +154 -129
  18. package/web/dist/assets/index-DaiVo1RY.css +1 -0
  19. package/web/dist/assets/index-RB5ffy32.js +620 -0
  20. package/web/dist/assets/{markdown-CrVimah5.js → markdown-B2L4Mq-x.js} +1 -1
  21. package/web/dist/assets/{panels-BykQW6E1.js → panels-P_I7Q72_.js} +1 -1
  22. package/web/dist/assets/{sttLanguages-D4JbRJc6.js → profileChange-C7Jg9C61.js} +1 -1
  23. package/web/dist/assets/{react-vendor-DM-M1fu_.js → react-vendor-B2V_5iSS.js} +1 -1
  24. package/web/dist/assets/{state-D8omNTWe.js → state-0T92JV0u.js} +1 -1
  25. package/web/dist/fonts/OFL-Inter.txt +93 -0
  26. package/web/dist/fonts/inter-latin-400-normal.woff2 +0 -0
  27. package/web/dist/fonts/inter-latin-600-normal.woff2 +0 -0
  28. package/web/dist/icons/icon-180.png +0 -0
  29. package/web/dist/icons/icon-192.png +0 -0
  30. package/web/dist/icons/icon-512.png +0 -0
  31. package/web/dist/icons/icon-maskable-512.png +0 -0
  32. package/web/dist/index.html +38 -8
  33. package/web/dist/manifest.webmanifest +16 -0
  34. package/web/dist/assets/AutomationView-D2Z-_4qe.js +0 -1
  35. package/web/dist/assets/ConnectorsView-ELXDmM9m.js +0 -1
  36. package/web/dist/assets/HookConfigView-DR8TP3QG.js +0 -1
  37. package/web/dist/assets/ModelsView-BW6eRUwf.js +0 -1
  38. package/web/dist/assets/PluginsView-CrHGk_JC.js +0 -1
  39. package/web/dist/assets/SessionGrid-DYYsm2dT.js +0 -52
  40. package/web/dist/assets/SettingsModal-DNxIKsKC.js +0 -10
  41. package/web/dist/assets/SkillsView-DS0nnKig.js +0 -1
  42. package/web/dist/assets/TemplatesTab-pXElHCnz.js +0 -1
  43. package/web/dist/assets/ThreeScene-DFL_qzB1.js +0 -2863
  44. package/web/dist/assets/ThreeScene-DvOrMIoG.css +0 -1
  45. package/web/dist/assets/ToolsView-Bk4hckku.js +0 -1
  46. package/web/dist/assets/index-CtPliI0f.css +0 -1
  47. package/web/dist/assets/index-D1N4vQ9I.js +0 -591
@@ -1,5 +1,5 @@
1
- import{j as s}from"./markdown-CrVimah5.js";import{a as o,W as J,aN as Ne,j as Te,bg as Pe,ae as Ee,a7 as Le,a3 as de,n as Re,D as fe,f as Fe,ag as De,T as Ae}from"./icons-YJcunJnw.js";import{u as ze,a as Q,t as F,d as pe}from"./index-D1N4vQ9I.js";import"./react-vendor-DM-M1fu_.js";import"./state-D8omNTWe.js";import"./panels-BykQW6E1.js";function he(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 $e(e){if(Array.isArray(e))return e}function Ie(e,t,r){return(t=Ke(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Ve(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var n,i,c,p,y=[],b=!0,O=!1;try{if(c=(r=r.call(e)).next,t!==0)for(;!(b=(n=c.call(r)).done)&&(y.push(n.value),y.length!==t);b=!0);}catch(N){O=!0,i=N}finally{try{if(!b&&r.return!=null&&(p=r.return(),Object(p)!==p))return}finally{if(O)throw i}}return y}}function Ue(){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 me(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function ge(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?me(Object(r),!0).forEach(function(n){Ie(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):me(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function qe(e,t){if(e==null)return{};var r,n,i=He(e,t);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);for(n=0;n<c.length;n++)r=c[n],t.indexOf(r)===-1&&{}.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}function He(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 We(e,t){return $e(e)||Ve(e,t)||Qe(e,t)||Ue()}function Be(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 Ke(e){var t=Be(e,"string");return typeof t=="symbol"?t:t+""}function Qe(e,t){if(e){if(typeof e=="string")return he(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)?he(e,t):void 0}}function Ge(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ve(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function be(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?ve(Object(r),!0).forEach(function(n){Ge(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ve(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Je(){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(i,c){return c(i)},n)}}function _(e){return function t(){for(var r=this,n=arguments.length,i=new Array(n),c=0;c<n;c++)i[c]=arguments[c];return i.length>=e.length?e.apply(this,i):function(){for(var p=arguments.length,y=new Array(p),b=0;b<p;b++)y[b]=arguments[b];return t.apply(r,[].concat(i,y))}}}function ie(e){return{}.toString.call(e).includes("Object")}function Ye(e){return!Object.keys(e).length}function Z(e){return typeof e=="function"}function _e(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Xe(e,t){return ie(t)||I("changeType"),Object.keys(t).some(function(r){return!_e(e,r)})&&I("changeField"),t}function Ze(e){Z(e)||I("selectorType")}function et(e){Z(e)||ie(e)||I("handlerType"),ie(e)&&Object.values(e).some(function(t){return!Z(t)})&&I("handlersType")}function tt(e){e||I("initialIsRequired"),ie(e)||I("initialType"),Ye(e)&&I("initialContent")}function rt(e,t){throw new Error(e[t]||e.default)}var nt={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"},I=_(rt)(nt),ne={changes:Xe,selector:Ze,handler:et,initial:tt};function at(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};ne.initial(e),ne.handler(t);var r={current:e},n=_(st)(r,t),i=_(ot)(r),c=_(ne.changes)(e),p=_(it)(r);function y(){var O=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(N){return N};return ne.selector(O),O(r.current)}function b(O){Je(n,i,c,p)(O)}return[y,b]}function it(e,t){return Z(t)?t(e.current):t}function ot(e,t){return e.current=be(be({},e.current),t),t}function st(e,t,r){return Z(t)?t(e.current):Object.keys(r).forEach(function(n){var i;return(i=t[n])===null||i===void 0?void 0:i.call(t,e.current[n])}),r}var ct={create:at},lt={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}};function ut(e){return function t(){for(var r=this,n=arguments.length,i=new Array(n),c=0;c<n;c++)i[c]=arguments[c];return i.length>=e.length?e.apply(this,i):function(){for(var p=arguments.length,y=new Array(p),b=0;b<p;b++)y[b]=arguments[b];return t.apply(r,[].concat(i,y))}}}function dt(e){return{}.toString.call(e).includes("Object")}function ft(e){return e||ye("configIsRequired"),dt(e)||ye("configType"),e.urls?(pt(),{paths:{vs:e.urls.monacoBase}}):e}function pt(){console.warn(xe.deprecation)}function ht(e,t){throw new Error(e[t]||e.default)}var xe={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!
1
+ import{j as s}from"./markdown-B2L4Mq-x.js";import{a as o,W as Y,aU as Ne,k as Te,bG as Pe,a1 as Ee,ah as Le,ad as de,o as Re,D as fe,f as Fe,Y as De,U as Ae}from"./icons-BxNxyk-c.js";import{u as ze,a as K,t as F,c as pe}from"./index-RB5ffy32.js";import"./react-vendor-B2V_5iSS.js";import"./state-0T92JV0u.js";import"./panels-P_I7Q72_.js";function he(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 $e(e){if(Array.isArray(e))return e}function Ie(e,t,r){return(t=Ge(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Ve(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var n,i,c,p,y=[],b=!0,O=!1;try{if(c=(r=r.call(e)).next,t!==0)for(;!(b=(n=c.call(r)).done)&&(y.push(n.value),y.length!==t);b=!0);}catch(N){O=!0,i=N}finally{try{if(!b&&r.return!=null&&(p=r.return(),Object(p)!==p))return}finally{if(O)throw i}}return y}}function Ue(){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 me(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function ge(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?me(Object(r),!0).forEach(function(n){Ie(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):me(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function qe(e,t){if(e==null)return{};var r,n,i=He(e,t);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);for(n=0;n<c.length;n++)r=c[n],t.indexOf(r)===-1&&{}.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}function He(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 We(e,t){return $e(e)||Ve(e,t)||Ke(e,t)||Ue()}function Be(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 Ge(e){var t=Be(e,"string");return typeof t=="symbol"?t:t+""}function Ke(e,t){if(e){if(typeof e=="string")return he(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)?he(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 ve(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function be(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?ve(Object(r),!0).forEach(function(n){Qe(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ve(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Ye(){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(i,c){return c(i)},n)}}function _(e){return function t(){for(var r=this,n=arguments.length,i=new Array(n),c=0;c<n;c++)i[c]=arguments[c];return i.length>=e.length?e.apply(this,i):function(){for(var p=arguments.length,y=new Array(p),b=0;b<p;b++)y[b]=arguments[b];return t.apply(r,[].concat(i,y))}}}function ie(e){return{}.toString.call(e).includes("Object")}function Je(e){return!Object.keys(e).length}function Z(e){return typeof e=="function"}function _e(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Xe(e,t){return ie(t)||I("changeType"),Object.keys(t).some(function(r){return!_e(e,r)})&&I("changeField"),t}function Ze(e){Z(e)||I("selectorType")}function et(e){Z(e)||ie(e)||I("handlerType"),ie(e)&&Object.values(e).some(function(t){return!Z(t)})&&I("handlersType")}function tt(e){e||I("initialIsRequired"),ie(e)||I("initialType"),Je(e)&&I("initialContent")}function rt(e,t){throw new Error(e[t]||e.default)}var nt={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"},I=_(rt)(nt),ne={changes:Xe,selector:Ze,handler:et,initial:tt};function at(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};ne.initial(e),ne.handler(t);var r={current:e},n=_(st)(r,t),i=_(ot)(r),c=_(ne.changes)(e),p=_(it)(r);function y(){var O=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(N){return N};return ne.selector(O),O(r.current)}function b(O){Ye(n,i,c,p)(O)}return[y,b]}function it(e,t){return Z(t)?t(e.current):t}function ot(e,t){return e.current=be(be({},e.current),t),t}function st(e,t,r){return Z(t)?t(e.current):Object.keys(r).forEach(function(n){var i;return(i=t[n])===null||i===void 0?void 0:i.call(t,e.current[n])}),r}var ct={create:at},lt={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}};function ut(e){return function t(){for(var r=this,n=arguments.length,i=new Array(n),c=0;c<n;c++)i[c]=arguments[c];return i.length>=e.length?e.apply(this,i):function(){for(var p=arguments.length,y=new Array(p),b=0;b<p;b++)y[b]=arguments[b];return t.apply(r,[].concat(i,y))}}}function dt(e){return{}.toString.call(e).includes("Object")}function ft(e){return e||ye("configIsRequired"),dt(e)||ye("configType"),e.urls?(pt(),{paths:{vs:e.urls.monacoBase}}):e}function pt(){console.warn(xe.deprecation)}function ht(e,t){throw new Error(e[t]||e.default)}var xe={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
3
  You are using deprecated way of configuration.
4
4
 
5
5
  Instead of using
@@ -8,4 +8,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
8
8
  monaco.config({ paths: { vs: '...' } })
9
9
 
10
10
  For more please check the link https://github.com/suren-atoyan/monaco-loader#config
11
- `},ye=ut(ht)(xe),mt={config:ft},gt=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return function(i){return r.reduceRight(function(c,p){return p(c)},i)}};function we(e,t){return Object.keys(t).forEach(function(r){t[r]instanceof Object&&e[r]&&Object.assign(t[r],we(e[r],t[r]))}),ge(ge({},e),t)}var vt={type:"cancelation",msg:"operation is manually canceled"};function ce(e){var t=!1,r=new Promise(function(n,i){e.then(function(c){return t?i(vt):n(c)}),e.catch(i)});return r.cancel=function(){return t=!0},r}var bt=["monaco"],yt=ct.create({config:lt,isInitialized:!1,resolve:null,reject:null,monaco:null}),je=We(yt,2),ee=je[0],oe=je[1];function xt(e){var t=mt.config(e),r=t.monaco,n=qe(t,bt);oe(function(i){return{config:we(i.config,n),monaco:r}})}function wt(){var e=ee(function(t){var r=t.monaco,n=t.isInitialized,i=t.resolve;return{monaco:r,isInitialized:n,resolve:i}});if(!e.isInitialized){if(oe({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),ce(le);if(window.monaco&&window.monaco.editor)return Oe(window.monaco),e.resolve(window.monaco),ce(le);gt(jt,St)(Ct)}return ce(le)}function jt(e){return document.body.appendChild(e)}function Ot(e){var t=document.createElement("script");return e&&(t.src=e),t}function St(e){var t=ee(function(n){var i=n.config,c=n.reject;return{config:i,reject:c}}),r=Ot("".concat(t.config.paths.vs,"/loader.js"));return r.onload=function(){return e()},r.onerror=t.reject,r}function Ct(){var e=ee(function(r){var n=r.config,i=r.resolve,c=r.reject;return{config:n,resolve:i,reject:c}}),t=window.require;t.config(e.config),t(["vs/editor/editor.main"],function(r){var n=r.m||r;Oe(n),e.resolve(n)},function(r){e.reject(r)})}function Oe(e){ee().monaco||oe({monaco:e})}function Mt(){return ee(function(e){var t=e.monaco;return t})}var le=new Promise(function(e,t){return oe({resolve:e,reject:t})}),Se={config:xt,init:wt,__getMonacoInstance:Mt},kt={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},ue=kt,Nt={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},Tt=Nt;function Pt({children:e}){return J.createElement("div",{style:Tt.container},e)}var Et=Pt,Lt=Et;function Rt({width:e,height:t,isEditorReady:r,loading:n,_ref:i,className:c,wrapperProps:p}){return J.createElement("section",{style:{...ue.wrapper,width:e,height:t},...p},!r&&J.createElement(Lt,null,n),J.createElement("div",{ref:i,style:{...ue.fullWidth,...!r&&ue.hide},className:c}))}var Ft=Rt,Ce=o.memo(Ft);function Dt(e){o.useEffect(e,[])}var Me=Dt;function At(e,t,r=!0){let n=o.useRef(!0);o.useEffect(n.current||!r?()=>{n.current=!1}:e,t)}var k=At;function X(){}function G(e,t,r,n){return zt(e,n)||$t(e,t,r,n)}function zt(e,t){return e.editor.getModel(ke(e,t))}function $t(e,t,r,n){return e.editor.createModel(t,r,n?ke(e,n):void 0)}function ke(e,t){return e.Uri.parse(t)}function It({original:e,modified:t,language:r,originalLanguage:n,modifiedLanguage:i,originalModelPath:c,modifiedModelPath:p,keepCurrentOriginalModel:y=!1,keepCurrentModifiedModel:b=!1,theme:O="light",loading:N="Loading...",options:M={},height:Y="100%",width:U="100%",className:q,wrapperProps:H={},beforeMount:W=X,onMount:B=X}){let[S,T]=o.useState(!1),[L,w]=o.useState(!0),j=o.useRef(null),x=o.useRef(null),D=o.useRef(null),C=o.useRef(B),h=o.useRef(W),R=o.useRef(!1);Me(()=>{let d=Se.init();return d.then(m=>(x.current=m)&&w(!1)).catch(m=>(m==null?void 0:m.type)!=="cancelation"&&console.error("Monaco initialization: error:",m)),()=>j.current?A():d.cancel()}),k(()=>{if(j.current&&x.current){let d=j.current.getOriginalEditor(),m=G(x.current,e||"",n||r||"text",c||"");m!==d.getModel()&&d.setModel(m)}},[c],S),k(()=>{if(j.current&&x.current){let d=j.current.getModifiedEditor(),m=G(x.current,t||"",i||r||"text",p||"");m!==d.getModel()&&d.setModel(m)}},[p],S),k(()=>{let d=j.current.getModifiedEditor();d.getOption(x.current.editor.EditorOption.readOnly)?d.setValue(t||""):t!==d.getValue()&&(d.executeEdits("",[{range:d.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),d.pushUndoStop())},[t],S),k(()=>{var d,m;(m=(d=j.current)==null?void 0:d.getModel())==null||m.original.setValue(e||"")},[e],S),k(()=>{let{original:d,modified:m}=j.current.getModel();x.current.editor.setModelLanguage(d,n||r||"text"),x.current.editor.setModelLanguage(m,i||r||"text")},[r,n,i],S),k(()=>{var d;(d=x.current)==null||d.editor.setTheme(O)},[O],S),k(()=>{var d;(d=j.current)==null||d.updateOptions(M)},[M],S);let V=o.useCallback(()=>{var E;if(!x.current)return;h.current(x.current);let d=G(x.current,e||"",n||r||"text",c||""),m=G(x.current,t||"",i||r||"text",p||"");(E=j.current)==null||E.setModel({original:d,modified:m})},[r,t,i,e,n,c,p]),K=o.useCallback(()=>{var d;!R.current&&D.current&&(j.current=x.current.editor.createDiffEditor(D.current,{automaticLayout:!0,...M}),V(),(d=x.current)==null||d.editor.setTheme(O),T(!0),R.current=!0)},[M,O,V]);o.useEffect(()=>{S&&C.current(j.current,x.current)},[S]),o.useEffect(()=>{!L&&!S&&K()},[L,S,K]);function A(){var m,E,P,z;let d=(m=j.current)==null?void 0:m.getModel();y||((E=d==null?void 0:d.original)==null||E.dispose()),b||((P=d==null?void 0:d.modified)==null||P.dispose()),(z=j.current)==null||z.dispose()}return J.createElement(Ce,{width:U,height:Y,isEditorReady:S,loading:N,_ref:D,className:q,wrapperProps:H})}var Vt=It;o.memo(Vt);function Ut(e){let t=o.useRef();return o.useEffect(()=>{t.current=e},[e]),t.current}var qt=Ut,ae=new Map;function Ht({defaultValue:e,defaultLanguage:t,defaultPath:r,value:n,language:i,path:c,theme:p="light",line:y,loading:b="Loading...",options:O={},overrideServices:N={},saveViewState:M=!0,keepCurrentModel:Y=!1,width:U="100%",height:q="100%",className:H,wrapperProps:W={},beforeMount:B=X,onMount:S=X,onChange:T,onValidate:L=X}){let[w,j]=o.useState(!1),[x,D]=o.useState(!0),C=o.useRef(null),h=o.useRef(null),R=o.useRef(null),V=o.useRef(S),K=o.useRef(B),A=o.useRef(),d=o.useRef(n),m=qt(c),E=o.useRef(!1),P=o.useRef(!1);Me(()=>{let f=Se.init();return f.then(g=>(C.current=g)&&D(!1)).catch(g=>(g==null?void 0:g.type)!=="cancelation"&&console.error("Monaco initialization: error:",g)),()=>h.current?se():f.cancel()}),k(()=>{var g,a,l,u;let f=G(C.current,e||n||"",t||i||"",c||r||"");f!==((g=h.current)==null?void 0:g.getModel())&&(M&&ae.set(m,(a=h.current)==null?void 0:a.saveViewState()),(l=h.current)==null||l.setModel(f),M&&((u=h.current)==null||u.restoreViewState(ae.get(c))))},[c],w),k(()=>{var f;(f=h.current)==null||f.updateOptions(O)},[O],w),k(()=>{!h.current||n===void 0||(h.current.getOption(C.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],w),k(()=>{var g,a;let f=(g=h.current)==null?void 0:g.getModel();f&&i&&((a=C.current)==null||a.editor.setModelLanguage(f,i))},[i],w),k(()=>{var f;y!==void 0&&((f=h.current)==null||f.revealLine(y))},[y],w),k(()=>{var f;(f=C.current)==null||f.editor.setTheme(p)},[p],w);let z=o.useCallback(()=>{var f;if(!(!R.current||!C.current)&&!E.current){K.current(C.current);let g=c||r,a=G(C.current,n||e||"",t||i||"",g||"");h.current=(f=C.current)==null?void 0:f.editor.create(R.current,{model:a,automaticLayout:!0,...O},N),M&&h.current.restoreViewState(ae.get(g)),C.current.editor.setTheme(p),y!==void 0&&h.current.revealLine(y),j(!0),E.current=!0}},[e,t,r,n,i,c,O,N,M,p,y]);o.useEffect(()=>{w&&V.current(h.current,C.current)},[w]),o.useEffect(()=>{!x&&!w&&z()},[x,w,z]),d.current=n,o.useEffect(()=>{var f,g;w&&T&&((f=A.current)==null||f.dispose(),A.current=(g=h.current)==null?void 0:g.onDidChangeModelContent(a=>{P.current||T(h.current.getValue(),a)}))},[w,T]),o.useEffect(()=>{if(w){let f=C.current.editor.onDidChangeMarkers(g=>{var l;let a=(l=h.current.getModel())==null?void 0:l.uri;if(a&&g.find(u=>u.path===a.path)){let u=C.current.editor.getModelMarkers({resource:a});L==null||L(u)}});return()=>{f==null||f.dispose()}}return()=>{}},[w,L]);function se(){var f,g;(f=A.current)==null||f.dispose(),Y?M&&ae.set(c,h.current.saveViewState()):(g=h.current.getModel())==null||g.dispose(),h.current.dispose()}return J.createElement(Ce,{width:U,height:q,isEditorReady:w,loading:b,_ref:R,className:H,wrapperProps:W})}var Wt=Ht,Bt=o.memo(Wt),Kt=Bt;function Qt(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 er(){const{t:e}=ze(),[t,r]=o.useState([]),[n,i]=o.useState(null),[c,p]=o.useState(""),[y,b]=o.useState(""),[O,N]=o.useState(!1),[M,Y]=o.useState(""),[U,q]=o.useState(!1),[H,W]=o.useState(!1),[B,S]=o.useState(!1),[T,L]=o.useState(""),w=o.useRef(null);o.useEffect(()=>{if(!n){p(""),b("");return}N(!0),Q.files.read(n).then(a=>{if(a.success&&a.data){const l=typeof a.data=="string"?a.data:JSON.stringify(a.data);p(l),b(l)}else F.error(a.error||e("fileTree.readFail"))}).catch(()=>F.error(e("fileTree.readFail"))).finally(()=>N(!1))},[n]);const j=async a=>{q(!0);try{const l=await Q.files.list(a);l.success&&Array.isArray(l.data)&&r(l.data.map(u=>({...u,expanded:!1})))}finally{q(!1)}},x=async a=>{if(a.type==="directory")try{const l=await Q.files.list(a.path);if(l.success&&Array.isArray(l.data)){const u=l.data.map(v=>({...v,expanded:!1}));r(v=>D(v,a.id,u))}}catch{}},D=(a,l,u)=>a.map(v=>v.id===l?{...v,children:u,expanded:!0}:v.children?{...v,children:D(v.children,l,u)}:v);o.useEffect(()=>{j()},[]);const C=a=>{const l=R(t,a);if(l&&l.type==="directory"&&!l.children){x(l);return}r(u=>h(u,a))},h=(a,l)=>a.map(u=>u.id===l&&u.type==="directory"?{...u,expanded:!u.expanded}:u.children?{...u,children:h(u.children,l)}:u),R=(a,l)=>{for(const u of a){if(u.id===l)return u;if(u.children){const v=R(u.children,l);if(v)return v}}return null},V=(a,l)=>l?a.reduce((u,v)=>{if(v.name.toLowerCase().includes(l.toLowerCase()))u.push(v);else if(v.children){const $=V(v.children,l);$.length>0&&u.push({...v,children:$,expanded:!0})}return u},[]):a,K=o.useCallback(async()=>{if(n){W(!0);try{const a=await Q.files.update(n,c);a.success?(b(c),F.success(e("fileTree.saved"))):F.error(a.error||e("fileTree.saveFail"))}catch{F.error(e("fileTree.saveFail"))}finally{W(!1)}}},[n,c,e]),A=()=>{i(null),p(""),b("")},d=o.useCallback(async a=>{const l=await Q.files.download(a);l.success?F.success(e("fileTree.downloadStarted")):F.error(l.error||e("fileTree.downloadFail"))},[e]),m=()=>{var a;return(a=w.current)==null?void 0:a.click()},E=o.useCallback(async a=>{if(!a||a.length===0)return;const l=T||(n?n.replace(/[\\/][^\\/]+$/,""):"");S(!0);let u=0,v=0;for(const $ of Array.from(a)){const te=l?`${l}/${$.name}`:$.name;(await Q.files.upload($,te)).success?u++:v++}S(!1),u>0&&F.success(e("fileTree.uploadedCount",{count:u})),v>0&&F.error(e("fileTree.uploadFailedCount",{count:v})),await j()},[T,n,e]),P=c!==y,z=()=>P?typeof window>"u"||typeof window.confirm!="function"?!1:window.confirm(e("fileTree.discardConfirm",{file:n||""})):!0,se=()=>{z()&&A()},f=(a,l=0)=>{var te;const u=a.type==="directory",v=n===a.path,$=T===a.path;return s.jsxs("div",{children:[s.jsxs("div",{className:`group flex items-center gap-1 px-2 py-0.5 cursor-pointer rounded text-xs transition-colors ${v?"bg-accent-blue/20 text-accent-blue":$?"bg-accent-blue/10":"hover:bg-dark-hover"}`,style:{paddingLeft:`${l*14+6}px`},onClick:()=>u?(L(a.path),C(a.id)):i(a.path),title:u?e("fileTree.setUploadDirHint"):a.path,children:[u&&s.jsx("span",{className:"text-dark-muted shrink-0",children:a.expanded?s.jsx(Fe,{size:12}):s.jsx(De,{size:12})}),u?s.jsx(Ae,{size:12,className:"text-accent-yellow shrink-0"}):s.jsx("span",{className:"w-3"}),s.jsx("span",{className:"truncate flex-1",children:a.name}),!u&&s.jsx("button",{onClick:re=>{re.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:s.jsx(fe,{size:11})})]}),u&&a.expanded&&((te=a.children)==null?void 0:te.map(re=>f(re,l+1)))]},a.id)},g=M?V(t,M):t;return s.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[s.jsxs("div",{className:pe("flex flex-col overflow-hidden flex-1 min-h-0",n&&"hidden"),children:[s.jsx("div",{className:"flex items-center justify-between px-3 py-2 border-b border-dark-border",children:s.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[s.jsx("button",{onClick:m,disabled:B,className:"p-1 rounded hover:bg-dark-hover disabled:opacity-50",title:T?e("fileTree.uploadTo",{dir:T}):e("fileTree.uploadToRoot"),children:s.jsx(Ne,{size:12,className:B?"animate-pulse":""})}),s.jsx("button",{onClick:()=>j(),disabled:U,className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.refresh"),children:s.jsx(Te,{size:12,className:U?"animate-spin":""})}),s.jsx("button",{onClick:()=>{z()&&(r(t.map(a=>({...a,expanded:!1}))),A())},className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.collapse"),children:s.jsx(Pe,{size:12})})]})}),s.jsx("div",{className:"p-1.5 border-b border-dark-border",children:s.jsxs("div",{className:"relative",children:[s.jsx(Ee,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),s.jsx("input",{type:"text",value:M,onChange:a=>Y(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"})]})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar py-1",children:g.map(a=>f(a))}),s.jsx("input",{ref:w,type:"file",multiple:!0,className:"hidden",onChange:a=>{E(a.target.files),a.currentTarget.value=""}})]}),s.jsx("div",{className:pe("flex-1 flex flex-col min-w-0 bg-dark-bg",!n&&"hidden"),children:n?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-dark-border bg-dark-surface",children:[s.jsxs("div",{className:"flex items-center gap-2 text-xs min-w-0",children:[s.jsx("button",{onClick:se,className:"p-0.5 -ml-1 rounded hover:bg-dark-hover text-dark-muted hover:text-dark-text shrink-0",title:e("fileTree.backToList"),"aria-label":e("fileTree.backToList"),"data-testid":"file-tree-back",children:s.jsx(Le,{size:13})}),s.jsx(de,{size:12,className:"text-dark-muted shrink-0"}),s.jsx("span",{className:"truncate",children:n}),P&&s.jsxs("span",{className:"text-accent-yellow text-[10px] shrink-0",children:["● ",e("fileTree.modified")]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs("button",{onClick:K,disabled:!P||H,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:[s.jsx(Re,{size:10}),e(H?"fileTree.saving":"fileTree.save")]}),s.jsx("button",{onClick:()=>void d(n),className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.download"),children:s.jsx(fe,{size:12})})]})]}),s.jsx("div",{className:"flex-1 min-h-0",children:O?s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx("div",{className:"w-4 h-4 border-2 border-accent-blue border-t-transparent rounded-full animate-spin"})}):s.jsx(Kt,{language:Qt(n),value:c,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}})})]}):s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx(de,{size:32,className:"text-dark-muted mx-auto mb-2"}),s.jsx("p",{className:"text-sm text-dark-muted",children:e("fileTree.selectFileHint")})]})})})]})}export{er as FileTreeView};
11
+ `},ye=ut(ht)(xe),mt={config:ft},gt=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return function(i){return r.reduceRight(function(c,p){return p(c)},i)}};function we(e,t){return Object.keys(t).forEach(function(r){t[r]instanceof Object&&e[r]&&Object.assign(t[r],we(e[r],t[r]))}),ge(ge({},e),t)}var vt={type:"cancelation",msg:"operation is manually canceled"};function ce(e){var t=!1,r=new Promise(function(n,i){e.then(function(c){return t?i(vt):n(c)}),e.catch(i)});return r.cancel=function(){return t=!0},r}var bt=["monaco"],yt=ct.create({config:lt,isInitialized:!1,resolve:null,reject:null,monaco:null}),je=We(yt,2),ee=je[0],oe=je[1];function xt(e){var t=mt.config(e),r=t.monaco,n=qe(t,bt);oe(function(i){return{config:we(i.config,n),monaco:r}})}function wt(){var e=ee(function(t){var r=t.monaco,n=t.isInitialized,i=t.resolve;return{monaco:r,isInitialized:n,resolve:i}});if(!e.isInitialized){if(oe({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),ce(le);if(window.monaco&&window.monaco.editor)return Oe(window.monaco),e.resolve(window.monaco),ce(le);gt(jt,St)(Ct)}return ce(le)}function jt(e){return document.body.appendChild(e)}function Ot(e){var t=document.createElement("script");return e&&(t.src=e),t}function St(e){var t=ee(function(n){var i=n.config,c=n.reject;return{config:i,reject:c}}),r=Ot("".concat(t.config.paths.vs,"/loader.js"));return r.onload=function(){return e()},r.onerror=t.reject,r}function Ct(){var e=ee(function(r){var n=r.config,i=r.resolve,c=r.reject;return{config:n,resolve:i,reject:c}}),t=window.require;t.config(e.config),t(["vs/editor/editor.main"],function(r){var n=r.m||r;Oe(n),e.resolve(n)},function(r){e.reject(r)})}function Oe(e){ee().monaco||oe({monaco:e})}function Mt(){return ee(function(e){var t=e.monaco;return t})}var le=new Promise(function(e,t){return oe({resolve:e,reject:t})}),Se={config:xt,init:wt,__getMonacoInstance:Mt},kt={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},ue=kt,Nt={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},Tt=Nt;function Pt({children:e}){return Y.createElement("div",{style:Tt.container},e)}var Et=Pt,Lt=Et;function Rt({width:e,height:t,isEditorReady:r,loading:n,_ref:i,className:c,wrapperProps:p}){return Y.createElement("section",{style:{...ue.wrapper,width:e,height:t},...p},!r&&Y.createElement(Lt,null,n),Y.createElement("div",{ref:i,style:{...ue.fullWidth,...!r&&ue.hide},className:c}))}var Ft=Rt,Ce=o.memo(Ft);function Dt(e){o.useEffect(e,[])}var Me=Dt;function At(e,t,r=!0){let n=o.useRef(!0);o.useEffect(n.current||!r?()=>{n.current=!1}:e,t)}var k=At;function X(){}function Q(e,t,r,n){return zt(e,n)||$t(e,t,r,n)}function zt(e,t){return e.editor.getModel(ke(e,t))}function $t(e,t,r,n){return e.editor.createModel(t,r,n?ke(e,n):void 0)}function ke(e,t){return e.Uri.parse(t)}function It({original:e,modified:t,language:r,originalLanguage:n,modifiedLanguage:i,originalModelPath:c,modifiedModelPath:p,keepCurrentOriginalModel:y=!1,keepCurrentModifiedModel:b=!1,theme:O="light",loading:N="Loading...",options:M={},height:J="100%",width:U="100%",className:q,wrapperProps:H={},beforeMount:W=X,onMount:B=X}){let[S,T]=o.useState(!1),[L,w]=o.useState(!0),j=o.useRef(null),x=o.useRef(null),D=o.useRef(null),C=o.useRef(B),h=o.useRef(W),R=o.useRef(!1);Me(()=>{let d=Se.init();return d.then(m=>(x.current=m)&&w(!1)).catch(m=>(m==null?void 0:m.type)!=="cancelation"&&console.error("Monaco initialization: error:",m)),()=>j.current?A():d.cancel()}),k(()=>{if(j.current&&x.current){let d=j.current.getOriginalEditor(),m=Q(x.current,e||"",n||r||"text",c||"");m!==d.getModel()&&d.setModel(m)}},[c],S),k(()=>{if(j.current&&x.current){let d=j.current.getModifiedEditor(),m=Q(x.current,t||"",i||r||"text",p||"");m!==d.getModel()&&d.setModel(m)}},[p],S),k(()=>{let d=j.current.getModifiedEditor();d.getOption(x.current.editor.EditorOption.readOnly)?d.setValue(t||""):t!==d.getValue()&&(d.executeEdits("",[{range:d.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),d.pushUndoStop())},[t],S),k(()=>{var d,m;(m=(d=j.current)==null?void 0:d.getModel())==null||m.original.setValue(e||"")},[e],S),k(()=>{let{original:d,modified:m}=j.current.getModel();x.current.editor.setModelLanguage(d,n||r||"text"),x.current.editor.setModelLanguage(m,i||r||"text")},[r,n,i],S),k(()=>{var d;(d=x.current)==null||d.editor.setTheme(O)},[O],S),k(()=>{var d;(d=j.current)==null||d.updateOptions(M)},[M],S);let V=o.useCallback(()=>{var E;if(!x.current)return;h.current(x.current);let d=Q(x.current,e||"",n||r||"text",c||""),m=Q(x.current,t||"",i||r||"text",p||"");(E=j.current)==null||E.setModel({original:d,modified:m})},[r,t,i,e,n,c,p]),G=o.useCallback(()=>{var d;!R.current&&D.current&&(j.current=x.current.editor.createDiffEditor(D.current,{automaticLayout:!0,...M}),V(),(d=x.current)==null||d.editor.setTheme(O),T(!0),R.current=!0)},[M,O,V]);o.useEffect(()=>{S&&C.current(j.current,x.current)},[S]),o.useEffect(()=>{!L&&!S&&G()},[L,S,G]);function A(){var m,E,P,z;let d=(m=j.current)==null?void 0:m.getModel();y||((E=d==null?void 0:d.original)==null||E.dispose()),b||((P=d==null?void 0:d.modified)==null||P.dispose()),(z=j.current)==null||z.dispose()}return Y.createElement(Ce,{width:U,height:J,isEditorReady:S,loading:N,_ref:D,className:q,wrapperProps:H})}var Vt=It;o.memo(Vt);function Ut(e){let t=o.useRef();return o.useEffect(()=>{t.current=e},[e]),t.current}var qt=Ut,ae=new Map;function Ht({defaultValue:e,defaultLanguage:t,defaultPath:r,value:n,language:i,path:c,theme:p="light",line:y,loading:b="Loading...",options:O={},overrideServices:N={},saveViewState:M=!0,keepCurrentModel:J=!1,width:U="100%",height:q="100%",className:H,wrapperProps:W={},beforeMount:B=X,onMount:S=X,onChange:T,onValidate:L=X}){let[w,j]=o.useState(!1),[x,D]=o.useState(!0),C=o.useRef(null),h=o.useRef(null),R=o.useRef(null),V=o.useRef(S),G=o.useRef(B),A=o.useRef(),d=o.useRef(n),m=qt(c),E=o.useRef(!1),P=o.useRef(!1);Me(()=>{let f=Se.init();return f.then(g=>(C.current=g)&&D(!1)).catch(g=>(g==null?void 0:g.type)!=="cancelation"&&console.error("Monaco initialization: error:",g)),()=>h.current?se():f.cancel()}),k(()=>{var g,a,l,u;let f=Q(C.current,e||n||"",t||i||"",c||r||"");f!==((g=h.current)==null?void 0:g.getModel())&&(M&&ae.set(m,(a=h.current)==null?void 0:a.saveViewState()),(l=h.current)==null||l.setModel(f),M&&((u=h.current)==null||u.restoreViewState(ae.get(c))))},[c],w),k(()=>{var f;(f=h.current)==null||f.updateOptions(O)},[O],w),k(()=>{!h.current||n===void 0||(h.current.getOption(C.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],w),k(()=>{var g,a;let f=(g=h.current)==null?void 0:g.getModel();f&&i&&((a=C.current)==null||a.editor.setModelLanguage(f,i))},[i],w),k(()=>{var f;y!==void 0&&((f=h.current)==null||f.revealLine(y))},[y],w),k(()=>{var f;(f=C.current)==null||f.editor.setTheme(p)},[p],w);let z=o.useCallback(()=>{var f;if(!(!R.current||!C.current)&&!E.current){G.current(C.current);let g=c||r,a=Q(C.current,n||e||"",t||i||"",g||"");h.current=(f=C.current)==null?void 0:f.editor.create(R.current,{model:a,automaticLayout:!0,...O},N),M&&h.current.restoreViewState(ae.get(g)),C.current.editor.setTheme(p),y!==void 0&&h.current.revealLine(y),j(!0),E.current=!0}},[e,t,r,n,i,c,O,N,M,p,y]);o.useEffect(()=>{w&&V.current(h.current,C.current)},[w]),o.useEffect(()=>{!x&&!w&&z()},[x,w,z]),d.current=n,o.useEffect(()=>{var f,g;w&&T&&((f=A.current)==null||f.dispose(),A.current=(g=h.current)==null?void 0:g.onDidChangeModelContent(a=>{P.current||T(h.current.getValue(),a)}))},[w,T]),o.useEffect(()=>{if(w){let f=C.current.editor.onDidChangeMarkers(g=>{var l;let a=(l=h.current.getModel())==null?void 0:l.uri;if(a&&g.find(u=>u.path===a.path)){let u=C.current.editor.getModelMarkers({resource:a});L==null||L(u)}});return()=>{f==null||f.dispose()}}return()=>{}},[w,L]);function se(){var f,g;(f=A.current)==null||f.dispose(),J?M&&ae.set(c,h.current.saveViewState()):(g=h.current.getModel())==null||g.dispose(),h.current.dispose()}return Y.createElement(Ce,{width:U,height:q,isEditorReady:w,loading:b,_ref:R,className:H,wrapperProps:W})}var Wt=Ht,Bt=o.memo(Wt),Gt=Bt;function Kt(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 er(){const{t:e}=ze(),[t,r]=o.useState([]),[n,i]=o.useState(null),[c,p]=o.useState(""),[y,b]=o.useState(""),[O,N]=o.useState(!1),[M,J]=o.useState(""),[U,q]=o.useState(!1),[H,W]=o.useState(!1),[B,S]=o.useState(!1),[T,L]=o.useState(""),w=o.useRef(null);o.useEffect(()=>{if(!n){p(""),b("");return}N(!0),K.files.read(n).then(a=>{if(a.success&&a.data){const l=typeof a.data=="string"?a.data:JSON.stringify(a.data);p(l),b(l)}else F.error(a.error||e("fileTree.readFail"))}).catch(()=>F.error(e("fileTree.readFail"))).finally(()=>N(!1))},[n]);const j=async a=>{q(!0);try{const l=await K.files.list(a);l.success&&Array.isArray(l.data)&&r(l.data.map(u=>({...u,expanded:!1})))}finally{q(!1)}},x=async a=>{if(a.type==="directory")try{const l=await K.files.list(a.path);if(l.success&&Array.isArray(l.data)){const u=l.data.map(v=>({...v,expanded:!1}));r(v=>D(v,a.id,u))}}catch{}},D=(a,l,u)=>a.map(v=>v.id===l?{...v,children:u,expanded:!0}:v.children?{...v,children:D(v.children,l,u)}:v);o.useEffect(()=>{j()},[]);const C=a=>{const l=R(t,a);if(l&&l.type==="directory"&&!l.children){x(l);return}r(u=>h(u,a))},h=(a,l)=>a.map(u=>u.id===l&&u.type==="directory"?{...u,expanded:!u.expanded}:u.children?{...u,children:h(u.children,l)}:u),R=(a,l)=>{for(const u of a){if(u.id===l)return u;if(u.children){const v=R(u.children,l);if(v)return v}}return null},V=(a,l)=>l?a.reduce((u,v)=>{if(v.name.toLowerCase().includes(l.toLowerCase()))u.push(v);else if(v.children){const $=V(v.children,l);$.length>0&&u.push({...v,children:$,expanded:!0})}return u},[]):a,G=o.useCallback(async()=>{if(n){W(!0);try{const a=await K.files.update(n,c);a.success?(b(c),F.success(e("fileTree.saved"))):F.error(a.error||e("fileTree.saveFail"))}catch{F.error(e("fileTree.saveFail"))}finally{W(!1)}}},[n,c,e]),A=()=>{i(null),p(""),b("")},d=o.useCallback(async a=>{const l=await K.files.download(a);l.success?F.success(e("fileTree.downloadStarted")):F.error(l.error||e("fileTree.downloadFail"))},[e]),m=()=>{var a;return(a=w.current)==null?void 0:a.click()},E=o.useCallback(async a=>{if(!a||a.length===0)return;const l=T||(n?n.replace(/[\\/][^\\/]+$/,""):"");S(!0);let u=0,v=0;for(const $ of Array.from(a)){const te=l?`${l}/${$.name}`:$.name;(await K.files.upload($,te)).success?u++:v++}S(!1),u>0&&F.success(e("fileTree.uploadedCount",{count:u})),v>0&&F.error(e("fileTree.uploadFailedCount",{count:v})),await j()},[T,n,e]),P=c!==y,z=()=>P?typeof window>"u"||typeof window.confirm!="function"?!1:window.confirm(e("fileTree.discardConfirm",{file:n||""})):!0,se=()=>{z()&&A()},f=(a,l=0)=>{var te;const u=a.type==="directory",v=n===a.path,$=T===a.path;return s.jsxs("div",{children:[s.jsxs("div",{className:`group flex items-center gap-1 px-2 py-0.5 cursor-pointer rounded text-xs transition-colors ${v?"bg-accent-blue/20 text-accent-blue":$?"bg-accent-blue/10":"hover:bg-dark-hover"}`,style:{paddingLeft:`${l*14+6}px`},onClick:()=>u?(L(a.path),C(a.id)):i(a.path),title:u?e("fileTree.setUploadDirHint"):a.path,children:[u&&s.jsx("span",{className:"text-dark-muted shrink-0",children:a.expanded?s.jsx(Fe,{size:12}):s.jsx(De,{size:12})}),u?s.jsx(Ae,{size:12,className:"text-accent-yellow shrink-0"}):s.jsx("span",{className:"w-3"}),s.jsx("span",{className:"truncate flex-1",children:a.name}),!u&&s.jsx("button",{onClick:re=>{re.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:s.jsx(fe,{size:11})})]}),u&&a.expanded&&((te=a.children)==null?void 0:te.map(re=>f(re,l+1)))]},a.id)},g=M?V(t,M):t;return s.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[s.jsxs("div",{className:pe("flex flex-col overflow-hidden flex-1 min-h-0",n&&"hidden"),children:[s.jsx("div",{className:"flex items-center justify-between px-3 py-2 border-b border-dark-border",children:s.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[s.jsx("button",{onClick:m,disabled:B,className:"p-1 rounded hover:bg-dark-hover disabled:opacity-50",title:T?e("fileTree.uploadTo",{dir:T}):e("fileTree.uploadToRoot"),children:s.jsx(Ne,{size:12,className:B?"animate-pulse":""})}),s.jsx("button",{onClick:()=>j(),disabled:U,className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.refresh"),children:s.jsx(Te,{size:12,className:U?"animate-spin":""})}),s.jsx("button",{onClick:()=>{z()&&(r(t.map(a=>({...a,expanded:!1}))),A())},className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.collapse"),children:s.jsx(Pe,{size:12})})]})}),s.jsx("div",{className:"p-1.5 border-b border-dark-border",children:s.jsxs("div",{className:"relative",children:[s.jsx(Ee,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),s.jsx("input",{type:"text",value:M,onChange:a=>J(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"})]})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar py-1",children:g.map(a=>f(a))}),s.jsx("input",{ref:w,type:"file",multiple:!0,className:"hidden",onChange:a=>{E(a.target.files),a.currentTarget.value=""}})]}),s.jsx("div",{className:pe("flex-1 flex flex-col min-w-0 bg-dark-bg",!n&&"hidden"),children:n?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-dark-border bg-dark-surface",children:[s.jsxs("div",{className:"flex items-center gap-2 text-xs min-w-0",children:[s.jsx("button",{onClick:se,className:"p-0.5 -ml-1 rounded hover:bg-dark-hover text-dark-muted hover:text-dark-text shrink-0",title:e("fileTree.backToList"),"aria-label":e("fileTree.backToList"),"data-testid":"file-tree-back",children:s.jsx(Le,{size:13})}),s.jsx(de,{size:12,className:"text-dark-muted shrink-0"}),s.jsx("span",{className:"truncate",children:n}),P&&s.jsxs("span",{className:"text-accent-yellow text-[10px] shrink-0",children:["● ",e("fileTree.modified")]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs("button",{onClick:G,disabled:!P||H,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:[s.jsx(Re,{size:10}),e(H?"fileTree.saving":"fileTree.save")]}),s.jsx("button",{onClick:()=>void d(n),className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.download"),children:s.jsx(fe,{size:12})})]})]}),s.jsx("div",{className:"flex-1 min-h-0",children:O?s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx("div",{className:"w-4 h-4 border-2 border-accent-blue border-t-transparent rounded-full animate-spin"})}):s.jsx(Gt,{language:Kt(n),value:c,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}})})]}):s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx(de,{size:32,className:"text-dark-muted mx-auto mb-2"}),s.jsx("p",{className:"text-sm text-dark-muted",children:e("fileTree.selectFileHint")})]})})})]})}export{er as FileTreeView};
@@ -0,0 +1 @@
1
+ import{j as e}from"./markdown-B2L4Mq-x.js";import{a as y,b4 as L,t as D,b5 as $,aP as B,X as z,j as G,ah as J,Y as W,b6 as _,aX as q,aY as X,k as V,aU as K,D as Q,am as Z}from"./icons-BxNxyk-c.js";import{c as ee}from"./state-0T92JV0u.js";import{a as j,u as E}from"./index-RB5ffy32.js";import"./react-vendor-B2V_5iSS.js";import"./panels-P_I7Q72_.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($,{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])]}))},U=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)},M=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,Y=[{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:Y.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:M,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:U,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(V,{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(K,{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(Q,{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(Z,{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};
@@ -0,0 +1 @@
1
+ import{j as e}from"./markdown-B2L4Mq-x.js";import{a as o,k as ne,aw as Hs,am as ke,a1 as de,X as $e,aO as Gs,e as se,aP as Fe,aQ as ps,aD as qs,m as _s,aR as Vs,aS as Ws,D as Ys,aI as Qs,a2 as xs,A as Js,aT as Xs}from"./icons-BxNxyk-c.js";import{a as j,u as Zs,t as M,f as ce,M as hs,P as et}from"./index-RB5ffy32.js";import"./react-vendor-B2V_5iSS.js";import"./state-0T92JV0u.js";import"./panels-P_I7Q72_.js";function st(){const[k,v]=o.useState([]),[C,t]=o.useState("1.0"),[P,Pe]=o.useState(!0),[g,ie]=o.useState(!0),[Te,X]=o.useState(null),Z=o.useCallback(async()=>{ie(!0),X(null);try{const N=await j.providers.presets();N.success&&N.data?(v(Array.isArray(N.data.providers)?N.data.providers:[]),t(N.data.version||"1.0"),Pe(N.data.customSupported!==!1)):X(N.error||"获取 Provider 列表失败")}catch(N){X(N instanceof Error?N.message:"未知错误")}finally{ie(!1)}},[]);return o.useEffect(()=>{Z()},[Z]),{presets:k,loading:g,error:Te,version:C,customSupported:P,reload:Z}}const tt=[{key:"global",labelKey:"chat.globalDefault",color:"text-accent-red",bg:"bg-accent-red/20"},{key:"goal",labelKey:"chat.goalDefault",color:"text-accent-purple",bg:"bg-accent-purple/20"}],at={providerKey:"",apiKeys:[],modelIds:"",baseUrl:"",apiType:"",fullPath:!1,setDefault:!1,modelOverrides:{}},bs=et,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 te(k){return k.trim().split("|")[0].trim()}function lt(k){const v=k.toLowerCase();return v.startsWith("claude-code://")||v.includes("/backend-api/codex")?v.startsWith("claude-code://")?"claude-code":"codex-responses":v.includes("/anthropic")||v.includes("/coding")||v.includes("/claude")||v.includes("/messages")?"anthropic-messages":v.includes("/responses")?"openai-responses":"openai-completions"}function ze(k){if(!k)return{};const v={};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&&(v[C.id]=t)}return v}const we={"opencode-free":5,"opencode-go":6,commandcode:7,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 ut(){var ls,rs,os,ns,ds,cs,is;const{presets:k,loading:v,reload:C}=st(),{t}=Zs(),[P,Pe]=o.useState([]),[g,ie]=o.useState(null),[Te,X]=o.useState(!0),[Z,N]=o.useState(null),[Ee,Le]=o.useState(null),[n,fs]=o.useState(null),[$,gs]=o.useState([]),[vs,V]=o.useState(!1),[Re,W]=o.useState("select"),[T,B]=o.useState(null),[i,f]=o.useState(at),[ys,L]=o.useState(""),[Oe,Be]=o.useState(!1),[He,R]=o.useState(null),[Se,ae]=o.useState(!1),[ue,Ge]=o.useState(!1),[le,me]=o.useState(""),[Me,qe]=o.useState(!1),[K,Y]=o.useState([]),[pe,F]=o.useState(new Set),[_e,H]=o.useState(null),[xe,re]=o.useState(""),[Ke,Ve]=o.useState(!1),[he,G]=o.useState(null),We=o.useMemo(()=>{const s=xe.trim().toLowerCase();return s?K.filter(a=>a.id.toLowerCase().includes(s)||a.name.toLowerCase().includes(s)):K},[K,xe]),Q=o.useCallback(async()=>{try{const s=await j.config.provider.get();s.success&&s.data&&(fs(s.data),gs(Array.isArray(s.data.entries)?s.data.entries:[]))}catch{}},[]),D=o.useCallback(async()=>{X(!0),N(null);try{const[s,a]=await Promise.all([j.models.list(),j.system.status()]);if(await Q(),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};ie({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{N(t("models.loadFailed"))}finally{X(!1)}},[Q,t]);o.useEffect(()=>{D()},[D]),o.useEffect(()=>{const s=()=>{D(),Q()};return window.addEventListener("models-updated",s),()=>window.removeEventListener("models-updated",s)},[D,Q]);const be=o.useCallback(s=>`${s.provider}:${s.id}`,[]),U=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]),fe=o.useMemo(()=>[...U].sort((s,a)=>{if(s.isCustom)return-1;if(a.isCustom)return 1;const l=we[s.key],d=we[a.key];return l!==void 0&&d!==void 0?l-d:l!==void 0?-1:d!==void 0?1:s.name.localeCompare(a.name)}),[U]),Ye=o.useMemo(()=>{const s=le.trim().toLowerCase();return s?fe.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))):fe},[fe,le]),O=o.useMemo(()=>{var d,r,c,u;const s=(n==null?void 0:n.providers)||{},a=new Set(U.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,[,b])=>m+(b.modelCount||0),0),hasApiKey:l.some(([,m])=>m.hasApiKey),baseUrl:((r=(d=l.find(([,m])=>m.baseUrl))==null?void 0:d[1])==null?void 0:r.baseUrl)||"",apiType:((u=(c=l.find(([,m])=>m.apiType))==null?void 0:c[1])==null?void 0:u.apiType)||"openai-completions"}},[n,U]),J=T==="custom"?i.providerKey.trim():T||"",De=o.useMemo(()=>J?P.filter(s=>s.provider===J):[],[P,J]),js=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 $)s.has(l.key)||s.set(l.key,[]);const a=[...s.keys()];return a.sort((l,d)=>{const r=we[l],c=we[d];return r!==void 0&&c!==void 0?r-c:r!==void 0?-1:c!==void 0?1:l.localeCompare(d)}),a.map(l=>({provider:l,models:s.get(l)||[]}))},[P,$]),Qe=o.useCallback(s=>{var u,m;const a=(u=n==null?void 0:n.providers)==null?void 0:u[s.key],l=$.find(b=>b.key===s.key),d=P.filter(b=>b.provider===s.key).map(b=>b.id),r=((m=s.models)==null?void 0:m.slice(0,3).join(", "))||s.defaultModel,c=d.length>0?d.join(", "):r;B(s.key),L(""),f({providerKey:s.key,apiKeys:[""],modelIds:c,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)}),W("form"),V(!0),R(null),ae(!1),Y([]),F(new Set),H(null),re("")},[P,n,$]),ks=o.useCallback(s=>{var r;const a=(r=n==null?void 0:n.providers)==null?void 0:r[s],l=$.find(c=>c.key===s),d=P.filter(c=>c.provider===s).map(c=>c.id).join(", ");B("custom"),L(s),f({providerKey:s,apiKeys:[""],modelIds:d,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)}),R(null),ae(!1),Y([]),F(new Set),H(null),re("")},[n,P,$]),Ue=o.useCallback(()=>{B("custom"),L(""),f({providerKey:"",apiKeys:[""],modelIds:"",baseUrl:"",apiType:"",fullPath:!1,setDefault:!(n!=null&&n.configured),modelOverrides:{}}),W("form"),V(!0),R(null),ae(!1),Y([]),F(new Set),H(null),re("")},[n]),Ns=o.useCallback(async()=>{var d;const s=i.baseUrl;if(!s){H(t("models.baseUrlRequired"));return}qe(!0),H(null),Y([]),F(new Set);const a=U.find(r=>r.key===T)||null,l=!!a&&!a.isCustom&&(i.baseUrl||"")===a.baseUrl&&i.fullPath!==!0;try{const r=(i.apiKeys||[]).map(m=>m.trim()).filter(Boolean)[0]||"",c=r.replace(/[^\x00-\xFF]/g,"");c!==r&&M.warning(t("models.apiKeySanitized"));const u=await j.models.fetch(s,c,i.fullPath===!0,l?a.key:void 0);if(u.success&&((d=u.data)!=null&&d.models)){const m=u.data.models;Y(m);const b={};for(const h of m)h.protocol&&h.protocol!==i.apiType&&(b[h.id]={apiType:h.protocol});Object.keys(b).length>0&&f(h=>{var p;const S={...h.modelOverrides};for(const[E,y]of Object.entries(b))(p=S[E])!=null&&p.apiType||(S[E]={...S[E]||{},...y});return{...h,modelOverrides:S}});const I=new Set(m.map(h=>h.id)),z=i.modelIds.split(",").map(h=>h.trim()).filter(Boolean),x=z.filter(h=>I.has(h.split("|")[0].trim())),q=z.filter(h=>!I.has(h.split("|")[0].trim()));if(F(new Set(x.map(h=>h.split("|")[0].trim()))),q.length>0){const h=q.map(S=>S.split("|")[0].trim());f(S=>({...S,modelIds:x.join(", ")})),M.warning(t("models.autoRemovedMissingModels",{models:h.join(", ")}))}M.success(t("models.fetchedCount",{n:m.length}))}else H(u.error||t("models.fetchFailed"))}catch(r){H(r instanceof Error?r.message:t("models.requestFailed"))}finally{qe(!1)}},[i.baseUrl,i.apiKeys,i.modelIds,i.apiType,i.fullPath,T,U,t]),ws=o.useCallback(async()=>{var a,l;const s=i.baseUrl;if(!s){G({ok:!1,message:t("models.baseUrlRequired")});return}Ve(!0),G(null);try{const d=(i.apiKeys||[]).map(u=>u.trim()).filter(Boolean)[0]||"",r=d.replace(/[^\x00-\xFF]/g,"");r!==d&&M.warning(t("models.apiKeySanitized"));const c=await j.providers.testConnection(s,r);if(c.success&&((a=c.data)!=null&&a.reachable)){const u=c.data,m={};u.resolvedBaseUrl&&u.resolvedBaseUrl!==i.baseUrl&&(m.baseUrl=u.resolvedBaseUrl),u.detectedApiType&&i.apiType===""&&(m.apiType=u.detectedApiType),Object.keys(m).length>0&&f(z=>({...z,...m}));const b=[];m.baseUrl&&b.push(t("models.baseUrlAutoCompleted",{url:m.baseUrl})),m.apiType&&b.push(t("models.apiTypeAutoSelected",{type:Ne[m.apiType]}));const I=u.message||t("models.connectionSuccess");G({ok:!0,message:b.length>0?t("models.connectionSuccessWithHints",{message:I,hints:b.join(t("models.hintJoiner"))}):I})}else G({ok:!1,message:((l=c.data)==null?void 0:l.message)||c.error||t("models.connectionFailed")})}catch(d){G({ok:!1,message:d instanceof Error?d.message:t("models.requestFailed")})}finally{Ve(!1)}},[i.baseUrl,i.apiKeys,i.apiType,t]),Cs=o.useCallback(s=>{const a=new Set(pe);a.has(s)?a.delete(s):a.add(s),F(a),f(l=>({...l,modelIds:Array.from(a).join(", ")}))},[pe]),Ps=o.useCallback(s=>{const a=i.modelIds.split(",").map(c=>c.trim()).filter(Boolean),d=a.some(c=>te(c)===s.id)?a.filter(c=>te(c)!==s.id):[...a,s.name&&s.name!==s.id?`${s.id}|${s.name}`:s.id];f(c=>({...c,modelIds:d.join(", ")}));const r=new Set(K.map(c=>c.id));F(new Set(d.map(te).filter(c=>r.has(c))))},[i.modelIds,K]),[Ts,Je]=o.useState(!1),[Ie,Xe]=o.useState(""),[Ze,ge]=o.useState([]),[Ss,es]=o.useState(!1),[ss,ve]=o.useState(null),[ye,Ms]=o.useState(!1),[je,Ks]=o.useState(!0),Ds=o.useCallback(()=>{Xe(""),ge([]),ve(null),Je(!0),oe("",{reason:!1,tool:!0})},[]),oe=o.useCallback(async(s,a)=>{es(!0),ve(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?ge(l.data.hits||[]):(ve(l.error||t("models.catalogSearchFailed")),ge([]))}catch(l){ve(l instanceof Error?l.message:t("models.requestFailed")),ge([])}finally{es(!1)}},[t]),Us=o.useCallback(s=>{f(a=>{const l=a.modelIds.split(",").map(d=>d.trim()).filter(Boolean);return l.includes(s.model.id)?a:{...a,modelIds:[...l,s.model.id].join(", ")}}),M.success(t("models.addedModel",{id:s.model.id}))},[t]),[Ae,Is]=o.useState(null),As=o.useCallback(s=>{Xe(s),Ae&&clearTimeout(Ae),Is(setTimeout(()=>{oe(s,{reason:ye,tool:je})},300))},[Ae,ye,je,oe]),$s=async s=>{const a=s.provider,l=s.id,d=s.enabled!==!1,r=s.name||l,c=u=>d&&/default model/i.test(u);try{const u=await j.models.toggle(a,l);if(u.success){await D();return}const m=u.error||"";c(m)?M.error(t("models.defaultModelDisableBlocked",{name:r})):M.error(m||t("models.operationFailed"))}catch(u){const m=u instanceof Error?u.message:"";c(m)?M.error(t("models.defaultModelDisableBlocked",{name:r})):M.error(m||t("models.operationFailed"))}},Fs=async s=>{const a=be(s);Le(a);try{await j.models.test(s.id),await D()}finally{Le(null)}},zs=async(s,a)=>{if(confirm(t("models.deleteModelConfirm",{id:a})))try{(await j.models.delete(s,a)).success&&await D()}catch{}},ts=o.useCallback(s=>{var c;const a=$.find(u=>u.key===s),l=U.find(u=>u.key===s),d=!l||l.isCustom,r=(c=n==null?void 0:n.providers)==null?void 0:c[s];B(d?"custom":s),L(d?s:""),f({providerKey:s,apiKeys:[""],modelIds:(a==null?void 0:a.models.map(u=>u.name&&u.name!==u.id?`${u.id}|${u.name}`:u.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)}),W("form"),V(!0),R(null),ae(!1),Y([]),F(new Set),H(null),re("")},[$,U,n]),Es=s=>{ts(s.provider)},Ls=async()=>{var h,S;const s=U.find(p=>p.key===T)||null,a=T==="custom"?i.providerKey.trim():(s==null?void 0:s.key)||"";if(!a){R(t("models.providerNameRequired"));return}const l=(i.apiKeys||[]).map(p=>p.trim()).filter(Boolean),d=!!((S=(h=n==null?void 0:n.providers)==null?void 0:h[a])!=null&&S.hasApiKey);if(l.length===0&&!d){R(t("models.apiKeyRequired"));return}const r=s||{baseUrl:"",apiType:"openai-completions",defaultModel:""},c=l.map(p=>p.replace(/[^\x00-\xFF]/g,"")).filter(Boolean),u=K.length>0?new Set(K.map(p=>p.id)):null,m=(i.modelIds||r.defaultModel||"").split(",").map(p=>p.trim()).filter(Boolean),b=u?m.filter(p=>u.has(p.split("|")[0].trim())):m,I=u?m.filter(p=>!u.has(p.split("|")[0].trim())):[];I.length>0&&M.warning(t("models.autoSkippedMissingModels",{models:I.map(p=>p.split("|")[0].trim()).join(", ")}));const z=b.map(te).filter(Boolean),x=new Set;for(const p of P)p.provider!==a||z.includes(p.id)||(p.isGlobalDefault&&x.add("global"),p.isGoalDefault&&x.add("goal"));const q={provider:a,name:a,baseUrl:i.baseUrl||r.baseUrl,fullPath:i.fullPath===!0,apiType:i.apiType||lt(i.baseUrl||r.baseUrl)||r.apiType,models:b.map((p,E)=>{var ms;const y=p.trim().split("|").map(Bs=>Bs.trim()).filter(Boolean),A=y[0]||"",w=i.modelOverrides[A],us=(w==null?void 0:w.apiType)||((ms=s==null?void 0:s.modelApiTypes)==null?void 0:ms[A]);return{id:A,name:y[1]||A,aliases:y.length>2?y.slice(2):void 0,enabled:!0,priority:10+E,...us?{apiType:us}:{},...w!=null&&w.baseUrl?{baseUrl:w.baseUrl}:{}}}).filter(p=>p.id.length>0)};c.length>0&&(q.apiKeys=c),(!(n!=null&&n.configured)||i.setDefault)&&(q.setDefault=!0),Be(!0),R(null);try{const p=await j.config.provider.save(q);if(p.success){if(x.size>0){const E=z[0]||"",y={};if(E){const A=`${a}:${E}`;for(const w of x)y[w]=A}else{const A=P.find(w=>w.provider!==a);for(const w of x)w==="goal"?y[w]=null:A&&(y[w]=`${A.provider}:${A.id}`)}Object.keys(y).length>0&&(await j.models.setDefaults(y)).success&&M.success(t("models.defaultsAutoUpdated"))}V(!1),W("select"),B(null),L(""),await Q(),await D()}else R(p.error||t("models.saveFailed"))}catch(p){R(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 Q(),await D()}catch{}},Rs=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"}},Os=s=>{switch(s){case"online":return e.jsx(Xs,{size:14});case"offline":return e.jsx(xs,{size:14});case"error":return e.jsx(Js,{size:14});default:return e.jsx(xs,{size:14})}},ee=o.useMemo(()=>U.find(s=>s.key===T)||null,[T,U]);return Te?e.jsx("div",{className:"flex h-64 items-center justify-center text-dark-muted",children:t("models.loading")}):Z?e.jsx("div",{className:"flex h-64 items-center justify-center text-accent-red",children:Z}):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(),M.success(t("models.providerListRefreshed")),Ge(!0),await C(),setTimeout(()=>{C()},3e3)}catch{M.error(t("models.refreshFailed"))}},className:"btn btn-secondary px-3 py-2 text-xs",title:t("models.refreshListTitle"),children:[e.jsx(ne,{size:12}),t("models.refreshList")]}),e.jsxs("button",{onClick:()=>{ue&&me(""),Ge(s=>!s)},className:"btn btn-accent px-3 py-2 text-xs",children:[ue?e.jsx(Hs,{size:12}):e.jsx(ke,{size:12}),t(ue?"models.collapse":"models.addProvider")]})]})]}),ue&&e.jsxs("div",{children:[e.jsxs("div",{className:"relative mb-3 max-w-md",children:[e.jsx(de,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:le,onChange:s=>me(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")}),le&&e.jsx("button",{onClick:()=>me(""),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($e,{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:v?e.jsxs("div",{className:"col-span-full flex items-center justify-center py-4 text-dark-muted text-sm",children:[e.jsx(Gs,{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:le})}),e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsxs("button",{onClick:()=>me(""),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($e,{size:12}),t("models.clearSearch")]}),e.jsxs("button",{onClick:Ue,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 c,u;const a=s.key==="custom",l=a?O:(c=n==null?void 0:n.providers)==null?void 0:c[s.key],d=l==null?void 0:l.hasApiKey,r=a?!!(n!=null&&n.defaultProvider)&&((O==null?void 0:O.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 ${d?"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"?Ue():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}),d&&e.jsx(se,{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&&O?`${O.keys.join(", ")}`:s.defaultModel||t("models.noDefaultModel")}),e.jsxs("div",{children:[l?t("models.configuredCount",{n:l.modelCount}):t("models.availableCount",{n:((u=s.models)==null?void 0:u.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")})]}),d&&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(Fe,{size:13})})]},s.key)})})]})]}),g&&e.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[e.jsx(Ce,{title:t("models.overallStatus"),value:g.totalInstances===0?t("models.notConfigured"):g.overallStatus==="healthy"?t("models.healthy"):g.overallStatus==="degraded"?t("models.degraded"):t("models.abnormal"),color:g.totalInstances===0?"blue":g.overallStatus==="healthy"?"green":g.overallStatus==="degraded"?"yellow":"red"}),e.jsx(Ce,{title:t("models.healthRate"),value:g.totalInstances===0?"N/A":`${(g.healthRate*100).toFixed(0)}%`,color:g.totalInstances===0?"blue":g.healthRate>.8?"green":g.healthRate>.5?"yellow":"red"}),e.jsx(Ce,{title:t("models.onlineInstances"),value:g.totalInstances===0?t("models.none"):`${g.healthyInstances}/${g.totalInstances}`,color:g.healthyInstances>0?"green":"red"}),e.jsx(Ce,{title:t("models.totalRequests"),value:g.totalRequests>0?g.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:[js.map(s=>{var d;const a=$.find(r=>r.key===s.provider),l=(d=n==null?void 0:n.providers)==null?void 0:d[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(ps,{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(Fe,{size:13})})]})]}),e.jsxs("div",{className:"space-y-2 p-2 bg-dark-surface/40",children:[s.models.map(r=>{var m,b,I,z;const c=a==null?void 0:a.models.find(x=>x.id===r.id),u=!!(c!=null&&c.apiType&&c.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:Rs(r.status),children:Os(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}),u&&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.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(_,{label:t("models.loadLabel"),value:`${r.load}/${r.maxLoad}`}),e.jsx(_,{label:t("models.tokenUsageLabel"),value:`${ce(r.tokens)}/${ce(r.maxTokens)}`}),e.jsx(_,{label:t("models.inputPrice"),value:`$${r.price.input}/M`}),e.jsx(_,{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(_,{label:t("models.inputTokensLabel"),value:ce(((m=r.usage)==null?void 0:m.input)??0)}),e.jsx(_,{label:t("models.outputTokensLabel"),value:ce(((b=r.usage)==null?void 0:b.output)??0)}),e.jsx(_,{label:t("models.totalTokensLabel"),value:ce(((I=r.usage)==null?void 0:I.total)??0)}),e.jsx(_,{label:t("models.usageRequestsLabel"),value:String(((z=r.usage)==null?void 0:z.requests)??0)})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[tt.map(x=>{const q=x.key==="global"?r.isGlobalDefault:r.isGoalDefault,h=x.key==="global"?t("models.setGlobalDefaultTitle"):t("models.setGoalDefaultTitle"),S=t("models.unsetGoalDefaultTitle"),p=t("models.unsetGoalDefaultFailed"),E=t("models.setGoalDefaultFailed");return q?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(se,{size:11}),t(x.labelKey)]},x.key):e.jsxs("button",{onClick:async()=>{try{await j.models.setDefaults({[x.key]:null}),await D()}catch(y){N(y instanceof Error?y.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:S,children:[e.jsx(se,{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 D()}catch(y){N(y instanceof Error?y.message:E)}},className:"px-2 py-1 rounded text-[10px] border border-dark-border text-dark-muted hover:text-dark-text hover:border-dark-hover",title:h,children:t(x.labelKey)},x.key)}),e.jsx("button",{onClick:()=>Es(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(ps,{size:13})}),e.jsx("button",{onClick:()=>zs(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(Fe,{size:13})}),e.jsx("button",{onClick:()=>Fs(r),disabled:Ee===be(r),className:"p-1.5 rounded hover:bg-dark-hover disabled:opacity-50",title:t("models.refresh"),children:e.jsx(ne,{size:13,className:Ee===be(r)?"animate-spin":""})}),e.jsx("button",{onClick:()=>$s(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")})]})]})},be(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&&$.length===0&&e.jsxs("div",{className:"text-center text-dark-muted py-6",children:[e.jsx(qs,{size:36,className:"mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:t("models.emptyHint")})]})]})]}),e.jsx(hs,{isOpen:vs,onClose:()=>{V(!1),W("select"),B(null),L("")},title:Re==="select"?t("chat.selectProvider"):(ee==null?void 0:ee.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:[fe.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(se,{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:Ue,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(_s,{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:[T==="custom"&&e.jsxs("div",{className:"space-y-3",children:[O&&O.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:ys,onChange:s=>{const a=s.target.value;a?ks(a):(L(""),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")}),O.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:i.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[T==="custom"?i.providerKey.trim():T||""])!=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[T==="custom"?i.providerKey.trim():T||""])!=null&&ns.hasApiKey?t("models.apiKeysHintConfigured"):t("models.apiKeysHintNew")})]}),e.jsx("div",{className:"space-y-1.5",children:((ds=i.apiKeys)!=null&&ds.length?i.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:Se?"text":"password",value:s,autoComplete:"off",spellCheck:!1,onChange:l=>f(d=>({...d,apiKeys:d.apiKeys.map((r,c)=>c===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:()=>ae(l=>!l),className:"absolute right-2 top-1/2 -translate-y-1/2 text-dark-muted hover:text-white",title:t(Se?"models.hideKeyTitle":"models.showKeyTitle"),children:Se?e.jsx(Vs,{size:14}):e.jsx(Ws,{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((d,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($e,{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:i.modelIds,onChange:s=>{const a=s.target.value;f(l=>({...l,modelIds:a})),F(()=>{const l=new Set;for(const d of a.split(",")){const r=d.trim().split("|")[0].trim();r&&K.some(c=>c.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:(ee==null?void 0:ee.defaultModel)||t("models.modelIdPlaceholder")}),e.jsxs("button",{onClick:Ns,disabled:Me||!i.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:[Me?e.jsx(ne,{size:13,className:"animate-spin"}):e.jsx(Ys,{size:13}),t(Me?"models.fetchingModels":"models.fetchModels")]}),e.jsxs("button",{onClick:ws,disabled:Ke||!i.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:[Ke?e.jsx(ne,{size:13,className:"animate-spin"}):e.jsx(Qs,{size:13}),t(Ke?"models.testingConnection":"models.testConnection")]}),e.jsxs("button",{onClick:Ds,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(de,{size:13}),t("models.catalogSearch")]})]}),he&&e.jsxs("div",{className:`mt-1 text-xs ${he.ok?"text-accent-green":"text-accent-red"}`,children:[he.ok?"✓ ":"✗ ",he.message]}),_e&&e.jsx("div",{className:"mt-1 text-xs text-accent-red",children:_e}),K.length===0&&De.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:De.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:De.map(s=>{const a=i.modelIds.split(",").map(te).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:()=>Ps(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(se,{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.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)})})]}),K.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:K.length}),t("models.fetchedPanelMiddle"),e.jsx("strong",{className:"text-accent-blue",children:pe.size}),t("models.fetchedPanelSuffix"),e.jsx("span",{className:"text-accent-blue/70",children:t("models.fetchedPanelHint")})]}),e.jsx("button",{onClick:()=>{Y([]),F(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(de,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:xe,onChange:s=>re(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")})]}),xe.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:K.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=pe.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:()=>Cs(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(se,{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:i.baseUrl,onChange:s=>{f(a=>({...a,baseUrl:s.target.value})),G(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":i.fullPath,onClick:()=>{f(s=>({...s,fullPath:!s.fullPath})),G(null)},className:`relative w-9 h-5 rounded-full transition-colors shrink-0 ${i.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 ${i.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:i.apiType,onChange:s=>{f(a=>({...a,apiType:s.target.value})),G(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")}),bs.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=i.modelIds.split(",").map(te).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=i.modelOverrides[a])==null?void 0:l.apiType)||"",onChange:d=>f(r=>({...r,modelOverrides:{...r.modelOverrides,[a]:{...r.modelOverrides[a]||{},apiType:d.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(默认)"}),bs.map(d=>e.jsx("option",{value:d,children:Ne[d]},d))]})]},a)})})()})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:i.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:J&&((is=(cs=n==null?void 0:n.providers)==null?void 0:cs[J])==null?void 0:is.hasApiKey)&&e.jsx("button",{onClick:async()=>{if(confirm(t("models.deleteProviderConfirm",{key:J})))try{await j.config.provider.delete(J),V(!1),W("select"),B(null),L(""),await Q(),await D()}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:()=>{W("select"),B(null),L(""),V(!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:Ls,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(hs,{isOpen:Ts,onClose:()=>Je(!1),title:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(de,{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(de,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:Ie,onChange:s=>As(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:je,onChange:s=>{const a=s.target.checked;Ks(a),oe(Ie,{reason:ye,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:ye,onChange:s=>{const a=s.target.checked;Ms(a),oe(Ie,{reason:a,tool:je})},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}),Ss?e.jsxs("div",{className:"flex items-center justify-center py-10 text-dark-muted",children:[e.jsx(ne,{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,d;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)})}`:"",((d=s.model.cost)==null?void 0:d.input)!==void 0?` · $${s.model.cost.input}/M in / $${s.model.cost.output}/M out`:""]})]}),e.jsxs("button",{onClick:()=>Us(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:v,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:v})]})}function _({label:k,value:v}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-dark-muted",children:k}),e.jsx("div",{children:v})]})}export{ut as ModelsView,ut as default};
@@ -0,0 +1 @@
1
+ import{j as t}from"./markdown-B2L4Mq-x.js";import{a as s,aI as be,k as me,a1 as ge,X as J,A as he,n as W,a0 as ke,bB as ve,aP as fe,D as ee,ah as je,Y as ye}from"./icons-BxNxyk-c.js";import{u as Ne,at as p,C as Ce}from"./index-RB5ffy32.js";import"./react-vendor-B2V_5iSS.js";import"./state-0T92JV0u.js";import"./panels-P_I7Q72_.js";const E=12,we="other",Se=[{value:"all"},{value:"builtin"},{value:"openclaw"},{value:"deepseek-harness"}];function Pe(a){return a==="wired"?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":a==="pending"||a==="pending_wiring"?"bg-amber-500/15 text-amber-400 border-amber-500/30":"bg-dark-hover text-dark-muted border-dark-border"}function te(a){var n;return((n=a.category)==null?void 0:n.trim())||we}function $e(a,n){const f=n.trim().toLowerCase();return f?[a.id,a.name,a.description,a.category,...a.tags??[]].filter(S=>typeof S=="string").join(" ").toLowerCase().includes(f):!0}function Re(){const{t:a}=Ne(),[n,f]=s.useState("installed"),[b,S]=s.useState([]),[R,re]=s.useState([]),[F,ae]=s.useState(null),[j,B]=s.useState(!0),[P,L]=s.useState(null),[i,O]=s.useState(null),[$,U]=s.useState(null),[y,V]=s.useState(null),[N,M]=s.useState(null),[_,D]=s.useState(null),[m,q]=s.useState(""),[o,se]=s.useState(null),[c,le]=s.useState(null),[u,z]=s.useState(1),x=s.useCallback((e,r)=>{V({kind:e,text:r}),window.setTimeout(()=>V(null),4e3)},[]),g=s.useCallback(async()=>{B(!0),L(null);const[e,r]=await Promise.all([p.get("/api/plugins"),p.get("/api/plugins/market")]);e.success&&e.data?(S(e.data.plugins),ae(e.data.schemaVersion??null)):L(e.error??"Failed to load plugins"),r.success&&r.data&&re(r.data.plugins),B(!1)},[]);s.useEffect(()=>{g()},[g]);const T=s.useMemo(()=>b.filter(e=>e.installable!==!0),[b]),h=s.useMemo(()=>[...b.filter(e=>e.installable===!0),...R.filter(e=>!b.some(r=>r.id===e.id||r.marketId===e.id))],[b,R]),C=s.useCallback(e=>e.filter(r=>o&&te(r)!==o||c&&(r.market??null)!==c?!1:$e(r,m)),[o,m,c]),k=s.useMemo(()=>C(T),[C,T]),v=s.useMemo(()=>C(h),[C,h]),G=s.useMemo(()=>{const e=new Set;for(const r of h)e.add(te(r));return["all",...Array.from(e).sort()]},[h]),Y=e=>Math.max(1,Math.ceil(e/E)),H=(e,r)=>e.slice((r-1)*E,r*E),A=Y(k.length),I=Y(v.length),ne=s.useMemo(()=>H(k,Math.min(u,A)),[k,u,A]),de=s.useMemo(()=>H(v,Math.min(u,I)),[v,u,I]);s.useEffect(()=>{z(1)},[n,m,o,c]);const ie=m.trim().length>0||o!==null||c!==null,w=s.useCallback(async(e,r,d)=>{O(e),U(r);try{const l=await d();l&&l.success===!1?x("err",String(l.error??"Request failed")):(x("ok",`${r} ${e} ✓`),await g())}catch(l){x("err",l instanceof Error?l.message:String(l))}finally{O(null),U(null)}},[g,x]),K=(e,r)=>w(e,r?"installed+activated":"installed",()=>p.post("/api/plugins/install",{id:e,activate:r})),oe=e=>w(e,"activated",()=>p.post(`/api/plugins/${encodeURIComponent(e)}/activate`)),ce=e=>w(e,"deactivated",()=>p.post(`/api/plugins/${encodeURIComponent(e)}/deactivate`)),ue=e=>w(e,"uninstalled",()=>p.delete(`/api/plugins/${encodeURIComponent(e)}`)),xe=async e=>{D(e);try{const r=await p.post(`/api/plugins/l2/provider/${encodeURIComponent(e)}`);r.success&&r.data?(x("ok",`Provider ${r.data.applied} applied to config ✓`),await g()):x("err",r.error??"Apply failed")}catch(r){x("err",r instanceof Error?r.message:String(r))}finally{D(null)}},Q=e=>{const r=e==="bundled"?"bg-blue-500/15 text-blue-400 border-blue-500/30":e==="npm"?"bg-purple-500/15 text-purple-400 border-purple-500/30":e==="local"?"bg-cyan-500/15 text-cyan-400 border-cyan-500/30":"bg-dark-hover text-dark-muted border-dark-border";return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[11px] border ${r}`,children:e})},pe=e=>{if(!e)return null;const r=e==="builtin"?"bg-dark-hover text-dark-muted border-dark-border":e==="openclaw"?"bg-amber-500/15 text-amber-400 border-amber-500/30":e==="deepseek-harness"?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":"bg-dark-hover text-dark-muted border-dark-border";return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[11px] border ${r}`,children:e})},X=(e,r)=>r>1?t.jsxs("div",{className:"flex items-center justify-center gap-3 pt-3 pb-1 select-none",children:[t.jsxs("button",{onClick:()=>z(d=>Math.max(1,d-1)),disabled:u<=1,className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border bg-dark-hover text-dark-muted text-[11px] hover:text-dark-text disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:[t.jsx(je,{size:12})," ",a("plugins.prevPage")]}),t.jsx("span",{className:"text-[11px] text-dark-muted",children:a("plugins.pageInfo",{page:Math.min(u,r),pages:r,count:e})}),t.jsxs("button",{onClick:()=>z(d=>Math.min(r,d+1)),disabled:u>=r,className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border bg-dark-hover text-dark-muted text-[11px] hover:text-dark-text disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:[a("plugins.nextPage")," ",t.jsx(ye,{size:12})]})]}):null,Z=e=>t.jsx("div",{className:"mt-8 text-center text-[12px] text-dark-muted",children:ie?a("plugins.noMatch"):e});return t.jsxs("div",{className:"h-full flex flex-col min-h-0 bg-dark-bg",children:[t.jsxs("div",{className:"h-11 flex items-center gap-2 px-3 border-b border-dark-border bg-dark-bg shrink-0 select-none",children:[t.jsx(be,{size:15,className:"text-accent-blue"}),t.jsx("span",{className:"truncate text-[13px] font-medium text-dark-text",children:a("nav.plugins")}),F!==null&&t.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[10px] bg-dark-hover text-dark-muted border border-dark-border",children:["schema v",F]}),t.jsx("div",{className:"flex-1"}),t.jsx("button",{onClick:()=>void g(),className:"p-1.5 rounded hover:bg-dark-hover text-dark-muted hover:text-dark-text transition-colors",title:"Refresh",children:t.jsx(me,{size:14,className:j?"animate-spin":""})})]}),t.jsx("div",{className:"flex items-center gap-1 px-3 pt-2 shrink-0",children:["installed","available"].map(e=>t.jsx("button",{onClick:()=>f(e),className:`px-3 py-1.5 rounded-t text-[12px] transition-colors ${n===e?"bg-dark-surface text-accent-blue border border-b-0 border-dark-border":"text-dark-muted hover:text-dark-text"}`,children:e==="installed"?a("plugins.installedTab",{count:T.length}):a("plugins.availableTab",{count:h.length})},e))}),t.jsxs("div",{className:"shrink-0 px-3 pt-2 pb-1 space-y-2 bg-dark-bg",children:[t.jsxs("div",{className:"relative",children:[t.jsx(ge,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted pointer-events-none"}),t.jsx("input",{value:m,onChange:e=>q(e.target.value),placeholder:a("plugins.searchPlaceholder"),className:"w-full pl-8 pr-8 py-1.5 rounded bg-dark-hover border border-dark-border text-[12px] text-dark-text placeholder-dark-muted outline-none focus:border-accent-blue/50 transition-colors"}),m&&t.jsx("button",{onClick:()=>q(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-dark-muted hover:text-dark-text transition-colors",title:a("plugins.clear"),children:t.jsx(J,{size:12})})]}),n==="available"&&G.length>2&&t.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:G.map(e=>t.jsx("button",{onClick:()=>se(e==="all"?null:e),className:`px-2 py-0.5 rounded-full text-[11px] border transition-colors ${e==="all"&&o===null||o===e?"bg-accent-blue/20 text-accent-blue border-accent-blue/40":"bg-dark-hover text-dark-muted border-dark-border hover:text-dark-text"}`,children:e==="all"?a("plugins.allCategories"):e},e))}),n==="available"&&t.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:Se.map(e=>{const r=e.value==="all"?a("plugins.marketFilterAll"):e.value==="builtin"?a("plugins.marketFilterBuiltin"):e.value;return t.jsx("button",{onClick:()=>le(e.value==="all"?null:e.value),className:`px-2 py-0.5 rounded-full text-[11px] border transition-colors ${e.value==="all"&&c===null||c===e.value?"bg-accent-blue/20 text-accent-blue border-accent-blue/40":"bg-dark-hover text-dark-muted border-dark-border hover:text-dark-text"}`,children:r},e.value)})})]}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-3 pb-4",children:[P&&t.jsxs("div",{className:"mt-3 flex items-center gap-2 px-3 py-2 rounded bg-red-500/10 border border-red-500/30 text-red-400 text-[12px]",children:[t.jsx(he,{size:14})," ",P]}),j&&!P&&t.jsx("div",{className:"mt-10 flex justify-center",children:t.jsx("div",{className:"w-5 h-5 border-2 border-accent-blue border-t-transparent rounded-full animate-spin"})}),!j&&n==="installed"&&t.jsxs("div",{className:"mt-3 space-y-2",children:[k.length===0&&Z(a("plugins.emptyInstalled")),ne.map(e=>{const r=e.l2??[],d=e.status==="active";return t.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[13px] font-medium text-dark-text truncate",children:e.name||e.id}),e.version&&t.jsx("span",{className:"text-[11px] text-dark-muted shrink-0",children:e.version}),Q(e.source),t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[11px] border shrink-0 ${d?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":"bg-dark-hover text-dark-muted border-dark-border"}`,children:d?"active":"installed"}),e.httpMounted&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-[11px] bg-emerald-500/15 text-emerald-400 border border-emerald-500/30 shrink-0",children:"http mounted"}),t.jsx("div",{className:"flex-1"}),t.jsx("span",{className:"text-[11px] text-dark-muted font-mono shrink-0",children:e.id})]}),e.description&&t.jsx("p",{className:"mt-1 text-[12px] text-dark-muted",children:e.description}),r.length>0&&t.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5",children:[r.map(l=>t.jsxs("span",{title:l.note||l.id,className:`px-1.5 py-0.5 rounded text-[11px] border cursor-help ${Pe(l.status)}`,children:[l.kind," · ",l.status,l.status==="wired"&&t.jsx(W,{size:10,className:"inline ml-0.5"})]},`${l.kind}-${l.id}`)),r.filter(l=>l.kind==="provider"&&l.status==="wired").map(l=>t.jsx("button",{disabled:_===l.id,onClick:()=>void xe(l.id),className:"px-1.5 py-0.5 rounded text-[11px] border border-accent-blue/40 text-accent-blue hover:bg-accent-blue/10 disabled:opacity-50 transition-colors",title:a("plugins.applyProviderTitle"),children:_===l.id?"applying…":"apply provider"},`apply-${l.id}`))]}),t.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[d?t.jsxs("button",{onClick:()=>void ce(e.id),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-amber-500/15 border border-amber-500/30 text-amber-400 text-[11px] hover:bg-amber-500/25 disabled:opacity-50 transition-colors",children:[t.jsx(ke,{size:11})," ",i===e.id?`${$}…`:a("plugins.deactivate")]}):t.jsxs("button",{onClick:()=>void oe(e.id),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-emerald-500/15 border border-emerald-500/30 text-emerald-400 text-[11px] hover:bg-emerald-500/25 disabled:opacity-50 transition-colors",children:[t.jsx(ve,{size:11})," ",i===e.id?`${$}…`:a("plugins.activate")]}),t.jsxs("button",{onClick:()=>M(e.id),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-dark-hover border border-dark-border text-dark-muted text-[11px] hover:text-red-400 hover:border-red-500/40 disabled:opacity-50 transition-colors",children:[t.jsx(fe,{size:11})," ",a("plugins.uninstall")]})]})]},e.id)}),X(k.length,A)]}),!j&&n==="available"&&t.jsxs("div",{className:"mt-3 space-y-2",children:[v.length===0&&Z(a("plugins.emptyMarket")),de.map(e=>t.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[13px] font-medium text-dark-text truncate",children:e.name||e.id}),e.version&&t.jsx("span",{className:"text-[11px] text-dark-muted shrink-0",children:e.version}),Q(e.source),pe(e.market),e.category&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-[11px] bg-dark-hover text-dark-muted border border-dark-border shrink-0",children:e.category}),t.jsx("div",{className:"flex-1"}),t.jsx("span",{className:"text-[11px] text-dark-muted font-mono shrink-0",children:e.id})]}),e.description&&t.jsx("p",{className:"mt-1 text-[12px] text-dark-muted",children:e.description}),t.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[t.jsxs("button",{onClick:()=>void K(e.id,!0),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-accent-blue/20 border border-accent-blue/40 text-accent-blue text-[11px] hover:bg-accent-blue/30 disabled:opacity-50 transition-colors",children:[t.jsx(ee,{size:11})," ",i===e.id?`${$}…`:a("plugins.installActivate")]}),t.jsxs("button",{onClick:()=>void K(e.id,!1),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-dark-hover border border-dark-border text-dark-muted text-[11px] hover:text-dark-text disabled:opacity-50 transition-colors",children:[t.jsx(ee,{size:11})," ",a("plugins.installOnly")]})]})]},e.id)),X(v.length,I)]})]}),y&&t.jsxs("div",{className:`fixed bottom-4 right-4 z-50 flex items-center gap-2 px-3 py-2 rounded-lg border text-[12px] shadow-lg ${y.kind==="ok"?"bg-emerald-500/15 border-emerald-500/30 text-emerald-400":"bg-red-500/15 border-red-500/30 text-red-400"}`,children:[y.kind==="ok"?t.jsx(W,{size:13}):t.jsx(J,{size:13})," ",y.text]}),t.jsx(Ce,{isOpen:N!==null,title:a("plugins.uninstallTitle"),message:a("plugins.uninstallConfirm",{id:N??""}),onConfirm:()=>{N&&ue(N),M(null)},onClose:()=>M(null)})]})}export{Re as PluginsView};
@@ -0,0 +1 @@
1
+ import{j as e}from"./markdown-B2L4Mq-x.js";import{a as u,F as ae,C as ne,aR as oe,aF as me,f as he,Y as X,a4 as pe,n as je,X as de,bq as be,w as ge,bH as le,b7 as fe,A as Z,N as ke,aK as ye,aq as ve,ao as Ne,M as we,a1 as ue,ah as Ce,a0 as Se,k as Pe,bI as Ee}from"./icons-BxNxyk-c.js";import{au as h,av as Me,u as H,a1 as Q,c as N,aw as Ie,ax as z,ay as ze,az as Ae,aA as De,aB as Re,aC as Te,aD as Fe,aE as _e,aF as Be,aG as Le,aH as $e,aI as He,t as L,N as Ke,aJ as Oe}from"./index-RB5ffy32.js";import{D as qe}from"./WorkspaceDirPicker-C5knnArH.js";import"./react-vendor-B2V_5iSS.js";import"./state-0T92JV0u.js";import"./panels-P_I7Q72_.js";function Ve(b={}){const t=b.enabled!==!1,i=h(o=>o.projects),l=h(o=>o.total),c=h(o=>o.hidden),n=h(o=>o.detail),g=h(o=>o.detailLoading),r=h(o=>o.detailError),j=h(o=>o.query),y=h(o=>o.sort),s=h(o=>o.stale),f=h(o=>o.loading),P=h(o=>o.lastError),E=h(o=>o.disabled),I=h(o=>o.refresh);u.useEffect(()=>{t&&h.getState().refresh()},[t]),u.useEffect(()=>{!t||!s||h.getState().scheduleRefresh()},[t,s]),u.useEffect(()=>{if(!t||typeof document>"u")return;const o=()=>{document.visibilityState==="visible"&&h.getState().refresh()};return document.addEventListener("visibilitychange",o),()=>document.removeEventListener("visibilitychange",o)},[t]);const v=new Set(c),C=Me(i,y).filter(o=>!v.has(o.projectId));return{projects:C.filter(o=>o.rootExists),hiddenCount:i.length-C.length,total:l,detail:n,detailLoading:g,detailError:r,query:j,sort:y,stale:s,loading:f,lastError:P,disabled:E,setQuery:o=>h.getState().setQuery(o),setSort:o=>h.getState().setSort(o),openProject:o=>void h.getState().openProject(o),closeDetail:()=>h.getState().closeDetail(),createProject:(o,x)=>h.getState().createProject(o,x),hideProject:o=>h.getState().hideProject(o),unhideAll:()=>h.getState().unhideAll(),probeEntry:()=>void h.getState().probeEntry(),refresh:()=>void I()}}const Ge={neutral:"border-dark-border bg-dark-hover/40 text-dark-muted",ok:"border-accent-green/30 bg-accent-green/10 text-accent-green",warn:"border-accent-yellow/40 bg-accent-yellow/10 text-accent-yellow"};function q({tone:b="neutral",testid:t,title:i,children:l}){return e.jsx("span",{"data-testid":t,title:i,className:N("inline-flex items-center gap-0.5 rounded-full border px-1.5 py-px text-[10.5px] leading-4",Ge[b]),children:l})}function se({icon:b,label:t,hint:i,disabled:l,testid:c,onClick:n}){const g=l?`${t} — ${i??""}`:t;return e.jsx("button",{type:"button","aria-label":g,title:g,"data-testid":c,"data-disabled":l?"true":"false",disabled:l,onClick:r=>{r.stopPropagation(),n()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:bg-transparent",children:b})}const Qe=u.memo(function({project:t,onOpen:i,onOpenFolder:l,onCopyRoot:c,onHide:n,now:g}){const{t:r}=H(),j=!t.rootExists,y=Object.values(t.threads).reduce((f,P)=>f+P,0),s=Q(t.lastActivityAt,g,r);return e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>i(t.projectId),onKeyDown:f=>{(f.key==="Enter"||f.key===" ")&&f.target===f.currentTarget&&(f.preventDefault(),i(t.projectId))},className:N("group relative cursor-pointer rounded-xl border bg-dark-surface p-3.5 text-left shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent-blue",j?"border-dashed border-dark-border/60 opacity-70":"border-dark-border hover:border-accent-blue/40 hover:shadow-md"),"data-testid":`project-card-${t.projectId}`,"data-root-missing":j?"true":"false",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{"aria-hidden":"true",className:N("h-3.5 w-3.5 shrink-0 rounded-[4px] border",j?"border-dark-muted/40 bg-dark-muted/10":"border-accent-blue/50 bg-accent-blue/15")}),e.jsx("button",{type:"button",onClick:f=>{f.stopPropagation(),i(t.projectId)},className:"min-w-0 flex-1 truncate text-left text-[13px] font-semibold text-dark-text",title:t.root,"data-testid":`project-open-${t.projectId}`,children:t.name}),e.jsx("span",{className:"shrink-0 rounded border border-dark-border px-1 py-px text-[10px] leading-4 text-dark-muted",children:r("projects.visibility")})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[11px] text-dark-muted",children:[s&&e.jsx("span",{className:"font-mono tabular-nums","data-testid":`project-activity-${t.projectId}`,children:s}),j&&e.jsx("span",{className:"text-accent-yellow",children:r("projects.rootMissing")})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1",children:[e.jsxs(q,{testid:`project-sessions-${t.projectId}`,children:[r("projects.sessionCount",{count:t.sessions.total}),t.sessions.running>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-dark-muted/40","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"inline-flex items-center gap-0.5 text-accent-blue","data-testid":"project-running",children:r("projects.runningCount",{count:t.sessions.running})})]})]}),e.jsx(q,{testid:`project-threads-${t.projectId}`,children:y>0?r("projects.threadCount",{count:y}):r("projects.noThreads")}),t.agentMd.present?e.jsx(q,{tone:t.agentMd.truncated?"warn":"ok",testid:`project-agentmd-${t.projectId}`,title:t.agentMd.truncated?r("projects.agentMdTruncated",{bytes:t.agentMd.bytes??0}):r("projects.agentMdBytes",{bytes:t.agentMd.bytes??0}),children:t.agentMd.truncated?r("projects.agentMdTruncatedShort"):r("projects.agentMdReady")}):e.jsx(q,{testid:`project-agentmd-${t.projectId}`,children:r("projects.agentMdAbsent")}),j&&e.jsx(q,{tone:"warn",testid:`project-missing-${t.projectId}`,children:r("projects.rootMissingChip")})]}),e.jsx("div",{className:"mt-1.5 truncate font-mono text-[10.5px] text-dark-muted/80",title:t.root,children:t.root}),e.jsxs("div",{className:"mt-2.5 flex items-center gap-0.5 border-t border-dark-border/40 pt-2",onClick:f=>f.stopPropagation(),children:[e.jsx(se,{icon:e.jsx(ae,{size:13,"aria-hidden":"true"}),label:r("projects.openFolder"),hint:j?r("projects.openFolderDisabled"):void 0,disabled:j,testid:`project-open-folder-${t.projectId}`,onClick:()=>l(t.root)}),e.jsx(se,{icon:e.jsx(ne,{size:13,"aria-hidden":"true"}),label:r("projects.copyRoot"),testid:`project-copy-root-${t.projectId}`,onClick:()=>c(t.root)}),e.jsx(se,{icon:e.jsx(oe,{size:13,"aria-hidden":"true"}),label:r(j?"projects.removeView":"projects.hide"),hint:r("projects.hideHint"),testid:`project-hide-${t.projectId}`,onClick:()=>n(t.projectId)})]})]})});function Ue(b,t){const i=b.fields,l=c=>typeof i[c]=="string"?i[c]:"";switch(b.type){case"pm_started":return e.jsx("span",{children:t("projects.pmStarted")});case"pm_stopped":return e.jsx("span",{children:t("projects.pmStopped")});case"pm_wakeup":{const c=l("reason"),n=l("summary");return e.jsxs("span",{children:[t("projects.pmWakeup"),c?e.jsxs("span",{className:"text-dark-text-secondary",children:[" · ",c]}):null,n?e.jsx("span",{className:"block text-dark-text-secondary",children:n}):null]})}case"pm_report":{const c=l("title"),n=l("progressSummary"),g=l("nextAction"),r=typeof i.approvalsPending=="number"?i.approvalsPending:0;return e.jsxs("span",{children:[c?e.jsx("span",{className:"font-medium",children:c}):e.jsx("span",{children:t("projects.pmReport")}),n?e.jsx("span",{className:"block text-dark-text-secondary",children:n}):null,g?e.jsxs("span",{className:"block text-dark-text-secondary",children:[t("projects.pmNextAction"),": ",g]}):null,r>0?e.jsxs("span",{className:"mt-0.5 inline-flex items-center gap-1 text-amber-400",children:[e.jsx(pe,{size:12,"aria-hidden":"true"})," ",r," ",t("projects.pmApprovalsPending")]}):null]})}case"pm_approval_requested":return e.jsx("span",{children:t("projects.pmApprovalRequested")});case"pm_approval_resolved":return e.jsxs("span",{children:[t("projects.pmApprovalResolved"),l("decision")?e.jsxs("span",{className:"text-dark-text-secondary",children:[" · ",l("decision")]}):null]});default:return e.jsx("span",{children:b.type})}}const Ye=u.memo(function({root:t}){const{t:i}=H(),l=u.useMemo(()=>Ie(t)??"",[t]),c=z(x=>x.residentByProject[l]??!1),n=z(x=>x.activityByProject[l]??ze),g=z(x=>Ae(x,l)),r=z(x=>x.resolveApproval),[j,y]=u.useState(!1),[s,f]=u.useState(""),[P,E]=u.useState(!1),[I,v]=u.useState(!1);u.useEffect(()=>{l&&De(l)},[l]);const C=async()=>{if(!(!l||I)){v(!0);try{await Re(l,!c)}finally{v(!1)}}},w=async()=>{const x=s.trim();if(!(!x||!l||P)){E(!0);try{await Te(l,x),f("")}finally{E(!1)}}},o=n.slice(-20).reverse();return e.jsxs("section",{"aria-label":i("projects.pmPanel"),className:"border-b border-dark-border",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(me,{size:14,"aria-hidden":"true",className:c?"text-accent-green":"text-dark-text-secondary"}),e.jsx("span",{className:"text-xs font-medium",children:i("projects.pmPanel")}),e.jsxs("span",{className:N("inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[10px]",c?"bg-accent-green/15 text-accent-green":"bg-dark-bg-tertiary text-dark-text-secondary"),children:[e.jsx("span",{className:N("h-1.5 w-1.5 rounded-full",c?"bg-accent-green":"bg-dark-text-secondary"),"aria-hidden":"true"}),i(c?"projects.pmResident":"projects.pmOff")]}),e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:C,disabled:I||!l,className:N("rounded px-2 py-0.5 text-[11px] transition-colors",c?"text-dark-text-secondary hover:bg-dark-bg-tertiary hover:text-dark-text-primary":"bg-accent-green/15 text-accent-green hover:bg-accent-green/25"),children:i(c?"projects.pmStop":"projects.pmStart")}),e.jsx("button",{type:"button",onClick:()=>y(x=>!x),"aria-expanded":j,"aria-label":i("projects.pmToggleTimeline"),className:"rounded p-1 text-dark-text-secondary hover:bg-dark-bg-tertiary hover:text-dark-text-primary",children:j?e.jsx(he,{size:14,"aria-hidden":"true"}):e.jsx(X,{size:14,"aria-hidden":"true"})})]})]}),g.length>0&&e.jsx("ul",{className:"space-y-1.5 px-3 pb-2",children:g.map(x=>e.jsx("li",{className:"rounded-md border border-amber-500/30 bg-amber-500/5 p-2",children:e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(pe,{size:13,"aria-hidden":"true",className:"mt-0.5 shrink-0 text-amber-400"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-xs font-medium text-dark-text-primary",children:x.title||x.requestedAction||i("projects.pmApprovalCard")}),x.summary?e.jsx("p",{className:"mt-0.5 line-clamp-3 text-[11px] text-dark-text-secondary",children:x.summary}):null,e.jsxs("div",{className:"mt-1.5 flex gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>void r(x.escalationId,"approve"),className:"inline-flex items-center gap-1 rounded bg-accent-green/15 px-2 py-0.5 text-[11px] text-accent-green hover:bg-accent-green/25",children:[e.jsx(je,{size:11,"aria-hidden":"true"})," ",i("projects.pmApprove")]}),e.jsxs("button",{type:"button",onClick:()=>void r(x.escalationId,"reject"),className:"inline-flex items-center gap-1 rounded bg-red-500/10 px-2 py-0.5 text-[11px] text-red-400 hover:bg-red-500/20",children:[e.jsx(de,{size:11,"aria-hidden":"true"})," ",i("projects.pmReject")]})]})]})]})},x.escalationId))}),e.jsx("div",{className:"px-3 pb-2",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{value:s,onChange:x=>f(x.target.value),onKeyDown:x=>{x.key==="Enter"&&!x.nativeEvent.isComposing&&w()},placeholder:i(c?"projects.pmInputPlaceholder":"projects.pmInputDisabled"),disabled:!c,className:"min-w-0 flex-1 rounded-md border border-dark-border bg-dark-bg-tertiary px-2 py-1 text-xs text-dark-text-primary placeholder:text-dark-text-secondary focus:border-accent-green/50 focus:outline-none disabled:opacity-50"}),e.jsx("button",{type:"button",onClick:()=>void w(),disabled:!c||!s.trim()||P,"aria-label":i("projects.pmSend"),className:"rounded p-1.5 text-accent-green hover:bg-accent-green/10 disabled:opacity-40",children:e.jsx(be,{size:13,"aria-hidden":"true"})})]})}),j&&o.length>0&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx("ul",{className:"max-h-48 space-y-1.5 overflow-y-auto",children:o.map(x=>e.jsxs("li",{className:"flex items-start gap-1.5 text-xs",children:[x.type==="pm_report"?e.jsx(ge,{size:12,"aria-hidden":"true",className:"mt-0.5 shrink-0 text-accent-green"}):e.jsx("span",{className:"mt-1 h-1.5 w-1.5 shrink-0 rounded-full bg-dark-text-secondary","aria-hidden":"true"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-dark-text-primary",children:Ue(x,i)}),e.jsx("div",{className:"text-[10px] text-dark-text-secondary",children:Q(x.at)})]})]},x.id))})})]})}),We=["read file","read files","write file","edit file","list dir","list directory","apply patch","web search","web fetch","bash:","bash:","powershell:","powershell:","cmd:","cmd:","todo_write","notify_sessions","send_to_session","plugin_","mcp__"],Je=/^(?:grep|glob)(?:[ \t]+(?![\u4e00-\u9fff])|(?=[^\s\u4e00-\u9fff]))/;function ce(b){const t=b.trim().toLowerCase();return t?/^-{2,}/.test(t)||Je.test(t)?!0:We.some(i=>t.startsWith(i)):!1}const Xe=u.memo(function({currentProjectId:t,currentName:i,currentRootExists:l,currentLastActivityAt:c,onSelectProject:n,children:g}){var R;const{t:r}=H(),j=z(p=>p.managers),y=z(p=>p.dutyProjectKey),s=z(p=>p.managersLoading),f=z(p=>p.managersError),P=z(p=>p.residentByProject),E=z(p=>p.fetchManagers),I=z(p=>p.setDuty);u.useEffect(()=>{E()},[E]);const v=Date.now(),C=j.find(p=>p.projectKey===t)??null,w=j.filter(p=>p.projectKey!==t),o=y?((R=j.find(p=>p.projectKey===y))==null?void 0:R.name)??y:null,x=y===t,D=C?C.resident:P[t]??!1;return e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col","data-testid":"manager-roster",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 pb-1 pt-2",children:[e.jsx("span",{className:"text-xs font-medium text-dark-text","data-testid":"manager-roster-title",children:r("projects.managersTitle")}),y?e.jsxs("span",{className:"flex min-w-0 items-center gap-1 rounded-full border border-accent-yellow/40 bg-accent-yellow/10 px-1.5 py-px text-[10px] text-accent-yellow","data-testid":"manager-duty-now",children:[e.jsx(le,{size:10,className:"shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:r("projects.dutyNow",{name:o??""})})]}):e.jsx("span",{className:"rounded-full border border-dark-border bg-dark-hover/40 px-1.5 py-px text-[10px] text-dark-muted",title:r("projects.managersVacantHint"),"data-testid":"manager-duty-vacant",children:r("projects.dutyVacant")}),y&&e.jsxs("button",{type:"button",onClick:()=>void I(null),disabled:s,className:"ml-auto flex shrink-0 items-center gap-1 rounded border border-dark-border bg-dark-hover px-1.5 py-0.5 text-[10px] text-dark-muted transition-colors hover:text-dark-text disabled:cursor-not-allowed disabled:opacity-50",title:r("projects.managersVacantHint"),"data-testid":"manager-vacate",children:[e.jsx(fe,{size:10,"aria-hidden":"true"}),r("projects.dutyVacate")]})]}),f&&e.jsxs("div",{className:"mx-2 mb-1 flex shrink-0 items-center gap-1.5 rounded-lg border border-accent-red/40 bg-accent-red/10 px-2 py-1 text-[10px] leading-relaxed text-accent-red","data-testid":"manager-roster-error",children:[e.jsx(Z,{size:11,className:"shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:r("projects.managersLoadFailed")}),e.jsx("button",{type:"button",onClick:()=>void E(),className:"shrink-0 underline hover:no-underline","data-testid":"manager-roster-retry",children:r("projects.retry")})]}),e.jsxs("div",{className:"mx-2 flex min-h-0 flex-1 flex-col rounded-xl border border-accent-blue/30 bg-dark-hover/10","data-testid":"manager-row-current",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5 border-b border-dark-border/50 px-2.5 py-1.5",children:[e.jsx(le,{size:11,className:N("shrink-0",x?"text-accent-yellow":"text-dark-muted/40"),"aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-dark-text",title:t,children:i}),x&&e.jsx(V,{tone:"duty",label:r("projects.managerBadgeDuty")}),D&&e.jsx(V,{tone:"resident",label:r("projects.managerBadgeResident")}),!l&&e.jsx(V,{tone:"missing",label:r("projects.managerBadgeMissing")}),c&&e.jsx("span",{className:"ml-auto shrink-0 font-mono text-[10px] tabular-nums text-dark-muted",children:Q(c,v,r)})]}),g]}),w.length>0&&e.jsx("div",{className:"mx-2 mb-2 mt-1.5 flex max-h-40 shrink-0 flex-col gap-1 overflow-y-auto custom-scrollbar",children:w.map((p,_)=>e.jsxs("button",{type:"button",onClick:()=>n==null?void 0:n(p.projectKey),disabled:!n,title:p.managerSessionId,className:N("flex w-full shrink-0 items-center gap-1.5 rounded-lg border border-dark-border/70 bg-dark-surface/60 px-2.5 py-1.5 text-left transition-colors",n&&"hover:border-accent-blue/40 hover:bg-dark-hover/40",!n&&"cursor-default"),"data-testid":`manager-row-${_}`,"data-project-id":p.projectKey,children:[e.jsx("span",{className:N("h-1.5 w-1.5 shrink-0 rounded-full",p.resident?"bg-accent-green":"bg-dark-muted/50"),"aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-dark-text",children:p.name}),p.isDuty&&e.jsx(V,{tone:"duty",label:r("projects.managerBadgeDuty")}),!p.rootExists&&e.jsx(V,{tone:"missing",label:r("projects.managerBadgeMissing")}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-dark-muted",children:Q(p.lastActivityAt,v,r)}),e.jsx(X,{size:12,className:"shrink-0 text-dark-muted","aria-hidden":"true"})]},p.projectKey))})]})});function V({tone:b,label:t}){return e.jsx("span",{className:N("shrink-0 rounded-full border px-1.5 py-px text-[10px] leading-4",b==="duty"&&"border-accent-yellow/40 bg-accent-yellow/10 text-accent-yellow",b==="resident"&&"border-accent-blue/40 bg-accent-blue/10 text-accent-blue",b==="missing"&&"border-dark-border bg-dark-hover/40 text-dark-muted"),children:t})}const G=50,Ze=u.memo(function({projectId:t,onBack:i,onOpenFolder:l,onCopyRoot:c,onNewSessionHere:n,onOpenThreadSession:g,onOpenSession:r,onHide:j,onSelectProject:y}){const{t:s}=H(),[f,P]=u.useState(!1),[E,I]=u.useState(null),[v,C]=u.useState(""),[w,o]=u.useState("all"),[x,D]=u.useState(1),[R,p]=u.useState(!1),{state:_,open:K,openAt:ee,close:U}=Fe(),A=h(a=>a.detail),Y=h(a=>a.detailLoading),T=h(a=>a.detailError);u.useEffect(()=>{h.getState().openProject(t)},[t]),u.useEffect(()=>{I(null),P(!1),C(""),o("all"),D(1),p(!1)},[t]);const d=(A==null?void 0:A.project)??null,S=d?!d.rootExists:!1,W=Date.now(),$=(A==null?void 0:A.sessions)??[],F=u.useMemo(()=>{const a=v.trim().toLowerCase();return!a&&w==="all"?$:$.filter(B=>w==="running"&&!B.running?!1:a?B.title.toLowerCase().includes(a)||(B.preview??"").toLowerCase().includes(a):!0)},[$,v,w]),{mainSessions:M,noiseSessions:O}=u.useMemo(()=>{if(v.trim()!=="")return{mainSessions:F,noiseSessions:[]};const a=F.filter(te=>ce(te.title));return{mainSessions:F.filter(te=>!ce(te.title)),noiseSessions:a}},[F,v]),m=Math.max(1,Math.ceil(M.length/G)),k=Math.min(x,m),J=u.useMemo(()=>M.slice((k-1)*G,k*G),[M,k]);u.useEffect(()=>{D(1)},[v,w]);const ie=u.useMemo(()=>{if(!d)return[];const a=[{kind:"item",id:"copy-root",label:s("projects.copyRoot"),icon:ne,onSelect:()=>c(d.root)}];return j&&a.push({kind:"item",id:"hide-view",label:s(S?"projects.removeView":"projects.hide"),icon:oe,onSelect:()=>j(d.projectId)}),a},[d,S,c,j,s]);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col","data-testid":"project-detail",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-dark-border px-3 py-2.5",children:[e.jsx("button",{type:"button",onClick:i,className:"ui-icon-button",title:s("projects.back"),"aria-label":s("projects.back"),"data-testid":"project-detail-back",children:e.jsx(ke,{size:15,"aria-hidden":"true"})}),e.jsxs("nav",{className:"min-w-0 flex items-baseline gap-1.5 text-sm",children:[e.jsx("button",{type:"button",onClick:i,className:"shrink-0 text-dark-muted transition-colors hover:text-dark-text",children:s("projects.title")}),e.jsx("span",{className:"shrink-0 text-dark-muted/50","aria-hidden":"true",children:"›"}),e.jsx("span",{className:"truncate font-medium text-dark-text","data-testid":"project-detail-name",children:(d==null?void 0:d.name)??t})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[d&&e.jsx("span",{className:"hidden min-w-0 max-w-[240px] truncate font-mono text-[10.5px] text-dark-muted lg:block",title:d.root,"data-testid":"project-detail-root",children:d.root}),e.jsxs("button",{type:"button",onClick:()=>d&&l(d.root),disabled:S||!d,className:"btn shrink-0 text-[11px] disabled:cursor-not-allowed disabled:opacity-50",title:S?s("projects.openFolderDisabled"):d==null?void 0:d.root,"data-testid":"project-detail-open-folder",children:[e.jsx(ae,{size:12,"aria-hidden":"true"}),s("projects.openFolder")]}),e.jsx("span",{className:"rounded bg-dark-hover/70 px-1.5 py-px text-[10px] text-dark-muted",children:s("projects.overview")}),e.jsx("button",{type:"button",onClick:()=>P(a=>!a),"aria-expanded":f,className:"ui-icon-button",title:s("projects.settings"),"aria-label":s("projects.settings"),"data-testid":"project-detail-settings",children:e.jsx(ye,{size:14,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:a=>K(a,null),onKeyDown:a=>{if(a.key==="Enter"||a.key===" "){a.preventDefault();const B=a.currentTarget.getBoundingClientRect();ee(B.left,B.bottom+4,null,{height:_e(ie.length)})}},className:"ui-icon-button",title:s("projects.moreActions"),"aria-label":s("projects.moreActions"),"aria-haspopup":"menu","data-testid":"project-detail-more",children:e.jsx(ve,{size:14,"aria-hidden":"true"})})]})]}),S&&d&&e.jsxs("div",{className:"flex shrink-0 items-start gap-1.5 border-b border-accent-yellow/30 bg-accent-yellow/10 px-3 py-2 text-[10.5px] leading-relaxed text-accent-yellow","data-testid":"project-detail-missing",children:[e.jsx(Z,{size:12,className:"mt-[1px] shrink-0","aria-hidden":"true"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("b",{className:"font-semibold",children:s("projects.rootMissingTitle")}),d&&e.jsx("span",{className:"mx-1 font-mono",children:d.root}),e.jsx("br",{}),s("projects.rootMissingBody")]})]}),f&&d&&e.jsxs("div",{className:"shrink-0 space-y-1 border-b border-dark-border bg-dark-hover/20 px-3 py-2","data-testid":"project-settings",children:[e.jsx(re,{icon:e.jsx(ae,{size:12,"aria-hidden":"true"}),label:s("projects.openFolder"),hint:d.root,disabled:S,disabledHint:S?s("projects.openFolderDisabled"):void 0,onClick:()=>l(d.root),testId:"project-settings-open-folder"}),e.jsx(re,{icon:e.jsx(ne,{size:12,"aria-hidden":"true"}),label:s("projects.copyRoot"),hint:d.root,onClick:()=>c(d.root),testId:"project-settings-copy-root"}),e.jsx(re,{icon:e.jsx(Ne,{size:12,"aria-hidden":"true"}),label:s("projects.rename"),disabled:!0,disabledHint:s("projects.renameDisabled"),testId:"project-settings-rename"})]}),e.jsxs("div",{className:"flex min-h-0 flex-1",children:[e.jsxs(Xe,{currentProjectId:t,currentName:(d==null?void 0:d.name)??t,currentRootExists:d?d.rootExists:!0,currentLastActivityAt:d==null?void 0:d.lastActivityAt,onSelectProject:y,children:[e.jsxs("div",{className:"flex shrink-0 flex-col gap-2 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-dark-text",children:s("projects.sessions")}),d&&e.jsx("span",{className:"rounded-full border border-dark-border bg-dark-hover/40 px-1.5 py-px text-[10px] leading-4 text-dark-muted","data-testid":"project-sessions-count",children:s("projects.sessionsCount",{count:M.length})}),e.jsx("div",{className:"ml-auto flex items-center rounded-md bg-dark-hover/60 p-0.5",role:"group",children:["all","running"].map(a=>e.jsx("button",{type:"button",onClick:()=>o(a),"aria-pressed":w===a,className:N("shrink-0 rounded px-1.5 py-0.5 text-[10.5px] transition-colors",w===a?"bg-dark-surface text-dark-text":"text-dark-muted hover:text-dark-text"),"data-testid":`project-sessions-filter-${a}`,children:s(`projects.sessionsFilter.${a}`)},a))}),e.jsxs("button",{type:"button",onClick:()=>d&&n(d.root),disabled:S||!d,className:"btn btn-primary shrink-0 text-[11px] disabled:cursor-not-allowed disabled:opacity-60",title:s(S?"projects.newSessionDisabled":"projects.newSessionHere"),"data-testid":"project-new-session","data-disabled":S?"true":"false",children:[e.jsx(we,{size:12,"aria-hidden":"true"}),s("projects.newSessionHere")]})]}),e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-dark-border bg-dark-surface px-2.5 py-1.5 transition-colors focus-within:border-accent-blue/50",children:[e.jsx(ue,{size:13,className:"shrink-0 text-dark-muted","aria-hidden":"true"}),e.jsx("input",{type:"text",value:v,onChange:a=>C(a.target.value),placeholder:s("projects.sessionsSearchPlaceholder"),"aria-label":s("projects.sessionsSearchPlaceholder"),"data-testid":"project-sessions-search",className:"min-w-0 flex-1 bg-transparent text-xs text-dark-text placeholder:text-dark-muted focus:outline-none"}),v&&e.jsx("button",{type:"button",onClick:()=>C(""),className:"shrink-0 rounded p-0.5 text-dark-muted transition-colors hover:text-dark-text","aria-label":s("projects.searchClear"),"data-testid":"project-sessions-search-clear",children:e.jsx(de,{size:12,"aria-hidden":"true"})})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-2 pb-3 custom-scrollbar",children:T?e.jsxs("div",{className:"flex items-start gap-1.5 rounded-lg border border-accent-red/40 bg-accent-red/10 px-2 py-1.5 text-[10.5px] leading-relaxed text-accent-red","data-testid":"project-detail-error",children:[e.jsx(Z,{size:12,className:"mt-[1px] shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1",children:s("projects.detailLoadFailed",{message:T})}),e.jsx("button",{type:"button",onClick:()=>void h.getState().openProject(t),className:"shrink-0 underline hover:no-underline","data-testid":"project-detail-retry",children:s("projects.retry")})]}):Y&&!A?e.jsx("p",{className:"px-2 py-4 text-center text-[10.5px] text-dark-muted",children:s("common.loading")}):$.length===0?e.jsxs("div",{className:"px-2 py-6 text-center","data-testid":"project-sessions-empty",children:[e.jsx("p",{className:"text-[11px] text-dark-text",children:s("projects.noSessions")}),e.jsx("p",{className:"mt-1 text-[10.5px] leading-relaxed text-dark-muted",children:s("projects.noSessionsHint")})]}):F.length===0?e.jsxs("div",{className:"px-2 py-6 text-center","data-testid":"project-sessions-no-match",children:[e.jsx("p",{className:"text-[11px] text-dark-text",children:s("projects.sessionsNoMatch")}),e.jsx("p",{className:"mt-1 text-[10.5px] leading-relaxed text-dark-muted",children:s("projects.sessionsNoMatchHint")})]}):e.jsxs(e.Fragment,{children:[M.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-1.5","data-testid":"project-sessions-list",children:J.map(a=>e.jsx(xe,{id:a.id,title:a.title,preview:a.preview,running:a.running,updatedAt:a.updatedAt,now:W,onClick:()=>r==null?void 0:r(a.id,S||d==null?void 0:d.root,a.title)},a.id))}),m>1&&e.jsxs("div",{className:"flex select-none items-center justify-center gap-3 pt-3","data-testid":"project-sessions-pagination",children:[e.jsxs("button",{type:"button",onClick:()=>D(a=>Math.max(1,a-1)),disabled:k<=1,className:"flex items-center gap-1 rounded border border-dark-border bg-dark-hover px-2 py-1 text-[11px] text-dark-muted transition-colors hover:text-dark-text disabled:cursor-not-allowed disabled:opacity-40","data-testid":"project-sessions-prev",children:[e.jsx(Ce,{size:12,"aria-hidden":"true"}),s("common.prevPage")]}),e.jsx("span",{className:"text-[11px] tabular-nums text-dark-muted",children:s("common.pageInfo",{start:(k-1)*G+1,end:Math.min(k*G,M.length),total:M.length})}),e.jsxs("button",{type:"button",onClick:()=>D(a=>Math.min(m,a+1)),disabled:k>=m,className:"flex items-center gap-1 rounded border border-dark-border bg-dark-hover px-2 py-1 text-[11px] text-dark-muted transition-colors hover:text-dark-text disabled:cursor-not-allowed disabled:opacity-40","data-testid":"project-sessions-next",children:[s("common.nextPage"),e.jsx(X,{size:12,"aria-hidden":"true"})]})]})]}),O.length>0&&e.jsxs("div",{className:"mt-2 rounded-lg border border-dark-border/60 bg-dark-surface/40","data-testid":"project-noise-group",children:[e.jsxs("button",{type:"button",onClick:()=>p(a=>!a),"aria-expanded":R||M.length===0,className:"flex w-full items-center gap-1.5 px-2.5 py-1.5 text-left","data-testid":"project-noise-toggle",children:[e.jsx(X,{size:12,className:N("shrink-0 text-dark-muted transition-transform",(R||M.length===0)&&"rotate-90"),"aria-hidden":"true"}),e.jsx("span",{className:"text-[10.5px] text-dark-muted",children:s("projects.noiseGroupCount",{count:O.length})})]}),(R||M.length===0)&&e.jsx("div",{className:"max-h-48 space-y-1 overflow-y-auto border-t border-dark-border/60 p-1.5 custom-scrollbar",children:O.map(a=>e.jsx(xe,{id:a.id,title:a.title,preview:a.preview,running:a.running,updatedAt:a.updatedAt,now:W,onClick:()=>r==null?void 0:r(a.id,S||d==null?void 0:d.root,a.title)},a.id))})]})]})})]}),e.jsxs("div",{className:"flex min-h-0 w-[392px] shrink-0 flex-col border-l border-dark-border",children:[(d==null?void 0:d.root)&&e.jsx(Ye,{root:d.root}),E?e.jsx(Be,{threadId:E,onBack:()=>I(null),onOpenSession:g}):e.jsx(Le,{workspaceId:t,onOpenThread:I})]})]}),e.jsx($e,{items:ie,position:_?{x:_.x,y:_.y}:null,onClose:U,ariaLabel:s("projects.moreActions")})]})});function re({icon:b,label:t,hint:i,disabled:l,disabledHint:c,onClick:n,testId:g}){return e.jsxs("button",{type:"button",onClick:n,disabled:l,className:N("flex w-full items-center gap-2 rounded px-1.5 py-1 text-left text-[11px] transition-colors",l?"cursor-not-allowed text-dark-muted/60":"text-dark-text hover:bg-dark-hover"),"data-testid":g,"data-disabled":l?"true":"false",title:l?c:i,children:[e.jsx("span",{className:"shrink-0",children:b}),e.jsx("span",{className:"shrink-0",children:t}),e.jsx("span",{className:"ml-auto min-w-0 truncate font-mono text-[10px] text-dark-muted/70",children:l?c:i})]})}function xe({id:b,title:t,preview:i,running:l,updatedAt:c,now:n,onClick:g}){const{t:r}=H();return e.jsxs("button",{type:"button",onClick:g,className:"block w-full rounded-lg border border-dark-border/70 bg-dark-surface/60 px-2.5 py-2 text-left transition-colors hover:border-accent-blue/40 hover:bg-dark-hover/40","data-testid":`project-session-${b}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:N("h-1.5 w-1.5 shrink-0 rounded-full",l?"bg-accent-blue":"bg-dark-muted/50"),"aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-dark-text",title:t,children:t}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-dark-muted",children:Q(c,n,r)})]}),i&&e.jsx("p",{className:"mt-0.5 truncate pl-3 text-[10.5px] text-dark-muted/80",children:i})]})}const et=250,it=u.memo(function({workspaceDir:t,onNewSessionHere:i,onOpenThreadSession:l,onOpenSession:c}){const{t:n}=H(),{projects:g,hiddenCount:r,query:j,sort:y,loading:s,lastError:f,disabled:P,setQuery:E,setSort:I,openProject:v,closeDetail:C,createProject:w,hideProject:o,unhideAll:x,refresh:D}=Ve(),[R,p]=u.useState(null),[_,K]=u.useState(!1),[ee,U]=u.useState(!1),[A,Y]=u.useState(j),T=u.useRef(null);u.useEffect(()=>{Y(j)},[j]),u.useEffect(()=>()=>{T.current&&clearTimeout(T.current)},[]);const d=m=>{Y(m),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>E(m),et)},[S,W]=u.useState(()=>Date.now());u.useEffect(()=>{const m=setInterval(()=>W(Date.now()),3e4);return()=>clearInterval(m)},[]);const $=u.useMemo(()=>He,[]),F=m=>{Oe.openFolder(m).then(k=>{k.ok||L.error(k.error||n("projects.openFolderFailed"),5e3)})},M=m=>{var J;const k=(J=navigator.clipboard)==null?void 0:J.writeText(m);k&&k.then(()=>L.success(n("projects.copied"),2e3),()=>L.error(n("projects.copyFailed"),4e3))},O=m=>{K(!1),U(!0),w(m).then(k=>{if(U(!1),!k.ok){L.error(k.error,6e3);return}L.success(n("projects.created"),3e3),k.projectId&&p(k.projectId)})};return P?e.jsx("div",{className:"flex h-full items-center justify-center p-6","data-testid":"projects-disabled",children:e.jsxs("div",{className:"max-w-md rounded-xl border border-dark-border bg-dark-surface p-4 text-center",children:[e.jsx(Se,{size:18,className:"mx-auto text-dark-muted","aria-hidden":"true"}),e.jsx("p",{className:"mt-2 text-xs leading-relaxed text-dark-muted",children:n("projects.disabled")})]})}):e.jsxs("div",{className:"flex h-full min-h-0 flex-col","data-testid":"projects-view",children:[R?e.jsx(Ze,{projectId:R,onBack:()=>{p(null),C()},onOpenFolder:F,onCopyRoot:M,onNewSessionHere:i,onOpenThreadSession:l,onOpenSession:c,onHide:m=>{o(m),L.info(n("projects.hiddenToast"),4e3),p(null),C()},onSelectProject:m=>p(m)}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-dark-border px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium text-dark-text",children:n("projects.title")}),e.jsx("span",{className:"rounded-full border border-dark-border bg-dark-hover/40 px-1.5 py-px text-[10px] leading-4 text-dark-muted","data-testid":"projects-count-pill",children:n("projects.projectCount",{count:g.length})}),e.jsx("div",{className:"ml-1 flex items-center rounded-md bg-dark-hover/60 p-0.5",role:"group",children:$.map(m=>e.jsx("button",{type:"button",onClick:()=>I(m),"aria-pressed":y===m,className:N("shrink-0 rounded px-1.5 py-0.5 text-[10.5px] transition-colors",y===m?"bg-dark-surface text-dark-text":"text-dark-muted hover:text-dark-text"),"data-testid":`projects-sort-${m}`,children:n(`projects.sort.${m}`)},m))}),e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:D,disabled:s,className:"ui-icon-button disabled:opacity-50",title:n("common.refresh"),"aria-label":n("common.refresh"),"data-testid":"projects-refresh",children:e.jsx(Pe,{size:14,className:N(s&&"animate-spin"),"aria-hidden":"true"})}),e.jsxs("button",{type:"button",onClick:()=>K(!0),disabled:ee,className:"btn btn-primary shrink-0 text-[11px] disabled:opacity-60","data-testid":"projects-new",children:[e.jsx(Ee,{size:13,"aria-hidden":"true"}),n("projects.new")]})]})]}),f&&e.jsx("div",{className:"shrink-0 px-3 pt-2","data-testid":"projects-status-banner",children:e.jsxs("div",{className:"flex items-start gap-1.5 rounded-lg border border-accent-red/40 bg-accent-red/10 px-2 py-1.5 text-[10.5px] leading-relaxed text-accent-red",children:[e.jsx(Z,{size:12,className:"mt-[1px] shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1",children:n("projects.loadFailed",{message:f})}),e.jsx("button",{type:"button",onClick:D,className:"shrink-0 underline hover:no-underline","data-testid":"projects-retry",children:n("projects.retry")})]})}),r>0&&e.jsx("div",{className:"shrink-0 px-3 pt-2","data-testid":"projects-hidden-banner",children:e.jsxs("div",{className:"flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-hover/40 px-2 py-1.5 text-[10.5px] text-dark-muted",children:[e.jsx(oe,{size:11,className:"shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1",children:n("projects.hiddenCount",{count:r})}),e.jsx("button",{type:"button",onClick:x,className:"shrink-0 underline hover:no-underline","data-testid":"projects-unhide-all",children:n("projects.unhideAll")})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-3 py-3 custom-scrollbar",children:e.jsxs("div",{className:"mx-auto flex max-w-[860px] flex-col",children:[e.jsx("h1",{className:"text-lg font-semibold text-dark-text",children:n("projects.title")}),e.jsx("p",{className:"mt-0.5 text-xs leading-relaxed text-dark-muted",children:n("projects.subtitle")}),e.jsxs("div",{className:"mt-4 flex items-center gap-2 rounded-lg border border-dark-border bg-dark-surface px-2.5 py-1.5 transition-colors focus-within:border-accent-blue/50",children:[e.jsx(ue,{size:13,className:"shrink-0 text-dark-muted","aria-hidden":"true"}),e.jsx("input",{type:"text",value:A,onChange:m=>d(m.target.value),placeholder:n("projects.searchPlaceholder"),"aria-label":n("projects.searchPlaceholder"),"data-testid":"projects-search",className:"min-w-0 flex-1 bg-transparent text-xs text-dark-text placeholder:text-dark-muted focus:outline-none"}),A&&e.jsx("button",{type:"button",onClick:()=>d(""),className:"shrink-0 rounded p-0.5 text-dark-muted transition-colors hover:text-dark-text","aria-label":n("projects.searchClear"),"data-testid":"projects-search-clear",children:e.jsx(de,{size:12,"aria-hidden":"true"})}),e.jsx("span",{className:"shrink-0 text-[10px] text-dark-muted/70",children:n("projects.serverFilterHint")})]}),g.length===0?j.trim()?e.jsxs("div",{className:"mt-6 rounded-xl border border-dashed border-dark-border/60 py-8 text-center","data-testid":"projects-search-empty",children:[e.jsx("p",{className:"text-xs text-dark-text",children:n("projects.searchEmpty")}),e.jsx("p",{className:"mt-1 text-[10.5px] leading-relaxed text-dark-muted",children:n("projects.searchEmptyHint",{q:j.trim()})})]}):e.jsxs("div",{className:"mt-6 rounded-xl border border-dashed border-dark-border/60 py-8 text-center","data-testid":"projects-empty",children:[e.jsx("p",{className:"text-xs text-dark-text",children:n("projects.empty")}),e.jsx("p",{className:"mt-1 text-[10.5px] leading-relaxed text-dark-muted",children:n("projects.emptyHint")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-3 mt-5 flex items-center gap-2 text-[10px] font-semibold uppercase tracking-wide text-dark-muted/60",children:[e.jsx("span",{className:"shrink-0",children:n("projects.yourProjects")}),e.jsx("span",{className:"h-px flex-1 bg-dark-border/60","aria-hidden":"true"})]}),e.jsx("div",{className:"grid [grid-template-columns:repeat(auto-fill,minmax(250px,1fr))] gap-3","data-testid":"projects-list",children:g.map(m=>e.jsx(Qe,{project:m,onOpen:k=>{p(k),v(k)},onOpenFolder:F,onCopyRoot:M,onHide:k=>{o(k),L.info(n("projects.hiddenToast"),4e3)},now:S},m.projectId))})]})]})})]}),_&&Ke.createPortal(e.jsx(qe,{initial:t||"",onClose:()=>K(!1),onConfirm:O}),document.body)]})});export{it as ProjectsView};