@oneuptime/common 11.5.4 → 11.5.6

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 (539) hide show
  1. package/Models/DatabaseModels/AIAgentTaskPullRequest.ts +56 -45
  2. package/Models/DatabaseModels/AIInsight.ts +748 -0
  3. package/Models/DatabaseModels/AIRun.ts +262 -0
  4. package/Models/DatabaseModels/CodeRepository.ts +42 -0
  5. package/Models/DatabaseModels/GlobalConfig.ts +105 -0
  6. package/Models/DatabaseModels/Index.ts +4 -8
  7. package/Models/DatabaseModels/InstanceHealthLog.ts +277 -0
  8. package/Models/DatabaseModels/LlmLog.ts +33 -0
  9. package/Models/DatabaseModels/Project.ts +123 -6
  10. package/Models/DatabaseModels/Runbook.ts +1 -1
  11. package/Models/DatabaseModels/User.ts +47 -0
  12. package/Server/API/AIAgentDataAPI.ts +802 -140
  13. package/Server/API/AIAgentTaskAPI.ts +132 -69
  14. package/Server/API/AIAgentTaskLogAPI.ts +65 -41
  15. package/Server/API/AIAgentTaskPullRequestAPI.ts +41 -0
  16. package/Server/API/AIInsightAPI.ts +220 -0
  17. package/Server/API/AIInvestigationAPI.ts +363 -1
  18. package/Server/API/CodeFixRunAPI.ts +251 -0
  19. package/Server/API/GitHubAPI.ts +246 -3
  20. package/Server/API/TelemetryExceptionAPI.ts +193 -48
  21. package/Server/EnvironmentConfig.ts +1 -1
  22. package/Server/Infrastructure/Postgres/SchemaMigrations/1783943300000-DropServiceCodeRepository.ts +26 -0
  23. package/Server/Infrastructure/Postgres/SchemaMigrations/1783947444597-CodeFixRunsOnAIRun.ts +73 -0
  24. package/Server/Infrastructure/Postgres/SchemaMigrations/1783950962813-AddCodeFixTaskType.ts +29 -0
  25. package/Server/Infrastructure/Postgres/SchemaMigrations/1783954040984-AddInstrumentationFixTasksFlag.ts +31 -0
  26. package/Server/Infrastructure/Postgres/SchemaMigrations/1783957160597-MigrationName.ts +51 -0
  27. package/Server/Infrastructure/Postgres/SchemaMigrations/1783958542237-AddTaskContextToAIRun.ts +25 -0
  28. package/Server/Infrastructure/Postgres/SchemaMigrations/1783965945957-AddInvestigationVerdictAndGrade.ts +47 -0
  29. package/Server/Infrastructure/Postgres/SchemaMigrations/1783970619301-AddFixGuardrailColumns.ts +53 -0
  30. package/Server/Infrastructure/Postgres/SchemaMigrations/1783970619302-DropLegacyAIAgentTaskTables.ts +31 -0
  31. package/Server/Infrastructure/Postgres/SchemaMigrations/1783977781677-AddCiStatusToFixPullRequests.ts +37 -0
  32. package/Server/Infrastructure/Postgres/SchemaMigrations/1783990000000-AddCompletionTokensToLlmLog.ts +25 -0
  33. package/Server/Infrastructure/Postgres/SchemaMigrations/1784010274993-AddSentinelInsight.ts +75 -0
  34. package/Server/Infrastructure/Postgres/SchemaMigrations/1784010274994-AddSentinelInsightFlags.ts +37 -0
  35. package/Server/Infrastructure/Postgres/SchemaMigrations/1784030612266-RenameSentinelToAI.ts +203 -0
  36. package/Server/Infrastructure/Postgres/SchemaMigrations/1784033837629-MigrationName.ts +163 -0
  37. package/Server/Infrastructure/Postgres/SchemaMigrations/1784048917994-AddCreatedByUserToUser.ts +23 -0
  38. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +32 -0
  39. package/Server/Infrastructure/Queue.ts +82 -4
  40. package/Server/Infrastructure/Semaphore.ts +62 -1
  41. package/Server/Middleware/MasterAdminAuthorization.ts +37 -0
  42. package/Server/Middleware/ProjectAuthorization.ts +40 -15
  43. package/Server/Services/AIAgentService.ts +32 -0
  44. package/Server/Services/AIAgentTaskPullRequestService.ts +117 -0
  45. package/Server/Services/AIInsightService.ts +174 -0
  46. package/Server/Services/AIRunEventService.ts +63 -0
  47. package/Server/Services/AIRunService.ts +259 -1
  48. package/Server/Services/AIService.ts +249 -7
  49. package/Server/Services/AlertService.ts +4 -4
  50. package/Server/Services/CodeRepositoryService.ts +209 -0
  51. package/Server/Services/GlobalConfigService.ts +148 -0
  52. package/Server/Services/IncidentService.ts +183 -38
  53. package/Server/Services/IncidentStateTimelineService.ts +24 -4
  54. package/Server/Services/Index.ts +4 -4
  55. package/Server/Services/{AIAgentTaskLogService.ts → InstanceHealthLogService.ts} +1 -1
  56. package/Server/Services/LlmLogService.ts +27 -0
  57. package/Server/Services/LlmProviderService.ts +108 -0
  58. package/Server/Services/MetricBaselineService.ts +123 -0
  59. package/Server/Services/MonitorService.ts +15 -0
  60. package/Server/Services/TeamMemberService.ts +2 -0
  61. package/Server/Services/TelemetryExceptionService.ts +323 -116
  62. package/Server/Services/TraceAggregationService.ts +176 -0
  63. package/Server/Services/UserService.ts +10 -0
  64. package/Server/Types/Workflow/ComponentCode.ts +6 -0
  65. package/Server/Types/Workflow/Components/AI/GenerateText.ts +326 -0
  66. package/Server/Types/Workflow/Components/Index.ts +2 -0
  67. package/Server/Utils/AI/Chat/ObservabilityAssistant.ts +1 -1
  68. package/Server/Utils/AI/CodeFix/CodeAgentWorkspaceGuard.ts +71 -0
  69. package/Server/Utils/AI/CodeFix/CodeFixAgentCompletion.ts +243 -0
  70. package/Server/Utils/AI/CodeFix/CodeFixRunQueue.ts +131 -0
  71. package/Server/Utils/AI/CodeFix/FixRunBudget.ts +148 -0
  72. package/Server/Utils/AI/CodeFix/OpenPullRequestCap.ts +117 -0
  73. package/Server/Utils/AI/Eval/EvalCorpus.ts +369 -0
  74. package/Server/Utils/AI/Eval/EvalScores.ts +172 -0
  75. package/Server/Utils/AI/Eval/ReplayInvestigation.ts +87 -0
  76. package/Server/Utils/AI/PerfEvidence/SpanTreeAnalyzer.ts +676 -0
  77. package/Server/Utils/AI/{Sentinel/SentinelInvestigationEngine.ts → SRE/AIInvestigationEngine.ts} +58 -37
  78. package/Server/Utils/AI/{Sentinel/SentinelMemory.ts → SRE/AIMemory.ts} +3 -3
  79. package/Server/Utils/AI/{Sentinel → SRE}/AlertInvestigationRunner.ts +50 -20
  80. package/Server/Utils/AI/SRE/ConfidenceSignal.ts +293 -0
  81. package/Server/Utils/AI/SRE/FixFromIncidentTaskTrigger.ts +115 -0
  82. package/Server/Utils/AI/SRE/FixPerformanceTaskTrigger.ts +223 -0
  83. package/Server/Utils/AI/{Sentinel → SRE}/IncidentInvestigationRunner.ts +71 -21
  84. package/Server/Utils/AI/{Sentinel → SRE}/IncidentPostmortemRunner.ts +8 -8
  85. package/Server/Utils/AI/SRE/Insights/Detectors/ErrorLogSpikeDetector.ts +364 -0
  86. package/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.ts +317 -0
  87. package/Server/Utils/AI/SRE/Insights/Detectors/Index.ts +27 -0
  88. package/Server/Utils/AI/SRE/Insights/Detectors/MetricDriftDetector.ts +221 -0
  89. package/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.ts +238 -0
  90. package/Server/Utils/AI/SRE/Insights/Detectors/TraceLatencyRegressionDetector.ts +521 -0
  91. package/Server/Utils/AI/SRE/Insights/FixRouting.ts +242 -0
  92. package/Server/Utils/AI/SRE/Insights/InsightScanner.ts +290 -0
  93. package/Server/Utils/AI/SRE/Insights/InsightStore.ts +283 -0
  94. package/Server/Utils/AI/SRE/Insights/InsightTriageRunner.ts +242 -0
  95. package/Server/Utils/AI/SRE/Insights/Triage.ts +162 -0
  96. package/Server/Utils/AI/SRE/Insights/Types.ts +49 -0
  97. package/Server/Utils/AI/SRE/InstrumentationTaskTrigger.ts +212 -0
  98. package/Server/Utils/AI/SRE/InvestigationGrader.ts +282 -0
  99. package/Server/Utils/AI/{Sentinel → SRE}/InvestigationQueue.ts +114 -19
  100. package/Server/Utils/AI/{Sentinel → SRE}/README.md +4 -4
  101. package/Server/Utils/AI/SRE/SubjectCodeFixRun.ts +172 -0
  102. package/Server/Utils/AI/Toolbox/{SentinelActionTools.ts → AIActionTools.ts} +22 -1
  103. package/Server/Utils/AI/Toolbox/Index.ts +2 -2
  104. package/Server/Utils/AnalyticsDatabase/ClickhouseCapacity.ts +526 -0
  105. package/Server/Utils/CodeRepository/GitHub/GitHub.ts +319 -1
  106. package/Server/Utils/CodeRepository/ServiceRepoLinkSuggester.ts +221 -0
  107. package/Server/Utils/CodeRepository/StackTraceRepoResolver.ts +571 -0
  108. package/Server/Utils/Execute.ts +2 -1
  109. package/Server/Utils/LLM/LLMService.ts +160 -30
  110. package/Server/Utils/Monitor/Criteria/SqlMonitorCriteria.ts +152 -0
  111. package/Server/Utils/Monitor/MonitorCriteriaEvaluator.ts +29 -0
  112. package/Server/Utils/Monitor/MonitorCriteriaExpectationBuilder.ts +16 -6
  113. package/Server/Utils/Monitor/MonitorCriteriaMessageBuilder.ts +14 -0
  114. package/Server/Utils/Monitor/MonitorCriteriaMessageFormatter.ts +14 -3
  115. package/Server/Utils/Monitor/MonitorCriteriaObservationBuilder.ts +130 -12
  116. package/Tests/Server/Infrastructure/Queue.test.ts +227 -0
  117. package/Tests/Server/Infrastructure/SemaphorePermit.test.ts +159 -0
  118. package/Tests/Server/Services/AIAgentTaskPullRequestOutcomeStats.test.ts +154 -0
  119. package/Tests/Server/Services/AIInsightService.test.ts +324 -0
  120. package/Tests/Server/Services/AIRunCodeFixClaim.test.ts +401 -0
  121. package/Tests/Server/Services/AIRunHumanVerdict.test.ts +161 -0
  122. package/Tests/Server/Services/AIServiceDailyBudget.test.ts +95 -5
  123. package/Tests/Server/Services/AIServiceProjectAccess.test.ts +259 -0
  124. package/Tests/Server/Services/FixFromIncidentTaskTrigger.test.ts +249 -0
  125. package/Tests/Server/Services/FixPerformanceTaskTrigger.test.ts +274 -0
  126. package/Tests/Server/Services/GlobalConfigService.test.ts +80 -0
  127. package/Tests/Server/Services/IncidentInternalNoteAnnouncement.test.ts +1 -1
  128. package/Tests/Server/Services/InstrumentationTaskTrigger.test.ts +313 -0
  129. package/Tests/Server/Services/LlmProviderProjectOwned.test.ts +132 -0
  130. package/Tests/Server/Services/TelemetryExceptionAIFixReadiness.test.ts +405 -0
  131. package/Tests/Server/Services/TelemetryExceptionCodeFixRun.test.ts +322 -0
  132. package/Tests/Server/Services/TraceServiceLatencyProfile.test.ts +278 -0
  133. package/Tests/Server/Types/Workflow/Components/AIGenerateText.test.ts +722 -0
  134. package/Tests/Server/Utils/AI/{SentinelAlertGating.test.ts → AIAlertGating.test.ts} +19 -19
  135. package/Tests/Server/Utils/AI/AIConfidenceSignal.test.ts +362 -0
  136. package/Tests/Server/Utils/AI/{SentinelInvestigationQueue.test.ts → AIInvestigationQueue.test.ts} +19 -19
  137. package/Tests/Server/Utils/AI/CodeAgentWorkspaceGuard.test.ts +138 -0
  138. package/Tests/Server/Utils/AI/CodeFixAgentCompletion.test.ts +335 -0
  139. package/Tests/Server/Utils/AI/CodeFixRunQueue.test.ts +134 -0
  140. package/Tests/Server/Utils/AI/EvalCorpus.test.ts +209 -0
  141. package/Tests/Server/Utils/AI/EvalScores.test.ts +343 -0
  142. package/Tests/Server/Utils/AI/FixRunBudget.test.ts +218 -0
  143. package/Tests/Server/Utils/AI/Insights/ErrorLogSpikeDetector.test.ts +437 -0
  144. package/Tests/Server/Utils/AI/Insights/ExceptionSpikeDetector.test.ts +287 -0
  145. package/Tests/Server/Utils/AI/Insights/InsightDetectorsIndex.test.ts +34 -0
  146. package/Tests/Server/Utils/AI/Insights/InsightFixRouting.test.ts +572 -0
  147. package/Tests/Server/Utils/AI/Insights/InsightNeverThrowsHardening.test.ts +344 -0
  148. package/Tests/Server/Utils/AI/Insights/InsightScanner.test.ts +720 -0
  149. package/Tests/Server/Utils/AI/Insights/InsightStore.test.ts +467 -0
  150. package/Tests/Server/Utils/AI/Insights/InsightStoreHardening.test.ts +370 -0
  151. package/Tests/Server/Utils/AI/Insights/InsightTriage.test.ts +210 -0
  152. package/Tests/Server/Utils/AI/Insights/InsightTriageRunner.test.ts +221 -0
  153. package/Tests/Server/Utils/AI/Insights/InvestigationQueueInsightSubject.test.ts +328 -0
  154. package/Tests/Server/Utils/AI/Insights/MetricBaselineDrift.test.ts +182 -0
  155. package/Tests/Server/Utils/AI/Insights/MetricDriftDetector.test.ts +280 -0
  156. package/Tests/Server/Utils/AI/Insights/NewExceptionDetector.test.ts +259 -0
  157. package/Tests/Server/Utils/AI/Insights/TraceLatencyRegressionDetector.test.ts +770 -0
  158. package/Tests/Server/Utils/AI/InvestigationGrader.test.ts +343 -0
  159. package/Tests/Server/Utils/AI/LLMServiceRequestPolicy.test.ts +307 -0
  160. package/Tests/Server/Utils/AI/OpenPullRequestCap.test.ts +170 -0
  161. package/Tests/Server/Utils/AI/SpanTreeAnalyzer.test.ts +559 -0
  162. package/Tests/Server/Utils/AnalyticsDatabase/ClickhouseCapacity.test.ts +158 -0
  163. package/Tests/Server/Utils/GitHubCheckRunsConclusion.test.ts +100 -0
  164. package/Tests/Server/Utils/GitHubPullRequestStateMapping.test.ts +50 -0
  165. package/Tests/Server/Utils/Monitor/Criteria/SqlMonitorCriteria.test.ts +266 -0
  166. package/Tests/Server/Utils/Monitor/MonitorCriteriaExpectationBuilderUnits.test.ts +553 -0
  167. package/Tests/Server/Utils/Monitor/MonitorCriteriaMessageBuilderUnits.test.ts +590 -0
  168. package/Tests/Server/Utils/Monitor/MonitorCriteriaMessageFormatterUnits.test.ts +254 -0
  169. package/Tests/Server/Utils/Monitor/MonitorCriteriaObservationBuilderUnits.test.ts +821 -0
  170. package/Tests/Server/Utils/ServiceRepoLinkSuggester.test.ts +167 -0
  171. package/Tests/Server/Utils/StackTraceRepoResolver.test.ts +527 -0
  172. package/Tests/Types/AI/AIChatPermissionMode.test.ts +112 -0
  173. package/Tests/Types/AI/CodeFixTaskType.test.ts +152 -0
  174. package/Tests/Types/AI/FixPullRequestCiStatus.test.ts +181 -0
  175. package/Tests/Types/Monitor/MonitorStepSqlMonitor.test.ts +110 -0
  176. package/Tests/Types/Monitor/SqlDatabaseType.test.ts +55 -0
  177. package/Tests/Types/Workflow/AIGenerateTextMetadata.test.ts +180 -0
  178. package/Tests/UI/Components/TableBulkCsvExport.test.tsx +168 -0
  179. package/Tests/UI/Utils/TableColumnsToCsv.test.ts +523 -0
  180. package/Types/AI/AIChatTypes.ts +8 -0
  181. package/Types/AI/AIInsightEvidence.ts +77 -0
  182. package/Types/AI/AIInsightHumanVerdict.ts +15 -0
  183. package/Types/AI/AIInsightSeverity.ts +13 -0
  184. package/Types/AI/AIInsightStatus.ts +38 -0
  185. package/Types/AI/AIInsightType.ts +41 -0
  186. package/Types/AI/AIRunAutoGrade.ts +18 -0
  187. package/Types/AI/AIRunEventType.ts +5 -0
  188. package/Types/AI/AIRunHumanVerdict.ts +17 -0
  189. package/Types/AI/AIRunType.ts +6 -0
  190. package/Types/AI/CodeFixTaskContext.ts +88 -0
  191. package/Types/AI/CodeFixTaskType.ts +132 -0
  192. package/Types/AI/FixPullRequestCiStatus.ts +132 -0
  193. package/Types/BaseDatabase/AggregationIntervalUtil.ts +67 -0
  194. package/Types/Incident/IncidentMetricType.ts +7 -0
  195. package/Types/Monitor/CriteriaFilter.ts +8 -0
  196. package/Types/Monitor/MonitorCriteriaInstance.ts +67 -0
  197. package/Types/Monitor/MonitorStep.ts +38 -0
  198. package/Types/Monitor/MonitorStepSqlMonitor.ts +141 -0
  199. package/Types/Monitor/MonitorType.ts +17 -0
  200. package/Types/Monitor/SqlDatabaseType.ts +49 -0
  201. package/Types/Monitor/SqlMonitor/SqlMonitorResponse.ts +28 -0
  202. package/Types/Permission.ts +11 -95
  203. package/Types/Probe/ProbeMonitorResponse.ts +2 -0
  204. package/Types/Runbook/RunbookStep.ts +26 -2
  205. package/Types/Runbook/RunbookStepType.ts +1 -0
  206. package/Types/Workflow/Component.ts +13 -0
  207. package/Types/Workflow/ComponentID.ts +1 -0
  208. package/Types/Workflow/Components/AI.ts +148 -0
  209. package/Types/Workflow/Components.ts +8 -0
  210. package/UI/Components/AI/GenerateFromAIModal.tsx +1 -1
  211. package/UI/Components/Markdown.tsx/MarkdownViewer.tsx +11 -0
  212. package/UI/Components/MoreMenu/MoreMenu.tsx +1 -1
  213. package/UI/Components/Table/Table.tsx +38 -2
  214. package/UI/Utils/TableColumnsToCsv.ts +385 -0
  215. package/Utils/Monitor/MonitorMetricType.ts +1 -0
  216. package/build/dist/Models/DatabaseModels/AIAgentTaskPullRequest.js +59 -45
  217. package/build/dist/Models/DatabaseModels/AIAgentTaskPullRequest.js.map +1 -1
  218. package/build/dist/Models/DatabaseModels/AIInsight.js +795 -0
  219. package/build/dist/Models/DatabaseModels/AIInsight.js.map +1 -0
  220. package/build/dist/Models/DatabaseModels/AIRun.js +274 -0
  221. package/build/dist/Models/DatabaseModels/AIRun.js.map +1 -1
  222. package/build/dist/Models/DatabaseModels/CodeRepository.js +43 -0
  223. package/build/dist/Models/DatabaseModels/CodeRepository.js.map +1 -1
  224. package/build/dist/Models/DatabaseModels/GlobalConfig.js +110 -0
  225. package/build/dist/Models/DatabaseModels/GlobalConfig.js.map +1 -1
  226. package/build/dist/Models/DatabaseModels/Index.js +4 -8
  227. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  228. package/build/dist/Models/DatabaseModels/InstanceHealthLog.js +304 -0
  229. package/build/dist/Models/DatabaseModels/InstanceHealthLog.js.map +1 -0
  230. package/build/dist/Models/DatabaseModels/LlmLog.js +35 -0
  231. package/build/dist/Models/DatabaseModels/LlmLog.js.map +1 -1
  232. package/build/dist/Models/DatabaseModels/Project.js +127 -6
  233. package/build/dist/Models/DatabaseModels/Project.js.map +1 -1
  234. package/build/dist/Models/DatabaseModels/Runbook.js +1 -1
  235. package/build/dist/Models/DatabaseModels/Runbook.js.map +1 -1
  236. package/build/dist/Models/DatabaseModels/User.js +46 -0
  237. package/build/dist/Models/DatabaseModels/User.js.map +1 -1
  238. package/build/dist/Server/API/AIAgentDataAPI.js +568 -85
  239. package/build/dist/Server/API/AIAgentDataAPI.js.map +1 -1
  240. package/build/dist/Server/API/AIAgentTaskAPI.js +100 -44
  241. package/build/dist/Server/API/AIAgentTaskAPI.js.map +1 -1
  242. package/build/dist/Server/API/AIAgentTaskLogAPI.js +49 -25
  243. package/build/dist/Server/API/AIAgentTaskLogAPI.js.map +1 -1
  244. package/build/dist/Server/API/AIAgentTaskPullRequestAPI.js +27 -0
  245. package/build/dist/Server/API/AIAgentTaskPullRequestAPI.js.map +1 -1
  246. package/build/dist/Server/API/AIInsightAPI.js +140 -0
  247. package/build/dist/Server/API/AIInsightAPI.js.map +1 -0
  248. package/build/dist/Server/API/AIInvestigationAPI.js +257 -1
  249. package/build/dist/Server/API/AIInvestigationAPI.js.map +1 -1
  250. package/build/dist/Server/API/CodeFixRunAPI.js +181 -0
  251. package/build/dist/Server/API/CodeFixRunAPI.js.map +1 -0
  252. package/build/dist/Server/API/GitHubAPI.js +164 -2
  253. package/build/dist/Server/API/GitHubAPI.js.map +1 -1
  254. package/build/dist/Server/API/TelemetryExceptionAPI.js +148 -43
  255. package/build/dist/Server/API/TelemetryExceptionAPI.js.map +1 -1
  256. package/build/dist/Server/EnvironmentConfig.js +1 -1
  257. package/build/dist/Server/EnvironmentConfig.js.map +1 -1
  258. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783943300000-DropServiceCodeRepository.js +23 -0
  259. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783943300000-DropServiceCodeRepository.js.map +1 -0
  260. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783947444597-CodeFixRunsOnAIRun.js +32 -0
  261. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783947444597-CodeFixRunsOnAIRun.js.map +1 -0
  262. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783950962813-AddCodeFixTaskType.js +16 -0
  263. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783950962813-AddCodeFixTaskType.js.map +1 -0
  264. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783954040984-AddInstrumentationFixTasksFlag.js +16 -0
  265. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783954040984-AddInstrumentationFixTasksFlag.js.map +1 -0
  266. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783957160597-MigrationName.js +24 -0
  267. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783957160597-MigrationName.js.map +1 -0
  268. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783958542237-AddTaskContextToAIRun.js +16 -0
  269. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783958542237-AddTaskContextToAIRun.js.map +1 -0
  270. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783965945957-AddInvestigationVerdictAndGrade.js +24 -0
  271. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783965945957-AddInvestigationVerdictAndGrade.js.map +1 -0
  272. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783970619301-AddFixGuardrailColumns.js +24 -0
  273. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783970619301-AddFixGuardrailColumns.js.map +1 -0
  274. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783970619302-DropLegacyAIAgentTaskTables.js +24 -0
  275. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783970619302-DropLegacyAIAgentTaskTables.js.map +1 -0
  276. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783977781677-AddCiStatusToFixPullRequests.js +18 -0
  277. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783977781677-AddCiStatusToFixPullRequests.js.map +1 -0
  278. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783990000000-AddCompletionTokensToLlmLog.js +18 -0
  279. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783990000000-AddCompletionTokensToLlmLog.js.map +1 -0
  280. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784010274993-AddSentinelInsight.js +32 -0
  281. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784010274993-AddSentinelInsight.js.map +1 -0
  282. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784010274994-AddSentinelInsightFlags.js +18 -0
  283. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784010274994-AddSentinelInsightFlags.js.map +1 -0
  284. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784030612266-RenameSentinelToAI.js +125 -0
  285. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784030612266-RenameSentinelToAI.js.map +1 -0
  286. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784033837629-MigrationName.js +62 -0
  287. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784033837629-MigrationName.js.map +1 -0
  288. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784048917994-AddCreatedByUserToUser.js +18 -0
  289. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784048917994-AddCreatedByUserToUser.js.map +1 -0
  290. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +32 -0
  291. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  292. package/build/dist/Server/Infrastructure/Queue.js +73 -3
  293. package/build/dist/Server/Infrastructure/Queue.js.map +1 -1
  294. package/build/dist/Server/Infrastructure/Semaphore.js +44 -1
  295. package/build/dist/Server/Infrastructure/Semaphore.js.map +1 -1
  296. package/build/dist/Server/Middleware/MasterAdminAuthorization.js +26 -0
  297. package/build/dist/Server/Middleware/MasterAdminAuthorization.js.map +1 -1
  298. package/build/dist/Server/Middleware/ProjectAuthorization.js +40 -14
  299. package/build/dist/Server/Middleware/ProjectAuthorization.js.map +1 -1
  300. package/build/dist/Server/Services/AIAgentService.js +29 -0
  301. package/build/dist/Server/Services/AIAgentService.js.map +1 -1
  302. package/build/dist/Server/Services/AIAgentTaskPullRequestService.js +78 -0
  303. package/build/dist/Server/Services/AIAgentTaskPullRequestService.js.map +1 -1
  304. package/build/dist/Server/Services/AIInsightService.js +164 -0
  305. package/build/dist/Server/Services/AIInsightService.js.map +1 -0
  306. package/build/dist/Server/Services/AIRunEventService.js +49 -0
  307. package/build/dist/Server/Services/AIRunEventService.js.map +1 -1
  308. package/build/dist/Server/Services/AIRunService.js +221 -0
  309. package/build/dist/Server/Services/AIRunService.js.map +1 -1
  310. package/build/dist/Server/Services/AIService.js +198 -11
  311. package/build/dist/Server/Services/AIService.js.map +1 -1
  312. package/build/dist/Server/Services/AlertService.js +4 -4
  313. package/build/dist/Server/Services/AlertService.js.map +1 -1
  314. package/build/dist/Server/Services/CodeRepositoryService.js +180 -0
  315. package/build/dist/Server/Services/CodeRepositoryService.js.map +1 -1
  316. package/build/dist/Server/Services/GlobalConfigService.js +84 -0
  317. package/build/dist/Server/Services/GlobalConfigService.js.map +1 -1
  318. package/build/dist/Server/Services/IncidentService.js +149 -37
  319. package/build/dist/Server/Services/IncidentService.js.map +1 -1
  320. package/build/dist/Server/Services/IncidentStateTimelineService.js +24 -4
  321. package/build/dist/Server/Services/IncidentStateTimelineService.js.map +1 -1
  322. package/build/dist/Server/Services/Index.js +4 -4
  323. package/build/dist/Server/Services/Index.js.map +1 -1
  324. package/build/dist/Server/Services/{AIAgentTaskLogService.js → InstanceHealthLogService.js} +2 -2
  325. package/build/dist/Server/Services/InstanceHealthLogService.js.map +1 -0
  326. package/build/dist/Server/Services/LlmLogService.js +23 -0
  327. package/build/dist/Server/Services/LlmLogService.js.map +1 -1
  328. package/build/dist/Server/Services/LlmProviderService.js +96 -0
  329. package/build/dist/Server/Services/LlmProviderService.js.map +1 -1
  330. package/build/dist/Server/Services/MetricBaselineService.js +65 -0
  331. package/build/dist/Server/Services/MetricBaselineService.js.map +1 -1
  332. package/build/dist/Server/Services/MonitorService.js +9 -1
  333. package/build/dist/Server/Services/MonitorService.js.map +1 -1
  334. package/build/dist/Server/Services/TeamMemberService.js +2 -0
  335. package/build/dist/Server/Services/TeamMemberService.js.map +1 -1
  336. package/build/dist/Server/Services/TelemetryExceptionService.js +243 -82
  337. package/build/dist/Server/Services/TelemetryExceptionService.js.map +1 -1
  338. package/build/dist/Server/Services/TraceAggregationService.js +124 -0
  339. package/build/dist/Server/Services/TraceAggregationService.js.map +1 -1
  340. package/build/dist/Server/Services/UserService.js +8 -0
  341. package/build/dist/Server/Services/UserService.js.map +1 -1
  342. package/build/dist/Server/Types/Workflow/ComponentCode.js.map +1 -1
  343. package/build/dist/Server/Types/Workflow/Components/AI/GenerateText.js +240 -0
  344. package/build/dist/Server/Types/Workflow/Components/AI/GenerateText.js.map +1 -0
  345. package/build/dist/Server/Types/Workflow/Components/Index.js +2 -0
  346. package/build/dist/Server/Types/Workflow/Components/Index.js.map +1 -1
  347. package/build/dist/Server/Utils/AI/CodeFix/CodeAgentWorkspaceGuard.js +48 -0
  348. package/build/dist/Server/Utils/AI/CodeFix/CodeAgentWorkspaceGuard.js.map +1 -0
  349. package/build/dist/Server/Utils/AI/CodeFix/CodeFixAgentCompletion.js +174 -0
  350. package/build/dist/Server/Utils/AI/CodeFix/CodeFixAgentCompletion.js.map +1 -0
  351. package/build/dist/Server/Utils/AI/CodeFix/CodeFixRunQueue.js +126 -0
  352. package/build/dist/Server/Utils/AI/CodeFix/CodeFixRunQueue.js.map +1 -0
  353. package/build/dist/Server/Utils/AI/CodeFix/FixRunBudget.js +131 -0
  354. package/build/dist/Server/Utils/AI/CodeFix/FixRunBudget.js.map +1 -0
  355. package/build/dist/Server/Utils/AI/CodeFix/OpenPullRequestCap.js +99 -0
  356. package/build/dist/Server/Utils/AI/CodeFix/OpenPullRequestCap.js.map +1 -0
  357. package/build/dist/Server/Utils/AI/Eval/EvalCorpus.js +245 -0
  358. package/build/dist/Server/Utils/AI/Eval/EvalCorpus.js.map +1 -0
  359. package/build/dist/Server/Utils/AI/Eval/EvalScores.js +83 -0
  360. package/build/dist/Server/Utils/AI/Eval/EvalScores.js.map +1 -0
  361. package/build/dist/Server/Utils/AI/Eval/ReplayInvestigation.js +12 -0
  362. package/build/dist/Server/Utils/AI/Eval/ReplayInvestigation.js.map +1 -0
  363. package/build/dist/Server/Utils/AI/PerfEvidence/SpanTreeAnalyzer.js +439 -0
  364. package/build/dist/Server/Utils/AI/PerfEvidence/SpanTreeAnalyzer.js.map +1 -0
  365. package/build/dist/Server/Utils/AI/{Sentinel/SentinelInvestigationEngine.js → SRE/AIInvestigationEngine.js} +47 -31
  366. package/build/dist/Server/Utils/AI/SRE/AIInvestigationEngine.js.map +1 -0
  367. package/build/dist/Server/Utils/AI/{Sentinel/SentinelMemory.js → SRE/AIMemory.js} +5 -5
  368. package/build/dist/Server/Utils/AI/SRE/AIMemory.js.map +1 -0
  369. package/build/dist/Server/Utils/AI/{Sentinel → SRE}/AlertInvestigationRunner.js +42 -19
  370. package/build/dist/Server/Utils/AI/SRE/AlertInvestigationRunner.js.map +1 -0
  371. package/build/dist/Server/Utils/AI/SRE/ConfidenceSignal.js +226 -0
  372. package/build/dist/Server/Utils/AI/SRE/ConfidenceSignal.js.map +1 -0
  373. package/build/dist/Server/Utils/AI/SRE/FixFromIncidentTaskTrigger.js +100 -0
  374. package/build/dist/Server/Utils/AI/SRE/FixFromIncidentTaskTrigger.js.map +1 -0
  375. package/build/dist/Server/Utils/AI/SRE/FixPerformanceTaskTrigger.js +174 -0
  376. package/build/dist/Server/Utils/AI/SRE/FixPerformanceTaskTrigger.js.map +1 -0
  377. package/build/dist/Server/Utils/AI/{Sentinel → SRE}/IncidentInvestigationRunner.js +60 -22
  378. package/build/dist/Server/Utils/AI/SRE/IncidentInvestigationRunner.js.map +1 -0
  379. package/build/dist/Server/Utils/AI/{Sentinel → SRE}/IncidentPostmortemRunner.js +9 -9
  380. package/build/dist/Server/Utils/AI/SRE/IncidentPostmortemRunner.js.map +1 -0
  381. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ErrorLogSpikeDetector.js +268 -0
  382. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ErrorLogSpikeDetector.js.map +1 -0
  383. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.js +226 -0
  384. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.js.map +1 -0
  385. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/Index.js +26 -0
  386. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/Index.js.map +1 -0
  387. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/MetricDriftDetector.js +159 -0
  388. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/MetricDriftDetector.js.map +1 -0
  389. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.js +177 -0
  390. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.js.map +1 -0
  391. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/TraceLatencyRegressionDetector.js +384 -0
  392. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/TraceLatencyRegressionDetector.js.map +1 -0
  393. package/build/dist/Server/Utils/AI/SRE/Insights/FixRouting.js +180 -0
  394. package/build/dist/Server/Utils/AI/SRE/Insights/FixRouting.js.map +1 -0
  395. package/build/dist/Server/Utils/AI/SRE/Insights/InsightScanner.js +269 -0
  396. package/build/dist/Server/Utils/AI/SRE/Insights/InsightScanner.js.map +1 -0
  397. package/build/dist/Server/Utils/AI/SRE/Insights/InsightStore.js +231 -0
  398. package/build/dist/Server/Utils/AI/SRE/Insights/InsightStore.js.map +1 -0
  399. package/build/dist/Server/Utils/AI/SRE/Insights/InsightTriageRunner.js +206 -0
  400. package/build/dist/Server/Utils/AI/SRE/Insights/InsightTriageRunner.js.map +1 -0
  401. package/build/dist/Server/Utils/AI/SRE/Insights/Triage.js +121 -0
  402. package/build/dist/Server/Utils/AI/SRE/Insights/Triage.js.map +1 -0
  403. package/build/dist/Server/Utils/AI/SRE/Insights/Types.js +2 -0
  404. package/build/dist/Server/Utils/AI/SRE/Insights/Types.js.map +1 -0
  405. package/build/dist/Server/Utils/AI/SRE/InstrumentationTaskTrigger.js +148 -0
  406. package/build/dist/Server/Utils/AI/SRE/InstrumentationTaskTrigger.js.map +1 -0
  407. package/build/dist/Server/Utils/AI/SRE/InvestigationGrader.js +231 -0
  408. package/build/dist/Server/Utils/AI/SRE/InvestigationGrader.js.map +1 -0
  409. package/build/dist/Server/Utils/AI/{Sentinel → SRE}/InvestigationQueue.js +102 -23
  410. package/build/dist/Server/Utils/AI/SRE/InvestigationQueue.js.map +1 -0
  411. package/build/dist/Server/Utils/AI/SRE/SubjectCodeFixRun.js +167 -0
  412. package/build/dist/Server/Utils/AI/SRE/SubjectCodeFixRun.js.map +1 -0
  413. package/build/dist/Server/Utils/AI/Toolbox/{SentinelActionTools.js → AIActionTools.js} +18 -2
  414. package/build/dist/Server/Utils/AI/Toolbox/AIActionTools.js.map +1 -0
  415. package/build/dist/Server/Utils/AI/Toolbox/Index.js +2 -2
  416. package/build/dist/Server/Utils/AI/Toolbox/Index.js.map +1 -1
  417. package/build/dist/Server/Utils/AnalyticsDatabase/ClickhouseCapacity.js +301 -0
  418. package/build/dist/Server/Utils/AnalyticsDatabase/ClickhouseCapacity.js.map +1 -0
  419. package/build/dist/Server/Utils/CodeRepository/GitHub/GitHub.js +240 -2
  420. package/build/dist/Server/Utils/CodeRepository/GitHub/GitHub.js.map +1 -1
  421. package/build/dist/Server/Utils/CodeRepository/ServiceRepoLinkSuggester.js +127 -0
  422. package/build/dist/Server/Utils/CodeRepository/ServiceRepoLinkSuggester.js.map +1 -0
  423. package/build/dist/Server/Utils/CodeRepository/StackTraceRepoResolver.js +336 -0
  424. package/build/dist/Server/Utils/CodeRepository/StackTraceRepoResolver.js.map +1 -0
  425. package/build/dist/Server/Utils/Execute.js.map +1 -1
  426. package/build/dist/Server/Utils/LLM/LLMService.js +125 -25
  427. package/build/dist/Server/Utils/LLM/LLMService.js.map +1 -1
  428. package/build/dist/Server/Utils/Monitor/Criteria/SqlMonitorCriteria.js +120 -0
  429. package/build/dist/Server/Utils/Monitor/Criteria/SqlMonitorCriteria.js.map +1 -0
  430. package/build/dist/Server/Utils/Monitor/MonitorCriteriaEvaluator.js +21 -0
  431. package/build/dist/Server/Utils/Monitor/MonitorCriteriaEvaluator.js.map +1 -1
  432. package/build/dist/Server/Utils/Monitor/MonitorCriteriaExpectationBuilder.js +15 -7
  433. package/build/dist/Server/Utils/Monitor/MonitorCriteriaExpectationBuilder.js.map +1 -1
  434. package/build/dist/Server/Utils/Monitor/MonitorCriteriaMessageBuilder.js +12 -1
  435. package/build/dist/Server/Utils/Monitor/MonitorCriteriaMessageBuilder.js.map +1 -1
  436. package/build/dist/Server/Utils/Monitor/MonitorCriteriaMessageFormatter.js +8 -3
  437. package/build/dist/Server/Utils/Monitor/MonitorCriteriaMessageFormatter.js.map +1 -1
  438. package/build/dist/Server/Utils/Monitor/MonitorCriteriaObservationBuilder.js +96 -12
  439. package/build/dist/Server/Utils/Monitor/MonitorCriteriaObservationBuilder.js.map +1 -1
  440. package/build/dist/Types/AI/AIInsightEvidence.js +2 -0
  441. package/build/dist/Types/AI/AIInsightEvidence.js.map +1 -0
  442. package/build/dist/Types/AI/AIInsightHumanVerdict.js +16 -0
  443. package/build/dist/Types/AI/AIInsightHumanVerdict.js.map +1 -0
  444. package/build/dist/Types/AI/AIInsightSeverity.js +14 -0
  445. package/build/dist/Types/AI/AIInsightSeverity.js.map +1 -0
  446. package/build/dist/Types/AI/AIInsightStatus.js +36 -0
  447. package/build/dist/Types/AI/AIInsightStatus.js.map +1 -0
  448. package/build/dist/Types/AI/AIInsightType.js +42 -0
  449. package/build/dist/Types/AI/AIInsightType.js.map +1 -0
  450. package/build/dist/Types/AI/AIRunAutoGrade.js +19 -0
  451. package/build/dist/Types/AI/AIRunAutoGrade.js.map +1 -0
  452. package/build/dist/Types/AI/AIRunEventType.js +5 -0
  453. package/build/dist/Types/AI/AIRunEventType.js.map +1 -1
  454. package/build/dist/Types/AI/AIRunHumanVerdict.js +18 -0
  455. package/build/dist/Types/AI/AIRunHumanVerdict.js.map +1 -0
  456. package/build/dist/Types/AI/AIRunType.js +6 -0
  457. package/build/dist/Types/AI/AIRunType.js.map +1 -1
  458. package/build/dist/Types/AI/CodeFixTaskContext.js +29 -0
  459. package/build/dist/Types/AI/CodeFixTaskContext.js.map +1 -0
  460. package/build/dist/Types/AI/CodeFixTaskType.js +122 -0
  461. package/build/dist/Types/AI/CodeFixTaskType.js.map +1 -0
  462. package/build/dist/Types/AI/FixPullRequestCiStatus.js +102 -0
  463. package/build/dist/Types/AI/FixPullRequestCiStatus.js.map +1 -0
  464. package/build/dist/Types/BaseDatabase/AggregationIntervalUtil.js +55 -0
  465. package/build/dist/Types/BaseDatabase/AggregationIntervalUtil.js.map +1 -1
  466. package/build/dist/Types/Incident/IncidentMetricType.js +7 -0
  467. package/build/dist/Types/Incident/IncidentMetricType.js.map +1 -1
  468. package/build/dist/Types/Monitor/CriteriaFilter.js +7 -0
  469. package/build/dist/Types/Monitor/CriteriaFilter.js.map +1 -1
  470. package/build/dist/Types/Monitor/MonitorCriteriaInstance.js +62 -0
  471. package/build/dist/Types/Monitor/MonitorCriteriaInstance.js.map +1 -1
  472. package/build/dist/Types/Monitor/MonitorStep.js +28 -0
  473. package/build/dist/Types/Monitor/MonitorStep.js.map +1 -1
  474. package/build/dist/Types/Monitor/MonitorStepSqlMonitor.js +93 -0
  475. package/build/dist/Types/Monitor/MonitorStepSqlMonitor.js.map +1 -0
  476. package/build/dist/Types/Monitor/MonitorType.js +15 -0
  477. package/build/dist/Types/Monitor/MonitorType.js.map +1 -1
  478. package/build/dist/Types/Monitor/SqlDatabaseType.js +47 -0
  479. package/build/dist/Types/Monitor/SqlDatabaseType.js.map +1 -0
  480. package/build/dist/Types/Monitor/SqlMonitor/SqlMonitorResponse.js +2 -0
  481. package/build/dist/Types/Monitor/SqlMonitor/SqlMonitorResponse.js.map +1 -0
  482. package/build/dist/Types/Permission.js +10 -84
  483. package/build/dist/Types/Permission.js.map +1 -1
  484. package/build/dist/Types/Runbook/RunbookStepType.js +1 -0
  485. package/build/dist/Types/Runbook/RunbookStepType.js.map +1 -1
  486. package/build/dist/Types/Workflow/ComponentID.js +1 -0
  487. package/build/dist/Types/Workflow/ComponentID.js.map +1 -1
  488. package/build/dist/Types/Workflow/Components/AI.js +135 -0
  489. package/build/dist/Types/Workflow/Components/AI.js.map +1 -0
  490. package/build/dist/Types/Workflow/Components.js +7 -0
  491. package/build/dist/Types/Workflow/Components.js.map +1 -1
  492. package/build/dist/UI/Components/AI/GenerateFromAIModal.js +1 -1
  493. package/build/dist/UI/Components/AI/GenerateFromAIModal.js.map +1 -1
  494. package/build/dist/UI/Components/Markdown.tsx/MarkdownViewer.js +9 -0
  495. package/build/dist/UI/Components/Markdown.tsx/MarkdownViewer.js.map +1 -1
  496. package/build/dist/UI/Components/MoreMenu/MoreMenu.js +1 -1
  497. package/build/dist/UI/Components/Table/Table.js +28 -2
  498. package/build/dist/UI/Components/Table/Table.js.map +1 -1
  499. package/build/dist/UI/Utils/TableColumnsToCsv.js +291 -0
  500. package/build/dist/UI/Utils/TableColumnsToCsv.js.map +1 -0
  501. package/build/dist/Utils/Monitor/MonitorMetricType.js +1 -0
  502. package/build/dist/Utils/Monitor/MonitorMetricType.js.map +1 -1
  503. package/package.json +1 -1
  504. package/Models/DatabaseModels/AIAgentTask.ts +0 -660
  505. package/Models/DatabaseModels/AIAgentTaskLog.ts +0 -426
  506. package/Models/DatabaseModels/AIAgentTaskTelemetryException.ts +0 -399
  507. package/Models/DatabaseModels/ServiceCodeRepository.ts +0 -647
  508. package/Server/Services/AIAgentTaskService.ts +0 -240
  509. package/Server/Services/AIAgentTaskTelemetryExceptionService.ts +0 -39
  510. package/Server/Services/ServiceCodeRepositoryService.ts +0 -55
  511. package/Tests/Server/Services/AIAgentTaskServiceClaim.test.ts +0 -146
  512. package/Types/AI/AIAgentTaskMetadata.ts +0 -25
  513. package/Types/AI/AIAgentTaskType.ts +0 -40
  514. package/build/dist/Models/DatabaseModels/AIAgentTask.js +0 -691
  515. package/build/dist/Models/DatabaseModels/AIAgentTask.js.map +0 -1
  516. package/build/dist/Models/DatabaseModels/AIAgentTaskLog.js +0 -447
  517. package/build/dist/Models/DatabaseModels/AIAgentTaskLog.js.map +0 -1
  518. package/build/dist/Models/DatabaseModels/AIAgentTaskTelemetryException.js +0 -415
  519. package/build/dist/Models/DatabaseModels/AIAgentTaskTelemetryException.js.map +0 -1
  520. package/build/dist/Models/DatabaseModels/ServiceCodeRepository.js +0 -665
  521. package/build/dist/Models/DatabaseModels/ServiceCodeRepository.js.map +0 -1
  522. package/build/dist/Server/Services/AIAgentTaskLogService.js.map +0 -1
  523. package/build/dist/Server/Services/AIAgentTaskService.js +0 -217
  524. package/build/dist/Server/Services/AIAgentTaskService.js.map +0 -1
  525. package/build/dist/Server/Services/AIAgentTaskTelemetryExceptionService.js +0 -36
  526. package/build/dist/Server/Services/AIAgentTaskTelemetryExceptionService.js.map +0 -1
  527. package/build/dist/Server/Services/ServiceCodeRepositoryService.js +0 -54
  528. package/build/dist/Server/Services/ServiceCodeRepositoryService.js.map +0 -1
  529. package/build/dist/Server/Utils/AI/Sentinel/AlertInvestigationRunner.js.map +0 -1
  530. package/build/dist/Server/Utils/AI/Sentinel/IncidentInvestigationRunner.js.map +0 -1
  531. package/build/dist/Server/Utils/AI/Sentinel/IncidentPostmortemRunner.js.map +0 -1
  532. package/build/dist/Server/Utils/AI/Sentinel/InvestigationQueue.js.map +0 -1
  533. package/build/dist/Server/Utils/AI/Sentinel/SentinelInvestigationEngine.js.map +0 -1
  534. package/build/dist/Server/Utils/AI/Sentinel/SentinelMemory.js.map +0 -1
  535. package/build/dist/Server/Utils/AI/Toolbox/SentinelActionTools.js.map +0 -1
  536. package/build/dist/Types/AI/AIAgentTaskMetadata.js +0 -6
  537. package/build/dist/Types/AI/AIAgentTaskMetadata.js.map +0 -1
  538. package/build/dist/Types/AI/AIAgentTaskType.js +0 -29
  539. package/build/dist/Types/AI/AIAgentTaskType.js.map +0 -1
@@ -1,11 +1,15 @@
1
1
  import AIAgentService from "../Services/AIAgentService";
2
- import LlmProviderService from "../Services/LlmProviderService";
3
2
  import TelemetryExceptionService from "../Services/TelemetryExceptionService";
4
3
  import ServiceService from "../Services/ServiceService";
5
- import ServiceCodeRepositoryService from "../Services/ServiceCodeRepositoryService";
6
4
  import CodeRepositoryService from "../Services/CodeRepositoryService";
5
+ import { RepoResolution } from "../Utils/CodeRepository/StackTraceRepoResolver";
7
6
  import AIAgentTaskPullRequestService from "../Services/AIAgentTaskPullRequestService";
8
- import AIAgentTaskService from "../Services/AIAgentTaskService";
7
+ import AIRunService from "../Services/AIRunService";
8
+ import AIRunEventService from "../Services/AIRunEventService";
9
+ import IncidentService from "../Services/IncidentService";
10
+ import AlertService from "../Services/AlertService";
11
+ import IncidentFeedService from "../Services/IncidentFeedService";
12
+ import AlertFeedService from "../Services/AlertFeedService";
9
13
  import Express, {
10
14
  ExpressRequest,
11
15
  ExpressResponse,
@@ -14,13 +18,43 @@ import Express, {
14
18
  } from "../Utils/Express";
15
19
  import Response from "../Utils/Response";
16
20
  import AIAgent from "../../Models/DatabaseModels/AIAgent";
17
- import LlmProvider from "../../Models/DatabaseModels/LlmProvider";
18
21
  import TelemetryException from "../../Models/DatabaseModels/TelemetryException";
19
22
  import Service from "../../Models/DatabaseModels/Service";
20
- import ServiceCodeRepository from "../../Models/DatabaseModels/ServiceCodeRepository";
21
23
  import CodeRepository from "../../Models/DatabaseModels/CodeRepository";
22
24
  import AIAgentTaskPullRequest from "../../Models/DatabaseModels/AIAgentTaskPullRequest";
23
- import AIAgentTask from "../../Models/DatabaseModels/AIAgentTask";
25
+ import AIRun from "../../Models/DatabaseModels/AIRun";
26
+ import Incident from "../../Models/DatabaseModels/Incident";
27
+ import Alert from "../../Models/DatabaseModels/Alert";
28
+ import IncidentFeed, {
29
+ IncidentFeedEventType,
30
+ } from "../../Models/DatabaseModels/IncidentFeed";
31
+ import AlertFeed, {
32
+ AlertFeedEventType,
33
+ } from "../../Models/DatabaseModels/AlertFeed";
34
+ import AIRunEventType from "../../Types/AI/AIRunEventType";
35
+ import AIRunType from "../../Types/AI/AIRunType";
36
+ import CodeFixTaskType, {
37
+ CodeFixContextKind,
38
+ CodeFixTaskTypeHelper,
39
+ } from "../../Types/AI/CodeFixTaskType";
40
+ import CodeFixTaskContext, {
41
+ ImplicatedSpan,
42
+ PerformanceCodeLocation,
43
+ PerformanceFinding,
44
+ } from "../../Types/AI/CodeFixTaskContext";
45
+ import SpanTreeAnalyzer from "../Utils/AI/PerfEvidence/SpanTreeAnalyzer";
46
+ import OpenPullRequestCap, {
47
+ OpenPullRequestCapDecision,
48
+ } from "../Utils/AI/CodeFix/OpenPullRequestCap";
49
+ import CodeFixAgentCompletion, {
50
+ AgentCompletionResult,
51
+ } from "../Utils/AI/CodeFix/CodeFixAgentCompletion";
52
+ import {
53
+ LLMMessage,
54
+ LLMToolCall,
55
+ LLMToolDefinition,
56
+ } from "../Utils/LLM/LLMService";
57
+ import SortOrder from "../../Types/BaseDatabase/SortOrder";
24
58
  import BadDataException from "../../Types/Exception/BadDataException";
25
59
  import { JSONObject } from "../../Types/JSON";
26
60
  import ObjectID from "../../Types/ObjectID";
@@ -28,7 +62,6 @@ import GitHubUtil, {
28
62
  GitHubInstallationToken,
29
63
  } from "../Utils/CodeRepository/GitHub/GitHub";
30
64
  import CodeRepositoryType from "../../Types/CodeRepository/CodeRepositoryType";
31
- import LIMIT_MAX from "../../Types/Database/LimitMax";
32
65
  import URL from "../../Types/API/URL";
33
66
  import PullRequestState from "../../Types/CodeRepository/PullRequestState";
34
67
  import logger, { getLogAttributesFromRequest } from "../Utils/Logger";
@@ -46,9 +79,23 @@ export default class AIAgentDataAPI {
46
79
  }
47
80
 
48
81
  private initRoutes(): void {
49
- // Get LLM configuration for a project
82
+ /*
83
+ * Server-mediated LLM completion for the in-house code-fix agent (B4
84
+ * Tier 0, Internal/Roadmap/CodeFixSandboxDesign.md). One call = one
85
+ * completion of the worker's tool loop, executed through
86
+ * AIService.executeWithLogging: metered, LlmLog-linked to the run,
87
+ * inside the G4 daily budget, and under per-run loop budgets (max
88
+ * completion calls / output tokens) enforced server-side. The worker
89
+ * never receives a provider secret on this path.
90
+ *
91
+ * Request: { aiAgentId, aiAgentKey, taskId, messages, tools?, maxTokens? }
92
+ * Response: { message: { role: "assistant", content, toolCalls },
93
+ * stopReason: "stop" | "tool_use",
94
+ * budget: { completionCallsUsed, maxCompletionCalls,
95
+ * outputTokensUsed, maxOutputTokens } }
96
+ */
50
97
  this.router.post(
51
- "/ai-agent-data/get-llm-config",
98
+ "/ai-agent-data/llm-completion",
52
99
  async (
53
100
  req: ExpressRequest,
54
101
  res: ExpressResponse,
@@ -60,7 +107,7 @@ export default class AIAgentDataAPI {
60
107
  // Validate AI Agent credentials
61
108
  const aiAgent: AIAgent | null = await this.validateAIAgent(data);
62
109
 
63
- if (!aiAgent) {
110
+ if (!aiAgent || !aiAgent.id) {
64
111
  return Response.sendErrorResponse(
65
112
  req,
66
113
  res,
@@ -68,62 +115,44 @@ export default class AIAgentDataAPI {
68
115
  );
69
116
  }
70
117
 
71
- // Get project ID
72
- if (!data["projectId"]) {
73
- return Response.sendErrorResponse(
74
- req,
75
- res,
76
- new BadDataException("projectId is required"),
77
- );
78
- }
79
-
80
- const projectId: ObjectID = new ObjectID(data["projectId"] as string);
81
-
82
- // Check if this is a Project AI Agent (has a projectId)
83
- const isProjectAIAgent: boolean =
84
- aiAgent.projectId !== null && aiAgent.projectId !== undefined;
85
-
86
- // Get LLM provider for the project
87
- const llmProvider: LlmProvider | null =
88
- await LlmProviderService.getLLMProviderForProject(projectId);
89
-
90
- if (!llmProvider) {
118
+ if (!data["taskId"]) {
91
119
  return Response.sendErrorResponse(
92
120
  req,
93
121
  res,
94
- new BadDataException(
95
- "No LLM provider configured for this project",
96
- ),
122
+ new BadDataException("taskId is required"),
97
123
  );
98
124
  }
99
125
 
100
- /*
101
- * Security check: Project AI Agents cannot access Global LLM Providers
102
- * Only Global AI Agents (projectId is null) can access Global LLM Providers
103
- */
104
- const isGlobalLLMProvider: boolean = llmProvider.isGlobalLlm === true;
105
-
106
- if (isProjectAIAgent && isGlobalLLMProvider) {
107
- return Response.sendErrorResponse(
108
- req,
109
- res,
110
- new BadDataException(
111
- "Project AI Agents cannot access Global LLM Providers. Please configure a project-specific LLM Provider.",
112
- ),
113
- );
114
- }
126
+ const taskId: ObjectID = new ObjectID(data["taskId"] as string);
115
127
 
116
- logger.debug(
117
- `LLM config fetched for project ${projectId.toString()}: ${llmProvider.llmType}`,
118
- getLogAttributesFromRequest(req as any),
128
+ const messages: Array<LLMMessage> = this.parseCompletionMessages(
129
+ data["messages"],
119
130
  );
131
+ const tools: Array<LLMToolDefinition> | undefined =
132
+ this.parseCompletionTools(data["tools"]);
133
+ const maxTokens: number | undefined =
134
+ typeof data["maxTokens"] === "number" && data["maxTokens"] > 0
135
+ ? data["maxTokens"]
136
+ : undefined;
137
+
138
+ const result: AgentCompletionResult =
139
+ await CodeFixAgentCompletion.execute({
140
+ aiAgentId: aiAgent.id,
141
+ aiRunId: taskId,
142
+ messages,
143
+ tools,
144
+ maxTokens,
145
+ });
120
146
 
121
147
  return Response.sendJsonObjectResponse(req, res, {
122
- llmType: llmProvider.llmType,
123
- apiKey: llmProvider.apiKey,
124
- baseUrl: llmProvider.baseUrl,
125
- modelName: llmProvider.modelName,
126
- });
148
+ message: {
149
+ role: "assistant",
150
+ content: result.content,
151
+ toolCalls: result.toolCalls,
152
+ },
153
+ stopReason: result.stopReason,
154
+ budget: result.budget,
155
+ } as unknown as JSONObject);
127
156
  } catch (err) {
128
157
  next(err);
129
158
  }
@@ -238,7 +267,13 @@ export default class AIAgentDataAPI {
238
267
  },
239
268
  );
240
269
 
241
- // Get code repositories linked to a service
270
+ /*
271
+ * Resolve the repository the exception's code lives in — AT RUNTIME
272
+ * (stack-trace path matching over the project's connected repos, with
273
+ * name-match and only-repository fallbacks). Replaces the old
274
+ * ServiceCodeRepository mapping-table lookup; the response keeps the
275
+ * `repositories` array shape the agent already consumes.
276
+ */
242
277
  this.router.post(
243
278
  "/ai-agent-data/get-code-repositories",
244
279
  async (
@@ -260,100 +295,574 @@ export default class AIAgentDataAPI {
260
295
  );
261
296
  }
262
297
 
263
- // Get service ID (supports primaryEntityId plus legacy serviceId / telemetryServiceId from older agents)
264
- const serviceIdParam: string | undefined =
265
- (data["primaryEntityId"] as string) ||
266
- (data["serviceId"] as string) ||
267
- (data["telemetryServiceId"] as string);
298
+ if (!data["exceptionId"]) {
299
+ return Response.sendErrorResponse(
300
+ req,
301
+ res,
302
+ new BadDataException(
303
+ "exceptionId is required (agents older than the runtime-resolution change must be upgraded)",
304
+ ),
305
+ );
306
+ }
307
+
308
+ const exceptionId: ObjectID = new ObjectID(
309
+ data["exceptionId"] as string,
310
+ );
311
+
312
+ const exception: TelemetryException | null =
313
+ await TelemetryExceptionService.findOneById({
314
+ id: exceptionId,
315
+ select: {
316
+ _id: true,
317
+ projectId: true,
318
+ stackTrace: true,
319
+ primaryEntityId: true,
320
+ },
321
+ props: {
322
+ isRoot: true,
323
+ },
324
+ });
268
325
 
269
- if (!serviceIdParam) {
326
+ if (!exception || !exception.projectId) {
270
327
  return Response.sendErrorResponse(
271
328
  req,
272
329
  res,
273
- new BadDataException("primaryEntityId is required"),
330
+ new BadDataException("Exception not found"),
274
331
  );
275
332
  }
276
333
 
277
- const primaryEntityId: ObjectID = new ObjectID(serviceIdParam);
334
+ // Service name feeds the name-match fallback when there is one.
335
+ const service: Service | null = exception.primaryEntityId
336
+ ? await ServiceService.findOneById({
337
+ id: exception.primaryEntityId,
338
+ select: {
339
+ name: true,
340
+ },
341
+ props: {
342
+ isRoot: true,
343
+ },
344
+ })
345
+ : null;
346
+
347
+ const resolution: RepoResolution | null =
348
+ await CodeRepositoryService.resolveRepositoryForException({
349
+ projectId: exception.projectId,
350
+ stackTrace: exception.stackTrace || null,
351
+ serviceName: service?.name || null,
352
+ });
353
+
354
+ if (!resolution) {
355
+ logger.debug(
356
+ `No repository resolved for exception ${exceptionId.toString()}`,
357
+ getLogAttributesFromRequest(req as any),
358
+ );
359
+
360
+ return Response.sendJsonObjectResponse(req, res, {
361
+ repositories: [],
362
+ resolutionError:
363
+ "Could not resolve a repository for this exception: no connected repository contains the files in its stack trace, no repository name matches the service, and the project has more than one repository. Connect the right repository via the GitHub App.",
364
+ });
365
+ }
366
+
367
+ const repository: CodeRepository | null =
368
+ await CodeRepositoryService.findOneById({
369
+ id: new ObjectID(resolution.codeRepositoryId),
370
+ select: {
371
+ _id: true,
372
+ name: true,
373
+ repositoryHostedAt: true,
374
+ organizationName: true,
375
+ repositoryName: true,
376
+ mainBranchName: true,
377
+ gitHubAppInstallationId: true,
378
+ },
379
+ props: {
380
+ isRoot: true,
381
+ },
382
+ });
383
+
384
+ if (!repository) {
385
+ return Response.sendErrorResponse(
386
+ req,
387
+ res,
388
+ new BadDataException("Resolved repository no longer exists"),
389
+ );
390
+ }
278
391
 
279
- // Find CodeRepositories linked to this Service
280
- const repositories: Array<{
281
- id: string;
282
- name: string;
283
- repositoryHostedAt: string;
284
- organizationName: string;
285
- repositoryName: string;
286
- mainBranchName: string;
287
- servicePathInRepository: string | null;
288
- gitHubAppInstallationId: string | null;
289
- }> = [];
392
+ logger.debug(
393
+ `Resolved repository ${resolution.organizationName}/${resolution.repositoryName} for exception ${exceptionId.toString()} via ${resolution.method}: ${resolution.evidence}`,
394
+ getLogAttributesFromRequest(req as any),
395
+ );
290
396
 
291
- const serviceCodeRepositories: Array<ServiceCodeRepository> =
292
- await ServiceCodeRepositoryService.findBy({
293
- query: {
294
- serviceId: primaryEntityId,
397
+ return Response.sendJsonObjectResponse(req, res, {
398
+ repositories: [
399
+ {
400
+ id: repository.id!.toString(),
401
+ name: repository.name || "",
402
+ repositoryHostedAt: repository.repositoryHostedAt || "",
403
+ organizationName: repository.organizationName || "",
404
+ repositoryName: repository.repositoryName || "",
405
+ mainBranchName: repository.mainBranchName || "main",
406
+ servicePathInRepository: resolution.servicePathInRepository,
407
+ gitHubAppInstallationId:
408
+ repository.gitHubAppInstallationId || null,
409
+ resolutionMethod: resolution.method,
410
+ resolutionEvidence: resolution.evidence,
295
411
  },
412
+ ],
413
+ });
414
+ } catch (err) {
415
+ next(err);
416
+ }
417
+ },
418
+ );
419
+
420
+ /*
421
+ * Context for every non-exception recipe, keyed by the run id `taskId`
422
+ * (the id get-pending-task returned) — these runs have NO telemetry
423
+ * exception, so the exception-shaped endpoints above cannot serve them.
424
+ * The route name predates the newer recipes and is kept for agent
425
+ * compatibility. Two context kinds are served:
426
+ *
427
+ * - Incident/alert-subject recipes (ImproveInstrumentation,
428
+ * FixFromIncident): the investigation's posted analysis + subject
429
+ * metadata + the repository resolved without a stack trace. The
430
+ * analysis text comes from the subject's latest RootCause feed item:
431
+ * the AI's postAnalysis is the only writer of RootCause feed
432
+ * events, it writes them for BOTH subjects and BOTH confidence
433
+ * outcomes (quiet mode only mutes the workspace ping), so the feed
434
+ * item IS the investigation run's persisted output.
435
+ *
436
+ * - Trace-evidence recipes (FixPerformance): the deterministic
437
+ * span-tree findings stored on AIRun.taskContext at trigger time
438
+ * (subjectType "trace"; the rendered evidence rides in
439
+ * analysisMarkdown so the worker pipeline stays shared). Repository
440
+ * resolution here TRIES the stack-trace path matcher first, fed by a
441
+ * synthetic trace built from the implicated spans' code.*
442
+ * attributes, before the name-match / only-repository fallbacks.
443
+ */
444
+ this.router.post(
445
+ "/ai-agent-data/get-instrumentation-task-details",
446
+ async (
447
+ req: ExpressRequest,
448
+ res: ExpressResponse,
449
+ next: NextFunction,
450
+ ): Promise<void> => {
451
+ try {
452
+ const data: JSONObject = req.body;
453
+
454
+ // Validate AI Agent credentials
455
+ const aiAgent: AIAgent | null = await this.validateAIAgent(data);
456
+
457
+ if (!aiAgent) {
458
+ return Response.sendErrorResponse(
459
+ req,
460
+ res,
461
+ new BadDataException("Invalid AI Agent ID or AI Agent Key"),
462
+ );
463
+ }
464
+
465
+ if (!data["taskId"]) {
466
+ return Response.sendErrorResponse(
467
+ req,
468
+ res,
469
+ new BadDataException("taskId is required"),
470
+ );
471
+ }
472
+
473
+ const taskId: ObjectID = new ObjectID(data["taskId"] as string);
474
+
475
+ const run: AIRun | null = await AIRunService.findOneById({
476
+ id: taskId,
477
+ select: {
478
+ _id: true,
479
+ projectId: true,
480
+ runType: true,
481
+ codeFixTaskType: true,
482
+ triggeredByIncidentId: true,
483
+ triggeredByAlertId: true,
484
+ taskContext: true,
485
+ },
486
+ props: {
487
+ isRoot: true,
488
+ },
489
+ });
490
+
491
+ if (!run || !run.projectId) {
492
+ return Response.sendErrorResponse(
493
+ req,
494
+ res,
495
+ new BadDataException("Task not found"),
496
+ );
497
+ }
498
+
499
+ /*
500
+ * Any non-exception recipe is served here — the same context-kind
501
+ * grouping the claim guard uses.
502
+ */
503
+ const taskType: CodeFixTaskType =
504
+ CodeFixTaskTypeHelper.fromDatabaseValue(run.codeFixTaskType);
505
+ const contextKind: CodeFixContextKind =
506
+ CodeFixTaskTypeHelper.getContextKind(taskType);
507
+
508
+ if (
509
+ run.runType !== AIRunType.CodeFix ||
510
+ contextKind === CodeFixContextKind.TelemetryException
511
+ ) {
512
+ return Response.sendErrorResponse(
513
+ req,
514
+ res,
515
+ new BadDataException(
516
+ "Task is not an incident/alert-subject or trace-evidence code-fix run (ImproveInstrumentation, FixFromIncident or FixPerformance)",
517
+ ),
518
+ );
519
+ }
520
+
521
+ /*
522
+ * Trace-evidence recipes (FixPerformance): everything the worker
523
+ * needs was captured into taskContext at trigger time — the spans
524
+ * themselves may already be past ClickHouse retention.
525
+ */
526
+ if (contextKind === CodeFixContextKind.TaskContext) {
527
+ const taskContext: CodeFixTaskContext | undefined = run.taskContext;
528
+ const findings: Array<PerformanceFinding> =
529
+ taskContext?.performanceFindings || [];
530
+
531
+ if (!taskContext?.traceId || findings.length === 0) {
532
+ return Response.sendErrorResponse(
533
+ req,
534
+ res,
535
+ new BadDataException(
536
+ "This performance-fix task has no stored trace evidence — the task has nothing to work from.",
537
+ ),
538
+ );
539
+ }
540
+
541
+ // Deduped name+duration summary of every implicated span.
542
+ const spanSummaries: Array<ImplicatedSpan> = [];
543
+ const seenSpanIds: Set<string> = new Set();
544
+ for (const finding of findings) {
545
+ for (const implicated of finding.implicatedSpans) {
546
+ if (!seenSpanIds.has(implicated.spanId)) {
547
+ seenSpanIds.add(implicated.spanId);
548
+ spanSummaries.push(implicated);
549
+ }
550
+ }
551
+ }
552
+
553
+ /*
554
+ * Repository resolution: the implicated spans' code.*
555
+ * attributes (when the instrumentation stamps them) become a
556
+ * synthetic stack trace for the path matcher — each line is
557
+ * shaped so extractCandidatePathsFromStackTrace parses it.
558
+ * Without code attributes this degrades to the name-match /
559
+ * only-repository fallbacks, exactly like the subject recipes.
560
+ */
561
+ const codeLocations: Array<PerformanceCodeLocation> =
562
+ taskContext.codeLocations || [];
563
+ const syntheticStackTrace: string | null =
564
+ codeLocations.length > 0
565
+ ? codeLocations
566
+ .map((location: PerformanceCodeLocation): string => {
567
+ return ` at ${
568
+ location.functionName ? `${location.functionName} ` : ""
569
+ }(${location.filePath}:${location.lineNumber ?? 1})`;
570
+ })
571
+ .join("\n")
572
+ : null;
573
+
574
+ const serviceName: string | null = taskContext.serviceName || null;
575
+
576
+ const resolution: RepoResolution | null =
577
+ await CodeRepositoryService.resolveRepositoryForException({
578
+ projectId: run.projectId,
579
+ stackTrace: syntheticStackTrace,
580
+ serviceName,
581
+ });
582
+
583
+ const repository: CodeRepository | null = resolution
584
+ ? await CodeRepositoryService.findOneById({
585
+ id: new ObjectID(resolution.codeRepositoryId),
586
+ select: {
587
+ _id: true,
588
+ name: true,
589
+ repositoryHostedAt: true,
590
+ organizationName: true,
591
+ repositoryName: true,
592
+ mainBranchName: true,
593
+ gitHubAppInstallationId: true,
594
+ },
595
+ props: {
596
+ isRoot: true,
597
+ },
598
+ })
599
+ : null;
600
+
601
+ /*
602
+ * The rendered evidence rides in analysisMarkdown and the top
603
+ * finding's headline in subjectTitle, so the shared
604
+ * SubjectPullRequestTaskHandler pipeline needs no special
605
+ * casing — the structured findings travel alongside.
606
+ */
607
+ const basePayload: JSONObject = {
608
+ subjectType: "trace",
609
+ subjectTitle: findings[0]!.headline,
610
+ analysisMarkdown:
611
+ SpanTreeAnalyzer.renderFindingsMarkdown(findings),
612
+ serviceName,
613
+ projectId: run.projectId.toString(),
614
+ traceId: taskContext.traceId,
615
+ findings: findings as never,
616
+ spanSummaries: spanSummaries as never,
617
+ };
618
+
619
+ if (!resolution || !repository) {
620
+ logger.debug(
621
+ `No repository resolved for ${taskType} task ${taskId.toString()}`,
622
+ getLogAttributesFromRequest(req as any),
623
+ );
624
+
625
+ return Response.sendJsonObjectResponse(req, res, {
626
+ ...basePayload,
627
+ repositories: [],
628
+ resolutionError:
629
+ "Could not resolve a repository for this performance-fix task: the trace's spans carried no matching code file paths, no connected repository name matches the affected service, and the project has more than one repository. Connect the right repository via the GitHub App, or rename one to match the service.",
630
+ });
631
+ }
632
+
633
+ logger.debug(
634
+ `Resolved repository ${resolution.organizationName}/${resolution.repositoryName} for ${taskType} task ${taskId.toString()} via ${resolution.method}: ${resolution.evidence}`,
635
+ getLogAttributesFromRequest(req as any),
636
+ );
637
+
638
+ return Response.sendJsonObjectResponse(req, res, {
639
+ ...basePayload,
640
+ repositories: [
641
+ {
642
+ id: repository.id!.toString(),
643
+ name: repository.name || "",
644
+ repositoryHostedAt: repository.repositoryHostedAt || "",
645
+ organizationName: repository.organizationName || "",
646
+ repositoryName: repository.repositoryName || "",
647
+ mainBranchName: repository.mainBranchName || "main",
648
+ servicePathInRepository: resolution.servicePathInRepository,
649
+ gitHubAppInstallationId:
650
+ repository.gitHubAppInstallationId || null,
651
+ resolutionMethod: resolution.method,
652
+ resolutionEvidence: resolution.evidence,
653
+ },
654
+ ],
655
+ });
656
+ }
657
+
658
+ if (!run.triggeredByIncidentId && !run.triggeredByAlertId) {
659
+ return Response.sendErrorResponse(
660
+ req,
661
+ res,
662
+ new BadDataException(
663
+ "This task has no incident or alert subject",
664
+ ),
665
+ );
666
+ }
667
+
668
+ const subjectType: "incident" | "alert" = run.triggeredByIncidentId
669
+ ? "incident"
670
+ : "alert";
671
+
672
+ let subjectTitle: string = "";
673
+ /*
674
+ * Best-effort service attribution from the subject's monitors —
675
+ * it only feeds the repository name-match fallback, so null is
676
+ * fine when the subject has no monitor.
677
+ */
678
+ let serviceName: string | null = null;
679
+ let analysisMarkdown: string | null = null;
680
+
681
+ if (run.triggeredByIncidentId) {
682
+ const incident: Incident | null = await IncidentService.findOneById(
683
+ {
684
+ id: run.triggeredByIncidentId,
685
+ select: {
686
+ title: true,
687
+ monitors: {
688
+ name: true,
689
+ },
690
+ },
691
+ props: {
692
+ isRoot: true,
693
+ },
694
+ },
695
+ );
696
+
697
+ if (!incident) {
698
+ return Response.sendErrorResponse(
699
+ req,
700
+ res,
701
+ new BadDataException(
702
+ "The incident this task was created for no longer exists",
703
+ ),
704
+ );
705
+ }
706
+
707
+ subjectTitle = incident.title || "Untitled incident";
708
+ serviceName =
709
+ (incident.monitors || [])
710
+ .map((monitor: { name?: string | undefined }) => {
711
+ return monitor.name || "";
712
+ })
713
+ .filter(Boolean)[0] || null;
714
+
715
+ const feedItem: IncidentFeed | null =
716
+ await IncidentFeedService.findOneBy({
717
+ query: {
718
+ incidentId: run.triggeredByIncidentId,
719
+ incidentFeedEventType: IncidentFeedEventType.RootCause,
720
+ },
721
+ select: {
722
+ feedInfoInMarkdown: true,
723
+ },
724
+ sort: {
725
+ createdAt: SortOrder.Descending,
726
+ },
727
+ props: {
728
+ isRoot: true,
729
+ },
730
+ });
731
+
732
+ analysisMarkdown = feedItem?.feedInfoInMarkdown || null;
733
+ } else {
734
+ const alert: Alert | null = await AlertService.findOneById({
735
+ id: run.triggeredByAlertId!,
296
736
  select: {
297
- codeRepositoryId: true,
298
- servicePathInRepository: true,
299
- codeRepository: {
300
- _id: true,
737
+ title: true,
738
+ monitor: {
301
739
  name: true,
302
- repositoryHostedAt: true,
303
- organizationName: true,
304
- repositoryName: true,
305
- mainBranchName: true,
306
- gitHubAppInstallationId: true,
307
740
  },
308
741
  },
309
- skip: 0,
310
- limit: LIMIT_MAX,
311
742
  props: {
312
743
  isRoot: true,
313
744
  },
314
745
  });
315
746
 
316
- for (const scr of serviceCodeRepositories) {
317
- if (scr.codeRepository) {
318
- // Check if we already have this repository
319
- const existingRepo: boolean = repositories.some(
320
- (r: {
321
- id: string;
322
- name: string;
323
- repositoryHostedAt: string;
324
- organizationName: string;
325
- repositoryName: string;
326
- mainBranchName: string;
327
- servicePathInRepository: string | null;
328
- gitHubAppInstallationId: string | null;
329
- }) => {
330
- return r.id === scr.codeRepository?._id?.toString();
331
- },
747
+ if (!alert) {
748
+ return Response.sendErrorResponse(
749
+ req,
750
+ res,
751
+ new BadDataException(
752
+ "The alert this task was created for no longer exists",
753
+ ),
332
754
  );
333
- if (!existingRepo) {
334
- repositories.push({
335
- id: scr.codeRepository._id?.toString() || "",
336
- name: scr.codeRepository.name || "",
337
- repositoryHostedAt:
338
- scr.codeRepository.repositoryHostedAt || "",
339
- organizationName: scr.codeRepository.organizationName || "",
340
- repositoryName: scr.codeRepository.repositoryName || "",
341
- mainBranchName: scr.codeRepository.mainBranchName || "main",
342
- servicePathInRepository: scr.servicePathInRepository || null,
343
- gitHubAppInstallationId:
344
- scr.codeRepository.gitHubAppInstallationId || null,
345
- });
346
- }
347
755
  }
756
+
757
+ subjectTitle = alert.title || "Untitled alert";
758
+ serviceName = alert.monitor?.name || null;
759
+
760
+ const feedItem: AlertFeed | null = await AlertFeedService.findOneBy(
761
+ {
762
+ query: {
763
+ alertId: run.triggeredByAlertId!,
764
+ alertFeedEventType: AlertFeedEventType.RootCause,
765
+ },
766
+ select: {
767
+ feedInfoInMarkdown: true,
768
+ },
769
+ sort: {
770
+ createdAt: SortOrder.Descending,
771
+ },
772
+ props: {
773
+ isRoot: true,
774
+ },
775
+ },
776
+ );
777
+
778
+ analysisMarkdown = feedItem?.feedInfoInMarkdown || null;
779
+ }
780
+
781
+ if (!analysisMarkdown) {
782
+ return Response.sendErrorResponse(
783
+ req,
784
+ res,
785
+ new BadDataException(
786
+ `No posted investigation analysis found for this ${subjectType} — the task has nothing to work from (the analysis feed item may have been deleted).`,
787
+ ),
788
+ );
789
+ }
790
+
791
+ /*
792
+ * Resolve the repository WITHOUT a stack trace — these tasks have
793
+ * no exception, so only the name-match (against the subject's
794
+ * monitor/service name) and only-repository fallbacks apply. When
795
+ * nothing resolves the worker fails the run with this guidance.
796
+ */
797
+ const resolution: RepoResolution | null =
798
+ await CodeRepositoryService.resolveRepositoryForException({
799
+ projectId: run.projectId,
800
+ stackTrace: null,
801
+ serviceName,
802
+ });
803
+
804
+ const repository: CodeRepository | null = resolution
805
+ ? await CodeRepositoryService.findOneById({
806
+ id: new ObjectID(resolution.codeRepositoryId),
807
+ select: {
808
+ _id: true,
809
+ name: true,
810
+ repositoryHostedAt: true,
811
+ organizationName: true,
812
+ repositoryName: true,
813
+ mainBranchName: true,
814
+ gitHubAppInstallationId: true,
815
+ },
816
+ props: {
817
+ isRoot: true,
818
+ },
819
+ })
820
+ : null;
821
+
822
+ if (!resolution || !repository) {
823
+ logger.debug(
824
+ `No repository resolved for ${taskType} task ${taskId.toString()}`,
825
+ getLogAttributesFromRequest(req as any),
826
+ );
827
+
828
+ return Response.sendJsonObjectResponse(req, res, {
829
+ subjectType,
830
+ subjectTitle,
831
+ analysisMarkdown,
832
+ serviceName,
833
+ projectId: run.projectId.toString(),
834
+ repositories: [],
835
+ resolutionError:
836
+ "Could not resolve a repository for this task: no connected repository name matches the affected monitor/service and the project has more than one repository. Connect the right repository via the GitHub App, or rename one to match the service.",
837
+ });
348
838
  }
349
839
 
350
840
  logger.debug(
351
- `Found ${repositories.length} code repositories for service ${primaryEntityId.toString()}`,
841
+ `Resolved repository ${resolution.organizationName}/${resolution.repositoryName} for ${taskType} task ${taskId.toString()} via ${resolution.method}: ${resolution.evidence}`,
352
842
  getLogAttributesFromRequest(req as any),
353
843
  );
354
844
 
355
845
  return Response.sendJsonObjectResponse(req, res, {
356
- repositories: repositories,
846
+ subjectType,
847
+ subjectTitle,
848
+ analysisMarkdown,
849
+ serviceName,
850
+ projectId: run.projectId.toString(),
851
+ repositories: [
852
+ {
853
+ id: repository.id!.toString(),
854
+ name: repository.name || "",
855
+ repositoryHostedAt: repository.repositoryHostedAt || "",
856
+ organizationName: repository.organizationName || "",
857
+ repositoryName: repository.repositoryName || "",
858
+ mainBranchName: repository.mainBranchName || "main",
859
+ servicePathInRepository: resolution.servicePathInRepository,
860
+ gitHubAppInstallationId:
861
+ repository.gitHubAppInstallationId || null,
862
+ resolutionMethod: resolution.method,
863
+ resolutionEvidence: resolution.evidence,
864
+ },
865
+ ],
357
866
  });
358
867
  } catch (err) {
359
868
  next(err);
@@ -406,6 +915,7 @@ export default class AIAgentDataAPI {
406
915
  organizationName: true,
407
916
  repositoryName: true,
408
917
  gitHubAppInstallationId: true,
918
+ maxOpenFixPullRequests: true,
409
919
  },
410
920
  props: {
411
921
  isRoot: true,
@@ -442,6 +952,31 @@ export default class AIAgentDataAPI {
442
952
  );
443
953
  }
444
954
 
955
+ /*
956
+ * G11 guardrail: per-repo open-PR cap, enforced HERE because the
957
+ * token is the agent's only way to clone and push — a repo at its
958
+ * cap physically cannot receive another AI branch or PR. The
959
+ * worker records this message as the run's failure guidance.
960
+ */
961
+ const openPrCap: OpenPullRequestCapDecision =
962
+ await OpenPullRequestCap.checkForRepository({
963
+ codeRepositoryId,
964
+ configuredLimit: codeRepository.maxOpenFixPullRequests ?? null,
965
+ });
966
+
967
+ if (!openPrCap.allowed) {
968
+ return Response.sendErrorResponse(
969
+ req,
970
+ res,
971
+ new BadDataException(
972
+ OpenPullRequestCap.describeRejection({
973
+ decision: openPrCap,
974
+ repositoryName: `${codeRepository.organizationName}/${codeRepository.repositoryName}`,
975
+ }),
976
+ ),
977
+ );
978
+ }
979
+
445
980
  /*
446
981
  * Generate GitHub installation access token with write permissions
447
982
  * Required for AI Agent to push branches and create pull requests
@@ -555,21 +1090,22 @@ export default class AIAgentDataAPI {
555
1090
  | string
556
1091
  | undefined;
557
1092
 
558
- // Get the task to get the project ID
559
- const task: AIAgentTask | null = await AIAgentTaskService.findOneById(
560
- {
561
- id: taskId,
562
- select: {
563
- _id: true,
564
- projectId: true,
565
- },
566
- props: {
567
- isRoot: true,
568
- },
1093
+ /*
1094
+ * `taskId` carries the AIRun id of the code-fix run — get the run
1095
+ * for the project ID and so the PR can be recorded on its trail.
1096
+ */
1097
+ const run: AIRun | null = await AIRunService.findOneById({
1098
+ id: taskId,
1099
+ select: {
1100
+ _id: true,
1101
+ projectId: true,
569
1102
  },
570
- );
1103
+ props: {
1104
+ isRoot: true,
1105
+ },
1106
+ });
571
1107
 
572
- if (!task) {
1108
+ if (!run) {
573
1109
  return Response.sendErrorResponse(
574
1110
  req,
575
1111
  res,
@@ -595,11 +1131,11 @@ export default class AIAgentDataAPI {
595
1131
  const pullRequest: AIAgentTaskPullRequest =
596
1132
  new AIAgentTaskPullRequest();
597
1133
 
598
- if (task.projectId) {
599
- pullRequest.projectId = task.projectId;
1134
+ if (run.projectId) {
1135
+ pullRequest.projectId = run.projectId;
600
1136
  }
601
1137
 
602
- pullRequest.aiAgentTaskId = taskId;
1138
+ pullRequest.aiRunId = taskId;
603
1139
  pullRequest.aiAgentId = aiAgent.id!;
604
1140
  pullRequest.codeRepositoryId = codeRepositoryId;
605
1141
  pullRequest.pullRequestUrl = URL.fromString(pullRequestUrl);
@@ -644,8 +1180,24 @@ export default class AIAgentDataAPI {
644
1180
  },
645
1181
  });
646
1182
 
1183
+ /*
1184
+ * The pull request is the run's headline action — record it on
1185
+ * the run's glass-box trail so the activity feed shows it.
1186
+ */
1187
+ if (run.projectId) {
1188
+ await AIRunEventService.appendEventToRun({
1189
+ projectId: run.projectId,
1190
+ aiRunId: taskId,
1191
+ eventType: AIRunEventType.ActionExecuted,
1192
+ toolName: "open_pull_request",
1193
+ resultSummary: {
1194
+ message: `Opened pull request: ${title} — ${pullRequestUrl}`,
1195
+ },
1196
+ });
1197
+ }
1198
+
647
1199
  logger.debug(
648
- `Recorded pull request ${pullRequestUrl} for task ${taskId.toString()}`,
1200
+ `Recorded pull request ${pullRequestUrl} for run ${taskId.toString()}`,
649
1201
  getLogAttributesFromRequest(req as any),
650
1202
  );
651
1203
 
@@ -660,6 +1212,116 @@ export default class AIAgentDataAPI {
660
1212
  );
661
1213
  }
662
1214
 
1215
+ /*
1216
+ * Parse the completion request's messages into the LLMMessage shape —
1217
+ * strict on structure (role whitelist, string content) so malformed
1218
+ * worker payloads fail with a clear 4xx instead of a provider error.
1219
+ */
1220
+ private parseCompletionMessages(raw: unknown): Array<LLMMessage> {
1221
+ if (!Array.isArray(raw) || raw.length === 0) {
1222
+ throw new BadDataException("messages must be a non-empty array");
1223
+ }
1224
+
1225
+ const validRoles: Array<string> = ["system", "user", "assistant", "tool"];
1226
+
1227
+ return raw.map((entry: unknown, index: number): LLMMessage => {
1228
+ if (!entry || typeof entry !== "object") {
1229
+ throw new BadDataException(`messages[${index}] must be an object`);
1230
+ }
1231
+
1232
+ const messageObject: JSONObject = entry as JSONObject;
1233
+ const role: string = messageObject["role"] as string;
1234
+
1235
+ if (!validRoles.includes(role)) {
1236
+ throw new BadDataException(
1237
+ `messages[${index}].role must be one of: ${validRoles.join(", ")}`,
1238
+ );
1239
+ }
1240
+
1241
+ const message: LLMMessage = {
1242
+ role: role as LLMMessage["role"],
1243
+ content:
1244
+ typeof messageObject["content"] === "string"
1245
+ ? (messageObject["content"] as string)
1246
+ : "",
1247
+ };
1248
+
1249
+ if (Array.isArray(messageObject["toolCalls"])) {
1250
+ message.toolCalls = (
1251
+ messageObject["toolCalls"] as Array<JSONObject>
1252
+ ).map((toolCall: JSONObject, toolCallIndex: number): LLMToolCall => {
1253
+ if (
1254
+ typeof toolCall["id"] !== "string" ||
1255
+ typeof toolCall["name"] !== "string"
1256
+ ) {
1257
+ throw new BadDataException(
1258
+ `messages[${index}].toolCalls[${toolCallIndex}] must carry string id and name`,
1259
+ );
1260
+ }
1261
+
1262
+ return {
1263
+ id: toolCall["id"] as string,
1264
+ name: toolCall["name"] as string,
1265
+ arguments:
1266
+ toolCall["arguments"] &&
1267
+ typeof toolCall["arguments"] === "object" &&
1268
+ !Array.isArray(toolCall["arguments"])
1269
+ ? (toolCall["arguments"] as JSONObject)
1270
+ : {},
1271
+ };
1272
+ });
1273
+ }
1274
+
1275
+ if (typeof messageObject["toolCallId"] === "string") {
1276
+ message.toolCallId = messageObject["toolCallId"] as string;
1277
+ }
1278
+
1279
+ return message;
1280
+ });
1281
+ }
1282
+
1283
+ // Parse the completion request's tool definitions (optional).
1284
+ private parseCompletionTools(
1285
+ raw: unknown,
1286
+ ): Array<LLMToolDefinition> | undefined {
1287
+ if (raw === undefined || raw === null) {
1288
+ return undefined;
1289
+ }
1290
+
1291
+ if (!Array.isArray(raw)) {
1292
+ throw new BadDataException("tools must be an array when provided");
1293
+ }
1294
+
1295
+ if (raw.length === 0) {
1296
+ return undefined;
1297
+ }
1298
+
1299
+ return raw.map((entry: unknown, index: number): LLMToolDefinition => {
1300
+ if (!entry || typeof entry !== "object") {
1301
+ throw new BadDataException(`tools[${index}] must be an object`);
1302
+ }
1303
+
1304
+ const toolObject: JSONObject = entry as JSONObject;
1305
+
1306
+ if (
1307
+ typeof toolObject["name"] !== "string" ||
1308
+ typeof toolObject["description"] !== "string" ||
1309
+ !toolObject["inputSchema"] ||
1310
+ typeof toolObject["inputSchema"] !== "object"
1311
+ ) {
1312
+ throw new BadDataException(
1313
+ `tools[${index}] must carry string name, string description and an inputSchema object`,
1314
+ );
1315
+ }
1316
+
1317
+ return {
1318
+ name: toolObject["name"] as string,
1319
+ description: toolObject["description"] as string,
1320
+ inputSchema: toolObject["inputSchema"] as JSONObject,
1321
+ };
1322
+ });
1323
+ }
1324
+
663
1325
  // Validate AI Agent credentials from request body
664
1326
  private async validateAIAgent(data: JSONObject): Promise<AIAgent | null> {
665
1327
  if (!data["aiAgentId"] || !data["aiAgentKey"]) {