@resolveio/server-lib 22.3.221 → 22.3.222
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/ai/assistant-core-heuristics.d.ts +11 -0
- package/ai/assistant-core-heuristics.js +356 -0
- package/ai/assistant-core-heuristics.js.map +1 -0
- package/ai/resolveio-platform-intelligence-memory-corpus.d.ts +3 -0
- package/ai/resolveio-platform-intelligence-memory-corpus.js +214 -0
- package/ai/resolveio-platform-intelligence-memory-corpus.js.map +1 -0
- package/ai/resolveio-platform-intelligence-memory.d.ts +20 -0
- package/ai/resolveio-platform-intelligence-memory.js +341 -0
- package/ai/resolveio-platform-intelligence-memory.js.map +1 -0
- package/{src/ai/resolveio-platform-intelligence-types.ts → ai/resolveio-platform-intelligence-types.d.ts} +15 -20
- package/ai/resolveio-platform-intelligence-types.js +4 -0
- package/ai/resolveio-platform-intelligence-types.js.map +1 -0
- package/ai/resolveio-platform-intelligence.d.ts +6 -0
- package/ai/resolveio-platform-intelligence.js +463 -0
- package/ai/resolveio-platform-intelligence.js.map +1 -0
- package/client-server-app.d.ts +1 -0
- package/client-server-app.js +68 -0
- package/client-server-app.js.map +1 -0
- package/collections/ai-run.collection.d.ts +3 -0
- package/collections/ai-run.collection.js +170 -0
- package/collections/ai-run.collection.js.map +1 -0
- package/collections/ai-terminal-conversation.collection.d.ts +2 -0
- package/collections/ai-terminal-conversation.collection.js +140 -0
- package/collections/ai-terminal-conversation.collection.js.map +1 -0
- package/collections/ai-terminal-issue-report.collection.d.ts +2 -0
- package/collections/ai-terminal-issue-report.collection.js +148 -0
- package/collections/ai-terminal-issue-report.collection.js.map +1 -0
- package/collections/ai-terminal-message.collection.d.ts +2 -0
- package/collections/ai-terminal-message.collection.js +121 -0
- package/collections/ai-terminal-message.collection.js.map +1 -0
- package/collections/app-setting.collection.d.ts +3 -0
- package/collections/app-setting.collection.js +103 -0
- package/collections/app-setting.collection.js.map +1 -0
- package/collections/app-status.collection.d.ts +3 -0
- package/collections/app-status.collection.js +57 -0
- package/collections/app-status.collection.js.map +1 -0
- package/collections/communication-metric.collection.d.ts +2 -0
- package/collections/communication-metric.collection.js +133 -0
- package/collections/communication-metric.collection.js.map +1 -0
- package/collections/counter.collection.d.ts +3 -0
- package/collections/counter.collection.js +56 -0
- package/collections/counter.collection.js.map +1 -0
- package/collections/cron-job-history.collection.d.ts +3 -0
- package/collections/cron-job-history.collection.js +137 -0
- package/collections/cron-job-history.collection.js.map +1 -0
- package/collections/cron-job.collection.d.ts +3 -0
- package/collections/cron-job.collection.js +92 -0
- package/collections/cron-job.collection.js.map +1 -0
- package/collections/customer-notification.collection.d.ts +3 -0
- package/collections/customer-notification.collection.js +130 -0
- package/collections/customer-notification.collection.js.map +1 -0
- package/collections/customer-portal-password.collection.d.ts +3 -0
- package/collections/customer-portal-password.collection.js +75 -0
- package/collections/customer-portal-password.collection.js.map +1 -0
- package/collections/email-history.collection.d.ts +3 -0
- package/collections/email-history.collection.js +134 -0
- package/collections/email-history.collection.js.map +1 -0
- package/collections/email-verified.collection.d.ts +3 -0
- package/collections/email-verified.collection.js +62 -0
- package/collections/email-verified.collection.js.map +1 -0
- package/collections/file.collection.d.ts +3 -0
- package/collections/file.collection.js +74 -0
- package/collections/file.collection.js.map +1 -0
- package/collections/flag-update.collection.d.ts +3 -0
- package/collections/flag-update.collection.js +57 -0
- package/collections/flag-update.collection.js.map +1 -0
- package/collections/flag.collection.d.ts +3 -0
- package/collections/flag.collection.js +57 -0
- package/collections/flag.collection.js.map +1 -0
- package/collections/log-method-latency.collection.d.ts +3 -0
- package/collections/log-method-latency.collection.js +77 -0
- package/collections/log-method-latency.collection.js.map +1 -0
- package/collections/log-subscription.collection.d.ts +3 -0
- package/collections/log-subscription.collection.js +80 -0
- package/collections/log-subscription.collection.js.map +1 -0
- package/collections/log.collection.d.ts +3 -0
- package/collections/log.collection.js +93 -0
- package/collections/log.collection.js.map +1 -0
- package/collections/logged-in-users.collection.d.ts +3 -0
- package/collections/logged-in-users.collection.js +67 -0
- package/collections/logged-in-users.collection.js.map +1 -0
- package/collections/monitor-cpu.collection.d.ts +3 -0
- package/collections/monitor-cpu.collection.js +65 -0
- package/collections/monitor-cpu.collection.js.map +1 -0
- package/collections/monitor-function.collection.d.ts +3 -0
- package/collections/monitor-function.collection.js +74 -0
- package/collections/monitor-function.collection.js.map +1 -0
- package/collections/monitor-memory.collection.d.ts +3 -0
- package/collections/monitor-memory.collection.js +77 -0
- package/collections/monitor-memory.collection.js.map +1 -0
- package/collections/monitor-mongo.collection.d.ts +3 -0
- package/collections/monitor-mongo.collection.js +71 -0
- package/collections/monitor-mongo.collection.js.map +1 -0
- package/collections/notification.collection.d.ts +3 -0
- package/collections/notification.collection.js +57 -0
- package/collections/notification.collection.js.map +1 -0
- package/collections/openai-usage-ledger.collection.d.ts +2 -0
- package/collections/openai-usage-ledger.collection.js +188 -0
- package/collections/openai-usage-ledger.collection.js.map +1 -0
- package/collections/report-builder-dashboard-builder.collection.d.ts +3 -0
- package/collections/report-builder-dashboard-builder.collection.js +109 -0
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -0
- package/collections/report-builder-library.collection.d.ts +3 -0
- package/collections/report-builder-library.collection.js +87 -0
- package/collections/report-builder-library.collection.js.map +1 -0
- package/collections/report-builder-report.collection.d.ts +4 -0
- package/collections/report-builder-report.collection.js +184 -0
- package/collections/report-builder-report.collection.js.map +1 -0
- package/collections/user-group.collection.d.ts +4 -0
- package/collections/user-group.collection.js +89 -0
- package/collections/user-group.collection.js.map +1 -0
- package/collections/user-guide.collection.d.ts +3 -0
- package/collections/user-guide.collection.js +57 -0
- package/collections/user-guide.collection.js.map +1 -0
- package/collections/user.collection.d.ts +4 -0
- package/collections/user.collection.js +180 -0
- package/collections/user.collection.js.map +1 -0
- package/cron/cron.d.ts +14 -0
- package/cron/cron.js +216 -0
- package/cron/cron.js.map +1 -0
- package/fixtures/cron-jobs.d.ts +1 -0
- package/fixtures/cron-jobs.js +150 -0
- package/fixtures/cron-jobs.js.map +1 -0
- package/fixtures/init.d.ts +1 -0
- package/fixtures/init.js +91 -0
- package/fixtures/init.js.map +1 -0
- package/http/auth.d.ts +2 -0
- package/http/auth.js +951 -0
- package/http/auth.js.map +1 -0
- package/http/health.d.ts +1 -0
- package/http/health.js +11 -0
- package/http/health.js.map +1 -0
- package/http/home.d.ts +1 -0
- package/http/home.js +134 -0
- package/http/home.js.map +1 -0
- package/http/slow-query-publication.d.ts +2 -0
- package/http/slow-query-publication.js +99 -0
- package/http/slow-query-publication.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +19 -0
- package/index.js.map +1 -0
- package/managers/ai-assistant-codex-manager.manager.d.ts +67 -0
- package/managers/ai-assistant-codex-manager.manager.js +1113 -0
- package/managers/ai-assistant-codex-manager.manager.js.map +1 -0
- package/managers/ai-run-evidence.manager.d.ts +36 -0
- package/managers/ai-run-evidence.manager.js +377 -0
- package/managers/ai-run-evidence.manager.js.map +1 -0
- package/managers/communication-metric.manager.d.ts +16 -0
- package/managers/communication-metric.manager.js +134 -0
- package/managers/communication-metric.manager.js.map +1 -0
- package/managers/cron.manager.d.ts +20 -0
- package/managers/cron.manager.js +534 -0
- package/managers/cron.manager.js.map +1 -0
- package/managers/customer-notification-content.manager.d.ts +55 -0
- package/managers/customer-notification-content.manager.js +158 -0
- package/managers/customer-notification-content.manager.js.map +1 -0
- package/managers/diagnostic-manager-bootstrap.d.ts +9 -0
- package/managers/diagnostic-manager-bootstrap.js +260 -0
- package/managers/diagnostic-manager-bootstrap.js.map +1 -0
- package/managers/error-auto-fix.manager.d.ts +149 -0
- package/managers/error-auto-fix.manager.js +3064 -0
- package/managers/error-auto-fix.manager.js.map +1 -0
- package/managers/local-log.manager.d.ts +18 -0
- package/managers/local-log.manager.js +88 -0
- package/managers/local-log.manager.js.map +1 -0
- package/managers/method.manager.d.ts +84 -0
- package/managers/method.manager.js +1964 -0
- package/managers/method.manager.js.map +1 -0
- package/managers/mongo.manager.d.ts +224 -0
- package/managers/mongo.manager.js +5000 -0
- package/managers/mongo.manager.js.map +1 -0
- package/managers/monitor.manager.d.ts +70 -0
- package/managers/monitor.manager.js +550 -0
- package/managers/monitor.manager.js.map +1 -0
- package/managers/openai-usage-ledger.manager.d.ts +30 -0
- package/managers/openai-usage-ledger.manager.js +142 -0
- package/managers/openai-usage-ledger.manager.js.map +1 -0
- package/managers/slow-query-verifier.manager.d.ts +144 -0
- package/managers/slow-query-verifier.manager.js +3857 -0
- package/managers/slow-query-verifier.manager.js.map +1 -0
- package/managers/slow-query.manager.d.ts +28 -0
- package/managers/slow-query.manager.js +468 -0
- package/managers/slow-query.manager.js.map +1 -0
- package/managers/subscription.manager.d.ts +169 -0
- package/managers/subscription.manager.js +3434 -0
- package/managers/subscription.manager.js.map +1 -0
- package/managers/websocket.manager.d.ts +73 -0
- package/managers/websocket.manager.js +673 -0
- package/managers/websocket.manager.js.map +1 -0
- package/managers/worker-dispatcher.manager.d.ts +120 -0
- package/managers/worker-dispatcher.manager.js +1266 -0
- package/managers/worker-dispatcher.manager.js.map +1 -0
- package/managers/worker-server.manager.d.ts +35 -0
- package/managers/worker-server.manager.js +582 -0
- package/managers/worker-server.manager.js.map +1 -0
- package/methods/accounts.d.ts +2 -0
- package/methods/accounts.js +624 -0
- package/methods/accounts.js.map +1 -0
- package/methods/ai-terminal.d.ts +458 -0
- package/methods/ai-terminal.js +27991 -0
- package/methods/ai-terminal.js.map +1 -0
- package/methods/app-settings.d.ts +2 -0
- package/methods/app-settings.js +169 -0
- package/methods/app-settings.js.map +1 -0
- package/methods/aws.d.ts +2 -0
- package/methods/aws.js +877 -0
- package/methods/aws.js.map +1 -0
- package/methods/collections.d.ts +2 -0
- package/methods/collections.js +719 -0
- package/methods/collections.js.map +1 -0
- package/methods/counters.d.ts +2 -0
- package/methods/counters.js +113 -0
- package/methods/counters.js.map +1 -0
- package/methods/cron-jobs.d.ts +2 -0
- package/methods/cron-jobs.js +2475 -0
- package/methods/cron-jobs.js.map +1 -0
- package/methods/customer-notifications.d.ts +2 -0
- package/methods/customer-notifications.js +528 -0
- package/methods/customer-notifications.js.map +1 -0
- package/methods/diagnostics.d.ts +2 -0
- package/methods/diagnostics.js +703 -0
- package/methods/diagnostics.js.map +1 -0
- package/methods/flag-updates.d.ts +2 -0
- package/methods/flag-updates.js +8 -0
- package/methods/flag-updates.js.map +1 -0
- package/methods/flags.d.ts +2 -0
- package/methods/flags.js +8 -0
- package/methods/flags.js.map +1 -0
- package/methods/logs.d.ts +2 -0
- package/methods/logs.js +751 -0
- package/methods/logs.js.map +1 -0
- package/methods/mongo-explorer.d.ts +2 -0
- package/methods/mongo-explorer.js +1808 -0
- package/methods/mongo-explorer.js.map +1 -0
- package/methods/monitor.d.ts +2 -0
- package/methods/monitor.js +543 -0
- package/methods/monitor.js.map +1 -0
- package/methods/pdf.d.ts +2 -0
- package/methods/pdf.js +1216 -0
- package/methods/pdf.js.map +1 -0
- package/methods/publications.d.ts +1 -0
- package/methods/publications.js +183 -0
- package/methods/publications.js.map +1 -0
- package/methods/report-builder.d.ts +2 -0
- package/methods/report-builder.js +3094 -0
- package/methods/report-builder.js.map +1 -0
- package/methods/support.d.ts +2 -0
- package/methods/support.js +430 -0
- package/methods/support.js.map +1 -0
- package/models/ai-run.model.d.ts +19 -0
- package/models/ai-run.model.js +4 -0
- package/models/ai-run.model.js.map +1 -0
- package/models/ai-terminal-conversation.model.d.ts +17 -0
- package/models/ai-terminal-conversation.model.js +4 -0
- package/models/ai-terminal-conversation.model.js.map +1 -0
- package/models/ai-terminal-issue-report.model.d.ts +19 -0
- package/models/ai-terminal-issue-report.model.js +4 -0
- package/models/ai-terminal-issue-report.model.js.map +1 -0
- package/models/ai-terminal-message.model.d.ts +22 -0
- package/models/ai-terminal-message.model.js +4 -0
- package/models/ai-terminal-message.model.js.map +1 -0
- package/models/app-setting.model.d.ts +16 -0
- package/models/app-setting.model.js +4 -0
- package/models/app-setting.model.js.map +1 -0
- package/{src/models/app-status.model.ts → models/app-status.model.d.ts} +2 -3
- package/models/app-status.model.js +4 -0
- package/models/app-status.model.js.map +1 -0
- package/{src/models/billing-logged-in-users.model.ts → models/billing-logged-in-users.model.d.ts} +4 -5
- package/models/billing-logged-in-users.model.js +4 -0
- package/models/billing-logged-in-users.model.js.map +1 -0
- package/models/collection-document.model.d.ts +21 -0
- package/models/collection-document.model.js +4 -0
- package/models/collection-document.model.js.map +1 -0
- package/models/communication-metric.model.d.ts +20 -0
- package/models/communication-metric.model.js +4 -0
- package/models/communication-metric.model.js.map +1 -0
- package/{src/models/counter.model.ts → models/counter.model.d.ts} +3 -4
- package/models/counter.model.js +4 -0
- package/models/counter.model.js.map +1 -0
- package/models/cron-job-history.model.d.ts +15 -0
- package/models/cron-job-history.model.js +4 -0
- package/models/cron-job-history.model.js.map +1 -0
- package/models/cron-job.model.d.ts +14 -0
- package/models/cron-job.model.js +4 -0
- package/models/cron-job.model.js.map +1 -0
- package/models/customer-notification.model.d.ts +26 -0
- package/models/customer-notification.model.js +4 -0
- package/models/customer-notification.model.js.map +1 -0
- package/models/customer-portal-password.model.d.ts +11 -0
- package/models/customer-portal-password.model.js +4 -0
- package/models/customer-portal-password.model.js.map +1 -0
- package/models/dialog.model.d.ts +23 -0
- package/models/dialog.model.js +4 -0
- package/models/dialog.model.js.map +1 -0
- package/models/email-history.model.d.ts +32 -0
- package/{src/models/email-history.model.ts → models/email-history.model.js} +4 -36
- package/models/email-history.model.js.map +1 -0
- package/{src/models/email-verified.model.ts → models/email-verified.model.d.ts} +5 -6
- package/models/email-verified.model.js +4 -0
- package/models/email-verified.model.js.map +1 -0
- package/{src/models/file.model.ts → models/file.model.d.ts} +7 -8
- package/models/file.model.js +4 -0
- package/models/file.model.js.map +1 -0
- package/{src/models/flag-update.model.ts → models/flag-update.model.d.ts} +3 -4
- package/models/flag-update.model.js +4 -0
- package/models/flag-update.model.js.map +1 -0
- package/{src/models/flag.model.ts → models/flag.model.d.ts} +3 -4
- package/models/flag.model.js +4 -0
- package/models/flag.model.js.map +1 -0
- package/models/log-method-latency.model.d.ts +10 -0
- package/models/log-method-latency.model.js +4 -0
- package/models/log-method-latency.model.js.map +1 -0
- package/{src/models/log-subscription.model.ts → models/log-subscription.model.d.ts} +9 -11
- package/models/log-subscription.model.js +4 -0
- package/models/log-subscription.model.js.map +1 -0
- package/models/log.model.d.ts +17 -0
- package/models/log.model.js +4 -0
- package/models/log.model.js.map +1 -0
- package/{src/models/logged-in-users.model.ts → models/logged-in-users.model.d.ts} +5 -6
- package/models/logged-in-users.model.js +4 -0
- package/models/logged-in-users.model.js.map +1 -0
- package/{src/models/method-response.model.ts → models/method-response.model.d.ts} +6 -7
- package/models/method-response.model.js +4 -0
- package/models/method-response.model.js.map +1 -0
- package/models/method.model.d.ts +26 -0
- package/models/method.model.js +4 -0
- package/models/method.model.js.map +1 -0
- package/{src/models/monitor-cpu.model.ts → models/monitor-cpu.model.d.ts} +7 -9
- package/models/monitor-cpu.model.js +4 -0
- package/models/monitor-cpu.model.js.map +1 -0
- package/models/monitor-function.model.d.ts +14 -0
- package/models/monitor-function.model.js +4 -0
- package/models/monitor-function.model.js.map +1 -0
- package/models/monitor-memory.model.d.ts +15 -0
- package/models/monitor-memory.model.js +4 -0
- package/models/monitor-memory.model.js.map +1 -0
- package/models/monitor-mongo.model.d.ts +13 -0
- package/models/monitor-mongo.model.js +4 -0
- package/models/monitor-mongo.model.js.map +1 -0
- package/{src/models/notification.model.ts → models/notification.model.d.ts} +4 -6
- package/models/notification.model.js +4 -0
- package/models/notification.model.js.map +1 -0
- package/models/openai-usage-ledger.model.d.ts +30 -0
- package/models/openai-usage-ledger.model.js +4 -0
- package/models/openai-usage-ledger.model.js.map +1 -0
- package/models/pagination.model.d.ts +11 -0
- package/models/pagination.model.js +28 -0
- package/models/pagination.model.js.map +1 -0
- package/models/permission.model.d.ts +12 -0
- package/models/permission.model.js +4 -0
- package/models/permission.model.js.map +1 -0
- package/models/report-builder-dashboard-builder.model.d.ts +25 -0
- package/models/report-builder-dashboard-builder.model.js +4 -0
- package/models/report-builder-dashboard-builder.model.js.map +1 -0
- package/models/report-builder-library.model.d.ts +17 -0
- package/models/report-builder-library.model.js +4 -0
- package/models/report-builder-library.model.js.map +1 -0
- package/models/report-builder-report.model.d.ts +121 -0
- package/models/report-builder-report.model.js +4 -0
- package/models/report-builder-report.model.js.map +1 -0
- package/models/report-builder.model.d.ts +61 -0
- package/models/report-builder.model.js +4 -0
- package/models/report-builder.model.js.map +1 -0
- package/models/select-data-label.model.d.ts +9 -0
- package/models/select-data-label.model.js +4 -0
- package/models/select-data-label.model.js.map +1 -0
- package/models/server-message.model.d.ts +32 -0
- package/models/server-message.model.js +4 -0
- package/models/server-message.model.js.map +1 -0
- package/models/slow-query-report.model.d.ts +23 -0
- package/models/slow-query-report.model.js +4 -0
- package/models/slow-query-report.model.js.map +1 -0
- package/models/subscription.model.d.ts +31 -0
- package/models/subscription.model.js +4 -0
- package/models/subscription.model.js.map +1 -0
- package/models/support-ticket.model.d.ts +87 -0
- package/models/support-ticket.model.js +4 -0
- package/models/support-ticket.model.js.map +1 -0
- package/models/user-group.model.d.ts +20 -0
- package/models/user-group.model.js +4 -0
- package/models/user-group.model.js.map +1 -0
- package/{src/models/user-guide.model.ts → models/user-guide.model.d.ts} +4 -5
- package/models/user-guide.model.js +4 -0
- package/models/user-guide.model.js.map +1 -0
- package/models/user.model.d.ts +84 -0
- package/models/user.model.js +4 -0
- package/models/user.model.js.map +1 -0
- package/package.json +1 -1
- package/private/images/ResolveIO.png +0 -0
- package/public_api.js +127 -0
- package/public_api.js.map +1 -0
- package/publications/ai-terminal.d.ts +1 -0
- package/publications/ai-terminal.js +122 -0
- package/publications/ai-terminal.js.map +1 -0
- package/publications/app-settings.d.ts +2 -0
- package/publications/app-settings.js +28 -0
- package/publications/app-settings.js.map +1 -0
- package/publications/app-status.d.ts +2 -0
- package/publications/app-status.js +16 -0
- package/publications/app-status.js.map +1 -0
- package/publications/cron-jobs.d.ts +2 -0
- package/publications/cron-jobs.js +88 -0
- package/publications/cron-jobs.js.map +1 -0
- package/publications/customer-notifications.d.ts +2 -0
- package/publications/customer-notifications.js +161 -0
- package/publications/customer-notifications.js.map +1 -0
- package/publications/files.d.ts +2 -0
- package/publications/files.js +36 -0
- package/publications/files.js.map +1 -0
- package/publications/flags-update.d.ts +2 -0
- package/publications/flags-update.js +22 -0
- package/publications/flags-update.js.map +1 -0
- package/publications/flags.d.ts +2 -0
- package/publications/flags.js +22 -0
- package/publications/flags.js.map +1 -0
- package/publications/logs.d.ts +2 -0
- package/publications/logs.js +164 -0
- package/publications/logs.js.map +1 -0
- package/publications/notifications.d.ts +2 -0
- package/publications/notifications.js +16 -0
- package/publications/notifications.js.map +1 -0
- package/publications/report-builder-dashboard-builders.d.ts +2 -0
- package/publications/report-builder-dashboard-builders.js +42 -0
- package/publications/report-builder-dashboard-builders.js.map +1 -0
- package/publications/report-builder-libraries.d.ts +2 -0
- package/publications/report-builder-libraries.js +90 -0
- package/publications/report-builder-libraries.js.map +1 -0
- package/publications/report-builder-reports.d.ts +2 -0
- package/publications/report-builder-reports.js +50 -0
- package/publications/report-builder-reports.js.map +1 -0
- package/publications/super-admin.d.ts +2 -0
- package/publications/super-admin.js +16 -0
- package/publications/super-admin.js.map +1 -0
- package/publications/user-groups.d.ts +1 -0
- package/publications/user-groups.js +16 -0
- package/publications/user-groups.js.map +1 -0
- package/publications/user-guides.d.ts +1 -0
- package/publications/user-guides.js +16 -0
- package/publications/user-guides.js.map +1 -0
- package/resolveio-server-app.d.ts +70 -0
- package/resolveio-server-app.js +801 -0
- package/resolveio-server-app.js.map +1 -0
- package/server-app.d.ts +228 -0
- package/server-app.js +3566 -0
- package/server-app.js.map +1 -0
- package/services/codex-client.d.ts +128 -0
- package/services/codex-client.js +1629 -0
- package/services/codex-client.js.map +1 -0
- package/services/openai-client.d.ts +46 -0
- package/services/openai-client.js +318 -0
- package/services/openai-client.js.map +1 -0
- package/types/error-report.d.ts +25 -0
- package/types/error-report.js +4 -0
- package/types/error-report.js.map +1 -0
- package/types/slow-query-report.d.ts +27 -0
- package/types/slow-query-report.js +6 -0
- package/types/slow-query-report.js.map +1 -0
- package/util/ai-qa-policy.d.ts +124 -0
- package/util/ai-qa-policy.js +736 -0
- package/util/ai-qa-policy.js.map +1 -0
- package/util/ai-run-evidence-adapters.d.ts +109 -0
- package/util/ai-run-evidence-adapters.js +7234 -0
- package/util/ai-run-evidence-adapters.js.map +1 -0
- package/util/ai-run-evidence-dashboard.d.ts +88 -0
- package/util/ai-run-evidence-dashboard.js +343 -0
- package/util/ai-run-evidence-dashboard.js.map +1 -0
- package/util/ai-run-evidence-eval.d.ts +86 -0
- package/util/ai-run-evidence-eval.js +1018 -0
- package/util/ai-run-evidence-eval.js.map +1 -0
- package/util/ai-run-evidence.d.ts +244 -0
- package/util/ai-run-evidence.js +1096 -0
- package/util/ai-run-evidence.js.map +1 -0
- package/util/ai-runner-artifacts.d.ts +82 -0
- package/util/ai-runner-artifacts.js +713 -0
- package/util/ai-runner-artifacts.js.map +1 -0
- package/util/ai-runner-manager-autopilot.d.ts +210 -0
- package/util/ai-runner-manager-autopilot.js +642 -0
- package/util/ai-runner-manager-autopilot.js.map +1 -0
- package/util/ai-runner-manager-policy.d.ts +807 -0
- package/util/ai-runner-manager-policy.js +3501 -0
- package/util/ai-runner-manager-policy.js.map +1 -0
- package/util/ai-runner-qa-auth.d.ts +5 -0
- package/util/ai-runner-qa-auth.js +839 -0
- package/util/ai-runner-qa-auth.js.map +1 -0
- package/util/ai-runner-qa-tools.d.ts +26 -0
- package/util/ai-runner-qa-tools.js +3520 -0
- package/util/ai-runner-qa-tools.js.map +1 -0
- package/util/aicoder-runner-v6.d.ts +426 -0
- package/util/aicoder-runner-v6.js +2464 -0
- package/util/aicoder-runner-v6.js.map +1 -0
- package/util/common.d.ts +31 -0
- package/util/common.js +683 -0
- package/util/common.js.map +1 -0
- package/util/customer-portal-password.d.ts +13 -0
- package/util/customer-portal-password.js +209 -0
- package/util/customer-portal-password.js.map +1 -0
- package/util/error-reporter.d.ts +52 -0
- package/util/error-reporter.js +326 -0
- package/util/error-reporter.js.map +1 -0
- package/util/error-tracking.d.ts +13 -0
- package/util/error-tracking.js +120 -0
- package/util/error-tracking.js.map +1 -0
- package/util/openai-usage-cost.d.ts +6 -0
- package/util/openai-usage-cost.js +103 -0
- package/util/openai-usage-cost.js.map +1 -0
- package/util/report-builder-unwinds.d.ts +15 -0
- package/util/report-builder-unwinds.js +156 -0
- package/util/report-builder-unwinds.js.map +1 -0
- package/util/runner-process-janitor.d.ts +27 -0
- package/util/runner-process-janitor.js +208 -0
- package/util/runner-process-janitor.js.map +1 -0
- package/util/schema-report-builder.d.ts +6 -0
- package/util/schema-report-builder.js +481 -0
- package/util/schema-report-builder.js.map +1 -0
- package/util/slow-query-reporter.d.ts +28 -0
- package/util/slow-query-reporter.js +226 -0
- package/util/slow-query-reporter.js.map +1 -0
- package/util/subscription-dependency-context.d.ts +34 -0
- package/util/subscription-dependency-context.js +1283 -0
- package/util/subscription-dependency-context.js.map +1 -0
- package/util/support-runner-v5.d.ts +1426 -0
- package/util/support-runner-v5.js +7643 -0
- package/util/support-runner-v5.js.map +1 -0
- package/util/tokenizer.d.ts +5 -0
- package/util/tokenizer.js +41 -0
- package/util/tokenizer.js.map +1 -0
- package/workers/codex-runner.worker.d.ts +1 -0
- package/workers/codex-runner.worker.js +192 -0
- package/workers/codex-runner.worker.js.map +1 -0
- package/.nodemon.json +0 -5
- package/.vscode/settings.json +0 -21
- package/AGENTS.md +0 -195
- package/README.md +0 -22
- package/build_package.sh +0 -5
- package/compileDTS.pl +0 -64
- package/docs/ai-assistant-nightly-eval.md +0 -65
- package/docs/ai-assistant-preflight-checklist.md +0 -23
- package/docs/ai-assistant-report-builder-bridge-playbook.md +0 -115
- package/eslint-plugin-custom/index.js +0 -7
- package/eslint-plugin-custom/rules/no-filter-zero-index.js +0 -44
- package/eslint.config.js +0 -103
- package/gulpfile.js +0 -216
- package/methodAndPublicationListGenerator.py +0 -375
- package/mongodbensurers.js +0 -2
- package/mongostop.js +0 -3
- package/scripts/cleanup-bypassed-callmethod-logs.js +0 -616
- package/settings.development.json +0 -25
- package/settings.development.redacted.json +0 -25
- package/src/.env +0 -12
- package/src/ai/assistant-core-heuristics.ts +0 -379
- package/src/ai/resolveio-platform-intelligence-memory-corpus.ts +0 -185
- package/src/ai/resolveio-platform-intelligence-memory.ts +0 -325
- package/src/ai/resolveio-platform-intelligence.ts +0 -462
- package/src/client-server-app.ts +0 -12
- package/src/collections/ai-run.collection.ts +0 -117
- package/src/collections/ai-terminal-conversation.collection.ts +0 -91
- package/src/collections/ai-terminal-issue-report.collection.ts +0 -99
- package/src/collections/ai-terminal-message.collection.ts +0 -77
- package/src/collections/app-setting.collection.ts +0 -104
- package/src/collections/app-status.collection.ts +0 -58
- package/src/collections/communication-metric.collection.ts +0 -84
- package/src/collections/counter.collection.ts +0 -56
- package/src/collections/cron-job-history.collection.ts +0 -94
- package/src/collections/cron-job.collection.ts +0 -92
- package/src/collections/customer-notification.collection.ts +0 -131
- package/src/collections/customer-portal-password.collection.ts +0 -76
- package/src/collections/email-history.collection.ts +0 -134
- package/src/collections/email-verified.collection.ts +0 -62
- package/src/collections/file.collection.ts +0 -74
- package/src/collections/flag-update.collection.ts +0 -57
- package/src/collections/flag.collection.ts +0 -57
- package/src/collections/log-method-latency.collection.ts +0 -77
- package/src/collections/log-subscription.collection.ts +0 -80
- package/src/collections/log.collection.ts +0 -93
- package/src/collections/logged-in-users.collection.ts +0 -67
- package/src/collections/monitor-cpu.collection.ts +0 -65
- package/src/collections/monitor-function.collection.ts +0 -74
- package/src/collections/monitor-memory.collection.ts +0 -77
- package/src/collections/monitor-mongo.collection.ts +0 -71
- package/src/collections/notification.collection.ts +0 -57
- package/src/collections/openai-usage-ledger.collection.ts +0 -131
- package/src/collections/report-builder-dashboard-builder.collection.ts +0 -109
- package/src/collections/report-builder-library.collection.ts +0 -89
- package/src/collections/report-builder-report.collection.ts +0 -184
- package/src/collections/user-group.collection.ts +0 -89
- package/src/collections/user-guide.collection.ts +0 -57
- package/src/collections/user.collection.ts +0 -181
- package/src/cron/cron.ts +0 -117
- package/src/fixtures/cron-jobs.ts +0 -95
- package/src/fixtures/init.ts +0 -35
- package/src/http/auth.ts +0 -818
- package/src/http/health.ts +0 -7
- package/src/http/home.ts +0 -90
- package/src/http/slow-query-publication.ts +0 -49
- package/src/index.ts +0 -1
- package/src/managers/ai-assistant-codex-manager.manager.ts +0 -1131
- package/src/managers/ai-run-evidence.manager.ts +0 -264
- package/src/managers/communication-metric.manager.ts +0 -82
- package/src/managers/cron.manager.ts +0 -333
- package/src/managers/customer-notification-content.manager.ts +0 -236
- package/src/managers/diagnostic-manager-bootstrap.ts +0 -165
- package/src/managers/error-auto-fix.manager.ts +0 -2767
- package/src/managers/local-log.manager.ts +0 -113
- package/src/managers/method.manager.ts +0 -1857
- package/src/managers/mongo.manager.ts +0 -4575
- package/src/managers/monitor.manager.ts +0 -507
- package/src/managers/openai-usage-ledger.manager.ts +0 -112
- package/src/managers/slow-query-verifier.manager.ts +0 -3590
- package/src/managers/slow-query.manager.ts +0 -519
- package/src/managers/subscription.manager.ts +0 -3128
- package/src/managers/websocket.manager.ts +0 -746
- package/src/managers/worker-dispatcher.manager.ts +0 -1360
- package/src/managers/worker-server.manager.ts +0 -536
- package/src/methods/accounts.ts +0 -532
- package/src/methods/ai-terminal.ts +0 -29070
- package/src/methods/app-settings.ts +0 -114
- package/src/methods/aws.ts +0 -649
- package/src/methods/collections.ts +0 -641
- package/src/methods/counters.ts +0 -69
- package/src/methods/cron-jobs.ts +0 -2614
- package/src/methods/customer-notifications.ts +0 -458
- package/src/methods/diagnostics.ts +0 -616
- package/src/methods/flag-updates.ts +0 -7
- package/src/methods/flags.ts +0 -7
- package/src/methods/logs.ts +0 -657
- package/src/methods/mongo-explorer.ts +0 -1880
- package/src/methods/monitor.ts +0 -540
- package/src/methods/pdf.ts +0 -1236
- package/src/methods/publications.ts +0 -129
- package/src/methods/report-builder.ts +0 -3300
- package/src/methods/support.ts +0 -335
- package/src/models/ai-run.model.ts +0 -27
- package/src/models/ai-terminal-conversation.model.ts +0 -19
- package/src/models/ai-terminal-issue-report.model.ts +0 -21
- package/src/models/ai-terminal-message.model.ts +0 -24
- package/src/models/app-setting.model.ts +0 -17
- package/src/models/collection-document.model.ts +0 -24
- package/src/models/communication-metric.model.ts +0 -23
- package/src/models/cron-job-history.model.ts +0 -16
- package/src/models/cron-job.model.ts +0 -15
- package/src/models/customer-notification.model.ts +0 -28
- package/src/models/customer-portal-password.model.ts +0 -12
- package/src/models/dialog.model.ts +0 -25
- package/src/models/log-method-latency.model.ts +0 -11
- package/src/models/log.model.ts +0 -19
- package/src/models/method.model.ts +0 -25
- package/src/models/monitor-function.model.ts +0 -16
- package/src/models/monitor-memory.model.ts +0 -17
- package/src/models/monitor-mongo.model.ts +0 -15
- package/src/models/openai-usage-ledger.model.ts +0 -56
- package/src/models/pagination.model.ts +0 -35
- package/src/models/permission.model.ts +0 -14
- package/src/models/report-builder-dashboard-builder.model.ts +0 -29
- package/src/models/report-builder-library.model.ts +0 -20
- package/src/models/report-builder-report.model.ts +0 -136
- package/src/models/report-builder.model.ts +0 -68
- package/src/models/select-data-label.model.ts +0 -9
- package/src/models/server-message.model.ts +0 -31
- package/src/models/slow-query-report.model.ts +0 -23
- package/src/models/subscription.model.ts +0 -73
- package/src/models/support-ticket.model.ts +0 -104
- package/src/models/user-group.model.ts +0 -24
- package/src/models/user.model.ts +0 -96
- package/src/private/images/ResolveIO.png +0 -0
- package/src/publications/ai-terminal.ts +0 -73
- package/src/publications/app-settings.ts +0 -25
- package/src/publications/app-status.ts +0 -13
- package/src/publications/cron-jobs.ts +0 -40
- package/src/publications/customer-notifications.ts +0 -101
- package/src/publications/files.ts +0 -33
- package/src/publications/flags-update.ts +0 -19
- package/src/publications/flags.ts +0 -19
- package/src/publications/logs.ts +0 -163
- package/src/publications/notifications.ts +0 -13
- package/src/publications/report-builder-dashboard-builders.ts +0 -39
- package/src/publications/report-builder-libraries.ts +0 -41
- package/src/publications/report-builder-reports.ts +0 -47
- package/src/publications/super-admin.ts +0 -13
- package/src/publications/user-groups.ts +0 -12
- package/src/publications/user-guides.ts +0 -12
- package/src/resolveio-server-app.ts +0 -617
- package/src/server-app.ts +0 -3354
- package/src/services/codex-client.ts +0 -1231
- package/src/services/openai-client.ts +0 -265
- package/src/types/error-report.ts +0 -26
- package/src/types/js-tiktoken.d.ts +0 -11
- package/src/types/slow-query-report.ts +0 -28
- package/src/util/ai-qa-policy.ts +0 -925
- package/src/util/ai-run-evidence-adapters.ts +0 -8347
- package/src/util/ai-run-evidence-dashboard.ts +0 -323
- package/src/util/ai-run-evidence-eval.ts +0 -1057
- package/src/util/ai-run-evidence.ts +0 -1430
- package/src/util/ai-runner-artifacts.ts +0 -586
- package/src/util/ai-runner-manager-autopilot.ts +0 -961
- package/src/util/ai-runner-manager-policy.ts +0 -5011
- package/src/util/ai-runner-qa-auth.ts +0 -838
- package/src/util/ai-runner-qa-tools.ts +0 -3536
- package/src/util/aicoder-runner-v6.ts +0 -3121
- package/src/util/common.ts +0 -649
- package/src/util/customer-portal-password.ts +0 -183
- package/src/util/error-reporter.ts +0 -332
- package/src/util/error-tracking.ts +0 -79
- package/src/util/openai-usage-cost.ts +0 -114
- package/src/util/report-builder-unwinds.ts +0 -180
- package/src/util/runner-process-janitor.ts +0 -219
- package/src/util/schema-report-builder.ts +0 -448
- package/src/util/slow-query-reporter.ts +0 -216
- package/src/util/subscription-dependency-context.ts +0 -1096
- package/src/util/support-runner-v5.ts +0 -10040
- package/src/util/tokenizer.ts +0 -38
- package/src/workers/codex-runner.worker.ts +0 -142
- package/start_server.sh +0 -5
- package/tests/ai-assistant-corpus-build.ts +0 -484
- package/tests/ai-assistant-corpus-replay-e2e.ts +0 -774
- package/tests/ai-assistant-data-parity-e2e.ts +0 -1989
- package/tests/ai-assistant-eval-triage.ts +0 -831
- package/tests/ai-assistant-openai-e2e.ts +0 -1061
- package/tests/ai-assistant-openai-git-e2e.ts +0 -155
- package/tests/ai-assistant-preflight-matrix.ts +0 -215
- package/tests/ai-assistant-routing-eval.test.ts +0 -585
- package/tests/ai-assistant-snf-live-eval.ts +0 -975
- package/tests/ai-assistant-utils.test.ts +0 -4834
- package/tests/ai-manager-autopilot-snapshot.test.ts +0 -193
- package/tests/ai-manager-recovery-checkpoint.test.ts +0 -1383
- package/tests/ai-run-eval.test.ts +0 -132
- package/tests/ai-run-evidence.test.ts +0 -3773
- package/tests/ai-runner-contract.test.ts +0 -515
- package/tests/aicoder-runner-v6.test.ts +0 -822
- package/tests/error-reporter.test.ts +0 -145
- package/tests/method-publication-generator.test.ts +0 -46
- package/tests/report-builder-linking.test.ts +0 -79
- package/tests/resolveio-platform-intelligence.test.ts +0 -352
- package/tests/server-app-cron-owner.test.ts +0 -127
- package/tests/subscription-connect-race.test.ts +0 -158
- package/tests/subscription-dependency-context.test.ts +0 -324
- package/tests/subscription-manager-collection-tracking.test.ts +0 -86
- package/tests/subscription-manager-invalidation.test.ts +0 -86
- package/tests/support-runner-v5.test.ts +0 -3201
- package/tsconfig.json +0 -34
- /package/{src/private → private}/email-templates/enrollment.html +0 -0
- /package/{src/private → private}/email-templates/forgot-password.html +0 -0
- /package/{src/private → private}/email-templates/support-ticket-deleted.html +0 -0
- /package/{src/private → private}/email-templates/support-ticket-modified.html +0 -0
- /package/{src/private → private}/email-templates/support-ticket.html +0 -0
- /package/{src/public_api.ts → public_api.d.ts} +0 -0
|
@@ -1,1131 +0,0 @@
|
|
|
1
|
-
import { AiTerminalConversations } from '../collections/ai-terminal-conversation.collection';
|
|
2
|
-
import { AiTerminalIssueReports } from '../collections/ai-terminal-issue-report.collection';
|
|
3
|
-
import { AiTerminalMessages } from '../collections/ai-terminal-message.collection';
|
|
4
|
-
import { AiTerminalMessageModel } from '../models/ai-terminal-message.model';
|
|
5
|
-
import { AiTerminalConversationModel } from '../models/ai-terminal-conversation.model';
|
|
6
|
-
import { promises as fs } from 'fs';
|
|
7
|
-
import * as os from 'os';
|
|
8
|
-
import * as path from 'path';
|
|
9
|
-
import { execFile } from 'child_process';
|
|
10
|
-
import { promisify } from 'util';
|
|
11
|
-
|
|
12
|
-
type AiAssistantCodexManagerRuntime = {
|
|
13
|
-
isWorkersEnabled: boolean;
|
|
14
|
-
isWorkerInstance: boolean;
|
|
15
|
-
workerIndex?: string | null;
|
|
16
|
-
workerInstance?: string | null;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
type AiAssistantCodexManagerConfig = {
|
|
20
|
-
enabled: boolean;
|
|
21
|
-
runOnAnyWorker: boolean;
|
|
22
|
-
targetWorkerIndex: string;
|
|
23
|
-
targetWorkerInstance: string | null;
|
|
24
|
-
pollIntervalMs: number;
|
|
25
|
-
lookbackMinutes: number;
|
|
26
|
-
maxMessagesPerPoll: number;
|
|
27
|
-
maxRemediationsPerPoll: number;
|
|
28
|
-
autoReportEnabled: boolean;
|
|
29
|
-
autoRemediationEnabled: boolean;
|
|
30
|
-
remediationHookPath: string;
|
|
31
|
-
remediationTimeoutMs: number;
|
|
32
|
-
remediationMaxBufferBytes: number;
|
|
33
|
-
remediationMaxAttemptsPerIssue: number;
|
|
34
|
-
remediationCooldownMinutes: number;
|
|
35
|
-
autoReplayEnabled: boolean;
|
|
36
|
-
replayCommand: string;
|
|
37
|
-
replayTimeoutMs: number;
|
|
38
|
-
replayMaxBufferBytes: number;
|
|
39
|
-
replayMaxAttemptsPerIssue: number;
|
|
40
|
-
replayCooldownMinutes: number;
|
|
41
|
-
debug: boolean;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
type AiAssistantQualityDecision = {
|
|
45
|
-
status: 'pass' | 'needs_review';
|
|
46
|
-
reason: string;
|
|
47
|
-
code: string;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const DEFAULT_POLL_INTERVAL_MS = 15000;
|
|
51
|
-
const DEFAULT_LOOKBACK_MINUTES = 120;
|
|
52
|
-
const DEFAULT_MAX_MESSAGES_PER_POLL = 100;
|
|
53
|
-
const DEFAULT_MAX_REMEDIATIONS_PER_POLL = 3;
|
|
54
|
-
const DEFAULT_REMEDIATION_TIMEOUT_MS = 20 * 60 * 1000;
|
|
55
|
-
const DEFAULT_REMEDIATION_MAX_BUFFER_BYTES = 1024 * 1024;
|
|
56
|
-
const DEFAULT_REMEDIATION_MAX_ATTEMPTS_PER_ISSUE = 2;
|
|
57
|
-
const DEFAULT_REMEDIATION_COOLDOWN_MINUTES = 15;
|
|
58
|
-
const DEFAULT_REPLAY_TIMEOUT_MS = 5 * 60 * 1000;
|
|
59
|
-
const DEFAULT_REPLAY_MAX_BUFFER_BYTES = 1024 * 1024;
|
|
60
|
-
const DEFAULT_REPLAY_MAX_ATTEMPTS_PER_ISSUE = 2;
|
|
61
|
-
const DEFAULT_REPLAY_COOLDOWN_MINUTES = 10;
|
|
62
|
-
const MAX_STORED_OUTPUT_CHARS = 4000;
|
|
63
|
-
const execFileAsync = promisify(execFile);
|
|
64
|
-
|
|
65
|
-
function normalizeOptionalString(value: any): string {
|
|
66
|
-
return typeof value === 'string' ? value.trim() : '';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function parseBooleanEnv(value: any, fallback: boolean): boolean {
|
|
70
|
-
const normalized = normalizeOptionalString(value).toLowerCase();
|
|
71
|
-
if (!normalized) {
|
|
72
|
-
return fallback;
|
|
73
|
-
}
|
|
74
|
-
if (['1', 'true', 'yes', 'on', 'enabled'].includes(normalized)) {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
if (['0', 'false', 'no', 'off', 'disabled'].includes(normalized)) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
return fallback;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function parsePositiveInt(value: any, fallback: number, min = 1): number {
|
|
84
|
-
const parsed = parseInt(String(value ?? '').trim(), 10);
|
|
85
|
-
if (!Number.isFinite(parsed) || Number.isNaN(parsed) || parsed < min) {
|
|
86
|
-
return fallback;
|
|
87
|
-
}
|
|
88
|
-
return parsed;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function parsePositiveIntWithMax(value: any, fallback: number, min: number, max: number): number {
|
|
92
|
-
const parsed = parsePositiveInt(value, fallback, min);
|
|
93
|
-
return Math.min(parsed, max);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function resolveEnabledFlag(): boolean {
|
|
97
|
-
const explicitValue = process.env.AI_ASSISTANT_CODEX_MANAGER_ENABLED
|
|
98
|
-
?? process.env.AI_ASSISTANT_QUALITY_MANAGER_ENABLED;
|
|
99
|
-
if (explicitValue !== undefined && explicitValue !== null && String(explicitValue).trim() !== '') {
|
|
100
|
-
return parseBooleanEnv(explicitValue, false);
|
|
101
|
-
}
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export class AiAssistantCodexManager {
|
|
106
|
-
private readonly config: AiAssistantCodexManagerConfig;
|
|
107
|
-
private readonly runtime: AiAssistantCodexManagerRuntime;
|
|
108
|
-
private _interval: NodeJS.Timeout | null = null;
|
|
109
|
-
private _inFlight = false;
|
|
110
|
-
private _cursorCreatedAt: Date;
|
|
111
|
-
private _cursorMessageId = '';
|
|
112
|
-
|
|
113
|
-
constructor(config: AiAssistantCodexManagerConfig, runtime: AiAssistantCodexManagerRuntime) {
|
|
114
|
-
this.config = config;
|
|
115
|
-
this.runtime = runtime;
|
|
116
|
-
this._cursorCreatedAt = new Date(Date.now() - (config.lookbackMinutes * 60 * 1000));
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
static createIfEnabled(runtime: AiAssistantCodexManagerRuntime): AiAssistantCodexManager | null {
|
|
120
|
-
const config = this.resolveConfig();
|
|
121
|
-
if (!config.enabled) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
if (!this.shouldRunOnCurrentProcess(config, runtime)) {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
const manager = new AiAssistantCodexManager(config, runtime);
|
|
128
|
-
manager.initialize();
|
|
129
|
-
return manager;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private static resolveConfig(): AiAssistantCodexManagerConfig {
|
|
133
|
-
const targetWorkerIndex = normalizeOptionalString(
|
|
134
|
-
process.env.AI_ASSISTANT_CODEX_MANAGER_WORKER_INDEX
|
|
135
|
-
|| process.env.AI_ASSISTANT_CODEX_WORKER_INDEX
|
|
136
|
-
|| process.env.CODEX_WORKER_INDEX
|
|
137
|
-
|| 'ai-assistant-manager'
|
|
138
|
-
) || 'ai-assistant-manager';
|
|
139
|
-
const targetWorkerInstance = normalizeOptionalString(
|
|
140
|
-
process.env.AI_ASSISTANT_CODEX_MANAGER_WORKER_INSTANCE
|
|
141
|
-
) || null;
|
|
142
|
-
return {
|
|
143
|
-
enabled: resolveEnabledFlag(),
|
|
144
|
-
runOnAnyWorker: parseBooleanEnv(process.env.AI_ASSISTANT_CODEX_MANAGER_RUN_ANY_WORKER, false),
|
|
145
|
-
targetWorkerIndex,
|
|
146
|
-
targetWorkerInstance,
|
|
147
|
-
pollIntervalMs: parsePositiveInt(process.env.AI_ASSISTANT_CODEX_MANAGER_INTERVAL_MS, DEFAULT_POLL_INTERVAL_MS, 1000),
|
|
148
|
-
lookbackMinutes: parsePositiveInt(process.env.AI_ASSISTANT_CODEX_MANAGER_LOOKBACK_MINUTES, DEFAULT_LOOKBACK_MINUTES, 1),
|
|
149
|
-
maxMessagesPerPoll: parsePositiveIntWithMax(
|
|
150
|
-
process.env.AI_ASSISTANT_CODEX_MANAGER_MAX_MESSAGES_PER_POLL,
|
|
151
|
-
DEFAULT_MAX_MESSAGES_PER_POLL,
|
|
152
|
-
1,
|
|
153
|
-
1000
|
|
154
|
-
),
|
|
155
|
-
maxRemediationsPerPoll: parsePositiveIntWithMax(
|
|
156
|
-
process.env.AI_ASSISTANT_CODEX_MANAGER_MAX_REMEDIATIONS_PER_POLL,
|
|
157
|
-
DEFAULT_MAX_REMEDIATIONS_PER_POLL,
|
|
158
|
-
1,
|
|
159
|
-
100
|
|
160
|
-
),
|
|
161
|
-
autoReportEnabled: parseBooleanEnv(process.env.AI_ASSISTANT_CODEX_MANAGER_AUTO_REPORT, true),
|
|
162
|
-
autoRemediationEnabled: parseBooleanEnv(process.env.AI_ASSISTANT_CODEX_MANAGER_AUTO_REMEDIATE, false),
|
|
163
|
-
remediationHookPath: normalizeOptionalString(process.env.AI_ASSISTANT_CODEX_MANAGER_REMEDIATE_HOOK),
|
|
164
|
-
remediationTimeoutMs: parsePositiveInt(
|
|
165
|
-
process.env.AI_ASSISTANT_CODEX_MANAGER_REMEDIATE_TIMEOUT_MS,
|
|
166
|
-
DEFAULT_REMEDIATION_TIMEOUT_MS,
|
|
167
|
-
1000
|
|
168
|
-
),
|
|
169
|
-
remediationMaxBufferBytes: parsePositiveInt(
|
|
170
|
-
process.env.AI_ASSISTANT_CODEX_MANAGER_REMEDIATE_MAX_BUFFER_BYTES,
|
|
171
|
-
DEFAULT_REMEDIATION_MAX_BUFFER_BYTES,
|
|
172
|
-
1024
|
|
173
|
-
),
|
|
174
|
-
remediationMaxAttemptsPerIssue: parsePositiveInt(
|
|
175
|
-
process.env.AI_ASSISTANT_CODEX_MANAGER_REMEDIATE_MAX_ATTEMPTS_PER_ISSUE,
|
|
176
|
-
DEFAULT_REMEDIATION_MAX_ATTEMPTS_PER_ISSUE,
|
|
177
|
-
1
|
|
178
|
-
),
|
|
179
|
-
remediationCooldownMinutes: parsePositiveInt(
|
|
180
|
-
process.env.AI_ASSISTANT_CODEX_MANAGER_REMEDIATE_COOLDOWN_MINUTES,
|
|
181
|
-
DEFAULT_REMEDIATION_COOLDOWN_MINUTES,
|
|
182
|
-
1
|
|
183
|
-
),
|
|
184
|
-
autoReplayEnabled: parseBooleanEnv(process.env.AI_ASSISTANT_CODEX_MANAGER_REPLAY_ENABLED, false),
|
|
185
|
-
replayCommand: normalizeOptionalString(process.env.AI_ASSISTANT_CODEX_MANAGER_REPLAY_COMMAND),
|
|
186
|
-
replayTimeoutMs: parsePositiveInt(
|
|
187
|
-
process.env.AI_ASSISTANT_CODEX_MANAGER_REPLAY_TIMEOUT_MS,
|
|
188
|
-
DEFAULT_REPLAY_TIMEOUT_MS,
|
|
189
|
-
1000
|
|
190
|
-
),
|
|
191
|
-
replayMaxBufferBytes: parsePositiveInt(
|
|
192
|
-
process.env.AI_ASSISTANT_CODEX_MANAGER_REPLAY_MAX_BUFFER_BYTES,
|
|
193
|
-
DEFAULT_REPLAY_MAX_BUFFER_BYTES,
|
|
194
|
-
1024
|
|
195
|
-
),
|
|
196
|
-
replayMaxAttemptsPerIssue: parsePositiveInt(
|
|
197
|
-
process.env.AI_ASSISTANT_CODEX_MANAGER_REPLAY_MAX_ATTEMPTS_PER_ISSUE,
|
|
198
|
-
DEFAULT_REPLAY_MAX_ATTEMPTS_PER_ISSUE,
|
|
199
|
-
1
|
|
200
|
-
),
|
|
201
|
-
replayCooldownMinutes: parsePositiveInt(
|
|
202
|
-
process.env.AI_ASSISTANT_CODEX_MANAGER_REPLAY_COOLDOWN_MINUTES,
|
|
203
|
-
DEFAULT_REPLAY_COOLDOWN_MINUTES,
|
|
204
|
-
1
|
|
205
|
-
),
|
|
206
|
-
debug: parseBooleanEnv(process.env.AI_ASSISTANT_CODEX_MANAGER_DEBUG, false)
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
private static shouldRunOnCurrentProcess(config: AiAssistantCodexManagerConfig, runtime: AiAssistantCodexManagerRuntime): boolean {
|
|
211
|
-
const workerIndex = normalizeOptionalString(runtime.workerIndex);
|
|
212
|
-
const workerInstance = normalizeOptionalString(runtime.workerInstance);
|
|
213
|
-
if (!runtime.isWorkersEnabled) {
|
|
214
|
-
return true;
|
|
215
|
-
}
|
|
216
|
-
if (!runtime.isWorkerInstance) {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
if (config.runOnAnyWorker) {
|
|
220
|
-
if (config.targetWorkerInstance) {
|
|
221
|
-
return workerInstance === config.targetWorkerInstance;
|
|
222
|
-
}
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
if (workerIndex !== config.targetWorkerIndex) {
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
if (config.targetWorkerInstance && workerInstance !== config.targetWorkerInstance) {
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
private initialize(): void {
|
|
235
|
-
console.log(new Date(), '[AI Assistant Codex Manager] started', {
|
|
236
|
-
workerIndex: process.env.WORKER_INDEX || null,
|
|
237
|
-
workerInstance: process.env.NODE_APP_INSTANCE || null,
|
|
238
|
-
pollIntervalMs: this.config.pollIntervalMs,
|
|
239
|
-
maxMessagesPerPoll: this.config.maxMessagesPerPoll,
|
|
240
|
-
lookbackMinutes: this.config.lookbackMinutes,
|
|
241
|
-
autoRemediationEnabled: this.config.autoRemediationEnabled,
|
|
242
|
-
remediationHookPath: this.config.remediationHookPath || null,
|
|
243
|
-
autoReplayEnabled: this.config.autoReplayEnabled
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
setTimeout(async () => {
|
|
247
|
-
try {
|
|
248
|
-
await this.pollOnce();
|
|
249
|
-
}
|
|
250
|
-
catch (error) {
|
|
251
|
-
console.error(new Date(), '[AI Assistant Codex Manager] initial poll failed', error);
|
|
252
|
-
}
|
|
253
|
-
}, 2500);
|
|
254
|
-
|
|
255
|
-
this._interval = setInterval(async () => {
|
|
256
|
-
try {
|
|
257
|
-
await this.pollOnce();
|
|
258
|
-
}
|
|
259
|
-
catch (error) {
|
|
260
|
-
console.error(new Date(), '[AI Assistant Codex Manager] poll failed', error);
|
|
261
|
-
}
|
|
262
|
-
}, this.config.pollIntervalMs);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
private async pollOnce(): Promise<void> {
|
|
266
|
-
if (this._inFlight) {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
this._inFlight = true;
|
|
270
|
-
try {
|
|
271
|
-
const query: Record<string, any> = {
|
|
272
|
-
role: 'assistant',
|
|
273
|
-
$or: [
|
|
274
|
-
{ createdAt: { $gt: this._cursorCreatedAt } },
|
|
275
|
-
{ createdAt: this._cursorCreatedAt, _id: { $gt: this._cursorMessageId || '' } }
|
|
276
|
-
]
|
|
277
|
-
};
|
|
278
|
-
const messages = await AiTerminalMessages.find(
|
|
279
|
-
query,
|
|
280
|
-
{
|
|
281
|
-
sort: { createdAt: 1, _id: 1 },
|
|
282
|
-
limit: this.config.maxMessagesPerPoll
|
|
283
|
-
}
|
|
284
|
-
) as AiTerminalMessageModel[];
|
|
285
|
-
if (Array.isArray(messages) && messages.length) {
|
|
286
|
-
for (const message of messages) {
|
|
287
|
-
const createdAt = message?.createdAt ? new Date(message.createdAt) : null;
|
|
288
|
-
if (createdAt && Number.isFinite(createdAt.getTime())) {
|
|
289
|
-
this._cursorCreatedAt = createdAt;
|
|
290
|
-
}
|
|
291
|
-
this._cursorMessageId = normalizeOptionalString(message?._id);
|
|
292
|
-
await this.processMessage(message);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (this.config.autoRemediationEnabled) {
|
|
297
|
-
await this.pollRemediationQueue();
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
finally {
|
|
301
|
-
this._inFlight = false;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
private async processMessage(message: AiTerminalMessageModel): Promise<void> {
|
|
306
|
-
const messageId = normalizeOptionalString(message?._id);
|
|
307
|
-
const conversationId = normalizeOptionalString(message?.id_conversation);
|
|
308
|
-
if (!messageId || !conversationId) {
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
const metadata = this.normalizeMetadata(message?.metadata);
|
|
312
|
-
if (metadata.pending === true) {
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
if (metadata.quality_manager?.checked_at) {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const decision = this.evaluateMessageQuality(message, metadata);
|
|
320
|
-
let issueReportId = '';
|
|
321
|
-
if (decision.status === 'needs_review' && this.config.autoReportEnabled) {
|
|
322
|
-
issueReportId = await this.ensureAutomatedIssueReport(message, decision);
|
|
323
|
-
}
|
|
324
|
-
await this.markMessageQualityReviewed(messageId, decision, issueReportId);
|
|
325
|
-
if (issueReportId && this.config.autoRemediationEnabled) {
|
|
326
|
-
await this.runIssueRemediation(issueReportId, { source: 'auto', trigger: 'message_quality' });
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
private evaluateMessageQuality(message: AiTerminalMessageModel, metadata: Record<string, any>): AiAssistantQualityDecision {
|
|
331
|
-
const content = normalizeOptionalString(message?.content);
|
|
332
|
-
const toolError = normalizeOptionalString(metadata?.tool_execution?.outcome?.error);
|
|
333
|
-
if (metadata.failed === true) {
|
|
334
|
-
return {
|
|
335
|
-
status: 'needs_review',
|
|
336
|
-
reason: 'Assistant response finalized in failed state.',
|
|
337
|
-
code: 'metadata_failed'
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
if (/I ran into an internal error while preparing that response/i.test(content)) {
|
|
341
|
-
return {
|
|
342
|
-
status: 'needs_review',
|
|
343
|
-
reason: 'Assistant returned internal error text.',
|
|
344
|
-
code: 'internal_error_copy'
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
if (/That took longer than expected\./i.test(content)) {
|
|
348
|
-
return {
|
|
349
|
-
status: 'needs_review',
|
|
350
|
-
reason: 'Assistant response timed out.',
|
|
351
|
-
code: 'timeout_copy'
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
if (/I could not finish this request within the assistant time budget/i.test(content)) {
|
|
355
|
-
return {
|
|
356
|
-
status: 'needs_review',
|
|
357
|
-
reason: 'Assistant run exceeded configured time budget.',
|
|
358
|
-
code: 'run_budget_exceeded_copy'
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
if (toolError) {
|
|
362
|
-
return {
|
|
363
|
-
status: 'needs_review',
|
|
364
|
-
reason: `Assistant tool execution error: ${toolError}`.slice(0, 500),
|
|
365
|
-
code: 'tool_execution_error'
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
return {
|
|
369
|
-
status: 'pass',
|
|
370
|
-
reason: 'Quality check passed.',
|
|
371
|
-
code: 'ok'
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
private async ensureAutomatedIssueReport(message: AiTerminalMessageModel, decision: AiAssistantQualityDecision): Promise<string> {
|
|
376
|
-
const messageId = normalizeOptionalString(message?._id);
|
|
377
|
-
const conversationId = normalizeOptionalString(message?.id_conversation);
|
|
378
|
-
if (!messageId || !conversationId) {
|
|
379
|
-
return '';
|
|
380
|
-
}
|
|
381
|
-
const existing = await AiTerminalIssueReports.findOne({
|
|
382
|
-
id_message: messageId,
|
|
383
|
-
source: 'automated'
|
|
384
|
-
});
|
|
385
|
-
if (existing?._id) {
|
|
386
|
-
return normalizeOptionalString(existing._id);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
const conversation = await AiTerminalConversations.findById(conversationId) as AiTerminalConversationModel | null;
|
|
390
|
-
if (!conversation) {
|
|
391
|
-
return '';
|
|
392
|
-
}
|
|
393
|
-
const assistantContent = normalizeOptionalString(message?.content);
|
|
394
|
-
const requestId = normalizeOptionalString((message as any)?.metadata?.request_id);
|
|
395
|
-
const userPrompt = await this.resolveClosestUserPrompt(conversationId, message?.createdAt);
|
|
396
|
-
const now = new Date();
|
|
397
|
-
const doc: Record<string, any> = {
|
|
398
|
-
id_conversation: conversationId,
|
|
399
|
-
status: 'open',
|
|
400
|
-
source: 'automated',
|
|
401
|
-
reason: decision.reason,
|
|
402
|
-
...(userPrompt ? { user_prompt: userPrompt } : {}),
|
|
403
|
-
...(assistantContent ? { assistant_content: assistantContent } : {}),
|
|
404
|
-
...(requestId ? { request_id: requestId } : {}),
|
|
405
|
-
id_message: messageId,
|
|
406
|
-
...(normalizeOptionalString(conversation?.id_client) ? { id_client: normalizeOptionalString(conversation?.id_client) } : {}),
|
|
407
|
-
...(normalizeOptionalString(conversation?.id_app) ? { id_app: normalizeOptionalString(conversation?.id_app) } : {}),
|
|
408
|
-
...(normalizeOptionalString(conversation?.id_user) ? { id_user: normalizeOptionalString(conversation?.id_user) } : {}),
|
|
409
|
-
metadata: {
|
|
410
|
-
quality_manager: {
|
|
411
|
-
code: decision.code,
|
|
412
|
-
checked_at: now,
|
|
413
|
-
worker_index: normalizeOptionalString(process.env.WORKER_INDEX),
|
|
414
|
-
worker_instance: normalizeOptionalString(process.env.NODE_APP_INSTANCE)
|
|
415
|
-
}
|
|
416
|
-
},
|
|
417
|
-
createdAt: now,
|
|
418
|
-
updatedAt: now
|
|
419
|
-
};
|
|
420
|
-
const insertResult = await AiTerminalIssueReports.insertOne(doc as any);
|
|
421
|
-
const issueId = normalizeOptionalString(insertResult?._id);
|
|
422
|
-
console.log(new Date(), '[AI Assistant Codex Manager] created automated issue report', {
|
|
423
|
-
id_issue_report: issueId || null,
|
|
424
|
-
id_conversation: conversationId,
|
|
425
|
-
id_message: messageId,
|
|
426
|
-
code: decision.code
|
|
427
|
-
});
|
|
428
|
-
return issueId;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
private async pollRemediationQueue(): Promise<void> {
|
|
432
|
-
const issues = await AiTerminalIssueReports.find(
|
|
433
|
-
{
|
|
434
|
-
source: 'automated',
|
|
435
|
-
status: { $in: ['open', 'triaged'] },
|
|
436
|
-
$or: [
|
|
437
|
-
{ 'metadata.quality_manager.remediation.status': { $exists: false } },
|
|
438
|
-
{ 'metadata.quality_manager.remediation.status': { $in: ['queued', 'failed', 'skipped'] } }
|
|
439
|
-
]
|
|
440
|
-
},
|
|
441
|
-
{
|
|
442
|
-
sort: { updatedAt: 1, createdAt: 1 },
|
|
443
|
-
limit: this.config.maxRemediationsPerPoll
|
|
444
|
-
}
|
|
445
|
-
) as Array<Record<string, any>>;
|
|
446
|
-
if (!Array.isArray(issues) || !issues.length) {
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
for (const issue of issues) {
|
|
450
|
-
const issueId = normalizeOptionalString(issue?._id);
|
|
451
|
-
if (!issueId) {
|
|
452
|
-
continue;
|
|
453
|
-
}
|
|
454
|
-
const remediationResult = await this.runIssueRemediation(issueId, { source: 'auto', trigger: 'poll' });
|
|
455
|
-
if (remediationResult?.status === 'success' || remediationResult?.status === 'running') {
|
|
456
|
-
break;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
public async runIssueRemediation(
|
|
462
|
-
issueReportId: string,
|
|
463
|
-
options: { force?: boolean; source?: 'auto' | 'manual'; trigger?: string } = {}
|
|
464
|
-
): Promise<Record<string, any>> {
|
|
465
|
-
const issueId = normalizeOptionalString(issueReportId);
|
|
466
|
-
if (!issueId) {
|
|
467
|
-
return {
|
|
468
|
-
status: 'failed',
|
|
469
|
-
reason: 'Issue report id is required.'
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
if (!this.config.autoRemediationEnabled) {
|
|
473
|
-
return {
|
|
474
|
-
status: 'skipped',
|
|
475
|
-
reason: 'Auto remediation is disabled.'
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
if (!this.config.remediationHookPath) {
|
|
479
|
-
return {
|
|
480
|
-
status: 'skipped',
|
|
481
|
-
reason: 'Remediation hook path is not configured.'
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
const issue = await AiTerminalIssueReports.findById(issueId) as Record<string, any> | null;
|
|
486
|
-
if (!issue) {
|
|
487
|
-
return {
|
|
488
|
-
status: 'not_found',
|
|
489
|
-
reason: 'Issue report not found.'
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
const force = options.force === true;
|
|
494
|
-
const source = options.source === 'manual' ? 'manual' : 'auto';
|
|
495
|
-
const now = new Date();
|
|
496
|
-
const metadata = this.normalizeMetadata(issue.metadata);
|
|
497
|
-
const qualityManager = this.normalizeMetadata(metadata.quality_manager);
|
|
498
|
-
const remediation = this.normalizeMetadata(qualityManager.remediation);
|
|
499
|
-
const existingStatus = normalizeOptionalString(remediation.status).toLowerCase();
|
|
500
|
-
const attemptsUsed = Number.isFinite(Number(remediation.attempt_count)) ? Number(remediation.attempt_count) : 0;
|
|
501
|
-
const maxAttempts = this.config.remediationMaxAttemptsPerIssue;
|
|
502
|
-
const cooldownMinutes = this.config.remediationCooldownMinutes;
|
|
503
|
-
const cooldownMs = cooldownMinutes * 60 * 1000;
|
|
504
|
-
const lastAttemptAt = this.parseDate(remediation.last_attempt_at);
|
|
505
|
-
if (!force && existingStatus === 'running') {
|
|
506
|
-
return {
|
|
507
|
-
status: 'running',
|
|
508
|
-
reason: 'Remediation already running.',
|
|
509
|
-
issueId
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
if (!force && maxAttempts > 0 && attemptsUsed >= maxAttempts) {
|
|
513
|
-
return {
|
|
514
|
-
status: 'skipped',
|
|
515
|
-
reason: `Remediation attempt budget reached (${attemptsUsed}/${maxAttempts}).`,
|
|
516
|
-
issueId
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
if (!force && existingStatus === 'failed' && lastAttemptAt) {
|
|
520
|
-
const ageMs = now.getTime() - lastAttemptAt.getTime();
|
|
521
|
-
if (ageMs >= 0 && ageMs < cooldownMs) {
|
|
522
|
-
return {
|
|
523
|
-
status: 'skipped',
|
|
524
|
-
reason: 'Remediation cooldown active.',
|
|
525
|
-
issueId,
|
|
526
|
-
nextAttemptAt: new Date(lastAttemptAt.getTime() + cooldownMs)
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
const attemptCount = attemptsUsed + 1;
|
|
532
|
-
await AiTerminalIssueReports.updateOne(
|
|
533
|
-
{ _id: issueId },
|
|
534
|
-
{
|
|
535
|
-
$set: {
|
|
536
|
-
'metadata.quality_manager.remediation': {
|
|
537
|
-
...remediation,
|
|
538
|
-
status: 'running',
|
|
539
|
-
source,
|
|
540
|
-
trigger: normalizeOptionalString(options.trigger) || 'unspecified',
|
|
541
|
-
attempt_count: attemptCount,
|
|
542
|
-
max_attempts: maxAttempts,
|
|
543
|
-
cooldown_minutes: cooldownMinutes,
|
|
544
|
-
hook: this.config.remediationHookPath,
|
|
545
|
-
last_attempt_at: now,
|
|
546
|
-
updated_at: now,
|
|
547
|
-
last_error: '',
|
|
548
|
-
last_exit_code: null
|
|
549
|
-
},
|
|
550
|
-
updatedAt: now
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
);
|
|
554
|
-
|
|
555
|
-
const startedAtMs = Date.now();
|
|
556
|
-
const contextPath = await this.writeRemediationContextFile(issue, {
|
|
557
|
-
issueId,
|
|
558
|
-
attemptCount,
|
|
559
|
-
source,
|
|
560
|
-
trigger: normalizeOptionalString(options.trigger) || 'unspecified'
|
|
561
|
-
});
|
|
562
|
-
let parsedOutput: Record<string, any> | null = null;
|
|
563
|
-
try {
|
|
564
|
-
const execResult = await execFileAsync(
|
|
565
|
-
this.config.remediationHookPath,
|
|
566
|
-
[contextPath],
|
|
567
|
-
{
|
|
568
|
-
timeout: this.config.remediationTimeoutMs,
|
|
569
|
-
maxBuffer: this.config.remediationMaxBufferBytes,
|
|
570
|
-
env: {
|
|
571
|
-
...process.env,
|
|
572
|
-
RIO_AI_ASSISTANT_REMEDIATION_CONTEXT: contextPath,
|
|
573
|
-
RIO_AI_ASSISTANT_REMEDIATION_ISSUE_ID: issueId
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
);
|
|
577
|
-
const finishedAt = new Date();
|
|
578
|
-
const durationMs = Date.now() - startedAtMs;
|
|
579
|
-
const stdout = this.toSafeOutput(execResult?.stdout);
|
|
580
|
-
const stderr = this.toSafeOutput(execResult?.stderr);
|
|
581
|
-
parsedOutput = this.parseOutputJson(stdout);
|
|
582
|
-
const outputStatus = normalizeOptionalString(parsedOutput?.status).toLowerCase();
|
|
583
|
-
const success = outputStatus ? ['success', 'ok', 'completed', 'pass'].includes(outputStatus) : true;
|
|
584
|
-
const remediationStatus = success ? 'success' : 'failed';
|
|
585
|
-
const remediationReason = normalizeOptionalString(parsedOutput?.reason)
|
|
586
|
-
|| (success ? 'Remediation hook completed successfully.' : 'Remediation hook reported a non-success status.');
|
|
587
|
-
|
|
588
|
-
await AiTerminalIssueReports.updateOne(
|
|
589
|
-
{ _id: issueId },
|
|
590
|
-
{
|
|
591
|
-
$set: {
|
|
592
|
-
'metadata.quality_manager.remediation': {
|
|
593
|
-
...remediation,
|
|
594
|
-
status: remediationStatus,
|
|
595
|
-
source,
|
|
596
|
-
trigger: normalizeOptionalString(options.trigger) || 'unspecified',
|
|
597
|
-
attempt_count: attemptCount,
|
|
598
|
-
max_attempts: maxAttempts,
|
|
599
|
-
cooldown_minutes: cooldownMinutes,
|
|
600
|
-
hook: this.config.remediationHookPath,
|
|
601
|
-
last_attempt_at: now,
|
|
602
|
-
last_success_at: success ? finishedAt : remediation.last_success_at,
|
|
603
|
-
last_error: success ? '' : remediationReason,
|
|
604
|
-
last_exit_code: success ? 0 : null,
|
|
605
|
-
last_duration_ms: durationMs,
|
|
606
|
-
last_stdout: stdout,
|
|
607
|
-
last_stderr: stderr,
|
|
608
|
-
last_output: parsedOutput || undefined,
|
|
609
|
-
updated_at: finishedAt
|
|
610
|
-
},
|
|
611
|
-
...(success ? { status: 'triaged' } : {}),
|
|
612
|
-
updatedAt: finishedAt
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
);
|
|
616
|
-
|
|
617
|
-
let replayResult: Record<string, any> | null = null;
|
|
618
|
-
if (success && this.config.autoReplayEnabled) {
|
|
619
|
-
replayResult = await this.runIssueReplay(issueId, {
|
|
620
|
-
source,
|
|
621
|
-
trigger: normalizeOptionalString(options.trigger) || 'post_remediation'
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
console.log(new Date(), '[AI Assistant Codex Manager] remediation completed', {
|
|
626
|
-
id_issue_report: issueId,
|
|
627
|
-
status: remediationStatus,
|
|
628
|
-
attempt: attemptCount,
|
|
629
|
-
durationMs,
|
|
630
|
-
replayStatus: replayResult?.status || null
|
|
631
|
-
});
|
|
632
|
-
|
|
633
|
-
return {
|
|
634
|
-
status: remediationStatus,
|
|
635
|
-
reason: remediationReason,
|
|
636
|
-
issueId,
|
|
637
|
-
attemptCount,
|
|
638
|
-
durationMs,
|
|
639
|
-
replayStatus: replayResult?.status || '',
|
|
640
|
-
replayReason: replayResult?.reason || ''
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
catch (error) {
|
|
644
|
-
const finishedAt = new Date();
|
|
645
|
-
const durationMs = Date.now() - startedAtMs;
|
|
646
|
-
const err: any = error || {};
|
|
647
|
-
const stdout = this.toSafeOutput(err.stdout);
|
|
648
|
-
const stderr = this.toSafeOutput(err.stderr);
|
|
649
|
-
const exitCode = Number.isFinite(Number(err.code)) ? Number(err.code) : null;
|
|
650
|
-
const timeoutHit = err?.killed === true || normalizeOptionalString(err?.signal).toUpperCase() === 'SIGTERM';
|
|
651
|
-
const reason = timeoutHit
|
|
652
|
-
? `Remediation hook timed out after ${this.config.remediationTimeoutMs}ms.`
|
|
653
|
-
: (normalizeOptionalString(err?.message) || 'Remediation hook failed.');
|
|
654
|
-
const nextAttemptAt = new Date(finishedAt.getTime() + cooldownMs);
|
|
655
|
-
|
|
656
|
-
await AiTerminalIssueReports.updateOne(
|
|
657
|
-
{ _id: issueId },
|
|
658
|
-
{
|
|
659
|
-
$set: {
|
|
660
|
-
'metadata.quality_manager.remediation': {
|
|
661
|
-
...remediation,
|
|
662
|
-
status: 'failed',
|
|
663
|
-
source,
|
|
664
|
-
trigger: normalizeOptionalString(options.trigger) || 'unspecified',
|
|
665
|
-
attempt_count: attemptCount,
|
|
666
|
-
max_attempts: maxAttempts,
|
|
667
|
-
cooldown_minutes: cooldownMinutes,
|
|
668
|
-
hook: this.config.remediationHookPath,
|
|
669
|
-
last_attempt_at: now,
|
|
670
|
-
last_error: reason,
|
|
671
|
-
last_exit_code: exitCode,
|
|
672
|
-
last_duration_ms: durationMs,
|
|
673
|
-
last_stdout: stdout,
|
|
674
|
-
last_stderr: stderr,
|
|
675
|
-
last_output: parsedOutput || undefined,
|
|
676
|
-
next_attempt_at: nextAttemptAt,
|
|
677
|
-
updated_at: finishedAt
|
|
678
|
-
},
|
|
679
|
-
updatedAt: finishedAt
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
);
|
|
683
|
-
|
|
684
|
-
console.error(new Date(), '[AI Assistant Codex Manager] remediation failed', {
|
|
685
|
-
id_issue_report: issueId,
|
|
686
|
-
attempt: attemptCount,
|
|
687
|
-
reason,
|
|
688
|
-
exitCode,
|
|
689
|
-
durationMs
|
|
690
|
-
});
|
|
691
|
-
|
|
692
|
-
return {
|
|
693
|
-
status: 'failed',
|
|
694
|
-
reason,
|
|
695
|
-
issueId,
|
|
696
|
-
attemptCount,
|
|
697
|
-
durationMs,
|
|
698
|
-
exitCode
|
|
699
|
-
};
|
|
700
|
-
}
|
|
701
|
-
finally {
|
|
702
|
-
if (contextPath) {
|
|
703
|
-
try {
|
|
704
|
-
await fs.unlink(contextPath);
|
|
705
|
-
}
|
|
706
|
-
catch {
|
|
707
|
-
// Ignore cleanup failures.
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
public async runIssueReplay(
|
|
714
|
-
issueReportId: string,
|
|
715
|
-
options: { force?: boolean; source?: 'auto' | 'manual'; trigger?: string } = {}
|
|
716
|
-
): Promise<Record<string, any>> {
|
|
717
|
-
const issueId = normalizeOptionalString(issueReportId);
|
|
718
|
-
if (!issueId) {
|
|
719
|
-
return {
|
|
720
|
-
status: 'failed',
|
|
721
|
-
reason: 'Issue report id is required.'
|
|
722
|
-
};
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
const source = options.source === 'manual' ? 'manual' : 'auto';
|
|
726
|
-
if (!this.config.autoReplayEnabled && source !== 'manual') {
|
|
727
|
-
return {
|
|
728
|
-
status: 'skipped',
|
|
729
|
-
reason: 'Auto replay is disabled.'
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
if (!this.config.replayCommand) {
|
|
733
|
-
return {
|
|
734
|
-
status: 'skipped',
|
|
735
|
-
reason: 'Replay command is not configured.'
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
const issue = await AiTerminalIssueReports.findById(issueId) as Record<string, any> | null;
|
|
740
|
-
if (!issue) {
|
|
741
|
-
return {
|
|
742
|
-
status: 'not_found',
|
|
743
|
-
reason: 'Issue report not found.'
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
const force = options.force === true;
|
|
748
|
-
const now = new Date();
|
|
749
|
-
const metadata = this.normalizeMetadata(issue.metadata);
|
|
750
|
-
const qualityManager = this.normalizeMetadata(metadata.quality_manager);
|
|
751
|
-
const replay = this.normalizeMetadata(qualityManager.replay);
|
|
752
|
-
const existingStatus = normalizeOptionalString(replay.status).toLowerCase();
|
|
753
|
-
const attemptsUsed = Number.isFinite(Number(replay.attempt_count)) ? Number(replay.attempt_count) : 0;
|
|
754
|
-
const maxAttempts = this.config.replayMaxAttemptsPerIssue;
|
|
755
|
-
const cooldownMinutes = this.config.replayCooldownMinutes;
|
|
756
|
-
const cooldownMs = cooldownMinutes * 60 * 1000;
|
|
757
|
-
const lastAttemptAt = this.parseDate(replay.last_attempt_at);
|
|
758
|
-
if (!force && existingStatus === 'running') {
|
|
759
|
-
return {
|
|
760
|
-
status: 'running',
|
|
761
|
-
reason: 'Replay already running.',
|
|
762
|
-
issueId
|
|
763
|
-
};
|
|
764
|
-
}
|
|
765
|
-
if (!force && existingStatus === 'success') {
|
|
766
|
-
return {
|
|
767
|
-
status: 'skipped',
|
|
768
|
-
reason: 'Replay already succeeded.',
|
|
769
|
-
issueId
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
if (!force && maxAttempts > 0 && attemptsUsed >= maxAttempts) {
|
|
773
|
-
return {
|
|
774
|
-
status: 'skipped',
|
|
775
|
-
reason: `Replay attempt budget reached (${attemptsUsed}/${maxAttempts}).`,
|
|
776
|
-
issueId
|
|
777
|
-
};
|
|
778
|
-
}
|
|
779
|
-
if (!force && existingStatus === 'failed' && lastAttemptAt) {
|
|
780
|
-
const ageMs = now.getTime() - lastAttemptAt.getTime();
|
|
781
|
-
if (ageMs >= 0 && ageMs < cooldownMs) {
|
|
782
|
-
return {
|
|
783
|
-
status: 'skipped',
|
|
784
|
-
reason: 'Replay cooldown active.',
|
|
785
|
-
issueId,
|
|
786
|
-
nextAttemptAt: new Date(lastAttemptAt.getTime() + cooldownMs)
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
const attemptCount = attemptsUsed + 1;
|
|
792
|
-
await AiTerminalIssueReports.updateOne(
|
|
793
|
-
{ _id: issueId },
|
|
794
|
-
{
|
|
795
|
-
$set: {
|
|
796
|
-
'metadata.quality_manager.replay': {
|
|
797
|
-
...replay,
|
|
798
|
-
status: 'running',
|
|
799
|
-
source,
|
|
800
|
-
trigger: normalizeOptionalString(options.trigger) || 'unspecified',
|
|
801
|
-
attempt_count: attemptCount,
|
|
802
|
-
max_attempts: maxAttempts,
|
|
803
|
-
cooldown_minutes: cooldownMinutes,
|
|
804
|
-
command: this.config.replayCommand,
|
|
805
|
-
last_attempt_at: now,
|
|
806
|
-
updated_at: now,
|
|
807
|
-
last_error: '',
|
|
808
|
-
last_exit_code: null
|
|
809
|
-
},
|
|
810
|
-
updatedAt: now
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
);
|
|
814
|
-
|
|
815
|
-
const startedAtMs = Date.now();
|
|
816
|
-
const contextPath = await this.writeReplayContextFile(issue, {
|
|
817
|
-
issueId,
|
|
818
|
-
attemptCount,
|
|
819
|
-
source,
|
|
820
|
-
trigger: normalizeOptionalString(options.trigger) || 'unspecified'
|
|
821
|
-
});
|
|
822
|
-
let parsedOutput: Record<string, any> | null = null;
|
|
823
|
-
try {
|
|
824
|
-
const execResult = await execFileAsync(
|
|
825
|
-
'/bin/bash',
|
|
826
|
-
['-lc', this.config.replayCommand],
|
|
827
|
-
{
|
|
828
|
-
timeout: this.config.replayTimeoutMs,
|
|
829
|
-
maxBuffer: this.config.replayMaxBufferBytes,
|
|
830
|
-
env: {
|
|
831
|
-
...process.env,
|
|
832
|
-
RIO_AI_ASSISTANT_REPLAY_CONTEXT: contextPath,
|
|
833
|
-
RIO_AI_ASSISTANT_REPLAY_ISSUE_ID: issueId
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
);
|
|
837
|
-
const finishedAt = new Date();
|
|
838
|
-
const durationMs = Date.now() - startedAtMs;
|
|
839
|
-
const stdout = this.toSafeOutput(execResult?.stdout);
|
|
840
|
-
const stderr = this.toSafeOutput(execResult?.stderr);
|
|
841
|
-
parsedOutput = this.parseOutputJson(stdout);
|
|
842
|
-
const outputStatus = normalizeOptionalString(parsedOutput?.status).toLowerCase();
|
|
843
|
-
const success = outputStatus ? ['success', 'ok', 'completed', 'pass'].includes(outputStatus) : true;
|
|
844
|
-
const replayStatus = success ? 'success' : 'failed';
|
|
845
|
-
const replayReason = normalizeOptionalString(parsedOutput?.reason)
|
|
846
|
-
|| (success ? 'Replay command completed successfully.' : 'Replay command reported a non-success status.');
|
|
847
|
-
|
|
848
|
-
await AiTerminalIssueReports.updateOne(
|
|
849
|
-
{ _id: issueId },
|
|
850
|
-
{
|
|
851
|
-
$set: {
|
|
852
|
-
'metadata.quality_manager.replay': {
|
|
853
|
-
...replay,
|
|
854
|
-
status: replayStatus,
|
|
855
|
-
source,
|
|
856
|
-
trigger: normalizeOptionalString(options.trigger) || 'unspecified',
|
|
857
|
-
attempt_count: attemptCount,
|
|
858
|
-
max_attempts: maxAttempts,
|
|
859
|
-
cooldown_minutes: cooldownMinutes,
|
|
860
|
-
command: this.config.replayCommand,
|
|
861
|
-
last_attempt_at: now,
|
|
862
|
-
last_success_at: success ? finishedAt : replay.last_success_at,
|
|
863
|
-
last_error: success ? '' : replayReason,
|
|
864
|
-
last_exit_code: success ? 0 : null,
|
|
865
|
-
last_duration_ms: durationMs,
|
|
866
|
-
last_stdout: stdout,
|
|
867
|
-
last_stderr: stderr,
|
|
868
|
-
last_output: parsedOutput || undefined,
|
|
869
|
-
updated_at: finishedAt
|
|
870
|
-
},
|
|
871
|
-
updatedAt: finishedAt
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
);
|
|
875
|
-
|
|
876
|
-
console.log(new Date(), '[AI Assistant Codex Manager] replay completed', {
|
|
877
|
-
id_issue_report: issueId,
|
|
878
|
-
status: replayStatus,
|
|
879
|
-
attempt: attemptCount,
|
|
880
|
-
durationMs
|
|
881
|
-
});
|
|
882
|
-
|
|
883
|
-
return {
|
|
884
|
-
status: replayStatus,
|
|
885
|
-
reason: replayReason,
|
|
886
|
-
issueId,
|
|
887
|
-
attemptCount,
|
|
888
|
-
durationMs
|
|
889
|
-
};
|
|
890
|
-
}
|
|
891
|
-
catch (error) {
|
|
892
|
-
const finishedAt = new Date();
|
|
893
|
-
const durationMs = Date.now() - startedAtMs;
|
|
894
|
-
const err: any = error || {};
|
|
895
|
-
const stdout = this.toSafeOutput(err.stdout);
|
|
896
|
-
const stderr = this.toSafeOutput(err.stderr);
|
|
897
|
-
const exitCode = Number.isFinite(Number(err.code)) ? Number(err.code) : null;
|
|
898
|
-
const timeoutHit = err?.killed === true || normalizeOptionalString(err?.signal).toUpperCase() === 'SIGTERM';
|
|
899
|
-
const reason = timeoutHit
|
|
900
|
-
? `Replay command timed out after ${this.config.replayTimeoutMs}ms.`
|
|
901
|
-
: (normalizeOptionalString(err?.message) || 'Replay command failed.');
|
|
902
|
-
const nextAttemptAt = new Date(finishedAt.getTime() + cooldownMs);
|
|
903
|
-
|
|
904
|
-
await AiTerminalIssueReports.updateOne(
|
|
905
|
-
{ _id: issueId },
|
|
906
|
-
{
|
|
907
|
-
$set: {
|
|
908
|
-
'metadata.quality_manager.replay': {
|
|
909
|
-
...replay,
|
|
910
|
-
status: 'failed',
|
|
911
|
-
source,
|
|
912
|
-
trigger: normalizeOptionalString(options.trigger) || 'unspecified',
|
|
913
|
-
attempt_count: attemptCount,
|
|
914
|
-
max_attempts: maxAttempts,
|
|
915
|
-
cooldown_minutes: cooldownMinutes,
|
|
916
|
-
command: this.config.replayCommand,
|
|
917
|
-
last_attempt_at: now,
|
|
918
|
-
last_error: reason,
|
|
919
|
-
last_exit_code: exitCode,
|
|
920
|
-
last_duration_ms: durationMs,
|
|
921
|
-
last_stdout: stdout,
|
|
922
|
-
last_stderr: stderr,
|
|
923
|
-
last_output: parsedOutput || undefined,
|
|
924
|
-
next_attempt_at: nextAttemptAt,
|
|
925
|
-
updated_at: finishedAt
|
|
926
|
-
},
|
|
927
|
-
updatedAt: finishedAt
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
);
|
|
931
|
-
|
|
932
|
-
console.error(new Date(), '[AI Assistant Codex Manager] replay failed', {
|
|
933
|
-
id_issue_report: issueId,
|
|
934
|
-
attempt: attemptCount,
|
|
935
|
-
reason,
|
|
936
|
-
exitCode,
|
|
937
|
-
durationMs
|
|
938
|
-
});
|
|
939
|
-
|
|
940
|
-
return {
|
|
941
|
-
status: 'failed',
|
|
942
|
-
reason,
|
|
943
|
-
issueId,
|
|
944
|
-
attemptCount,
|
|
945
|
-
durationMs,
|
|
946
|
-
exitCode
|
|
947
|
-
};
|
|
948
|
-
}
|
|
949
|
-
finally {
|
|
950
|
-
if (contextPath) {
|
|
951
|
-
try {
|
|
952
|
-
await fs.unlink(contextPath);
|
|
953
|
-
}
|
|
954
|
-
catch {
|
|
955
|
-
// Ignore cleanup failures.
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
private async markMessageQualityReviewed(messageId: string, decision: AiAssistantQualityDecision, issueReportId = ''): Promise<void> {
|
|
962
|
-
const now = new Date();
|
|
963
|
-
const qualityPayload: Record<string, any> = {
|
|
964
|
-
status: decision.status,
|
|
965
|
-
reason: decision.reason,
|
|
966
|
-
code: decision.code,
|
|
967
|
-
checked_at: now,
|
|
968
|
-
worker_index: normalizeOptionalString(process.env.WORKER_INDEX),
|
|
969
|
-
worker_instance: normalizeOptionalString(process.env.NODE_APP_INSTANCE)
|
|
970
|
-
};
|
|
971
|
-
if (issueReportId) {
|
|
972
|
-
qualityPayload.id_issue_report = issueReportId;
|
|
973
|
-
}
|
|
974
|
-
await AiTerminalMessages.updateOne(
|
|
975
|
-
{ _id: messageId },
|
|
976
|
-
{
|
|
977
|
-
$set: {
|
|
978
|
-
'metadata.quality_manager': qualityPayload,
|
|
979
|
-
updatedAt: now
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
);
|
|
983
|
-
if (this.config.debug) {
|
|
984
|
-
console.log(new Date(), '[AI Assistant Codex Manager] checked message', {
|
|
985
|
-
id_message: messageId,
|
|
986
|
-
status: decision.status,
|
|
987
|
-
code: decision.code,
|
|
988
|
-
id_issue_report: issueReportId || null
|
|
989
|
-
});
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
private async resolveClosestUserPrompt(conversationId: string, assistantCreatedAt?: Date): Promise<string> {
|
|
994
|
-
const query: Record<string, any> = {
|
|
995
|
-
id_conversation: conversationId,
|
|
996
|
-
role: 'user'
|
|
997
|
-
};
|
|
998
|
-
const createdAt = assistantCreatedAt ? new Date(assistantCreatedAt) : null;
|
|
999
|
-
if (createdAt && Number.isFinite(createdAt.getTime())) {
|
|
1000
|
-
query.createdAt = { $lte: createdAt };
|
|
1001
|
-
}
|
|
1002
|
-
const userMessage = await AiTerminalMessages.findOne(query, { sort: { createdAt: -1 } }) as AiTerminalMessageModel | null;
|
|
1003
|
-
return normalizeOptionalString(userMessage?.content);
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
private async writeRemediationContextFile(issue: Record<string, any>, options: Record<string, any>): Promise<string> {
|
|
1007
|
-
const issueId = normalizeOptionalString(issue?._id);
|
|
1008
|
-
const filePath = path.join(os.tmpdir(), `resolveio-ai-assistant-remediation-${issueId}-${Date.now()}.json`);
|
|
1009
|
-
const payload = {
|
|
1010
|
-
created_at: new Date().toISOString(),
|
|
1011
|
-
issue_report: {
|
|
1012
|
-
_id: issueId,
|
|
1013
|
-
status: normalizeOptionalString(issue?.status),
|
|
1014
|
-
source: normalizeOptionalString(issue?.source),
|
|
1015
|
-
reason: normalizeOptionalString(issue?.reason),
|
|
1016
|
-
id_conversation: normalizeOptionalString(issue?.id_conversation),
|
|
1017
|
-
id_message: normalizeOptionalString(issue?.id_message),
|
|
1018
|
-
id_client: normalizeOptionalString(issue?.id_client),
|
|
1019
|
-
id_app: normalizeOptionalString(issue?.id_app),
|
|
1020
|
-
id_user: normalizeOptionalString(issue?.id_user),
|
|
1021
|
-
request_id: normalizeOptionalString(issue?.request_id),
|
|
1022
|
-
user_prompt: normalizeOptionalString(issue?.user_prompt),
|
|
1023
|
-
assistant_content: normalizeOptionalString(issue?.assistant_content)
|
|
1024
|
-
},
|
|
1025
|
-
remediation: {
|
|
1026
|
-
source: normalizeOptionalString(options?.source),
|
|
1027
|
-
trigger: normalizeOptionalString(options?.trigger),
|
|
1028
|
-
attempt_count: Number(options?.attemptCount) || 0,
|
|
1029
|
-
max_attempts: this.config.remediationMaxAttemptsPerIssue,
|
|
1030
|
-
cooldown_minutes: this.config.remediationCooldownMinutes
|
|
1031
|
-
}
|
|
1032
|
-
};
|
|
1033
|
-
await fs.writeFile(filePath, JSON.stringify(payload, null, 2), 'utf8');
|
|
1034
|
-
return filePath;
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
private async writeReplayContextFile(issue: Record<string, any>, options: Record<string, any>): Promise<string> {
|
|
1038
|
-
const issueId = normalizeOptionalString(issue?._id);
|
|
1039
|
-
const metadata = this.normalizeMetadata(issue?.metadata);
|
|
1040
|
-
const qualityManager = this.normalizeMetadata(metadata.quality_manager);
|
|
1041
|
-
const remediation = this.normalizeMetadata(qualityManager.remediation);
|
|
1042
|
-
const filePath = path.join(os.tmpdir(), `resolveio-ai-assistant-replay-${issueId}-${Date.now()}.json`);
|
|
1043
|
-
const payload = {
|
|
1044
|
-
created_at: new Date().toISOString(),
|
|
1045
|
-
issue_report: {
|
|
1046
|
-
_id: issueId,
|
|
1047
|
-
status: normalizeOptionalString(issue?.status),
|
|
1048
|
-
source: normalizeOptionalString(issue?.source),
|
|
1049
|
-
reason: normalizeOptionalString(issue?.reason),
|
|
1050
|
-
id_conversation: normalizeOptionalString(issue?.id_conversation),
|
|
1051
|
-
id_message: normalizeOptionalString(issue?.id_message),
|
|
1052
|
-
id_client: normalizeOptionalString(issue?.id_client),
|
|
1053
|
-
id_app: normalizeOptionalString(issue?.id_app),
|
|
1054
|
-
id_user: normalizeOptionalString(issue?.id_user),
|
|
1055
|
-
request_id: normalizeOptionalString(issue?.request_id),
|
|
1056
|
-
user_prompt: normalizeOptionalString(issue?.user_prompt),
|
|
1057
|
-
assistant_content: normalizeOptionalString(issue?.assistant_content)
|
|
1058
|
-
},
|
|
1059
|
-
remediation: {
|
|
1060
|
-
status: normalizeOptionalString(remediation.status),
|
|
1061
|
-
last_attempt_at: remediation.last_attempt_at || null,
|
|
1062
|
-
last_success_at: remediation.last_success_at || null,
|
|
1063
|
-
last_error: normalizeOptionalString(remediation.last_error),
|
|
1064
|
-
attempt_count: Number(remediation.attempt_count) || 0
|
|
1065
|
-
},
|
|
1066
|
-
replay: {
|
|
1067
|
-
source: normalizeOptionalString(options?.source),
|
|
1068
|
-
trigger: normalizeOptionalString(options?.trigger),
|
|
1069
|
-
attempt_count: Number(options?.attemptCount) || 0,
|
|
1070
|
-
max_attempts: this.config.replayMaxAttemptsPerIssue,
|
|
1071
|
-
cooldown_minutes: this.config.replayCooldownMinutes,
|
|
1072
|
-
command: this.config.replayCommand
|
|
1073
|
-
}
|
|
1074
|
-
};
|
|
1075
|
-
await fs.writeFile(filePath, JSON.stringify(payload, null, 2), 'utf8');
|
|
1076
|
-
return filePath;
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
private parseOutputJson(stdout: string): Record<string, any> | null {
|
|
1080
|
-
const text = normalizeOptionalString(stdout);
|
|
1081
|
-
if (!text) {
|
|
1082
|
-
return null;
|
|
1083
|
-
}
|
|
1084
|
-
const firstChar = text.charAt(0);
|
|
1085
|
-
if (firstChar !== '{' && firstChar !== '[') {
|
|
1086
|
-
return null;
|
|
1087
|
-
}
|
|
1088
|
-
try {
|
|
1089
|
-
const parsed = JSON.parse(text);
|
|
1090
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
1091
|
-
return null;
|
|
1092
|
-
}
|
|
1093
|
-
return parsed;
|
|
1094
|
-
}
|
|
1095
|
-
catch {
|
|
1096
|
-
return null;
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
private toSafeOutput(value: any): string {
|
|
1101
|
-
const asString = typeof value === 'string'
|
|
1102
|
-
? value
|
|
1103
|
-
: (Buffer.isBuffer(value) ? value.toString('utf8') : String(value || ''));
|
|
1104
|
-
const normalized = asString.trim();
|
|
1105
|
-
if (!normalized) {
|
|
1106
|
-
return '';
|
|
1107
|
-
}
|
|
1108
|
-
if (normalized.length <= MAX_STORED_OUTPUT_CHARS) {
|
|
1109
|
-
return normalized;
|
|
1110
|
-
}
|
|
1111
|
-
return normalized.slice(0, MAX_STORED_OUTPUT_CHARS);
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
private parseDate(value: any): Date | null {
|
|
1115
|
-
if (!value) {
|
|
1116
|
-
return null;
|
|
1117
|
-
}
|
|
1118
|
-
const date = value instanceof Date ? value : new Date(value);
|
|
1119
|
-
if (!Number.isFinite(date.getTime())) {
|
|
1120
|
-
return null;
|
|
1121
|
-
}
|
|
1122
|
-
return date;
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
private normalizeMetadata(value: any): Record<string, any> {
|
|
1126
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
1127
|
-
return {};
|
|
1128
|
-
}
|
|
1129
|
-
return value;
|
|
1130
|
-
}
|
|
1131
|
-
}
|