@resolveio/server-lib 22.3.220 → 22.3.221
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/.nodemon.json +5 -0
- package/.vscode/settings.json +21 -0
- package/AGENTS.md +195 -0
- package/README.md +22 -0
- package/build_package.sh +5 -0
- package/compileDTS.pl +64 -0
- package/docs/ai-assistant-nightly-eval.md +65 -0
- package/docs/ai-assistant-preflight-checklist.md +23 -0
- package/docs/ai-assistant-report-builder-bridge-playbook.md +115 -0
- package/eslint-plugin-custom/index.js +7 -0
- package/eslint-plugin-custom/rules/no-filter-zero-index.js +44 -0
- package/eslint.config.js +103 -0
- package/gulpfile.js +216 -0
- package/methodAndPublicationListGenerator.py +375 -0
- package/mongodbensurers.js +2 -0
- package/mongostop.js +3 -0
- package/package.json +1 -1
- package/scripts/cleanup-bypassed-callmethod-logs.js +616 -0
- package/settings.development.json +25 -0
- package/settings.development.redacted.json +25 -0
- package/src/.env +12 -0
- package/src/ai/assistant-core-heuristics.ts +379 -0
- package/src/ai/resolveio-platform-intelligence-memory-corpus.ts +185 -0
- package/src/ai/resolveio-platform-intelligence-memory.ts +325 -0
- package/{ai/resolveio-platform-intelligence-types.d.ts → src/ai/resolveio-platform-intelligence-types.ts} +20 -15
- package/src/ai/resolveio-platform-intelligence.ts +462 -0
- package/src/client-server-app.ts +12 -0
- package/src/collections/ai-run.collection.ts +117 -0
- package/src/collections/ai-terminal-conversation.collection.ts +91 -0
- package/src/collections/ai-terminal-issue-report.collection.ts +99 -0
- package/src/collections/ai-terminal-message.collection.ts +77 -0
- package/src/collections/app-setting.collection.ts +104 -0
- package/src/collections/app-status.collection.ts +58 -0
- package/src/collections/communication-metric.collection.ts +84 -0
- package/src/collections/counter.collection.ts +56 -0
- package/src/collections/cron-job-history.collection.ts +94 -0
- package/src/collections/cron-job.collection.ts +92 -0
- package/src/collections/customer-notification.collection.ts +131 -0
- package/src/collections/customer-portal-password.collection.ts +76 -0
- package/src/collections/email-history.collection.ts +134 -0
- package/src/collections/email-verified.collection.ts +62 -0
- package/src/collections/file.collection.ts +74 -0
- package/src/collections/flag-update.collection.ts +57 -0
- package/src/collections/flag.collection.ts +57 -0
- package/src/collections/log-method-latency.collection.ts +77 -0
- package/src/collections/log-subscription.collection.ts +80 -0
- package/src/collections/log.collection.ts +93 -0
- package/src/collections/logged-in-users.collection.ts +67 -0
- package/src/collections/monitor-cpu.collection.ts +65 -0
- package/src/collections/monitor-function.collection.ts +74 -0
- package/src/collections/monitor-memory.collection.ts +77 -0
- package/src/collections/monitor-mongo.collection.ts +71 -0
- package/src/collections/notification.collection.ts +57 -0
- package/src/collections/openai-usage-ledger.collection.ts +131 -0
- package/src/collections/report-builder-dashboard-builder.collection.ts +109 -0
- package/src/collections/report-builder-library.collection.ts +89 -0
- package/src/collections/report-builder-report.collection.ts +184 -0
- package/src/collections/user-group.collection.ts +89 -0
- package/src/collections/user-guide.collection.ts +57 -0
- package/src/collections/user.collection.ts +181 -0
- package/src/cron/cron.ts +117 -0
- package/src/fixtures/cron-jobs.ts +95 -0
- package/src/fixtures/init.ts +35 -0
- package/src/http/auth.ts +818 -0
- package/src/http/health.ts +7 -0
- package/src/http/home.ts +90 -0
- package/src/http/slow-query-publication.ts +49 -0
- package/src/index.ts +1 -0
- package/src/managers/ai-assistant-codex-manager.manager.ts +1131 -0
- package/src/managers/ai-run-evidence.manager.ts +264 -0
- package/src/managers/communication-metric.manager.ts +82 -0
- package/src/managers/cron.manager.ts +333 -0
- package/src/managers/customer-notification-content.manager.ts +236 -0
- package/src/managers/diagnostic-manager-bootstrap.ts +165 -0
- package/src/managers/error-auto-fix.manager.ts +2767 -0
- package/src/managers/local-log.manager.ts +113 -0
- package/src/managers/method.manager.ts +1857 -0
- package/src/managers/mongo.manager.ts +4575 -0
- package/src/managers/monitor.manager.ts +507 -0
- package/src/managers/openai-usage-ledger.manager.ts +112 -0
- package/src/managers/slow-query-verifier.manager.ts +3590 -0
- package/src/managers/slow-query.manager.ts +519 -0
- package/src/managers/subscription.manager.ts +3128 -0
- package/src/managers/websocket.manager.ts +746 -0
- package/src/managers/worker-dispatcher.manager.ts +1360 -0
- package/src/managers/worker-server.manager.ts +536 -0
- package/src/methods/accounts.ts +532 -0
- package/src/methods/ai-terminal.ts +29070 -0
- package/src/methods/app-settings.ts +114 -0
- package/src/methods/aws.ts +649 -0
- package/src/methods/collections.ts +641 -0
- package/src/methods/counters.ts +69 -0
- package/src/methods/cron-jobs.ts +2614 -0
- package/src/methods/customer-notifications.ts +458 -0
- package/src/methods/diagnostics.ts +616 -0
- package/src/methods/flag-updates.ts +7 -0
- package/src/methods/flags.ts +7 -0
- package/src/methods/logs.ts +657 -0
- package/src/methods/mongo-explorer.ts +1880 -0
- package/src/methods/monitor.ts +540 -0
- package/src/methods/pdf.ts +1236 -0
- package/src/methods/publications.ts +129 -0
- package/src/methods/report-builder.ts +3300 -0
- package/src/methods/support.ts +335 -0
- package/src/models/ai-run.model.ts +27 -0
- package/src/models/ai-terminal-conversation.model.ts +19 -0
- package/src/models/ai-terminal-issue-report.model.ts +21 -0
- package/src/models/ai-terminal-message.model.ts +24 -0
- package/src/models/app-setting.model.ts +17 -0
- package/{models/app-status.model.d.ts → src/models/app-status.model.ts} +3 -2
- package/{models/billing-logged-in-users.model.d.ts → src/models/billing-logged-in-users.model.ts} +5 -4
- package/src/models/collection-document.model.ts +24 -0
- package/src/models/communication-metric.model.ts +23 -0
- package/{models/counter.model.d.ts → src/models/counter.model.ts} +4 -3
- package/src/models/cron-job-history.model.ts +16 -0
- package/src/models/cron-job.model.ts +15 -0
- package/src/models/customer-notification.model.ts +28 -0
- package/src/models/customer-portal-password.model.ts +12 -0
- package/src/models/dialog.model.ts +25 -0
- package/{models/email-history.model.js → src/models/email-history.model.ts} +36 -4
- package/{models/email-verified.model.d.ts → src/models/email-verified.model.ts} +6 -5
- package/{models/file.model.d.ts → src/models/file.model.ts} +8 -7
- package/{models/flag-update.model.d.ts → src/models/flag-update.model.ts} +4 -3
- package/{models/flag.model.d.ts → src/models/flag.model.ts} +4 -3
- package/src/models/log-method-latency.model.ts +11 -0
- package/{models/log-subscription.model.d.ts → src/models/log-subscription.model.ts} +11 -9
- package/src/models/log.model.ts +19 -0
- package/{models/logged-in-users.model.d.ts → src/models/logged-in-users.model.ts} +6 -5
- package/{models/method-response.model.d.ts → src/models/method-response.model.ts} +7 -6
- package/src/models/method.model.ts +25 -0
- package/{models/monitor-cpu.model.d.ts → src/models/monitor-cpu.model.ts} +9 -7
- package/src/models/monitor-function.model.ts +16 -0
- package/src/models/monitor-memory.model.ts +17 -0
- package/src/models/monitor-mongo.model.ts +15 -0
- package/{models/notification.model.d.ts → src/models/notification.model.ts} +6 -4
- package/src/models/openai-usage-ledger.model.ts +56 -0
- package/src/models/pagination.model.ts +35 -0
- package/src/models/permission.model.ts +14 -0
- package/src/models/report-builder-dashboard-builder.model.ts +29 -0
- package/src/models/report-builder-library.model.ts +20 -0
- package/src/models/report-builder-report.model.ts +136 -0
- package/src/models/report-builder.model.ts +68 -0
- package/src/models/select-data-label.model.ts +9 -0
- package/src/models/server-message.model.ts +31 -0
- package/src/models/slow-query-report.model.ts +23 -0
- package/src/models/subscription.model.ts +73 -0
- package/src/models/support-ticket.model.ts +104 -0
- package/src/models/user-group.model.ts +24 -0
- package/{models/user-guide.model.d.ts → src/models/user-guide.model.ts} +5 -4
- package/src/models/user.model.ts +96 -0
- package/src/private/images/ResolveIO.png +0 -0
- package/src/publications/ai-terminal.ts +73 -0
- package/src/publications/app-settings.ts +25 -0
- package/src/publications/app-status.ts +13 -0
- package/src/publications/cron-jobs.ts +40 -0
- package/src/publications/customer-notifications.ts +101 -0
- package/src/publications/files.ts +33 -0
- package/src/publications/flags-update.ts +19 -0
- package/src/publications/flags.ts +19 -0
- package/src/publications/logs.ts +163 -0
- package/src/publications/notifications.ts +13 -0
- package/src/publications/report-builder-dashboard-builders.ts +39 -0
- package/src/publications/report-builder-libraries.ts +41 -0
- package/src/publications/report-builder-reports.ts +47 -0
- package/src/publications/super-admin.ts +13 -0
- package/src/publications/user-groups.ts +12 -0
- package/src/publications/user-guides.ts +12 -0
- package/src/resolveio-server-app.ts +617 -0
- package/src/server-app.ts +3354 -0
- package/src/services/codex-client.ts +1231 -0
- package/src/services/openai-client.ts +265 -0
- package/src/types/error-report.ts +26 -0
- package/src/types/js-tiktoken.d.ts +11 -0
- package/src/types/slow-query-report.ts +28 -0
- package/src/util/ai-qa-policy.ts +925 -0
- package/src/util/ai-run-evidence-adapters.ts +8347 -0
- package/src/util/ai-run-evidence-dashboard.ts +323 -0
- package/src/util/ai-run-evidence-eval.ts +1057 -0
- package/src/util/ai-run-evidence.ts +1430 -0
- package/src/util/ai-runner-artifacts.ts +586 -0
- package/src/util/ai-runner-manager-autopilot.ts +961 -0
- package/src/util/ai-runner-manager-policy.ts +5011 -0
- package/src/util/ai-runner-qa-auth.ts +838 -0
- package/src/util/ai-runner-qa-tools.ts +3536 -0
- package/src/util/aicoder-runner-v6.ts +3121 -0
- package/src/util/common.ts +649 -0
- package/src/util/customer-portal-password.ts +183 -0
- package/src/util/error-reporter.ts +332 -0
- package/src/util/error-tracking.ts +79 -0
- package/src/util/openai-usage-cost.ts +114 -0
- package/src/util/report-builder-unwinds.ts +180 -0
- package/src/util/runner-process-janitor.ts +219 -0
- package/src/util/schema-report-builder.ts +448 -0
- package/src/util/slow-query-reporter.ts +216 -0
- package/src/util/subscription-dependency-context.ts +1096 -0
- package/src/util/support-runner-v5.ts +10040 -0
- package/src/util/tokenizer.ts +38 -0
- package/src/workers/codex-runner.worker.ts +142 -0
- package/start_server.sh +5 -0
- package/tests/ai-assistant-corpus-build.ts +484 -0
- package/tests/ai-assistant-corpus-replay-e2e.ts +774 -0
- package/tests/ai-assistant-data-parity-e2e.ts +1989 -0
- package/tests/ai-assistant-eval-triage.ts +831 -0
- package/tests/ai-assistant-openai-e2e.ts +1061 -0
- package/tests/ai-assistant-openai-git-e2e.ts +155 -0
- package/tests/ai-assistant-preflight-matrix.ts +215 -0
- package/tests/ai-assistant-routing-eval.test.ts +585 -0
- package/tests/ai-assistant-snf-live-eval.ts +975 -0
- package/tests/ai-assistant-utils.test.ts +4834 -0
- package/tests/ai-manager-autopilot-snapshot.test.ts +193 -0
- package/tests/ai-manager-recovery-checkpoint.test.ts +1383 -0
- package/tests/ai-run-eval.test.ts +132 -0
- package/tests/ai-run-evidence.test.ts +3773 -0
- package/tests/ai-runner-contract.test.ts +515 -0
- package/tests/aicoder-runner-v6.test.ts +822 -0
- package/tests/error-reporter.test.ts +145 -0
- package/tests/method-publication-generator.test.ts +46 -0
- package/tests/report-builder-linking.test.ts +79 -0
- package/tests/resolveio-platform-intelligence.test.ts +352 -0
- package/tests/server-app-cron-owner.test.ts +127 -0
- package/tests/subscription-connect-race.test.ts +158 -0
- package/tests/subscription-dependency-context.test.ts +324 -0
- package/tests/subscription-manager-collection-tracking.test.ts +86 -0
- package/tests/subscription-manager-invalidation.test.ts +86 -0
- package/tests/support-runner-v5.test.ts +3201 -0
- package/tsconfig.json +34 -0
- package/ai/assistant-core-heuristics.d.ts +0 -11
- package/ai/assistant-core-heuristics.js +0 -356
- package/ai/assistant-core-heuristics.js.map +0 -1
- package/ai/resolveio-platform-intelligence-memory-corpus.d.ts +0 -3
- package/ai/resolveio-platform-intelligence-memory-corpus.js +0 -214
- package/ai/resolveio-platform-intelligence-memory-corpus.js.map +0 -1
- package/ai/resolveio-platform-intelligence-memory.d.ts +0 -20
- package/ai/resolveio-platform-intelligence-memory.js +0 -341
- package/ai/resolveio-platform-intelligence-memory.js.map +0 -1
- package/ai/resolveio-platform-intelligence-types.js +0 -4
- package/ai/resolveio-platform-intelligence-types.js.map +0 -1
- package/ai/resolveio-platform-intelligence.d.ts +0 -6
- package/ai/resolveio-platform-intelligence.js +0 -463
- package/ai/resolveio-platform-intelligence.js.map +0 -1
- package/client-server-app.d.ts +0 -1
- package/client-server-app.js +0 -68
- package/client-server-app.js.map +0 -1
- package/collections/ai-run.collection.d.ts +0 -3
- package/collections/ai-run.collection.js +0 -170
- package/collections/ai-run.collection.js.map +0 -1
- package/collections/ai-terminal-conversation.collection.d.ts +0 -2
- package/collections/ai-terminal-conversation.collection.js +0 -140
- package/collections/ai-terminal-conversation.collection.js.map +0 -1
- package/collections/ai-terminal-issue-report.collection.d.ts +0 -2
- package/collections/ai-terminal-issue-report.collection.js +0 -148
- package/collections/ai-terminal-issue-report.collection.js.map +0 -1
- package/collections/ai-terminal-message.collection.d.ts +0 -2
- package/collections/ai-terminal-message.collection.js +0 -121
- package/collections/ai-terminal-message.collection.js.map +0 -1
- package/collections/app-setting.collection.d.ts +0 -3
- package/collections/app-setting.collection.js +0 -103
- package/collections/app-setting.collection.js.map +0 -1
- package/collections/app-status.collection.d.ts +0 -3
- package/collections/app-status.collection.js +0 -57
- package/collections/app-status.collection.js.map +0 -1
- package/collections/communication-metric.collection.d.ts +0 -2
- package/collections/communication-metric.collection.js +0 -133
- package/collections/communication-metric.collection.js.map +0 -1
- package/collections/counter.collection.d.ts +0 -3
- package/collections/counter.collection.js +0 -56
- package/collections/counter.collection.js.map +0 -1
- package/collections/cron-job-history.collection.d.ts +0 -3
- package/collections/cron-job-history.collection.js +0 -137
- package/collections/cron-job-history.collection.js.map +0 -1
- package/collections/cron-job.collection.d.ts +0 -3
- package/collections/cron-job.collection.js +0 -92
- package/collections/cron-job.collection.js.map +0 -1
- package/collections/customer-notification.collection.d.ts +0 -3
- package/collections/customer-notification.collection.js +0 -130
- package/collections/customer-notification.collection.js.map +0 -1
- package/collections/customer-portal-password.collection.d.ts +0 -3
- package/collections/customer-portal-password.collection.js +0 -75
- package/collections/customer-portal-password.collection.js.map +0 -1
- package/collections/email-history.collection.d.ts +0 -3
- package/collections/email-history.collection.js +0 -134
- package/collections/email-history.collection.js.map +0 -1
- package/collections/email-verified.collection.d.ts +0 -3
- package/collections/email-verified.collection.js +0 -62
- package/collections/email-verified.collection.js.map +0 -1
- package/collections/file.collection.d.ts +0 -3
- package/collections/file.collection.js +0 -74
- package/collections/file.collection.js.map +0 -1
- package/collections/flag-update.collection.d.ts +0 -3
- package/collections/flag-update.collection.js +0 -57
- package/collections/flag-update.collection.js.map +0 -1
- package/collections/flag.collection.d.ts +0 -3
- package/collections/flag.collection.js +0 -57
- package/collections/flag.collection.js.map +0 -1
- package/collections/log-method-latency.collection.d.ts +0 -3
- package/collections/log-method-latency.collection.js +0 -77
- package/collections/log-method-latency.collection.js.map +0 -1
- package/collections/log-subscription.collection.d.ts +0 -3
- package/collections/log-subscription.collection.js +0 -80
- package/collections/log-subscription.collection.js.map +0 -1
- package/collections/log.collection.d.ts +0 -3
- package/collections/log.collection.js +0 -93
- package/collections/log.collection.js.map +0 -1
- package/collections/logged-in-users.collection.d.ts +0 -3
- package/collections/logged-in-users.collection.js +0 -67
- package/collections/logged-in-users.collection.js.map +0 -1
- package/collections/monitor-cpu.collection.d.ts +0 -3
- package/collections/monitor-cpu.collection.js +0 -65
- package/collections/monitor-cpu.collection.js.map +0 -1
- package/collections/monitor-function.collection.d.ts +0 -3
- package/collections/monitor-function.collection.js +0 -74
- package/collections/monitor-function.collection.js.map +0 -1
- package/collections/monitor-memory.collection.d.ts +0 -3
- package/collections/monitor-memory.collection.js +0 -77
- package/collections/monitor-memory.collection.js.map +0 -1
- package/collections/monitor-mongo.collection.d.ts +0 -3
- package/collections/monitor-mongo.collection.js +0 -71
- package/collections/monitor-mongo.collection.js.map +0 -1
- package/collections/notification.collection.d.ts +0 -3
- package/collections/notification.collection.js +0 -57
- package/collections/notification.collection.js.map +0 -1
- package/collections/openai-usage-ledger.collection.d.ts +0 -2
- package/collections/openai-usage-ledger.collection.js +0 -188
- package/collections/openai-usage-ledger.collection.js.map +0 -1
- package/collections/report-builder-dashboard-builder.collection.d.ts +0 -3
- package/collections/report-builder-dashboard-builder.collection.js +0 -109
- package/collections/report-builder-dashboard-builder.collection.js.map +0 -1
- package/collections/report-builder-library.collection.d.ts +0 -3
- package/collections/report-builder-library.collection.js +0 -87
- package/collections/report-builder-library.collection.js.map +0 -1
- package/collections/report-builder-report.collection.d.ts +0 -4
- package/collections/report-builder-report.collection.js +0 -184
- package/collections/report-builder-report.collection.js.map +0 -1
- package/collections/user-group.collection.d.ts +0 -4
- package/collections/user-group.collection.js +0 -89
- package/collections/user-group.collection.js.map +0 -1
- package/collections/user-guide.collection.d.ts +0 -3
- package/collections/user-guide.collection.js +0 -57
- package/collections/user-guide.collection.js.map +0 -1
- package/collections/user.collection.d.ts +0 -4
- package/collections/user.collection.js +0 -180
- package/collections/user.collection.js.map +0 -1
- package/cron/cron.d.ts +0 -14
- package/cron/cron.js +0 -216
- package/cron/cron.js.map +0 -1
- package/fixtures/cron-jobs.d.ts +0 -1
- package/fixtures/cron-jobs.js +0 -150
- package/fixtures/cron-jobs.js.map +0 -1
- package/fixtures/init.d.ts +0 -1
- package/fixtures/init.js +0 -91
- package/fixtures/init.js.map +0 -1
- package/http/auth.d.ts +0 -2
- package/http/auth.js +0 -951
- package/http/auth.js.map +0 -1
- package/http/health.d.ts +0 -1
- package/http/health.js +0 -11
- package/http/health.js.map +0 -1
- package/http/home.d.ts +0 -1
- package/http/home.js +0 -134
- package/http/home.js.map +0 -1
- package/http/slow-query-publication.d.ts +0 -2
- package/http/slow-query-publication.js +0 -99
- package/http/slow-query-publication.js.map +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -19
- package/index.js.map +0 -1
- package/managers/ai-assistant-codex-manager.manager.d.ts +0 -67
- package/managers/ai-assistant-codex-manager.manager.js +0 -1113
- package/managers/ai-assistant-codex-manager.manager.js.map +0 -1
- package/managers/ai-run-evidence.manager.d.ts +0 -36
- package/managers/ai-run-evidence.manager.js +0 -377
- package/managers/ai-run-evidence.manager.js.map +0 -1
- package/managers/communication-metric.manager.d.ts +0 -16
- package/managers/communication-metric.manager.js +0 -134
- package/managers/communication-metric.manager.js.map +0 -1
- package/managers/cron.manager.d.ts +0 -20
- package/managers/cron.manager.js +0 -534
- package/managers/cron.manager.js.map +0 -1
- package/managers/customer-notification-content.manager.d.ts +0 -55
- package/managers/customer-notification-content.manager.js +0 -158
- package/managers/customer-notification-content.manager.js.map +0 -1
- package/managers/diagnostic-manager-bootstrap.d.ts +0 -9
- package/managers/diagnostic-manager-bootstrap.js +0 -260
- package/managers/diagnostic-manager-bootstrap.js.map +0 -1
- package/managers/error-auto-fix.manager.d.ts +0 -149
- package/managers/error-auto-fix.manager.js +0 -3064
- package/managers/error-auto-fix.manager.js.map +0 -1
- package/managers/local-log.manager.d.ts +0 -18
- package/managers/local-log.manager.js +0 -88
- package/managers/local-log.manager.js.map +0 -1
- package/managers/method.manager.d.ts +0 -84
- package/managers/method.manager.js +0 -1964
- package/managers/method.manager.js.map +0 -1
- package/managers/mongo.manager.d.ts +0 -224
- package/managers/mongo.manager.js +0 -5000
- package/managers/mongo.manager.js.map +0 -1
- package/managers/monitor.manager.d.ts +0 -70
- package/managers/monitor.manager.js +0 -550
- package/managers/monitor.manager.js.map +0 -1
- package/managers/openai-usage-ledger.manager.d.ts +0 -30
- package/managers/openai-usage-ledger.manager.js +0 -142
- package/managers/openai-usage-ledger.manager.js.map +0 -1
- package/managers/slow-query-verifier.manager.d.ts +0 -144
- package/managers/slow-query-verifier.manager.js +0 -3857
- package/managers/slow-query-verifier.manager.js.map +0 -1
- package/managers/slow-query.manager.d.ts +0 -28
- package/managers/slow-query.manager.js +0 -468
- package/managers/slow-query.manager.js.map +0 -1
- package/managers/subscription.manager.d.ts +0 -169
- package/managers/subscription.manager.js +0 -3434
- package/managers/subscription.manager.js.map +0 -1
- package/managers/websocket.manager.d.ts +0 -73
- package/managers/websocket.manager.js +0 -673
- package/managers/websocket.manager.js.map +0 -1
- package/managers/worker-dispatcher.manager.d.ts +0 -120
- package/managers/worker-dispatcher.manager.js +0 -1266
- package/managers/worker-dispatcher.manager.js.map +0 -1
- package/managers/worker-server.manager.d.ts +0 -35
- package/managers/worker-server.manager.js +0 -582
- package/managers/worker-server.manager.js.map +0 -1
- package/methods/accounts.d.ts +0 -2
- package/methods/accounts.js +0 -624
- package/methods/accounts.js.map +0 -1
- package/methods/ai-terminal.d.ts +0 -458
- package/methods/ai-terminal.js +0 -27991
- package/methods/ai-terminal.js.map +0 -1
- package/methods/app-settings.d.ts +0 -2
- package/methods/app-settings.js +0 -169
- package/methods/app-settings.js.map +0 -1
- package/methods/aws.d.ts +0 -2
- package/methods/aws.js +0 -877
- package/methods/aws.js.map +0 -1
- package/methods/collections.d.ts +0 -2
- package/methods/collections.js +0 -719
- package/methods/collections.js.map +0 -1
- package/methods/counters.d.ts +0 -2
- package/methods/counters.js +0 -113
- package/methods/counters.js.map +0 -1
- package/methods/cron-jobs.d.ts +0 -2
- package/methods/cron-jobs.js +0 -2475
- package/methods/cron-jobs.js.map +0 -1
- package/methods/customer-notifications.d.ts +0 -2
- package/methods/customer-notifications.js +0 -528
- package/methods/customer-notifications.js.map +0 -1
- package/methods/diagnostics.d.ts +0 -2
- package/methods/diagnostics.js +0 -703
- package/methods/diagnostics.js.map +0 -1
- package/methods/flag-updates.d.ts +0 -2
- package/methods/flag-updates.js +0 -8
- package/methods/flag-updates.js.map +0 -1
- package/methods/flags.d.ts +0 -2
- package/methods/flags.js +0 -8
- package/methods/flags.js.map +0 -1
- package/methods/logs.d.ts +0 -2
- package/methods/logs.js +0 -751
- package/methods/logs.js.map +0 -1
- package/methods/mongo-explorer.d.ts +0 -2
- package/methods/mongo-explorer.js +0 -1808
- package/methods/mongo-explorer.js.map +0 -1
- package/methods/monitor.d.ts +0 -2
- package/methods/monitor.js +0 -543
- package/methods/monitor.js.map +0 -1
- package/methods/pdf.d.ts +0 -2
- package/methods/pdf.js +0 -1216
- package/methods/pdf.js.map +0 -1
- package/methods/publications.d.ts +0 -1
- package/methods/publications.js +0 -183
- package/methods/publications.js.map +0 -1
- package/methods/report-builder.d.ts +0 -2
- package/methods/report-builder.js +0 -3094
- package/methods/report-builder.js.map +0 -1
- package/methods/support.d.ts +0 -2
- package/methods/support.js +0 -430
- package/methods/support.js.map +0 -1
- package/models/ai-run.model.d.ts +0 -19
- package/models/ai-run.model.js +0 -4
- package/models/ai-run.model.js.map +0 -1
- package/models/ai-terminal-conversation.model.d.ts +0 -17
- package/models/ai-terminal-conversation.model.js +0 -4
- package/models/ai-terminal-conversation.model.js.map +0 -1
- package/models/ai-terminal-issue-report.model.d.ts +0 -19
- package/models/ai-terminal-issue-report.model.js +0 -4
- package/models/ai-terminal-issue-report.model.js.map +0 -1
- package/models/ai-terminal-message.model.d.ts +0 -22
- package/models/ai-terminal-message.model.js +0 -4
- package/models/ai-terminal-message.model.js.map +0 -1
- package/models/app-setting.model.d.ts +0 -16
- package/models/app-setting.model.js +0 -4
- package/models/app-setting.model.js.map +0 -1
- package/models/app-status.model.js +0 -4
- package/models/app-status.model.js.map +0 -1
- package/models/billing-logged-in-users.model.js +0 -4
- package/models/billing-logged-in-users.model.js.map +0 -1
- package/models/collection-document.model.d.ts +0 -21
- package/models/collection-document.model.js +0 -4
- package/models/collection-document.model.js.map +0 -1
- package/models/communication-metric.model.d.ts +0 -20
- package/models/communication-metric.model.js +0 -4
- package/models/communication-metric.model.js.map +0 -1
- package/models/counter.model.js +0 -4
- package/models/counter.model.js.map +0 -1
- package/models/cron-job-history.model.d.ts +0 -15
- package/models/cron-job-history.model.js +0 -4
- package/models/cron-job-history.model.js.map +0 -1
- package/models/cron-job.model.d.ts +0 -14
- package/models/cron-job.model.js +0 -4
- package/models/cron-job.model.js.map +0 -1
- package/models/customer-notification.model.d.ts +0 -26
- package/models/customer-notification.model.js +0 -4
- package/models/customer-notification.model.js.map +0 -1
- package/models/customer-portal-password.model.d.ts +0 -11
- package/models/customer-portal-password.model.js +0 -4
- package/models/customer-portal-password.model.js.map +0 -1
- package/models/dialog.model.d.ts +0 -23
- package/models/dialog.model.js +0 -4
- package/models/dialog.model.js.map +0 -1
- package/models/email-history.model.d.ts +0 -32
- package/models/email-history.model.js.map +0 -1
- package/models/email-verified.model.js +0 -4
- package/models/email-verified.model.js.map +0 -1
- package/models/file.model.js +0 -4
- package/models/file.model.js.map +0 -1
- package/models/flag-update.model.js +0 -4
- package/models/flag-update.model.js.map +0 -1
- package/models/flag.model.js +0 -4
- package/models/flag.model.js.map +0 -1
- package/models/log-method-latency.model.d.ts +0 -10
- package/models/log-method-latency.model.js +0 -4
- package/models/log-method-latency.model.js.map +0 -1
- package/models/log-subscription.model.js +0 -4
- package/models/log-subscription.model.js.map +0 -1
- package/models/log.model.d.ts +0 -17
- package/models/log.model.js +0 -4
- package/models/log.model.js.map +0 -1
- package/models/logged-in-users.model.js +0 -4
- package/models/logged-in-users.model.js.map +0 -1
- package/models/method-response.model.js +0 -4
- package/models/method-response.model.js.map +0 -1
- package/models/method.model.d.ts +0 -26
- package/models/method.model.js +0 -4
- package/models/method.model.js.map +0 -1
- package/models/monitor-cpu.model.js +0 -4
- package/models/monitor-cpu.model.js.map +0 -1
- package/models/monitor-function.model.d.ts +0 -14
- package/models/monitor-function.model.js +0 -4
- package/models/monitor-function.model.js.map +0 -1
- package/models/monitor-memory.model.d.ts +0 -15
- package/models/monitor-memory.model.js +0 -4
- package/models/monitor-memory.model.js.map +0 -1
- package/models/monitor-mongo.model.d.ts +0 -13
- package/models/monitor-mongo.model.js +0 -4
- package/models/monitor-mongo.model.js.map +0 -1
- package/models/notification.model.js +0 -4
- package/models/notification.model.js.map +0 -1
- package/models/openai-usage-ledger.model.d.ts +0 -30
- package/models/openai-usage-ledger.model.js +0 -4
- package/models/openai-usage-ledger.model.js.map +0 -1
- package/models/pagination.model.d.ts +0 -11
- package/models/pagination.model.js +0 -28
- package/models/pagination.model.js.map +0 -1
- package/models/permission.model.d.ts +0 -12
- package/models/permission.model.js +0 -4
- package/models/permission.model.js.map +0 -1
- package/models/report-builder-dashboard-builder.model.d.ts +0 -25
- package/models/report-builder-dashboard-builder.model.js +0 -4
- package/models/report-builder-dashboard-builder.model.js.map +0 -1
- package/models/report-builder-library.model.d.ts +0 -17
- package/models/report-builder-library.model.js +0 -4
- package/models/report-builder-library.model.js.map +0 -1
- package/models/report-builder-report.model.d.ts +0 -121
- package/models/report-builder-report.model.js +0 -4
- package/models/report-builder-report.model.js.map +0 -1
- package/models/report-builder.model.d.ts +0 -61
- package/models/report-builder.model.js +0 -4
- package/models/report-builder.model.js.map +0 -1
- package/models/select-data-label.model.d.ts +0 -9
- package/models/select-data-label.model.js +0 -4
- package/models/select-data-label.model.js.map +0 -1
- package/models/server-message.model.d.ts +0 -32
- package/models/server-message.model.js +0 -4
- package/models/server-message.model.js.map +0 -1
- package/models/slow-query-report.model.d.ts +0 -23
- package/models/slow-query-report.model.js +0 -4
- package/models/slow-query-report.model.js.map +0 -1
- package/models/subscription.model.d.ts +0 -31
- package/models/subscription.model.js +0 -4
- package/models/subscription.model.js.map +0 -1
- package/models/support-ticket.model.d.ts +0 -87
- package/models/support-ticket.model.js +0 -4
- package/models/support-ticket.model.js.map +0 -1
- package/models/user-group.model.d.ts +0 -20
- package/models/user-group.model.js +0 -4
- package/models/user-group.model.js.map +0 -1
- package/models/user-guide.model.js +0 -4
- package/models/user-guide.model.js.map +0 -1
- package/models/user.model.d.ts +0 -84
- package/models/user.model.js +0 -4
- package/models/user.model.js.map +0 -1
- package/private/images/ResolveIO.png +0 -0
- package/public_api.js +0 -127
- package/public_api.js.map +0 -1
- package/publications/ai-terminal.d.ts +0 -1
- package/publications/ai-terminal.js +0 -122
- package/publications/ai-terminal.js.map +0 -1
- package/publications/app-settings.d.ts +0 -2
- package/publications/app-settings.js +0 -28
- package/publications/app-settings.js.map +0 -1
- package/publications/app-status.d.ts +0 -2
- package/publications/app-status.js +0 -16
- package/publications/app-status.js.map +0 -1
- package/publications/cron-jobs.d.ts +0 -2
- package/publications/cron-jobs.js +0 -88
- package/publications/cron-jobs.js.map +0 -1
- package/publications/customer-notifications.d.ts +0 -2
- package/publications/customer-notifications.js +0 -161
- package/publications/customer-notifications.js.map +0 -1
- package/publications/files.d.ts +0 -2
- package/publications/files.js +0 -36
- package/publications/files.js.map +0 -1
- package/publications/flags-update.d.ts +0 -2
- package/publications/flags-update.js +0 -22
- package/publications/flags-update.js.map +0 -1
- package/publications/flags.d.ts +0 -2
- package/publications/flags.js +0 -22
- package/publications/flags.js.map +0 -1
- package/publications/logs.d.ts +0 -2
- package/publications/logs.js +0 -164
- package/publications/logs.js.map +0 -1
- package/publications/notifications.d.ts +0 -2
- package/publications/notifications.js +0 -16
- package/publications/notifications.js.map +0 -1
- package/publications/report-builder-dashboard-builders.d.ts +0 -2
- package/publications/report-builder-dashboard-builders.js +0 -42
- package/publications/report-builder-dashboard-builders.js.map +0 -1
- package/publications/report-builder-libraries.d.ts +0 -2
- package/publications/report-builder-libraries.js +0 -90
- package/publications/report-builder-libraries.js.map +0 -1
- package/publications/report-builder-reports.d.ts +0 -2
- package/publications/report-builder-reports.js +0 -50
- package/publications/report-builder-reports.js.map +0 -1
- package/publications/super-admin.d.ts +0 -2
- package/publications/super-admin.js +0 -16
- package/publications/super-admin.js.map +0 -1
- package/publications/user-groups.d.ts +0 -1
- package/publications/user-groups.js +0 -16
- package/publications/user-groups.js.map +0 -1
- package/publications/user-guides.d.ts +0 -1
- package/publications/user-guides.js +0 -16
- package/publications/user-guides.js.map +0 -1
- package/resolveio-server-app.d.ts +0 -70
- package/resolveio-server-app.js +0 -801
- package/resolveio-server-app.js.map +0 -1
- package/server-app.d.ts +0 -228
- package/server-app.js +0 -3566
- package/server-app.js.map +0 -1
- package/services/codex-client.d.ts +0 -128
- package/services/codex-client.js +0 -1629
- package/services/codex-client.js.map +0 -1
- package/services/openai-client.d.ts +0 -46
- package/services/openai-client.js +0 -318
- package/services/openai-client.js.map +0 -1
- package/types/error-report.d.ts +0 -25
- package/types/error-report.js +0 -4
- package/types/error-report.js.map +0 -1
- package/types/slow-query-report.d.ts +0 -27
- package/types/slow-query-report.js +0 -6
- package/types/slow-query-report.js.map +0 -1
- package/util/ai-qa-policy.d.ts +0 -124
- package/util/ai-qa-policy.js +0 -736
- package/util/ai-qa-policy.js.map +0 -1
- package/util/ai-run-evidence-adapters.d.ts +0 -109
- package/util/ai-run-evidence-adapters.js +0 -7234
- package/util/ai-run-evidence-adapters.js.map +0 -1
- package/util/ai-run-evidence-dashboard.d.ts +0 -88
- package/util/ai-run-evidence-dashboard.js +0 -343
- package/util/ai-run-evidence-dashboard.js.map +0 -1
- package/util/ai-run-evidence-eval.d.ts +0 -86
- package/util/ai-run-evidence-eval.js +0 -1018
- package/util/ai-run-evidence-eval.js.map +0 -1
- package/util/ai-run-evidence.d.ts +0 -244
- package/util/ai-run-evidence.js +0 -1096
- package/util/ai-run-evidence.js.map +0 -1
- package/util/ai-runner-artifacts.d.ts +0 -82
- package/util/ai-runner-artifacts.js +0 -713
- package/util/ai-runner-artifacts.js.map +0 -1
- package/util/ai-runner-manager-autopilot.d.ts +0 -210
- package/util/ai-runner-manager-autopilot.js +0 -642
- package/util/ai-runner-manager-autopilot.js.map +0 -1
- package/util/ai-runner-manager-policy.d.ts +0 -807
- package/util/ai-runner-manager-policy.js +0 -3501
- package/util/ai-runner-manager-policy.js.map +0 -1
- package/util/ai-runner-qa-auth.d.ts +0 -5
- package/util/ai-runner-qa-auth.js +0 -839
- package/util/ai-runner-qa-auth.js.map +0 -1
- package/util/ai-runner-qa-tools.d.ts +0 -26
- package/util/ai-runner-qa-tools.js +0 -3520
- package/util/ai-runner-qa-tools.js.map +0 -1
- package/util/aicoder-runner-v6.d.ts +0 -426
- package/util/aicoder-runner-v6.js +0 -2464
- package/util/aicoder-runner-v6.js.map +0 -1
- package/util/common.d.ts +0 -31
- package/util/common.js +0 -683
- package/util/common.js.map +0 -1
- package/util/customer-portal-password.d.ts +0 -13
- package/util/customer-portal-password.js +0 -209
- package/util/customer-portal-password.js.map +0 -1
- package/util/error-reporter.d.ts +0 -52
- package/util/error-reporter.js +0 -326
- package/util/error-reporter.js.map +0 -1
- package/util/error-tracking.d.ts +0 -13
- package/util/error-tracking.js +0 -120
- package/util/error-tracking.js.map +0 -1
- package/util/openai-usage-cost.d.ts +0 -6
- package/util/openai-usage-cost.js +0 -103
- package/util/openai-usage-cost.js.map +0 -1
- package/util/report-builder-unwinds.d.ts +0 -15
- package/util/report-builder-unwinds.js +0 -156
- package/util/report-builder-unwinds.js.map +0 -1
- package/util/runner-process-janitor.d.ts +0 -27
- package/util/runner-process-janitor.js +0 -208
- package/util/runner-process-janitor.js.map +0 -1
- package/util/schema-report-builder.d.ts +0 -6
- package/util/schema-report-builder.js +0 -481
- package/util/schema-report-builder.js.map +0 -1
- package/util/slow-query-reporter.d.ts +0 -28
- package/util/slow-query-reporter.js +0 -226
- package/util/slow-query-reporter.js.map +0 -1
- package/util/subscription-dependency-context.d.ts +0 -34
- package/util/subscription-dependency-context.js +0 -1283
- package/util/subscription-dependency-context.js.map +0 -1
- package/util/support-runner-v5.d.ts +0 -1426
- package/util/support-runner-v5.js +0 -7631
- package/util/support-runner-v5.js.map +0 -1
- package/util/tokenizer.d.ts +0 -5
- package/util/tokenizer.js +0 -41
- package/util/tokenizer.js.map +0 -1
- package/workers/codex-runner.worker.d.ts +0 -1
- package/workers/codex-runner.worker.js +0 -192
- package/workers/codex-runner.worker.js.map +0 -1
- /package/{private → src/private}/email-templates/enrollment.html +0 -0
- /package/{private → src/private}/email-templates/forgot-password.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket-deleted.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket-modified.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket.html +0 -0
- /package/{public_api.d.ts → src/public_api.ts} +0 -0
|
@@ -1,3064 +0,0 @@
|
|
|
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 __values = (this && this.__values) || function(o) {
|
|
66
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
67
|
-
if (m) return m.call(o);
|
|
68
|
-
if (o && typeof o.length === "number") return {
|
|
69
|
-
next: function () {
|
|
70
|
-
if (o && i >= o.length) o = void 0;
|
|
71
|
-
return { value: o && o[i++], done: !o };
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
75
|
-
};
|
|
76
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
77
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
78
|
-
if (ar || !(i in from)) {
|
|
79
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
80
|
-
ar[i] = from[i];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
84
|
-
};
|
|
85
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
86
|
-
exports.ErrorAutoFixManager = void 0;
|
|
87
|
-
exports.registerErrorAutoFixManagerDependencies = registerErrorAutoFixManagerDependencies;
|
|
88
|
-
exports.ensureErrorAutoFixManager = ensureErrorAutoFixManager;
|
|
89
|
-
exports.reportDevError = reportDevError;
|
|
90
|
-
var resolveio_server_app_1 = require("../resolveio-server-app");
|
|
91
|
-
var common_1 = require("../util/common");
|
|
92
|
-
var axios_1 = require("axios");
|
|
93
|
-
var crypto_1 = require("crypto");
|
|
94
|
-
var url_1 = require("url");
|
|
95
|
-
var user_collection_1 = require("../collections/user.collection");
|
|
96
|
-
var app_setting_collection_1 = require("../collections/app-setting.collection");
|
|
97
|
-
var customer_notification_content_manager_1 = require("./customer-notification-content.manager");
|
|
98
|
-
var OPTIONAL_COLLECTION = {
|
|
99
|
-
findOne: function () { return Promise.resolve(null); },
|
|
100
|
-
findById: function () { return Promise.resolve(null); },
|
|
101
|
-
find: function () { return Promise.resolve([]); }
|
|
102
|
-
};
|
|
103
|
-
var AICoderApps = OPTIONAL_COLLECTION;
|
|
104
|
-
var AIDashboardJobs = OPTIONAL_COLLECTION;
|
|
105
|
-
var Clients = OPTIONAL_COLLECTION;
|
|
106
|
-
var ErrorAutoFixLogs = null;
|
|
107
|
-
var configuredErrorAutoFixDependencies = null;
|
|
108
|
-
function resolveErrorAutoFixManagerDependencies(overrides) {
|
|
109
|
-
var resolved = __assign(__assign({}, (configuredErrorAutoFixDependencies || {})), (overrides || {}));
|
|
110
|
-
if (!resolved.ErrorAutoFixLogs) {
|
|
111
|
-
throw new Error('ErrorAutoFixManager dependencies are not configured.');
|
|
112
|
-
}
|
|
113
|
-
return resolved;
|
|
114
|
-
}
|
|
115
|
-
function applyErrorAutoFixDependencies(dependencies) {
|
|
116
|
-
configuredErrorAutoFixDependencies = dependencies;
|
|
117
|
-
Clients = dependencies.Clients || OPTIONAL_COLLECTION;
|
|
118
|
-
ErrorAutoFixLogs = dependencies.ErrorAutoFixLogs;
|
|
119
|
-
AICoderApps = dependencies.AICoderApps || OPTIONAL_COLLECTION;
|
|
120
|
-
AIDashboardJobs = dependencies.AIDashboardJobs || OPTIONAL_COLLECTION;
|
|
121
|
-
}
|
|
122
|
-
function registerErrorAutoFixManagerDependencies(dependencies) {
|
|
123
|
-
applyErrorAutoFixDependencies(dependencies);
|
|
124
|
-
ensureErrorAutoFixManager();
|
|
125
|
-
}
|
|
126
|
-
var INFRA_SUBJECT_KEYWORDS = [
|
|
127
|
-
'failed snapshot',
|
|
128
|
-
'replica set',
|
|
129
|
-
'data size used',
|
|
130
|
-
'oplog',
|
|
131
|
-
'lock during backup',
|
|
132
|
-
'backup',
|
|
133
|
-
'no primary',
|
|
134
|
-
'no secondary',
|
|
135
|
-
'preferred primary',
|
|
136
|
-
'exceeding memory',
|
|
137
|
-
'exceeding storage',
|
|
138
|
-
'unhealthy status',
|
|
139
|
-
'disconnected status',
|
|
140
|
-
'replication lag',
|
|
141
|
-
'database storage size',
|
|
142
|
-
'compacting collections',
|
|
143
|
-
'failed connection',
|
|
144
|
-
'heartbeat',
|
|
145
|
-
'high cpu usage',
|
|
146
|
-
'high ram usage'
|
|
147
|
-
];
|
|
148
|
-
var MONGO_SOURCE_KEYWORDS = [
|
|
149
|
-
'mongo-explorer',
|
|
150
|
-
'mongo explorer',
|
|
151
|
-
'mongo-manager',
|
|
152
|
-
'mongo manager',
|
|
153
|
-
'mongomanager',
|
|
154
|
-
'mongodb'
|
|
155
|
-
];
|
|
156
|
-
var MONGO_TEXT_PATTERNS = [
|
|
157
|
-
/\[mongo\]/i,
|
|
158
|
-
/\bmongo(?:db)?\s+(?:server\s+)?error\b/i,
|
|
159
|
-
/\bmongoservererror\b/i,
|
|
160
|
-
/\bmongonetwork(?:timeout)?error\b/i,
|
|
161
|
-
/\bmongonetworktimeouterror\b/i
|
|
162
|
-
];
|
|
163
|
-
var DEFAULT_ERROR_ALERT_EMAIL = 'dev@resolveio.com';
|
|
164
|
-
var MAX_LOCAL_NOTIFICATION_USERS = 5000;
|
|
165
|
-
var LIBRARY_MARKER_PATTERNS = [
|
|
166
|
-
{ label: 'node_modules stack', pattern: /(?:^|[\/\\])node_modules(?:[\/\\]|$)/i },
|
|
167
|
-
{ label: '@resolveio/client-lib', pattern: /@resolveio\/client-lib(?:-[a-z0-9-]+)?/i },
|
|
168
|
-
{ label: '@resolveio/server-lib', pattern: /@resolveio\/server-lib/i },
|
|
169
|
-
{ label: 'resolveio-client-lib path', pattern: /(?:^|[\/\\])resolveio-client-lib(?:[\/\\]|$)/i },
|
|
170
|
-
{ label: 'resolveio-server-lib path', pattern: /(?:^|[\/\\])resolveio-server-lib(?:[\/\\]|$)/i },
|
|
171
|
-
{ label: 'base template path', pattern: /(?:^|[\/\\])aicoder[\/\\]templates[\/\\]base_(?:small|medium|large|tool)(?:[\/\\]|$)/i }
|
|
172
|
-
];
|
|
173
|
-
var APP_OWNED_PATH_PATTERN = /(?:^|[\/\\])(angular[\/\\]app|server[\/\\]src)(?:[\/\\]|$)/i;
|
|
174
|
-
var FILE_PATH_PATTERN = /(?:webpack:\/\/\/?|\/|\.\/|[A-Za-z]:\\)[^\s'"`]+?\.(?:ts|tsx|js|jsx|mjs|cjs|html|scss|css)/g;
|
|
175
|
-
var ErrorAutoFixManager = /** @class */ (function () {
|
|
176
|
-
function ErrorAutoFixManager(serverConfig, dependencies) {
|
|
177
|
-
this._serverConfig = null;
|
|
178
|
-
this.githubApiBase = 'https://api.github.com';
|
|
179
|
-
this.dashboardMonitors = new Map();
|
|
180
|
-
this.appSettingsAutoOptimizeCacheExpiresAt = 0;
|
|
181
|
-
this.appSettingsAutoOptimizeCacheValue = null;
|
|
182
|
-
this.ready = false;
|
|
183
|
-
var resolvedDependencies = resolveErrorAutoFixManagerDependencies(dependencies);
|
|
184
|
-
applyErrorAutoFixDependencies(resolvedDependencies);
|
|
185
|
-
this._serverConfig = serverConfig || {};
|
|
186
|
-
this.config = this.resolveConfig();
|
|
187
|
-
if (!resolvedDependencies.AICoderApps || !resolvedDependencies.AIDashboardJobs) {
|
|
188
|
-
this.config.dashboardWorkflowEnabled = false;
|
|
189
|
-
}
|
|
190
|
-
if (!this.config.enabled) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (!this.config.dashboardWorkflowEnabled && (!this.config.repoRoot || !this.config.githubOwner || !this.config.githubRepo)) {
|
|
194
|
-
console.warn('ErrorAutoFixManager auto-optimize unavailable - missing repository configuration. Ingest and manual runs remain available.');
|
|
195
|
-
}
|
|
196
|
-
this.ready = true;
|
|
197
|
-
// console.log('ErrorAutoFixManager initialized (HTTP intake mode).');
|
|
198
|
-
// console.log('ErrorAutoFixManager config source:', this.config.configSource);
|
|
199
|
-
// if (this.config.debugLogging) {
|
|
200
|
-
// console.log('ErrorAutoFixManager debug logging enabled.');
|
|
201
|
-
// }
|
|
202
|
-
// if (!this.config.autoOptimizeEnabled) {
|
|
203
|
-
// console.log('ErrorAutoFixManager auto-run disabled. Manual OpenAI runs required.');
|
|
204
|
-
// }
|
|
205
|
-
}
|
|
206
|
-
ErrorAutoFixManager.prototype.isReady = function () {
|
|
207
|
-
var _a;
|
|
208
|
-
return !!(this.ready && ((_a = this.config) === null || _a === void 0 ? void 0 : _a.enabled));
|
|
209
|
-
};
|
|
210
|
-
ErrorAutoFixManager.prototype.validateIngestKey = function (candidate) {
|
|
211
|
-
var _a;
|
|
212
|
-
var keys = Array.isArray((_a = this.config) === null || _a === void 0 ? void 0 : _a.ingestKeys) ? this.config.ingestKeys.filter(Boolean) : [];
|
|
213
|
-
if (!keys.length) {
|
|
214
|
-
return true;
|
|
215
|
-
}
|
|
216
|
-
if (!candidate) {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
return keys.includes(candidate.trim());
|
|
220
|
-
};
|
|
221
|
-
ErrorAutoFixManager.prototype.debugLog = function (message, details) {
|
|
222
|
-
var _a;
|
|
223
|
-
if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.debugLogging)) {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
return;
|
|
227
|
-
if (typeof details === 'undefined') {
|
|
228
|
-
console.log("[ErrorAutoFixManager][debug] ".concat(message));
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
console.log("[ErrorAutoFixManager][debug] ".concat(message), details);
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
ErrorAutoFixManager.prototype.resolveConfig = function () {
|
|
235
|
-
var scAutofix = (this._serverConfig && (this._serverConfig.autofix || this._serverConfig.AUTOFIX)) || {};
|
|
236
|
-
var notifyEmails = [];
|
|
237
|
-
var escalationEmails = [];
|
|
238
|
-
if (process.env.AUTOFIX_NOTIFY_EMAILS) {
|
|
239
|
-
notifyEmails = process.env.AUTOFIX_NOTIFY_EMAILS.split(',').map(function (a) { return a.trim(); }).filter(Boolean);
|
|
240
|
-
}
|
|
241
|
-
else if (Array.isArray(scAutofix.notifyEmails)) {
|
|
242
|
-
notifyEmails = scAutofix.notifyEmails.map(function (a) { return (a || '').trim(); }).filter(Boolean);
|
|
243
|
-
}
|
|
244
|
-
else if (typeof scAutofix.notifyEmails === 'string') {
|
|
245
|
-
notifyEmails = scAutofix.notifyEmails.split(',').map(function (a) { return a.trim(); }).filter(Boolean);
|
|
246
|
-
}
|
|
247
|
-
if (process.env.AUTOFIX_ESCALATION_EMAILS) {
|
|
248
|
-
escalationEmails = process.env.AUTOFIX_ESCALATION_EMAILS.split(',').map(function (a) { return a.trim(); }).filter(Boolean);
|
|
249
|
-
}
|
|
250
|
-
else if (Array.isArray(scAutofix.escalationEmails)) {
|
|
251
|
-
escalationEmails = scAutofix.escalationEmails.map(function (a) { return (a || '').trim(); }).filter(Boolean);
|
|
252
|
-
}
|
|
253
|
-
else if (typeof scAutofix.escalationEmails === 'string') {
|
|
254
|
-
escalationEmails = scAutofix.escalationEmails.split(',').map(function (a) { return a.trim(); }).filter(Boolean);
|
|
255
|
-
}
|
|
256
|
-
var getString = function (envKey, scKey, fallback) {
|
|
257
|
-
if (fallback === void 0) { fallback = ''; }
|
|
258
|
-
return process.env[envKey] || scAutofix[scKey] || fallback;
|
|
259
|
-
};
|
|
260
|
-
var getNumber = function (envKey, scKey, fallback) {
|
|
261
|
-
var envVal = Number(process.env[envKey]);
|
|
262
|
-
if (!Number.isNaN(envVal) && process.env[envKey] !== undefined) {
|
|
263
|
-
return envVal;
|
|
264
|
-
}
|
|
265
|
-
var scVal = Number(scAutofix[scKey]);
|
|
266
|
-
if (!Number.isNaN(scVal) && scAutofix[scKey] !== undefined) {
|
|
267
|
-
return scVal;
|
|
268
|
-
}
|
|
269
|
-
return fallback;
|
|
270
|
-
};
|
|
271
|
-
var getBoolean = function (envKey, scKey, fallback) {
|
|
272
|
-
if (fallback === void 0) { fallback = false; }
|
|
273
|
-
if (typeof process.env[envKey] !== 'undefined') {
|
|
274
|
-
return process.env[envKey] === 'true';
|
|
275
|
-
}
|
|
276
|
-
if (typeof scAutofix[scKey] !== 'undefined') {
|
|
277
|
-
return !!scAutofix[scKey];
|
|
278
|
-
}
|
|
279
|
-
return fallback;
|
|
280
|
-
};
|
|
281
|
-
var parseKeyList = function (value) {
|
|
282
|
-
if (Array.isArray(value)) {
|
|
283
|
-
return value.map(function (val) { return "".concat(val || '').trim(); }).filter(Boolean);
|
|
284
|
-
}
|
|
285
|
-
if (typeof value === 'string') {
|
|
286
|
-
return value.split(',').map(function (val) { return val.trim(); }).filter(Boolean);
|
|
287
|
-
}
|
|
288
|
-
return [];
|
|
289
|
-
};
|
|
290
|
-
var normalizePositiveInt = function (value, fallback) {
|
|
291
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
292
|
-
return fallback;
|
|
293
|
-
}
|
|
294
|
-
return Math.floor(value);
|
|
295
|
-
};
|
|
296
|
-
var openaiProjectId = getString('OPENAI_PROJECT_ID', 'openaiProjectId');
|
|
297
|
-
var openaiEnvironment = getString('OPENAI_ENVIRONMENT', 'openaiEnvironment', openaiProjectId);
|
|
298
|
-
var ingestSource = typeof process.env.AUTOFIX_INGEST_KEYS !== 'undefined'
|
|
299
|
-
? process.env.AUTOFIX_INGEST_KEYS
|
|
300
|
-
: scAutofix.ingestKeys;
|
|
301
|
-
var hasAutoOptimizeEnv = typeof process.env.AUTOFIX_AUTO_OPTIMIZE_ENABLED !== 'undefined';
|
|
302
|
-
var autoOptimizeEnabled = getBoolean('AUTOFIX_AUTO_OPTIMIZE_ENABLED', 'autoOptimizeEnabled', false);
|
|
303
|
-
return {
|
|
304
|
-
enabled: true,
|
|
305
|
-
repoRoot: getString('AUTOFIX_REPO_ROOT', 'repoRoot', ''),
|
|
306
|
-
baseBranch: getString('AUTOFIX_BASE_BRANCH', 'baseBranch', 'main'),
|
|
307
|
-
branchPrefix: getString('AUTOFIX_BRANCH_PREFIX', 'branchPrefix', 'openai/auto'),
|
|
308
|
-
githubToken: getString('GITHUB_TOKEN', 'githubToken', getString('AUTOFIX_GITHUB_TOKEN', 'githubToken')),
|
|
309
|
-
githubOwner: getString('AUTOFIX_GITHUB_OWNER', 'githubOwner', 'resolveio'),
|
|
310
|
-
githubRepo: getString('AUTOFIX_GITHUB_REPO', 'githubRepo', 'resolveio-all'),
|
|
311
|
-
commandTimeoutMs: getNumber('AUTOFIX_COMMAND_TIMEOUT_MS', 'commandTimeoutMs', 600000),
|
|
312
|
-
notifyEmails: notifyEmails,
|
|
313
|
-
debugLogging: getBoolean('AUTOFIX_DEBUG_LOGS', 'debugLogging', false),
|
|
314
|
-
configSource: hasAutoOptimizeEnv ? 'environment' : (Object.keys(scAutofix).length ? 'serverConfig' : 'defaults'),
|
|
315
|
-
openaiEnvironment: openaiEnvironment,
|
|
316
|
-
openaiProjectId: openaiProjectId,
|
|
317
|
-
autoOptimizeEnabled: autoOptimizeEnabled,
|
|
318
|
-
ingestKeys: parseKeyList(ingestSource),
|
|
319
|
-
dashboardWorkflowEnabled: getBoolean('AUTOFIX_DASHBOARD_WORKFLOW_ENABLED', 'dashboardWorkflowEnabled', true),
|
|
320
|
-
dashboardFallbackToGithub: getBoolean('AUTOFIX_DASHBOARD_FALLBACK_TO_GITHUB', 'dashboardFallbackToGithub', true),
|
|
321
|
-
dashboardWaitTimeoutMs: getNumber('AUTOFIX_DASHBOARD_WAIT_TIMEOUT_MS', 'dashboardWaitTimeoutMs', 45 * 60 * 1000),
|
|
322
|
-
dashboardPublishRequired: getBoolean('AUTOFIX_DASHBOARD_PUBLISH_REQUIRED', 'dashboardPublishRequired', true),
|
|
323
|
-
maxAutoRunAttemptsPerIssue: normalizePositiveInt(getNumber('AUTOFIX_MAX_AUTORUN_ATTEMPTS_PER_ISSUE', 'maxAutoRunAttemptsPerIssue', 3), 3),
|
|
324
|
-
escalationEmails: escalationEmails
|
|
325
|
-
};
|
|
326
|
-
};
|
|
327
|
-
ErrorAutoFixManager.prototype.extractEmailAddress = function (value) {
|
|
328
|
-
if (!value) {
|
|
329
|
-
return '';
|
|
330
|
-
}
|
|
331
|
-
var email = value;
|
|
332
|
-
var angleMatch = value.match(/<([^>]+)>/);
|
|
333
|
-
if (angleMatch && angleMatch[1]) {
|
|
334
|
-
email = angleMatch[1];
|
|
335
|
-
}
|
|
336
|
-
email = email.split(';')[0].split(',')[0];
|
|
337
|
-
return email.trim().toLowerCase();
|
|
338
|
-
};
|
|
339
|
-
ErrorAutoFixManager.prototype.escapeRegex = function (value) {
|
|
340
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
341
|
-
};
|
|
342
|
-
ErrorAutoFixManager.prototype.resolveClientForEnvironment = function (environment) {
|
|
343
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
344
|
-
var host, escaped, query, err_1;
|
|
345
|
-
return __generator(this, function (_a) {
|
|
346
|
-
switch (_a.label) {
|
|
347
|
-
case 0:
|
|
348
|
-
host = this.extractHostFromUrl(environment);
|
|
349
|
-
if (!host) {
|
|
350
|
-
return [2 /*return*/, null];
|
|
351
|
-
}
|
|
352
|
-
_a.label = 1;
|
|
353
|
-
case 1:
|
|
354
|
-
_a.trys.push([1, 3, , 4]);
|
|
355
|
-
escaped = this.escapeRegex(host);
|
|
356
|
-
query = {
|
|
357
|
-
website: {
|
|
358
|
-
$regex: escaped,
|
|
359
|
-
$options: 'i'
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
return [4 /*yield*/, Clients.findOne(query)];
|
|
363
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
364
|
-
case 3:
|
|
365
|
-
err_1 = _a.sent();
|
|
366
|
-
console.error('ErrorAutoFixManager resolveClientForEnvironment error:', err_1);
|
|
367
|
-
return [2 /*return*/, null];
|
|
368
|
-
case 4: return [2 /*return*/];
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
};
|
|
373
|
-
ErrorAutoFixManager.prototype.extractHostFromUrl = function (value) {
|
|
374
|
-
if (!value) {
|
|
375
|
-
return null;
|
|
376
|
-
}
|
|
377
|
-
var trimmed = value.trim();
|
|
378
|
-
if (!trimmed) {
|
|
379
|
-
return null;
|
|
380
|
-
}
|
|
381
|
-
try {
|
|
382
|
-
var parsed = new url_1.URL(trimmed);
|
|
383
|
-
return parsed.hostname.toLowerCase();
|
|
384
|
-
}
|
|
385
|
-
catch (_a) {
|
|
386
|
-
return trimmed.toLowerCase();
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
ErrorAutoFixManager.prototype.resolveClientForReport = function (report) {
|
|
390
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
391
|
-
var byId, tryField, _a, _b, _c, err_2;
|
|
392
|
-
var _this = this;
|
|
393
|
-
return __generator(this, function (_d) {
|
|
394
|
-
switch (_d.label) {
|
|
395
|
-
case 0:
|
|
396
|
-
if (!report) {
|
|
397
|
-
return [2 /*return*/, null];
|
|
398
|
-
}
|
|
399
|
-
_d.label = 1;
|
|
400
|
-
case 1:
|
|
401
|
-
_d.trys.push([1, 11, , 12]);
|
|
402
|
-
if (!report.clientId) return [3 /*break*/, 3];
|
|
403
|
-
return [4 /*yield*/, Clients.findById(report.clientId)];
|
|
404
|
-
case 2:
|
|
405
|
-
byId = _d.sent();
|
|
406
|
-
if (byId) {
|
|
407
|
-
return [2 /*return*/, byId];
|
|
408
|
-
}
|
|
409
|
-
_d.label = 3;
|
|
410
|
-
case 3:
|
|
411
|
-
tryField = function (field, value) { return __awaiter(_this, void 0, void 0, function () {
|
|
412
|
-
var escaped, query;
|
|
413
|
-
return __generator(this, function (_a) {
|
|
414
|
-
switch (_a.label) {
|
|
415
|
-
case 0:
|
|
416
|
-
if (!value) {
|
|
417
|
-
return [2 /*return*/, null];
|
|
418
|
-
}
|
|
419
|
-
escaped = this.escapeRegex(value);
|
|
420
|
-
query = {};
|
|
421
|
-
query[field] = { $regex: "^".concat(escaped, "$"), $options: 'i' };
|
|
422
|
-
return [4 /*yield*/, Clients.findOne(query)];
|
|
423
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
}); };
|
|
427
|
-
return [4 /*yield*/, tryField('name', report.clientName)];
|
|
428
|
-
case 4:
|
|
429
|
-
_c = (_d.sent());
|
|
430
|
-
if (_c) return [3 /*break*/, 6];
|
|
431
|
-
return [4 /*yield*/, tryField('demo_name', report.clientSlug)];
|
|
432
|
-
case 5:
|
|
433
|
-
_c = (_d.sent());
|
|
434
|
-
_d.label = 6;
|
|
435
|
-
case 6:
|
|
436
|
-
_b = _c;
|
|
437
|
-
if (_b) return [3 /*break*/, 8];
|
|
438
|
-
return [4 /*yield*/, tryField('repo', report.clientRepo)];
|
|
439
|
-
case 7:
|
|
440
|
-
_b = (_d.sent());
|
|
441
|
-
_d.label = 8;
|
|
442
|
-
case 8:
|
|
443
|
-
_a = _b;
|
|
444
|
-
if (_a) return [3 /*break*/, 10];
|
|
445
|
-
return [4 /*yield*/, this.resolveClientForEnvironment(report.environment)];
|
|
446
|
-
case 9:
|
|
447
|
-
_a = (_d.sent());
|
|
448
|
-
_d.label = 10;
|
|
449
|
-
case 10: return [2 /*return*/, (_a)];
|
|
450
|
-
case 11:
|
|
451
|
-
err_2 = _d.sent();
|
|
452
|
-
console.error('ErrorAutoFixManager resolveClientForReport error:', err_2);
|
|
453
|
-
return [2 /*return*/, null];
|
|
454
|
-
case 12: return [2 /*return*/];
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
});
|
|
458
|
-
};
|
|
459
|
-
ErrorAutoFixManager.prototype.determineOpenAIEnvironment = function (client) {
|
|
460
|
-
var repoCandidate = ((client === null || client === void 0 ? void 0 : client.repo) || '').trim();
|
|
461
|
-
if (repoCandidate) {
|
|
462
|
-
return repoCandidate;
|
|
463
|
-
}
|
|
464
|
-
var configEnv = (this.config.openaiEnvironment || '').trim();
|
|
465
|
-
if (configEnv) {
|
|
466
|
-
return configEnv;
|
|
467
|
-
}
|
|
468
|
-
if ((this.config.githubOwner || '').trim() && (this.config.githubRepo || '').trim()) {
|
|
469
|
-
return "".concat(this.config.githubOwner, "/").concat(this.config.githubRepo).trim();
|
|
470
|
-
}
|
|
471
|
-
return '';
|
|
472
|
-
};
|
|
473
|
-
ErrorAutoFixManager.prototype.resolveEnvironmentForTask = function (email, log) {
|
|
474
|
-
if (email && email.openai_environment && email.openai_environment.trim()) {
|
|
475
|
-
return email.openai_environment.trim();
|
|
476
|
-
}
|
|
477
|
-
if (log && log.openai_environment && log.openai_environment.trim()) {
|
|
478
|
-
return log.openai_environment.trim();
|
|
479
|
-
}
|
|
480
|
-
return this.determineOpenAIEnvironment();
|
|
481
|
-
};
|
|
482
|
-
ErrorAutoFixManager.prototype.buildEmailFromReport = function (report) {
|
|
483
|
-
var timestamp = report.reportedAt instanceof Date && !Number.isNaN(report.reportedAt.getTime())
|
|
484
|
-
? report.reportedAt
|
|
485
|
-
: new Date();
|
|
486
|
-
var safeMessage = (report.message || '').toString().trim() || 'Unknown error';
|
|
487
|
-
var subjectBase = "[AppError] ".concat(report.sourceApp || 'application').concat(report.environment ? " (".concat(report.environment, ")") : '');
|
|
488
|
-
var subject = "".concat(subjectBase, " - ").concat(safeMessage.slice(0, 120));
|
|
489
|
-
var lines = [
|
|
490
|
-
"Source App:\t".concat(report.sourceApp),
|
|
491
|
-
"Environment:\t".concat(report.environment || 'n/a'),
|
|
492
|
-
"Severity:\t".concat(report.severity || 'error'),
|
|
493
|
-
"Client Hint:\t".concat(report.clientName || report.clientSlug || report.clientRepo || report.clientId || 'n/a'),
|
|
494
|
-
"Reported By:\t".concat(report.reportedBy || report.clientEmail || 'n/a'),
|
|
495
|
-
"Reported At:\t".concat(timestamp.toISOString()),
|
|
496
|
-
"Message:\t".concat(safeMessage)
|
|
497
|
-
];
|
|
498
|
-
if (report.stack) {
|
|
499
|
-
lines.push('', 'Stack Trace:', report.stack);
|
|
500
|
-
}
|
|
501
|
-
if (report.context && typeof report.context === 'object' && Object.keys(report.context).length) {
|
|
502
|
-
lines.push('', 'Context JSON:', JSON.stringify(report.context, null, 2));
|
|
503
|
-
}
|
|
504
|
-
if (report.metadata && typeof report.metadata === 'object' && Object.keys(report.metadata).length) {
|
|
505
|
-
lines.push('', 'Metadata JSON:', JSON.stringify(report.metadata, null, 2));
|
|
506
|
-
}
|
|
507
|
-
if (Array.isArray(report.attachments) && report.attachments.length) {
|
|
508
|
-
lines.push('', 'Attachments:');
|
|
509
|
-
report.attachments.forEach(function (att) {
|
|
510
|
-
var desc = [];
|
|
511
|
-
if (att.name) {
|
|
512
|
-
desc.push(att.name);
|
|
513
|
-
}
|
|
514
|
-
if (att.contentType) {
|
|
515
|
-
desc.push(att.contentType);
|
|
516
|
-
}
|
|
517
|
-
if (typeof att.size === 'number') {
|
|
518
|
-
desc.push("".concat(att.size, "b"));
|
|
519
|
-
}
|
|
520
|
-
var summary = desc.length ? desc.join(' | ') : 'attachment';
|
|
521
|
-
lines.push("- ".concat(summary).concat(att.url ? " -> ".concat(att.url) : ''));
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
if (report.fingerprint) {
|
|
525
|
-
lines.push('', "Fingerprint:\t".concat(report.fingerprint));
|
|
526
|
-
}
|
|
527
|
-
if (report.idempotencyKey) {
|
|
528
|
-
lines.push("Idempotency Key:\t".concat(report.idempotencyKey));
|
|
529
|
-
}
|
|
530
|
-
var body = lines.join('\n');
|
|
531
|
-
return {
|
|
532
|
-
key: "report:".concat(timestamp.getTime().toString(36), ":").concat(Math.random().toString(36).slice(2, 10)),
|
|
533
|
-
subject: subject,
|
|
534
|
-
body: body,
|
|
535
|
-
raw: body,
|
|
536
|
-
from: report.reportedBy || report.clientEmail || 'errors@resolveio.com',
|
|
537
|
-
sourceApp: report.sourceApp,
|
|
538
|
-
sourceEnvironment: report.environment,
|
|
539
|
-
severity: report.severity,
|
|
540
|
-
reportedBy: report.reportedBy,
|
|
541
|
-
reportMetadata: report.metadata,
|
|
542
|
-
reportContext: report.context,
|
|
543
|
-
attachments: Array.isArray(report.attachments) ? report.attachments : [],
|
|
544
|
-
openai_environment: report.clientRepo,
|
|
545
|
-
reportedAt: timestamp
|
|
546
|
-
};
|
|
547
|
-
};
|
|
548
|
-
ErrorAutoFixManager.prototype.classifyEmail = function (email) {
|
|
549
|
-
var subject = (email.subject || '').toLowerCase();
|
|
550
|
-
var body = email.body || '';
|
|
551
|
-
var normalizedBody = body.toLowerCase();
|
|
552
|
-
if (subject.includes('autofix') &&
|
|
553
|
-
(normalizedBody.includes('auto-fix workflow') || normalizedBody.includes('autofix workflow'))) {
|
|
554
|
-
return { source: 'noise', skip: true, reason: 'AutoFix status notification' };
|
|
555
|
-
}
|
|
556
|
-
if (this.isMongoOriginError(email)) {
|
|
557
|
-
return {
|
|
558
|
-
source: 'infrastructure',
|
|
559
|
-
skip: true,
|
|
560
|
-
reason: 'Mongo-origin error ignored for auto-fix',
|
|
561
|
-
markIgnored: true
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
if (subject.includes('[database]') || subject.includes('[server]')) {
|
|
565
|
-
return { source: 'infrastructure', skip: true, reason: 'Infrastructure alert (subject tag)' };
|
|
566
|
-
}
|
|
567
|
-
var infraKeyword = INFRA_SUBJECT_KEYWORDS.find(function (keyword) { return subject.includes(keyword); });
|
|
568
|
-
if (infraKeyword) {
|
|
569
|
-
return { source: 'infrastructure', skip: true, reason: "Infrastructure alert (".concat(infraKeyword, ")") };
|
|
570
|
-
}
|
|
571
|
-
if (!body.trim()) {
|
|
572
|
-
return { source: 'noise', skip: true, reason: 'Empty error payload' };
|
|
573
|
-
}
|
|
574
|
-
var emptyErrorsRegex = /errors\s*[\r\n]+(\{\s*\}|\[\s*\])/i;
|
|
575
|
-
if (emptyErrorsRegex.test(body)) {
|
|
576
|
-
return { source: 'noise', skip: true, reason: 'Empty error details' };
|
|
577
|
-
}
|
|
578
|
-
if (subject.includes('database is down') || normalizedBody.includes('database is down')) {
|
|
579
|
-
return { source: 'infrastructure', skip: true, reason: 'Database outage alert' };
|
|
580
|
-
}
|
|
581
|
-
return { source: 'app', skip: false };
|
|
582
|
-
};
|
|
583
|
-
ErrorAutoFixManager.prototype.isMongoOriginError = function (email) {
|
|
584
|
-
var sourceApp = String((email === null || email === void 0 ? void 0 : email.sourceApp) || '').toLowerCase();
|
|
585
|
-
var sourceEnvironment = String((email === null || email === void 0 ? void 0 : email.sourceEnvironment) || '').toLowerCase();
|
|
586
|
-
var subject = String((email === null || email === void 0 ? void 0 : email.subject) || '').toLowerCase();
|
|
587
|
-
var body = String((email === null || email === void 0 ? void 0 : email.body) || '');
|
|
588
|
-
var sourceMatches = MONGO_SOURCE_KEYWORDS.some(function (keyword) {
|
|
589
|
-
return sourceApp.includes(keyword) || sourceEnvironment.includes(keyword);
|
|
590
|
-
});
|
|
591
|
-
if (sourceMatches) {
|
|
592
|
-
return true;
|
|
593
|
-
}
|
|
594
|
-
var text = "".concat(subject, "\n").concat(body);
|
|
595
|
-
return MONGO_TEXT_PATTERNS.some(function (pattern) { return pattern.test(text); });
|
|
596
|
-
};
|
|
597
|
-
ErrorAutoFixManager.prototype.generateRawEmailHash = function (email) {
|
|
598
|
-
return (0, crypto_1.createHash)('sha256').update("".concat(email.subject || '', "\n").concat(email.body || ''), 'utf8').digest('hex');
|
|
599
|
-
};
|
|
600
|
-
ErrorAutoFixManager.prototype.generateIssueHash = function (email) {
|
|
601
|
-
var subject = this.normalizeTextForHash(email.subject || '');
|
|
602
|
-
var body = this.normalizeBodyForHash(email.body || '');
|
|
603
|
-
return (0, crypto_1.createHash)('sha256').update("".concat(subject, "\n").concat(body), 'utf8').digest('hex');
|
|
604
|
-
};
|
|
605
|
-
ErrorAutoFixManager.prototype.normalizeTextForHash = function (value) {
|
|
606
|
-
if (!value) {
|
|
607
|
-
return '';
|
|
608
|
-
}
|
|
609
|
-
var normalized = value
|
|
610
|
-
.replace(/\r/g, '\n')
|
|
611
|
-
.toLowerCase()
|
|
612
|
-
.replace(/0x[0-9a-f]+/gi, '0x#')
|
|
613
|
-
.replace(/\b[0-9a-f]{7,64}\b/gi, '#')
|
|
614
|
-
.replace(/\b[0-9]{4}[-/][0-9]{2}[-/][0-9]{2}(?:[ t][0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]{1,6})?)?\b/g, '#datetime#')
|
|
615
|
-
.replace(/\b[0-9]{2}:[0-9]{2}:[0-9]{2}\b/g, '#time#')
|
|
616
|
-
.replace(/[0-9]+/g, '#')
|
|
617
|
-
.replace(/[^\S\n]+/g, ' ')
|
|
618
|
-
.split('\n')
|
|
619
|
-
.map(function (line) { return line.trim(); })
|
|
620
|
-
.filter(Boolean)
|
|
621
|
-
.slice(0, 60)
|
|
622
|
-
.join('\n');
|
|
623
|
-
return normalized.length > 4000 ? normalized.slice(0, 4000) : normalized;
|
|
624
|
-
};
|
|
625
|
-
ErrorAutoFixManager.prototype.normalizeBodyForHash = function (body) {
|
|
626
|
-
if (!body) {
|
|
627
|
-
return '';
|
|
628
|
-
}
|
|
629
|
-
var withoutStackNoise = body
|
|
630
|
-
.replace(/=+\s*stack trace\s*=+/gi, 'stack trace')
|
|
631
|
-
.replace(/-{3,}/g, '-')
|
|
632
|
-
.replace(/\[[^\]]*request id[^\]]*\]/gi, '[request id]')
|
|
633
|
-
.replace(/guid:[^\s]+/gi, 'guid:#')
|
|
634
|
-
.replace(/request id:[^\s]+/gi, 'request id:#')
|
|
635
|
-
.replace(/correlation id:[^\s]+/gi, 'correlation id:#');
|
|
636
|
-
return this.normalizeTextForHash(withoutStackNoise);
|
|
637
|
-
};
|
|
638
|
-
ErrorAutoFixManager.prototype.parseRepoTarget = function (env) {
|
|
639
|
-
var trimmed = (env || '').trim();
|
|
640
|
-
if (!trimmed) {
|
|
641
|
-
return null;
|
|
642
|
-
}
|
|
643
|
-
var _a = __read(trimmed.split('/', 2), 2), owner = _a[0], repo = _a[1];
|
|
644
|
-
if (!owner || !repo) {
|
|
645
|
-
return null;
|
|
646
|
-
}
|
|
647
|
-
return {
|
|
648
|
-
owner: owner.trim(),
|
|
649
|
-
repo: repo.trim()
|
|
650
|
-
};
|
|
651
|
-
};
|
|
652
|
-
ErrorAutoFixManager.prototype.buildWorkBranch = function (hash) {
|
|
653
|
-
var shortHash = (hash || '').toLowerCase().replace(/[^a-z0-9]/g, '').slice(0, 12) || 'autofix';
|
|
654
|
-
var prefix = (this.config.branchPrefix || 'openai/auto').trim();
|
|
655
|
-
if (!prefix) {
|
|
656
|
-
return shortHash;
|
|
657
|
-
}
|
|
658
|
-
var segments = prefix.split('/').map(function (segment) { return segment.trim(); }).filter(Boolean);
|
|
659
|
-
var sanitized = segments.map(function (segment) { return segment.replace(/[^a-zA-Z0-9._-]/g, '-'); });
|
|
660
|
-
return "".concat(sanitized.join('/'), "/").concat(shortHash);
|
|
661
|
-
};
|
|
662
|
-
ErrorAutoFixManager.prototype.normalizeEmailText = function (value, limit) {
|
|
663
|
-
if (limit === void 0) { limit = 20000; }
|
|
664
|
-
if (!value) {
|
|
665
|
-
return '';
|
|
666
|
-
}
|
|
667
|
-
var cleaned = value.replace(/\r/g, '');
|
|
668
|
-
if (cleaned.length <= limit) {
|
|
669
|
-
return cleaned;
|
|
670
|
-
}
|
|
671
|
-
return "".concat(cleaned.slice(0, limit), "\n... (truncated)");
|
|
672
|
-
};
|
|
673
|
-
ErrorAutoFixManager.prototype.buildContextMarkdown = function (email, identifier, normalizedBody) {
|
|
674
|
-
var lines = [
|
|
675
|
-
"# OpenAI Error Context: ".concat(identifier),
|
|
676
|
-
'',
|
|
677
|
-
"**Subject**: ".concat(email.subject || '(no subject)'),
|
|
678
|
-
email.fromAddress ? "**From**: ".concat(email.fromAddress) : undefined,
|
|
679
|
-
email.client_name ? "**Client**: ".concat(email.client_name) : undefined,
|
|
680
|
-
email.source_type ? "**Classification**: ".concat(email.source_type).concat(email.classification_reason ? " (".concat(email.classification_reason, ")") : '') : undefined,
|
|
681
|
-
email.id_client ? "**Client Id**: ".concat(email.id_client) : undefined,
|
|
682
|
-
'',
|
|
683
|
-
'## Body',
|
|
684
|
-
'```',
|
|
685
|
-
normalizedBody || '(empty body)',
|
|
686
|
-
'```',
|
|
687
|
-
'',
|
|
688
|
-
'_Generated by ErrorAutoFixManager_'
|
|
689
|
-
];
|
|
690
|
-
return lines.filter(function (line) { return typeof line !== 'undefined'; }).join('\n');
|
|
691
|
-
};
|
|
692
|
-
ErrorAutoFixManager.prototype.buildOpenAIComment = function (email, contextPath, normalizedBody) {
|
|
693
|
-
var lines = [
|
|
694
|
-
'@openai review',
|
|
695
|
-
'',
|
|
696
|
-
"**Email Subject**: ".concat(email.subject || '(no subject)'),
|
|
697
|
-
email.fromAddress ? "**From**: ".concat(email.fromAddress) : undefined,
|
|
698
|
-
email.client_name ? "**Client**: ".concat(email.client_name) : undefined,
|
|
699
|
-
contextPath ? "Context file: `".concat(contextPath, "`") : undefined,
|
|
700
|
-
'',
|
|
701
|
-
'```',
|
|
702
|
-
normalizedBody || '(empty body)',
|
|
703
|
-
'```',
|
|
704
|
-
'',
|
|
705
|
-
'Please investigate this error and propose a minimal, safe fix.'
|
|
706
|
-
];
|
|
707
|
-
return lines.filter(function (line) { return typeof line !== 'undefined'; }).join('\n');
|
|
708
|
-
};
|
|
709
|
-
ErrorAutoFixManager.prototype.formatGithubError = function (error) {
|
|
710
|
-
var _a, _b, _c;
|
|
711
|
-
if (!error) {
|
|
712
|
-
return 'GitHub request failed.';
|
|
713
|
-
}
|
|
714
|
-
var status = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status;
|
|
715
|
-
var message = ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || (error === null || error === void 0 ? void 0 : error.message) || 'GitHub request failed.';
|
|
716
|
-
if (status) {
|
|
717
|
-
return "GitHub API error (".concat(status, "): ").concat(message);
|
|
718
|
-
}
|
|
719
|
-
return "GitHub API error: ".concat(message);
|
|
720
|
-
};
|
|
721
|
-
ErrorAutoFixManager.prototype.buildGithubAuthHeader = function (token) {
|
|
722
|
-
var trimmed = (token || '').trim();
|
|
723
|
-
if (!trimmed) {
|
|
724
|
-
return '';
|
|
725
|
-
}
|
|
726
|
-
if (/^(token|Bearer)\s+/i.test(trimmed)) {
|
|
727
|
-
return trimmed;
|
|
728
|
-
}
|
|
729
|
-
if (trimmed.includes('.') && !trimmed.startsWith('gh')) {
|
|
730
|
-
return "Bearer ".concat(trimmed);
|
|
731
|
-
}
|
|
732
|
-
return "token ".concat(trimmed);
|
|
733
|
-
};
|
|
734
|
-
ErrorAutoFixManager.prototype.githubRequest = function (config_1) {
|
|
735
|
-
return __awaiter(this, arguments, void 0, function (config, allow404) {
|
|
736
|
-
var authHeader, headers, finalConfig, response, err_3, status_1;
|
|
737
|
-
var _a;
|
|
738
|
-
if (allow404 === void 0) { allow404 = false; }
|
|
739
|
-
return __generator(this, function (_b) {
|
|
740
|
-
switch (_b.label) {
|
|
741
|
-
case 0:
|
|
742
|
-
authHeader = this.buildGithubAuthHeader(this.config.githubToken);
|
|
743
|
-
headers = __assign(__assign({}, (authHeader ? { Authorization: authHeader } : {})), { Accept: 'application/vnd.github+json', 'User-Agent': 'ResolveIO-AutoFix', 'X-GitHub-Api-Version': '2022-11-28' });
|
|
744
|
-
finalConfig = __assign(__assign({}, config), { baseURL: this.githubApiBase, headers: __assign(__assign({}, headers), (config.headers || {})), timeout: Math.min(Math.max(this.config.commandTimeoutMs || 600000, 1000), 120000) });
|
|
745
|
-
_b.label = 1;
|
|
746
|
-
case 1:
|
|
747
|
-
_b.trys.push([1, 3, , 4]);
|
|
748
|
-
return [4 /*yield*/, axios_1.default.request(finalConfig)];
|
|
749
|
-
case 2:
|
|
750
|
-
response = _b.sent();
|
|
751
|
-
return [2 /*return*/, response.data];
|
|
752
|
-
case 3:
|
|
753
|
-
err_3 = _b.sent();
|
|
754
|
-
status_1 = (_a = err_3 === null || err_3 === void 0 ? void 0 : err_3.response) === null || _a === void 0 ? void 0 : _a.status;
|
|
755
|
-
if (allow404 && status_1 === 404) {
|
|
756
|
-
return [2 /*return*/, null];
|
|
757
|
-
}
|
|
758
|
-
throw new Error(this.formatGithubError(err_3));
|
|
759
|
-
case 4: return [2 /*return*/];
|
|
760
|
-
}
|
|
761
|
-
});
|
|
762
|
-
});
|
|
763
|
-
};
|
|
764
|
-
ErrorAutoFixManager.prototype.resolveBaseBranch = function (target) {
|
|
765
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
766
|
-
var fallback, repo, defaultBranch, err_4;
|
|
767
|
-
return __generator(this, function (_a) {
|
|
768
|
-
switch (_a.label) {
|
|
769
|
-
case 0:
|
|
770
|
-
fallback = (this.config.baseBranch || 'main').trim();
|
|
771
|
-
_a.label = 1;
|
|
772
|
-
case 1:
|
|
773
|
-
_a.trys.push([1, 3, , 4]);
|
|
774
|
-
return [4 /*yield*/, this.githubRequest({ method: 'GET', url: "/repos/".concat(target.owner, "/").concat(target.repo) })];
|
|
775
|
-
case 2:
|
|
776
|
-
repo = _a.sent();
|
|
777
|
-
defaultBranch = ((repo === null || repo === void 0 ? void 0 : repo.default_branch) || '').trim();
|
|
778
|
-
return [2 /*return*/, defaultBranch || fallback];
|
|
779
|
-
case 3:
|
|
780
|
-
err_4 = _a.sent();
|
|
781
|
-
this.debugLog('Failed to fetch default branch. Falling back to configured branch.', {
|
|
782
|
-
target: target,
|
|
783
|
-
error: err_4 === null || err_4 === void 0 ? void 0 : err_4.message
|
|
784
|
-
});
|
|
785
|
-
return [2 /*return*/, fallback];
|
|
786
|
-
case 4: return [2 /*return*/];
|
|
787
|
-
}
|
|
788
|
-
});
|
|
789
|
-
});
|
|
790
|
-
};
|
|
791
|
-
ErrorAutoFixManager.prototype.getBranchSha = function (target, branch) {
|
|
792
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
793
|
-
var ref, sha;
|
|
794
|
-
var _a;
|
|
795
|
-
return __generator(this, function (_b) {
|
|
796
|
-
switch (_b.label) {
|
|
797
|
-
case 0: return [4 /*yield*/, this.githubRequest({ method: 'GET', url: "/repos/".concat(target.owner, "/").concat(target.repo, "/git/ref/heads/").concat(branch) })];
|
|
798
|
-
case 1:
|
|
799
|
-
ref = _b.sent();
|
|
800
|
-
sha = (_a = ref === null || ref === void 0 ? void 0 : ref.object) === null || _a === void 0 ? void 0 : _a.sha;
|
|
801
|
-
if (!sha) {
|
|
802
|
-
throw new Error("Base branch ".concat(branch, " not found."));
|
|
803
|
-
}
|
|
804
|
-
return [2 /*return*/, sha];
|
|
805
|
-
}
|
|
806
|
-
});
|
|
807
|
-
});
|
|
808
|
-
};
|
|
809
|
-
ErrorAutoFixManager.prototype.ensureBranch = function (target, newBranch, baseBranch, baseSha) {
|
|
810
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
811
|
-
var existing;
|
|
812
|
-
return __generator(this, function (_a) {
|
|
813
|
-
switch (_a.label) {
|
|
814
|
-
case 0: return [4 /*yield*/, this.githubRequest({ method: 'GET', url: "/repos/".concat(target.owner, "/").concat(target.repo, "/git/ref/heads/").concat(newBranch) }, true)];
|
|
815
|
-
case 1:
|
|
816
|
-
existing = _a.sent();
|
|
817
|
-
if (existing) {
|
|
818
|
-
return [2 /*return*/];
|
|
819
|
-
}
|
|
820
|
-
return [4 /*yield*/, this.githubRequest({
|
|
821
|
-
method: 'POST',
|
|
822
|
-
url: "/repos/".concat(target.owner, "/").concat(target.repo, "/git/refs"),
|
|
823
|
-
data: {
|
|
824
|
-
ref: "refs/heads/".concat(newBranch),
|
|
825
|
-
sha: baseSha
|
|
826
|
-
}
|
|
827
|
-
})];
|
|
828
|
-
case 2:
|
|
829
|
-
_a.sent();
|
|
830
|
-
return [2 /*return*/];
|
|
831
|
-
}
|
|
832
|
-
});
|
|
833
|
-
});
|
|
834
|
-
};
|
|
835
|
-
ErrorAutoFixManager.prototype.upsertContextFile = function (target, branch, contextPath, content) {
|
|
836
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
837
|
-
var encodedPath, existing, sha, commitMessage;
|
|
838
|
-
return __generator(this, function (_a) {
|
|
839
|
-
switch (_a.label) {
|
|
840
|
-
case 0:
|
|
841
|
-
encodedPath = encodeURIComponent(contextPath).replace(/%2F/g, '/');
|
|
842
|
-
return [4 /*yield*/, this.githubRequest({
|
|
843
|
-
method: 'GET',
|
|
844
|
-
url: "/repos/".concat(target.owner, "/").concat(target.repo, "/contents/").concat(encodedPath),
|
|
845
|
-
params: { ref: branch }
|
|
846
|
-
}, true)];
|
|
847
|
-
case 1:
|
|
848
|
-
existing = _a.sent();
|
|
849
|
-
sha = existing && existing.sha ? existing.sha : undefined;
|
|
850
|
-
commitMessage = "chore(openai): update error context ".concat(contextPath);
|
|
851
|
-
return [4 /*yield*/, this.githubRequest({
|
|
852
|
-
method: 'PUT',
|
|
853
|
-
url: "/repos/".concat(target.owner, "/").concat(target.repo, "/contents/").concat(encodedPath),
|
|
854
|
-
data: {
|
|
855
|
-
message: commitMessage.slice(0, 200),
|
|
856
|
-
content: Buffer.from(content, 'utf8').toString('base64'),
|
|
857
|
-
branch: branch,
|
|
858
|
-
sha: sha
|
|
859
|
-
}
|
|
860
|
-
})];
|
|
861
|
-
case 2:
|
|
862
|
-
_a.sent();
|
|
863
|
-
return [2 /*return*/];
|
|
864
|
-
}
|
|
865
|
-
});
|
|
866
|
-
});
|
|
867
|
-
};
|
|
868
|
-
ErrorAutoFixManager.prototype.findOpenPullRequest = function (target, branch, base) {
|
|
869
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
870
|
-
var prs;
|
|
871
|
-
return __generator(this, function (_a) {
|
|
872
|
-
switch (_a.label) {
|
|
873
|
-
case 0: return [4 /*yield*/, this.githubRequest({
|
|
874
|
-
method: 'GET',
|
|
875
|
-
url: "/repos/".concat(target.owner, "/").concat(target.repo, "/pulls"),
|
|
876
|
-
params: {
|
|
877
|
-
state: 'open',
|
|
878
|
-
head: "".concat(target.owner, ":").concat(branch),
|
|
879
|
-
base: base,
|
|
880
|
-
per_page: 1
|
|
881
|
-
}
|
|
882
|
-
})];
|
|
883
|
-
case 1:
|
|
884
|
-
prs = _a.sent();
|
|
885
|
-
if (prs && prs.length) {
|
|
886
|
-
return [2 /*return*/, prs[0]];
|
|
887
|
-
}
|
|
888
|
-
return [2 /*return*/, null];
|
|
889
|
-
}
|
|
890
|
-
});
|
|
891
|
-
});
|
|
892
|
-
};
|
|
893
|
-
ErrorAutoFixManager.prototype.createPullRequest = function (target, branch, base, title, body) {
|
|
894
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
895
|
-
var pr;
|
|
896
|
-
return __generator(this, function (_a) {
|
|
897
|
-
switch (_a.label) {
|
|
898
|
-
case 0: return [4 /*yield*/, this.githubRequest({
|
|
899
|
-
method: 'POST',
|
|
900
|
-
url: "/repos/".concat(target.owner, "/").concat(target.repo, "/pulls"),
|
|
901
|
-
data: {
|
|
902
|
-
title: title,
|
|
903
|
-
head: branch,
|
|
904
|
-
base: base,
|
|
905
|
-
body: body
|
|
906
|
-
}
|
|
907
|
-
})];
|
|
908
|
-
case 1:
|
|
909
|
-
pr = _a.sent();
|
|
910
|
-
return [2 /*return*/, pr];
|
|
911
|
-
}
|
|
912
|
-
});
|
|
913
|
-
});
|
|
914
|
-
};
|
|
915
|
-
ErrorAutoFixManager.prototype.commentOnPullRequest = function (target, prNumber, body) {
|
|
916
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
917
|
-
return __generator(this, function (_a) {
|
|
918
|
-
switch (_a.label) {
|
|
919
|
-
case 0: return [4 /*yield*/, this.githubRequest({
|
|
920
|
-
method: 'POST',
|
|
921
|
-
url: "/repos/".concat(target.owner, "/").concat(target.repo, "/issues/").concat(prNumber, "/comments"),
|
|
922
|
-
data: {
|
|
923
|
-
body: body
|
|
924
|
-
}
|
|
925
|
-
})];
|
|
926
|
-
case 1:
|
|
927
|
-
_a.sent();
|
|
928
|
-
return [2 /*return*/];
|
|
929
|
-
}
|
|
930
|
-
});
|
|
931
|
-
});
|
|
932
|
-
};
|
|
933
|
-
ErrorAutoFixManager.prototype.parseBooleanEnv = function (envKey) {
|
|
934
|
-
if (typeof process.env[envKey] === 'undefined') {
|
|
935
|
-
return null;
|
|
936
|
-
}
|
|
937
|
-
return process.env[envKey] === 'true';
|
|
938
|
-
};
|
|
939
|
-
ErrorAutoFixManager.prototype.resolveAutoOptimizeEnabled = function () {
|
|
940
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
941
|
-
var now, envValue, enabled, activeSetting, _a, error_1;
|
|
942
|
-
var _b;
|
|
943
|
-
return __generator(this, function (_c) {
|
|
944
|
-
switch (_c.label) {
|
|
945
|
-
case 0:
|
|
946
|
-
now = Date.now();
|
|
947
|
-
if (this.appSettingsAutoOptimizeCacheValue !== null && now < this.appSettingsAutoOptimizeCacheExpiresAt) {
|
|
948
|
-
return [2 /*return*/, this.appSettingsAutoOptimizeCacheValue];
|
|
949
|
-
}
|
|
950
|
-
envValue = this.parseBooleanEnv('AUTOFIX_AUTO_OPTIMIZE_ENABLED');
|
|
951
|
-
enabled = envValue !== null ? envValue : !!this.config.autoOptimizeEnabled;
|
|
952
|
-
_c.label = 1;
|
|
953
|
-
case 1:
|
|
954
|
-
_c.trys.push([1, 6, , 7]);
|
|
955
|
-
if (!(app_setting_collection_1.AppSettings && typeof app_setting_collection_1.AppSettings.findOne === 'function')) return [3 /*break*/, 5];
|
|
956
|
-
return [4 /*yield*/, app_setting_collection_1.AppSettings.findOne({
|
|
957
|
-
is_active: {
|
|
958
|
-
$ne: false
|
|
959
|
-
}
|
|
960
|
-
}, {
|
|
961
|
-
sort: {
|
|
962
|
-
updatedAt: -1,
|
|
963
|
-
createdAt: -1
|
|
964
|
-
}
|
|
965
|
-
})];
|
|
966
|
-
case 2:
|
|
967
|
-
_a = (_c.sent());
|
|
968
|
-
if (_a) return [3 /*break*/, 4];
|
|
969
|
-
return [4 /*yield*/, app_setting_collection_1.AppSettings.findOne({}, {
|
|
970
|
-
sort: {
|
|
971
|
-
updatedAt: -1,
|
|
972
|
-
createdAt: -1
|
|
973
|
-
}
|
|
974
|
-
})];
|
|
975
|
-
case 3:
|
|
976
|
-
_a = (_c.sent());
|
|
977
|
-
_c.label = 4;
|
|
978
|
-
case 4:
|
|
979
|
-
activeSetting = _a;
|
|
980
|
-
if (activeSetting && typeof activeSetting.enable_auto_fix === 'boolean') {
|
|
981
|
-
enabled = !!activeSetting.enable_auto_fix;
|
|
982
|
-
}
|
|
983
|
-
_c.label = 5;
|
|
984
|
-
case 5: return [3 /*break*/, 7];
|
|
985
|
-
case 6:
|
|
986
|
-
error_1 = _c.sent();
|
|
987
|
-
if ((_b = this.config) === null || _b === void 0 ? void 0 : _b.debugLogging) {
|
|
988
|
-
console.warn('ErrorAutoFixManager failed to read app settings auto-fix toggle', error_1);
|
|
989
|
-
}
|
|
990
|
-
return [3 /*break*/, 7];
|
|
991
|
-
case 7:
|
|
992
|
-
this.appSettingsAutoOptimizeCacheValue = enabled;
|
|
993
|
-
this.appSettingsAutoOptimizeCacheExpiresAt = now + ErrorAutoFixManager.APP_SETTINGS_CACHE_TTL_MS;
|
|
994
|
-
return [2 /*return*/, enabled];
|
|
995
|
-
}
|
|
996
|
-
});
|
|
997
|
-
});
|
|
998
|
-
};
|
|
999
|
-
ErrorAutoFixManager.prototype.reserveLog = function (email_1, client_1) {
|
|
1000
|
-
return __awaiter(this, arguments, void 0, function (email, client, autoOptimizeEnabled) {
|
|
1001
|
-
var hash, rawHash, now, existing, updatedExisting, metaUpdate, reactivated, attemptsUsed, maxAttempts, reason, exhausted, resumed, counterValue, counterString, doc;
|
|
1002
|
-
if (autoOptimizeEnabled === void 0) { autoOptimizeEnabled = false; }
|
|
1003
|
-
return __generator(this, function (_a) {
|
|
1004
|
-
switch (_a.label) {
|
|
1005
|
-
case 0:
|
|
1006
|
-
hash = email.hash;
|
|
1007
|
-
rawHash = email.rawHash || hash;
|
|
1008
|
-
now = email.reportedAt || new Date();
|
|
1009
|
-
existing = null;
|
|
1010
|
-
if (!hash) return [3 /*break*/, 2];
|
|
1011
|
-
return [4 /*yield*/, ErrorAutoFixLogs.findOne({ issue_hash: hash })];
|
|
1012
|
-
case 1:
|
|
1013
|
-
existing = _a.sent();
|
|
1014
|
-
_a.label = 2;
|
|
1015
|
-
case 2:
|
|
1016
|
-
if (!(!existing && rawHash)) return [3 /*break*/, 4];
|
|
1017
|
-
return [4 /*yield*/, ErrorAutoFixLogs.findOne({ email_hash: rawHash })];
|
|
1018
|
-
case 3:
|
|
1019
|
-
existing = _a.sent();
|
|
1020
|
-
_a.label = 4;
|
|
1021
|
-
case 4:
|
|
1022
|
-
if (!(!existing && hash && hash !== rawHash)) return [3 /*break*/, 6];
|
|
1023
|
-
return [4 /*yield*/, ErrorAutoFixLogs.findOne({ email_hash: hash })];
|
|
1024
|
-
case 5:
|
|
1025
|
-
existing = _a.sent();
|
|
1026
|
-
_a.label = 6;
|
|
1027
|
-
case 6:
|
|
1028
|
-
if (!existing) return [3 /*break*/, 18];
|
|
1029
|
-
return [4 /*yield*/, this.markDuplicate(existing._id, now)];
|
|
1030
|
-
case 7:
|
|
1031
|
-
_a.sent();
|
|
1032
|
-
return [4 /*yield*/, ErrorAutoFixLogs.findOne({ _id: existing._id })];
|
|
1033
|
-
case 8:
|
|
1034
|
-
updatedExisting = (_a.sent()) || existing;
|
|
1035
|
-
metaUpdate = {};
|
|
1036
|
-
if (hash && (!updatedExisting.issue_hash || updatedExisting.issue_hash !== hash)) {
|
|
1037
|
-
metaUpdate.issue_hash = hash;
|
|
1038
|
-
}
|
|
1039
|
-
if (rawHash && (!updatedExisting.email_hash || updatedExisting.email_hash !== rawHash)) {
|
|
1040
|
-
metaUpdate.email_hash = rawHash;
|
|
1041
|
-
}
|
|
1042
|
-
if (email.fromAddress && email.fromAddress !== updatedExisting.from_email) {
|
|
1043
|
-
metaUpdate.from_email = email.fromAddress;
|
|
1044
|
-
}
|
|
1045
|
-
if (client) {
|
|
1046
|
-
if (!updatedExisting.id_client || updatedExisting.id_client !== client._id) {
|
|
1047
|
-
metaUpdate.id_client = client._id;
|
|
1048
|
-
}
|
|
1049
|
-
if (!updatedExisting.client_name || updatedExisting.client_name !== client.name) {
|
|
1050
|
-
metaUpdate.client_name = client.name;
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
if (email.openai_environment && email.openai_environment !== updatedExisting.openai_environment) {
|
|
1054
|
-
metaUpdate.openai_environment = email.openai_environment;
|
|
1055
|
-
}
|
|
1056
|
-
if (email.sourceApp && email.sourceApp !== updatedExisting.source_app) {
|
|
1057
|
-
metaUpdate.source_app = email.sourceApp;
|
|
1058
|
-
}
|
|
1059
|
-
if (email.sourceEnvironment && email.sourceEnvironment !== updatedExisting.source_environment) {
|
|
1060
|
-
metaUpdate.source_environment = email.sourceEnvironment;
|
|
1061
|
-
}
|
|
1062
|
-
if (email.severity && email.severity !== updatedExisting.severity) {
|
|
1063
|
-
metaUpdate.severity = email.severity;
|
|
1064
|
-
}
|
|
1065
|
-
if (email.reportedBy && email.reportedBy !== updatedExisting.reported_by) {
|
|
1066
|
-
metaUpdate.reported_by = email.reportedBy;
|
|
1067
|
-
}
|
|
1068
|
-
if (typeof email.reportMetadata !== 'undefined') {
|
|
1069
|
-
metaUpdate.report_metadata = email.reportMetadata;
|
|
1070
|
-
}
|
|
1071
|
-
if (typeof email.reportContext !== 'undefined') {
|
|
1072
|
-
metaUpdate.report_context = email.reportContext;
|
|
1073
|
-
}
|
|
1074
|
-
if (typeof email.attachments !== 'undefined') {
|
|
1075
|
-
metaUpdate.attachments = email.attachments;
|
|
1076
|
-
}
|
|
1077
|
-
metaUpdate.last_reported_at = now;
|
|
1078
|
-
if (!Object.keys(metaUpdate).length) return [3 /*break*/, 10];
|
|
1079
|
-
return [4 /*yield*/, this.updateLog(updatedExisting._id, metaUpdate)];
|
|
1080
|
-
case 9:
|
|
1081
|
-
_a.sent();
|
|
1082
|
-
_a.label = 10;
|
|
1083
|
-
case 10:
|
|
1084
|
-
if (!(updatedExisting.status === 'completed')) return [3 /*break*/, 12];
|
|
1085
|
-
return [4 /*yield*/, ErrorAutoFixLogs.findOneAndUpdate({ _id: updatedExisting._id }, {
|
|
1086
|
-
$set: {
|
|
1087
|
-
status: 'pending',
|
|
1088
|
-
ignored: false,
|
|
1089
|
-
last_error: '',
|
|
1090
|
-
openai_task_id: '',
|
|
1091
|
-
branch_name: '',
|
|
1092
|
-
pr_url: ''
|
|
1093
|
-
}
|
|
1094
|
-
}, {
|
|
1095
|
-
returnDocument: 'after'
|
|
1096
|
-
})];
|
|
1097
|
-
case 11:
|
|
1098
|
-
reactivated = (_a.sent()) || updatedExisting;
|
|
1099
|
-
return [2 /*return*/, {
|
|
1100
|
-
proceed: true,
|
|
1101
|
-
log: reactivated
|
|
1102
|
-
}];
|
|
1103
|
-
case 12:
|
|
1104
|
-
if (updatedExisting.ignored) {
|
|
1105
|
-
return [2 /*return*/, {
|
|
1106
|
-
proceed: false,
|
|
1107
|
-
log: updatedExisting,
|
|
1108
|
-
reason: 'ignored'
|
|
1109
|
-
}];
|
|
1110
|
-
}
|
|
1111
|
-
if (!(autoOptimizeEnabled && (updatedExisting.status === 'failed' || updatedExisting.status === 'skipped') && !updatedExisting.ignored)) return [3 /*break*/, 17];
|
|
1112
|
-
attemptsUsed = Number.isFinite(Number(updatedExisting.attempt_count))
|
|
1113
|
-
? Number(updatedExisting.attempt_count)
|
|
1114
|
-
: 0;
|
|
1115
|
-
maxAttempts = Number.isFinite(Number(this.config.maxAutoRunAttemptsPerIssue))
|
|
1116
|
-
? Number(this.config.maxAutoRunAttemptsPerIssue)
|
|
1117
|
-
: 0;
|
|
1118
|
-
if (!(maxAttempts > 0 && attemptsUsed >= maxAttempts)) return [3 /*break*/, 15];
|
|
1119
|
-
reason = "Auto-fix attempt budget reached (".concat(attemptsUsed, "/").concat(maxAttempts, ").");
|
|
1120
|
-
return [4 /*yield*/, ErrorAutoFixLogs.findOneAndUpdate({ _id: updatedExisting._id }, {
|
|
1121
|
-
$set: {
|
|
1122
|
-
status: 'skipped',
|
|
1123
|
-
ignored: true,
|
|
1124
|
-
last_error: "".concat(reason, " Marked ignored pending manual intervention."),
|
|
1125
|
-
last_result_at: now,
|
|
1126
|
-
updatedAt: now
|
|
1127
|
-
}
|
|
1128
|
-
}, {
|
|
1129
|
-
returnDocument: 'after'
|
|
1130
|
-
})];
|
|
1131
|
-
case 13:
|
|
1132
|
-
exhausted = (_a.sent()) || updatedExisting;
|
|
1133
|
-
return [4 /*yield*/, this.sendEscalationNotice(exhausted, reason)];
|
|
1134
|
-
case 14:
|
|
1135
|
-
_a.sent();
|
|
1136
|
-
return [2 /*return*/, {
|
|
1137
|
-
proceed: false,
|
|
1138
|
-
log: exhausted,
|
|
1139
|
-
reason: 'budget_exhausted'
|
|
1140
|
-
}];
|
|
1141
|
-
case 15: return [4 /*yield*/, ErrorAutoFixLogs.findOneAndUpdate({ _id: updatedExisting._id }, {
|
|
1142
|
-
$inc: {
|
|
1143
|
-
attempt_count: 1
|
|
1144
|
-
},
|
|
1145
|
-
$set: {
|
|
1146
|
-
status: 'in_progress',
|
|
1147
|
-
last_attempt_at: now,
|
|
1148
|
-
openai_task_id: '',
|
|
1149
|
-
branch_name: '',
|
|
1150
|
-
pr_url: '',
|
|
1151
|
-
last_error: ''
|
|
1152
|
-
}
|
|
1153
|
-
}, {
|
|
1154
|
-
returnDocument: 'after'
|
|
1155
|
-
})];
|
|
1156
|
-
case 16:
|
|
1157
|
-
resumed = _a.sent();
|
|
1158
|
-
return [2 /*return*/, {
|
|
1159
|
-
proceed: true,
|
|
1160
|
-
log: resumed || updatedExisting
|
|
1161
|
-
}];
|
|
1162
|
-
case 17:
|
|
1163
|
-
if (updatedExisting.status === 'in_progress') {
|
|
1164
|
-
return [2 /*return*/, {
|
|
1165
|
-
proceed: false,
|
|
1166
|
-
log: updatedExisting,
|
|
1167
|
-
reason: 'in_progress'
|
|
1168
|
-
}];
|
|
1169
|
-
}
|
|
1170
|
-
if (updatedExisting.status === 'success') {
|
|
1171
|
-
return [2 /*return*/, {
|
|
1172
|
-
proceed: false,
|
|
1173
|
-
log: updatedExisting,
|
|
1174
|
-
reason: 'success'
|
|
1175
|
-
}];
|
|
1176
|
-
}
|
|
1177
|
-
return [2 /*return*/, {
|
|
1178
|
-
proceed: false,
|
|
1179
|
-
log: updatedExisting,
|
|
1180
|
-
reason: 'duplicate'
|
|
1181
|
-
}];
|
|
1182
|
-
case 18: return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethod('incCounter', 'autofix_error')];
|
|
1183
|
-
case 19:
|
|
1184
|
-
counterValue = _a.sent();
|
|
1185
|
-
counterString = (0, common_1.pad)(counterValue, 6);
|
|
1186
|
-
doc = {
|
|
1187
|
-
_id: (0, common_1.objectIdHexString)(),
|
|
1188
|
-
email_hash: rawHash,
|
|
1189
|
-
issue_hash: hash,
|
|
1190
|
-
subject: email.subject,
|
|
1191
|
-
message_id: email.messageId,
|
|
1192
|
-
body: email.body,
|
|
1193
|
-
status: autoOptimizeEnabled ? 'in_progress' : 'pending',
|
|
1194
|
-
ignored: false,
|
|
1195
|
-
attempt_count: autoOptimizeEnabled ? 1 : 0,
|
|
1196
|
-
duplicate_count: 0,
|
|
1197
|
-
autofix_error_count: counterValue,
|
|
1198
|
-
autofix_error_count_string: counterString,
|
|
1199
|
-
first_seen_at: now,
|
|
1200
|
-
last_attempt_at: autoOptimizeEnabled ? now : undefined,
|
|
1201
|
-
from_email: email.fromAddress || '',
|
|
1202
|
-
id_client: client === null || client === void 0 ? void 0 : client._id,
|
|
1203
|
-
client_name: client === null || client === void 0 ? void 0 : client.name,
|
|
1204
|
-
openai_environment: email.openai_environment || this.determineOpenAIEnvironment(client),
|
|
1205
|
-
source_app: email.sourceApp,
|
|
1206
|
-
source_environment: email.sourceEnvironment,
|
|
1207
|
-
severity: email.severity,
|
|
1208
|
-
reported_by: email.reportedBy || email.fromAddress || '',
|
|
1209
|
-
last_reported_at: now,
|
|
1210
|
-
report_metadata: email.reportMetadata,
|
|
1211
|
-
report_context: email.reportContext,
|
|
1212
|
-
attachments: email.attachments
|
|
1213
|
-
};
|
|
1214
|
-
return [4 /*yield*/, ErrorAutoFixLogs.insertOne(doc)];
|
|
1215
|
-
case 20:
|
|
1216
|
-
_a.sent();
|
|
1217
|
-
return [2 /*return*/, {
|
|
1218
|
-
proceed: true,
|
|
1219
|
-
log: doc
|
|
1220
|
-
}];
|
|
1221
|
-
}
|
|
1222
|
-
});
|
|
1223
|
-
});
|
|
1224
|
-
};
|
|
1225
|
-
ErrorAutoFixManager.prototype.markDuplicate = function (logId, timestamp) {
|
|
1226
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1227
|
-
return __generator(this, function (_a) {
|
|
1228
|
-
switch (_a.label) {
|
|
1229
|
-
case 0: return [4 /*yield*/, ErrorAutoFixLogs.updateOne({ _id: logId }, {
|
|
1230
|
-
$inc: {
|
|
1231
|
-
duplicate_count: 1
|
|
1232
|
-
},
|
|
1233
|
-
$set: {
|
|
1234
|
-
last_duplicate_at: timestamp,
|
|
1235
|
-
last_reported_at: timestamp,
|
|
1236
|
-
updatedAt: timestamp
|
|
1237
|
-
}
|
|
1238
|
-
})];
|
|
1239
|
-
case 1:
|
|
1240
|
-
_a.sent();
|
|
1241
|
-
return [2 /*return*/];
|
|
1242
|
-
}
|
|
1243
|
-
});
|
|
1244
|
-
});
|
|
1245
|
-
};
|
|
1246
|
-
ErrorAutoFixManager.prototype.updateLog = function (logId, set, inc) {
|
|
1247
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1248
|
-
var cleanedSet, rawSet, update, result;
|
|
1249
|
-
return __generator(this, function (_a) {
|
|
1250
|
-
switch (_a.label) {
|
|
1251
|
-
case 0:
|
|
1252
|
-
cleanedSet = {};
|
|
1253
|
-
rawSet = set ? __assign({}, set) : {};
|
|
1254
|
-
Object.keys(rawSet).forEach(function (key) {
|
|
1255
|
-
if (typeof rawSet[key] !== 'undefined') {
|
|
1256
|
-
cleanedSet[key] = rawSet[key];
|
|
1257
|
-
}
|
|
1258
|
-
});
|
|
1259
|
-
cleanedSet.updatedAt = new Date();
|
|
1260
|
-
update = {
|
|
1261
|
-
$set: cleanedSet
|
|
1262
|
-
};
|
|
1263
|
-
if (inc) {
|
|
1264
|
-
update.$inc = inc;
|
|
1265
|
-
}
|
|
1266
|
-
return [4 /*yield*/, ErrorAutoFixLogs.findOneAndUpdate({ _id: logId }, update, {
|
|
1267
|
-
returnDocument: 'after'
|
|
1268
|
-
})];
|
|
1269
|
-
case 1:
|
|
1270
|
-
result = _a.sent();
|
|
1271
|
-
return [2 /*return*/, result];
|
|
1272
|
-
}
|
|
1273
|
-
});
|
|
1274
|
-
});
|
|
1275
|
-
};
|
|
1276
|
-
ErrorAutoFixManager.prototype.getEscalationRecipients = function () {
|
|
1277
|
-
var unique = new Set();
|
|
1278
|
-
var add = function (value) {
|
|
1279
|
-
var normalized = String(value || '').trim().toLowerCase();
|
|
1280
|
-
if (!normalized) {
|
|
1281
|
-
return;
|
|
1282
|
-
}
|
|
1283
|
-
unique.add(normalized);
|
|
1284
|
-
};
|
|
1285
|
-
(this.config.escalationEmails || []).forEach(add);
|
|
1286
|
-
(this.config.notifyEmails || []).forEach(add);
|
|
1287
|
-
if (!unique.size) {
|
|
1288
|
-
add(DEFAULT_ERROR_ALERT_EMAIL);
|
|
1289
|
-
}
|
|
1290
|
-
return Array.from(unique);
|
|
1291
|
-
};
|
|
1292
|
-
ErrorAutoFixManager.prototype.sendEscalationNotice = function (log, reason) {
|
|
1293
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1294
|
-
var recipients, identifier, subject, body, methodManager, recipients_1, recipients_1_1, recipient, error_2, e_1_1;
|
|
1295
|
-
var e_1, _a;
|
|
1296
|
-
return __generator(this, function (_b) {
|
|
1297
|
-
switch (_b.label) {
|
|
1298
|
-
case 0:
|
|
1299
|
-
recipients = this.getEscalationRecipients();
|
|
1300
|
-
if (!recipients.length || !(log === null || log === void 0 ? void 0 : log._id)) {
|
|
1301
|
-
return [2 /*return*/];
|
|
1302
|
-
}
|
|
1303
|
-
identifier = log.autofix_error_count_string || log._id;
|
|
1304
|
-
subject = "ResolveIO AutoFix Escalation: ".concat(identifier);
|
|
1305
|
-
body = [
|
|
1306
|
-
'Auto-fix retry budget was exhausted for this recurring issue and further autonomous attempts were stopped.',
|
|
1307
|
-
'',
|
|
1308
|
-
"Reason: ".concat(reason),
|
|
1309
|
-
"Issue Log ID: ".concat(log._id),
|
|
1310
|
-
"Issue Counter: ".concat(log.autofix_error_count_string || 'n/a'),
|
|
1311
|
-
"Client: ".concat(log.client_name || log.id_client || 'unknown'),
|
|
1312
|
-
"Source App: ".concat(log.source_app || 'unknown'),
|
|
1313
|
-
"Environment: ".concat(log.source_environment || log.openai_environment || 'unknown'),
|
|
1314
|
-
"Attempts: ".concat(log.attempt_count || 0, "/").concat(this.config.maxAutoRunAttemptsPerIssue),
|
|
1315
|
-
"Issue Hash: ".concat(log.issue_hash || log.email_hash || 'n/a'),
|
|
1316
|
-
'',
|
|
1317
|
-
'The issue is now marked ignored for auto-fix to protect customer token usage. Manual intervention is required.'
|
|
1318
|
-
].join('\n');
|
|
1319
|
-
methodManager = resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager();
|
|
1320
|
-
_b.label = 1;
|
|
1321
|
-
case 1:
|
|
1322
|
-
_b.trys.push([1, 8, 9, 10]);
|
|
1323
|
-
recipients_1 = __values(recipients), recipients_1_1 = recipients_1.next();
|
|
1324
|
-
_b.label = 2;
|
|
1325
|
-
case 2:
|
|
1326
|
-
if (!!recipients_1_1.done) return [3 /*break*/, 7];
|
|
1327
|
-
recipient = recipients_1_1.value;
|
|
1328
|
-
_b.label = 3;
|
|
1329
|
-
case 3:
|
|
1330
|
-
_b.trys.push([3, 5, , 6]);
|
|
1331
|
-
return [4 /*yield*/, methodManager.sendEmail(recipient, subject, body)];
|
|
1332
|
-
case 4:
|
|
1333
|
-
_b.sent();
|
|
1334
|
-
return [3 /*break*/, 6];
|
|
1335
|
-
case 5:
|
|
1336
|
-
error_2 = _b.sent();
|
|
1337
|
-
console.error('Failed sending auto-fix escalation email', { recipient: recipient, logId: log._id, error: error_2 });
|
|
1338
|
-
return [3 /*break*/, 6];
|
|
1339
|
-
case 6:
|
|
1340
|
-
recipients_1_1 = recipients_1.next();
|
|
1341
|
-
return [3 /*break*/, 2];
|
|
1342
|
-
case 7: return [3 /*break*/, 10];
|
|
1343
|
-
case 8:
|
|
1344
|
-
e_1_1 = _b.sent();
|
|
1345
|
-
e_1 = { error: e_1_1 };
|
|
1346
|
-
return [3 /*break*/, 10];
|
|
1347
|
-
case 9:
|
|
1348
|
-
try {
|
|
1349
|
-
if (recipients_1_1 && !recipients_1_1.done && (_a = recipients_1.return)) _a.call(recipients_1);
|
|
1350
|
-
}
|
|
1351
|
-
finally { if (e_1) throw e_1.error; }
|
|
1352
|
-
return [7 /*endfinally*/];
|
|
1353
|
-
case 10: return [2 /*return*/];
|
|
1354
|
-
}
|
|
1355
|
-
});
|
|
1356
|
-
});
|
|
1357
|
-
};
|
|
1358
|
-
ErrorAutoFixManager.prototype.collectLibraryIssueSignalText = function (email, log) {
|
|
1359
|
-
var attachments = Array.isArray(log === null || log === void 0 ? void 0 : log.attachments) ? log.attachments : [];
|
|
1360
|
-
var attachmentSignals = attachments.map(function (attachment) {
|
|
1361
|
-
return [
|
|
1362
|
-
(attachment === null || attachment === void 0 ? void 0 : attachment.name) || '',
|
|
1363
|
-
(attachment === null || attachment === void 0 ? void 0 : attachment.url) || '',
|
|
1364
|
-
(attachment === null || attachment === void 0 ? void 0 : attachment.contentType) || ''
|
|
1365
|
-
].filter(Boolean).join(' ');
|
|
1366
|
-
});
|
|
1367
|
-
var metadata = (log === null || log === void 0 ? void 0 : log.report_metadata) && Object.keys(log.report_metadata).length
|
|
1368
|
-
? JSON.stringify(log.report_metadata)
|
|
1369
|
-
: '';
|
|
1370
|
-
var context = (log === null || log === void 0 ? void 0 : log.report_context) && Object.keys(log.report_context).length
|
|
1371
|
-
? JSON.stringify(log.report_context)
|
|
1372
|
-
: '';
|
|
1373
|
-
return [
|
|
1374
|
-
(email === null || email === void 0 ? void 0 : email.subject) || '',
|
|
1375
|
-
(email === null || email === void 0 ? void 0 : email.body) || '',
|
|
1376
|
-
(log === null || log === void 0 ? void 0 : log.body) || '',
|
|
1377
|
-
metadata,
|
|
1378
|
-
context,
|
|
1379
|
-
attachmentSignals.join('\n')
|
|
1380
|
-
].filter(Boolean).join('\n');
|
|
1381
|
-
};
|
|
1382
|
-
ErrorAutoFixManager.prototype.evaluateLibraryIssueGate = function (email, log) {
|
|
1383
|
-
var e_2, _a;
|
|
1384
|
-
var signalText = this.collectLibraryIssueSignalText(email, log);
|
|
1385
|
-
if (!signalText) {
|
|
1386
|
-
return { blocked: false, evidence: [] };
|
|
1387
|
-
}
|
|
1388
|
-
var evidence = [];
|
|
1389
|
-
var markerHits = 0;
|
|
1390
|
-
try {
|
|
1391
|
-
for (var LIBRARY_MARKER_PATTERNS_1 = __values(LIBRARY_MARKER_PATTERNS), LIBRARY_MARKER_PATTERNS_1_1 = LIBRARY_MARKER_PATTERNS_1.next(); !LIBRARY_MARKER_PATTERNS_1_1.done; LIBRARY_MARKER_PATTERNS_1_1 = LIBRARY_MARKER_PATTERNS_1.next()) {
|
|
1392
|
-
var marker = LIBRARY_MARKER_PATTERNS_1_1.value;
|
|
1393
|
-
if (!marker.pattern.test(signalText)) {
|
|
1394
|
-
continue;
|
|
1395
|
-
}
|
|
1396
|
-
markerHits += 1;
|
|
1397
|
-
evidence.push(marker.label);
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1401
|
-
finally {
|
|
1402
|
-
try {
|
|
1403
|
-
if (LIBRARY_MARKER_PATTERNS_1_1 && !LIBRARY_MARKER_PATTERNS_1_1.done && (_a = LIBRARY_MARKER_PATTERNS_1.return)) _a.call(LIBRARY_MARKER_PATTERNS_1);
|
|
1404
|
-
}
|
|
1405
|
-
finally { if (e_2) throw e_2.error; }
|
|
1406
|
-
}
|
|
1407
|
-
var rawPaths = signalText.match(FILE_PATH_PATTERN) || [];
|
|
1408
|
-
var normalizedPaths = rawPaths
|
|
1409
|
-
.map(function (value) { return String(value || '').trim(); })
|
|
1410
|
-
.filter(Boolean)
|
|
1411
|
-
.map(function (value) { return value.replace(/\\/g, '/').toLowerCase(); });
|
|
1412
|
-
var appOwnedPathCount = normalizedPaths.filter(function (value) { return APP_OWNED_PATH_PATTERN.test(value); }).length;
|
|
1413
|
-
var libraryPathCount = normalizedPaths.filter(function (value) {
|
|
1414
|
-
return value.includes('/node_modules/')
|
|
1415
|
-
|| value.includes('@resolveio/client-lib')
|
|
1416
|
-
|| value.includes('@resolveio/server-lib')
|
|
1417
|
-
|| value.includes('/resolveio-client-lib/')
|
|
1418
|
-
|| value.includes('/resolveio-server-lib/')
|
|
1419
|
-
|| value.includes('/aicoder/templates/base_');
|
|
1420
|
-
}).length;
|
|
1421
|
-
var shouldBlock = (libraryPathCount > 0 && appOwnedPathCount === 0)
|
|
1422
|
-
|| (markerHits >= 2 && appOwnedPathCount === 0)
|
|
1423
|
-
|| (markerHits >= 1 && libraryPathCount >= 2);
|
|
1424
|
-
if (!shouldBlock) {
|
|
1425
|
-
return { blocked: false, evidence: evidence };
|
|
1426
|
-
}
|
|
1427
|
-
var compactEvidence = Array.from(new Set(__spreadArray(__spreadArray(__spreadArray([], __read(evidence), false), __read((libraryPathCount ? ["library_paths=".concat(libraryPathCount)] : [])), false), __read((appOwnedPathCount ? ["app_paths=".concat(appOwnedPathCount)] : [])), false))).slice(0, 8);
|
|
1428
|
-
return {
|
|
1429
|
-
blocked: true,
|
|
1430
|
-
reason: 'Root cause appears to be in shared ResolveIO libraries/templates; app-level auto-fix was blocked.',
|
|
1431
|
-
evidence: compactEvidence
|
|
1432
|
-
};
|
|
1433
|
-
};
|
|
1434
|
-
ErrorAutoFixManager.prototype.sendLibraryIssueNotice = function (log, reason, evidence) {
|
|
1435
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1436
|
-
var recipients, identifier, subject, body, methodManager, recipients_2, recipients_2_1, recipient, error_3, e_3_1;
|
|
1437
|
-
var e_3, _a;
|
|
1438
|
-
return __generator(this, function (_b) {
|
|
1439
|
-
switch (_b.label) {
|
|
1440
|
-
case 0:
|
|
1441
|
-
recipients = this.getEscalationRecipients();
|
|
1442
|
-
if (!recipients.length || !(log === null || log === void 0 ? void 0 : log._id)) {
|
|
1443
|
-
return [2 /*return*/];
|
|
1444
|
-
}
|
|
1445
|
-
identifier = log.autofix_error_count_string || log._id;
|
|
1446
|
-
subject = "ResolveIO AutoFix Blocked (Library): ".concat(identifier);
|
|
1447
|
-
body = [
|
|
1448
|
-
'Auto-fix was blocked because the issue appears library-owned, so no autonomous patch was attempted.',
|
|
1449
|
-
'',
|
|
1450
|
-
"Reason: ".concat(reason),
|
|
1451
|
-
evidence.length ? "Evidence: ".concat(evidence.join(', ')) : '',
|
|
1452
|
-
"Issue Log ID: ".concat(log._id),
|
|
1453
|
-
"Issue Counter: ".concat(log.autofix_error_count_string || 'n/a'),
|
|
1454
|
-
"Client: ".concat(log.client_name || log.id_client || 'unknown'),
|
|
1455
|
-
"Source App: ".concat(log.source_app || 'unknown'),
|
|
1456
|
-
"Environment: ".concat(log.source_environment || log.openai_environment || 'unknown'),
|
|
1457
|
-
"Issue Hash: ".concat(log.issue_hash || log.email_hash || 'n/a'),
|
|
1458
|
-
'',
|
|
1459
|
-
'Manual library release/fix is required. App-level auto-fix remains blocked for this issue to protect credits.'
|
|
1460
|
-
].filter(Boolean).join('\n');
|
|
1461
|
-
methodManager = resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager();
|
|
1462
|
-
_b.label = 1;
|
|
1463
|
-
case 1:
|
|
1464
|
-
_b.trys.push([1, 8, 9, 10]);
|
|
1465
|
-
recipients_2 = __values(recipients), recipients_2_1 = recipients_2.next();
|
|
1466
|
-
_b.label = 2;
|
|
1467
|
-
case 2:
|
|
1468
|
-
if (!!recipients_2_1.done) return [3 /*break*/, 7];
|
|
1469
|
-
recipient = recipients_2_1.value;
|
|
1470
|
-
_b.label = 3;
|
|
1471
|
-
case 3:
|
|
1472
|
-
_b.trys.push([3, 5, , 6]);
|
|
1473
|
-
return [4 /*yield*/, methodManager.sendEmail(recipient, subject, body)];
|
|
1474
|
-
case 4:
|
|
1475
|
-
_b.sent();
|
|
1476
|
-
return [3 /*break*/, 6];
|
|
1477
|
-
case 5:
|
|
1478
|
-
error_3 = _b.sent();
|
|
1479
|
-
console.error('Failed sending library-issue auto-fix email', { recipient: recipient, logId: log._id, error: error_3 });
|
|
1480
|
-
return [3 /*break*/, 6];
|
|
1481
|
-
case 6:
|
|
1482
|
-
recipients_2_1 = recipients_2.next();
|
|
1483
|
-
return [3 /*break*/, 2];
|
|
1484
|
-
case 7: return [3 /*break*/, 10];
|
|
1485
|
-
case 8:
|
|
1486
|
-
e_3_1 = _b.sent();
|
|
1487
|
-
e_3 = { error: e_3_1 };
|
|
1488
|
-
return [3 /*break*/, 10];
|
|
1489
|
-
case 9:
|
|
1490
|
-
try {
|
|
1491
|
-
if (recipients_2_1 && !recipients_2_1.done && (_a = recipients_2.return)) _a.call(recipients_2);
|
|
1492
|
-
}
|
|
1493
|
-
finally { if (e_3) throw e_3.error; }
|
|
1494
|
-
return [7 /*endfinally*/];
|
|
1495
|
-
case 10: return [2 /*return*/];
|
|
1496
|
-
}
|
|
1497
|
-
});
|
|
1498
|
-
});
|
|
1499
|
-
};
|
|
1500
|
-
ErrorAutoFixManager.prototype.blockLibraryOwnedIssue = function (email, log, gate) {
|
|
1501
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1502
|
-
var reason, details, message, updated;
|
|
1503
|
-
return __generator(this, function (_a) {
|
|
1504
|
-
switch (_a.label) {
|
|
1505
|
-
case 0:
|
|
1506
|
-
reason = gate.reason || 'Library-owned issue detected.';
|
|
1507
|
-
details = gate.evidence.length ? "Signals: ".concat(gate.evidence.join(', ')) : '';
|
|
1508
|
-
message = [reason, details].filter(Boolean).join(' ');
|
|
1509
|
-
return [4 /*yield*/, this.updateLog(log._id, {
|
|
1510
|
-
status: 'skipped',
|
|
1511
|
-
ignored: true,
|
|
1512
|
-
last_error: message,
|
|
1513
|
-
last_result_at: new Date()
|
|
1514
|
-
})];
|
|
1515
|
-
case 1:
|
|
1516
|
-
updated = (_a.sent()) || log;
|
|
1517
|
-
return [4 /*yield*/, this.notifyCustomerWorkflowStatus('blocked_library_issue', email, updated, {
|
|
1518
|
-
error: reason,
|
|
1519
|
-
notes: details
|
|
1520
|
-
})];
|
|
1521
|
-
case 2:
|
|
1522
|
-
_a.sent();
|
|
1523
|
-
return [4 /*yield*/, this.sendLibraryIssueNotice(updated, reason, gate.evidence)];
|
|
1524
|
-
case 3:
|
|
1525
|
-
_a.sent();
|
|
1526
|
-
return [2 /*return*/, {
|
|
1527
|
-
status: 'skipped',
|
|
1528
|
-
email: email,
|
|
1529
|
-
error: message,
|
|
1530
|
-
log: updated,
|
|
1531
|
-
reason: 'library_issue_blocked',
|
|
1532
|
-
summary: updated.plan_summary || email.subject,
|
|
1533
|
-
notes: details
|
|
1534
|
-
}];
|
|
1535
|
-
}
|
|
1536
|
-
});
|
|
1537
|
-
});
|
|
1538
|
-
};
|
|
1539
|
-
ErrorAutoFixManager.prototype.shouldNotifySkip = function (reason) {
|
|
1540
|
-
return ['in_progress', 'success', 'ignored', 'duplicate', 'pending'].indexOf(reason) === -1;
|
|
1541
|
-
};
|
|
1542
|
-
ErrorAutoFixManager.prototype.isGeneratedAICoderClient = function (idClient) {
|
|
1543
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1544
|
-
var normalizedClientId, match;
|
|
1545
|
-
return __generator(this, function (_a) {
|
|
1546
|
-
switch (_a.label) {
|
|
1547
|
-
case 0:
|
|
1548
|
-
normalizedClientId = String(idClient || '').trim();
|
|
1549
|
-
if (!normalizedClientId) {
|
|
1550
|
-
return [2 /*return*/, false];
|
|
1551
|
-
}
|
|
1552
|
-
return [4 /*yield*/, AICoderApps.findOne({
|
|
1553
|
-
client_id: normalizedClientId
|
|
1554
|
-
}, {
|
|
1555
|
-
projection: {
|
|
1556
|
-
_id: 1
|
|
1557
|
-
}
|
|
1558
|
-
})];
|
|
1559
|
-
case 1:
|
|
1560
|
-
match = _a.sent();
|
|
1561
|
-
return [2 /*return*/, !!(match === null || match === void 0 ? void 0 : match._id)];
|
|
1562
|
-
}
|
|
1563
|
-
});
|
|
1564
|
-
});
|
|
1565
|
-
};
|
|
1566
|
-
ErrorAutoFixManager.prototype.buildAICoderWorkflowSummary = function (stage, email, log, extra) {
|
|
1567
|
-
return (0, customer_notification_content_manager_1.buildGeneratedAppAutoFixSummary)(stage, {
|
|
1568
|
-
source_app: String((log === null || log === void 0 ? void 0 : log.source_app) || (email === null || email === void 0 ? void 0 : email.sourceApp) || '').trim(),
|
|
1569
|
-
environment: String((log === null || log === void 0 ? void 0 : log.source_environment) || (email === null || email === void 0 ? void 0 : email.sourceEnvironment) || '').trim(),
|
|
1570
|
-
severity: String((log === null || log === void 0 ? void 0 : log.severity) || (email === null || email === void 0 ? void 0 : email.severity) || '').trim(),
|
|
1571
|
-
error: extra === null || extra === void 0 ? void 0 : extra.error
|
|
1572
|
-
}, extra);
|
|
1573
|
-
};
|
|
1574
|
-
ErrorAutoFixManager.prototype.buildResolveIOProjectWorkflowDetails = function (email, log, extra) {
|
|
1575
|
-
return (0, customer_notification_content_manager_1.buildResolveIOProjectAutoFixDetails)({
|
|
1576
|
-
client_name: (log === null || log === void 0 ? void 0 : log.client_name) || (email === null || email === void 0 ? void 0 : email.client_name) || '',
|
|
1577
|
-
issue_counter: (log === null || log === void 0 ? void 0 : log.autofix_error_count_string) || '',
|
|
1578
|
-
source_app: (log === null || log === void 0 ? void 0 : log.source_app) || (email === null || email === void 0 ? void 0 : email.sourceApp) || '',
|
|
1579
|
-
environment: (log === null || log === void 0 ? void 0 : log.source_environment) || (email === null || email === void 0 ? void 0 : email.sourceEnvironment) || (log === null || log === void 0 ? void 0 : log.openai_environment) || '',
|
|
1580
|
-
severity: (log === null || log === void 0 ? void 0 : log.severity) || (email === null || email === void 0 ? void 0 : email.severity) || '',
|
|
1581
|
-
issue_hash: (log === null || log === void 0 ? void 0 : log.issue_hash) || (email === null || email === void 0 ? void 0 : email.issueHash) || (log === null || log === void 0 ? void 0 : log.email_hash) || '',
|
|
1582
|
-
log_id: (log === null || log === void 0 ? void 0 : log._id) || '',
|
|
1583
|
-
notes: extra === null || extra === void 0 ? void 0 : extra.notes,
|
|
1584
|
-
error: extra === null || extra === void 0 ? void 0 : extra.error
|
|
1585
|
-
});
|
|
1586
|
-
};
|
|
1587
|
-
ErrorAutoFixManager.prototype.buildLocalInternalUserCriteria = function () {
|
|
1588
|
-
return {
|
|
1589
|
-
$and: [
|
|
1590
|
-
{
|
|
1591
|
-
is_customer: {
|
|
1592
|
-
$ne: true
|
|
1593
|
-
}
|
|
1594
|
-
},
|
|
1595
|
-
{
|
|
1596
|
-
$nor: [
|
|
1597
|
-
{
|
|
1598
|
-
'other.id_customer': {
|
|
1599
|
-
$exists: true,
|
|
1600
|
-
$nin: ['', null]
|
|
1601
|
-
}
|
|
1602
|
-
},
|
|
1603
|
-
{
|
|
1604
|
-
id_customer: {
|
|
1605
|
-
$exists: true,
|
|
1606
|
-
$nin: ['', null]
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
]
|
|
1610
|
-
}
|
|
1611
|
-
]
|
|
1612
|
-
};
|
|
1613
|
-
};
|
|
1614
|
-
ErrorAutoFixManager.prototype.buildLocalAdminUserCriteria = function () {
|
|
1615
|
-
return {
|
|
1616
|
-
$or: [
|
|
1617
|
-
{
|
|
1618
|
-
'roles.super_admin': true
|
|
1619
|
-
},
|
|
1620
|
-
{
|
|
1621
|
-
'roles.groups.name': {
|
|
1622
|
-
$regex: 'admin',
|
|
1623
|
-
$options: 'i'
|
|
1624
|
-
}
|
|
1625
|
-
},
|
|
1626
|
-
{
|
|
1627
|
-
'roles.groups.views': {
|
|
1628
|
-
$regex: '^/manage'
|
|
1629
|
-
}
|
|
1630
|
-
},
|
|
1631
|
-
{
|
|
1632
|
-
'roles.groups.views': '/manage'
|
|
1633
|
-
}
|
|
1634
|
-
]
|
|
1635
|
-
};
|
|
1636
|
-
};
|
|
1637
|
-
ErrorAutoFixManager.prototype.resolveLocalNotificationUserIds = function (isGeneratedApp) {
|
|
1638
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1639
|
-
var andClauses, users, unique, users_1, users_1_1, user, idUser;
|
|
1640
|
-
var e_4, _a;
|
|
1641
|
-
return __generator(this, function (_b) {
|
|
1642
|
-
switch (_b.label) {
|
|
1643
|
-
case 0:
|
|
1644
|
-
andClauses = [
|
|
1645
|
-
{
|
|
1646
|
-
active: true
|
|
1647
|
-
},
|
|
1648
|
-
{
|
|
1649
|
-
username: {
|
|
1650
|
-
$exists: true
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
];
|
|
1654
|
-
if (isGeneratedApp) {
|
|
1655
|
-
andClauses.push(this.buildLocalInternalUserCriteria());
|
|
1656
|
-
}
|
|
1657
|
-
else {
|
|
1658
|
-
andClauses.push(this.buildLocalAdminUserCriteria());
|
|
1659
|
-
}
|
|
1660
|
-
return [4 /*yield*/, user_collection_1.Users.find({
|
|
1661
|
-
$and: andClauses
|
|
1662
|
-
}, {
|
|
1663
|
-
projection: {
|
|
1664
|
-
_id: 1
|
|
1665
|
-
},
|
|
1666
|
-
limit: MAX_LOCAL_NOTIFICATION_USERS
|
|
1667
|
-
})];
|
|
1668
|
-
case 1:
|
|
1669
|
-
users = _b.sent();
|
|
1670
|
-
if (!Array.isArray(users) || !users.length) {
|
|
1671
|
-
return [2 /*return*/, []];
|
|
1672
|
-
}
|
|
1673
|
-
unique = new Set();
|
|
1674
|
-
try {
|
|
1675
|
-
for (users_1 = __values(users), users_1_1 = users_1.next(); !users_1_1.done; users_1_1 = users_1.next()) {
|
|
1676
|
-
user = users_1_1.value;
|
|
1677
|
-
idUser = String((user === null || user === void 0 ? void 0 : user._id) || '').trim();
|
|
1678
|
-
if (idUser) {
|
|
1679
|
-
unique.add(idUser);
|
|
1680
|
-
}
|
|
1681
|
-
if (unique.size >= MAX_LOCAL_NOTIFICATION_USERS) {
|
|
1682
|
-
break;
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1687
|
-
finally {
|
|
1688
|
-
try {
|
|
1689
|
-
if (users_1_1 && !users_1_1.done && (_a = users_1.return)) _a.call(users_1);
|
|
1690
|
-
}
|
|
1691
|
-
finally { if (e_4) throw e_4.error; }
|
|
1692
|
-
}
|
|
1693
|
-
return [2 /*return*/, Array.from(unique)];
|
|
1694
|
-
}
|
|
1695
|
-
});
|
|
1696
|
-
});
|
|
1697
|
-
};
|
|
1698
|
-
ErrorAutoFixManager.prototype.notifyCustomerWorkflowStatus = function (stage, email, log, extra) {
|
|
1699
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1700
|
-
var idClient, isGeneratedApp, resolvedEnvironment, app, issueKey, clientName, targetPayload, idUsers, basePayload, payload, error_4;
|
|
1701
|
-
return __generator(this, function (_a) {
|
|
1702
|
-
switch (_a.label) {
|
|
1703
|
-
case 0:
|
|
1704
|
-
idClient = String((log === null || log === void 0 ? void 0 : log.id_client) || (email === null || email === void 0 ? void 0 : email.id_client) || '').trim();
|
|
1705
|
-
isGeneratedApp = false;
|
|
1706
|
-
if (!idClient) return [3 /*break*/, 2];
|
|
1707
|
-
return [4 /*yield*/, this.isGeneratedAICoderClient(idClient)];
|
|
1708
|
-
case 1:
|
|
1709
|
-
isGeneratedApp = _a.sent();
|
|
1710
|
-
return [3 /*break*/, 4];
|
|
1711
|
-
case 2:
|
|
1712
|
-
resolvedEnvironment = this.resolveEnvironmentForTask(email, log);
|
|
1713
|
-
return [4 /*yield*/, this.resolveAutoFixApp(email, log, resolvedEnvironment)];
|
|
1714
|
-
case 3:
|
|
1715
|
-
app = _a.sent();
|
|
1716
|
-
isGeneratedApp = !!app;
|
|
1717
|
-
_a.label = 4;
|
|
1718
|
-
case 4:
|
|
1719
|
-
if (!isGeneratedApp && stage !== 'completed_success') {
|
|
1720
|
-
return [2 /*return*/];
|
|
1721
|
-
}
|
|
1722
|
-
issueKey = String((log === null || log === void 0 ? void 0 : log.issue_hash) || (log === null || log === void 0 ? void 0 : log.email_hash) || (email === null || email === void 0 ? void 0 : email.issueHash) || (email === null || email === void 0 ? void 0 : email.hash) || (log === null || log === void 0 ? void 0 : log._id) || '').trim();
|
|
1723
|
-
clientName = String((log === null || log === void 0 ? void 0 : log.client_name) || (email === null || email === void 0 ? void 0 : email.client_name) || '').trim();
|
|
1724
|
-
targetPayload = {};
|
|
1725
|
-
if (!idClient) return [3 /*break*/, 5];
|
|
1726
|
-
targetPayload.target_type = isGeneratedApp ? 'client_internal' : 'client_admins';
|
|
1727
|
-
targetPayload.id_client = idClient;
|
|
1728
|
-
targetPayload.client_name = clientName || undefined;
|
|
1729
|
-
return [3 /*break*/, 7];
|
|
1730
|
-
case 5: return [4 /*yield*/, this.resolveLocalNotificationUserIds(isGeneratedApp)];
|
|
1731
|
-
case 6:
|
|
1732
|
-
idUsers = _a.sent();
|
|
1733
|
-
if (!idUsers.length) {
|
|
1734
|
-
return [2 /*return*/];
|
|
1735
|
-
}
|
|
1736
|
-
targetPayload.target_type = 'users';
|
|
1737
|
-
targetPayload.id_users = idUsers;
|
|
1738
|
-
targetPayload.client_name = clientName || undefined;
|
|
1739
|
-
_a.label = 7;
|
|
1740
|
-
case 7:
|
|
1741
|
-
basePayload = __assign(__assign({}, targetPayload), { category: 'autofix', source: 'error-auto-fix', source_id: String((log === null || log === void 0 ? void 0 : log._id) || '').trim() || undefined, dedupe_key: issueKey ? "autofix:".concat(issueKey, ":").concat(stage) : "autofix:".concat(String((log === null || log === void 0 ? void 0 : log._id) || '').trim(), ":").concat(stage), metadata: {
|
|
1742
|
-
issue_hash: (log === null || log === void 0 ? void 0 : log.issue_hash) || (email === null || email === void 0 ? void 0 : email.issueHash) || '',
|
|
1743
|
-
log_id: (log === null || log === void 0 ? void 0 : log._id) || '',
|
|
1744
|
-
severity: (log === null || log === void 0 ? void 0 : log.severity) || (email === null || email === void 0 ? void 0 : email.severity) || '',
|
|
1745
|
-
source_app: (log === null || log === void 0 ? void 0 : log.source_app) || (email === null || email === void 0 ? void 0 : email.sourceApp) || '',
|
|
1746
|
-
source_environment: (log === null || log === void 0 ? void 0 : log.source_environment) || (email === null || email === void 0 ? void 0 : email.sourceEnvironment) || '',
|
|
1747
|
-
error: (extra === null || extra === void 0 ? void 0 : extra.error) || '',
|
|
1748
|
-
notes: (extra === null || extra === void 0 ? void 0 : extra.notes) || ''
|
|
1749
|
-
} });
|
|
1750
|
-
payload = {};
|
|
1751
|
-
if (isGeneratedApp) {
|
|
1752
|
-
if (stage === 'detected_autofix_enabled') {
|
|
1753
|
-
payload = {
|
|
1754
|
-
title: 'Issue detected. Auto-fix is in progress.',
|
|
1755
|
-
message: 'We detected an issue in your app and started an automatic fix workflow. We will notify you when it is complete.',
|
|
1756
|
-
severity: 'info',
|
|
1757
|
-
details: this.buildAICoderWorkflowSummary(stage, email, log, extra)
|
|
1758
|
-
};
|
|
1759
|
-
}
|
|
1760
|
-
else if (stage === 'detected_autofix_disabled') {
|
|
1761
|
-
payload = {
|
|
1762
|
-
title: 'Issue detected. Auto-fix is disabled.',
|
|
1763
|
-
message: 'We detected an issue, but automatic fixing is not enabled. Please ask the AI assistant to investigate this issue.',
|
|
1764
|
-
severity: 'warning',
|
|
1765
|
-
details: this.buildAICoderWorkflowSummary(stage, email, log, extra)
|
|
1766
|
-
};
|
|
1767
|
-
}
|
|
1768
|
-
else if (stage === 'completed_success') {
|
|
1769
|
-
payload = {
|
|
1770
|
-
title: 'Auto-fix completed successfully.',
|
|
1771
|
-
message: 'Your issue was fixed automatically and the update was published.',
|
|
1772
|
-
severity: 'success',
|
|
1773
|
-
details: this.buildAICoderWorkflowSummary(stage, email, log, extra)
|
|
1774
|
-
};
|
|
1775
|
-
}
|
|
1776
|
-
else if (stage === 'blocked_library_issue') {
|
|
1777
|
-
payload = {
|
|
1778
|
-
title: 'Issue requires a platform library update.',
|
|
1779
|
-
message: 'We detected this issue in shared platform libraries, so app auto-fix was stopped. Our engineering team has been notified to ship a library-level fix.',
|
|
1780
|
-
severity: 'warning',
|
|
1781
|
-
details: this.buildAICoderWorkflowSummary(stage, email, log, extra)
|
|
1782
|
-
};
|
|
1783
|
-
}
|
|
1784
|
-
else {
|
|
1785
|
-
payload = {
|
|
1786
|
-
title: 'Auto-fix needs manual review.',
|
|
1787
|
-
message: 'We could not complete an automatic fix for this issue. Manual follow-up is required.',
|
|
1788
|
-
severity: 'warning',
|
|
1789
|
-
details: this.buildAICoderWorkflowSummary(stage, email, log, extra)
|
|
1790
|
-
};
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
else {
|
|
1794
|
-
payload = {
|
|
1795
|
-
title: 'ResolveIO project auto-fix completed',
|
|
1796
|
-
message: "A fix for ".concat(String((log === null || log === void 0 ? void 0 : log.source_app) || (email === null || email === void 0 ? void 0 : email.sourceApp) || 'the project').trim(), " completed successfully."),
|
|
1797
|
-
severity: 'success',
|
|
1798
|
-
details: this.buildResolveIOProjectWorkflowDetails(email, log, extra)
|
|
1799
|
-
};
|
|
1800
|
-
}
|
|
1801
|
-
_a.label = 8;
|
|
1802
|
-
case 8:
|
|
1803
|
-
_a.trys.push([8, 10, , 11]);
|
|
1804
|
-
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethod('createCustomerNotification', __assign(__assign({}, basePayload), payload))];
|
|
1805
|
-
case 9:
|
|
1806
|
-
_a.sent();
|
|
1807
|
-
return [3 /*break*/, 11];
|
|
1808
|
-
case 10:
|
|
1809
|
-
error_4 = _a.sent();
|
|
1810
|
-
this.debugLog('Failed to create customer auto-fix notification', {
|
|
1811
|
-
logId: log === null || log === void 0 ? void 0 : log._id,
|
|
1812
|
-
stage: stage,
|
|
1813
|
-
error: (error_4 === null || error_4 === void 0 ? void 0 : error_4.message) || error_4
|
|
1814
|
-
});
|
|
1815
|
-
return [3 /*break*/, 11];
|
|
1816
|
-
case 11: return [2 /*return*/];
|
|
1817
|
-
}
|
|
1818
|
-
});
|
|
1819
|
-
});
|
|
1820
|
-
};
|
|
1821
|
-
ErrorAutoFixManager.prototype.delay = function (ms) {
|
|
1822
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1823
|
-
return __generator(this, function (_a) {
|
|
1824
|
-
switch (_a.label) {
|
|
1825
|
-
case 0:
|
|
1826
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
1827
|
-
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, ms); })];
|
|
1828
|
-
case 1:
|
|
1829
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
1830
|
-
_a.sent();
|
|
1831
|
-
return [2 /*return*/];
|
|
1832
|
-
}
|
|
1833
|
-
});
|
|
1834
|
-
});
|
|
1835
|
-
};
|
|
1836
|
-
ErrorAutoFixManager.prototype.reportDevError = function (options) {
|
|
1837
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1838
|
-
var subject, body, sourceApp, environment, severity, fingerprint, metadata, err_5;
|
|
1839
|
-
return __generator(this, function (_a) {
|
|
1840
|
-
switch (_a.label) {
|
|
1841
|
-
case 0:
|
|
1842
|
-
subject = ((options === null || options === void 0 ? void 0 : options.subject) || '').trim() || 'ResolveIO alert';
|
|
1843
|
-
body = (options === null || options === void 0 ? void 0 : options.body) || '';
|
|
1844
|
-
sourceApp = (options === null || options === void 0 ? void 0 : options.sourceApp) || resolveio_server_app_1.ResolveIOServer.getClientName() || 'resolveio-server';
|
|
1845
|
-
environment = (options === null || options === void 0 ? void 0 : options.environment) || process.env.NODE_ENV || '';
|
|
1846
|
-
severity = (options === null || options === void 0 ? void 0 : options.severity) || 'infrastructure';
|
|
1847
|
-
fingerprint = ((options === null || options === void 0 ? void 0 : options.fingerprint) || (0, crypto_1.createHash)('sha256').update("".concat(sourceApp, ":").concat(environment || 'env', ":").concat(subject)).digest('hex')).trim();
|
|
1848
|
-
metadata = (options === null || options === void 0 ? void 0 : options.metadata) && Object.keys(options.metadata).length ? options.metadata : undefined;
|
|
1849
|
-
if (!this.isReady()) {
|
|
1850
|
-
console.warn('AutoFix manager not ready for dev alert', { subject: subject, environment: environment });
|
|
1851
|
-
return [2 /*return*/];
|
|
1852
|
-
}
|
|
1853
|
-
_a.label = 1;
|
|
1854
|
-
case 1:
|
|
1855
|
-
_a.trys.push([1, 3, , 4]);
|
|
1856
|
-
return [4 /*yield*/, this.ingestErrorReport({
|
|
1857
|
-
sourceApp: sourceApp,
|
|
1858
|
-
environment: environment,
|
|
1859
|
-
message: subject,
|
|
1860
|
-
stack: body,
|
|
1861
|
-
severity: severity,
|
|
1862
|
-
metadata: metadata,
|
|
1863
|
-
fingerprint: fingerprint,
|
|
1864
|
-
idempotencyKey: options === null || options === void 0 ? void 0 : options.idempotencyKey,
|
|
1865
|
-
clientId: options === null || options === void 0 ? void 0 : options.clientId,
|
|
1866
|
-
clientName: options === null || options === void 0 ? void 0 : options.clientName,
|
|
1867
|
-
clientSlug: options === null || options === void 0 ? void 0 : options.clientSlug,
|
|
1868
|
-
reportedBy: 'resolveio-server'
|
|
1869
|
-
})];
|
|
1870
|
-
case 2:
|
|
1871
|
-
_a.sent();
|
|
1872
|
-
return [3 /*break*/, 4];
|
|
1873
|
-
case 3:
|
|
1874
|
-
err_5 = _a.sent();
|
|
1875
|
-
console.error('Failed to log developer alert', subject, err_5);
|
|
1876
|
-
return [3 /*break*/, 4];
|
|
1877
|
-
case 4: return [2 /*return*/];
|
|
1878
|
-
}
|
|
1879
|
-
});
|
|
1880
|
-
});
|
|
1881
|
-
};
|
|
1882
|
-
ErrorAutoFixManager.prototype.ingestErrorReport = function (report) {
|
|
1883
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1884
|
-
var normalizedReport, email, rawHash, fingerprint, client, autoOptimizeEnabled, reservation, classification, updated, queued, result, finalLog, _a;
|
|
1885
|
-
return __generator(this, function (_b) {
|
|
1886
|
-
switch (_b.label) {
|
|
1887
|
-
case 0:
|
|
1888
|
-
if (!this.isReady()) {
|
|
1889
|
-
throw new Error('ErrorAutoFixManager is not enabled.');
|
|
1890
|
-
}
|
|
1891
|
-
if (!report || !report.sourceApp || !report.message) {
|
|
1892
|
-
throw new Error('Invalid error report payload.');
|
|
1893
|
-
}
|
|
1894
|
-
normalizedReport = __assign(__assign({}, report), { message: (report.message || '').toString(), stack: report.stack ? report.stack.toString() : undefined, metadata: report.metadata || undefined, context: report.context || undefined, attachments: Array.isArray(report.attachments) ? report.attachments : undefined, reportedAt: report.reportedAt instanceof Date && !Number.isNaN(report.reportedAt.getTime()) ? report.reportedAt : new Date() });
|
|
1895
|
-
email = this.buildEmailFromReport(normalizedReport);
|
|
1896
|
-
email.reportedAt = normalizedReport.reportedAt;
|
|
1897
|
-
email.openai_environment = normalizedReport.clientRepo || email.openai_environment;
|
|
1898
|
-
email.fromAddress = this.extractEmailAddress(normalizedReport.clientEmail || normalizedReport.reportedBy || email.from || '');
|
|
1899
|
-
if (!email.fromAddress && normalizedReport.clientSlug) {
|
|
1900
|
-
email.fromAddress = "".concat(normalizedReport.clientSlug, "@errors.resolveio.com");
|
|
1901
|
-
}
|
|
1902
|
-
rawHash = normalizedReport.idempotencyKey ? normalizedReport.idempotencyKey.trim() : '';
|
|
1903
|
-
email.rawHash = rawHash || this.generateRawEmailHash(email);
|
|
1904
|
-
fingerprint = normalizedReport.fingerprint ? normalizedReport.fingerprint.trim() : '';
|
|
1905
|
-
if (fingerprint) {
|
|
1906
|
-
email.issueHash = fingerprint;
|
|
1907
|
-
email.hash = fingerprint;
|
|
1908
|
-
}
|
|
1909
|
-
else {
|
|
1910
|
-
email.issueHash = this.generateIssueHash(email);
|
|
1911
|
-
email.hash = email.issueHash || email.rawHash;
|
|
1912
|
-
}
|
|
1913
|
-
return [4 /*yield*/, this.resolveClientForReport(normalizedReport)];
|
|
1914
|
-
case 1:
|
|
1915
|
-
client = _b.sent();
|
|
1916
|
-
return [4 /*yield*/, this.resolveAutoOptimizeEnabled()];
|
|
1917
|
-
case 2:
|
|
1918
|
-
autoOptimizeEnabled = _b.sent();
|
|
1919
|
-
return [4 /*yield*/, this.reserveLog(email, client, autoOptimizeEnabled)];
|
|
1920
|
-
case 3:
|
|
1921
|
-
reservation = _b.sent();
|
|
1922
|
-
if (!!reservation.proceed) return [3 /*break*/, 6];
|
|
1923
|
-
if (!(reservation.reason && this.shouldNotifySkip(reservation.reason))) return [3 /*break*/, 5];
|
|
1924
|
-
return [4 /*yield*/, this.notify({
|
|
1925
|
-
status: 'skipped',
|
|
1926
|
-
email: email,
|
|
1927
|
-
reason: reservation.reason,
|
|
1928
|
-
error: "Skipped auto-fix (".concat(reservation.reason, ")."),
|
|
1929
|
-
log: reservation.log
|
|
1930
|
-
})];
|
|
1931
|
-
case 4:
|
|
1932
|
-
_b.sent();
|
|
1933
|
-
_b.label = 5;
|
|
1934
|
-
case 5: return [2 /*return*/, {
|
|
1935
|
-
status: reservation.reason === 'duplicate' ? 'duplicate' : reservation.reason || 'skipped',
|
|
1936
|
-
reason: reservation.reason,
|
|
1937
|
-
log: reservation.log
|
|
1938
|
-
}];
|
|
1939
|
-
case 6:
|
|
1940
|
-
email.logId = reservation.log._id;
|
|
1941
|
-
classification = this.classifyEmail(email);
|
|
1942
|
-
return [4 /*yield*/, this.updateLog(email.logId, {
|
|
1943
|
-
id_client: client === null || client === void 0 ? void 0 : client._id,
|
|
1944
|
-
client_name: client === null || client === void 0 ? void 0 : client.name,
|
|
1945
|
-
from_email: email.fromAddress,
|
|
1946
|
-
source_type: classification.source,
|
|
1947
|
-
classification_reason: classification.reason || '',
|
|
1948
|
-
openai_environment: email.openai_environment || reservation.log.openai_environment || this.determineOpenAIEnvironment(client),
|
|
1949
|
-
source_app: email.sourceApp,
|
|
1950
|
-
source_environment: email.sourceEnvironment,
|
|
1951
|
-
severity: email.severity,
|
|
1952
|
-
reported_by: email.reportedBy || email.fromAddress,
|
|
1953
|
-
report_metadata: email.reportMetadata,
|
|
1954
|
-
report_context: email.reportContext,
|
|
1955
|
-
attachments: email.attachments,
|
|
1956
|
-
last_reported_at: email.reportedAt || new Date()
|
|
1957
|
-
})];
|
|
1958
|
-
case 7:
|
|
1959
|
-
_b.sent();
|
|
1960
|
-
if (!classification.skip) return [3 /*break*/, 11];
|
|
1961
|
-
return [4 /*yield*/, this.updateLog(email.logId, {
|
|
1962
|
-
status: 'skipped',
|
|
1963
|
-
ignored: !!classification.markIgnored,
|
|
1964
|
-
last_error: classification.reason || 'Ignored non-app alert',
|
|
1965
|
-
last_result_at: new Date()
|
|
1966
|
-
})];
|
|
1967
|
-
case 8:
|
|
1968
|
-
updated = _b.sent();
|
|
1969
|
-
if (!classification.notify) return [3 /*break*/, 10];
|
|
1970
|
-
return [4 /*yield*/, this.notify({
|
|
1971
|
-
status: 'skipped',
|
|
1972
|
-
email: email,
|
|
1973
|
-
error: classification.reason,
|
|
1974
|
-
log: updated,
|
|
1975
|
-
reason: 'classified'
|
|
1976
|
-
})];
|
|
1977
|
-
case 9:
|
|
1978
|
-
_b.sent();
|
|
1979
|
-
_b.label = 10;
|
|
1980
|
-
case 10: return [2 /*return*/, {
|
|
1981
|
-
status: 'skipped',
|
|
1982
|
-
reason: classification.reason,
|
|
1983
|
-
log: updated
|
|
1984
|
-
}];
|
|
1985
|
-
case 11:
|
|
1986
|
-
if (!!autoOptimizeEnabled) return [3 /*break*/, 14];
|
|
1987
|
-
return [4 /*yield*/, this.updateLog(email.logId, {
|
|
1988
|
-
status: 'pending'
|
|
1989
|
-
})];
|
|
1990
|
-
case 12:
|
|
1991
|
-
queued = _b.sent();
|
|
1992
|
-
return [4 /*yield*/, this.notifyCustomerWorkflowStatus('detected_autofix_disabled', email, queued || reservation.log)];
|
|
1993
|
-
case 13:
|
|
1994
|
-
_b.sent();
|
|
1995
|
-
return [2 /*return*/, {
|
|
1996
|
-
status: 'queued',
|
|
1997
|
-
log: queued
|
|
1998
|
-
}];
|
|
1999
|
-
case 14: return [4 /*yield*/, this.notifyCustomerWorkflowStatus('detected_autofix_enabled', email, reservation.log)];
|
|
2000
|
-
case 15:
|
|
2001
|
-
_b.sent();
|
|
2002
|
-
return [4 /*yield*/, this.processEmail(email, reservation.log)];
|
|
2003
|
-
case 16:
|
|
2004
|
-
result = _b.sent();
|
|
2005
|
-
return [4 /*yield*/, this.notify(result)];
|
|
2006
|
-
case 17:
|
|
2007
|
-
_b.sent();
|
|
2008
|
-
_a = result.log;
|
|
2009
|
-
if (_a) return [3 /*break*/, 19];
|
|
2010
|
-
return [4 /*yield*/, ErrorAutoFixLogs.findOne({ _id: email.logId })];
|
|
2011
|
-
case 18:
|
|
2012
|
-
_a = (_b.sent());
|
|
2013
|
-
_b.label = 19;
|
|
2014
|
-
case 19:
|
|
2015
|
-
finalLog = _a;
|
|
2016
|
-
return [2 /*return*/, {
|
|
2017
|
-
status: result.status,
|
|
2018
|
-
reason: result.reason,
|
|
2019
|
-
log: finalLog || result.log
|
|
2020
|
-
}];
|
|
2021
|
-
}
|
|
2022
|
-
});
|
|
2023
|
-
});
|
|
2024
|
-
};
|
|
2025
|
-
ErrorAutoFixManager.prototype.runLog = function (logId) {
|
|
2026
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2027
|
-
var log, now, email, classification, ignoredLog, inProgressLog, result;
|
|
2028
|
-
return __generator(this, function (_a) {
|
|
2029
|
-
switch (_a.label) {
|
|
2030
|
-
case 0:
|
|
2031
|
-
if (!this.config.enabled) {
|
|
2032
|
-
throw new Error('Auto-fix manager disabled.');
|
|
2033
|
-
}
|
|
2034
|
-
return [4 /*yield*/, ErrorAutoFixLogs.findOne({ _id: logId })];
|
|
2035
|
-
case 1:
|
|
2036
|
-
log = _a.sent();
|
|
2037
|
-
if (!log) {
|
|
2038
|
-
throw new Error('Auto-fix log not found.');
|
|
2039
|
-
}
|
|
2040
|
-
if (log.ignored) {
|
|
2041
|
-
throw new Error('Auto-fix log is ignored.');
|
|
2042
|
-
}
|
|
2043
|
-
if (log.status === 'in_progress') {
|
|
2044
|
-
throw new Error('Auto-fix workflow already running.');
|
|
2045
|
-
}
|
|
2046
|
-
if (!log.body) {
|
|
2047
|
-
throw new Error('Auto-fix log is missing email body.');
|
|
2048
|
-
}
|
|
2049
|
-
now = new Date();
|
|
2050
|
-
email = this.buildEmailFromLog(log);
|
|
2051
|
-
classification = this.classifyEmail(email);
|
|
2052
|
-
if (!(classification.skip && classification.markIgnored)) return [3 /*break*/, 3];
|
|
2053
|
-
return [4 /*yield*/, this.updateLog(logId, {
|
|
2054
|
-
status: 'skipped',
|
|
2055
|
-
ignored: true,
|
|
2056
|
-
last_error: classification.reason || 'Mongo-origin error ignored for auto-fix',
|
|
2057
|
-
last_result_at: now
|
|
2058
|
-
})];
|
|
2059
|
-
case 2:
|
|
2060
|
-
ignoredLog = _a.sent();
|
|
2061
|
-
return [2 /*return*/, {
|
|
2062
|
-
status: 'skipped',
|
|
2063
|
-
email: email,
|
|
2064
|
-
reason: 'classified',
|
|
2065
|
-
error: classification.reason || 'Mongo-origin error ignored for auto-fix',
|
|
2066
|
-
log: ignoredLog
|
|
2067
|
-
}];
|
|
2068
|
-
case 3: return [4 /*yield*/, ErrorAutoFixLogs.findOneAndUpdate({ _id: logId }, {
|
|
2069
|
-
$inc: {
|
|
2070
|
-
attempt_count: 1
|
|
2071
|
-
},
|
|
2072
|
-
$set: {
|
|
2073
|
-
status: 'in_progress',
|
|
2074
|
-
last_attempt_at: now,
|
|
2075
|
-
last_error: '',
|
|
2076
|
-
ignored: false
|
|
2077
|
-
}
|
|
2078
|
-
}, {
|
|
2079
|
-
returnDocument: 'after'
|
|
2080
|
-
})];
|
|
2081
|
-
case 4:
|
|
2082
|
-
inProgressLog = (_a.sent()) || log;
|
|
2083
|
-
return [4 /*yield*/, this.processEmail(email, inProgressLog)];
|
|
2084
|
-
case 5:
|
|
2085
|
-
result = _a.sent();
|
|
2086
|
-
return [4 /*yield*/, this.notify(result)];
|
|
2087
|
-
case 6:
|
|
2088
|
-
_a.sent();
|
|
2089
|
-
return [2 /*return*/, result];
|
|
2090
|
-
}
|
|
2091
|
-
});
|
|
2092
|
-
});
|
|
2093
|
-
};
|
|
2094
|
-
ErrorAutoFixManager.prototype.buildEmailFromLog = function (log) {
|
|
2095
|
-
return {
|
|
2096
|
-
key: log.message_id || log._id,
|
|
2097
|
-
subject: log.subject,
|
|
2098
|
-
body: log.body || '',
|
|
2099
|
-
messageId: log.message_id,
|
|
2100
|
-
hash: log.issue_hash || log.email_hash,
|
|
2101
|
-
rawHash: log.email_hash,
|
|
2102
|
-
issueHash: log.issue_hash,
|
|
2103
|
-
raw: log.body || '',
|
|
2104
|
-
id_client: log.id_client,
|
|
2105
|
-
client_name: log.client_name,
|
|
2106
|
-
fromAddress: log.from_email,
|
|
2107
|
-
source_type: log.source_type || 'app',
|
|
2108
|
-
classification_reason: log.classification_reason,
|
|
2109
|
-
openai_environment: log.openai_environment,
|
|
2110
|
-
sourceApp: log.source_app,
|
|
2111
|
-
sourceEnvironment: log.source_environment,
|
|
2112
|
-
severity: log.severity,
|
|
2113
|
-
reportedBy: log.reported_by,
|
|
2114
|
-
reportMetadata: log.report_metadata,
|
|
2115
|
-
reportContext: log.report_context,
|
|
2116
|
-
attachments: log.attachments,
|
|
2117
|
-
reportedAt: log.last_reported_at
|
|
2118
|
-
};
|
|
2119
|
-
};
|
|
2120
|
-
ErrorAutoFixManager.prototype.processEmail = function (email, log) {
|
|
2121
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2122
|
-
var libraryIssueGate, dashboardResult;
|
|
2123
|
-
return __generator(this, function (_a) {
|
|
2124
|
-
switch (_a.label) {
|
|
2125
|
-
case 0:
|
|
2126
|
-
libraryIssueGate = this.evaluateLibraryIssueGate(email, log);
|
|
2127
|
-
if (!libraryIssueGate.blocked) return [3 /*break*/, 2];
|
|
2128
|
-
return [4 /*yield*/, this.blockLibraryOwnedIssue(email, log, libraryIssueGate)];
|
|
2129
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
2130
|
-
case 2:
|
|
2131
|
-
if (!this.config.dashboardWorkflowEnabled) return [3 /*break*/, 4];
|
|
2132
|
-
return [4 /*yield*/, this.dispatchDashboardWorkflow(email, log)];
|
|
2133
|
-
case 3:
|
|
2134
|
-
dashboardResult = _a.sent();
|
|
2135
|
-
if (dashboardResult.status === 'in_progress' || dashboardResult.status === 'success') {
|
|
2136
|
-
return [2 /*return*/, dashboardResult];
|
|
2137
|
-
}
|
|
2138
|
-
if (!this.config.dashboardFallbackToGithub) {
|
|
2139
|
-
return [2 /*return*/, dashboardResult];
|
|
2140
|
-
}
|
|
2141
|
-
this.debugLog('Dashboard workflow unavailable; falling back to GitHub workflow.', {
|
|
2142
|
-
logId: log === null || log === void 0 ? void 0 : log._id,
|
|
2143
|
-
reason: dashboardResult.reason,
|
|
2144
|
-
error: dashboardResult.error
|
|
2145
|
-
});
|
|
2146
|
-
_a.label = 4;
|
|
2147
|
-
case 4: return [4 /*yield*/, this.dispatchGithubWorkflow(email, log)];
|
|
2148
|
-
case 5: return [2 /*return*/, _a.sent()];
|
|
2149
|
-
}
|
|
2150
|
-
});
|
|
2151
|
-
});
|
|
2152
|
-
};
|
|
2153
|
-
ErrorAutoFixManager.prototype.shouldFallbackDashboardMethod = function (error) {
|
|
2154
|
-
var message = "".concat((error === null || error === void 0 ? void 0 : error.message) || '').toLowerCase();
|
|
2155
|
-
return message.includes('not found')
|
|
2156
|
-
|| message.includes('worker dispatch unavailable')
|
|
2157
|
-
|| message.includes('no worker')
|
|
2158
|
-
|| message.includes('unavailable for aidashboard');
|
|
2159
|
-
};
|
|
2160
|
-
ErrorAutoFixManager.prototype.createDashboardJob = function (payload) {
|
|
2161
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2162
|
-
var methodManager, error_5, manager;
|
|
2163
|
-
return __generator(this, function (_a) {
|
|
2164
|
-
switch (_a.label) {
|
|
2165
|
-
case 0:
|
|
2166
|
-
methodManager = resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager();
|
|
2167
|
-
_a.label = 1;
|
|
2168
|
-
case 1:
|
|
2169
|
-
_a.trys.push([1, 3, , 4]);
|
|
2170
|
-
return [4 /*yield*/, methodManager.callMethod('aiDashboardCreateJob', payload)];
|
|
2171
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
2172
|
-
case 3:
|
|
2173
|
-
error_5 = _a.sent();
|
|
2174
|
-
if (!this.shouldFallbackDashboardMethod(error_5)) {
|
|
2175
|
-
throw error_5;
|
|
2176
|
-
}
|
|
2177
|
-
return [3 /*break*/, 4];
|
|
2178
|
-
case 4:
|
|
2179
|
-
manager = resolveio_server_app_1.ResolveIOServer['AIDashboardManager'];
|
|
2180
|
-
if (!(manager && manager.isEnabled && manager.isEnabled())) return [3 /*break*/, 6];
|
|
2181
|
-
return [4 /*yield*/, manager.createJob(payload)];
|
|
2182
|
-
case 5: return [2 /*return*/, _a.sent()];
|
|
2183
|
-
case 6: throw new Error('AI Dashboard manager is not available.');
|
|
2184
|
-
}
|
|
2185
|
-
});
|
|
2186
|
-
});
|
|
2187
|
-
};
|
|
2188
|
-
ErrorAutoFixManager.prototype.waitForDashboardJobStop = function (jobId, timeoutMs) {
|
|
2189
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2190
|
-
var methodManager, error_6, manager;
|
|
2191
|
-
return __generator(this, function (_a) {
|
|
2192
|
-
switch (_a.label) {
|
|
2193
|
-
case 0:
|
|
2194
|
-
methodManager = resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager();
|
|
2195
|
-
_a.label = 1;
|
|
2196
|
-
case 1:
|
|
2197
|
-
_a.trys.push([1, 3, , 4]);
|
|
2198
|
-
return [4 /*yield*/, methodManager.callMethod('aiDashboardWaitForJobStop', jobId, timeoutMs)];
|
|
2199
|
-
case 2:
|
|
2200
|
-
_a.sent();
|
|
2201
|
-
return [2 /*return*/];
|
|
2202
|
-
case 3:
|
|
2203
|
-
error_6 = _a.sent();
|
|
2204
|
-
if (!this.shouldFallbackDashboardMethod(error_6)) {
|
|
2205
|
-
throw error_6;
|
|
2206
|
-
}
|
|
2207
|
-
return [3 /*break*/, 4];
|
|
2208
|
-
case 4:
|
|
2209
|
-
manager = resolveio_server_app_1.ResolveIOServer['AIDashboardManager'];
|
|
2210
|
-
if (!(manager && manager.isEnabled && manager.isEnabled())) return [3 /*break*/, 6];
|
|
2211
|
-
return [4 /*yield*/, manager.waitForJobStop(jobId, timeoutMs)];
|
|
2212
|
-
case 5:
|
|
2213
|
-
_a.sent();
|
|
2214
|
-
return [2 /*return*/];
|
|
2215
|
-
case 6: throw new Error('AI Dashboard manager is not available.');
|
|
2216
|
-
}
|
|
2217
|
-
});
|
|
2218
|
-
});
|
|
2219
|
-
};
|
|
2220
|
-
ErrorAutoFixManager.prototype.isDashboardJobRunning = function (jobId) {
|
|
2221
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2222
|
-
var methodManager, running, error_7, manager;
|
|
2223
|
-
return __generator(this, function (_a) {
|
|
2224
|
-
switch (_a.label) {
|
|
2225
|
-
case 0:
|
|
2226
|
-
methodManager = resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager();
|
|
2227
|
-
_a.label = 1;
|
|
2228
|
-
case 1:
|
|
2229
|
-
_a.trys.push([1, 3, , 4]);
|
|
2230
|
-
return [4 /*yield*/, methodManager.callMethod('aiDashboardIsJobRunning', jobId)];
|
|
2231
|
-
case 2:
|
|
2232
|
-
running = _a.sent();
|
|
2233
|
-
return [2 /*return*/, !!running];
|
|
2234
|
-
case 3:
|
|
2235
|
-
error_7 = _a.sent();
|
|
2236
|
-
if (!this.shouldFallbackDashboardMethod(error_7)) {
|
|
2237
|
-
throw error_7;
|
|
2238
|
-
}
|
|
2239
|
-
return [3 /*break*/, 4];
|
|
2240
|
-
case 4:
|
|
2241
|
-
manager = resolveio_server_app_1.ResolveIOServer['AIDashboardManager'];
|
|
2242
|
-
if (manager && manager.isEnabled && manager.isEnabled()) {
|
|
2243
|
-
return [2 /*return*/, !!manager.isJobRunning(jobId)];
|
|
2244
|
-
}
|
|
2245
|
-
throw new Error('AI Dashboard manager is not available.');
|
|
2246
|
-
}
|
|
2247
|
-
});
|
|
2248
|
-
});
|
|
2249
|
-
};
|
|
2250
|
-
ErrorAutoFixManager.prototype.resolveAutoFixApp = function (email, log, resolvedEnvironment) {
|
|
2251
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2252
|
-
var clientId, byClientId, lookupClientCandidates, lookupClientCandidates_1, lookupClientCandidates_1_1, candidate, escaped, clientDoc, byClient, e_5_1, environmentRepo, escapedRepo, byRepo, appNameCandidates, appNameCandidates_1, appNameCandidates_1_1, candidate, escaped, bySlugOrName, e_6_1;
|
|
2253
|
-
var e_5, _a, e_6, _b;
|
|
2254
|
-
return __generator(this, function (_c) {
|
|
2255
|
-
switch (_c.label) {
|
|
2256
|
-
case 0:
|
|
2257
|
-
clientId = (email.id_client || log.id_client || '').trim();
|
|
2258
|
-
if (!clientId) return [3 /*break*/, 2];
|
|
2259
|
-
return [4 /*yield*/, AICoderApps.findOne({ client_id: clientId }, {
|
|
2260
|
-
sort: {
|
|
2261
|
-
updatedAt: -1,
|
|
2262
|
-
createdAt: -1
|
|
2263
|
-
}
|
|
2264
|
-
})];
|
|
2265
|
-
case 1:
|
|
2266
|
-
byClientId = _c.sent();
|
|
2267
|
-
if (byClientId) {
|
|
2268
|
-
return [2 /*return*/, byClientId];
|
|
2269
|
-
}
|
|
2270
|
-
_c.label = 2;
|
|
2271
|
-
case 2:
|
|
2272
|
-
lookupClientCandidates = [
|
|
2273
|
-
(email.client_name || '').trim(),
|
|
2274
|
-
(log.client_name || '').trim()
|
|
2275
|
-
].filter(Boolean);
|
|
2276
|
-
_c.label = 3;
|
|
2277
|
-
case 3:
|
|
2278
|
-
_c.trys.push([3, 9, 10, 11]);
|
|
2279
|
-
lookupClientCandidates_1 = __values(lookupClientCandidates), lookupClientCandidates_1_1 = lookupClientCandidates_1.next();
|
|
2280
|
-
_c.label = 4;
|
|
2281
|
-
case 4:
|
|
2282
|
-
if (!!lookupClientCandidates_1_1.done) return [3 /*break*/, 8];
|
|
2283
|
-
candidate = lookupClientCandidates_1_1.value;
|
|
2284
|
-
escaped = this.escapeRegex(candidate);
|
|
2285
|
-
return [4 /*yield*/, Clients.findOne({
|
|
2286
|
-
$or: [
|
|
2287
|
-
{ name: { $regex: "^".concat(escaped, "$"), $options: 'i' } },
|
|
2288
|
-
{ demo_name: { $regex: "^".concat(escaped, "$"), $options: 'i' } },
|
|
2289
|
-
{ repo: { $regex: "^".concat(escaped, "$"), $options: 'i' } }
|
|
2290
|
-
]
|
|
2291
|
-
})];
|
|
2292
|
-
case 5:
|
|
2293
|
-
clientDoc = _c.sent();
|
|
2294
|
-
if (!(clientDoc === null || clientDoc === void 0 ? void 0 : clientDoc._id)) {
|
|
2295
|
-
return [3 /*break*/, 7];
|
|
2296
|
-
}
|
|
2297
|
-
return [4 /*yield*/, AICoderApps.findOne({ client_id: clientDoc._id }, {
|
|
2298
|
-
sort: {
|
|
2299
|
-
updatedAt: -1,
|
|
2300
|
-
createdAt: -1
|
|
2301
|
-
}
|
|
2302
|
-
})];
|
|
2303
|
-
case 6:
|
|
2304
|
-
byClient = _c.sent();
|
|
2305
|
-
if (byClient) {
|
|
2306
|
-
return [2 /*return*/, byClient];
|
|
2307
|
-
}
|
|
2308
|
-
_c.label = 7;
|
|
2309
|
-
case 7:
|
|
2310
|
-
lookupClientCandidates_1_1 = lookupClientCandidates_1.next();
|
|
2311
|
-
return [3 /*break*/, 4];
|
|
2312
|
-
case 8: return [3 /*break*/, 11];
|
|
2313
|
-
case 9:
|
|
2314
|
-
e_5_1 = _c.sent();
|
|
2315
|
-
e_5 = { error: e_5_1 };
|
|
2316
|
-
return [3 /*break*/, 11];
|
|
2317
|
-
case 10:
|
|
2318
|
-
try {
|
|
2319
|
-
if (lookupClientCandidates_1_1 && !lookupClientCandidates_1_1.done && (_a = lookupClientCandidates_1.return)) _a.call(lookupClientCandidates_1);
|
|
2320
|
-
}
|
|
2321
|
-
finally { if (e_5) throw e_5.error; }
|
|
2322
|
-
return [7 /*endfinally*/];
|
|
2323
|
-
case 11:
|
|
2324
|
-
environmentRepo = (resolvedEnvironment || '').trim();
|
|
2325
|
-
if (!environmentRepo) return [3 /*break*/, 13];
|
|
2326
|
-
escapedRepo = this.escapeRegex(environmentRepo);
|
|
2327
|
-
return [4 /*yield*/, AICoderApps.findOne({
|
|
2328
|
-
repo: {
|
|
2329
|
-
$regex: "^".concat(escapedRepo, "$"),
|
|
2330
|
-
$options: 'i'
|
|
2331
|
-
}
|
|
2332
|
-
}, {
|
|
2333
|
-
sort: {
|
|
2334
|
-
updatedAt: -1,
|
|
2335
|
-
createdAt: -1
|
|
2336
|
-
}
|
|
2337
|
-
})];
|
|
2338
|
-
case 12:
|
|
2339
|
-
byRepo = _c.sent();
|
|
2340
|
-
if (byRepo) {
|
|
2341
|
-
return [2 /*return*/, byRepo];
|
|
2342
|
-
}
|
|
2343
|
-
_c.label = 13;
|
|
2344
|
-
case 13:
|
|
2345
|
-
appNameCandidates = [
|
|
2346
|
-
(email.sourceApp || '').trim(),
|
|
2347
|
-
(log.source_app || '').trim()
|
|
2348
|
-
].filter(Boolean);
|
|
2349
|
-
_c.label = 14;
|
|
2350
|
-
case 14:
|
|
2351
|
-
_c.trys.push([14, 19, 20, 21]);
|
|
2352
|
-
appNameCandidates_1 = __values(appNameCandidates), appNameCandidates_1_1 = appNameCandidates_1.next();
|
|
2353
|
-
_c.label = 15;
|
|
2354
|
-
case 15:
|
|
2355
|
-
if (!!appNameCandidates_1_1.done) return [3 /*break*/, 18];
|
|
2356
|
-
candidate = appNameCandidates_1_1.value;
|
|
2357
|
-
escaped = this.escapeRegex(candidate);
|
|
2358
|
-
return [4 /*yield*/, AICoderApps.findOne({
|
|
2359
|
-
$or: [
|
|
2360
|
-
{ slug: { $regex: "^".concat(escaped, "$"), $options: 'i' } },
|
|
2361
|
-
{ name: { $regex: "^".concat(escaped, "$"), $options: 'i' } }
|
|
2362
|
-
]
|
|
2363
|
-
}, {
|
|
2364
|
-
sort: {
|
|
2365
|
-
updatedAt: -1,
|
|
2366
|
-
createdAt: -1
|
|
2367
|
-
}
|
|
2368
|
-
})];
|
|
2369
|
-
case 16:
|
|
2370
|
-
bySlugOrName = _c.sent();
|
|
2371
|
-
if (bySlugOrName) {
|
|
2372
|
-
return [2 /*return*/, bySlugOrName];
|
|
2373
|
-
}
|
|
2374
|
-
_c.label = 17;
|
|
2375
|
-
case 17:
|
|
2376
|
-
appNameCandidates_1_1 = appNameCandidates_1.next();
|
|
2377
|
-
return [3 /*break*/, 15];
|
|
2378
|
-
case 18: return [3 /*break*/, 21];
|
|
2379
|
-
case 19:
|
|
2380
|
-
e_6_1 = _c.sent();
|
|
2381
|
-
e_6 = { error: e_6_1 };
|
|
2382
|
-
return [3 /*break*/, 21];
|
|
2383
|
-
case 20:
|
|
2384
|
-
try {
|
|
2385
|
-
if (appNameCandidates_1_1 && !appNameCandidates_1_1.done && (_b = appNameCandidates_1.return)) _b.call(appNameCandidates_1);
|
|
2386
|
-
}
|
|
2387
|
-
finally { if (e_6) throw e_6.error; }
|
|
2388
|
-
return [7 /*endfinally*/];
|
|
2389
|
-
case 21: return [2 /*return*/, null];
|
|
2390
|
-
}
|
|
2391
|
-
});
|
|
2392
|
-
});
|
|
2393
|
-
};
|
|
2394
|
-
ErrorAutoFixManager.prototype.buildDashboardAutoFixTitle = function (email, log, app) {
|
|
2395
|
-
var identifier = log.autofix_error_count_string || (log._id || '').slice(-6) || 'error';
|
|
2396
|
-
var source = (email.sourceApp || log.source_app || (app === null || app === void 0 ? void 0 : app.name) || 'application').trim();
|
|
2397
|
-
return "Auto-fix ".concat(identifier, ": ").concat(source);
|
|
2398
|
-
};
|
|
2399
|
-
ErrorAutoFixManager.prototype.buildDashboardAutoFixDescription = function (email, log, app) {
|
|
2400
|
-
var normalizedBody = this.normalizeEmailText(email.body || log.body || '', 15000);
|
|
2401
|
-
var metadata = log.report_metadata && Object.keys(log.report_metadata).length
|
|
2402
|
-
? JSON.stringify(log.report_metadata, null, 2)
|
|
2403
|
-
: '';
|
|
2404
|
-
var context = log.report_context && Object.keys(log.report_context).length
|
|
2405
|
-
? JSON.stringify(log.report_context, null, 2)
|
|
2406
|
-
: '';
|
|
2407
|
-
var attachments = Array.isArray(log.attachments) ? log.attachments : [];
|
|
2408
|
-
var attachmentLines = attachments.length
|
|
2409
|
-
? attachments.map(function (att) { return "- ".concat(((att === null || att === void 0 ? void 0 : att.name) || 'attachment').trim(), " ").concat((att === null || att === void 0 ? void 0 : att.url) ? "(".concat(att.url, ")") : '').trim(); }).join('\n')
|
|
2410
|
-
: '(none)';
|
|
2411
|
-
var lines = [
|
|
2412
|
-
'Autonomous production error remediation request.',
|
|
2413
|
-
'',
|
|
2414
|
-
'Hard requirements:',
|
|
2415
|
-
'1. Before changing code, query the project MongoDB diagnostics logs for the latest context.',
|
|
2416
|
-
'2. Query `error-autofix-logs` using `_id`, `issue_hash`, and `email_hash` from this task, then use the newest matching records.',
|
|
2417
|
-
'3. If a previous dashboard job id is provided, query `ai-development-jobs` by that `_id` and review recent failure logs before retrying.',
|
|
2418
|
-
'4. Treat `.dashboard-output/build-*.log` as primary build evidence, and `.build-output/build-*.log` as retained history when diagnosing failures.',
|
|
2419
|
-
'5. Reproduce and fix the reported issue with the smallest safe code change.',
|
|
2420
|
-
'6. Keep query/result behavior backward compatible unless explicitly required by the bug fix.',
|
|
2421
|
-
'7. Run project build checks and continue iterating until the build is green.',
|
|
2422
|
-
'8. Ensure there are no new lint/type/runtime regressions introduced by the fix.',
|
|
2423
|
-
'9. Finish by publishing the passing fix to the default branch and deploying artifacts.',
|
|
2424
|
-
'',
|
|
2425
|
-
"App: ".concat((app === null || app === void 0 ? void 0 : app.name) || (app === null || app === void 0 ? void 0 : app._id) || 'unknown'),
|
|
2426
|
-
"Repo: ".concat((app === null || app === void 0 ? void 0 : app.repo) || 'unknown'),
|
|
2427
|
-
"Environment: ".concat(email.sourceEnvironment || log.source_environment || 'unknown'),
|
|
2428
|
-
"Severity: ".concat(email.severity || log.severity || 'error'),
|
|
2429
|
-
"Fingerprint: ".concat(email.issueHash || log.issue_hash || log.email_hash || 'n/a'),
|
|
2430
|
-
"Error Log Id: ".concat(String((log === null || log === void 0 ? void 0 : log._id) || '').trim() || 'n/a'),
|
|
2431
|
-
"Previous Dashboard Job Id: ".concat(String((log === null || log === void 0 ? void 0 : log.openai_task_id) || '').trim() || 'n/a'),
|
|
2432
|
-
'',
|
|
2433
|
-
'Reported error payload:',
|
|
2434
|
-
'```',
|
|
2435
|
-
normalizedBody || '(empty error body)',
|
|
2436
|
-
'```',
|
|
2437
|
-
'',
|
|
2438
|
-
'Attachments:',
|
|
2439
|
-
attachmentLines
|
|
2440
|
-
];
|
|
2441
|
-
if (metadata) {
|
|
2442
|
-
lines.push('', 'Metadata JSON:', '```json', metadata, '```');
|
|
2443
|
-
}
|
|
2444
|
-
if (context) {
|
|
2445
|
-
lines.push('', 'Context JSON:', '```json', context, '```');
|
|
2446
|
-
}
|
|
2447
|
-
return lines.join('\n');
|
|
2448
|
-
};
|
|
2449
|
-
ErrorAutoFixManager.prototype.evaluateDashboardPublishOutcome = function (job) {
|
|
2450
|
-
var logEntries = Array.isArray(job === null || job === void 0 ? void 0 : job.log) ? job.log : [];
|
|
2451
|
-
var lastMatch = function (predicate) {
|
|
2452
|
-
for (var i = logEntries.length - 1; i >= 0; i -= 1) {
|
|
2453
|
-
if (predicate(logEntries[i] || '')) {
|
|
2454
|
-
return logEntries[i];
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
return '';
|
|
2458
|
-
};
|
|
2459
|
-
var failureEntry = lastMatch(function (entry) { return /publish failed|artifact publish failed|deploy failed/i.test(entry || ''); });
|
|
2460
|
-
if (failureEntry) {
|
|
2461
|
-
return {
|
|
2462
|
-
success: false,
|
|
2463
|
-
message: failureEntry
|
|
2464
|
-
};
|
|
2465
|
-
}
|
|
2466
|
-
var publishEntry = lastMatch(function (entry) { return /Published build to /i.test(entry || ''); });
|
|
2467
|
-
if (publishEntry) {
|
|
2468
|
-
var branchMatch = publishEntry.match(/\(([^()]+)\)\.?$/);
|
|
2469
|
-
return {
|
|
2470
|
-
success: true,
|
|
2471
|
-
branchName: (branchMatch && branchMatch[1]) ? branchMatch[1].trim() : undefined,
|
|
2472
|
-
message: publishEntry
|
|
2473
|
-
};
|
|
2474
|
-
}
|
|
2475
|
-
var skippedEntry = lastMatch(function (entry) { return /Publish skipped/i.test(entry || ''); });
|
|
2476
|
-
if (skippedEntry) {
|
|
2477
|
-
return {
|
|
2478
|
-
success: !this.config.dashboardPublishRequired,
|
|
2479
|
-
message: skippedEntry
|
|
2480
|
-
};
|
|
2481
|
-
}
|
|
2482
|
-
return {
|
|
2483
|
-
success: !this.config.dashboardPublishRequired,
|
|
2484
|
-
message: 'Dashboard job completed without a publish confirmation log entry.'
|
|
2485
|
-
};
|
|
2486
|
-
};
|
|
2487
|
-
ErrorAutoFixManager.prototype.queueDashboardMonitor = function (log, email, jobId, effectiveEnvironment) {
|
|
2488
|
-
var _this = this;
|
|
2489
|
-
var logId = ((log === null || log === void 0 ? void 0 : log._id) || '').trim();
|
|
2490
|
-
var normalizedJobId = (jobId || '').trim();
|
|
2491
|
-
if (!logId || !normalizedJobId) {
|
|
2492
|
-
return;
|
|
2493
|
-
}
|
|
2494
|
-
if (this.dashboardMonitors.has(logId)) {
|
|
2495
|
-
return;
|
|
2496
|
-
}
|
|
2497
|
-
var monitor = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2498
|
-
var error_8;
|
|
2499
|
-
return __generator(this, function (_a) {
|
|
2500
|
-
switch (_a.label) {
|
|
2501
|
-
case 0:
|
|
2502
|
-
_a.trys.push([0, 2, 3, 4]);
|
|
2503
|
-
return [4 /*yield*/, this.monitorDashboardAutoFixJob(log, email, normalizedJobId, effectiveEnvironment)];
|
|
2504
|
-
case 1:
|
|
2505
|
-
_a.sent();
|
|
2506
|
-
return [3 /*break*/, 4];
|
|
2507
|
-
case 2:
|
|
2508
|
-
error_8 = _a.sent();
|
|
2509
|
-
console.error('Auto-fix dashboard monitor failed', { logId: logId, jobId: normalizedJobId, error: error_8 });
|
|
2510
|
-
return [3 /*break*/, 4];
|
|
2511
|
-
case 3:
|
|
2512
|
-
this.dashboardMonitors.delete(logId);
|
|
2513
|
-
return [7 /*endfinally*/];
|
|
2514
|
-
case 4: return [2 /*return*/];
|
|
2515
|
-
}
|
|
2516
|
-
});
|
|
2517
|
-
}); })();
|
|
2518
|
-
this.dashboardMonitors.set(logId, monitor);
|
|
2519
|
-
};
|
|
2520
|
-
ErrorAutoFixManager.prototype.monitorDashboardAutoFixJob = function (log, email, jobId, effectiveEnvironment) {
|
|
2521
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2522
|
-
var logId, fail, error_9, message, isRunning, error_10, message, job, publishOutcome, fallbackBranch, branchName, successLog;
|
|
2523
|
-
var _this = this;
|
|
2524
|
-
var _a;
|
|
2525
|
-
return __generator(this, function (_b) {
|
|
2526
|
-
switch (_b.label) {
|
|
2527
|
-
case 0:
|
|
2528
|
-
logId = ((log === null || log === void 0 ? void 0 : log._id) || '').trim();
|
|
2529
|
-
if (!logId) {
|
|
2530
|
-
return [2 /*return*/];
|
|
2531
|
-
}
|
|
2532
|
-
fail = function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
2533
|
-
var failedLog;
|
|
2534
|
-
return __generator(this, function (_a) {
|
|
2535
|
-
switch (_a.label) {
|
|
2536
|
-
case 0: return [4 /*yield*/, this.updateLog(logId, {
|
|
2537
|
-
status: 'failed',
|
|
2538
|
-
last_error: message,
|
|
2539
|
-
last_result_at: new Date(),
|
|
2540
|
-
openai_task_id: jobId,
|
|
2541
|
-
openai_environment: effectiveEnvironment
|
|
2542
|
-
})];
|
|
2543
|
-
case 1:
|
|
2544
|
-
failedLog = (_a.sent()) || log;
|
|
2545
|
-
return [4 /*yield*/, this.notifyCustomerWorkflowStatus('completed_failed', email, failedLog, { error: message })];
|
|
2546
|
-
case 2:
|
|
2547
|
-
_a.sent();
|
|
2548
|
-
return [4 /*yield*/, this.notify({
|
|
2549
|
-
status: 'failed',
|
|
2550
|
-
email: email,
|
|
2551
|
-
error: message,
|
|
2552
|
-
log: failedLog,
|
|
2553
|
-
summary: failedLog.plan_summary || email.subject
|
|
2554
|
-
})];
|
|
2555
|
-
case 3:
|
|
2556
|
-
_a.sent();
|
|
2557
|
-
return [2 /*return*/];
|
|
2558
|
-
}
|
|
2559
|
-
});
|
|
2560
|
-
}); };
|
|
2561
|
-
_b.label = 1;
|
|
2562
|
-
case 1:
|
|
2563
|
-
_b.trys.push([1, 3, , 5]);
|
|
2564
|
-
return [4 /*yield*/, this.waitForDashboardJobStop(jobId, this.config.dashboardWaitTimeoutMs)];
|
|
2565
|
-
case 2:
|
|
2566
|
-
_b.sent();
|
|
2567
|
-
return [3 /*break*/, 5];
|
|
2568
|
-
case 3:
|
|
2569
|
-
error_9 = _b.sent();
|
|
2570
|
-
message = (error_9 === null || error_9 === void 0 ? void 0 : error_9.message) || 'Failed while waiting for dashboard job completion.';
|
|
2571
|
-
return [4 /*yield*/, fail(message)];
|
|
2572
|
-
case 4:
|
|
2573
|
-
_b.sent();
|
|
2574
|
-
return [2 /*return*/];
|
|
2575
|
-
case 5:
|
|
2576
|
-
isRunning = false;
|
|
2577
|
-
_b.label = 6;
|
|
2578
|
-
case 6:
|
|
2579
|
-
_b.trys.push([6, 8, , 10]);
|
|
2580
|
-
return [4 /*yield*/, this.isDashboardJobRunning(jobId)];
|
|
2581
|
-
case 7:
|
|
2582
|
-
isRunning = _b.sent();
|
|
2583
|
-
return [3 /*break*/, 10];
|
|
2584
|
-
case 8:
|
|
2585
|
-
error_10 = _b.sent();
|
|
2586
|
-
message = (error_10 === null || error_10 === void 0 ? void 0 : error_10.message) || 'Unable to confirm dashboard job completion state.';
|
|
2587
|
-
return [4 /*yield*/, fail(message)];
|
|
2588
|
-
case 9:
|
|
2589
|
-
_b.sent();
|
|
2590
|
-
return [2 /*return*/];
|
|
2591
|
-
case 10:
|
|
2592
|
-
if (!isRunning) return [3 /*break*/, 12];
|
|
2593
|
-
return [4 /*yield*/, fail("Dashboard job ".concat(jobId, " timed out before completion."))];
|
|
2594
|
-
case 11:
|
|
2595
|
-
_b.sent();
|
|
2596
|
-
return [2 /*return*/];
|
|
2597
|
-
case 12: return [4 /*yield*/, AIDashboardJobs.findOne({ _id: jobId })];
|
|
2598
|
-
case 13:
|
|
2599
|
-
job = _b.sent();
|
|
2600
|
-
if (!!job) return [3 /*break*/, 15];
|
|
2601
|
-
return [4 /*yield*/, fail("Dashboard job ".concat(jobId, " not found."))];
|
|
2602
|
-
case 14:
|
|
2603
|
-
_b.sent();
|
|
2604
|
-
return [2 /*return*/];
|
|
2605
|
-
case 15:
|
|
2606
|
-
if (!(job.phase !== 'COMPLETE' || job.paused)) return [3 /*break*/, 17];
|
|
2607
|
-
return [4 /*yield*/, fail("Dashboard job ".concat(jobId, " ended in phase ").concat(job.phase || 'unknown').concat(job.paused ? ' (paused)' : '', "."))];
|
|
2608
|
-
case 16:
|
|
2609
|
-
_b.sent();
|
|
2610
|
-
return [2 /*return*/];
|
|
2611
|
-
case 17:
|
|
2612
|
-
publishOutcome = this.evaluateDashboardPublishOutcome(job);
|
|
2613
|
-
if (!!publishOutcome.success) return [3 /*break*/, 19];
|
|
2614
|
-
return [4 /*yield*/, fail(publishOutcome.message)];
|
|
2615
|
-
case 18:
|
|
2616
|
-
_b.sent();
|
|
2617
|
-
return [2 /*return*/];
|
|
2618
|
-
case 19:
|
|
2619
|
-
fallbackBranch = (String(((_a = this._serverConfig) === null || _a === void 0 ? void 0 : _a['GITHUB_DEFAULT_BRANCH']) || process.env.GITHUB_DEFAULT_BRANCH || 'main').trim() || 'main');
|
|
2620
|
-
branchName = publishOutcome.branchName || fallbackBranch;
|
|
2621
|
-
return [4 /*yield*/, this.updateLog(logId, {
|
|
2622
|
-
status: 'success',
|
|
2623
|
-
branch_name: branchName,
|
|
2624
|
-
pr_url: '',
|
|
2625
|
-
last_error: '',
|
|
2626
|
-
last_result_at: new Date(),
|
|
2627
|
-
openai_task_id: jobId,
|
|
2628
|
-
openai_environment: effectiveEnvironment
|
|
2629
|
-
})];
|
|
2630
|
-
case 20:
|
|
2631
|
-
successLog = (_b.sent()) || log;
|
|
2632
|
-
return [4 /*yield*/, this.notifyCustomerWorkflowStatus('completed_success', email, successLog, { notes: publishOutcome.message })];
|
|
2633
|
-
case 21:
|
|
2634
|
-
_b.sent();
|
|
2635
|
-
return [4 /*yield*/, this.notify({
|
|
2636
|
-
status: 'success',
|
|
2637
|
-
email: email,
|
|
2638
|
-
branchName: branchName,
|
|
2639
|
-
log: successLog,
|
|
2640
|
-
summary: successLog.plan_summary || email.subject,
|
|
2641
|
-
notes: publishOutcome.message
|
|
2642
|
-
})];
|
|
2643
|
-
case 22:
|
|
2644
|
-
_b.sent();
|
|
2645
|
-
return [2 /*return*/];
|
|
2646
|
-
}
|
|
2647
|
-
});
|
|
2648
|
-
});
|
|
2649
|
-
};
|
|
2650
|
-
ErrorAutoFixManager.prototype.dispatchDashboardWorkflow = function (email, log) {
|
|
2651
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2652
|
-
var fail, openaiEnvironment, app, repo, effectiveEnvironment, emailHash, rawHash, title, description, job, error_11, message, jobId, queuedLog;
|
|
2653
|
-
var _this = this;
|
|
2654
|
-
return __generator(this, function (_a) {
|
|
2655
|
-
switch (_a.label) {
|
|
2656
|
-
case 0:
|
|
2657
|
-
fail = function (status, reason, message) { return __awaiter(_this, void 0, void 0, function () {
|
|
2658
|
-
var updated;
|
|
2659
|
-
return __generator(this, function (_a) {
|
|
2660
|
-
switch (_a.label) {
|
|
2661
|
-
case 0: return [4 /*yield*/, this.updateLog(log._id, {
|
|
2662
|
-
status: status,
|
|
2663
|
-
last_error: message,
|
|
2664
|
-
last_result_at: new Date()
|
|
2665
|
-
})];
|
|
2666
|
-
case 1:
|
|
2667
|
-
updated = (_a.sent()) || log;
|
|
2668
|
-
return [2 /*return*/, {
|
|
2669
|
-
status: status,
|
|
2670
|
-
email: email,
|
|
2671
|
-
error: message,
|
|
2672
|
-
log: updated,
|
|
2673
|
-
reason: reason
|
|
2674
|
-
}];
|
|
2675
|
-
}
|
|
2676
|
-
});
|
|
2677
|
-
}); };
|
|
2678
|
-
openaiEnvironment = this.resolveEnvironmentForTask(email, log);
|
|
2679
|
-
return [4 /*yield*/, this.resolveAutoFixApp(email, log, openaiEnvironment)];
|
|
2680
|
-
case 1:
|
|
2681
|
-
app = _a.sent();
|
|
2682
|
-
if (!!(app === null || app === void 0 ? void 0 : app._id)) return [3 /*break*/, 3];
|
|
2683
|
-
return [4 /*yield*/, fail('skipped', 'dashboard_app_not_found', 'No AI Coder app found for this error log.')];
|
|
2684
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
2685
|
-
case 3:
|
|
2686
|
-
repo = (app.repo || '').trim();
|
|
2687
|
-
if (!!repo) return [3 /*break*/, 5];
|
|
2688
|
-
return [4 /*yield*/, fail('skipped', 'dashboard_repo_missing', 'Resolved AI Coder app is missing repo configuration.')];
|
|
2689
|
-
case 4: return [2 /*return*/, _a.sent()];
|
|
2690
|
-
case 5:
|
|
2691
|
-
effectiveEnvironment = repo;
|
|
2692
|
-
emailHash = email.issueHash || email.hash || this.generateIssueHash(email);
|
|
2693
|
-
rawHash = email.rawHash || this.generateRawEmailHash(email);
|
|
2694
|
-
title = this.buildDashboardAutoFixTitle(email, log, app);
|
|
2695
|
-
description = this.buildDashboardAutoFixDescription(email, log, app);
|
|
2696
|
-
_a.label = 6;
|
|
2697
|
-
case 6:
|
|
2698
|
-
_a.trys.push([6, 8, , 10]);
|
|
2699
|
-
return [4 /*yield*/, this.createDashboardJob({
|
|
2700
|
-
project: app._id,
|
|
2701
|
-
title: title,
|
|
2702
|
-
description: description,
|
|
2703
|
-
repo: repo,
|
|
2704
|
-
path: app.git_local_path || undefined,
|
|
2705
|
-
projectRoot: app.project_root || undefined
|
|
2706
|
-
})];
|
|
2707
|
-
case 7:
|
|
2708
|
-
job = _a.sent();
|
|
2709
|
-
return [3 /*break*/, 10];
|
|
2710
|
-
case 8:
|
|
2711
|
-
error_11 = _a.sent();
|
|
2712
|
-
message = (error_11 === null || error_11 === void 0 ? void 0 : error_11.message) || 'Unable to enqueue dashboard auto-fix job.';
|
|
2713
|
-
return [4 /*yield*/, fail('failed', 'dashboard_job_create_failed', message)];
|
|
2714
|
-
case 9: return [2 /*return*/, _a.sent()];
|
|
2715
|
-
case 10:
|
|
2716
|
-
jobId = ((job === null || job === void 0 ? void 0 : job._id) || '').trim();
|
|
2717
|
-
if (!!jobId) return [3 /*break*/, 12];
|
|
2718
|
-
return [4 /*yield*/, fail('failed', 'dashboard_job_missing_id', 'Dashboard job created without an id.')];
|
|
2719
|
-
case 11: return [2 /*return*/, _a.sent()];
|
|
2720
|
-
case 12: return [4 /*yield*/, this.updateLog(log._id, {
|
|
2721
|
-
status: 'in_progress',
|
|
2722
|
-
last_attempt_at: new Date(),
|
|
2723
|
-
branch_name: '',
|
|
2724
|
-
pr_url: '',
|
|
2725
|
-
last_error: '',
|
|
2726
|
-
openai_environment: effectiveEnvironment,
|
|
2727
|
-
issue_hash: emailHash,
|
|
2728
|
-
email_hash: rawHash,
|
|
2729
|
-
openai_task_id: jobId,
|
|
2730
|
-
plan_summary: title,
|
|
2731
|
-
plan_body: description
|
|
2732
|
-
})];
|
|
2733
|
-
case 13:
|
|
2734
|
-
queuedLog = (_a.sent()) || log;
|
|
2735
|
-
this.queueDashboardMonitor(queuedLog, email, jobId, effectiveEnvironment);
|
|
2736
|
-
return [2 /*return*/, {
|
|
2737
|
-
status: 'in_progress',
|
|
2738
|
-
email: email,
|
|
2739
|
-
log: queuedLog,
|
|
2740
|
-
reason: 'dashboard_job_queued',
|
|
2741
|
-
summary: title,
|
|
2742
|
-
notes: "Dashboard job ".concat(jobId, " queued for autonomous build/fix/publish/deploy.")
|
|
2743
|
-
}];
|
|
2744
|
-
}
|
|
2745
|
-
});
|
|
2746
|
-
});
|
|
2747
|
-
};
|
|
2748
|
-
ErrorAutoFixManager.prototype.dispatchGithubWorkflow = function (email, log) {
|
|
2749
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2750
|
-
var openaiEnvironment, fallbackEnv, resolvedEnvironment, repoTarget, updated, updated, effectiveEnv, emailHash, rawHash, workBranch, contextIdentifier, contextPath, normalizedBody, contextContent, commentBody, baseBranch, baseSha, pr, title, bodyLines, updated, err_6, message, updated;
|
|
2751
|
-
return __generator(this, function (_a) {
|
|
2752
|
-
switch (_a.label) {
|
|
2753
|
-
case 0:
|
|
2754
|
-
openaiEnvironment = this.resolveEnvironmentForTask(email, log);
|
|
2755
|
-
fallbackEnv = this.config.githubOwner && this.config.githubRepo ? "".concat(this.config.githubOwner, "/").concat(this.config.githubRepo) : '';
|
|
2756
|
-
resolvedEnvironment = (openaiEnvironment || fallbackEnv || '').trim();
|
|
2757
|
-
repoTarget = this.parseRepoTarget(resolvedEnvironment) || this.parseRepoTarget(fallbackEnv);
|
|
2758
|
-
this.debugLog('Starting GitHub PR workflow.', {
|
|
2759
|
-
emailKey: email.key,
|
|
2760
|
-
logId: log._id,
|
|
2761
|
-
openaiEnvironment: resolvedEnvironment,
|
|
2762
|
-
repoTarget: repoTarget
|
|
2763
|
-
});
|
|
2764
|
-
if (!!this.config.githubToken) return [3 /*break*/, 2];
|
|
2765
|
-
return [4 /*yield*/, this.updateLog(log._id, {
|
|
2766
|
-
status: 'skipped',
|
|
2767
|
-
last_error: 'GitHub token not configured',
|
|
2768
|
-
last_result_at: new Date(),
|
|
2769
|
-
id_client: email.id_client,
|
|
2770
|
-
client_name: email.client_name,
|
|
2771
|
-
from_email: email.fromAddress,
|
|
2772
|
-
source_type: email.source_type,
|
|
2773
|
-
classification_reason: email.classification_reason || '',
|
|
2774
|
-
openai_environment: resolvedEnvironment
|
|
2775
|
-
})];
|
|
2776
|
-
case 1:
|
|
2777
|
-
updated = (_a.sent()) || log;
|
|
2778
|
-
return [2 /*return*/, {
|
|
2779
|
-
status: 'skipped',
|
|
2780
|
-
email: email,
|
|
2781
|
-
error: 'GitHub token not configured',
|
|
2782
|
-
log: updated,
|
|
2783
|
-
reason: 'missing_github_token'
|
|
2784
|
-
}];
|
|
2785
|
-
case 2:
|
|
2786
|
-
if (!!repoTarget) return [3 /*break*/, 4];
|
|
2787
|
-
return [4 /*yield*/, this.updateLog(log._id, {
|
|
2788
|
-
status: 'skipped',
|
|
2789
|
-
last_error: 'GitHub repository not configured',
|
|
2790
|
-
last_result_at: new Date(),
|
|
2791
|
-
id_client: email.id_client,
|
|
2792
|
-
client_name: email.client_name,
|
|
2793
|
-
from_email: email.fromAddress,
|
|
2794
|
-
source_type: email.source_type,
|
|
2795
|
-
classification_reason: email.classification_reason || '',
|
|
2796
|
-
openai_environment: resolvedEnvironment
|
|
2797
|
-
})];
|
|
2798
|
-
case 3:
|
|
2799
|
-
updated = (_a.sent()) || log;
|
|
2800
|
-
return [2 /*return*/, {
|
|
2801
|
-
status: 'skipped',
|
|
2802
|
-
email: email,
|
|
2803
|
-
error: 'GitHub repository not configured',
|
|
2804
|
-
log: updated,
|
|
2805
|
-
reason: 'missing_github_repo'
|
|
2806
|
-
}];
|
|
2807
|
-
case 4:
|
|
2808
|
-
effectiveEnv = "".concat(repoTarget.owner, "/").concat(repoTarget.repo);
|
|
2809
|
-
emailHash = email.issueHash || email.hash || this.generateIssueHash(email);
|
|
2810
|
-
rawHash = email.rawHash || this.generateRawEmailHash(email);
|
|
2811
|
-
workBranch = this.buildWorkBranch(emailHash);
|
|
2812
|
-
contextIdentifier = (emailHash || '').slice(0, 12) || 'autofix';
|
|
2813
|
-
contextPath = ".openai/error-context/".concat(contextIdentifier, ".md");
|
|
2814
|
-
normalizedBody = this.normalizeEmailText(email.body || '');
|
|
2815
|
-
contextContent = this.buildContextMarkdown(email, contextIdentifier, normalizedBody);
|
|
2816
|
-
commentBody = this.buildOpenAIComment(email, contextPath, normalizedBody);
|
|
2817
|
-
return [4 /*yield*/, this.updateLog(log._id, {
|
|
2818
|
-
status: 'in_progress',
|
|
2819
|
-
last_attempt_at: new Date(),
|
|
2820
|
-
branch_name: workBranch,
|
|
2821
|
-
pr_url: '',
|
|
2822
|
-
last_error: '',
|
|
2823
|
-
openai_environment: effectiveEnv,
|
|
2824
|
-
issue_hash: emailHash,
|
|
2825
|
-
email_hash: rawHash
|
|
2826
|
-
})];
|
|
2827
|
-
case 5:
|
|
2828
|
-
_a.sent();
|
|
2829
|
-
_a.label = 6;
|
|
2830
|
-
case 6:
|
|
2831
|
-
_a.trys.push([6, 16, , 18]);
|
|
2832
|
-
return [4 /*yield*/, this.resolveBaseBranch(repoTarget)];
|
|
2833
|
-
case 7:
|
|
2834
|
-
baseBranch = _a.sent();
|
|
2835
|
-
return [4 /*yield*/, this.getBranchSha(repoTarget, baseBranch)];
|
|
2836
|
-
case 8:
|
|
2837
|
-
baseSha = _a.sent();
|
|
2838
|
-
return [4 /*yield*/, this.ensureBranch(repoTarget, workBranch, baseBranch, baseSha)];
|
|
2839
|
-
case 9:
|
|
2840
|
-
_a.sent();
|
|
2841
|
-
return [4 /*yield*/, this.upsertContextFile(repoTarget, workBranch, contextPath, contextContent)];
|
|
2842
|
-
case 10:
|
|
2843
|
-
_a.sent();
|
|
2844
|
-
return [4 /*yield*/, this.findOpenPullRequest(repoTarget, workBranch, baseBranch)];
|
|
2845
|
-
case 11:
|
|
2846
|
-
pr = _a.sent();
|
|
2847
|
-
if (!!pr) return [3 /*break*/, 13];
|
|
2848
|
-
title = "AI Autofix: ".concat((email.subject || 'ResolveIO Error').slice(0, 180));
|
|
2849
|
-
bodyLines = [
|
|
2850
|
-
'This PR was opened automatically to let AI investigate the reported failure.',
|
|
2851
|
-
'',
|
|
2852
|
-
"Context file: `".concat(contextPath, "`")
|
|
2853
|
-
];
|
|
2854
|
-
return [4 /*yield*/, this.createPullRequest(repoTarget, workBranch, baseBranch, title, bodyLines.join('\n'))];
|
|
2855
|
-
case 12:
|
|
2856
|
-
pr = _a.sent();
|
|
2857
|
-
_a.label = 13;
|
|
2858
|
-
case 13: return [4 /*yield*/, this.commentOnPullRequest(repoTarget, pr.number, commentBody)];
|
|
2859
|
-
case 14:
|
|
2860
|
-
_a.sent();
|
|
2861
|
-
return [4 /*yield*/, this.updateLog(log._id, {
|
|
2862
|
-
status: 'success',
|
|
2863
|
-
branch_name: workBranch,
|
|
2864
|
-
pr_url: pr.html_url,
|
|
2865
|
-
plan_summary: email.subject,
|
|
2866
|
-
plan_body: commentBody,
|
|
2867
|
-
last_result_at: new Date(),
|
|
2868
|
-
id_client: email.id_client,
|
|
2869
|
-
client_name: email.client_name,
|
|
2870
|
-
from_email: email.fromAddress,
|
|
2871
|
-
source_type: email.source_type,
|
|
2872
|
-
classification_reason: email.classification_reason || '',
|
|
2873
|
-
openai_environment: effectiveEnv,
|
|
2874
|
-
issue_hash: emailHash,
|
|
2875
|
-
email_hash: rawHash
|
|
2876
|
-
})];
|
|
2877
|
-
case 15:
|
|
2878
|
-
updated = (_a.sent()) || log;
|
|
2879
|
-
return [2 /*return*/, {
|
|
2880
|
-
status: 'success',
|
|
2881
|
-
email: email,
|
|
2882
|
-
branchName: workBranch,
|
|
2883
|
-
prUrl: pr.html_url,
|
|
2884
|
-
log: updated,
|
|
2885
|
-
summary: email.subject,
|
|
2886
|
-
notes: "Context file: ".concat(contextPath)
|
|
2887
|
-
}];
|
|
2888
|
-
case 16:
|
|
2889
|
-
err_6 = _a.sent();
|
|
2890
|
-
message = (err_6 === null || err_6 === void 0 ? void 0 : err_6.message) || 'GitHub workflow failed.';
|
|
2891
|
-
return [4 /*yield*/, this.updateLog(log._id, {
|
|
2892
|
-
status: 'failed',
|
|
2893
|
-
last_error: message,
|
|
2894
|
-
last_result_at: new Date(),
|
|
2895
|
-
id_client: email.id_client,
|
|
2896
|
-
client_name: email.client_name,
|
|
2897
|
-
from_email: email.fromAddress,
|
|
2898
|
-
source_type: email.source_type,
|
|
2899
|
-
classification_reason: email.classification_reason || '',
|
|
2900
|
-
openai_environment: effectiveEnv,
|
|
2901
|
-
issue_hash: emailHash,
|
|
2902
|
-
email_hash: rawHash
|
|
2903
|
-
})];
|
|
2904
|
-
case 17:
|
|
2905
|
-
updated = (_a.sent()) || log;
|
|
2906
|
-
return [2 /*return*/, {
|
|
2907
|
-
status: 'failed',
|
|
2908
|
-
email: email,
|
|
2909
|
-
error: message,
|
|
2910
|
-
log: updated
|
|
2911
|
-
}];
|
|
2912
|
-
case 18: return [2 /*return*/];
|
|
2913
|
-
}
|
|
2914
|
-
});
|
|
2915
|
-
});
|
|
2916
|
-
};
|
|
2917
|
-
ErrorAutoFixManager.prototype.notify = function (result) {
|
|
2918
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2919
|
-
var recipients, subject, bodyLines, logId, summary, reason, textBody, recipients_3, recipients_3_1, email, e_7_1;
|
|
2920
|
-
var e_7, _a;
|
|
2921
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2922
|
-
return __generator(this, function (_l) {
|
|
2923
|
-
switch (_l.label) {
|
|
2924
|
-
case 0:
|
|
2925
|
-
if (result.status === 'in_progress') {
|
|
2926
|
-
return [2 /*return*/];
|
|
2927
|
-
}
|
|
2928
|
-
if (result.status === 'skipped' && result.reason && !this.shouldNotifySkip(result.reason)) {
|
|
2929
|
-
return [2 /*return*/];
|
|
2930
|
-
}
|
|
2931
|
-
recipients = this.config.notifyEmails.length
|
|
2932
|
-
? this.config.notifyEmails
|
|
2933
|
-
: (result.status === 'failed' ? [DEFAULT_ERROR_ALERT_EMAIL] : []);
|
|
2934
|
-
if (!recipients.length) {
|
|
2935
|
-
return [2 /*return*/];
|
|
2936
|
-
}
|
|
2937
|
-
subject = '';
|
|
2938
|
-
bodyLines = [];
|
|
2939
|
-
logId = ((_b = result.log) === null || _b === void 0 ? void 0 : _b._id) || '';
|
|
2940
|
-
summary = result.summary || ((_c = result.log) === null || _c === void 0 ? void 0 : _c.plan_summary) || result.email.subject;
|
|
2941
|
-
if (result.status === 'success') {
|
|
2942
|
-
subject = "ResolveIO AutoFix \u2714 ".concat(summary);
|
|
2943
|
-
bodyLines = [
|
|
2944
|
-
'Auto-fix workflow completed successfully.',
|
|
2945
|
-
"Client: ".concat(((_d = result.log) === null || _d === void 0 ? void 0 : _d.client_name) || result.email.client_name || 'Unknown'),
|
|
2946
|
-
"Source: ".concat(((_e = result.log) === null || _e === void 0 ? void 0 : _e.source_type) || result.email.source_type || 'app'),
|
|
2947
|
-
'',
|
|
2948
|
-
"Branch: ".concat(result.branchName || 'unknown'),
|
|
2949
|
-
"PR: ".concat(result.prUrl || 'pending'),
|
|
2950
|
-
'',
|
|
2951
|
-
'Summary:',
|
|
2952
|
-
summary || '(none)',
|
|
2953
|
-
''
|
|
2954
|
-
];
|
|
2955
|
-
if (result.notes) {
|
|
2956
|
-
bodyLines.push("Notes: ".concat(result.notes), '');
|
|
2957
|
-
}
|
|
2958
|
-
if (logId) {
|
|
2959
|
-
bodyLines.push("Log ID: ".concat(logId));
|
|
2960
|
-
}
|
|
2961
|
-
}
|
|
2962
|
-
else if (result.status === 'failed') {
|
|
2963
|
-
subject = "ResolveIO AutoFix \u2716 ".concat(summary);
|
|
2964
|
-
bodyLines = [
|
|
2965
|
-
'Auto-fix workflow failed.',
|
|
2966
|
-
"Reason: ".concat(result.error || ((_f = result.log) === null || _f === void 0 ? void 0 : _f.last_error) || 'Unknown error'),
|
|
2967
|
-
"Client: ".concat(((_g = result.log) === null || _g === void 0 ? void 0 : _g.client_name) || result.email.client_name || 'Unknown'),
|
|
2968
|
-
"Source: ".concat(((_h = result.log) === null || _h === void 0 ? void 0 : _h.source_type) || result.email.source_type || 'app'),
|
|
2969
|
-
'',
|
|
2970
|
-
'Email Subject:',
|
|
2971
|
-
result.email.subject
|
|
2972
|
-
];
|
|
2973
|
-
if (logId) {
|
|
2974
|
-
bodyLines.push('', "Log ID: ".concat(logId));
|
|
2975
|
-
}
|
|
2976
|
-
}
|
|
2977
|
-
else {
|
|
2978
|
-
subject = "ResolveIO AutoFix \u26A0 ".concat(result.email.subject);
|
|
2979
|
-
reason = result.reason || 'skipped';
|
|
2980
|
-
bodyLines = [
|
|
2981
|
-
"Auto-fix skipped. Reason: ".concat(reason, "."),
|
|
2982
|
-
result.error && result.error !== reason ? "Details: ".concat(result.error) : '',
|
|
2983
|
-
"Client: ".concat(((_j = result.log) === null || _j === void 0 ? void 0 : _j.client_name) || result.email.client_name || 'Unknown'),
|
|
2984
|
-
"Source: ".concat(((_k = result.log) === null || _k === void 0 ? void 0 : _k.source_type) || result.email.source_type || 'app'),
|
|
2985
|
-
''
|
|
2986
|
-
];
|
|
2987
|
-
if (logId) {
|
|
2988
|
-
bodyLines.push("Log ID: ".concat(logId));
|
|
2989
|
-
}
|
|
2990
|
-
bodyLines.push('Update or remove the log entry to retry processing.');
|
|
2991
|
-
}
|
|
2992
|
-
textBody = bodyLines.filter(function (line) { return line !== undefined && line !== null && line !== ''; }).join('\n');
|
|
2993
|
-
_l.label = 1;
|
|
2994
|
-
case 1:
|
|
2995
|
-
_l.trys.push([1, 6, 7, 8]);
|
|
2996
|
-
recipients_3 = __values(recipients), recipients_3_1 = recipients_3.next();
|
|
2997
|
-
_l.label = 2;
|
|
2998
|
-
case 2:
|
|
2999
|
-
if (!!recipients_3_1.done) return [3 /*break*/, 5];
|
|
3000
|
-
email = recipients_3_1.value;
|
|
3001
|
-
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().sendEmail(email, subject, textBody)];
|
|
3002
|
-
case 3:
|
|
3003
|
-
_l.sent();
|
|
3004
|
-
_l.label = 4;
|
|
3005
|
-
case 4:
|
|
3006
|
-
recipients_3_1 = recipients_3.next();
|
|
3007
|
-
return [3 /*break*/, 2];
|
|
3008
|
-
case 5: return [3 /*break*/, 8];
|
|
3009
|
-
case 6:
|
|
3010
|
-
e_7_1 = _l.sent();
|
|
3011
|
-
e_7 = { error: e_7_1 };
|
|
3012
|
-
return [3 /*break*/, 8];
|
|
3013
|
-
case 7:
|
|
3014
|
-
try {
|
|
3015
|
-
if (recipients_3_1 && !recipients_3_1.done && (_a = recipients_3.return)) _a.call(recipients_3);
|
|
3016
|
-
}
|
|
3017
|
-
finally { if (e_7) throw e_7.error; }
|
|
3018
|
-
return [7 /*endfinally*/];
|
|
3019
|
-
case 8: return [2 /*return*/];
|
|
3020
|
-
}
|
|
3021
|
-
});
|
|
3022
|
-
});
|
|
3023
|
-
};
|
|
3024
|
-
ErrorAutoFixManager.APP_SETTINGS_CACHE_TTL_MS = 10000;
|
|
3025
|
-
return ErrorAutoFixManager;
|
|
3026
|
-
}());
|
|
3027
|
-
exports.ErrorAutoFixManager = ErrorAutoFixManager;
|
|
3028
|
-
function ensureErrorAutoFixManager(serverConfig) {
|
|
3029
|
-
var existing = resolveio_server_app_1.ResolveIOServer['AutoFixManager'];
|
|
3030
|
-
if (existing) {
|
|
3031
|
-
return existing;
|
|
3032
|
-
}
|
|
3033
|
-
if (!configuredErrorAutoFixDependencies) {
|
|
3034
|
-
return null;
|
|
3035
|
-
}
|
|
3036
|
-
var resolvedServerConfig = serverConfig || resolveio_server_app_1.ResolveIOServer.getServerConfig();
|
|
3037
|
-
if (!resolvedServerConfig) {
|
|
3038
|
-
return null;
|
|
3039
|
-
}
|
|
3040
|
-
var manager = new ErrorAutoFixManager(resolvedServerConfig);
|
|
3041
|
-
resolveio_server_app_1.ResolveIOServer['AutoFixManager'] = manager;
|
|
3042
|
-
return manager;
|
|
3043
|
-
}
|
|
3044
|
-
function reportDevError(options) {
|
|
3045
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3046
|
-
var manager;
|
|
3047
|
-
return __generator(this, function (_a) {
|
|
3048
|
-
switch (_a.label) {
|
|
3049
|
-
case 0:
|
|
3050
|
-
manager = ensureErrorAutoFixManager();
|
|
3051
|
-
if (!manager) {
|
|
3052
|
-
console.warn('AutoFix manager not initialized for dev alert', options === null || options === void 0 ? void 0 : options.subject);
|
|
3053
|
-
return [2 /*return*/];
|
|
3054
|
-
}
|
|
3055
|
-
return [4 /*yield*/, manager.reportDevError(options)];
|
|
3056
|
-
case 1:
|
|
3057
|
-
_a.sent();
|
|
3058
|
-
return [2 /*return*/];
|
|
3059
|
-
}
|
|
3060
|
-
});
|
|
3061
|
-
});
|
|
3062
|
-
}
|
|
3063
|
-
|
|
3064
|
-
//# sourceMappingURL=error-auto-fix.manager.js.map
|