@oneuptime/common 11.5.12 → 11.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/Models/DatabaseModels/AIInsight.ts +30 -0
  2. package/Models/DatabaseModels/EnterpriseLicense.ts +21 -0
  3. package/Models/DatabaseModels/EnterpriseLicenseInstance.ts +25 -0
  4. package/Models/DatabaseModels/GlobalConfig.ts +76 -0
  5. package/Models/DatabaseModels/Project.ts +30 -0
  6. package/Models/DatabaseModels/TelemetryException.ts +128 -0
  7. package/Server/API/AIAgentDataAPI.ts +129 -5
  8. package/Server/API/AIInvestigationAPI.ts +87 -0
  9. package/Server/API/EnterpriseLicenseAPI.ts +57 -0
  10. package/Server/API/GlobalConfigAPI.ts +62 -1
  11. package/Server/EnvironmentConfig.ts +22 -0
  12. package/Server/Infrastructure/Postgres/SchemaMigrations/1784640000000-AddExceptionTriageAndPrivacyColumns.ts +56 -0
  13. package/Server/Infrastructure/Postgres/SchemaMigrations/1784659816363-AddInstanceVersionAndLatestReleaseColumns.ts +38 -0
  14. package/Server/Infrastructure/Postgres/SchemaMigrations/1784705487674-AddEnterpriseLicenseEvaluationColumns.ts +25 -0
  15. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +6 -0
  16. package/Server/Services/AIRunService.ts +8 -0
  17. package/Server/Services/AnalyticsDatabaseService.ts +48 -45
  18. package/Server/Services/DatabaseService.ts +66 -1
  19. package/Server/Services/TelemetryExceptionService.ts +320 -24
  20. package/Server/Services/WorkflowService.ts +100 -39
  21. package/Server/Types/Workflow/Components/Schedule.ts +57 -32
  22. package/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.ts +15 -4
  23. package/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.ts +15 -4
  24. package/Server/Utils/AI/SRE/Insights/InsightScanner.ts +222 -24
  25. package/Server/Utils/AI/SRE/Insights/InsightTriageRunner.ts +225 -9
  26. package/Server/Utils/AI/SRE/SubjectCodeFixRun.ts +39 -0
  27. package/Server/Utils/AI/SRE/TelemetryImprovementTaskTrigger.ts +114 -0
  28. package/Server/Utils/AnalyticsDatabase/InsertDedupContext.ts +59 -0
  29. package/Server/Utils/Express.ts +13 -0
  30. package/Server/Utils/Telemetry/ExceptionSanitizer.ts +222 -0
  31. package/Server/Utils/Telemetry/TelemetryFanInWriter.ts +799 -0
  32. package/Server/Utils/Telemetry/TelemetryWriterClient.ts +263 -0
  33. package/Server/Utils/Telemetry/TelemetryWriterServer.ts +240 -0
  34. package/Server/Utils/Telemetry/TelemetryWriterShedMetrics.ts +93 -0
  35. package/Tests/Server/Services/DatabaseServiceSanitizeUpdateData.test.ts +232 -0
  36. package/Tests/Server/Services/TelemetryExceptionCodeFixRun.test.ts +205 -1
  37. package/Tests/Server/Services/UpdateOneByIdKeepsRowId.test.ts +107 -0
  38. package/Tests/Server/Services/WorkflowService.test.ts +308 -0
  39. package/Tests/Server/Utils/AI/Insights/InsightScanner.test.ts +150 -141
  40. package/Tests/Server/Utils/AI/Insights/InsightTriageRunner.test.ts +277 -1
  41. package/Tests/Server/Utils/Attribution.test.ts +203 -0
  42. package/Tests/Server/Utils/ExceptionSanitizer.test.ts +70 -0
  43. package/Tests/Server/Utils/InsightTriageClassification.test.ts +57 -0
  44. package/Tests/Server/Utils/Marketing/ConversionUploadProvider.test.ts +183 -0
  45. package/Tests/Server/Utils/Marketing/GoogleAds.test.ts +340 -0
  46. package/Tests/Server/Utils/Monitor/Criteria/ExceptionMonitorCriteria.test.ts +87 -0
  47. package/Tests/Server/Utils/Monitor/Criteria/LogMonitorCriteria.test.ts +165 -0
  48. package/Tests/Server/Utils/Monitor/Criteria/TraceMonitorCriteria.test.ts +86 -0
  49. package/Tests/Server/Utils/Telemetry/TelemetryFanInWriter.test.ts +1565 -0
  50. package/Tests/Server/Utils/Telemetry/TelemetryWriterClient.test.ts +313 -0
  51. package/Tests/Server/Utils/Telemetry/TelemetryWriterServer.test.ts +270 -0
  52. package/Tests/Server/Utils/Telemetry/TelemetryWriterShedMetrics.test.ts +127 -0
  53. package/Tests/Server/Utils/TelemetryImprovementTaskTrigger.test.ts +141 -0
  54. package/Tests/Types/AI/CodeFixTaskType.test.ts +3 -0
  55. package/Tests/Types/Monitor/MonitorCriteriaMetricVariables.test.ts +228 -0
  56. package/Tests/Types/Monitor/MonitorStepDefaultTelemetryConfig.test.ts +169 -0
  57. package/Tests/Types/Monitor/MonitorStepExceptionMonitor.test.ts +289 -0
  58. package/Tests/Types/Monitor/MonitorStepLogMonitor.test.ts +231 -0
  59. package/Tests/Types/Monitor/MonitorStepMetricViewConfigUtil.test.ts +245 -0
  60. package/Tests/Types/Monitor/MonitorStepNetworkDeviceMonitor.test.ts +155 -0
  61. package/Tests/Types/Monitor/MonitorStepTelemetrySerialization.test.ts +141 -0
  62. package/Tests/Types/Monitor/MonitorStepTraceMonitor.test.ts +137 -0
  63. package/Tests/Types/Workspace/NotificationRules/NotificationRuleCondition.test.ts +311 -0
  64. package/Tests/UI/Components/ModelTableSelectFromColumns.test.ts +259 -0
  65. package/Tests/UI/Utils/Breadcrumb/BreadcrumbTrailResolver.test.ts +461 -0
  66. package/Tests/UI/Utils/Breadcrumb/fixtures/RealBreadcrumbTrails.ts +2852 -0
  67. package/Tests/UI/Utils/Breadcrumb/fixtures/RealRoutePatterns.ts +758 -0
  68. package/Tests/UI/Utils/NotificationMethodUtil.test.ts +564 -0
  69. package/Tests/Utils/Array.test.ts +156 -0
  70. package/Tests/Utils/CronTab.test.ts +199 -0
  71. package/Tests/Utils/ModelImportExport.test.ts +101 -0
  72. package/Tests/Utils/Number.test.ts +179 -0
  73. package/Tests/Utils/VersionUtil.test.ts +348 -0
  74. package/Tests/jest.setup.ts +1 -0
  75. package/Types/AI/CodeFixTaskContext.ts +6 -0
  76. package/Types/AI/CodeFixTaskType.ts +38 -1
  77. package/Types/AI/ExceptionAIClassification.ts +27 -0
  78. package/Types/EnterpriseLicense/EnterpriseLicenseInstanceSummary.ts +6 -0
  79. package/Types/Log/LogScrubPatternType.ts +7 -0
  80. package/Types/Monitor/MonitorStep.ts +24 -4
  81. package/Types/Monitor/MonitorStepMetricViewConfigUtil.ts +105 -0
  82. package/Types/Trace/TraceScrubPatternType.ts +7 -0
  83. package/UI/Components/EditionLabel/EditionLabel.tsx +445 -12
  84. package/UI/Components/ModelTable/BaseModelTable.tsx +15 -46
  85. package/UI/Components/ModelTable/SelectFromColumns.ts +129 -0
  86. package/UI/Components/Workflow/ArgumentsForm.tsx +68 -30
  87. package/UI/Components/Workflow/CronScheduleField.tsx +411 -0
  88. package/UI/Utils/Breadcrumb/BreadcrumbTrailResolver.ts +176 -0
  89. package/UI/Utils/NotificationMethodUtil.ts +310 -0
  90. package/Utils/CronTab.ts +823 -0
  91. package/Utils/ModelImportExport.ts +21 -6
  92. package/Utils/VersionUtil.ts +260 -0
  93. package/build/dist/Models/DatabaseModels/AIInsight.js +31 -0
  94. package/build/dist/Models/DatabaseModels/AIInsight.js.map +1 -1
  95. package/build/dist/Models/DatabaseModels/EnterpriseLicense.js +22 -0
  96. package/build/dist/Models/DatabaseModels/EnterpriseLicense.js.map +1 -1
  97. package/build/dist/Models/DatabaseModels/EnterpriseLicenseInstance.js +26 -0
  98. package/build/dist/Models/DatabaseModels/EnterpriseLicenseInstance.js.map +1 -1
  99. package/build/dist/Models/DatabaseModels/GlobalConfig.js +81 -0
  100. package/build/dist/Models/DatabaseModels/GlobalConfig.js.map +1 -1
  101. package/build/dist/Models/DatabaseModels/Project.js +31 -0
  102. package/build/dist/Models/DatabaseModels/Project.js.map +1 -1
  103. package/build/dist/Models/DatabaseModels/TelemetryException.js +134 -0
  104. package/build/dist/Models/DatabaseModels/TelemetryException.js.map +1 -1
  105. package/build/dist/Server/API/AIAgentDataAPI.js +97 -8
  106. package/build/dist/Server/API/AIAgentDataAPI.js.map +1 -1
  107. package/build/dist/Server/API/AIInvestigationAPI.js +55 -0
  108. package/build/dist/Server/API/AIInvestigationAPI.js.map +1 -1
  109. package/build/dist/Server/API/EnterpriseLicenseAPI.js +47 -0
  110. package/build/dist/Server/API/EnterpriseLicenseAPI.js.map +1 -1
  111. package/build/dist/Server/API/GlobalConfigAPI.js +52 -1
  112. package/build/dist/Server/API/GlobalConfigAPI.js.map +1 -1
  113. package/build/dist/Server/EnvironmentConfig.js +17 -0
  114. package/build/dist/Server/EnvironmentConfig.js.map +1 -1
  115. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784640000000-AddExceptionTriageAndPrivacyColumns.js +33 -0
  116. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784640000000-AddExceptionTriageAndPrivacyColumns.js.map +1 -0
  117. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784659816363-AddInstanceVersionAndLatestReleaseColumns.js +18 -0
  118. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784659816363-AddInstanceVersionAndLatestReleaseColumns.js.map +1 -0
  119. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784705487674-AddEnterpriseLicenseEvaluationColumns.js +14 -0
  120. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784705487674-AddEnterpriseLicenseEvaluationColumns.js.map +1 -0
  121. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +6 -0
  122. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  123. package/build/dist/Server/Services/AIRunService.js +9 -2
  124. package/build/dist/Server/Services/AIRunService.js.map +1 -1
  125. package/build/dist/Server/Services/AnalyticsDatabaseService.js +44 -16
  126. package/build/dist/Server/Services/AnalyticsDatabaseService.js.map +1 -1
  127. package/build/dist/Server/Services/DatabaseService.js +53 -1
  128. package/build/dist/Server/Services/DatabaseService.js.map +1 -1
  129. package/build/dist/Server/Services/TelemetryExceptionService.js +263 -22
  130. package/build/dist/Server/Services/TelemetryExceptionService.js.map +1 -1
  131. package/build/dist/Server/Services/WorkflowService.js +80 -30
  132. package/build/dist/Server/Services/WorkflowService.js.map +1 -1
  133. package/build/dist/Server/Types/Workflow/Components/Schedule.js +44 -19
  134. package/build/dist/Server/Types/Workflow/Components/Schedule.js.map +1 -1
  135. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.js +12 -4
  136. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.js.map +1 -1
  137. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.js +12 -4
  138. package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.js.map +1 -1
  139. package/build/dist/Server/Utils/AI/SRE/Insights/InsightScanner.js +193 -22
  140. package/build/dist/Server/Utils/AI/SRE/Insights/InsightScanner.js.map +1 -1
  141. package/build/dist/Server/Utils/AI/SRE/Insights/InsightTriageRunner.js +178 -9
  142. package/build/dist/Server/Utils/AI/SRE/Insights/InsightTriageRunner.js.map +1 -1
  143. package/build/dist/Server/Utils/AI/SRE/SubjectCodeFixRun.js +37 -0
  144. package/build/dist/Server/Utils/AI/SRE/SubjectCodeFixRun.js.map +1 -1
  145. package/build/dist/Server/Utils/AI/SRE/TelemetryImprovementTaskTrigger.js +98 -0
  146. package/build/dist/Server/Utils/AI/SRE/TelemetryImprovementTaskTrigger.js.map +1 -0
  147. package/build/dist/Server/Utils/AnalyticsDatabase/InsertDedupContext.js +24 -0
  148. package/build/dist/Server/Utils/AnalyticsDatabase/InsertDedupContext.js.map +1 -0
  149. package/build/dist/Server/Utils/Express.js +12 -0
  150. package/build/dist/Server/Utils/Express.js.map +1 -1
  151. package/build/dist/Server/Utils/Telemetry/ExceptionSanitizer.js +149 -0
  152. package/build/dist/Server/Utils/Telemetry/ExceptionSanitizer.js.map +1 -0
  153. package/build/dist/Server/Utils/Telemetry/TelemetryFanInWriter.js +496 -0
  154. package/build/dist/Server/Utils/Telemetry/TelemetryFanInWriter.js.map +1 -0
  155. package/build/dist/Server/Utils/Telemetry/TelemetryWriterClient.js +165 -0
  156. package/build/dist/Server/Utils/Telemetry/TelemetryWriterClient.js.map +1 -0
  157. package/build/dist/Server/Utils/Telemetry/TelemetryWriterServer.js +136 -0
  158. package/build/dist/Server/Utils/Telemetry/TelemetryWriterServer.js.map +1 -0
  159. package/build/dist/Server/Utils/Telemetry/TelemetryWriterShedMetrics.js +76 -0
  160. package/build/dist/Server/Utils/Telemetry/TelemetryWriterShedMetrics.js.map +1 -0
  161. package/build/dist/Types/AI/CodeFixTaskType.js +38 -1
  162. package/build/dist/Types/AI/CodeFixTaskType.js.map +1 -1
  163. package/build/dist/Types/AI/ExceptionAIClassification.js +28 -0
  164. package/build/dist/Types/AI/ExceptionAIClassification.js.map +1 -0
  165. package/build/dist/Types/Log/LogScrubPatternType.js +7 -0
  166. package/build/dist/Types/Log/LogScrubPatternType.js.map +1 -1
  167. package/build/dist/Types/Monitor/MonitorStep.js +20 -4
  168. package/build/dist/Types/Monitor/MonitorStep.js.map +1 -1
  169. package/build/dist/Types/Monitor/MonitorStepMetricViewConfigUtil.js +73 -0
  170. package/build/dist/Types/Monitor/MonitorStepMetricViewConfigUtil.js.map +1 -0
  171. package/build/dist/Types/Trace/TraceScrubPatternType.js +7 -0
  172. package/build/dist/Types/Trace/TraceScrubPatternType.js.map +1 -1
  173. package/build/dist/UI/Components/EditionLabel/EditionLabel.js +261 -13
  174. package/build/dist/UI/Components/EditionLabel/EditionLabel.js.map +1 -1
  175. package/build/dist/UI/Components/ModelTable/BaseModelTable.js +12 -37
  176. package/build/dist/UI/Components/ModelTable/BaseModelTable.js.map +1 -1
  177. package/build/dist/UI/Components/ModelTable/SelectFromColumns.js +82 -0
  178. package/build/dist/UI/Components/ModelTable/SelectFromColumns.js.map +1 -0
  179. package/build/dist/UI/Components/Workflow/ArgumentsForm.js +30 -6
  180. package/build/dist/UI/Components/Workflow/ArgumentsForm.js.map +1 -1
  181. package/build/dist/UI/Components/Workflow/CronScheduleField.js +209 -0
  182. package/build/dist/UI/Components/Workflow/CronScheduleField.js.map +1 -0
  183. package/build/dist/UI/Utils/Breadcrumb/BreadcrumbTrailResolver.js +129 -0
  184. package/build/dist/UI/Utils/Breadcrumb/BreadcrumbTrailResolver.js.map +1 -0
  185. package/build/dist/UI/Utils/NotificationMethodUtil.js +189 -0
  186. package/build/dist/UI/Utils/NotificationMethodUtil.js.map +1 -0
  187. package/build/dist/Utils/CronTab.js +609 -0
  188. package/build/dist/Utils/CronTab.js.map +1 -0
  189. package/build/dist/Utils/ModelImportExport.js +20 -6
  190. package/build/dist/Utils/ModelImportExport.js.map +1 -1
  191. package/build/dist/Utils/VersionUtil.js +193 -0
  192. package/build/dist/Utils/VersionUtil.js.map +1 -0
  193. package/package.json +1 -1
@@ -0,0 +1,98 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import CodeFixTaskType from "../../../../Types/AI/CodeFixTaskType";
11
+ import BadDataException from "../../../../Types/Exception/BadDataException";
12
+ import ServiceService from "../../../Services/ServiceService";
13
+ import SubjectCodeFixRun from "./SubjectCodeFixRun";
14
+ import CaptureSpan from "../../Telemetry/CaptureSpan";
15
+ /*
16
+ * AI SRE — the service-scoped instrumentation-improvement triggers:
17
+ * ImproveLogging and ImproveTracing. One click on a service's Logs or
18
+ * Traces page opens a draft PR that improves that service's logging or
19
+ * tracing hygiene — parameterized log messages, correct severities, spans
20
+ * on uninstrumented paths, proper exception recording — WITHOUT changing
21
+ * behavior.
22
+ *
23
+ * Like FixFromIncident and FixPerformance these are human-triggered from a
24
+ * user-facing endpoint (POST /ai-investigation/
25
+ * create-telemetry-improvement-task), so there is no project opt-in flag —
26
+ * the human in the loop IS the gate — and every unmet gate FAILS EARLY
27
+ * with a clear message. The recipe's grounding is the SERVICE: repository
28
+ * resolution at task-details time uses the service name (name-match /
29
+ * only-repository), the same path the incident-subject recipes use.
30
+ */
31
+ export default class TelemetryImprovementTaskTrigger {
32
+ /*
33
+ * Gate and enqueue an ImproveLogging / ImproveTracing CodeFix run for a
34
+ * telemetry service. The caller must already have loaded the service
35
+ * under the USER's permissions (the access check) — this method reads
36
+ * and writes as root.
37
+ *
38
+ * Throws BadDataException naming the failed gate: unsupported recipe, no
39
+ * GitHub-App repository, a duplicate active run for the same service, or
40
+ * (via enqueueSubjectCodeFixRun) the daily fix-run budget.
41
+ */
42
+ static async createTelemetryImprovementTask(data) {
43
+ var _a;
44
+ if (data.taskType !== CodeFixTaskType.ImproveLogging &&
45
+ data.taskType !== CodeFixTaskType.ImproveTracing) {
46
+ throw new BadDataException(`Task type "${data.taskType}" is not a telemetry-improvement recipe. Supported: ${CodeFixTaskType.ImproveLogging}, ${CodeFixTaskType.ImproveTracing}.`);
47
+ }
48
+ const service = await ServiceService.findOneById({
49
+ id: data.telemetryServiceId,
50
+ select: {
51
+ _id: true,
52
+ name: true,
53
+ projectId: true,
54
+ },
55
+ props: { isRoot: true },
56
+ });
57
+ if (!service ||
58
+ ((_a = service.projectId) === null || _a === void 0 ? void 0 : _a.toString()) !== data.projectId.toString()) {
59
+ throw new BadDataException("Telemetry service not found.");
60
+ }
61
+ // Gate — a repository the agent can actually open a PR against.
62
+ const hasConnectedRepository = await SubjectCodeFixRun.hasGitHubAppConnectedRepository(data.projectId);
63
+ if (!hasConnectedRepository) {
64
+ throw new BadDataException("No GitHub-App-connected repository exists for this project, so the agent has nowhere to open the pull request. Connect one under AI > Code Repositories.");
65
+ }
66
+ /*
67
+ * Gate — per-(service, recipe) dedupe: repeated clicks must not fan
68
+ * out into duplicate PRs.
69
+ */
70
+ const existingRun = await SubjectCodeFixRun.findNonTerminalRunForTelemetryService({
71
+ projectId: data.projectId,
72
+ taskType: data.taskType,
73
+ telemetryServiceId: data.telemetryServiceId.toString(),
74
+ });
75
+ if (existingRun) {
76
+ throw new BadDataException(`An ${data.taskType === CodeFixTaskType.ImproveLogging
77
+ ? "improve-logging"
78
+ : "improve-tracing"} task is already queued or running for this service. Track its progress on the AI > Tasks page.`);
79
+ }
80
+ const taskContext = {
81
+ telemetryServiceId: data.telemetryServiceId.toString(),
82
+ serviceName: service.name || undefined,
83
+ };
84
+ return SubjectCodeFixRun.enqueueSubjectCodeFixRun({
85
+ projectId: data.projectId,
86
+ taskType: data.taskType,
87
+ userId: data.userId,
88
+ taskContext,
89
+ });
90
+ }
91
+ }
92
+ __decorate([
93
+ CaptureSpan(),
94
+ __metadata("design:type", Function),
95
+ __metadata("design:paramtypes", [Object]),
96
+ __metadata("design:returntype", Promise)
97
+ ], TelemetryImprovementTaskTrigger, "createTelemetryImprovementTask", null);
98
+ //# sourceMappingURL=TelemetryImprovementTaskTrigger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TelemetryImprovementTaskTrigger.js","sourceRoot":"","sources":["../../../../../../Server/Utils/AI/SRE/TelemetryImprovementTaskTrigger.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,eAAe,MAAM,sCAAsC,CAAC;AAEnE,OAAO,gBAAgB,MAAM,8CAA8C,CAAC;AAG5E,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAC9D,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,WAAW,MAAM,6BAA6B,CAAC;AAEtD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,OAAO,+BAA+B;IAClD;;;;;;;;;OASG;IAEiB,AAAb,MAAM,CAAC,KAAK,CAAC,8BAA8B,C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CAAC,QAAQ,KAAK,eAAe,CAAC,cAAc;gBAC9C,CAAC,CAAC,iBAAiB;gBACnB,CAAC,CAAC,iBACN,iGAAiG,CAClG,CAAC;QACJ,CAAC;QAED,MAAM,WAAW,GAAuB;YACtC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE;YACtD,WAAW,EAAE,OAAO,CAAC,IAAI,IAAI,SAAS;SACvC,CAAC;QAEF,OAAO,iBAAiB,CAAC,wBAAwB,CAAC;YAChD,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,WAAW;SACZ,CAAC,CAAC;IACL,CAAC;CACF;AA3EqB;IADnB,WAAW,EAAE;;;;2EA2Eb"}
@@ -0,0 +1,24 @@
1
+ import { AsyncLocalStorage } from "async_hooks";
2
+ const insertDedupContext = new AsyncLocalStorage();
3
+ export function runWithInsertDedup(tokenBase, fn) {
4
+ return insertDedupContext.run({ tokenBase, chunkIndexByTable: new Map() }, fn);
5
+ }
6
+ /**
7
+ * Consume the next deterministic dedup token for `tableName` from the
8
+ * ambient context, or undefined when called outside a runWithInsertDedup
9
+ * scope. Consuming advances the per-table chunk counter, so calls must
10
+ * happen in a deterministic order relative to the payload — true for the
11
+ * ingest services, whose chunking is a pure function of the (byte-identical
12
+ * across retries) job body.
13
+ */
14
+ export function nextInsertDedupToken(tableName) {
15
+ var _a;
16
+ const store = insertDedupContext.getStore();
17
+ if (!store) {
18
+ return undefined;
19
+ }
20
+ const chunkIndex = (_a = store.chunkIndexByTable.get(tableName)) !== null && _a !== void 0 ? _a : 0;
21
+ store.chunkIndexByTable.set(tableName, chunkIndex + 1);
22
+ return `${store.tokenBase}:${tableName}:${chunkIndex}`;
23
+ }
24
+ //# sourceMappingURL=InsertDedupContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InsertDedupContext.js","sourceRoot":"","sources":["../../../../../Server/Utils/AnalyticsDatabase/InsertDedupContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AA0BhD,MAAM,kBAAkB,GACtB,IAAI,iBAAiB,EAA2B,CAAC;AAEnD,MAAM,UAAU,kBAAkB,CAChC,SAAiB,EACjB,EAAoB;IAEpB,OAAO,kBAAkB,CAAC,GAAG,CAC3B,EAAE,SAAS,EAAE,iBAAiB,EAAE,IAAI,GAAG,EAAkB,EAAE,EAC3D,EAAE,CACH,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAAiB;;IACpD,MAAM,KAAK,GACT,kBAAkB,CAAC,QAAQ,EAAE,CAAC;IAEhC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,UAAU,GAAW,MAAA,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,mCAAI,CAAC,CAAC;IACvE,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,GAAG,CAAC,CAAC,CAAC;IACvD,OAAO,GAAG,KAAK,CAAC,SAAS,IAAI,SAAS,IAAI,UAAU,EAAE,CAAC;AACzD,CAAC"}
@@ -32,6 +32,18 @@ class Express {
32
32
  }
33
33
  if (!this.httpServer) {
34
34
  this.httpServer = createServer(this.app);
35
+ /*
36
+ * Keep upstream (nginx) connection reuse safe. When the ingress pools
37
+ * idle upstream connections (proxy keepalive), the backend must NOT be
38
+ * the side that closes an idle socket first — otherwise nginx can pick a
39
+ * socket the backend already closed and 502 a request it cannot safely
40
+ * retry (e.g. a POST on the telemetry ingest path). Node's default
41
+ * keepAliveTimeout (~5s) is well below nginx's upstream keepalive_timeout
42
+ * (60s), so raise it above that window. headersTimeout must stay greater
43
+ * than keepAliveTimeout or Node can cut an idle socket mid-request.
44
+ */
45
+ this.httpServer.keepAliveTimeout = 75 * 1000;
46
+ this.httpServer.headersTimeout = 76 * 1000;
35
47
  }
36
48
  /*
37
49
  * On shutdown, stop accepting new connections first (before datastores are
@@ -1 +1 @@
1
- {"version":3,"file":"Express.js","sourceRoot":"","sources":["../../../../Server/Utils/Express.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,gBAAgB,EAAE,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAYxE,OAAO,KAAK,CAAC;AACb,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAU,YAAY,EAAE,MAAM,MAAM,CAAC;AAK5C,MAAM,CAAC,MAAM,aAAa,GAAoB,OAAO,CAAC,MAAM,CAAC;AAC7D,MAAM,CAAC,MAAM,WAAW,GAAoB,OAAO,CAAC,IAAI,CAAC;AACzD,MAAM,CAAC,MAAM,iBAAiB,GAAoB,OAAO,CAAC,UAAU,CAAC;AACrE,MAAM,CAAC,MAAM,UAAU,GAAoB,OAAO,CAAC,GAAG,CAAC;AAEvD,MAAM,CAAC,MAAM,gBAAgB,GAC3B,GAAwB,EAAE;IACxB,OAAO,OAAO,EAAE,CAAC;AACnB,CAAC,CAAC;AA2CJ,MAAM,OAAO;IAIJ,MAAM,CAAC,SAAS;QACrB,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC;IAC1B,CAAC;IAEM,MAAM,CAAC,YAAY;QACxB,IAAI,CAAC,GAAG,GAAG,OAAO,EAAE,CAAC;IACvB,CAAC;IAEM,MAAM,CAAC,aAAa;QACzB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAEM,MAAM,CAAC,aAAa;QACzB,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACd,IAAI,CAAC,YAAY,EAAE,CAAC;QACtB,CAAC;QAED,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,iBAAiB,CACnC,OAAe,EACf,IAAW;QAEX,IAAI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;IACjC,CAAC;IAED,MAAM,QAAQ,GAAuB,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC3D,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,MAAM,aAAa,GAAuB,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IACrE,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,CAAC,aAAa,GAAG,aAAa,CAAC;IACvC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAgD,CACtE,GAAmB,EACC,EAAE;;IACtB,MAAM,SAAS,GAAuC,GAAG,CAAC,OAAO,CAC/D,iBAAiB,CACoB,CAAC;IAExC,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrD,OAAO,MAAA,MAAA,SAAS,CAAC,CAAC,CAAC,0CAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,0CAAE,IAAI,EAAE,CAAC;IAC7C,CAAC;IAED,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjE,OAAO,MAAA,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,0CAAE,IAAI,EAAE,CAAC;IACzC,CAAC;IAED,IAAI,MAAA,GAAG,CAAC,MAAM,0CAAE,aAAa,EAAE,CAAC;QAC9B,OAAO,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC;IAClC,CAAC;IAED,OAAO,GAAG,CAAC,EAAE,CAAC;AAChB,CAAC,CAAC"}
@@ -0,0 +1,149 @@
1
+ import ToolResultSerializer from "../AI/Toolbox/Serializer";
2
+ /*
3
+ * Shared exception-text sanitization.
4
+ *
5
+ * normalizeExceptionText is the fingerprint normalizer that used to live
6
+ * in App/FeatureSet/Telemetry/Utils/Exception.ts — it was moved here (the
7
+ * App util now delegates) so server-side consumers in Common (the AI
8
+ * agent data API) can sanitize exception messages before they reach LLM
9
+ * prompts, pull-request text, and commit messages. The replacement
10
+ * behavior MUST stay byte-for-byte stable: fingerprints are computed from
11
+ * its output, and changing it regroups every existing exception.
12
+ */
13
+ /**
14
+ * Normalizes a string by replacing dynamic values with placeholders.
15
+ * This ensures that exceptions with the same root cause but different
16
+ * dynamic values (like IDs, timestamps, etc.) get the same fingerprint.
17
+ *
18
+ * @param text - The text to normalize (message or stack trace)
19
+ * @returns The normalized text with dynamic values replaced
20
+ */
21
+ export function normalizeExceptionText(text) {
22
+ if (!text) {
23
+ return "";
24
+ }
25
+ let normalized = text;
26
+ // Order matters! More specific patterns should come before generic ones.
27
+ // 1. UUIDs (e.g., 550e8400-e29b-41d4-a716-446655440000)
28
+ normalized = normalized.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, "<UUID>");
29
+ // 2. MongoDB ObjectIDs (24 hex characters)
30
+ normalized = normalized.replace(/\b[0-9a-f]{24}\b/gi, "<OBJECT_ID>");
31
+ /*
32
+ * 3. Stripe-style IDs (e.g., sub_xxx, cus_xxx, pi_xxx, ch_xxx, etc.)
33
+ * These have a prefix followed by underscore and alphanumeric characters
34
+ */
35
+ normalized = normalized.replace(/\b(sub|cus|pi|ch|pm|card|price|prod|inv|txn|evt|req|acct|payout|ba|btok|src|tok|seti|si|cs|link|file|dp|icr|ii|il|is|isci|mbur|or|po|qt|rcpt|re|refund|sku|tax|txi|tr|us|wh)_[A-Za-z0-9]{10,32}\b/g, "<STRIPE_ID>");
36
+ /*
37
+ * 4. Generic API/Service IDs - alphanumeric strings that look like IDs
38
+ * Matches patterns like: prefix_alphanumeric or just long alphanumeric strings
39
+ * Common in many services (AWS, GCP, etc.)
40
+ */
41
+ normalized = normalized.replace(/\b[a-z]{2,10}_[A-Za-z0-9]{8,}\b/g, "<SERVICE_ID>");
42
+ // 5. JWT tokens (three base64 segments separated by dots)
43
+ normalized = normalized.replace(/\beyJ[A-Za-z0-9_-]*\.eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\b/g, "<JWT>");
44
+ // 6. Base64 encoded strings (long sequences, likely tokens or encoded data)
45
+ normalized = normalized.replace(/\b[A-Za-z0-9+/]{40,}={0,2}\b/g, "<BASE64>");
46
+ // 7. IP addresses (IPv4)
47
+ normalized = normalized.replace(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g, "<IP>");
48
+ // 8. IP addresses (IPv6) - simplified pattern
49
+ normalized = normalized.replace(/\b(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\b/g, "<IPV6>");
50
+ normalized = normalized.replace(/\b::1\b/g, "<IPV6>"); // localhost IPv6
51
+ // 9. Email addresses
52
+ normalized = normalized.replace(/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g, "<EMAIL>");
53
+ /*
54
+ * 10. URLs with dynamic paths/query params (normalize the dynamic parts)
55
+ * Keep the domain but normalize path segments that look like IDs
56
+ */
57
+ normalized = normalized.replace(/\/[0-9a-f]{8,}(?=\/|$|\?|#|\s|'|")/gi, "/<ID>");
58
+ /*
59
+ * 11. Timestamps in various formats
60
+ * ISO 8601 timestamps
61
+ */
62
+ normalized = normalized.replace(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?/g, "<TIMESTAMP>");
63
+ // Unix timestamps (10 or 13 digits)
64
+ normalized = normalized.replace(/\b1[0-9]{9,12}\b/g, "<TIMESTAMP>");
65
+ // 12. Date formats (YYYY-MM-DD, MM/DD/YYYY, etc.)
66
+ normalized = normalized.replace(/\b\d{4}[-/]\d{2}[-/]\d{2}\b/g, "<DATE>");
67
+ normalized = normalized.replace(/\b\d{2}[-/]\d{2}[-/]\d{4}\b/g, "<DATE>");
68
+ // 13. Time formats (HH:MM:SS, HH:MM)
69
+ normalized = normalized.replace(/\b\d{2}:\d{2}(?::\d{2})?\b/g, "<TIME>");
70
+ // 14. Memory addresses (0x followed by hex)
71
+ normalized = normalized.replace(/\b0x[0-9a-fA-F]+\b/g, "<MEMORY_ADDR>");
72
+ // 15. Session IDs (common patterns) - MUST come before hex ID pattern
73
+ normalized = normalized.replace(/\bsession[_-]?id[=:\s]*['"]?[A-Za-z0-9_-]+['"]?/gi, "session_id=<SESSION>");
74
+ // 16. Request IDs (common patterns) - MUST come before hex ID pattern
75
+ normalized = normalized.replace(/\brequest[_-]?id[=:\s]*['"]?[A-Za-z0-9_-]+['"]?/gi, "request_id=<REQUEST>");
76
+ // 17. Correlation IDs - MUST come before hex ID pattern
77
+ normalized = normalized.replace(/\bcorrelation[_-]?id[=:\s]*['"]?[A-Za-z0-9_-]+['"]?/gi, "correlation_id=<CORRELATION>");
78
+ // 18. Transaction IDs - MUST come before hex ID pattern
79
+ normalized = normalized.replace(/\btransaction[_-]?id[=:\s]*['"]?[A-Za-z0-9_-]+['"]?/gi, "transaction_id=<TRANSACTION>");
80
+ // 19. Hex strings that are likely IDs (8+ chars)
81
+ normalized = normalized.replace(/\b[0-9a-f]{8,}\b/gi, "<HEX_ID>");
82
+ /*
83
+ * 20. Quoted strings containing IDs or dynamic values
84
+ * Match strings in single or double quotes that look like IDs
85
+ */
86
+ normalized = normalized.replace(/'[A-Za-z0-9_-]{16,}'/g, "'<ID>'");
87
+ normalized = normalized.replace(/"[A-Za-z0-9_-]{16,}"/g, '"<ID>"');
88
+ // 21. Port numbers in URLs or connection strings
89
+ normalized = normalized.replace(/:(\d{4,5})(?=\/|$|\s)/g, ":<PORT>");
90
+ /*
91
+ * 22. Line numbers in stack traces (keep for context, but normalize large numbers)
92
+ * This normalizes specific line/column references that might vary
93
+ */
94
+ normalized = normalized.replace(/:\d+:\d+\)?$/gm, ":<LINE>:<COL>)");
95
+ // 23. Process/Thread IDs
96
+ normalized = normalized.replace(/\bPID[:\s]*\d+\b/gi, "PID:<PID>");
97
+ normalized = normalized.replace(/\bTID[:\s]*\d+\b/gi, "TID:<TID>");
98
+ // 24. Numeric IDs in common patterns (id=123, id: 123, etc.)
99
+ normalized = normalized.replace(/\bid[=:\s]*['"]?\d+['"]?/gi, "id=<ID>");
100
+ // 25. Large numbers that are likely IDs (more than 6 digits)
101
+ normalized = normalized.replace(/\b\d{7,}\b/g, "<NUMBER>");
102
+ return normalized;
103
+ }
104
+ /**
105
+ * Sanitize an exception message for surfaces that leave the platform:
106
+ * LLM prompts, pull-request titles/bodies, and commit messages.
107
+ *
108
+ * Normalization replaces the dynamic tokens (UUIDs, emails, IPs, IDs,
109
+ * timestamps...) that carry user data, then the secret redactor sweeps
110
+ * whatever is left (bearer tokens, API keys, cards...). The message
111
+ * keeps its structure — "invalid input syntax for type uuid: <HEX_ID>"
112
+ * is still perfectly actionable for a fix.
113
+ */
114
+ export function sanitizeExceptionMessage(message) {
115
+ if (!message) {
116
+ return "";
117
+ }
118
+ return ToolResultSerializer.redact(normalizeExceptionText(message)).text;
119
+ }
120
+ /**
121
+ * Sanitize a stack trace for the same surfaces.
122
+ *
123
+ * Runtimes prefix the native stack string with the exception MESSAGE
124
+ * ("Error: <message>" in Node, "ValueError: <message>" in Python
125
+ * headers, "Caused by: ..." in Java) — so a redact-only pass would leak
126
+ * the very identifiers sanitizeExceptionMessage strips. Frame lines are
127
+ * indented (" at fn (file:42:7)", ' File "x.py", line 3', "\tat ...")
128
+ * and must keep exact file:line references for the code agent, so the
129
+ * split is: unindented header/message lines get full normalization,
130
+ * indented frame lines are left intact, and the secret redactor sweeps
131
+ * everything at the end.
132
+ */
133
+ // Frame lines are indented; header/message lines are not.
134
+ const INDENTED_FRAME_LINE_REGEX = /^\s/;
135
+ export function sanitizeStackTrace(stackTrace) {
136
+ if (!stackTrace) {
137
+ return "";
138
+ }
139
+ const normalized = stackTrace
140
+ .split("\n")
141
+ .map((line) => {
142
+ return INDENTED_FRAME_LINE_REGEX.test(line)
143
+ ? line
144
+ : normalizeExceptionText(line);
145
+ })
146
+ .join("\n");
147
+ return ToolResultSerializer.redact(normalized).text;
148
+ }
149
+ //# sourceMappingURL=ExceptionSanitizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExceptionSanitizer.js","sourceRoot":"","sources":["../../../../../Server/Utils/Telemetry/ExceptionSanitizer.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAE5D;;;;;;;;;;GAUG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,UAAU,GAAW,IAAI,CAAC;IAE9B,yEAAyE;IAEzE,wDAAwD;IACxD,UAAU,GAAG,UAAU,CAAC,OAAO,CAC7B,gEAAgE,EAChE,QAAQ,CACT,CAAC;IAEF,2CAA2C;IAC3C,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,oBAAoB,EAAE,aAAa,CAAC,CAAC;IAErE;;;OAGG;IACH,UAAU,GAAG,UAAU,CAAC,OAAO,CAC7B,oMAAoM,EACpM,aAAa,CACd,CAAC;IAEF;;;;OAIG;IACH,UAAU,GAAG,UAAU,CAAC,OAAO,CAC7B,kCAAkC,EAClC,cAAc,CACf,CAAC;IAEF,0DAA0D;IAC1D,UAAU,GAAG,UAAU,CAAC,OAAO,CAC7B,2DAA2D,EAC3D,OAAO,CACR,CAAC;IAEF,4EAA4E;IAC5E,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,+BAA+B,EAAE,UAAU,CAAC,CAAC;IAE7E,yBAAyB;IACzB,UAAU,GAAG,UAAU,CAAC,OAAO,CAC7B,yCAAyC,EACzC,MAAM,CACP,CAAC;IAEF,8CAA8C;IAC9C,UAAU,GAAG,UAAU,CAAC,OAAO,CAC7B,+CAA+C,EAC/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