@vertesia/ui 0.67.0 → 0.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/lib/esm/core/components/Badge.js +1 -1
  2. package/lib/esm/core/components/Badge.js.map +1 -1
  3. package/lib/esm/core/components/FormItem.js +2 -2
  4. package/lib/esm/core/components/FormItem.js.map +1 -1
  5. package/lib/esm/core/components/InputList.js +2 -2
  6. package/lib/esm/core/components/InputList.js.map +1 -1
  7. package/lib/esm/core/components/shadcn/checkbox.js +1 -1
  8. package/lib/esm/core/components/shadcn/checkbox.js.map +1 -1
  9. package/lib/esm/core/components/shadcn/command.js +1 -1
  10. package/lib/esm/core/components/shadcn/command.js.map +1 -1
  11. package/lib/esm/core/components/shadcn/dialog.js +6 -6
  12. package/lib/esm/core/components/shadcn/dialog.js.map +1 -1
  13. package/lib/esm/core/components/shadcn/filters/DynamicLabel.js.map +1 -1
  14. package/lib/esm/core/components/shadcn/filters/comboBox/DateCombobox.js +129 -0
  15. package/lib/esm/core/components/shadcn/filters/comboBox/DateCombobox.js.map +1 -0
  16. package/lib/esm/core/components/shadcn/filters/comboBox/SelectCombobox.js +46 -0
  17. package/lib/esm/core/components/shadcn/filters/comboBox/SelectCombobox.js.map +1 -0
  18. package/lib/esm/core/components/shadcn/filters/comboBox/StringListCombobox.js +23 -0
  19. package/lib/esm/core/components/shadcn/filters/comboBox/StringListCombobox.js.map +1 -0
  20. package/lib/esm/core/components/shadcn/filters/comboBox/TextCombobox.js +28 -0
  21. package/lib/esm/core/components/shadcn/filters/comboBox/TextCombobox.js.map +1 -0
  22. package/lib/esm/core/components/shadcn/filters/comboBox/comboBox.js +5 -0
  23. package/lib/esm/core/components/shadcn/filters/comboBox/comboBox.js.map +1 -0
  24. package/lib/esm/core/components/shadcn/filters/filter/SelectFilter.js +101 -0
  25. package/lib/esm/core/components/shadcn/filters/filter/SelectFilter.js.map +1 -0
  26. package/lib/esm/core/components/shadcn/filters/{stringListFilter.js → filter/StringListFilter.js} +3 -3
  27. package/lib/esm/core/components/shadcn/filters/filter/StringListFilter.js.map +1 -0
  28. package/lib/esm/core/components/shadcn/filters/{textFilter.js → filter/TextFilter.js} +4 -4
  29. package/lib/esm/core/components/shadcn/filters/filter/TextFilter.js.map +1 -0
  30. package/lib/esm/core/components/shadcn/filters/filter/dateFilter.js +161 -0
  31. package/lib/esm/core/components/shadcn/filters/filter/dateFilter.js.map +1 -0
  32. package/lib/esm/core/components/shadcn/filters/filter-styles.js +88 -0
  33. package/lib/esm/core/components/shadcn/filters/filter-styles.js.map +1 -0
  34. package/lib/esm/core/components/shadcn/filters/filterBar.js +128 -87
  35. package/lib/esm/core/components/shadcn/filters/filterBar.js.map +1 -1
  36. package/lib/esm/core/components/shadcn/filters/filters.js +7 -6
  37. package/lib/esm/core/components/shadcn/filters/filters.js.map +1 -1
  38. package/lib/esm/core/components/shadcn/filters/index.js +1 -1
  39. package/lib/esm/core/components/shadcn/filters/index.js.map +1 -1
  40. package/lib/esm/core/components/shadcn/filters/types.js.map +1 -1
  41. package/lib/esm/core/components/toast/NotificationPanel.js +24 -18
  42. package/lib/esm/core/components/toast/NotificationPanel.js.map +1 -1
  43. package/lib/esm/features/agent/PayloadBuilder.js +47 -27
  44. package/lib/esm/features/agent/PayloadBuilder.js.map +1 -1
  45. package/lib/esm/features/agent/chat/ModernAgentConversation.js +9 -3
  46. package/lib/esm/features/agent/chat/ModernAgentConversation.js.map +1 -1
  47. package/lib/esm/features/agent/chat/ModernAgentOutput/AllMessagesMixed.js +7 -6
  48. package/lib/esm/features/agent/chat/ModernAgentOutput/AllMessagesMixed.js.map +1 -1
  49. package/lib/esm/features/agent/chat/ModernAgentOutput/MessageItem.js +12 -1
  50. package/lib/esm/features/agent/chat/ModernAgentOutput/MessageItem.js.map +1 -1
  51. package/lib/esm/features/agent/chat/ModernAgentOutput/SlidingMessages.js +2 -1
  52. package/lib/esm/features/agent/chat/ModernAgentOutput/SlidingMessages.js.map +1 -1
  53. package/lib/esm/features/agent/chat/ModernAgentOutput/utils.js +10 -4
  54. package/lib/esm/features/agent/chat/ModernAgentOutput/utils.js.map +1 -1
  55. package/lib/esm/features/facets/DocumentsFacetsNav.js +133 -0
  56. package/lib/esm/features/facets/DocumentsFacetsNav.js.map +1 -0
  57. package/lib/esm/features/facets/RunsFacetsNav.js +125 -0
  58. package/lib/esm/features/facets/RunsFacetsNav.js.map +1 -0
  59. package/lib/esm/features/facets/VFacetsNav.js +4 -113
  60. package/lib/esm/features/facets/VFacetsNav.js.map +1 -1
  61. package/lib/esm/features/facets/VStringFacet.js +6 -4
  62. package/lib/esm/features/facets/VStringFacet.js.map +1 -1
  63. package/lib/esm/features/facets/VTypeFacet.js +4 -5
  64. package/lib/esm/features/facets/VTypeFacet.js.map +1 -1
  65. package/lib/esm/features/facets/VUserFacet.js +1 -1
  66. package/lib/esm/features/facets/VUserFacet.js.map +1 -1
  67. package/lib/esm/features/facets/WorkflowExecutionsFacetsNav.js +98 -0
  68. package/lib/esm/features/facets/WorkflowExecutionsFacetsNav.js.map +1 -0
  69. package/lib/esm/features/facets/index.js +3 -2
  70. package/lib/esm/features/facets/index.js.map +1 -1
  71. package/lib/esm/features/store/collections/CollectionsTable.js +1 -1
  72. package/lib/esm/features/store/collections/CollectionsTable.js.map +1 -1
  73. package/lib/esm/features/store/collections/CreateCollection.js +10 -9
  74. package/lib/esm/features/store/collections/CreateCollection.js.map +1 -1
  75. package/lib/esm/features/store/collections/EditCollectionView.js +10 -9
  76. package/lib/esm/features/store/collections/EditCollectionView.js.map +1 -1
  77. package/lib/esm/features/store/collections/SelectCollection.js +1 -1
  78. package/lib/esm/features/store/collections/SelectCollection.js.map +1 -1
  79. package/lib/esm/features/store/objects/DocumentPreviewPanel.js +0 -1
  80. package/lib/esm/features/store/objects/DocumentPreviewPanel.js.map +1 -1
  81. package/lib/esm/features/store/objects/DocumentSearchResults.js +37 -2
  82. package/lib/esm/features/store/objects/DocumentSearchResults.js.map +1 -1
  83. package/lib/esm/features/store/objects/components/ContentOverview.js +0 -2
  84. package/lib/esm/features/store/objects/components/ContentOverview.js.map +1 -1
  85. package/lib/esm/features/store/objects/components/SelectDocument.js +2 -2
  86. package/lib/esm/features/store/objects/components/SelectDocument.js.map +1 -1
  87. package/lib/esm/features/store/objects/components/VectorSearchWidget.js +1 -1
  88. package/lib/esm/features/store/objects/components/VectorSearchWidget.js.map +1 -1
  89. package/lib/esm/features/store/objects/selection/actions/AddToCollectionAction.js +16 -4
  90. package/lib/esm/features/store/objects/selection/actions/AddToCollectionAction.js.map +1 -1
  91. package/lib/esm/features/store/objects/upload/DocumentUploadModal.js +72 -37
  92. package/lib/esm/features/store/objects/upload/DocumentUploadModal.js.map +1 -1
  93. package/lib/esm/features/store/types/ObjectSchemaEditor.js +15 -0
  94. package/lib/esm/features/store/types/ObjectSchemaEditor.js.map +1 -1
  95. package/lib/esm/features/user/UserInfo.js +8 -8
  96. package/lib/esm/features/user/UserInfo.js.map +1 -1
  97. package/lib/esm/router/HistoryNavigator.js +2 -2
  98. package/lib/esm/router/HistoryNavigator.js.map +1 -1
  99. package/lib/esm/shell/SplashScreen.js +19 -0
  100. package/lib/esm/shell/SplashScreen.js.map +1 -0
  101. package/lib/esm/shell/VertesiaShell.js +10 -0
  102. package/lib/esm/shell/VertesiaShell.js.map +1 -0
  103. package/lib/esm/shell/index.js +7 -0
  104. package/lib/esm/shell/index.js.map +1 -0
  105. package/lib/esm/shell/login/EnterpriseSigninButton.js +81 -0
  106. package/lib/esm/shell/login/EnterpriseSigninButton.js.map +1 -0
  107. package/lib/esm/shell/login/GitHubSignInButton.js +24 -0
  108. package/lib/esm/shell/login/GitHubSignInButton.js.map +1 -0
  109. package/lib/esm/shell/login/GoogleSignInButton.js +25 -0
  110. package/lib/esm/shell/login/GoogleSignInButton.js.map +1 -0
  111. package/lib/esm/shell/login/InviteAcceptModal.js +45 -0
  112. package/lib/esm/shell/login/InviteAcceptModal.js.map +1 -0
  113. package/lib/esm/shell/login/MicrosoftSigninButton.js +19 -0
  114. package/lib/esm/shell/login/MicrosoftSigninButton.js.map +1 -0
  115. package/lib/esm/shell/login/PreviewIcon.js +23 -0
  116. package/lib/esm/shell/login/PreviewIcon.js.map +1 -0
  117. package/lib/esm/shell/login/SignInModal.js +9 -0
  118. package/lib/esm/shell/login/SignInModal.js.map +1 -0
  119. package/lib/esm/shell/login/SigninScreen.js +64 -0
  120. package/lib/esm/shell/login/SigninScreen.js.map +1 -0
  121. package/lib/esm/shell/login/SignupForm.js +91 -0
  122. package/lib/esm/shell/login/SignupForm.js.map +1 -0
  123. package/lib/esm/shell/login/TerminalLogin.js +179 -0
  124. package/lib/esm/shell/login/TerminalLogin.js.map +1 -0
  125. package/lib/esm/shell/login/UserInfo.js +40 -0
  126. package/lib/esm/shell/login/UserInfo.js.map +1 -0
  127. package/lib/esm/shell/login/UserSessionMenu.js +31 -0
  128. package/lib/esm/shell/login/UserSessionMenu.js.map +1 -0
  129. package/lib/esm/shell/utils.js +6 -0
  130. package/lib/esm/shell/utils.js.map +1 -0
  131. package/lib/esm/widgets/SvgIcon.js +36 -0
  132. package/lib/esm/widgets/SvgIcon.js.map +1 -0
  133. package/lib/esm/widgets/index.js +7 -6
  134. package/lib/esm/widgets/index.js.map +1 -1
  135. package/lib/esm/widgets/upload/UploadSummary.js +1 -1
  136. package/lib/esm/widgets/upload/UploadSummary.js.map +1 -1
  137. package/lib/tsconfig.tsbuildinfo +1 -1
  138. package/lib/types/core/components/FormItem.d.ts +2 -1
  139. package/lib/types/core/components/shadcn/dialog.d.ts +2 -1
  140. package/lib/types/core/components/shadcn/filters/DynamicLabel.d.ts +1 -1
  141. package/lib/types/core/components/shadcn/filters/comboBox/DateCombobox.d.ts +5 -0
  142. package/lib/types/core/components/shadcn/filters/comboBox/SelectCombobox.d.ts +8 -0
  143. package/lib/types/core/components/shadcn/filters/comboBox/StringListCombobox.d.ts +5 -0
  144. package/lib/types/core/components/shadcn/filters/comboBox/TextCombobox.d.ts +5 -0
  145. package/lib/types/core/components/shadcn/filters/comboBox/comboBox.d.ts +4 -0
  146. package/lib/types/core/components/shadcn/filters/{selectFilter.d.ts → filter/SelectFilter.d.ts} +2 -2
  147. package/lib/types/core/components/shadcn/filters/{stringListFilter.d.ts → filter/StringListFilter.d.ts} +1 -1
  148. package/lib/types/core/components/shadcn/filters/{textFilter.d.ts → filter/TextFilter.d.ts} +1 -1
  149. package/lib/types/core/components/shadcn/filters/{dateFilter.d.ts → filter/dateFilter.d.ts} +1 -1
  150. package/lib/types/core/components/shadcn/filters/filter-styles.d.ts +1 -0
  151. package/lib/types/core/components/shadcn/filters/filterBar.d.ts +14 -4
  152. package/lib/types/core/components/shadcn/filters/index.d.ts +1 -1
  153. package/lib/types/core/components/shadcn/filters/types.d.ts +2 -0
  154. package/lib/types/features/agent/PayloadBuilder.d.ts +17 -8
  155. package/lib/types/features/agent/chat/ModernAgentOutput/utils.d.ts +2 -1
  156. package/lib/types/features/facets/DocumentsFacetsNav.d.ts +16 -0
  157. package/lib/types/features/facets/RunsFacetsNav.d.ts +18 -0
  158. package/lib/types/features/facets/VFacetsNav.d.ts +1 -1
  159. package/lib/types/features/facets/VStringFacet.d.ts +6 -2
  160. package/lib/types/features/facets/VTypeFacet.d.ts +3 -1
  161. package/lib/types/features/facets/WorkflowExecutionsFacetsNav.d.ts +13 -0
  162. package/lib/types/features/facets/index.d.ts +3 -2
  163. package/lib/types/shell/SplashScreen.d.ts +4 -0
  164. package/lib/types/shell/VertesiaShell.d.ts +7 -0
  165. package/lib/types/shell/index.d.ts +6 -0
  166. package/lib/types/shell/login/EnterpriseSigninButton.d.ts +5 -0
  167. package/lib/types/shell/login/GitHubSignInButton.d.ts +5 -0
  168. package/lib/types/shell/login/GoogleSignInButton.d.ts +5 -0
  169. package/lib/types/shell/login/InviteAcceptModal.d.ts +1 -0
  170. package/lib/types/shell/login/MicrosoftSigninButton.d.ts +5 -0
  171. package/lib/types/shell/login/PreviewIcon.d.ts +5 -0
  172. package/lib/types/shell/login/SignInModal.d.ts +6 -0
  173. package/lib/types/shell/login/SigninScreen.d.ts +8 -0
  174. package/lib/types/shell/login/SignupForm.d.ts +7 -0
  175. package/lib/types/shell/login/TerminalLogin.d.ts +1 -0
  176. package/lib/types/shell/login/UserInfo.d.ts +5 -0
  177. package/lib/types/shell/login/UserSessionMenu.d.ts +8 -0
  178. package/lib/types/shell/utils.d.ts +1 -0
  179. package/lib/types/widgets/SvgIcon.d.ts +6 -0
  180. package/lib/types/widgets/index.d.ts +7 -6
  181. package/lib/vertesia-ui-core.js +1 -1
  182. package/lib/vertesia-ui-core.js.map +1 -1
  183. package/lib/vertesia-ui-features.js +1 -1
  184. package/lib/vertesia-ui-features.js.map +1 -1
  185. package/lib/vertesia-ui-router.js +1 -1
  186. package/lib/vertesia-ui-router.js.map +1 -1
  187. package/lib/vertesia-ui-shell.js +2 -0
  188. package/lib/vertesia-ui-shell.js.map +1 -0
  189. package/lib/vertesia-ui-widgets.js +1 -1
  190. package/lib/vertesia-ui-widgets.js.map +1 -1
  191. package/package.json +14 -6
  192. package/src/core/components/Badge.tsx +12 -8
  193. package/src/core/components/FormItem.tsx +4 -3
  194. package/src/core/components/InputList.tsx +21 -17
  195. package/src/core/components/shadcn/checkbox.tsx +2 -2
  196. package/src/core/components/shadcn/command.tsx +1 -1
  197. package/src/core/components/shadcn/dialog.tsx +18 -9
  198. package/src/core/components/shadcn/filters/DynamicLabel.tsx +1 -2
  199. package/src/core/components/shadcn/filters/comboBox/DateCombobox.tsx +211 -0
  200. package/src/core/components/shadcn/filters/{comboBox.tsx → comboBox/SelectCombobox.tsx} +8 -192
  201. package/src/core/components/shadcn/filters/comboBox/StringListCombobox.tsx +76 -0
  202. package/src/core/components/shadcn/filters/comboBox/TextCombobox.tsx +81 -0
  203. package/src/core/components/shadcn/filters/comboBox/comboBox.tsx +4 -0
  204. package/src/core/components/shadcn/filters/filter/SelectFilter.tsx +161 -0
  205. package/src/core/components/shadcn/filters/{stringListFilter.tsx → filter/StringListFilter.tsx} +7 -7
  206. package/src/core/components/shadcn/filters/{textFilter.tsx → filter/TextFilter.tsx} +17 -11
  207. package/src/core/components/shadcn/filters/filter/dateFilter.tsx +256 -0
  208. package/src/core/components/shadcn/filters/filter-styles.ts +87 -0
  209. package/src/core/components/shadcn/filters/filterBar.tsx +208 -152
  210. package/src/core/components/shadcn/filters/filters.tsx +7 -5
  211. package/src/core/components/shadcn/filters/index.ts +1 -1
  212. package/src/core/components/shadcn/filters/types.ts +2 -0
  213. package/src/core/components/toast/NotificationPanel.tsx +38 -22
  214. package/src/features/agent/PayloadBuilder.tsx +56 -31
  215. package/src/features/agent/chat/ModernAgentConversation.tsx +10 -4
  216. package/src/features/agent/chat/ModernAgentOutput/AllMessagesMixed.tsx +7 -6
  217. package/src/features/agent/chat/ModernAgentOutput/MessageItem.tsx +12 -1
  218. package/src/features/agent/chat/ModernAgentOutput/SlidingMessages.tsx +2 -1
  219. package/src/features/agent/chat/ModernAgentOutput/utils.ts +12 -4
  220. package/src/features/facets/DocumentsFacetsNav.tsx +171 -0
  221. package/src/features/facets/RunsFacetsNav.tsx +166 -0
  222. package/src/features/facets/VFacetsNav.tsx +10 -126
  223. package/src/features/facets/VStringFacet.tsx +10 -4
  224. package/src/features/facets/VTypeFacet.tsx +6 -5
  225. package/src/features/facets/VUserFacet.tsx +5 -3
  226. package/src/features/facets/WorkflowExecutionsFacetsNav.tsx +132 -0
  227. package/src/features/facets/index.ts +5 -2
  228. package/src/features/store/collections/CollectionsTable.tsx +3 -2
  229. package/src/features/store/collections/CreateCollection.tsx +17 -15
  230. package/src/features/store/collections/EditCollectionView.tsx +19 -16
  231. package/src/features/store/collections/SelectCollection.tsx +1 -1
  232. package/src/features/store/objects/DocumentPreviewPanel.tsx +0 -1
  233. package/src/features/store/objects/DocumentSearchResults.tsx +80 -11
  234. package/src/features/store/objects/components/ContentOverview.tsx +0 -2
  235. package/src/features/store/objects/components/SelectDocument.tsx +2 -2
  236. package/src/features/store/objects/components/VectorSearchWidget.tsx +2 -2
  237. package/src/features/store/objects/selection/actions/AddToCollectionAction.tsx +40 -19
  238. package/src/features/store/objects/upload/DocumentUploadModal.tsx +160 -214
  239. package/src/features/store/types/ObjectSchemaEditor.tsx +15 -0
  240. package/src/features/user/UserInfo.tsx +17 -14
  241. package/src/router/HistoryNavigator.ts +2 -2
  242. package/src/shell/SplashScreen.tsx +41 -0
  243. package/src/shell/VertesiaShell.tsx +27 -0
  244. package/src/shell/index.tsx +6 -0
  245. package/src/shell/login/EnterpriseSigninButton.tsx +106 -0
  246. package/src/shell/login/GitHubSignInButton.tsx +40 -0
  247. package/src/shell/login/GoogleSignInButton.tsx +36 -0
  248. package/src/shell/login/InviteAcceptModal.tsx +78 -0
  249. package/src/shell/login/MicrosoftSigninButton.tsx +30 -0
  250. package/src/shell/login/PreviewIcon.tsx +29 -0
  251. package/src/shell/login/SignInModal.tsx +28 -0
  252. package/src/shell/login/SigninScreen.tsx +162 -0
  253. package/src/shell/login/SignupForm.tsx +178 -0
  254. package/src/shell/login/TerminalLogin.tsx +299 -0
  255. package/src/shell/login/UserInfo.tsx +76 -0
  256. package/src/shell/login/UserSessionMenu.tsx +81 -0
  257. package/src/shell/utils.tsx +7 -0
  258. package/src/widgets/SvgIcon.tsx +44 -0
  259. package/src/widgets/index.ts +7 -6
  260. package/src/widgets/upload/UploadSummary.tsx +3 -4
  261. package/lib/esm/core/components/shadcn/filters/comboBox.js +0 -101
  262. package/lib/esm/core/components/shadcn/filters/comboBox.js.map +0 -1
  263. package/lib/esm/core/components/shadcn/filters/dateFilter.js +0 -36
  264. package/lib/esm/core/components/shadcn/filters/dateFilter.js.map +0 -1
  265. package/lib/esm/core/components/shadcn/filters/selectFilter.js +0 -67
  266. package/lib/esm/core/components/shadcn/filters/selectFilter.js.map +0 -1
  267. package/lib/esm/core/components/shadcn/filters/stringListFilter.js.map +0 -1
  268. package/lib/esm/core/components/shadcn/filters/textFilter.js.map +0 -1
  269. package/lib/esm/features/facets/InteractionFacet.js +0 -39
  270. package/lib/esm/features/facets/InteractionFacet.js.map +0 -1
  271. package/lib/esm/features/facets/TypeOptions.js +0 -19
  272. package/lib/esm/features/facets/TypeOptions.js.map +0 -1
  273. package/lib/esm/features/facets/UserFacet.js +0 -33
  274. package/lib/esm/features/facets/UserFacet.js.map +0 -1
  275. package/lib/types/core/components/shadcn/filters/comboBox.d.ts +0 -22
  276. package/lib/types/features/facets/InteractionFacet.d.ts +0 -9
  277. package/lib/types/features/facets/TypeOptions.d.ts +0 -3
  278. package/lib/types/features/facets/UserFacet.d.ts +0 -11
  279. package/src/core/components/shadcn/filters/dateFilter.tsx +0 -82
  280. package/src/core/components/shadcn/filters/selectFilter.tsx +0 -110
  281. package/src/features/facets/InteractionFacet.tsx +0 -53
  282. package/src/features/facets/TypeOptions.tsx +0 -22
  283. package/src/features/facets/UserFacet.tsx +0 -61
@@ -1,2 +1,2 @@
1
- import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import r from"clsx";import{AnimatePresence as s,motion as a}from"motion/react";import i,{useMemo as l,useState as o,useEffect as c,createContext as d,useContext as m,useRef as u,useCallback as h,useLayoutEffect as p}from"react";import{cn as g,useToast as f,Badge as b,Button as y,Popover as x,PopoverTrigger as v,PopoverContent as w,Command as N,CommandList as k,CommandGroup as C,CommandItem as S,Modal as _,ModalTitle as j,ModalBody as P,RadioGroup as T,FormItem as I,Input as $,ModalFooter as E,RadioOptionAdapter as L,Spinner as A,Card as U,Separator as O,CardContent as z,VTooltip as F,SelectBox as D,InputList as R,useFetch as M,Avatar as V,Table as q,FilterBar as W,TBody as B,SharedState as J,useWatchSharedState as H,useIntersectionObserver as G,ErrorBox as K,VModal as Q,VModalTitle as Y,VModalBody as X,useFlag as Z,Styles as ee,useDebounce as te,SidePanel as ne,Divider as re,VSelectBox as se,Switch as ae,VModalFooter as ie,TR as le,EmptyCollection as oe,ConfirmModal as ce,Textarea as de,SelectList as me,Portal as ue,MessageBox as he,Center as pe}from"@vertesia/ui/core";import{AgentMessageType as ge,mergePromptsSchema as fe,supportsToolUse as be,ImageRenditionFormat as ye,PrincipalType as xe,ApiKeyTypes as ve,InteractionStatus as we,SupportedEmbeddingTypes as Ne}from"@vertesia/common";import{useUserSession as ke}from"@vertesia/ui/session";import{X as Ce,Circle as Se,AlertCircle as _e,Clock as je,CheckCircle as Pe,CopyIcon as Te,Bot as Ie,MessageSquare as $e,Info as Ee,User as Le,ClipboardList as Ae,XIcon as Ue,MoreVertical as Oe,ExternalLink as ze,DownloadCloudIcon as Fe,TableProperties as De,LayoutGrid as Re,Copy as Me,SquarePen as Ve,Download as qe,Eye as We,CheckCircleIcon as Be,UploadIcon as Je,AlertCircleIcon as He,FileIcon as Ge,XCircleIcon as Ke,FolderIcon as Qe,RefreshCw as Ye,ChevronsUpDown as Xe,FileText as Ze,Maximize2 as et,ChevronRight as tt,Trash2 as nt,Search as rt,FolderClosed as st,EllipsisVertical as at,PaperclipIcon as it,SendIcon as lt,Activity as ot,Cpu as ct,CloudDownload as dt,ChevronsUp as mt,ImageIcon as ut,InfoIcon as ht,AtSignIcon as pt,ChevronsDown as gt}from"lucide-react";import{NavLink as ft,useNavigate as bt}from"@vertesia/ui/router";import yt from"dayjs";import xt from"react-markdown";import vt from"remark-gfm";import wt from"ajv";import{JSONDisplay as Nt,DropZone as kt,UploadSummary as Ct,useSchema as St,CodeMirrorEditor as _t,SchemaEditor as jt,ManagedObject as Pt,GeneratedForm as Tt,Popover as It,JSONCode as $t,XMLViewer as Et}from"@vertesia/ui/widgets";import Lt from"@monaco-editor/react";import At from"dayjs/plugin/localizedFormat";import Ut from"dayjs/plugin/relativeTime";import{Md5 as Ot}from"ts-md5";import{json as zt}from"@codemirror/lang-json";import{basicSetup as Ft}from"codemirror";import{ErrorBoundary as Dt}from"react-error-boundary";import{SidebarItem as Rt}from"@vertesia/ui/layout";function Mt({children:t,secondary:n=!1}){return e("span",{className:n?"bg-secondary text-primary":"text-foreground bg-muted",children:t})}function Vt(e){return e?"array"===e.name?Vt(e.innerType):e:void 0}function qt({property:n}){return t("div",{className:"flex items-center gap-x-2",children:[e("div",{className:"font-semibold text-gray-600",children:n.name}),n.optional&&e(Mt,{children:"optional"}),e(Mt,{children:n.type.value})]})}function Wt({activities:t}){return e("div",{className:"flex flex-col gap-y-4 divide-y divide-gray-200",children:t.map((t=>e(Jt,{activity:t},t.name)))})}function Bt({code:n,children:r}){return t("div",{className:"flex gap-2 items-center border-b border-b-gray-200 mb-2",children:[e("div",{className:"text-lg font-medium text-gray-900 py-2 ",children:r}),n&&e("div",{children:e(Mt,{children:n})})]})}function Jt({activity:n,headingClass:r,headingRef:s}){return t("div",{className:r,id:n.name,ref:s,children:[e("div",{className:"text-xl font-semibold pt-8",children:n.title}),e("div",{className:"pb-4",children:e(Mt,{children:n.name})}),n.doc&&e("div",{className:"text-gray-700 pb-2",children:n.doc}),t("div",{className:"pb-4",children:[e(Bt,{code:n.paramsType,children:"Parameters"}),e("div",{className:"divide-y divide-gray-100",children:n.params.map((t=>e(Ht,{property:t},t.name)))})]}),t("div",{className:"pb-4",children:[e(Bt,{children:"Returns"}),e("div",{children:n.returnType?n.returnType.value:"void"})]})]})}function Ht({property:n,className:s}){const a=l((()=>{const t=Vt(n.type.innerType)??n.type;return"object"===t.name&&t.members?e(Kt,{members:t.members}):"enum"===t.name&&t.enum?e(Gt,{values:t.enum}):null}),[n.type.innerType]);return t("div",{className:r("py-2",s),children:[e(qt,{property:n}),n.doc&&e("div",{className:"text-gray-700 text-sm pt-2",children:n.doc}),a&&e("div",{className:"my-2 overflow-hidden",children:a})]})}function Gt({values:t}){return e("div",{className:"flex flex-wrap items-center gap-2",children:t.map(((t,n)=>e(Mt,{secondary:!0,children:t},n)))})}function Kt({members:n}){return e(Yt,{className:"rounded-md border border-gray-200",button:n=>t("div",{className:"px-4 py-2 flex items-center gap-x-2 text-sm font-medium hover:text-blue-600",children:[e(Xt,{isOpen:n}),e("div",n?{children:"Hide child properties"}:{children:"Show child properties"})]}),body:e(Qt,{properties:n})})}function Qt({properties:t}){return e("div",{className:"border-l-2 border-l-blue-200 flex flex-col divide-y divide-gray-100 border-t border-t-gray-200",children:t.map((t=>e(Ht,{property:t,className:"px-4 py-2"},t.name)))})}function Yt({button:n,body:i,className:l,isInitiallyOpen:c}){const[d,m]=o(c||!1);return t("div",{className:r(d?"block":"inline-block",l),children:[e("button",{className:"p-0 m-0 bg-transparent",onClick:()=>m(!d),children:e(s,{children:n(d)})}),e(s,{children:d&&e(a.div,{className:"overflow-hidden",initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.3,ease:"easeOut"},children:i})})]})}function Xt({isOpen:t}){return e(s,{propagate:!0,mode:"wait",children:e(a.div,{className:"font-mono font-semibold text-gray-400 text-lg",initial:{rotate:0},animate:{rotate:t?45:0},transition:{duration:.2},children:"+"},"closeIcon")})}function Zt({className:n,inline:r=!1}){return t("div",{className:g("flex items-center gap-1",r?"inline-flex":"",n),children:[e("div",{className:"w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_infinite_ease-in-out] hover:bg-blue-600",style:{transform:"translateY(0)",animationRange:"0px -8px"}}),e("div",{className:"w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_0.3s_infinite_ease-in-out] hover:bg-blue-600",style:{transform:"translateY(0)",animationRange:"0px -8px"}}),e("div",{className:"w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_0.6s_infinite_ease-in-out] hover:bg-blue-600",style:{transform:"translateY(0)",animationRange:"0px -8px"}})]})}function en({className:n,inline:r=!1,color:s="blue"}){const a={blue:"from-blue-400 to-indigo-500 dark:from-blue-500 dark:to-indigo-400",purple:"from-purple-400 to-violet-500 dark:from-purple-500 dark:to-violet-400",teal:"from-teal-400 to-emerald-500 dark:from-teal-500 dark:to-emerald-400",green:"from-green-400 to-emerald-500 dark:from-green-500 dark:to-emerald-400",amber:"from-amber-400 to-orange-500 dark:from-amber-500 dark:to-orange-400"}[s];return t("div",{className:g("flex items-center gap-1.5",r?"inline-flex":"",n),children:[e("div",{className:`w-2 h-2 bg-gradient-to-r ${a} rounded-full animate-[bounce_1.2s_ease-in-out_infinite]`}),e("div",{className:`w-2 h-2 bg-gradient-to-r ${a} rounded-full animate-[bounce_1.2s_ease-in-out_0.2s_infinite]`}),e("div",{className:`w-2 h-2 bg-gradient-to-r ${a} rounded-full animate-[bounce_1.2s_ease-in-out_0.4s_infinite]`})]})}function tn({className:n,size:r="md",color:s="blue"}){const a={blue:"bg-blue-500 dark:bg-blue-400",purple:"bg-purple-500 dark:bg-purple-400",teal:"bg-teal-500 dark:bg-teal-400",green:"bg-green-500 dark:bg-green-400",amber:"bg-amber-500 dark:bg-amber-400"};return t("span",{className:g("relative flex",n),children:[e("span",{className:g("animate-ping absolute inline-flex h-full w-full rounded-full opacity-60",a[s])}),e("span",{className:g("animate-pulse absolute inline-flex h-[80%] w-[80%] rounded-full opacity-80",a[s]),style:{left:"10%",top:"10%",animationDuration:"2s"}}),e("span",{className:g("relative inline-flex rounded-full",a[s],{sm:"w-3 h-3",md:"w-5 h-5",lg:"w-7 h-7"}[r])})]})}function nn({className:t,color:n="blue"}){const[r,s]=o(".");return c((()=>{const e=setInterval((()=>{s((e=>"."===e?"..":".."===e?"...":"."))}),500);return()=>clearInterval(e)}),[]),e("span",{className:g({blue:"text-blue-600 dark:text-blue-400",purple:"text-purple-600 dark:text-purple-400",teal:"text-teal-600 dark:text-teal-400",green:"text-green-600 dark:text-green-400",amber:"text-amber-600 dark:text-amber-400"}[n],"font-bold",t),children:r})}function rn({message:n,className:r,color:s="blue"}){const a={blue:{dot:"bg-blue-500 dark:bg-blue-400",text:"text-blue-700 dark:text-blue-300"},purple:{dot:"bg-purple-500 dark:bg-purple-400",text:"text-purple-700 dark:text-purple-300"},teal:{dot:"bg-teal-500 dark:bg-teal-400",text:"text-teal-700 dark:text-teal-300"},green:{dot:"bg-green-500 dark:bg-green-400",text:"text-green-700 dark:text-green-300"},amber:{dot:"bg-amber-500 dark:bg-amber-400",text:"text-amber-700 dark:text-amber-300"}};return t("div",{className:g("flex items-center gap-2 py-1",r),children:[t("div",{className:"flex space-x-1",children:[e("div",{className:`w-1.5 h-1.5 ${a[s].dot} rounded-full animate-bounce`}),e("div",{className:`w-1.5 h-1.5 ${a[s].dot} rounded-full animate-bounce`,style:{animationDelay:"0.2s"}}),e("div",{className:`w-1.5 h-1.5 ${a[s].dot} rounded-full animate-bounce`,style:{animationDelay:"0.4s"}})]}),e("div",{className:`${a[s].text} font-medium text-xs`,children:n})]})}function sn({className:n,color:r="blue",width:s="md",message:a}){const[i,l]=o(15),[d,m]=o("increasing"),[u,h]=o(.4);return c((()=>{let e,t=Date.now();const n=()=>{const r=Date.now(),s=r-t;t=r,l((e=>{const t=u*(s/16);let n="increasing"===d?e+t:e-t;return n>=85?(m("decreasing"),h(.3+.2*Math.random()),85):n<=15?(m("increasing"),h(.3+.2*Math.random()),15):(Math.random()>.99&&h((e=>Math.max(.2,Math.min(.5,e+(.1*Math.random()-.05))))),n)})),e=requestAnimationFrame(n)};return e=requestAnimationFrame(n),()=>{cancelAnimationFrame(e)}}),[d,u]),t("div",{className:g("flex flex-col gap-1",n),children:[a&&e("div",{className:`text-xs font-medium ${{blue:"text-blue-700 dark:text-blue-300",purple:"text-purple-700 dark:text-purple-300",teal:"text-teal-700 dark:text-teal-300",green:"text-green-700 dark:text-green-300",amber:"text-amber-700 dark:text-amber-300"}[r]} mb-1`,children:a}),e("div",{className:g("h-1.5 rounded-full overflow-hidden shadow-inner",{blue:"bg-blue-200 dark:bg-blue-900/30",purple:"bg-purple-200 dark:bg-purple-900/30",teal:"bg-teal-200 dark:bg-teal-900/30",green:"bg-green-200 dark:bg-green-900/30",amber:"bg-amber-200 dark:bg-amber-900/30"}[r],{sm:"w-24",md:"w-32",lg:"w-48",xl:"w-64",full:"w-full"}[s]),children:e("div",{className:g("h-full rounded-full",{blue:"bg-gradient-to-r from-blue-400 to-blue-500 dark:from-blue-500 dark:to-blue-400",purple:"bg-gradient-to-r from-purple-400 to-purple-500 dark:from-purple-500 dark:to-purple-400",teal:"bg-gradient-to-r from-teal-400 to-teal-500 dark:from-teal-500 dark:to-teal-400",green:"bg-gradient-to-r from-green-400 to-green-500 dark:from-green-500 dark:to-green-400",amber:"bg-gradient-to-r from-amber-400 to-amber-500 dark:from-amber-500 dark:to-amber-400"}[r]),style:{width:`${i}%`,transition:"width 150ms cubic-bezier(0.4, 0.0, 0.2, 1)"}})})]})}function an({className:t,color:n="blue",size:r="md"}){const[s,a]=o(Array(7).fill(50)),i={sm:{width:"w-16",height:"h-4",barWidth:"w-0.5",gap:"gap-[2px]"},md:{width:"w-20",height:"h-5",barWidth:"w-1",gap:"gap-[3px]"},lg:{width:"w-24",height:"h-6",barWidth:"w-1.5",gap:"gap-1"}},l={blue:"bg-gradient-to-b from-blue-400 to-blue-500 dark:from-blue-400 dark:to-blue-500",purple:"bg-gradient-to-b from-purple-400 to-purple-500 dark:from-purple-400 dark:to-purple-500",teal:"bg-gradient-to-b from-teal-400 to-teal-500 dark:from-teal-400 dark:to-teal-500",green:"bg-gradient-to-b from-green-400 to-green-500 dark:from-green-400 dark:to-green-500",amber:"bg-gradient-to-b from-amber-400 to-amber-500 dark:from-amber-400 dark:to-amber-500"};return c((()=>{let e;const t=[1.2,1,1.5,.8,1.3,.9,1.1],n=[0,.5,1,1.5,2,2.5,3];let r=0;const i=()=>{r+=.02;const l=s.map(((e,s)=>10+40*(Math.sin(r*t[s]+n[s])+1)));a(l),e=requestAnimationFrame(i)};return e=requestAnimationFrame(i),()=>{cancelAnimationFrame(e)}}),[]),e("div",{className:g("flex items-end justify-center",i[r].width,i[r].height,i[r].gap,t),children:s.map(((t,s)=>e("div",{className:g(i[r].barWidth,"rounded-full transform-gpu",l[n]),style:{height:`${t}%`,transition:"height 100ms cubic-bezier(0.4, 0.0, 0.2, 1)",opacity:.9}},s)))})}function ln({plan:r,workstreamStatus:s,isOpen:a,onClose:i,plans:l=[],activePlanIndex:o=0,onChangePlan:c=()=>{}}){return a?t("div",{className:"fixed top-24 right-8 bottom-24 z-50 bg-white dark:bg-gray-900 shadow-xl border border-gray-200 dark:border-gray-700 overflow-hidden",style:{width:"350px"},children:[t("div",{className:"flex items-center justify-between p-3 border-b border-gray-200 dark:border-gray-800",children:[e("h3",{className:"font-bold text-gray-800 dark:text-gray-200 text-base",children:"Plan"}),t("button",{className:"p-1 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-full text-gray-500 dark:text-gray-400",onClick:i,children:[e(Ce,{className:"h-4 w-4"}),e("span",{className:"sr-only",children:"Close"})]})]}),t("div",{className:"p-3 overflow-y-auto",style:{height:"calc(100% - 44px)",maxHeight:"calc(100vh - 150px)"},children:[t("div",{className:"mb-3 p-2 bg-blue-50 dark:bg-blue-900/20 rounded-md border border-blue-100 dark:border-blue-800",children:[e("div",{className:"text-xs font-medium text-blue-700 dark:text-blue-300 mb-1",children:"Task Progress"}),e("div",{className:"flex items-center gap-2",children:(()=>{const a=r.plan||[],i=a.length;let l=0;i>0&&a.forEach((e=>{if(e&&e.id){const t=e.id.toString();"completed"===s.get(t)&&l++}}));const o=i>0?Math.round(l/i*100):0;return t(n,{children:[e("div",{className:"w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2",children:e("div",{className:"bg-blue-600 h-2 rounded-full",style:{width:`${o}%`}})}),e("span",{className:"text-xs text-gray-600 dark:text-gray-400",children:i>0?`${l}/${i}`:"0/0"})]})})()})]}),l.length>1&&t("div",{className:"mb-3 flex items-center justify-between",children:[e("button",{className:"text-xs px-2 py-1 rounded-md bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-300 disabled:opacity-50",onClick:()=>c(Math.min(l.length-1,o+1)),disabled:o>=l.length-1,children:"Older Plan"}),e("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:l[o]?.timestamp?new Date(l[o].timestamp).toLocaleTimeString():"Unknown time"}),e("button",{className:"text-xs px-2 py-1 rounded-md bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-300 disabled:opacity-50",onClick:()=>c(Math.max(0,o-1)),disabled:o<=0,children:"Newer Plan"})]}),t("div",{className:"rounded-md border border-gray-200 dark:border-gray-800",children:[e("div",{className:"p-2 border-b border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-900/50",children:e("div",{className:"font-medium text-xs",children:"Step-by-Step Plan"})}),e("div",{className:"divide-y divide-gray-100 dark:divide-gray-800 max-h-[calc(100vh-350px)] overflow-y-auto",children:r.plan&&r.plan.length>0?r.plan.map(((n,r)=>{const a=n.id?n.id.toString():`task-${r}`,i=n.goal||`Task ${r+1}`;let l=n.status||"pending";s.has(a)&&(l=s.get(a));let o=Se,c="text-gray-400",d="";return"in_progress"===l?(o=je,c="text-blue-500",d="bg-blue-50/50 dark:bg-blue-900/10"):"completed"===l&&(o=Pe,c="text-green-500"),t("div",{className:`flex p-3 my-1 ${d}`,children:[e("div",{className:`mr-2 mt-0.5 flex-shrink-0 ${c}`,children:e(o,{className:"h-3.5 w-3.5"})}),t("div",{className:"w-full",children:[e("div",{className:"text-sm font-medium text-gray-800 dark:text-gray-200 mb-2",children:i}),t("div",{className:"mt-1 flex justify-between items-center",children:[e("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300",children:a}),e("span",{className:"ml-2 text-xs px-2 py-0.5 rounded-full "+("completed"===l?"bg-green-100 text-green-600 dark:bg-green-900/30 dark:text-green-400":"in_progress"===l?"bg-blue-100 text-blue-600 dark:bg-blue-900/30 dark:text-blue-400":"bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400"),children:"completed"===l?"Completed":"in_progress"===l?"In Progress":"Pending"})]})]})]},r)})):t("div",{className:"p-3 text-center text-gray-500 dark:text-gray-400 italic",children:[e(_e,{className:"h-4 w-4 mx-auto mb-2 text-amber-500"}),e("p",{className:"text-xs",children:"No plan has been detected yet"}),e("p",{className:"text-xs mt-1",children:"Plans will appear here when the agent creates one"})]})})]}),(()=>{const n=new Set((r.plan||[]).filter((e=>e&&e.id)).map((e=>e.id.toString()))),a=Array.from(s.entries()).filter((([e])=>"main"!==e&&!n.has(e)));return a.length>0?t("div",{className:"mt-3 rounded-md border border-gray-200 dark:border-gray-800",children:[e("div",{className:"p-2 border-b border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-900/50",children:e("div",{className:"font-medium text-xs",children:"Workstreams"})}),e("div",{className:"p-3",children:e("div",{className:"grid grid-cols-1 gap-2",children:a.map((([n,r])=>{let s=Se,a="text-gray-400",i="bg-gray-100 dark:bg-gray-800",l="Pending";return"in_progress"===r?(s=je,a="text-blue-500",i="bg-blue-100 dark:bg-blue-800/30",l="In Progress"):"completed"===r&&(s=Pe,a="text-green-500",i="bg-green-100 dark:bg-green-800/30",l="Completed"),t("div",{className:`flex items-center p-1.5 rounded ${i}`,children:[e("div",{className:`mr-1.5 ${a}`,children:e(s,{className:"h-3.5 w-3.5"})}),e("div",{className:"flex-1",children:e("span",{className:"text-xs font-medium text-gray-800 dark:text-gray-300",children:n})}),e("span",{className:"text-xs font-medium",children:l})]},n)}))})})]}):null})()]})]}):null}const on=["Brewing some code magic...","Doing the robot dance...","Cooking up something good...","Working my gears...","Parsing the possibilities...","Crunching the numbers...","Connecting the digital dots...","Processing at maximum capacity...","Searching through my circuits...","Running advanced algorithms...","Computing optimal solutions...","Loading brilliance.exe...","Scanning the knowledge base...","Optimizing response protocols...","Having a quick brainstorm...","Thinking cap firmly on...","Pondering the digital universe...","Consulting my silicon wisdom...","Untangling the logic knots...","Assembling clever responses...","Mixing thoughtful ingredients...","Polishing the perfect answer...","Taking a momentary mind sprint...","Connecting virtual synapses...","Baking fresh ideas...","Stirring the thought pot...","Simmering solutions slowly...","Whipping up a smart response...","Adding a dash of intelligence...","Preparing a gourmet answer...","Growing brilliant ideas...","Cultivating the perfect response...","Gathering digital nectar...","Planting seeds of solutions...","Exploring the data landscape...","Mapping the solution path...","Navigating through possibilities...","Charting the course to answers...","Embarking on a thought expedition...","Sketching out concepts...","Painting with digital brushstrokes...","Composing my response symphony...","Crafting precision answers...","Weaving threads of information...","Just a moment of processing...","Taking a quick thinking break...","Almost there, final touches...","Putting the pieces together...","Making progress, hold tight..."];function cn(e){return e.workstream_id?(e.type===ge.COMPLETE&&console.log("[getWorkstreamId] COMPLETE message with workstream_id:",e.workstream_id),e.workstream_id):(e.type===ge.COMPLETE&&console.log("[getWorkstreamId] COMPLETE message without workstream_id, defaulting to 'main'"),"main")}function dn({message:r,showPulsatingCircle:s=!1}){const[a,i]=o(!1),[l,d]=o(""),[m,u]=o(!1),{client:h}=ke(),p=f(),g=(()=>{const t={containerClass:"bg-white border-l-4 border-l-muted/30 shadow-sm",iconComponent:e(Ie,{className:"size-4 text-muted"}),sender:""};switch(r.type){case ge.ANSWER:return{...t,containerClass:"bg-white border-l-4 border-l-muted/30 shadow-sm",iconComponent:e(Ie,{className:"size-4 text-muted"}),sender:"Agent"};case ge.COMPLETE:return{...t,containerClass:"bg-white border-l-4 border-l-green-500 shadow-sm",iconComponent:e(Pe,{className:"size-4 text-success"}),sender:"Completed"};case ge.QUESTION:return{...t,iconComponent:e(Le,{className:"size-4 text-muted"}),sender:"User"};case ge.THOUGHT:return{...t,iconComponent:s?e(tn,{size:"sm",color:"blue"}):e(Ie,{className:"size-4 text-muted"}),sender:"Agent"};case ge.ERROR:return{...t,iconComponent:e(_e,{className:"size-4 text-muted"}),sender:"System"};case ge.UPDATE:return{...t,containerClass:"bg-white border-l-4 border-success shadow-sm",iconComponent:e(Ee,{className:"size-4 text-success"}),sender:"Update"};case ge.PLAN:return{...t,iconComponent:e($e,{className:"size-4 text-muted"}),sender:"Agent"};default:return{...t,sender:"Agent"}}})(),x=()=>{let e="";if(r.message&&(e="object"==typeof r.message?JSON.stringify(r.message,null,2):r.message.trim?r.message.trim():String(r.message)),"string"==typeof e&&e.includes("%thinking_message%")){const t=Math.floor(Math.random()*on.length);e=e.replace(/%thinking_message%/g,on[t])}return e},v=r=>"object"==typeof r?e("pre",{className:"text-xs font-mono whitespace-pre-wrap overflow-x-auto bg-gray-100 dark:bg-gray-800 p-2 rounded text-gray-700 ",children:JSON.stringify(r,null,2)}):e("div",{className:"vprose prose-sm",children:e(xt,{remarkPlugins:[vt],components:{a:({node:t,...n})=>{const r=n.href||"";return r.includes("/store/objects")?e(ft,{href:r,topLevelNav:!0,children:n.children}):e("a",{...n,target:"_blank",rel:"noopener noreferrer"})},img:({node:t,...n})=>e("img",{...n,className:"max-w-full h-auto rounded-lg shadow-md my-3 cursor-pointer hover:shadow-lg transition-shadow",loading:"lazy",onClick:()=>n.src&&window.open(n.src,"_blank")}),code:({node:r,className:s,children:a,...i})=>{const l=/language-(\w+)/.exec(s||""),o=!l,c=l?l[1]:"";return t(n,{children:[!o&&c&&e("div",{className:"code-language-indicator",children:c}),e("code",{...i,children:a})]})},p:t=>e("p",{...t}),strong:t=>e("strong",{...t}),em:t=>e("em",{...t}),pre:t=>e("pre",{...t}),h1:t=>e("h1",{...t}),h2:t=>e("h2",{...t}),h3:t=>e("h3",{...t}),li:t=>e("li",{...t}),ul:t=>e("ul",{...t}),ol:t=>e("ol",{...t}),blockquote:t=>e("blockquote",{...t}),hr:t=>e("hr",{...t}),table:t=>e("div",{className:"overflow-x-auto",children:e("table",{...t})}),th:t=>e("th",{...t}),td:t=>e("td",{...t})},children:r})}),w=x();c((()=>{(async()=>{if(w){u(!0);try{const e=await(async e=>{if("string"!=typeof e)return e;let t=e;t=t.replace(/\[([^\]]+)\]\((store|collection):([a-f\d]{24})\)/gi,((e,t,n,r)=>`[${t}](/store/${"store"===n?"objects":"collections"}/${r})`));const n=Array.from(t.matchAll(/!\[([^\]]*)\]\(image:([^)]+)\)/g)),r=await Promise.all(n.map((async e=>{const[t,n,r]=e;try{return{fullMatch:t,replacement:`![${n}](${(await h.files.getDownloadUrl(r)).url})`}}catch(e){return console.error(`Failed to get download URL for image: ${r}`,e),{fullMatch:t,replacement:t}}})));for(const{fullMatch:e,replacement:n}of r)t=t.replace(e,n);return t})((e=>{if("string"!=typeof e)return e;if(r.type===ge.THOUGHT||"string"==typeof r.message&&(r.message.toLowerCase().includes("thinking about")||r.message.toLowerCase().includes("i'm thinking")||r.message.toLowerCase().includes("💭"))){let t=e;return/\d+\.\s+.+/.test(t)&&(t=t.replace(/(\d+\.\s+.+?)(?=\s+\d+\.\s+|$)/g,"$1\n\n"),t=t.replace(/(\d+\.\s+.+\n)([^\d\n][^:])/g,"$1 $2")),t.includes(":")&&!t.includes("\n\n")&&(t=t.replace(/\b(First|Next|Then|Finally|Lastly|Additionally|Step \d+):\s+/gi,"\n\n$&")),t.includes(" - ")&&(t=t.replace(/\s+-\s+/g,"\n- ")),t}return/\d+\.\s+.+/.test(e)&&!e.includes("\n\n")?e.replace(/(\d+\.\s+.+?)(?=\s+\d+\.\s+|$)/g,"$1\n\n"):e})(w));d(e)}catch(e){console.error("Error processing message content:",e),d(w)}finally{u(!1)}}})()}),[w,h]);const N=cn(r),k=(()=>{switch(r.type){case ge.ANSWER:return"border-l-info bg-info";case ge.COMPLETE:return"border-l-success bg-success";case ge.IDLE:return"border-l-muted bg-muted";case ge.REQUEST_INPUT:return"border-l-attention bg-attention";case ge.QUESTION:return"border-l-muted bg-muted";case ge.THOUGHT:return"border-l-accent dark:border-l-purple-500 bg-purple-50/50 dark:bg-purple-900/10";case ge.ERROR:return"border-l-destructive bg-destructive";case ge.UPDATE:return"border-l-success bg-success";case ge.PLAN:return"border-l-attention bg-attention";default:return"border-l-indigo-500 dark:border-l-indigo-400 bg-indigo-50/50 dark:bg-indigo-900/10"}})();return t("div",{className:`border-l-4 shadow-md overflow-hidden bg-white dark:bg-gray-900 mb-5 ${k}`,"data-workstream-id":N,children:[t("div",{className:"flex items-center justify-between px-4 py-2 border-b border-gray-100/80 dark:border-gray-800/80 bg-white/50 dark:bg-gray-900/50 backdrop-blur-sm",children:[t("div",{className:"flex items-center gap-2",children:[e("div",{className:s?"animate-fadeIn":"",children:(()=>{const t=(()=>{switch(r.type){case ge.ANSWER:return"text-info";case ge.COMPLETE:return"text-success";case ge.IDLE:return"text-muted";case ge.REQUEST_INPUT:return"text-attention";case ge.QUESTION:return"text-muted";case ge.THOUGHT:return"text-purple-600 dark:text-purple-400";case ge.ERROR:return"text-destructive";case ge.UPDATE:return"text-success";case ge.PLAN:return"text-attention";default:return"text-muted"}})(),n=t=>("number"==typeof r.timestamp?r.timestamp:new Date(r.timestamp).getTime())%2==0?e(tn,{size:"sm",color:t}):e(en,{color:t});switch(r.type){case ge.ANSWER:return s?n("blue"):e(Ie,{className:`size-4 ${t}`});case ge.COMPLETE:return e(Pe,{className:`size-4 ${t}`});case ge.IDLE:return e(je,{className:`size-4 ${t}`});case ge.REQUEST_INPUT:case ge.QUESTION:return e(Le,{className:`size-4 ${t}`});case ge.THOUGHT:return s?n("purple"):e(Ie,{className:`size-4 ${t}`});case ge.ERROR:return e(_e,{className:`size-4 ${t}`});case ge.UPDATE:return s?n("green"):e(Ee,{className:`size-4 ${t}`});case ge.PLAN:return s?n("amber"):e($e,{className:`size-4 ${t}`});default:return s?n("blue"):e(Ie,{className:`size-4 ${t}`})}})()}),e("span",{className:"text-xs font-medium text-muted ",children:g.sender}),"main"!==N&&"all"!==N&&e(b,{variant:"default",className:"text-xs text-muted",children:N})]}),t("div",{className:"flex items-center gap-2",children:[e("span",{className:"text-xs text-muted",children:yt(r.timestamp).format("HH:mm:ss")}),e(y,{variant:"ghost",size:"xs",onClick:()=>{const e=x()||"",t="string"==typeof r.details?r.details:r.details?JSON.stringify(r.details,null,2):"",n=[e,t?"\n\nDetails:\n"+t:""].join("").trim();navigator.clipboard.writeText(n).then((()=>{p({status:"success",title:"Copied to clipboard",duration:2e3})}))},className:"text-muted",title:"Copy message",children:e(Te,{className:"size-3"})})]})]}),t("div",{className:"px-4 py-3 bg-white dark:bg-gray-900",children:[w&&e("div",{className:"message-content",children:m?t("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[e(en,{color:"blue"}),e("span",{children:"Loading images..."})]}):v(l||w)}),r.details&&t("div",{className:"mt-2",children:[t("button",{onClick:()=>i(!a),className:"text-xs text-muted flex items-center",children:[a?"Hide":"Show"," details",e("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3 w-3 ml-1 transition-transform "+(a?"rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),a&&e("div",{className:"mt-2 p-2 bg-muted border border-mixer-muted/40 rounded text-sm",children:"string"==typeof r.details?v(r.details):e("pre",{className:"text-xs font-mono whitespace-pre-wrap overflow-x-auto bg-muted p-2 rounded text-muted ",children:JSON.stringify(r.details,null,2)})})]})]})]})}function mn({workstreams:n,activeWorkstream:r,onSelectWorkstream:s,count:a,completionStatus:i}){const l=new Map;l.set("all","All Messages"),l.set("main","Main"),n.forEach(((e,t)=>{"all"!==t&&"main"!==t&&"research_france"!==t&&"statistics"!==t&&l.set(t,e)})),n=l;const o=Array.from(n.entries()).sort((([e],[t])=>"all"===e?-1:"all"===t?1:"main"===e?-1:"main"===t?1:e.localeCompare(t))),c=o.length>2;return e("div",c?{className:"flex overflow-x-auto space-x-1 pb-2 mb-2 border-b-2 border-blue-200 dark:border-blue-900 sticky top-0 bg-white dark:bg-gray-900 z-10 pt-1",children:o.map((([n,l])=>t("button",{className:"px-3 py-1.5 text-xs font-medium whitespace-nowrap transition-colors flex items-center gap-1.5\n "+(r===n?"bg-blue-200 text-blue-800 dark:bg-blue-800 dark:text-blue-200 border-b-2 border-blue-500":"text-gray-600 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-800/30 border-b-2 border-transparent"),onClick:()=>s(n),title:l.length>20?l:void 0,children:[l.length>20?l.substring(0,18)+"...":l,a&&a.has(n)&&a.get(n)>0&&t("div",{className:"flex items-center space-x-1",children:[e("span",{className:"inline-flex items-center justify-center w-4 h-4 text-xs\n "+(r===n?"bg-blue-200 text-blue-800 dark:bg-blue-800 dark:text-blue-200":"bg-gray-200 text-gray-600 dark:bg-gray-700 dark:text-gray-300"),children:a.get(n)}),i&&"all"!==n&&(i.get(n)?e(Pe,{className:"h-3 w-3 text-green-500"}):e(je,{className:"h-3 w-3 text-amber-500"}))]})]},n)))}:{className:"py-1"})}function un(e,t){return"all"===t?[...e]:"main"===t?e.filter((e=>"main"===cn(e))):e.filter((e=>cn(e)===t))}function hn({messages:r,bottomRef:s,viewMode:a="stacked",isCompleted:d=!1,plan:m={plan:[]},workstreamStatus:u=new Map,showPlanPanel:h=!1,onTogglePlanPanel:p=()=>{},plans:g=[],activePlanIndex:f=0,onChangePlan:b=()=>{}}){const y=i.useRef(null),[x,v]=o("all");c((()=>{s.current&&s.current.scrollIntoView({behavior:"smooth"})}),[r,s]);const w=i.useMemo((()=>[...r].sort(((e,t)=>("number"==typeof e.timestamp?e.timestamp:new Date(e.timestamp).getTime())-("number"==typeof t.timestamp?t.timestamp:new Date(t.timestamp).getTime())))),[r]),N=i.useMemo((()=>{const e=function(e){const t=new Map;return t.set("all","All Messages"),t.set("main","Main"),e.forEach((e=>{e.workstream_id&&"main"!==e.workstream_id&&"all"!==e.workstream_id&&!t.has(e.workstream_id)&&(t.set(e.workstream_id,e.workstream_id),console.log(`Found workstream: ${e.workstream_id}`))})),t.size<=2&&!t.has("main")&&t.set("main","Main"),console.log("Final workstreams map:",t),t}(w);return e}),[w]),k=i.useMemo((()=>{const e=new Map;e.set("all",w.length);const t=un(w,"main");return e.set("main",t.length),w.forEach((t=>{const n=cn(t);"main"!==n&&e.set(n,(e.get(n)||0)+1)})),e}),[w]),C=i.useMemo((()=>"all"===x?w:un(w,x)),[w,x]),S=l((()=>{const e=new Map,t=new Map;w.forEach((e=>{const n=cn(e);t.has(n)||t.set(n,[]),t.get(n).push(e)}));for(const[n,r]of t.entries())if(r.length>0){const t=r[r.length-1];e.set(n,[ge.COMPLETE,ge.IDLE,ge.REQUEST_INPUT].includes(t.type))}return e}),[w]);return t("div",{ref:y,className:"flex-1 min-h-0 h-full overflow-y-auto py-2 px-4 sm:px-6 lg:px-8 flex flex-col relative","data-testid":"all-messages-mixed",style:h?{paddingRight:"350px"}:{},children:[e(ln,{plan:m,workstreamStatus:u,isOpen:h,onClose:p,plans:g,activePlanIndex:f,onChangePlan:b}),e("div",{className:"sticky top-0 bg-white dark:bg-gray-900 z-10",children:e(mn,{workstreams:N,activeWorkstream:x,onSelectWorkstream:v,count:k,completionStatus:S})}),0===C.length?e("div",{className:"flex items-center justify-center h-full text-center py-8",children:e("div",{className:"flex items-center px-4 py-3 text-gray-500 dark:text-gray-400",children:"all"===x?"Waiting for agent response...":"No messages in this workstream yet..."})}):t("div",{className:"flex-1 flex flex-col justify-start pb-4 space-y-2",children:["stacked"===a?C.map(((t,n)=>{const r=!d&&n===C.length-1&&![ge.COMPLETE,ge.IDLE,ge.REQUEST_INPUT].includes(t.type);return e(dn,{message:t,showPulsatingCircle:r},`${t.timestamp}-${n}`)})):e(n,{children:(()=>{const t=C.filter((e=>e.type===ge.ANSWER||e.type===ge.QUESTION||e.type===ge.COMPLETE||e.type===ge.REQUEST_INPUT)),n=d?null:C.filter((e=>e.type===ge.THOUGHT||e.type===ge.UPDATE||e.type===ge.PLAN)).sort(((e,t)=>{const n="number"==typeof e.timestamp?e.timestamp:new Date(e.timestamp).getTime();return("number"==typeof t.timestamp?t.timestamp:new Date(t.timestamp).getTime())-n}))[0],r=[...t];return n&&r.push(n),r.sort(((e,t)=>("number"==typeof e.timestamp?e.timestamp:new Date(e.timestamp).getTime())-("number"==typeof t.timestamp?t.timestamp:new Date(t.timestamp).getTime()))),r.map(((t,n)=>{const s=!d&&n===r.length-1&&![ge.COMPLETE,ge.IDLE,ge.REQUEST_INPUT].includes(t.type);return e(dn,{message:t,showPulsatingCircle:s},`${t.timestamp}-${n}`)}))})()}),e("div",{ref:s,className:"h-4"})]})]})}class pn{vertesia;updateState;_interactive=!0;_debug_mode=!1;_collection;_start=!1;payload;_interactionParamsSchema;_inputValidator;constructor(e,t){this.vertesia=e,this.updateState=t,this.payload={model:"",tools:[]}}onStateChanged(){const e=this.clone();this.updateState(e)}clone(){const e=new pn(this.vertesia,this.updateState);return e._interactionParamsSchema=this._interactionParamsSchema,e.payload=this.payload,e._interactive=this._interactive,e._debug_mode=this._debug_mode,e._inputValidator=this._inputValidator,e._start=this._start,e._collection=this._collection,e}get interactive(){return this._interactive}set interactive(e){e!==this._interactive&&(this._interactive=e,this.onStateChanged())}get debug_mode(){return this._debug_mode}set debug_mode(e){e!==this._debug_mode&&(this._debug_mode=e,this.onStateChanged())}get collection(){return this._collection}set collection(e){e!==this._collection&&(this._collection=e,this.onStateChanged())}get search_scope(){return this._collection?"collection":void 0}get interaction(){return this.payload.interaction}set interaction(e){e?.id!==this.payload.interaction?.id&&(this.payload.interaction=e,this._interactionParamsSchema=fe(this.interaction),this._inputValidator=void 0,e&&(e.environment&&("string"==typeof e.environment?this.vertesia.environments.retrieve(e.environment).then((e=>this.environment=e)):this.payload.environment=e.environment),e.model?this.payload.model=e.model:this.payload.model=this.environment?.default_model&&be(this.environment.default_model,this.environment.provider)?this.environment.default_model:void 0),this.onStateChanged())}get environment(){return this.payload.environment}set environment(e){e?.id!==this.payload.environment?.id&&(this.payload.environment=e,this.payload.model=e?.default_model&&be(e.default_model,e.provider)?e.default_model:void 0,this.onStateChanged())}get model(){return this.payload.model}set model(e){e!==this.payload.model&&(this.payload.model=e,this.onStateChanged())}get tools(){return this.payload.tools}set tools(e){this.payload.tools=e,this.onStateChanged()}get prompt_data(){return this.payload.prompt_data}set prompt_data(e){this.payload.prompt_data=e,this.onStateChanged()}set run(e){console.log("run",e),this.onStateChanged()}set start(e){this._start!==e&&(this._start=e,this.onStateChanged())}get start(){return this._start}get interactionParamsSchema(){return this._interactionParamsSchema}set interactionParamsSchema(e){this._interactionParamsSchema!==e&&(this._interactionParamsSchema=e,this.onStateChanged())}reset(){if(this._start=!1,this._interactive=!0,this._debug_mode=!1,this._collection=void 0,this.payload={model:"",tools:[],interaction:void 0,environment:void 0,prompt_data:void 0},this._interactionParamsSchema=null,this._inputValidator=void 0,this.onStateChanged(),location.hash){const e=window.location.origin+window.location.pathname+window.location.search;history.replaceState(null,"",e),location.hash=""}}validateInput(){if(!this._interactionParamsSchema)return{isValid:!0};if(!this._inputValidator||this._inputValidator.schema!==this._interactionParamsSchema){const e=new wt({strict:!1});this._inputValidator={validate:e.compile(this._interactionParamsSchema),schema:this._interactionParamsSchema}}const e=this.payload.prompt_data||{};if(!this._inputValidator.validate(e)){return{isValid:!1,errorMessage:this._inputValidator.validate.errors?this._inputValidator.validate.errors.map((e=>`${e.instancePath}: ${e.message}`)).join(", "):"Invalid payload data"}}return{isValid:!0}}}const gn=d(void 0);function fn({children:t}){const{client:n}=ke(),[r,s]=o();return c((()=>{s(new pn(n,s))}),[]),r&&e(gn.Provider,{value:r,children:t})}function bn(){const e=m(gn);if(!e)throw new Error("usePayloadBuilder must be used within a PayloadProvider");return e}function yn({title:n,onClose:r,isModal:s,run:a,viewMode:i,onViewModeChange:l,showPlanPanel:o,hasPlan:c=!1,onTogglePlanPanel:d,onDownload:m,onCopyRunId:u,resetWorkflow:h}){return e(fn,{children:t("div",{className:"flex items-center justify-between py-1.5 px-2 border-b shadow-sm flex-shrink-0",children:[t("div",{className:"flex flex-wrap items-center space-x-2",children:[t("div",{className:"flex items-center space-x-1",children:[e(Ie,{className:"size-5 text-muted"}),e("span",{className:"font-medium",children:n})]}),t("span",{className:"text-xs text-muted ml-1",children:["(Run ID: ",a.runId.substring(0,8),"...)"]})]}),t("div",{className:"flex items-center space-x-2",children:[t("div",{className:"flex items-center space-x-1 bg-muted rounded p-0.5",children:[e(y,{variant:"stacked"===i?"outline":"ghost",size:"xs",className:"rounded-l-md",onClick:()=>l("stacked"),children:"Details"}),e(y,{variant:"sliding"===i?"outline":"ghost",size:"xs",className:"rounded-l-md",onClick:()=>l("sliding"),children:"Most Important"})]}),t("div",{className:"relative",children:[c&&!o&&e("span",{className:"absolute -top-1 -right-1 w-2.5 h-2.5 bg-primary rounded-full border border-border z-10"}),t(y,{size:"sm",variant:o?"primary":"secondary",onClick:d,className:"transition-all duration-200 rounded-md",title:"Toggle plan panel",children:[e(Ae,{className:"size-4 mr-1.5"}),e("span",{className:"font-medium text-xs",children:o?"Hide Plan":"Show Plan"})]})]}),e(xn,{run:a,isModal:s,onClose:r,onDownload:m,onCopyRunId:u,resetWorkflow:h}),r&&!s&&e(y,{size:"xs",variant:"ghost",onClick:r,children:e(Ue,{className:"size-4"})})]})]})})}function xn({run:n,isModal:r,onClose:s,onDownload:a,onCopyRunId:i,resetWorkflow:l}){const o=f(),{client:c}=ke(),d=bn();return t(x,{hover:!0,children:[e(v,{children:e(y,{size:"xs",variant:"ghost",title:"More actions",children:e(Oe,{className:"size-4"})})}),e(w,{className:"w-48",align:"end",children:e("div",{className:"rounded-md shadow-lg z-50",children:e("div",{className:"py-1 min-w-36",children:e(N,{children:e(k,{children:t(C,{children:[e("div",{className:"flex items-center px-3 py-1.5 text-xs text-gray-700 dark:text-gray-300",children:e("span",{className:"text-muted",children:"Actions"})}),r&&t(S,{className:"text-xs",onSelect:()=>{return e=`/store/agent-runner?agentId=${n.runId}__${n.workflowId}`,window.open(e,"_blank"),e;var e},children:[e(ze,{className:"size-3.5 mr-2 text-muted"})," Open in new tab"]}),t(S,{className:"text-xs",onSelect:()=>{i?i():(navigator.clipboard.writeText(n.runId),o({status:"success",title:"Run ID copied",duration:2e3}))},children:[e(Te,{className:"size-3.5 mr-2 text-muted"})," Copy Run ID"]}),t(S,{className:"text-xs",onSelect:()=>{a?a():async function(e,t){return e.files.getDownloadUrl(`agents/${t}/conversation.json`).then((e=>e.url))}(c,n.runId).then((e=>window.open(e,"_blank")))},children:[e(Fe,{className:"size-3.5 mr-2 text-muted"})," Download Conversation"]}),s&&r&&t(S,{className:"text-xs",onSelect:s,children:[e(Ue,{className:"size-3.5 mr-2 text-muted"})," Close"]}),t(S,{className:"text-xs text-destructive",onSelect:()=>{(async e=>{try{return await c.store.workflows.terminate(e.workflowId,e.runId,"cancel"),o({status:"success",title:"Workflow cancelled",duration:2e3}),d.reset(),l?.(),!0}catch(e){return o({status:"error",title:"Failed to cancel workflow",duration:2e3}),!1}})(n)},children:[e(Ue,{className:"size-3.5 mr-2 text-destructive"})," Cancel Workflow"]})]})})})})})})]})}const vn="vertesia.content_store.lastDisplayedView";function wn({onUpdate:t}){const[n,r]=o("grid"===localStorage.getItem(vn)),s=()=>{localStorage.setItem(vn,"grid"),r(!0),t(!0)},a=()=>{localStorage.setItem(vn,"table"),r(!1),t(!1)};return e(y,{variant:"outline",onClick:()=>{n?a():s()},alt:n?"Table View":"Thumbnail View",children:e(n?De:Re,{})})}wn.LAST_DISPLAYED_VIEW=vn;class Nn extends L{labelOf(e){return e.label}idOf(e){return e.id}renderOption(n){return t("div",{children:[e("div",{className:"font-medium",children:n.label}),e("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:n.description})]})}}function kn({isOpen:n,onClose:r,onConfirm:s,isLoading:a,uploadedFileName:i}){const l=[{id:"update",label:"Update current version",description:i?"Replace the content file and modify properties directly in the current revision.":"Modify the properties directly in the current revision."},{id:"new-version",label:"Create new version",description:i?"Create a new revision with the replacement file while preserving the original.":"Create a new revision with these property changes while preserving the original."}],[c,d]=o(l[0]),[m,u]=o(""),h=new Nn,p="new-version"===c?.id;return t(_,{isOpen:n,onClose:r,className:"sm:max-w-md",children:[e(j,{children:"Save Changes"}),e(P,{children:t("div",{className:"space-y-4",children:[i&&e("div",{className:"mb-4 p-3 bg-blue-50 dark:bg-blue-900/20 rounded-md",children:t("p",{className:"text-sm text-blue-700 dark:text-blue-300 font-medium",children:["You're about to replace the content file with: ",e("span",{className:"font-bold",children:i})]})}),e("p",{className:"text-sm text-mixer-muted/5",children:"How would you like to save these changes?"}),e(T,{adapter:h,options:l,value:c,onChange:e=>{d(e)},gap:"gap-4"}),p&&e(I,{label:"Version Label (Optional)",description:"Optional label for the new version.",className:"mt-3 pl-8",children:e($,{value:m,onChange:u,placeholder:"e.g., v1.2, approved, post-review",className:"w-full"})})]})}),t(E,{children:[e(y,{variant:"secondary",onClick:r,disabled:a,children:"Cancel"}),e(y,{variant:"primary",onClick:async()=>{await s(p,p?m:void 0)},isLoading:a,children:"Save"})]})]})}function Cn({isOpen:r,onClose:s,object:a,refetch:i}){const{client:l,store:d}=ke(),m=f(),h=bt(),[p,g]=o(!1),[b,x]=o(""),[v,w]=o(!1),[N,k]=o(null),C=u(null),S=u(null),[T,I]=o(null),[$,L]=o(null);function A(e,t){e.languages.json.jsonDefaults.setDiagnosticsOptions({validate:!0,schemas:[{uri:"http://myserver/object-schema.json",fileMatch:["*"],schema:t}]})}return c((()=>{r&&(x(JSON.stringify(a.properties||{},null,2)),a.type?.id&&async function(e){try{const t=await d.types.retrieve(e);t.object_schema&&(I(t.object_schema),S.current&&A(S.current,t.object_schema))}catch(e){console.error("Failed to fetch JSON schema:",e)}}(a.type.id))}),[r,a]),t(n,{children:[t(_,{isOpen:r,onClose:s,className:"sm:max-w-[90%] md:max-w-[80%] lg:max-w-[75%] xl:max-w-[70%]",children:[e(j,{children:"Edit Properties"}),t(P,{children:[t("div",{className:"mb-2 text-sm text-gray-500",children:[a.type?.name?t("span",{children:["Editing properties for object type: ",e("strong",{children:a.type.name})]}):e("span",{children:"Editing properties for generic document"}),T&&e("span",{className:"ml-2 text-green-600",children:"(JSON schema validation enabled)"})]}),e("div",{className:"h-[75vh] border border-gray-300 dark:border-gray-700 rounded-md",children:e(Lt,{height:"100%",language:"json",value:b,onChange:e=>x(e||""),onMount:function(e,t){C.current=e,S.current=t,T&&A(t,T)},options:{minimap:{enabled:!1},scrollBeyondLastLine:!1,formatOnPaste:!0,formatOnType:!0,automaticLayout:!0,wordWrap:"on"}})})]}),t(E,{children:[e(y,{variant:"secondary",onClick:s,children:"Cancel"}),e(y,{variant:"primary",onClick:function(){if(!C.current)return;const e=C.current.getValue();try{const t=JSON.parse(e);k(t),w(!0)}catch(e){m({status:"error",title:"Invalid JSON",description:"Please fix the JSON syntax errors before saving.",duration:5e3})}},children:"Save Changes"})]})]}),e(kn,{isOpen:v,onClose:function(){w(!1)},onConfirm:async function(e,t){try{g(!0);const n=N||JSON.parse(b);if(e){const e=await l.objects.update(a.id,{properties:n},{createRevision:!0,revisionLabel:t});e.id!==a.id&&L(e.id),m({status:"success",title:"New version created",description:"A new version with updated properties has been created.",duration:2e3}),w(!1),s(),e.id!==a.id&&setTimeout((()=>{h(`/objects/${e.id}`),m({status:"info",title:"Viewing New Version",description:t?`Now viewing version '${t}'`:"Now viewing the new version",duration:3e3})}),100)}else await d.objects.update(a.id,{properties:n}),m({status:"success",title:"Properties updated",description:"The object properties have been updated successfully.",duration:2e3}),i&&await i(),w(!1),s()}catch(e){m({status:"error",title:"Error updating properties",description:e.message||"An error occurred while updating the properties.",duration:5e3}),g(!1)}},isLoading:p})]})}function Sn({object:r,loadText:s,refetch:a}){const{client:i,store:l}=ke(),[d,m]=o(!1),[u,h]=o(r.text),[p,g]=o(),[b,x]=o(!1),v=f(),[w,N]=o(!1);c((()=>{s&&!u&&(m(!0),l.objects.getObjectText(r.id).then((e=>{h(e.text)})).catch((e=>{console.error("Failed to load text",e)})).finally((()=>{m(!1)})))}),[s]);const k=async(e,t)=>{try{await navigator.clipboard.writeText(e),v({status:"success",title:("text"===t?"Content":"Properties")+" copied",description:`Successfully copied ${t} to clipboard`,duration:2e3})}catch(e){console.error(`Failed to copy ${t}:`,e),v({status:"error",title:"Copy failed",description:`Failed to copy ${t} to clipboard`,duration:5e3})}},C=async e=>{try{const t=await i.objects.getRendition(r.id,{format:e,max_hw:1024,generate_if_missing:!0,sign_url:!0});if("generating"===t.status)return v({status:"info",title:"Generating document",description:`Please wait while we prepare your ${e.toUpperCase()} file...`,duration:5e3}),void setTimeout((()=>C(e)),3e3);if("failed"===t.status)throw new Error("Document generation failed");if(t.renditions&&t.renditions.length>0){const n=t.renditions[0];if("pdf"===e)window.open(n,"_blank"),v({status:"success",title:"PDF opened",description:"PDF document opened in a new window",duration:2e3});else{const t=document.createElement("a");t.href=n,t.download=`${r.name||"document"}.${e}`,document.body.appendChild(t),t.click(),document.body.removeChild(t),v({status:"success",title:"Document exported",description:`Successfully exported to ${e.toUpperCase()} format`,duration:2e3})}}}catch(t){console.error(`Failed to export document as ${e}:`,t),v({status:"error",title:"Export failed",description:`Failed to export document to ${e.toUpperCase()} format`,duration:5e3})}},S=r.content,_=S&&S.source&&S.type&&S.type.startsWith("image/"),j=S&&S.type&&("text/markdown"===S.type||"text/plain"===S.type),P=u&&(u.includes("\n#")||u.includes("\n*")||u.includes("\n+")||u.includes("!["));return c((()=>{_&&i.objects.getRendition(r.id,{max_hw:1024,format:ye.jpeg,generate_if_missing:!1,sign_url:!0}).then((e=>"found"===e.status?e.renditions?.length?e.renditions[0]:null:r)).catch((()=>r)).then((()=>{i.files.getDownloadUrl(r.content.source).then((e=>{g(e.url)}))}))}),[]),t("div",{className:"w-full",children:[t("div",{className:"flex flex-col lg:flex-row lg:gap-8",children:[t("div",{className:"w-full lg:w-1/2",children:[t("div",{className:"h-[41px] text-lg font-semibold mb-4 border-b flex justify-between items-center",children:[t("div",{className:"flex items-center gap-1",children:["Properties",e(y,{variant:"outline",size:"sm",alt:""+(w?"Preview":"View in JSON format"),onClick:()=>N(!w),children:w?"Preview":"JSON"})]}),t("div",{className:"flex items-center gap-2",children:[r.properties&&e(y,{variant:"ghost",size:"sm",title:"Copy properties",onClick:()=>k(JSON.stringify(r.properties,null,2),"properties"),children:e(Me,{className:"size-4"})}),e(y,{variant:"ghost",size:"sm",onClick:()=>{x(!0)},title:"Edit properties",className:"flex items-center gap-2",children:e(Ve,{className:"size-4"})})]})]}),r.properties?e(Nt,{value:r.properties,viewCode:w}):e("div",{children:"No properties defined"}),_&&t("div",{className:"my-4",children:[e("div",{className:"h-[41px] text-lg font-semibold mb-4 border-b flex justify-between items-center",children:e("span",{className:"py-1",children:"Image"})}),p?e("img",{src:p,alt:r.name,className:"w-full object-contain"}):e(A,{size:"md"})]})]}),t("div",{className:"w-full lg:w-1/2 mt-4 lg:mt-0",children:[t("div",{className:"h-[41px] text-lg font-semibold mb-4 border-b flex justify-between items-center",children:[e("span",{className:"py-1",children:"Text"}),t("div",{className:"flex items-center gap-2",children:[u&&e(y,{variant:"ghost",size:"sm",title:"Copy text",onClick:()=>k(u,"text"),className:"flex items-center gap-2",children:e(Me,{className:"h-4 w-4"})}),(j||P)&&u&&t(n,{children:[t(y,{variant:"ghost",size:"sm",onClick:()=>C("docx"),className:"flex items-center gap-2",children:[e(qe,{className:"h-4 w-4"}),"DOCX"]}),t(y,{variant:"ghost",size:"sm",onClick:()=>C("pdf"),className:"flex items-center gap-2",children:[e(qe,{className:"h-4 w-4"}),"PDF"]})]})]})]}),d&&e(A,{size:"md"}),e("div",u?{className:"border shadow-xs rounded-xs max-w-7xl",children:P?e("div",{className:"vprose prose-sm p-1",children:e(xt,{remarkPlugins:[vt],components:{a:({node:t,...n})=>{const r=n.href||"";return r.includes("/store/objects/")?e(ft,{topLevelNav:!0,href:r,className:"text-info",children:n.children}):e("a",{...n,"data-debug":"test",target:"_blank",rel:"noopener noreferrer"})},p:({node:t,...n})=>e("p",{...n,className:"my-0"}),pre:({node:t,...n})=>e("pre",{...n,className:"my-2 p-2 rounded"}),code:({node:t,className:n,children:r,...s})=>{const a=/language-(\w+)/.exec(n||"");return e("code",{...s,className:!a?"px-1.5 py-0.5 rounded":"text-muted",children:r})},h1:({node:t,...n})=>e("h1",{...n,className:"font-bold text-2xl my-2"}),h2:({node:t,...n})=>e("h2",{...n,className:"font-bold text-xl my-2"}),h3:({node:t,...n})=>e("h3",{...n,className:"font-bold text-lg my-2"}),li:({node:t,...n})=>e("li",{...n})},children:u})}):e("pre",{className:"text-wrap bg-muted text-muted p-2",children:u})}:{children:"No content"})]})]}),e(Cn,{isOpen:b,onClose:()=>{x(!1)},object:r,refetch:a})]})}function _n(e,t=7){return e?"~"+e.slice(-t):""}function jn(e,t){return e.length>t?e.substring(0,t)+"...":e}const Pn="text/csv",Tn="image/",In="application/pdf",$n="video/",En=e=>e===Pn||Pn.includes(e),Ln=e=>e.startsWith(Tn)||Tn.includes(e),An=e=>e===In||In.includes(e),Un=e=>e.startsWith($n)||$n.includes(e),On=import.meta.env,zn={max_hw:On?.VITE_RENDITION_HW||256,format:ye.jpeg,generate_if_missing:!0},Fn="vertesia.content_store.renditionId";async function Dn(e,t,n,r,s){if(!t?.content?.type||!(Ln(t.content.type)||Un(t.content.type)||An(t.content.type)))return void s("No preview available");s("Preparing preview...");const a=(new Date).getTime()/1e3,i=localStorage.getItem(`${Fn}_${t.id}_${zn.max_hw}`),l=localStorage.getItem(`${Fn}_${t.id}_${zn.max_hw}_time`);if(i?.length&&l&&Math.abs(a-parseInt(l))<=900)return n(i),r(`${t.name} Rendition`),s("ready"),i;s("Preparing preview..."),e.objects.getRendition(t.id,zn).then((a=>{if("generating"===a.status)s("Preparing preview..."),n(""),r(""),setTimeout((()=>Dn(e,t,n,r,s)),6e4);else{if("failed"===a.status)return s("No preview available"),n(""),void r("");{if(!a?.renditions?.length)return s("No preview available"),n(""),void r("");const e=a.renditions[0];localStorage.setItem(`${Fn}_${t.id}_${zn.max_hw}`,e),localStorage.setItem(`${Fn}_${t.id}_${zn.max_hw}_time`,((new Date).getTime()/1e3).toString()),n(e),r(`${t.name} Rendition`),s("ready"),console.log(`Rendition for document ${t.id} retrieved successfully: ${e}`)}}})).catch((e=>{s("No preview available"),console.warn("Failed to retrieve rendition:",e),n(""),r("")}))}function Rn({selection:n,document:r,onSelectionChange:s,onRowClick:a}){const{client:i}=ke(),[l,d]=o(void 0),[m,u]=o(void 0),[h,p]=o(void 0);return c((()=>{r?.content&&Dn(i,r,d,u,p)}),[r]),t(U,{className:"relative flex flex-col border h-fit",onClick:()=>a&&a(r),children:[n&&e("div",{className:"absolute top-2 left-2 z-10 flex flex-col items-center gap-1",children:e("input",{checked:n.isSelected(r.id),type:"checkbox",onChange:e=>{e.stopPropagation(),s(r,e)},onClick:e=>e.stopPropagation()})}),e("div",{className:"absolute top-1 right-1 z-10 flex flex-col items-center",children:e(ft,{topLevelNav:!0,href:`/store/objects/${r.id}`,children:e(y,{variant:"ghost",size:"sm",title:"Open Object",children:e(We,{className:"size-4 "+("ready"===h?"text-muted":"text-white")})})})}),l&&"ready"==h?e("img",{src:l,alt:m,className:"w-auto h-48 object-cover rounded-t-xl"}):e("div",{className:"h-48 bg-gray-700 rounded-t-xl flex items-center justify-center text-muted",children:h}),e(O,{className:"bg-gray-200 h-[2px]"}),e(z,{className:"p-2 flex flex-col gap-1",children:t("div",{className:"flex flex-col",children:[e(F,{placement:"top",description:r.properties?.title??r.name,children:e("h3",{className:"text-start font-medium leading-none truncate",children:r.properties?.title??r.name})}),r?.type?.name?e(F,{placement:"bottom",size:"xs",description:r?.type?.name,children:e("p",{className:"text-start text-xs text-muted truncate",children:r?.type?.name})}):e("p",{className:"text-xs text-muted",children:" "})]})})]})}function Mn(e){return`${e._id} (${e.count})`}function Vn(e){return`${e.name} (${e.count})`}function qn({search:t,buckets:n,placeholder:r="All Environments",className:s}){const{client:a}=ke(),[i,l]=o([]),d=t.getFilterValue("environment");c((()=>{if(a){const e=n.map((async e=>{let t;return await a.environments.retrieve(e._id).then((e=>{t=e.name})).catch((()=>{t=`${e._id} (deleted)`})),t||(t=e._id),{...e,name:t}}));Promise.all(e).then((e=>{e.sort(((e,t)=>e.name.localeCompare(t.name))),l(e)}))}}),[n,a]);const m=i?.find((e=>e._id===d));return e(D,{filterBy:"name",className:s,isClearable:!0,optionLabel:Vn,options:i,value:m,onChange:e=>{t.setFilterValue("environment",e?._id)},by:"_id",placeholder:r})}function Wn({search:t,buckets:n,name:r,placeholder:s,className:a}){const i=t.getFilterValue(r),l=n?.find((e=>JSON.stringify(e._id)===JSON.stringify(i)));return e(D,{filterBy:"_id",className:a,isClearable:!0,optionLabel:Mn,options:n,value:l,onChange:e=>{t.setFilterValue(r,e?._id)},by:"_id",placeholder:s})}function Bn({search:t,name:n,placeholder:r,className:s}){const[a,i]=o([]);return c((()=>{t.setFilterValue(n,a)}),[a]),e(R,{className:s,value:a,onChange:i,placeholder:r})}function Jn(e){return`${e.name} (${e.count})`}function Hn({search:t,buckets:n,placeholder:r="Filter by Type",className:s}){const[a,i]=o([]),{typeRegistry:l}=ke(),d=t.getFilterValue("type");c((()=>{if(l){const e=n.map((e=>{let t;return null==e._id?(e._id="Document",t="Document"):(t=l.getTypeName(e._id),t||(console.warn("Content Object Type not found",e._id),t=e._id)),{...e,name:t}}));e.sort(((e,t)=>e.name.localeCompare(t.name))),i(e)}}),[n,l]);const m=a?.find((e=>e._id===d));return e(D,{filterBy:"name",className:s,isClearable:!0,optionLabel:Jn,options:a,value:m,onChange:e=>{t.setFilterValue("type",e?._id)},by:"_id",placeholder:r})}function Gn({facets:n,search:r}){return t("div",{className:"flex items-center gap-x-4 w-full",children:[n.role&&e(Wn,{search:r,className:"flex-1",name:"role",buckets:n.role||[],placeholder:"Filter by Role"}),n.type&&e(Hn,{search:r,className:"flex-1",buckets:n.type||[]}),n.status&&e(Wn,{search:r,className:"flex-1",name:"status",buckets:n.status||[],placeholder:"Filter by Status"}),n.location&&e(Wn,{search:r,className:"flex-1",name:"location",buckets:n.location||[],placeholder:"Filter by Location"}),n.tags&&e(Bn,{search:r,className:"flex-1",name:"tags",buckets:n.tags||[],placeholder:"Filter by Tags"})]})}function Kn({search:t,buckets:n,placeholder:r="All Interactions",className:s}){const{client:a}=ke(),[i,l]=o([]),d=t.getFilterValue("interaction");c((()=>{if(a){const e=n.map((async e=>{let t;return await a.interactions.retrieve(e._id).then((e=>{t=e.name})).catch((()=>{t=`${e._id} (deleted)`})),t||(t=e._id),{...e,name:t}}));Promise.all(e).then((e=>{e.sort(((e,t)=>e.name.localeCompare(t.name))),l(e)}))}}),[n,a]);const m=i?.find((e=>e._id===d));return e(D,{filterBy:"name",className:s,isClearable:!0,optionLabel:Vn,options:i,value:m,onChange:e=>{t.setFilterValue("interaction",e?._id)},by:"_id",placeholder:r})}const Qn={};function Yn(e){const{client:t}=ke();return M((()=>{let n=Qn[e];return n||(n=t.users.retrieve(e).then((e=>e)),Qn[e]=n),n}),[e])}function Xn(){return e("div",{className:"size-8"})}function Zn({showTitle:n=!1,size:r="md"}){return t(ir,{title:"System User",description:"The system user is used to initialize built-in objects.",children:[e(V,{src:"/icon.svg",size:r}),n&&e("div",{className:"text-sm font-semibold pl-2",children:"System User"})]})}function er({accountId:r,showTitle:s=!1,size:a="md"}){const i=t(n,{children:[e("div",{children:"This user is used by robots like workflow workers."}),t("div",{className:"text-gray-800 dark:text-gray-500 text-sm",children:[e("span",{className:"font-semibold",children:"ID:"})," ",r]})]});return e(ir,{title:"Service Account",description:i,children:t("div",{className:"flex flex-row items-center gap-2",children:[e(V,{src:"/cloud.svg",name:"SA",color:"bg-amber-500",className:"px-[5px] text-white",size:a}),s&&t("div",{className:"text-sm font-semibold pl-2 truncate",children:["Service Account : ",r]})]})})}function tr({title:t="Error",error:n,showTitle:r=!1,size:s="md"}){return e(rr,{title:t,message:"string"==typeof n?n:n.message,color:"bg-red-500",showTitle:r,size:s})}function nr({userRef:t,showTitle:n=!1,size:r="md"}){if(!t)return e(rr,{title:"Unknown User",message:"User information is not available.",showTitle:n,size:r});const[s,a]=t?t.split(":"):["unknown"];switch(s){case xe.User:return e(sr,{userId:a,showTitle:n,size:r});case"system":return e(Zn,{showTitle:n,size:r});case xe.ServiceAccount:return e(er,{accountId:a,showTitle:n,size:r});case xe.ApiKey:return e(ar,{keyId:a,size:r,showTitle:n});default:return e(tr,{title:"Unknown User",error:`Invalid user ref type: ${s}`,showTitle:n,size:r})}}function rr({title:n,message:r,color:s,size:a="md",showTitle:i=!1}){return e(ir,{title:n,description:r,children:t("div",{className:"flex flex-row items-center gap-2",children:[e(V,{color:s,size:a}),i&&e("div",{className:"text-sm font-semibold pl-1",children:n})]})})}function sr({userId:n,showTitle:r=!1,size:s="md"}){const{data:a,error:i}=Yn(n);return i?e(tr,{title:"Failed to fetch user",error:i,showTitle:r,size:s}):a?e(ir,{title:a.name||a.email||a.username||"unknown",description:a.email,children:t("div",{className:"flex flex-row items-center gap-2",children:[e(V,{src:a.picture,name:a.name,color:"bg-indigo-500",size:s}),r&&e("div",{className:"text-sm font-semibold pl-2",children:a.name||a.email||a.username||"unknown"})]})}):e(Xn,{})}function ar({keyId:n,showTitle:r=!1,size:s="md"}){const{client:a}=ke(),{data:i,error:l}=M((()=>a.apikeys.retrieve(n)),[]);if(l)return e(tr,{title:"Failed to fetch the apikey",error:l,showTitle:r,size:s});if(!i)return e(Xn,{});const o=i.type===ve.public,c=o?"Public Key":"Private Key",d=e(V,{name:o?"PK":"SK",color:"bg-pink-500",size:s}),m=t(q,{className:"dark:bg-gray-800 dark:text-gray-200",children:[t("tr",{children:[e("td",{className:"font-semibold",children:"Key:"}),e("td",{children:i?.name})]}),t("tr",{children:[e("td",{className:"font-semibold",children:"Account:"}),e("td",{children:i?.account})]}),t("tr",{children:[e("td",{className:"font-semibold",children:"Project:"}),e("td",{children:i?.project})]})]});return e(ir,{title:c,description:m,children:t("div",{className:"flex flex-row items-center gap-2",children:[d,r&&e("div",{className:"text-sm font-semibold pl-2",children:i?.name||i?.account||i?.project||"unknown"})]})})}function ir({title:n,description:r,children:s}){return t(x,{hover:!0,children:[e(v,{className:"cursor-pointer flex items-center inline-block",children:e("div",{children:s})}),e(w,{align:"center",sideOffset:8,side:"right",children:t("div",{className:"flex flex-col gap-1 rounded-md shadow-md p-2",children:[e("div",{className:"text-md font-semibold",children:n}),e("div",{children:r})]})})]})}function lr(t){return null==t._id?`UnKnown User (${t.count})`:e(nr,{userRef:t._id,showTitle:!0,size:"sm"})}function or({search:t,buckets:n,placeholder:r="Filter by User",className:s}){const[a,i]=o([]),l=t.getFilterValue("created_by");c((()=>{(async()=>{const e=await Promise.all(n.map((async e=>({...e}))));i(e)})()}),[n]);const d=a?.find((e=>e._id===l));return e(D,{filterBy:"name",className:s,isClearable:!0,optionLabel:lr,options:a,value:d,onChange:e=>{t.setFilterValue("created_by",e?._id)},by:"_id",placeholder:r})}function cr({buckets:e,name:t,placeholder:n}){return function({buckets:e,name:t,placeholder:n}){return{name:t,options:e.map((e=>({label:Mn(e),value:e._id}))),type:"select",placeholder:`${n??`${t.charAt(0).toUpperCase()+t.slice(1)}`}`}}({buckets:e,name:t,placeholder:n})}function dr({buckets:n,typeRegistry:r}){const s=new Map;n.forEach((e=>{let t,n=e._id;null==e._id?(n="Document",t="Document"):(t=r.getTypeName(e._id),t||(console.warn("Content Object Type not found",e._id),t=e._id)),s.set(n,{name:t,count:e.count})}));return{name:"Type",type:"select",options:n.map((e=>({value:e._id||"Document",label:`(${e.count})`}))),labelRenderer:n=>{const r=s.get(n);return r?t("div",{className:"w-full flex items-center",children:[e("span",{className:"text-sm truncate",children:r.name}),t("span",{className:"ml-2 text-xs",children:["(",r.count,")"]})]}):(console.warn(`Type data not found for ${n}`),n)},filterBy:(e,t)=>{const n=s.get(e);return n?n.name.toLowerCase().includes(t.toLowerCase()):(console.warn(`Type name not found for ${e}`),!1)}}}function mr({buckets:n,name:r,placeholder:s}){return function({buckets:n,name:r,placeholder:s}){const a=n.map((e=>({value:e._id,label:`(${e.count})`})));return{name:r,placeholder:s||`${r.charAt(0).toUpperCase()+r.slice(1)}`,options:a,labelRenderer:r=>{if("Unknown User"===r||!r){const e=n.find((e=>e._id===r));return`Unknown User (${e?.count||0})`}const s=n.find((e=>e._id===r));return t("div",{className:"flex items-center justify-between w-full",children:[e(nr,{userRef:r,showTitle:!0,size:"sm"}),t("span",{className:"text-muted-foreground ml-2",children:["(",s?.count||0,")"]})]})}}}({buckets:n,name:r,placeholder:s})}function ur({facets:n,search:r,textSearch:s=""}){const[a,i]=o([]),l=[],{typeRegistry:c}=ke();if(s&&l.push({placeholder:s,name:"name",type:"text",options:[]}),n.type){const e=dr({buckets:n.type||[],typeRegistry:c});l.push(e)}if(n.status){const e=cr({buckets:n.status||[],name:"Status"});l.push(e)}if(n.role){const e=cr({buckets:n.role||[],name:"Role"});l.push(e)}if(n.location){const e=cr({buckets:n.location||[],name:"Location"});l.push(e)}if(n.initiated_by){const e=mr({buckets:n.initiated_by||[],name:"User"});l.push(e)}if(n.interactions){const r=function({buckets:n,name:r,placeholder:s}){return{name:r,placeholder:s,options:n.map((e=>({label:`(${e.count})`,value:e._id}))),type:"select",labelRenderer:r=>{const s=n.find((e=>e._id===r)),a=s?.name||r;let i="success";if(s?.status)switch(s.status){case we.published:i="success";break;case we.archived:i="destructive";break;default:i="attention"}const l=s?.version&&s?.status?`v${s.version} ${s.status}`:s?.status||(s?.version?`v${s.version}`:"");return t("div",{className:"w-full flex items-center justify-between",children:[t("div",{className:"flex flex-row flex-wrap items-center gap-2 min-w-0 flex-1",children:[e("span",{className:"text-sm truncate",children:a}),l&&e(b,{variant:i,className:"text-xs w-fit",children:l})]}),t("span",{className:"ml-2 text-xs shrink-0",children:["(",s?.count||0,")"]})]})},filterBy:(e,t)=>{const r=n.find((t=>t._id===e));return(r?.name||e).toLowerCase().includes(t.toLowerCase())}}}({buckets:n.interactions||[],name:"interaction",placeholder:"Interactions"});l.push(r)}if(n.environments){const r=function({buckets:n,name:r}){const s=n.map((e=>({label:`(${e.count})`,value:e._id})));return{name:r.charAt(0).toUpperCase()+r.slice(1),options:s,type:"select",labelRenderer:r=>{const s=n.find((e=>e._id===r));return t("div",{className:"w-full flex items-center",children:[e("span",{className:"text-sm truncate",children:s?.name||r}),t("span",{className:"ml-2 text-xs",children:["(",s?.count||0,")"]})]})},filterBy:(e,t)=>{const r=n.find((t=>t._id===e));return(r?.name||e).toLowerCase().includes(t.toLowerCase())}}}({buckets:n.environments||[],name:"Environments"});l.push(r)}if(n.models){const e=cr({buckets:n.models||[],name:"Model"});l.push(e)}if(n.statuses){const e=cr({buckets:n.statuses||[],name:"Status"});l.push(e)}if(n.finish_reason){const e=cr({buckets:n.finish_reason.map((e=>({...e,_id:null===e._id?"none":e._id}))),name:"finish_reason",placeholder:"Finish Reason"});l.push(e)}if(n.created_by){const e=mr({buckets:n.created_by||[],name:"created_by",placeholder:"Created By"});l.push(e)}n.tags&&l.push({name:"Tags",type:"stringList",options:n.tags.map((e=>({label:e,value:e})))});return e(W,{filterGroups:l,filters:a,setFilters:e=>{const t="function"==typeof e?e(a):e;if(0===t.length)return r.clearFilters(),void i([]);i(t),r.clearFilters(!1),t.forEach((e=>{if(e.value&&e.value.length>0){const t=e.name.toLowerCase(),n="stringList"===e.type?e.value.map((e=>"string"==typeof e?e:e.value)):Array.isArray(e.value)&&e.value[0]&&"object"==typeof e.value[0]?e.value[0].value:e.value;if("name"===t)r.query.search_term=n,r.query.name=n;else r.query[t]=n}})),r.search()}})}class hr{object;objects;setState;collectionId;singleSelection=!1;constructor(e,t,n,r){this.object=e,this.objects=n,this.setState=r,this.singleSelection=0===Object.keys(this.objects).length,this.collectionId=t}isSingleSelection(){return this.singleSelection}hasSelection(){return void 0!==this.object||0!==this.size()}size(){return Object.keys(this.objects).length}getObjectIds(){return Object.keys(this.objects)}getObjectId(){return this.object?.id}clone(){return new hr(this.object,this.collectionId,this.objects,this.setState)}add(e){this.objects[e.id]=e,this.singleSelection=0===Object.keys(this.objects).length,this.setState(this.clone())}remove(e){delete this.objects[e],this.singleSelection=0===Object.keys(this.objects).length,this.setState(this.clone())}addAll(e){for(const t of e)this.objects[t.id]=t;this.setState(this.clone())}isSelected(e){return void 0!==this.objects[e]}removeAll(){this.objects={},this.singleSelection=!0,this.setState(this.clone())}}const pr=d(void 0);function gr(){const e=m(pr);if(!e)throw new Error("useObjectSelection must be used within a ObjectSelectionProvider");return e}function fr(){return m(pr)}function br({value:t,collectionId:n,children:r}){const[s,a]=o();return c((()=>{const e=new hr(t,n,{},a);a(e)}),[t]),s&&e(pr.Provider,{value:s,children:r})}yt.extend(Ut),yt.extend(At);const yr={string(t){let n=[];if(t){const e=t.get("slice");e&&n.push((t=>t.slice(parseInt(e))));const r=t.get("max_length");r&&n.push((e=>e.slice(0,parseInt(r)))),t.has("upper")&&n.push((e=>e.toUpperCase())),t.has("lower")&&n.push((e=>e.toLowerCase())),t.has("capitalize")&&n.push((e=>e[0].toUpperCase()+e.substring(1))),t.has("ellipsis")&&n.push((e=>e+"..."))}return(t,r)=>{let s;if(t){if(s=String(t),n.length>0)for(const e of n)s=e(s)}else s="";return e("td",{children:s},r)}},fileSize:t=>(t,n)=>{let r="";if(t){const e=Number(t);if(isNaN(e))r=String(t);else{const t=["Bytes","KB","MB","GB","TB"];if(0===e)r="0 Bytes";else{const n=Math.floor(Math.log(e)/Math.log(1024));r=`${(e/Math.pow(1024,n)).toFixed(2)} ${t[n]}`}}}return e("td",{children:r},n)},number(t){let n,r;t&&(n=t.get("currency")||void 0,r=t.get("decimals")||void 0);const s=r?parseInt(r):2;return(t,r)=>{let a=new Intl.NumberFormat("en-US",{style:n?"currency":"decimal",currency:n,maximumFractionDigits:s}).format(t);return e("td",{children:a},r)}},objectLink(t){let n="title";return t&&(n=t.get("title")||"title"),(t,r)=>e("td",{children:e(ft,{topLevelNav:!0,className:"underline text-indigo-800 dark:text-indigo-300",href:`/store/objects/${t.id}`,children:t.properties?.[n]||t.name||_n(t.id)})},r)},typeLink:t=>(t,n)=>e("td",{children:t?.name||"n/a"},n),date(t){let n="format",r="LLL";if(t){const e=t.get("localized");if(e)r=e;else{const e=t.get("relative");e&&(n=e,r=void 0)}}return(t,s)=>e("td",{children:yt(t)[n](r)},s)}},xr=yr.string();function vr(e,t){let n=e;if(!n)return;if(!t.length)return n;const r=t.length-1;for(let e=0;e<r;e++)if(n=n[t[e]],!n)return;return n[t[r]]}function wr(e){return e&&"."!==e?e.split("."):[]}class Nr{layout;renderer=xr;path;fallbackPath;constructor(e){if(this.layout=e,this.path=wr(e.field||""),this.fallbackPath=e.fallback?wr(e.fallback):void 0,e.render)this.renderer=(e,t)=>null;else{const t=e.type||"string",n=t.indexOf("?");if(n>0){const e=t.substring(0,n),r=new URLSearchParams(t.substring(n+1));this.renderer=yr[e](r)}else this.renderer=yr[t]()}}get name(){return this.layout.name}resolveValue(e){let t=vr(e,this.path);return void 0===t&&this.fallbackPath&&(t=vr(e,this.fallbackPath)),void 0===t&&(t=this.layout.default),t}render(t,n){return this.layout.render?e("td",{className:"whitespace-nowrap px-3 py-4 text-sm",children:this.layout.render(t)},n):this.renderer(this.resolveValue(t),n)}}function kr({objects:n,selection:r,isLoading:s,onRowClick:a,columns:i,toggleAll:l,onSelectionChange:o}){return t(q,{className:"w-full border-t",children:[e("thead",{children:t("tr",{children:[r&&e("th",{children:e("input",{type:"checkbox",onChange:l})}),i.map((t=>e("th",{children:t.name},t.name)))]})}),t(B,{isLoading:s,columns:i.length,children:[n?.map((n=>t("tr",{className:"cursor-pointer hover:bg-muted",onClick:()=>{a&&a(n)},children:[r&&e("td",{onClick:e=>e.stopPropagation(),children:e("input",{checked:r.isSelected(n.id),type:"checkbox",onChange:e=>o(n,e)})}),i.map(((e,t)=>e.render(n,t)))]},n.id))),0===n.length&&e("tr",{children:e("td",{colSpan:i.length+(r?1:0),className:"text-center",children:"No objects. Just drag and drop documents or images here to create content objects."})})]})]})}function Cr({objects:s,selection:a,isLoading:i,onSelectionChange:l,onRowClick:o}){return t(n,{children:[e("div",{className:r("bg-white opacity-40 absolute inset-0 z-50 flex justify-center items-center",i?"block":"hidden"),children:e(A,{size:"xl"})}),e("div",{className:"w-full gap-2 grid lg:grid-cols-6",children:s.map((t=>e(Rn,{document:t,selection:a,onSelectionChange:l,onRowClick:o},t.id)))})]})}class Sr{client;limit;collectionId;facets=new J({});result=new J({objects:[],isLoading:!1});facetSpecs=[];query={};constructor(e,t=100){this.client=e,this.limit=t}withFacets(e){return this.facetSpecs=e,this}get objects(){return this.result.value.objects}get error(){return this.result.value.error}get isRunning(){return this.result.value.isLoading}getFilterValue(e){return this.query[e]}setFilterValue(e,t){this.query[e]=t,this.search()}clearFilters(e=!0){const t=this.query.parent;this.query={parent:t},e&&this.search()}getFacetBuckets(e){return this.facets.value[e]?.buckets||[]}resetFacets(){this.query={}}reset(e=!1){this.result.value={objects:[],isLoading:e}}_updateRunningState(e){const t=this.result.value;this.result.value={objects:t.objects,isLoading:e,error:t.error}}_searchRequest(e,t,n){return this.collectionId?this.client.collections.searchMembers(this.collectionId,{limit:t,offset:n,query:e}):this.client.objects.search({limit:t,offset:n,query:e})}_facetsRequest(){return this.collectionId?this.client.collections.computeFacets(this.collectionId,{facets:this.facetSpecs,query:this.query}):this.client.objects.computeFacets({facets:this.facetSpecs,query:this.query})}computeFacets(e){this._facetsRequest().then((e=>{this.facets.value=e}))}_search(e=!1){if(this.isRunning)return Promise.resolve(!1);this.result.value={isLoading:!0,objects:e?this.objects:[]};const t=this.limit,n=this.objects.length;return this._searchRequest(this.query,t,n).then((async e=>(this.result.value={isLoading:!1,objects:this.objects.concat(e)},!0))).catch((e=>{throw this.result.value={error:e,isLoading:!1,objects:this.objects},e}))}search(e=!1){return this.isRunning?Promise.resolve(!1):(!e&&this.computeFacets(this.query),this._search(!1))}loadMore(e=!1){return this.isRunning?Promise.resolve(!1):(0===this.objects.length&&!e&&this.computeFacets(this.query),this._search(!0))}}const _r=d(void 0);function jr(){return m(_r)}function Pr(){return H(jr().facets)}function Tr(){const e=jr();return{...H(e.result),search:e}}function Ir(){const e=jr();return H(e.facets).total}var $r;async function Er(e){try{const t=await e.arrayBuffer(),n=new Ot;n.appendByteArray(new Uint8Array(t));const r=n.end();return r?.toString()}catch(e){return void console.error("Error calculating file hash:",e)}}function Lr(){const{client:e}=ke(),t=f();return{checkDocumentProcessing:async(n,r,s)=>{try{console.log(`Preparing metadata for ${n.length} files...`);const t=await async function(e,t){const n=[];for(let r=0;r<e.length;r+=5){const s=e.slice(r,r+5),a=await Promise.all(s.map((async e=>{let n=t||void 0;if(e.webkitRelativePath){const r=e.webkitRelativePath.split("/");if(r.length>1){const e=r.slice(0,-1).join("/");n=t?`${t}/${e}`:e}}return{file:e,hash:await Er(e),name:e.name,size:e.size,location:n}})));n.push(...a)}return n}(n,r),a=async()=>{const n={"content.etag":{$in:t.map((e=>e.hash))}};let r;r=s?await e.store.collections.searchMembers(s,{query:{match:n},select:void 0}):await e.store.objects.search({query:{match:n},select:void 0});for(const e of r){const n=t.find((t=>t.hash===e.content.etag));n&&(n.existingId=e.id,n.action=$r.SKIP)}},i=async()=>{const n=t.filter((e=>e.action!==$r.SKIP)),r=n.map((e=>e.location)),a=Array.from(new Set(r)),i=[];for(const t of a){const r=n.filter((e=>e.location===t)).map((e=>e.name)),a={location:t??"","content.name":{$in:r}};if(s){const t=e.store.collections.searchMembers(s,{query:{match:a},select:void 0});i.push(t)}else{const t=e.store.objects.find({query:{match:a},select:void 0});i.push(t)}}const l=(await Promise.all(i)).flat();console.log(`Found ${l.length} document to update`,l);for(const e of l){const n=t.find((t=>t.name===e.content.name&&(t.location?t.location===e.location:""===e.location)));n&&(n.existingId=e.id,n.action=$r.UPDATE)}console.log(`Reconciled ${t.filter((e=>e.action===$r.UPDATE)).length}`)};return await a(),await i(),t.forEach((e=>{e.action||(e.action=$r.CREATE)})),console.log("Document processing check results:",{totalFiles:n.length,toCreate:t.filter((e=>e.action===$r.CREATE)).length,toUpdate:t.filter((e=>e.action===$r.UPDATE)).length,toSkip:t.filter((e=>e.action===$r.SKIP)).length}),t}catch(e){throw t({title:"Error in file upload processing check",status:"error",description:e.message}),console.log("Error in file upload processing check",e),new Error("Error in file upload processing check: "+e.message)}}}}function Ar({isOpen:r,onClose:s,files:a,collectionId:i,selectedFolder:d,title:m="Upload Files",children:u,onUploadComplete:h,hideFileSelection:p=!1,showTypeSelectionOnly:g=!1}){const{client:b,typeRegistry:x}=ke(),v=f(),[w,N]=o([]),[k,C]=o([]),[S,T]=o(!1),[I,$]=o(null),[L,U]=o([]),[O,z]=o(!1),[F,R]=o(!1),[M,V]=o(0),[q,W]=o(Date.now()),[B,J]=o(void 0);c((()=>{i&&b.store.collections.retrieve(i).then(J)}),[i]);const H=()=>B||d?t("div",{className:"mb-4 p-3 bg-blue-50 rounded-md border border-blue-100",children:[t("div",{className:"flex items-center text-blue-700",children:[e(Qe,{className:"h-5 w-5 mr-2"}),e("span",{className:"font-medium",children:"Upload Location:"})]}),t("div",{className:"ml-7 text-sm text-blue-700 mt-1",children:[B&&t("div",{className:"flex items-center",children:[e("span",{className:"mr-1",children:"Collection:"}),e("span",{className:"font-medium",children:B.name})]}),d&&t("div",{className:"flex items-center mt-1",children:[e("span",{className:"mr-1",children:"Folder:"}),e("span",{className:"font-medium",children:d})]})]})]}):null,[G,K]=o({toCreate:0,toUpdate:0,toSkip:0}),{checkDocumentProcessing:Q}=Lr(),Y=l((()=>x?.types||[]),[x?.types]);c((()=>{r&&(a&&a.length>0?(N(a),ee(a)):(N([]),C([]),T(!1),$(null),U([]),z(!1),R(!1),V(0),K({toCreate:0,toUpdate:0,toSkip:0})),W(Date.now()))}),[r,a]);const X=()=>{N([]),C([]),T(!1),$(null),U([]),z(!1),R(!1),V(0),K({toCreate:0,toUpdate:0,toSkip:0}),s()},Z=e=>{e&&e.length>0&&(N(e),ee(e))},ee=async e=>{if(e.length)try{console.log(`Processing ${e.length} files to determine required actions...`);const t=await Q(e,d,i);C(t);const n=t.filter((e=>e.action===$r.CREATE)).length,r=t.filter((e=>e.action===$r.UPDATE)).length,s=t.filter((e=>e.action===$r.SKIP)).length;K({toCreate:n,toUpdate:r,toSkip:s}),v({title:"Files analyzed",description:`${e.length} file(s): ${n} new, ${r} to update, ${s} to skip`,status:"info",duration:4e3}),T(!0)}catch(e){console.error("Error processing files:",e),v({title:"Error",description:"There was an error analyzing the files",status:"error",duration:5e3})}},te=async()=>{if(!k.length)return;const e=I?.id||null,t=k.map((e=>({file:e.file,status:"pending",progress:0,action:e.action===$r.CREATE?"create":e.action===$r.UPDATE?"update":"skip"})));U(t),z(!0),R(!1);const n=k.filter((e=>e.action===$r.SKIP)),r=k.filter((e=>e.action===$r.UPDATE)),s=k.filter((e=>e.action===$r.CREATE)),a={success:!0,objectIds:[],uploadedFiles:[],skippedFiles:[],failedFiles:[]};for(const t of n)t.existingId&&(a.objectIds.push(t.existingId),a.skippedFiles.push({id:t.existingId,name:t.name,type:e,status:"skipped",location:t.location}),U((e=>e.map((e=>e.file===t.file?{...e,status:"success",progress:100,id:t.existingId}:e)))));const l=async(t,n)=>{const r=[];for(let e=0;e<t.length;e+=50)r.push(t.slice(e,e+50));for(let s=0;s<r.length;s++){const l=r[s];if(console.log(`Processing ${n} batch ${s+1}/${r.length} (${l.length} files)`),t.length>50){v({title:`Processing files (${n})`,description:`Processed ${50*s}/${t.length} files...`,status:"info",duration:2e3})}await Promise.all(l.map((async t=>{try{if(U((e=>e.map((e=>e.file===t.file?{...e,status:"uploading",progress:20}:e)))),"update"===n&&t.existingId)await b.store.objects.update(t.existingId,{type:e||void 0,content:t.file,location:t.location,name:t.name},{createRevision:!0,revisionLabel:"upload on "+(new Date).toISOString()}),U((e=>e.map((e=>e.file===t.file?{...e,status:"success",progress:100,id:t.existingId}:e)))),a.objectIds.push(t.existingId),a.uploadedFiles.push({id:t.existingId,name:t.name,type:e,status:"updated",location:t.location});else{const n=await b.store.objects.create({type:e||void 0,content:t.file,location:t.location||t.file.webkitRelativePath||t.name},{collection_id:i});U((e=>e.map((e=>e.file===t.file?{...e,status:"success",progress:100,id:n.id}:e)))),a.objectIds.push(n.id),a.uploadedFiles.push({id:n.id,name:t.name,type:e,status:"created",location:t.location})}}catch(n){console.error(`Failed to process file ${t.name}:`,n),U((e=>e.map((e=>e.file===t.file?{...e,status:"error",progress:100,message:n.message||"Unknown error"}:e)))),a.failedFiles.push({name:t.name,error:n.message||"Unknown error",status:"failed",location:t.location,type:e}),a.success=!1}})));const o=L.filter((e=>"success"===e.status||"error"===e.status)).length,c=L.length,d=Math.round(o/c*100);V(d)}};r.length>0&&await l(r,"update"),s.length>0&&await l(s,"create"),U((e=>{const t=e.filter((e=>"pending"===e.status)).map((e=>({...e,status:"error",progress:100,message:"Upload process interrupted"})));return t.length>0?(t.forEach((e=>{a.failedFiles.push({name:e.file.name,error:"Upload process interrupted",status:"failed",type:I?.id||null})})),a.success=!1,e.map((e=>"pending"===e.status?{...e,status:"error",progress:100,message:"Upload process interrupted"}:e))):e})),z(!1),R(!0);const o=a.uploadedFiles.filter((e=>"created"===e.status)).length,c=a.uploadedFiles.filter((e=>"updated"===e.status)).length,d=a.skippedFiles.length,m=a.failedFiles.length;let u="";o>0&&(u+=`${o} file${1!==o?"s":""} uploaded`),c>0&&(u+=u?", ":"",u+=`${c} file${1!==c?"s":""} updated`),d>0&&(u+=u?", ":"",u+=`${d} file${1!==d?"s":""} skipped`),m>0&&(u+=u?", ":"",u+=`${m} file${1!==m?"s":""} failed`),v({title:"Upload Complete",description:u,status:m>0?"warning":"success",duration:5e3}),h&&h(a)};return t(_,{isOpen:r,onClose:X,className:"w-full max-w-3xl mx-auto",children:[e(j,{children:m}),g?t(P,{className:"p-6",children:[u,H(),t("div",{className:"mb-4",children:[t("label",{className:"block text-sm font-medium mb-2",children:["Content Type ",e("span",{className:"text-gray-500 font-normal",children:"(Optional)"})]}),e(D,{options:Y,value:I,optionLabel:e=>e?e.name:"Select a content type",placeholder:"Select a content type or leave empty for automatic detection",onChange:e=>$(void 0===e?null:e),filterBy:"name",isClearable:!0}),t("div",{className:"mt-2 text-sm text-blue-600 flex items-center",children:[e(Be,{className:"h-4 w-4 mr-1"}),t("span",{children:[e("strong",{children:"Type selection is optional."})," Leave empty to let Vertesia choose the appropriate type"]})]})]}),t("div",I?{className:"text-sm text-gray-500 bg-gray-50 p-3 rounded-md mb-4",children:[e("div",{className:"font-medium",children:I.name}),I.description&&e("div",{className:"mt-1",children:I.description})]}:{className:"text-sm text-blue-600 bg-blue-50 p-3 rounded-md mb-4",children:[t("div",{className:"font-medium flex items-center",children:[e(Be,{className:"h-5 w-5 mr-1"}),"Automatic Type Detection"]}),t("div",{className:"mt-1",children:[e("p",{children:e("strong",{children:"Vertesia will analyze the content and select the most appropriate type."})}),e("p",{className:"mt-1",children:"This is recommended for most uploads and ensures optimal processing."})]})]})]}):0!==w.length||p?O||F?O?t(P,{className:"p-6",children:[H(),t("div",{className:"mb-4",children:[t("div",{className:"flex justify-between items-center mb-2",children:[e("div",{className:"text-lg font-medium",children:"Uploading Files"}),t("div",{className:"text-sm text-muted",children:[Math.round(M),"% complete"]})]}),e("div",{className:"h-2 bg-color-muted/20 rounded-full overflow-hidden",children:e("div",{className:"h-full bg-color-primary rounded-full",style:{width:`${M}%`}})})]}),e("div",{className:"max-h-96 overflow-y-auto",children:L.map(((n,r)=>t("div",{className:"flex items-center py-2 border-b border-color-border last:border-b-0",children:[t("div",{className:"mr-3",children:["pending"===n.status&&e(Ge,{className:"h-5 w-5 text-muted"}),"uploading"===n.status&&e(A,{size:"sm"}),"success"===n.status&&e(Be,{className:"h-5 w-5 text-green-500"}),"error"===n.status&&e(Ke,{className:"h-5 w-5 text-red-500"})]}),t("div",{className:"flex-1 min-w-0",children:[e("div",{className:"truncate font-medium",children:n.file.name}),t("div",{className:"text-xs text-muted",children:["pending"===n.status&&"Waiting...","uploading"===n.status&&"Uploading...","success"===n.status&&("create"===n.action?"Created":"update"===n.action?"Updated":"Skipped"),"error"===n.status&&n.message]})]})]},`${n.file.name}-${r}`)))})]}):e(P,{className:"p-6",children:t("div",{className:"mb-4",children:[e("div",{className:"text-lg font-medium mb-2",children:"Upload Complete"}),H(),e(Ct,{files:L.map((e=>{let t;return t="success"===e.status?"create"===e.action?"success":"update"===e.action?"updated":"skipped":"failed",{name:e.file.name,status:t,error:"error"===e.status?e.message:void 0}})),location:d||void 0,collection:B?.name})]})}):e(P,{className:"p-6",children:S?t(n,{children:[H(),t("div",{className:"mb-4",children:[t("div",{className:"flex justify-between items-center mb-2",children:[e("div",{className:"text-lg font-medium",children:"File Analysis Results"}),t("div",{className:"text-sm text-muted",children:[w.length," file",1!==w.length?"s":""]})]}),e("div",{className:"bg-color-muted/10 p-4 rounded-md mb-4",children:t("div",{className:"grid grid-cols-3 gap-4",children:[t("div",{className:"flex flex-col items-center",children:[t("div",{className:"flex items-center",children:[e(Je,{className:"h-5 w-5 text-blue-500 mr-2"}),e("span",{className:"font-medium",children:"New"})]}),e("div",{className:"text-2xl font-semibold",children:G.toCreate})]}),t("div",{className:"flex flex-col items-center",children:[t("div",{className:"flex items-center",children:[e(Be,{className:"h-5 w-5 text-green-500 mr-2"}),e("span",{className:"font-medium",children:"Update"})]}),e("div",{className:"text-2xl font-semibold",children:G.toUpdate})]}),t("div",{className:"flex flex-col items-center",children:[t("div",{className:"flex items-center",children:[e(He,{className:"h-5 w-5 text-yellow-500 mr-2"}),e("span",{className:"font-medium",children:"Skip"})]}),e("div",{className:"text-2xl font-semibold",children:G.toSkip})]})]})})]}),t("div",{className:"mb-4",children:[t("label",{className:"block text-sm font-medium mb-2",children:["Content Type ",e("span",{className:"text-gray-500 font-normal",children:"(Optional)"})]}),e(D,{options:Y,value:I,optionLabel:e=>e?e.name:"Select a content type",placeholder:"Select a content type or leave empty for automatic detection",onChange:e=>$(void 0===e?null:e),filterBy:"name",isClearable:!0}),t("div",{className:"mt-2 text-sm text-blue-600 flex items-center",children:[e(Be,{className:"h-4 w-4 mr-1"}),t("span",{children:[e("strong",{children:"Type selection is optional."})," Leave empty to let Vertesia choose the appropriate type"]})]})]}),t("div",I?{className:"p-4 bg-gray-50 rounded-md border border-gray-100 mb-4",children:[e("div",{className:"font-medium mb-2",children:"Files to process with selected type:"}),e("div",{className:"text-sm",children:G.toCreate+G.toUpdate>0?t("div",{className:"space-y-1",children:[t("p",{children:[G.toCreate+G.toUpdate," file(s) ready to process",G.toSkip>0&&` (${G.toSkip} will be skipped as they already exist)`]}),t("p",{className:"text-green-600",children:["Files will be uploaded with type:"," ",e("strong",{children:I.name})]}),I.description&&e("p",{className:"text-gray-500 mt-1",children:I.description})]}):G.toSkip>0?t("span",{children:["All ",G.toSkip," file(s) already exist in the system and will be skipped. You can proceed to view the results."]}):e("span",{children:"No files to process."})})]}:{className:"p-4 bg-blue-50 rounded-md border border-blue-100 mb-4",children:[t("div",{className:"font-medium mb-2 flex items-center text-blue-700",children:[e(Be,{className:"h-5 w-5 mr-1"}),"Automatic Type Detection"]}),e("div",{className:"text-sm text-blue-700",children:G.toCreate+G.toUpdate>0?t("div",{className:"space-y-1",children:[t("p",{children:[G.toCreate+G.toUpdate," file(s) ready to process",G.toSkip>0&&` (${G.toSkip} will be skipped as they already exist)`]}),e("p",{className:"mt-2",children:e("strong",{children:"Vertesia will analyze each file and select the most appropriate type."})}),e("p",{className:"mt-1",children:"This is recommended for most uploads and ensures optimal processing."})]}):G.toSkip>0?t("span",{children:["All ",G.toSkip," file(s) already exist in the system and will be skipped. You can proceed to view the results."]}):e("span",{children:"No files to process."})})]})]}):t("div",{className:"flex flex-col items-center justify-center py-8",children:[e(A,{size:"lg",className:"mb-4"}),e("div",{className:"text-lg font-medium",children:"Analyzing files..."}),e("div",{className:"text-sm text-muted mt-2",children:"Checking for duplicates and updates"})]})}):t(P,{className:"flex flex-col items-center justify-center p-8",children:[H(),e(kt,{onDrop:Z,message:"Drag and drop files here or click to select",buttonLabel:"Select Files",className:"w-full h-64"}),u]}),(()=>{if(g)return t(E,{children:[e(y,{variant:"ghost",onClick:X,children:"Cancel"}),e(y,{onClick:()=>{h&&h({success:!0,objectIds:[],uploadedFiles:[{name:"type-selection",type:I?.id||null,status:"created"}],skippedFiles:[],failedFiles:[]}),X()},children:I?`Use ${I.name}`:"Use Automatic Type Detection"})]});if(0===w.length&&!p)return e(E,{children:e(y,{variant:"ghost",onClick:X,children:"Cancel"})});if(!O&&!F){const n=S;return t(E,{children:[e(y,{variant:"ghost",onClick:X,children:"Cancel"}),e(y,{disabled:!n,onClick:te,className:I?"":"bg-blue-600 hover:bg-blue-700",children:G.toCreate+G.toUpdate>0?I?`Upload with ${I.name}`:"Upload with Automatic Type Detection":"Continue"})]})}return O?e(E,{children:e(y,{variant:"ghost",disabled:!0,children:"Uploading..."})}):t(E,{children:[e(y,{variant:"ghost",onClick:()=>{N([]),C([]),T(!1),$(null),U([]),z(!1),R(!1),V(0),K({toCreate:0,toUpdate:0,toSkip:0})},children:"Upload More"}),e(y,{onClick:X,children:"Close"})]})})()]},q)}function Ur(e){const t="function"==typeof e?e:e.onUploadDone,{client:n,project:r,store:s}=ke(),a=jr(),i=f(),{checkDocumentProcessing:l}=Lr();return async(e,o,c)=>{const d={success:!1,objectIds:[],uploadedFiles:[],skippedFiles:[],failedFiles:[]};if(!r)return i({status:"error",title:"No project selected",duration:3e3}),d;if(!e||0===e.length)return i({status:"warning",title:"No files selected",duration:3e3}),d;const m=Array.from(e).filter((e=>e.size>0));if(0===m.length)return i({status:"error",title:"No valid files selected",description:"Please select files with valid content.",duration:5e3}),d;const u=[],h=[],p=[];console.log(`Processing ${m.length} files with smart file processing...`);const g=await l(m,null,c),f=g.filter((e=>e.action===$r.CREATE)).length,b=g.filter((e=>e.action===$r.UPDATE)).length,y=g.filter((e=>e.action===$r.SKIP)).length;i({title:"Files analyzed",description:`${m.length} file(s): ${f} new, ${b} to update, ${y} to skip`,status:"info",duration:4e3});for(const e of g.filter((e=>e.action===$r.SKIP&&e.existingId)))u.push({id:e.existingId,name:e.name,type:o,status:"skipped",location:e.location});const x=g.filter((e=>(e.action===$r.CREATE||e.action===$r.UPDATE)&&e.file));if(x.length>0){console.log(`Processing ${x.length} files (${x.filter((e=>e.action===$r.CREATE)).length} create, ${x.filter((e=>e.action===$r.UPDATE)).length} update)...`);const e=50,t=[];for(let n=0;n<x.length;n+=e)t.push(x.slice(n,n+e));for(let r=0;r<t.length;r++){const a=t[r],l=r*e;console.log(`Processing batch ${r+1}/${t.length} (${a.length} files)`),x.length>e&&i({title:"Processing files",description:`Processed ${l}/${x.length} files...`,status:"info",duration:2e3});const m=await Promise.all(a.map((async e=>{try{if(e.action===$r.UPDATE&&e.existingId){const t=await n.store.objects.update(e.existingId,{type:o||void 0,content:e.file,location:e.location,name:e.name},{createRevision:!0,revisionLabel:"upload on "+(new Date).toISOString()});return h.push({id:e.existingId,name:e.name,type:o,status:"updated",location:e.location}),d.objectIds.push(e.existingId),{success:!0,id:t.id,name:e.name,action:"update"}}{const t=c?{collection_id:c}:void 0,n=await s.objects.create({type:o||void 0,content:e.file,location:e.location||e.file.webkitRelativePath||e.name},t);h.push({id:n.id,name:e.name,type:o,status:"created",location:e.location})}}catch(t){console.error(`Failed to process file ${e.name}:`,t),p.push({name:e.name,error:t.message||"Unknown error",status:"failed",location:e.location,type:o}),i({status:"error",title:`Processing failed for ${e.name}`,description:t.message,duration:4e3})}}))),u=h.filter((e=>"created"===e.status)),g=h.filter((e=>"updated"===e.status)),f=h.filter((e=>"failed"===e.status));console.log(`Batch ${r+1} results:`,{creates:u,updates:g,failures:f,total:m.length})}}const v=h.filter((e=>"created"===e.status)).length,w=h.filter((e=>"updated"===e.status)).length,N=h.filter((e=>"failed"===e.status)).length,k=h.filter((e=>"skipped"===e.status)).length;t&&(console.log("Upload complete:",{totalObjectIds:d.objectIds.length,uploadedFiles:v,updatedFiles:w,skippedFiles:k,failedFiles:N}),await t(d.objectIds));let C="";return v>0&&(C+=`${v} file${1!==v?"s":""} uploaded`),w>0&&(C+=C?", ":"",C+=`${w} file${1!==w?"s":""} updated`),k>0&&(C+=C?", ":"",C+=`${k} file${1!==k?"s":""} skipped (already existed)`),N>0&&(C+=C?", ":"",C+=`${N} file${1!==N?"s":""} failed`),C&&i({status:N>0?"warning":"success",title:C,duration:4e3}),a.search(),d}}!function(e){e.CREATE="create",e.SKIP="skip",e.UPDATE="update"}($r||($r={}));const Or=[{name:"ID",field:"id",type:"string?slice=-7"},{name:"Name",field:".",type:"objectLink"},{name:"Type",field:"type.name",type:"string"},{name:"Status",field:"status",type:"string"},{name:"Updated At",field:"updated_at",type:"date"}];function zr({isGridView:t=!1,onUpload:n,collectionId:r,...s}){return n?e(Fr,{...s,onUpload:n,isGridView:t,collectionId:r}):e(Dr,{...s,isGridView:t})}function Fr({isGridView:n,onUpload:s,collectionId:a,skipTypeModal:i=!1,...l}){const[c,d]=o(!1),[m,u]=o([]),[h,p]=o(!1),[g,b]=o(null),[y,x]=o(!1),v=jr(),w=f(),{checkDocumentProcessing:N}=Lr(),k=async(e,t)=>{console.log("Files dropped on ObjectTable:",e.length,t),d(!0);try{if(a){const t=await N(e,null,a);b(t);const n=t.filter((e=>"create"===e.action)).length,r=t.filter((e=>"update"===e.action)).length,s=t.filter((e=>"skip"===e.action)).length;w({title:"Files ready to process",description:`${e.length} file(s): ${n} new, ${r} to update, ${s} to skip`,status:"info",duration:4e3})}else b(null)}catch(e){console.error("Error processing files:",e),w({title:"Error processing files",description:"There was an error checking for duplicate files",status:"error",duration:4e3}),b(null)}finally{if(d(!1),u(e),p(!1),i){console.log("Skipping type modal and calling onUpload directly",{filesLength:e.length,processedFilesLength:g?.length});const t=s(e,null,a);t&&"object"==typeof t&&(t.processedFiles=g)}else console.log("Setting typeSelectionOpen to true",{filesLength:e.length}),x(!0)}},C=e=>{const t=[...m];u([]),b(null),x(!1),t.length>0&&void 0!==e&&(d(!0),console.log("Starting upload with",{typeId:e,filesCount:t.length,hasProcessingResults:!!g,collectionId:a}),s(t,e,a).finally((()=>{d(!1),v.search()})))},S=e=>{e.preventDefault(),e.stopPropagation(),p(!0)};return t("div",{className:"min-h-[400px] relative",onDragOver:S,onDragEnter:S,onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),e.currentTarget.contains(e.relatedTarget)||p(!1)},onDrop:e=>{if(e.preventDefault(),e.stopPropagation(),p(!1),e.dataTransfer.items){const t=[];for(let n=0;n<e.dataTransfer.items.length;n++){const r=e.dataTransfer.items[n];if("file"===r.kind){const e=r.getAsFile();e&&t.push(e)}}if(t.length>0){const e={count:t.length,message:`Preparing to upload ${t.length} file${1===t.length?"":"s"}...`};k(t,e)}}},children:[e("div",{className:r("bg-white dark:bg-gray-800 opacity-40 absolute inset-0 z-50 flex justify-center items-center",c?"block":"hidden"),children:e(A,{size:"xl"})}),e(Dr,{...l,isGridView:n}),e("div",{className:r("absolute inset-0 pointer-events-none",h?"z-40":"-z-10"),children:e("div",{className:"w-full h-full relative",children:e(kt,{onDrop:k,message:"Drop files or folders here to upload",className:r("absolute inset-0 bg-white/90 dark:bg-gray-800/90 pointer-events-auto",h?"flex":"hidden"),buttonLabel:"Select Files or Folders",allowFolders:!0})})}),e(Ar,{isOpen:y&&m.length>0,onClose:()=>{u([]),b(null),x(!1),C(void 0)},files:m,collectionId:a,selectedFolder:null,title:"Upload Files",onUploadComplete:e=>{if(e){if(e.failedFiles&&e.failedFiles.length>0&&w({title:"Upload Issues",description:`${e.failedFiles.length} file(s) failed to upload`,status:"warning",duration:5e3}),e.success){const t=e.uploadedFiles.filter((e=>"created"===e.status)).length,n=e.uploadedFiles.filter((e=>"updated"===e.status)).length,r=e.skippedFiles.length;(t>0||n>0)&&w({title:"Upload Complete",description:`${t>0?`${t} created`:""}${t>0&&n>0?", ":""}${n>0?`${n} updated`:""}${r>0?`, ${r} skipped`:""}`,status:"success",duration:5e3})}v.search()}u([]),b(null),x(!1),e&&e.success&&e.objectIds.length>0?C(null):C(void 0)}})]})}function Dr({objects:t,layout:n=Or,isLoading:r,onRowClick:s,onSelectionChange:a,isGridView:i}){const o=fr(),c=(e,n)=>{if(o){const r=n.nativeEvent.shiftKey;if(n.target.checked){if(o.add(e),r){const n=t.findIndex((t=>t.id===e.id)),r=function(e,t,n){for(let r=t-1;r>=0;r--)if(n.isSelected(e[r].id))return r;return-1}(t,n,o);if(r>-1&&r<n-1){const e=[];for(let s=r+1;s<n;s++)e.push(t[s]);o.addAll(e)}else{const e=function(e,t,n){const r=e.length;for(let s=t+1;s<r;s++)if(n.isSelected(e[s].id))return s;return-1}(t,n,o);if(e>-1&&e>n+1){const r=[];for(let s=n+1;s<e;s++)r.push(t[s]);o.addAll(r)}}}}else o.remove(e.id);a&&a(o)}},d=e=>{if(o){e.target.checked?o.addAll(t):o.removeAll()}},m=l((()=>(n.length>0?n:Or).map((e=>new Nr(e)))),[n]);return e(i?Cr:kr,{objects:t,isLoading:r,columns:m,onRowClick:s,selection:o,toggleAll:d,onSelectionChange:c})}function Rr({children:t,limit:n,parent:r,typeId:s,facets:a,similarTo:i,embeddingType:o,name:c,collectionId:d}){const{store:m}=ke(),u=l((()=>{let e;a?e=a:(e=[{name:"status",field:"status"},{name:"location",field:"location"}],s||e.unshift({name:"type",field:"type"}));const t=new Sr(m,n).withFacets(e);return t.collectionId=d,t.query.type=s,t.query.parent=r,t.query.similarTo=i,t.query.embeddingType=o,t.query.name=c,t}),[s,n]);return e(_r.Provider,{value:u,children:t})}const Mr=[{name:"Name",field:"properties.title",type:"string",fallback:"name"},{name:"Type",field:"type.name",type:"string"},{name:"Status",field:"status",type:"string"},{name:"Created At",field:"created_at",type:"date"}];function Vr({onChange:t}){return e(Rr,{children:e(Wr,{onRowClick:e=>{t(e||void 0)}})})}const qr="vertesia.content_store.lastDisplayedView";function Wr({onRowClick:n}){const[r,s]=o(!1),[a,i]=o("grid"===localStorage.getItem(qr)),{search:l,isLoading:d,error:m,objects:h}=Tr(),p=u(null);G(p,(()=>{r&&l.loadMore(!0)}),{deps:[r]}),c((()=>{l.search().then((()=>s(!0)))}),[]);const g=Pr(),f=jr();return m?e(K,{title:"Search failed",children:m.message}):t("div",{children:[t("div",{className:"flex justify-between items-center mb-4",children:[e(ur,{facets:g,search:f,textSearch:"Filter content"}),t("div",{className:"flex items-center gap-2",children:[e(y,{variant:"outline",onClick:()=>{s(!1),l.search().then((()=>s(!0)))},alt:"Refresh",children:e(Ye,{size:16})}),e(wn,{onUpdate:i})]})]}),e(zr,{objects:h||[],isLoading:!1,layout:Mr,onRowClick:n,isGridView:a}),e("div",{ref:p,className:"mt-10"}),d&&e("div",{className:"flex justify-center",children:e(A,{size:"xl"})})]})}function Br({isOpen:n,onClose:r}){return t(Q,{onClose:()=>r(),isOpen:!!n,className:"min-w-[60vw]",children:[e(Y,{children:"Select Content"}),e(X,{className:"pt-0 overflow-y-auto max-h-[80vh] min-h-[80vh]",children:n&&e(Vr,{onChange:r})})]})}const Jr=/store:([a-f0-9]+)/;function Hr({object:n}){const{client:s}=ke(),{off:a,on:i,isOn:l}=Z(),[d,m]=o(null!=n.value?String(n.value):""),[u,h]=o(void 0),p=()=>{m(""),n.value="",h(void 0)};return c((()=>{if(!d||u)return;const e=d.match(Jr);e&&s.objects.get(e[1]).then((e=>{h(e)})).catch((()=>{p()}))}),[d]),t("div",{children:[t("div",{className:"relative",children:[e("input",{value:d,onChange:e=>{const t=e.target.value;m(t),n.value=t},className:r(ee.INPUT,"pr-10 w-full")}),u&&e("div",{className:"absolute inset-y-0 right-10 flex items-center justify-center ",children:e(y,{onClick:p,variant:"unstyled",className:"hover:text-red-500 hover:bg-gray-100 dark:hover:bg-gray-600",children:e(Ce,{className:"size-5"})})}),e("div",{className:"absolute inset-y-0 right-0 flex items-center justify-center",children:e(y,{onClick:i,variant:"unstyled",className:"hover:bg-gray-100 dark:hover:bg-gray-600",children:e(Xe,{className:"size-5"})})}),e(Br,{value:d,isOpen:l,onClose:e=>{if(e){const t="store:"+e.id;m(t),h(e||void 0),n.value=t}a()}})]}),u&&e("div",{className:"p-1 semibold text-sm text-gray-600 dark:text-slate-300",children:u.properties?.title||u.name})]})}function Gr(e,t,n){return()=>{n&&e.files.getDownloadUrl(n).then((e=>{window.open(e.url,"_blank")})).catch((e=>{t({status:"error",title:"Failed to get download URL",description:e.message,duration:5e3})}))}}function Kr({objectId:n,isOpen:r,onClose:s}){const a=bt(),{client:i,store:l}=ke(),[d,m]=o(null),[u,h]=o(!1),[p,g]=o(!1),[b,x]=o(),[v,w]=o(),[N,k]=o("preview"),C=f();c((()=>{n&&r?(h(!0),l.objects.retrieve(n,"+embeddings").then((e=>{m(e),e.text?x(e.text):S(e.id);const t=e.content;t&&t.source&&t.type&&t.type.startsWith("image/")&&_(e)})).catch((e=>{console.error("Error loading object:",e),C({title:"Error",description:"Failed to load document",status:"error",duration:3e3})})).finally((()=>{h(!1)}))):(m(null),x(void 0),w(void 0))}),[n,r,l.objects]);const S=async e=>{g(!0);try{const t=await l.objects.getObjectText(e);x(t.text)}catch(e){console.error("Error loading text:",e)}finally{g(!1)}},_=async e=>{try{"found"===(await i.objects.getRendition(e.id,{max_hw:1024,format:ye.jpeg,generate_if_missing:!1})).status&&console.log("Found rendition");const t=await i.files.getDownloadUrl(e.content.source);w(t.url)}catch(e){console.error("Error loading image:",e)}},j=()=>{d&&(a(`/legal/objects/${d.id}`),s())},P=b&&(b.startsWith("#")||b.includes("\n#")||b.includes("\n*")),T=d?.content?.type&&d.content.type.startsWith("image/"),I="application/pdf"===d?.content?.type;return r?t("div",{className:"fixed inset-y-0 right-0 w-2/5 dark:bg-slate-900 shadow-xl z-50 flex flex-col transition-transform duration-300 transform "+(r?"translate-x-0":"translate-x-full"),children:[t("div",{className:"flex items-center justify-between px-4 py-3 border-b dark:border-gray-700 bg-gradient-to-r from-indigo-50 to-gray-50 dark:from-gray-800 dark:to-gray-900",children:[t("div",{className:"flex items-center",children:[e(Ze,{className:"h-5 w-5 text-indigo-600 mr-2"}),e("h2",{className:"text-lg font-semibold text-gray-800 dark:text-gray-200 truncate",children:u?"Loading document...":d?.name||"Document Preview"})]}),t("div",{className:"flex items-center space-x-2",children:[t(y,{variant:"ghost",size:"sm",onClick:j,className:"flex items-center gap-1 text-indigo-600 hover:text-indigo-800",children:[e(et,{className:"h-4 w-4"}),e("span",{children:"Full View"})]}),e(y,{variant:"ghost",size:"sm",onClick:s,className:"flex items-center text-gray-600 hover:text-gray-800 dark:text-gray-300 dark:hover:text-gray-100",children:e(Ce,{className:"h-5 w-5"})})]})]}),u?e("div",{className:"flex-1 flex items-center justify-center",children:t("div",{className:"text-center",children:[e(A,{size:"lg",className:"text-indigo-600 dark:text-indigo-400 mb-2"}),e("p",{className:"text-gray-600 dark:text-gray-400",children:"Loading document..."})]})}):t("div",{className:"flex-1 flex flex-col h-full",children:[e("div",{className:"border-b",children:t("div",{className:"flex px-4",children:[e("button",{className:"py-2 px-4 font-medium border-b-2 "+("preview"===N?"border-indigo-600 text-indigo-700 dark:text-indigo-300":"border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"),onClick:()=>k("preview"),children:t("div",{className:"flex items-center gap-1",children:[e(Re,{className:"h-4 w-4"}),e("span",{children:"Preview"})]})}),e("button",{className:"py-2 px-4 font-medium border-b-2 "+("properties"===N?"border-indigo-600 text-indigo-700 dark:text-indigo-300":"border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"),onClick:()=>k("properties"),children:t("div",{className:"flex items-center gap-1",children:[e(Ee,{className:"h-4 w-4"}),e("span",{children:"Properties"})]})})]})}),t("div",{className:"flex-1 overflow-auto p-4",children:["preview"===N&&t("div",{className:"h-full",children:[p?e("div",{className:"flex items-center justify-center h-40",children:e(A,{size:"md",className:"text-indigo-600 dark:text-indigo-400"})}):b?e("div",{className:"shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800",children:P?e("div",{className:"prose prose-sm max-w-none prose-p:my-2 prose-pre:bg-gray-800 prose-pre:my-2 prose-headings:text-indigo-700 dark:prose-invert dark:prose-headings:text-indigo-300",children:e(xt,{remarkPlugins:[vt],children:b})}):e("pre",{className:"text-wrap whitespace-pre-wrap dark:text-gray-200",children:b})}):null,T&&e("div",{className:"mt-4",children:e("div",v?{className:"border border-gray-200 dark:border-gray-700 rounded-md p-2 bg-white dark:bg-gray-800",children:e("img",{src:v,alt:d?.name,className:"mx-auto max-h-[70vh] object-contain"})}:{className:"flex items-center justify-center h-40",children:e(A,{size:"md",className:"text-indigo-600 dark:text-indigo-400"})})}),I&&t("div",{className:"flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800",children:[e(Ze,{className:"h-16 w-16 text-indigo-300 dark:text-indigo-400 mb-4"}),t("p",{className:"text-gray-600 dark:text-gray-400 text-center mb-4",children:["PDF document preview is available in full view. TODO"," "]}),e(y,{onClick:j,className:"bg-indigo-600 hover:bg-indigo-700 text-white",children:"Open Full Document View"})]}),!T&&!b&&!I&&!p&&t("div",{className:"flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800",children:[e(Ze,{className:"h-16 w-16 text-gray-300 dark:text-gray-600 mb-4"}),e("p",{className:"text-gray-600 dark:text-gray-400 text-center",children:"No preview available for this document type."})]})]}),"properties"===N&&d&&t("div",{className:"h-full",children:[d.properties?e("div",{className:"shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800",children:e(Nt,{value:d.properties})}):t("div",{className:"flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800",children:[e(Ee,{className:"h-16 w-16 text-gray-300 dark:text-gray-600 mb-4"}),e("p",{className:"text-gray-600 dark:text-gray-400 text-center",children:"No properties available for this document."})]}),t("div",{className:"mt-4",children:[e("h3",{className:"text-sm font-semibold text-gray-700 dark:text-gray-300 mb-2",children:"Document Information"}),e("div",{className:"shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800",children:t("div",{className:"grid grid-cols-2 gap-y-2 gap-x-4 text-sm",children:[e("div",{className:"text-gray-500 dark:text-gray-400",children:"ID"}),e("div",{className:"font-medium dark:text-gray-200",children:d.id}),e("div",{className:"text-gray-500 dark:text-gray-400",children:"Type"}),e("div",{className:"font-medium dark:text-gray-200",children:d.type?.name||"Unknown"}),e("div",{className:"text-gray-500 dark:text-gray-400",children:"Content Type"}),e("div",{className:"font-medium dark:text-gray-200",children:d.content?.type||"N/A"}),e("div",{className:"text-gray-500",children:"Size"}),e("div",{className:"font-medium",children:d.content&&"size"in d.content?Qr(d.content.size):"Unknown"}),e("div",{className:"text-gray-500",children:"Created"}),e("div",{className:"font-medium",children:d.created_at?new Date(d.created_at).toLocaleString():"N/A"}),e("div",{className:"text-gray-500",children:"Updated"}),e("div",{className:"font-medium",children:d.updated_at?new Date(d.updated_at).toLocaleString():"N/A"})]})})]})]})]})]}),t("div",{className:"flex items-center justify-between p-4 border-t bg-gray-50 dark:bg-gray-800 dark:border-gray-700",children:[e("div",{children:d?.content?.source&&t(y,{onClick:()=>{d?.content?.source&&i.files.getDownloadUrl(d.content.source).then((e=>{window.open(e.url,"_blank")})).catch((e=>{console.error("Error getting download URL:",e),C({title:"Error",description:"Failed to download file",status:"error",duration:3e3})}))},variant:"outline",className:"text-indigo-600 border-indigo-300 hover:bg-indigo-50",children:[e(qe,{className:"h-4 w-4 mr-2"}),"Download"]})}),t(y,{onClick:j,className:"bg-indigo-600 hover:bg-indigo-700 text-white",children:["Open Full Document",e(tt,{className:"h-4 w-4 ml-2"})]})]})]}):null}function Qr(e){if(0===e)return"0 Bytes";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(2))+" "+["Bytes","KB","MB","GB","TB"][t]}function Yr({onChange:n,isLoading:r,refresh:s}){const{client:a,project:i}=ke(),l=f(),[d,m]=o(void 0),[u,h]=o(void 0),[p,g]=o(void 0),b=!(!i||!p?.embeddings.text&&!p?.embeddings.image),[x,v]=o(void 0);c((()=>{m(void 0),h(void 0),v(void 0)}),[s]),c((()=>{i&&a.projects.retrieve(i.id).then((e=>{g(e.configuration)}))}),[i]),c((()=>{x&&l({title:x,status:"success",duration:2e3})}),[x]),c((()=>{d&&0!==d.length||n(void 0)}),[d]);const w=async()=>{if(!b||!d||!p?.embeddings.text)return;v("Generating text embeddings...");return{values:(await a.environments.embeddings(p.embeddings.text?.environment,{model:p.embeddings.text?.model,text:d})).values,type:Ne.text}},N=async()=>{if(!b||!d||!p?.embeddings.image)return;v("Generating image embeddings...");return{values:(await a.environments.embeddings(p.embeddings.image?.environment,{model:p.embeddings.image?.model,image:u})).values,type:Ne.image}},k=(e="text")=>{("text"===e?w:N)().then((e=>{v("Embeddings generated"),e&&(n(e),v("Searching..."))}))};return t("div",{className:"flex gap-1 items-center w-full",children:[e($,{placeholder:"Type what you are looking for",value:d,onChange:m,onKeyDown:e=>{"Enter"===e.key&&k("text")}}),e(y,{variant:"secondary",isLoading:r,onClick:()=>k("text"),isDisabled:!b,alt:"semantic search",children:"Search"})]})}const Xr=[{name:"ID",field:"id",type:"string?slice=-7"},{name:"Name",field:".",type:"objectLink"},{name:"Type",field:"type.name",type:"string"},{name:"Status",field:"status",type:"string"},{name:"Updated At",field:"updated_at",type:"date"}];function Zr({onUploadDone:t=async()=>{},layout:n}){const r=jr(),s=f(),a=Ur((async e=>{await t(e),setTimeout((()=>{console.log("Delayed refresh after upload to ensure backend consistency"),r.search().then((()=>{s({title:"Document list refreshed",description:"The document list has been updated with your uploaded files.",status:"info",duration:3e3})})).catch((e=>{console.error("Failed to refresh search results:",e)}))}),1e3)}));return e(es,{layout:n,onUpload:(e,t)=>{const n=r.collectionId;return a(e,t,n)}})}function es({layout:n,onUpload:r,allowFilter:s=!0,allowSearch:a=!0}){const i=jr(),[l,d]=o(!1),[m,h]=o(null),{typeRegistry:p}=ke(),{search:g,isLoading:f,error:b,objects:x}=Tr(),[v,w]=o(void 0),[N,k]=o(p?n||(C=p,((S=g.query.type)?C.getTypeLayout(S):Xr)??Xr):Xr);var C,S;const[_,j]=o(0),[P,T]=o(0),[I,$]=o("grid"===localStorage.getItem(wn.LAST_DISPLAYED_VIEW)),E=u(null);G(E,(()=>{l&&x.length>0&&x.length!=P&&(d(!1),g.loadMore().finally((()=>{T(x.length),d(!0)})))}),{deps:[l,x.length]}),c((()=>{g.search().then((()=>d(!0)))}),[]);const[L,U]=o(""),O=te(L,500);c((()=>{g.query.name=L,g.search().then((()=>d(!0)))}),[O]),c((()=>{if(v){if(g.query.vector=v,!N.find((e=>"Vector Similarity"===e.name))){const e=[...N,{name:"Vector Similarity",field:"score"}];k(e)}g.search().then((()=>d(!0)))}else delete g.query.vector,g.search().then((()=>d(!0)))}),[v?.values]);const z=Pr(),F=jr();return t("div",{className:"flex flex-col gap-y-2",children:[e(ts,{object:m,onClose:()=>h(null)}),b&&e(K,{title:"Error",children:b.message}),t("div",{className:"flex flex-row gap-4 items-center justify-between w-full",children:[a&&e(Yr,{onChange:w,isLoading:f,refresh:_}),t("div",{className:"flex gap-1 items-center",children:[e(y,{variant:"outline",onClick:()=>{g.search().then((()=>d(!0)))},alt:"Refresh",children:e(Ye,{size:16})}),e(wn,{onUpdate:$})]})]}),s&&e(ur,{facets:z,search:F,textSearch:"Name or ID"}),e(zr,{objects:x,isLoading:!x.length&&f,layout:N,onRowClick:h,onUpload:r,isGridView:I,collectionId:i.collectionId}),f&&e("div",{className:"flex justify-center",children:e(A,{size:"xl"})}),e("div",{ref:E})]})}function ts({object:n,onClose:r}){const{store:s}=ke(),a=f(),i=bt(),l=Gr(s,a,n?.content?.source);return n?t(ne,{title:n.properties?.title||n.name,isOpen:!0,onClose:r,children:[t("div",{className:"flex items-center gap-x-2",children:[e(y,{variant:"ghost",size:"sm",title:"Open Object",onClick:()=>i(`/objects/${n.id}`),children:e(We,{className:"size-4"})}),n.content?.source&&e(y,{variant:"ghost",size:"sm",title:"Download",onClick:l,children:e(qe,{className:"size-4"})})]}),e(re,{className:"my-2"}),e("div",{className:"pt-2",children:e(Sn,{object:n,loadText:!0})})]}):null}var ns;function rs({isExporting:n,isOpen:r,onClose:s}){return t(_,{onClose:()=>s(void 0),isOpen:r,className:"relative overflow-visible",children:[e(j,{children:"Export Object Properties"}),!n&&e(ss,{onClose:s}),n&&e(as,{})]})}function ss({onClose:n}){const[r,s]=o(void 0),[a,i]=o(void 0),l=["Export selected objects","Export all objects"];return t(P,{className:"min-h-[104px] pt-0 flex flex-col gap-y-4",children:[e("div",{className:"h-1/3",children:e(D,{options:l,value:a,onChange:i,placeholder:"Choose what to export",className:"h-full w-full text-sm",filterBy:"name",isClearable:!0})}),t("div",{className:"h-1/2 flex flex-col gap-y-8 content-between",children:[e(D,{options:Object.values(ns),value:r,onChange:s,placeholder:"Choose a format",className:"h-full w-full text-sm",filterBy:"name",isClearable:!0}),e(y,{className:"w-full",isDisabled:!r||!a,onClick:()=>{n(r,a==l[1])},children:"Export Properties"})]})]})}function as({}){return e(P,{className:"min-h-[84px] pt-0",children:t("div",{className:"h-full grid flex-col gap-y-2 content-between justify-items-center",children:[t("div",{className:"text-sm flex flex-col gap-x-2",children:[e("p",{children:"EXPORT IS IN PROGRESS"}),e("p",{className:"pt-2 grid justify-items-center",children:"PLEASE WAIT"})]}),e(A,{size:"lg"})]})})}function is({collection:t}){const n=f(),{client:r,typeRegistry:s}=ke(),a=function(e,t){let n=e.table_layout;if(n&&n.length>0)return n;e.type&&t&&(n=t?.getTypeLayout(e.type.id));return n&&n.length>0?n:void 0}(t,s);return t.dynamic?e(es,{layout:a}):e(Zr,{onUploadDone:async e=>{e.length>0&&await r.store.collections.addMembers(t.id,e).catch((e=>{n({title:"Failed to add objects to collection",description:e.message,status:"error"})}))},layout:a})}!function(e){e.CSV="CSV",e.JSON="JSON"}(ns||(ns={}));const ls=n=>null===n?"None":t("div",{children:[e("div",{className:"text-sm",children:n.name}),e("div",{className:"text-xs text-gray-500",children:n.description})]});function os({className:t,defaultValue:n,onChange:r,isClearable:s,multiple:a}){const i=ke(),[l,d]=o(!1),[m,u]=o(),[h,p]=o([]);c((()=>{if(!l&&(d(!0),i.typeRegistry&&n)){if(a&&Array.isArray(n)){const e=i.typeRegistry.types.filter((e=>n.includes(e.id)));p(e)}const e=i.typeRegistry.types.find((e=>e.id===n));e&&u(e)}}),[i.typeRegistry,n,a]);const g=e=>{p(e),r(e)};return e("div",a?{className:"flex flex-col gap-4 content-between",children:e(se,{options:i.typeRegistry?.types||[],value:h,onChange:g,placeholder:"Choose Content Types...",optionLabel:ls,className:t||"text-sm bg-background",filterBy:"name",isClearable:s||!1,multiple:!0})}:{className:"flex flex-col gap-4 content-between",children:e(se,{options:i.typeRegistry?.types||[],value:m,onChange:e=>{u(e||void 0),r(e)},placeholder:"Choose a Content Type...",optionLabel:ls,className:t||"text-sm bg-background",filterBy:"name",isClearable:s||!1})})}function cs({onClose:n,redirect:r=!0,onAddToCollection:s}){const a=bt(),i=f(),[l,c]=o(!1),{client:d}=ke(),[m,u]=o({dynamic:!1,name:"",description:""});function h(e,t){u({...m,[e]:t})}return t("form",{children:[t(X,{children:[e(I,{label:"Name",required:!0,children:e($,{type:"text",value:m.name||"",onChange:e=>h("name",e)})}),e(I,{label:"Description",className:"mt-2",children:e("textarea",{className:ee.INPUT,value:m.description||"",onChange:e=>h("description",e.target.value)})}),e(I,{label:"Dynamic Collection",className:"mt-2",direction:"row",description:"Dynamic Collection is based on a query vs. users manully adding content.",children:e(ae,{value:m.dynamic||!1,onChange:e=>h("dynamic",e)})}),e(I,{label:"Type",className:"mt-2",description:"This is optional and drives what properties are used to describe a collection",children:e(os,{defaultValue:m.type||null,onChange:e=>{Array.isArray(e)?h("type",e.length>0?e[0].id:null):h("type",e?.id||null)},isClearable:!0})}),e(I,{label:"Allowed Content Types",className:"mt-4",children:e(os,{defaultValue:m.allowed_types||null,onChange:e=>{Array.isArray(e)?h("allowed_types",e.map((e=>e.id))):h("allowed_types",e?[e.id]:[])},isClearable:!0,multiple:!0})})]}),e(ie,{children:e(y,{isDisabled:l,onClick:()=>{m?.name&&m.name.trim()?(m.name=m.name.trim(),m.description&&(m.description=m.description.trim()),null==m.dynamic&&(m.dynamic=!1),c(!0),d.store.collections.create(m).then((e=>{n(),i({title:"Collection created",description:`Collection "${e.name}" created successfully`,status:"success",duration:3e3}),r&&a(`/collections/${e.id}`),s&&s(e.id)})).catch((e=>{i({title:"Failed to create collection",description:e.message,status:"error",duration:5e3})})).finally((()=>c(!1)))):i({title:"Name is required",description:"Please provide a name for the collection",status:"error",duration:5e3})},children:"Create Collection"})})]})}function ds({isOpen:n,onClose:r}){return t(Q,{onClose:r,isOpen:n,children:[e(Y,{children:"Create a Collection"}),e(cs,{onClose:r})]})}function ms({}){const{client:r}=ke(),s=f(),[a,i]=o(),[l,d]=o(!0),[m,u]=o(!1),{data:h,error:p,refetch:g}=M((()=>r.store.collections.list()),[]);if(c((()=>{(h||p)&&d(!1)}),[h,p]),p)return e(K,{title:"Collections fetch failed",children:p.message});return t(n,{children:[h&&(h.length>0?t(q,{className:"w-full",children:[e("thead",{children:t("tr",{children:[e("th",{children:"Name"}),e("th",{children:"Type"}),e("th",{children:"Created"}),e("th",{})]})}),e(B,{columns:4,isLoading:l,children:h.map((n=>t(le,{children:[e("td",{children:t("div",{className:"flex items-center gap-2",children:[us(n.dynamic),e(ft,{href:`/collections/${n.id}`,children:n.name})]})}),e("td",{children:n.type?.name||"-"}),e("td",{children:yt(n.created_at).fromNow()}),e("td",{className:"text-right",children:e(y,{variant:"destructive",size:"sm",onClick:()=>i(n.id),children:e(nt,{className:"size-4"})})})]},n.id)))})]}):e(oe,{title:"No Collections",buttonLabel:"New Collections",onClick:()=>u(!0),children:"Get started by creating a new Collections."})),e(ds,{isOpen:m,onClose:()=>u(!1)}),e(ce,{isOpen:!!a,title:"Delete Collection",content:"Are you sure you want to delete this collection? This action cannot be undone.",onConfirm:async()=>{if(a)try{await r.store.collections.delete(a),s({title:"Collection deleted",status:"success",duration:3e3}),g()}catch(e){console.error("Failed to delete collection:",e),s({title:"Failed to delete collection",description:e.message||"An error occurred",status:"error",duration:5e3})}finally{i(void 0)}},onCancel:()=>i(void 0)})]})}function us(t){const n=t?"Dynamic Collection":"Static Collection",r=e(t?rt:st,{className:"size-5"});return e(F,{description:n,className:"mr-2",children:r})}function hs({objects:n,isLoading:r}){const s=bt();return e("div",{children:t(q,{className:"w-full",children:[e("thead",{children:t("tr",{children:[e("th",{children:"Name"}),e("th",{children:"Strict Mode"}),e("th",{children:"Semantic Chunking"}),e("th",{children:"Updated At"})]})}),e(B,{isLoading:r,columns:3,children:n?.map((n=>t("tr",{onClick:()=>s(`/types/${n.id}`),className:"cursor-pointer hover:bg-muted",children:[e("td",{children:n.name}),e("td",{children:n.strict_mode?"Yes":"No"}),e("td",{children:n.is_chunkable?"Yes":"No"}),e("td",{children:yt(n.updated_at).fromNow()})]},n.id)))})]})})}yt.extend(Ut),yt.extend(Ut);class ps{client;limit;result=new J({objects:[],isLoading:!1});query={};constructor(e,t=100){this.client=e,this.limit=t}get objects(){return this.result.value.objects}get error(){return this.result.value.error}get isRunning(){return this.result.value.isLoading}getFilterValue(e){return this.query[e]}setFilterValue(e,t){this.query[e]=t,this.search()}reset(e=!1){this.result.value={objects:[],isLoading:e}}_updateRunningState(e){const t=this.result.value;this.result.value={objects:t.objects,isLoading:e,error:t.error}}async _search(e=!1){if(this.isRunning)return Promise.resolve(!1);this.result.value={isLoading:!0,objects:e?this.objects:[]};const t=this.limit,n=this.objects.length;return this.client.types.list({limit:t,offset:n,query:this.query}).then((async e=>(this.result.value={isLoading:!1,objects:this.objects.concat(e)},!0))).catch((e=>{throw this.result.value={error:e,isLoading:!1,objects:this.objects},e}))}search(){return this.isRunning?Promise.resolve(!1):this._search(!1)}loadMore(){return this.isRunning?Promise.resolve(!1):this._search(!0)}}const gs=d(void 0);function fs(){return m(gs)}function bs(){const e=fs();return{...H(e.result),search:e}}function ys(){return fs().objects.length}function xs({title:n,isOpen:r,onClose:s,okLabel:a,initialPayload:i}){const l=f(),[c,d]=o(i?.name),[m,u]=o(i?.description),[h,p]=o(i?.strict_mode??!1);return t(_,{isOpen:r,onClose:()=>s(),children:[e(j,{children:n}),e(P,{className:"pt-0",children:t("div",{className:"h-full flex flex-col gap-4 content-between",children:[t("div",{children:[e("label",{className:"block text-sm font-medium text-muted",children:"Name"}),e($,{value:c,onChange:d})]}),t("div",{children:[e("label",{className:"block text-sm font-medium text-muted",children:"Description"}),e(de,{value:m,onChange:u})]})]})}),e(E,{children:t("div",{className:"flex justify-end gap-4",children:[e(y,{variant:"secondary",onClick:()=>s(),children:"Cancel"}),e(y,{variant:"primary",onClick:()=>(()=>{if(!c)return void l({status:"error",title:"Name is required",duration:5e3});s({name:c,description:m,strict_mode:h}).then((()=>s())),d(void 0),u(void 0),p(!1)})(),children:a})]})})]})}var vs;function ws({isDirty:n=!1}){const r=ke(),{store:s}=r,a=f(),[i,l]=o(!1),{search:d,isLoading:m,error:h,objects:p}=bs(),[g,b]=o(""),y=te(g,500),x=u(null);G(x,(()=>{i&&d.loadMore()}),{deps:[i]}),c((()=>{d.search().then((()=>l(!0)))}),[]),c((()=>{d.query.name=g,d.search().then((()=>l(!0)))}),[y]);const[v,w]=o(void 0);c((()=>{d.query.chunkable=v?"Yes"==v:void 0,d.search().then((()=>l(!0)))}),[v]),c((()=>{n&&i&&d.search().then((()=>l(!0)))}),[n]);const[N,k]=o(!1);if(h)return e(K,{title:"Failed to fetch ObjectTypes",children:h.message});return t("div",{className:"flex flex-col gap-4 h-full",children:[t("div",{className:"flex gap-4",children:[e($,{placeholder:"Filter by Name",value:g,onChange:b}),e(D,{className:"w-60",isClearable:!0,options:Object.values(vs),value:v,onChange:e=>{w(e)},placeholder:"Is Chunkable"})]}),t("div",{className:"flex-1",children:[m||0!==p?.length?e(hs,{objects:p,isLoading:m}):e(oe,{title:"No Type",buttonLabel:"Create Type",onClick:()=>{k(!0)},children:"Get started by creating a new Type."}),e(xs,{okLabel:"Create",title:"Create Type",isOpen:N,onClose:async e=>e?s.types.create(e).then((async()=>{a({status:"success",title:"Type created",duration:2e3}),r.reloadTypes(),d.search().then((()=>l(!0)))})).catch((e=>{a({status:"error",title:"Error creating type",description:e.message,duration:5e3})})):(k(!1),Promise.resolve())})]})]})}!function(e){e.true="Yes",e.false="No"}(vs||(vs={}));const Ns=[Ft,zt()];function ks({objectType:n,onSchemaUpdate:r}){const{store:s}=ke(),a=f(),[i,c]=o(!1),d=St(n.object_schema),m=u(void 0),[h,p]=o(!1),g=l((()=>function(e){if(!e)return"";return JSON.stringify(e,null,2)}(d.schema)),[d]),b=()=>{if(m.current){const e=m.current.getValue();try{const t=function(e){if(!e?.trim())return;return JSON.parse(e.trim())}(e);d.replaceSchema(t)}catch(e){return a({status:"error",title:"Invalid JSON Schema",description:e.message,duration:5e3}),!1}}return!0};return t("div",{className:"mx-2 my-2 rounded-2xl border border-solid shadow-md border-spacing-2",children:[t("div",{className:"flex items-center rounded-t-md border-b gap-x-2 py-2 pl-4 pr-2",children:[e("div",{className:"text-base font-semibold",children:"Schema Editor"}),e("div",{children:e(y,{variant:"outline",size:"sm",onClick:()=>{h&&!b()||p((e=>!e))},children:h?"Edit Schema":"Edit Json"})}),e("div",{className:"ml-auto flex gap-x-2",children:e(y,{isLoading:i,variant:"outline",size:"sm",onClick:()=>{h&&!b()||(c(!0),s.types.update(n.id,{object_schema:d.schema}).then((()=>{r(d),a({status:"success",title:"Schema updated",description:"The schema has been updated successfully",duration:2e3})})).catch((e=>{a({status:"error",title:"Failed to update schema",description:e.message,duration:5e3})})).finally((()=>{c(!1)})))},children:"Save Changes"})})]}),e("div",{className:"px-4 py-2",children:h?e(_t,{value:g,extensions:Ns,editorRef:m}):e(jt,{schema:d})})]})}function Cs({children:t,limit:n,name:r,chunkable:s}){const{store:a}=ke(),i=l((()=>{const e=new ps(a,n);return e.query.name=r,e.query.chunkable=s,e}),[n]);return e(gs.Provider,{value:i,children:t})}function Ss({isOpen:n,onClose:r,title:s="Select Content Type",children:a,initialSelectedType:i=null,confirmLabel:l="Select Type",allowNone:c=!0}){const{typeRegistry:d}=ke(),[m,u]=o(i),h=d?.types||[],p=()=>{r(void 0)};return t(_,{isOpen:n,onClose:p,className:"w-full max-w-xl mx-auto",children:[e(j,{children:s}),t(P,{className:"p-6",children:[a,t("div",{className:"mb-4 mt-4",children:[t("label",{className:"block text-sm font-medium mb-2",children:["Content Type ",c&&e("span",{className:"text-gray-500 font-normal",children:"(Optional)"})]}),e(D,c?{options:h,value:m,optionLabel:e=>e?e.name:"Select a content type",placeholder:"Select a content type or leave empty for automatic detection",onChange:e=>u(e||null),filterBy:"name",isClearable:!0}:{options:h,value:m,optionLabel:e=>e?e.name:"Select a content type",placeholder:"Select a content type",onChange:e=>u(e||null),filterBy:"name"}),c&&t("div",{className:"mt-2 text-sm text-blue-600 flex items-center",children:[e(Be,{className:"h-4 w-4 mr-1"}),t("span",{children:[e("strong",{children:"Type selection is optional."})," Leave empty to let Vertesia choose the appropriate type"]})]})]}),m?t("div",{className:"text-sm text-gray-500 bg-gray-50 p-3 rounded-md mb-4",children:[e("div",{className:"font-medium",children:m.name}),m.description&&e("div",{className:"mt-1",children:m.description})]}):c&&t("div",{className:"text-sm text-blue-600 bg-blue-50 p-3 rounded-md mb-4",children:[e("div",{className:"font-medium",children:"Automatic Type Detection"}),t("div",{className:"mt-1",children:["Vertesia will analyze each file's content and automatically select the most appropriate type.",e("br",{}),e("span",{className:"mt-1 block font-medium",children:"This is recommended for most uploads."})]})]})]}),t(E,{children:[e(y,{variant:"ghost",onClick:p,children:"Cancel"}),e(y,{onClick:()=>{r(m?.id??null)},children:m?`${l}: ${m.name}`:c?"Let Vertesia Choose":l})]})]})}const _s=[Ft,zt()];function js({objectType:n,onLayoutUpdate:r}){const s=f(),[a,i]=o(!1),{store:c}=ke(),d=u(void 0),m=l((()=>Ps(n.table_layout)),[n.table_layout]),h=(e,t)=>{s({status:"error",title:e,description:t,duration:5e3})};return t("div",{className:"mx-2 my-2 rounded-2xl border border-solid shadow-xs",children:[t("div",{className:"flex items-center rounded-t-md border-b gap-x-2 py-2 pl-4 pr-2",children:[e("div",{className:"text-base font-semibold ",children:"Table Layout Editor"}),e("div",{className:"ml-auto flex gap-x-2",children:e(y,{isLoading:a,variant:"outline",size:"sm",onClick:()=>{if(!d.current)return;const e=d.current.getValue();let t;if(e)try{t=JSON.parse(e)}catch(e){return h("Invalid JSON",e.message)}else t=null;return Array.isArray(t)?t.some((e=>!e||!e.name||!e.field))?h("Invalid JSON","A table layout entry must contain the following properties:] {field, name, converter?}"):(i(!0),void c.types.update(n.id,{table_layout:t}).then((e=>{s({status:"success",title:"Table Layout updated",description:"The table layout has been updated successfully",duration:2e3}),r(e.table_layout)})).catch((e=>{s({status:"error",title:"Failed to update table layout",description:e.message,duration:5e3})})).finally((()=>{i(!1)}))):h("Invalid JSON","The table layout must be an array")},children:"Save Changes"})})]}),e("div",{className:"px-4 py-2",children:e(_t,{value:m,extensions:_s,editorRef:d})})]})}function Ps(e){return e?JSON.stringify(e,null,2):"[\n\n]"}const Ts=[Ft,zt()];function Is({refetch:n,collection:r}){const s=r.type?.id,a=u(void 0),i=f(),{client:c}=ke(),[d,m]=o(!1),[h,p]=o({name:r.name,description:r.description||"",query:r.query?JSON.stringify(r.query,null,2):"",tags:r.tags||[],type:r.type?.id||"",allowed_types:r.allowed_types||[]}),g=l((()=>Ps(r.table_layout)),[r.table_layout]),b=(e,t)=>{p({...h,[e]:t})};return t("div",{className:"flex flex-col gap-4 py-2",children:[e(I,{label:"Name",required:!0,children:e($,{value:h.name,onChange:e=>b("name",e)})}),e(I,{label:"Description",children:e("textarea",{className:ee.INPUT,value:h.description,onChange:e=>b("description",e.target.value)})}),r.dynamic&&e(I,{label:"Query",description:"Define the query to fetch dynamic content for this collection.",children:e("textarea",{className:ee.INPUT,value:h.query,onChange:e=>b("query",e.target.value)})}),e(I,{label:"Table Layout",description:"Define how the collection should be displayed in tables.",children:e(_t,{className:"border-1 rounded-md border-border",value:g,extensions:Ts,editorRef:a})}),e(I,{label:"Type",children:e(os,{defaultValue:h.type||null,onChange:e=>{Array.isArray(e)?b("type",e.length>0?e[0].id:null):b("type",e?.id||null)},isClearable:!0})}),e(I,{label:"Allowed Content Types",children:e(os,{defaultValue:h.allowed_types||null,onChange:e=>{Array.isArray(e)?b("allowed_types",e.map((e=>e.id))):b("allowed_types",e?[e.id]:[])},isClearable:!0,multiple:!0})}),e(y,{size:"lg",className:"w-min my-4",isDisabled:d,onClick:()=>{const e=h.query?JSON.parse(h.query):void 0,t={name:h.name,description:h.description,query:e,tags:h.tags,type:h.type,allowed_types:h.allowed_types};let s;if(t.name||(s="Name is required"),t.type||(t.type=null),s&&i({title:"Validation failed",description:s,status:"error",duration:5e3}),a.current){const e=a.current.getValue();if(e)try{t.table_layout=JSON.parse(e)}catch(e){return void i({title:"Invalid Table Layout",description:e.message,status:"error",duration:5e3})}else t.table_layout=null}m(!0),c.store.collections.update(r.id,t).then((()=>{n(),i({title:"Collection updated",description:"Collection has been updated successfully",status:"success",duration:3e3})})).catch((e=>{i({title:"Failed to update collection",description:e.message,status:"error",duration:5e3})})).finally((()=>{m(!1)}))},children:"Save Metadata"}),s&&e($s,{typeId:s,collection:r})]})}function $s({typeId:t,collection:n}){const{client:r}=ke(),{data:s,error:a}=M((()=>r.store.types.retrieve(t)),[t]);return a?e(K,{title:"Failed to load type",children:a.message}):e(Ls,{title:"Properties",children:s&&e(Es,{collection:n,schema:s.object_schema})})}function Es({schema:t={},collection:n}){const{client:r}=ke(),s=f(),a=l((()=>new Pt(t,n.properties||{})),[t,n]),[i,c]=o(!1);return e(Tt,{object:a,onSubmit:e=>{const t={properties:e||{}};c(!0),r.store.collections.update(n.id,t).then((()=>{s({title:"Collection properties updated",description:"Collection has been updated successfully",status:"success",duration:3e3})})).catch((e=>{s({title:"Failed to update collection properties",description:e.message,status:"error",duration:5e3})})).finally((()=>{c(!1)}))},children:e(y,{size:"lg",isLoading:i,className:"my-4",variant:"primary",type:"submit",children:"Save Properties"})})}function Ls({children:n,title:r}){return t("div",{className:"my-4",children:[e("div",{className:"text-lg text-gray-700 font-semibold border-b border-b-gray-300 py-2 mb-4",children:r}),n]})}function As({onChange:t,value:n,disabled:r=!1,className:s}){const{client:a}=ke(),{data:i,error:l}=M((()=>a.store.collections.list({dynamic:!1})),[]);if(l)return e(K,{title:"Collection fetch failed",children:l.message});const o=n?i?.find((e=>e.id===n)):void 0;return e(se,{filterBy:"name",value:o,onChange:e=>{t(e?.id,e)},placeholder:"Select a collection",options:i||[],optionLabel:e=>e.name,by:"id",className:s,disabled:r})}function Us({action:n,objectIds:r,children:s}){const{store:a}=ke(),i=f(),[l,c]=o(!1),d=h((()=>(c(!0),Promise.resolve(!0))),[]);ea(n.id,d);return t("div",{children:[s,e(Ss,{isOpen:l,onClose:e=>{c(!1),void 0!==e&&a.runOperation({name:"change_type",ids:r,params:{typeId:e}}).then((e=>{i({status:"success",title:"Change Type",description:`Change the type of ${r.length} objects is ${"in_progress"===e.status?"in progress":"completed"}`,duration:2e3})})).catch((e=>{i({status:"error",title:"Error changing type",description:e.message,duration:5e3})}))},title:"Change Content Type",confirmLabel:"Change Type",children:t("div",{className:"text-sm flex flex-col gap-x-2",children:[t("p",{children:["Choose a new Content Type for the selected object",r.length>1?"s":" ","or let the system choose or generate a type based on the content."]}),t("p",{className:"pt-2 text-xs",children:["Note: This action will raise the ",e("code",{children:"change_type"})," event and will trigger the standard intake workflows which may reset the object properties."]})]})})]})}const Os={id:"changeType",name:"Change Content Type",description:"Change the Content Type of the selected documents",confirm:!1,component:Us};function zs({action:r,callback:s,children:a}){const[i,l]=o(!1),c=r.confirmationText||`Are you sure you want to ${r.name}?`,d=h((e=>r.confirm?(l(!0),Promise.resolve(!0)):s(e)),[r.confirm,s]),m=ea(r.id,d);return t(n,{children:[a,e(ce,{onConfirm:()=>{l(!1),s({...m.params,action:r})},onCancel:()=>l(!1),title:"Are you sure?",content:c,isOpen:i})]})}function Fs({action:t,objectIds:n,children:r}){const s=Zs(),a=f(),{client:i}=ke(),l=jr(),o=bt(),c=h((()=>n&&n.length?Promise.all(n.map((e=>i.store.objects.delete(e)))).then((e=>{const t=e.length>1?"s":"";if(a({status:"success",title:`${e.length} object${t} deleted`,description:`Objects ${e.map((e=>e.id)).join(", ")} have been deleted`,duration:2e3}),l){s.params?.selection?.removeAll();const e=JSON.parse(JSON.stringify(l.facets));n.length===e._value.total&&l.resetFacets(),l.search()}else o("/objects")})).catch((e=>{a({status:"error",title:"Error deleting objects",description:e.message,duration:5e3})})):(a({status:"error",title:"No objects selected",description:"Please select objects to delete",duration:3e3}),Promise.resolve(!1))),[n]);return e(zs,{action:t,callback:c,children:r})}const Ds={id:"delete",name:"Delete",description:"Delete the selected objects",confirm:!0,confirmationText:"Are you sure you want to delete the selected objects?",component:Fs,destructive:!0};function Rs({action:t,objectIds:n}){const{store:r}=ke(),s=f(),[a,i]=o(!1),[l,c]=o(!1),d=h((()=>(i(!0),Promise.resolve(!0))),[]),m=ea(t.id,d);return e("div",{children:e(rs,{isExporting:l,isOpen:a,onClose:(e,t)=>{if(e&&(t||n.length>0)){c(!0);const a=m.params?.search?.query||{},l=m.params?.search?.result?.value?.objects?.map((e=>e.id))||void 0,o=async e=>r.objects.list({query:{parent:e}}).then((e=>e.map((e=>e.id))));(async()=>t?l?a.vector?l:[]:0===n.length?[]:(await o(n[0])).concat(n):n)().then((l=>{r.objects.exportProperties({objectIds:l,type:e,query:t&&!a.vector?a:{type:a.type}}).then((r=>{let a;if(e===ns.CSV)a=new Blob([r.data],{type:r.type});else if(e===ns.JSON)a=new Blob([JSON.stringify(r.data)],{type:r.type});else{const e=r.data;a=new Blob([new Uint8Array(e.data)],{type:r.type})}const i=window.URL.createObjectURL(a),l=document.createElement("a");l.download=r.name,l.href=i,l.click(),s({status:"success",title:"Export Properties",description:t?"Export the properties of all objects completed":`Export the properties of ${n.length} object${n.length>1?"s":""} is completed`,duration:2e3})})).catch((e=>{s({status:"error",title:"Error Export Properties",description:e.message,duration:5e3})})).finally((()=>{c(!1),i(!1)}))}))}else i(!1)}})})}const Ms={id:"exportProperties",name:"Export Properties",description:"Export all Object Properties",confirm:!1,component:Rs};function Vs({action:t,objectIds:n,collectionId:r}){const s=Zs(),a=f(),{client:i}=ke(),l=jr(),o=h((()=>n&&n.length?r?i.store.collections.deleteMembers(r,n).then((()=>{const e=n.length>1?"s":"";a({status:"success",title:`${n.length} object${e} removed from collection`,description:"Objects have been removed from the collection",duration:2e3}),l&&(s.params?.selection?.removeAll(),l.search())})).catch((e=>{a({status:"error",title:"Error removing objects from collection",description:e.message,duration:5e3})})):(a({status:"error",title:"No collection context",description:"Cannot remove objects: no collection specified",duration:3e3}),Promise.resolve(!1)):(a({status:"error",title:"No objects selected",description:"Please select objects to remove from collection",duration:3e3}),Promise.resolve(!1))),[n,r]);return e(zs,{action:t,callback:o})}const qs={id:"removeFromCollection",name:"Remove from Collection",description:"Remove the selected objects from this collection",confirm:!0,confirmationText:"Are you sure you want to remove the selected objects from this collection?",component:Vs,destructive:!0};function Ws({action:t,objectIds:n,collectionId:r}){const s=f(),{client:a}=ke(),[i,l]=o(!1),c=h((()=>(l(!0),Promise.resolve(!0))),[]);return ea(t.id,c),e(Js,{isOpen:i,onClose:e=>{if(l(!1),e)return a.store.workflows.rules.execute(e,n,{collection_id:r}).then((()=>{s({title:"Workflow started",status:"success",duration:3e3})})).catch((e=>{s({title:"Error starting workflow",status:"error",description:e.message,duration:9e3})}))}})}const Bs={id:"startWorkflow",name:"Start Workflow",description:"Start an workflow on the selected objects",confirm:!1,hideInList:!0,component:Ws};function Js({isOpen:n,onClose:r}){return t(Q,{onClose:()=>r(void 0),isOpen:n,className:"",children:[e(Y,{children:"Start a Workflow by Rule"}),e(Gs,{onClose:r})]})}function Hs(n){return{label:t("div",{children:[e("div",{children:n.name}),e("div",{className:"text-sm text-muted",children:n.description})]}),reverse:!0}}function Gs({onClose:n}){const[r,s]=o(void 0),a=Zs();return t("div",{children:[t(X,{children:[e("div",{className:"pb-2",children:"Choose a workflow rule to start:"}),e("div",{className:"max-h-[420px] overflow-y-scroll border-border border rounded-md",children:e(me,{options:a.wfRules,optionLayout:Hs,onChange:e=>{s(e)},value:r})})]}),t(ie,{children:[e(y,{variant:"secondary",onClick:()=>n(),children:"Cancel"}),e(y,{onClick:()=>{r&&n(r.id)},isDisabled:!r,children:"Start"})]})]})}class Ks{params;allActions=[Ms,Os,Bs,ra,Ds,qs];wfRules=[];callbacks={};startWorkflow;constructor(e){this.params=e}get actions(){return!!this.params.selection?.collectionId?this.allActions.filter((e=>"addToCollection"!==e.id&&"delete"!==e.id)):this.allActions.filter((e=>"removeFromCollection"!==e.id))}async loadWorkflows(){return this.params.client.workflows.rules.list().then((e=>{this.wfRules=e.map((e=>({id:e.id,name:e.name,description:e.description,confirm:!1,isWorkflow:!0,component:Ws}))).sort(((e,t)=>e.name.localeCompare(t.name)))})),this.wfRules}registerCallback(e,t){return this.callbacks[e]=t,()=>{delete this.callbacks[e]}}unregisterCallback(e){delete this.callbacks[e]}findAction(e){let t=this.allActions.find((t=>t.id===e));return t||(t=this.wfRules.find((t=>t.id===e))),t}async run(e){const t=this.findAction(e);if(!t)throw new Error(`Action ${e} not found`);const n={...this.params,action:t},r=this.callbacks[e];if(r)return r(n);throw new Error("No action callback set")}}const Qs=d(void 0);function Ys({children:n}){const r=gr(),s=f(),{client:a}=ke(),i=jr(),{data:o,error:c}=M((()=>a.workflows.rules.list().then((e=>e.map((e=>({id:e.id,name:e.name,description:e.description,confirm:!1,isWorkflow:!0,component:Ws}))).sort(((e,t)=>e.name.localeCompare(t.name)))))),[]),d=l((()=>{const e=new Ks({selection:r,toast:s,client:a,search:i});return e.wfRules=o,e}),[r,o]);return c?e(K,{title:"Failed to fetch workflows",children:c.message}):d&&t(Qs.Provider,{value:d,children:[e(Xs,{}),n]})}function Xs({}){const t=Zs(),n=t.params.selection,r=n.getObjectId(),s=n.isSingleSelection()&&r?[r]:n.getObjectIds();return e("div",{style:{display:"none"},children:t.allActions.map((t=>e(t.component,{action:t,objectIds:s,collectionId:n.collectionId},t.id)))})}function Zs(){const e=m(Qs);if(!e)throw new Error("You cannot use useActionContext outside an ActionProvider");return e}function ea(e,t){const n=Zs();return c((()=>n.registerCallback(e,t)),[n,e,t]),n}function ta(e){const t=Zs();return c((()=>(t.startWorkflow=e,()=>{t.startWorkflow=void 0})),[e,t]),t}function na({action:t,objectIds:n}){const[r,s]=o(!1),a=h((()=>(n.length>0&&s(!0),Promise.resolve(!0))),[n]);return ea(t.id,a),r&&e(ue,{children:e(sa,{objectIds:n,isOpen:r,onClose:()=>{s(!1)}})})}const ra={id:"addToCollection",name:"Add to Collection",description:"Add documents to a collection",confirm:!1,component:na};function sa({isOpen:n,onClose:r,objectIds:s}){return t(Q,{isOpen:n,onClose:r,children:[e(Y,{children:"Add to a Collection"}),e(aa,{onClose:r,objectIds:s})]})}function aa({onClose:r,objectIds:s}){const a=f(),{client:i}=ke(),[l,c]=o(),d=({collectionId:e})=>{e&&s?.length&&i.store.collections.addMembers(e,s).then((()=>{a({title:"Add to collection success",status:"success",description:`Added ${s.length} objects to the selected collection`,duration:3e3}),r()})).catch((()=>{a({title:"Add to collection failure",status:"error",description:"Failed to add the selected objects to the collection",duration:5e3})}))};return t(n,{children:[e(X,{children:e(As,{onChange:e=>{c(e)},value:l,className:"mb-4"})}),e(ie,{children:e(y,{isDisabled:!l,onClick:()=>l&&d({collectionId:l}),children:"Add to Collection"})}),t("div",{className:"flex items-center flex-row w-full text-muted",children:[e("hr",{className:"w-full"}),e("div",{className:"px-2 text-xs",children:"OR"}),e("hr",{className:"w-full"})]}),e(cs,{onClose:r,onAddToCollection:e=>d({collectionId:e}),redirect:!1})]})}function ia(){const n=gr(),r=n.size(),s=r>1?"s":"",a=n?.hasSelection(),i=n?.isSingleSelection();return e(Ys,{children:t("div",{className:"flex items-center gap-x-2",children:[a&&!i&&t("div",{className:"flex items-center gap-x-1 shrink-0",children:[t("div",{className:"text-sm nowrap",children:[r," document",s," selected"]}),e(y,{title:"Clear selection",variant:"ghost",onClick:()=>{n?.removeAll()},children:e(Ce,{className:"size-4"})})]}),e(ma,{selection:n,children:e(y,{variant:"ghost",alt:"More action",size:"sm",children:e(at,{size:16})})}),a&&e(la,{selection:n})]})})}function la({}){return e(ca,{})}function oa({collectionId:r}){const[s,a]=o([]),i=gr(),l=i?.hasSelection();return!l&&t(n,{children:[e(y,{onClick:()=>(()=>{const e=document.createElement("input");e.type="file",e?.click(),e.onchange=e=>{const t=e.target.files;t&&a(Array.from(t))}})(),children:"Upload"}),e(Ar,{collectionId:r??"",isOpen:s.length>0,onClose:()=>a([]),files:s,title:"Upload Files",onUploadComplete:e=>{e&&e.success&&a([])},children:e("div",{className:"text-sm",children:"Select the associated Content Type, or let the system choose or generate the type based on the content."})})]})}function ca(){const t=Zs();return t.params.selection.hasSelection()&&e(y,{onClick:()=>t.run(Bs.id),children:"Start Workflow"})}function da(e){return{label:e.name,className:r("flex-1 px-2 py-2 hover:bg-accent nowrap",e.destructive?"text-destructive":"")}}function ma({selection:n,children:r}){const s=Zs();return t(x,{hover:!0,children:[e(v,{children:r}),e(w,{className:"p-0 w-50",align:"end",sideOffset:6,children:e(ua,{executeAction:e=>{s.run(e.id)},selection:n})})]})}function ua({executeAction:t,selection:n}){const r=Zs(),s=n?.hasSelection()?r.actions.filter((e=>!e.hideInList)):[Ms];return e("div",{className:"rounded-md shadow-md py-2",children:e("div",{className:"px-1 text-sm",children:e(me,{options:s,optionLayout:da,onChange:e=>{t(e)},noCheck:!0})})})}function ha({value:n,onChange:r,onSend:s,disabled:a=!1,isSending:i=!1,isCompleted:l=!1,activeTaskCount:d=0,placeholder:m="Type your message..."}){const h=u(null),[p,g]=o(!1);c((()=>{!a&&l&&h.current?.focus()}),[a,l]);return t("div",{className:"p-3 border-t border-muted flex-shrink-0",style:{minHeight:"90px"},children:[t("div",{className:"flex items-center space-x-2",children:[t("div",{className:"flex flex-1 space-x-1",children:[e($,{ref:h,value:n,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),s())},onChange:r,disabled:a||i,placeholder:m,className:"pr-12 py-2.5"}),e(y,{variant:"ghost",className:"rounded-full",disabled:!l,onClick:()=>g(!0),alt:"Link Object",children:e(it,{className:"size-4"})})]}),t(y,{onClick:s,disabled:a||i||!n.trim(),className:"px-4 py-2.5",children:[i?e(A,{size:"sm",className:"mr-2"}):e(lt,{className:"size-4 mr-2"})," Send"]})]}),e("div",{className:"text-xs text-muted mt-2 text-center",children:d>0?t("div",{className:"flex items-center justify-center",children:[e(ot,{className:"h-3 w-3 mr-1 text-attention"}),t("span",{children:["Agent has ",d," active workstream",1!==d?"s":""," running"]})]}):a?"Agent is processing, you can continue once it completes...":"You can send a message at any time"}),t(Q,{isOpen:p,onClose:()=>g(!1),className:"min-w-[60vw]",children:[e(Y,{children:"Link Object"}),e(X,{className:"pb-6",children:e(Vr,{onChange:e=>{const t=`[${e.properties?.title||e.name||"Object"}](store:${e.id})`,s=n||"",a=h.current?.selectionStart||s.length,i=s.substring(0,a)+t+s.substring(a);r(i),g(!1),setTimeout((()=>{if(h.current){h.current.focus();const e=a+t.length;h.current.setSelectionRange(e,e)}}),100)}})})]})]})}function pa({plan:n,workstreamStatus:r,isVisible:s}){return s?t("div",{className:"border-b border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-900 p-3 shadow-sm transition-all duration-300 ease-in-out transform",children:[e("div",{className:"text-xs font-medium mb-2 text-gray-800 dark:text-gray-200",children:"Agent Plan"}),n.plan&&n.plan.length>0?e("div",{className:"space-y-1.5",children:n.plan.map(((n,s)=>{const a=n.id.toString(),i=n.goal;let l=n.status||"pending";r.has(a)&&(l=r.get(a));let o=Se,c="text-gray-400";return"in_progress"===l?(o=je,c="text-blue-500"):"completed"===l&&(o=Pe,c="text-green-500"),t("div",{className:"flex items-start",children:[e("div",{className:`mr-1.5 mt-0.5 ${c}`,children:e(o,{className:"h-3.5 w-3.5"})}),t("div",{className:"text-xs",children:[e("span",{className:"text-gray-700 dark:text-gray-300",children:i}),e("span",{className:"ml-1 bg-gray-200 dark:bg-gray-700 px-1 py-0.5 rounded text-[10px] font-mono",children:a})]})]},s)}))}):t("div",{className:"text-xs text-gray-500 dark:text-gray-400 italic flex items-center",children:[e(_e,{className:"h-3.5 w-3.5 mr-1.5 text-amber-500"}),"No plan detected yet"]}),r.size>1&&t("div",{className:"mt-3 pt-2 border-t border-gray-200 dark:border-gray-700",children:[e("div",{className:"text-xs font-medium mb-1.5 text-gray-800 dark:text-gray-200",children:"Workstreams"}),e("div",{className:"grid grid-cols-2 gap-1.5",children:Array.from(r.entries()).filter((([e,t])=>{if("main"===e)return!0;if(/^\d+$/.test(e))return!1;if(n?.plan){return!n.plan.find((t=>t.id?.toString()===e))}return!0})).map((([n,r])=>{let s=Se,a="text-gray-400",i="Pending";"in_progress"===r?(s=je,a="text-blue-500",i="In Progress"):"completed"===r&&(s=Pe,a="text-green-500",i="Completed");const l="main"===n?"Main":n;return t("div",{className:"flex items-center",children:[e("div",{className:`mr-1.5 ${a}`,children:e(s,{className:"h-3 w-3"})}),e("span",{className:"text-[10px] font-medium text-gray-600 dark:text-gray-400",children:l}),e("span",{className:"text-[10px] text-gray-500 dark:text-gray-500 ml-1",children:i})]},n)}))})]})]}):null}function ga(t){const{run:n,startWorkflow:r}=t;if(n){const r="runId"in n?n:{runId:n.run_id,workflowId:n.workflow_id};return e(ya,{...t,run:r})}return r?e(ba,{...t}):e(fa,{})}function fa(){return t(he,{status:"info",icon:e(Ie,{className:"size-16 text-muted mb-4"}),children:[e("div",{className:"text-base font-medium text-muted",children:"No agent currently running"}),e("div",{className:"mt-3 text-sm text-muted",children:"Select an interaction and click Start to start an agent"})]})}function ba({initialMessage:n,startWorkflow:r,onClose:s,isModal:a=!1,placeholder:i="Type your message...",startButtonText:l="Start Agent",title:d="Start New Conversation"}){const[m,h]=o(""),[p,g]=o(!1),[b,x]=o(),v=f(),w=u(null);c((()=>{w.current&&w.current.focus()}),[]);const N=async()=>{if(!r)return;const e=m.trim();if(e&&!p){g(!0);try{sessionStorage.removeItem("plan-panel-shown"),v({title:"Starting agent...",status:"info",duration:3e3});const t=await r(e);t&&(x({runId:t.run_id,workflowId:t.workflow_id}),h(""),v({title:"Agent started",status:"success",duration:3e3}))}catch(e){v({title:"Error starting workflow",status:"error",duration:3e3,description:e instanceof Error?e.message:"Unknown error"})}finally{g(!1)}}};return b?e(ya,{onClose:s,isModal:a,initialMessage:n,placeholder:i,run:b,title:d}):t("div",{className:"flex flex-col h-full bg-white dark:bg-gray-900 overflow-hidden border-0",children:[t("div",{className:"flex items-center justify-between py-2 px-3 border-b border-gray-100 dark:border-gray-800 bg-white dark:bg-gray-900",children:[t("div",{className:"flex items-center space-x-2",children:[e("div",{className:"p-1",children:e(ct,{className:"h-3.5 w-3.5 text-gray-400 dark:text-gray-500"})}),e("span",{className:"font-medium text-sm text-gray-700 dark:text-gray-300",children:d})]}),s&&!a&&e(y,{size:"xs",variant:"ghost",onClick:s,title:"Close",className:"text-slate-500 hover:text-slate-700",children:e(Ue,{className:"h-4 w-4"})})]}),t("div",{className:"flex-1 overflow-y-auto px-4 py-6 bg-white dark:bg-gray-900 flex flex-col items-center justify-center",children:[n&&e("div",{className:"px-4 py-3 mb-4 bg-blue-50/80 dark:bg-blue-900/30 border-l-2 border-blue-400 dark:border-blue-500 text-blue-700 dark:text-blue-300 max-w-md",children:n}),t("div",{className:"bg-white dark:bg-slate-800 p-4 max-w-md border-l-2 border-blue-400 dark:border-blue-500",children:[e("div",{className:"text-base text-slate-600 dark:text-slate-300 font-medium",children:"Enter a message to start a conversation"}),t("div",{className:"mt-3 text-sm text-slate-500 dark:text-slate-400",children:["Type your question below and press Enter or click ",l," ","to begin"]})]})]}),t("div",{className:"py-3 px-3 border-t border-gray-100 dark:border-gray-800 bg-white dark:bg-gray-900",children:[t("div",{className:"flex items-center gap-2",children:[e("div",{className:"flex-1",children:e("input",{ref:w,value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),N())},placeholder:i,disabled:p,className:"w-full py-2 px-3 text-sm border border-gray-200 dark:border-gray-700 dark:bg-gray-800 dark:text-white focus:border-gray-300 dark:focus:border-gray-600 focus:ring-0 rounded-md"})}),t(y,{onClick:N,disabled:!m.trim()||p,className:"px-3 py-2 bg-gray-800 dark:bg-gray-700 hover:bg-gray-700 dark:hover:bg-gray-600 text-white text-xs rounded-md transition-colors",children:[p?e(A,{size:"sm",className:"mr-1.5"}):e(lt,{className:"h-3.5 w-3.5 mr-1.5"}),l]})]}),e("div",{className:"text-xs text-gray-400 dark:text-gray-500 mt-2 text-center",children:"Type a message to start the conversation"})]})]})}function ya({run:n,title:r,interactive:s=!0,onClose:a,isModal:i=!1,placeholder:d="Type your message...",resetWorkflow:m}){const{client:h}=ke(),p=u(null),[g,b]=o([]),[y,x]=o(!1),[v,w]=o(""),[N,k]=o(!1),[C,S]=o("sliding"),[_,j]=o(!1),[P,T]=o(!1),[I,$]=o([]),[E,L]=o(0),[A,U]=o(new Map),[O,z]=o(0),F=f(),[D,R]=o(s),[M,V]=o(null),q=l((()=>{const e=I[E]||{plan:{plan:[]},timestamp:0},t=A.get(e.timestamp)||new Map;return{plan:e.plan,workstreamStatus:t}}),[I,E,A]);c((()=>{if(!y){const e=setInterval((()=>{z((()=>Math.floor(Math.random()*(on.length-1))))}),4e3);return()=>clearInterval(e)}}),[y]);c((()=>(b([]),$([]),L(0),U(new Map),T(!1),V(null),(async()=>{try{const e=await h.store.workflows.getRunDetails(n.runId,n.workflowId);V(e.status)}catch(e){console.error("Failed to check workflow status:",e)}})(),h.store.workflows.streamMessages(n.workflowId,n.runId,(e=>{e.message&&b((t=>t.find((t=>t.timestamp===e.timestamp))?t:(function(e,t){const n="number"==typeof t.timestamp?t.timestamp:new Date(t.timestamp).getTime(),r=e.findIndex((e=>("number"==typeof e.timestamp?e.timestamp:new Date(e.timestamp).getTime())>n));-1===r?e.push(t):e.splice(r,0,t)}(t,e),[...t])))})),()=>{b([])})),[n.runId,h.store.workflows]),c((()=>{x(!function(e){if(!e.length)return!0;const t=new Map;if(e.forEach((e=>{const n=cn(e);t.has(n)||t.set(n,[]),t.get(n).push(e)})),console.log("[isInProgress] Workstreams found:",Array.from(t.keys())),1===t.size&&!t.has("main")){const e=t.keys().next().value||"unknown";console.log(`[isInProgress] Only one workstream found (${e}), treating as main`);const n=t.get(e),r=n[n.length-1];return console.log(`[isInProgress] Last message type in only workstream: ${r.type}`),[ge.COMPLETE,ge.IDLE,ge.REQUEST_INPUT].includes(r.type)?(console.log("[isInProgress] Only workstream is completed"),!1):(console.log("[isInProgress] Only workstream is still in progress"),!0)}if(t.has("main")){const e=t.get("main");if(0===e.length)return console.log("[isInProgress] Main workstream exists but has no messages, still in progress"),!0;const n=e[e.length-1];return console.log(`[isInProgress] Last message type in main workstream: ${n.type}`),[ge.COMPLETE,ge.IDLE,ge.REQUEST_INPUT].includes(n.type)?(console.log("[isInProgress] Main workstream is completed"),!1):(console.log("[isInProgress] Main workstream is still in progress"),!0)}console.log("[isInProgress] Multiple workstreams but no main, checking if any are still active");for(const[e,n]of t.entries())if(n.length>0){const t=n[n.length-1];if(![ge.COMPLETE,ge.IDLE,ge.REQUEST_INPUT].includes(t.type))return console.log(`[isInProgress] Workstream ${e} is still active`),!0}return console.log("[isInProgress] All workstreams are completed"),!1}(g)),0===I.length&&T(!1)}),[g,I.length]),c((()=>{if(1===I.length&&!P&&!sessionStorage.getItem("plan-panel-shown")){const e=setTimeout((()=>{T(!0),sessionStorage.setItem("plan-panel-shown","true")}),500);return()=>clearTimeout(e)}g.forEach((e=>{if(e.type===ge.PLAN)try{console.log("PLAN message received:",e.type);let t=null;if(e.details&&"object"==typeof e.details&&e.details.plan&&Array.isArray(e.details.plan)&&(console.log("Valid plan array found in message.details.plan"),t={plan:e.details.plan}),t){const n="number"==typeof e.timestamp?e.timestamp:new Date(e.timestamp).getTime();if(-1===I.findIndex((e=>e.timestamp===n))&&t){console.log("Adding new plan to plans array");const e={plan:t,timestamp:n};console.log("Adding plan to plans array:",e),$((t=>{const n=[e,...t];return console.log("New plans array:",n),n})),L(0),console.log("Setting showSlidingPanel to true"),T(!0);const r=new Map;r.set("main","in_progress"),Array.isArray(t.plan)&&t.plan.forEach((e=>{if(e&&"object"==typeof e&&e.id){const t=e.id.toString();r.set(t,e.status||"pending")}})),U((e=>{const t=new Map(e);return t.set(n,r),t}))}}}catch(e){console.error("Failed to parse plan from message:",e)}e.type===ge.UPDATE&&e.details&&e.details.updates&&Array.isArray(e.details.updates)&&console.log("Ignoring UPDATE message with details.updates - waiting for PLAN message with full plan")}));const e=g[g.length-1];e&&R(!!s||e.type===ge.REQUEST_INPUT)}),[g,I,E]);const W=r||n.workflowId.split(":")[2]||"Agent Conversation";return t("div",{className:"flex flex-col h-full min-h-0 "+(i?"rounded-lg overflow-hidden":""),children:[e(yn,{title:W,isCompleted:y,onClose:a,isModal:i,run:n,viewMode:C,onViewModeChange:S,showPlanPanel:P,hasPlan:I.length>0,onTogglePlanPanel:()=>{T(!P),P||sessionStorage.setItem("plan-panel-shown","true")},onDownload:async()=>{try{const e=await async function(e,t){return e.files.getDownloadUrl(`agents/${t}/conversation.json`).then((e=>e.url))}(h,n.runId);e&&window.open(e,"_blank")}catch(e){console.error("Failed to download conversation",e),F({status:"error",title:"Failed to download conversation",duration:3e3})}},onCopyRunId:()=>{navigator.clipboard.writeText(n.runId),F({status:"success",title:"Run ID copied",duration:2e3})},resetWorkflow:m}),_&&!P&&I.length>0&&e(pa,{plan:q.plan,workstreamStatus:q.workstreamStatus,isVisible:!0}),0!==g.length||y?e(hn,{messages:g,bottomRef:p,viewMode:C,isCompleted:y,plan:q.plan,workstreamStatus:q.workstreamStatus,showPlanPanel:P,onTogglePlanPanel:()=>{console.log("Toggle plan panel called, current state:",P),T(!P)},plans:I,activePlanIndex:E,onChangePlan:e=>L(e),taskLabels:q.plan.plan?.reduce(((e,t)=>(t.id&&t.goal&&e.set(t.id.toString(),t.goal),e)),new Map)}):e("div",{className:"flex-1 flex flex-col items-center justify-center h-full text-center py-6 bg-white dark:bg-gray-900",children:t("div",{className:"bg-white dark:bg-slate-800 p-5 max-w-md border border-blue-200 dark:border-blue-900/50 rounded-lg shadow-sm",children:[t("div",{className:"flex items-center space-x-3 mb-3",children:[e(tn,{size:"sm",color:"blue"}),e("div",{className:"text-sm text-slate-600 dark:text-slate-300 font-medium",children:on[O]})]}),e("div",{className:"mt-4 flex justify-center",children:e(en,{color:"blue",className:"mt-1"})})]})}),M&&("RUNNING"!==M?t(he,{status:"COMPLETED"===M?"success":"done",icon:null,className:"flex-shrink-0 m-2",children:["This Workflow is ",M]}):D&&e(ha,{value:v,onChange:w,onSend:()=>{const e=v.trim();e&&!N&&(k(!0),w(""),h.store.workflows.sendSignal(n.workflowId,n.runId,"UserInput",{message:e}).then((()=>{x(!1),F({status:"success",title:"Message Sent",duration:2e3})})).catch((e=>{F({status:"error",title:"Failed to Send Message",description:e instanceof Error?e.message:"Unknown error",duration:3e3})})).finally((()=>{k(!1)})))},disabled:!1,isSending:N,isCompleted:y,activeTaskCount:(()=>{if(!g.length)return 0;const e=new Map;g.forEach((t=>{const n=cn(t);"main"!==n&&"all"!==n&&(e.has(n)||e.set(n,[]),e.get(n).push(t))}));let t=0;for(const[n,r]of e.entries())if(r.length>0){const e=r[r.length-1];[ge.COMPLETE,ge.IDLE].includes(e.type)||t++}return t})(),placeholder:d}))]})}function xa({children:t,fallback:n}){return va?e(va,{fallback:n,children:t}):e(Dt,{FallbackComponent:n,children:t})}let va=null;function wa(e){va=e}function Na({children:t}){return e(xa,{fallback:ka,children:t})}function ka({error:n}){return t(he,{status:"error",title:"Sorry, something went wrong...",children:[t("div",{className:"mb-4",children:["Our team has been notified and will be quickly working on resolving it. If you'd like to escalate or simply contact us, please email us at ",e("a",{className:"text-info",href:"mailto:support@vertesiahq.com",children:"support@vertesiahq.com"}),"."]}),n?.message&&e("code",{className:"w-full mt-4 text-sm text-muted break-words",children:n.message})]})}function Ca({children:t}){return e(xa,{fallback:Sa,children:t})}function Sa({error:n}){return e("tr",{children:t("td",{colSpan:100,children:[e("span",{className:"text-xs",children:" Cannot display row"}),e("br",{}),e("span",{className:"bg-gray-400",children:n?.message})]})})}function _a({children:t}){return e(xa,{fallback:ja,children:t})}function ja({error:n}){return console.log("WidgetError",n),t("div",{className:"text-sm",children:["Sorry, this area cannot be loaded or rendered.",n?.message&&e("pre",{children:n.message})]})}function Pa({className:n,children:s,title:a,description:i,actions:l,breadcrumbs:o,isCompact:c=!1}){return t("div",{className:r(c?"pb-0":"pb-2","p-4 flex flex-col",n),children:[t("div",{className:"flex items-start gap-4",children:[t("div",{className:"w-full flex place-content-between h-auto min-h-8 flex-col items-start",children:[e("nav",{className:"flex-1 flex justify-start text-xs",children:o?.map(((n,r)=>t("div",{className:"flex items-center text-muted",children:[n,r<o.length-1&&e(tt,{className:"w-3.5 h-3.5"})]},r)))}),t("div",{className:"flex gap-2 items-center",children:[e("h1",{className:"text-xl font-semibold break-all",children:a}),i&&e(F,{description:i,children:e(Ee,{className:"size-4 text-muted"})})]})]}),e("div",{className:"flex gap-x-2 shrink-0",children:l})]}),s&&e("div",{className:"w-full flex items-center",children:s})]})}function Ta({}){return t("div",{className:"text-center pt-32",children:[e("h1",{className:"text-3xl font-bold text-red-500",children:"404"}),e("p",{className:"text-2xl",children:"Page Not Found"})]})}class Ia{totalPages;layoutUrls=[];cache;constructor(e){this.totalPages=e,this.cache=new Array(e)}async loadUrls(e,t){const n=[];for(let r=0;r<this.totalPages;r++)n.push(za(e,t,r+1));const r=await Promise.all(n);this.layoutUrls=r.map((e=>e.url))}async getPageLayout(e){const t=e-1;let n=this.cache[t];if(void 0===n){const e=this.layoutUrls[t];n=await fetch(e,{method:"GET"}).then((e=>{if(e.ok)return e.text();throw new Error("Failed to fetch json layout: "+e.statusText)})),this.cache[t]=n}return n}}const $a=d(void 0);function Ea({children:t,object:n}){const{client:r}=ke(),[s,a]=o();return c((()=>{const e=n.metadata.page_count||10;(async function(e,t,n){const r=[];for(let s=0;s<n;s++)r.push(Aa(e,t.id,s+1));const s=await Promise.all(r),a=[];for(let r=0;r<n;r++)a.push(Ua(e,t.id,r+1));const i=await Promise.all(a),l=[];for(let r=0;r<n;r++)l.push(Oa(e,t.id,r+1));const o=await Promise.all(l),c=new Ia(n);await c.loadUrls(e,t.id);const d=t.text?Ra(t.text):"";return{count:n,urls:s.map((e=>e.url)),annotatedUrls:i.map((e=>e.url)),instrumentedUrls:o.map((e=>e.url)),layoutProvider:c,xml:d,xmlPages:t.text?Da(d):[]}})(r,n,e).then(a)}),[n.id]),s&&e($a.Provider,{value:s,children:t})}function La(e){return`magic-pdf/${e}`}function Aa(e,t,n){return e.files.getDownloadUrl(function(e,t,n=".jpg"){return`${La(e)}/pages/page-${t}${n}`}(t,n))}function Ua(e,t,n){return e.files.getDownloadUrl(function(e,t,n=".jpg"){return`${La(e)}/pages/page-${t}-annotated${n}`}(t,n))}function Oa(e,t,n){return e.files.getDownloadUrl(function(e,t,n=".jpg"){return`${La(e)}/pages/page-${t}.instrumented${n}`}(t,n))}function za(e,t,n){return e.files.getDownloadUrl(function(e,t){return`${La(e)}/pages/page-${t}.layout.json`}(t,n))}function Fa(){const e=i.useContext($a);if(!e)throw new Error("usePdfPagesInfo must be used within a PdfPageProvider");return e}function Da(e){const t=(new DOMParser).parseFromString(Ra(e),"text/xml").getElementsByTagName("page"),n=new XMLSerializer;return Array.from(t).map((e=>n.serializeToString(e)))}function Ra(e){return e.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,"").replace(/<\?xml.*?\?>/g,"")}function Ma({object:n}){const{client:r}=ke(),s=e=>{(function(e,t,n){return e.files.getDownloadUrl(`${La(t)}/${n}`).then((e=>e.url))})(r,n.id,e).then((e=>window.open(e,"_blank")))};return e("div",{className:"absolute bottom-[58px] right-[20px] w-[36px] h-[36px] cursor-pointer text-indigo-400 border-indigo-400 hover:border-indigo-500 hover:text-indigo-500 border-2 rounded-full shadow-xs flex items-center justify-center",children:t(It,{strategy:"absolute",placement:"top-end",zIndex:100,offset:20,children:[e(It.Trigger,{click:!0,children:e(dt,{className:"size-6"})}),e(It.Content,{children:t("div",{className:"rounded-md shadow-md border border-gray-100 bg-white dark:bg-slate-50 dark:border-slate-100 min-w-[200px] flex flex-col divide-y",children:[e("button",{className:"p-2 cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-100",onClick:()=>s("annotated.pdf"),children:"annotated.pdf"}),e("button",{className:"p-2 cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-100",onClick:()=>s("document.xml"),children:"document.xml"}),e("button",{className:"p-2 cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-100",onClick:()=>s("analyzed-pages.json"),children:"analyzed-pages.json"})]})})]})})}var Va;function qa({className:n,currentPage:s,onChange:a}){const[i,l]=o(Va.default),c=u(null),{urls:d,annotatedUrls:m,instrumentedUrls:h}=Fa(),p=i===Va.instrumented?h:i===Va.annotated?m:d;return t("div",{ref:c,className:r("flex flex-col items-stretch gap-y-2",n),children:[t("div",{className:"flex h-5 items-center justify-center relative",children:[e("button",{className:Ba,onClick:()=>{s>1&&(a(s-1),c.current&&c.current.querySelector(`div[data-index="${s-1}"]`)?.scrollIntoView({behavior:"smooth",block:"end",inline:"center"}))},children:e(mt,{className:"w-5 h-5"})}),t("div",{className:"absolute right-3 flex gap-x-1",children:[e("button",{className:Ja(Va.default,i),onClick:()=>l(Va.default),children:e(ut,{className:"w-5 h-5 mt-1"})}),e("button",{className:Ja(Va.instrumented,i),onClick:()=>l(Va.instrumented),children:e(ht,{className:"w-5 h-5 mt-1"})}),e("button",{className:Ja(Va.annotated,i),onClick:()=>l(Va.annotated),children:e(pt,{className:"w-5 h-5 mt-1"})})]})]}),e("div",{className:"flex flex-col items-center gap-2 flex-1 overflow-y-auto px-2",children:p.map(((t,n)=>e(Wa,{url:t,currentPage:s,pageNumber:n+1,onSelect:()=>a(n+1)},n)))}),e("div",{className:"flex h-5 items-center justify-center relative",children:e("button",{className:Ba,onClick:()=>{s<d.length&&(a(s+1),c.current&&c.current.querySelector(`div[data-index="${s+1}"]`)?.scrollIntoView({behavior:"smooth",block:"end",inline:"center"}))},children:e(gt,{className:"size-5"})})})]})}function Wa({url:n,pageNumber:s,currentPage:a,onSelect:i}){return t("div",{className:"p-2 hover:bg-gray-200 dark:hover:bg-slate-600 rounded-md","data-index":s-1,children:[e("div",{className:r("relative border-[2px] cursor-pointer",s===a?"border-blue-500 dark:border-pink-400":"border-gray-300"),onClick:i,children:e("img",{src:n,alt:`Page ${s}`})}),e(pe,{className:"text-sm text-gray-500 dark:text-gray-400 pt-1 font-semibold align",children:s})]})}!function(e){e[e.default=0]="default",e[e.instrumented=1]="instrumented",e[e.annotated=2]="annotated"}(Va||(Va={}));const Ba="cursor-pointer text-gray-500 dark:text-gray-400 hover:text-blue-600 dark:hover:text-blue-500 hover:font-semibold";function Ja(e,t){return e===t?"${BTN_CLASS} text-pink-600":`${Ba}`}const Ha={attributeKeyColor:"#FFD700",attributeValueColor:"#FF4500",tagColor:"#87CEFA",textColor:"#00FF00",separatorColor:"#FFD700",commentColor:"#BEBEBE",cdataColor:"#33CC66"};function Ga({viewType:t,pageNumber:n}){return e("json"===t?Qa:Ka,{pageNumber:n})}function Ka({pageNumber:t}){const[n,r]=o(),{xmlPages:s}=Fa();return p((()=>{const e=window.matchMedia("(prefers-color-scheme: dark)"),t=e=>{r(e.matches?Ha:void 0)};return e.addEventListener("change",t),e.matches&&r(Ha),()=>{e.removeEventListener("change",t)}}),[]),e("div",{className:"px-4 py-2",children:e(Et,{xml:s[t-1],collapsible:!0,theme:n})})}function Qa({pageNumber:t}){const[n,r]=o(),{layoutProvider:s}=Fa();return c((()=>{s.getPageLayout(t).then((e=>r(e?JSON.parse(e):void 0))).catch((e=>{console.error(e),r(void 0)}))}),[t]),n&&e($t,{className:"w-full",data:n})}function Ya({objectId:t,onClose:n}){const{client:r}=ke(),{data:s,error:a}=M((()=>r.store.objects.retrieve(t,"+text")),[t]);return a?e(K,{title:"Fetching document failed",children:a.message}):s?e("div",{className:"fixed inset-0 bg-white dark:bg-slate-700 z-50 flex items-center justify-center",children:e(Ea,{object:s,children:e(Xa,{object:s,onClose:n})})}):"Loading..."}function Xa({object:r,onClose:s}){const[a,i]=o("xml"),[l,d]=o(1),m=u(null),h=u(null),p=u(null);var g;return c((()=>{if(g.handler.current&&g.left.current&&g.right.current){const e=g.handler.current,t=g.left.current,n=g.right.current,r=e=>{let r=e.clientX,s=t.offsetWidth,a=n.offsetLeft;const i=e=>{const i=e.clientX-r;t.style.width=`${s+i}px`,n.style.left=`${a+i}px`,e.target.classList.add("resizing")},l=e=>{e.target.classList.remove("resizing"),i(e),document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",l)};document.addEventListener("mousemove",i),document.addEventListener("mouseup",l)};return e.addEventListener("mousedown",r),()=>{e.removeEventListener("mousedown",r)}}}),[(g={handler:m,left:h,right:p}).handler.current,g.left.current,g.right.current]),t(n,{children:[t("div",{ref:h,className:"absolute top-0 left-0 bottom-0 w-[50%] bg-gray-100 dark:bg-slate-800 flex items-stretch justify-stretch py-2",children:[e(qa,{className:"flex-1",currentPage:l,onChange:d}),e("div",{ref:m,className:"w-[2px] p-[2px] m-0 bg-slate-300 cursor-ew-resize"})]}),e("div",{ref:p,className:"absolute top-0 left-[50%] right-0 bottom-0 flex items-stretch justify-stretch overflow-auto p-2",children:e(Ga,{pageNumber:l,viewType:a})}),e(Ma,{object:r}),e(Za,{type:a,onSwitch:i}),!!s&&e("div",{className:"absolute top-6 right-7 w-9 h-9 cursor-pointer text-red-400 border-red-400 hover:border-red-500 hover:text-red-500 border-2 rounded-full shadow-xs flex items-center justify-center",onClick:s,children:e(Ce,{className:"size-6"})})]})}function Za({type:e="xml",onSwitch:n}){return t("div",{className:"absolute bottom-[16px] right-[20px] w-[36px] h-[36px] cursor-pointer text-indigo-400 border-indigo-400 hover:border-indigo-500 hover:text-indigo-500 border-2 rounded-full shadow-xs flex items-center justify-center",onClick:()=>{"xml"===e?n("json"):"json"===e&&n("xml")},children:["xml"===e&&ei,"json"===e&&ti]})}const ei=e("svg",{width:"16px",height:"16px",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",children:e("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M6 2.984V2h-.09c-.313 0-.616.062-.909.185a2.33 2.33 0 0 0-.775.53 2.23 2.23 0 0 0-.493.753v.001a3.542 3.542 0 0 0-.198.83v.002a6.08 6.08 0 0 0-.024.863c.012.29.018.58.018.869 0 .203-.04.393-.117.572v.001a1.504 1.504 0 0 1-.765.787 1.376 1.376 0 0 1-.558.115H2v.984h.09c.195 0 .38.04.556.121l.001.001c.178.078.329.184.455.318l.002.002c.13.13.233.285.307.465l.001.002c.078.18.117.368.117.566 0 .29-.006.58-.018.869-.012.296-.004.585.024.87v.001c.033.283.099.558.197.824v.001c.106.273.271.524.494.753.223.23.482.407.775.53.293.123.596.185.91.185H6v-.984h-.09c-.2 0-.387-.038-.563-.115a1.613 1.613 0 0 1-.457-.32 1.659 1.659 0 0 1-.309-.467c-.074-.18-.11-.37-.11-.573 0-.228.003-.453.011-.672.008-.228.008-.45 0-.665a4.639 4.639 0 0 0-.055-.64 2.682 2.682 0 0 0-.168-.609A2.284 2.284 0 0 0 3.522 8a2.284 2.284 0 0 0 .738-.955c.08-.192.135-.393.168-.602.033-.21.051-.423.055-.64.008-.22.008-.442 0-.666-.008-.224-.012-.45-.012-.678a1.47 1.47 0 0 1 .877-1.354 1.33 1.33 0 0 1 .563-.121H6zm4 10.032V14h.09c.313 0 .616-.062.909-.185.293-.123.552-.3.775-.53.223-.23.388-.48.493-.753v-.001c.1-.266.165-.543.198-.83v-.002c.028-.28.036-.567.024-.863-.012-.29-.018-.58-.018-.869 0-.203.04-.393.117-.572v-.001a1.502 1.502 0 0 1 .765-.787 1.38 1.38 0 0 1 .558-.115H14v-.984h-.09c-.196 0-.381-.04-.557-.121l-.001-.001a1.376 1.376 0 0 1-.455-.318l-.002-.002a1.415 1.415 0 0 1-.307-.465v-.002a1.405 1.405 0 0 1-.118-.566c0-.29.006-.58.018-.869a6.174 6.174 0 0 0-.024-.87v-.001a3.537 3.537 0 0 0-.197-.824v-.001a2.23 2.23 0 0 0-.494-.753 2.331 2.331 0 0 0-.775-.53 2.325 2.325 0 0 0-.91-.185H10v.984h.09c.2 0 .387.038.562.115.174.082.326.188.457.32.127.134.23.29.309.467.074.18.11.37.11.573 0 .228-.003.452-.011.672-.008.228-.008.45 0 .665.004.222.022.435.055.64.033.214.089.416.168.609a2.285 2.285 0 0 0 .738.955 2.285 2.285 0 0 0-.738.955 2.689 2.689 0 0 0-.168.602c-.033.21-.051.423-.055.64a9.15 9.15 0 0 0 0 .666c.008.224.012.45.012.678a1.471 1.471 0 0 1-.877 1.354 1.33 1.33 0 0 1-.563.121H10z"})}),ti=e("svg",{width:"16px",height:"16px",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",children:e("path",{d:"M4.708 5.578L2.061 8.224l2.647 2.646-.708.708-3-3V7.87l3-3 .708.708zm7-.708L11 5.578l2.647 2.646L11 10.87l.708.708 3-3V7.87l-3-3zM4.908 13l.894.448 5-10L9.908 3l-5 10z"})});function ni(...e){const t=Array.from(e);return t.__AnyOf__=!0,t}function ri(...e){return Array.from(e)}function si(e){return!0===e.__AnyOf__}class ai{system_roles;roles;permissions;constructor(e,t){if(!e.authToken)throw new Error("No auth token found in user session");this.system_roles=t;const n=new Set(e.authToken.account_roles||[]);if(e.authToken.project_roles)for(const t of e.authToken.project_roles)n.add(t);this.roles=n;const r={};for(const e of t)r[e.name]=e.permissions;const s=new Set;for(const e of n){const t=r[e];if(t)for(const e of t)s.add(e)}this.permissions=s}hasPermission(e){if("string"==typeof e)return this.permissions.has(e);if(si(e))return e.some((e=>this.permissions.has(e)));for(const t of e)if(!this.permissions.has(t))return!1;return!0}}const ii=d(void 0);function li(){const e=m(ii);if(!e)throw new Error("UserPermissionContext cannot be used outside UserPermissionProvider");return e}function oi({children:t}){const n=ke(),{data:r,error:s,isLoading:a}=M((()=>n.user?n.client.iam.roles.list():Promise.resolve(void 0)),[n.user]),i=l((()=>n.authToken&&r&&!a?new ai(n,r):void 0),[n,r,a]);return s?e(K,{title:"Failed to fetch role mappings",children:s.message}):i&&e(ii.Provider,{value:i,children:t})}function ci({permission:t,isDisabled:n,title:r,children:s,...a}){return li().hasPermission(t)||(n=!0,r="You do not have permission to perform this action"),e(y,{isDisabled:n,title:r,...a,children:s})}function di({permission:t,...n}){return li().hasPermission(t)?e(Rt,{...n}):null}function mi({user:n}){return t("div",{className:"flex items-center",children:[e("div",{className:"w-9 h-9",children:(()=>{if(n.picture)return e("img",{className:"inline-block h-9 w-9 rounded-full",src:n.picture,alt:n.name});{const t=n.name.split(" ").map((e=>e[0])).join("");return e("span",{className:"inline-flex h-8 w-8 items-center justify-center rounded-full bg-indigo-600",children:e("span",{className:"text-sm font-medium leading-none text-white",children:t})})}})()}),t("div",{className:"ml-3",children:[e("p",{className:"text-sm font-medium text-gray-700 dark:text-slate-50 group-hover:text-gray-900",children:n.name??"Deleted User"}),e("p",{className:"text-xs font-medium text-gray-500 dark:text-slate-300 group-hover:text-gray-700",children:n.email??"Deleted User"})]})]})}export{Wt as ActivitiesDoc,Jt as ActivityDoc,ra as AddToCollectionAction,na as AddToCollectionActionComponent,ri as AllOf,en as AnimatedThinkingDots,ni as AnyOf,ar as ApiKeyAvatar,is as BrowseCollectionView,Os as ChangeTypeAction,Us as ChangeTypeActionComponent,ms as CollectionsTable,wn as ContentDispositionButton,ws as ContentObjectTypesSearch,hs as ContentObjectTypesTable,Sn as ContentOverview,cs as CreateCollectionForm,ds as CreateCollectionModal,xs as CreateOrUpdateTypeModal,Ds as DeleteObjectsAction,Fs as DeleteObjectsActionComponent,Cr as DocumentGridView,Rn as DocumentIcon,Hr as DocumentInput,Kr as DocumentPreviewPanel,Sr as DocumentSearch,Rr as DocumentSearchProvider,es as DocumentSearchResults,Zr as DocumentSearchResultsWithDropZone,hr as DocumentSelection,br as DocumentSelectionProvider,zr as DocumentTable,Nr as DocumentTableColumn,kr as DocumentTableView,Ar as DocumentUploadModal,Is as EditCollectionView,qn as EnvironmentFacet,Ms as ExportPropertiesAction,Rs as ExportPropertiesComponent,rs as ExportPropertiesModal,ns as ExportTypes,Gn as FacetsNav,$r as FileUploadAction,Pa as GenericPageNavHeader,Kn as InteractionFacet,Zt as JumpingDots,Ya as MagicPdfView,ga as ModernAgentConversation,Ta as NotFoundView,ks as ObjectSchemaEditor,ps as ObjectTypeSearch,gs as ObjectTypeSearchContext,Cs as ObjectTypeSearchProvider,Ks as ObjectsActionContext,Ys as ObjectsActionContextProvider,Na as PanelErrorBoundary,pn as PayloadBuilder,fn as PayloadBuilderProvider,gn as PayloadContext,Cn as PropertiesEditorModal,tn as PulsatingCircle,rn as PulsingMessageLoader,qs as RemoveFromCollectionAction,Vs as RemoveFromCollectionActionComponent,Ca as RowErrorBoundary,kn as SaveVersionConfirmModal,_r as SearchContext,ci as SecureButton,di as SecureSidebarItem,As as SelectCollection,os as SelectContentType,Ss as SelectContentTypeModal,Vr as SelectDocument,Br as SelectDocumentModal,ia as SelectionActions,Bs as StartWorkflowAction,Ws as StartWorkflowComponent,Wn as StringFacet,Bn as StringListFacet,js as TableLayoutEditor,sn as ThinkingBar,on as ThinkingMessages,Hn as TypeFacet,nn as TypedDots,oa as UploadObjectsButton,mi as UserAvatar,or as UserFacet,nr as UserInfo,oi as UserPermissionProvider,ai as UserPermissions,ur as VFacetsNav,cr as VStringFacet,dr as VTypeFacet,mr as VUserFacet,xa as VertesiaErrorBoundary,an as WavyThinking,_a as WidgetErrorBoundary,us as collectionIcon,si as isAnyOf,En as isCsv,Ln as isImage,An as isPdf,Un as isVideo,Dn as retrieveRendition,wa as setErrorBoundaryComponent,_n as shortId,jn as shortenString,Ps as stringifyTableLayout,jr as useDocumentSearch,Ir as useDocumentSearchCount,gr as useDocumentSelection,Ur as useDocumentUploadHandler,Gr as useDownloadDocument,Yn as useFetchUserInfo,ea as useObjectsActionCallback,Zs as useObjectsActionContext,fr as useOptionalDocumentSelection,bn as usePayloadBuilder,fs as useSearch,ys as useSearchCount,Lr as useSmartFileUploadProcessing,ta as useStartWorkflowCallback,li as useUserPermissions,Pr as useWatchDocumentSearchFacets,Tr as useWatchDocumentSearchResult,bs as useWatchSearchResult};
1
+ import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import r from"clsx";import{AnimatePresence as a,motion as s}from"motion/react";import i,{useMemo as l,useState as o,useEffect as c,createContext as d,useContext as m,useRef as u,useCallback as h,useLayoutEffect as p}from"react";import{cn as g,useToast as f,Badge as b,Button as y,Popover as v,PopoverTrigger as x,PopoverContent as w,Command as N,CommandList as k,CommandGroup as C,CommandItem as S,Modal as j,ModalTitle as _,ModalBody as P,RadioGroup as T,FormItem as I,Input as $,ModalFooter as E,RadioOptionAdapter as A,Spinner as L,Card as z,Separator as D,CardContent as O,VTooltip as U,SelectBox as F,InputList as R,FilterProvider as M,FilterBtn as V,FilterBar as q,FilterClear as W,useFetch as B,Avatar as J,Table as G,TBody as H,SharedState as K,useWatchSharedState as Y,VModal as Q,VModalTitle as X,VModalBody as Z,MessageBox as ee,VModalFooter as te,VSelectBox as ne,useIntersectionObserver as re,ErrorBox as ae,useFlag as se,Styles as ie,useDebounce as le,SidePanel as oe,Divider as ce,Switch as de,TR as me,EmptyCollection as ue,ConfirmModal as he,Textarea as pe,SelectList as ge,Portal as fe,DialogDescription as be,Heading as ye,VTabs as ve,VTabsBar as xe,VTabsPanel as we,Center as Ne}from"@vertesia/ui/core";import{AgentMessageType as ke,mergePromptsSchema as Ce,supportsToolUse as Se,ImageRenditionFormat as je,PrincipalType as _e,InteractionStatus as Pe,SupportedEmbeddingTypes as Te}from"@vertesia/common";import{useUserSession as Ie}from"@vertesia/ui/session";import{X as $e,Circle as Ee,AlertCircle as Ae,Clock as Le,CheckCircle as ze,CopyIcon as De,Bot as Oe,MessageSquare as Ue,Info as Fe,User as Re,ClipboardList as Me,XIcon as Ve,MoreVertical as qe,ExternalLink as We,DownloadCloudIcon as Be,TableProperties as Je,LayoutGrid as Ge,Copy as He,SquarePen as Ke,Download as Ye,Eye as Qe,UploadIcon as Xe,CheckCircleIcon as Ze,AlertCircleIcon as et,FileIcon as tt,XCircleIcon as nt,FolderIcon as rt,RefreshCw as at,ChevronsUpDown as st,FileText as it,Maximize2 as lt,ChevronRight as ot,Trash2 as ct,Search as dt,FolderClosed as mt,EllipsisVertical as ut,PaperclipIcon as ht,SendIcon as pt,Activity as gt,Cpu as ft,CloudDownload as bt,ChevronsUp as yt,ImageIcon as vt,InfoIcon as xt,AtSignIcon as wt,ChevronsDown as Nt}from"lucide-react";import{NavLink as kt,useNavigate as Ct}from"@vertesia/ui/router";import St from"dayjs";import jt from"react-markdown";import _t from"remark-gfm";import Pt,{Ajv as Tt}from"ajv";import{JSONDisplay as It,DropZone as $t,UploadSummary as Et,useSchema as At,CodeMirrorEditor as Lt,SchemaEditor as zt,ManagedObject as Dt,GeneratedForm as Ot,Popover as Ut,JSONCode as Ft,XMLViewer as Rt}from"@vertesia/ui/widgets";import Mt from"@monaco-editor/react";import Vt from"dayjs/plugin/localizedFormat";import qt from"dayjs/plugin/relativeTime";import{Md5 as Wt}from"ts-md5";import{json as Bt}from"@codemirror/lang-json";import{basicSetup as Jt}from"codemirror";import{ErrorBoundary as Gt}from"react-error-boundary";import{SidebarItem as Ht}from"@vertesia/ui/layout";function Kt({children:t,secondary:n=!1}){return e("span",{className:n?"bg-secondary text-primary":"text-foreground bg-muted",children:t})}function Yt(e){return e?"array"===e.name?Yt(e.innerType):e:void 0}function Qt({property:n}){return t("div",{className:"flex items-center gap-x-2",children:[e("div",{className:"font-semibold text-gray-600",children:n.name}),n.optional&&e(Kt,{children:"optional"}),e(Kt,{children:n.type.value})]})}function Xt({activities:t}){return e("div",{className:"flex flex-col gap-y-4 divide-y divide-gray-200",children:t.map((t=>e(en,{activity:t},t.name)))})}function Zt({code:n,children:r}){return t("div",{className:"flex gap-2 items-center border-b border-b-gray-200 mb-2",children:[e("div",{className:"text-lg font-medium text-gray-900 py-2 ",children:r}),n&&e("div",{children:e(Kt,{children:n})})]})}function en({activity:n,headingClass:r,headingRef:a}){return t("div",{className:r,id:n.name,ref:a,children:[e("div",{className:"text-xl font-semibold pt-8",children:n.title}),e("div",{className:"pb-4",children:e(Kt,{children:n.name})}),n.doc&&e("div",{className:"text-gray-700 pb-2",children:n.doc}),t("div",{className:"pb-4",children:[e(Zt,{code:n.paramsType,children:"Parameters"}),e("div",{className:"divide-y divide-gray-100",children:n.params.map((t=>e(tn,{property:t},t.name)))})]}),t("div",{className:"pb-4",children:[e(Zt,{children:"Returns"}),e("div",{children:n.returnType?n.returnType.value:"void"})]})]})}function tn({property:n,className:a}){const s=l((()=>{const t=Yt(n.type.innerType)??n.type;return"object"===t.name&&t.members?e(rn,{members:t.members}):"enum"===t.name&&t.enum?e(nn,{values:t.enum}):null}),[n.type.innerType]);return t("div",{className:r("py-2",a),children:[e(Qt,{property:n}),n.doc&&e("div",{className:"text-gray-700 text-sm pt-2",children:n.doc}),s&&e("div",{className:"my-2 overflow-hidden",children:s})]})}function nn({values:t}){return e("div",{className:"flex flex-wrap items-center gap-2",children:t.map(((t,n)=>e(Kt,{secondary:!0,children:t},n)))})}function rn({members:n}){return e(sn,{className:"rounded-md border border-gray-200",button:n=>t("div",{className:"px-4 py-2 flex items-center gap-x-2 text-sm font-medium hover:text-blue-600",children:[e(ln,{isOpen:n}),e("div",n?{children:"Hide child properties"}:{children:"Show child properties"})]}),body:e(an,{properties:n})})}function an({properties:t}){return e("div",{className:"border-l-2 border-l-blue-200 flex flex-col divide-y divide-gray-100 border-t border-t-gray-200",children:t.map((t=>e(tn,{property:t,className:"px-4 py-2"},t.name)))})}function sn({button:n,body:i,className:l,isInitiallyOpen:c}){const[d,m]=o(c||!1);return t("div",{className:r(d?"block":"inline-block",l),children:[e("button",{className:"p-0 m-0 bg-transparent",onClick:()=>m(!d),children:e(a,{children:n(d)})}),e(a,{children:d&&e(s.div,{className:"overflow-hidden",initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.3,ease:"easeOut"},children:i})})]})}function ln({isOpen:t}){return e(a,{propagate:!0,mode:"wait",children:e(s.div,{className:"font-mono font-semibold text-gray-400 text-lg",initial:{rotate:0},animate:{rotate:t?45:0},transition:{duration:.2},children:"+"},"closeIcon")})}function on({className:n,inline:r=!1}){return t("div",{className:g("flex items-center gap-1",r?"inline-flex":"",n),children:[e("div",{className:"w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_infinite_ease-in-out] hover:bg-blue-600",style:{transform:"translateY(0)",animationRange:"0px -8px"}}),e("div",{className:"w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_0.3s_infinite_ease-in-out] hover:bg-blue-600",style:{transform:"translateY(0)",animationRange:"0px -8px"}}),e("div",{className:"w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_0.6s_infinite_ease-in-out] hover:bg-blue-600",style:{transform:"translateY(0)",animationRange:"0px -8px"}})]})}function cn({className:n,inline:r=!1,color:a="blue"}){const s={blue:"from-blue-400 to-indigo-500 dark:from-blue-500 dark:to-indigo-400",purple:"from-purple-400 to-violet-500 dark:from-purple-500 dark:to-violet-400",teal:"from-teal-400 to-emerald-500 dark:from-teal-500 dark:to-emerald-400",green:"from-green-400 to-emerald-500 dark:from-green-500 dark:to-emerald-400",amber:"from-amber-400 to-orange-500 dark:from-amber-500 dark:to-orange-400"}[a];return t("div",{className:g("flex items-center gap-1.5",r?"inline-flex":"",n),children:[e("div",{className:`w-2 h-2 bg-gradient-to-r ${s} rounded-full animate-[bounce_1.2s_ease-in-out_infinite]`}),e("div",{className:`w-2 h-2 bg-gradient-to-r ${s} rounded-full animate-[bounce_1.2s_ease-in-out_0.2s_infinite]`}),e("div",{className:`w-2 h-2 bg-gradient-to-r ${s} rounded-full animate-[bounce_1.2s_ease-in-out_0.4s_infinite]`})]})}function dn({className:n,size:r="md",color:a="blue"}){const s={blue:"bg-blue-500 dark:bg-blue-400",purple:"bg-purple-500 dark:bg-purple-400",teal:"bg-teal-500 dark:bg-teal-400",green:"bg-green-500 dark:bg-green-400",amber:"bg-amber-500 dark:bg-amber-400"};return t("span",{className:g("relative flex",n),children:[e("span",{className:g("animate-ping absolute inline-flex h-full w-full rounded-full opacity-60",s[a])}),e("span",{className:g("animate-pulse absolute inline-flex h-[80%] w-[80%] rounded-full opacity-80",s[a]),style:{left:"10%",top:"10%",animationDuration:"2s"}}),e("span",{className:g("relative inline-flex rounded-full",s[a],{sm:"w-3 h-3",md:"w-5 h-5",lg:"w-7 h-7"}[r])})]})}function mn({className:t,color:n="blue"}){const[r,a]=o(".");return c((()=>{const e=setInterval((()=>{a((e=>"."===e?"..":".."===e?"...":"."))}),500);return()=>clearInterval(e)}),[]),e("span",{className:g({blue:"text-blue-600 dark:text-blue-400",purple:"text-purple-600 dark:text-purple-400",teal:"text-teal-600 dark:text-teal-400",green:"text-green-600 dark:text-green-400",amber:"text-amber-600 dark:text-amber-400"}[n],"font-bold",t),children:r})}function un({message:n,className:r,color:a="blue"}){const s={blue:{dot:"bg-blue-500 dark:bg-blue-400",text:"text-blue-700 dark:text-blue-300"},purple:{dot:"bg-purple-500 dark:bg-purple-400",text:"text-purple-700 dark:text-purple-300"},teal:{dot:"bg-teal-500 dark:bg-teal-400",text:"text-teal-700 dark:text-teal-300"},green:{dot:"bg-green-500 dark:bg-green-400",text:"text-green-700 dark:text-green-300"},amber:{dot:"bg-amber-500 dark:bg-amber-400",text:"text-amber-700 dark:text-amber-300"}};return t("div",{className:g("flex items-center gap-2 py-1",r),children:[t("div",{className:"flex space-x-1",children:[e("div",{className:`w-1.5 h-1.5 ${s[a].dot} rounded-full animate-bounce`}),e("div",{className:`w-1.5 h-1.5 ${s[a].dot} rounded-full animate-bounce`,style:{animationDelay:"0.2s"}}),e("div",{className:`w-1.5 h-1.5 ${s[a].dot} rounded-full animate-bounce`,style:{animationDelay:"0.4s"}})]}),e("div",{className:`${s[a].text} font-medium text-xs`,children:n})]})}function hn({className:n,color:r="blue",width:a="md",message:s}){const[i,l]=o(15),[d,m]=o("increasing"),[u,h]=o(.4);return c((()=>{let e,t=Date.now();const n=()=>{const r=Date.now(),a=r-t;t=r,l((e=>{const t=u*(a/16);let n="increasing"===d?e+t:e-t;return n>=85?(m("decreasing"),h(.3+.2*Math.random()),85):n<=15?(m("increasing"),h(.3+.2*Math.random()),15):(Math.random()>.99&&h((e=>Math.max(.2,Math.min(.5,e+(.1*Math.random()-.05))))),n)})),e=requestAnimationFrame(n)};return e=requestAnimationFrame(n),()=>{cancelAnimationFrame(e)}}),[d,u]),t("div",{className:g("flex flex-col gap-1",n),children:[s&&e("div",{className:`text-xs font-medium ${{blue:"text-blue-700 dark:text-blue-300",purple:"text-purple-700 dark:text-purple-300",teal:"text-teal-700 dark:text-teal-300",green:"text-green-700 dark:text-green-300",amber:"text-amber-700 dark:text-amber-300"}[r]} mb-1`,children:s}),e("div",{className:g("h-1.5 rounded-full overflow-hidden shadow-inner",{blue:"bg-blue-200 dark:bg-blue-900/30",purple:"bg-purple-200 dark:bg-purple-900/30",teal:"bg-teal-200 dark:bg-teal-900/30",green:"bg-green-200 dark:bg-green-900/30",amber:"bg-amber-200 dark:bg-amber-900/30"}[r],{sm:"w-24",md:"w-32",lg:"w-48",xl:"w-64",full:"w-full"}[a]),children:e("div",{className:g("h-full rounded-full",{blue:"bg-gradient-to-r from-blue-400 to-blue-500 dark:from-blue-500 dark:to-blue-400",purple:"bg-gradient-to-r from-purple-400 to-purple-500 dark:from-purple-500 dark:to-purple-400",teal:"bg-gradient-to-r from-teal-400 to-teal-500 dark:from-teal-500 dark:to-teal-400",green:"bg-gradient-to-r from-green-400 to-green-500 dark:from-green-500 dark:to-green-400",amber:"bg-gradient-to-r from-amber-400 to-amber-500 dark:from-amber-500 dark:to-amber-400"}[r]),style:{width:`${i}%`,transition:"width 150ms cubic-bezier(0.4, 0.0, 0.2, 1)"}})})]})}function pn({className:t,color:n="blue",size:r="md"}){const[a,s]=o(Array(7).fill(50)),i={sm:{width:"w-16",height:"h-4",barWidth:"w-0.5",gap:"gap-[2px]"},md:{width:"w-20",height:"h-5",barWidth:"w-1",gap:"gap-[3px]"},lg:{width:"w-24",height:"h-6",barWidth:"w-1.5",gap:"gap-1"}},l={blue:"bg-gradient-to-b from-blue-400 to-blue-500 dark:from-blue-400 dark:to-blue-500",purple:"bg-gradient-to-b from-purple-400 to-purple-500 dark:from-purple-400 dark:to-purple-500",teal:"bg-gradient-to-b from-teal-400 to-teal-500 dark:from-teal-400 dark:to-teal-500",green:"bg-gradient-to-b from-green-400 to-green-500 dark:from-green-400 dark:to-green-500",amber:"bg-gradient-to-b from-amber-400 to-amber-500 dark:from-amber-400 dark:to-amber-500"};return c((()=>{let e;const t=[1.2,1,1.5,.8,1.3,.9,1.1],n=[0,.5,1,1.5,2,2.5,3];let r=0;const i=()=>{r+=.02;const l=a.map(((e,a)=>10+40*(Math.sin(r*t[a]+n[a])+1)));s(l),e=requestAnimationFrame(i)};return e=requestAnimationFrame(i),()=>{cancelAnimationFrame(e)}}),[]),e("div",{className:g("flex items-end justify-center",i[r].width,i[r].height,i[r].gap,t),children:a.map(((t,a)=>e("div",{className:g(i[r].barWidth,"rounded-full transform-gpu",l[n]),style:{height:`${t}%`,transition:"height 100ms cubic-bezier(0.4, 0.0, 0.2, 1)",opacity:.9}},a)))})}function gn({plan:r,workstreamStatus:a,isOpen:s,onClose:i,plans:l=[],activePlanIndex:o=0,onChangePlan:c=()=>{}}){return s?t("div",{className:"fixed top-24 right-8 bottom-24 z-50 bg-white dark:bg-gray-900 shadow-xl border border-gray-200 dark:border-gray-700 overflow-hidden",style:{width:"350px"},children:[t("div",{className:"flex items-center justify-between p-3 border-b border-gray-200 dark:border-gray-800",children:[e("h3",{className:"font-bold text-gray-800 dark:text-gray-200 text-base",children:"Plan"}),t("button",{className:"p-1 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-full text-gray-500 dark:text-gray-400",onClick:i,children:[e($e,{className:"h-4 w-4"}),e("span",{className:"sr-only",children:"Close"})]})]}),t("div",{className:"p-3 overflow-y-auto",style:{height:"calc(100% - 44px)",maxHeight:"calc(100vh - 150px)"},children:[t("div",{className:"mb-3 p-2 bg-blue-50 dark:bg-blue-900/20 rounded-md border border-blue-100 dark:border-blue-800",children:[e("div",{className:"text-xs font-medium text-blue-700 dark:text-blue-300 mb-1",children:"Task Progress"}),e("div",{className:"flex items-center gap-2",children:(()=>{const s=r.plan||[],i=s.length;let l=0;i>0&&s.forEach((e=>{if(e&&e.id){const t=e.id.toString();"completed"===a.get(t)&&l++}}));const o=i>0?Math.round(l/i*100):0;return t(n,{children:[e("div",{className:"w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2",children:e("div",{className:"bg-blue-600 h-2 rounded-full",style:{width:`${o}%`}})}),e("span",{className:"text-xs text-gray-600 dark:text-gray-400",children:i>0?`${l}/${i}`:"0/0"})]})})()})]}),l.length>1&&t("div",{className:"mb-3 flex items-center justify-between",children:[e("button",{className:"text-xs px-2 py-1 rounded-md bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-300 disabled:opacity-50",onClick:()=>c(Math.min(l.length-1,o+1)),disabled:o>=l.length-1,children:"Older Plan"}),e("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:l[o]?.timestamp?new Date(l[o].timestamp).toLocaleTimeString():"Unknown time"}),e("button",{className:"text-xs px-2 py-1 rounded-md bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-300 disabled:opacity-50",onClick:()=>c(Math.max(0,o-1)),disabled:o<=0,children:"Newer Plan"})]}),t("div",{className:"rounded-md border border-gray-200 dark:border-gray-800",children:[e("div",{className:"p-2 border-b border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-900/50",children:e("div",{className:"font-medium text-xs",children:"Step-by-Step Plan"})}),e("div",{className:"divide-y divide-gray-100 dark:divide-gray-800 max-h-[calc(100vh-350px)] overflow-y-auto",children:r.plan&&r.plan.length>0?r.plan.map(((n,r)=>{const s=n.id?n.id.toString():`task-${r}`,i=n.goal||`Task ${r+1}`;let l=n.status||"pending";a.has(s)&&(l=a.get(s));let o=Ee,c="text-gray-400",d="";return"in_progress"===l?(o=Le,c="text-blue-500",d="bg-blue-50/50 dark:bg-blue-900/10"):"completed"===l&&(o=ze,c="text-green-500"),t("div",{className:`flex p-3 my-1 ${d}`,children:[e("div",{className:`mr-2 mt-0.5 flex-shrink-0 ${c}`,children:e(o,{className:"h-3.5 w-3.5"})}),t("div",{className:"w-full",children:[e("div",{className:"text-sm font-medium text-gray-800 dark:text-gray-200 mb-2",children:i}),t("div",{className:"mt-1 flex justify-between items-center",children:[e("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300",children:s}),e("span",{className:"ml-2 text-xs px-2 py-0.5 rounded-full "+("completed"===l?"bg-green-100 text-green-600 dark:bg-green-900/30 dark:text-green-400":"in_progress"===l?"bg-blue-100 text-blue-600 dark:bg-blue-900/30 dark:text-blue-400":"bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400"),children:"completed"===l?"Completed":"in_progress"===l?"In Progress":"Pending"})]})]})]},r)})):t("div",{className:"p-3 text-center text-gray-500 dark:text-gray-400 italic",children:[e(Ae,{className:"h-4 w-4 mx-auto mb-2 text-amber-500"}),e("p",{className:"text-xs",children:"No plan has been detected yet"}),e("p",{className:"text-xs mt-1",children:"Plans will appear here when the agent creates one"})]})})]}),(()=>{const n=new Set((r.plan||[]).filter((e=>e&&e.id)).map((e=>e.id.toString()))),s=Array.from(a.entries()).filter((([e])=>"main"!==e&&!n.has(e)));return s.length>0?t("div",{className:"mt-3 rounded-md border border-gray-200 dark:border-gray-800",children:[e("div",{className:"p-2 border-b border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-900/50",children:e("div",{className:"font-medium text-xs",children:"Workstreams"})}),e("div",{className:"p-3",children:e("div",{className:"grid grid-cols-1 gap-2",children:s.map((([n,r])=>{let a=Ee,s="text-gray-400",i="bg-gray-100 dark:bg-gray-800",l="Pending";return"in_progress"===r?(a=Le,s="text-blue-500",i="bg-blue-100 dark:bg-blue-800/30",l="In Progress"):"completed"===r&&(a=ze,s="text-green-500",i="bg-green-100 dark:bg-green-800/30",l="Completed"),t("div",{className:`flex items-center p-1.5 rounded ${i}`,children:[e("div",{className:`mr-1.5 ${s}`,children:e(a,{className:"h-3.5 w-3.5"})}),e("div",{className:"flex-1",children:e("span",{className:"text-xs font-medium text-gray-800 dark:text-gray-300",children:n})}),e("span",{className:"text-xs font-medium",children:l})]},n)}))})})]}):null})()]})]}):null}const fn=["Brewing some code magic...","Doing the robot dance...","Cooking up something good...","Working my gears...","Parsing the possibilities...","Crunching the numbers...","Connecting the digital dots...","Processing at maximum capacity...","Searching through my circuits...","Running advanced algorithms...","Computing optimal solutions...","Loading brilliance.exe...","Scanning the knowledge base...","Optimizing response protocols...","Having a quick brainstorm...","Thinking cap firmly on...","Pondering the digital universe...","Consulting my silicon wisdom...","Untangling the logic knots...","Assembling clever responses...","Mixing thoughtful ingredients...","Polishing the perfect answer...","Taking a momentary mind sprint...","Connecting virtual synapses...","Baking fresh ideas...","Stirring the thought pot...","Simmering solutions slowly...","Whipping up a smart response...","Adding a dash of intelligence...","Preparing a gourmet answer...","Growing brilliant ideas...","Cultivating the perfect response...","Gathering digital nectar...","Planting seeds of solutions...","Exploring the data landscape...","Mapping the solution path...","Navigating through possibilities...","Charting the course to answers...","Embarking on a thought expedition...","Sketching out concepts...","Painting with digital brushstrokes...","Composing my response symphony...","Crafting precision answers...","Weaving threads of information...","Just a moment of processing...","Taking a quick thinking break...","Almost there, final touches...","Putting the pieces together...","Making progress, hold tight..."];const bn=[ke.COMPLETE,ke.IDLE,ke.REQUEST_INPUT,ke.TERMINATED];function yn(e){return e.workstream_id?(e.type===ke.COMPLETE&&console.log("[getWorkstreamId] COMPLETE message with workstream_id:",e.workstream_id),e.workstream_id):(e.type===ke.COMPLETE&&console.log("[getWorkstreamId] COMPLETE message without workstream_id, defaulting to 'main'"),"main")}function vn({message:r,showPulsatingCircle:a=!1}){const[s,i]=o(!1),[l,d]=o(""),[m,u]=o(!1),{client:h}=Ie(),p=f(),g=(()=>{const t={containerClass:"bg-white border-l-4 border-l-muted/30 shadow-sm",iconComponent:e(Oe,{className:"size-4 text-muted"}),sender:""};switch(r.type){case ke.ANSWER:return{...t,containerClass:"bg-white border-l-4 border-l-muted/30 shadow-sm",iconComponent:e(Oe,{className:"size-4 text-muted"}),sender:"Agent"};case ke.COMPLETE:return{...t,containerClass:"bg-white border-l-4 border-l-success shadow-sm",iconComponent:e(ze,{className:"size-4 text-success"}),sender:"Completed"};case ke.TERMINATED:return{...t,containerClass:"bg-white border-l-4 border-l-attention shadow-sm",iconComponent:e(ze,{className:"size-4 text-attention"}),sender:"Terminated"};case ke.QUESTION:return{...t,iconComponent:e(Re,{className:"size-4 text-muted"}),sender:"User"};case ke.THOUGHT:return{...t,iconComponent:a?e(dn,{size:"sm",color:"blue"}):e(Oe,{className:"size-4 text-muted"}),sender:"Agent"};case ke.ERROR:return{...t,iconComponent:e(Ae,{className:"size-4 text-muted"}),sender:"System"};case ke.UPDATE:return{...t,containerClass:"bg-white border-l-4 border-success shadow-sm",iconComponent:e(Fe,{className:"size-4 text-success"}),sender:"Update"};case ke.PLAN:return{...t,iconComponent:e(Ue,{className:"size-4 text-muted"}),sender:"Agent"};default:return{...t,sender:"Agent"}}})(),v=()=>{let e="";if(r.message&&(e="object"==typeof r.message?JSON.stringify(r.message,null,2):r.message.trim?r.message.trim():String(r.message)),"string"==typeof e&&e.includes("%thinking_message%")){const t=Math.floor(Math.random()*fn.length);e=e.replace(/%thinking_message%/g,fn[t])}return e},x=r=>"object"==typeof r?e("pre",{className:"text-xs font-mono whitespace-pre-wrap overflow-x-auto bg-gray-100 dark:bg-gray-800 p-2 rounded text-gray-700 ",children:JSON.stringify(r,null,2)}):e("div",{className:"vprose prose-sm",children:e(jt,{remarkPlugins:[_t],components:{a:({node:t,...n})=>{const r=n.href||"";return r.includes("/store/objects")?e(kt,{href:r,topLevelNav:!0,children:n.children}):e("a",{...n,target:"_blank",rel:"noopener noreferrer"})},img:({node:t,...n})=>e("img",{...n,className:"max-w-full h-auto rounded-lg shadow-md my-3 cursor-pointer hover:shadow-lg transition-shadow",loading:"lazy",onClick:()=>n.src&&window.open(n.src,"_blank")}),code:({node:r,className:a,children:s,...i})=>{const l=/language-(\w+)/.exec(a||""),o=!l,c=l?l[1]:"";return t(n,{children:[!o&&c&&e("div",{className:"code-language-indicator",children:c}),e("code",{...i,children:s})]})},p:t=>e("p",{...t}),strong:t=>e("strong",{...t}),em:t=>e("em",{...t}),pre:t=>e("pre",{...t}),h1:t=>e("h1",{...t}),h2:t=>e("h2",{...t}),h3:t=>e("h3",{...t}),li:t=>e("li",{...t}),ul:t=>e("ul",{...t}),ol:t=>e("ol",{...t}),blockquote:t=>e("blockquote",{...t}),hr:t=>e("hr",{...t}),table:t=>e("div",{className:"overflow-x-auto",children:e("table",{...t})}),th:t=>e("th",{...t}),td:t=>e("td",{...t})},children:r})}),w=v();c((()=>{(async()=>{if(w){u(!0);try{const e=await(async e=>{if("string"!=typeof e)return e;let t=e;t=t.replace(/\[([^\]]+)\]\((store|collection):([a-f\d]{24})\)/gi,((e,t,n,r)=>`[${t}](/store/${"store"===n?"objects":"collections"}/${r})`));const n=Array.from(t.matchAll(/!\[([^\]]*)\]\(image:([^)]+)\)/g)),r=await Promise.all(n.map((async e=>{const[t,n,r]=e;try{return{fullMatch:t,replacement:`![${n}](${(await h.files.getDownloadUrl(r)).url})`}}catch(e){return console.error(`Failed to get download URL for image: ${r}`,e),{fullMatch:t,replacement:t}}})));for(const{fullMatch:e,replacement:n}of r)t=t.replace(e,n);return t})((e=>{if("string"!=typeof e)return e;if(r.type===ke.THOUGHT||"string"==typeof r.message&&(r.message.toLowerCase().includes("thinking about")||r.message.toLowerCase().includes("i'm thinking")||r.message.toLowerCase().includes("💭"))){let t=e;return/\d+\.\s+.+/.test(t)&&(t=t.replace(/(\d+\.\s+.+?)(?=\s+\d+\.\s+|$)/g,"$1\n\n"),t=t.replace(/(\d+\.\s+.+\n)([^\d\n][^:])/g,"$1 $2")),t.includes(":")&&!t.includes("\n\n")&&(t=t.replace(/\b(First|Next|Then|Finally|Lastly|Additionally|Step \d+):\s+/gi,"\n\n$&")),t.includes(" - ")&&(t=t.replace(/\s+-\s+/g,"\n- ")),t}return/\d+\.\s+.+/.test(e)&&!e.includes("\n\n")?e.replace(/(\d+\.\s+.+?)(?=\s+\d+\.\s+|$)/g,"$1\n\n"):e})(w));d(e)}catch(e){console.error("Error processing message content:",e),d(w)}finally{u(!1)}}})()}),[w,h]);const N=yn(r),k=(()=>{switch(r.type){case ke.ANSWER:return"border-l-info bg-info";case ke.COMPLETE:return"border-l-success bg-success";case ke.IDLE:return"border-l-muted bg-muted";case ke.REQUEST_INPUT:return"border-l-attention bg-attention";case ke.QUESTION:return"border-l-muted bg-muted";case ke.THOUGHT:return"border-l-accent dark:border-l-purple-500 bg-purple-50/50 dark:bg-purple-900/10";case ke.ERROR:return"border-l-destructive bg-destructive";case ke.UPDATE:return"border-l-success bg-success";case ke.PLAN:return"border-l-attention bg-attention";case ke.TERMINATED:return"border-l-muted bg-muted";default:return"border-l-indigo-500 dark:border-l-indigo-400 bg-indigo-50/50 dark:bg-indigo-900/10"}})();return t("div",{className:`border-l-4 shadow-md overflow-hidden bg-white dark:bg-gray-900 mb-5 ${k}`,"data-workstream-id":N,children:[t("div",{className:"flex items-center justify-between px-4 py-2 border-b border-gray-100/80 dark:border-gray-800/80 bg-white/50 dark:bg-gray-900/50 backdrop-blur-sm",children:[t("div",{className:"flex items-center gap-2",children:[e("div",{className:a?"animate-fadeIn":"",children:(()=>{const t=(()=>{switch(r.type){case ke.ANSWER:return"text-info";case ke.COMPLETE:return"text-success";case ke.IDLE:return"text-muted";case ke.REQUEST_INPUT:return"text-attention";case ke.QUESTION:return"text-muted";case ke.THOUGHT:return"text-purple-600 dark:text-purple-400";case ke.ERROR:return"text-destructive";case ke.UPDATE:return"text-success";case ke.PLAN:return"text-attention";default:return"text-muted"}})(),n=t=>("number"==typeof r.timestamp?r.timestamp:new Date(r.timestamp).getTime())%2==0?e(dn,{size:"sm",color:t}):e(cn,{color:t});switch(r.type){case ke.ANSWER:return a?n("blue"):e(Oe,{className:`size-4 ${t}`});case ke.COMPLETE:case ke.TERMINATED:return e(ze,{className:`size-4 ${t}`});case ke.IDLE:return e(Le,{className:`size-4 ${t}`});case ke.REQUEST_INPUT:case ke.QUESTION:return e(Re,{className:`size-4 ${t}`});case ke.THOUGHT:return a?n("purple"):e(Oe,{className:`size-4 ${t}`});case ke.ERROR:return e(Ae,{className:`size-4 ${t}`});case ke.UPDATE:return a?n("green"):e(Fe,{className:`size-4 ${t}`});case ke.PLAN:return a?n("amber"):e(Ue,{className:`size-4 ${t}`});default:return a?n("blue"):e(Oe,{className:`size-4 ${t}`})}})()}),e("span",{className:"text-xs font-medium text-muted ",children:g.sender}),"main"!==N&&"all"!==N&&e(b,{variant:"default",className:"text-xs text-muted",children:N})]}),t("div",{className:"flex items-center gap-2",children:[e("span",{className:"text-xs text-muted",children:St(r.timestamp).format("HH:mm:ss")}),e(y,{variant:"ghost",size:"xs",onClick:()=>{const e=v()||"",t="string"==typeof r.details?r.details:r.details?JSON.stringify(r.details,null,2):"",n=[e,t?"\n\nDetails:\n"+t:""].join("").trim();navigator.clipboard.writeText(n).then((()=>{p({status:"success",title:"Copied to clipboard",duration:2e3})}))},className:"text-muted",title:"Copy message",children:e(De,{className:"size-3"})})]})]}),t("div",{className:"px-4 py-3 bg-white dark:bg-gray-900",children:[w&&e("div",{className:"message-content",children:m?t("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[e(cn,{color:"blue"}),e("span",{children:"Loading images..."})]}):x(l||w)}),r.details&&t("div",{className:"mt-2",children:[t("button",{onClick:()=>i(!s),className:"text-xs text-muted flex items-center",children:[s?"Hide":"Show"," details",e("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3 w-3 ml-1 transition-transform "+(s?"rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),s&&e("div",{className:"mt-2 p-2 bg-muted border border-mixer-muted/40 rounded text-sm",children:"string"==typeof r.details?x(r.details):e("pre",{className:"text-xs font-mono whitespace-pre-wrap overflow-x-auto bg-muted p-2 rounded text-muted ",children:JSON.stringify(r.details,null,2)})})]})]})]})}function xn({workstreams:n,activeWorkstream:r,onSelectWorkstream:a,count:s,completionStatus:i}){const l=new Map;l.set("all","All Messages"),l.set("main","Main"),n.forEach(((e,t)=>{"all"!==t&&"main"!==t&&"research_france"!==t&&"statistics"!==t&&l.set(t,e)})),n=l;const o=Array.from(n.entries()).sort((([e],[t])=>"all"===e?-1:"all"===t?1:"main"===e?-1:"main"===t?1:e.localeCompare(t))),c=o.length>2;return e("div",c?{className:"flex overflow-x-auto space-x-1 pb-2 mb-2 border-b-2 border-blue-200 dark:border-blue-900 sticky top-0 bg-white dark:bg-gray-900 z-10 pt-1",children:o.map((([n,l])=>t("button",{className:"px-3 py-1.5 text-xs font-medium whitespace-nowrap transition-colors flex items-center gap-1.5\n "+(r===n?"bg-blue-200 text-blue-800 dark:bg-blue-800 dark:text-blue-200 border-b-2 border-blue-500":"text-gray-600 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-800/30 border-b-2 border-transparent"),onClick:()=>a(n),title:l.length>20?l:void 0,children:[l.length>20?l.substring(0,18)+"...":l,s&&s.has(n)&&s.get(n)>0&&t("div",{className:"flex items-center space-x-1",children:[e("span",{className:"inline-flex items-center justify-center w-4 h-4 text-xs\n "+(r===n?"bg-blue-200 text-blue-800 dark:bg-blue-800 dark:text-blue-200":"bg-gray-200 text-gray-600 dark:bg-gray-700 dark:text-gray-300"),children:s.get(n)}),i&&"all"!==n&&(i.get(n)?e(ze,{className:"h-3 w-3 text-green-500"}):e(Le,{className:"h-3 w-3 text-amber-500"}))]})]},n)))}:{className:"py-1"})}function wn(e,t){return"all"===t?[...e]:"main"===t?e.filter((e=>"main"===yn(e))):e.filter((e=>yn(e)===t))}function Nn({messages:r,bottomRef:a,viewMode:s="stacked",isCompleted:d=!1,plan:m={plan:[]},workstreamStatus:u=new Map,showPlanPanel:h=!1,onTogglePlanPanel:p=()=>{},plans:g=[],activePlanIndex:f=0,onChangePlan:b=()=>{}}){const y=i.useRef(null),[v,x]=o("all");c((()=>{a.current&&a.current.scrollIntoView({behavior:"smooth"})}),[r,a]);const w=i.useMemo((()=>[...r].sort(((e,t)=>("number"==typeof e.timestamp?e.timestamp:new Date(e.timestamp).getTime())-("number"==typeof t.timestamp?t.timestamp:new Date(t.timestamp).getTime())))),[r]),N=i.useMemo((()=>{const e=function(e){const t=new Map;return t.set("all","All Messages"),t.set("main","Main"),e.forEach((e=>{e.workstream_id&&"main"!==e.workstream_id&&"all"!==e.workstream_id&&!t.has(e.workstream_id)&&(t.set(e.workstream_id,e.workstream_id),console.log(`Found workstream: ${e.workstream_id}`))})),t.size<=2&&!t.has("main")&&t.set("main","Main"),console.log("Final workstreams map:",t),t}(w);return e}),[w]),k=i.useMemo((()=>{const e=new Map;e.set("all",w.length);const t=wn(w,"main");return e.set("main",t.length),w.forEach((t=>{const n=yn(t);"main"!==n&&e.set(n,(e.get(n)||0)+1)})),e}),[w]),C=i.useMemo((()=>"all"===v?w:wn(w,v)),[w,v]),S=l((()=>{const e=new Map,t=new Map;w.forEach((e=>{const n=yn(e);t.has(n)||t.set(n,[]),t.get(n).push(e)}));for(const[n,r]of t.entries())if(r.length>0){const t=r[r.length-1];e.set(n,[ke.COMPLETE,ke.IDLE,ke.REQUEST_INPUT,ke.TERMINATED].includes(t.type))}return e}),[w]);return t("div",{ref:y,className:"flex-1 min-h-0 h-full overflow-y-auto py-2 px-4 sm:px-6 lg:px-8 flex flex-col relative","data-testid":"all-messages-mixed",style:h?{paddingRight:"350px"}:{},children:[e(gn,{plan:m,workstreamStatus:u,isOpen:h,onClose:p,plans:g,activePlanIndex:f,onChangePlan:b}),e("div",{className:"sticky top-0 bg-white dark:bg-gray-900 z-10",children:e(xn,{workstreams:N,activeWorkstream:v,onSelectWorkstream:x,count:k,completionStatus:S})}),0===C.length?e("div",{className:"flex items-center justify-center h-full text-center py-8",children:e("div",{className:"flex items-center px-4 py-3 text-gray-500 dark:text-gray-400",children:"all"===v?"Waiting for agent response...":"No messages in this workstream yet..."})}):t("div",{className:"flex-1 flex flex-col justify-start pb-4 space-y-2",children:["stacked"===s?C.map(((t,n)=>{const r=!d&&n===C.length-1&&!bn.includes(t.type);return e(vn,{message:t,showPulsatingCircle:r},`${t.timestamp}-${n}`)})):e(n,{children:(()=>{const t=C.filter((e=>e.type===ke.ANSWER||e.type===ke.QUESTION||e.type===ke.COMPLETE||e.type===ke.TERMINATED)),n=d?null:C.filter((e=>e.type===ke.THOUGHT||e.type===ke.UPDATE||e.type===ke.PLAN)).sort(((e,t)=>{const n="number"==typeof e.timestamp?e.timestamp:new Date(e.timestamp).getTime();return("number"==typeof t.timestamp?t.timestamp:new Date(t.timestamp).getTime())-n}))[0],r=[...t];return n&&r.push(n),r.sort(((e,t)=>("number"==typeof e.timestamp?e.timestamp:new Date(e.timestamp).getTime())-("number"==typeof t.timestamp?t.timestamp:new Date(t.timestamp).getTime()))),r.map(((t,n)=>{const a=!d&&n===r.length-1&&!bn.includes(t.type);return e(vn,{message:t,showPulsatingCircle:a},`${t.timestamp}-${n}`)}))})()}),e("div",{ref:a,className:"h-4"})]})]})}class kn{vertesia;updateState;_interactive=!0;_debug_mode=!1;_collection;_start=!1;_preserveRunValues=!1;payload;_interactionParamsSchema;_inputValidator;constructor(e,t){this.vertesia=e,this.updateState=t,this.payload={config:{model:""},tool_names:[]}}onStateChanged(){const e=this.clone();this.updateState(e)}clone(){const e=new kn(this.vertesia,this.updateState);return e._interactionParamsSchema=this._interactionParamsSchema,e.payload=this.payload,e._interactive=this._interactive,e._debug_mode=this._debug_mode,e._inputValidator=this._inputValidator,e._start=this._start,e._collection=this._collection,e._preserveRunValues=this._preserveRunValues,e}get interactive(){return this._interactive}set interactive(e){e!==this._interactive&&(this._interactive=e,this.onStateChanged())}get debug_mode(){return this._debug_mode}set debug_mode(e){e!==this._debug_mode&&(this._debug_mode=e,this.onStateChanged())}get collection(){return this._collection}set collection(e){e!==this._collection&&(this._collection=e,this.onStateChanged())}get search_scope(){return this._collection?"collection":void 0}get interaction(){return this.payload.interaction}set interaction(e){e?.id!==this.payload.interaction?.id&&(this.payload.interaction=e,this._interactionParamsSchema=Ce(this.interaction),this._inputValidator=void 0,e&&!this._preserveRunValues&&(e.environment&&("string"==typeof e.environment?this.vertesia.environments.retrieve(e.environment).then((e=>this.environment=e)):this.payload.config.environment=e.environment),e.model?this.payload.config.model=e.model:this.payload.config.model=this.environment?.default_model&&Se(this.environment.default_model,this.environment.provider)?this.environment.default_model:void 0),this.onStateChanged())}get environment(){return this.payload.config.environment}set environment(e){e?.id!==this.payload.config.environment?.id&&(this.payload.config.environment=e,this._preserveRunValues||(this.payload.config.model=e?.default_model&&Se(e.default_model,e.provider)?e.default_model:void 0),this.onStateChanged())}get model(){return this.payload.config.model}set model(e){e!==this.payload.config.model&&(this.payload.config.model=e,this.onStateChanged())}get tool_names(){return this.payload.tool_names}set tool_names(e){this.payload.tool_names=e,this.onStateChanged()}get data(){return this.payload.data}set data(e){this.payload.data=e,this.onStateChanged()}get config(){return this.payload.config}set run(e){console.log("run",e),this.onStateChanged()}set start(e){this._start!==e&&(this._start=e,this.onStateChanged())}get start(){return this._start}get preserveRunValues(){return this._preserveRunValues}set preserveRunValues(e){this._preserveRunValues=e}get interactionParamsSchema(){return this._interactionParamsSchema}set interactionParamsSchema(e){this._interactionParamsSchema!==e&&(this._interactionParamsSchema=e,this.onStateChanged())}reset(){if(this._start=!1,this._interactive=!0,this._debug_mode=!1,this._collection=void 0,this._preserveRunValues=!1,this.payload={config:{environment:void 0,model:""},tool_names:[],interaction:void 0,data:void 0},this._interactionParamsSchema=null,this._inputValidator=void 0,this.model=void 0,this.environment=void 0,this.onStateChanged(),location.hash){const e=window.location.origin+window.location.pathname+window.location.search;history.replaceState(null,"",e),location.hash=""}}validateInput(){if(!this._interactionParamsSchema)return{isValid:!0};if(!this._inputValidator||this._inputValidator.schema!==this._interactionParamsSchema){const e=new Pt({strict:!1});this._inputValidator={validate:e.compile(this._interactionParamsSchema),schema:this._interactionParamsSchema}}const e=this.payload.data||{};if(!this._inputValidator.validate(e)){return{isValid:!1,errorMessage:this._inputValidator.validate.errors?this._inputValidator.validate.errors.map((e=>`${e.instancePath}: ${e.message}`)).join(", "):"Invalid payload data"}}return{isValid:!0}}}const Cn=d(void 0);function Sn({children:t}){const{client:n}=Ie(),[r,a]=o();return c((()=>{a(new kn(n,a))}),[]),r&&e(Cn.Provider,{value:r,children:t})}function jn(){const e=m(Cn);if(!e)throw new Error("usePayloadBuilder must be used within a PayloadProvider");return e}function _n({title:n,onClose:r,isModal:a,run:s,viewMode:i,onViewModeChange:l,showPlanPanel:o,hasPlan:c=!1,onTogglePlanPanel:d,onDownload:m,onCopyRunId:u,resetWorkflow:h}){return e(Sn,{children:t("div",{className:"flex items-center justify-between py-1.5 px-2 border-b shadow-sm flex-shrink-0",children:[t("div",{className:"flex flex-wrap items-center space-x-2",children:[t("div",{className:"flex items-center space-x-1",children:[e(Oe,{className:"size-5 text-muted"}),e("span",{className:"font-medium",children:n})]}),t("span",{className:"text-xs text-muted ml-1",children:["(Run ID: ",s.runId.substring(0,8),"...)"]})]}),t("div",{className:"flex items-center space-x-2",children:[t("div",{className:"flex items-center space-x-1 bg-muted rounded p-0.5",children:[e(y,{variant:"stacked"===i?"outline":"ghost",size:"xs",className:"rounded-l-md",onClick:()=>l("stacked"),children:"Details"}),e(y,{variant:"sliding"===i?"outline":"ghost",size:"xs",className:"rounded-l-md",onClick:()=>l("sliding"),children:"Most Important"})]}),t("div",{className:"relative",children:[c&&!o&&e("span",{className:"absolute -top-1 -right-1 w-2.5 h-2.5 bg-primary rounded-full border border-border z-10"}),t(y,{size:"sm",variant:o?"primary":"secondary",onClick:d,className:"transition-all duration-200 rounded-md",title:"Toggle plan panel",children:[e(Me,{className:"size-4 mr-1.5"}),e("span",{className:"font-medium text-xs",children:o?"Hide Plan":"Show Plan"})]})]}),e(Pn,{run:s,isModal:a,onClose:r,onDownload:m,onCopyRunId:u,resetWorkflow:h}),r&&!a&&e(y,{size:"xs",variant:"ghost",onClick:r,children:e(Ve,{className:"size-4"})})]})]})})}function Pn({run:n,isModal:r,onClose:a,onDownload:s,onCopyRunId:i,resetWorkflow:l}){const o=f(),{client:c}=Ie(),d=jn();return t(v,{hover:!0,children:[e(x,{children:e(y,{size:"xs",variant:"ghost",title:"More actions",children:e(qe,{className:"size-4"})})}),e(w,{className:"w-48",align:"end",children:e("div",{className:"rounded-md shadow-lg z-50",children:e("div",{className:"py-1 min-w-36",children:e(N,{children:e(k,{children:t(C,{children:[e("div",{className:"flex items-center px-3 py-1.5 text-xs text-gray-700 dark:text-gray-300",children:e("span",{className:"text-muted",children:"Actions"})}),r&&t(S,{className:"text-xs",onSelect:()=>{return e=`/store/agent-runner?agentId=${n.runId}__${n.workflowId}`,window.open(e,"_blank"),e;var e},children:[e(We,{className:"size-3.5 mr-2 text-muted"})," Open in new tab"]}),t(S,{className:"text-xs",onSelect:()=>{i?i():(navigator.clipboard.writeText(n.runId),o({status:"success",title:"Run ID copied",duration:2e3}))},children:[e(De,{className:"size-3.5 mr-2 text-muted"})," Copy Run ID"]}),t(S,{className:"text-xs",onSelect:()=>{s?s():async function(e,t){return e.files.getDownloadUrl(`agents/${t}/conversation.json`).then((e=>e.url))}(c,n.runId).then((e=>window.open(e,"_blank")))},children:[e(Be,{className:"size-3.5 mr-2 text-muted"})," Download Conversation"]}),a&&r&&t(S,{className:"text-xs",onSelect:a,children:[e(Ve,{className:"size-3.5 mr-2 text-muted"})," Close"]}),t(S,{className:"text-xs text-destructive",onSelect:()=>{(async e=>{try{return await c.store.workflows.terminate(e.workflowId,e.runId,"cancel"),o({status:"success",title:"Workflow cancelled",duration:2e3}),d.reset(),l?.(),!0}catch(e){return o({status:"error",title:"Failed to cancel workflow",duration:2e3}),!1}})(n)},children:[e(Ve,{className:"size-3.5 mr-2 text-destructive"})," Cancel Workflow"]})]})})})})})})]})}const Tn="vertesia.content_store.lastDisplayedView";function In({onUpdate:t}){const[n,r]=o("grid"===localStorage.getItem(Tn)),a=()=>{localStorage.setItem(Tn,"grid"),r(!0),t(!0)},s=()=>{localStorage.setItem(Tn,"table"),r(!1),t(!1)};return e(y,{variant:"outline",onClick:()=>{n?s():a()},alt:n?"Table View":"Thumbnail View",children:e(n?Je:Ge,{})})}In.LAST_DISPLAYED_VIEW=Tn;class $n extends A{labelOf(e){return e.label}idOf(e){return e.id}renderOption(n){return t("div",{children:[e("div",{className:"font-medium",children:n.label}),e("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:n.description})]})}}function En({isOpen:n,onClose:r,onConfirm:a,isLoading:s,uploadedFileName:i}){const l=[{id:"update",label:"Update current version",description:i?"Replace the content file and modify properties directly in the current revision.":"Modify the properties directly in the current revision."},{id:"new-version",label:"Create new version",description:i?"Create a new revision with the replacement file while preserving the original.":"Create a new revision with these property changes while preserving the original."}],[c,d]=o(l[0]),[m,u]=o(""),h=new $n,p="new-version"===c?.id;return t(j,{isOpen:n,onClose:r,className:"sm:max-w-md",children:[e(_,{children:"Save Changes"}),e(P,{children:t("div",{className:"space-y-4",children:[i&&e("div",{className:"mb-4 p-3 bg-blue-50 dark:bg-blue-900/20 rounded-md",children:t("p",{className:"text-sm text-blue-700 dark:text-blue-300 font-medium",children:["You're about to replace the content file with: ",e("span",{className:"font-bold",children:i})]})}),e("p",{className:"text-sm text-mixer-muted/5",children:"How would you like to save these changes?"}),e(T,{adapter:h,options:l,value:c,onChange:e=>{d(e)},gap:"gap-4"}),p&&e(I,{label:"Version Label (Optional)",description:"Optional label for the new version.",className:"mt-3 pl-8",children:e($,{value:m,onChange:u,placeholder:"e.g., v1.2, approved, post-review",className:"w-full"})})]})}),t(E,{children:[e(y,{variant:"secondary",onClick:r,disabled:s,children:"Cancel"}),e(y,{variant:"primary",onClick:async()=>{await a(p,p?m:void 0)},isLoading:s,children:"Save"})]})]})}function An({isOpen:r,onClose:a,object:s,refetch:i}){const{client:l,store:d}=Ie(),m=f(),h=Ct(),[p,g]=o(!1),[b,v]=o(""),[x,w]=o(!1),[N,k]=o(null),C=u(null),S=u(null),[T,I]=o(null),[$,A]=o(null);function L(e,t){e.languages.json.jsonDefaults.setDiagnosticsOptions({validate:!0,schemas:[{uri:"http://myserver/object-schema.json",fileMatch:["*"],schema:t}]})}return c((()=>{r&&(v(JSON.stringify(s.properties||{},null,2)),s.type?.id&&async function(e){try{const t=await d.types.retrieve(e);t.object_schema&&(I(t.object_schema),S.current&&L(S.current,t.object_schema))}catch(e){console.error("Failed to fetch JSON schema:",e)}}(s.type.id))}),[r,s]),t(n,{children:[t(j,{isOpen:r,onClose:a,className:"sm:max-w-[90%] md:max-w-[80%] lg:max-w-[75%] xl:max-w-[70%]",children:[e(_,{children:"Edit Properties"}),t(P,{children:[t("div",{className:"mb-2 text-sm text-gray-500",children:[s.type?.name?t("span",{children:["Editing properties for object type: ",e("strong",{children:s.type.name})]}):e("span",{children:"Editing properties for generic document"}),T&&e("span",{className:"ml-2 text-green-600",children:"(JSON schema validation enabled)"})]}),e("div",{className:"h-[75vh] border border-gray-300 dark:border-gray-700 rounded-md",children:e(Mt,{height:"100%",language:"json",value:b,onChange:e=>v(e||""),onMount:function(e,t){C.current=e,S.current=t,T&&L(t,T)},options:{minimap:{enabled:!1},scrollBeyondLastLine:!1,formatOnPaste:!0,formatOnType:!0,automaticLayout:!0,wordWrap:"on"}})})]}),t(E,{children:[e(y,{variant:"secondary",onClick:a,children:"Cancel"}),e(y,{variant:"primary",onClick:function(){if(!C.current)return;const e=C.current.getValue();try{const t=JSON.parse(e);k(t),w(!0)}catch(e){m({status:"error",title:"Invalid JSON",description:"Please fix the JSON syntax errors before saving.",duration:5e3})}},children:"Save Changes"})]})]}),e(En,{isOpen:x,onClose:function(){w(!1)},onConfirm:async function(e,t){try{g(!0);const n=N||JSON.parse(b);if(e){const e=await l.objects.update(s.id,{properties:n},{createRevision:!0,revisionLabel:t});e.id!==s.id&&A(e.id),m({status:"success",title:"New version created",description:"A new version with updated properties has been created.",duration:2e3}),w(!1),a(),e.id!==s.id&&setTimeout((()=>{h(`/objects/${e.id}`),m({status:"info",title:"Viewing New Version",description:t?`Now viewing version '${t}'`:"Now viewing the new version",duration:3e3})}),100)}else await d.objects.update(s.id,{properties:n}),m({status:"success",title:"Properties updated",description:"The object properties have been updated successfully.",duration:2e3}),i&&await i(),w(!1),a()}catch(e){m({status:"error",title:"Error updating properties",description:e.message||"An error occurred while updating the properties.",duration:5e3}),g(!1)}},isLoading:p})]})}function Ln({object:r,loadText:a,refetch:s}){const{client:i,store:l}=Ie(),[d,m]=o(!1),[u,h]=o(r.text),[p,g]=o(),[b,v]=o(!1),x=f(),[w,N]=o(!1);c((()=>{a&&!u&&(m(!0),l.objects.getObjectText(r.id).then((e=>{h(e.text)})).catch((e=>{console.error("Failed to load text",e)})).finally((()=>{m(!1)})))}),[a]);const k=async(e,t)=>{try{await navigator.clipboard.writeText(e),x({status:"success",title:("text"===t?"Content":"Properties")+" copied",description:`Successfully copied ${t} to clipboard`,duration:2e3})}catch(e){console.error(`Failed to copy ${t}:`,e),x({status:"error",title:"Copy failed",description:`Failed to copy ${t} to clipboard`,duration:5e3})}},C=async e=>{try{const t=await i.objects.getRendition(r.id,{format:e,generate_if_missing:!0,sign_url:!0});if("generating"===t.status)return x({status:"info",title:"Generating document",description:`Please wait while we prepare your ${e.toUpperCase()} file...`,duration:5e3}),void setTimeout((()=>C(e)),3e3);if("failed"===t.status)throw new Error("Document generation failed");if(t.renditions&&t.renditions.length>0){const n=t.renditions[0];if("pdf"===e)window.open(n,"_blank"),x({status:"success",title:"PDF opened",description:"PDF document opened in a new window",duration:2e3});else{const t=document.createElement("a");t.href=n,t.download=`${r.name||"document"}.${e}`,document.body.appendChild(t),t.click(),document.body.removeChild(t),x({status:"success",title:"Document exported",description:`Successfully exported to ${e.toUpperCase()} format`,duration:2e3})}}}catch(t){console.error(`Failed to export document as ${e}:`,t),x({status:"error",title:"Export failed",description:`Failed to export document to ${e.toUpperCase()} format`,duration:5e3})}},S=r.content,j=S&&S.source&&S.type&&S.type.startsWith("image/"),_=S&&S.type&&("text/markdown"===S.type||"text/plain"===S.type),P=u&&(u.includes("\n#")||u.includes("\n*")||u.includes("\n+")||u.includes("!["));return c((()=>{j&&i.objects.getRendition(r.id,{format:je.jpeg,generate_if_missing:!1,sign_url:!0}).then((e=>"found"===e.status?e.renditions?.length?e.renditions[0]:null:r)).catch((()=>r)).then((()=>{i.files.getDownloadUrl(r.content.source).then((e=>{g(e.url)}))}))}),[]),t("div",{className:"w-full",children:[t("div",{className:"flex flex-col lg:flex-row lg:gap-8",children:[t("div",{className:"w-full lg:w-1/2",children:[t("div",{className:"h-[41px] text-lg font-semibold mb-4 border-b flex justify-between items-center",children:[t("div",{className:"flex items-center gap-1",children:["Properties",e(y,{variant:"outline",size:"sm",alt:""+(w?"Preview":"View in JSON format"),onClick:()=>N(!w),children:w?"Preview":"JSON"})]}),t("div",{className:"flex items-center gap-2",children:[r.properties&&e(y,{variant:"ghost",size:"sm",title:"Copy properties",onClick:()=>k(JSON.stringify(r.properties,null,2),"properties"),children:e(He,{className:"size-4"})}),e(y,{variant:"ghost",size:"sm",onClick:()=>{v(!0)},title:"Edit properties",className:"flex items-center gap-2",children:e(Ke,{className:"size-4"})})]})]}),r.properties?e(It,{value:r.properties,viewCode:w}):e("div",{children:"No properties defined"}),j&&t("div",{className:"my-4",children:[e("div",{className:"h-[41px] text-lg font-semibold mb-4 border-b flex justify-between items-center",children:e("span",{className:"py-1",children:"Image"})}),p?e("img",{src:p,alt:r.name,className:"w-full object-contain"}):e(L,{size:"md"})]})]}),t("div",{className:"w-full lg:w-1/2 mt-4 lg:mt-0",children:[t("div",{className:"h-[41px] text-lg font-semibold mb-4 border-b flex justify-between items-center",children:[e("span",{className:"py-1",children:"Text"}),t("div",{className:"flex items-center gap-2",children:[u&&e(y,{variant:"ghost",size:"sm",title:"Copy text",onClick:()=>k(u,"text"),className:"flex items-center gap-2",children:e(He,{className:"h-4 w-4"})}),(_||P)&&u&&t(n,{children:[t(y,{variant:"ghost",size:"sm",onClick:()=>C("docx"),className:"flex items-center gap-2",children:[e(Ye,{className:"h-4 w-4"}),"DOCX"]}),t(y,{variant:"ghost",size:"sm",onClick:()=>C("pdf"),className:"flex items-center gap-2",children:[e(Ye,{className:"h-4 w-4"}),"PDF"]})]})]})]}),d&&e(L,{size:"md"}),e("div",u?{className:"border shadow-xs rounded-xs max-w-7xl",children:P?e("div",{className:"vprose prose-sm p-1",children:e(jt,{remarkPlugins:[_t],components:{a:({node:t,...n})=>{const r=n.href||"";return r.includes("/store/objects/")?e(kt,{topLevelNav:!0,href:r,className:"text-info",children:n.children}):e("a",{...n,"data-debug":"test",target:"_blank",rel:"noopener noreferrer"})},p:({node:t,...n})=>e("p",{...n,className:"my-0"}),pre:({node:t,...n})=>e("pre",{...n,className:"my-2 p-2 rounded"}),code:({node:t,className:n,children:r,...a})=>{const s=/language-(\w+)/.exec(n||"");return e("code",{...a,className:!s?"px-1.5 py-0.5 rounded":"text-muted",children:r})},h1:({node:t,...n})=>e("h1",{...n,className:"font-bold text-2xl my-2"}),h2:({node:t,...n})=>e("h2",{...n,className:"font-bold text-xl my-2"}),h3:({node:t,...n})=>e("h3",{...n,className:"font-bold text-lg my-2"}),li:({node:t,...n})=>e("li",{...n})},children:u})}):e("pre",{className:"text-wrap bg-muted text-muted p-2",children:u})}:{children:"No content"})]})]}),e(An,{isOpen:b,onClose:()=>{v(!1)},object:r,refetch:s})]})}function zn(e,t=7){return e?"~"+e.slice(-t):""}function Dn(e,t){return e.length>t?e.substring(0,t)+"...":e}const On="text/csv",Un="image/",Fn="application/pdf",Rn="video/",Mn=e=>e===On||On.includes(e),Vn=e=>e.startsWith(Un)||Un.includes(e),qn=e=>e===Fn||Fn.includes(e),Wn=e=>e.startsWith(Rn)||Rn.includes(e),Bn=import.meta.env,Jn={max_hw:Bn?.VITE_RENDITION_HW||256,format:je.jpeg,generate_if_missing:!0},Gn="vertesia.content_store.renditionId";async function Hn(e,t,n,r,a){if(!t?.content?.type||!(Vn(t.content.type)||Wn(t.content.type)||qn(t.content.type)))return void a("No preview available");a("Preparing preview...");const s=(new Date).getTime()/1e3,i=localStorage.getItem(`${Gn}_${t.id}_${Jn.max_hw}`),l=localStorage.getItem(`${Gn}_${t.id}_${Jn.max_hw}_time`);if(i?.length&&l&&Math.abs(s-parseInt(l))<=900)return n(i),r(`${t.name} Rendition`),a("ready"),i;a("Preparing preview..."),e.objects.getRendition(t.id,Jn).then((s=>{if("generating"===s.status)a("Preparing preview..."),n(""),r(""),setTimeout((()=>Hn(e,t,n,r,a)),6e4);else{if("failed"===s.status)return a("No preview available"),n(""),void r("");{if(!s?.renditions?.length)return a("No preview available"),n(""),void r("");const e=s.renditions[0];localStorage.setItem(`${Gn}_${t.id}_${Jn.max_hw}`,e),localStorage.setItem(`${Gn}_${t.id}_${Jn.max_hw}_time`,((new Date).getTime()/1e3).toString()),n(e),r(`${t.name} Rendition`),a("ready"),console.log(`Rendition for document ${t.id} retrieved successfully: ${e}`)}}})).catch((e=>{a("No preview available"),console.warn("Failed to retrieve rendition:",e),n(""),r("")}))}function Kn({selection:n,document:r,onSelectionChange:a,onRowClick:s}){const{client:i}=Ie(),[l,d]=o(void 0),[m,u]=o(void 0),[h,p]=o(void 0);return c((()=>{r?.content&&Hn(i,r,d,u,p)}),[r]),t(z,{className:"relative flex flex-col border h-fit",onClick:()=>s&&s(r),children:[n&&e("div",{className:"absolute top-2 left-2 z-10 flex flex-col items-center gap-1",children:e("input",{checked:n.isSelected(r.id),type:"checkbox",onChange:e=>{e.stopPropagation(),a(r,e)},onClick:e=>e.stopPropagation()})}),e("div",{className:"absolute top-1 right-1 z-10 flex flex-col items-center",children:e(kt,{topLevelNav:!0,href:`/store/objects/${r.id}`,children:e(y,{variant:"ghost",size:"sm",title:"Open Object",children:e(Qe,{className:"size-4 "+("ready"===h?"text-muted":"text-white")})})})}),l&&"ready"==h?e("img",{src:l,alt:m,className:"w-auto h-48 object-cover rounded-t-xl"}):e("div",{className:"h-48 bg-gray-700 rounded-t-xl flex items-center justify-center text-muted",children:h}),e(D,{className:"bg-gray-200 h-[2px]"}),e(O,{className:"p-2 flex flex-col gap-1",children:t("div",{className:"flex flex-col",children:[e(U,{placement:"top",description:r.properties?.title??r.name,children:e("h3",{className:"text-start font-medium leading-none truncate",children:r.properties?.title??r.name})}),r?.type?.name?e(U,{placement:"bottom",size:"xs",description:r?.type?.name,children:e("p",{className:"text-start text-xs text-muted truncate",children:r?.type?.name})}):e("p",{className:"text-xs text-muted",children:" "})]})})]})}function Yn(e){return`${e._id} (${e.count})`}function Qn(e){return`${e.name} (${e.count})`}function Xn({search:t,buckets:n,placeholder:r="All Environments",className:a}){const{client:s}=Ie(),[i,l]=o([]),d=t.getFilterValue("environment");c((()=>{if(s){const e=n.map((async e=>{let t;return await s.environments.retrieve(e._id).then((e=>{t=e.name})).catch((()=>{t=`${e._id} (deleted)`})),t||(t=e._id),{...e,name:t}}));Promise.all(e).then((e=>{e.sort(((e,t)=>e.name.localeCompare(t.name))),l(e)}))}}),[n,s]);const m=i?.find((e=>e._id===d));return e(F,{filterBy:"name",className:a,isClearable:!0,optionLabel:Qn,options:i,value:m,onChange:e=>{t.setFilterValue("environment",e?._id)},by:"_id",placeholder:r})}function Zn({search:t,buckets:n,name:r,placeholder:a,className:s}){const i=t.getFilterValue(r),l=n?.find((e=>JSON.stringify(e._id)===JSON.stringify(i)));return e(F,{filterBy:"_id",className:s,isClearable:!0,optionLabel:Yn,options:n,value:l,onChange:e=>{t.setFilterValue(r,e?._id)},by:"_id",placeholder:a})}function er({search:t,name:n,placeholder:r,className:a}){const[s,i]=o([]);return c((()=>{t.setFilterValue(n,s)}),[s]),e(R,{className:a,value:s,onChange:i,placeholder:r})}function tr(e){return`${e.name} (${e.count})`}function nr({search:t,buckets:n,placeholder:r="Filter by Type",className:a}){const[s,i]=o([]),{typeRegistry:l}=Ie(),d=t.getFilterValue("type");c((()=>{if(l){const e=n.map((e=>{let t;return null==e._id?(e._id="Document",t="Document"):(t=l.getTypeName(e._id),t||(console.warn("Content Object Type not found",e._id),t=e._id)),{...e,name:t}}));e.sort(((e,t)=>e.name.localeCompare(t.name))),i(e)}}),[n,l]);const m=s?.find((e=>e._id===d));return e(F,{filterBy:"name",className:a,isClearable:!0,optionLabel:tr,options:s,value:m,onChange:e=>{t.setFilterValue("type",e?._id)},by:"_id",placeholder:r})}function rr({facets:n,search:r}){return t("div",{className:"flex items-center gap-x-4 w-full",children:[n.role&&e(Zn,{search:r,className:"flex-1",name:"role",buckets:n.role||[],placeholder:"Filter by Role"}),n.type&&e(nr,{search:r,className:"flex-1",buckets:n.type||[]}),n.status&&e(Zn,{search:r,className:"flex-1",name:"status",buckets:n.status||[],placeholder:"Filter by Status"}),n.location&&e(Zn,{search:r,className:"flex-1",name:"location",buckets:n.location||[],placeholder:"Filter by Location"}),n.tags&&e(er,{search:r,className:"flex-1",name:"tags",buckets:n.tags||[],placeholder:"Filter by Tags"})]})}function ar({search:n,textSearch:r=""}){const[a,s]=o([]),i=[];r&&i.push({placeholder:r,name:"name",type:"text",options:[]});return e(M,{filterGroups:i,filters:a,setFilters:e=>{const t="function"==typeof e?e(a):e;if(0===t.length)return n.clearFilters(),void s([]);s(t),n.clearFilters(!1),t.forEach((e=>{if(e.value&&e.value.length>0){const t=e.name.toLowerCase(),r="stringList"===e.type?e.value.map((e=>"string"==typeof e?e:e.value)):Array.isArray(e.value)&&e.value[0]&&"object"==typeof e.value[0]?e.value[0].value:e.value;if("name"===t)n.query.search_term=r,n.query.name=r;else n.query[t]=r}})),n.search()},children:t("div",{className:"flex gap-2 items-center",children:[e(V,{}),e(q,{}),e(W,{})]})})}function sr({buckets:e,name:t,placeholder:n,type:r,multiple:a}){return function({buckets:e,name:t,placeholder:n,type:r="select",multiple:a=!1}){return{name:t,options:e.map((e=>({label:Yn(e),value:e._id}))),type:r,multiple:a,placeholder:`${n??`${t.charAt(0).toUpperCase()+t.slice(1)}`}`,allowCreate:!1}}({buckets:e,name:t,placeholder:n,type:r,multiple:a})}function ir({buckets:n,typeRegistry:r,type:a="select",multiple:s=!1}){const i=new Map;n.forEach((e=>{let t,n=e._id;null==e._id?(n="Document",t="Document"):(t=r.getTypeName(e._id),t||(console.warn("Content Object Type not found",e._id),t=e._id)),i.set(n,{name:t,count:e.count})}));return{name:"Types",type:a,multiple:s,options:n.map((e=>({value:e._id||"Document",label:`(${e.count})`}))),labelRenderer:n=>{const r=i.get(n);return r?t("div",{className:"w-full flex items-center",children:[e("span",{className:"text-sm truncate",children:r.name}),t("span",{className:"ml-2 text-xs",children:["(",r.count,")"]})]}):(console.warn(`Type data not found for ${n}`),n)},filterBy:(e,t)=>{const n=i.get(e);return n?n.name.toLowerCase().includes(t.toLowerCase()):(console.warn(`Type name not found for ${e}`),!1)}}}const lr={};function or(e){const{client:t}=Ie();return B((()=>{let n=lr[e];return n||(n=t.users.retrieve(e).then((e=>e)),lr[e]=n),n}),[e])}function cr(){return e("div",{className:"size-8"})}function dr({showTitle:n=!1,size:r="md"}){return t(br,{title:"System User",description:"The system user is used to initialize built-in objects.",children:[e(J,{src:"/icon.svg",size:r}),n&&e("div",{className:"text-sm font-semibold pl-2",children:"System User"})]})}function mr({accountId:r,showTitle:a=!1,size:s="md"}){const i=t(n,{children:[e("div",{children:"This user is used by robots like workflow workers."}),t("div",{className:"text-gray-800 dark:text-gray-500 text-sm",children:[e("span",{className:"font-semibold",children:"ID:"})," ",r]})]});return e(br,{title:"Service Account",description:i,children:t("div",{className:"flex flex-row items-center gap-2",children:[e(J,{src:"/cloud.svg",name:"SA",color:"bg-amber-500",className:"px-[5px] text-white",size:s}),a&&t("div",{className:"text-sm font-semibold pl-2 truncate",children:["Service Account : ",r]})]})})}function ur({title:t="Error",error:n,showTitle:r=!1,size:a="md"}){return e(pr,{title:t,message:"string"==typeof n?n:n.message,color:"bg-red-500",showTitle:r,size:a})}function hr({userRef:t,showTitle:n=!1,size:r="md"}){if(!t)return e(pr,{title:"Unknown User",message:"User information is not available.",showTitle:n,size:r});const[a,s]=t?t.split(":"):["unknown"];switch(a){case _e.User:return e(gr,{userId:s,showTitle:n,size:r});case"system":return e(dr,{showTitle:n,size:r});case _e.ServiceAccount:return e(mr,{accountId:s,showTitle:n,size:r});case _e.ApiKey:return e(fr,{keyId:s,size:r,showTitle:n});default:return e(ur,{title:"Unknown User",error:`Invalid user ref type: ${a}`,showTitle:n,size:r})}}function pr({title:n,message:r,color:a,size:s="md",showTitle:i=!1}){return e(br,{title:n,description:r,children:t("div",{className:"flex flex-row items-center gap-2",children:[e(J,{color:a,size:s}),i&&e("div",{className:"text-sm font-semibold pl-1",children:n})]})})}function gr({userId:n,showTitle:r=!1,size:a="md"}){const{data:s,error:i}=or(n);if(i)return e(ur,{title:"Failed to fetch user",error:i,showTitle:r,size:a});if(!s)return e(cr,{});const l=e("div",{className:"truncate",title:s.email,children:s.email});return e(br,{title:s.name||s.email||s.username||"unknown",description:l,children:t("div",{className:"flex flex-row items-center gap-2",children:[e(J,{src:s.picture,name:s.name,color:"bg-indigo-500",size:a}),r&&e("div",{className:"text-sm font-semibold pl-2",children:s.name||s.email||s.username||"unknown"})]})})}function fr({keyId:n,showTitle:r=!1,size:a="md"}){const{client:s}=Ie(),{data:i,error:l}=B((()=>s.apikeys.retrieve(n)),[]);if(l)return e(ur,{title:"Failed to fetch the apikey",error:l,showTitle:r,size:a});if(!i)return e(cr,{});const o=e(J,{name:"PK",color:"bg-pink-500",size:a}),c=t(G,{className:"dark:bg-gray-800 dark:text-gray-200 table-fixed w-full",children:[t("tr",{children:[e("td",{className:"font-semibold w-20",children:"Key:"}),e("td",{className:"truncate max-w-0",children:i?.name})]}),t("tr",{children:[e("td",{className:"font-semibold w-20",children:"Account:"}),e("td",{className:"truncate max-w-0",children:i?.account})]}),t("tr",{children:[e("td",{className:"font-semibold w-20",children:"Project:"}),e("td",{className:"truncate max-w-0",children:i?.project})]})]});return e(br,{title:"Private Key",description:c,children:t("div",{className:"flex flex-row items-center gap-2",children:[o,r&&e("div",{className:"text-sm font-semibold",children:i?.name||i?.account||i?.project||"unknown"})]})})}function br({title:n,description:r,children:a}){return t(v,{hover:!0,children:[e(x,{className:"cursor-pointer flex items-center inline-block",children:e("div",{children:a})}),e(w,{align:"center",sideOffset:8,side:"right",children:t("div",{className:"flex flex-col gap-1 rounded-md shadow-md p-2",children:[e("div",{className:"text-md font-semibold",children:n}),r]})})]})}function yr({buckets:n,name:r,placeholder:a}){return function({buckets:n,name:r,placeholder:a}){const s=n.map((e=>({value:e._id,label:`(${e.count})`})));return{name:r,placeholder:a||`${r.charAt(0).toUpperCase()+r.slice(1)}`,options:s,labelRenderer:r=>{if("Unknown User"===r||!r){const e=n.find((e=>e._id===r));return`Unknown User (${e?.count||0})`}const a=n.find((e=>e._id===r));return t("div",{className:"flex items-center w-full gap-2",children:[e("div",{className:"flex-1 min-w-0 flex items-center truncate",children:e(hr,{userRef:r,showTitle:!0,size:"sm"})}),t("span",{className:"text-muted-foreground flex-shrink-0",children:["(",a?.count||0,")"]})]})}}}({buckets:n,name:r,placeholder:a})}function vr(n){const r=[];if(n.interactions){const a=function({buckets:n,name:r,placeholder:a}){return{name:r,placeholder:a,options:n.map((e=>({label:`(${e.count})`,value:e._id}))),type:"select",labelRenderer:r=>{const a=n.find((e=>e._id===r)),s=a?.name||r;let i="success";if(a?.status)switch(a.status){case Pe.published:i="success";break;case Pe.archived:i="destructive";break;default:i="attention"}const l=a?.version&&a?.status?`v${a.version} ${a.status}`:a?.status||(a?.version?`v${a.version}`:"");return t("div",{className:"w-full flex items-center justify-between",children:[t("div",{className:"flex flex-row flex-wrap items-center gap-2 min-w-0 flex-1",children:[e("span",{className:"text-sm truncate",children:s}),l&&e(b,{variant:i,className:"text-xs w-fit",children:l})]}),t("span",{className:"ml-2 text-xs shrink-0",children:["(",a?.count||0,")"]})]})},filterBy:(e,t)=>{const r=n.find((t=>t._id===e));return(r?.name||e).toLowerCase().includes(t.toLowerCase())}}}({buckets:n.interactions||[],name:"interaction",placeholder:"Interactions"});r.push(a)}if(n.environments){const a=function({buckets:n,name:r}){const a=n.map((e=>({label:`(${e.count})`,value:e._id})));return{name:r.charAt(0).toUpperCase()+r.slice(1),options:a,type:"select",labelRenderer:r=>{const a=n.find((e=>e._id===r));return t("div",{className:"w-full flex items-center",children:[e("span",{className:"text-sm truncate",children:a?.name||r}),t("span",{className:"ml-2 text-xs",children:["(",a?.count||0,")"]})]})},filterBy:(e,t)=>{const r=n.find((t=>t._id===e));return(r?.name||e).toLowerCase().includes(t.toLowerCase())}}}({buckets:n.environments||[],name:"Environments"});r.push(a)}if(n.models){const e=sr({buckets:n.models||[],name:"Model"});r.push(e)}if(n.statuses){const e=sr({buckets:n.statuses||[],name:"Status"});r.push(e)}if(n.finish_reason){const e=sr({buckets:n.finish_reason.map((e=>({...e,_id:null===e._id?"none":e._id}))),name:"finish_reason",placeholder:"Finish Reason"});r.push(e)}if(n.created_by){const e=yr({buckets:n.created_by||[],name:"created_by",placeholder:"Created By"});r.push(e)}r.push({name:"start",placeholder:"Date After",type:"date",multiple:!1});return r.push({name:"end",placeholder:"Date Before",type:"date",multiple:!1}),r}function xr(e){return t=>{0!==t.length?(e.clearFilters(!1),t.forEach((t=>{if(t.value&&t.value.length>0){const n=t.name;let r;r="stringList"===t.type?t.value.map((e=>"string"==typeof e?e:e.value)):t.multiple?Array.isArray(t.value)?t.value.map((e=>"object"==typeof e&&e.value?e.value:e)):["object"==typeof t.value&&t.value.value?t.value.value:t.value]:Array.isArray(t.value)&&t.value[0]&&"object"==typeof t.value[0]?t.value[0].value:Array.isArray(t.value)&&t.value[0]?t.value[0]:t.value,e.query[n]=r}})),e.search()):e.clearFilters()}}function wr({facets:n,search:r}){const[a,s]=o([]),i=vr(n),l=xr(r);return e(M,{filterGroups:i,filters:a,setFilters:e=>{const t="function"==typeof e?e(a):e;s(t),l(t)},children:t("div",{className:"flex gap-2 items-center",children:[e(V,{}),e(q,{}),e(W,{})]})})}function Nr(e){const t=[];if(t.push({placeholder:"Search by Workflow or Run ID",name:"name",type:"text",options:[]}),e.status){const n=sr({buckets:e.status||[],name:"Status"});t.push(n)}if(e.initiated_by){const n=yr({buckets:e.initiated_by||[],name:"User"});t.push(n)}t.push({name:"start",placeholder:"Date After",type:"date",multiple:!1});return t.push({name:"end",placeholder:"Date Before",type:"date",multiple:!1}),t}function kr(e){return t=>{0!==t.length?(e.clearFilters(!1),t.forEach((t=>{if(t.value&&t.value.length>0){const n=t.name;let r;r="stringList"===t.type?t.value.map((e=>"string"==typeof e?e:e.value)):t.multiple?Array.isArray(t.value)?t.value.map((e=>"object"==typeof e&&e.value?e.value:e)):["object"==typeof t.value&&t.value.value?t.value.value:t.value]:Array.isArray(t.value)&&t.value[0]&&"object"==typeof t.value[0]?t.value[0].value:Array.isArray(t.value)&&t.value[0]?t.value[0]:t.value,"name"===n?(e.query.search_term=r,e.query.name=r):e.query[n]=r}})),e.search()):e.clearFilters()}}function Cr({facets:n,search:r}){const[a,s]=o([]),i=Nr(n),l=kr(r);return e(M,{filterGroups:i,filters:a,setFilters:e=>{const t="function"==typeof e?e(a):e;s(t),l(t)},children:t("div",{className:"flex gap-2 items-center",children:[e(V,{}),e(q,{}),e(W,{})]})})}function Sr(e){const{typeRegistry:t}=Ie(),n=[];if(n.push({placeholder:"Name or ID",name:"name",type:"text",options:[]}),e.type){const r=ir({buckets:e.type||[],typeRegistry:t,type:"select",multiple:!0});n.push(r)}if(e.status){const t=sr({buckets:e.status||[],name:"Status",type:"select",multiple:!0});n.push(t)}return e.tags&&n.push({name:"Tags",type:"stringList",options:e.tags.map((e=>({label:e,value:e})))}),n.push({name:"created_at",placeholder:"Created Date",type:"date",multiple:!0,options:[]}),n.push({name:"updated_at",placeholder:"Updated Date",type:"date",multiple:!0,options:[]}),n}function jr(e){return t=>{0!==t.length?(e.clearFilters(!1),t.forEach((t=>{if(t.value&&t.value.length>0){const n=t.name;let r;if("date"===t.type&&t.multiple){if(Array.isArray(t.value)&&t.value.length>0)if(1===t.value.length){const e="object"==typeof t.value[0]?t.value[0].value:t.value[0];r={gte:e,lte:e}}else if(2===t.value.length){r={gte:"object"==typeof t.value[0]?t.value[0].value:t.value[0],lte:"object"==typeof t.value[1]?t.value[1].value:t.value[1]}}}else r=t.multiple?Array.isArray(t.value)?t.value.map((e=>"object"==typeof e&&e.value?e.value:e)):["object"==typeof t.value&&t.value.value?t.value.value:t.value]:Array.isArray(t.value)&&t.value[0]&&"object"==typeof t.value[0]?t.value[0].value:Array.isArray(t.value)&&t.value[0]?t.value[0]:t.value;"name"===n?(e.query.search_term=r,e.query.name=r):e.query[n]=r}})),e.search()):e.clearFilters()}}function _r({facets:n,search:r}){const[a,s]=o([]),i=Sr(n),l=jr(r);return e(M,{filterGroups:i,filters:a,setFilters:e=>{const t="function"==typeof e?e(a):e;s(t),l(t)},children:t("div",{className:"flex gap-2 items-center",children:[e(V,{}),e(q,{}),e(W,{})]})})}class Pr{object;objects;setState;collectionId;singleSelection=!1;constructor(e,t,n,r){this.object=e,this.objects=n,this.setState=r,this.singleSelection=0===Object.keys(this.objects).length,this.collectionId=t}isSingleSelection(){return this.singleSelection}hasSelection(){return void 0!==this.object||0!==this.size()}size(){return Object.keys(this.objects).length}getObjectIds(){return Object.keys(this.objects)}getObjectId(){return this.object?.id}clone(){return new Pr(this.object,this.collectionId,this.objects,this.setState)}add(e){this.objects[e.id]=e,this.singleSelection=0===Object.keys(this.objects).length,this.setState(this.clone())}remove(e){delete this.objects[e],this.singleSelection=0===Object.keys(this.objects).length,this.setState(this.clone())}addAll(e){for(const t of e)this.objects[t.id]=t;this.setState(this.clone())}isSelected(e){return void 0!==this.objects[e]}removeAll(){this.objects={},this.singleSelection=!0,this.setState(this.clone())}}const Tr=d(void 0);function Ir(){const e=m(Tr);if(!e)throw new Error("useObjectSelection must be used within a ObjectSelectionProvider");return e}function $r(){return m(Tr)}function Er({value:t,collectionId:n,children:r}){const[a,s]=o();return c((()=>{const e=new Pr(t,n,{},s);s(e)}),[t]),a&&e(Tr.Provider,{value:a,children:r})}St.extend(qt),St.extend(Vt);const Ar={string(t){let n=[];if(t){const e=t.get("slice");e&&n.push((t=>t.slice(parseInt(e))));const r=t.get("max_length");r&&n.push((e=>e.slice(0,parseInt(r)))),t.has("upper")&&n.push((e=>e.toUpperCase())),t.has("lower")&&n.push((e=>e.toLowerCase())),t.has("capitalize")&&n.push((e=>e[0].toUpperCase()+e.substring(1))),t.has("ellipsis")&&n.push((e=>e+"..."))}return(t,r)=>{let a;if(t){if(a=String(t),n.length>0)for(const e of n)a=e(a)}else a="";return e("td",{children:a},r)}},fileSize:t=>(t,n)=>{let r="";if(t){const e=Number(t);if(isNaN(e))r=String(t);else{const t=["Bytes","KB","MB","GB","TB"];if(0===e)r="0 Bytes";else{const n=Math.floor(Math.log(e)/Math.log(1024));r=`${(e/Math.pow(1024,n)).toFixed(2)} ${t[n]}`}}}return e("td",{children:r},n)},number(t){let n,r;t&&(n=t.get("currency")||void 0,r=t.get("decimals")||void 0);const a=r?parseInt(r):2;return(t,r)=>{let s=new Intl.NumberFormat("en-US",{style:n?"currency":"decimal",currency:n,maximumFractionDigits:a}).format(t);return e("td",{children:s},r)}},objectLink(t){let n="title";return t&&(n=t.get("title")||"title"),(t,r)=>e("td",{children:e(kt,{topLevelNav:!0,className:"underline text-indigo-800 dark:text-indigo-300",href:`/store/objects/${t.id}`,children:t.properties?.[n]||t.name||zn(t.id)})},r)},typeLink:t=>(t,n)=>e("td",{children:t?.name||"n/a"},n),date(t){let n="format",r="LLL";if(t){const e=t.get("localized");if(e)r=e;else{const e=t.get("relative");e&&(n=e,r=void 0)}}return(t,a)=>e("td",{children:St(t)[n](r)},a)}},Lr=Ar.string();function zr(e,t){let n=e;if(!n)return;if(!t.length)return n;const r=t.length-1;for(let e=0;e<r;e++)if(n=n[t[e]],!n)return;return n[t[r]]}function Dr(e){return e&&"."!==e?e.split("."):[]}class Or{layout;renderer=Lr;path;fallbackPath;constructor(e){if(this.layout=e,this.path=Dr(e.field||""),this.fallbackPath=e.fallback?Dr(e.fallback):void 0,e.render)this.renderer=(e,t)=>null;else{const t=e.type||"string",n=t.indexOf("?");if(n>0){const e=t.substring(0,n),r=new URLSearchParams(t.substring(n+1));this.renderer=Ar[e](r)}else this.renderer=Ar[t]()}}get name(){return this.layout.name}resolveValue(e){let t=zr(e,this.path);return void 0===t&&this.fallbackPath&&(t=zr(e,this.fallbackPath)),void 0===t&&(t=this.layout.default),t}render(t,n){return this.layout.render?e("td",{className:"whitespace-nowrap px-3 py-4 text-sm",children:this.layout.render(t)},n):this.renderer(this.resolveValue(t),n)}}function Ur({objects:n,selection:r,isLoading:a,onRowClick:s,columns:i,toggleAll:l,onSelectionChange:o}){return t(G,{className:"w-full border-t",children:[e("thead",{children:t("tr",{children:[r&&e("th",{children:e("input",{type:"checkbox",onChange:l})}),i.map((t=>e("th",{children:t.name},t.name)))]})}),t(H,{isLoading:a,columns:i.length,children:[n?.map((n=>t("tr",{className:"cursor-pointer hover:bg-muted",onClick:()=>{s&&s(n)},children:[r&&e("td",{onClick:e=>e.stopPropagation(),children:e("input",{checked:r.isSelected(n.id),type:"checkbox",onChange:e=>o(n,e)})}),i.map(((e,t)=>e.render(n,t)))]},n.id))),0===n.length&&e("tr",{children:e("td",{colSpan:i.length+(r?1:0),className:"text-center",children:"No objects. Just drag and drop documents or images here to create content objects."})})]})]})}function Fr({objects:a,selection:s,isLoading:i,onSelectionChange:l,onRowClick:o}){return t(n,{children:[e("div",{className:r("bg-white opacity-40 absolute inset-0 z-50 flex justify-center items-center",i?"block":"hidden"),children:e(L,{size:"xl"})}),e("div",{className:"w-full gap-2 grid lg:grid-cols-6",children:a.map((t=>e(Kn,{document:t,selection:s,onSelectionChange:l,onRowClick:o},t.id)))})]})}class Rr{client;limit;collectionId;facets=new K({});result=new K({objects:[],isLoading:!1});facetSpecs=[];query={};constructor(e,t=100){this.client=e,this.limit=t}withFacets(e){return this.facetSpecs=e,this}get objects(){return this.result.value.objects}get error(){return this.result.value.error}get isRunning(){return this.result.value.isLoading}getFilterValue(e){return this.query[e]}setFilterValue(e,t){this.query[e]=t,this.search()}clearFilters(e=!0){const t=this.query.parent;this.query={parent:t},e&&this.search()}getFacetBuckets(e){return this.facets.value[e]?.buckets||[]}resetFacets(){this.query={}}reset(e=!1){this.result.value={objects:[],isLoading:e}}_updateRunningState(e){const t=this.result.value;this.result.value={objects:t.objects,isLoading:e,error:t.error}}_searchRequest(e,t,n){return this.collectionId?this.client.collections.searchMembers(this.collectionId,{limit:t,offset:n,query:e}):this.client.objects.search({limit:t,offset:n,query:e})}_facetsRequest(){return this.collectionId?this.client.collections.computeFacets(this.collectionId,{facets:this.facetSpecs,query:this.query}):this.client.objects.computeFacets({facets:this.facetSpecs,query:this.query})}computeFacets(e){this._facetsRequest().then((e=>{this.facets.value=e}))}_search(e=!1){if(this.isRunning)return Promise.resolve(!1);this.result.value={isLoading:!0,objects:e?this.objects:[]};const t=this.limit,n=this.objects.length;return this._searchRequest(this.query,t,n).then((async e=>(this.result.value={isLoading:!1,objects:this.objects.concat(e)},!0))).catch((e=>{throw this.result.value={error:e,isLoading:!1,objects:this.objects},e}))}search(e=!1){return this.isRunning?Promise.resolve(!1):(!e&&this.computeFacets(this.query),this._search(!1))}loadMore(e=!1){return this.isRunning?Promise.resolve(!1):(0===this.objects.length&&!e&&this.computeFacets(this.query),this._search(!0))}}const Mr=d(void 0);function Vr(){return m(Mr)}function qr(){return Y(Vr().facets)}function Wr(){const e=Vr();return{...Y(e.result),search:e}}function Br(){const e=Vr();return Y(e.facets).total}var Jr;async function Gr(e){try{const t=await e.arrayBuffer(),n=new Wt;n.appendByteArray(new Uint8Array(t));const r=n.end();return r?.toString()}catch(e){return void console.error("Error calculating file hash:",e)}}function Hr(){const{client:e}=Ie(),t=f();return{checkDocumentProcessing:async(n,r,a)=>{try{console.log(`Preparing metadata for ${n.length} files...`);const t=await async function(e,t){const n=[];for(let r=0;r<e.length;r+=5){const a=e.slice(r,r+5),s=await Promise.all(a.map((async e=>{let n=t||void 0;if(e.webkitRelativePath){const r=e.webkitRelativePath.split("/");if(r.length>1){const e=r.slice(0,-1).join("/");n=t?`${t}/${e}`:e}}return{file:e,hash:await Gr(e),name:e.name,size:e.size,location:n}})));n.push(...s)}return n}(n,r),s=async()=>{const n={"content.etag":{$in:t.map((e=>e.hash))}};let r;r=a?await e.store.collections.searchMembers(a,{query:{match:n},select:void 0}):await e.store.objects.search({query:{match:n},select:void 0});for(const e of r){const n=t.find((t=>t.hash===e.content.etag));n&&(n.existingId=e.id,n.action=Jr.SKIP)}},i=async()=>{const n=t.filter((e=>e.action!==Jr.SKIP)),r=n.map((e=>e.location)),s=Array.from(new Set(r)),i=[];for(const t of s){const r=n.filter((e=>e.location===t)).map((e=>e.name)),s={location:t??"","content.name":{$in:r}};if(a){const t=e.store.collections.searchMembers(a,{query:{match:s},select:void 0});i.push(t)}else{const t=e.store.objects.find({query:{match:s},select:void 0});i.push(t)}}const l=(await Promise.all(i)).flat();console.log(`Found ${l.length} document to update`,l);for(const e of l){const n=t.find((t=>t.name===e.content.name&&(t.location?t.location===e.location:""===e.location)));n&&(n.existingId=e.id,n.action=Jr.UPDATE)}console.log(`Reconciled ${t.filter((e=>e.action===Jr.UPDATE)).length}`)};return await s(),await i(),t.forEach((e=>{e.action||(e.action=Jr.CREATE)})),console.log("Document processing check results:",{totalFiles:n.length,toCreate:t.filter((e=>e.action===Jr.CREATE)).length,toUpdate:t.filter((e=>e.action===Jr.UPDATE)).length,toSkip:t.filter((e=>e.action===Jr.SKIP)).length}),t}catch(e){throw t({title:"Error in file upload processing check",status:"error",description:e.message}),console.log("Error in file upload processing check",e),new Error("Error in file upload processing check: "+e.message)}}}}function Kr({isOpen:r,onClose:a,files:s,collectionId:i,selectedFolder:d,title:m="Upload Files",children:u,onUploadComplete:h,hideFileSelection:p=!1,showTypeSelectionOnly:g=!1}){const{client:b,typeRegistry:v}=Ie(),x=f(),[w,N]=o([]),[k,C]=o([]),[S,j]=o(!1),[_,P]=o(null),[T,I]=o([]),[$,E]=o(!1),[A,z]=o(!1),[D,O]=o(0),[F,R]=o(Date.now()),[M,V]=o(void 0),[q,W]=o(null),[B,J]=o(m),[G,H]=o("");c((()=>{i&&b.store.collections.retrieve(i).then(V)}),[i]),c((()=>{$?(J("Uploading Files"),H(`${Math.round(D)}% complete`)):A?(J("Upload Complete"),H("")):S?(J("File Analysis Results"),H(`${w.length} file${1!==w.length?"s":""}`)):w.length>0?(J(m),H("Checking for duplicates and updates")):(J(m),H(""))}),[$,A,S,m,D,w.length]);const K=()=>M||d?t("div",{className:"mb-4 p-3 bg-primary rounded-md border border-primary",children:[t("div",{className:"flex items-center text-primary",children:[e(rt,{className:"size-5 mr-2"}),e("span",{className:"font-medium",children:"Upload Location:"})]}),t("div",{className:"ml-7 text-sm text-primary mt-1",children:[M&&t("div",{className:"flex items-center",children:[e("span",{className:"mr-1",children:"Collection:"}),e("span",{className:"font-medium",children:M.name})]}),d&&t("div",{className:"flex items-center mt-1",children:[e("span",{className:"mr-1",children:"Folder:"}),e("span",{className:"font-medium",children:d})]})]})]}):null,[Y,re]=o({toCreate:0,toUpdate:0,toSkip:0}),{checkDocumentProcessing:ae}=Hr(),se=l((()=>v?.types||[]),[v?.types]);c((()=>{r&&(C([]),j(!1),P(null),I([]),E(!1),z(!1),O(0),re({toCreate:0,toUpdate:0,toSkip:0}),W(null),J(m),H(""),s&&s.length>0?(N(s),oe(s)):N([]),R(Date.now()))}),[r,s]);const ie=()=>{N([]),C([]),j(!1),P(null),I([]),E(!1),z(!1),O(0),re({toCreate:0,toUpdate:0,toSkip:0}),W(null),J(m),H(""),R(Date.now()),a()},le=e=>{e&&e.length>0&&(N(e),oe(e))},oe=async e=>{if(e.length)try{console.log(`Processing ${e.length} files to determine required actions...`);const t=await ae(e,d,i);C(t);const n=t.filter((e=>e.action===Jr.CREATE)).length,r=t.filter((e=>e.action===Jr.UPDATE)).length,a=t.filter((e=>e.action===Jr.SKIP)).length;re({toCreate:n,toUpdate:r,toSkip:a}),x({title:"Files analyzed",description:`${e.length} file(s): ${n} new, ${r} to update, ${a} to skip`,status:"info",duration:4e3}),j(!0)}catch(e){console.error("Error processing files:",e),x({title:"Error",description:"There was an error analyzing the files",status:"error",duration:5e3})}},ce=async()=>{if(!k.length)return;const e=_?.id||null,t=k.map((e=>({file:e.file,status:"pending",progress:0,action:e.action===Jr.CREATE?"create":e.action===Jr.UPDATE?"update":"skip"})));I(t),E(!0),z(!1);const n=k.filter((e=>e.action===Jr.SKIP)),r=k.filter((e=>e.action===Jr.UPDATE)),a=k.filter((e=>e.action===Jr.CREATE)),s={success:!0,objectIds:[],uploadedFiles:[],skippedFiles:[],failedFiles:[]};for(const t of n)t.existingId&&(s.objectIds.push(t.existingId),s.skippedFiles.push({id:t.existingId,name:t.name,type:e,status:"skipped",location:t.location}),I((e=>e.map((e=>e.file===t.file?{...e,status:"success",progress:100,id:t.existingId}:e)))));const l=async(t,n)=>{const r=[];for(let e=0;e<t.length;e+=50)r.push(t.slice(e,e+50));for(let a=0;a<r.length;a++){const l=r[a];if(console.log(`Processing ${n} batch ${a+1}/${r.length} (${l.length} files)`),t.length>50){x({title:`Processing files (${n})`,description:`Processed ${50*a}/${t.length} files...`,status:"info",duration:2e3})}await Promise.all(l.map((async t=>{try{if(I((e=>e.map((e=>e.file===t.file?{...e,status:"uploading",progress:20}:e)))),"update"===n&&t.existingId)await b.store.objects.update(t.existingId,{type:e||void 0,content:t.file,location:t.location,name:t.name},{createRevision:!0,revisionLabel:"upload on "+(new Date).toISOString()}),I((e=>e.map((e=>e.file===t.file?{...e,status:"success",progress:100,id:t.existingId}:e)))),s.objectIds.push(t.existingId),s.uploadedFiles.push({id:t.existingId,name:t.name,type:e,status:"updated",location:t.location});else{const n=await b.store.objects.create({type:e||void 0,content:t.file,location:t.location||t.file.webkitRelativePath||t.name},{collection_id:i});I((e=>e.map((e=>e.file===t.file?{...e,status:"success",progress:100,id:n.id}:e)))),s.objectIds.push(n.id),s.uploadedFiles.push({id:n.id,name:t.name,type:e,status:"created",location:t.location})}}catch(n){console.error(`Failed to process file ${t.name}:`,n),I((e=>e.map((e=>e.file===t.file?{...e,status:"error",progress:100,message:n.message||"Unknown error"}:e)))),s.failedFiles.push({name:t.name,error:n.message||"Unknown error",status:"failed",location:t.location,type:e}),s.success=!1}})));const o=T.filter((e=>"success"===e.status||"error"===e.status)).length,c=T.length,d=Math.round(o/c*100);O(d)}};r.length>0&&await l(r,"update"),a.length>0&&await l(a,"create"),I((e=>{const t=e.filter((e=>"pending"===e.status)).map((e=>({...e,status:"error",progress:100,message:"Upload process interrupted"})));return t.length>0?(t.forEach((e=>{s.failedFiles.push({name:e.file.name,error:"Upload process interrupted",status:"failed",type:_?.id||null})})),s.success=!1,e.map((e=>"pending"===e.status?{...e,status:"error",progress:100,message:"Upload process interrupted"}:e))):e})),E(!1),z(!0);const o=s.uploadedFiles.filter((e=>"created"===e.status)).length,c=s.uploadedFiles.filter((e=>"updated"===e.status)).length,d=s.skippedFiles.length,m=s.failedFiles.length;let u="";o>0&&(u+=`${o} file${1!==o?"s":""} uploaded`),c>0&&(u+=u?", ":"",u+=`${c} file${1!==c?"s":""} updated`),d>0&&(u+=u?", ":"",u+=`${d} file${1!==d?"s":""} skipped`),m>0&&(u+=u?", ":"",u+=`${m} file${1!==m?"s":""} failed`),x({title:"Upload Complete",description:u,status:m>0?"warning":"success",duration:5e3}),W(s)},de=()=>t("div",{className:"mb-4",children:[t("label",{className:"block text-sm font-medium mb-2",children:["Content Type ",e("span",{className:"text-muted font-normal",children:"(Optional)"}),e(U,{description:"Select a content type to apply to the uploaded files. If left empty, Vertesia will automatically detect the type based on file content.",placement:"top",size:"xs",children:e(Fe,{className:"size-3 ml-2"})})]}),e(ne,{options:se,value:_,optionLabel:e=>e?e.name:"Select a content type",placeholder:"Select a content type or leave empty for automatic detection",onChange:e=>P(void 0===e?null:e),filterBy:"name",isClearable:!0}),_?e(n,{}):e("div",{className:"p-2 rounded-md",children:t("div",{className:"flex items-center text-attention",children:[e(Ze,{className:"size-4 mr-1"}),"Automatic Type Detection",e(U,{description:"Vertesia will analyze the content and select the most appropriate type. This is recommended for most uploads and ensures optimal processing.",placement:"top",size:"xs",children:e(Fe,{className:"size-3 ml-2"})})]})})]});return t(Q,{isOpen:r,onClose:ie,className:"mx-auto",children:[e(X,{description:G,children:B}),g?t(Z,{children:[u,K(),de()]}):0!==w.length||p?$||A?$?t(Z,{children:[K(),e("div",{className:"mb-4",children:e("div",{className:"h-2 bg-muted/20 rounded-full overflow-hidden",children:e("div",{className:"h-full bg-primary rounded-full",style:{width:`${D}%`}})})}),e("div",{className:"max-h-96 overflow-y-auto",children:T.map(((n,r)=>t("div",{className:"flex items-center py-2 border-b border-border last:border-b-0",children:[t("div",{className:"mr-3",children:["pending"===n.status&&e(tt,{className:"size-5 text-muted"}),"uploading"===n.status&&e(L,{size:"sm"}),"success"===n.status&&e(Ze,{className:"size-5 text-success"}),"error"===n.status&&e(nt,{className:"size-5 text-destructive"})]}),t("div",{className:"flex-1 min-w-0",children:[e("div",{className:"truncate font-medium",children:n.file.name}),t("div",{className:"text-xs text-muted",children:["pending"===n.status&&"Waiting...","uploading"===n.status&&"Uploading...","success"===n.status&&("create"===n.action?"Created":"update"===n.action?"Updated":"Skipped"),"error"===n.status&&n.message]})]})]},`${n.file.name}-${r}`)))})]}):e(Z,{children:t("div",{className:"mb-4",children:[K(),e(Et,{files:T.map((e=>{let t;return t="success"===e.status?"create"===e.action?"success":"update"===e.action?"updated":"skipped":"failed",{name:e.file.name,status:t,error:"error"===e.status?e.message:void 0}})),location:d||void 0,collection:M?.name})]})}):e(Z,{children:S?t(n,{children:[K(),e("div",{className:"mb-4",children:e("div",{className:"p-4 rounded-md mb-4",children:t("div",{className:"grid grid-cols-3 gap-4",children:[t("div",{className:"flex flex-col items-center",children:[t("div",{className:"flex items-center gap-2",children:[e(Xe,{className:"size-5 text-primary"}),e("span",{className:"font-medium",children:"New"})]}),e("div",{className:"text-2xl font-semibold",children:Y.toCreate})]}),t("div",{className:"flex flex-col items-center",children:[t("div",{className:"flex items-center gap-2",children:[e(Ze,{className:"size-5 text-success"}),e("span",{className:"font-medium",children:"Update"})]}),e("div",{className:"text-2xl font-semibold",children:Y.toUpdate})]}),t("div",{className:"flex flex-col items-center",children:[t("div",{className:"flex items-center gap-2",children:[e(et,{className:"size-5 text-mixer-attention/40"}),e("span",{className:"font-medium",children:"Skip"})]}),e("div",{className:"text-2xl font-semibold",children:Y.toSkip})]})]})})}),de(),e(ee,{className:"mb-4",status:"info",children:Y.toCreate+Y.toUpdate>0?t("div",{className:"space-y-1",children:[t("p",{children:[Y.toCreate+Y.toUpdate," file",Y.toCreate+Y.toUpdate>1?"s are":" is"," ready to process"]}),e("p",{children:Y.toSkip>0&&`${Y.toSkip} file${Y.toSkip>1?"s are":" is"} already in the system and will be skipped.`})]}):Y.toSkip>0?t("span",{children:["All ",Y.toSkip," file(s) already exist in the system and will be skipped. You can proceed to view the results."]}):e("span",{children:"No files to process."})})]}):t("div",{className:"flex flex-col items-center justify-center py-4",children:[e(L,{size:"lg",className:"mb-4"}),e("div",{className:"text-lg font-medium",children:"Analyzing files..."})]})}):t(Z,{className:"flex flex-col items-center justify-center p-8",children:[K(),e($t,{onDrop:le,message:"Drag and drop files here or click to select",buttonLabel:"Select Files",className:"w-full h-64"}),u]}),(()=>{if(g)return t(te,{children:[e(y,{variant:"ghost",onClick:ie,children:"Cancel"}),e(y,{onClick:()=>{h&&h({success:!0,objectIds:[],uploadedFiles:[{name:"type-selection",type:_?.id||null,status:"created"}],skippedFiles:[],failedFiles:[]}),ie()},children:_?`Use ${_.name}`:"Use Automatic Type Detection"})]});if(0===w.length&&!p)return e(te,{children:e(y,{variant:"ghost",onClick:ie,children:"Cancel"})});if(!$&&!A){const n=S;return t(te,{children:[e(y,{variant:"ghost",onClick:ie,children:"Cancel"}),e(y,{disabled:!n,onClick:ce,children:Y.toCreate+Y.toUpdate>0?"Upload":"Continue"})]})}return $?e(te,{children:e(y,{variant:"ghost",disabled:!0,children:"Uploading..."})}):t(te,{children:[e(y,{variant:"ghost",onClick:()=>{N([]),C([]),j(!1),P(null),I([]),E(!1),z(!1),O(0),re({toCreate:0,toUpdate:0,toSkip:0})},children:"Upload More"}),e(y,{onClick:()=>{h&&q&&h(q),ie()},children:"Close"})]})})()]},F)}function Yr(e){const t="function"==typeof e?e:e.onUploadDone,{client:n,project:r,store:a}=Ie(),s=Vr(),i=f(),{checkDocumentProcessing:l}=Hr();return async(e,o,c)=>{const d={success:!1,objectIds:[],uploadedFiles:[],skippedFiles:[],failedFiles:[]};if(!r)return i({status:"error",title:"No project selected",duration:3e3}),d;if(!e||0===e.length)return i({status:"warning",title:"No files selected",duration:3e3}),d;const m=Array.from(e).filter((e=>e.size>0));if(0===m.length)return i({status:"error",title:"No valid files selected",description:"Please select files with valid content.",duration:5e3}),d;const u=[],h=[],p=[];console.log(`Processing ${m.length} files with smart file processing...`);const g=await l(m,null,c),f=g.filter((e=>e.action===Jr.CREATE)).length,b=g.filter((e=>e.action===Jr.UPDATE)).length,y=g.filter((e=>e.action===Jr.SKIP)).length;i({title:"Files analyzed",description:`${m.length} file(s): ${f} new, ${b} to update, ${y} to skip`,status:"info",duration:4e3});for(const e of g.filter((e=>e.action===Jr.SKIP&&e.existingId)))u.push({id:e.existingId,name:e.name,type:o,status:"skipped",location:e.location});const v=g.filter((e=>(e.action===Jr.CREATE||e.action===Jr.UPDATE)&&e.file));if(v.length>0){console.log(`Processing ${v.length} files (${v.filter((e=>e.action===Jr.CREATE)).length} create, ${v.filter((e=>e.action===Jr.UPDATE)).length} update)...`);const e=50,t=[];for(let n=0;n<v.length;n+=e)t.push(v.slice(n,n+e));for(let r=0;r<t.length;r++){const s=t[r],l=r*e;console.log(`Processing batch ${r+1}/${t.length} (${s.length} files)`),v.length>e&&i({title:"Processing files",description:`Processed ${l}/${v.length} files...`,status:"info",duration:2e3});const m=await Promise.all(s.map((async e=>{try{if(e.action===Jr.UPDATE&&e.existingId){const t=await n.store.objects.update(e.existingId,{type:o||void 0,content:e.file,location:e.location,name:e.name},{createRevision:!0,revisionLabel:"upload on "+(new Date).toISOString()});return h.push({id:e.existingId,name:e.name,type:o,status:"updated",location:e.location}),d.objectIds.push(e.existingId),{success:!0,id:t.id,name:e.name,action:"update"}}{const t=c?{collection_id:c}:void 0,n=await a.objects.create({type:o||void 0,content:e.file,location:e.location||e.file.webkitRelativePath||e.name},t);h.push({id:n.id,name:e.name,type:o,status:"created",location:e.location})}}catch(t){console.error(`Failed to process file ${e.name}:`,t),p.push({name:e.name,error:t.message||"Unknown error",status:"failed",location:e.location,type:o}),i({status:"error",title:`Processing failed for ${e.name}`,description:t.message,duration:4e3})}}))),u=h.filter((e=>"created"===e.status)),g=h.filter((e=>"updated"===e.status)),f=h.filter((e=>"failed"===e.status));console.log(`Batch ${r+1} results:`,{creates:u,updates:g,failures:f,total:m.length})}}const x=h.filter((e=>"created"===e.status)).length,w=h.filter((e=>"updated"===e.status)).length,N=h.filter((e=>"failed"===e.status)).length,k=h.filter((e=>"skipped"===e.status)).length;t&&(console.log("Upload complete:",{totalObjectIds:d.objectIds.length,uploadedFiles:x,updatedFiles:w,skippedFiles:k,failedFiles:N}),await t(d.objectIds));let C="";return x>0&&(C+=`${x} file${1!==x?"s":""} uploaded`),w>0&&(C+=C?", ":"",C+=`${w} file${1!==w?"s":""} updated`),k>0&&(C+=C?", ":"",C+=`${k} file${1!==k?"s":""} skipped (already existed)`),N>0&&(C+=C?", ":"",C+=`${N} file${1!==N?"s":""} failed`),C&&i({status:N>0?"warning":"success",title:C,duration:4e3}),s.search(),d}}!function(e){e.CREATE="create",e.SKIP="skip",e.UPDATE="update"}(Jr||(Jr={}));const Qr=[{name:"ID",field:"id",type:"string?slice=-7"},{name:"Name",field:".",type:"objectLink"},{name:"Type",field:"type.name",type:"string"},{name:"Status",field:"status",type:"string"},{name:"Updated At",field:"updated_at",type:"date"}];function Xr({isGridView:t=!1,onUpload:n,collectionId:r,...a}){return n?e(Zr,{...a,onUpload:n,isGridView:t,collectionId:r}):e(ea,{...a,isGridView:t})}function Zr({isGridView:n,onUpload:a,collectionId:s,skipTypeModal:i=!1,...l}){const[c,d]=o(!1),[m,u]=o([]),[h,p]=o(!1),[g,b]=o(null),[y,v]=o(!1),x=Vr(),w=f(),{checkDocumentProcessing:N}=Hr(),k=async(e,t)=>{console.log("Files dropped on ObjectTable:",e.length,t),d(!0);try{if(s){const t=await N(e,null,s);b(t);const n=t.filter((e=>"create"===e.action)).length,r=t.filter((e=>"update"===e.action)).length,a=t.filter((e=>"skip"===e.action)).length;w({title:"Files ready to process",description:`${e.length} file(s): ${n} new, ${r} to update, ${a} to skip`,status:"info",duration:4e3})}else b(null)}catch(e){console.error("Error processing files:",e),w({title:"Error processing files",description:"There was an error checking for duplicate files",status:"error",duration:4e3}),b(null)}finally{if(d(!1),u(e),p(!1),i){console.log("Skipping type modal and calling onUpload directly",{filesLength:e.length,processedFilesLength:g?.length});const t=a(e,null,s);t&&"object"==typeof t&&(t.processedFiles=g)}else console.log("Setting typeSelectionOpen to true",{filesLength:e.length}),v(!0)}},C=e=>{const t=[...m];u([]),b(null),v(!1),t.length>0&&void 0!==e&&(d(!0),console.log("Starting upload with",{typeId:e,filesCount:t.length,hasProcessingResults:!!g,collectionId:s}),a(t,e,s).finally((()=>{d(!1),x.search()})))},S=e=>{e.preventDefault(),e.stopPropagation(),p(!0)};return t("div",{className:"min-h-[400px] relative",onDragOver:S,onDragEnter:S,onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),e.currentTarget.contains(e.relatedTarget)||p(!1)},onDrop:e=>{if(e.preventDefault(),e.stopPropagation(),p(!1),e.dataTransfer.items){const t=[];for(let n=0;n<e.dataTransfer.items.length;n++){const r=e.dataTransfer.items[n];if("file"===r.kind){const e=r.getAsFile();e&&t.push(e)}}if(t.length>0){const e={count:t.length,message:`Preparing to upload ${t.length} file${1===t.length?"":"s"}...`};k(t,e)}}},children:[e("div",{className:r("bg-white dark:bg-gray-800 opacity-40 absolute inset-0 z-50 flex justify-center items-center",c?"block":"hidden"),children:e(L,{size:"xl"})}),e(ea,{...l,isGridView:n}),e("div",{className:r("absolute inset-0 pointer-events-none",h?"z-40":"-z-10"),children:e("div",{className:"w-full h-full relative",children:e($t,{onDrop:k,message:"Drop files or folders here to upload",className:r("absolute inset-0 bg-white/90 dark:bg-gray-800/90 pointer-events-auto",h?"flex":"hidden"),buttonLabel:"Select Files or Folders",allowFolders:!0})})}),e(Kr,{isOpen:y&&m.length>0,onClose:()=>{u([]),b(null),v(!1),C(void 0)},files:m,collectionId:s,selectedFolder:null,title:"Upload Files",onUploadComplete:e=>{if(e){if(e.failedFiles&&e.failedFiles.length>0&&w({title:"Upload Issues",description:`${e.failedFiles.length} file(s) failed to upload`,status:"warning",duration:5e3}),e.success){const t=e.uploadedFiles.filter((e=>"created"===e.status)).length,n=e.uploadedFiles.filter((e=>"updated"===e.status)).length,r=e.skippedFiles.length;(t>0||n>0)&&w({title:"Upload Complete",description:`${t>0?`${t} created`:""}${t>0&&n>0?", ":""}${n>0?`${n} updated`:""}${r>0?`, ${r} skipped`:""}`,status:"success",duration:5e3})}x.search()}u([]),b(null),v(!1),e&&e.success&&e.objectIds.length>0?C(null):C(void 0)}})]})}function ea({objects:t,layout:n=Qr,isLoading:r,onRowClick:a,onSelectionChange:s,isGridView:i}){const o=$r(),c=(e,n)=>{if(o){const r=n.nativeEvent.shiftKey;if(n.target.checked){if(o.add(e),r){const n=t.findIndex((t=>t.id===e.id)),r=function(e,t,n){for(let r=t-1;r>=0;r--)if(n.isSelected(e[r].id))return r;return-1}(t,n,o);if(r>-1&&r<n-1){const e=[];for(let a=r+1;a<n;a++)e.push(t[a]);o.addAll(e)}else{const e=function(e,t,n){const r=e.length;for(let a=t+1;a<r;a++)if(n.isSelected(e[a].id))return a;return-1}(t,n,o);if(e>-1&&e>n+1){const r=[];for(let a=n+1;a<e;a++)r.push(t[a]);o.addAll(r)}}}}else o.remove(e.id);s&&s(o)}},d=e=>{if(o){e.target.checked?o.addAll(t):o.removeAll()}},m=l((()=>(n.length>0?n:Qr).map((e=>new Or(e)))),[n]);return e(i?Fr:Ur,{objects:t,isLoading:r,columns:m,onRowClick:a,selection:o,toggleAll:d,onSelectionChange:c})}function ta({children:t,limit:n,parent:r,typeId:a,facets:s,similarTo:i,embeddingType:o,name:c,collectionId:d}){const{store:m}=Ie(),u=l((()=>{let e;s?e=s:(e=[{name:"status",field:"status"},{name:"location",field:"location"}],a||e.unshift({name:"type",field:"type"}));const t=new Rr(m,n).withFacets(e);return t.collectionId=d,t.query.type=a,t.query.parent=r,t.query.similarTo=i,t.query.embeddingType=o,t.query.name=c,t}),[a,n]);return e(Mr.Provider,{value:u,children:t})}const na=[{name:"Name",field:"properties.title",type:"string",fallback:"name"},{name:"Type",field:"type.name",type:"string"},{name:"Status",field:"status",type:"string"},{name:"Created At",field:"created_at",type:"date"}];function ra({onChange:t}){return e(ta,{children:e(sa,{onRowClick:e=>{t(e||void 0)}})})}const aa="vertesia.content_store.lastDisplayedView";function sa({onRowClick:n}){const[r,a]=o(!1),[s,i]=o("grid"===localStorage.getItem(aa)),{search:l,isLoading:d,error:m,objects:h}=Wr(),p=u(null);re(p,(()=>{r&&l.loadMore(!0)}),{deps:[r]}),c((()=>{l.search().then((()=>a(!0)))}),[]);const g=qr(),f=Vr();return m?e(ae,{title:"Search failed",children:m.message}):t("div",{children:[t("div",{className:"flex justify-between items-center mb-4",children:[e(_r,{facets:g,search:f}),t("div",{className:"flex items-center gap-2",children:[e(y,{variant:"outline",onClick:()=>{a(!1),l.search().then((()=>a(!0)))},alt:"Refresh",children:e(at,{size:16})}),e(In,{onUpdate:i})]})]}),e(Xr,{objects:h||[],isLoading:!1,layout:na,onRowClick:n,isGridView:s}),e("div",{ref:p,className:"mt-10"}),d&&e("div",{className:"flex justify-center",children:e(L,{size:"xl"})})]})}function ia({isOpen:n,onClose:r}){return t(Q,{onClose:()=>r(),isOpen:!!n,className:"min-w-[60vw]",children:[e(X,{children:"Select Content"}),e(Z,{className:"pt-0 overflow-y-auto max-h-[80vh] min-h-[80vh]",children:n&&e(ra,{onChange:r})})]})}const la=/store:([a-f0-9]+)/;function oa({object:n}){const{client:a}=Ie(),{off:s,on:i,isOn:l}=se(),[d,m]=o(null!=n.value?String(n.value):""),[u,h]=o(void 0),p=()=>{m(""),n.value="",h(void 0)};return c((()=>{if(!d||u)return;const e=d.match(la);e&&a.objects.get(e[1]).then((e=>{h(e)})).catch((()=>{p()}))}),[d]),t("div",{children:[t("div",{className:"relative",children:[e("input",{value:d,onChange:e=>{const t=e.target.value;m(t),n.value=t},className:r(ie.INPUT,"pr-10 w-full")}),u&&e("div",{className:"absolute inset-y-0 right-10 flex items-center justify-center ",children:e(y,{onClick:p,variant:"unstyled",className:"hover:text-red-500 hover:bg-gray-100 dark:hover:bg-gray-600",children:e($e,{className:"size-5"})})}),e("div",{className:"absolute inset-y-0 right-0 flex items-center justify-center",children:e(y,{onClick:i,variant:"unstyled",className:"hover:bg-gray-100 dark:hover:bg-gray-600",children:e(st,{className:"size-5"})})}),e(ia,{value:d,isOpen:l,onClose:e=>{if(e){const t="store:"+e.id;m(t),h(e||void 0),n.value=t}s()}})]}),u&&e("div",{className:"p-1 semibold text-sm text-gray-600 dark:text-slate-300",children:u.properties?.title||u.name})]})}function ca(e,t,n){return()=>{n&&e.files.getDownloadUrl(n).then((e=>{window.open(e.url,"_blank")})).catch((e=>{t({status:"error",title:"Failed to get download URL",description:e.message,duration:5e3})}))}}function da({objectId:n,isOpen:r,onClose:a}){const s=Ct(),{client:i,store:l}=Ie(),[d,m]=o(null),[u,h]=o(!1),[p,g]=o(!1),[b,v]=o(),[x,w]=o(),[N,k]=o("preview"),C=f();c((()=>{n&&r?(h(!0),l.objects.retrieve(n,"+embeddings").then((e=>{m(e),e.text?v(e.text):S(e.id);const t=e.content;t&&t.source&&t.type&&t.type.startsWith("image/")&&j(e)})).catch((e=>{console.error("Error loading object:",e),C({title:"Error",description:"Failed to load document",status:"error",duration:3e3})})).finally((()=>{h(!1)}))):(m(null),v(void 0),w(void 0))}),[n,r,l.objects]);const S=async e=>{g(!0);try{const t=await l.objects.getObjectText(e);v(t.text)}catch(e){console.error("Error loading text:",e)}finally{g(!1)}},j=async e=>{try{"found"===(await i.objects.getRendition(e.id,{format:je.jpeg,generate_if_missing:!1})).status&&console.log("Found rendition");const t=await i.files.getDownloadUrl(e.content.source);w(t.url)}catch(e){console.error("Error loading image:",e)}},_=()=>{d&&(s(`/legal/objects/${d.id}`),a())},P=b&&(b.startsWith("#")||b.includes("\n#")||b.includes("\n*")),T=d?.content?.type&&d.content.type.startsWith("image/"),I="application/pdf"===d?.content?.type;return r?t("div",{className:"fixed inset-y-0 right-0 w-2/5 dark:bg-slate-900 shadow-xl z-50 flex flex-col transition-transform duration-300 transform "+(r?"translate-x-0":"translate-x-full"),children:[t("div",{className:"flex items-center justify-between px-4 py-3 border-b dark:border-gray-700 bg-gradient-to-r from-indigo-50 to-gray-50 dark:from-gray-800 dark:to-gray-900",children:[t("div",{className:"flex items-center",children:[e(it,{className:"h-5 w-5 text-indigo-600 mr-2"}),e("h2",{className:"text-lg font-semibold text-gray-800 dark:text-gray-200 truncate",children:u?"Loading document...":d?.name||"Document Preview"})]}),t("div",{className:"flex items-center space-x-2",children:[t(y,{variant:"ghost",size:"sm",onClick:_,className:"flex items-center gap-1 text-indigo-600 hover:text-indigo-800",children:[e(lt,{className:"h-4 w-4"}),e("span",{children:"Full View"})]}),e(y,{variant:"ghost",size:"sm",onClick:a,className:"flex items-center text-gray-600 hover:text-gray-800 dark:text-gray-300 dark:hover:text-gray-100",children:e($e,{className:"h-5 w-5"})})]})]}),u?e("div",{className:"flex-1 flex items-center justify-center",children:t("div",{className:"text-center",children:[e(L,{size:"lg",className:"text-indigo-600 dark:text-indigo-400 mb-2"}),e("p",{className:"text-gray-600 dark:text-gray-400",children:"Loading document..."})]})}):t("div",{className:"flex-1 flex flex-col h-full",children:[e("div",{className:"border-b",children:t("div",{className:"flex px-4",children:[e("button",{className:"py-2 px-4 font-medium border-b-2 "+("preview"===N?"border-indigo-600 text-indigo-700 dark:text-indigo-300":"border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"),onClick:()=>k("preview"),children:t("div",{className:"flex items-center gap-1",children:[e(Ge,{className:"h-4 w-4"}),e("span",{children:"Preview"})]})}),e("button",{className:"py-2 px-4 font-medium border-b-2 "+("properties"===N?"border-indigo-600 text-indigo-700 dark:text-indigo-300":"border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"),onClick:()=>k("properties"),children:t("div",{className:"flex items-center gap-1",children:[e(Fe,{className:"h-4 w-4"}),e("span",{children:"Properties"})]})})]})}),t("div",{className:"flex-1 overflow-auto p-4",children:["preview"===N&&t("div",{className:"h-full",children:[p?e("div",{className:"flex items-center justify-center h-40",children:e(L,{size:"md",className:"text-indigo-600 dark:text-indigo-400"})}):b?e("div",{className:"shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800",children:P?e("div",{className:"prose prose-sm max-w-none prose-p:my-2 prose-pre:bg-gray-800 prose-pre:my-2 prose-headings:text-indigo-700 dark:prose-invert dark:prose-headings:text-indigo-300",children:e(jt,{remarkPlugins:[_t],children:b})}):e("pre",{className:"text-wrap whitespace-pre-wrap dark:text-gray-200",children:b})}):null,T&&e("div",{className:"mt-4",children:e("div",x?{className:"border border-gray-200 dark:border-gray-700 rounded-md p-2 bg-white dark:bg-gray-800",children:e("img",{src:x,alt:d?.name,className:"mx-auto max-h-[70vh] object-contain"})}:{className:"flex items-center justify-center h-40",children:e(L,{size:"md",className:"text-indigo-600 dark:text-indigo-400"})})}),I&&t("div",{className:"flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800",children:[e(it,{className:"h-16 w-16 text-indigo-300 dark:text-indigo-400 mb-4"}),t("p",{className:"text-gray-600 dark:text-gray-400 text-center mb-4",children:["PDF document preview is available in full view. TODO"," "]}),e(y,{onClick:_,className:"bg-indigo-600 hover:bg-indigo-700 text-white",children:"Open Full Document View"})]}),!T&&!b&&!I&&!p&&t("div",{className:"flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800",children:[e(it,{className:"h-16 w-16 text-gray-300 dark:text-gray-600 mb-4"}),e("p",{className:"text-gray-600 dark:text-gray-400 text-center",children:"No preview available for this document type."})]})]}),"properties"===N&&d&&t("div",{className:"h-full",children:[d.properties?e("div",{className:"shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800",children:e(It,{value:d.properties})}):t("div",{className:"flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800",children:[e(Fe,{className:"h-16 w-16 text-gray-300 dark:text-gray-600 mb-4"}),e("p",{className:"text-gray-600 dark:text-gray-400 text-center",children:"No properties available for this document."})]}),t("div",{className:"mt-4",children:[e("h3",{className:"text-sm font-semibold text-gray-700 dark:text-gray-300 mb-2",children:"Document Information"}),e("div",{className:"shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800",children:t("div",{className:"grid grid-cols-2 gap-y-2 gap-x-4 text-sm",children:[e("div",{className:"text-gray-500 dark:text-gray-400",children:"ID"}),e("div",{className:"font-medium dark:text-gray-200",children:d.id}),e("div",{className:"text-gray-500 dark:text-gray-400",children:"Type"}),e("div",{className:"font-medium dark:text-gray-200",children:d.type?.name||"Unknown"}),e("div",{className:"text-gray-500 dark:text-gray-400",children:"Content Type"}),e("div",{className:"font-medium dark:text-gray-200",children:d.content?.type||"N/A"}),e("div",{className:"text-gray-500",children:"Size"}),e("div",{className:"font-medium",children:d.content&&"size"in d.content?ma(d.content.size):"Unknown"}),e("div",{className:"text-gray-500",children:"Created"}),e("div",{className:"font-medium",children:d.created_at?new Date(d.created_at).toLocaleString():"N/A"}),e("div",{className:"text-gray-500",children:"Updated"}),e("div",{className:"font-medium",children:d.updated_at?new Date(d.updated_at).toLocaleString():"N/A"})]})})]})]})]})]}),t("div",{className:"flex items-center justify-between p-4 border-t bg-gray-50 dark:bg-gray-800 dark:border-gray-700",children:[e("div",{children:d?.content?.source&&t(y,{onClick:()=>{d?.content?.source&&i.files.getDownloadUrl(d.content.source).then((e=>{window.open(e.url,"_blank")})).catch((e=>{console.error("Error getting download URL:",e),C({title:"Error",description:"Failed to download file",status:"error",duration:3e3})}))},variant:"outline",className:"text-indigo-600 border-indigo-300 hover:bg-indigo-50",children:[e(Ye,{className:"h-4 w-4 mr-2"}),"Download"]})}),t(y,{onClick:_,className:"bg-indigo-600 hover:bg-indigo-700 text-white",children:["Open Full Document",e(ot,{className:"h-4 w-4 ml-2"})]})]})]}):null}function ma(e){if(0===e)return"0 Bytes";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(2))+" "+["Bytes","KB","MB","GB","TB"][t]}function ua({onChange:n,isLoading:r,refresh:a}){const{client:s,project:i}=Ie(),l=f(),[d,m]=o(void 0),[u,h]=o(void 0),[p,g]=o(void 0),b=!(!i||!p?.embeddings.text&&!p?.embeddings.image),[v,x]=o(void 0);c((()=>{m(void 0),h(void 0),x(void 0)}),[a]),c((()=>{i&&s.projects.retrieve(i.id).then((e=>{g(e.configuration)}))}),[i]),c((()=>{v&&l({title:v,status:"success",duration:2e3})}),[v]),c((()=>{d&&0!==d.length||n(void 0)}),[d]);const w=async()=>{if(!b||!d||!p?.embeddings.text)return;x("Generating text embeddings...");return{values:(await s.environments.embeddings(p.embeddings.text?.environment,{model:p.embeddings.text?.model,text:d})).values,type:Te.text}},N=async()=>{if(!b||!d||!p?.embeddings.image)return;x("Generating image embeddings...");return{values:(await s.environments.embeddings(p.embeddings.image?.environment,{model:p.embeddings.image?.model,image:u})).values,type:Te.image}},k=(e="text")=>{("text"===e?w:N)().then((e=>{x("Embeddings generated"),e&&(n(e),x("Searching..."))}))};return t("div",{className:"flex gap-1 items-center w-1/2",children:[e($,{placeholder:"Type what you are looking for, or select a filter",value:d,onChange:m,onKeyDown:e=>{"Enter"===e.key&&k("text")}}),e(y,{variant:"secondary",isLoading:r,onClick:()=>k("text"),isDisabled:!b,alt:"semantic search",children:"Search"})]})}const ha=[{name:"ID",field:"id",type:"string?slice=-7"},{name:"Name",field:".",type:"objectLink"},{name:"Type",field:"type.name",type:"string"},{name:"Status",field:"status",type:"string"},{name:"Updated At",field:"updated_at",type:"date"}];function pa({onUploadDone:t=async()=>{},layout:n}){const r=Vr(),a=f(),s=Yr((async e=>{await t(e),setTimeout((()=>{console.log("Delayed refresh after upload to ensure backend consistency"),r.search().then((()=>{a({title:"Document list refreshed",description:"The document list has been updated with your uploaded files.",status:"info",duration:3e3})})).catch((e=>{console.error("Failed to refresh search results:",e)}))}),1e3)}));return e(ga,{layout:n,onUpload:(e,t)=>{const n=r.collectionId;return s(e,t,n)}})}function ga({layout:n,onUpload:r,allowFilter:a=!0,allowSearch:s=!0}){const i=Vr(),[l,d]=o(!1),[m,h]=o(null),{typeRegistry:p}=Ie(),{search:g,isLoading:f,error:b,objects:v}=Wr(),[x,w]=o(void 0),[N,k]=o(p?n||(C=p,((S=g.query.type)?C.getTypeLayout(S):ha)??ha):ha);var C,S;const[j,_]=o(0),[P,T]=o(0),[I,$]=o("grid"===localStorage.getItem(In.LAST_DISPLAYED_VIEW)),[E,A]=o([]),z=u(null);re(z,(()=>{l&&v.length>0&&v.length!=P&&(d(!1),g.loadMore().finally((()=>{T(v.length),d(!0)})))}),{deps:[l,v.length]}),c((()=>{g.search().then((()=>d(!0)))}),[]);const[D,O]=o(""),U=le(D,500);c((()=>{g.query.name=D,g.search().then((()=>d(!0)))}),[U]),c((()=>{if(x){if(g.query.vector=x,!N.find((e=>"Vector Similarity"===e.name))){const e=[...N,{name:"Vector Similarity",field:"score"}];k(e)}g.search().then((()=>d(!0)))}else delete g.query.vector,g.search().then((()=>d(!0)))}),[x?.values]);const F=qr(),R=Vr(),B=()=>{g.search().then((()=>d(!0)))},J=Sr(F),G=jr(R),H=new URL(window.location.href),K=H.searchParams.get("filters");if(K)try{const e=K.split(";"),t=e.filter((e=>{const[t]=e.split(":"),n=decodeURIComponent(t);return"start"!==n&&"end"!==n}));if(t.length!==e.length){const e=t.length>0?t.join(";"):"";e?H.searchParams.set("filters",e):H.searchParams.delete("filters"),window.history.replaceState({},"",H.toString())}}catch(b){console.error("Failed to clean start/end filters from URL:",b)}return t("div",{className:"flex flex-col gap-y-2",children:[e(fa,{object:m,onClose:()=>h(null)}),b&&e(ae,{title:"Error",children:b.message}),a&&t(M,{filterGroups:J,filters:E,setFilters:e=>{const t="function"==typeof e?e(E):e;A(t),G(t)},children:[t("div",{className:"flex flex-row gap-4 items-center justify-between w-full",children:[t("div",{className:"flex gap-2 items-center w-2/3",children:[s&&e(ua,{onChange:w,isLoading:f,refresh:j,className:"w-wull"}),e(V,{})]}),t("div",{className:"flex gap-1 items-center",children:[e(y,{variant:"outline",onClick:B,alt:"Refresh",children:e(at,{size:16})}),e(In,{onUpdate:$})]})]}),t("div",{className:"flex gap-2 items-center",children:[e(q,{}),e(W,{})]})]}),!a&&t("div",{className:"flex flex-row gap-4 items-center justify-between w-full",children:[e("div",{className:"flex gap-2 items-center w-2/3",children:s&&e(ua,{onChange:w,isLoading:f,refresh:j})}),t("div",{className:"flex gap-1 items-center",children:[e(y,{variant:"outline",onClick:B,alt:"Refresh",children:e(at,{size:16})}),e(In,{onUpdate:$})]})]}),e(Xr,{objects:v,isLoading:!v.length&&f,layout:N,onRowClick:h,onUpload:r,isGridView:I,collectionId:i.collectionId}),f&&e("div",{className:"flex justify-center",children:e(L,{size:"xl"})}),e("div",{ref:z})]})}function fa({object:n,onClose:r}){const{store:a}=Ie(),s=f(),i=Ct(),l=ca(a,s,n?.content?.source);return n?t(oe,{title:n.properties?.title||n.name,isOpen:!0,onClose:r,children:[t("div",{className:"flex items-center gap-x-2",children:[e(y,{variant:"ghost",size:"sm",title:"Open Object",onClick:()=>i(`/objects/${n.id}`),children:e(Qe,{className:"size-4"})}),n.content?.source&&e(y,{variant:"ghost",size:"sm",title:"Download",onClick:l,children:e(Ye,{className:"size-4"})})]}),e(ce,{className:"my-2"}),e("div",{className:"pt-2",children:e(Ln,{object:n,loadText:!0})})]}):null}var ba;function ya({isExporting:n,isOpen:r,onClose:a}){return t(j,{onClose:()=>a(void 0),isOpen:r,className:"relative overflow-visible",children:[e(_,{children:"Export Object Properties"}),!n&&e(va,{onClose:a}),n&&e(xa,{})]})}function va({onClose:n}){const[r,a]=o(void 0),[s,i]=o(void 0),l=["Export selected objects","Export all objects"];return t(P,{className:"min-h-[104px] pt-0 flex flex-col gap-y-4",children:[e("div",{className:"h-1/3",children:e(F,{options:l,value:s,onChange:i,placeholder:"Choose what to export",className:"h-full w-full text-sm",filterBy:"name",isClearable:!0})}),t("div",{className:"h-1/2 flex flex-col gap-y-8 content-between",children:[e(F,{options:Object.values(ba),value:r,onChange:a,placeholder:"Choose a format",className:"h-full w-full text-sm",filterBy:"name",isClearable:!0}),e(y,{className:"w-full",isDisabled:!r||!s,onClick:()=>{n(r,s==l[1])},children:"Export Properties"})]})]})}function xa({}){return e(P,{className:"min-h-[84px] pt-0",children:t("div",{className:"h-full grid flex-col gap-y-2 content-between justify-items-center",children:[t("div",{className:"text-sm flex flex-col gap-x-2",children:[e("p",{children:"EXPORT IS IN PROGRESS"}),e("p",{className:"pt-2 grid justify-items-center",children:"PLEASE WAIT"})]}),e(L,{size:"lg"})]})})}function wa({collection:t}){const n=f(),{client:r,typeRegistry:a}=Ie(),s=function(e,t){let n=e.table_layout;if(n&&n.length>0)return n;e.type&&t&&(n=t?.getTypeLayout(e.type.id));return n&&n.length>0?n:void 0}(t,a);return t.dynamic?e(ga,{layout:s}):e(pa,{onUploadDone:async e=>{e.length>0&&await r.store.collections.addMembers(t.id,e).catch((e=>{n({title:"Failed to add objects to collection",description:e.message,status:"error"})}))},layout:s})}!function(e){e.CSV="CSV",e.JSON="JSON"}(ba||(ba={}));const Na=n=>null===n?"None":t("div",{children:[e("div",{className:"text-sm",children:n.name}),e("div",{className:"text-xs text-gray-500",children:n.description})]});function ka({className:t,defaultValue:n,onChange:r,isClearable:a,multiple:s}){const i=Ie(),[l,d]=o(!1),[m,u]=o(),[h,p]=o([]);c((()=>{if(!l&&(d(!0),i.typeRegistry&&n)){if(s&&Array.isArray(n)){const e=i.typeRegistry.types.filter((e=>n.includes(e.id)));p(e)}const e=i.typeRegistry.types.find((e=>e.id===n));e&&u(e)}}),[i.typeRegistry,n,s]);const g=e=>{p(e),r(e)};return e("div",s?{className:"flex flex-col gap-4 content-between",children:e(ne,{options:i.typeRegistry?.types||[],value:h,onChange:g,placeholder:"Choose Content Types...",optionLabel:Na,className:t||"text-sm bg-background",filterBy:"name",isClearable:a||!1,multiple:!0})}:{className:"flex flex-col gap-4 content-between",children:e(ne,{options:i.typeRegistry?.types||[],value:m,onChange:e=>{u(e||void 0),r(e)},placeholder:"Choose a Content Type...",optionLabel:Na,className:t||"text-sm bg-background",filterBy:"name",isClearable:a||!1})})}function Ca({onClose:n,redirect:r=!0,onAddToCollection:a}){const s=Ct(),i=f(),[l,c]=o(!1),{client:d}=Ie(),[m,u]=o({dynamic:!1,name:"",description:""});function h(e,t){u({...m,[e]:t})}return t("form",{children:[t(Z,{children:[e(I,{label:"Name",required:!0,children:e($,{type:"text",value:m.name||"",onChange:e=>h("name",e)})}),e(I,{label:"Description",className:"mt-2",children:e("textarea",{className:ie.INPUT,value:m.description||"",onChange:e=>h("description",e.target.value)})}),e(I,{label:"Dynamic Collection",className:"mt-2",direction:"row",description:"Dynamically fetch content for the collection based on a query. If not enabled, then content must be added by users or agents.",children:e(de,{value:m.dynamic||!1,onChange:e=>h("dynamic",e)})}),!m.dynamic&&e(I,{label:"Allowed Content Types",className:"mt-4",description:"Optionally select which content types can be added to the collection. If not set, then all content types are allowed.",children:e(ka,{defaultValue:m.allowed_types||null,onChange:e=>{Array.isArray(e)?h("allowed_types",e.map((e=>e.id))):h("allowed_types",e?[e.id]:[])},isClearable:!0,multiple:!0})}),e(I,{label:"Type",className:"mt-2",description:"Optionally select a content type to assign custom properties and data to the collection.",children:e(ka,{defaultValue:m.type||null,onChange:e=>{Array.isArray(e)?h("type",e.length>0?e[0].id:null):h("type",e?.id||null)},isClearable:!0})})]}),e(te,{children:e(y,{isDisabled:l,onClick:()=>{m?.name&&m.name.trim()?(m.name=m.name.trim(),m.description&&(m.description=m.description.trim()),null==m.dynamic&&(m.dynamic=!1),c(!0),d.store.collections.create(m).then((e=>{n(),i({title:"Collection created",description:`Collection "${e.name}" created successfully`,status:"success",duration:3e3}),r&&s(`/collections/${e.id}`),a&&a(e.id)})).catch((e=>{i({title:"Failed to create collection",description:e.message,status:"error",duration:5e3})})).finally((()=>c(!1)))):i({title:"Name is required",description:"Please provide a name for the collection",status:"error",duration:5e3})},children:"Create Collection"})})]})}function Sa({isOpen:n,onClose:r}){return t(Q,{onClose:r,isOpen:n,children:[e(X,{children:"Create a Collection"}),e(Ca,{onClose:r})]})}function ja({}){const{client:r}=Ie(),a=f(),[s,i]=o(),[l,d]=o(!0),[m,u]=o(!1),{data:h,error:p,refetch:g}=B((()=>r.store.collections.search({})),[]);if(c((()=>{(h||p)&&d(!1)}),[h,p]),p)return e(ae,{title:"Collections fetch failed",children:p.message});return t(n,{children:[h&&(h.length>0?t(G,{className:"w-full",children:[e("thead",{children:t("tr",{children:[e("th",{children:"Name"}),e("th",{children:"Type"}),e("th",{children:"Created"}),e("th",{})]})}),e(H,{columns:4,isLoading:l,children:h.map((n=>t(me,{children:[e("td",{children:t("div",{className:"flex items-center gap-2",children:[_a(n.dynamic),e(kt,{href:`/collections/${n.id}`,children:n.name})]})}),e("td",{children:n.type?.name||"-"}),e("td",{children:St(n.created_at).fromNow()}),e("td",{className:"text-right",children:e(y,{variant:"destructive",size:"sm",onClick:()=>i(n.id),children:e(ct,{className:"size-4"})})})]},n.id)))})]}):e(ue,{title:"No Collections",buttonLabel:"New Collections",onClick:()=>u(!0),children:"Get started by creating a new Collections."})),e(Sa,{isOpen:m,onClose:()=>u(!1)}),e(he,{isOpen:!!s,title:"Delete Collection",content:"Are you sure you want to delete this collection? This action cannot be undone.",onConfirm:async()=>{if(s)try{await r.store.collections.delete(s),a({title:"Collection deleted",status:"success",duration:3e3}),g()}catch(e){console.error("Failed to delete collection:",e),a({title:"Failed to delete collection",description:e.message||"An error occurred",status:"error",duration:5e3})}finally{i(void 0)}},onCancel:()=>i(void 0)})]})}function _a(t){const n=t?"Dynamic Collection":"Static Collection",r=e(t?dt:mt,{className:"size-5"});return e(U,{description:n,className:"mr-2",children:r})}function Pa({objects:n,isLoading:r}){const a=Ct();return e("div",{children:t(G,{className:"w-full",children:[e("thead",{children:t("tr",{children:[e("th",{children:"Name"}),e("th",{children:"Strict Mode"}),e("th",{children:"Semantic Chunking"}),e("th",{children:"Updated At"})]})}),e(H,{isLoading:r,columns:3,children:n?.map((n=>t("tr",{onClick:()=>a(`/types/${n.id}`),className:"cursor-pointer hover:bg-muted",children:[e("td",{children:n.name}),e("td",{children:n.strict_mode?"Yes":"No"}),e("td",{children:n.is_chunkable?"Yes":"No"}),e("td",{children:St(n.updated_at).fromNow()})]},n.id)))})]})})}St.extend(qt),St.extend(qt);class Ta{client;limit;result=new K({objects:[],isLoading:!1});query={};constructor(e,t=100){this.client=e,this.limit=t}get objects(){return this.result.value.objects}get error(){return this.result.value.error}get isRunning(){return this.result.value.isLoading}getFilterValue(e){return this.query[e]}setFilterValue(e,t){this.query[e]=t,this.search()}reset(e=!1){this.result.value={objects:[],isLoading:e}}_updateRunningState(e){const t=this.result.value;this.result.value={objects:t.objects,isLoading:e,error:t.error}}async _search(e=!1){if(this.isRunning)return Promise.resolve(!1);this.result.value={isLoading:!0,objects:e?this.objects:[]};const t=this.limit,n=this.objects.length;return this.client.types.list({limit:t,offset:n,query:this.query}).then((async e=>(this.result.value={isLoading:!1,objects:this.objects.concat(e)},!0))).catch((e=>{throw this.result.value={error:e,isLoading:!1,objects:this.objects},e}))}search(){return this.isRunning?Promise.resolve(!1):this._search(!1)}loadMore(){return this.isRunning?Promise.resolve(!1):this._search(!0)}}const Ia=d(void 0);function $a(){return m(Ia)}function Ea(){const e=$a();return{...Y(e.result),search:e}}function Aa(){return $a().objects.length}function La({title:n,isOpen:r,onClose:a,okLabel:s,initialPayload:i}){const l=f(),[c,d]=o(i?.name),[m,u]=o(i?.description),[h,p]=o(i?.strict_mode??!1);return t(j,{isOpen:r,onClose:()=>a(),children:[e(_,{children:n}),e(P,{className:"pt-0",children:t("div",{className:"h-full flex flex-col gap-4 content-between",children:[t("div",{children:[e("label",{className:"block text-sm font-medium text-muted",children:"Name"}),e($,{value:c,onChange:d})]}),t("div",{children:[e("label",{className:"block text-sm font-medium text-muted",children:"Description"}),e(pe,{value:m,onChange:u})]})]})}),e(E,{children:t("div",{className:"flex justify-end gap-4",children:[e(y,{variant:"secondary",onClick:()=>a(),children:"Cancel"}),e(y,{variant:"primary",onClick:()=>(()=>{if(!c)return void l({status:"error",title:"Name is required",duration:5e3});a({name:c,description:m,strict_mode:h}).then((()=>a())),d(void 0),u(void 0),p(!1)})(),children:s})]})})]})}var za;function Da({isDirty:n=!1}){const r=Ie(),{store:a}=r,s=f(),[i,l]=o(!1),{search:d,isLoading:m,error:h,objects:p}=Ea(),[g,b]=o(""),y=le(g,500),v=u(null);re(v,(()=>{i&&d.loadMore()}),{deps:[i]}),c((()=>{d.search().then((()=>l(!0)))}),[]),c((()=>{d.query.name=g,d.search().then((()=>l(!0)))}),[y]);const[x,w]=o(void 0);c((()=>{d.query.chunkable=x?"Yes"==x:void 0,d.search().then((()=>l(!0)))}),[x]),c((()=>{n&&i&&d.search().then((()=>l(!0)))}),[n]);const[N,k]=o(!1);if(h)return e(ae,{title:"Failed to fetch ObjectTypes",children:h.message});return t("div",{className:"flex flex-col gap-4 h-full",children:[t("div",{className:"flex gap-4",children:[e($,{placeholder:"Filter by Name",value:g,onChange:b}),e(F,{className:"w-60",isClearable:!0,options:Object.values(za),value:x,onChange:e=>{w(e)},placeholder:"Is Chunkable"})]}),t("div",{className:"flex-1",children:[m||0!==p?.length?e(Pa,{objects:p,isLoading:m}):e(ue,{title:"No Type",buttonLabel:"Create Type",onClick:()=>{k(!0)},children:"Get started by creating a new Type."}),e(La,{okLabel:"Create",title:"Create Type",isOpen:N,onClose:async e=>e?a.types.create(e).then((async()=>{s({status:"success",title:"Type created",duration:2e3}),r.reloadTypes(),d.search().then((()=>l(!0)))})).catch((e=>{s({status:"error",title:"Error creating type",description:e.message,duration:5e3})})):(k(!1),Promise.resolve())})]})]})}!function(e){e.true="Yes",e.false="No"}(za||(za={}));const Oa=[Jt,Bt()];function Ua({objectType:n,onSchemaUpdate:r}){const{store:a}=Ie(),s=f(),[i,c]=o(!1),d=At(n.object_schema),m=u(void 0),[h,p]=o(!1),g=l((()=>function(e){if(!e)return"";return JSON.stringify(e,null,2)}(d.schema)),[d]),b=()=>{if(m.current){const e=m.current.getValue();try{const t=function(e){if(!e?.trim())return;return JSON.parse(e.trim())}(e);Fa(t),d.replaceSchema(t)}catch(e){return s({status:"error",title:"Invalid JSON Schema",description:e.message,duration:5e3}),!1}}return!0};return t("div",{className:"mx-2 my-2 rounded-2xl border border-solid shadow-md border-spacing-2",children:[t("div",{className:"flex items-center rounded-t-md border-b gap-x-2 py-2 pl-4 pr-2",children:[e("div",{className:"text-base font-semibold",children:"Schema Editor"}),e("div",{children:e(y,{variant:"outline",size:"sm",onClick:()=>{h&&!b()||p((e=>!e))},children:h?"Edit Schema":"Edit Json"})}),e("div",{className:"ml-auto flex gap-x-2",children:e(y,{isLoading:i,variant:"outline",size:"sm",onClick:()=>{h&&!b()||(c(!0),a.types.update(n.id,{object_schema:d.schema}).then((()=>{r(d),s({status:"success",title:"Schema updated",description:"The schema has been updated successfully",duration:2e3})})).catch((e=>{s({status:"error",title:"Failed to update schema",description:e.message,duration:5e3})})).finally((()=>{c(!1)})))},children:"Save Changes"})})]}),e("div",{className:"px-4 py-2",children:h?e(Lt,{value:g,extensions:Oa,editorRef:m}):e(zt,{schema:d})})]})}const Fa=e=>{try{new Tt({strict:!0}).compile(e)}catch(e){throw new Error(`Invalid JSON Schema definition: ${e.message}`)}};function Ra({children:t,limit:n,name:r,chunkable:a}){const{store:s}=Ie(),i=l((()=>{const e=new Ta(s,n);return e.query.name=r,e.query.chunkable=a,e}),[n]);return e(Ia.Provider,{value:i,children:t})}function Ma({isOpen:n,onClose:r,title:a="Select Content Type",children:s,initialSelectedType:i=null,confirmLabel:l="Select Type",allowNone:c=!0}){const{typeRegistry:d}=Ie(),[m,u]=o(i),h=d?.types||[],p=()=>{r(void 0)};return t(j,{isOpen:n,onClose:p,className:"w-full max-w-xl mx-auto",children:[e(_,{children:a}),t(P,{className:"p-6",children:[s,t("div",{className:"mb-4 mt-4",children:[t("label",{className:"block text-sm font-medium mb-2",children:["Content Type ",c&&e("span",{className:"text-gray-500 font-normal",children:"(Optional)"})]}),e(F,c?{options:h,value:m,optionLabel:e=>e?e.name:"Select a content type",placeholder:"Select a content type or leave empty for automatic detection",onChange:e=>u(e||null),filterBy:"name",isClearable:!0}:{options:h,value:m,optionLabel:e=>e?e.name:"Select a content type",placeholder:"Select a content type",onChange:e=>u(e||null),filterBy:"name"}),c&&t("div",{className:"mt-2 text-sm text-blue-600 flex items-center",children:[e(Ze,{className:"h-4 w-4 mr-1"}),t("span",{children:[e("strong",{children:"Type selection is optional."})," Leave empty to let Vertesia choose the appropriate type"]})]})]}),m?t("div",{className:"text-sm text-gray-500 bg-gray-50 p-3 rounded-md mb-4",children:[e("div",{className:"font-medium",children:m.name}),m.description&&e("div",{className:"mt-1",children:m.description})]}):c&&t("div",{className:"text-sm text-blue-600 bg-blue-50 p-3 rounded-md mb-4",children:[e("div",{className:"font-medium",children:"Automatic Type Detection"}),t("div",{className:"mt-1",children:["Vertesia will analyze each file's content and automatically select the most appropriate type.",e("br",{}),e("span",{className:"mt-1 block font-medium",children:"This is recommended for most uploads."})]})]})]}),t(E,{children:[e(y,{variant:"ghost",onClick:p,children:"Cancel"}),e(y,{onClick:()=>{r(m?.id??null)},children:m?`${l}: ${m.name}`:c?"Let Vertesia Choose":l})]})]})}const Va=[Jt,Bt()];function qa({objectType:n,onLayoutUpdate:r}){const a=f(),[s,i]=o(!1),{store:c}=Ie(),d=u(void 0),m=l((()=>Wa(n.table_layout)),[n.table_layout]),h=(e,t)=>{a({status:"error",title:e,description:t,duration:5e3})};return t("div",{className:"mx-2 my-2 rounded-2xl border border-solid shadow-xs",children:[t("div",{className:"flex items-center rounded-t-md border-b gap-x-2 py-2 pl-4 pr-2",children:[e("div",{className:"text-base font-semibold ",children:"Table Layout Editor"}),e("div",{className:"ml-auto flex gap-x-2",children:e(y,{isLoading:s,variant:"outline",size:"sm",onClick:()=>{if(!d.current)return;const e=d.current.getValue();let t;if(e)try{t=JSON.parse(e)}catch(e){return h("Invalid JSON",e.message)}else t=null;return Array.isArray(t)?t.some((e=>!e||!e.name||!e.field))?h("Invalid JSON","A table layout entry must contain the following properties:] {field, name, converter?}"):(i(!0),void c.types.update(n.id,{table_layout:t}).then((e=>{a({status:"success",title:"Table Layout updated",description:"The table layout has been updated successfully",duration:2e3}),r(e.table_layout)})).catch((e=>{a({status:"error",title:"Failed to update table layout",description:e.message,duration:5e3})})).finally((()=>{i(!1)}))):h("Invalid JSON","The table layout must be an array")},children:"Save Changes"})})]}),e("div",{className:"px-4 py-2",children:e(Lt,{value:m,extensions:Va,editorRef:d})})]})}function Wa(e){return e?JSON.stringify(e,null,2):"[\n\n]"}const Ba=[Jt,Bt()];function Ja({refetch:n,collection:r}){const a=r.type?.id,s=u(void 0),i=f(),{client:c}=Ie(),[d,m]=o(!1),[h,p]=o({name:r.name,description:r.description||"",query:r.query?JSON.stringify(r.query,null,2):"",tags:r.tags||[],type:r.type?.id||"",allowed_types:r.allowed_types||[]}),g=l((()=>Wa(r.table_layout)),[r.table_layout]),b=(e,t)=>{p({...h,[e]:t})};return t("div",{className:"flex flex-col gap-4 py-2",children:[e(I,{label:"Name",required:!0,children:e($,{value:h.name,onChange:e=>b("name",e)})}),e(I,{label:"Description",children:e("textarea",{className:ie.INPUT,value:h.description,onChange:e=>b("description",e.target.value)})}),!r.dynamic&&e(I,{label:"Allowed Content Types",description:"Select which content types can be added to the collection. If not set, then all content types are allowed.",children:e(ka,{defaultValue:h.allowed_types||null,onChange:e=>{Array.isArray(e)?b("allowed_types",e.map((e=>e.id))):b("allowed_types",e?[e.id]:[])},isClearable:!0,multiple:!0})}),r.dynamic&&e(I,{label:"Query",description:"Define the query to dynamically fetch content for the collection.",children:e("textarea",{className:ie.INPUT,value:h.query,onChange:e=>b("query",e.target.value)})}),e(I,{label:"Table Layout",description:"Define a custom layout for displaying the collection in tables.",children:e(Lt,{className:"border-1 rounded-md border-border",value:g,extensions:Ba,editorRef:s})}),e(I,{label:"Type",description:"Select a content type to assign custom properties and data to the collection.",children:e(ka,{defaultValue:h.type||null,onChange:e=>{Array.isArray(e)?b("type",e.length>0?e[0].id:null):b("type",e?.id||null)},isClearable:!0})}),e(y,{size:"lg",className:"w-min my-4",isDisabled:d,onClick:()=>{const e=h.query?JSON.parse(h.query):void 0,t={name:h.name,description:h.description,query:e,tags:h.tags,type:h.type,allowed_types:h.allowed_types};let a;if(t.name||(a="Name is required"),t.type||(t.type=null),a&&i({title:"Validation failed",description:a,status:"error",duration:5e3}),s.current){const e=s.current.getValue();if(e)try{t.table_layout=JSON.parse(e)}catch(e){return void i({title:"Invalid Table Layout",description:e.message,status:"error",duration:5e3})}else t.table_layout=null}m(!0),c.store.collections.update(r.id,t).then((()=>{n(),i({title:"Collection updated",description:"Collection has been updated successfully",status:"success",duration:3e3})})).catch((e=>{i({title:"Failed to update collection",description:e.message,status:"error",duration:5e3})})).finally((()=>{m(!1)}))},children:"Save Metadata"}),a&&e(Ga,{typeId:a,collection:r})]})}function Ga({typeId:t,collection:n}){const{client:r}=Ie(),{data:a,error:s}=B((()=>r.store.types.retrieve(t)),[t]);return s?e(ae,{title:"Failed to load type",children:s.message}):e(Ka,{title:"Properties",children:a&&e(Ha,{collection:n,schema:a.object_schema})})}function Ha({schema:t={},collection:n}){const{client:r}=Ie(),a=f(),s=l((()=>new Dt(t,n.properties||{})),[t,n]),[i,c]=o(!1);return e(Ot,{object:s,onSubmit:e=>{const t={properties:e||{}};c(!0),r.store.collections.update(n.id,t).then((()=>{a({title:"Collection properties updated",description:"Collection has been updated successfully",status:"success",duration:3e3})})).catch((e=>{a({title:"Failed to update collection properties",description:e.message,status:"error",duration:5e3})})).finally((()=>{c(!1)}))},children:e(y,{size:"lg",isLoading:i,className:"my-4",variant:"primary",type:"submit",children:"Save Properties"})})}function Ka({children:n,title:r}){return t("div",{className:"my-4",children:[e("div",{className:"text-lg text-gray-700 font-semibold border-b border-b-gray-300 py-2 mb-4",children:r}),n]})}function Ya({onChange:t,value:n,disabled:r=!1,className:a}){const{client:s}=Ie(),{data:i,error:l}=B((()=>s.store.collections.search({dynamic:!1})),[]);if(l)return e(ae,{title:"Collection fetch failed",children:l.message});const o=n?i?.find((e=>e.id===n)):void 0;return e(ne,{filterBy:"name",value:o,onChange:e=>{t(e?.id,e)},placeholder:"Select a collection",options:i||[],optionLabel:e=>e.name,by:"id",className:a,disabled:r})}function Qa({action:n,objectIds:r,children:a}){const{store:s}=Ie(),i=f(),[l,c]=o(!1),d=h((()=>(c(!0),Promise.resolve(!0))),[]);fs(n.id,d);return t("div",{children:[a,e(Ma,{isOpen:l,onClose:e=>{c(!1),void 0!==e&&s.runOperation({name:"change_type",ids:r,params:{typeId:e}}).then((e=>{i({status:"success",title:"Change Type",description:`Change the type of ${r.length} objects is ${"in_progress"===e.status?"in progress":"completed"}`,duration:2e3})})).catch((e=>{i({status:"error",title:"Error changing type",description:e.message,duration:5e3})}))},title:"Change Content Type",confirmLabel:"Change Type",children:t("div",{className:"text-sm flex flex-col gap-x-2",children:[t("p",{children:["Choose a new Content Type for the selected object",r.length>1?"s":" ","or let the system choose or generate a type based on the content."]}),t("p",{className:"pt-2 text-xs",children:["Note: This action will raise the ",e("code",{children:"change_type"})," event and will trigger the standard intake workflows which may reset the object properties."]})]})})]})}const Xa={id:"changeType",name:"Change Content Type",description:"Change the Content Type of the selected documents",confirm:!1,component:Qa};function Za({action:r,callback:a,children:s}){const[i,l]=o(!1),c=r.confirmationText||`Are you sure you want to ${r.name}?`,d=h((e=>r.confirm?(l(!0),Promise.resolve(!0)):a(e)),[r.confirm,a]),m=fs(r.id,d);return t(n,{children:[s,e(he,{onConfirm:()=>{l(!1),a({...m.params,action:r})},onCancel:()=>l(!1),title:"Are you sure?",content:c,isOpen:i})]})}function es({action:t,objectIds:n,children:r}){const a=gs(),s=f(),{client:i}=Ie(),l=Vr(),o=Ct(),c=h((()=>n&&n.length?Promise.all(n.map((e=>i.store.objects.delete(e)))).then((e=>{const t=e.length>1?"s":"";if(s({status:"success",title:`${e.length} object${t} deleted`,description:`Objects ${e.map((e=>e.id)).join(", ")} have been deleted`,duration:2e3}),l){a.params?.selection?.removeAll();const e=JSON.parse(JSON.stringify(l.facets));n.length===e._value.total&&l.resetFacets(),l.search()}else o("/objects")})).catch((e=>{s({status:"error",title:"Error deleting objects",description:e.message,duration:5e3})})):(s({status:"error",title:"No objects selected",description:"Please select objects to delete",duration:3e3}),Promise.resolve(!1))),[n]);return e(Za,{action:t,callback:c,children:r})}const ts={id:"delete",name:"Delete",description:"Delete the selected objects",confirm:!0,confirmationText:"Are you sure you want to delete the selected objects?",component:es,destructive:!0};function ns({action:t,objectIds:n}){const{store:r}=Ie(),a=f(),[s,i]=o(!1),[l,c]=o(!1),d=h((()=>(i(!0),Promise.resolve(!0))),[]),m=fs(t.id,d);return e("div",{children:e(ya,{isExporting:l,isOpen:s,onClose:(e,t)=>{if(e&&(t||n.length>0)){c(!0);const s=m.params?.search?.query||{},l=m.params?.search?.result?.value?.objects?.map((e=>e.id))||void 0,o=async e=>r.objects.list({query:{parent:e}}).then((e=>e.map((e=>e.id))));(async()=>t?l?s.vector?l:[]:0===n.length?[]:(await o(n[0])).concat(n):n)().then((l=>{r.objects.exportProperties({objectIds:l,type:e,query:t&&!s.vector?s:{type:s.type}}).then((r=>{let s;if(e===ba.CSV)s=new Blob([r.data],{type:r.type});else if(e===ba.JSON)s=new Blob([JSON.stringify(r.data)],{type:r.type});else{const e=r.data;s=new Blob([new Uint8Array(e.data)],{type:r.type})}const i=window.URL.createObjectURL(s),l=document.createElement("a");l.download=r.name,l.href=i,l.click(),a({status:"success",title:"Export Properties",description:t?"Export the properties of all objects completed":`Export the properties of ${n.length} object${n.length>1?"s":""} is completed`,duration:2e3})})).catch((e=>{a({status:"error",title:"Error Export Properties",description:e.message,duration:5e3})})).finally((()=>{c(!1),i(!1)}))}))}else i(!1)}})})}const rs={id:"exportProperties",name:"Export Properties",description:"Export all Object Properties",confirm:!1,component:ns};function as({action:t,objectIds:n,collectionId:r}){const a=gs(),s=f(),{client:i}=Ie(),l=Vr(),o=h((()=>n&&n.length?r?i.store.collections.deleteMembers(r,n).then((()=>{const e=n.length>1?"s":"";s({status:"success",title:`${n.length} object${e} removed from collection`,description:"Objects have been removed from the collection",duration:2e3}),l&&(a.params?.selection?.removeAll(),l.search())})).catch((e=>{s({status:"error",title:"Error removing objects from collection",description:e.message,duration:5e3})})):(s({status:"error",title:"No collection context",description:"Cannot remove objects: no collection specified",duration:3e3}),Promise.resolve(!1)):(s({status:"error",title:"No objects selected",description:"Please select objects to remove from collection",duration:3e3}),Promise.resolve(!1))),[n,r]);return e(Za,{action:t,callback:o})}const ss={id:"removeFromCollection",name:"Remove from Collection",description:"Remove the selected objects from this collection",confirm:!0,confirmationText:"Are you sure you want to remove the selected objects from this collection?",component:as,destructive:!0};function is({action:t,objectIds:n,collectionId:r}){const a=f(),{client:s}=Ie(),[i,l]=o(!1),c=h((()=>(l(!0),Promise.resolve(!0))),[]);return fs(t.id,c),e(os,{isOpen:i,onClose:e=>{if(l(!1),e)return s.store.workflows.rules.execute(e,n,{collection_id:r}).then((()=>{a({title:"Workflow started",status:"success",duration:3e3})})).catch((e=>{a({title:"Error starting workflow",status:"error",description:e.message,duration:9e3})}))}})}const ls={id:"startWorkflow",name:"Start Workflow",description:"Start an workflow on the selected objects",confirm:!1,hideInList:!0,component:is};function os({isOpen:n,onClose:r}){return t(Q,{onClose:()=>r(void 0),isOpen:n,className:"",children:[e(X,{children:"Start a Workflow by Rule"}),e(ds,{onClose:r})]})}function cs(n){return{label:t("div",{children:[e("div",{children:n.name}),e("div",{className:"text-sm text-muted",children:n.description})]}),reverse:!0}}function ds({onClose:n}){const[r,a]=o(void 0),s=gs();return t("div",{children:[t(Z,{children:[e("div",{className:"pb-2",children:"Choose a workflow rule to start:"}),e("div",{className:"max-h-[420px] overflow-y-scroll border-border border rounded-md",children:e(ge,{options:s.wfRules,optionLayout:cs,onChange:e=>{a(e)},value:r})})]}),t(te,{children:[e(y,{variant:"secondary",onClick:()=>n(),children:"Cancel"}),e(y,{onClick:()=>{r&&n(r.id)},isDisabled:!r,children:"Start"})]})]})}class ms{params;allActions=[rs,Xa,ls,vs,ts,ss];wfRules=[];callbacks={};startWorkflow;constructor(e){this.params=e}get actions(){return!!this.params.selection?.collectionId?this.allActions.filter((e=>"addToCollection"!==e.id&&"delete"!==e.id)):this.allActions.filter((e=>"removeFromCollection"!==e.id))}async loadWorkflows(){return this.params.client.workflows.rules.list().then((e=>{this.wfRules=e.map((e=>({id:e.id,name:e.name,description:e.description,confirm:!1,isWorkflow:!0,component:is}))).sort(((e,t)=>e.name.localeCompare(t.name)))})),this.wfRules}registerCallback(e,t){return this.callbacks[e]=t,()=>{delete this.callbacks[e]}}unregisterCallback(e){delete this.callbacks[e]}findAction(e){let t=this.allActions.find((t=>t.id===e));return t||(t=this.wfRules.find((t=>t.id===e))),t}async run(e){const t=this.findAction(e);if(!t)throw new Error(`Action ${e} not found`);const n={...this.params,action:t},r=this.callbacks[e];if(r)return r(n);throw new Error("No action callback set")}}const us=d(void 0);function hs({children:n}){const r=Ir(),a=f(),{client:s}=Ie(),i=Vr(),{data:o,error:c}=B((()=>s.workflows.rules.list().then((e=>e.map((e=>({id:e.id,name:e.name,description:e.description,confirm:!1,isWorkflow:!0,component:is}))).sort(((e,t)=>e.name.localeCompare(t.name)))))),[]),d=l((()=>{const e=new ms({selection:r,toast:a,client:s,search:i});return e.wfRules=o,e}),[r,o]);return c?e(ae,{title:"Failed to fetch workflows",children:c.message}):d&&t(us.Provider,{value:d,children:[e(ps,{}),n]})}function ps({}){const t=gs(),n=t.params.selection,r=n.getObjectId(),a=n.isSingleSelection()&&r?[r]:n.getObjectIds();return e("div",{style:{display:"none"},children:t.allActions.map((t=>e(t.component,{action:t,objectIds:a,collectionId:n.collectionId},t.id)))})}function gs(){const e=m(us);if(!e)throw new Error("You cannot use useActionContext outside an ActionProvider");return e}function fs(e,t){const n=gs();return c((()=>n.registerCallback(e,t)),[n,e,t]),n}function bs(e){const t=gs();return c((()=>(t.startWorkflow=e,()=>{t.startWorkflow=void 0})),[e,t]),t}function ys({action:t,objectIds:n}){const[r,a]=o(!1),s=h((()=>(n.length>0&&a(!0),Promise.resolve(!0))),[n]);return fs(t.id,s),r&&e(fe,{children:e(xs,{objectIds:n,isOpen:r,onClose:()=>{a(!1)}})})}const vs={id:"addToCollection",name:"Add to Collection",description:"Add documents to a collection",confirm:!1,component:ys};function xs({isOpen:n,onClose:r,objectIds:a}){return t(Q,{isOpen:n,onClose:r,children:[e(X,{className:"flex flex-col",children:"Add to a Collection"}),e(be,{children:"Add the selected objects to an existing collection or create a new one."}),e(ws,{onClose:r,objectIds:a})]})}function ws({onClose:n,objectIds:r}){const a=f(),{client:s}=Ie(),[i,l]=o(),c=({collectionId:e})=>{e&&r?.length&&s.store.collections.addMembers(e,r).then((()=>{a({title:"Add to collection success",status:"success",description:`Added ${r.length} objects to the selected collection`,duration:3e3}),n()})).catch((()=>{a({title:"Add to collection failure",status:"error",description:"Failed to add the selected objects to the collection",duration:5e3})}))},d=[{name:"select",label:"Select Collection",content:t("div",{className:"p-4",children:[e(ye,{level:5,children:"Choose from existing collections"}),e(Z,{children:e(Ya,{onChange:e=>{l(e)},value:i,className:"mb-4"})}),e(te,{children:e(y,{isDisabled:!i,onClick:()=>i&&c({collectionId:i}),children:"Add to Collection"})})]})},{name:"create",label:"Create new",content:e("div",{className:"p-4",children:e(Ca,{onClose:n,onAddToCollection:e=>c({collectionId:e}),redirect:!1})})}];return t(ve,{defaultValue:"select",tabs:d,fullWidth:!0,children:[e(xe,{}),e(we,{})]})}function Ns(){const n=Ir(),r=n.size(),a=r>1?"s":"",s=n?.hasSelection(),i=n?.isSingleSelection();return e(hs,{children:t("div",{className:"flex items-center gap-x-2",children:[s&&!i&&t("div",{className:"flex items-center gap-x-1 shrink-0",children:[t("div",{className:"text-sm nowrap",children:[r," document",a," selected"]}),e(y,{title:"Clear selection",variant:"ghost",onClick:()=>{n?.removeAll()},children:e($e,{className:"size-4"})})]}),e(_s,{selection:n,children:e(y,{variant:"ghost",alt:"More action",size:"sm",children:e(ut,{size:16})})}),s&&e(ks,{selection:n})]})})}function ks({}){return e(Ss,{})}function Cs({collectionId:r}){const[a,s]=o([]),i=Ir(),l=i?.hasSelection();return!l&&t(n,{children:[e(y,{onClick:()=>(()=>{const e=document.createElement("input");e.type="file",e?.click(),e.onchange=e=>{const t=e.target.files;t&&s(Array.from(t))}})(),children:"Upload"}),e(Kr,{collectionId:r??"",isOpen:a.length>0,onClose:()=>s([]),files:a,title:"Upload Files",onUploadComplete:e=>{e&&e.success&&s([])},children:e("div",{className:"text-sm",children:"Select the associated Content Type, or let the system choose or generate the type based on the content."})})]})}function Ss(){const t=gs();return t.params.selection.hasSelection()&&e(y,{onClick:()=>t.run(ls.id),children:"Start Workflow"})}function js(e){return{label:e.name,className:r("flex-1 px-2 py-2 hover:bg-accent nowrap",e.destructive?"text-destructive":"")}}function _s({selection:n,children:r}){const a=gs();return t(v,{hover:!0,children:[e(x,{children:r}),e(w,{className:"p-0 w-50",align:"end",sideOffset:6,children:e(Ps,{executeAction:e=>{a.run(e.id)},selection:n})})]})}function Ps({executeAction:t,selection:n}){const r=gs(),a=n?.hasSelection()?r.actions.filter((e=>!e.hideInList)):[rs];return e("div",{className:"rounded-md shadow-md py-2",children:e("div",{className:"px-1 text-sm",children:e(ge,{options:a,optionLayout:js,onChange:e=>{t(e)},noCheck:!0})})})}function Ts({value:n,onChange:r,onSend:a,disabled:s=!1,isSending:i=!1,isCompleted:l=!1,activeTaskCount:d=0,placeholder:m="Type your message..."}){const h=u(null),[p,g]=o(!1);c((()=>{!s&&l&&h.current?.focus()}),[s,l]);return t("div",{className:"p-3 border-t border-muted flex-shrink-0",style:{minHeight:"90px"},children:[t("div",{className:"flex items-center space-x-2",children:[t("div",{className:"flex flex-1 space-x-1",children:[e($,{ref:h,value:n,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),a())},onChange:r,disabled:s||i,placeholder:m,className:"pr-12 py-2.5"}),e(y,{variant:"ghost",className:"rounded-full",disabled:!l,onClick:()=>g(!0),alt:"Link Object",children:e(ht,{className:"size-4"})})]}),t(y,{onClick:a,disabled:s||i||!n.trim(),className:"px-4 py-2.5",children:[i?e(L,{size:"sm",className:"mr-2"}):e(pt,{className:"size-4 mr-2"})," Send"]})]}),e("div",{className:"text-xs text-muted mt-2 text-center",children:d>0?t("div",{className:"flex items-center justify-center",children:[e(gt,{className:"h-3 w-3 mr-1 text-attention"}),t("span",{children:["Agent has ",d," active workstream",1!==d?"s":""," running"]})]}):s?"Agent is processing, you can continue once it completes...":"You can send a message at any time"}),t(Q,{isOpen:p,onClose:()=>g(!1),className:"min-w-[60vw]",children:[e(X,{children:"Link Object"}),e(Z,{className:"pb-6",children:e(ra,{onChange:e=>{const t=`[${e.properties?.title||e.name||"Object"}](store:${e.id})`,a=n||"",s=h.current?.selectionStart||a.length,i=a.substring(0,s)+t+a.substring(s);r(i),g(!1),setTimeout((()=>{if(h.current){h.current.focus();const e=s+t.length;h.current.setSelectionRange(e,e)}}),100)}})})]})]})}function Is({plan:n,workstreamStatus:r,isVisible:a}){return a?t("div",{className:"border-b border-gray-200 dark:border-gray-800 bg-gray-50 dark:bg-gray-900 p-3 shadow-sm transition-all duration-300 ease-in-out transform",children:[e("div",{className:"text-xs font-medium mb-2 text-gray-800 dark:text-gray-200",children:"Agent Plan"}),n.plan&&n.plan.length>0?e("div",{className:"space-y-1.5",children:n.plan.map(((n,a)=>{const s=n.id.toString(),i=n.goal;let l=n.status||"pending";r.has(s)&&(l=r.get(s));let o=Ee,c="text-gray-400";return"in_progress"===l?(o=Le,c="text-blue-500"):"completed"===l&&(o=ze,c="text-green-500"),t("div",{className:"flex items-start",children:[e("div",{className:`mr-1.5 mt-0.5 ${c}`,children:e(o,{className:"h-3.5 w-3.5"})}),t("div",{className:"text-xs",children:[e("span",{className:"text-gray-700 dark:text-gray-300",children:i}),e("span",{className:"ml-1 bg-gray-200 dark:bg-gray-700 px-1 py-0.5 rounded text-[10px] font-mono",children:s})]})]},a)}))}):t("div",{className:"text-xs text-gray-500 dark:text-gray-400 italic flex items-center",children:[e(Ae,{className:"h-3.5 w-3.5 mr-1.5 text-amber-500"}),"No plan detected yet"]}),r.size>1&&t("div",{className:"mt-3 pt-2 border-t border-gray-200 dark:border-gray-700",children:[e("div",{className:"text-xs font-medium mb-1.5 text-gray-800 dark:text-gray-200",children:"Workstreams"}),e("div",{className:"grid grid-cols-2 gap-1.5",children:Array.from(r.entries()).filter((([e,t])=>{if("main"===e)return!0;if(/^\d+$/.test(e))return!1;if(n?.plan){return!n.plan.find((t=>t.id?.toString()===e))}return!0})).map((([n,r])=>{let a=Ee,s="text-gray-400",i="Pending";"in_progress"===r?(a=Le,s="text-blue-500",i="In Progress"):"completed"===r&&(a=ze,s="text-green-500",i="Completed");const l="main"===n?"Main":n;return t("div",{className:"flex items-center",children:[e("div",{className:`mr-1.5 ${s}`,children:e(a,{className:"h-3 w-3"})}),e("span",{className:"text-[10px] font-medium text-gray-600 dark:text-gray-400",children:l}),e("span",{className:"text-[10px] text-gray-500 dark:text-gray-500 ml-1",children:i})]},n)}))})]})]}):null}function $s(t){const{run:n,startWorkflow:r}=t;if(n){const r="runId"in n?n:{runId:n.run_id,workflowId:n.workflow_id};return e(Ls,{...t,run:r})}return r?e(As,{...t}):e(Es,{})}function Es(){return t(ee,{status:"info",icon:e(Oe,{className:"size-16 text-muted mb-4"}),children:[e("div",{className:"text-base font-medium text-muted",children:"No agent currently running"}),e("div",{className:"mt-3 text-sm text-muted",children:"Select an interaction and click Start to start an agent"})]})}function As({initialMessage:n,startWorkflow:r,onClose:a,isModal:s=!1,placeholder:i="Type your message...",startButtonText:l="Start Agent",title:d="Start New Conversation"}){const[m,h]=o(""),[p,g]=o(!1),[b,v]=o(),x=f(),w=u(null);c((()=>{w.current&&w.current.focus()}),[]);const N=async()=>{if(!r)return;const e=m.trim();if(e&&!p){g(!0);try{sessionStorage.removeItem("plan-panel-shown"),x({title:"Starting agent...",status:"info",duration:3e3});const t=await r(e);t&&(v({runId:t.run_id,workflowId:t.workflow_id}),h(""),x({title:"Agent started",status:"success",duration:3e3}))}catch(e){x({title:"Error starting workflow",status:"error",duration:3e3,description:e instanceof Error?e.message:"Unknown error"})}finally{g(!1)}}};return b?e(Ls,{onClose:a,isModal:s,initialMessage:n,placeholder:i,run:b,title:d}):t("div",{className:"flex flex-col h-full bg-white dark:bg-gray-900 overflow-hidden border-0",children:[t("div",{className:"flex items-center justify-between py-2 px-3 border-b border-gray-100 dark:border-gray-800 bg-white dark:bg-gray-900",children:[t("div",{className:"flex items-center space-x-2",children:[e("div",{className:"p-1",children:e(ft,{className:"h-3.5 w-3.5 text-gray-400 dark:text-gray-500"})}),e("span",{className:"font-medium text-sm text-gray-700 dark:text-gray-300",children:d})]}),a&&!s&&e(y,{size:"xs",variant:"ghost",onClick:a,title:"Close",className:"text-slate-500 hover:text-slate-700",children:e(Ve,{className:"h-4 w-4"})})]}),t("div",{className:"flex-1 overflow-y-auto px-4 py-6 bg-white dark:bg-gray-900 flex flex-col items-center justify-center",children:[n&&e("div",{className:"px-4 py-3 mb-4 bg-blue-50/80 dark:bg-blue-900/30 border-l-2 border-blue-400 dark:border-blue-500 text-blue-700 dark:text-blue-300 max-w-md",children:n}),t("div",{className:"bg-white dark:bg-slate-800 p-4 max-w-md border-l-2 border-blue-400 dark:border-blue-500",children:[e("div",{className:"text-base text-slate-600 dark:text-slate-300 font-medium",children:"Enter a message to start a conversation"}),t("div",{className:"mt-3 text-sm text-slate-500 dark:text-slate-400",children:["Type your question below and press Enter or click ",l," ","to begin"]})]})]}),t("div",{className:"py-3 px-3 border-t border-gray-100 dark:border-gray-800 bg-white dark:bg-gray-900",children:[t("div",{className:"flex items-center gap-2",children:[e("div",{className:"flex-1",children:e("input",{ref:w,value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),N())},placeholder:i,disabled:p,className:"w-full py-2 px-3 text-sm border border-gray-200 dark:border-gray-700 dark:bg-gray-800 dark:text-white focus:border-gray-300 dark:focus:border-gray-600 focus:ring-0 rounded-md"})}),t(y,{onClick:N,disabled:!m.trim()||p,className:"px-3 py-2 bg-gray-800 dark:bg-gray-700 hover:bg-gray-700 dark:hover:bg-gray-600 text-white text-xs rounded-md transition-colors",children:[p?e(L,{size:"sm",className:"mr-1.5"}):e(pt,{className:"h-3.5 w-3.5 mr-1.5"}),l]})]}),e("div",{className:"text-xs text-gray-400 dark:text-gray-500 mt-2 text-center",children:"Type a message to start the conversation"})]})]})}function Ls({run:n,title:r,interactive:a=!0,onClose:s,isModal:i=!1,placeholder:d="Type your message...",resetWorkflow:m}){const{client:h}=Ie(),p=u(null),[g,b]=o([]),[y,v]=o(!1),[x,w]=o(""),[N,k]=o(!1),[C,S]=o("sliding"),[j,_]=o(!1),[P,T]=o(!1),[I,$]=o([]),[E,A]=o(0),[L,z]=o(new Map),[D,O]=o(0),U=f(),[F,R]=o(a),[M,V]=o(null),q=l((()=>{const e=I[E]||{plan:{plan:[]},timestamp:0},t=L.get(e.timestamp)||new Map;return{plan:e.plan,workstreamStatus:t}}),[I,E,L]);c((()=>{if(!y){const e=setInterval((()=>{O((()=>Math.floor(Math.random()*(fn.length-1))))}),4e3);return()=>clearInterval(e)}}),[y]);c((()=>(b([]),$([]),A(0),z(new Map),T(!1),V(null),(async()=>{try{const e=await h.store.workflows.getRunDetails(n.runId,n.workflowId);V(e.status)}catch(e){console.error("Failed to check workflow status:",e)}})(),h.store.workflows.streamMessages(n.workflowId,n.runId,(e=>{e.message&&b((t=>t.find((t=>t.timestamp===e.timestamp))?t:(function(e,t){const n="number"==typeof t.timestamp?t.timestamp:new Date(t.timestamp).getTime(),r=e.findIndex((e=>("number"==typeof e.timestamp?e.timestamp:new Date(e.timestamp).getTime())>n));-1===r?e.push(t):e.splice(r,0,t)}(t,e),[...t])))})),()=>{b([])})),[n.runId,h.store.workflows]),c((()=>{v(!function(e){if(!e.length)return!0;const t=new Map;if(e.forEach((e=>{const n=yn(e);t.has(n)||t.set(n,[]),t.get(n).push(e)})),console.log("[isInProgress] Workstreams found:",Array.from(t.keys())),1===t.size&&!t.has("main")){const e=t.keys().next().value||"unknown";console.log(`[isInProgress] Only one workstream found (${e}), treating as main`);const n=t.get(e),r=n[n.length-1];return console.log(`[isInProgress] Last message type in only workstream: ${r.type}`),bn.includes(r.type)?(console.log("[isInProgress] Only workstream is completed"),!1):(console.log("[isInProgress] Only workstream is still in progress"),!0)}if(t.has("main")){const e=t.get("main");if(0===e.length)return console.log("[isInProgress] Main workstream exists but has no messages, still in progress"),!0;const n=e[e.length-1];return console.log(`[isInProgress] Last message type in main workstream: ${n.type}`),bn.includes(n.type)?(console.log("[isInProgress] Main workstream is completed"),!1):(console.log("[isInProgress] Main workstream is still in progress"),!0)}console.log("[isInProgress] Multiple workstreams but no main, checking if any are still active");for(const[e,n]of t.entries())if(n.length>0){const t=n[n.length-1];if(!bn.includes(t.type))return console.log(`[isInProgress] Workstream ${e} is still active`),!0}return console.log("[isInProgress] All workstreams are completed"),!1}(g)),0===I.length&&T(!1)}),[g,I.length]),c((()=>{if(1===I.length&&!P&&!sessionStorage.getItem("plan-panel-shown")){const e=setTimeout((()=>{T(!0),sessionStorage.setItem("plan-panel-shown","true")}),500);return()=>clearTimeout(e)}g.forEach((e=>{if(e.type===ke.PLAN)try{console.log("PLAN message received:",e.type);let t=null;if(e.details&&"object"==typeof e.details&&e.details.plan&&Array.isArray(e.details.plan)&&(console.log("Valid plan array found in message.details.plan"),t={plan:e.details.plan}),t){const n="number"==typeof e.timestamp?e.timestamp:new Date(e.timestamp).getTime();if(-1===I.findIndex((e=>e.timestamp===n))&&t){console.log("Adding new plan to plans array");const e={plan:t,timestamp:n};console.log("Adding plan to plans array:",e),$((t=>{const n=[e,...t];return console.log("New plans array:",n),n})),A(0),console.log("Setting showSlidingPanel to true"),T(!0);const r=new Map;r.set("main","in_progress"),Array.isArray(t.plan)&&t.plan.forEach((e=>{if(e&&"object"==typeof e&&e.id){const t=e.id.toString();r.set(t,e.status||"pending")}})),z((e=>{const t=new Map(e);return t.set(n,r),t}))}}}catch(e){console.error("Failed to parse plan from message:",e)}e.type===ke.UPDATE&&e.details&&e.details.updates&&Array.isArray(e.details.updates)&&console.log("Ignoring UPDATE message with details.updates - waiting for PLAN message with full plan")}));const e=g[g.length-1];e&&(e.type===ke.TERMINATED?(R(!1),V("TERMINATED")):R(!!a||e.type===ke.REQUEST_INPUT))}),[g,I,E]);const W=r||n.workflowId.split(":")[2]||"Agent Conversation";return t("div",{className:"flex flex-col h-full min-h-0 "+(i?"rounded-lg overflow-hidden":""),children:[e(_n,{title:W,isCompleted:y,onClose:s,isModal:i,run:n,viewMode:C,onViewModeChange:S,showPlanPanel:P,hasPlan:I.length>0,onTogglePlanPanel:()=>{T(!P),P||sessionStorage.setItem("plan-panel-shown","true")},onDownload:async()=>{try{const e=await async function(e,t){return e.files.getDownloadUrl(`agents/${t}/conversation.json`).then((e=>e.url))}(h,n.runId);e&&window.open(e,"_blank")}catch(e){console.error("Failed to download conversation",e),U({status:"error",title:"Failed to download conversation",duration:3e3})}},onCopyRunId:()=>{navigator.clipboard.writeText(n.runId),U({status:"success",title:"Run ID copied",duration:2e3})},resetWorkflow:m}),j&&!P&&I.length>0&&e(Is,{plan:q.plan,workstreamStatus:q.workstreamStatus,isVisible:!0}),0!==g.length||y?e(Nn,{messages:g,bottomRef:p,viewMode:C,isCompleted:y,plan:q.plan,workstreamStatus:q.workstreamStatus,showPlanPanel:P,onTogglePlanPanel:()=>{console.log("Toggle plan panel called, current state:",P),T(!P)},plans:I,activePlanIndex:E,onChangePlan:e=>A(e),taskLabels:q.plan.plan?.reduce(((e,t)=>(t.id&&t.goal&&e.set(t.id.toString(),t.goal),e)),new Map)}):e("div",{className:"flex-1 flex flex-col items-center justify-center h-full text-center py-6 bg-white dark:bg-gray-900",children:t("div",{className:"bg-white dark:bg-slate-800 p-5 max-w-md border border-blue-200 dark:border-blue-900/50 rounded-lg shadow-sm",children:[t("div",{className:"flex items-center space-x-3 mb-3",children:[e(dn,{size:"sm",color:"blue"}),e("div",{className:"text-sm text-slate-600 dark:text-slate-300 font-medium",children:fn[D]})]}),e("div",{className:"mt-4 flex justify-center",children:e(cn,{color:"blue",className:"mt-1"})})]})}),M&&("RUNNING"!==M?t(ee,{status:"COMPLETED"===M?"success":"done",icon:null,className:"flex-shrink-0 m-2",children:["This Workflow is ",M]}):F&&e(Ts,{value:x,onChange:w,onSend:()=>{const e=x.trim();e&&!N&&(k(!0),w(""),h.store.workflows.sendSignal(n.workflowId,n.runId,"UserInput",{message:e}).then((()=>{v(!1),U({status:"success",title:"Message Sent",duration:2e3})})).catch((e=>{U({status:"error",title:"Failed to Send Message",description:e instanceof Error?e.message:"Unknown error",duration:3e3})})).finally((()=>{k(!1)})))},disabled:!1,isSending:N,isCompleted:y,activeTaskCount:(()=>{if(!g.length)return 0;const e=new Map;g.forEach((t=>{const n=yn(t);"main"!==n&&"all"!==n&&(e.has(n)||e.set(n,[]),e.get(n).push(t))}));let t=0;for(const[n,r]of e.entries())if(r.length>0){const e=r[r.length-1];[ke.COMPLETE,ke.IDLE].includes(e.type)||t++}return t})(),placeholder:d}))]})}function zs({children:t,fallback:n}){return Ds?e(Ds,{fallback:n,children:t}):e(Gt,{FallbackComponent:n,children:t})}let Ds=null;function Os(e){Ds=e}function Us({children:t}){return e(zs,{fallback:Fs,children:t})}function Fs({error:n}){return t(ee,{status:"error",title:"Sorry, something went wrong...",children:[t("div",{className:"mb-4",children:["Our team has been notified and will be quickly working on resolving it. If you'd like to escalate or simply contact us, please email us at ",e("a",{className:"text-info",href:"mailto:support@vertesiahq.com",children:"support@vertesiahq.com"}),"."]}),n?.message&&e("code",{className:"w-full mt-4 text-sm text-muted break-words",children:n.message})]})}function Rs({children:t}){return e(zs,{fallback:Ms,children:t})}function Ms({error:n}){return e("tr",{children:t("td",{colSpan:100,children:[e("span",{className:"text-xs",children:" Cannot display row"}),e("br",{}),e("span",{className:"bg-gray-400",children:n?.message})]})})}function Vs({children:t}){return e(zs,{fallback:qs,children:t})}function qs({error:n}){return console.log("WidgetError",n),t("div",{className:"text-sm",children:["Sorry, this area cannot be loaded or rendered.",n?.message&&e("pre",{children:n.message})]})}function Ws({className:n,children:a,title:s,description:i,actions:l,breadcrumbs:o,isCompact:c=!1}){return t("div",{className:r(c?"pb-0":"pb-2","p-4 flex flex-col",n),children:[t("div",{className:"flex items-start gap-4",children:[t("div",{className:"w-full flex place-content-between h-auto min-h-8 flex-col items-start",children:[e("nav",{className:"flex-1 flex justify-start text-xs",children:o?.map(((n,r)=>t("div",{className:"flex items-center text-muted",children:[n,r<o.length-1&&e(ot,{className:"w-3.5 h-3.5"})]},r)))}),t("div",{className:"flex gap-2 items-center",children:[e("h1",{className:"text-xl font-semibold break-all",children:s}),i&&e(U,{description:i,children:e(Fe,{className:"size-4 text-muted"})})]})]}),e("div",{className:"flex gap-x-2 shrink-0",children:l})]}),a&&e("div",{className:"w-full flex items-center",children:a})]})}function Bs({}){return t("div",{className:"text-center pt-32",children:[e("h1",{className:"text-3xl font-bold text-red-500",children:"404"}),e("p",{className:"text-2xl",children:"Page Not Found"})]})}class Js{totalPages;layoutUrls=[];cache;constructor(e){this.totalPages=e,this.cache=new Array(e)}async loadUrls(e,t){const n=[];for(let r=0;r<this.totalPages;r++)n.push(Zs(e,t,r+1));const r=await Promise.all(n);this.layoutUrls=r.map((e=>e.url))}async getPageLayout(e){const t=e-1;let n=this.cache[t];if(void 0===n){const e=this.layoutUrls[t];n=await fetch(e,{method:"GET"}).then((e=>{if(e.ok)return e.text();throw new Error("Failed to fetch json layout: "+e.statusText)})),this.cache[t]=n}return n}}const Gs=d(void 0);function Hs({children:t,object:n}){const{client:r}=Ie(),[a,s]=o();return c((()=>{const e=n.metadata.page_count||10;(async function(e,t,n){const r=[];for(let a=0;a<n;a++)r.push(Ys(e,t.id,a+1));const a=await Promise.all(r),s=[];for(let r=0;r<n;r++)s.push(Qs(e,t.id,r+1));const i=await Promise.all(s),l=[];for(let r=0;r<n;r++)l.push(Xs(e,t.id,r+1));const o=await Promise.all(l),c=new Js(n);await c.loadUrls(e,t.id);const d=t.text?ni(t.text):"";return{count:n,urls:a.map((e=>e.url)),annotatedUrls:i.map((e=>e.url)),instrumentedUrls:o.map((e=>e.url)),layoutProvider:c,xml:d,xmlPages:t.text?ti(d):[]}})(r,n,e).then(s)}),[n.id]),a&&e(Gs.Provider,{value:a,children:t})}function Ks(e){return`magic-pdf/${e}`}function Ys(e,t,n){return e.files.getDownloadUrl(function(e,t,n=".jpg"){return`${Ks(e)}/pages/page-${t}${n}`}(t,n))}function Qs(e,t,n){return e.files.getDownloadUrl(function(e,t,n=".jpg"){return`${Ks(e)}/pages/page-${t}-annotated${n}`}(t,n))}function Xs(e,t,n){return e.files.getDownloadUrl(function(e,t,n=".jpg"){return`${Ks(e)}/pages/page-${t}.instrumented${n}`}(t,n))}function Zs(e,t,n){return e.files.getDownloadUrl(function(e,t){return`${Ks(e)}/pages/page-${t}.layout.json`}(t,n))}function ei(){const e=i.useContext(Gs);if(!e)throw new Error("usePdfPagesInfo must be used within a PdfPageProvider");return e}function ti(e){const t=(new DOMParser).parseFromString(ni(e),"text/xml").getElementsByTagName("page"),n=new XMLSerializer;return Array.from(t).map((e=>n.serializeToString(e)))}function ni(e){return e.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,"").replace(/<\?xml.*?\?>/g,"")}function ri({object:n}){const{client:r}=Ie(),a=e=>{(function(e,t,n){return e.files.getDownloadUrl(`${Ks(t)}/${n}`).then((e=>e.url))})(r,n.id,e).then((e=>window.open(e,"_blank")))};return e("div",{className:"absolute bottom-[58px] right-[20px] w-[36px] h-[36px] cursor-pointer text-indigo-400 border-indigo-400 hover:border-indigo-500 hover:text-indigo-500 border-2 rounded-full shadow-xs flex items-center justify-center",children:t(Ut,{strategy:"absolute",placement:"top-end",zIndex:100,offset:20,children:[e(Ut.Trigger,{click:!0,children:e(bt,{className:"size-6"})}),e(Ut.Content,{children:t("div",{className:"rounded-md shadow-md border border-gray-100 bg-white dark:bg-slate-50 dark:border-slate-100 min-w-[200px] flex flex-col divide-y",children:[e("button",{className:"p-2 cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-100",onClick:()=>a("annotated.pdf"),children:"annotated.pdf"}),e("button",{className:"p-2 cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-100",onClick:()=>a("document.xml"),children:"document.xml"}),e("button",{className:"p-2 cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-100",onClick:()=>a("analyzed-pages.json"),children:"analyzed-pages.json"})]})})]})})}var ai;function si({className:n,currentPage:a,onChange:s}){const[i,l]=o(ai.default),c=u(null),{urls:d,annotatedUrls:m,instrumentedUrls:h}=ei(),p=i===ai.instrumented?h:i===ai.annotated?m:d;return t("div",{ref:c,className:r("flex flex-col items-stretch gap-y-2",n),children:[t("div",{className:"flex h-5 items-center justify-center relative",children:[e("button",{className:li,onClick:()=>{a>1&&(s(a-1),c.current&&c.current.querySelector(`div[data-index="${a-1}"]`)?.scrollIntoView({behavior:"smooth",block:"end",inline:"center"}))},children:e(yt,{className:"w-5 h-5"})}),t("div",{className:"absolute right-3 flex gap-x-1",children:[e("button",{className:oi(ai.default,i),onClick:()=>l(ai.default),children:e(vt,{className:"w-5 h-5 mt-1"})}),e("button",{className:oi(ai.instrumented,i),onClick:()=>l(ai.instrumented),children:e(xt,{className:"w-5 h-5 mt-1"})}),e("button",{className:oi(ai.annotated,i),onClick:()=>l(ai.annotated),children:e(wt,{className:"w-5 h-5 mt-1"})})]})]}),e("div",{className:"flex flex-col items-center gap-2 flex-1 overflow-y-auto px-2",children:p.map(((t,n)=>e(ii,{url:t,currentPage:a,pageNumber:n+1,onSelect:()=>s(n+1)},n)))}),e("div",{className:"flex h-5 items-center justify-center relative",children:e("button",{className:li,onClick:()=>{a<d.length&&(s(a+1),c.current&&c.current.querySelector(`div[data-index="${a+1}"]`)?.scrollIntoView({behavior:"smooth",block:"end",inline:"center"}))},children:e(Nt,{className:"size-5"})})})]})}function ii({url:n,pageNumber:a,currentPage:s,onSelect:i}){return t("div",{className:"p-2 hover:bg-gray-200 dark:hover:bg-slate-600 rounded-md","data-index":a-1,children:[e("div",{className:r("relative border-[2px] cursor-pointer",a===s?"border-blue-500 dark:border-pink-400":"border-gray-300"),onClick:i,children:e("img",{src:n,alt:`Page ${a}`})}),e(Ne,{className:"text-sm text-gray-500 dark:text-gray-400 pt-1 font-semibold align",children:a})]})}!function(e){e[e.default=0]="default",e[e.instrumented=1]="instrumented",e[e.annotated=2]="annotated"}(ai||(ai={}));const li="cursor-pointer text-gray-500 dark:text-gray-400 hover:text-blue-600 dark:hover:text-blue-500 hover:font-semibold";function oi(e,t){return e===t?"${BTN_CLASS} text-pink-600":`${li}`}const ci={attributeKeyColor:"#FFD700",attributeValueColor:"#FF4500",tagColor:"#87CEFA",textColor:"#00FF00",separatorColor:"#FFD700",commentColor:"#BEBEBE",cdataColor:"#33CC66"};function di({viewType:t,pageNumber:n}){return e("json"===t?ui:mi,{pageNumber:n})}function mi({pageNumber:t}){const[n,r]=o(),{xmlPages:a}=ei();return p((()=>{const e=window.matchMedia("(prefers-color-scheme: dark)"),t=e=>{r(e.matches?ci:void 0)};return e.addEventListener("change",t),e.matches&&r(ci),()=>{e.removeEventListener("change",t)}}),[]),e("div",{className:"px-4 py-2",children:e(Rt,{xml:a[t-1],collapsible:!0,theme:n})})}function ui({pageNumber:t}){const[n,r]=o(),{layoutProvider:a}=ei();return c((()=>{a.getPageLayout(t).then((e=>r(e?JSON.parse(e):void 0))).catch((e=>{console.error(e),r(void 0)}))}),[t]),n&&e(Ft,{className:"w-full",data:n})}function hi({objectId:t,onClose:n}){const{client:r}=Ie(),{data:a,error:s}=B((()=>r.store.objects.retrieve(t,"+text")),[t]);return s?e(ae,{title:"Fetching document failed",children:s.message}):a?e("div",{className:"fixed inset-0 bg-white dark:bg-slate-700 z-50 flex items-center justify-center",children:e(Hs,{object:a,children:e(pi,{object:a,onClose:n})})}):"Loading..."}function pi({object:r,onClose:a}){const[s,i]=o("xml"),[l,d]=o(1),m=u(null),h=u(null),p=u(null);var g;return c((()=>{if(g.handler.current&&g.left.current&&g.right.current){const e=g.handler.current,t=g.left.current,n=g.right.current,r=e=>{let r=e.clientX,a=t.offsetWidth,s=n.offsetLeft;const i=e=>{const i=e.clientX-r;t.style.width=`${a+i}px`,n.style.left=`${s+i}px`,e.target.classList.add("resizing")},l=e=>{e.target.classList.remove("resizing"),i(e),document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",l)};document.addEventListener("mousemove",i),document.addEventListener("mouseup",l)};return e.addEventListener("mousedown",r),()=>{e.removeEventListener("mousedown",r)}}}),[(g={handler:m,left:h,right:p}).handler.current,g.left.current,g.right.current]),t(n,{children:[t("div",{ref:h,className:"absolute top-0 left-0 bottom-0 w-[50%] bg-gray-100 dark:bg-slate-800 flex items-stretch justify-stretch py-2",children:[e(si,{className:"flex-1",currentPage:l,onChange:d}),e("div",{ref:m,className:"w-[2px] p-[2px] m-0 bg-slate-300 cursor-ew-resize"})]}),e("div",{ref:p,className:"absolute top-0 left-[50%] right-0 bottom-0 flex items-stretch justify-stretch overflow-auto p-2",children:e(di,{pageNumber:l,viewType:s})}),e(ri,{object:r}),e(gi,{type:s,onSwitch:i}),!!a&&e("div",{className:"absolute top-6 right-7 w-9 h-9 cursor-pointer text-red-400 border-red-400 hover:border-red-500 hover:text-red-500 border-2 rounded-full shadow-xs flex items-center justify-center",onClick:a,children:e($e,{className:"size-6"})})]})}function gi({type:e="xml",onSwitch:n}){return t("div",{className:"absolute bottom-[16px] right-[20px] w-[36px] h-[36px] cursor-pointer text-indigo-400 border-indigo-400 hover:border-indigo-500 hover:text-indigo-500 border-2 rounded-full shadow-xs flex items-center justify-center",onClick:()=>{"xml"===e?n("json"):"json"===e&&n("xml")},children:["xml"===e&&fi,"json"===e&&bi]})}const fi=e("svg",{width:"16px",height:"16px",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",children:e("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M6 2.984V2h-.09c-.313 0-.616.062-.909.185a2.33 2.33 0 0 0-.775.53 2.23 2.23 0 0 0-.493.753v.001a3.542 3.542 0 0 0-.198.83v.002a6.08 6.08 0 0 0-.024.863c.012.29.018.58.018.869 0 .203-.04.393-.117.572v.001a1.504 1.504 0 0 1-.765.787 1.376 1.376 0 0 1-.558.115H2v.984h.09c.195 0 .38.04.556.121l.001.001c.178.078.329.184.455.318l.002.002c.13.13.233.285.307.465l.001.002c.078.18.117.368.117.566 0 .29-.006.58-.018.869-.012.296-.004.585.024.87v.001c.033.283.099.558.197.824v.001c.106.273.271.524.494.753.223.23.482.407.775.53.293.123.596.185.91.185H6v-.984h-.09c-.2 0-.387-.038-.563-.115a1.613 1.613 0 0 1-.457-.32 1.659 1.659 0 0 1-.309-.467c-.074-.18-.11-.37-.11-.573 0-.228.003-.453.011-.672.008-.228.008-.45 0-.665a4.639 4.639 0 0 0-.055-.64 2.682 2.682 0 0 0-.168-.609A2.284 2.284 0 0 0 3.522 8a2.284 2.284 0 0 0 .738-.955c.08-.192.135-.393.168-.602.033-.21.051-.423.055-.64.008-.22.008-.442 0-.666-.008-.224-.012-.45-.012-.678a1.47 1.47 0 0 1 .877-1.354 1.33 1.33 0 0 1 .563-.121H6zm4 10.032V14h.09c.313 0 .616-.062.909-.185.293-.123.552-.3.775-.53.223-.23.388-.48.493-.753v-.001c.1-.266.165-.543.198-.83v-.002c.028-.28.036-.567.024-.863-.012-.29-.018-.58-.018-.869 0-.203.04-.393.117-.572v-.001a1.502 1.502 0 0 1 .765-.787 1.38 1.38 0 0 1 .558-.115H14v-.984h-.09c-.196 0-.381-.04-.557-.121l-.001-.001a1.376 1.376 0 0 1-.455-.318l-.002-.002a1.415 1.415 0 0 1-.307-.465v-.002a1.405 1.405 0 0 1-.118-.566c0-.29.006-.58.018-.869a6.174 6.174 0 0 0-.024-.87v-.001a3.537 3.537 0 0 0-.197-.824v-.001a2.23 2.23 0 0 0-.494-.753 2.331 2.331 0 0 0-.775-.53 2.325 2.325 0 0 0-.91-.185H10v.984h.09c.2 0 .387.038.562.115.174.082.326.188.457.32.127.134.23.29.309.467.074.18.11.37.11.573 0 .228-.003.452-.011.672-.008.228-.008.45 0 .665.004.222.022.435.055.64.033.214.089.416.168.609a2.285 2.285 0 0 0 .738.955 2.285 2.285 0 0 0-.738.955 2.689 2.689 0 0 0-.168.602c-.033.21-.051.423-.055.64a9.15 9.15 0 0 0 0 .666c.008.224.012.45.012.678a1.471 1.471 0 0 1-.877 1.354 1.33 1.33 0 0 1-.563.121H10z"})}),bi=e("svg",{width:"16px",height:"16px",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",children:e("path",{d:"M4.708 5.578L2.061 8.224l2.647 2.646-.708.708-3-3V7.87l3-3 .708.708zm7-.708L11 5.578l2.647 2.646L11 10.87l.708.708 3-3V7.87l-3-3zM4.908 13l.894.448 5-10L9.908 3l-5 10z"})});function yi(...e){const t=Array.from(e);return t.__AnyOf__=!0,t}function vi(...e){return Array.from(e)}function xi(e){return!0===e.__AnyOf__}class wi{system_roles;roles;permissions;constructor(e,t){if(!e.authToken)throw new Error("No auth token found in user session");this.system_roles=t;const n=new Set(e.authToken.account_roles||[]);if(e.authToken.project_roles)for(const t of e.authToken.project_roles)n.add(t);this.roles=n;const r={};for(const e of t)r[e.name]=e.permissions;const a=new Set;for(const e of n){const t=r[e];if(t)for(const e of t)a.add(e)}this.permissions=a}hasPermission(e){if("string"==typeof e)return this.permissions.has(e);if(xi(e))return e.some((e=>this.permissions.has(e)));for(const t of e)if(!this.permissions.has(t))return!1;return!0}}const Ni=d(void 0);function ki(){const e=m(Ni);if(!e)throw new Error("UserPermissionContext cannot be used outside UserPermissionProvider");return e}function Ci({children:t}){const n=Ie(),{data:r,error:a,isLoading:s}=B((()=>n.user?n.client.iam.roles.list():Promise.resolve(void 0)),[n.user]),i=l((()=>n.authToken&&r&&!s?new wi(n,r):void 0),[n,r,s]);return a?e(ae,{title:"Failed to fetch role mappings",children:a.message}):i&&e(Ni.Provider,{value:i,children:t})}function Si({permission:t,isDisabled:n,title:r,children:a,...s}){return ki().hasPermission(t)||(n=!0,r="You do not have permission to perform this action"),e(y,{isDisabled:n,title:r,...s,children:a})}function ji({permission:t,...n}){return ki().hasPermission(t)?e(Ht,{...n}):null}function _i({user:n}){return t("div",{className:"flex items-center",children:[e("div",{className:"w-9 h-9",children:(()=>{if(n.picture)return e("img",{className:"inline-block h-9 w-9 rounded-full",src:n.picture,alt:n.name});{const t=n.name.split(" ").map((e=>e[0])).join("");return e("span",{className:"inline-flex h-8 w-8 items-center justify-center rounded-full bg-indigo-600",children:e("span",{className:"text-sm font-medium leading-none text-white",children:t})})}})()}),t("div",{className:"ml-3",children:[e("p",{className:"text-sm font-medium text-gray-700 dark:text-slate-50 group-hover:text-gray-900",children:n.name??"Deleted User"}),e("p",{className:"text-xs font-medium text-gray-500 dark:text-slate-300 group-hover:text-gray-700",children:n.email??"Deleted User"})]})]})}export{Xt as ActivitiesDoc,en as ActivityDoc,vs as AddToCollectionAction,ys as AddToCollectionActionComponent,vi as AllOf,cn as AnimatedThinkingDots,yi as AnyOf,fr as ApiKeyAvatar,wa as BrowseCollectionView,Xa as ChangeTypeAction,Qa as ChangeTypeActionComponent,ja as CollectionsTable,In as ContentDispositionButton,Da as ContentObjectTypesSearch,Pa as ContentObjectTypesTable,Ln as ContentOverview,Ca as CreateCollectionForm,Sa as CreateCollectionModal,La as CreateOrUpdateTypeModal,ts as DeleteObjectsAction,es as DeleteObjectsActionComponent,Fr as DocumentGridView,Kn as DocumentIcon,oa as DocumentInput,da as DocumentPreviewPanel,Rr as DocumentSearch,ta as DocumentSearchProvider,ga as DocumentSearchResults,pa as DocumentSearchResultsWithDropZone,Pr as DocumentSelection,Er as DocumentSelectionProvider,Xr as DocumentTable,Or as DocumentTableColumn,Ur as DocumentTableView,Kr as DocumentUploadModal,_r as DocumentsFacetsNav,Ja as EditCollectionView,Xn as EnvironmentFacet,rs as ExportPropertiesAction,ns as ExportPropertiesComponent,ya as ExportPropertiesModal,ba as ExportTypes,rr as FacetsNav,Jr as FileUploadAction,Ws as GenericPageNavHeader,on as JumpingDots,hi as MagicPdfView,$s as ModernAgentConversation,Bs as NotFoundView,Ua as ObjectSchemaEditor,Ta as ObjectTypeSearch,Ia as ObjectTypeSearchContext,Ra as ObjectTypeSearchProvider,ms as ObjectsActionContext,hs as ObjectsActionContextProvider,Us as PanelErrorBoundary,kn as PayloadBuilder,Sn as PayloadBuilderProvider,Cn as PayloadContext,An as PropertiesEditorModal,dn as PulsatingCircle,un as PulsingMessageLoader,ss as RemoveFromCollectionAction,as as RemoveFromCollectionActionComponent,Rs as RowErrorBoundary,wr as RunsFacetsNav,En as SaveVersionConfirmModal,Mr as SearchContext,Si as SecureButton,ji as SecureSidebarItem,Ya as SelectCollection,ka as SelectContentType,Ma as SelectContentTypeModal,ra as SelectDocument,ia as SelectDocumentModal,Ns as SelectionActions,ls as StartWorkflowAction,is as StartWorkflowComponent,Zn as StringFacet,er as StringListFacet,qa as TableLayoutEditor,hn as ThinkingBar,fn as ThinkingMessages,nr as TypeFacet,mn as TypedDots,Cs as UploadObjectsButton,_i as UserAvatar,hr as UserInfo,Ci as UserPermissionProvider,wi as UserPermissions,ar as VFacetsNav,sr as VStringFacet,ir as VTypeFacet,yr as VUserFacet,zs as VertesiaErrorBoundary,pn as WavyThinking,Vs as WidgetErrorBoundary,Cr as WorkflowExecutionsFacetsNav,_a as collectionIcon,xi as isAnyOf,Mn as isCsv,Vn as isImage,qn as isPdf,Wn as isVideo,Hn as retrieveRendition,Os as setErrorBoundaryComponent,zn as shortId,Dn as shortenString,Wa as stringifyTableLayout,Sr as useDocumentFilterGroups,jr as useDocumentFilterHandler,Vr as useDocumentSearch,Br as useDocumentSearchCount,Ir as useDocumentSelection,Yr as useDocumentUploadHandler,ca as useDownloadDocument,or as useFetchUserInfo,fs as useObjectsActionCallback,gs as useObjectsActionContext,$r as useOptionalDocumentSelection,jn as usePayloadBuilder,vr as useRunsFilterGroups,xr as useRunsFilterHandler,$a as useSearch,Aa as useSearchCount,Hr as useSmartFileUploadProcessing,bs as useStartWorkflowCallback,ki as useUserPermissions,qr as useWatchDocumentSearchFacets,Wr as useWatchDocumentSearchResult,Ea as useWatchSearchResult,Nr as useWorkflowExecutionsFilterGroups,kr as useWorkflowExecutionsFilterHandler};
2
2
  //# sourceMappingURL=vertesia-ui-features.js.map