@yrpri/api 9.0.103 → 9.0.105
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/package.json +1 -2
- package/dist/active-citizen/controllers/activities.cjs +0 -174
- package/dist/active-citizen/controllers/news_feeds.cjs +0 -96
- package/dist/active-citizen/controllers/notifications.cjs +0 -243
- package/dist/active-citizen/controllers/recommendations.cjs +0 -280
- package/dist/active-citizen/engine/allOurIdeas/aiHelper.js +0 -204
- package/dist/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +0 -66
- package/dist/active-citizen/engine/allOurIdeas/iconGenerator.js +0 -38
- package/dist/active-citizen/engine/analytics/export_anon_community_activities.js +0 -334
- package/dist/active-citizen/engine/analytics/importer.js +0 -308
- package/dist/active-citizen/engine/analytics/manager.cjs +0 -377
- package/dist/active-citizen/engine/analytics/plausible/manager.cjs +0 -500
- package/dist/active-citizen/engine/analytics/statsCalc.cjs +0 -194
- package/dist/active-citizen/engine/analytics/utils.cjs +0 -369
- package/dist/active-citizen/engine/marketing/campaign.cjs +0 -90
- package/dist/active-citizen/engine/moderation/fraud/CreateFraudAuditReport.cjs +0 -313
- package/dist/active-citizen/engine/moderation/fraud/FraudBase.cjs +0 -239
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteBase.cjs +0 -211
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteEndorsements.cjs +0 -120
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePointQualities.cjs +0 -114
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePoints.cjs +0 -101
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePosts.cjs +0 -84
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteRatings.cjs +0 -15
- package/dist/active-citizen/engine/moderation/fraud/FraudGetBase.cjs +0 -133
- package/dist/active-citizen/engine/moderation/fraud/FraudGetEndorsements.cjs +0 -185
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPointQualities.cjs +0 -184
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPoints.cjs +0 -170
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPosts.cjs +0 -109
- package/dist/active-citizen/engine/moderation/fraud/FraudGetRatings.cjs +0 -140
- package/dist/active-citizen/engine/moderation/fraud/FraudScannerNotifier.cjs +0 -279
- package/dist/active-citizen/engine/moderation/get_moderation_items.cjs +0 -386
- package/dist/active-citizen/engine/moderation/image_labeling/CommunityLabeling.cjs +0 -49
- package/dist/active-citizen/engine/moderation/image_labeling/GroupLabeling.cjs +0 -68
- package/dist/active-citizen/engine/moderation/image_labeling/ImageLabelingBase.cjs +0 -288
- package/dist/active-citizen/engine/moderation/image_labeling/PointLabeling.cjs +0 -33
- package/dist/active-citizen/engine/moderation/image_labeling/PostLabeling.cjs +0 -56
- package/dist/active-citizen/engine/moderation/perspective_api_client.cjs +0 -106
- package/dist/active-citizen/engine/moderation/process_moderation_items.cjs +0 -344
- package/dist/active-citizen/engine/moderation/toxicity_analysis.cjs +0 -810
- package/dist/active-citizen/engine/news_feeds/activity_and_item_index_definitions.cjs +0 -15
- package/dist/active-citizen/engine/news_feeds/generate_dynamically.cjs +0 -362
- package/dist/active-citizen/engine/news_feeds/generate_from_notifications.cjs +0 -268
- package/dist/active-citizen/engine/news_feeds/news_feeds_utils.cjs +0 -439
- package/dist/active-citizen/engine/notifications/emails_utils.cjs +0 -569
- package/dist/active-citizen/engine/notifications/generate_point_notifications.cjs +0 -233
- package/dist/active-citizen/engine/notifications/generate_post_notifications.cjs +0 -118
- package/dist/active-citizen/engine/notifications/generate_post_status_change_notifications.cjs +0 -41
- package/dist/active-citizen/engine/notifications/notifications_utils.cjs +0 -148
- package/dist/active-citizen/engine/notifications/point_delivery.cjs +0 -54
- package/dist/active-citizen/engine/notifications/post_delivery.cjs +0 -31
- package/dist/active-citizen/engine/notifications/process_delayed_notifications.cjs +0 -471
- package/dist/active-citizen/engine/notifications/process_general_notifications.cjs +0 -212
- package/dist/active-citizen/engine/old/exporters/categories_dataset.js +0 -153
- package/dist/active-citizen/engine/old/exporters/dataset_tools.js +0 -80
- package/dist/active-citizen/engine/old/exporters/sentiment_dataset.js +0 -157
- package/dist/active-citizen/engine/recommendations/events_importer.cjs +0 -139
- package/dist/active-citizen/engine/recommendations/events_manager.cjs +0 -212
- package/dist/active-citizen/engine/reports/add_points_to_sheet.cjs +0 -83
- package/dist/active-citizen/engine/reports/commonUtils.js +0 -75
- package/dist/active-citizen/engine/reports/common_utils.cjs +0 -740
- package/dist/active-citizen/engine/reports/docx_group_report.cjs +0 -596
- package/dist/active-citizen/engine/reports/xlsAllOurIdeasExport.js +0 -232
- package/dist/active-citizen/engine/reports/xls_community_users_report.cjs +0 -277
- package/dist/active-citizen/engine/reports/xls_group_report.cjs +0 -718
- package/dist/active-citizen/llms/baseChatBot.js +0 -183
- package/dist/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +0 -56
- package/dist/active-citizen/llms/imageGeneration/collectionImageGenerator.js +0 -109
- package/dist/active-citizen/llms/imageGeneration/dalleImageGenerator.js +0 -84
- package/dist/active-citizen/llms/imageGeneration/fluxImageGenerator.js +0 -49
- package/dist/active-citizen/llms/imageGeneration/iImageGenerator.js +0 -1
- package/dist/active-citizen/llms/imageGeneration/imageProcessorService.js +0 -64
- package/dist/active-citizen/llms/imageGeneration/imagenImageGenerator.js +0 -107
- package/dist/active-citizen/llms/imageGeneration/s3Service.js +0 -110
- package/dist/active-citizen/llms/llmTranslation.js +0 -472
- package/dist/active-citizen/models/ac_activity.cjs +0 -216
- package/dist/active-citizen/models/ac_background_job.cjs +0 -109
- package/dist/active-citizen/models/ac_campaign.cjs +0 -97
- package/dist/active-citizen/models/ac_client_activity.cjs +0 -23
- package/dist/active-citizen/models/ac_delayed_notification.cjs +0 -43
- package/dist/active-citizen/models/ac_following.cjs +0 -43
- package/dist/active-citizen/models/ac_list.cjs +0 -68
- package/dist/active-citizen/models/ac_list_users.cjs +0 -19
- package/dist/active-citizen/models/ac_mute.cjs +0 -27
- package/dist/active-citizen/models/ac_news_feed_item.cjs +0 -57
- package/dist/active-citizen/models/ac_news_feed_processed_range.cjs +0 -59
- package/dist/active-citizen/models/ac_notification.cjs +0 -292
- package/dist/active-citizen/models/ac_translation_cache.cjs +0 -750
- package/dist/active-citizen/models/ac_watching.cjs +0 -31
- package/dist/active-citizen/scripts/analytics/setup_all_plausible_goals.cjs +0 -13
- package/dist/active-citizen/scripts/fix_old_delayed_notifications.js +0 -63
- package/dist/active-citizen/scripts/kue_status.js +0 -31
- package/dist/active-citizen/scripts/kue_watch_stuck_jobs.js +0 -24
- package/dist/active-citizen/scripts/translation_clear_language.js +0 -117
- package/dist/active-citizen/scripts/translation_delete.js +0 -27
- package/dist/active-citizen/scripts/translation_replace_text_from_url.js +0 -180
- package/dist/active-citizen/scripts/translation_update.js +0 -28
- package/dist/active-citizen/scripts/translations_list.js +0 -27
- package/dist/active-citizen/utils/airbrake.cjs +0 -17
- package/dist/active-citizen/utils/get_anonymous_system_user.cjs +0 -21
- package/dist/active-citizen/utils/i18n.cjs +0 -3
- package/dist/active-citizen/utils/logger.cjs +0 -25
- package/dist/active-citizen/utils/redisConnection.cjs +0 -29
- package/dist/active-citizen/utils/to_json.cjs +0 -9
- package/dist/active-citizen/utils/translation_cloning.cjs +0 -171
- package/dist/active-citizen/utils/translation_helpers.cjs +0 -534
- package/dist/active-citizen/utils/truncate_text.cjs +0 -21
- package/dist/active-citizen/utils/updateAllLocalesFromEn.js +0 -253
- package/dist/active-citizen/utils/updateLocaleFolders.js +0 -34
- package/dist/active-citizen/workers/activity.cjs +0 -189
- package/dist/active-citizen/workers/anonymizations.cjs +0 -734
- package/dist/active-citizen/workers/bulk_status_update.cjs +0 -458
- package/dist/active-citizen/workers/delayed_jobs.cjs +0 -244
- package/dist/active-citizen/workers/deletions.cjs +0 -1911
- package/dist/active-citizen/workers/email.cjs +0 -9
- package/dist/active-citizen/workers/fraud_management.cjs +0 -109
- package/dist/active-citizen/workers/generativeAi.js +0 -56
- package/dist/active-citizen/workers/main.cjs +0 -89
- package/dist/active-citizen/workers/marketing.cjs +0 -25
- package/dist/active-citizen/workers/moderation.cjs +0 -73
- package/dist/active-citizen/workers/notification_delivery.cjs +0 -368
- package/dist/active-citizen/workers/notification_news_feed.cjs +0 -142
- package/dist/active-citizen/workers/queue.cjs +0 -99
- package/dist/active-citizen/workers/recount.cjs +0 -74
- package/dist/active-citizen/workers/reports.cjs +0 -42
- package/dist/active-citizen/workers/similarities.cjs +0 -21
- package/dist/active-citizen/workers/speech_to_text.cjs +0 -482
- package/dist/agents/assistants/agentAssistant.js +0 -88
- package/dist/agents/assistants/baseAssistant.js +0 -888
- package/dist/agents/assistants/baseAssistantWithVoice.js +0 -150
- package/dist/agents/assistants/modes/agentDirectConnection.js +0 -84
- package/dist/agents/assistants/modes/agentSelectionMode.js +0 -44
- package/dist/agents/assistants/modes/baseAssistantMode.js +0 -54
- package/dist/agents/assistants/modes/tools/agentTools.js +0 -447
- package/dist/agents/assistants/modes/tools/baseTools.js +0 -58
- package/dist/agents/assistants/modes/tools/loginTools.js +0 -156
- package/dist/agents/assistants/modes/tools/models/agents.js +0 -146
- package/dist/agents/assistants/modes/tools/models/subscriptions.js +0 -332
- package/dist/agents/assistants/modes/tools/models/users.js +0 -11
- package/dist/agents/assistants/modes/tools/navigationTools.js +0 -166
- package/dist/agents/assistants/modes/tools/subscriptionTools.js +0 -323
- package/dist/agents/assistants/modes/tools/workflowConverstationTools.js +0 -112
- package/dist/agents/assistants/voiceAssistant.js +0 -619
- package/dist/agents/controllers/agentProductController.js +0 -103
- package/dist/agents/controllers/agentSubscriptionController.js +0 -261
- package/dist/agents/controllers/assistantsController.js +0 -511
- package/dist/agents/controllers/policySynthAgents.js +0 -395
- package/dist/agents/managers/agentProductManager.js +0 -91
- package/dist/agents/managers/emailInvitesManager.js +0 -55
- package/dist/agents/managers/emailTemplateRenderer.js +0 -362
- package/dist/agents/managers/newAiModelSetup.js +0 -650
- package/dist/agents/managers/notificationAgentQueueManager.js +0 -510
- package/dist/agents/managers/subscriptionManager.js +0 -535
- package/dist/agents/managers/workflowConversationManager.js +0 -79
- package/dist/agents/models/agentProduct.js +0 -116
- package/dist/agents/models/agentProductBoosterPurchase.js +0 -58
- package/dist/agents/models/agentProductBundle.js +0 -68
- package/dist/agents/models/agentProductRun.js +0 -52
- package/dist/agents/models/discount.js +0 -88
- package/dist/agents/models/subscription.js +0 -79
- package/dist/agents/models/subscriptionPlan.js +0 -46
- package/dist/agents/models/subscriptionUser.js +0 -27
- package/dist/agents/models/testData/createEvolyAgentProduct.js +0 -477
- package/dist/agents/models/testData/old/updateAgentWorkflowConfiguration.js +0 -230
- package/dist/agents/models/testData/setupEvolyAgentProductConfig.js +0 -233
- package/dist/agents/models/testData/updateAgentWorkflowConfiguration.js +0 -230
- package/dist/agents/models/workflowConversation.js +0 -53
- package/dist/agents/tools/setTemplateWorkflowCommunityId.js +0 -46
- package/dist/app.js +0 -943
- package/dist/authorization.cjs +0 -1860
- package/dist/bot_control.js +0 -1930
- package/dist/config/config.cjs +0 -14
- package/dist/config/config.js +0 -14
- package/dist/controllers/allOurIdeas.js +0 -696
- package/dist/controllers/audios.cjs +0 -100
- package/dist/controllers/bulkStatusUpdates.cjs +0 -202
- package/dist/controllers/categories.cjs +0 -199
- package/dist/controllers/communities.cjs +0 -2996
- package/dist/controllers/domains.cjs +0 -1341
- package/dist/controllers/externalIds.cjs +0 -223
- package/dist/controllers/groups.cjs +0 -4309
- package/dist/controllers/images.cjs +0 -499
- package/dist/controllers/index.cjs +0 -449
- package/dist/controllers/legacyPages.cjs +0 -35
- package/dist/controllers/legacyPosts.cjs +0 -56
- package/dist/controllers/legacyUsers.cjs +0 -36
- package/dist/controllers/nonSpa.cjs +0 -574
- package/dist/controllers/organizations.cjs +0 -250
- package/dist/controllers/points.cjs +0 -1137
- package/dist/controllers/posts.cjs +0 -2036
- package/dist/controllers/ratings.cjs +0 -234
- package/dist/controllers/users.cjs +0 -2255
- package/dist/controllers/videos.cjs +0 -226
- package/dist/deleteUnwantedDeclerations.cjs +0 -55
- package/dist/migrations/agentAuditLogs.cjs +0 -46
- package/dist/migrations/agentClasses.cjs +0 -60
- package/dist/migrations/agentConnectorClasses.cjs +0 -61
- package/dist/migrations/agentConnectors.cjs +0 -50
- package/dist/migrations/agentEvals.cjs +0 -45
- package/dist/migrations/agentRegistries.cjs +0 -40
- package/dist/migrations/agents.cjs +0 -54
- package/dist/migrations/aiModels.cjs +0 -49
- package/dist/migrations/apiUsage.cjs +0 -47
- package/dist/migrations/apis.cjs +0 -49
- package/dist/migrations/groupPrivateData.cjs +0 -30
- package/dist/migrations/modelUsage.cjs +0 -60
- package/dist/migrations/oldMigrations/2019/20181030020612-AddActivitiesIndex.js +0 -23
- package/dist/migrations/oldMigrations/2019/20181102210612-AddFirstVideoFeatures.js +0 -360
- package/dist/migrations/oldMigrations/2019/20181212210612-ModerationFeatures.js +0 -29
- package/dist/migrations/oldMigrations/2019/2019010610612-CommunityFolders.js +0 -43
- package/dist/migrations/oldMigrations/2019/20190117020612-AddMissingIndexes.js +0 -24
- package/dist/migrations/oldMigrations/2019/20190117020612-RemoveUnusedIndexes.js +0 -29
- package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartThree.js +0 -22
- package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartTwo.js +0 -23
- package/dist/migrations/oldMigrations/2019/20190223020612-AddPrivateProfileDataToUsers.js +0 -18
- package/dist/migrations/oldMigrations/2019/20190706210612-AddCustomRatings.js +0 -43
- package/dist/migrations/oldMigrations/2019/20190829210612-AddGeneralStore.js +0 -36
- package/dist/migrations/oldMigrations/2019/20192811210612-AddAcClientActivities.js +0 -41
- package/dist/migrations/oldMigrations/2020/20190527020612-WorkOnIndexes.js +0 -88
- package/dist/migrations/oldMigrations/2020/20200409020612-AddBackgroundJob.js +0 -33
- package/dist/migrations/oldMigrations/2020/20200716210612-AddDataToCollections.js +0 -38
- package/dist/migrations/oldMigrations/2022/20220215100612-AddDataToEndorsements.js +0 -19
- package/dist/migrations/oldMigrations/2022/20220220100612-AddDataForFraudDetection.js +0 -19
- package/dist/migrations/oldMigrations/2022/20220903100612-AddPromotionFeatures.js +0 -127
- package/dist/migrations/oldMigrations/2022/onHold/20200527020612-AddCampaigns.js +0 -68
- package/dist/migrations/oldMigrations/2024/20241304175112-AddMediaSupportForHtmlGroups.cjs +0 -63
- package/dist/migrations/oldMigrations/older/20160511172514-AddNotificationFeatures.js +0 -14
- package/dist/migrations/oldMigrations/older/20161030020612-AddBulkStatusUpdate.js +0 -71
- package/dist/migrations/oldMigrations/older/20170514035258-add-metadata-to-invites.js +0 -12
- package/dist/migrations/oldMigrations/older/20180216020612-AddTranslationCaches.js +0 -46
- package/dist/migrations/oldMigrations/older/20180218210612-AddTranslationAndLanguages.js +0 -46
- package/dist/migrations/privateAccessStore.cjs +0 -55
- package/dist/migrations/zzz_associations.cjs +0 -154
- package/dist/migrations/zzzz_createUsersAndAdminsForClasses.cjs +0 -100
- package/dist/migrations/zzzzz_create_agent_runs.cjs +0 -606
- package/dist/migrations/zzzzzz_create_agent_runs_fix.cjs +0 -11
- package/dist/migrations/zzzzzzz_create_trees.cjs +0 -81
- package/dist/models/audio.cjs +0 -430
- package/dist/models/bulk_status_update.cjs +0 -58
- package/dist/models/campaign.cjs +0 -78
- package/dist/models/category.cjs +0 -94
- package/dist/models/community.cjs +0 -337
- package/dist/models/domain.cjs +0 -486
- package/dist/models/endorsement.cjs +0 -39
- package/dist/models/general_data_store.cjs +0 -20
- package/dist/models/group.cjs +0 -728
- package/dist/models/image.cjs +0 -579
- package/dist/models/index.cjs +0 -186
- package/dist/models/invite.cjs +0 -48
- package/dist/models/iso_country.cjs +0 -16
- package/dist/models/organization.cjs +0 -122
- package/dist/models/page.cjs +0 -273
- package/dist/models/point.cjs +0 -622
- package/dist/models/point_quality.cjs +0 -39
- package/dist/models/point_revision.cjs +0 -47
- package/dist/models/post.cjs +0 -680
- package/dist/models/post_revision.cjs +0 -38
- package/dist/models/post_status_change.cjs +0 -35
- package/dist/models/promotion.cjs +0 -34
- package/dist/models/rating.cjs +0 -51
- package/dist/models/relationship.cjs +0 -19
- package/dist/models/request_to_join.cjs +0 -20
- package/dist/models/user.cjs +0 -604
- package/dist/models/user_legacy_password.cjs +0 -13
- package/dist/models/video.cjs +0 -1137
- package/dist/publish.js +0 -40
- package/dist/repack.js +0 -53
- package/dist/scripts/addRatingUsersToGroup.js +0 -51
- package/dist/scripts/addUserToOrganization.js +0 -71
- package/dist/scripts/analyseRatingsForCommunity.js +0 -150
- package/dist/scripts/analyzeAndFixBrokenPointUsers.js +0 -28
- package/dist/scripts/analyzeEndorsementsByCountry.js +0 -70
- package/dist/scripts/analyzePostsForCommunity.js +0 -185
- package/dist/scripts/bulkStatusUpdates/listUpdates.js +0 -14
- package/dist/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +0 -110
- package/dist/scripts/bulkStatusUpdates/performUpdate.js +0 -116
- package/dist/scripts/bulkStatusUpdates/performUpdateForGroup.cjs +0 -124
- package/dist/scripts/bulkStatusUpdates/performUpdateForStatus.js +0 -141
- package/dist/scripts/change/changeVideoAspectTo.js +0 -34
- package/dist/scripts/change/setUseNewVersion.cjs +0 -22
- package/dist/scripts/changeCommunityGroupcount.js +0 -30
- package/dist/scripts/changeCommunityPostCount.js +0 -30
- package/dist/scripts/changeGroupPostCount.js +0 -30
- package/dist/scripts/changeLanguage.js +0 -50
- package/dist/scripts/changeOfficalStatus.js +0 -30
- package/dist/scripts/cleanups/deleteAnonNotifications.cjs +0 -91
- package/dist/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +0 -62
- package/dist/scripts/cleanups/deleteYearOldNotifications.cjs +0 -72
- package/dist/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +0 -43
- package/dist/scripts/clearAllEndorsementInGroup.js +0 -50
- package/dist/scripts/cloning/clearUsersForCommunitiesFromUrl.js +0 -129
- package/dist/scripts/cloning/cloneFromUrlScript.js +0 -65
- package/dist/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +0 -140
- package/dist/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +0 -140
- package/dist/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +0 -131
- package/dist/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +0 -173
- package/dist/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +0 -18
- package/dist/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +0 -17
- package/dist/scripts/cloning/copyCommunityToDomainWithEverything.js +0 -17
- package/dist/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +0 -26
- package/dist/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +0 -205
- package/dist/scripts/cloning/copyPostToGroupOld.js +0 -397
- package/dist/scripts/cloning/copyPostVideosFromURL.js +0 -236
- package/dist/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +0 -17
- package/dist/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +0 -131
- package/dist/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +0 -139
- package/dist/scripts/cloning/setAdminsFromURL.js +0 -161
- package/dist/scripts/cloning/setExternalIdsFromURL.js +0 -129
- package/dist/scripts/countCommunity.js +0 -291
- package/dist/scripts/countCommunityUsers.js +0 -152
- package/dist/scripts/countDelayedNotifications.js +0 -18
- package/dist/scripts/countGroup.js +0 -246
- package/dist/scripts/countStuff.js +0 -67
- package/dist/scripts/countUniqueVotersInAGroup.js +0 -48
- package/dist/scripts/createInvitesAndShow.js +0 -75
- package/dist/scripts/database/sync_database.js +0 -14
- package/dist/scripts/database/sync_dev_database.js +0 -17
- package/dist/scripts/debugNotifications.js +0 -58
- package/dist/scripts/deleteAllNewsFeeds.js +0 -10
- package/dist/scripts/deleteCategory.js +0 -13
- package/dist/scripts/deleteOldAppActivities.js +0 -40
- package/dist/scripts/deletePostContactDataForCommunity.js +0 -53
- package/dist/scripts/destroy/destroy_all_but_one_domain.js +0 -1026
- package/dist/scripts/displayAuthorForPost.js +0 -16
- package/dist/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +0 -183
- package/dist/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +0 -208
- package/dist/scripts/exportAllStatusChanges.js +0 -36
- package/dist/scripts/exportClientAcitivity.js +0 -36
- package/dist/scripts/exportEndorsementsForCommunity.js +0 -79
- package/dist/scripts/exportPointQualitiesForCommunity.js +0 -84
- package/dist/scripts/exportPostsAndPointsForCommunity.js +0 -147
- package/dist/scripts/exportPostsDataSetForDomain.js +0 -244
- package/dist/scripts/exportPostsForGroup.js +0 -173
- package/dist/scripts/exportRatingsForPost.js +0 -15
- package/dist/scripts/exportUserEndorsementsWithUserAnalysis.js +0 -123
- package/dist/scripts/exportUsersForCommunity.js +0 -24
- package/dist/scripts/exportUsersForDomain.js +0 -24
- package/dist/scripts/exportUsersForGroup.js +0 -24
- package/dist/scripts/exports/ratingDistribution.js +0 -71
- package/dist/scripts/exports/whoEndorsedWhatByCommunity.js +0 -56
- package/dist/scripts/findUnusedClientImports.js +0 -56
- package/dist/scripts/fixAllPostPointCounts.js +0 -22
- package/dist/scripts/fixAnonNotificationsSettings.js +0 -48
- package/dist/scripts/fixCountKopavogur.js +0 -9
- package/dist/scripts/fixEndorsementsAfterCopyPostToGroup.js +0 -190
- package/dist/scripts/fixExternalUserId.js +0 -24
- package/dist/scripts/fixGroupAccess.js +0 -16
- package/dist/scripts/fixGroupIdeasAndPointsCount.js +0 -49
- package/dist/scripts/fixNotificationSettings.js +0 -39
- package/dist/scripts/fixSurveyRadioBakedInSubCodes.js +0 -64
- package/dist/scripts/fixWrongUserIdForStatusUpdates.js +0 -49
- package/dist/scripts/gallery/exportGalleryData.js +0 -40
- package/dist/scripts/gallery/importGalleryForCommunity.js +0 -168
- package/dist/scripts/gallery/readJsonAndDownloadImagesVersion2.js +0 -55
- package/dist/scripts/gallery/refreshAcApiPostIdsForCommunity.js +0 -58
- package/dist/scripts/genderAnalysis.js +0 -63
- package/dist/scripts/genderAnalysisByStatus.js +0 -62
- package/dist/scripts/importAllLocalesFromLocalFolders.js +0 -55
- package/dist/scripts/importDomain.js +0 -1652
- package/dist/scripts/keys/addOidcToDomain.cjs +0 -61
- package/dist/scripts/landUseGame/export3Ddata.js +0 -162
- package/dist/scripts/listLanguagesForGroup.js +0 -54
- package/dist/scripts/loadTestCreateDummyContentForGroup.js +0 -27
- package/dist/scripts/makeRecursiveMapData.js +0 -103
- package/dist/scripts/mapping/community_map_csv.js +0 -145
- package/dist/scripts/moveCommunityToDomain.js +0 -22
- package/dist/scripts/moveGroupToCommunity.js +0 -23
- package/dist/scripts/movePostToGroup.js +0 -101
- package/dist/scripts/movePostsToGroupsRecountGroupFromUrl.js +0 -297
- package/dist/scripts/oldMovePostToGroup.js +0 -153
- package/dist/scripts/processCsvForPdfUrls.js +0 -37
- package/dist/scripts/processCsvForTranslationAndToxicity.js +0 -125
- package/dist/scripts/recount/recount_recursive_communities.js +0 -125
- package/dist/scripts/recountALLCommunityGroupCounts.js +0 -37
- package/dist/scripts/recountAll.js +0 -97
- package/dist/scripts/recountCommunitesFromUrl.js +0 -58
- package/dist/scripts/recountCommunity.js +0 -19
- package/dist/scripts/recountGroup.js +0 -218
- package/dist/scripts/recountGroupNoUserChange.js +0 -219
- package/dist/scripts/resetAllEndorsementsForGroup.js +0 -57
- package/dist/scripts/resetEnTranslationForGroup.js +0 -45
- package/dist/scripts/setAdminOnAll.cjs +0 -107
- package/dist/scripts/setDomainAdmin.cjs +0 -43
- package/dist/scripts/setDomainLocales.js +0 -33
- package/dist/scripts/setEarlQuestionIdOnGroup.cjs +0 -29
- package/dist/scripts/setLanguageOnGroupCommunitesFromUrl.js +0 -86
- package/dist/scripts/setMemberOfAll.js +0 -101
- package/dist/scripts/setNewUserForContentOfCommunity.js +0 -189
- package/dist/scripts/setOfficialStatusOnAllPostsForCommunity.js +0 -35
- package/dist/scripts/setUserOnAll.js +0 -101
- package/dist/scripts/showCategoryForGroup.js +0 -18
- package/dist/scripts/showOldActivityTypes.js +0 -14
- package/dist/scripts/showPostsMissingCategoryForGroup.js +0 -17
- package/dist/scripts/showStatuses.js +0 -17
- package/dist/scripts/showUniqueVotersInCommunity.js +0 -61
- package/dist/scripts/showUserAgentsAndIpsForEmails.js +0 -66
- package/dist/scripts/simpleExportForGroupsForCommunity.js +0 -46
- package/dist/scripts/simpleExportForPointsForCommunity.js +0 -82
- package/dist/scripts/simpleExportForPostsForCommunity.js +0 -61
- package/dist/scripts/testForEndorsments.js +0 -21
- package/dist/scripts/undeleteGroupAndAllContent.js +0 -151
- package/dist/scripts/undeletePost.js +0 -135
- package/dist/scripts/unlinkSsn.js +0 -23
- package/dist/scripts/updateFromAlthingi.js +0 -303
- package/dist/server.js +0 -3
- package/dist/utils/airbrake.cjs +0 -17
- package/dist/utils/cjsCodeReview.js +0 -99
- package/dist/utils/community_mapping_tools.cjs +0 -124
- package/dist/utils/copy_utils.cjs +0 -1399
- package/dist/utils/docx_utils.cjs +0 -464
- package/dist/utils/export_utils.cjs +0 -491
- package/dist/utils/i18n.cjs +0 -17
- package/dist/utils/is_valid_db_id.cjs +0 -28
- package/dist/utils/logger.cjs +0 -25
- package/dist/utils/loggerTs.js +0 -26
- package/dist/utils/manifest_generator.cjs +0 -104
- package/dist/utils/parse_domain.cjs +0 -16
- package/dist/utils/recount_utils.cjs +0 -415
- package/dist/utils/sharing_parameters.cjs +0 -111
- package/dist/utils/sitemap_generator.cjs +0 -286
- package/dist/utils/to_json.cjs +0 -14
- package/dist/utils/ypLanguages.js +0 -747
- package/dist/webSockets.js +0 -77
|
@@ -1,510 +0,0 @@
|
|
|
1
|
-
import { Queue, QueueEvents } from "bullmq";
|
|
2
|
-
import { AgentQueueManager } from "@policysynth/agents/operations/agentQueueManager.js";
|
|
3
|
-
import { PsAgent } from "@policysynth/agents/dbModels/agent.js";
|
|
4
|
-
import { PsAgentClass } from "@policysynth/agents/dbModels/agentClass.js";
|
|
5
|
-
import { YpAgentProductRun } from "../models/agentProductRun.js";
|
|
6
|
-
import models from "../../models/index.cjs";
|
|
7
|
-
import { YpSubscriptionPlan } from "../models/subscriptionPlan.js";
|
|
8
|
-
import { YpAgentProduct } from "../models/agentProduct.js";
|
|
9
|
-
import { YpSubscription } from "../models/subscription.js";
|
|
10
|
-
import { YpAgentProductBundle } from "../models/agentProductBundle.js";
|
|
11
|
-
import queue from "../../active-citizen/workers/queue.cjs";
|
|
12
|
-
import { EmailTemplateRenderer } from "./emailTemplateRenderer.js";
|
|
13
|
-
const dbModels = models;
|
|
14
|
-
const Group = dbModels.Group;
|
|
15
|
-
const User = dbModels.User;
|
|
16
|
-
const Community = dbModels.Community;
|
|
17
|
-
const Domain = dbModels.Domain;
|
|
18
|
-
export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
19
|
-
constructor(wsClients) {
|
|
20
|
-
super();
|
|
21
|
-
console.log("NotificationAgentQueueManager: Initializing");
|
|
22
|
-
this.initializeRedis();
|
|
23
|
-
this.queues = new Map();
|
|
24
|
-
this.wsClients = wsClients;
|
|
25
|
-
}
|
|
26
|
-
async sendNotification(agent, agentRun, action, wsClientId, status, result, agentRunId, updatedWorkflow) {
|
|
27
|
-
console.log("NotificationAgentQueueManager: Sending notification", agentRunId, updatedWorkflow);
|
|
28
|
-
const wsClient = this.wsClients.get(wsClientId);
|
|
29
|
-
if (wsClient) {
|
|
30
|
-
const currentWorkflowStep = updatedWorkflow?.steps[updatedWorkflow?.currentStepIndex];
|
|
31
|
-
wsClient.send(JSON.stringify({
|
|
32
|
-
type: "updated_workflow",
|
|
33
|
-
action,
|
|
34
|
-
status,
|
|
35
|
-
result,
|
|
36
|
-
agentRunId,
|
|
37
|
-
updatedWorkflow: {
|
|
38
|
-
workflow: updatedWorkflow,
|
|
39
|
-
status: status,
|
|
40
|
-
currentWorkflowStep,
|
|
41
|
-
},
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
console.error(`NotificationAgentQueueManager: WebSocket client with ID ${wsClientId} not found`);
|
|
46
|
-
}
|
|
47
|
-
if (updatedWorkflow) {
|
|
48
|
-
await this.sendNotificationEmail(agent, agentRun, updatedWorkflow);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
console.error("NotificationAgentQueueManager: No updated workflow found");
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async sendNotificationEmail(agent, agentRun, updatedWorkflow) {
|
|
55
|
-
// Send email notification
|
|
56
|
-
const subject = `${agentRun.Subscription?.Plan?.AgentProduct?.name} - ${updatedWorkflow?.steps[updatedWorkflow?.currentStepIndex]?.shortName} ready`;
|
|
57
|
-
const bundleId = agentRun.Subscription?.Plan?.AgentProduct?.AgentBundles?.[0]?.id || 1;
|
|
58
|
-
const currentWorkflowStep = updatedWorkflow?.steps[updatedWorkflow?.currentStepIndex];
|
|
59
|
-
const userId = agentRun.Subscription?.user_id;
|
|
60
|
-
const group = (await Group.findOne({
|
|
61
|
-
where: { id: agent.group_id },
|
|
62
|
-
include: [
|
|
63
|
-
{ model: User, as: "GroupAdmins" },
|
|
64
|
-
{
|
|
65
|
-
model: Community,
|
|
66
|
-
attributes: ["id", "name"],
|
|
67
|
-
include: [
|
|
68
|
-
{ model: Domain, attributes: ["id", "name", "domain_name"] },
|
|
69
|
-
],
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
}));
|
|
73
|
-
const link = `https://app.${group.Community?.Domain?.domain_name}/agent_bundle/${bundleId}?needsLogin=true`;
|
|
74
|
-
if (group && group.GroupAdmins && group.GroupAdmins.length > 0) {
|
|
75
|
-
let admins = group.GroupAdmins.filter((admin) => admin.email);
|
|
76
|
-
const emailContent = EmailTemplateRenderer.renderEmail("", "", agentRun.Subscription?.Plan?.AgentProduct?.name || "", updatedWorkflow, link, "https://evoly.ai/is/amplifier/img/amplifier-logo.png", "https://evoly.ai/is/amplifier/img/evoly-bw-logo.png", "https://evoly.ai/", "© 2024 Evoly ehf, Vegmuli 8, 108, Reykjavik, Iceland");
|
|
77
|
-
const MAX_ADMIN_EMAILS = 25;
|
|
78
|
-
// Deduplicate admins using Set
|
|
79
|
-
admins = Array.from(new Set(admins.map((admin) => admin.email)))
|
|
80
|
-
.map((email) => admins.find((admin) => admin.email === email))
|
|
81
|
-
.filter((admin) => admin !== undefined);
|
|
82
|
-
for (let u = 0; u < Math.min(admins.length, MAX_ADMIN_EMAILS); u++) {
|
|
83
|
-
queue.add("send-one-email", {
|
|
84
|
-
subject: subject,
|
|
85
|
-
template: "general_user_notification",
|
|
86
|
-
user: admins[u],
|
|
87
|
-
domain: group.Community?.Domain,
|
|
88
|
-
group: group,
|
|
89
|
-
object: agent,
|
|
90
|
-
header: "",
|
|
91
|
-
content: emailContent,
|
|
92
|
-
link: link,
|
|
93
|
-
skipHeaderAndFooter: true,
|
|
94
|
-
}, { priority: "high" });
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
console.error("No group admins with email found");
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
async goBackOneWorkflowStepIfNeeded(agentRunId, status, wsClientId, currentWorkflowStepIndex = undefined) {
|
|
103
|
-
// Get the agent run record
|
|
104
|
-
const agentRun = await YpAgentProductRun.findByPk(agentRunId, {
|
|
105
|
-
attributes: ["id", "workflow", "status"],
|
|
106
|
-
});
|
|
107
|
-
if (!agentRun || !agentRun.workflow) {
|
|
108
|
-
console.error(`NotificationAgentQueueManager: Agent run ${agentRunId} or its workflow not found`);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const workflowConfig = agentRun.workflow;
|
|
112
|
-
if (currentWorkflowStepIndex !== undefined &&
|
|
113
|
-
currentWorkflowStepIndex !== workflowConfig.currentStepIndex) {
|
|
114
|
-
console.error("NotificationAgentQueueManager: Current workflow step index is undefined or matches the current step index, not advancing to the next step");
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if (currentWorkflowStepIndex === 0) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
let lastStatus;
|
|
122
|
-
if (workflowConfig.steps[workflowConfig.currentStepIndex].type ===
|
|
123
|
-
"agentOps") {
|
|
124
|
-
lastStatus = "waiting_on_user";
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
lastStatus = "running";
|
|
128
|
-
}
|
|
129
|
-
agentRun.status = lastStatus;
|
|
130
|
-
workflowConfig.currentStepIndex--;
|
|
131
|
-
agentRun.workflow = workflowConfig;
|
|
132
|
-
agentRun.changed("workflow", true);
|
|
133
|
-
agentRun.changed("status", true);
|
|
134
|
-
await agentRun.save();
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
async advanceWorkflowStepOrCompleteAgentRun(agentRunId, status, wsClientId, currentWorkflowStepIndex = undefined) {
|
|
138
|
-
try {
|
|
139
|
-
console.log("NotificationAgentQueueManager: Advancing workflow step or completing agent run", agentRunId, status);
|
|
140
|
-
// Get the agent run record
|
|
141
|
-
const agentRun = await YpAgentProductRun.findByPk(agentRunId, {
|
|
142
|
-
attributes: ["id", "workflow", "status"],
|
|
143
|
-
include: [
|
|
144
|
-
{
|
|
145
|
-
model: YpSubscription,
|
|
146
|
-
as: "Subscription",
|
|
147
|
-
attributes: ["id", "user_id"],
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
});
|
|
151
|
-
if (!agentRun || !agentRun.workflow) {
|
|
152
|
-
console.error(`NotificationAgentQueueManager: Agent run ${agentRunId} or its workflow not found`);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
const workflowConfig = agentRun.workflow;
|
|
156
|
-
if (status === "failed") {
|
|
157
|
-
// Mark the workflow as failed
|
|
158
|
-
await agentRun.update({ status: "failed", completedAt: new Date() });
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if (currentWorkflowStepIndex !== undefined &&
|
|
162
|
-
currentWorkflowStepIndex !== workflowConfig.currentStepIndex) {
|
|
163
|
-
console.error("NotificationAgentQueueManager: Current workflow step index is undefined or matches the current step index, not advancing to the next step");
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
// Check if there are more steps
|
|
167
|
-
if (workflowConfig.currentStepIndex < workflowConfig.steps.length - 1) {
|
|
168
|
-
workflowConfig.currentStepIndex++;
|
|
169
|
-
let nextStatus;
|
|
170
|
-
if (workflowConfig.steps[workflowConfig.currentStepIndex].type ===
|
|
171
|
-
"agentOps") {
|
|
172
|
-
nextStatus = "running";
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
nextStatus = "waiting_on_user";
|
|
176
|
-
}
|
|
177
|
-
agentRun.status = nextStatus;
|
|
178
|
-
agentRun.workflow = workflowConfig;
|
|
179
|
-
agentRun.changed("status", true);
|
|
180
|
-
agentRun.changed("workflow", true);
|
|
181
|
-
await agentRun.save();
|
|
182
|
-
//TODO: UPDATE AGENT MEMORY, Maybe
|
|
183
|
-
console.log("NotificationAgentQueueManager: Updated workflow for agent run", agentRunId, status, workflowConfig);
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
// This was the last step, mark the workflow as completed
|
|
187
|
-
agentRun.status = "completed";
|
|
188
|
-
agentRun.changed("status", true);
|
|
189
|
-
await agentRun.save();
|
|
190
|
-
await agentRun.update({ status: "completed", completedAt: new Date() });
|
|
191
|
-
console.log("NotificationAgentQueueManager: Updated workflow for agent run", agentRunId, "to completed");
|
|
192
|
-
}
|
|
193
|
-
return workflowConfig;
|
|
194
|
-
}
|
|
195
|
-
catch (error) {
|
|
196
|
-
console.error(`NotificationAgentQueueManager: Error in advanceWorkflowStepOrCompleteAgentRun:`, error);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
static async getAgentRun(agentRunId) {
|
|
200
|
-
return await YpAgentProductRun.findOne({
|
|
201
|
-
where: { id: agentRunId },
|
|
202
|
-
attributes: ["id", "status", "workflow"],
|
|
203
|
-
include: [
|
|
204
|
-
{
|
|
205
|
-
model: YpSubscription,
|
|
206
|
-
as: "Subscription",
|
|
207
|
-
attributes: ["id", "user_id"],
|
|
208
|
-
include: [
|
|
209
|
-
{
|
|
210
|
-
model: YpSubscriptionPlan,
|
|
211
|
-
attributes: ["id", "name"],
|
|
212
|
-
as: "Plan",
|
|
213
|
-
include: [
|
|
214
|
-
{
|
|
215
|
-
model: YpAgentProduct,
|
|
216
|
-
attributes: ["id", "name", "description"],
|
|
217
|
-
as: "AgentProduct",
|
|
218
|
-
include: [
|
|
219
|
-
{
|
|
220
|
-
model: YpAgentProductBundle,
|
|
221
|
-
attributes: ["id", "name"],
|
|
222
|
-
as: "AgentBundles",
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
},
|
|
226
|
-
],
|
|
227
|
-
},
|
|
228
|
-
],
|
|
229
|
-
},
|
|
230
|
-
],
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
getQueue(queueName) {
|
|
234
|
-
console.log(`NotificationAgentQueueManager: Getting queue for ${queueName}`);
|
|
235
|
-
if (!this.queues.has(queueName)) {
|
|
236
|
-
console.log(`NotificationAgentQueueManager: Creating new queue for ${queueName}`);
|
|
237
|
-
const newQueue = new Queue(queueName, {
|
|
238
|
-
connection: this.redisClient,
|
|
239
|
-
});
|
|
240
|
-
newQueue.on("error", (error) => {
|
|
241
|
-
console.log(`NotificationAgentQueueManager: Error in queue ${queueName}:`, error);
|
|
242
|
-
});
|
|
243
|
-
newQueue.on("waiting", (jobId) => {
|
|
244
|
-
console.log(`Job ${jobId} is waiting in queue ${queueName}`);
|
|
245
|
-
});
|
|
246
|
-
// Create QueueEvents instance for global events
|
|
247
|
-
const queueEvents = new QueueEvents(queueName, {
|
|
248
|
-
connection: this.redisClient,
|
|
249
|
-
});
|
|
250
|
-
// Add event listeners for debugging
|
|
251
|
-
queueEvents.on("waiting", ({ jobId }) => {
|
|
252
|
-
console.log(`Job ${jobId} is waiting in queue ${queueName}`);
|
|
253
|
-
});
|
|
254
|
-
queueEvents.on("active", ({ jobId, prev }) => {
|
|
255
|
-
console.log(`Job ${jobId} is active in queue ${queueName} (prev state: ${prev})`);
|
|
256
|
-
});
|
|
257
|
-
queueEvents.on("completed", async ({ jobId, returnvalue }) => {
|
|
258
|
-
console.log(`Job ${jobId} completed in queue ${queueName}. Result:`, returnvalue);
|
|
259
|
-
try {
|
|
260
|
-
console.log("NotificationAgentQueueManager: Job completed in queue", queueName, jobId);
|
|
261
|
-
// Retrieve the job instance
|
|
262
|
-
const job = await newQueue.getJob(jobId);
|
|
263
|
-
if (job) {
|
|
264
|
-
const { agentId, type, wsClientId, agentRunId, currentWorkflowStepIndex, } = job.data;
|
|
265
|
-
console.log("NotificationAgentQueueManager: Job data", job.data);
|
|
266
|
-
console.log("NotificationAgentQueueManager: currentWorkflowStepIndex", currentWorkflowStepIndex);
|
|
267
|
-
// Load the agent database record
|
|
268
|
-
const agent = await PsAgent.findByPk(agentId, {
|
|
269
|
-
include: [{ model: PsAgentClass, as: "Class" }],
|
|
270
|
-
});
|
|
271
|
-
const agentRun = await NotificationAgentQueueManager.getAgentRun(agentRunId);
|
|
272
|
-
if (!agentRun) {
|
|
273
|
-
console.error(`NotificationAgentQueueManager: Agent run with ID ${agentRunId} not found.`);
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
console.log("NotificationAgentQueueManager: Agent", agent);
|
|
277
|
-
let updatedWorkflow;
|
|
278
|
-
if (agentRun.status === "running" ||
|
|
279
|
-
agentRun.status === "waiting_on_user") {
|
|
280
|
-
if (agentRunId) {
|
|
281
|
-
updatedWorkflow =
|
|
282
|
-
await this.advanceWorkflowStepOrCompleteAgentRun(agentRunId, agentRun.status, wsClientId, currentWorkflowStepIndex);
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
console.error(`NotificationAgentQueueManager: Agent run ID ${agentRunId} not found.`);
|
|
286
|
-
}
|
|
287
|
-
if (agent) {
|
|
288
|
-
// Send notification
|
|
289
|
-
await this.sendNotification(agent, agentRun, type, wsClientId, agentRun.status, returnvalue, agentRunId, updatedWorkflow);
|
|
290
|
-
}
|
|
291
|
-
else {
|
|
292
|
-
console.error(`NotificationAgentQueueManager: Agent with ID ${agentId} not found.`);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
else if (agentRun.status === "stopped") {
|
|
296
|
-
if (agentRunId) {
|
|
297
|
-
updatedWorkflow = await this.goBackOneWorkflowStepIfNeeded(agentRunId, agentRun.status, wsClientId, currentWorkflowStepIndex);
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
console.error(`NotificationAgentQueueManager: Agent run ID ${agentRunId} not found.`);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
console.error(`NotificationAgentQueueManager: Agent run ${agentRunId} is not completed, status ${agentRun.status} but the job completed`);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
console.error(`NotificationAgentQueueManager: Job with ID ${jobId} not found.`);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
catch (error) {
|
|
312
|
-
console.error(`NotificationAgentQueueManager: Error handling job completion for job ${jobId}:`, error);
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
queueEvents.on("failed", async ({ jobId, failedReason }) => {
|
|
316
|
-
console.log(`Job ${jobId} failed in queue ${queueName}. Reason:`, failedReason);
|
|
317
|
-
try {
|
|
318
|
-
// Retrieve the job instance
|
|
319
|
-
const job = await newQueue.getJob(jobId);
|
|
320
|
-
if (job) {
|
|
321
|
-
const { agentId, type, wsClientId, agentRunId } = job.data;
|
|
322
|
-
console.log("NotificationAgentQueueManager: FAILED Job data", job.data);
|
|
323
|
-
// Load the agent database record
|
|
324
|
-
const agent = await PsAgent.findByPk(agentId, {
|
|
325
|
-
include: [{ model: PsAgentClass, as: "Class" }],
|
|
326
|
-
});
|
|
327
|
-
const agentRun = await NotificationAgentQueueManager.getAgentRun(agentRunId);
|
|
328
|
-
if (agent && agentRun) {
|
|
329
|
-
// Send notification email
|
|
330
|
-
//TODO: Fix this, the agent run should not be marked as failed if the job failed
|
|
331
|
-
/*await this.sendNotification(
|
|
332
|
-
agent,
|
|
333
|
-
agentRun,
|
|
334
|
-
type,
|
|
335
|
-
wsClientId,
|
|
336
|
-
"failed",
|
|
337
|
-
failedReason,
|
|
338
|
-
agentRunId,
|
|
339
|
-
agentRun.workflow
|
|
340
|
-
);*/
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
console.error(`NotificationAgentQueueManager: Agent with ID ${agentId} not found.`);
|
|
344
|
-
}
|
|
345
|
-
if (!agentRun) {
|
|
346
|
-
console.error(`NotificationAgentQueueManager: Agent run with ID ${agentRunId} not found.`);
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
agentRun.workflow.steps[agentRun.workflow.currentStepIndex].endTime = new Date();
|
|
350
|
-
//TODO: Fix this, the agent run should not be marked as failed if the job failed
|
|
351
|
-
//agentRun.status = "failed";
|
|
352
|
-
agentRun.changed("status", true);
|
|
353
|
-
agentRun.changed("workflow", true);
|
|
354
|
-
await agentRun.save();
|
|
355
|
-
}
|
|
356
|
-
else {
|
|
357
|
-
console.error(`Job with ID ${jobId} not found.`);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
catch (error) {
|
|
361
|
-
console.error(`Error handling job failure for job ${jobId}:`, error);
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
queueEvents.on("progress", ({ jobId, data }) => {
|
|
365
|
-
console.log(`Job ${jobId} reported progress in queue ${queueName}:`, data);
|
|
366
|
-
});
|
|
367
|
-
queueEvents.on("removed", ({ jobId }) => {
|
|
368
|
-
console.log(`Job ${jobId} was removed from queue ${queueName}`);
|
|
369
|
-
});
|
|
370
|
-
queueEvents.on("drained", () => {
|
|
371
|
-
console.log(`Queue ${queueName} was drained`);
|
|
372
|
-
});
|
|
373
|
-
queueEvents.on("error", (error) => {
|
|
374
|
-
console.log(`Error in queue ${queueName}:`, error);
|
|
375
|
-
});
|
|
376
|
-
this.queues.set(queueName, newQueue);
|
|
377
|
-
}
|
|
378
|
-
return this.queues.get(queueName);
|
|
379
|
-
}
|
|
380
|
-
async controlAgent(agentId, action) {
|
|
381
|
-
console.log(`AgentQueueManager: Controlling agent ${agentId} with action ${action}`);
|
|
382
|
-
const agent = await PsAgent.findByPk(agentId, {
|
|
383
|
-
include: [{ model: PsAgentClass, as: "Class" }],
|
|
384
|
-
});
|
|
385
|
-
if (!agent || !agent.Class) {
|
|
386
|
-
console.error(`AgentQueueManager: Agent or Agent Class not found for agent ${agentId}`);
|
|
387
|
-
throw new Error("Agent or Agent Class not found");
|
|
388
|
-
}
|
|
389
|
-
const queueName = agent.Class.configuration.queueName;
|
|
390
|
-
if (!queueName) {
|
|
391
|
-
console.error(`AgentQueueManager: Queue name not defined for agent class ${agent.Class.id}`);
|
|
392
|
-
throw new Error("Queue name not defined for this agent class");
|
|
393
|
-
}
|
|
394
|
-
const queue = this.getQueue(queueName);
|
|
395
|
-
console.log(`AgentQueueManager: Adding ${action} job to queue ${queueName} for agent ${agentId}`);
|
|
396
|
-
await queue.add(`${action}Agent`, { agentId, action });
|
|
397
|
-
const message = `${action.charAt(0).toUpperCase() + action.slice(1)} request for agent ${agentId} queued in ${queueName}`;
|
|
398
|
-
console.log(`AgentQueueManager: ${message}`);
|
|
399
|
-
return message;
|
|
400
|
-
}
|
|
401
|
-
async startAgentProcessingWithWsClient(agentId, agentRunId, wsClientId, structuredAnswersOverrides) {
|
|
402
|
-
console.log(`NotificationAgentQueueManager: Starting agent processing for agent ${agentId}`);
|
|
403
|
-
const agent = await PsAgent.findByPk(agentId, {
|
|
404
|
-
include: [{ model: PsAgentClass, as: "Class" }],
|
|
405
|
-
});
|
|
406
|
-
if (!agent || !agent.Class) {
|
|
407
|
-
console.error(`NotificationAgentQueueManager: Agent or Agent Class not found for agent ${agentId}`);
|
|
408
|
-
return undefined;
|
|
409
|
-
}
|
|
410
|
-
const agentRun = await NotificationAgentQueueManager.getAgentRun(agentRunId);
|
|
411
|
-
if (!agentRun) {
|
|
412
|
-
console.error(`NotificationAgentQueueManager: Agent run with ID ${agentRunId} not found.`);
|
|
413
|
-
return undefined;
|
|
414
|
-
}
|
|
415
|
-
const currentWorkflow = agentRun.workflow;
|
|
416
|
-
const queueName = agent.Class.configuration.queueName;
|
|
417
|
-
const queue = this.getQueue(queueName);
|
|
418
|
-
console.log(`NotificationAgentQueueManager: Adding start-processing job to queue ${queueName} for agent ${agentId}`);
|
|
419
|
-
const action = "start";
|
|
420
|
-
const job = await queue.add("control-message", {
|
|
421
|
-
type: `${action}Agent${agent.id}`,
|
|
422
|
-
agentId: agent.id,
|
|
423
|
-
action: action,
|
|
424
|
-
wsClientId: wsClientId,
|
|
425
|
-
agentRunId: agentRunId,
|
|
426
|
-
structuredAnswersOverrides: structuredAnswersOverrides,
|
|
427
|
-
currentWorkflowStepIndex: currentWorkflow.currentStepIndex,
|
|
428
|
-
});
|
|
429
|
-
console.log(`NotificationAgentQueueManager: Updating agent ${agentId} status to running`);
|
|
430
|
-
await this.updateAgentStatus(agent.id, "running");
|
|
431
|
-
return job.id;
|
|
432
|
-
}
|
|
433
|
-
async stopAgentProcessing(agentId, wsClientId, agentRunId) {
|
|
434
|
-
console.log(`NotificationAgentQueueManager: Stopping agent processing for agent ${agentId}`);
|
|
435
|
-
const agent = await PsAgent.findByPk(agentId, {
|
|
436
|
-
include: [{ model: PsAgentClass, as: "Class" }],
|
|
437
|
-
});
|
|
438
|
-
if (!agent || !agent.Class) {
|
|
439
|
-
throw Error(`NotificationAgentQueueManager: Agent or Agent Class not found for agent ${agentId}`);
|
|
440
|
-
}
|
|
441
|
-
const agentRun = await NotificationAgentQueueManager.getAgentRun(agentRunId);
|
|
442
|
-
if (!agentRun) {
|
|
443
|
-
console.error(`NotificationAgentQueueManager: Agent run with ID ${agentRunId} not found.`);
|
|
444
|
-
return false;
|
|
445
|
-
}
|
|
446
|
-
const currentWorkflow = agentRun.workflow;
|
|
447
|
-
const queueName = agent.Class.configuration.queueName;
|
|
448
|
-
const queue = this.getQueue(queueName);
|
|
449
|
-
const action = "stop";
|
|
450
|
-
console.log(`NotificationAgentQueueManager: Adding stop-processing job to queue ${queueName} for agent ${agentId} ${action}`);
|
|
451
|
-
await queue.add("control-message", {
|
|
452
|
-
type: `${action}Agent${agent.id}`,
|
|
453
|
-
agentId: agent.id,
|
|
454
|
-
action: action,
|
|
455
|
-
wsClientId: wsClientId,
|
|
456
|
-
agentRunId: agentRunId,
|
|
457
|
-
currentWorkflowStepIndex: currentWorkflow.currentStepIndex,
|
|
458
|
-
});
|
|
459
|
-
await this.updateAgentStatus(agent.id, "stopped");
|
|
460
|
-
return true;
|
|
461
|
-
}
|
|
462
|
-
async getAgentStatus(agentId) {
|
|
463
|
-
const agent = await PsAgent.findByPk(agentId, {
|
|
464
|
-
include: [{ model: PsAgentClass, as: "Class" }],
|
|
465
|
-
});
|
|
466
|
-
if (agent) {
|
|
467
|
-
const statusDataString = await this.redisClient.get(agent.redisStatusKey);
|
|
468
|
-
if (statusDataString) {
|
|
469
|
-
const statusData = JSON.parse(statusDataString);
|
|
470
|
-
return statusData;
|
|
471
|
-
}
|
|
472
|
-
else {
|
|
473
|
-
return null;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
else {
|
|
477
|
-
return null;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
async updateAgentStatus(agentId, state, progress, message, details) {
|
|
481
|
-
const agent = await PsAgent.findByPk(agentId, {
|
|
482
|
-
include: [{ model: PsAgentClass, as: "Class" }],
|
|
483
|
-
});
|
|
484
|
-
if (agent) {
|
|
485
|
-
const statusDataString = await this.redisClient.get(agent.redisStatusKey);
|
|
486
|
-
if (statusDataString) {
|
|
487
|
-
const statusData = JSON.parse(statusDataString);
|
|
488
|
-
statusData.state = state;
|
|
489
|
-
statusData.lastUpdated = Date.now();
|
|
490
|
-
if (progress !== undefined)
|
|
491
|
-
statusData.progress = progress;
|
|
492
|
-
if (message)
|
|
493
|
-
statusData.messages.push(message);
|
|
494
|
-
if (details)
|
|
495
|
-
statusData.details = {
|
|
496
|
-
...statusData.details,
|
|
497
|
-
...details,
|
|
498
|
-
};
|
|
499
|
-
await this.redisClient.set(agent.redisStatusKey, JSON.stringify(statusData));
|
|
500
|
-
return true;
|
|
501
|
-
}
|
|
502
|
-
else {
|
|
503
|
-
return false;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
else {
|
|
507
|
-
return false;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|