@resolveio/server-lib 22.2.4 → 22.2.7

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 (45) hide show
  1. package/collections/app-setting.collection.d.ts +3 -0
  2. package/collections/app-setting.collection.js +103 -0
  3. package/collections/app-setting.collection.js.map +1 -0
  4. package/managers/customer-notification-content.manager.d.ts +55 -0
  5. package/managers/customer-notification-content.manager.js +158 -0
  6. package/managers/customer-notification-content.manager.js.map +1 -0
  7. package/managers/diagnostic-manager-bootstrap.d.ts +9 -0
  8. package/managers/diagnostic-manager-bootstrap.js +260 -0
  9. package/managers/diagnostic-manager-bootstrap.js.map +1 -0
  10. package/managers/error-auto-fix.manager.d.ts +143 -0
  11. package/managers/error-auto-fix.manager.js +2934 -0
  12. package/managers/error-auto-fix.manager.js.map +1 -0
  13. package/managers/method.manager.js +2 -0
  14. package/managers/method.manager.js.map +1 -1
  15. package/managers/slow-query-verifier.manager.d.ts +114 -0
  16. package/managers/slow-query-verifier.manager.js +3358 -0
  17. package/managers/slow-query-verifier.manager.js.map +1 -0
  18. package/managers/slow-query.manager.d.ts +28 -0
  19. package/managers/slow-query.manager.js +468 -0
  20. package/managers/slow-query.manager.js.map +1 -0
  21. package/managers/subscription.manager.js +2 -0
  22. package/managers/subscription.manager.js.map +1 -1
  23. package/methods/app-settings.d.ts +2 -0
  24. package/methods/app-settings.js +169 -0
  25. package/methods/app-settings.js.map +1 -0
  26. package/methods/customer-notifications.js +77 -9
  27. package/methods/customer-notifications.js.map +1 -1
  28. package/methods.ts +3 -0
  29. package/models/app-setting.model.d.ts +16 -0
  30. package/models/app-setting.model.js +4 -0
  31. package/models/app-setting.model.js.map +1 -0
  32. package/package.json +3 -1
  33. package/public_api.d.ts +9 -0
  34. package/public_api.js +9 -0
  35. package/public_api.js.map +1 -1
  36. package/publications/app-settings.d.ts +2 -0
  37. package/publications/app-settings.js +28 -0
  38. package/publications/app-settings.js.map +1 -0
  39. package/publications.ts +6 -0
  40. package/types/error-report.d.ts +25 -0
  41. package/types/error-report.js +4 -0
  42. package/types/error-report.js.map +1 -0
  43. package/types/slow-query-report.d.ts +27 -0
  44. package/types/slow-query-report.js +6 -0
  45. package/types/slow-query-report.js.map +1 -0
@@ -0,0 +1,3 @@
1
+ import { MongoManagerCollection } from '../managers/mongo.manager';
2
+ import { AppSettingModel } from '../models/app-setting.model';
3
+ export declare let AppSettings: MongoManagerCollection<AppSettingModel>;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppSettings = void 0;
4
+ var mongo_manager_1 = require("../managers/mongo.manager");
5
+ var resolveio_server_app_1 = require("../resolveio-server-app");
6
+ var schema = {
7
+ _id: {
8
+ type: String,
9
+ optional: true
10
+ },
11
+ __v: {
12
+ type: Number,
13
+ optional: true
14
+ },
15
+ updatedAt: {
16
+ type: Date,
17
+ optional: true
18
+ },
19
+ createdAt: {
20
+ type: Date,
21
+ optional: true
22
+ },
23
+ company_name: {
24
+ type: String,
25
+ optional: true
26
+ },
27
+ timezone: {
28
+ type: String,
29
+ optional: true
30
+ },
31
+ currency: {
32
+ type: String,
33
+ optional: true
34
+ },
35
+ invoice_prefix: {
36
+ type: String,
37
+ optional: true
38
+ },
39
+ support_email: {
40
+ type: String,
41
+ optional: true
42
+ },
43
+ support_phone: {
44
+ type: String,
45
+ optional: true
46
+ },
47
+ support_address: {
48
+ type: String,
49
+ optional: true
50
+ },
51
+ notes: {
52
+ type: String,
53
+ optional: true
54
+ },
55
+ enable_ai: {
56
+ type: Boolean,
57
+ optional: true
58
+ },
59
+ enable_auto_fix: {
60
+ type: Boolean,
61
+ optional: true
62
+ },
63
+ enable_slow_query_optimizer: {
64
+ type: Boolean,
65
+ optional: true
66
+ },
67
+ custom_settings: {
68
+ type: Object,
69
+ optional: true,
70
+ blackbox: true
71
+ },
72
+ is_active: {
73
+ type: Boolean,
74
+ optional: true
75
+ }
76
+ };
77
+ exports.AppSettings = null;
78
+ initializeCollection();
79
+ function initializeCollection() {
80
+ if (resolveio_server_app_1.ResolveIOServer && resolveio_server_app_1.ResolveIOServer.getMainDB() && mongo_manager_1.MongoManagerModel) {
81
+ var model = mongo_manager_1.MongoManagerModel.create({
82
+ collectionName: 'app-settings',
83
+ schema: schema,
84
+ useVersionCollection: true,
85
+ useReportBuilder: false,
86
+ reportBuilderLookupTables: [],
87
+ timestamps: true,
88
+ createLogs: true,
89
+ checkSchema: true,
90
+ collectionOptions: null
91
+ });
92
+ exports.AppSettings = model.collection_main;
93
+ exports.AppSettings.createIndex({ company_name: 1 });
94
+ exports.AppSettings.createIndex({ is_active: 1 });
95
+ }
96
+ else {
97
+ setImmediate(function () {
98
+ initializeCollection();
99
+ });
100
+ }
101
+ }
102
+
103
+ //# sourceMappingURL=app-setting.collection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/collections/app-setting.collection.ts"],"names":[],"mappings":";;;AAAA,2DAAsF;AAEtF,gEAA0D;AAE1D,IAAI,MAAM,GAAQ;IACjB,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;IACD,YAAY,EAAE;QACb,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,cAAc,EAAE;QACf,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,aAAa,EAAE;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7C,mBAAW,CAAC,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;IAC3C,CAAC;SACI,CAAC;QACL,YAAY,CAAC;YACZ,oBAAoB,EAAE,CAAC;QACxB,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC","file":"app-setting.collection.js","sourcesContent":["import { MongoManagerCollection, MongoManagerModel } from '../managers/mongo.manager';\nimport { AppSettingModel } from '../models/app-setting.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\n\nlet schema: any = {\n\t_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t__v: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tupdatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tcreatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tcompany_name: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\ttimezone: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tcurrency: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tinvoice_prefix: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tsupport_email: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tsupport_phone: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tsupport_address: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tnotes: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tenable_ai: {\n\t\ttype: Boolean,\n\t\toptional: true\n\t},\n\tenable_auto_fix: {\n\t\ttype: Boolean,\n\t\toptional: true\n\t},\n\tenable_slow_query_optimizer: {\n\t\ttype: Boolean,\n\t\toptional: true\n\t},\n\tcustom_settings: {\n\t\ttype: Object,\n\t\toptional: true,\n\t\tblackbox: true\n\t},\n\tis_active: {\n\t\ttype: Boolean,\n\t\toptional: true\n\t}\n};\n\nexport let AppSettings: MongoManagerCollection<AppSettingModel> = null;\n\ninitializeCollection();\n\nfunction initializeCollection() {\n\tif (ResolveIOServer && ResolveIOServer.getMainDB() && MongoManagerModel) {\n\t\tconst model = MongoManagerModel.create<AppSettingModel>({\n\t\t\tcollectionName: 'app-settings',\n\t\t\tschema: schema,\n\t\t\tuseVersionCollection: true,\n\t\t\tuseReportBuilder: false,\n\t\t\treportBuilderLookupTables: [],\n\t\t\ttimestamps: true,\n\t\t\tcreateLogs: true,\n\t\t\tcheckSchema: true,\n\t\t\tcollectionOptions: null\n\t\t});\n\n\t\tAppSettings = model.collection_main;\n\t\tAppSettings.createIndex({ company_name: 1 });\n\t\tAppSettings.createIndex({ is_active: 1 });\n\t}\n\telse {\n\t\tsetImmediate(() => {\n\t\t\tinitializeCollection();\n\t\t});\n\t}\n}\n"]}
@@ -0,0 +1,55 @@
1
+ export type AutoFixWorkflowStage = 'detected_autofix_enabled' | 'detected_autofix_disabled' | 'completed_success' | 'completed_failed' | 'blocked_library_issue';
2
+ export type SlowQueryWorkflowStage = 'detected_auto_optimize_enabled' | 'completed_success' | 'completed_failed';
3
+ export interface GeneratedAutoFixSummaryContext {
4
+ source_app?: string;
5
+ environment?: string;
6
+ severity?: string;
7
+ error?: string;
8
+ }
9
+ export interface ResolveIOProjectAutoFixDetailsContext {
10
+ client_name?: string;
11
+ issue_counter?: string;
12
+ source_app?: string;
13
+ environment?: string;
14
+ severity?: string;
15
+ summary?: string;
16
+ branch_name?: string;
17
+ pr_url?: string;
18
+ issue_hash?: string;
19
+ log_id?: string;
20
+ notes?: string;
21
+ error?: string;
22
+ }
23
+ export interface GeneratedSlowQuerySummaryContext {
24
+ collection?: string;
25
+ source_app?: string;
26
+ environment?: string;
27
+ baseline_duration_ms?: number;
28
+ after_duration_ms?: number;
29
+ reason?: string;
30
+ notes?: string;
31
+ }
32
+ export interface ResolveIOProjectSlowQueryDetailsContext {
33
+ collection?: string;
34
+ client_name?: string;
35
+ client_slug?: string;
36
+ source_app?: string;
37
+ environment?: string;
38
+ query_hash?: string;
39
+ baseline_duration_ms?: number;
40
+ after_duration_ms?: number;
41
+ verification_run_durations_ms?: number[];
42
+ log_id?: string;
43
+ reason?: string;
44
+ notes?: string;
45
+ }
46
+ export declare function buildGeneratedAppAutoFixSummary(stage: AutoFixWorkflowStage, context: GeneratedAutoFixSummaryContext, extra?: {
47
+ error?: string;
48
+ notes?: string;
49
+ }): string;
50
+ export declare function buildResolveIOProjectAutoFixDetails(context: ResolveIOProjectAutoFixDetailsContext): string;
51
+ export declare function buildGeneratedSlowQuerySummary(stage: SlowQueryWorkflowStage, context: GeneratedSlowQuerySummaryContext, extra?: {
52
+ reason?: string;
53
+ notes?: string;
54
+ }): string;
55
+ export declare function buildResolveIOProjectSlowQueryDetails(context: ResolveIOProjectSlowQueryDetailsContext): string;
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildGeneratedAppAutoFixSummary = buildGeneratedAppAutoFixSummary;
4
+ exports.buildResolveIOProjectAutoFixDetails = buildResolveIOProjectAutoFixDetails;
5
+ exports.buildGeneratedSlowQuerySummary = buildGeneratedSlowQuerySummary;
6
+ exports.buildResolveIOProjectSlowQueryDetails = buildResolveIOProjectSlowQueryDetails;
7
+ var common_1 = require("../util/common");
8
+ function normalizeText(value, fallback) {
9
+ if (fallback === void 0) { fallback = ''; }
10
+ var normalized = String(value || '').trim();
11
+ return normalized || fallback;
12
+ }
13
+ function normalizeDuration(value) {
14
+ var parsed = Number(value);
15
+ if (!Number.isFinite(parsed) || parsed < 0) {
16
+ return null;
17
+ }
18
+ return parsed;
19
+ }
20
+ function formatDuration(value) {
21
+ var duration = normalizeDuration(value);
22
+ if (duration === null) {
23
+ return 'unknown';
24
+ }
25
+ return "".concat((0, common_1.round)(duration, 0).toLocaleString(), " ms");
26
+ }
27
+ function buildGeneratedAppAutoFixSummary(stage, context, extra) {
28
+ var sourceApp = normalizeText(context === null || context === void 0 ? void 0 : context.source_app, 'your app');
29
+ var environment = normalizeText(context === null || context === void 0 ? void 0 : context.environment, 'production');
30
+ var severity = normalizeText(context === null || context === void 0 ? void 0 : context.severity, 'issue');
31
+ if (stage === 'detected_autofix_enabled') {
32
+ return [
33
+ "What happened: We found a ".concat(severity, " in ").concat(sourceApp, "."),
34
+ "Where: ".concat(environment, "."),
35
+ 'What happens next: Auto-fix is running. You will get another notice when it is done.'
36
+ ].join('\n');
37
+ }
38
+ if (stage === 'detected_autofix_disabled') {
39
+ return [
40
+ "What happened: We found a ".concat(severity, " in ").concat(sourceApp, "."),
41
+ "Where: ".concat(environment, "."),
42
+ 'What happens next: Auto-fix is disabled, so this needs a manual follow-up.'
43
+ ].join('\n');
44
+ }
45
+ if (stage === 'completed_success') {
46
+ return [
47
+ "What happened: We fixed an issue in ".concat(sourceApp, "."),
48
+ "Where: ".concat(environment, "."),
49
+ 'What to do: No action is needed unless you still see the same problem.'
50
+ ].join('\n');
51
+ }
52
+ if (stage === 'blocked_library_issue') {
53
+ return [
54
+ "What happened: The issue in ".concat(sourceApp, " is tied to shared platform code."),
55
+ 'What happens next: Engineering has been notified to ship a platform-level update.',
56
+ 'What to do: Wait for the next platform update notice.'
57
+ ].join('\n');
58
+ }
59
+ return [
60
+ "What happened: We investigated an issue in ".concat(sourceApp, " but could not complete an automatic fix."),
61
+ "Where: ".concat(environment, "."),
62
+ "Why: ".concat((extra === null || extra === void 0 ? void 0 : extra.error) || (context === null || context === void 0 ? void 0 : context.error) || 'Manual review is required.'),
63
+ 'What to do: Ask the team to review this issue manually.'
64
+ ].join('\n');
65
+ }
66
+ function buildResolveIOProjectAutoFixDetails(context) {
67
+ var lines = [
68
+ 'Auto-fix completed for a ResolveIO project.',
69
+ '',
70
+ "Client: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.client_name, 'unknown')),
71
+ "Issue Counter: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.issue_counter, 'n/a')),
72
+ "Source App: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.source_app, 'unknown')),
73
+ "Environment: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.environment, 'unknown')),
74
+ "Severity: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.severity, 'error')),
75
+ "Summary: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.summary, 'Auto-fix completed.')),
76
+ "Branch: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.branch_name, 'unknown')),
77
+ "PR URL: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.pr_url, 'n/a')),
78
+ "Issue Hash: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.issue_hash, 'n/a')),
79
+ "Log ID: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.log_id, 'n/a'))
80
+ ];
81
+ if (normalizeText(context === null || context === void 0 ? void 0 : context.notes)) {
82
+ lines.push("Notes: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.notes)));
83
+ }
84
+ if (normalizeText(context === null || context === void 0 ? void 0 : context.error)) {
85
+ lines.push("Error: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.error)));
86
+ }
87
+ return lines.join('\n');
88
+ }
89
+ function buildGeneratedSlowQuerySummary(stage, context, extra) {
90
+ var collection = normalizeText(context === null || context === void 0 ? void 0 : context.collection, 'a collection');
91
+ var sourceApp = normalizeText(context === null || context === void 0 ? void 0 : context.source_app, 'your app');
92
+ var environment = normalizeText(context === null || context === void 0 ? void 0 : context.environment, 'production');
93
+ var baselineDuration = normalizeDuration(context === null || context === void 0 ? void 0 : context.baseline_duration_ms);
94
+ var afterDuration = normalizeDuration(context === null || context === void 0 ? void 0 : context.after_duration_ms);
95
+ var hasDurations = baselineDuration !== null && afterDuration !== null && baselineDuration > 0;
96
+ var improvementPct = hasDurations
97
+ ? Math.max(0, ((baselineDuration - afterDuration) / baselineDuration) * 100)
98
+ : null;
99
+ if (stage === 'detected_auto_optimize_enabled') {
100
+ return [
101
+ "What happened: We found a slow operation in ".concat(collection, "."),
102
+ "Where: ".concat(sourceApp, " (").concat(environment, ")."),
103
+ 'What happens next: Auto-optimization is running and we will send another update when done.'
104
+ ].join('\n');
105
+ }
106
+ if (stage === 'completed_success') {
107
+ return [
108
+ "What happened: We optimized slow performance for ".concat(collection, "."),
109
+ "Where: ".concat(sourceApp, " (").concat(environment, ")."),
110
+ hasDurations
111
+ ? "Estimated improvement: about ".concat((0, common_1.round)(improvementPct, 1), "% faster response time.")
112
+ : 'Estimated improvement: performance is now better than before.',
113
+ 'What to do: No action is needed unless you still notice slow behavior.'
114
+ ].join('\n');
115
+ }
116
+ return [
117
+ "What happened: We could not safely complete automatic optimization for ".concat(collection, "."),
118
+ "Where: ".concat(sourceApp, " (").concat(environment, ")."),
119
+ "Why: ".concat((extra === null || extra === void 0 ? void 0 : extra.reason) || (extra === null || extra === void 0 ? void 0 : extra.notes) || (context === null || context === void 0 ? void 0 : context.reason) || (context === null || context === void 0 ? void 0 : context.notes) || 'Manual review is required.'),
120
+ 'What to do: Ask the team to review this slow operation manually.'
121
+ ].join('\n');
122
+ }
123
+ function buildResolveIOProjectSlowQueryDetails(context) {
124
+ var baselineDuration = normalizeDuration(context === null || context === void 0 ? void 0 : context.baseline_duration_ms);
125
+ var afterDuration = normalizeDuration(context === null || context === void 0 ? void 0 : context.after_duration_ms);
126
+ var hasDurations = baselineDuration !== null && afterDuration !== null && baselineDuration > 0;
127
+ var improvementPct = hasDurations
128
+ ? (0, common_1.round)(((baselineDuration - afterDuration) / baselineDuration) * 100, 1)
129
+ : null;
130
+ var runDurations = Array.isArray(context === null || context === void 0 ? void 0 : context.verification_run_durations_ms)
131
+ ? context.verification_run_durations_ms
132
+ .map(function (duration) { return formatDuration(duration); })
133
+ .filter(Boolean)
134
+ : [];
135
+ var lines = [
136
+ 'Slow-query optimization completed for a ResolveIO project.',
137
+ '',
138
+ "Collection: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.collection, 'unknown')),
139
+ "Client: ".concat(normalizeText((context === null || context === void 0 ? void 0 : context.client_name) || (context === null || context === void 0 ? void 0 : context.client_slug), 'unknown')),
140
+ "Source App: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.source_app, 'unknown')),
141
+ "Environment: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.environment, 'unknown')),
142
+ "Query Hash: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.query_hash, 'n/a')),
143
+ hasDurations
144
+ ? "Performance Change: ".concat((0, common_1.round)(baselineDuration, 0), " ms -> ").concat((0, common_1.round)(afterDuration, 0), " ms (").concat(improvementPct, "%)")
145
+ : 'Performance Change: available in slow-query logs.',
146
+ "Verification Runs: ".concat(runDurations.join(', ') || 'n/a'),
147
+ "Log ID: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.log_id, 'n/a'))
148
+ ];
149
+ if (normalizeText(context === null || context === void 0 ? void 0 : context.notes)) {
150
+ lines.push("Notes: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.notes)));
151
+ }
152
+ if (normalizeText(context === null || context === void 0 ? void 0 : context.reason)) {
153
+ lines.push("Reason: ".concat(normalizeText(context === null || context === void 0 ? void 0 : context.reason)));
154
+ }
155
+ return lines.join('\n');
156
+ }
157
+
158
+ //# sourceMappingURL=customer-notification-content.manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/managers/customer-notification-content.manager.ts"],"names":[],"mappings":";;AAkFA,0EA+CC;AAED,kFAwBC;AAED,wEAwCC;AAED,sFAoCC;AA3OD,yCAAuC;AA6DvC,SAAS,aAAa,CAAC,KAAU,EAAE,QAAa;IAAb,yBAAA,EAAA,aAAa;IAC/C,IAAM,UAAU,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9C,OAAO,UAAU,IAAI,QAAQ,CAAC;AAC/B,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAU;IACpC,IAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QA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AAE;QAC9D,uBAAgB,aAAa,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAE,SAAS,CAAC,CAAE;QAChE,sBAAe,aAAa,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,EAAE,KAAK,CAAC,CAAE;QAC1D,YAAY;YACX,CAAC,CAAC,8BAAuB,IAAA,cAAK,EAAC,gBAAgB,EAAE,CAAC,CAAC,oBAAU,IAAA,cAAK,EAAC,aAAa,EAAE,CAAC,CAAC,kBAAQ,cAAc,OAAI;YAC9G,CAAC,CAAC,mDAAmD;QACtD,6BAAsB,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,CAAE;QACxD,kBAAW,aAAa,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,EAAE,KAAK,CAAC,CAAE;KAClD,CAAC;IAEF,IAAI,aAAa,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAC,EAAE,CAAC;QACnC,KAAK,CAAC,IAAI,CAAC,iBAAU,aAAa,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAC,CAAE,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,aAAa,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC,EAAE,CAAC;QACpC,KAAK,CAAC,IAAI,CAAC,kBAAW,aAAa,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC,CAAE,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC","file":"customer-notification-content.manager.js","sourcesContent":["import { round } from '../util/common';\n\nexport type AutoFixWorkflowStage =\n\t'detected_autofix_enabled' |\n\t'detected_autofix_disabled' |\n\t'completed_success' |\n\t'completed_failed' |\n\t'blocked_library_issue';\n\nexport type SlowQueryWorkflowStage =\n\t'detected_auto_optimize_enabled' |\n\t'completed_success' |\n\t'completed_failed';\n\nexport interface GeneratedAutoFixSummaryContext {\n\tsource_app?: string;\n\tenvironment?: string;\n\tseverity?: string;\n\terror?: string;\n}\n\nexport interface ResolveIOProjectAutoFixDetailsContext {\n\tclient_name?: string;\n\tissue_counter?: string;\n\tsource_app?: string;\n\tenvironment?: string;\n\tseverity?: string;\n\tsummary?: string;\n\tbranch_name?: string;\n\tpr_url?: string;\n\tissue_hash?: string;\n\tlog_id?: string;\n\tnotes?: string;\n\terror?: string;\n}\n\nexport interface GeneratedSlowQuerySummaryContext {\n\tcollection?: string;\n\tsource_app?: string;\n\tenvironment?: string;\n\tbaseline_duration_ms?: number;\n\tafter_duration_ms?: number;\n\treason?: string;\n\tnotes?: string;\n}\n\nexport interface ResolveIOProjectSlowQueryDetailsContext {\n\tcollection?: string;\n\tclient_name?: string;\n\tclient_slug?: string;\n\tsource_app?: string;\n\tenvironment?: string;\n\tquery_hash?: string;\n\tbaseline_duration_ms?: number;\n\tafter_duration_ms?: number;\n\tverification_run_durations_ms?: number[];\n\tlog_id?: string;\n\treason?: string;\n\tnotes?: string;\n}\n\nfunction normalizeText(value: any, fallback = ''): string {\n\tconst normalized = String(value || '').trim();\n\treturn normalized || fallback;\n}\n\nfunction normalizeDuration(value: any): number | null {\n\tconst parsed = Number(value);\n\tif (!Number.isFinite(parsed) || parsed < 0) {\n\t\treturn null;\n\t}\n\treturn parsed;\n}\n\nfunction formatDuration(value: any): string {\n\tconst duration = normalizeDuration(value);\n\tif (duration === null) {\n\t\treturn 'unknown';\n\t}\n\treturn `${round(duration, 0).toLocaleString()} ms`;\n}\n\nexport function buildGeneratedAppAutoFixSummary(\n\tstage: AutoFixWorkflowStage,\n\tcontext: GeneratedAutoFixSummaryContext,\n\textra?: { error?: string; notes?: string }\n): string {\n\tconst sourceApp = normalizeText(context?.source_app, 'your app');\n\tconst environment = normalizeText(context?.environment, 'production');\n\tconst severity = normalizeText(context?.severity, 'issue');\n\n\tif (stage === 'detected_autofix_enabled') {\n\t\treturn [\n\t\t\t`What happened: We found a ${severity} in ${sourceApp}.`,\n\t\t\t`Where: ${environment}.`,\n\t\t\t'What happens next: Auto-fix is running. You will get another notice when it is done.'\n\t\t].join('\\n');\n\t}\n\n\tif (stage === 'detected_autofix_disabled') {\n\t\treturn [\n\t\t\t`What happened: We found a ${severity} in ${sourceApp}.`,\n\t\t\t`Where: ${environment}.`,\n\t\t\t'What happens next: Auto-fix is disabled, so this needs a manual follow-up.'\n\t\t].join('\\n');\n\t}\n\n\tif (stage === 'completed_success') {\n\t\treturn [\n\t\t\t`What happened: We fixed an issue in ${sourceApp}.`,\n\t\t\t`Where: ${environment}.`,\n\t\t\t'What to do: No action is needed unless you still see the same problem.'\n\t\t].join('\\n');\n\t}\n\n\tif (stage === 'blocked_library_issue') {\n\t\treturn [\n\t\t\t`What happened: The issue in ${sourceApp} is tied to shared platform code.`,\n\t\t\t'What happens next: Engineering has been notified to ship a platform-level update.',\n\t\t\t'What to do: Wait for the next platform update notice.'\n\t\t].join('\\n');\n\t}\n\n\treturn [\n\t\t`What happened: We investigated an issue in ${sourceApp} but could not complete an automatic fix.`,\n\t\t`Where: ${environment}.`,\n\t\t`Why: ${extra?.error || context?.error || 'Manual review is required.'}`,\n\t\t'What to do: Ask the team to review this issue manually.'\n\t].join('\\n');\n}\n\nexport function buildResolveIOProjectAutoFixDetails(context: ResolveIOProjectAutoFixDetailsContext): string {\n\tconst lines = [\n\t\t'Auto-fix completed for a ResolveIO project.',\n\t\t'',\n\t\t`Client: ${normalizeText(context?.client_name, 'unknown')}`,\n\t\t`Issue Counter: ${normalizeText(context?.issue_counter, 'n/a')}`,\n\t\t`Source App: ${normalizeText(context?.source_app, 'unknown')}`,\n\t\t`Environment: ${normalizeText(context?.environment, 'unknown')}`,\n\t\t`Severity: ${normalizeText(context?.severity, 'error')}`,\n\t\t`Summary: ${normalizeText(context?.summary, 'Auto-fix completed.')}`,\n\t\t`Branch: ${normalizeText(context?.branch_name, 'unknown')}`,\n\t\t`PR URL: ${normalizeText(context?.pr_url, 'n/a')}`,\n\t\t`Issue Hash: ${normalizeText(context?.issue_hash, 'n/a')}`,\n\t\t`Log ID: ${normalizeText(context?.log_id, 'n/a')}`\n\t];\n\n\tif (normalizeText(context?.notes)) {\n\t\tlines.push(`Notes: ${normalizeText(context?.notes)}`);\n\t}\n\tif (normalizeText(context?.error)) {\n\t\tlines.push(`Error: ${normalizeText(context?.error)}`);\n\t}\n\n\treturn lines.join('\\n');\n}\n\nexport function buildGeneratedSlowQuerySummary(\n\tstage: SlowQueryWorkflowStage,\n\tcontext: GeneratedSlowQuerySummaryContext,\n\textra?: { reason?: string; notes?: string }\n): string {\n\tconst collection = normalizeText(context?.collection, 'a collection');\n\tconst sourceApp = normalizeText(context?.source_app, 'your app');\n\tconst environment = normalizeText(context?.environment, 'production');\n\tconst baselineDuration = normalizeDuration(context?.baseline_duration_ms);\n\tconst afterDuration = normalizeDuration(context?.after_duration_ms);\n\tconst hasDurations = baselineDuration !== null && afterDuration !== null && baselineDuration > 0;\n\tconst improvementPct = hasDurations\n\t\t? Math.max(0, ((baselineDuration - afterDuration) / baselineDuration) * 100)\n\t\t: null;\n\n\tif (stage === 'detected_auto_optimize_enabled') {\n\t\treturn [\n\t\t\t`What happened: We found a slow operation in ${collection}.`,\n\t\t\t`Where: ${sourceApp} (${environment}).`,\n\t\t\t'What happens next: Auto-optimization is running and we will send another update when done.'\n\t\t].join('\\n');\n\t}\n\n\tif (stage === 'completed_success') {\n\t\treturn [\n\t\t\t`What happened: We optimized slow performance for ${collection}.`,\n\t\t\t`Where: ${sourceApp} (${environment}).`,\n\t\t\thasDurations\n\t\t\t\t? `Estimated improvement: about ${round(improvementPct, 1)}% faster response time.`\n\t\t\t\t: 'Estimated improvement: performance is now better than before.',\n\t\t\t'What to do: No action is needed unless you still notice slow behavior.'\n\t\t].join('\\n');\n\t}\n\n\treturn [\n\t\t`What happened: We could not safely complete automatic optimization for ${collection}.`,\n\t\t`Where: ${sourceApp} (${environment}).`,\n\t\t`Why: ${extra?.reason || extra?.notes || context?.reason || context?.notes || 'Manual review is required.'}`,\n\t\t'What to do: Ask the team to review this slow operation manually.'\n\t].join('\\n');\n}\n\nexport function buildResolveIOProjectSlowQueryDetails(context: ResolveIOProjectSlowQueryDetailsContext): string {\n\tconst baselineDuration = normalizeDuration(context?.baseline_duration_ms);\n\tconst afterDuration = normalizeDuration(context?.after_duration_ms);\n\tconst hasDurations = baselineDuration !== null && afterDuration !== null && baselineDuration > 0;\n\tconst improvementPct = hasDurations\n\t\t? round(((baselineDuration - afterDuration) / baselineDuration) * 100, 1)\n\t\t: null;\n\tconst runDurations = Array.isArray(context?.verification_run_durations_ms)\n\t\t? context.verification_run_durations_ms\n\t\t\t.map(duration => formatDuration(duration))\n\t\t\t.filter(Boolean)\n\t\t: [];\n\n\tconst lines = [\n\t\t'Slow-query optimization completed for a ResolveIO project.',\n\t\t'',\n\t\t`Collection: ${normalizeText(context?.collection, 'unknown')}`,\n\t\t`Client: ${normalizeText(context?.client_name || context?.client_slug, 'unknown')}`,\n\t\t`Source App: ${normalizeText(context?.source_app, 'unknown')}`,\n\t\t`Environment: ${normalizeText(context?.environment, 'unknown')}`,\n\t\t`Query Hash: ${normalizeText(context?.query_hash, 'n/a')}`,\n\t\thasDurations\n\t\t\t? `Performance Change: ${round(baselineDuration, 0)} ms -> ${round(afterDuration, 0)} ms (${improvementPct}%)`\n\t\t\t: 'Performance Change: available in slow-query logs.',\n\t\t`Verification Runs: ${runDurations.join(', ') || 'n/a'}`,\n\t\t`Log ID: ${normalizeText(context?.log_id, 'n/a')}`\n\t];\n\n\tif (normalizeText(context?.notes)) {\n\t\tlines.push(`Notes: ${normalizeText(context?.notes)}`);\n\t}\n\tif (normalizeText(context?.reason)) {\n\t\tlines.push(`Reason: ${normalizeText(context?.reason)}`);\n\t}\n\n\treturn lines.join('\\n');\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import { CheckAICoderTokenEligibilityFn } from './slow-query-verifier.manager';
2
+ export interface DiagnosticManagerBootstrapDependencies {
3
+ ErrorAutoFixLogs?: any;
4
+ SlowQueryLogs?: any;
5
+ AICoderApps?: any;
6
+ AIDashboardJobs?: any;
7
+ checkAICoderTokenEligibility?: CheckAICoderTokenEligibilityFn;
8
+ }
9
+ export declare function registerDiagnosticManagerDependencies(dependencies?: DiagnosticManagerBootstrapDependencies): void;
@@ -0,0 +1,260 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __read = (this && this.__read) || function (o, n) {
50
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
51
+ if (!m) return o;
52
+ var i = m.call(o), r, ar = [], e;
53
+ try {
54
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
55
+ }
56
+ catch (error) { e = { error: error }; }
57
+ finally {
58
+ try {
59
+ if (r && !r.done && (m = i["return"])) m.call(i);
60
+ }
61
+ finally { if (e) throw e.error; }
62
+ }
63
+ return ar;
64
+ };
65
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
66
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
67
+ if (ar || !(i in from)) {
68
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
69
+ ar[i] = from[i];
70
+ }
71
+ }
72
+ return to.concat(ar || Array.prototype.slice.call(from));
73
+ };
74
+ Object.defineProperty(exports, "__esModule", { value: true });
75
+ exports.registerDiagnosticManagerDependencies = registerDiagnosticManagerDependencies;
76
+ var resolveio_server_app_1 = require("../resolveio-server-app");
77
+ var error_auto_fix_manager_1 = require("./error-auto-fix.manager");
78
+ var slow_query_manager_1 = require("./slow-query.manager");
79
+ var slow_query_verifier_manager_1 = require("./slow-query-verifier.manager");
80
+ var indexesEnsured = false;
81
+ function resolveMainCollection(collectionName) {
82
+ var mainDb = resolveio_server_app_1.ResolveIOServer.getMainDB();
83
+ if (!mainDb) {
84
+ throw new Error("Cannot resolve collection ".concat(collectionName, " before MongoDB main DB is initialized."));
85
+ }
86
+ return mainDb.collection(collectionName);
87
+ }
88
+ function createCollectionAdapter(collectionName) {
89
+ var _this = this;
90
+ var collection = resolveMainCollection(collectionName);
91
+ return {
92
+ findOne: function (query, options) {
93
+ if (query === void 0) { query = {}; }
94
+ if (options === void 0) { options = {}; }
95
+ return collection.findOne(query, options);
96
+ },
97
+ find: function (query, options) {
98
+ if (query === void 0) { query = {}; }
99
+ if (options === void 0) { options = {}; }
100
+ var findOptions = __assign({}, (options || {}));
101
+ var sort = findOptions.sort;
102
+ var skip = findOptions.skip;
103
+ var limit = findOptions.limit;
104
+ delete findOptions.sort;
105
+ delete findOptions.skip;
106
+ delete findOptions.limit;
107
+ var cursor = collection.find(query, findOptions);
108
+ if (sort) {
109
+ cursor = cursor.sort(sort);
110
+ }
111
+ if (typeof skip === 'number') {
112
+ cursor = cursor.skip(skip);
113
+ }
114
+ if (typeof limit === 'number') {
115
+ cursor = cursor.limit(limit);
116
+ }
117
+ return cursor.toArray();
118
+ },
119
+ insertOne: function (document, options) {
120
+ if (options === void 0) { options = {}; }
121
+ return collection.insertOne(document, options);
122
+ },
123
+ updateOne: function (query, update, options) {
124
+ if (options === void 0) { options = {}; }
125
+ return collection.updateOne(query, update, options);
126
+ },
127
+ findOneAndUpdate: function (query_1, update_1) {
128
+ var args_1 = [];
129
+ for (var _i = 2; _i < arguments.length; _i++) {
130
+ args_1[_i - 2] = arguments[_i];
131
+ }
132
+ return __awaiter(_this, __spreadArray([query_1, update_1], __read(args_1), false), void 0, function (query, update, options) {
133
+ var result;
134
+ if (options === void 0) { options = {}; }
135
+ return __generator(this, function (_a) {
136
+ switch (_a.label) {
137
+ case 0: return [4 /*yield*/, collection.findOneAndUpdate(query, update, options)];
138
+ case 1:
139
+ result = _a.sent();
140
+ if (result && typeof result === 'object' && Object.prototype.hasOwnProperty.call(result, 'value')) {
141
+ return [2 /*return*/, result.value];
142
+ }
143
+ return [2 /*return*/, result];
144
+ }
145
+ });
146
+ });
147
+ },
148
+ findById: function (id, options) {
149
+ if (options === void 0) { options = {}; }
150
+ return collection.findOne({ _id: id }, options);
151
+ },
152
+ createIndex: function (spec, options) {
153
+ if (options === void 0) { options = {}; }
154
+ return collection.createIndex(spec, options);
155
+ }
156
+ };
157
+ }
158
+ function ensureCollectionIndexes(collections) {
159
+ var _this = this;
160
+ if (indexesEnsured) {
161
+ return;
162
+ }
163
+ indexesEnsured = true;
164
+ setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
165
+ var error_1, error_2;
166
+ return __generator(this, function (_a) {
167
+ switch (_a.label) {
168
+ case 0:
169
+ _a.trys.push([0, 6, , 7]);
170
+ if (!(typeof collections.ErrorAutoFixLogs.createIndex === 'function')) return [3 /*break*/, 5];
171
+ return [4 /*yield*/, collections.ErrorAutoFixLogs.createIndex({ email_hash: 1 })];
172
+ case 1:
173
+ _a.sent();
174
+ return [4 /*yield*/, collections.ErrorAutoFixLogs.createIndex({ issue_hash: 1 })];
175
+ case 2:
176
+ _a.sent();
177
+ return [4 /*yield*/, collections.ErrorAutoFixLogs.createIndex({ status: 1 })];
178
+ case 3:
179
+ _a.sent();
180
+ return [4 /*yield*/, collections.ErrorAutoFixLogs.createIndex({ ignored: 1 })];
181
+ case 4:
182
+ _a.sent();
183
+ _a.label = 5;
184
+ case 5: return [3 /*break*/, 7];
185
+ case 6:
186
+ error_1 = _a.sent();
187
+ console.error('Failed to ensure error auto-fix indexes', error_1);
188
+ return [3 /*break*/, 7];
189
+ case 7:
190
+ _a.trys.push([7, 18, , 19]);
191
+ if (!(typeof collections.SlowQueryLogs.createIndex === 'function')) return [3 /*break*/, 17];
192
+ return [4 /*yield*/, collections.SlowQueryLogs.createIndex({ query_hash: 1 })];
193
+ case 8:
194
+ _a.sent();
195
+ return [4 /*yield*/, collections.SlowQueryLogs.createIndex({ collection: 1 })];
196
+ case 9:
197
+ _a.sent();
198
+ return [4 /*yield*/, collections.SlowQueryLogs.createIndex({ client_slug: 1 })];
199
+ case 10:
200
+ _a.sent();
201
+ return [4 /*yield*/, collections.SlowQueryLogs.createIndex({ status: 1 })];
202
+ case 11:
203
+ _a.sent();
204
+ return [4 /*yield*/, collections.SlowQueryLogs.createIndex({ ignored: 1 })];
205
+ case 12:
206
+ _a.sent();
207
+ return [4 /*yield*/, collections.SlowQueryLogs.createIndex({ last_seen_at: -1 })];
208
+ case 13:
209
+ _a.sent();
210
+ return [4 /*yield*/, collections.SlowQueryLogs.createIndex({ collection: 1, duration_ms: -1 })];
211
+ case 14:
212
+ _a.sent();
213
+ return [4 /*yield*/, collections.SlowQueryLogs.createIndex({ publication: 1 })];
214
+ case 15:
215
+ _a.sent();
216
+ return [4 /*yield*/, collections.SlowQueryLogs.createIndex({ server_url: 1 })];
217
+ case 16:
218
+ _a.sent();
219
+ _a.label = 17;
220
+ case 17: return [3 /*break*/, 19];
221
+ case 18:
222
+ error_2 = _a.sent();
223
+ console.error('Failed to ensure slow query indexes', error_2);
224
+ return [3 /*break*/, 19];
225
+ case 19: return [2 /*return*/];
226
+ }
227
+ });
228
+ }); }, 5000);
229
+ }
230
+ function registerDiagnosticManagerDependencies(dependencies) {
231
+ if (dependencies === void 0) { dependencies = {}; }
232
+ var errorAutoFixLogs = dependencies.ErrorAutoFixLogs || createCollectionAdapter('error-autofix-logs');
233
+ var slowQueryLogs = dependencies.SlowQueryLogs || createCollectionAdapter('slow-query-logs');
234
+ var aiCoderApps = dependencies.AICoderApps;
235
+ var aiDashboardJobs = dependencies.AIDashboardJobs;
236
+ var errorAutoFixDependencies = {
237
+ ErrorAutoFixLogs: errorAutoFixLogs,
238
+ AICoderApps: aiCoderApps,
239
+ AIDashboardJobs: aiDashboardJobs
240
+ };
241
+ (0, error_auto_fix_manager_1.registerErrorAutoFixManagerDependencies)(errorAutoFixDependencies);
242
+ (0, slow_query_manager_1.registerSlowQueryManagerDependencies)({
243
+ SlowQueryLogs: slowQueryLogs
244
+ });
245
+ var slowQueryVerifierDependencies = {
246
+ SlowQueryLogs: slowQueryLogs,
247
+ AICoderApps: aiCoderApps,
248
+ AIDashboardJobs: aiDashboardJobs
249
+ };
250
+ if (dependencies.checkAICoderTokenEligibility) {
251
+ slowQueryVerifierDependencies.checkAICoderTokenEligibility = dependencies.checkAICoderTokenEligibility;
252
+ }
253
+ (0, slow_query_verifier_manager_1.registerSlowQueryVerifierDependencies)(slowQueryVerifierDependencies);
254
+ ensureCollectionIndexes({
255
+ ErrorAutoFixLogs: errorAutoFixLogs,
256
+ SlowQueryLogs: slowQueryLogs
257
+ });
258
+ }
259
+
260
+ //# sourceMappingURL=diagnostic-manager-bootstrap.js.map