@oneuptime/common 9.2.16 → 9.2.18

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 (133) hide show
  1. package/Models/DatabaseModels/CodeRepository.ts +664 -0
  2. package/Models/DatabaseModels/Index.ts +8 -0
  3. package/Models/DatabaseModels/LlmLog.ts +818 -0
  4. package/Models/DatabaseModels/LlmProvider.ts +21 -0
  5. package/Models/DatabaseModels/Project.ts +206 -0
  6. package/Models/DatabaseModels/ServiceCatalogCodeRepository.ts +549 -0
  7. package/Server/API/AIBillingAPI.ts +126 -0
  8. package/Server/API/AlertAPI.ts +139 -0
  9. package/Server/API/GitHubAPI.ts +360 -0
  10. package/Server/API/IncidentAPI.ts +258 -0
  11. package/Server/API/ScheduledMaintenanceAPI.ts +164 -0
  12. package/Server/EnvironmentConfig.ts +44 -0
  13. package/Server/Infrastructure/Postgres/SchemaMigrations/1765580181582-MigrationName.ts +79 -0
  14. package/Server/Infrastructure/Postgres/SchemaMigrations/1765633554715-MigrationName.ts +75 -0
  15. package/Server/Infrastructure/Postgres/SchemaMigrations/1765801357168-MigrationName.ts +32 -0
  16. package/Server/Infrastructure/Postgres/SchemaMigrations/1765810218488-MigrationName.ts +69 -0
  17. package/Server/Infrastructure/Postgres/SchemaMigrations/1765830758857-MigrationName.ts +111 -0
  18. package/Server/Infrastructure/Postgres/SchemaMigrations/1765834537501-MigrationName.ts +39 -0
  19. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +12 -0
  20. package/Server/Services/AIBillingService.ts +247 -0
  21. package/Server/Services/AIService.ts +238 -0
  22. package/Server/Services/CodeRepositoryService.ts +10 -0
  23. package/Server/Services/IncidentService.ts +88 -0
  24. package/Server/Services/Index.ts +2 -0
  25. package/Server/Services/LlmLogService.ts +14 -0
  26. package/Server/Services/LlmProviderService.ts +58 -0
  27. package/Server/Services/ServiceCatalogCodeRepositoryService.ts +55 -0
  28. package/Server/Utils/AI/AlertAIContextBuilder.ts +264 -0
  29. package/Server/Utils/AI/IncidentAIContextBuilder.ts +710 -0
  30. package/Server/Utils/AI/ScheduledMaintenanceAIContextBuilder.ts +345 -0
  31. package/Server/Utils/CodeRepository/GitHub/GitHub.ts +226 -0
  32. package/Server/Utils/LLM/LLMService.ts +276 -0
  33. package/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.ts +166 -0
  34. package/Server/Utils/Workspace/Slack/Slack.ts +134 -0
  35. package/Server/Utils/Workspace/Workspace.ts +126 -0
  36. package/Tests/Types/Domain.test.ts +24 -3
  37. package/Types/CodeRepository/CodeRepositoryType.ts +1 -1
  38. package/Types/Domain.ts +21 -24
  39. package/Types/LlmLogStatus.ts +7 -0
  40. package/Types/Permission.ts +87 -0
  41. package/Types/ServiceCatalog/CodeRepositoryImprovementAction.ts +9 -0
  42. package/UI/Components/AI/AILoader.tsx +95 -0
  43. package/UI/Components/AI/GenerateFromAIModal.tsx +432 -0
  44. package/UI/Components/Modal/Modal.tsx +6 -1
  45. package/build/dist/Models/DatabaseModels/CodeRepository.js +689 -0
  46. package/build/dist/Models/DatabaseModels/CodeRepository.js.map +1 -0
  47. package/build/dist/Models/DatabaseModels/Index.js +7 -0
  48. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  49. package/build/dist/Models/DatabaseModels/LlmLog.js +856 -0
  50. package/build/dist/Models/DatabaseModels/LlmLog.js.map +1 -0
  51. package/build/dist/Models/DatabaseModels/LlmProvider.js +22 -0
  52. package/build/dist/Models/DatabaseModels/LlmProvider.js.map +1 -1
  53. package/build/dist/Models/DatabaseModels/Project.js +220 -0
  54. package/build/dist/Models/DatabaseModels/Project.js.map +1 -1
  55. package/build/dist/Models/DatabaseModels/ServiceCatalogCodeRepository.js +565 -0
  56. package/build/dist/Models/DatabaseModels/ServiceCatalogCodeRepository.js.map +1 -0
  57. package/build/dist/Server/API/AIBillingAPI.js +58 -0
  58. package/build/dist/Server/API/AIBillingAPI.js.map +1 -0
  59. package/build/dist/Server/API/AlertAPI.js +94 -0
  60. package/build/dist/Server/API/AlertAPI.js.map +1 -0
  61. package/build/dist/Server/API/GitHubAPI.js +207 -0
  62. package/build/dist/Server/API/GitHubAPI.js.map +1 -0
  63. package/build/dist/Server/API/IncidentAPI.js +171 -1
  64. package/build/dist/Server/API/IncidentAPI.js.map +1 -1
  65. package/build/dist/Server/API/ScheduledMaintenanceAPI.js +103 -0
  66. package/build/dist/Server/API/ScheduledMaintenanceAPI.js.map +1 -0
  67. package/build/dist/Server/EnvironmentConfig.js +31 -0
  68. package/build/dist/Server/EnvironmentConfig.js.map +1 -1
  69. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765580181582-MigrationName.js +34 -0
  70. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765580181582-MigrationName.js.map +1 -0
  71. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765633554715-MigrationName.js +32 -0
  72. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765633554715-MigrationName.js.map +1 -0
  73. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765801357168-MigrationName.js +38 -0
  74. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765801357168-MigrationName.js.map +1 -0
  75. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765810218488-MigrationName.js +30 -0
  76. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765810218488-MigrationName.js.map +1 -0
  77. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765830758857-MigrationName.js +44 -0
  78. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765830758857-MigrationName.js.map +1 -0
  79. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765834537501-MigrationName.js +22 -0
  80. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765834537501-MigrationName.js.map +1 -0
  81. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +12 -0
  82. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  83. package/build/dist/Server/Services/AIBillingService.js +187 -0
  84. package/build/dist/Server/Services/AIBillingService.js.map +1 -0
  85. package/build/dist/Server/Services/AIService.js +184 -0
  86. package/build/dist/Server/Services/AIService.js.map +1 -0
  87. package/build/dist/Server/Services/CodeRepositoryService.js +9 -0
  88. package/build/dist/Server/Services/CodeRepositoryService.js.map +1 -0
  89. package/build/dist/Server/Services/IncidentService.js +60 -0
  90. package/build/dist/Server/Services/IncidentService.js.map +1 -1
  91. package/build/dist/Server/Services/Index.js +2 -0
  92. package/build/dist/Server/Services/Index.js.map +1 -1
  93. package/build/dist/Server/Services/LlmLogService.js +13 -0
  94. package/build/dist/Server/Services/LlmLogService.js.map +1 -0
  95. package/build/dist/Server/Services/LlmProviderService.js +65 -0
  96. package/build/dist/Server/Services/LlmProviderService.js.map +1 -1
  97. package/build/dist/Server/Services/ServiceCatalogCodeRepositoryService.js +54 -0
  98. package/build/dist/Server/Services/ServiceCatalogCodeRepositoryService.js.map +1 -0
  99. package/build/dist/Server/Utils/AI/AlertAIContextBuilder.js +238 -0
  100. package/build/dist/Server/Utils/AI/AlertAIContextBuilder.js.map +1 -0
  101. package/build/dist/Server/Utils/AI/IncidentAIContextBuilder.js +597 -0
  102. package/build/dist/Server/Utils/AI/IncidentAIContextBuilder.js.map +1 -0
  103. package/build/dist/Server/Utils/AI/ScheduledMaintenanceAIContextBuilder.js +311 -0
  104. package/build/dist/Server/Utils/AI/ScheduledMaintenanceAIContextBuilder.js.map +1 -0
  105. package/build/dist/Server/Utils/CodeRepository/GitHub/GitHub.js +163 -0
  106. package/build/dist/Server/Utils/CodeRepository/GitHub/GitHub.js.map +1 -1
  107. package/build/dist/Server/Utils/LLM/LLMService.js +225 -0
  108. package/build/dist/Server/Utils/LLM/LLMService.js.map +1 -0
  109. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js +110 -0
  110. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js.map +1 -1
  111. package/build/dist/Server/Utils/Workspace/Slack/Slack.js +89 -0
  112. package/build/dist/Server/Utils/Workspace/Slack/Slack.js.map +1 -1
  113. package/build/dist/Server/Utils/Workspace/Workspace.js +80 -0
  114. package/build/dist/Server/Utils/Workspace/Workspace.js.map +1 -1
  115. package/build/dist/Tests/Types/Domain.test.js +19 -3
  116. package/build/dist/Tests/Types/Domain.test.js.map +1 -1
  117. package/build/dist/Types/CodeRepository/CodeRepositoryType.js +1 -1
  118. package/build/dist/Types/CodeRepository/CodeRepositoryType.js.map +1 -1
  119. package/build/dist/Types/Domain.js +18 -16
  120. package/build/dist/Types/Domain.js.map +1 -1
  121. package/build/dist/Types/LlmLogStatus.js +8 -0
  122. package/build/dist/Types/LlmLogStatus.js.map +1 -0
  123. package/build/dist/Types/Permission.js +74 -0
  124. package/build/dist/Types/Permission.js.map +1 -1
  125. package/build/dist/Types/ServiceCatalog/CodeRepositoryImprovementAction.js +10 -0
  126. package/build/dist/Types/ServiceCatalog/CodeRepositoryImprovementAction.js.map +1 -0
  127. package/build/dist/UI/Components/AI/AILoader.js +64 -0
  128. package/build/dist/UI/Components/AI/AILoader.js.map +1 -0
  129. package/build/dist/UI/Components/AI/GenerateFromAIModal.js +320 -0
  130. package/build/dist/UI/Components/AI/GenerateFromAIModal.js.map +1 -0
  131. package/build/dist/UI/Components/Modal/Modal.js +6 -1
  132. package/build/dist/UI/Components/Modal/Modal.js.map +1 -1
  133. package/package.json +1 -1
@@ -0,0 +1,264 @@
1
+ import ObjectID from "../../../Types/ObjectID";
2
+ import Alert from "../../../Models/DatabaseModels/Alert";
3
+ import AlertStateTimeline from "../../../Models/DatabaseModels/AlertStateTimeline";
4
+ import AlertInternalNote from "../../../Models/DatabaseModels/AlertInternalNote";
5
+ import AlertService from "../../Services/AlertService";
6
+ import AlertStateTimelineService from "../../Services/AlertStateTimelineService";
7
+ import AlertInternalNoteService from "../../Services/AlertInternalNoteService";
8
+ import CaptureSpan from "../Telemetry/CaptureSpan";
9
+ import OneUptimeDate from "../../../Types/Date";
10
+ import SortOrder from "../../../Types/BaseDatabase/SortOrder";
11
+ import { LLMMessage } from "../LLM/LLMService";
12
+
13
+ export interface AlertContextData {
14
+ alert: Alert;
15
+ stateTimeline: Array<AlertStateTimeline>;
16
+ internalNotes: Array<AlertInternalNote>;
17
+ }
18
+
19
+ export interface AIGenerationContext {
20
+ contextText: string;
21
+ systemPrompt: string;
22
+ messages: Array<LLMMessage>;
23
+ }
24
+
25
+ export default class AlertAIContextBuilder {
26
+ @CaptureSpan()
27
+ public static async buildAlertContext(data: {
28
+ alertId: ObjectID;
29
+ }): Promise<AlertContextData> {
30
+ const alert: Alert | null = await AlertService.findOneById({
31
+ id: data.alertId,
32
+ select: {
33
+ _id: true,
34
+ title: true,
35
+ description: true,
36
+ createdAt: true,
37
+ customFields: true,
38
+ projectId: true,
39
+ alertSeverity: {
40
+ name: true,
41
+ color: true,
42
+ },
43
+ currentAlertState: {
44
+ name: true,
45
+ color: true,
46
+ },
47
+ monitor: {
48
+ name: true,
49
+ },
50
+ labels: {
51
+ name: true,
52
+ color: true,
53
+ },
54
+ rootCause: true,
55
+ remediationNotes: true,
56
+ },
57
+ props: {
58
+ isRoot: true,
59
+ },
60
+ });
61
+
62
+ if (!alert) {
63
+ throw new Error("Alert not found");
64
+ }
65
+
66
+ // Fetch state timeline
67
+ const stateTimeline: Array<AlertStateTimeline> =
68
+ await AlertStateTimelineService.findBy({
69
+ query: {
70
+ alertId: data.alertId,
71
+ },
72
+ select: {
73
+ _id: true,
74
+ createdAt: true,
75
+ startsAt: true,
76
+ endsAt: true,
77
+ rootCause: true,
78
+ alertState: {
79
+ name: true,
80
+ color: true,
81
+ },
82
+ createdByUser: {
83
+ name: true,
84
+ email: true,
85
+ },
86
+ },
87
+ sort: {
88
+ startsAt: SortOrder.Ascending,
89
+ },
90
+ limit: 100,
91
+ skip: 0,
92
+ props: {
93
+ isRoot: true,
94
+ },
95
+ });
96
+
97
+ // Fetch internal notes
98
+ const internalNotes: Array<AlertInternalNote> =
99
+ await AlertInternalNoteService.findBy({
100
+ query: {
101
+ alertId: data.alertId,
102
+ },
103
+ select: {
104
+ _id: true,
105
+ note: true,
106
+ createdAt: true,
107
+ createdByUser: {
108
+ name: true,
109
+ email: true,
110
+ },
111
+ },
112
+ sort: {
113
+ createdAt: SortOrder.Ascending,
114
+ },
115
+ limit: 100,
116
+ skip: 0,
117
+ props: {
118
+ isRoot: true,
119
+ },
120
+ });
121
+
122
+ return {
123
+ alert,
124
+ stateTimeline,
125
+ internalNotes,
126
+ };
127
+ }
128
+
129
+ @CaptureSpan()
130
+ public static formatAlertContextForNote(
131
+ contextData: AlertContextData,
132
+ template?: string,
133
+ ): AIGenerationContext {
134
+ const { alert, stateTimeline, internalNotes } = contextData;
135
+
136
+ let contextText: string = "";
137
+
138
+ // Basic alert information
139
+ contextText += "# Alert Information\n\n";
140
+ contextText += `**Title:** ${alert.title || "N/A"}\n\n`;
141
+ contextText += `**Description:** ${alert.description || "N/A"}\n\n`;
142
+ contextText += `**Severity:** ${alert.alertSeverity?.name || "N/A"}\n\n`;
143
+ contextText += `**Current State:** ${alert.currentAlertState?.name || "N/A"}\n\n`;
144
+ contextText += `**Created At:** ${alert.createdAt ? OneUptimeDate.getDateAsFormattedString(alert.createdAt) : "N/A"}\n\n`;
145
+
146
+ // Affected monitor
147
+ if (alert.monitor) {
148
+ contextText += `**Monitor:** ${alert.monitor.name || "N/A"}\n\n`;
149
+ }
150
+
151
+ // Labels
152
+ if (alert.labels && alert.labels.length > 0) {
153
+ contextText += "**Labels:** ";
154
+ contextText += alert.labels
155
+ .map((l: { name?: string }) => {
156
+ return l.name;
157
+ })
158
+ .join(", ");
159
+ contextText += "\n\n";
160
+ }
161
+
162
+ // Root cause if available
163
+ if (alert.rootCause) {
164
+ contextText += `**Root Cause:** ${alert.rootCause}\n\n`;
165
+ }
166
+
167
+ // Remediation notes if available
168
+ if (alert.remediationNotes) {
169
+ contextText += `**Remediation Notes:** ${alert.remediationNotes}\n\n`;
170
+ }
171
+
172
+ // State timeline
173
+ if (stateTimeline.length > 0) {
174
+ contextText += "# State Timeline\n\n";
175
+ for (const timeline of stateTimeline) {
176
+ const startTime: string = timeline.startsAt
177
+ ? OneUptimeDate.getDateAsFormattedString(timeline.startsAt)
178
+ : "N/A";
179
+ const stateName: string =
180
+ timeline.alertState?.name?.toString() || "Unknown";
181
+ const createdBy: string =
182
+ timeline.createdByUser?.name?.toString() ||
183
+ timeline.createdByUser?.email?.toString() ||
184
+ "System";
185
+
186
+ contextText += `- **${startTime}**: State changed to **${stateName}** by ${createdBy}\n`;
187
+ if (timeline.rootCause) {
188
+ contextText += ` - Root cause noted: ${timeline.rootCause}\n`;
189
+ }
190
+ }
191
+ contextText += "\n";
192
+ }
193
+
194
+ // Internal notes
195
+ if (internalNotes.length > 0) {
196
+ contextText += "# Internal Notes (Private)\n\n";
197
+ for (const note of internalNotes) {
198
+ const noteTime: string = note.createdAt
199
+ ? OneUptimeDate.getDateAsFormattedString(note.createdAt)
200
+ : "N/A";
201
+ const createdBy: string =
202
+ note.createdByUser?.name?.toString() ||
203
+ note.createdByUser?.email?.toString() ||
204
+ "Unknown";
205
+
206
+ contextText += `**[${noteTime}] ${createdBy}:**\n`;
207
+ contextText += `${note.note || "N/A"}\n\n`;
208
+ }
209
+ }
210
+
211
+ // System prompt for note generation (alerts only have internal notes)
212
+ let systemPrompt: string;
213
+
214
+ if (template) {
215
+ systemPrompt = `You are an expert Site Reliability Engineer (SRE). Your task is to fill in an internal alert note template based on the provided alert data.
216
+
217
+ CRITICAL INSTRUCTIONS:
218
+ - You MUST use ONLY the exact template structure provided below
219
+ - Fill in each section of the template with relevant information from the alert data
220
+ - Do NOT add any new sections, headers, or content that is not part of the template
221
+ - Do NOT add introductions, conclusions, or any text outside the template structure
222
+ - Be technical and detailed - this is for the internal team
223
+ - Include relevant technical details, observations, and analysis
224
+
225
+ TEMPLATE TO FILL (use this exact structure):
226
+
227
+ ${template}`;
228
+ } else {
229
+ systemPrompt = `You are an expert Site Reliability Engineer (SRE). Your task is to generate an internal alert note for the team.
230
+
231
+ The note should:
232
+ 1. Provide technical details about the alert and its current status
233
+ 2. Document observations, findings, or actions taken
234
+ 3. Include relevant metrics or error messages if mentioned in the context
235
+ 4. Be detailed enough to help team members understand the situation
236
+ 5. Use technical language appropriate for the engineering team
237
+
238
+ Write in markdown format for better readability. Be thorough and technical.`;
239
+ }
240
+
241
+ // Build user message
242
+ const userMessage: string = template
243
+ ? `Fill in the template above using ONLY the following alert data. Output only the filled template, nothing else:\n\n${contextText}`
244
+ : `Based on the following alert data, please generate an internal technical alert note:\n\n${contextText}`;
245
+
246
+ // Build messages array
247
+ const messages: Array<LLMMessage> = [
248
+ {
249
+ role: "system",
250
+ content: systemPrompt,
251
+ },
252
+ {
253
+ role: "user",
254
+ content: userMessage,
255
+ },
256
+ ];
257
+
258
+ return {
259
+ contextText,
260
+ systemPrompt,
261
+ messages,
262
+ };
263
+ }
264
+ }