@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.
- package/Models/DatabaseModels/AIInsight.ts +30 -0
- package/Models/DatabaseModels/EnterpriseLicense.ts +21 -0
- package/Models/DatabaseModels/EnterpriseLicenseInstance.ts +25 -0
- package/Models/DatabaseModels/GlobalConfig.ts +76 -0
- package/Models/DatabaseModels/Project.ts +30 -0
- package/Models/DatabaseModels/TelemetryException.ts +128 -0
- package/Server/API/AIAgentDataAPI.ts +129 -5
- package/Server/API/AIInvestigationAPI.ts +87 -0
- package/Server/API/EnterpriseLicenseAPI.ts +57 -0
- package/Server/API/GlobalConfigAPI.ts +62 -1
- package/Server/EnvironmentConfig.ts +22 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1784640000000-AddExceptionTriageAndPrivacyColumns.ts +56 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1784659816363-AddInstanceVersionAndLatestReleaseColumns.ts +38 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1784705487674-AddEnterpriseLicenseEvaluationColumns.ts +25 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +6 -0
- package/Server/Services/AIRunService.ts +8 -0
- package/Server/Services/AnalyticsDatabaseService.ts +48 -45
- package/Server/Services/DatabaseService.ts +66 -1
- package/Server/Services/TelemetryExceptionService.ts +320 -24
- package/Server/Services/WorkflowService.ts +100 -39
- package/Server/Types/Workflow/Components/Schedule.ts +57 -32
- package/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.ts +15 -4
- package/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.ts +15 -4
- package/Server/Utils/AI/SRE/Insights/InsightScanner.ts +222 -24
- package/Server/Utils/AI/SRE/Insights/InsightTriageRunner.ts +225 -9
- package/Server/Utils/AI/SRE/SubjectCodeFixRun.ts +39 -0
- package/Server/Utils/AI/SRE/TelemetryImprovementTaskTrigger.ts +114 -0
- package/Server/Utils/AnalyticsDatabase/InsertDedupContext.ts +59 -0
- package/Server/Utils/Express.ts +13 -0
- package/Server/Utils/Telemetry/ExceptionSanitizer.ts +222 -0
- package/Server/Utils/Telemetry/TelemetryFanInWriter.ts +799 -0
- package/Server/Utils/Telemetry/TelemetryWriterClient.ts +263 -0
- package/Server/Utils/Telemetry/TelemetryWriterServer.ts +240 -0
- package/Server/Utils/Telemetry/TelemetryWriterShedMetrics.ts +93 -0
- package/Tests/Server/Services/DatabaseServiceSanitizeUpdateData.test.ts +232 -0
- package/Tests/Server/Services/TelemetryExceptionCodeFixRun.test.ts +205 -1
- package/Tests/Server/Services/UpdateOneByIdKeepsRowId.test.ts +107 -0
- package/Tests/Server/Services/WorkflowService.test.ts +308 -0
- package/Tests/Server/Utils/AI/Insights/InsightScanner.test.ts +150 -141
- package/Tests/Server/Utils/AI/Insights/InsightTriageRunner.test.ts +277 -1
- package/Tests/Server/Utils/Attribution.test.ts +203 -0
- package/Tests/Server/Utils/ExceptionSanitizer.test.ts +70 -0
- package/Tests/Server/Utils/InsightTriageClassification.test.ts +57 -0
- package/Tests/Server/Utils/Marketing/ConversionUploadProvider.test.ts +183 -0
- package/Tests/Server/Utils/Marketing/GoogleAds.test.ts +340 -0
- package/Tests/Server/Utils/Monitor/Criteria/ExceptionMonitorCriteria.test.ts +87 -0
- package/Tests/Server/Utils/Monitor/Criteria/LogMonitorCriteria.test.ts +165 -0
- package/Tests/Server/Utils/Monitor/Criteria/TraceMonitorCriteria.test.ts +86 -0
- package/Tests/Server/Utils/Telemetry/TelemetryFanInWriter.test.ts +1565 -0
- package/Tests/Server/Utils/Telemetry/TelemetryWriterClient.test.ts +313 -0
- package/Tests/Server/Utils/Telemetry/TelemetryWriterServer.test.ts +270 -0
- package/Tests/Server/Utils/Telemetry/TelemetryWriterShedMetrics.test.ts +127 -0
- package/Tests/Server/Utils/TelemetryImprovementTaskTrigger.test.ts +141 -0
- package/Tests/Types/AI/CodeFixTaskType.test.ts +3 -0
- package/Tests/Types/Monitor/MonitorCriteriaMetricVariables.test.ts +228 -0
- package/Tests/Types/Monitor/MonitorStepDefaultTelemetryConfig.test.ts +169 -0
- package/Tests/Types/Monitor/MonitorStepExceptionMonitor.test.ts +289 -0
- package/Tests/Types/Monitor/MonitorStepLogMonitor.test.ts +231 -0
- package/Tests/Types/Monitor/MonitorStepMetricViewConfigUtil.test.ts +245 -0
- package/Tests/Types/Monitor/MonitorStepNetworkDeviceMonitor.test.ts +155 -0
- package/Tests/Types/Monitor/MonitorStepTelemetrySerialization.test.ts +141 -0
- package/Tests/Types/Monitor/MonitorStepTraceMonitor.test.ts +137 -0
- package/Tests/Types/Workspace/NotificationRules/NotificationRuleCondition.test.ts +311 -0
- package/Tests/UI/Components/ModelTableSelectFromColumns.test.ts +259 -0
- package/Tests/UI/Utils/Breadcrumb/BreadcrumbTrailResolver.test.ts +461 -0
- package/Tests/UI/Utils/Breadcrumb/fixtures/RealBreadcrumbTrails.ts +2852 -0
- package/Tests/UI/Utils/Breadcrumb/fixtures/RealRoutePatterns.ts +758 -0
- package/Tests/UI/Utils/NotificationMethodUtil.test.ts +564 -0
- package/Tests/Utils/Array.test.ts +156 -0
- package/Tests/Utils/CronTab.test.ts +199 -0
- package/Tests/Utils/ModelImportExport.test.ts +101 -0
- package/Tests/Utils/Number.test.ts +179 -0
- package/Tests/Utils/VersionUtil.test.ts +348 -0
- package/Tests/jest.setup.ts +1 -0
- package/Types/AI/CodeFixTaskContext.ts +6 -0
- package/Types/AI/CodeFixTaskType.ts +38 -1
- package/Types/AI/ExceptionAIClassification.ts +27 -0
- package/Types/EnterpriseLicense/EnterpriseLicenseInstanceSummary.ts +6 -0
- package/Types/Log/LogScrubPatternType.ts +7 -0
- package/Types/Monitor/MonitorStep.ts +24 -4
- package/Types/Monitor/MonitorStepMetricViewConfigUtil.ts +105 -0
- package/Types/Trace/TraceScrubPatternType.ts +7 -0
- package/UI/Components/EditionLabel/EditionLabel.tsx +445 -12
- package/UI/Components/ModelTable/BaseModelTable.tsx +15 -46
- package/UI/Components/ModelTable/SelectFromColumns.ts +129 -0
- package/UI/Components/Workflow/ArgumentsForm.tsx +68 -30
- package/UI/Components/Workflow/CronScheduleField.tsx +411 -0
- package/UI/Utils/Breadcrumb/BreadcrumbTrailResolver.ts +176 -0
- package/UI/Utils/NotificationMethodUtil.ts +310 -0
- package/Utils/CronTab.ts +823 -0
- package/Utils/ModelImportExport.ts +21 -6
- package/Utils/VersionUtil.ts +260 -0
- package/build/dist/Models/DatabaseModels/AIInsight.js +31 -0
- package/build/dist/Models/DatabaseModels/AIInsight.js.map +1 -1
- package/build/dist/Models/DatabaseModels/EnterpriseLicense.js +22 -0
- package/build/dist/Models/DatabaseModels/EnterpriseLicense.js.map +1 -1
- package/build/dist/Models/DatabaseModels/EnterpriseLicenseInstance.js +26 -0
- package/build/dist/Models/DatabaseModels/EnterpriseLicenseInstance.js.map +1 -1
- package/build/dist/Models/DatabaseModels/GlobalConfig.js +81 -0
- package/build/dist/Models/DatabaseModels/GlobalConfig.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Project.js +31 -0
- package/build/dist/Models/DatabaseModels/Project.js.map +1 -1
- package/build/dist/Models/DatabaseModels/TelemetryException.js +134 -0
- package/build/dist/Models/DatabaseModels/TelemetryException.js.map +1 -1
- package/build/dist/Server/API/AIAgentDataAPI.js +97 -8
- package/build/dist/Server/API/AIAgentDataAPI.js.map +1 -1
- package/build/dist/Server/API/AIInvestigationAPI.js +55 -0
- package/build/dist/Server/API/AIInvestigationAPI.js.map +1 -1
- package/build/dist/Server/API/EnterpriseLicenseAPI.js +47 -0
- package/build/dist/Server/API/EnterpriseLicenseAPI.js.map +1 -1
- package/build/dist/Server/API/GlobalConfigAPI.js +52 -1
- package/build/dist/Server/API/GlobalConfigAPI.js.map +1 -1
- package/build/dist/Server/EnvironmentConfig.js +17 -0
- package/build/dist/Server/EnvironmentConfig.js.map +1 -1
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784640000000-AddExceptionTriageAndPrivacyColumns.js +33 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784640000000-AddExceptionTriageAndPrivacyColumns.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784659816363-AddInstanceVersionAndLatestReleaseColumns.js +18 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784659816363-AddInstanceVersionAndLatestReleaseColumns.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784705487674-AddEnterpriseLicenseEvaluationColumns.js +14 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1784705487674-AddEnterpriseLicenseEvaluationColumns.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +6 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Services/AIRunService.js +9 -2
- package/build/dist/Server/Services/AIRunService.js.map +1 -1
- package/build/dist/Server/Services/AnalyticsDatabaseService.js +44 -16
- package/build/dist/Server/Services/AnalyticsDatabaseService.js.map +1 -1
- package/build/dist/Server/Services/DatabaseService.js +53 -1
- package/build/dist/Server/Services/DatabaseService.js.map +1 -1
- package/build/dist/Server/Services/TelemetryExceptionService.js +263 -22
- package/build/dist/Server/Services/TelemetryExceptionService.js.map +1 -1
- package/build/dist/Server/Services/WorkflowService.js +80 -30
- package/build/dist/Server/Services/WorkflowService.js.map +1 -1
- package/build/dist/Server/Types/Workflow/Components/Schedule.js +44 -19
- package/build/dist/Server/Types/Workflow/Components/Schedule.js.map +1 -1
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.js +12 -4
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.js.map +1 -1
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.js +12 -4
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.js.map +1 -1
- package/build/dist/Server/Utils/AI/SRE/Insights/InsightScanner.js +193 -22
- package/build/dist/Server/Utils/AI/SRE/Insights/InsightScanner.js.map +1 -1
- package/build/dist/Server/Utils/AI/SRE/Insights/InsightTriageRunner.js +178 -9
- package/build/dist/Server/Utils/AI/SRE/Insights/InsightTriageRunner.js.map +1 -1
- package/build/dist/Server/Utils/AI/SRE/SubjectCodeFixRun.js +37 -0
- package/build/dist/Server/Utils/AI/SRE/SubjectCodeFixRun.js.map +1 -1
- package/build/dist/Server/Utils/AI/SRE/TelemetryImprovementTaskTrigger.js +98 -0
- package/build/dist/Server/Utils/AI/SRE/TelemetryImprovementTaskTrigger.js.map +1 -0
- package/build/dist/Server/Utils/AnalyticsDatabase/InsertDedupContext.js +24 -0
- package/build/dist/Server/Utils/AnalyticsDatabase/InsertDedupContext.js.map +1 -0
- package/build/dist/Server/Utils/Express.js +12 -0
- package/build/dist/Server/Utils/Express.js.map +1 -1
- package/build/dist/Server/Utils/Telemetry/ExceptionSanitizer.js +149 -0
- package/build/dist/Server/Utils/Telemetry/ExceptionSanitizer.js.map +1 -0
- package/build/dist/Server/Utils/Telemetry/TelemetryFanInWriter.js +496 -0
- package/build/dist/Server/Utils/Telemetry/TelemetryFanInWriter.js.map +1 -0
- package/build/dist/Server/Utils/Telemetry/TelemetryWriterClient.js +165 -0
- package/build/dist/Server/Utils/Telemetry/TelemetryWriterClient.js.map +1 -0
- package/build/dist/Server/Utils/Telemetry/TelemetryWriterServer.js +136 -0
- package/build/dist/Server/Utils/Telemetry/TelemetryWriterServer.js.map +1 -0
- package/build/dist/Server/Utils/Telemetry/TelemetryWriterShedMetrics.js +76 -0
- package/build/dist/Server/Utils/Telemetry/TelemetryWriterShedMetrics.js.map +1 -0
- package/build/dist/Types/AI/CodeFixTaskType.js +38 -1
- package/build/dist/Types/AI/CodeFixTaskType.js.map +1 -1
- package/build/dist/Types/AI/ExceptionAIClassification.js +28 -0
- package/build/dist/Types/AI/ExceptionAIClassification.js.map +1 -0
- package/build/dist/Types/Log/LogScrubPatternType.js +7 -0
- package/build/dist/Types/Log/LogScrubPatternType.js.map +1 -1
- package/build/dist/Types/Monitor/MonitorStep.js +20 -4
- package/build/dist/Types/Monitor/MonitorStep.js.map +1 -1
- package/build/dist/Types/Monitor/MonitorStepMetricViewConfigUtil.js +73 -0
- package/build/dist/Types/Monitor/MonitorStepMetricViewConfigUtil.js.map +1 -0
- package/build/dist/Types/Trace/TraceScrubPatternType.js +7 -0
- package/build/dist/Types/Trace/TraceScrubPatternType.js.map +1 -1
- package/build/dist/UI/Components/EditionLabel/EditionLabel.js +261 -13
- package/build/dist/UI/Components/EditionLabel/EditionLabel.js.map +1 -1
- package/build/dist/UI/Components/ModelTable/BaseModelTable.js +12 -37
- package/build/dist/UI/Components/ModelTable/BaseModelTable.js.map +1 -1
- package/build/dist/UI/Components/ModelTable/SelectFromColumns.js +82 -0
- package/build/dist/UI/Components/ModelTable/SelectFromColumns.js.map +1 -0
- package/build/dist/UI/Components/Workflow/ArgumentsForm.js +30 -6
- package/build/dist/UI/Components/Workflow/ArgumentsForm.js.map +1 -1
- package/build/dist/UI/Components/Workflow/CronScheduleField.js +209 -0
- package/build/dist/UI/Components/Workflow/CronScheduleField.js.map +1 -0
- package/build/dist/UI/Utils/Breadcrumb/BreadcrumbTrailResolver.js +129 -0
- package/build/dist/UI/Utils/Breadcrumb/BreadcrumbTrailResolver.js.map +1 -0
- package/build/dist/UI/Utils/NotificationMethodUtil.js +189 -0
- package/build/dist/UI/Utils/NotificationMethodUtil.js.map +1 -0
- package/build/dist/Utils/CronTab.js +609 -0
- package/build/dist/Utils/CronTab.js.map +1 -0
- package/build/dist/Utils/ModelImportExport.js +20 -6
- package/build/dist/Utils/ModelImportExport.js.map +1 -1
- package/build/dist/Utils/VersionUtil.js +193 -0
- package/build/dist/Utils/VersionUtil.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import ToolResultSerializer from "../AI/Toolbox/Serializer";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Shared exception-text sanitization.
|
|
5
|
+
*
|
|
6
|
+
* normalizeExceptionText is the fingerprint normalizer that used to live
|
|
7
|
+
* in App/FeatureSet/Telemetry/Utils/Exception.ts — it was moved here (the
|
|
8
|
+
* App util now delegates) so server-side consumers in Common (the AI
|
|
9
|
+
* agent data API) can sanitize exception messages before they reach LLM
|
|
10
|
+
* prompts, pull-request text, and commit messages. The replacement
|
|
11
|
+
* behavior MUST stay byte-for-byte stable: fingerprints are computed from
|
|
12
|
+
* its output, and changing it regroups every existing exception.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Normalizes a string by replacing dynamic values with placeholders.
|
|
17
|
+
* This ensures that exceptions with the same root cause but different
|
|
18
|
+
* dynamic values (like IDs, timestamps, etc.) get the same fingerprint.
|
|
19
|
+
*
|
|
20
|
+
* @param text - The text to normalize (message or stack trace)
|
|
21
|
+
* @returns The normalized text with dynamic values replaced
|
|
22
|
+
*/
|
|
23
|
+
export function normalizeExceptionText(text: string): string {
|
|
24
|
+
if (!text) {
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let normalized: string = text;
|
|
29
|
+
|
|
30
|
+
// Order matters! More specific patterns should come before generic ones.
|
|
31
|
+
|
|
32
|
+
// 1. UUIDs (e.g., 550e8400-e29b-41d4-a716-446655440000)
|
|
33
|
+
normalized = normalized.replace(
|
|
34
|
+
/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,
|
|
35
|
+
"<UUID>",
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// 2. MongoDB ObjectIDs (24 hex characters)
|
|
39
|
+
normalized = normalized.replace(/\b[0-9a-f]{24}\b/gi, "<OBJECT_ID>");
|
|
40
|
+
|
|
41
|
+
/*
|
|
42
|
+
* 3. Stripe-style IDs (e.g., sub_xxx, cus_xxx, pi_xxx, ch_xxx, etc.)
|
|
43
|
+
* These have a prefix followed by underscore and alphanumeric characters
|
|
44
|
+
*/
|
|
45
|
+
normalized = normalized.replace(
|
|
46
|
+
/\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,
|
|
47
|
+
"<STRIPE_ID>",
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
* 4. Generic API/Service IDs - alphanumeric strings that look like IDs
|
|
52
|
+
* Matches patterns like: prefix_alphanumeric or just long alphanumeric strings
|
|
53
|
+
* Common in many services (AWS, GCP, etc.)
|
|
54
|
+
*/
|
|
55
|
+
normalized = normalized.replace(
|
|
56
|
+
/\b[a-z]{2,10}_[A-Za-z0-9]{8,}\b/g,
|
|
57
|
+
"<SERVICE_ID>",
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// 5. JWT tokens (three base64 segments separated by dots)
|
|
61
|
+
normalized = normalized.replace(
|
|
62
|
+
/\beyJ[A-Za-z0-9_-]*\.eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\b/g,
|
|
63
|
+
"<JWT>",
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
// 6. Base64 encoded strings (long sequences, likely tokens or encoded data)
|
|
67
|
+
normalized = normalized.replace(/\b[A-Za-z0-9+/]{40,}={0,2}\b/g, "<BASE64>");
|
|
68
|
+
|
|
69
|
+
// 7. IP addresses (IPv4)
|
|
70
|
+
normalized = normalized.replace(
|
|
71
|
+
/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g,
|
|
72
|
+
"<IP>",
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// 8. IP addresses (IPv6) - simplified pattern
|
|
76
|
+
normalized = normalized.replace(
|
|
77
|
+
/\b(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\b/g,
|
|
78
|
+
"<IPV6>",
|
|
79
|
+
);
|
|
80
|
+
normalized = normalized.replace(/\b::1\b/g, "<IPV6>"); // localhost IPv6
|
|
81
|
+
|
|
82
|
+
// 9. Email addresses
|
|
83
|
+
normalized = normalized.replace(
|
|
84
|
+
/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g,
|
|
85
|
+
"<EMAIL>",
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
/*
|
|
89
|
+
* 10. URLs with dynamic paths/query params (normalize the dynamic parts)
|
|
90
|
+
* Keep the domain but normalize path segments that look like IDs
|
|
91
|
+
*/
|
|
92
|
+
normalized = normalized.replace(
|
|
93
|
+
/\/[0-9a-f]{8,}(?=\/|$|\?|#|\s|'|")/gi,
|
|
94
|
+
"/<ID>",
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
/*
|
|
98
|
+
* 11. Timestamps in various formats
|
|
99
|
+
* ISO 8601 timestamps
|
|
100
|
+
*/
|
|
101
|
+
normalized = normalized.replace(
|
|
102
|
+
/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?/g,
|
|
103
|
+
"<TIMESTAMP>",
|
|
104
|
+
);
|
|
105
|
+
// Unix timestamps (10 or 13 digits)
|
|
106
|
+
normalized = normalized.replace(/\b1[0-9]{9,12}\b/g, "<TIMESTAMP>");
|
|
107
|
+
|
|
108
|
+
// 12. Date formats (YYYY-MM-DD, MM/DD/YYYY, etc.)
|
|
109
|
+
normalized = normalized.replace(/\b\d{4}[-/]\d{2}[-/]\d{2}\b/g, "<DATE>");
|
|
110
|
+
normalized = normalized.replace(/\b\d{2}[-/]\d{2}[-/]\d{4}\b/g, "<DATE>");
|
|
111
|
+
|
|
112
|
+
// 13. Time formats (HH:MM:SS, HH:MM)
|
|
113
|
+
normalized = normalized.replace(/\b\d{2}:\d{2}(?::\d{2})?\b/g, "<TIME>");
|
|
114
|
+
|
|
115
|
+
// 14. Memory addresses (0x followed by hex)
|
|
116
|
+
normalized = normalized.replace(/\b0x[0-9a-fA-F]+\b/g, "<MEMORY_ADDR>");
|
|
117
|
+
|
|
118
|
+
// 15. Session IDs (common patterns) - MUST come before hex ID pattern
|
|
119
|
+
normalized = normalized.replace(
|
|
120
|
+
/\bsession[_-]?id[=:\s]*['"]?[A-Za-z0-9_-]+['"]?/gi,
|
|
121
|
+
"session_id=<SESSION>",
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// 16. Request IDs (common patterns) - MUST come before hex ID pattern
|
|
125
|
+
normalized = normalized.replace(
|
|
126
|
+
/\brequest[_-]?id[=:\s]*['"]?[A-Za-z0-9_-]+['"]?/gi,
|
|
127
|
+
"request_id=<REQUEST>",
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
// 17. Correlation IDs - MUST come before hex ID pattern
|
|
131
|
+
normalized = normalized.replace(
|
|
132
|
+
/\bcorrelation[_-]?id[=:\s]*['"]?[A-Za-z0-9_-]+['"]?/gi,
|
|
133
|
+
"correlation_id=<CORRELATION>",
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
// 18. Transaction IDs - MUST come before hex ID pattern
|
|
137
|
+
normalized = normalized.replace(
|
|
138
|
+
/\btransaction[_-]?id[=:\s]*['"]?[A-Za-z0-9_-]+['"]?/gi,
|
|
139
|
+
"transaction_id=<TRANSACTION>",
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
// 19. Hex strings that are likely IDs (8+ chars)
|
|
143
|
+
normalized = normalized.replace(/\b[0-9a-f]{8,}\b/gi, "<HEX_ID>");
|
|
144
|
+
|
|
145
|
+
/*
|
|
146
|
+
* 20. Quoted strings containing IDs or dynamic values
|
|
147
|
+
* Match strings in single or double quotes that look like IDs
|
|
148
|
+
*/
|
|
149
|
+
normalized = normalized.replace(/'[A-Za-z0-9_-]{16,}'/g, "'<ID>'");
|
|
150
|
+
normalized = normalized.replace(/"[A-Za-z0-9_-]{16,}"/g, '"<ID>"');
|
|
151
|
+
|
|
152
|
+
// 21. Port numbers in URLs or connection strings
|
|
153
|
+
normalized = normalized.replace(/:(\d{4,5})(?=\/|$|\s)/g, ":<PORT>");
|
|
154
|
+
|
|
155
|
+
/*
|
|
156
|
+
* 22. Line numbers in stack traces (keep for context, but normalize large numbers)
|
|
157
|
+
* This normalizes specific line/column references that might vary
|
|
158
|
+
*/
|
|
159
|
+
normalized = normalized.replace(/:\d+:\d+\)?$/gm, ":<LINE>:<COL>)");
|
|
160
|
+
|
|
161
|
+
// 23. Process/Thread IDs
|
|
162
|
+
normalized = normalized.replace(/\bPID[:\s]*\d+\b/gi, "PID:<PID>");
|
|
163
|
+
normalized = normalized.replace(/\bTID[:\s]*\d+\b/gi, "TID:<TID>");
|
|
164
|
+
|
|
165
|
+
// 24. Numeric IDs in common patterns (id=123, id: 123, etc.)
|
|
166
|
+
normalized = normalized.replace(/\bid[=:\s]*['"]?\d+['"]?/gi, "id=<ID>");
|
|
167
|
+
|
|
168
|
+
// 25. Large numbers that are likely IDs (more than 6 digits)
|
|
169
|
+
normalized = normalized.replace(/\b\d{7,}\b/g, "<NUMBER>");
|
|
170
|
+
|
|
171
|
+
return normalized;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Sanitize an exception message for surfaces that leave the platform:
|
|
176
|
+
* LLM prompts, pull-request titles/bodies, and commit messages.
|
|
177
|
+
*
|
|
178
|
+
* Normalization replaces the dynamic tokens (UUIDs, emails, IPs, IDs,
|
|
179
|
+
* timestamps...) that carry user data, then the secret redactor sweeps
|
|
180
|
+
* whatever is left (bearer tokens, API keys, cards...). The message
|
|
181
|
+
* keeps its structure — "invalid input syntax for type uuid: <HEX_ID>"
|
|
182
|
+
* is still perfectly actionable for a fix.
|
|
183
|
+
*/
|
|
184
|
+
export function sanitizeExceptionMessage(message: string): string {
|
|
185
|
+
if (!message) {
|
|
186
|
+
return "";
|
|
187
|
+
}
|
|
188
|
+
return ToolResultSerializer.redact(normalizeExceptionText(message)).text;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Sanitize a stack trace for the same surfaces.
|
|
193
|
+
*
|
|
194
|
+
* Runtimes prefix the native stack string with the exception MESSAGE
|
|
195
|
+
* ("Error: <message>" in Node, "ValueError: <message>" in Python
|
|
196
|
+
* headers, "Caused by: ..." in Java) — so a redact-only pass would leak
|
|
197
|
+
* the very identifiers sanitizeExceptionMessage strips. Frame lines are
|
|
198
|
+
* indented (" at fn (file:42:7)", ' File "x.py", line 3', "\tat ...")
|
|
199
|
+
* and must keep exact file:line references for the code agent, so the
|
|
200
|
+
* split is: unindented header/message lines get full normalization,
|
|
201
|
+
* indented frame lines are left intact, and the secret redactor sweeps
|
|
202
|
+
* everything at the end.
|
|
203
|
+
*/
|
|
204
|
+
// Frame lines are indented; header/message lines are not.
|
|
205
|
+
const INDENTED_FRAME_LINE_REGEX: RegExp = /^\s/;
|
|
206
|
+
|
|
207
|
+
export function sanitizeStackTrace(stackTrace: string): string {
|
|
208
|
+
if (!stackTrace) {
|
|
209
|
+
return "";
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const normalized: string = stackTrace
|
|
213
|
+
.split("\n")
|
|
214
|
+
.map((line: string): string => {
|
|
215
|
+
return INDENTED_FRAME_LINE_REGEX.test(line)
|
|
216
|
+
? line
|
|
217
|
+
: normalizeExceptionText(line);
|
|
218
|
+
})
|
|
219
|
+
.join("\n");
|
|
220
|
+
|
|
221
|
+
return ToolResultSerializer.redact(normalized).text;
|
|
222
|
+
}
|