@deepseekcode/cli 1.0.26 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1057 -985
- package/package.json +31 -31
- package/web/dist/assets/{AutomationView-CPCd-Qhd.js → AutomationView-ClGqJM46.js} +1 -1
- package/web/dist/assets/{ChannelConfigView-D6JtjZyf.js → ChannelConfigView-BcGUdK94.js} +1 -1
- package/web/dist/assets/{ConnectorsView-BPPr7T9p.js → ConnectorsView-Dadj20jv.js} +1 -1
- package/web/dist/assets/{FileTreeView-CO8knuwu.js → FileTreeView-DLRQZmLP.js} +1 -1
- package/web/dist/assets/{HookConfigView-CYuzwf8u.js → HookConfigView-DE0NCrV9.js} +1 -1
- package/web/dist/assets/{ModelsView-Cji4mbXE.js → ModelsView-DVTuTql9.js} +1 -1
- package/web/dist/assets/{PluginsView-CKKnYKMP.js → PluginsView-DBF_BvKL.js} +1 -1
- package/web/dist/assets/SessionGrid-ByIAFTc2.js +38 -0
- package/web/dist/assets/SettingsPanel-CHRy0Xqj.js +4 -0
- package/web/dist/assets/{SkillsView-DmQGY9v0.js → SkillsView-BAorWQAI.js} +1 -1
- package/web/dist/assets/{TemplatesTab-_vSIuTZP.js → TemplatesTab-DEblm2pS.js} +1 -1
- package/web/dist/assets/{TerminalView-CTU0aA8o.js → TerminalView-Cnnipr8e.js} +1 -1
- package/web/dist/assets/ThreeScene-5Zi32o_j.js +2863 -0
- package/web/dist/assets/ThreeScene-DvOrMIoG.css +1 -0
- package/web/dist/assets/{ToolsView-DUEqePPo.js → ToolsView-lOHdaw4V.js} +1 -1
- package/web/dist/assets/{icons-qcawb7PZ.js → icons-DLsYqrD5.js} +144 -119
- package/web/dist/assets/index-Bht_ARrv.css +1 -0
- package/web/dist/assets/{index-DUpwXfa-.js → index-DEninW1j.js} +9 -9
- package/web/dist/assets/{markdown-yjmXQjrx.js → markdown-tZ6sw2sR.js} +1 -1
- package/web/dist/assets/{panels-CX_dYEv0.js → panels-wDJMsvra.js} +1 -1
- package/web/dist/assets/{react-vendor-CSlQceOk.js → react-vendor-BRkWBfPR.js} +1 -1
- package/web/dist/assets/{state-DOzZasIm.js → state-B80cA8v4.js} +1 -1
- package/web/dist/favicon.svg +38 -30
- package/web/dist/index.html +7 -7
- package/web/dist/logo.svg +38 -30
- package/web/dist/assets/SessionGrid-BOpVWUEK.js +0 -37
- package/web/dist/assets/SettingsPanel-R1fOoB25.js +0 -4
- package/web/dist/assets/index-DL2ULWxM.css +0 -1
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{j as e}from"./markdown-tZ6sw2sR.js";import{a as s,h as U,F as ie,$ as F,a8 as oe,aO as de,l as V,L as K,b as Z,b5 as Q,o as xe,aZ as q,D as ue,k as me,b6 as le,b7 as ce,E as X,b8 as pe,b9 as he,ba as ge,al as be,O as J,bb as fe,bc as ee,_ as te,bd as je,b0 as ke,t as ve,be as ye,bf as we,a9 as Ne}from"./icons-DLsYqrD5.js";import{a as S,t as g,u as G,d as se,f as Ce,U as Se,V as Te,z as ae}from"./index-DEninW1j.js";import"./react-vendor-BRkWBfPR.js";import"./state-B80cA8v4.js";import"./panels-wDJMsvra.js";function ze(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Ee(t){return new Date(t).toLocaleString()}function $e(){const[t,x]=s.useState([]),[i,n]=s.useState(null),[p,l]=s.useState(""),[j,k]=s.useState(""),[v,u]=s.useState(!1),[y,N]=s.useState(!1),E=s.useCallback(async()=>{u(!0);try{const a=await S.config.files.list();a.success&&Array.isArray(a.data)&&x(a.data)}catch{g.error("Failed to load config files")}finally{u(!1)}},[]),w=s.useCallback(async a=>{try{const c=await S.config.files.read(a);if(c.success&&c.data){const m=c.data;n(m.name),l(m.content),k(m.content)}}catch{g.error(`Failed to read ${a}`)}},[]);s.useEffect(()=>{E()},[E]);const D=s.useCallback(async()=>{if(i){N(!0);try{const a=await S.config.files.write(i,p);a.success?(k(p),g.success(`${i} saved`),E()):g.error(a.error||"Failed to save")}catch{g.error("Failed to save file")}finally{N(!1)}}},[i,p,E]),b=p!==j,$=(i==null?void 0:i.endsWith(".yaml"))||(i==null?void 0:i.endsWith(".yml")),O=i==null?void 0:i.endsWith(".json"),R=a=>$?a.replace(/(#.*)$/,'<span class="text-dark-muted">$1</span>').replace(/^(\s*)([\w-]+)(:)/,'$1<span class="text-accent-blue">$2</span>$3').replace(/:\s+(true|false|null|~)(\s*)$/,': <span class="text-accent-purple">$1</span>$2').replace(/:\s+(\d+\.?\d*)(\s*)$/,': <span class="text-accent-green">$1</span>$2').replace(/:\s+"([^"]*)"(\s*)$/,': <span class="text-accent-yellow">"$1"</span>$2'):O?a.replace(/(\s*"[^"]*")(\s*:)/g,'<span class="text-accent-blue">$1</span>$2').replace(/:\s+(true|false|null)/g,': <span class="text-accent-purple">$1</span>').replace(/:\s+(\d+\.?\d*)/g,': <span class="text-accent-green">$1</span>').replace(/:\s+"([^"]*)"/g,': <span class="text-accent-yellow">"$1"</span>'):a;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-sm font-medium text-dark-text",children:"Config Files"}),e.jsx("button",{onClick:E,disabled:v,className:"p-1.5 rounded hover:bg-dark-hover transition-colors text-dark-muted",title:"Refresh file list",children:e.jsx(U,{size:14,className:v?"animate-spin":""})})]}),t.length===0&&!v&&e.jsx("p",{className:"text-xs text-dark-muted",children:"No config files found in ~/.agent/"}),t.length>0&&e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:"w-48 shrink-0 space-y-0.5 max-h-[300px] overflow-y-auto custom-scrollbar",children:t.map(a=>e.jsxs("button",{onClick:()=>w(a.name),className:`w-full text-left px-2.5 py-1.5 rounded text-xs flex items-center gap-2 transition-colors ${i===a.name?"bg-accent-blue/10 text-accent-blue":"text-dark-text hover:bg-dark-hover"}`,children:[e.jsx(ie,{size:12,className:"shrink-0"}),e.jsx("span",{className:"truncate flex-1",children:a.name}),!a.editable&&e.jsx("span",{className:"text-[10px] text-dark-muted shrink-0",title:"Read-only",children:"read"})]},a.name))}),i?e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted",children:[e.jsx("span",{className:"text-dark-text font-medium",children:i}),t.find(a=>a.name===i)&&e.jsxs("span",{children:[ze(t.find(a=>a.name===i).size)," · ",Ee(t.find(a=>a.name===i).modified)]}),b&&e.jsxs("span",{className:"text-accent-yellow flex items-center gap-1",children:[e.jsx(F,{size:10}),"unsaved changes"]})]}),e.jsxs("button",{onClick:D,disabled:!b||y,className:`flex items-center gap-1 px-2.5 py-1 rounded text-xs transition-all ${b?"bg-accent-blue text-white hover:opacity-90":"bg-dark-hover text-dark-muted cursor-not-allowed"}`,children:[e.jsx(oe,{size:12}),y?"Saving...":"Save"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"w-full h-[260px] p-3 rounded-lg bg-dark-bg border border-dark-border font-mono text-xs leading-relaxed overflow-auto custom-scrollbar pointer-events-none",dangerouslySetInnerHTML:{__html:p.split(`
|
|
2
|
+
`).map(R).join(`
|
|
3
|
+
`)||" "}}),e.jsx("textarea",{value:p,onChange:a=>l(a.target.value),className:"absolute inset-0 w-full h-full p-3 rounded-lg bg-transparent border border-dark-border font-mono text-xs leading-relaxed resize-none overflow-auto custom-scrollbar text-transparent caret-dark-text focus:outline-none focus:border-accent-blue/50",style:{color:"transparent"},spellCheck:!1})]})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-dark-muted",children:"Select a file to edit"})]})]})}function Oe(){const{t}=G(),[x,i]=s.useState(null),[n,p]=s.useState(null),[l,j]=s.useState({running:!1,logs:[]}),[k,v]=s.useState(!1),u=s.useRef(null),y=s.useRef(l),N=s.useRef(null),[E,w]=s.useState(()=>{try{return localStorage.getItem("dsc.stt.lang")==="zh"?"zh":"en"}catch{return"en"}}),D=s.useCallback(o=>{w(o);try{localStorage.setItem("dsc.stt.lang",o)}catch{}window.dispatchEvent(new CustomEvent("stt-lang-changed",{detail:{lang:o}}))},[]);s.useEffect(()=>{y.current=l},[l]);const b=s.useCallback(async()=>{v(!0);const o=await S.stt.status();o.success&&o.data?(i(o.data),o.data.env&&p(o.data.env)):o.error&&g.error(o.error),v(!1)},[]);s.useEffect(()=>{b()},[b]);const $=s.useCallback(async()=>{const o=await S.stt.installStatus();if(o.success&&o.data){const z=y.current.running;j(o.data),o.data.running?u.current=window.setTimeout(()=>void $(),1e3):(b(),z&&o.data.status==="done"&&window.dispatchEvent(new CustomEvent("stt-backends-changed")))}},[b]);s.useEffect(()=>()=>{u.current&&window.clearTimeout(u.current)},[]),s.useEffect(()=>{N.current&&(N.current.scrollTop=N.current.scrollHeight)},[l.logs]);const O=s.useCallback(async o=>{var d,h,f,P;const z=await S.stt.install(o);z.success&&((d=z.data)!=null&&d.started)?(j({running:!0,backend:o,logs:[],status:"running"}),$()):(h=z.data)!=null&&h.alreadyRunning?(g.info(t("stt.setup.jobInProgress")),$()):j({running:!1,backend:o,logs:[],status:"error",error:z.error||((f=z.data)==null?void 0:f.error)||"install failed",manualCommand:(P=z.data)==null?void 0:P.manualCommand})},[$,t]),R=s.useCallback(async()=>{await S.stt.cancelInstall(),$()},[$]),a=s.useCallback(o=>{navigator.clipboard.writeText(o).then(()=>g.success(t("stt.setup.copySuccess")),()=>g.error(t("stt.setup.copyFailed")))},[t]),c=l.running?l.backend:void 0,m=l.running,T=o=>o?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-accent-green/15 text-accent-green",children:[e.jsx(V,{size:12}),t("stt.setup.installed")]}):e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-dark-hover text-dark-muted",children:[e.jsx(me,{size:12}),t("stt.setup.notInstalled")]}),C=(o,z,d)=>{var W;const h=((W=x==null?void 0:x.backends)==null?void 0:W[o])??{installed:!1},f=c===o,P=m&&!f,_=E===o;return e.jsxs("div",{className:se("rounded-lg border p-3 flex items-start justify-between gap-3 transition-colors cursor-pointer",_?"border-accent-blue/50 bg-accent-blue/5":"border-dark-border bg-dark-bg hover:border-dark-hover"),onClick:()=>D(o),children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:se("w-9 h-9 shrink-0 rounded-lg flex items-center justify-center text-sm font-semibold",_?"bg-accent-blue/15 text-accent-blue":"bg-accent-blue/10 text-accent-blue"),children:o==="en"?"W":"F"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-medium text-dark-text",children:z}),T(h.installed),_&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-accent-blue/15 text-accent-blue",children:[e.jsx(Q,{size:12}),t("stt.setup.inUse")]})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-[11px] text-dark-muted",children:[e.jsx("code",{className:"text-[10px] bg-dark-hover px-1.5 py-0.5 rounded",children:d}),e.jsx("span",{children:t(o==="en"?"stt.setup.whisperDesc":"stt.setup.funasrDesc")})]}),o==="zh"&&e.jsxs("p",{className:"mt-1 text-[11px] text-dark-muted flex items-center gap-1",children:[e.jsx(q,{size:11}),t("stt.setup.torchHint")]}),_&&!h.installed&&e.jsxs("p",{className:"mt-1 text-[11px] text-accent-orange flex items-center gap-1",children:[e.jsx(F,{size:11}),t("stt.setup.engineNotInstalledHint")]})]})]}),e.jsx("div",{className:"shrink-0",onClick:Y=>Y.stopPropagation(),children:f?e.jsxs("button",{className:"btn btn-secondary cursor-not-allowed opacity-70",disabled:!0,children:[e.jsx(K,{size:14,className:"animate-spin"}),t("stt.setup.installing")]}):P?e.jsx("button",{className:"btn btn-secondary cursor-not-allowed opacity-50",disabled:!0,children:t("stt.setup.installing")}):h.installed?e.jsxs("button",{className:"btn btn-ghost",onClick:()=>void b(),title:t("stt.setup.recheck"),children:[e.jsx(U,{size:14}),t("stt.setup.recheck")]}):e.jsxs("button",{className:"btn btn-accent",onClick:()=>void O(o),children:[e.jsx(ue,{size:14}),t("stt.setup.install")]})})]})},M=(n==null?void 0:n.pythonAvailable)&&(n==null?void 0:n.pipAvailable);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-bg p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-dark-text",children:[e.jsx(de,{size:14,className:"text-accent-blue"}),t("stt.setup.envCard")]}),e.jsxs("button",{className:"btn btn-ghost",onClick:()=>void b(),disabled:k,children:[e.jsx(U,{size:13,className:k?"animate-spin":""}),t("stt.setup.recheck")]})]}),e.jsxs("div",{className:"mt-2.5 space-y-2",children:[n?n.pythonAvailable?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-text",children:[e.jsx(V,{size:13,className:"text-accent-green"}),t("stt.setup.pythonOk",{version:(n.pythonVersion||"").replace(/^Python\s*/i,"")||n.pythonPath||"Python"}),n.pythonPath?e.jsx("code",{className:"text-[10px] text-dark-muted",children:n.pythonPath}):null]}):e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-accent-red/30 bg-accent-red/5 px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent-red",children:[e.jsx(F,{size:13}),t("stt.setup.pythonMissing")]}),e.jsx("a",{className:"btn btn-secondary !py-1 !px-2 text-xs",href:"https://www.python.org/downloads/",target:"_blank",rel:"noreferrer",children:t("stt.setup.pythonGuide")})]}):e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted",children:[e.jsx(K,{size:13,className:"animate-spin"}),t("stt.setup.envChecking")]}),n&&!n.pipAvailable&&e.jsxs("div",{className:"rounded-md border border-accent-red/30 bg-accent-red/5 px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent-red",children:[e.jsx(F,{size:13}),t("stt.setup.pipMissing")]}),e.jsxs("div",{className:"mt-1.5",children:[e.jsx("div",{className:"text-[10px] text-dark-muted mb-1",children:t("stt.setup.pipGuide")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("code",{className:"flex-1 rounded bg-dark-bg border border-dark-border px-2 py-1 font-mono text-[10px] text-dark-text break-all select-all",children:[n.pythonPath||"python"," -m ensurepip --upgrade"]}),e.jsx("button",{className:"btn btn-ghost !py-1 !px-2 text-xs",onClick:()=>a(`${n.pythonPath||"python"} -m ensurepip --upgrade`),children:e.jsx(Z,{size:12})})]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-dark-text",children:[e.jsx(Q,{size:14,className:"text-accent-blue"}),t("stt.setup.defaultEngine")]}),e.jsx("p",{className:"mt-1 text-[11px] text-dark-muted",children:t("stt.setup.defaultEngineHint")})]}),C("en",t("stt.setup.whisperTitle"),"base.en"),C("zh",t("stt.setup.funasrTitle"),"paraformer-zh"),m&&e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-bg p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent-blue font-medium",children:[e.jsx(K,{size:13,className:"animate-spin"}),t("stt.setup.installing"),e.jsxs("span",{className:"text-dark-muted font-normal",children:["(",c==="en"?"whisper":"funasr",")"]})]}),e.jsx("button",{className:"btn btn-danger !py-1 !px-2 text-xs",onClick:()=>void R(),children:t("stt.setup.cancel")})]}),e.jsx("div",{ref:N,className:"rounded-md border border-dark-border bg-dark-bg p-2.5 font-mono text-[11px] text-dark-muted overflow-auto max-h-48 whitespace-pre-wrap custom-scrollbar",children:l.logs.length===0?e.jsx("span",{className:"text-dark-muted/70",children:t("stt.setup.logWaiting")}):l.logs.join(`
|
|
4
|
+
`)})]}),!m&&l.status&&l.status!=="done"&&e.jsxs("div",{className:"rounded-lg border border-accent-red/30 bg-accent-red/5 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent-red font-medium",children:[e.jsx(F,{size:13}),l.status==="timeout"?t("stt.setup.installTimeout"):l.status==="cancelled"?t("stt.setup.installCancelled"):t("stt.setup.installFailed")]}),l.error?e.jsx("p",{className:"mt-1 text-xs text-accent-red/90 break-all",children:l.error}):null,(l.manualCommand||l.status==="error"&&c)&&e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"text-[10px] text-dark-muted mb-1 flex items-center gap-1",children:[e.jsx(xe,{size:11}),t("stt.setup.manualCommand")]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("code",{className:"flex-1 rounded bg-dark-bg border border-dark-border px-2 py-1.5 font-mono text-[10px] text-dark-text break-all whitespace-pre-wrap select-all",children:l.manualCommand??(c==="zh"?`${(n==null?void 0:n.pythonPath)||"python"} -m pip install -U "funasr>=1.1.0" "modelscope>=1.15.0" "torch>=2.0.0"`:`${(n==null?void 0:n.pythonPath)||"python"} -m pip install "faster-whisper>=1.0.0"`)}),l.manualCommand&&e.jsxs("button",{className:"btn btn-ghost !py-1 !px-2 text-xs shrink-0",onClick:()=>a(l.manualCommand),children:[e.jsx(Z,{size:12}),t("stt.setup.copyCommand")]})]})]})]}),!m&&l.status==="done"&&e.jsxs("div",{className:"rounded-lg border border-accent-green/30 bg-accent-green/5 px-3 py-2.5 flex items-center gap-2 text-xs text-accent-green",children:[e.jsx(V,{size:14}),t("stt.setup.installDone")]}),!m&&M&&x&&!x.backends.en.installed&&!x.backends.zh.installed&&e.jsx("p",{className:"text-[11px] text-dark-muted px-1",children:t("stt.setup.chooseHint")})]})}const ne=["google-workspace","gmail","ms365-graph","x-twitter"],Me={"google-workspace":ce,gmail:ge,"ms365-graph":he,"x-twitter":pe},Be={"google-workspace":"Google Workspace",gmail:"Gmail","ms365-graph":"Microsoft 365","x-twitter":"X / Twitter"},Ie={ready:"text-accent-green",installed:"text-dark-muted",connecting:"text-accent-yellow",installing:"text-accent-yellow",error:"text-accent-red",disabled:"text-dark-muted","not-installed":"text-dark-muted"};function De({onNavigate:t}){const{t:x}=G(),[i,n]=s.useState(null),[p,l]=s.useState(!1),[j,k]=s.useState([]),[v,u]=s.useState(!0),[y,N]=s.useState(null),[E,w]=s.useState(null),D=s.useCallback(async()=>{l(!0);try{const a=await S.tools.get("computer_use");n(a.success&&a.data?!!a.data.enabled:!1)}catch{n(!1)}l(!1)},[]),b=s.useCallback(async()=>{var c;u(!0),w(null);const a=await S.connectors.list();a.success&&Array.isArray((c=a.data)==null?void 0:c.connectors)?k(a.data.connectors.filter(m=>ne.includes(m.id))):w(a.error||x("settings.capabilities.loadFailed")),u(!1)},[x]);s.useEffect(()=>{D(),b()},[]);const $=async()=>{if(i===null)return;const a=!i;N("computer_use");try{const c=await S.tools.toggle("computer_use",a);c.success?n(a):w(c.error||x("settings.capabilities.toggleFailed"))}catch(c){w(c instanceof Error?c.message:String(c))}N(null)},O=async a=>{const c=!a.enabled;if(c&&a.missingEnv&&a.missingEnv.length>0){t==null||t("connectors");return}N(a.id),w(null),k(m=>m.map(T=>T.id===a.id?{...T,enabled:c,status:c?"connecting":"disabled"}:T));try{const m=await S.connectors.toggle(a.id,c);if(m.success&&m.data){const T=m.data;k(C=>C.map(M=>M.id===T.id?T:M))}else w(m.error||x("settings.capabilities.toggleFailed")),b()}catch(m){w(m instanceof Error?m.message:String(m)),b()}N(null)},R=a=>{if(a.missingEnv&&a.missingEnv.length>0)return`${x("connectors.needCredentials")} ${a.missingEnv.join(", ")}`;const c=a.status==="not-installed"?"notInstalled":a.status;return x(`connectors.${c}`)||a.status};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 py-1",children:[e.jsxs("div",{className:"min-w-0 flex items-start gap-2",children:[e.jsx(le,{size:16,className:"text-accent-blue mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-dark-text",children:"Computer Use"}),e.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:"GUI 截屏 + 鼠标键盘操控(Windows)。每次调用需审批;需要视觉模型读屏。"})]})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":!!i,disabled:p||y==="computer_use",onClick:$,className:`relative w-9 h-5 rounded-full transition-colors shrink-0 disabled:opacity-50 ${i?"bg-accent-blue":"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?"translate-x-[18px]":"translate-x-0.5"}`})})]}),e.jsxs("div",{className:"pt-3 border-t border-dark-border",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"text-xs font-semibold text-dark-text flex items-center gap-1.5",children:[e.jsx(ce,{size:13,className:"text-accent-purple"}),"Grok 式连接器(Gmail / Workspace / M365 / X)"]}),e.jsxs("button",{onClick:()=>t==null?void 0:t("connectors"),className:"text-xs text-dark-muted hover:text-accent-blue flex items-center gap-1 transition-colors",children:["全部管理",e.jsx(X,{size:11})]})]}),v?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted py-2",children:[e.jsx(K,{size:12,className:"animate-spin"}),"Loading..."]}):e.jsx("div",{className:"space-y-1",children:ne.map(a=>{const c=j.find(o=>o.id===a),m=Me[a]??Ae,T=y===a,C=(c==null?void 0:c.missingEnv)&&c.missingEnv.length>0,M=c?Ie[c.status]??"text-dark-muted":"text-dark-muted";return e.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-sm text-dark-text flex items-center gap-1.5 truncate",children:[e.jsx(m,{size:14,className:"shrink-0 text-dark-muted"}),Be[a],C&&e.jsx(F,{size:12,className:"text-accent-yellow shrink-0"})]}),c&&e.jsxs("div",{className:`text-[11px] mt-0.5 flex items-center gap-1 ${M}`,children:[c.status==="ready"?e.jsx(V,{size:10}):null,R(c),typeof c.toolCount=="number"&&c.toolCount>0?` · ${x("connectors.toolCount",{count:c.toolCount})}`:""]})]}),c?e.jsx("button",{type:"button",role:"switch","aria-checked":c.enabled,disabled:T,onClick:()=>O(c),className:`relative w-9 h-5 rounded-full transition-colors shrink-0 disabled:opacity-50 ${c.enabled?"bg-accent-blue":"bg-dark-border"}`,children:T?e.jsx(K,{size:12,className:"absolute left-[7px] top-[3px] animate-spin text-white"}):e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${c.enabled?"translate-x-[18px]":"translate-x-0.5"}`})}):e.jsx("button",{onClick:()=>t==null?void 0:t("connectors"),className:"text-xs text-dark-muted hover:text-accent-blue shrink-0 transition-colors",children:"添加"})]},a)})})]}),e.jsxs("div",{className:"pt-3 border-t border-dark-border flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex items-start gap-2",children:[e.jsx(q,{size:16,className:"text-accent-yellow mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-dark-text",children:"xAI (Grok) API"}),e.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:"官方 OpenAI 兼容端点,支持 X 实时数据的 Grok 系列模型。"})]})]}),e.jsxs("button",{onClick:()=>t==null?void 0:t("models"),className:"flex items-center gap-1.5 px-3 py-1.5 bg-accent-blue/10 text-accent-blue border border-accent-blue/30 rounded-lg hover:bg-accent-blue/20 transition-colors text-xs shrink-0",children:["配置",e.jsx(X,{size:11})]})]}),E&&e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs text-accent-red bg-accent-red/10 border border-accent-red/30 rounded-lg px-3 py-2",children:[e.jsx("span",{className:"truncate",children:E}),e.jsxs("button",{onClick:()=>{b(),D(),w(null)},className:"shrink-0 hover:text-accent-red/80 flex items-center gap-1",children:[e.jsx(U,{size:11}),"重试"]})]})]})}function Ae(t){return e.jsxs("svg",{width:t.size??14,height:t.size??14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:t.className,children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z"})]})}function H({label:t,value:x,onChange:i,min:n,max:p,disabled:l,envOverridden:j,hint:k}){return e.jsxs("div",{className:"mb-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-muted mb-1",children:[t,j&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-accent-yellow",title:k,children:[e.jsx(F,{size:12})," env"]})]}),e.jsx("input",{type:"number",value:x,onChange:v=>i(v.target.value),min:n,max:p,disabled:l||j,className:"w-40 bg-dark-bg border border-dark-border rounded-lg px-3 py-1.5 text-sm text-dark-text font-mono focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all disabled:opacity-50"})]})}function Le(){const{t}=G(),[x,i]=s.useState(!0),[n,p]=s.useState(!1),[l,j]=s.useState({}),[k,v]=s.useState(!1),[u,y]=s.useState(""),[N,E]=s.useState(null),[w,D]=s.useState(!1),[b,$]=s.useState(""),[O,R]=s.useState(""),[a,c]=s.useState(""),[m,T]=s.useState(""),[C,M]=s.useState(""),o=s.useCallback(async()=>{i(!0);try{const d=await S.config.context.get();if(d.success&&d.data){const h=d.data.values??{};j(d.data.envOverridden??{}),v(d.data.effective.offload),y(d.data.defaultArtifactRoot??""),E(d.data.stats??null),D(!!h.artifactOffload),$(typeof h.artifactDir=="string"?h.artifactDir:""),R(h.artifactMaxTotalMb!=null?String(h.artifactMaxTotalMb):""),c(h.artifactTtlDays!=null?String(h.artifactTtlDays):""),T(h.outboundToolBytes!=null?String(h.outboundToolBytes):""),M(h.turnBudgetTokens!=null?String(h.turnBudgetTokens):"")}}catch{}i(!1)},[]);s.useEffect(()=>{o()},[o]);const z=async()=>{p(!0);try{const d={artifactOffload:w};l.artifactDir||(d.artifactDir=b.trim()||null),!l.artifactMaxTotalMb&&O.trim()&&(d.artifactMaxTotalMb=parseInt(O,10)),!l.artifactTtlDays&&a.trim()&&(d.artifactTtlDays=parseInt(a,10)),!l.outboundToolBytes&&m.trim()&&(d.outboundToolBytes=parseInt(m,10)),!l.turnBudgetTokens&&C.trim()&&(d.turnBudgetTokens=parseInt(C,10));for(const f of["artifactMaxTotalMb","artifactTtlDays","outboundToolBytes","turnBudgetTokens"])if(f in d&&(isNaN(d[f])||d[f]<=0)){g.error(t("settings.contextOffload.invalidNumber")),p(!1);return}const h=await S.config.context.save(d);h.success?(g.success(t("settings.contextOffload.saved")),await o()):g.error(h.error||t("settings.contextOffload.saveFailed"))}catch(d){g.error(d instanceof Error?d.message:String(d))}p(!1)};return x?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-dark-muted py-2",children:[e.jsx(K,{size:14,className:"animate-spin"}),t("common.loading")]}):e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:t("settings.contextOffload.desc")}),e.jsxs("label",{className:"flex items-center justify-between mb-4 cursor-pointer",children:[e.jsxs("span",{className:"text-sm",children:[t("settings.contextOffload.enableLabel"),e.jsxs("span",{className:`ml-2 text-xs ${k?"text-accent-green":"text-dark-muted"}`,children:["(",t("settings.contextOffload.currently"),": ",k?"ON":"OFF",")"]})]}),e.jsx("button",{role:"switch","aria-checked":w,onClick:()=>D(!w),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${w?"bg-accent-green":"bg-dark-border"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${w?"translate-x-6":"translate-x-1"}`})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-x-6",children:[e.jsx(H,{label:t("settings.contextOffload.maxTotalMb"),value:O,onChange:R,min:1,envOverridden:l.artifactMaxTotalMb}),e.jsx(H,{label:t("settings.contextOffload.ttlDays"),value:a,onChange:c,min:1,max:365,envOverridden:l.artifactTtlDays}),e.jsx(H,{label:`${t("settings.contextOffload.outboundBytes")} (${t("settings.contextOffload.optional")})`,value:m,onChange:T,min:1024,envOverridden:l.outboundToolBytes}),e.jsx(H,{label:t("settings.contextOffload.turnBudget"),value:C,onChange:M,min:1e3,envOverridden:l.turnBudgetTokens})]}),e.jsxs("div",{className:"mb-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-muted mb-1",children:[t("settings.contextOffload.dir")," (",t("settings.contextOffload.optional"),")",l.artifactDir&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-accent-yellow",children:[e.jsx(F,{size:12})," env"]})]}),e.jsx("input",{type:"text",value:b,onChange:d=>$(d.target.value),disabled:l.artifactDir,placeholder:u,className:"w-full bg-dark-bg border border-dark-border rounded-lg px-3 py-1.5 text-sm text-dark-text font-mono focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all disabled:opacity-50"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:z,disabled:n||x,className:"px-3 py-1.5 rounded-lg text-sm bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:t(n?"common.saving":"common.save")}),e.jsx("span",{className:"text-xs text-dark-muted",children:t("settings.contextOffload.envHint")})]}),N&&N.count>0&&e.jsx("p",{className:"text-xs text-dark-muted mt-2",children:t("settings.contextOffload.stats",{count:N.count,size:(N.totalBytes/1024/1024).toFixed(1)})})]})}const Re=s.memo(function({nameKey:x,descriptionKey:i,colors:n,isSelected:p,onClick:l}){const{t:j}=G(),k=["bg","surface","border","text","muted","accentBlue","accentGreen","accentRed","accentYellow","accentPurple"];return e.jsxs("button",{onClick:l,className:`relative flex flex-col items-center rounded-xl p-2 transition-all focus:outline-none focus:ring-2 focus:ring-accent-blue/50 ${p?"ring-2 ring-accent-blue/60 bg-dark-bg border border-accent-blue/40 shadow-sm":"border border-dark-border hover:border-accent-blue/30 bg-dark-bg hover:shadow-sm"}`,title:j(i),"aria-pressed":p,"aria-label":j(x),children:[e.jsx("div",{className:"flex gap-[2px] rounded-md overflow-hidden w-full h-8 mb-1.5 border border-dark-border/40",children:k.map(v=>e.jsx("div",{className:"flex-1",style:{backgroundColor:n[v]},title:v},v))}),e.jsx("span",{className:`text-[11px] font-medium truncate w-full text-center ${p?"text-accent-blue":"text-dark-text"}`,children:j(x)}),p&&e.jsx("span",{className:"absolute top-1 right-1 w-4 h-4 bg-accent-blue rounded-full flex items-center justify-center shadow-sm",children:e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",children:e.jsx("path",{d:"M1.5 4L3.5 6L6.5 2",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})}),Fe="1.0.0",Pe={version:Fe},re=[{key:"bg",labelKey:"settings.colorBg"},{key:"surface",labelKey:"settings.colorSurface"},{key:"border",labelKey:"settings.colorBorder"},{key:"text",labelKey:"settings.colorText"},{key:"muted",labelKey:"settings.colorMuted"},{key:"accentBlue",labelKey:"settings.colorAccentBlue"},{key:"accentGreen",labelKey:"settings.colorAccentGreen"},{key:"accentRed",labelKey:"settings.colorAccentRed"},{key:"accentYellow",labelKey:"settings.colorAccentYellow"},{key:"accentPurple",labelKey:"settings.colorAccentPurple"}],_e={language:["language","lang","Chinese","中文","English","en","zh"],theme:["theme","dark","light","color","palette","custom"],display:["display","view","developer","activity","界面","视图","开发者","活动"],provider:["provider","model","api","key","openai","anthropic","deepseek"],context:["context","max","window","token","上下文","offload","artifact","外置"],configFiles:["config","file","yaml","json","editor"],capabilities:["capabilities","computer","use","gmail","google","workspace","sharepoint","m365","twitter","x","grok","xai","connector","agent","能力","电脑","推特"],system:["system","server","uptime","restart","reboot"],about:["about","version","info"],stt:["voice","语音","stt","whisper","funasr","安装","install","python","pip","speech"]},Xe=s.memo(function({onNavigate:x,focusSection:i}){const{t:n}=G(),{theme:p,setTheme:l,themePresetId:j,setThemePreset:k,language:v,setLanguage:u,customTheme:y,customThemeEnabled:N,setCustomTheme:E,setCustomThemeEnabled:w,resetCustomTheme:D,developerView:b,setDeveloperView:$}=Ce(),[O,R]=s.useState(N),a=s.useMemo(()=>p==="dark"?"dark":p==="light"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",[p]),c=s.useMemo(()=>Object.values(Se),[]),[m,T]=s.useState(0),[C,M]=s.useState(!1),[o,z]=s.useState(!1),[d,h]=s.useState(""),f=s.useCallback(r=>{if(!d.trim())return!0;const I=d.toLowerCase().trim();return(_e[r]??[]).some(A=>A.toLowerCase().includes(I))},[d]),P=s.useRef(null);s.useEffect(()=>{var r;(i==null?void 0:i.section)==="stt"&&((r=P.current)==null||r.scrollIntoView({behavior:"smooth",block:"start"}))},[i==null?void 0:i.nonce]),s.useEffect(()=>{let r=!0;const I=async()=>{try{const A=await S.system.status();r&&A.success&&A.data&&T(A.data.uptime)}catch{}};I();const B=setInterval(I,C?2e3:1e4);return()=>{r=!1,clearInterval(B)}},[C]);const _=s.useCallback(async()=>{if(window.confirm("Restart the server? All active sessions will be disconnected.")){M(!0);try{const r=await S.system.restart();r.success?g.info("Server restarting..."):(g.error(r.error||"Restart failed"),M(!1))}catch{g.error("Failed to send restart request"),M(!1)}}},[]),W=s.useCallback(async()=>{if(window.confirm("Shut down the server? This will stop the entire backend process.")&&window.confirm("Are you sure? All active sessions and unsaved work will be lost.")){z(!0);try{const r=await S.system.shutdown();r.success?g.info("Server shutting down..."):(g.error(r.error||"Shutdown failed"),z(!1))}catch{g.error("Failed to send shutdown request"),z(!1)}}},[]);s.useEffect(()=>{C&&m<1e4&&(M(!1),g.success("Server restarted"))},[m,C]);const Y=r=>{const I=Math.floor(r/1e3),B=Math.floor(I/60),A=Math.floor(B/60);return A>0?`${A}h ${B%60}m`:B>0?`${B}m ${I%60}s`:`${I}s`};return e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar p-4 bg-transparent",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4 gap-4 rounded-xl border border-dark-border bg-dark-surface p-3",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2 shrink-0",children:[e.jsx(be,{size:18,className:"text-accent-blue"}),n("settings.title")]}),e.jsxs("div",{className:"relative flex-1 max-w-xs",children:[e.jsx(J,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted pointer-events-none"}),e.jsx("input",{type:"text",value:d,onChange:r=>h(r.target.value),placeholder:"Search settings...",className:"w-full bg-dark-bg border border-dark-border rounded-lg pl-9 pr-3 py-1.5 text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all"}),d&&e.jsx("button",{onClick:()=>h(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-dark-muted hover:text-dark-text text-xs p-1 rounded",children:"×"})]})]}),e.jsxs("div",{className:"space-y-5 max-w-3xl",children:[f("language")&&e.jsx(L,{icon:fe,iconColor:"text-accent-blue",title:n("settings.language"),children:e.jsx("div",{className:"flex gap-2",children:["zh-CN","en"].map(r=>e.jsx("button",{onClick:()=>u(r),className:`px-4 py-2 rounded-lg transition-all ${v===r?"bg-accent-blue text-white":"bg-dark-hover text-dark-text hover:bg-dark-border"}`,children:n(r==="zh-CN"?"settings.languageZh":"settings.languageEn")},r))})}),f("theme")&&e.jsxs(L,{icon:ee,iconColor:"text-accent-purple",title:n("settings.theme"),children:[e.jsx("div",{className:"flex gap-2 mb-4",children:["dark","light","auto"].map(r=>e.jsx("button",{onClick:()=>l(r),className:`px-4 py-2 rounded-lg transition-all ${p===r?"bg-accent-blue text-white":"bg-dark-hover text-dark-text hover:bg-dark-border"}`,children:n(r==="dark"?"settings.themeDark":r==="light"?"settings.themeLight":"settings.themeAuto")},r))}),e.jsxs("div",{className:"mb-4",children:[e.jsx("h4",{className:"text-xs font-semibold text-dark-text mb-2",children:n("settings.themePresets")}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2",children:c.map(r=>{if(!r)return null;const I=(j||Te)===r.id,B=a==="dark"?r.dark:r.light;return e.jsx(Re,{id:r.id,nameKey:r.nameKey,descriptionKey:r.descriptionKey,colors:B,isSelected:I,onClick:()=>k(r.id)},r.id)})})]}),e.jsxs("div",{className:"pt-4 border-t border-dark-border",children:[e.jsxs("button",{onClick:()=>{const r=!O;R(r),w(r)},className:"flex items-center gap-2 text-sm text-dark-muted hover:text-dark-text transition-colors",children:[e.jsx(ee,{size:14}),e.jsx("span",{children:n("settings.customOverrides")}),e.jsx("span",{className:`w-8 h-4 rounded-full transition-colors ${O?"bg-accent-blue":"bg-dark-border"}`,children:e.jsx("span",{className:`block w-3 h-3 rounded-full bg-white transition-transform mt-0.5 ${O?"ml-4":"ml-0.5"}`})})]}),O&&e.jsx("p",{className:"text-[10px] text-dark-muted mt-1 mb-2",children:n("settings.customOverridesHint")}),O&&e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"flex gap-1 mb-3 rounded-lg overflow-hidden h-6",children:re.map(({key:r})=>e.jsx("div",{className:"flex-1",style:{backgroundColor:y[r]},title:r},r))}),e.jsx("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2",children:re.map(({key:r,labelKey:I})=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:y[r],onChange:B=>E({[r]:B.target.value}),className:"w-8 h-8 rounded border border-dark-border cursor-pointer bg-transparent p-0.5 shrink-0"}),e.jsx("span",{className:"text-xs text-dark-muted flex-1 truncate",children:n(I)}),e.jsx("input",{type:"text",value:y[r],onChange:B=>{const A=B.target.value;/^#[0-9a-fA-F]{0,6}$/.test(A)&&E({[r]:A})},className:"w-16 bg-dark-bg border border-dark-border rounded px-1 py-0.5 text-xs text-dark-text font-mono text-center",maxLength:7})]},r))}),e.jsx("button",{onClick:D,className:"mt-2 text-xs text-dark-muted hover:text-accent-red transition-colors",children:n("settings.resetColors")})]})]})]}),f("display")&&e.jsx(L,{icon:te,iconColor:"text-accent-blue",title:n("settings.display"),children:e.jsxs("label",{className:"flex items-center justify-between gap-3 py-1 cursor-pointer",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm text-dark-text",children:n("settings.developerView")}),e.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:n("settings.developerViewHint")})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":b,onClick:()=>$(!b),className:`relative w-9 h-5 rounded-full transition-colors shrink-0 ${b?"bg-accent-blue":"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 ${b?"translate-x-[18px]":"translate-x-0.5"}`})})]})}),f("provider")&&e.jsxs(L,{icon:q,iconColor:"text-accent-yellow",title:"Provider & Models",children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:"Configure AI providers, API keys, and model settings. Add or remove providers like OpenAI, Anthropic, DeepSeek, and more."}),e.jsxs("button",{onClick:()=>x==null?void 0:x("models"),className:"flex items-center gap-2 px-4 py-2 bg-accent-blue text-white rounded-lg hover:opacity-90 transition-opacity text-sm w-fit",children:[e.jsx(X,{size:14}),"Manage Providers & Models"]})]}),f("capabilities")&&e.jsx(L,{icon:le,iconColor:"text-accent-green",title:n("settings.capabilities.title"),children:e.jsx(De,{onNavigate:x})}),f("context")&&e.jsx(L,{icon:je,iconColor:"text-accent-blue",title:"Max Context",children:e.jsx(Ke,{})}),f("context")&&e.jsx(L,{icon:te,iconColor:"text-accent-purple",title:n("settings.contextOffload.title"),children:e.jsx(Le,{})}),f("stt")&&e.jsx(L,{icon:ke,iconColor:"text-accent-blue",title:n("stt.setup.title"),children:e.jsx("div",{ref:P,id:"settings-section-stt",className:"scroll-mt-4",children:e.jsx(Oe,{})})}),f("configFiles")&&e.jsx(L,{icon:ve,iconColor:"text-accent-green",title:"Config Files (~/.agent/)",children:e.jsx($e,{})}),f("system")&&e.jsx(L,{icon:ye,iconColor:"text-dark-muted",title:"System",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-dark-muted",children:"Server Uptime"}),e.jsx("span",{className:"text-dark-text font-mono",children:Y(m)})]}),e.jsxs("button",{onClick:_,disabled:C,className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm transition-all ${C?"bg-dark-hover text-dark-muted cursor-wait":"bg-accent-red/10 text-accent-red hover:bg-accent-red/20 border border-accent-red/30"}`,children:[e.jsx(U,{size:14,className:C?"animate-spin":""}),C?"Restarting...":"Restart Server"]}),e.jsxs("button",{onClick:W,disabled:o,className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm transition-all ${o?"bg-dark-hover text-dark-muted cursor-wait":"bg-accent-red/10 text-accent-red hover:bg-accent-red/20 border border-accent-red/30"}`,children:[e.jsx(we,{size:14,className:o?"animate-pulse":""}),o?"Shutting Down...":"Shutdown Server"]})]})}),f("about")&&e.jsx(L,{icon:Ne,iconColor:"text-accent-blue",title:n("settings.about"),children:e.jsxs("div",{className:"text-sm text-dark-muted space-y-2",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-dark-text",children:"DeepSeekCode Web"})," v",Pe.version]}),e.jsx("p",{children:n("settings.aboutDesc")}),e.jsx("p",{className:"text-xs",children:"Powered by React + TypeScript + TailwindCSS"}),e.jsx("p",{className:"text-xs",children:"联系:ngwlh2026@gmail.com"})]})}),d.trim()&&!["language","theme","provider","capabilities","context","stt","configFiles","system","about"].some(f)&&e.jsxs("div",{className:"text-center py-12 text-dark-muted",children:[e.jsx(J,{size:32,className:"mx-auto mb-2 opacity-40"}),e.jsxs("p",{className:"text-sm",children:["No settings match “",d,"”"]})]})]})]})});function Ke(){const t=ae(u=>u.maxContextTokens),x=ae(u=>u.setMaxContextTokens),[i,n]=s.useState(String(t)),[p,l]=s.useState(!1),j=[32e3,64e3,128e3,256e3,512e3,1e6,2e6],k=async()=>{const u=parseInt(i,10);if(!(isNaN(u)||u<1e3)){l(!0),x(u);try{await S.config.provider.save({contextWindow:u}),g.success("Context window saved")}catch(y){g.error("Failed to save context window: "+(y instanceof Error?y.message:"Unknown error"))}l(!1)}},v=u=>u>=1e6?(u/1e6).toFixed(0)+"M":(u/1e3).toFixed(0)+"K";return e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:"Set the maximum context window (in tokens) for your AI model. This controls how the progress bar and usage percentage are calculated."}),e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("input",{type:"number",value:i,onChange:u=>n(u.target.value),min:1e3,max:1e7,step:1e3,className:"w-32 bg-dark-bg border border-dark-border rounded-lg px-3 py-1.5 text-sm text-dark-text font-mono focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all"}),e.jsx("span",{className:"text-sm text-dark-muted",children:"tokens"}),e.jsx("button",{onClick:k,disabled:p,className:"px-3 py-1.5 rounded-lg text-sm bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:p?"Saving...":"Apply"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:j.map(u=>e.jsx("button",{onClick:async()=>{n(String(u)),x(u);try{await S.config.provider.save({contextWindow:u}),g.success("Context window saved")}catch(y){g.error("Failed to save context window: "+(y instanceof Error?y.message:"Unknown error"))}},className:"px-3 py-1 rounded-lg text-xs transition-all",children:v(u)},u))}),e.jsxs("p",{className:"text-xs text-dark-muted mt-2",children:["Current: ",e.jsx("span",{className:"font-mono text-dark-text",children:parseInt(i,10).toLocaleString()})," tokens"]})]})}function L({icon:t,iconColor:x,title:i,children:n}){return e.jsxs("div",{className:"rounded-xl border border-dark-border bg-dark-surface p-4",children:[e.jsxs("h3",{className:"font-medium mb-3 flex items-center gap-2",children:[e.jsx(t,{size:16,className:x}),i]}),n]})}export{Xe as SettingsPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./markdown-yjmXQjrx.js";import{a as n,z as G,h as N,aA as K,$ as ie,X as Q,aB as Le,aC as Me,aD as Ee,D as ss,y as ts,K as as,ay as Te,az as Fe,a1 as Pe,a8 as le,aq as rs,aE as ls,aF as ns}from"./icons-qcawb7PZ.js";import{u as qe,a as m,M as Ie,C as is}from"./index-DUpwXfa-.js";import"./react-vendor-CSlQceOk.js";import"./state-DOzZasIm.js";import"./panels-CX_dYEv0.js";function cs(){const{t:c}=qe(),[t,u]=n.useState([]),[b,h]=n.useState(!0),[A,v]=n.useState(null),[L,y]=n.useState(null),[q,w]=n.useState(!1),[p,C]=n.useState({skillName:"",description:"",trigger:"",content:""}),[k,F]=n.useState(!1),[P,S]=n.useState(null),f=n.useCallback(async()=>{h(!0);try{const r=await m.skills.workshop.list();u(r.data??[]),v(null)}catch(r){v(r instanceof Error?r.message:String(r))}finally{h(!1)}},[]);n.useEffect(()=>{f()},[f]);const $=async r=>{y(r);try{await m.skills.workshop.apply(r),await f()}catch(x){v(x instanceof Error?x.message:String(x))}finally{y(null)}},z=async r=>{y(r);try{await m.skills.workshop.reject(r),await f()}catch(x){v(x instanceof Error?x.message:String(x))}finally{y(null)}},d=async()=>{if(!p.skillName.trim()||!p.content.trim()){S(c("skills.workshopFormRequired")||"skillName and content are required");return}F(!0),S(null);try{await m.skills.workshop.propose({skillName:p.skillName.trim(),description:p.description.trim(),trigger:p.trigger.trim(),content:p.content.trim(),reason:"manual proposal"}),C({skillName:"",description:"",trigger:"",content:""}),w(!1),await f()}catch(r){S(r instanceof Error?r.message:String(r))}finally{F(!1)}};return e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar pr-1 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-xs text-dark-muted",children:c("skills.workshopHint")||"技能提案:从会话/手动生成,审核后一键应用为技能"}),e.jsxs("button",{onClick:()=>{w(r=>!r),S(null)},className:"px-3 py-1.5 bg-accent-blue text-white rounded-lg text-sm flex items-center gap-1.5 whitespace-nowrap shrink-0",children:[e.jsx(G,{size:14}),c("skills.workshopPropose")||"新建提案"]})]}),q&&e.jsxs("div",{className:"rounded-xl border border-dark-border bg-dark-surface p-3 space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("input",{value:p.skillName,onChange:r=>C(x=>({...x,skillName:r.target.value})),placeholder:c("skills.workshopName")||"技能名 (skill-name) 如 format-json",className:"px-3 py-2 rounded-lg bg-dark-bg border border-dark-border outline-none focus:border-accent-blue text-sm"}),e.jsx("input",{value:p.trigger,onChange:r=>C(x=>({...x,trigger:r.target.value})),placeholder:c("skills.workshopTrigger")||"触发关键词(可选)",className:"px-3 py-2 rounded-lg bg-dark-bg border border-dark-border outline-none focus:border-accent-blue text-sm"})]}),e.jsx("input",{value:p.description,onChange:r=>C(x=>({...x,description:r.target.value})),placeholder:c("skills.workshopDescription")||"一句话描述",className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border outline-none focus:border-accent-blue text-sm"}),e.jsx("textarea",{value:p.content,onChange:r=>C(x=>({...x,content:r.target.value})),placeholder:c("skills.workshopContent")||"技能正文(系统提示 / 工作流指令)",rows:5,className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border outline-none focus:border-accent-blue text-sm resize-y"}),P&&e.jsx("div",{className:"text-xs text-accent-red",children:P}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:()=>w(!1),className:"px-3 py-1.5 rounded-lg text-sm border border-dark-border hover:bg-dark-hover",children:c("common.cancel")||"取消"}),e.jsxs("button",{onClick:d,disabled:k,className:"px-3 py-1.5 bg-accent-blue text-white rounded-lg text-sm flex items-center gap-1.5 disabled:opacity-50",children:[k?e.jsx(N,{size:14,className:"animate-spin"}):e.jsx(K,{size:14}),c("skills.workshopSubmit")||"提交提案"]})]})]}),A&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-accent-red/10 text-accent-red text-sm",children:[e.jsx(ie,{size:14,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:A}),e.jsx("button",{onClick:()=>v(null),className:"shrink-0 p-0.5 rounded hover:bg-dark-hover",children:e.jsx(Q,{size:14})})]}),b?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(N,{size:24,className:"animate-spin text-accent-blue"})}):t.length===0?e.jsx("div",{className:"text-sm text-dark-muted py-10 text-center",children:c("skills.workshopEmpty")||"暂无技能提案"}):t.map(r=>e.jsxs("div",{className:"rounded-xl border border-dark-border bg-dark-surface p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Le,{size:14,className:"text-accent-blue shrink-0"}),e.jsx("span",{className:"font-medium text-sm truncate",children:r.skillName}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded-full shrink-0 ${r.status==="applied"?"bg-accent-green/15 text-accent-green":r.status==="rejected"?"bg-dark-hover text-dark-muted":"bg-accent-yellow/15 text-accent-yellow"}`,children:r.status})]}),e.jsx("div",{className:"flex items-center gap-1 shrink-0",children:r.status==="pending"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>$(r.id),disabled:L===r.id,className:"px-2 py-1 bg-accent-green text-white rounded text-xs flex items-center gap-1 disabled:opacity-50",children:[e.jsx(K,{size:12}),c("skills.workshopApply")||"应用"]}),e.jsx("button",{onClick:()=>z(r.id),disabled:L===r.id,className:"px-2 py-1 rounded text-xs border border-dark-border hover:bg-dark-hover disabled:opacity-50",children:e.jsx(Q,{size:12})})]})})]}),r.description&&e.jsx("div",{className:"text-xs text-dark-muted truncate",children:r.description}),r.trigger&&e.jsxs("div",{className:"text-xs text-accent-blue",children:["trigger: ",r.trigger]}),e.jsx("div",{className:"text-xs text-dark-muted line-clamp-3 whitespace-pre-wrap",children:r.content}),e.jsxs("div",{className:"text-[11px] text-dark-muted/70 flex items-center justify-between",children:[e.jsx("span",{children:r.reason}),e.jsx("span",{children:new Date(r.createdAt).toLocaleString()})]})]},r.id))]})}const ne={id:"",name:"",description:"",category:"",trigger:"",systemPrompt:"",injection:"lazy",tags:"",requiredTools:""},Z=8;function gs({onUseSkill:c}){var Se;const{t}=qe(),[u,b]=n.useState("marketplace"),[h,A]=n.useState([]),[v,L]=n.useState(!0),[y,q]=n.useState(null),[w,p]=n.useState(""),[C,k]=n.useState(!1),[F,P]=n.useState(null),[S,f]=n.useState(!1),[$,z]=n.useState(null),[d,r]=n.useState(ne),[x,V]=n.useState(!1),[Re,ce]=n.useState(!1),[de,W]=n.useState(null),D=n.useRef(null),[oe,X]=n.useState([]),[$e,Y]=n.useState([]),[xe,H]=n.useState({}),[De,J]=n.useState(!1),[me,g]=n.useState(null),[He,ue]=n.useState(null),[Oe,Be]=n.useState({}),[pe,Ue]=n.useState({}),[ge,_e]=n.useState({}),[ee,be]=n.useState(""),[he,ke]=n.useState(""),[fe,je]=n.useState(!1),[R,se]=n.useState(null),O=n.useMemo(()=>h.filter(s=>s.source==="marketplace"||s.provenance==="marketplace"),[h]),te=n.useMemo(()=>h.filter(s=>s.source!=="marketplace"&&s.provenance!=="marketplace"),[h]),Ze=s=>{var l;const a=((l=xe[s])==null?void 0:l.skills)||[];return Math.max(1,Math.ceil(a.length/Z))},Ne=(s,a)=>{Be(l=>({...l,[s]:Math.max(0,Math.min(Ze(s)-1,a))}))},Ge=async()=>{var a,l,o;J(!0),g(null);const s=await m.skills.marketplaces.list();if(!s.success){g(s.error||t("skills.loadMarketplaceFail")),J(!1);return}X(((a=s.data)==null?void 0:a.marketplaces)||[]),Y(((l=s.data)==null?void 0:l.installed)||[]),H(((o=s.data)==null?void 0:o.indexes)||{}),J(!1)},Ke=async()=>{const s=ee.trim();if(!s)return;je(!0),g(null);const a=await m.skills.marketplaces.add({url:s,name:he.trim()||void 0});if(a.success&&a.data){be(""),ke("");const l=a.data.marketplace;X(o=>[...o.filter(E=>E.id!==l.id),l]),H(o=>({...o,[l.id]:a.data.index}))}else g(a.error||t("skills.addFail"));je(!1)},ve=async s=>{g(null);const a=await m.skills.marketplaces.refresh(s);a.success&&a.data?H(l=>({...l,[s]:a.data.index})):g(a.error||t("skills.loadMarketplaceFail"))},Qe=async s=>{await m.skills.marketplaces.remove(s),X(a=>a.filter(l=>l.id!==s)),H(a=>{const l={...a};return delete l[s],l})},Ve=async(s,a)=>{ue(a),g(null);const l=await m.skills.marketplaces.install(s,a);l.success&&l.data?(Y(o=>[...o.filter(E=>E!==l.data.id),l.data.id]),await M()):g(l.error||t("skills.installFail")),ue(null)},We=async s=>{g(null);const a=await m.skills.delete(s);a.success?(Y(l=>l.filter(o=>o!==s)),await M()):g(a.error||t("skills.uninstallFail")),se(null)},M=async()=>{L(!0),q(null);const s=await m.skills.list();if(s.success){const a=Array.isArray(s.data)?s.data:[];A(a),s.data!==null&&s.data!==void 0&&!Array.isArray(s.data)&&q("服务端返回的技能数据格式异常")}else q(s.error||t("skills.loadFailedFallback"));L(!1)};n.useEffect(()=>{M(),Ge()},[]);const ae=n.useMemo(()=>{const s=w.trim().toLowerCase();return s?te.filter(a=>[a.id,a.name,a.description,a.category,...a.tags||[]].join(" ").toLowerCase().includes(s)):te},[te,w]),ye=()=>{P(null),r(ne),z(null),k(!0)},we=s=>{P(s.id),r({id:s.id,name:s.name,description:s.description,category:s.category,trigger:s.trigger||"",systemPrompt:s.systemPrompt||"",injection:s.injection||"lazy",tags:(s.tags||[]).join(", "),requiredTools:(s.requiredTools||[]).join(", ")}),z(null),k(!0)},Xe=async()=>{const s=d.id.trim();if(!s){z(t("skills.fieldId")+" is required");return}f(!0),z(null);const a={id:s,name:d.name.trim(),description:d.description.trim(),category:d.category.trim(),trigger:d.trigger.trim(),systemPrompt:d.systemPrompt,injection:d.injection.trim(),tags:Ae(d.tags),requiredTools:Ae(d.requiredTools)},l=F?await m.skills.update(F,a):await m.skills.create(a);l.success?(k(!1),P(null),r(ne),await M()):z(l.error||t("skills.save")),f(!1)},Ce=async s=>{(await m.skills.toggle(s.id,!s.enabled)).success&&A(l=>l.map(o=>o.id===s.id?{...o,enabled:!o.enabled}:o))},Ye=async s=>{ce(!0),W(null);try{const a=await s.text(),l=await m.skills.import({fileName:s.name,content:a});l.success?(V(!1),await M()):W(l.error||t("skills.import"))}catch(a){W(a instanceof Error?a.message:t("skills.import"))}finally{ce(!1),D.current&&(D.current.value="")}};if(v)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(N,{size:32,className:"animate-spin mx-auto mb-2 text-accent-blue"}),e.jsx("p",{className:"text-dark-muted",children:"Loading..."})]})});if(y)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ie,{size:32,className:"mx-auto mb-2 text-accent-red"}),e.jsx("p",{className:"text-accent-red mb-4",children:y}),e.jsx("button",{onClick:M,className:"px-4 py-2 bg-accent-blue text-white rounded-lg",children:t("skills.retry")})]})});const B=s=>`flex items-center gap-2 px-4 py-1.5 rounded-lg text-sm font-medium transition-colors ${s?"bg-accent-blue/20 text-accent-blue":"text-dark-muted hover:bg-dark-hover"}`;return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4 gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2 shrink-0",children:[e.jsx(Me,{size:20}),t("skills.title"),e.jsxs("span",{className:"text-sm font-normal text-dark-muted",children:["(",h.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-1 bg-dark-surface border border-dark-border rounded-xl p-1",children:[e.jsxs("button",{onClick:()=>b("marketplace"),className:B(u==="marketplace"),children:[e.jsx(Ee,{size:14}),t("skills.marketplaceTab")]}),e.jsxs("button",{onClick:()=>b("mine"),className:B(u==="mine"),children:[e.jsx(Me,{size:14}),t("skills.mineTab")]}),e.jsxs("button",{onClick:()=>b("installed"),className:B(u==="installed"),children:[e.jsx(K,{size:14}),t("skills.installedTab"),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-dark-bg border border-dark-border",children:O.length})]}),e.jsxs("button",{onClick:()=>b("workshop"),className:B(u==="workshop"),children:[e.jsx(Le,{size:14}),t("skills.workshopTab")]})]})]}),me&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-accent-red/10 text-accent-red text-sm",children:[e.jsx(ie,{size:14,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:me}),e.jsx("button",{onClick:()=>g(null),className:"shrink-0 p-0.5 rounded hover:bg-dark-hover",children:e.jsx(Q,{size:14})})]}),u==="marketplace"&&e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar pr-1 space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:ee,onChange:s=>be(s.target.value),placeholder:t("skills.marketplaceUrlPlaceholder"),className:"flex-1 px-3 py-2 rounded-lg bg-dark-surface border border-dark-border outline-none focus:border-accent-blue text-sm"}),e.jsx("input",{value:he,onChange:s=>ke(s.target.value),placeholder:t("skills.marketplaceName"),className:"w-40 px-3 py-2 rounded-lg bg-dark-surface border border-dark-border outline-none focus:border-accent-blue text-sm"}),e.jsxs("button",{onClick:Ke,disabled:fe||!ee.trim(),className:"px-4 py-2 bg-accent-blue text-white rounded-lg text-sm flex items-center gap-2 whitespace-nowrap disabled:opacity-50",children:[e.jsx(G,{size:14}),t(fe?"skills.adding":"skills.addMarketplace")]})]}),e.jsx("div",{className:"text-xs text-dark-muted",children:t("skills.marketplaceHint")}),De?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(N,{size:24,className:"animate-spin text-accent-blue"})}):e.jsxs(e.Fragment,{children:[oe.length===0&&e.jsx("div",{className:"text-sm text-dark-muted py-10 text-center",children:t("skills.noMarketplaces")}),oe.map(s=>{const a=xe[s.id],l=(a==null?void 0:a.skills)||[],o=(pe[s.id]||"").trim().toLowerCase(),E=ge[s.id]||"",ze=Array.from(new Set(l.map(i=>i.category).filter(Boolean))).sort(),U=l.filter(i=>(!o||[i.name,i.id,i.description,...i.tags||[]].join(" ").toLowerCase().includes(o))&&(!E||i.category===E)),_=Math.max(1,Math.ceil(U.length/Z)),T=Math.min(Oe[s.id]||0,_-1),Je=U.slice(T*Z,(T+1)*Z),es=o||E?`${U.length}/${l.length}`:String(l.length);return e.jsxs("div",{className:"border border-dark-border rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-2 border-b border-dark-border bg-dark-surface flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-medium flex items-center gap-2",children:[s.builtin&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/20 text-accent-blue",children:t("skills.presets")}),e.jsx("span",{className:"truncate",children:s.name})]}),e.jsx("div",{className:"text-xs text-dark-muted truncate",children:s.url})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("span",{className:"text-xs text-dark-muted whitespace-nowrap",children:t("skills.skillCount",{count:es})}),e.jsx("button",{onClick:()=>ve(s.id),className:"p-1.5 rounded hover:bg-dark-hover",title:t("skills.refreshMarketplace"),children:e.jsx(N,{size:14})}),!s.builtin&&e.jsx("button",{onClick:()=>Qe(s.id),className:"p-1.5 rounded hover:bg-dark-hover text-accent-red",title:t("skills.removeMarketplace"),children:e.jsx(Q,{size:14})})]})]}),a!=null&&a.error?e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2 bg-accent-red/10 text-accent-red text-xs",children:[e.jsx("span",{className:"min-w-0 truncate",title:a.error,children:t("skills.marketplaceError",{error:a.error})}),e.jsxs("button",{onClick:()=>ve(s.id),className:"flex items-center gap-1 px-2 py-1 rounded bg-dark-surface border border-dark-border whitespace-nowrap shrink-0",children:[e.jsx(N,{size:12}),t("skills.retryMarket")]})]}):l.length===0?e.jsx("div",{className:"text-xs text-dark-muted py-4 text-center",children:t("skills.noSkillsInMarket")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-dark-border/60 bg-dark-surface/40",children:[e.jsx("input",{value:pe[s.id]||"",onChange:i=>Ue(j=>({...j,[s.id]:i.target.value})),placeholder:t("skills.marketFilterPlaceholder"),className:"flex-1 px-2.5 py-1.5 rounded-lg bg-dark-bg border border-dark-border outline-none focus:border-accent-blue text-xs"}),ze.length>1&&e.jsxs("select",{value:ge[s.id]||"",onChange:i=>_e(j=>({...j,[s.id]:i.target.value})),className:"px-2.5 py-1.5 rounded-lg bg-dark-bg border border-dark-border outline-none text-xs",children:[e.jsx("option",{value:"",children:t("skills.marketCategoryAll")}),ze.map(i=>e.jsx("option",{value:i,children:i},i))]})]}),U.length===0?e.jsx("div",{className:"text-xs text-dark-muted py-4 text-center",children:t("skills.noSkillsInMarket")}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2 p-3",children:Je.map(i=>{const j=$e.includes(i.id),re=He===i.id;return e.jsxs("div",{className:"border border-dark-border rounded-lg p-3 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsxs("span",{className:"font-medium text-sm truncate",children:[i.icon," ",i.name]}),i.risk==="critical"&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-red/20 text-accent-red shrink-0",children:t("skills.riskCritical")})]}),e.jsxs("div",{className:"text-xs text-dark-muted truncate",children:[i.category,i.author?` · ${i.author}`:"",i.version?` · v${i.version}`:""]})]}),e.jsxs("button",{disabled:j||re,onClick:()=>Ve(s.id,i.id),className:`flex items-center gap-1 px-2.5 py-1.5 rounded-lg text-xs font-medium whitespace-nowrap shrink-0 disabled:opacity-60 ${j?"bg-accent-green/20 text-accent-green":"bg-accent-blue text-white hover:bg-accent-blue/80"}`,children:[j?e.jsx(K,{size:12}):re?e.jsx(N,{size:12,className:"animate-spin"}):e.jsx(ss,{size:12}),t(j?"skills.installed":re?"skills.installing":"skills.installSkill")]})]}),i.description&&e.jsx("p",{className:"text-xs text-dark-muted line-clamp-2",children:i.description})]},i.id)})}),_>1&&e.jsxs("div",{className:"flex items-center justify-center gap-3 pb-3 text-xs text-dark-muted",children:[e.jsxs("button",{disabled:T<=0,onClick:()=>Ne(s.id,T-1),className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border hover:bg-dark-hover disabled:opacity-40",children:[e.jsx(ts,{size:14}),t("skills.pagePrev")]}),e.jsx("span",{className:"whitespace-nowrap",children:t("skills.pageOf",{page:T+1,total:_})}),e.jsxs("button",{disabled:T>=_-1,onClick:()=>Ne(s.id,T+1),className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border hover:bg-dark-hover disabled:opacity-40",children:[t("skills.pageNext"),e.jsx(as,{size:14})]})]})]})]})]},s.id)})]})]}),u==="installed"&&e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar pr-1",children:O.length===0?e.jsxs("div",{className:"text-center py-16 text-dark-muted",children:[e.jsx("p",{className:"mb-1",children:t("skills.emptyInstalled")}),e.jsx("p",{className:"text-xs mb-4",children:t("skills.emptyInstalledHint")}),e.jsxs("button",{onClick:()=>b("marketplace"),className:"inline-flex items-center gap-2 px-4 py-2 bg-accent-blue text-white rounded-lg text-sm",children:[e.jsx(Ee,{size:14}),t("skills.browseMarket")]})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2",children:O.map(s=>e.jsxs("div",{className:"border border-dark-border rounded-lg p-3 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-medium text-sm truncate",children:[s.icon||"⭐"," ",s.name]}),e.jsxs("div",{className:"text-xs text-dark-muted truncate",children:[s.id," · ",s.category]})]}),e.jsxs("button",{onClick:()=>Ce(s),className:`flex items-center gap-1 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shrink-0 transition-colors ${s.enabled?"bg-accent-green/20 text-accent-green hover:bg-accent-green/30":"bg-accent-red/20 text-accent-red hover:bg-accent-red/30"}`,title:s.enabled?t("skills.disable"):t("skills.enable"),children:[s.enabled?e.jsx(Te,{size:14}):e.jsx(Fe,{size:14}),s.enabled?t("skills.enabled"):t("skills.disabled")]})]}),s.description&&e.jsx("p",{className:"text-xs text-dark-muted line-clamp-2",children:s.description}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mt-1",children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-dark-bg border border-dark-border text-dark-muted truncate",children:s.marketplace||s.source||t("skills.marketplace")}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[c&&e.jsxs("button",{onClick:()=>c(s),className:"flex items-center gap-1 px-2 py-1 rounded bg-accent-blue/15 text-accent-blue text-xs hover:bg-accent-blue/25 transition-colors",title:t("skills.useHint"),children:[e.jsx(Pe,{size:12}),t("skills.use")]}),e.jsxs("button",{onClick:()=>we(s),className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border text-xs hover:bg-dark-hover",children:[e.jsx(le,{size:12}),t("skills.edit")]}),e.jsxs("button",{onClick:()=>se(s.id),className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border text-accent-red text-xs hover:bg-accent-red/10",children:[e.jsx(rs,{size:12}),t("skills.uninstall")]})]})]})]},s.id))})}),u==="workshop"&&e.jsx(cs,{}),u==="mine"&&e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("input",{value:w,onChange:s=>p(s.target.value),placeholder:"Search skills",className:"w-56 px-3 py-2 bg-dark-surface border border-dark-border rounded-lg text-sm outline-none focus:border-accent-blue"}),e.jsx("span",{className:"text-sm text-dark-muted shrink-0",children:ae.length})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:ye,className:"flex items-center gap-2 px-3 py-2 bg-accent-blue text-white rounded-lg",children:[e.jsx(G,{size:14}),t("skills.new")]}),e.jsxs("button",{onClick:()=>V(!0),className:"flex items-center gap-2 px-3 py-2 bg-dark-surface border border-dark-border rounded-lg",children:[e.jsx(ls,{size:14}),t("skills.import")]}),e.jsxs("button",{onClick:M,className:"flex items-center gap-2 px-3 py-2 bg-dark-surface border border-dark-border rounded-lg",children:[e.jsx(N,{size:14}),t("skills.refresh")]})]})]}),ae.length===0?e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-dark-muted gap-3",children:[e.jsx("p",{children:t("skills.noSkills")}),e.jsxs("button",{onClick:ye,className:"px-4 py-2 bg-accent-blue text-white rounded-lg text-sm inline-flex items-center gap-2",children:[e.jsx(G,{size:14}),t("skills.new")]})]}):e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar pr-1",children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 gap-3",children:ae.map(s=>e.jsxs("div",{className:"border border-dark-border rounded-lg p-3 flex flex-col gap-2 bg-dark-surface",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-medium text-sm truncate",children:[s.icon||"⭐"," ",s.name]}),e.jsx("div",{className:"text-xs text-dark-muted truncate",children:s.id})]}),e.jsxs("button",{onClick:()=>Ce(s),className:`flex items-center gap-1 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shrink-0 transition-colors ${s.enabled?"bg-accent-green/20 text-accent-green hover:bg-accent-green/30":"bg-accent-red/20 text-accent-red hover:bg-accent-red/30"}`,title:s.enabled?t("skills.disable"):t("skills.enable"),children:[s.enabled?e.jsx(Te,{size:14}):e.jsx(Fe,{size:14}),s.enabled?t("skills.enabled"):t("skills.disabled")]})]}),s.description&&e.jsx("p",{className:"text-xs text-dark-muted line-clamp-2",children:s.description}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mt-auto",children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-dark-bg border border-dark-border text-dark-muted truncate",children:s.category}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[c&&e.jsxs("button",{onClick:()=>c(s),className:"flex items-center gap-1 px-2 py-1 rounded bg-accent-blue/15 text-accent-blue text-xs hover:bg-accent-blue/25 transition-colors",title:t("skills.useHint"),children:[e.jsx(Pe,{size:12}),t("skills.use")]}),e.jsxs("button",{onClick:()=>we(s),className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border text-xs hover:bg-dark-hover shrink-0",children:[e.jsx(le,{size:12}),t("skills.edit")]})]})]})]},s.id))})})]}),e.jsx(Ie,{isOpen:C,onClose:()=>k(!1),title:t(F?"skills.edit":"skills.new"),size:"xl",children:e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(I,{label:t("skills.fieldId"),value:d.id,onChange:s=>r(a=>({...a,id:s}))}),e.jsx(I,{label:t("skills.fieldName"),value:d.name,onChange:s=>r(a=>({...a,name:s}))}),e.jsx(I,{label:t("skills.fieldCategory"),value:d.category,onChange:s=>r(a=>({...a,category:s}))}),e.jsx(I,{label:t("skills.fieldTrigger"),value:d.trigger,onChange:s=>r(a=>({...a,trigger:s}))}),e.jsx(I,{label:t("skills.tags"),value:d.tags,onChange:s=>r(a=>({...a,tags:s}))}),e.jsx(I,{label:t("skills.fieldTools"),value:d.requiredTools,onChange:s=>r(a=>({...a,requiredTools:s}))}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-sm mb-1 text-dark-muted",children:t("skills.description")}),e.jsx("textarea",{value:d.description,onChange:s=>r(a=>({...a,description:s.target.value})),className:"w-full h-20 px-3 py-2 rounded-lg bg-dark-bg border border-dark-border outline-none resize-none"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-sm mb-1 text-dark-muted",children:t("skills.systemPrompt")}),e.jsx("textarea",{value:d.systemPrompt,onChange:s=>r(a=>({...a,systemPrompt:s.target.value})),className:"w-full h-40 px-3 py-2 rounded-lg bg-dark-bg border border-dark-border outline-none resize-none font-mono text-sm"})]}),$&&e.jsx("div",{className:"col-span-2 text-sm text-accent-red",children:$}),e.jsxs("div",{className:"col-span-2 flex justify-end gap-2",children:[e.jsx("button",{onClick:()=>k(!1),className:"px-4 py-2 border border-dark-border rounded-lg",children:t("skills.cancel")}),e.jsxs("button",{disabled:S,onClick:Xe,className:"px-4 py-2 bg-accent-blue text-white rounded-lg flex items-center gap-2",children:[e.jsx(le,{size:14}),t(S?"skills.saving":"skills.save")]})]})]})}),e.jsx(Ie,{isOpen:x,onClose:()=>V(!1),title:t("skills.importTitle"),size:"md",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{ref:D,type:"file",accept:".md,.skill.md,.txt",className:"hidden",onChange:s=>{var l;const a=(l=s.target.files)==null?void 0:l[0];a&&Ye(a)}}),e.jsxs("button",{onClick:()=>{var s;return(s=D.current)==null?void 0:s.click()},disabled:Re,className:"w-full py-6 border border-dashed border-dark-border rounded-lg flex items-center justify-center gap-2",children:[e.jsx(ns,{size:16}),t("skills.chooseFile")]}),de&&e.jsx("div",{className:"text-sm text-accent-red",children:de}),e.jsx("div",{className:"text-xs text-dark-muted",children:t("skills.importHint")})]})}),e.jsx(is,{isOpen:R!==null,onClose:()=>se(null),onConfirm:()=>{R&&We(R)},title:t("skills.uninstall"),message:t("skills.uninstallConfirm",{name:((Se=O.find(s=>s.id===R))==null?void 0:Se.name)||R||""}),confirmText:t("skills.uninstall"),cancelText:t("skills.cancel"),variant:"danger"})]})}function Ae(c){return c.split(",").map(t=>t.trim()).filter(Boolean)}function I({label:c,value:t,onChange:u}){return e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm mb-1 text-dark-muted",children:c}),e.jsx("input",{value:t,onChange:b=>u(b.target.value),className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border outline-none focus:border-accent-blue"})]})}export{gs as SkillsView};
|
|
1
|
+
import{j as e}from"./markdown-tZ6sw2sR.js";import{a as n,z as G,h as N,aA as K,$ as ie,X as Q,aB as Le,aC as Me,aD as Ee,D as ss,y as ts,K as as,ay as Te,az as Fe,a1 as Pe,a8 as le,aq as rs,aE as ls,aF as ns}from"./icons-DLsYqrD5.js";import{u as qe,a as m,M as Ie,C as is}from"./index-DEninW1j.js";import"./react-vendor-BRkWBfPR.js";import"./state-B80cA8v4.js";import"./panels-wDJMsvra.js";function cs(){const{t:c}=qe(),[t,u]=n.useState([]),[b,h]=n.useState(!0),[A,v]=n.useState(null),[L,y]=n.useState(null),[q,w]=n.useState(!1),[p,C]=n.useState({skillName:"",description:"",trigger:"",content:""}),[k,F]=n.useState(!1),[P,S]=n.useState(null),f=n.useCallback(async()=>{h(!0);try{const r=await m.skills.workshop.list();u(r.data??[]),v(null)}catch(r){v(r instanceof Error?r.message:String(r))}finally{h(!1)}},[]);n.useEffect(()=>{f()},[f]);const $=async r=>{y(r);try{await m.skills.workshop.apply(r),await f()}catch(x){v(x instanceof Error?x.message:String(x))}finally{y(null)}},z=async r=>{y(r);try{await m.skills.workshop.reject(r),await f()}catch(x){v(x instanceof Error?x.message:String(x))}finally{y(null)}},d=async()=>{if(!p.skillName.trim()||!p.content.trim()){S(c("skills.workshopFormRequired")||"skillName and content are required");return}F(!0),S(null);try{await m.skills.workshop.propose({skillName:p.skillName.trim(),description:p.description.trim(),trigger:p.trigger.trim(),content:p.content.trim(),reason:"manual proposal"}),C({skillName:"",description:"",trigger:"",content:""}),w(!1),await f()}catch(r){S(r instanceof Error?r.message:String(r))}finally{F(!1)}};return e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar pr-1 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-xs text-dark-muted",children:c("skills.workshopHint")||"技能提案:从会话/手动生成,审核后一键应用为技能"}),e.jsxs("button",{onClick:()=>{w(r=>!r),S(null)},className:"px-3 py-1.5 bg-accent-blue text-white rounded-lg text-sm flex items-center gap-1.5 whitespace-nowrap shrink-0",children:[e.jsx(G,{size:14}),c("skills.workshopPropose")||"新建提案"]})]}),q&&e.jsxs("div",{className:"rounded-xl border border-dark-border bg-dark-surface p-3 space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("input",{value:p.skillName,onChange:r=>C(x=>({...x,skillName:r.target.value})),placeholder:c("skills.workshopName")||"技能名 (skill-name) 如 format-json",className:"px-3 py-2 rounded-lg bg-dark-bg border border-dark-border outline-none focus:border-accent-blue text-sm"}),e.jsx("input",{value:p.trigger,onChange:r=>C(x=>({...x,trigger:r.target.value})),placeholder:c("skills.workshopTrigger")||"触发关键词(可选)",className:"px-3 py-2 rounded-lg bg-dark-bg border border-dark-border outline-none focus:border-accent-blue text-sm"})]}),e.jsx("input",{value:p.description,onChange:r=>C(x=>({...x,description:r.target.value})),placeholder:c("skills.workshopDescription")||"一句话描述",className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border outline-none focus:border-accent-blue text-sm"}),e.jsx("textarea",{value:p.content,onChange:r=>C(x=>({...x,content:r.target.value})),placeholder:c("skills.workshopContent")||"技能正文(系统提示 / 工作流指令)",rows:5,className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border outline-none focus:border-accent-blue text-sm resize-y"}),P&&e.jsx("div",{className:"text-xs text-accent-red",children:P}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:()=>w(!1),className:"px-3 py-1.5 rounded-lg text-sm border border-dark-border hover:bg-dark-hover",children:c("common.cancel")||"取消"}),e.jsxs("button",{onClick:d,disabled:k,className:"px-3 py-1.5 bg-accent-blue text-white rounded-lg text-sm flex items-center gap-1.5 disabled:opacity-50",children:[k?e.jsx(N,{size:14,className:"animate-spin"}):e.jsx(K,{size:14}),c("skills.workshopSubmit")||"提交提案"]})]})]}),A&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-accent-red/10 text-accent-red text-sm",children:[e.jsx(ie,{size:14,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:A}),e.jsx("button",{onClick:()=>v(null),className:"shrink-0 p-0.5 rounded hover:bg-dark-hover",children:e.jsx(Q,{size:14})})]}),b?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(N,{size:24,className:"animate-spin text-accent-blue"})}):t.length===0?e.jsx("div",{className:"text-sm text-dark-muted py-10 text-center",children:c("skills.workshopEmpty")||"暂无技能提案"}):t.map(r=>e.jsxs("div",{className:"rounded-xl border border-dark-border bg-dark-surface p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Le,{size:14,className:"text-accent-blue shrink-0"}),e.jsx("span",{className:"font-medium text-sm truncate",children:r.skillName}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded-full shrink-0 ${r.status==="applied"?"bg-accent-green/15 text-accent-green":r.status==="rejected"?"bg-dark-hover text-dark-muted":"bg-accent-yellow/15 text-accent-yellow"}`,children:r.status})]}),e.jsx("div",{className:"flex items-center gap-1 shrink-0",children:r.status==="pending"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>$(r.id),disabled:L===r.id,className:"px-2 py-1 bg-accent-green text-white rounded text-xs flex items-center gap-1 disabled:opacity-50",children:[e.jsx(K,{size:12}),c("skills.workshopApply")||"应用"]}),e.jsx("button",{onClick:()=>z(r.id),disabled:L===r.id,className:"px-2 py-1 rounded text-xs border border-dark-border hover:bg-dark-hover disabled:opacity-50",children:e.jsx(Q,{size:12})})]})})]}),r.description&&e.jsx("div",{className:"text-xs text-dark-muted truncate",children:r.description}),r.trigger&&e.jsxs("div",{className:"text-xs text-accent-blue",children:["trigger: ",r.trigger]}),e.jsx("div",{className:"text-xs text-dark-muted line-clamp-3 whitespace-pre-wrap",children:r.content}),e.jsxs("div",{className:"text-[11px] text-dark-muted/70 flex items-center justify-between",children:[e.jsx("span",{children:r.reason}),e.jsx("span",{children:new Date(r.createdAt).toLocaleString()})]})]},r.id))]})}const ne={id:"",name:"",description:"",category:"",trigger:"",systemPrompt:"",injection:"lazy",tags:"",requiredTools:""},Z=8;function gs({onUseSkill:c}){var Se;const{t}=qe(),[u,b]=n.useState("marketplace"),[h,A]=n.useState([]),[v,L]=n.useState(!0),[y,q]=n.useState(null),[w,p]=n.useState(""),[C,k]=n.useState(!1),[F,P]=n.useState(null),[S,f]=n.useState(!1),[$,z]=n.useState(null),[d,r]=n.useState(ne),[x,V]=n.useState(!1),[Re,ce]=n.useState(!1),[de,W]=n.useState(null),D=n.useRef(null),[oe,X]=n.useState([]),[$e,Y]=n.useState([]),[xe,H]=n.useState({}),[De,J]=n.useState(!1),[me,g]=n.useState(null),[He,ue]=n.useState(null),[Oe,Be]=n.useState({}),[pe,Ue]=n.useState({}),[ge,_e]=n.useState({}),[ee,be]=n.useState(""),[he,ke]=n.useState(""),[fe,je]=n.useState(!1),[R,se]=n.useState(null),O=n.useMemo(()=>h.filter(s=>s.source==="marketplace"||s.provenance==="marketplace"),[h]),te=n.useMemo(()=>h.filter(s=>s.source!=="marketplace"&&s.provenance!=="marketplace"),[h]),Ze=s=>{var l;const a=((l=xe[s])==null?void 0:l.skills)||[];return Math.max(1,Math.ceil(a.length/Z))},Ne=(s,a)=>{Be(l=>({...l,[s]:Math.max(0,Math.min(Ze(s)-1,a))}))},Ge=async()=>{var a,l,o;J(!0),g(null);const s=await m.skills.marketplaces.list();if(!s.success){g(s.error||t("skills.loadMarketplaceFail")),J(!1);return}X(((a=s.data)==null?void 0:a.marketplaces)||[]),Y(((l=s.data)==null?void 0:l.installed)||[]),H(((o=s.data)==null?void 0:o.indexes)||{}),J(!1)},Ke=async()=>{const s=ee.trim();if(!s)return;je(!0),g(null);const a=await m.skills.marketplaces.add({url:s,name:he.trim()||void 0});if(a.success&&a.data){be(""),ke("");const l=a.data.marketplace;X(o=>[...o.filter(E=>E.id!==l.id),l]),H(o=>({...o,[l.id]:a.data.index}))}else g(a.error||t("skills.addFail"));je(!1)},ve=async s=>{g(null);const a=await m.skills.marketplaces.refresh(s);a.success&&a.data?H(l=>({...l,[s]:a.data.index})):g(a.error||t("skills.loadMarketplaceFail"))},Qe=async s=>{await m.skills.marketplaces.remove(s),X(a=>a.filter(l=>l.id!==s)),H(a=>{const l={...a};return delete l[s],l})},Ve=async(s,a)=>{ue(a),g(null);const l=await m.skills.marketplaces.install(s,a);l.success&&l.data?(Y(o=>[...o.filter(E=>E!==l.data.id),l.data.id]),await M()):g(l.error||t("skills.installFail")),ue(null)},We=async s=>{g(null);const a=await m.skills.delete(s);a.success?(Y(l=>l.filter(o=>o!==s)),await M()):g(a.error||t("skills.uninstallFail")),se(null)},M=async()=>{L(!0),q(null);const s=await m.skills.list();if(s.success){const a=Array.isArray(s.data)?s.data:[];A(a),s.data!==null&&s.data!==void 0&&!Array.isArray(s.data)&&q("服务端返回的技能数据格式异常")}else q(s.error||t("skills.loadFailedFallback"));L(!1)};n.useEffect(()=>{M(),Ge()},[]);const ae=n.useMemo(()=>{const s=w.trim().toLowerCase();return s?te.filter(a=>[a.id,a.name,a.description,a.category,...a.tags||[]].join(" ").toLowerCase().includes(s)):te},[te,w]),ye=()=>{P(null),r(ne),z(null),k(!0)},we=s=>{P(s.id),r({id:s.id,name:s.name,description:s.description,category:s.category,trigger:s.trigger||"",systemPrompt:s.systemPrompt||"",injection:s.injection||"lazy",tags:(s.tags||[]).join(", "),requiredTools:(s.requiredTools||[]).join(", ")}),z(null),k(!0)},Xe=async()=>{const s=d.id.trim();if(!s){z(t("skills.fieldId")+" is required");return}f(!0),z(null);const a={id:s,name:d.name.trim(),description:d.description.trim(),category:d.category.trim(),trigger:d.trigger.trim(),systemPrompt:d.systemPrompt,injection:d.injection.trim(),tags:Ae(d.tags),requiredTools:Ae(d.requiredTools)},l=F?await m.skills.update(F,a):await m.skills.create(a);l.success?(k(!1),P(null),r(ne),await M()):z(l.error||t("skills.save")),f(!1)},Ce=async s=>{(await m.skills.toggle(s.id,!s.enabled)).success&&A(l=>l.map(o=>o.id===s.id?{...o,enabled:!o.enabled}:o))},Ye=async s=>{ce(!0),W(null);try{const a=await s.text(),l=await m.skills.import({fileName:s.name,content:a});l.success?(V(!1),await M()):W(l.error||t("skills.import"))}catch(a){W(a instanceof Error?a.message:t("skills.import"))}finally{ce(!1),D.current&&(D.current.value="")}};if(v)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(N,{size:32,className:"animate-spin mx-auto mb-2 text-accent-blue"}),e.jsx("p",{className:"text-dark-muted",children:"Loading..."})]})});if(y)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ie,{size:32,className:"mx-auto mb-2 text-accent-red"}),e.jsx("p",{className:"text-accent-red mb-4",children:y}),e.jsx("button",{onClick:M,className:"px-4 py-2 bg-accent-blue text-white rounded-lg",children:t("skills.retry")})]})});const B=s=>`flex items-center gap-2 px-4 py-1.5 rounded-lg text-sm font-medium transition-colors ${s?"bg-accent-blue/20 text-accent-blue":"text-dark-muted hover:bg-dark-hover"}`;return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4 gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2 shrink-0",children:[e.jsx(Me,{size:20}),t("skills.title"),e.jsxs("span",{className:"text-sm font-normal text-dark-muted",children:["(",h.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-1 bg-dark-surface border border-dark-border rounded-xl p-1",children:[e.jsxs("button",{onClick:()=>b("marketplace"),className:B(u==="marketplace"),children:[e.jsx(Ee,{size:14}),t("skills.marketplaceTab")]}),e.jsxs("button",{onClick:()=>b("mine"),className:B(u==="mine"),children:[e.jsx(Me,{size:14}),t("skills.mineTab")]}),e.jsxs("button",{onClick:()=>b("installed"),className:B(u==="installed"),children:[e.jsx(K,{size:14}),t("skills.installedTab"),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-dark-bg border border-dark-border",children:O.length})]}),e.jsxs("button",{onClick:()=>b("workshop"),className:B(u==="workshop"),children:[e.jsx(Le,{size:14}),t("skills.workshopTab")]})]})]}),me&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-accent-red/10 text-accent-red text-sm",children:[e.jsx(ie,{size:14,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:me}),e.jsx("button",{onClick:()=>g(null),className:"shrink-0 p-0.5 rounded hover:bg-dark-hover",children:e.jsx(Q,{size:14})})]}),u==="marketplace"&&e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar pr-1 space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:ee,onChange:s=>be(s.target.value),placeholder:t("skills.marketplaceUrlPlaceholder"),className:"flex-1 px-3 py-2 rounded-lg bg-dark-surface border border-dark-border outline-none focus:border-accent-blue text-sm"}),e.jsx("input",{value:he,onChange:s=>ke(s.target.value),placeholder:t("skills.marketplaceName"),className:"w-40 px-3 py-2 rounded-lg bg-dark-surface border border-dark-border outline-none focus:border-accent-blue text-sm"}),e.jsxs("button",{onClick:Ke,disabled:fe||!ee.trim(),className:"px-4 py-2 bg-accent-blue text-white rounded-lg text-sm flex items-center gap-2 whitespace-nowrap disabled:opacity-50",children:[e.jsx(G,{size:14}),t(fe?"skills.adding":"skills.addMarketplace")]})]}),e.jsx("div",{className:"text-xs text-dark-muted",children:t("skills.marketplaceHint")}),De?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(N,{size:24,className:"animate-spin text-accent-blue"})}):e.jsxs(e.Fragment,{children:[oe.length===0&&e.jsx("div",{className:"text-sm text-dark-muted py-10 text-center",children:t("skills.noMarketplaces")}),oe.map(s=>{const a=xe[s.id],l=(a==null?void 0:a.skills)||[],o=(pe[s.id]||"").trim().toLowerCase(),E=ge[s.id]||"",ze=Array.from(new Set(l.map(i=>i.category).filter(Boolean))).sort(),U=l.filter(i=>(!o||[i.name,i.id,i.description,...i.tags||[]].join(" ").toLowerCase().includes(o))&&(!E||i.category===E)),_=Math.max(1,Math.ceil(U.length/Z)),T=Math.min(Oe[s.id]||0,_-1),Je=U.slice(T*Z,(T+1)*Z),es=o||E?`${U.length}/${l.length}`:String(l.length);return e.jsxs("div",{className:"border border-dark-border rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-2 border-b border-dark-border bg-dark-surface flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-medium flex items-center gap-2",children:[s.builtin&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/20 text-accent-blue",children:t("skills.presets")}),e.jsx("span",{className:"truncate",children:s.name})]}),e.jsx("div",{className:"text-xs text-dark-muted truncate",children:s.url})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("span",{className:"text-xs text-dark-muted whitespace-nowrap",children:t("skills.skillCount",{count:es})}),e.jsx("button",{onClick:()=>ve(s.id),className:"p-1.5 rounded hover:bg-dark-hover",title:t("skills.refreshMarketplace"),children:e.jsx(N,{size:14})}),!s.builtin&&e.jsx("button",{onClick:()=>Qe(s.id),className:"p-1.5 rounded hover:bg-dark-hover text-accent-red",title:t("skills.removeMarketplace"),children:e.jsx(Q,{size:14})})]})]}),a!=null&&a.error?e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2 bg-accent-red/10 text-accent-red text-xs",children:[e.jsx("span",{className:"min-w-0 truncate",title:a.error,children:t("skills.marketplaceError",{error:a.error})}),e.jsxs("button",{onClick:()=>ve(s.id),className:"flex items-center gap-1 px-2 py-1 rounded bg-dark-surface border border-dark-border whitespace-nowrap shrink-0",children:[e.jsx(N,{size:12}),t("skills.retryMarket")]})]}):l.length===0?e.jsx("div",{className:"text-xs text-dark-muted py-4 text-center",children:t("skills.noSkillsInMarket")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-dark-border/60 bg-dark-surface/40",children:[e.jsx("input",{value:pe[s.id]||"",onChange:i=>Ue(j=>({...j,[s.id]:i.target.value})),placeholder:t("skills.marketFilterPlaceholder"),className:"flex-1 px-2.5 py-1.5 rounded-lg bg-dark-bg border border-dark-border outline-none focus:border-accent-blue text-xs"}),ze.length>1&&e.jsxs("select",{value:ge[s.id]||"",onChange:i=>_e(j=>({...j,[s.id]:i.target.value})),className:"px-2.5 py-1.5 rounded-lg bg-dark-bg border border-dark-border outline-none text-xs",children:[e.jsx("option",{value:"",children:t("skills.marketCategoryAll")}),ze.map(i=>e.jsx("option",{value:i,children:i},i))]})]}),U.length===0?e.jsx("div",{className:"text-xs text-dark-muted py-4 text-center",children:t("skills.noSkillsInMarket")}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2 p-3",children:Je.map(i=>{const j=$e.includes(i.id),re=He===i.id;return e.jsxs("div",{className:"border border-dark-border rounded-lg p-3 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsxs("span",{className:"font-medium text-sm truncate",children:[i.icon," ",i.name]}),i.risk==="critical"&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-red/20 text-accent-red shrink-0",children:t("skills.riskCritical")})]}),e.jsxs("div",{className:"text-xs text-dark-muted truncate",children:[i.category,i.author?` · ${i.author}`:"",i.version?` · v${i.version}`:""]})]}),e.jsxs("button",{disabled:j||re,onClick:()=>Ve(s.id,i.id),className:`flex items-center gap-1 px-2.5 py-1.5 rounded-lg text-xs font-medium whitespace-nowrap shrink-0 disabled:opacity-60 ${j?"bg-accent-green/20 text-accent-green":"bg-accent-blue text-white hover:bg-accent-blue/80"}`,children:[j?e.jsx(K,{size:12}):re?e.jsx(N,{size:12,className:"animate-spin"}):e.jsx(ss,{size:12}),t(j?"skills.installed":re?"skills.installing":"skills.installSkill")]})]}),i.description&&e.jsx("p",{className:"text-xs text-dark-muted line-clamp-2",children:i.description})]},i.id)})}),_>1&&e.jsxs("div",{className:"flex items-center justify-center gap-3 pb-3 text-xs text-dark-muted",children:[e.jsxs("button",{disabled:T<=0,onClick:()=>Ne(s.id,T-1),className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border hover:bg-dark-hover disabled:opacity-40",children:[e.jsx(ts,{size:14}),t("skills.pagePrev")]}),e.jsx("span",{className:"whitespace-nowrap",children:t("skills.pageOf",{page:T+1,total:_})}),e.jsxs("button",{disabled:T>=_-1,onClick:()=>Ne(s.id,T+1),className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border hover:bg-dark-hover disabled:opacity-40",children:[t("skills.pageNext"),e.jsx(as,{size:14})]})]})]})]})]},s.id)})]})]}),u==="installed"&&e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar pr-1",children:O.length===0?e.jsxs("div",{className:"text-center py-16 text-dark-muted",children:[e.jsx("p",{className:"mb-1",children:t("skills.emptyInstalled")}),e.jsx("p",{className:"text-xs mb-4",children:t("skills.emptyInstalledHint")}),e.jsxs("button",{onClick:()=>b("marketplace"),className:"inline-flex items-center gap-2 px-4 py-2 bg-accent-blue text-white rounded-lg text-sm",children:[e.jsx(Ee,{size:14}),t("skills.browseMarket")]})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2",children:O.map(s=>e.jsxs("div",{className:"border border-dark-border rounded-lg p-3 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-medium text-sm truncate",children:[s.icon||"⭐"," ",s.name]}),e.jsxs("div",{className:"text-xs text-dark-muted truncate",children:[s.id," · ",s.category]})]}),e.jsxs("button",{onClick:()=>Ce(s),className:`flex items-center gap-1 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shrink-0 transition-colors ${s.enabled?"bg-accent-green/20 text-accent-green hover:bg-accent-green/30":"bg-accent-red/20 text-accent-red hover:bg-accent-red/30"}`,title:s.enabled?t("skills.disable"):t("skills.enable"),children:[s.enabled?e.jsx(Te,{size:14}):e.jsx(Fe,{size:14}),s.enabled?t("skills.enabled"):t("skills.disabled")]})]}),s.description&&e.jsx("p",{className:"text-xs text-dark-muted line-clamp-2",children:s.description}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mt-1",children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-dark-bg border border-dark-border text-dark-muted truncate",children:s.marketplace||s.source||t("skills.marketplace")}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[c&&e.jsxs("button",{onClick:()=>c(s),className:"flex items-center gap-1 px-2 py-1 rounded bg-accent-blue/15 text-accent-blue text-xs hover:bg-accent-blue/25 transition-colors",title:t("skills.useHint"),children:[e.jsx(Pe,{size:12}),t("skills.use")]}),e.jsxs("button",{onClick:()=>we(s),className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border text-xs hover:bg-dark-hover",children:[e.jsx(le,{size:12}),t("skills.edit")]}),e.jsxs("button",{onClick:()=>se(s.id),className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border text-accent-red text-xs hover:bg-accent-red/10",children:[e.jsx(rs,{size:12}),t("skills.uninstall")]})]})]})]},s.id))})}),u==="workshop"&&e.jsx(cs,{}),u==="mine"&&e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("input",{value:w,onChange:s=>p(s.target.value),placeholder:"Search skills",className:"w-56 px-3 py-2 bg-dark-surface border border-dark-border rounded-lg text-sm outline-none focus:border-accent-blue"}),e.jsx("span",{className:"text-sm text-dark-muted shrink-0",children:ae.length})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:ye,className:"flex items-center gap-2 px-3 py-2 bg-accent-blue text-white rounded-lg",children:[e.jsx(G,{size:14}),t("skills.new")]}),e.jsxs("button",{onClick:()=>V(!0),className:"flex items-center gap-2 px-3 py-2 bg-dark-surface border border-dark-border rounded-lg",children:[e.jsx(ls,{size:14}),t("skills.import")]}),e.jsxs("button",{onClick:M,className:"flex items-center gap-2 px-3 py-2 bg-dark-surface border border-dark-border rounded-lg",children:[e.jsx(N,{size:14}),t("skills.refresh")]})]})]}),ae.length===0?e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-dark-muted gap-3",children:[e.jsx("p",{children:t("skills.noSkills")}),e.jsxs("button",{onClick:ye,className:"px-4 py-2 bg-accent-blue text-white rounded-lg text-sm inline-flex items-center gap-2",children:[e.jsx(G,{size:14}),t("skills.new")]})]}):e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar pr-1",children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 gap-3",children:ae.map(s=>e.jsxs("div",{className:"border border-dark-border rounded-lg p-3 flex flex-col gap-2 bg-dark-surface",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-medium text-sm truncate",children:[s.icon||"⭐"," ",s.name]}),e.jsx("div",{className:"text-xs text-dark-muted truncate",children:s.id})]}),e.jsxs("button",{onClick:()=>Ce(s),className:`flex items-center gap-1 px-2 py-1 rounded text-xs font-medium whitespace-nowrap shrink-0 transition-colors ${s.enabled?"bg-accent-green/20 text-accent-green hover:bg-accent-green/30":"bg-accent-red/20 text-accent-red hover:bg-accent-red/30"}`,title:s.enabled?t("skills.disable"):t("skills.enable"),children:[s.enabled?e.jsx(Te,{size:14}):e.jsx(Fe,{size:14}),s.enabled?t("skills.enabled"):t("skills.disabled")]})]}),s.description&&e.jsx("p",{className:"text-xs text-dark-muted line-clamp-2",children:s.description}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mt-auto",children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-dark-bg border border-dark-border text-dark-muted truncate",children:s.category}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[c&&e.jsxs("button",{onClick:()=>c(s),className:"flex items-center gap-1 px-2 py-1 rounded bg-accent-blue/15 text-accent-blue text-xs hover:bg-accent-blue/25 transition-colors",title:t("skills.useHint"),children:[e.jsx(Pe,{size:12}),t("skills.use")]}),e.jsxs("button",{onClick:()=>we(s),className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border text-xs hover:bg-dark-hover shrink-0",children:[e.jsx(le,{size:12}),t("skills.edit")]})]})]})]},s.id))})})]}),e.jsx(Ie,{isOpen:C,onClose:()=>k(!1),title:t(F?"skills.edit":"skills.new"),size:"xl",children:e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(I,{label:t("skills.fieldId"),value:d.id,onChange:s=>r(a=>({...a,id:s}))}),e.jsx(I,{label:t("skills.fieldName"),value:d.name,onChange:s=>r(a=>({...a,name:s}))}),e.jsx(I,{label:t("skills.fieldCategory"),value:d.category,onChange:s=>r(a=>({...a,category:s}))}),e.jsx(I,{label:t("skills.fieldTrigger"),value:d.trigger,onChange:s=>r(a=>({...a,trigger:s}))}),e.jsx(I,{label:t("skills.tags"),value:d.tags,onChange:s=>r(a=>({...a,tags:s}))}),e.jsx(I,{label:t("skills.fieldTools"),value:d.requiredTools,onChange:s=>r(a=>({...a,requiredTools:s}))}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-sm mb-1 text-dark-muted",children:t("skills.description")}),e.jsx("textarea",{value:d.description,onChange:s=>r(a=>({...a,description:s.target.value})),className:"w-full h-20 px-3 py-2 rounded-lg bg-dark-bg border border-dark-border outline-none resize-none"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-sm mb-1 text-dark-muted",children:t("skills.systemPrompt")}),e.jsx("textarea",{value:d.systemPrompt,onChange:s=>r(a=>({...a,systemPrompt:s.target.value})),className:"w-full h-40 px-3 py-2 rounded-lg bg-dark-bg border border-dark-border outline-none resize-none font-mono text-sm"})]}),$&&e.jsx("div",{className:"col-span-2 text-sm text-accent-red",children:$}),e.jsxs("div",{className:"col-span-2 flex justify-end gap-2",children:[e.jsx("button",{onClick:()=>k(!1),className:"px-4 py-2 border border-dark-border rounded-lg",children:t("skills.cancel")}),e.jsxs("button",{disabled:S,onClick:Xe,className:"px-4 py-2 bg-accent-blue text-white rounded-lg flex items-center gap-2",children:[e.jsx(le,{size:14}),t(S?"skills.saving":"skills.save")]})]})]})}),e.jsx(Ie,{isOpen:x,onClose:()=>V(!1),title:t("skills.importTitle"),size:"md",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{ref:D,type:"file",accept:".md,.skill.md,.txt",className:"hidden",onChange:s=>{var l;const a=(l=s.target.files)==null?void 0:l[0];a&&Ye(a)}}),e.jsxs("button",{onClick:()=>{var s;return(s=D.current)==null?void 0:s.click()},disabled:Re,className:"w-full py-6 border border-dashed border-dark-border rounded-lg flex items-center justify-center gap-2",children:[e.jsx(ns,{size:16}),t("skills.chooseFile")]}),de&&e.jsx("div",{className:"text-sm text-accent-red",children:de}),e.jsx("div",{className:"text-xs text-dark-muted",children:t("skills.importHint")})]})}),e.jsx(is,{isOpen:R!==null,onClose:()=>se(null),onConfirm:()=>{R&&We(R)},title:t("skills.uninstall"),message:t("skills.uninstallConfirm",{name:((Se=O.find(s=>s.id===R))==null?void 0:Se.name)||R||""}),confirmText:t("skills.uninstall"),cancelText:t("skills.cancel"),variant:"danger"})]})}function Ae(c){return c.split(",").map(t=>t.trim()).filter(Boolean)}function I({label:c,value:t,onChange:u}){return e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm mb-1 text-dark-muted",children:c}),e.jsx("input",{value:t,onChange:b=>u(b.target.value),className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border outline-none focus:border-accent-blue"})]})}export{gs as SkillsView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./markdown-yjmXQjrx.js";import{a as r,z as Ze,h as Se,O as et,aG as F,ak as Ce,aH as Te,ag as Le,L as Ae,I as tt,aq as st,G as Ee,ac as at,f as rt,_ as nt,Q as lt,a8 as ot,aI as it}from"./icons-qcawb7PZ.js";import{u as Oe,a as b,d as A,B as I,M as De,I as ct,C as dt}from"./index-DUpwXfa-.js";import"./react-vendor-CSlQceOk.js";import"./state-DOzZasIm.js";import"./panels-CX_dYEv0.js";function ze(x,t,i){const u=new Date().toISOString();return{id:`wf_${Date.now()}`,title:x,description:"",nodes:[{id:"task-1",title:t,description:i,type:"task",status:"pending",dependencies:[],priority:5,createdAt:u,updatedAt:u}],createdAt:u,updatedAt:u}}function W(x){const t=(x.nodes??[]).map(i=>({...i,dependencies:Array.isArray(i.dependencies)?i.dependencies:[]}));return{...x,nodes:t}}const L="__all__",xt={saved:"templates.sourceSaved",script:"templates.sourceScript",handwritten:"templates.sourceHandwritten"},mt={explore:"info",plan:"default",execute:"success",verify:"warning",summarize:"info",generic:"default"},ut={explore:"templates.roleExplore",plan:"templates.rolePlan",execute:"templates.roleExecute",verify:"templates.roleVerify",summarize:"templates.roleSummarize",generic:"templates.roleGeneric"};function pt(x){var i;const t=(i=x.metadata)==null?void 0:i.role;return typeof t=="string"?t:x.type}function bt(x){const t=new Map(x.map(m=>[m.id,m])),i=new Set,u=[];let n=[...x];for(;n.length>0;){const m=n.filter(l=>(l.dependencies??[]).every(f=>i.has(f)||!t.has(f)));if(m.length===0){u.push(...n);break}for(const l of m)u.push(l),i.add(l.id);n=n.filter(l=>!i.has(l.id))}return u}function ft({definition:x}){const{t}=Oe(),i=r.useMemo(()=>bt(x.nodes||[]),[x.nodes]);if(i.length===0)return e.jsx("p",{className:"text-xs text-dark-muted",children:t("templates.noNodes")});const u=new Map(i.map(n=>[n.id,n]));return e.jsx("div",{className:"space-y-0",children:i.map((n,m)=>{const l=pt(n),f=mt[l]||"default",D=ut[l],w=(n.dependencies??[]).map(p=>{var h;return((h=u.get(p))==null?void 0:h.title)||p}).filter((p,h,k)=>k.indexOf(p)===h);return e.jsxs("div",{className:"flex gap-2.5",children:[e.jsxs("div",{className:"flex flex-col items-center shrink-0",children:[e.jsx("span",{className:"w-6 h-6 rounded-full grid place-items-center bg-dark-border/60 text-dark-muted text-[10px] font-semibold shrink-0",children:m+1}),m<i.length-1&&e.jsx("span",{className:"w-px flex-1 bg-dark-border/70 my-0.5"})]}),e.jsxs("div",{className:"flex-1 min-w-0 mb-1.5 rounded-lg border border-dark-border bg-dark-bg/60 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5",children:[e.jsx(it,{size:12,className:A("shrink-0",l==="verify"?"text-accent-yellow":l==="explore"?"text-accent-blue":"text-dark-muted")}),e.jsx("span",{className:"text-xs font-medium text-dark-text truncate flex-1",children:n.title}),e.jsx(I,{size:"sm",variant:f,children:D?t(D):l})]}),n.description&&e.jsx("p",{className:"px-2.5 pb-1.5 text-[11px] text-dark-muted leading-relaxed",children:n.description}),w.length>0&&e.jsxs("div",{className:"px-2.5 pb-2 flex items-center flex-wrap gap-1",children:[e.jsx(Ee,{size:11,className:"text-dark-muted/60 shrink-0"}),w.map(p=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-dark-hover text-dark-muted truncate max-w-[16rem]",children:p},p))]})]})]},n.id)})})}function yt({onLaunch:x}){const{t}=Oe(),[i,u]=r.useState([]),[n,m]=r.useState(null),[l,f]=r.useState(null),[D,w]=r.useState(!1),[p,h]=r.useState(""),[k,Me]=r.useState(""),[S,Pe]=r.useState(L),[Q,Y]=r.useState(""),[U,X]=r.useState(""),[Z,ee]=r.useState(""),[te,se]=r.useState(""),[ae,re]=r.useState(""),[Fe,R]=r.useState(!1),[ne,N]=r.useState(""),[Ie,Re]=r.useState(!1),[le,oe]=r.useState([]),[Je,ie]=r.useState(!1),[j,ce]=r.useState(null),[C,z]=r.useState(null),[E,de]=r.useState(null),[Ve,xe]=r.useState(!1),[_e,J]=r.useState(!1),[He,O]=r.useState(!1),[V,_]=r.useState(""),[me,H]=r.useState(""),[ue,pe]=r.useState("general"),[be,B]=r.useState("[]"),[fe,q]=r.useState(()=>JSON.stringify(ze(t("templates.starterTitle"),t("templates.starterNodeTitle"),t("templates.starterNodeDesc")),null,2)),[he,g]=r.useState(""),[G,M]=r.useState(!1),[$,ge]=r.useState(""),[P,K]=r.useState(!1),[ke,v]=r.useState(""),Be=()=>{_(""),H(""),pe("general"),B("[]"),q(JSON.stringify(ze(t("templates.starterTitle"),t("templates.starterNodeTitle"),t("templates.starterNodeDesc")),null,2)),g(""),M(!1),ge(""),K(!1),v(""),O(!0)},qe=async()=>{if(!$.trim()){v(t("templates.aiPromptRequired"));return}K(!0),v("");try{const s=await b.workflows.synthesize($.trim());s.success&&s.data?(_(s.data.title||""),H(s.data.description||""),B("[]"),q(JSON.stringify(W(s.data),null,2)),M(!1),g("")):v(s.error||t("templates.aiDraftFailed"))}catch(s){v(s instanceof Error?s.message:String(s))}finally{K(!1)}},Ge=async()=>{if(!V.trim()){g(t("templates.nameRequired"));return}let s,a;try{s=JSON.parse(be),a=JSON.parse(fe)}catch(c){g(t("templates.jsonParseFailed",{error:c instanceof Error?c.message:String(c)}));return}if(!a||typeof a!="object"||!Array.isArray(a.nodes)){g(t("templates.invalidDefinition"));return}g("");const o=await b.templates.create({name:V.trim(),description:me.trim(),category:ue.trim()||"general",inputs:Array.isArray(s)?s:[],definition:W(a),source:{type:"handwritten"}});o.success&&o.data?(O(!1),m(o.data.id),y()):g(o.error||t("templates.createFailed"))},y=r.useCallback(async()=>{const s=await b.templates.list();s.success&&s.data&&(u(s.data),n&&!s.data.some(a=>a.id===n)&&(m(null),f(null)))},[n]);r.useEffect(()=>{y()},[]),r.useEffect(()=>{if(!n){f(null);return}let s=!1;return w(!0),b.templates.get(n).then(a=>{s||(a.success&&a.data?(f(a.data),Y(a.data.name),X(a.data.description),ee(a.data.category),se(JSON.stringify(a.data.inputs,null,2)),re(JSON.stringify(a.data.definition,null,2)),R(!1),N(""),ie(!1),ce(null),b.templates.versions(n).then(o=>{o.success&&o.data&&oe(o.data)})):h(a.error||t("templates.loadFailed")))}).catch(()=>h(t("templates.loadFailed"))).finally(()=>w(!1)),()=>{s=!0}},[n]);const $e=r.useMemo(()=>{const s=new Set;for(const a of i)s.add(a.category||t("templates.uncategorized"));return[L,...[...s].sort()]},[i,t]),Ne=r.useMemo(()=>{const s=k.trim().toLowerCase();return i.filter(a=>S!==L&&(a.category||t("templates.uncategorized"))!==S?!1:s?`${a.name} ${a.description} ${a.category}`.toLowerCase().includes(s):!0)},[i,k,S,t]),je=r.useMemo(()=>{const s=new Map;for(const a of Ne){const o=a.category||t("templates.uncategorized"),c=s.get(o)||[];c.push(a),s.set(o,c)}return[...s.entries()]},[Ne,t]),T=s=>a=>{s(a),R(!0),N("")},Ke=async()=>{if(!n||!l)return;let s,a;try{s=JSON.parse(te),a=JSON.parse(ae)}catch(c){N(t("templates.jsonParseFailed",{error:c instanceof Error?c.message:String(c)}));return}N("");const o=await b.templates.update(n,{name:Q,description:U,category:Z,inputs:Array.isArray(s)?s:[],definition:W(a)});o.success&&o.data?(f(o.data),R(!1),N(t("templates.savedVersion",{version:o.data.version})),y(),b.templates.versions(n).then(c=>{c.success&&c.data&&oe(c.data)})):N(o.error||t("templates.saveFailed"))},We=async s=>{if(!n)return;xe(!0);const a=await b.templates.render(n,s);xe(!1),de({ok:a.success,json:a.success?JSON.stringify(a.data,null,2):void 0,error:a.success?void 0:a.error||t("templates.renderFailed")})},Qe=s=>{l&&(x(l,s),z(null))},ve=s=>{l&&(de(null),z({mode:s}))},Ye=async s=>{if(!n)return;const a=await b.templates.getVersion(n,s);a.success&&a.data&&ce(a.data)},Ue=async()=>{if(!n)return;(await b.templates.remove(n)).success&&(m(null),J(!1),y())},Xe=()=>{var c,ye,we;if(!n)return e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-dark-muted",children:e.jsxs("div",{className:"text-center px-8",children:[e.jsx(tt,{size:36,className:"mx-auto mb-2 opacity-30 text-dark-muted"}),e.jsx("p",{children:t("templates.selectTemplateHint")}),e.jsx("p",{className:"text-xs text-dark-muted/60 mt-1",children:t("templates.selectTemplateHintSub")})]})});if(D||!l)return e.jsxs("div",{className:"flex-1 flex items-center justify-center text-dark-muted",children:[e.jsx(Ae,{className:"w-4 h-4 animate-spin mr-2"})," ",t("templates.loading")]});const s=((ye=(c=l.definition)==null?void 0:c.nodes)==null?void 0:ye.length)??0,a=((we=l.inputs)==null?void 0:we.length)??0,o=xt[l.source.type];return e.jsx("div",{className:"flex-1 min-w-0 flex flex-col overflow-y-auto custom-scrollbar",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("input",{value:Q,onChange:d=>T(Y)(d.target.value),className:"flex-1 min-w-[200px] px-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-sm text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"}),e.jsxs(I,{variant:"info",children:["v",l.version]}),e.jsx(I,{variant:l.source.type==="saved"?"success":"default",children:o?t(o):l.source.type}),e.jsx("button",{onClick:()=>J(!0),className:"p-2 rounded-lg text-dark-muted hover:text-accent-red hover:bg-dark-hover transition-colors",title:t("templates.deleteTemplate"),children:e.jsx(st,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.categoryLabel")}),e.jsx("input",{value:Z,onChange:d=>T(ee)(d.target.value),className:"w-full px-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-sm text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.descriptionLabel")}),e.jsx("input",{value:U,onChange:d=>T(X)(d.target.value),className:"w-full px-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-sm text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]})]}),e.jsxs("div",{className:"flex items-center gap-4 flex-wrap text-xs text-dark-muted",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Ee,{size:13,className:"text-accent-blue"}),t("templates.nodeCount",{n:s})]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Te,{size:13,className:"text-accent-green"}),t("templates.topologyHint")]}),a>0&&e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(F,{size:13,className:"text-accent-yellow"}),t("templates.inputCount",{n:a})]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Ce,{size:13,className:"text-dark-muted/60"}),new Date(l.updatedAt).toLocaleString()]})]}),e.jsxs("div",{className:"border border-dark-border rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-2 bg-dark-surface border-b border-dark-border flex items-center gap-2",children:[e.jsx(at,{size:13,className:"text-accent-blue shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-dark-text",children:t("templates.workflowNodes")}),e.jsx("span",{className:"ml-auto text-[10px] text-dark-muted",children:t("templates.sortedByDeps")})]}),e.jsx("div",{className:"p-3",children:e.jsx(ft,{definition:l.definition})})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{onClick:()=>ve("launch"),className:"px-4 py-2 rounded-lg bg-accent-blue text-white hover:bg-accent-blue/90 transition-colors inline-flex items-center gap-1.5",children:[e.jsx(rt,{className:"w-4 h-4"})," ",t("templates.launchWithTemplate")]}),e.jsxs("button",{onClick:()=>ve("preview"),className:"px-4 py-2 rounded-lg border border-dark-border text-dark-text hover:bg-dark-hover transition-colors inline-flex items-center gap-1.5",children:[e.jsx(nt,{className:"w-4 h-4"})," ",t("templates.testRun")]}),e.jsxs("button",{onClick:()=>ie(d=>!d),className:"px-4 py-2 rounded-lg border border-dark-border text-dark-text hover:bg-dark-hover transition-colors inline-flex items-center gap-1.5",children:[e.jsx(lt,{className:"w-4 h-4"})," ",t("templates.versionHistory")]}),e.jsxs("button",{onClick:()=>Re(d=>!d),className:"px-4 py-2 rounded-lg border border-dark-border text-dark-text hover:bg-dark-hover transition-colors inline-flex items-center gap-1.5",children:[e.jsx(F,{className:"w-4 h-4"})," ",t("templates.advancedJson")]}),e.jsx("button",{onClick:y,className:"p-2 rounded-lg text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",title:t("templates.refresh"),children:e.jsx(Se,{className:"w-4 h-4"})}),ne&&e.jsx("span",{className:"text-xs text-dark-muted",children:ne})]}),Ie&&e.jsxs("div",{className:"border border-dark-border rounded-lg p-3 space-y-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.inputsSchemaLabel")}),e.jsx("textarea",{value:te,onChange:d=>T(se)(d.target.value),rows:5,spellCheck:!1,className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-xs font-mono text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.definitionLabel")}),e.jsx("textarea",{value:ae,onChange:d=>T(re)(d.target.value),rows:10,spellCheck:!1,className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-xs font-mono text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]}),e.jsxs("button",{onClick:Ke,disabled:!Fe,className:"px-4 py-2 rounded-lg bg-accent-blue text-white hover:bg-accent-blue/90 disabled:opacity-40 transition-colors inline-flex items-center gap-1.5",children:[e.jsx(ot,{className:"w-4 h-4"})," ",t("templates.saveChanges")]})]}),Je&&e.jsxs("div",{className:"border border-dark-border rounded-lg p-3 space-y-1.5",children:[e.jsx("div",{className:"text-xs text-dark-muted mb-1",children:t("templates.versionSnapshotLabel")}),le.length===0&&e.jsx("div",{className:"text-xs text-dark-muted/60",children:t("templates.noVersions")}),le.map(d=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>Ye(d),className:"text-xs px-2 py-1 rounded border border-dark-border hover:border-accent-blue/50 transition-colors",children:["v",d]}),j&&j.version===d&&e.jsx("span",{className:"text-xs text-dark-muted/60",children:t("templates.viewingVersion")})]},d)),j&&e.jsx("pre",{className:"mt-2 p-3 rounded-lg bg-dark-bg text-[10px] font-mono text-dark-muted max-h-60 overflow-y-auto custom-scrollbar",children:JSON.stringify({version:j.version,inputs:j.inputs,definition:j.definition},null,2)})]})]})})};return e.jsxs("div",{className:"flex flex-1 min-h-0 bg-dark-bg",children:[e.jsxs("div",{className:"w-80 shrink-0 border-r border-dark-border overflow-y-auto custom-scrollbar p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 px-1",children:[e.jsx("span",{className:"text-xs uppercase tracking-wider text-dark-muted font-medium",children:t("templates.libraryTitle")}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("button",{onClick:Be,className:"p-1.5 rounded-lg text-accent-blue hover:bg-accent-blue/10 transition-colors inline-flex items-center gap-1 text-xs",title:t("templates.newTemplate"),children:[e.jsx(Ze,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden xl:inline",children:t("templates.newShort")})]}),e.jsx("button",{onClick:()=>{h(""),y()},className:"p-1.5 rounded-lg text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",title:t("templates.refresh"),children:e.jsx(Se,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"relative mb-2",children:[e.jsx(et,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted/60"}),e.jsx("input",{value:k,onChange:s=>Me(s.target.value),placeholder:t("templates.searchPlaceholder"),className:"w-full pl-8 pr-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-xs text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue placeholder:text-dark-muted/50"})]}),e.jsx("div",{className:"flex items-center gap-1.5 mb-3 flex-wrap",children:$e.map(s=>e.jsx("button",{onClick:()=>Pe(s),className:A("text-[11px] px-2 py-0.5 rounded-full border transition-colors",S===s?"border-accent-blue text-accent-blue bg-accent-blue/10":"border-dark-border text-dark-muted hover:border-dark-muted/50 hover:text-dark-text"),children:s===L?t("templates.filterAll"):s},s))}),p&&e.jsx("div",{className:"text-xs text-accent-red mb-2",children:p}),je.length===0&&!p&&e.jsx("div",{className:"text-xs text-dark-muted px-1 py-4 text-center",children:t(k||S!==L?"templates.noMatchTemplates":"templates.emptyTemplates")}),je.map(([s,a])=>e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"px-1 mb-1.5 text-[10px] uppercase tracking-wider text-dark-muted/70",children:s}),e.jsx("div",{className:"space-y-1.5",children:a.map(o=>{const c=n===o.id;return e.jsxs("button",{onClick:()=>m(o.id),className:A("w-full text-left px-3 py-2.5 rounded-lg border transition-colors",c?"bg-accent-blue/10 border-accent-blue/30 text-dark-text":"border-transparent hover:bg-dark-hover text-dark-muted"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:o.name}),e.jsxs(I,{size:"sm",variant:"info",children:["v",o.version]})]}),o.description&&e.jsx("div",{className:"text-[11px] text-dark-muted/70 truncate mt-0.5",children:o.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5 text-[10px] text-dark-muted/60",children:[o.inputs.length>0&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(F,{size:10}),t("templates.paramCount",{n:o.inputs.length})]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{size:10}),new Date(o.updatedAt).toLocaleDateString()]}),e.jsxs("span",{className:"ml-auto inline-flex items-center gap-0.5 text-accent-blue",children:[t(c?"templates.viewing":"templates.view"),!c&&e.jsx(Te,{size:10})]})]})]},o.id)})})]},s))]}),Xe(),C&&l&&e.jsxs(De,{isOpen:!0,onClose:()=>z(null),title:C.mode==="launch"?t("templates.launchModalTitle",{name:l.name}):t("templates.previewModalTitle",{name:l.name}),size:"md",children:[e.jsx(ct,{template:l,onCancel:()=>z(null),onSubmit:C.mode==="launch"?Qe:We,submitLabel:C.mode==="launch"?t("templates.launch"):t("templates.renderPreview"),busy:Ve}),C.mode==="preview"&&E&&e.jsx("div",{className:"mt-4",children:E.ok?e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-accent-green mb-1.5",children:t("templates.renderSuccess")}),e.jsx("pre",{className:"p-3 rounded-lg bg-dark-bg text-[10px] font-mono text-dark-muted max-h-72 overflow-y-auto custom-scrollbar",children:E.json})]}):e.jsx("div",{className:"text-xs text-accent-red",children:E.error})})]}),e.jsx(De,{isOpen:He,onClose:()=>O(!1),title:t("templates.newTemplate"),size:"lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.nameLabel")}),e.jsx("input",{value:V,onChange:s=>_(s.target.value),placeholder:t("templates.namePlaceholder"),className:"w-full px-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-sm text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.categoryField")}),e.jsx("input",{value:ue,onChange:s=>pe(s.target.value),className:"w-full px-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-sm text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.descriptionField")}),e.jsx("input",{value:me,onChange:s=>H(s.target.value),className:"w-full px-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-sm text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{M(!0),v("")},className:A("px-3 py-1.5 rounded-lg border text-xs transition-colors inline-flex items-center gap-1.5",G?"border-accent-blue text-accent-blue bg-accent-blue/10":"border-dark-border text-dark-muted hover:border-dark-muted/50 hover:text-dark-text"),children:[e.jsx(Le,{size:12})," ",t("templates.aiDraftTab")]}),e.jsxs("button",{type:"button",onClick:()=>M(!1),className:A("px-3 py-1.5 rounded-lg border text-xs transition-colors inline-flex items-center gap-1.5",G?"border-dark-border text-dark-muted hover:border-dark-muted/50 hover:text-dark-text":"border-accent-blue text-accent-blue bg-accent-blue/10"),children:[e.jsx(F,{size:12})," ",t("templates.manualJsonTab")]})]}),G?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.aiPromptLabel")}),e.jsx("textarea",{value:$,onChange:s=>ge(s.target.value),rows:4,spellCheck:!1,placeholder:t("templates.aiPromptPlaceholder"),className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-xs text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]}),e.jsxs("button",{type:"button",onClick:()=>void qe(),disabled:P,className:"px-4 py-2 rounded-lg bg-accent-blue text-white hover:bg-accent-blue/90 disabled:opacity-40 transition-colors inline-flex items-center gap-1.5",children:[P?e.jsx(Ae,{className:"w-4 h-4 animate-spin"}):e.jsx(Le,{className:"w-4 h-4"}),t(P?"templates.aiWorking":"templates.generateWorkflow")]}),P&&e.jsx("div",{className:"text-xs text-dark-muted",children:t("templates.aiTimeHint")}),ke&&e.jsx("div",{className:"text-xs text-accent-red",children:ke})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.newInputsLabel")}),e.jsx("textarea",{value:be,onChange:s=>B(s.target.value),rows:4,spellCheck:!1,placeholder:t("templates.inputsExamplePlaceholder"),className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-xs font-mono text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.definitionLabel")}),e.jsx("textarea",{value:fe,onChange:s=>q(s.target.value),rows:12,spellCheck:!1,className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-xs font-mono text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]})]}),he&&e.jsx("div",{className:"text-xs text-accent-red",children:he}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{onClick:()=>O(!1),className:"px-4 py-2 rounded-lg border border-dark-border text-dark-text hover:bg-dark-hover transition-colors",children:t("templates.cancel")}),e.jsx("button",{onClick:()=>void Ge(),className:"px-4 py-2 rounded-lg bg-accent-blue text-white hover:bg-accent-blue/90 transition-colors",children:t("templates.create")})]})]})}),e.jsx(dt,{isOpen:_e,onClose:()=>J(!1),onConfirm:Ue,title:t("templates.deleteTemplate"),message:t("templates.deleteConfirm",{name:(l==null?void 0:l.name)||n||""}),confirmText:t("templates.delete"),variant:"danger"})]})}export{yt as TemplatesTab,bt as topoSortNodes};
|
|
1
|
+
import{j as e}from"./markdown-tZ6sw2sR.js";import{a as r,z as Ze,h as Se,O as et,aG as F,ak as Ce,aH as Te,ag as Le,L as Ae,I as tt,aq as st,G as Ee,ac as at,f as rt,_ as nt,Q as lt,a8 as ot,aI as it}from"./icons-DLsYqrD5.js";import{u as Oe,a as b,d as A,B as I,M as De,I as ct,C as dt}from"./index-DEninW1j.js";import"./react-vendor-BRkWBfPR.js";import"./state-B80cA8v4.js";import"./panels-wDJMsvra.js";function ze(x,t,i){const u=new Date().toISOString();return{id:`wf_${Date.now()}`,title:x,description:"",nodes:[{id:"task-1",title:t,description:i,type:"task",status:"pending",dependencies:[],priority:5,createdAt:u,updatedAt:u}],createdAt:u,updatedAt:u}}function W(x){const t=(x.nodes??[]).map(i=>({...i,dependencies:Array.isArray(i.dependencies)?i.dependencies:[]}));return{...x,nodes:t}}const L="__all__",xt={saved:"templates.sourceSaved",script:"templates.sourceScript",handwritten:"templates.sourceHandwritten"},mt={explore:"info",plan:"default",execute:"success",verify:"warning",summarize:"info",generic:"default"},ut={explore:"templates.roleExplore",plan:"templates.rolePlan",execute:"templates.roleExecute",verify:"templates.roleVerify",summarize:"templates.roleSummarize",generic:"templates.roleGeneric"};function pt(x){var i;const t=(i=x.metadata)==null?void 0:i.role;return typeof t=="string"?t:x.type}function bt(x){const t=new Map(x.map(m=>[m.id,m])),i=new Set,u=[];let n=[...x];for(;n.length>0;){const m=n.filter(l=>(l.dependencies??[]).every(f=>i.has(f)||!t.has(f)));if(m.length===0){u.push(...n);break}for(const l of m)u.push(l),i.add(l.id);n=n.filter(l=>!i.has(l.id))}return u}function ft({definition:x}){const{t}=Oe(),i=r.useMemo(()=>bt(x.nodes||[]),[x.nodes]);if(i.length===0)return e.jsx("p",{className:"text-xs text-dark-muted",children:t("templates.noNodes")});const u=new Map(i.map(n=>[n.id,n]));return e.jsx("div",{className:"space-y-0",children:i.map((n,m)=>{const l=pt(n),f=mt[l]||"default",D=ut[l],w=(n.dependencies??[]).map(p=>{var h;return((h=u.get(p))==null?void 0:h.title)||p}).filter((p,h,k)=>k.indexOf(p)===h);return e.jsxs("div",{className:"flex gap-2.5",children:[e.jsxs("div",{className:"flex flex-col items-center shrink-0",children:[e.jsx("span",{className:"w-6 h-6 rounded-full grid place-items-center bg-dark-border/60 text-dark-muted text-[10px] font-semibold shrink-0",children:m+1}),m<i.length-1&&e.jsx("span",{className:"w-px flex-1 bg-dark-border/70 my-0.5"})]}),e.jsxs("div",{className:"flex-1 min-w-0 mb-1.5 rounded-lg border border-dark-border bg-dark-bg/60 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5",children:[e.jsx(it,{size:12,className:A("shrink-0",l==="verify"?"text-accent-yellow":l==="explore"?"text-accent-blue":"text-dark-muted")}),e.jsx("span",{className:"text-xs font-medium text-dark-text truncate flex-1",children:n.title}),e.jsx(I,{size:"sm",variant:f,children:D?t(D):l})]}),n.description&&e.jsx("p",{className:"px-2.5 pb-1.5 text-[11px] text-dark-muted leading-relaxed",children:n.description}),w.length>0&&e.jsxs("div",{className:"px-2.5 pb-2 flex items-center flex-wrap gap-1",children:[e.jsx(Ee,{size:11,className:"text-dark-muted/60 shrink-0"}),w.map(p=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-dark-hover text-dark-muted truncate max-w-[16rem]",children:p},p))]})]})]},n.id)})})}function yt({onLaunch:x}){const{t}=Oe(),[i,u]=r.useState([]),[n,m]=r.useState(null),[l,f]=r.useState(null),[D,w]=r.useState(!1),[p,h]=r.useState(""),[k,Me]=r.useState(""),[S,Pe]=r.useState(L),[Q,Y]=r.useState(""),[U,X]=r.useState(""),[Z,ee]=r.useState(""),[te,se]=r.useState(""),[ae,re]=r.useState(""),[Fe,R]=r.useState(!1),[ne,N]=r.useState(""),[Ie,Re]=r.useState(!1),[le,oe]=r.useState([]),[Je,ie]=r.useState(!1),[j,ce]=r.useState(null),[C,z]=r.useState(null),[E,de]=r.useState(null),[Ve,xe]=r.useState(!1),[_e,J]=r.useState(!1),[He,O]=r.useState(!1),[V,_]=r.useState(""),[me,H]=r.useState(""),[ue,pe]=r.useState("general"),[be,B]=r.useState("[]"),[fe,q]=r.useState(()=>JSON.stringify(ze(t("templates.starterTitle"),t("templates.starterNodeTitle"),t("templates.starterNodeDesc")),null,2)),[he,g]=r.useState(""),[G,M]=r.useState(!1),[$,ge]=r.useState(""),[P,K]=r.useState(!1),[ke,v]=r.useState(""),Be=()=>{_(""),H(""),pe("general"),B("[]"),q(JSON.stringify(ze(t("templates.starterTitle"),t("templates.starterNodeTitle"),t("templates.starterNodeDesc")),null,2)),g(""),M(!1),ge(""),K(!1),v(""),O(!0)},qe=async()=>{if(!$.trim()){v(t("templates.aiPromptRequired"));return}K(!0),v("");try{const s=await b.workflows.synthesize($.trim());s.success&&s.data?(_(s.data.title||""),H(s.data.description||""),B("[]"),q(JSON.stringify(W(s.data),null,2)),M(!1),g("")):v(s.error||t("templates.aiDraftFailed"))}catch(s){v(s instanceof Error?s.message:String(s))}finally{K(!1)}},Ge=async()=>{if(!V.trim()){g(t("templates.nameRequired"));return}let s,a;try{s=JSON.parse(be),a=JSON.parse(fe)}catch(c){g(t("templates.jsonParseFailed",{error:c instanceof Error?c.message:String(c)}));return}if(!a||typeof a!="object"||!Array.isArray(a.nodes)){g(t("templates.invalidDefinition"));return}g("");const o=await b.templates.create({name:V.trim(),description:me.trim(),category:ue.trim()||"general",inputs:Array.isArray(s)?s:[],definition:W(a),source:{type:"handwritten"}});o.success&&o.data?(O(!1),m(o.data.id),y()):g(o.error||t("templates.createFailed"))},y=r.useCallback(async()=>{const s=await b.templates.list();s.success&&s.data&&(u(s.data),n&&!s.data.some(a=>a.id===n)&&(m(null),f(null)))},[n]);r.useEffect(()=>{y()},[]),r.useEffect(()=>{if(!n){f(null);return}let s=!1;return w(!0),b.templates.get(n).then(a=>{s||(a.success&&a.data?(f(a.data),Y(a.data.name),X(a.data.description),ee(a.data.category),se(JSON.stringify(a.data.inputs,null,2)),re(JSON.stringify(a.data.definition,null,2)),R(!1),N(""),ie(!1),ce(null),b.templates.versions(n).then(o=>{o.success&&o.data&&oe(o.data)})):h(a.error||t("templates.loadFailed")))}).catch(()=>h(t("templates.loadFailed"))).finally(()=>w(!1)),()=>{s=!0}},[n]);const $e=r.useMemo(()=>{const s=new Set;for(const a of i)s.add(a.category||t("templates.uncategorized"));return[L,...[...s].sort()]},[i,t]),Ne=r.useMemo(()=>{const s=k.trim().toLowerCase();return i.filter(a=>S!==L&&(a.category||t("templates.uncategorized"))!==S?!1:s?`${a.name} ${a.description} ${a.category}`.toLowerCase().includes(s):!0)},[i,k,S,t]),je=r.useMemo(()=>{const s=new Map;for(const a of Ne){const o=a.category||t("templates.uncategorized"),c=s.get(o)||[];c.push(a),s.set(o,c)}return[...s.entries()]},[Ne,t]),T=s=>a=>{s(a),R(!0),N("")},Ke=async()=>{if(!n||!l)return;let s,a;try{s=JSON.parse(te),a=JSON.parse(ae)}catch(c){N(t("templates.jsonParseFailed",{error:c instanceof Error?c.message:String(c)}));return}N("");const o=await b.templates.update(n,{name:Q,description:U,category:Z,inputs:Array.isArray(s)?s:[],definition:W(a)});o.success&&o.data?(f(o.data),R(!1),N(t("templates.savedVersion",{version:o.data.version})),y(),b.templates.versions(n).then(c=>{c.success&&c.data&&oe(c.data)})):N(o.error||t("templates.saveFailed"))},We=async s=>{if(!n)return;xe(!0);const a=await b.templates.render(n,s);xe(!1),de({ok:a.success,json:a.success?JSON.stringify(a.data,null,2):void 0,error:a.success?void 0:a.error||t("templates.renderFailed")})},Qe=s=>{l&&(x(l,s),z(null))},ve=s=>{l&&(de(null),z({mode:s}))},Ye=async s=>{if(!n)return;const a=await b.templates.getVersion(n,s);a.success&&a.data&&ce(a.data)},Ue=async()=>{if(!n)return;(await b.templates.remove(n)).success&&(m(null),J(!1),y())},Xe=()=>{var c,ye,we;if(!n)return e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-dark-muted",children:e.jsxs("div",{className:"text-center px-8",children:[e.jsx(tt,{size:36,className:"mx-auto mb-2 opacity-30 text-dark-muted"}),e.jsx("p",{children:t("templates.selectTemplateHint")}),e.jsx("p",{className:"text-xs text-dark-muted/60 mt-1",children:t("templates.selectTemplateHintSub")})]})});if(D||!l)return e.jsxs("div",{className:"flex-1 flex items-center justify-center text-dark-muted",children:[e.jsx(Ae,{className:"w-4 h-4 animate-spin mr-2"})," ",t("templates.loading")]});const s=((ye=(c=l.definition)==null?void 0:c.nodes)==null?void 0:ye.length)??0,a=((we=l.inputs)==null?void 0:we.length)??0,o=xt[l.source.type];return e.jsx("div",{className:"flex-1 min-w-0 flex flex-col overflow-y-auto custom-scrollbar",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("input",{value:Q,onChange:d=>T(Y)(d.target.value),className:"flex-1 min-w-[200px] px-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-sm text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"}),e.jsxs(I,{variant:"info",children:["v",l.version]}),e.jsx(I,{variant:l.source.type==="saved"?"success":"default",children:o?t(o):l.source.type}),e.jsx("button",{onClick:()=>J(!0),className:"p-2 rounded-lg text-dark-muted hover:text-accent-red hover:bg-dark-hover transition-colors",title:t("templates.deleteTemplate"),children:e.jsx(st,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.categoryLabel")}),e.jsx("input",{value:Z,onChange:d=>T(ee)(d.target.value),className:"w-full px-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-sm text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.descriptionLabel")}),e.jsx("input",{value:U,onChange:d=>T(X)(d.target.value),className:"w-full px-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-sm text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]})]}),e.jsxs("div",{className:"flex items-center gap-4 flex-wrap text-xs text-dark-muted",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Ee,{size:13,className:"text-accent-blue"}),t("templates.nodeCount",{n:s})]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Te,{size:13,className:"text-accent-green"}),t("templates.topologyHint")]}),a>0&&e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(F,{size:13,className:"text-accent-yellow"}),t("templates.inputCount",{n:a})]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Ce,{size:13,className:"text-dark-muted/60"}),new Date(l.updatedAt).toLocaleString()]})]}),e.jsxs("div",{className:"border border-dark-border rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-2 bg-dark-surface border-b border-dark-border flex items-center gap-2",children:[e.jsx(at,{size:13,className:"text-accent-blue shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-dark-text",children:t("templates.workflowNodes")}),e.jsx("span",{className:"ml-auto text-[10px] text-dark-muted",children:t("templates.sortedByDeps")})]}),e.jsx("div",{className:"p-3",children:e.jsx(ft,{definition:l.definition})})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{onClick:()=>ve("launch"),className:"px-4 py-2 rounded-lg bg-accent-blue text-white hover:bg-accent-blue/90 transition-colors inline-flex items-center gap-1.5",children:[e.jsx(rt,{className:"w-4 h-4"})," ",t("templates.launchWithTemplate")]}),e.jsxs("button",{onClick:()=>ve("preview"),className:"px-4 py-2 rounded-lg border border-dark-border text-dark-text hover:bg-dark-hover transition-colors inline-flex items-center gap-1.5",children:[e.jsx(nt,{className:"w-4 h-4"})," ",t("templates.testRun")]}),e.jsxs("button",{onClick:()=>ie(d=>!d),className:"px-4 py-2 rounded-lg border border-dark-border text-dark-text hover:bg-dark-hover transition-colors inline-flex items-center gap-1.5",children:[e.jsx(lt,{className:"w-4 h-4"})," ",t("templates.versionHistory")]}),e.jsxs("button",{onClick:()=>Re(d=>!d),className:"px-4 py-2 rounded-lg border border-dark-border text-dark-text hover:bg-dark-hover transition-colors inline-flex items-center gap-1.5",children:[e.jsx(F,{className:"w-4 h-4"})," ",t("templates.advancedJson")]}),e.jsx("button",{onClick:y,className:"p-2 rounded-lg text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",title:t("templates.refresh"),children:e.jsx(Se,{className:"w-4 h-4"})}),ne&&e.jsx("span",{className:"text-xs text-dark-muted",children:ne})]}),Ie&&e.jsxs("div",{className:"border border-dark-border rounded-lg p-3 space-y-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.inputsSchemaLabel")}),e.jsx("textarea",{value:te,onChange:d=>T(se)(d.target.value),rows:5,spellCheck:!1,className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-xs font-mono text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.definitionLabel")}),e.jsx("textarea",{value:ae,onChange:d=>T(re)(d.target.value),rows:10,spellCheck:!1,className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-xs font-mono text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]}),e.jsxs("button",{onClick:Ke,disabled:!Fe,className:"px-4 py-2 rounded-lg bg-accent-blue text-white hover:bg-accent-blue/90 disabled:opacity-40 transition-colors inline-flex items-center gap-1.5",children:[e.jsx(ot,{className:"w-4 h-4"})," ",t("templates.saveChanges")]})]}),Je&&e.jsxs("div",{className:"border border-dark-border rounded-lg p-3 space-y-1.5",children:[e.jsx("div",{className:"text-xs text-dark-muted mb-1",children:t("templates.versionSnapshotLabel")}),le.length===0&&e.jsx("div",{className:"text-xs text-dark-muted/60",children:t("templates.noVersions")}),le.map(d=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>Ye(d),className:"text-xs px-2 py-1 rounded border border-dark-border hover:border-accent-blue/50 transition-colors",children:["v",d]}),j&&j.version===d&&e.jsx("span",{className:"text-xs text-dark-muted/60",children:t("templates.viewingVersion")})]},d)),j&&e.jsx("pre",{className:"mt-2 p-3 rounded-lg bg-dark-bg text-[10px] font-mono text-dark-muted max-h-60 overflow-y-auto custom-scrollbar",children:JSON.stringify({version:j.version,inputs:j.inputs,definition:j.definition},null,2)})]})]})})};return e.jsxs("div",{className:"flex flex-1 min-h-0 bg-dark-bg",children:[e.jsxs("div",{className:"w-80 shrink-0 border-r border-dark-border overflow-y-auto custom-scrollbar p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 px-1",children:[e.jsx("span",{className:"text-xs uppercase tracking-wider text-dark-muted font-medium",children:t("templates.libraryTitle")}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("button",{onClick:Be,className:"p-1.5 rounded-lg text-accent-blue hover:bg-accent-blue/10 transition-colors inline-flex items-center gap-1 text-xs",title:t("templates.newTemplate"),children:[e.jsx(Ze,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden xl:inline",children:t("templates.newShort")})]}),e.jsx("button",{onClick:()=>{h(""),y()},className:"p-1.5 rounded-lg text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",title:t("templates.refresh"),children:e.jsx(Se,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"relative mb-2",children:[e.jsx(et,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted/60"}),e.jsx("input",{value:k,onChange:s=>Me(s.target.value),placeholder:t("templates.searchPlaceholder"),className:"w-full pl-8 pr-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-xs text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue placeholder:text-dark-muted/50"})]}),e.jsx("div",{className:"flex items-center gap-1.5 mb-3 flex-wrap",children:$e.map(s=>e.jsx("button",{onClick:()=>Pe(s),className:A("text-[11px] px-2 py-0.5 rounded-full border transition-colors",S===s?"border-accent-blue text-accent-blue bg-accent-blue/10":"border-dark-border text-dark-muted hover:border-dark-muted/50 hover:text-dark-text"),children:s===L?t("templates.filterAll"):s},s))}),p&&e.jsx("div",{className:"text-xs text-accent-red mb-2",children:p}),je.length===0&&!p&&e.jsx("div",{className:"text-xs text-dark-muted px-1 py-4 text-center",children:t(k||S!==L?"templates.noMatchTemplates":"templates.emptyTemplates")}),je.map(([s,a])=>e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"px-1 mb-1.5 text-[10px] uppercase tracking-wider text-dark-muted/70",children:s}),e.jsx("div",{className:"space-y-1.5",children:a.map(o=>{const c=n===o.id;return e.jsxs("button",{onClick:()=>m(o.id),className:A("w-full text-left px-3 py-2.5 rounded-lg border transition-colors",c?"bg-accent-blue/10 border-accent-blue/30 text-dark-text":"border-transparent hover:bg-dark-hover text-dark-muted"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:o.name}),e.jsxs(I,{size:"sm",variant:"info",children:["v",o.version]})]}),o.description&&e.jsx("div",{className:"text-[11px] text-dark-muted/70 truncate mt-0.5",children:o.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5 text-[10px] text-dark-muted/60",children:[o.inputs.length>0&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(F,{size:10}),t("templates.paramCount",{n:o.inputs.length})]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ce,{size:10}),new Date(o.updatedAt).toLocaleDateString()]}),e.jsxs("span",{className:"ml-auto inline-flex items-center gap-0.5 text-accent-blue",children:[t(c?"templates.viewing":"templates.view"),!c&&e.jsx(Te,{size:10})]})]})]},o.id)})})]},s))]}),Xe(),C&&l&&e.jsxs(De,{isOpen:!0,onClose:()=>z(null),title:C.mode==="launch"?t("templates.launchModalTitle",{name:l.name}):t("templates.previewModalTitle",{name:l.name}),size:"md",children:[e.jsx(ct,{template:l,onCancel:()=>z(null),onSubmit:C.mode==="launch"?Qe:We,submitLabel:C.mode==="launch"?t("templates.launch"):t("templates.renderPreview"),busy:Ve}),C.mode==="preview"&&E&&e.jsx("div",{className:"mt-4",children:E.ok?e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-accent-green mb-1.5",children:t("templates.renderSuccess")}),e.jsx("pre",{className:"p-3 rounded-lg bg-dark-bg text-[10px] font-mono text-dark-muted max-h-72 overflow-y-auto custom-scrollbar",children:E.json})]}):e.jsx("div",{className:"text-xs text-accent-red",children:E.error})})]}),e.jsx(De,{isOpen:He,onClose:()=>O(!1),title:t("templates.newTemplate"),size:"lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.nameLabel")}),e.jsx("input",{value:V,onChange:s=>_(s.target.value),placeholder:t("templates.namePlaceholder"),className:"w-full px-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-sm text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.categoryField")}),e.jsx("input",{value:ue,onChange:s=>pe(s.target.value),className:"w-full px-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-sm text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.descriptionField")}),e.jsx("input",{value:me,onChange:s=>H(s.target.value),className:"w-full px-3 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-sm text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{M(!0),v("")},className:A("px-3 py-1.5 rounded-lg border text-xs transition-colors inline-flex items-center gap-1.5",G?"border-accent-blue text-accent-blue bg-accent-blue/10":"border-dark-border text-dark-muted hover:border-dark-muted/50 hover:text-dark-text"),children:[e.jsx(Le,{size:12})," ",t("templates.aiDraftTab")]}),e.jsxs("button",{type:"button",onClick:()=>M(!1),className:A("px-3 py-1.5 rounded-lg border text-xs transition-colors inline-flex items-center gap-1.5",G?"border-dark-border text-dark-muted hover:border-dark-muted/50 hover:text-dark-text":"border-accent-blue text-accent-blue bg-accent-blue/10"),children:[e.jsx(F,{size:12})," ",t("templates.manualJsonTab")]})]}),G?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.aiPromptLabel")}),e.jsx("textarea",{value:$,onChange:s=>ge(s.target.value),rows:4,spellCheck:!1,placeholder:t("templates.aiPromptPlaceholder"),className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-xs text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]}),e.jsxs("button",{type:"button",onClick:()=>void qe(),disabled:P,className:"px-4 py-2 rounded-lg bg-accent-blue text-white hover:bg-accent-blue/90 disabled:opacity-40 transition-colors inline-flex items-center gap-1.5",children:[P?e.jsx(Ae,{className:"w-4 h-4 animate-spin"}):e.jsx(Le,{className:"w-4 h-4"}),t(P?"templates.aiWorking":"templates.generateWorkflow")]}),P&&e.jsx("div",{className:"text-xs text-dark-muted",children:t("templates.aiTimeHint")}),ke&&e.jsx("div",{className:"text-xs text-accent-red",children:ke})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.newInputsLabel")}),e.jsx("textarea",{value:be,onChange:s=>B(s.target.value),rows:4,spellCheck:!1,placeholder:t("templates.inputsExamplePlaceholder"),className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-xs font-mono text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted mb-1 block",children:t("templates.definitionLabel")}),e.jsx("textarea",{value:fe,onChange:s=>q(s.target.value),rows:12,spellCheck:!1,className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-xs font-mono text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]})]}),he&&e.jsx("div",{className:"text-xs text-accent-red",children:he}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{onClick:()=>O(!1),className:"px-4 py-2 rounded-lg border border-dark-border text-dark-text hover:bg-dark-hover transition-colors",children:t("templates.cancel")}),e.jsx("button",{onClick:()=>void Ge(),className:"px-4 py-2 rounded-lg bg-accent-blue text-white hover:bg-accent-blue/90 transition-colors",children:t("templates.create")})]})]})}),e.jsx(dt,{isOpen:_e,onClose:()=>J(!1),onConfirm:Ue,title:t("templates.deleteTemplate"),message:t("templates.deleteConfirm",{name:(l==null?void 0:l.name)||n||""}),confirmText:t("templates.delete"),variant:"danger"})]})}export{yt as TemplatesTab,bt as topoSortNodes};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{j as r}from"./markdown-
|
|
1
|
+
import{j as r}from"./markdown-tZ6sw2sR.js";import{a as s,aO as U,aP as X,h as G,b as V,D as K,aq as Q,w as Z,x as ee}from"./icons-DLsYqrD5.js";import{r as te,a as re}from"./terminal-DgJRGhIz.js";import{u as se,e as $,f as ne,g as C,t as oe}from"./index-DEninW1j.js";import"./react-vendor-BRkWBfPR.js";import"./state-B80cA8v4.js";import"./panels-wDJMsvra.js";var ae=te(),ce=re();const le={background:"#1e1e1e",foreground:"#d4d4d4",cursor:"#d4d4d4",cursorAccent:"#1e1e1e",black:"#1e1e1e",red:"#f44747",green:"#608b4e",yellow:"#dcdcaa",blue:"#569cd6",magenta:"#c586c0",cyan:"#4ec9b0",white:"#d4d4d4",brightBlack:"#808080",brightRed:"#f44747",brightGreen:"#608b4e",brightYellow:"#dcdcaa",brightBlue:"#569cd6",brightMagenta:"#c586c0",brightCyan:"#4ec9b0",brightWhite:"#ffffff"};function be(){const{t:j}=se(),p=s.useRef(null),c=s.useRef(null),w=s.useRef(null),o=s.useRef(null),[S,I]=s.useState(!1),[k,B]=s.useState(null),[y,R]=s.useState(!0),d=s.useRef(!1),T=s.useRef({isAtBottom:!0}),M=s.useCallback(t=>{const e=c.current;if(!e)return;const n=e.buffer.active;T.current.isAtBottom=n.baseY+e.rows>=n.length,e.write(t,()=>{T.current.isAtBottom&&!d.current&&e.scrollToBottom();const l=e.buffer.active;l.baseY+e.rows>=l.length&&(d.current=!1)})},[]),[v,N]=s.useState(""),b=s.useCallback(()=>{const t=c.current,e=o.current;!t||!e||e.readyState!==WebSocket.OPEN||e.send(JSON.stringify({type:"resize",cols:t.cols,rows:t.rows}))},[]),{status:z,errorMessage:E,port:A}=$(),{setStarting:D,setRunning:F,setStopping:L,setIdle:O,setError:m}=$(),{workspaceDir:x}=ne(),h=s.useCallback(()=>{o.current&&(o.current.onclose=null,o.current.onmessage=null,o.current.onerror=null,o.current.onopen=null,o.current.close(),o.current=null)},[]),g=s.useCallback(async t=>{D(),t.writeln("\x1B[90mStarting local terminal...\x1B[0m");try{const e=await C.post("/api/terminal/start",{workspaceDir:x});if(!e.success||!e.data){const a=e.error||"Failed to start terminal";m(a),t.writeln(`\x1B[31m${a}\x1B[0m`);return}const n=e.data.port??e.data.ttydPort,l=e.data.wsUrl;if(!n||!l){const a="Invalid terminal start response";m(a),t.writeln(`\x1B[31m${a}\x1B[0m`);return}F(n,l),N(e.data.workspaceDir||x);const i=new WebSocket(l);o.current=i,i.onopen=()=>{const a=sessionStorage.getItem("auth_token")??localStorage.getItem("auth_token");a&&i.send(JSON.stringify({type:"auth",token:a})),t.clear(),t.focus(),t.writeln("\x1B[32mConnected to local shell\x1B[0m"),setTimeout(()=>{var u,f;(u=w.current)==null||u.fit(),b(),d.current||(f=c.current)==null||f.scrollToBottom()},50)},i.onmessage=a=>{typeof a.data=="string"&&M(a.data)},i.onerror=()=>{m("Terminal connection error")},i.onclose=()=>{o.current===i&&(o.current=null,m("Terminal disconnected"),t.writeln("\x1B[33mTerminal disconnected\x1B[0m"))}}catch(e){const n=e instanceof Error?e.message:"Unknown error";m(n),t.writeln(`\x1B[31m${n}\x1B[0m`)}},[x,D,F,m,b]),W=s.useCallback(async()=>{h(),L();try{await C.post("/api/terminal/stop")}catch{}O()},[h,L,O]);s.useEffect(()=>{p.current&&C.get("/api/terminal/status").then(t=>{const e=t.success&&t.data?t.data:null;B((e==null?void 0:e.terminalAvailable)!==!1),e!=null&&e.workspaceDir&&N(e.workspaceDir)}).catch(()=>B(!1))},[]),s.useEffect(()=>{if(k!==!0||!p.current)return;const t=new ae.Terminal({theme:le,fontFamily:'"Cascadia Code", "Fira Code", Consolas, "Courier New", monospace',fontSize:14,lineHeight:1.2,cursorBlink:!0,cursorStyle:"block",scrollback:1e4,convertEol:!0}),e=new ce.FitAddon;t.loadAddon(e),t.open(p.current),t.focus(),e.fit(),c.current=t,w.current=e,t.writeln("\x1B[36mDeepSeekCode Local Terminal\x1B[0m"),t.writeln("\x1B[90mRun commands directly on this machine.\x1B[0m");const n=t.onData(u=>{var f;((f=o.current)==null?void 0:f.readyState)===WebSocket.OPEN&&o.current.send(u)}),l=t.onScroll(()=>{const u=t.buffer.active;u.baseY+t.rows<u.length&&(d.current=!0,R(!1))}),i=()=>{var u;(u=w.current)==null||u.fit(),b(),d.current||t.scrollToBottom()};window.addEventListener("resize",i);const a=window.setTimeout(()=>g(t),50);return()=>{clearTimeout(a),window.removeEventListener("resize",i),n.dispose(),l.dispose(),W(),t.dispose(),c.current=null}},[k,g,W,b]);const P=s.useCallback(()=>{var e;const t=(e=c.current)==null?void 0:e.getSelection();t&&(navigator.clipboard.writeText(t),oe.success("Copied selection"))},[]),Y=s.useCallback(()=>{var t,e;(t=c.current)==null||t.clear(),d.current||(e=c.current)==null||e.scrollToBottom()},[]),q=s.useCallback(()=>{h(),c.current&&(c.current.clear(),g(c.current))},[h,g]),_=s.useCallback(()=>{R(t=>{var n;const e=!t;return d.current=!e,e&&((n=c.current)==null||n.scrollToBottom()),e})},[]),H=s.useCallback(()=>{const t=`Workspace: ${v||x}
|
|
2
2
|
Terminal session: ${A??""}
|
|
3
3
|
`,e=new Blob([t],{type:"text/plain"}),n=URL.createObjectURL(e),l=document.createElement("a");l.href=n,l.download=`terminal-${Date.now()}.log`,l.click(),URL.revokeObjectURL(n)},[x,v,A]),J=s.useMemo(()=>({idle:"Idle",starting:"Connecting",running:"Connected",stopping:"Stopping",error:"Error"})[z],[z]);return k===!1?r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center bg-[#1e1e1e] gap-3 p-8",children:[r.jsx(U,{size:44,className:"text-dark-muted opacity-40"}),r.jsx("div",{className:"text-sm text-dark-muted",children:"Local terminal unavailable"})]}):r.jsxs("div",{className:`flex flex-col bg-[#1e1e1e] border-t border-dark-border ${S?"fixed inset-0 z-50":"flex-1 min-h-0"}`,children:[r.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2 bg-[#252526] border-b border-[#3c3c3c]",children:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx(U,{size:14,className:"text-dark-muted shrink-0"}),r.jsx("span",{className:"text-xs text-dark-muted shrink-0",children:"Terminal"}),r.jsx("span",{className:"text-xs text-dark-muted truncate",children:v||x}),r.jsxs("span",{className:"text-xs text-dark-muted",children:["[",J,"]"]}),E&&r.jsx("span",{className:"text-xs text-accent-red truncate max-w-[240px]",children:E})]}),r.jsxs("div",{className:"flex items-center gap-1 flex-wrap justify-end",children:[r.jsx("button",{onClick:_,className:`p-1 rounded hover:bg-[#3c3c3c] ${y?"text-accent-blue":"text-dark-muted"} hover:text-dark-text`,title:j(y?"terminal.autoFollowOn":"terminal.autoFollowOff"),children:r.jsx(X,{size:12})}),r.jsx("button",{onClick:q,className:"p-1 rounded hover:bg-[#3c3c3c] text-dark-muted hover:text-dark-text",title:"Restart",children:r.jsx(G,{size:12})}),r.jsx("button",{onClick:P,className:"p-1 rounded hover:bg-[#3c3c3c] text-dark-muted hover:text-dark-text",title:"Copy",children:r.jsx(V,{size:12})}),r.jsx("button",{onClick:H,className:"p-1 rounded hover:bg-[#3c3c3c] text-dark-muted hover:text-dark-text",title:"Download log",children:r.jsx(K,{size:12})}),r.jsx("button",{onClick:Y,className:"p-1 rounded hover:bg-[#3c3c3c] text-dark-muted hover:text-dark-text",title:"Clear",children:r.jsx(Q,{size:12})}),r.jsx("button",{onClick:()=>I(t=>!t),className:"p-1 rounded hover:bg-[#3c3c3c] text-dark-muted hover:text-dark-text",title:"Fullscreen",children:S?r.jsx(Z,{size:12}):r.jsx(ee,{size:12})})]})]}),r.jsx("div",{ref:p,className:"flex-1 overflow-hidden"})]})}export{be as TerminalView,be as default};
|