@kimicode/cli 1.0.39 → 1.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/LICENSE.md +12 -0
  2. package/README.md +427 -31
  3. package/bin/stt/requirements.txt +32 -0
  4. package/bin/stt/stt_server.py +619 -0
  5. package/bin/tts/requirements.txt +21 -0
  6. package/bin/tts/tts_server.py +404 -0
  7. package/cli-wrapper.cjs +4 -0
  8. package/llms.txt +88 -0
  9. package/package.json +30 -11
  10. package/web/dist/assets/AssistantsView-BiUiWjhF.js +1 -0
  11. package/web/dist/assets/AutomationView-Dcf_yNaI.js +1 -0
  12. package/web/dist/assets/ChannelConfigView-BLnxsMGm.js +8 -0
  13. package/web/dist/assets/ConnectorsView-CX3E6X6c.js +1 -0
  14. package/web/dist/assets/DesignSystemView--x-P-lpD.js +1 -0
  15. package/web/dist/assets/Drawer-CjAgqH3B.js +1 -0
  16. package/web/dist/assets/{FileTreeView-hBtHBbAV.js → FileTreeView-Chb_fzTK.js} +3 -3
  17. package/web/dist/assets/HookConfigView-EafYlWdN.js +1 -0
  18. package/web/dist/assets/InputArea-BbHslX7b.js +50 -0
  19. package/web/dist/assets/ModelsView-CGN5Nljr.js +1 -0
  20. package/web/dist/assets/PluginsView-CDiJgvI8.js +2 -0
  21. package/web/dist/assets/ProjectsView-C5Usmwqy.js +1 -0
  22. package/web/dist/assets/SessionGrid-Drxg0r_u.js +4 -0
  23. package/web/dist/assets/SettingsModal-Cmts6aBG.js +10 -0
  24. package/web/dist/assets/Skeleton-Dsk6B0U3.js +1 -0
  25. package/web/dist/assets/SkillsView-TEDR_3XX.js +1 -0
  26. package/web/dist/assets/TemplatesTab-DtN5Kdgh.js +1 -0
  27. package/web/dist/assets/ToolsView-VukZnIt1.js +1 -0
  28. package/web/dist/assets/VizCardsSkeleton-C_GaEfXd.js +1 -0
  29. package/web/dist/assets/abnfDiagram-YUKMZFIV-BIFw6B_N.js +1 -0
  30. package/web/dist/assets/arc-BZQ951h9.js +1 -0
  31. package/web/dist/assets/architectureDiagram-47P4ROYG-BP5qiXzf.js +36 -0
  32. package/web/dist/assets/blockDiagram-E7TT5TSB-DtRpcE7F.js +140 -0
  33. package/web/dist/assets/c4Diagram-CRA5TL53-Gdzn8UBh.js +38 -0
  34. package/web/dist/assets/channel-BND6_KSH.js +1 -0
  35. package/web/dist/assets/chunk-2Q5K7J3B-3U6HMlsm.js +1 -0
  36. package/web/dist/assets/chunk-5VM5RSS4-CYl9mwa-.js +15 -0
  37. package/web/dist/assets/chunk-7TKQ45FW-Dn6ktcY5.js +1 -0
  38. package/web/dist/assets/chunk-AW2ZBBNX-De0QX6p1.js +88 -0
  39. package/web/dist/assets/chunk-FVRAUYC3-CpXDfvz4.js +2 -0
  40. package/web/dist/assets/chunk-HTAEGDNF-D1KDvcDd.js +1 -0
  41. package/web/dist/assets/chunk-JWPE2WC7-umm4A-fq.js +1 -0
  42. package/web/dist/assets/chunk-KQW6MTUR-JYH94hpE.js +1 -0
  43. package/web/dist/assets/chunk-XXDRQBXY-CSlCFByc.js +1 -0
  44. package/web/dist/assets/classDiagram-v2-K4WV4PDN-DnFwS0qN.js +217 -0
  45. package/web/dist/assets/cose-bilkent-JH36ORCC-BxUTUyep.js +1 -0
  46. package/web/dist/assets/cynefin-EF2NZ3EQ-CiMvulJr.js +141 -0
  47. package/web/dist/assets/cynefinDiagram-3GCD6N5R-DuXFORdW.js +62 -0
  48. package/web/dist/assets/cytoscape.esm-Ix0LnXOy.js +331 -0
  49. package/web/dist/assets/dagre-W4DXFKR2-DzMZHXci.js +4 -0
  50. package/web/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
  51. package/web/dist/assets/diagram-2UJZ2QOL-B6tO5G1v.js +200 -0
  52. package/web/dist/assets/diagram-OVF4WLC6-DRZt8tGc.js +24 -0
  53. package/web/dist/assets/diagram-PFPMY2P6-DGh6IecR.js +30 -0
  54. package/web/dist/assets/diagram-UMYRVEAY-BLbnt0yT.js +24 -0
  55. package/web/dist/assets/diagram-YEKJPTXX-C-S5DVhj.js +41 -0
  56. package/web/dist/assets/diagram-ZIFT7M5P-JrGHTWbo.js +3 -0
  57. package/web/dist/assets/ebnfDiagram-VR2GEFS7-DPXA-YOi.js +1 -0
  58. package/web/dist/assets/elk-IJKZMXRS-CINeWt2W.js +27 -0
  59. package/web/dist/assets/erDiagram-O2IAPWRE-PPaHmqA1.js +99 -0
  60. package/web/dist/assets/flowDiagram-OXPTDLAJ-t-u0QXEA.js +213 -0
  61. package/web/dist/assets/ganttDiagram-R7TSEDQI-Bw49ZD_b.js +292 -0
  62. package/web/dist/assets/gitGraphDiagram-XJZIOB7I-BAfOqeeg.js +106 -0
  63. package/web/dist/assets/graph-Bn3Yngep.js +1 -0
  64. package/web/dist/assets/{icons-BxNxyk-c.js → icons-Bm_ZzSAy.js} +320 -160
  65. package/web/dist/assets/index-CeeLdENM.js +677 -0
  66. package/web/dist/assets/index-Ceez9lYk.css +1 -0
  67. package/web/dist/assets/infoDiagram-5W2HQ5XZ-Bv4RBxYW.js +2 -0
  68. package/web/dist/assets/init-Gi6I4Gst.js +1 -0
  69. package/web/dist/assets/ishikawaDiagram-K3B6WC7H-DEpj0bRp.js +70 -0
  70. package/web/dist/assets/journeyDiagram-COXZFDF6-MJu84Iiz.js +139 -0
  71. package/web/dist/assets/kanban-definition-P3RFRI5V-mlYSRALK.js +89 -0
  72. package/web/dist/assets/linear-5j9gt8MV.js +1 -0
  73. package/web/dist/assets/{markdown-B2L4Mq-x.js → markdown-BWXjRrSw.js} +8 -8
  74. package/web/dist/assets/mermaid.core-DLb6eAON.js +314 -0
  75. package/web/dist/assets/mindmap-definition-LZFPQGKD-C9v_57Ex.js +96 -0
  76. package/web/dist/assets/ordinal-Cboi1Yqb.js +1 -0
  77. package/web/dist/assets/{panels-P_I7Q72_.js → panels-BQOvnbWH.js} +1 -1
  78. package/web/dist/assets/pegDiagram-BGZESJAR-KQP26s3-.js +1 -0
  79. package/web/dist/assets/pieDiagram-CAPJLFHJ-DN3RQ_ih.js +39 -0
  80. package/web/dist/assets/profileChange-B7TaQ18u.js +1 -0
  81. package/web/dist/assets/quadrantDiagram-GDMTTRAM-BpL_ZL76.js +7 -0
  82. package/web/dist/assets/railroadDiagram-SM67HX2B-DZ-fPU85.js +1 -0
  83. package/web/dist/assets/{react-vendor-B2V_5iSS.js → react-vendor-C0HIWSpf.js} +1 -1
  84. package/web/dist/assets/requirementDiagram-X7JNWC4A-mKPGj64L.js +84 -0
  85. package/web/dist/assets/sankeyDiagram-UM26HJRW-Bs4xfjQP.js +40 -0
  86. package/web/dist/assets/sequenceDiagram-ZO4K6R2Y-BjUmzZaO.js +169 -0
  87. package/web/dist/assets/sizeCapture-INFHLROL-BXBM3j_Q.js +1 -0
  88. package/web/dist/assets/{state-0T92JV0u.js → state-Kfon1nTr.js} +1 -1
  89. package/web/dist/assets/stateDiagram-v2-TBUQTH76-FGgFDGUU.js +291 -0
  90. package/web/dist/assets/sttLanguages-C7kVulzY.js +1 -0
  91. package/web/dist/assets/swimlanes-N4OXWK64-wkd_n4HU.js +1 -0
  92. package/web/dist/assets/swimlanesDiagram-K3J5GTZL-CKnwEuq_.js +8 -0
  93. package/web/dist/assets/timeline-definition-YOQAKGHF-DyBln1jw.js +120 -0
  94. package/web/dist/assets/usecaseDiagram-VIAY4XPW-Cqis3XHX.js +370 -0
  95. package/web/dist/assets/vennDiagram-BLWOH2XV-BaiFLOVS.js +34 -0
  96. package/web/dist/assets/wardleyDiagram-YMQ3BMBF-C4CzpJto.js +78 -0
  97. package/web/dist/assets/xychartDiagram-TAQBALBS-Dp1hfe3-.js +7 -0
  98. package/web/dist/figma-demo/product-1.jpg +0 -0
  99. package/web/dist/figma-demo/product-2.jpg +0 -0
  100. package/web/dist/figma-demo/trail-1.jpg +0 -0
  101. package/web/dist/figma-demo/trail-2.jpg +0 -0
  102. package/web/dist/figma-demo/trail-3.jpg +0 -0
  103. package/web/dist/index.html +8 -8
  104. package/web/dist/assets/AssistantsView-0aLB_cG6.js +0 -1
  105. package/web/dist/assets/AutomationView-CAMjPhJ2.js +0 -1
  106. package/web/dist/assets/ChannelConfigView-FcioeeYb.js +0 -8
  107. package/web/dist/assets/ConnectorsView-DERP7zAW.js +0 -1
  108. package/web/dist/assets/HookConfigView-NModtSB8.js +0 -1
  109. package/web/dist/assets/ModelsView-BPpO50C_.js +0 -1
  110. package/web/dist/assets/PluginsView-D0NE7zrt.js +0 -1
  111. package/web/dist/assets/ProjectsView-PIv7Gx4q.js +0 -1
  112. package/web/dist/assets/SessionGrid-BsDL3lov.js +0 -47
  113. package/web/dist/assets/SettingsModal-DdebvEmv.js +0 -10
  114. package/web/dist/assets/SkillsView-BNoigImJ.js +0 -1
  115. package/web/dist/assets/TemplatesTab-D8Pa68fj.js +0 -1
  116. package/web/dist/assets/ToolsView-NY-yk5YX.js +0 -1
  117. package/web/dist/assets/WorkspaceDirPicker-C5knnArH.js +0 -6
  118. package/web/dist/assets/index-DaiVo1RY.css +0 -1
  119. package/web/dist/assets/index-RB5ffy32.js +0 -620
  120. package/web/dist/assets/profileChange-C7Jg9C61.js +0 -1
@@ -0,0 +1 @@
1
+ import{j as e}from"./markdown-BWXjRrSw.js";import{a as n,s as Q,k as W,A as xe,X,d as L,a8 as $e,a9 as Fe,aa as Pe,D as ls,ab as ns,C as is,T as Ae,j as Le,Z as qe,p as de,w as cs,U as ds,ac as os}from"./icons-Bm_ZzSAy.js";import{u as me,a as u,B as j,M as De,C as xs}from"./index-CeeLdENM.js";import{S as ms}from"./Skeleton-Dsk6B0U3.js";import"./react-vendor-C0HIWSpf.js";import"./state-Kfon1nTr.js";import"./panels-BQOvnbWH.js";function us(){const{t:c}=me(),[t,p]=n.useState([]),[b,h]=n.useState(!0),[x,f]=n.useState(null),[q,y]=n.useState(null),[D,w]=n.useState(!1),[g,C]=n.useState({skillName:"",description:"",trigger:"",content:""}),[S,T]=n.useState(!1),[F,P]=n.useState(null),v=n.useCallback(async()=>{h(!0);try{const r=await u.skills.workshop.list();p(r.data??[]),f(null)}catch(r){f(r instanceof Error?r.message:String(r))}finally{h(!1)}},[]);n.useEffect(()=>{v()},[v]);const $=async r=>{y(r);try{await u.skills.workshop.apply(r),await v()}catch(m){f(m instanceof Error?m.message:String(m))}finally{y(null)}},z=async r=>{y(r);try{await u.skills.workshop.reject(r),await v()}catch(m){f(m instanceof Error?m.message:String(m))}finally{y(null)}},d=async()=>{if(!g.skillName.trim()||!g.content.trim()){P(c("skills.workshopFormRequired")||"skillName and content are required");return}T(!0),P(null);try{await u.skills.workshop.propose({skillName:g.skillName.trim(),description:g.description.trim(),trigger:g.trigger.trim(),content:g.content.trim(),reason:"manual proposal"}),C({skillName:"",description:"",trigger:"",content:""}),w(!1),await v()}catch(r){P(r instanceof Error?r.message:String(r))}finally{T(!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.jsx(j,{variant:"accent",leftIcon:e.jsx(Q,{size:14}),onClick:()=>{w(r=>!r),P(null)},children:c("skills.workshopPropose")||"新建提案"})]}),D&&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:g.skillName,onChange:r=>C(m=>({...m,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:g.trigger,onChange:r=>C(m=>({...m,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:g.description,onChange:r=>C(m=>({...m,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:g.content,onChange:r=>C(m=>({...m,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"}),F&&e.jsx("div",{className:"text-xs text-accent-red",children:F}),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.jsx(j,{variant:"accent",leftIcon:e.jsx(W,{size:14}),loading:S,onClick:d,children:c("skills.workshopSubmit")||"提交提案"})]})]}),x&&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(xe,{size:14,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:x}),e.jsx("button",{onClick:()=>f(null),className:"shrink-0 p-0.5 rounded hover:bg-dark-hover",children:e.jsx(X,{size:14})})]}),b?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(L,{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($e,{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:q===r.id,className:"px-2 py-1 bg-accent-green text-accent-fg rounded text-xs flex items-center gap-1 disabled:opacity-50",children:[e.jsx(W,{size:12}),c("skills.workshopApply")||"应用"]}),e.jsx("button",{onClick:()=>z(r.id),disabled:q===r.id,className:"px-2 py-1 rounded text-xs border border-dark-border hover:bg-dark-hover disabled:opacity-50",children:e.jsx(X,{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-meta 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 ps=/^(https?:|data:)/i;function V({icon:c,className:t="w-4 h-4 rounded object-cover shrink-0"}){return c&&ps.test(c)?e.jsx("img",{src:c,alt:"",loading:"lazy",className:t}):e.jsx("span",{children:c||"⭐"})}function gs({marketplaces:c,value:t,onChange:p}){const{t:b}=me(),h=Array.from(new Map(c.filter(x=>x.domain).map(x=>[x.domain,x.domainIcon||"📁"])).entries());return h.length===0?null:e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:[{id:"",icon:"🗂️"},...h.map(([x,f])=>({id:x,icon:f}))].map(x=>e.jsxs("button",{onClick:()=>p(x.id),className:`flex items-center gap-1 px-2.5 py-1 rounded-full border text-xs transition-colors ${t===x.id?"border-accent-blue bg-accent-blue/15 text-accent-blue":"border-dark-border bg-dark-surface text-dark-muted hover:bg-dark-hover"}`,children:[e.jsx(V,{icon:x.icon,className:"w-3.5 h-3.5 rounded-sm object-cover shrink-0"}),e.jsx("span",{children:x.id||b("skills.marketDomainAll")})]},x.id||"__all__"))})}const oe={id:"",name:"",description:"",category:"",trigger:"",systemPrompt:"",injection:"lazy",tags:"",requiredTools:""},G=8;function ys({onUseSkill:c}){var Ee;const{t}=me(),[p,b]=n.useState("marketplace"),[h,x]=n.useState([]),[f,q]=n.useState(!0),[y,D]=n.useState(null),[w,g]=n.useState(""),[C,S]=n.useState(!1),[T,F]=n.useState(null),[P,v]=n.useState(!1),[$,z]=n.useState(null),[d,r]=n.useState(oe),[m,Y]=n.useState(!1),[_e,ue]=n.useState(!1),[pe,J]=n.useState(null),_=n.useRef(null),[K,ee]=n.useState([]),[He,se]=n.useState([]),[ge,H]=n.useState({}),[Oe,te]=n.useState(!1),[be,k]=n.useState(null),[Be,he]=n.useState(null),[Ue,Ze]=n.useState({}),[ke,Ge]=n.useState({}),[fe,Qe]=n.useState({}),[ae,Ve]=n.useState(""),[re,je]=n.useState(""),[ve,Ne]=n.useState(""),[ye,we]=n.useState(!1),[R,le]=n.useState(null),O=n.useMemo(()=>h.filter(s=>s.source==="marketplace"||s.provenance==="marketplace"),[h]),ne=n.useMemo(()=>h.filter(s=>s.source!=="marketplace"&&s.provenance!=="marketplace"),[h]),We=s=>{var l;const a=((l=ge[s])==null?void 0:l.skills)||[];return Math.max(1,Math.ceil(a.length/G))},Ce=(s,a)=>{Ze(l=>({...l,[s]:Math.max(0,Math.min(We(s)-1,a))}))},Xe=async()=>{var a,l,o;te(!0),k(null);const s=await u.skills.marketplaces.list();if(!s.success){k(s.error||t("skills.loadMarketplaceFail")),te(!1);return}ee(((a=s.data)==null?void 0:a.marketplaces)||[]),se(((l=s.data)==null?void 0:l.installed)||[]),H(((o=s.data)==null?void 0:o.indexes)||{}),te(!1)},Ye=async()=>{const s=re.trim();if(!s)return;we(!0),k(null);const a=await u.skills.marketplaces.add({url:s,name:ve.trim()||void 0});if(a.success&&a.data){je(""),Ne("");const l=a.data.marketplace;ee(o=>[...o.filter(I=>I.id!==l.id),l]),H(o=>({...o,[l.id]:a.data.index}))}else k(a.error||t("skills.addFail"));we(!1)},Se=async s=>{k(null);const a=await u.skills.marketplaces.refresh(s);a.success&&a.data?H(l=>({...l,[s]:a.data.index})):k(a.error||t("skills.loadMarketplaceFail"))},Je=async s=>{await u.skills.marketplaces.remove(s),ee(a=>a.filter(l=>l.id!==s)),H(a=>{const l={...a};return delete l[s],l})},Ke=async(s,a)=>{he(a),k(null);const l=await u.skills.marketplaces.install(s,a);l.success&&l.data?(se(o=>[...o.filter(I=>I!==l.data.id),l.data.id]),await M()):k(l.error||t("skills.installFail")),he(null)},es=async s=>{k(null);const a=await u.skills.delete(s);a.success?(se(l=>l.filter(o=>o!==s)),await M()):k(a.error||t("skills.uninstallFail")),le(null)},M=async()=>{q(!0),D(null);const s=await u.skills.list();if(s.success){const a=Array.isArray(s.data)?s.data:[];x(a),s.data!==null&&s.data!==void 0&&!Array.isArray(s.data)&&D("服务端返回的技能数据格式异常")}else D(s.error||t("skills.loadFailedFallback"));q(!1)};n.useEffect(()=>{M(),Xe()},[]);const ie=n.useMemo(()=>{const s=w.trim().toLowerCase();return s?ne.filter(a=>[a.id,a.name,a.description,a.category,...a.tags||[]].join(" ").toLowerCase().includes(s)):ne},[ne,w]),ze=()=>{F(null),r(oe),z(null),S(!0)},Me=s=>{F(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),S(!0)},ss=async()=>{const s=d.id.trim();if(!s){z(t("skills.fieldId")+" is required");return}v(!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:Re(d.tags),requiredTools:Re(d.requiredTools)},l=T?await u.skills.update(T,a):await u.skills.create(a);l.success?(S(!1),F(null),r(oe),await M()):z(l.error||t("skills.save")),v(!1)},Ie=async s=>{(await u.skills.toggle(s.id,!s.enabled)).success&&x(l=>l.map(o=>o.id===s.id?{...o,enabled:!o.enabled}:o))},ts=async s=>{ue(!0),J(null);try{const a=await s.text(),l=await u.skills.import({fileName:s.name,content:a});l.success?(Y(!1),await M()):J(l.error||t("skills.import"))}catch(a){J(a instanceof Error?a.message:t("skills.import"))}finally{ue(!1),_.current&&(_.current.value="")}};if(f)return e.jsx("div",{className:"flex-1 overflow-y-auto p-4",role:"status",children:e.jsx(ms,{count:5})});if(y)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(xe,{size:32,className:"mx-auto mb-2 text-accent-red"}),e.jsx("p",{className:"text-accent-red mb-4",children:y}),e.jsx(j,{variant:"accent",onClick:M,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(Fe,{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(p==="marketplace"),children:[e.jsx(Pe,{size:14}),t("skills.marketplaceTab")]}),e.jsxs("button",{onClick:()=>b("mine"),className:B(p==="mine"),children:[e.jsx(Fe,{size:14}),t("skills.mineTab")]}),e.jsxs("button",{onClick:()=>b("installed"),className:B(p==="installed"),children:[e.jsx(W,{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(p==="workshop"),children:[e.jsx($e,{size:14}),t("skills.workshopTab")]})]})]}),be&&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(xe,{size:14,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:be}),e.jsx("button",{onClick:()=>k(null),className:"shrink-0 p-0.5 rounded hover:bg-dark-hover",children:e.jsx(X,{size:14})})]}),p==="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:re,onChange:s=>je(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:ve,onChange:s=>Ne(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.jsx(j,{variant:"accent",onClick:Ye,disabled:!re.trim(),loading:ye,leftIcon:e.jsx(Q,{size:14}),children:t(ye?"skills.adding":"skills.addMarketplace")})]}),e.jsx("div",{className:"text-xs text-dark-muted",children:t("skills.marketplaceHint")}),e.jsx(gs,{marketplaces:K,value:ae,onChange:Ve}),Oe?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(L,{size:24,className:"animate-spin text-accent-blue"})}):e.jsxs(e.Fragment,{children:[K.length===0&&e.jsx("div",{className:"text-sm text-dark-muted py-10 text-center",children:t("skills.noMarketplaces")}),K.filter(s=>!ae||s.domain===ae).map(s=>{const a=ge[s.id],l=(a==null?void 0:a.skills)||[],o=(ke[s.id]||"").trim().toLowerCase(),I=fe[s.id]||"",Te=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))&&(!I||i.category===I)),Z=Math.max(1,Math.ceil(U.length/G)),E=Math.min(Ue[s.id]||0,Z-1),as=U.slice(E*G,(E+1)*G),rs=o||I?`${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-badge 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:rs})}),e.jsx("button",{onClick:()=>Se(s.id),className:"p-1.5 rounded hover:bg-dark-hover",title:t("skills.refreshMarketplace"),children:e.jsx(L,{size:14})}),!s.builtin&&e.jsx("button",{onClick:()=>Je(s.id),className:"p-1.5 rounded hover:bg-dark-hover text-accent-red",title:t("skills.removeMarketplace"),children:e.jsx(X,{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:()=>Se(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(L,{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:ke[s.id]||"",onChange:i=>Ge(N=>({...N,[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"}),Te.length>1&&e.jsxs("select",{value:fe[s.id]||"",onChange:i=>Qe(N=>({...N,[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")}),Te.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:as.map(i=>{const N=He.includes(i.id),ce=Be===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:[e.jsx(V,{icon:i.icon})," ",i.name]}),i.risk==="critical"&&e.jsx("span",{className:"text-badge 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:N||ce,onClick:()=>Ke(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 ${N?"bg-accent-green/20 text-accent-green":"bg-accent-blue text-accent-fg hover:bg-accent-blue/80"}`,children:[N?e.jsx(W,{size:12}):ce?e.jsx(L,{size:12,className:"animate-spin"}):e.jsx(ls,{size:12}),t(N?"skills.installed":ce?"skills.installing":"skills.installSkill")]})]}),i.description&&e.jsx("p",{className:"text-xs text-dark-muted line-clamp-2",children:i.description})]},i.id)})}),Z>1&&e.jsxs("div",{className:"flex items-center justify-center gap-3 pb-3 text-xs text-dark-muted",children:[e.jsxs("button",{disabled:E<=0,onClick:()=>Ce(s.id,E-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(ns,{size:14}),t("skills.pagePrev")]}),e.jsx("span",{className:"whitespace-nowrap",children:t("skills.pageOf",{page:E+1,total:Z})}),e.jsxs("button",{disabled:E>=Z-1,onClick:()=>Ce(s.id,E+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(is,{size:14})]})]})]})]})]},s.id)})]})]}),p==="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.jsx(j,{variant:"accent",leftIcon:e.jsx(Pe,{size:14}),onClick:()=>b("marketplace"),children: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:[e.jsx(V,{icon:s.icon})," ",s.name]}),e.jsxs("div",{className:"text-xs text-dark-muted truncate",children:[s.id," · ",s.category]})]}),e.jsxs("button",{onClick:()=>Ie(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(Ae,{size:14}):e.jsx(Le,{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-badge 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(qe,{size:12}),t("skills.use")]}),e.jsxs("button",{onClick:()=>Me(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(de,{size:12}),t("skills.edit")]}),e.jsxs("button",{onClick:()=>le(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(cs,{size:12}),t("skills.uninstall")]})]})]})]},s.id))})}),p==="workshop"&&e.jsx(us,{}),p==="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=>g(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:ie.length})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx(j,{variant:"accent",leftIcon:e.jsx(Q,{size:14}),onClick:ze,children:t("skills.new")}),e.jsxs("button",{onClick:()=>Y(!0),className:"flex items-center gap-2 px-3 py-2 bg-dark-surface border border-dark-border rounded-lg",children:[e.jsx(ds,{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(L,{size:14}),t("skills.refresh")]})]})]}),ie.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.jsx(j,{variant:"accent",leftIcon:e.jsx(Q,{size:14}),onClick:ze,children: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:ie.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:[e.jsx(V,{icon:s.icon})," ",s.name]}),e.jsx("div",{className:"text-xs text-dark-muted truncate",children:s.id})]}),e.jsxs("button",{onClick:()=>Ie(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(Ae,{size:14}):e.jsx(Le,{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-badge 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(qe,{size:12}),t("skills.use")]}),e.jsxs("button",{onClick:()=>Me(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(de,{size:12}),t("skills.edit")]})]})]})]},s.id))})})]}),e.jsx(De,{isOpen:C,onClose:()=>S(!1),title:t(T?"skills.edit":"skills.new"),size:"xl",children:e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(A,{label:t("skills.fieldId"),value:d.id,onChange:s=>r(a=>({...a,id:s}))}),e.jsx(A,{label:t("skills.fieldName"),value:d.name,onChange:s=>r(a=>({...a,name:s}))}),e.jsx(A,{label:t("skills.fieldCategory"),value:d.category,onChange:s=>r(a=>({...a,category:s}))}),e.jsx(A,{label:t("skills.fieldTrigger"),value:d.trigger,onChange:s=>r(a=>({...a,trigger:s}))}),e.jsx(A,{label:t("skills.tags"),value:d.tags,onChange:s=>r(a=>({...a,tags:s}))}),e.jsx(A,{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(j,{variant:"secondary",onClick:()=>S(!1),children:t("skills.cancel")}),e.jsx(j,{variant:"accent",leftIcon:e.jsx(de,{size:14}),loading:P,onClick:ss,children:t("skills.save")})]})]})}),e.jsx(De,{isOpen:m,onClose:()=>Y(!1),title:t("skills.importTitle"),size:"md",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{ref:_,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&&ts(a)}}),e.jsxs("button",{onClick:()=>{var s;return(s=_.current)==null?void 0:s.click()},disabled:_e,className:"w-full py-6 border border-dashed border-dark-border rounded-lg flex items-center justify-center gap-2",children:[e.jsx(os,{size:16}),t("skills.chooseFile")]}),pe&&e.jsx("div",{className:"text-sm text-accent-red",children:pe}),e.jsx("div",{className:"text-xs text-dark-muted",children:t("skills.importHint")})]})}),e.jsx(xs,{isOpen:R!==null,onClose:()=>le(null),onConfirm:()=>{R&&es(R)},title:t("skills.uninstall"),message:t("skills.uninstallConfirm",{name:((Ee=O.find(s=>s.id===R))==null?void 0:Ee.name)||R||""}),confirmText:t("skills.uninstall"),cancelText:t("skills.cancel"),variant:"danger"})]})}function Re(c){return c.split(",").map(t=>t.trim()).filter(Boolean)}function A({label:c,value:t,onChange:p}){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=>p(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{ys as SkillsView};
@@ -0,0 +1 @@
1
+ import{j as e}from"./markdown-BWXjRrSw.js";import{a as u,ai as Ze,aj as oe,h as et,k as xs,X as hs,I as At,ak as Tt,a2 as fs,al as bs,D as gs,am as ks,an as zt,ao as le,w as Ie,L as tt,ap as De,e as ze,d as Ee,s as ie,A as js,S as Ns,z as vt,u as vs,y as ys,p as ws}from"./icons-Bm_ZzSAy.js";import{u as D,f as I,k as N,B as q,a as w,l as Cs,M as Ss,C as yt}from"./index-CeeLdENM.js";import{D as As}from"./Drawer-CjAgqH3B.js";import"./react-vendor-C0HIWSpf.js";import"./state-Kfon1nTr.js";import"./panels-BQOvnbWH.js";const Ts=new Set(["read_file","grep","glob","list_dir","web_fetch","web_search","git_status","git_diff","git_log","code_intel_lookup","lsp_diagnostics","artifact_query","artifact_read"]),Qe=new Set(["write_file","edit_file","file_delete","apply_patch","bash","git_commit","git_apply_patch","notebook_edit","git_branch","git_pr"]);function Lt(a){const t=(a.metadata??{}).primitive,n=t==null?void 0:t.options;return Array.isArray(n==null?void 0:n.tools)?n.tools.map(String):null}const zs=new Set(["explore","plan","verify"]);function Ls(a){const s=Lt(a);if(s!==null)return s;const t=a.metadata??{},n=typeof t.role=="string"?t.role:a.type;return zs.has(n)?[]:null}function Es(a){if(Ds(a))return!1;const s=Ls(a);return s===null?!0:s.length===0?!1:s.some(t=>Qe.has(t))}const Is=new Set(["parallel","pipeline","phase","condition","loop","synthesize","checkpoint","retry"]);function Ds(a){const t=(a.metadata??{}).primitive,n=typeof(t==null?void 0:t.kind)=="string"?t.kind:void 0;return n===void 0?Is.has(a.type):n!=="agent"&&n!=="tool"}function Oe(a){const s=[];for(const t of a)s.push(t),Array.isArray(t.children)&&t.children.length&&s.push(...Oe(t.children));return s}function Et(a){const s=new Map(a.map(i=>[i.id,i])),t=new Set,n=[];let d=[...a];for(;d.length>0;){const i=d.filter(o=>(o.dependencies??[]).every(r=>t.has(r)||!s.has(r)));if(i.length===0){n.push(d);break}n.push(i);for(const o of i)t.add(o.id);d=d.filter(o=>!t.has(o.id))}return n}function Os(a){return Et(a).reduce((s,t)=>Math.max(s,t.length),1)}function It(a){const s=a.children??[];if(s.length===0)return 1;const t=Math.max(...s.map(n=>It(n)));return a.type==="parallel"?Math.max(s.length,t):Math.max(1,t)}function Rs(a){const s=Os(a),t=a.reduce((n,d)=>Math.max(n,It(d)),1);return Math.max(s,t)}function Dt(a,s=0){if(!a||!Array.isArray(a.nodes)||a.nodes.length===0)return{readonly:!0,risk:"low",maxParallel:0,nodeCount:0,inputCount:s||0,roles:[]};const t=Oe(a.nodes),n=[];let d=!0;for(const o of t){const r=typeof(o.metadata??{}).role=="string"?String(o.metadata.role):o.type;n.includes(r)||n.push(r),Es(o)&&(d=!1)}return{readonly:d,risk:d?"low":"medium",maxParallel:Rs(a.nodes),nodeCount:t.length,inputCount:s||0,roles:n}}const st={parallel:"templates.nodeParallel",pipeline:"templates.nodePipeline",phase:"templates.nodePhase",synthesize:"templates.nodeSynthesize",condition:"templates.nodeCondition",loop:"templates.nodeLoop",checkpoint:"templates.nodeCheckpoint"},wt={retry:"templates.nodeRetry"};function Ot(a){var n;const s=(n=a.metadata)==null?void 0:n.primitive,t=typeof(s==null?void 0:s.kind)=="string"?s.kind:void 0;return t&&wt[t]?wt[t]:st[a.type]}const Ms={explore:"info",plan:"default",execute:"success",verify:"warning",summarize:"info",generic:"default"},_s={explore:"templates.roleExplore",plan:"templates.rolePlan",execute:"templates.roleExecute",verify:"templates.roleVerify",summarize:"templates.roleSummarize",generic:"templates.roleGeneric"},Ps={explore:"text-accent-blue",plan:"text-dark-muted",execute:"text-accent-green",verify:"text-accent-yellow",summarize:"text-dark-muted"};function $s(a){var t;const s=(t=a.metadata)==null?void 0:t.role;return typeof s=="string"?s:a.type}function Fs({definition:a}){const{t:s}=D(),t=u.useMemo(()=>Oe(a.nodes||[]),[a.nodes]),n=u.useMemo(()=>Et(t),[t]),d=u.useMemo(()=>new Map(t.map(i=>[i.id,i])),[t]);return n.length===0?e.jsx("p",{className:"text-xs text-dark-muted",children:s("templates.noNodes")}):e.jsxs("div",{className:"space-y-0",children:[n.map((i,o)=>e.jsxs("div",{className:"flex",children:[e.jsxs("div",{className:"flex flex-col items-center shrink-0 w-6 mr-2",children:[o>0&&e.jsx("span",{className:"w-px h-3 bg-dark-border/60"}),i.length>1&&e.jsx("span",{className:"inline-flex items-center gap-0.5 mt-0.5 mb-0.5",children:i.map((r,c)=>e.jsx("span",{className:"w-[2px] h-2 rounded bg-accent-blue/40"},c))}),o<n.length-1&&e.jsx("span",{className:"w-px flex-1 bg-dark-border/60 my-0.5"})]}),e.jsx("div",{className:I("flex-1 min-w-0",i.length>1?"grid grid-cols-2 gap-2 py-1":"py-0.5"),children:i.map(r=>{const c=$s(r),h=Ps[c]||"text-dark-muted",f=(r.dependencies??[]).map(g=>{var v;return((v=d.get(g))==null?void 0:v.title)||g}),j=Ot(r);return e.jsxs("div",{className:"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(Ze,{size:12,className:I("shrink-0",h)}),e.jsx("span",{className:"text-xs font-medium text-dark-text truncate flex-1",title:r.title,children:r.title}),e.jsx(N,{size:"sm",variant:Ms[c]||"default",children:s(j||_s[c]||"templates.roleGeneric")})]}),r.description&&e.jsx("p",{className:"px-2.5 pb-1.5 text-meta text-dark-muted leading-relaxed",children:r.description}),f.length>0&&e.jsx("div",{className:"px-2.5 pb-1.5 flex items-center flex-wrap gap-1",children:f.map(g=>e.jsxs("span",{className:"text-badge px-1.5 py-0.5 rounded bg-dark-hover text-dark-muted truncate max-w-[14rem]",children:["← ",g]},g))})]},r.id)})})]},o)),e.jsxs("div",{className:"flex items-center gap-3 mt-3 pt-2 border-t border-dark-border text-badge text-dark-muted",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(oe,{size:11,className:"text-accent-yellow"})," ",s("templates.roleVerify")]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ze,{size:11,className:"text-accent-blue"})," ",s("templates.roleExplore")]})]})]})}function Ge(a){var t;const s=(t=a.metadata)==null?void 0:t.role;return typeof s=="string"?s:a.type}function Vs({definition:a}){const{t:s}=D(),t=u.useMemo(()=>Oe(a.nodes||[]),[a.nodes]),{readonly:n,allowList:d,toolSet:i}=u.useMemo(()=>{const r=new Set;let c=!1;for(const f of t){const j=Lt(f);if(j!==null){for(const g of j)r.add(g);j.some(g=>Qe.has(g))&&(c=!0)}else Ge(f)!=="explore"&&Ge(f)!=="plan"&&Ge(f)!=="verify"&&(c=!0)}const h=[...r].filter(f=>Ts.has(f));return{readonly:!c,allowList:h,toolSet:r}},[t]),o=u.useMemo(()=>[...Qe].filter(r=>!i.has(r)),[i]);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[n?e.jsx(oe,{size:16,className:"text-accent-green"}):e.jsx(et,{size:16,className:"text-accent-yellow"}),e.jsx("span",{className:"text-sm text-dark-text",children:s(n?"templates.readonly":"templates.writable")}),e.jsx(N,{size:"sm",variant:n?"success":"warning",children:s(n?"templates.riskLow":"templates.riskMedium")})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"rounded-lg border border-dark-border p-3",children:[e.jsx("div",{className:"text-meta uppercase tracking-wider text-dark-muted/70 mb-2",children:s("templates.allowDuringReplay")}),d.length>0?e.jsx("ul",{className:"space-y-1",children:d.map(r=>e.jsxs("li",{className:"flex items-center gap-1.5 text-xs text-dark-muted",children:[e.jsx(xs,{size:12,className:"text-accent-green shrink-0"})," ",r]},r))}):e.jsx("p",{className:"text-xs text-dark-muted/70",children:s("templates.noToolsRestriction")})]}),e.jsxs("div",{className:"rounded-lg border border-dark-border p-3",children:[e.jsx("div",{className:"text-meta uppercase tracking-wider text-dark-muted/70 mb-2",children:s("templates.denyDuringReplay")}),n?e.jsx("ul",{className:"space-y-1",children:o.map(r=>e.jsxs("li",{className:"flex items-center gap-1.5 text-xs text-dark-muted",children:[e.jsx(hs,{size:12,className:"text-accent-red shrink-0"})," ",r]},r))}):e.jsx("p",{className:"text-xs text-dark-muted/70",children:"—"})]})]}),i.size>0&&e.jsxs("div",{className:"rounded-lg border border-dark-border p-3",children:[e.jsx("div",{className:"text-meta uppercase tracking-wider text-dark-muted/70 mb-1.5",children:s("templates.toolWhitelist")}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:[...i].map(r=>e.jsx("span",{className:"text-badge px-1.5 py-0.5 rounded bg-dark-hover text-dark-muted",children:r},r))})]})]})}function Js(a){const{t:s,detail:t,sourceLabelKey:n,detailTab:d,onTabChange:i,onReplay:o,onPreflight:r,onEdit:c,onDelete:h,onExport:f,onCopyId:j,onToggleAdvanced:g,onToggleVersions:v,onReRecord:_,versions:x,historyView:A,onLoadVersion:V,onClearHistory:ce,onRefresh:me,menuOpen:U,setMenuOpen:Y,saveMsg:G}=a,C=u.useMemo(()=>{var T;return Dt(t.definition,((T=t.inputs)==null?void 0:T.length)??0)},[t.definition,t.inputs]),Z=n?s(n):t.source.type,J=C.inputCount,Q=[{id:"overview",label:s("templates.overviewTab")},{id:"flow",label:s("templates.flowTab")},{id:"permissions",label:s("templates.permissionsTab")},{id:"history",label:s("templates.historyTab")}];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-start gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h2",{className:"text-lg font-semibold text-dark-text truncate",children:t.name}),e.jsxs(N,{variant:"info",children:["v",t.version]}),t.status==="degraded"&&e.jsxs(N,{variant:"warning",children:["⚠ ",s("templates.degradedBadge")]}),e.jsx(N,{variant:t.source.type==="saved"?"success":"default",children:Z})]}),t.description&&e.jsx("p",{className:"text-sm text-dark-muted mt-1",children:t.description})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx(q,{variant:"accent",leftIcon:e.jsx(At,{className:"w-4 h-4"}),onClick:o,children:s("templates.replay")}),e.jsx(q,{variant:"secondary",leftIcon:e.jsx(Tt,{className:"w-4 h-4"}),onClick:r,children:s("templates.preflight")}),e.jsxs("button",{onClick:c,className:"px-3 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(fs,{className:"w-4 h-4"})," ",s("templates.edit")]}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:()=>Y(!U),className:"p-2 rounded-lg text-dark-muted hover:bg-dark-hover transition-colors","aria-label":s("templates.more"),children:e.jsx(bs,{className:"w-4 h-4"})}),U&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>Y(!1)}),e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-50 w-52 rounded-lg border border-dark-border bg-dark-surface shadow-xl p-1.5 space-y-0.5 text-compact",children:[e.jsx(re,{icon:e.jsx(gs,{size:13}),label:s("templates.exportJson"),onClick:f}),e.jsx(re,{icon:e.jsx(ks,{size:13}),label:s("templates.copyId"),onClick:j}),e.jsx(re,{icon:e.jsx(zt,{size:13}),label:s("templates.versionHistory"),onClick:v}),e.jsx(re,{icon:e.jsx(le,{size:13}),label:s("templates.advancedJson"),onClick:g}),e.jsx("div",{className:"border-t border-dark-border my-1"}),e.jsx(re,{icon:e.jsx(Ie,{size:13}),label:s("templates.deleteTemplate"),onClick:h,danger:!0})]})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.category&&e.jsxs(N,{size:"sm",variant:"info",className:"gap-1",children:[e.jsx(tt,{size:11}),t.category]}),e.jsxs(N,{size:"sm",variant:C.readonly?"success":"warning",className:"gap-1",children:[C.readonly?e.jsx(oe,{size:11}):e.jsx(et,{size:11}),C.readonly?`${s("templates.readonly")} · ${s("templates.riskLow")}`:`${s("templates.writable")} · ${s("templates.riskMedium")}`]}),e.jsxs(N,{size:"sm",variant:"default",className:"gap-1",children:[e.jsx(De,{size:11}),C.maxParallel>1?s("templates.parallelCount",{n:C.nodeCount,p:C.maxParallel}):s("templates.stepCount",{n:C.nodeCount})]}),e.jsxs(N,{size:"sm",variant:"default",className:"gap-1",children:[e.jsx(ze,{size:11}),J>0?s("templates.confirmCount",{n:J}):s("templates.confirmCountNone")]}),G&&e.jsx("span",{className:"text-xs text-dark-muted",children:G})]}),e.jsxs("div",{className:"flex items-center gap-1 border-b border-dark-border pb-1.5",children:[Q.map(T=>e.jsx("button",{onClick:()=>i(T.id),className:I("px-3 py-1.5 rounded-md text-xs transition-colors",d===T.id?"bg-accent-blue/10 text-accent-blue font-medium":"text-dark-muted hover:text-dark-text hover:bg-dark-hover"),children:T.label},T.id)),e.jsx("div",{className:"ml-auto flex items-center gap-1",children:e.jsx("button",{onClick:me,className:"p-1.5 rounded-md text-dark-muted hover:text-dark-text hover:bg-dark-hover",title:s("templates.refresh"),children:e.jsx(Ee,{className:"w-3.5 h-3.5"})})})]}),e.jsxs("div",{children:[d==="overview"&&e.jsx(Hs,{t:s,detail:t,meta:C,inputCount:J}),d==="flow"&&e.jsx(Fs,{definition:t.definition}),d==="permissions"&&e.jsx(Vs,{definition:t.definition}),d==="history"&&e.jsx(Bs,{t:s,versions:x,currentVersion:t.version,historyView:A,onLoadVersion:V,onClearHistory:ce,onReRecord:_})]})]})})}function re({icon:a,label:s,onClick:t,danger:n}){return e.jsxs("button",{onClick:t,className:I("w-full flex items-center gap-2 px-2 py-1.5 rounded-md hover:bg-dark-hover text-left transition-colors",n?"text-accent-red hover:text-accent-red":"text-dark-muted hover:text-dark-text"),children:[a," ",s]})}function Hs({t:a,detail:s,meta:t,inputCount:n}){const d=s.inputs??[],i=s.outputs??[];return e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-dark-border p-3",children:[e.jsx("div",{className:"text-meta uppercase tracking-wider text-dark-muted/70 mb-2",children:a("templates.inputsNeeded")}),n>0?e.jsx("ul",{className:"space-y-1.5",children:d.map(o=>e.jsxs("li",{className:"flex items-center justify-between gap-2 text-xs",children:[e.jsx("span",{className:"text-dark-text truncate",children:o.label||o.name}),o.required&&e.jsx("span",{className:"text-accent-red shrink-0",children:"*"})]},o.name))}):e.jsx("p",{className:"text-xs text-dark-muted/70",children:a("templates.confirmCountNone")})]}),e.jsxs("div",{className:"rounded-lg border border-dark-border p-3",children:[e.jsx("div",{className:"text-meta uppercase tracking-wider text-dark-muted/70 mb-2",children:a("templates.outputsProduced")}),i.length>0?e.jsx("ul",{className:"space-y-1.5",children:i.map(o=>e.jsxs("li",{className:"flex items-center justify-between gap-2 text-xs",children:[e.jsx("span",{className:"text-dark-text truncate",children:o.label||o.name}),o.kind&&e.jsx(N,{size:"sm",children:o.kind})]},o.name))}):e.jsx("p",{className:"text-xs text-dark-muted/70",children:a("templates.noOutputsDeclared")})]}),e.jsxs("div",{className:"col-span-2 text-meta text-dark-muted/70",children:[a("templates.replayNewSession")," · ",t.readonly?a("templates.readonlyHint"):a("templates.writable")]})]})}function Bs({t:a,versions:s,currentVersion:t,historyView:n,onLoadVersion:d,onClearHistory:i,onReRecord:o}){return e.jsxs("div",{className:"space-y-2",children:[s.length===0&&e.jsx("p",{className:"text-xs text-dark-muted/70",children:a("templates.noVersions")}),[...s].reverse().map(r=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-dark-border px-3 py-2",children:[e.jsxs(N,{variant:r===t?"success":"default",children:["v",r]}),r===t&&e.jsx("span",{className:"text-meta text-accent-green",children:a("templates.statusReady")}),e.jsx("span",{className:"text-meta text-dark-muted/60",children:r===t?a("templates.reRecordHint",{v:r}):""}),e.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>d(r),className:"text-meta px-2 py-1 rounded border border-dark-border hover:border-accent-blue/50 transition-colors",children:a("templates.compare")}),r!==t&&e.jsxs("button",{onClick:()=>o(r),className:"text-meta px-2 py-1 rounded border border-accent-blue/40 text-accent-blue hover:bg-accent-blue/10 transition-colors inline-flex items-center gap-1",children:[e.jsx(Ee,{className:"w-3 h-3"})," ",a("templates.reRecordAsNew")]})]})]},r)),n&&e.jsxs("div",{className:"rounded-lg border border-dark-border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-xs text-dark-muted",children:[a("templates.viewingVersion")," v",n.version]}),e.jsx("button",{onClick:i,className:"text-meta text-dark-muted hover:text-dark-text",children:a("templates.cancel")})]}),e.jsx("pre",{className:"p-3 rounded-lg bg-dark-bg text-badge font-mono text-dark-muted max-h-60 overflow-y-auto custom-scrollbar",children:JSON.stringify({version:n.version,inputs:n.inputs,definition:n.definition},null,2)})]})]})}const Ks={explore:"info",plan:"default",execute:"success",verify:"warning",summarize:"info",generic:"default"},Ws={explore:"templates.roleExplore",plan:"templates.rolePlan",execute:"templates.roleExecute",verify:"templates.roleVerify",summarize:"templates.roleSummarize",generic:"templates.roleGeneric"};function qs(a){var t;const s=(t=a.metadata)==null?void 0:t.role;return typeof s=="string"?s:a.type}function Us(a){const s=new Map(a.map(i=>[i.id,i])),t=new Set,n=[];let d=[...a];for(;d.length>0;){const i=d.filter(o=>(o.dependencies??[]).every(r=>t.has(r)||!s.has(r)));if(i.length===0){n.push(...d);break}for(const o of i)n.push(o),t.add(o.id);d=d.filter(o=>!t.has(o.id))}return n}function de(a){const s=[];for(const t of a)s.push(t),Array.isArray(t.children)&&t.children.length&&s.push(...de(t.children));return s}function Rt(a,s){for(const t of a)s.set(t.id,s.size+1),Array.isArray(t.children)&&t.children.length&&Rt(t.children,s)}function Mt({nodes:a,allById:s,indexById:t}){const{t:n}=D();return e.jsx(e.Fragment,{children:a.map((d,i)=>{const o=qs(d),r=Ks[o]||"default",c=Ot(d),h=Ws[o],f=c?n(c):h?n(h):o,j=(d.dependencies??[]).map(g=>{var v;return((v=s.get(g))==null?void 0:v.title)||g}).filter((g,v,_)=>_.indexOf(g)===v);return e.jsxs("div",{children:[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-badge font-semibold shrink-0",children:t.get(d.id)??i+1}),i<a.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(Ze,{size:12,className:I("shrink-0",o==="verify"?"text-accent-yellow":o==="explore"?"text-accent-blue":"text-dark-muted")}),e.jsx("span",{className:"text-xs font-medium text-dark-text truncate flex-1",children:d.title}),e.jsx(N,{size:"sm",variant:r,children:f})]}),d.description&&e.jsx("p",{className:"px-2.5 pb-1.5 text-meta text-dark-muted leading-relaxed",children:d.description}),j.length>0&&e.jsxs("div",{className:"px-2.5 pb-2 flex items-center flex-wrap gap-1",children:[e.jsx(De,{size:11,className:"text-dark-muted/60 shrink-0"}),j.map(g=>e.jsx("span",{className:"text-badge px-1.5 py-0.5 rounded bg-dark-hover text-dark-muted truncate max-w-[16rem]",children:g},g))]})]})]}),Array.isArray(d.children)&&d.children.length>0&&e.jsx("div",{className:"ml-3 pl-3 border-l-2 border-dark-border/60",children:e.jsx(Mt,{nodes:d.children,allById:s,indexById:t})})]},d.id)})})}function Ys({definition:a}){const{t:s}=D(),t=u.useMemo(()=>Us(a.nodes||[]),[a.nodes]),n=u.useMemo(()=>new Map(de(a.nodes||[]).map(i=>[i.id,i])),[a.nodes]),d=u.useMemo(()=>{const i=new Map;return Rt(a.nodes||[],i),i},[a.nodes]);return t.length===0?e.jsx("p",{className:"text-xs text-dark-muted",children:s("templates.noNodes")}):e.jsx("div",{className:"space-y-0",children:e.jsx(Mt,{nodes:t,allById:n,indexById:d})})}function _t(a){const s=[];for(const t of a)s.push(t),Array.isArray(t.children)&&t.children.length&&s.push(..._t(t.children));return s}function Gs(a,s){const t=new Set,n=(d,i)=>{for(const o of d){const r=i||o.id===s;r&&t.add(o.id),Array.isArray(o.children)&&o.children.length&&n(o.children,r)}};return n(a,!1),t}function Zs(a){const s=new Set(_t(a).map(n=>n.id));let t=1;for(;s.has(`task-${t}`);)t++;return`task-${t}`}function Le(a,s,t){return a.map(n=>n.id===s?{...n,...t}:Array.isArray(n.children)&&n.children.length?{...n,children:Le(n.children,s,t)}:n)}function Qs(a,s){const t=n=>n.filter(d=>d.id!==s).map(d=>({...d,dependencies:(d.dependencies??[]).filter(i=>i!==s),children:Array.isArray(d.children)&&d.children.length?t(d.children):d.children}));return t(a)}function Xe(a,s,t){const n=new Date().toISOString(),d={id:Zs(a),title:"",description:"",type:"task",status:"pending",dependencies:[],priority:5,createdAt:n,updatedAt:n};if(!s)return[...a,d];const i=o=>o.map(r=>r.id===s?{...r,children:[...Array.isArray(r.children)?r.children:[],d]}:Array.isArray(r.children)&&r.children.length?{...r,children:i(r.children)}:r);return i(a)}const Xs=["task","agent","parallel","pipeline","phase","condition","loop","checkpoint"],Pt=new Set(["parallel","pipeline","phase","condition","loop","checkpoint"]),ea=["string","number","select","boolean","folder","connector"];function ta(a){return st[a]??(a==="agent"?"templates.editorTypeAgent":"templates.editorTypeTask")}function sa(a,s){return Pt.has(s)?a(st[s]??s):a(ta(s))}function aa(a){const{t:s}=D(),{node:t,index:n,depth:d,depOptions:i,definition:o,onChange:r,onRemove:c,onAddChild:h,onDepAdd:f,onDepRemove:j}=a,g=t.dependencies??[],v=Array.isArray(t.children)&&t.children.length>0,_=Pt.has(t.type);return e.jsxs("div",{className:ra(d)+" rounded-lg border border-dark-border bg-dark-bg/60","data-node-id":t.id,children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5",children:[e.jsx("span",{className:"text-badge text-dark-muted/70 shrink-0 w-4 text-right",children:n}),e.jsx("input",{value:t.title,onChange:x=>r({title:x.target.value}),placeholder:s("templates.editorNodeTitlePlaceholder"),"aria-label":s("templates.editorNodeTitlePlaceholder"),className:"flex-1 min-w-[120px] px-2 py-1 rounded-md bg-dark-surface border border-dark-border text-xs text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"}),e.jsx("span",{className:"text-badge font-mono text-dark-muted/50 shrink-0 hidden xl:inline",title:t.id,children:t.id}),e.jsx("select",{value:t.type,onChange:x=>r({type:x.target.value}),"aria-label":s("templates.editorInputType"),className:"shrink-0 px-1.5 py-1 rounded-md bg-dark-surface border border-dark-border text-meta text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue",children:Xs.map(x=>e.jsx("option",{value:x,children:sa(s,x)},x))}),e.jsx("button",{onClick:c,className:"p-1 rounded-md text-dark-muted hover:text-accent-red hover:bg-dark-hover transition-colors shrink-0",title:s("templates.editorDeleteNode"),"aria-label":`${s("templates.editorDeleteNode")} ${t.title||t.id}`,children:e.jsx(Ie,{size:12})})]}),e.jsxs("div",{className:"px-2.5 pb-2 space-y-1.5",children:[e.jsx("textarea",{value:t.description,onChange:x=>r({description:x.target.value}),rows:2,placeholder:s("templates.editorNodeDescPlaceholder"),"aria-label":`${s("templates.editorNodeDescPlaceholder")} ${t.id}`,className:"w-full px-2 py-1 rounded-md bg-dark-surface border border-dark-border text-meta text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue placeholder:text-dark-muted/40"}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx(De,{size:11,className:"text-dark-muted/60 shrink-0"}),e.jsx("span",{className:"text-meta text-dark-muted shrink-0",children:s("templates.editorDepsLabel")}),g.length===0&&e.jsx("span",{className:"text-meta text-dark-muted/50",children:s("templates.editorDepsNone")}),g.map(x=>{const A=de(o.nodes??[]).find(V=>V.id===x);return e.jsxs("span",{className:"inline-flex items-center gap-1 text-meta px-1.5 py-0.5 rounded bg-accent-blue/10 text-accent-blue",children:[(A==null?void 0:A.title)||x,e.jsx("button",{onClick:()=>j(x),className:"hover:text-accent-red","aria-label":`${s("templates.editorDepsRemove")} ${(A==null?void 0:A.title)||x}`,children:"✕"})]},x)}),e.jsxs("select",{value:"",onChange:x=>{x.target.value&&f(x.target.value)},"aria-label":s("templates.editorDepsAdd"),className:"ml-auto px-1.5 py-0.5 rounded-md bg-dark-surface border border-dark-border text-meta text-dark-muted focus:outline-none focus:ring-1 focus:ring-accent-blue",children:[e.jsx("option",{value:"",children:s("templates.editorDepsAdd")}),i.filter(x=>!g.includes(x.id)).map(x=>e.jsx("option",{value:x.id,children:x.title||x.id},x.id))]}),e.jsxs("label",{className:"ml-auto inline-flex items-center gap-1 text-meta text-dark-muted",children:[s("templates.editorPriority"),e.jsx("input",{type:"number",value:t.priority,onChange:x=>r({priority:Number(x.target.value)||0}),className:"w-14 px-1.5 py-0.5 rounded-md bg-dark-surface border border-dark-border text-meta text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"})]})]})]}),(_||v)&&e.jsxs("div",{className:"ml-3 pl-3 pb-2 border-l-2 border-dark-border/60",children:[v&&e.jsx($t,{nodes:t.children,depth:d+1,definition:o,onChangeNodes:x=>r({children:x})}),e.jsxs("button",{onClick:h,className:"mt-1 inline-flex items-center gap-1 text-meta text-dark-muted hover:text-accent-blue transition-colors",children:[e.jsx(ie,{size:11})," ",s("templates.editorAddChild")]})]})]})}function ra(a){return a>0?"ml-3":""}function $t({nodes:a,depth:s,definition:t,onChangeNodes:n}){const{t:d}=D(),i=u.useMemo(()=>de(t.nodes??[]),[t.nodes]);return e.jsxs("div",{className:"space-y-2",children:[a.map((o,r)=>{const c=Gs(t.nodes??[],o.id),h=i.filter(f=>!c.has(f.id));return e.jsx("div",{children:e.jsx(aa,{node:o,index:r+1,depth:s,depOptions:h,definition:t,onChange:f=>n(Le(a,o.id,f)),onRemove:()=>n(Qs(a,o.id)),onAddChild:()=>n(Xe(a,o.id)),onDepAdd:f=>n(Le(a,o.id,{dependencies:[...o.dependencies??[],f]})),onDepRemove:f=>n(Le(a,o.id,{dependencies:(o.dependencies??[]).filter(j=>j!==f)}))})},o.id)}),a.length===0&&e.jsx("p",{className:"text-meta text-dark-muted/50",children:d("templates.editorEmptyLevel")})]})}function na({inputs:a,onChange:s}){const{t}=D(),n=(o,r)=>{s(a.map((c,h)=>h===o?{...c,...r}:c))},d=()=>{const o=new Set(a.map(c=>c.name));let r=1;for(;o.has(`input_${r}`);)r++;s([...a,{name:`input_${r}`,label:"",type:"string"}])},i=o=>s(a.filter((r,c)=>c!==o));return 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("span",{className:"text-xs font-semibold text-dark-text",children:t("templates.editorInputsTitle")}),e.jsx("span",{className:"ml-auto text-badge text-dark-muted",children:t("templates.confirmCount",{n:a.length})})]}),e.jsxs("div",{className:"p-2.5 space-y-1.5",children:[a.length===0&&e.jsx("p",{className:"text-meta text-dark-muted/50",children:t("templates.editorInputsEmpty")}),a.map((o,r)=>e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("input",{value:o.name,onChange:c=>n(r,{name:c.target.value}),placeholder:t("templates.editorInputName"),"aria-label":`${t("templates.editorInputName")} ${r+1}`,className:"w-28 px-2 py-1 rounded-md bg-dark-surface border border-dark-border text-meta font-mono text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"}),e.jsx("input",{value:o.label,onChange:c=>n(r,{label:c.target.value}),placeholder:t("templates.editorInputLabel"),"aria-label":`${t("templates.editorInputLabel")} ${r+1}`,className:"flex-1 min-w-[80px] px-2 py-1 rounded-md bg-dark-surface border border-dark-border text-meta text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"}),e.jsx("select",{value:o.type,onChange:c=>n(r,{type:c.target.value}),"aria-label":`${t("templates.editorInputType")} ${r+1}`,className:"px-1.5 py-1 rounded-md bg-dark-surface border border-dark-border text-meta text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue",children:ea.map(c=>e.jsx("option",{value:c,children:c},c))}),e.jsxs("label",{className:"inline-flex items-center gap-1 text-meta text-dark-muted shrink-0",children:[e.jsx("input",{type:"checkbox",checked:!!o.required,onChange:c=>n(r,{required:c.target.checked}),"aria-label":`${t("templates.editorInputRequired")} ${r+1}`}),t("templates.editorInputRequired")]}),e.jsx("input",{value:o.default===void 0||o.default===null?"":String(o.default),onChange:c=>{const h=c.target.value;if(h===""){n(r,{default:void 0});return}if(o.type==="number"&&Number.isFinite(Number(h))){n(r,{default:Number(h)});return}if(o.type==="boolean"){n(r,{default:h==="true"});return}n(r,{default:h})},placeholder:t("templates.editorInputDefault"),"aria-label":`${t("templates.editorInputDefault")} ${r+1}`,className:"w-24 px-2 py-1 rounded-md bg-dark-surface border border-dark-border text-meta text-dark-text focus:outline-none focus:ring-1 focus:ring-accent-blue"}),e.jsx("button",{onClick:()=>i(r),className:"p-1 rounded-md text-dark-muted hover:text-accent-red hover:bg-dark-hover transition-colors",title:t("templates.editorInputRemove"),"aria-label":`${t("templates.editorInputRemove")} ${o.name||r+1}`,children:e.jsx(Ie,{size:12})})]},r)),e.jsxs("button",{onClick:d,className:"inline-flex items-center gap-1 text-meta text-dark-muted hover:text-accent-blue transition-colors",children:[e.jsx(ie,{size:11})," ",t("templates.editorInputsAdd")]})]})]})}function Ct({definition:a,inputs:s,issues:t,onDefinitionChange:n,onInputsChange:d}){const{t:i}=D(),o=a.nodes??[],r=u.useMemo(()=>de(o),[o]),c=h=>{n({...a,nodes:h,updatedAt:new Date().toISOString()})};return e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-[3fr_2fr] gap-4 items-start",children:[e.jsxs("section",{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(tt,{size:13,className:"text-accent-blue shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-dark-text",children:i("templates.editorNodesTitle")}),e.jsx("span",{className:"text-badge text-dark-muted",children:i("templates.editorNodeCount",{n:r.length})}),e.jsxs("button",{onClick:()=>c(Xe(o)),className:"ml-auto inline-flex items-center gap-1 text-meta px-2 py-1 rounded-md border border-dark-border text-dark-muted hover:text-accent-blue hover:border-accent-blue/40 transition-colors",children:[e.jsx(ie,{size:11})," ",i("templates.editorAddNode")]})]}),e.jsxs("div",{className:"p-2.5 space-y-2",children:[e.jsx($t,{nodes:o,depth:0,definition:a,onChangeNodes:c}),o.length===0&&e.jsxs("button",{onClick:()=>c(Xe(o)),className:"w-full border border-dashed border-dark-border rounded-lg py-3 text-xs text-dark-muted hover:text-accent-blue hover:border-accent-blue/40 transition-colors",children:[e.jsx(ie,{size:12,className:"inline mr-1"})," ",i("templates.editorAddNode")]})]})]}),e.jsxs("section",{className:"space-y-3 min-w-0",children:[e.jsxs("div",{className:"border border-dark-border rounded-lg overflow-hidden",children:[e.jsx("div",{className:"px-3 py-2 bg-dark-surface border-b border-dark-border",children:e.jsx("span",{className:"text-xs font-semibold text-dark-text",children:i("templates.editorPreviewTitle")})}),e.jsx("div",{className:"p-2.5",children:e.jsx(Ys,{definition:a})})]}),t.length>0&&e.jsxs("div",{className:"rounded-lg border border-accent-yellow/40 bg-accent-yellow/5 px-3 py-2 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-accent-yellow font-medium",children:[e.jsx(js,{size:13})," ",i("templates.editorValidationIssues")]}),t.map((h,f)=>e.jsx("div",{className:"text-meta text-dark-muted",children:i(h.key,h.params)},f))]}),t.length===0&&r.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(N,{size:"sm",variant:"success",children:i("templates.editorValidationOk")}),e.jsx("span",{className:"text-meta text-dark-muted/60",children:i("templates.editorAdvancedSyncHint")})]}),e.jsx(na,{inputs:s,onChange:d})]})]})}const la=/<<input:([A-Za-z][A-Za-z0-9_]*)>>/g;function Ft(a){const s=[];for(const t of a)!t||typeof t!="object"||(s.push(t),Array.isArray(t.children)&&t.children.length&&s.push(...Ft(t.children)));return s}function ia(a){const s=new Map(a.map(i=>[i.id,i])),t=new Map(a.map(i=>[i.id,0]));for(const i of a)for(const o of i.dependencies||[])s.has(o)&&t.set(i.id,(t.get(i.id)??0)+1);const n=a.filter(i=>(t.get(i.id)??0)===0).map(i=>i.id);let d=0;for(;n.length;){const i=n.pop();d++;for(const o of a)if((o.dependencies||[]).includes(i)){const r=(t.get(o.id)??0)-1;t.set(o.id,r),r===0&&n.push(o.id)}}return d<a.length}function Te(a,s){const t=[];if(!a||!Array.isArray(a.nodes)||a.nodes.length===0)return t.push({key:"templates.validateNoNodes"}),t;const n=Ft(a.nodes);if(n.length===0)return t.push({key:"templates.validateNoNodes"}),t;const d=new Set;for(const c of n){if(typeof c.id!="string"||c.id===""){t.push({key:"templates.validateNodeNoId"});continue}d.has(c.id)&&t.push({key:"templates.validateDupNodeId",params:{id:c.id}}),d.add(c.id)}const i=new Map(n.map(c=>[c.id,c]));for(const c of n)for(const h of c.dependencies||[])i.has(h)||t.push({key:"templates.validateDanglingDep",params:{node:c.id,dep:h}});ia(n)&&t.push({key:"templates.validateCycle"});const o=new Set((s??[]).map(c=>c==null?void 0:c.name).filter(c=>typeof c=="string")),r=new Set;for(const c of n)for(const h of[c.title,c.description])if(typeof h=="string")for(const f of h.matchAll(la)){const j=f[1];j&&!o.has(j)&&r.add(j)}for(const c of r)t.push({key:"templates.validateUndeclaredInput",params:{name:c}});return t}function St(a,s,t){const n=new Date().toISOString();return{id:`wf_${Date.now()}`,title:a,description:"",nodes:[{id:"task-1",title:s,description:t,type:"task",status:"pending",dependencies:[],priority:5,createdAt:n,updatedAt:n}],createdAt:n,updatedAt:n}}function F(a){const s=(a.nodes??[]).map(t=>({...t,dependencies:Array.isArray(t.dependencies)?t.dependencies:[]}));return{...a,nodes:s}}const ne="__all__";function oa(a,s){if(!s)return;const t={};for(const n of a.inputs??[])n.type==="folder"&&n.default===void 0&&s&&(t[n.name]={value:s,label:s});return Object.keys(t).length>0?t:void 0}function da({t:a,detail:s,workspaceDir:t}){const n=u.useMemo(()=>{var d;return Dt(s.definition,((d=s.inputs)==null?void 0:d.length)??0)},[s.definition,s.inputs]);return n.nodeCount===0?null:e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-bg/50 px-3 py-2.5 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap text-xs",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 font-medium text-dark-text",children:[e.jsx(oe,{size:13,className:n.readonly?"text-accent-green":"text-accent-yellow"}),n.readonly?a("templates.readonly"):a("templates.writable")," · ",n.readonly?a("templates.riskLow"):a("templates.riskMedium")]}),e.jsx("span",{className:"text-dark-muted",children:n.maxParallel>1?a("templates.parallelCount",{n:n.nodeCount,p:n.maxParallel}):a("templates.stepCount",{n:n.nodeCount})}),e.jsx("span",{className:"text-dark-muted",children:n.inputCount>0?a("templates.confirmCount",{n:n.inputCount}):a("templates.confirmCountNone")})]}),t&&!n.readonly&&e.jsxs("div",{className:"text-meta text-dark-muted/70 truncate",title:t,children:[a("templates.writable"),": ",t]})]})}const ca={saved:"templates.sourceSaved",script:"templates.sourceScript",handwritten:"templates.sourceHandwritten"};function ga({onLaunch:a,workspaceDir:s}){const{t}=D(),[n,d]=u.useState([]),[i,o]=u.useState(null),[r,c]=u.useState(null),[h,f]=u.useState(!1),[j,g]=u.useState(""),[v,_]=u.useState(""),[x,A]=u.useState(ne),[V,ce]=u.useState(""),[me,U]=u.useState(""),[Y,G]=u.useState(""),[C,Z]=u.useState(""),[J,Q]=u.useState(""),[T,O]=u.useState(!1),[Re,S]=u.useState(""),[Vt,ue]=u.useState(!1),[Me,pe]=u.useState([]),[Jt,H]=u.useState(!1),[P,X]=u.useState(null),[B,R]=u.useState(null),[xe,ee]=u.useState(null),[Ht,at]=u.useState(!1),[Bt,he]=u.useState(!1),[rt,_e]=u.useState(null),[nt,lt]=u.useState(!1),te=u.useRef(i);te.current=i;const[it,fe]=u.useState(!0),[Kt,se]=u.useState("overview"),[Wt,$]=u.useState(!1),[Pe,be]=u.useState([]),[ge,ke]=u.useState(null),ot=()=>{r&&(be(r.inputs??[]),ke(F(r.definition))),fe(!1)},qt=l=>{ke(l),Q(JSON.stringify(l,null,2)),O(!0),S("")},Ut=l=>{be(l),Z(JSON.stringify(l,null,2)),O(!0),S("")},Yt=l=>{try{const m=JSON.parse(l);m&&typeof m=="object"&&Array.isArray(m.nodes)&&ke(F(m))}catch{}},Gt=l=>{try{const m=JSON.parse(l);Array.isArray(m)&&be(m)}catch{}},$e=u.useMemo(()=>Te(ge??void 0,Pe),[ge,Pe]),[Zt,je]=u.useState(!1),[Fe,Ve]=u.useState(""),[dt,Je]=u.useState(""),[ct,mt]=u.useState("general"),[ut,Ne]=u.useState("[]"),[pt,ve]=u.useState(()=>JSON.stringify(St(t("templates.starterTitle"),t("templates.starterNodeTitle"),t("templates.starterNodeDesc")),null,2)),[xt,z]=u.useState(""),[He,ye]=u.useState([]),[we,Ce]=u.useState(null),[Qt,Be]=u.useState(!1),[Ke,Se]=u.useState(!1),[We,ht]=u.useState(""),[Ae,qe]=u.useState(!1),[ft,K]=u.useState(""),Xt=()=>{const l=St(t("templates.starterTitle"),t("templates.starterNodeTitle"),t("templates.starterNodeDesc"));Ve(""),Je(""),mt("general"),Ne("[]"),ve(JSON.stringify(l,null,2)),Ce(l),ye([]),Be(!1),z(""),Se(!1),ht(""),qe(!1),K(""),je(!0)},es=async()=>{if(!We.trim()){K(t("templates.aiPromptRequired"));return}qe(!0),K("");try{const l=await w.workflows.synthesize(We.trim());if(l.success&&l.data){const m=F(l.data);Ve(l.data.title||""),Je(l.data.description||""),Ce(m),ye([]),Ne("[]"),ve(JSON.stringify(m,null,2)),Be(!1),Se(!1),z("")}else K(l.error||t("templates.aiDraftFailed"))}catch(l){K(l instanceof Error?l.message:String(l))}finally{qe(!1)}},ts=l=>{Ce(l),ve(JSON.stringify(l,null,2)),z("")},ss=l=>{ye(l),Ne(JSON.stringify(l,null,2))},as=l=>{try{const m=JSON.parse(l);m&&typeof m=="object"&&Array.isArray(m.nodes)&&Ce(F(m))}catch{}},rs=l=>{try{const m=JSON.parse(l);Array.isArray(m)&&ye(m)}catch{}},ns=u.useMemo(()=>Te(we??void 0,He),[we,He]),ls=async()=>{if(!Fe.trim()){z(t("templates.nameRequired"));return}let l,m;try{l=JSON.parse(ut),m=JSON.parse(pt)}catch(b){z(t("templates.jsonParseFailed",{error:b instanceof Error?b.message:String(b)}));return}if(!m||typeof m!="object"||!Array.isArray(m.nodes)){z(t("templates.invalidDefinition"));return}const p=Te(m,Array.isArray(l)?l:[]);if(p.length>0){z(p.map(b=>t(b.key,b.params)).join(";"));return}z("");const y=await w.templates.create({name:Fe.trim(),description:dt.trim(),category:ct.trim()||"general",inputs:Array.isArray(l)?l:[],definition:F(m),source:{type:"handwritten"}});y.success&&y.data?(je(!1),o(y.data.id),M()):z(y.error||t("templates.createFailed"))},M=u.useCallback(async()=>{const l=await w.templates.list();l.success&&l.data&&(d(l.data),i&&!l.data.some(m=>m.id===i)&&(o(null),c(null)))},[i]);u.useEffect(()=>{M()},[]),u.useEffect(()=>{if(!i){c(null);return}let l=!1;return f(!0),w.templates.get(i).then(m=>{l||(m.success&&m.data?(c(m.data),ce(m.data.name),U(m.data.description),G(m.data.category),Z(JSON.stringify(m.data.inputs,null,2)),Q(JSON.stringify(m.data.definition,null,2)),be(m.data.inputs??[]),ke(F(m.data.definition)),O(!1),S(""),H(!1),X(null),w.templates.versions(i).then(p=>{!l&&p.success&&p.data&&pe(p.data)})):g(m.error||t("templates.loadFailed")))}).catch(()=>g(t("templates.loadFailed"))).finally(()=>f(!1)),()=>{l=!0}},[i]);const is=u.useMemo(()=>{const l=new Set;for(const m of n)l.add(m.category||t("templates.uncategorized"));return[ne,...[...l].sort()]},[n,t]),bt=u.useMemo(()=>{const l=v.trim().toLowerCase();return n.filter(m=>x!==ne&&(m.category||t("templates.uncategorized"))!==x?!1:l?`${m.name} ${m.description} ${m.category}`.toLowerCase().includes(l):!0)},[n,v,x,t]),gt=u.useMemo(()=>{const l=new Map;for(const m of bt){const p=m.category||t("templates.uncategorized"),y=l.get(p)||[];y.push(m),l.set(p,y)}return[...l.entries()]},[bt,t]),kt=l=>{o(l),fe(!0),ue(!1),H(!1),X(null),ee(null),R(null),$(!1),O(!1),S(""),se("overview")},os=l=>{if(l!==i){if(!it&&T){_e(l);return}kt(l)}},ae=l=>m=>{l(m),O(!0),S("")},ds=async()=>{if(!i||!r||nt)return;const l=i;let m,p;try{m=JSON.parse(C),p=JSON.parse(J)}catch(b){S(t("templates.jsonParseFailed",{error:b instanceof Error?b.message:String(b)}));return}const y=Te(p,Array.isArray(m)?m:[]);if(y.length>0){S(y.map(b=>t(b.key,b.params)).join(";"));return}S(""),lt(!0);try{const b=await w.templates.update(l,{name:V,description:me,category:Y,inputs:Array.isArray(m)?m:[],definition:F(p)});if(te.current!==l)return;b.success&&b.data?(c(b.data),O(!1),S(t("templates.savedVersion",{version:b.data.version})),M(),w.templates.versions(l).then(L=>{te.current===l&&L.success&&L.data&&pe(L.data)})):S(b.error||t("templates.saveFailed"))}finally{lt(!1)}},cs=async l=>{if(!i)return;const m=i;at(!0);try{const p=await w.templates.render(m,l);if(te.current!==m)return;ee({ok:p.success,json:p.success?JSON.stringify(p.data,null,2):void 0,error:p.success?void 0:p.error||t("templates.renderFailed")})}catch(p){ee({ok:!1,error:p instanceof Error?p.message:t("templates.renderFailed")})}finally{at(!1)}},ms=l=>{r&&(a(r,l),R(null))},jt=l=>{r&&(ee(null),R({mode:l}))},Nt=async l=>{if(!i)return;const m=await w.templates.getVersion(i,l);m.success&&m.data&&X(m.data)},us=async()=>{if(!i)return;const l=i;(await w.templates.remove(l)).success&&te.current===l&&(pe([]),H(!1),X(null),ee(null),R(null),se("overview"),fe(!0),S(""),O(!1),o(null),he(!1),M())},ps=()=>{var y,b,L;if(!i)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.workflowLibraryHint")})]})});if(h||!r)return e.jsxs("div",{className:"flex-1 flex items-center justify-center text-dark-muted",children:[e.jsx(vs,{className:"w-4 h-4 animate-spin mr-2"})," ",t("templates.loading")]});const l=((b=(y=r.definition)==null?void 0:y.nodes)==null?void 0:b.length)??0,m=((L=r.inputs)==null?void 0:L.length)??0,p=ca[r.source.type];return it?e.jsx(Js,{t,detail:r,nodeCount:l,inputCount:m,sourceLabelKey:p,detailTab:Kt,onTabChange:se,onReplay:()=>{R({mode:"launch"}),$(!1)},onPreflight:()=>{R({mode:"preview"}),$(!1)},onEdit:()=>{ot(),$(!1)},onDelete:()=>he(!0),onExport:()=>{const k=new Blob([JSON.stringify(r,null,2)],{type:"application/json"}),W=URL.createObjectURL(k),E=document.createElement("a");E.href=W,E.download=`${r.id}.template.json`,E.click(),URL.revokeObjectURL(W)},onCopyId:async()=>{try{await navigator.clipboard.writeText(r.id),S(t("templates.copied"))}catch{}},onToggleAdvanced:()=>{ot(),ue(!0),$(!1)},onToggleVersions:()=>{se("history"),$(!1),H(!1)},onReRecord:async k=>{const W=await w.templates.getVersion(i,k);if(W.success&&W.data){const E=W.data,Ue=await w.templates.update(i,{name:E.name,description:E.description,category:E.category,inputs:E.inputs,definition:E.definition});Ue.success&&Ue.data&&(c(Ue.data),se("history"),M(),w.templates.versions(i).then(Ye=>{Ye.success&&Ye.data&&pe(Ye.data)}))}},versions:Me,historyView:P,onLoadVersion:Nt,onClearHistory:()=>X(null),onRefresh:M,menuOpen:Wt,setMenuOpen:$,saveMsg:Re}):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.jsxs("button",{onClick:()=>{fe(!0),O(!1),ue(!1),H(!1)},className:"inline-flex items-center gap-1 text-xs text-dark-muted hover:text-dark-text transition-colors shrink-0",children:["← ",t("templates.backToView")]}),e.jsx("input",{value:V,onChange:k=>ae(ce)(k.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(N,{variant:"info",children:["v",r.version]}),e.jsx(N,{variant:r.source.type==="saved"?"success":"default",children:p?t(p):r.source.type}),e.jsx("button",{onClick:()=>he(!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(Ie,{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:Y,onChange:k=>ae(G)(k.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:me,onChange:k=>ae(U)(k.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(De,{size:13,className:"text-accent-blue"}),t("templates.nodeCount",{n:l})]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ze,{size:13,className:"text-accent-green"}),t("templates.topologyHint")]}),m>0&&e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(le,{size:13,className:"text-accent-yellow"}),t("templates.inputCount",{n:m})]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ys,{size:13,className:"text-dark-muted/60"}),new Date(r.updatedAt).toLocaleString()]})]}),ge&&e.jsx(Ct,{definition:ge,inputs:Pe,issues:$e,onDefinitionChange:qt,onInputsChange:Ut}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(q,{variant:"accent",leftIcon:e.jsx(At,{className:"w-4 h-4"}),onClick:()=>jt("launch"),children:t("templates.launchWithTemplate")}),e.jsxs("button",{onClick:()=>jt("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(Tt,{className:"w-4 h-4"})," ",t("templates.testRun")]}),e.jsxs("button",{onClick:()=>H(k=>!k),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(zt,{className:"w-4 h-4"})," ",t("templates.versionHistory")]}),e.jsx(q,{variant:"accent",leftIcon:e.jsx(ws,{className:"w-4 h-4"}),onClick:ds,loading:nt,disabled:!T||$e.length>0,title:$e.length>0?t("templates.editorValidationIssues"):void 0,children:t("templates.saveChanges")}),e.jsxs("button",{onClick:()=>ue(k=>!k),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(le,{className:"w-4 h-4"})," ",t("templates.advancedJson")]}),e.jsx("button",{onClick:M,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(Ee,{className:"w-4 h-4"})}),Re&&e.jsx("span",{className:"text-xs text-dark-muted",children:Re})]}),Vt&&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:C,onChange:k=>{ae(Z)(k.target.value),Gt(k.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:J,onChange:k=>{ae(Q)(k.target.value),Yt(k.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.jsx("p",{className:"text-meta text-dark-muted/60",children:t("templates.editorAdvancedSyncHint")})]}),Jt&&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")}),Me.length===0&&e.jsx("div",{className:"text-xs text-dark-muted/60",children:t("templates.noVersions")}),Me.map(k=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>Nt(k),className:"text-xs px-2 py-1 rounded border border-dark-border hover:border-accent-blue/50 transition-colors",children:["v",k]}),P&&P.version===k&&e.jsx("span",{className:"text-xs text-dark-muted/60",children:t("templates.viewingVersion")})]},k)),P&&e.jsx("pre",{className:"mt-2 p-3 rounded-lg bg-dark-bg text-badge font-mono text-dark-muted max-h-60 overflow-y-auto custom-scrollbar",children:JSON.stringify({version:P.version,inputs:P.inputs,definition:P.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.workflowLibraryTitle")}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("button",{onClick:Xt,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.manualCreateTitle"),children:[e.jsx(ie,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden xl:inline",children:t("templates.manualCreate")})]}),e.jsx("button",{onClick:()=>{g(""),M()},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(Ee,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"relative mb-2",children:[e.jsx(Ns,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted/60"}),e.jsx("input",{value:v,onChange:l=>_(l.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:is.map(l=>e.jsx("button",{onClick:()=>A(l),className:I("text-meta px-2 py-0.5 rounded-full border transition-colors",x===l?"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:l===ne?t("templates.filterAll"):l},l))}),j&&e.jsx("div",{className:"text-xs text-accent-red mb-2",children:j}),gt.length===0&&!j&&e.jsx("div",{className:"text-xs text-dark-muted px-1 py-4 text-center",children:t(v||x!==ne?"templates.noMatchTemplates":"templates.emptyTemplates")}),gt.map(([l,m])=>e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"px-1 mb-1.5 text-badge uppercase tracking-wider text-dark-muted/70",children:l}),e.jsx("div",{className:"space-y-1.5",children:m.map(p=>{const y=i===p.id,b=p.status&&p.status!=="ready"?p.status:null,L=b==="degraded"?"templates.degradedBadge":b==="draft"?"templates.statusDraft":b==="deprecated"?"templates.statusDeprecated":b==="archived"?"templates.statusArchived":null;return e.jsxs("button",{onClick:()=>os(p.id),className:I("w-full text-left px-3 py-2.5 rounded-lg border transition-colors",y?"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:p.name}),e.jsxs("span",{className:"flex items-center gap-1 shrink-0",children:[L&&e.jsx(N,{size:"sm",variant:b==="degraded"?"warning":"default",children:t(L)}),e.jsxs(N,{size:"sm",variant:"info",children:["v",p.version]})]})]}),p.description&&e.jsx("div",{className:"text-meta text-dark-muted/70 truncate mt-0.5",children:p.description}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-2 flex-wrap",children:[p.summary&&e.jsxs(N,{size:"sm",variant:p.summary.readonly?"success":"warning",className:"gap-1",children:[p.summary.readonly?e.jsx(oe,{size:10}):e.jsx(et,{size:10}),p.summary.readonly?`${t("templates.readonly")} · ${t("templates.riskLow")}`:`${t("templates.writable")} · ${t("templates.riskMedium")}`]}),e.jsx(N,{size:"sm",variant:"default",children:p.inputs.length>0?t("templates.confirmCount",{n:p.inputs.length}):t("templates.confirmCountNone")}),e.jsxs("span",{className:"ml-auto inline-flex items-center gap-0.5 text-badge text-accent-blue",children:[t(y?"templates.viewing":"templates.view"),!y&&e.jsx(ze,{size:10})]})]})]},p.id)})})]},l))]}),ps(),B&&r&&e.jsxs(As,{isOpen:!0,onClose:()=>R(null),title:B.mode==="launch"?t("templates.replayDrawerTitle",{name:r.name}):t("templates.previewModalTitle",{name:r.name}),size:"md",children:[e.jsx(Cs,{template:r,onCancel:()=>R(null),onSubmit:B.mode==="launch"?ms:cs,submitLabel:B.mode==="launch"?t("templates.replayStart"):t("templates.renderPreview"),submitIcon:B.mode==="launch"?e.jsx(ze,{className:"w-3.5 h-3.5"}):void 0,busy:Ht,autoValues:oa(r,s),preflightSummary:e.jsx(da,{t,detail:r,workspaceDir:s})}),B.mode==="preview"&&xe&&e.jsx("div",{className:"mt-4",children:xe.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-badge font-mono text-dark-muted max-h-72 overflow-y-auto custom-scrollbar",children:xe.json})]}):e.jsx("div",{className:"text-xs text-accent-red",children:xe.error})})]}),e.jsx(Ss,{isOpen:Zt,onClose:()=>je(!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:Fe,onChange:l=>Ve(l.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:ct,onChange:l=>mt(l.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:dt,onChange:l=>Je(l.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:()=>{Se(!0),K("")},className:I("px-3 py-1.5 rounded-lg border text-xs transition-colors inline-flex items-center gap-1.5",Ke?"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(vt,{size:12})," ",t("templates.aiDraftTab")]}),e.jsxs("button",{type:"button",onClick:()=>Se(!1),className:I("px-3 py-1.5 rounded-lg border text-xs transition-colors inline-flex items-center gap-1.5",Ke?"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(le,{size:12})," ",t("templates.editorManualTab")]})]}),Ke?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:We,onChange:l=>ht(l.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.jsx(q,{variant:"accent",onClick:()=>void es(),loading:Ae,leftIcon:Ae?void 0:e.jsx(vt,{className:"w-4 h-4"}),children:t(Ae?"templates.aiWorking":"templates.generateWorkflow")}),Ae&&e.jsx("div",{className:"text-xs text-dark-muted",children:t("templates.aiTimeHint")}),ft&&e.jsx("div",{className:"text-xs text-accent-red",children:ft})]}):e.jsxs(e.Fragment,{children:[we&&e.jsx(Ct,{definition:we,inputs:He,issues:ns,onDefinitionChange:ts,onInputsChange:ss}),e.jsx("div",{children:e.jsxs("button",{type:"button",onClick:()=>Be(l=>!l),className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-dark-border text-xs text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:[e.jsx(le,{size:12})," ",t("templates.advancedJson")]})}),Qt&&e.jsxs("div",{className:"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:ut,onChange:l=>{Ne(l.target.value),rs(l.target.value)},rows:4,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:pt,onChange:l=>{ve(l.target.value),as(l.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.jsx("p",{className:"text-meta text-dark-muted/60",children:t("templates.editorAdvancedSyncHint")})]})]}),xt&&e.jsx("div",{className:"text-xs text-accent-red",children:xt}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{onClick:()=>je(!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(q,{variant:"accent",onClick:()=>void ls(),children:t("templates.create")})]})]})}),e.jsx(yt,{isOpen:Bt,onClose:()=>he(!1),onConfirm:us,title:t("templates.deleteTemplate"),message:t("templates.deleteConfirm",{name:(r==null?void 0:r.name)||i||""}),confirmText:t("templates.delete"),variant:"danger"}),e.jsx(yt,{isOpen:rt!==null,onClose:()=>_e(null),onConfirm:()=>{const l=rt;_e(null),l&&kt(l)},title:t("templates.discardEditsTitle"),message:t("templates.discardEditsMessage",{name:(r==null?void 0:r.name)||i||""}),confirmText:t("templates.discardEditsConfirm"),variant:"danger"})]})}export{ga as TemplatesTab,Us as topoSortNodes};
@@ -0,0 +1 @@
1
+ import{j as e}from"./markdown-BWXjRrSw.js";import{a as o,A as ce,b as G,D as ie,U as ue,d as xe,e as me,S as pe,L as be,C as $,f as J,h as he,P as ge,i as fe,T as ke,j as je,k as ve,X as ye}from"./icons-Bm_ZzSAy.js";import{u as Ne,a as j,t as i,B as q,M as we}from"./index-CeeLdENM.js";import{S as Ce}from"./Skeleton-Dsk6B0U3.js";import"./react-vendor-C0HIWSpf.js";import"./state-Kfon1nTr.js";import"./panels-BQOvnbWH.js";const Se={critical:0,high:1,medium:2,low:3},ze={critical:"bg-accent-red/20 text-accent-red",high:"bg-accent-red/15 text-accent-red",medium:"bg-accent-yellow/20 text-accent-yellow",low:"bg-accent-green/20 text-accent-green"};function Re(s,d){const u=`tools.cat.${s}`,x=d(u);if(x&&x!==u)return x;const n=s.replace(/_/g," ").trim();return n?n.charAt(0).toUpperCase()+n.slice(1):d("tools.groupUncategorized")}function K(s,d){switch(s){case"critical":return d("tools.riskCritical");case"high":return d("tools.riskHigh");case"medium":return d("tools.riskMedium");case"low":return d("tools.riskLow");default:return d("tools.riskUnknown")}}function Ee(s,d,u){const x=new Map;for(const n of s){let c,p,f=0;d==="risk"?(c=n.risk??"unknown",p=K(n.risk,u),f=Se[c]??99):d==="state"?(c=n.enabled?"on":"off",p=n.enabled?u("tools.enabled"):u("tools.disabled"),f=n.enabled?0:1):(c=n.category||"__none__",p=n.category?Re(n.category,u):u("tools.groupUncategorized"));let y=x.get(c);y||(y={key:c,label:p,tools:[],order:f},x.set(c,y)),y.tools.push(n)}for(const n of x.values())n.tools.sort((c,p)=>c.enabled!==p.enabled?c.enabled?-1:1:c.id.localeCompare(p.id));return[...x.values()].sort((n,c)=>d==="category"?c.tools.length-n.tools.length||n.label.localeCompare(c.label):n.order-c.order||n.label.localeCompare(c.label))}function Le(s,d){try{if(typeof URL.createObjectURL!="function")return!1;const u=new Blob([JSON.stringify(d,null,2)],{type:"application/json"}),x=URL.createObjectURL(u),n=document.createElement("a");return n.href=x,n.download=s,n.click(),URL.revokeObjectURL(x),!0}catch{return!1}}function Be(){const{t:s}=Ne(),[d,u]=o.useState([]),[x,n]=o.useState(!0),[c,p]=o.useState(null),[f,y]=o.useState(""),[L,Q]=o.useState("category"),[I,D]=o.useState(new Set),[V,P]=o.useState(null),[W,z]=o.useState(null),[h,S]=o.useState({name:"",description:"",category:"",enabled:!0}),[T,N]=o.useState(null),[U,X]=o.useState(null),[O,Y]=o.useState(0),[Z,ee]=o.useState(null),[w,R]=o.useState(null),B=o.useRef(null),k=o.useCallback(async()=>{n(!0),p(null);const[t,a]=await Promise.all([j.tools.list(),j.tools.exportConfig()]);t.success&&Array.isArray(t.data)?u(t.data):t.success&&t.data&&!Array.isArray(t.data)?p(s("tools.invalidData")):p(t.error||s("tools.loadFailed")),a.success&&a.data&&(X(a.data.path??null),Y(Object.keys(a.data.tools??{}).length),ee(a.data.profile??null)),n(!1)},[s]);o.useEffect(()=>{k()},[k]);const se=o.useCallback(()=>{window.dispatchEvent(new CustomEvent("switch-tab",{detail:"connectors"}))},[]),A=o.useMemo(()=>{const t=f.trim().toLowerCase();return t?d.filter(a=>a.id.toLowerCase().includes(t)||a.name.toLowerCase().includes(t)||a.description.toLowerCase().includes(t)||a.category.toLowerCase().includes(t)):d},[d,f]),E=o.useMemo(()=>Ee(A,L,s),[A,L,s]),M=o.useMemo(()=>d.filter(t=>t.enabled).length,[d]),C=o.useCallback((t,a,l)=>{u(r=>r.map(b=>b.id===a?{...b,...l,...t??{}}:b))},[]),te=o.useCallback(async t=>{var r;N(t.id);const a=await j.tools.toggle(t.id,!t.enabled);if(N(null),!a.success){i.error(a.error||s("tools.toggleFailed"));return}const l=((r=a.data)==null?void 0:r.enabled)??!t.enabled;C(void 0,t.id,{enabled:l,overridden:!0})},[C,s]),ae=o.useCallback(t=>{z(t.id),P(t.id),S({name:t.name,description:t.description,category:t.category,enabled:t.enabled})},[]),re=o.useCallback(async t=>{N(t.id);const a=await j.tools.update(t.id,{name:h.name,description:h.description,category:h.category,enabled:h.enabled});if(N(null),!a.success||!a.data){i.error(a.error||s("tools.saveFailed"));return}C(a.data,t.id,{}),z(null),i.success(s("tools.saved"))},[h,C,s]),le=o.useCallback(async t=>{N(t.id);const a=await j.tools.reset(t.id);if(N(null),!a.success||!a.data){i.error(a.error||s("tools.resetFailed"));return}C(a.data,t.id,{}),z(l=>l===t.id?null:l),i.success(s("tools.resetDone"))},[C,s]),F=o.useCallback(async(t,a)=>{const l=t.tools.filter(g=>g.enabled!==a);if(l.length===0)return;const b=(await Promise.all(l.map(g=>j.tools.toggle(g.id,a)))).filter(g=>!g.success).length;b>0&&i.warning(s("tools.groupPartial",{failed:b,total:l.length})),await k()},[k,s]),oe=o.useCallback(async()=>{const t=await j.tools.exportConfig();if(!t.success||!t.data){i.error(t.error||s("tools.loadFailed"));return}const a=Object.keys(t.data.tools??{}).length;if(a===0){i.info(s("tools.exportEmpty"));return}if(!Le("deepseekcode-tools.json",t.data)){i.error(s("tools.exportFailed"));return}i.success(s("tools.exportDone",{count:a}))},[s]),ne=o.useCallback(async t=>{let a;try{a=JSON.parse(await t.text())}catch{i.error(s("tools.importInvalid"));return}const l=a&&typeof a=="object"&&"tools"in a?a.tools:a,r=l&&typeof l=="object"&&!Array.isArray(l)?Object.keys(l).length:0;if(r===0){i.error(s("tools.importEmpty"));return}R({payload:a,count:r})},[s]),H=o.useCallback(async t=>{const a=w;if(R(null),!a)return;const l=await j.tools.importConfig(a.payload,t);if(!l.success||!l.data){i.error(s("tools.importFailed",{error:l.error??""}));return}l.data.unknown.length>0&&i.warning(s("tools.importUnknown",{count:l.data.unknown.length})),i.success(s("tools.importDone",{count:l.data.applied.length})),await k()},[k,w,s]),de=o.useCallback(t=>{D(a=>{const l=new Set(a);return l.has(t)?l.delete(t):l.add(t),l})},[]),_=E.length>0&&E.every(t=>I.has(t.key));return x?e.jsx("div",{className:"flex-1 overflow-y-auto p-4",role:"status","aria-label":s("tools.loading"),children:e.jsx(Ce,{count:5})}):c?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ce,{size:32,className:"mx-auto mb-2 text-accent-red"}),e.jsx("p",{className:"text-accent-red mb-4",children:c}),e.jsx(q,{variant:"accent",onClick:()=>void k(),children:s("tools.retry")})]})}):e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 gap-3",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2 min-w-0",children:[e.jsx(G,{size:20,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:s("tools.title")}),e.jsxs("span",{className:"text-sm font-normal text-dark-muted whitespace-nowrap",children:[s("tools.totalTools",{count:d.length})," · ",s("tools.enabledCount",{count:M})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:()=>void oe(),title:U?s("tools.importPath",{path:U}):void 0,className:"flex items-center gap-1.5 px-3 py-1.5 bg-dark-surface border border-dark-border rounded hover:bg-dark-hover transition-colors",children:[e.jsx(ie,{size:14}),s("tools.exportConfig"),O>0&&e.jsxs("span",{className:"text-xs text-accent-blue",children:["(",O,")"]})]}),e.jsxs("button",{onClick:()=>{var t;return(t=B.current)==null?void 0:t.click()},className:"flex items-center gap-1.5 px-3 py-1.5 bg-dark-surface border border-dark-border rounded hover:bg-dark-hover transition-colors",children:[e.jsx(ue,{size:14}),s("tools.importConfig")]}),e.jsx("input",{ref:B,type:"file",accept:"application/json,.json",className:"hidden","data-testid":"tools-import-input",onChange:t=>{var l;const a=(l=t.target.files)==null?void 0:l[0];t.target.value="",a&&ne(a)}}),e.jsxs("button",{onClick:()=>void k(),className:"flex items-center gap-1.5 px-3 py-1.5 bg-dark-surface border border-dark-border rounded hover:bg-dark-hover transition-colors",children:[e.jsx(xe,{size:14}),s("tools.refresh")]})]})]}),e.jsxs("div",{className:"mb-3 px-3 py-2 rounded-lg bg-accent-blue/10 border border-accent-blue/20 text-xs text-dark-muted space-y-1",children:[Z==="minimal"&&e.jsx("div",{children:s("tools.profileMinimalHint",{off:d.length-M})}),e.jsxs("div",{className:"flex items-center gap-x-2 gap-y-1 flex-wrap",children:[e.jsx("span",{children:s("tools.scopeHint")}),e.jsxs("button",{type:"button",onClick:se,className:"inline-flex items-center gap-1 text-accent-blue hover:underline",children:[s("tools.scopeHintConnectorsLink"),e.jsx(me,{size:11})]})]})]}),e.jsxs("div",{className:"flex gap-3 mb-3 items-center flex-wrap",children:[e.jsxs("div",{className:"flex-1 min-w-[200px] relative",children:[e.jsx(pe,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{type:"text",value:f,onChange:t=>y(t.target.value),placeholder:s("tools.searchTools"),className:"w-full pl-10 pr-4 py-2 bg-dark-surface border border-dark-border rounded-lg text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),e.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[e.jsx(be,{size:14,className:"text-dark-muted"}),e.jsx("span",{className:"text-dark-muted mr-1",children:s("tools.groupBy")}),["category","risk","state"].map(t=>e.jsx("button",{onClick:()=>Q(t),className:`px-3 py-1.5 rounded-lg transition-colors ${L===t?"bg-accent-blue text-accent-fg":"bg-dark-surface border border-dark-border hover:bg-dark-hover"}`,children:s(t==="category"?"tools.groupByCategory":t==="risk"?"tools.groupByRisk":"tools.groupByState")},t)),e.jsx("button",{onClick:()=>D(_?new Set:new Set(E.map(t=>t.key))),className:"px-3 py-1.5 rounded-lg bg-dark-surface border border-dark-border hover:bg-dark-hover transition-colors",children:s(_?"tools.expandAll":"tools.collapseAll")})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar",children:e.jsxs("div",{className:"space-y-3",children:[E.map(t=>{const a=I.has(t.key),l=t.tools.filter(r=>r.enabled).length;return e.jsxs("div",{className:"bg-dark-surface border border-dark-border rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-dark-hover/40",children:[e.jsxs("button",{onClick:()=>de(t.key),className:"flex items-center gap-2 min-w-0 flex-1 text-left",children:[a?e.jsx($,{size:16,className:"shrink-0 text-dark-muted"}):e.jsx(J,{size:16,className:"shrink-0 text-dark-muted"}),e.jsx("span",{className:"font-medium truncate",children:t.label}),e.jsx("span",{className:"text-xs text-dark-muted whitespace-nowrap",children:s("tools.groupEnabled",{on:l,total:t.tools.length})})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>void F(t,!0),disabled:l===t.tools.length,className:"text-xs px-2 py-1 rounded border border-dark-border hover:bg-dark-hover disabled:opacity-40 disabled:cursor-not-allowed",children:s("tools.enableGroup")}),e.jsx("button",{onClick:()=>void F(t,!1),disabled:l===0,className:"text-xs px-2 py-1 rounded border border-dark-border hover:bg-dark-hover disabled:opacity-40 disabled:cursor-not-allowed",children:s("tools.disableGroup")})]})]}),!a&&e.jsx("div",{className:"divide-y divide-dark-border",children:t.tools.map(r=>{const b=W===r.id,g=V===r.id||b;return e.jsxs("div",{className:r.enabled?"":"opacity-60",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 gap-3",children:[e.jsxs("button",{className:"flex items-center gap-2 flex-1 min-w-0 text-left",onClick:()=>P(g&&!b?null:r.id),children:[g?e.jsx(J,{size:14,className:"shrink-0 text-dark-muted"}):e.jsx($,{size:14,className:"shrink-0 text-dark-muted"}),e.jsx("span",{className:"font-medium truncate",children:r.name}),e.jsx("code",{className:"text-xs text-dark-muted truncate",children:r.id}),r.risk&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-badge whitespace-nowrap ${ze[r.risk]??"bg-dark-hover text-dark-muted"}`,children:[r.risk==="high"||r.risk==="critical"?e.jsx(he,{size:10,className:"inline -mt-px mr-0.5"}):null,K(r.risk,s)]}),r.overridden&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-badge bg-accent-purple/20 text-accent-purple whitespace-nowrap",children:s("tools.overridden")}),!r.enabled&&!r.overridden&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-badge bg-dark-hover text-dark-muted whitespace-nowrap",children:r.defaultEnabled===!1?s("tools.defaultOff"):s("tools.disabled")}),r.userInstalled&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-badge bg-accent-blue/20 text-accent-blue whitespace-nowrap",title:s("tools.userInstalledHint"),children:s("tools.userInstalled")})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>ae(r),title:s("tools.edit"),className:"p-1.5 rounded text-dark-muted hover:bg-dark-hover hover:text-dark-text transition-colors",children:e.jsx(ge,{size:14})}),r.overridden&&e.jsx("button",{onClick:()=>void le(r),disabled:T===r.id,title:s("tools.reset"),className:"p-1.5 rounded text-dark-muted hover:bg-dark-hover hover:text-dark-text transition-colors disabled:opacity-40",children:e.jsx(fe,{size:14})}),e.jsx("button",{onClick:()=>void te(r),disabled:T===r.id,title:r.enabled?s("tools.disabled"):s("tools.enabled"),className:`p-1.5 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${r.enabled?"text-accent-green hover:bg-accent-green/10":"text-dark-muted hover:bg-dark-hover"}`,children:r.enabled?e.jsx(ke,{size:24}):e.jsx(je,{size:24})})]})]}),g&&e.jsx("div",{className:"px-3 pb-3 border-t border-dark-border",children:b?e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted",children:s("tools.fieldName")}),e.jsx("input",{value:h.name,onChange:m=>S(v=>({...v,name:m.target.value})),placeholder:s("tools.namePlaceholder"),className:"w-full mt-1 px-2 py-1.5 bg-dark-bg border border-dark-border rounded text-sm focus:border-accent-blue focus:outline-none"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted",children:s("tools.fieldCategory")}),e.jsx("input",{value:h.category,onChange:m=>S(v=>({...v,category:m.target.value})),placeholder:s("tools.categoryPlaceholder"),className:"w-full mt-1 px-2 py-1.5 bg-dark-bg border border-dark-border rounded text-sm focus:border-accent-blue focus:outline-none"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-dark-muted",children:s("tools.fieldDescription")}),e.jsx("textarea",{value:h.description,onChange:m=>S(v=>({...v,description:m.target.value})),placeholder:s("tools.descriptionPlaceholder"),rows:3,className:"w-full mt-1 px-2 py-1.5 bg-dark-bg border border-dark-border rounded text-sm focus:border-accent-blue focus:outline-none resize-y"})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:h.enabled,onChange:m=>S(v=>({...v,enabled:m.target.checked}))}),s("tools.fieldEnabled")]}),e.jsx("p",{className:"text-xs text-dark-muted",children:s("tools.descriptionHint")}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx(q,{variant:"accent",size:"sm",leftIcon:e.jsx(ve,{size:14}),loading:T===r.id,onClick:()=>void re(r),children:s("tools.save")}),e.jsxs("button",{onClick:()=>z(null),className:"flex items-center gap-1.5 px-3 py-1.5 border border-dark-border rounded text-sm hover:bg-dark-hover",children:[e.jsx(ye,{size:14}),s("tools.cancel")]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-dark-muted mt-3 mb-3 whitespace-pre-wrap",children:r.description}),r.usage&&e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"text-xs text-dark-muted mb-1",children:s("tools.usageHint")}),e.jsx("p",{className:"text-sm text-dark-muted whitespace-pre-wrap",children:r.usage})]}),r.params&&r.params.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-dark-muted mb-2",children:s("tools.params")}),e.jsx("div",{className:"space-y-1",children:r.params.map(m=>e.jsxs("div",{className:"flex items-center gap-2 text-sm flex-wrap",children:[e.jsxs("code",{className:"px-1.5 py-0.5 bg-dark-bg rounded text-accent-blue",children:[m.name,m.required&&e.jsx("span",{className:"text-accent-red",children:"*"})]}),e.jsxs("span",{className:"text-dark-muted text-xs",children:["(",m.type,")"]}),e.jsx("span",{className:"text-dark-muted text-xs",children:m.description})]},m.name))})]})]})})]},r.id)})})]},t.key)}),A.length===0&&e.jsxs("div",{className:"text-center text-dark-muted py-8",children:[e.jsx(G,{size:48,className:"mx-auto mb-2 opacity-50"}),e.jsx("p",{children:s(f?"tools.noMatch":"tools.noTools")})]})]})}),e.jsxs(we,{isOpen:w!==null,onClose:()=>R(null),title:s("tools.importTitle"),size:"sm",children:[e.jsx("p",{className:"text-sm text-dark-muted mb-4",children:s("tools.importDesc",{count:(w==null?void 0:w.count)??0})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{onClick:()=>void H("merge"),className:"w-full text-left px-3 py-2 border border-dark-border rounded hover:bg-dark-hover transition-colors",children:[e.jsx("div",{className:"font-medium text-sm",children:s("tools.importMerge")}),e.jsx("div",{className:"text-xs text-dark-muted",children:s("tools.importMergeHint")})]}),e.jsxs("button",{onClick:()=>void H("replace"),className:"w-full text-left px-3 py-2 border border-dark-border rounded hover:bg-dark-hover transition-colors",children:[e.jsx("div",{className:"font-medium text-sm",children:s("tools.importReplace")}),e.jsx("div",{className:"text-xs text-dark-muted",children:s("tools.importReplaceHint")})]}),e.jsx("button",{onClick:()=>R(null),className:"w-full px-3 py-2 text-sm text-dark-muted hover:text-dark-text transition-colors",children:s("tools.cancel")})]})]})]})}export{Be as ToolsView,Be as default};
@@ -0,0 +1 @@
1
+ import{j as e}from"./markdown-BWXjRrSw.js";import{f as a,u as t,U as m}from"./index-CeeLdENM.js";function j({app:s,layout:r="carousel",chrome:d="card",count:i=3}){const c=r==="carousel",n=d==="transparent",l=e.jsx("div",{className:a(c?"viz-carousel":"grid gap-2.5 grid-cols-2 sm:grid-cols-3"),"aria-hidden":"true",children:Array.from({length:i}).map((x,o)=>e.jsx("div",{className:a("flex flex-col",!n&&"rounded-xl"),children:e.jsxs("div",{className:a("overflow-hidden rounded-xl border border-dark-border/60",n?"bg-transparent":"bg-dark-bg"),children:[e.jsx("div",{className:"skeleton-shimmer aspect-square w-full"}),e.jsxs("div",{className:a("space-y-1.5",n?"pt-2":"p-2.5"),children:[e.jsx("div",{className:"skeleton-shimmer h-3 w-4/5 rounded"}),e.jsx("div",{className:"skeleton-shimmer h-2.5 w-3/5 rounded"}),e.jsx("div",{className:"skeleton-shimmer h-2 w-2/5 rounded"}),e.jsx("div",{className:"skeleton-shimmer mt-2 h-6 w-full rounded-full"})]})]})},`ghost-${o}`))});return e.jsxs("figure",{className:"my-3","aria-busy":"true",children:[e.jsx("header",{className:"mb-2 flex items-center gap-2",children:e.jsx(u,{app:s})}),d==="contained"?e.jsxs("div",{className:"rounded-xl border border-dark-border bg-dark-surface/45 p-3",children:[e.jsx("div",{className:"skeleton-shimmer mb-2 h-3 w-24 rounded"}),l]}):l]})}function u({app:s}){const{t:r}=t();return e.jsxs("span",{className:"inline-flex max-w-full items-center gap-1.5 rounded-full border border-dark-border bg-dark-surface/60 px-2 py-0.5",children:[e.jsx("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[0.2rem] bg-dark-hover",children:s!=null&&s.icon?e.jsx("img",{src:s.icon,alt:"",className:"h-full w-full object-cover"}):e.jsx(m.appFallback,{size:10,className:"text-dark-muted","aria-hidden":"true"})}),e.jsx("span",{className:"text-shimmer truncate text-compact font-medium",children:s!=null&&s.name?r("viz.connecting",{app:s.name}):r("viz.connectingGeneric")})]})}export{j as V};
@@ -0,0 +1 @@
1
+ import{g as p,r as u,d as a}from"./chunk-AW2ZBBNX-De0QX6p1.js";import{p as f}from"./chunk-JWPE2WC7-umm4A-fq.js";import{_ as n,l as o}from"./mermaid.core-DLb6eAON.js";import{M as c,b as d}from"./cynefin-EF2NZ3EQ-CiMvulJr.js";import"./index-CeeLdENM.js";import"./markdown-BWXjRrSw.js";import"./icons-Bm_ZzSAy.js";import"./react-vendor-C0HIWSpf.js";import"./state-Kfon1nTr.js";import"./panels-BQOvnbWH.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),m=t?parseInt(t,10):0,l=s?parseInt(s,10):1/0;return{min:m,max:l}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},L={parser:R,db:a,renderer:u,styles:p};export{L as diagram};
@@ -0,0 +1 @@
1
+ import{V as ln,W as an,X as j,Y as q,Z as X,$ as un,a0 as y,a1 as tn,a2 as C,a3 as _,a4 as rn,a5 as o,a6 as on,a7 as sn,a8 as fn}from"./mermaid.core-DLb6eAON.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,I,D,v,A,Y,a){var O=I-l,i=D-h,n=Y-v,d=a-A,u=d*O-n*i;if(!(u*u<y))return u=(n*(h-A)-d*(l-v))/u,[l+u*O,h+u*i]}function L(l,h,I,D,v,A,Y){var a=l-I,O=h-D,i=(Y?A:-A)/C(a*a+O*O),n=i*O,d=-i*a,u=l+n,s=h+d,f=I+n,c=D+d,Z=(u+f)/2,t=(s+c)/2,m=f-u,g=c-s,R=m*m+g*g,T=v-A,P=u*c-f*s,S=(g<0?-1:1)*C(on(0,T*T*R-P*P)),V=(P*g-m*S)/R,W=(-P*m-g*S)/R,w=(P*g+m*S)/R,p=(-P*m+g*S)/R,x=V-Z,e=W-t,r=w-Z,$=p-t;return x*x+e*e>r*r+$*$&&(V=w,W=p),{cx:V,cy:W,x01:-n,y01:-d,x11:V*(v/T-1),y11:W*(v/T-1)}}function hn(){var l=cn,h=yn,I=X(0),D=null,v=gn,A=dn,Y=mn,a=null,O=ln(i);function i(){var n,d,u=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-un,c=A.apply(this,arguments)-un,Z=rn(c-f),t=c>f;if(a||(a=n=O()),s<u&&(d=s,s=u,u=d),!(s>y))a.moveTo(0,0);else if(Z>tn-y)a.moveTo(s*j(f),s*q(f)),a.arc(0,0,s,f,c,!t),u>y&&(a.moveTo(u*j(c),u*q(c)),a.arc(0,0,u,c,f,t));else{var m=f,g=c,R=f,T=c,P=Z,S=Z,V=Y.apply(this,arguments)/2,W=V>y&&(D?+D.apply(this,arguments):C(u*u+s*s)),w=_(rn(s-u)/2,+I.apply(this,arguments)),p=w,x=w,e,r;if(W>y){var $=sn(W/u*q(V)),F=sn(W/s*q(V));(P-=$*2)>y?($*=t?1:-1,R+=$,T-=$):(P=0,R=T=(f+c)/2),(S-=F*2)>y?(F*=t?1:-1,m+=F,g-=F):(S=0,m=g=(f+c)/2)}var z=s*j(m),B=s*q(m),G=u*j(T),H=u*q(T);if(w>y){var J=s*j(g),K=s*q(g),M=u*j(R),N=u*q(R),E;if(Z<an)if(E=pn(z,B,M,N,J,K,G,H)){var Q=z-E[0],U=B-E[1],k=J-E[0],b=K-E[1],nn=1/q(fn((Q*k+U*b)/(C(Q*Q+U*U)*C(k*k+b*b)))/2),en=C(E[0]*E[0]+E[1]*E[1]);p=_(w,(u-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}S>y?x>y?(e=L(M,N,z,B,s,x,t),r=L(J,K,G,H,s,x,t),a.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),a.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(a.moveTo(z,B),a.arc(0,0,s,m,g,!t)):a.moveTo(z,B),!(u>y)||!(P>y)?a.lineTo(G,H):p>y?(e=L(G,H,J,K,u,-p,t),r=L(z,B,M,N,u,-p,t),a.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,u,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),a.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):a.arc(0,0,u,T,R,t)}if(a.closePath(),n)return a=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-an/2;return[j(d)*n,q(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:X(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:X(+n),i):h},i.cornerRadius=function(n){return arguments.length?(I=typeof n=="function"?n:X(+n),i):I},i.padRadius=function(n){return arguments.length?(D=n==null?null:typeof n=="function"?n:X(+n),i):D},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:X(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:X(+n),i):A},i.padAngle=function(n){return arguments.length?(Y=typeof n=="function"?n:X(+n),i):Y},i.context=function(n){return arguments.length?(a=n??null,i):a},i}export{hn as d};