@cnrai/pave 0.11.63 → 0.11.65

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 (66) hide show
  1. package/package.json +1 -1
  2. package/pave.js +2 -2
  3. package/web/assets/{abnfDiagram-VRR7QNED-qRSe9DAB.js → abnfDiagram-N423BO3Z-B45eXM23.js} +1 -1
  4. package/web/assets/{arc-B7SXJwvQ.js → arc-mwUEDZhA.js} +1 -1
  5. package/web/assets/architectureDiagram-T3A2C74G-B8K3d3gz.js +36 -0
  6. package/web/assets/{blockDiagram-677ZJIJ3-DUAxiYnz.js → blockDiagram-VBNYF7ZC-BTypeqq2.js} +1 -1
  7. package/web/assets/{c4Diagram-LMCZKHZV-E7l-uYc0.js → c4Diagram-5PPSVZJV-DZR35MXO.js} +1 -1
  8. package/web/assets/channel-1QgHwsaH.js +1 -0
  9. package/web/assets/{chunk-32BRIVSS-DwEvjPZL.js → chunk-2GRJ4B5K-DsFL8m4M.js} +1 -1
  10. package/web/assets/{chunk-2Q5K7J3B-CFaAUvC6.js → chunk-2Q5K7J3B-Pt_0_j6q.js} +1 -1
  11. package/web/assets/{chunk-EX3LRPZG-B79R-suC.js → chunk-5RXB4S5H-kEbBmsN9.js} +1 -1
  12. package/web/assets/{chunk-5VM5RSS4-BuT2qpJC.js → chunk-5VM5RSS4-B7dhgfMK.js} +1 -1
  13. package/web/assets/{chunk-MOJQB5TN-CTduFJG_.js → chunk-6Q2QTUOP-C6X4LADQ.js} +1 -1
  14. package/web/assets/{chunk-V7JOEXUC-DuYm5ISe.js → chunk-GF5L2VYU-iNt2SgK_.js} +1 -1
  15. package/web/assets/{chunk-JWPE2WC7-B3eT8v8h.js → chunk-JWPE2WC7-TyhfCWBi.js} +1 -1
  16. package/web/assets/{chunk-VR4S4FIN-DOGM8M0x.js → chunk-KBJHAD2P-BqnrSlZb.js} +1 -1
  17. package/web/assets/{chunk-RYQCIY6F-CwVsCKni.js → chunk-RYQCIY6F-V_HLaHJd.js} +1 -1
  18. package/web/assets/{chunk-XXDRQBXY-D1lUnqR9.js → chunk-XXDRQBXY-DVrzC4u0.js} +1 -1
  19. package/web/assets/classDiagram-JCYQIIEL-B2hgYK4x.js +1 -0
  20. package/web/assets/classDiagram-v2-OCEON4UE-B2hgYK4x.js +1 -0
  21. package/web/assets/{cose-bilkent-JH36ORCC-F0vY69Q1.js → cose-bilkent-JH36ORCC-C4Z6xUob.js} +1 -1
  22. package/web/assets/{cynefin-VYW2F7L2-D1bEJ_1X.js → cynefin-VYW2F7L2-DOzj3Nv7.js} +1 -1
  23. package/web/assets/{cynefinDiagram-TSTJHNR4-C5i6TpKM.js → cynefinDiagram-MW4NZA55-CIk6ebOE.js} +1 -1
  24. package/web/assets/{dagre-VKFMJZFB-BaJhQrcg.js → dagre-VZM6K2ZE-CyjmCzoT.js} +1 -1
  25. package/web/assets/{diagram-OA4YK3LP-CdVytGiC.js → diagram-7IWD3JNH-BreNfeKM.js} +1 -1
  26. package/web/assets/{diagram-FQU43EPY-B5s2GugH.js → diagram-B4RE2ZJO-DNEJccKH.js} +1 -1
  27. package/web/assets/{diagram-NH7WQ7WH-Be8CFL2y.js → diagram-LBJQPF4R-BXJzic7t.js} +1 -1
  28. package/web/assets/{diagram-G47NLZAW-CqhWh7wb.js → diagram-Q27KOJAE-BAbCMYNG.js} +1 -1
  29. package/web/assets/diagram-UB23O5K3-BYJLvHyN.js +41 -0
  30. package/web/assets/{ebnfDiagram-CCIWWBDH-B5h3rL5s.js → ebnfDiagram-BXEA7PRR-C4OZq1wq.js} +1 -1
  31. package/web/assets/{erDiagram-Q63AITRT-CEP5X1_j.js → erDiagram-JOGREHBK-Va-T6jTW.js} +1 -1
  32. package/web/assets/{flowDiagram-23GEKE2U-xuryGu7o.js → flowDiagram-UKHOOZJN-BJFudK1A.js} +5 -5
  33. package/web/assets/{ganttDiagram-NO4QXBWP-DAE1Z40G.js → ganttDiagram-PKOTCBZU-_0I5ZmkI.js} +1 -1
  34. package/web/assets/{gitGraphDiagram-IHSO6WYX-CJBqjaw2.js → gitGraphDiagram-DS77QQ5N-seIKqMLH.js} +1 -1
  35. package/web/assets/{index-DZcQ8cq-.js → index-Unz9INDW.js} +1 -1
  36. package/web/assets/{infoDiagram-FWYZ7A6U-CZ4YANgy.js → infoDiagram-6WML65LV-DW3T8xKZ.js} +1 -1
  37. package/web/assets/{ishikawaDiagram-FXEZZL3T-CClm-Sn4.js → ishikawaDiagram-WSZJBQD7-BQuJwSD9.js} +1 -1
  38. package/web/assets/{journeyDiagram-5HDEW3XC-BifxEcxw.js → journeyDiagram-NVQOT4AX-CCEfABU-.js} +1 -1
  39. package/web/assets/{kanban-definition-HUTT4EX6-DEstl5u8.js → kanban-definition-27J2QSJJ-Bc2SbMw6.js} +1 -1
  40. package/web/assets/{linear-DFGFp-ES.js → linear-C4N1qnOV.js} +1 -1
  41. package/web/assets/{mermaid.core-D2L8Rtb7.js → mermaid.core-Czi3lWeD.js} +77 -77
  42. package/web/assets/{mindmap-definition-LN4V7U3C-BaYXUjOF.js → mindmap-definition-FAOFIHXS-xXdVBN-Y.js} +1 -1
  43. package/web/assets/{pegDiagram-2B236MQR-DCE72-8K.js → pegDiagram-VL7TDLO6-Cvt5l1-C.js} +1 -1
  44. package/web/assets/{pieDiagram-ENE6RG2P-32NA7bXp.js → pieDiagram-7S7Q4E2Y-3s9kj7j9.js} +1 -1
  45. package/web/assets/{quadrantDiagram-ABIIQ3AL-BBziNWms.js → quadrantDiagram-CIZ2JOQS-DLESOtv9.js} +1 -1
  46. package/web/assets/{railroadDiagram-RFXS5EU6-CPa5am_S.js → railroadDiagram-AXF67PYL-BEezKvtO.js} +1 -1
  47. package/web/assets/{requirementDiagram-TGXJPOKE-CPcFcu10.js → requirementDiagram-LRYGKXZP-GIDEYmLw.js} +1 -1
  48. package/web/assets/{sankeyDiagram-HTMAVEWB-DUrSTgld.js → sankeyDiagram-W5VNT64P-BzcfWkzj.js} +1 -1
  49. package/web/assets/{sequenceDiagram-DBY2YBRQ-Bem4ofsM.js → sequenceDiagram-SI44F4Z6-9qGO_jGz.js} +1 -1
  50. package/web/assets/{sizeCapture-X5ZJPWSS-D0nColKd.js → sizeCapture-X5ZJPWSS-BCeBizlX.js} +1 -1
  51. package/web/assets/{stateDiagram-2N3HPSRC-Fd7AhaTH.js → stateDiagram-OKZ733FA-CQqZfF4g.js} +1 -1
  52. package/web/assets/stateDiagram-v2-UEYNNEHI-BP-uYIhl.js +1 -0
  53. package/web/assets/{swimlanes-5IMT3BWC-1Lc6dTz0.js → swimlanes-SLNWSIFB-DMIWyWE4.js} +2 -2
  54. package/web/assets/swimlanesDiagram-ULZ7WXOC-xqFio8Ua.js +8 -0
  55. package/web/assets/{timeline-definition-FHXFAJF6-Buz7EWxM.js → timeline-definition-Z64GVDOM-DXGNeWh3.js} +1 -1
  56. package/web/assets/{vennDiagram-L72KCM5P-oTEYn7-i.js → vennDiagram-T6HMQDX7-CppWCqpI.js} +1 -1
  57. package/web/assets/{wardleyDiagram-EHGQE667-BLo-yQ5P.js → wardleyDiagram-T6FBY63Y-DyutMVu-.js} +1 -1
  58. package/web/assets/{xychartDiagram-FW5EYKEG-DEdu279q.js → xychartDiagram-ELKLHX3M-DsQQ9Qkf.js} +4 -4
  59. package/web/index.html +1 -1
  60. package/web/assets/architectureDiagram-ZJ3FMSHR-DDYMKNo_.js +0 -36
  61. package/web/assets/channel-Bea3U6kR.js +0 -1
  62. package/web/assets/classDiagram-OUVF2IWQ-ljhJH3EO.js +0 -1
  63. package/web/assets/classDiagram-v2-EOCWNBFH-ljhJH3EO.js +0 -1
  64. package/web/assets/diagram-WEI45ONY-CimHxyF4.js +0 -41
  65. package/web/assets/stateDiagram-v2-6OUMAXLB-DkJN7koK.js +0 -1
  66. package/web/assets/swimlanesDiagram-G3AALYLV-CnY2Vcjb.js +0 -8
@@ -101,7 +101,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),C=S,Q=I),B===void 0&&(
101
101
  `),$+=B}else S.type==="tool"&&(P(),G(),A.push({type:"tool",part:S,key:"tool-"+(S.id||M)}))}if(P(),G(),r.length>0&&A.push({type:"files",parts:r,key:"files"}),n.length>0&&A.push({type:"images",parts:n,key:"images"}),A.length===0)return null;var Q=[],C=[],K="";function W(){C.length>0&&(Q.push(o.jsx("div",{className:"mb-2 pl-2 border-l-2 border-gray-200 dark:border-gray-700",children:C},"accent-"+K)),C=[])}for(var j=0;j<A.length;j++){var U=A[j];if(U.type==="text"){W();var le=Object.assign({},a);if(s&&c>0){var Z=function(ve,me){return function({children:pe,node:Le,...Se}){return o.jsx(ve,{...Se,children:Jy(pe,s,l,me,u,d)})}};le.p=Z("p",i),le.li=Z("li",i),le.td=Z("td",i),le.th=Z("th",i),le.h1=Z("h1",i),le.h2=Z("h2",i),le.h3=Z("h3",i),le.h4=Z("h4",i),le.h5=Z("h5",i),le.h6=Z("h6",i),le.blockquote=Z("blockquote",i)}Q.push(o.jsx("div",{className:"mb-2 prose prose-sm dark:prose-invert max-w-none break-words",children:o.jsx(Jo,{remarkPlugins:[tl,Ky],rehypePlugins:[$k],components:le,children:U.text})},U.key))}else if(U.type==="reasoning")if(m)C.length===0&&(K=U.key),C.push(o.jsx(DF,{text:U.text,isStreaming:j===A.length-1&&v&&x},U.key));else{if(W(),p)continue;Q.push(o.jsxs("div",{className:"my-2 p-3 rounded-lg bg-gray-100 dark:bg-gray-800 border-l-4 border-amber-500 dark:border-amber-400",children:[o.jsxs("div",{className:"flex items-center gap-2 text-amber-600 dark:text-amber-400 text-xs font-medium uppercase tracking-wide",children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"})}),g("chat.thinking")]}),o.jsx("div",{className:"mt-2 prose prose-sm dark:prose-invert max-w-none break-words text-gray-600 dark:text-gray-300 italic opacity-80",children:o.jsx(Jo,{remarkPlugins:[tl,Ky],rehypePlugins:[$k],components:a,children:U.text})})]},U.key))}else if(U.type==="tool"){var ke=U.part.tool||U.part.state&&U.part.state.title||"",re=ke==="question";if(re){W();var X=U.part.callID||U.part.id||"",Ne=y&&y[X]?y[X]:null;Q.push(o.jsx("div",{className:"my-2",children:o.jsx(BB,{part:U.part,questionId:Ne})},U.key))}else m&&!f?(C.length===0&&(K=U.key),C.push(o.jsx(OF,{part:U.part},U.key))):(W(),Q.push(o.jsx("div",{className:`my-2 ${f?"hidden":""}`,children:o.jsx(LF,{part:U.part})},U.key)))}else U.type==="files"?(W(),Q.push(o.jsx("div",{className:Q.length>0?"mt-2":"",children:o.jsx("div",{className:"flex flex-wrap gap-2",children:U.parts.map(function(ve,me){return o.jsxs("div",{className:"inline-flex items-center gap-2 bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg px-3 py-2 text-sm max-w-xs",title:ve.mime||"",children:[o.jsx("svg",{className:"w-5 h-5 text-gray-500 dark:text-gray-400 flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,"aria-hidden":"true",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),o.jsx("span",{className:"truncate text-xs text-gray-700 dark:text-gray-300",children:ve.filename})]},ve.id||"file-"+me)})})},U.key))):U.type==="images"&&Q.push(o.jsx("div",{className:Q.length>0?"mt-2":"",children:o.jsx("div",{className:"flex flex-wrap gap-2",children:U.parts.map(function(ve,me){var pe=ve.image_url.url||ve.image_url;return o.jsx("a",{href:pe,target:"_blank",rel:"noopener noreferrer",children:o.jsx("img",{src:pe,alt:g("chat.attachment_with_index",{index:me+1}),className:"max-w-[200px] max-h-[200px] rounded-lg object-cover cursor-pointer hover:opacity-90 transition-opacity"})},ve.id||"img-"+me)})})},U.key))}return W(),Q}function Lo(e){return e==null?"":typeof e=="string"?e:typeof e=="number"?String(e):Array.isArray(e)?e.map(Lo).join(""):h.isValidElement(e)?Lo(e.props.children):""}function YB(e,t){if(!e)return"";var n=e.created||e.updated;if(!n)return"";var r=new Date(n);if(isNaN(r.getTime()))return"";var a=new Date,i=r.toDateString()===a.toDateString(),s=new Date(a);s.setDate(s.getDate()-1);var l=r.toDateString()===s.toDateString(),c=r.getHours(),u=r.getMinutes(),d=c>=12?"PM":"AM";c=c%12,c===0&&(c=12);var f=c+":"+(u<10?"0":"")+u+" "+d;if(i)return f;if(l)return t?t("chat.yesterday_time",{time:f}):"Yesterday "+f;var p=r.getMonth()+1,g=r.getDate();return p+"/"+g+" "+f}function QB(e,t,n,r,a){if(!t||!e)return o.jsx("p",{className:"text-sm whitespace-pre-wrap break-words",children:e});for(var i=e.toLowerCase(),s=t.toLowerCase(),l=[],c=0,u=0;;){var d=i.indexOf(s,c);if(d===-1)break;d>c&&l.push(e.substring(c,d));var f=n+u,p=f===r;l.push(o.jsx("mark",{ref:function(g){a(f,g)},className:p?"bg-accent-400 text-gray-900 rounded-sm px-0.5":"bg-yellow-200 dark:bg-yellow-700 text-gray-900 dark:text-gray-100 rounded-sm px-0.5",children:e.substring(d,d+t.length)},"m-"+u)),u++,c=d+t.length}return c<e.length&&l.push(e.substring(c)),o.jsx("p",{className:"text-sm whitespace-pre-wrap break-words",children:l})}function Jy(e,t,n,r,a,i){if(!e)return e;if(Array.isArray(e))return e.map(function(y,v){return o.jsx(h.Fragment,{children:Jy(y,t,n,r,a,i)},v)});if(typeof e=="string"){for(var s=e,l=s.toLowerCase(),c=t.toLowerCase(),u=[],d=0;;){var f=l.indexOf(c,d);if(f===-1)break;f>d&&u.push(s.substring(d,f));var p=n+r.current,g=p===a;u.push(o.jsx("mark",{ref:function(y){i(p,y)},className:g?"bg-accent-400 text-gray-900 rounded-sm px-0.5":"bg-yellow-200 dark:bg-yellow-700 text-gray-900 dark:text-gray-100 rounded-sm px-0.5",children:s.substring(f,f+t.length)},"m-"+r.current)),r.current++,d=f+t.length}return d<s.length&&u.push(s.substring(d)),u.length>0?u:s}if(h.isValidElement(e)){if(e.type==="code"||e.type===Bc)return e;if(e.props&&e.props.children!==void 0){var m=Jy(e.props.children,t,n,r,a,i);return h.cloneElement(e,void 0,m)}}return e}function XB({sessionID:e,banners:t,hidden:n,onToggle:r}){var[a,i]=h.useState(0),[s,l]=h.useState(!1);if(h.useRef(null),h.useEffect(function(){i(0)},[e,t&&t.length,t&&t[0]&&t[0].timestamp]),!e||!t||t.length===0)return null;if(n)return o.jsx("button",{type:"button",onClick:r,className:"w-full text-center text-xs text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 py-1 border-b border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-900/50 transition-colors","aria-label":"Show banner",children:"▾ Show banner"});var c=t[a]||t[0],u=function(){i(function(f){return Math.min(t.length-1,f+1)})},d=function(){i(function(f){return Math.max(0,f-1)})};return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"sticky top-0 z-10 bg-white dark:bg-gray-900 group border-b border-gray-200 dark:border-gray-800",children:o.jsxs("div",{className:"relative w-full overflow-hidden cursor-zoom-in",style:{aspectRatio:"16 / 9",maxHeight:"20vh"},onClick:function(){l(!0)},title:c.prompt||"Session banner",children:[o.jsx("img",{src:c.url,alt:c.prompt||"Session banner",className:"w-full h-full object-cover",loading:"lazy",draggable:!1}),c.prompt?o.jsx("div",{className:"absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/70 to-transparent text-white text-xs px-3 py-2 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none",children:o.jsx("div",{className:"line-clamp-2",children:c.prompt})}):null,t.length>1?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",onClick:function(f){f.stopPropagation(),u()},disabled:a>=t.length-1,className:"absolute left-1 top-1/2 -translate-y-1/2 bg-black/40 hover:bg-black/60 text-white rounded-full w-7 h-7 flex items-center justify-center disabled:opacity-30 opacity-0 group-hover:opacity-100 transition-opacity","aria-label":"Older banner",children:"‹"}),o.jsx("button",{type:"button",onClick:function(f){f.stopPropagation(),d()},disabled:a<=0,className:"absolute right-1 top-1/2 -translate-y-1/2 bg-black/40 hover:bg-black/60 text-white rounded-full w-7 h-7 flex items-center justify-center disabled:opacity-30 opacity-0 group-hover:opacity-100 transition-opacity","aria-label":"Newer banner",children:"›"}),o.jsx("div",{className:"absolute top-1 right-2 bg-black/40 text-white text-[10px] px-1.5 py-0.5 rounded opacity-0 group-hover:opacity-100 transition-opacity",children:a+1+" / "+t.length})]}):null]})}),s?o.jsxs("div",{className:"fixed inset-0 z-50 bg-black/85 flex items-center justify-center p-4 cursor-zoom-out",onClick:function(){l(!1)},children:[o.jsxs("div",{className:"max-w-5xl w-full",onClick:function(f){f.stopPropagation()},children:[o.jsx("img",{src:c.url,alt:c.prompt||"Session banner",className:"w-full h-auto rounded shadow-2xl",style:{aspectRatio:"16 / 9",objectFit:"cover"}}),c.prompt?o.jsx("div",{className:"text-white text-sm mt-3 px-2",children:c.prompt}):null,o.jsxs("div",{className:"text-white/60 text-xs mt-1 px-2",children:[new Date(c.timestamp).toLocaleString(),t.length>1?" · "+(a+1)+" of "+t.length:""]})]}),o.jsx("button",{type:"button",className:"absolute top-4 right-4 text-white text-2xl leading-none w-10 h-10 flex items-center justify-center rounded-full bg-white/10 hover:bg-white/20",onClick:function(){l(!1)},"aria-label":"Close",children:"×"})]}):null]})}var ZB=h.forwardRef(function({messages:t,streamingParts:n,streamingProgress:r,isBusy:a,compactingInfo:i,compactionResult:s,onSwitchToCompactedSession:l,onDismissCompactionResult:c,user:u,searchQuery:d,activeMatchIndex:f,onTotalMatchesChange:p,onRetry:g,onEditAndResend:m,onCancelQueued:y,hackerMode:v,mobileFrameless:x,hideThinking:b,sessionID:k,banners:N,bannerHidden:w,onToggleBanner:_,privateMessageIds:T,parentSessionID:A,onViewParentSession:D,compactionPinned:R,onUnpinCompaction:$,questionIdMap:F},G){const{t:P}=vt(),M=h.useRef(null),S=h.useRef(null),I=h.useRef(!0),B=h.useRef({}),[Q,C]=h.useState(!1);var K=function(){M.current&&M.current.scrollIntoView({behavior:"smooth"})};h.useImperativeHandle(G,function(){return{scrollToBottom:K,resetAutoScroll:function(){I.current=!0}}},[]);var W=h.useCallback(function(re,X){X?B.current[re]=X:delete B.current[re]},[]),j=h.useRef({}),U=h.useMemo(function(){if(!d)return{perMessage:{},total:0,_nextCache:{}};for(var re=d.toLowerCase(),X=0,Ne={},ve={},me=j.current,pe=0;pe<t.length;pe++){var Le=t[pe],Se=VB(Le.parts,n[Le.info.id],b),Te=Le.info.role==="assistant",Fe=Te?GB(Se):Se,fe=Fe.toLowerCase(),xe=Le.info.id,Ce=me[xe],ue;Ce&&Ce.text===fe&&Ce.query===re?ue=Ce.count:ue=JB(fe,re),ve[xe]={text:fe,query:re,count:ue},ue>0&&(Ne[Le.info.id]={offset:X,count:ue}),X+=ue}return{perMessage:Ne,total:X,_nextCache:ve}},[t,n,d,b]);h.useEffect(function(){j.current=U._nextCache},[U]);var le=h.useMemo(function(){return{perMessage:U.perMessage,total:U.total}},[U]);h.useEffect(function(){p&&p(le.total)},[le.total,p]),h.useEffect(function(){if(!(!d||le.total===0)){var re=requestAnimationFrame(function(){var X=B.current[f];X&&X.scrollIntoView({behavior:"smooth",block:"center"})});return function(){cancelAnimationFrame(re)}}},[f,d,le.total]),h.useEffect(function(){B.current={}},[d]),h.useEffect(function(){var re=S.current;if(re){var X=0,Ne=!1,ve=function(){X||(X=requestAnimationFrame(function(){if(X=0,!!S.current){var me=re.scrollTop,pe=re.scrollHeight,Le=re.clientHeight,Se=pe-me-Le;I.current=Se<80;var Te=Se>200;Te!==Ne&&(Ne=Te,C(Te))}}))};return re.addEventListener("scroll",ve),ve(),function(){re.removeEventListener("scroll",ve),X&&cancelAnimationFrame(X)}}},[]),h.useEffect(function(){!d&&I.current&&M.current&&M.current.scrollIntoView({behavior:"smooth"})},[t,n,d]);for(var Z=-1,ke=t.length-1;ke>=0;ke--)if(t[ke].info.role==="assistant"){Z=ke;break}return o.jsxs("div",{ref:S,className:"flex-1 overflow-y-auto overflow-x-hidden relative",children:[o.jsx(XB,{sessionID:k,banners:N,hidden:w,onToggle:_}),o.jsx(az,{sessionID:k,parentSessionID:A,onViewParentSession:D,compactionPinned:R,onUnpinCompaction:$,t:P}),o.jsx("div",{className:"px-2 sm:px-4 py-6",children:o.jsxs("div",{className:"max-w-full sm:max-w-3xl mx-auto space-y-6",children:[t.map(function(re,X){var Ne=le.perMessage[re.info.id]||null,ve=X===Z,me=re.info.role==="user",pe=re.info.compactedOut===!0,Le=X>0&&t[X-1].info.compactedOut===!0,Se=Le&&!pe;return o.jsxs(h.Fragment,{children:[Se?o.jsxs("div",{"data-testid":"compaction-boundary",className:"flex items-center gap-3 select-none",children:[o.jsx("div",{className:"flex-1 border-t border-dashed border-gray-300 dark:border-gray-700"}),o.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500 whitespace-nowrap",children:P&&P("compaction.boundary")||"Context compacted — messages above are no longer in the model’s context"}),o.jsx("div",{className:"flex-1 border-t border-dashed border-gray-300 dark:border-gray-700"})]},re.info.id+"-boundary"):null,o.jsx(nT,{isCompactedOut:pe,message:re.info,parts:re.parts,streamingParts:n[re.info.id],user:u,searchQuery:d,matchOffset:Ne?Ne.offset:-1,matchCount:Ne?Ne.count:0,activeMatchIndex:f,registerMatchRef:W,isLast:ve,isBusy:a,sessionID:k,onRetry:ve&&!a&&!pe?g:void 0,onEditAndResend:me&&!a&&!pe&&!tz(re.parts)?m:void 0,onCancelQueued:pe?void 0:y,hackerMode:v,mobileFrameless:x,hideThinking:b,isPrivate:T&&T.has(re.info.id),questionIdMap:F},re.info.id)]},re.info.id)}),a&&(x?!0:!ez(t,n,v,b))&&(x?o.jsx("div",{className:"flex justify-start py-2",children:o.jsxs("svg",{className:"w-4 h-4 text-gray-400 dark:text-gray-500 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[o.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),o.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}):o.jsxs("div",{className:"flex gap-3 justify-start",children:[o.jsx("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-primary-500 flex items-center justify-center mt-1",children:o.jsx("span",{className:"text-white font-bold text-xs",children:"P"})}),o.jsx("div",{className:"bg-gray-100 dark:bg-gray-800 rounded-2xl rounded-bl-md px-4 py-3",children:o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-400 dark:bg-gray-500 animate-bounce",style:{animationDelay:"0ms"}}),o.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-400 dark:bg-gray-500 animate-bounce",style:{animationDelay:"150ms"}}),o.jsx("span",{className:"w-2 h-2 rounded-full bg-gray-400 dark:bg-gray-500 animate-bounce",style:{animationDelay:"300ms"}})]})})]})),a&&!x&&r&&r.toolCalls>0&&o.jsxs("div",{className:"flex gap-3 justify-start",children:[o.jsx("div",{className:"flex-shrink-0 w-7 h-7 rounded-lg bg-accent-500 flex items-center justify-center mt-1",children:o.jsxs("svg",{className:"w-4 h-4 text-white animate-spin",fill:"none",viewBox:"0 0 24 24",children:[o.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),o.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}),o.jsxs("div",{className:"bg-gray-100 dark:bg-gray-800 rounded-2xl rounded-bl-md px-2 sm:px-4 py-3 min-w-0 max-w-[75%] sm:max-w-[320px]",children:[o.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[o.jsx("span",{className:"text-xs font-medium text-gray-600 dark:text-gray-300",children:nz(r.toolNames,P)}),o.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500 ml-2 tabular-nums",children:rz(r.toolArgBytes)})]}),o.jsx("div",{className:"h-1 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden",children:o.jsx("div",{className:"h-full bg-accent-500 rounded-full animate-progress-indeterminate",style:{width:"40%",animation:"progress-indeterminate 1.5s ease-in-out infinite"}})})]})]}),o.jsx("div",{ref:M})]})}),Q&&o.jsx("button",{onClick:K,"aria-label":P("chat.scroll_to_bottom"),className:"fixed bottom-24 left-1/2 -translate-x-1/2 z-10 w-9 h-9 rounded-full bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 shadow-lg flex items-center justify-center text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-primary-500 transition-all",title:P("chat.scroll_to_bottom"),children:o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 14l-7 7m0 0l-7-7m7 7V3"})})})]})});function JB(e,t){if(!t)return 0;for(var n=0,r=0;r=e.indexOf(t,r),r!==-1;)n++,r+=t.length;return n}function ez(e,t,n,r){var a=!n;for(var i of Object.keys(t)){var s=t[i];if(s){var l=Object.values(s).some(function(p){return p.type==="reasoning"&&r?!1:(p.type==="text"||p.type==="reasoning")&&(p.text||p.delta)});if(l)return!0}}for(var c=e.length-1;c>=0;c--){var u=e[c];if(u.info.role==="assistant"){var d=(u.parts||[]).some(function(p){return p.type==="reasoning"&&r?!1:(p.type==="text"||p.type==="reasoning")&&p.text}),f=(u.parts||[]).some(function(p){return p.type==="tool"});return d||a&&f}if(u.info.role==="user")break}return!1}function tz(e){return!e||!Array.isArray(e)?!1:e.some(function(t){return t.type==="image_url"||t.type==="file"})}function nz(e,t){if(!e||e.length===0)return t?t("chat.tool_preparing"):"Preparing tool call";var n={write:t?t("chat.tool_write"):"Writing file",edit:t?t("chat.tool_edit"):"Editing file",read:t?t("chat.tool_read"):"Reading file",bash:t?t("chat.tool_bash"):"Running command",glob:t?t("chat.tool_glob"):"Searching files",grep:t?t("chat.tool_grep"):"Searching code"},r=e[0],a=n[r]||(t?t("chat.tool_preparing_name",{name:r}):"Preparing "+r);return e.length>1&&(a+=" +"+(e.length-1)),a}function rz(e){return e<1024?e+" B":e<1024*1024?(e/1024).toFixed(1)+" KB":(e/1024/1024).toFixed(1)+" MB"}function az({sessionID:e,parentSessionID:t,onViewParentSession:n,compactionPinned:r,onUnpinCompaction:a,t:i}){var s="pave:compactionBannerDismissed:"+e,l=function(){try{return localStorage.getItem(s)==="1"}catch{return!1}},c=function(){try{localStorage.setItem(s,"1")}catch{}g(!0)},u=function(){n&&t&&n(t)},d=l(),f=h.useState(!d),p=f[0],g=f[1];return!t||p?null:o.jsx("div",{className:"px-2 sm:px-4 py-2 bg-blue-50 dark:bg-blue-900/20 border-b border-blue-200 dark:border-blue-800/50",children:o.jsxs("div",{className:"max-w-full sm:max-w-3xl mx-auto flex items-center gap-2",children:[o.jsx("svg",{className:"w-4 h-4 text-blue-500 dark:text-blue-400 flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2H7a2 2 0 00-2 2v2M9 11V7a3 3 0 016 0v4"})}),o.jsx("span",{className:"text-xs text-blue-700 dark:text-blue-300 flex-1 min-w-0",children:i&&i("compaction.banner_title")||"This session was compacted from a previous conversation."}),o.jsx("button",{type:"button",onClick:u,className:"text-xs font-medium text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-200 hover:underline focus:outline-none focus:underline transition-colors whitespace-nowrap flex-shrink-0",children:i&&i("compaction.view_original")||"View original"}),r?o.jsx("button",{type:"button",onClick:function(){a&&a(e)},className:"text-xs font-medium text-amber-600 dark:text-amber-400 hover:text-amber-800 dark:hover:text-amber-200 hover:underline focus:outline-none focus:underline transition-colors whitespace-nowrap flex-shrink-0",children:i&&i("chat.unpin_compacted")||"Unpin — go back to original"}):null,o.jsx("button",{type:"button",onClick:c,"aria-label":i&&i("compaction.dismiss")||"Dismiss",className:"text-blue-400 dark:text-blue-500 hover:text-blue-600 dark:hover:text-blue-300 flex-shrink-0 ml-1",children:o.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})})}const Qu=["image/png","image/jpeg","image/jpg","image/gif","image/webp"],rT=["text/plain","text/markdown","text/csv","application/json","application/xml","application/x-yaml","application/yaml","application/javascript","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/pdf","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel.sheet.macroenabled.12","application/vnd.oasis.opendocument.spreadsheet","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.ms-excel","application/msword","application/vnd.ms-powerpoint","application/rtf","text/rtf"],aT=[...Qu,...rT],xu=5,Jk=Math.floor(4*1024*1024/1.34),e_=5*1024*1024,t_=6*1024*1024,n_=Math.floor(4*1024*1024/1.34),iz=aT.join(",");function Lf(e){return e?Qu.indexOf(e.toLowerCase())!==-1:!1}class sz{constructor(t){t||(t={}),this._sampleRate=t.sampleRate||16e3,this._capacity=Math.max(1,Math.round((t.maxDuration||30)*this._sampleRate)),this._buffer=new Float32Array(this._capacity),this._start=0,this._length=0,this._totalAppended=0}get capacity(){return this._capacity}get length(){return this._length}get totalAppended(){return this._totalAppended}get sampleRate(){return this._sampleRate}append(t){if(!t||!(t instanceof Float32Array))throw new TypeError("append() requires a Float32Array argument");const n=t.length;if(n===0)return;if(this._totalAppended+=n,n>=this._capacity){const s=n-this._capacity;this._buffer.set(t.subarray(s,n)),this._start=0,this._length=this._capacity;return}const r=(this._start+this._length)%this._capacity,a=Math.min(n,this._capacity-r);this._buffer.set(t.subarray(0,a),r),a<n&&this._buffer.set(t.subarray(a,n),0);const i=this._length+n;if(i<=this._capacity)this._length=i;else{const s=i-this._capacity;this._start=(this._start+s)%this._capacity,this._length=this._capacity}}read(t,n){if(typeof t!="number"||t<0)throw new RangeError("read() offset must be >= 0, got "+t);if(typeof n!="number"||n<0)throw new RangeError("read() count must be >= 0, got "+n);if(t>=this._length||n===0)return new Float32Array(0);const r=Math.min(n,this._length-t),a=new Float32Array(r),i=(this._start+t)%this._capacity,s=Math.min(r,this._capacity-i);return a.set(this._buffer.subarray(i,i+s),0),s<r&&a.set(this._buffer.subarray(0,r-s),s),a}trimBefore(t){(typeof t!="number"||t<0)&&(t=0),t>this._length&&(t=this._length),this._start=(this._start+t)%this._capacity,this._length-=t}clear(){this._start=0,this._length=0,this._totalAppended=0}}var oz={AudioRingBuffer:sz};class lz{constructor(t){t||(t={}),this._sampleRate=t.sampleRate||16e3,this._chunkSamples=Math.round((t.chunkDuration||10)*this._sampleRate),this._overlapSamples=Math.round((t.overlapDuration||3)*this._sampleRate),this._minChunkSamples=Math.round((t.minChunkDuration||3)*this._sampleRate),this._maxInitialPrompt=t.maxInitialPrompt||200,this.reset()}get slotIndex(){return this._slotIndex}get pendingNewSamples(){return this._pendingNewSamples}get inflight(){return this._inflight}appendAndSchedule(t){if(this._inflight)return null;const n=t.totalAppended-this._lastSlotEndTotalAppended;this._pendingNewSamples=Math.max(0,n);const r=this._slotIndex===0?this._minChunkSamples:this._chunkSamples;return this._pendingNewSamples<r?null:this._cutSlot(t)}reportResult(t){this._inflight&&(this._inflight=!1,this._prevText=t||"")}drain(t){if(this._inflight)return null;const n=t.totalAppended-this._lastSlotEndTotalAppended;return n<=0?null:this._cutSlot(t,n)}reset(){this._slotIndex=0,this._inflight=!1,this._pendingNewSamples=0,this._lastSlotEndTotalAppended=0,this._prevText="",this._drained=!1}clearPrevText(){this._prevText=""}_cutSlot(t,n){const r=this._slotIndex===0,a=t.totalAppended-t.length,i=r?0:Math.min(this._overlapSamples,Math.max(0,this._lastSlotEndTotalAppended-a)),s=n!=null?Math.min(n,t.totalAppended-this._lastSlotEndTotalAppended):Math.min(this._pendingNewSamples,t.totalAppended-this._lastSlotEndTotalAppended),l=i+s,c=Math.max(0,this._lastSlotEndTotalAppended-a-i),u=t.read(c,l);let d="";this._prevText.length>0&&(d=this._prevText.length>this._maxInitialPrompt?this._prevText.slice(-this._maxInitialPrompt):this._prevText);const f={audio:u,overlapSamples:i,slotIndex:this._slotIndex,initialPrompt:d,chunkId:"slot-"+this._slotIndex};return this._lastSlotEndTotalAppended+=s,this._slotIndex++,this._inflight=!0,this._pendingNewSamples=0,f}}var cz={TranscriptionScheduler:lz};function uz(e,t){const n=e.length,r=t.length;if(n===0)return r;if(r===0)return n;let a=new Array(r+1),i=new Array(r+1);for(let s=0;s<=r;s++)a[s]=s;for(let s=1;s<=n;s++){i[0]=s;for(let c=1;c<=r;c++){const u=e[s-1]===t[c-1]?0:1;i[c]=Math.min(i[c-1]+1,a[c]+1,a[c-1]+u)}const l=a;a=i,i=l}return a[r]}function dz(e,t,n){if(!e)return t||"";if(!t)return"";const r=n&&n.maxOverlapChars||50,a=n&&typeof n.maxEditRatio=="number"?n.maxEditRatio:.2,i=Math.min(r,e.length,t.length);for(let s=i;s>=1;s--){const l=e.slice(-s),c=t.slice(0,s);if(uz(l,c)/s<=a)return t.slice(s)}return t}var fz={dedupOverlap:dz};const Qi=16e3,pz=10,gz=3,hz=3,mz=200,r_=3,Of=2,yz=1e3,a_=.01,xz=1500;function i_(e){if(!e||e.length===0)return 0;let t=0;for(let n=0;n<e.length;n++){const r=e[n];t+=r*r}return Math.sqrt(t/e.length)}function bz(e,t){const n=e.sampleRate,r=e.getChannelData(0);if(n===t)return new Float32Array(r);const a=n/t,i=Math.round(r.length/a),s=new Float32Array(i);for(let l=0;l<i;l+=1){const c=l*a,u=Math.floor(c),d=Math.min(u+1,r.length-1),f=c-u;s[l]=r[u]*(1-f)+r[d]*f}return s}function vz(e,t){const a=t*1*2,i=1*(16/8),s=e.length*i,l=new ArrayBuffer(44+s),c=new DataView(l);let u=0;for(let d=0;d<4;d++)c.setUint8(u++,"RIFF".charCodeAt(d));c.setUint32(u,36+s,!0),u+=4;for(let d=0;d<4;d++)c.setUint8(u++,"WAVE".charCodeAt(d));for(let d=0;d<4;d++)c.setUint8(u++,"fmt ".charCodeAt(d));c.setUint32(u,16,!0),u+=4,c.setUint16(u,1,!0),u+=2,c.setUint16(u,1,!0),u+=2,c.setUint32(u,t,!0),u+=4,c.setUint32(u,a,!0),u+=4,c.setUint16(u,i,!0),u+=2,c.setUint16(u,16,!0),u+=2;for(let d=0;d<4;d++)c.setUint8(u++,"data".charCodeAt(d));c.setUint32(u,s,!0),u+=4;for(let d=0;d<e.length;d++){const f=Math.max(-1,Math.min(1,e[d]));c.setInt16(u,f<0?f*32768:f*32767,!0),u+=2}return new Blob([l],{type:"audio/wav"})}function kz({onTranscript:e,onError:t,onAutoSubmit:n,language:r,model:a}){const[i,s]=h.useState("idle"),[l,c]=h.useState(0),[u,d]=h.useState(null),[f,p]=h.useState(null),[g,m]=h.useState(""),y=h.useRef(null),v=h.useRef(null),x=h.useRef(null),b=h.useRef(null),k=h.useRef(!1),N=h.useRef(null),w=h.useRef(null),_=h.useRef(null),T=h.useRef(null),A=h.useRef(null),D=h.useRef(null),R=h.useRef(0),$=h.useRef(!1),F=h.useRef(""),G=h.useRef(!1),P=h.useRef(null),M=h.useRef("idle"),S=h.useCallback(fe=>{M.current=fe,s(fe)},[]),I=h.useRef(e),B=h.useRef(t),Q=h.useRef(n),C=h.useRef(r),K=h.useRef(a);h.useEffect(()=>{I.current=e},[e]),h.useEffect(()=>{B.current=t},[t]),h.useEffect(()=>{Q.current=n},[n]),h.useEffect(()=>{C.current=r},[r]),h.useEffect(()=>{K.current=a},[a]),h.useEffect(()=>{T.current&&(M.current==="recording"||M.current==="paused")&&T.current.clearPrevText()},[r]);const W=h.useCallback(()=>A.current?Promise.resolve(A.current):(D.current||(D.current=Zy().then(fe=>(A.current=fe,fe)).catch(()=>{const fe={mode:"auto",backendAvailable:!1};return A.current=fe,fe})),D.current),[]);h.useEffect(()=>{W()},[W]);const j=h.useCallback(()=>{N.current&&(N.current.getTracks().forEach(fe=>fe.stop()),N.current=null)},[]),U=h.useCallback(()=>{y.current&&(y.current.terminate(),y.current=null)},[]),le=h.useCallback(()=>{const fe=x.current,xe=v.current,Ce=b.current;if(fe){try{fe.disconnect()}catch{}fe.onaudioprocess=null,x.current=null}if(xe){try{xe.disconnect()}catch{}v.current=null}if(Ce){try{Ce.disconnect()}catch{}b.current=null}k.current=!1,j(),w.current&&w.current.state!=="closed"&&(w.current.close().catch(()=>{}),w.current=null),U(),_.current&&_.current.clear(),T.current&&T.current.reset(),R.current=0},[j,U]),Z=h.useRef(null),ke=h.useRef(null),re=h.useRef(null),X=h.useRef(null),Ne=h.useRef(null),ve=h.useRef(null);Z.current=function(xe){const Ce=xe&&xe.text||"";xe&&xe.chunkId;const ue=T.current,he=xe&&xe._silent;ue&&ue.reportResult(Ce);const _e=fz.dedupOverlap(F.current,Ce);if(_e){const Pe=F.current+_e;F.current=Pe,m(Pe),I.current&&I.current(_e)}if(R.current=0,(he||Ce.trim()==="")&&F.current.trim()&&Q.current&&Q.current(),M.current==="draining"&&ue&&!ue.inflight){const Pe=_.current,Xe=ue.drain(Pe);Xe?X.current(Xe):ve.current();return}re.current()},ke.current=function(xe){const Ce=T.current;if(Ce&&Ce.reportResult(""),R.current+=1,console.warn("[useContinuousVoiceInput] Chunk transcription error:",xe,"("+R.current+"/"+r_+")"),R.current>=r_){le(),S("idle"),B.current&&B.current("Voice transcription failed repeatedly. Please try again.");return}if(M.current==="draining"&&Ce&&!Ce.inflight){ve.current();return}re.current()},re.current=function(){const xe=T.current,Ce=_.current;if(!xe||!Ce)return;const ue=M.current;if(ue!=="recording"&&ue!=="paused"&&ue!=="draining")return;const he=xe.appendAndSchedule(Ce);if(he){X.current(he);return}if((ue==="paused"||ue==="draining")&&!xe.inflight){const _e=xe.drain(Ce);_e?X.current(_e):ue==="draining"&&ve.current()}},X.current=async function(xe){const Ce=i_(xe.audio);if(Ce<a_){console.debug("[useContinuousVoiceInput] Skipping silent chunk (RMS="+Ce.toFixed(6)+")"),Z.current({text:"",chunkId:xe.chunkId,_silent:!0});return}const ue=A.current||{mode:"auto",backendAvailable:!1},he=ue.backendAvailable&&ue.mode!=="local-only",_e=ue.mode!=="backend-only",Pe=C.current,Xe=K.current;if(he&&!$.current){const te=vz(xe.audio,Qi),ce={};xe.initialPrompt&&(ce.initialPrompt=xe.initialPrompt);let je=null;for(let Be=0;Be<=Of;Be++)try{const Ke=await AB(te,Pe,Xe,ce);if(typeof Ke.text=="string"){p("backend"),Z.current({text:Ke.text,chunkId:xe.chunkId});return}}catch(Ke){je=Ke;const Ye=Ke.status;if((Ye===429||Ye===503)&&Be<Of){const ot=yz*2**Be;console.warn("[useContinuousVoiceInput] Backend "+Ye+", retrying in "+ot+"ms (attempt "+(Be+1)+"/"+Of+")"),await new Promise(Rt=>{setTimeout(Rt,ot)});continue}(Ye===429||Ye===503)&&($.current=!0,console.warn("[useContinuousVoiceInput] Backend throttled (429/503), falling back to local for rest of recording"));break}if(!_e){ke.current(je?je.message:"Backend transcription failed");return}console.warn("[useContinuousVoiceInput] Backend chunk failed, trying local:",je?je.message:"unknown")}if(!_e){ke.current("Backend transcription is not available and local mode is disabled.");return}const H=Ne.current();p("local");const z={type:"transcribe",audio:xe.audio};Pe&&(z.language=Pe),xe.initialPrompt&&(z.initialPrompt=xe.initialPrompt),xe.chunkId&&(z.chunkId=xe.chunkId),H.postMessage(z,[xe.audio.buffer])},Ne.current=function(){if(y.current)return y.current;const xe=new Worker(new URL("/assets/whisper-worker-Dtk1MkQa.js",import.meta.url),{type:"module"});return xe.onmessage=Ce=>{const ue=Ce.data;if(ue)switch(ue.type){case"loading":c(ue.progress||0),d(ue.file?ue.file.split("/").pop():null);break;case"ready":M.current==="loading"&&S("recording"),c(100),d(null);break;case"result":Z.current(ue);break;case"error":ke.current(ue.error||"Transcription failed");break}},xe.onerror=()=>{const Ce=T.current;Ce&&Ce.reportResult(""),R.current+=1,U();const ue=new Worker(new URL("/assets/whisper-worker-Dtk1MkQa.js",import.meta.url),{type:"module"});ue.onmessage=he=>{const _e=he.data;if(_e)switch(_e.type){case"loading":c(_e.progress||0),d(_e.file?_e.file.split("/").pop():null);break;case"ready":M.current==="loading"&&S("recording"),c(100),d(null),re.current();break;case"result":Z.current(_e);break;case"error":ke.current(_e.error||"Transcription failed");break}},ue.onerror=()=>{ue.terminate(),y.current=null,le(),S("idle"),F.current="",m(""),B.current&&B.current("Voice transcription worker crashed.")},y.current=ue},y.current=xe,xe},ve.current=function(){const xe=y.current;xe&&xe.postMessage({type:"unload"}),w.current&&w.current.state!=="closed"&&(w.current.close().catch(()=>{}),w.current=null),T.current&&T.current.reset(),_.current&&_.current.clear(),S("idle")};const me=h.useCallback(async()=>{if(M.current==="idle"){if(!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia){B.current&&B.current("Microphone access is not supported in this browser.");return}if(typeof AudioContext>"u"&&typeof webkitAudioContext>"u"){B.current&&B.current("Audio recording is not supported in this browser.");return}try{const fe=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,sampleRate:Qi,echoCancellation:!0,noiseSuppression:!0}});N.current=fe;const xe=await W(),Ce=xe.mode==="local-only"||!xe.backendAvailable&&xe.mode!=="backend-only",ue=window.AudioContext||window.webkitAudioContext;(!w.current||w.current.state==="closed")&&(w.current=new ue);const he=w.current;_.current=new oz.AudioRingBuffer({maxDuration:30,sampleRate:Qi}),T.current=new cz.TranscriptionScheduler({chunkDuration:pz,overlapDuration:gz,minChunkDuration:hz,sampleRate:Qi,maxInitialPrompt:mz}),F.current="",m(""),R.current=0,$.current=!1,G.current=!1,P.current=null;const _e=he.createMediaStreamSource(fe),Xe=he.createScriptProcessor(4096,1,1),H=he.createGain();H.gain.value=0,_e.connect(Xe),Xe.connect(H),H.connect(he.destination),v.current=_e,x.current=Xe,b.current=H,k.current=!1,Xe.onaudioprocess=z=>{if(k.current)return;const te=z.inputBuffer,ce=te.sampleRate,je=te.getChannelData(0);let Be;if(ce===Qi?Be=new Float32Array(je):Be=bz({sampleRate:ce,getChannelData:()=>je},Qi),Be.length===0)return;const Ke=_.current;Ke&&Ke.append(Be);const Ye=i_(Be),ot=performance.now();if(Ye>=a_)G.current=!0,P.current=null;else if(G.current){if(!P.current)P.current=ot;else if(ot-P.current>=xz){G.current=!1,P.current=null;const Rt=T.current;if(Rt&&!Rt.inflight&&Ke){const mt=Rt.drain(Ke);mt&&X.current(mt)}}}re.current()},Ce?(S("loading"),c(0),Ne.current().postMessage({type:"load"})):(S("recording"),c(100))}catch(fe){j(),S("idle");const xe=fe.name==="NotAllowedError"?"Microphone permission was denied. Please allow microphone access.":"Could not access microphone: "+(fe.message||String(fe));B.current&&B.current(xe)}}},[W,j]),pe=h.useCallback(()=>{const fe=M.current;if(fe==="loading"){le(),U(),S("idle");return}if(fe!=="recording"&&fe!=="paused")return;const xe=x.current,Ce=v.current,ue=b.current;if(xe){try{xe.disconnect()}catch{}xe.onaudioprocess=null,x.current=null}if(Ce){try{Ce.disconnect()}catch{}v.current=null}if(ue){try{ue.disconnect()}catch{}b.current=null}j(),S("draining"),setTimeout(()=>{const he=T.current,_e=_.current;if(!he||!_e){ve.current();return}if(!he.inflight){const Pe=he.drain(_e);Pe?X.current(Pe):ve.current()}},0)},[j,le,U]),Le=h.useCallback(()=>{M.current==="recording"&&(k.current=!0,S("paused"),re.current())},[]),Se=h.useCallback(()=>{M.current==="paused"&&(k.current=!1,S("recording"))},[]),Te=h.useCallback(()=>{M.current!=="idle"&&(le(),U(),F.current="",m(""),S("idle"))},[le,U]),Fe=h.useCallback(()=>{if(M.current!=="idle"){B.current&&B.current("Cannot clear cache while recording.");return}S("loading"),c(0),U(),Ne.current().postMessage({type:"clearCache"})},[U]);return h.useEffect(()=>()=>{le(),U()},[le,U]),{state:i,progress:l,downloadingFile:u,transcriptionSource:f,transcriptText:g,startRecording:me,stopRecording:pe,pauseRecording:Le,resumeRecording:Se,cancelRecording:Te,clearModelCache:Fe}}function _z({skills:e,builtins:t,filter:n,onSelect:r,visible:a,selectedIndex:i,activeSkill:s,onBack:l}){const{t:c}=vt(),u=h.useRef(null),d=h.useRef(null);if(h.useEffect(()=>{u.current&&u.current.scrollIntoView({block:"nearest"})},[i,s,n,e.length]),!a)return null;const f=(n||"").trim().toLowerCase();let p=[],g=!1;if(s){g=!0;const m=e.find(v=>v.skill===s);p=(m&&m.commands||[]).filter(v=>f?(v.name||"").toLowerCase().includes(f)||(v.description||"").toLowerCase().includes(f):!0).map(v=>({type:"command",skill:s,name:v.name,description:v.description}))}else{const m=(t||[]).filter(v=>f?(v.name||"").toLowerCase().includes(f)||(v.description||"").toLowerCase().includes(f):!0).map(v=>({type:"builtin",name:v.name,description:v.description})),y=e.filter(v=>f?(v.skill||"").toLowerCase().includes(f)||(v.description||"").toLowerCase().includes(f)||(v.commands||[]).some(x=>(x.name||"").toLowerCase().includes(f)||(x.description||"").toLowerCase().includes(f)):!0).map(v=>({type:"skill",skill:v.skill,description:v.description,commandCount:(v.commands||[]).length,configured:v.configured}));p=m.concat(y)}return o.jsxs("div",{className:"absolute bottom-full left-0 right-0 mb-1 bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg overflow-hidden z-50 flex flex-col",style:{maxHeight:"40vh"},children:[o.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 border-b border-gray-100 dark:border-gray-800 text-xs text-gray-500 dark:text-gray-400",role:"presentation",children:[g&&o.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1 hover:text-gray-700 dark:hover:text-gray-200 transition-colors","aria-label":c("slashCommand.back"),children:[o.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 19l-7-7 7-7"})}),c("slashCommand.skills")]}),o.jsx("span",{className:"flex-1 text-right",children:g?s+" "+c("slashCommand.commands"):c("slashCommand.title")})]}),o.jsx("div",{ref:d,className:"flex-1 min-h-0 overflow-y-auto",id:"slash-command-listbox",role:"listbox","aria-label":s?c("slashCommand.commands")+" — "+s:c("slashCommand.title"),children:p.length===0?o.jsx("div",{className:"px-3 py-4 text-sm text-gray-400 dark:text-gray-500 text-center",children:c("slashCommand.noResults")}):p.map((m,y)=>{const v=y===i,x="slash-item-"+y;return o.jsx("div",{id:x,ref:v?u:null,role:"option","aria-selected":v,onClick:()=>{m.type==="skill"?r(m.skill,null):m.type==="builtin"?r("__builtin__",m.name):r(m.skill,m.name)},className:"flex items-center gap-3 px-3 py-2 cursor-pointer text-sm transition-colors "+(v?"bg-accent-50 dark:bg-accent-900/30 text-accent-700 dark:text-accent-300":"hover:bg-gray-50 dark:hover:bg-gray-800 text-gray-700 dark:text-gray-300"),children:m.type==="builtin"?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"flex-shrink-0 w-6 h-6 rounded bg-accent-100 dark:bg-accent-900/40 flex items-center justify-center",children:o.jsx("svg",{className:"w-3.5 h-3.5 text-accent-600 dark:text-accent-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsxs("span",{className:"font-medium",children:["/",m.name]}),o.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:"built-in"})]}),m.description&&o.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 truncate",children:m.description})]})]}):m.type==="skill"?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"flex-shrink-0 w-6 h-6 rounded bg-gray-100 dark:bg-gray-800 flex items-center justify-center text-xs font-medium text-gray-500 dark:text-gray-400",children:(m.skill||"?")[0].toUpperCase()}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"font-medium truncate",children:m.skill}),!m.configured&&o.jsx("span",{className:"text-xs text-yellow-600 dark:text-yellow-400",children:c("slashCommand.notConfigured")})]}),m.description&&o.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 truncate",children:m.description})]}),o.jsxs("div",{className:"flex-shrink-0 text-xs text-gray-400 dark:text-gray-500",children:[m.commandCount," ",m.commandCount===1?c("slashCommand.command"):c("slashCommand.commands")]}),o.jsx("svg",{className:"w-4 h-4 text-gray-400 flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})})]}):o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"flex-shrink-0 w-6 h-6 rounded bg-accent-100 dark:bg-accent-900/40 flex items-center justify-center",children:o.jsx("svg",{className:"w-3.5 h-3.5 text-accent-600 dark:text-accent-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})})}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsxs("span",{className:"font-medium",children:["/",s," ",m.name]}),m.description&&o.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 truncate",children:m.description})]})]})},m.type+"-"+(m.skill||"_")+"-"+(m.name||""))})}),o.jsxs("div",{className:"flex-shrink-0 px-3 py-1.5 border-t border-gray-100 dark:border-gray-800 text-xs text-gray-400 dark:text-gray-500 flex gap-3",role:"presentation",children:[o.jsxs("span",{children:[o.jsx("kbd",{className:"px-1 py-0.5 bg-gray-100 dark:bg-gray-800 rounded text-xs",children:"↑↓"})," ",c("slashCommand.navigate")]}),o.jsxs("span",{children:[o.jsx("kbd",{className:"px-1 py-0.5 bg-gray-100 dark:bg-gray-800 rounded text-xs",children:"Enter"})," ",c("slashCommand.select")]}),o.jsxs("span",{children:[o.jsx("kbd",{className:"px-1 py-0.5 bg-gray-100 dark:bg-gray-800 rounded text-xs",children:"Esc"})," ",c("slashCommand.close")]})]})]})}const zc=[{name:"btw",description:"By the way… — fork the current session and continue in a new one",takesArgs:!0},{name:"compact",description:"Compact the current session — summarize history into a new, shorter session",takesArgs:!1}];function wz(){return zc.slice()}function Ez(e){if(!e)return null;const t=String(e).toLowerCase();for(let n=0;n<zc.length;n++)if(zc[n].name===t)return zc[n];return null}function Nz(e){if(typeof e!="string")return null;const t=e.trim();if(!t.startsWith("/"))return null;const n=t.match(/^\/([a-zA-Z0-9_-]+)(?:\s+([\s\S]*))?$/);if(!n)return null;const r=n[1].toLowerCase(),a=Ez(r);if(!a)return null;const i=(n[2]||"").trim();return{name:r,args:i,builtin:a}}const oi="pave-draft-",Sz=h.forwardRef(function({onSend:t,onAbort:n,isBusy:r,disabled:a,sessionId:i,queuedCount:s=0,onBuiltinCommand:l},c){const{t:u}=vt(),[d,f]=h.useState(""),[p,g]=h.useState([]),[m,y]=h.useState(!1);h.useEffect(()=>{const ae=()=>y(!1);return window.addEventListener("pave:plan-execute",ae),()=>window.removeEventListener("pave:plan-execute",ae)},[]);const[v,x]=h.useState(null),[b,k]=h.useState([]),[N,w]=h.useState(""),[_,T]=h.useState(!1),A=h.useRef(null),D=h.useRef([]),[R,$]=h.useState(-1),F="pave-asr-language",G=[{code:"auto",label:"Auto"},{code:"en",label:"English"},{code:"yue",label:"粵語"},{code:"zh",label:"普通話"},{code:"ja",label:"日本語"},{code:"ko",label:"한국어"},{code:"es",label:"Español"},{code:"fr",label:"Français"},{code:"de",label:"Deutsch"},{code:"fi",label:"Suomi"}],[P,M]=h.useState(()=>{try{return localStorage.getItem(F)||"auto"}catch{return"auto"}}),[S,I]=h.useState(!1),B=h.useRef(null),Q=h.useRef(p),C=h.useRef(null),K=h.useRef(null),W=h.useRef(null),j=h.useRef(i),U=h.useRef(d),le=h.useRef(null),[Z,ke]=h.useState(!1),[re,X]=h.useState(""),[Ne,ve]=h.useState([]),[me,pe]=h.useState(0),[Le,Se]=h.useState(null),Te=h.useRef({data:null,time:0}),Fe=6e4,fe=h.useCallback(ae=>{x(ae),le.current&&clearTimeout(le.current),le.current=setTimeout(()=>x(null),5e3)},[]);h.useEffect(()=>()=>{le.current&&clearTimeout(le.current)},[]),h.useLayoutEffect(()=>{U.current=d},[d]),h.useLayoutEffect(()=>{j.current=i,W.current&&(clearTimeout(W.current),W.current=null);let ae="";if(i)try{ae=localStorage.getItem(oi+i)||""}catch{}return f(ae),U.current=ae,g(Ie=>(Ie.forEach(De=>{De.preview&&URL.revokeObjectURL(De.preview)}),[])),()=>{W.current&&(clearTimeout(W.current),W.current=null);const Ie=j.current;if(Ie)try{U.current?localStorage.setItem(oi+Ie,U.current):localStorage.removeItem(oi+Ie)}catch{}}},[i]),h.useEffect(()=>{j.current&&(W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{try{d?localStorage.setItem(oi+j.current,d):localStorage.removeItem(oi+j.current)}catch{}},300))},[d]);const xe=h.useCallback(async()=>{const ae=Te.current;if(ae.data&&Date.now()-ae.time<Fe){ve(ae.data);return}try{const Ie=await lB(),De=Array.isArray(Ie)?Ie:[];Te.current={data:De,time:Date.now()},ve(De)}catch{ve([])}},[]),Ce=h.useMemo(()=>wz(),[]),ue=h.useMemo(()=>{const ae=(re||"").trim().toLowerCase();if(Le){const Ve=Ne.find(et=>et.skill===Le);return(Ve&&Ve.commands||[]).filter(et=>ae?(et.name||"").toLowerCase().includes(ae)||(et.description||"").toLowerCase().includes(ae):!0).map(et=>({type:"command",skill:Le,name:et.name}))}const Ie=Ce.filter(Ve=>ae?(Ve.name||"").toLowerCase().includes(ae)||(Ve.description||"").toLowerCase().includes(ae):!0).map(Ve=>({type:"builtin",name:Ve.name})),De=Ne.filter(Ve=>ae?(Ve.skill||"").toLowerCase().includes(ae)||(Ve.description||"").toLowerCase().includes(ae)||(Ve.commands||[]).some(ft=>(ft.name||"").toLowerCase().includes(ae)||(ft.description||"").toLowerCase().includes(ae)):!0).map(Ve=>({type:"skill",skill:Ve.skill}));return Ie.concat(De)},[re,Le,Ne,Ce]),he=h.useCallback(()=>ue.length,[ue]),_e=h.useCallback(ae=>{if(f(ae),U.current=ae,ae.startsWith("/")){const Ie=ae.slice(1),De=Ie.split(/\s/)[0]||"";if(!De.includes("/")&&!De.includes(".")){if(Le){const Ve=Le+" ";Ie.startsWith(Ve)?(X(Ie.slice(Ve.length)),pe(0)):(Se(null),X(Ie),pe(0))}else X(Ie),pe(0);Z||(xe(),ke(!0),pe(0))}else ke(!1),X(""),Se(null),pe(0)}else ke(!1),X(""),Se(null),pe(0)},[Z,Le,xe]),Pe=h.useCallback((ae,Ie)=>{var De,Ve,ft;if(ae==="__builtin__"&&Ie){f("/"+Ie+" "),ke(!1),X(""),Se(null),pe(0),(De=C.current)==null||De.focus();return}if(!Ie)Se(ae),X(""),pe(0),f("/"+ae+" "),(Ve=C.current)==null||Ve.focus();else{const et="/"+ae+" "+Ie+" ";f(et),ke(!1),X(""),Se(null),pe(0),(ft=C.current)==null||ft.focus()}},[]),Xe=h.useCallback(()=>{var ae;Se(null),X(""),pe(0),f("/"),(ae=C.current)==null||ae.focus()},[]),H=h.useCallback(ae=>{f(Ie=>{const De=Ie&&!Ie.endsWith(" ")&&!Ie.endsWith(`
102
102
  `)?" ":"";return Ie+De+ae})},[]),z=h.useRef(null),te=h.useCallback(()=>{setTimeout(()=>{z.current&&z.current()},50)},[]),{state:ce,progress:je,downloadingFile:Be,startRecording:Ke,stopRecording:Ye,resumeRecording:ot,cancelRecording:Rt}=kz({onTranscript:H,onError:fe,onAutoSubmit:te,model:N||void 0,language:P&&P!=="auto"?P:void 0});h.useEffect(()=>{try{P&&localStorage.setItem(F,P)}catch{}},[P]),h.useEffect(()=>{if(!S)return;const ae=Ie=>{B.current&&!B.current.contains(Ie.target)&&I(!1)};return document.addEventListener("mousedown",ae),()=>document.removeEventListener("mousedown",ae)},[S]),h.useEffect(()=>{let ae=!1;return Zy().then(Ie=>{ae||Ie&&Array.isArray(Ie.models)&&Ie.models.length>0&&(k(Ie.models),w(De=>De||Ie.models[0].name))}).catch(()=>{}),()=>{ae=!0}},[Zy]),h.useEffect(()=>{if(!_){$(-1);return}D.current.length=b.length;function ae(De){A.current&&!A.current.contains(De.target)&&T(!1)}function Ie(De){if(De.key==="Escape"){T(!1);return}De.key!=="ArrowDown"&&De.key!=="ArrowUp"&&De.key!=="Home"&&De.key!=="End"||(De.preventDefault(),$(Ve=>{const ft=D.current.length;if(!ft)return Ve;const et=typeof Ve=="number"?Ve:-1;let Qe=et;return De.key==="ArrowDown"?Qe=et<ft-1?et+1:0:De.key==="ArrowUp"?Qe=et>0?et-1:ft-1:De.key==="Home"?Qe=0:De.key==="End"&&(Qe=ft-1),D.current[Qe]&&D.current[Qe].focus(),Qe}))}return document.addEventListener("mousedown",ae),document.addEventListener("keydown",Ie),()=>{document.removeEventListener("mousedown",ae),document.removeEventListener("keydown",Ie)}},[_,b.length]),h.useEffect(()=>{const ae=C.current;ae&&(ae.style.height="auto",ae.style.height=Math.min(ae.scrollHeight,200)+"px")},[d]),h.useEffect(()=>{Q.current=p},[p]),h.useEffect(()=>{var ae;(ae=C.current)==null||ae.focus()},[]),h.useImperativeHandle(c,()=>({focus:()=>{var ae;(ae=C.current)==null||ae.focus()},setText:ae=>{f(typeof ae=="string"?ae:""),requestAnimationFrame(()=>{var Ie;return(Ie=C.current)==null?void 0:Ie.focus()})}}),[]);const mt=async()=>{const ae=d.trim();var Ie=p.filter(function(et){return Lf(et.type)}),De=p.filter(function(et){return!Lf(et.type)});const Ve=Nz(ae);if(Ve&&typeof l=="function"){const et=j.current;try{await l(Ve.name,Ve.args,{imageAttachments:Ie.length>0?Ie:void 0,fileAttachments:De.length>0?De:void 0})}catch{return}if(f(""),ke(!1),X(""),Se(null),pe(0),et)try{localStorage.removeItem(oi+et)}catch{}p.forEach(function(Qe){Qe.preview&&URL.revokeObjectURL(Qe.preview)}),g([]),C.current&&(C.current.style.height="auto");return}if(!ae&&Ie.length===0&&De.length===0)return;const ft=j.current;try{await t(ae,Ie.length>0?Ie:void 0,m?"plan":void 0,De.length>0?De:void 0)}catch{return}if(f(""),ke(!1),X(""),Se(null),pe(0),ft)try{localStorage.removeItem(oi+ft)}catch{}p.forEach(function(et){et.preview&&URL.revokeObjectURL(et.preview)}),g([]),C.current&&(C.current.style.height="auto")};z.current=mt;const Mt=ae=>{if(Z){const Ie=he();if(ae.key==="ArrowDown"){Ie>0&&(ae.preventDefault(),pe(De=>(De+1)%Ie));return}if(ae.key==="ArrowUp"){Ie>0&&(ae.preventDefault(),pe(De=>(De-1+Ie)%Ie));return}if(ae.key==="Enter"||ae.key==="Tab"){if(Ie>0){ae.preventDefault();const De=ue[me];De&&(De.type==="command"?Pe(De.skill,De.name):De.type==="builtin"?Pe("__builtin__",De.name):Pe(De.skill,null));return}if(ae.key==="Tab"){ke(!1),X(""),Se(null),pe(0);return}}if(ae.key==="Escape"){ae.preventDefault(),ke(!1),X(""),Se(null),pe(0);return}if(ae.key==="Backspace"&&Le){const De=d.slice(1),Ve=Le+" ";if(De===Ve||De===Le){ae.preventDefault(),Xe();return}}}ae.key==="Enter"&&!ae.shiftKey&&(ae.preventDefault(),mt())},de=ae=>{if(!a){var Ie=ae.clipboardData&&ae.clipboardData.items;if(Ie){for(var De=[],Ve=0;Ve<Ie.length;Ve++){var ft=(Ie[Ve].type||"").toLowerCase();if(Qu.indexOf(ft)!==-1){var et=Ie[Ve].getAsFile();et&&De.push(et)}}if(De.length!==0){for(var Qe=!1,Xt=0;Xt<Ie.length;Xt++)if(Ie[Xt].type&&Ie[Xt].type.startsWith("text/")){Qe=!0;break}Qe||ae.preventDefault();var oe=De.map(function(jt){return{id:Date.now()+"-"+Math.random().toString(36).slice(2,8),file:jt,name:jt.name||"pasted-image.png",size:jt.size,type:jt.type,preview:null}});g(function(jt){var ct=xu-jt.length;if(ct<=0)return jt;for(var wt=oe.slice(0,ct),gt=0;gt<wt.length;gt++)wt[gt].preview=URL.createObjectURL(wt[gt].file);return jt.concat(wt)})}}}},We=ae=>{const Ie=Array.from(ae.target.files||[]);if(Ie.length===0)return;const De=Ie.filter(ft=>aT.indexOf(ft.type)!==-1);if(De.length===0){ae.target.value="";return}const Ve=De.map(ft=>({id:Date.now()+"-"+Math.random().toString(36).slice(2,8),file:ft,name:ft.name,size:ft.size,type:ft.type,preview:null}));g(ft=>{var et=xu-ft.length;if(et<=0)return ft;for(var Qe=Ve.slice(0,et),Xt=0;Xt<Qe.length;Xt++)Qe[Xt].preview=Lf(Qe[Xt].file.type)?URL.createObjectURL(Qe[Xt].file):null;return[...ft,...Qe]}),ae.target.value=""},nt=ae=>{g(Ie=>{const De=Ie.find(Ve=>Ve.id===ae);return De!=null&&De.preview&&URL.revokeObjectURL(De.preview),Ie.filter(Ve=>Ve.id!==ae)})},yt=ae=>ae<1024?ae+" B":ae<1024*1024?(ae/1024).toFixed(1)+" KB":(ae/(1024*1024)).toFixed(1)+" MB";return h.useEffect(()=>()=>{Q.current.forEach(ae=>{ae.preview&&URL.revokeObjectURL(ae.preview)})},[]),o.jsx("div",{className:"border-t border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-950 px-2 sm:px-4 py-3",children:o.jsxs("div",{className:"max-w-full sm:max-w-3xl mx-auto",children:[m&&o.jsxs("div",{className:"flex items-center gap-2 mb-2 px-3 py-1.5 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg text-xs text-amber-700 dark:text-amber-300",children:[o.jsx("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z"})}),o.jsx("span",{children:"Plan mode -- read-only. The agent will analyze and plan without making changes."})]}),p.length>0&&o.jsx("div",{className:"flex flex-wrap gap-2 mb-2 overflow-hidden",children:p.map(ae=>o.jsxs("div",{className:"relative group flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm",children:[ae.preview?o.jsx("img",{src:ae.preview,alt:ae.name,className:"w-10 h-10 rounded object-cover"}):o.jsx("svg",{className:"w-5 h-5 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("p",{className:"text-xs text-gray-700 dark:text-gray-300 truncate max-w-[120px]",children:ae.name}),o.jsx("p",{className:"text-xs text-gray-400",children:yt(ae.size)})]}),o.jsx("button",{onClick:()=>nt(ae.id),"aria-label":`Remove attachment ${ae.name||""}`,className:"absolute -top-1.5 -right-1.5 w-5 h-5 rounded-full bg-gray-500 hover:bg-red-500 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:o.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]},ae.id))}),o.jsxs("div",{className:"relative flex flex-col sm:flex-row sm:items-end gap-1 sm:gap-2 bg-gray-100 dark:bg-gray-800 rounded-2xl px-3 py-2",children:[o.jsx(_z,{skills:Ne,builtins:Ce,filter:re,onSelect:Pe,visible:Z,selectedIndex:me,activeSkill:Le,onBack:Xe}),o.jsxs("div",{className:"order-2 sm:order-none flex items-center gap-1 flex-wrap sm:flex-nowrap relative",children:[o.jsx("button",{onClick:()=>{var ae;return(ae=K.current)==null?void 0:ae.click()},disabled:a||r,className:"flex-shrink-0 w-8 h-8 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 disabled:opacity-40 flex items-center justify-center transition-colors text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200",title:u("chat.attach_file"),"aria-label":u("chat.attach_file"),children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M18.375 12.739l-7.693 7.693a4.5 4.5 0 01-6.364-6.364l10.94-10.94A3 3 0 1119.5 7.372L8.552 18.32m.009-.01l-.01.01m5.699-9.941l-7.81 7.81a1.5 1.5 0 002.112 2.13"})})}),o.jsx("input",{ref:K,type:"file",multiple:!0,accept:iz,onChange:We,className:"hidden"}),o.jsx("button",{onClick:ce==="recording"?Ye:ce==="paused"?ot:ce==="loading"?Rt:Ke,disabled:ce==="draining"||(a||r)&&ce!=="recording"&&ce!=="loading"&&ce!=="paused",className:"flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center transition-colors "+(ce==="recording"?"bg-red-500 hover:bg-red-600 text-white animate-pulse":ce==="paused"?"bg-yellow-500 hover:bg-yellow-600 text-white":ce==="loading"||ce==="draining"?"bg-gray-200 dark:bg-gray-700 text-gray-400 cursor-wait":"hover:bg-gray-200 dark:hover:bg-gray-700 disabled:opacity-40 text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200"),title:ce==="recording"?u("voice.stop_recording")||"Stop recording":ce==="paused"?u("voice.resume_recording")||"Resume recording":ce==="loading"?u("voice.loading_model"):ce==="draining"?u("voice.processing")||"Processing remaining audio":u("voice.start_recording"),"aria-label":ce==="recording"?u("voice.stop_recording")||"Stop recording":ce==="paused"?u("voice.resume_recording")||"Resume recording":ce==="loading"?u("voice.loading_model"):ce==="draining"?u("voice.processing")||"Processing remaining audio":u("voice.start_recording"),children:ce==="draining"?o.jsxs("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[o.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),o.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}):ce==="loading"?o.jsxs("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[o.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),o.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}):ce==="recording"?o.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 24 24",children:o.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})}):ce==="paused"?o.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 24 24",children:o.jsx("circle",{cx:"12",cy:"12",r:"6"})}):o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 18.75a6 6 0 006-6v-1.5m-6 7.5a6 6 0 01-6-6v-1.5m6 7.5v3.75m-3.75 0h7.5M12 15.75a3 3 0 01-3-3V4.5a3 3 0 116 0v8.25a3 3 0 01-3 3z"})})}),ce==="loading"&&o.jsxs("div",{className:"absolute -top-6 left-1/2 -translate-x-1/2 bg-gray-800 dark:bg-gray-700 text-white text-xs px-2 py-1 rounded shadow whitespace-nowrap flex items-center gap-2",children:[o.jsx("div",{className:"w-16 h-1.5 bg-gray-600 rounded-full overflow-hidden",children:o.jsx("div",{className:"h-full bg-primary-400 transition-all duration-300",style:{width:`${je}%`}})}),o.jsx("span",{children:Be?`${Be} ${je}%`:`${je}%`})]}),o.jsxs("div",{className:"relative flex-shrink-0",ref:B,children:[o.jsxs("button",{onClick:()=>I(ae=>!ae),disabled:ce==="recording"||ce==="draining",className:"h-8 px-2 rounded-full flex items-center justify-center gap-1 transition-colors text-xs font-medium hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 disabled:opacity-40 disabled:cursor-not-allowed",title:"Speech recognition language","aria-label":"Select speech recognition language","aria-haspopup":"menu","aria-expanded":S,children:[o.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 21l5.25-11.25L21 21m-9-3h7.5M3 5.621a48.474 48.474 0 016-.371m0 0c1.12 0 2.233.038 3.334.114M9 5.25V3m3.334 2.364C11.176 10.658 7.69 15.08 3 17.502m9.334-12.138c.896.061 1.785.147 2.666.257m-4.589 8.495a18.023 18.023 0 01-3.827-5.802"})}),o.jsx("span",{className:"max-w-[80px] truncate",children:(G.find(ae=>ae.code===P)||G[0]).label}),o.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 8.25l-7.5 7.5-7.5-7.5"})})]}),S&&o.jsx("div",{className:"absolute bottom-full mb-1 left-0 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg py-1 min-w-[180px] max-h-64 overflow-y-auto z-50",role:"menu","aria-label":"Speech recognition language",children:G.map(ae=>o.jsx("button",{role:"menuitemradio","aria-checked":ae.code===P,onClick:()=>{M(ae.code),I(!1),ae.code==="yue"&&fe("Cantonese requires whisper-small or larger. If transcription is poor, this device may be using the tiny model (Safari, or older cached version).")},className:"w-full text-left px-3 py-1.5 text-xs transition-colors "+(ae.code===P?"bg-blue-50 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 font-medium":"text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700"),children:ae.label},ae.code))})]}),b.length>1&&o.jsxs("div",{className:"relative flex-shrink-0",ref:A,children:[o.jsxs("button",{onClick:()=>T(ae=>!ae),disabled:ce==="recording"||ce==="draining",className:"h-8 px-2 rounded-full flex items-center justify-center gap-1 transition-colors text-xs font-medium hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 disabled:opacity-40 disabled:cursor-not-allowed",title:u("voice.select_asr_model"),"aria-label":u("voice.select_asr_model"),"aria-haspopup":"menu","aria-expanded":_,children:[o.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09z"})}),o.jsx("span",{className:"max-w-[80px] truncate",children:(b.find(ae=>ae.name===N)||b[0]).label}),o.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 8.25l-7.5 7.5-7.5-7.5"})})]}),_&&o.jsx("div",{className:"absolute bottom-full mb-1 left-0 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg py-1 min-w-[160px] z-50",role:"menu","aria-label":u("voice.select_asr_model"),children:b.map((ae,Ie)=>o.jsxs("button",{ref:De=>{D.current[Ie]=De},role:"menuitemradio","aria-checked":ae.name===N,tabIndex:R===Ie?0:-1,onClick:()=>{w(ae.name),T(!1)},className:"w-full text-left px-3 py-1.5 text-xs transition-colors "+(ae.name===N?"bg-blue-50 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 font-medium":"text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700"),children:[ae.label,ae.type!=="openai"&&o.jsxs("span",{className:"ml-1 text-gray-400 dark:text-gray-500",children:["(",ae.type,")"]})]},`${ae.name}-${Ie}`))})]}),o.jsxs("button",{onClick:()=>y(ae=>!ae),disabled:a||r,className:"flex-shrink-0 h-8 px-2 rounded-full flex items-center justify-center gap-1 transition-colors text-xs font-medium "+(m?"bg-amber-100 dark:bg-amber-900/40 text-amber-700 dark:text-amber-300 ring-1 ring-amber-300 dark:ring-amber-700":"hover:bg-gray-200 dark:hover:bg-gray-700 disabled:opacity-40 text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200"),title:m?"Plan mode active (read-only) — click to switch to build":"Switch to plan mode (read-only)","aria-label":m?"Disable plan mode":"Enable plan mode","aria-pressed":m,children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12h3.75M9 15h3.75M9 18h3.75m3 .75H18a2.25 2.25 0 002.25-2.25V6.108c0-1.135-.845-2.098-1.976-2.192a48.424 48.424 0 00-1.123-.08m-5.801 0c-.065.21-.1.433-.1.664 0 .414.336.75.75.75h4.5a.75.75 0 00.75-.75 2.25 2.25 0 00-.1-.664m-5.8 0A2.251 2.251 0 0113.5 2.25H15c1.012 0 1.867.668 2.15 1.586m-5.8 0c-.376.023-.75.05-1.124.08C9.095 4.01 8.25 4.973 8.25 6.108V8.25m0 0H4.875c-.621 0-1.125.504-1.125 1.125v11.25c0 .621.504 1.125 1.125 1.125h9.75c.621 0 1.125-.504 1.125-1.125V9.375c0-.621-.504-1.125-1.125-1.125H8.25zM6.75 12h.008v.008H6.75V12zm0 3h.008v.008H6.75V15zm0 3h.008v.008H6.75V18z"})}),m?"Plan":""]})]}),o.jsxs("div",{className:"order-1 sm:order-none flex items-end gap-2 flex-1 min-w-0",children:[o.jsx("textarea",{ref:C,value:d,onChange:ae=>_e(ae.target.value),onKeyDown:Mt,onPaste:de,placeholder:u("chat.send_placeholder"),disabled:a,rows:1,role:Z?"combobox":void 0,"aria-controls":Z?"slash-command-listbox":void 0,"aria-activedescendant":Z&&he()>0?"slash-item-"+me:void 0,"aria-expanded":Z||void 0,className:"flex-1 bg-transparent resize-none outline-none text-sm py-1.5 min-h-[32px] text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 max-h-[200px]"}),r&&o.jsx("button",{onClick:n,className:"flex-shrink-0 w-8 h-8 rounded-full bg-red-500 hover:bg-red-600 flex items-center justify-center transition-colors",title:u("chat.stop_generating"),"aria-label":u("chat.stop_generating"),children:o.jsx("svg",{className:"w-3.5 h-3.5 text-white",fill:"currentColor",viewBox:"0 0 24 24",children:o.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})})}),o.jsxs("button",{onClick:mt,disabled:!d.trim()&&p.length===0||a,className:"relative flex-shrink-0 w-8 h-8 rounded-full bg-accent-400 hover:bg-accent-500 disabled:bg-gray-300 dark:disabled:bg-gray-600 flex items-center justify-center transition-colors",title:r?"Queue message (will send when current finishes)":u("chat.send_button"),"aria-label":r?"Queue message":u("chat.send_button"),"aria-disabled":!d.trim()&&p.length===0||a?"true":void 0,children:[o.jsx("svg",{className:"w-4 h-4 text-gray-900",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 12h14M12 5l7 7-7 7"})}),s>0&&o.jsx("span",{className:"absolute -top-1 -right-1 min-w-[16px] h-4 px-1 rounded-full bg-amber-500 text-white text-[10px] font-bold flex items-center justify-center ring-2 ring-white dark:ring-gray-800","aria-label":`${s} message${s===1?"":"s"} queued`,children:s})]})]})]}),o.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 mt-1.5 text-center",children:u("chat.send_hint")}),v&&o.jsxs("div",{role:"alert",className:"mt-2 px-3 py-2 bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300 text-sm rounded-lg flex items-center gap-2",children:[o.jsx("svg",{className:"w-4 h-4 flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"})}),o.jsx("span",{children:v}),o.jsx("button",{onClick:()=>x(null),className:"ml-auto text-red-500 hover:text-red-700 dark:hover:text-red-200","aria-label":u("voice.dismiss_error"),children:o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})]})})});function Cz({darkMode:e,onToggleTheme:t}){const{t:n}=vt(),r=(v,x)=>{const b=n(v);return b===v?x:b},[a,i]=h.useState(""),[s,l]=h.useState(""),[c,u]=h.useState(!1),[d,f]=h.useState(null),[p,g]=h.useState(!1);h.useEffect(()=>{fetch("/auth/membership/available").then(v=>v.json()).then(v=>g(v.available===!0)).catch(()=>{})},[]);const m=async v=>{v.preventDefault(),f(null),u(!0);try{const x=await fetch("/auth/membership/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:a,password:s})}),b=await x.json().catch(()=>({}));if(!x.ok){f(b.error||"Login failed"),u(!1);return}window.location.reload()}catch(x){f("Connection error: "+x.message),u(!1)}},y=async()=>{f(null),u(!0);try{const v=await fetch("/auth/local/login",{method:"POST",credentials:"include"}),x=await v.json().catch(()=>({}));if(!v.ok){f(x.error||"Local login failed"),u(!1);return}window.location.href="/"}catch(v){f("Connection error: "+v.message),u(!1)}};return o.jsxs("div",{className:"min-h-screen flex flex-col bg-gray-50 dark:bg-gray-950",children:[o.jsx("div",{className:"flex justify-end p-4",children:o.jsx("button",{onClick:t,className:"p-2 rounded-lg bg-gray-200 dark:bg-gray-800 text-gray-600 dark:text-gray-300 hover:bg-gray-300 dark:hover:bg-gray-700 transition-colors",title:n(e?"theme.light":"theme.dark"),"aria-label":n(e?"theme.light":"theme.dark"),children:e?o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"})}):o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"})})})}),o.jsx("div",{className:"flex-1 flex items-center justify-center px-4",children:o.jsxs("div",{className:"w-full max-w-sm",children:[o.jsxs("div",{className:"text-center mb-8",children:[o.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-primary-500 mb-4",children:o.jsx("span",{className:"text-white font-bold text-2xl",children:"P"})}),o.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:"PAVE"}),o.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:n("login.pave_subtitle")})]}),o.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-xl border border-gray-200 dark:border-gray-800 p-6 shadow-sm ring-1 ring-accent-400/20",children:[o.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 text-center mb-6",children:n("login.sign_in")}),d&&o.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 text-sm border border-red-200 dark:border-red-800",children:d}),p&&o.jsxs("form",{onSubmit:m,className:"space-y-3 mb-4",children:[o.jsx("input",{type:"email",placeholder:r("login.email_placeholder","Email"),value:a,onChange:v=>i(v.target.value),required:!0,className:"w-full px-3 py-2.5 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent"}),o.jsx("input",{type:"password",placeholder:r("login.password_placeholder","Password"),value:s,onChange:v=>l(v.target.value),required:!0,className:"w-full px-3 py-2.5 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent"}),o.jsx("button",{type:"submit",disabled:c,className:"w-full py-2.5 px-4 rounded-lg bg-primary-500 hover:bg-primary-600 text-white font-medium text-sm transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:c?r("login.signing_in","Signing in..."):n("login.sign_in")})]}),p&&o.jsxs("div",{className:"flex items-center gap-3 my-4",children:[o.jsx("div",{className:"flex-1 border-t border-gray-200 dark:border-gray-700"}),o.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:r("login.or","or")}),o.jsx("div",{className:"flex-1 border-t border-gray-200 dark:border-gray-700"})]}),o.jsxs("button",{type:"button",onClick:y,disabled:c,className:"flex items-center justify-center gap-3 w-full py-2.5 px-4 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-200 font-medium text-sm transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),r("login.sign_in_locally","Sign in locally")]}),o.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 text-center mt-4",children:n("login.terms")})]})]})})]})}function jz({user:e,onLogout:t,onSkillManagement:n,onAgentManagement:r,onPricingSettings:a,onDlpSettings:i,onSettings:s}){const{t:l}=vt(),[c,u]=h.useState(!1),d=h.useRef(null);if(h.useEffect(()=>{if(!c)return;function p(g){d.current&&!d.current.contains(g.target)&&u(!1)}return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[c]),!e)return null;const f=(e.name||e.email||"?").split(" ").map(p=>p[0]).join("").slice(0,2).toUpperCase();return o.jsxs("div",{className:"relative",ref:d,children:[o.jsxs("button",{onClick:()=>u(!c),className:"flex items-center gap-2 px-2 py-1 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors",title:e.email,"aria-label":e.name||e.email||l("user_menu.title"),children:[e.picture?o.jsx("img",{src:e.picture,alt:"","aria-hidden":"true",className:"w-7 h-7 rounded-full",referrerPolicy:"no-referrer"}):o.jsx("div",{className:"w-7 h-7 rounded-full bg-primary-500 flex items-center justify-center",children:o.jsx("span",{className:"text-white text-xs font-semibold",children:f})}),o.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300 hidden sm:inline max-w-[120px] truncate",children:e.name||e.email}),o.jsx("svg",{className:"w-3 h-3 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]}),c&&o.jsxs("div",{className:"absolute right-0 top-full mt-1 w-56 bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700 shadow-lg z-50 py-1",children:[o.jsxs("div",{className:"px-3 py-2 border-b border-gray-100 dark:border-gray-800",children:[o.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 truncate",children:e.name}),o.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:e.email})]}),n&&o.jsxs("button",{type:"button",onClick:()=>{u(!1),n()},className:"w-full text-left px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors flex items-center gap-2",children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11 4a2 2 0 114 0v1a1 1 0 001 1h3a1 1 0 011 1v3a1 1 0 01-1 1h-1a2 2 0 100 4h1a1 1 0 011 1v3a1 1 0 01-1 1h-3a1 1 0 01-1-1v-1a2 2 0 10-4 0v1a1 1 0 01-1 1H7a1 1 0 01-1-1v-3a1 1 0 00-1-1H4a2 2 0 110-4h1a1 1 0 001-1V7a1 1 0 011-1h3a1 1 0 001-1V4z"})}),l("user_menu.skills")]}),r&&o.jsxs("button",{onClick:()=>{u(!1),r()},className:"w-full text-left px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors flex items-center gap-2",children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),l("user_menu.agents")]}),a&&o.jsxs("button",{onClick:()=>{u(!1),a()},className:"w-full text-left px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors flex items-center gap-2",children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),l("user_menu.pricing")]}),i&&o.jsxs("button",{onClick:()=>{u(!1),i()},className:"w-full text-left px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors flex items-center gap-2",children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"})}),l("user_menu.privacy_dlp")]}),s&&o.jsxs("button",{onClick:()=>{u(!1),s()},className:"w-full text-left px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors flex items-center gap-2",children:[o.jsxs("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),l("user_menu.settings")]}),t&&o.jsx("button",{onClick:()=>{u(!1),t()},className:"w-full text-left px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors",children:l("user_menu.sign_out")})]})]})}function iT({toolParts:e}){const{t}=vt();return!e||e.length===0?o.jsxs("div",{className:"p-4",children:[o.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide font-medium mb-3",children:t("task.activity")}),o.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500",children:t("task.no_active")})]}):o.jsxs("div",{className:"p-4",children:[o.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide font-medium mb-3",children:t("task.working")}),o.jsx("div",{className:"space-y-1 max-h-[calc(100vh-300px)] overflow-y-auto",children:e.map(n=>o.jsx(Tz,{part:n},n.id))})]})}function Tz({part:e}){var a,i;const t=((a=e.state)==null?void 0:a.status)||"running",n=((i=e.state)==null?void 0:i.input)||{},r=Az(e.tool,n);return o.jsxs("div",{className:"flex items-center gap-2 py-1",children:[o.jsxs("div",{className:"flex-shrink-0",children:[t==="running"&&o.jsx("div",{className:"w-3.5 h-3.5 rounded-full border-2 border-primary-400 border-t-transparent animate-spin"}),t==="completed"&&o.jsx("svg",{className:"w-3.5 h-3.5 text-green-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),t==="error"&&o.jsx("svg",{className:"w-3.5 h-3.5 text-red-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),t==="pending_confirmation"&&o.jsx("svg",{className:"w-3.5 h-3.5 text-amber-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v2m0 4h.01"})})]}),o.jsx("span",{className:`text-xs truncate ${t==="running"?"text-gray-800 dark:text-gray-200":t==="error"?"text-red-500 dark:text-red-400":"text-gray-500 dark:text-gray-400"}`,children:r})]})}function Az(e,t){if(!e)return"Processing...";switch(e){case"Read":return"Reading "+hc(t.filePath);case"Write":return"Writing "+hc(t.filePath);case"Edit":return"Editing "+hc(t.filePath);case"Bash":{const n=t.command||"";return s_(n)}case"Glob":return"Searching for files"+(t.pattern?": "+t.pattern:"");case"Grep":return"Searching code"+(t.pattern?' for "'+ex(t.pattern,30)+'"':"");case"Fetch":case"WebFetch":return"Fetching web page"+(t.url?": "+ex(t.url,40):"");case"Skill":{const n=t.name||t.skill||"";return Rz(n)}case"Todo":case"TodoWrite":return"Updating plan";case"Task":return t._purpose||"Running sub-task";default:return t.filePath?"Processing "+hc(t.filePath):t.command?s_(t.command):"Running "+e.toLowerCase()}}function hc(e){if(!e)return"file";const t=e.split("/"),n=t[t.length-1]||"file";return t.length<=2?n:t[t.length-2]+"/"+n}function s_(e){if(!e)return"Running command";const t=e.trim();if(/^(ls|dir)\b/i.test(t))return"Listing files";if(/^(cat|less|more)\b/i.test(t))return"Reading file contents";if(/^(mkdir)\b/i.test(t))return"Creating directory";if(/^(rm|del)\b/i.test(t))return"Removing files";if(/^(cp|copy)\b/i.test(t))return"Copying files";if(/^(mv|move|rename)\b/i.test(t))return"Moving files";if(/^(git\s+status)\b/i.test(t))return"Checking git status";if(/^(git\s+log)\b/i.test(t))return"Viewing git history";if(/^(git\s+diff)\b/i.test(t))return"Comparing changes";if(/^(git\s+add)\b/i.test(t))return"Staging changes";if(/^(git\s+commit)\b/i.test(t))return"Committing changes";if(/^(git\s+push)\b/i.test(t))return"Pushing to remote";if(/^(git\s+pull)\b/i.test(t))return"Pulling from remote";if(/^(git\s+clone)\b/i.test(t))return"Cloning repository";if(/^(git\s+checkout|git\s+switch)\b/i.test(t))return"Switching branches";if(/^(git\s+branch)\b/i.test(t))return"Managing branches";if(/^git\b/i.test(t))return"Running git command";if(/^(npm\s+install|npm\s+i|yarn\s+install|yarn\s+add|pnpm\s+install)\b/i.test(t))return"Installing dependencies";if(/^(npm\s+run\s+build|yarn\s+build|pnpm\s+build)\b/i.test(t))return"Building project";if(/^(npm\s+run\s+test|npm\s+test|yarn\s+test|jest|pytest|mocha)\b/i.test(t))return"Running tests";if(/^(npm\s+run\s+dev|npm\s+start|yarn\s+dev|yarn\s+start)\b/i.test(t))return"Starting dev server";if(/^(npm|yarn|pnpm)\b/i.test(t))return"Running package manager";if(/^(node|python|ruby|php|java)\b/i.test(t))return"Running script";if(/^(docker)\b/i.test(t))return"Running Docker command";if(/^(curl|wget)\b/i.test(t))return"Fetching URL";if(/^(chmod|chown)\b/i.test(t))return"Changing permissions";if(/^(find|locate)\b/i.test(t))return"Finding files";if(/^(grep|rg|ag)\b/i.test(t))return"Searching file contents";if(/^(sed|awk)\b/i.test(t))return"Processing text";if(/^(echo|printf)\b/i.test(t))return"Running command";if(/^(ssh|scp)\b/i.test(t))return"Connecting remotely";if(/^(ping|traceroute|nslookup|dig)\b/i.test(t))return"Checking network";if(/^(tar|zip|unzip|gzip)\b/i.test(t))return"Compressing/extracting files";const n=t.split(/\s+/)[0];return"Running "+ex(n,20)}function Rz(e,t){const n=(e||"").toLowerCase();return n.includes("gmail")||n.includes("email")?"Checking email":n.includes("gdrive")||n.includes("drive")?"Accessing Google Drive":n.includes("gcal")||n.includes("calendar")?"Checking calendar":n.includes("gtasks")||n.includes("tasks")?"Managing tasks":n.includes("discord")?"Using Discord":n.includes("whatsapp")?"Using WhatsApp":n.includes("wrike")?"Checking Wrike":n.includes("dropbox")?"Accessing Dropbox":n.includes("pandadoc")?"Working with PandaDoc":n.includes("freshbooks")?"Checking FreshBooks":n.includes("mailchimp")?"Using Mailchimp":n.includes("bamboohr")?"Checking BambooHR":e?"Using "+e:"Running skill"}function ex(e,t){return e?e.length<=t?e:e.slice(0,t)+"...":""}const tx=10,nx=24,o_=2,Mz=14,sT="pave-terminal-font-size";function Iz(){try{const e=localStorage.getItem(sT);if(e!==null){const t=parseInt(e,10);if(!Number.isNaN(t)&&t>=tx&&t<=nx)return t}}catch{}return Mz}function oT({toolParts:e,matrixMode:t,onToggleMatrix:n,darkMode:r=!0}){var{t:a}=vt();const i=h.useRef(null),s=h.useRef(null),l=h.useRef(null),[c,u]=h.useState(Iz),d=h.useCallback(()=>{u(y=>Math.max(tx,y-o_))},[]),f=h.useCallback(()=>{u(y=>Math.min(nx,y+o_))},[]);h.useEffect(()=>{try{localStorage.setItem(sT,String(c))}catch{}},[c]);const p=r?{bg:"bg-gray-950",headerBg:"bg-gray-900",headerBorder:"border-gray-800",titleText:"text-gray-400",promptColor:"text-green-400",commandColor:"text-gray-200",outputColor:"text-green-300/70",waitingText:"text-gray-500",runningColor:"text-yellow-400",doneColor:"text-green-500",errorColor:"text-red-400",pendingColor:"text-blue-400"}:{bg:"bg-gray-100",headerBg:"bg-gray-200",headerBorder:"border-gray-300",titleText:"text-gray-600",promptColor:"text-green-600",commandColor:"text-gray-800",outputColor:"text-green-700/80",waitingText:"text-gray-500",runningColor:"text-yellow-600",doneColor:"text-green-600",errorColor:"text-red-600",pendingColor:"text-blue-600"},g=`px-1.5 py-0.5 text-xs font-mono rounded ${r?"bg-gray-600 text-gray-300 hover:bg-gray-500":"bg-gray-300 text-gray-700 hover:bg-gray-200"} disabled:opacity-40 disabled:cursor-default`;h.useEffect(()=>{i.current&&!t&&(i.current.scrollTop=i.current.scrollHeight)},[e,t]);const m=h.useCallback(()=>{const y=s.current;if(!y)return;const v=y.getContext("2d");if(!v)return;const x=()=>{const A=y.parentElement;if(A&&A.clientWidth>0&&A.clientHeight>0){y.width=A.clientWidth,y.height=A.clientHeight;return}const D=y.getBoundingClientRect();if(D.width>0&&D.height>0){y.width=D.width,y.height=D.height;return}y.width=0,y.height=0};x();const b=c;let k=Math.floor(y.width/b),N=new Array(k).fill(1);const w="アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",_=()=>{v.fillStyle="rgba(0, 0, 0, 0.05)",v.fillRect(0,0,y.width,y.height),v.fillStyle="#0F0",v.font=b+"px monospace";for(let A=0;A<N.length;A++){const D=w.charAt(Math.floor(Math.random()*w.length));v.fillText(D,A*b,N[A]*b),N[A]*b>y.height&&Math.random()>.975&&(N[A]=0),N[A]++}l.current=requestAnimationFrame(_)},T=()=>{x(),k=Math.floor(y.width/b);const A=new Array(k).fill(0);for(let D=0;D<Math.min(N.length,A.length);D++)A[D]=N[D];N=A};return window.addEventListener("resize",T),l.current=requestAnimationFrame(_),()=>{window.removeEventListener("resize",T),l.current&&cancelAnimationFrame(l.current)}},[c]);return h.useEffect(()=>{let y;return t?y=m():l.current&&(cancelAnimationFrame(l.current),l.current=null),()=>{y&&y(),l.current&&(cancelAnimationFrame(l.current),l.current=null)}},[t,m]),e&&e.some(y=>{var v;return(((v=y.state)==null?void 0:v.status)||"running")==="running"}),o.jsxs("div",{className:`flex flex-col h-full ${p.bg} font-mono`,style:{fontSize:c+"px"},children:[o.jsxs("div",{className:`flex items-center justify-between px-3 py-2 ${p.headerBg} border-b ${p.headerBorder} flex-shrink-0`,children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsxs("div",{className:"flex gap-1.5",children:[o.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-red-500 cursor-pointer",onDoubleClick:n,title:""}),o.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-yellow-500"}),o.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-green-500"})]}),o.jsx("span",{className:`${p.titleText} text-xs ml-2`,children:"PAVE Terminal"})]}),o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx("button",{type:"button",onClick:d,disabled:c<=tx,className:g,"aria-label":a("terminal.decrease_font"),title:a("terminal.decrease_font"),children:"A-"}),o.jsx("button",{type:"button",onClick:f,disabled:c>=nx,className:g,"aria-label":a("terminal.increase_font"),title:a("terminal.increase_font"),children:"A+"})]})]}),o.jsx("div",{className:"flex-1 relative overflow-hidden",children:t?o.jsxs(o.Fragment,{children:[o.jsx("canvas",{ref:s,className:"absolute inset-0 w-full h-full"}),e&&e.length>0&&o.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/60 px-3 py-2 max-h-32 overflow-y-auto",children:e.slice(-3).map(y=>o.jsx(Oz,{part:y},y.id))})]}):o.jsx("div",{ref:i,className:"h-full overflow-y-auto px-3 py-2 space-y-1",children:!e||e.length===0?o.jsxs("div",{children:[o.jsxs("div",{className:p.promptColor,children:["$ ",o.jsx("span",{className:"terminal-cursor",children:"█"})]}),o.jsx("p",{className:`${p.waitingText} mt-2`,children:"Awaiting commands..."})]}):o.jsxs(o.Fragment,{children:[e.map(y=>o.jsx(Lz,{part:y,theme:p},y.id)),o.jsxs("div",{className:p.promptColor,children:["$ ",o.jsx("span",{className:"terminal-cursor",children:"█"})]})]})})})]})}function Lz({part:e,theme:t}){var{t:n}=vt();const{tool:r,state:a}=e;if(!a)return null;const i=a.status||"running",l=Yu(r||a.title,a.input)||r||a.title||"unknown",c=a.output?_i(typeof a.output=="string"?a.output:JSON.stringify(a.output,null,2)):null;return o.jsxs("div",{className:"mb-2",children:[o.jsxs("div",{className:`${t.commandColor} break-all`,children:[o.jsx("span",{className:`${t.promptColor} select-none`,children:"$ "}),l]}),i==="running"&&o.jsx("div",{className:`${t.runningColor} mt-0.5`,children:"[running...]"}),i==="completed"&&c&&o.jsx("pre",{className:`${t.outputColor} mt-0.5 whitespace-pre-wrap break-all`,children:c}),i==="completed"&&!c&&o.jsx("div",{className:`${t.doneColor} mt-0.5`,children:"[done]"}),i==="error"&&o.jsxs("pre",{className:`${t.errorColor} mt-0.5 whitespace-pre-wrap break-all`,children:["[error] ",a.error?_i(typeof a.error=="string"?a.error:a.error.message||n("common.error")):n("common.unknown_error")]}),i==="pending_confirmation"&&o.jsx("div",{className:`${t.pendingColor} mt-0.5`,children:"[awaiting confirmation...]"})]})}function Oz({part:e}){const{tool:t,state:n}=e;if(!n)return null;const r=n.status||"running",i=Yu(t||n.title,n.input)||t||n.title||"unknown",s={running:"text-yellow-400",completed:"text-green-400",error:"text-red-400",pending_confirmation:"text-blue-400"},l={running:"RUN",completed:"OK",error:"ERR",pending_confirmation:"WAIT"};return o.jsxs("div",{className:"text-xs font-mono truncate",children:[o.jsxs("span",{className:s[r]||"text-gray-400",children:["[",l[r]||r,"]"]}),o.jsxs("span",{className:"text-green-300 ml-1",children:["$ ",i]})]})}function Ib(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Df,l_;function Dz(){if(l_)return Df;l_=1;function e(){this.__data__=[],this.size=0}return Df=e,Df}var Pf,c_;function Ps(){if(c_)return Pf;c_=1;function e(t,n){return t===n||t!==t&&n!==n}return Pf=e,Pf}var Ff,u_;function Xu(){if(u_)return Ff;u_=1;var e=Ps();function t(n,r){for(var a=n.length;a--;)if(e(n[a][0],r))return a;return-1}return Ff=t,Ff}var Bf,d_;function Pz(){if(d_)return Bf;d_=1;var e=Xu(),t=Array.prototype,n=t.splice;function r(a){var i=this.__data__,s=e(i,a);if(s<0)return!1;var l=i.length-1;return s==l?i.pop():n.call(i,s,1),--this.size,!0}return Bf=r,Bf}var zf,f_;function Fz(){if(f_)return zf;f_=1;var e=Xu();function t(n){var r=this.__data__,a=e(r,n);return a<0?void 0:r[a][1]}return zf=t,zf}var Uf,p_;function Bz(){if(p_)return Uf;p_=1;var e=Xu();function t(n){return e(this.__data__,n)>-1}return Uf=t,Uf}var qf,g_;function zz(){if(g_)return qf;g_=1;var e=Xu();function t(n,r){var a=this.__data__,i=e(a,n);return i<0?(++this.size,a.push([n,r])):a[i][1]=r,this}return qf=t,qf}var $f,h_;function Zu(){if(h_)return $f;h_=1;var e=Dz(),t=Pz(),n=Fz(),r=Bz(),a=zz();function i(s){var l=-1,c=s==null?0:s.length;for(this.clear();++l<c;){var u=s[l];this.set(u[0],u[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=n,i.prototype.has=r,i.prototype.set=a,$f=i,$f}var Hf,m_;function Uz(){if(m_)return Hf;m_=1;var e=Zu();function t(){this.__data__=new e,this.size=0}return Hf=t,Hf}var Wf,y_;function qz(){if(y_)return Wf;y_=1;function e(t){var n=this.__data__,r=n.delete(t);return this.size=n.size,r}return Wf=e,Wf}var Vf,x_;function $z(){if(x_)return Vf;x_=1;function e(t){return this.__data__.get(t)}return Vf=e,Vf}var Gf,b_;function Hz(){if(b_)return Gf;b_=1;function e(t){return this.__data__.has(t)}return Gf=e,Gf}var Kf,v_;function lT(){if(v_)return Kf;v_=1;var e=typeof Da=="object"&&Da&&Da.Object===Object&&Da;return Kf=e,Kf}var Yf,k_;function Ir(){if(k_)return Yf;k_=1;var e=lT(),t=typeof self=="object"&&self&&self.Object===Object&&self,n=e||t||Function("return this")();return Yf=n,Yf}var Qf,__;function Fs(){if(__)return Qf;__=1;var e=Ir(),t=e.Symbol;return Qf=t,Qf}var Xf,w_;function Wz(){if(w_)return Xf;w_=1;var e=Fs(),t=Object.prototype,n=t.hasOwnProperty,r=t.toString,a=e?e.toStringTag:void 0;function i(s){var l=n.call(s,a),c=s[a];try{s[a]=void 0;var u=!0}catch{}var d=r.call(s);return u&&(l?s[a]=c:delete s[a]),d}return Xf=i,Xf}var Zf,E_;function Vz(){if(E_)return Zf;E_=1;var e=Object.prototype,t=e.toString;function n(r){return t.call(r)}return Zf=n,Zf}var Jf,N_;function Li(){if(N_)return Jf;N_=1;var e=Fs(),t=Wz(),n=Vz(),r="[object Null]",a="[object Undefined]",i=e?e.toStringTag:void 0;function s(l){return l==null?l===void 0?a:r:i&&i in Object(l)?t(l):n(l)}return Jf=s,Jf}var ep,S_;function yr(){if(S_)return ep;S_=1;function e(t){var n=typeof t;return t!=null&&(n=="object"||n=="function")}return ep=e,ep}var tp,C_;function ml(){if(C_)return tp;C_=1;var e=Li(),t=yr(),n="[object AsyncFunction]",r="[object Function]",a="[object GeneratorFunction]",i="[object Proxy]";function s(l){if(!t(l))return!1;var c=e(l);return c==r||c==a||c==n||c==i}return tp=s,tp}var np,j_;function Gz(){if(j_)return np;j_=1;var e=Ir(),t=e["__core-js_shared__"];return np=t,np}var rp,T_;function Kz(){if(T_)return rp;T_=1;var e=Gz(),t=function(){var r=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return r?"Symbol(src)_1."+r:""}();function n(r){return!!t&&t in r}return rp=n,rp}var ap,A_;function cT(){if(A_)return ap;A_=1;var e=Function.prototype,t=e.toString;function n(r){if(r!=null){try{return t.call(r)}catch{}try{return r+""}catch{}}return""}return ap=n,ap}var ip,R_;function Yz(){if(R_)return ip;R_=1;var e=ml(),t=Kz(),n=yr(),r=cT(),a=/[\\^$.*+?()[\]{}|]/g,i=/^\[object .+?Constructor\]$/,s=Function.prototype,l=Object.prototype,c=s.toString,u=l.hasOwnProperty,d=RegExp("^"+c.call(u).replace(a,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function f(p){if(!n(p)||t(p))return!1;var g=e(p)?d:i;return g.test(r(p))}return ip=f,ip}var sp,M_;function Qz(){if(M_)return sp;M_=1;function e(t,n){return t==null?void 0:t[n]}return sp=e,sp}var op,I_;function Oi(){if(I_)return op;I_=1;var e=Yz(),t=Qz();function n(r,a){var i=t(r,a);return e(i)?i:void 0}return op=n,op}var lp,L_;function Lb(){if(L_)return lp;L_=1;var e=Oi(),t=Ir(),n=e(t,"Map");return lp=n,lp}var cp,O_;function Ju(){if(O_)return cp;O_=1;var e=Oi(),t=e(Object,"create");return cp=t,cp}var up,D_;function Xz(){if(D_)return up;D_=1;var e=Ju();function t(){this.__data__=e?e(null):{},this.size=0}return up=t,up}var dp,P_;function Zz(){if(P_)return dp;P_=1;function e(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n}return dp=e,dp}var fp,F_;function Jz(){if(F_)return fp;F_=1;var e=Ju(),t="__lodash_hash_undefined__",n=Object.prototype,r=n.hasOwnProperty;function a(i){var s=this.__data__;if(e){var l=s[i];return l===t?void 0:l}return r.call(s,i)?s[i]:void 0}return fp=a,fp}var pp,B_;function eU(){if(B_)return pp;B_=1;var e=Ju(),t=Object.prototype,n=t.hasOwnProperty;function r(a){var i=this.__data__;return e?i[a]!==void 0:n.call(i,a)}return pp=r,pp}var gp,z_;function tU(){if(z_)return gp;z_=1;var e=Ju(),t="__lodash_hash_undefined__";function n(r,a){var i=this.__data__;return this.size+=this.has(r)?0:1,i[r]=e&&a===void 0?t:a,this}return gp=n,gp}var hp,U_;function nU(){if(U_)return hp;U_=1;var e=Xz(),t=Zz(),n=Jz(),r=eU(),a=tU();function i(s){var l=-1,c=s==null?0:s.length;for(this.clear();++l<c;){var u=s[l];this.set(u[0],u[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=n,i.prototype.has=r,i.prototype.set=a,hp=i,hp}var mp,q_;function rU(){if(q_)return mp;q_=1;var e=nU(),t=Zu(),n=Lb();function r(){this.size=0,this.__data__={hash:new e,map:new(n||t),string:new e}}return mp=r,mp}var yp,$_;function aU(){if($_)return yp;$_=1;function e(t){var n=typeof t;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?t!=="__proto__":t===null}return yp=e,yp}var xp,H_;function ed(){if(H_)return xp;H_=1;var e=aU();function t(n,r){var a=n.__data__;return e(r)?a[typeof r=="string"?"string":"hash"]:a.map}return xp=t,xp}var bp,W_;function iU(){if(W_)return bp;W_=1;var e=ed();function t(n){var r=e(this,n).delete(n);return this.size-=r?1:0,r}return bp=t,bp}var vp,V_;function sU(){if(V_)return vp;V_=1;var e=ed();function t(n){return e(this,n).get(n)}return vp=t,vp}var kp,G_;function oU(){if(G_)return kp;G_=1;var e=ed();function t(n){return e(this,n).has(n)}return kp=t,kp}var _p,K_;function lU(){if(K_)return _p;K_=1;var e=ed();function t(n,r){var a=e(this,n),i=a.size;return a.set(n,r),this.size+=a.size==i?0:1,this}return _p=t,_p}var wp,Y_;function Ob(){if(Y_)return wp;Y_=1;var e=rU(),t=iU(),n=sU(),r=oU(),a=lU();function i(s){var l=-1,c=s==null?0:s.length;for(this.clear();++l<c;){var u=s[l];this.set(u[0],u[1])}}return i.prototype.clear=e,i.prototype.delete=t,i.prototype.get=n,i.prototype.has=r,i.prototype.set=a,wp=i,wp}var Ep,Q_;function cU(){if(Q_)return Ep;Q_=1;var e=Zu(),t=Lb(),n=Ob(),r=200;function a(i,s){var l=this.__data__;if(l instanceof e){var c=l.__data__;if(!t||c.length<r-1)return c.push([i,s]),this.size=++l.size,this;l=this.__data__=new n(c)}return l.set(i,s),this.size=l.size,this}return Ep=a,Ep}var Np,X_;function td(){if(X_)return Np;X_=1;var e=Zu(),t=Uz(),n=qz(),r=$z(),a=Hz(),i=cU();function s(l){var c=this.__data__=new e(l);this.size=c.size}return s.prototype.clear=t,s.prototype.delete=n,s.prototype.get=r,s.prototype.has=a,s.prototype.set=i,Np=s,Np}var Sp,Z_;function Db(){if(Z_)return Sp;Z_=1;function e(t,n){for(var r=-1,a=t==null?0:t.length;++r<a&&n(t[r],r,t)!==!1;);return t}return Sp=e,Sp}var Cp,J_;function uT(){if(J_)return Cp;J_=1;var e=Oi(),t=function(){try{var n=e(Object,"defineProperty");return n({},"",{}),n}catch{}}();return Cp=t,Cp}var jp,ew;function nd(){if(ew)return jp;ew=1;var e=uT();function t(n,r,a){r=="__proto__"&&e?e(n,r,{configurable:!0,enumerable:!0,value:a,writable:!0}):n[r]=a}return jp=t,jp}var Tp,tw;function rd(){if(tw)return Tp;tw=1;var e=nd(),t=Ps(),n=Object.prototype,r=n.hasOwnProperty;function a(i,s,l){var c=i[s];(!(r.call(i,s)&&t(c,l))||l===void 0&&!(s in i))&&e(i,s,l)}return Tp=a,Tp}var Ap,nw;function yl(){if(nw)return Ap;nw=1;var e=rd(),t=nd();function n(r,a,i,s){var l=!i;i||(i={});for(var c=-1,u=a.length;++c<u;){var d=a[c],f=s?s(i[d],r[d],d,i,r):void 0;f===void 0&&(f=r[d]),l?t(i,d,f):e(i,d,f)}return i}return Ap=n,Ap}var Rp,rw;function uU(){if(rw)return Rp;rw=1;function e(t,n){for(var r=-1,a=Array(t);++r<t;)a[r]=n(r);return a}return Rp=e,Rp}var Mp,aw;function Kr(){if(aw)return Mp;aw=1;function e(t){return t!=null&&typeof t=="object"}return Mp=e,Mp}var Ip,iw;function dU(){if(iw)return Ip;iw=1;var e=Li(),t=Kr(),n="[object Arguments]";function r(a){return t(a)&&e(a)==n}return Ip=r,Ip}var Lp,sw;function xl(){if(sw)return Lp;sw=1;var e=dU(),t=Kr(),n=Object.prototype,r=n.hasOwnProperty,a=n.propertyIsEnumerable,i=e(function(){return arguments}())?e:function(s){return t(s)&&r.call(s,"callee")&&!a.call(s,"callee")};return Lp=i,Lp}var Op,ow;function sn(){if(ow)return Op;ow=1;var e=Array.isArray;return Op=e,Op}var go={exports:{}},Dp,lw;function fU(){if(lw)return Dp;lw=1;function e(){return!1}return Dp=e,Dp}go.exports;var cw;function Bs(){return cw||(cw=1,function(e,t){var n=Ir(),r=fU(),a=t&&!t.nodeType&&t,i=a&&!0&&e&&!e.nodeType&&e,s=i&&i.exports===a,l=s?n.Buffer:void 0,c=l?l.isBuffer:void 0,u=c||r;e.exports=u}(go,go.exports)),go.exports}var Pp,uw;function ad(){if(uw)return Pp;uw=1;var e=9007199254740991,t=/^(?:0|[1-9]\d*)$/;function n(r,a){var i=typeof r;return a=a??e,!!a&&(i=="number"||i!="symbol"&&t.test(r))&&r>-1&&r%1==0&&r<a}return Pp=n,Pp}var Fp,dw;function Pb(){if(dw)return Fp;dw=1;var e=9007199254740991;function t(n){return typeof n=="number"&&n>-1&&n%1==0&&n<=e}return Fp=t,Fp}var Bp,fw;function pU(){if(fw)return Bp;fw=1;var e=Li(),t=Pb(),n=Kr(),r="[object Arguments]",a="[object Array]",i="[object Boolean]",s="[object Date]",l="[object Error]",c="[object Function]",u="[object Map]",d="[object Number]",f="[object Object]",p="[object RegExp]",g="[object Set]",m="[object String]",y="[object WeakMap]",v="[object ArrayBuffer]",x="[object DataView]",b="[object Float32Array]",k="[object Float64Array]",N="[object Int8Array]",w="[object Int16Array]",_="[object Int32Array]",T="[object Uint8Array]",A="[object Uint8ClampedArray]",D="[object Uint16Array]",R="[object Uint32Array]",$={};$[b]=$[k]=$[N]=$[w]=$[_]=$[T]=$[A]=$[D]=$[R]=!0,$[r]=$[a]=$[v]=$[i]=$[x]=$[s]=$[l]=$[c]=$[u]=$[d]=$[f]=$[p]=$[g]=$[m]=$[y]=!1;function F(G){return n(G)&&t(G.length)&&!!$[e(G)]}return Bp=F,Bp}var zp,pw;function id(){if(pw)return zp;pw=1;function e(t){return function(n){return t(n)}}return zp=e,zp}var ho={exports:{}};ho.exports;var gw;function Fb(){return gw||(gw=1,function(e,t){var n=lT(),r=t&&!t.nodeType&&t,a=r&&!0&&e&&!e.nodeType&&e,i=a&&a.exports===r,s=i&&n.process,l=function(){try{var c=a&&a.require&&a.require("util").types;return c||s&&s.binding&&s.binding("util")}catch{}}();e.exports=l}(ho,ho.exports)),ho.exports}var Up,hw;function bl(){if(hw)return Up;hw=1;var e=pU(),t=id(),n=Fb(),r=n&&n.isTypedArray,a=r?t(r):e;return Up=a,Up}var qp,mw;function dT(){if(mw)return qp;mw=1;var e=uU(),t=xl(),n=sn(),r=Bs(),a=ad(),i=bl(),s=Object.prototype,l=s.hasOwnProperty;function c(u,d){var f=n(u),p=!f&&t(u),g=!f&&!p&&r(u),m=!f&&!p&&!g&&i(u),y=f||p||g||m,v=y?e(u.length,String):[],x=v.length;for(var b in u)(d||l.call(u,b))&&!(y&&(b=="length"||g&&(b=="offset"||b=="parent")||m&&(b=="buffer"||b=="byteLength"||b=="byteOffset")||a(b,x)))&&v.push(b);return v}return qp=c,qp}var $p,yw;function sd(){if(yw)return $p;yw=1;var e=Object.prototype;function t(n){var r=n&&n.constructor,a=typeof r=="function"&&r.prototype||e;return n===a}return $p=t,$p}var Hp,xw;function fT(){if(xw)return Hp;xw=1;function e(t,n){return function(r){return t(n(r))}}return Hp=e,Hp}var Wp,bw;function gU(){if(bw)return Wp;bw=1;var e=fT(),t=e(Object.keys,Object);return Wp=t,Wp}var Vp,vw;function Bb(){if(vw)return Vp;vw=1;var e=sd(),t=gU(),n=Object.prototype,r=n.hasOwnProperty;function a(i){if(!e(i))return t(i);var s=[];for(var l in Object(i))r.call(i,l)&&l!="constructor"&&s.push(l);return s}return Vp=a,Vp}var Gp,kw;function ya(){if(kw)return Gp;kw=1;var e=ml(),t=Pb();function n(r){return r!=null&&t(r.length)&&!e(r)}return Gp=n,Gp}var Kp,_w;function ri(){if(_w)return Kp;_w=1;var e=dT(),t=Bb(),n=ya();function r(a){return n(a)?e(a):t(a)}return Kp=r,Kp}var Yp,ww;function hU(){if(ww)return Yp;ww=1;var e=yl(),t=ri();function n(r,a){return r&&e(a,t(a),r)}return Yp=n,Yp}var Qp,Ew;function mU(){if(Ew)return Qp;Ew=1;function e(t){var n=[];if(t!=null)for(var r in Object(t))n.push(r);return n}return Qp=e,Qp}var Xp,Nw;function yU(){if(Nw)return Xp;Nw=1;var e=yr(),t=sd(),n=mU(),r=Object.prototype,a=r.hasOwnProperty;function i(s){if(!e(s))return n(s);var l=t(s),c=[];for(var u in s)u=="constructor"&&(l||!a.call(s,u))||c.push(u);return c}return Xp=i,Xp}var Zp,Sw;function Di(){if(Sw)return Zp;Sw=1;var e=dT(),t=yU(),n=ya();function r(a){return n(a)?e(a,!0):t(a)}return Zp=r,Zp}var Jp,Cw;function xU(){if(Cw)return Jp;Cw=1;var e=yl(),t=Di();function n(r,a){return r&&e(a,t(a),r)}return Jp=n,Jp}var mo={exports:{}};mo.exports;var jw;function pT(){return jw||(jw=1,function(e,t){var n=Ir(),r=t&&!t.nodeType&&t,a=r&&!0&&e&&!e.nodeType&&e,i=a&&a.exports===r,s=i?n.Buffer:void 0,l=s?s.allocUnsafe:void 0;function c(u,d){if(d)return u.slice();var f=u.length,p=l?l(f):new u.constructor(f);return u.copy(p),p}e.exports=c}(mo,mo.exports)),mo.exports}var eg,Tw;function gT(){if(Tw)return eg;Tw=1;function e(t,n){var r=-1,a=t.length;for(n||(n=Array(a));++r<a;)n[r]=t[r];return n}return eg=e,eg}var tg,Aw;function hT(){if(Aw)return tg;Aw=1;function e(t,n){for(var r=-1,a=t==null?0:t.length,i=0,s=[];++r<a;){var l=t[r];n(l,r,t)&&(s[i++]=l)}return s}return tg=e,tg}var ng,Rw;function mT(){if(Rw)return ng;Rw=1;function e(){return[]}return ng=e,ng}var rg,Mw;function zb(){if(Mw)return rg;Mw=1;var e=hT(),t=mT(),n=Object.prototype,r=n.propertyIsEnumerable,a=Object.getOwnPropertySymbols,i=a?function(s){return s==null?[]:(s=Object(s),e(a(s),function(l){return r.call(s,l)}))}:t;return rg=i,rg}var ag,Iw;function bU(){if(Iw)return ag;Iw=1;var e=yl(),t=zb();function n(r,a){return e(r,t(r),a)}return ag=n,ag}var ig,Lw;function Ub(){if(Lw)return ig;Lw=1;function e(t,n){for(var r=-1,a=n.length,i=t.length;++r<a;)t[i+r]=n[r];return t}return ig=e,ig}var sg,Ow;function od(){if(Ow)return sg;Ow=1;var e=fT(),t=e(Object.getPrototypeOf,Object);return sg=t,sg}var og,Dw;function yT(){if(Dw)return og;Dw=1;var e=Ub(),t=od(),n=zb(),r=mT(),a=Object.getOwnPropertySymbols,i=a?function(s){for(var l=[];s;)e(l,n(s)),s=t(s);return l}:r;return og=i,og}var lg,Pw;function vU(){if(Pw)return lg;Pw=1;var e=yl(),t=yT();function n(r,a){return e(r,t(r),a)}return lg=n,lg}var cg,Fw;function xT(){if(Fw)return cg;Fw=1;var e=Ub(),t=sn();function n(r,a,i){var s=a(r);return t(r)?s:e(s,i(r))}return cg=n,cg}var ug,Bw;function bT(){if(Bw)return ug;Bw=1;var e=xT(),t=zb(),n=ri();function r(a){return e(a,n,t)}return ug=r,ug}var dg,zw;function kU(){if(zw)return dg;zw=1;var e=xT(),t=yT(),n=Di();function r(a){return e(a,n,t)}return dg=r,dg}var fg,Uw;function _U(){if(Uw)return fg;Uw=1;var e=Oi(),t=Ir(),n=e(t,"DataView");return fg=n,fg}var pg,qw;function wU(){if(qw)return pg;qw=1;var e=Oi(),t=Ir(),n=e(t,"Promise");return pg=n,pg}var gg,$w;function vT(){if($w)return gg;$w=1;var e=Oi(),t=Ir(),n=e(t,"Set");return gg=n,gg}var hg,Hw;function EU(){if(Hw)return hg;Hw=1;var e=Oi(),t=Ir(),n=e(t,"WeakMap");return hg=n,hg}var mg,Ww;function zs(){if(Ww)return mg;Ww=1;var e=_U(),t=Lb(),n=wU(),r=vT(),a=EU(),i=Li(),s=cT(),l="[object Map]",c="[object Object]",u="[object Promise]",d="[object Set]",f="[object WeakMap]",p="[object DataView]",g=s(e),m=s(t),y=s(n),v=s(r),x=s(a),b=i;return(e&&b(new e(new ArrayBuffer(1)))!=p||t&&b(new t)!=l||n&&b(n.resolve())!=u||r&&b(new r)!=d||a&&b(new a)!=f)&&(b=function(k){var N=i(k),w=N==c?k.constructor:void 0,_=w?s(w):"";if(_)switch(_){case g:return p;case m:return l;case y:return u;case v:return d;case x:return f}return N}),mg=b,mg}var yg,Vw;function NU(){if(Vw)return yg;Vw=1;var e=Object.prototype,t=e.hasOwnProperty;function n(r){var a=r.length,i=new r.constructor(a);return a&&typeof r[0]=="string"&&t.call(r,"index")&&(i.index=r.index,i.input=r.input),i}return yg=n,yg}var xg,Gw;function kT(){if(Gw)return xg;Gw=1;var e=Ir(),t=e.Uint8Array;return xg=t,xg}var bg,Kw;function qb(){if(Kw)return bg;Kw=1;var e=kT();function t(n){var r=new n.constructor(n.byteLength);return new e(r).set(new e(n)),r}return bg=t,bg}var vg,Yw;function SU(){if(Yw)return vg;Yw=1;var e=qb();function t(n,r){var a=r?e(n.buffer):n.buffer;return new n.constructor(a,n.byteOffset,n.byteLength)}return vg=t,vg}var kg,Qw;function CU(){if(Qw)return kg;Qw=1;var e=/\w*$/;function t(n){var r=new n.constructor(n.source,e.exec(n));return r.lastIndex=n.lastIndex,r}return kg=t,kg}var _g,Xw;function jU(){if(Xw)return _g;Xw=1;var e=Fs(),t=e?e.prototype:void 0,n=t?t.valueOf:void 0;function r(a){return n?Object(n.call(a)):{}}return _g=r,_g}var wg,Zw;function _T(){if(Zw)return wg;Zw=1;var e=qb();function t(n,r){var a=r?e(n.buffer):n.buffer;return new n.constructor(a,n.byteOffset,n.length)}return wg=t,wg}var Eg,Jw;function TU(){if(Jw)return Eg;Jw=1;var e=qb(),t=SU(),n=CU(),r=jU(),a=_T(),i="[object Boolean]",s="[object Date]",l="[object Map]",c="[object Number]",u="[object RegExp]",d="[object Set]",f="[object String]",p="[object Symbol]",g="[object ArrayBuffer]",m="[object DataView]",y="[object Float32Array]",v="[object Float64Array]",x="[object Int8Array]",b="[object Int16Array]",k="[object Int32Array]",N="[object Uint8Array]",w="[object Uint8ClampedArray]",_="[object Uint16Array]",T="[object Uint32Array]";function A(D,R,$){var F=D.constructor;switch(R){case g:return e(D);case i:case s:return new F(+D);case m:return t(D,$);case y:case v:case x:case b:case k:case N:case w:case _:case T:return a(D,$);case l:return new F;case c:case f:return new F(D);case u:return n(D);case d:return new F;case p:return r(D)}}return Eg=A,Eg}var Ng,e2;function wT(){if(e2)return Ng;e2=1;var e=yr(),t=Object.create,n=function(){function r(){}return function(a){if(!e(a))return{};if(t)return t(a);r.prototype=a;var i=new r;return r.prototype=void 0,i}}();return Ng=n,Ng}var Sg,t2;function ET(){if(t2)return Sg;t2=1;var e=wT(),t=od(),n=sd();function r(a){return typeof a.constructor=="function"&&!n(a)?e(t(a)):{}}return Sg=r,Sg}var Cg,n2;function AU(){if(n2)return Cg;n2=1;var e=zs(),t=Kr(),n="[object Map]";function r(a){return t(a)&&e(a)==n}return Cg=r,Cg}var jg,r2;function RU(){if(r2)return jg;r2=1;var e=AU(),t=id(),n=Fb(),r=n&&n.isMap,a=r?t(r):e;return jg=a,jg}var Tg,a2;function MU(){if(a2)return Tg;a2=1;var e=zs(),t=Kr(),n="[object Set]";function r(a){return t(a)&&e(a)==n}return Tg=r,Tg}var Ag,i2;function IU(){if(i2)return Ag;i2=1;var e=MU(),t=id(),n=Fb(),r=n&&n.isSet,a=r?t(r):e;return Ag=a,Ag}var Rg,s2;function NT(){if(s2)return Rg;s2=1;var e=td(),t=Db(),n=rd(),r=hU(),a=xU(),i=pT(),s=gT(),l=bU(),c=vU(),u=bT(),d=kU(),f=zs(),p=NU(),g=TU(),m=ET(),y=sn(),v=Bs(),x=RU(),b=yr(),k=IU(),N=ri(),w=Di(),_=1,T=2,A=4,D="[object Arguments]",R="[object Array]",$="[object Boolean]",F="[object Date]",G="[object Error]",P="[object Function]",M="[object GeneratorFunction]",S="[object Map]",I="[object Number]",B="[object Object]",Q="[object RegExp]",C="[object Set]",K="[object String]",W="[object Symbol]",j="[object WeakMap]",U="[object ArrayBuffer]",le="[object DataView]",Z="[object Float32Array]",ke="[object Float64Array]",re="[object Int8Array]",X="[object Int16Array]",Ne="[object Int32Array]",ve="[object Uint8Array]",me="[object Uint8ClampedArray]",pe="[object Uint16Array]",Le="[object Uint32Array]",Se={};Se[D]=Se[R]=Se[U]=Se[le]=Se[$]=Se[F]=Se[Z]=Se[ke]=Se[re]=Se[X]=Se[Ne]=Se[S]=Se[I]=Se[B]=Se[Q]=Se[C]=Se[K]=Se[W]=Se[ve]=Se[me]=Se[pe]=Se[Le]=!0,Se[G]=Se[P]=Se[j]=!1;function Te(Fe,fe,xe,Ce,ue,he){var _e,Pe=fe&_,Xe=fe&T,H=fe&A;if(xe&&(_e=ue?xe(Fe,Ce,ue,he):xe(Fe)),_e!==void 0)return _e;if(!b(Fe))return Fe;var z=y(Fe);if(z){if(_e=p(Fe),!Pe)return s(Fe,_e)}else{var te=f(Fe),ce=te==P||te==M;if(v(Fe))return i(Fe,Pe);if(te==B||te==D||ce&&!ue){if(_e=Xe||ce?{}:m(Fe),!Pe)return Xe?c(Fe,a(_e,Fe)):l(Fe,r(_e,Fe))}else{if(!Se[te])return ue?Fe:{};_e=g(Fe,te,Pe)}}he||(he=new e);var je=he.get(Fe);if(je)return je;he.set(Fe,_e),k(Fe)?Fe.forEach(function(Ye){_e.add(Te(Ye,fe,xe,Ye,Fe,he))}):x(Fe)&&Fe.forEach(function(Ye,ot){_e.set(ot,Te(Ye,fe,xe,ot,Fe,he))});var Be=H?Xe?d:u:Xe?w:N,Ke=z?void 0:Be(Fe);return t(Ke||Fe,function(Ye,ot){Ke&&(ot=Ye,Ye=Fe[ot]),n(_e,ot,Te(Ye,fe,xe,ot,Fe,he))}),_e}return Rg=Te,Rg}var Mg,o2;function LU(){if(o2)return Mg;o2=1;var e=NT(),t=4;function n(r){return e(r,t)}return Mg=n,Mg}var Ig,l2;function $b(){if(l2)return Ig;l2=1;function e(t){return function(){return t}}return Ig=e,Ig}var Lg,c2;function OU(){if(c2)return Lg;c2=1;function e(t){return function(n,r,a){for(var i=-1,s=Object(n),l=a(n),c=l.length;c--;){var u=l[t?c:++i];if(r(s[u],u,s)===!1)break}return n}}return Lg=e,Lg}var Og,u2;function Hb(){if(u2)return Og;u2=1;var e=OU(),t=e();return Og=t,Og}var Dg,d2;function Wb(){if(d2)return Dg;d2=1;var e=Hb(),t=ri();function n(r,a){return r&&e(r,a,t)}return Dg=n,Dg}var Pg,f2;function DU(){if(f2)return Pg;f2=1;var e=ya();function t(n,r){return function(a,i){if(a==null)return a;if(!e(a))return n(a,i);for(var s=a.length,l=r?s:-1,c=Object(a);(r?l--:++l<s)&&i(c[l],l,c)!==!1;);return a}}return Pg=t,Pg}var Fg,p2;function ld(){if(p2)return Fg;p2=1;var e=Wb(),t=DU(),n=t(e);return Fg=n,Fg}var Bg,g2;function Pi(){if(g2)return Bg;g2=1;function e(t){return t}return Bg=e,Bg}var zg,h2;function ST(){if(h2)return zg;h2=1;var e=Pi();function t(n){return typeof n=="function"?n:e}return zg=t,zg}var Ug,m2;function CT(){if(m2)return Ug;m2=1;var e=Db(),t=ld(),n=ST(),r=sn();function a(i,s){var l=r(i)?e:t;return l(i,n(s))}return Ug=a,Ug}var qg,y2;function jT(){return y2||(y2=1,qg=CT()),qg}var $g,x2;function PU(){if(x2)return $g;x2=1;var e=ld();function t(n,r){var a=[];return e(n,function(i,s,l){r(i,s,l)&&a.push(i)}),a}return $g=t,$g}var Hg,b2;function FU(){if(b2)return Hg;b2=1;var e="__lodash_hash_undefined__";function t(n){return this.__data__.set(n,e),this}return Hg=t,Hg}var Wg,v2;function BU(){if(v2)return Wg;v2=1;function e(t){return this.__data__.has(t)}return Wg=e,Wg}var Vg,k2;function TT(){if(k2)return Vg;k2=1;var e=Ob(),t=FU(),n=BU();function r(a){var i=-1,s=a==null?0:a.length;for(this.__data__=new e;++i<s;)this.add(a[i])}return r.prototype.add=r.prototype.push=t,r.prototype.has=n,Vg=r,Vg}var Gg,_2;function zU(){if(_2)return Gg;_2=1;function e(t,n){for(var r=-1,a=t==null?0:t.length;++r<a;)if(n(t[r],r,t))return!0;return!1}return Gg=e,Gg}var Kg,w2;function AT(){if(w2)return Kg;w2=1;function e(t,n){return t.has(n)}return Kg=e,Kg}var Yg,E2;function RT(){if(E2)return Yg;E2=1;var e=TT(),t=zU(),n=AT(),r=1,a=2;function i(s,l,c,u,d,f){var p=c&r,g=s.length,m=l.length;if(g!=m&&!(p&&m>g))return!1;var y=f.get(s),v=f.get(l);if(y&&v)return y==l&&v==s;var x=-1,b=!0,k=c&a?new e:void 0;for(f.set(s,l),f.set(l,s);++x<g;){var N=s[x],w=l[x];if(u)var _=p?u(w,N,x,l,s,f):u(N,w,x,s,l,f);if(_!==void 0){if(_)continue;b=!1;break}if(k){if(!t(l,function(T,A){if(!n(k,A)&&(N===T||d(N,T,c,u,f)))return k.push(A)})){b=!1;break}}else if(!(N===w||d(N,w,c,u,f))){b=!1;break}}return f.delete(s),f.delete(l),b}return Yg=i,Yg}var Qg,N2;function UU(){if(N2)return Qg;N2=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(a,i){r[++n]=[i,a]}),r}return Qg=e,Qg}var Xg,S2;function Vb(){if(S2)return Xg;S2=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(a){r[++n]=a}),r}return Xg=e,Xg}var Zg,C2;function qU(){if(C2)return Zg;C2=1;var e=Fs(),t=kT(),n=Ps(),r=RT(),a=UU(),i=Vb(),s=1,l=2,c="[object Boolean]",u="[object Date]",d="[object Error]",f="[object Map]",p="[object Number]",g="[object RegExp]",m="[object Set]",y="[object String]",v="[object Symbol]",x="[object ArrayBuffer]",b="[object DataView]",k=e?e.prototype:void 0,N=k?k.valueOf:void 0;function w(_,T,A,D,R,$,F){switch(A){case b:if(_.byteLength!=T.byteLength||_.byteOffset!=T.byteOffset)return!1;_=_.buffer,T=T.buffer;case x:return!(_.byteLength!=T.byteLength||!$(new t(_),new t(T)));case c:case u:case p:return n(+_,+T);case d:return _.name==T.name&&_.message==T.message;case g:case y:return _==T+"";case f:var G=a;case m:var P=D&s;if(G||(G=i),_.size!=T.size&&!P)return!1;var M=F.get(_);if(M)return M==T;D|=l,F.set(_,T);var S=r(G(_),G(T),D,R,$,F);return F.delete(_),S;case v:if(N)return N.call(_)==N.call(T)}return!1}return Zg=w,Zg}var Jg,j2;function $U(){if(j2)return Jg;j2=1;var e=bT(),t=1,n=Object.prototype,r=n.hasOwnProperty;function a(i,s,l,c,u,d){var f=l&t,p=e(i),g=p.length,m=e(s),y=m.length;if(g!=y&&!f)return!1;for(var v=g;v--;){var x=p[v];if(!(f?x in s:r.call(s,x)))return!1}var b=d.get(i),k=d.get(s);if(b&&k)return b==s&&k==i;var N=!0;d.set(i,s),d.set(s,i);for(var w=f;++v<g;){x=p[v];var _=i[x],T=s[x];if(c)var A=f?c(T,_,x,s,i,d):c(_,T,x,i,s,d);if(!(A===void 0?_===T||u(_,T,l,c,d):A)){N=!1;break}w||(w=x=="constructor")}if(N&&!w){var D=i.constructor,R=s.constructor;D!=R&&"constructor"in i&&"constructor"in s&&!(typeof D=="function"&&D instanceof D&&typeof R=="function"&&R instanceof R)&&(N=!1)}return d.delete(i),d.delete(s),N}return Jg=a,Jg}var eh,T2;function HU(){if(T2)return eh;T2=1;var e=td(),t=RT(),n=qU(),r=$U(),a=zs(),i=sn(),s=Bs(),l=bl(),c=1,u="[object Arguments]",d="[object Array]",f="[object Object]",p=Object.prototype,g=p.hasOwnProperty;function m(y,v,x,b,k,N){var w=i(y),_=i(v),T=w?d:a(y),A=_?d:a(v);T=T==u?f:T,A=A==u?f:A;var D=T==f,R=A==f,$=T==A;if($&&s(y)){if(!s(v))return!1;w=!0,D=!1}if($&&!D)return N||(N=new e),w||l(y)?t(y,v,x,b,k,N):n(y,v,T,x,b,k,N);if(!(x&c)){var F=D&&g.call(y,"__wrapped__"),G=R&&g.call(v,"__wrapped__");if(F||G){var P=F?y.value():y,M=G?v.value():v;return N||(N=new e),k(P,M,x,b,N)}}return $?(N||(N=new e),r(y,v,x,b,k,N)):!1}return eh=m,eh}var th,A2;function MT(){if(A2)return th;A2=1;var e=HU(),t=Kr();function n(r,a,i,s,l){return r===a?!0:r==null||a==null||!t(r)&&!t(a)?r!==r&&a!==a:e(r,a,i,s,n,l)}return th=n,th}var nh,R2;function WU(){if(R2)return nh;R2=1;var e=td(),t=MT(),n=1,r=2;function a(i,s,l,c){var u=l.length,d=u,f=!c;if(i==null)return!d;for(i=Object(i);u--;){var p=l[u];if(f&&p[2]?p[1]!==i[p[0]]:!(p[0]in i))return!1}for(;++u<d;){p=l[u];var g=p[0],m=i[g],y=p[1];if(f&&p[2]){if(m===void 0&&!(g in i))return!1}else{var v=new e;if(c)var x=c(m,y,g,i,s,v);if(!(x===void 0?t(y,m,n|r,c,v):x))return!1}}return!0}return nh=a,nh}var rh,M2;function IT(){if(M2)return rh;M2=1;var e=yr();function t(n){return n===n&&!e(n)}return rh=t,rh}var ah,I2;function VU(){if(I2)return ah;I2=1;var e=IT(),t=ri();function n(r){for(var a=t(r),i=a.length;i--;){var s=a[i],l=r[s];a[i]=[s,l,e(l)]}return a}return ah=n,ah}var ih,L2;function LT(){if(L2)return ih;L2=1;function e(t,n){return function(r){return r==null?!1:r[t]===n&&(n!==void 0||t in Object(r))}}return ih=e,ih}var sh,O2;function GU(){if(O2)return sh;O2=1;var e=WU(),t=VU(),n=LT();function r(a){var i=t(a);return i.length==1&&i[0][2]?n(i[0][0],i[0][1]):function(s){return s===a||e(s,a,i)}}return sh=r,sh}var oh,D2;function Us(){if(D2)return oh;D2=1;var e=Li(),t=Kr(),n="[object Symbol]";function r(a){return typeof a=="symbol"||t(a)&&e(a)==n}return oh=r,oh}var lh,P2;function Gb(){if(P2)return lh;P2=1;var e=sn(),t=Us(),n=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,r=/^\w*$/;function a(i,s){if(e(i))return!1;var l=typeof i;return l=="number"||l=="symbol"||l=="boolean"||i==null||t(i)?!0:r.test(i)||!n.test(i)||s!=null&&i in Object(s)}return lh=a,lh}var ch,F2;function KU(){if(F2)return ch;F2=1;var e=Ob(),t="Expected a function";function n(r,a){if(typeof r!="function"||a!=null&&typeof a!="function")throw new TypeError(t);var i=function(){var s=arguments,l=a?a.apply(this,s):s[0],c=i.cache;if(c.has(l))return c.get(l);var u=r.apply(this,s);return i.cache=c.set(l,u)||c,u};return i.cache=new(n.Cache||e),i}return n.Cache=e,ch=n,ch}var uh,B2;function YU(){if(B2)return uh;B2=1;var e=KU(),t=500;function n(r){var a=e(r,function(s){return i.size===t&&i.clear(),s}),i=a.cache;return a}return uh=n,uh}var dh,z2;function QU(){if(z2)return dh;z2=1;var e=YU(),t=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,n=/\\(\\)?/g,r=e(function(a){var i=[];return a.charCodeAt(0)===46&&i.push(""),a.replace(t,function(s,l,c,u){i.push(c?u.replace(n,"$1"):l||s)}),i});return dh=r,dh}var fh,U2;function cd(){if(U2)return fh;U2=1;function e(t,n){for(var r=-1,a=t==null?0:t.length,i=Array(a);++r<a;)i[r]=n(t[r],r,t);return i}return fh=e,fh}var ph,q2;function XU(){if(q2)return ph;q2=1;var e=Fs(),t=cd(),n=sn(),r=Us(),a=e?e.prototype:void 0,i=a?a.toString:void 0;function s(l){if(typeof l=="string")return l;if(n(l))return t(l,s)+"";if(r(l))return i?i.call(l):"";var c=l+"";return c=="0"&&1/l==-1/0?"-0":c}return ph=s,ph}var gh,$2;function OT(){if($2)return gh;$2=1;var e=XU();function t(n){return n==null?"":e(n)}return gh=t,gh}var hh,H2;function ud(){if(H2)return hh;H2=1;var e=sn(),t=Gb(),n=QU(),r=OT();function a(i,s){return e(i)?i:t(i,s)?[i]:n(r(i))}return hh=a,hh}var mh,W2;function vl(){if(W2)return mh;W2=1;var e=Us();function t(n){if(typeof n=="string"||e(n))return n;var r=n+"";return r=="0"&&1/n==-1/0?"-0":r}return mh=t,mh}var yh,V2;function dd(){if(V2)return yh;V2=1;var e=ud(),t=vl();function n(r,a){a=e(a,r);for(var i=0,s=a.length;r!=null&&i<s;)r=r[t(a[i++])];return i&&i==s?r:void 0}return yh=n,yh}var xh,G2;function ZU(){if(G2)return xh;G2=1;var e=dd();function t(n,r,a){var i=n==null?void 0:e(n,r);return i===void 0?a:i}return xh=t,xh}var bh,K2;function JU(){if(K2)return bh;K2=1;function e(t,n){return t!=null&&n in Object(t)}return bh=e,bh}var vh,Y2;function DT(){if(Y2)return vh;Y2=1;var e=ud(),t=xl(),n=sn(),r=ad(),a=Pb(),i=vl();function s(l,c,u){c=e(c,l);for(var d=-1,f=c.length,p=!1;++d<f;){var g=i(c[d]);if(!(p=l!=null&&u(l,g)))break;l=l[g]}return p||++d!=f?p:(f=l==null?0:l.length,!!f&&a(f)&&r(g,f)&&(n(l)||t(l)))}return vh=s,vh}var kh,Q2;function PT(){if(Q2)return kh;Q2=1;var e=JU(),t=DT();function n(r,a){return r!=null&&t(r,a,e)}return kh=n,kh}var _h,X2;function eq(){if(X2)return _h;X2=1;var e=MT(),t=ZU(),n=PT(),r=Gb(),a=IT(),i=LT(),s=vl(),l=1,c=2;function u(d,f){return r(d)&&a(f)?i(s(d),f):function(p){var g=t(p,d);return g===void 0&&g===f?n(p,d):e(f,g,l|c)}}return _h=u,_h}var wh,Z2;function FT(){if(Z2)return wh;Z2=1;function e(t){return function(n){return n==null?void 0:n[t]}}return wh=e,wh}var Eh,J2;function tq(){if(J2)return Eh;J2=1;var e=dd();function t(n){return function(r){return e(r,n)}}return Eh=t,Eh}var Nh,eE;function nq(){if(eE)return Nh;eE=1;var e=FT(),t=tq(),n=Gb(),r=vl();function a(i){return n(i)?e(r(i)):t(i)}return Nh=a,Nh}var Sh,tE;function xa(){if(tE)return Sh;tE=1;var e=GU(),t=eq(),n=Pi(),r=sn(),a=nq();function i(s){return typeof s=="function"?s:s==null?n:typeof s=="object"?r(s)?t(s[0],s[1]):e(s):a(s)}return Sh=i,Sh}var Ch,nE;function BT(){if(nE)return Ch;nE=1;var e=hT(),t=PU(),n=xa(),r=sn();function a(i,s){var l=r(i)?e:t;return l(i,n(s,3))}return Ch=a,Ch}var jh,rE;function rq(){if(rE)return jh;rE=1;var e=Object.prototype,t=e.hasOwnProperty;function n(r,a){return r!=null&&t.call(r,a)}return jh=n,jh}var Th,aE;function zT(){if(aE)return Th;aE=1;var e=rq(),t=DT();function n(r,a){return r!=null&&t(r,a,e)}return Th=n,Th}var Ah,iE;function aq(){if(iE)return Ah;iE=1;var e=Bb(),t=zs(),n=xl(),r=sn(),a=ya(),i=Bs(),s=sd(),l=bl(),c="[object Map]",u="[object Set]",d=Object.prototype,f=d.hasOwnProperty;function p(g){if(g==null)return!0;if(a(g)&&(r(g)||typeof g=="string"||typeof g.splice=="function"||i(g)||l(g)||n(g)))return!g.length;var m=t(g);if(m==c||m==u)return!g.size;if(s(g))return!e(g).length;for(var y in g)if(f.call(g,y))return!1;return!0}return Ah=p,Ah}var Rh,sE;function UT(){if(sE)return Rh;sE=1;function e(t){return t===void 0}return Rh=e,Rh}var Mh,oE;function qT(){if(oE)return Mh;oE=1;var e=ld(),t=ya();function n(r,a){var i=-1,s=t(r)?Array(r.length):[];return e(r,function(l,c,u){s[++i]=a(l,c,u)}),s}return Mh=n,Mh}var Ih,lE;function $T(){if(lE)return Ih;lE=1;var e=cd(),t=xa(),n=qT(),r=sn();function a(i,s){var l=r(i)?e:n;return l(i,t(s,3))}return Ih=a,Ih}var Lh,cE;function iq(){if(cE)return Lh;cE=1;function e(t,n,r,a){var i=-1,s=t==null?0:t.length;for(a&&s&&(r=t[++i]);++i<s;)r=n(r,t[i],i,t);return r}return Lh=e,Lh}var Oh,uE;function sq(){if(uE)return Oh;uE=1;function e(t,n,r,a,i){return i(t,function(s,l,c){r=a?(a=!1,s):n(r,s,l,c)}),r}return Oh=e,Oh}var Dh,dE;function HT(){if(dE)return Dh;dE=1;var e=iq(),t=ld(),n=xa(),r=sq(),a=sn();function i(s,l,c){var u=a(s)?e:r,d=arguments.length<3;return u(s,n(l,4),c,d,t)}return Dh=i,Dh}var Ph,fE;function oq(){if(fE)return Ph;fE=1;var e=Li(),t=sn(),n=Kr(),r="[object String]";function a(i){return typeof i=="string"||!t(i)&&n(i)&&e(i)==r}return Ph=a,Ph}var Fh,pE;function lq(){if(pE)return Fh;pE=1;var e=FT(),t=e("length");return Fh=t,Fh}var Bh,gE;function cq(){if(gE)return Bh;gE=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",n="\\ufe20-\\ufe2f",r="\\u20d0-\\u20ff",a=t+n+r,i="\\ufe0e\\ufe0f",s="\\u200d",l=RegExp("["+s+e+a+i+"]");function c(u){return l.test(u)}return Bh=c,Bh}var zh,hE;function uq(){if(hE)return zh;hE=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",n="\\ufe20-\\ufe2f",r="\\u20d0-\\u20ff",a=t+n+r,i="\\ufe0e\\ufe0f",s="["+e+"]",l="["+a+"]",c="\\ud83c[\\udffb-\\udfff]",u="(?:"+l+"|"+c+")",d="[^"+e+"]",f="(?:\\ud83c[\\udde6-\\uddff]){2}",p="[\\ud800-\\udbff][\\udc00-\\udfff]",g="\\u200d",m=u+"?",y="["+i+"]?",v="(?:"+g+"(?:"+[d,f,p].join("|")+")"+y+m+")*",x=y+m+v,b="(?:"+[d+l+"?",l,f,p,s].join("|")+")",k=RegExp(c+"(?="+c+")|"+b+x,"g");function N(w){for(var _=k.lastIndex=0;k.test(w);)++_;return _}return zh=N,zh}var Uh,mE;function dq(){if(mE)return Uh;mE=1;var e=lq(),t=cq(),n=uq();function r(a){return t(a)?n(a):e(a)}return Uh=r,Uh}var qh,yE;function fq(){if(yE)return qh;yE=1;var e=Bb(),t=zs(),n=ya(),r=oq(),a=dq(),i="[object Map]",s="[object Set]";function l(c){if(c==null)return 0;if(n(c))return r(c)?a(c):c.length;var u=t(c);return u==i||u==s?c.size:e(c).length}return qh=l,qh}var $h,xE;function pq(){if(xE)return $h;xE=1;var e=Db(),t=wT(),n=Wb(),r=xa(),a=od(),i=sn(),s=Bs(),l=ml(),c=yr(),u=bl();function d(f,p,g){var m=i(f),y=m||s(f)||u(f);if(p=r(p,4),g==null){var v=f&&f.constructor;y?g=m?new v:[]:c(f)?g=l(v)?t(a(f)):{}:g={}}return(y?e:n)(f,function(x,b,k){return p(g,x,b,k)}),g}return $h=d,$h}var Hh,bE;function gq(){if(bE)return Hh;bE=1;var e=Fs(),t=xl(),n=sn(),r=e?e.isConcatSpreadable:void 0;function a(i){return n(i)||t(i)||!!(r&&i&&i[r])}return Hh=a,Hh}var Wh,vE;function Kb(){if(vE)return Wh;vE=1;var e=Ub(),t=gq();function n(r,a,i,s,l){var c=-1,u=r.length;for(i||(i=t),l||(l=[]);++c<u;){var d=r[c];a>0&&i(d)?a>1?n(d,a-1,i,s,l):e(l,d):s||(l[l.length]=d)}return l}return Wh=n,Wh}var Vh,kE;function hq(){if(kE)return Vh;kE=1;function e(t,n,r){switch(r.length){case 0:return t.call(n);case 1:return t.call(n,r[0]);case 2:return t.call(n,r[0],r[1]);case 3:return t.call(n,r[0],r[1],r[2])}return t.apply(n,r)}return Vh=e,Vh}var Gh,_E;function WT(){if(_E)return Gh;_E=1;var e=hq(),t=Math.max;function n(r,a,i){return a=t(a===void 0?r.length-1:a,0),function(){for(var s=arguments,l=-1,c=t(s.length-a,0),u=Array(c);++l<c;)u[l]=s[a+l];l=-1;for(var d=Array(a+1);++l<a;)d[l]=s[l];return d[a]=i(u),e(r,this,d)}}return Gh=n,Gh}var Kh,wE;function mq(){if(wE)return Kh;wE=1;var e=$b(),t=uT(),n=Pi(),r=t?function(a,i){return t(a,"toString",{configurable:!0,enumerable:!1,value:e(i),writable:!0})}:n;return Kh=r,Kh}var Yh,EE;function yq(){if(EE)return Yh;EE=1;var e=800,t=16,n=Date.now;function r(a){var i=0,s=0;return function(){var l=n(),c=t-(l-s);if(s=l,c>0){if(++i>=e)return arguments[0]}else i=0;return a.apply(void 0,arguments)}}return Yh=r,Yh}var Qh,NE;function VT(){if(NE)return Qh;NE=1;var e=mq(),t=yq(),n=t(e);return Qh=n,Qh}var Xh,SE;function fd(){if(SE)return Xh;SE=1;var e=Pi(),t=WT(),n=VT();function r(a,i){return n(t(a,i,e),a+"")}return Xh=r,Xh}var Zh,CE;function GT(){if(CE)return Zh;CE=1;function e(t,n,r,a){for(var i=t.length,s=r+(a?1:-1);a?s--:++s<i;)if(n(t[s],s,t))return s;return-1}return Zh=e,Zh}var Jh,jE;function xq(){if(jE)return Jh;jE=1;function e(t){return t!==t}return Jh=e,Jh}var em,TE;function bq(){if(TE)return em;TE=1;function e(t,n,r){for(var a=r-1,i=t.length;++a<i;)if(t[a]===n)return a;return-1}return em=e,em}var tm,AE;function vq(){if(AE)return tm;AE=1;var e=GT(),t=xq(),n=bq();function r(a,i,s){return i===i?n(a,i,s):e(a,t,s)}return tm=r,tm}var nm,RE;function kq(){if(RE)return nm;RE=1;var e=vq();function t(n,r){var a=n==null?0:n.length;return!!a&&e(n,r,0)>-1}return nm=t,nm}var rm,ME;function _q(){if(ME)return rm;ME=1;function e(t,n,r){for(var a=-1,i=t==null?0:t.length;++a<i;)if(r(n,t[a]))return!0;return!1}return rm=e,rm}var am,IE;function wq(){if(IE)return am;IE=1;function e(){}return am=e,am}var im,LE;function Eq(){if(LE)return im;LE=1;var e=vT(),t=wq(),n=Vb(),r=1/0,a=e&&1/n(new e([,-0]))[1]==r?function(i){return new e(i)}:t;return im=a,im}var sm,OE;function Nq(){if(OE)return sm;OE=1;var e=TT(),t=kq(),n=_q(),r=AT(),a=Eq(),i=Vb(),s=200;function l(c,u,d){var f=-1,p=t,g=c.length,m=!0,y=[],v=y;if(d)m=!1,p=n;else if(g>=s){var x=u?null:a(c);if(x)return i(x);m=!1,p=r,v=new e}else v=u?[]:y;e:for(;++f<g;){var b=c[f],k=u?u(b):b;if(b=d||b!==0?b:0,m&&k===k){for(var N=v.length;N--;)if(v[N]===k)continue e;u&&v.push(k),y.push(b)}else p(v,k,d)||(v!==y&&v.push(k),y.push(b))}return y}return sm=l,sm}var om,DE;function KT(){if(DE)return om;DE=1;var e=ya(),t=Kr();function n(r){return t(r)&&e(r)}return om=n,om}var lm,PE;function Sq(){if(PE)return lm;PE=1;var e=Kb(),t=fd(),n=Nq(),r=KT(),a=t(function(i){return n(e(i,1,r,!0))});return lm=a,lm}var cm,FE;function Cq(){if(FE)return cm;FE=1;var e=cd();function t(n,r){return e(r,function(a){return n[a]})}return cm=t,cm}var um,BE;function YT(){if(BE)return um;BE=1;var e=Cq(),t=ri();function n(r){return r==null?[]:e(r,t(r))}return um=n,um}var dm,zE;function xr(){if(zE)return dm;zE=1;var e;if(typeof Ib=="function")try{e={clone:LU(),constant:$b(),each:jT(),filter:BT(),has:zT(),isArray:sn(),isEmpty:aq(),isFunction:ml(),isUndefined:UT(),keys:ri(),map:$T(),reduce:HT(),size:fq(),transform:pq(),union:Sq(),values:YT()}}catch{}return e||(e=window._),dm=e,dm}var fm,UE;function Yb(){if(UE)return fm;UE=1;var e=xr();fm=a;var t="\0",n="\0",r="";function a(d){this._isDirected=e.has(d,"directed")?d.directed:!0,this._isMultigraph=e.has(d,"multigraph")?d.multigraph:!1,this._isCompound=e.has(d,"compound")?d.compound:!1,this._label=void 0,this._defaultNodeLabelFn=e.constant(void 0),this._defaultEdgeLabelFn=e.constant(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[n]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}a.prototype._nodeCount=0,a.prototype._edgeCount=0,a.prototype.isDirected=function(){return this._isDirected},a.prototype.isMultigraph=function(){return this._isMultigraph},a.prototype.isCompound=function(){return this._isCompound},a.prototype.setGraph=function(d){return this._label=d,this},a.prototype.graph=function(){return this._label},a.prototype.setDefaultNodeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultNodeLabelFn=d,this},a.prototype.nodeCount=function(){return this._nodeCount},a.prototype.nodes=function(){return e.keys(this._nodes)},a.prototype.sources=function(){var d=this;return e.filter(this.nodes(),function(f){return e.isEmpty(d._in[f])})},a.prototype.sinks=function(){var d=this;return e.filter(this.nodes(),function(f){return e.isEmpty(d._out[f])})},a.prototype.setNodes=function(d,f){var p=arguments,g=this;return e.each(d,function(m){p.length>1?g.setNode(m,f):g.setNode(m)}),this},a.prototype.setNode=function(d,f){return e.has(this._nodes,d)?(arguments.length>1&&(this._nodes[d]=f),this):(this._nodes[d]=arguments.length>1?f:this._defaultNodeLabelFn(d),this._isCompound&&(this._parent[d]=n,this._children[d]={},this._children[n][d]=!0),this._in[d]={},this._preds[d]={},this._out[d]={},this._sucs[d]={},++this._nodeCount,this)},a.prototype.node=function(d){return this._nodes[d]},a.prototype.hasNode=function(d){return e.has(this._nodes,d)},a.prototype.removeNode=function(d){var f=this;if(e.has(this._nodes,d)){var p=function(g){f.removeEdge(f._edgeObjs[g])};delete this._nodes[d],this._isCompound&&(this._removeFromParentsChildList(d),delete this._parent[d],e.each(this.children(d),function(g){f.setParent(g)}),delete this._children[d]),e.each(e.keys(this._in[d]),p),delete this._in[d],delete this._preds[d],e.each(e.keys(this._out[d]),p),delete this._out[d],delete this._sucs[d],--this._nodeCount}return this},a.prototype.setParent=function(d,f){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(f))f=n;else{f+="";for(var p=f;!e.isUndefined(p);p=this.parent(p))if(p===d)throw new Error("Setting "+f+" as parent of "+d+" would create a cycle");this.setNode(f)}return this.setNode(d),this._removeFromParentsChildList(d),this._parent[d]=f,this._children[f][d]=!0,this},a.prototype._removeFromParentsChildList=function(d){delete this._children[this._parent[d]][d]},a.prototype.parent=function(d){if(this._isCompound){var f=this._parent[d];if(f!==n)return f}},a.prototype.children=function(d){if(e.isUndefined(d)&&(d=n),this._isCompound){var f=this._children[d];if(f)return e.keys(f)}else{if(d===n)return this.nodes();if(this.hasNode(d))return[]}},a.prototype.predecessors=function(d){var f=this._preds[d];if(f)return e.keys(f)},a.prototype.successors=function(d){var f=this._sucs[d];if(f)return e.keys(f)},a.prototype.neighbors=function(d){var f=this.predecessors(d);if(f)return e.union(f,this.successors(d))},a.prototype.isLeaf=function(d){var f;return this.isDirected()?f=this.successors(d):f=this.neighbors(d),f.length===0},a.prototype.filterNodes=function(d){var f=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});f.setGraph(this.graph());var p=this;e.each(this._nodes,function(y,v){d(v)&&f.setNode(v,y)}),e.each(this._edgeObjs,function(y){f.hasNode(y.v)&&f.hasNode(y.w)&&f.setEdge(y,p.edge(y))});var g={};function m(y){var v=p.parent(y);return v===void 0||f.hasNode(v)?(g[y]=v,v):v in g?g[v]:m(v)}return this._isCompound&&e.each(f.nodes(),function(y){f.setParent(y,m(y))}),f},a.prototype.setDefaultEdgeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultEdgeLabelFn=d,this},a.prototype.edgeCount=function(){return this._edgeCount},a.prototype.edges=function(){return e.values(this._edgeObjs)},a.prototype.setPath=function(d,f){var p=this,g=arguments;return e.reduce(d,function(m,y){return g.length>1?p.setEdge(m,y,f):p.setEdge(m,y),y}),this},a.prototype.setEdge=function(){var d,f,p,g,m=!1,y=arguments[0];typeof y=="object"&&y!==null&&"v"in y?(d=y.v,f=y.w,p=y.name,arguments.length===2&&(g=arguments[1],m=!0)):(d=y,f=arguments[1],p=arguments[3],arguments.length>2&&(g=arguments[2],m=!0)),d=""+d,f=""+f,e.isUndefined(p)||(p=""+p);var v=l(this._isDirected,d,f,p);if(e.has(this._edgeLabels,v))return m&&(this._edgeLabels[v]=g),this;if(!e.isUndefined(p)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(d),this.setNode(f),this._edgeLabels[v]=m?g:this._defaultEdgeLabelFn(d,f,p);var x=c(this._isDirected,d,f,p);return d=x.v,f=x.w,Object.freeze(x),this._edgeObjs[v]=x,i(this._preds[f],d),i(this._sucs[d],f),this._in[f][v]=x,this._out[d][v]=x,this._edgeCount++,this},a.prototype.edge=function(d,f,p){var g=arguments.length===1?u(this._isDirected,arguments[0]):l(this._isDirected,d,f,p);return this._edgeLabels[g]},a.prototype.hasEdge=function(d,f,p){var g=arguments.length===1?u(this._isDirected,arguments[0]):l(this._isDirected,d,f,p);return e.has(this._edgeLabels,g)},a.prototype.removeEdge=function(d,f,p){var g=arguments.length===1?u(this._isDirected,arguments[0]):l(this._isDirected,d,f,p),m=this._edgeObjs[g];return m&&(d=m.v,f=m.w,delete this._edgeLabels[g],delete this._edgeObjs[g],s(this._preds[f],d),s(this._sucs[d],f),delete this._in[f][g],delete this._out[d][g],this._edgeCount--),this},a.prototype.inEdges=function(d,f){var p=this._in[d];if(p){var g=e.values(p);return f?e.filter(g,function(m){return m.v===f}):g}},a.prototype.outEdges=function(d,f){var p=this._out[d];if(p){var g=e.values(p);return f?e.filter(g,function(m){return m.w===f}):g}},a.prototype.nodeEdges=function(d,f){var p=this.inEdges(d,f);if(p)return p.concat(this.outEdges(d,f))};function i(d,f){d[f]?d[f]++:d[f]=1}function s(d,f){--d[f]||delete d[f]}function l(d,f,p,g){var m=""+f,y=""+p;if(!d&&m>y){var v=m;m=y,y=v}return m+r+y+r+(e.isUndefined(g)?t:g)}function c(d,f,p,g){var m=""+f,y=""+p;if(!d&&m>y){var v=m;m=y,y=v}var x={v:m,w:y};return g&&(x.name=g),x}function u(d,f){return l(d,f.v,f.w,f.name)}return fm}var pm,qE;function jq(){return qE||(qE=1,pm="2.1.8"),pm}var gm,$E;function Tq(){return $E||($E=1,gm={Graph:Yb(),version:jq()}),gm}var hm,HE;function Aq(){if(HE)return hm;HE=1;var e=xr(),t=Yb();hm={write:n,read:i};function n(s){var l={options:{directed:s.isDirected(),multigraph:s.isMultigraph(),compound:s.isCompound()},nodes:r(s),edges:a(s)};return e.isUndefined(s.graph())||(l.value=e.clone(s.graph())),l}function r(s){return e.map(s.nodes(),function(l){var c=s.node(l),u=s.parent(l),d={v:l};return e.isUndefined(c)||(d.value=c),e.isUndefined(u)||(d.parent=u),d})}function a(s){return e.map(s.edges(),function(l){var c=s.edge(l),u={v:l.v,w:l.w};return e.isUndefined(l.name)||(u.name=l.name),e.isUndefined(c)||(u.value=c),u})}function i(s){var l=new t(s.options).setGraph(s.value);return e.each(s.nodes,function(c){l.setNode(c.v,c.value),c.parent&&l.setParent(c.v,c.parent)}),e.each(s.edges,function(c){l.setEdge({v:c.v,w:c.w,name:c.name},c.value)}),l}return hm}var mm,WE;function Rq(){if(WE)return mm;WE=1;var e=xr();mm=t;function t(n){var r={},a=[],i;function s(l){e.has(r,l)||(r[l]=!0,i.push(l),e.each(n.successors(l),s),e.each(n.predecessors(l),s))}return e.each(n.nodes(),function(l){i=[],s(l),i.length&&a.push(i)}),a}return mm}var ym,VE;function QT(){if(VE)return ym;VE=1;var e=xr();ym=t;function t(){this._arr=[],this._keyIndices={}}return t.prototype.size=function(){return this._arr.length},t.prototype.keys=function(){return this._arr.map(function(n){return n.key})},t.prototype.has=function(n){return e.has(this._keyIndices,n)},t.prototype.priority=function(n){var r=this._keyIndices[n];if(r!==void 0)return this._arr[r].priority},t.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},t.prototype.add=function(n,r){var a=this._keyIndices;if(n=String(n),!e.has(a,n)){var i=this._arr,s=i.length;return a[n]=s,i.push({key:n,priority:r}),this._decrease(s),!0}return!1},t.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var n=this._arr.pop();return delete this._keyIndices[n.key],this._heapify(0),n.key},t.prototype.decrease=function(n,r){var a=this._keyIndices[n];if(r>this._arr[a].priority)throw new Error("New priority is greater than current priority. Key: "+n+" Old: "+this._arr[a].priority+" New: "+r);this._arr[a].priority=r,this._decrease(a)},t.prototype._heapify=function(n){var r=this._arr,a=2*n,i=a+1,s=n;a<r.length&&(s=r[a].priority<r[s].priority?a:s,i<r.length&&(s=r[i].priority<r[s].priority?i:s),s!==n&&(this._swap(n,s),this._heapify(s)))},t.prototype._decrease=function(n){for(var r=this._arr,a=r[n].priority,i;n!==0&&(i=n>>1,!(r[i].priority<a));)this._swap(n,i),n=i},t.prototype._swap=function(n,r){var a=this._arr,i=this._keyIndices,s=a[n],l=a[r];a[n]=l,a[r]=s,i[l.key]=n,i[s.key]=r},ym}var xm,GE;function XT(){if(GE)return xm;GE=1;var e=xr(),t=QT();xm=r;var n=e.constant(1);function r(i,s,l,c){return a(i,String(s),l||n,c||function(u){return i.outEdges(u)})}function a(i,s,l,c){var u={},d=new t,f,p,g=function(m){var y=m.v!==f?m.v:m.w,v=u[y],x=l(m),b=p.distance+x;if(x<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+m+" Weight: "+x);b<v.distance&&(v.distance=b,v.predecessor=f,d.decrease(y,b))};for(i.nodes().forEach(function(m){var y=m===s?0:Number.POSITIVE_INFINITY;u[m]={distance:y},d.add(m,y)});d.size()>0&&(f=d.removeMin(),p=u[f],p.distance!==Number.POSITIVE_INFINITY);)c(f).forEach(g);return u}return xm}var bm,KE;function Mq(){if(KE)return bm;KE=1;var e=XT(),t=xr();bm=n;function n(r,a,i){return t.transform(r.nodes(),function(s,l){s[l]=e(r,l,a,i)},{})}return bm}var vm,YE;function ZT(){if(YE)return vm;YE=1;var e=xr();vm=t;function t(n){var r=0,a=[],i={},s=[];function l(c){var u=i[c]={onStack:!0,lowlink:r,index:r++};if(a.push(c),n.successors(c).forEach(function(p){e.has(i,p)?i[p].onStack&&(u.lowlink=Math.min(u.lowlink,i[p].index)):(l(p),u.lowlink=Math.min(u.lowlink,i[p].lowlink))}),u.lowlink===u.index){var d=[],f;do f=a.pop(),i[f].onStack=!1,d.push(f);while(c!==f);s.push(d)}}return n.nodes().forEach(function(c){e.has(i,c)||l(c)}),s}return vm}var km,QE;function Iq(){if(QE)return km;QE=1;var e=xr(),t=ZT();km=n;function n(r){return e.filter(t(r),function(a){return a.length>1||a.length===1&&r.hasEdge(a[0],a[0])})}return km}var _m,XE;function Lq(){if(XE)return _m;XE=1;var e=xr();_m=n;var t=e.constant(1);function n(a,i,s){return r(a,i||t,s||function(l){return a.outEdges(l)})}function r(a,i,s){var l={},c=a.nodes();return c.forEach(function(u){l[u]={},l[u][u]={distance:0},c.forEach(function(d){u!==d&&(l[u][d]={distance:Number.POSITIVE_INFINITY})}),s(u).forEach(function(d){var f=d.v===u?d.w:d.v,p=i(d);l[u][f]={distance:p,predecessor:u}})}),c.forEach(function(u){var d=l[u];c.forEach(function(f){var p=l[f];c.forEach(function(g){var m=p[u],y=d[g],v=p[g],x=m.distance+y.distance;x<v.distance&&(v.distance=x,v.predecessor=y.predecessor)})})}),l}return _m}var wm,ZE;function JT(){if(ZE)return wm;ZE=1;var e=xr();wm=t,t.CycleException=n;function t(r){var a={},i={},s=[];function l(c){if(e.has(i,c))throw new n;e.has(a,c)||(i[c]=!0,a[c]=!0,e.each(r.predecessors(c),l),delete i[c],s.push(c))}if(e.each(r.sinks(),l),e.size(a)!==r.nodeCount())throw new n;return s}function n(){}return n.prototype=new Error,wm}var Em,JE;function Oq(){if(JE)return Em;JE=1;var e=JT();Em=t;function t(n){try{e(n)}catch(r){if(r instanceof e.CycleException)return!1;throw r}return!0}return Em}var Nm,eN;function eA(){if(eN)return Nm;eN=1;var e=xr();Nm=t;function t(r,a,i){e.isArray(a)||(a=[a]);var s=(r.isDirected()?r.successors:r.neighbors).bind(r),l=[],c={};return e.each(a,function(u){if(!r.hasNode(u))throw new Error("Graph does not have node: "+u);n(r,u,i==="post",c,s,l)}),l}function n(r,a,i,s,l,c){e.has(s,a)||(s[a]=!0,i||c.push(a),e.each(l(a),function(u){n(r,u,i,s,l,c)}),i&&c.push(a))}return Nm}var Sm,tN;function Dq(){if(tN)return Sm;tN=1;var e=eA();Sm=t;function t(n,r){return e(n,r,"post")}return Sm}var Cm,nN;function Pq(){if(nN)return Cm;nN=1;var e=eA();Cm=t;function t(n,r){return e(n,r,"pre")}return Cm}var jm,rN;function Fq(){if(rN)return jm;rN=1;var e=xr(),t=Yb(),n=QT();jm=r;function r(a,i){var s=new t,l={},c=new n,u;function d(p){var g=p.v===u?p.w:p.v,m=c.priority(g);if(m!==void 0){var y=i(p);y<m&&(l[g]=u,c.decrease(g,y))}}if(a.nodeCount()===0)return s;e.each(a.nodes(),function(p){c.add(p,Number.POSITIVE_INFINITY),s.setNode(p)}),c.decrease(a.nodes()[0],0);for(var f=!1;c.size()>0;){if(u=c.removeMin(),e.has(l,u))s.setEdge(u,l[u]);else{if(f)throw new Error("Input graph is not connected: "+a);f=!0}a.nodeEdges(u).forEach(d)}return s}return jm}var Tm,aN;function Bq(){return aN||(aN=1,Tm={components:Rq(),dijkstra:XT(),dijkstraAll:Mq(),findCycles:Iq(),floydWarshall:Lq(),isAcyclic:Oq(),postorder:Dq(),preorder:Pq(),prim:Fq(),tarjan:ZT(),topsort:JT()}),Tm}var Am,iN;function zq(){if(iN)return Am;iN=1;var e=Tq();return Am={Graph:e.Graph,json:Aq(),alg:Bq(),version:e.version},Am}var bu;if(typeof Ib=="function")try{bu=zq()}catch{}bu||(bu=window.graphlib);var Lr=bu,Rm,sN;function Uq(){if(sN)return Rm;sN=1;var e=NT(),t=1,n=4;function r(a){return e(a,t|n)}return Rm=r,Rm}var Mm,oN;function pd(){if(oN)return Mm;oN=1;var e=Ps(),t=ya(),n=ad(),r=yr();function a(i,s,l){if(!r(l))return!1;var c=typeof s;return(c=="number"?t(l)&&n(s,l.length):c=="string"&&s in l)?e(l[s],i):!1}return Mm=a,Mm}var Im,lN;function qq(){if(lN)return Im;lN=1;var e=fd(),t=Ps(),n=pd(),r=Di(),a=Object.prototype,i=a.hasOwnProperty,s=e(function(l,c){l=Object(l);var u=-1,d=c.length,f=d>2?c[2]:void 0;for(f&&n(c[0],c[1],f)&&(d=1);++u<d;)for(var p=c[u],g=r(p),m=-1,y=g.length;++m<y;){var v=g[m],x=l[v];(x===void 0||t(x,a[v])&&!i.call(l,v))&&(l[v]=p[v])}return l});return Im=s,Im}var Lm,cN;function $q(){if(cN)return Lm;cN=1;var e=xa(),t=ya(),n=ri();function r(a){return function(i,s,l){var c=Object(i);if(!t(i)){var u=e(s,3);i=n(i),s=function(f){return u(c[f],f,c)}}var d=a(i,s,l);return d>-1?c[u?i[d]:d]:void 0}}return Lm=r,Lm}var Om,uN;function Hq(){if(uN)return Om;uN=1;var e=/\s/;function t(n){for(var r=n.length;r--&&e.test(n.charAt(r)););return r}return Om=t,Om}var Dm,dN;function Wq(){if(dN)return Dm;dN=1;var e=Hq(),t=/^\s+/;function n(r){return r&&r.slice(0,e(r)+1).replace(t,"")}return Dm=n,Dm}var Pm,fN;function Vq(){if(fN)return Pm;fN=1;var e=Wq(),t=yr(),n=Us(),r=NaN,a=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,s=/^0o[0-7]+$/i,l=parseInt;function c(u){if(typeof u=="number")return u;if(n(u))return r;if(t(u)){var d=typeof u.valueOf=="function"?u.valueOf():u;u=t(d)?d+"":d}if(typeof u!="string")return u===0?u:+u;u=e(u);var f=i.test(u);return f||s.test(u)?l(u.slice(2),f?2:8):a.test(u)?r:+u}return Pm=c,Pm}var Fm,pN;function tA(){if(pN)return Fm;pN=1;var e=Vq(),t=1/0,n=17976931348623157e292;function r(a){if(!a)return a===0?a:0;if(a=e(a),a===t||a===-t){var i=a<0?-1:1;return i*n}return a===a?a:0}return Fm=r,Fm}var Bm,gN;function Gq(){if(gN)return Bm;gN=1;var e=tA();function t(n){var r=e(n),a=r%1;return r===r?a?r-a:r:0}return Bm=t,Bm}var zm,hN;function Kq(){if(hN)return zm;hN=1;var e=GT(),t=xa(),n=Gq(),r=Math.max;function a(i,s,l){var c=i==null?0:i.length;if(!c)return-1;var u=l==null?0:n(l);return u<0&&(u=r(c+u,0)),e(i,t(s,3),u)}return zm=a,zm}var Um,mN;function Yq(){if(mN)return Um;mN=1;var e=$q(),t=Kq(),n=e(t);return Um=n,Um}var qm,yN;function nA(){if(yN)return qm;yN=1;var e=Kb();function t(n){var r=n==null?0:n.length;return r?e(n,1):[]}return qm=t,qm}var $m,xN;function Qq(){if(xN)return $m;xN=1;var e=Hb(),t=ST(),n=Di();function r(a,i){return a==null?a:e(a,t(i),n)}return $m=r,$m}var Hm,bN;function Xq(){if(bN)return Hm;bN=1;function e(t){var n=t==null?0:t.length;return n?t[n-1]:void 0}return Hm=e,Hm}var Wm,vN;function Zq(){if(vN)return Wm;vN=1;var e=nd(),t=Wb(),n=xa();function r(a,i){var s={};return i=n(i,3),t(a,function(l,c,u){e(s,c,i(l,c,u))}),s}return Wm=r,Wm}var Vm,kN;function Qb(){if(kN)return Vm;kN=1;var e=Us();function t(n,r,a){for(var i=-1,s=n.length;++i<s;){var l=n[i],c=r(l);if(c!=null&&(u===void 0?c===c&&!e(c):a(c,u)))var u=c,d=l}return d}return Vm=t,Vm}var Gm,_N;function Jq(){if(_N)return Gm;_N=1;function e(t,n){return t>n}return Gm=e,Gm}var Km,wN;function e$(){if(wN)return Km;wN=1;var e=Qb(),t=Jq(),n=Pi();function r(a){return a&&a.length?e(a,n,t):void 0}return Km=r,Km}var Ym,EN;function rA(){if(EN)return Ym;EN=1;var e=nd(),t=Ps();function n(r,a,i){(i!==void 0&&!t(r[a],i)||i===void 0&&!(a in r))&&e(r,a,i)}return Ym=n,Ym}var Qm,NN;function t$(){if(NN)return Qm;NN=1;var e=Li(),t=od(),n=Kr(),r="[object Object]",a=Function.prototype,i=Object.prototype,s=a.toString,l=i.hasOwnProperty,c=s.call(Object);function u(d){if(!n(d)||e(d)!=r)return!1;var f=t(d);if(f===null)return!0;var p=l.call(f,"constructor")&&f.constructor;return typeof p=="function"&&p instanceof p&&s.call(p)==c}return Qm=u,Qm}var Xm,SN;function aA(){if(SN)return Xm;SN=1;function e(t,n){if(!(n==="constructor"&&typeof t[n]=="function")&&n!="__proto__")return t[n]}return Xm=e,Xm}var Zm,CN;function n$(){if(CN)return Zm;CN=1;var e=yl(),t=Di();function n(r){return e(r,t(r))}return Zm=n,Zm}var Jm,jN;function r$(){if(jN)return Jm;jN=1;var e=rA(),t=pT(),n=_T(),r=gT(),a=ET(),i=xl(),s=sn(),l=KT(),c=Bs(),u=ml(),d=yr(),f=t$(),p=bl(),g=aA(),m=n$();function y(v,x,b,k,N,w,_){var T=g(v,b),A=g(x,b),D=_.get(A);if(D){e(v,b,D);return}var R=w?w(T,A,b+"",v,x,_):void 0,$=R===void 0;if($){var F=s(A),G=!F&&c(A),P=!F&&!G&&p(A);R=A,F||G||P?s(T)?R=T:l(T)?R=r(T):G?($=!1,R=t(A,!0)):P?($=!1,R=n(A,!0)):R=[]:f(A)||i(A)?(R=T,i(T)?R=m(T):(!d(T)||u(T))&&(R=a(A))):$=!1}$&&(_.set(A,R),N(R,A,k,w,_),_.delete(A)),e(v,b,R)}return Jm=y,Jm}var e0,TN;function a$(){if(TN)return e0;TN=1;var e=td(),t=rA(),n=Hb(),r=r$(),a=yr(),i=Di(),s=aA();function l(c,u,d,f,p){c!==u&&n(u,function(g,m){if(p||(p=new e),a(g))r(c,u,m,d,l,f,p);else{var y=f?f(s(c,m),g,m+"",c,u,p):void 0;y===void 0&&(y=g),t(c,m,y)}},i)}return e0=l,e0}var t0,AN;function i$(){if(AN)return t0;AN=1;var e=fd(),t=pd();function n(r){return e(function(a,i){var s=-1,l=i.length,c=l>1?i[l-1]:void 0,u=l>2?i[2]:void 0;for(c=r.length>3&&typeof c=="function"?(l--,c):void 0,u&&t(i[0],i[1],u)&&(c=l<3?void 0:c,l=1),a=Object(a);++s<l;){var d=i[s];d&&r(a,d,s,c)}return a})}return t0=n,t0}var n0,RN;function s$(){if(RN)return n0;RN=1;var e=a$(),t=i$(),n=t(function(r,a,i){e(r,a,i)});return n0=n,n0}var r0,MN;function iA(){if(MN)return r0;MN=1;function e(t,n){return t<n}return r0=e,r0}var a0,IN;function o$(){if(IN)return a0;IN=1;var e=Qb(),t=iA(),n=Pi();function r(a){return a&&a.length?e(a,n,t):void 0}return a0=r,a0}var i0,LN;function l$(){if(LN)return i0;LN=1;var e=Qb(),t=xa(),n=iA();function r(a,i){return a&&a.length?e(a,t(i,2),n):void 0}return i0=r,i0}var s0,ON;function c$(){if(ON)return s0;ON=1;var e=Ir(),t=function(){return e.Date.now()};return s0=t,s0}var o0,DN;function u$(){if(DN)return o0;DN=1;var e=rd(),t=ud(),n=ad(),r=yr(),a=vl();function i(s,l,c,u){if(!r(s))return s;l=t(l,s);for(var d=-1,f=l.length,p=f-1,g=s;g!=null&&++d<f;){var m=a(l[d]),y=c;if(m==="__proto__"||m==="constructor"||m==="prototype")return s;if(d!=p){var v=g[m];y=u?u(v,m,g):void 0,y===void 0&&(y=r(v)?v:n(l[d+1])?[]:{})}e(g,m,y),g=g[m]}return s}return o0=i,o0}var l0,PN;function d$(){if(PN)return l0;PN=1;var e=dd(),t=u$(),n=ud();function r(a,i,s){for(var l=-1,c=i.length,u={};++l<c;){var d=i[l],f=e(a,d);s(f,d)&&t(u,n(d,a),f)}return u}return l0=r,l0}var c0,FN;function f$(){if(FN)return c0;FN=1;var e=d$(),t=PT();function n(r,a){return e(r,a,function(i,s){return t(r,s)})}return c0=n,c0}var u0,BN;function p$(){if(BN)return u0;BN=1;var e=nA(),t=WT(),n=VT();function r(a){return n(t(a,void 0,e),a+"")}return u0=r,u0}var d0,zN;function g$(){if(zN)return d0;zN=1;var e=f$(),t=p$(),n=t(function(r,a){return r==null?{}:e(r,a)});return d0=n,d0}var f0,UN;function h$(){if(UN)return f0;UN=1;var e=Math.ceil,t=Math.max;function n(r,a,i,s){for(var l=-1,c=t(e((a-r)/(i||1)),0),u=Array(c);c--;)u[s?c:++l]=r,r+=i;return u}return f0=n,f0}var p0,qN;function m$(){if(qN)return p0;qN=1;var e=h$(),t=pd(),n=tA();function r(a){return function(i,s,l){return l&&typeof l!="number"&&t(i,s,l)&&(s=l=void 0),i=n(i),s===void 0?(s=i,i=0):s=n(s),l=l===void 0?i<s?1:-1:n(l),e(i,s,l,a)}}return p0=r,p0}var g0,$N;function y$(){if($N)return g0;$N=1;var e=m$(),t=e();return g0=t,g0}var h0,HN;function x$(){if(HN)return h0;HN=1;function e(t,n){var r=t.length;for(t.sort(n);r--;)t[r]=t[r].value;return t}return h0=e,h0}var m0,WN;function b$(){if(WN)return m0;WN=1;var e=Us();function t(n,r){if(n!==r){var a=n!==void 0,i=n===null,s=n===n,l=e(n),c=r!==void 0,u=r===null,d=r===r,f=e(r);if(!u&&!f&&!l&&n>r||l&&c&&d&&!u&&!f||i&&c&&d||!a&&d||!s)return 1;if(!i&&!l&&!f&&n<r||f&&a&&s&&!i&&!l||u&&a&&s||!c&&s||!d)return-1}return 0}return m0=t,m0}var y0,VN;function v$(){if(VN)return y0;VN=1;var e=b$();function t(n,r,a){for(var i=-1,s=n.criteria,l=r.criteria,c=s.length,u=a.length;++i<c;){var d=e(s[i],l[i]);if(d){if(i>=u)return d;var f=a[i];return d*(f=="desc"?-1:1)}}return n.index-r.index}return y0=t,y0}var x0,GN;function k$(){if(GN)return x0;GN=1;var e=cd(),t=dd(),n=xa(),r=qT(),a=x$(),i=id(),s=v$(),l=Pi(),c=sn();function u(d,f,p){f.length?f=e(f,function(y){return c(y)?function(v){return t(v,y.length===1?y[0]:y)}:y}):f=[l];var g=-1;f=e(f,i(n));var m=r(d,function(y,v,x){var b=e(f,function(k){return k(y)});return{criteria:b,index:++g,value:y}});return a(m,function(y,v){return s(y,v,p)})}return x0=u,x0}var b0,KN;function _$(){if(KN)return b0;KN=1;var e=Kb(),t=k$(),n=fd(),r=pd(),a=n(function(i,s){if(i==null)return[];var l=s.length;return l>1&&r(i,s[0],s[1])?s=[]:l>2&&r(s[0],s[1],s[2])&&(s=[s[0]]),t(i,e(s,1),[])});return b0=a,b0}var v0,YN;function w$(){if(YN)return v0;YN=1;var e=OT(),t=0;function n(r){var a=++t;return e(r)+a}return v0=n,v0}var k0,QN;function E$(){if(QN)return k0;QN=1;function e(t,n,r){for(var a=-1,i=t.length,s=n.length,l={};++a<i;){var c=a<s?n[a]:void 0;r(l,t[a],c)}return l}return k0=e,k0}var _0,XN;function N$(){if(XN)return _0;XN=1;var e=rd(),t=E$();function n(r,a){return t(r||[],a||[],e)}return _0=n,_0}var vu;if(typeof Ib=="function")try{vu={cloneDeep:Uq(),constant:$b(),defaults:qq(),each:jT(),filter:BT(),find:Yq(),flatten:nA(),forEach:CT(),forIn:Qq(),has:zT(),isUndefined:UT(),last:Xq(),map:$T(),mapValues:Zq(),max:e$(),merge:s$(),min:o$(),minBy:l$(),now:c$(),pick:g$(),range:y$(),reduce:HT(),sortBy:_$(),uniqueId:w$(),values:YT(),zipObject:N$()}}catch{}vu||(vu=window._);var Wt=vu,S$=gd;function gd(){var e={};e._next=e._prev=e,this._sentinel=e}gd.prototype.dequeue=function(){var e=this._sentinel,t=e._prev;if(t!==e)return sA(t),t};gd.prototype.enqueue=function(e){var t=this._sentinel;e._prev&&e._next&&sA(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t};gd.prototype.toString=function(){for(var e=[],t=this._sentinel,n=t._prev;n!==t;)e.push(JSON.stringify(n,C$)),n=n._prev;return"["+e.join(", ")+"]"};function sA(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function C$(e,t){if(e!=="_next"&&e!=="_prev")return t}var sa=Wt,j$=Lr.Graph,T$=S$,A$=M$,R$=sa.constant(1);function M$(e,t){if(e.nodeCount()<=1)return[];var n=L$(e,t||R$),r=I$(n.graph,n.buckets,n.zeroIdx);return sa.flatten(sa.map(r,function(a){return e.outEdges(a.v,a.w)}),!0)}function I$(e,t,n){for(var r=[],a=t[t.length-1],i=t[0],s;e.nodeCount();){for(;s=i.dequeue();)w0(e,t,n,s);for(;s=a.dequeue();)w0(e,t,n,s);if(e.nodeCount()){for(var l=t.length-2;l>0;--l)if(s=t[l].dequeue(),s){r=r.concat(w0(e,t,n,s,!0));break}}}return r}function w0(e,t,n,r,a){var i=a?[]:void 0;return sa.forEach(e.inEdges(r.v),function(s){var l=e.edge(s),c=e.node(s.v);a&&i.push({v:s.v,w:s.w}),c.out-=l,rx(t,n,c)}),sa.forEach(e.outEdges(r.v),function(s){var l=e.edge(s),c=s.w,u=e.node(c);u.in-=l,rx(t,n,u)}),e.removeNode(r.v),i}function L$(e,t){var n=new j$,r=0,a=0;sa.forEach(e.nodes(),function(l){n.setNode(l,{v:l,in:0,out:0})}),sa.forEach(e.edges(),function(l){var c=n.edge(l.v,l.w)||0,u=t(l),d=c+u;n.setEdge(l.v,l.w,d),a=Math.max(a,n.node(l.v).out+=u),r=Math.max(r,n.node(l.w).in+=u)});var i=sa.range(a+r+3).map(function(){return new T$}),s=r+1;return sa.forEach(n.nodes(),function(l){rx(i,s,n.node(l))}),{graph:n,buckets:i,zeroIdx:s}}function rx(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}var yi=Wt,O$=A$,D$={run:P$,undo:B$};function P$(e){var t=e.graph().acyclicer==="greedy"?O$(e,n(e)):F$(e);yi.forEach(t,function(r){var a=e.edge(r);e.removeEdge(r),a.forwardName=r.name,a.reversed=!0,e.setEdge(r.w,r.v,a,yi.uniqueId("rev"))});function n(r){return function(a){return r.edge(a).weight}}}function F$(e){var t=[],n={},r={};function a(i){yi.has(r,i)||(r[i]=!0,n[i]=!0,yi.forEach(e.outEdges(i),function(s){yi.has(n,s.w)?t.push(s):a(s.w)}),delete n[i])}return yi.forEach(e.nodes(),a),t}function B$(e){yi.forEach(e.edges(),function(t){var n=e.edge(t);if(n.reversed){e.removeEdge(t);var r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}var St=Wt,oA=Lr.Graph,Vn={addDummyNode:lA,simplify:z$,asNonCompoundGraph:U$,successorWeights:q$,predecessorWeights:$$,intersectRect:H$,buildLayerMatrix:W$,normalizeRanks:V$,removeEmptyRanks:G$,addBorderNode:K$,maxRank:cA,partition:Y$,time:Q$,notime:X$};function lA(e,t,n,r){var a;do a=St.uniqueId(r);while(e.hasNode(a));return n.dummy=t,e.setNode(a,n),a}function z$(e){var t=new oA().setGraph(e.graph());return St.forEach(e.nodes(),function(n){t.setNode(n,e.node(n))}),St.forEach(e.edges(),function(n){var r=t.edge(n.v,n.w)||{weight:0,minlen:1},a=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+a.weight,minlen:Math.max(r.minlen,a.minlen)})}),t}function U$(e){var t=new oA({multigraph:e.isMultigraph()}).setGraph(e.graph());return St.forEach(e.nodes(),function(n){e.children(n).length||t.setNode(n,e.node(n))}),St.forEach(e.edges(),function(n){t.setEdge(n,e.edge(n))}),t}function q$(e){var t=St.map(e.nodes(),function(n){var r={};return St.forEach(e.outEdges(n),function(a){r[a.w]=(r[a.w]||0)+e.edge(a).weight}),r});return St.zipObject(e.nodes(),t)}function $$(e){var t=St.map(e.nodes(),function(n){var r={};return St.forEach(e.inEdges(n),function(a){r[a.v]=(r[a.v]||0)+e.edge(a).weight}),r});return St.zipObject(e.nodes(),t)}function H$(e,t){var n=e.x,r=e.y,a=t.x-n,i=t.y-r,s=e.width/2,l=e.height/2;if(!a&&!i)throw new Error("Not possible to find intersection inside of the rectangle");var c,u;return Math.abs(i)*s>Math.abs(a)*l?(i<0&&(l=-l),c=l*a/i,u=l):(a<0&&(s=-s),c=s,u=s*i/a),{x:n+c,y:r+u}}function W$(e){var t=St.map(St.range(cA(e)+1),function(){return[]});return St.forEach(e.nodes(),function(n){var r=e.node(n),a=r.rank;St.isUndefined(a)||(t[a][r.order]=n)}),t}function V$(e){var t=St.min(St.map(e.nodes(),function(n){return e.node(n).rank}));St.forEach(e.nodes(),function(n){var r=e.node(n);St.has(r,"rank")&&(r.rank-=t)})}function G$(e){var t=St.min(St.map(e.nodes(),function(i){return e.node(i).rank})),n=[];St.forEach(e.nodes(),function(i){var s=e.node(i).rank-t;n[s]||(n[s]=[]),n[s].push(i)});var r=0,a=e.graph().nodeRankFactor;St.forEach(n,function(i,s){St.isUndefined(i)&&s%a!==0?--r:r&&St.forEach(i,function(l){e.node(l).rank+=r})})}function K$(e,t,n,r){var a={width:0,height:0};return arguments.length>=4&&(a.rank=n,a.order=r),lA(e,"border",a,t)}function cA(e){return St.max(St.map(e.nodes(),function(t){var n=e.node(t).rank;if(!St.isUndefined(n))return n}))}function Y$(e,t){var n={lhs:[],rhs:[]};return St.forEach(e,function(r){t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function Q$(e,t){var n=St.now();try{return t()}finally{console.log(e+" time: "+(St.now()-n)+"ms")}}function X$(e,t){return t()}var uA=Wt,Z$=Vn,J$={run:eH,undo:nH};function eH(e){e.graph().dummyChains=[],uA.forEach(e.edges(),function(t){tH(e,t)})}function tH(e,t){var n=t.v,r=e.node(n).rank,a=t.w,i=e.node(a).rank,s=t.name,l=e.edge(t),c=l.labelRank;if(i!==r+1){e.removeEdge(t);var u,d,f;for(f=0,++r;r<i;++f,++r)l.points=[],d={width:0,height:0,edgeLabel:l,edgeObj:t,rank:r},u=Z$.addDummyNode(e,"edge",d,"_d"),r===c&&(d.width=l.width,d.height=l.height,d.dummy="edge-label",d.labelpos=l.labelpos),e.setEdge(n,u,{weight:l.weight},s),f===0&&e.graph().dummyChains.push(u),n=u;e.setEdge(n,a,{weight:l.weight},s)}}function nH(e){uA.forEach(e.graph().dummyChains,function(t){var n=e.node(t),r=n.edgeLabel,a;for(e.setEdge(n.edgeObj,r);n.dummy;)a=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=a,n=e.node(t)})}var mc=Wt,hd={longestPath:rH,slack:aH};function rH(e){var t={};function n(r){var a=e.node(r);if(mc.has(t,r))return a.rank;t[r]=!0;var i=mc.min(mc.map(e.outEdges(r),function(s){return n(s.w)-e.edge(s).minlen}));return(i===Number.POSITIVE_INFINITY||i===void 0||i===null)&&(i=0),a.rank=i}mc.forEach(e.sources(),n)}function aH(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var ku=Wt,iH=Lr.Graph,_u=hd.slack,dA=sH;function sH(e){var t=new iH({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var a,i;oH(t,e)<r;)a=lH(t,e),i=t.hasNode(a.v)?_u(e,a):-_u(e,a),cH(t,e,i);return t}function oH(e,t){function n(r){ku.forEach(t.nodeEdges(r),function(a){var i=a.v,s=r===i?a.w:i;!e.hasNode(s)&&!_u(t,a)&&(e.setNode(s,{}),e.setEdge(r,s,{}),n(s))})}return ku.forEach(e.nodes(),n),e.nodeCount()}function lH(e,t){return ku.minBy(t.edges(),function(n){if(e.hasNode(n.v)!==e.hasNode(n.w))return _u(t,n)})}function cH(e,t,n){ku.forEach(e.nodes(),function(r){t.node(r).rank+=n})}var ga=Wt,uH=dA,dH=hd.slack,fH=hd.longestPath,pH=Lr.alg.preorder,gH=Lr.alg.postorder,hH=Vn.simplify,mH=Fi;Fi.initLowLimValues=Zb;Fi.initCutValues=Xb;Fi.calcCutValue=fA;Fi.leaveEdge=gA;Fi.enterEdge=hA;Fi.exchangeEdges=mA;function Fi(e){e=hH(e),fH(e);var t=uH(e);Zb(t),Xb(t,e);for(var n,r;n=gA(t);)r=hA(t,e,n),mA(t,e,n,r)}function Xb(e,t){var n=gH(e,e.nodes());n=n.slice(0,n.length-1),ga.forEach(n,function(r){yH(e,t,r)})}function yH(e,t,n){var r=e.node(n),a=r.parent;e.edge(n,a).cutvalue=fA(e,t,n)}function fA(e,t,n){var r=e.node(n),a=r.parent,i=!0,s=t.edge(n,a),l=0;return s||(i=!1,s=t.edge(a,n)),l=s.weight,ga.forEach(t.nodeEdges(n),function(c){var u=c.v===n,d=u?c.w:c.v;if(d!==a){var f=u===i,p=t.edge(c).weight;if(l+=f?p:-p,bH(e,n,d)){var g=e.edge(n,d).cutvalue;l+=f?-g:g}}}),l}function Zb(e,t){arguments.length<2&&(t=e.nodes()[0]),pA(e,{},1,t)}function pA(e,t,n,r,a){var i=n,s=e.node(r);return t[r]=!0,ga.forEach(e.neighbors(r),function(l){ga.has(t,l)||(n=pA(e,t,n,l,r))}),s.low=i,s.lim=n++,a?s.parent=a:delete s.parent,n}function gA(e){return ga.find(e.edges(),function(t){return e.edge(t).cutvalue<0})}function hA(e,t,n){var r=n.v,a=n.w;t.hasEdge(r,a)||(r=n.w,a=n.v);var i=e.node(r),s=e.node(a),l=i,c=!1;i.lim>s.lim&&(l=s,c=!0);var u=ga.filter(t.edges(),function(d){return c===ZN(e,e.node(d.v),l)&&c!==ZN(e,e.node(d.w),l)});return ga.minBy(u,function(d){return dH(t,d)})}function mA(e,t,n,r){var a=n.v,i=n.w;e.removeEdge(a,i),e.setEdge(r.v,r.w,{}),Zb(e),Xb(e,t),xH(e,t)}function xH(e,t){var n=ga.find(e.nodes(),function(a){return!t.node(a).parent}),r=pH(e,n);r=r.slice(1),ga.forEach(r,function(a){var i=e.node(a).parent,s=t.edge(a,i),l=!1;s||(s=t.edge(i,a),l=!0),t.node(a).rank=t.node(i).rank+(l?s.minlen:-s.minlen)})}function bH(e,t,n){return e.hasEdge(t,n)}function ZN(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var vH=hd,yA=vH.longestPath,kH=dA,_H=mH,wH=EH;function EH(e){switch(e.graph().ranker){case"network-simplex":JN(e);break;case"tight-tree":SH(e);break;case"longest-path":NH(e);break;default:JN(e)}}var NH=yA;function SH(e){yA(e),kH(e)}function JN(e){_H(e)}var ax=Wt,CH=jH;function jH(e){var t=AH(e);ax.forEach(e.graph().dummyChains,function(n){for(var r=e.node(n),a=r.edgeObj,i=TH(e,t,a.v,a.w),s=i.path,l=i.lca,c=0,u=s[c],d=!0;n!==a.w;){if(r=e.node(n),d){for(;(u=s[c])!==l&&e.node(u).maxRank<r.rank;)c++;u===l&&(d=!1)}if(!d){for(;c<s.length-1&&e.node(u=s[c+1]).minRank<=r.rank;)c++;u=s[c]}e.setParent(n,u),n=e.successors(n)[0]}})}function TH(e,t,n,r){var a=[],i=[],s=Math.min(t[n].low,t[r].low),l=Math.max(t[n].lim,t[r].lim),c,u;c=n;do c=e.parent(c),a.push(c);while(c&&(t[c].low>s||l>t[c].lim));for(u=c,c=r;(c=e.parent(c))!==u;)i.push(c);return{path:a.concat(i.reverse()),lca:u}}function AH(e){var t={},n=0;function r(a){var i=n;ax.forEach(e.children(a),r),t[a]={low:i,lim:n++}}return ax.forEach(e.children(),r),t}var oa=Wt,ix=Vn,RH={run:MH,cleanup:OH};function MH(e){var t=ix.addDummyNode(e,"root",{},"_root"),n=IH(e),r=oa.max(oa.values(n))-1,a=2*r+1;e.graph().nestingRoot=t,oa.forEach(e.edges(),function(s){e.edge(s).minlen*=a});var i=LH(e)+1;oa.forEach(e.children(),function(s){xA(e,t,a,i,r,n,s)}),e.graph().nodeRankFactor=a}function xA(e,t,n,r,a,i,s){var l=e.children(s);if(!l.length){s!==t&&e.setEdge(t,s,{weight:0,minlen:n});return}var c=ix.addBorderNode(e,"_bt"),u=ix.addBorderNode(e,"_bb"),d=e.node(s);e.setParent(c,s),d.borderTop=c,e.setParent(u,s),d.borderBottom=u,oa.forEach(l,function(f){xA(e,t,n,r,a,i,f);var p=e.node(f),g=p.borderTop?p.borderTop:f,m=p.borderBottom?p.borderBottom:f,y=p.borderTop?r:2*r,v=g!==m?1:a-i[s]+1;e.setEdge(c,g,{weight:y,minlen:v,nestingEdge:!0}),e.setEdge(m,u,{weight:y,minlen:v,nestingEdge:!0})}),e.parent(s)||e.setEdge(t,c,{weight:0,minlen:a+i[s]})}function IH(e){var t={};function n(r,a){var i=e.children(r);i&&i.length&&oa.forEach(i,function(s){n(s,a+1)}),t[r]=a}return oa.forEach(e.children(),function(r){n(r,1)}),t}function LH(e){return oa.reduce(e.edges(),function(t,n){return t+e.edge(n).weight},0)}function OH(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,oa.forEach(e.edges(),function(n){var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}var E0=Wt,DH=Vn,PH=FH;function FH(e){function t(n){var r=e.children(n),a=e.node(n);if(r.length&&E0.forEach(r,t),E0.has(a,"minRank")){a.borderLeft=[],a.borderRight=[];for(var i=a.minRank,s=a.maxRank+1;i<s;++i)eS(e,"borderLeft","_bl",n,a,i),eS(e,"borderRight","_br",n,a,i)}}E0.forEach(e.children(),t)}function eS(e,t,n,r,a,i){var s={width:0,height:0,rank:i,borderType:t},l=a[t][i-1],c=DH.addDummyNode(e,"border",s,n);a[t][i]=c,e.setParent(c,r),l&&e.setEdge(l,c,{weight:1})}var $r=Wt,BH={adjust:zH,undo:UH};function zH(e){var t=e.graph().rankdir.toLowerCase();(t==="lr"||t==="rl")&&bA(e)}function UH(e){var t=e.graph().rankdir.toLowerCase();(t==="bt"||t==="rl")&&qH(e),(t==="lr"||t==="rl")&&($H(e),bA(e))}function bA(e){$r.forEach(e.nodes(),function(t){tS(e.node(t))}),$r.forEach(e.edges(),function(t){tS(e.edge(t))})}function tS(e){var t=e.width;e.width=e.height,e.height=t}function qH(e){$r.forEach(e.nodes(),function(t){N0(e.node(t))}),$r.forEach(e.edges(),function(t){var n=e.edge(t);$r.forEach(n.points,N0),$r.has(n,"y")&&N0(n)})}function N0(e){e.y=-e.y}function $H(e){$r.forEach(e.nodes(),function(t){S0(e.node(t))}),$r.forEach(e.edges(),function(t){var n=e.edge(t);$r.forEach(n.points,S0),$r.has(n,"x")&&S0(n)})}function S0(e){var t=e.x;e.x=e.y,e.y=t}var ta=Wt,HH=WH;function WH(e){var t={},n=ta.filter(e.nodes(),function(l){return!e.children(l).length}),r=ta.max(ta.map(n,function(l){return e.node(l).rank})),a=ta.map(ta.range(r+1),function(){return[]});function i(l){if(!ta.has(t,l)){t[l]=!0;var c=e.node(l);a[c.rank].push(l),ta.forEach(e.successors(l),i)}}var s=ta.sortBy(n,function(l){return e.node(l).rank});return ta.forEach(s,i),a}var Ca=Wt,VH=GH;function GH(e,t){for(var n=0,r=1;r<t.length;++r)n+=KH(e,t[r-1],t[r]);return n}function KH(e,t,n){for(var r=Ca.zipObject(n,Ca.map(n,function(u,d){return d})),a=Ca.flatten(Ca.map(t,function(u){return Ca.sortBy(Ca.map(e.outEdges(u),function(d){return{pos:r[d.w],weight:e.edge(d).weight}}),"pos")}),!0),i=1;i<n.length;)i<<=1;var s=2*i-1;i-=1;var l=Ca.map(new Array(s),function(){return 0}),c=0;return Ca.forEach(a.forEach(function(u){var d=u.pos+i;l[d]+=u.weight;for(var f=0;d>0;)d%2&&(f+=l[d+1]),d=d-1>>1,l[d]+=u.weight;c+=u.weight*f})),c}var nS=Wt,YH=QH;function QH(e,t){return nS.map(t,function(n){var r=e.inEdges(n);if(r.length){var a=nS.reduce(r,function(i,s){var l=e.edge(s),c=e.node(s.v);return{sum:i.sum+l.weight*c.order,weight:i.weight+l.weight}},{sum:0,weight:0});return{v:n,barycenter:a.sum/a.weight,weight:a.weight}}else return{v:n}})}var er=Wt,XH=ZH;function ZH(e,t){var n={};er.forEach(e,function(a,i){var s=n[a.v]={indegree:0,in:[],out:[],vs:[a.v],i};er.isUndefined(a.barycenter)||(s.barycenter=a.barycenter,s.weight=a.weight)}),er.forEach(t.edges(),function(a){var i=n[a.v],s=n[a.w];!er.isUndefined(i)&&!er.isUndefined(s)&&(s.indegree++,i.out.push(n[a.w]))});var r=er.filter(n,function(a){return!a.indegree});return JH(r)}function JH(e){var t=[];function n(i){return function(s){s.merged||(er.isUndefined(s.barycenter)||er.isUndefined(i.barycenter)||s.barycenter>=i.barycenter)&&eW(i,s)}}function r(i){return function(s){s.in.push(i),--s.indegree===0&&e.push(s)}}for(;e.length;){var a=e.pop();t.push(a),er.forEach(a.in.reverse(),n(a)),er.forEach(a.out,r(a))}return er.map(er.filter(t,function(i){return!i.merged}),function(i){return er.pick(i,["vs","i","barycenter","weight"])})}function eW(e,t){var n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}var yo=Wt,tW=Vn,nW=rW;function rW(e,t){var n=tW.partition(e,function(d){return yo.has(d,"barycenter")}),r=n.lhs,a=yo.sortBy(n.rhs,function(d){return-d.i}),i=[],s=0,l=0,c=0;r.sort(aW(!!t)),c=rS(i,a,c),yo.forEach(r,function(d){c+=d.vs.length,i.push(d.vs),s+=d.barycenter*d.weight,l+=d.weight,c=rS(i,a,c)});var u={vs:yo.flatten(i,!0)};return l&&(u.barycenter=s/l,u.weight=l),u}function rS(e,t,n){for(var r;t.length&&(r=yo.last(t)).i<=n;)t.pop(),e.push(r.vs),n++;return n}function aW(e){return function(t,n){return t.barycenter<n.barycenter?-1:t.barycenter>n.barycenter?1:e?n.i-t.i:t.i-n.i}}var La=Wt,iW=YH,sW=XH,oW=nW,lW=vA;function vA(e,t,n,r){var a=e.children(t),i=e.node(t),s=i?i.borderLeft:void 0,l=i?i.borderRight:void 0,c={};s&&(a=La.filter(a,function(m){return m!==s&&m!==l}));var u=iW(e,a);La.forEach(u,function(m){if(e.children(m.v).length){var y=vA(e,m.v,n,r);c[m.v]=y,La.has(y,"barycenter")&&uW(m,y)}});var d=sW(u,n);cW(d,c);var f=oW(d,r);if(s&&(f.vs=La.flatten([s,f.vs,l],!0),e.predecessors(s).length)){var p=e.node(e.predecessors(s)[0]),g=e.node(e.predecessors(l)[0]);La.has(f,"barycenter")||(f.barycenter=0,f.weight=0),f.barycenter=(f.barycenter*f.weight+p.order+g.order)/(f.weight+2),f.weight+=2}return f}function cW(e,t){La.forEach(e,function(n){n.vs=La.flatten(n.vs.map(function(r){return t[r]?t[r].vs:r}),!0)})}function uW(e,t){La.isUndefined(e.barycenter)?(e.barycenter=t.barycenter,e.weight=t.weight):(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight)}var xo=Wt,dW=Lr.Graph,fW=pW;function pW(e,t,n){var r=gW(e),a=new dW({compound:!0}).setGraph({root:r}).setDefaultNodeLabel(function(i){return e.node(i)});return xo.forEach(e.nodes(),function(i){var s=e.node(i),l=e.parent(i);(s.rank===t||s.minRank<=t&&t<=s.maxRank)&&(a.setNode(i),a.setParent(i,l||r),xo.forEach(e[n](i),function(c){var u=c.v===i?c.w:c.v,d=a.edge(u,i),f=xo.isUndefined(d)?0:d.weight;a.setEdge(u,i,{weight:e.edge(c).weight+f})}),xo.has(s,"minRank")&&a.setNode(i,{borderLeft:s.borderLeft[t],borderRight:s.borderRight[t]}))}),a}function gW(e){for(var t;e.hasNode(t=xo.uniqueId("_root")););return t}var hW=Wt,mW=yW;function yW(e,t,n){var r={},a;hW.forEach(n,function(i){for(var s=e.parent(i),l,c;s;){if(l=e.parent(s),l?(c=r[l],r[l]=s):(c=a,a=s),c&&c!==s){t.setEdge(c,s);return}s=l}})}var Ya=Wt,xW=HH,bW=VH,vW=lW,kW=fW,_W=mW,wW=Lr.Graph,aS=Vn,EW=NW;function NW(e){var t=aS.maxRank(e),n=iS(e,Ya.range(1,t+1),"inEdges"),r=iS(e,Ya.range(t-1,-1,-1),"outEdges"),a=xW(e);sS(e,a);for(var i=Number.POSITIVE_INFINITY,s,l=0,c=0;c<4;++l,++c){SW(l%2?n:r,l%4>=2),a=aS.buildLayerMatrix(e);var u=bW(e,a);u<i&&(c=0,s=Ya.cloneDeep(a),i=u)}sS(e,s)}function iS(e,t,n){return Ya.map(t,function(r){return kW(e,r,n)})}function SW(e,t){var n=new wW;Ya.forEach(e,function(r){var a=r.graph().root,i=vW(r,a,n,t);Ya.forEach(i.vs,function(s,l){r.node(s).order=l}),_W(r,n,i.vs)})}function sS(e,t){Ya.forEach(t,function(n){Ya.forEach(n,function(r,a){e.node(r).order=a})})}var ut=Wt,CW=Lr.Graph,jW=Vn,TW={positionX:zW};function AW(e,t){var n={};function r(a,i){var s=0,l=0,c=a.length,u=ut.last(i);return ut.forEach(i,function(d,f){var p=MW(e,d),g=p?e.node(p).order:c;(p||d===u)&&(ut.forEach(i.slice(l,f+1),function(m){ut.forEach(e.predecessors(m),function(y){var v=e.node(y),x=v.order;(x<s||g<x)&&!(v.dummy&&e.node(m).dummy)&&kA(n,y,m)})}),l=f+1,s=g)}),i}return ut.reduce(t,r),n}function RW(e,t){var n={};function r(i,s,l,c,u){var d;ut.forEach(ut.range(s,l),function(f){d=i[f],e.node(d).dummy&&ut.forEach(e.predecessors(d),function(p){var g=e.node(p);g.dummy&&(g.order<c||g.order>u)&&kA(n,p,d)})})}function a(i,s){var l=-1,c,u=0;return ut.forEach(s,function(d,f){if(e.node(d).dummy==="border"){var p=e.predecessors(d);p.length&&(c=e.node(p[0]).order,r(s,u,f,l,c),u=f,l=c)}r(s,u,s.length,c,i.length)}),s}return ut.reduce(t,a),n}function MW(e,t){if(e.node(t).dummy)return ut.find(e.predecessors(t),function(n){return e.node(n).dummy})}function kA(e,t,n){if(t>n){var r=t;t=n,n=r}var a=e[t];a||(e[t]=a={}),a[n]=!0}function IW(e,t,n){if(t>n){var r=t;t=n,n=r}return ut.has(e[t],n)}function LW(e,t,n,r){var a={},i={},s={};return ut.forEach(t,function(l){ut.forEach(l,function(c,u){a[c]=c,i[c]=c,s[c]=u})}),ut.forEach(t,function(l){var c=-1;ut.forEach(l,function(u){var d=r(u);if(d.length){d=ut.sortBy(d,function(y){return s[y]});for(var f=(d.length-1)/2,p=Math.floor(f),g=Math.ceil(f);p<=g;++p){var m=d[p];i[u]===u&&c<s[m]&&!IW(n,u,m)&&(i[m]=u,i[u]=a[u]=a[m],c=s[m])}}})}),{root:a,align:i}}function OW(e,t,n,r,a){var i={},s=DW(e,t,n,a),l=a?"borderLeft":"borderRight";function c(f,p){for(var g=s.nodes(),m=g.pop(),y={};m;)y[m]?f(m):(y[m]=!0,g.push(m),g=g.concat(p(m))),m=g.pop()}function u(f){i[f]=s.inEdges(f).reduce(function(p,g){return Math.max(p,i[g.v]+s.edge(g))},0)}function d(f){var p=s.outEdges(f).reduce(function(m,y){return Math.min(m,i[y.w]-s.edge(y))},Number.POSITIVE_INFINITY),g=e.node(f);p!==Number.POSITIVE_INFINITY&&g.borderType!==l&&(i[f]=Math.max(i[f],p))}return c(u,s.predecessors.bind(s)),c(d,s.successors.bind(s)),ut.forEach(r,function(f){i[f]=i[n[f]]}),i}function DW(e,t,n,r){var a=new CW,i=e.graph(),s=UW(i.nodesep,i.edgesep,r);return ut.forEach(t,function(l){var c;ut.forEach(l,function(u){var d=n[u];if(a.setNode(d),c){var f=n[c],p=a.edge(f,d);a.setEdge(f,d,Math.max(s(e,u,c),p||0))}c=u})}),a}function PW(e,t){return ut.minBy(ut.values(t),function(n){var r=Number.NEGATIVE_INFINITY,a=Number.POSITIVE_INFINITY;return ut.forIn(n,function(i,s){var l=qW(e,s)/2;r=Math.max(i+l,r),a=Math.min(i-l,a)}),r-a})}function FW(e,t){var n=ut.values(t),r=ut.min(n),a=ut.max(n);ut.forEach(["u","d"],function(i){ut.forEach(["l","r"],function(s){var l=i+s,c=e[l],u;if(c!==t){var d=ut.values(c);u=s==="l"?r-ut.min(d):a-ut.max(d),u&&(e[l]=ut.mapValues(c,function(f){return f+u}))}})})}function BW(e,t){return ut.mapValues(e.ul,function(n,r){if(t)return e[t.toLowerCase()][r];var a=ut.sortBy(ut.map(e,r));return(a[1]+a[2])/2})}function zW(e){var t=jW.buildLayerMatrix(e),n=ut.merge(AW(e,t),RW(e,t)),r={},a;ut.forEach(["u","d"],function(s){a=s==="u"?t:ut.values(t).reverse(),ut.forEach(["l","r"],function(l){l==="r"&&(a=ut.map(a,function(f){return ut.values(f).reverse()}));var c=(s==="u"?e.predecessors:e.successors).bind(e),u=LW(e,a,n,c),d=OW(e,a,u.root,u.align,l==="r");l==="r"&&(d=ut.mapValues(d,function(f){return-f})),r[s+l]=d})});var i=PW(e,r);return FW(r,i),BW(r,e.graph().align)}function UW(e,t,n){return function(r,a,i){var s=r.node(a),l=r.node(i),c=0,u;if(c+=s.width/2,ut.has(s,"labelpos"))switch(s.labelpos.toLowerCase()){case"l":u=-s.width/2;break;case"r":u=s.width/2;break}if(u&&(c+=n?u:-u),u=0,c+=(s.dummy?t:e)/2,c+=(l.dummy?t:e)/2,c+=l.width/2,ut.has(l,"labelpos"))switch(l.labelpos.toLowerCase()){case"l":u=l.width/2;break;case"r":u=-l.width/2;break}return u&&(c+=n?u:-u),u=0,c}}function qW(e,t){return e.node(t).width}var bo=Wt,_A=Vn,$W=TW.positionX,HW=WW;function WW(e){e=_A.asNonCompoundGraph(e),VW(e),bo.forEach($W(e),function(t,n){e.node(n).x=t})}function VW(e){var t=_A.buildLayerMatrix(e),n=e.graph().ranksep,r=0;bo.forEach(t,function(a){var i=bo.max(bo.map(a,function(s){return e.node(s).height}));bo.forEach(a,function(s){e.node(s).y=r+i/2}),r+=i+n})}var ht=Wt,oS=D$,lS=J$,GW=wH,KW=Vn.normalizeRanks,YW=CH,QW=Vn.removeEmptyRanks,cS=RH,XW=PH,uS=BH,ZW=EW,JW=HW,Za=Vn,eV=Lr.Graph,tV=nV;function nV(e,t){var n=t&&t.debugTiming?Za.time:Za.notime;n("layout",function(){var r=n(" buildLayoutGraph",function(){return pV(e)});n(" runLayout",function(){rV(r,n)}),n(" updateInputGraph",function(){aV(e,r)})})}function rV(e,t){t(" makeSpaceForEdgeLabels",function(){gV(e)}),t(" removeSelfEdges",function(){wV(e)}),t(" acyclic",function(){oS.run(e)}),t(" nestingGraph.run",function(){cS.run(e)}),t(" rank",function(){GW(Za.asNonCompoundGraph(e))}),t(" injectEdgeLabelProxies",function(){hV(e)}),t(" removeEmptyRanks",function(){QW(e)}),t(" nestingGraph.cleanup",function(){cS.cleanup(e)}),t(" normalizeRanks",function(){KW(e)}),t(" assignRankMinMax",function(){mV(e)}),t(" removeEdgeLabelProxies",function(){yV(e)}),t(" normalize.run",function(){lS.run(e)}),t(" parentDummyChains",function(){YW(e)}),t(" addBorderSegments",function(){XW(e)}),t(" order",function(){ZW(e)}),t(" insertSelfEdges",function(){EV(e)}),t(" adjustCoordinateSystem",function(){uS.adjust(e)}),t(" position",function(){JW(e)}),t(" positionSelfEdges",function(){NV(e)}),t(" removeBorderNodes",function(){_V(e)}),t(" normalize.undo",function(){lS.undo(e)}),t(" fixupEdgeLabelCoords",function(){vV(e)}),t(" undoCoordinateSystem",function(){uS.undo(e)}),t(" translateGraph",function(){xV(e)}),t(" assignNodeIntersects",function(){bV(e)}),t(" reversePoints",function(){kV(e)}),t(" acyclic.undo",function(){oS.undo(e)})}function aV(e,t){ht.forEach(e.nodes(),function(n){var r=e.node(n),a=t.node(n);r&&(r.x=a.x,r.y=a.y,t.children(n).length&&(r.width=a.width,r.height=a.height))}),ht.forEach(e.edges(),function(n){var r=e.edge(n),a=t.edge(n);r.points=a.points,ht.has(a,"x")&&(r.x=a.x,r.y=a.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var iV=["nodesep","edgesep","ranksep","marginx","marginy"],sV={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},oV=["acyclicer","ranker","rankdir","align"],lV=["width","height"],cV={width:0,height:0},uV=["minlen","weight","width","height","labeloffset"],dV={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},fV=["labelpos"];function pV(e){var t=new eV({multigraph:!0,compound:!0}),n=j0(e.graph());return t.setGraph(ht.merge({},sV,C0(n,iV),ht.pick(n,oV))),ht.forEach(e.nodes(),function(r){var a=j0(e.node(r));t.setNode(r,ht.defaults(C0(a,lV),cV)),t.setParent(r,e.parent(r))}),ht.forEach(e.edges(),function(r){var a=j0(e.edge(r));t.setEdge(r,ht.merge({},dV,C0(a,uV),ht.pick(a,fV)))}),t}function gV(e){var t=e.graph();t.ranksep/=2,ht.forEach(e.edges(),function(n){var r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function hV(e){ht.forEach(e.edges(),function(t){var n=e.edge(t);if(n.width&&n.height){var r=e.node(t.v),a=e.node(t.w),i={rank:(a.rank-r.rank)/2+r.rank,e:t};Za.addDummyNode(e,"edge-proxy",i,"_ep")}})}function mV(e){var t=0;ht.forEach(e.nodes(),function(n){var r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=ht.max(t,r.maxRank))}),e.graph().maxRank=t}function yV(e){ht.forEach(e.nodes(),function(t){var n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function xV(e){var t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,a=0,i=e.graph(),s=i.marginx||0,l=i.marginy||0;function c(u){var d=u.x,f=u.y,p=u.width,g=u.height;t=Math.min(t,d-p/2),n=Math.max(n,d+p/2),r=Math.min(r,f-g/2),a=Math.max(a,f+g/2)}ht.forEach(e.nodes(),function(u){c(e.node(u))}),ht.forEach(e.edges(),function(u){var d=e.edge(u);ht.has(d,"x")&&c(d)}),t-=s,r-=l,ht.forEach(e.nodes(),function(u){var d=e.node(u);d.x-=t,d.y-=r}),ht.forEach(e.edges(),function(u){var d=e.edge(u);ht.forEach(d.points,function(f){f.x-=t,f.y-=r}),ht.has(d,"x")&&(d.x-=t),ht.has(d,"y")&&(d.y-=r)}),i.width=n-t+s,i.height=a-r+l}function bV(e){ht.forEach(e.edges(),function(t){var n=e.edge(t),r=e.node(t.v),a=e.node(t.w),i,s;n.points?(i=n.points[0],s=n.points[n.points.length-1]):(n.points=[],i=a,s=r),n.points.unshift(Za.intersectRect(r,i)),n.points.push(Za.intersectRect(a,s))})}function vV(e){ht.forEach(e.edges(),function(t){var n=e.edge(t);if(ht.has(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function kV(e){ht.forEach(e.edges(),function(t){var n=e.edge(t);n.reversed&&n.points.reverse()})}function _V(e){ht.forEach(e.nodes(),function(t){if(e.children(t).length){var n=e.node(t),r=e.node(n.borderTop),a=e.node(n.borderBottom),i=e.node(ht.last(n.borderLeft)),s=e.node(ht.last(n.borderRight));n.width=Math.abs(s.x-i.x),n.height=Math.abs(a.y-r.y),n.x=i.x+n.width/2,n.y=r.y+n.height/2}}),ht.forEach(e.nodes(),function(t){e.node(t).dummy==="border"&&e.removeNode(t)})}function wV(e){ht.forEach(e.edges(),function(t){if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function EV(e){var t=Za.buildLayerMatrix(e);ht.forEach(t,function(n){var r=0;ht.forEach(n,function(a,i){var s=e.node(a);s.order=i+r,ht.forEach(s.selfEdges,function(l){Za.addDummyNode(e,"selfedge",{width:l.label.width,height:l.label.height,rank:s.rank,order:i+ ++r,e:l.e,label:l.label},"_se")}),delete s.selfEdges})})}function NV(e){ht.forEach(e.nodes(),function(t){var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),a=r.x+r.width/2,i=r.y,s=n.x-a,l=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:a+2*s/3,y:i-l},{x:a+5*s/6,y:i-l},{x:a+s,y:i},{x:a+5*s/6,y:i+l},{x:a+2*s/3,y:i+l}],n.label.x=n.x,n.label.y=n.y}})}function C0(e,t){return ht.mapValues(ht.pick(e,t),Number)}function j0(e){var t={};return ht.forEach(e,function(n,r){t[r.toLowerCase()]=n}),t}var yc=Wt,SV=Vn,CV=Lr.Graph,jV={debugOrdering:TV};function TV(e){var t=SV.buildLayerMatrix(e),n=new CV({compound:!0,multigraph:!0}).setGraph({});return yc.forEach(e.nodes(),function(r){n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),yc.forEach(e.edges(),function(r){n.setEdge(r.v,r.w,{},r.name)}),yc.forEach(t,function(r,a){var i="layer"+a;n.setNode(i,{rank:"same"}),yc.reduce(r,function(s,l){return n.setEdge(s,l,{style:"invis"}),l})}),n}var AV="0.8.5",RV={graphlib:Lr,layout:tV,debug:jV,util:{time:Vn.time,notime:Vn.notime},version:AV};const wu=il(RV),MV={completed:{fill:"#dcfce7",stroke:"#16a34a",label:"#15803d"},in_progress:{fill:"#dbeafe",stroke:"#3b82f6",label:"#1d4ed8"},blocked:{fill:"#fef3c7",stroke:"#f59e0b",label:"#b45309"},open:{fill:"#f1f5f9",stroke:"#94a3b8",label:"#475569"}},IV={completed:{fill:"#14532d",stroke:"#22c55e",label:"#86efac"},in_progress:{fill:"#1e3a8a",stroke:"#60a5fa",label:"#bfdbfe"},blocked:{fill:"#78350f",stroke:"#fbbf24",label:"#fde68a"},open:{fill:"#1e293b",stroke:"#64748b",label:"#cbd5e1"}};function LV(e,t){return e?e.length<=t?e:e.slice(0,t-1)+"…":""}function dS(e){return e.status==="completed"?"completed":e.status==="in_progress"?"in_progress":e.blockedBy&&e.blockedBy.length>0&&e.isBlocked?"blocked":"open"}function OV({todos:e,darkMode:t}){const n=Array.isArray(e)?e:[],[r,a]=h.useState(null),i=h.useRef(null),s=h.useRef(null),[l,c]=h.useState(400),[u,d]=h.useState(function(){if(typeof window<"u"){const F=parseFloat(localStorage.getItem("pave-map-zoom")||"");if(Number.isFinite(F)&&F>.1)return F}return 1});h.useEffect(function(){typeof window<"u"&&localStorage.setItem("pave-map-zoom",String(u))},[u]);const[f,p]=h.useState(function(){return typeof window<"u"?localStorage.getItem("pave-map-show-completed")!=="false":!0});h.useEffect(function(){typeof window<"u"&&localStorage.setItem("pave-map-show-completed",f?"true":"false")},[f]);const[g,m]=h.useState(function(){if(typeof window<"u"){const F=localStorage.getItem("pave-map-rankdir");if(F==="LR"||F==="TB")return F}return"TB"});h.useEffect(function(){typeof window<"u"&&localStorage.setItem("pave-map-rankdir",g)},[g]);const y=h.useMemo(function(){if(f)return n;const F=n.filter(function(P){return P.status!=="completed"}),G={};return F.forEach(function(P){G[P.id]=!0}),F.map(function(P){if(!P.blockedBy||!P.blockedBy.length)return P;const M=P.blockedBy.filter(function(S){return G[S]});return M.length===P.blockedBy.length?P:Object.assign({},P,{blockedBy:M})})},[n,f]);h.useEffect(function(){if(!i.current)return;function F(){i.current&&c(i.current.clientWidth||400)}F();const G=new ResizeObserver(F);return G.observe(i.current),function(){G.disconnect()}},[]);const v=h.useMemo(function(){if(!y.length)return{nodes:[],edges:[],width:0,height:0};const F=new wu.graphlib.Graph;F.setGraph({rankdir:g,nodesep:24,ranksep:36,marginx:16,marginy:16}),F.setDefaultEdgeLabel(function(){return{}});const G=180,P=56;y.forEach(function(I){F.setNode(String(I.id),{width:G,height:P,todo:I})}),y.forEach(function(I){(I.blockedBy||[]).forEach(function(Q){F.hasNode(String(Q))&&F.setEdge(String(Q),String(I.id))})}),wu.layout(F);const M=F.nodes().map(function(I){const B=F.node(I);return{id:I,x:B.x-G/2,y:B.y-P/2,w:G,h:P,todo:B.todo}}),S=F.edges().map(function(I){const B=F.edge(I);return{from:I.v,to:I.w,points:B.points}});return{nodes:M,edges:S,width:F.graph().width||G+32,height:F.graph().height||P+32}},[y,g]),x=t?IV:MV;if(!y.length){const F=n.length-y.length;return o.jsxs("div",{ref:i,className:"flex flex-col items-center justify-center h-full text-center px-6",children:[o.jsx("div",{className:"text-gray-400 dark:text-gray-500 mb-2",children:o.jsx("svg",{className:"w-12 h-12 mx-auto opacity-50",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"})})}),F>0?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"text-sm font-medium text-gray-600 dark:text-gray-300",children:"All work complete"}),o.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1 max-w-xs",children:[F," completed ",F===1?"todo is":"todos are"," hidden."]}),o.jsx("button",{type:"button",onClick:function(){p(!0)},className:"mt-3 text-xs px-3 py-1 rounded border border-gray-300 dark:border-gray-600 text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800",children:"Show completed"})]}):o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"text-sm font-medium text-gray-600 dark:text-gray-300",children:"Strategy map is empty"}),o.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1 max-w-xs",children:["Ask the agent to plan the work — todos created with the ",o.jsx("code",{className:"px-1 bg-gray-200 dark:bg-gray-700 rounded",children:"todo"})," tool will appear here as a live DAG."]})]})]})}function b(F){if(!F||F.length<2)return"";let G="M "+F[0].x+" "+F[0].y;for(let P=1;P<F.length;P++)G+=" L "+F[P].x+" "+F[P].y;return G}const k=n.reduce(function(F,G){const P=dS(G);return F[P]=(F[P]||0)+1,F},{}),N=k.completed||0,w=Math.max(v.width,100),_=Math.max(v.height,100),A=(w>l-24?1:(l-24)/w)*u,D=w*A,R=_*A;function $(F){(F.ctrlKey||F.metaKey)&&(F.preventDefault(),d(function(G){const P=F.deltaY<0?G*1.1:G/1.1;return Math.max(.25,Math.min(4,P))}))}return o.jsxs("div",{ref:i,className:"h-full flex flex-col bg-white dark:bg-gray-900",children:[o.jsxs("div",{className:"flex items-center justify-between px-3 pt-3 pb-2 text-xs flex-shrink-0",children:[o.jsx("div",{className:"font-semibold text-gray-700 dark:text-gray-200",children:"Strategy Map"}),o.jsxs("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[o.jsxs("span",{children:[n.length," total"]}),k.in_progress?o.jsxs("span",{className:"text-blue-600 dark:text-blue-400",children:[k.in_progress," active"]}):null,N?o.jsxs("span",{className:"text-green-600 dark:text-green-400",children:[N," done"]}):null,k.blocked?o.jsxs("span",{className:"text-amber-600 dark:text-amber-400",children:[k.blocked," blocked"]}):null,o.jsxs("div",{className:"flex items-center gap-0.5 ml-1 border-l border-gray-200 dark:border-gray-700 pl-2",children:[o.jsx("button",{type:"button",onClick:function(){m(function(F){return F==="TB"?"LR":"TB"})},className:"px-1.5 py-0.5 rounded text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 text-[10px]",title:g==="TB"?"Switch to horizontal layout":"Switch to vertical layout","aria-label":"Toggle layout direction",children:g==="TB"?"↓":"→"}),o.jsx("button",{type:"button",onClick:function(){d(function(F){return Math.max(.25,F/1.25)})},className:"px-1.5 py-0.5 rounded text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800",title:"Zoom out","aria-label":"Zoom out",children:"−"}),o.jsxs("button",{type:"button",onClick:function(){d(1)},className:"px-1.5 py-0.5 rounded text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 text-[10px] tabular-nums min-w-[3em]",title:"Reset zoom","aria-label":"Reset zoom",children:[Math.round(u*100),"%"]}),o.jsx("button",{type:"button",onClick:function(){d(function(F){return Math.min(4,F*1.25)})},className:"px-1.5 py-0.5 rounded text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800",title:"Zoom in","aria-label":"Zoom in",children:"+"})]}),N>0?o.jsx("button",{type:"button",onClick:function(){p(function(F){return!F})},className:"ml-1 px-2 py-0.5 rounded border text-[10px] "+(f?"border-blue-400 text-blue-600 dark:text-blue-400 bg-blue-50 dark:bg-blue-900/30":"border-gray-300 dark:border-gray-600 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800"),title:f?"Hide completed todos":"Show completed todos",children:f?"hide done":"show done"}):null]})]}),o.jsx("div",{ref:s,className:"flex-1 min-h-0 overflow-auto px-3 pb-3",onWheel:$,children:o.jsxs("svg",{viewBox:"0 0 "+w+" "+_,width:D,height:R,style:{display:"block"},children:[o.jsx("defs",{children:o.jsx("marker",{id:"sm-arrow",viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"5",markerHeight:"5",orient:"auto",children:o.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:t?"#64748b":"#94a3b8"})})}),v.edges.map(function(F,G){return o.jsx("path",{d:b(F.points),fill:"none",stroke:t?"#475569":"#cbd5e1",strokeWidth:1.5,markerEnd:"url(#sm-arrow)"},"e"+G)}),v.nodes.map(function(F){const G=dS(F.todo),P=x[G],M=G==="in_progress",S=r===F.id;return o.jsxs("g",{transform:"translate("+F.x+","+F.y+")",onMouseEnter:function(){a(F.id)},onMouseLeave:function(){a(null)},style:{cursor:"pointer"},children:[o.jsx("rect",{width:F.w,height:F.h,rx:6,ry:6,fill:P.fill,stroke:P.stroke,strokeWidth:M||S?2:1.25,children:M?o.jsx("animate",{attributeName:"stroke-width",values:"1.5;2.5;1.5",dur:"1.6s",repeatCount:"indefinite"}):null}),M?o.jsx("circle",{cx:10,cy:10,r:3.5,fill:P.stroke,children:o.jsx("animate",{attributeName:"r",values:"3;5;3",dur:"1.4s",repeatCount:"indefinite"})}):null,o.jsx("text",{x:F.w/2,y:F.h/2-6,textAnchor:"middle",fontSize:11,fontWeight:600,fill:P.label,children:"#"+F.todo.id}),o.jsx("text",{x:F.w/2,y:F.h/2+12,textAnchor:"middle",fontSize:11,fill:t?"#e2e8f0":"#0f172a",children:LV(F.todo.text,26)}),S&&F.todo.text&&F.todo.text.length>26?o.jsx("title",{children:F.todo.text}):null]},F.id)})]})})]})}const DV={bash:{fill:"#f1f5f9",stroke:"#64748b",label:"#334155"},read:{fill:"#dbeafe",stroke:"#3b82f6",label:"#1d4ed8"},Read:{fill:"#dbeafe",stroke:"#3b82f6",label:"#1d4ed8"},edit:{fill:"#dcfce7",stroke:"#16a34a",label:"#15803d"},Edit:{fill:"#dcfce7",stroke:"#16a34a",label:"#15803d"},write:{fill:"#dcfce7",stroke:"#15803d",label:"#14532d"},Write:{fill:"#dcfce7",stroke:"#15803d",label:"#14532d"},glob:{fill:"#ede9fe",stroke:"#8b5cf6",label:"#6d28d9"},grep:{fill:"#ede9fe",stroke:"#8b5cf6",label:"#6d28d9"},fetch:{fill:"#fce7f3",stroke:"#db2777",label:"#9d174d"},canvas:{fill:"#fef3c7",stroke:"#f59e0b",label:"#b45309"},todo:{fill:"#e0f2fe",stroke:"#0ea5e9",label:"#0369a1"}},PV={fill:"#f1f5f9",stroke:"#94a3b8",label:"#475569"},FV={fill:"#fee2e2",stroke:"#dc2626",label:"#991b1b"},BV={bash:{fill:"#1e293b",stroke:"#94a3b8",label:"#e2e8f0"},read:{fill:"#1e3a8a",stroke:"#60a5fa",label:"#bfdbfe"},Read:{fill:"#1e3a8a",stroke:"#60a5fa",label:"#bfdbfe"},edit:{fill:"#14532d",stroke:"#22c55e",label:"#86efac"},Edit:{fill:"#14532d",stroke:"#22c55e",label:"#86efac"},write:{fill:"#14532d",stroke:"#16a34a",label:"#bbf7d0"},Write:{fill:"#14532d",stroke:"#16a34a",label:"#bbf7d0"},glob:{fill:"#4c1d95",stroke:"#a78bfa",label:"#ddd6fe"},grep:{fill:"#4c1d95",stroke:"#a78bfa",label:"#ddd6fe"},fetch:{fill:"#831843",stroke:"#f472b6",label:"#fbcfe8"},canvas:{fill:"#78350f",stroke:"#fbbf24",label:"#fde68a"},todo:{fill:"#0c4a6e",stroke:"#38bdf8",label:"#bae6fd"}},zV={fill:"#1e293b",stroke:"#64748b",label:"#cbd5e1"},UV={fill:"#7f1d1d",stroke:"#f87171",label:"#fecaca"},qV={fill:"#fef9c3",stroke:"#ca8a04",label:"#713f12"},$V={fill:"#3f2d0a",stroke:"#facc15",label:"#fde68a"},ja={data:{light:"#0ea5e9",dark:"#38bdf8"},file:{light:"#94a3b8",dark:"#64748b"},seq:{light:"#cbd5e1",dark:"#475569"}};function HV(e,t){return e?e.length<=t?e:e.slice(0,t-1)+"…":""}function WV(e,t){return e.kind==="thought"?t?$V:qV:e.status==="error"?t?UV:FV:(t?BV:DV)[e.tool]||(t?zV:PV)}function VV({graph:e,darkMode:t,onNodeClick:n}){const r=e&&Array.isArray(e.nodes)?e.nodes:[],a=e&&Array.isArray(e.edges)?e.edges:[],i=h.useRef(null),s=h.useRef(null),[l,c]=h.useState(null),[u,d]=h.useState(400),[f,p]=h.useState(function(){if(typeof window<"u"){const M=parseFloat(localStorage.getItem("pave-toolmap-zoom")||"");if(Number.isFinite(M)&&M>.1)return M}return 1});h.useEffect(function(){typeof window<"u"&&localStorage.setItem("pave-toolmap-zoom",String(f))},[f]);const[g,m]=h.useState(function(){if(typeof window<"u"){const M=localStorage.getItem("pave-toolmap-rankdir");if(M==="LR"||M==="TB")return M}return"TB"});h.useEffect(function(){typeof window<"u"&&localStorage.setItem("pave-toolmap-rankdir",g)},[g]);const[y,v]=h.useState(function(){return typeof window<"u"?localStorage.getItem("pave-toolmap-show-hidden")==="true":!1});h.useEffect(function(){typeof window<"u"&&localStorage.setItem("pave-toolmap-show-hidden",y?"true":"false")},[y]);const[x,b]=h.useState(function(){return!(typeof window<"u"&&localStorage.getItem("pave-toolmap-show-thoughts")==="false")});h.useEffect(function(){typeof window<"u"&&localStorage.setItem("pave-toolmap-show-thoughts",x?"true":"false")},[x]);const k=h.useMemo(function(){let M=r;return y||(M=M.filter(function(S){return!S.hidden})),x||(M=M.filter(function(S){return S.kind!=="thought"})),M},[r,y,x]),N=h.useMemo(function(){const M={};return k.forEach(function(S){M[S.id]=!0}),a.filter(function(S){return M[S.from]&&M[S.to]})},[a,k]),w=h.useMemo(function(){if(!k.length)return{nodes:[],edges:[],width:0,height:0};const M=new wu.graphlib.Graph;M.setGraph({rankdir:g,nodesep:18,ranksep:32,marginx:14,marginy:14}),M.setDefaultEdgeLabel(function(){return{}});const S=168,I=44,B=240,Q=60;k.forEach(function(W){W.kind==="thought"?M.setNode(W.id,{width:B,height:Q,node:W}):M.setNode(W.id,{width:S,height:I,node:W})}),N.forEach(function(W){M.hasNode(W.from)&&M.hasNode(W.to)&&M.setEdge(W.from,W.to,{kind:W.kind})}),wu.layout(M);const C=M.nodes().map(function(W){const j=M.node(W);return{id:W,x:j.x-j.width/2,y:j.y-j.height/2,w:j.width,h:j.height,node:j.node}}),K=M.edges().map(function(W){const j=M.edge(W);return{from:W.v,to:W.w,points:j.points||[],kind:j.kind||"seq"}});return{nodes:C,edges:K,width:M.graph().width||S+28,height:M.graph().height||I+28}},[k,N,g]);h.useEffect(function(){if(!i.current)return;function M(){i.current&&d(i.current.clientWidth||400)}M();const S=new ResizeObserver(M);return S.observe(i.current),function(){S.disconnect()}},[]);const _=h.useMemo(function(){const M={total:0,ok:0,error:0,running:0,hidden:0,thoughts:0};return r.forEach(function(S){if(S.kind==="thought"){M.thoughts++;return}M.total++,S.hidden&&M.hidden++,S.status==="error"?M.error++:S.status==="running"?M.running++:M.ok++}),M},[r]);if(!k.length)return o.jsxs("div",{ref:i,className:"flex flex-col items-center justify-center h-full text-center px-6",children:[o.jsx("div",{className:"text-gray-400 dark:text-gray-500 mb-2",children:o.jsx("svg",{className:"w-12 h-12 mx-auto opacity-50",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})})}),o.jsx("div",{className:"text-sm font-medium text-gray-600 dark:text-gray-300",children:"No tool calls yet"}),o.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1 max-w-xs",children:"Tool invocations will appear here as a DAG showing data flow and file dependencies."}),_.hidden>0&&!y?o.jsxs("button",{type:"button",onClick:function(){v(!0)},className:"mt-3 text-xs px-3 py-1 rounded border border-gray-300 dark:border-gray-600 text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800",children:["Show ",_.hidden," hidden"]}):null]});function T(M){if(!M||M.length<2)return"";let S="M "+M[0].x+" "+M[0].y;for(let I=1;I<M.length;I++)S+=" L "+M[I].x+" "+M[I].y;return S}const A=Math.max(w.width,100),D=Math.max(w.height,100),$=(A>u-24?1:(u-24)/A)*f,F=A*$,G=D*$;function P(M){(M.ctrlKey||M.metaKey)&&(M.preventDefault(),p(function(S){const I=M.deltaY<0?S*1.1:S/1.1;return Math.max(.25,Math.min(4,I))}))}return o.jsxs("div",{ref:i,className:"h-full flex flex-col bg-white dark:bg-gray-900",children:[o.jsxs("div",{className:"flex items-center justify-between px-3 pt-3 pb-2 text-xs flex-shrink-0",children:[o.jsx("div",{className:"font-semibold text-gray-700 dark:text-gray-200",children:"Tool Calls"}),o.jsxs("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[o.jsxs("span",{children:[_.total," tools"]}),_.running?o.jsxs("span",{className:"text-blue-600 dark:text-blue-400",children:[_.running," live"]}):null,_.error?o.jsxs("span",{className:"text-red-600 dark:text-red-400",children:[_.error," err"]}):null,o.jsxs("div",{className:"flex items-center gap-0.5 ml-1 border-l border-gray-200 dark:border-gray-700 pl-2",children:[o.jsx("button",{type:"button",onClick:function(){m(function(M){return M==="TB"?"LR":"TB"})},className:"px-1.5 py-0.5 rounded text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 text-[10px]",title:g==="TB"?"Switch to horizontal layout":"Switch to vertical layout","aria-label":"Toggle layout direction",children:g==="TB"?"↓":"→"}),o.jsx("button",{type:"button",onClick:function(){p(function(M){return Math.max(.25,M/1.25)})},className:"px-1.5 py-0.5 rounded text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800",title:"Zoom out","aria-label":"Zoom out",children:"−"}),o.jsxs("button",{type:"button",onClick:function(){p(1)},className:"px-1.5 py-0.5 rounded text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 text-[10px] tabular-nums min-w-[3em]",title:"Reset zoom","aria-label":"Reset zoom",children:[Math.round(f*100),"%"]}),o.jsx("button",{type:"button",onClick:function(){p(function(M){return Math.min(4,M*1.25)})},className:"px-1.5 py-0.5 rounded text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800",title:"Zoom in","aria-label":"Zoom in",children:"+"})]}),_.hidden>0?o.jsx("button",{type:"button",onClick:function(){v(function(M){return!M})},className:"ml-1 px-2 py-0.5 rounded border text-[10px] "+(y?"border-blue-400 text-blue-600 dark:text-blue-400 bg-blue-50 dark:bg-blue-900/30":"border-gray-300 dark:border-gray-600 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800"),title:y?"Hide bookkeeping tools":"Show bookkeeping tools (todo, permission, etc.)",children:y?"hide bk":"show bk"}):null,_.thoughts>0?o.jsx("button",{type:"button",onClick:function(){b(function(M){return!M})},className:"ml-1 px-2 py-0.5 rounded border text-[10px] "+(x?"border-yellow-500 text-yellow-700 dark:text-yellow-300 bg-yellow-50 dark:bg-yellow-900/30":"border-gray-300 dark:border-gray-600 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800"),title:x?"Hide reasoning bubbles":"Show reasoning bubbles ("+_.thoughts+" thoughts)",children:x?"💭 "+_.thoughts:"💭 off"}):null]})]}),o.jsx("div",{ref:s,className:"flex-1 min-h-0 overflow-auto px-3 pb-3",onWheel:P,children:o.jsxs("svg",{viewBox:"0 0 "+A+" "+D,width:F,height:G,style:{display:"block"},children:[o.jsxs("defs",{children:[o.jsx("marker",{id:"tcm-arrow-data",viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"5",markerHeight:"5",orient:"auto",children:o.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:t?ja.data.dark:ja.data.light})}),o.jsx("marker",{id:"tcm-arrow-file",viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"5",markerHeight:"5",orient:"auto",children:o.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:t?ja.file.dark:ja.file.light})}),o.jsx("marker",{id:"tcm-arrow-seq",viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"5",markerHeight:"5",orient:"auto",children:o.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:t?ja.seq.dark:ja.seq.light})})]}),w.edges.map(function(M,S){const I=t?ja[M.kind].dark:ja[M.kind].light;return o.jsx("path",{d:T(M.points),fill:"none",stroke:I,strokeWidth:M.kind==="data"?1.75:M.kind==="file"?1.25:1,strokeDasharray:M.kind==="seq"?"3,3":void 0,markerEnd:"url(#tcm-arrow-"+M.kind+")"},"e"+S)}),w.nodes.map(function(M){const S=M.node,I=WV(S,t),B=S.status==="running",Q=l===M.id;if(S.kind==="thought"){const K=S.label||"",W=32,j=3,U=K.split(/\s+/),le=[];let Z="";for(const ke of U){if(le.length===j-1&&(Z+" "+ke).length>W){le.push(Z);const re=U.slice(U.indexOf(ke)).join(" ");le.push(re.length>W?re.slice(0,W-1)+"…":re),Z="";break}if(!Z){Z=ke;continue}if((Z+" "+ke).length<=W?Z=Z+" "+ke:(le.push(Z),Z=ke),le.length>=j)break}return Z&&le.length<j&&le.push(Z),o.jsxs("g",{transform:"translate("+M.x+","+M.y+")",onMouseEnter:function(){c(M.id)},onMouseLeave:function(){c(null)},onClick:function(){n&&n(S)},style:{cursor:n?"pointer":"default"},children:[o.jsx("rect",{width:M.w,height:M.h,rx:M.h/2,ry:M.h/2,fill:I.fill,stroke:I.stroke,strokeWidth:Q?1.75:1,strokeDasharray:S.source==="reasoning"?void 0:"4,2"}),o.jsx("text",{x:14,y:2,fontSize:9,fontStyle:"italic",fill:I.label,children:le.map(function(ke,re){return o.jsx("tspan",{x:14,dy:re===0?14:11,children:(re===0?"💭 ":"")+ke},"ln"+re)})}),o.jsx("title",{children:(S.source==="reasoning"?"[reasoning] ":"[thought] ")+(S.fullText||S.label)})]},M.id)}return o.jsxs("g",{transform:"translate("+M.x+","+M.y+")",onMouseEnter:function(){c(M.id)},onMouseLeave:function(){c(null)},onClick:function(){n&&n(S)},style:{cursor:n?"pointer":"default"},children:[o.jsx("rect",{width:M.w,height:M.h,rx:5,ry:5,fill:I.fill,stroke:I.stroke,strokeWidth:B||Q?2:1.25,opacity:S.hidden?.55:1,children:B?o.jsx("animate",{attributeName:"stroke-width",values:"1.5;2.5;1.5",dur:"1.6s",repeatCount:"indefinite"}):null}),o.jsx("text",{x:8,y:16,fontSize:10,fontWeight:600,fill:I.label,children:S.tool}),o.jsx("text",{x:8,y:32,fontSize:10,fill:t?"#cbd5e1":"#475569",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",children:HV(S.label,22)}),o.jsx("title",{children:S.tool+" · "+S.label+(S.status==="error"?" · ERROR":S.status==="running"?" · RUNNING":"")}),B?o.jsxs("g",{transform:"translate("+(M.w-9)+",9)",children:[o.jsx("circle",{r:4.5,fill:t?"#1e293b":"#ffffff",stroke:I.stroke,strokeWidth:.75}),o.jsxs("circle",{r:3,fill:t?"#38bdf8":"#0ea5e9",children:[o.jsx("animate",{attributeName:"opacity",values:"1;0.25;1",dur:"1.1s",repeatCount:"indefinite"}),o.jsx("animate",{attributeName:"r",values:"2.4;3.4;2.4",dur:"1.1s",repeatCount:"indefinite"})]})]}):null]},M.id)})]})})]})}/*! @license DOMPurify 3.4.13 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.13/LICENSE */function fS(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function GV(e){if(Array.isArray(e))return e}function KV(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r,a,i,s,l=[],c=!0,u=!1;try{if(i=(n=n.call(e)).next,t!==0)for(;!(c=(r=i.call(n)).done)&&(l.push(r.value),l.length!==t);c=!0);}catch(d){u=!0,a=d}finally{try{if(!c&&n.return!=null&&(s=n.return(),Object(s)!==s))return}finally{if(u)throw a}}return l}}function YV(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
103
103
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function QV(e,t){return GV(e)||KV(e,t)||XV(e,t)||YV()}function XV(e,t){if(e){if(typeof e=="string")return fS(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?fS(e,t):void 0}}const wA=Object.entries,pS=Object.setPrototypeOf,ZV=Object.isFrozen,JV=Object.getPrototypeOf,eG=Object.getOwnPropertyDescriptor;let xn=Object.freeze,kn=Object.seal,rs=Object.create,EA=typeof Reflect<"u"&&Reflect,sx=EA.apply,ox=EA.construct;xn||(xn=function(t){return t});kn||(kn=function(t){return t});sx||(sx=function(t,n){for(var r=arguments.length,a=new Array(r>2?r-2:0),i=2;i<r;i++)a[i-2]=arguments[i];return t.apply(n,a)});ox||(ox=function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),a=1;a<n;a++)r[a-1]=arguments[a];return new t(...r)});const Xi=an(Array.prototype.forEach),tG=an(Array.prototype.lastIndexOf),gS=an(Array.prototype.pop),Zi=an(Array.prototype.push),nG=an(Array.prototype.splice),Oa=Array.isArray,vo=an(String.prototype.toLowerCase),T0=an(String.prototype.toString),hS=an(String.prototype.match),oo=an(String.prototype.replace),mS=an(String.prototype.indexOf),rG=an(String.prototype.trim),aG=an(Number.prototype.toString),iG=an(Boolean.prototype.toString),yS=typeof BigInt>"u"?null:an(BigInt.prototype.toString),xS=typeof Symbol>"u"?null:an(Symbol.prototype.toString),fn=an(Object.prototype.hasOwnProperty),lo=an(Object.prototype.toString),dn=an(RegExp.prototype.test),li=sG(TypeError);function an(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);for(var n=arguments.length,r=new Array(n>1?n-1:0),a=1;a<n;a++)r[a-1]=arguments[a];return sx(e,t,r)}}function sG(e){return function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return ox(e,n)}}function kt(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:vo;if(pS&&pS(e,null),!Oa(t))return e;let r=t.length;for(;r--;){let a=t[r];if(typeof a=="string"){const i=n(a);i!==a&&(ZV(t)||(t[r]=i),a=i)}e[a]=!0}return e}function oG(e){for(let t=0;t<e.length;t++)fn(e,t)||(e[t]=null);return e}function En(e){const t=rs(null);for(const r of wA(e)){var n=QV(r,2);const a=n[0],i=n[1];fn(e,a)&&(Oa(i)?t[a]=oG(i):i&&typeof i=="object"&&i.constructor===Object?t[a]=En(i):t[a]=i)}return t}function lG(e){switch(typeof e){case"string":return e;case"number":return aG(e);case"boolean":return iG(e);case"bigint":return yS?yS(e):"0";case"symbol":return xS?xS(e):"Symbol()";case"undefined":return lo(e);case"function":case"object":{if(e===null)return lo(e);const t=e,n=Er(t,"toString");if(typeof n=="function"){const r=n(t);return typeof r=="string"?r:lo(r)}return lo(e)}default:return lo(e)}}function Er(e,t){for(;e!==null;){const r=eG(e,t);if(r){if(r.get)return an(r.get);if(typeof r.value=="function")return an(r.value)}e=JV(e)}function n(){return null}return n}function cG(e){try{return dn(e,""),!0}catch{return!1}}const bS=xn(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),A0=xn(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),R0=xn(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),uG=xn(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),M0=xn(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),dG=xn(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),vS=xn(["#text"]),kS=xn(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","command","commandfor","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns"]),I0=xn(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dominant-baseline","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-orientation","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),_S=xn(["accent","accentunder","align","bevelled","close","columnalign","columnlines","columnspacing","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lquote","lspace","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),xc=xn(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),fG=kn(/{{[\w\W]*|^[\w\W]*}}/g),pG=kn(/<%[\w\W]*|^[\w\W]*%>/g),gG=kn(/\${[\w\W]*/g),hG=kn(/^data-[\-\w.\u00B7-\uFFFF]+$/),mG=kn(/^aria-[\-\w]+$/),wS=kn(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),yG=kn(/^(?:\w+script|data):/i),xG=kn(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),bG=kn(/^html$/i),vG=kn(/^[a-z][.\w]*(-[.\w]+)+$/i),ES=kn(/<[/\w!]/g),NS=kn(/<[/\w]/g),kG=kn(/<\/no(script|embed|frames)/i),_G=kn(/\/>/i),Xn={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},wG=function(){return typeof window>"u"?null:window},EG=function(t,n){if(typeof t!="object"||typeof t.createPolicy!="function")return null;let r=null;const a="data-tt-policy-suffix";n&&n.hasAttribute(a)&&(r=n.getAttribute(a));const i="dompurify"+(r?"#"+r:"");try{return t.createPolicy(i,{createHTML(s){return s},createScriptURL(s){return s}})}catch{return console.warn("TrustedTypes policy "+i+" could not be created."),null}},SS=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Ta=function(t,n,r,a){return fn(t,n)&&Oa(t[n])?kt(a.base?En(a.base):{},t[n],a.transform):r};function NA(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:wG();const t=Me=>NA(Me);if(t.version="3.4.13",t.removed=[],!e||!e.document||e.document.nodeType!==Xn.document||!e.Element)return t.isSupported=!1,t;let n=e.document;const r=n,a=r.currentScript;e.DocumentFragment;const i=e.HTMLTemplateElement,s=e.Node,l=e.Element,c=e.NodeFilter,u=e.NamedNodeMap;u===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;const d=e.DOMParser,f=e.trustedTypes,p=l.prototype,g=Er(p,"cloneNode"),m=Er(p,"remove"),y=Er(p,"nextSibling"),v=Er(p,"childNodes"),x=Er(p,"parentNode"),b=Er(p,"shadowRoot"),k=Er(p,"attributes"),N=s&&s.prototype?Er(s.prototype,"nodeType"):null,w=s&&s.prototype?Er(s.prototype,"nodeName"):null,_=s&&s.prototype?Er(s.prototype,"ownerDocument"):null;if(typeof i=="function"){const Me=n.createElement("template");Me.content&&Me.content.ownerDocument&&(n=Me.content.ownerDocument)}let T,A="",D,R=!1,$=0;const F=function(){if($>0)throw li('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},G=function(O){F(),$++;try{return T.createHTML(O)}finally{$--}},P=function(O){F(),$++;try{return T.createScriptURL(O)}finally{$--}},M=function(){return R||(D=EG(f,a),R=!0),D},S=n,I=S.implementation,B=S.createNodeIterator,Q=S.createDocumentFragment,C=S.getElementsByTagName,K=r.importNode;let W=SS();t.isSupported=typeof wA=="function"&&typeof x=="function"&&I&&I.createHTMLDocument!==void 0;const j=fG,U=pG,le=gG,Z=hG,ke=mG,re=yG,X=xG,Ne=vG;let ve=wS,me=null;const pe=kt({},[...bS,...A0,...R0,...M0,...vS]);let Le=null;const Se=kt({},[...kS,...I0,..._S,...xc]);let Te=Object.seal(rs(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),Fe=null,fe=null;const xe=Object.seal(rs(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let Ce=!0,ue=!0,he=!1,_e=!0,Pe=!1,Xe=!0,H=!1,z=!1,te=null,ce=null,je=!1,Be=!1,Ke=!1,Ye=!1,ot=!0,Rt=!1;const mt="user-content-";let Mt=!0,de=!1,We={},nt=null;const yt=kt({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]);let ae=null;const Ie=kt({},["audio","video","img","source","image","track"]);let De=null;const Ve=kt({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),ft="http://www.w3.org/1998/Math/MathML",et="http://www.w3.org/2000/svg",Qe="http://www.w3.org/1999/xhtml";let Xt=Qe,oe=!1,jt=null;const ct=kt({},[ft,et,Qe],T0),wt=xn(["mi","mo","mn","ms","mtext"]);let gt=kt({},wt);const cn=xn(["annotation-xml"]);let Kn=kt({},cn);const or=kt({},["title","style","font","a","script"]);let we=null;const Ze=["application/xhtml+xml","text/html"],$t="text/html";let Ct=null,br=null;const Pn=n.createElement("form"),vr=function(O){return O instanceof RegExp||O instanceof Function},ba=function(){let O=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(br&&br===O)return;(!O||typeof O!="object")&&(O={}),O=En(O),we=Ze.indexOf(O.PARSER_MEDIA_TYPE)===-1?$t:O.PARSER_MEDIA_TYPE,Ct=we==="application/xhtml+xml"?T0:vo,me=Ta(O,"ALLOWED_TAGS",pe,{transform:Ct}),Le=Ta(O,"ALLOWED_ATTR",Se,{transform:Ct}),jt=Ta(O,"ALLOWED_NAMESPACES",ct,{transform:T0}),De=Ta(O,"ADD_URI_SAFE_ATTR",Ve,{transform:Ct,base:Ve}),ae=Ta(O,"ADD_DATA_URI_TAGS",Ie,{transform:Ct,base:Ie}),nt=Ta(O,"FORBID_CONTENTS",yt,{transform:Ct}),Fe=Ta(O,"FORBID_TAGS",En({}),{transform:Ct}),fe=Ta(O,"FORBID_ATTR",En({}),{transform:Ct}),We=fn(O,"USE_PROFILES")?O.USE_PROFILES&&typeof O.USE_PROFILES=="object"?En(O.USE_PROFILES):O.USE_PROFILES:!1,Ce=O.ALLOW_ARIA_ATTR!==!1,ue=O.ALLOW_DATA_ATTR!==!1,he=O.ALLOW_UNKNOWN_PROTOCOLS||!1,_e=O.ALLOW_SELF_CLOSE_IN_ATTR!==!1,Pe=O.SAFE_FOR_TEMPLATES||!1,Xe=O.SAFE_FOR_XML!==!1,H=O.WHOLE_DOCUMENT||!1,Be=O.RETURN_DOM||!1,Ke=O.RETURN_DOM_FRAGMENT||!1,Ye=O.RETURN_TRUSTED_TYPE||!1,je=O.FORCE_BODY||!1,ot=O.SANITIZE_DOM!==!1,Rt=O.SANITIZE_NAMED_PROPS||!1,Mt=O.KEEP_CONTENT!==!1,de=O.IN_PLACE||!1,ve=cG(O.ALLOWED_URI_REGEXP)?O.ALLOWED_URI_REGEXP:wS,Xt=typeof O.NAMESPACE=="string"?O.NAMESPACE:Qe,gt=fn(O,"MATHML_TEXT_INTEGRATION_POINTS")&&O.MATHML_TEXT_INTEGRATION_POINTS&&typeof O.MATHML_TEXT_INTEGRATION_POINTS=="object"?En(O.MATHML_TEXT_INTEGRATION_POINTS):kt({},wt),Kn=fn(O,"HTML_INTEGRATION_POINTS")&&O.HTML_INTEGRATION_POINTS&&typeof O.HTML_INTEGRATION_POINTS=="object"?En(O.HTML_INTEGRATION_POINTS):kt({},cn);const ie=fn(O,"CUSTOM_ELEMENT_HANDLING")&&O.CUSTOM_ELEMENT_HANDLING&&typeof O.CUSTOM_ELEMENT_HANDLING=="object"?En(O.CUSTOM_ELEMENT_HANDLING):rs(null);if(Te=rs(null),fn(ie,"tagNameCheck")&&vr(ie.tagNameCheck)&&(Te.tagNameCheck=ie.tagNameCheck),fn(ie,"attributeNameCheck")&&vr(ie.attributeNameCheck)&&(Te.attributeNameCheck=ie.attributeNameCheck),fn(ie,"allowCustomizedBuiltInElements")&&typeof ie.allowCustomizedBuiltInElements=="boolean"&&(Te.allowCustomizedBuiltInElements=ie.allowCustomizedBuiltInElements),kn(Te),Pe&&(ue=!1),Ke&&(Be=!0),We&&(me=kt({},vS),Le=rs(null),We.html===!0&&(kt(me,bS),kt(Le,kS)),We.svg===!0&&(kt(me,A0),kt(Le,I0),kt(Le,xc)),We.svgFilters===!0&&(kt(me,R0),kt(Le,I0),kt(Le,xc)),We.mathMl===!0&&(kt(me,M0),kt(Le,_S),kt(Le,xc))),xe.tagCheck=null,xe.attributeCheck=null,fn(O,"ADD_TAGS")&&(typeof O.ADD_TAGS=="function"?xe.tagCheck=O.ADD_TAGS:Oa(O.ADD_TAGS)&&(me===pe&&(me=En(me)),kt(me,O.ADD_TAGS,Ct))),fn(O,"ADD_ATTR")&&(typeof O.ADD_ATTR=="function"?xe.attributeCheck=O.ADD_ATTR:Oa(O.ADD_ATTR)&&(Le===Se&&(Le=En(Le)),kt(Le,O.ADD_ATTR,Ct))),fn(O,"ADD_URI_SAFE_ATTR")&&Oa(O.ADD_URI_SAFE_ATTR)&&kt(De,O.ADD_URI_SAFE_ATTR,Ct),fn(O,"FORBID_CONTENTS")&&Oa(O.FORBID_CONTENTS)&&(nt===yt&&(nt=En(nt)),kt(nt,O.FORBID_CONTENTS,Ct)),fn(O,"ADD_FORBID_CONTENTS")&&Oa(O.ADD_FORBID_CONTENTS)&&(nt===yt&&(nt=En(nt)),kt(nt,O.ADD_FORBID_CONTENTS,Ct)),Mt&&(me["#text"]=!0),H&&kt(me,["html","head","body"]),me.table&&(kt(me,["tbody"]),delete Fe.tbody),O.TRUSTED_TYPES_POLICY){if(typeof O.TRUSTED_TYPES_POLICY.createHTML!="function")throw li('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof O.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw li('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');const Ee=T;T=O.TRUSTED_TYPES_POLICY;try{A=G("")}catch($e){throw T=Ee,$e}}else O.TRUSTED_TYPES_POLICY===null?(T=void 0,A=""):(T===void 0&&(T=M()),T&&typeof A=="string"&&(A=G("")));xn&&xn(O),br=O},Fn=kt({},[...A0,...R0,...uG]),_l=kt({},[...M0,...dG]),va=function(O,ie,Ee){return ie.namespaceURI===Qe?O==="svg":ie.namespaceURI===ft?O==="svg"&&(Ee==="annotation-xml"||gt[Ee]):!!Fn[O]},Bi=function(O,ie,Ee){return ie.namespaceURI===Qe?O==="math":ie.namespaceURI===et?O==="math"&&Kn[Ee]:!!_l[O]},wl=function(O,ie,Ee){return ie.namespaceURI===et&&!Kn[Ee]||ie.namespaceURI===ft&&!gt[Ee]?!1:!_l[O]&&(or[O]||!Fn[O])},El=function(O){let ie=x(O);(!ie||!ie.tagName)&&(ie={namespaceURI:Xt,tagName:"template"});const Ee=vo(O.tagName),$e=vo(ie.tagName);return jt[O.namespaceURI]?O.namespaceURI===et?va(Ee,ie,$e):O.namespaceURI===ft?Bi(Ee,ie,$e):O.namespaceURI===Qe?wl(Ee,ie,$e):!!(we==="application/xhtml+xml"&&jt[O.namespaceURI]):!1},Yn=function(O){Zi(t.removed,{element:O});try{x(O).removeChild(O)}catch{if(m(O),!x(O))throw li("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},hn=function(O){ai(O);const ie=v(O);if(ie){const $e=[];Xi(ie,Ge=>{Zi($e,Ge)}),Xi($e,Ge=>{try{m(Ge)}catch{}})}const Ee=k(O);if(Ee)for(let $e=Ee.length-1;$e>=0;--$e){const Ge=Ee[$e],it=Ge&&Ge.name;if(typeof it=="string")try{O.removeAttribute(it)}catch{}}},Zt=function(O,ie){try{Zi(t.removed,{attribute:ie.getAttributeNode(O),from:ie})}catch{Zi(t.removed,{attribute:null,from:ie})}if(ie.removeAttribute(O),O==="is")if(Be||Ke)try{Yn(ie)}catch{}else try{ie.setAttribute(O,"")}catch{}},Nl=function(O){const ie=k(O);if(ie)for(let Ee=ie.length-1;Ee>=0;--Ee){const $e=ie[Ee],Ge=$e&&$e.name;if(!(typeof Ge!="string"||Le[Ct(Ge)]))try{O.removeAttribute(Ge)}catch{}}},ai=function(O){const ie=[O];for(;ie.length>0;){const Ee=ie.pop();(N?N(Ee):Ee.nodeType)===Xn.element&&Nl(Ee);const Ge=v(Ee);if(Ge)for(let it=Ge.length-1;it>=0;--it)ie.push(Ge[it])}},Or=function(O){if(!Xe)return;const ie=[O];for(;ie.length>0;){const Ee=ie.pop(),$e=N?N(Ee):Ee.nodeType;if($e===Xn.processingInstruction||$e===Xn.comment&&dn(NS,Ee.data)){try{m(Ee)}catch{}continue}if($e===Xn.element){const it=Ee,Et=Ct(w?w(Ee):Ee.nodeName);try{it.hasAttribute&&it.hasAttribute("patchsrc")&&it.removeAttribute("patchsrc"),it.hasAttribute&&it.hasAttribute("for")&&Et!=="label"&&Et!=="output"&&it.removeAttribute("for")}catch{}}const Ge=v(Ee);if(Ge)for(let it=Ge.length-1;it>=0;--it)ie.push(Ge[it])}},Sl=function(O){let ie=null,Ee=null;if(je)O="<remove></remove>"+O;else{const it=hS(O,/^[\r\n\t ]+/);Ee=it&&it[0]}we==="application/xhtml+xml"&&Xt===Qe&&(O='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+O+"</body></html>");const $e=T?G(O):O;if(Xt===Qe)try{ie=new d().parseFromString($e,we)}catch{}if(!ie||!ie.documentElement){ie=I.createDocument(Xt,"template",null);try{ie.documentElement.innerHTML=oe?A:$e}catch{}}const Ge=ie.body||ie.documentElement;return O&&Ee&&Ge.insertBefore(n.createTextNode(Ee),Ge.childNodes[0]||null),Xt===Qe?C.call(ie,H?"html":"body")[0]:H?ie.documentElement:Ge},zi=function(O){const ie=_?_(O):O.ownerDocument;return B.call(ie||O,O,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},Ui=function(O){return O=oo(O,j," "),O=oo(O,U," "),O=oo(O,le," "),O},ka=function(O){var ie;O.normalize();const Ee=_?_(O):O.ownerDocument,$e=B.call(Ee||O,O,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null);let Ge=$e.nextNode();for(;Ge;)Ge.data=Ui(Ge.data),Ge=$e.nextNode();const it=(ie=O.querySelectorAll)===null||ie===void 0?void 0:ie.call(O,"template");it&&Xi(it,Et=>{Yr(Et.content)&&ka(Et.content)})},qi=function(O){const ie=w?w(O):null;return typeof ie!="string"||Ct(ie)!=="form"?!1:typeof O.nodeName!="string"||typeof O.textContent!="string"||typeof O.removeChild!="function"||O.attributes!==k(O)||typeof O.removeAttribute!="function"||typeof O.setAttribute!="function"||typeof O.namespaceURI!="string"||typeof O.insertBefore!="function"||typeof O.hasChildNodes!="function"||O.nodeType!==N(O)||O.childNodes!==v(O)},Yr=function(O){if(!N||typeof O!="object"||O===null)return!1;try{return N(O)===Xn.documentFragment}catch{return!1}},kr=function(O){if(!N||typeof O!="object"||O===null)return!1;try{return typeof N(O)=="number"}catch{return!1}};function Bn(Me,O,ie){Me.length!==0&&Xi(Me,Ee=>{Ee.call(t,O,ie,br)})}const yd=function(O,ie){return!!(Xe&&O.hasChildNodes()&&!kr(O.firstElementChild)&&dn(ES,O.textContent)&&dn(ES,O.innerHTML)||Xe&&O.namespaceURI===Qe&&ie==="style"&&kr(O.firstElementChild)||O.nodeType===Xn.processingInstruction||Xe&&O.nodeType===Xn.comment&&dn(NS,O.data))},ii=function(O,ie,Ee){if(!Fe[ie]&&Tl(ie)&&(Te.tagNameCheck instanceof RegExp&&dn(Te.tagNameCheck,ie)||Te.tagNameCheck instanceof Function&&Te.tagNameCheck(ie)))return!1;if(Mt&&!nt[ie]){const $e=x(O),Ge=v(O);if(Ge&&$e){const it=Ge.length;for(let Et=it-1;Et>=0;--Et){const Tt=O===Ee?g(Ge[Et],!0):Ge[Et];$e.insertBefore(Tt,y(O))}}}return Yn(O),!0},qs=function(O,ie,Ee,$e){return O.length===0?ie:ie===Ee||ie===$e?En(ie):ie},He=function(O,ie){if(Bn(W.beforeSanitizeElements,O,null),O!==ie&&x(O)===null)return de&&ai(O),!0;if(qi(O))return Yn(O),!0;const Ee=Ct(w?w(O):O.nodeName);if(me=qs(W.uponSanitizeElement,me,pe,te),Bn(W.uponSanitizeElement,O,{tagName:Ee,allowedTags:me}),O!==ie&&x(O)===null)return de&&ai(O),!0;if(yd(O,Ee))return Yn(O),!0;if(Fe[Ee]||!(xe.tagCheck instanceof Function&&xe.tagCheck(Ee))&&!me[Ee]){const Ge=ii(O,Ee,ie);return Ge===!1&&Bn(W.afterSanitizeElements,O,null),Ge}if((N?N(O):O.nodeType)===Xn.element&&!El(O)||(Ee==="noscript"||Ee==="noembed"||Ee==="noframes")&&dn(kG,O.innerHTML))return Yn(O),!0;if(Pe&&O.nodeType===Xn.text){const Ge=Ui(O.textContent);O.textContent!==Ge&&(Zi(t.removed,{element:O.cloneNode()}),O.textContent=Ge)}return Bn(W.afterSanitizeElements,O,null),!1},Cl=function(O,ie,Ee){if(fe[ie]||Xe&&ie==="patchsrc"||Xe&&ie==="for"&&O!=="label"&&O!=="output"||ot&&(ie==="id"||ie==="name")&&(Ee in n||Ee in Pn))return!1;const $e=Le[ie]||xe.attributeCheck instanceof Function&&xe.attributeCheck(ie,O);if(!(ue&&dn(Z,ie))){if(!(Ce&&dn(ke,ie))){if($e){if(!De[ie]){if(!dn(ve,oo(Ee,X,""))){if(!((ie==="src"||ie==="xlink:href"||ie==="href")&&O!=="script"&&mS(Ee,"data:")===0&&ae[O])){if(!(he&&!dn(re,oo(Ee,X,"")))){if(Ee)return!1}}}}}else if(!(Tl(O)&&(Te.tagNameCheck instanceof RegExp&&dn(Te.tagNameCheck,O)||Te.tagNameCheck instanceof Function&&Te.tagNameCheck(O))&&(Te.attributeNameCheck instanceof RegExp&&dn(Te.attributeNameCheck,ie)||Te.attributeNameCheck instanceof Function&&Te.attributeNameCheck(ie,O))||ie==="is"&&Te.allowCustomizedBuiltInElements&&(Te.tagNameCheck instanceof RegExp&&dn(Te.tagNameCheck,Ee)||Te.tagNameCheck instanceof Function&&Te.tagNameCheck(Ee))))return!1}}return!0},jl=kt({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),Tl=function(O){return!jl[vo(O)]&&dn(Ne,O)},xd=function(O,ie,Ee,$e){if(T&&typeof f=="object"&&typeof f.getAttributeType=="function"&&!Ee)switch(f.getAttributeType(O,ie)){case"TrustedHTML":return G($e);case"TrustedScriptURL":return P($e)}return $e},Al=function(O,ie,Ee,$e){try{Ee?O.setAttributeNS(Ee,ie,$e):O.setAttribute(ie,$e),qi(O)?Yn(O):gS(t.removed)}catch{Zt(ie,O)}},Rl=function(O){Bn(W.beforeSanitizeAttributes,O,null);const ie=O.attributes;if(!ie||qi(O))return;Le=qs(W.uponSanitizeAttribute,Le,Se,ce);const Ee={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:Le,forceKeepAttr:void 0};let $e=ie.length;const Ge=Ct(O.nodeName);for(;$e--;){const it=ie[$e],Et=it.name,Tt=it.namespaceURI,Vt=it.value,Bt=Ct(Et),wa=Vt;let Jt=Et==="value"?wa:rG(wa);if(Ee.attrName=Bt,Ee.attrValue=Jt,Ee.keepAttr=!0,Ee.forceKeepAttr=void 0,Bn(W.uponSanitizeAttribute,O,Ee),Jt=Ee.attrValue,Rt&&(Bt==="id"||Bt==="name")&&mS(Jt,mt)!==0&&(Zt(Et,O),Jt=mt+Jt),Xe&&dn(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,Jt)){Zt(Et,O);continue}if(Bt==="attributename"&&hS(Jt,"href")){Zt(Et,O);continue}if(!Ee.forceKeepAttr){if(!Ee.keepAttr){Zt(Et,O);continue}if(!_e&&dn(_G,Jt)){Zt(Et,O);continue}if(Pe&&(Jt=Ui(Jt)),!Cl(Ge,Bt,Jt)){Zt(Et,O);continue}Jt=xd(Ge,Bt,Tt,Jt),Jt!==wa&&Al(O,Et,Tt,Jt)}}Bn(W.afterSanitizeAttributes,O,null)},_a=function(O){let ie=null;const Ee=zi(O);for(Bn(W.beforeSanitizeShadowDOM,O,null);ie=Ee.nextNode();)if(Bn(W.uponSanitizeShadowNode,ie,null),He(ie,O),Rl(ie),Yr(ie.content)&&_a(ie.content),(N?N(ie):ie.nodeType)===Xn.element){const Ge=b(ie);Yr(Ge)&&($s(Ge),_a(Ge))}Bn(W.afterSanitizeShadowDOM,O,null)},$s=function(O){const ie=[{node:O,shadow:null}];for(;ie.length>0;){const Ee=ie.pop();if(Ee.shadow){_a(Ee.shadow);continue}const $e=Ee.node,it=(N?N($e):$e.nodeType)===Xn.element,Et=v($e);if(Et)for(let Tt=Et.length-1;Tt>=0;--Tt)ie.push({node:Et[Tt],shadow:null});if(it){const Tt=w?w($e):null;if(typeof Tt=="string"&&Ct(Tt)==="template"){const Vt=$e.content;Yr(Vt)&&ie.push({node:Vt,shadow:null})}}if(it){const Tt=b($e);Yr(Tt)&&ie.push({node:null,shadow:Tt},{node:Tt,shadow:null})}}};return t.sanitize=function(Me){let O=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},ie=null,Ee=null,$e=null,Ge=null;if(oe=!Me,oe&&(Me="<!-->"),typeof Me!="string"&&!kr(Me)&&(Me=lG(Me),typeof Me!="string"))throw li("dirty is not a string, aborting");if(!t.isSupported)return Me;z?(me=te,Le=ce):ba(O),(W.uponSanitizeElement.length>0||W.uponSanitizeAttribute.length>0)&&(me=En(me)),W.uponSanitizeAttribute.length>0&&(Le=En(Le)),t.removed=[];const it=de&&typeof Me!="string"&&kr(Me);if(it){Or(Me);const Vt=w?w(Me):Me.nodeName;if(typeof Vt=="string"){const Bt=Ct(Vt);if(!me[Bt]||Fe[Bt])throw hn(Me),li("root node is forbidden and cannot be sanitized in-place")}if(qi(Me))throw hn(Me),li("root node is clobbered and cannot be sanitized in-place");try{$s(Me)}catch(Bt){throw hn(Me),Bt}}else if(kr(Me))ie=Sl("<!---->"),Ee=ie.ownerDocument.importNode(Me,!0),Ee.nodeType===Xn.element&&Ee.nodeName==="BODY"||Ee.nodeName==="HTML"?ie=Ee:ie.appendChild(Ee),$s(Ee);else{if(!Be&&!Pe&&!H&&Me.indexOf("<")===-1)return T&&Ye?G(Me):Me;if(ie=Sl(Me),!ie)return Be?null:Ye?A:""}ie&&je&&Yn(ie.firstChild);const Et=it?Me:ie;try{const Vt=zi(Et);for(;$e=Vt.nextNode();)He($e,Et),Rl($e),Yr($e.content)&&_a($e.content)}catch(Vt){throw it&&(hn(Me),Xi(t.removed,Bt=>{Bt.element&&ai(Bt.element)})),Vt}if(it)return Xi(t.removed,Vt=>{Vt.element&&ai(Vt.element)}),Pe&&ka(Me),Me;if(Be){if(Pe&&ka(ie),Ke)for(Ge=Q.call(ie.ownerDocument);ie.firstChild;)Ge.appendChild(ie.firstChild);else Ge=ie;return(Le.shadowroot||Le.shadowrootmode)&&(Ge=K.call(r,Ge,!0)),Ge}let Tt=H?ie.outerHTML:ie.innerHTML;return H&&me["!doctype"]&&ie.ownerDocument&&ie.ownerDocument.doctype&&ie.ownerDocument.doctype.name&&dn(bG,ie.ownerDocument.doctype.name)&&(Tt="<!DOCTYPE "+ie.ownerDocument.doctype.name+`>
104
- `+Tt),Pe&&(Tt=Ui(Tt)),T&&Ye?G(Tt):Tt},t.setConfig=function(){let Me=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};ba(Me),z=!0,te=me,ce=Le},t.clearConfig=function(){br=null,z=!1,te=null,ce=null,T=D,A=""},t.isValidAttribute=function(Me,O,ie){br||ba({});const Ee=Ct(Me),$e=Ct(O);return Cl(Ee,$e,ie)},t.addHook=function(Me,O){typeof O=="function"&&fn(W,Me)&&Zi(W[Me],O)},t.removeHook=function(Me,O){if(fn(W,Me)){if(O!==void 0){const ie=tG(W[Me],O);return ie===-1?void 0:nG(W[Me],ie,1)[0]}return gS(W[Me])}},t.removeHooks=function(Me){fn(W,Me)&&(W[Me]=[])},t.removeAllHooks=function(){W=SS()},t}var NG=NA();let L0=null;function SG(){return L0||(L0=uj(()=>import("./mermaid.core-D2L8Rtb7.js").then(e=>e.bo),[]).then(function(e){const t=e.default||e;return t.initialize({startOnLoad:!1,securityLevel:"strict",theme:"default",flowchart:{curve:"basis"},suppressErrorRendering:!0}),t})),L0}function CS(){return typeof document>"u"?!1:document.documentElement.classList.contains("dark")}let jS=0;function CG(){return jS+=1,"pave-canvas-"+jS}function jG({source:e}){const t=h.useRef(null),n=h.useRef(CG()),[r,a]=h.useState(null),[i,s]=h.useState(CS());return h.useEffect(function(){if(typeof window>"u")return;const l=new MutationObserver(function(){const c=CS();s(function(u){return u!==c?c:u})});return l.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),function(){l.disconnect()}},[]),h.useEffect(function(){let l=!1;return a(null),SG().then(function(c){l||(c.initialize({startOnLoad:!1,securityLevel:"strict",theme:i?"dark":"default",flowchart:{curve:"basis"},suppressErrorRendering:!0}),c.render(n.current,e).then(function(u){if(!l&&t.current){let d=u.svg;d=d.replace(/<svg([^>]*)\sstyle="[^"]*max-width:[^";]*;?[^"]*"/i,"<svg$1"),d=d.replace(/(<svg[^>]*)\swidth="[^"]*"/i,"$1"),d=d.replace(/(<svg[^>]*)\sheight="[^"]*"/i,"$1"),d=d.replace(/<svg\b/i,'<svg width="100%" height="100%" preserveAspectRatio="xMidYMid meet"'),t.current.innerHTML=d}}).catch(function(u){l||a(u&&u.message||String(u))}))}).catch(function(c){l||a("Failed to load mermaid: "+(c&&c.message||String(c)))}),function(){l=!0}},[e,i]),r?o.jsxs("div",{className:"text-xs text-red-600 dark:text-red-400 p-2",children:[o.jsx("div",{className:"font-semibold mb-1",children:"Mermaid render error:"}),o.jsx("pre",{className:"whitespace-pre-wrap",children:r}),o.jsxs("details",{className:"mt-2",children:[o.jsx("summary",{className:"cursor-pointer text-gray-600 dark:text-gray-400",children:"Source"}),o.jsx("pre",{className:"mt-1 p-2 bg-gray-100 dark:bg-gray-800 rounded overflow-x-auto",children:e})]})]}):o.jsx("div",{ref:t,className:"mermaid-canvas w-full h-full flex items-center justify-center [&>svg]:max-w-full [&>svg]:max-h-full [&>svg]:w-full [&>svg]:h-auto"})}function TG({source:e}){const t=h.useMemo(function(){return NG.sanitize(e,{USE_PROFILES:{svg:!0,svgFilters:!0}})},[e]);return o.jsx("div",{className:"svg-canvas overflow-x-auto",dangerouslySetInnerHTML:{__html:t}})}function AG({source:e}){return o.jsx("pre",{className:"text-sm p-2 bg-gray-100 dark:bg-gray-800 rounded overflow-x-auto",children:e})}function RG({canvas:e}){if(!e||!e.type||!e.source)return null;let t=null;return e.type==="mermaid"?t=o.jsx(jG,{source:e.source}):e.type==="svg"?t=o.jsx(TG,{source:e.source}):e.type==="katex"?t=o.jsx(AG,{source:e.source}):t=o.jsxs("pre",{className:"text-xs text-red-600 dark:text-red-400",children:["Unknown canvas type: ",e.type]}),o.jsx("div",{className:"w-full h-full flex items-center justify-center",children:t})}function TS({canvases:e,onClear:t}){const n=Array.isArray(e)?e:[],[r,a]=h.useState(Math.max(0,n.length-1)),[i,s]=h.useState(1),[l,c]=h.useState(!1);h.useEffect(function(){a(function(v){return v>=n.length-2?Math.max(0,n.length-1):Math.min(v,Math.max(0,n.length-1))})},[n.length]),h.useEffect(function(){s(1)},[r]),h.useEffect(function(){if(!l)return;const v=x=>{x.key==="Escape"&&c(!1)};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[l]);const u=h.useCallback(()=>s(v=>Math.min(4,+(v+.25).toFixed(2))),[]),d=h.useCallback(()=>s(v=>Math.max(.5,+(v-.25).toFixed(2))),[]),f=h.useCallback(()=>s(1),[]);if(n.length===0)return o.jsxs("div",{className:"h-full flex flex-col items-center justify-center p-6 text-center",children:[o.jsx("svg",{className:"w-12 h-12 text-gray-300 dark:text-gray-600 mb-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 17V7m0 10a2 2 0 01-2 2H5a2 2 0 01-2-2V7a2 2 0 012-2h2a2 2 0 012 2m0 10a2 2 0 002 2h2a2 2 0 002-2M9 7a2 2 0 012-2h2a2 2 0 012 2m0 10V7m0 10a2 2 0 002 2h2a2 2 0 002-2V7a2 2 0 00-2-2h-2a2 2 0 00-2 2"})}),o.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400 max-w-xs",children:["Ask the agent to draw something here. It can use the ",o.jsx("code",{className:"px-1 bg-gray-200 dark:bg-gray-700 rounded",children:"canvas"})," tool to render Mermaid diagrams, SVG illustrations, or math."]})]});const p=Math.min(Math.max(0,r),n.length-1),g=n[p],m=o.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5 border-b border-gray-200 dark:border-gray-700 text-xs",children:[n.length>1?o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx("button",{type:"button",onClick:()=>a(Math.max(0,p-1)),disabled:p===0,className:"px-2 py-0.5 rounded text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-40 disabled:cursor-not-allowed",title:"Previous canvas",children:"←"}),o.jsxs("span",{className:"text-gray-500 dark:text-gray-400 tabular-nums",children:[p+1,"/",n.length]}),o.jsx("button",{type:"button",onClick:()=>a(Math.min(n.length-1,p+1)),disabled:p===n.length-1,className:"px-2 py-0.5 rounded text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-40 disabled:cursor-not-allowed",title:"Next canvas",children:"→"})]}):o.jsx("div",{}),o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx("button",{type:"button",onClick:d,disabled:i<=.5,className:"px-1.5 py-0.5 rounded text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-40",title:"Zoom out",children:"−"}),o.jsxs("button",{type:"button",onClick:f,className:"px-1.5 py-0.5 rounded text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 tabular-nums min-w-[3rem]",title:"Reset zoom",children:[Math.round(i*100),"%"]}),o.jsx("button",{type:"button",onClick:u,disabled:i>=4,className:"px-1.5 py-0.5 rounded text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-40",title:"Zoom in",children:"+"}),o.jsx("button",{type:"button",onClick:()=>c(v=>!v),className:"ml-1 px-1.5 py-0.5 rounded text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800",title:l?"Exit fullscreen (Esc)":"Fullscreen",children:l?"⤢":"⛶"}),t?o.jsx("button",{type:"button",onClick:t,className:"ml-1 px-1.5 py-0.5 rounded text-gray-600 dark:text-gray-300 hover:bg-red-50 dark:hover:bg-red-900/30 hover:text-red-600 dark:hover:text-red-400",title:"Clear all canvases (hides them; messages preserved)",children:"✕"}):null]})]}),y=o.jsxs("div",{className:"flex-1 overflow-auto p-3",children:[g.title?o.jsx("div",{className:"text-sm font-semibold text-gray-700 dark:text-gray-200 mb-2",children:g.title}):null,o.jsx("div",{style:{transform:`scale(${i})`,transformOrigin:"top left",width:i===1?"100%":`${100/i}%`},children:o.jsx(RG,{canvas:g})}),g.caption?o.jsx("div",{className:"mt-2 text-xs text-gray-500 dark:text-gray-400 italic",children:g.caption}):null]});return l?o.jsxs("div",{className:"fixed inset-0 z-50 bg-white dark:bg-gray-900 flex flex-col",children:[m,y]}):o.jsxs("div",{className:"h-full flex flex-col",children:[m,y]})}function MG(e){return e?e.includes("/")?e.split("/").slice(1).join("/")||null:e:null}function IG(e,t){const n=MG(e);return{modelID:n||t||null,activeModelID:n,conversationModelID:t}}const Jb={"github-copilot":"GitHub Copilot",anthropic:"Anthropic",openai:"OpenAI",google:"Google",other:"Other"};function ev(e){return e==="recommended"?" — Recommended":e==="fast"?" — Fast":e==="premium"?" — Premium":""}function tv(e){const t={};return e.forEach(n=>{const r=n.provider||"other";t[r]||(t[r]=[]),t[r].push(n)}),t}const AS={"claude-opus-4.5":2e5,"claude-opus-4.6":2e5,"claude-sonnet-4":2e5,"claude-sonnet-4.5":2e5,"claude-sonnet-4.6":2e5,"gpt-4o":128e3,"gpt-4.1":1047576,"gpt-4-turbo":128e3,"gpt-4":8192,o1:2e5,"o1-mini":128e3,o3:2e5,"o3-mini":2e5},LG=128e3;function O0(e){const[t,n]=h.useState(e),r=h.useRef(e),a=h.useRef(0),i=h.useRef(0);return h.useEffect(()=>{if(e===r.current)return;a.current=0,r.current=t;const s=400,l=t,c=e,u=d=>{a.current||(a.current=d);const f=d-a.current,p=Math.min(f/s,1),g=1-Math.pow(1-p,3);n(Math.round(l+(c-l)*g)),p<1?i.current=requestAnimationFrame(u):n(c)};return i.current=requestAnimationFrame(u),()=>cancelAnimationFrame(i.current)},[e]),t}function OG({messages:e,isBusy:t,activeModel:n,sessionModel:r,isPrivateMode:a,registryEntries:i}){var K,W;var{t:s}=vt();const l=e.filter(j=>{var U;return((U=j.info)==null?void 0:U.role)==="user"}).length,c=e.filter(j=>{var U;return((U=j.info)==null?void 0:U.role)==="assistant"}).length;let u=0,d=0,f=0,p=null,g=null;for(let j=e.length-1;j>=0;j--){const U=e[j];if(((K=U.info)==null?void 0:K.role)==="assistant"&&((W=U.info)==null?void 0:W.mode)!=="compaction"){const le=U.info.tokens;if(le&&(le.input||le.output)){!p&&U.info.modelID&&(p=U.info.modelID),u=le.lastInput??le.input??0,d=le.lastOutput??le.output??0,f=le.lastReasoning??le.reasoning??0,U.info.contextLimit&&(g=U.info.contextLimit);break}}}const m=O0(u),y=O0(d),v=O0(f),x=m+y+v,b=u+d+f>0;let k=n;typeof r=="string"&&r?k=r:r&&r.providerID&&r.modelID&&(k=r.providerID+"/"+r.modelID);let{modelID:N,activeModelID:w}=IG(k,p),_=null;if(a){N="privacy",w="privacy";let j=null;typeof r=="string"&&r?j=r.includes("/")?r.split("/").pop():r:r&&r.modelID&&(j=r.modelID),_=j||(n?String(n).split("/").pop():null)}else p&&w&&p!==w&&(_=p);const T=h.useMemo(()=>{const j={};if(i&&i.length>0){for(const U of i)if(U.limit&&typeof U.limit.context=="number"&&U.limit.context>0){j[U.key]=U.limit.context;const le=U.key.includes("/")?U.key.split("/").pop():U.key;le&&(j[le]=U.limit.context)}}return j},[i]),A=p||N,R=!!(p&&w&&p!==w)&&(T[k]||T[N]||AS[N])||g||T[A]||T[k]||AS[A]||LG,$=Math.min(100,Math.round(m/R*100));let F="bg-green-500";$>=90?F="bg-red-500":$>=75?F="bg-orange-500":$>=50&&(F="bg-yellow-500");const G="border-gray-200 dark:border-gray-800",P="text-gray-500 dark:text-gray-400",M="text-gray-500 dark:text-gray-400",S="text-gray-700 dark:text-gray-300",I="border-gray-100 dark:border-gray-800";return o.jsxs("div",{className:`p-4 border-t ${G}`,children:[o.jsx("p",{className:`text-xs ${P} uppercase tracking-wide font-medium mb-3`,children:s("token_usage.session_info")}),o.jsxs("div",{className:"space-y-2",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:`text-xs ${M}`,children:s("token_usage.messages")}),o.jsx("span",{className:`text-xs font-medium ${S}`,children:l+c})]}),N&&o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:`text-xs ${M}`,children:s("token_usage.model")}),o.jsx("span",{className:`text-xs font-medium ${S} truncate ml-2 max-w-[140px]`,children:RS(N)})]}),_&&o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:`text-xs ${M}`,children:s("token_usage.originally")}),o.jsx("span",{className:`text-xs ${M} truncate ml-2 max-w-[140px]`,children:RS(_)})]}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:`text-xs ${M}`,children:s("token_usage.status")}),o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("div",{className:`w-1.5 h-1.5 rounded-full ${t?"bg-accent-400 animate-pulse":"bg-green-500"}`}),o.jsx("span",{className:`text-xs font-medium ${S}`,children:s(t?"token_usage.generating":"token_usage.idle")})]})]}),b?o.jsx(o.Fragment,{children:o.jsxs("div",{className:`border-t ${I} pt-2 mt-2`,children:[o.jsxs("div",{className:"mb-2",children:[o.jsxs("div",{className:"flex items-center justify-between mb-1",children:[o.jsx("span",{className:`text-xs ${M}`,children:"Context"}),o.jsxs("span",{className:`text-xs ${M}`,children:[$,"% of ",(R/1e3).toFixed(0),"k"]})]}),o.jsx("div",{className:"h-1.5 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden",children:o.jsx("div",{className:`h-full ${F} transition-all duration-300`,style:{width:`${$}%`}})})]}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:`text-xs ${M}`,children:"Input"}),o.jsx("span",{className:`text-xs font-medium ${S} tabular-nums`,children:m.toLocaleString()})]}),o.jsxs("div",{className:"flex items-center justify-between mt-1",children:[o.jsx("span",{className:`text-xs ${M}`,children:"Output"}),o.jsx("span",{className:`text-xs font-medium ${S} tabular-nums`,children:y.toLocaleString()})]}),f>0&&o.jsxs("div",{className:"flex items-center justify-between mt-1",children:[o.jsx("span",{className:`text-xs ${M}`,children:"Reasoning"}),o.jsx("span",{className:`text-xs font-medium ${S} tabular-nums`,children:v.toLocaleString()})]}),o.jsxs("div",{className:`flex items-center justify-between mt-1 pt-1 border-t ${I}`,children:[o.jsx("span",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:"Total"}),o.jsx("span",{className:"text-xs font-semibold text-gray-900 dark:text-gray-100 tabular-nums",children:x.toLocaleString()})]})]})}):o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:`text-xs ${M}`,children:"Tokens"}),o.jsx("span",{className:`text-xs ${M}`,children:"--"})]})]})]})}function RS(e){return e?{"claude-opus-4.5":"Claude Opus 4.5","claude-opus-4.6":"Claude Opus 4.6","claude-sonnet-4":"Claude Sonnet 4","claude-sonnet-4.5":"Claude Sonnet 4.5","claude-sonnet-4.6":"Claude Sonnet 4.6","gpt-4o":"GPT-4o","gpt-4.1":"GPT-4.1","gpt-4-turbo":"GPT-4 Turbo","gpt-4":"GPT-4"}[e]||e:""}function DG({sessionModel:e,activeModel:t,registryEntries:n,onModelChange:r,disabled:a,lockedReason:i}){const{t:s}=vt(),[l,c]=h.useState(!1),u=h.useRef(null),[d,f]=h.useState(-1),p=h.useRef([]);h.useEffect(()=>{if(!l)return;function b(k){u.current&&!u.current.contains(k.target)&&c(!1)}return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[l]),h.useEffect(()=>{if(!l)return;function b(k){if(k.key==="Escape"){c(!1);return}k.key!=="ArrowDown"&&k.key!=="ArrowUp"&&k.key!=="Home"&&k.key!=="End"||(k.preventDefault(),f(N=>{const w=p.current.length;if(!w)return N;const _=typeof N=="number"?N:-1;let T=_;return k.key==="ArrowDown"?T=_<w-1?_+1:0:k.key==="ArrowUp"?T=_>0?_-1:w-1:k.key==="Home"?T=0:k.key==="End"&&(T=w-1),p.current[T]&&p.current[T].focus(),T}))}return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[l]);const g=typeof e=="string"&&e.trim()?e.trim():null,m=g!=null,y=Array.isArray(n)?n:[],v=PG(g,t,y,s),x=h.useCallback(b=>{r(b===t||g&&g===b?null:b),c(!1)},[g,t,r]);return p.current.length=y.length,o.jsxs("div",{className:"relative",ref:u,children:[o.jsxs("button",{type:"button",onClick:()=>c(b=>!b),disabled:a,className:"flex items-center gap-1.5 px-2 py-1 text-xs font-medium rounded-md transition-colors "+(m||v?"bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400 hover:bg-primary-200 dark:hover:bg-primary-900/50":"text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800")+(a?" opacity-50 cursor-not-allowed":" cursor-pointer"),title:i||s("model_selector.title"),"aria-label":i||s("model_selector.title"),"aria-haspopup":"menu","aria-expanded":l,children:[i?o.jsxs("svg",{className:"w-3.5 h-3.5 flex-shrink-0 text-emerald-600 dark:text-emerald-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 11c.667 0 2 .4 2 2v3a2 2 0 11-4 0v-3c0-1.6 1.333-2 2-2zM6 11V8a6 6 0 1112 0v3"}),o.jsx("rect",{x:"5",y:"11",width:"14",height:"10",rx:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}):o.jsx("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),o.jsx("span",{className:"max-w-[120px] truncate",children:v}),o.jsx("svg",{className:`w-3 h-3 transition-transform ${l?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]}),l&&o.jsxs("div",{className:"absolute left-0 sm:left-auto sm:right-0 top-full mt-1 w-64 max-w-[calc(100vw-1.5rem)] max-h-72 overflow-y-auto bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg z-50",role:"menu","aria-label":s("model_selector.list_label"),children:[y.length===0&&o.jsx("div",{className:"px-3 py-2 text-xs text-gray-400 dark:text-gray-500",children:s("model_selector.no_models")}),y.map((b,k)=>{const N=g===b.key,w=!!t&&(b.key===t||b.target===t||b.url===t),_=b.builtin?b.key:b.displayName||b.key;return o.jsxs("button",{type:"button",ref:T=>{p.current[k]=T},tabIndex:d===k?0:-1,role:"menuitemradio","aria-checked":N||!m&&w,onClick:()=>x(b.key),className:"w-full text-left px-3 py-2 text-xs transition-colors "+(N||!m&&w?"bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-400":"text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800"),children:[o.jsx("span",{className:"font-medium",children:_}),w&&o.jsxs("span",{className:"ml-1 text-gray-400 dark:text-gray-500",children:["(",s("model_selector.default_label"),")"]})]},b.key)})]})]})}function PG(e,t,n,r){return e?MS(e,n):t?MS(t,n):r("model_selector.default_label")}function FG(e,t){if(!e||!Array.isArray(t))return null;for(let n=0;n<t.length;n++){const r=t[n];if(r&&(r.key===e||r.target===e||r.url===e))return r}return null}function MS(e,t){if(!e)return"";const n=FG(e,t);return n?n.builtin?n.key:n.displayName||n.key:typeof e=="string"&&e.includes("/")?e.split("/").slice(1).join("/"):e}function BG(e){e.sessionId;var t=e.disabledSkills,n=e.onToggle,r=e.onResetToDefaults,a=e.t,i=e.disabled,s=h.useState(!1),l=s[0],c=s[1],u=h.useState([]),d=u[0],f=u[1],p=h.useState(!1),g=p[0],m=p[1],y=h.useRef(null),v=t instanceof Array?new Set(t):new Set,x=h.useCallback(async function(){m(!0);try{var _=await Rb();f(_||[])}catch{}finally{m(!1)}},[]);h.useEffect(function(){x()},[x]),h.useEffect(function(){if(!l)return;function _(T){y.current&&!y.current.contains(T.target)&&c(!1)}return document.addEventListener("mousedown",_),function(){document.removeEventListener("mousedown",_)}},[l]);var b=v.size,k=v.has("agent"),N=k?b-1:b,w=Math.max(0,d.length-N+(k?0:1));return o.jsxs("div",{className:"relative",ref:y,children:[o.jsxs("button",{onClick:function(){c(!l)},disabled:i,className:"p-1.5 rounded-lg transition-colors "+(b>0?"bg-amber-500/10 text-amber-600 dark:text-amber-400":"text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800")+(i?" opacity-50 cursor-not-allowed":""),title:a("skills.toggle_title"),"aria-label":a("skills.toggle_title"),children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11 4a2 2 0 114 0v1a1 1 0 001 1h3a1 1 0 011 1v3a1 1 0 01-1 1h-1a2 2 0 100 4h1a1 1 0 011 1v3a1 1 0 01-1 1h-3a1 1 0 01-1-1v-1a2 2 0 10-4 0v1a1 1 0 01-1 1H7a1 1 0 01-1-1v-3a1 1 0 00-1-1H4a2 2 0 110-4h1a1 1 0 001-1V7a1 1 0 011-1h3a1 1 0 001-1V4z"})}),w>0&&o.jsx("span",{className:"absolute -top-1 -right-1 w-4 h-4 text-[9px] font-bold flex items-center justify-center bg-primary-500 text-white rounded-full",children:w})]}),l&&o.jsxs("div",{className:"absolute left-0 sm:left-auto sm:right-0 top-full mt-1 w-64 max-w-[calc(100vw-1.5rem)] bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg z-50 max-h-80 overflow-y-auto",children:[o.jsxs("div",{className:"px-3 py-2 border-b border-gray-100 dark:border-gray-800",children:[o.jsx("p",{className:"text-xs font-semibold text-gray-700 dark:text-gray-300",children:a("skills.toggle_header")}),o.jsx("p",{className:"text-[10px] text-gray-400 dark:text-gray-500 mt-0.5",children:a("skills.toggle_hint")})]}),g?o.jsx("div",{className:"flex items-center justify-center py-4",children:o.jsx("div",{className:"w-5 h-5 border-2 border-primary-500 border-t-transparent rounded-full animate-spin"})}):d.length===0?o.jsx("div",{className:"px-3 py-4 text-center",children:o.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500",children:a("skills.no_skills")})}):o.jsx("div",{className:"py-1",children:d.map(function(_){var T=v.has(_.name);return o.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 hover:bg-gray-50 dark:hover:bg-gray-800/50",children:[o.jsx("span",{className:"text-xs text-gray-700 dark:text-gray-300 truncate flex-1 mr-2",children:_.name}),o.jsx("button",{onClick:function(){n(_.name,T)},className:"relative inline-flex h-5 w-9 items-center rounded-full transition-colors flex-shrink-0 "+(T?"bg-gray-300 dark:bg-gray-600":"bg-primary-500"),role:"switch","aria-checked":!T,children:o.jsx("span",{className:"inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform "+(T?"translate-x-1":"translate-x-5")})})]},_.name)})}),o.jsx("div",{className:"px-3 py-1.5 border-t border-gray-100 dark:border-gray-800",children:o.jsx("p",{className:"text-[10px] font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wide",children:a("skills.builtin_tools")})}),o.jsx("div",{className:"py-1",children:o.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 hover:bg-gray-50 dark:hover:bg-gray-800/50",children:[o.jsx("span",{className:"text-xs text-gray-700 dark:text-gray-300 truncate flex-1 mr-2",children:a("skills.agent_comm")}),o.jsx("button",{onClick:function(){n("agent",k)},className:"relative inline-flex h-5 w-9 items-center rounded-full transition-colors flex-shrink-0 "+(k?"bg-gray-300 dark:bg-gray-600":"bg-primary-500"),role:"switch","aria-checked":!k,children:o.jsx("span",{className:"inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform "+(k?"translate-x-1":"translate-x-5")})})]})}),r&&o.jsx("div",{className:"px-3 py-1.5 border-t border-gray-100 dark:border-gray-800",children:o.jsx("button",{onClick:r,className:"w-full text-xs font-medium text-gray-500 dark:text-gray-400 hover:text-primary-600 dark:hover:text-primary-400 hover:underline transition-colors text-center",children:a("skills.reset_to_defaults")})})]})]})}function zG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M14.25 6.087c0-.355.186-.676.401-.959.221-.29.349-.634.349-1.003 0-1.036-1.007-1.875-2.25-1.875S10.5 3.089 10.5 4.125c0 .369.128.713.349 1.003.215.283.401.604.401.959V6a.75.75 0 01-.75.75H7.5a.75.75 0 00-.75.75v2.25c0 .414-.336.75-.75.75S5.25 10.164 5.25 9.75V9A2.25 2.25 0 003 11.25v.75a.75.75 0 00.75.75h2.25c.414 0 .75.336.75.75s-.336.75-.75.75H3.75a.75.75 0 00-.75.75v.75A2.25 2.25 0 005.25 18h1.5a.75.75 0 01.75.75v.75c0 .414.336.75.75.75h6a.75.75 0 00.75-.75v-.75a.75.75 0 01.75-.75h1.5A2.25 2.25 0 0019.5 15.75v-.75a.75.75 0 00-.75-.75h-2.25a.75.75 0 01-.75-.75c0-.414.336-.75.75-.75h2.25a.75.75 0 00.75-.75v-.75A2.25 2.25 0 0017.25 9h-3a.75.75 0 01-.75-.75V6.087z"})})}function UG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M20 18h-2V9.25L12 13 6 9.25V18H4V6h1.2l6.8 4.25L18.8 6H20m0-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2z"})})}function qG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M7.71 3.5l-5.71 9.94 3.48 6.06h5.44L4.07 8.56 7.71 3.5zm1.42 0L15.84 15h-6.71L2.42 3.5h6.71zm.71 12h11.46l-3.48 6.06H6.36l3.48-6.06zm.71-1L16.84 3.5l5.71 9.94-3.48.06H10.55z"})})}function $G({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M20.317 4.37a19.791 19.791 0 00-4.885-1.515.074.074 0 00-.079.037c-.21.375-.444.864-.608 1.25a18.27 18.27 0 00-5.487 0 12.64 12.64 0 00-.617-1.25.077.077 0 00-.079-.037A19.736 19.736 0 003.677 4.37a.07.07 0 00-.032.027C.533 9.046-.32 13.58.099 18.057a.082.082 0 00.031.057 19.9 19.9 0 005.993 3.03.078.078 0 00.084-.028c.462-.63.874-1.295 1.226-1.994a.076.076 0 00-.041-.106 13.107 13.107 0 01-1.872-.892.077.077 0 01-.008-.128 10.2 10.2 0 00.372-.292.074.074 0 01.077-.01c3.928 1.793 8.18 1.793 12.062 0a.074.074 0 01.078.01c.12.098.246.198.373.292a.077.077 0 01-.006.127 12.299 12.299 0 01-1.873.892.077.077 0 00-.041.107c.36.698.772 1.362 1.225 1.993a.076.076 0 00.084.028 19.839 19.839 0 006.002-3.03.077.077 0 00.032-.054c.5-5.177-.838-9.674-3.549-13.66a.061.061 0 00-.031-.03zM8.02 15.33c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.956-2.419 2.157-2.419 1.21 0 2.176 1.096 2.157 2.42 0 1.333-.956 2.418-2.157 2.418zm7.975 0c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.955-2.419 2.157-2.419 1.21 0 2.176 1.096 2.157 2.42 0 1.333-.946 2.418-2.157 2.418z"})})}function HG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"})})}function WG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M3 6l3.5 12h2l2.5-8 2.5 8h2L19 6h-2.5l-2.25 8L12 6h-2l-2.25 8L5.5 6H3z"})})}function VG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M5 3a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2V5a2 2 0 00-2-2H5zm11.293 6.707l-5.5 5.5a1 1 0 01-1.414 0l-2.5-2.5a1 1 0 111.414-1.414L10.086 13.1l4.793-4.793a1 1 0 111.414 1.4z"})})}function GG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M4 18V6h3.2l2.8 7 2.8-7H16v12h-2.4V9.6L10.6 18H9.4L6.4 9.6V18H4z"})})}function KG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 15.5v-5l-3 3v-4l3-3v-3l4 4-4 4v4z"})})}function YG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})})}function QG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"})})}function XG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M6 2l6 3.75L6 9.5.002 5.75 6 2zm12 0l6 3.75-6 3.75-5.998-3.75L18 2zM.002 13.25L6 9.5l6 3.75L6 17 .002 13.25zm17.998-3.75l6 3.75L18 17l-5.998-3.75L18 9.5zM6 18.25l6-3.75 6 3.75-6 3.75-6-3.75z"})})}function ZG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6v12m-3-2.818l.879.659c1.171.879 3.07.879 4.242 0 1.172-.879 1.172-2.303 0-3.182C13.536 12.219 12.768 12 12 12c-.725 0-1.45-.22-2.003-.659-1.106-.879-1.106-2.303 0-3.182s2.9-.879 4.006 0l.415.33M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}function JG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 012.25-2.25h13.5A2.25 2.25 0 0121 7.5v11.25m-18 0A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75m-18 0v-7.5A2.25 2.25 0 015.25 9h13.5A2.25 2.25 0 0121 11.25v7.5"})})}function eK({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})})}const IS={gmail:UG,gdrive:qG,discord:$G,whatsapp:HG,wrike:WG,gtasks:VG,mailchimp:GG,bamboohr:KG,pandadoc:YG,exa:QG,dropbox:XG,freshbooks:ZG,gcal:JG,docx2md:eK};function tK(e){return Object.prototype.hasOwnProperty.call(IS,e)?IS[e]:zG}const LS={gmail:"#EA4335",gdrive:"#4285F4",discord:"#5865F2",whatsapp:"#25D366",wrike:"#08CF65",gtasks:"#4285F4",mailchimp:"#FFE01B",bamboohr:"#73C41D",pandadoc:"#4ABB5A",exa:"#6366F1",dropbox:"#0061FF",freshbooks:"#00B7E3",gcal:"#4285F4",docx2md:"#6B7280"};function nK({installed:e,configured:t,t:n}){return e?t?o.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",children:[o.jsx("svg",{className:"w-3 h-3 mr-1",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}),n("skills.configured")]}):o.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-400",children:[o.jsx("svg",{className:"w-3 h-3 mr-1",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})}),n("skills.needs_setup")]}):o.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-gray-100 dark:bg-gray-800 text-gray-500 dark:text-gray-400",children:n("skills.not_installed")})}function rK({skill:e,onClose:t,onSaved:n}){var{t:r}=vt(),a=dl(),[i,s]=h.useState({}),[l,c]=h.useState(!0),[u,d]=h.useState(!1),[f,p]=h.useState(null),[g,m]=h.useState(!1),[y,v]=h.useState(null);h.useEffect(function(){var A=!1;async function D(){try{var R=await uB(e.name);if(A)return;v(R);for(var $=Object.create(null),F=Object.keys(R.tokens||{}),G=0;G<F.length;G++){var P=F[G],M=R.tokens[P]||{},S=M.env||P;$[S]=""}s($),c(!1)}catch(I){A||(p(I.message),c(!1))}}return D(),function(){A=!0}},[e.name]);var x=h.useMemo(function(){if(!y||!y.tokens)return null;for(var A=Object.keys(y.tokens),D=0;D<A.length;D++){var R=y.tokens[A[D]]||{};if(R.description&&R.description.includes("OAuth")){for(var $=null,F=null,G=null,P=Object.entries(y.tokens),M=0;M<P.length;M++){var S=P[M][0];S.includes("REFRESH_TOKEN")&&($=S),(S.includes("CLIENT_ID")||S.includes("APP_KEY"))&&(F=S),(S.includes("CLIENT_SECRET")||S.includes("APP_SECRET"))&&(G=S)}if($&&F){var I=y.tokens[$]&&y.tokens[$].configured,B=y.tokens[F]&&y.tokens[F].configured,Q=G&&y.tokens[G]&&y.tokens[G].configured,C="OAuth";return e.name==="gmail"||e.name==="gdrive"||e.name==="gcal"||e.name==="gtasks"?C="Google":e.name==="dropbox"?C="Dropbox":e.name==="freshbooks"&&(C="FreshBooks"),{provider:C,canConnect:B&&Q&&!I,refreshConfigured:I,clientIdConfigured:B,clientSecretConfigured:Q}}}}return null},[y,e.name]),b=h.useCallback(async function(){p(null),m(!0);try{var A=await xB(e.name),D=600,R=700,$=(window.screen.width-D)/2,F=(window.screen.height-R)/2,G=window.open(A.authorizeUrl,"oauth_popup","width="+D+",height="+R+",left="+$+",top="+F+",scrollbars=yes");if(G)var P=setInterval(function(){G.closed&&(clearInterval(P),m(!1),n())},500);else p("Popup blocked. Please allow popups or visit: "+A.authorizeUrl),m(!1)}catch(M){p(M.message),m(!1)}},[e.name,n]),k=h.useCallback(async function(){p(null),d(!0);try{for(var A=Object.create(null),D=Object.keys(i),R=0;R<D.length;R++){var $=D[R];i[$]&&i[$].trim()&&(A[$]=i[$].trim())}if(Object.keys(A).length===0){p(r("skills.enter_token")),d(!1);return}await gB(e.name,A),n()}catch(F){p(F.message)}finally{d(!1)}},[i,e.name,n,r]),N=h.useCallback(async function(){if(await a({title:r("skills.clear_title"),message:r("skills.clear_confirm",{skill:e.name}),destructive:!0})){p(null),d(!0);try{await hB(e.name),n()}catch(A){p(A.message)}finally{d(!1)}}},[e.name,n,a,r]),w=h.useCallback(function(A,D){s(function(R){var $=Object.assign(Object.create(null),R);return $[A]=D,$})},[]),_=y?Object.entries(y.tokens||{}).map(function(A){var D=A[0],R=A[1],$=R&&R.env||D;return{name:D,env:$,description:R.description,configured:R.configured,maskedValue:R.maskedValue}}):[],T=h.useRef(null);return h.useEffect(function(){function A(D){D.key==="Escape"&&t()}return document.addEventListener("keydown",A),T.current&&T.current.focus(),function(){document.removeEventListener("keydown",A)}},[t]),o.jsx("div",{ref:T,tabIndex:-1,className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:t,role:"dialog","aria-modal":"true","aria-label":r("skills.configure_skill",{skill:e.name}),children:o.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-xl shadow-2xl w-full max-w-lg mx-4 p-6",onClick:function(A){A.stopPropagation()},children:[o.jsxs("div",{className:"flex items-center justify-between mb-4",children:[o.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:r("skills.configure_skill",{skill:e.name})}),o.jsx("button",{onClick:t,className:"p-1 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-400","aria-label":r("skills.close_credential_editor"),children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),l&&o.jsx("div",{className:"flex items-center justify-center py-8",children:o.jsx("div",{className:"w-6 h-6 border-2 border-primary-500 border-t-transparent rounded-full animate-spin"})}),!l&&_.length>0&&o.jsx("div",{className:"space-y-3 mb-4",children:_.map(function(A){return o.jsxs("div",{children:[o.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:[A.env,A.configured&&o.jsxs("span",{className:"ml-2 text-xs text-green-600 dark:text-green-400",children:["(",r("skills.current_value",{value:A.maskedValue}),")"]})]}),A.description&&o.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1",children:A.description}),o.jsx("input",{type:"password",placeholder:A.configured?r("skills.leave_blank"):r("skills.enter_value"),value:i[A.env]||"",onChange:function(D){w(A.env,D.target.value)},className:"w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 placeholder-gray-400"})]},A.env)})}),!l&&x&&o.jsx("div",{className:"mb-4 p-4 bg-gray-50 dark:bg-gray-800/50 rounded-lg border border-gray-200 dark:border-gray-700",children:x.canConnect?o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-3",children:r("skills.oauth_connect_hint",{provider:x.provider})}),o.jsx("button",{onClick:b,disabled:g||u,className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-primary-500 hover:bg-primary-600 text-white font-medium rounded-lg disabled:opacity-50 transition-colors",children:g?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}),r("skills.oauth_connecting")]}):o.jsxs(o.Fragment,{children:[o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"})}),r("skills.oauth_connect",{provider:x.provider})]})})]}):x.refreshConfigured?o.jsxs("p",{className:"text-sm text-green-600 dark:text-green-400 flex items-center gap-2",children:[o.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}),r("skills.oauth_connected",{provider:x.provider})]}):o.jsx("p",{className:"text-sm text-amber-600 dark:text-amber-400",children:r("skills.oauth_needs_credentials",{provider:x.provider})})}),!l&&!f&&_.length===0&&o.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 py-4",children:r("skills.no_credentials_needed")}),f&&o.jsx("p",{className:"text-sm text-red-600 dark:text-red-400 mb-3",children:f}),!l&&_.length>0&&o.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-gray-200 dark:border-gray-700",children:[o.jsx("button",{onClick:N,disabled:u,className:"text-sm text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 disabled:opacity-50",children:r("skills.clear_all")}),o.jsxs("div",{className:"flex gap-2",children:[o.jsx("button",{onClick:t,className:"px-3 py-1.5 text-sm text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg",children:r("skills.cancel")}),o.jsx("button",{onClick:k,disabled:u,className:"px-4 py-1.5 text-sm font-medium bg-primary-500 hover:bg-primary-600 text-white rounded-lg disabled:opacity-50 transition-colors",children:r(u?"skills.saving":"skills.save")})]})]})]})})}function aK({skill:e,installed:t,updateInfo:n,updatingSkill:r,onConfigure:a,onInstall:i,onUpdate:s,onUninstall:l,skillDefaultEnabled:c,onToggleDefault:u,t:d}){var f=tK(e.name),p=Object.prototype.hasOwnProperty.call(LS,e.name)?LS[e.name]:"#6B7280",[g,m]=h.useState(!1),y=r===e.name,v=n&&n.hasUpdate,x=h.useCallback(async function(){m(!0);try{await i(e)}finally{m(!1)}},[e,i]),b=h.useCallback(function(){s&&s(e.name)},[e.name,s]);return o.jsxs("div",{className:"group relative bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-xl p-4 hover:shadow-md dark:hover:shadow-gray-800/50 transition-all flex flex-col",children:[o.jsx("div",{className:"absolute top-0 left-4 right-4 h-0.5 rounded-full",style:{backgroundColor:p}}),o.jsxs("div",{className:"flex items-start gap-3 mt-1 flex-1",children:[o.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center flex-shrink-0",style:{backgroundColor:p+"15"},children:o.jsx(f,{className:"w-5 h-5",style:{color:p}})}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[o.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100 truncate",children:e.name}),o.jsx(nK,{installed:t,configured:t&&e.allTokensConfigured,t:d}),t&&v&&o.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400",children:[o.jsx("svg",{className:"w-3 h-3 mr-1",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),"v",n.latestVersion]}),t&&n&&!v&&o.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",children:d("skills.up_to_date")})]}),o.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 line-clamp-2",children:e.description||d("skills.no_description")}),e.version&&o.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:["v",e.version]})]})]}),o.jsx("div",{className:"mt-auto pt-3 flex items-center gap-2",children:t?o.jsxs(o.Fragment,{children:[o.jsx("button",{onClick:function(){a(e)},className:"flex-1 px-3 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-lg transition-colors",children:d("skills.configure")}),u&&o.jsxs("button",{onClick:function(){u(e.name,!c)},title:d("skills.default_for_new_sessions"),className:"px-2 py-1.5 text-xs font-medium rounded-lg transition-colors flex items-center gap-1 "+(c?"text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20 hover:bg-primary-100 dark:hover:bg-primary-900/40":"text-gray-400 dark:text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-800"),children:[o.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:c?o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"}):o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),d("skills.default")]}),v&&o.jsx("button",{onClick:b,disabled:y,className:"px-3 py-1.5 text-xs font-medium text-white bg-primary-500 hover:bg-primary-600 rounded-lg transition-colors disabled:opacity-50",children:y?o.jsxs("span",{className:"flex items-center gap-1",children:[o.jsx("svg",{className:"w-3 h-3 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),d("skills.updating")]}):d("skills.update")}),l&&o.jsx("button",{onClick:function(){l(e)},title:d("skills.uninstall"),className:"px-2 py-1.5 text-xs font-medium text-gray-400 hover:text-red-500 dark:hover:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 rounded-lg transition-colors","aria-label":d("skills.uninstall"),children:o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]}):o.jsx("button",{onClick:x,disabled:g,className:"flex-1 px-3 py-1.5 text-xs font-medium text-white bg-primary-500 hover:bg-primary-600 rounded-lg transition-colors disabled:opacity-50",children:g?o.jsxs("span",{className:"flex items-center justify-center gap-1",children:[o.jsx("svg",{className:"w-3 h-3 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),d("skills.installing")]}):d("skills.install")})})]})}function iK({onBack:e}){var{t}=vt(),[n,r]=h.useState([]),[a,i]=h.useState([]),[s,l]=h.useState(!0),[c,u]=h.useState(null),[d,f]=h.useState(null),[p,g]=h.useState("all"),[m,y]=h.useState(""),[v,x]=h.useState(!1),[b,k]=h.useState(Object.create(null)),[N,w]=h.useState(null),[_,T]=h.useState(!1),[A,D]=h.useState(Object.create(null)),R=dl(),$=h.useCallback(async function(){l(!0),u(null),T(!1);try{var U=await Promise.allSettled([Rb(),cB(),eT()]),le=U[0].status==="fulfilled"?U[0].value:[],Z=U[1].status==="fulfilled"?U[1].value:[],ke=U[2].status==="fulfilled"?U[2].value.skillDefaults||{}:{};r(le),i(Z),D(ke);var re=[];U[0].status==="rejected"&&re.push(t("skills.load_installed_failed",{error:U[0].reason.message})),U[1].status==="rejected"&&re.push(t("skills.load_marketplace_failed",{error:U[1].reason.message})),re.length>0&&u(re.join("; "))}catch(X){u(X.message)}finally{l(!1)}},[t]);h.useEffect(function(){$()},[$]);var F=[],G=new Set(n.map(function(U){return U.name}));n.forEach(function(U){F.push(Object.assign({},U,{_installed:!0}))}),a.forEach(function(U){G.has(U.name)||F.push(Object.assign({},U,{_installed:!1,allTokensConfigured:!1}))});var P=F;if(p==="installed"?P=F.filter(function(U){return U._installed}):p==="available"&&(P=F.filter(function(U){return!U._installed})),m){var M=m.toLowerCase();P=P.filter(function(U){return U.name&&U.name.toLowerCase().indexOf(M)!==-1||U.description&&U.description.toLowerCase().indexOf(M)!==-1||U.category&&U.category.toLowerCase().indexOf(M)!==-1})}var S=h.useCallback(async function(U){try{await dB(U.name),$()}catch(le){u(t("skills.install_failed",{error:le.message}))}},[$,t]),I=h.useCallback(function(U){f(U)},[]),B=h.useCallback(async function(U){if(await R({title:t("skills.uninstall_title"),message:t("skills.uninstall_confirm",{skill:U.name}),destructive:!0,confirmLabel:t("skills.uninstall")}))try{await mB(U.name),$()}catch(le){u(t("skills.uninstall_failed",{error:le.message}))}},[$,R,t]),Q=h.useCallback(function(){f(null),$()},[$]),C=h.useCallback(async function(U,le){D(function(ke){var re=Object.assign({},ke);return le?re[U]=!0:delete re[U],re});try{var Z={};Z[U]=le,await yB(Z)}catch(ke){D(function(re){var X=Object.assign({},re);return le?delete X[U]:X[U]=!0,X}),u(ke.message)}},[]),K=h.useCallback(async function(){x(!0),u(null);try{var U=await pB(),le=Object.create(null);(U.skills||[]).forEach(function(Z){le[Z.name]={hasUpdate:Z.hasUpdate,latestVersion:Z.latestVersion,currentVersion:Z.currentVersion}}),k(le),T(!0)}catch(Z){u(Z.message)}finally{x(!1)}},[]),W=h.useCallback(async function(U){w(U),u(null);try{var le=await fB(U);le.updated&&(k(function(Z){var ke=Object.assign(Object.create(null),Z);return ke[U]={hasUpdate:!1,latestVersion:Z[U]?Z[U].latestVersion:null,currentVersion:Z[U]?Z[U].currentVersion:null},ke}),$())}catch(Z){u(t("skills.update_failed")+": "+Z.message)}finally{w(null)}},[$,t]),j=Object.values(b).filter(function(U){return U&&U.hasUpdate}).length;return o.jsxs("div",{className:"h-full flex flex-col bg-white dark:bg-gray-950 min-h-0",children:[o.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between px-6 py-4 border-b border-gray-200 dark:border-gray-800",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("button",{onClick:e,className:"p-1.5 rounded-lg text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors","aria-label":t("skills.back_to_chat"),children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})})}),o.jsxs("div",{children:[o.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:t("skills.skill_management")}),o.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:t("skills.installed_count",{installed:n.length,available:a.filter(function(U){return!G.has(U.name)}).length})})]})]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("button",{onClick:K,disabled:v||s,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-gray-600 dark:text-gray-300 bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-lg transition-colors disabled:opacity-50",children:v?o.jsxs(o.Fragment,{children:[o.jsx("svg",{className:"w-3.5 h-3.5 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),t("skills.checking_updates")]}):o.jsxs(o.Fragment,{children:[o.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),t("skills.check_updates")]})}),j>0&&o.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400 rounded-full",children:t("skills.updates_available",{count:j})}),_&&j===0&&!v&&o.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 rounded-full",children:t("skills.no_updates")}),o.jsx("div",{className:"flex items-center gap-1 bg-gray-100 dark:bg-gray-800 rounded-lg p-0.5",children:["all","installed","available"].map(function(U){return o.jsx("button",{onClick:function(){g(U)},className:"px-3 py-1 text-xs font-medium rounded-md transition-colors "+(p===U?"bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 shadow-sm":"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300"),children:t("skills.tab_"+U)},U)})})]})]}),o.jsx("div",{className:"flex-shrink-0 px-6 py-3 border-b border-gray-100 dark:border-gray-800/50",children:o.jsxs("div",{className:"relative",children:[o.jsx("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),o.jsx("input",{type:"text",placeholder:t("skills.search_placeholder"),value:m,onChange:function(U){y(U.target.value)},className:"w-full pl-10 pr-4 py-2 text-sm bg-gray-50 dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg text-gray-900 dark:text-gray-100 placeholder-gray-400 outline-none focus:ring-2 focus:ring-primary-500/30 focus:border-primary-500"})]})}),o.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden p-6 min-h-0",children:[s&&o.jsx("div",{className:"flex items-center justify-center py-12",children:o.jsx("div",{className:"w-8 h-8 border-2 border-primary-500 border-t-transparent rounded-full animate-spin"})}),c&&o.jsx("div",{className:"mb-4 p-3 bg-red-50 dark:bg-red-900/20 rounded-lg border border-red-200 dark:border-red-800",children:o.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:c})}),!s&&P.length===0&&o.jsx("div",{className:"text-center py-12",children:o.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:t(m?"skills.no_match":"skills.no_skills")})}),!s&&P.length>0&&o.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:P.map(function(U){return o.jsx(aK,{skill:U,installed:U._installed,updateInfo:b[U.name],updatingSkill:N,onConfigure:I,onInstall:S,onUpdate:W,onUninstall:U._installed?B:null,skillDefaultEnabled:!!A[U.name],onToggleDefault:U._installed?C:null,t},U.name)})})]}),d&&o.jsx(rK,{skill:d,onClose:function(){f(null)},onSaved:Q})]})}const Pt="";function Ft(e,t={}){return fetch(e,{credentials:"include",...t})}async function sK(){const e=await Ft(Pt+"/api/agents");if(!e.ok)throw new Error("Failed to fetch agents: "+e.statusText);return e.json()}async function oK(e){const t=await Ft(Pt+"/api/agents/"+encodeURIComponent(e));if(!t.ok)throw new Error("Failed to fetch agent: "+t.statusText);return t.json()}async function lx(e){const t=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/start",{method:"POST"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error||"Failed to start agent")}return t.json()}async function cx(e){const t=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/stop",{method:"POST"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error||"Failed to stop agent")}return t.json()}async function Eu(e,t){const n={};t&&t.clean&&(n.clean=!0);const r=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok){const a=await r.json().catch(()=>({}));throw new Error(a.error||"Failed to restart agent")}return r.json()}async function ux(e,t){const n={};t&&t.level&&(n.level=t.level),t&&t.span&&(n.span=t.span);const r=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/pause",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok){const a=await r.json().catch(()=>({}));throw new Error(a.error||"Failed to pause agent")}return r.json()}async function dx(e){const t=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/unpause",{method:"POST"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error||"Failed to unpause agent")}return t.json()}async function lK(e,t,n,r){const a={message:t,priority:n};r!=null&&(a.replyToInbox=r);const i=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/inbox",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok){const s=await i.json().catch(()=>({}));throw new Error(s.error||"Failed to send message to agent")}return i.json()}async function cK(e,t,n){const r={message:t};n!=null&&(r.replyToInbox=n);const a=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/interrupt",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!a.ok){const i=await a.json().catch(()=>({}));throw new Error(i.error||"Failed to send urgent interrupt to agent")}return a.json()}async function uK(e,t){let n=Pt+"/api/agents/"+encodeURIComponent(e)+"/messages";t&&t.refresh&&(n+="?refresh=true");const r=await Ft(n);if(!r.ok)throw new Error("Failed to fetch agent messages: "+r.statusText);return r.json()}async function dK(){const e=await Ft(Pt+"/api/pricing");if(!e.ok)throw new Error("Failed to fetch pricing: "+e.statusText);return e.json()}async function fK(e){const t=await Ft(Pt+"/api/pricing",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error||"Failed to update pricing")}return t.json()}async function pK(){const e=await Ft(Pt+"/api/pricing/reset",{method:"POST"});if(!e.ok){const t=await e.json().catch(()=>({}));throw new Error(t.error||"Failed to reset pricing")}return e.json()}async function gK(e,t=!1){const n=Pt+"/api/agents/"+encodeURIComponent(e)+(t?"?force=true":""),r=await Ft(n,{method:"DELETE"});if(!r.ok){const a=await r.json().catch(()=>({}));throw new Error(a.error||"Failed to delete agent")}return r.json()}async function hK(e){const t=await Ft(Pt+"/api/agents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error||"Failed to create agent")}return t.json()}async function SA(){const e=await Ft(Pt+"/api/skills");if(!e.ok)throw new Error("Failed to fetch skills: "+e.statusText);return e.json()}async function nv(){const e=await Ft(Pt+"/api/models");if(!e.ok)throw new Error("Failed to fetch models: "+e.statusText);return e.json()}async function mK(e,t){const n=await Ft(Pt+"/api/agents/"+encodeURIComponent(e),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||"Failed to update agent")}return n.json()}async function yK(e){const t=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/agents-md");if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error||"Failed to fetch AGENTS.md")}return t.json()}async function xK(e,t){const n=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/agents-md",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||"Failed to update AGENTS.md")}return n.json()}async function CA(e){const t=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/export");if(!t.ok){const l=await t.json().catch(()=>({}));throw new Error(l.error||"Failed to export agent")}const n=await t.text(),r=new Blob([n],{type:"text/yaml"}),a=URL.createObjectURL(r),i=t.headers.get("X-Filename")||e+".agent.yaml",s=document.createElement("a");s.href=a,s.download=i,document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>URL.revokeObjectURL(a),5e3)}async function bK(e,t){const n=new URLSearchParams,r=n.toString()?"?"+n.toString():"",a=await Ft(Pt+"/api/agents/import"+r,{method:"POST",headers:{"Content-Type":"text/yaml"},body:e});if(!a.ok){const i=await a.json().catch(()=>({}));throw new Error(i.error||"Failed to import agent")}return a.json()}async function D0(){const e=await Ft(Pt+"/api/system/updates");if(!e.ok){const t="Failed to check for updates",n=await e.json().catch(()=>({})),r=n.error||n.message||n.output||e.statusText;throw r?r.indexOf(t)===0||r===t?new Error(r):new Error(t+": "+r):new Error(t)}return e.json()}async function vK(){const e=await Ft(Pt+"/api/system/update",{method:"POST"});if(!e.ok){const n="Failed to perform update",r=await e.json().catch(()=>({})),a=r.error||r.message||r.output||e.statusText;throw a?a.indexOf(n)===0||a===n?new Error(a):new Error(n+": "+a):new Error(n)}const t=await e.json();if(t.status!=="success"){let n=t.error||t.message||"";throw t.output&&!t.error&&!t.message?n="Update returned status: "+(t.status||"failed")+(t.output?": "+t.output:""):t.output&&(n+=t.output?" ("+t.output+")":""),n||(n="Update returned unexpected status: "+(t.status||"unknown")),new Error(n)}return t}async function OS(){const e=await Ft(Pt+"/api/models/registry");if(!e.ok)throw new Error("Failed to fetch model registry: "+e.statusText);return e.json()}async function DS(e,t){const n=await Ft(Pt+"/api/models/registry",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,...t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||"Failed to save model: "+n.statusText)}return n.json()}async function PS(e){const t=await Ft(Pt+"/api/models/registry/"+encodeURIComponent(e),{method:"DELETE"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error||"Failed to delete model: "+t.statusText)}return t.json()}function jA(e){const t=typeof e=="string"?e.split("-"):null;if(t&&t.length===3){const n=Number(t[0]),r=Number(t[1]),a=Number(t[2]);if(!Number.isNaN(n)&&!Number.isNaN(r)&&!Number.isNaN(a))return new Date(n,r-1,a)}return new Date(e)}function kK(e){const t=jA(e),n=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];return n[t.getDay()]+", "+r[t.getMonth()]+" "+t.getDate()}function bc(e){return e>=1e6?(e/1e6).toFixed(1)+"M":e>=1e3?(e/1e3).toFixed(1)+"K":e.toString()}function _K({data:e}){if(!e||e.length===0)return o.jsx("div",{className:"h-32 flex items-center justify-center text-sm text-gray-400 dark:text-gray-500",children:"No usage data available"});const t=280,n=120,r={top:10,right:10,bottom:25,left:40},a=t-r.left-r.right,i=n-r.top-r.bottom,s=Math.max(...e.map(p=>(p.input||0)+(p.output||0)+(p.cached||0)),1),l=a/e.length,c=Math.max(8,l*.6),u=(l-c)/2,d=p=>i-p/s*i,f=[0,.25,.5,.75,1].map(p=>Math.round(s*p));return o.jsxs("div",{className:"relative",children:[o.jsxs("svg",{width:"100%",height:n,viewBox:`0 0 ${t} ${n}`,className:"overflow-visible",children:[f.map((p,g)=>{const m=r.top+d(p);return o.jsxs("g",{children:[o.jsx("line",{x1:r.left,y1:m,x2:t-r.right,y2:m,stroke:"currentColor",strokeOpacity:.1,className:"text-gray-400 dark:text-gray-600"}),o.jsx("text",{x:r.left-5,y:m,textAnchor:"end",dominantBaseline:"middle",className:"text-[9px] fill-gray-400 dark:fill-gray-500",children:bc(p)})]},g)}),e.map((p,g)=>{const m=r.left+g*l+u,y=p.input||0,v=p.output||0,x=p.cached||0,b=y/s*i,k=v/s*i,N=x/s*i,w=r.top+i-b,_=w-k,T=_-N,A=jA(p.date),D=["S","M","T","W","T","F","S"][A.getDay()];return o.jsxs("g",{className:"group",children:[o.jsx("rect",{x:m-u,y:r.top,width:l,height:i,fill:"transparent",className:"cursor-pointer"}),y>0&&o.jsx("rect",{x:m,y:w,width:c,height:b,rx:2,className:"fill-blue-500 dark:fill-blue-400 transition-opacity group-hover:opacity-80"}),v>0&&o.jsx("rect",{x:m,y:_,width:c,height:k,rx:2,className:"fill-green-500 dark:fill-green-400 transition-opacity group-hover:opacity-80"}),x>0&&o.jsx("rect",{x:m,y:T,width:c,height:N,rx:2,className:"fill-purple-500 dark:fill-purple-400 transition-opacity group-hover:opacity-80"}),o.jsx("text",{x:m+c/2,y:n-5,textAnchor:"middle",className:"text-[9px] fill-gray-400 dark:fill-gray-500",children:D}),o.jsxs("g",{className:"opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none",children:[o.jsx("rect",{x:m+c/2-45,y:Math.min(T,_,w)-50,width:90,height:45,rx:4,className:"fill-gray-900 dark:fill-gray-100"}),o.jsx("text",{x:m+c/2,y:Math.min(T,_,w)-38,textAnchor:"middle",className:"text-[9px] fill-white dark:fill-gray-900 font-medium",children:kK(p.date)}),o.jsxs("text",{x:m+c/2,y:Math.min(T,_,w)-26,textAnchor:"middle",className:"text-[8px] fill-blue-300 dark:fill-blue-600",children:["In: ",bc(y)]}),o.jsxs("text",{x:m+c/2,y:Math.min(T,_,w)-16,textAnchor:"middle",className:"text-[8px] fill-green-300 dark:fill-green-600",children:["Out: ",bc(v)]}),o.jsxs("text",{x:m+c/2,y:Math.min(T,_,w)-6,textAnchor:"middle",className:"text-[8px] fill-purple-300 dark:fill-purple-600",children:["Cache: ",bc(x)]})]})]},g)})]}),o.jsxs("div",{className:"flex items-center justify-center gap-4 mt-2 text-xs",children:[o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx("div",{className:"w-2 h-2 rounded-sm bg-blue-500 dark:bg-blue-400"}),o.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Input"})]}),o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx("div",{className:"w-2 h-2 rounded-sm bg-green-500 dark:bg-green-400"}),o.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Output"})]}),o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx("div",{className:"w-2 h-2 rounded-sm bg-purple-500 dark:bg-purple-400"}),o.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Cached"})]})]})]})}function wK({agentName:e,onClose:t,onToolPartsChange:n,hackerMode:r}){var{t:a}=vt(),[i,s]=h.useState([]),[l,c]=h.useState(!0),[u,d]=h.useState(null),[f,p]=h.useState(!1),[g,m]=h.useState(""),[y,v]=h.useState(!0),[x,b]=h.useState(!1),[k,N]=h.useState(!1),[w,_]=h.useState(!1),[T,A]=h.useState(!1),D=h.useRef(null),R=h.useRef(null),$=h.useRef(!0),F=h.useRef([]),G=h.useRef(null),P=h.useRef(null),M=h.useRef(null),S=h.useRef(null);h.useEffect(function(){F.current=i},[i]);var I=h.useCallback(async function(Z,ke){if(e){ke!==!1&&c(!0);try{var re=await uK(e,{refresh:!!Z}),X=re.messages||[],Ne=F.current,ve=X.length!==Ne.length;if(!ve&&X.length>0&&Ne.length>0){var me=X[X.length-1],pe=Ne[Ne.length-1];if(me.info.id!==pe.info.id&&(ve=!0),!ve){var Le=me.parts||[],Se=pe.parts||[];if(Le.length!==Se.length)ve=!0;else for(var Te=0;Te<Le.length&&!ve;Te++){var Fe=Le[Te]||{},fe=Se[Te]||{},xe=Fe.state?Fe.state.status:Fe.status,Ce=fe.state?fe.state.status:fe.status;(Fe.id!==fe.id||xe!==Ce)&&(ve=!0)}}}ve&&s(X.slice()),d(null)}catch(ue){console.error("Failed to load messages:",ue),d(ue.message)}finally{ke!==!1&&c(!1)}}},[e]);h.useEffect(function(){I(!0);var Z=setInterval(function(){I(!0,!1)},5e3);return function(){clearInterval(Z),P.current&&clearTimeout(P.current),S.current&&clearTimeout(S.current)}},[I]),h.useEffect(function(){$.current&&D.current&&D.current.scrollIntoView({behavior:"smooth"})},[i]);var B=h.useCallback(function(){var Z=R.current;Z&&($.current=Z.scrollHeight-Z.scrollTop-Z.clientHeight<50)},[]),Q=h.useMemo(function(){for(var Z=null,ke=i.length-1;ke>=0;ke--)if(i[ke].info&&i[ke].info.role==="assistant"){Z=i[ke];break}return Z?(Z.parts||[]).filter(function(re){return re.type==="tool"}):[]},[i]);h.useEffect(function(){n&&n(Q)},[Q,n]);var C=h.useCallback(async function(){if(!(!g.trim()||x)){b(!0),N(!1),_(!1),A(!1),d(null);try{await lK(e,g.trim(),"normal",y),m(""),N(!0),P.current&&clearTimeout(P.current),P.current=setTimeout(function(){N(!1),p(!1),P.current=null},1500),S.current&&clearTimeout(S.current),S.current=setTimeout(function(){I(!0,!1),S.current=null},500)}catch(Z){d(Z.message)}finally{b(!1)}}},[e,g,y,x,I]),K=h.useCallback(async function(){if(!(!g.trim()||x)){if(!T){A(!0);return}b(!0),N(!1),_(!0),A(!1),d(null);try{await cK(e,g.trim(),y),m(""),N(!0),P.current&&clearTimeout(P.current),P.current=setTimeout(function(){N(!1),p(!1),P.current=null},1500),S.current&&clearTimeout(S.current),S.current=setTimeout(function(){I(!0,!1),S.current=null},500)}catch(Z){d(Z.message)}finally{b(!1)}}},[e,g,x,T,y,I]),W=h.useCallback(function(){p(!1),A(!1),d(null),P.current&&(clearTimeout(P.current),P.current=null),S.current&&(clearTimeout(S.current),S.current=null),N(!1)},[]);h.useEffect(function(){if(!f)return;function Z(ke){ke.key==="Escape"&&!x&&W()}return document.addEventListener("keydown",Z),function(){document.removeEventListener("keydown",Z)}},[f,W,x]),h.useEffect(function(){if(!(!f||!M.current)){var Z=M.current;Z.contains(document.activeElement)||Z.focus()}},[f]);var j=h.useCallback(function(Z){Z.target===Z.currentTarget&&!x&&W()},[W,x]),U=h.useCallback(function(Z){Z.key==="Enter"&&!Z.shiftKey&&!T&&(Z.preventDefault(),C())},[C,T]),le=h.useCallback(function(){},[]);return o.jsxs("div",{className:"h-full flex flex-col bg-white dark:bg-gray-900 relative",children:[o.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-800",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("button",{onClick:t,className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-500 dark:text-gray-400 transition-colors",title:a("agents.back"),children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 19l-7-7 7-7"})})}),o.jsxs("div",{children:[o.jsx("h2",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:"Conversation"}),o.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:[e," - ",i.length," messages"]})]})]}),o.jsx("button",{onClick:function(){$.current=!0,I(!0),D.current&&D.current.scrollIntoView({behavior:"smooth"})},disabled:l,className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-400 transition-colors disabled:opacity-50",title:a("agents.refresh"),children:o.jsx("svg",{className:`w-4 h-4 ${l?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]}),u&&o.jsxs("div",{className:"mx-4 mt-3 px-4 py-2 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 text-sm rounded-lg flex items-center justify-between",children:[o.jsx("span",{children:u}),o.jsx("button",{onClick:function(){d(null)},className:"ml-2 text-red-400 hover:text-red-600",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),k&&o.jsxs("div",{className:`mx-4 mt-3 px-4 py-2 text-sm rounded-lg flex items-center gap-2 ${w?"bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400":"bg-green-50 dark:bg-green-900/20 text-green-600 dark:text-green-400"}`,children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w?o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13 10V3L4 14h7v7l9-11h-7z"}):o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),a(w?"agent_conversation.interrupt_sent":"agent_conversation.message_queued")]}),o.jsx("div",{ref:R,onScroll:B,className:"flex-1 overflow-y-auto px-4 py-4",children:l&&i.length===0?o.jsx("div",{className:"flex items-center justify-center h-32",children:o.jsx("div",{className:"w-6 h-6 border-2 border-primary-500 border-t-transparent rounded-full animate-spin"})}):i.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center h-32 text-center",children:[o.jsx("div",{className:"w-12 h-12 rounded-xl bg-gray-100 dark:bg-gray-800 flex items-center justify-center mb-3",children:o.jsx("svg",{className:"w-6 h-6 text-gray-400 dark:text-gray-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})}),o.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:a("agent_conversation.no_messages")}),o.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 mt-1",children:a("agent_conversation.no_messages_hint")})]}):o.jsxs("div",{className:"max-w-3xl mx-auto space-y-6",children:[i.map(function(Z){return o.jsx(nT,{message:Z.info,parts:Z.parts,streamingParts:null,searchQuery:null,matchOffset:-1,matchCount:0,activeMatchIndex:-1,registerMatchRef:le,hackerMode:r,hideThinking:!1},Z.info.id)}),o.jsx("div",{ref:D})]})}),o.jsx("div",{className:"absolute bottom-6 right-6",children:o.jsxs("button",{onClick:function(){p(!0),A(!1),d(null)},className:"px-4 py-2.5 bg-primary-500 hover:bg-primary-600 text-white rounded-full shadow-lg font-medium text-sm transition-colors flex items-center gap-2","aria-label":a("agent_conversation.compose_button"),children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),a("agent_conversation.compose_button")]})}),f&&o.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40 backdrop-blur-sm",onClick:j,children:o.jsxs("div",{ref:M,tabIndex:-1,role:"dialog","aria-modal":"true","aria-labelledby":"compose-modal-title",className:"bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700 shadow-xl w-full max-w-lg mx-4 max-h-[80vh] flex flex-col",children:[o.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[o.jsx("h3",{id:"compose-modal-title",className:"text-base font-semibold text-gray-900 dark:text-white",children:a("agent_conversation.modal_title",{name:e})}),o.jsx("button",{onClick:W,disabled:x,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors"+(x?" opacity-50 cursor-not-allowed":""),"aria-label":a("common.close"),children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),o.jsxs("div",{className:"px-5 py-4 space-y-4 overflow-y-auto flex-1 min-h-0",children:[o.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[o.jsx("input",{type:"checkbox",checked:y,onChange:function(Z){v(Z.target.checked)},className:"w-4 h-4 rounded border-gray-300 dark:border-gray-600 text-primary-600 focus:ring-primary-500"}),o.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:a("agent_conversation.reply_to_inbox")})]}),o.jsx("textarea",{ref:G,value:g,onChange:function(Z){m(Z.target.value)},onKeyDown:U,placeholder:a("agent_conversation.send_placeholder"),className:"w-full px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 outline-none resize-none text-sm text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:ring-2 focus:ring-primary-500 dark:focus:ring-primary-400 focus:border-transparent",rows:4,disabled:x,autoFocus:!0}),k&&o.jsx("p",{className:"text-sm text-green-600 dark:text-green-400 font-medium",children:a(w?"agent_conversation.interrupt_sent":"agent_conversation.message_queued")}),u&&o.jsx("p",{className:"text-sm text-red-500 dark:text-red-400",children:u})]}),o.jsx("div",{className:"px-5 py-4 border-t border-gray-200 dark:border-gray-700 flex-shrink-0",children:T?o.jsxs("div",{className:"space-y-2",children:[o.jsx("p",{className:"text-xs text-red-500 dark:text-red-400 font-medium",children:a("agent_conversation.urgent_warning")}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("button",{onClick:function(){A(!1)},className:"px-3 py-1.5 text-xs text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 transition-colors",children:a("common.cancel")}),o.jsxs("button",{onClick:K,disabled:!g.trim()||x,className:"px-3 py-1.5 bg-red-500 hover:bg-red-600 text-white rounded-lg disabled:opacity-50 disabled:cursor-not-allowed text-xs font-medium transition-colors flex items-center gap-1.5",children:[x&&w?o.jsx("div",{className:"w-3 h-3 border-2 border-white border-t-transparent rounded-full animate-spin"}):o.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13 10V3L4 14h7v7l9-11h-7z"})}),a("agent_conversation.confirm_interrupt")]})]})]}):o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("button",{onClick:K,disabled:!g.trim()||x,className:"px-3 py-1.5 text-xs text-red-500 dark:text-red-400 hover:text-red-600 dark:hover:text-red-300 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center gap-1.5",children:[o.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13 10V3L4 14h7v7l9-11h-7z"})}),a("agent_conversation.urgent_interrupt_button")]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("button",{onClick:W,disabled:x,className:"px-4 py-2 text-sm transition-colors"+(x?" text-gray-400 dark:text-gray-600 cursor-not-allowed":" text-gray-600 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200"),children:a("common.cancel")}),o.jsxs("button",{onClick:C,disabled:!g.trim()||x,className:"px-4 py-2 bg-primary-500 hover:bg-primary-600 text-white rounded-lg disabled:opacity-50 disabled:cursor-not-allowed font-medium text-sm transition-colors flex items-center gap-2",children:[x&&!w?o.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}):o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})}),a("agent_conversation.send_button")]})]})]})})]})})]})}function EK({isOpen:e,agent:t,onClose:n,onUpdated:r,onDeleted:a}){const{t:i}=vt(),[s,l]=h.useState(""),[c,u]=h.useState(""),[d,f]=h.useState(""),[p,g]=h.useState(""),[m,y]=h.useState(!1),[v,x]=h.useState([]),[b,k]=h.useState(!1),[N,w]=h.useState(""),[_,T]=h.useState(null),[A,D]=h.useState(!1),[R,$]=h.useState([]),[F,G]=h.useState([]),[P,M]=h.useState(!1),[S,I]=h.useState(!0),[B,Q]=h.useState(!1),[C,K]=h.useState(!1),[W,j]=h.useState(null),[U,le]=h.useState(!1),[Z,ke]=h.useState(!1),[re,X]=h.useState("general"),[Ne,ve]=h.useState(!1);h.useEffect(()=>{const ue={cancelled:!1};if(e&&t&&!Ne){me();const he=(typeof t.model=="string"?t.model.trim():t.model)||"github-copilot/claude-opus-4.6";pe(ue,he),ve(!0)}return e||(ve(!1),y(!1),g(""),I(!0),G([])),()=>{ue.cancelled=!0}},[e,t==null?void 0:t.name]);const me=()=>{if(!t)return;l(t.displayName||t.name||""),u(t.cwd||"");const ue=(typeof t.model=="string"?t.model.trim():t.model)||"github-copilot/claude-opus-4.6";f(ue),y(!1),g(""),x(Array.isArray(t.skills)?t.skills:[]),k(!!t.skipInitialPrompt)},pe=async(ue,he)=>{M(!0),I(!0),t!=null&&t.name&&Q(!0);const _e=[SA(),nv()];t!=null&&t.name&&_e.push(yK(t.name));const Pe=await Promise.allSettled(_e);if(ue.cancelled)return;const[Xe,H,z]=Pe;if(Xe.status==="fulfilled"?$(Xe.value):(console.error("Failed to load skills:",Xe.reason),$([])),M(!1),H.status==="fulfilled"){const te=H.value;G(te);const ce=he;te.find(je=>je.id===ce)||(y(!0),g(ce),f(ce))}else console.error("Failed to load models:",H.reason),G([]);if(I(!1),t!=null&&t.name&&z){if(z.status==="fulfilled"){const te=z.value;w(te.content||""),T(te.path||null),D(te.exists||!1)}else console.error("Failed to load AGENTS.md:",z.reason),w(""),T(null),D(!1);Q(!1)}},Le=ue=>{x(he=>he.includes(ue)?he.filter(_e=>_e!==ue):[...he,ue])},Se=()=>{v.length===R.length?x([]):x(R.map(ue=>ue.name))},Te=async ue=>{if(ue&&ue.preventDefault(),!!(t!=null&&t.name)){j(null),K(!0);try{await mK(t.name,{displayName:s.trim()||t.name,workspace:c.trim(),model:d,skipInitialPrompt:b,skills:v}),_&&N!==null&&!Ce&&await xK(t.name,N),r&&r(t.name),n()}catch(he){j(he.message)}finally{K(!1)}}},Fe=async()=>{if(t!=null&&t.name){ke(!0),j(null);try{await gK(t.name,!0),a&&a(t.name),n()}catch(ue){j(ue.message),le(!1)}finally{ke(!1)}}},fe=()=>{!C&&!Z&&(j(null),le(!1),X("general"),n())};if(!e||!t)return null;const xe=t.state==="working"||t.state==="idle"||t.state==="starting",Ce=c.trim()!==(t.cwd||"");return o.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[o.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:fe}),U&&o.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[o.jsx("div",{className:"absolute inset-0 bg-black/30",onClick:()=>le(!1)}),o.jsxs("div",{className:"relative bg-white dark:bg-gray-900 rounded-xl shadow-2xl max-w-md w-full p-6",children:[o.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 mb-2",children:"Delete Agent?"}),o.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-4",children:["Are you sure you want to delete ",o.jsx("strong",{children:t.displayName||t.name}),"?",xe&&o.jsx("span",{className:"block mt-2 text-yellow-600 dark:text-yellow-400",children:"Warning: This agent is currently running and will be stopped."})]}),o.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-500 mb-4",children:"This will remove the agent registration. The workspace directory will not be deleted."}),o.jsxs("div",{className:"flex justify-end gap-3",children:[o.jsx("button",{onClick:()=>le(!1),disabled:Z,className:"px-4 py-2 rounded-lg text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors disabled:opacity-50",children:i("common.cancel")}),o.jsx("button",{onClick:Fe,disabled:Z,className:"px-4 py-2 rounded-lg bg-red-600 hover:bg-red-700 text-white font-medium transition-colors disabled:opacity-50 flex items-center gap-2",children:Z?o.jsxs(o.Fragment,{children:[o.jsxs("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[o.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),o.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),i("common.deleting")]}):i("common.delete")})]})]})]}),o.jsxs("div",{className:"relative bg-white dark:bg-gray-900 rounded-2xl shadow-2xl max-w-2xl w-full max-h-[90vh] overflow-hidden flex flex-col",children:[o.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200 dark:border-gray-800",children:[o.jsxs("div",{children:[o.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:i("agent_edit.title")}),o.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:[t.name,xe&&o.jsxs("span",{className:"ml-2 text-yellow-600 dark:text-yellow-400",children:["(",i("agent_edit.running_warning"),")"]})]})]}),o.jsx("button",{onClick:fe,disabled:C||Z,className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-400 transition-colors disabled:opacity-50",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),o.jsxs("div",{className:"flex border-b border-gray-200 dark:border-gray-800 px-6",children:[o.jsx("button",{onClick:()=>X("general"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${re==="general"?"border-primary-500 text-primary-600 dark:text-primary-400":"border-transparent text-gray-500 hover:text-gray-700 dark:hover:text-gray-300"}`,children:i("agent_edit.tab_general")}),o.jsx("button",{onClick:()=>X("soul"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${re==="soul"?"border-primary-500 text-primary-600 dark:text-primary-400":"border-transparent text-gray-500 hover:text-gray-700 dark:hover:text-gray-300"}`,children:i("agent_edit.tab_soul")})]}),o.jsxs("form",{onSubmit:ue=>ue.preventDefault(),className:"flex-1 overflow-y-auto p-6 space-y-6",children:[W&&o.jsxs("div",{className:"px-4 py-3 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 text-sm rounded-lg flex items-center justify-between",children:[o.jsx("span",{children:W}),o.jsx("button",{type:"button",onClick:()=>j(null),className:"ml-2 text-red-400 hover:text-red-600",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),re==="general"&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{children:[o.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:[i("agent_edit.name_label"),o.jsx("span",{className:"text-gray-400 font-normal ml-1",children:i("agent_edit.cannot_change")})]}),o.jsx("input",{type:"text",value:t.name,disabled:!0,className:"w-full px-4 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-500 dark:text-gray-400 cursor-not-allowed font-mono"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:i("agent_edit.display_name_label")}),o.jsx("input",{type:"text",value:s,onChange:ue=>l(ue.target.value),placeholder:i("agent_edit.display_name_placeholder"),className:"w-full px-4 py-2 rounded-lg bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-primary-500"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:i("agent_edit.working_dir_label")}),xe?o.jsx("div",{className:"px-4 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-500 dark:text-gray-400 font-mono text-sm break-all",children:c||i("agent_edit.not_set")}):o.jsx("input",{type:"text",value:c,onChange:ue=>u(ue.target.value),placeholder:i("agent_edit.working_dir_placeholder"),disabled:C||Z,className:"w-full px-4 py-2 rounded-lg bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-primary-500 font-mono text-sm disabled:opacity-50"}),xe?o.jsx("p",{className:"mt-1 text-xs text-gray-400",children:i("agent_edit.stop_to_change")}):c.trim()!==(t.cwd||"")?o.jsx("p",{className:"mt-1 text-xs text-amber-500 dark:text-amber-400",children:i("agent_edit.workspace_move_warning")}):o.jsx("p",{className:"mt-1 text-xs text-gray-400",children:i("agent_edit.working_dir_hint")})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:i("agent_edit.model_label")}),S?o.jsx("div",{className:"w-full px-4 py-2 rounded-lg bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-400 text-sm",children:i("agent_edit.loading_models")}):F.length===0?o.jsx("input",{type:"text",value:d,onChange:ue=>f(ue.target.value),placeholder:i("agent_edit.model_placeholder"),className:"w-full px-4 py-2 rounded-lg bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-primary-500 font-mono text-sm"}):o.jsxs(o.Fragment,{children:[o.jsxs("select",{value:m?"__custom__":d,onChange:ue=>{ue.target.value==="__custom__"?(y(!0),d&&d!=="__custom__"&&g(d)):(y(!1),f(ue.target.value))},className:"w-full px-4 py-2 rounded-lg bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500",children:[(()=>{const ue=tv(F);return Object.entries(ue).map(([he,_e])=>o.jsx("optgroup",{label:Jb[he]||he,children:_e.map(Pe=>o.jsxs("option",{value:Pe.id,children:[Pe.name,ev(Pe.tier)]},Pe.id))},he))})(),o.jsx("option",{value:"__custom__",children:i("agent_edit.custom_model")})]}),m&&o.jsx("input",{type:"text",value:p,onChange:ue=>{g(ue.target.value),f(ue.target.value)},placeholder:i("agent_edit.custom_model_placeholder"),className:"w-full mt-2 px-4 py-2 rounded-lg bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-primary-500 font-mono text-sm"})]}),o.jsx("p",{className:"mt-1 text-xs text-gray-400",children:i(m?"agent_edit.custom_model_hint":"agent_edit.model_hint")})]}),o.jsxs("div",{className:"space-y-3",children:[o.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:i("agent_edit.start_mode")}),o.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[o.jsx("input",{type:"checkbox",checked:b,onChange:ue=>k(ue.target.checked),className:"mt-0.5 rounded border-gray-300 dark:border-gray-600 text-primary-600 focus:ring-primary-500"}),o.jsxs("div",{children:[o.jsx("span",{className:"text-sm text-gray-900 dark:text-gray-100",children:i("agent_edit.dormant_mode")}),o.jsx("p",{className:"text-xs text-gray-400 mt-0.5",children:i("agent_edit.dormant_mode_desc")})]})]})]}),o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center justify-between mb-2",children:[o.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:i("agent_edit.skills_label")}),o.jsx("button",{type:"button",onClick:Se,className:"text-xs text-primary-600 dark:text-primary-400 hover:underline",children:v.length===R.length?i("agent_edit.deselect_all"):i("agent_edit.select_all")})]}),o.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-3 max-h-48 overflow-y-auto bg-gray-50 dark:bg-gray-800",children:P?o.jsx("div",{className:"text-center py-4 text-gray-500",children:i("agent_edit.loading_skills")}):R.length===0?o.jsx("div",{className:"text-center py-4 text-gray-500",children:i("agent_edit.no_skills")}):o.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-2",children:R.map(ue=>o.jsxs("label",{className:`flex items-center gap-2 px-3 py-2 rounded-lg cursor-pointer transition-colors ${v.includes(ue.name)?"bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-300":"hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-300"}`,children:[o.jsx("input",{type:"checkbox",checked:v.includes(ue.name),onChange:()=>Le(ue.name),className:"rounded border-gray-300 text-primary-600 focus:ring-primary-500"}),o.jsxs("span",{className:"text-sm truncate",title:ue.description,children:[ue.icon&&o.jsx("span",{className:"mr-1",children:ue.icon}),ue.name]})]},ue.name))})}),o.jsx("p",{className:"mt-1 text-xs text-gray-400",children:i("agent_edit.skills_selected",{count:v.length})})]})]}),re==="soul"&&o.jsxs("div",{className:"space-y-4",children:[_&&o.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400 font-mono bg-gray-50 dark:bg-gray-800 rounded px-3 py-2",children:[_,!A&&o.jsx("span",{className:"ml-2 text-yellow-600 dark:text-yellow-400",children:i("agent_edit.will_be_created")})]}),!_&&!c.trim()&&o.jsx("div",{className:"px-4 py-3 bg-yellow-50 dark:bg-yellow-900/20 text-yellow-700 dark:text-yellow-400 text-sm rounded-lg",children:i("agent_edit.no_workspace_warning")}),Ce&&o.jsx("div",{className:"px-4 py-3 bg-amber-50 dark:bg-amber-900/20 text-amber-700 dark:text-amber-400 text-sm rounded-lg",children:i("agent_edit.workspace_changed_warning")}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:i("agent_edit.instructions_label")}),o.jsx("textarea",{value:N,onChange:ue=>w(ue.target.value),disabled:!_||Ce,rows:16,placeholder:i(B?"common.loading":"agent_edit.soul_placeholder"),className:"w-full px-4 py-3 rounded-lg bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-primary-500 font-mono text-sm resize-none disabled:cursor-not-allowed disabled:opacity-50"}),o.jsx("p",{className:"mt-1 text-xs text-gray-400",children:i("agent_edit.instructions_hint")})]})]})]}),o.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-t border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-900",children:[o.jsxs("button",{type:"button",onClick:()=>le(!0),disabled:C||Z,className:"px-4 py-2 rounded-lg text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors disabled:opacity-50 flex items-center gap-2",children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),i("common.delete")]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("button",{type:"button",onClick:fe,disabled:C||Z,className:"px-4 py-2 rounded-lg text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors disabled:opacity-50",children:i("common.cancel")}),o.jsx("button",{type:"button",onClick:Te,disabled:C||Z,className:"px-6 py-2 rounded-lg bg-primary-600 hover:bg-primary-700 text-white font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:C?o.jsxs(o.Fragment,{children:[o.jsxs("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[o.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),o.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),i("agent_edit.saving")]}):o.jsxs(o.Fragment,{children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),i("agent_edit.save")]})})]})]})]})]})}const FS={working:"bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",idle:"bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-400",paused:"bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-400",stopped:"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400",crashed:"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400",error:"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400",starting:"bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-400"},BS={working:o.jsx("svg",{className:"w-4 h-4 mr-1.5",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),idle:o.jsx("svg",{className:"w-4 h-4 mr-1.5",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{d:"M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"})}),paused:o.jsx("svg",{className:"w-4 h-4 mr-1.5",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zM7 8a1 1 0 012 0v4a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v4a1 1 0 102 0V8a1 1 0 00-1-1z",clipRule:"evenodd"})}),stopped:o.jsx("svg",{className:"w-4 h-4 mr-1.5",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8 7a1 1 0 00-1 1v4a1 1 0 001 1h4a1 1 0 001-1V8a1 1 0 00-1-1H8z",clipRule:"evenodd"})}),crashed:o.jsx("svg",{className:"w-4 h-4 mr-1.5",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})}),error:o.jsx("svg",{className:"w-4 h-4 mr-1.5",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})}),starting:o.jsx("svg",{className:"w-4 h-4 mr-1.5 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})};function NK({state:e}){const t=FS[e]||FS.stopped,n=BS[e]||BS.stopped;return o.jsxs("span",{className:`inline-flex items-center px-3 py-1 rounded-full text-sm font-medium ${t}`,children:[n,e]})}function SK(e){if(!e)return"-";const t=Date.now()-e,n=Math.floor(t/1e3);if(n<60)return n+"s";const r=Math.floor(n/60);if(r<60)return r+"m";const a=Math.floor(r/60),i=r%60;if(a<24)return a+"h "+i+"m";const s=Math.floor(a/24),l=a%24;return s+"d "+l+"h"}function P0({label:e,value:t,max:n,color:r}){const a=n>0?Math.min(100,Math.round(t/n*100)):0;return o.jsxs("div",{className:"space-y-1",children:[o.jsxs("div",{className:"flex items-center justify-between text-xs",children:[o.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:e}),o.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:t.toLocaleString()})]}),o.jsx("div",{className:"h-1.5 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden",children:o.jsx("div",{className:`h-full ${r} transition-all duration-300`,style:{width:a+"%"}})})]})}function ci({label:e,value:t,mono:n}){return o.jsxs("div",{className:"flex items-center justify-between py-2 border-b border-gray-100 dark:border-gray-800 last:border-0",children:[o.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:e}),o.jsx("span",{className:`text-sm text-gray-900 dark:text-gray-100 ${n?"font-mono":""}`,children:t||"-"})]})}function CK({agent:e,onClose:t,onAction:n,onToolPartsChange:r,hackerMode:a}){const{t:i}=vt(),[s,l]=h.useState(e),[c,u]=h.useState(null),[d,f]=h.useState(null),[p,g]=h.useState(!1),[m,y]=h.useState(!1),v=h.useCallback(async()=>{if(e!=null&&e.name)try{const A=await oK(e.name);l(A),u(null)}catch(A){console.error("Failed to load agent:",A),u(A.message)}},[e==null?void 0:e.name]);h.useEffect(()=>{v();const A=setInterval(v,5e3);return()=>clearInterval(A)},[v]);const x=h.useCallback(async A=>{f(A),u(null);try{A==="start"?await lx(s.name):A==="stop"?await cx(s.name):A==="restart"?await Eu(s.name):A==="cleanRestart"?await Eu(s.name,{clean:!0}):A==="pause"?await ux(s.name,{level:"tools"}):A==="unpause"&&await dx(s.name),await v(),n&&n(s.name,A)}catch(D){u(D.message)}finally{f(null)}},[s==null?void 0:s.name,v,n]),b=(s==null?void 0:s.state)==="working"||(s==null?void 0:s.state)==="idle"||(s==null?void 0:s.state)==="starting"||(s==null?void 0:s.state)==="paused",k=(s==null?void 0:s.state)==="paused"||(s==null?void 0:s.paused),N=(s==null?void 0:s.displayName)||(s==null?void 0:s.name)||"Unknown Agent",w=(s==null?void 0:s.tokens)||{input:0,output:0,cached:0,total:0},_=Math.max(w.input,w.output,w.cached,1),T=(s==null?void 0:s.cost)||{input:0,output:0,cached:0,total:0};return p?o.jsx(wK,{agentName:s==null?void 0:s.name,onClose:()=>{g(!1),r&&r(null)},onToolPartsChange:r,hackerMode:a}):o.jsxs("div",{className:"h-full flex flex-col bg-white dark:bg-gray-900 border-l border-gray-200 dark:border-gray-800",children:[o.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200 dark:border-gray-800",children:[o.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[o.jsx("button",{onClick:t,className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-500 dark:text-gray-400 transition-colors flex-shrink-0",title:i("agent_detail.back"),"aria-label":i("agent_detail.back"),children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 19l-7-7 7-7"})})}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 truncate",title:N,children:N}),(s==null?void 0:s.displayName)&&s.displayName!==s.name&&o.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 truncate",title:s.name,children:s.name})]})]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("button",{onClick:()=>y(!0),className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-500 dark:text-gray-400 transition-colors",title:i("agent_detail.edit_settings"),"aria-label":i("agent_detail.edit_settings"),children:o.jsxs("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})}),o.jsx(NK,{state:(s==null?void 0:s.state)||"stopped"})]})]}),o.jsx(EK,{isOpen:m,agent:s,onClose:()=>y(!1),onUpdated:A=>{v(),n&&n(A,"updated")},onDeleted:A=>{n&&n(A,"deleted"),t()}}),c&&o.jsxs("div",{className:"mx-6 mt-4 px-4 py-2 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 text-sm rounded-lg flex items-center justify-between",children:[o.jsx("span",{children:c}),o.jsx("button",{onClick:()=>u(null),className:"ml-2 text-red-400 hover:text-red-600",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),o.jsxs("div",{className:"flex-1 overflow-y-auto p-6 space-y-6",children:[o.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:b?o.jsxs(o.Fragment,{children:[o.jsx("button",{onClick:()=>x("stop"),disabled:d,className:"flex-1 px-4 py-2 text-sm font-medium rounded-lg bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 disabled:opacity-50 transition-colors",children:i(d==="stop"?"agents.stopping":"agents.stop")}),k?o.jsx("button",{onClick:()=>x("unpause"),disabled:d,className:"flex-1 px-4 py-2 text-sm font-medium rounded-lg bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 hover:bg-green-200 dark:hover:bg-green-800/40 disabled:opacity-50 transition-colors",children:i(d==="unpause"?"agents.resuming":"agents.resume")}):o.jsx("button",{onClick:()=>x("pause"),disabled:d,className:"flex-1 px-4 py-2 text-sm font-medium rounded-lg bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-400 hover:bg-orange-200 dark:hover:bg-orange-800/40 disabled:opacity-50 transition-colors",children:i(d==="pause"?"agents.pausing":"agents.pause")}),o.jsx("button",{onClick:()=>x("restart"),disabled:d,className:"flex-1 px-4 py-2 text-sm font-medium rounded-lg bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400 hover:bg-primary-200 dark:hover:bg-primary-800/40 disabled:opacity-50 transition-colors",children:i(d==="restart"?"agents.restarting":"agents.restart")}),o.jsx("button",{onClick:()=>x("cleanRestart"),disabled:d,className:"flex-1 px-4 py-2 text-sm font-medium rounded-lg bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-400 hover:bg-orange-200 dark:hover:bg-orange-800/40 disabled:opacity-50 transition-colors",title:i("agents.clean_restart_tooltip"),children:i(d==="cleanRestart"?"agents.restarting":"agents.clean_restart")})]}):o.jsx("button",{onClick:()=>x("start"),disabled:d,className:"flex-1 px-4 py-2 text-sm font-medium rounded-lg bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 hover:bg-green-200 dark:hover:bg-green-800/40 disabled:opacity-50 transition-colors",children:i(d==="start"?"agents.starting":"agents.start")})}),o.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800/50 rounded-xl p-4",children:[o.jsx("h3",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-3",children:i("agent_detail.agent_info")}),o.jsxs("div",{className:"space-y-0",children:[o.jsx(ci,{label:i("agent_detail.model"),value:s==null?void 0:s.model,mono:!0}),o.jsx(ci,{label:i("agent_detail.port"),value:s==null?void 0:s.port,mono:!0}),o.jsx(ci,{label:i("agent_detail.pid"),value:s==null?void 0:s.pid,mono:!0}),o.jsx(ci,{label:i("agent_detail.session_id"),value:s!=null&&s.sessionId?s.sessionId.slice(0,12)+"...":null,mono:!0}),o.jsx(ci,{label:i("agent_detail.uptime"),value:SK(s==null?void 0:s.startedAt)}),o.jsx(ci,{label:i("agent_detail.iteration"),value:s==null?void 0:s.iteration}),o.jsx(ci,{label:i("agent_detail.start_mode"),value:s!=null&&s.skipInitialPrompt?i("agent_detail.start_mode_dormant"):i("agent_detail.start_mode_normal")})]})]}),o.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800/50 rounded-xl p-4",children:[o.jsx("h3",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-3",children:i("agent_detail.token_usage")}),o.jsxs("div",{className:"space-y-3",children:[o.jsx(P0,{label:i("agent_detail.token_input"),value:w.input,max:_,color:"bg-blue-500"}),o.jsx(P0,{label:i("agent_detail.token_output"),value:w.output,max:_,color:"bg-green-500"}),o.jsx(P0,{label:i("agent_detail.token_cached"),value:w.cached,max:_,color:"bg-purple-500"}),o.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-gray-200 dark:border-gray-700",children:[o.jsx("span",{className:"text-sm font-medium text-gray-600 dark:text-gray-300",children:"Total"}),o.jsx("span",{className:"text-sm font-bold text-gray-900 dark:text-gray-100",children:w.total.toLocaleString()})]})]})]}),o.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800/50 rounded-xl p-4",children:[o.jsx("h3",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-3",children:"Estimated Cost"}),o.jsxs("div",{className:"grid grid-cols-3 gap-4 mb-3",children:[o.jsxs("div",{className:"text-center",children:[o.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Input"}),o.jsxs("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:["$",T.input.toFixed(4)]})]}),o.jsxs("div",{className:"text-center",children:[o.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Output"}),o.jsxs("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:["$",T.output.toFixed(4)]})]}),o.jsxs("div",{className:"text-center",children:[o.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Cached"}),o.jsxs("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:["$",T.cached.toFixed(4)]})]})]}),o.jsxs("div",{className:"flex items-center justify-between pt-3 border-t border-gray-200 dark:border-gray-700",children:[o.jsx("span",{className:"text-sm font-medium text-gray-600 dark:text-gray-300",children:i("agent_detail.total_cost")}),o.jsxs("span",{className:"text-lg font-bold text-gray-900 dark:text-gray-100",children:["$",T.total.toFixed(4)]})]})]}),(s==null?void 0:s.dailyUsage)&&s.dailyUsage.length>0&&o.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800/50 rounded-xl p-4",children:[o.jsx("h3",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-3",children:"Daily Usage (Last 7 Days)"}),o.jsx(_K,{data:s.dailyUsage})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsxs("button",{className:"w-full px-4 py-2.5 text-sm font-medium rounded-lg border border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors flex items-center justify-center gap-2",onClick:()=>g(!0),children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),i("agent_detail.view_conversation")]}),o.jsxs("button",{className:"w-full px-4 py-2.5 text-sm font-medium rounded-lg border border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors flex items-center justify-center gap-2",onClick:()=>y(!0),children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),i("agent_detail.edit_settings")]}),o.jsxs("button",{className:"w-full px-4 py-2.5 text-sm font-medium rounded-lg border border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors flex items-center justify-center gap-2",onClick:async()=>{try{await CA(s.name)}catch(A){u(i("agents.export_error")+": "+A.message)}},children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),i("agents.export")]})]}),(s==null?void 0:s.cwd)&&o.jsxs("div",{className:"text-xs text-gray-400 dark:text-gray-500 break-all",children:[o.jsx("span",{className:"font-medium",children:i("agent_detail.working_dir_label")}),o.jsx("br",{}),o.jsx("span",{className:"font-mono",children:s.cwd})]})]})]})}const vc=["swift","quick","rapid","agile","nimble","clever","smart","wise","bright","keen","bold","brave","calm","steady","noble","silent","shadow","storm","iron","steel","amber","azure","cobalt","crimson","golden","cosmic","cyber","digital","quantum","prime"],kc=["falcon","hawk","eagle","raven","phoenix","wolf","fox","hound","coyote","tiger","panther","lynx","leopard","bear","orca","shark","viper","cobra","dragon","griffin","sentinel","guardian","titan","node","nexus","core","spark","pulse"];function zS(e=[],t=100){const n=new Set(e.map(s=>s.toLowerCase()));for(let s=0;s<t;s++){const l=vc[Math.floor(Math.random()*vc.length)],c=kc[Math.floor(Math.random()*kc.length)],u=`${l}-${c}`;if(!n.has(u))return u}const r=vc[Math.floor(Math.random()*vc.length)],a=kc[Math.floor(Math.random()*kc.length)],i=Math.floor(Math.random()*1e3);return`${r}-${a}-${i}`}function US(e,t=[]){if(!e||typeof e!="string")return{valid:!1,error:"Name is required"};const n=e.trim().toLowerCase();return n.length===0?{valid:!1,error:"Name cannot be empty"}:n.length<2?{valid:!1,error:"Name must be at least 2 characters"}:n.length>50?{valid:!1,error:"Name must be 50 characters or less"}:/^[a-z0-9_-]+$/.test(n)?new Set(t.map(a=>a.toLowerCase())).has(n)?{valid:!1,error:"An agent with this name already exists"}:{valid:!0,error:null}:{valid:!1,error:"Name can only contain lowercase letters, numbers, hyphens, and underscores"}}function jK(e){return e?e.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9_-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,""):""}const _c=`# AGENTS.md - AI Agent Instructions
104
+ `+Tt),Pe&&(Tt=Ui(Tt)),T&&Ye?G(Tt):Tt},t.setConfig=function(){let Me=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};ba(Me),z=!0,te=me,ce=Le},t.clearConfig=function(){br=null,z=!1,te=null,ce=null,T=D,A=""},t.isValidAttribute=function(Me,O,ie){br||ba({});const Ee=Ct(Me),$e=Ct(O);return Cl(Ee,$e,ie)},t.addHook=function(Me,O){typeof O=="function"&&fn(W,Me)&&Zi(W[Me],O)},t.removeHook=function(Me,O){if(fn(W,Me)){if(O!==void 0){const ie=tG(W[Me],O);return ie===-1?void 0:nG(W[Me],ie,1)[0]}return gS(W[Me])}},t.removeHooks=function(Me){fn(W,Me)&&(W[Me]=[])},t.removeAllHooks=function(){W=SS()},t}var NG=NA();let L0=null;function SG(){return L0||(L0=uj(()=>import("./mermaid.core-Czi3lWeD.js").then(e=>e.bo),[]).then(function(e){const t=e.default||e;return t.initialize({startOnLoad:!1,securityLevel:"strict",theme:"default",flowchart:{curve:"basis"},suppressErrorRendering:!0}),t})),L0}function CS(){return typeof document>"u"?!1:document.documentElement.classList.contains("dark")}let jS=0;function CG(){return jS+=1,"pave-canvas-"+jS}function jG({source:e}){const t=h.useRef(null),n=h.useRef(CG()),[r,a]=h.useState(null),[i,s]=h.useState(CS());return h.useEffect(function(){if(typeof window>"u")return;const l=new MutationObserver(function(){const c=CS();s(function(u){return u!==c?c:u})});return l.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),function(){l.disconnect()}},[]),h.useEffect(function(){let l=!1;return a(null),SG().then(function(c){l||(c.initialize({startOnLoad:!1,securityLevel:"strict",theme:i?"dark":"default",flowchart:{curve:"basis"},suppressErrorRendering:!0}),c.render(n.current,e).then(function(u){if(!l&&t.current){let d=u.svg;d=d.replace(/<svg([^>]*)\sstyle="[^"]*max-width:[^";]*;?[^"]*"/i,"<svg$1"),d=d.replace(/(<svg[^>]*)\swidth="[^"]*"/i,"$1"),d=d.replace(/(<svg[^>]*)\sheight="[^"]*"/i,"$1"),d=d.replace(/<svg\b/i,'<svg width="100%" height="100%" preserveAspectRatio="xMidYMid meet"'),t.current.innerHTML=d}}).catch(function(u){l||a(u&&u.message||String(u))}))}).catch(function(c){l||a("Failed to load mermaid: "+(c&&c.message||String(c)))}),function(){l=!0}},[e,i]),r?o.jsxs("div",{className:"text-xs text-red-600 dark:text-red-400 p-2",children:[o.jsx("div",{className:"font-semibold mb-1",children:"Mermaid render error:"}),o.jsx("pre",{className:"whitespace-pre-wrap",children:r}),o.jsxs("details",{className:"mt-2",children:[o.jsx("summary",{className:"cursor-pointer text-gray-600 dark:text-gray-400",children:"Source"}),o.jsx("pre",{className:"mt-1 p-2 bg-gray-100 dark:bg-gray-800 rounded overflow-x-auto",children:e})]})]}):o.jsx("div",{ref:t,className:"mermaid-canvas w-full h-full flex items-center justify-center [&>svg]:max-w-full [&>svg]:max-h-full [&>svg]:w-full [&>svg]:h-auto"})}function TG({source:e}){const t=h.useMemo(function(){return NG.sanitize(e,{USE_PROFILES:{svg:!0,svgFilters:!0}})},[e]);return o.jsx("div",{className:"svg-canvas overflow-x-auto",dangerouslySetInnerHTML:{__html:t}})}function AG({source:e}){return o.jsx("pre",{className:"text-sm p-2 bg-gray-100 dark:bg-gray-800 rounded overflow-x-auto",children:e})}function RG({canvas:e}){if(!e||!e.type||!e.source)return null;let t=null;return e.type==="mermaid"?t=o.jsx(jG,{source:e.source}):e.type==="svg"?t=o.jsx(TG,{source:e.source}):e.type==="katex"?t=o.jsx(AG,{source:e.source}):t=o.jsxs("pre",{className:"text-xs text-red-600 dark:text-red-400",children:["Unknown canvas type: ",e.type]}),o.jsx("div",{className:"w-full h-full flex items-center justify-center",children:t})}function TS({canvases:e,onClear:t}){const n=Array.isArray(e)?e:[],[r,a]=h.useState(Math.max(0,n.length-1)),[i,s]=h.useState(1),[l,c]=h.useState(!1);h.useEffect(function(){a(function(v){return v>=n.length-2?Math.max(0,n.length-1):Math.min(v,Math.max(0,n.length-1))})},[n.length]),h.useEffect(function(){s(1)},[r]),h.useEffect(function(){if(!l)return;const v=x=>{x.key==="Escape"&&c(!1)};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[l]);const u=h.useCallback(()=>s(v=>Math.min(4,+(v+.25).toFixed(2))),[]),d=h.useCallback(()=>s(v=>Math.max(.5,+(v-.25).toFixed(2))),[]),f=h.useCallback(()=>s(1),[]);if(n.length===0)return o.jsxs("div",{className:"h-full flex flex-col items-center justify-center p-6 text-center",children:[o.jsx("svg",{className:"w-12 h-12 text-gray-300 dark:text-gray-600 mb-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 17V7m0 10a2 2 0 01-2 2H5a2 2 0 01-2-2V7a2 2 0 012-2h2a2 2 0 012 2m0 10a2 2 0 002 2h2a2 2 0 002-2M9 7a2 2 0 012-2h2a2 2 0 012 2m0 10V7m0 10a2 2 0 002 2h2a2 2 0 002-2V7a2 2 0 00-2-2h-2a2 2 0 00-2 2"})}),o.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400 max-w-xs",children:["Ask the agent to draw something here. It can use the ",o.jsx("code",{className:"px-1 bg-gray-200 dark:bg-gray-700 rounded",children:"canvas"})," tool to render Mermaid diagrams, SVG illustrations, or math."]})]});const p=Math.min(Math.max(0,r),n.length-1),g=n[p],m=o.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5 border-b border-gray-200 dark:border-gray-700 text-xs",children:[n.length>1?o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx("button",{type:"button",onClick:()=>a(Math.max(0,p-1)),disabled:p===0,className:"px-2 py-0.5 rounded text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-40 disabled:cursor-not-allowed",title:"Previous canvas",children:"←"}),o.jsxs("span",{className:"text-gray-500 dark:text-gray-400 tabular-nums",children:[p+1,"/",n.length]}),o.jsx("button",{type:"button",onClick:()=>a(Math.min(n.length-1,p+1)),disabled:p===n.length-1,className:"px-2 py-0.5 rounded text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-40 disabled:cursor-not-allowed",title:"Next canvas",children:"→"})]}):o.jsx("div",{}),o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx("button",{type:"button",onClick:d,disabled:i<=.5,className:"px-1.5 py-0.5 rounded text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-40",title:"Zoom out",children:"−"}),o.jsxs("button",{type:"button",onClick:f,className:"px-1.5 py-0.5 rounded text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 tabular-nums min-w-[3rem]",title:"Reset zoom",children:[Math.round(i*100),"%"]}),o.jsx("button",{type:"button",onClick:u,disabled:i>=4,className:"px-1.5 py-0.5 rounded text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-40",title:"Zoom in",children:"+"}),o.jsx("button",{type:"button",onClick:()=>c(v=>!v),className:"ml-1 px-1.5 py-0.5 rounded text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800",title:l?"Exit fullscreen (Esc)":"Fullscreen",children:l?"⤢":"⛶"}),t?o.jsx("button",{type:"button",onClick:t,className:"ml-1 px-1.5 py-0.5 rounded text-gray-600 dark:text-gray-300 hover:bg-red-50 dark:hover:bg-red-900/30 hover:text-red-600 dark:hover:text-red-400",title:"Clear all canvases (hides them; messages preserved)",children:"✕"}):null]})]}),y=o.jsxs("div",{className:"flex-1 overflow-auto p-3",children:[g.title?o.jsx("div",{className:"text-sm font-semibold text-gray-700 dark:text-gray-200 mb-2",children:g.title}):null,o.jsx("div",{style:{transform:`scale(${i})`,transformOrigin:"top left",width:i===1?"100%":`${100/i}%`},children:o.jsx(RG,{canvas:g})}),g.caption?o.jsx("div",{className:"mt-2 text-xs text-gray-500 dark:text-gray-400 italic",children:g.caption}):null]});return l?o.jsxs("div",{className:"fixed inset-0 z-50 bg-white dark:bg-gray-900 flex flex-col",children:[m,y]}):o.jsxs("div",{className:"h-full flex flex-col",children:[m,y]})}function MG(e){return e?e.includes("/")?e.split("/").slice(1).join("/")||null:e:null}function IG(e,t){const n=MG(e);return{modelID:n||t||null,activeModelID:n,conversationModelID:t}}const Jb={"github-copilot":"GitHub Copilot",anthropic:"Anthropic",openai:"OpenAI",google:"Google",other:"Other"};function ev(e){return e==="recommended"?" — Recommended":e==="fast"?" — Fast":e==="premium"?" — Premium":""}function tv(e){const t={};return e.forEach(n=>{const r=n.provider||"other";t[r]||(t[r]=[]),t[r].push(n)}),t}const AS={"claude-opus-4.5":2e5,"claude-opus-4.6":2e5,"claude-sonnet-4":2e5,"claude-sonnet-4.5":2e5,"claude-sonnet-4.6":2e5,"gpt-4o":128e3,"gpt-4.1":1047576,"gpt-4-turbo":128e3,"gpt-4":8192,o1:2e5,"o1-mini":128e3,o3:2e5,"o3-mini":2e5},LG=128e3;function O0(e){const[t,n]=h.useState(e),r=h.useRef(e),a=h.useRef(0),i=h.useRef(0);return h.useEffect(()=>{if(e===r.current)return;a.current=0,r.current=t;const s=400,l=t,c=e,u=d=>{a.current||(a.current=d);const f=d-a.current,p=Math.min(f/s,1),g=1-Math.pow(1-p,3);n(Math.round(l+(c-l)*g)),p<1?i.current=requestAnimationFrame(u):n(c)};return i.current=requestAnimationFrame(u),()=>cancelAnimationFrame(i.current)},[e]),t}function OG({messages:e,isBusy:t,activeModel:n,sessionModel:r,isPrivateMode:a,registryEntries:i}){var K,W;var{t:s}=vt();const l=e.filter(j=>{var U;return((U=j.info)==null?void 0:U.role)==="user"}).length,c=e.filter(j=>{var U;return((U=j.info)==null?void 0:U.role)==="assistant"}).length;let u=0,d=0,f=0,p=null,g=null;for(let j=e.length-1;j>=0;j--){const U=e[j];if(((K=U.info)==null?void 0:K.role)==="assistant"&&((W=U.info)==null?void 0:W.mode)!=="compaction"){const le=U.info.tokens;if(le&&(le.input||le.output)){!p&&U.info.modelID&&(p=U.info.modelID),u=le.lastInput??le.input??0,d=le.lastOutput??le.output??0,f=le.lastReasoning??le.reasoning??0,U.info.contextLimit&&(g=U.info.contextLimit);break}}}const m=O0(u),y=O0(d),v=O0(f),x=m+y+v,b=u+d+f>0;let k=n;typeof r=="string"&&r?k=r:r&&r.providerID&&r.modelID&&(k=r.providerID+"/"+r.modelID);let{modelID:N,activeModelID:w}=IG(k,p),_=null;if(a){N="privacy",w="privacy";let j=null;typeof r=="string"&&r?j=r.includes("/")?r.split("/").pop():r:r&&r.modelID&&(j=r.modelID),_=j||(n?String(n).split("/").pop():null)}else p&&w&&p!==w&&(_=p);const T=h.useMemo(()=>{const j={};if(i&&i.length>0){for(const U of i)if(U.limit&&typeof U.limit.context=="number"&&U.limit.context>0){j[U.key]=U.limit.context;const le=U.key.includes("/")?U.key.split("/").pop():U.key;le&&(j[le]=U.limit.context)}}return j},[i]),A=p||N,R=!!(p&&w&&p!==w)&&(T[k]||T[N]||AS[N])||g||T[A]||T[k]||AS[A]||LG,$=Math.min(100,Math.round(m/R*100));let F="bg-green-500";$>=90?F="bg-red-500":$>=75?F="bg-orange-500":$>=50&&(F="bg-yellow-500");const G="border-gray-200 dark:border-gray-800",P="text-gray-500 dark:text-gray-400",M="text-gray-500 dark:text-gray-400",S="text-gray-700 dark:text-gray-300",I="border-gray-100 dark:border-gray-800";return o.jsxs("div",{className:`p-4 border-t ${G}`,children:[o.jsx("p",{className:`text-xs ${P} uppercase tracking-wide font-medium mb-3`,children:s("token_usage.session_info")}),o.jsxs("div",{className:"space-y-2",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:`text-xs ${M}`,children:s("token_usage.messages")}),o.jsx("span",{className:`text-xs font-medium ${S}`,children:l+c})]}),N&&o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:`text-xs ${M}`,children:s("token_usage.model")}),o.jsx("span",{className:`text-xs font-medium ${S} truncate ml-2 max-w-[140px]`,children:RS(N)})]}),_&&o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:`text-xs ${M}`,children:s("token_usage.originally")}),o.jsx("span",{className:`text-xs ${M} truncate ml-2 max-w-[140px]`,children:RS(_)})]}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:`text-xs ${M}`,children:s("token_usage.status")}),o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("div",{className:`w-1.5 h-1.5 rounded-full ${t?"bg-accent-400 animate-pulse":"bg-green-500"}`}),o.jsx("span",{className:`text-xs font-medium ${S}`,children:s(t?"token_usage.generating":"token_usage.idle")})]})]}),b?o.jsx(o.Fragment,{children:o.jsxs("div",{className:`border-t ${I} pt-2 mt-2`,children:[o.jsxs("div",{className:"mb-2",children:[o.jsxs("div",{className:"flex items-center justify-between mb-1",children:[o.jsx("span",{className:`text-xs ${M}`,children:"Context"}),o.jsxs("span",{className:`text-xs ${M}`,children:[$,"% of ",(R/1e3).toFixed(0),"k"]})]}),o.jsx("div",{className:"h-1.5 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden",children:o.jsx("div",{className:`h-full ${F} transition-all duration-300`,style:{width:`${$}%`}})})]}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:`text-xs ${M}`,children:"Input"}),o.jsx("span",{className:`text-xs font-medium ${S} tabular-nums`,children:m.toLocaleString()})]}),o.jsxs("div",{className:"flex items-center justify-between mt-1",children:[o.jsx("span",{className:`text-xs ${M}`,children:"Output"}),o.jsx("span",{className:`text-xs font-medium ${S} tabular-nums`,children:y.toLocaleString()})]}),f>0&&o.jsxs("div",{className:"flex items-center justify-between mt-1",children:[o.jsx("span",{className:`text-xs ${M}`,children:"Reasoning"}),o.jsx("span",{className:`text-xs font-medium ${S} tabular-nums`,children:v.toLocaleString()})]}),o.jsxs("div",{className:`flex items-center justify-between mt-1 pt-1 border-t ${I}`,children:[o.jsx("span",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:"Total"}),o.jsx("span",{className:"text-xs font-semibold text-gray-900 dark:text-gray-100 tabular-nums",children:x.toLocaleString()})]})]})}):o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:`text-xs ${M}`,children:"Tokens"}),o.jsx("span",{className:`text-xs ${M}`,children:"--"})]})]})]})}function RS(e){return e?{"claude-opus-4.5":"Claude Opus 4.5","claude-opus-4.6":"Claude Opus 4.6","claude-sonnet-4":"Claude Sonnet 4","claude-sonnet-4.5":"Claude Sonnet 4.5","claude-sonnet-4.6":"Claude Sonnet 4.6","gpt-4o":"GPT-4o","gpt-4.1":"GPT-4.1","gpt-4-turbo":"GPT-4 Turbo","gpt-4":"GPT-4"}[e]||e:""}function DG({sessionModel:e,activeModel:t,registryEntries:n,onModelChange:r,disabled:a,lockedReason:i}){const{t:s}=vt(),[l,c]=h.useState(!1),u=h.useRef(null),[d,f]=h.useState(-1),p=h.useRef([]);h.useEffect(()=>{if(!l)return;function b(k){u.current&&!u.current.contains(k.target)&&c(!1)}return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[l]),h.useEffect(()=>{if(!l)return;function b(k){if(k.key==="Escape"){c(!1);return}k.key!=="ArrowDown"&&k.key!=="ArrowUp"&&k.key!=="Home"&&k.key!=="End"||(k.preventDefault(),f(N=>{const w=p.current.length;if(!w)return N;const _=typeof N=="number"?N:-1;let T=_;return k.key==="ArrowDown"?T=_<w-1?_+1:0:k.key==="ArrowUp"?T=_>0?_-1:w-1:k.key==="Home"?T=0:k.key==="End"&&(T=w-1),p.current[T]&&p.current[T].focus(),T}))}return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[l]);const g=typeof e=="string"&&e.trim()?e.trim():null,m=g!=null,y=Array.isArray(n)?n:[],v=PG(g,t,y,s),x=h.useCallback(b=>{r(b===t||g&&g===b?null:b),c(!1)},[g,t,r]);return p.current.length=y.length,o.jsxs("div",{className:"relative",ref:u,children:[o.jsxs("button",{type:"button",onClick:()=>c(b=>!b),disabled:a,className:"flex items-center gap-1.5 px-2 py-1 text-xs font-medium rounded-md transition-colors "+(m||v?"bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400 hover:bg-primary-200 dark:hover:bg-primary-900/50":"text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800")+(a?" opacity-50 cursor-not-allowed":" cursor-pointer"),title:i||s("model_selector.title"),"aria-label":i||s("model_selector.title"),"aria-haspopup":"menu","aria-expanded":l,children:[i?o.jsxs("svg",{className:"w-3.5 h-3.5 flex-shrink-0 text-emerald-600 dark:text-emerald-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 11c.667 0 2 .4 2 2v3a2 2 0 11-4 0v-3c0-1.6 1.333-2 2-2zM6 11V8a6 6 0 1112 0v3"}),o.jsx("rect",{x:"5",y:"11",width:"14",height:"10",rx:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}):o.jsx("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),o.jsx("span",{className:"max-w-[120px] truncate",children:v}),o.jsx("svg",{className:`w-3 h-3 transition-transform ${l?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]}),l&&o.jsxs("div",{className:"absolute left-0 sm:left-auto sm:right-0 top-full mt-1 w-64 max-w-[calc(100vw-1.5rem)] max-h-72 overflow-y-auto bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg z-50",role:"menu","aria-label":s("model_selector.list_label"),children:[y.length===0&&o.jsx("div",{className:"px-3 py-2 text-xs text-gray-400 dark:text-gray-500",children:s("model_selector.no_models")}),y.map((b,k)=>{const N=g===b.key,w=!!t&&(b.key===t||b.target===t||b.url===t),_=b.builtin?b.key:b.displayName||b.key;return o.jsxs("button",{type:"button",ref:T=>{p.current[k]=T},tabIndex:d===k?0:-1,role:"menuitemradio","aria-checked":N||!m&&w,onClick:()=>x(b.key),className:"w-full text-left px-3 py-2 text-xs transition-colors "+(N||!m&&w?"bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-400":"text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800"),children:[o.jsx("span",{className:"font-medium",children:_}),w&&o.jsxs("span",{className:"ml-1 text-gray-400 dark:text-gray-500",children:["(",s("model_selector.default_label"),")"]})]},b.key)})]})]})}function PG(e,t,n,r){return e?MS(e,n):t?MS(t,n):r("model_selector.default_label")}function FG(e,t){if(!e||!Array.isArray(t))return null;for(let n=0;n<t.length;n++){const r=t[n];if(r&&(r.key===e||r.target===e||r.url===e))return r}return null}function MS(e,t){if(!e)return"";const n=FG(e,t);return n?n.builtin?n.key:n.displayName||n.key:typeof e=="string"&&e.includes("/")?e.split("/").slice(1).join("/"):e}function BG(e){e.sessionId;var t=e.disabledSkills,n=e.onToggle,r=e.onResetToDefaults,a=e.t,i=e.disabled,s=h.useState(!1),l=s[0],c=s[1],u=h.useState([]),d=u[0],f=u[1],p=h.useState(!1),g=p[0],m=p[1],y=h.useRef(null),v=t instanceof Array?new Set(t):new Set,x=h.useCallback(async function(){m(!0);try{var _=await Rb();f(_||[])}catch{}finally{m(!1)}},[]);h.useEffect(function(){x()},[x]),h.useEffect(function(){if(!l)return;function _(T){y.current&&!y.current.contains(T.target)&&c(!1)}return document.addEventListener("mousedown",_),function(){document.removeEventListener("mousedown",_)}},[l]);var b=v.size,k=v.has("agent"),N=k?b-1:b,w=Math.max(0,d.length-N+(k?0:1));return o.jsxs("div",{className:"relative",ref:y,children:[o.jsxs("button",{onClick:function(){c(!l)},disabled:i,className:"p-1.5 rounded-lg transition-colors "+(b>0?"bg-amber-500/10 text-amber-600 dark:text-amber-400":"text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800")+(i?" opacity-50 cursor-not-allowed":""),title:a("skills.toggle_title"),"aria-label":a("skills.toggle_title"),children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11 4a2 2 0 114 0v1a1 1 0 001 1h3a1 1 0 011 1v3a1 1 0 01-1 1h-1a2 2 0 100 4h1a1 1 0 011 1v3a1 1 0 01-1 1h-3a1 1 0 01-1-1v-1a2 2 0 10-4 0v1a1 1 0 01-1 1H7a1 1 0 01-1-1v-3a1 1 0 00-1-1H4a2 2 0 110-4h1a1 1 0 001-1V7a1 1 0 011-1h3a1 1 0 001-1V4z"})}),w>0&&o.jsx("span",{className:"absolute -top-1 -right-1 w-4 h-4 text-[9px] font-bold flex items-center justify-center bg-primary-500 text-white rounded-full",children:w})]}),l&&o.jsxs("div",{className:"absolute left-0 sm:left-auto sm:right-0 top-full mt-1 w-64 max-w-[calc(100vw-1.5rem)] bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg z-50 max-h-80 overflow-y-auto",children:[o.jsxs("div",{className:"px-3 py-2 border-b border-gray-100 dark:border-gray-800",children:[o.jsx("p",{className:"text-xs font-semibold text-gray-700 dark:text-gray-300",children:a("skills.toggle_header")}),o.jsx("p",{className:"text-[10px] text-gray-400 dark:text-gray-500 mt-0.5",children:a("skills.toggle_hint")})]}),g?o.jsx("div",{className:"flex items-center justify-center py-4",children:o.jsx("div",{className:"w-5 h-5 border-2 border-primary-500 border-t-transparent rounded-full animate-spin"})}):d.length===0?o.jsx("div",{className:"px-3 py-4 text-center",children:o.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500",children:a("skills.no_skills")})}):o.jsx("div",{className:"py-1",children:d.map(function(_){var T=v.has(_.name);return o.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 hover:bg-gray-50 dark:hover:bg-gray-800/50",children:[o.jsx("span",{className:"text-xs text-gray-700 dark:text-gray-300 truncate flex-1 mr-2",children:_.name}),o.jsx("button",{onClick:function(){n(_.name,T)},className:"relative inline-flex h-5 w-9 items-center rounded-full transition-colors flex-shrink-0 "+(T?"bg-gray-300 dark:bg-gray-600":"bg-primary-500"),role:"switch","aria-checked":!T,children:o.jsx("span",{className:"inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform "+(T?"translate-x-1":"translate-x-5")})})]},_.name)})}),o.jsx("div",{className:"px-3 py-1.5 border-t border-gray-100 dark:border-gray-800",children:o.jsx("p",{className:"text-[10px] font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-wide",children:a("skills.builtin_tools")})}),o.jsx("div",{className:"py-1",children:o.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 hover:bg-gray-50 dark:hover:bg-gray-800/50",children:[o.jsx("span",{className:"text-xs text-gray-700 dark:text-gray-300 truncate flex-1 mr-2",children:a("skills.agent_comm")}),o.jsx("button",{onClick:function(){n("agent",k)},className:"relative inline-flex h-5 w-9 items-center rounded-full transition-colors flex-shrink-0 "+(k?"bg-gray-300 dark:bg-gray-600":"bg-primary-500"),role:"switch","aria-checked":!k,children:o.jsx("span",{className:"inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform "+(k?"translate-x-1":"translate-x-5")})})]})}),r&&o.jsx("div",{className:"px-3 py-1.5 border-t border-gray-100 dark:border-gray-800",children:o.jsx("button",{onClick:r,className:"w-full text-xs font-medium text-gray-500 dark:text-gray-400 hover:text-primary-600 dark:hover:text-primary-400 hover:underline transition-colors text-center",children:a("skills.reset_to_defaults")})})]})]})}function zG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M14.25 6.087c0-.355.186-.676.401-.959.221-.29.349-.634.349-1.003 0-1.036-1.007-1.875-2.25-1.875S10.5 3.089 10.5 4.125c0 .369.128.713.349 1.003.215.283.401.604.401.959V6a.75.75 0 01-.75.75H7.5a.75.75 0 00-.75.75v2.25c0 .414-.336.75-.75.75S5.25 10.164 5.25 9.75V9A2.25 2.25 0 003 11.25v.75a.75.75 0 00.75.75h2.25c.414 0 .75.336.75.75s-.336.75-.75.75H3.75a.75.75 0 00-.75.75v.75A2.25 2.25 0 005.25 18h1.5a.75.75 0 01.75.75v.75c0 .414.336.75.75.75h6a.75.75 0 00.75-.75v-.75a.75.75 0 01.75-.75h1.5A2.25 2.25 0 0019.5 15.75v-.75a.75.75 0 00-.75-.75h-2.25a.75.75 0 01-.75-.75c0-.414.336-.75.75-.75h2.25a.75.75 0 00.75-.75v-.75A2.25 2.25 0 0017.25 9h-3a.75.75 0 01-.75-.75V6.087z"})})}function UG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M20 18h-2V9.25L12 13 6 9.25V18H4V6h1.2l6.8 4.25L18.8 6H20m0-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2z"})})}function qG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M7.71 3.5l-5.71 9.94 3.48 6.06h5.44L4.07 8.56 7.71 3.5zm1.42 0L15.84 15h-6.71L2.42 3.5h6.71zm.71 12h11.46l-3.48 6.06H6.36l3.48-6.06zm.71-1L16.84 3.5l5.71 9.94-3.48.06H10.55z"})})}function $G({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M20.317 4.37a19.791 19.791 0 00-4.885-1.515.074.074 0 00-.079.037c-.21.375-.444.864-.608 1.25a18.27 18.27 0 00-5.487 0 12.64 12.64 0 00-.617-1.25.077.077 0 00-.079-.037A19.736 19.736 0 003.677 4.37a.07.07 0 00-.032.027C.533 9.046-.32 13.58.099 18.057a.082.082 0 00.031.057 19.9 19.9 0 005.993 3.03.078.078 0 00.084-.028c.462-.63.874-1.295 1.226-1.994a.076.076 0 00-.041-.106 13.107 13.107 0 01-1.872-.892.077.077 0 01-.008-.128 10.2 10.2 0 00.372-.292.074.074 0 01.077-.01c3.928 1.793 8.18 1.793 12.062 0a.074.074 0 01.078.01c.12.098.246.198.373.292a.077.077 0 01-.006.127 12.299 12.299 0 01-1.873.892.077.077 0 00-.041.107c.36.698.772 1.362 1.225 1.993a.076.076 0 00.084.028 19.839 19.839 0 006.002-3.03.077.077 0 00.032-.054c.5-5.177-.838-9.674-3.549-13.66a.061.061 0 00-.031-.03zM8.02 15.33c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.956-2.419 2.157-2.419 1.21 0 2.176 1.096 2.157 2.42 0 1.333-.956 2.418-2.157 2.418zm7.975 0c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.955-2.419 2.157-2.419 1.21 0 2.176 1.096 2.157 2.42 0 1.333-.946 2.418-2.157 2.418z"})})}function HG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"})})}function WG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M3 6l3.5 12h2l2.5-8 2.5 8h2L19 6h-2.5l-2.25 8L12 6h-2l-2.25 8L5.5 6H3z"})})}function VG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M5 3a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2V5a2 2 0 00-2-2H5zm11.293 6.707l-5.5 5.5a1 1 0 01-1.414 0l-2.5-2.5a1 1 0 111.414-1.414L10.086 13.1l4.793-4.793a1 1 0 111.414 1.4z"})})}function GG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M4 18V6h3.2l2.8 7 2.8-7H16v12h-2.4V9.6L10.6 18H9.4L6.4 9.6V18H4z"})})}function KG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 15.5v-5l-3 3v-4l3-3v-3l4 4-4 4v4z"})})}function YG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})})}function QG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"})})}function XG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("path",{d:"M6 2l6 3.75L6 9.5.002 5.75 6 2zm12 0l6 3.75-6 3.75-5.998-3.75L18 2zM.002 13.25L6 9.5l6 3.75L6 17 .002 13.25zm17.998-3.75l6 3.75L18 17l-5.998-3.75L18 9.5zM6 18.25l6-3.75 6 3.75-6 3.75-6-3.75z"})})}function ZG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6v12m-3-2.818l.879.659c1.171.879 3.07.879 4.242 0 1.172-.879 1.172-2.303 0-3.182C13.536 12.219 12.768 12 12 12c-.725 0-1.45-.22-2.003-.659-1.106-.879-1.106-2.303 0-3.182s2.9-.879 4.006 0l.415.33M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}function JG({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 012.25-2.25h13.5A2.25 2.25 0 0121 7.5v11.25m-18 0A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75m-18 0v-7.5A2.25 2.25 0 015.25 9h13.5A2.25 2.25 0 0121 11.25v7.5"})})}function eK({className:e,...t}){return o.jsx("svg",{className:e,...t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})})}const IS={gmail:UG,gdrive:qG,discord:$G,whatsapp:HG,wrike:WG,gtasks:VG,mailchimp:GG,bamboohr:KG,pandadoc:YG,exa:QG,dropbox:XG,freshbooks:ZG,gcal:JG,docx2md:eK};function tK(e){return Object.prototype.hasOwnProperty.call(IS,e)?IS[e]:zG}const LS={gmail:"#EA4335",gdrive:"#4285F4",discord:"#5865F2",whatsapp:"#25D366",wrike:"#08CF65",gtasks:"#4285F4",mailchimp:"#FFE01B",bamboohr:"#73C41D",pandadoc:"#4ABB5A",exa:"#6366F1",dropbox:"#0061FF",freshbooks:"#00B7E3",gcal:"#4285F4",docx2md:"#6B7280"};function nK({installed:e,configured:t,t:n}){return e?t?o.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",children:[o.jsx("svg",{className:"w-3 h-3 mr-1",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}),n("skills.configured")]}):o.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-400",children:[o.jsx("svg",{className:"w-3 h-3 mr-1",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})}),n("skills.needs_setup")]}):o.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-gray-100 dark:bg-gray-800 text-gray-500 dark:text-gray-400",children:n("skills.not_installed")})}function rK({skill:e,onClose:t,onSaved:n}){var{t:r}=vt(),a=dl(),[i,s]=h.useState({}),[l,c]=h.useState(!0),[u,d]=h.useState(!1),[f,p]=h.useState(null),[g,m]=h.useState(!1),[y,v]=h.useState(null);h.useEffect(function(){var A=!1;async function D(){try{var R=await uB(e.name);if(A)return;v(R);for(var $=Object.create(null),F=Object.keys(R.tokens||{}),G=0;G<F.length;G++){var P=F[G],M=R.tokens[P]||{},S=M.env||P;$[S]=""}s($),c(!1)}catch(I){A||(p(I.message),c(!1))}}return D(),function(){A=!0}},[e.name]);var x=h.useMemo(function(){if(!y||!y.tokens)return null;for(var A=Object.keys(y.tokens),D=0;D<A.length;D++){var R=y.tokens[A[D]]||{};if(R.description&&R.description.includes("OAuth")){for(var $=null,F=null,G=null,P=Object.entries(y.tokens),M=0;M<P.length;M++){var S=P[M][0];S.includes("REFRESH_TOKEN")&&($=S),(S.includes("CLIENT_ID")||S.includes("APP_KEY"))&&(F=S),(S.includes("CLIENT_SECRET")||S.includes("APP_SECRET"))&&(G=S)}if($&&F){var I=y.tokens[$]&&y.tokens[$].configured,B=y.tokens[F]&&y.tokens[F].configured,Q=G&&y.tokens[G]&&y.tokens[G].configured,C="OAuth";return e.name==="gmail"||e.name==="gdrive"||e.name==="gcal"||e.name==="gtasks"?C="Google":e.name==="dropbox"?C="Dropbox":e.name==="freshbooks"&&(C="FreshBooks"),{provider:C,canConnect:B&&Q&&!I,refreshConfigured:I,clientIdConfigured:B,clientSecretConfigured:Q}}}}return null},[y,e.name]),b=h.useCallback(async function(){p(null),m(!0);try{var A=await xB(e.name),D=600,R=700,$=(window.screen.width-D)/2,F=(window.screen.height-R)/2,G=window.open(A.authorizeUrl,"oauth_popup","width="+D+",height="+R+",left="+$+",top="+F+",scrollbars=yes");if(G)var P=setInterval(function(){G.closed&&(clearInterval(P),m(!1),n())},500);else p("Popup blocked. Please allow popups or visit: "+A.authorizeUrl),m(!1)}catch(M){p(M.message),m(!1)}},[e.name,n]),k=h.useCallback(async function(){p(null),d(!0);try{for(var A=Object.create(null),D=Object.keys(i),R=0;R<D.length;R++){var $=D[R];i[$]&&i[$].trim()&&(A[$]=i[$].trim())}if(Object.keys(A).length===0){p(r("skills.enter_token")),d(!1);return}await gB(e.name,A),n()}catch(F){p(F.message)}finally{d(!1)}},[i,e.name,n,r]),N=h.useCallback(async function(){if(await a({title:r("skills.clear_title"),message:r("skills.clear_confirm",{skill:e.name}),destructive:!0})){p(null),d(!0);try{await hB(e.name),n()}catch(A){p(A.message)}finally{d(!1)}}},[e.name,n,a,r]),w=h.useCallback(function(A,D){s(function(R){var $=Object.assign(Object.create(null),R);return $[A]=D,$})},[]),_=y?Object.entries(y.tokens||{}).map(function(A){var D=A[0],R=A[1],$=R&&R.env||D;return{name:D,env:$,description:R.description,configured:R.configured,maskedValue:R.maskedValue}}):[],T=h.useRef(null);return h.useEffect(function(){function A(D){D.key==="Escape"&&t()}return document.addEventListener("keydown",A),T.current&&T.current.focus(),function(){document.removeEventListener("keydown",A)}},[t]),o.jsx("div",{ref:T,tabIndex:-1,className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:t,role:"dialog","aria-modal":"true","aria-label":r("skills.configure_skill",{skill:e.name}),children:o.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-xl shadow-2xl w-full max-w-lg mx-4 p-6",onClick:function(A){A.stopPropagation()},children:[o.jsxs("div",{className:"flex items-center justify-between mb-4",children:[o.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:r("skills.configure_skill",{skill:e.name})}),o.jsx("button",{onClick:t,className:"p-1 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-400","aria-label":r("skills.close_credential_editor"),children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),l&&o.jsx("div",{className:"flex items-center justify-center py-8",children:o.jsx("div",{className:"w-6 h-6 border-2 border-primary-500 border-t-transparent rounded-full animate-spin"})}),!l&&_.length>0&&o.jsx("div",{className:"space-y-3 mb-4",children:_.map(function(A){return o.jsxs("div",{children:[o.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:[A.env,A.configured&&o.jsxs("span",{className:"ml-2 text-xs text-green-600 dark:text-green-400",children:["(",r("skills.current_value",{value:A.maskedValue}),")"]})]}),A.description&&o.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1",children:A.description}),o.jsx("input",{type:"password",placeholder:A.configured?r("skills.leave_blank"):r("skills.enter_value"),value:i[A.env]||"",onChange:function(D){w(A.env,D.target.value)},className:"w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 placeholder-gray-400"})]},A.env)})}),!l&&x&&o.jsx("div",{className:"mb-4 p-4 bg-gray-50 dark:bg-gray-800/50 rounded-lg border border-gray-200 dark:border-gray-700",children:x.canConnect?o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-3",children:r("skills.oauth_connect_hint",{provider:x.provider})}),o.jsx("button",{onClick:b,disabled:g||u,className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-primary-500 hover:bg-primary-600 text-white font-medium rounded-lg disabled:opacity-50 transition-colors",children:g?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}),r("skills.oauth_connecting")]}):o.jsxs(o.Fragment,{children:[o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"})}),r("skills.oauth_connect",{provider:x.provider})]})})]}):x.refreshConfigured?o.jsxs("p",{className:"text-sm text-green-600 dark:text-green-400 flex items-center gap-2",children:[o.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}),r("skills.oauth_connected",{provider:x.provider})]}):o.jsx("p",{className:"text-sm text-amber-600 dark:text-amber-400",children:r("skills.oauth_needs_credentials",{provider:x.provider})})}),!l&&!f&&_.length===0&&o.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 py-4",children:r("skills.no_credentials_needed")}),f&&o.jsx("p",{className:"text-sm text-red-600 dark:text-red-400 mb-3",children:f}),!l&&_.length>0&&o.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-gray-200 dark:border-gray-700",children:[o.jsx("button",{onClick:N,disabled:u,className:"text-sm text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 disabled:opacity-50",children:r("skills.clear_all")}),o.jsxs("div",{className:"flex gap-2",children:[o.jsx("button",{onClick:t,className:"px-3 py-1.5 text-sm text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg",children:r("skills.cancel")}),o.jsx("button",{onClick:k,disabled:u,className:"px-4 py-1.5 text-sm font-medium bg-primary-500 hover:bg-primary-600 text-white rounded-lg disabled:opacity-50 transition-colors",children:r(u?"skills.saving":"skills.save")})]})]})]})})}function aK({skill:e,installed:t,updateInfo:n,updatingSkill:r,onConfigure:a,onInstall:i,onUpdate:s,onUninstall:l,skillDefaultEnabled:c,onToggleDefault:u,t:d}){var f=tK(e.name),p=Object.prototype.hasOwnProperty.call(LS,e.name)?LS[e.name]:"#6B7280",[g,m]=h.useState(!1),y=r===e.name,v=n&&n.hasUpdate,x=h.useCallback(async function(){m(!0);try{await i(e)}finally{m(!1)}},[e,i]),b=h.useCallback(function(){s&&s(e.name)},[e.name,s]);return o.jsxs("div",{className:"group relative bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-xl p-4 hover:shadow-md dark:hover:shadow-gray-800/50 transition-all flex flex-col",children:[o.jsx("div",{className:"absolute top-0 left-4 right-4 h-0.5 rounded-full",style:{backgroundColor:p}}),o.jsxs("div",{className:"flex items-start gap-3 mt-1 flex-1",children:[o.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center flex-shrink-0",style:{backgroundColor:p+"15"},children:o.jsx(f,{className:"w-5 h-5",style:{color:p}})}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[o.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100 truncate",children:e.name}),o.jsx(nK,{installed:t,configured:t&&e.allTokensConfigured,t:d}),t&&v&&o.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400",children:[o.jsx("svg",{className:"w-3 h-3 mr-1",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),"v",n.latestVersion]}),t&&n&&!v&&o.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",children:d("skills.up_to_date")})]}),o.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 line-clamp-2",children:e.description||d("skills.no_description")}),e.version&&o.jsxs("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:["v",e.version]})]})]}),o.jsx("div",{className:"mt-auto pt-3 flex items-center gap-2",children:t?o.jsxs(o.Fragment,{children:[o.jsx("button",{onClick:function(){a(e)},className:"flex-1 px-3 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-lg transition-colors",children:d("skills.configure")}),u&&o.jsxs("button",{onClick:function(){u(e.name,!c)},title:d("skills.default_for_new_sessions"),className:"px-2 py-1.5 text-xs font-medium rounded-lg transition-colors flex items-center gap-1 "+(c?"text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20 hover:bg-primary-100 dark:hover:bg-primary-900/40":"text-gray-400 dark:text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-800"),children:[o.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:c?o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"}):o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),d("skills.default")]}),v&&o.jsx("button",{onClick:b,disabled:y,className:"px-3 py-1.5 text-xs font-medium text-white bg-primary-500 hover:bg-primary-600 rounded-lg transition-colors disabled:opacity-50",children:y?o.jsxs("span",{className:"flex items-center gap-1",children:[o.jsx("svg",{className:"w-3 h-3 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),d("skills.updating")]}):d("skills.update")}),l&&o.jsx("button",{onClick:function(){l(e)},title:d("skills.uninstall"),className:"px-2 py-1.5 text-xs font-medium text-gray-400 hover:text-red-500 dark:hover:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 rounded-lg transition-colors","aria-label":d("skills.uninstall"),children:o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]}):o.jsx("button",{onClick:x,disabled:g,className:"flex-1 px-3 py-1.5 text-xs font-medium text-white bg-primary-500 hover:bg-primary-600 rounded-lg transition-colors disabled:opacity-50",children:g?o.jsxs("span",{className:"flex items-center justify-center gap-1",children:[o.jsx("svg",{className:"w-3 h-3 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),d("skills.installing")]}):d("skills.install")})})]})}function iK({onBack:e}){var{t}=vt(),[n,r]=h.useState([]),[a,i]=h.useState([]),[s,l]=h.useState(!0),[c,u]=h.useState(null),[d,f]=h.useState(null),[p,g]=h.useState("all"),[m,y]=h.useState(""),[v,x]=h.useState(!1),[b,k]=h.useState(Object.create(null)),[N,w]=h.useState(null),[_,T]=h.useState(!1),[A,D]=h.useState(Object.create(null)),R=dl(),$=h.useCallback(async function(){l(!0),u(null),T(!1);try{var U=await Promise.allSettled([Rb(),cB(),eT()]),le=U[0].status==="fulfilled"?U[0].value:[],Z=U[1].status==="fulfilled"?U[1].value:[],ke=U[2].status==="fulfilled"?U[2].value.skillDefaults||{}:{};r(le),i(Z),D(ke);var re=[];U[0].status==="rejected"&&re.push(t("skills.load_installed_failed",{error:U[0].reason.message})),U[1].status==="rejected"&&re.push(t("skills.load_marketplace_failed",{error:U[1].reason.message})),re.length>0&&u(re.join("; "))}catch(X){u(X.message)}finally{l(!1)}},[t]);h.useEffect(function(){$()},[$]);var F=[],G=new Set(n.map(function(U){return U.name}));n.forEach(function(U){F.push(Object.assign({},U,{_installed:!0}))}),a.forEach(function(U){G.has(U.name)||F.push(Object.assign({},U,{_installed:!1,allTokensConfigured:!1}))});var P=F;if(p==="installed"?P=F.filter(function(U){return U._installed}):p==="available"&&(P=F.filter(function(U){return!U._installed})),m){var M=m.toLowerCase();P=P.filter(function(U){return U.name&&U.name.toLowerCase().indexOf(M)!==-1||U.description&&U.description.toLowerCase().indexOf(M)!==-1||U.category&&U.category.toLowerCase().indexOf(M)!==-1})}var S=h.useCallback(async function(U){try{await dB(U.name),$()}catch(le){u(t("skills.install_failed",{error:le.message}))}},[$,t]),I=h.useCallback(function(U){f(U)},[]),B=h.useCallback(async function(U){if(await R({title:t("skills.uninstall_title"),message:t("skills.uninstall_confirm",{skill:U.name}),destructive:!0,confirmLabel:t("skills.uninstall")}))try{await mB(U.name),$()}catch(le){u(t("skills.uninstall_failed",{error:le.message}))}},[$,R,t]),Q=h.useCallback(function(){f(null),$()},[$]),C=h.useCallback(async function(U,le){D(function(ke){var re=Object.assign({},ke);return le?re[U]=!0:delete re[U],re});try{var Z={};Z[U]=le,await yB(Z)}catch(ke){D(function(re){var X=Object.assign({},re);return le?delete X[U]:X[U]=!0,X}),u(ke.message)}},[]),K=h.useCallback(async function(){x(!0),u(null);try{var U=await pB(),le=Object.create(null);(U.skills||[]).forEach(function(Z){le[Z.name]={hasUpdate:Z.hasUpdate,latestVersion:Z.latestVersion,currentVersion:Z.currentVersion}}),k(le),T(!0)}catch(Z){u(Z.message)}finally{x(!1)}},[]),W=h.useCallback(async function(U){w(U),u(null);try{var le=await fB(U);le.updated&&(k(function(Z){var ke=Object.assign(Object.create(null),Z);return ke[U]={hasUpdate:!1,latestVersion:Z[U]?Z[U].latestVersion:null,currentVersion:Z[U]?Z[U].currentVersion:null},ke}),$())}catch(Z){u(t("skills.update_failed")+": "+Z.message)}finally{w(null)}},[$,t]),j=Object.values(b).filter(function(U){return U&&U.hasUpdate}).length;return o.jsxs("div",{className:"h-full flex flex-col bg-white dark:bg-gray-950 min-h-0",children:[o.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between px-6 py-4 border-b border-gray-200 dark:border-gray-800",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("button",{onClick:e,className:"p-1.5 rounded-lg text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors","aria-label":t("skills.back_to_chat"),children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})})}),o.jsxs("div",{children:[o.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:t("skills.skill_management")}),o.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:t("skills.installed_count",{installed:n.length,available:a.filter(function(U){return!G.has(U.name)}).length})})]})]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("button",{onClick:K,disabled:v||s,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-gray-600 dark:text-gray-300 bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-lg transition-colors disabled:opacity-50",children:v?o.jsxs(o.Fragment,{children:[o.jsx("svg",{className:"w-3.5 h-3.5 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),t("skills.checking_updates")]}):o.jsxs(o.Fragment,{children:[o.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),t("skills.check_updates")]})}),j>0&&o.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400 rounded-full",children:t("skills.updates_available",{count:j})}),_&&j===0&&!v&&o.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 rounded-full",children:t("skills.no_updates")}),o.jsx("div",{className:"flex items-center gap-1 bg-gray-100 dark:bg-gray-800 rounded-lg p-0.5",children:["all","installed","available"].map(function(U){return o.jsx("button",{onClick:function(){g(U)},className:"px-3 py-1 text-xs font-medium rounded-md transition-colors "+(p===U?"bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 shadow-sm":"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300"),children:t("skills.tab_"+U)},U)})})]})]}),o.jsx("div",{className:"flex-shrink-0 px-6 py-3 border-b border-gray-100 dark:border-gray-800/50",children:o.jsxs("div",{className:"relative",children:[o.jsx("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),o.jsx("input",{type:"text",placeholder:t("skills.search_placeholder"),value:m,onChange:function(U){y(U.target.value)},className:"w-full pl-10 pr-4 py-2 text-sm bg-gray-50 dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg text-gray-900 dark:text-gray-100 placeholder-gray-400 outline-none focus:ring-2 focus:ring-primary-500/30 focus:border-primary-500"})]})}),o.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden p-6 min-h-0",children:[s&&o.jsx("div",{className:"flex items-center justify-center py-12",children:o.jsx("div",{className:"w-8 h-8 border-2 border-primary-500 border-t-transparent rounded-full animate-spin"})}),c&&o.jsx("div",{className:"mb-4 p-3 bg-red-50 dark:bg-red-900/20 rounded-lg border border-red-200 dark:border-red-800",children:o.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:c})}),!s&&P.length===0&&o.jsx("div",{className:"text-center py-12",children:o.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:t(m?"skills.no_match":"skills.no_skills")})}),!s&&P.length>0&&o.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:P.map(function(U){return o.jsx(aK,{skill:U,installed:U._installed,updateInfo:b[U.name],updatingSkill:N,onConfigure:I,onInstall:S,onUpdate:W,onUninstall:U._installed?B:null,skillDefaultEnabled:!!A[U.name],onToggleDefault:U._installed?C:null,t},U.name)})})]}),d&&o.jsx(rK,{skill:d,onClose:function(){f(null)},onSaved:Q})]})}const Pt="";function Ft(e,t={}){return fetch(e,{credentials:"include",...t})}async function sK(){const e=await Ft(Pt+"/api/agents");if(!e.ok)throw new Error("Failed to fetch agents: "+e.statusText);return e.json()}async function oK(e){const t=await Ft(Pt+"/api/agents/"+encodeURIComponent(e));if(!t.ok)throw new Error("Failed to fetch agent: "+t.statusText);return t.json()}async function lx(e){const t=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/start",{method:"POST"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error||"Failed to start agent")}return t.json()}async function cx(e){const t=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/stop",{method:"POST"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error||"Failed to stop agent")}return t.json()}async function Eu(e,t){const n={};t&&t.clean&&(n.clean=!0);const r=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok){const a=await r.json().catch(()=>({}));throw new Error(a.error||"Failed to restart agent")}return r.json()}async function ux(e,t){const n={};t&&t.level&&(n.level=t.level),t&&t.span&&(n.span=t.span);const r=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/pause",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok){const a=await r.json().catch(()=>({}));throw new Error(a.error||"Failed to pause agent")}return r.json()}async function dx(e){const t=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/unpause",{method:"POST"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error||"Failed to unpause agent")}return t.json()}async function lK(e,t,n,r){const a={message:t,priority:n};r!=null&&(a.replyToInbox=r);const i=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/inbox",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok){const s=await i.json().catch(()=>({}));throw new Error(s.error||"Failed to send message to agent")}return i.json()}async function cK(e,t,n){const r={message:t};n!=null&&(r.replyToInbox=n);const a=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/interrupt",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!a.ok){const i=await a.json().catch(()=>({}));throw new Error(i.error||"Failed to send urgent interrupt to agent")}return a.json()}async function uK(e,t){let n=Pt+"/api/agents/"+encodeURIComponent(e)+"/messages";t&&t.refresh&&(n+="?refresh=true");const r=await Ft(n);if(!r.ok)throw new Error("Failed to fetch agent messages: "+r.statusText);return r.json()}async function dK(){const e=await Ft(Pt+"/api/pricing");if(!e.ok)throw new Error("Failed to fetch pricing: "+e.statusText);return e.json()}async function fK(e){const t=await Ft(Pt+"/api/pricing",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error||"Failed to update pricing")}return t.json()}async function pK(){const e=await Ft(Pt+"/api/pricing/reset",{method:"POST"});if(!e.ok){const t=await e.json().catch(()=>({}));throw new Error(t.error||"Failed to reset pricing")}return e.json()}async function gK(e,t=!1){const n=Pt+"/api/agents/"+encodeURIComponent(e)+(t?"?force=true":""),r=await Ft(n,{method:"DELETE"});if(!r.ok){const a=await r.json().catch(()=>({}));throw new Error(a.error||"Failed to delete agent")}return r.json()}async function hK(e){const t=await Ft(Pt+"/api/agents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error||"Failed to create agent")}return t.json()}async function SA(){const e=await Ft(Pt+"/api/skills");if(!e.ok)throw new Error("Failed to fetch skills: "+e.statusText);return e.json()}async function nv(){const e=await Ft(Pt+"/api/models");if(!e.ok)throw new Error("Failed to fetch models: "+e.statusText);return e.json()}async function mK(e,t){const n=await Ft(Pt+"/api/agents/"+encodeURIComponent(e),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||"Failed to update agent")}return n.json()}async function yK(e){const t=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/agents-md");if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error||"Failed to fetch AGENTS.md")}return t.json()}async function xK(e,t){const n=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/agents-md",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||"Failed to update AGENTS.md")}return n.json()}async function CA(e){const t=await Ft(Pt+"/api/agents/"+encodeURIComponent(e)+"/export");if(!t.ok){const l=await t.json().catch(()=>({}));throw new Error(l.error||"Failed to export agent")}const n=await t.text(),r=new Blob([n],{type:"text/yaml"}),a=URL.createObjectURL(r),i=t.headers.get("X-Filename")||e+".agent.yaml",s=document.createElement("a");s.href=a,s.download=i,document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>URL.revokeObjectURL(a),5e3)}async function bK(e,t){const n=new URLSearchParams,r=n.toString()?"?"+n.toString():"",a=await Ft(Pt+"/api/agents/import"+r,{method:"POST",headers:{"Content-Type":"text/yaml"},body:e});if(!a.ok){const i=await a.json().catch(()=>({}));throw new Error(i.error||"Failed to import agent")}return a.json()}async function D0(){const e=await Ft(Pt+"/api/system/updates");if(!e.ok){const t="Failed to check for updates",n=await e.json().catch(()=>({})),r=n.error||n.message||n.output||e.statusText;throw r?r.indexOf(t)===0||r===t?new Error(r):new Error(t+": "+r):new Error(t)}return e.json()}async function vK(){const e=await Ft(Pt+"/api/system/update",{method:"POST"});if(!e.ok){const n="Failed to perform update",r=await e.json().catch(()=>({})),a=r.error||r.message||r.output||e.statusText;throw a?a.indexOf(n)===0||a===n?new Error(a):new Error(n+": "+a):new Error(n)}const t=await e.json();if(t.status!=="success"){let n=t.error||t.message||"";throw t.output&&!t.error&&!t.message?n="Update returned status: "+(t.status||"failed")+(t.output?": "+t.output:""):t.output&&(n+=t.output?" ("+t.output+")":""),n||(n="Update returned unexpected status: "+(t.status||"unknown")),new Error(n)}return t}async function OS(){const e=await Ft(Pt+"/api/models/registry");if(!e.ok)throw new Error("Failed to fetch model registry: "+e.statusText);return e.json()}async function DS(e,t){const n=await Ft(Pt+"/api/models/registry",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,...t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||"Failed to save model: "+n.statusText)}return n.json()}async function PS(e){const t=await Ft(Pt+"/api/models/registry/"+encodeURIComponent(e),{method:"DELETE"});if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n.error||"Failed to delete model: "+t.statusText)}return t.json()}function jA(e){const t=typeof e=="string"?e.split("-"):null;if(t&&t.length===3){const n=Number(t[0]),r=Number(t[1]),a=Number(t[2]);if(!Number.isNaN(n)&&!Number.isNaN(r)&&!Number.isNaN(a))return new Date(n,r-1,a)}return new Date(e)}function kK(e){const t=jA(e),n=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];return n[t.getDay()]+", "+r[t.getMonth()]+" "+t.getDate()}function bc(e){return e>=1e6?(e/1e6).toFixed(1)+"M":e>=1e3?(e/1e3).toFixed(1)+"K":e.toString()}function _K({data:e}){if(!e||e.length===0)return o.jsx("div",{className:"h-32 flex items-center justify-center text-sm text-gray-400 dark:text-gray-500",children:"No usage data available"});const t=280,n=120,r={top:10,right:10,bottom:25,left:40},a=t-r.left-r.right,i=n-r.top-r.bottom,s=Math.max(...e.map(p=>(p.input||0)+(p.output||0)+(p.cached||0)),1),l=a/e.length,c=Math.max(8,l*.6),u=(l-c)/2,d=p=>i-p/s*i,f=[0,.25,.5,.75,1].map(p=>Math.round(s*p));return o.jsxs("div",{className:"relative",children:[o.jsxs("svg",{width:"100%",height:n,viewBox:`0 0 ${t} ${n}`,className:"overflow-visible",children:[f.map((p,g)=>{const m=r.top+d(p);return o.jsxs("g",{children:[o.jsx("line",{x1:r.left,y1:m,x2:t-r.right,y2:m,stroke:"currentColor",strokeOpacity:.1,className:"text-gray-400 dark:text-gray-600"}),o.jsx("text",{x:r.left-5,y:m,textAnchor:"end",dominantBaseline:"middle",className:"text-[9px] fill-gray-400 dark:fill-gray-500",children:bc(p)})]},g)}),e.map((p,g)=>{const m=r.left+g*l+u,y=p.input||0,v=p.output||0,x=p.cached||0,b=y/s*i,k=v/s*i,N=x/s*i,w=r.top+i-b,_=w-k,T=_-N,A=jA(p.date),D=["S","M","T","W","T","F","S"][A.getDay()];return o.jsxs("g",{className:"group",children:[o.jsx("rect",{x:m-u,y:r.top,width:l,height:i,fill:"transparent",className:"cursor-pointer"}),y>0&&o.jsx("rect",{x:m,y:w,width:c,height:b,rx:2,className:"fill-blue-500 dark:fill-blue-400 transition-opacity group-hover:opacity-80"}),v>0&&o.jsx("rect",{x:m,y:_,width:c,height:k,rx:2,className:"fill-green-500 dark:fill-green-400 transition-opacity group-hover:opacity-80"}),x>0&&o.jsx("rect",{x:m,y:T,width:c,height:N,rx:2,className:"fill-purple-500 dark:fill-purple-400 transition-opacity group-hover:opacity-80"}),o.jsx("text",{x:m+c/2,y:n-5,textAnchor:"middle",className:"text-[9px] fill-gray-400 dark:fill-gray-500",children:D}),o.jsxs("g",{className:"opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none",children:[o.jsx("rect",{x:m+c/2-45,y:Math.min(T,_,w)-50,width:90,height:45,rx:4,className:"fill-gray-900 dark:fill-gray-100"}),o.jsx("text",{x:m+c/2,y:Math.min(T,_,w)-38,textAnchor:"middle",className:"text-[9px] fill-white dark:fill-gray-900 font-medium",children:kK(p.date)}),o.jsxs("text",{x:m+c/2,y:Math.min(T,_,w)-26,textAnchor:"middle",className:"text-[8px] fill-blue-300 dark:fill-blue-600",children:["In: ",bc(y)]}),o.jsxs("text",{x:m+c/2,y:Math.min(T,_,w)-16,textAnchor:"middle",className:"text-[8px] fill-green-300 dark:fill-green-600",children:["Out: ",bc(v)]}),o.jsxs("text",{x:m+c/2,y:Math.min(T,_,w)-6,textAnchor:"middle",className:"text-[8px] fill-purple-300 dark:fill-purple-600",children:["Cache: ",bc(x)]})]})]},g)})]}),o.jsxs("div",{className:"flex items-center justify-center gap-4 mt-2 text-xs",children:[o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx("div",{className:"w-2 h-2 rounded-sm bg-blue-500 dark:bg-blue-400"}),o.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Input"})]}),o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx("div",{className:"w-2 h-2 rounded-sm bg-green-500 dark:bg-green-400"}),o.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Output"})]}),o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx("div",{className:"w-2 h-2 rounded-sm bg-purple-500 dark:bg-purple-400"}),o.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:"Cached"})]})]})]})}function wK({agentName:e,onClose:t,onToolPartsChange:n,hackerMode:r}){var{t:a}=vt(),[i,s]=h.useState([]),[l,c]=h.useState(!0),[u,d]=h.useState(null),[f,p]=h.useState(!1),[g,m]=h.useState(""),[y,v]=h.useState(!0),[x,b]=h.useState(!1),[k,N]=h.useState(!1),[w,_]=h.useState(!1),[T,A]=h.useState(!1),D=h.useRef(null),R=h.useRef(null),$=h.useRef(!0),F=h.useRef([]),G=h.useRef(null),P=h.useRef(null),M=h.useRef(null),S=h.useRef(null);h.useEffect(function(){F.current=i},[i]);var I=h.useCallback(async function(Z,ke){if(e){ke!==!1&&c(!0);try{var re=await uK(e,{refresh:!!Z}),X=re.messages||[],Ne=F.current,ve=X.length!==Ne.length;if(!ve&&X.length>0&&Ne.length>0){var me=X[X.length-1],pe=Ne[Ne.length-1];if(me.info.id!==pe.info.id&&(ve=!0),!ve){var Le=me.parts||[],Se=pe.parts||[];if(Le.length!==Se.length)ve=!0;else for(var Te=0;Te<Le.length&&!ve;Te++){var Fe=Le[Te]||{},fe=Se[Te]||{},xe=Fe.state?Fe.state.status:Fe.status,Ce=fe.state?fe.state.status:fe.status;(Fe.id!==fe.id||xe!==Ce)&&(ve=!0)}}}ve&&s(X.slice()),d(null)}catch(ue){console.error("Failed to load messages:",ue),d(ue.message)}finally{ke!==!1&&c(!1)}}},[e]);h.useEffect(function(){I(!0);var Z=setInterval(function(){I(!0,!1)},5e3);return function(){clearInterval(Z),P.current&&clearTimeout(P.current),S.current&&clearTimeout(S.current)}},[I]),h.useEffect(function(){$.current&&D.current&&D.current.scrollIntoView({behavior:"smooth"})},[i]);var B=h.useCallback(function(){var Z=R.current;Z&&($.current=Z.scrollHeight-Z.scrollTop-Z.clientHeight<50)},[]),Q=h.useMemo(function(){for(var Z=null,ke=i.length-1;ke>=0;ke--)if(i[ke].info&&i[ke].info.role==="assistant"){Z=i[ke];break}return Z?(Z.parts||[]).filter(function(re){return re.type==="tool"}):[]},[i]);h.useEffect(function(){n&&n(Q)},[Q,n]);var C=h.useCallback(async function(){if(!(!g.trim()||x)){b(!0),N(!1),_(!1),A(!1),d(null);try{await lK(e,g.trim(),"normal",y),m(""),N(!0),P.current&&clearTimeout(P.current),P.current=setTimeout(function(){N(!1),p(!1),P.current=null},1500),S.current&&clearTimeout(S.current),S.current=setTimeout(function(){I(!0,!1),S.current=null},500)}catch(Z){d(Z.message)}finally{b(!1)}}},[e,g,y,x,I]),K=h.useCallback(async function(){if(!(!g.trim()||x)){if(!T){A(!0);return}b(!0),N(!1),_(!0),A(!1),d(null);try{await cK(e,g.trim(),y),m(""),N(!0),P.current&&clearTimeout(P.current),P.current=setTimeout(function(){N(!1),p(!1),P.current=null},1500),S.current&&clearTimeout(S.current),S.current=setTimeout(function(){I(!0,!1),S.current=null},500)}catch(Z){d(Z.message)}finally{b(!1)}}},[e,g,x,T,y,I]),W=h.useCallback(function(){p(!1),A(!1),d(null),P.current&&(clearTimeout(P.current),P.current=null),S.current&&(clearTimeout(S.current),S.current=null),N(!1)},[]);h.useEffect(function(){if(!f)return;function Z(ke){ke.key==="Escape"&&!x&&W()}return document.addEventListener("keydown",Z),function(){document.removeEventListener("keydown",Z)}},[f,W,x]),h.useEffect(function(){if(!(!f||!M.current)){var Z=M.current;Z.contains(document.activeElement)||Z.focus()}},[f]);var j=h.useCallback(function(Z){Z.target===Z.currentTarget&&!x&&W()},[W,x]),U=h.useCallback(function(Z){Z.key==="Enter"&&!Z.shiftKey&&!T&&(Z.preventDefault(),C())},[C,T]),le=h.useCallback(function(){},[]);return o.jsxs("div",{className:"h-full flex flex-col bg-white dark:bg-gray-900 relative",children:[o.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-800",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("button",{onClick:t,className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-500 dark:text-gray-400 transition-colors",title:a("agents.back"),children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 19l-7-7 7-7"})})}),o.jsxs("div",{children:[o.jsx("h2",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:"Conversation"}),o.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:[e," - ",i.length," messages"]})]})]}),o.jsx("button",{onClick:function(){$.current=!0,I(!0),D.current&&D.current.scrollIntoView({behavior:"smooth"})},disabled:l,className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-400 transition-colors disabled:opacity-50",title:a("agents.refresh"),children:o.jsx("svg",{className:`w-4 h-4 ${l?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]}),u&&o.jsxs("div",{className:"mx-4 mt-3 px-4 py-2 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 text-sm rounded-lg flex items-center justify-between",children:[o.jsx("span",{children:u}),o.jsx("button",{onClick:function(){d(null)},className:"ml-2 text-red-400 hover:text-red-600",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),k&&o.jsxs("div",{className:`mx-4 mt-3 px-4 py-2 text-sm rounded-lg flex items-center gap-2 ${w?"bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400":"bg-green-50 dark:bg-green-900/20 text-green-600 dark:text-green-400"}`,children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:w?o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13 10V3L4 14h7v7l9-11h-7z"}):o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),a(w?"agent_conversation.interrupt_sent":"agent_conversation.message_queued")]}),o.jsx("div",{ref:R,onScroll:B,className:"flex-1 overflow-y-auto px-4 py-4",children:l&&i.length===0?o.jsx("div",{className:"flex items-center justify-center h-32",children:o.jsx("div",{className:"w-6 h-6 border-2 border-primary-500 border-t-transparent rounded-full animate-spin"})}):i.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center h-32 text-center",children:[o.jsx("div",{className:"w-12 h-12 rounded-xl bg-gray-100 dark:bg-gray-800 flex items-center justify-center mb-3",children:o.jsx("svg",{className:"w-6 h-6 text-gray-400 dark:text-gray-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})}),o.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:a("agent_conversation.no_messages")}),o.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 mt-1",children:a("agent_conversation.no_messages_hint")})]}):o.jsxs("div",{className:"max-w-3xl mx-auto space-y-6",children:[i.map(function(Z){return o.jsx(nT,{message:Z.info,parts:Z.parts,streamingParts:null,searchQuery:null,matchOffset:-1,matchCount:0,activeMatchIndex:-1,registerMatchRef:le,hackerMode:r,hideThinking:!1},Z.info.id)}),o.jsx("div",{ref:D})]})}),o.jsx("div",{className:"absolute bottom-6 right-6",children:o.jsxs("button",{onClick:function(){p(!0),A(!1),d(null)},className:"px-4 py-2.5 bg-primary-500 hover:bg-primary-600 text-white rounded-full shadow-lg font-medium text-sm transition-colors flex items-center gap-2","aria-label":a("agent_conversation.compose_button"),children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),a("agent_conversation.compose_button")]})}),f&&o.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40 backdrop-blur-sm",onClick:j,children:o.jsxs("div",{ref:M,tabIndex:-1,role:"dialog","aria-modal":"true","aria-labelledby":"compose-modal-title",className:"bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700 shadow-xl w-full max-w-lg mx-4 max-h-[80vh] flex flex-col",children:[o.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[o.jsx("h3",{id:"compose-modal-title",className:"text-base font-semibold text-gray-900 dark:text-white",children:a("agent_conversation.modal_title",{name:e})}),o.jsx("button",{onClick:W,disabled:x,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors"+(x?" opacity-50 cursor-not-allowed":""),"aria-label":a("common.close"),children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),o.jsxs("div",{className:"px-5 py-4 space-y-4 overflow-y-auto flex-1 min-h-0",children:[o.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[o.jsx("input",{type:"checkbox",checked:y,onChange:function(Z){v(Z.target.checked)},className:"w-4 h-4 rounded border-gray-300 dark:border-gray-600 text-primary-600 focus:ring-primary-500"}),o.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:a("agent_conversation.reply_to_inbox")})]}),o.jsx("textarea",{ref:G,value:g,onChange:function(Z){m(Z.target.value)},onKeyDown:U,placeholder:a("agent_conversation.send_placeholder"),className:"w-full px-4 py-3 bg-gray-50 dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 outline-none resize-none text-sm text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:ring-2 focus:ring-primary-500 dark:focus:ring-primary-400 focus:border-transparent",rows:4,disabled:x,autoFocus:!0}),k&&o.jsx("p",{className:"text-sm text-green-600 dark:text-green-400 font-medium",children:a(w?"agent_conversation.interrupt_sent":"agent_conversation.message_queued")}),u&&o.jsx("p",{className:"text-sm text-red-500 dark:text-red-400",children:u})]}),o.jsx("div",{className:"px-5 py-4 border-t border-gray-200 dark:border-gray-700 flex-shrink-0",children:T?o.jsxs("div",{className:"space-y-2",children:[o.jsx("p",{className:"text-xs text-red-500 dark:text-red-400 font-medium",children:a("agent_conversation.urgent_warning")}),o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("button",{onClick:function(){A(!1)},className:"px-3 py-1.5 text-xs text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 transition-colors",children:a("common.cancel")}),o.jsxs("button",{onClick:K,disabled:!g.trim()||x,className:"px-3 py-1.5 bg-red-500 hover:bg-red-600 text-white rounded-lg disabled:opacity-50 disabled:cursor-not-allowed text-xs font-medium transition-colors flex items-center gap-1.5",children:[x&&w?o.jsx("div",{className:"w-3 h-3 border-2 border-white border-t-transparent rounded-full animate-spin"}):o.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13 10V3L4 14h7v7l9-11h-7z"})}),a("agent_conversation.confirm_interrupt")]})]})]}):o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("button",{onClick:K,disabled:!g.trim()||x,className:"px-3 py-1.5 text-xs text-red-500 dark:text-red-400 hover:text-red-600 dark:hover:text-red-300 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center gap-1.5",children:[o.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13 10V3L4 14h7v7l9-11h-7z"})}),a("agent_conversation.urgent_interrupt_button")]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("button",{onClick:W,disabled:x,className:"px-4 py-2 text-sm transition-colors"+(x?" text-gray-400 dark:text-gray-600 cursor-not-allowed":" text-gray-600 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200"),children:a("common.cancel")}),o.jsxs("button",{onClick:C,disabled:!g.trim()||x,className:"px-4 py-2 bg-primary-500 hover:bg-primary-600 text-white rounded-lg disabled:opacity-50 disabled:cursor-not-allowed font-medium text-sm transition-colors flex items-center gap-2",children:[x&&!w?o.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}):o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})}),a("agent_conversation.send_button")]})]})]})})]})})]})}function EK({isOpen:e,agent:t,onClose:n,onUpdated:r,onDeleted:a}){const{t:i}=vt(),[s,l]=h.useState(""),[c,u]=h.useState(""),[d,f]=h.useState(""),[p,g]=h.useState(""),[m,y]=h.useState(!1),[v,x]=h.useState([]),[b,k]=h.useState(!1),[N,w]=h.useState(""),[_,T]=h.useState(null),[A,D]=h.useState(!1),[R,$]=h.useState([]),[F,G]=h.useState([]),[P,M]=h.useState(!1),[S,I]=h.useState(!0),[B,Q]=h.useState(!1),[C,K]=h.useState(!1),[W,j]=h.useState(null),[U,le]=h.useState(!1),[Z,ke]=h.useState(!1),[re,X]=h.useState("general"),[Ne,ve]=h.useState(!1);h.useEffect(()=>{const ue={cancelled:!1};if(e&&t&&!Ne){me();const he=(typeof t.model=="string"?t.model.trim():t.model)||"github-copilot/claude-opus-4.6";pe(ue,he),ve(!0)}return e||(ve(!1),y(!1),g(""),I(!0),G([])),()=>{ue.cancelled=!0}},[e,t==null?void 0:t.name]);const me=()=>{if(!t)return;l(t.displayName||t.name||""),u(t.cwd||"");const ue=(typeof t.model=="string"?t.model.trim():t.model)||"github-copilot/claude-opus-4.6";f(ue),y(!1),g(""),x(Array.isArray(t.skills)?t.skills:[]),k(!!t.skipInitialPrompt)},pe=async(ue,he)=>{M(!0),I(!0),t!=null&&t.name&&Q(!0);const _e=[SA(),nv()];t!=null&&t.name&&_e.push(yK(t.name));const Pe=await Promise.allSettled(_e);if(ue.cancelled)return;const[Xe,H,z]=Pe;if(Xe.status==="fulfilled"?$(Xe.value):(console.error("Failed to load skills:",Xe.reason),$([])),M(!1),H.status==="fulfilled"){const te=H.value;G(te);const ce=he;te.find(je=>je.id===ce)||(y(!0),g(ce),f(ce))}else console.error("Failed to load models:",H.reason),G([]);if(I(!1),t!=null&&t.name&&z){if(z.status==="fulfilled"){const te=z.value;w(te.content||""),T(te.path||null),D(te.exists||!1)}else console.error("Failed to load AGENTS.md:",z.reason),w(""),T(null),D(!1);Q(!1)}},Le=ue=>{x(he=>he.includes(ue)?he.filter(_e=>_e!==ue):[...he,ue])},Se=()=>{v.length===R.length?x([]):x(R.map(ue=>ue.name))},Te=async ue=>{if(ue&&ue.preventDefault(),!!(t!=null&&t.name)){j(null),K(!0);try{await mK(t.name,{displayName:s.trim()||t.name,workspace:c.trim(),model:d,skipInitialPrompt:b,skills:v}),_&&N!==null&&!Ce&&await xK(t.name,N),r&&r(t.name),n()}catch(he){j(he.message)}finally{K(!1)}}},Fe=async()=>{if(t!=null&&t.name){ke(!0),j(null);try{await gK(t.name,!0),a&&a(t.name),n()}catch(ue){j(ue.message),le(!1)}finally{ke(!1)}}},fe=()=>{!C&&!Z&&(j(null),le(!1),X("general"),n())};if(!e||!t)return null;const xe=t.state==="working"||t.state==="idle"||t.state==="starting",Ce=c.trim()!==(t.cwd||"");return o.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[o.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:fe}),U&&o.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-4",children:[o.jsx("div",{className:"absolute inset-0 bg-black/30",onClick:()=>le(!1)}),o.jsxs("div",{className:"relative bg-white dark:bg-gray-900 rounded-xl shadow-2xl max-w-md w-full p-6",children:[o.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 mb-2",children:"Delete Agent?"}),o.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-4",children:["Are you sure you want to delete ",o.jsx("strong",{children:t.displayName||t.name}),"?",xe&&o.jsx("span",{className:"block mt-2 text-yellow-600 dark:text-yellow-400",children:"Warning: This agent is currently running and will be stopped."})]}),o.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-500 mb-4",children:"This will remove the agent registration. The workspace directory will not be deleted."}),o.jsxs("div",{className:"flex justify-end gap-3",children:[o.jsx("button",{onClick:()=>le(!1),disabled:Z,className:"px-4 py-2 rounded-lg text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors disabled:opacity-50",children:i("common.cancel")}),o.jsx("button",{onClick:Fe,disabled:Z,className:"px-4 py-2 rounded-lg bg-red-600 hover:bg-red-700 text-white font-medium transition-colors disabled:opacity-50 flex items-center gap-2",children:Z?o.jsxs(o.Fragment,{children:[o.jsxs("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[o.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),o.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),i("common.deleting")]}):i("common.delete")})]})]})]}),o.jsxs("div",{className:"relative bg-white dark:bg-gray-900 rounded-2xl shadow-2xl max-w-2xl w-full max-h-[90vh] overflow-hidden flex flex-col",children:[o.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200 dark:border-gray-800",children:[o.jsxs("div",{children:[o.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:i("agent_edit.title")}),o.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:[t.name,xe&&o.jsxs("span",{className:"ml-2 text-yellow-600 dark:text-yellow-400",children:["(",i("agent_edit.running_warning"),")"]})]})]}),o.jsx("button",{onClick:fe,disabled:C||Z,className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-400 transition-colors disabled:opacity-50",children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),o.jsxs("div",{className:"flex border-b border-gray-200 dark:border-gray-800 px-6",children:[o.jsx("button",{onClick:()=>X("general"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${re==="general"?"border-primary-500 text-primary-600 dark:text-primary-400":"border-transparent text-gray-500 hover:text-gray-700 dark:hover:text-gray-300"}`,children:i("agent_edit.tab_general")}),o.jsx("button",{onClick:()=>X("soul"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${re==="soul"?"border-primary-500 text-primary-600 dark:text-primary-400":"border-transparent text-gray-500 hover:text-gray-700 dark:hover:text-gray-300"}`,children:i("agent_edit.tab_soul")})]}),o.jsxs("form",{onSubmit:ue=>ue.preventDefault(),className:"flex-1 overflow-y-auto p-6 space-y-6",children:[W&&o.jsxs("div",{className:"px-4 py-3 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 text-sm rounded-lg flex items-center justify-between",children:[o.jsx("span",{children:W}),o.jsx("button",{type:"button",onClick:()=>j(null),className:"ml-2 text-red-400 hover:text-red-600",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),re==="general"&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{children:[o.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:[i("agent_edit.name_label"),o.jsx("span",{className:"text-gray-400 font-normal ml-1",children:i("agent_edit.cannot_change")})]}),o.jsx("input",{type:"text",value:t.name,disabled:!0,className:"w-full px-4 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-500 dark:text-gray-400 cursor-not-allowed font-mono"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:i("agent_edit.display_name_label")}),o.jsx("input",{type:"text",value:s,onChange:ue=>l(ue.target.value),placeholder:i("agent_edit.display_name_placeholder"),className:"w-full px-4 py-2 rounded-lg bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-primary-500"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:i("agent_edit.working_dir_label")}),xe?o.jsx("div",{className:"px-4 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-500 dark:text-gray-400 font-mono text-sm break-all",children:c||i("agent_edit.not_set")}):o.jsx("input",{type:"text",value:c,onChange:ue=>u(ue.target.value),placeholder:i("agent_edit.working_dir_placeholder"),disabled:C||Z,className:"w-full px-4 py-2 rounded-lg bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-primary-500 font-mono text-sm disabled:opacity-50"}),xe?o.jsx("p",{className:"mt-1 text-xs text-gray-400",children:i("agent_edit.stop_to_change")}):c.trim()!==(t.cwd||"")?o.jsx("p",{className:"mt-1 text-xs text-amber-500 dark:text-amber-400",children:i("agent_edit.workspace_move_warning")}):o.jsx("p",{className:"mt-1 text-xs text-gray-400",children:i("agent_edit.working_dir_hint")})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:i("agent_edit.model_label")}),S?o.jsx("div",{className:"w-full px-4 py-2 rounded-lg bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-400 text-sm",children:i("agent_edit.loading_models")}):F.length===0?o.jsx("input",{type:"text",value:d,onChange:ue=>f(ue.target.value),placeholder:i("agent_edit.model_placeholder"),className:"w-full px-4 py-2 rounded-lg bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-primary-500 font-mono text-sm"}):o.jsxs(o.Fragment,{children:[o.jsxs("select",{value:m?"__custom__":d,onChange:ue=>{ue.target.value==="__custom__"?(y(!0),d&&d!=="__custom__"&&g(d)):(y(!1),f(ue.target.value))},className:"w-full px-4 py-2 rounded-lg bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500",children:[(()=>{const ue=tv(F);return Object.entries(ue).map(([he,_e])=>o.jsx("optgroup",{label:Jb[he]||he,children:_e.map(Pe=>o.jsxs("option",{value:Pe.id,children:[Pe.name,ev(Pe.tier)]},Pe.id))},he))})(),o.jsx("option",{value:"__custom__",children:i("agent_edit.custom_model")})]}),m&&o.jsx("input",{type:"text",value:p,onChange:ue=>{g(ue.target.value),f(ue.target.value)},placeholder:i("agent_edit.custom_model_placeholder"),className:"w-full mt-2 px-4 py-2 rounded-lg bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-primary-500 font-mono text-sm"})]}),o.jsx("p",{className:"mt-1 text-xs text-gray-400",children:i(m?"agent_edit.custom_model_hint":"agent_edit.model_hint")})]}),o.jsxs("div",{className:"space-y-3",children:[o.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:i("agent_edit.start_mode")}),o.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[o.jsx("input",{type:"checkbox",checked:b,onChange:ue=>k(ue.target.checked),className:"mt-0.5 rounded border-gray-300 dark:border-gray-600 text-primary-600 focus:ring-primary-500"}),o.jsxs("div",{children:[o.jsx("span",{className:"text-sm text-gray-900 dark:text-gray-100",children:i("agent_edit.dormant_mode")}),o.jsx("p",{className:"text-xs text-gray-400 mt-0.5",children:i("agent_edit.dormant_mode_desc")})]})]})]}),o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center justify-between mb-2",children:[o.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:i("agent_edit.skills_label")}),o.jsx("button",{type:"button",onClick:Se,className:"text-xs text-primary-600 dark:text-primary-400 hover:underline",children:v.length===R.length?i("agent_edit.deselect_all"):i("agent_edit.select_all")})]}),o.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-3 max-h-48 overflow-y-auto bg-gray-50 dark:bg-gray-800",children:P?o.jsx("div",{className:"text-center py-4 text-gray-500",children:i("agent_edit.loading_skills")}):R.length===0?o.jsx("div",{className:"text-center py-4 text-gray-500",children:i("agent_edit.no_skills")}):o.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-2",children:R.map(ue=>o.jsxs("label",{className:`flex items-center gap-2 px-3 py-2 rounded-lg cursor-pointer transition-colors ${v.includes(ue.name)?"bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-300":"hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-300"}`,children:[o.jsx("input",{type:"checkbox",checked:v.includes(ue.name),onChange:()=>Le(ue.name),className:"rounded border-gray-300 text-primary-600 focus:ring-primary-500"}),o.jsxs("span",{className:"text-sm truncate",title:ue.description,children:[ue.icon&&o.jsx("span",{className:"mr-1",children:ue.icon}),ue.name]})]},ue.name))})}),o.jsx("p",{className:"mt-1 text-xs text-gray-400",children:i("agent_edit.skills_selected",{count:v.length})})]})]}),re==="soul"&&o.jsxs("div",{className:"space-y-4",children:[_&&o.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400 font-mono bg-gray-50 dark:bg-gray-800 rounded px-3 py-2",children:[_,!A&&o.jsx("span",{className:"ml-2 text-yellow-600 dark:text-yellow-400",children:i("agent_edit.will_be_created")})]}),!_&&!c.trim()&&o.jsx("div",{className:"px-4 py-3 bg-yellow-50 dark:bg-yellow-900/20 text-yellow-700 dark:text-yellow-400 text-sm rounded-lg",children:i("agent_edit.no_workspace_warning")}),Ce&&o.jsx("div",{className:"px-4 py-3 bg-amber-50 dark:bg-amber-900/20 text-amber-700 dark:text-amber-400 text-sm rounded-lg",children:i("agent_edit.workspace_changed_warning")}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:i("agent_edit.instructions_label")}),o.jsx("textarea",{value:N,onChange:ue=>w(ue.target.value),disabled:!_||Ce,rows:16,placeholder:i(B?"common.loading":"agent_edit.soul_placeholder"),className:"w-full px-4 py-3 rounded-lg bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-primary-500 font-mono text-sm resize-none disabled:cursor-not-allowed disabled:opacity-50"}),o.jsx("p",{className:"mt-1 text-xs text-gray-400",children:i("agent_edit.instructions_hint")})]})]})]}),o.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-t border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-900",children:[o.jsxs("button",{type:"button",onClick:()=>le(!0),disabled:C||Z,className:"px-4 py-2 rounded-lg text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors disabled:opacity-50 flex items-center gap-2",children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),i("common.delete")]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("button",{type:"button",onClick:fe,disabled:C||Z,className:"px-4 py-2 rounded-lg text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors disabled:opacity-50",children:i("common.cancel")}),o.jsx("button",{type:"button",onClick:Te,disabled:C||Z,className:"px-6 py-2 rounded-lg bg-primary-600 hover:bg-primary-700 text-white font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:C?o.jsxs(o.Fragment,{children:[o.jsxs("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[o.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),o.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),i("agent_edit.saving")]}):o.jsxs(o.Fragment,{children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),i("agent_edit.save")]})})]})]})]})]})}const FS={working:"bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",idle:"bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-400",paused:"bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-400",stopped:"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400",crashed:"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400",error:"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400",starting:"bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-400"},BS={working:o.jsx("svg",{className:"w-4 h-4 mr-1.5",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),idle:o.jsx("svg",{className:"w-4 h-4 mr-1.5",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{d:"M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"})}),paused:o.jsx("svg",{className:"w-4 h-4 mr-1.5",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zM7 8a1 1 0 012 0v4a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v4a1 1 0 102 0V8a1 1 0 00-1-1z",clipRule:"evenodd"})}),stopped:o.jsx("svg",{className:"w-4 h-4 mr-1.5",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8 7a1 1 0 00-1 1v4a1 1 0 001 1h4a1 1 0 001-1V8a1 1 0 00-1-1H8z",clipRule:"evenodd"})}),crashed:o.jsx("svg",{className:"w-4 h-4 mr-1.5",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})}),error:o.jsx("svg",{className:"w-4 h-4 mr-1.5",fill:"currentColor",viewBox:"0 0 20 20",children:o.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})}),starting:o.jsx("svg",{className:"w-4 h-4 mr-1.5 animate-spin",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})};function NK({state:e}){const t=FS[e]||FS.stopped,n=BS[e]||BS.stopped;return o.jsxs("span",{className:`inline-flex items-center px-3 py-1 rounded-full text-sm font-medium ${t}`,children:[n,e]})}function SK(e){if(!e)return"-";const t=Date.now()-e,n=Math.floor(t/1e3);if(n<60)return n+"s";const r=Math.floor(n/60);if(r<60)return r+"m";const a=Math.floor(r/60),i=r%60;if(a<24)return a+"h "+i+"m";const s=Math.floor(a/24),l=a%24;return s+"d "+l+"h"}function P0({label:e,value:t,max:n,color:r}){const a=n>0?Math.min(100,Math.round(t/n*100)):0;return o.jsxs("div",{className:"space-y-1",children:[o.jsxs("div",{className:"flex items-center justify-between text-xs",children:[o.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:e}),o.jsx("span",{className:"text-gray-700 dark:text-gray-300 font-medium",children:t.toLocaleString()})]}),o.jsx("div",{className:"h-1.5 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden",children:o.jsx("div",{className:`h-full ${r} transition-all duration-300`,style:{width:a+"%"}})})]})}function ci({label:e,value:t,mono:n}){return o.jsxs("div",{className:"flex items-center justify-between py-2 border-b border-gray-100 dark:border-gray-800 last:border-0",children:[o.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:e}),o.jsx("span",{className:`text-sm text-gray-900 dark:text-gray-100 ${n?"font-mono":""}`,children:t||"-"})]})}function CK({agent:e,onClose:t,onAction:n,onToolPartsChange:r,hackerMode:a}){const{t:i}=vt(),[s,l]=h.useState(e),[c,u]=h.useState(null),[d,f]=h.useState(null),[p,g]=h.useState(!1),[m,y]=h.useState(!1),v=h.useCallback(async()=>{if(e!=null&&e.name)try{const A=await oK(e.name);l(A),u(null)}catch(A){console.error("Failed to load agent:",A),u(A.message)}},[e==null?void 0:e.name]);h.useEffect(()=>{v();const A=setInterval(v,5e3);return()=>clearInterval(A)},[v]);const x=h.useCallback(async A=>{f(A),u(null);try{A==="start"?await lx(s.name):A==="stop"?await cx(s.name):A==="restart"?await Eu(s.name):A==="cleanRestart"?await Eu(s.name,{clean:!0}):A==="pause"?await ux(s.name,{level:"tools"}):A==="unpause"&&await dx(s.name),await v(),n&&n(s.name,A)}catch(D){u(D.message)}finally{f(null)}},[s==null?void 0:s.name,v,n]),b=(s==null?void 0:s.state)==="working"||(s==null?void 0:s.state)==="idle"||(s==null?void 0:s.state)==="starting"||(s==null?void 0:s.state)==="paused",k=(s==null?void 0:s.state)==="paused"||(s==null?void 0:s.paused),N=(s==null?void 0:s.displayName)||(s==null?void 0:s.name)||"Unknown Agent",w=(s==null?void 0:s.tokens)||{input:0,output:0,cached:0,total:0},_=Math.max(w.input,w.output,w.cached,1),T=(s==null?void 0:s.cost)||{input:0,output:0,cached:0,total:0};return p?o.jsx(wK,{agentName:s==null?void 0:s.name,onClose:()=>{g(!1),r&&r(null)},onToolPartsChange:r,hackerMode:a}):o.jsxs("div",{className:"h-full flex flex-col bg-white dark:bg-gray-900 border-l border-gray-200 dark:border-gray-800",children:[o.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-200 dark:border-gray-800",children:[o.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[o.jsx("button",{onClick:t,className:"p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-500 dark:text-gray-400 transition-colors flex-shrink-0",title:i("agent_detail.back"),"aria-label":i("agent_detail.back"),children:o.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 19l-7-7 7-7"})})}),o.jsxs("div",{className:"min-w-0",children:[o.jsx("h2",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 truncate",title:N,children:N}),(s==null?void 0:s.displayName)&&s.displayName!==s.name&&o.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 truncate",title:s.name,children:s.name})]})]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("button",{onClick:()=>y(!0),className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-500 dark:text-gray-400 transition-colors",title:i("agent_detail.edit_settings"),"aria-label":i("agent_detail.edit_settings"),children:o.jsxs("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})}),o.jsx(NK,{state:(s==null?void 0:s.state)||"stopped"})]})]}),o.jsx(EK,{isOpen:m,agent:s,onClose:()=>y(!1),onUpdated:A=>{v(),n&&n(A,"updated")},onDeleted:A=>{n&&n(A,"deleted"),t()}}),c&&o.jsxs("div",{className:"mx-6 mt-4 px-4 py-2 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 text-sm rounded-lg flex items-center justify-between",children:[o.jsx("span",{children:c}),o.jsx("button",{onClick:()=>u(null),className:"ml-2 text-red-400 hover:text-red-600",children:o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),o.jsxs("div",{className:"flex-1 overflow-y-auto p-6 space-y-6",children:[o.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:b?o.jsxs(o.Fragment,{children:[o.jsx("button",{onClick:()=>x("stop"),disabled:d,className:"flex-1 px-4 py-2 text-sm font-medium rounded-lg bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 disabled:opacity-50 transition-colors",children:i(d==="stop"?"agents.stopping":"agents.stop")}),k?o.jsx("button",{onClick:()=>x("unpause"),disabled:d,className:"flex-1 px-4 py-2 text-sm font-medium rounded-lg bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 hover:bg-green-200 dark:hover:bg-green-800/40 disabled:opacity-50 transition-colors",children:i(d==="unpause"?"agents.resuming":"agents.resume")}):o.jsx("button",{onClick:()=>x("pause"),disabled:d,className:"flex-1 px-4 py-2 text-sm font-medium rounded-lg bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-400 hover:bg-orange-200 dark:hover:bg-orange-800/40 disabled:opacity-50 transition-colors",children:i(d==="pause"?"agents.pausing":"agents.pause")}),o.jsx("button",{onClick:()=>x("restart"),disabled:d,className:"flex-1 px-4 py-2 text-sm font-medium rounded-lg bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400 hover:bg-primary-200 dark:hover:bg-primary-800/40 disabled:opacity-50 transition-colors",children:i(d==="restart"?"agents.restarting":"agents.restart")}),o.jsx("button",{onClick:()=>x("cleanRestart"),disabled:d,className:"flex-1 px-4 py-2 text-sm font-medium rounded-lg bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-400 hover:bg-orange-200 dark:hover:bg-orange-800/40 disabled:opacity-50 transition-colors",title:i("agents.clean_restart_tooltip"),children:i(d==="cleanRestart"?"agents.restarting":"agents.clean_restart")})]}):o.jsx("button",{onClick:()=>x("start"),disabled:d,className:"flex-1 px-4 py-2 text-sm font-medium rounded-lg bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 hover:bg-green-200 dark:hover:bg-green-800/40 disabled:opacity-50 transition-colors",children:i(d==="start"?"agents.starting":"agents.start")})}),o.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800/50 rounded-xl p-4",children:[o.jsx("h3",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-3",children:i("agent_detail.agent_info")}),o.jsxs("div",{className:"space-y-0",children:[o.jsx(ci,{label:i("agent_detail.model"),value:s==null?void 0:s.model,mono:!0}),o.jsx(ci,{label:i("agent_detail.port"),value:s==null?void 0:s.port,mono:!0}),o.jsx(ci,{label:i("agent_detail.pid"),value:s==null?void 0:s.pid,mono:!0}),o.jsx(ci,{label:i("agent_detail.session_id"),value:s!=null&&s.sessionId?s.sessionId.slice(0,12)+"...":null,mono:!0}),o.jsx(ci,{label:i("agent_detail.uptime"),value:SK(s==null?void 0:s.startedAt)}),o.jsx(ci,{label:i("agent_detail.iteration"),value:s==null?void 0:s.iteration}),o.jsx(ci,{label:i("agent_detail.start_mode"),value:s!=null&&s.skipInitialPrompt?i("agent_detail.start_mode_dormant"):i("agent_detail.start_mode_normal")})]})]}),o.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800/50 rounded-xl p-4",children:[o.jsx("h3",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-3",children:i("agent_detail.token_usage")}),o.jsxs("div",{className:"space-y-3",children:[o.jsx(P0,{label:i("agent_detail.token_input"),value:w.input,max:_,color:"bg-blue-500"}),o.jsx(P0,{label:i("agent_detail.token_output"),value:w.output,max:_,color:"bg-green-500"}),o.jsx(P0,{label:i("agent_detail.token_cached"),value:w.cached,max:_,color:"bg-purple-500"}),o.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-gray-200 dark:border-gray-700",children:[o.jsx("span",{className:"text-sm font-medium text-gray-600 dark:text-gray-300",children:"Total"}),o.jsx("span",{className:"text-sm font-bold text-gray-900 dark:text-gray-100",children:w.total.toLocaleString()})]})]})]}),o.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800/50 rounded-xl p-4",children:[o.jsx("h3",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-3",children:"Estimated Cost"}),o.jsxs("div",{className:"grid grid-cols-3 gap-4 mb-3",children:[o.jsxs("div",{className:"text-center",children:[o.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Input"}),o.jsxs("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:["$",T.input.toFixed(4)]})]}),o.jsxs("div",{className:"text-center",children:[o.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Output"}),o.jsxs("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:["$",T.output.toFixed(4)]})]}),o.jsxs("div",{className:"text-center",children:[o.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Cached"}),o.jsxs("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:["$",T.cached.toFixed(4)]})]})]}),o.jsxs("div",{className:"flex items-center justify-between pt-3 border-t border-gray-200 dark:border-gray-700",children:[o.jsx("span",{className:"text-sm font-medium text-gray-600 dark:text-gray-300",children:i("agent_detail.total_cost")}),o.jsxs("span",{className:"text-lg font-bold text-gray-900 dark:text-gray-100",children:["$",T.total.toFixed(4)]})]})]}),(s==null?void 0:s.dailyUsage)&&s.dailyUsage.length>0&&o.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800/50 rounded-xl p-4",children:[o.jsx("h3",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-3",children:"Daily Usage (Last 7 Days)"}),o.jsx(_K,{data:s.dailyUsage})]}),o.jsxs("div",{className:"space-y-2",children:[o.jsxs("button",{className:"w-full px-4 py-2.5 text-sm font-medium rounded-lg border border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors flex items-center justify-center gap-2",onClick:()=>g(!0),children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),i("agent_detail.view_conversation")]}),o.jsxs("button",{className:"w-full px-4 py-2.5 text-sm font-medium rounded-lg border border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors flex items-center justify-center gap-2",onClick:()=>y(!0),children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),i("agent_detail.edit_settings")]}),o.jsxs("button",{className:"w-full px-4 py-2.5 text-sm font-medium rounded-lg border border-gray-200 dark:border-gray-700 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors flex items-center justify-center gap-2",onClick:async()=>{try{await CA(s.name)}catch(A){u(i("agents.export_error")+": "+A.message)}},children:[o.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),i("agents.export")]})]}),(s==null?void 0:s.cwd)&&o.jsxs("div",{className:"text-xs text-gray-400 dark:text-gray-500 break-all",children:[o.jsx("span",{className:"font-medium",children:i("agent_detail.working_dir_label")}),o.jsx("br",{}),o.jsx("span",{className:"font-mono",children:s.cwd})]})]})]})}const vc=["swift","quick","rapid","agile","nimble","clever","smart","wise","bright","keen","bold","brave","calm","steady","noble","silent","shadow","storm","iron","steel","amber","azure","cobalt","crimson","golden","cosmic","cyber","digital","quantum","prime"],kc=["falcon","hawk","eagle","raven","phoenix","wolf","fox","hound","coyote","tiger","panther","lynx","leopard","bear","orca","shark","viper","cobra","dragon","griffin","sentinel","guardian","titan","node","nexus","core","spark","pulse"];function zS(e=[],t=100){const n=new Set(e.map(s=>s.toLowerCase()));for(let s=0;s<t;s++){const l=vc[Math.floor(Math.random()*vc.length)],c=kc[Math.floor(Math.random()*kc.length)],u=`${l}-${c}`;if(!n.has(u))return u}const r=vc[Math.floor(Math.random()*vc.length)],a=kc[Math.floor(Math.random()*kc.length)],i=Math.floor(Math.random()*1e3);return`${r}-${a}-${i}`}function US(e,t=[]){if(!e||typeof e!="string")return{valid:!1,error:"Name is required"};const n=e.trim().toLowerCase();return n.length===0?{valid:!1,error:"Name cannot be empty"}:n.length<2?{valid:!1,error:"Name must be at least 2 characters"}:n.length>50?{valid:!1,error:"Name must be 50 characters or less"}:/^[a-z0-9_-]+$/.test(n)?new Set(t.map(a=>a.toLowerCase())).has(n)?{valid:!1,error:"An agent with this name already exists"}:{valid:!0,error:null}:{valid:!1,error:"Name can only contain lowercase letters, numbers, hyphens, and underscores"}}function jK(e){return e?e.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9_-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,""):""}const _c=`# AGENTS.md - AI Agent Instructions
105
105
 
106
106
  ## Overview
107
107
  You are an autonomous AI agent. Your goal is to help users accomplish tasks efficiently.