@oneuptime/common 11.4.1 → 11.5.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 (321) hide show
  1. package/Models/DatabaseModels/AIRun.ts +50 -0
  2. package/Models/DatabaseModels/AlertSeverity.ts +6 -0
  3. package/Models/DatabaseModels/IncidentSeverity.ts +6 -0
  4. package/Models/DatabaseModels/Index.ts +16 -0
  5. package/Models/DatabaseModels/IoTDeviceCredential.ts +471 -0
  6. package/Models/DatabaseModels/LlmLog.ts +56 -0
  7. package/Models/DatabaseModels/LlmProvider.ts +33 -0
  8. package/Models/DatabaseModels/NetworkDevice.ts +1385 -0
  9. package/Models/DatabaseModels/NetworkDeviceDiscoveryScan.ts +717 -0
  10. package/Models/DatabaseModels/NetworkDeviceLabelRule.ts +514 -0
  11. package/Models/DatabaseModels/NetworkDeviceOwnerRule.ts +596 -0
  12. package/Models/DatabaseModels/NetworkDeviceOwnerTeam.ts +487 -0
  13. package/Models/DatabaseModels/NetworkDeviceOwnerUser.ts +486 -0
  14. package/Models/DatabaseModels/NetworkInterface.ts +563 -0
  15. package/Models/DatabaseModels/Project.ts +145 -0
  16. package/Models/DatabaseModels/TelemetryEntityRelationship.ts +54 -0
  17. package/Server/API/AIInvestigationAPI.ts +131 -63
  18. package/Server/API/AlertAPI.ts +5 -0
  19. package/Server/API/IncidentAPI.ts +10 -0
  20. package/Server/API/IncidentEpisodeAPI.ts +5 -0
  21. package/Server/API/LlmProviderAPI.ts +4 -0
  22. package/Server/API/ScheduledMaintenanceAPI.ts +5 -0
  23. package/Server/Infrastructure/Postgres/SchemaMigrations/1783650000000-AddAdditionalParamsToLlmProvider.ts +19 -0
  24. package/Server/Infrastructure/Postgres/SchemaMigrations/1783695782697-AddCacheTokenColumnsToLlmLog.ts +25 -0
  25. package/Server/Infrastructure/Postgres/SchemaMigrations/1783701585317-AddAlertInvestigationGating.ts +31 -0
  26. package/Server/Infrastructure/Postgres/SchemaMigrations/1783702431535-AddAiDailyAutonomousTokenLimitToProject.ts +19 -0
  27. package/Server/Infrastructure/Postgres/SchemaMigrations/1783720000000-AddNetworkDeviceTables.ts +105 -0
  28. package/Server/Infrastructure/Postgres/SchemaMigrations/1783721121260-AddAttemptCountToAIRun.ts +15 -0
  29. package/Server/Infrastructure/Postgres/SchemaMigrations/1783730000000-AddNetworkDeviceOwnersAndRules.ts +192 -0
  30. package/Server/Infrastructure/Postgres/SchemaMigrations/1783740000000-AddNetworkDeviceDiscoveryScan.ts +37 -0
  31. package/Server/Infrastructure/Postgres/SchemaMigrations/1783750000000-AddLldpNeighborsToNetworkDevice.ts +19 -0
  32. package/Server/Infrastructure/Postgres/SchemaMigrations/1783760576655-AddInvestigationTuningToProject.ts +25 -0
  33. package/Server/Infrastructure/Postgres/SchemaMigrations/1783762505482-AddTelemetryEntityRelationshipMetrics.ts +31 -0
  34. package/Server/Infrastructure/Postgres/SchemaMigrations/1783780000000-AddIoTDeviceCredentialTable.ts +79 -0
  35. package/Server/Infrastructure/Postgres/SchemaMigrations/1783790000000-AddSnmpV3AuthColumnsToNetworkDevice.ts +49 -0
  36. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +24 -0
  37. package/Server/Services/AIRunService.ts +58 -0
  38. package/Server/Services/AIService.ts +101 -0
  39. package/Server/Services/IncidentService.ts +14 -41
  40. package/Server/Services/Index.ts +14 -0
  41. package/Server/Services/IoTDeviceCredentialService.ts +351 -0
  42. package/Server/Services/IoTDeviceService.ts +64 -21
  43. package/Server/Services/LlmLogService.ts +26 -0
  44. package/Server/Services/LlmProviderService.ts +3 -0
  45. package/Server/Services/MonitorService.ts +4 -1
  46. package/Server/Services/NetworkDeviceDiscoveryScanService.ts +10 -0
  47. package/Server/Services/NetworkDeviceLabelRuleEngineService.ts +204 -0
  48. package/Server/Services/NetworkDeviceLabelRuleService.ts +14 -0
  49. package/Server/Services/NetworkDeviceOwnerRuleEngineService.ts +222 -0
  50. package/Server/Services/NetworkDeviceOwnerRuleService.ts +14 -0
  51. package/Server/Services/NetworkDeviceOwnerTeamService.ts +10 -0
  52. package/Server/Services/NetworkDeviceOwnerUserService.ts +10 -0
  53. package/Server/Services/NetworkDeviceService.ts +50 -0
  54. package/Server/Services/NetworkInterfaceService.ts +10 -0
  55. package/Server/Services/TelemetryEntityRelationshipService.ts +23 -0
  56. package/Server/Services/TelemetryEntityService.ts +72 -2
  57. package/Server/Utils/AI/Sentinel/AlertInvestigationRunner.ts +244 -12
  58. package/Server/Utils/AI/Sentinel/IncidentInvestigationRunner.ts +92 -19
  59. package/Server/Utils/AI/Sentinel/InvestigationQueue.ts +493 -0
  60. package/Server/Utils/AI/Sentinel/SentinelInvestigationEngine.ts +88 -68
  61. package/Server/Utils/AI/Toolbox/Index.ts +2 -1
  62. package/Server/Utils/AI/Toolbox/MetricTools.ts +391 -0
  63. package/Server/Utils/LLM/LLMService.ts +21 -0
  64. package/Server/Utils/Monitor/Criteria/SnmpMonitorCriteria.ts +170 -2
  65. package/Server/Utils/Monitor/IoTDeviceAbsenceSeries.ts +101 -0
  66. package/Server/Utils/Monitor/MonitorAlert.ts +15 -3
  67. package/Server/Utils/Monitor/MonitorCriteriaEvaluator.ts +1 -1
  68. package/Server/Utils/Monitor/MonitorIncident.ts +19 -3
  69. package/Server/Utils/Monitor/MonitorMetricUtil.ts +87 -0
  70. package/Server/Utils/Monitor/MonitorResource.ts +77 -21
  71. package/Server/Utils/Monitor/MonitorTemplateUtil.ts +1 -1
  72. package/Server/Utils/Monitor/NetworkDeviceHydrationUtil.ts +201 -0
  73. package/Server/Utils/Monitor/NetworkInventoryUtil.ts +215 -0
  74. package/Server/Utils/Monitor/SnmpInterfaceRateUtil.ts +169 -0
  75. package/Tests/Server/Services/AIServiceDailyBudget.test.ts +173 -0
  76. package/Tests/Server/Services/IncidentInternalNoteAnnouncement.test.ts +97 -0
  77. package/Tests/Server/Services/IoTDeviceService.test.ts +54 -0
  78. package/Tests/Server/Utils/AI/BaselineAnomalyTool.test.ts +253 -0
  79. package/Tests/Server/Utils/AI/LLMServiceToolCalling.test.ts +44 -0
  80. package/Tests/Server/Utils/AI/SentinelAlertGating.test.ts +360 -0
  81. package/Tests/Server/Utils/AI/SentinelInvestigationQueue.test.ts +295 -0
  82. package/Tests/Server/Utils/Monitor/Criteria/SnmpMonitorCriteria.test.ts +59 -0
  83. package/Tests/Server/Utils/Monitor/IoTDeviceAbsenceSeries.test.ts +113 -0
  84. package/Tests/Server/Utils/Monitor/PerSeriesRecoveryResolution.test.ts +198 -0
  85. package/Tests/Types/Monitor/MonitorType.test.ts +1 -1
  86. package/Tests/Utils/Monitor/LatencyMatrixUtil.test.ts +111 -0
  87. package/Types/AI/AIRunStatus.ts +9 -0
  88. package/Types/Dashboard/DashboardComponents/ComponentArgument.ts +0 -1
  89. package/Types/Dashboard/DashboardComponents/DashboardLogChartComponent.ts +8 -3
  90. package/Types/LlmLogStatus.ts +1 -0
  91. package/Types/Monitor/CriteriaFilter.ts +5 -0
  92. package/Types/Monitor/IotAlertTemplates.ts +22 -3
  93. package/Types/Monitor/LatencyMatrix.ts +27 -0
  94. package/Types/Monitor/MonitorCriteriaInstance.ts +2 -2
  95. package/Types/Monitor/MonitorMetricType.ts +10 -0
  96. package/Types/Monitor/MonitorStep.ts +36 -11
  97. package/Types/Monitor/MonitorStepNetworkDeviceMonitor.ts +55 -0
  98. package/Types/Monitor/MonitorStepSnmpMonitor.ts +8 -0
  99. package/Types/Monitor/MonitorType.ts +14 -9
  100. package/Types/Monitor/SnmpMonitor/LldpNeighbor.ts +12 -0
  101. package/Types/Monitor/SnmpMonitor/NetworkDeviceAlertPack.ts +116 -0
  102. package/Types/Monitor/SnmpMonitor/NetworkTopology.ts +29 -0
  103. package/Types/Monitor/SnmpMonitor/SnmpInterface.ts +31 -0
  104. package/Types/Monitor/SnmpMonitor/SnmpMonitorResponse.ts +24 -0
  105. package/Types/Monitor/SnmpMonitor/SnmpTrap.ts +20 -0
  106. package/Types/Monitor/SnmpMonitor/SnmpVendorTemplate.ts +173 -0
  107. package/Types/Permission.ts +314 -0
  108. package/Types/Probe/ProbeMonitorResponse.ts +8 -0
  109. package/UI/Components/Icon/Icon.tsx +8 -6
  110. package/UI/Components/MonitorTemplateVariables/TemplateVariablesCatalog.ts +2 -2
  111. package/UI/Components/Tabs/Tabs.tsx +10 -1
  112. package/UI/Utils/Navigation.ts +10 -1
  113. package/Utils/Dashboard/Components/DashboardLogChartComponent.ts +16 -21
  114. package/Utils/Monitor/LatencyMatrixUtil.ts +162 -0
  115. package/Utils/Monitor/MonitorMetricType.ts +71 -1
  116. package/Utils/Monitor/NetworkTopologyUtil.ts +159 -0
  117. package/Utils/Telemetry/EntityRelationship.ts +11 -0
  118. package/build/dist/Models/DatabaseModels/AIRun.js +52 -0
  119. package/build/dist/Models/DatabaseModels/AIRun.js.map +1 -1
  120. package/build/dist/Models/DatabaseModels/AlertSeverity.js +6 -0
  121. package/build/dist/Models/DatabaseModels/AlertSeverity.js.map +1 -1
  122. package/build/dist/Models/DatabaseModels/IncidentSeverity.js +6 -0
  123. package/build/dist/Models/DatabaseModels/IncidentSeverity.js.map +1 -1
  124. package/build/dist/Models/DatabaseModels/Index.js +16 -0
  125. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  126. package/build/dist/Models/DatabaseModels/IoTDeviceCredential.js +493 -0
  127. package/build/dist/Models/DatabaseModels/IoTDeviceCredential.js.map +1 -0
  128. package/build/dist/Models/DatabaseModels/LlmLog.js +58 -0
  129. package/build/dist/Models/DatabaseModels/LlmLog.js.map +1 -1
  130. package/build/dist/Models/DatabaseModels/LlmProvider.js +33 -0
  131. package/build/dist/Models/DatabaseModels/LlmProvider.js.map +1 -1
  132. package/build/dist/Models/DatabaseModels/NetworkDevice.js +1426 -0
  133. package/build/dist/Models/DatabaseModels/NetworkDevice.js.map +1 -0
  134. package/build/dist/Models/DatabaseModels/NetworkDeviceDiscoveryScan.js +738 -0
  135. package/build/dist/Models/DatabaseModels/NetworkDeviceDiscoveryScan.js.map +1 -0
  136. package/build/dist/Models/DatabaseModels/NetworkDeviceLabelRule.js +522 -0
  137. package/build/dist/Models/DatabaseModels/NetworkDeviceLabelRule.js.map +1 -0
  138. package/build/dist/Models/DatabaseModels/NetworkDeviceOwnerRule.js +603 -0
  139. package/build/dist/Models/DatabaseModels/NetworkDeviceOwnerRule.js.map +1 -0
  140. package/build/dist/Models/DatabaseModels/NetworkDeviceOwnerTeam.js +503 -0
  141. package/build/dist/Models/DatabaseModels/NetworkDeviceOwnerTeam.js.map +1 -0
  142. package/build/dist/Models/DatabaseModels/NetworkDeviceOwnerUser.js +502 -0
  143. package/build/dist/Models/DatabaseModels/NetworkDeviceOwnerUser.js.map +1 -0
  144. package/build/dist/Models/DatabaseModels/NetworkInterface.js +589 -0
  145. package/build/dist/Models/DatabaseModels/NetworkInterface.js.map +1 -0
  146. package/build/dist/Models/DatabaseModels/Project.js +147 -0
  147. package/build/dist/Models/DatabaseModels/Project.js.map +1 -1
  148. package/build/dist/Models/DatabaseModels/TelemetryEntityRelationship.js +57 -0
  149. package/build/dist/Models/DatabaseModels/TelemetryEntityRelationship.js.map +1 -1
  150. package/build/dist/Server/API/AIInvestigationAPI.js +95 -55
  151. package/build/dist/Server/API/AIInvestigationAPI.js.map +1 -1
  152. package/build/dist/Server/API/AlertAPI.js +5 -0
  153. package/build/dist/Server/API/AlertAPI.js.map +1 -1
  154. package/build/dist/Server/API/IncidentAPI.js +10 -0
  155. package/build/dist/Server/API/IncidentAPI.js.map +1 -1
  156. package/build/dist/Server/API/IncidentEpisodeAPI.js +5 -0
  157. package/build/dist/Server/API/IncidentEpisodeAPI.js.map +1 -1
  158. package/build/dist/Server/API/LlmProviderAPI.js +5 -7
  159. package/build/dist/Server/API/LlmProviderAPI.js.map +1 -1
  160. package/build/dist/Server/API/ScheduledMaintenanceAPI.js +5 -0
  161. package/build/dist/Server/API/ScheduledMaintenanceAPI.js.map +1 -1
  162. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783650000000-AddAdditionalParamsToLlmProvider.js +12 -0
  163. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783650000000-AddAdditionalParamsToLlmProvider.js.map +1 -0
  164. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783695782697-AddCacheTokenColumnsToLlmLog.js +14 -0
  165. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783695782697-AddCacheTokenColumnsToLlmLog.js.map +1 -0
  166. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783701585317-AddAlertInvestigationGating.js +18 -0
  167. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783701585317-AddAlertInvestigationGating.js.map +1 -0
  168. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783702431535-AddAiDailyAutonomousTokenLimitToProject.js +12 -0
  169. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783702431535-AddAiDailyAutonomousTokenLimitToProject.js.map +1 -0
  170. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783720000000-AddNetworkDeviceTables.js +51 -0
  171. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783720000000-AddNetworkDeviceTables.js.map +1 -0
  172. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783721121260-AddAttemptCountToAIRun.js +12 -0
  173. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783721121260-AddAttemptCountToAIRun.js.map +1 -0
  174. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783730000000-AddNetworkDeviceOwnersAndRules.js +101 -0
  175. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783730000000-AddNetworkDeviceOwnersAndRules.js.map +1 -0
  176. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783740000000-AddNetworkDeviceDiscoveryScan.js +18 -0
  177. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783740000000-AddNetworkDeviceDiscoveryScan.js.map +1 -0
  178. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783750000000-AddLldpNeighborsToNetworkDevice.js +12 -0
  179. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783750000000-AddLldpNeighborsToNetworkDevice.js.map +1 -0
  180. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783760576655-AddInvestigationTuningToProject.js +14 -0
  181. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783760576655-AddInvestigationTuningToProject.js.map +1 -0
  182. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783762505482-AddTelemetryEntityRelationshipMetrics.js +16 -0
  183. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783762505482-AddTelemetryEntityRelationshipMetrics.js.map +1 -0
  184. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783780000000-AddIoTDeviceCredentialTable.js +38 -0
  185. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783780000000-AddIoTDeviceCredentialTable.js.map +1 -0
  186. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783790000000-AddSnmpV3AuthColumnsToNetworkDevice.js +22 -0
  187. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783790000000-AddSnmpV3AuthColumnsToNetworkDevice.js.map +1 -0
  188. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +24 -0
  189. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  190. package/build/dist/Server/Services/AIRunService.js +33 -0
  191. package/build/dist/Server/Services/AIRunService.js.map +1 -1
  192. package/build/dist/Server/Services/AIService.js +82 -9
  193. package/build/dist/Server/Services/AIService.js.map +1 -1
  194. package/build/dist/Server/Services/IncidentService.js +14 -25
  195. package/build/dist/Server/Services/IncidentService.js.map +1 -1
  196. package/build/dist/Server/Services/Index.js +14 -0
  197. package/build/dist/Server/Services/Index.js.map +1 -1
  198. package/build/dist/Server/Services/IoTDeviceCredentialService.js +321 -0
  199. package/build/dist/Server/Services/IoTDeviceCredentialService.js.map +1 -0
  200. package/build/dist/Server/Services/IoTDeviceService.js +49 -15
  201. package/build/dist/Server/Services/IoTDeviceService.js.map +1 -1
  202. package/build/dist/Server/Services/LlmLogService.js +29 -0
  203. package/build/dist/Server/Services/LlmLogService.js.map +1 -1
  204. package/build/dist/Server/Services/LlmProviderService.js +3 -0
  205. package/build/dist/Server/Services/LlmProviderService.js.map +1 -1
  206. package/build/dist/Server/Services/MonitorService.js +2 -1
  207. package/build/dist/Server/Services/MonitorService.js.map +1 -1
  208. package/build/dist/Server/Services/NetworkDeviceDiscoveryScanService.js +9 -0
  209. package/build/dist/Server/Services/NetworkDeviceDiscoveryScanService.js.map +1 -0
  210. package/build/dist/Server/Services/NetworkDeviceLabelRuleEngineService.js +166 -0
  211. package/build/dist/Server/Services/NetworkDeviceLabelRuleEngineService.js.map +1 -0
  212. package/build/dist/Server/Services/NetworkDeviceLabelRuleService.js +13 -0
  213. package/build/dist/Server/Services/NetworkDeviceLabelRuleService.js.map +1 -0
  214. package/build/dist/Server/Services/NetworkDeviceOwnerRuleEngineService.js +186 -0
  215. package/build/dist/Server/Services/NetworkDeviceOwnerRuleEngineService.js.map +1 -0
  216. package/build/dist/Server/Services/NetworkDeviceOwnerRuleService.js +13 -0
  217. package/build/dist/Server/Services/NetworkDeviceOwnerRuleService.js.map +1 -0
  218. package/build/dist/Server/Services/NetworkDeviceOwnerTeamService.js +9 -0
  219. package/build/dist/Server/Services/NetworkDeviceOwnerTeamService.js.map +1 -0
  220. package/build/dist/Server/Services/NetworkDeviceOwnerUserService.js +9 -0
  221. package/build/dist/Server/Services/NetworkDeviceOwnerUserService.js.map +1 -0
  222. package/build/dist/Server/Services/NetworkDeviceService.js +52 -0
  223. package/build/dist/Server/Services/NetworkDeviceService.js.map +1 -0
  224. package/build/dist/Server/Services/NetworkInterfaceService.js +9 -0
  225. package/build/dist/Server/Services/NetworkInterfaceService.js.map +1 -0
  226. package/build/dist/Server/Services/TelemetryEntityRelationshipService.js +22 -0
  227. package/build/dist/Server/Services/TelemetryEntityRelationshipService.js.map +1 -1
  228. package/build/dist/Server/Services/TelemetryEntityService.js +64 -2
  229. package/build/dist/Server/Services/TelemetryEntityService.js.map +1 -1
  230. package/build/dist/Server/Utils/AI/Sentinel/AlertInvestigationRunner.js +189 -9
  231. package/build/dist/Server/Utils/AI/Sentinel/AlertInvestigationRunner.js.map +1 -1
  232. package/build/dist/Server/Utils/AI/Sentinel/IncidentInvestigationRunner.js +84 -17
  233. package/build/dist/Server/Utils/AI/Sentinel/IncidentInvestigationRunner.js.map +1 -1
  234. package/build/dist/Server/Utils/AI/Sentinel/InvestigationQueue.js +428 -0
  235. package/build/dist/Server/Utils/AI/Sentinel/InvestigationQueue.js.map +1 -0
  236. package/build/dist/Server/Utils/AI/Sentinel/SentinelInvestigationEngine.js +63 -47
  237. package/build/dist/Server/Utils/AI/Sentinel/SentinelInvestigationEngine.js.map +1 -1
  238. package/build/dist/Server/Utils/AI/Toolbox/Index.js +2 -1
  239. package/build/dist/Server/Utils/AI/Toolbox/Index.js.map +1 -1
  240. package/build/dist/Server/Utils/AI/Toolbox/MetricTools.js +300 -0
  241. package/build/dist/Server/Utils/AI/Toolbox/MetricTools.js.map +1 -1
  242. package/build/dist/Server/Utils/LLM/LLMService.js +16 -0
  243. package/build/dist/Server/Utils/LLM/LLMService.js.map +1 -1
  244. package/build/dist/Server/Utils/Monitor/Criteria/SnmpMonitorCriteria.js +130 -2
  245. package/build/dist/Server/Utils/Monitor/Criteria/SnmpMonitorCriteria.js.map +1 -1
  246. package/build/dist/Server/Utils/Monitor/IoTDeviceAbsenceSeries.js +81 -0
  247. package/build/dist/Server/Utils/Monitor/IoTDeviceAbsenceSeries.js.map +1 -0
  248. package/build/dist/Server/Utils/Monitor/MonitorAlert.js +18 -7
  249. package/build/dist/Server/Utils/Monitor/MonitorAlert.js.map +1 -1
  250. package/build/dist/Server/Utils/Monitor/MonitorCriteriaEvaluator.js +1 -1
  251. package/build/dist/Server/Utils/Monitor/MonitorCriteriaEvaluator.js.map +1 -1
  252. package/build/dist/Server/Utils/Monitor/MonitorIncident.js +25 -10
  253. package/build/dist/Server/Utils/Monitor/MonitorIncident.js.map +1 -1
  254. package/build/dist/Server/Utils/Monitor/MonitorMetricUtil.js +69 -3
  255. package/build/dist/Server/Utils/Monitor/MonitorMetricUtil.js.map +1 -1
  256. package/build/dist/Server/Utils/Monitor/MonitorResource.js +76 -30
  257. package/build/dist/Server/Utils/Monitor/MonitorResource.js.map +1 -1
  258. package/build/dist/Server/Utils/Monitor/MonitorTemplateUtil.js +1 -1
  259. package/build/dist/Server/Utils/Monitor/MonitorTemplateUtil.js.map +1 -1
  260. package/build/dist/Server/Utils/Monitor/NetworkDeviceHydrationUtil.js +147 -0
  261. package/build/dist/Server/Utils/Monitor/NetworkDeviceHydrationUtil.js.map +1 -0
  262. package/build/dist/Server/Utils/Monitor/NetworkInventoryUtil.js +167 -0
  263. package/build/dist/Server/Utils/Monitor/NetworkInventoryUtil.js.map +1 -0
  264. package/build/dist/Server/Utils/Monitor/SnmpInterfaceRateUtil.js +93 -0
  265. package/build/dist/Server/Utils/Monitor/SnmpInterfaceRateUtil.js.map +1 -0
  266. package/build/dist/Types/AI/AIRunStatus.js +9 -0
  267. package/build/dist/Types/AI/AIRunStatus.js.map +1 -1
  268. package/build/dist/Types/Dashboard/DashboardComponents/ComponentArgument.js +0 -1
  269. package/build/dist/Types/Dashboard/DashboardComponents/ComponentArgument.js.map +1 -1
  270. package/build/dist/Types/LlmLogStatus.js +1 -0
  271. package/build/dist/Types/LlmLogStatus.js.map +1 -1
  272. package/build/dist/Types/Monitor/CriteriaFilter.js +5 -0
  273. package/build/dist/Types/Monitor/CriteriaFilter.js.map +1 -1
  274. package/build/dist/Types/Monitor/IotAlertTemplates.js +7 -7
  275. package/build/dist/Types/Monitor/IotAlertTemplates.js.map +1 -1
  276. package/build/dist/Types/Monitor/LatencyMatrix.js +2 -0
  277. package/build/dist/Types/Monitor/LatencyMatrix.js.map +1 -0
  278. package/build/dist/Types/Monitor/MonitorCriteriaInstance.js +2 -2
  279. package/build/dist/Types/Monitor/MonitorCriteriaInstance.js.map +1 -1
  280. package/build/dist/Types/Monitor/MonitorMetricType.js +9 -0
  281. package/build/dist/Types/Monitor/MonitorMetricType.js.map +1 -1
  282. package/build/dist/Types/Monitor/MonitorStep.js +22 -9
  283. package/build/dist/Types/Monitor/MonitorStep.js.map +1 -1
  284. package/build/dist/Types/Monitor/MonitorStepNetworkDeviceMonitor.js +36 -0
  285. package/build/dist/Types/Monitor/MonitorStepNetworkDeviceMonitor.js.map +1 -0
  286. package/build/dist/Types/Monitor/MonitorStepSnmpMonitor.js +3 -0
  287. package/build/dist/Types/Monitor/MonitorStepSnmpMonitor.js.map +1 -1
  288. package/build/dist/Types/Monitor/MonitorType.js +14 -9
  289. package/build/dist/Types/Monitor/MonitorType.js.map +1 -1
  290. package/build/dist/Types/Monitor/SnmpMonitor/LldpNeighbor.js +2 -0
  291. package/build/dist/Types/Monitor/SnmpMonitor/LldpNeighbor.js.map +1 -0
  292. package/build/dist/Types/Monitor/SnmpMonitor/NetworkDeviceAlertPack.js +89 -0
  293. package/build/dist/Types/Monitor/SnmpMonitor/NetworkDeviceAlertPack.js.map +1 -0
  294. package/build/dist/Types/Monitor/SnmpMonitor/NetworkTopology.js +2 -0
  295. package/build/dist/Types/Monitor/SnmpMonitor/NetworkTopology.js.map +1 -0
  296. package/build/dist/Types/Monitor/SnmpMonitor/SnmpInterface.js +2 -0
  297. package/build/dist/Types/Monitor/SnmpMonitor/SnmpInterface.js.map +1 -0
  298. package/build/dist/Types/Monitor/SnmpMonitor/SnmpTrap.js +2 -0
  299. package/build/dist/Types/Monitor/SnmpMonitor/SnmpTrap.js.map +1 -0
  300. package/build/dist/Types/Monitor/SnmpMonitor/SnmpVendorTemplate.js +137 -0
  301. package/build/dist/Types/Monitor/SnmpMonitor/SnmpVendorTemplate.js.map +1 -0
  302. package/build/dist/Types/Permission.js +280 -0
  303. package/build/dist/Types/Permission.js.map +1 -1
  304. package/build/dist/UI/Components/Icon/Icon.js +8 -6
  305. package/build/dist/UI/Components/Icon/Icon.js.map +1 -1
  306. package/build/dist/UI/Components/MonitorTemplateVariables/TemplateVariablesCatalog.js +2 -2
  307. package/build/dist/UI/Components/MonitorTemplateVariables/TemplateVariablesCatalog.js.map +1 -1
  308. package/build/dist/UI/Components/Tabs/Tabs.js +3 -1
  309. package/build/dist/UI/Components/Tabs/Tabs.js.map +1 -1
  310. package/build/dist/UI/Utils/Navigation.js +11 -1
  311. package/build/dist/UI/Utils/Navigation.js.map +1 -1
  312. package/build/dist/Utils/Dashboard/Components/DashboardLogChartComponent.js +17 -20
  313. package/build/dist/Utils/Dashboard/Components/DashboardLogChartComponent.js.map +1 -1
  314. package/build/dist/Utils/Monitor/LatencyMatrixUtil.js +89 -0
  315. package/build/dist/Utils/Monitor/LatencyMatrixUtil.js.map +1 -0
  316. package/build/dist/Utils/Monitor/MonitorMetricType.js +68 -1
  317. package/build/dist/Utils/Monitor/MonitorMetricType.js.map +1 -1
  318. package/build/dist/Utils/Monitor/NetworkTopologyUtil.js +112 -0
  319. package/build/dist/Utils/Monitor/NetworkTopologyUtil.js.map +1 -0
  320. package/build/dist/Utils/Telemetry/EntityRelationship.js.map +1 -1
  321. package/package.json +1 -1
@@ -0,0 +1,493 @@
1
+ import ObjectID from "../../../../Types/ObjectID";
2
+ import OneUptimeDate from "../../../../Types/Date";
3
+ import AIRunType from "../../../../Types/AI/AIRunType";
4
+ import AIRunStatus from "../../../../Types/AI/AIRunStatus";
5
+ import AIRun from "../../../../Models/DatabaseModels/AIRun";
6
+ import Project from "../../../../Models/DatabaseModels/Project";
7
+ import AIRunService from "../../../Services/AIRunService";
8
+ import ProjectService from "../../../Services/ProjectService";
9
+ import AIService, { AutonomousBudgetStatus } from "../../../Services/AIService";
10
+ import SortOrder from "../../../../Types/BaseDatabase/SortOrder";
11
+ import QueryHelper from "../../../Types/Database/QueryHelper";
12
+ import logger from "../../Logger";
13
+ import CaptureSpan from "../../Telemetry/CaptureSpan";
14
+
15
+ /*
16
+ * Sentinel — the durable investigation queue (Phase 2's first item; Q1
17
+ * decided as the DB-claim pattern on AIRun rows, no new infrastructure).
18
+ *
19
+ * The problem it replaces: investigations ran as detached in-process
20
+ * promises, so a pod restart orphaned them silently (Deviations log D2).
21
+ *
22
+ * The shape:
23
+ * 1. enqueue() records the durable intent as an AIRun in status Queued
24
+ * BEFORE any expensive work, then immediately tries to process it
25
+ * in-process — same latency as before when the pod stays alive.
26
+ * 2. Claims go through AIRunService.attemptStatusTransition — one
27
+ * conditional UPDATE guarded on BOTH status=Queued and the expected
28
+ * attemptCount — so the enqueueing pod and the poller can race and
29
+ * exactly one wins, and a stale queue snapshot can never claim (or
30
+ * re-number) a run that moved on. attemptCount can therefore never
31
+ * exceed MAX_INVESTIGATION_ATTEMPTS.
32
+ * 3. A Workers poller claims whatever the inline path left behind
33
+ * (pod died, cap was full, budget was exhausted) and expires runs
34
+ * that sat queued past their usefulness window. The poller claims
35
+ * sequentially (so the concurrency cap sees each claim) but executes
36
+ * detached, keeping the every-minute tick fast.
37
+ * 4. Failed attempts requeue (transient errors and stale heartbeats)
38
+ * until MAX_ATTEMPTS, then finalize as Error/Stale — G9's retry
39
+ * policy. Permanent errors (bad configuration) never retry.
40
+ *
41
+ * Mid-run message-level checkpointing is deliberately NOT here: a retried
42
+ * investigation re-runs from the top, which is safe because investigations
43
+ * are read-only until the single postAnalysis at the end.
44
+ */
45
+
46
+ // Initial attempt + one retry.
47
+ export const MAX_INVESTIGATION_ATTEMPTS: number = 2;
48
+
49
+ /*
50
+ * G4 cost guardrail: at most this many investigations may be Running per
51
+ * project at once (per-project override in
52
+ * Project.aiMaxConcurrentInvestigations). Enforced at CLAIM time, so a storm
53
+ * queues (bounded by dedupe + severity gates + this TTL) and drains at cap
54
+ * rate instead of being dropped.
55
+ */
56
+ export const DEFAULT_MAX_CONCURRENT_INVESTIGATIONS: number = 3;
57
+ /*
58
+ * Clamp bounds for the per-project override. Pausing has its own switches
59
+ * (the opt-in toggles, daily limit 0), so the floor is 1, not 0.
60
+ */
61
+ const MIN_CONCURRENT_INVESTIGATIONS: number = 1;
62
+ const MAX_CONCURRENT_INVESTIGATIONS: number = 25;
63
+
64
+ /*
65
+ * A first-pass RCA is only useful while the incident is fresh. Queued runs
66
+ * older than this are expired rather than run late — this also caps queue
67
+ * growth when the daily budget blocks claiming for hours.
68
+ */
69
+ export const QUEUE_TTL_MINUTES: number = 30;
70
+
71
+ // How many queued runs one poller tick will try to claim.
72
+ const POLLER_BATCH_SIZE: number = 10;
73
+
74
+ export interface QueuedRunRef {
75
+ id: ObjectID;
76
+ projectId: ObjectID;
77
+ attemptCount: number;
78
+ triggeredByIncidentId?: ObjectID | undefined;
79
+ triggeredByAlertId?: ObjectID | undefined;
80
+ }
81
+
82
+ export default class SentinelInvestigationQueue {
83
+ /*
84
+ * Record the durable intent to investigate, then try to process it
85
+ * immediately (detached — the poller is the safety net if this pod dies).
86
+ * Callers have already passed the subject-specific gates (opt-in,
87
+ * severity floor, dedupe window).
88
+ */
89
+ @CaptureSpan()
90
+ public static async enqueue(data: {
91
+ projectId: ObjectID;
92
+ subjectIncidentId?: ObjectID | undefined;
93
+ subjectAlertId?: ObjectID | undefined;
94
+ subjectMonitorId?: ObjectID | undefined;
95
+ }): Promise<void> {
96
+ const { projectId } = data;
97
+
98
+ /*
99
+ * Budget quiet-skip at enqueue: when the daily budget is already
100
+ * exhausted there is no point recording intent that the TTL would
101
+ * expire anyway. Fails cheap (skip) like all the cost gates.
102
+ */
103
+ try {
104
+ const budget: AutonomousBudgetStatus =
105
+ await AIService.getAutonomousDailyBudgetStatus(projectId);
106
+
107
+ if (budget.exhausted) {
108
+ logger.debug(
109
+ `Sentinel: not enqueueing investigation for project ${projectId.toString()} — daily autonomous token budget exhausted (${budget.usedTokensToday} of ${budget.limitInTokens} tokens used today).`,
110
+ );
111
+ return;
112
+ }
113
+ } catch (error) {
114
+ logger.error(
115
+ `Sentinel: budget check failed, not enqueueing investigation: ${error}`,
116
+ );
117
+ return;
118
+ }
119
+
120
+ const run: AIRun = new AIRun();
121
+ run.projectId = projectId;
122
+ run.runType = AIRunType.Investigation;
123
+ run.status = AIRunStatus.Queued;
124
+
125
+ if (data.subjectIncidentId) {
126
+ run.triggeredByIncidentId = data.subjectIncidentId;
127
+ }
128
+ if (data.subjectAlertId) {
129
+ run.triggeredByAlertId = data.subjectAlertId;
130
+ }
131
+ if (data.subjectMonitorId) {
132
+ run.monitorId = data.subjectMonitorId;
133
+ }
134
+
135
+ let createdRun: AIRun;
136
+ try {
137
+ createdRun = await AIRunService.create({
138
+ data: run,
139
+ props: { isRoot: true },
140
+ });
141
+ } catch (error) {
142
+ logger.error(`Sentinel: failed to enqueue investigation run: ${error}`);
143
+ return;
144
+ }
145
+
146
+ // Inline kick — preserves the 1-3 minute RCA latency on the happy path.
147
+ this.processRun({
148
+ id: createdRun.id!,
149
+ projectId,
150
+ attemptCount: 0,
151
+ triggeredByIncidentId: data.subjectIncidentId,
152
+ triggeredByAlertId: data.subjectAlertId,
153
+ }).catch((error: Error) => {
154
+ logger.error(
155
+ `Sentinel: inline processing of queued run ${createdRun.id?.toString()} failed: ${error}`,
156
+ );
157
+ });
158
+ }
159
+
160
+ /*
161
+ * Claim a queued run and execute it to completion. Safe to call from
162
+ * multiple places concurrently — the claim is one conditional UPDATE, so
163
+ * exactly one caller wins. Leaves the run Queued (for the poller / TTL)
164
+ * when the concurrency cap is full or the budget is exhausted.
165
+ */
166
+ @CaptureSpan()
167
+ public static async processRun(run: QueuedRunRef): Promise<void> {
168
+ try {
169
+ if (!(await this.passesClaimGates(run))) {
170
+ return;
171
+ }
172
+
173
+ const attempt: number | null = await this.claim(run);
174
+
175
+ if (attempt === null) {
176
+ return;
177
+ }
178
+
179
+ await this.dispatch(run, attempt);
180
+ } catch (error) {
181
+ logger.error(
182
+ `Sentinel: failed to process queued run ${run.id.toString()}: ${error}`,
183
+ );
184
+ }
185
+ }
186
+
187
+ /*
188
+ * One poller tick: expire runs that queued past their usefulness window,
189
+ * then claim a batch of the rest. Claims happen sequentially — each claim
190
+ * sets Running immediately, so the next iteration's concurrency-cap count
191
+ * sees it — but execution is detached so the tick finishes in seconds
192
+ * instead of holding the job open for the length of the investigations.
193
+ * Called every minute from Workers; also the recovery path for runs
194
+ * orphaned by pod restarts.
195
+ */
196
+ @CaptureSpan()
197
+ public static async processQueuedRuns(): Promise<void> {
198
+ const expiryThreshold: Date =
199
+ OneUptimeDate.getSomeMinutesAgo(QUEUE_TTL_MINUTES);
200
+
201
+ const expiredRuns: Array<AIRun> = await AIRunService.findBy({
202
+ query: {
203
+ runType: AIRunType.Investigation,
204
+ status: AIRunStatus.Queued,
205
+ createdAt: QueryHelper.lessThan(expiryThreshold),
206
+ },
207
+ select: { _id: true },
208
+ limit: 100,
209
+ skip: 0,
210
+ props: { isRoot: true },
211
+ });
212
+
213
+ for (const expired of expiredRuns) {
214
+ await AIRunService.attemptStatusTransition({
215
+ aiRunId: expired.id!,
216
+ fromStatus: AIRunStatus.Queued,
217
+ set: {
218
+ status: AIRunStatus.Cancelled,
219
+ completedAt: OneUptimeDate.getCurrentDate(),
220
+ errorMessage: `Expired in the investigation queue after ${QUEUE_TTL_MINUTES} minutes — a first-pass analysis this late would no longer be useful. The project may have been at its concurrency cap or daily token budget.`,
221
+ },
222
+ });
223
+ }
224
+
225
+ const queuedRuns: Array<AIRun> = await AIRunService.findBy({
226
+ query: {
227
+ runType: AIRunType.Investigation,
228
+ status: AIRunStatus.Queued,
229
+ },
230
+ select: {
231
+ _id: true,
232
+ projectId: true,
233
+ attemptCount: true,
234
+ triggeredByIncidentId: true,
235
+ triggeredByAlertId: true,
236
+ },
237
+ sort: { createdAt: SortOrder.Ascending },
238
+ limit: POLLER_BATCH_SIZE,
239
+ skip: 0,
240
+ props: { isRoot: true },
241
+ });
242
+
243
+ for (const queued of queuedRuns) {
244
+ const ref: QueuedRunRef = {
245
+ id: queued.id!,
246
+ projectId: queued.projectId!,
247
+ attemptCount: queued.attemptCount || 0,
248
+ triggeredByIncidentId: queued.triggeredByIncidentId,
249
+ triggeredByAlertId: queued.triggeredByAlertId,
250
+ };
251
+
252
+ try {
253
+ if (!(await this.passesClaimGates(ref))) {
254
+ continue;
255
+ }
256
+
257
+ const attempt: number | null = await this.claim(ref);
258
+
259
+ if (attempt === null) {
260
+ continue;
261
+ }
262
+
263
+ /*
264
+ * Execute detached — the run is claimed (Running + heartbeat), so
265
+ * the sweeper owns recovery if this pod dies mid-flight.
266
+ */
267
+ this.dispatch(ref, attempt).catch((error: Error) => {
268
+ logger.error(
269
+ `Sentinel: detached execution of run ${ref.id.toString()} failed: ${error}`,
270
+ );
271
+ });
272
+ } catch (error) {
273
+ logger.error(
274
+ `Sentinel: poller failed on queued run ${ref.id.toString()}: ${error}`,
275
+ );
276
+ }
277
+ }
278
+ }
279
+
280
+ /*
281
+ * Finalize a failed attempt: requeue transient failures while attempts
282
+ * remain, otherwise mark the run Error. The transition guards on Running
283
+ * so a run that already completed (e.g. only postAnalysis failed) is
284
+ * never clobbered or re-run.
285
+ */
286
+ @CaptureSpan()
287
+ public static async failOrRequeue(data: {
288
+ aiRunId: ObjectID;
289
+ attemptCount: number;
290
+ errorMessage: string;
291
+ isPermanent: boolean;
292
+ }): Promise<void> {
293
+ const truncatedMessage: string = data.errorMessage.substring(0, 400);
294
+
295
+ if (!data.isPermanent && data.attemptCount < MAX_INVESTIGATION_ATTEMPTS) {
296
+ const requeued: number = await AIRunService.attemptStatusTransition({
297
+ aiRunId: data.aiRunId,
298
+ fromStatus: AIRunStatus.Running,
299
+ set: {
300
+ status: AIRunStatus.Queued,
301
+ errorMessage: `Attempt ${data.attemptCount} failed and the run was requeued: ${truncatedMessage}`,
302
+ },
303
+ });
304
+
305
+ if (requeued > 0) {
306
+ logger.debug(
307
+ `Sentinel: requeued run ${data.aiRunId.toString()} after attempt ${data.attemptCount} failed.`,
308
+ );
309
+ }
310
+ return;
311
+ }
312
+
313
+ await AIRunService.attemptStatusTransition({
314
+ aiRunId: data.aiRunId,
315
+ fromStatus: AIRunStatus.Running,
316
+ set: {
317
+ status: AIRunStatus.Error,
318
+ completedAt: OneUptimeDate.getCurrentDate(),
319
+ errorMessage: truncatedMessage,
320
+ },
321
+ });
322
+ }
323
+
324
+ /*
325
+ * Called by the stale-run sweeper for an Investigation run whose
326
+ * heartbeat went silent (the pod running it died). Requeues while
327
+ * attempts remain; otherwise marks it Stale as before.
328
+ */
329
+ @CaptureSpan()
330
+ public static async requeueOrMarkStale(run: {
331
+ id: ObjectID;
332
+ attemptCount: number;
333
+ }): Promise<"requeued" | "stale"> {
334
+ if ((run.attemptCount || 0) < MAX_INVESTIGATION_ATTEMPTS) {
335
+ const requeued: number = await AIRunService.attemptStatusTransition({
336
+ aiRunId: run.id,
337
+ fromStatus: AIRunStatus.Running,
338
+ set: {
339
+ status: AIRunStatus.Queued,
340
+ errorMessage: `Attempt ${run.attemptCount} stopped reporting progress (the server processing it may have restarted) and the run was requeued.`,
341
+ },
342
+ });
343
+
344
+ if (requeued > 0) {
345
+ return "requeued";
346
+ }
347
+ }
348
+
349
+ await AIRunService.attemptStatusTransition({
350
+ aiRunId: run.id,
351
+ fromStatus: AIRunStatus.Running,
352
+ set: {
353
+ status: AIRunStatus.Stale,
354
+ completedAt: OneUptimeDate.getCurrentDate(),
355
+ errorMessage:
356
+ "The run stopped reporting progress and was marked as stale after exhausting its retry attempts. The server processing it may have restarted.",
357
+ },
358
+ });
359
+
360
+ return "stale";
361
+ }
362
+
363
+ /*
364
+ * The claim-time cost gates: concurrency cap and daily budget. A run
365
+ * failing these stays Queued — the poller retries and the TTL expires
366
+ * what never fits. Fails cheap (skip) on gate errors.
367
+ */
368
+ private static async passesClaimGates(run: QueuedRunRef): Promise<boolean> {
369
+ // Per-project cap override, defaulting to 3 and clamped to [1, 25].
370
+ const project: Project | null = await ProjectService.findOneById({
371
+ id: run.projectId,
372
+ select: { aiMaxConcurrentInvestigations: true },
373
+ props: { isRoot: true },
374
+ });
375
+
376
+ const concurrencyCap: number = Math.min(
377
+ MAX_CONCURRENT_INVESTIGATIONS,
378
+ Math.max(
379
+ MIN_CONCURRENT_INVESTIGATIONS,
380
+ project?.aiMaxConcurrentInvestigations ??
381
+ DEFAULT_MAX_CONCURRENT_INVESTIGATIONS,
382
+ ),
383
+ );
384
+
385
+ const runningCount: number = (
386
+ await AIRunService.countBy({
387
+ query: {
388
+ projectId: run.projectId,
389
+ runType: AIRunType.Investigation,
390
+ status: AIRunStatus.Running,
391
+ },
392
+ props: { isRoot: true },
393
+ })
394
+ ).toNumber();
395
+
396
+ if (runningCount >= concurrencyCap) {
397
+ logger.debug(
398
+ `Sentinel: leaving run ${run.id.toString()} queued — ${runningCount} investigations already running (cap: ${concurrencyCap}).`,
399
+ );
400
+ return false;
401
+ }
402
+
403
+ const budget: AutonomousBudgetStatus =
404
+ await AIService.getAutonomousDailyBudgetStatus(run.projectId);
405
+
406
+ if (budget.exhausted) {
407
+ logger.debug(
408
+ `Sentinel: leaving run ${run.id.toString()} queued — daily autonomous token budget exhausted.`,
409
+ );
410
+ return false;
411
+ }
412
+
413
+ return true;
414
+ }
415
+
416
+ /*
417
+ * The atomic claim: Queued -> Running, guarded on the attemptCount the
418
+ * caller observed, so a stale queue snapshot can neither double-claim
419
+ * nor reset the attempt numbering. Returns the claimed attempt number,
420
+ * or null when another actor won.
421
+ */
422
+ private static async claim(run: QueuedRunRef): Promise<number | null> {
423
+ const attempt: number = (run.attemptCount || 0) + 1;
424
+
425
+ const claimedCount: number = await AIRunService.attemptStatusTransition({
426
+ aiRunId: run.id,
427
+ fromStatus: AIRunStatus.Queued,
428
+ expectedAttemptCount: run.attemptCount || 0,
429
+ set: {
430
+ status: AIRunStatus.Running,
431
+ startedAt: OneUptimeDate.getCurrentDate(),
432
+ lastHeartbeatAt: OneUptimeDate.getCurrentDate(),
433
+ attemptCount: attempt,
434
+ },
435
+ });
436
+
437
+ if (claimedCount === 0) {
438
+ return null;
439
+ }
440
+
441
+ return attempt;
442
+ }
443
+
444
+ // Route a claimed run to its subject's executor.
445
+ private static async dispatch(
446
+ run: QueuedRunRef,
447
+ attempt: number,
448
+ ): Promise<void> {
449
+ if (run.triggeredByIncidentId) {
450
+ /*
451
+ * Lazy require: the runners import this queue to enqueue, so a
452
+ * top-level import here would be circular at module-init time
453
+ * (same pattern as DatabaseService -> AuditLogService).
454
+ */
455
+ const incidentRunner: typeof import("./IncidentInvestigationRunner").default =
456
+ // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
457
+ require("./IncidentInvestigationRunner").default;
458
+
459
+ await incidentRunner.executeInvestigation({
460
+ aiRunId: run.id,
461
+ projectId: run.projectId,
462
+ incidentId: run.triggeredByIncidentId,
463
+ attemptCount: attempt,
464
+ });
465
+ return;
466
+ }
467
+
468
+ if (run.triggeredByAlertId) {
469
+ const alertRunner: typeof import("./AlertInvestigationRunner").default =
470
+ // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
471
+ require("./AlertInvestigationRunner").default;
472
+
473
+ await alertRunner.executeInvestigation({
474
+ aiRunId: run.id,
475
+ projectId: run.projectId,
476
+ alertId: run.triggeredByAlertId,
477
+ attemptCount: attempt,
478
+ });
479
+ return;
480
+ }
481
+
482
+ // A queued investigation without a subject cannot be executed.
483
+ await AIRunService.attemptStatusTransition({
484
+ aiRunId: run.id,
485
+ fromStatus: AIRunStatus.Running,
486
+ set: {
487
+ status: AIRunStatus.Error,
488
+ completedAt: OneUptimeDate.getCurrentDate(),
489
+ errorMessage: "Queued investigation has no subject to investigate.",
490
+ },
491
+ });
492
+ }
493
+ }