@bigduu/lotus 2026.5.4 → 2026.5.5

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.
@@ -1 +1 @@
1
- var ee=Object.defineProperty;var te=(i,t,s)=>t in i?ee(i,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[t]=s;var z=(i,t,s)=>te(i,typeof t!="symbol"?t+"":t,s);import{j as e}from"./vendor-markdown-yOmFo5hK.js";import{u as V,a as o,i as q}from"./vendor-i18n-BNURlJ23.js";import{w as D,a as se}from"./App-CIBUzKFV.js";import{A as O,t as Q,m as B,M as G,S as j,B as P,D as N,G as ae,H as re,J,C as ie,v as Z,E as M,L as W,q as C,K as _,N as Y,O as ne,Q as ce,U as oe,p as L,I as le,V as de}from"./vendor-antd-BpW-8RO2.js";import"./main-_fs1sZGu.js";import"./vendor-charts-fIPNnfk-.js";import"./vendor-mermaid-DA4JIJaA.js";const he=({visible:i,onClose:t,onSelect:s})=>{const{t:n}=V(),{message:r}=O.useApp(),{token:a}=Q.useToken(),{Text:c}=B,[p,w]=o.useState(!1),[l,x]=o.useState(""),[u,b]=o.useState(),[S,k]=o.useState([]),[v,y]=o.useState([]);o.useEffect(()=>{i&&g()},[i]);const g=async d=>{w(!0);try{const m=await D.browseFolder(d);x(m.current_path),b(m.parent_path),k(m.folders)}catch(m){console.error("Failed to load directory:",m),r.error("Unable to read folder")}finally{w(!1)}},f=d=>{y([...v,l]),g(d.path)},E=()=>{u&&(y(v.slice(0,-1)),g(u))},T=()=>{y([]),g()},I=()=>{s(l),t()},R=()=>{if(!l)return[];const d=l.split(/[/\\]/).filter(Boolean);return l.startsWith("/")&&d.unshift("/"),d},A=d=>{const F=R().slice(0,d+1).join("/"),$=(l.startsWith("/"),F);g($)};return e.jsx(G,{title:n("chat.folderBrowser.title"),open:i,onCancel:t,width:700,footer:null,children:e.jsxs(j,{direction:"vertical",size:"middle",style:{width:"100%"},children:[e.jsxs(j,{children:[e.jsx(P,{icon:e.jsx(N,{}),onClick:T,size:"small",children:n("common.home")}),e.jsx(P,{icon:e.jsx(ae,{}),onClick:E,disabled:!u,size:"small",children:n("common.parentDirectory")}),e.jsx(P,{type:"primary",icon:e.jsx(re,{}),onClick:I,size:"small",children:n("chat.folderBrowser.selectCurrent")})]}),e.jsx(J,{children:R().map((d,m)=>e.jsx(J.Item,{children:e.jsx(P,{type:"link",size:"small",onClick:()=>A(m),style:{padding:0},children:d==="/"?e.jsx(N,{}):d})},m))}),e.jsxs(ie,{size:"small",styles:{body:{padding:a.paddingXS}},children:[e.jsx(c,{type:"secondary",style:{fontSize:12},children:n("common.currentPath")})," ",e.jsx(c,{code:!0,children:l})]}),e.jsx(Z,{spinning:p,children:S.length===0&&!p?e.jsx(M,{image:M.PRESENTED_IMAGE_SIMPLE,description:e.jsx(c,{type:"secondary",children:n("chat.folderBrowser.emptyFolder")})}):e.jsx(W,{dataSource:S,style:{maxHeight:400,overflowY:"auto"},renderItem:d=>e.jsx(W.Item,{style:{padding:0},children:e.jsx(P,{type:"text",icon:e.jsx(C,{}),onClick:()=>f(d),style:{width:"100%",textAlign:"left",padding:`${a.paddingXS}px ${a.paddingSM}px`},children:d.name})})})}),e.jsx(c,{type:"secondary",style:{fontSize:12},children:n("chat.folderBrowser.tip")})]})})};class pe{constructor(t={}){z(this,"cache",new Map);z(this,"pendingValidations",new Map);z(this,"options");this.options={debounceMs:t.debounceMs??300,cacheTimeoutMs:t.cacheTimeoutMs??5*60*1e3,maxRetries:t.maxRetries??3}}async validateWorkspace(t){if(!t||t.trim().length===0)return{path:"",is_valid:!1,error_message:q.t("chat.workspace.errorEnterPath")};const s=t.trim(),n=this.getCachedResult(s);if(n)return n;const r=this.pendingValidations.get(s);if(r)return r;const a=this.performValidation(s);this.pendingValidations.set(s,a);try{const c=await a;return this.setCachedResult(s,c),c}finally{this.pendingValidations.delete(s)}}validateWorkspaceDebounced(t,s){let n;return n=setTimeout(async()=>{try{const a=await this.validateWorkspace(t);s(a)}catch(a){const c={path:t,is_valid:!1,error_message:a instanceof Error?a.message:q.t("chat.workspace.checkDescription")};s(c)}},this.options.debounceMs),()=>{clearTimeout(n)}}clearCache(){this.cache.clear()}getCachedResult(t){const s=this.cache.get(t);return s?Date.now()-s.timestamp>this.options.cacheTimeoutMs?(this.cache.delete(t),null):s.result:null}setCachedResult(t,s){this.cache.set(t,{result:s,timestamp:Date.now()})}async performValidation(t,s=0){try{return await se.post("workspace/validate",{path:t})}catch(n){if(s<this.options.maxRetries&&this.isRetryableError(n))return await this.delay(Math.pow(2,s)*1e3),this.performValidation(t,s+1);throw n}}isRetryableError(t){return t instanceof Error?t.message.includes("Failed to fetch")||t.message.includes("HTTP error! status: 5"):!1}delay(t){return new Promise(s=>setTimeout(s,t))}async validateMultiplePaths(t){const n=[];for(let r=0;r<t.length;r+=5){const a=t.slice(r,r+5),c=await Promise.all(a.map(p=>this.validateWorkspace(p)));n.push(...c),r+5<t.length&&await this.delay(100)}return n}}const ue=new pe,me=({value:i="",onChange:t,showRecentWorkspaces:s,showSuggestions:n,onValidationChange:r})=>{const{message:a}=O.useApp(),[c,p]=o.useState(i),[w,l]=o.useState({isValidating:!1,result:null}),[x,u]=o.useState([]),[b,S]=o.useState(!1),[k,v]=o.useState([]),[y,g]=o.useState(!1),[f,E]=o.useState(!1),T=o.useRef(null),I=o.useRef(null);o.useEffect(()=>{p(i)},[i]),o.useEffect(()=>(s&&R(),n&&A(),()=>{T.current&&T.current.abort(),I.current&&I.current()}),[s,n]);const R=o.useCallback(async()=>{g(!0);try{const h=await D.getRecentWorkspaces();u(h.slice(0,5))}catch(h){console.error("Failed to load recent workspaces:",h),u([])}finally{g(!1)}},[]),A=o.useCallback(async()=>{E(!0);try{const h=await D.getPathSuggestions();v(h.suggestions.slice(0,8))}catch(h){console.error("Failed to load suggestions:",h),v([])}finally{E(!1)}},[]),d=o.useCallback(h=>{p(h),t&&t(h),T.current&&T.current.abort(),I.current&&I.current(),h.trim()?(l({isValidating:!0,result:null}),I.current=ue.validateWorkspaceDebounced(h.trim(),U=>{l({isValidating:!1,result:U}),r&&r(U)})):(l({isValidating:!1,result:null}),r&&r(null))},[t,r]),m=o.useCallback(()=>{S(!0)},[]),F=o.useCallback(h=>{d(h),a.success("Folder selected successfully")},[d]),$=o.useCallback(h=>{d(h)},[d]);return{path:c,validationStatus:w,recentWorkspaces:x,suggestions:k,isLoadingRecent:y,isLoadingSuggestions:f,folderBrowserVisible:b,setFolderBrowserVisible:S,handlePathChange:d,handleBrowseClick:m,handleFolderSelect:F,handleWorkspaceSelect:$}},{Text:H}=B,ge=({show:i,isLoading:t,recentWorkspaces:s,onSelect:n,token:r})=>{const{t:a}=V();return i?e.jsxs(_,{vertical:!0,gap:r.marginXS,style:{marginTop:r.marginMD},children:[e.jsxs(j,{style:{paddingInline:r.paddingSM},children:[e.jsx(Y,{}),e.jsx(H,{strong:!0,children:a("chat.workspace.recentTitle")})]}),t?e.jsx(_,{justify:"center",style:{padding:r.paddingSM},children:e.jsx(Z,{size:"small"})}):s.length===0?e.jsx(M,{description:a("chat.workspace.noRecentWorkspaces"),image:M.PRESENTED_IMAGE_SIMPLE,style:{padding:r.paddingSM}}):e.jsx(W,{size:"small",dataSource:s,style:{paddingInline:r.paddingSM},renderItem:c=>e.jsx(W.Item,{style:{padding:0},children:e.jsx(P,{type:"text",onClick:()=>n(c.path),style:{width:"100%",textAlign:"left",padding:`${r.paddingXS}px 0`,height:"auto"},children:e.jsxs(_,{justify:"space-between",align:"center",style:{width:"100%"},children:[e.jsxs(j,{children:[e.jsx(C,{style:{color:r.colorWarning}}),e.jsx(H,{strong:!0,children:c.workspace_name||c.path.split("/").pop()||a("chat.workspace.defaultWorkspaceName")})]}),e.jsx(H,{type:"secondary",ellipsis:{tooltip:c.path},style:{fontSize:12,maxWidth:"55%",textAlign:"right"},children:c.path})]})})})})]}):null},{Text:X}=B,xe=(i,t)=>{switch(i.suggestion_type){case"home":return e.jsx(N,{style:{color:t.colorPrimary}});case"documents":case"desktop":case"downloads":return e.jsx(C,{style:{color:t.colorSuccess}});case"recent":return e.jsx(Y,{style:{color:t.colorWarning}});default:return e.jsx(C,{})}},fe=({show:i,isLoading:t,suggestions:s,onSelect:n,token:r})=>{const{t:a}=V();return i?e.jsxs(_,{vertical:!0,gap:r.marginXS,style:{marginTop:r.marginMD},children:[e.jsxs(j,{style:{paddingInline:r.paddingSM},children:[e.jsx(C,{}),e.jsx(X,{strong:!0,children:a("chat.workspace.suggestedTitle")})]}),t?e.jsx(_,{justify:"center",style:{padding:r.paddingSM},children:e.jsx(Z,{size:"small"})}):s.length===0?e.jsx(M,{description:a("chat.workspace.noSuggestions"),image:M.PRESENTED_IMAGE_SIMPLE,style:{padding:r.paddingSM}}):e.jsx(W,{size:"small",dataSource:s,style:{paddingInline:r.paddingSM},renderItem:c=>e.jsx(W.Item,{style:{padding:0},children:e.jsx(P,{type:"text",onClick:()=>n(c.path),style:{width:"100%",textAlign:"left",padding:`${r.paddingXS}px 0`,height:"auto"},children:e.jsxs(_,{justify:"space-between",align:"center",style:{width:"100%"},children:[e.jsxs(j,{children:[xe(c,r),e.jsx(X,{strong:!0,children:c.name})]}),e.jsx(X,{type:"secondary",ellipsis:{tooltip:c.path},style:{fontSize:12,maxWidth:"55%",textAlign:"right"},children:c.path})]})})})})]}):null},ye=({isValidating:i,result:t,token:s})=>i?e.jsx(ne,{style:{color:s.colorPrimary}}):t?t.is_valid?e.jsx(ce,{style:{color:s.colorSuccess}}):e.jsx(oe,{style:{color:s.colorError}}):null,{Text:K}=B,je=({result:i,token:t})=>{const{t:s}=V();return i?e.jsx("div",{style:{marginTop:t.marginXS},children:i.is_valid?e.jsx(L,{type:"success",message:e.jsxs(j,{children:[e.jsx("span",{children:s("chat.workspace.validWorkspace")}),i.workspace_name&&e.jsxs(K,{type:"secondary",children:["(",i.workspace_name,")"]}),i.file_count!==void 0&&e.jsx(K,{type:"secondary",children:s("chat.workspace.fileCount",{count:i.file_count})})]}),showIcon:!0}):e.jsx(L,{type:"error",message:i.error_message||s("validation.invalidPath"),showIcon:!0})}):null},{Text:we}=B,Se=({value:i="",onChange:t,placeholder:s,disabled:n=!1,allowBrowse:r=!0,showRecentWorkspaces:a=!0,showSuggestions:c=!0,onValidationChange:p,className:w,style:l})=>{const{t:x}=V(),{token:u}=Q.useToken(),b=s??x("chat.workspace.placeholder"),{path:S,validationStatus:k,recentWorkspaces:v,suggestions:y,isLoadingRecent:g,isLoadingSuggestions:f,folderBrowserVisible:E,setFolderBrowserVisible:T,handlePathChange:I,handleBrowseClick:R,handleFolderSelect:A,handleWorkspaceSelect:d}=me({value:i,onChange:t,showRecentWorkspaces:a,showSuggestions:c,onValidationChange:p});return e.jsxs("div",{className:w,style:l,children:[e.jsx(le,{value:S,onChange:m=>I(m.target.value),placeholder:b,disabled:n,size:"middle",style:{width:"100%"},suffix:e.jsx(ye,{isValidating:k.isValidating,result:k.result,token:u}),addonBefore:e.jsxs(j,{children:[e.jsx(C,{}),e.jsx(we,{children:x("chat.workspace.label")})]}),addonAfter:r?e.jsx(P,{"aria-label":x("chat.workspace.browseFolder"),title:x("chat.workspace.browseFolder"),icon:e.jsx(C,{}),onClick:R,disabled:n,type:"text",size:"middle",style:{display:"inline-flex",alignItems:"center"}}):void 0}),e.jsx(je,{result:k.result,token:u}),(a||c)&&e.jsxs(e.Fragment,{children:[e.jsx(de,{style:{margin:"16px 0 12px 0"}}),e.jsx(ge,{show:a,isLoading:g,recentWorkspaces:v,onSelect:d,token:u}),e.jsx(fe,{show:c,isLoading:f,suggestions:y,onSelect:d,token:u})]}),e.jsx(he,{visible:E,onClose:()=>T(!1),onSelect:A})]})},{Title:ke}=B,_e=({open:i,initialPath:t="",loading:s=!1,onSubmit:n,onCancel:r})=>{const{t:a}=V(),{message:c}=O.useApp(),[p,w]=o.useState(t),[l,x]=o.useState(null),[u,b]=o.useState(!1);o.useEffect(()=>{i&&(w(t),x(null))},[i,t]);const S=f=>{w(f)},k=f=>{x(f)},v=async()=>{if(!p.trim()){c.error(a("chat.workspace.errorEnterPath"));return}l&&!l.is_valid?G.confirm({title:a("chat.workspace.invalidTitle"),content:e.jsxs("div",{children:[e.jsx("p",{children:a("chat.workspace.issuesDetected")}),e.jsx("p",{children:l.error_message||a("chat.workspace.invalidTitle")}),e.jsx("p",{children:a("chat.workspace.confirmSaveInvalid")})]}),okText:a("common.saveAnyway"),cancelText:a("common.cancel"),onOk:()=>y()}):y()},y=async()=>{b(!0);try{l!=null&&l.is_valid&&await D.addRecentWorkspace(p.trim(),{workspace_name:l.workspace_name}),n(p.trim())}catch(f){console.error("Failed to save workspace path:",f),c.error(a("chat.workspace.errorSaveFailed"))}finally{b(!1)}},g=!p.trim()||s||u;return e.jsx(G,{open:i,title:e.jsx(j,{children:e.jsx(ke,{level:4,style:{margin:0},children:a("chat.workspace.modalTitle")})}),okText:a("common.save"),cancelText:a("common.cancel"),onOk:v,onCancel:r,okButtonProps:{disabled:g,loading:u||s},width:600,destroyOnClose:!0,children:e.jsxs(j,{direction:"vertical",size:"middle",style:{width:"100%"},children:[e.jsx(L,{message:a("chat.workspace.descriptionTitle"),description:e.jsxs("div",{children:[e.jsx("p",{children:a("chat.workspace.descriptionP1")}),e.jsx("p",{children:a("chat.workspace.descriptionP2")})]}),type:"info",showIcon:!0}),e.jsx(Se,{value:p,onChange:S,onValidationChange:k,placeholder:a("chat.workspace.placeholder"),disabled:u,allowBrowse:!0,showRecentWorkspaces:!0,showSuggestions:!0}),l&&!l.is_valid&&e.jsx(L,{message:a("chat.workspace.checkTitle"),description:l.error_message||a("chat.workspace.checkDescription"),type:"warning",showIcon:!0})]})})};export{_e as default};
1
+ var ee=Object.defineProperty;var te=(i,t,s)=>t in i?ee(i,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[t]=s;var z=(i,t,s)=>te(i,typeof t!="symbol"?t+"":t,s);import{j as e}from"./vendor-markdown-yOmFo5hK.js";import{u as V,a as o,i as q}from"./vendor-i18n-BNURlJ23.js";import{w as D,a as se}from"./App-b3yZCRqq.js";import{A as O,t as Q,m as B,M as G,S as j,B as P,D as N,G as ae,H as re,J,C as ie,v as Z,E as M,L as W,q as C,K as _,N as Y,O as ne,Q as ce,U as oe,p as L,I as le,V as de}from"./vendor-antd-BpW-8RO2.js";import"./main-NZYpmPsh.js";import"./vendor-charts-fIPNnfk-.js";import"./vendor-mermaid-DA4JIJaA.js";const he=({visible:i,onClose:t,onSelect:s})=>{const{t:n}=V(),{message:r}=O.useApp(),{token:a}=Q.useToken(),{Text:c}=B,[p,w]=o.useState(!1),[l,x]=o.useState(""),[u,b]=o.useState(),[S,k]=o.useState([]),[v,y]=o.useState([]);o.useEffect(()=>{i&&g()},[i]);const g=async d=>{w(!0);try{const m=await D.browseFolder(d);x(m.current_path),b(m.parent_path),k(m.folders)}catch(m){console.error("Failed to load directory:",m),r.error("Unable to read folder")}finally{w(!1)}},f=d=>{y([...v,l]),g(d.path)},E=()=>{u&&(y(v.slice(0,-1)),g(u))},T=()=>{y([]),g()},I=()=>{s(l),t()},R=()=>{if(!l)return[];const d=l.split(/[/\\]/).filter(Boolean);return l.startsWith("/")&&d.unshift("/"),d},A=d=>{const F=R().slice(0,d+1).join("/"),$=(l.startsWith("/"),F);g($)};return e.jsx(G,{title:n("chat.folderBrowser.title"),open:i,onCancel:t,width:700,footer:null,children:e.jsxs(j,{direction:"vertical",size:"middle",style:{width:"100%"},children:[e.jsxs(j,{children:[e.jsx(P,{icon:e.jsx(N,{}),onClick:T,size:"small",children:n("common.home")}),e.jsx(P,{icon:e.jsx(ae,{}),onClick:E,disabled:!u,size:"small",children:n("common.parentDirectory")}),e.jsx(P,{type:"primary",icon:e.jsx(re,{}),onClick:I,size:"small",children:n("chat.folderBrowser.selectCurrent")})]}),e.jsx(J,{children:R().map((d,m)=>e.jsx(J.Item,{children:e.jsx(P,{type:"link",size:"small",onClick:()=>A(m),style:{padding:0},children:d==="/"?e.jsx(N,{}):d})},m))}),e.jsxs(ie,{size:"small",styles:{body:{padding:a.paddingXS}},children:[e.jsx(c,{type:"secondary",style:{fontSize:12},children:n("common.currentPath")})," ",e.jsx(c,{code:!0,children:l})]}),e.jsx(Z,{spinning:p,children:S.length===0&&!p?e.jsx(M,{image:M.PRESENTED_IMAGE_SIMPLE,description:e.jsx(c,{type:"secondary",children:n("chat.folderBrowser.emptyFolder")})}):e.jsx(W,{dataSource:S,style:{maxHeight:400,overflowY:"auto"},renderItem:d=>e.jsx(W.Item,{style:{padding:0},children:e.jsx(P,{type:"text",icon:e.jsx(C,{}),onClick:()=>f(d),style:{width:"100%",textAlign:"left",padding:`${a.paddingXS}px ${a.paddingSM}px`},children:d.name})})})}),e.jsx(c,{type:"secondary",style:{fontSize:12},children:n("chat.folderBrowser.tip")})]})})};class pe{constructor(t={}){z(this,"cache",new Map);z(this,"pendingValidations",new Map);z(this,"options");this.options={debounceMs:t.debounceMs??300,cacheTimeoutMs:t.cacheTimeoutMs??5*60*1e3,maxRetries:t.maxRetries??3}}async validateWorkspace(t){if(!t||t.trim().length===0)return{path:"",is_valid:!1,error_message:q.t("chat.workspace.errorEnterPath")};const s=t.trim(),n=this.getCachedResult(s);if(n)return n;const r=this.pendingValidations.get(s);if(r)return r;const a=this.performValidation(s);this.pendingValidations.set(s,a);try{const c=await a;return this.setCachedResult(s,c),c}finally{this.pendingValidations.delete(s)}}validateWorkspaceDebounced(t,s){let n;return n=setTimeout(async()=>{try{const a=await this.validateWorkspace(t);s(a)}catch(a){const c={path:t,is_valid:!1,error_message:a instanceof Error?a.message:q.t("chat.workspace.checkDescription")};s(c)}},this.options.debounceMs),()=>{clearTimeout(n)}}clearCache(){this.cache.clear()}getCachedResult(t){const s=this.cache.get(t);return s?Date.now()-s.timestamp>this.options.cacheTimeoutMs?(this.cache.delete(t),null):s.result:null}setCachedResult(t,s){this.cache.set(t,{result:s,timestamp:Date.now()})}async performValidation(t,s=0){try{return await se.post("workspace/validate",{path:t})}catch(n){if(s<this.options.maxRetries&&this.isRetryableError(n))return await this.delay(Math.pow(2,s)*1e3),this.performValidation(t,s+1);throw n}}isRetryableError(t){return t instanceof Error?t.message.includes("Failed to fetch")||t.message.includes("HTTP error! status: 5"):!1}delay(t){return new Promise(s=>setTimeout(s,t))}async validateMultiplePaths(t){const n=[];for(let r=0;r<t.length;r+=5){const a=t.slice(r,r+5),c=await Promise.all(a.map(p=>this.validateWorkspace(p)));n.push(...c),r+5<t.length&&await this.delay(100)}return n}}const ue=new pe,me=({value:i="",onChange:t,showRecentWorkspaces:s,showSuggestions:n,onValidationChange:r})=>{const{message:a}=O.useApp(),[c,p]=o.useState(i),[w,l]=o.useState({isValidating:!1,result:null}),[x,u]=o.useState([]),[b,S]=o.useState(!1),[k,v]=o.useState([]),[y,g]=o.useState(!1),[f,E]=o.useState(!1),T=o.useRef(null),I=o.useRef(null);o.useEffect(()=>{p(i)},[i]),o.useEffect(()=>(s&&R(),n&&A(),()=>{T.current&&T.current.abort(),I.current&&I.current()}),[s,n]);const R=o.useCallback(async()=>{g(!0);try{const h=await D.getRecentWorkspaces();u(h.slice(0,5))}catch(h){console.error("Failed to load recent workspaces:",h),u([])}finally{g(!1)}},[]),A=o.useCallback(async()=>{E(!0);try{const h=await D.getPathSuggestions();v(h.suggestions.slice(0,8))}catch(h){console.error("Failed to load suggestions:",h),v([])}finally{E(!1)}},[]),d=o.useCallback(h=>{p(h),t&&t(h),T.current&&T.current.abort(),I.current&&I.current(),h.trim()?(l({isValidating:!0,result:null}),I.current=ue.validateWorkspaceDebounced(h.trim(),U=>{l({isValidating:!1,result:U}),r&&r(U)})):(l({isValidating:!1,result:null}),r&&r(null))},[t,r]),m=o.useCallback(()=>{S(!0)},[]),F=o.useCallback(h=>{d(h),a.success("Folder selected successfully")},[d]),$=o.useCallback(h=>{d(h)},[d]);return{path:c,validationStatus:w,recentWorkspaces:x,suggestions:k,isLoadingRecent:y,isLoadingSuggestions:f,folderBrowserVisible:b,setFolderBrowserVisible:S,handlePathChange:d,handleBrowseClick:m,handleFolderSelect:F,handleWorkspaceSelect:$}},{Text:H}=B,ge=({show:i,isLoading:t,recentWorkspaces:s,onSelect:n,token:r})=>{const{t:a}=V();return i?e.jsxs(_,{vertical:!0,gap:r.marginXS,style:{marginTop:r.marginMD},children:[e.jsxs(j,{style:{paddingInline:r.paddingSM},children:[e.jsx(Y,{}),e.jsx(H,{strong:!0,children:a("chat.workspace.recentTitle")})]}),t?e.jsx(_,{justify:"center",style:{padding:r.paddingSM},children:e.jsx(Z,{size:"small"})}):s.length===0?e.jsx(M,{description:a("chat.workspace.noRecentWorkspaces"),image:M.PRESENTED_IMAGE_SIMPLE,style:{padding:r.paddingSM}}):e.jsx(W,{size:"small",dataSource:s,style:{paddingInline:r.paddingSM},renderItem:c=>e.jsx(W.Item,{style:{padding:0},children:e.jsx(P,{type:"text",onClick:()=>n(c.path),style:{width:"100%",textAlign:"left",padding:`${r.paddingXS}px 0`,height:"auto"},children:e.jsxs(_,{justify:"space-between",align:"center",style:{width:"100%"},children:[e.jsxs(j,{children:[e.jsx(C,{style:{color:r.colorWarning}}),e.jsx(H,{strong:!0,children:c.workspace_name||c.path.split("/").pop()||a("chat.workspace.defaultWorkspaceName")})]}),e.jsx(H,{type:"secondary",ellipsis:{tooltip:c.path},style:{fontSize:12,maxWidth:"55%",textAlign:"right"},children:c.path})]})})})})]}):null},{Text:X}=B,xe=(i,t)=>{switch(i.suggestion_type){case"home":return e.jsx(N,{style:{color:t.colorPrimary}});case"documents":case"desktop":case"downloads":return e.jsx(C,{style:{color:t.colorSuccess}});case"recent":return e.jsx(Y,{style:{color:t.colorWarning}});default:return e.jsx(C,{})}},fe=({show:i,isLoading:t,suggestions:s,onSelect:n,token:r})=>{const{t:a}=V();return i?e.jsxs(_,{vertical:!0,gap:r.marginXS,style:{marginTop:r.marginMD},children:[e.jsxs(j,{style:{paddingInline:r.paddingSM},children:[e.jsx(C,{}),e.jsx(X,{strong:!0,children:a("chat.workspace.suggestedTitle")})]}),t?e.jsx(_,{justify:"center",style:{padding:r.paddingSM},children:e.jsx(Z,{size:"small"})}):s.length===0?e.jsx(M,{description:a("chat.workspace.noSuggestions"),image:M.PRESENTED_IMAGE_SIMPLE,style:{padding:r.paddingSM}}):e.jsx(W,{size:"small",dataSource:s,style:{paddingInline:r.paddingSM},renderItem:c=>e.jsx(W.Item,{style:{padding:0},children:e.jsx(P,{type:"text",onClick:()=>n(c.path),style:{width:"100%",textAlign:"left",padding:`${r.paddingXS}px 0`,height:"auto"},children:e.jsxs(_,{justify:"space-between",align:"center",style:{width:"100%"},children:[e.jsxs(j,{children:[xe(c,r),e.jsx(X,{strong:!0,children:c.name})]}),e.jsx(X,{type:"secondary",ellipsis:{tooltip:c.path},style:{fontSize:12,maxWidth:"55%",textAlign:"right"},children:c.path})]})})})})]}):null},ye=({isValidating:i,result:t,token:s})=>i?e.jsx(ne,{style:{color:s.colorPrimary}}):t?t.is_valid?e.jsx(ce,{style:{color:s.colorSuccess}}):e.jsx(oe,{style:{color:s.colorError}}):null,{Text:K}=B,je=({result:i,token:t})=>{const{t:s}=V();return i?e.jsx("div",{style:{marginTop:t.marginXS},children:i.is_valid?e.jsx(L,{type:"success",message:e.jsxs(j,{children:[e.jsx("span",{children:s("chat.workspace.validWorkspace")}),i.workspace_name&&e.jsxs(K,{type:"secondary",children:["(",i.workspace_name,")"]}),i.file_count!==void 0&&e.jsx(K,{type:"secondary",children:s("chat.workspace.fileCount",{count:i.file_count})})]}),showIcon:!0}):e.jsx(L,{type:"error",message:i.error_message||s("validation.invalidPath"),showIcon:!0})}):null},{Text:we}=B,Se=({value:i="",onChange:t,placeholder:s,disabled:n=!1,allowBrowse:r=!0,showRecentWorkspaces:a=!0,showSuggestions:c=!0,onValidationChange:p,className:w,style:l})=>{const{t:x}=V(),{token:u}=Q.useToken(),b=s??x("chat.workspace.placeholder"),{path:S,validationStatus:k,recentWorkspaces:v,suggestions:y,isLoadingRecent:g,isLoadingSuggestions:f,folderBrowserVisible:E,setFolderBrowserVisible:T,handlePathChange:I,handleBrowseClick:R,handleFolderSelect:A,handleWorkspaceSelect:d}=me({value:i,onChange:t,showRecentWorkspaces:a,showSuggestions:c,onValidationChange:p});return e.jsxs("div",{className:w,style:l,children:[e.jsx(le,{value:S,onChange:m=>I(m.target.value),placeholder:b,disabled:n,size:"middle",style:{width:"100%"},suffix:e.jsx(ye,{isValidating:k.isValidating,result:k.result,token:u}),addonBefore:e.jsxs(j,{children:[e.jsx(C,{}),e.jsx(we,{children:x("chat.workspace.label")})]}),addonAfter:r?e.jsx(P,{"aria-label":x("chat.workspace.browseFolder"),title:x("chat.workspace.browseFolder"),icon:e.jsx(C,{}),onClick:R,disabled:n,type:"text",size:"middle",style:{display:"inline-flex",alignItems:"center"}}):void 0}),e.jsx(je,{result:k.result,token:u}),(a||c)&&e.jsxs(e.Fragment,{children:[e.jsx(de,{style:{margin:"16px 0 12px 0"}}),e.jsx(ge,{show:a,isLoading:g,recentWorkspaces:v,onSelect:d,token:u}),e.jsx(fe,{show:c,isLoading:f,suggestions:y,onSelect:d,token:u})]}),e.jsx(he,{visible:E,onClose:()=>T(!1),onSelect:A})]})},{Title:ke}=B,_e=({open:i,initialPath:t="",loading:s=!1,onSubmit:n,onCancel:r})=>{const{t:a}=V(),{message:c}=O.useApp(),[p,w]=o.useState(t),[l,x]=o.useState(null),[u,b]=o.useState(!1);o.useEffect(()=>{i&&(w(t),x(null))},[i,t]);const S=f=>{w(f)},k=f=>{x(f)},v=async()=>{if(!p.trim()){c.error(a("chat.workspace.errorEnterPath"));return}l&&!l.is_valid?G.confirm({title:a("chat.workspace.invalidTitle"),content:e.jsxs("div",{children:[e.jsx("p",{children:a("chat.workspace.issuesDetected")}),e.jsx("p",{children:l.error_message||a("chat.workspace.invalidTitle")}),e.jsx("p",{children:a("chat.workspace.confirmSaveInvalid")})]}),okText:a("common.saveAnyway"),cancelText:a("common.cancel"),onOk:()=>y()}):y()},y=async()=>{b(!0);try{l!=null&&l.is_valid&&await D.addRecentWorkspace(p.trim(),{workspace_name:l.workspace_name}),n(p.trim())}catch(f){console.error("Failed to save workspace path:",f),c.error(a("chat.workspace.errorSaveFailed"))}finally{b(!1)}},g=!p.trim()||s||u;return e.jsx(G,{open:i,title:e.jsx(j,{children:e.jsx(ke,{level:4,style:{margin:0},children:a("chat.workspace.modalTitle")})}),okText:a("common.save"),cancelText:a("common.cancel"),onOk:v,onCancel:r,okButtonProps:{disabled:g,loading:u||s},width:600,destroyOnClose:!0,children:e.jsxs(j,{direction:"vertical",size:"middle",style:{width:"100%"},children:[e.jsx(L,{message:a("chat.workspace.descriptionTitle"),description:e.jsxs("div",{children:[e.jsx("p",{children:a("chat.workspace.descriptionP1")}),e.jsx("p",{children:a("chat.workspace.descriptionP2")})]}),type:"info",showIcon:!0}),e.jsx(Se,{value:p,onChange:S,onValidationChange:k,placeholder:a("chat.workspace.placeholder"),disabled:u,allowBrowse:!0,showRecentWorkspaces:!0,showSuggestions:!0}),l&&!l.is_valid&&e.jsx(L,{message:a("chat.workspace.checkTitle"),description:l.error_message||a("chat.workspace.checkDescription"),type:"warning",showIcon:!0})]})})};export{_e as default};
@@ -1 +1 @@
1
- import{j as s}from"./vendor-markdown-yOmFo5hK.js";import{u as b,a as x}from"./vendor-i18n-BNURlJ23.js";import{u as i}from"./App-CIBUzKFV.js";import{A as w,F as n,B as l,i as T,L as c,T as k,j as F,P as L,k as R,M as v,I as d}from"./vendor-antd-BpW-8RO2.js";import"./main-_fs1sZGu.js";import"./vendor-charts-fIPNnfk-.js";import"./vendor-mermaid-DA4JIJaA.js";const O=()=>{const{t}=b(),{message:r}=w.useApp(),f=i(e=>e.systemPrompts),P=i(e=>e.addSystemPrompt),j=i(e=>e.updateSystemPrompt),M=i(e=>e.deleteSystemPrompt),[h,u]=x.useState(!1),[a,p]=x.useState(null),[o]=n.useForm(),g=(e=null)=>{if(e!=null&&e.isDefault){r.warning(t("settings.systemPromptManager.defaultPromptLocked"));return}p(e),o.setFieldsValue(e||{name:"",description:"",content:""}),u(!0)},y=()=>{u(!1),p(null),o.resetFields()},S=async()=>{if(a!=null&&a.isDefault){r.warning(t("settings.systemPromptManager.defaultPromptLocked"));return}try{const e=await o.validateFields();a?(await j({...a,...e}),r.success(t("settings.systemPromptManager.updateSuccess"))):(await P(e),r.success(t("settings.systemPromptManager.addSuccess"))),y()}catch(e){console.error("Failed to save prompt:",e),r.error(e instanceof Error?e.message:t("settings.systemPromptManager.saveError"))}},I=async e=>{try{await M(e),r.success(t("settings.systemPromptManager.deleteSuccess"))}catch(m){console.error("Failed to delete prompt:",m),r.error(m instanceof Error?m.message:t("settings.systemPromptManager.deleteError"))}};return s.jsxs("div",{children:[s.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16},children:[s.jsx("h2",{children:t("settings.systemPromptManager.title")}),s.jsx(l,{type:"primary",icon:s.jsx(T,{}),onClick:()=>g(),children:t("settings.systemPromptManager.addButton")})]}),s.jsx(c,{itemLayout:"horizontal",dataSource:f,renderItem:e=>s.jsxs(c.Item,{actions:[e.isDefault?null:s.jsx(l,{type:"text",icon:s.jsx(F,{}),onClick:()=>g(e)}),e.isDefault?null:s.jsx(L,{title:t("settings.systemPromptManager.deleteConfirm"),onConfirm:()=>I(e.id),okText:t("common.yes"),cancelText:t("common.no"),children:s.jsx(l,{type:"text",danger:!0,icon:s.jsx(R,{}),"aria-label":t("common.delete")})})],children:[s.jsx(c.Item.Meta,{title:e.name,description:e.description||e.content.substring(0,200)+(e.content.length>200?"...":"")}),e.isDefault&&s.jsx(k,{children:t("settings.systemPromptManager.defaultTag")})]})}),s.jsx(v,{title:t(a?"settings.systemPromptManager.editTitle":"settings.systemPromptManager.addTitle"),open:h,onOk:S,onCancel:y,width:"60%",forceRender:!0,children:s.jsxs(n,{form:o,layout:"vertical",name:"system_prompt_form",children:[s.jsx(n.Item,{name:"name",label:t("settings.systemPromptManager.nameLabel"),rules:[{required:!0,message:t("settings.systemPromptManager.nameRequired")}],children:s.jsx(d,{})}),s.jsx(n.Item,{name:"description",label:t("settings.systemPromptManager.descriptionLabel"),rules:[{required:!1,message:t("settings.systemPromptManager.descriptionRequired")}],children:s.jsx(d.TextArea,{rows:3})}),s.jsx(n.Item,{name:"content",label:t("settings.systemPromptManager.contentLabel"),rules:[{required:!0,message:t("settings.systemPromptManager.contentRequired")}],children:s.jsx(d.TextArea,{rows:10})})]})})]})};export{O as default};
1
+ import{j as s}from"./vendor-markdown-yOmFo5hK.js";import{u as b,a as x}from"./vendor-i18n-BNURlJ23.js";import{u as i}from"./App-b3yZCRqq.js";import{A as w,F as n,B as l,i as T,L as c,T as k,j as F,P as L,k as R,M as v,I as d}from"./vendor-antd-BpW-8RO2.js";import"./main-NZYpmPsh.js";import"./vendor-charts-fIPNnfk-.js";import"./vendor-mermaid-DA4JIJaA.js";const O=()=>{const{t}=b(),{message:r}=w.useApp(),f=i(e=>e.systemPrompts),P=i(e=>e.addSystemPrompt),j=i(e=>e.updateSystemPrompt),M=i(e=>e.deleteSystemPrompt),[h,u]=x.useState(!1),[a,p]=x.useState(null),[o]=n.useForm(),g=(e=null)=>{if(e!=null&&e.isDefault){r.warning(t("settings.systemPromptManager.defaultPromptLocked"));return}p(e),o.setFieldsValue(e||{name:"",description:"",content:""}),u(!0)},y=()=>{u(!1),p(null),o.resetFields()},S=async()=>{if(a!=null&&a.isDefault){r.warning(t("settings.systemPromptManager.defaultPromptLocked"));return}try{const e=await o.validateFields();a?(await j({...a,...e}),r.success(t("settings.systemPromptManager.updateSuccess"))):(await P(e),r.success(t("settings.systemPromptManager.addSuccess"))),y()}catch(e){console.error("Failed to save prompt:",e),r.error(e instanceof Error?e.message:t("settings.systemPromptManager.saveError"))}},I=async e=>{try{await M(e),r.success(t("settings.systemPromptManager.deleteSuccess"))}catch(m){console.error("Failed to delete prompt:",m),r.error(m instanceof Error?m.message:t("settings.systemPromptManager.deleteError"))}};return s.jsxs("div",{children:[s.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16},children:[s.jsx("h2",{children:t("settings.systemPromptManager.title")}),s.jsx(l,{type:"primary",icon:s.jsx(T,{}),onClick:()=>g(),children:t("settings.systemPromptManager.addButton")})]}),s.jsx(c,{itemLayout:"horizontal",dataSource:f,renderItem:e=>s.jsxs(c.Item,{actions:[e.isDefault?null:s.jsx(l,{type:"text",icon:s.jsx(F,{}),onClick:()=>g(e)}),e.isDefault?null:s.jsx(L,{title:t("settings.systemPromptManager.deleteConfirm"),onConfirm:()=>I(e.id),okText:t("common.yes"),cancelText:t("common.no"),children:s.jsx(l,{type:"text",danger:!0,icon:s.jsx(R,{}),"aria-label":t("common.delete")})})],children:[s.jsx(c.Item.Meta,{title:e.name,description:e.description||e.content.substring(0,200)+(e.content.length>200?"...":"")}),e.isDefault&&s.jsx(k,{children:t("settings.systemPromptManager.defaultTag")})]})}),s.jsx(v,{title:t(a?"settings.systemPromptManager.editTitle":"settings.systemPromptManager.addTitle"),open:h,onOk:S,onCancel:y,width:"60%",forceRender:!0,children:s.jsxs(n,{form:o,layout:"vertical",name:"system_prompt_form",children:[s.jsx(n.Item,{name:"name",label:t("settings.systemPromptManager.nameLabel"),rules:[{required:!0,message:t("settings.systemPromptManager.nameRequired")}],children:s.jsx(d,{})}),s.jsx(n.Item,{name:"description",label:t("settings.systemPromptManager.descriptionLabel"),rules:[{required:!1,message:t("settings.systemPromptManager.descriptionRequired")}],children:s.jsx(d.TextArea,{rows:3})}),s.jsx(n.Item,{name:"content",label:t("settings.systemPromptManager.contentLabel"),rules:[{required:!0,message:t("settings.systemPromptManager.contentRequired")}],children:s.jsx(d.TextArea,{rows:10})})]})})]})};export{O as default};
@@ -1 +1 @@
1
- import{j as s}from"./vendor-markdown-yOmFo5hK.js";import{C as $,d as v,p as T}from"./App-CIBUzKFV.js";import{a as l,u as B}from"./vendor-i18n-BNURlJ23.js";import{v as E,t as M,T as L,w as D,x as K,q as F}from"./vendor-antd-BpW-8RO2.js";import"./main-_fs1sZGu.js";import"./vendor-charts-fIPNnfk-.js";import"./vendor-mermaid-DA4JIJaA.js";const z=({visible:p,searchText:k,onSelect:j,onCancel:f,onAutoComplete:g})=>{const[o,i]=l.useState([]),[c,R]=l.useState([]),[d,u]=l.useState(0),[N,I]=l.useState(!1),S=l.useRef(null),h=l.useRef(null);l.useEffect(()=>{if(!p)return;const a=$.getInstance();(async()=>{I(!0);try{const r=await a.listCommands();v("[CommandSelector]","[CommandSelector] Fetched commands:",r),i(r),u(0)}catch(r){console.error("[CommandSelector] Failed to fetch commands:",r),i([])}finally{I(!1)}})()},[p]),l.useEffect(()=>{const a=o.filter(e=>{var x,y,b,C,w;const r=k.toLowerCase(),n=(e.displayName??"").toLowerCase();return e.name.toLowerCase().includes(r)||n.includes(r)||e.description.toLowerCase().includes(r)||e.type==="mcp"&&[(x=e.metadata)==null?void 0:x.serverId,(y=e.metadata)==null?void 0:y.serverName,(b=e.metadata)==null?void 0:b.originalName].filter(m=>typeof m=="string").some(m=>m.toLowerCase().includes(r))||(((C=e.category)==null?void 0:C.toLowerCase().includes(r))??!1)||(((w=e.tags)==null?void 0:w.some(m=>m.toLowerCase().includes(r)))??!1)});R(a),u(0)},[o,k]),l.useEffect(()=>{if(!h.current||!S.current)return;const a=S.current,e=h.current,r=a.getBoundingClientRect(),n=e.getBoundingClientRect();n.top<r.top?e.scrollIntoView({block:"start",behavior:"smooth"}):n.bottom>r.bottom&&e.scrollIntoView({block:"end",behavior:"smooth"})},[d,c]);const t=l.useCallback(async a=>{try{j({name:a.name,type:a.type,id:a.id})}catch(e){console.error(`[CommandSelector] Failed to select command '${a.name}':`,e)}},[j]);return l.useEffect(()=>{const a=e=>{if(p)switch(e.key){case"ArrowDown":case"n":if(e.key==="n"&&!e.ctrlKey)break;e.preventDefault(),e.stopPropagation(),u(r=>r<c.length-1?r+1:0);break;case"ArrowUp":case"p":if(e.key==="p"&&!e.ctrlKey)break;e.preventDefault(),e.stopPropagation(),u(r=>r>0?r-1:c.length-1);break;case"Enter":e.preventDefault(),e.stopPropagation(),c[d]&&t(c[d]);break;case" ":case"Tab":e.preventDefault(),e.stopPropagation(),c[d]&&g&&g(c[d].name);break;case"Escape":e.preventDefault(),e.stopPropagation(),f();break}};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[p,c,d,f,g,t]),{containerRef:S,selectedItemRef:h,filteredCommands:c,selectedIndex:d,setSelectedIndex:u,isLoading:N,handleCommandSelect:t}},{useToken:X}=M,P={workflow:{color:"blue",icon:s.jsx(F,{}),labelKey:"chat.commandSelector.types.workflow"},skill:{color:"green",icon:s.jsx(K,{}),labelKey:"chat.commandSelector.types.skill"},mcp:{color:"purple",icon:s.jsx(D,{}),labelKey:"chat.commandSelector.types.mcp"}},U=({visible:p,onSelect:k,onCancel:j,searchText:f,onAutoComplete:g})=>{const{token:o}=X(),{t:i}=B(),{containerRef:c,selectedItemRef:R,filteredCommands:d,selectedIndex:u,setSelectedIndex:N,isLoading:I,handleCommandSelect:S}=z({visible:p,searchText:f,onSelect:k,onCancel:j,onAutoComplete:g});if(!p)return null;if(I)return s.jsxs("div",{style:{position:"absolute",bottom:"100%",left:0,right:0,background:o.colorBgContainer,border:`1px solid ${o.colorBorderSecondary}`,borderRadius:o.borderRadiusSM,boxShadow:o.boxShadowSecondary,padding:`${o.paddingSM}px ${o.paddingMD}px`,zIndex:1e3,marginBottom:o.marginXS,textAlign:"center"},children:[s.jsx(E,{size:"small"})," ",i("chat.commandSelector.loading")]});if(d.length===0)return s.jsx("div",{style:{position:"absolute",bottom:"100%",left:0,right:0,background:o.colorBgContainer,border:`1px solid ${o.colorBorderSecondary}`,borderRadius:o.borderRadiusSM,boxShadow:o.boxShadowSecondary,padding:`${o.paddingSM}px ${o.paddingMD}px`,zIndex:1e3,marginBottom:o.marginXS,textAlign:"center",color:o.colorTextSecondary},children:f?i("chat.commandSelector.emptyWithSearch",{search:f}):i("chat.commandSelector.empty")});const h=(t,a)=>{var b,C,w;const e=P[t.type],r=a===u,n=t.type==="mcp"?T(t.name):null,x=t.type==="mcp"?((b=t.metadata)==null?void 0:b.originalName)||(n==null?void 0:n.toolName)||t.displayName||t.name:null,y=t.type==="mcp"&&(((C=t.metadata)==null?void 0:C.serverName)||((w=t.metadata)==null?void 0:w.serverId)||(n==null?void 0:n.serverId))||null;return s.jsxs("div",{ref:r?R:null,className:`command-selector-item ${r?"selected":""}`,onClick:()=>S(t),onMouseEnter:()=>N(a),children:[s.jsxs("div",{className:"command-selector-item-header",children:[s.jsxs("div",{className:"command-selector-item-name",style:{color:o.colorPrimary},children:["/",t.type==="mcp"&&x?x:t.name]}),s.jsxs("div",{style:{display:"flex",gap:o.marginXS},children:[t.type==="mcp"&&y&&s.jsx(L,{color:"processing",children:y}),s.jsxs(L,{color:e.color,children:[e.icon," ",i(e.labelKey)]})]})]}),s.jsx("div",{className:"command-selector-item-description",style:{color:o.colorTextSecondary},children:t.description}),t.type==="mcp"&&y&&s.jsxs("div",{className:"command-selector-item-category",style:{color:o.colorTextTertiary},children:[i("common.server")," ",y]}),t.category&&s.jsxs("div",{className:"command-selector-item-category",style:{color:o.colorTextTertiary},children:[i("common.category")," ",t.category]}),t.tags&&t.tags.length>0&&s.jsx("div",{className:"command-selector-item-tags",children:t.tags.slice(0,3).map(m=>s.jsx(L,{children:m},m))})]},t.id)};return s.jsxs("div",{ref:c,className:"command-selector-container",style:{background:o.colorBgContainer,border:`1px solid ${o.colorBorderSecondary}`,borderRadius:o.borderRadiusSM,boxShadow:o.boxShadowSecondary},children:[s.jsx("div",{style:{padding:`${o.paddingXXS}px ${o.paddingSM}px`,borderBottom:`1px solid ${o.colorBorderSecondary}`,background:o.colorFillQuaternary,fontSize:o.fontSizeSM,color:o.colorTextTertiary},children:i("chat.commandSelector.navigationHint")}),d.map((t,a)=>h(t,a))]})};export{U as default};
1
+ import{j as s}from"./vendor-markdown-yOmFo5hK.js";import{C as $,d as v,p as T}from"./App-b3yZCRqq.js";import{a as l,u as B}from"./vendor-i18n-BNURlJ23.js";import{v as E,t as M,T as L,w as D,x as K,q as F}from"./vendor-antd-BpW-8RO2.js";import"./main-NZYpmPsh.js";import"./vendor-charts-fIPNnfk-.js";import"./vendor-mermaid-DA4JIJaA.js";const z=({visible:p,searchText:k,onSelect:j,onCancel:f,onAutoComplete:g})=>{const[o,i]=l.useState([]),[c,R]=l.useState([]),[d,u]=l.useState(0),[N,I]=l.useState(!1),S=l.useRef(null),h=l.useRef(null);l.useEffect(()=>{if(!p)return;const a=$.getInstance();(async()=>{I(!0);try{const r=await a.listCommands();v("[CommandSelector]","[CommandSelector] Fetched commands:",r),i(r),u(0)}catch(r){console.error("[CommandSelector] Failed to fetch commands:",r),i([])}finally{I(!1)}})()},[p]),l.useEffect(()=>{const a=o.filter(e=>{var x,y,b,C,w;const r=k.toLowerCase(),n=(e.displayName??"").toLowerCase();return e.name.toLowerCase().includes(r)||n.includes(r)||e.description.toLowerCase().includes(r)||e.type==="mcp"&&[(x=e.metadata)==null?void 0:x.serverId,(y=e.metadata)==null?void 0:y.serverName,(b=e.metadata)==null?void 0:b.originalName].filter(m=>typeof m=="string").some(m=>m.toLowerCase().includes(r))||(((C=e.category)==null?void 0:C.toLowerCase().includes(r))??!1)||(((w=e.tags)==null?void 0:w.some(m=>m.toLowerCase().includes(r)))??!1)});R(a),u(0)},[o,k]),l.useEffect(()=>{if(!h.current||!S.current)return;const a=S.current,e=h.current,r=a.getBoundingClientRect(),n=e.getBoundingClientRect();n.top<r.top?e.scrollIntoView({block:"start",behavior:"smooth"}):n.bottom>r.bottom&&e.scrollIntoView({block:"end",behavior:"smooth"})},[d,c]);const t=l.useCallback(async a=>{try{j({name:a.name,type:a.type,id:a.id})}catch(e){console.error(`[CommandSelector] Failed to select command '${a.name}':`,e)}},[j]);return l.useEffect(()=>{const a=e=>{if(p)switch(e.key){case"ArrowDown":case"n":if(e.key==="n"&&!e.ctrlKey)break;e.preventDefault(),e.stopPropagation(),u(r=>r<c.length-1?r+1:0);break;case"ArrowUp":case"p":if(e.key==="p"&&!e.ctrlKey)break;e.preventDefault(),e.stopPropagation(),u(r=>r>0?r-1:c.length-1);break;case"Enter":e.preventDefault(),e.stopPropagation(),c[d]&&t(c[d]);break;case" ":case"Tab":e.preventDefault(),e.stopPropagation(),c[d]&&g&&g(c[d].name);break;case"Escape":e.preventDefault(),e.stopPropagation(),f();break}};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[p,c,d,f,g,t]),{containerRef:S,selectedItemRef:h,filteredCommands:c,selectedIndex:d,setSelectedIndex:u,isLoading:N,handleCommandSelect:t}},{useToken:X}=M,P={workflow:{color:"blue",icon:s.jsx(F,{}),labelKey:"chat.commandSelector.types.workflow"},skill:{color:"green",icon:s.jsx(K,{}),labelKey:"chat.commandSelector.types.skill"},mcp:{color:"purple",icon:s.jsx(D,{}),labelKey:"chat.commandSelector.types.mcp"}},U=({visible:p,onSelect:k,onCancel:j,searchText:f,onAutoComplete:g})=>{const{token:o}=X(),{t:i}=B(),{containerRef:c,selectedItemRef:R,filteredCommands:d,selectedIndex:u,setSelectedIndex:N,isLoading:I,handleCommandSelect:S}=z({visible:p,searchText:f,onSelect:k,onCancel:j,onAutoComplete:g});if(!p)return null;if(I)return s.jsxs("div",{style:{position:"absolute",bottom:"100%",left:0,right:0,background:o.colorBgContainer,border:`1px solid ${o.colorBorderSecondary}`,borderRadius:o.borderRadiusSM,boxShadow:o.boxShadowSecondary,padding:`${o.paddingSM}px ${o.paddingMD}px`,zIndex:1e3,marginBottom:o.marginXS,textAlign:"center"},children:[s.jsx(E,{size:"small"})," ",i("chat.commandSelector.loading")]});if(d.length===0)return s.jsx("div",{style:{position:"absolute",bottom:"100%",left:0,right:0,background:o.colorBgContainer,border:`1px solid ${o.colorBorderSecondary}`,borderRadius:o.borderRadiusSM,boxShadow:o.boxShadowSecondary,padding:`${o.paddingSM}px ${o.paddingMD}px`,zIndex:1e3,marginBottom:o.marginXS,textAlign:"center",color:o.colorTextSecondary},children:f?i("chat.commandSelector.emptyWithSearch",{search:f}):i("chat.commandSelector.empty")});const h=(t,a)=>{var b,C,w;const e=P[t.type],r=a===u,n=t.type==="mcp"?T(t.name):null,x=t.type==="mcp"?((b=t.metadata)==null?void 0:b.originalName)||(n==null?void 0:n.toolName)||t.displayName||t.name:null,y=t.type==="mcp"&&(((C=t.metadata)==null?void 0:C.serverName)||((w=t.metadata)==null?void 0:w.serverId)||(n==null?void 0:n.serverId))||null;return s.jsxs("div",{ref:r?R:null,className:`command-selector-item ${r?"selected":""}`,onClick:()=>S(t),onMouseEnter:()=>N(a),children:[s.jsxs("div",{className:"command-selector-item-header",children:[s.jsxs("div",{className:"command-selector-item-name",style:{color:o.colorPrimary},children:["/",t.type==="mcp"&&x?x:t.name]}),s.jsxs("div",{style:{display:"flex",gap:o.marginXS},children:[t.type==="mcp"&&y&&s.jsx(L,{color:"processing",children:y}),s.jsxs(L,{color:e.color,children:[e.icon," ",i(e.labelKey)]})]})]}),s.jsx("div",{className:"command-selector-item-description",style:{color:o.colorTextSecondary},children:t.description}),t.type==="mcp"&&y&&s.jsxs("div",{className:"command-selector-item-category",style:{color:o.colorTextTertiary},children:[i("common.server")," ",y]}),t.category&&s.jsxs("div",{className:"command-selector-item-category",style:{color:o.colorTextTertiary},children:[i("common.category")," ",t.category]}),t.tags&&t.tags.length>0&&s.jsx("div",{className:"command-selector-item-tags",children:t.tags.slice(0,3).map(m=>s.jsx(L,{children:m},m))})]},t.id)};return s.jsxs("div",{ref:c,className:"command-selector-container",style:{background:o.colorBgContainer,border:`1px solid ${o.colorBorderSecondary}`,borderRadius:o.borderRadiusSM,boxShadow:o.boxShadowSecondary},children:[s.jsx("div",{style:{padding:`${o.paddingXXS}px ${o.paddingSM}px`,borderBottom:`1px solid ${o.colorBorderSecondary}`,background:o.colorFillQuaternary,fontSize:o.fontSizeSM,color:o.colorTextTertiary},children:i("chat.commandSelector.navigationHint")}),d.map((t,a)=>h(t,a))]})};export{U as default};