@oneuptime/common 9.2.27 → 9.3.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 (263) hide show
  1. package/Models/DatabaseModels/AIAgent.ts +589 -0
  2. package/Models/DatabaseModels/AIAgentOwnerTeam.ts +434 -0
  3. package/Models/DatabaseModels/AIAgentOwnerUser.ts +433 -0
  4. package/Models/DatabaseModels/AIAgentTask.ts +549 -0
  5. package/Models/DatabaseModels/AIAgentTaskLog.ts +417 -0
  6. package/Models/DatabaseModels/AIAgentTaskPullRequest.ts +731 -0
  7. package/Models/DatabaseModels/AIAgentTaskTelemetryException.ts +388 -0
  8. package/Models/DatabaseModels/Index.ts +15 -0
  9. package/Models/DatabaseModels/Monitor.ts +33 -0
  10. package/Models/DatabaseModels/Project.ts +25 -0
  11. package/Models/DatabaseModels/TelemetryException.ts +1 -1
  12. package/Server/API/AIAgentAPI.ts +200 -0
  13. package/Server/API/AIAgentDataAPI.ts +692 -0
  14. package/Server/API/AIAgentTaskAPI.ts +286 -0
  15. package/Server/API/AIAgentTaskLogAPI.ts +165 -0
  16. package/Server/API/AIAgentTaskPullRequestAPI.ts +14 -0
  17. package/Server/API/GitHubAPI.ts +25 -7
  18. package/Server/API/TelemetryExceptionAPI.ts +169 -0
  19. package/Server/EnvironmentConfig.ts +3 -0
  20. package/Server/Infrastructure/Postgres/SchemaMigrations/1766590916627-MigrationName.ts +195 -0
  21. package/Server/Infrastructure/Postgres/SchemaMigrations/1766600860972-MigrationName.ts +31 -0
  22. package/Server/Infrastructure/Postgres/SchemaMigrations/1766606720183-MigrationName.ts +17 -0
  23. package/Server/Infrastructure/Postgres/SchemaMigrations/1766688107858-MigrationName.ts +63 -0
  24. package/Server/Infrastructure/Postgres/SchemaMigrations/1766754182870-MigrationName.ts +75 -0
  25. package/Server/Infrastructure/Postgres/SchemaMigrations/1766774689743-MigrationName.ts +157 -0
  26. package/Server/Infrastructure/Postgres/SchemaMigrations/1766777986427-MigrationName.ts +33 -0
  27. package/Server/Infrastructure/Postgres/SchemaMigrations/1766918848434-AddAIAgentIsDefault.ts +27 -0
  28. package/Server/Infrastructure/Postgres/SchemaMigrations/1766923324521-MigrationName.ts +37 -0
  29. package/Server/Infrastructure/Postgres/SchemaMigrations/1766958924188-AddGitHubAppInstallationIdToProject.ts +31 -0
  30. package/Server/Infrastructure/Postgres/SchemaMigrations/1767009661768-MigrationName.ts +35 -0
  31. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +22 -0
  32. package/Server/Services/AIAgentOwnerTeamService.ts +10 -0
  33. package/Server/Services/AIAgentOwnerUserService.ts +10 -0
  34. package/Server/Services/AIAgentService.ts +564 -0
  35. package/Server/Services/AIAgentTaskLogService.ts +10 -0
  36. package/Server/Services/AIAgentTaskPullRequestService.ts +10 -0
  37. package/Server/Services/AIAgentTaskService.ts +178 -0
  38. package/Server/Services/AIAgentTaskTelemetryExceptionService.ts +39 -0
  39. package/Server/Services/Index.ts +10 -0
  40. package/Server/Services/TelemetryExceptionService.ts +162 -0
  41. package/Server/Utils/Monitor/MonitorResource.ts +228 -0
  42. package/Server/Utils/PushNotificationUtil.ts +29 -0
  43. package/Server/Utils/WhatsAppTemplateUtil.ts +6 -0
  44. package/Tests/UI/Components/Badge.test.tsx +5 -5
  45. package/Tests/UI/Components/Card.test.tsx +4 -8
  46. package/Tests/UI/Components/HiddenText.test.tsx +2 -5
  47. package/Tests/UI/Components/SideMenuItem.test.tsx +4 -2
  48. package/Types/AI/AIAgentTaskMetadata.ts +25 -0
  49. package/Types/AI/AIAgentTaskStatus.ts +65 -0
  50. package/Types/AI/AIAgentTaskType.ts +40 -0
  51. package/Types/Email/EmailTemplateType.ts +2 -0
  52. package/Types/Monitor/MonitorEvaluationSummary.ts +2 -1
  53. package/Types/NotificationSetting/NotificationSettingEventType.ts +4 -0
  54. package/Types/Permission.ts +176 -0
  55. package/Types/WhatsApp/WhatsAppTemplates.ts +9 -0
  56. package/UI/Components/AIAgent/AIAgent.tsx +69 -0
  57. package/UI/Components/Badge/Badge.tsx +9 -5
  58. package/UI/Components/Banner/Banner.tsx +1 -1
  59. package/UI/Components/Card/Card.tsx +14 -12
  60. package/UI/Components/CodeBlock/CodeBlock.tsx +47 -4
  61. package/UI/Components/Detail/Detail.tsx +239 -49
  62. package/UI/Components/Detail/FieldLabel.tsx +35 -11
  63. package/UI/Components/Detail/PlaceholderText.tsx +18 -1
  64. package/UI/Components/Footer/Footer.tsx +9 -7
  65. package/UI/Components/Header/Header.tsx +4 -3
  66. package/UI/Components/Header/HeaderIconDropdownButton.tsx +13 -11
  67. package/UI/Components/Header/IconDropdown/IconDropdownItem.tsx +3 -3
  68. package/UI/Components/Header/IconDropdown/IconDropdownMenu.tsx +1 -1
  69. package/UI/Components/Header/ProjectPicker/CreateNewProjectButton.tsx +4 -4
  70. package/UI/Components/Header/ProjectPicker/ProjectPicker.tsx +6 -6
  71. package/UI/Components/Header/ProjectPicker/ProjectPickerFilterBox.tsx +3 -3
  72. package/UI/Components/Header/ProjectPicker/ProjectPickerMenu.tsx +1 -1
  73. package/UI/Components/Header/ProjectPicker/ProjectPickerMenuItem.tsx +4 -4
  74. package/UI/Components/HeaderAlert/HeaderAlert.tsx +32 -32
  75. package/UI/Components/HeaderAlert/HeaderAlertGroup.tsx +1 -7
  76. package/UI/Components/HiddenText/HiddenText.tsx +98 -27
  77. package/UI/Components/Icon/Icon.tsx +12 -9
  78. package/UI/Components/InfoCard/InfoCard.tsx +7 -3
  79. package/UI/Components/ModelTable/BaseModelTable.tsx +1 -1
  80. package/UI/Components/ObjectID/ObjectIDView.tsx +73 -0
  81. package/UI/Components/Page/Page.tsx +3 -5
  82. package/UI/Components/SideMenu/SideMenu.tsx +175 -40
  83. package/UI/Components/SideMenu/SideMenuDivider.tsx +17 -0
  84. package/UI/Components/SideMenu/SideMenuItem.tsx +111 -158
  85. package/UI/Components/SideMenu/SideMenuSection.tsx +53 -3
  86. package/UI/Components/Table/Table.tsx +1 -1
  87. package/UI/Components/Types/FieldType.ts +2 -0
  88. package/UI/Config.ts +5 -0
  89. package/build/dist/Models/DatabaseModels/AIAgent.js +614 -0
  90. package/build/dist/Models/DatabaseModels/AIAgent.js.map +1 -0
  91. package/build/dist/Models/DatabaseModels/AIAgentOwnerTeam.js +452 -0
  92. package/build/dist/Models/DatabaseModels/AIAgentOwnerTeam.js.map +1 -0
  93. package/build/dist/Models/DatabaseModels/AIAgentOwnerUser.js +451 -0
  94. package/build/dist/Models/DatabaseModels/AIAgentOwnerUser.js.map +1 -0
  95. package/build/dist/Models/DatabaseModels/AIAgentTask.js +580 -0
  96. package/build/dist/Models/DatabaseModels/AIAgentTask.js.map +1 -0
  97. package/build/dist/Models/DatabaseModels/AIAgentTaskLog.js +438 -0
  98. package/build/dist/Models/DatabaseModels/AIAgentTaskLog.js.map +1 -0
  99. package/build/dist/Models/DatabaseModels/AIAgentTaskPullRequest.js +771 -0
  100. package/build/dist/Models/DatabaseModels/AIAgentTaskPullRequest.js.map +1 -0
  101. package/build/dist/Models/DatabaseModels/AIAgentTaskTelemetryException.js +404 -0
  102. package/build/dist/Models/DatabaseModels/AIAgentTaskTelemetryException.js.map +1 -0
  103. package/build/dist/Models/DatabaseModels/Index.js +14 -0
  104. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  105. package/build/dist/Models/DatabaseModels/Monitor.js +34 -0
  106. package/build/dist/Models/DatabaseModels/Monitor.js.map +1 -1
  107. package/build/dist/Models/DatabaseModels/Project.js +26 -0
  108. package/build/dist/Models/DatabaseModels/Project.js.map +1 -1
  109. package/build/dist/Models/DatabaseModels/TelemetryException.js +1 -1
  110. package/build/dist/Models/DatabaseModels/TelemetryException.js.map +1 -1
  111. package/build/dist/Server/API/AIAgentAPI.js +141 -0
  112. package/build/dist/Server/API/AIAgentAPI.js.map +1 -0
  113. package/build/dist/Server/API/AIAgentDataAPI.js +415 -0
  114. package/build/dist/Server/API/AIAgentDataAPI.js.map +1 -0
  115. package/build/dist/Server/API/AIAgentTaskAPI.js +199 -0
  116. package/build/dist/Server/API/AIAgentTaskAPI.js.map +1 -0
  117. package/build/dist/Server/API/AIAgentTaskLogAPI.js +106 -0
  118. package/build/dist/Server/API/AIAgentTaskLogAPI.js.map +1 -0
  119. package/build/dist/Server/API/AIAgentTaskPullRequestAPI.js +9 -0
  120. package/build/dist/Server/API/AIAgentTaskPullRequestAPI.js.map +1 -0
  121. package/build/dist/Server/API/GitHubAPI.js +23 -8
  122. package/build/dist/Server/API/GitHubAPI.js.map +1 -1
  123. package/build/dist/Server/API/TelemetryExceptionAPI.js +120 -0
  124. package/build/dist/Server/API/TelemetryExceptionAPI.js.map +1 -0
  125. package/build/dist/Server/EnvironmentConfig.js +2 -0
  126. package/build/dist/Server/EnvironmentConfig.js.map +1 -1
  127. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766590916627-MigrationName.js +74 -0
  128. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766590916627-MigrationName.js.map +1 -0
  129. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766600860972-MigrationName.js +18 -0
  130. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766600860972-MigrationName.js.map +1 -0
  131. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766606720183-MigrationName.js +12 -0
  132. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766606720183-MigrationName.js.map +1 -0
  133. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766688107858-MigrationName.js +28 -0
  134. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766688107858-MigrationName.js.map +1 -0
  135. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766754182870-MigrationName.js +32 -0
  136. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766754182870-MigrationName.js.map +1 -0
  137. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766774689743-MigrationName.js +60 -0
  138. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766774689743-MigrationName.js.map +1 -0
  139. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766777986427-MigrationName.js +18 -0
  140. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766777986427-MigrationName.js.map +1 -0
  141. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766918848434-AddAIAgentIsDefault.js +16 -0
  142. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766918848434-AddAIAgentIsDefault.js.map +1 -0
  143. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766923324521-MigrationName.js +20 -0
  144. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766923324521-MigrationName.js.map +1 -0
  145. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766958924188-AddGitHubAppInstallationIdToProject.js +16 -0
  146. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1766958924188-AddGitHubAppInstallationIdToProject.js.map +1 -0
  147. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1767009661768-MigrationName.js +18 -0
  148. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1767009661768-MigrationName.js.map +1 -0
  149. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +22 -0
  150. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  151. package/build/dist/Server/Services/AIAgentOwnerTeamService.js +9 -0
  152. package/build/dist/Server/Services/AIAgentOwnerTeamService.js.map +1 -0
  153. package/build/dist/Server/Services/AIAgentOwnerUserService.js +9 -0
  154. package/build/dist/Server/Services/AIAgentOwnerUserService.js.map +1 -0
  155. package/build/dist/Server/Services/AIAgentService.js +471 -0
  156. package/build/dist/Server/Services/AIAgentService.js.map +1 -0
  157. package/build/dist/Server/Services/AIAgentTaskLogService.js +9 -0
  158. package/build/dist/Server/Services/AIAgentTaskLogService.js.map +1 -0
  159. package/build/dist/Server/Services/AIAgentTaskPullRequestService.js +9 -0
  160. package/build/dist/Server/Services/AIAgentTaskPullRequestService.js.map +1 -0
  161. package/build/dist/Server/Services/AIAgentTaskService.js +158 -0
  162. package/build/dist/Server/Services/AIAgentTaskService.js.map +1 -0
  163. package/build/dist/Server/Services/AIAgentTaskTelemetryExceptionService.js +36 -0
  164. package/build/dist/Server/Services/AIAgentTaskTelemetryExceptionService.js.map +1 -0
  165. package/build/dist/Server/Services/Index.js +10 -0
  166. package/build/dist/Server/Services/Index.js.map +1 -1
  167. package/build/dist/Server/Services/TelemetryExceptionService.js +137 -0
  168. package/build/dist/Server/Services/TelemetryExceptionService.js.map +1 -1
  169. package/build/dist/Server/Utils/Monitor/MonitorResource.js +168 -0
  170. package/build/dist/Server/Utils/Monitor/MonitorResource.js.map +1 -1
  171. package/build/dist/Server/Utils/PushNotificationUtil.js +21 -0
  172. package/build/dist/Server/Utils/PushNotificationUtil.js.map +1 -1
  173. package/build/dist/Server/Utils/WhatsAppTemplateUtil.js +4 -0
  174. package/build/dist/Server/Utils/WhatsAppTemplateUtil.js.map +1 -1
  175. package/build/dist/Tests/UI/Components/Badge.test.js +5 -5
  176. package/build/dist/Tests/UI/Components/Badge.test.js.map +1 -1
  177. package/build/dist/Tests/UI/Components/Card.test.js +4 -8
  178. package/build/dist/Tests/UI/Components/Card.test.js.map +1 -1
  179. package/build/dist/Tests/UI/Components/HiddenText.test.js +2 -3
  180. package/build/dist/Tests/UI/Components/HiddenText.test.js.map +1 -1
  181. package/build/dist/Tests/UI/Components/SideMenuItem.test.js +3 -2
  182. package/build/dist/Tests/UI/Components/SideMenuItem.test.js.map +1 -1
  183. package/build/dist/Types/AI/AIAgentTaskMetadata.js +6 -0
  184. package/build/dist/Types/AI/AIAgentTaskMetadata.js.map +1 -0
  185. package/build/dist/Types/AI/AIAgentTaskStatus.js +51 -0
  186. package/build/dist/Types/AI/AIAgentTaskStatus.js.map +1 -0
  187. package/build/dist/Types/AI/AIAgentTaskType.js +29 -0
  188. package/build/dist/Types/AI/AIAgentTaskType.js.map +1 -0
  189. package/build/dist/Types/Email/EmailTemplateType.js +2 -0
  190. package/build/dist/Types/Email/EmailTemplateType.js.map +1 -1
  191. package/build/dist/Types/NotificationSetting/NotificationSettingEventType.js +3 -0
  192. package/build/dist/Types/NotificationSetting/NotificationSettingEventType.js.map +1 -1
  193. package/build/dist/Types/Permission.js +160 -0
  194. package/build/dist/Types/Permission.js.map +1 -1
  195. package/build/dist/Types/WhatsApp/WhatsAppTemplates.js +6 -0
  196. package/build/dist/Types/WhatsApp/WhatsAppTemplates.js.map +1 -1
  197. package/build/dist/UI/Components/AIAgent/AIAgent.js +32 -0
  198. package/build/dist/UI/Components/AIAgent/AIAgent.js.map +1 -0
  199. package/build/dist/UI/Components/Badge/Badge.js +9 -5
  200. package/build/dist/UI/Components/Badge/Badge.js.map +1 -1
  201. package/build/dist/UI/Components/Banner/Banner.js +1 -1
  202. package/build/dist/UI/Components/Banner/Banner.js.map +1 -1
  203. package/build/dist/UI/Components/Card/Card.js +12 -12
  204. package/build/dist/UI/Components/Card/Card.js.map +1 -1
  205. package/build/dist/UI/Components/CodeBlock/CodeBlock.js +22 -2
  206. package/build/dist/UI/Components/CodeBlock/CodeBlock.js.map +1 -1
  207. package/build/dist/UI/Components/Detail/Detail.js +117 -37
  208. package/build/dist/UI/Components/Detail/Detail.js.map +1 -1
  209. package/build/dist/UI/Components/Detail/FieldLabel.js +12 -7
  210. package/build/dist/UI/Components/Detail/FieldLabel.js.map +1 -1
  211. package/build/dist/UI/Components/Detail/PlaceholderText.js +4 -1
  212. package/build/dist/UI/Components/Detail/PlaceholderText.js.map +1 -1
  213. package/build/dist/UI/Components/Footer/Footer.js +6 -6
  214. package/build/dist/UI/Components/Footer/Footer.js.map +1 -1
  215. package/build/dist/UI/Components/Header/Header.js +4 -3
  216. package/build/dist/UI/Components/Header/Header.js.map +1 -1
  217. package/build/dist/UI/Components/Header/HeaderIconDropdownButton.js +7 -7
  218. package/build/dist/UI/Components/Header/HeaderIconDropdownButton.js.map +1 -1
  219. package/build/dist/UI/Components/Header/IconDropdown/IconDropdownItem.js +3 -3
  220. package/build/dist/UI/Components/Header/IconDropdown/IconDropdownItem.js.map +1 -1
  221. package/build/dist/UI/Components/Header/IconDropdown/IconDropdownMenu.js +1 -1
  222. package/build/dist/UI/Components/Header/IconDropdown/IconDropdownMenu.js.map +1 -1
  223. package/build/dist/UI/Components/Header/ProjectPicker/CreateNewProjectButton.js +4 -4
  224. package/build/dist/UI/Components/Header/ProjectPicker/CreateNewProjectButton.js.map +1 -1
  225. package/build/dist/UI/Components/Header/ProjectPicker/ProjectPicker.js +6 -6
  226. package/build/dist/UI/Components/Header/ProjectPicker/ProjectPicker.js.map +1 -1
  227. package/build/dist/UI/Components/Header/ProjectPicker/ProjectPickerFilterBox.js +2 -2
  228. package/build/dist/UI/Components/Header/ProjectPicker/ProjectPickerFilterBox.js.map +1 -1
  229. package/build/dist/UI/Components/Header/ProjectPicker/ProjectPickerMenu.js +1 -1
  230. package/build/dist/UI/Components/Header/ProjectPicker/ProjectPickerMenu.js.map +1 -1
  231. package/build/dist/UI/Components/Header/ProjectPicker/ProjectPickerMenuItem.js +4 -4
  232. package/build/dist/UI/Components/Header/ProjectPicker/ProjectPickerMenuItem.js.map +1 -1
  233. package/build/dist/UI/Components/HeaderAlert/HeaderAlert.js +31 -29
  234. package/build/dist/UI/Components/HeaderAlert/HeaderAlert.js.map +1 -1
  235. package/build/dist/UI/Components/HeaderAlert/HeaderAlertGroup.js +1 -3
  236. package/build/dist/UI/Components/HeaderAlert/HeaderAlertGroup.js.map +1 -1
  237. package/build/dist/UI/Components/HiddenText/HiddenText.js +33 -14
  238. package/build/dist/UI/Components/HiddenText/HiddenText.js.map +1 -1
  239. package/build/dist/UI/Components/Icon/Icon.js +3 -4
  240. package/build/dist/UI/Components/Icon/Icon.js.map +1 -1
  241. package/build/dist/UI/Components/InfoCard/InfoCard.js +3 -3
  242. package/build/dist/UI/Components/InfoCard/InfoCard.js.map +1 -1
  243. package/build/dist/UI/Components/ModelTable/BaseModelTable.js +1 -1
  244. package/build/dist/UI/Components/ModelTable/BaseModelTable.js.map +1 -1
  245. package/build/dist/UI/Components/ObjectID/ObjectIDView.js +30 -0
  246. package/build/dist/UI/Components/ObjectID/ObjectIDView.js.map +1 -0
  247. package/build/dist/UI/Components/Page/Page.js +3 -3
  248. package/build/dist/UI/Components/Page/Page.js.map +1 -1
  249. package/build/dist/UI/Components/SideMenu/SideMenu.js +82 -17
  250. package/build/dist/UI/Components/SideMenu/SideMenu.js.map +1 -1
  251. package/build/dist/UI/Components/SideMenu/SideMenuDivider.js +7 -0
  252. package/build/dist/UI/Components/SideMenu/SideMenuDivider.js.map +1 -0
  253. package/build/dist/UI/Components/SideMenu/SideMenuItem.js +68 -97
  254. package/build/dist/UI/Components/SideMenu/SideMenuItem.js.map +1 -1
  255. package/build/dist/UI/Components/SideMenu/SideMenuSection.js +18 -3
  256. package/build/dist/UI/Components/SideMenu/SideMenuSection.js.map +1 -1
  257. package/build/dist/UI/Components/Table/Table.js +1 -1
  258. package/build/dist/UI/Components/Table/Table.js.map +1 -1
  259. package/build/dist/UI/Components/Types/FieldType.js +2 -0
  260. package/build/dist/UI/Components/Types/FieldType.js.map +1 -1
  261. package/build/dist/UI/Config.js +2 -0
  262. package/build/dist/UI/Config.js.map +1 -1
  263. package/package.json +1 -1
@@ -0,0 +1,564 @@
1
+ import User from "../../Models/DatabaseModels/User";
2
+ import CreateBy from "../Types/Database/CreateBy";
3
+ import { OnCreate, OnUpdate } from "../Types/Database/Hooks";
4
+ import DatabaseService from "./DatabaseService";
5
+ import ObjectID from "../../Types/ObjectID";
6
+ import Version from "../../Types/Version";
7
+ import Model, {
8
+ AIAgentConnectionStatus,
9
+ } from "../../Models/DatabaseModels/AIAgent";
10
+ import AIAgentOwnerUser from "../../Models/DatabaseModels/AIAgentOwnerUser";
11
+ import AIAgentOwnerUserService from "./AIAgentOwnerUserService";
12
+ import LIMIT_MAX, { LIMIT_PER_PROJECT } from "../../Types/Database/LimitMax";
13
+ import AIAgentOwnerTeam from "../../Models/DatabaseModels/AIAgentOwnerTeam";
14
+ import AIAgentOwnerTeamService from "./AIAgentOwnerTeamService";
15
+ import TeamMemberService from "./TeamMemberService";
16
+ import BadDataException from "../../Types/Exception/BadDataException";
17
+ import ProjectService from "./ProjectService";
18
+ import Dictionary from "../../Types/Dictionary";
19
+ import OneUptimeDate from "../../Types/Date";
20
+ import UserNotificationSettingService from "./UserNotificationSettingService";
21
+ import NotificationSettingEventType from "../../Types/NotificationSetting/NotificationSettingEventType";
22
+ import logger from "../Utils/Logger";
23
+ import { CallRequestMessage } from "../../Types/Call/CallRequest";
24
+ import { SMSMessage } from "../../Types/SMS/SMS";
25
+ import { EmailEnvelope } from "../../Types/Email/EmailMessage";
26
+ import EmailTemplateType from "../../Types/Email/EmailTemplateType";
27
+ import DatabaseConfig from "../DatabaseConfig";
28
+ import URL from "../../Types/API/URL";
29
+ import UpdateBy from "../Types/Database/UpdateBy";
30
+ import PushNotificationMessage from "../../Types/PushNotification/PushNotificationMessage";
31
+ import PushNotificationUtil from "../Utils/PushNotificationUtil";
32
+ import { createWhatsAppMessageFromTemplate } from "../Utils/WhatsAppTemplateUtil";
33
+ import { WhatsAppMessagePayload } from "../../Types/WhatsApp/WhatsAppMessage";
34
+ import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
35
+ import { IsBillingEnabled } from "../EnvironmentConfig";
36
+ import GlobalCache from "../Infrastructure/GlobalCache";
37
+ import QueryHelper from "../Types/Database/QueryHelper";
38
+
39
+ export class Service extends DatabaseService<Model> {
40
+ public constructor() {
41
+ super(Model);
42
+ }
43
+
44
+ public async saveLastAliveInCache(
45
+ aiAgentId: ObjectID,
46
+ lastAlive: Date,
47
+ ): Promise<void> {
48
+ if (!aiAgentId) {
49
+ throw new BadDataException("aiAgentId is required");
50
+ }
51
+
52
+ try {
53
+ await GlobalCache.setString(
54
+ "ai-agent-last-alive",
55
+ aiAgentId.toString(),
56
+ OneUptimeDate.toString(lastAlive),
57
+ );
58
+ } catch (err) {
59
+ logger.error("Error in saving last alive in cache");
60
+ logger.error(err);
61
+ }
62
+ }
63
+
64
+ public async shouldSaveLastAlive(aiAgentId: ObjectID): Promise<boolean> {
65
+ const now: Date = OneUptimeDate.getCurrentDate();
66
+
67
+ try {
68
+ // before we hit the database, we need to check if the lastAlive was updated in Global Cache.
69
+ const previousLastAliveCheck: string | null = await GlobalCache.getString(
70
+ "ai-agent-last-alive",
71
+ aiAgentId.toString(),
72
+ );
73
+
74
+ if (!previousLastAliveCheck) {
75
+ await this.saveLastAliveInCache(aiAgentId, now);
76
+ return true;
77
+ }
78
+
79
+ const previousLastAliveCheckDate: Date | null = OneUptimeDate.fromString(
80
+ previousLastAliveCheck,
81
+ );
82
+
83
+ // if this date is within 30 seconds of current date, then we will not update the last alive.
84
+ if (previousLastAliveCheckDate) {
85
+ const diff: number = OneUptimeDate.getDifferenceInSeconds(
86
+ now,
87
+ previousLastAliveCheckDate,
88
+ );
89
+
90
+ if (diff < 30) {
91
+ return false;
92
+ }
93
+ }
94
+
95
+ await this.saveLastAliveInCache(aiAgentId, now);
96
+ } catch (err) {
97
+ // failed to hit the cache, so we will hit the database
98
+ logger.error("Error in getting last alive from cache");
99
+ logger.error(err);
100
+ }
101
+
102
+ return true;
103
+ }
104
+
105
+ public async updateLastAlive(aiAgentId: ObjectID): Promise<void> {
106
+ if (!aiAgentId) {
107
+ throw new BadDataException("aiAgentId is required");
108
+ }
109
+
110
+ const shouldSaveLastAlive: boolean =
111
+ await this.shouldSaveLastAlive(aiAgentId);
112
+
113
+ if (!shouldSaveLastAlive) {
114
+ return;
115
+ }
116
+
117
+ const now: Date = OneUptimeDate.getCurrentDate();
118
+
119
+ await this.updateOneById({
120
+ id: aiAgentId,
121
+ data: {
122
+ lastAlive: now,
123
+ },
124
+ props: {
125
+ isRoot: true,
126
+ },
127
+ });
128
+ }
129
+
130
+ @CaptureSpan()
131
+ protected override async onBeforeCreate(
132
+ createBy: CreateBy<Model>,
133
+ ): Promise<OnCreate<Model>> {
134
+ if (!createBy.data.key) {
135
+ createBy.data.key = ObjectID.generate().toString();
136
+ }
137
+
138
+ if (!createBy.data.aiAgentVersion) {
139
+ createBy.data.aiAgentVersion = new Version("1.0.0");
140
+ }
141
+
142
+ // When creating a new AI Agent, set it as default by default
143
+ if (createBy.data.isDefault === undefined) {
144
+ createBy.data.isDefault = true;
145
+ }
146
+
147
+ // If this agent is being set as default, unset other defaults in the same project
148
+ if (createBy.data.isDefault && createBy.data.projectId) {
149
+ await this.updateBy({
150
+ query: {
151
+ projectId: createBy.data.projectId,
152
+ isDefault: true,
153
+ },
154
+ data: {
155
+ isDefault: false,
156
+ },
157
+ props: {
158
+ isRoot: true,
159
+ },
160
+ limit: LIMIT_MAX,
161
+ skip: 0,
162
+ });
163
+ }
164
+
165
+ return { createBy: createBy, carryForward: [] };
166
+ }
167
+
168
+ @CaptureSpan()
169
+ public async getOwners(aiAgentId: ObjectID): Promise<Array<User>> {
170
+ if (!aiAgentId) {
171
+ throw new BadDataException("aiAgentId is required");
172
+ }
173
+
174
+ const ownerUsers: Array<AIAgentOwnerUser> =
175
+ await AIAgentOwnerUserService.findBy({
176
+ query: {
177
+ aiAgentId: aiAgentId,
178
+ },
179
+ select: {
180
+ _id: true,
181
+ user: {
182
+ _id: true,
183
+ email: true,
184
+ name: true,
185
+ timezone: true,
186
+ },
187
+ },
188
+ props: {
189
+ isRoot: true,
190
+ },
191
+ limit: LIMIT_PER_PROJECT,
192
+ skip: 0,
193
+ });
194
+
195
+ const ownerTeams: Array<AIAgentOwnerTeam> =
196
+ await AIAgentOwnerTeamService.findBy({
197
+ query: {
198
+ aiAgentId: aiAgentId,
199
+ },
200
+ select: {
201
+ _id: true,
202
+ teamId: true,
203
+ },
204
+ skip: 0,
205
+ limit: LIMIT_PER_PROJECT,
206
+ props: {
207
+ isRoot: true,
208
+ },
209
+ });
210
+
211
+ const users: Array<User> =
212
+ ownerUsers.map((ownerUser: AIAgentOwnerUser) => {
213
+ return ownerUser.user!;
214
+ }) || [];
215
+
216
+ if (ownerTeams.length > 0) {
217
+ const teamIds: Array<ObjectID> =
218
+ ownerTeams.map((ownerTeam: AIAgentOwnerTeam) => {
219
+ return ownerTeam.teamId!;
220
+ }) || [];
221
+
222
+ const teamUsers: Array<User> =
223
+ await TeamMemberService.getUsersInTeams(teamIds);
224
+
225
+ for (const teamUser of teamUsers) {
226
+ //check if the user is already added.
227
+ const isUserAlreadyAdded: User | undefined = users.find(
228
+ (user: User) => {
229
+ return user.id!.toString() === teamUser.id!.toString();
230
+ },
231
+ );
232
+
233
+ if (!isUserAlreadyAdded) {
234
+ users.push(teamUser);
235
+ }
236
+ }
237
+ }
238
+
239
+ return users;
240
+ }
241
+
242
+ @CaptureSpan()
243
+ protected override async onBeforeUpdate(
244
+ updateBy: UpdateBy<Model>,
245
+ ): Promise<OnUpdate<Model>> {
246
+ const carryForward: any = {
247
+ aiAgentsToNotifyOwners: [],
248
+ };
249
+
250
+ if (updateBy.data.connectionStatus && updateBy.query._id) {
251
+ const aiAgents: Array<Model> = await this.findBy({
252
+ query: updateBy.query,
253
+ props: {
254
+ isRoot: true,
255
+ },
256
+ select: {
257
+ _id: true,
258
+ connectionStatus: true,
259
+ },
260
+ skip: 0,
261
+ limit: LIMIT_MAX,
262
+ });
263
+
264
+ const aiAgentsToNotifyOwners: Array<Model> = aiAgents.filter(
265
+ (aiAgent: Model) => {
266
+ return (
267
+ aiAgent.connectionStatus &&
268
+ aiAgent.connectionStatus !== updateBy.data.connectionStatus
269
+ );
270
+ },
271
+ );
272
+
273
+ carryForward.aiAgentsToNotifyOwners = aiAgentsToNotifyOwners;
274
+ }
275
+
276
+ // If setting isDefault to true, we need to unset other defaults in the same project
277
+ if (updateBy.data.isDefault === true) {
278
+ // Get the items being updated to find their project IDs
279
+ const itemsToUpdate: Array<Model> = await this.findBy({
280
+ query: updateBy.query,
281
+ select: {
282
+ _id: true,
283
+ projectId: true,
284
+ },
285
+ props: {
286
+ isRoot: true,
287
+ },
288
+ limit: LIMIT_MAX,
289
+ skip: 0,
290
+ });
291
+
292
+ // Collect unique project IDs
293
+ const projectIds: Set<string> = new Set();
294
+ const itemIds: Set<string> = new Set();
295
+ for (const item of itemsToUpdate) {
296
+ if (item.projectId) {
297
+ projectIds.add(item.projectId.toString());
298
+ }
299
+ if (item._id) {
300
+ itemIds.add(item._id);
301
+ }
302
+ }
303
+
304
+ // For each project, unset the default on other agents
305
+ for (const projectIdStr of projectIds) {
306
+ const projectId: ObjectID = new ObjectID(projectIdStr);
307
+ await this.updateBy({
308
+ query: {
309
+ projectId: projectId,
310
+ isDefault: true,
311
+ _id: QueryHelper.notInOrNull(Array.from(itemIds)),
312
+ },
313
+ data: {
314
+ isDefault: false,
315
+ },
316
+ props: {
317
+ isRoot: true,
318
+ },
319
+ limit: LIMIT_MAX,
320
+ skip: 0,
321
+ });
322
+ }
323
+ }
324
+
325
+ return { updateBy: updateBy, carryForward };
326
+ }
327
+
328
+ @CaptureSpan()
329
+ protected override async onUpdateSuccess(
330
+ onUpdate: OnUpdate<Model>,
331
+ _updatedItemIds: Array<ObjectID>,
332
+ ): Promise<OnUpdate<Model>> {
333
+ if (
334
+ onUpdate.carryForward &&
335
+ onUpdate.carryForward.aiAgentsToNotifyOwners.length > 0
336
+ ) {
337
+ for (const aiAgent of onUpdate.carryForward.aiAgentsToNotifyOwners) {
338
+ await this.notifyOwnersOnStatusChange({
339
+ aiAgentId: aiAgent.id!,
340
+ });
341
+ }
342
+ }
343
+
344
+ return Promise.resolve(onUpdate);
345
+ }
346
+
347
+ @CaptureSpan()
348
+ public async notifyOwnersOnStatusChange(data: {
349
+ aiAgentId: ObjectID;
350
+ }): Promise<void> {
351
+ const aiAgent: Model | null = await this.findOneById({
352
+ id: data.aiAgentId,
353
+ props: {
354
+ isRoot: true,
355
+ },
356
+ select: {
357
+ _id: true,
358
+ lastAlive: true,
359
+ connectionStatus: true,
360
+ isGlobalAIAgent: true,
361
+ name: true,
362
+ description: true,
363
+ projectId: true,
364
+ project: {
365
+ name: true,
366
+ },
367
+ },
368
+ });
369
+
370
+ if (!aiAgent || !aiAgent.id) {
371
+ throw new BadDataException("AI Agent not found");
372
+ }
373
+
374
+ if (!aiAgent.projectId) {
375
+ return; // might be global AI agent. Do not notify.
376
+ }
377
+
378
+ if (aiAgent.isGlobalAIAgent && IsBillingEnabled) {
379
+ return; // do not notify for global AI agents.
380
+ }
381
+
382
+ // notify the AI agent owner
383
+ let owners: Array<User> = await this.getOwners(aiAgent.id!);
384
+
385
+ let doesResourceHasOwners: boolean = true;
386
+
387
+ if (owners.length === 0) {
388
+ doesResourceHasOwners = false;
389
+
390
+ // find project owners.
391
+ owners = await ProjectService.getOwners(aiAgent.projectId!);
392
+ }
393
+
394
+ if (owners.length === 0) {
395
+ return; // no owners to notify.
396
+ }
397
+
398
+ const connectionStatus: string =
399
+ aiAgent.connectionStatus === AIAgentConnectionStatus.Connected
400
+ ? "Connected"
401
+ : "Disconnected";
402
+
403
+ for (const user of owners) {
404
+ try {
405
+ const vars: Dictionary<string> = {
406
+ title: `${aiAgent.name} is ${connectionStatus}`,
407
+ aiAgentName: aiAgent.name || "AI Agent",
408
+ aiAgentDescription: aiAgent.description || "No description provided",
409
+ projectName: aiAgent.project?.name || "Project",
410
+ aiAgentStatus: connectionStatus || "Unknown",
411
+ lastAlive: OneUptimeDate.getDateAsFormattedHTMLInMultipleTimezones({
412
+ date: aiAgent.lastAlive || OneUptimeDate.getCurrentDate(),
413
+ timezones: user.timezone ? [user.timezone] : [],
414
+ }),
415
+ viewAIAgentsLink: (
416
+ await this.getLinkInDashboard(aiAgent.projectId!, aiAgent.id!)
417
+ ).toString(),
418
+ };
419
+
420
+ if (doesResourceHasOwners === true) {
421
+ vars["isOwner"] = "true";
422
+ }
423
+
424
+ const emailMessage: EmailEnvelope = {
425
+ templateType: EmailTemplateType.AIAgentConnectionStatusChange,
426
+ vars: vars,
427
+ subject: `[AI Agent ${connectionStatus}] ${aiAgent.name}`,
428
+ };
429
+
430
+ const sms: SMSMessage = {
431
+ message: `This is a message from OneUptime. AI Agent ${aiAgent.name} is ${connectionStatus}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard.`,
432
+ };
433
+
434
+ const callMessage: CallRequestMessage = {
435
+ data: [
436
+ {
437
+ sayMessage: `This is a message from OneUptime. AI Agent ${aiAgent.name} is ${connectionStatus}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard. Good bye.`,
438
+ },
439
+ ],
440
+ };
441
+
442
+ const pushMessageParams: {
443
+ aiAgentName: string;
444
+ projectName: string;
445
+ connectionStatus: string;
446
+ clickAction?: string;
447
+ } = {
448
+ aiAgentName: aiAgent.name!,
449
+ projectName: aiAgent.project?.name || "Project",
450
+ connectionStatus: connectionStatus,
451
+ };
452
+
453
+ if (vars["viewAIAgentsLink"]) {
454
+ pushMessageParams.clickAction = vars["viewAIAgentsLink"];
455
+ }
456
+
457
+ const pushMessage: PushNotificationMessage =
458
+ PushNotificationUtil.createAIAgentStatusChangedNotification(
459
+ pushMessageParams,
460
+ );
461
+
462
+ const eventType: NotificationSettingEventType =
463
+ NotificationSettingEventType.SEND_AI_AGENT_STATUS_CHANGED_OWNER_NOTIFICATION;
464
+
465
+ const whatsAppMessage: WhatsAppMessagePayload =
466
+ createWhatsAppMessageFromTemplate({
467
+ eventType,
468
+ templateVariables: {
469
+ ai_agent_name: aiAgent.name!,
470
+ ai_agent_status: connectionStatus,
471
+ ai_agent_link: vars["viewAIAgentsLink"] || "",
472
+ },
473
+ });
474
+
475
+ await UserNotificationSettingService.sendUserNotification({
476
+ userId: user.id!,
477
+ projectId: aiAgent.projectId!,
478
+ emailEnvelope: emailMessage,
479
+ smsMessage: sms,
480
+ callRequestMessage: callMessage,
481
+ pushNotificationMessage: pushMessage,
482
+ whatsAppMessage,
483
+ eventType,
484
+ });
485
+ } catch (e) {
486
+ logger.error(
487
+ "Error in sending AI agent status changed resource notification",
488
+ );
489
+ logger.error(e);
490
+ }
491
+ }
492
+ }
493
+
494
+ @CaptureSpan()
495
+ public async getLinkInDashboard(
496
+ projectId: ObjectID,
497
+ aiAgentId: ObjectID,
498
+ ): Promise<URL> {
499
+ const dashboardUrl: URL = await DatabaseConfig.getDashboardUrl();
500
+
501
+ return URL.fromString(dashboardUrl.toString()).addRoute(
502
+ `/${projectId.toString()}/settings/ai-agents/${aiAgentId.toString()}`,
503
+ );
504
+ }
505
+
506
+ @CaptureSpan()
507
+ public async getAIAgentForProject(
508
+ projectId: ObjectID,
509
+ ): Promise<Model | null> {
510
+ // First try to get the default AI agent for the project
511
+ let agent: Model | null = await this.findOneBy({
512
+ query: {
513
+ projectId: projectId,
514
+ isDefault: true,
515
+ },
516
+ select: {
517
+ _id: true,
518
+ name: true,
519
+ description: true,
520
+ key: true,
521
+ aiAgentVersion: true,
522
+ connectionStatus: true,
523
+ isGlobalAIAgent: true,
524
+ lastAlive: true,
525
+ },
526
+ props: {
527
+ isRoot: true,
528
+ },
529
+ });
530
+
531
+ if (agent) {
532
+ return agent;
533
+ }
534
+
535
+ // If no default agent, get any global AI agent
536
+ agent = await this.findOneBy({
537
+ query: {
538
+ projectId: QueryHelper.isNull(),
539
+ isGlobalAIAgent: true,
540
+ },
541
+ select: {
542
+ _id: true,
543
+ name: true,
544
+ description: true,
545
+ key: true,
546
+ aiAgentVersion: true,
547
+ connectionStatus: true,
548
+ isGlobalAIAgent: true,
549
+ lastAlive: true,
550
+ },
551
+ props: {
552
+ isRoot: true,
553
+ },
554
+ });
555
+
556
+ if (agent) {
557
+ return agent;
558
+ }
559
+
560
+ return null;
561
+ }
562
+ }
563
+
564
+ export default new Service();
@@ -0,0 +1,10 @@
1
+ import DatabaseService from "./DatabaseService";
2
+ import Model from "../../Models/DatabaseModels/AIAgentTaskLog";
3
+
4
+ export class Service extends DatabaseService<Model> {
5
+ public constructor() {
6
+ super(Model);
7
+ }
8
+ }
9
+
10
+ export default new Service();
@@ -0,0 +1,10 @@
1
+ import DatabaseService from "./DatabaseService";
2
+ import Model from "../../Models/DatabaseModels/AIAgentTaskPullRequest";
3
+
4
+ export class Service extends DatabaseService<Model> {
5
+ public constructor() {
6
+ super(Model);
7
+ }
8
+ }
9
+
10
+ export default new Service();