@promptowl/contextnest-community 1.24.0 → 1.25.0

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 (102) hide show
  1. package/API.md +109 -6
  2. package/CONFIGURATION.md +7 -2
  3. package/README.md +1 -1
  4. package/STEWARDSHIP.md +24 -0
  5. package/dist/{chunk-2TPQTN4Y.js → chunk-2KHM5C7V.js} +37 -3
  6. package/dist/{chunk-XUIWAWDO.js → chunk-32SZCH36.js} +4 -4
  7. package/dist/{chunk-KIAAEHWL.js → chunk-7FROMOZM.js} +23 -5
  8. package/dist/{chunk-5EZOPA47.js → chunk-DTLMBF4W.js} +10 -8
  9. package/dist/{chunk-LA3VTQ22.js → chunk-JDAOA5KP.js} +43 -1
  10. package/dist/{chunk-I3CSD6CK.js → chunk-KPGNZLZL.js} +2 -2
  11. package/dist/{chunk-YVMSM7LS.js → chunk-LHWOJPFE.js} +7 -0
  12. package/dist/{chunk-ZTT4U4NE.js → chunk-TI7HMP64.js} +99 -12
  13. package/dist/{client-KEY4PYJH.js → client-D44ZHDTJ.js} +1 -1
  14. package/dist/{engine-S3QBQ7LH.js → engine-TER6FDBP.js} +3 -3
  15. package/dist/{external-edit-service-6FNFPOJJ.js → external-edit-service-CAGENHDJ.js} +4 -4
  16. package/dist/{grants-service-UT3EQ3R7.js → grants-service-2OTFS7EH.js} +3 -3
  17. package/dist/index.js +863 -355
  18. package/dist/{migrations.postgres-AIQ7WSU7.js → migrations.postgres-23VJJJJX.js} +12 -2
  19. package/dist/{review-service-HHGOTO6P.js → review-service-4G2XUFS6.js} +7 -7
  20. package/dist/{stewardship-service-4DHNRULG.js → stewardship-service-S22V2JKG.js} +6 -4
  21. package/dist/{version-service-KIOQME6U.js → version-service-X4FAG2OZ.js} +4 -4
  22. package/dist/web3/assets/ActivityTracePage-D2iIbEph.js +1 -0
  23. package/dist/web3/assets/{AgentDocsPage-CIiaBqMy.js → AgentDocsPage-Dkhgb1hk.js} +1 -1
  24. package/dist/web3/assets/CollaboratorManager-Bo81D--Q.js +1 -0
  25. package/dist/web3/assets/CollaboratorsTab-DRCitQuX.js +1 -0
  26. package/dist/web3/assets/DocumentEditor-DV2WHYbj.js +36 -0
  27. package/dist/web3/assets/{DocumentsTab-Vba-AzBv.js → DocumentsTab-BUxBCN8o.js} +2 -2
  28. package/dist/web3/assets/{ExternalEditsTab-BSzAQIGM.js → ExternalEditsTab-kIBimZyE.js} +1 -1
  29. package/dist/web3/assets/MarkdownEditor-CsVusP2d.css +1 -0
  30. package/dist/web3/assets/MarkdownEditor-Dfk5uIE5.js +648 -0
  31. package/dist/web3/assets/{NestPageHeader-CoLUV1Oz.js → NestPageHeader-yOK-OIYZ.js} +1 -1
  32. package/dist/web3/assets/NestView-DwIagxwJ.js +68 -0
  33. package/dist/web3/assets/{OverviewTab-Dxi-Hu-N.js → OverviewTab-DFOFMVyE.js} +1 -1
  34. package/dist/web3/assets/{PersonCombobox-CPOlNs6G.js → PersonCombobox-D350WlrJ.js} +1 -1
  35. package/dist/web3/assets/{ReasonDialog-DgLxfRWv.js → ReasonDialog-CN3ECAnQ.js} +1 -1
  36. package/dist/web3/assets/{ReviewActions-OfOdqzCn.js → ReviewActions-BXDTDPp1.js} +1 -1
  37. package/dist/web3/assets/{ReviewTab-CyX8yxd3.js → ReviewTab-CZewAYiz.js} +1 -1
  38. package/dist/web3/assets/StewardsTab-AagNWcWS.js +1 -0
  39. package/dist/web3/assets/{SubmitForReviewModal-Ci2DdWs0.js → SubmitForReviewModal-BOZJxwRN.js} +1 -1
  40. package/dist/web3/assets/{alert-dialog-DTozKlmV.js → alert-dialog-4SiLKlz8.js} +1 -1
  41. package/dist/web3/assets/{arrow-left-BCKt4CwQ.js → arrow-left-BAgIocLn.js} +1 -1
  42. package/dist/web3/assets/backlinks-Cb8Uf8mw.js +24 -0
  43. package/dist/web3/assets/{card-XG2dP5Xf.js → card-UDyMRcps.js} +1 -1
  44. package/dist/web3/assets/{chevron-left-BPwUT9DS.js → chevron-left-XR4ReJ9Z.js} +1 -1
  45. package/dist/web3/assets/{circle-check-DI8IBGeo.js → circle-check-CSkZUEFK.js} +1 -1
  46. package/dist/web3/assets/{circle-x-VKVhC88W.js → circle-x-in2o3aHU.js} +1 -1
  47. package/dist/web3/assets/client-attribution-BraarYaP.js +1 -0
  48. package/dist/web3/assets/{code-xml-CMabYZvH.js → code-xml-pPQgdctI.js} +1 -1
  49. package/dist/web3/assets/{corner-down-right-BGxwK6wH.js → corner-down-right-CuxZWscX.js} +1 -1
  50. package/dist/web3/assets/{count-skeleton-DMbdpscX.js → count-skeleton-DBWCDhRy.js} +1 -1
  51. package/dist/web3/assets/{earth-BEp1EKTo.js → earth-CXOcThqn.js} +1 -1
  52. package/dist/web3/assets/{file-exclamation-point-r8qZGIjP.js → file-exclamation-point-CSphs1VD.js} +1 -1
  53. package/dist/web3/assets/{folder-input-Cmtx1Jhk.js → folder-input-BAwK9tFL.js} +1 -1
  54. package/dist/web3/assets/{index-C1wTSjfP.js → index-A0_ymcqL.js} +1 -1
  55. package/dist/web3/assets/index-B5hLclEq.js +389 -0
  56. package/dist/web3/assets/index-DrUAtoQM.css +1 -0
  57. package/dist/web3/assets/page-BHD4beun.js +1 -0
  58. package/dist/web3/assets/{page-CPjWQNKx.js → page-BSYUXYmO.js} +1 -1
  59. package/dist/web3/assets/page-BYc2DIux.js +45 -0
  60. package/dist/web3/assets/{page-Bicf02Cz.js → page-BfibLg8e.js} +1 -1
  61. package/dist/web3/assets/page-CGe8MtUu.js +9 -0
  62. package/dist/web3/assets/{page-CQt3ZGbf.js → page-CIgPJmG6.js} +1 -1
  63. package/dist/web3/assets/{page-CHb0F5hV.js → page-CUjuSs5Q.js} +1 -1
  64. package/dist/web3/assets/{page-BYUFhYWZ.js → page-Ck31nx9b.js} +1 -1
  65. package/dist/web3/assets/{page-BExMvttJ.js → page-Cpdj_11Y.js} +1 -1
  66. package/dist/web3/assets/{page-CtaW65El.js → page-D0sN3GO6.js} +1 -1
  67. package/dist/web3/assets/page-DEpH91X2.js +1 -0
  68. package/dist/web3/assets/{page-CC0NJi8v.js → page-l8-B7CGt.js} +1 -1
  69. package/dist/web3/assets/{page-DGOL9l8i.js → page-mnSHmk6A.js} +1 -1
  70. package/dist/web3/assets/{page-title-ClvvBsIo.js → page-title-BkqlUA0j.js} +1 -1
  71. package/dist/web3/assets/{page-ByyVLDVo.js → page-xzYqkBUP.js} +5 -5
  72. package/dist/web3/assets/{play-C5YNKpAH.js → play-B8xE9j5f.js} +1 -1
  73. package/dist/web3/assets/{refresh-cw-BhHzSH9m.js → refresh-cw-CsCtmWwX.js} +1 -1
  74. package/dist/web3/assets/{scroll-area-hz-xtayP.js → scroll-area-CbcH6yrZ.js} +1 -1
  75. package/dist/web3/assets/{select-DBFTrUmI.js → select-DrL0mpRN.js} +2 -2
  76. package/dist/web3/assets/{send-0CHvmluT.js → send-CvAgOUPG.js} +1 -1
  77. package/dist/web3/assets/{settings-CeeF4LEb.js → settings-EY4A_DYv.js} +1 -1
  78. package/dist/web3/assets/{share-2-CMnOlOt-.js → share-2-vGmZUl90.js} +1 -1
  79. package/dist/web3/assets/{tag-DQ_6J5Gv.js → tag-Br_y1f00.js} +1 -1
  80. package/dist/web3/assets/{trash-2-HBi-Pslz.js → trash-2-B4hRXo-p.js} +1 -1
  81. package/dist/web3/assets/{triangle-alert-CDy8-7sv.js → triangle-alert-CsYGyfGZ.js} +1 -1
  82. package/dist/web3/assets/{user-plus-CvBNcpn4.js → user-plus-4CTYEkd3.js} +1 -1
  83. package/dist/web3/assets/{x-By7piikG.js → x-qxt1WrUi.js} +1 -1
  84. package/dist/web3/assets/zap-BcsKR0ef.js +16 -0
  85. package/dist/web3/index.html +2 -2
  86. package/package.json +2 -2
  87. package/dist/web3/assets/ActivityTracePage-BOZHgJ8S.js +0 -1
  88. package/dist/web3/assets/CollaboratorManager-By91wrIr.js +0 -1
  89. package/dist/web3/assets/CollaboratorsTab-D1EE64Fs.js +0 -1
  90. package/dist/web3/assets/DocumentEditor-DrQfrW3d.js +0 -36
  91. package/dist/web3/assets/MarkdownEditor-74N_naNQ.css +0 -1
  92. package/dist/web3/assets/MarkdownEditor-C9zqZjC5.js +0 -643
  93. package/dist/web3/assets/NestView-CTZ55tXD.js +0 -63
  94. package/dist/web3/assets/StewardsTab-DBEEfAQI.js +0 -1
  95. package/dist/web3/assets/backlinks-CYd4xENL.js +0 -24
  96. package/dist/web3/assets/index-BM-h3DwI.css +0 -1
  97. package/dist/web3/assets/index-EaX2yql0.js +0 -389
  98. package/dist/web3/assets/page-B3yvQvHy.js +0 -1
  99. package/dist/web3/assets/page-BUOADv2X.js +0 -1
  100. package/dist/web3/assets/page-BsPMDm5d.js +0 -45
  101. package/dist/web3/assets/page-Cj1NetQ-.js +0 -1
  102. package/dist/web3/assets/zap-C2T8riBp.js +0 -11
@@ -1,16 +1,16 @@
1
- import{c as gt,r,j as e,T as Vt,P as Bt,Q as Ve,R as Be,aY as ft,aZ as vt,a_ as Ue,a$ as jt,b0 as qt,b1 as Je,I as te,B as S,L as J,b2 as Qe,b3 as Ie,b4 as yt,b5 as bt,e as se,b6 as Ut,aP as oe,b7 as Xt,b8 as Gt,b9 as mt,ba as Jt,O as Yt,bb as Zt,bc as Nt,bd as Qt,be as wt,bf as It,bg as es,bh as ts,bi as ss,bj as ns,a2 as as,F as rs,bk as kt,bl as os,bm as _t,aw as ls,bn as qe,bo as is,bp as cs,aE as ds,aa as us,aT as ms}from"./index-EaX2yql0.js";import{f as xs}from"./dates-BCxbm4_q.js";import{A as Ye,W as St,T as hs,O as ps}from"./MarkdownEditor-C9zqZjC5.js";import{S as Ct,a as Et,b as Tt,c as $t,d as et}from"./select-DBFTrUmI.js";import{F as gs,N as We}from"./NestView-CTZ55tXD.js";import{N as fs}from"./NestPageHeader-CoLUV1Oz.js";import{R as st}from"./refresh-cw-BhHzSH9m.js";import{P as At}from"./play-C5YNKpAH.js";import{T as ze}from"./trash-2-HBi-Pslz.js";import{Z as Pt}from"./zap-C2T8riBp.js";import{C as nt}from"./corner-down-right-BGxwK6wH.js";import{X as Rt}from"./x-By7piikG.js";import{A as vs}from"./arrow-left-BCKt4CwQ.js";import"./scroll-area-hz-xtayP.js";import"./index-C1wTSjfP.js";import"./triangle-alert-CDy8-7sv.js";import"./chevron-left-BPwUT9DS.js";import"./alert-dialog-DTozKlmV.js";import"./count-skeleton-DMbdpscX.js";import"./folder-input-Cmtx1Jhk.js";import"./card-XG2dP5Xf.js";import"./PersonCombobox-CPOlNs6G.js";import"./tag-DQ_6J5Gv.js";import"./user-plus-CvBNcpn4.js";import"./ReviewActions-OfOdqzCn.js";import"./circle-check-DI8IBGeo.js";import"./circle-x-VKVhC88W.js";import"./ReasonDialog-DgLxfRWv.js";import"./settings-CeeF4LEb.js";/**
1
+ import{c as gt,r,j as e,T as Vt,P as Bt,Q as Ve,R as Be,aY as ft,aZ as vt,a_ as Ue,a$ as jt,b0 as qt,b1 as Je,I as te,B as S,L as J,b2 as Qe,b3 as Ie,b4 as yt,b5 as bt,e as se,b6 as Ut,aP as oe,b7 as Xt,b8 as Gt,b9 as mt,ba as Jt,O as Yt,bb as Zt,bc as Nt,bd as Qt,be as wt,bf as It,bg as es,bh as ts,bi as ss,bj as ns,a2 as as,F as rs,bk as kt,bl as os,bm as _t,at as ls,bn as qe,bo as is,bp as cs,aE as ds,ag as us,aT as ms}from"./index-B5hLclEq.js";import{f as xs}from"./dates-BCxbm4_q.js";import{A as Ye,W as St,T as hs,O as ps}from"./MarkdownEditor-Dfk5uIE5.js";import{S as Ct,a as Et,b as Tt,c as $t,d as et}from"./select-DrL0mpRN.js";import{F as gs,N as We}from"./NestView-DwIagxwJ.js";import{N as fs}from"./NestPageHeader-yOK-OIYZ.js";import{R as st}from"./refresh-cw-CsCtmWwX.js";import{P as At}from"./play-B8xE9j5f.js";import{T as ze}from"./trash-2-B4hRXo-p.js";import{Z as Pt,F as vs}from"./zap-BcsKR0ef.js";import{C as nt}from"./corner-down-right-CuxZWscX.js";import{X as Rt}from"./x-qxt1WrUi.js";import{A as js}from"./arrow-left-BAgIocLn.js";import"./triangle-alert-CsYGyfGZ.js";import"./scroll-area-CbcH6yrZ.js";import"./index-A0_ymcqL.js";import"./chevron-left-XR4ReJ9Z.js";import"./alert-dialog-4SiLKlz8.js";import"./count-skeleton-DBWCDhRy.js";import"./folder-input-BAwK9tFL.js";import"./card-UDyMRcps.js";import"./PersonCombobox-D350WlrJ.js";import"./tag-Br_y1f00.js";import"./user-plus-4CTYEkd3.js";import"./ReviewActions-BXDTDPp1.js";import"./circle-check-CSkZUEFK.js";import"./circle-x-in2o3aHU.js";import"./ReasonDialog-CN3ECAnQ.js";import"./settings-EY4A_DYv.js";/**
2
2
  * @license lucide-react v0.577.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const js=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],ys=gt("bell",js);/**
6
+ */const ys=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],bs=gt("bell",ys);/**
7
7
  * @license lucide-react v0.577.0 - ISC
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const bs=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6h4",key:"135r8i"}]],Ns=gt("clock-3",bs),ws=6,xt=46;function ks(s,m){const g=m?`${s} · ${m}`:s,y=g.length>xt?`${g.slice(0,xt-1).trimEnd()}…`:g;return{full:g,short:y,width:y.length*ws+8}}const tt=s=>s==="succeeded"?"default":s==="failed"||s==="cancelled"?"destructive":s==="queued"?"outline":"secondary",_s=.85,Ss=6;function ht(s){return`${.75+Math.min(s,Ss)*_s}rem`}const Ae=s=>qe(s)?"queued":s.status,Mt="Created — waiting for a runner to claim it",Cs=s=>s==="read"?e.jsx(ds,{className:"h-3.5 w-3.5"}):s==="branch"?e.jsx(Pt,{className:"h-3.5 w-3.5"}):s==="write"?e.jsx(us,{className:"h-3.5 w-3.5"}):s==="notify"?e.jsx(ys,{className:"h-3.5 w-3.5"}):e.jsx("span",{className:"h-3.5 w-3.5"}),Ee=s=>xs(s)||s;function Es({nestId:s,nestName:m,onBack:g}){const[y,C]=r.useState("canvas");return e.jsxs("div",{children:[e.jsx(fs,{nestName:m,onBack:g}),e.jsxs(Vt,{value:y,onValueChange:C,children:[e.jsxs(Bt,{children:[e.jsx(Ve,{value:"canvas",children:"Canvas"}),e.jsx(Ve,{value:"table",children:"Table"}),e.jsx(Ve,{value:"run",children:"Run"}),e.jsx(Ve,{value:"activity",children:"Activity"})]}),e.jsx(Be,{value:"canvas",className:"mt-4",children:e.jsx(zs,{nestId:s})}),e.jsx(Be,{value:"table",className:"mt-4",children:e.jsx($s,{nestId:s})}),e.jsx(Be,{value:"run",className:"mt-4",children:e.jsx(Ms,{nestId:s})}),e.jsxs(Be,{value:"activity",className:"mt-4 space-y-6",children:[e.jsx(Hs,{nestId:s}),e.jsx(Fs,{nestId:s}),e.jsx(Vs,{nestId:s}),e.jsx(Ds,{nestId:s})]})]})]})}function Ce({type:s}){return s==="agent"?e.jsx(as,{className:"h-3.5 w-3.5 text-violet-500 shrink-0"}):s==="skill"?e.jsx(Pt,{className:"h-3.5 w-3.5 text-blue-500 shrink-0"}):s==="artifact"?e.jsx(gs,{className:"h-3.5 w-3.5 text-amber-500 shrink-0"}):s==="tool"?e.jsx(St,{className:"h-3.5 w-3.5 text-teal-500 shrink-0"}):s==="table"?e.jsx(hs,{className:"h-3.5 w-3.5 text-cyan-500 shrink-0"}):e.jsx(rs,{className:"h-3.5 w-3.5 text-slate-400 shrink-0"})}function Ts({edge:s}){if(!s.condition_mode||!s.condition)return e.jsx("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[10px] text-muted-foreground",children:"always"});if(s.condition_mode==="nl")return e.jsxs("span",{className:"rounded-full bg-amber-500/10 text-amber-700 dark:text-amber-300 px-2 py-0.5 text-[10px] italic max-w-[260px] truncate inline-block align-middle",title:`AI judges: "${s.condition}"`,children:["if “",String(s.condition),"”"]});let m="";try{const g=typeof s.condition=="string"?JSON.parse(s.condition):s.condition;m=g&&g.term?`${g.term} ${g.op??""} ${g.value??""}`:JSON.stringify(g)}catch{m=String(s.condition)}return e.jsx("span",{className:"rounded-full bg-blue-500/10 text-blue-700 dark:text-blue-300 px-2 py-0.5 text-[10px] font-mono max-w-[260px] truncate inline-block align-middle",title:`Deterministic check: ${m}`,children:m})}function $s({nestId:s}){var ke;const[m,g]=r.useState([]),[y,C]=r.useState([]),[b,j]=r.useState(!0),[k,d]=r.useState(null),[h,E]=r.useState([]),[N,w]=r.useState(""),[x,O]=r.useState(""),[c,L]=r.useState(""),[T,B]=r.useState(""),[D,q]=r.useState(""),[Y,U]=r.useState(""),[i,$]=r.useState(">"),[W,he]=r.useState(""),[ne,de]=r.useState(!1),[ye,pe]=r.useState(!1),X=r.useCallback(async()=>{var n;j(!0);try{const[v,P,z]=await Promise.all([ft(s),vt(s),Ue(s).then(R=>R.nodes).catch(()=>[])]);g(v),C(P),E(z),!c&&P.length&&L(((n=P.find(R=>R.is_flow))==null?void 0:n.name)??P[0].name),d(null)}catch(v){d(v instanceof Error?v.message:"Failed to load edges")}finally{j(!1)}},[s,c]);r.useEffect(()=>{X()},[X]);const le=async()=>{if(!N.trim()||!x.trim()||!c)return;const n=m.find(v=>v.from_node===N.trim()&&v.to_node===x.trim()&&v.type.name===c);if(n){d(`${H(n.from_node)} → ${H(n.to_node)} is already connected with "${c}".`);return}de(!0);try{const v=T==="structured"?{term:Y.trim(),op:i,value:isNaN(Number(W))?W.trim():Number(W)}:T==="nl"?D.trim():null;await kt(s,{from_node:N.trim(),to_node:x.trim(),type:c,condition_mode:T||null,condition:T?v:null}),O(""),q(""),U(""),he(""),B(""),await X()}catch(v){d(v instanceof Error?v.message:"Failed to add edge")}finally{de(!1)}},be=n=>{w(n),pe(!0)},Ne=async n=>{try{await _t(s,n),g(v=>v.filter(P=>P.id!==n))}catch(v){d(v instanceof Error?v.message:"Failed to delete edge")}},we=new Map(h.map(n=>[n.id,n])),H=n=>{var v;return((v=we.get(n))==null?void 0:v.title)||n.replace(/^nodes\//,"")},ae=n=>{var v;return(v=we.get(n))==null?void 0:v.type},re=m.filter(n=>n.type.is_flow),G=m.filter(n=>!n.type.is_flow),Te=(ke=y.find(n=>n.is_flow))==null?void 0:ke.name,Z=new Map;for(const n of re)Z.has(n.from_node)||Z.set(n.from_node,[]),Z.get(n.from_node).push(n);const $e=new Set(re.map(n=>n.to_node)),Q=[...Z.keys()].filter(n=>!$e.has(n)).sort(),I=[...h].sort((n,v)=>{const P=z=>z.type==="agent"?0:z.type==="skill"?1:2;return P(n)-P(v)||String(n.title||n.id).localeCompare(String(v.title||v.id))}),ue=(n,v,P)=>{const z=[];for(const R of Z.get(n)??[])z.push(e.jsxs("div",{className:"flex items-center gap-2 py-1 rounded px-1 -mx-1 hover:bg-muted/40 group",style:{marginLeft:`${v*1.5}rem`},children:[e.jsx(nt,{className:"h-3.5 w-3.5 text-muted-foreground/50 shrink-0"}),e.jsx(Ts,{edge:R}),e.jsx(Ye,{className:"h-3 w-3 text-muted-foreground/50 shrink-0"}),e.jsx(Ce,{type:ae(R.to_node)}),e.jsx("span",{className:"text-sm truncate",title:R.to_node,children:H(R.to_node)}),R.type.name!==Te&&e.jsxs("span",{className:"text-[10px] text-muted-foreground shrink-0",children:["(",R.type.name,")"]}),e.jsx("div",{className:"flex-1"}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 text-muted-foreground",onClick:()=>be(R.to_node),title:"Add a step after this document",children:e.jsx(oe,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-destructive",onClick:()=>void Ne(R.id),title:"Remove this step",children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]},R.id)),P.has(R.to_node)||(P.add(R.to_node),z.push(...ue(R.to_node,v+1,P)));return z},ie=e.jsxs("div",{className:"rounded-lg border bg-muted/20 p-3",id:"wf-composer",children:[e.jsx("div",{className:"text-xs font-medium mb-2",children:"Connect two documents"}),e.jsxs("div",{className:"flex items-center flex-wrap gap-2",children:[e.jsxs("select",{value:N,onChange:n=>w(n.target.value),className:"h-8 rounded-md border bg-background px-2 text-sm max-w-[220px]","data-testid":"wf-compose-from",children:[e.jsx("option",{value:"",children:"When this runs…"}),I.map(n=>e.jsxs("option",{value:n.id,children:[n.type==="agent"?"🤖 ":n.type==="skill"?"⚡ ":"",n.title||n.id]},n.id))]}),e.jsx(Ye,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("div",{className:"flex items-center rounded-md border h-8 text-xs overflow-hidden",children:[["","always"],["nl","if…"],["structured","metric"]].map(([n,v],P)=>e.jsx("button",{type:"button",className:`px-2.5 h-full ${P>0?"border-l":""} ${T===n?"bg-primary text-primary-foreground":"hover:bg-muted"}`,onClick:()=>B(n),children:v},n))}),T==="nl"&&e.jsx(te,{value:D,onChange:n=>q(n.target.value),placeholder:'e.g. "lost on price, not product"',className:"h-8 text-sm italic w-60",title:"An AI judges this plain-English rule against the run's context"}),T==="structured"&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(te,{value:Y,onChange:n=>U(n.target.value),placeholder:"CAC",className:"h-8 text-sm w-24 font-mono",title:"A term from your governed definitions"}),e.jsx("select",{value:i,onChange:n=>$(n.target.value),className:"h-8 rounded-md border bg-background px-1.5 text-sm font-mono",children:[">","<",">=","<=","=","!="].map(n=>e.jsx("option",{value:n,children:n},n))}),e.jsx(te,{value:W,onChange:n=>he(n.target.value),placeholder:"500",className:"h-8 text-sm w-20 font-mono"})]}),e.jsx(Ye,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsxs("select",{value:x,onChange:n=>O(n.target.value),className:"h-8 rounded-md border bg-background px-2 text-sm max-w-[220px]","data-testid":"wf-compose-to",children:[e.jsx("option",{value:"",children:"…continue to"}),I.map(n=>e.jsxs("option",{value:n.id,children:[n.type==="agent"?"🤖 ":n.type==="skill"?"⚡ ":"",n.title||n.id]},n.id))]}),e.jsxs(S,{size:"sm",className:"h-8",disabled:ne||!N||!x||T==="nl"&&!D.trim()||T==="structured"&&!Y.trim(),onClick:()=>void le(),children:[ne?e.jsx(J,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(oe,{className:"h-3.5 w-3.5 mr-1"}),"Add step"]}),e.jsx("select",{value:c,onChange:n=>L(n.target.value),className:"h-8 rounded-md border bg-background px-1.5 text-xs text-muted-foreground ml-auto",title:"Edge type — flow types (▶) are walked by the runner; others are reference links",children:y.map(n=>e.jsxs("option",{value:n.name,children:[n.is_flow?"▶ ":"",n.name]},n.id))})]})]});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Each card is a flow the runner can walk, starting from its top node."}),e.jsx("div",{className:"flex-1"}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>void X(),children:[e.jsx(st,{className:"h-3.5 w-3.5 mr-1"})," Refresh"]})]}),k&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-line",children:k}),b?e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:e.jsx(J,{className:"h-4 w-4 animate-spin inline"})}):Q.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed p-6 text-center",children:[e.jsx("p",{className:"text-sm font-medium mb-1",children:"No flows yet"}),e.jsxs("p",{className:"text-xs text-muted-foreground max-w-md mx-auto",children:["A flow is a chain of steps: an ",e.jsx("b",{children:"agent"})," runs, and each connection says what happens next — always, when an AI judges a rule true, or when a metric crosses a threshold. Connect your first two documents below."]})]}):Q.map(n=>e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ce,{type:ae(n)}),e.jsx("span",{className:"font-medium text-sm truncate",title:n,children:H(n)}),e.jsx(se,{variant:"secondary",className:"text-[10px]",children:ae(n)==="agent"?"agent · start":"start"}),e.jsx("div",{className:"flex-1"}),e.jsxs(S,{variant:"ghost",size:"sm",className:"h-7 text-xs text-muted-foreground",onClick:()=>be(n),children:[e.jsx(oe,{className:"h-3.5 w-3.5 mr-1"})," Step"]})]}),ue(n,0,new Set([n]))]},n)),ye||Q.length===0||G.length+re.length===0?ie:e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>pe(!0),children:[e.jsx(oe,{className:"h-3.5 w-3.5 mr-1"})," Connect documents"]}),G.length>0&&e.jsxs("details",{className:"rounded-lg border px-3 py-2",children:[e.jsxs("summary",{className:"cursor-pointer text-xs font-medium text-muted-foreground select-none",children:["Reference links (",G.length,") — ontology edges the runner doesn't walk"]}),e.jsx("div",{className:"mt-2 space-y-1",children:G.map(n=>e.jsxs("div",{className:"flex items-center gap-2 text-sm group",children:[e.jsx(Ce,{type:ae(n.from_node)}),e.jsx("span",{className:"truncate",title:n.from_node,children:H(n.from_node)}),e.jsx("span",{className:"rounded-full px-2 py-0.5 text-[10px] text-muted-foreground border",style:{borderColor:n.type.color??void 0},children:n.type.name}),e.jsx(Ce,{type:ae(n.to_node)}),e.jsx("span",{className:"truncate",title:n.to_node,children:H(n.to_node)}),e.jsx("div",{className:"flex-1"}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-destructive",onClick:()=>void Ne(n.id),title:"Delete link",children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]},n.id))})]}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[e.jsx("b",{children:"always"})," = the step fires whenever the previous one runs ·"," ",e.jsx("b",{children:"if…"})," = an AI judges a plain-English rule against the run's context · ",e.jsx("b",{children:"metric"})," = a deterministic check like"," ",e.jsx("code",{children:"CAC > 500"}),", resolved from your governed terms."]})]})}const As=8,Ps=16;function pt({value:s,onValueChange:m,runnables:g,placeholder:y,testId:C,disabledReason:b}){return e.jsxs(Ct,{value:s||void 0,onValueChange:m,children:[e.jsx(Et,{className:"h-9 w-full","data-testid":C,disabled:!g.length,children:e.jsx(Tt,{placeholder:g.length?y:"No runnable agents yet"})}),e.jsx($t,{children:g.map(j=>{const k=(b==null?void 0:b(j.id))??null;return e.jsx(et,{value:j.id,disabled:!!k,children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(We,{type:j.type,className:"h-3.5 w-3.5"}),j.title||j.id,k&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["— ",k]})]})},j.id)})})]})}function Rs({value:s,onValueChange:m,runs:g,runLabel:y,runType:C,blockedReason:b}){const j="__none__",k=g.filter(d=>d.status==="running");return e.jsxs(Ct,{value:s||j,onValueChange:d=>m(d===j?"":d),children:[e.jsx(Et,{className:"h-auto min-h-9 w-full","data-testid":"run-parent-lookup",children:e.jsx(Tt,{})}),e.jsxs($t,{children:[e.jsx(et,{value:j,children:"— None (top-level run)"}),k.map(d=>{const h=b(d),E=d.depth??0;return e.jsx(et,{value:d.id,disabled:!!h,children:e.jsxs("span",{className:"flex flex-col gap-0.5 py-0.5",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(We,{type:C(d.agent_node),className:"h-3.5 w-3.5"}),e.jsx("span",{className:"font-medium",children:y(d.agent_node)}),e.jsx("span",{className:"font-mono text-[11px] text-muted-foreground",children:d.id.replace(/^run_/,"").slice(0,8)}),h&&e.jsx(se,{variant:"outline",className:"text-[10px]",children:h})]}),e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:["depth ",E," → ",E+1," · ",Ee(d.started_at)]})]})},d.id)})]})]})}function Ms({nestId:s}){const{subagentRunsEnabled:m,subagentMaxDepth:g,subagentMaxChildren:y}=Yt(),C=g||As,b=y||Ps,[j,k]=r.useState([]),[d,h]=r.useState(null),[E,N]=r.useState(!0),[w,x]=r.useState(null),[O,c]=r.useState(""),[L,T]=r.useState(!1),[B,D]=r.useState(""),[q,Y]=r.useState(""),[U,i]=r.useState(""),[$,W]=r.useState(""),[he,ne]=r.useState(""),[de,ye]=r.useState(!1),[pe,X]=r.useState(null),[le,be]=r.useState(null),[Ne,we]=r.useState([]),H=r.useCallback(async()=>{N(!0);try{const[a,p]=await Promise.all([Zt(s,void 0,500),Ue(s).then(F=>F.nodes).catch(()=>[])]);k(a),we(p),x(null)}catch(a){x(a instanceof Error?a.message:"Failed to load runs")}finally{N(!1)}},[s]),ae=Ne.filter(a=>a.type==="agent"||a.type==="skill");r.useEffect(()=>{H()},[H]);const re=async a=>{try{h(await cs(a))}catch(p){x(p instanceof Error?p.message:"Failed to load run")}},G=async a=>{be(a);try{await is(a),await H(),(d==null?void 0:d.id)===a&&await re(a)}catch(p){x(p instanceof Error?p.message:"Failed to cancel run")}finally{be(null)}},Te=a=>{const p=a.trim();if(p)try{const F=JSON.parse(p);return typeof F=="object"&&F!==null?F:{input:F}}catch{return{input:p}}},Z=async()=>{if(O.trim()){T(!0);try{await Qe(s,O.trim(),Te(B),q||void 0),c(""),D(""),Y(""),await H()}catch(a){x(a instanceof Error?a.message:"Failed to trigger run")}finally{T(!1)}}},$e=async a=>{if($.trim()){ye(!0),X(null);try{await Qe(s,$.trim(),Te(he),a),i(""),W(""),ne(""),await H()}catch(p){X(p instanceof Error?p.message:"Failed to spawn sub-agent")}finally{ye(!1)}}},Q=new Map(Ne.map(a=>[a.id,a])),I=a=>{var p;return((p=Q.get(a))==null?void 0:p.title)||a.replace(/^nodes\//,"")},ue=a=>{var p;return(p=Q.get(a))==null?void 0:p.type},ie=new Map,ke=new Set(j.map(a=>a.id)),n=[];for(const a of j)a.parent_run_id&&ke.has(a.parent_run_id)?(ie.has(a.parent_run_id)||ie.set(a.parent_run_id,[]),ie.get(a.parent_run_id).push(a)):n.push(a);const v=new Map(j.map(a=>[a.id,a])),P=a=>{var p;return((p=ie.get(a))==null?void 0:p.length)??0},z=a=>{const p=new Set;let F=a;for(let me=0;F&&me<=C+1;me++){const fe=v.get(F);if(!fe)break;p.add(fe.agent_node),F=fe.parent_run_id??null}return p},R=(a,p)=>(a.depth??0)>=C?"at max depth":P(a.id)>=b?`${b}/${b} full`:p&&z(a.id).has(p)?"would loop":null,Fe=q?v.get(q)??null:null,ge=Fe?R(Fe,O):null,Pe=(a,p)=>{var fe;const F=ie.get(a.id)??[],me=p?ht(p):void 0;return e.jsxs("div",{children:[e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>void re(a.id),onKeyDown:K=>{(K.key==="Enter"||K.key===" ")&&re(a.id)},className:`group w-full overflow-hidden cursor-pointer px-3 py-2 hover:bg-muted/40 ${(d==null?void 0:d.id)===a.id?"bg-muted/60":""}`,style:{paddingLeft:me},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[p>0&&e.jsx(nt,{className:"h-3 w-3 text-muted-foreground/50 shrink-0","aria-label":`Sub-agent at depth ${a.depth??p}`,children:e.jsx("title",{children:`Sub-agent at depth ${a.depth??p}`})}),e.jsx(We,{type:ue(a.agent_node),className:"h-3.5 w-3.5"}),e.jsx("span",{className:"font-mono text-xs truncate min-w-[6rem]",title:a.id,children:a.id.length>12?`${a.id.slice(0,12)}…`:a.id}),e.jsx(se,{variant:tt(Ae(a)),className:"text-[10px]",title:qe(a)?Mt:void 0,children:Ae(a)}),a.status==="running"&&(()=>{const K=[];return m&&(a.depth??0)<C&&P(a.id)<b&&K.push({label:U===a.id?"Close sub-agent form":"Spawn sub-agent",icon:oe,testId:"run-action-spawn",onSelect:()=>{i(U===a.id?"":a.id),W(""),ne(""),X(null)}}),K.push({label:le===a.id?"Cancelling…":"Cancel run",icon:le===a.id?J:Rt,iconClassName:le===a.id?"animate-spin":void 0,destructive:!0,disabled:le===a.id,separatorBefore:!0,testId:"run-action-cancel",onSelect:()=>void G(a.id)}),e.jsx("div",{className:"ml-auto shrink-0",children:e.jsx(ps,{actions:K,className:"h-6 w-6 text-muted-foreground",triggerTitle:"Run actions",testId:"run-actions"})})})()]}),e.jsxs("div",{className:"text-[11px] text-muted-foreground truncate",children:[I(a.agent_node)," · ",Ee(a.started_at),F.length>0&&` · ${F.length} child${F.length===1?"":"ren"}`]}),a.status==="failed"&&((fe=a.trace)==null?void 0:fe.error)&&e.jsx("div",{className:"text-[11px] text-destructive truncate mt-0.5",title:String(a.trace.error),children:String(a.trace.error).replace(/^\d+ /,"").slice(0,110)})]}),m&&U===a.id&&e.jsxs("div",{className:"border-t bg-muted/20 px-3 py-2.5 space-y-2",style:{paddingLeft:ht(p+1)},children:[e.jsxs("div",{className:"text-[11px] font-medium text-muted-foreground",children:["New sub-agent under"," ",e.jsx("span",{className:"font-mono",children:a.id.slice(0,12)})," —"," ",I(a.agent_node)," · depth ",a.depth??p," → child depth"," ",(a.depth??p)+1]}),e.jsx(pt,{value:$,onValueChange:W,runnables:ae,placeholder:"Choose an agent…",testId:"spawn-agent-lookup",disabledReason:K=>z(a.id).has(K)?"already in this chain":null}),e.jsx("textarea",{value:he,onChange:K=>ne(K.target.value),placeholder:"Inputs (optional) — plain text or JSON",className:"w-full rounded-md border bg-background px-2 py-1.5 text-xs font-mono min-h-[44px]"}),pe&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-2.5 py-1.5 text-[11px] text-destructive",children:pe}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(S,{size:"sm",className:"h-7",disabled:de||!$.trim(),onClick:()=>void $e(a.id),children:[de?e.jsx(J,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):e.jsx(oe,{className:"h-3.5 w-3.5 mr-1"}),"Create sub-agent"]}),e.jsx(S,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{i(""),X(null)},children:"Cancel"})]})]}),F.map(K=>Pe(K,p+1))]},a.id)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Trigger a run"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Creates a run record + bundle (inputs ride along). The server never executes — a runner (the contextnest-runner) walks the bundle and posts each step back into the trace below."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[11px] font-medium text-muted-foreground mb-1",children:"Agent / skill node"}),e.jsx(pt,{value:O,onValueChange:c,runnables:ae,placeholder:"Choose an agent to run…",testId:"run-agent-lookup"})]}),m&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-[11px] font-medium text-muted-foreground mb-1",children:"Parent run (optional — spawn as a sub-agent)"}),e.jsx(Rs,{value:q,onValueChange:Y,runs:j,runLabel:I,runType:ue,blockedReason:a=>R(a,O)}),ge&&e.jsxs("p",{className:"text-[11px] text-destructive mt-1",children:["This parent can't be used (",ge,") — pick another or change the agent."]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[11px] font-medium text-muted-foreground mb-1",children:"Inputs (optional — plain text or JSON)"}),e.jsx("textarea",{value:B,onChange:a=>D(a.target.value),placeholder:'e.g. {"account":"Foley"}',className:"w-full rounded-md border bg-background px-2 py-1.5 text-xs font-mono min-h-[64px]"})]}),w&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:w}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(S,{disabled:L||!O.trim()||!!ge,onClick:()=>void Z(),title:"Create a run (a runner executes it)",children:[L?e.jsx(J,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):e.jsx(At,{className:"h-3.5 w-3.5 mr-1.5"}),"Create run"]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>void H(),children:[e.jsx(st,{className:"h-3.5 w-3.5 mr-1"})," Refresh"]})]}),e.jsxs("details",{className:"rounded-md border bg-muted/30 px-3 py-2 text-[11px]",children:[e.jsx("summary",{className:"cursor-pointer font-medium",children:"How do I run one? (the runner is a separate process)"}),e.jsxs("div",{className:"mt-2 space-y-1.5 text-muted-foreground",children:[e.jsxs("p",{children:["The ",e.jsx("b",{children:"trigger"})," button just records a run. The"," ",e.jsx("b",{children:"runner"})," is a small stateless container that actually walks it and calls the LLM. Point it at this nest:"]}),e.jsx("pre",{className:"overflow-x-auto rounded bg-background border p-2 font-mono text-[10.5px] leading-relaxed",children:`docker run -d --name cn-runner --network host \\
11
+ */const Ns=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6h4",key:"135r8i"}]],ws=gt("clock-3",Ns),ks=6,xt=46;function _s(s,m){const g=m?`${s} · ${m}`:s,y=g.length>xt?`${g.slice(0,xt-1).trimEnd()}…`:g;return{full:g,short:y,width:y.length*ks+8}}const tt=s=>s==="succeeded"?"default":s==="failed"||s==="cancelled"?"destructive":s==="queued"?"outline":"secondary",Ss=.85,Cs=6;function ht(s){return`${.75+Math.min(s,Cs)*Ss}rem`}const Ae=s=>qe(s)?"queued":s.status,Mt="Created — waiting for a runner to claim it",Es=s=>s==="read"?e.jsx(ds,{className:"h-3.5 w-3.5"}):s==="branch"?e.jsx(Pt,{className:"h-3.5 w-3.5"}):s==="write"?e.jsx(us,{className:"h-3.5 w-3.5"}):s==="notify"?e.jsx(bs,{className:"h-3.5 w-3.5"}):e.jsx("span",{className:"h-3.5 w-3.5"}),Ee=s=>xs(s)||s;function Ts({nestId:s,nestName:m,onBack:g}){const[y,C]=r.useState("canvas");return e.jsxs("div",{children:[e.jsx(fs,{nestName:m,onBack:g}),e.jsxs(Vt,{value:y,onValueChange:C,children:[e.jsxs(Bt,{children:[e.jsx(Ve,{value:"canvas",children:"Canvas"}),e.jsx(Ve,{value:"table",children:"Table"}),e.jsx(Ve,{value:"run",children:"Run"}),e.jsx(Ve,{value:"activity",children:"Activity"})]}),e.jsx(Be,{value:"canvas",className:"mt-4",children:e.jsx(Fs,{nestId:s})}),e.jsx(Be,{value:"table",className:"mt-4",children:e.jsx(As,{nestId:s})}),e.jsx(Be,{value:"run",className:"mt-4",children:e.jsx(Os,{nestId:s})}),e.jsxs(Be,{value:"activity",className:"mt-4 space-y-6",children:[e.jsx(Ks,{nestId:s}),e.jsx(Ds,{nestId:s}),e.jsx(Bs,{nestId:s}),e.jsx(Hs,{nestId:s})]})]})]})}function Ce({type:s}){return s==="agent"?e.jsx(as,{className:"h-3.5 w-3.5 text-violet-500 shrink-0"}):s==="skill"?e.jsx(Pt,{className:"h-3.5 w-3.5 text-blue-500 shrink-0"}):s==="artifact"?e.jsx(gs,{className:"h-3.5 w-3.5 text-amber-500 shrink-0"}):s==="tool"?e.jsx(St,{className:"h-3.5 w-3.5 text-teal-500 shrink-0"}):s==="table"?e.jsx(hs,{className:"h-3.5 w-3.5 text-cyan-500 shrink-0"}):s==="pdf"?e.jsx(vs,{className:"h-3.5 w-3.5 text-rose-500 shrink-0"}):e.jsx(rs,{className:"h-3.5 w-3.5 text-slate-400 shrink-0"})}function $s({edge:s}){if(!s.condition_mode||!s.condition)return e.jsx("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[10px] text-muted-foreground",children:"always"});if(s.condition_mode==="nl")return e.jsxs("span",{className:"rounded-full bg-amber-500/10 text-amber-700 dark:text-amber-300 px-2 py-0.5 text-[10px] italic max-w-[260px] truncate inline-block align-middle",title:`AI judges: "${s.condition}"`,children:["if “",String(s.condition),"”"]});let m="";try{const g=typeof s.condition=="string"?JSON.parse(s.condition):s.condition;m=g&&g.term?`${g.term} ${g.op??""} ${g.value??""}`:JSON.stringify(g)}catch{m=String(s.condition)}return e.jsx("span",{className:"rounded-full bg-blue-500/10 text-blue-700 dark:text-blue-300 px-2 py-0.5 text-[10px] font-mono max-w-[260px] truncate inline-block align-middle",title:`Deterministic check: ${m}`,children:m})}function As({nestId:s}){var ke;const[m,g]=r.useState([]),[y,C]=r.useState([]),[b,j]=r.useState(!0),[k,d]=r.useState(null),[h,E]=r.useState([]),[N,w]=r.useState(""),[x,O]=r.useState(""),[c,L]=r.useState(""),[T,B]=r.useState(""),[D,q]=r.useState(""),[Y,U]=r.useState(""),[i,$]=r.useState(">"),[W,he]=r.useState(""),[ne,de]=r.useState(!1),[ye,pe]=r.useState(!1),X=r.useCallback(async()=>{var n;j(!0);try{const[v,P,z]=await Promise.all([ft(s),vt(s),Ue(s).then(R=>R.nodes).catch(()=>[])]);g(v),C(P),E(z),!c&&P.length&&L(((n=P.find(R=>R.is_flow))==null?void 0:n.name)??P[0].name),d(null)}catch(v){d(v instanceof Error?v.message:"Failed to load edges")}finally{j(!1)}},[s,c]);r.useEffect(()=>{X()},[X]);const le=async()=>{if(!N.trim()||!x.trim()||!c)return;const n=m.find(v=>v.from_node===N.trim()&&v.to_node===x.trim()&&v.type.name===c);if(n){d(`${H(n.from_node)} → ${H(n.to_node)} is already connected with "${c}".`);return}de(!0);try{const v=T==="structured"?{term:Y.trim(),op:i,value:isNaN(Number(W))?W.trim():Number(W)}:T==="nl"?D.trim():null;await kt(s,{from_node:N.trim(),to_node:x.trim(),type:c,condition_mode:T||null,condition:T?v:null}),O(""),q(""),U(""),he(""),B(""),await X()}catch(v){d(v instanceof Error?v.message:"Failed to add edge")}finally{de(!1)}},be=n=>{w(n),pe(!0)},Ne=async n=>{try{await _t(s,n),g(v=>v.filter(P=>P.id!==n))}catch(v){d(v instanceof Error?v.message:"Failed to delete edge")}},we=new Map(h.map(n=>[n.id,n])),H=n=>{var v;return((v=we.get(n))==null?void 0:v.title)||n.replace(/^nodes\//,"")},ae=n=>{var v;return(v=we.get(n))==null?void 0:v.type},re=m.filter(n=>n.type.is_flow),G=m.filter(n=>!n.type.is_flow),Te=(ke=y.find(n=>n.is_flow))==null?void 0:ke.name,Z=new Map;for(const n of re)Z.has(n.from_node)||Z.set(n.from_node,[]),Z.get(n.from_node).push(n);const $e=new Set(re.map(n=>n.to_node)),Q=[...Z.keys()].filter(n=>!$e.has(n)).sort(),I=[...h].sort((n,v)=>{const P=z=>z.type==="agent"?0:z.type==="skill"?1:2;return P(n)-P(v)||String(n.title||n.id).localeCompare(String(v.title||v.id))}),ue=(n,v,P)=>{const z=[];for(const R of Z.get(n)??[])z.push(e.jsxs("div",{className:"flex items-center gap-2 py-1 rounded px-1 -mx-1 hover:bg-muted/40 group",style:{marginLeft:`${v*1.5}rem`},children:[e.jsx(nt,{className:"h-3.5 w-3.5 text-muted-foreground/50 shrink-0"}),e.jsx($s,{edge:R}),e.jsx(Ye,{className:"h-3 w-3 text-muted-foreground/50 shrink-0"}),e.jsx(Ce,{type:ae(R.to_node)}),e.jsx("span",{className:"text-sm truncate",title:R.to_node,children:H(R.to_node)}),R.type.name!==Te&&e.jsxs("span",{className:"text-[10px] text-muted-foreground shrink-0",children:["(",R.type.name,")"]}),e.jsx("div",{className:"flex-1"}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 text-muted-foreground",onClick:()=>be(R.to_node),title:"Add a step after this document",children:e.jsx(oe,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-destructive",onClick:()=>void Ne(R.id),title:"Remove this step",children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]},R.id)),P.has(R.to_node)||(P.add(R.to_node),z.push(...ue(R.to_node,v+1,P)));return z},ie=e.jsxs("div",{className:"rounded-lg border bg-muted/20 p-3",id:"wf-composer",children:[e.jsx("div",{className:"text-xs font-medium mb-2",children:"Connect two documents"}),e.jsxs("div",{className:"flex items-center flex-wrap gap-2",children:[e.jsxs("select",{value:N,onChange:n=>w(n.target.value),className:"h-8 rounded-md border bg-background px-2 text-sm max-w-[220px]","data-testid":"wf-compose-from",children:[e.jsx("option",{value:"",children:"When this runs…"}),I.map(n=>e.jsxs("option",{value:n.id,children:[n.type==="agent"?"🤖 ":n.type==="skill"?"⚡ ":"",n.title||n.id]},n.id))]}),e.jsx(Ye,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("div",{className:"flex items-center rounded-md border h-8 text-xs overflow-hidden",children:[["","always"],["nl","if…"],["structured","metric"]].map(([n,v],P)=>e.jsx("button",{type:"button",className:`px-2.5 h-full ${P>0?"border-l":""} ${T===n?"bg-primary text-primary-foreground":"hover:bg-muted"}`,onClick:()=>B(n),children:v},n))}),T==="nl"&&e.jsx(te,{value:D,onChange:n=>q(n.target.value),placeholder:'e.g. "lost on price, not product"',className:"h-8 text-sm italic w-60",title:"An AI judges this plain-English rule against the run's context"}),T==="structured"&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(te,{value:Y,onChange:n=>U(n.target.value),placeholder:"CAC",className:"h-8 text-sm w-24 font-mono",title:"A term from your governed definitions"}),e.jsx("select",{value:i,onChange:n=>$(n.target.value),className:"h-8 rounded-md border bg-background px-1.5 text-sm font-mono",children:[">","<",">=","<=","=","!="].map(n=>e.jsx("option",{value:n,children:n},n))}),e.jsx(te,{value:W,onChange:n=>he(n.target.value),placeholder:"500",className:"h-8 text-sm w-20 font-mono"})]}),e.jsx(Ye,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsxs("select",{value:x,onChange:n=>O(n.target.value),className:"h-8 rounded-md border bg-background px-2 text-sm max-w-[220px]","data-testid":"wf-compose-to",children:[e.jsx("option",{value:"",children:"…continue to"}),I.map(n=>e.jsxs("option",{value:n.id,children:[n.type==="agent"?"🤖 ":n.type==="skill"?"⚡ ":"",n.title||n.id]},n.id))]}),e.jsxs(S,{size:"sm",className:"h-8",disabled:ne||!N||!x||T==="nl"&&!D.trim()||T==="structured"&&!Y.trim(),onClick:()=>void le(),children:[ne?e.jsx(J,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(oe,{className:"h-3.5 w-3.5 mr-1"}),"Add step"]}),e.jsx("select",{value:c,onChange:n=>L(n.target.value),className:"h-8 rounded-md border bg-background px-1.5 text-xs text-muted-foreground ml-auto",title:"Edge type — flow types (▶) are walked by the runner; others are reference links",children:y.map(n=>e.jsxs("option",{value:n.name,children:[n.is_flow?"▶ ":"",n.name]},n.id))})]})]});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Each card is a flow the runner can walk, starting from its top node."}),e.jsx("div",{className:"flex-1"}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>void X(),children:[e.jsx(st,{className:"h-3.5 w-3.5 mr-1"})," Refresh"]})]}),k&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-line",children:k}),b?e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:e.jsx(J,{className:"h-4 w-4 animate-spin inline"})}):Q.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed p-6 text-center",children:[e.jsx("p",{className:"text-sm font-medium mb-1",children:"No flows yet"}),e.jsxs("p",{className:"text-xs text-muted-foreground max-w-md mx-auto",children:["A flow is a chain of steps: an ",e.jsx("b",{children:"agent"})," runs, and each connection says what happens next — always, when an AI judges a rule true, or when a metric crosses a threshold. Connect your first two documents below."]})]}):Q.map(n=>e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ce,{type:ae(n)}),e.jsx("span",{className:"font-medium text-sm truncate",title:n,children:H(n)}),e.jsx(se,{variant:"secondary",className:"text-[10px]",children:ae(n)==="agent"?"agent · start":"start"}),e.jsx("div",{className:"flex-1"}),e.jsxs(S,{variant:"ghost",size:"sm",className:"h-7 text-xs text-muted-foreground",onClick:()=>be(n),children:[e.jsx(oe,{className:"h-3.5 w-3.5 mr-1"})," Step"]})]}),ue(n,0,new Set([n]))]},n)),ye||Q.length===0||G.length+re.length===0?ie:e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>pe(!0),children:[e.jsx(oe,{className:"h-3.5 w-3.5 mr-1"})," Connect documents"]}),G.length>0&&e.jsxs("details",{className:"rounded-lg border px-3 py-2",children:[e.jsxs("summary",{className:"cursor-pointer text-xs font-medium text-muted-foreground select-none",children:["Reference links (",G.length,") — ontology edges the runner doesn't walk"]}),e.jsx("div",{className:"mt-2 space-y-1",children:G.map(n=>e.jsxs("div",{className:"flex items-center gap-2 text-sm group",children:[e.jsx(Ce,{type:ae(n.from_node)}),e.jsx("span",{className:"truncate",title:n.from_node,children:H(n.from_node)}),e.jsx("span",{className:"rounded-full px-2 py-0.5 text-[10px] text-muted-foreground border",style:{borderColor:n.type.color??void 0},children:n.type.name}),e.jsx(Ce,{type:ae(n.to_node)}),e.jsx("span",{className:"truncate",title:n.to_node,children:H(n.to_node)}),e.jsx("div",{className:"flex-1"}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-destructive",onClick:()=>void Ne(n.id),title:"Delete link",children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]},n.id))})]}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[e.jsx("b",{children:"always"})," = the step fires whenever the previous one runs ·"," ",e.jsx("b",{children:"if…"})," = an AI judges a plain-English rule against the run's context · ",e.jsx("b",{children:"metric"})," = a deterministic check like"," ",e.jsx("code",{children:"CAC > 500"}),", resolved from your governed terms."]})]})}const Ps=8,Rs=16;function pt({value:s,onValueChange:m,runnables:g,placeholder:y,testId:C,disabledReason:b}){return e.jsxs(Ct,{value:s||void 0,onValueChange:m,children:[e.jsx(Et,{className:"h-9 w-full","data-testid":C,disabled:!g.length,children:e.jsx(Tt,{placeholder:g.length?y:"No runnable agents yet"})}),e.jsx($t,{children:g.map(j=>{const k=(b==null?void 0:b(j.id))??null;return e.jsx(et,{value:j.id,disabled:!!k,children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(We,{type:j.type,className:"h-3.5 w-3.5"}),j.title||j.id,k&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["— ",k]})]})},j.id)})})]})}function Ms({value:s,onValueChange:m,runs:g,runLabel:y,runType:C,blockedReason:b}){const j="__none__",k=g.filter(d=>d.status==="running");return e.jsxs(Ct,{value:s||j,onValueChange:d=>m(d===j?"":d),children:[e.jsx(Et,{className:"h-auto min-h-9 w-full","data-testid":"run-parent-lookup",children:e.jsx(Tt,{})}),e.jsxs($t,{children:[e.jsx(et,{value:j,children:"— None (top-level run)"}),k.map(d=>{const h=b(d),E=d.depth??0;return e.jsx(et,{value:d.id,disabled:!!h,children:e.jsxs("span",{className:"flex flex-col gap-0.5 py-0.5",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(We,{type:C(d.agent_node),className:"h-3.5 w-3.5"}),e.jsx("span",{className:"font-medium",children:y(d.agent_node)}),e.jsx("span",{className:"font-mono text-[11px] text-muted-foreground",children:d.id.replace(/^run_/,"").slice(0,8)}),h&&e.jsx(se,{variant:"outline",className:"text-[10px]",children:h})]}),e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:["depth ",E," → ",E+1," · ",Ee(d.started_at)]})]})},d.id)})]})]})}function Os({nestId:s}){const{subagentRunsEnabled:m,subagentMaxDepth:g,subagentMaxChildren:y}=Yt(),C=g||Ps,b=y||Rs,[j,k]=r.useState([]),[d,h]=r.useState(null),[E,N]=r.useState(!0),[w,x]=r.useState(null),[O,c]=r.useState(""),[L,T]=r.useState(!1),[B,D]=r.useState(""),[q,Y]=r.useState(""),[U,i]=r.useState(""),[$,W]=r.useState(""),[he,ne]=r.useState(""),[de,ye]=r.useState(!1),[pe,X]=r.useState(null),[le,be]=r.useState(null),[Ne,we]=r.useState([]),H=r.useCallback(async()=>{N(!0);try{const[a,p]=await Promise.all([Zt(s,void 0,500),Ue(s).then(F=>F.nodes).catch(()=>[])]);k(a),we(p),x(null)}catch(a){x(a instanceof Error?a.message:"Failed to load runs")}finally{N(!1)}},[s]),ae=Ne.filter(a=>a.type==="agent"||a.type==="skill");r.useEffect(()=>{H()},[H]);const re=async a=>{try{h(await cs(a))}catch(p){x(p instanceof Error?p.message:"Failed to load run")}},G=async a=>{be(a);try{await is(a),await H(),(d==null?void 0:d.id)===a&&await re(a)}catch(p){x(p instanceof Error?p.message:"Failed to cancel run")}finally{be(null)}},Te=a=>{const p=a.trim();if(p)try{const F=JSON.parse(p);return typeof F=="object"&&F!==null?F:{input:F}}catch{return{input:p}}},Z=async()=>{if(O.trim()){T(!0);try{await Qe(s,O.trim(),Te(B),q||void 0),c(""),D(""),Y(""),await H()}catch(a){x(a instanceof Error?a.message:"Failed to trigger run")}finally{T(!1)}}},$e=async a=>{if($.trim()){ye(!0),X(null);try{await Qe(s,$.trim(),Te(he),a),i(""),W(""),ne(""),await H()}catch(p){X(p instanceof Error?p.message:"Failed to spawn sub-agent")}finally{ye(!1)}}},Q=new Map(Ne.map(a=>[a.id,a])),I=a=>{var p;return((p=Q.get(a))==null?void 0:p.title)||a.replace(/^nodes\//,"")},ue=a=>{var p;return(p=Q.get(a))==null?void 0:p.type},ie=new Map,ke=new Set(j.map(a=>a.id)),n=[];for(const a of j)a.parent_run_id&&ke.has(a.parent_run_id)?(ie.has(a.parent_run_id)||ie.set(a.parent_run_id,[]),ie.get(a.parent_run_id).push(a)):n.push(a);const v=new Map(j.map(a=>[a.id,a])),P=a=>{var p;return((p=ie.get(a))==null?void 0:p.length)??0},z=a=>{const p=new Set;let F=a;for(let me=0;F&&me<=C+1;me++){const fe=v.get(F);if(!fe)break;p.add(fe.agent_node),F=fe.parent_run_id??null}return p},R=(a,p)=>(a.depth??0)>=C?"at max depth":P(a.id)>=b?`${b}/${b} full`:p&&z(a.id).has(p)?"would loop":null,Fe=q?v.get(q)??null:null,ge=Fe?R(Fe,O):null,Pe=(a,p)=>{var fe;const F=ie.get(a.id)??[],me=p?ht(p):void 0;return e.jsxs("div",{children:[e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>void re(a.id),onKeyDown:K=>{(K.key==="Enter"||K.key===" ")&&re(a.id)},className:`group w-full overflow-hidden cursor-pointer px-3 py-2 hover:bg-muted/40 ${(d==null?void 0:d.id)===a.id?"bg-muted/60":""}`,style:{paddingLeft:me},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[p>0&&e.jsx(nt,{className:"h-3 w-3 text-muted-foreground/50 shrink-0","aria-label":`Sub-agent at depth ${a.depth??p}`,children:e.jsx("title",{children:`Sub-agent at depth ${a.depth??p}`})}),e.jsx(We,{type:ue(a.agent_node),className:"h-3.5 w-3.5"}),e.jsx("span",{className:"font-mono text-xs truncate min-w-[6rem]",title:a.id,children:a.id.length>12?`${a.id.slice(0,12)}…`:a.id}),e.jsx(se,{variant:tt(Ae(a)),className:"text-[10px]",title:qe(a)?Mt:void 0,children:Ae(a)}),a.status==="running"&&(()=>{const K=[];return m&&(a.depth??0)<C&&P(a.id)<b&&K.push({label:U===a.id?"Close sub-agent form":"Spawn sub-agent",icon:oe,testId:"run-action-spawn",onSelect:()=>{i(U===a.id?"":a.id),W(""),ne(""),X(null)}}),K.push({label:le===a.id?"Cancelling…":"Cancel run",icon:le===a.id?J:Rt,iconClassName:le===a.id?"animate-spin":void 0,destructive:!0,disabled:le===a.id,separatorBefore:!0,testId:"run-action-cancel",onSelect:()=>void G(a.id)}),e.jsx("div",{className:"ml-auto shrink-0",children:e.jsx(ps,{actions:K,className:"h-6 w-6 text-muted-foreground",triggerTitle:"Run actions",testId:"run-actions"})})})()]}),e.jsxs("div",{className:"text-[11px] text-muted-foreground truncate",children:[I(a.agent_node)," · ",Ee(a.started_at),F.length>0&&` · ${F.length} child${F.length===1?"":"ren"}`]}),a.status==="failed"&&((fe=a.trace)==null?void 0:fe.error)&&e.jsx("div",{className:"text-[11px] text-destructive truncate mt-0.5",title:String(a.trace.error),children:String(a.trace.error).replace(/^\d+ /,"").slice(0,110)})]}),m&&U===a.id&&e.jsxs("div",{className:"border-t bg-muted/20 px-3 py-2.5 space-y-2",style:{paddingLeft:ht(p+1)},children:[e.jsxs("div",{className:"text-[11px] font-medium text-muted-foreground",children:["New sub-agent under"," ",e.jsx("span",{className:"font-mono",children:a.id.slice(0,12)})," —"," ",I(a.agent_node)," · depth ",a.depth??p," → child depth"," ",(a.depth??p)+1]}),e.jsx(pt,{value:$,onValueChange:W,runnables:ae,placeholder:"Choose an agent…",testId:"spawn-agent-lookup",disabledReason:K=>z(a.id).has(K)?"already in this chain":null}),e.jsx("textarea",{value:he,onChange:K=>ne(K.target.value),placeholder:"Inputs (optional) — plain text or JSON",className:"w-full rounded-md border bg-background px-2 py-1.5 text-xs font-mono min-h-[44px]"}),pe&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-2.5 py-1.5 text-[11px] text-destructive",children:pe}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(S,{size:"sm",className:"h-7",disabled:de||!$.trim(),onClick:()=>void $e(a.id),children:[de?e.jsx(J,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):e.jsx(oe,{className:"h-3.5 w-3.5 mr-1"}),"Create sub-agent"]}),e.jsx(S,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{i(""),X(null)},children:"Cancel"})]})]}),F.map(K=>Pe(K,p+1))]},a.id)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Trigger a run"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Creates a run record + bundle (inputs ride along). The server never executes — a runner (the contextnest-runner) walks the bundle and posts each step back into the trace below."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[11px] font-medium text-muted-foreground mb-1",children:"Agent / skill node"}),e.jsx(pt,{value:O,onValueChange:c,runnables:ae,placeholder:"Choose an agent to run…",testId:"run-agent-lookup"})]}),m&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-[11px] font-medium text-muted-foreground mb-1",children:"Parent run (optional — spawn as a sub-agent)"}),e.jsx(Ms,{value:q,onValueChange:Y,runs:j,runLabel:I,runType:ue,blockedReason:a=>R(a,O)}),ge&&e.jsxs("p",{className:"text-[11px] text-destructive mt-1",children:["This parent can't be used (",ge,") — pick another or change the agent."]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[11px] font-medium text-muted-foreground mb-1",children:"Inputs (optional — plain text or JSON)"}),e.jsx("textarea",{value:B,onChange:a=>D(a.target.value),placeholder:'e.g. {"account":"Foley"}',className:"w-full rounded-md border bg-background px-2 py-1.5 text-xs font-mono min-h-[64px]"})]}),w&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:w}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(S,{disabled:L||!O.trim()||!!ge,onClick:()=>void Z(),title:"Create a run (a runner executes it)",children:[L?e.jsx(J,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):e.jsx(At,{className:"h-3.5 w-3.5 mr-1.5"}),"Create run"]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>void H(),children:[e.jsx(st,{className:"h-3.5 w-3.5 mr-1"})," Refresh"]})]}),e.jsxs("details",{className:"rounded-md border bg-muted/30 px-3 py-2 text-[11px]",children:[e.jsx("summary",{className:"cursor-pointer font-medium",children:"How do I run one? (the runner is a separate process)"}),e.jsxs("div",{className:"mt-2 space-y-1.5 text-muted-foreground",children:[e.jsxs("p",{children:["The ",e.jsx("b",{children:"trigger"})," button just records a run. The"," ",e.jsx("b",{children:"runner"})," is a small stateless container that actually walks it and calls the LLM. Point it at this nest:"]}),e.jsx("pre",{className:"overflow-x-auto rounded bg-background border p-2 font-mono text-[10.5px] leading-relaxed",children:`docker run -d --name cn-runner --network host \\
12
12
  -e CONTEXTNEST_SERVER=http://localhost:4040 \\
13
13
  -e CONTEXTNEST_NEST=${s} \\
14
14
  -e CONTEXTNEST_KEY=cnst_localdev \\
15
- contextnest-runner:local poll`}),e.jsxs("p",{children:[e.jsx("b",{children:"poll"})," claims every run this server creates (Schedule tab, Run buttons) and executes it — one standing container per nest. No Anthropic key flag needed: set"," ",e.jsx("code",{children:"ANTHROPIC_API_KEY"})," in Activity → Tool environment and the runner picks it up from the run bundle. Steps stream back into the trace below — refresh to watch."]})]})]})]}),e.jsxs("div",{className:`grid gap-4 items-start ${d?"lg:grid-cols-[minmax(0,24rem)_minmax(0,1fr)]":"grid-cols-1"}`,children:[e.jsx("div",{className:"rounded-lg border divide-y min-w-0",children:E?e.jsx("div",{className:"px-3 py-6 text-center text-muted-foreground",children:e.jsx(J,{className:"h-4 w-4 animate-spin inline"})}):j.length===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:"No runs yet. Trigger an agent above."}):n.map(a=>Pe(a,0))}),d&&e.jsx("div",{className:"rounded-lg border p-4 min-w-0 lg:sticky lg:top-20",children:e.jsx(Os,{run:d,children:j.filter(a=>a.parent_run_id===d.id),parent:d.parent_run_id?j.find(a=>a.id===d.parent_run_id)??null:null,label:I,typeOf:ue,onOpen:a=>void re(a),onCancel:a=>void G(a),cancelling:le===d.id})})]})]})}function Os({run:s,children:m=[],parent:g=null,label:y=d=>d,typeOf:C=()=>{},onOpen:b,onCancel:j,cancelling:k=!1}){var d;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(We,{type:C(s.agent_node),className:"h-4 w-4"}),e.jsx("span",{className:"font-mono text-sm",children:s.id}),e.jsx(se,{variant:tt(Ae(s)),title:qe(s)?Mt:void 0,children:Ae(s)}),(s.depth??0)>0&&e.jsxs(se,{variant:"outline",className:"text-[10px]",children:["sub-agent · depth ",s.depth]}),s.status==="running"&&j&&e.jsxs(S,{variant:"outline",size:"sm",className:"ml-auto h-7",disabled:k,onClick:()=>j(s.id),title:"Cancel this run",children:[k?e.jsx(J,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):e.jsx(Rt,{className:"h-3.5 w-3.5 mr-1"}),"Cancel run"]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mb-4",children:["agent ",y(s.agent_node)," · started ",Ee(s.started_at),s.finished_at?` · finished ${Ee(s.finished_at)}`:""," · triggered by ",s.triggered_by]}),g&&e.jsxs("button",{type:"button",onClick:()=>b==null?void 0:b(g.id),className:"mb-3 inline-flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground",title:"Open the run that spawned this one",children:[e.jsx(vs,{className:"h-3 w-3"})," Spawned by ",y(g.agent_node)," ",e.jsxs("span",{className:"font-mono",children:["(",g.id.slice(0,8),")"]})]}),m.length>0&&e.jsxs("div",{className:"mb-4 rounded-md border bg-muted/20 p-2.5",children:[e.jsxs("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground mb-1.5",children:["Sub-agents spawned (",m.length,")"]}),e.jsx("div",{className:"space-y-1",children:m.map(h=>e.jsxs("button",{type:"button",onClick:()=>b==null?void 0:b(h.id),className:"flex w-full items-center gap-2 rounded px-1.5 py-1 text-left text-xs hover:bg-muted/50",children:[e.jsx(nt,{className:"h-3 w-3 text-muted-foreground/50 shrink-0"}),e.jsx(We,{type:C(h.agent_node),className:"h-3.5 w-3.5"}),e.jsx("span",{className:"truncate",children:y(h.agent_node)}),e.jsx(se,{variant:tt(Ae(h)),className:"text-[10px] shrink-0",children:Ae(h)}),e.jsx("span",{className:"ml-auto font-mono text-[10px] text-muted-foreground shrink-0",children:h.id.slice(0,8)})]},h.id))})]}),((d=s.trace)==null?void 0:d.error)&&e.jsx("div",{className:"mb-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive font-mono break-all",children:s.trace.error}),e.jsx("div",{className:"space-y-0",children:s.steps.length===0?e.jsx("div",{className:"text-xs text-muted-foreground",children:qe(s)?"No steps yet — queued, waiting for a runner to claim it. Start a runner (see “How do I run one?” above) or cancel the run.":"No steps recorded."}):s.steps.map(h=>e.jsxs("div",{className:"grid grid-cols-[24px_1fr] gap-3 py-2 border-b border-dashed last:border-0",children:[e.jsx("div",{className:"text-muted-foreground pt-0.5",children:Cs(h.action)}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs",children:[e.jsxs("span",{className:"text-muted-foreground",children:[Ee(h.at)," ·"," "]}),e.jsx("span",{className:"font-medium",children:h.action}),h.node_id&&e.jsxs("span",{className:"font-mono text-muted-foreground",children:[" ",h.node_id]})]}),h.detail&&e.jsx("div",{className:"text-[11px] text-muted-foreground font-mono mt-0.5 break-all",children:typeof h.detail=="string"?h.detail:JSON.stringify(h.detail)})]})]},h.seq))})]})}const _e=168,je=56,Ls=260,Ws=100,Se=30,Ze=70;function zs({nestId:s}){const[m,g]=r.useState([]),[y,C]=r.useState([]),[b,j]=r.useState([]),[k,d]=r.useState(!0),[h,E]=r.useState(null),[N,w]=r.useState(null),[x,O]=r.useState(null),[c,L]=r.useState(null),[T,B]=r.useState(""),[D,q]=r.useState(""),[Y,U]=r.useState(""),[i,$]=r.useState(""),[W,he]=r.useState(">"),[ne,de]=r.useState(""),[ye,pe]=r.useState(!1),[X,le]=r.useState(""),[be,Ne]=r.useState([]),[we,H]=r.useState(60),[ae,re]=r.useState(""),[G,Te]=r.useState(1),[Z,$e]=r.useState(""),[Q,I]=r.useState(null),[ue,ie]=r.useState(!1),[ke,n]=r.useState(""),[v,P]=r.useState([]),[z,R]=r.useState(""),[Fe,ge]=r.useState([]),[Pe,a]=r.useState("slack"),[p,F]=r.useState({}),[me,fe]=r.useState(null),[K,at]=r.useState(0);r.useEffect(()=>{if(!me)return;const t=new ResizeObserver(o=>{var f;const u=((f=o[0])==null?void 0:f.contentRect.width)??0;u&&at(u)});return t.observe(me),at(me.clientWidth),()=>t.disconnect()},[me]);const xe=r.useCallback(async()=>{d(!0);try{const[t,o,u,f]=await Promise.all([ft(s),vt(s),Ue(s).then(_=>_.nodes).catch(()=>[]),jt(s).catch(()=>[])]);g(t),C(o),j(u),Ne(f),E(null)}catch(t){E(t instanceof Error?t.message:"Failed to load canvas")}finally{d(!1)}},[s]);r.useEffect(()=>{if(!x)return;let t=!1;return qt(s,x).then(o=>!t&&P(o.map(u=>u.user_email))).catch(()=>!t&&P([])),Je(s,x).then(o=>!t&&ge(o)).catch(()=>!t&&ge([])),()=>{t=!0}},[s,x]);const De=(t,o)=>{ls(o).then(u=>{u&&($e(t),setTimeout(()=>$e(""),1500))})};r.useEffect(()=>{xe()},[xe]);const rt=new Map(b.map(t=>[t.id,t])),V=t=>{var o;return((o=rt.get(t))==null?void 0:o.title)||t.replace(/^nodes\//,"")},Re=t=>{var o;return(o=rt.get(t))==null?void 0:o.type},ot=m.filter(t=>t.type.is_flow),ee=new Map;{const t=new Set;for(const A of m)t.add(A.from_node),t.add(A.to_node);const o=new Map,u=new Set(ot.map(A=>A.to_node)),f=[...t].filter(A=>!u.has(A)).sort();for(const A of f)o.set(A,0);for(let A=0;A<t.size;A++){let l=!1;for(const M of ot){const ce=(o.get(M.from_node)??0)+1;ce>(o.get(M.to_node)??0)&&(o.set(M.to_node,ce),l=!0)}if(!l)break}const _=new Map;for(const A of[...t].sort((l,M)=>String(V(l)).localeCompare(V(M)))){const l=o.get(A)??0;_.has(l)||_.set(l,[]),_.get(l).push(A)}for(const[A,l]of _)l.forEach((M,ce)=>{ee.set(M,{id:M,x:Se+A*Ls,y:Ze+ce*Ws})})}const Ot=Se*2+(Math.max(0,...[...ee.values()].map(t=>t.x))+_e+60),lt=Math.max(300,Ze+(Math.max(-Ze+40,...[...ee.values()].map(t=>t.y))+je+40)),He=ke.trim().toLowerCase(),Me=b.map(t=>t.id).filter(t=>!ee.has(t)).filter(t=>!He||V(t).toLowerCase().includes(He)||t.toLowerCase().includes(He)).sort((t,o)=>{const u=f=>Re(f)==="agent"?0:Re(f)==="skill"?1:2;return u(t)-u(o)||V(t).localeCompare(V(o))}),Oe=lt+46,it=Math.max(Ot,K>0?Math.floor(K):920),Xe=Math.max(1,Math.floor((it-Se*2)/(_e+46)));Me.forEach((t,o)=>{ee.set(t,{id:t,x:Se+o%Xe*(_e+46),y:Oe+Math.floor(o/Xe)*(je+28)})});const ct=it,Lt=Me.length?Oe+Math.ceil(Me.length/Xe)*(je+28)+30:lt+20,ve=(t,o)=>{const u=ee.get(t);return u?{x:o==="out"?u.x+_e:u.x,y:u.y+je/2}:{x:0,y:0}},Wt=(t,o,u=0)=>{const f=ve(t,"out"),_=ve(o,"in"),A=Math.max(40,(_.x-f.x)/2),l=u*4/3;return`M${f.x},${f.y} C${f.x+A},${f.y+l} ${_.x-A},${_.y+l} ${_.x},${_.y}`},Ge=new Map;{const t=new Map;for(const o of m){const u=`${o.from_node}\0${o.to_node}`,f=t.get(u)??[];f.push(o),t.set(u,f)}for(const o of t.values())o.length<2||o.forEach((u,f)=>Ge.set(u.id,(f-(o.length-1)/2)*34))}const dt=t=>t.type.color||(t.type.is_flow?"#34a853":"#94a3b8"),zt=m.filter(t=>ee.has(t.from_node)&&ee.has(t.to_node)).map(t=>{let o="";if(t.condition_mode==="nl"&&t.condition)o=`“${t.condition}”`;else if(t.condition_mode==="structured"&&t.condition)try{const _=typeof t.condition=="string"?JSON.parse(t.condition):t.condition;o=_!=null&&_.term?`${_.term} ${_.op??""} ${_.value??""}`:""}catch{}const u=ve(t.from_node,"out"),f=ve(t.to_node,"in");return{edge:t,x:(u.x+f.x)/2,y:(u.y+f.y)/2+(Ge.get(t.id)??0)-je/2-6,...ks(t.type.name,o)}}),Ke=t=>{if(O(null),I(null),w(t.id),B(t.type.name),q(t.condition_mode||""),t.condition_mode==="nl")U(String(t.condition??""));else if(t.condition_mode==="structured"&&t.condition)try{const o=typeof t.condition=="string"?JSON.parse(t.condition):t.condition;$(String(o.term??"")),he(String(o.op??">")),de(String(o.value??""))}catch{$(""),de("")}},Ft=async()=>{if(!N)return;const t=m.find(u=>u.id===N),o=t&&m.find(u=>u.id!==N&&u.from_node===t.from_node&&u.to_node===t.to_node&&u.type.name===T);if(o){E(`${V(o.from_node)} → ${V(o.to_node)} is already connected with "${T}".`);return}pe(!0);try{await os(s,N,{type:T,condition_mode:D||null,condition:D==="nl"?Y.trim():D==="structured"?{term:i.trim(),op:W,value:isNaN(Number(ne))?ne.trim():Number(ne)}:null}),await xe()}catch(u){E(u instanceof Error?u.message:"Failed to save edge")}finally{pe(!1)}},Dt=async t=>{try{await _t(s,t),w(null),await xe()}catch(o){E(o instanceof Error?o.message:"Failed to delete edge")}},ut=async(t,o)=>{var _,A;if(t===o)return;const u=((_=y.find(l=>l.is_flow))==null?void 0:_.name)??((A=y[0])==null?void 0:A.name);if(!u)return;const f=m.find(l=>l.from_node===t&&l.to_node===o&&l.type.name===u);if(f){E(`${V(t)} → ${V(o)} is already connected with "${u}".`),Ke(f);return}try{const l=await kt(s,{from_node:t,to_node:o,type:u,condition_mode:null,condition:null});await xe(),Ke(l)}catch(l){E(l instanceof Error?l.message:"Failed to connect")}},Ht=t=>{const o=t.currentTarget.closest("svg").getBoundingClientRect();return{x:t.clientX-o.left,y:t.clientY-o.top}},Le=m.find(t=>t.id===N)??null,Kt=[...new Set(m.map(dt))];return e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[minmax(0,1fr)_300px] gap-4",children:[e.jsxs("div",{className:"rounded-lg border overflow-hidden bg-background",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b text-xs text-muted-foreground",children:[e.jsxs("span",{className:"hidden md:inline",children:["Drag from a card's ",e.jsx("b",{children:"right port"})," onto another card to connect. Click a wire or card to edit it."]}),e.jsx("div",{className:"flex-1"}),e.jsx(te,{value:ke,onChange:t=>n(t.target.value),placeholder:"Find a document to wire in…",className:"h-7 w-56 text-xs","data-testid":"canvas-shelf-search"}),e.jsx(S,{variant:"outline",size:"sm",className:"h-7",onClick:()=>void xe(),children:e.jsx(st,{className:"h-3.5 w-3.5"})})]}),h&&e.jsx("div",{className:"mx-3 mt-2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-line",children:h}),k?e.jsx("div",{className:"py-16 text-center text-muted-foreground",children:e.jsx(J,{className:"h-4 w-4 animate-spin inline"})}):ee.size===0?e.jsx("div",{className:"py-16 text-center text-sm text-muted-foreground",children:"No documents in this nest yet — create one from the Documents tab and it appears here, ready to wire up."}):e.jsx("div",{className:"overflow-auto max-h-[70vh]",ref:fe,children:e.jsxs("svg",{width:ct,height:Lt,ref:t=>{},style:{background:"radial-gradient(circle, hsl(var(--muted-foreground) / 0.18) 1px, transparent 1px)",backgroundSize:"20px 20px"},onMouseMove:t=>{if(!c)return;const o=t.currentTarget.getBoundingClientRect();L({...c,x:t.clientX-o.left,y:t.clientY-o.top})},onMouseUp:()=>L(null),onClick:()=>{w(null),O(null)},children:[e.jsx("defs",{children:Kt.map(t=>e.jsx("marker",{id:`ah-${t.replace(/[^a-z0-9]/gi,"")}`,markerWidth:"9",markerHeight:"9",refX:"7",refY:"3",orient:"auto",children:e.jsx("path",{d:"M0,0 L7,3 L0,6 z",fill:t})},t))}),m.map(t=>{if(!ee.has(t.from_node)||!ee.has(t.to_node))return null;const o=Ge.get(t.id)??0,u=Wt(t.from_node,t.to_node,o),f=dt(t);return e.jsxs("g",{children:[e.jsx("path",{d:u,fill:"none",stroke:f,strokeWidth:N===t.id?3:2,strokeDasharray:t.type.is_flow?void 0:"4 4",markerEnd:`url(#ah-${f.replace(/[^a-z0-9]/gi,"")})`,opacity:N&&N!==t.id?.45:1}),e.jsx("path",{d:u,fill:"none",stroke:"transparent",strokeWidth:14,style:{cursor:"pointer"},onClick:_=>{_.stopPropagation(),Ke(t)}})]},t.id)}),c&&e.jsx("path",{d:`M${ve(c.from,"out").x},${ve(c.from,"out").y} C${ve(c.from,"out").x+60},${ve(c.from,"out").y} ${c.x-60},${c.y} ${c.x},${c.y}`,fill:"none",stroke:"hsl(var(--primary))",strokeWidth:2,strokeDasharray:"5 4"}),Me.length>0&&e.jsxs("g",{children:[e.jsx("line",{x1:Se,y1:Oe-26,x2:ct-Se,y2:Oe-26,stroke:"hsl(var(--border))",strokeDasharray:"3 3"}),e.jsxs("text",{x:Se,y:Oe-32,style:{font:"10px sans-serif",fill:"hsl(var(--muted-foreground))"},children:["NOT WIRED IN YET (",Me.length,He?" matching":"",") — drag a right port onto any card to connect"]})]}),[...ee.values()].map(t=>{const o=Re(t.id),u=x===t.id;return e.jsxs("g",{children:[e.jsx("foreignObject",{x:t.x,y:t.y,width:_e,height:je+6,children:e.jsxs("div",{className:`rounded-lg border-2 bg-background px-2.5 py-1.5 shadow-sm cursor-pointer select-none ${u?"border-primary ring-2 ring-primary/20":"border-border"}`,style:{width:_e,height:je},onClick:f=>{f.stopPropagation(),w(null),I(null),O(t.id)},onMouseUp:()=>{c&&c.from!==t.id&&(ut(c.from,t.id),L(null))},title:t.id,children:[e.jsxs("div",{className:"flex items-center gap-1 text-[10px] uppercase tracking-wide text-muted-foreground",children:[e.jsx(Ce,{type:o}),o??"document"]}),e.jsx("div",{className:"text-xs font-semibold truncate mt-0.5",children:V(t.id)})]})}),e.jsx("circle",{cx:t.x+_e,cy:t.y+je/2,r:6,fill:"hsl(var(--background))",stroke:"hsl(var(--primary))",strokeWidth:1.5,style:{cursor:"crosshair"},onMouseDown:f=>{f.stopPropagation(),f.preventDefault();const _=Ht(f);L({from:t.id,x:_.x,y:_.y})}})]},t.id)}),zt.map(t=>e.jsxs("g",{style:{cursor:"pointer"},onClick:o=>{o.stopPropagation(),Ke(t.edge)},children:[e.jsx("title",{children:t.full}),e.jsx("rect",{x:t.x-t.width/2,y:t.y-9,width:t.width,height:13,rx:3,fill:"hsl(var(--background))",opacity:.92}),e.jsx("text",{x:t.x,y:t.y,textAnchor:"middle",style:{font:"10px ui-monospace, monospace",fill:"hsl(var(--muted-foreground))"},children:t.short})]},`label-${t.edge.id}`))]})})]}),e.jsx("div",{className:"rounded-lg border p-4 h-fit",children:Le?e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold",children:["Edge · ",Le.type.name]}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-3",children:[V(Le.from_node)," → ",V(Le.to_node)]}),e.jsx("label",{className:"block text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"Type"}),e.jsx("select",{value:T,onChange:t=>B(t.target.value),className:"w-full h-8 rounded-md border bg-background px-2 text-sm mb-3",children:y.map(t=>e.jsxs("option",{value:t.name,children:[t.is_flow?"▶ ":"",t.name]},t.id))}),e.jsx("label",{className:"block text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"Fires"}),e.jsx("div",{className:"flex items-center rounded-md border h-8 text-xs overflow-hidden w-fit mb-2",children:[["","always"],["nl","if…"],["structured","metric"]].map(([t,o],u)=>e.jsx("button",{type:"button",className:`px-2.5 h-full ${u>0?"border-l":""} ${D===t?"bg-primary text-primary-foreground":"hover:bg-muted"}`,onClick:()=>q(t),children:o},t))}),D==="nl"&&e.jsx(te,{value:Y,onChange:t=>U(t.target.value),placeholder:'e.g. "lost on price, not product"',className:"h-8 text-sm italic mb-2"}),D==="structured"&&e.jsxs("div",{className:"grid grid-cols-[1fr_58px_1fr] gap-1.5 mb-2",children:[e.jsx(te,{value:i,onChange:t=>$(t.target.value),placeholder:"CAC",className:"h-8 text-sm font-mono"}),e.jsx("select",{value:W,onChange:t=>he(t.target.value),className:"h-8 rounded-md border bg-background px-1 text-sm font-mono",children:[">","<",">=","<=","=","!="].map(t=>e.jsx("option",{value:t,children:t},t))}),e.jsx(te,{value:ne,onChange:t=>de(t.target.value),placeholder:"500",className:"h-8 text-sm font-mono"})]}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(S,{size:"sm",className:"flex-1",disabled:ye,onClick:()=>void Ft(),children:ye?e.jsx(J,{className:"h-3.5 w-3.5 animate-spin"}):"Save"}),e.jsx(S,{size:"sm",variant:"outline",className:"text-destructive",onClick:()=>void Dt(Le.id),children:"Delete"})]})]}):x?(()=>{const t=["agent","skill"].includes(Re(x)??""),o=be.find(l=>l.agent_node===x),u=window.location.origin,f=`[[${V(x)}]]`,_=`curl -s -X POST ${u}/nests/${s}/context -H 'Content-Type: application/json' -d '{"selector":"${f}","hops":${G},"max_tokens":4000}'`,A=`curl -s -X PATCH ${u}/nests/${s}/nodes/${x} -H 'Content-Type: application/json' -d '{"append":"<your update>","changeNote":"via ctx"}'`;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{type:Re(x)}),e.jsx("h3",{className:"text-sm font-semibold truncate",children:V(x)})]}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono truncate",children:x})]}),t&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(S,{size:"sm",className:"w-full",onClick:async()=>{try{await Qe(s,x),re("Run created — a polling runner will pick it up"),setTimeout(()=>re(""),3e3)}catch(l){E(l instanceof Error?l.message:"Trigger failed")}},children:[e.jsx(At,{className:"h-3.5 w-3.5 mr-1.5"})," Run now"]}),ae&&e.jsx("p",{className:"text-[11px] text-emerald-600",children:ae}),e.jsx("label",{className:"block text-[10px] uppercase tracking-wide text-muted-foreground",children:"Schedule"}),o?e.jsxs("div",{className:"rounded-md border px-2.5 py-2 text-xs space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{children:["every"," ",e.jsx("b",{children:o.every_minutes>=60?`${o.every_minutes/60}h`:`${o.every_minutes}m`}),o.enabled?"":" · paused"]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{type:"button",className:"text-primary hover:underline",onClick:async()=>{await Ie(s,o.id,{enabled:!o.enabled}),await xe()},children:o.enabled?"Pause":"Resume"}),e.jsx("button",{type:"button",className:"text-destructive hover:underline",onClick:async()=>{await yt(s,o.id),await xe()},children:"Remove"})]}),o.enabled&&o.next_due_at&&e.jsxs("div",{className:"text-muted-foreground",children:["next fire ~",Ee(o.next_due_at)]})]}):e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("select",{value:we,onChange:l=>H(Number(l.target.value)),className:"h-8 rounded-md border bg-background px-2 text-sm flex-1",children:[e.jsx("option",{value:15,children:"every 15 minutes"}),e.jsx("option",{value:60,children:"every hour"}),e.jsx("option",{value:360,children:"every 6 hours"}),e.jsx("option",{value:1440,children:"every day"})]}),e.jsx(S,{size:"sm",className:"h-8",onClick:async()=>{try{await bt(s,{agent_node:x,every_minutes:we}),await xe()}catch(l){E(l instanceof Error?l.message:"Schedule failed")}},children:"Schedule"})]})]}),t&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-[10px] uppercase tracking-wide text-muted-foreground",children:"Triggers — call this agent from outside"}),Fe.map(l=>e.jsxs("div",{className:"rounded-md border px-2 py-1.5 text-[11px] space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(se,{variant:"secondary",className:"text-[10px]",children:l.preset}),e.jsxs("span",{className:"text-muted-foreground",children:["fired ",l.fire_count,"×"]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{type:"button",className:"text-destructive hover:underline",onClick:async()=>{await Ut(s,l.id),ge(await Je(s,x))},children:"Remove"})]}),l.url??p[l.id]?e.jsx("button",{type:"button",className:"w-full text-left font-mono break-all rounded bg-muted/40 px-1.5 py-1 hover:border-primary border border-transparent",title:"Copy the trigger URL — paste into a Slack slash command / Events API, Teams outgoing webhook, or any system that can POST",onClick:()=>De(`hook-${l.id}`,l.url??p[l.id]),children:Z===`hook-${l.id}`?"✓ copied":l.url??p[l.id]}):e.jsx("p",{className:"text-muted-foreground px-1.5",children:"URL was shown at creation only (like an API key). Remove + re-add to mint a fresh one."})]},l.id)),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("select",{value:Pe,onChange:l=>a(l.target.value),className:"h-7 rounded-md border bg-background px-1.5 text-xs flex-1",children:[e.jsx("option",{value:"slack",children:"Slack (slash command / @mention)"}),e.jsx("option",{value:"teams",children:"Teams (outgoing webhook)"}),e.jsx("option",{value:"webhook",children:"Webhook (any system)"})]}),e.jsx(S,{size:"sm",variant:"outline",className:"h-7 px-2",onClick:async()=>{const l=await Xt(s,x,Pe);if(l.url){const M=`${l.id.slice(0,7)}…${l.id.slice(-4)}`;F(ce=>({...ce,[M]:l.url}))}ge(await Je(s,x))},children:e.jsx(oe,{className:"h-3.5 w-3.5"})})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Each trigger is a secret URL that queues a run — message text becomes the run's inputs. Add SLACK_SIGNING_SECRET to the Tool environment to verify Slack requests."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-[10px] uppercase tracking-wide text-muted-foreground",children:"Notify on output"}),v.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:v.map(l=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-muted px-2 py-0.5 text-[11px]",children:[l,e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-destructive",title:"Stop notifying",onClick:async()=>{const M=await Gt(s,x,l);P(M.map(ce=>ce.user_email))},children:"✕"})]},l))}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(te,{value:z,onChange:l=>R(l.target.value),placeholder:"person@team.com",className:"h-7 text-xs flex-1",onKeyDown:async l=>{if(l.key==="Enter"&&z.includes("@")){const M=await mt(s,x,z.trim());P(M.map(ce=>ce.user_email)),R("")}}}),e.jsx(S,{size:"sm",variant:"outline",className:"h-7 px-2",disabled:!z.includes("@"),onClick:async()=>{const l=await mt(s,x,z.trim());P(l.map(M=>M.user_email)),R("")},children:e.jsx(oe,{className:"h-3.5 w-3.5"})})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Tagged people get an inbox notification when this node's output lands for review. (Slack/webhook delivery comes later — same table.)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"Add a step after this"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("select",{value:X,onChange:l=>le(l.target.value),className:"h-8 rounded-md border bg-background px-2 text-sm flex-1 min-w-0",children:[e.jsx("option",{value:"",children:"Choose a document…"}),b.filter(l=>l.id!==x).map(l=>e.jsx("option",{value:l.id,children:l.title||l.id},l.id))]}),e.jsx(S,{size:"sm",className:"h-8",disabled:!X,onClick:()=>{ut(x,X),le("")},children:e.jsx(oe,{className:"h-3.5 w-3.5"})})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1.5",children:"Or drag from the node's right port straight onto another card."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Use from CLI / agent"}),e.jsx("div",{className:"flex-1"}),e.jsx("select",{value:G,onChange:l=>Te(Number(l.target.value)),className:"h-6 rounded border bg-background px-1 text-[11px]",title:"How many hops of linked context to pull with it",children:[0,1,2,3].map(l=>e.jsxs("option",{value:l,children:[l," hop",l===1?"":"s"]},l))})]}),e.jsx("button",{type:"button",className:"w-full text-left rounded-md border bg-muted/40 px-2 py-1.5 text-[10.5px] font-mono break-all hover:border-primary",onClick:()=>De("sel",f),title:"Copy the selector",children:Z==="sel"?"✓ copied":f}),e.jsx("button",{type:"button",className:"w-full text-left rounded-md border bg-muted/40 px-2 py-1.5 text-[10.5px] font-mono break-all hover:border-primary",onClick:()=>De("read",_),title:"Copy — deterministic read: this node + linked context",children:Z==="read"?"✓ copied":`read → ${_.slice(0,64)}…`}),e.jsx("button",{type:"button",className:"w-full text-left rounded-md border bg-muted/40 px-2 py-1.5 text-[10.5px] font-mono break-all hover:border-primary",onClick:()=>De("write",A),title:"Copy — governed write: append to this node (lands as a new version / review request)",children:Z==="write"?"✓ copied":`write → ${A.slice(0,64)}…`}),e.jsx(S,{variant:"outline",size:"sm",className:"w-full h-7 text-xs",disabled:ue,onClick:async()=>{var l;ie(!0);try{const M=await Jt(s,f,G);I({text:M.context||"(empty context)",nodes:((l=M.trace)==null?void 0:l.nodes_traversed)??M.nodes_traversed??0})}catch(M){E(M instanceof Error?M.message:"Preview failed")}finally{ie(!1)}},children:ue?e.jsx(J,{className:"h-3.5 w-3.5 animate-spin"}):e.jsxs(e.Fragment,{children:["Test: preview what it reads (",G," hop",G===1?"":"s",")"]})}),Q&&e.jsxs("div",{className:"rounded-md border bg-muted/30 p-2",children:[e.jsxs("div",{className:"flex items-center text-[10px] text-muted-foreground mb-1",children:[e.jsxs("span",{children:[Q.nodes," node",Q.nodes===1?"":"s"," assembled — exactly what a run reads"]}),e.jsx("button",{type:"button",className:"ml-auto hover:text-foreground",onClick:()=>I(null),children:"✕"})]}),e.jsxs("pre",{className:"max-h-56 overflow-auto whitespace-pre-wrap text-[10.5px] leading-relaxed",children:[Q.text.slice(0,4e3),Q.text.length>4e3?`
16
- …(truncated)`:""]})]})]})]})})():e.jsxs("div",{className:"text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium text-foreground mb-1",children:"Nothing selected"}),e.jsxs("p",{className:"text-xs",children:["Click a ",e.jsx("b",{children:"wire"})," to change its type or condition, click a"," ",e.jsx("b",{children:"card"})," to add a next step, or drag from a card's right port onto another card to connect them."]})]})})]})}function Fs({nestId:s}){const[m,g]=r.useState([]),[y,C]=r.useState([]),[b,j]=r.useState(!0),[k,d]=r.useState(null),[h,E]=r.useState(""),[N,w]=r.useState(60),[x,O]=r.useState(""),[c,L]=r.useState(!1),T=r.useCallback(async()=>{j(!0);try{const[i,$]=await Promise.all([jt(s),Ue(s).then(W=>W.nodes).catch(()=>[])]);g(i),C($),d(null)}catch(i){d(i instanceof Error?i.message:"Failed to load schedules")}finally{j(!1)}},[s]);r.useEffect(()=>{T()},[T]);const B=i=>{var $;return(($=y.find(W=>W.id===i))==null?void 0:$.title)||i.replace(/^nodes\//,"")},D=i=>{var $;return($=y.find(W=>W.id===i))==null?void 0:$.type},q=y.filter(i=>i.type==="agent"||i.type==="skill"),Y=q.filter(i=>!m.some($=>$.agent_node===i.id)),U=i=>i>=1440?`${i/1440}d`:i>=60?`${i/60}h`:`${i}m`;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["A schedule decides ",e.jsx("b",{children:"when a run starts"})," and its stop-after bound decides ",e.jsx("b",{children:"when it's done"}),". What happens ",e.jsx("em",{children:"inside"})," a run — which step fires, on what condition — lives on the wires in the Canvas (click a wire to set always / if… / metric). Scheduled output still lands as a review request; scheduling doesn't skip governance."]}),k&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:k}),b?e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:e.jsx(J,{className:"h-4 w-4 animate-spin inline"})}):m.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed p-6 text-center",children:[e.jsx(Ns,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),e.jsx("p",{className:"text-sm font-medium mb-1",children:"Nothing on the clock yet"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:q.length?"Pick an agent below — every interval, the server files a run for it.":"This nest has no runnable agents yet. Create one from Documents → New → type Agent (its body is the instructions), then schedule it here."})]}):e.jsx("div",{className:"rounded-lg border divide-y",children:m.map(i=>e.jsxs("div",{className:"px-3 py-2.5 flex items-center gap-2 text-sm",children:[e.jsx(Ce,{type:D(i.agent_node)}),e.jsx("span",{className:"truncate font-medium",title:i.agent_node,children:B(i.agent_node)}),e.jsxs(se,{variant:"secondary",className:"text-[10px] shrink-0",children:["every ",U(i.every_minutes)]}),i.max_runs!==null&&e.jsxs(se,{variant:"outline",className:"text-[10px] shrink-0",title:"Stops automatically after this many runs",children:[i.runs_created,"/",i.max_runs," runs"]}),i.enabled?i.next_due_at&&e.jsxs("span",{className:"text-[11px] text-muted-foreground shrink-0",children:["next ~",Ee(i.next_due_at)]}):i.max_runs!==null&&i.runs_created>=i.max_runs?e.jsx(se,{className:"text-[10px] shrink-0 bg-emerald-600",children:"done"}):e.jsx(se,{variant:"outline",className:"text-[10px] shrink-0",children:"paused"}),e.jsx("div",{className:"flex-1"}),e.jsxs("select",{value:i.every_minutes,onChange:async $=>{await Ie(s,i.id,{every_minutes:Number($.target.value)}),await T()},className:"h-7 rounded-md border bg-background px-1.5 text-xs shrink-0",title:"Change the interval",children:[[15,60,360,1440].map($=>e.jsx("option",{value:$,children:U($)},$)),![15,60,360,1440].includes(i.every_minutes)&&e.jsx("option",{value:i.every_minutes,children:U(i.every_minutes)})]}),e.jsx(S,{variant:"outline",size:"sm",className:"h-7 text-xs shrink-0",onClick:async()=>{await Ie(s,i.id,{enabled:!i.enabled}),await T()},children:i.enabled?"Pause":"Resume"}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive shrink-0",onClick:async()=>{await yt(s,i.id),await T()},title:"Remove schedule",children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]},i.id))}),e.jsxs("div",{className:"rounded-lg border bg-muted/20 p-3",children:[e.jsx("div",{className:"text-xs font-medium mb-2",children:"Put an agent on the clock"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("select",{value:h,onChange:i=>E(i.target.value),className:"h-8 rounded-md border bg-background px-2 text-sm flex-1 min-w-0","data-testid":"schedule-agent-lookup",children:[e.jsx("option",{value:"",children:Y.length?"Choose an agent…":"Every runnable agent is scheduled"}),Y.map(i=>e.jsxs("option",{value:i.id,children:[i.type==="agent"?"🤖 ":"⚡ ",i.title||i.id]},i.id))]}),e.jsxs("select",{value:N,onChange:i=>w(Number(i.target.value)),className:"h-8 rounded-md border bg-background px-2 text-sm",children:[e.jsx("option",{value:15,children:"every 15 minutes"}),e.jsx("option",{value:60,children:"every hour"}),e.jsx("option",{value:360,children:"every 6 hours"}),e.jsx("option",{value:1440,children:"every day"})]}),e.jsxs("select",{value:x,onChange:i=>O(i.target.value===""?"":Number(i.target.value)),className:"h-8 rounded-md border bg-background px-2 text-sm",title:"The stop condition: pause automatically after this many runs",children:[e.jsx("option",{value:"",children:"until stopped"}),e.jsx("option",{value:1,children:"once"}),e.jsx("option",{value:5,children:"stop after 5"}),e.jsx("option",{value:10,children:"stop after 10"}),e.jsx("option",{value:25,children:"stop after 25"})]}),e.jsxs(S,{size:"sm",className:"h-8",disabled:c||!h,onClick:async()=>{L(!0);try{await bt(s,{agent_node:h,every_minutes:N,max_runs:x===""?null:x}),E(""),await T()}catch(i){d(i instanceof Error?i.message:"Schedule failed")}finally{L(!1)}},children:[e.jsx(oe,{className:"h-3.5 w-3.5 mr-1"})," Schedule"]})]})]})]})}function Ds({nestId:s}){const[m,g]=r.useState([]),[y,C]=r.useState(null),[b,j]=r.useState(""),[k,d]=r.useState(""),[h,E]=r.useState(!1),N=r.useCallback(async()=>{try{g(await Nt(s)),C(null)}catch(w){C(w instanceof Error?w.message:"Failed to load env")}},[s]);return r.useEffect(()=>{N()},[N]),e.jsxs("details",{className:"rounded-lg border px-4 py-3",children:[e.jsxs("summary",{className:"cursor-pointer select-none text-sm font-medium flex items-center gap-2",children:[e.jsx(St,{className:"h-4 w-4 text-teal-500 inline"})," Tool environment (",m.length," key",m.length===1?"":"s",")"]}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Credentials for ",e.jsx("b",{children:"tool"})," nodes. Values are write-only here and travel to the runner inside the run bundle. Stored alongside nest content, not encrypted — treat this box like the nest itself."]}),y&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:y}),m.length>0&&e.jsx("div",{className:"rounded-md border divide-y",children:m.map(w=>e.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"font-mono font-medium",children:w.key}),e.jsx("span",{className:"font-mono text-muted-foreground",children:w.value_masked}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-muted-foreground",children:w.updated_by}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-destructive",title:"Delete key",onClick:async()=>{await ns(s,w.key),await N()},children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]},w.key))}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(te,{value:b,onChange:w=>j(w.target.value.toUpperCase()),placeholder:"SLACK_TOKEN",className:"h-8 text-xs font-mono w-44"}),e.jsx(te,{value:k,onChange:w=>d(w.target.value),placeholder:"value (write-only)",type:"password",className:"h-8 text-xs font-mono flex-1"}),e.jsx(S,{size:"sm",className:"h-8",disabled:h||!/^[A-Z][A-Z0-9_]*$/.test(b)||!k,onClick:async()=>{E(!0);try{await wt(s,b,k),j(""),d(""),await N()}catch(w){C(w instanceof Error?w.message:"Save failed")}finally{E(!1)}},children:h?e.jsx(J,{className:"h-3.5 w-3.5 animate-spin"}):"Set"})]})]})]})}function Hs({nestId:s}){const[m,g]=r.useState(null),[y,C]=r.useState(""),[b,j]=r.useState(!1),[k,d]=r.useState(null),[h,E]=r.useState(!1);return r.useEffect(()=>{let N=!1;return Promise.all([Nt(s).catch(()=>null),Qt().catch(()=>null)]).then(([w,x])=>{if(!N){if(x!=null&&x.runner_key_configured)return g(!0);if(!w)return g(null);g(w.some(O=>O.key==="ANTHROPIC_API_KEY"))}}),()=>{N=!0}},[s]),m!==!1?h?e.jsx("div",{className:"rounded-lg border border-emerald-400/50 bg-emerald-500/5 px-4 py-3 text-sm",children:"✓ Key stored (masked from here on). Runners pick it up from the run bundle — start one in poll mode and your queued runs execute."}):null:e.jsxs("div",{className:"rounded-lg border border-amber-400/60 bg-amber-500/5 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-medium mb-1",children:"🔑 Add your Anthropic API key to execute runs"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Runs are created here, but a runner needs a key to call the model. Paste it once — it's stored write-only for this nest (masked everywhere, delivered to runners inside the run bundle). Get one at console.anthropic.com → Settings → API keys."}),k&&e.jsx("p",{className:"text-xs text-destructive mb-2",children:k}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{type:"password",value:y,onChange:N=>C(N.target.value),placeholder:"sk-ant-…",className:"h-8 text-sm font-mono flex-1","data-testid":"runner-key-input"}),e.jsx(S,{size:"sm",className:"h-8",disabled:b||!y.trim().startsWith("sk-"),onClick:async()=>{j(!0);try{await wt(s,"ANTHROPIC_API_KEY",y.trim()),C(""),g(!0),E(!0)}catch(N){d(N instanceof Error?N.message:"Save failed")}finally{j(!1)}},children:b?e.jsx(J,{className:"h-3.5 w-3.5 animate-spin"}):"Save key"})]})]})}const Ks=[["review_requested","review requested"],["review_approved","approved"],["review_rejected","rejected"],["run_failed","run failed"],["mention","mentioned"]];function Vs({nestId:s}){const[m,g]=r.useState([]),[y,C]=r.useState(null),[b,j]=r.useState("slack"),[k,d]=r.useState(""),[h,E]=r.useState(["*"]),[N,w]=r.useState(!1),x=r.useCallback(async()=>{try{g(await It(s)),C(null)}catch(c){C(c instanceof Error?c.message:"Failed to load connectors")}},[s]);r.useEffect(()=>{x()},[x]);const O=c=>{E(L=>{if(c==="*")return["*"];const T=L.filter(B=>B!=="*"&&B!==c);return L.includes(c)?T.length?T:["*"]:[...T,c]})};return e.jsxs("details",{className:"rounded-lg border px-4 py-3",open:m.length>0,children:[e.jsxs("summary",{className:"cursor-pointer select-none text-sm font-medium",children:["📤 Connectors (",m.length,") — send events to Slack / Teams / webhooks"]}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Governance + run events post to each matching channel. Fire-and-forget — a channel outage never blocks a review. The server-wide Slack webhook (super-admin Settings) always fires too."}),y&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:y}),m.length>0&&e.jsx("div",{className:"rounded-md border divide-y",children:m.map(c=>e.jsxs("div",{className:"px-3 py-2 flex items-center gap-2 text-xs",children:[e.jsx(se,{variant:"secondary",className:"text-[10px] shrink-0",children:c.channel}),e.jsx("span",{className:"font-mono truncate",children:c.url}),e.jsx("span",{className:"text-muted-foreground shrink-0",children:c.events.includes("*")?"all events":c.events.join(", ")}),e.jsx("div",{className:"flex-1"}),e.jsx(S,{variant:"outline",size:"sm",className:"h-6 text-[11px] px-2 shrink-0",onClick:async()=>{await es(s,c.id,{enabled:!c.enabled}),await x()},children:c.enabled?"Pause":"Resume"}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-destructive shrink-0",onClick:async()=>{await ts(s,c.id),await x()},title:"Delete connector",children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]},c.id))}),e.jsxs("div",{className:"space-y-2 rounded-md border bg-muted/20 p-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("select",{value:b,onChange:c=>j(c.target.value),className:"h-8 rounded-md border bg-background px-1.5 text-xs",children:[e.jsx("option",{value:"slack",children:"Slack"}),e.jsx("option",{value:"teams",children:"Teams"}),e.jsx("option",{value:"webhook",children:"Webhook (raw JSON)"})]}),e.jsx(te,{value:k,onChange:c=>d(c.target.value),placeholder:"https://hooks.slack.com/… or env:SLACK_WEBHOOK",className:"h-8 text-xs font-mono flex-1"}),e.jsx(S,{size:"sm",className:"h-8",disabled:N||!(k.startsWith("https://")||k.startsWith("env:")),onClick:async()=>{w(!0);try{await ss(s,{channel:b,url:k.trim(),events:h}),d(""),E(["*"]),await x()}catch(c){C(c instanceof Error?c.message:"Create failed")}finally{w(!1)}},children:e.jsx(oe,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex items-center flex-wrap gap-1 text-[11px]",children:[e.jsx("button",{type:"button",className:`rounded-full border px-2 py-0.5 ${h.includes("*")?"bg-primary text-primary-foreground border-primary":"hover:bg-muted"}`,onClick:()=>O("*"),children:"all events"}),Ks.map(([c,L])=>e.jsx("button",{type:"button",className:`rounded-full border px-2 py-0.5 ${h.includes(c)?"bg-primary text-primary-foreground border-primary":"hover:bg-muted"}`,onClick:()=>O(c),children:L},c))]})]})]})]})}function yn(){const s=ms();return e.jsx(Es,{nestId:s.nestId,nestName:s.nestName,onBack:s.leaveNest})}export{yn as default};
15
+ contextnest-runner:local poll`}),e.jsxs("p",{children:[e.jsx("b",{children:"poll"})," claims every run this server creates (Schedule tab, Run buttons) and executes it — one standing container per nest. No Anthropic key flag needed: set"," ",e.jsx("code",{children:"ANTHROPIC_API_KEY"})," in Activity → Tool environment and the runner picks it up from the run bundle. Steps stream back into the trace below — refresh to watch."]})]})]})]}),e.jsxs("div",{className:`grid gap-4 items-start ${d?"lg:grid-cols-[minmax(0,24rem)_minmax(0,1fr)]":"grid-cols-1"}`,children:[e.jsx("div",{className:"rounded-lg border divide-y min-w-0",children:E?e.jsx("div",{className:"px-3 py-6 text-center text-muted-foreground",children:e.jsx(J,{className:"h-4 w-4 animate-spin inline"})}):j.length===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:"No runs yet. Trigger an agent above."}):n.map(a=>Pe(a,0))}),d&&e.jsx("div",{className:"rounded-lg border p-4 min-w-0 lg:sticky lg:top-20",children:e.jsx(Ls,{run:d,children:j.filter(a=>a.parent_run_id===d.id),parent:d.parent_run_id?j.find(a=>a.id===d.parent_run_id)??null:null,label:I,typeOf:ue,onOpen:a=>void re(a),onCancel:a=>void G(a),cancelling:le===d.id})})]})]})}function Ls({run:s,children:m=[],parent:g=null,label:y=d=>d,typeOf:C=()=>{},onOpen:b,onCancel:j,cancelling:k=!1}){var d;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(We,{type:C(s.agent_node),className:"h-4 w-4"}),e.jsx("span",{className:"font-mono text-sm",children:s.id}),e.jsx(se,{variant:tt(Ae(s)),title:qe(s)?Mt:void 0,children:Ae(s)}),(s.depth??0)>0&&e.jsxs(se,{variant:"outline",className:"text-[10px]",children:["sub-agent · depth ",s.depth]}),s.status==="running"&&j&&e.jsxs(S,{variant:"outline",size:"sm",className:"ml-auto h-7",disabled:k,onClick:()=>j(s.id),title:"Cancel this run",children:[k?e.jsx(J,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):e.jsx(Rt,{className:"h-3.5 w-3.5 mr-1"}),"Cancel run"]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mb-4",children:["agent ",y(s.agent_node)," · started ",Ee(s.started_at),s.finished_at?` · finished ${Ee(s.finished_at)}`:""," · triggered by ",s.triggered_by]}),g&&e.jsxs("button",{type:"button",onClick:()=>b==null?void 0:b(g.id),className:"mb-3 inline-flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground",title:"Open the run that spawned this one",children:[e.jsx(js,{className:"h-3 w-3"})," Spawned by ",y(g.agent_node)," ",e.jsxs("span",{className:"font-mono",children:["(",g.id.slice(0,8),")"]})]}),m.length>0&&e.jsxs("div",{className:"mb-4 rounded-md border bg-muted/20 p-2.5",children:[e.jsxs("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground mb-1.5",children:["Sub-agents spawned (",m.length,")"]}),e.jsx("div",{className:"space-y-1",children:m.map(h=>e.jsxs("button",{type:"button",onClick:()=>b==null?void 0:b(h.id),className:"flex w-full items-center gap-2 rounded px-1.5 py-1 text-left text-xs hover:bg-muted/50",children:[e.jsx(nt,{className:"h-3 w-3 text-muted-foreground/50 shrink-0"}),e.jsx(We,{type:C(h.agent_node),className:"h-3.5 w-3.5"}),e.jsx("span",{className:"truncate",children:y(h.agent_node)}),e.jsx(se,{variant:tt(Ae(h)),className:"text-[10px] shrink-0",children:Ae(h)}),e.jsx("span",{className:"ml-auto font-mono text-[10px] text-muted-foreground shrink-0",children:h.id.slice(0,8)})]},h.id))})]}),((d=s.trace)==null?void 0:d.error)&&e.jsx("div",{className:"mb-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive font-mono break-all",children:s.trace.error}),e.jsx("div",{className:"space-y-0",children:s.steps.length===0?e.jsx("div",{className:"text-xs text-muted-foreground",children:qe(s)?"No steps yet — queued, waiting for a runner to claim it. Start a runner (see “How do I run one?” above) or cancel the run.":"No steps recorded."}):s.steps.map(h=>e.jsxs("div",{className:"grid grid-cols-[24px_1fr] gap-3 py-2 border-b border-dashed last:border-0",children:[e.jsx("div",{className:"text-muted-foreground pt-0.5",children:Es(h.action)}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs",children:[e.jsxs("span",{className:"text-muted-foreground",children:[Ee(h.at)," ·"," "]}),e.jsx("span",{className:"font-medium",children:h.action}),h.node_id&&e.jsxs("span",{className:"font-mono text-muted-foreground",children:[" ",h.node_id]})]}),h.detail&&e.jsx("div",{className:"text-[11px] text-muted-foreground font-mono mt-0.5 break-all",children:typeof h.detail=="string"?h.detail:JSON.stringify(h.detail)})]})]},h.seq))})]})}const _e=168,je=56,Ws=260,zs=100,Se=30,Ze=70;function Fs({nestId:s}){const[m,g]=r.useState([]),[y,C]=r.useState([]),[b,j]=r.useState([]),[k,d]=r.useState(!0),[h,E]=r.useState(null),[N,w]=r.useState(null),[x,O]=r.useState(null),[c,L]=r.useState(null),[T,B]=r.useState(""),[D,q]=r.useState(""),[Y,U]=r.useState(""),[i,$]=r.useState(""),[W,he]=r.useState(">"),[ne,de]=r.useState(""),[ye,pe]=r.useState(!1),[X,le]=r.useState(""),[be,Ne]=r.useState([]),[we,H]=r.useState(60),[ae,re]=r.useState(""),[G,Te]=r.useState(1),[Z,$e]=r.useState(""),[Q,I]=r.useState(null),[ue,ie]=r.useState(!1),[ke,n]=r.useState(""),[v,P]=r.useState([]),[z,R]=r.useState(""),[Fe,ge]=r.useState([]),[Pe,a]=r.useState("slack"),[p,F]=r.useState({}),[me,fe]=r.useState(null),[K,at]=r.useState(0);r.useEffect(()=>{if(!me)return;const t=new ResizeObserver(o=>{var f;const u=((f=o[0])==null?void 0:f.contentRect.width)??0;u&&at(u)});return t.observe(me),at(me.clientWidth),()=>t.disconnect()},[me]);const xe=r.useCallback(async()=>{d(!0);try{const[t,o,u,f]=await Promise.all([ft(s),vt(s),Ue(s).then(_=>_.nodes).catch(()=>[]),jt(s).catch(()=>[])]);g(t),C(o),j(u),Ne(f),E(null)}catch(t){E(t instanceof Error?t.message:"Failed to load canvas")}finally{d(!1)}},[s]);r.useEffect(()=>{if(!x)return;let t=!1;return qt(s,x).then(o=>!t&&P(o.map(u=>u.user_email))).catch(()=>!t&&P([])),Je(s,x).then(o=>!t&&ge(o)).catch(()=>!t&&ge([])),()=>{t=!0}},[s,x]);const De=(t,o)=>{ls(o).then(u=>{u&&($e(t),setTimeout(()=>$e(""),1500))})};r.useEffect(()=>{xe()},[xe]);const rt=new Map(b.map(t=>[t.id,t])),V=t=>{var o;return((o=rt.get(t))==null?void 0:o.title)||t.replace(/^nodes\//,"")},Re=t=>{var o;return(o=rt.get(t))==null?void 0:o.type},ot=m.filter(t=>t.type.is_flow),ee=new Map;{const t=new Set;for(const A of m)t.add(A.from_node),t.add(A.to_node);const o=new Map,u=new Set(ot.map(A=>A.to_node)),f=[...t].filter(A=>!u.has(A)).sort();for(const A of f)o.set(A,0);for(let A=0;A<t.size;A++){let l=!1;for(const M of ot){const ce=(o.get(M.from_node)??0)+1;ce>(o.get(M.to_node)??0)&&(o.set(M.to_node,ce),l=!0)}if(!l)break}const _=new Map;for(const A of[...t].sort((l,M)=>String(V(l)).localeCompare(V(M)))){const l=o.get(A)??0;_.has(l)||_.set(l,[]),_.get(l).push(A)}for(const[A,l]of _)l.forEach((M,ce)=>{ee.set(M,{id:M,x:Se+A*Ws,y:Ze+ce*zs})})}const Ot=Se*2+(Math.max(0,...[...ee.values()].map(t=>t.x))+_e+60),lt=Math.max(300,Ze+(Math.max(-Ze+40,...[...ee.values()].map(t=>t.y))+je+40)),He=ke.trim().toLowerCase(),Me=b.map(t=>t.id).filter(t=>!ee.has(t)).filter(t=>!He||V(t).toLowerCase().includes(He)||t.toLowerCase().includes(He)).sort((t,o)=>{const u=f=>Re(f)==="agent"?0:Re(f)==="skill"?1:2;return u(t)-u(o)||V(t).localeCompare(V(o))}),Oe=lt+46,it=Math.max(Ot,K>0?Math.floor(K):920),Xe=Math.max(1,Math.floor((it-Se*2)/(_e+46)));Me.forEach((t,o)=>{ee.set(t,{id:t,x:Se+o%Xe*(_e+46),y:Oe+Math.floor(o/Xe)*(je+28)})});const ct=it,Lt=Me.length?Oe+Math.ceil(Me.length/Xe)*(je+28)+30:lt+20,ve=(t,o)=>{const u=ee.get(t);return u?{x:o==="out"?u.x+_e:u.x,y:u.y+je/2}:{x:0,y:0}},Wt=(t,o,u=0)=>{const f=ve(t,"out"),_=ve(o,"in"),A=Math.max(40,(_.x-f.x)/2),l=u*4/3;return`M${f.x},${f.y} C${f.x+A},${f.y+l} ${_.x-A},${_.y+l} ${_.x},${_.y}`},Ge=new Map;{const t=new Map;for(const o of m){const u=`${o.from_node}\0${o.to_node}`,f=t.get(u)??[];f.push(o),t.set(u,f)}for(const o of t.values())o.length<2||o.forEach((u,f)=>Ge.set(u.id,(f-(o.length-1)/2)*34))}const dt=t=>t.type.color||(t.type.is_flow?"#34a853":"#94a3b8"),zt=m.filter(t=>ee.has(t.from_node)&&ee.has(t.to_node)).map(t=>{let o="";if(t.condition_mode==="nl"&&t.condition)o=`“${t.condition}”`;else if(t.condition_mode==="structured"&&t.condition)try{const _=typeof t.condition=="string"?JSON.parse(t.condition):t.condition;o=_!=null&&_.term?`${_.term} ${_.op??""} ${_.value??""}`:""}catch{}const u=ve(t.from_node,"out"),f=ve(t.to_node,"in");return{edge:t,x:(u.x+f.x)/2,y:(u.y+f.y)/2+(Ge.get(t.id)??0)-je/2-6,..._s(t.type.name,o)}}),Ke=t=>{if(O(null),I(null),w(t.id),B(t.type.name),q(t.condition_mode||""),t.condition_mode==="nl")U(String(t.condition??""));else if(t.condition_mode==="structured"&&t.condition)try{const o=typeof t.condition=="string"?JSON.parse(t.condition):t.condition;$(String(o.term??"")),he(String(o.op??">")),de(String(o.value??""))}catch{$(""),de("")}},Ft=async()=>{if(!N)return;const t=m.find(u=>u.id===N),o=t&&m.find(u=>u.id!==N&&u.from_node===t.from_node&&u.to_node===t.to_node&&u.type.name===T);if(o){E(`${V(o.from_node)} → ${V(o.to_node)} is already connected with "${T}".`);return}pe(!0);try{await os(s,N,{type:T,condition_mode:D||null,condition:D==="nl"?Y.trim():D==="structured"?{term:i.trim(),op:W,value:isNaN(Number(ne))?ne.trim():Number(ne)}:null}),await xe()}catch(u){E(u instanceof Error?u.message:"Failed to save edge")}finally{pe(!1)}},Dt=async t=>{try{await _t(s,t),w(null),await xe()}catch(o){E(o instanceof Error?o.message:"Failed to delete edge")}},ut=async(t,o)=>{var _,A;if(t===o)return;const u=((_=y.find(l=>l.is_flow))==null?void 0:_.name)??((A=y[0])==null?void 0:A.name);if(!u)return;const f=m.find(l=>l.from_node===t&&l.to_node===o&&l.type.name===u);if(f){E(`${V(t)} → ${V(o)} is already connected with "${u}".`),Ke(f);return}try{const l=await kt(s,{from_node:t,to_node:o,type:u,condition_mode:null,condition:null});await xe(),Ke(l)}catch(l){E(l instanceof Error?l.message:"Failed to connect")}},Ht=t=>{const o=t.currentTarget.closest("svg").getBoundingClientRect();return{x:t.clientX-o.left,y:t.clientY-o.top}},Le=m.find(t=>t.id===N)??null,Kt=[...new Set(m.map(dt))];return e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[minmax(0,1fr)_300px] gap-4",children:[e.jsxs("div",{className:"rounded-lg border overflow-hidden bg-background",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b text-xs text-muted-foreground",children:[e.jsxs("span",{className:"hidden md:inline",children:["Drag from a card's ",e.jsx("b",{children:"right port"})," onto another card to connect. Click a wire or card to edit it."]}),e.jsx("div",{className:"flex-1"}),e.jsx(te,{value:ke,onChange:t=>n(t.target.value),placeholder:"Find a document to wire in…",className:"h-7 w-56 text-xs","data-testid":"canvas-shelf-search"}),e.jsx(S,{variant:"outline",size:"sm",className:"h-7",onClick:()=>void xe(),children:e.jsx(st,{className:"h-3.5 w-3.5"})})]}),h&&e.jsx("div",{className:"mx-3 mt-2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-line",children:h}),k?e.jsx("div",{className:"py-16 text-center text-muted-foreground",children:e.jsx(J,{className:"h-4 w-4 animate-spin inline"})}):ee.size===0?e.jsx("div",{className:"py-16 text-center text-sm text-muted-foreground",children:"No documents in this nest yet — create one from the Documents tab and it appears here, ready to wire up."}):e.jsx("div",{className:"overflow-auto max-h-[70vh]",ref:fe,children:e.jsxs("svg",{width:ct,height:Lt,ref:t=>{},style:{background:"radial-gradient(circle, hsl(var(--muted-foreground) / 0.18) 1px, transparent 1px)",backgroundSize:"20px 20px"},onMouseMove:t=>{if(!c)return;const o=t.currentTarget.getBoundingClientRect();L({...c,x:t.clientX-o.left,y:t.clientY-o.top})},onMouseUp:()=>L(null),onClick:()=>{w(null),O(null)},children:[e.jsx("defs",{children:Kt.map(t=>e.jsx("marker",{id:`ah-${t.replace(/[^a-z0-9]/gi,"")}`,markerWidth:"9",markerHeight:"9",refX:"7",refY:"3",orient:"auto",children:e.jsx("path",{d:"M0,0 L7,3 L0,6 z",fill:t})},t))}),m.map(t=>{if(!ee.has(t.from_node)||!ee.has(t.to_node))return null;const o=Ge.get(t.id)??0,u=Wt(t.from_node,t.to_node,o),f=dt(t);return e.jsxs("g",{children:[e.jsx("path",{d:u,fill:"none",stroke:f,strokeWidth:N===t.id?3:2,strokeDasharray:t.type.is_flow?void 0:"4 4",markerEnd:`url(#ah-${f.replace(/[^a-z0-9]/gi,"")})`,opacity:N&&N!==t.id?.45:1}),e.jsx("path",{d:u,fill:"none",stroke:"transparent",strokeWidth:14,style:{cursor:"pointer"},onClick:_=>{_.stopPropagation(),Ke(t)}})]},t.id)}),c&&e.jsx("path",{d:`M${ve(c.from,"out").x},${ve(c.from,"out").y} C${ve(c.from,"out").x+60},${ve(c.from,"out").y} ${c.x-60},${c.y} ${c.x},${c.y}`,fill:"none",stroke:"hsl(var(--primary))",strokeWidth:2,strokeDasharray:"5 4"}),Me.length>0&&e.jsxs("g",{children:[e.jsx("line",{x1:Se,y1:Oe-26,x2:ct-Se,y2:Oe-26,stroke:"hsl(var(--border))",strokeDasharray:"3 3"}),e.jsxs("text",{x:Se,y:Oe-32,style:{font:"10px sans-serif",fill:"hsl(var(--muted-foreground))"},children:["NOT WIRED IN YET (",Me.length,He?" matching":"",") — drag a right port onto any card to connect"]})]}),[...ee.values()].map(t=>{const o=Re(t.id),u=x===t.id;return e.jsxs("g",{children:[e.jsx("foreignObject",{x:t.x,y:t.y,width:_e,height:je+6,children:e.jsxs("div",{className:`rounded-lg border-2 bg-background px-2.5 py-1.5 shadow-sm cursor-pointer select-none ${u?"border-primary ring-2 ring-primary/20":"border-border"}`,style:{width:_e,height:je},onClick:f=>{f.stopPropagation(),w(null),I(null),O(t.id)},onMouseUp:()=>{c&&c.from!==t.id&&(ut(c.from,t.id),L(null))},title:t.id,children:[e.jsxs("div",{className:"flex items-center gap-1 text-[10px] uppercase tracking-wide text-muted-foreground",children:[e.jsx(Ce,{type:o}),o??"document"]}),e.jsx("div",{className:"text-xs font-semibold truncate mt-0.5",children:V(t.id)})]})}),e.jsx("circle",{cx:t.x+_e,cy:t.y+je/2,r:6,fill:"hsl(var(--background))",stroke:"hsl(var(--primary))",strokeWidth:1.5,style:{cursor:"crosshair"},onMouseDown:f=>{f.stopPropagation(),f.preventDefault();const _=Ht(f);L({from:t.id,x:_.x,y:_.y})}})]},t.id)}),zt.map(t=>e.jsxs("g",{style:{cursor:"pointer"},onClick:o=>{o.stopPropagation(),Ke(t.edge)},children:[e.jsx("title",{children:t.full}),e.jsx("rect",{x:t.x-t.width/2,y:t.y-9,width:t.width,height:13,rx:3,fill:"hsl(var(--background))",opacity:.92}),e.jsx("text",{x:t.x,y:t.y,textAnchor:"middle",style:{font:"10px ui-monospace, monospace",fill:"hsl(var(--muted-foreground))"},children:t.short})]},`label-${t.edge.id}`))]})})]}),e.jsx("div",{className:"rounded-lg border p-4 h-fit",children:Le?e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold",children:["Edge · ",Le.type.name]}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-3",children:[V(Le.from_node)," → ",V(Le.to_node)]}),e.jsx("label",{className:"block text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"Type"}),e.jsx("select",{value:T,onChange:t=>B(t.target.value),className:"w-full h-8 rounded-md border bg-background px-2 text-sm mb-3",children:y.map(t=>e.jsxs("option",{value:t.name,children:[t.is_flow?"▶ ":"",t.name]},t.id))}),e.jsx("label",{className:"block text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"Fires"}),e.jsx("div",{className:"flex items-center rounded-md border h-8 text-xs overflow-hidden w-fit mb-2",children:[["","always"],["nl","if…"],["structured","metric"]].map(([t,o],u)=>e.jsx("button",{type:"button",className:`px-2.5 h-full ${u>0?"border-l":""} ${D===t?"bg-primary text-primary-foreground":"hover:bg-muted"}`,onClick:()=>q(t),children:o},t))}),D==="nl"&&e.jsx(te,{value:Y,onChange:t=>U(t.target.value),placeholder:'e.g. "lost on price, not product"',className:"h-8 text-sm italic mb-2"}),D==="structured"&&e.jsxs("div",{className:"grid grid-cols-[1fr_58px_1fr] gap-1.5 mb-2",children:[e.jsx(te,{value:i,onChange:t=>$(t.target.value),placeholder:"CAC",className:"h-8 text-sm font-mono"}),e.jsx("select",{value:W,onChange:t=>he(t.target.value),className:"h-8 rounded-md border bg-background px-1 text-sm font-mono",children:[">","<",">=","<=","=","!="].map(t=>e.jsx("option",{value:t,children:t},t))}),e.jsx(te,{value:ne,onChange:t=>de(t.target.value),placeholder:"500",className:"h-8 text-sm font-mono"})]}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(S,{size:"sm",className:"flex-1",disabled:ye,onClick:()=>void Ft(),children:ye?e.jsx(J,{className:"h-3.5 w-3.5 animate-spin"}):"Save"}),e.jsx(S,{size:"sm",variant:"outline",className:"text-destructive",onClick:()=>void Dt(Le.id),children:"Delete"})]})]}):x?(()=>{const t=["agent","skill"].includes(Re(x)??""),o=be.find(l=>l.agent_node===x),u=window.location.origin,f=`[[${V(x)}]]`,_=`curl -s -X POST ${u}/nests/${s}/context -H 'Content-Type: application/json' -d '{"selector":"${f}","hops":${G},"max_tokens":4000}'`,A=`curl -s -X PATCH ${u}/nests/${s}/nodes/${x} -H 'Content-Type: application/json' -d '{"append":"<your update>","changeNote":"via ctx"}'`;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{type:Re(x)}),e.jsx("h3",{className:"text-sm font-semibold truncate",children:V(x)})]}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono truncate",children:x})]}),t&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(S,{size:"sm",className:"w-full",onClick:async()=>{try{await Qe(s,x),re("Run created — a polling runner will pick it up"),setTimeout(()=>re(""),3e3)}catch(l){E(l instanceof Error?l.message:"Trigger failed")}},children:[e.jsx(At,{className:"h-3.5 w-3.5 mr-1.5"})," Run now"]}),ae&&e.jsx("p",{className:"text-[11px] text-emerald-600",children:ae}),e.jsx("label",{className:"block text-[10px] uppercase tracking-wide text-muted-foreground",children:"Schedule"}),o?e.jsxs("div",{className:"rounded-md border px-2.5 py-2 text-xs space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{children:["every"," ",e.jsx("b",{children:o.every_minutes>=60?`${o.every_minutes/60}h`:`${o.every_minutes}m`}),o.enabled?"":" · paused"]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{type:"button",className:"text-primary hover:underline",onClick:async()=>{await Ie(s,o.id,{enabled:!o.enabled}),await xe()},children:o.enabled?"Pause":"Resume"}),e.jsx("button",{type:"button",className:"text-destructive hover:underline",onClick:async()=>{await yt(s,o.id),await xe()},children:"Remove"})]}),o.enabled&&o.next_due_at&&e.jsxs("div",{className:"text-muted-foreground",children:["next fire ~",Ee(o.next_due_at)]})]}):e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("select",{value:we,onChange:l=>H(Number(l.target.value)),className:"h-8 rounded-md border bg-background px-2 text-sm flex-1",children:[e.jsx("option",{value:15,children:"every 15 minutes"}),e.jsx("option",{value:60,children:"every hour"}),e.jsx("option",{value:360,children:"every 6 hours"}),e.jsx("option",{value:1440,children:"every day"})]}),e.jsx(S,{size:"sm",className:"h-8",onClick:async()=>{try{await bt(s,{agent_node:x,every_minutes:we}),await xe()}catch(l){E(l instanceof Error?l.message:"Schedule failed")}},children:"Schedule"})]})]}),t&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-[10px] uppercase tracking-wide text-muted-foreground",children:"Triggers — call this agent from outside"}),Fe.map(l=>e.jsxs("div",{className:"rounded-md border px-2 py-1.5 text-[11px] space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(se,{variant:"secondary",className:"text-[10px]",children:l.preset}),e.jsxs("span",{className:"text-muted-foreground",children:["fired ",l.fire_count,"×"]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{type:"button",className:"text-destructive hover:underline",onClick:async()=>{await Ut(s,l.id),ge(await Je(s,x))},children:"Remove"})]}),l.url??p[l.id]?e.jsx("button",{type:"button",className:"w-full text-left font-mono break-all rounded bg-muted/40 px-1.5 py-1 hover:border-primary border border-transparent",title:"Copy the trigger URL — paste into a Slack slash command / Events API, Teams outgoing webhook, or any system that can POST",onClick:()=>De(`hook-${l.id}`,l.url??p[l.id]),children:Z===`hook-${l.id}`?"✓ copied":l.url??p[l.id]}):e.jsx("p",{className:"text-muted-foreground px-1.5",children:"URL was shown at creation only (like an API key). Remove + re-add to mint a fresh one."})]},l.id)),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("select",{value:Pe,onChange:l=>a(l.target.value),className:"h-7 rounded-md border bg-background px-1.5 text-xs flex-1",children:[e.jsx("option",{value:"slack",children:"Slack (slash command / @mention)"}),e.jsx("option",{value:"teams",children:"Teams (outgoing webhook)"}),e.jsx("option",{value:"webhook",children:"Webhook (any system)"})]}),e.jsx(S,{size:"sm",variant:"outline",className:"h-7 px-2",onClick:async()=>{const l=await Xt(s,x,Pe);if(l.url){const M=`${l.id.slice(0,7)}…${l.id.slice(-4)}`;F(ce=>({...ce,[M]:l.url}))}ge(await Je(s,x))},children:e.jsx(oe,{className:"h-3.5 w-3.5"})})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Each trigger is a secret URL that queues a run — message text becomes the run's inputs. Add SLACK_SIGNING_SECRET to the Tool environment to verify Slack requests."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-[10px] uppercase tracking-wide text-muted-foreground",children:"Notify on output"}),v.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:v.map(l=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-muted px-2 py-0.5 text-[11px]",children:[l,e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-destructive",title:"Stop notifying",onClick:async()=>{const M=await Gt(s,x,l);P(M.map(ce=>ce.user_email))},children:"✕"})]},l))}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(te,{value:z,onChange:l=>R(l.target.value),placeholder:"person@team.com",className:"h-7 text-xs flex-1",onKeyDown:async l=>{if(l.key==="Enter"&&z.includes("@")){const M=await mt(s,x,z.trim());P(M.map(ce=>ce.user_email)),R("")}}}),e.jsx(S,{size:"sm",variant:"outline",className:"h-7 px-2",disabled:!z.includes("@"),onClick:async()=>{const l=await mt(s,x,z.trim());P(l.map(M=>M.user_email)),R("")},children:e.jsx(oe,{className:"h-3.5 w-3.5"})})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Tagged people get an inbox notification when this node's output lands for review. (Slack/webhook delivery comes later — same table.)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"Add a step after this"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("select",{value:X,onChange:l=>le(l.target.value),className:"h-8 rounded-md border bg-background px-2 text-sm flex-1 min-w-0",children:[e.jsx("option",{value:"",children:"Choose a document…"}),b.filter(l=>l.id!==x).map(l=>e.jsx("option",{value:l.id,children:l.title||l.id},l.id))]}),e.jsx(S,{size:"sm",className:"h-8",disabled:!X,onClick:()=>{ut(x,X),le("")},children:e.jsx(oe,{className:"h-3.5 w-3.5"})})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1.5",children:"Or drag from the node's right port straight onto another card."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Use from CLI / agent"}),e.jsx("div",{className:"flex-1"}),e.jsx("select",{value:G,onChange:l=>Te(Number(l.target.value)),className:"h-6 rounded border bg-background px-1 text-[11px]",title:"How many hops of linked context to pull with it",children:[0,1,2,3].map(l=>e.jsxs("option",{value:l,children:[l," hop",l===1?"":"s"]},l))})]}),e.jsx("button",{type:"button",className:"w-full text-left rounded-md border bg-muted/40 px-2 py-1.5 text-[10.5px] font-mono break-all hover:border-primary",onClick:()=>De("sel",f),title:"Copy the selector",children:Z==="sel"?"✓ copied":f}),e.jsx("button",{type:"button",className:"w-full text-left rounded-md border bg-muted/40 px-2 py-1.5 text-[10.5px] font-mono break-all hover:border-primary",onClick:()=>De("read",_),title:"Copy — deterministic read: this node + linked context",children:Z==="read"?"✓ copied":`read → ${_.slice(0,64)}…`}),e.jsx("button",{type:"button",className:"w-full text-left rounded-md border bg-muted/40 px-2 py-1.5 text-[10.5px] font-mono break-all hover:border-primary",onClick:()=>De("write",A),title:"Copy — governed write: append to this node (lands as a new version / review request)",children:Z==="write"?"✓ copied":`write → ${A.slice(0,64)}…`}),e.jsx(S,{variant:"outline",size:"sm",className:"w-full h-7 text-xs",disabled:ue,onClick:async()=>{var l;ie(!0);try{const M=await Jt(s,f,G);I({text:M.context||"(empty context)",nodes:((l=M.trace)==null?void 0:l.nodes_traversed)??M.nodes_traversed??0})}catch(M){E(M instanceof Error?M.message:"Preview failed")}finally{ie(!1)}},children:ue?e.jsx(J,{className:"h-3.5 w-3.5 animate-spin"}):e.jsxs(e.Fragment,{children:["Test: preview what it reads (",G," hop",G===1?"":"s",")"]})}),Q&&e.jsxs("div",{className:"rounded-md border bg-muted/30 p-2",children:[e.jsxs("div",{className:"flex items-center text-[10px] text-muted-foreground mb-1",children:[e.jsxs("span",{children:[Q.nodes," node",Q.nodes===1?"":"s"," assembled — exactly what a run reads"]}),e.jsx("button",{type:"button",className:"ml-auto hover:text-foreground",onClick:()=>I(null),children:"✕"})]}),e.jsxs("pre",{className:"max-h-56 overflow-auto whitespace-pre-wrap text-[10.5px] leading-relaxed",children:[Q.text.slice(0,4e3),Q.text.length>4e3?`
16
+ …(truncated)`:""]})]})]})]})})():e.jsxs("div",{className:"text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium text-foreground mb-1",children:"Nothing selected"}),e.jsxs("p",{className:"text-xs",children:["Click a ",e.jsx("b",{children:"wire"})," to change its type or condition, click a"," ",e.jsx("b",{children:"card"})," to add a next step, or drag from a card's right port onto another card to connect them."]})]})})]})}function Ds({nestId:s}){const[m,g]=r.useState([]),[y,C]=r.useState([]),[b,j]=r.useState(!0),[k,d]=r.useState(null),[h,E]=r.useState(""),[N,w]=r.useState(60),[x,O]=r.useState(""),[c,L]=r.useState(!1),T=r.useCallback(async()=>{j(!0);try{const[i,$]=await Promise.all([jt(s),Ue(s).then(W=>W.nodes).catch(()=>[])]);g(i),C($),d(null)}catch(i){d(i instanceof Error?i.message:"Failed to load schedules")}finally{j(!1)}},[s]);r.useEffect(()=>{T()},[T]);const B=i=>{var $;return(($=y.find(W=>W.id===i))==null?void 0:$.title)||i.replace(/^nodes\//,"")},D=i=>{var $;return($=y.find(W=>W.id===i))==null?void 0:$.type},q=y.filter(i=>i.type==="agent"||i.type==="skill"),Y=q.filter(i=>!m.some($=>$.agent_node===i.id)),U=i=>i>=1440?`${i/1440}d`:i>=60?`${i/60}h`:`${i}m`;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["A schedule decides ",e.jsx("b",{children:"when a run starts"})," and its stop-after bound decides ",e.jsx("b",{children:"when it's done"}),". What happens ",e.jsx("em",{children:"inside"})," a run — which step fires, on what condition — lives on the wires in the Canvas (click a wire to set always / if… / metric). Scheduled output still lands as a review request; scheduling doesn't skip governance."]}),k&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:k}),b?e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:e.jsx(J,{className:"h-4 w-4 animate-spin inline"})}):m.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed p-6 text-center",children:[e.jsx(ws,{className:"h-6 w-6 text-muted-foreground/50 mx-auto mb-2"}),e.jsx("p",{className:"text-sm font-medium mb-1",children:"Nothing on the clock yet"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:q.length?"Pick an agent below — every interval, the server files a run for it.":"This nest has no runnable agents yet. Create one from Documents → New → type Agent (its body is the instructions), then schedule it here."})]}):e.jsx("div",{className:"rounded-lg border divide-y",children:m.map(i=>e.jsxs("div",{className:"px-3 py-2.5 flex items-center gap-2 text-sm",children:[e.jsx(Ce,{type:D(i.agent_node)}),e.jsx("span",{className:"truncate font-medium",title:i.agent_node,children:B(i.agent_node)}),e.jsxs(se,{variant:"secondary",className:"text-[10px] shrink-0",children:["every ",U(i.every_minutes)]}),i.max_runs!==null&&e.jsxs(se,{variant:"outline",className:"text-[10px] shrink-0",title:"Stops automatically after this many runs",children:[i.runs_created,"/",i.max_runs," runs"]}),i.enabled?i.next_due_at&&e.jsxs("span",{className:"text-[11px] text-muted-foreground shrink-0",children:["next ~",Ee(i.next_due_at)]}):i.max_runs!==null&&i.runs_created>=i.max_runs?e.jsx(se,{className:"text-[10px] shrink-0 bg-emerald-600",children:"done"}):e.jsx(se,{variant:"outline",className:"text-[10px] shrink-0",children:"paused"}),e.jsx("div",{className:"flex-1"}),e.jsxs("select",{value:i.every_minutes,onChange:async $=>{await Ie(s,i.id,{every_minutes:Number($.target.value)}),await T()},className:"h-7 rounded-md border bg-background px-1.5 text-xs shrink-0",title:"Change the interval",children:[[15,60,360,1440].map($=>e.jsx("option",{value:$,children:U($)},$)),![15,60,360,1440].includes(i.every_minutes)&&e.jsx("option",{value:i.every_minutes,children:U(i.every_minutes)})]}),e.jsx(S,{variant:"outline",size:"sm",className:"h-7 text-xs shrink-0",onClick:async()=>{await Ie(s,i.id,{enabled:!i.enabled}),await T()},children:i.enabled?"Pause":"Resume"}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive shrink-0",onClick:async()=>{await yt(s,i.id),await T()},title:"Remove schedule",children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]},i.id))}),e.jsxs("div",{className:"rounded-lg border bg-muted/20 p-3",children:[e.jsx("div",{className:"text-xs font-medium mb-2",children:"Put an agent on the clock"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("select",{value:h,onChange:i=>E(i.target.value),className:"h-8 rounded-md border bg-background px-2 text-sm flex-1 min-w-0","data-testid":"schedule-agent-lookup",children:[e.jsx("option",{value:"",children:Y.length?"Choose an agent…":"Every runnable agent is scheduled"}),Y.map(i=>e.jsxs("option",{value:i.id,children:[i.type==="agent"?"🤖 ":"⚡ ",i.title||i.id]},i.id))]}),e.jsxs("select",{value:N,onChange:i=>w(Number(i.target.value)),className:"h-8 rounded-md border bg-background px-2 text-sm",children:[e.jsx("option",{value:15,children:"every 15 minutes"}),e.jsx("option",{value:60,children:"every hour"}),e.jsx("option",{value:360,children:"every 6 hours"}),e.jsx("option",{value:1440,children:"every day"})]}),e.jsxs("select",{value:x,onChange:i=>O(i.target.value===""?"":Number(i.target.value)),className:"h-8 rounded-md border bg-background px-2 text-sm",title:"The stop condition: pause automatically after this many runs",children:[e.jsx("option",{value:"",children:"until stopped"}),e.jsx("option",{value:1,children:"once"}),e.jsx("option",{value:5,children:"stop after 5"}),e.jsx("option",{value:10,children:"stop after 10"}),e.jsx("option",{value:25,children:"stop after 25"})]}),e.jsxs(S,{size:"sm",className:"h-8",disabled:c||!h,onClick:async()=>{L(!0);try{await bt(s,{agent_node:h,every_minutes:N,max_runs:x===""?null:x}),E(""),await T()}catch(i){d(i instanceof Error?i.message:"Schedule failed")}finally{L(!1)}},children:[e.jsx(oe,{className:"h-3.5 w-3.5 mr-1"})," Schedule"]})]})]})]})}function Hs({nestId:s}){const[m,g]=r.useState([]),[y,C]=r.useState(null),[b,j]=r.useState(""),[k,d]=r.useState(""),[h,E]=r.useState(!1),N=r.useCallback(async()=>{try{g(await Nt(s)),C(null)}catch(w){C(w instanceof Error?w.message:"Failed to load env")}},[s]);return r.useEffect(()=>{N()},[N]),e.jsxs("details",{className:"rounded-lg border px-4 py-3",children:[e.jsxs("summary",{className:"cursor-pointer select-none text-sm font-medium flex items-center gap-2",children:[e.jsx(St,{className:"h-4 w-4 text-teal-500 inline"})," Tool environment (",m.length," key",m.length===1?"":"s",")"]}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Credentials for ",e.jsx("b",{children:"tool"})," nodes. Values are write-only here and travel to the runner inside the run bundle. Stored alongside nest content, not encrypted — treat this box like the nest itself."]}),y&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:y}),m.length>0&&e.jsx("div",{className:"rounded-md border divide-y",children:m.map(w=>e.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"font-mono font-medium",children:w.key}),e.jsx("span",{className:"font-mono text-muted-foreground",children:w.value_masked}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-muted-foreground",children:w.updated_by}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-destructive",title:"Delete key",onClick:async()=>{await ns(s,w.key),await N()},children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]},w.key))}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(te,{value:b,onChange:w=>j(w.target.value.toUpperCase()),placeholder:"SLACK_TOKEN",className:"h-8 text-xs font-mono w-44"}),e.jsx(te,{value:k,onChange:w=>d(w.target.value),placeholder:"value (write-only)",type:"password",className:"h-8 text-xs font-mono flex-1"}),e.jsx(S,{size:"sm",className:"h-8",disabled:h||!/^[A-Z][A-Z0-9_]*$/.test(b)||!k,onClick:async()=>{E(!0);try{await wt(s,b,k),j(""),d(""),await N()}catch(w){C(w instanceof Error?w.message:"Save failed")}finally{E(!1)}},children:h?e.jsx(J,{className:"h-3.5 w-3.5 animate-spin"}):"Set"})]})]})]})}function Ks({nestId:s}){const[m,g]=r.useState(null),[y,C]=r.useState(""),[b,j]=r.useState(!1),[k,d]=r.useState(null),[h,E]=r.useState(!1);return r.useEffect(()=>{let N=!1;return Promise.all([Nt(s).catch(()=>null),Qt().catch(()=>null)]).then(([w,x])=>{if(!N){if(x!=null&&x.runner_key_configured)return g(!0);if(!w)return g(null);g(w.some(O=>O.key==="ANTHROPIC_API_KEY"))}}),()=>{N=!0}},[s]),m!==!1?h?e.jsx("div",{className:"rounded-lg border border-emerald-400/50 bg-emerald-500/5 px-4 py-3 text-sm",children:"✓ Key stored (masked from here on). Runners pick it up from the run bundle — start one in poll mode and your queued runs execute."}):null:e.jsxs("div",{className:"rounded-lg border border-amber-400/60 bg-amber-500/5 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-medium mb-1",children:"🔑 Add your Anthropic API key to execute runs"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Runs are created here, but a runner needs a key to call the model. Paste it once — it's stored write-only for this nest (masked everywhere, delivered to runners inside the run bundle). Get one at console.anthropic.com → Settings → API keys."}),k&&e.jsx("p",{className:"text-xs text-destructive mb-2",children:k}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{type:"password",value:y,onChange:N=>C(N.target.value),placeholder:"sk-ant-…",className:"h-8 text-sm font-mono flex-1","data-testid":"runner-key-input"}),e.jsx(S,{size:"sm",className:"h-8",disabled:b||!y.trim().startsWith("sk-"),onClick:async()=>{j(!0);try{await wt(s,"ANTHROPIC_API_KEY",y.trim()),C(""),g(!0),E(!0)}catch(N){d(N instanceof Error?N.message:"Save failed")}finally{j(!1)}},children:b?e.jsx(J,{className:"h-3.5 w-3.5 animate-spin"}):"Save key"})]})]})}const Vs=[["review_requested","review requested"],["review_approved","approved"],["review_rejected","rejected"],["run_failed","run failed"],["mention","mentioned"]];function Bs({nestId:s}){const[m,g]=r.useState([]),[y,C]=r.useState(null),[b,j]=r.useState("slack"),[k,d]=r.useState(""),[h,E]=r.useState(["*"]),[N,w]=r.useState(!1),x=r.useCallback(async()=>{try{g(await It(s)),C(null)}catch(c){C(c instanceof Error?c.message:"Failed to load connectors")}},[s]);r.useEffect(()=>{x()},[x]);const O=c=>{E(L=>{if(c==="*")return["*"];const T=L.filter(B=>B!=="*"&&B!==c);return L.includes(c)?T.length?T:["*"]:[...T,c]})};return e.jsxs("details",{className:"rounded-lg border px-4 py-3",open:m.length>0,children:[e.jsxs("summary",{className:"cursor-pointer select-none text-sm font-medium",children:["📤 Connectors (",m.length,") — send events to Slack / Teams / webhooks"]}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Governance + run events post to each matching channel. Fire-and-forget — a channel outage never blocks a review. The server-wide Slack webhook (super-admin Settings) always fires too."}),y&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:y}),m.length>0&&e.jsx("div",{className:"rounded-md border divide-y",children:m.map(c=>e.jsxs("div",{className:"px-3 py-2 flex items-center gap-2 text-xs",children:[e.jsx(se,{variant:"secondary",className:"text-[10px] shrink-0",children:c.channel}),e.jsx("span",{className:"font-mono truncate",children:c.url}),e.jsx("span",{className:"text-muted-foreground shrink-0",children:c.events.includes("*")?"all events":c.events.join(", ")}),e.jsx("div",{className:"flex-1"}),e.jsx(S,{variant:"outline",size:"sm",className:"h-6 text-[11px] px-2 shrink-0",onClick:async()=>{await es(s,c.id,{enabled:!c.enabled}),await x()},children:c.enabled?"Pause":"Resume"}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-destructive shrink-0",onClick:async()=>{await ts(s,c.id),await x()},title:"Delete connector",children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]},c.id))}),e.jsxs("div",{className:"space-y-2 rounded-md border bg-muted/20 p-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("select",{value:b,onChange:c=>j(c.target.value),className:"h-8 rounded-md border bg-background px-1.5 text-xs",children:[e.jsx("option",{value:"slack",children:"Slack"}),e.jsx("option",{value:"teams",children:"Teams"}),e.jsx("option",{value:"webhook",children:"Webhook (raw JSON)"})]}),e.jsx(te,{value:k,onChange:c=>d(c.target.value),placeholder:"https://hooks.slack.com/… or env:SLACK_WEBHOOK",className:"h-8 text-xs font-mono flex-1"}),e.jsx(S,{size:"sm",className:"h-8",disabled:N||!(k.startsWith("https://")||k.startsWith("env:")),onClick:async()=>{w(!0);try{await ss(s,{channel:b,url:k.trim(),events:h}),d(""),E(["*"]),await x()}catch(c){C(c instanceof Error?c.message:"Create failed")}finally{w(!1)}},children:e.jsx(oe,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex items-center flex-wrap gap-1 text-[11px]",children:[e.jsx("button",{type:"button",className:`rounded-full border px-2 py-0.5 ${h.includes("*")?"bg-primary text-primary-foreground border-primary":"hover:bg-muted"}`,onClick:()=>O("*"),children:"all events"}),Vs.map(([c,L])=>e.jsx("button",{type:"button",className:`rounded-full border px-2 py-0.5 ${h.includes(c)?"bg-primary text-primary-foreground border-primary":"hover:bg-muted"}`,onClick:()=>O(c),children:L},c))]})]})]})]})}function bn(){const s=ms();return e.jsx(Ts,{nestId:s.nestId,nestName:s.nestName,onBack:s.leaveNest})}export{bn as default};
@@ -1,4 +1,4 @@
1
- import{c as a}from"./index-EaX2yql0.js";/**
1
+ import{c as a}from"./index-B5hLclEq.js";/**
2
2
  * @license lucide-react v0.577.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{c as e}from"./index-EaX2yql0.js";/**
1
+ import{c as e}from"./index-B5hLclEq.js";/**
2
2
  * @license lucide-react v0.577.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1 +1 @@
1
- import{r as n,j as p,s as H,cX as Z,cY as T,cJ as ft,cL as ht,cT as mt,cO as pt,cZ as re,c_ as bt,c$ as ne,d0 as vt,cM as V,cP as F,d1 as gt,d2 as wt,cU as Me,C as St,d3 as xt,d4 as Y,d5 as Ct}from"./index-EaX2yql0.js";import{e as yt}from"./select-DBFTrUmI.js";const Et=n.forwardRef(({className:e,...r},t)=>p.jsx("textarea",{className:H("flex min-h-[82px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:t,...r}));Et.displayName="Textarea";var je=1,Rt=.9,kt=.8,Pt=.17,pe=.1,be=.999,At=.9999,It=.99,Tt=/[\\\/_+.#"@\[\(\{&]/,Nt=/[\\\/_+.#"@\[\(\{&]/g,jt=/[\s-]/,Oe=/[\s-]/g;function ge(e,r,t,a,o,l,c){if(l===r.length)return o===e.length?je:It;var i=`${o},${l}`;if(c[i]!==void 0)return c[i];for(var u=a.charAt(l),d=t.indexOf(u,o),f=0,h,m,v,S;d>=0;)h=ge(e,r,t,a,d+1,l+1,c),h>f&&(d===o?h*=je:Tt.test(e.charAt(d-1))?(h*=kt,v=e.slice(o,d-1).match(Nt),v&&o>0&&(h*=Math.pow(be,v.length))):jt.test(e.charAt(d-1))?(h*=Rt,S=e.slice(o,d-1).match(Oe),S&&o>0&&(h*=Math.pow(be,S.length))):(h*=Pt,o>0&&(h*=Math.pow(be,d-o))),e.charAt(d)!==r.charAt(l)&&(h*=At)),(h<pe&&t.charAt(d-1)===a.charAt(l+1)||a.charAt(l+1)===a.charAt(l)&&t.charAt(d-1)!==a.charAt(l))&&(m=ge(e,r,t,a,d+1,l+2,c),m*pe>h&&(h=m*pe)),h>f&&(f=h),d=t.indexOf(u,d+1);return c[i]=f,f}function _e(e){return e.toLowerCase().replace(Oe," ")}function _t(e,r,t){return e=t&&t.length>0?`${e+" "+t.join(" ")}`:e,ge(e,r,_e(e),_e(r),0,0,{})}var te='[cmdk-group=""]',ve='[cmdk-group-items=""]',Lt='[cmdk-group-heading=""]',He='[cmdk-item=""]',Le=`${He}:not([aria-disabled="true"])`,we="cmdk-item-select",G="data-value",Dt=(e,r,t)=>_t(e,r,t),ze=n.createContext(void 0),oe=()=>n.useContext(ze),We=n.createContext(void 0),Se=()=>n.useContext(We),Be=n.createContext(void 0),Fe=n.forwardRef((e,r)=>{let t=J(()=>{var s,g;return{search:"",value:(g=(s=e.value)!=null?s:e.defaultValue)!=null?g:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),a=J(()=>new Set),o=J(()=>new Map),l=J(()=>new Map),c=J(()=>new Set),i=Xe(e),{label:u,children:d,value:f,onValueChange:h,filter:m,shouldFilter:v,loop:S,disablePointerSelection:I=!1,vimBindings:A=!0,...y}=e,R=Z(),z=Z(),M=Z(),N=n.useRef(null),x=Vt();q(()=>{if(f!==void 0){let s=f.trim();t.current.value=s,k.emit()}},[f]),q(()=>{x(6,Pe)},[]);let k=n.useMemo(()=>({subscribe:s=>(c.current.add(s),()=>c.current.delete(s)),snapshot:()=>t.current,setState:(s,g,w)=>{var b,C,E,D;if(!Object.is(t.current[s],g)){if(t.current[s]=g,s==="search")le(),j(),x(1,W);else if(s==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let _=document.getElementById(M);_?_.focus():(b=document.getElementById(R))==null||b.focus()}if(x(7,()=>{var _;t.current.selectedItemId=(_=K())==null?void 0:_.id,k.emit()}),w||x(5,Pe),((C=i.current)==null?void 0:C.value)!==void 0){let _=g??"";(D=(E=i.current).onValueChange)==null||D.call(E,_);return}}k.emit()}},emit:()=>{c.current.forEach(s=>s())}}),[]),X=n.useMemo(()=>({value:(s,g,w)=>{var b;g!==((b=l.current.get(s))==null?void 0:b.value)&&(l.current.set(s,{value:g,keywords:w}),t.current.filtered.items.set(s,P(g,w)),x(2,()=>{j(),k.emit()}))},item:(s,g)=>(a.current.add(s),g&&(o.current.has(g)?o.current.get(g).add(s):o.current.set(g,new Set([s]))),x(3,()=>{le(),j(),t.current.value||W(),k.emit()}),()=>{l.current.delete(s),a.current.delete(s),t.current.filtered.items.delete(s);let w=K();x(4,()=>{le(),(w==null?void 0:w.getAttribute("id"))===s&&W(),k.emit()})}),group:s=>(o.current.has(s)||o.current.set(s,new Set),()=>{l.current.delete(s),o.current.delete(s)}),filter:()=>i.current.shouldFilter,label:u||e["aria-label"],getDisablePointerSelection:()=>i.current.disablePointerSelection,listId:R,inputId:M,labelId:z,listInnerRef:N}),[]);function P(s,g){var w,b;let C=(b=(w=i.current)==null?void 0:w.filter)!=null?b:Dt;return s?C(s,t.current.search,g):0}function j(){if(!t.current.search||i.current.shouldFilter===!1)return;let s=t.current.filtered.items,g=[];t.current.filtered.groups.forEach(b=>{let C=o.current.get(b),E=0;C.forEach(D=>{let _=s.get(D);E=Math.max(_,E)}),g.push([b,E])});let w=N.current;ee().sort((b,C)=>{var E,D;let _=b.getAttribute("id"),ae=C.getAttribute("id");return((E=s.get(ae))!=null?E:0)-((D=s.get(_))!=null?D:0)}).forEach(b=>{let C=b.closest(ve);C?C.appendChild(b.parentElement===C?b:b.closest(`${ve} > *`)):w.appendChild(b.parentElement===w?b:b.closest(`${ve} > *`))}),g.sort((b,C)=>C[1]-b[1]).forEach(b=>{var C;let E=(C=N.current)==null?void 0:C.querySelector(`${te}[${G}="${encodeURIComponent(b[0])}"]`);E==null||E.parentElement.appendChild(E)})}function W(){let s=ee().find(w=>w.getAttribute("aria-disabled")!=="true"),g=s==null?void 0:s.getAttribute(G);k.setState("value",g||void 0)}function le(){var s,g,w,b;if(!t.current.search||i.current.shouldFilter===!1){t.current.filtered.count=a.current.size;return}t.current.filtered.groups=new Set;let C=0;for(let E of a.current){let D=(g=(s=l.current.get(E))==null?void 0:s.value)!=null?g:"",_=(b=(w=l.current.get(E))==null?void 0:w.keywords)!=null?b:[],ae=P(D,_);t.current.filtered.items.set(E,ae),ae>0&&C++}for(let[E,D]of o.current)for(let _ of D)if(t.current.filtered.items.get(_)>0){t.current.filtered.groups.add(E);break}t.current.filtered.count=C}function Pe(){var s,g,w;let b=K();b&&(((s=b.parentElement)==null?void 0:s.firstChild)===b&&((w=(g=b.closest(te))==null?void 0:g.querySelector(Lt))==null||w.scrollIntoView({block:"nearest"})),b.scrollIntoView({block:"nearest"}))}function K(){var s;return(s=N.current)==null?void 0:s.querySelector(`${He}[aria-selected="true"]`)}function ee(){var s;return Array.from(((s=N.current)==null?void 0:s.querySelectorAll(Le))||[])}function he(s){let g=ee()[s];g&&k.setState("value",g.getAttribute(G))}function me(s){var g;let w=K(),b=ee(),C=b.findIndex(D=>D===w),E=b[C+s];(g=i.current)!=null&&g.loop&&(E=C+s<0?b[b.length-1]:C+s===b.length?b[0]:b[C+s]),E&&k.setState("value",E.getAttribute(G))}function Ae(s){let g=K(),w=g==null?void 0:g.closest(te),b;for(;w&&!b;)w=s>0?$t(w,te):Ut(w,te),b=w==null?void 0:w.querySelector(Le);b?k.setState("value",b.getAttribute(G)):me(s)}let Ie=()=>he(ee().length-1),Te=s=>{s.preventDefault(),s.metaKey?Ie():s.altKey?Ae(1):me(1)},Ne=s=>{s.preventDefault(),s.metaKey?he(0):s.altKey?Ae(-1):me(-1)};return n.createElement(T.div,{ref:r,tabIndex:-1,...y,"cmdk-root":"",onKeyDown:s=>{var g;(g=y.onKeyDown)==null||g.call(y,s);let w=s.nativeEvent.isComposing||s.keyCode===229;if(!(s.defaultPrevented||w))switch(s.key){case"n":case"j":{A&&s.ctrlKey&&Te(s);break}case"ArrowDown":{Te(s);break}case"p":case"k":{A&&s.ctrlKey&&Ne(s);break}case"ArrowUp":{Ne(s);break}case"Home":{s.preventDefault(),he(0);break}case"End":{s.preventDefault(),Ie();break}case"Enter":{s.preventDefault();let b=K();if(b){let C=new Event(we);b.dispatchEvent(C)}}}}},n.createElement("label",{"cmdk-label":"",htmlFor:X.inputId,id:X.labelId,style:qt},u),ie(e,s=>n.createElement(We.Provider,{value:k},n.createElement(ze.Provider,{value:X},s))))}),Mt=n.forwardRef((e,r)=>{var t,a;let o=Z(),l=n.useRef(null),c=n.useContext(Be),i=oe(),u=Xe(e),d=(a=(t=u.current)==null?void 0:t.forceMount)!=null?a:c==null?void 0:c.forceMount;q(()=>{if(!d)return i.item(o,c==null?void 0:c.id)},[d]);let f=$e(o,l,[e.value,e.children,l],e.keywords),h=Se(),m=U(x=>x.value&&x.value===f.current),v=U(x=>d||i.filter()===!1?!0:x.search?x.filtered.items.get(o)>0:!0);n.useEffect(()=>{let x=l.current;if(!(!x||e.disabled))return x.addEventListener(we,S),()=>x.removeEventListener(we,S)},[v,e.onSelect,e.disabled]);function S(){var x,k;I(),(k=(x=u.current).onSelect)==null||k.call(x,f.current)}function I(){h.setState("value",f.current,!0)}if(!v)return null;let{disabled:A,value:y,onSelect:R,forceMount:z,keywords:M,...N}=e;return n.createElement(T.div,{ref:re(l,r),...N,id:o,"cmdk-item":"",role:"option","aria-disabled":!!A,"aria-selected":!!m,"data-disabled":!!A,"data-selected":!!m,onPointerMove:A||i.getDisablePointerSelection()?void 0:I,onClick:A?void 0:S},e.children)}),Ot=n.forwardRef((e,r)=>{let{heading:t,children:a,forceMount:o,...l}=e,c=Z(),i=n.useRef(null),u=n.useRef(null),d=Z(),f=oe(),h=U(v=>o||f.filter()===!1?!0:v.search?v.filtered.groups.has(c):!0);q(()=>f.group(c),[]),$e(c,i,[e.value,e.heading,u]);let m=n.useMemo(()=>({id:c,forceMount:o}),[o]);return n.createElement(T.div,{ref:re(i,r),...l,"cmdk-group":"",role:"presentation",hidden:h?void 0:!0},t&&n.createElement("div",{ref:u,"cmdk-group-heading":"","aria-hidden":!0,id:d},t),ie(e,v=>n.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":t?d:void 0},n.createElement(Be.Provider,{value:m},v))))}),Ht=n.forwardRef((e,r)=>{let{alwaysRender:t,...a}=e,o=n.useRef(null),l=U(c=>!c.search);return!t&&!l?null:n.createElement(T.div,{ref:re(o,r),...a,"cmdk-separator":"",role:"separator"})}),zt=n.forwardRef((e,r)=>{let{onValueChange:t,...a}=e,o=e.value!=null,l=Se(),c=U(d=>d.search),i=U(d=>d.selectedItemId),u=oe();return n.useEffect(()=>{e.value!=null&&l.setState("search",e.value)},[e.value]),n.createElement(T.input,{ref:r,...a,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":u.listId,"aria-labelledby":u.labelId,"aria-activedescendant":i,id:u.inputId,type:"text",value:o?e.value:c,onChange:d=>{o||l.setState("search",d.target.value),t==null||t(d.target.value)}})}),Wt=n.forwardRef((e,r)=>{let{children:t,label:a="Suggestions",...o}=e,l=n.useRef(null),c=n.useRef(null),i=U(d=>d.selectedItemId),u=oe();return n.useEffect(()=>{if(c.current&&l.current){let d=c.current,f=l.current,h,m=new ResizeObserver(()=>{h=requestAnimationFrame(()=>{let v=d.offsetHeight;f.style.setProperty("--cmdk-list-height",v.toFixed(1)+"px")})});return m.observe(d),()=>{cancelAnimationFrame(h),m.unobserve(d)}}},[]),n.createElement(T.div,{ref:re(l,r),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":i,"aria-label":a,id:u.listId},ie(e,d=>n.createElement("div",{ref:re(c,u.listInnerRef),"cmdk-list-sizer":""},d)))}),Bt=n.forwardRef((e,r)=>{let{open:t,onOpenChange:a,overlayClassName:o,contentClassName:l,container:c,...i}=e;return n.createElement(ft,{open:t,onOpenChange:a},n.createElement(ht,{container:c},n.createElement(mt,{"cmdk-overlay":"",className:o}),n.createElement(pt,{"aria-label":e.label,"cmdk-dialog":"",className:l},n.createElement(Fe,{ref:r,...i}))))}),Ft=n.forwardRef((e,r)=>U(t=>t.filtered.count===0)?n.createElement(T.div,{ref:r,...e,"cmdk-empty":"",role:"presentation"}):null),Xt=n.forwardRef((e,r)=>{let{progress:t,children:a,label:o="Loading...",...l}=e;return n.createElement(T.div,{ref:r,...l,"cmdk-loading":"",role:"progressbar","aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},ie(e,c=>n.createElement("div",{"aria-hidden":!0},c)))}),L=Object.assign(Fe,{List:Wt,Item:Mt,Input:zt,Group:Ot,Separator:Ht,Dialog:Bt,Empty:Ft,Loading:Xt});function $t(e,r){let t=e.nextElementSibling;for(;t;){if(t.matches(r))return t;t=t.nextElementSibling}}function Ut(e,r){let t=e.previousElementSibling;for(;t;){if(t.matches(r))return t;t=t.previousElementSibling}}function Xe(e){let r=n.useRef(e);return q(()=>{r.current=e}),r}var q=typeof window>"u"?n.useEffect:n.useLayoutEffect;function J(e){let r=n.useRef();return r.current===void 0&&(r.current=e()),r}function U(e){let r=Se(),t=()=>e(r.snapshot());return n.useSyncExternalStore(r.subscribe,t,t)}function $e(e,r,t,a=[]){let o=n.useRef(),l=oe();return q(()=>{var c;let i=(()=>{var d;for(let f of t){if(typeof f=="string")return f.trim();if(typeof f=="object"&&"current"in f)return f.current?(d=f.current.textContent)==null?void 0:d.trim():o.current}})(),u=a.map(d=>d.trim());l.value(e,i,u),(c=r.current)==null||c.setAttribute(G,i),o.current=i}),o}var Vt=()=>{let[e,r]=n.useState(),t=J(()=>new Map);return q(()=>{t.current.forEach(a=>a()),t.current=new Map},[e]),(a,o)=>{t.current.set(a,o),r({})}};function Yt(e){let r=e.type;return typeof r=="function"?r(e.props):"render"in r?r.render(e.props):e}function ie({asChild:e,children:r},t){return e&&n.isValidElement(r)?n.cloneElement(Yt(r),{ref:r.ref},t(r.props.children)):t(r)}var qt={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const Kt=n.forwardRef(({className:e,...r},t)=>p.jsx(L,{ref:t,className:H("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...r}));Kt.displayName=L.displayName;const Gt=n.forwardRef(({className:e,...r},t)=>p.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[p.jsx(bt,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),p.jsx(L.Input,{ref:t,className:H("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...r})]}));Gt.displayName=L.Input.displayName;const Jt=n.forwardRef(({className:e,...r},t)=>p.jsx(L.List,{ref:t,className:H("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...r}));Jt.displayName=L.List.displayName;const Zt=n.forwardRef((e,r)=>p.jsx(L.Empty,{ref:r,className:"py-6 text-center text-sm",...e}));Zt.displayName=L.Empty.displayName;const Qt=n.forwardRef(({className:e,...r},t)=>p.jsx(L.Group,{ref:t,className:H("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",e),...r}));Qt.displayName=L.Group.displayName;const er=n.forwardRef(({className:e,...r},t)=>p.jsx(L.Separator,{ref:t,className:H("-mx-1 h-px bg-border",e),...r}));er.displayName=L.Separator.displayName;const tr=n.forwardRef(({className:e,...r},t)=>p.jsx(L.Item,{ref:t,className:H("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",e),...r}));tr.displayName=L.Item.displayName;var de="Checkbox",[rr]=Me(de),[nr,xe]=rr(de);function or(e){const{__scopeCheckbox:r,checked:t,children:a,defaultChecked:o,disabled:l,form:c,name:i,onCheckedChange:u,required:d,value:f="on",internal_do_not_use_render:h}=e,[m,v]=vt({prop:t,defaultProp:o??!1,onChange:u,caller:de}),[S,I]=n.useState(null),[A,y]=n.useState(null),R=n.useRef(!1),z=S?!!c||!!S.closest("form"):!0,M={checked:m,disabled:l,setChecked:v,control:S,setControl:I,name:i,form:c,value:f,hasConsumerStoppedPropagationRef:R,required:d,defaultChecked:$(o)?!1:o,isFormControl:z,bubbleInput:A,setBubbleInput:y};return p.jsx(nr,{scope:r,...M,children:lr(h)?h(M):a})}var Ue="CheckboxTrigger",Ve=n.forwardRef(({__scopeCheckbox:e,onKeyDown:r,onClick:t,...a},o)=>{const{control:l,value:c,disabled:i,checked:u,required:d,setControl:f,setChecked:h,hasConsumerStoppedPropagationRef:m,isFormControl:v,bubbleInput:S}=xe(Ue,e),I=V(o,f),A=n.useRef(u);return n.useEffect(()=>{const y=l==null?void 0:l.form;if(y){const R=()=>h(A.current);return y.addEventListener("reset",R),()=>y.removeEventListener("reset",R)}},[l,h]),p.jsx(T.button,{type:"button",role:"checkbox","aria-checked":$(u)?"mixed":u,"aria-required":d,"data-state":Je(u),"data-disabled":i?"":void 0,disabled:i,value:c,...a,ref:I,onKeyDown:F(r,y=>{y.key==="Enter"&&y.preventDefault()}),onClick:F(t,y=>{h(R=>$(R)?!0:!R),S&&v&&(m.current=y.isPropagationStopped(),m.current||y.stopPropagation())})})});Ve.displayName=Ue;var Ce=n.forwardRef((e,r)=>{const{__scopeCheckbox:t,name:a,checked:o,defaultChecked:l,required:c,disabled:i,value:u,onCheckedChange:d,form:f,...h}=e;return p.jsx(or,{__scopeCheckbox:t,checked:o,defaultChecked:l,disabled:i,required:c,onCheckedChange:d,name:a,form:f,value:u,internal_do_not_use_render:({isFormControl:m})=>p.jsxs(p.Fragment,{children:[p.jsx(Ve,{...h,ref:r,__scopeCheckbox:t}),m&&p.jsx(Ge,{__scopeCheckbox:t})]})})});Ce.displayName=de;var Ye="CheckboxIndicator",qe=n.forwardRef((e,r)=>{const{__scopeCheckbox:t,forceMount:a,...o}=e,l=xe(Ye,t);return p.jsx(ne,{present:a||$(l.checked)||l.checked===!0,children:p.jsx(T.span,{"data-state":Je(l.checked),"data-disabled":l.disabled?"":void 0,...o,ref:r,style:{pointerEvents:"none",...e.style}})})});qe.displayName=Ye;var Ke="CheckboxBubbleInput",Ge=n.forwardRef(({__scopeCheckbox:e,...r},t)=>{const{control:a,hasConsumerStoppedPropagationRef:o,checked:l,defaultChecked:c,required:i,disabled:u,name:d,value:f,form:h,bubbleInput:m,setBubbleInput:v}=xe(Ke,e),S=V(t,v),I=gt(l),A=wt(a);n.useEffect(()=>{const R=m;if(!R)return;const z=window.HTMLInputElement.prototype,N=Object.getOwnPropertyDescriptor(z,"checked").set,x=!o.current;if(I!==l&&N){const k=new Event("click",{bubbles:x});R.indeterminate=$(l),N.call(R,$(l)?!1:l),R.dispatchEvent(k)}},[m,I,l,o]);const y=n.useRef($(l)?!1:l);return p.jsx(T.input,{type:"checkbox","aria-hidden":!0,defaultChecked:c??y.current,required:i,disabled:u,name:d,value:f,form:h,...r,tabIndex:-1,ref:S,style:{...r.style,...A,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});Ge.displayName=Ke;function lr(e){return typeof e=="function"}function $(e){return e==="indeterminate"}function Je(e){return $(e)?"indeterminate":e?"checked":"unchecked"}const ar=n.forwardRef(({className:e,...r},t)=>p.jsx(Ce,{ref:t,className:H("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",e),...r,children:p.jsx(qe,{className:H("flex items-center justify-center text-current"),children:p.jsx(St,{className:"h-4 w-4"})})}));ar.displayName=Ce.displayName;function cr(e,r){return n.useReducer((t,a)=>r[t][a]??t,e)}var ye="ScrollArea",[Ze]=Me(ye),[sr,O]=Ze(ye),Qe=n.forwardRef((e,r)=>{const{__scopeScrollArea:t,type:a="hover",dir:o,scrollHideDelay:l=600,...c}=e,[i,u]=n.useState(null),[d,f]=n.useState(null),[h,m]=n.useState(null),[v,S]=n.useState(null),[I,A]=n.useState(null),[y,R]=n.useState(0),[z,M]=n.useState(0),[N,x]=n.useState(!1),[k,X]=n.useState(!1),P=V(r,W=>u(W)),j=xt(o);return p.jsx(sr,{scope:t,type:a,dir:j,scrollHideDelay:l,scrollArea:i,viewport:d,onViewportChange:f,content:h,onContentChange:m,scrollbarX:v,onScrollbarXChange:S,scrollbarXEnabled:N,onScrollbarXEnabledChange:x,scrollbarY:I,onScrollbarYChange:A,scrollbarYEnabled:k,onScrollbarYEnabledChange:X,onCornerWidthChange:R,onCornerHeightChange:M,children:p.jsx(T.div,{dir:j,...c,ref:P,style:{position:"relative","--radix-scroll-area-corner-width":y+"px","--radix-scroll-area-corner-height":z+"px",...e.style}})})});Qe.displayName=ye;var et="ScrollAreaViewport",tt=n.forwardRef((e,r)=>{const{__scopeScrollArea:t,children:a,nonce:o,...l}=e,c=O(et,t),i=n.useRef(null),u=V(r,i,c.onViewportChange);return p.jsxs(p.Fragment,{children:[p.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),p.jsx(T.div,{"data-radix-scroll-area-viewport":"",...l,ref:u,style:{overflowX:c.scrollbarXEnabled?"scroll":"hidden",overflowY:c.scrollbarYEnabled?"scroll":"hidden",...e.style},children:p.jsx("div",{ref:c.onContentChange,style:{minWidth:"100%",display:"table"},children:a})})]})});tt.displayName=et;var B="ScrollAreaScrollbar",Ee=n.forwardRef((e,r)=>{const{forceMount:t,...a}=e,o=O(B,e.__scopeScrollArea),{onScrollbarXEnabledChange:l,onScrollbarYEnabledChange:c}=o,i=e.orientation==="horizontal";return n.useEffect(()=>(i?l(!0):c(!0),()=>{i?l(!1):c(!1)}),[i,l,c]),o.type==="hover"?p.jsx(ir,{...a,ref:r,forceMount:t}):o.type==="scroll"?p.jsx(dr,{...a,ref:r,forceMount:t}):o.type==="auto"?p.jsx(rt,{...a,ref:r,forceMount:t}):o.type==="always"?p.jsx(Re,{...a,ref:r}):null});Ee.displayName=B;var ir=n.forwardRef((e,r)=>{const{forceMount:t,...a}=e,o=O(B,e.__scopeScrollArea),[l,c]=n.useState(!1);return n.useEffect(()=>{const i=o.scrollArea;let u=0;if(i){const d=()=>{window.clearTimeout(u),c(!0)},f=()=>{u=window.setTimeout(()=>c(!1),o.scrollHideDelay)};return i.addEventListener("pointerenter",d),i.addEventListener("pointerleave",f),()=>{window.clearTimeout(u),i.removeEventListener("pointerenter",d),i.removeEventListener("pointerleave",f)}}},[o.scrollArea,o.scrollHideDelay]),p.jsx(ne,{present:t||l,children:p.jsx(rt,{"data-state":l?"visible":"hidden",...a,ref:r})})}),dr=n.forwardRef((e,r)=>{const{forceMount:t,...a}=e,o=O(B,e.__scopeScrollArea),l=e.orientation==="horizontal",c=fe(()=>u("SCROLL_END"),100),[i,u]=cr("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return n.useEffect(()=>{if(i==="idle"){const d=window.setTimeout(()=>u("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(d)}},[i,o.scrollHideDelay,u]),n.useEffect(()=>{const d=o.viewport,f=l?"scrollLeft":"scrollTop";if(d){let h=d[f];const m=()=>{const v=d[f];h!==v&&(u("SCROLL"),c()),h=v};return d.addEventListener("scroll",m),()=>d.removeEventListener("scroll",m)}},[o.viewport,l,u,c]),p.jsx(ne,{present:t||i!=="hidden",children:p.jsx(Re,{"data-state":i==="hidden"?"hidden":"visible",...a,ref:r,onPointerEnter:F(e.onPointerEnter,()=>u("POINTER_ENTER")),onPointerLeave:F(e.onPointerLeave,()=>u("POINTER_LEAVE"))})})}),rt=n.forwardRef((e,r)=>{const t=O(B,e.__scopeScrollArea),{forceMount:a,...o}=e,[l,c]=n.useState(!1),i=e.orientation==="horizontal",u=fe(()=>{if(t.viewport){const d=t.viewport.offsetWidth<t.viewport.scrollWidth,f=t.viewport.offsetHeight<t.viewport.scrollHeight;c(i?d:f)}},10);return Q(t.viewport,u),Q(t.content,u),p.jsx(ne,{present:a||l,children:p.jsx(Re,{"data-state":l?"visible":"hidden",...o,ref:r})})}),Re=n.forwardRef((e,r)=>{const{orientation:t="vertical",...a}=e,o=O(B,e.__scopeScrollArea),l=n.useRef(null),c=n.useRef(0),[i,u]=n.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),d=ct(i.viewport,i.content),f={...a,sizes:i,onSizesChange:u,hasThumb:d>0&&d<1,onThumbChange:m=>l.current=m,onThumbPointerUp:()=>c.current=0,onThumbPointerDown:m=>c.current=m};function h(m,v){return br(m,c.current,i,v)}return t==="horizontal"?p.jsx(ur,{...f,ref:r,onThumbPositionChange:()=>{if(o.viewport&&l.current){const m=o.viewport.scrollLeft,v=De(m,i,o.dir);l.current.style.transform=`translate3d(${v}px, 0, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollLeft=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollLeft=h(m,o.dir))}}):t==="vertical"?p.jsx(fr,{...f,ref:r,onThumbPositionChange:()=>{if(o.viewport&&l.current){const m=o.viewport.scrollTop,v=De(m,i);l.current.style.transform=`translate3d(0, ${v}px, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollTop=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollTop=h(m))}}):null}),ur=n.forwardRef((e,r)=>{const{sizes:t,onSizesChange:a,...o}=e,l=O(B,e.__scopeScrollArea),[c,i]=n.useState(),u=n.useRef(null),d=V(r,u,l.onScrollbarXChange);return n.useEffect(()=>{u.current&&i(getComputedStyle(u.current))},[u]),p.jsx(ot,{"data-orientation":"horizontal",...o,ref:d,sizes:t,style:{bottom:0,left:l.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:l.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":ue(t)+"px",...e.style},onThumbPointerDown:f=>e.onThumbPointerDown(f.x),onDragScroll:f=>e.onDragScroll(f.x),onWheelScroll:(f,h)=>{if(l.viewport){const m=l.viewport.scrollLeft+f.deltaX;e.onWheelScroll(m),it(m,h)&&f.preventDefault()}},onResize:()=>{u.current&&l.viewport&&c&&a({content:l.viewport.scrollWidth,viewport:l.viewport.offsetWidth,scrollbar:{size:u.current.clientWidth,paddingStart:se(c.paddingLeft),paddingEnd:se(c.paddingRight)}})}})}),fr=n.forwardRef((e,r)=>{const{sizes:t,onSizesChange:a,...o}=e,l=O(B,e.__scopeScrollArea),[c,i]=n.useState(),u=n.useRef(null),d=V(r,u,l.onScrollbarYChange);return n.useEffect(()=>{u.current&&i(getComputedStyle(u.current))},[u]),p.jsx(ot,{"data-orientation":"vertical",...o,ref:d,sizes:t,style:{top:0,right:l.dir==="ltr"?0:void 0,left:l.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":ue(t)+"px",...e.style},onThumbPointerDown:f=>e.onThumbPointerDown(f.y),onDragScroll:f=>e.onDragScroll(f.y),onWheelScroll:(f,h)=>{if(l.viewport){const m=l.viewport.scrollTop+f.deltaY;e.onWheelScroll(m),it(m,h)&&f.preventDefault()}},onResize:()=>{u.current&&l.viewport&&c&&a({content:l.viewport.scrollHeight,viewport:l.viewport.offsetHeight,scrollbar:{size:u.current.clientHeight,paddingStart:se(c.paddingTop),paddingEnd:se(c.paddingBottom)}})}})}),[hr,nt]=Ze(B),ot=n.forwardRef((e,r)=>{const{__scopeScrollArea:t,sizes:a,hasThumb:o,onThumbChange:l,onThumbPointerUp:c,onThumbPointerDown:i,onThumbPositionChange:u,onDragScroll:d,onWheelScroll:f,onResize:h,...m}=e,v=O(B,t),[S,I]=n.useState(null),A=V(r,P=>I(P)),y=n.useRef(null),R=n.useRef(""),z=v.viewport,M=a.content-a.viewport,N=Y(f),x=Y(u),k=fe(h,10);function X(P){if(y.current){const j=P.clientX-y.current.left,W=P.clientY-y.current.top;d({x:j,y:W})}}return n.useEffect(()=>{const P=j=>{const W=j.target;(S==null?void 0:S.contains(W))&&N(j,M)};return document.addEventListener("wheel",P,{passive:!1}),()=>document.removeEventListener("wheel",P,{passive:!1})},[z,S,M,N]),n.useEffect(x,[a,x]),Q(S,k),Q(v.content,k),p.jsx(hr,{scope:t,scrollbar:S,hasThumb:o,onThumbChange:Y(l),onThumbPointerUp:Y(c),onThumbPositionChange:x,onThumbPointerDown:Y(i),children:p.jsx(T.div,{...m,ref:A,style:{position:"absolute",...m.style},onPointerDown:F(e.onPointerDown,P=>{P.button===0&&(P.target.setPointerCapture(P.pointerId),y.current=S.getBoundingClientRect(),R.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",v.viewport&&(v.viewport.style.scrollBehavior="auto"),X(P))}),onPointerMove:F(e.onPointerMove,X),onPointerUp:F(e.onPointerUp,P=>{const j=P.target;j.hasPointerCapture(P.pointerId)&&j.releasePointerCapture(P.pointerId),document.body.style.webkitUserSelect=R.current,v.viewport&&(v.viewport.style.scrollBehavior=""),y.current=null})})})}),ce="ScrollAreaThumb",lt=n.forwardRef((e,r)=>{const{forceMount:t,...a}=e,o=nt(ce,e.__scopeScrollArea);return p.jsx(ne,{present:t||o.hasThumb,children:p.jsx(mr,{ref:r,...a})})}),mr=n.forwardRef((e,r)=>{const{__scopeScrollArea:t,style:a,...o}=e,l=O(ce,t),c=nt(ce,t),{onThumbPositionChange:i}=c,u=V(r,h=>c.onThumbChange(h)),d=n.useRef(void 0),f=fe(()=>{d.current&&(d.current(),d.current=void 0)},100);return n.useEffect(()=>{const h=l.viewport;if(h){const m=()=>{if(f(),!d.current){const v=vr(h,i);d.current=v,i()}};return i(),h.addEventListener("scroll",m),()=>h.removeEventListener("scroll",m)}},[l.viewport,f,i]),p.jsx(T.div,{"data-state":c.hasThumb?"visible":"hidden",...o,ref:u,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...a},onPointerDownCapture:F(e.onPointerDownCapture,h=>{const v=h.target.getBoundingClientRect(),S=h.clientX-v.left,I=h.clientY-v.top;c.onThumbPointerDown({x:S,y:I})}),onPointerUp:F(e.onPointerUp,c.onThumbPointerUp)})});lt.displayName=ce;var ke="ScrollAreaCorner",at=n.forwardRef((e,r)=>{const t=O(ke,e.__scopeScrollArea),a=!!(t.scrollbarX&&t.scrollbarY);return t.type!=="scroll"&&a?p.jsx(pr,{...e,ref:r}):null});at.displayName=ke;var pr=n.forwardRef((e,r)=>{const{__scopeScrollArea:t,...a}=e,o=O(ke,t),[l,c]=n.useState(0),[i,u]=n.useState(0),d=!!(l&&i);return Q(o.scrollbarX,()=>{var h;const f=((h=o.scrollbarX)==null?void 0:h.offsetHeight)||0;o.onCornerHeightChange(f),u(f)}),Q(o.scrollbarY,()=>{var h;const f=((h=o.scrollbarY)==null?void 0:h.offsetWidth)||0;o.onCornerWidthChange(f),c(f)}),d?p.jsx(T.div,{...a,ref:r,style:{width:l,height:i,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function se(e){return e?parseInt(e,10):0}function ct(e,r){const t=e/r;return isNaN(t)?0:t}function ue(e){const r=ct(e.viewport,e.content),t=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,a=(e.scrollbar.size-t)*r;return Math.max(a,18)}function br(e,r,t,a="ltr"){const o=ue(t),l=o/2,c=r||l,i=o-c,u=t.scrollbar.paddingStart+c,d=t.scrollbar.size-t.scrollbar.paddingEnd-i,f=t.content-t.viewport,h=a==="ltr"?[0,f]:[f*-1,0];return st([u,d],h)(e)}function De(e,r,t="ltr"){const a=ue(r),o=r.scrollbar.paddingStart+r.scrollbar.paddingEnd,l=r.scrollbar.size-o,c=r.content-r.viewport,i=l-a,u=t==="ltr"?[0,c]:[c*-1,0],d=yt(e,u);return st([0,c],[0,i])(d)}function st(e,r){return t=>{if(e[0]===e[1]||r[0]===r[1])return r[0];const a=(r[1]-r[0])/(e[1]-e[0]);return r[0]+a*(t-e[0])}}function it(e,r){return e>0&&e<r}var vr=(e,r=()=>{})=>{let t={left:e.scrollLeft,top:e.scrollTop},a=0;return(function o(){const l={left:e.scrollLeft,top:e.scrollTop},c=t.left!==l.left,i=t.top!==l.top;(c||i)&&r(),t=l,a=window.requestAnimationFrame(o)})(),()=>window.cancelAnimationFrame(a)};function fe(e,r){const t=Y(e),a=n.useRef(0);return n.useEffect(()=>()=>window.clearTimeout(a.current),[]),n.useCallback(()=>{window.clearTimeout(a.current),a.current=window.setTimeout(t,r)},[t,r])}function Q(e,r){const t=Y(r);Ct(()=>{let a=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(a),a=window.requestAnimationFrame(t)});return o.observe(e),()=>{window.cancelAnimationFrame(a),o.unobserve(e)}}},[e,t])}var dt=Qe,gr=tt,wr=at;const Sr=n.forwardRef(({className:e,children:r,...t},a)=>p.jsxs(dt,{ref:a,className:H("relative overflow-hidden",e),...t,children:[p.jsx(gr,{className:"h-full w-full rounded-[inherit] [&>div]:!block [&>div]:!min-w-0",children:r}),p.jsx(ut,{}),p.jsx(wr,{})]}));Sr.displayName=dt.displayName;const ut=n.forwardRef(({className:e,orientation:r="vertical",...t},a)=>p.jsx(Ee,{ref:a,orientation:r,className:H("flex touch-none select-none transition-colors",r==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",r==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...t,children:p.jsx(lt,{className:"relative flex-1 rounded-full bg-border"})}));ut.displayName=Ee.displayName;export{Kt as C,Sr as S,Et as T,Gt as a,Jt as b,Zt as c,Qt as d,tr as e,ar as f};
1
+ import{r as n,j as p,s as H,c_ as Q,c$ as T,cM as ft,cO as ht,cW as mt,cR as pt,d0 as re,d1 as bt,d2 as ne,d3 as vt,cP as U,cS as F,d4 as gt,d5 as wt,cX as Me,C as St,d6 as xt,d7 as Y,d8 as Ct}from"./index-B5hLclEq.js";import{e as yt}from"./select-DrL0mpRN.js";const Et=n.forwardRef(({className:e,...r},t)=>p.jsx("textarea",{className:H("flex min-h-[82px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:t,...r}));Et.displayName="Textarea";var je=1,Rt=.9,kt=.8,Pt=.17,pe=.1,be=.999,At=.9999,It=.99,Tt=/[\\\/_+.#"@\[\(\{&]/,Nt=/[\\\/_+.#"@\[\(\{&]/g,jt=/[\s-]/,Oe=/[\s-]/g;function ge(e,r,t,a,o,l,s){if(l===r.length)return o===e.length?je:It;var i=`${o},${l}`;if(s[i]!==void 0)return s[i];for(var u=a.charAt(l),d=t.indexOf(u,o),f=0,h,m,v,S;d>=0;)h=ge(e,r,t,a,d+1,l+1,s),h>f&&(d===o?h*=je:Tt.test(e.charAt(d-1))?(h*=kt,v=e.slice(o,d-1).match(Nt),v&&o>0&&(h*=Math.pow(be,v.length))):jt.test(e.charAt(d-1))?(h*=Rt,S=e.slice(o,d-1).match(Oe),S&&o>0&&(h*=Math.pow(be,S.length))):(h*=Pt,o>0&&(h*=Math.pow(be,d-o))),e.charAt(d)!==r.charAt(l)&&(h*=At)),(h<pe&&t.charAt(d-1)===a.charAt(l+1)||a.charAt(l+1)===a.charAt(l)&&t.charAt(d-1)!==a.charAt(l))&&(m=ge(e,r,t,a,d+1,l+2,s),m*pe>h&&(h=m*pe)),h>f&&(f=h),d=t.indexOf(u,d+1);return s[i]=f,f}function _e(e){return e.toLowerCase().replace(Oe," ")}function _t(e,r,t){return e=t&&t.length>0?`${e+" "+t.join(" ")}`:e,ge(e,r,_e(e),_e(r),0,0,{})}var te='[cmdk-group=""]',ve='[cmdk-group-items=""]',Lt='[cmdk-group-heading=""]',He='[cmdk-item=""]',Le=`${He}:not([aria-disabled="true"])`,we="cmdk-item-select",G="data-value",Dt=(e,r,t)=>_t(e,r,t),We=n.createContext(void 0),oe=()=>n.useContext(We),ze=n.createContext(void 0),Se=()=>n.useContext(ze),Be=n.createContext(void 0),Fe=n.forwardRef((e,r)=>{let t=J(()=>{var c,g;return{search:"",value:(g=(c=e.value)!=null?c:e.defaultValue)!=null?g:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),a=J(()=>new Set),o=J(()=>new Map),l=J(()=>new Map),s=J(()=>new Set),i=Xe(e),{label:u,children:d,value:f,onValueChange:h,filter:m,shouldFilter:v,loop:S,disablePointerSelection:I=!1,vimBindings:A=!0,...y}=e,R=Q(),W=Q(),M=Q(),N=n.useRef(null),x=Ut();q(()=>{if(f!==void 0){let c=f.trim();t.current.value=c,k.emit()}},[f]),q(()=>{x(6,Pe)},[]);let k=n.useMemo(()=>({subscribe:c=>(s.current.add(c),()=>s.current.delete(c)),snapshot:()=>t.current,setState:(c,g,w)=>{var b,C,E,D;if(!Object.is(t.current[c],g)){if(t.current[c]=g,c==="search")le(),j(),x(1,z);else if(c==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let _=document.getElementById(M);_?_.focus():(b=document.getElementById(R))==null||b.focus()}if(x(7,()=>{var _;t.current.selectedItemId=(_=K())==null?void 0:_.id,k.emit()}),w||x(5,Pe),((C=i.current)==null?void 0:C.value)!==void 0){let _=g??"";(D=(E=i.current).onValueChange)==null||D.call(E,_);return}}k.emit()}},emit:()=>{s.current.forEach(c=>c())}}),[]),X=n.useMemo(()=>({value:(c,g,w)=>{var b;g!==((b=l.current.get(c))==null?void 0:b.value)&&(l.current.set(c,{value:g,keywords:w}),t.current.filtered.items.set(c,P(g,w)),x(2,()=>{j(),k.emit()}))},item:(c,g)=>(a.current.add(c),g&&(o.current.has(g)?o.current.get(g).add(c):o.current.set(g,new Set([c]))),x(3,()=>{le(),j(),t.current.value||z(),k.emit()}),()=>{l.current.delete(c),a.current.delete(c),t.current.filtered.items.delete(c);let w=K();x(4,()=>{le(),(w==null?void 0:w.getAttribute("id"))===c&&z(),k.emit()})}),group:c=>(o.current.has(c)||o.current.set(c,new Set),()=>{l.current.delete(c),o.current.delete(c)}),filter:()=>i.current.shouldFilter,label:u||e["aria-label"],getDisablePointerSelection:()=>i.current.disablePointerSelection,listId:R,inputId:M,labelId:W,listInnerRef:N}),[]);function P(c,g){var w,b;let C=(b=(w=i.current)==null?void 0:w.filter)!=null?b:Dt;return c?C(c,t.current.search,g):0}function j(){if(!t.current.search||i.current.shouldFilter===!1)return;let c=t.current.filtered.items,g=[];t.current.filtered.groups.forEach(b=>{let C=o.current.get(b),E=0;C.forEach(D=>{let _=c.get(D);E=Math.max(_,E)}),g.push([b,E])});let w=N.current;ee().sort((b,C)=>{var E,D;let _=b.getAttribute("id"),ae=C.getAttribute("id");return((E=c.get(ae))!=null?E:0)-((D=c.get(_))!=null?D:0)}).forEach(b=>{let C=b.closest(ve);C?C.appendChild(b.parentElement===C?b:b.closest(`${ve} > *`)):w.appendChild(b.parentElement===w?b:b.closest(`${ve} > *`))}),g.sort((b,C)=>C[1]-b[1]).forEach(b=>{var C;let E=(C=N.current)==null?void 0:C.querySelector(`${te}[${G}="${encodeURIComponent(b[0])}"]`);E==null||E.parentElement.appendChild(E)})}function z(){let c=ee().find(w=>w.getAttribute("aria-disabled")!=="true"),g=c==null?void 0:c.getAttribute(G);k.setState("value",g||void 0)}function le(){var c,g,w,b;if(!t.current.search||i.current.shouldFilter===!1){t.current.filtered.count=a.current.size;return}t.current.filtered.groups=new Set;let C=0;for(let E of a.current){let D=(g=(c=l.current.get(E))==null?void 0:c.value)!=null?g:"",_=(b=(w=l.current.get(E))==null?void 0:w.keywords)!=null?b:[],ae=P(D,_);t.current.filtered.items.set(E,ae),ae>0&&C++}for(let[E,D]of o.current)for(let _ of D)if(t.current.filtered.items.get(_)>0){t.current.filtered.groups.add(E);break}t.current.filtered.count=C}function Pe(){var c,g,w;let b=K();b&&(((c=b.parentElement)==null?void 0:c.firstChild)===b&&((w=(g=b.closest(te))==null?void 0:g.querySelector(Lt))==null||w.scrollIntoView({block:"nearest"})),b.scrollIntoView({block:"nearest"}))}function K(){var c;return(c=N.current)==null?void 0:c.querySelector(`${He}[aria-selected="true"]`)}function ee(){var c;return Array.from(((c=N.current)==null?void 0:c.querySelectorAll(Le))||[])}function he(c){let g=ee()[c];g&&k.setState("value",g.getAttribute(G))}function me(c){var g;let w=K(),b=ee(),C=b.findIndex(D=>D===w),E=b[C+c];(g=i.current)!=null&&g.loop&&(E=C+c<0?b[b.length-1]:C+c===b.length?b[0]:b[C+c]),E&&k.setState("value",E.getAttribute(G))}function Ae(c){let g=K(),w=g==null?void 0:g.closest(te),b;for(;w&&!b;)w=c>0?$t(w,te):Vt(w,te),b=w==null?void 0:w.querySelector(Le);b?k.setState("value",b.getAttribute(G)):me(c)}let Ie=()=>he(ee().length-1),Te=c=>{c.preventDefault(),c.metaKey?Ie():c.altKey?Ae(1):me(1)},Ne=c=>{c.preventDefault(),c.metaKey?he(0):c.altKey?Ae(-1):me(-1)};return n.createElement(T.div,{ref:r,tabIndex:-1,...y,"cmdk-root":"",onKeyDown:c=>{var g;(g=y.onKeyDown)==null||g.call(y,c);let w=c.nativeEvent.isComposing||c.keyCode===229;if(!(c.defaultPrevented||w))switch(c.key){case"n":case"j":{A&&c.ctrlKey&&Te(c);break}case"ArrowDown":{Te(c);break}case"p":case"k":{A&&c.ctrlKey&&Ne(c);break}case"ArrowUp":{Ne(c);break}case"Home":{c.preventDefault(),he(0);break}case"End":{c.preventDefault(),Ie();break}case"Enter":{c.preventDefault();let b=K();if(b){let C=new Event(we);b.dispatchEvent(C)}}}}},n.createElement("label",{"cmdk-label":"",htmlFor:X.inputId,id:X.labelId,style:qt},u),ie(e,c=>n.createElement(ze.Provider,{value:k},n.createElement(We.Provider,{value:X},c))))}),Mt=n.forwardRef((e,r)=>{var t,a;let o=Q(),l=n.useRef(null),s=n.useContext(Be),i=oe(),u=Xe(e),d=(a=(t=u.current)==null?void 0:t.forceMount)!=null?a:s==null?void 0:s.forceMount;q(()=>{if(!d)return i.item(o,s==null?void 0:s.id)},[d]);let f=$e(o,l,[e.value,e.children,l],e.keywords),h=Se(),m=V(x=>x.value&&x.value===f.current),v=V(x=>d||i.filter()===!1?!0:x.search?x.filtered.items.get(o)>0:!0);n.useEffect(()=>{let x=l.current;if(!(!x||e.disabled))return x.addEventListener(we,S),()=>x.removeEventListener(we,S)},[v,e.onSelect,e.disabled]);function S(){var x,k;I(),(k=(x=u.current).onSelect)==null||k.call(x,f.current)}function I(){h.setState("value",f.current,!0)}if(!v)return null;let{disabled:A,value:y,onSelect:R,forceMount:W,keywords:M,...N}=e;return n.createElement(T.div,{ref:re(l,r),...N,id:o,"cmdk-item":"",role:"option","aria-disabled":!!A,"aria-selected":!!m,"data-disabled":!!A,"data-selected":!!m,onPointerMove:A||i.getDisablePointerSelection()?void 0:I,onClick:A?void 0:S},e.children)}),Ot=n.forwardRef((e,r)=>{let{heading:t,children:a,forceMount:o,...l}=e,s=Q(),i=n.useRef(null),u=n.useRef(null),d=Q(),f=oe(),h=V(v=>o||f.filter()===!1?!0:v.search?v.filtered.groups.has(s):!0);q(()=>f.group(s),[]),$e(s,i,[e.value,e.heading,u]);let m=n.useMemo(()=>({id:s,forceMount:o}),[o]);return n.createElement(T.div,{ref:re(i,r),...l,"cmdk-group":"",role:"presentation",hidden:h?void 0:!0},t&&n.createElement("div",{ref:u,"cmdk-group-heading":"","aria-hidden":!0,id:d},t),ie(e,v=>n.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":t?d:void 0},n.createElement(Be.Provider,{value:m},v))))}),Ht=n.forwardRef((e,r)=>{let{alwaysRender:t,...a}=e,o=n.useRef(null),l=V(s=>!s.search);return!t&&!l?null:n.createElement(T.div,{ref:re(o,r),...a,"cmdk-separator":"",role:"separator"})}),Wt=n.forwardRef((e,r)=>{let{onValueChange:t,...a}=e,o=e.value!=null,l=Se(),s=V(d=>d.search),i=V(d=>d.selectedItemId),u=oe();return n.useEffect(()=>{e.value!=null&&l.setState("search",e.value)},[e.value]),n.createElement(T.input,{ref:r,...a,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":u.listId,"aria-labelledby":u.labelId,"aria-activedescendant":i,id:u.inputId,type:"text",value:o?e.value:s,onChange:d=>{o||l.setState("search",d.target.value),t==null||t(d.target.value)}})}),zt=n.forwardRef((e,r)=>{let{children:t,label:a="Suggestions",...o}=e,l=n.useRef(null),s=n.useRef(null),i=V(d=>d.selectedItemId),u=oe();return n.useEffect(()=>{if(s.current&&l.current){let d=s.current,f=l.current,h,m=new ResizeObserver(()=>{h=requestAnimationFrame(()=>{let v=d.offsetHeight;f.style.setProperty("--cmdk-list-height",v.toFixed(1)+"px")})});return m.observe(d),()=>{cancelAnimationFrame(h),m.unobserve(d)}}},[]),n.createElement(T.div,{ref:re(l,r),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":i,"aria-label":a,id:u.listId},ie(e,d=>n.createElement("div",{ref:re(s,u.listInnerRef),"cmdk-list-sizer":""},d)))}),Bt=n.forwardRef((e,r)=>{let{open:t,onOpenChange:a,overlayClassName:o,contentClassName:l,container:s,...i}=e;return n.createElement(ft,{open:t,onOpenChange:a},n.createElement(ht,{container:s},n.createElement(mt,{"cmdk-overlay":"",className:o}),n.createElement(pt,{"aria-label":e.label,"cmdk-dialog":"",className:l},n.createElement(Fe,{ref:r,...i}))))}),Ft=n.forwardRef((e,r)=>V(t=>t.filtered.count===0)?n.createElement(T.div,{ref:r,...e,"cmdk-empty":"",role:"presentation"}):null),Xt=n.forwardRef((e,r)=>{let{progress:t,children:a,label:o="Loading...",...l}=e;return n.createElement(T.div,{ref:r,...l,"cmdk-loading":"",role:"progressbar","aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},ie(e,s=>n.createElement("div",{"aria-hidden":!0},s)))}),L=Object.assign(Fe,{List:zt,Item:Mt,Input:Wt,Group:Ot,Separator:Ht,Dialog:Bt,Empty:Ft,Loading:Xt});function $t(e,r){let t=e.nextElementSibling;for(;t;){if(t.matches(r))return t;t=t.nextElementSibling}}function Vt(e,r){let t=e.previousElementSibling;for(;t;){if(t.matches(r))return t;t=t.previousElementSibling}}function Xe(e){let r=n.useRef(e);return q(()=>{r.current=e}),r}var q=typeof window>"u"?n.useEffect:n.useLayoutEffect;function J(e){let r=n.useRef();return r.current===void 0&&(r.current=e()),r}function V(e){let r=Se(),t=()=>e(r.snapshot());return n.useSyncExternalStore(r.subscribe,t,t)}function $e(e,r,t,a=[]){let o=n.useRef(),l=oe();return q(()=>{var s;let i=(()=>{var d;for(let f of t){if(typeof f=="string")return f.trim();if(typeof f=="object"&&"current"in f)return f.current?(d=f.current.textContent)==null?void 0:d.trim():o.current}})(),u=a.map(d=>d.trim());l.value(e,i,u),(s=r.current)==null||s.setAttribute(G,i),o.current=i}),o}var Ut=()=>{let[e,r]=n.useState(),t=J(()=>new Map);return q(()=>{t.current.forEach(a=>a()),t.current=new Map},[e]),(a,o)=>{t.current.set(a,o),r({})}};function Yt(e){let r=e.type;return typeof r=="function"?r(e.props):"render"in r?r.render(e.props):e}function ie({asChild:e,children:r},t){return e&&n.isValidElement(r)?n.cloneElement(Yt(r),{ref:r.ref},t(r.props.children)):t(r)}var qt={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const Kt=n.forwardRef(({className:e,...r},t)=>p.jsx(L,{ref:t,className:H("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...r}));Kt.displayName=L.displayName;const Gt=n.forwardRef(({className:e,...r},t)=>p.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[p.jsx(bt,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),p.jsx(L.Input,{ref:t,className:H("flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...r})]}));Gt.displayName=L.Input.displayName;const Jt=n.forwardRef(({className:e,...r},t)=>p.jsx(L.List,{ref:t,className:H("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...r}));Jt.displayName=L.List.displayName;const Qt=n.forwardRef((e,r)=>p.jsx(L.Empty,{ref:r,className:"py-6 text-center text-sm",...e}));Qt.displayName=L.Empty.displayName;const Zt=n.forwardRef(({className:e,...r},t)=>p.jsx(L.Group,{ref:t,className:H("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",e),...r}));Zt.displayName=L.Group.displayName;const er=n.forwardRef(({className:e,...r},t)=>p.jsx(L.Separator,{ref:t,className:H("-mx-1 h-px bg-border",e),...r}));er.displayName=L.Separator.displayName;const tr=n.forwardRef(({className:e,...r},t)=>p.jsx(L.Item,{ref:t,className:H("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",e),...r}));tr.displayName=L.Item.displayName;var de="Checkbox",[rr]=Me(de),[nr,xe]=rr(de);function or(e){const{__scopeCheckbox:r,checked:t,children:a,defaultChecked:o,disabled:l,form:s,name:i,onCheckedChange:u,required:d,value:f="on",internal_do_not_use_render:h}=e,[m,v]=vt({prop:t,defaultProp:o??!1,onChange:u,caller:de}),[S,I]=n.useState(null),[A,y]=n.useState(null),R=n.useRef(!1),W=S?!!s||!!S.closest("form"):!0,M={checked:m,disabled:l,setChecked:v,control:S,setControl:I,name:i,form:s,value:f,hasConsumerStoppedPropagationRef:R,required:d,defaultChecked:$(o)?!1:o,isFormControl:W,bubbleInput:A,setBubbleInput:y};return p.jsx(nr,{scope:r,...M,children:lr(h)?h(M):a})}var Ve="CheckboxTrigger",Ue=n.forwardRef(({__scopeCheckbox:e,onKeyDown:r,onClick:t,...a},o)=>{const{control:l,value:s,disabled:i,checked:u,required:d,setControl:f,setChecked:h,hasConsumerStoppedPropagationRef:m,isFormControl:v,bubbleInput:S}=xe(Ve,e),I=U(o,f),A=n.useRef(u);return n.useEffect(()=>{const y=l==null?void 0:l.form;if(y){const R=()=>h(A.current);return y.addEventListener("reset",R),()=>y.removeEventListener("reset",R)}},[l,h]),p.jsx(T.button,{type:"button",role:"checkbox","aria-checked":$(u)?"mixed":u,"aria-required":d,"data-state":Je(u),"data-disabled":i?"":void 0,disabled:i,value:s,...a,ref:I,onKeyDown:F(r,y=>{y.key==="Enter"&&y.preventDefault()}),onClick:F(t,y=>{h(R=>$(R)?!0:!R),S&&v&&(m.current=y.isPropagationStopped(),m.current||y.stopPropagation())})})});Ue.displayName=Ve;var Ce=n.forwardRef((e,r)=>{const{__scopeCheckbox:t,name:a,checked:o,defaultChecked:l,required:s,disabled:i,value:u,onCheckedChange:d,form:f,...h}=e;return p.jsx(or,{__scopeCheckbox:t,checked:o,defaultChecked:l,disabled:i,required:s,onCheckedChange:d,name:a,form:f,value:u,internal_do_not_use_render:({isFormControl:m})=>p.jsxs(p.Fragment,{children:[p.jsx(Ue,{...h,ref:r,__scopeCheckbox:t}),m&&p.jsx(Ge,{__scopeCheckbox:t})]})})});Ce.displayName=de;var Ye="CheckboxIndicator",qe=n.forwardRef((e,r)=>{const{__scopeCheckbox:t,forceMount:a,...o}=e,l=xe(Ye,t);return p.jsx(ne,{present:a||$(l.checked)||l.checked===!0,children:p.jsx(T.span,{"data-state":Je(l.checked),"data-disabled":l.disabled?"":void 0,...o,ref:r,style:{pointerEvents:"none",...e.style}})})});qe.displayName=Ye;var Ke="CheckboxBubbleInput",Ge=n.forwardRef(({__scopeCheckbox:e,...r},t)=>{const{control:a,hasConsumerStoppedPropagationRef:o,checked:l,defaultChecked:s,required:i,disabled:u,name:d,value:f,form:h,bubbleInput:m,setBubbleInput:v}=xe(Ke,e),S=U(t,v),I=gt(l),A=wt(a);n.useEffect(()=>{const R=m;if(!R)return;const W=window.HTMLInputElement.prototype,N=Object.getOwnPropertyDescriptor(W,"checked").set,x=!o.current;if(I!==l&&N){const k=new Event("click",{bubbles:x});R.indeterminate=$(l),N.call(R,$(l)?!1:l),R.dispatchEvent(k)}},[m,I,l,o]);const y=n.useRef($(l)?!1:l);return p.jsx(T.input,{type:"checkbox","aria-hidden":!0,defaultChecked:s??y.current,required:i,disabled:u,name:d,value:f,form:h,...r,tabIndex:-1,ref:S,style:{...r.style,...A,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});Ge.displayName=Ke;function lr(e){return typeof e=="function"}function $(e){return e==="indeterminate"}function Je(e){return $(e)?"indeterminate":e?"checked":"unchecked"}const ar=n.forwardRef(({className:e,...r},t)=>p.jsx(Ce,{ref:t,className:H("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",e),...r,children:p.jsx(qe,{className:H("flex items-center justify-center text-current"),children:p.jsx(St,{className:"h-4 w-4"})})}));ar.displayName=Ce.displayName;function sr(e,r){return n.useReducer((t,a)=>r[t][a]??t,e)}var ye="ScrollArea",[Qe]=Me(ye),[cr,O]=Qe(ye),Ze=n.forwardRef((e,r)=>{const{__scopeScrollArea:t,type:a="hover",dir:o,scrollHideDelay:l=600,...s}=e,[i,u]=n.useState(null),[d,f]=n.useState(null),[h,m]=n.useState(null),[v,S]=n.useState(null),[I,A]=n.useState(null),[y,R]=n.useState(0),[W,M]=n.useState(0),[N,x]=n.useState(!1),[k,X]=n.useState(!1),P=U(r,z=>u(z)),j=xt(o);return p.jsx(cr,{scope:t,type:a,dir:j,scrollHideDelay:l,scrollArea:i,viewport:d,onViewportChange:f,content:h,onContentChange:m,scrollbarX:v,onScrollbarXChange:S,scrollbarXEnabled:N,onScrollbarXEnabledChange:x,scrollbarY:I,onScrollbarYChange:A,scrollbarYEnabled:k,onScrollbarYEnabledChange:X,onCornerWidthChange:R,onCornerHeightChange:M,children:p.jsx(T.div,{dir:j,...s,ref:P,style:{position:"relative","--radix-scroll-area-corner-width":y+"px","--radix-scroll-area-corner-height":W+"px",...e.style}})})});Ze.displayName=ye;var et="ScrollAreaViewport",tt=n.forwardRef((e,r)=>{const{__scopeScrollArea:t,children:a,nonce:o,...l}=e,s=O(et,t),i=n.useRef(null),u=U(r,i,s.onViewportChange);return p.jsxs(p.Fragment,{children:[p.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),p.jsx(T.div,{"data-radix-scroll-area-viewport":"",...l,ref:u,style:{overflowX:s.scrollbarXEnabled?"scroll":"hidden",overflowY:s.scrollbarYEnabled?"scroll":"hidden",...e.style},children:p.jsx("div",{ref:s.onContentChange,style:{minWidth:"100%",display:"table"},children:a})})]})});tt.displayName=et;var B="ScrollAreaScrollbar",Ee=n.forwardRef((e,r)=>{const{forceMount:t,...a}=e,o=O(B,e.__scopeScrollArea),{onScrollbarXEnabledChange:l,onScrollbarYEnabledChange:s}=o,i=e.orientation==="horizontal";return n.useEffect(()=>(i?l(!0):s(!0),()=>{i?l(!1):s(!1)}),[i,l,s]),o.type==="hover"?p.jsx(ir,{...a,ref:r,forceMount:t}):o.type==="scroll"?p.jsx(dr,{...a,ref:r,forceMount:t}):o.type==="auto"?p.jsx(rt,{...a,ref:r,forceMount:t}):o.type==="always"?p.jsx(Re,{...a,ref:r}):null});Ee.displayName=B;var ir=n.forwardRef((e,r)=>{const{forceMount:t,...a}=e,o=O(B,e.__scopeScrollArea),[l,s]=n.useState(!1);return n.useEffect(()=>{const i=o.scrollArea;let u=0;if(i){const d=()=>{window.clearTimeout(u),s(!0)},f=()=>{u=window.setTimeout(()=>s(!1),o.scrollHideDelay)};return i.addEventListener("pointerenter",d),i.addEventListener("pointerleave",f),()=>{window.clearTimeout(u),i.removeEventListener("pointerenter",d),i.removeEventListener("pointerleave",f)}}},[o.scrollArea,o.scrollHideDelay]),p.jsx(ne,{present:t||l,children:p.jsx(rt,{"data-state":l?"visible":"hidden",...a,ref:r})})}),dr=n.forwardRef((e,r)=>{const{forceMount:t,...a}=e,o=O(B,e.__scopeScrollArea),l=e.orientation==="horizontal",s=fe(()=>u("SCROLL_END"),100),[i,u]=sr("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return n.useEffect(()=>{if(i==="idle"){const d=window.setTimeout(()=>u("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(d)}},[i,o.scrollHideDelay,u]),n.useEffect(()=>{const d=o.viewport,f=l?"scrollLeft":"scrollTop";if(d){let h=d[f];const m=()=>{const v=d[f];h!==v&&(u("SCROLL"),s()),h=v};return d.addEventListener("scroll",m),()=>d.removeEventListener("scroll",m)}},[o.viewport,l,u,s]),p.jsx(ne,{present:t||i!=="hidden",children:p.jsx(Re,{"data-state":i==="hidden"?"hidden":"visible",...a,ref:r,onPointerEnter:F(e.onPointerEnter,()=>u("POINTER_ENTER")),onPointerLeave:F(e.onPointerLeave,()=>u("POINTER_LEAVE"))})})}),rt=n.forwardRef((e,r)=>{const t=O(B,e.__scopeScrollArea),{forceMount:a,...o}=e,[l,s]=n.useState(!1),i=e.orientation==="horizontal",u=fe(()=>{if(t.viewport){const d=t.viewport.offsetWidth<t.viewport.scrollWidth,f=t.viewport.offsetHeight<t.viewport.scrollHeight;s(i?d:f)}},10);return Z(t.viewport,u),Z(t.content,u),p.jsx(ne,{present:a||l,children:p.jsx(Re,{"data-state":l?"visible":"hidden",...o,ref:r})})}),Re=n.forwardRef((e,r)=>{const{orientation:t="vertical",...a}=e,o=O(B,e.__scopeScrollArea),l=n.useRef(null),s=n.useRef(0),[i,u]=n.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),d=st(i.viewport,i.content),f={...a,sizes:i,onSizesChange:u,hasThumb:d>0&&d<1,onThumbChange:m=>l.current=m,onThumbPointerUp:()=>s.current=0,onThumbPointerDown:m=>s.current=m};function h(m,v){return br(m,s.current,i,v)}return t==="horizontal"?p.jsx(ur,{...f,ref:r,onThumbPositionChange:()=>{if(o.viewport&&l.current){const m=o.viewport.scrollLeft,v=De(m,i,o.dir);l.current.style.transform=`translate3d(${v}px, 0, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollLeft=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollLeft=h(m,o.dir))}}):t==="vertical"?p.jsx(fr,{...f,ref:r,onThumbPositionChange:()=>{if(o.viewport&&l.current){const m=o.viewport.scrollTop,v=De(m,i);l.current.style.transform=`translate3d(0, ${v}px, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollTop=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollTop=h(m))}}):null}),ur=n.forwardRef((e,r)=>{const{sizes:t,onSizesChange:a,...o}=e,l=O(B,e.__scopeScrollArea),[s,i]=n.useState(),u=n.useRef(null),d=U(r,u,l.onScrollbarXChange);return n.useEffect(()=>{u.current&&i(getComputedStyle(u.current))},[u]),p.jsx(ot,{"data-orientation":"horizontal",...o,ref:d,sizes:t,style:{bottom:0,left:l.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:l.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":ue(t)+"px",...e.style},onThumbPointerDown:f=>e.onThumbPointerDown(f.x),onDragScroll:f=>e.onDragScroll(f.x),onWheelScroll:(f,h)=>{if(l.viewport){const m=l.viewport.scrollLeft+f.deltaX;e.onWheelScroll(m),it(m,h)&&f.preventDefault()}},onResize:()=>{u.current&&l.viewport&&s&&a({content:l.viewport.scrollWidth,viewport:l.viewport.offsetWidth,scrollbar:{size:u.current.clientWidth,paddingStart:ce(s.paddingLeft),paddingEnd:ce(s.paddingRight)}})}})}),fr=n.forwardRef((e,r)=>{const{sizes:t,onSizesChange:a,...o}=e,l=O(B,e.__scopeScrollArea),[s,i]=n.useState(),u=n.useRef(null),d=U(r,u,l.onScrollbarYChange);return n.useEffect(()=>{u.current&&i(getComputedStyle(u.current))},[u]),p.jsx(ot,{"data-orientation":"vertical",...o,ref:d,sizes:t,style:{top:0,right:l.dir==="ltr"?0:void 0,left:l.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":ue(t)+"px",...e.style},onThumbPointerDown:f=>e.onThumbPointerDown(f.y),onDragScroll:f=>e.onDragScroll(f.y),onWheelScroll:(f,h)=>{if(l.viewport){const m=l.viewport.scrollTop+f.deltaY;e.onWheelScroll(m),it(m,h)&&f.preventDefault()}},onResize:()=>{u.current&&l.viewport&&s&&a({content:l.viewport.scrollHeight,viewport:l.viewport.offsetHeight,scrollbar:{size:u.current.clientHeight,paddingStart:ce(s.paddingTop),paddingEnd:ce(s.paddingBottom)}})}})}),[hr,nt]=Qe(B),ot=n.forwardRef((e,r)=>{const{__scopeScrollArea:t,sizes:a,hasThumb:o,onThumbChange:l,onThumbPointerUp:s,onThumbPointerDown:i,onThumbPositionChange:u,onDragScroll:d,onWheelScroll:f,onResize:h,...m}=e,v=O(B,t),[S,I]=n.useState(null),A=U(r,P=>I(P)),y=n.useRef(null),R=n.useRef(""),W=v.viewport,M=a.content-a.viewport,N=Y(f),x=Y(u),k=fe(h,10);function X(P){if(y.current){const j=P.clientX-y.current.left,z=P.clientY-y.current.top;d({x:j,y:z})}}return n.useEffect(()=>{const P=j=>{const z=j.target;(S==null?void 0:S.contains(z))&&N(j,M)};return document.addEventListener("wheel",P,{passive:!1}),()=>document.removeEventListener("wheel",P,{passive:!1})},[W,S,M,N]),n.useEffect(x,[a,x]),Z(S,k),Z(v.content,k),p.jsx(hr,{scope:t,scrollbar:S,hasThumb:o,onThumbChange:Y(l),onThumbPointerUp:Y(s),onThumbPositionChange:x,onThumbPointerDown:Y(i),children:p.jsx(T.div,{...m,ref:A,style:{position:"absolute",...m.style},onPointerDown:F(e.onPointerDown,P=>{P.button===0&&(P.target.setPointerCapture(P.pointerId),y.current=S.getBoundingClientRect(),R.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",v.viewport&&(v.viewport.style.scrollBehavior="auto"),X(P))}),onPointerMove:F(e.onPointerMove,X),onPointerUp:F(e.onPointerUp,P=>{const j=P.target;j.hasPointerCapture(P.pointerId)&&j.releasePointerCapture(P.pointerId),document.body.style.webkitUserSelect=R.current,v.viewport&&(v.viewport.style.scrollBehavior=""),y.current=null})})})}),se="ScrollAreaThumb",lt=n.forwardRef((e,r)=>{const{forceMount:t,...a}=e,o=nt(se,e.__scopeScrollArea);return p.jsx(ne,{present:t||o.hasThumb,children:p.jsx(mr,{ref:r,...a})})}),mr=n.forwardRef((e,r)=>{const{__scopeScrollArea:t,style:a,...o}=e,l=O(se,t),s=nt(se,t),{onThumbPositionChange:i}=s,u=U(r,h=>s.onThumbChange(h)),d=n.useRef(void 0),f=fe(()=>{d.current&&(d.current(),d.current=void 0)},100);return n.useEffect(()=>{const h=l.viewport;if(h){const m=()=>{if(f(),!d.current){const v=vr(h,i);d.current=v,i()}};return i(),h.addEventListener("scroll",m),()=>h.removeEventListener("scroll",m)}},[l.viewport,f,i]),p.jsx(T.div,{"data-state":s.hasThumb?"visible":"hidden",...o,ref:u,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...a},onPointerDownCapture:F(e.onPointerDownCapture,h=>{const v=h.target.getBoundingClientRect(),S=h.clientX-v.left,I=h.clientY-v.top;s.onThumbPointerDown({x:S,y:I})}),onPointerUp:F(e.onPointerUp,s.onThumbPointerUp)})});lt.displayName=se;var ke="ScrollAreaCorner",at=n.forwardRef((e,r)=>{const t=O(ke,e.__scopeScrollArea),a=!!(t.scrollbarX&&t.scrollbarY);return t.type!=="scroll"&&a?p.jsx(pr,{...e,ref:r}):null});at.displayName=ke;var pr=n.forwardRef((e,r)=>{const{__scopeScrollArea:t,...a}=e,o=O(ke,t),[l,s]=n.useState(0),[i,u]=n.useState(0),d=!!(l&&i);return Z(o.scrollbarX,()=>{var h;const f=((h=o.scrollbarX)==null?void 0:h.offsetHeight)||0;o.onCornerHeightChange(f),u(f)}),Z(o.scrollbarY,()=>{var h;const f=((h=o.scrollbarY)==null?void 0:h.offsetWidth)||0;o.onCornerWidthChange(f),s(f)}),d?p.jsx(T.div,{...a,ref:r,style:{width:l,height:i,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function ce(e){return e?parseInt(e,10):0}function st(e,r){const t=e/r;return isNaN(t)?0:t}function ue(e){const r=st(e.viewport,e.content),t=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,a=(e.scrollbar.size-t)*r;return Math.max(a,18)}function br(e,r,t,a="ltr"){const o=ue(t),l=o/2,s=r||l,i=o-s,u=t.scrollbar.paddingStart+s,d=t.scrollbar.size-t.scrollbar.paddingEnd-i,f=t.content-t.viewport,h=a==="ltr"?[0,f]:[f*-1,0];return ct([u,d],h)(e)}function De(e,r,t="ltr"){const a=ue(r),o=r.scrollbar.paddingStart+r.scrollbar.paddingEnd,l=r.scrollbar.size-o,s=r.content-r.viewport,i=l-a,u=t==="ltr"?[0,s]:[s*-1,0],d=yt(e,u);return ct([0,s],[0,i])(d)}function ct(e,r){return t=>{if(e[0]===e[1]||r[0]===r[1])return r[0];const a=(r[1]-r[0])/(e[1]-e[0]);return r[0]+a*(t-e[0])}}function it(e,r){return e>0&&e<r}var vr=(e,r=()=>{})=>{let t={left:e.scrollLeft,top:e.scrollTop},a=0;return(function o(){const l={left:e.scrollLeft,top:e.scrollTop},s=t.left!==l.left,i=t.top!==l.top;(s||i)&&r(),t=l,a=window.requestAnimationFrame(o)})(),()=>window.cancelAnimationFrame(a)};function fe(e,r){const t=Y(e),a=n.useRef(0);return n.useEffect(()=>()=>window.clearTimeout(a.current),[]),n.useCallback(()=>{window.clearTimeout(a.current),a.current=window.setTimeout(t,r)},[t,r])}function Z(e,r){const t=Y(r);Ct(()=>{let a=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(a),a=window.requestAnimationFrame(t)});return o.observe(e),()=>{window.cancelAnimationFrame(a),o.unobserve(e)}}},[e,t])}var dt=Ze,gr=tt,wr=at;const Sr=n.forwardRef(({className:e,children:r,...t},a)=>p.jsxs(dt,{ref:a,className:H("relative overflow-hidden",e),...t,children:[p.jsx(gr,{className:"h-full w-full rounded-[inherit] [&>div]:!block [&>div]:!min-w-0",children:r}),p.jsx(ut,{}),p.jsx(wr,{})]}));Sr.displayName=dt.displayName;const ut=n.forwardRef(({className:e,orientation:r="vertical",...t},a)=>p.jsx(Ee,{ref:a,orientation:r,className:H("flex touch-none select-none transition-colors",r==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",r==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...t,children:p.jsx(lt,{className:"relative flex-1 rounded-full bg-border"})}));ut.displayName=Ee.displayName;export{Kt as C,Sr as S,Et as T,Gt as a,Jt as b,Qt as c,Zt as d,tr as e,ar as f};