@oneuptime/common 11.5.7 → 11.5.9

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 (212) hide show
  1. package/Models/DatabaseModels/AIAgentTaskPullRequest.ts +15 -6
  2. package/Models/DatabaseModels/AIRun.ts +68 -0
  3. package/Models/DatabaseModels/AIRunEvent.ts +34 -1
  4. package/Models/DatabaseModels/NetworkDeviceDiscoveryScan.ts +215 -0
  5. package/Models/DatabaseModels/Project.ts +25 -0
  6. package/Models/DatabaseModels/StatusPage.ts +42 -0
  7. package/Server/API/AIAgentTaskAPI.ts +38 -12
  8. package/Server/API/AIAgentTaskLogAPI.ts +49 -0
  9. package/Server/API/AIChatAPI.ts +16 -0
  10. package/Server/API/AIReadinessAPI.ts +84 -0
  11. package/Server/API/CodeFixRunAPI.ts +190 -57
  12. package/Server/API/TelemetryExceptionAPI.ts +6 -1
  13. package/Server/Infrastructure/Postgres/SchemaMigrations/1784105912819-BackfillCodeFixTaskType.ts +41 -0
  14. package/Server/Infrastructure/Postgres/SchemaMigrations/1784124919694-AddAITaskNumberAndRunTranscript.ts +95 -0
  15. package/Server/Infrastructure/Postgres/SchemaMigrations/1784135099754-AllowNullAiAgentOnPullRequest.ts +52 -0
  16. package/Server/Infrastructure/Postgres/SchemaMigrations/1784137457184-AddEnableMcpServerToStatusPage.ts +30 -0
  17. package/Server/Infrastructure/Postgres/SchemaMigrations/1784200000000-AddSnmpV3ColumnsToNetworkDeviceDiscoveryScan.ts +49 -0
  18. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +10 -0
  19. package/Server/Middleware/MasterAdminAuthorization.ts +1 -1
  20. package/Server/Middleware/ProjectAuthorization.ts +1 -1
  21. package/Server/Services/AIRunEventService.ts +15 -1
  22. package/Server/Services/AIRunService.ts +48 -12
  23. package/Server/Services/LlmProviderService.ts +2 -0
  24. package/Server/Services/ProjectService.ts +42 -0
  25. package/Server/Services/StatusPageService.ts +87 -0
  26. package/Server/Services/TelemetryExceptionService.ts +19 -90
  27. package/Server/Types/Markdown.ts +9 -9
  28. package/Server/Types/MarkdownSlugify.ts +47 -0
  29. package/Server/Utils/AI/AIRunPrivacyFilter.ts +106 -0
  30. package/Server/Utils/AI/AIRunTranscript.ts +240 -0
  31. package/Server/Utils/AI/Chat/ChatAgentRunner.ts +9 -0
  32. package/Server/Utils/AI/Chat/ObservabilityChatPrompt.ts +119 -5
  33. package/Server/Utils/AI/CodeFix/CodeFixAgentCompletion.ts +75 -0
  34. package/Server/Utils/AI/CodeFix/CodeFixReadiness.ts +235 -0
  35. package/Server/Utils/AI/SRE/Insights/FixRouting.ts +2 -3
  36. package/Server/Utils/AI/Toolbox/CodeTools.ts +883 -0
  37. package/Server/Utils/AI/Toolbox/CodeWriteTools.ts +519 -0
  38. package/Server/Utils/AI/Toolbox/Index.ts +27 -0
  39. package/Server/Utils/AI/Toolbox/ScheduledMaintenanceTools.ts +279 -0
  40. package/Server/Utils/AnalyticsDatabase/ClickhouseCapacity.ts +19 -1
  41. package/Server/Utils/CodeRepository/GitHub/GitHub.ts +600 -0
  42. package/Server/Utils/CodeRepository/StackTraceRepoResolver.ts +7 -2
  43. package/Server/Utils/LLM/LLMService.ts +397 -18
  44. package/Server/Utils/Monitor/NetworkDeviceHydrationUtil.ts +4 -11
  45. package/Tests/Models/StatusPageEnableMcpServer.test.ts +125 -0
  46. package/Tests/Server/Services/StatusPageServiceMcp.test.ts +223 -0
  47. package/Tests/Server/Services/TelemetryExceptionAIFixReadiness.test.ts +26 -3
  48. package/Tests/Server/Services/TelemetryExceptionCodeFixRun.test.ts +12 -0
  49. package/Tests/Server/Types/Markdown.test.ts +106 -0
  50. package/Tests/Server/Utils/AI/AIRunPrivacyFilter.test.ts +295 -0
  51. package/Tests/Server/Utils/AI/AIRunTranscript.test.ts +182 -0
  52. package/Tests/Server/Utils/AI/CodeFixReadiness.test.ts +411 -0
  53. package/Tests/Server/Utils/AI/CodeTools.test.ts +596 -0
  54. package/Tests/Server/Utils/AI/CodeWriteTools.test.ts +475 -0
  55. package/Tests/Server/Utils/AI/LLMServiceModelCompatibility.test.ts +548 -0
  56. package/Tests/Server/Utils/AI/ObservabilityChatPrompt.test.ts +142 -0
  57. package/Tests/Server/Utils/AI/ScheduledMaintenanceTools.test.ts +176 -0
  58. package/Tests/Server/Utils/AnalyticsDatabase/ClickhouseCapacity.test.ts +63 -0
  59. package/Tests/Server/Utils/GitHubGetFileContent.test.ts +197 -0
  60. package/Tests/Server/Utils/Monitor/NetworkDeviceHydrationUtil.test.ts +502 -0
  61. package/Tests/Types/AI/AIAgentTaskStatus.test.ts +7 -6
  62. package/Tests/Types/AI/AIChatPageContext.test.ts +0 -0
  63. package/Tests/Types/AI/AIRunStatus.test.ts +42 -0
  64. package/Tests/Types/Log/LogSeverity.test.ts +78 -0
  65. package/Tests/UI/Components/BasicFormDropdownNormalization.test.tsx +167 -0
  66. package/Tests/UI/Components/Charts/AxisTickColor.test.tsx +66 -0
  67. package/Tests/UI/Utils/AIChatExport/ChatWidgetData.test.ts +319 -0
  68. package/Tests/UI/Utils/AIChatExport/ChatWidgetMarkdown.test.ts +188 -0
  69. package/Types/AI/AIAgentTaskStatus.ts +13 -0
  70. package/Types/AI/AIChatPageContext.ts +137 -0
  71. package/Types/AI/AIChatTypes.ts +44 -0
  72. package/Types/AI/AIFixReadiness.ts +46 -0
  73. package/Types/AI/AIRunStatus.ts +11 -0
  74. package/Types/Email/EmailTemplateType.ts +2 -0
  75. package/Types/Log/LogSeverity.ts +61 -0
  76. package/Types/Monitor/SnmpMonitor/SnmpVersion.ts +40 -0
  77. package/UI/Components/Charts/ChartLibrary/AreaChart/AreaChart.tsx +8 -2
  78. package/UI/Components/Charts/ChartLibrary/BarChart/BarChart.tsx +3 -1
  79. package/UI/Components/Charts/ChartLibrary/LineChart/LineChart.tsx +8 -2
  80. package/UI/Components/EditionLabel/EditionLabel.tsx +821 -331
  81. package/UI/Components/Forms/BasicForm.tsx +26 -8
  82. package/UI/Styles/Theme.css +1314 -0
  83. package/UI/Utils/AIChatExport/ChatWidgetData.ts +316 -0
  84. package/UI/Utils/AIChatExport/ChatWidgetMarkdown.ts +349 -0
  85. package/UI/Utils/AIChatExport/ConversationMarkdown.ts +177 -0
  86. package/UI/Utils/AIChatExport/MarkdownBlocks.ts +327 -0
  87. package/UI/Utils/AIChatExport/MarkdownSafety.ts +215 -0
  88. package/UI/Utils/DownloadFile.ts +54 -0
  89. package/build/dist/Models/DatabaseModels/AIAgentTaskPullRequest.js +15 -7
  90. package/build/dist/Models/DatabaseModels/AIAgentTaskPullRequest.js.map +1 -1
  91. package/build/dist/Models/DatabaseModels/AIRun.js +69 -0
  92. package/build/dist/Models/DatabaseModels/AIRun.js.map +1 -1
  93. package/build/dist/Models/DatabaseModels/AIRunEvent.js +31 -0
  94. package/build/dist/Models/DatabaseModels/AIRunEvent.js.map +1 -1
  95. package/build/dist/Models/DatabaseModels/NetworkDeviceDiscoveryScan.js +225 -0
  96. package/build/dist/Models/DatabaseModels/NetworkDeviceDiscoveryScan.js.map +1 -1
  97. package/build/dist/Models/DatabaseModels/Project.js +27 -0
  98. package/build/dist/Models/DatabaseModels/Project.js.map +1 -1
  99. package/build/dist/Models/DatabaseModels/StatusPage.js +43 -0
  100. package/build/dist/Models/DatabaseModels/StatusPage.js.map +1 -1
  101. package/build/dist/Server/API/AIAgentTaskAPI.js +37 -11
  102. package/build/dist/Server/API/AIAgentTaskAPI.js.map +1 -1
  103. package/build/dist/Server/API/AIAgentTaskLogAPI.js +32 -7
  104. package/build/dist/Server/API/AIAgentTaskLogAPI.js.map +1 -1
  105. package/build/dist/Server/API/AIChatAPI.js +9 -0
  106. package/build/dist/Server/API/AIChatAPI.js.map +1 -1
  107. package/build/dist/Server/API/AIReadinessAPI.js +57 -0
  108. package/build/dist/Server/API/AIReadinessAPI.js.map +1 -0
  109. package/build/dist/Server/API/CodeFixRunAPI.js +165 -51
  110. package/build/dist/Server/API/CodeFixRunAPI.js.map +1 -1
  111. package/build/dist/Server/API/TelemetryExceptionAPI.js +4 -0
  112. package/build/dist/Server/API/TelemetryExceptionAPI.js.map +1 -1
  113. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784105912819-BackfillCodeFixTaskType.js +36 -0
  114. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784105912819-BackfillCodeFixTaskType.js.map +1 -0
  115. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784124919694-AddAITaskNumberAndRunTranscript.js +80 -0
  116. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784124919694-AddAITaskNumberAndRunTranscript.js.map +1 -0
  117. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784135099754-AllowNullAiAgentOnPullRequest.js +37 -0
  118. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784135099754-AllowNullAiAgentOnPullRequest.js.map +1 -0
  119. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784137457184-AddEnableMcpServerToStatusPage.js +23 -0
  120. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784137457184-AddEnableMcpServerToStatusPage.js.map +1 -0
  121. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784200000000-AddSnmpV3ColumnsToNetworkDeviceDiscoveryScan.js +22 -0
  122. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784200000000-AddSnmpV3ColumnsToNetworkDeviceDiscoveryScan.js.map +1 -0
  123. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +10 -0
  124. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  125. package/build/dist/Server/Middleware/MasterAdminAuthorization.js +1 -1
  126. package/build/dist/Server/Middleware/ProjectAuthorization.js +1 -1
  127. package/build/dist/Server/Services/AIRunEventService.js +8 -0
  128. package/build/dist/Server/Services/AIRunEventService.js.map +1 -1
  129. package/build/dist/Server/Services/AIRunService.js +39 -3
  130. package/build/dist/Server/Services/AIRunService.js.map +1 -1
  131. package/build/dist/Server/Services/LlmProviderService.js +2 -0
  132. package/build/dist/Server/Services/LlmProviderService.js.map +1 -1
  133. package/build/dist/Server/Services/ProjectService.js +39 -0
  134. package/build/dist/Server/Services/ProjectService.js.map +1 -1
  135. package/build/dist/Server/Services/StatusPageService.js +81 -0
  136. package/build/dist/Server/Services/StatusPageService.js.map +1 -1
  137. package/build/dist/Server/Services/TelemetryExceptionService.js +14 -61
  138. package/build/dist/Server/Services/TelemetryExceptionService.js.map +1 -1
  139. package/build/dist/Server/Types/Markdown.js +8 -8
  140. package/build/dist/Server/Types/Markdown.js.map +1 -1
  141. package/build/dist/Server/Types/MarkdownSlugify.js +47 -0
  142. package/build/dist/Server/Types/MarkdownSlugify.js.map +1 -0
  143. package/build/dist/Server/Utils/AI/AIRunPrivacyFilter.js +82 -0
  144. package/build/dist/Server/Utils/AI/AIRunPrivacyFilter.js.map +1 -0
  145. package/build/dist/Server/Utils/AI/AIRunTranscript.js +180 -0
  146. package/build/dist/Server/Utils/AI/AIRunTranscript.js.map +1 -0
  147. package/build/dist/Server/Utils/AI/Chat/ChatAgentRunner.js +1 -0
  148. package/build/dist/Server/Utils/AI/Chat/ChatAgentRunner.js.map +1 -1
  149. package/build/dist/Server/Utils/AI/Chat/ObservabilityChatPrompt.js +103 -5
  150. package/build/dist/Server/Utils/AI/Chat/ObservabilityChatPrompt.js.map +1 -1
  151. package/build/dist/Server/Utils/AI/CodeFix/CodeFixAgentCompletion.js +55 -0
  152. package/build/dist/Server/Utils/AI/CodeFix/CodeFixAgentCompletion.js.map +1 -1
  153. package/build/dist/Server/Utils/AI/CodeFix/CodeFixReadiness.js +211 -0
  154. package/build/dist/Server/Utils/AI/CodeFix/CodeFixReadiness.js.map +1 -0
  155. package/build/dist/Server/Utils/AI/SRE/Insights/FixRouting.js.map +1 -1
  156. package/build/dist/Server/Utils/AI/Toolbox/CodeTools.js +654 -0
  157. package/build/dist/Server/Utils/AI/Toolbox/CodeTools.js.map +1 -0
  158. package/build/dist/Server/Utils/AI/Toolbox/CodeWriteTools.js +389 -0
  159. package/build/dist/Server/Utils/AI/Toolbox/CodeWriteTools.js.map +1 -0
  160. package/build/dist/Server/Utils/AI/Toolbox/Index.js +19 -0
  161. package/build/dist/Server/Utils/AI/Toolbox/Index.js.map +1 -1
  162. package/build/dist/Server/Utils/AI/Toolbox/ScheduledMaintenanceTools.js +239 -0
  163. package/build/dist/Server/Utils/AI/Toolbox/ScheduledMaintenanceTools.js.map +1 -0
  164. package/build/dist/Server/Utils/AnalyticsDatabase/ClickhouseCapacity.js +19 -1
  165. package/build/dist/Server/Utils/AnalyticsDatabase/ClickhouseCapacity.js.map +1 -1
  166. package/build/dist/Server/Utils/CodeRepository/GitHub/GitHub.js +439 -0
  167. package/build/dist/Server/Utils/CodeRepository/GitHub/GitHub.js.map +1 -1
  168. package/build/dist/Server/Utils/CodeRepository/StackTraceRepoResolver.js +1 -1
  169. package/build/dist/Server/Utils/CodeRepository/StackTraceRepoResolver.js.map +1 -1
  170. package/build/dist/Server/Utils/LLM/LLMService.js +275 -19
  171. package/build/dist/Server/Utils/LLM/LLMService.js.map +1 -1
  172. package/build/dist/Server/Utils/Monitor/NetworkDeviceHydrationUtil.js +2 -11
  173. package/build/dist/Server/Utils/Monitor/NetworkDeviceHydrationUtil.js.map +1 -1
  174. package/build/dist/Types/AI/AIAgentTaskStatus.js +12 -0
  175. package/build/dist/Types/AI/AIAgentTaskStatus.js.map +1 -1
  176. package/build/dist/Types/AI/AIChatPageContext.js +101 -0
  177. package/build/dist/Types/AI/AIChatPageContext.js.map +1 -0
  178. package/build/dist/Types/AI/AIChatTypes.js +2 -0
  179. package/build/dist/Types/AI/AIChatTypes.js.map +1 -1
  180. package/build/dist/Types/AI/AIFixReadiness.js +9 -0
  181. package/build/dist/Types/AI/AIFixReadiness.js.map +1 -0
  182. package/build/dist/Types/AI/AIRunStatus.js +11 -0
  183. package/build/dist/Types/AI/AIRunStatus.js.map +1 -1
  184. package/build/dist/Types/Email/EmailTemplateType.js +1 -0
  185. package/build/dist/Types/Email/EmailTemplateType.js.map +1 -1
  186. package/build/dist/Types/Log/LogSeverity.js +56 -0
  187. package/build/dist/Types/Log/LogSeverity.js.map +1 -1
  188. package/build/dist/Types/Monitor/SnmpMonitor/SnmpVersion.js +38 -0
  189. package/build/dist/Types/Monitor/SnmpMonitor/SnmpVersion.js.map +1 -1
  190. package/build/dist/UI/Components/Charts/ChartLibrary/AreaChart/AreaChart.js +9 -2
  191. package/build/dist/UI/Components/Charts/ChartLibrary/AreaChart/AreaChart.js.map +1 -1
  192. package/build/dist/UI/Components/Charts/ChartLibrary/BarChart/BarChart.js +3 -1
  193. package/build/dist/UI/Components/Charts/ChartLibrary/BarChart/BarChart.js.map +1 -1
  194. package/build/dist/UI/Components/Charts/ChartLibrary/LineChart/LineChart.js +9 -2
  195. package/build/dist/UI/Components/Charts/ChartLibrary/LineChart/LineChart.js.map +1 -1
  196. package/build/dist/UI/Components/EditionLabel/EditionLabel.js +424 -139
  197. package/build/dist/UI/Components/EditionLabel/EditionLabel.js.map +1 -1
  198. package/build/dist/UI/Components/Forms/BasicForm.js +24 -6
  199. package/build/dist/UI/Components/Forms/BasicForm.js.map +1 -1
  200. package/build/dist/UI/Utils/AIChatExport/ChatWidgetData.js +217 -0
  201. package/build/dist/UI/Utils/AIChatExport/ChatWidgetData.js.map +1 -0
  202. package/build/dist/UI/Utils/AIChatExport/ChatWidgetMarkdown.js +234 -0
  203. package/build/dist/UI/Utils/AIChatExport/ChatWidgetMarkdown.js.map +1 -0
  204. package/build/dist/UI/Utils/AIChatExport/ConversationMarkdown.js +111 -0
  205. package/build/dist/UI/Utils/AIChatExport/ConversationMarkdown.js.map +1 -0
  206. package/build/dist/UI/Utils/AIChatExport/MarkdownBlocks.js +233 -0
  207. package/build/dist/UI/Utils/AIChatExport/MarkdownBlocks.js.map +1 -0
  208. package/build/dist/UI/Utils/AIChatExport/MarkdownSafety.js +134 -0
  209. package/build/dist/UI/Utils/AIChatExport/MarkdownSafety.js.map +1 -0
  210. package/build/dist/UI/Utils/DownloadFile.js +41 -0
  211. package/build/dist/UI/Utils/DownloadFile.js.map +1 -0
  212. package/package.json +5 -1
@@ -0,0 +1,279 @@
1
+ import ScheduledMaintenance from "../../../../Models/DatabaseModels/ScheduledMaintenance";
2
+ import { JSONObject } from "../../../../Types/JSON";
3
+ import ObjectID from "../../../../Types/ObjectID";
4
+ import Permission from "../../../../Types/Permission";
5
+ import SortOrder from "../../../../Types/BaseDatabase/SortOrder";
6
+ import { AIChatCitationTargetType } from "../../../../Types/AI/AIChatTypes";
7
+ import ScheduledMaintenanceService from "../../../Services/ScheduledMaintenanceService";
8
+ import QueryHelper from "../../../Types/Database/QueryHelper";
9
+ import OneUptimeDate from "../../../../Types/Date";
10
+ import ToolResultSerializer, { SerializedResult } from "./Serializer";
11
+ import WidgetBuilder from "./WidgetBuilder";
12
+ import {
13
+ ObservabilityTool,
14
+ ToolArgs,
15
+ ToolContext,
16
+ ToolExecutionResult,
17
+ } from "./ToolTypes";
18
+
19
+ /*
20
+ * Derived from the model ACL so the tool gate can never drift from RBAC.
21
+ * Resolved lazily rather than at module load: this module is pulled in through
22
+ * the service import graph before the model class is fully wired up, so
23
+ * calling a model method at import time throws a circular-dependency
24
+ * TypeError. By the time a tool actually executes, every module is loaded.
25
+ */
26
+ let cachedReadPermissions: Array<Permission> | null = null;
27
+ const resolveReadPermissions: () => Array<Permission> =
28
+ (): Array<Permission> => {
29
+ if (!cachedReadPermissions) {
30
+ cachedReadPermissions = new ScheduledMaintenance().getReadPermissions();
31
+ }
32
+ return cachedReadPermissions;
33
+ };
34
+
35
+ function joinNames(items: Array<{ name?: string }> | undefined): string {
36
+ return (items || [])
37
+ .map((item: { name?: string }) => {
38
+ return item.name || "";
39
+ })
40
+ .filter((value: string) => {
41
+ return value.length > 0;
42
+ })
43
+ .join(", ");
44
+ }
45
+
46
+ export const QueryScheduledMaintenanceTool: ObservabilityTool = {
47
+ name: "query_scheduled_maintenance",
48
+ description:
49
+ "Query scheduled maintenance events (planned maintenance windows) in this project — past, ongoing and upcoming. Returns events whose window overlaps the requested range, with their state, window and affected monitors. Pass scheduledMaintenanceId to get full details of one event. Use the event's window to judge whether telemetry changes were expected maintenance rather than a real problem.",
50
+ inputSchema: {
51
+ type: "object",
52
+ properties: {
53
+ scheduledMaintenanceId: {
54
+ type: "string",
55
+ description:
56
+ "Get one scheduled maintenance event by its ID (includes description and affected monitors).",
57
+ },
58
+ pastDays: {
59
+ type: "number",
60
+ description:
61
+ "Include events whose window ends within this many days in the past (default 30, max 365).",
62
+ },
63
+ upcomingDays: {
64
+ type: "number",
65
+ description:
66
+ "Include events whose window starts within this many days in the future (default 30, max 365).",
67
+ },
68
+ limit: {
69
+ type: "number",
70
+ description: "Maximum events to return (default 10, max 25).",
71
+ },
72
+ },
73
+ },
74
+ get requiredPermissions(): Array<Permission> {
75
+ return resolveReadPermissions();
76
+ },
77
+ execute: async (
78
+ args: JSONObject,
79
+ ctx: ToolContext,
80
+ ): Promise<ToolExecutionResult> => {
81
+ const scheduledMaintenanceId: ObjectID | undefined = ToolArgs.getObjectID(
82
+ args,
83
+ "scheduledMaintenanceId",
84
+ );
85
+
86
+ if (scheduledMaintenanceId) {
87
+ const event: ScheduledMaintenance | null =
88
+ await ScheduledMaintenanceService.findOneById({
89
+ id: scheduledMaintenanceId,
90
+ select: {
91
+ _id: true,
92
+ title: true,
93
+ description: true,
94
+ scheduledMaintenanceNumber: true,
95
+ createdAt: true,
96
+ startsAt: true,
97
+ endsAt: true,
98
+ currentScheduledMaintenanceState: {
99
+ name: true,
100
+ },
101
+ monitors: {
102
+ _id: true,
103
+ name: true,
104
+ },
105
+ labels: {
106
+ name: true,
107
+ },
108
+ },
109
+ props: ctx.props,
110
+ });
111
+
112
+ /*
113
+ * Surface the blast radius (affected monitors) and the exact window so
114
+ * the model can scope log/trace/metric queries to the maintenance
115
+ * period instead of guessing which hours were "expected downtime".
116
+ */
117
+ const rows: Array<JSONObject> = event
118
+ ? [
119
+ {
120
+ id: event.id?.toString(),
121
+ scheduledMaintenanceNumber: event.scheduledMaintenanceNumber,
122
+ title: event.title,
123
+ description: event.description,
124
+ state: event.currentScheduledMaintenanceState?.name,
125
+ startsAt: event.startsAt,
126
+ endsAt: event.endsAt,
127
+ createdAt: event.createdAt,
128
+ affectedMonitors: joinNames(event.monitors) || undefined,
129
+ labels: joinNames(event.labels) || undefined,
130
+ },
131
+ ]
132
+ : [];
133
+
134
+ const serialized: SerializedResult =
135
+ ToolResultSerializer.serializeRows(rows);
136
+
137
+ return {
138
+ dataForLlm: serialized.text,
139
+ rowCount: serialized.rowCount,
140
+ citationLabel: `Scheduled maintenance ${
141
+ event?.scheduledMaintenanceNumber
142
+ ? `#${event.scheduledMaintenanceNumber}`
143
+ : scheduledMaintenanceId.toString()
144
+ }`,
145
+ citationTarget: {
146
+ type: AIChatCitationTargetType.ScheduledMaintenanceView,
147
+ params: {
148
+ scheduledMaintenanceId: scheduledMaintenanceId.toString(),
149
+ },
150
+ },
151
+ redactionCount: serialized.redactionCount,
152
+ isTruncated: serialized.isTruncated,
153
+ widget:
154
+ rows.length > 0
155
+ ? WidgetBuilder.table({
156
+ title:
157
+ `Scheduled maintenance #${event?.scheduledMaintenanceNumber ?? ""}`.trim(),
158
+ columns: [
159
+ { key: "title", title: "Title", type: "text" },
160
+ { key: "state", title: "State", type: "text" },
161
+ { key: "startsAt", title: "Starts", type: "date" },
162
+ { key: "endsAt", title: "Ends", type: "date" },
163
+ {
164
+ key: "affectedMonitors",
165
+ title: "Affected monitors",
166
+ type: "text",
167
+ },
168
+ ],
169
+ rows: rows,
170
+ link: {
171
+ type: AIChatCitationTargetType.ScheduledMaintenanceView,
172
+ params: {
173
+ scheduledMaintenanceId: scheduledMaintenanceId.toString(),
174
+ },
175
+ },
176
+ })
177
+ : undefined,
178
+ };
179
+ }
180
+
181
+ const pastDays: number = ToolArgs.getNumber(args, "pastDays", {
182
+ defaultValue: 30,
183
+ min: 0,
184
+ max: 365,
185
+ });
186
+ const upcomingDays: number = ToolArgs.getNumber(args, "upcomingDays", {
187
+ defaultValue: 30,
188
+ min: 0,
189
+ max: 365,
190
+ });
191
+ const limit: number = ToolArgs.getNumber(args, "limit", {
192
+ defaultValue: 10,
193
+ min: 1,
194
+ max: 25,
195
+ });
196
+
197
+ const now: Date = OneUptimeDate.getCurrentDate();
198
+ const windowStart: Date = OneUptimeDate.addRemoveDays(now, -1 * pastDays);
199
+ const windowEnd: Date = OneUptimeDate.addRemoveDays(now, upcomingDays);
200
+
201
+ // Overlap: the event's window intersects [windowStart, windowEnd].
202
+ const events: Array<ScheduledMaintenance> =
203
+ await ScheduledMaintenanceService.findBy({
204
+ query: {
205
+ startsAt: QueryHelper.lessThanEqualTo(windowEnd),
206
+ endsAt: QueryHelper.greaterThanEqualTo(windowStart),
207
+ },
208
+ select: {
209
+ _id: true,
210
+ title: true,
211
+ scheduledMaintenanceNumber: true,
212
+ startsAt: true,
213
+ endsAt: true,
214
+ currentScheduledMaintenanceState: {
215
+ name: true,
216
+ },
217
+ monitors: {
218
+ name: true,
219
+ },
220
+ },
221
+ sort: {
222
+ startsAt: SortOrder.Descending,
223
+ },
224
+ limit: limit,
225
+ skip: 0,
226
+ props: ctx.props,
227
+ });
228
+
229
+ const rows: Array<JSONObject> = events.map(
230
+ (event: ScheduledMaintenance) => {
231
+ return {
232
+ id: event.id?.toString(),
233
+ scheduledMaintenanceNumber: event.scheduledMaintenanceNumber,
234
+ title: event.title,
235
+ state: event.currentScheduledMaintenanceState?.name,
236
+ startsAt: event.startsAt,
237
+ endsAt: event.endsAt,
238
+ affectedMonitors: joinNames(event.monitors) || undefined,
239
+ };
240
+ },
241
+ );
242
+
243
+ const serialized: SerializedResult =
244
+ ToolResultSerializer.serializeRows(rows);
245
+
246
+ return {
247
+ dataForLlm: serialized.text,
248
+ rowCount: serialized.rowCount,
249
+ citationLabel: `Scheduled maintenance, -${pastDays}d/+${upcomingDays}d (${serialized.rowCount} found)`,
250
+ citationTarget: {
251
+ type: AIChatCitationTargetType.ScheduledMaintenanceEvents,
252
+ },
253
+ redactionCount: serialized.redactionCount,
254
+ isTruncated: serialized.isTruncated,
255
+ widget:
256
+ rows.length > 0
257
+ ? WidgetBuilder.table({
258
+ title: `Scheduled maintenance (${rows.length})`,
259
+ description: `Windows overlapping the last ${pastDays}d and next ${upcomingDays}d`,
260
+ columns: [
261
+ {
262
+ key: "scheduledMaintenanceNumber",
263
+ title: "#",
264
+ type: "number",
265
+ },
266
+ { key: "title", title: "Title", type: "text" },
267
+ { key: "state", title: "State", type: "text" },
268
+ { key: "startsAt", title: "Starts", type: "date" },
269
+ { key: "endsAt", title: "Ends", type: "date" },
270
+ ],
271
+ rows: rows,
272
+ link: {
273
+ type: AIChatCitationTargetType.ScheduledMaintenanceEvents,
274
+ },
275
+ })
276
+ : undefined,
277
+ };
278
+ },
279
+ };
@@ -520,7 +520,25 @@ export async function dropClickhousePartition(data: {
520
520
  const cluster: string = escapeStringLiteral(getClickhouseClusterName());
521
521
  const partitionId: string = escapeStringLiteral(data.partitionId);
522
522
 
523
+ /*
524
+ * max_partition_size_to_drop = 0 lifts the server's 50 GB drop guard
525
+ * (query-level since ClickHouse 23.12) for this statement only. That guard
526
+ * exists to stop a human fat-fingering a DROP: it cannot tell a wrong
527
+ * partition from a merely large one, and every partition reaching this call
528
+ * has already cleared the PRUNABLE_LOCAL_TABLES allowlist, the daily
529
+ * partition id check, newest-partition protection and a capacity plan that
530
+ * only selects partitions relieving a disk still over target. A single day
531
+ * of spans routinely exceeds 50 GB, so the guard rejects precisely the drops
532
+ * capacity pruning exists to perform. Setting it per statement rather than
533
+ * in config.xml keeps the guard in force for manual operator DDL, which is
534
+ * the fat-finger case it is actually for.
535
+ *
536
+ * Debugging note: ClickHouse strips this SETTINGS clause from the query text
537
+ * it stores in the distributed DDL queue and propagates the setting in the
538
+ * task's separate settings field, so system.distributed_ddl_queue shows the
539
+ * ALTER without it. The setting is still applied on every replica.
540
+ */
523
541
  await getClient().command({
524
- query: `ALTER TABLE ${database}.${tableName} ON CLUSTER '${cluster}' DROP PARTITION ID '${partitionId}'`,
542
+ query: `ALTER TABLE ${database}.${tableName} ON CLUSTER '${cluster}' DROP PARTITION ID '${partitionId}' SETTINGS max_partition_size_to_drop = 0`,
525
543
  });
526
544
  }