@decocms/mesh 2.38.2 → 2.38.4

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 (137) hide show
  1. package/dist/client/assets/{AlertCircle-z3xwiUwg.js → AlertCircle-B4xqDHbG.js} +1 -1
  2. package/dist/client/assets/{ArrowLeft-BkoJglZy.js → ArrowLeft-BlDPaWrc.js} +1 -1
  3. package/dist/client/assets/{ArrowUp-BAMBJKzk.js → ArrowUp-CLiwYXs0.js} +1 -1
  4. package/dist/client/assets/{Check-BK9-0hKa.js → Check-CCn5GCwg.js} +1 -1
  5. package/dist/client/assets/{ChevronDown-PIP2u0bO.js → ChevronDown-YbVVQVLg.js} +1 -1
  6. package/dist/client/assets/{Code01-Bur40qHc.js → Code01-Dir622wi.js} +1 -1
  7. package/dist/client/assets/{Copy01-BOhF0ZEB.js → Copy01-CjY-NlSc.js} +1 -1
  8. package/dist/client/assets/{CpuChip02-BTAUjBs1.js → CpuChip02-yUWdNp1P.js} +1 -1
  9. package/dist/client/assets/{DotsHorizontal-DxGrUc9a.js → DotsHorizontal-Do1LS6Wx.js} +1 -1
  10. package/dist/client/assets/{DotsVertical-D61roAg3.js → DotsVertical-Dp-gx6mF.js} +1 -1
  11. package/dist/client/assets/{Download01-DH0bL3Nt.js → Download01-DAAiXVpc.js} +1 -1
  12. package/dist/client/assets/{Edit01-DINJ246_.js → Edit01-B_nUJxlr.js} +1 -1
  13. package/dist/client/assets/{File06-DVkrNas0.js → File06-CB-q8MUQ.js} +1 -1
  14. package/dist/client/assets/{FilterLines-so_Nzmiv.js → FilterLines-Br-acHX0.js} +1 -1
  15. package/dist/client/assets/{FlipBackward-iQ8t51Yv.js → FlipBackward-Cj4V50Wu.js} +1 -1
  16. package/dist/client/assets/{GitBranch01-T4MUtqYK.js → GitBranch01-zw_VkZBZ.js} +1 -1
  17. package/dist/client/assets/{Grid01-CN_8958k.js → Grid01-CPA-Um40.js} +1 -1
  18. package/dist/client/assets/{Home02-DuEnlN2j.js → Home02-DoAoQwmo.js} +1 -1
  19. package/dist/client/assets/{Image01-CAZIUcM5.js → Image01-CNk-r4qX.js} +1 -1
  20. package/dist/client/assets/{Inbox01-CM3kHNUT.js → Inbox01-By8bLcOc.js} +1 -1
  21. package/dist/client/assets/{InfoCircle-yeMjcoma.js → InfoCircle-B0FNzXlM.js} +1 -1
  22. package/dist/client/assets/{Key01-9yBwokED.js → Key01-B_LfAqq6.js} +1 -1
  23. package/dist/client/assets/{LinkExternal01-DVQPzyFK.js → LinkExternal01-s2DQaDMZ.js} +1 -1
  24. package/dist/client/assets/{List-BuWxjuK8.js → List-d67v1RYc.js} +1 -1
  25. package/dist/client/assets/{Loading01-D1yLQLik.js → Loading01-Da3G3uHv.js} +1 -1
  26. package/dist/client/assets/{Lock01-RqyglEYd.js → Lock01-mht9NTxx.js} +1 -1
  27. package/dist/client/assets/{Play-DVdw4qV-.js → Play-LyI9ODLq.js} +1 -1
  28. package/dist/client/assets/{Plus-Je-soon7.js → Plus-C8Yk0Byt.js} +1 -1
  29. package/dist/client/assets/{SearchMd-CbtolPap.js → SearchMd-DFqFsfr3.js} +1 -1
  30. package/dist/client/assets/{Terminal-DYGeKWvi.js → Terminal-sjkm0kJR.js} +1 -1
  31. package/dist/client/assets/{Trash01-CZvA_s0Y.js → Trash01-DsqSsyPF.js} +1 -1
  32. package/dist/client/assets/{Upload01-DhaDMFFD.js → Upload01-D0gUGV2F.js} +1 -1
  33. package/dist/client/assets/{X-sxVQmAsr.js → X-8Mftq7jS.js} +1 -1
  34. package/dist/client/assets/{XClose-zzu-jidq.js → XClose-CM1uqjVP.js} +1 -1
  35. package/dist/client/assets/{agent-detail-BlRpinmR.js → agent-detail-BbRahLm7.js} +1 -1
  36. package/dist/client/assets/{agents-DknJreAQ.js → agents-CO51KXQ7.js} +1 -1
  37. package/dist/client/assets/{alert-dialog-CVkwkecf.js → alert-dialog-CP6Si-sS.js} +1 -1
  38. package/dist/client/assets/{auth-catchall-w4I8mOfz.js → auth-catchall-iqpKi7T9.js} +1 -1
  39. package/dist/client/assets/{avatar-C9tVSVlv.js → avatar-qY1FecOi.js} +1 -1
  40. package/dist/client/assets/{badge-C7J4I2Hj.js → badge-DfcjklCU.js} +1 -1
  41. package/dist/client/assets/{binder-CbjhFDGc.js → binder-oimq46F2.js} +1 -1
  42. package/dist/client/assets/{button-CceSuFKi.js → button-CEYz4vVv.js} +1 -1
  43. package/dist/client/assets/{card-BGHb8OmC.js → card-Czj8cnsu.js} +1 -1
  44. package/dist/client/assets/{checkbox-Cu04V43g.js → checkbox-YBwSx7EQ.js} +1 -1
  45. package/dist/client/assets/{collection-detail-D2oIsKq-.js → collection-detail-CCz5bSND.js} +1 -1
  46. package/dist/client/assets/{collection-display-button-Df_9WgFb.js → collection-display-button-DnLs8bVk.js} +1 -1
  47. package/dist/client/assets/{collection-header-COgMCOx8.js → collection-header-BKBivTdh.js} +1 -1
  48. package/dist/client/assets/{collection-page-DVakSZpa.js → collection-page-BQnr3vxz.js} +1 -1
  49. package/dist/client/assets/{collection-search-Fe3W5Myr.js → collection-search-BtYrCrPa.js} +1 -1
  50. package/dist/client/assets/collection-tab-B7nFFfRR.js +1 -0
  51. package/dist/client/assets/{collection-table-wrapper-VkF3O5dC.js → collection-table-wrapper-qsmwllrX.js} +1 -1
  52. package/dist/client/assets/{connection-card-Bq9AH0T5.js → connection-card-BmrG8yB6.js} +1 -1
  53. package/dist/client/assets/{connection-detail-CbrkwDLO.js → connection-detail-DrwBqwII.js} +1 -1
  54. package/dist/client/assets/{connections-unSJ25xy.js → connections-EyHBeVDZ.js} +1 -1
  55. package/dist/client/assets/{constants-DqnLzZpL.js → constants-C56YODyA.js} +1 -1
  56. package/dist/client/assets/constants-DFc-Xc3W.js +1 -0
  57. package/dist/client/assets/{create-organization-dialog-DCA75BPi.js → create-organization-dialog-BP-zgBpE.js} +1 -1
  58. package/dist/client/assets/{dialog-CL6M-Xmi.js → dialog-Cur3bgyn.js} +1 -1
  59. package/dist/client/assets/{dropdown-menu-BMu3zBVo.js → dropdown-menu-DRvXtcX1.js} +1 -1
  60. package/dist/client/assets/{dynamic-plugin-layout-CKzehx9R.js → dynamic-plugin-layout-Cd-NaU-8.js} +1 -1
  61. package/dist/client/assets/{empty-state-BHdJzPJs.js → empty-state-B52GWMyA.js} +1 -1
  62. package/dist/client/assets/{empty-state-B0xeJKH5.js → empty-state-D96Y5HBy.js} +1 -1
  63. package/dist/client/assets/{env-vars-editor-CtvDpSON.js → env-vars-editor-BvlIX34u.js} +1 -1
  64. package/dist/client/assets/{error-boundary-vgLVbtql.js → error-boundary-B-AbkEzN.js} +1 -1
  65. package/dist/client/assets/{extract-connection-data-w2VKbBVM.js → extract-connection-data-xYQXXnta.js} +1 -1
  66. package/dist/client/assets/{file-browser-C_o-XRN_.js → file-browser-BM3fdjJP.js} +2 -2
  67. package/dist/client/assets/{form-DWBp_92q.js → form-BuxG1-zn.js} +1 -1
  68. package/dist/client/assets/{grid-view-D4uG2rz_.js → grid-view-x-p3DL4O.js} +1 -1
  69. package/dist/client/assets/{home-tcH3yRYZ.js → home-C9y8ew9m.js} +1 -1
  70. package/dist/client/assets/{index-BfBspZNA.js → index-B1uX_6ZJ.js} +3 -3
  71. package/dist/client/assets/{index-CQ6L3uZi.js → index-B7TTLamD.js} +1 -1
  72. package/dist/client/assets/{index-CUpy3pKS.js → index-BaKebp2o.js} +1 -1
  73. package/dist/client/assets/{index-DimTMp-G.js → index-BqaxN2xC.js} +2 -2
  74. package/dist/client/assets/index-DNsNPBek.js +1 -0
  75. package/dist/client/assets/{index-D4QmV-sc.js → index-DZba6oBj.js} +1 -1
  76. package/dist/client/assets/{infiniteQueryObserver-DeWE7Mv6.js → infiniteQueryObserver-93EeshRP.js} +1 -1
  77. package/dist/client/assets/{input-BzZt5UMQ.js → input-lyCEJ-v7.js} +1 -1
  78. package/dist/client/assets/{layout-DqvUpliw.js → layout-D-OU3f8P.js} +1 -1
  79. package/dist/client/assets/{localstorage-keys-Pb1bSOSH.js → localstorage-keys-ONdhlVrj.js} +1 -1
  80. package/dist/client/assets/{login-Bw3mNwou.js → login-uVCvvt_Q.js} +1 -1
  81. package/dist/client/assets/{mcp-oauth-DVTAVhIy.js → mcp-oauth-Cf6g90Vj.js} +1 -1
  82. package/dist/client/assets/{mcp-server-card-BOsrfsoy.js → mcp-server-card-DHP36XTl.js} +1 -1
  83. package/dist/client/assets/{mcp-server-detail-DL4a0l-I.js → mcp-server-detail-C0U713uq.js} +2 -2
  84. package/dist/client/assets/members-DyA8e--q.js +3 -0
  85. package/dist/client/assets/{monaco-editor-C3l8YLnM.js → monaco-editor-DGUxTU96.js} +1 -1
  86. package/dist/client/assets/{monitoring-BXzU__Q2.js → monitoring-XFLd7M9_.js} +17 -17
  87. package/dist/client/assets/{oauth-callback-C29sykPI.js → oauth-callback-C6TgACkm.js} +1 -1
  88. package/dist/client/assets/{page-D9f3s0Zn.js → page-B_m9E6ic.js} +1 -1
  89. package/dist/client/assets/{page-DFTluz6T.js → page-D2nSeVmo.js} +4 -4
  90. package/dist/client/assets/{pin-to-sidebar-button-a3_Q5PIg.js → pin-to-sidebar-button-S58VyRdL.js} +1 -1
  91. package/dist/client/assets/{plugin-empty-state-gioOq0db.js → plugin-empty-state-DRyAVBqZ.js} +1 -1
  92. package/dist/client/assets/{plugin-header-OS_VhXuY.js → plugin-header-Or8ouB6a.js} +1 -1
  93. package/dist/client/assets/{plugins-6jaAX9OI.js → plugins-BfxCF9MV.js} +1 -1
  94. package/dist/client/assets/{popover-DCXtR4UV.js → popover-DJUBm9Y-.js} +1 -1
  95. package/dist/client/assets/{registry-utils-B1EtgBkU.js → registry-utils-Byyd88f7.js} +1 -1
  96. package/dist/client/assets/{resizable-C5jfRumR.js → resizable-R_MVWpDo.js} +1 -1
  97. package/dist/client/assets/{resource-tabs-BNBJ-3ue.js → resource-tabs-CXTSNkut.js} +1 -1
  98. package/dist/client/assets/{select-DVxy4dZt.js → select-DGKcOybq.js} +1 -1
  99. package/dist/client/assets/{settings-DlMrUAFl.js → settings-Co5ybzun.js} +1 -1
  100. package/dist/client/assets/{shell-layout-C02QmtDM.js → shell-layout-C3pBvx_P.js} +1 -1
  101. package/dist/client/assets/{spinner-BK_gptNQ.js → spinner-CwB0mUYA.js} +1 -1
  102. package/dist/client/assets/{switch-BEUY1ZkG.js → switch-LeZRc51C.js} +1 -1
  103. package/dist/client/assets/{textarea-Dok2BUMd.js → textarea-CphdD9q0.js} +1 -1
  104. package/dist/client/assets/{tool-set-selector-BPpD_gne.js → tool-set-selector-CRLNbs4C.js} +1 -1
  105. package/dist/client/assets/{tools-list-eucrhDw_.js → tools-list-BeRMZtG9.js} +1 -1
  106. package/dist/client/assets/{tooltip-BotDoy6T.js → tooltip-DzrZ9wCu.js} +1 -1
  107. package/dist/client/assets/{typewriter-title-C0AyXxMG.js → typewriter-title-yCfBZocB.js} +1 -1
  108. package/dist/client/assets/{use-binding-Dj1HVNst.js → use-binding-B4CdGd_R.js} +1 -1
  109. package/dist/client/assets/{use-collections-Vpvt2q4e.js → use-collections-oaTV6V1V.js} +1 -1
  110. package/dist/client/assets/use-connection-BC3zltzG.js +1 -0
  111. package/dist/client/assets/{use-create-virtual-mcp-Jf2xsGTe.js → use-create-virtual-mcp-Cj9oL1-p.js} +1 -1
  112. package/dist/client/assets/{use-list-state-Bzarl2oM.js → use-list-state-CUj2Pms0.js} +1 -1
  113. package/dist/client/assets/{use-members-BtNqo2oh.js → use-members-BxzdumcN.js} +1 -1
  114. package/dist/client/assets/{use-mobile-CcOC6HBd.js → use-mobile-BYgIoeGI.js} +1 -1
  115. package/dist/client/assets/use-organization-settings-DYLZDPKB.js +1 -0
  116. package/dist/client/assets/use-virtual-mcp-DsllWo9H.js +1 -0
  117. package/dist/client/assets/useInfiniteQuery-fnNpWW1Y.js +1 -0
  118. package/dist/client/assets/{useMutation-d4_WWA7-.js → useMutation-Cwf-gT4m.js} +1 -1
  119. package/dist/client/assets/useQuery-Czw6cUjK.js +1 -0
  120. package/dist/client/assets/{value-BHid2kuo.js → value-BcjHEbtF.js} +1 -1
  121. package/dist/client/assets/{view-mode-toggle-DhWV5fbM.js → view-mode-toggle-Ba3TLRo6.js} +1 -1
  122. package/dist/client/assets/{virtual-mcp-Dyh0Ag7o.js → virtual-mcp-CoYEAnoS.js} +1 -1
  123. package/dist/client/assets/{workflow-Bw7jESqY.js → workflow-7kcB8-gn.js} +1 -1
  124. package/dist/client/index.html +1 -1
  125. package/dist/server/cli.js +142 -142
  126. package/dist/server/migrate.js +112 -112
  127. package/dist/server/server.js +127 -127
  128. package/package.json +1 -1
  129. package/dist/client/assets/collection-tab-_C4vj95J.js +0 -1
  130. package/dist/client/assets/constants-CrS7edVE.js +0 -1
  131. package/dist/client/assets/index-D1MpJYf1.js +0 -1
  132. package/dist/client/assets/members-CaWwLwBY.js +0 -3
  133. package/dist/client/assets/use-connection-DTjI_RtQ.js +0 -1
  134. package/dist/client/assets/use-organization-settings-CwiS3zFY.js +0 -1
  135. package/dist/client/assets/use-virtual-mcp-hN6G5B_j.js +0 -1
  136. package/dist/client/assets/useInfiniteQuery-B-B7Ix7h.js +0 -1
  137. package/dist/client/assets/useQuery-BMYUlGUP.js +0 -1
@@ -1 +1 @@
1
- import{c as f,j as s,d as I,r as C,b2 as F,e as E,E as O,a0 as w}from"./index-DimTMp-G.js";import{C as k}from"./card-BGHb8OmC.js";import{c as y,B as $}from"./button-CceSuFKi.js";import{A as R}from"./avatar-C9tVSVlv.js";import{i as D}from"./AlertCircle-z3xwiUwg.js";import{i as H}from"./Check-BK9-0hKa.js";import{s as G}from"./Plus-Je-soon7.js";import{i as Q}from"./SearchMd-CbtolPap.js";import{s as q}from"./XClose-zzu-jidq.js";import{I as B}from"./input-BzZt5UMQ.js";import{C as T}from"./create-organization-dialog-DCA75BPi.js";import"./alert-dialog-CVkwkecf.js";import"./form-DWBp_92q.js";import"./spinner-BK_gptNQ.js";import"./useMutation-d4_WWA7-.js";function U(t){const e=f.c(10),{children:n,className:l,onNavigate:i,showHoverRing:r}=t,d=r===void 0?!1:r;let o;e[0]!==i?(o=p=>{i&&i(p)},e[0]=i,e[1]=o):o=e[1];const m=o,x=i&&"cursor-pointer",a=d&&"hover:ring-2 hover:ring-primary";let c;e[2]!==l||e[3]!==x||e[4]!==a?(c=y("group transition-all flex flex-col gap-0",x,a,l),e[2]=l,e[3]=x,e[4]=a,e[5]=c):c=e[5];let g;return e[6]!==n||e[7]!==m||e[8]!==c?(g=s.jsx(k,{className:c,onClick:m,children:n}),e[6]=n,e[7]=m,e[8]=c,e[9]=g):g=e[9],g}function M(t){const e=f.c(7),{url:n,fallback:l,shape:i,size:r,objectFit:d,className:o}=t,m=i===void 0?"square":i,x=r===void 0?"lg":r,a=d===void 0?"contain":d;let c;return e[0]!==o||e[1]!==l||e[2]!==a||e[3]!==m||e[4]!==x||e[5]!==n?(c=s.jsx(R,{url:n,fallback:l,shape:m,size:x,objectFit:a,className:o}),e[0]=o,e[1]=l,e[2]=a,e[3]=m,e[4]=x,e[5]=n,e[6]=c):c=e[6],c}function P(t){const e=f.c(5),{children:n,className:l}=t;let i;e[0]!==l?(i=y("p-4 flex flex-col gap-4",l),e[0]=l,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("div",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r}function V(t){const e=f.c(5),{children:n,className:l}=t;let i;e[0]!==l?(i=y("font-medium truncate",l),e[0]=l,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("p",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r}function X(t){const e=f.c(5),{children:n,className:l}=t;let i;e[0]!==l?(i=y("text-sm text-muted-foreground truncate",l),e[0]=l,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("h3",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r}function Y(t){const e=f.c(5),{children:n,className:l}=t;let i;e[0]!==l?(i=y("flex flex-col gap-[2px]",l),e[0]=l,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("div",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r}function J(t){const e=f.c(5),{children:n,className:l}=t;let i;e[0]!==l?(i=y("flex justify-between items-start",l),e[0]=l,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("div",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r}function K(t){const e=f.c(5),{children:n,className:l}=t;let i;e[0]!==l?(i=y("p-4 border-t border-border flex justify-between items-center",l),e[0]=l,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("div",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r}function W(t){const e=f.c(5),{children:n,className:l}=t;let i;e[0]!==l?(i=y("flex items-center text-xs text-muted-foreground",l),e[0]=l,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("div",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r}function Z(){const t=f.c(3);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"flex justify-between items-start",children:s.jsx("div",{className:"h-12 w-12 bg-muted rounded-lg animate-pulse"})}),t[0]=e):e=t[0];let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsxs("div",{className:"p-4 flex flex-col gap-4",children:[e,s.jsxs("div",{className:"flex flex-col gap-[2px]",children:[s.jsx("div",{className:"h-4 w-32 bg-muted rounded-lg animate-pulse"}),s.jsx("div",{className:"h-4 w-40 bg-muted rounded-lg animate-pulse"})]})]}),t[1]=n):n=t[1];let l;return t[2]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsxs(k,{className:"group transition-colors flex flex-col",children:[n,s.jsxs("div",{className:"p-4 border-t border-border flex justify-between items-center",children:[s.jsx("div",{className:"h-6 w-6 bg-muted rounded-full animate-pulse"}),s.jsx("div",{className:"h-6 w-6 bg-muted rounded-full animate-pulse -ml-2"})]})]}),t[2]=l):l=t[2],l}const u=Object.assign(U,{Avatar:M,AvatarSection:J,Header:P,Title:V,Subtitle:X,Content:Y,Footer:K,Badge:W,Skeleton:Z}),ee={0:"gap-0",1:"gap-1",2:"gap-2",3:"gap-3",4:"gap-4",5:"gap-5",6:"gap-6",8:"gap-8"},te={1:"grid-cols-1",2:"grid-cols-2",3:"grid-cols-3",4:"grid-cols-4",5:"grid-cols-5",6:"grid-cols-6",7:"grid-cols-7",8:"grid-cols-8"},se={1:"@min-3xl:grid-cols-1",2:"@min-3xl:grid-cols-2",3:"@min-3xl:grid-cols-3",4:"@min-3xl:grid-cols-4",5:"@min-3xl:grid-cols-5",6:"@min-3xl:grid-cols-6",7:"@min-3xl:grid-cols-7",8:"@min-3xl:grid-cols-8"},ie={1:"@min-6xl:grid-cols-1",2:"@min-6xl:grid-cols-2",3:"@min-6xl:grid-cols-3",4:"@min-6xl:grid-cols-4",5:"@min-6xl:grid-cols-5",6:"@min-6xl:grid-cols-6",7:"@min-6xl:grid-cols-7",8:"@min-6xl:grid-cols-8"},le={1:"@min-7xl:grid-cols-1",2:"@min-7xl:grid-cols-2",3:"@min-7xl:grid-cols-3",4:"@min-7xl:grid-cols-4",5:"@min-7xl:grid-cols-5",6:"@min-7xl:grid-cols-6",7:"@min-7xl:grid-cols-7",8:"@min-7xl:grid-cols-8"},ne={1:"@min-8xl:grid-cols-1",2:"@min-8xl:grid-cols-2",3:"@min-8xl:grid-cols-3",4:"@min-8xl:grid-cols-4",5:"@min-8xl:grid-cols-5",6:"@min-8xl:grid-cols-6",7:"@min-8xl:grid-cols-7",8:"@min-8xl:grid-cols-8"};function L(t){const e=f.c(13),{children:n,columns:l,gap:i,className:r}=t;let d;e[0]!==l?(d=l===void 0?{sm:2,md:3,lg:4}:l,e[0]=l,e[1]=d):d=e[1];const o=d,x=ee[i===void 0?4:i],a=o.sm&&te[o.sm],c=o.md&&se[o.md],g=o.lg&&ie[o.lg],p=o.xl&&le[o.xl],v=o["2xl"]&&ne[o["2xl"]];let N;e[2]!==r||e[3]!==x||e[4]!==a||e[5]!==c||e[6]!==g||e[7]!==p||e[8]!==v?(N=y("w-full grid",x,a,c,g,p,v,r),e[2]=r,e[3]=x,e[4]=a,e[5]=c,e[6]=g,e[7]=p,e[8]=v,e[9]=N):N=e[9];const b=N;let h;return e[10]!==n||e[11]!==b?(h=s.jsx("div",{className:b,children:n}),e[10]=n,e[11]=b,e[12]=h):h=e[12],h}function re(t){const e=f.c(9),{count:n,columns:l,gap:i,className:r}=t,d=n===void 0?8:n;let o;e[0]!==l?(o=l===void 0?{sm:2,md:3,lg:4}:l,e[0]=l,e[1]=o):o=e[1];const m=o,x=i===void 0?4:i;let a;e[2]!==d?(a=Array.from({length:d}).map(ae),e[2]=d,e[3]=a):a=e[3];let c;return e[4]!==r||e[5]!==m||e[6]!==x||e[7]!==a?(c=s.jsx(L,{columns:m,gap:x,className:r,children:a}),e[4]=r,e[5]=m,e[6]=x,e[7]=a,e[8]=c):c=e[8],c}function ae(t,e){return s.jsxs("div",{className:"bg-card hover:bg-accent transition-colors flex flex-col rounded-lg animate-pulse",children:[s.jsxs("div",{className:"p-4 flex flex-col gap-4",children:[s.jsx("div",{className:"h-12 w-12 bg-muted rounded-lg"}),s.jsx("div",{className:"h-4 w-32 bg-muted rounded-lg"}),s.jsx("div",{className:"h-4 w-32 bg-muted rounded-lg"})]}),s.jsxs("div",{className:"p-4 border-t border-border flex items-center",children:[s.jsx("div",{className:"h-6 w-6 bg-muted rounded-full animate-pulse"}),s.jsx("div",{className:"h-6 w-6 bg-muted rounded-full animate-pulse -ml-2"}),s.jsx("div",{className:"h-6 w-6 bg-muted rounded-full animate-pulse -ml-2"})]})]},e)}const A=Object.assign(L,{Skeleton:re});function oe({invitation:t}){const[e,n]=C.useState(!1),[l,i]=C.useState(!1),r=O(),d=E(),o=async()=>{n(!0);try{const a=await I.organization.acceptInvitation({invitationId:t.id});if(a.error)w.error(a.error.message),n(!1);else{const c=await I.organization.setActive({organizationId:t.organizationId});c?.data?.slug?(w.success("Invitation accepted!"),d({to:"/$org",params:{org:c.data.slug}})):(w.success("Invitation accepted! Redirecting..."),d({to:"/"}))}}catch{w.error("Failed to accept invitation"),n(!1)}},m=async()=>{i(!0);try{const a=await I.organization.rejectInvitation({invitationId:t.id});a.error?(w.error(a.error.message),i(!1)):(w.success("Invitation rejected"),await r.invalidateQueries(),i(!1))}catch{w.error("Failed to reject invitation"),i(!1)}},x=t.organizationName||t.organizationId;return s.jsxs(u,{className:"border-dashed",children:[s.jsxs(u.Header,{children:[s.jsx(u.AvatarSection,{children:s.jsx(u.Avatar,{url:"",fallback:x,size:"lg",objectFit:"contain"})}),s.jsxs(u.Content,{children:[s.jsx(u.Subtitle,{children:"You've been invited to join"}),s.jsx(u.Title,{children:x})]})]}),s.jsx(u.Footer,{className:"border-t border-dashed",children:s.jsxs("div",{className:"flex h-3.5 items-center gap-2 w-full",children:[s.jsx($,{onClick:o,disabled:e||l,className:"flex-1",size:"sm",children:e?"Accepting...":s.jsxs(s.Fragment,{children:[s.jsx(H,{size:16}),"Accept"]})}),s.jsx($,{variant:"outline",onClick:m,disabled:e||l,className:"flex-1",size:"sm",children:l?"Declining...":s.jsxs(s.Fragment,{children:[s.jsx(q,{size:16}),"Decline"]})})]})})]})}function ce({query:t}){const e=C.useContext(F),{data:n}=e.hooks.useListUserInvitations(),i=(n??[]).filter(d=>d.status==="pending"&&new Date(d.expiresAt)>new Date),r=t?(()=>{const d=t.toLowerCase();return i.filter(o=>o.organizationName?.toLowerCase().includes(d)||o.organizationId.toLowerCase().includes(d))})():i;return r.length===0?null:s.jsxs("div",{className:"mb-16",children:[s.jsx("h2",{className:"text-lg font-medium pb-2 border-b border-border/50 mb-6 px-2",children:"Invitations"}),s.jsx(A,{columns:{sm:2,md:3,lg:4},children:r.map(d=>s.jsx(oe,{invitation:d},d.id))})]})}function de(t){const e=f.c(14),{query:n}=t,{data:l}=I.useListOrganizations(),i=E();let r;e[0]!==l||e[1]!==n?(r=l?n?(()=>{const a=n.toLowerCase();return l.filter(c=>c.name.toLowerCase().includes(a)||c.slug.toLowerCase().includes(a))})():l:[],e[0]=l,e[1]=n,e[2]=r):r=e[2];const d=r;if(!l||l.length===0){let a;return e[3]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:s.jsx("div",{className:"text-sm text-muted-foreground text-center",children:"No organizations yet. Create your first organization to get started."})}),e[3]=a):a=e[3],a}if(d.length===0){let a;return e[4]!==n?(a=s.jsx("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:s.jsxs("div",{className:"text-sm text-muted-foreground text-center",children:['No organizations found matching "',n,'".']})}),e[4]=n,e[5]=a):a=e[5],a}let o;e[6]===Symbol.for("react.memo_cache_sentinel")?(o={sm:2,md:3,lg:4},e[6]=o):o=e[6];let m;if(e[7]!==d||e[8]!==i){let a;e[10]!==i?(a=c=>s.jsxs(u,{onNavigate:()=>i({to:"/$org",params:{org:c.slug}}),children:[s.jsxs(u.Header,{children:[s.jsx(u.AvatarSection,{children:s.jsx(u.Avatar,{url:c.logo||"",fallback:c.name,size:"lg",objectFit:"contain"})}),s.jsxs(u.Content,{children:[s.jsxs(u.Subtitle,{children:["@",c.slug]}),s.jsx(u.Title,{children:c.name})]})]}),s.jsx(u.Footer,{children:s.jsxs("div",{className:"flex h-3.5 items-center text-xs text-muted-foreground",children:["Created:"," ",new Date(c.createdAt).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})]})})]},c.id),e[10]=i,e[11]=a):a=e[11],m=d.map(a),e[7]=d,e[8]=i,e[9]=m}else m=e[9];let x;return e[12]!==m?(x=s.jsx(A,{columns:o,children:m}),e[12]=m,e[13]=x):x=e[13],x}function me(t){const e=f.c(3),{error:n}=t;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx(D,{size:24,className:"text-destructive"}),e[0]=l):l=e[0];let i;return e[1]!==n.message?(i=s.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[l,s.jsxs("div",{className:"text-sm text-muted-foreground text-center",children:["Error loading organizations: ",n.message]})]}),e[1]=n.message,e[2]=i):i=e[2],i}function xe(){const t=f.c(27),{error:e,isPending:n}=I.useListOrganizations(),[l,i]=C.useState(""),[r,d]=C.useState(!1),o=C.useDeferredValue(l);if(n){let j;return t[0]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx("div",{className:"max-w-6xl mx-auto p-8",children:s.jsx("div",{className:"@container",children:s.jsx(A.Skeleton,{count:8,columns:{sm:2,md:3,lg:4}})})}),t[0]=j):j=t[0],j}if(e){let j;return t[1]!==e?(j=s.jsx("div",{className:"max-w-6xl mx-auto p-8",children:s.jsx(me,{error:e})}),t[1]=e,t[2]=j):j=t[2],j}let m;t[3]!==o?(m=s.jsx(C.Suspense,{fallback:null,children:s.jsx(ce,{query:o})}),t[3]=o,t[4]=m):m=t[4];let x;t[5]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx("h2",{className:"text-lg font-medium",children:"My organizations"}),t[5]=x):x=t[5];let a;t[6]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(Q,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground"}),t[6]=a):a=t[6];let c;t[7]===Symbol.for("react.memo_cache_sentinel")?(c=j=>i(j.target.value),t[7]=c):c=t[7];let g;t[8]!==l?(g=s.jsxs("div",{className:"relative",children:[a,s.jsx(B,{className:"pl-8 h-8 w-52 border-none shadow-none focus-visible:ring-0",placeholder:"Search organizations...",value:l,onChange:c})]}),t[8]=l,t[9]=g):g=t[9];let p;t[10]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsxs($,{size:"sm",onClick:()=>d(!0),children:[s.jsx(G,{size:16}),s.jsx("span",{children:"New organization"})]}),t[10]=p):p=t[10];let v;t[11]!==g?(v=s.jsxs("div",{className:"flex items-center justify-between pb-2 border-b border-border/50 mb-6 px-2",children:[x,s.jsxs("div",{className:"flex items-center gap-3",children:[g,p]})]}),t[11]=g,t[12]=v):v=t[12];let N;t[13]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(A.Skeleton,{count:8,columns:{sm:2,md:3,lg:4}}),t[13]=N):N=t[13];let b;t[14]!==o?(b=s.jsx(C.Suspense,{fallback:N,children:s.jsx(de,{query:o})}),t[14]=o,t[15]=b):b=t[15];let h;t[16]!==v||t[17]!==b?(h=s.jsxs("div",{children:[v,b]}),t[16]=v,t[17]=b,t[18]=h):h=t[18];let S;t[19]!==m||t[20]!==h?(S=s.jsxs("div",{className:"@container",children:[m,h]}),t[19]=m,t[20]=h,t[21]=S):S=t[21];let z;t[22]!==r?(z=s.jsx(T,{open:r,onOpenChange:d}),t[22]=r,t[23]=z):z=t[23];let _;return t[24]!==S||t[25]!==z?(_=s.jsxs("div",{className:"max-w-6xl mx-auto p-8",children:[S,z]}),t[24]=S,t[25]=z,t[26]=_):_=t[26],_}function _e(){const t=f.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"min-h-full",children:s.jsx(xe,{})}),t[0]=e):e=t[0],e}export{_e as default};
1
+ import{c as f,j as s,d as I,r as C,b2 as F,e as E,E as O,a0 as w}from"./index-BqaxN2xC.js";import{C as k}from"./card-Czj8cnsu.js";import{c as y,B as $}from"./button-CEYz4vVv.js";import{A as R}from"./avatar-qY1FecOi.js";import{i as D}from"./AlertCircle-B4xqDHbG.js";import{i as H}from"./Check-CCn5GCwg.js";import{s as G}from"./Plus-C8Yk0Byt.js";import{i as Q}from"./SearchMd-DFqFsfr3.js";import{s as q}from"./XClose-CM1uqjVP.js";import{I as B}from"./input-lyCEJ-v7.js";import{C as T}from"./create-organization-dialog-BP-zgBpE.js";import"./alert-dialog-CP6Si-sS.js";import"./form-BuxG1-zn.js";import"./spinner-CwB0mUYA.js";import"./useMutation-Cwf-gT4m.js";function U(t){const e=f.c(10),{children:n,className:l,onNavigate:i,showHoverRing:r}=t,d=r===void 0?!1:r;let o;e[0]!==i?(o=p=>{i&&i(p)},e[0]=i,e[1]=o):o=e[1];const m=o,x=i&&"cursor-pointer",a=d&&"hover:ring-2 hover:ring-primary";let c;e[2]!==l||e[3]!==x||e[4]!==a?(c=y("group transition-all flex flex-col gap-0",x,a,l),e[2]=l,e[3]=x,e[4]=a,e[5]=c):c=e[5];let g;return e[6]!==n||e[7]!==m||e[8]!==c?(g=s.jsx(k,{className:c,onClick:m,children:n}),e[6]=n,e[7]=m,e[8]=c,e[9]=g):g=e[9],g}function M(t){const e=f.c(7),{url:n,fallback:l,shape:i,size:r,objectFit:d,className:o}=t,m=i===void 0?"square":i,x=r===void 0?"lg":r,a=d===void 0?"contain":d;let c;return e[0]!==o||e[1]!==l||e[2]!==a||e[3]!==m||e[4]!==x||e[5]!==n?(c=s.jsx(R,{url:n,fallback:l,shape:m,size:x,objectFit:a,className:o}),e[0]=o,e[1]=l,e[2]=a,e[3]=m,e[4]=x,e[5]=n,e[6]=c):c=e[6],c}function P(t){const e=f.c(5),{children:n,className:l}=t;let i;e[0]!==l?(i=y("p-4 flex flex-col gap-4",l),e[0]=l,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("div",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r}function V(t){const e=f.c(5),{children:n,className:l}=t;let i;e[0]!==l?(i=y("font-medium truncate",l),e[0]=l,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("p",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r}function X(t){const e=f.c(5),{children:n,className:l}=t;let i;e[0]!==l?(i=y("text-sm text-muted-foreground truncate",l),e[0]=l,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("h3",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r}function Y(t){const e=f.c(5),{children:n,className:l}=t;let i;e[0]!==l?(i=y("flex flex-col gap-[2px]",l),e[0]=l,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("div",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r}function J(t){const e=f.c(5),{children:n,className:l}=t;let i;e[0]!==l?(i=y("flex justify-between items-start",l),e[0]=l,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("div",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r}function K(t){const e=f.c(5),{children:n,className:l}=t;let i;e[0]!==l?(i=y("p-4 border-t border-border flex justify-between items-center",l),e[0]=l,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("div",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r}function W(t){const e=f.c(5),{children:n,className:l}=t;let i;e[0]!==l?(i=y("flex items-center text-xs text-muted-foreground",l),e[0]=l,e[1]=i):i=e[1];let r;return e[2]!==n||e[3]!==i?(r=s.jsx("div",{className:i,children:n}),e[2]=n,e[3]=i,e[4]=r):r=e[4],r}function Z(){const t=f.c(3);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"flex justify-between items-start",children:s.jsx("div",{className:"h-12 w-12 bg-muted rounded-lg animate-pulse"})}),t[0]=e):e=t[0];let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsxs("div",{className:"p-4 flex flex-col gap-4",children:[e,s.jsxs("div",{className:"flex flex-col gap-[2px]",children:[s.jsx("div",{className:"h-4 w-32 bg-muted rounded-lg animate-pulse"}),s.jsx("div",{className:"h-4 w-40 bg-muted rounded-lg animate-pulse"})]})]}),t[1]=n):n=t[1];let l;return t[2]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsxs(k,{className:"group transition-colors flex flex-col",children:[n,s.jsxs("div",{className:"p-4 border-t border-border flex justify-between items-center",children:[s.jsx("div",{className:"h-6 w-6 bg-muted rounded-full animate-pulse"}),s.jsx("div",{className:"h-6 w-6 bg-muted rounded-full animate-pulse -ml-2"})]})]}),t[2]=l):l=t[2],l}const u=Object.assign(U,{Avatar:M,AvatarSection:J,Header:P,Title:V,Subtitle:X,Content:Y,Footer:K,Badge:W,Skeleton:Z}),ee={0:"gap-0",1:"gap-1",2:"gap-2",3:"gap-3",4:"gap-4",5:"gap-5",6:"gap-6",8:"gap-8"},te={1:"grid-cols-1",2:"grid-cols-2",3:"grid-cols-3",4:"grid-cols-4",5:"grid-cols-5",6:"grid-cols-6",7:"grid-cols-7",8:"grid-cols-8"},se={1:"@min-3xl:grid-cols-1",2:"@min-3xl:grid-cols-2",3:"@min-3xl:grid-cols-3",4:"@min-3xl:grid-cols-4",5:"@min-3xl:grid-cols-5",6:"@min-3xl:grid-cols-6",7:"@min-3xl:grid-cols-7",8:"@min-3xl:grid-cols-8"},ie={1:"@min-6xl:grid-cols-1",2:"@min-6xl:grid-cols-2",3:"@min-6xl:grid-cols-3",4:"@min-6xl:grid-cols-4",5:"@min-6xl:grid-cols-5",6:"@min-6xl:grid-cols-6",7:"@min-6xl:grid-cols-7",8:"@min-6xl:grid-cols-8"},le={1:"@min-7xl:grid-cols-1",2:"@min-7xl:grid-cols-2",3:"@min-7xl:grid-cols-3",4:"@min-7xl:grid-cols-4",5:"@min-7xl:grid-cols-5",6:"@min-7xl:grid-cols-6",7:"@min-7xl:grid-cols-7",8:"@min-7xl:grid-cols-8"},ne={1:"@min-8xl:grid-cols-1",2:"@min-8xl:grid-cols-2",3:"@min-8xl:grid-cols-3",4:"@min-8xl:grid-cols-4",5:"@min-8xl:grid-cols-5",6:"@min-8xl:grid-cols-6",7:"@min-8xl:grid-cols-7",8:"@min-8xl:grid-cols-8"};function L(t){const e=f.c(13),{children:n,columns:l,gap:i,className:r}=t;let d;e[0]!==l?(d=l===void 0?{sm:2,md:3,lg:4}:l,e[0]=l,e[1]=d):d=e[1];const o=d,x=ee[i===void 0?4:i],a=o.sm&&te[o.sm],c=o.md&&se[o.md],g=o.lg&&ie[o.lg],p=o.xl&&le[o.xl],v=o["2xl"]&&ne[o["2xl"]];let N;e[2]!==r||e[3]!==x||e[4]!==a||e[5]!==c||e[6]!==g||e[7]!==p||e[8]!==v?(N=y("w-full grid",x,a,c,g,p,v,r),e[2]=r,e[3]=x,e[4]=a,e[5]=c,e[6]=g,e[7]=p,e[8]=v,e[9]=N):N=e[9];const b=N;let h;return e[10]!==n||e[11]!==b?(h=s.jsx("div",{className:b,children:n}),e[10]=n,e[11]=b,e[12]=h):h=e[12],h}function re(t){const e=f.c(9),{count:n,columns:l,gap:i,className:r}=t,d=n===void 0?8:n;let o;e[0]!==l?(o=l===void 0?{sm:2,md:3,lg:4}:l,e[0]=l,e[1]=o):o=e[1];const m=o,x=i===void 0?4:i;let a;e[2]!==d?(a=Array.from({length:d}).map(ae),e[2]=d,e[3]=a):a=e[3];let c;return e[4]!==r||e[5]!==m||e[6]!==x||e[7]!==a?(c=s.jsx(L,{columns:m,gap:x,className:r,children:a}),e[4]=r,e[5]=m,e[6]=x,e[7]=a,e[8]=c):c=e[8],c}function ae(t,e){return s.jsxs("div",{className:"bg-card hover:bg-accent transition-colors flex flex-col rounded-lg animate-pulse",children:[s.jsxs("div",{className:"p-4 flex flex-col gap-4",children:[s.jsx("div",{className:"h-12 w-12 bg-muted rounded-lg"}),s.jsx("div",{className:"h-4 w-32 bg-muted rounded-lg"}),s.jsx("div",{className:"h-4 w-32 bg-muted rounded-lg"})]}),s.jsxs("div",{className:"p-4 border-t border-border flex items-center",children:[s.jsx("div",{className:"h-6 w-6 bg-muted rounded-full animate-pulse"}),s.jsx("div",{className:"h-6 w-6 bg-muted rounded-full animate-pulse -ml-2"}),s.jsx("div",{className:"h-6 w-6 bg-muted rounded-full animate-pulse -ml-2"})]})]},e)}const A=Object.assign(L,{Skeleton:re});function oe({invitation:t}){const[e,n]=C.useState(!1),[l,i]=C.useState(!1),r=O(),d=E(),o=async()=>{n(!0);try{const a=await I.organization.acceptInvitation({invitationId:t.id});if(a.error)w.error(a.error.message),n(!1);else{const c=await I.organization.setActive({organizationId:t.organizationId});c?.data?.slug?(w.success("Invitation accepted!"),d({to:"/$org",params:{org:c.data.slug}})):(w.success("Invitation accepted! Redirecting..."),d({to:"/"}))}}catch{w.error("Failed to accept invitation"),n(!1)}},m=async()=>{i(!0);try{const a=await I.organization.rejectInvitation({invitationId:t.id});a.error?(w.error(a.error.message),i(!1)):(w.success("Invitation rejected"),await r.invalidateQueries(),i(!1))}catch{w.error("Failed to reject invitation"),i(!1)}},x=t.organizationName||t.organizationId;return s.jsxs(u,{className:"border-dashed",children:[s.jsxs(u.Header,{children:[s.jsx(u.AvatarSection,{children:s.jsx(u.Avatar,{url:"",fallback:x,size:"lg",objectFit:"contain"})}),s.jsxs(u.Content,{children:[s.jsx(u.Subtitle,{children:"You've been invited to join"}),s.jsx(u.Title,{children:x})]})]}),s.jsx(u.Footer,{className:"border-t border-dashed",children:s.jsxs("div",{className:"flex h-3.5 items-center gap-2 w-full",children:[s.jsx($,{onClick:o,disabled:e||l,className:"flex-1",size:"sm",children:e?"Accepting...":s.jsxs(s.Fragment,{children:[s.jsx(H,{size:16}),"Accept"]})}),s.jsx($,{variant:"outline",onClick:m,disabled:e||l,className:"flex-1",size:"sm",children:l?"Declining...":s.jsxs(s.Fragment,{children:[s.jsx(q,{size:16}),"Decline"]})})]})})]})}function ce({query:t}){const e=C.useContext(F),{data:n}=e.hooks.useListUserInvitations(),i=(n??[]).filter(d=>d.status==="pending"&&new Date(d.expiresAt)>new Date),r=t?(()=>{const d=t.toLowerCase();return i.filter(o=>o.organizationName?.toLowerCase().includes(d)||o.organizationId.toLowerCase().includes(d))})():i;return r.length===0?null:s.jsxs("div",{className:"mb-16",children:[s.jsx("h2",{className:"text-lg font-medium pb-2 border-b border-border/50 mb-6 px-2",children:"Invitations"}),s.jsx(A,{columns:{sm:2,md:3,lg:4},children:r.map(d=>s.jsx(oe,{invitation:d},d.id))})]})}function de(t){const e=f.c(14),{query:n}=t,{data:l}=I.useListOrganizations(),i=E();let r;e[0]!==l||e[1]!==n?(r=l?n?(()=>{const a=n.toLowerCase();return l.filter(c=>c.name.toLowerCase().includes(a)||c.slug.toLowerCase().includes(a))})():l:[],e[0]=l,e[1]=n,e[2]=r):r=e[2];const d=r;if(!l||l.length===0){let a;return e[3]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:s.jsx("div",{className:"text-sm text-muted-foreground text-center",children:"No organizations yet. Create your first organization to get started."})}),e[3]=a):a=e[3],a}if(d.length===0){let a;return e[4]!==n?(a=s.jsx("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:s.jsxs("div",{className:"text-sm text-muted-foreground text-center",children:['No organizations found matching "',n,'".']})}),e[4]=n,e[5]=a):a=e[5],a}let o;e[6]===Symbol.for("react.memo_cache_sentinel")?(o={sm:2,md:3,lg:4},e[6]=o):o=e[6];let m;if(e[7]!==d||e[8]!==i){let a;e[10]!==i?(a=c=>s.jsxs(u,{onNavigate:()=>i({to:"/$org",params:{org:c.slug}}),children:[s.jsxs(u.Header,{children:[s.jsx(u.AvatarSection,{children:s.jsx(u.Avatar,{url:c.logo||"",fallback:c.name,size:"lg",objectFit:"contain"})}),s.jsxs(u.Content,{children:[s.jsxs(u.Subtitle,{children:["@",c.slug]}),s.jsx(u.Title,{children:c.name})]})]}),s.jsx(u.Footer,{children:s.jsxs("div",{className:"flex h-3.5 items-center text-xs text-muted-foreground",children:["Created:"," ",new Date(c.createdAt).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})]})})]},c.id),e[10]=i,e[11]=a):a=e[11],m=d.map(a),e[7]=d,e[8]=i,e[9]=m}else m=e[9];let x;return e[12]!==m?(x=s.jsx(A,{columns:o,children:m}),e[12]=m,e[13]=x):x=e[13],x}function me(t){const e=f.c(3),{error:n}=t;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx(D,{size:24,className:"text-destructive"}),e[0]=l):l=e[0];let i;return e[1]!==n.message?(i=s.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[l,s.jsxs("div",{className:"text-sm text-muted-foreground text-center",children:["Error loading organizations: ",n.message]})]}),e[1]=n.message,e[2]=i):i=e[2],i}function xe(){const t=f.c(27),{error:e,isPending:n}=I.useListOrganizations(),[l,i]=C.useState(""),[r,d]=C.useState(!1),o=C.useDeferredValue(l);if(n){let j;return t[0]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx("div",{className:"max-w-6xl mx-auto p-8",children:s.jsx("div",{className:"@container",children:s.jsx(A.Skeleton,{count:8,columns:{sm:2,md:3,lg:4}})})}),t[0]=j):j=t[0],j}if(e){let j;return t[1]!==e?(j=s.jsx("div",{className:"max-w-6xl mx-auto p-8",children:s.jsx(me,{error:e})}),t[1]=e,t[2]=j):j=t[2],j}let m;t[3]!==o?(m=s.jsx(C.Suspense,{fallback:null,children:s.jsx(ce,{query:o})}),t[3]=o,t[4]=m):m=t[4];let x;t[5]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx("h2",{className:"text-lg font-medium",children:"My organizations"}),t[5]=x):x=t[5];let a;t[6]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(Q,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground"}),t[6]=a):a=t[6];let c;t[7]===Symbol.for("react.memo_cache_sentinel")?(c=j=>i(j.target.value),t[7]=c):c=t[7];let g;t[8]!==l?(g=s.jsxs("div",{className:"relative",children:[a,s.jsx(B,{className:"pl-8 h-8 w-52 border-none shadow-none focus-visible:ring-0",placeholder:"Search organizations...",value:l,onChange:c})]}),t[8]=l,t[9]=g):g=t[9];let p;t[10]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsxs($,{size:"sm",onClick:()=>d(!0),children:[s.jsx(G,{size:16}),s.jsx("span",{children:"New organization"})]}),t[10]=p):p=t[10];let v;t[11]!==g?(v=s.jsxs("div",{className:"flex items-center justify-between pb-2 border-b border-border/50 mb-6 px-2",children:[x,s.jsxs("div",{className:"flex items-center gap-3",children:[g,p]})]}),t[11]=g,t[12]=v):v=t[12];let N;t[13]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(A.Skeleton,{count:8,columns:{sm:2,md:3,lg:4}}),t[13]=N):N=t[13];let b;t[14]!==o?(b=s.jsx(C.Suspense,{fallback:N,children:s.jsx(de,{query:o})}),t[14]=o,t[15]=b):b=t[15];let h;t[16]!==v||t[17]!==b?(h=s.jsxs("div",{children:[v,b]}),t[16]=v,t[17]=b,t[18]=h):h=t[18];let S;t[19]!==m||t[20]!==h?(S=s.jsxs("div",{className:"@container",children:[m,h]}),t[19]=m,t[20]=h,t[21]=S):S=t[21];let z;t[22]!==r?(z=s.jsx(T,{open:r,onOpenChange:d}),t[22]=r,t[23]=z):z=t[23];let _;return t[24]!==S||t[25]!==z?(_=s.jsxs("div",{className:"max-w-6xl mx-auto p-8",children:[S,z]}),t[24]=S,t[25]=z,t[26]=_):_=t[26],_}function _e(){const t=f.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"min-h-full",children:s.jsx(xe,{})}),t[0]=e):e=t[0],e}export{_e as default};
@@ -1,4 +1,4 @@
1
- import{r as M,c as ne,j as S,bM as $O,bN as zO,t as jO,a5 as jt,s as ee,bO as io,bP as a_,bf as qO,bg as GO,bd as VO,a2 as Ot,a3 as Ma,h as rs,o as Oe,be as de,a4 as Zn,bQ as WO,bR as ze,_ as YO,bm as ul,i as s_,K as Hi,u as o_,E as Gg,a0 as un,d as l_,a as KO,b as XO,F as u_,bS as c_,bJ as ZO,br as Lt,bT as QO,bU as JO,aP as d_,bV as eL,bW as vn,bX as Xl,bY as tL,bZ as Zl,b_ as nL,b$ as rL,c0 as iL,c1 as aL,c2 as sL,c3 as oL,c4 as lL,c5 as uL,e as p_,bI as ao,aa as Vg,ab as cL,ad as dL,a6 as pL,a8 as fL,a9 as hL,b3 as mL,ai as gL}from"./index-DimTMp-G.js";import{c as me,B as gt}from"./button-CceSuFKi.js";import{i as bL}from"./X-sxVQmAsr.js";import{u as Gn}from"./virtual-mcp-Dyh0Ag7o.js";import{u as Qr,W as Wg,d as EL}from"./constants-DqnLzZpL.js";import{u as f_}from"./use-virtual-mcp-hN6G5B_j.js";import{a as yL}from"./use-collections-Vpvt2q4e.js";import{a as h_,u as TL}from"./use-connection-DTjI_RtQ.js";import{a as SL}from"./use-binding-Dj1HVNst.js";import{u as AL,M as m_,s as HE}from"./monaco-editor-C3l8YLnM.js";import{u as ma,L as so}from"./localstorage-keys-Pb1bSOSH.js";import{I as Yg}from"./input-BzZt5UMQ.js";import{a as is,b as as,P as ss}from"./popover-DCXtR4UV.js";import{S as kL,a as xL,b as vL,c as _L,d as CL}from"./select-DVxy4dZt.js";import{i as IL}from"./File06-DVkrNas0.js";import{c as NL,i as g_}from"./Grid01-CN_8958k.js";import{a as wL}from"./Image01-CAZIUcM5.js";import{i as cl}from"./SearchMd-CbtolPap.js";import{S as dl}from"./spinner-BK_gptNQ.js";import{c as Jr,T as ei,a as ti,b as Kg}from"./tooltip-BotDoy6T.js";import{useMCPPromptsList as RL,getPrompt as b_,listPrompts as $E,listResources as zE,readResource as OL}from"./index-D1MpJYf1.js";import{E as LL,i as DL}from"./error-boundary-vgLVbtql.js";import{c as ML,b as PL,e as FL,a as BL,D as UL}from"./dialog-CL6M-Xmi.js";import{a as HL,F as $L,b as zL,c as jL,d as qL,f as GL}from"./form-DWBp_92q.js";import{I as Xg,E as VL}from"./empty-state-B0xeJKH5.js";import{i as E_}from"./AlertCircle-z3xwiUwg.js";import{i as WL}from"./ArrowUp-BAMBJKzk.js";import{t as YL}from"./ChevronDown-PIP2u0bO.js";import{i as Zg}from"./CpuChip02-BTAUjBs1.js";import{i as KL}from"./Edit01-DINJ246_.js";import{i as pl}from"./Check-BK9-0hKa.js";import{a as Qg}from"./Copy01-BOhF0ZEB.js";import{i as XL}from"./Terminal-DYGeKWvi.js";import{g as ZL}from"./generate-id-Dyweu44Y.js";import{s as QL}from"./Trash01-CZvA_s0Y.js";import{u as JL}from"./use-create-virtual-mcp-Jf2xsGTe.js";import{s as e2}from"./Plus-Je-soon7.js";var Pa;(function(t){t.assertEqual=i=>{};function e(i){}t.assertIs=e;function n(i){throw new Error}t.assertNever=n,t.arrayToEnum=i=>{const a={};for(const s of i)a[s]=s;return a},t.getValidEnumValues=i=>{const a=t.objectKeys(i).filter(o=>typeof i[i[o]]!="number"),s={};for(const o of a)s[o]=i[o];return t.objectValues(s)},t.objectValues=i=>t.objectKeys(i).map(function(a){return i[a]}),t.objectKeys=typeof Object.keys=="function"?i=>Object.keys(i):i=>{const a=[];for(const s in i)Object.prototype.hasOwnProperty.call(i,s)&&a.push(s);return a},t.find=(i,a)=>{for(const s of i)if(a(s))return s},t.isInteger=typeof Number.isInteger=="function"?i=>Number.isInteger(i):i=>typeof i=="number"&&Number.isFinite(i)&&Math.floor(i)===i;function r(i,a=" | "){return i.map(s=>typeof s=="string"?`'${s}'`:s).join(a)}t.joinValues=r,t.jsonStringifyReplacer=(i,a)=>typeof a=="bigint"?a.toString():a})(Pa||(Pa={}));var jE;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(jE||(jE={}));Pa.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]);Pa.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class oo extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}format(e){const n=e||function(a){return a.message},r={_errors:[]},i=a=>{for(const s of a.issues)if(s.code==="invalid_union")s.unionErrors.map(i);else if(s.code==="invalid_return_type")i(s.returnTypeError);else if(s.code==="invalid_arguments")i(s.argumentsError);else if(s.path.length===0)r._errors.push(n(s));else{let o=r,l=0;for(;l<s.path.length;){const u=s.path[l];l===s.path.length-1?(o[u]=o[u]||{_errors:[]},o[u]._errors.push(n(s))):o[u]=o[u]||{_errors:[]},o=o[u],l++}}};return i(this),r}static assert(e){if(!(e instanceof oo))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,Pa.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){const n=Object.create(null),r=[];for(const i of this.issues)if(i.path.length>0){const a=i.path[0];n[a]=n[a]||[],n[a].push(e(i))}else r.push(e(i));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}oo.create=t=>new oo(t);var qE;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(qE||(qE={}));var ge;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(ge||(ge={}));const y_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"M17.115 15.358c-.27.306-.554.608-.851.905-4.296 4.296-9.678 5.88-12.021 3.536-1.607-1.606-1.368-4.641.325-7.775M6.89 8.725c.281-.32.578-.636.888-.947C12.074 3.482 17.456 1.9 19.8 4.243c1.608 1.607 1.367 4.645-.33 7.781m-3.206-4.246c4.296 4.296 5.88 9.678 3.536 12.021-2.343 2.343-7.725.76-12.02-3.535C3.483 11.968 1.9 6.586 4.244 4.243c2.343-2.343 7.725-.76 12.02 3.535ZM13 12a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"}));y_.displayName="Atom02";const T_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"m7 15 5 5 5-5M7 9l5-5 5 5"}));T_.displayName="ChevronSelectorVertical";const S_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"M15.938 15.938A7.001 7.001 0 0 0 15 2a7.001 7.001 0 0 0-6.938 6.062M16 15a7 7 0 1 1-14 0 7 7 0 0 1 14 0Z"}));S_.displayName="Coins01";const A_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"M6 16a4 4 0 0 0 4 4h4a4 4 0 0 0 0-8h-4a4 4 0 0 1 0-8h4a4 4 0 0 1 4 4m-6-6v20"}));A_.displayName="CurrencyDollar";const k_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"M15 16.5V19c0 .932 0 1.398-.152 1.765a2 2 0 0 1-1.083 1.083C13.398 22 12.932 22 12 22c-.932 0-1.398 0-1.765-.152a2 2 0 0 1-1.083-1.083C9 20.398 9 19.932 9 19v-2.5m6 0c2.649-1.157 4.5-3.925 4.5-7a7.5 7.5 0 0 0-15 0c0 3.075 1.851 5.843 4.5 7m6 0H9"}));k_.displayName="Lightbulb01";const x_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"m18 8 4 4m0 0-4 4m4-4H9m6-7.796A8.383 8.383 0 0 0 10.667 3C5.88 3 2 7.03 2 12s3.88 9 8.667 9A8.384 8.384 0 0 0 15 19.796"}));x_.displayName="LogOut04";const fl=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"m6.5 13 .784 1.569c.266.53.399.796.576 1.026a3 3 0 0 0 .545.545c.23.177.495.31 1.026.575L11 17.5l-1.569.785c-.53.265-.796.398-1.026.575a3 3 0 0 0-.545.545c-.177.23-.31.495-.576 1.026L6.5 22l-.784-1.569c-.266-.53-.399-.796-.576-1.026a3 3 0 0 0-.545-.545c-.23-.177-.495-.31-1.026-.575L2 17.5l1.569-.785c.53-.265.796-.398 1.026-.575a3 3 0 0 0 .545-.545c.177-.23.31-.495.576-1.026L6.5 13ZM15 2l1.179 3.064c.282.734.423 1.1.642 1.409a3 3 0 0 0 .706.706c.309.22.675.36 1.409.642L22 9l-3.064 1.179c-.734.282-1.1.423-1.409.642a3 3 0 0 0-.706.706c-.22.309-.36.675-.642 1.409L15 16l-1.179-3.064c-.282-.734-.423-1.1-.642-1.409a3 3 0 0 0-.706-.706c-.309-.22-.675-.36-1.409-.642L8 9l3.064-1.179c.734-.282 1.1-.423 1.409-.642a3 3 0 0 0 .706-.706c.22-.309.36-.675.642-1.409L15 2Z"}));fl.displayName="Stars01";const v_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"M3 7.8c0-1.68 0-2.52.327-3.162a3 3 0 0 1 1.311-1.311C5.28 3 6.12 3 7.8 3h8.4c1.68 0 2.52 0 3.162.327a3 3 0 0 1 1.311 1.311C21 5.28 21 6.12 21 7.8v8.4c0 1.68 0 2.52-.327 3.162a3 3 0 0 1-1.311 1.311C18.72 21 17.88 21 16.2 21H7.8c-1.68 0-2.52 0-3.162-.327a3 3 0 0 1-1.311-1.311C3 18.72 3 17.88 3 16.2V7.8Z"}));v_.displayName="Stop";const __=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"M16 8V5l3-3 1 2 2 1-3 3h-3Zm0 0-4 4m10 0c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2m5 10a5 5 0 1 1-5-5"}));__.displayName="Target04";const C_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"m15 9-6 6m0-6 6 6m7-3c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10Z"}));C_.displayName="XCircle";function yt(t){const e=ne.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let i;e[3]!==n?(i=me("bg-accent animate-pulse rounded-md",n),e[3]=n,e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=S.jsx("div",{"data-slot":"skeleton",className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a}function t2(){const t=ne.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=so.developerMode(),t[0]=e):e=t[0],ma(e,!1)}var I_="vercel.ai.error",n2=Symbol.for(I_),GE,VE,Cn=class N_ extends(VE=Error,GE=n2,VE){constructor({name:e,message:n,cause:r}){super(n),this[GE]=!0,this.name=e,this.cause=r}static isInstance(e){return N_.hasMarker(e,I_)}static hasMarker(e,n){const r=Symbol.for(n);return e!=null&&typeof e=="object"&&r in e&&typeof e[r]=="boolean"&&e[r]===!0}};function w_(t){return t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:JSON.stringify(t)}var R_="AI_InvalidArgumentError",O_=`vercel.ai.error.${R_}`,r2=Symbol.for(O_),WE,YE,i2=class extends(YE=Cn,WE=r2,YE){constructor({message:t,cause:e,argument:n}){super({name:R_,message:t,cause:e}),this[WE]=!0,this.argument=n}static isInstance(t){return Cn.hasMarker(t,O_)}},L_="AI_JSONParseError",D_=`vercel.ai.error.${L_}`,a2=Symbol.for(D_),KE,XE,ZE=class extends(XE=Cn,KE=a2,XE){constructor({text:t,cause:e}){super({name:L_,message:`JSON parsing failed: Text: ${t}.
1
+ import{r as M,c as ne,j as S,bM as $O,bN as zO,t as jO,a5 as jt,s as ee,bO as io,bP as a_,bf as qO,bg as GO,bd as VO,a2 as Ot,a3 as Ma,h as rs,o as Oe,be as de,a4 as Zn,bQ as WO,bR as ze,_ as YO,bm as ul,i as s_,K as Hi,u as o_,E as Gg,a0 as un,d as l_,a as KO,b as XO,F as u_,bS as c_,bJ as ZO,br as Lt,bT as QO,bU as JO,aP as d_,bV as eL,bW as vn,bX as Xl,bY as tL,bZ as Zl,b_ as nL,b$ as rL,c0 as iL,c1 as aL,c2 as sL,c3 as oL,c4 as lL,c5 as uL,e as p_,bI as ao,aa as Vg,ab as cL,ad as dL,a6 as pL,a8 as fL,a9 as hL,b3 as mL,ai as gL}from"./index-BqaxN2xC.js";import{c as me,B as gt}from"./button-CEYz4vVv.js";import{i as bL}from"./X-8Mftq7jS.js";import{u as Gn}from"./virtual-mcp-CoYEAnoS.js";import{u as Qr,S as Wg,d as EL}from"./constants-C56YODyA.js";import{u as f_}from"./use-virtual-mcp-DsllWo9H.js";import{a as yL}from"./use-collections-oaTV6V1V.js";import{a as h_,u as TL}from"./use-connection-BC3zltzG.js";import{a as SL}from"./use-binding-B4CdGd_R.js";import{u as AL,M as m_,s as HE}from"./monaco-editor-DGUxTU96.js";import{u as ma,L as so}from"./localstorage-keys-ONdhlVrj.js";import{I as Yg}from"./input-lyCEJ-v7.js";import{a as is,b as as,P as ss}from"./popover-DJUBm9Y-.js";import{S as kL,a as xL,b as vL,c as _L,d as CL}from"./select-DGKcOybq.js";import{i as IL}from"./File06-CB-q8MUQ.js";import{c as NL,i as g_}from"./Grid01-CPA-Um40.js";import{a as wL}from"./Image01-CNk-r4qX.js";import{i as cl}from"./SearchMd-DFqFsfr3.js";import{S as dl}from"./spinner-CwB0mUYA.js";import{c as Jr,T as ei,a as ti,b as Kg}from"./tooltip-DzrZ9wCu.js";import{useMCPPromptsList as RL,getPrompt as b_,listPrompts as $E,listResources as zE,readResource as OL}from"./index-DNsNPBek.js";import{E as LL,i as DL}from"./error-boundary-B-AbkEzN.js";import{c as ML,b as PL,e as FL,a as BL,D as UL}from"./dialog-Cur3bgyn.js";import{a as HL,F as $L,b as zL,c as jL,d as qL,f as GL}from"./form-BuxG1-zn.js";import{I as Xg,E as VL}from"./empty-state-D96Y5HBy.js";import{i as E_}from"./AlertCircle-B4xqDHbG.js";import{i as WL}from"./ArrowUp-CLiwYXs0.js";import{t as YL}from"./ChevronDown-YbVVQVLg.js";import{i as Zg}from"./CpuChip02-yUWdNp1P.js";import{i as KL}from"./Edit01-B_nUJxlr.js";import{i as pl}from"./Check-CCn5GCwg.js";import{a as Qg}from"./Copy01-CjY-NlSc.js";import{i as XL}from"./Terminal-sjkm0kJR.js";import{g as ZL}from"./generate-id-Dyweu44Y.js";import{s as QL}from"./Trash01-DsqSsyPF.js";import{u as JL}from"./use-create-virtual-mcp-Cj9oL1-p.js";import{s as e2}from"./Plus-C8Yk0Byt.js";var Pa;(function(t){t.assertEqual=i=>{};function e(i){}t.assertIs=e;function n(i){throw new Error}t.assertNever=n,t.arrayToEnum=i=>{const a={};for(const s of i)a[s]=s;return a},t.getValidEnumValues=i=>{const a=t.objectKeys(i).filter(o=>typeof i[i[o]]!="number"),s={};for(const o of a)s[o]=i[o];return t.objectValues(s)},t.objectValues=i=>t.objectKeys(i).map(function(a){return i[a]}),t.objectKeys=typeof Object.keys=="function"?i=>Object.keys(i):i=>{const a=[];for(const s in i)Object.prototype.hasOwnProperty.call(i,s)&&a.push(s);return a},t.find=(i,a)=>{for(const s of i)if(a(s))return s},t.isInteger=typeof Number.isInteger=="function"?i=>Number.isInteger(i):i=>typeof i=="number"&&Number.isFinite(i)&&Math.floor(i)===i;function r(i,a=" | "){return i.map(s=>typeof s=="string"?`'${s}'`:s).join(a)}t.joinValues=r,t.jsonStringifyReplacer=(i,a)=>typeof a=="bigint"?a.toString():a})(Pa||(Pa={}));var jE;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(jE||(jE={}));Pa.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]);Pa.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class oo extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}format(e){const n=e||function(a){return a.message},r={_errors:[]},i=a=>{for(const s of a.issues)if(s.code==="invalid_union")s.unionErrors.map(i);else if(s.code==="invalid_return_type")i(s.returnTypeError);else if(s.code==="invalid_arguments")i(s.argumentsError);else if(s.path.length===0)r._errors.push(n(s));else{let o=r,l=0;for(;l<s.path.length;){const u=s.path[l];l===s.path.length-1?(o[u]=o[u]||{_errors:[]},o[u]._errors.push(n(s))):o[u]=o[u]||{_errors:[]},o=o[u],l++}}};return i(this),r}static assert(e){if(!(e instanceof oo))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,Pa.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){const n=Object.create(null),r=[];for(const i of this.issues)if(i.path.length>0){const a=i.path[0];n[a]=n[a]||[],n[a].push(e(i))}else r.push(e(i));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}oo.create=t=>new oo(t);var qE;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(qE||(qE={}));var ge;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(ge||(ge={}));const y_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"M17.115 15.358c-.27.306-.554.608-.851.905-4.296 4.296-9.678 5.88-12.021 3.536-1.607-1.606-1.368-4.641.325-7.775M6.89 8.725c.281-.32.578-.636.888-.947C12.074 3.482 17.456 1.9 19.8 4.243c1.608 1.607 1.367 4.645-.33 7.781m-3.206-4.246c4.296 4.296 5.88 9.678 3.536 12.021-2.343 2.343-7.725.76-12.02-3.535C3.483 11.968 1.9 6.586 4.244 4.243c2.343-2.343 7.725-.76 12.02 3.535ZM13 12a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"}));y_.displayName="Atom02";const T_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"m7 15 5 5 5-5M7 9l5-5 5 5"}));T_.displayName="ChevronSelectorVertical";const S_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"M15.938 15.938A7.001 7.001 0 0 0 15 2a7.001 7.001 0 0 0-6.938 6.062M16 15a7 7 0 1 1-14 0 7 7 0 0 1 14 0Z"}));S_.displayName="Coins01";const A_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"M6 16a4 4 0 0 0 4 4h4a4 4 0 0 0 0-8h-4a4 4 0 0 1 0-8h4a4 4 0 0 1 4 4m-6-6v20"}));A_.displayName="CurrencyDollar";const k_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"M15 16.5V19c0 .932 0 1.398-.152 1.765a2 2 0 0 1-1.083 1.083C13.398 22 12.932 22 12 22c-.932 0-1.398 0-1.765-.152a2 2 0 0 1-1.083-1.083C9 20.398 9 19.932 9 19v-2.5m6 0c2.649-1.157 4.5-3.925 4.5-7a7.5 7.5 0 0 0-15 0c0 3.075 1.851 5.843 4.5 7m6 0H9"}));k_.displayName="Lightbulb01";const x_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"m18 8 4 4m0 0-4 4m4-4H9m6-7.796A8.383 8.383 0 0 0 10.667 3C5.88 3 2 7.03 2 12s3.88 9 8.667 9A8.384 8.384 0 0 0 15 19.796"}));x_.displayName="LogOut04";const fl=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"m6.5 13 .784 1.569c.266.53.399.796.576 1.026a3 3 0 0 0 .545.545c.23.177.495.31 1.026.575L11 17.5l-1.569.785c-.53.265-.796.398-1.026.575a3 3 0 0 0-.545.545c-.177.23-.31.495-.576 1.026L6.5 22l-.784-1.569c-.266-.53-.399-.796-.576-1.026a3 3 0 0 0-.545-.545c-.23-.177-.495-.31-1.026-.575L2 17.5l1.569-.785c.53-.265.796-.398 1.026-.575a3 3 0 0 0 .545-.545c.177-.23.31-.495.576-1.026L6.5 13ZM15 2l1.179 3.064c.282.734.423 1.1.642 1.409a3 3 0 0 0 .706.706c.309.22.675.36 1.409.642L22 9l-3.064 1.179c-.734.282-1.1.423-1.409.642a3 3 0 0 0-.706.706c-.22.309-.36.675-.642 1.409L15 16l-1.179-3.064c-.282-.734-.423-1.1-.642-1.409a3 3 0 0 0-.706-.706c-.309-.22-.675-.36-1.409-.642L8 9l3.064-1.179c.734-.282 1.1-.423 1.409-.642a3 3 0 0 0 .706-.706c.22-.309.36-.675.642-1.409L15 2Z"}));fl.displayName="Stars01";const v_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"M3 7.8c0-1.68 0-2.52.327-3.162a3 3 0 0 1 1.311-1.311C5.28 3 6.12 3 7.8 3h8.4c1.68 0 2.52 0 3.162.327a3 3 0 0 1 1.311 1.311C21 5.28 21 6.12 21 7.8v8.4c0 1.68 0 2.52-.327 3.162a3 3 0 0 1-1.311 1.311C18.72 21 17.88 21 16.2 21H7.8c-1.68 0-2.52 0-3.162-.327a3 3 0 0 1-1.311-1.311C3 18.72 3 17.88 3 16.2V7.8Z"}));v_.displayName="Stop";const __=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"M16 8V5l3-3 1 2 2 1-3 3h-3Zm0 0-4 4m10 0c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2m5 10a5 5 0 1 1-5-5"}));__.displayName="Target04";const C_=({size:t=24,color:e="currentColor",...n})=>M.createElement("svg",{viewBox:"0 0 24 24",width:t,height:t,stroke:e,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n},M.createElement("path",{d:"m15 9-6 6m0-6 6 6m7-3c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10Z"}));C_.displayName="XCircle";function yt(t){const e=ne.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let i;e[3]!==n?(i=me("bg-accent animate-pulse rounded-md",n),e[3]=n,e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=S.jsx("div",{"data-slot":"skeleton",className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a}function t2(){const t=ne.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=so.developerMode(),t[0]=e):e=t[0],ma(e,!1)}var I_="vercel.ai.error",n2=Symbol.for(I_),GE,VE,Cn=class N_ extends(VE=Error,GE=n2,VE){constructor({name:e,message:n,cause:r}){super(n),this[GE]=!0,this.name=e,this.cause=r}static isInstance(e){return N_.hasMarker(e,I_)}static hasMarker(e,n){const r=Symbol.for(n);return e!=null&&typeof e=="object"&&r in e&&typeof e[r]=="boolean"&&e[r]===!0}};function w_(t){return t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:JSON.stringify(t)}var R_="AI_InvalidArgumentError",O_=`vercel.ai.error.${R_}`,r2=Symbol.for(O_),WE,YE,i2=class extends(YE=Cn,WE=r2,YE){constructor({message:t,cause:e,argument:n}){super({name:R_,message:t,cause:e}),this[WE]=!0,this.argument=n}static isInstance(t){return Cn.hasMarker(t,O_)}},L_="AI_JSONParseError",D_=`vercel.ai.error.${L_}`,a2=Symbol.for(D_),KE,XE,ZE=class extends(XE=Cn,KE=a2,XE){constructor({text:t,cause:e}){super({name:L_,message:`JSON parsing failed: Text: ${t}.
2
2
  Error message: ${w_(e)}`,cause:e}),this[KE]=!0,this.text=t}static isInstance(t){return Cn.hasMarker(t,D_)}},M_="AI_TypeValidationError",P_=`vercel.ai.error.${M_}`,s2=Symbol.for(P_),QE,JE,Ii=class Mm extends(JE=Cn,QE=s2,JE){constructor({value:e,cause:n}){super({name:M_,message:`Type validation failed: Value: ${JSON.stringify(e)}.
3
3
  Error message: ${w_(n)}`,cause:n}),this[QE]=!0,this.value=e}static isInstance(e){return Cn.hasMarker(e,P_)}static wrap({value:e,cause:n}){return Mm.isInstance(n)&&n.value===e?n:new Mm({value:e,cause:n})}},ls=({prefix:t,size:e=16,alphabet:n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",separator:r="-"}={})=>{const i=()=>{const a=n.length,s=new Array(e);for(let o=0;o<e;o++)s[o]=n[Math.random()*a|0];return s.join("")};if(t==null)return i;if(n.includes(r))throw new i2({argument:"separator",message:`The separator "${r}" must not be part of the alphabet "${n}".`});return()=>`${t}${r}${i()}`},o2=ls();function e0(t=globalThis){var e,n,r;return t.window?"runtime/browser":(e=t.navigator)!=null&&e.userAgent?`runtime/${t.navigator.userAgent.toLowerCase()}`:(r=(n=t.process)==null?void 0:n.versions)!=null&&r.node?`runtime/node.js/${t.process.version.substring(0)}`:t.EdgeRuntime?"runtime/vercel-edge":"runtime/unknown"}function wr(t){if(t==null)return{};const e={};if(t instanceof Headers)t.forEach((n,r)=>{e[r.toLowerCase()]=n});else{Array.isArray(t)||(t=Object.entries(t));for(const[n,r]of t)r!=null&&(e[n.toLowerCase()]=r)}return e}function t0(t,...e){const n=new Headers(wr(t)),r=n.get("user-agent")||"";return n.set("user-agent",[r,...e].filter(Boolean).join(" ")),Object.fromEntries(n.entries())}var l2=/"__proto__"\s*:/,u2=/"constructor"\s*:/;function n0(t){const e=JSON.parse(t);return e===null||typeof e!="object"||l2.test(t)===!1&&u2.test(t)===!1?e:c2(e)}function c2(t){let e=[t];for(;e.length;){const n=e;e=[];for(const r of n){if(Object.prototype.hasOwnProperty.call(r,"__proto__"))throw new SyntaxError("Object contains forbidden prototype property");if(Object.prototype.hasOwnProperty.call(r,"constructor")&&Object.prototype.hasOwnProperty.call(r.constructor,"prototype"))throw new SyntaxError("Object contains forbidden prototype property");for(const i in r){const a=r[i];a&&typeof a=="object"&&e.push(a)}}}return t}function d2(t){const{stackTraceLimit:e}=Error;try{Error.stackTraceLimit=0}catch{return n0(t)}try{return n0(t)}finally{Error.stackTraceLimit=e}}function Jg(t){if(t.type==="object"||Array.isArray(t.type)&&t.type.includes("object")){t.additionalProperties=!1;const{properties:n}=t;if(n!=null)for(const r of Object.keys(n))n[r]=Cr(n[r])}t.items!=null&&(t.items=Array.isArray(t.items)?t.items.map(Cr):Cr(t.items)),t.anyOf!=null&&(t.anyOf=t.anyOf.map(Cr)),t.allOf!=null&&(t.allOf=t.allOf.map(Cr)),t.oneOf!=null&&(t.oneOf=t.oneOf.map(Cr));const{definitions:e}=t;if(e!=null)for(const n of Object.keys(e))e[n]=Cr(e[n]);return t}function Cr(t){return typeof t=="boolean"?t:Jg(t)}var p2=Symbol("Let zodToJsonSchema decide on which parser to use"),r0={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",strictUnions:!1,definitions:{},errorMessages:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref"},f2=t=>typeof t=="string"?{...r0,name:t}:{...r0,...t};function Qt(){return{}}function h2(t,e){var n,r,i;const a={type:"array"};return(n=t.type)!=null&&n._def&&((i=(r=t.type)==null?void 0:r._def)==null?void 0:i.typeName)!==ge.ZodAny&&(a.items=De(t.type._def,{...e,currentPath:[...e.currentPath,"items"]})),t.minLength&&(a.minItems=t.minLength.value),t.maxLength&&(a.maxItems=t.maxLength.value),t.exactLength&&(a.minItems=t.exactLength.value,a.maxItems=t.exactLength.value),a}function m2(t){const e={type:"integer",format:"int64"};if(!t.checks)return e;for(const n of t.checks)switch(n.kind){case"min":n.inclusive?e.minimum=n.value:e.exclusiveMinimum=n.value;break;case"max":n.inclusive?e.maximum=n.value:e.exclusiveMaximum=n.value;break;case"multipleOf":e.multipleOf=n.value;break}return e}function g2(){return{type:"boolean"}}function F_(t,e){return De(t.type._def,e)}var b2=(t,e)=>De(t.innerType._def,e);function B_(t,e,n){const r=n??e.dateStrategy;if(Array.isArray(r))return{anyOf:r.map((i,a)=>B_(t,e,i))};switch(r){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return E2(t)}}var E2=t=>{const e={type:"integer",format:"unix-time"};for(const n of t.checks)switch(n.kind){case"min":e.minimum=n.value;break;case"max":e.maximum=n.value;break}return e};function y2(t,e){return{...De(t.innerType._def,e),default:t.defaultValue()}}function T2(t,e){return e.effectStrategy==="input"?De(t.schema._def,e):Qt()}function S2(t){return{type:"string",enum:Array.from(t.values)}}var A2=t=>"type"in t&&t.type==="string"?!1:"allOf"in t;function k2(t,e){const n=[De(t.left._def,{...e,currentPath:[...e.currentPath,"allOf","0"]}),De(t.right._def,{...e,currentPath:[...e.currentPath,"allOf","1"]})].filter(i=>!!i),r=[];return n.forEach(i=>{if(A2(i))r.push(...i.allOf);else{let a=i;if("additionalProperties"in i&&i.additionalProperties===!1){const{additionalProperties:s,...o}=i;a=o}r.push(a)}}),r.length?{allOf:r}:void 0}function x2(t){const e=typeof t.value;return e!=="bigint"&&e!=="number"&&e!=="boolean"&&e!=="string"?{type:Array.isArray(t.value)?"array":"object"}:{type:e==="bigint"?"integer":e,const:t.value}}var Ql=void 0,pn={cuid:/^[cC][^\s-]{8,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,email:/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,emoji:()=>(Ql===void 0&&(Ql=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),Ql),uuid:/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv4Cidr:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,ipv6:/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,ipv6Cidr:/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64url:/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,jwt:/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/};function U_(t,e){const n={type:"string"};if(t.checks)for(const r of t.checks)switch(r.kind){case"min":n.minLength=typeof n.minLength=="number"?Math.max(n.minLength,r.value):r.value;break;case"max":n.maxLength=typeof n.maxLength=="number"?Math.min(n.maxLength,r.value):r.value;break;case"email":switch(e.emailStrategy){case"format:email":fn(n,"email",r.message,e);break;case"format:idn-email":fn(n,"idn-email",r.message,e);break;case"pattern:zod":Rt(n,pn.email,r.message,e);break}break;case"url":fn(n,"uri",r.message,e);break;case"uuid":fn(n,"uuid",r.message,e);break;case"regex":Rt(n,r.regex,r.message,e);break;case"cuid":Rt(n,pn.cuid,r.message,e);break;case"cuid2":Rt(n,pn.cuid2,r.message,e);break;case"startsWith":Rt(n,RegExp(`^${Jl(r.value,e)}`),r.message,e);break;case"endsWith":Rt(n,RegExp(`${Jl(r.value,e)}$`),r.message,e);break;case"datetime":fn(n,"date-time",r.message,e);break;case"date":fn(n,"date",r.message,e);break;case"time":fn(n,"time",r.message,e);break;case"duration":fn(n,"duration",r.message,e);break;case"length":n.minLength=typeof n.minLength=="number"?Math.max(n.minLength,r.value):r.value,n.maxLength=typeof n.maxLength=="number"?Math.min(n.maxLength,r.value):r.value;break;case"includes":{Rt(n,RegExp(Jl(r.value,e)),r.message,e);break}case"ip":{r.version!=="v6"&&fn(n,"ipv4",r.message,e),r.version!=="v4"&&fn(n,"ipv6",r.message,e);break}case"base64url":Rt(n,pn.base64url,r.message,e);break;case"jwt":Rt(n,pn.jwt,r.message,e);break;case"cidr":{r.version!=="v6"&&Rt(n,pn.ipv4Cidr,r.message,e),r.version!=="v4"&&Rt(n,pn.ipv6Cidr,r.message,e);break}case"emoji":Rt(n,pn.emoji(),r.message,e);break;case"ulid":{Rt(n,pn.ulid,r.message,e);break}case"base64":{switch(e.base64Strategy){case"format:binary":{fn(n,"binary",r.message,e);break}case"contentEncoding:base64":{n.contentEncoding="base64";break}case"pattern:zod":{Rt(n,pn.base64,r.message,e);break}}break}case"nanoid":Rt(n,pn.nanoid,r.message,e)}return n}function Jl(t,e){return e.patternStrategy==="escape"?_2(t):t}var v2=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function _2(t){let e="";for(let n=0;n<t.length;n++)v2.has(t[n])||(e+="\\"),e+=t[n];return e}function fn(t,e,n,r){var i;t.format||(i=t.anyOf)!=null&&i.some(a=>a.format)?(t.anyOf||(t.anyOf=[]),t.format&&(t.anyOf.push({format:t.format}),delete t.format),t.anyOf.push({format:e,...n&&r.errorMessages&&{errorMessage:{format:n}}})):t.format=e}function Rt(t,e,n,r){var i;t.pattern||(i=t.allOf)!=null&&i.some(a=>a.pattern)?(t.allOf||(t.allOf=[]),t.pattern&&(t.allOf.push({pattern:t.pattern}),delete t.pattern),t.allOf.push({pattern:i0(e,r),...n&&r.errorMessages&&{errorMessage:{pattern:n}}})):t.pattern=i0(e,r)}function i0(t,e){var n;if(!e.applyRegexFlags||!t.flags)return t.source;const r={i:t.flags.includes("i"),m:t.flags.includes("m"),s:t.flags.includes("s")},i=r.i?t.source.toLowerCase():t.source;let a="",s=!1,o=!1,l=!1;for(let u=0;u<i.length;u++){if(s){a+=i[u],s=!1;continue}if(r.i){if(o){if(i[u].match(/[a-z]/)){l?(a+=i[u],a+=`${i[u-2]}-${i[u]}`.toUpperCase(),l=!1):i[u+1]==="-"&&((n=i[u+2])!=null&&n.match(/[a-z]/))?(a+=i[u],l=!0):a+=`${i[u]}${i[u].toUpperCase()}`;continue}}else if(i[u].match(/[a-z]/)){a+=`[${i[u]}${i[u].toUpperCase()}]`;continue}}if(r.m){if(i[u]==="^"){a+=`(^|(?<=[\r
4
4
  ]))`;continue}else if(i[u]==="$"){a+=`($|(?=[\r
@@ -8,7 +8,7 @@ Error message: ${w_(n)}`,cause:n}),this[QE]=!0,this.value=e}static isInstance(e)
8
8
 
9
9
  `)},flush(t){t.enqueue(`data: [DONE]
10
10
 
11
- `)}})}});var _D=Q2(()=>$_(jt([ze({type:de("text-start"),id:ee(),providerMetadata:xe.optional()}),ze({type:de("text-delta"),id:ee(),delta:ee(),providerMetadata:xe.optional()}),ze({type:de("text-end"),id:ee(),providerMetadata:xe.optional()}),ze({type:de("error"),errorText:ee()}),ze({type:de("tool-input-start"),toolCallId:ee(),toolName:ee(),providerExecuted:Ot().optional(),providerMetadata:xe.optional(),dynamic:Ot().optional(),title:ee().optional()}),ze({type:de("tool-input-delta"),toolCallId:ee(),inputTextDelta:ee()}),ze({type:de("tool-input-available"),toolCallId:ee(),toolName:ee(),input:Zn(),providerExecuted:Ot().optional(),providerMetadata:xe.optional(),dynamic:Ot().optional(),title:ee().optional()}),ze({type:de("tool-input-error"),toolCallId:ee(),toolName:ee(),input:Zn(),providerExecuted:Ot().optional(),providerMetadata:xe.optional(),dynamic:Ot().optional(),errorText:ee(),title:ee().optional()}),ze({type:de("tool-approval-request"),approvalId:ee(),toolCallId:ee()}),ze({type:de("tool-output-available"),toolCallId:ee(),output:Zn(),providerExecuted:Ot().optional(),dynamic:Ot().optional(),preliminary:Ot().optional()}),ze({type:de("tool-output-error"),toolCallId:ee(),errorText:ee(),providerExecuted:Ot().optional(),dynamic:Ot().optional()}),ze({type:de("tool-output-denied"),toolCallId:ee()}),ze({type:de("reasoning-start"),id:ee(),providerMetadata:xe.optional()}),ze({type:de("reasoning-delta"),id:ee(),delta:ee(),providerMetadata:xe.optional()}),ze({type:de("reasoning-end"),id:ee(),providerMetadata:xe.optional()}),ze({type:de("source-url"),sourceId:ee(),url:ee(),title:ee().optional(),providerMetadata:xe.optional()}),ze({type:de("source-document"),sourceId:ee(),mediaType:ee(),title:ee(),filename:ee().optional(),providerMetadata:xe.optional()}),ze({type:de("file"),url:ee(),mediaType:ee(),providerMetadata:xe.optional()}),ze({type:a_(t=>typeof t=="string"&&t.startsWith("data-"),{message:'Type must start with "data-"'}),id:ee().optional(),data:Zn(),transient:Ot().optional()}),ze({type:de("start-step")}),ze({type:de("finish-step")}),ze({type:de("start"),messageId:ee().optional(),messageMetadata:Zn().optional()}),ze({type:de("finish"),finishReason:YO(["stop","length","content-filter","tool-calls","error","other"]).optional(),messageMetadata:Zn().optional()}),ze({type:de("abort"),reason:ee().optional()}),ze({type:de("message-metadata"),messageMetadata:Zn()})])));function CD(t){return t.type.startsWith("data-")}function Bm(t){return t.type.startsWith("tool-")}function ID(t){return t.type==="dynamic-tool"}function Um(t){return Bm(t)||ID(t)}function o0(t){return t.type.split("-").slice(1).join("-")}function ND({lastMessage:t,messageId:e}){return{message:t?.role==="assistant"?t:{id:e,metadata:void 0,role:"assistant",parts:[]},activeTextParts:{},activeReasoningParts:{},partialToolCalls:{}}}function wD({stream:t,messageMetadataSchema:e,dataPartSchemas:n,runUpdateMessageJob:r,onError:i,onToolCall:a,onData:s}){return t.pipeThrough(new TransformStream({async transform(o,l){await r(async({state:u,write:c})=>{var d,p,f,h;function g(y){const x=u.message.parts.filter(Um).find(A=>A.toolCallId===y);if(x==null)throw new ui({chunkType:"tool-invocation",chunkId:y,message:`No tool invocation found for tool call ID "${y}".`});return x}function b(y){var k;const x=u.message.parts.find(w=>Bm(w)&&w.toolCallId===y.toolCallId),A=y,v=x;x!=null?(x.state=y.state,v.input=A.input,v.output=A.output,v.errorText=A.errorText,v.rawInput=A.rawInput,v.preliminary=A.preliminary,y.title!==void 0&&(v.title=y.title),v.providerExecuted=(k=A.providerExecuted)!=null?k:x.providerExecuted,A.providerMetadata!=null&&(x.callProviderMetadata=A.providerMetadata)):u.message.parts.push({type:`tool-${y.toolName}`,toolCallId:y.toolCallId,state:y.state,title:y.title,input:A.input,output:A.output,rawInput:A.rawInput,errorText:A.errorText,providerExecuted:A.providerExecuted,preliminary:A.preliminary,...A.providerMetadata!=null?{callProviderMetadata:A.providerMetadata}:{}})}function E(y){var k,x;const A=u.message.parts.find(C=>C.type==="dynamic-tool"&&C.toolCallId===y.toolCallId),v=y,w=A;A!=null?(A.state=y.state,w.toolName=y.toolName,w.input=v.input,w.output=v.output,w.errorText=v.errorText,w.rawInput=(k=v.rawInput)!=null?k:w.rawInput,w.preliminary=v.preliminary,y.title!==void 0&&(w.title=y.title),w.providerExecuted=(x=v.providerExecuted)!=null?x:A.providerExecuted,v.providerMetadata!=null&&(A.callProviderMetadata=v.providerMetadata)):u.message.parts.push({type:"dynamic-tool",toolName:y.toolName,toolCallId:y.toolCallId,state:y.state,input:v.input,output:v.output,errorText:v.errorText,preliminary:v.preliminary,providerExecuted:v.providerExecuted,title:y.title,...v.providerMetadata!=null?{callProviderMetadata:v.providerMetadata}:{}})}async function T(y){if(y!=null){const k=u.message.metadata!=null?Q_(u.message.metadata,y):y;e!=null&&await a0({value:k,schema:e}),u.message.metadata=k}}switch(o.type){case"text-start":{const y={type:"text",text:"",providerMetadata:o.providerMetadata,state:"streaming"};u.activeTextParts[o.id]=y,u.message.parts.push(y),c();break}case"text-delta":{const y=u.activeTextParts[o.id];if(y==null)throw new ui({chunkType:"text-delta",chunkId:o.id,message:`Received text-delta for missing text part with ID "${o.id}". Ensure a "text-start" chunk is sent before any "text-delta" chunks.`});y.text+=o.delta,y.providerMetadata=(d=o.providerMetadata)!=null?d:y.providerMetadata,c();break}case"text-end":{const y=u.activeTextParts[o.id];if(y==null)throw new ui({chunkType:"text-end",chunkId:o.id,message:`Received text-end for missing text part with ID "${o.id}". Ensure a "text-start" chunk is sent before any "text-end" chunks.`});y.state="done",y.providerMetadata=(p=o.providerMetadata)!=null?p:y.providerMetadata,delete u.activeTextParts[o.id],c();break}case"reasoning-start":{const y={type:"reasoning",text:"",providerMetadata:o.providerMetadata,state:"streaming"};u.activeReasoningParts[o.id]=y,u.message.parts.push(y),c();break}case"reasoning-delta":{const y=u.activeReasoningParts[o.id];if(y==null)throw new ui({chunkType:"reasoning-delta",chunkId:o.id,message:`Received reasoning-delta for missing reasoning part with ID "${o.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-delta" chunks.`});y.text+=o.delta,y.providerMetadata=(f=o.providerMetadata)!=null?f:y.providerMetadata,c();break}case"reasoning-end":{const y=u.activeReasoningParts[o.id];if(y==null)throw new ui({chunkType:"reasoning-end",chunkId:o.id,message:`Received reasoning-end for missing reasoning part with ID "${o.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-end" chunks.`});y.providerMetadata=(h=o.providerMetadata)!=null?h:y.providerMetadata,y.state="done",delete u.activeReasoningParts[o.id],c();break}case"file":{u.message.parts.push({type:"file",mediaType:o.mediaType,url:o.url}),c();break}case"source-url":{u.message.parts.push({type:"source-url",sourceId:o.sourceId,url:o.url,title:o.title,providerMetadata:o.providerMetadata}),c();break}case"source-document":{u.message.parts.push({type:"source-document",sourceId:o.sourceId,mediaType:o.mediaType,title:o.title,filename:o.filename,providerMetadata:o.providerMetadata}),c();break}case"tool-input-start":{const y=u.message.parts.filter(Bm);u.partialToolCalls[o.toolCallId]={text:"",toolName:o.toolName,index:y.length,dynamic:o.dynamic,title:o.title},o.dynamic?E({toolCallId:o.toolCallId,toolName:o.toolName,state:"input-streaming",input:void 0,providerExecuted:o.providerExecuted,title:o.title,providerMetadata:o.providerMetadata}):b({toolCallId:o.toolCallId,toolName:o.toolName,state:"input-streaming",input:void 0,providerExecuted:o.providerExecuted,title:o.title,providerMetadata:o.providerMetadata}),c();break}case"tool-input-delta":{const y=u.partialToolCalls[o.toolCallId];if(y==null)throw new ui({chunkType:"tool-input-delta",chunkId:o.toolCallId,message:`Received tool-input-delta for missing tool call with ID "${o.toolCallId}". Ensure a "tool-input-start" chunk is sent before any "tool-input-delta" chunks.`});y.text+=o.inputTextDelta;const{value:k}=await us(y.text);y.dynamic?E({toolCallId:o.toolCallId,toolName:y.toolName,state:"input-streaming",input:k,title:y.title}):b({toolCallId:o.toolCallId,toolName:y.toolName,state:"input-streaming",input:k,title:y.title}),c();break}case"tool-input-available":{o.dynamic?E({toolCallId:o.toolCallId,toolName:o.toolName,state:"input-available",input:o.input,providerExecuted:o.providerExecuted,providerMetadata:o.providerMetadata,title:o.title}):b({toolCallId:o.toolCallId,toolName:o.toolName,state:"input-available",input:o.input,providerExecuted:o.providerExecuted,providerMetadata:o.providerMetadata,title:o.title}),c(),a&&!o.providerExecuted&&await a({toolCall:o});break}case"tool-input-error":{o.dynamic?E({toolCallId:o.toolCallId,toolName:o.toolName,state:"output-error",input:o.input,errorText:o.errorText,providerExecuted:o.providerExecuted,providerMetadata:o.providerMetadata}):b({toolCallId:o.toolCallId,toolName:o.toolName,state:"output-error",input:void 0,rawInput:o.input,errorText:o.errorText,providerExecuted:o.providerExecuted,providerMetadata:o.providerMetadata}),c();break}case"tool-approval-request":{const y=g(o.toolCallId);y.state="approval-requested",y.approval={id:o.approvalId},c();break}case"tool-output-denied":{const y=g(o.toolCallId);y.state="output-denied",c();break}case"tool-output-available":{const y=g(o.toolCallId);y.type==="dynamic-tool"?E({toolCallId:o.toolCallId,toolName:y.toolName,state:"output-available",input:y.input,output:o.output,preliminary:o.preliminary,providerExecuted:o.providerExecuted,title:y.title}):b({toolCallId:o.toolCallId,toolName:o0(y),state:"output-available",input:y.input,output:o.output,providerExecuted:o.providerExecuted,preliminary:o.preliminary,title:y.title}),c();break}case"tool-output-error":{const y=g(o.toolCallId);y.type==="dynamic-tool"?E({toolCallId:o.toolCallId,toolName:y.toolName,state:"output-error",input:y.input,errorText:o.errorText,providerExecuted:o.providerExecuted,title:y.title}):b({toolCallId:o.toolCallId,toolName:o0(y),state:"output-error",input:y.input,rawInput:y.rawInput,errorText:o.errorText,providerExecuted:o.providerExecuted,title:y.title}),c();break}case"start-step":{u.message.parts.push({type:"step-start"});break}case"finish-step":{u.activeTextParts={},u.activeReasoningParts={};break}case"start":{o.messageId!=null&&(u.message.id=o.messageId),await T(o.messageMetadata),(o.messageId!=null||o.messageMetadata!=null)&&c();break}case"finish":{o.finishReason!=null&&(u.finishReason=o.finishReason),await T(o.messageMetadata),o.messageMetadata!=null&&c();break}case"message-metadata":{await T(o.messageMetadata),o.messageMetadata!=null&&c();break}case"error":{i?.(new Error(o.errorText));break}default:if(CD(o)){n?.[o.type]!=null&&await a0({value:o.data,schema:n[o.type]});const y=o;if(y.transient){s?.(y);break}const k=y.id!=null?u.message.parts.find(x=>y.type===x.type&&y.id===x.id):void 0;k!=null?k.data=y.data:u.message.parts.push(y),s?.(y),c()}}l.enqueue(o)})}}))}async function RD({stream:t,onError:e}){const n=t.getReader();try{for(;;){const{done:r}=await n.read();if(r)break}}catch(r){e?.(r)}finally{n.releaseLock()}}ls({prefix:"aitxt",size:24});ls({prefix:"aiobj",size:24});var OD=class{constructor(){this.queue=[],this.isProcessing=!1}async processQueue(){if(!this.isProcessing){for(this.isProcessing=!0;this.queue.length>0;)await this.queue[0](),this.queue.shift();this.isProcessing=!1}}async run(t){return new Promise((e,n)=>{this.queue.push(async()=>{try{await t(),e()}catch(r){n(r)}}),this.processQueue()})}};ls({prefix:"aiobj",size:24});async function LD(t){if(t==null)return[];if(!globalThis.FileList||!(t instanceof globalThis.FileList))throw new Error("FileList is not supported in the current environment");return Promise.all(Array.from(t).map(async e=>{const{name:n,type:r}=e,i=await new Promise((a,s)=>{const o=new FileReader;o.onload=l=>{var u;a((u=l.target)==null?void 0:u.result)},o.onerror=l=>s(l),o.readAsDataURL(e)});return{type:"file",mediaType:r,filename:n,url:i}}))}var DD=class{constructor({api:t="/api/chat",credentials:e,headers:n,body:r,fetch:i,prepareSendMessagesRequest:a,prepareReconnectToStreamRequest:s}){this.api=t,this.credentials=e,this.headers=n,this.body=r,this.fetch=i,this.prepareSendMessagesRequest=a,this.prepareReconnectToStreamRequest=s}async sendMessages({abortSignal:t,...e}){var n,r,i,a,s;const o=await nr(this.body),l=await nr(this.headers),u=await nr(this.credentials),c={...wr(l),...wr(e.headers)},d=await((n=this.prepareSendMessagesRequest)==null?void 0:n.call(this,{api:this.api,id:e.chatId,messages:e.messages,body:{...o,...e.body},headers:c,credentials:u,requestMetadata:e.metadata,trigger:e.trigger,messageId:e.messageId})),p=(r=d?.api)!=null?r:this.api,f=d?.headers!==void 0?wr(d.headers):c,h=d?.body!==void 0?d.body:{...o,...e.body,id:e.chatId,messages:e.messages,trigger:e.trigger,messageId:e.messageId},g=(i=d?.credentials)!=null?i:u,E=await((a=this.fetch)!=null?a:globalThis.fetch)(p,{method:"POST",headers:t0({"Content-Type":"application/json",...f},`ai-sdk/${s0}`,e0()),body:JSON.stringify(h),credentials:g,signal:t});if(!E.ok)throw new Error((s=await E.text())!=null?s:"Failed to fetch the chat response.");if(!E.body)throw new Error("The response body is empty.");return this.processResponseStream(E.body)}async reconnectToStream(t){var e,n,r,i,a;const s=await nr(this.body),o=await nr(this.headers),l=await nr(this.credentials),u={...wr(o),...wr(t.headers)},c=await((e=this.prepareReconnectToStreamRequest)==null?void 0:e.call(this,{api:this.api,id:t.chatId,body:{...s,...t.body},headers:u,credentials:l,requestMetadata:t.metadata})),d=(n=c?.api)!=null?n:`${this.api}/${t.chatId}/stream`,p=c?.headers!==void 0?wr(c.headers):u,f=(r=c?.credentials)!=null?r:l,g=await((i=this.fetch)!=null?i:globalThis.fetch)(d,{method:"GET",headers:t0(p,`ai-sdk/${s0}`,e0()),credentials:f});if(g.status===204)return null;if(!g.ok)throw new Error((a=await g.text())!=null?a:"Failed to fetch the chat response.");if(!g.body)throw new Error("The response body is empty.");return this.processResponseStream(g.body)}},J_=class extends DD{constructor(t={}){super(t)}processResponseStream(t){return iD({stream:t,schema:_D}).pipeThrough(new TransformStream({async transform(e,n){if(!e.success)throw e.error;n.enqueue(e.value)}}))}},MD=class{constructor({generateId:t=o2,id:e=t(),transport:n=new J_,messageMetadataSchema:r,dataPartSchemas:i,state:a,onError:s,onToolCall:o,onFinish:l,onData:u,sendAutomaticallyWhen:c}){this.activeResponse=void 0,this.jobExecutor=new OD,this.sendMessage=async(d,p)=>{var f,h,g,b;if(d==null){await this.makeRequest({trigger:"submit-message",messageId:(f=this.lastMessage)==null?void 0:f.id,...p});return}let E;if("text"in d||"files"in d?E={parts:[...Array.isArray(d.files)?d.files:await LD(d.files),..."text"in d&&d.text!=null?[{type:"text",text:d.text}]:[]]}:E=d,d.messageId!=null){const T=this.state.messages.findIndex(y=>y.id===d.messageId);if(T===-1)throw new Error(`message with id ${d.messageId} not found`);if(this.state.messages[T].role!=="user")throw new Error(`message with id ${d.messageId} is not a user message`);this.state.messages=this.state.messages.slice(0,T+1),this.state.replaceMessage(T,{...E,id:d.messageId,role:(h=E.role)!=null?h:"user",metadata:d.metadata})}else this.state.pushMessage({...E,id:(g=E.id)!=null?g:this.generateId(),role:(b=E.role)!=null?b:"user",metadata:d.metadata});await this.makeRequest({trigger:"submit-message",messageId:d.messageId,...p})},this.regenerate=async({messageId:d,...p}={})=>{const f=d==null?this.state.messages.length-1:this.state.messages.findIndex(h=>h.id===d);if(f===-1)throw new Error(`message ${d} not found`);this.state.messages=this.state.messages.slice(0,this.messages[f].role==="assistant"?f:f+1),await this.makeRequest({trigger:"regenerate-message",messageId:d,...p})},this.resumeStream=async(d={})=>{await this.makeRequest({trigger:"resume-stream",...d})},this.clearError=()=>{this.status==="error"&&(this.state.error=void 0,this.setStatus({status:"ready"}))},this.addToolApprovalResponse=async({id:d,approved:p,reason:f})=>this.jobExecutor.run(async()=>{var h,g;const b=this.state.messages,E=b[b.length-1],T=y=>Um(y)&&y.state==="approval-requested"&&y.approval.id===d?{...y,state:"approval-responded",approval:{id:d,approved:p,reason:f}}:y;this.state.replaceMessage(b.length-1,{...E,parts:E.parts.map(T)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(T)),this.status!=="streaming"&&this.status!=="submitted"&&((h=this.sendAutomaticallyWhen)!=null&&h.call(this,{messages:this.state.messages}))&&this.makeRequest({trigger:"submit-message",messageId:(g=this.lastMessage)==null?void 0:g.id})}),this.addToolOutput=async({state:d="output-available",tool:p,toolCallId:f,output:h,errorText:g})=>this.jobExecutor.run(async()=>{var b,E;const T=this.state.messages,y=T[T.length-1],k=x=>Um(x)&&x.toolCallId===f?{...x,state:d,output:h,errorText:g}:x;this.state.replaceMessage(T.length-1,{...y,parts:y.parts.map(k)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(k)),this.status!=="streaming"&&this.status!=="submitted"&&((b=this.sendAutomaticallyWhen)!=null&&b.call(this,{messages:this.state.messages}))&&this.makeRequest({trigger:"submit-message",messageId:(E=this.lastMessage)==null?void 0:E.id})}),this.addToolResult=this.addToolOutput,this.stop=async()=>{var d;this.status!=="streaming"&&this.status!=="submitted"||(d=this.activeResponse)!=null&&d.abortController&&this.activeResponse.abortController.abort()},this.id=e,this.transport=n,this.generateId=t,this.messageMetadataSchema=r,this.dataPartSchemas=i,this.state=a,this.onError=s,this.onToolCall=o,this.onFinish=l,this.onData=u,this.sendAutomaticallyWhen=c}get status(){return this.state.status}setStatus({status:t,error:e}){this.status!==t&&(this.state.status=t,this.state.error=e)}get error(){return this.state.error}get messages(){return this.state.messages}get lastMessage(){return this.state.messages[this.state.messages.length-1]}set messages(t){this.state.messages=t}async makeRequest({trigger:t,metadata:e,headers:n,body:r,messageId:i}){var a,s,o,l;this.setStatus({status:"submitted",error:void 0});const u=this.lastMessage;let c=!1,d=!1,p=!1;try{const f={state:ND({lastMessage:this.state.snapshot(u),messageId:this.generateId()}),abortController:new AbortController};f.abortController.signal.addEventListener("abort",()=>{c=!0}),this.activeResponse=f;let h;if(t==="resume-stream"){const b=await this.transport.reconnectToStream({chatId:this.id,metadata:e,headers:n,body:r});if(b==null){this.setStatus({status:"ready"});return}h=b}else h=await this.transport.sendMessages({chatId:this.id,messages:this.state.messages,abortSignal:f.abortController.signal,metadata:e,headers:n,body:r,trigger:t,messageId:i});const g=b=>this.jobExecutor.run(()=>b({state:f.state,write:()=>{var E;this.setStatus({status:"streaming"}),f.state.message.id===((E=this.lastMessage)==null?void 0:E.id)?this.state.replaceMessage(this.state.messages.length-1,f.state.message):this.state.pushMessage(f.state.message)}}));await RD({stream:wD({stream:h,onToolCall:this.onToolCall,onData:this.onData,messageMetadataSchema:this.messageMetadataSchema,dataPartSchemas:this.dataPartSchemas,runUpdateMessageJob:g,onError:b=>{throw b}}),onError:b=>{throw b}}),this.setStatus({status:"ready"})}catch(f){if(c||f.name==="AbortError")return c=!0,this.setStatus({status:"ready"}),null;p=!0,f instanceof TypeError&&(f.message.toLowerCase().includes("fetch")||f.message.toLowerCase().includes("network"))&&(d=!0),this.onError&&f instanceof Error&&this.onError(f),this.setStatus({status:"error",error:f})}finally{try{(s=this.onFinish)==null||s.call(this,{message:this.activeResponse.state.message,messages:this.state.messages,isAbort:c,isDisconnect:d,isError:p,finishReason:(a=this.activeResponse)==null?void 0:a.state.finishReason})}catch(f){console.error(f)}this.activeResponse=void 0}(o=this.sendAutomaticallyWhen)!=null&&o.call(this,{messages:this.state.messages})&&!p&&await this.makeRequest({trigger:"submit-message",messageId:(l=this.lastMessage)==null?void 0:l.id,metadata:e,headers:n,body:r})}},eu,l0;function PD(){if(l0)return eu;l0=1;function t(e,n){if(typeof e!="function")throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof e}\`.`);let r,i=0;return function(...s){clearTimeout(r);const o=Date.now(),l=o-i,u=n-l;u<=0?(i=o,e.apply(this,s)):r=setTimeout(()=>{i=Date.now(),e.apply(this,s)},u)}}return eu=t,eu}var FD=PD();const BD=ul(FD);var eC=(t,e,n)=>{if(!e.has(t))throw TypeError("Cannot "+n)},je=(t,e,n)=>(eC(t,e,"read from private field"),n?n.call(t):e.get(t)),yn=(t,e,n)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,n)},Qn=(t,e,n,r)=>(eC(t,e,"write to private field"),e.set(t,n),n);function UD(t,e){return e!=null?BD(t,e):t}var nn,Gs,Vs,oa,la,ua,hi,Hm,$m,HD=class{constructor(t=[]){yn(this,nn,void 0),yn(this,Gs,"ready"),yn(this,Vs,void 0),yn(this,oa,new Set),yn(this,la,new Set),yn(this,ua,new Set),this.pushMessage=e=>{Qn(this,nn,je(this,nn).concat(e)),je(this,hi).call(this)},this.popMessage=()=>{Qn(this,nn,je(this,nn).slice(0,-1)),je(this,hi).call(this)},this.replaceMessage=(e,n)=>{Qn(this,nn,[...je(this,nn).slice(0,e),this.snapshot(n),...je(this,nn).slice(e+1)]),je(this,hi).call(this)},this.snapshot=e=>structuredClone(e),this["~registerMessagesCallback"]=(e,n)=>{const r=n?UD(e,n):e;return je(this,oa).add(r),()=>{je(this,oa).delete(r)}},this["~registerStatusCallback"]=e=>(je(this,la).add(e),()=>{je(this,la).delete(e)}),this["~registerErrorCallback"]=e=>(je(this,ua).add(e),()=>{je(this,ua).delete(e)}),yn(this,hi,()=>{je(this,oa).forEach(e=>e())}),yn(this,Hm,()=>{je(this,la).forEach(e=>e())}),yn(this,$m,()=>{je(this,ua).forEach(e=>e())}),Qn(this,nn,t)}get status(){return je(this,Gs)}set status(t){Qn(this,Gs,t),je(this,Hm).call(this)}get error(){return je(this,Vs)}set error(t){Qn(this,Vs,t),je(this,$m).call(this)}get messages(){return je(this,nn)}set messages(t){Qn(this,nn,[...t]),je(this,hi).call(this)}};nn=new WeakMap;Gs=new WeakMap;Vs=new WeakMap;oa=new WeakMap;la=new WeakMap;ua=new WeakMap;hi=new WeakMap;Hm=new WeakMap;$m=new WeakMap;var mi,u0=class extends MD{constructor({messages:e,...n}){const r=new HD(e);super({...n,state:r}),yn(this,mi,void 0),this["~registerMessagesCallback"]=(i,a)=>je(this,mi)["~registerMessagesCallback"](i,a),this["~registerStatusCallback"]=i=>je(this,mi)["~registerStatusCallback"](i),this["~registerErrorCallback"]=i=>je(this,mi)["~registerErrorCallback"](i),Qn(this,mi,r)}};mi=new WeakMap;function $D({experimental_throttle:t,resume:e=!1,...n}={}){const r=M.useRef("chat"in n?{}:{onToolCall:n.onToolCall,onData:n.onData,onFinish:n.onFinish,onError:n.onError,sendAutomaticallyWhen:n.sendAutomaticallyWhen});"chat"in n||(r.current={onToolCall:n.onToolCall,onData:n.onData,onFinish:n.onFinish,onError:n.onError,sendAutomaticallyWhen:n.sendAutomaticallyWhen});const i={...n,onToolCall:p=>{var f,h;return(h=(f=r.current).onToolCall)==null?void 0:h.call(f,p)},onData:p=>{var f,h;return(h=(f=r.current).onData)==null?void 0:h.call(f,p)},onFinish:p=>{var f,h;return(h=(f=r.current).onFinish)==null?void 0:h.call(f,p)},onError:p=>{var f,h;return(h=(f=r.current).onError)==null?void 0:h.call(f,p)},sendAutomaticallyWhen:p=>{var f,h,g;return(g=(h=(f=r.current).sendAutomaticallyWhen)==null?void 0:h.call(f,p))!=null?g:!1}},a=M.useRef("chat"in n?n.chat:new u0(i));("chat"in n&&n.chat!==a.current||"id"in n&&a.current.id!==n.id)&&(a.current="chat"in n?n.chat:new u0(i));const o=M.useCallback(p=>a.current["~registerMessagesCallback"](p,t),[t,a.current.id]),l=M.useSyncExternalStore(o,()=>a.current.messages,()=>a.current.messages),u=M.useSyncExternalStore(a.current["~registerStatusCallback"],()=>a.current.status,()=>a.current.status),c=M.useSyncExternalStore(a.current["~registerErrorCallback"],()=>a.current.error,()=>a.current.error),d=M.useCallback(p=>{typeof p=="function"&&(p=p(a.current.messages)),a.current.messages=p},[a]);return M.useEffect(()=>{e&&a.current.resumeStream()},[e,a]),{id:a.current.id,messages:l,setMessages:d,sendMessage:a.current.sendMessage,regenerate:a.current.regenerate,clearError:a.current.clearError,stop:a.current.stop,error:c,resumeStream:a.current.resumeStream,status:u,addToolResult:a.current.addToolOutput,addToolOutput:a.current.addToolOutput,addToolApprovalResponse:a.current.addToolApprovalResponse}}function zD(t,e){const n=ne.c(5);let r;n[0]!==e?(r=e===void 0?{}:e,n[0]=e,n[1]=r):r=n[1];const i=r,{org:a}=Gn(),s=t??null;let o;n[2]!==a.id||n[3]!==s?(o={connectionId:s,orgId:a.id},n[2]=a.id,n[3]=s,n[4]=o):o=n[4];const l=Qr(o);return yL(t??"no-connection","LLM",l,i)}function tb(){const t=ne.c(2),e=h_();let n;return t[0]!==e?(n={connections:e,binding:"LLMS"},t[0]=e,t[1]=n):n=t[1],SL(n)}const tC=50;function wre(){const t=ne.c(20),{locator:e,org:n}=Gn();let r;t[0]!==n.id?(r=Wg.SELF(n.id),t[0]=n.id,t[1]=r):r=t[1];let i;t[2]!==n.id||t[3]!==r?(i={connectionId:r,orgId:n.id},t[2]=n.id,t[3]=r,t[4]=i):i=t[4];const a=Qr(i);let s;t[5]!==e?(s=Hi.threads(e),t[5]=e,t[6]=s):s=t[6];let o;t[7]!==a?(o=async E=>{const{pageParam:T}=E,y=T===void 0?0:T;if(!a)throw new Error("MCP client is not available");const k={limit:tC,offset:y},x=await a.callTool({name:"COLLECTION_THREADS_LIST",arguments:k}),A=x.structuredContent??x;return{items:A.items??[],hasMore:A.hasMore??!1,totalCount:A.totalCount}},t[7]=a,t[8]=o):o=t[8];let l;t[9]!==s||t[10]!==o?(l={queryKey:s,queryFn:o,getNextPageParam:qD,initialPageParam:0,staleTime:3e4},t[9]=s,t[10]=o,t[11]=l):l=t[11];const{data:u,fetchNextPage:c,hasNextPage:d,isFetchingNextPage:p,refetch:f}=AL(l);let h;t[12]!==u?.pages?(h=u?.pages.flatMap(jD)??[],t[12]=u?.pages,t[13]=h):h=t[13];const g=h;let b;return t[14]!==c||t[15]!==d||t[16]!==p||t[17]!==f||t[18]!==g?(b={threads:g,refetch:f,hasNextPage:d,isFetchingNextPage:p,fetchNextPage:c},t[14]=c,t[15]=d,t[16]=p,t[17]=f,t[18]=g,t[19]=b):b=t[19],b}function jD(t){return t.items}function qD(t,e){if(t.hasMore)return e.length*tC}function GD(t){const{locator:e,org:n}=Gn(),r=Qr({connectionId:Wg.SELF(n.id),orgId:n.id}),i="COLLECTION_THREAD_MESSAGES_LIST",{data:a}=s_({queryKey:Hi.threadMessages(e,t??""),queryFn:async()=>{try{if(!t||!r)return[];const s={threadId:t,limit:100,offset:0},o=await r.callTool({name:i,arguments:s});return(o.structuredContent??o).items??[]}catch{return[]}},staleTime:0});return a??[]}function VD(t){const e=ne.c(10);let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n={strict:!1},e[0]=n):n=e[0];const r=o_(n);let i;if(e[1]!==r.collectionName||e[2]!==r.connectionId||e[3]!==r.itemId||e[4]!==t){i=[],t&&i.push(`### Selected Agent
11
+ `)}})}});var _D=Q2(()=>$_(jt([ze({type:de("text-start"),id:ee(),providerMetadata:xe.optional()}),ze({type:de("text-delta"),id:ee(),delta:ee(),providerMetadata:xe.optional()}),ze({type:de("text-end"),id:ee(),providerMetadata:xe.optional()}),ze({type:de("error"),errorText:ee()}),ze({type:de("tool-input-start"),toolCallId:ee(),toolName:ee(),providerExecuted:Ot().optional(),providerMetadata:xe.optional(),dynamic:Ot().optional(),title:ee().optional()}),ze({type:de("tool-input-delta"),toolCallId:ee(),inputTextDelta:ee()}),ze({type:de("tool-input-available"),toolCallId:ee(),toolName:ee(),input:Zn(),providerExecuted:Ot().optional(),providerMetadata:xe.optional(),dynamic:Ot().optional(),title:ee().optional()}),ze({type:de("tool-input-error"),toolCallId:ee(),toolName:ee(),input:Zn(),providerExecuted:Ot().optional(),providerMetadata:xe.optional(),dynamic:Ot().optional(),errorText:ee(),title:ee().optional()}),ze({type:de("tool-approval-request"),approvalId:ee(),toolCallId:ee()}),ze({type:de("tool-output-available"),toolCallId:ee(),output:Zn(),providerExecuted:Ot().optional(),dynamic:Ot().optional(),preliminary:Ot().optional()}),ze({type:de("tool-output-error"),toolCallId:ee(),errorText:ee(),providerExecuted:Ot().optional(),dynamic:Ot().optional()}),ze({type:de("tool-output-denied"),toolCallId:ee()}),ze({type:de("reasoning-start"),id:ee(),providerMetadata:xe.optional()}),ze({type:de("reasoning-delta"),id:ee(),delta:ee(),providerMetadata:xe.optional()}),ze({type:de("reasoning-end"),id:ee(),providerMetadata:xe.optional()}),ze({type:de("source-url"),sourceId:ee(),url:ee(),title:ee().optional(),providerMetadata:xe.optional()}),ze({type:de("source-document"),sourceId:ee(),mediaType:ee(),title:ee(),filename:ee().optional(),providerMetadata:xe.optional()}),ze({type:de("file"),url:ee(),mediaType:ee(),providerMetadata:xe.optional()}),ze({type:a_(t=>typeof t=="string"&&t.startsWith("data-"),{message:'Type must start with "data-"'}),id:ee().optional(),data:Zn(),transient:Ot().optional()}),ze({type:de("start-step")}),ze({type:de("finish-step")}),ze({type:de("start"),messageId:ee().optional(),messageMetadata:Zn().optional()}),ze({type:de("finish"),finishReason:YO(["stop","length","content-filter","tool-calls","error","other"]).optional(),messageMetadata:Zn().optional()}),ze({type:de("abort"),reason:ee().optional()}),ze({type:de("message-metadata"),messageMetadata:Zn()})])));function CD(t){return t.type.startsWith("data-")}function Bm(t){return t.type.startsWith("tool-")}function ID(t){return t.type==="dynamic-tool"}function Um(t){return Bm(t)||ID(t)}function o0(t){return t.type.split("-").slice(1).join("-")}function ND({lastMessage:t,messageId:e}){return{message:t?.role==="assistant"?t:{id:e,metadata:void 0,role:"assistant",parts:[]},activeTextParts:{},activeReasoningParts:{},partialToolCalls:{}}}function wD({stream:t,messageMetadataSchema:e,dataPartSchemas:n,runUpdateMessageJob:r,onError:i,onToolCall:a,onData:s}){return t.pipeThrough(new TransformStream({async transform(o,l){await r(async({state:u,write:c})=>{var d,p,f,h;function g(y){const x=u.message.parts.filter(Um).find(A=>A.toolCallId===y);if(x==null)throw new ui({chunkType:"tool-invocation",chunkId:y,message:`No tool invocation found for tool call ID "${y}".`});return x}function b(y){var k;const x=u.message.parts.find(w=>Bm(w)&&w.toolCallId===y.toolCallId),A=y,v=x;x!=null?(x.state=y.state,v.input=A.input,v.output=A.output,v.errorText=A.errorText,v.rawInput=A.rawInput,v.preliminary=A.preliminary,y.title!==void 0&&(v.title=y.title),v.providerExecuted=(k=A.providerExecuted)!=null?k:x.providerExecuted,A.providerMetadata!=null&&(x.callProviderMetadata=A.providerMetadata)):u.message.parts.push({type:`tool-${y.toolName}`,toolCallId:y.toolCallId,state:y.state,title:y.title,input:A.input,output:A.output,rawInput:A.rawInput,errorText:A.errorText,providerExecuted:A.providerExecuted,preliminary:A.preliminary,...A.providerMetadata!=null?{callProviderMetadata:A.providerMetadata}:{}})}function E(y){var k,x;const A=u.message.parts.find(C=>C.type==="dynamic-tool"&&C.toolCallId===y.toolCallId),v=y,w=A;A!=null?(A.state=y.state,w.toolName=y.toolName,w.input=v.input,w.output=v.output,w.errorText=v.errorText,w.rawInput=(k=v.rawInput)!=null?k:w.rawInput,w.preliminary=v.preliminary,y.title!==void 0&&(w.title=y.title),w.providerExecuted=(x=v.providerExecuted)!=null?x:A.providerExecuted,v.providerMetadata!=null&&(A.callProviderMetadata=v.providerMetadata)):u.message.parts.push({type:"dynamic-tool",toolName:y.toolName,toolCallId:y.toolCallId,state:y.state,input:v.input,output:v.output,errorText:v.errorText,preliminary:v.preliminary,providerExecuted:v.providerExecuted,title:y.title,...v.providerMetadata!=null?{callProviderMetadata:v.providerMetadata}:{}})}async function T(y){if(y!=null){const k=u.message.metadata!=null?Q_(u.message.metadata,y):y;e!=null&&await a0({value:k,schema:e}),u.message.metadata=k}}switch(o.type){case"text-start":{const y={type:"text",text:"",providerMetadata:o.providerMetadata,state:"streaming"};u.activeTextParts[o.id]=y,u.message.parts.push(y),c();break}case"text-delta":{const y=u.activeTextParts[o.id];if(y==null)throw new ui({chunkType:"text-delta",chunkId:o.id,message:`Received text-delta for missing text part with ID "${o.id}". Ensure a "text-start" chunk is sent before any "text-delta" chunks.`});y.text+=o.delta,y.providerMetadata=(d=o.providerMetadata)!=null?d:y.providerMetadata,c();break}case"text-end":{const y=u.activeTextParts[o.id];if(y==null)throw new ui({chunkType:"text-end",chunkId:o.id,message:`Received text-end for missing text part with ID "${o.id}". Ensure a "text-start" chunk is sent before any "text-end" chunks.`});y.state="done",y.providerMetadata=(p=o.providerMetadata)!=null?p:y.providerMetadata,delete u.activeTextParts[o.id],c();break}case"reasoning-start":{const y={type:"reasoning",text:"",providerMetadata:o.providerMetadata,state:"streaming"};u.activeReasoningParts[o.id]=y,u.message.parts.push(y),c();break}case"reasoning-delta":{const y=u.activeReasoningParts[o.id];if(y==null)throw new ui({chunkType:"reasoning-delta",chunkId:o.id,message:`Received reasoning-delta for missing reasoning part with ID "${o.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-delta" chunks.`});y.text+=o.delta,y.providerMetadata=(f=o.providerMetadata)!=null?f:y.providerMetadata,c();break}case"reasoning-end":{const y=u.activeReasoningParts[o.id];if(y==null)throw new ui({chunkType:"reasoning-end",chunkId:o.id,message:`Received reasoning-end for missing reasoning part with ID "${o.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-end" chunks.`});y.providerMetadata=(h=o.providerMetadata)!=null?h:y.providerMetadata,y.state="done",delete u.activeReasoningParts[o.id],c();break}case"file":{u.message.parts.push({type:"file",mediaType:o.mediaType,url:o.url}),c();break}case"source-url":{u.message.parts.push({type:"source-url",sourceId:o.sourceId,url:o.url,title:o.title,providerMetadata:o.providerMetadata}),c();break}case"source-document":{u.message.parts.push({type:"source-document",sourceId:o.sourceId,mediaType:o.mediaType,title:o.title,filename:o.filename,providerMetadata:o.providerMetadata}),c();break}case"tool-input-start":{const y=u.message.parts.filter(Bm);u.partialToolCalls[o.toolCallId]={text:"",toolName:o.toolName,index:y.length,dynamic:o.dynamic,title:o.title},o.dynamic?E({toolCallId:o.toolCallId,toolName:o.toolName,state:"input-streaming",input:void 0,providerExecuted:o.providerExecuted,title:o.title,providerMetadata:o.providerMetadata}):b({toolCallId:o.toolCallId,toolName:o.toolName,state:"input-streaming",input:void 0,providerExecuted:o.providerExecuted,title:o.title,providerMetadata:o.providerMetadata}),c();break}case"tool-input-delta":{const y=u.partialToolCalls[o.toolCallId];if(y==null)throw new ui({chunkType:"tool-input-delta",chunkId:o.toolCallId,message:`Received tool-input-delta for missing tool call with ID "${o.toolCallId}". Ensure a "tool-input-start" chunk is sent before any "tool-input-delta" chunks.`});y.text+=o.inputTextDelta;const{value:k}=await us(y.text);y.dynamic?E({toolCallId:o.toolCallId,toolName:y.toolName,state:"input-streaming",input:k,title:y.title}):b({toolCallId:o.toolCallId,toolName:y.toolName,state:"input-streaming",input:k,title:y.title}),c();break}case"tool-input-available":{o.dynamic?E({toolCallId:o.toolCallId,toolName:o.toolName,state:"input-available",input:o.input,providerExecuted:o.providerExecuted,providerMetadata:o.providerMetadata,title:o.title}):b({toolCallId:o.toolCallId,toolName:o.toolName,state:"input-available",input:o.input,providerExecuted:o.providerExecuted,providerMetadata:o.providerMetadata,title:o.title}),c(),a&&!o.providerExecuted&&await a({toolCall:o});break}case"tool-input-error":{o.dynamic?E({toolCallId:o.toolCallId,toolName:o.toolName,state:"output-error",input:o.input,errorText:o.errorText,providerExecuted:o.providerExecuted,providerMetadata:o.providerMetadata}):b({toolCallId:o.toolCallId,toolName:o.toolName,state:"output-error",input:void 0,rawInput:o.input,errorText:o.errorText,providerExecuted:o.providerExecuted,providerMetadata:o.providerMetadata}),c();break}case"tool-approval-request":{const y=g(o.toolCallId);y.state="approval-requested",y.approval={id:o.approvalId},c();break}case"tool-output-denied":{const y=g(o.toolCallId);y.state="output-denied",c();break}case"tool-output-available":{const y=g(o.toolCallId);y.type==="dynamic-tool"?E({toolCallId:o.toolCallId,toolName:y.toolName,state:"output-available",input:y.input,output:o.output,preliminary:o.preliminary,providerExecuted:o.providerExecuted,title:y.title}):b({toolCallId:o.toolCallId,toolName:o0(y),state:"output-available",input:y.input,output:o.output,providerExecuted:o.providerExecuted,preliminary:o.preliminary,title:y.title}),c();break}case"tool-output-error":{const y=g(o.toolCallId);y.type==="dynamic-tool"?E({toolCallId:o.toolCallId,toolName:y.toolName,state:"output-error",input:y.input,errorText:o.errorText,providerExecuted:o.providerExecuted,title:y.title}):b({toolCallId:o.toolCallId,toolName:o0(y),state:"output-error",input:y.input,rawInput:y.rawInput,errorText:o.errorText,providerExecuted:o.providerExecuted,title:y.title}),c();break}case"start-step":{u.message.parts.push({type:"step-start"});break}case"finish-step":{u.activeTextParts={},u.activeReasoningParts={};break}case"start":{o.messageId!=null&&(u.message.id=o.messageId),await T(o.messageMetadata),(o.messageId!=null||o.messageMetadata!=null)&&c();break}case"finish":{o.finishReason!=null&&(u.finishReason=o.finishReason),await T(o.messageMetadata),o.messageMetadata!=null&&c();break}case"message-metadata":{await T(o.messageMetadata),o.messageMetadata!=null&&c();break}case"error":{i?.(new Error(o.errorText));break}default:if(CD(o)){n?.[o.type]!=null&&await a0({value:o.data,schema:n[o.type]});const y=o;if(y.transient){s?.(y);break}const k=y.id!=null?u.message.parts.find(x=>y.type===x.type&&y.id===x.id):void 0;k!=null?k.data=y.data:u.message.parts.push(y),s?.(y),c()}}l.enqueue(o)})}}))}async function RD({stream:t,onError:e}){const n=t.getReader();try{for(;;){const{done:r}=await n.read();if(r)break}}catch(r){e?.(r)}finally{n.releaseLock()}}ls({prefix:"aitxt",size:24});ls({prefix:"aiobj",size:24});var OD=class{constructor(){this.queue=[],this.isProcessing=!1}async processQueue(){if(!this.isProcessing){for(this.isProcessing=!0;this.queue.length>0;)await this.queue[0](),this.queue.shift();this.isProcessing=!1}}async run(t){return new Promise((e,n)=>{this.queue.push(async()=>{try{await t(),e()}catch(r){n(r)}}),this.processQueue()})}};ls({prefix:"aiobj",size:24});async function LD(t){if(t==null)return[];if(!globalThis.FileList||!(t instanceof globalThis.FileList))throw new Error("FileList is not supported in the current environment");return Promise.all(Array.from(t).map(async e=>{const{name:n,type:r}=e,i=await new Promise((a,s)=>{const o=new FileReader;o.onload=l=>{var u;a((u=l.target)==null?void 0:u.result)},o.onerror=l=>s(l),o.readAsDataURL(e)});return{type:"file",mediaType:r,filename:n,url:i}}))}var DD=class{constructor({api:t="/api/chat",credentials:e,headers:n,body:r,fetch:i,prepareSendMessagesRequest:a,prepareReconnectToStreamRequest:s}){this.api=t,this.credentials=e,this.headers=n,this.body=r,this.fetch=i,this.prepareSendMessagesRequest=a,this.prepareReconnectToStreamRequest=s}async sendMessages({abortSignal:t,...e}){var n,r,i,a,s;const o=await nr(this.body),l=await nr(this.headers),u=await nr(this.credentials),c={...wr(l),...wr(e.headers)},d=await((n=this.prepareSendMessagesRequest)==null?void 0:n.call(this,{api:this.api,id:e.chatId,messages:e.messages,body:{...o,...e.body},headers:c,credentials:u,requestMetadata:e.metadata,trigger:e.trigger,messageId:e.messageId})),p=(r=d?.api)!=null?r:this.api,f=d?.headers!==void 0?wr(d.headers):c,h=d?.body!==void 0?d.body:{...o,...e.body,id:e.chatId,messages:e.messages,trigger:e.trigger,messageId:e.messageId},g=(i=d?.credentials)!=null?i:u,E=await((a=this.fetch)!=null?a:globalThis.fetch)(p,{method:"POST",headers:t0({"Content-Type":"application/json",...f},`ai-sdk/${s0}`,e0()),body:JSON.stringify(h),credentials:g,signal:t});if(!E.ok)throw new Error((s=await E.text())!=null?s:"Failed to fetch the chat response.");if(!E.body)throw new Error("The response body is empty.");return this.processResponseStream(E.body)}async reconnectToStream(t){var e,n,r,i,a;const s=await nr(this.body),o=await nr(this.headers),l=await nr(this.credentials),u={...wr(o),...wr(t.headers)},c=await((e=this.prepareReconnectToStreamRequest)==null?void 0:e.call(this,{api:this.api,id:t.chatId,body:{...s,...t.body},headers:u,credentials:l,requestMetadata:t.metadata})),d=(n=c?.api)!=null?n:`${this.api}/${t.chatId}/stream`,p=c?.headers!==void 0?wr(c.headers):u,f=(r=c?.credentials)!=null?r:l,g=await((i=this.fetch)!=null?i:globalThis.fetch)(d,{method:"GET",headers:t0(p,`ai-sdk/${s0}`,e0()),credentials:f});if(g.status===204)return null;if(!g.ok)throw new Error((a=await g.text())!=null?a:"Failed to fetch the chat response.");if(!g.body)throw new Error("The response body is empty.");return this.processResponseStream(g.body)}},J_=class extends DD{constructor(t={}){super(t)}processResponseStream(t){return iD({stream:t,schema:_D}).pipeThrough(new TransformStream({async transform(e,n){if(!e.success)throw e.error;n.enqueue(e.value)}}))}},MD=class{constructor({generateId:t=o2,id:e=t(),transport:n=new J_,messageMetadataSchema:r,dataPartSchemas:i,state:a,onError:s,onToolCall:o,onFinish:l,onData:u,sendAutomaticallyWhen:c}){this.activeResponse=void 0,this.jobExecutor=new OD,this.sendMessage=async(d,p)=>{var f,h,g,b;if(d==null){await this.makeRequest({trigger:"submit-message",messageId:(f=this.lastMessage)==null?void 0:f.id,...p});return}let E;if("text"in d||"files"in d?E={parts:[...Array.isArray(d.files)?d.files:await LD(d.files),..."text"in d&&d.text!=null?[{type:"text",text:d.text}]:[]]}:E=d,d.messageId!=null){const T=this.state.messages.findIndex(y=>y.id===d.messageId);if(T===-1)throw new Error(`message with id ${d.messageId} not found`);if(this.state.messages[T].role!=="user")throw new Error(`message with id ${d.messageId} is not a user message`);this.state.messages=this.state.messages.slice(0,T+1),this.state.replaceMessage(T,{...E,id:d.messageId,role:(h=E.role)!=null?h:"user",metadata:d.metadata})}else this.state.pushMessage({...E,id:(g=E.id)!=null?g:this.generateId(),role:(b=E.role)!=null?b:"user",metadata:d.metadata});await this.makeRequest({trigger:"submit-message",messageId:d.messageId,...p})},this.regenerate=async({messageId:d,...p}={})=>{const f=d==null?this.state.messages.length-1:this.state.messages.findIndex(h=>h.id===d);if(f===-1)throw new Error(`message ${d} not found`);this.state.messages=this.state.messages.slice(0,this.messages[f].role==="assistant"?f:f+1),await this.makeRequest({trigger:"regenerate-message",messageId:d,...p})},this.resumeStream=async(d={})=>{await this.makeRequest({trigger:"resume-stream",...d})},this.clearError=()=>{this.status==="error"&&(this.state.error=void 0,this.setStatus({status:"ready"}))},this.addToolApprovalResponse=async({id:d,approved:p,reason:f})=>this.jobExecutor.run(async()=>{var h,g;const b=this.state.messages,E=b[b.length-1],T=y=>Um(y)&&y.state==="approval-requested"&&y.approval.id===d?{...y,state:"approval-responded",approval:{id:d,approved:p,reason:f}}:y;this.state.replaceMessage(b.length-1,{...E,parts:E.parts.map(T)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(T)),this.status!=="streaming"&&this.status!=="submitted"&&((h=this.sendAutomaticallyWhen)!=null&&h.call(this,{messages:this.state.messages}))&&this.makeRequest({trigger:"submit-message",messageId:(g=this.lastMessage)==null?void 0:g.id})}),this.addToolOutput=async({state:d="output-available",tool:p,toolCallId:f,output:h,errorText:g})=>this.jobExecutor.run(async()=>{var b,E;const T=this.state.messages,y=T[T.length-1],k=x=>Um(x)&&x.toolCallId===f?{...x,state:d,output:h,errorText:g}:x;this.state.replaceMessage(T.length-1,{...y,parts:y.parts.map(k)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(k)),this.status!=="streaming"&&this.status!=="submitted"&&((b=this.sendAutomaticallyWhen)!=null&&b.call(this,{messages:this.state.messages}))&&this.makeRequest({trigger:"submit-message",messageId:(E=this.lastMessage)==null?void 0:E.id})}),this.addToolResult=this.addToolOutput,this.stop=async()=>{var d;this.status!=="streaming"&&this.status!=="submitted"||(d=this.activeResponse)!=null&&d.abortController&&this.activeResponse.abortController.abort()},this.id=e,this.transport=n,this.generateId=t,this.messageMetadataSchema=r,this.dataPartSchemas=i,this.state=a,this.onError=s,this.onToolCall=o,this.onFinish=l,this.onData=u,this.sendAutomaticallyWhen=c}get status(){return this.state.status}setStatus({status:t,error:e}){this.status!==t&&(this.state.status=t,this.state.error=e)}get error(){return this.state.error}get messages(){return this.state.messages}get lastMessage(){return this.state.messages[this.state.messages.length-1]}set messages(t){this.state.messages=t}async makeRequest({trigger:t,metadata:e,headers:n,body:r,messageId:i}){var a,s,o,l;this.setStatus({status:"submitted",error:void 0});const u=this.lastMessage;let c=!1,d=!1,p=!1;try{const f={state:ND({lastMessage:this.state.snapshot(u),messageId:this.generateId()}),abortController:new AbortController};f.abortController.signal.addEventListener("abort",()=>{c=!0}),this.activeResponse=f;let h;if(t==="resume-stream"){const b=await this.transport.reconnectToStream({chatId:this.id,metadata:e,headers:n,body:r});if(b==null){this.setStatus({status:"ready"});return}h=b}else h=await this.transport.sendMessages({chatId:this.id,messages:this.state.messages,abortSignal:f.abortController.signal,metadata:e,headers:n,body:r,trigger:t,messageId:i});const g=b=>this.jobExecutor.run(()=>b({state:f.state,write:()=>{var E;this.setStatus({status:"streaming"}),f.state.message.id===((E=this.lastMessage)==null?void 0:E.id)?this.state.replaceMessage(this.state.messages.length-1,f.state.message):this.state.pushMessage(f.state.message)}}));await RD({stream:wD({stream:h,onToolCall:this.onToolCall,onData:this.onData,messageMetadataSchema:this.messageMetadataSchema,dataPartSchemas:this.dataPartSchemas,runUpdateMessageJob:g,onError:b=>{throw b}}),onError:b=>{throw b}}),this.setStatus({status:"ready"})}catch(f){if(c||f.name==="AbortError")return c=!0,this.setStatus({status:"ready"}),null;p=!0,f instanceof TypeError&&(f.message.toLowerCase().includes("fetch")||f.message.toLowerCase().includes("network"))&&(d=!0),this.onError&&f instanceof Error&&this.onError(f),this.setStatus({status:"error",error:f})}finally{try{(s=this.onFinish)==null||s.call(this,{message:this.activeResponse.state.message,messages:this.state.messages,isAbort:c,isDisconnect:d,isError:p,finishReason:(a=this.activeResponse)==null?void 0:a.state.finishReason})}catch(f){console.error(f)}this.activeResponse=void 0}(o=this.sendAutomaticallyWhen)!=null&&o.call(this,{messages:this.state.messages})&&!p&&await this.makeRequest({trigger:"submit-message",messageId:(l=this.lastMessage)==null?void 0:l.id,metadata:e,headers:n,body:r})}},eu,l0;function PD(){if(l0)return eu;l0=1;function t(e,n){if(typeof e!="function")throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof e}\`.`);let r,i=0;return function(...s){clearTimeout(r);const o=Date.now(),l=o-i,u=n-l;u<=0?(i=o,e.apply(this,s)):r=setTimeout(()=>{i=Date.now(),e.apply(this,s)},u)}}return eu=t,eu}var FD=PD();const BD=ul(FD);var eC=(t,e,n)=>{if(!e.has(t))throw TypeError("Cannot "+n)},je=(t,e,n)=>(eC(t,e,"read from private field"),n?n.call(t):e.get(t)),yn=(t,e,n)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,n)},Qn=(t,e,n,r)=>(eC(t,e,"write to private field"),e.set(t,n),n);function UD(t,e){return e!=null?BD(t,e):t}var nn,Gs,Vs,oa,la,ua,hi,Hm,$m,HD=class{constructor(t=[]){yn(this,nn,void 0),yn(this,Gs,"ready"),yn(this,Vs,void 0),yn(this,oa,new Set),yn(this,la,new Set),yn(this,ua,new Set),this.pushMessage=e=>{Qn(this,nn,je(this,nn).concat(e)),je(this,hi).call(this)},this.popMessage=()=>{Qn(this,nn,je(this,nn).slice(0,-1)),je(this,hi).call(this)},this.replaceMessage=(e,n)=>{Qn(this,nn,[...je(this,nn).slice(0,e),this.snapshot(n),...je(this,nn).slice(e+1)]),je(this,hi).call(this)},this.snapshot=e=>structuredClone(e),this["~registerMessagesCallback"]=(e,n)=>{const r=n?UD(e,n):e;return je(this,oa).add(r),()=>{je(this,oa).delete(r)}},this["~registerStatusCallback"]=e=>(je(this,la).add(e),()=>{je(this,la).delete(e)}),this["~registerErrorCallback"]=e=>(je(this,ua).add(e),()=>{je(this,ua).delete(e)}),yn(this,hi,()=>{je(this,oa).forEach(e=>e())}),yn(this,Hm,()=>{je(this,la).forEach(e=>e())}),yn(this,$m,()=>{je(this,ua).forEach(e=>e())}),Qn(this,nn,t)}get status(){return je(this,Gs)}set status(t){Qn(this,Gs,t),je(this,Hm).call(this)}get error(){return je(this,Vs)}set error(t){Qn(this,Vs,t),je(this,$m).call(this)}get messages(){return je(this,nn)}set messages(t){Qn(this,nn,[...t]),je(this,hi).call(this)}};nn=new WeakMap;Gs=new WeakMap;Vs=new WeakMap;oa=new WeakMap;la=new WeakMap;ua=new WeakMap;hi=new WeakMap;Hm=new WeakMap;$m=new WeakMap;var mi,u0=class extends MD{constructor({messages:e,...n}){const r=new HD(e);super({...n,state:r}),yn(this,mi,void 0),this["~registerMessagesCallback"]=(i,a)=>je(this,mi)["~registerMessagesCallback"](i,a),this["~registerStatusCallback"]=i=>je(this,mi)["~registerStatusCallback"](i),this["~registerErrorCallback"]=i=>je(this,mi)["~registerErrorCallback"](i),Qn(this,mi,r)}};mi=new WeakMap;function $D({experimental_throttle:t,resume:e=!1,...n}={}){const r=M.useRef("chat"in n?{}:{onToolCall:n.onToolCall,onData:n.onData,onFinish:n.onFinish,onError:n.onError,sendAutomaticallyWhen:n.sendAutomaticallyWhen});"chat"in n||(r.current={onToolCall:n.onToolCall,onData:n.onData,onFinish:n.onFinish,onError:n.onError,sendAutomaticallyWhen:n.sendAutomaticallyWhen});const i={...n,onToolCall:p=>{var f,h;return(h=(f=r.current).onToolCall)==null?void 0:h.call(f,p)},onData:p=>{var f,h;return(h=(f=r.current).onData)==null?void 0:h.call(f,p)},onFinish:p=>{var f,h;return(h=(f=r.current).onFinish)==null?void 0:h.call(f,p)},onError:p=>{var f,h;return(h=(f=r.current).onError)==null?void 0:h.call(f,p)},sendAutomaticallyWhen:p=>{var f,h,g;return(g=(h=(f=r.current).sendAutomaticallyWhen)==null?void 0:h.call(f,p))!=null?g:!1}},a=M.useRef("chat"in n?n.chat:new u0(i));("chat"in n&&n.chat!==a.current||"id"in n&&a.current.id!==n.id)&&(a.current="chat"in n?n.chat:new u0(i));const o=M.useCallback(p=>a.current["~registerMessagesCallback"](p,t),[t,a.current.id]),l=M.useSyncExternalStore(o,()=>a.current.messages,()=>a.current.messages),u=M.useSyncExternalStore(a.current["~registerStatusCallback"],()=>a.current.status,()=>a.current.status),c=M.useSyncExternalStore(a.current["~registerErrorCallback"],()=>a.current.error,()=>a.current.error),d=M.useCallback(p=>{typeof p=="function"&&(p=p(a.current.messages)),a.current.messages=p},[a]);return M.useEffect(()=>{e&&a.current.resumeStream()},[e,a]),{id:a.current.id,messages:l,setMessages:d,sendMessage:a.current.sendMessage,regenerate:a.current.regenerate,clearError:a.current.clearError,stop:a.current.stop,error:c,resumeStream:a.current.resumeStream,status:u,addToolResult:a.current.addToolOutput,addToolOutput:a.current.addToolOutput,addToolApprovalResponse:a.current.addToolApprovalResponse}}function zD(t,e){const n=ne.c(5);let r;n[0]!==e?(r=e===void 0?{}:e,n[0]=e,n[1]=r):r=n[1];const i=r,{org:a}=Gn(),s=t??null;let o;n[2]!==a.id||n[3]!==s?(o={connectionId:s,orgId:a.id},n[2]=a.id,n[3]=s,n[4]=o):o=n[4];const l=Qr(o);return yL(t??"no-connection","LLM",l,i)}function tb(){const t=ne.c(2),e=h_();let n;return t[0]!==e?(n={connections:e,binding:"LLMS"},t[0]=e,t[1]=n):n=t[1],SL(n)}const tC=50;function wre(){const t=ne.c(17),{locator:e,org:n}=Gn();let r;t[0]!==n.id?(r={connectionId:Wg,orgId:n.id},t[0]=n.id,t[1]=r):r=t[1];const i=Qr(r);let a;t[2]!==e?(a=Hi.threads(e),t[2]=e,t[3]=a):a=t[3];let s;t[4]!==i?(s=async b=>{const{pageParam:E}=b,T=E===void 0?0:E;if(!i)throw new Error("MCP client is not available");const y={limit:tC,offset:T},k=await i.callTool({name:"COLLECTION_THREADS_LIST",arguments:y}),x=k.structuredContent??k;return{items:x.items??[],hasMore:x.hasMore??!1,totalCount:x.totalCount}},t[4]=i,t[5]=s):s=t[5];let o;t[6]!==a||t[7]!==s?(o={queryKey:a,queryFn:s,getNextPageParam:qD,initialPageParam:0,staleTime:3e4},t[6]=a,t[7]=s,t[8]=o):o=t[8];const{data:l,fetchNextPage:u,hasNextPage:c,isFetchingNextPage:d,refetch:p}=AL(o);let f;t[9]!==l?.pages?(f=l?.pages.flatMap(jD)??[],t[9]=l?.pages,t[10]=f):f=t[10];const h=f;let g;return t[11]!==u||t[12]!==c||t[13]!==d||t[14]!==p||t[15]!==h?(g={threads:h,refetch:p,hasNextPage:c,isFetchingNextPage:d,fetchNextPage:u},t[11]=u,t[12]=c,t[13]=d,t[14]=p,t[15]=h,t[16]=g):g=t[16],g}function jD(t){return t.items}function qD(t,e){if(t.hasMore)return e.length*tC}function GD(t){const{locator:e,org:n}=Gn(),r=Qr({connectionId:Wg,orgId:n.id}),i="COLLECTION_THREAD_MESSAGES_LIST",{data:a}=s_({queryKey:Hi.threadMessages(e,t??""),queryFn:async()=>{try{if(!t||!r)return[];const s={threadId:t,limit:100,offset:0},o=await r.callTool({name:i,arguments:s});return(o.structuredContent??o).items??[]}catch{return[]}},staleTime:0});return a??[]}function VD(t){const e=ne.c(10);let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n={strict:!1},e[0]=n):n=e[0];const r=o_(n);let i;if(e[1]!==r.collectionName||e[2]!==r.connectionId||e[3]!==r.itemId||e[4]!==t){i=[],t&&i.push(`### Selected Agent
12
12
  - ID: ${t}`);let a;e[6]!==r.collectionName||e[7]!==r.connectionId||e[8]!==r.itemId?(a=[],r.connectionId&&a.push(`- Connection ID: ${r.connectionId}`),r.collectionName&&a.push(`- Collection: ${r.collectionName}`),r.itemId&&a.push(`- Item ID: ${r.itemId}`),e[6]=r.collectionName,e[7]=r.connectionId,e[8]=r.itemId,e[9]=a):a=e[9],a.length>0&&i.push(`### Current Resource
13
13
  The user is viewing the following resource:
14
14
  ${a.join(`
@@ -20,7 +20,7 @@ Help the user understand and work with this resource.`),e[1]=r.collectionName,e[
20
20
  ${r.text}`}):"blob"in r&&r.blob&&r.mimeType&&n.push({type:"file",url:`data:${r.mimeType};base64,${r.blob}`,filename:String(r.uri),mediaType:String(r.mimeType)});return n}function hM(t,e){const n=[];for(const r of t){if(r.role!=="user"||!r.content)continue;const i=Array.isArray(r.content)?r.content:[r.content];for(const a of i)switch(a.type){case"text":{const s=a.text?.trim();if(!s)continue;n.push({type:"text",text:`[${e}]
21
21
  ${s}`});break}case"image":case"audio":{if(!a.data||!a.mimeType)continue;n.push({type:"file",url:`data:${a.mimeType};base64,${a.data}`,mediaType:a.mimeType});break}case"resource":{const s=a.resource;if(!s||!s.mimeType)continue;s&&("text"in s&&s.text?n.push({type:"text",text:`[${e}]
22
22
  ${s.text}`}):"blob"in s&&s.blob&&s.mimeType&&n.push({type:"file",url:`data:${s.mimeType};base64,${s.blob}`,filename:String(s.uri),mediaType:String(s.mimeType)}));break}}}return n}function mM(t,e){const{mimeType:n,data:r}=t;if(n.startsWith("text/"))try{const i=atob(r);return[{type:"text",text:`${e}
23
- ${i}`}]}catch(i){console.error("Failed to decode text file:",i)}return[{type:"file",url:`data:${n};base64,${r}`,filename:e,mediaType:n}]}function gM(t){if(!t)return[];const e=[];let n="";const r=i=>{if(i){if(i.type==="text"&&"text"in i&&typeof i.text=="string")n+=i.text;else if(i.type==="mention"&&i.attrs){const a=i.attrs.char??"/",s=`${a}${i.attrs.name}`;if(n+=s,a==="@"){const o=i.attrs.metadata||[];e.push(...fM(o,s))}else{const o=i.attrs.metadata||i.attrs.prompts||[];e.push(...hM(o,s))}}else if(i.type==="file"&&i.attrs){const a=i.attrs,s=`[file:://${encodeURIComponent(a.name)}]`;n+=s,e.push(...mM(a,s))}if("content"in i&&Array.isArray(i.content))for(const a of i.content)r(a)}};return r(t),n.trim()&&e.unshift({type:"text",text:n.trim()}),e}async function bM(t,e,n){if(!t)throw new Error("MCP client is not available");const r=await t.callTool({name:"COLLECTION_THREADS_UPDATE",arguments:{id:e,data:n}});return(r.structuredContent??r).item}const aC=M.createContext(null);function EM({children:t,initialThreads:e,hasNextPage:n,isFetchingNextPage:r,fetchNextPage:i}){const{locator:a,org:s}=Gn(),[o,l]=ma(so.assistantChatThreads(a),e),[u,c]=ma(so.assistantChatActiveThread(a)+":state",e[0]?.id??crypto.randomUUID()),d=Qr({connectionId:Wg.SELF(s.id),orgId:s.id}),{data:p}=l_.useSession(),f=p?.user??null,[h,g]=M.useReducer(pM,iC),b=f_(),[E,T]=ma(`${a}:selected-virtual-mcp-id`,null),y=tb(),[k,x]=dM(a,y),A=GD(u),v=VD(E),w=WD(),C=E?b.find(te=>te.id===E)??null:null,_=cM(s.slug),z=$D({id:u,messages:A,transport:_,onFinish:async({finishReason:te,messages:pe,isAbort:Te,isDisconnect:Ce,isError:Se})=>{if(g({type:"SET_FINISH_REASON",payload:te??null}),te!=="stop"||Te||Ce||Se)return;const Ie=pe.slice(-1).filter(Boolean);if(Ie.length!==1){console.warn("[chat] Expected 1 message, got",Ie.length);return}const He=pe.find(we=>we.metadata?.title)?.metadata?.title,Me=o.findIndex(we=>we.id===u)===-1;l(Me?we=>{if(we.find(Jt=>Jt.id===u))return we;const Pe=new Date().toISOString(),Ke=Ie[0]?.metadata?.created_at??Pe,Ve=typeof Ke=="string"?Ke:new Date(Ke).toISOString();return[...we,{id:u,title:He??"New Thread",createdAt:Ve,updatedAt:Ve}]}:we=>we.map($e=>$e.id===u?{...$e,updatedAt:new Date().toISOString(),...He&&{title:He}}:$e))},onToolCall:w,onError:te=>{console.error("[chat] Error",te)}}),F=z.status==="submitted"||z.status==="streaming",B=z.messages.length===0,$=te=>g({type:"SET_TIPTAP_DOC",payload:te}),G=()=>g({type:"CLEAR_TIPTAP_DOC"}),H=()=>g({type:"RESET"}),V=async te=>{try{if(await bM(d,te,{hidden:!0})){const Te=te===u,Ce=o.find(Se=>Se.id!==te);Te&&c(Ce?.id??crypto.randomUUID()),l(Se=>Se.filter(Ie=>Ie.id!==te))}}catch(pe){const Te=pe;un.error(`Failed to update thread: ${Te.message}`),console.error("[chat] Failed to update thread:",pe)}},N=te=>{T(te)},K=te=>{x({id:te.id,connectionId:te.connectionId})},ie=async te=>{if(!k){un.error("No model configured");return}const pe=gM(te);if(pe.length===0)return;H();const Te={tiptapDoc:te,created_at:new Date().toISOString(),thread_id:u,cheapModelId:k.cheapModelId,agent:{id:C?.id??null},user:{avatar:f?.image??void 0,name:f?.name??"you"}},Ce={...Te,system:v,model:{id:k.id,connectionId:k.connectionId,provider:k.provider??void 0,limits:k.limits??void 0,capabilities:{vision:k.capabilities?.includes("vision")??void 0,text:k.capabilities?.includes("text")??void 0,tools:k.capabilities?.includes("tools")??void 0}}},Se={id:crypto.randomUUID(),role:"user",parts:pe,metadata:Te};await z.sendMessage(Se,{metadata:Ce})},R=()=>z.stop(),ae=()=>g({type:"CLEAR_FINISH_REASON"}),se={tiptapDoc:h.tiptapDoc,setTiptapDoc:$,clearTiptapDoc:G,resetInteraction:H,activeThreadId:u,threads:o,setActiveThreadId:c,hideThread:V,hasNextPage:n,isFetchingNextPage:r,fetchNextPage:i,virtualMcps:b,selectedVirtualMcp:C,setVirtualMcpId:N,modelsConnections:y,selectedModel:k,setSelectedModel:K,messages:z.messages,chatStatus:z.status,isStreaming:F,isChatEmpty:B,sendMessage:ie,stopStreaming:R,setMessages:z.setMessages,chatError:z.error,clearChatError:z.clearError,finishReason:h.finishReason,clearFinishReason:ae};return S.jsx(aC.Provider,{value:se,children:t})}function cs(){const t=M.useContext(aC);if(!t)throw new Error("useChat must be used within a ChatProvider");return t}function yM(t){return(t.costs?.input??0)+(t.costs?.output??0)>0}function TM(t,e){const n=e.costs?.input??0,r=e.costs?.output??0,i=(t?.costs?.input??0)+(t?.costs?.output??0);return!t||i===0||n+r<i?e:t}function SM(t){const e={};for(const n of t.arguments??[])e[n.name]=n.required?ee().min(1,"Required"):ee();return Oe(e)}function AM(t){const e={};for(const n of t.arguments??[])e[n.name]="";return e}function sC(t){const e=ne.c(64),{prompt:n,setPrompt:r,onSubmit:i}=t,a=M.useId();let s;if(e[0]!==n){const H=n?SM(n):Oe({});s=KO(H),e[0]=n,e[1]=s}else s=e[1];const l=s;let u;e[2]!==n?(u=n?AM(n):{},e[2]=n,e[3]=u):u=e[3];let c;e[4]!==l||e[5]!==u?(c={resolver:l,defaultValues:u,mode:"onChange"},e[4]=l,e[5]=u,e[6]=c):c=e[6];const d=XO(c);let p;e[7]!==n?.arguments?(p=n?.arguments??[],e[7]=n?.arguments,e[8]=p):p=e[8];const f=p;let h;e[9]!==d||e[10]!==i||e[11]!==r?(h=async H=>{await i(H),r(null),d.reset()},e[9]=d,e[10]=i,e[11]=r,e[12]=h):h=e[12];const g=h;let b;e[13]!==d||e[14]!==r?(b=H=>{H||(d.reset(),r(null))},e[13]=d,e[14]=r,e[15]=b):b=e[15];const E=b;if(!n)return null;let T;e[16]!==n.name||e[17]!==n.title?(T=n.title||n.name.replace(/_/g," "),e[16]=n.name,e[17]=n.title,e[18]=T):T=e[18];let y;e[19]!==T?(y=S.jsx(ML,{children:T}),e[19]=T,e[20]=y):y=e[20];let k;e[21]!==n.description?(k=n.description&&S.jsx("p",{className:"text-sm text-muted-foreground",children:n.description}),e[21]=n.description,e[22]=k):k=e[22];let x;e[23]!==k||e[24]!==y?(x=S.jsxs(PL,{children:[y,k]}),e[23]=k,e[24]=y,e[25]=x):x=e[25];let A;e[26]!==d||e[27]!==g?(A=H=>{H.stopPropagation(),d.handleSubmit(g)(H)},e[26]=d,e[27]=g,e[28]=A):A=e[28];let v;if(e[29]!==f||e[30]!==d.control||e[31]!==d.formState.isSubmitting){let H;e[33]!==d.control||e[34]!==d.formState.isSubmitting?(H=V=>S.jsx($L,{control:d.control,name:V.name,render:N=>{const{field:K}=N;return S.jsxs(zL,{children:[S.jsxs(jL,{className:"text-xs",children:[V.name,V.required?null:S.jsxs("span",{className:"text-muted-foreground font-normal",children:[" ","(optional)"]})]}),S.jsx(qL,{children:S.jsx(Yg,{...K,value:K.value??"",required:V.required,placeholder:V.description??"",className:"h-9",disabled:d.formState.isSubmitting})}),S.jsx(GL,{})]})}},V.name),e[33]=d.control,e[34]=d.formState.isSubmitting,e[35]=H):H=e[35],v=f.map(H),e[29]=f,e[30]=d.control,e[31]=d.formState.isSubmitting,e[32]=v}else v=e[32];let w;e[36]!==E?(w=()=>E(!1),e[36]=E,e[37]=w):w=e[37];let C;e[38]!==d.formState.isSubmitting||e[39]!==w?(C=S.jsx(gt,{type:"button",variant:"ghost",onClick:w,disabled:d.formState.isSubmitting,children:"Cancel"}),e[38]=d.formState.isSubmitting,e[39]=w,e[40]=C):C=e[40];const _=!d.formState.isValid||d.formState.isSubmitting;let D;e[41]!==d.formState.isSubmitting?(D=d.formState.isSubmitting?S.jsxs("span",{className:"flex items-center gap-2",children:[S.jsx(dl,{size:"xs"}),"Loading..."]}):"Use prompt",e[41]=d.formState.isSubmitting,e[42]=D):D=e[42];let P;e[43]!==a||e[44]!==_||e[45]!==D?(P=S.jsx(gt,{type:"submit",form:a,disabled:_,children:D}),e[43]=a,e[44]=_,e[45]=D,e[46]=P):P=e[46];let z;e[47]!==C||e[48]!==P?(z=S.jsxs(FL,{children:[C,P]}),e[47]=C,e[48]=P,e[49]=z):z=e[49];let F;e[50]!==a||e[51]!==A||e[52]!==v||e[53]!==z?(F=S.jsxs("form",{id:a,className:"space-y-4 py-4",autoComplete:"off",onSubmit:A,children:[v,z]}),e[50]=a,e[51]=A,e[52]=v,e[53]=z,e[54]=F):F=e[54];let B;e[55]!==d||e[56]!==F?(B=S.jsx(HL,{...d,children:F}),e[55]=d,e[56]=F,e[57]=B):B=e[57];let $;e[58]!==x||e[59]!==B?($=S.jsxs(BL,{className:"sm:max-w-lg max-h-[80vh] overflow-y-auto",children:[x,B]}),e[58]=x,e[59]=B,e[60]=$):$=e[60];let G;return e[61]!==E||e[62]!==$?(G=S.jsx(UL,{open:!0,onOpenChange:E,children:$}),e[61]=E,e[62]=$,e[63]=G):G=e[63],G}function ft(t){this.content=t}ft.prototype={constructor:ft,find:function(t){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===t)return e;return-1},get:function(t){var e=this.find(t);return e==-1?void 0:this.content[e+1]},update:function(t,e,n){var r=n&&n!=t?this.remove(n):this,i=r.find(t),a=r.content.slice();return i==-1?a.push(n||t,e):(a[i+1]=e,n&&(a[i]=n)),new ft(a)},remove:function(t){var e=this.find(t);if(e==-1)return this;var n=this.content.slice();return n.splice(e,2),new ft(n)},addToStart:function(t,e){return new ft([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var n=this.remove(t).content.slice();return n.push(t,e),new ft(n)},addBefore:function(t,e,n){var r=this.remove(e),i=r.content.slice(),a=r.find(t);return i.splice(a==-1?i.length:a,0,e,n),new ft(i)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+1])},prepend:function(t){return t=ft.from(t),t.size?new ft(t.content.concat(this.subtract(t).content)):this},append:function(t){return t=ft.from(t),t.size?new ft(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=ft.from(t);for(var n=0;n<t.content.length;n+=2)e=e.remove(t.content[n]);return e},toObject:function(){var t={};return this.forEach(function(e,n){t[e]=n}),t},get size(){return this.content.length>>1}};ft.from=function(t){if(t instanceof ft)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new ft(e)};function oC(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),a=e.child(r);if(i==a){n+=i.nodeSize;continue}if(!i.sameMarkup(a))return n;if(i.isText&&i.text!=a.text){for(let s=0;i.text[s]==a.text[s];s++)n++;return n}if(i.content.size||a.content.size){let s=oC(i.content,a.content,n+1);if(s!=null)return s}n+=i.nodeSize}}function lC(t,e,n,r){for(let i=t.childCount,a=e.childCount;;){if(i==0||a==0)return i==a?null:{a:n,b:r};let s=t.child(--i),o=e.child(--a),l=s.nodeSize;if(s==o){n-=l,r-=l;continue}if(!s.sameMarkup(o))return{a:n,b:r};if(s.isText&&s.text!=o.text){let u=0,c=Math.min(s.text.length,o.text.length);for(;u<c&&s.text[s.text.length-u-1]==o.text[o.text.length-u-1];)u++,n--,r--;return{a:n,b:r}}if(s.content.size||o.content.size){let u=lC(s.content,o.content,n-1,r-1);if(u)return u}n-=l,r-=l}}class Y{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,n,r,i=0,a){for(let s=0,o=0;o<n;s++){let l=this.content[s],u=o+l.nodeSize;if(u>e&&r(l,i+o,a||null,s)!==!1&&l.content.size){let c=o+1;l.nodesBetween(Math.max(0,e-c),Math.min(l.content.size,n-c),r,i+c)}o=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let a="",s=!0;return this.nodesBetween(e,n,(o,l)=>{let u=o.isText?o.text.slice(Math.max(e,l)-l,n-l):o.isLeaf?i?typeof i=="function"?i(o):i:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&u||o.isTextblock)&&r&&(s?s=!1:a+=r),a+=u},0),a}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);a<e.content.length;a++)i.push(e.content[a]);return new Y(i,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let r=[],i=0;if(n>e)for(let a=0,s=0;s<n;a++){let o=this.content[a],l=s+o.nodeSize;l>e&&((s<e||l>n)&&(o.isText?o=o.cut(Math.max(0,e-s),Math.min(o.text.length,n-s)):o=o.cut(Math.max(0,e-s-1),Math.min(o.content.size,n-s-1))),r.push(o),i+=o.nodeSize),s=l}return new Y(r,i)}cutByIndex(e,n){return e==n?Y.empty:e==0&&n==this.content.length?this:new Y(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new Y(i,a)}addToStart(e){return new Y([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new Y(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,r=0;n<this.content.length;n++){let i=this.content[n];e(i,r,n),r+=i.nodeSize}}findDiffStart(e,n=0){return oC(this,e,n)}findDiffEnd(e,n=this.size,r=e.size){return lC(this,e,n,r)}findIndex(e){if(e==0)return ks(0,e);if(e==this.size)return ks(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let i=this.child(n),a=r+i.nodeSize;if(a>=e)return a==e?ks(n+1,a):ks(n,r);r=a}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return Y.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new Y(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return Y.empty;let n,r=0;for(let i=0;i<e.length;i++){let a=e[i];r+=a.nodeSize,i&&a.isText&&e[i-1].sameMarkup(a)?(n||(n=e.slice(0,i)),n[n.length-1]=a.withText(n[n.length-1].text+a.text)):n&&n.push(a)}return new Y(n||e,r)}static from(e){if(!e)return Y.empty;if(e instanceof Y)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new Y([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}Y.empty=new Y([],0);const tu={index:0,offset:0};function ks(t,e){return tu.index=t,tu.offset=e,tu}function lo(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!lo(t[r],e[r]))return!1}else{for(let r in t)if(!(r in e)||!lo(t[r],e[r]))return!1;for(let r in e)if(!(r in t))return!1}return!0}let Fe=class jm{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,r=!1;for(let i=0;i<e.length;i++){let a=e[i];if(this.eq(a))return e;if(this.type.excludes(a.type))n||(n=e.slice(0,i));else{if(a.type.excludes(this.type))return e;!r&&a.type.rank>this.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(a)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&lo(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);let i=r.create(n.attrs);return r.checkAttrs(i.attrs),i}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(n[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return jm.none;if(e instanceof jm)return[e];let n=e.slice();return n.sort((r,i)=>r.type.rank-i.type.rank),n}};Fe.none=[];class uo extends Error{}class re{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=cC(this.content,e+this.openStart,n);return r&&new re(r,this.openStart,this.openEnd)}removeBetween(e,n){return new re(uC(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return re.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new re(Y.fromJSON(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let a=e.firstChild;a&&!a.isLeaf&&(n||!a.type.spec.isolating);a=a.firstChild)r++;for(let a=e.lastChild;a&&!a.isLeaf&&(n||!a.type.spec.isolating);a=a.lastChild)i++;return new re(e,r,i)}}re.empty=new re(Y.empty,0,0);function uC(t,e,n){let{index:r,offset:i}=t.findIndex(e),a=t.maybeChild(r),{index:s,offset:o}=t.findIndex(n);if(i==e||a.isText){if(o!=n&&!t.child(s).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=s)throw new RangeError("Removing non-flat range");return t.replaceChild(r,a.copy(uC(a.content,e-i-1,n-i-1)))}function cC(t,e,n,r){let{index:i,offset:a}=t.findIndex(e),s=t.maybeChild(i);if(a==e||s.isText)return r&&!r.canReplace(i,i,n)?null:t.cut(0,e).append(n).append(t.cut(e));let o=cC(s.content,e-a-1,n,s);return o&&t.replaceChild(i,s.copy(o))}function kM(t,e,n){if(n.openStart>t.depth)throw new uo("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new uo("Inconsistent open depths");return dC(t,e,n,0)}function dC(t,e,n,r){let i=t.index(r),a=t.node(r);if(i==e.index(r)&&r<t.depth-n.openStart){let s=dC(t,e,n,r+1);return a.copy(a.content.replaceChild(i,s))}else if(n.content.size)if(!n.openStart&&!n.openEnd&&t.depth==r&&e.depth==r){let s=t.parent,o=s.content;return Br(s,o.cut(0,t.parentOffset).append(n.content).append(o.cut(e.parentOffset)))}else{let{start:s,end:o}=xM(n,t);return Br(a,fC(t,s,o,e,r))}else return Br(a,co(t,e,r))}function pC(t,e){if(!e.type.compatibleContent(t.type))throw new uo("Cannot join "+e.type.name+" onto "+t.type.name)}function qm(t,e,n){let r=t.node(n);return pC(r,e.node(n)),r}function Fr(t,e){let n=e.length-1;n>=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function ga(t,e,n,r){let i=(e||t).node(n),a=0,s=e?e.index(n):i.childCount;t&&(a=t.index(n),t.depth>n?a++:t.textOffset&&(Fr(t.nodeAfter,r),a++));for(let o=a;o<s;o++)Fr(i.child(o),r);e&&e.depth==n&&e.textOffset&&Fr(e.nodeBefore,r)}function Br(t,e){return t.type.checkContent(e),t.copy(e)}function fC(t,e,n,r,i){let a=t.depth>i&&qm(t,e,i+1),s=r.depth>i&&qm(n,r,i+1),o=[];return ga(null,t,i,o),a&&s&&e.index(i)==n.index(i)?(pC(a,s),Fr(Br(a,fC(t,e,n,r,i+1)),o)):(a&&Fr(Br(a,co(t,e,i+1)),o),ga(e,n,i,o),s&&Fr(Br(s,co(n,r,i+1)),o)),ga(r,null,i,o),new Y(o)}function co(t,e,n){let r=[];if(ga(null,t,n,r),t.depth>n){let i=qm(t,e,n+1);Fr(Br(i,co(t,e,n+1)),r)}return ga(e,null,n,r),new Y(r)}function xM(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let a=n-1;a>=0;a--)i=e.node(a).copy(Y.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}class Ua{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(n);return r?e.child(n).cut(r):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let a=0;a<e;a++)i+=r.child(a).nodeSize;return i}marks(){let e=this.parent,n=this.index();if(e.content.size==0)return Fe.none;if(this.textOffset)return e.child(n).marks;let r=e.maybeChild(n-1),i=e.maybeChild(n);if(!r){let o=r;r=i,i=o}let a=r.marks;for(var s=0;s<a.length;s++)a[s].type.spec.inclusive===!1&&(!i||!a[s].isInSet(i.marks))&&(a=a[s--].removeFromSet(a));return a}marksAcross(e){let n=this.parent.maybeChild(this.index());if(!n||!n.isInline)return null;let r=n.marks,i=e.parent.maybeChild(e.index());for(var a=0;a<r.length;a++)r[a].type.spec.inclusive===!1&&(!i||!r[a].isInSet(i.marks))&&(r=r[a--].removeFromSet(r));return r}sharedDepth(e){for(let n=this.depth;n>0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos<this.pos)return e.blockRange(this);for(let r=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);r>=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new po(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let n=1;n<=this.depth;n++)e+=(e?"/":"")+this.node(n).type.name+"_"+this.index(n-1);return e+":"+this.parentOffset}static resolve(e,n){if(!(n>=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],i=0,a=n;for(let s=e;;){let{index:o,offset:l}=s.content.findIndex(a),u=a-l;if(r.push(s,o,i+l),!u||(s=s.child(o),s.isText))break;a=u-1,i+=l+1}return new Ua(n,r,a)}static resolveCached(e,n){let r=d0.get(e);if(r)for(let a=0;a<r.elts.length;a++){let s=r.elts[a];if(s.pos==n)return s}else d0.set(e,r=new vM);let i=r.elts[r.i]=Ua.resolve(e,n);return r.i=(r.i+1)%_M,i}}class vM{constructor(){this.elts=[],this.i=0}}const _M=12,d0=new WeakMap;class po{constructor(e,n,r){this.$from=e,this.$to=n,this.depth=r}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const CM=Object.create(null);let hr=class Gm{constructor(e,n,r,i=Fe.none){this.type=e,this.attrs=n,this.marks=i,this.content=r||Y.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,n,r,i=0){this.content.nodesBetween(e,n,r,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,n,r,i){return this.content.textBetween(e,n,r,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,n,r){return this.type==e&&lo(this.attrs,n||e.defaultAttrs||CM)&&Fe.sameSet(this.marks,r||Fe.none)}copy(e=null){return e==this.content?this:new Gm(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new Gm(this.type,this.attrs,this.content,e)}cut(e,n=this.content.size){return e==0&&n==this.content.size?this:this.copy(this.content.cut(e,n))}slice(e,n=this.content.size,r=!1){if(e==n)return re.empty;let i=this.resolve(e),a=this.resolve(n),s=r?0:i.sharedDepth(n),o=i.start(s),u=i.node(s).content.cut(i.pos-o,a.pos-o);return new re(u,i.depth-s,a.depth-s)}replace(e,n,r){return kM(this.resolve(e),this.resolve(n),r)}nodeAt(e){for(let n=this;;){let{index:r,offset:i}=n.content.findIndex(e);if(n=n.maybeChild(r),!n)return null;if(i==e||n.isText)return n;e-=i+1}}childAfter(e){let{index:n,offset:r}=this.content.findIndex(e);return{node:this.content.maybeChild(n),index:n,offset:r}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:n,offset:r}=this.content.findIndex(e);if(r<e)return{node:this.content.child(n),index:n,offset:r};let i=this.content.child(n-1);return{node:i,index:n-1,offset:r-i.nodeSize}}resolve(e){return Ua.resolveCached(this,e)}resolveNoCache(e){return Ua.resolve(this,e)}rangeHasMark(e,n,r){let i=!1;return n>e&&this.nodesBetween(e,n,a=>(r.isInSet(a.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),hC(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=Y.empty,i=0,a=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,a),o=s&&s.matchFragment(this.content,n);if(!o||!o.validEnd)return!1;for(let l=i;l<a;l++)if(!this.type.allowsMarks(r.child(l).marks))return!1;return!0}canReplaceWith(e,n,r,i){if(i&&!this.type.allowsMarks(i))return!1;let a=this.contentMatchAt(e).matchType(r),s=a&&a.matchFragment(this.content,n);return s?s.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=Fe.none;for(let n=0;n<this.marks.length;n++){let r=this.marks[n];r.type.checkAttrs(r.attrs),e=r.addToSet(e)}if(!Fe.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(n=>n.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let i=Y.fromJSON(e,n.content),a=e.nodeType(n.type).create(n.attrs,i,r);return a.type.checkAttrs(a.attrs),a}};hr.prototype.text=void 0;class fo extends hr{constructor(e,n,r,i){if(super(e,n,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):hC(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new fo(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new fo(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function hC(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class Gr{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new IM(e,n);if(r.next==null)return Gr.empty;let i=mC(r);r.next&&r.err("Unexpected trailing text");let a=MM(DM(i));return PM(a,r),a}matchType(e){for(let n=0;n<this.next.length;n++)if(this.next[n].type==e)return this.next[n].next;return null}matchFragment(e,n=0,r=e.childCount){let i=this;for(let a=n;i&&a<r;a++)i=i.matchType(e.child(a).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:n}=this.next[e];if(!(n.isText||n.hasRequiredAttrs()))return n}return null}compatible(e){for(let n=0;n<this.next.length;n++)for(let r=0;r<e.next.length;r++)if(this.next[n].type==e.next[r].type)return!0;return!1}fillBefore(e,n=!1,r=0){let i=[this];function a(s,o){let l=s.matchFragment(e,r);if(l&&(!n||l.validEnd))return Y.from(o.map(u=>u.createAndFill()));for(let u=0;u<s.next.length;u++){let{type:c,next:d}=s.next[u];if(!(c.isText||c.hasRequiredAttrs())&&i.indexOf(d)==-1){i.push(d);let p=a(d,o.concat(c));if(p)return p}}return null}return a(this,[])}findWrapping(e){for(let r=0;r<this.wrapCache.length;r+=2)if(this.wrapCache[r]==e)return this.wrapCache[r+1];let n=this.computeWrapping(e);return this.wrapCache.push(e,n),n}computeWrapping(e){let n=Object.create(null),r=[{match:this,type:null,via:null}];for(;r.length;){let i=r.shift(),a=i.match;if(a.matchType(e)){let s=[];for(let o=i;o.type;o=o.via)s.push(o.type);return s.reverse()}for(let s=0;s<a.next.length;s++){let{type:o,next:l}=a.next[s];!o.isLeaf&&!o.hasRequiredAttrs()&&!(o.name in n)&&(!i.type||l.validEnd)&&(r.push({match:o.contentMatch,type:o,via:i}),n[o.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let i=0;i<r.next.length;i++)e.indexOf(r.next[i].next)==-1&&n(r.next[i].next)}return n(this),e.map((r,i)=>{let a=i+(r.validEnd?"*":" ")+" ";for(let s=0;s<r.next.length;s++)a+=(s?", ":"")+r.next[s].type.name+"->"+e.indexOf(r.next[s].next);return a}).join(`
23
+ ${i}`}]}catch(i){console.error("Failed to decode text file:",i)}return[{type:"file",url:`data:${n};base64,${r}`,filename:e,mediaType:n}]}function gM(t){if(!t)return[];const e=[];let n="";const r=i=>{if(i){if(i.type==="text"&&"text"in i&&typeof i.text=="string")n+=i.text;else if(i.type==="mention"&&i.attrs){const a=i.attrs.char??"/",s=`${a}${i.attrs.name}`;if(n+=s,a==="@"){const o=i.attrs.metadata||[];e.push(...fM(o,s))}else{const o=i.attrs.metadata||i.attrs.prompts||[];e.push(...hM(o,s))}}else if(i.type==="file"&&i.attrs){const a=i.attrs,s=`[file:://${encodeURIComponent(a.name)}]`;n+=s,e.push(...mM(a,s))}if("content"in i&&Array.isArray(i.content))for(const a of i.content)r(a)}};return r(t),n.trim()&&e.unshift({type:"text",text:n.trim()}),e}async function bM(t,e,n){if(!t)throw new Error("MCP client is not available");const r=await t.callTool({name:"COLLECTION_THREADS_UPDATE",arguments:{id:e,data:n}});return(r.structuredContent??r).item}const aC=M.createContext(null);function EM({children:t,initialThreads:e,hasNextPage:n,isFetchingNextPage:r,fetchNextPage:i}){const{locator:a,org:s}=Gn(),[o,l]=ma(so.assistantChatThreads(a),e),[u,c]=ma(so.assistantChatActiveThread(a)+":state",e[0]?.id??crypto.randomUUID()),d=Qr({connectionId:Wg,orgId:s.id}),{data:p}=l_.useSession(),f=p?.user??null,[h,g]=M.useReducer(pM,iC),b=f_(),[E,T]=ma(`${a}:selected-virtual-mcp-id`,null),y=tb(),[k,x]=dM(a,y),A=GD(u),v=VD(E),w=WD(),C=E?b.find(te=>te.id===E)??null:null,_=cM(s.slug),z=$D({id:u,messages:A,transport:_,onFinish:async({finishReason:te,messages:pe,isAbort:Te,isDisconnect:Ce,isError:Se})=>{if(g({type:"SET_FINISH_REASON",payload:te??null}),te!=="stop"||Te||Ce||Se)return;const Ie=pe.slice(-1).filter(Boolean);if(Ie.length!==1){console.warn("[chat] Expected 1 message, got",Ie.length);return}const He=pe.find(we=>we.metadata?.title)?.metadata?.title,Me=o.findIndex(we=>we.id===u)===-1;l(Me?we=>{if(we.find(Jt=>Jt.id===u))return we;const Pe=new Date().toISOString(),Ke=Ie[0]?.metadata?.created_at??Pe,Ve=typeof Ke=="string"?Ke:new Date(Ke).toISOString();return[...we,{id:u,title:He??"New Thread",createdAt:Ve,updatedAt:Ve}]}:we=>we.map($e=>$e.id===u?{...$e,updatedAt:new Date().toISOString(),...He&&{title:He}}:$e))},onToolCall:w,onError:te=>{console.error("[chat] Error",te)}}),F=z.status==="submitted"||z.status==="streaming",B=z.messages.length===0,$=te=>g({type:"SET_TIPTAP_DOC",payload:te}),G=()=>g({type:"CLEAR_TIPTAP_DOC"}),H=()=>g({type:"RESET"}),V=async te=>{try{if(await bM(d,te,{hidden:!0})){const Te=te===u,Ce=o.find(Se=>Se.id!==te);Te&&c(Ce?.id??crypto.randomUUID()),l(Se=>Se.filter(Ie=>Ie.id!==te))}}catch(pe){const Te=pe;un.error(`Failed to update thread: ${Te.message}`),console.error("[chat] Failed to update thread:",pe)}},N=te=>{T(te)},K=te=>{x({id:te.id,connectionId:te.connectionId})},ie=async te=>{if(!k){un.error("No model configured");return}const pe=gM(te);if(pe.length===0)return;H();const Te={tiptapDoc:te,created_at:new Date().toISOString(),thread_id:u,cheapModelId:k.cheapModelId,agent:{id:C?.id??null},user:{avatar:f?.image??void 0,name:f?.name??"you"}},Ce={...Te,system:v,model:{id:k.id,connectionId:k.connectionId,provider:k.provider??void 0,limits:k.limits??void 0,capabilities:{vision:k.capabilities?.includes("vision")??void 0,text:k.capabilities?.includes("text")??void 0,tools:k.capabilities?.includes("tools")??void 0}}},Se={id:crypto.randomUUID(),role:"user",parts:pe,metadata:Te};await z.sendMessage(Se,{metadata:Ce})},R=()=>z.stop(),ae=()=>g({type:"CLEAR_FINISH_REASON"}),se={tiptapDoc:h.tiptapDoc,setTiptapDoc:$,clearTiptapDoc:G,resetInteraction:H,activeThreadId:u,threads:o,setActiveThreadId:c,hideThread:V,hasNextPage:n,isFetchingNextPage:r,fetchNextPage:i,virtualMcps:b,selectedVirtualMcp:C,setVirtualMcpId:N,modelsConnections:y,selectedModel:k,setSelectedModel:K,messages:z.messages,chatStatus:z.status,isStreaming:F,isChatEmpty:B,sendMessage:ie,stopStreaming:R,setMessages:z.setMessages,chatError:z.error,clearChatError:z.clearError,finishReason:h.finishReason,clearFinishReason:ae};return S.jsx(aC.Provider,{value:se,children:t})}function cs(){const t=M.useContext(aC);if(!t)throw new Error("useChat must be used within a ChatProvider");return t}function yM(t){return(t.costs?.input??0)+(t.costs?.output??0)>0}function TM(t,e){const n=e.costs?.input??0,r=e.costs?.output??0,i=(t?.costs?.input??0)+(t?.costs?.output??0);return!t||i===0||n+r<i?e:t}function SM(t){const e={};for(const n of t.arguments??[])e[n.name]=n.required?ee().min(1,"Required"):ee();return Oe(e)}function AM(t){const e={};for(const n of t.arguments??[])e[n.name]="";return e}function sC(t){const e=ne.c(64),{prompt:n,setPrompt:r,onSubmit:i}=t,a=M.useId();let s;if(e[0]!==n){const H=n?SM(n):Oe({});s=KO(H),e[0]=n,e[1]=s}else s=e[1];const l=s;let u;e[2]!==n?(u=n?AM(n):{},e[2]=n,e[3]=u):u=e[3];let c;e[4]!==l||e[5]!==u?(c={resolver:l,defaultValues:u,mode:"onChange"},e[4]=l,e[5]=u,e[6]=c):c=e[6];const d=XO(c);let p;e[7]!==n?.arguments?(p=n?.arguments??[],e[7]=n?.arguments,e[8]=p):p=e[8];const f=p;let h;e[9]!==d||e[10]!==i||e[11]!==r?(h=async H=>{await i(H),r(null),d.reset()},e[9]=d,e[10]=i,e[11]=r,e[12]=h):h=e[12];const g=h;let b;e[13]!==d||e[14]!==r?(b=H=>{H||(d.reset(),r(null))},e[13]=d,e[14]=r,e[15]=b):b=e[15];const E=b;if(!n)return null;let T;e[16]!==n.name||e[17]!==n.title?(T=n.title||n.name.replace(/_/g," "),e[16]=n.name,e[17]=n.title,e[18]=T):T=e[18];let y;e[19]!==T?(y=S.jsx(ML,{children:T}),e[19]=T,e[20]=y):y=e[20];let k;e[21]!==n.description?(k=n.description&&S.jsx("p",{className:"text-sm text-muted-foreground",children:n.description}),e[21]=n.description,e[22]=k):k=e[22];let x;e[23]!==k||e[24]!==y?(x=S.jsxs(PL,{children:[y,k]}),e[23]=k,e[24]=y,e[25]=x):x=e[25];let A;e[26]!==d||e[27]!==g?(A=H=>{H.stopPropagation(),d.handleSubmit(g)(H)},e[26]=d,e[27]=g,e[28]=A):A=e[28];let v;if(e[29]!==f||e[30]!==d.control||e[31]!==d.formState.isSubmitting){let H;e[33]!==d.control||e[34]!==d.formState.isSubmitting?(H=V=>S.jsx($L,{control:d.control,name:V.name,render:N=>{const{field:K}=N;return S.jsxs(zL,{children:[S.jsxs(jL,{className:"text-xs",children:[V.name,V.required?null:S.jsxs("span",{className:"text-muted-foreground font-normal",children:[" ","(optional)"]})]}),S.jsx(qL,{children:S.jsx(Yg,{...K,value:K.value??"",required:V.required,placeholder:V.description??"",className:"h-9",disabled:d.formState.isSubmitting})}),S.jsx(GL,{})]})}},V.name),e[33]=d.control,e[34]=d.formState.isSubmitting,e[35]=H):H=e[35],v=f.map(H),e[29]=f,e[30]=d.control,e[31]=d.formState.isSubmitting,e[32]=v}else v=e[32];let w;e[36]!==E?(w=()=>E(!1),e[36]=E,e[37]=w):w=e[37];let C;e[38]!==d.formState.isSubmitting||e[39]!==w?(C=S.jsx(gt,{type:"button",variant:"ghost",onClick:w,disabled:d.formState.isSubmitting,children:"Cancel"}),e[38]=d.formState.isSubmitting,e[39]=w,e[40]=C):C=e[40];const _=!d.formState.isValid||d.formState.isSubmitting;let D;e[41]!==d.formState.isSubmitting?(D=d.formState.isSubmitting?S.jsxs("span",{className:"flex items-center gap-2",children:[S.jsx(dl,{size:"xs"}),"Loading..."]}):"Use prompt",e[41]=d.formState.isSubmitting,e[42]=D):D=e[42];let P;e[43]!==a||e[44]!==_||e[45]!==D?(P=S.jsx(gt,{type:"submit",form:a,disabled:_,children:D}),e[43]=a,e[44]=_,e[45]=D,e[46]=P):P=e[46];let z;e[47]!==C||e[48]!==P?(z=S.jsxs(FL,{children:[C,P]}),e[47]=C,e[48]=P,e[49]=z):z=e[49];let F;e[50]!==a||e[51]!==A||e[52]!==v||e[53]!==z?(F=S.jsxs("form",{id:a,className:"space-y-4 py-4",autoComplete:"off",onSubmit:A,children:[v,z]}),e[50]=a,e[51]=A,e[52]=v,e[53]=z,e[54]=F):F=e[54];let B;e[55]!==d||e[56]!==F?(B=S.jsx(HL,{...d,children:F}),e[55]=d,e[56]=F,e[57]=B):B=e[57];let $;e[58]!==x||e[59]!==B?($=S.jsxs(BL,{className:"sm:max-w-lg max-h-[80vh] overflow-y-auto",children:[x,B]}),e[58]=x,e[59]=B,e[60]=$):$=e[60];let G;return e[61]!==E||e[62]!==$?(G=S.jsx(UL,{open:!0,onOpenChange:E,children:$}),e[61]=E,e[62]=$,e[63]=G):G=e[63],G}function ft(t){this.content=t}ft.prototype={constructor:ft,find:function(t){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===t)return e;return-1},get:function(t){var e=this.find(t);return e==-1?void 0:this.content[e+1]},update:function(t,e,n){var r=n&&n!=t?this.remove(n):this,i=r.find(t),a=r.content.slice();return i==-1?a.push(n||t,e):(a[i+1]=e,n&&(a[i]=n)),new ft(a)},remove:function(t){var e=this.find(t);if(e==-1)return this;var n=this.content.slice();return n.splice(e,2),new ft(n)},addToStart:function(t,e){return new ft([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var n=this.remove(t).content.slice();return n.push(t,e),new ft(n)},addBefore:function(t,e,n){var r=this.remove(e),i=r.content.slice(),a=r.find(t);return i.splice(a==-1?i.length:a,0,e,n),new ft(i)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+1])},prepend:function(t){return t=ft.from(t),t.size?new ft(t.content.concat(this.subtract(t).content)):this},append:function(t){return t=ft.from(t),t.size?new ft(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=ft.from(t);for(var n=0;n<t.content.length;n+=2)e=e.remove(t.content[n]);return e},toObject:function(){var t={};return this.forEach(function(e,n){t[e]=n}),t},get size(){return this.content.length>>1}};ft.from=function(t){if(t instanceof ft)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new ft(e)};function oC(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),a=e.child(r);if(i==a){n+=i.nodeSize;continue}if(!i.sameMarkup(a))return n;if(i.isText&&i.text!=a.text){for(let s=0;i.text[s]==a.text[s];s++)n++;return n}if(i.content.size||a.content.size){let s=oC(i.content,a.content,n+1);if(s!=null)return s}n+=i.nodeSize}}function lC(t,e,n,r){for(let i=t.childCount,a=e.childCount;;){if(i==0||a==0)return i==a?null:{a:n,b:r};let s=t.child(--i),o=e.child(--a),l=s.nodeSize;if(s==o){n-=l,r-=l;continue}if(!s.sameMarkup(o))return{a:n,b:r};if(s.isText&&s.text!=o.text){let u=0,c=Math.min(s.text.length,o.text.length);for(;u<c&&s.text[s.text.length-u-1]==o.text[o.text.length-u-1];)u++,n--,r--;return{a:n,b:r}}if(s.content.size||o.content.size){let u=lC(s.content,o.content,n-1,r-1);if(u)return u}n-=l,r-=l}}class Y{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,n,r,i=0,a){for(let s=0,o=0;o<n;s++){let l=this.content[s],u=o+l.nodeSize;if(u>e&&r(l,i+o,a||null,s)!==!1&&l.content.size){let c=o+1;l.nodesBetween(Math.max(0,e-c),Math.min(l.content.size,n-c),r,i+c)}o=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let a="",s=!0;return this.nodesBetween(e,n,(o,l)=>{let u=o.isText?o.text.slice(Math.max(e,l)-l,n-l):o.isLeaf?i?typeof i=="function"?i(o):i:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&u||o.isTextblock)&&r&&(s?s=!1:a+=r),a+=u},0),a}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);a<e.content.length;a++)i.push(e.content[a]);return new Y(i,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let r=[],i=0;if(n>e)for(let a=0,s=0;s<n;a++){let o=this.content[a],l=s+o.nodeSize;l>e&&((s<e||l>n)&&(o.isText?o=o.cut(Math.max(0,e-s),Math.min(o.text.length,n-s)):o=o.cut(Math.max(0,e-s-1),Math.min(o.content.size,n-s-1))),r.push(o),i+=o.nodeSize),s=l}return new Y(r,i)}cutByIndex(e,n){return e==n?Y.empty:e==0&&n==this.content.length?this:new Y(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new Y(i,a)}addToStart(e){return new Y([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new Y(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,r=0;n<this.content.length;n++){let i=this.content[n];e(i,r,n),r+=i.nodeSize}}findDiffStart(e,n=0){return oC(this,e,n)}findDiffEnd(e,n=this.size,r=e.size){return lC(this,e,n,r)}findIndex(e){if(e==0)return ks(0,e);if(e==this.size)return ks(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let i=this.child(n),a=r+i.nodeSize;if(a>=e)return a==e?ks(n+1,a):ks(n,r);r=a}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return Y.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new Y(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return Y.empty;let n,r=0;for(let i=0;i<e.length;i++){let a=e[i];r+=a.nodeSize,i&&a.isText&&e[i-1].sameMarkup(a)?(n||(n=e.slice(0,i)),n[n.length-1]=a.withText(n[n.length-1].text+a.text)):n&&n.push(a)}return new Y(n||e,r)}static from(e){if(!e)return Y.empty;if(e instanceof Y)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new Y([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}Y.empty=new Y([],0);const tu={index:0,offset:0};function ks(t,e){return tu.index=t,tu.offset=e,tu}function lo(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!lo(t[r],e[r]))return!1}else{for(let r in t)if(!(r in e)||!lo(t[r],e[r]))return!1;for(let r in e)if(!(r in t))return!1}return!0}let Fe=class jm{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,r=!1;for(let i=0;i<e.length;i++){let a=e[i];if(this.eq(a))return e;if(this.type.excludes(a.type))n||(n=e.slice(0,i));else{if(a.type.excludes(this.type))return e;!r&&a.type.rank>this.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(a)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&lo(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[n.type];if(!r)throw new RangeError(`There is no mark type ${n.type} in this schema`);let i=r.create(n.attrs);return r.checkAttrs(i.attrs),i}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(n[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return jm.none;if(e instanceof jm)return[e];let n=e.slice();return n.sort((r,i)=>r.type.rank-i.type.rank),n}};Fe.none=[];class uo extends Error{}class re{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=cC(this.content,e+this.openStart,n);return r&&new re(r,this.openStart,this.openEnd)}removeBetween(e,n){return new re(uC(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return re.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new re(Y.fromJSON(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let a=e.firstChild;a&&!a.isLeaf&&(n||!a.type.spec.isolating);a=a.firstChild)r++;for(let a=e.lastChild;a&&!a.isLeaf&&(n||!a.type.spec.isolating);a=a.lastChild)i++;return new re(e,r,i)}}re.empty=new re(Y.empty,0,0);function uC(t,e,n){let{index:r,offset:i}=t.findIndex(e),a=t.maybeChild(r),{index:s,offset:o}=t.findIndex(n);if(i==e||a.isText){if(o!=n&&!t.child(s).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=s)throw new RangeError("Removing non-flat range");return t.replaceChild(r,a.copy(uC(a.content,e-i-1,n-i-1)))}function cC(t,e,n,r){let{index:i,offset:a}=t.findIndex(e),s=t.maybeChild(i);if(a==e||s.isText)return r&&!r.canReplace(i,i,n)?null:t.cut(0,e).append(n).append(t.cut(e));let o=cC(s.content,e-a-1,n,s);return o&&t.replaceChild(i,s.copy(o))}function kM(t,e,n){if(n.openStart>t.depth)throw new uo("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new uo("Inconsistent open depths");return dC(t,e,n,0)}function dC(t,e,n,r){let i=t.index(r),a=t.node(r);if(i==e.index(r)&&r<t.depth-n.openStart){let s=dC(t,e,n,r+1);return a.copy(a.content.replaceChild(i,s))}else if(n.content.size)if(!n.openStart&&!n.openEnd&&t.depth==r&&e.depth==r){let s=t.parent,o=s.content;return Br(s,o.cut(0,t.parentOffset).append(n.content).append(o.cut(e.parentOffset)))}else{let{start:s,end:o}=xM(n,t);return Br(a,fC(t,s,o,e,r))}else return Br(a,co(t,e,r))}function pC(t,e){if(!e.type.compatibleContent(t.type))throw new uo("Cannot join "+e.type.name+" onto "+t.type.name)}function qm(t,e,n){let r=t.node(n);return pC(r,e.node(n)),r}function Fr(t,e){let n=e.length-1;n>=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function ga(t,e,n,r){let i=(e||t).node(n),a=0,s=e?e.index(n):i.childCount;t&&(a=t.index(n),t.depth>n?a++:t.textOffset&&(Fr(t.nodeAfter,r),a++));for(let o=a;o<s;o++)Fr(i.child(o),r);e&&e.depth==n&&e.textOffset&&Fr(e.nodeBefore,r)}function Br(t,e){return t.type.checkContent(e),t.copy(e)}function fC(t,e,n,r,i){let a=t.depth>i&&qm(t,e,i+1),s=r.depth>i&&qm(n,r,i+1),o=[];return ga(null,t,i,o),a&&s&&e.index(i)==n.index(i)?(pC(a,s),Fr(Br(a,fC(t,e,n,r,i+1)),o)):(a&&Fr(Br(a,co(t,e,i+1)),o),ga(e,n,i,o),s&&Fr(Br(s,co(n,r,i+1)),o)),ga(r,null,i,o),new Y(o)}function co(t,e,n){let r=[];if(ga(null,t,n,r),t.depth>n){let i=qm(t,e,n+1);Fr(Br(i,co(t,e,n+1)),r)}return ga(e,null,n,r),new Y(r)}function xM(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let a=n-1;a>=0;a--)i=e.node(a).copy(Y.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}class Ua{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(n);return r?e.child(n).cut(r):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let a=0;a<e;a++)i+=r.child(a).nodeSize;return i}marks(){let e=this.parent,n=this.index();if(e.content.size==0)return Fe.none;if(this.textOffset)return e.child(n).marks;let r=e.maybeChild(n-1),i=e.maybeChild(n);if(!r){let o=r;r=i,i=o}let a=r.marks;for(var s=0;s<a.length;s++)a[s].type.spec.inclusive===!1&&(!i||!a[s].isInSet(i.marks))&&(a=a[s--].removeFromSet(a));return a}marksAcross(e){let n=this.parent.maybeChild(this.index());if(!n||!n.isInline)return null;let r=n.marks,i=e.parent.maybeChild(e.index());for(var a=0;a<r.length;a++)r[a].type.spec.inclusive===!1&&(!i||!r[a].isInSet(i.marks))&&(r=r[a--].removeFromSet(r));return r}sharedDepth(e){for(let n=this.depth;n>0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos<this.pos)return e.blockRange(this);for(let r=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);r>=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new po(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let n=1;n<=this.depth;n++)e+=(e?"/":"")+this.node(n).type.name+"_"+this.index(n-1);return e+":"+this.parentOffset}static resolve(e,n){if(!(n>=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],i=0,a=n;for(let s=e;;){let{index:o,offset:l}=s.content.findIndex(a),u=a-l;if(r.push(s,o,i+l),!u||(s=s.child(o),s.isText))break;a=u-1,i+=l+1}return new Ua(n,r,a)}static resolveCached(e,n){let r=d0.get(e);if(r)for(let a=0;a<r.elts.length;a++){let s=r.elts[a];if(s.pos==n)return s}else d0.set(e,r=new vM);let i=r.elts[r.i]=Ua.resolve(e,n);return r.i=(r.i+1)%_M,i}}class vM{constructor(){this.elts=[],this.i=0}}const _M=12,d0=new WeakMap;class po{constructor(e,n,r){this.$from=e,this.$to=n,this.depth=r}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const CM=Object.create(null);let hr=class Gm{constructor(e,n,r,i=Fe.none){this.type=e,this.attrs=n,this.marks=i,this.content=r||Y.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,n,r,i=0){this.content.nodesBetween(e,n,r,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,n,r,i){return this.content.textBetween(e,n,r,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,n,r){return this.type==e&&lo(this.attrs,n||e.defaultAttrs||CM)&&Fe.sameSet(this.marks,r||Fe.none)}copy(e=null){return e==this.content?this:new Gm(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new Gm(this.type,this.attrs,this.content,e)}cut(e,n=this.content.size){return e==0&&n==this.content.size?this:this.copy(this.content.cut(e,n))}slice(e,n=this.content.size,r=!1){if(e==n)return re.empty;let i=this.resolve(e),a=this.resolve(n),s=r?0:i.sharedDepth(n),o=i.start(s),u=i.node(s).content.cut(i.pos-o,a.pos-o);return new re(u,i.depth-s,a.depth-s)}replace(e,n,r){return kM(this.resolve(e),this.resolve(n),r)}nodeAt(e){for(let n=this;;){let{index:r,offset:i}=n.content.findIndex(e);if(n=n.maybeChild(r),!n)return null;if(i==e||n.isText)return n;e-=i+1}}childAfter(e){let{index:n,offset:r}=this.content.findIndex(e);return{node:this.content.maybeChild(n),index:n,offset:r}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:n,offset:r}=this.content.findIndex(e);if(r<e)return{node:this.content.child(n),index:n,offset:r};let i=this.content.child(n-1);return{node:i,index:n-1,offset:r-i.nodeSize}}resolve(e){return Ua.resolveCached(this,e)}resolveNoCache(e){return Ua.resolve(this,e)}rangeHasMark(e,n,r){let i=!1;return n>e&&this.nodesBetween(e,n,a=>(r.isInSet(a.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),hC(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=Y.empty,i=0,a=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,a),o=s&&s.matchFragment(this.content,n);if(!o||!o.validEnd)return!1;for(let l=i;l<a;l++)if(!this.type.allowsMarks(r.child(l).marks))return!1;return!0}canReplaceWith(e,n,r,i){if(i&&!this.type.allowsMarks(i))return!1;let a=this.contentMatchAt(e).matchType(r),s=a&&a.matchFragment(this.content,n);return s?s.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=Fe.none;for(let n=0;n<this.marks.length;n++){let r=this.marks[n];r.type.checkAttrs(r.attrs),e=r.addToSet(e)}if(!Fe.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(n=>n.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let i=Y.fromJSON(e,n.content),a=e.nodeType(n.type).create(n.attrs,i,r);return a.type.checkAttrs(a.attrs),a}};hr.prototype.text=void 0;class fo extends hr{constructor(e,n,r,i){if(super(e,n,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):hC(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new fo(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new fo(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function hC(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class Gr{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new IM(e,n);if(r.next==null)return Gr.empty;let i=mC(r);r.next&&r.err("Unexpected trailing text");let a=MM(DM(i));return PM(a,r),a}matchType(e){for(let n=0;n<this.next.length;n++)if(this.next[n].type==e)return this.next[n].next;return null}matchFragment(e,n=0,r=e.childCount){let i=this;for(let a=n;i&&a<r;a++)i=i.matchType(e.child(a).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:n}=this.next[e];if(!(n.isText||n.hasRequiredAttrs()))return n}return null}compatible(e){for(let n=0;n<this.next.length;n++)for(let r=0;r<e.next.length;r++)if(this.next[n].type==e.next[r].type)return!0;return!1}fillBefore(e,n=!1,r=0){let i=[this];function a(s,o){let l=s.matchFragment(e,r);if(l&&(!n||l.validEnd))return Y.from(o.map(u=>u.createAndFill()));for(let u=0;u<s.next.length;u++){let{type:c,next:d}=s.next[u];if(!(c.isText||c.hasRequiredAttrs())&&i.indexOf(d)==-1){i.push(d);let p=a(d,o.concat(c));if(p)return p}}return null}return a(this,[])}findWrapping(e){for(let r=0;r<this.wrapCache.length;r+=2)if(this.wrapCache[r]==e)return this.wrapCache[r+1];let n=this.computeWrapping(e);return this.wrapCache.push(e,n),n}computeWrapping(e){let n=Object.create(null),r=[{match:this,type:null,via:null}];for(;r.length;){let i=r.shift(),a=i.match;if(a.matchType(e)){let s=[];for(let o=i;o.type;o=o.via)s.push(o.type);return s.reverse()}for(let s=0;s<a.next.length;s++){let{type:o,next:l}=a.next[s];!o.isLeaf&&!o.hasRequiredAttrs()&&!(o.name in n)&&(!i.type||l.validEnd)&&(r.push({match:o.contentMatch,type:o,via:i}),n[o.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let i=0;i<r.next.length;i++)e.indexOf(r.next[i].next)==-1&&n(r.next[i].next)}return n(this),e.map((r,i)=>{let a=i+(r.validEnd?"*":" ")+" ";for(let s=0;s<r.next.length;s++)a+=(s?", ":"")+r.next[s].type.name+"->"+e.indexOf(r.next[s].next);return a}).join(`
24
24
  `)}}Gr.empty=new Gr(!0);class IM{constructor(e,n){this.string=e,this.nodeTypes=n,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function mC(t){let e=[];do e.push(NM(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function NM(t){let e=[];do e.push(wM(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function wM(t){let e=LM(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=RM(t,e);else break;return e}function p0(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function RM(t,e){let n=p0(t),r=n;return t.eat(",")&&(t.next!="}"?r=p0(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function OM(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let i=[];for(let a in n){let s=n[a];s.isInGroup(e)&&i.push(s)}return i.length==0&&t.err("No node type or group '"+e+"' found"),i}function LM(t){if(t.eat("(")){let e=mC(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=OM(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function DM(t){let e=[[]];return i(a(t,0),n()),e;function n(){return e.push([])-1}function r(s,o,l){let u={term:l,to:o};return e[s].push(u),u}function i(s,o){s.forEach(l=>l.to=o)}function a(s,o){if(s.type=="choice")return s.exprs.reduce((l,u)=>l.concat(a(u,o)),[]);if(s.type=="seq")for(let l=0;;l++){let u=a(s.exprs[l],o);if(l==s.exprs.length-1)return u;i(u,o=n())}else if(s.type=="star"){let l=n();return r(o,l),i(a(s.expr,l),l),[r(l)]}else if(s.type=="plus"){let l=n();return i(a(s.expr,o),l),i(a(s.expr,l),l),[r(l)]}else{if(s.type=="opt")return[r(o)].concat(a(s.expr,o));if(s.type=="range"){let l=o;for(let u=0;u<s.min;u++){let c=n();i(a(s.expr,l),c),l=c}if(s.max==-1)i(a(s.expr,l),l);else for(let u=s.min;u<s.max;u++){let c=n();r(l,c),i(a(s.expr,l),c),l=c}return[r(l)]}else{if(s.type=="name")return[r(o,void 0,s.value)];throw new Error("Unknown expr type")}}}}function gC(t,e){return e-t}function f0(t,e){let n=[];return r(e),n.sort(gC);function r(i){let a=t[i];if(a.length==1&&!a[0].term)return r(a[0].to);n.push(i);for(let s=0;s<a.length;s++){let{term:o,to:l}=a[s];!o&&n.indexOf(l)==-1&&r(l)}}}function MM(t){let e=Object.create(null);return n(f0(t,0));function n(r){let i=[];r.forEach(s=>{t[s].forEach(({term:o,to:l})=>{if(!o)return;let u;for(let c=0;c<i.length;c++)i[c][0]==o&&(u=i[c][1]);f0(t,l).forEach(c=>{u||i.push([o,u=[]]),u.indexOf(c)==-1&&u.push(c)})})});let a=e[r.join(",")]=new Gr(r.indexOf(t.length-1)>-1);for(let s=0;s<i.length;s++){let o=i[s][1].sort(gC);a.next.push({type:i[s][0],next:e[o.join(",")]||n(o)})}return a}}function PM(t,e){for(let n=0,r=[t];n<r.length;n++){let i=r[n],a=!i.validEnd,s=[];for(let o=0;o<i.next.length;o++){let{type:l,next:u}=i.next[o];s.push(l.name),a&&!(l.isText||l.hasRequiredAttrs())&&(a=!1),r.indexOf(u)==-1&&r.push(u)}a&&e.err("Only non-generatable nodes ("+s.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function bC(t){let e=Object.create(null);for(let n in t){let r=t[n];if(!r.hasDefault)return null;e[n]=r.default}return e}function EC(t,e){let n=Object.create(null);for(let r in t){let i=e&&e[r];if(i===void 0){let a=t[r];if(a.hasDefault)i=a.default;else throw new RangeError("No value supplied for attribute "+r)}n[r]=i}return n}function yC(t,e,n,r){for(let i in e)if(!(i in t))throw new RangeError(`Unsupported attribute ${i} for ${n} of type ${i}`);for(let i in t){let a=t[i];a.validate&&a.validate(e[i])}}function TC(t,e){let n=Object.create(null);if(e)for(let r in e)n[r]=new BM(t,r,e[r]);return n}let h0=class SC{constructor(e,n,r){this.name=e,this.schema=n,this.spec=r,this.markSet=null,this.groups=r.group?r.group.split(" "):[],this.attrs=TC(e,r.attrs),this.defaultAttrs=bC(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(r.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==Gr.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:EC(this.attrs,e)}create(e=null,n,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new hr(this,this.computeAttrs(e),Y.from(n),Fe.setFrom(r))}createChecked(e=null,n,r){return n=Y.from(n),this.checkContent(n),new hr(this,this.computeAttrs(e),n,Fe.setFrom(r))}createAndFill(e=null,n,r){if(e=this.computeAttrs(e),n=Y.from(n),n.size){let s=this.contentMatch.fillBefore(n);if(!s)return null;n=s.append(n)}let i=this.contentMatch.matchFragment(n),a=i&&i.fillBefore(Y.empty,!0);return a?new hr(this,e,n.append(a),Fe.setFrom(r)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let r=0;r<e.childCount;r++)if(!this.allowsMarks(e.child(r).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){yC(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;n<e.length;n++)if(!this.allowsMarkType(e[n].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let n;for(let r=0;r<e.length;r++)this.allowsMarkType(e[r].type)?n&&n.push(e[r]):n||(n=e.slice(0,r));return n?n.length?n:Fe.none:e}static compile(e,n){let r=Object.create(null);e.forEach((a,s)=>r[a]=new SC(a,n,s));let i=n.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let a in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function FM(t,e,n){let r=n.split("|");return i=>{let a=i===null?"null":typeof i;if(r.indexOf(a)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${t}, got ${a}`)}}class BM{constructor(e,n,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?FM(e,n,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class ml{constructor(e,n,r,i){this.name=e,this.rank=n,this.schema=r,this.spec=i,this.attrs=TC(e,i.attrs),this.excluded=null;let a=bC(this.attrs);this.instance=a?new Fe(this,a):null}create(e=null){return!e&&this.instance?this.instance:new Fe(this,EC(this.attrs,e))}static compile(e,n){let r=Object.create(null),i=0;return e.forEach((a,s)=>r[a]=new ml(a,i++,n,s)),r}removeFromSet(e){for(var n=0;n<e.length;n++)e[n].type==this&&(e=e.slice(0,n).concat(e.slice(n+1)),n--);return e}isInSet(e){for(let n=0;n<e.length;n++)if(e[n].type==this)return e[n]}checkAttrs(e){yC(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}let AC=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let i in e)n[i]=e[i];n.nodes=ft.from(e.nodes),n.marks=ft.from(e.marks||{}),this.nodes=h0.compile(this.spec.nodes,this),this.marks=ml.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let a=this.nodes[i],s=a.spec.content||"",o=a.spec.marks;if(a.contentMatch=r[s]||(r[s]=Gr.parse(s,this.nodes)),a.inlineContent=a.contentMatch.inlineContent,a.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!a.isInline||!a.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=a}a.markSet=o=="_"?null:o?m0(this,o.split(" ")):o==""||!a.inlineContent?[]:null}for(let i in this.marks){let a=this.marks[i],s=a.spec.excludes;a.excluded=s==null?[a]:s==""?[]:m0(this,s.split(" "))}this.nodeFromJSON=i=>hr.fromJSON(this,i),this.markFromJSON=i=>Fe.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof h0){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,r,i)}text(e,n){let r=this.nodes.text;return new fo(r,r.defaultAttrs,e,Fe.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}};function m0(t,e){let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t.marks[i],s=a;if(a)n.push(a);else for(let o in t.marks){let l=t.marks[o];(i=="_"||l.spec.group&&l.spec.group.split(" ").indexOf(i)>-1)&&n.push(s=l)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}function UM(t){return t.tag!=null}function HM(t){return t.style!=null}class mr{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let r=this.matchedStyles=[];n.forEach(i=>{if(UM(i))this.tags.push(i);else if(HM(i)){let a=/[^=]*/.exec(i.style)[0];r.indexOf(a)<0&&r.push(a),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let a=e.nodes[i.node];return a.contentMatch.matchType(a)})}parse(e,n={}){let r=new b0(this,n,!1);return r.addAll(e,Fe.none,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new b0(this,n,!0);return r.addAll(e,Fe.none,n.from,n.to),re.maxOpen(r.finish())}matchTag(e,n,r){for(let i=r?this.tags.indexOf(r)+1:0;i<this.tags.length;i++){let a=this.tags[i];if(jM(e,a.tag)&&(a.namespace===void 0||e.namespaceURI==a.namespace)&&(!a.context||n.matchesContext(a.context))){if(a.getAttrs){let s=a.getAttrs(e);if(s===!1)continue;a.attrs=s||void 0}return a}}}matchStyle(e,n,r,i){for(let a=i?this.styles.indexOf(i)+1:0;a<this.styles.length;a++){let s=this.styles[a],o=s.style;if(!(o.indexOf(e)!=0||s.context&&!r.matchesContext(s.context)||o.length>e.length&&(o.charCodeAt(e.length)!=61||o.slice(e.length+1)!=n))){if(s.getAttrs){let l=s.getAttrs(n);if(l===!1)continue;s.attrs=l||void 0}return s}}}static schemaRules(e){let n=[];function r(i){let a=i.priority==null?50:i.priority,s=0;for(;s<n.length;s++){let o=n[s];if((o.priority==null?50:o.priority)<a)break}n.splice(s,0,i)}for(let i in e.marks){let a=e.marks[i].spec.parseDOM;a&&a.forEach(s=>{r(s=E0(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let a=e.nodes[i].spec.parseDOM;a&&a.forEach(s=>{r(s=E0(s)),s.node||s.ignore||s.mark||(s.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new mr(e,mr.schemaRules(e)))}}const kC={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},$M={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},xC={ol:!0,ul:!0},Ha=1,Vm=2,ba=4;function g0(t,e,n){return e!=null?(e?Ha:0)|(e==="full"?Vm:0):t&&t.whitespace=="pre"?Ha|Vm:n&~ba}class xs{constructor(e,n,r,i,a,s){this.type=e,this.attrs=n,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=Fe.none,this.match=a||(s&ba?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(Y.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ha)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let a=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=a.withText(a.text.slice(0,a.text.length-i[0].length))}}let n=Y.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(Y.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!kC.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class b0{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let i=n.topNode,a,s=g0(null,n.preserveWhitespace,0)|(r?ba:0);i?a=new xs(i.type,i.attrs,Fe.none,!0,n.topMatch||i.type.contentMatch,s):r?a=new xs(null,null,Fe.none,!0,null,s):a=new xs(e.schema.topNodeType,null,Fe.none,!0,null,s),this.nodes=[a],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,n){e.nodeType==3?this.addTextNode(e,n):e.nodeType==1&&this.addElement(e,n)}addTextNode(e,n){let r=e.nodeValue,i=this.top,a=i.options&Vm?"full":this.localPreserveWS||(i.options&Ha)>0,{schema:s}=this.parser;if(a==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(a)if(a==="full")r=r.replace(/\r\n?/g,`
25
25
  `);else if(s.linebreakReplacement&&/[\r\n]/.test(r)&&this.top.findWrapping(s.linebreakReplacement.create())){let o=r.split(/\r?\n|\r/);for(let l=0;l<o.length;l++)l&&this.insertNode(s.linebreakReplacement.create(),n,!0),o[l]&&this.insertNode(s.text(o[l]),n,!/\S/.test(o[l]));r=""}else r=r.replace(/\r?\n|\r/g," ");else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let o=i.content[i.content.length-1],l=e.previousSibling;(!o||l&&l.nodeName=="BR"||o.isText&&/[ \t\r\n\u000c]$/.test(o.text))&&(r=r.slice(1))}r&&this.insertNode(s.text(r),n,!/\S/.test(r)),this.findInText(e)}else this.findInside(e)}addElement(e,n,r){let i=this.localPreserveWS,a=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let s=e.nodeName.toLowerCase(),o;xC.hasOwnProperty(s)&&this.parser.normalizeLists&&zM(e);let l=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,r));e:if(l?l.ignore:$M.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,n);else if(!l||l.skip||l.closeParent){l&&l.closeParent?this.open=Math.max(0,this.open-1):l&&l.skip.nodeType&&(e=l.skip);let u,c=this.needsBlock;if(kC.hasOwnProperty(s))a.content.length&&a.content[0].isInline&&this.open&&(this.open--,a=this.top),u=!0,a.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,n);break e}let d=l&&l.skip?n:this.readStyles(e,n);d&&this.addAll(e,d),u&&this.sync(a),this.needsBlock=c}else{let u=this.readStyles(e,n);u&&this.addElementByRule(e,l,u,l.consuming===!1?o:void 0)}this.localPreserveWS=i}leafFallback(e,n){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
26
26
  `),n)}ignoreFallback(e,n){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),n,!0)}readStyles(e,n){let r=e.style;if(r&&r.length)for(let i=0;i<this.parser.matchedStyles.length;i++){let a=this.parser.matchedStyles[i],s=r.getPropertyValue(a);if(s)for(let o=void 0;;){let l=this.parser.matchStyle(a,s,this,o);if(!l)break;if(l.ignore)return null;if(l.clearMark?n=n.filter(u=>!l.clearMark(u)):n=n.concat(this.parser.schema.marks[l.mark].create(l.attrs)),l.consuming===!1)o=l;else break}}return n}addElementByRule(e,n,r,i){let a,s;if(n.node)if(s=this.parser.schema.nodes[n.node],s.isLeaf)this.insertNode(s.create(n.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let l=this.enter(s,n.attrs||null,r,n.preserveWhitespace);l&&(a=!0,r=l)}else{let l=this.parser.schema.marks[n.mark];r=r.concat(l.create(n.attrs))}let o=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(l=>this.insertNode(l,r,!1));else{let l=e;typeof n.contentElement=="string"?l=e.querySelector(n.contentElement):typeof n.contentElement=="function"?l=n.contentElement(e):n.contentElement&&(l=n.contentElement),this.findAround(e,l,!0),this.addAll(l,r),this.findAround(e,l,!1)}a&&this.sync(o)&&this.open--}addAll(e,n,r,i){let a=r||0;for(let s=r?e.childNodes[r]:e.firstChild,o=i==null?null:e.childNodes[i];s!=o;s=s.nextSibling,++a)this.findAtPoint(e,a),this.addDOM(s,n);this.findAtPoint(e,a)}findPlace(e,n,r){let i,a;for(let s=this.open,o=0;s>=0;s--){let l=this.nodes[s],u=l.findWrapping(e);if(u&&(!i||i.length>u.length+o)&&(i=u,a=l,!u.length))break;if(l.solid){if(r)break;o+=2}}if(!i)return null;this.sync(a);for(let s=0;s<i.length;s++)n=this.enterInner(i[s],null,n,!1);return n}insertNode(e,n,r){if(e.isInline&&this.needsBlock&&!this.top.type){let a=this.textblockFromContext();a&&(n=this.enterInner(a,null,n))}let i=this.findPlace(e,n,r);if(i){this.closeExtra();let a=this.top;a.match&&(a.match=a.match.matchType(e.type));let s=Fe.none;for(let o of i.concat(e.marks))(a.type?a.type.allowsMarkType(o.type):y0(o.type,e.type))&&(s=o.addToSet(s));return a.content.push(e.mark(s)),!0}return!1}enter(e,n,r,i){let a=this.findPlace(e.create(n),r,!1);return a&&(a=this.enterInner(e,n,r,!0,i)),a}enterInner(e,n,r,i=!1,a){this.closeExtra();let s=this.top;s.match=s.match&&s.match.matchType(e);let o=g0(e,a,s.options);s.options&ba&&s.content.length==0&&(o|=ba);let l=Fe.none;return r=r.filter(u=>(s.type?s.type.allowsMarkType(u.type):y0(u.type,e))?(l=u.addToSet(l),!1):!0),this.nodes.push(new xs(e,n,l,i,null,o)),this.open++,r}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let n=this.open;n>=0;n--){if(this.nodes[n]==e)return this.open=n,!0;this.localPreserveWS&&(this.nodes[n].options|=Ha)}return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r<this.find.length;r++)this.find[r].node==e&&this.find[r].offset==n&&(this.find[r].pos=this.currentPos)}findInside(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&e.nodeType==1&&e.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(e,n,r){if(e!=n&&this.find)for(let i=0;i<this.find.length;i++)this.find[i].pos==null&&e.nodeType==1&&e.contains(this.find[i].node)&&n.compareDocumentPosition(this.find[i].node)&(r?2:4)&&(this.find[i].pos=this.currentPos)}findInText(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&(this.find[n].pos=this.currentPos-(e.nodeValue.length-this.find[n].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),a=-(r?r.depth+1:0)+(i?0:1),s=(o,l)=>{for(;o>=0;o--){let u=n[o];if(u==""){if(o==n.length-1||o==0)continue;for(;l>=a;l--)if(s(o-1,l))return!0;return!1}else{let c=l>0||l==0&&i?this.nodes[l].type:r&&l>=a?r.node(l-a).type:null;if(!c||c.name!=u&&!c.isInGroup(u))return!1;l--}}return!0};return s(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}}function zM(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&xC.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function jM(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function E0(t){let e={};for(let n in t)e[n]=t[n];return e}function y0(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))continue;let a=[],s=o=>{a.push(o);for(let l=0;l<o.edgeCount;l++){let{type:u,next:c}=o.edge(l);if(u==e||a.indexOf(c)<0&&s(c))return!0}};if(s(i.contentMatch))return!0}}class ni{constructor(e,n){this.nodes=e,this.marks=n}serializeFragment(e,n={},r){r||(r=nu(n).createDocumentFragment());let i=r,a=[];return e.forEach(s=>{if(a.length||s.marks.length){let o=0,l=0;for(;o<a.length&&l<s.marks.length;){let u=s.marks[l];if(!this.marks[u.type.name]){l++;continue}if(!u.eq(a[o][0])||u.type.spec.spanning===!1)break;o++,l++}for(;o<a.length;)i=a.pop()[1];for(;l<s.marks.length;){let u=s.marks[l++],c=this.serializeMark(u,s.isInline,n);c&&(a.push([u,i]),i.appendChild(c.dom),i=c.contentDOM||c.dom)}}i.appendChild(this.serializeNodeInner(s,n))}),r}serializeNodeInner(e,n){let{dom:r,contentDOM:i}=Ws(nu(n),this.nodes[e.type.name](e),null,e.attrs);if(i){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,n,i)}return r}serializeNode(e,n={}){let r=this.serializeNodeInner(e,n);for(let i=e.marks.length-1;i>=0;i--){let a=this.serializeMark(e.marks[i],e.isInline,n);a&&((a.contentDOM||a.dom).appendChild(r),r=a.dom)}return r}serializeMark(e,n,r={}){let i=this.marks[e.type.name];return i&&Ws(nu(r),i(e,n),null,e.attrs)}static renderSpec(e,n,r=null,i){return Ws(e,n,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new ni(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=T0(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return T0(e.marks)}}function T0(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function nu(t){return t.document||window.document}const S0=new WeakMap;function qM(t){let e=S0.get(t);return e===void 0&&S0.set(t,e=GM(t)),e}function GM(t){let e=null;function n(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i<r.length;i++)n(r[i]);else for(let i in r)n(r[i])}return n(t),e}function Ws(t,e,n,r){if(typeof e=="string")return{dom:t.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let i=e[0],a;if(typeof i!="string")throw new RangeError("Invalid array passed to renderSpec");if(r&&(a=qM(r))&&a.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s=i.indexOf(" ");s>0&&(n=i.slice(0,s),i=i.slice(s+1));let o,l=n?t.createElementNS(n,i):t.createElement(i),u=e[1],c=1;if(u&&typeof u=="object"&&u.nodeType==null&&!Array.isArray(u)){c=2;for(let d in u)if(u[d]!=null){let p=d.indexOf(" ");p>0?l.setAttributeNS(d.slice(0,p),d.slice(p+1),u[d]):d=="style"&&l.style?l.style.cssText=u[d]:l.setAttribute(d,u[d])}}for(let d=c;d<e.length;d++){let p=e[d];if(p===0){if(d<e.length-1||d>c)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:f,contentDOM:h}=Ws(t,p,n,r);if(l.appendChild(f),h){if(o)throw new RangeError("Multiple content holes");o=h}}}return{dom:l,contentDOM:o}}const vC=65535,_C=Math.pow(2,16);function VM(t,e){return t+e*_C}function A0(t){return t&vC}function WM(t){return(t-(t&vC))/_C}const CC=1,IC=2,Ys=4,NC=8;class Wm{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&NC)>0}get deletedBefore(){return(this.delInfo&(CC|Ys))>0}get deletedAfter(){return(this.delInfo&(IC|Ys))>0}get deletedAcross(){return(this.delInfo&Ys)>0}}class Kt{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&Kt.empty)return Kt.empty}recover(e){let n=0,r=A0(e);if(!this.inverted)for(let i=0;i<r;i++)n+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[r*3]+n+WM(e)}mapResult(e,n=1){return this._map(e,n,!1)}map(e,n=1){return this._map(e,n,!0)}_map(e,n,r){let i=0,a=this.inverted?2:1,s=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let l=this.ranges[o]-(this.inverted?i:0);if(l>e)break;let u=this.ranges[o+a],c=this.ranges[o+s],d=l+u;if(e<=d){let p=u?e==l?-1:e==d?1:n:n,f=l+i+(p<0?0:c);if(r)return f;let h=e==(n<0?l:d)?null:VM(o/3,e-l),g=e==l?IC:e==d?CC:Ys;return(n<0?e!=l:e!=d)&&(g|=NC),new Wm(f,g,h)}i+=c-u}return r?e+i:new Wm(e+i,0,null)}touches(e,n){let r=0,i=A0(n),a=this.inverted?2:1,s=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let l=this.ranges[o]-(this.inverted?r:0);if(l>e)break;let u=this.ranges[o+a],c=l+u;if(e<=c&&o==i*3)return!0;r+=this.ranges[o+s]-u}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,a=0;i<this.ranges.length;i+=3){let s=this.ranges[i],o=s-(this.inverted?a:0),l=s+(this.inverted?0:a),u=this.ranges[i+n],c=this.ranges[i+r];e(o,o+u,l,l+c),a+=c-u}}invert(){return new Kt(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Kt.empty:new Kt(e<0?[0,-e,0]:[0,0,e])}}Kt.empty=new Kt([]);class $a{constructor(e,n,r=0,i=e?e.length:0){this.mirror=n,this.from=r,this.to=i,this._maps=e||[],this.ownData=!(e||n)}get maps(){return this._maps}slice(e=0,n=this.maps.length){return new $a(this._maps,this.mirror,e,n)}appendMap(e,n){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),n!=null&&this.setMirror(this._maps.length-1,n)}appendMapping(e){for(let n=0,r=this._maps.length;n<e._maps.length;n++){let i=e.getMirror(n);this.appendMap(e._maps[n],i!=null&&i<n?r+i:void 0)}}getMirror(e){if(this.mirror){for(let n=0;n<this.mirror.length;n++)if(this.mirror[n]==e)return this.mirror[n+(n%2?-1:1)]}}setMirror(e,n){this.mirror||(this.mirror=[]),this.mirror.push(e,n)}appendMappingInverted(e){for(let n=e.maps.length-1,r=this._maps.length+e._maps.length;n>=0;n--){let i=e.getMirror(n);this.appendMap(e._maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new $a;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;r<this.to;r++)e=this._maps[r].map(e,n);return e}mapResult(e,n=1){return this._map(e,n,!1)}_map(e,n,r){let i=0;for(let a=this.from;a<this.to;a++){let s=this._maps[a],o=s.mapResult(e,n);if(o.recover!=null){let l=this.getMirror(a);if(l!=null&&l>a&&l<this.to){a=l,e=this._maps[l].recover(o.recover);continue}}i|=o.delInfo,e=o.pos}return r?e:new Wm(e,i,null)}}const ru=Object.create(null);class kt{getMap(){return Kt.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=ru[n.stepType];if(!r)throw new RangeError(`No step type ${n.stepType} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in ru)throw new RangeError("Duplicate use of step JSON ID "+e);return ru[e]=n,n.prototype.jsonID=e,n}}class nt{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new nt(e,null)}static fail(e){return new nt(null,e)}static fromReplace(e,n,r,i){try{return nt.ok(e.replace(n,r,i))}catch(a){if(a instanceof uo)return nt.fail(a.message);throw a}}}function rb(t,e,n){let r=[];for(let i=0;i<t.childCount;i++){let a=t.child(i);a.content.size&&(a=a.copy(rb(a.content,e,a))),a.isInline&&(a=e(a,n,i)),r.push(a)}return Y.fromArray(r)}class lr extends kt{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=e.resolve(this.from),i=r.node(r.sharedDepth(this.to)),a=new re(rb(n.content,(s,o)=>!s.isAtom||!o.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),n.openStart,n.openEnd);return nt.fromReplace(e,this.from,this.to,a)}invert(){return new mn(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new lr(n.pos,r.pos,this.mark)}merge(e){return e instanceof lr&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new lr(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new lr(n.from,n.to,e.markFromJSON(n.mark))}}kt.jsonID("addMark",lr);class mn extends kt{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new re(rb(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return nt.fromReplace(e,this.from,this.to,r)}invert(){return new lr(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new mn(n.pos,r.pos,this.mark)}merge(e){return e instanceof mn&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new mn(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new mn(n.from,n.to,e.markFromJSON(n.mark))}}kt.jsonID("removeMark",mn);class ur extends kt{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return nt.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return nt.fromReplace(e,this.pos,this.pos+1,new re(Y.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;i<n.marks.length;i++)if(!n.marks[i].isInSet(r))return new ur(this.pos,n.marks[i]);return new ur(this.pos,this.mark)}}return new Vr(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new ur(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new ur(n.pos,e.markFromJSON(n.mark))}}kt.jsonID("addNodeMark",ur);class Vr extends kt{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return nt.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.removeFromSet(n.marks));return nt.fromReplace(e,this.pos,this.pos+1,new re(Y.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);return!n||!this.mark.isInSet(n.marks)?this:new ur(this.pos,this.mark)}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Vr(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Vr(n.pos,e.markFromJSON(n.mark))}}kt.jsonID("removeNodeMark",Vr);class lt extends kt{constructor(e,n,r,i=!1){super(),this.from=e,this.to=n,this.slice=r,this.structure=i}apply(e){return this.structure&&Ym(e,this.from,this.to)?nt.fail("Structure replace would overwrite content"):nt.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Kt([this.from,this.to-this.from,this.slice.size])}invert(e){return new lt(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new lt(n.pos,Math.max(n.pos,r.pos),this.slice,this.structure)}merge(e){if(!(e instanceof lt)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let n=this.slice.size+e.slice.size==0?re.empty:new re(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new lt(this.from,this.to+(e.to-e.from),n,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let n=this.slice.size+e.slice.size==0?re.empty:new re(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new lt(e.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new lt(n.from,n.to,re.fromJSON(e,n.slice),!!n.structure)}}kt.jsonID("replace",lt);class dt extends kt{constructor(e,n,r,i,a,s,o=!1){super(),this.from=e,this.to=n,this.gapFrom=r,this.gapTo=i,this.slice=a,this.insert=s,this.structure=o}apply(e){if(this.structure&&(Ym(e,this.from,this.gapFrom)||Ym(e,this.gapTo,this.to)))return nt.fail("Structure gap-replace would overwrite content");let n=e.slice(this.gapFrom,this.gapTo);if(n.openStart||n.openEnd)return nt.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,n.content);return r?nt.fromReplace(e,this.from,this.to,r):nt.fail("Content does not fit in gap")}getMap(){return new Kt([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let n=this.gapTo-this.gapFrom;return new dt(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),i=this.from==this.gapFrom?n.pos:e.map(this.gapFrom,-1),a=this.to==this.gapTo?r.pos:e.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||i<n.pos||a>r.pos?null:new dt(n.pos,r.pos,i,a,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new dt(n.from,n.to,n.gapFrom,n.gapTo,re.fromJSON(e,n.slice),n.insert,!!n.structure)}}kt.jsonID("replaceAround",dt);function Ym(t,e,n){let r=t.resolve(e),i=n-e,a=r.depth;for(;i>0&&a>0&&r.indexAfter(a)==r.node(a).childCount;)a--,i--;if(i>0){let s=r.node(a).maybeChild(r.indexAfter(a));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function YM(t,e,n,r){let i=[],a=[],s,o;t.doc.nodesBetween(e,n,(l,u,c)=>{if(!l.isInline)return;let d=l.marks;if(!r.isInSet(d)&&c.type.allowsMarkType(r.type)){let p=Math.max(u,e),f=Math.min(u+l.nodeSize,n),h=r.addToSet(d);for(let g=0;g<d.length;g++)d[g].isInSet(h)||(s&&s.to==p&&s.mark.eq(d[g])?s.to=f:i.push(s=new mn(p,f,d[g])));o&&o.to==p?o.to=f:a.push(o=new lr(p,f,r))}}),i.forEach(l=>t.step(l)),a.forEach(l=>t.step(l))}function KM(t,e,n,r){let i=[],a=0;t.doc.nodesBetween(e,n,(s,o)=>{if(!s.isInline)return;a++;let l=null;if(r instanceof ml){let u=s.marks,c;for(;c=r.isInSet(u);)(l||(l=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(s.marks)&&(l=[r]):l=s.marks;if(l&&l.length){let u=Math.min(o+s.nodeSize,n);for(let c=0;c<l.length;c++){let d=l[c],p;for(let f=0;f<i.length;f++){let h=i[f];h.step==a-1&&d.eq(i[f].style)&&(p=h)}p?(p.to=u,p.step=a):i.push({style:d,from:Math.max(o,e),to:u,step:a})}}}),i.forEach(s=>t.step(new mn(s.from,s.to,s.style)))}function ib(t,e,n,r=n.contentMatch,i=!0){let a=t.doc.nodeAt(e),s=[],o=e+1;for(let l=0;l<a.childCount;l++){let u=a.child(l),c=o+u.nodeSize,d=r.matchType(u.type);if(!d)s.push(new lt(o,c,re.empty));else{r=d;for(let p=0;p<u.marks.length;p++)n.allowsMarkType(u.marks[p].type)||t.step(new mn(o,c,u.marks[p]));if(i&&u.isText&&n.whitespace!="pre"){let p,f=/\r?\n|\r/g,h;for(;p=f.exec(u.text);)h||(h=new re(Y.from(n.schema.text(" ",n.allowedMarks(u.marks))),0,0)),s.push(new lt(o+p.index,o+p.index+p[0].length,h))}}o=c}if(!r.validEnd){let l=r.fillBefore(Y.empty,!0);t.replace(o,o,new re(l,0,0))}for(let l=s.length-1;l>=0;l--)t.step(s[l])}function XM(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function $i(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth,i=0,a=0;;--r){let s=t.$from.node(r),o=t.$from.index(r)+i,l=t.$to.indexAfter(r)-a;if(r<t.depth&&s.canReplace(o,l,n))return r;if(r==0||s.type.spec.isolating||!XM(s,o,l))break;o&&(i=1),l<s.childCount&&(a=1)}return null}function ZM(t,e,n){let{$from:r,$to:i,depth:a}=e,s=r.before(a+1),o=i.after(a+1),l=s,u=o,c=Y.empty,d=0;for(let h=a,g=!1;h>n;h--)g||r.index(h)>0?(g=!0,c=Y.from(r.node(h).copy(c)),d++):l--;let p=Y.empty,f=0;for(let h=a,g=!1;h>n;h--)g||i.after(h+1)<i.end(h)?(g=!0,p=Y.from(i.node(h).copy(p)),f++):u++;t.step(new dt(l,u,s,o,new re(c.append(p),d,f),c.size-d,!0))}function ab(t,e,n=null,r=t){let i=QM(t,e),a=i&&JM(r,e);return a?i.map(k0).concat({type:e,attrs:n}).concat(a.map(k0)):null}function k0(t){return{type:t,attrs:null}}function QM(t,e){let{parent:n,startIndex:r,endIndex:i}=t,a=n.contentMatchAt(r).findWrapping(e);if(!a)return null;let s=a.length?a[0]:e;return n.canReplaceWith(r,i,s)?a:null}function JM(t,e){let{parent:n,startIndex:r,endIndex:i}=t,a=n.child(r),s=e.contentMatch.findWrapping(a.type);if(!s)return null;let l=(s.length?s[s.length-1]:e).contentMatch;for(let u=r;l&&u<i;u++)l=l.matchType(n.child(u).type);return!l||!l.validEnd?null:s}function e3(t,e,n){let r=Y.empty;for(let s=n.length-1;s>=0;s--){if(r.size){let o=n[s].type.contentMatch.matchFragment(r);if(!o||!o.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=Y.from(n[s].type.create(n[s].attrs,r))}let i=e.start,a=e.end;t.step(new dt(i,a,i,a,new re(r,0,0),n.length,!0))}function t3(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let a=t.steps.length;t.doc.nodesBetween(e,n,(s,o)=>{let l=typeof i=="function"?i(s):i;if(s.isTextblock&&!s.hasMarkup(r,l)&&n3(t.doc,t.mapping.slice(a).map(o),r)){let u=null;if(r.schema.linebreakReplacement){let f=r.whitespace=="pre",h=!!r.contentMatch.matchType(r.schema.linebreakReplacement);f&&!h?u=!1:!f&&h&&(u=!0)}u===!1&&RC(t,s,o,a),ib(t,t.mapping.slice(a).map(o,1),r,void 0,u===null);let c=t.mapping.slice(a),d=c.map(o,1),p=c.map(o+s.nodeSize,1);return t.step(new dt(d,p,d+1,p-1,new re(Y.from(r.create(l,null,s.marks)),0,0),1,!0)),u===!0&&wC(t,s,o,a),!1}})}function wC(t,e,n,r){e.forEach((i,a)=>{if(i.isText){let s,o=/\r?\n|\r/g;for(;s=o.exec(i.text);){let l=t.mapping.slice(r).map(n+1+a+s.index);t.replaceWith(l,l+1,e.type.schema.linebreakReplacement.create())}}})}function RC(t,e,n,r){e.forEach((i,a)=>{if(i.type==i.type.schema.linebreakReplacement){let s=t.mapping.slice(r).map(n+1+a);t.replaceWith(s,s+1,e.type.schema.text(`