@oneuptime/common 11.5.3 → 11.5.5
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.
- package/Models/DatabaseModels/AIAgentTaskPullRequest.ts +56 -45
- package/Models/DatabaseModels/AIInsight.ts +748 -0
- package/Models/DatabaseModels/AIRun.ts +262 -0
- package/Models/DatabaseModels/CodeRepository.ts +42 -0
- package/Models/DatabaseModels/Dashboard.ts +3 -3
- package/Models/DatabaseModels/GlobalConfig.ts +105 -0
- package/Models/DatabaseModels/Index.ts +4 -8
- package/Models/DatabaseModels/InstanceHealthLog.ts +277 -0
- package/Models/DatabaseModels/LlmLog.ts +33 -0
- package/Models/DatabaseModels/Project.ts +123 -6
- package/Models/DatabaseModels/Runbook.ts +1 -1
- package/Server/API/AIAgentDataAPI.ts +802 -140
- package/Server/API/AIAgentTaskAPI.ts +132 -69
- package/Server/API/AIAgentTaskLogAPI.ts +65 -41
- package/Server/API/AIAgentTaskPullRequestAPI.ts +41 -0
- package/Server/API/AIInsightAPI.ts +220 -0
- package/Server/API/AIInvestigationAPI.ts +363 -1
- package/Server/API/CodeFixRunAPI.ts +251 -0
- package/Server/API/GitHubAPI.ts +246 -3
- package/Server/API/TelemetryExceptionAPI.ts +193 -48
- package/Server/EnvironmentConfig.ts +1 -1
- package/Server/Infrastructure/Postgres/SchemaMigrations/1783943300000-DropServiceCodeRepository.ts +26 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1783947444597-CodeFixRunsOnAIRun.ts +73 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1783950962813-AddCodeFixTaskType.ts +29 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1783954040984-AddInstrumentationFixTasksFlag.ts +31 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1783957160597-MigrationName.ts +51 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1783958542237-AddTaskContextToAIRun.ts +25 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1783965945957-AddInvestigationVerdictAndGrade.ts +47 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1783970619301-AddFixGuardrailColumns.ts +53 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1783970619302-DropLegacyAIAgentTaskTables.ts +31 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1783977781677-AddCiStatusToFixPullRequests.ts +37 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1783990000000-AddCompletionTokensToLlmLog.ts +25 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1784010274993-AddSentinelInsight.ts +75 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1784010274994-AddSentinelInsightFlags.ts +37 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1784030612266-RenameSentinelToAI.ts +203 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1784033837629-MigrationName.ts +163 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +30 -0
- package/Server/Infrastructure/Queue.ts +82 -4
- package/Server/Infrastructure/Semaphore.ts +62 -1
- package/Server/Services/AIAgentService.ts +32 -0
- package/Server/Services/AIAgentTaskPullRequestService.ts +117 -0
- package/Server/Services/AIInsightService.ts +174 -0
- package/Server/Services/AIRunEventService.ts +63 -0
- package/Server/Services/AIRunService.ts +259 -1
- package/Server/Services/AIService.ts +249 -7
- package/Server/Services/AlertService.ts +4 -4
- package/Server/Services/CodeRepositoryService.ts +209 -0
- package/Server/Services/DashboardService.ts +11 -2
- package/Server/Services/GlobalConfigService.ts +148 -0
- package/Server/Services/IncidentService.ts +183 -38
- package/Server/Services/IncidentStateTimelineService.ts +24 -4
- package/Server/Services/Index.ts +4 -4
- package/Server/Services/{AIAgentTaskLogService.ts → InstanceHealthLogService.ts} +1 -1
- package/Server/Services/LlmLogService.ts +27 -0
- package/Server/Services/LlmProviderService.ts +108 -0
- package/Server/Services/MetricBaselineService.ts +123 -0
- package/Server/Services/MonitorService.ts +15 -0
- package/Server/Services/TelemetryExceptionService.ts +323 -116
- package/Server/Services/TraceAggregationService.ts +176 -0
- package/Server/Types/Workflow/ComponentCode.ts +6 -0
- package/Server/Types/Workflow/Components/AI/GenerateText.ts +326 -0
- package/Server/Types/Workflow/Components/Index.ts +2 -0
- package/Server/Utils/AI/Chat/ObservabilityAssistant.ts +1 -1
- package/Server/Utils/AI/CodeFix/CodeAgentWorkspaceGuard.ts +71 -0
- package/Server/Utils/AI/CodeFix/CodeFixAgentCompletion.ts +243 -0
- package/Server/Utils/AI/CodeFix/CodeFixRunQueue.ts +131 -0
- package/Server/Utils/AI/CodeFix/FixRunBudget.ts +148 -0
- package/Server/Utils/AI/CodeFix/OpenPullRequestCap.ts +117 -0
- package/Server/Utils/AI/Eval/EvalCorpus.ts +369 -0
- package/Server/Utils/AI/Eval/EvalScores.ts +172 -0
- package/Server/Utils/AI/Eval/ReplayInvestigation.ts +87 -0
- package/Server/Utils/AI/PerfEvidence/SpanTreeAnalyzer.ts +676 -0
- package/Server/Utils/AI/{Sentinel/SentinelInvestigationEngine.ts → SRE/AIInvestigationEngine.ts} +58 -37
- package/Server/Utils/AI/{Sentinel/SentinelMemory.ts → SRE/AIMemory.ts} +3 -3
- package/Server/Utils/AI/{Sentinel → SRE}/AlertInvestigationRunner.ts +50 -20
- package/Server/Utils/AI/SRE/ConfidenceSignal.ts +293 -0
- package/Server/Utils/AI/SRE/FixFromIncidentTaskTrigger.ts +115 -0
- package/Server/Utils/AI/SRE/FixPerformanceTaskTrigger.ts +223 -0
- package/Server/Utils/AI/{Sentinel → SRE}/IncidentInvestigationRunner.ts +71 -21
- package/Server/Utils/AI/{Sentinel → SRE}/IncidentPostmortemRunner.ts +8 -8
- package/Server/Utils/AI/SRE/Insights/Detectors/ErrorLogSpikeDetector.ts +364 -0
- package/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.ts +317 -0
- package/Server/Utils/AI/SRE/Insights/Detectors/Index.ts +27 -0
- package/Server/Utils/AI/SRE/Insights/Detectors/MetricDriftDetector.ts +221 -0
- package/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.ts +238 -0
- package/Server/Utils/AI/SRE/Insights/Detectors/TraceLatencyRegressionDetector.ts +521 -0
- package/Server/Utils/AI/SRE/Insights/FixRouting.ts +242 -0
- package/Server/Utils/AI/SRE/Insights/InsightScanner.ts +290 -0
- package/Server/Utils/AI/SRE/Insights/InsightStore.ts +283 -0
- package/Server/Utils/AI/SRE/Insights/InsightTriageRunner.ts +242 -0
- package/Server/Utils/AI/SRE/Insights/Triage.ts +162 -0
- package/Server/Utils/AI/SRE/Insights/Types.ts +49 -0
- package/Server/Utils/AI/SRE/InstrumentationTaskTrigger.ts +212 -0
- package/Server/Utils/AI/SRE/InvestigationGrader.ts +282 -0
- package/Server/Utils/AI/{Sentinel → SRE}/InvestigationQueue.ts +114 -19
- package/Server/Utils/AI/{Sentinel → SRE}/README.md +4 -4
- package/Server/Utils/AI/SRE/SubjectCodeFixRun.ts +172 -0
- package/Server/Utils/AI/Toolbox/{SentinelActionTools.ts → AIActionTools.ts} +22 -1
- package/Server/Utils/AI/Toolbox/Index.ts +2 -2
- package/Server/Utils/AnalyticsDatabase/ClickhouseCapacity.ts +526 -0
- package/Server/Utils/CodeRepository/GitHub/GitHub.ts +319 -1
- package/Server/Utils/CodeRepository/ServiceRepoLinkSuggester.ts +221 -0
- package/Server/Utils/CodeRepository/StackTraceRepoResolver.ts +571 -0
- package/Server/Utils/Execute.ts +34 -13
- package/Server/Utils/LLM/LLMService.ts +160 -30
- package/Server/Utils/Monitor/Criteria/SqlMonitorCriteria.ts +152 -0
- package/Server/Utils/Monitor/MonitorCriteriaEvaluator.ts +29 -0
- package/Tests/Server/API/DashboardMasterPasswordAPI.test.ts +225 -0
- package/Tests/Server/Infrastructure/Queue.test.ts +227 -0
- package/Tests/Server/Infrastructure/SemaphorePermit.test.ts +159 -0
- package/Tests/Server/Services/AIAgentTaskPullRequestOutcomeStats.test.ts +154 -0
- package/Tests/Server/Services/AIInsightService.test.ts +324 -0
- package/Tests/Server/Services/AIRunCodeFixClaim.test.ts +401 -0
- package/Tests/Server/Services/AIRunHumanVerdict.test.ts +161 -0
- package/Tests/Server/Services/AIServiceDailyBudget.test.ts +95 -5
- package/Tests/Server/Services/AIServiceProjectAccess.test.ts +259 -0
- package/Tests/Server/Services/FixFromIncidentTaskTrigger.test.ts +249 -0
- package/Tests/Server/Services/FixPerformanceTaskTrigger.test.ts +274 -0
- package/Tests/Server/Services/GlobalConfigService.test.ts +80 -0
- package/Tests/Server/Services/IncidentInternalNoteAnnouncement.test.ts +1 -1
- package/Tests/Server/Services/InstrumentationTaskTrigger.test.ts +313 -0
- package/Tests/Server/Services/LlmProviderProjectOwned.test.ts +132 -0
- package/Tests/Server/Services/TelemetryExceptionAIFixReadiness.test.ts +405 -0
- package/Tests/Server/Services/TelemetryExceptionCodeFixRun.test.ts +322 -0
- package/Tests/Server/Services/TraceServiceLatencyProfile.test.ts +278 -0
- package/Tests/Server/Types/Workflow/Components/AIGenerateText.test.ts +722 -0
- package/Tests/Server/Utils/AI/{SentinelAlertGating.test.ts → AIAlertGating.test.ts} +19 -19
- package/Tests/Server/Utils/AI/AIConfidenceSignal.test.ts +362 -0
- package/Tests/Server/Utils/AI/{SentinelInvestigationQueue.test.ts → AIInvestigationQueue.test.ts} +19 -19
- package/Tests/Server/Utils/AI/CodeAgentWorkspaceGuard.test.ts +138 -0
- package/Tests/Server/Utils/AI/CodeFixAgentCompletion.test.ts +335 -0
- package/Tests/Server/Utils/AI/CodeFixRunQueue.test.ts +134 -0
- package/Tests/Server/Utils/AI/EvalCorpus.test.ts +209 -0
- package/Tests/Server/Utils/AI/EvalScores.test.ts +343 -0
- package/Tests/Server/Utils/AI/FixRunBudget.test.ts +218 -0
- package/Tests/Server/Utils/AI/Insights/ErrorLogSpikeDetector.test.ts +437 -0
- package/Tests/Server/Utils/AI/Insights/ExceptionSpikeDetector.test.ts +287 -0
- package/Tests/Server/Utils/AI/Insights/InsightDetectorsIndex.test.ts +34 -0
- package/Tests/Server/Utils/AI/Insights/InsightFixRouting.test.ts +572 -0
- package/Tests/Server/Utils/AI/Insights/InsightNeverThrowsHardening.test.ts +344 -0
- package/Tests/Server/Utils/AI/Insights/InsightScanner.test.ts +720 -0
- package/Tests/Server/Utils/AI/Insights/InsightStore.test.ts +467 -0
- package/Tests/Server/Utils/AI/Insights/InsightStoreHardening.test.ts +370 -0
- package/Tests/Server/Utils/AI/Insights/InsightTriage.test.ts +210 -0
- package/Tests/Server/Utils/AI/Insights/InsightTriageRunner.test.ts +221 -0
- package/Tests/Server/Utils/AI/Insights/InvestigationQueueInsightSubject.test.ts +328 -0
- package/Tests/Server/Utils/AI/Insights/MetricBaselineDrift.test.ts +182 -0
- package/Tests/Server/Utils/AI/Insights/MetricDriftDetector.test.ts +280 -0
- package/Tests/Server/Utils/AI/Insights/NewExceptionDetector.test.ts +259 -0
- package/Tests/Server/Utils/AI/Insights/TraceLatencyRegressionDetector.test.ts +770 -0
- package/Tests/Server/Utils/AI/InvestigationGrader.test.ts +343 -0
- package/Tests/Server/Utils/AI/LLMServiceRequestPolicy.test.ts +307 -0
- package/Tests/Server/Utils/AI/OpenPullRequestCap.test.ts +170 -0
- package/Tests/Server/Utils/AI/SpanTreeAnalyzer.test.ts +559 -0
- package/Tests/Server/Utils/AnalyticsDatabase/ClickhouseCapacity.test.ts +158 -0
- package/Tests/Server/Utils/GitHubCheckRunsConclusion.test.ts +100 -0
- package/Tests/Server/Utils/GitHubPullRequestStateMapping.test.ts +50 -0
- package/Tests/Server/Utils/Monitor/Criteria/SqlMonitorCriteria.test.ts +266 -0
- package/Tests/Server/Utils/ServiceRepoLinkSuggester.test.ts +167 -0
- package/Tests/Server/Utils/StackTraceRepoResolver.test.ts +527 -0
- package/Tests/Types/AI/AIChatPermissionMode.test.ts +112 -0
- package/Tests/Types/AI/CodeFixTaskType.test.ts +152 -0
- package/Tests/Types/AI/FixPullRequestCiStatus.test.ts +181 -0
- package/Tests/Types/Monitor/MonitorStepSqlMonitor.test.ts +110 -0
- package/Tests/Types/Monitor/SqlDatabaseType.test.ts +55 -0
- package/Tests/Types/Workflow/AIGenerateTextMetadata.test.ts +180 -0
- package/Tests/UI/Components/TableBulkCsvExport.test.tsx +168 -0
- package/Tests/UI/Utils/TableColumnsToCsv.test.ts +523 -0
- package/Types/AI/AIChatTypes.ts +8 -0
- package/Types/AI/AIInsightEvidence.ts +77 -0
- package/Types/AI/AIInsightHumanVerdict.ts +15 -0
- package/Types/AI/AIInsightSeverity.ts +13 -0
- package/Types/AI/AIInsightStatus.ts +38 -0
- package/Types/AI/AIInsightType.ts +41 -0
- package/Types/AI/AIRunAutoGrade.ts +18 -0
- package/Types/AI/AIRunEventType.ts +5 -0
- package/Types/AI/AIRunHumanVerdict.ts +17 -0
- package/Types/AI/AIRunType.ts +6 -0
- package/Types/AI/CodeFixTaskContext.ts +88 -0
- package/Types/AI/CodeFixTaskType.ts +132 -0
- package/Types/AI/FixPullRequestCiStatus.ts +132 -0
- package/Types/BaseDatabase/AggregationIntervalUtil.ts +67 -0
- package/Types/Incident/IncidentMetricType.ts +7 -0
- package/Types/Monitor/CriteriaFilter.ts +8 -0
- package/Types/Monitor/MonitorCriteriaInstance.ts +67 -0
- package/Types/Monitor/MonitorStep.ts +38 -0
- package/Types/Monitor/MonitorStepSqlMonitor.ts +141 -0
- package/Types/Monitor/MonitorType.ts +17 -0
- package/Types/Monitor/SqlDatabaseType.ts +49 -0
- package/Types/Monitor/SqlMonitor/SqlMonitorResponse.ts +28 -0
- package/Types/Permission.ts +11 -95
- package/Types/Probe/ProbeMonitorResponse.ts +2 -0
- package/Types/Runbook/RunbookStep.ts +26 -2
- package/Types/Runbook/RunbookStepType.ts +1 -0
- package/Types/Workflow/Component.ts +13 -0
- package/Types/Workflow/ComponentID.ts +1 -0
- package/Types/Workflow/Components/AI.ts +148 -0
- package/Types/Workflow/Components.ts +8 -0
- package/UI/Components/AI/GenerateFromAIModal.tsx +1 -1
- package/UI/Components/Markdown.tsx/MarkdownViewer.tsx +11 -0
- package/UI/Components/MoreMenu/MoreMenu.tsx +1 -1
- package/UI/Components/Table/Table.tsx +38 -2
- package/UI/Utils/TableColumnsToCsv.ts +385 -0
- package/Utils/Monitor/MonitorMetricType.ts +1 -0
- package/build/dist/Models/DatabaseModels/AIAgentTaskPullRequest.js +59 -45
- package/build/dist/Models/DatabaseModels/AIAgentTaskPullRequest.js.map +1 -1
- package/build/dist/Models/DatabaseModels/AIInsight.js +795 -0
- package/build/dist/Models/DatabaseModels/AIInsight.js.map +1 -0
- package/build/dist/Models/DatabaseModels/AIRun.js +274 -0
- package/build/dist/Models/DatabaseModels/AIRun.js.map +1 -1
- package/build/dist/Models/DatabaseModels/CodeRepository.js +43 -0
- package/build/dist/Models/DatabaseModels/CodeRepository.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Dashboard.js +3 -3
- package/build/dist/Models/DatabaseModels/Dashboard.js.map +1 -1
- package/build/dist/Models/DatabaseModels/GlobalConfig.js +110 -0
- package/build/dist/Models/DatabaseModels/GlobalConfig.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Index.js +4 -8
- package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
- package/build/dist/Models/DatabaseModels/InstanceHealthLog.js +304 -0
- package/build/dist/Models/DatabaseModels/InstanceHealthLog.js.map +1 -0
- package/build/dist/Models/DatabaseModels/LlmLog.js +35 -0
- package/build/dist/Models/DatabaseModels/LlmLog.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Project.js +127 -6
- package/build/dist/Models/DatabaseModels/Project.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Runbook.js +1 -1
- package/build/dist/Models/DatabaseModels/Runbook.js.map +1 -1
- package/build/dist/Server/API/AIAgentDataAPI.js +568 -85
- package/build/dist/Server/API/AIAgentDataAPI.js.map +1 -1
- package/build/dist/Server/API/AIAgentTaskAPI.js +100 -44
- package/build/dist/Server/API/AIAgentTaskAPI.js.map +1 -1
- package/build/dist/Server/API/AIAgentTaskLogAPI.js +49 -25
- package/build/dist/Server/API/AIAgentTaskLogAPI.js.map +1 -1
- package/build/dist/Server/API/AIAgentTaskPullRequestAPI.js +27 -0
- package/build/dist/Server/API/AIAgentTaskPullRequestAPI.js.map +1 -1
- package/build/dist/Server/API/AIInsightAPI.js +140 -0
- package/build/dist/Server/API/AIInsightAPI.js.map +1 -0
- package/build/dist/Server/API/AIInvestigationAPI.js +257 -1
- package/build/dist/Server/API/AIInvestigationAPI.js.map +1 -1
- package/build/dist/Server/API/CodeFixRunAPI.js +181 -0
- package/build/dist/Server/API/CodeFixRunAPI.js.map +1 -0
- package/build/dist/Server/API/GitHubAPI.js +164 -2
- package/build/dist/Server/API/GitHubAPI.js.map +1 -1
- package/build/dist/Server/API/TelemetryExceptionAPI.js +148 -43
- package/build/dist/Server/API/TelemetryExceptionAPI.js.map +1 -1
- package/build/dist/Server/EnvironmentConfig.js +1 -1
- package/build/dist/Server/EnvironmentConfig.js.map +1 -1
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783943300000-DropServiceCodeRepository.js +23 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783943300000-DropServiceCodeRepository.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783947444597-CodeFixRunsOnAIRun.js +32 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783947444597-CodeFixRunsOnAIRun.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783950962813-AddCodeFixTaskType.js +16 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783950962813-AddCodeFixTaskType.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783954040984-AddInstrumentationFixTasksFlag.js +16 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783954040984-AddInstrumentationFixTasksFlag.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783957160597-MigrationName.js +24 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783957160597-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783958542237-AddTaskContextToAIRun.js +16 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783958542237-AddTaskContextToAIRun.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783965945957-AddInvestigationVerdictAndGrade.js +24 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783965945957-AddInvestigationVerdictAndGrade.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783970619301-AddFixGuardrailColumns.js +24 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783970619301-AddFixGuardrailColumns.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783970619302-DropLegacyAIAgentTaskTables.js +24 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783970619302-DropLegacyAIAgentTaskTables.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783977781677-AddCiStatusToFixPullRequests.js +18 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783977781677-AddCiStatusToFixPullRequests.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783990000000-AddCompletionTokensToLlmLog.js +18 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783990000000-AddCompletionTokensToLlmLog.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784010274993-AddSentinelInsight.js +32 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784010274993-AddSentinelInsight.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784010274994-AddSentinelInsightFlags.js +18 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784010274994-AddSentinelInsightFlags.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784030612266-RenameSentinelToAI.js +125 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784030612266-RenameSentinelToAI.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784033837629-MigrationName.js +62 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784033837629-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +30 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Infrastructure/Queue.js +73 -3
- package/build/dist/Server/Infrastructure/Queue.js.map +1 -1
- package/build/dist/Server/Infrastructure/Semaphore.js +44 -1
- package/build/dist/Server/Infrastructure/Semaphore.js.map +1 -1
- package/build/dist/Server/Services/AIAgentService.js +29 -0
- package/build/dist/Server/Services/AIAgentService.js.map +1 -1
- package/build/dist/Server/Services/AIAgentTaskPullRequestService.js +78 -0
- package/build/dist/Server/Services/AIAgentTaskPullRequestService.js.map +1 -1
- package/build/dist/Server/Services/AIInsightService.js +164 -0
- package/build/dist/Server/Services/AIInsightService.js.map +1 -0
- package/build/dist/Server/Services/AIRunEventService.js +49 -0
- package/build/dist/Server/Services/AIRunEventService.js.map +1 -1
- package/build/dist/Server/Services/AIRunService.js +221 -0
- package/build/dist/Server/Services/AIRunService.js.map +1 -1
- package/build/dist/Server/Services/AIService.js +198 -11
- package/build/dist/Server/Services/AIService.js.map +1 -1
- package/build/dist/Server/Services/AlertService.js +4 -4
- package/build/dist/Server/Services/AlertService.js.map +1 -1
- package/build/dist/Server/Services/CodeRepositoryService.js +180 -0
- package/build/dist/Server/Services/CodeRepositoryService.js.map +1 -1
- package/build/dist/Server/Services/DashboardService.js +8 -2
- package/build/dist/Server/Services/DashboardService.js.map +1 -1
- package/build/dist/Server/Services/GlobalConfigService.js +84 -0
- package/build/dist/Server/Services/GlobalConfigService.js.map +1 -1
- package/build/dist/Server/Services/IncidentService.js +149 -37
- package/build/dist/Server/Services/IncidentService.js.map +1 -1
- package/build/dist/Server/Services/IncidentStateTimelineService.js +24 -4
- package/build/dist/Server/Services/IncidentStateTimelineService.js.map +1 -1
- package/build/dist/Server/Services/Index.js +4 -4
- package/build/dist/Server/Services/Index.js.map +1 -1
- package/build/dist/Server/Services/{AIAgentTaskLogService.js → InstanceHealthLogService.js} +2 -2
- package/build/dist/Server/Services/InstanceHealthLogService.js.map +1 -0
- package/build/dist/Server/Services/LlmLogService.js +23 -0
- package/build/dist/Server/Services/LlmLogService.js.map +1 -1
- package/build/dist/Server/Services/LlmProviderService.js +96 -0
- package/build/dist/Server/Services/LlmProviderService.js.map +1 -1
- package/build/dist/Server/Services/MetricBaselineService.js +65 -0
- package/build/dist/Server/Services/MetricBaselineService.js.map +1 -1
- package/build/dist/Server/Services/MonitorService.js +9 -1
- package/build/dist/Server/Services/MonitorService.js.map +1 -1
- package/build/dist/Server/Services/TelemetryExceptionService.js +243 -82
- package/build/dist/Server/Services/TelemetryExceptionService.js.map +1 -1
- package/build/dist/Server/Services/TraceAggregationService.js +124 -0
- package/build/dist/Server/Services/TraceAggregationService.js.map +1 -1
- package/build/dist/Server/Types/Workflow/ComponentCode.js.map +1 -1
- package/build/dist/Server/Types/Workflow/Components/AI/GenerateText.js +240 -0
- package/build/dist/Server/Types/Workflow/Components/AI/GenerateText.js.map +1 -0
- package/build/dist/Server/Types/Workflow/Components/Index.js +2 -0
- package/build/dist/Server/Types/Workflow/Components/Index.js.map +1 -1
- package/build/dist/Server/Utils/AI/CodeFix/CodeAgentWorkspaceGuard.js +48 -0
- package/build/dist/Server/Utils/AI/CodeFix/CodeAgentWorkspaceGuard.js.map +1 -0
- package/build/dist/Server/Utils/AI/CodeFix/CodeFixAgentCompletion.js +174 -0
- package/build/dist/Server/Utils/AI/CodeFix/CodeFixAgentCompletion.js.map +1 -0
- package/build/dist/Server/Utils/AI/CodeFix/CodeFixRunQueue.js +126 -0
- package/build/dist/Server/Utils/AI/CodeFix/CodeFixRunQueue.js.map +1 -0
- package/build/dist/Server/Utils/AI/CodeFix/FixRunBudget.js +131 -0
- package/build/dist/Server/Utils/AI/CodeFix/FixRunBudget.js.map +1 -0
- package/build/dist/Server/Utils/AI/CodeFix/OpenPullRequestCap.js +99 -0
- package/build/dist/Server/Utils/AI/CodeFix/OpenPullRequestCap.js.map +1 -0
- package/build/dist/Server/Utils/AI/Eval/EvalCorpus.js +245 -0
- package/build/dist/Server/Utils/AI/Eval/EvalCorpus.js.map +1 -0
- package/build/dist/Server/Utils/AI/Eval/EvalScores.js +83 -0
- package/build/dist/Server/Utils/AI/Eval/EvalScores.js.map +1 -0
- package/build/dist/Server/Utils/AI/Eval/ReplayInvestigation.js +12 -0
- package/build/dist/Server/Utils/AI/Eval/ReplayInvestigation.js.map +1 -0
- package/build/dist/Server/Utils/AI/PerfEvidence/SpanTreeAnalyzer.js +439 -0
- package/build/dist/Server/Utils/AI/PerfEvidence/SpanTreeAnalyzer.js.map +1 -0
- package/build/dist/Server/Utils/AI/{Sentinel/SentinelInvestigationEngine.js → SRE/AIInvestigationEngine.js} +47 -31
- package/build/dist/Server/Utils/AI/SRE/AIInvestigationEngine.js.map +1 -0
- package/build/dist/Server/Utils/AI/{Sentinel/SentinelMemory.js → SRE/AIMemory.js} +5 -5
- package/build/dist/Server/Utils/AI/SRE/AIMemory.js.map +1 -0
- package/build/dist/Server/Utils/AI/{Sentinel → SRE}/AlertInvestigationRunner.js +42 -19
- package/build/dist/Server/Utils/AI/SRE/AlertInvestigationRunner.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/ConfidenceSignal.js +226 -0
- package/build/dist/Server/Utils/AI/SRE/ConfidenceSignal.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/FixFromIncidentTaskTrigger.js +100 -0
- package/build/dist/Server/Utils/AI/SRE/FixFromIncidentTaskTrigger.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/FixPerformanceTaskTrigger.js +174 -0
- package/build/dist/Server/Utils/AI/SRE/FixPerformanceTaskTrigger.js.map +1 -0
- package/build/dist/Server/Utils/AI/{Sentinel → SRE}/IncidentInvestigationRunner.js +60 -22
- package/build/dist/Server/Utils/AI/SRE/IncidentInvestigationRunner.js.map +1 -0
- package/build/dist/Server/Utils/AI/{Sentinel → SRE}/IncidentPostmortemRunner.js +9 -9
- package/build/dist/Server/Utils/AI/SRE/IncidentPostmortemRunner.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ErrorLogSpikeDetector.js +268 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ErrorLogSpikeDetector.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.js +226 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/Index.js +26 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/Index.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/MetricDriftDetector.js +159 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/MetricDriftDetector.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.js +177 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/TraceLatencyRegressionDetector.js +384 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/TraceLatencyRegressionDetector.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/FixRouting.js +180 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/FixRouting.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/InsightScanner.js +269 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/InsightScanner.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/InsightStore.js +231 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/InsightStore.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/InsightTriageRunner.js +206 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/InsightTriageRunner.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Triage.js +121 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Triage.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Types.js +2 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Types.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/InstrumentationTaskTrigger.js +148 -0
- package/build/dist/Server/Utils/AI/SRE/InstrumentationTaskTrigger.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/InvestigationGrader.js +231 -0
- package/build/dist/Server/Utils/AI/SRE/InvestigationGrader.js.map +1 -0
- package/build/dist/Server/Utils/AI/{Sentinel → SRE}/InvestigationQueue.js +102 -23
- package/build/dist/Server/Utils/AI/SRE/InvestigationQueue.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/SubjectCodeFixRun.js +167 -0
- package/build/dist/Server/Utils/AI/SRE/SubjectCodeFixRun.js.map +1 -0
- package/build/dist/Server/Utils/AI/Toolbox/{SentinelActionTools.js → AIActionTools.js} +18 -2
- package/build/dist/Server/Utils/AI/Toolbox/AIActionTools.js.map +1 -0
- package/build/dist/Server/Utils/AI/Toolbox/Index.js +2 -2
- package/build/dist/Server/Utils/AI/Toolbox/Index.js.map +1 -1
- package/build/dist/Server/Utils/AnalyticsDatabase/ClickhouseCapacity.js +301 -0
- package/build/dist/Server/Utils/AnalyticsDatabase/ClickhouseCapacity.js.map +1 -0
- package/build/dist/Server/Utils/CodeRepository/GitHub/GitHub.js +240 -2
- package/build/dist/Server/Utils/CodeRepository/GitHub/GitHub.js.map +1 -1
- package/build/dist/Server/Utils/CodeRepository/ServiceRepoLinkSuggester.js +127 -0
- package/build/dist/Server/Utils/CodeRepository/ServiceRepoLinkSuggester.js.map +1 -0
- package/build/dist/Server/Utils/CodeRepository/StackTraceRepoResolver.js +336 -0
- package/build/dist/Server/Utils/CodeRepository/StackTraceRepoResolver.js.map +1 -0
- package/build/dist/Server/Utils/Execute.js +21 -11
- package/build/dist/Server/Utils/Execute.js.map +1 -1
- package/build/dist/Server/Utils/LLM/LLMService.js +125 -25
- package/build/dist/Server/Utils/LLM/LLMService.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/Criteria/SqlMonitorCriteria.js +120 -0
- package/build/dist/Server/Utils/Monitor/Criteria/SqlMonitorCriteria.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaEvaluator.js +21 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaEvaluator.js.map +1 -1
- package/build/dist/Types/AI/AIInsightEvidence.js +2 -0
- package/build/dist/Types/AI/AIInsightEvidence.js.map +1 -0
- package/build/dist/Types/AI/AIInsightHumanVerdict.js +16 -0
- package/build/dist/Types/AI/AIInsightHumanVerdict.js.map +1 -0
- package/build/dist/Types/AI/AIInsightSeverity.js +14 -0
- package/build/dist/Types/AI/AIInsightSeverity.js.map +1 -0
- package/build/dist/Types/AI/AIInsightStatus.js +36 -0
- package/build/dist/Types/AI/AIInsightStatus.js.map +1 -0
- package/build/dist/Types/AI/AIInsightType.js +42 -0
- package/build/dist/Types/AI/AIInsightType.js.map +1 -0
- package/build/dist/Types/AI/AIRunAutoGrade.js +19 -0
- package/build/dist/Types/AI/AIRunAutoGrade.js.map +1 -0
- package/build/dist/Types/AI/AIRunEventType.js +5 -0
- package/build/dist/Types/AI/AIRunEventType.js.map +1 -1
- package/build/dist/Types/AI/AIRunHumanVerdict.js +18 -0
- package/build/dist/Types/AI/AIRunHumanVerdict.js.map +1 -0
- package/build/dist/Types/AI/AIRunType.js +6 -0
- package/build/dist/Types/AI/AIRunType.js.map +1 -1
- package/build/dist/Types/AI/CodeFixTaskContext.js +29 -0
- package/build/dist/Types/AI/CodeFixTaskContext.js.map +1 -0
- package/build/dist/Types/AI/CodeFixTaskType.js +122 -0
- package/build/dist/Types/AI/CodeFixTaskType.js.map +1 -0
- package/build/dist/Types/AI/FixPullRequestCiStatus.js +102 -0
- package/build/dist/Types/AI/FixPullRequestCiStatus.js.map +1 -0
- package/build/dist/Types/BaseDatabase/AggregationIntervalUtil.js +55 -0
- package/build/dist/Types/BaseDatabase/AggregationIntervalUtil.js.map +1 -1
- package/build/dist/Types/Incident/IncidentMetricType.js +7 -0
- package/build/dist/Types/Incident/IncidentMetricType.js.map +1 -1
- package/build/dist/Types/Monitor/CriteriaFilter.js +7 -0
- package/build/dist/Types/Monitor/CriteriaFilter.js.map +1 -1
- package/build/dist/Types/Monitor/MonitorCriteriaInstance.js +62 -0
- package/build/dist/Types/Monitor/MonitorCriteriaInstance.js.map +1 -1
- package/build/dist/Types/Monitor/MonitorStep.js +28 -0
- package/build/dist/Types/Monitor/MonitorStep.js.map +1 -1
- package/build/dist/Types/Monitor/MonitorStepSqlMonitor.js +93 -0
- package/build/dist/Types/Monitor/MonitorStepSqlMonitor.js.map +1 -0
- package/build/dist/Types/Monitor/MonitorType.js +15 -0
- package/build/dist/Types/Monitor/MonitorType.js.map +1 -1
- package/build/dist/Types/Monitor/SqlDatabaseType.js +47 -0
- package/build/dist/Types/Monitor/SqlDatabaseType.js.map +1 -0
- package/build/dist/Types/Monitor/SqlMonitor/SqlMonitorResponse.js +2 -0
- package/build/dist/Types/Monitor/SqlMonitor/SqlMonitorResponse.js.map +1 -0
- package/build/dist/Types/Permission.js +10 -84
- package/build/dist/Types/Permission.js.map +1 -1
- package/build/dist/Types/Runbook/RunbookStepType.js +1 -0
- package/build/dist/Types/Runbook/RunbookStepType.js.map +1 -1
- package/build/dist/Types/Workflow/ComponentID.js +1 -0
- package/build/dist/Types/Workflow/ComponentID.js.map +1 -1
- package/build/dist/Types/Workflow/Components/AI.js +135 -0
- package/build/dist/Types/Workflow/Components/AI.js.map +1 -0
- package/build/dist/Types/Workflow/Components.js +7 -0
- package/build/dist/Types/Workflow/Components.js.map +1 -1
- package/build/dist/UI/Components/AI/GenerateFromAIModal.js +1 -1
- package/build/dist/UI/Components/AI/GenerateFromAIModal.js.map +1 -1
- package/build/dist/UI/Components/Markdown.tsx/MarkdownViewer.js +9 -0
- package/build/dist/UI/Components/Markdown.tsx/MarkdownViewer.js.map +1 -1
- package/build/dist/UI/Components/MoreMenu/MoreMenu.js +1 -1
- package/build/dist/UI/Components/Table/Table.js +28 -2
- package/build/dist/UI/Components/Table/Table.js.map +1 -1
- package/build/dist/UI/Utils/TableColumnsToCsv.js +291 -0
- package/build/dist/UI/Utils/TableColumnsToCsv.js.map +1 -0
- package/build/dist/Utils/Monitor/MonitorMetricType.js +1 -0
- package/build/dist/Utils/Monitor/MonitorMetricType.js.map +1 -1
- package/package.json +1 -1
- package/Models/DatabaseModels/AIAgentTask.ts +0 -660
- package/Models/DatabaseModels/AIAgentTaskLog.ts +0 -426
- package/Models/DatabaseModels/AIAgentTaskTelemetryException.ts +0 -399
- package/Models/DatabaseModels/ServiceCodeRepository.ts +0 -647
- package/Server/Services/AIAgentTaskService.ts +0 -240
- package/Server/Services/AIAgentTaskTelemetryExceptionService.ts +0 -39
- package/Server/Services/ServiceCodeRepositoryService.ts +0 -55
- package/Tests/Server/Services/AIAgentTaskServiceClaim.test.ts +0 -146
- package/Types/AI/AIAgentTaskMetadata.ts +0 -25
- package/Types/AI/AIAgentTaskType.ts +0 -40
- package/build/dist/Models/DatabaseModels/AIAgentTask.js +0 -691
- package/build/dist/Models/DatabaseModels/AIAgentTask.js.map +0 -1
- package/build/dist/Models/DatabaseModels/AIAgentTaskLog.js +0 -447
- package/build/dist/Models/DatabaseModels/AIAgentTaskLog.js.map +0 -1
- package/build/dist/Models/DatabaseModels/AIAgentTaskTelemetryException.js +0 -415
- package/build/dist/Models/DatabaseModels/AIAgentTaskTelemetryException.js.map +0 -1
- package/build/dist/Models/DatabaseModels/ServiceCodeRepository.js +0 -665
- package/build/dist/Models/DatabaseModels/ServiceCodeRepository.js.map +0 -1
- package/build/dist/Server/Services/AIAgentTaskLogService.js.map +0 -1
- package/build/dist/Server/Services/AIAgentTaskService.js +0 -217
- package/build/dist/Server/Services/AIAgentTaskService.js.map +0 -1
- package/build/dist/Server/Services/AIAgentTaskTelemetryExceptionService.js +0 -36
- package/build/dist/Server/Services/AIAgentTaskTelemetryExceptionService.js.map +0 -1
- package/build/dist/Server/Services/ServiceCodeRepositoryService.js +0 -54
- package/build/dist/Server/Services/ServiceCodeRepositoryService.js.map +0 -1
- package/build/dist/Server/Utils/AI/Sentinel/AlertInvestigationRunner.js.map +0 -1
- package/build/dist/Server/Utils/AI/Sentinel/IncidentInvestigationRunner.js.map +0 -1
- package/build/dist/Server/Utils/AI/Sentinel/IncidentPostmortemRunner.js.map +0 -1
- package/build/dist/Server/Utils/AI/Sentinel/InvestigationQueue.js.map +0 -1
- package/build/dist/Server/Utils/AI/Sentinel/SentinelInvestigationEngine.js.map +0 -1
- package/build/dist/Server/Utils/AI/Sentinel/SentinelMemory.js.map +0 -1
- package/build/dist/Server/Utils/AI/Toolbox/SentinelActionTools.js.map +0 -1
- package/build/dist/Types/AI/AIAgentTaskMetadata.js +0 -6
- package/build/dist/Types/AI/AIAgentTaskMetadata.js.map +0 -1
- package/build/dist/Types/AI/AIAgentTaskType.js +0 -29
- 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
|
|
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
|
|
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
|
-
|
|
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/
|
|
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
|
-
|
|
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
|
-
|
|
117
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
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
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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 (!
|
|
326
|
+
if (!exception || !exception.projectId) {
|
|
270
327
|
return Response.sendErrorResponse(
|
|
271
328
|
req,
|
|
272
329
|
res,
|
|
273
|
-
new BadDataException("
|
|
330
|
+
new BadDataException("Exception not found"),
|
|
274
331
|
);
|
|
275
332
|
}
|
|
276
333
|
|
|
277
|
-
|
|
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
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
298
|
-
|
|
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
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
(
|
|
321
|
-
|
|
322
|
-
|
|
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
|
-
`
|
|
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
|
-
|
|
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
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
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 (!
|
|
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 (
|
|
599
|
-
pullRequest.projectId =
|
|
1134
|
+
if (run.projectId) {
|
|
1135
|
+
pullRequest.projectId = run.projectId;
|
|
600
1136
|
}
|
|
601
1137
|
|
|
602
|
-
pullRequest.
|
|
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
|
|
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"]) {
|