@yrpri/api 9.0.101 → 9.0.103
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/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +11 -1
- package/active-citizen/llms/baseChatBot.js +8 -75
- package/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
- package/active-citizen/llms/imageGeneration/collectionImageGenerator.js +6 -0
- package/agents/assistants/agentAssistant.js +3 -2
- package/agents/assistants/baseAssistant.js +7 -30
- package/agents/assistants/baseAssistantWithVoice.js +3 -3
- package/agents/assistants/voiceAssistant.js +2 -2
- package/agents/controllers/agentProductController.js +2 -1
- package/agents/controllers/agentSubscriptionController.js +20 -11
- package/agents/controllers/assistantsController.js +171 -127
- package/agents/controllers/policySynthAgents.js +33 -12
- package/agents/managers/newAiModelSetup.js +96 -0
- package/agents/managers/subscriptionManager.js +2 -2
- package/app.js +12 -12
- package/authorization.cjs +4 -0
- package/controllers/allOurIdeas.js +2 -1
- package/controllers/communities.cjs +47 -1
- package/controllers/groups.cjs +67 -4
- package/controllers/index.cjs +7 -7
- package/controllers/nonSpa.cjs +1 -1
- package/dist/active-citizen/controllers/activities.cjs +174 -0
- package/dist/active-citizen/controllers/news_feeds.cjs +96 -0
- package/dist/active-citizen/controllers/notifications.cjs +243 -0
- package/dist/active-citizen/controllers/recommendations.cjs +280 -0
- package/dist/active-citizen/engine/allOurIdeas/aiHelper.js +204 -0
- package/dist/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +66 -0
- package/dist/active-citizen/engine/allOurIdeas/iconGenerator.js +38 -0
- package/dist/active-citizen/engine/analytics/export_anon_community_activities.js +334 -0
- package/dist/active-citizen/engine/analytics/importer.js +308 -0
- package/dist/active-citizen/engine/analytics/manager.cjs +377 -0
- package/dist/active-citizen/engine/analytics/plausible/manager.cjs +500 -0
- package/dist/active-citizen/engine/analytics/statsCalc.cjs +194 -0
- package/dist/active-citizen/engine/analytics/utils.cjs +369 -0
- package/dist/active-citizen/engine/marketing/campaign.cjs +90 -0
- package/dist/active-citizen/engine/moderation/fraud/CreateFraudAuditReport.cjs +313 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudBase.cjs +239 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteBase.cjs +211 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteEndorsements.cjs +120 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePointQualities.cjs +114 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePoints.cjs +101 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePosts.cjs +84 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteRatings.cjs +15 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetBase.cjs +133 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetEndorsements.cjs +185 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPointQualities.cjs +184 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPoints.cjs +170 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPosts.cjs +109 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetRatings.cjs +140 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudScannerNotifier.cjs +279 -0
- package/dist/active-citizen/engine/moderation/get_moderation_items.cjs +386 -0
- package/dist/active-citizen/engine/moderation/image_labeling/CommunityLabeling.cjs +49 -0
- package/dist/active-citizen/engine/moderation/image_labeling/GroupLabeling.cjs +68 -0
- package/dist/active-citizen/engine/moderation/image_labeling/ImageLabelingBase.cjs +288 -0
- package/dist/active-citizen/engine/moderation/image_labeling/PointLabeling.cjs +33 -0
- package/dist/active-citizen/engine/moderation/image_labeling/PostLabeling.cjs +56 -0
- package/dist/active-citizen/engine/moderation/perspective_api_client.cjs +106 -0
- package/dist/active-citizen/engine/moderation/process_moderation_items.cjs +344 -0
- package/dist/active-citizen/engine/moderation/toxicity_analysis.cjs +810 -0
- package/dist/active-citizen/engine/news_feeds/activity_and_item_index_definitions.cjs +15 -0
- package/dist/active-citizen/engine/news_feeds/generate_dynamically.cjs +362 -0
- package/dist/active-citizen/engine/news_feeds/generate_from_notifications.cjs +268 -0
- package/dist/active-citizen/engine/news_feeds/news_feeds_utils.cjs +439 -0
- package/dist/active-citizen/engine/notifications/emails_utils.cjs +569 -0
- package/dist/active-citizen/engine/notifications/generate_point_notifications.cjs +233 -0
- package/dist/active-citizen/engine/notifications/generate_post_notifications.cjs +118 -0
- package/dist/active-citizen/engine/notifications/generate_post_status_change_notifications.cjs +41 -0
- package/dist/active-citizen/engine/notifications/notifications_utils.cjs +148 -0
- package/dist/active-citizen/engine/notifications/point_delivery.cjs +54 -0
- package/dist/active-citizen/engine/notifications/post_delivery.cjs +31 -0
- package/dist/active-citizen/engine/notifications/process_delayed_notifications.cjs +471 -0
- package/dist/active-citizen/engine/notifications/process_general_notifications.cjs +212 -0
- package/dist/active-citizen/engine/old/exporters/categories_dataset.js +153 -0
- package/dist/active-citizen/engine/old/exporters/dataset_tools.js +80 -0
- package/dist/active-citizen/engine/old/exporters/sentiment_dataset.js +157 -0
- package/dist/active-citizen/engine/recommendations/events_importer.cjs +139 -0
- package/dist/active-citizen/engine/recommendations/events_manager.cjs +212 -0
- package/dist/active-citizen/engine/reports/add_points_to_sheet.cjs +83 -0
- package/dist/active-citizen/engine/reports/commonUtils.js +75 -0
- package/dist/active-citizen/engine/reports/common_utils.cjs +740 -0
- package/dist/active-citizen/engine/reports/docx_group_report.cjs +596 -0
- package/dist/active-citizen/engine/reports/xlsAllOurIdeasExport.js +232 -0
- package/dist/active-citizen/engine/reports/xls_community_users_report.cjs +277 -0
- package/dist/active-citizen/engine/reports/xls_group_report.cjs +718 -0
- package/dist/active-citizen/llms/baseChatBot.js +183 -0
- package/dist/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
- package/dist/active-citizen/llms/imageGeneration/collectionImageGenerator.js +109 -0
- package/dist/active-citizen/llms/imageGeneration/dalleImageGenerator.js +84 -0
- package/dist/active-citizen/llms/imageGeneration/fluxImageGenerator.js +49 -0
- package/dist/active-citizen/llms/imageGeneration/imageProcessorService.js +64 -0
- package/dist/active-citizen/llms/imageGeneration/imagenImageGenerator.js +107 -0
- package/dist/active-citizen/llms/imageGeneration/s3Service.js +110 -0
- package/dist/active-citizen/llms/llmTranslation.js +472 -0
- package/dist/active-citizen/models/ac_activity.cjs +216 -0
- package/dist/active-citizen/models/ac_background_job.cjs +109 -0
- package/dist/active-citizen/models/ac_campaign.cjs +97 -0
- package/dist/active-citizen/models/ac_client_activity.cjs +23 -0
- package/dist/active-citizen/models/ac_delayed_notification.cjs +43 -0
- package/dist/active-citizen/models/ac_following.cjs +43 -0
- package/dist/active-citizen/models/ac_list.cjs +68 -0
- package/dist/active-citizen/models/ac_list_users.cjs +19 -0
- package/dist/active-citizen/models/ac_mute.cjs +27 -0
- package/dist/active-citizen/models/ac_news_feed_item.cjs +57 -0
- package/dist/active-citizen/models/ac_news_feed_processed_range.cjs +59 -0
- package/dist/active-citizen/models/ac_notification.cjs +292 -0
- package/dist/active-citizen/models/ac_translation_cache.cjs +750 -0
- package/dist/active-citizen/models/ac_watching.cjs +31 -0
- package/dist/active-citizen/scripts/analytics/setup_all_plausible_goals.cjs +13 -0
- package/dist/active-citizen/scripts/fix_old_delayed_notifications.js +63 -0
- package/dist/active-citizen/scripts/kue_status.js +31 -0
- package/dist/active-citizen/scripts/kue_watch_stuck_jobs.js +24 -0
- package/dist/active-citizen/scripts/translation_clear_language.js +117 -0
- package/dist/active-citizen/scripts/translation_delete.js +27 -0
- package/dist/active-citizen/scripts/translation_replace_text_from_url.js +180 -0
- package/dist/active-citizen/scripts/translation_update.js +28 -0
- package/dist/active-citizen/scripts/translations_list.js +27 -0
- package/{active-citizen/utils/airbrake.js → dist/active-citizen/utils/airbrake.cjs} +1 -1
- package/dist/active-citizen/utils/get_anonymous_system_user.cjs +21 -0
- package/dist/active-citizen/utils/i18n.cjs +3 -0
- package/dist/active-citizen/utils/logger.cjs +25 -0
- package/dist/active-citizen/utils/redisConnection.cjs +29 -0
- package/dist/active-citizen/utils/to_json.cjs +9 -0
- package/dist/active-citizen/utils/translation_cloning.cjs +171 -0
- package/dist/active-citizen/utils/translation_helpers.cjs +534 -0
- package/dist/active-citizen/utils/truncate_text.cjs +21 -0
- package/dist/active-citizen/utils/updateAllLocalesFromEn.js +253 -0
- package/dist/active-citizen/utils/updateLocaleFolders.js +34 -0
- package/dist/active-citizen/workers/activity.cjs +189 -0
- package/dist/active-citizen/workers/anonymizations.cjs +734 -0
- package/dist/active-citizen/workers/bulk_status_update.cjs +458 -0
- package/dist/active-citizen/workers/delayed_jobs.cjs +244 -0
- package/dist/active-citizen/workers/deletions.cjs +1911 -0
- package/dist/active-citizen/workers/email.cjs +9 -0
- package/dist/active-citizen/workers/fraud_management.cjs +109 -0
- package/dist/active-citizen/workers/generativeAi.js +56 -0
- package/dist/active-citizen/workers/main.cjs +89 -0
- package/dist/active-citizen/workers/marketing.cjs +25 -0
- package/dist/active-citizen/workers/moderation.cjs +73 -0
- package/dist/active-citizen/workers/notification_delivery.cjs +368 -0
- package/dist/active-citizen/workers/notification_news_feed.cjs +142 -0
- package/dist/active-citizen/workers/queue.cjs +99 -0
- package/dist/active-citizen/workers/recount.cjs +74 -0
- package/dist/active-citizen/workers/reports.cjs +42 -0
- package/dist/active-citizen/workers/similarities.cjs +21 -0
- package/dist/active-citizen/workers/speech_to_text.cjs +482 -0
- package/dist/agents/assistants/agentAssistant.js +88 -0
- package/dist/agents/assistants/baseAssistant.js +888 -0
- package/dist/agents/assistants/baseAssistantWithVoice.js +150 -0
- package/dist/agents/assistants/modes/agentDirectConnection.js +84 -0
- package/dist/agents/assistants/modes/agentSelectionMode.js +44 -0
- package/dist/agents/assistants/modes/baseAssistantMode.js +54 -0
- package/dist/agents/assistants/modes/tools/agentTools.js +447 -0
- package/dist/agents/assistants/modes/tools/baseTools.js +58 -0
- package/dist/agents/assistants/modes/tools/loginTools.js +156 -0
- package/dist/agents/assistants/modes/tools/models/agents.js +146 -0
- package/dist/agents/assistants/modes/tools/models/subscriptions.js +332 -0
- package/dist/agents/assistants/modes/tools/models/users.js +11 -0
- package/dist/agents/assistants/modes/tools/navigationTools.js +166 -0
- package/{agents/assistants/modes/tools/workflowConversationTools.js → dist/agents/assistants/modes/tools/subscriptionTools.js} +1 -4
- package/{agents/assistants/modes/tools/workflowTools.js → dist/agents/assistants/modes/tools/workflowConverstationTools.js} +1 -1
- package/dist/agents/assistants/voiceAssistant.js +619 -0
- package/dist/agents/controllers/agentProductController.js +103 -0
- package/dist/agents/controllers/agentSubscriptionController.js +261 -0
- package/dist/agents/controllers/assistantsController.js +511 -0
- package/dist/agents/controllers/policySynthAgents.js +395 -0
- package/{agents → dist/agents/managers}/agentProductManager.js +2 -2
- package/dist/agents/managers/emailInvitesManager.js +55 -0
- package/dist/agents/managers/emailTemplateRenderer.js +362 -0
- package/dist/agents/managers/newAiModelSetup.js +650 -0
- package/dist/agents/managers/notificationAgentQueueManager.js +510 -0
- package/dist/agents/managers/subscriptionManager.js +535 -0
- package/dist/agents/managers/workflowConversationManager.js +79 -0
- package/dist/agents/models/agentProduct.js +116 -0
- package/dist/agents/models/agentProductBoosterPurchase.js +58 -0
- package/dist/agents/models/agentProductBundle.js +68 -0
- package/dist/agents/models/agentProductRun.js +52 -0
- package/dist/agents/models/discount.js +88 -0
- package/dist/agents/models/subscription.js +79 -0
- package/dist/agents/models/subscriptionPlan.js +46 -0
- package/dist/agents/models/subscriptionUser.js +27 -0
- package/dist/agents/models/testData/createEvolyAgentProduct.js +477 -0
- package/dist/agents/models/testData/old/updateAgentWorkflowConfiguration.js +230 -0
- package/dist/agents/models/testData/setupEvolyAgentProductConfig.js +233 -0
- package/dist/agents/models/testData/updateAgentWorkflowConfiguration.js +230 -0
- package/{agents/models/workflowConverstation.js → dist/agents/models/workflowConversation.js} +1 -1
- package/{agents/tools/updateTemplateWorkflow.js → dist/agents/tools/setTemplateWorkflowCommunityId.js} +1 -0
- package/dist/app.js +943 -0
- package/dist/authorization.cjs +1860 -0
- package/dist/bot_control.js +1930 -0
- package/dist/config/config.cjs +14 -0
- package/dist/config/config.js +14 -0
- package/dist/controllers/allOurIdeas.js +696 -0
- package/dist/controllers/audios.cjs +100 -0
- package/dist/controllers/bulkStatusUpdates.cjs +202 -0
- package/dist/controllers/categories.cjs +199 -0
- package/dist/controllers/communities.cjs +2996 -0
- package/dist/controllers/domains.cjs +1341 -0
- package/dist/controllers/externalIds.cjs +223 -0
- package/dist/controllers/groups.cjs +4309 -0
- package/dist/controllers/images.cjs +499 -0
- package/dist/controllers/index.cjs +449 -0
- package/dist/controllers/legacyPages.cjs +35 -0
- package/dist/controllers/legacyPosts.cjs +56 -0
- package/dist/controllers/legacyUsers.cjs +36 -0
- package/dist/controllers/nonSpa.cjs +574 -0
- package/dist/controllers/organizations.cjs +250 -0
- package/dist/controllers/points.cjs +1137 -0
- package/dist/controllers/posts.cjs +2036 -0
- package/dist/controllers/ratings.cjs +234 -0
- package/dist/controllers/users.cjs +2255 -0
- package/dist/controllers/videos.cjs +226 -0
- package/dist/deleteUnwantedDeclerations.cjs +55 -0
- package/dist/migrations/agentAuditLogs.cjs +46 -0
- package/dist/migrations/agentClasses.cjs +60 -0
- package/dist/migrations/agentConnectorClasses.cjs +61 -0
- package/dist/migrations/agentConnectors.cjs +50 -0
- package/dist/migrations/agentEvals.cjs +45 -0
- package/dist/migrations/agentRegistries.cjs +40 -0
- package/dist/migrations/agents.cjs +54 -0
- package/dist/migrations/aiModels.cjs +49 -0
- package/dist/migrations/apiUsage.cjs +47 -0
- package/dist/migrations/apis.cjs +49 -0
- package/dist/migrations/groupPrivateData.cjs +30 -0
- package/dist/migrations/modelUsage.cjs +60 -0
- package/dist/migrations/oldMigrations/2019/20181030020612-AddActivitiesIndex.js +23 -0
- package/dist/migrations/oldMigrations/2019/20181102210612-AddFirstVideoFeatures.js +360 -0
- package/dist/migrations/oldMigrations/2019/20181212210612-ModerationFeatures.js +29 -0
- package/dist/migrations/oldMigrations/2019/2019010610612-CommunityFolders.js +43 -0
- package/dist/migrations/oldMigrations/2019/20190117020612-AddMissingIndexes.js +24 -0
- package/dist/migrations/oldMigrations/2019/20190117020612-RemoveUnusedIndexes.js +29 -0
- package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartThree.js +22 -0
- package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartTwo.js +23 -0
- package/{migrations/200824_create_embeddings_and_org_update.cjs → dist/migrations/oldMigrations/2019/20190223020612-AddPrivateProfileDataToUsers.js} +6 -3
- package/dist/migrations/oldMigrations/2019/20190706210612-AddCustomRatings.js +43 -0
- package/dist/migrations/oldMigrations/2019/20190829210612-AddGeneralStore.js +36 -0
- package/dist/migrations/oldMigrations/2019/20192811210612-AddAcClientActivities.js +41 -0
- package/dist/migrations/oldMigrations/2020/20190527020612-WorkOnIndexes.js +88 -0
- package/dist/migrations/oldMigrations/2020/20200409020612-AddBackgroundJob.js +33 -0
- package/dist/migrations/oldMigrations/2020/20200716210612-AddDataToCollections.js +38 -0
- package/dist/migrations/oldMigrations/2022/20220215100612-AddDataToEndorsements.js +19 -0
- package/dist/migrations/oldMigrations/2022/20220220100612-AddDataForFraudDetection.js +19 -0
- package/dist/migrations/oldMigrations/2022/20220903100612-AddPromotionFeatures.js +127 -0
- package/dist/migrations/oldMigrations/2022/onHold/20200527020612-AddCampaigns.js +68 -0
- package/dist/migrations/oldMigrations/2024/20241304175112-AddMediaSupportForHtmlGroups.cjs +63 -0
- package/dist/migrations/oldMigrations/older/20160511172514-AddNotificationFeatures.js +14 -0
- package/dist/migrations/oldMigrations/older/20161030020612-AddBulkStatusUpdate.js +71 -0
- package/dist/migrations/oldMigrations/older/20170514035258-add-metadata-to-invites.js +12 -0
- package/dist/migrations/oldMigrations/older/20180216020612-AddTranslationCaches.js +46 -0
- package/dist/migrations/oldMigrations/older/20180218210612-AddTranslationAndLanguages.js +46 -0
- package/dist/migrations/privateAccessStore.cjs +55 -0
- package/dist/migrations/zzz_associations.cjs +154 -0
- package/dist/migrations/zzzzz_create_agent_runs.cjs +606 -0
- package/dist/migrations/zzzzzz_create_agent_runs_fix.cjs +11 -0
- package/dist/migrations/zzzzzzz_create_trees.cjs +81 -0
- package/dist/models/audio.cjs +430 -0
- package/dist/models/bulk_status_update.cjs +58 -0
- package/dist/models/campaign.cjs +78 -0
- package/dist/models/category.cjs +94 -0
- package/dist/models/community.cjs +337 -0
- package/dist/models/domain.cjs +486 -0
- package/dist/models/endorsement.cjs +39 -0
- package/dist/models/general_data_store.cjs +20 -0
- package/dist/models/group.cjs +728 -0
- package/dist/models/image.cjs +579 -0
- package/dist/models/index.cjs +186 -0
- package/dist/models/invite.cjs +48 -0
- package/dist/models/iso_country.cjs +16 -0
- package/dist/models/organization.cjs +122 -0
- package/dist/models/page.cjs +273 -0
- package/dist/models/point.cjs +622 -0
- package/dist/models/point_quality.cjs +39 -0
- package/dist/models/point_revision.cjs +47 -0
- package/dist/models/post.cjs +680 -0
- package/dist/models/post_revision.cjs +38 -0
- package/dist/models/post_status_change.cjs +35 -0
- package/dist/models/promotion.cjs +34 -0
- package/dist/models/rating.cjs +51 -0
- package/dist/models/relationship.cjs +19 -0
- package/dist/models/request_to_join.cjs +20 -0
- package/dist/models/user.cjs +604 -0
- package/dist/models/user_legacy_password.cjs +13 -0
- package/dist/models/video.cjs +1137 -0
- package/dist/publish.js +40 -0
- package/dist/repack.js +53 -0
- package/dist/scripts/addRatingUsersToGroup.js +51 -0
- package/dist/scripts/addUserToOrganization.js +71 -0
- package/dist/scripts/analyseRatingsForCommunity.js +150 -0
- package/dist/scripts/analyzeAndFixBrokenPointUsers.js +28 -0
- package/dist/scripts/analyzeEndorsementsByCountry.js +70 -0
- package/dist/scripts/analyzePostsForCommunity.js +185 -0
- package/dist/scripts/bulkStatusUpdates/listUpdates.js +14 -0
- package/dist/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +110 -0
- package/dist/scripts/bulkStatusUpdates/performUpdate.js +116 -0
- package/{scripts/bulkStatusUpdates/performUpdateForGroup.js → dist/scripts/bulkStatusUpdates/performUpdateForGroup.cjs} +1 -2
- package/dist/scripts/bulkStatusUpdates/performUpdateForStatus.js +141 -0
- package/dist/scripts/change/changeVideoAspectTo.js +34 -0
- package/dist/scripts/change/setUseNewVersion.cjs +22 -0
- package/dist/scripts/changeCommunityGroupcount.js +30 -0
- package/dist/scripts/changeCommunityPostCount.js +30 -0
- package/dist/scripts/changeGroupPostCount.js +30 -0
- package/dist/scripts/changeLanguage.js +50 -0
- package/dist/scripts/changeOfficalStatus.js +30 -0
- package/{scripts/cleanups/deleteAnonNotifications.js → dist/scripts/cleanups/deleteAnonNotifications.cjs} +1 -1
- package/dist/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +62 -0
- package/dist/scripts/cleanups/deleteYearOldNotifications.cjs +72 -0
- package/dist/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +43 -0
- package/dist/scripts/clearAllEndorsementInGroup.js +50 -0
- package/dist/scripts/cloning/clearUsersForCommunitiesFromUrl.js +129 -0
- package/dist/scripts/cloning/cloneFromUrlScript.js +65 -0
- package/dist/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +140 -0
- package/dist/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +140 -0
- package/dist/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +131 -0
- package/dist/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +173 -0
- package/dist/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +18 -0
- package/dist/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +17 -0
- package/dist/scripts/cloning/copyCommunityToDomainWithEverything.js +17 -0
- package/dist/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +26 -0
- package/dist/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +205 -0
- package/dist/scripts/cloning/copyPostToGroupOld.js +397 -0
- package/dist/scripts/cloning/copyPostVideosFromURL.js +236 -0
- package/dist/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +17 -0
- package/dist/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +131 -0
- package/dist/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +139 -0
- package/dist/scripts/cloning/setAdminsFromURL.js +161 -0
- package/dist/scripts/cloning/setExternalIdsFromURL.js +129 -0
- package/dist/scripts/countCommunity.js +291 -0
- package/dist/scripts/countCommunityUsers.js +152 -0
- package/dist/scripts/countDelayedNotifications.js +18 -0
- package/dist/scripts/countGroup.js +246 -0
- package/dist/scripts/countStuff.js +67 -0
- package/dist/scripts/countUniqueVotersInAGroup.js +48 -0
- package/dist/scripts/createInvitesAndShow.js +75 -0
- package/dist/scripts/database/sync_database.js +14 -0
- package/dist/scripts/database/sync_dev_database.js +17 -0
- package/dist/scripts/debugNotifications.js +58 -0
- package/dist/scripts/deleteAllNewsFeeds.js +10 -0
- package/dist/scripts/deleteCategory.js +13 -0
- package/dist/scripts/deleteOldAppActivities.js +40 -0
- package/dist/scripts/deletePostContactDataForCommunity.js +53 -0
- package/dist/scripts/destroy/destroy_all_but_one_domain.js +1026 -0
- package/dist/scripts/displayAuthorForPost.js +16 -0
- package/dist/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +183 -0
- package/dist/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +208 -0
- package/dist/scripts/exportAllStatusChanges.js +36 -0
- package/dist/scripts/exportClientAcitivity.js +36 -0
- package/dist/scripts/exportEndorsementsForCommunity.js +79 -0
- package/dist/scripts/exportPointQualitiesForCommunity.js +84 -0
- package/dist/scripts/exportPostsAndPointsForCommunity.js +147 -0
- package/dist/scripts/exportPostsDataSetForDomain.js +244 -0
- package/dist/scripts/exportPostsForGroup.js +173 -0
- package/dist/scripts/exportRatingsForPost.js +15 -0
- package/dist/scripts/exportUserEndorsementsWithUserAnalysis.js +123 -0
- package/dist/scripts/exportUsersForCommunity.js +24 -0
- package/dist/scripts/exportUsersForDomain.js +24 -0
- package/dist/scripts/exportUsersForGroup.js +24 -0
- package/dist/scripts/exports/ratingDistribution.js +71 -0
- package/dist/scripts/exports/whoEndorsedWhatByCommunity.js +56 -0
- package/dist/scripts/findUnusedClientImports.js +56 -0
- package/dist/scripts/fixAllPostPointCounts.js +22 -0
- package/dist/scripts/fixAnonNotificationsSettings.js +48 -0
- package/dist/scripts/fixCountKopavogur.js +9 -0
- package/dist/scripts/fixEndorsementsAfterCopyPostToGroup.js +190 -0
- package/dist/scripts/fixExternalUserId.js +24 -0
- package/dist/scripts/fixGroupAccess.js +16 -0
- package/dist/scripts/fixGroupIdeasAndPointsCount.js +49 -0
- package/dist/scripts/fixNotificationSettings.js +39 -0
- package/dist/scripts/fixSurveyRadioBakedInSubCodes.js +64 -0
- package/dist/scripts/fixWrongUserIdForStatusUpdates.js +49 -0
- package/dist/scripts/gallery/exportGalleryData.js +40 -0
- package/dist/scripts/gallery/importGalleryForCommunity.js +168 -0
- package/dist/scripts/gallery/readJsonAndDownloadImagesVersion2.js +55 -0
- package/dist/scripts/gallery/refreshAcApiPostIdsForCommunity.js +58 -0
- package/dist/scripts/genderAnalysis.js +63 -0
- package/dist/scripts/genderAnalysisByStatus.js +62 -0
- package/dist/scripts/importAllLocalesFromLocalFolders.js +55 -0
- package/dist/scripts/importDomain.js +1652 -0
- package/dist/scripts/keys/addOidcToDomain.cjs +61 -0
- package/dist/scripts/landUseGame/export3Ddata.js +162 -0
- package/dist/scripts/listLanguagesForGroup.js +54 -0
- package/dist/scripts/loadTestCreateDummyContentForGroup.js +27 -0
- package/dist/scripts/makeRecursiveMapData.js +103 -0
- package/dist/scripts/mapping/community_map_csv.js +145 -0
- package/dist/scripts/moveCommunityToDomain.js +22 -0
- package/dist/scripts/moveGroupToCommunity.js +23 -0
- package/dist/scripts/movePostToGroup.js +101 -0
- package/dist/scripts/movePostsToGroupsRecountGroupFromUrl.js +297 -0
- package/dist/scripts/oldMovePostToGroup.js +153 -0
- package/dist/scripts/processCsvForPdfUrls.js +37 -0
- package/dist/scripts/processCsvForTranslationAndToxicity.js +125 -0
- package/dist/scripts/recount/recount_recursive_communities.js +125 -0
- package/dist/scripts/recountALLCommunityGroupCounts.js +37 -0
- package/dist/scripts/recountAll.js +97 -0
- package/dist/scripts/recountCommunitesFromUrl.js +58 -0
- package/dist/scripts/recountCommunity.js +19 -0
- package/dist/scripts/recountGroup.js +218 -0
- package/dist/scripts/recountGroupNoUserChange.js +219 -0
- package/dist/scripts/resetAllEndorsementsForGroup.js +57 -0
- package/dist/scripts/resetEnTranslationForGroup.js +45 -0
- package/dist/scripts/setAdminOnAll.cjs +107 -0
- package/{scripts/change → dist/scripts}/setDomainAdmin.cjs +0 -2
- package/dist/scripts/setDomainLocales.js +33 -0
- package/dist/scripts/setEarlQuestionIdOnGroup.cjs +29 -0
- package/dist/scripts/setLanguageOnGroupCommunitesFromUrl.js +86 -0
- package/dist/scripts/setMemberOfAll.js +101 -0
- package/dist/scripts/setNewUserForContentOfCommunity.js +189 -0
- package/dist/scripts/setOfficialStatusOnAllPostsForCommunity.js +35 -0
- package/dist/scripts/setUserOnAll.js +101 -0
- package/dist/scripts/showCategoryForGroup.js +18 -0
- package/dist/scripts/showOldActivityTypes.js +14 -0
- package/dist/scripts/showPostsMissingCategoryForGroup.js +17 -0
- package/dist/scripts/showStatuses.js +17 -0
- package/dist/scripts/showUniqueVotersInCommunity.js +61 -0
- package/dist/scripts/showUserAgentsAndIpsForEmails.js +66 -0
- package/dist/scripts/simpleExportForGroupsForCommunity.js +46 -0
- package/dist/scripts/simpleExportForPointsForCommunity.js +82 -0
- package/dist/scripts/simpleExportForPostsForCommunity.js +61 -0
- package/dist/scripts/testForEndorsments.js +21 -0
- package/dist/scripts/undeleteGroupAndAllContent.js +151 -0
- package/dist/scripts/undeletePost.js +135 -0
- package/dist/scripts/unlinkSsn.js +23 -0
- package/dist/scripts/updateFromAlthingi.js +303 -0
- package/dist/server.js +3 -0
- package/dist/utils/airbrake.cjs +17 -0
- package/dist/utils/cjsCodeReview.js +99 -0
- package/dist/utils/community_mapping_tools.cjs +124 -0
- package/dist/utils/copy_utils.cjs +1399 -0
- package/dist/utils/docx_utils.cjs +464 -0
- package/dist/utils/export_utils.cjs +491 -0
- package/dist/utils/i18n.cjs +17 -0
- package/dist/utils/is_valid_db_id.cjs +28 -0
- package/dist/utils/logger.cjs +25 -0
- package/dist/utils/loggerTs.js +26 -0
- package/dist/utils/manifest_generator.cjs +104 -0
- package/dist/utils/parse_domain.cjs +16 -0
- package/dist/utils/recount_utils.cjs +415 -0
- package/dist/utils/sharing_parameters.cjs +111 -0
- package/dist/utils/sitemap_generator.cjs +286 -0
- package/dist/utils/to_json.cjs +14 -0
- package/dist/utils/ypLanguages.js +747 -0
- package/dist/webSockets.js +77 -0
- package/package.json +46 -44
- package/server.d.ts +104 -2
- package/utils/copy_utils.cjs +7 -1
- package/active-citizen/engine/allOurIdeas/aiHelper.d.ts +0 -21
- package/active-citizen/engine/allOurIdeas/aiHelper.d.ts.map +0 -1
- package/active-citizen/engine/allOurIdeas/explainAnswersAssistant.d.ts.map +0 -1
- package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts +0 -12
- package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts.map +0 -1
- package/active-citizen/engine/analytics/export_anon_community_activities.d.ts.map +0 -1
- package/active-citizen/engine/analytics/importer.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/categories_dataset.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/dataset_tools.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/sentiment_dataset.d.ts.map +0 -1
- package/active-citizen/engine/reports/xls_all_our_ideas_export.js +0 -141
- package/active-citizen/llms/baseChatBot.d.ts +0 -51
- package/active-citizen/llms/baseChatBot.d.ts.map +0 -1
- package/active-citizen/llms/collectionImageGenerator.js +0 -357
- package/active-citizen/llms/llmTranslation.d.ts +0 -24
- package/active-citizen/llms/llmTranslation.d.ts.map +0 -1
- package/active-citizen/scripts/fix_old_delayed_notifications.d.ts.map +0 -1
- package/active-citizen/scripts/kue_status.d.ts.map +0 -1
- package/active-citizen/scripts/kue_watch_stuck_jobs.d.ts.map +0 -1
- package/active-citizen/scripts/translation_clear_language.d.ts.map +0 -1
- package/active-citizen/scripts/translation_delete.d.ts.map +0 -1
- package/active-citizen/scripts/translation_replace_text_from_url.d.ts.map +0 -1
- package/active-citizen/scripts/translation_update.d.ts.map +0 -1
- package/active-citizen/scripts/translations_list.d.ts.map +0 -1
- package/active-citizen/utils/airbrake.d.ts.map +0 -1
- package/active-citizen/utils/updateAllLocalesFromEn.d.ts +0 -21
- package/active-citizen/utils/updateAllLocalesFromEn.d.ts.map +0 -1
- package/active-citizen/utils/updateLocaleFolders.d.ts +0 -2
- package/active-citizen/utils/updateLocaleFolders.d.ts.map +0 -1
- package/active-citizen/workers/cloudflare/voiceSession/worker.js +0 -213
- package/active-citizen/workers/generativeAi.d.ts.map +0 -1
- package/agents/assistants/agentAssistantOld.js +0 -863
- package/agents/assistants/modes/agentConfigurationMode.js +0 -63
- package/agents/assistants/modes/agentOperationsMode.js +0 -195
- package/agents/assistants/modes/commonTools.js +0 -58
- package/agents/assistants/modes/directConversationMode.js +0 -14
- package/agents/assistants/modes/toolHandlers/accountHandlers.js +0 -46
- package/agents/assistants/modes/toolHandlers/commonHandlers.js +0 -57
- package/agents/assistants/modes/toolHandlers/commonTools.js +0 -58
- package/agents/assistants/modes/toolHandlers/loginHandlers.js +0 -46
- package/agents/assistants/modes/toolHandlers/subscriptionHandlers.js +0 -469
- package/agents/assistants/modes/tools/agentConnectionTools.js +0 -326
- package/agents/assistants/modes/tools/commonHandlers.js +0 -57
- package/agents/assistants/modes/tools/loginHandlers.js +0 -46
- package/agents/assistants/modes/tools/subscriptionHandlers.js +0 -469
- package/agents/controllers/assistantController.js +0 -243
- package/agents/managers/workflowManager.js +0 -76
- package/agents/models/testData/setupConfig.js +0 -140
- package/agents/models/workflow.js +0 -53
- package/agents/subscriptionManager.js +0 -218
- package/app.d.ts +0 -40
- package/app.d.ts.map +0 -1
- package/bot_control.d.ts.map +0 -1
- package/publish.d.ts.map +0 -1
- package/repack.d.ts.map +0 -1
- package/scripts/addRatingUsersToGroup.d.ts.map +0 -1
- package/scripts/addUserToOrganization.d.ts.map +0 -1
- package/scripts/analyseRatingsForCommunity.d.ts.map +0 -1
- package/scripts/analyzeAndFixBrokenPointUsers.d.ts.map +0 -1
- package/scripts/analyzeEndorsementsByCountry.d.ts.map +0 -1
- package/scripts/analyzePostsForCommunity.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/listUpdates.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdate.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdateForGroup.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdateForStatus.d.ts.map +0 -1
- package/scripts/change/changeVideoAspectTo.d.ts.map +0 -1
- package/scripts/changeCommunityGroupcount.d.ts.map +0 -1
- package/scripts/changeCommunityPostCount.d.ts.map +0 -1
- package/scripts/changeGroupPostCount.d.ts.map +0 -1
- package/scripts/changeLanguage.d.ts.map +0 -1
- package/scripts/changeOfficalStatus.d.ts.map +0 -1
- package/scripts/cleanups/deleteAnonNotifications.d.ts.map +0 -1
- package/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.d.ts.map +0 -1
- package/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.d.ts.map +0 -1
- package/scripts/clearAllEndorsementInGroup.d.ts.map +0 -1
- package/scripts/cloning/clearUsersForCommunitiesFromUrl.d.ts.map +0 -1
- package/scripts/cloning/cloneFromUrlScript.d.ts.map +0 -1
- package/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.d.ts.map +0 -1
- package/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainWithEverything.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainWithOnlyGroups.d.ts.map +0 -1
- package/scripts/cloning/copyGroupConfigAndTranslationsFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyPostToGroupOld.d.ts.map +0 -1
- package/scripts/cloning/copyPostVideosFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyPostWithOutAnyVotingOrActivities.d.ts.map +0 -1
- package/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/setAdminsFromURL.d.ts.map +0 -1
- package/scripts/cloning/setExternalIdsFromURL.d.ts.map +0 -1
- package/scripts/countCommunity.d.ts.map +0 -1
- package/scripts/countCommunityUsers.d.ts.map +0 -1
- package/scripts/countDelayedNotifications.d.ts.map +0 -1
- package/scripts/countGroup.d.ts.map +0 -1
- package/scripts/countStuff.d.ts.map +0 -1
- package/scripts/countUniqueVotersInAGroup.d.ts.map +0 -1
- package/scripts/createInvitesAndShow.d.ts.map +0 -1
- package/scripts/database/seedTestAiModels.js +0 -64
- package/scripts/database/sync_database.d.ts.map +0 -1
- package/scripts/database/sync_dev_database.d.ts.map +0 -1
- package/scripts/debugNotifications.d.ts.map +0 -1
- package/scripts/deleteAllNewsFeeds.d.ts.map +0 -1
- package/scripts/deleteCategory.d.ts.map +0 -1
- package/scripts/deleteOldAppActivities.d.ts.map +0 -1
- package/scripts/deletePostContactDataForCommunity.d.ts.map +0 -1
- package/scripts/destroy/destroy_all_but_one_domain.d.ts.map +0 -1
- package/scripts/displayAuthorForPost.d.ts.map +0 -1
- package/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.d.ts.map +0 -1
- package/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.d.ts.map +0 -1
- package/scripts/exportAllStatusChanges.d.ts.map +0 -1
- package/scripts/exportClientAcitivity.d.ts.map +0 -1
- package/scripts/exportEndorsementsForCommunity.d.ts.map +0 -1
- package/scripts/exportPointQualitiesForCommunity.d.ts.map +0 -1
- package/scripts/exportPostsAndPointsForCommunity.d.ts.map +0 -1
- package/scripts/exportPostsDataSetForDomain.d.ts.map +0 -1
- package/scripts/exportPostsForGroup.d.ts.map +0 -1
- package/scripts/exportRatingsForPost.d.ts.map +0 -1
- package/scripts/exportUserEndorsementsWithUserAnalysis.d.ts.map +0 -1
- package/scripts/exportUsersForCommunity.d.ts.map +0 -1
- package/scripts/exportUsersForDomain.d.ts.map +0 -1
- package/scripts/exportUsersForGroup.d.ts.map +0 -1
- package/scripts/exports/ratingDistribution.d.ts.map +0 -1
- package/scripts/exports/whoEndorsedWhatByCommunity.d.ts.map +0 -1
- package/scripts/findUnusedClientImports.d.ts.map +0 -1
- package/scripts/fixAllPostPointCounts.d.ts.map +0 -1
- package/scripts/fixAnonNotificationsSettings.d.ts.map +0 -1
- package/scripts/fixCountKopavogur.d.ts.map +0 -1
- package/scripts/fixEndorsementsAfterCopyPostToGroup.d.ts.map +0 -1
- package/scripts/fixExternalUserId.d.ts.map +0 -1
- package/scripts/fixGroupAccess.d.ts.map +0 -1
- package/scripts/fixGroupIdeasAndPointsCount.d.ts.map +0 -1
- package/scripts/fixNotificationSettings.d.ts.map +0 -1
- package/scripts/fixSurveyRadioBakedInSubCodes.d.ts.map +0 -1
- package/scripts/fixWrongUserIdForStatusUpdates.d.ts.map +0 -1
- package/scripts/gallery/exportGalleryData.d.ts.map +0 -1
- package/scripts/gallery/importGalleryForCommunity.d.ts.map +0 -1
- package/scripts/gallery/readJsonAndDownloadImagesVersion2.d.ts.map +0 -1
- package/scripts/gallery/refreshAcApiPostIdsForCommunity.d.ts.map +0 -1
- package/scripts/genderAnalysis.d.ts.map +0 -1
- package/scripts/genderAnalysisByStatus.d.ts.map +0 -1
- package/scripts/importAllLocalesFromLocalFolders.d.ts.map +0 -1
- package/scripts/importDomain.d.ts.map +0 -1
- package/scripts/landUseGame/export3Ddata.d.ts.map +0 -1
- package/scripts/listLanguagesForGroup.d.ts.map +0 -1
- package/scripts/loadTestCreateDummyContentForGroup.d.ts.map +0 -1
- package/scripts/makeRecursiveMapData.d.ts.map +0 -1
- package/scripts/mapping/community_map_csv.d.ts.map +0 -1
- package/scripts/moveCommunityToDomain.d.ts.map +0 -1
- package/scripts/moveGroupToCommunity.d.ts.map +0 -1
- package/scripts/movePostToGroup.d.ts.map +0 -1
- package/scripts/movePostsToGroupsRecountGroupFromUrl.d.ts.map +0 -1
- package/scripts/oldMovePostToGroup.d.ts.map +0 -1
- package/scripts/processCsvForPdfUrls.d.ts.map +0 -1
- package/scripts/processCsvForTranslationAndToxicity.d.ts.map +0 -1
- package/scripts/recount/recount_recursive_communities.d.ts.map +0 -1
- package/scripts/recountALLCommunityGroupCounts.d.ts.map +0 -1
- package/scripts/recountAll.d.ts.map +0 -1
- package/scripts/recountCommunitesFromUrl.d.ts.map +0 -1
- package/scripts/recountCommunity.d.ts.map +0 -1
- package/scripts/recountGroup.d.ts.map +0 -1
- package/scripts/recountGroupNoUserChange.d.ts.map +0 -1
- package/scripts/resetAllEndorsementsForGroup.d.ts.map +0 -1
- package/scripts/resetEnTranslationForGroup.d.ts.map +0 -1
- package/scripts/setDomainLocales.d.ts.map +0 -1
- package/scripts/setLanguageOnGroupCommunitesFromUrl.d.ts.map +0 -1
- package/scripts/setMemberOfAll.d.ts.map +0 -1
- package/scripts/setNewUserForContentOfCommunity.d.ts.map +0 -1
- package/scripts/setOfficialStatusOnAllPostsForCommunity.d.ts.map +0 -1
- package/scripts/setUserOnAll.d.ts.map +0 -1
- package/scripts/showCategoryForGroup.d.ts.map +0 -1
- package/scripts/showOldActivityTypes.d.ts.map +0 -1
- package/scripts/showPostsMissingCategoryForGroup.d.ts.map +0 -1
- package/scripts/showStatuses.d.ts.map +0 -1
- package/scripts/showUniqueVotersInCommunity.d.ts.map +0 -1
- package/scripts/showUserAgentsAndIpsForEmails.d.ts.map +0 -1
- package/scripts/simpleExportForGroupsForCommunity.d.ts.map +0 -1
- package/scripts/simpleExportForPointsForCommunity.d.ts.map +0 -1
- package/scripts/simpleExportForPostsForCommunity.d.ts.map +0 -1
- package/scripts/testForEndorsments.d.ts.map +0 -1
- package/scripts/undeleteGroupAndAllContent.d.ts.map +0 -1
- package/scripts/undeletePost.d.ts.map +0 -1
- package/scripts/unlinkSsn.d.ts.map +0 -1
- package/scripts/updateFromAlthingi.d.ts.map +0 -1
- package/server.d.ts.map +0 -1
- package/utils/copyGroup.js +0 -246
- package/utils/loggerTs.d.ts +0 -4
- package/utils/loggerTs.d.ts.map +0 -1
- package/utils/ypLanguages.d.ts +0 -18
- package/utils/ypLanguages.d.ts.map +0 -1
- /package/{agents/tools/updateCommunityWorkflow.js → dist/active-citizen/llms/imageGeneration/iImageGenerator.js} +0 -0
- /package/{migrations/270724_createUsersAndAdminsForClasses.cjs → dist/migrations/zzzz_createUsersAndAdminsForClasses.cjs} +0 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { OpenAI } from "openai";
|
|
2
|
+
export class AiHelper {
|
|
3
|
+
constructor(wsClientSocket = undefined) {
|
|
4
|
+
this.modelName = "gpt-4o";
|
|
5
|
+
this.maxTokens = 2048;
|
|
6
|
+
this.temperature = 0.7;
|
|
7
|
+
this.cacheExpireTime = 60 * 60;
|
|
8
|
+
this.moderationSystemPrompt = (instructions) => `The user will provide you with a question and an answer.
|
|
9
|
+
Your job is to moderate the answer if it passes automated moderation or not.
|
|
10
|
+
Moderation instructions:
|
|
11
|
+
${instructions}
|
|
12
|
+
|
|
13
|
+
Only output: PASSES or FAILS`;
|
|
14
|
+
this.moderationUserPrompt = (question, answer) => `
|
|
15
|
+
Question: ${question}
|
|
16
|
+
Answer: ${answer}
|
|
17
|
+
`;
|
|
18
|
+
this.getModerationResponse = async (instructions, question, answerToModerate) => {
|
|
19
|
+
const messages = [
|
|
20
|
+
{
|
|
21
|
+
role: "system",
|
|
22
|
+
content: this.moderationSystemPrompt(instructions),
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
role: "user",
|
|
26
|
+
content: this.moderationUserPrompt(question, answerToModerate),
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
console.log(JSON.stringify(messages, null, 2));
|
|
30
|
+
const response = await this.openaiClient.chat.completions.create({
|
|
31
|
+
model: this.modelName,
|
|
32
|
+
messages,
|
|
33
|
+
max_tokens: 5,
|
|
34
|
+
temperature: 0,
|
|
35
|
+
});
|
|
36
|
+
if (response &&
|
|
37
|
+
response.choices &&
|
|
38
|
+
response.choices[0] &&
|
|
39
|
+
response.choices[0].message &&
|
|
40
|
+
response.choices[0].message.content) {
|
|
41
|
+
console.log("Moderation response:", response.choices[0].message.content);
|
|
42
|
+
return ["PASSES", "PASS"].includes(response.choices[0].message.content.toUpperCase())
|
|
43
|
+
? true
|
|
44
|
+
: false;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
this.openaiClient = new OpenAI({
|
|
51
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
52
|
+
});
|
|
53
|
+
this.wsClientSocket = wsClientSocket;
|
|
54
|
+
}
|
|
55
|
+
async streamChatCompletions(messages) {
|
|
56
|
+
const stream = await this.openaiClient.chat.completions.create({
|
|
57
|
+
model: this.modelName,
|
|
58
|
+
messages,
|
|
59
|
+
max_tokens: this.maxTokens,
|
|
60
|
+
temperature: this.temperature,
|
|
61
|
+
stream: true,
|
|
62
|
+
});
|
|
63
|
+
await this.streamWebSocketResponses(stream);
|
|
64
|
+
}
|
|
65
|
+
sendToClient(sender, message, type = "stream") {
|
|
66
|
+
this.wsClientSocket?.send(JSON.stringify({
|
|
67
|
+
sender,
|
|
68
|
+
type: type,
|
|
69
|
+
message,
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
async streamWebSocketResponses(stream) {
|
|
73
|
+
return new Promise(async (resolve, reject) => {
|
|
74
|
+
this.sendToClient("bot", "", "start");
|
|
75
|
+
try {
|
|
76
|
+
let botMessage = "";
|
|
77
|
+
for await (const part of stream) {
|
|
78
|
+
this.sendToClient("bot", part.choices[0].delta.content);
|
|
79
|
+
botMessage += part.choices[0].delta.content;
|
|
80
|
+
}
|
|
81
|
+
if (this.redisClient && this.cacheKeyForFullResponse) {
|
|
82
|
+
this.redisClient.set(this.cacheKeyForFullResponse, botMessage, "EX", this.cacheExpireTime);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.error(error);
|
|
87
|
+
this.sendToClient("bot", "There has been an error, please retry", "error");
|
|
88
|
+
reject();
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
this.sendToClient("bot", "", "end");
|
|
92
|
+
}
|
|
93
|
+
resolve();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async getAnswerIdeas(question, previousIdeas, firstMessage) {
|
|
97
|
+
try {
|
|
98
|
+
const moderationResponse = await this.openaiClient.moderations.create({
|
|
99
|
+
input: question,
|
|
100
|
+
});
|
|
101
|
+
console.log("Moderation response:", moderationResponse);
|
|
102
|
+
const flagged = moderationResponse.results[0].flagged;
|
|
103
|
+
console.log("Flagged:", flagged);
|
|
104
|
+
if (flagged) {
|
|
105
|
+
console.error("Flagged:", question);
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
let firstMessageWithPreviousIdeasTemplate = "";
|
|
110
|
+
let previewIdeasText = "";
|
|
111
|
+
if (previousIdeas && previousIdeas.length > 0) {
|
|
112
|
+
previewIdeasText = `Previous answer ideas:\n${JSON.stringify(previousIdeas, null, 2)}\n\n`;
|
|
113
|
+
if (firstMessage) {
|
|
114
|
+
firstMessageWithPreviousIdeasTemplate =
|
|
115
|
+
"For your answers please follow the tone of voice, prose, style, and length of the Previous answer ideas\n";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const messages = [
|
|
119
|
+
{
|
|
120
|
+
role: "system",
|
|
121
|
+
content: `You are a highly competent AI that is able to generate clear answer ideas for questions.
|
|
122
|
+
Genereate up to 10 high quality answer ideas.
|
|
123
|
+
Never use numbers at the start of each line.
|
|
124
|
+
Always output the ideas in the same language the user is asking the question.
|
|
125
|
+
Never use a dash or quote or anything similar at the start of each line, just start with the text.
|
|
126
|
+
Never output more than 30 words per idea.
|
|
127
|
+
\n${firstMessageWithPreviousIdeasTemplate}`,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
role: "user",
|
|
131
|
+
content: `What are some possible answers to the question: ${question}\n\n${previewIdeasText}Answers:\n`,
|
|
132
|
+
},
|
|
133
|
+
];
|
|
134
|
+
await this.streamChatCompletions(messages);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
console.error("Error in getAnswerIdeas:", error);
|
|
139
|
+
this.sendToClient("bot", "There has been an error, please retry", "error");
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async getAiAnalysis(questionId, contextPrompt, answers, cacheKeyForFullResponse, redisClient, locale, topOrBottomIdeasText, typeOfAnalysisText) {
|
|
144
|
+
this.redisClient = redisClient;
|
|
145
|
+
this.cacheKeyForFullResponse = cacheKeyForFullResponse;
|
|
146
|
+
const basePrePrompt = `You are a highly competent text and ideas analysis AI.
|
|
147
|
+
Instructions:
|
|
148
|
+
If an answer sounds implausible as an answer to the question, then include a short observation about it in your analysis.
|
|
149
|
+
Keep your output short, under 300 words.
|
|
150
|
+
The answers have been rated by the public using a pairwise voting method, so the user is always selecting one to win or one to lose.
|
|
151
|
+
Generally, do not include the number of wins and losses in your answers.
|
|
152
|
+
If there are very few wins or losses, under 10 for most of the ideas, then always output a disclaimer to that end, in a separate second paragraph.
|
|
153
|
+
Don't output Idea 1, Idea 2 in your answer.
|
|
154
|
+
Be creative and think step by step.
|
|
155
|
+
|
|
156
|
+
Output:
|
|
157
|
+
If the prompt asks for a table always output a markdown table.
|
|
158
|
+
Always output in a clear markdown format.
|
|
159
|
+
Always start with the type of analysis and if those are top or bottom ideas.
|
|
160
|
+
|
|
161
|
+
Example output:
|
|
162
|
+
|
|
163
|
+
## Points for the most popular answers
|
|
164
|
+
|
|
165
|
+
<Your dynamic markdown output>
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
`;
|
|
169
|
+
const answersText = answers
|
|
170
|
+
.map((answer) => `${answer.data.content} (Won: ${answer.wins}, Lost: ${answer.losses})`)
|
|
171
|
+
.join("\n");
|
|
172
|
+
try {
|
|
173
|
+
const moderationResponse = await this.openaiClient.moderations.create({
|
|
174
|
+
input: answersText,
|
|
175
|
+
});
|
|
176
|
+
const flagged = moderationResponse.results[0].flagged;
|
|
177
|
+
if (flagged) {
|
|
178
|
+
console.error("Flagged:", answersText);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
const messages = [
|
|
183
|
+
{
|
|
184
|
+
role: "system",
|
|
185
|
+
content: `${basePrePrompt}\n${contextPrompt}`,
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
role: "user",
|
|
189
|
+
content: `The question: ${questionId}
|
|
190
|
+
${topOrBottomIdeasText}
|
|
191
|
+
Type of analysis: ${typeOfAnalysisText}
|
|
192
|
+
Language to output: ${locale}
|
|
193
|
+
Answers to analyse:\n${answersText}`,
|
|
194
|
+
},
|
|
195
|
+
];
|
|
196
|
+
this.streamChatCompletions(messages);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
console.error("Error in getAiAnalysis:", error);
|
|
201
|
+
this.sendToClient("bot", "There has been an error, please retry", "error");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { OpenAI } from "openai";
|
|
2
|
+
import { YpBaseChatBot } from "../../llms/baseChatBot.js";
|
|
3
|
+
import ioredis from "ioredis";
|
|
4
|
+
import { v4 as uuidv4 } from "uuid";
|
|
5
|
+
const tlsOptions = process.env.REDIS_MEMORY_URL?.startsWith("rediss://")
|
|
6
|
+
? { rejectUnauthorized: false }
|
|
7
|
+
: undefined;
|
|
8
|
+
export class ExplainAnswersAssistant extends YpBaseChatBot {
|
|
9
|
+
constructor(wsClientId, wsClients, languageName) {
|
|
10
|
+
const redisConnection = new ioredis.default(process.env.REDIS_MEMORY_URL ||
|
|
11
|
+
process.env.REDIS_URL ||
|
|
12
|
+
"redis://localhost:6379", {
|
|
13
|
+
tls: tlsOptions,
|
|
14
|
+
});
|
|
15
|
+
super(wsClientId, wsClients, redisConnection, `${YpBaseChatBot.redisMemoryKeyPrefix}-${uuidv4()}-explain-answers-assistant`);
|
|
16
|
+
this.modelName = "gpt-4o";
|
|
17
|
+
this.maxTokens = 4000;
|
|
18
|
+
this.temperature = 0.8;
|
|
19
|
+
this.explainConversation = async (chatLog) => {
|
|
20
|
+
this.setChatLog(chatLog);
|
|
21
|
+
let messages = chatLog.map((message) => {
|
|
22
|
+
return {
|
|
23
|
+
role: message.sender,
|
|
24
|
+
content: message.message,
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
const systemMessage = {
|
|
28
|
+
role: "system",
|
|
29
|
+
content: this.renderSystemPrompt(),
|
|
30
|
+
};
|
|
31
|
+
messages.unshift(systemMessage);
|
|
32
|
+
const stream = await this.openaiClient.chat.completions.create({
|
|
33
|
+
model: this.llmModel,
|
|
34
|
+
messages,
|
|
35
|
+
max_tokens: this.maxTokens,
|
|
36
|
+
temperature: this.temperature,
|
|
37
|
+
stream: true,
|
|
38
|
+
});
|
|
39
|
+
this.streamWebSocketResponses(stream);
|
|
40
|
+
};
|
|
41
|
+
this.languageName = languageName;
|
|
42
|
+
this.openaiClient = new OpenAI({
|
|
43
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
renderSystemPrompt() {
|
|
47
|
+
return `The user is doing pairwise voting on two answers at the time, to a question, the user needs help deciding what to vote on.
|
|
48
|
+
|
|
49
|
+
Instructions:
|
|
50
|
+
Use a relevant emoji for the first and second answers.
|
|
51
|
+
Use thumbs emojis for pros and thumb down emjoi for cons
|
|
52
|
+
Use summary emoji for summary.
|
|
53
|
+
Use simple and upbeat language.
|
|
54
|
+
Ask the user clarifying questions if needed.
|
|
55
|
+
Always answers in the language the user asks for.
|
|
56
|
+
|
|
57
|
+
Output:
|
|
58
|
+
* Each answer
|
|
59
|
+
-- One short paragraph, max three sentences, explanation in a very simple language
|
|
60
|
+
-- The top pro and con
|
|
61
|
+
-- If this is likely to be a root cause of the problem set out in the question
|
|
62
|
+
* Never offer the user your opinion as we don't want to influence the user, they must make their own decision.
|
|
63
|
+
* Always output in this language: ${this.languageName}
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import { v4 as uuidv4 } from "uuid";
|
|
4
|
+
import axios from "axios";
|
|
5
|
+
import models from "../../../models/index.cjs";
|
|
6
|
+
import { CollectionImageGenerator } from "../../llms/imageGeneration/collectionImageGenerator.js";
|
|
7
|
+
const dbModels = models;
|
|
8
|
+
const Image = dbModels.Image;
|
|
9
|
+
export class AoiIconGenerator extends CollectionImageGenerator {
|
|
10
|
+
async createCollectionImage(workPackage) {
|
|
11
|
+
// 1. Generate the image and record using the base implementation.
|
|
12
|
+
const { imageId, imageUrl } = await super.createCollectionImage(workPackage);
|
|
13
|
+
// 2. Now process the image for the icon:
|
|
14
|
+
// Download the generated image to a temporary location.
|
|
15
|
+
const tempIconPath = path.join("/tmp", `${uuidv4()}-icon.png`);
|
|
16
|
+
await this.imageProcessorService.downloadImage(imageUrl, tempIconPath, axios);
|
|
17
|
+
if (!fs.existsSync(tempIconPath)) {
|
|
18
|
+
throw new Error("Failed to download the generated image for icon processing.");
|
|
19
|
+
}
|
|
20
|
+
// Resize the downloaded image to 400x400 pixels.
|
|
21
|
+
const resizedIconPath = await this.imageProcessorService.resizeImage(tempIconPath, 400, 400);
|
|
22
|
+
// Define a new S3 path for the icon image.
|
|
23
|
+
const iconS3ImagePath = `ypGenAi/${workPackage.collectionType}/${workPackage.collectionId}/${uuidv4()}-icon.png`;
|
|
24
|
+
// Upload the resized icon to S3.
|
|
25
|
+
await this.s3Service.uploadImageToS3(process.env.S3_BUCKET, resizedIconPath, iconS3ImagePath);
|
|
26
|
+
// Construct a public URL for the icon image.
|
|
27
|
+
const newIconUrl = process.env.CLOUDFLARE_IMAGE_PROXY_DOMAIN
|
|
28
|
+
? `https://${process.env.CLOUDFLARE_IMAGE_PROXY_DOMAIN}/${iconS3ImagePath}`
|
|
29
|
+
: `https://${process.env.S3_BUCKET}.s3.amazonaws.com/${iconS3ImagePath}`;
|
|
30
|
+
// Optionally, update the DB record with the new icon URL.
|
|
31
|
+
const imageRecord = await Image.findOne({ where: { id: imageId } });
|
|
32
|
+
if (imageRecord) {
|
|
33
|
+
imageRecord.formats = JSON.stringify([newIconUrl]);
|
|
34
|
+
await imageRecord.save();
|
|
35
|
+
}
|
|
36
|
+
return { imageId, imageUrl: newIconUrl };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
const models = require('../../../models/index.cjs');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
|
+
const log = require('../../../utils/logger.cjs');
|
|
5
|
+
const crypto = require('crypto');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
//const request = require('request');
|
|
8
|
+
const request = {
|
|
9
|
+
post: (data, done) => {
|
|
10
|
+
console.log(JSON.stringify(data, null, 4));
|
|
11
|
+
done();
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const clean = (text) => {
|
|
15
|
+
//console.log("Before: "+ text);
|
|
16
|
+
var newText = text.replace('"', "'").replace('\n', '').replace('\r', '').replace(/(\r\n|\n|\r)/gm, "").replace(/"/gm, "'").replace(/,/, ';').trim();
|
|
17
|
+
//console.log("After:" + newText);
|
|
18
|
+
return newText.replace(/´/g, '');
|
|
19
|
+
};
|
|
20
|
+
const getEncryptedId = (id, key, iv) => {
|
|
21
|
+
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key), iv);
|
|
22
|
+
let encrypted = cipher.update(id.toString());
|
|
23
|
+
encrypted = Buffer.concat([encrypted, cipher.final()]);
|
|
24
|
+
return encrypted.toString('hex');
|
|
25
|
+
};
|
|
26
|
+
let csvPostsTxt = "Id,Date,Name,NameEn,Description,DescriptionEn,ToxicityScore\n";
|
|
27
|
+
const saveAnonymousPost = (post, accessKey, done) => {
|
|
28
|
+
let expiryDate = new Date();
|
|
29
|
+
expiryDate.setDate(expiryDate.getDate() + 7);
|
|
30
|
+
const properties = {
|
|
31
|
+
id: post.id,
|
|
32
|
+
name: post.name,
|
|
33
|
+
name_en: post.name_en,
|
|
34
|
+
date: post.created_at.toISOString(),
|
|
35
|
+
description: post.description,
|
|
36
|
+
description_en: post.description_en,
|
|
37
|
+
toxicity_score: post.toxicity_score,
|
|
38
|
+
access_key: accessKey,
|
|
39
|
+
access_expires_at: expiryDate.toISOString()
|
|
40
|
+
};
|
|
41
|
+
csvPostsTxt += post.id + ',' + properties.date + ',"' + clean(post.name) + '","' + clean(post.name_en) + '",' + '"' + clean(post.description) + '",' + '"' + clean(post.description_en) + '",' + post.toxicity_score + '\n';
|
|
42
|
+
const options = {
|
|
43
|
+
url: process.env["AC_ANALYTICS_BASE_URL"] + "anonPosts/" + process.env.AC_ANALYTICS_CLUSTER_ID + "/" + `${accessKey}${post.id}`,
|
|
44
|
+
headers: {
|
|
45
|
+
'X-API-KEY': process.env["AC_ANALYTICS_KEY"]
|
|
46
|
+
},
|
|
47
|
+
json: properties
|
|
48
|
+
};
|
|
49
|
+
request.post(options, (error) => {
|
|
50
|
+
done(error);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
let csvPointsTxt = "Id,Date,Content,ContentEn,Value,ToxicityScore\n";
|
|
54
|
+
const saveAnonymousPoint = (point, accessKey, done) => {
|
|
55
|
+
let expiryDate = new Date();
|
|
56
|
+
expiryDate.setDate(expiryDate.getDate() + 7);
|
|
57
|
+
const properties = {
|
|
58
|
+
id: point.id,
|
|
59
|
+
date: point.created_at.toISOString(),
|
|
60
|
+
content: point.content,
|
|
61
|
+
content_en: point.content_en,
|
|
62
|
+
value: point.value,
|
|
63
|
+
access_key: accessKey,
|
|
64
|
+
toxicity_score: point.toxicity_score,
|
|
65
|
+
access_expires_at: expiryDate.toISOString()
|
|
66
|
+
};
|
|
67
|
+
csvPointsTxt += point.id + ',' + properties.date + ',"' + clean(point.content) + '",' + '"' + clean(point.content_en) + '",' + point.value + ',' + point.toxicity_score + '\n';
|
|
68
|
+
const options = {
|
|
69
|
+
url: process.env["AC_ANALYTICS_BASE_URL"] + "anonPoints/" + process.env.AC_ANALYTICS_CLUSTER_ID + "/" + `${accessKey}${point.id}`,
|
|
70
|
+
headers: {
|
|
71
|
+
'X-API-KEY': process.env["AC_ANALYTICS_KEY"]
|
|
72
|
+
},
|
|
73
|
+
json: properties
|
|
74
|
+
};
|
|
75
|
+
request.post(options, (error) => {
|
|
76
|
+
done(error);
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
let csvActivitiesTxt = "Id,Date,Type,PointId,PostId,UserId\n";
|
|
80
|
+
const saveActivity = (activity, accessKey, done) => {
|
|
81
|
+
let expiryDate = new Date();
|
|
82
|
+
expiryDate.setDate(expiryDate.getDate() + 7);
|
|
83
|
+
const properties = {
|
|
84
|
+
id: activity.id,
|
|
85
|
+
date: activity.created_at.toISOString(),
|
|
86
|
+
type: activity.type,
|
|
87
|
+
point_id: activity.point_id,
|
|
88
|
+
post_id: activity.post_id,
|
|
89
|
+
user_id: activity.user_id,
|
|
90
|
+
access_key: accessKey,
|
|
91
|
+
access_expires_at: expiryDate.toISOString()
|
|
92
|
+
};
|
|
93
|
+
csvActivitiesTxt += activity.id + ',' + properties.date + ',"' + activity.type + '",' + '"' + activity.point_id + '",' + '"' + activity.post_id + '",' + '"' + activity.user_id + '"\n';
|
|
94
|
+
const options = {
|
|
95
|
+
url: process.env["AC_ANALYTICS_BASE_URL"] + "anonActivities/" + process.env.AC_ANALYTICS_CLUSTER_ID + "/" + `${accessKey}${activity.id}`,
|
|
96
|
+
headers: {
|
|
97
|
+
'X-API-KEY': process.env["AC_ANALYTICS_KEY"]
|
|
98
|
+
},
|
|
99
|
+
json: properties
|
|
100
|
+
};
|
|
101
|
+
request.post(options, (error) => {
|
|
102
|
+
done(error);
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
let csvUsersTxt = "Id\n";
|
|
106
|
+
const saveAnonymousUser = (user, accessKey, done) => {
|
|
107
|
+
let expiryDate = new Date();
|
|
108
|
+
expiryDate.setDate(expiryDate.getDate() + 7);
|
|
109
|
+
const properties = {
|
|
110
|
+
id: user.id,
|
|
111
|
+
access_key: accessKey,
|
|
112
|
+
access_expires_at: expiryDate.toISOString()
|
|
113
|
+
};
|
|
114
|
+
csvUsersTxt += user.id + '\n';
|
|
115
|
+
const options = {
|
|
116
|
+
url: process.env["AC_ANALYTICS_BASE_URL"] + "anonUsers/" + process.env.AC_ANALYTICS_CLUSTER_ID + "/" + `${accessKey}${user.id}`,
|
|
117
|
+
headers: {
|
|
118
|
+
'X-API-KEY': process.env["AC_ANALYTICS_KEY"]
|
|
119
|
+
},
|
|
120
|
+
json: properties
|
|
121
|
+
};
|
|
122
|
+
request.post(options, (error) => {
|
|
123
|
+
done(error);
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
const collectAllPostsAndPoints = (activities, collectedPostIds, collectedPointIds) => {
|
|
127
|
+
activities.forEach((item) => {
|
|
128
|
+
if (item.Post) {
|
|
129
|
+
collectedPostIds.push(item.Post.id);
|
|
130
|
+
}
|
|
131
|
+
if (item.Point) {
|
|
132
|
+
collectedPointIds.push(item.Point.id);
|
|
133
|
+
}
|
|
134
|
+
if (!item.Point && !item.Post) {
|
|
135
|
+
log.warn("Can't find post or point id for activity in anonymous export", { item });
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
const sendAllCollectedPostAndPoints = (accessKey, collectedPostIds, collectedPointIds, encryptionKey, encryptionIv, done) => {
|
|
140
|
+
collectedPostIds = _.uniq(collectedPostIds);
|
|
141
|
+
collectedPointIds = _.uniq(collectedPointIds);
|
|
142
|
+
async.series([
|
|
143
|
+
(seriesCallback) => {
|
|
144
|
+
async.forEachSeries(collectedPostIds, (postId, forEachSeriesCallback) => {
|
|
145
|
+
models.Post.findOne({
|
|
146
|
+
where: {
|
|
147
|
+
id: postId
|
|
148
|
+
},
|
|
149
|
+
attributes: ['id', 'name', 'description', 'public_data', 'created_at', 'data']
|
|
150
|
+
}).then((post) => {
|
|
151
|
+
let req = {
|
|
152
|
+
query: {
|
|
153
|
+
textType: 'postContent',
|
|
154
|
+
targetLanguage: 'en'
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
models.AcTranslationCache.getTranslation(req, post, function (error, descriptionEn) {
|
|
158
|
+
req = {
|
|
159
|
+
query: {
|
|
160
|
+
textType: 'postName',
|
|
161
|
+
targetLanguage: 'en'
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
models.AcTranslationCache.getTranslation(req, post, function (error, nameEn) {
|
|
165
|
+
saveAnonymousPost({
|
|
166
|
+
id: getEncryptedId((post.id), encryptionKey, encryptionIv),
|
|
167
|
+
name: post.name,
|
|
168
|
+
name_en: nameEn ? nameEn.content : 'no translation',
|
|
169
|
+
created_at: post.created_at,
|
|
170
|
+
toxicity_score: (post.data && post.data.moderation) ? post.data.moderation.toxicityScore : null,
|
|
171
|
+
description: post.description,
|
|
172
|
+
description_en: descriptionEn ? descriptionEn.content : 'no translation',
|
|
173
|
+
}, accessKey, forEachSeriesCallback);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
}).catch((error) => {
|
|
177
|
+
forEachSeriesCallback(error);
|
|
178
|
+
});
|
|
179
|
+
}, (error) => {
|
|
180
|
+
seriesCallback(error);
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
(seriesCallback) => {
|
|
184
|
+
async.forEachSeries(collectedPointIds, (pointId, forEachSeriesCallback) => {
|
|
185
|
+
models.Point.findOne({
|
|
186
|
+
where: {
|
|
187
|
+
id: pointId
|
|
188
|
+
},
|
|
189
|
+
order: [
|
|
190
|
+
[models.PointRevision, 'created_at', 'asc'],
|
|
191
|
+
],
|
|
192
|
+
attributes: ['id', 'created_at', 'content', 'value', 'data'],
|
|
193
|
+
include: [
|
|
194
|
+
{
|
|
195
|
+
model: models.PointRevision,
|
|
196
|
+
attributes: ['id', 'content']
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
}).then((point) => {
|
|
200
|
+
let req = {
|
|
201
|
+
query: {
|
|
202
|
+
textType: 'pointContent',
|
|
203
|
+
targetLanguage: 'en'
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
models.AcTranslationCache.getTranslation(req, point, function (error, contentEn) {
|
|
207
|
+
saveAnonymousPoint({
|
|
208
|
+
id: getEncryptedId((point.id), encryptionKey, encryptionIv),
|
|
209
|
+
content: point.content,
|
|
210
|
+
value: point.value,
|
|
211
|
+
toxicity_score: (point.data && point.data.moderation) ? point.data.moderation.toxicityScore : null,
|
|
212
|
+
created_at: point.created_at,
|
|
213
|
+
content_en: contentEn ? contentEn.content : 'no translation'
|
|
214
|
+
}, accessKey, forEachSeriesCallback);
|
|
215
|
+
});
|
|
216
|
+
}).catch((error) => {
|
|
217
|
+
forEachSeriesCallback(error);
|
|
218
|
+
});
|
|
219
|
+
}, (error) => {
|
|
220
|
+
seriesCallback(error);
|
|
221
|
+
});
|
|
222
|
+
},
|
|
223
|
+
], (error) => {
|
|
224
|
+
done(error);
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
const sendAllUserActivitiesWithContent = (userId, communityId, collectedPostIds, collectedPointIds, encryptionKey, encryptionIv, accessKey, done) => {
|
|
228
|
+
models.AcActivity.findAll({
|
|
229
|
+
where: {
|
|
230
|
+
user_id: userId,
|
|
231
|
+
community_id: communityId,
|
|
232
|
+
type: {
|
|
233
|
+
$in: [
|
|
234
|
+
"activity.post.new", "activity.post.opposition.new", "activity.post.endorsement.new",
|
|
235
|
+
"activity.point.new", "activity.point.helpful.new", "activity.point.unhelpful.new"
|
|
236
|
+
]
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
attributes: ['id', 'type', 'created_at', 'user_id', 'post_id', 'point_id'],
|
|
240
|
+
include: [
|
|
241
|
+
{
|
|
242
|
+
model: models.Post,
|
|
243
|
+
required: false,
|
|
244
|
+
attributes: ['id']
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
model: models.Point,
|
|
248
|
+
required: false,
|
|
249
|
+
attributes: ['id']
|
|
250
|
+
}
|
|
251
|
+
]
|
|
252
|
+
}).then((activities) => {
|
|
253
|
+
collectAllPostsAndPoints(activities, collectedPostIds, collectedPointIds);
|
|
254
|
+
async.forEachSeries(activities, (activity, forEachSeriesCallback) => {
|
|
255
|
+
if (activity.Post || activity.Point) {
|
|
256
|
+
saveActivity({
|
|
257
|
+
id: getEncryptedId(activity.id, encryptionKey, encryptionIv),
|
|
258
|
+
type: activity.type,
|
|
259
|
+
created_at: activity.created_at,
|
|
260
|
+
post_id: activity.Post ? getEncryptedId(activity.Post.id, encryptionKey, encryptionIv) : null,
|
|
261
|
+
point_id: activity.Point ? getEncryptedId(activity.Point.id, encryptionKey, encryptionIv) : null,
|
|
262
|
+
user_id: getEncryptedId(activity.user_id, encryptionKey, encryptionIv)
|
|
263
|
+
}, accessKey, forEachSeriesCallback);
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
log.warn("Can't find post or point for activity");
|
|
267
|
+
forEachSeriesCallback();
|
|
268
|
+
}
|
|
269
|
+
}, (error) => {
|
|
270
|
+
done(error);
|
|
271
|
+
});
|
|
272
|
+
}).catch(function (error) {
|
|
273
|
+
done(error);
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
const importCommunityUsersAndActivities = (communityId, accessKey, done) => {
|
|
277
|
+
const encryptionKey = crypto.randomBytes(32);
|
|
278
|
+
const encryptionIv = crypto.randomBytes(16);
|
|
279
|
+
let collectedPostIds = [];
|
|
280
|
+
let collectedPointIds = [];
|
|
281
|
+
models.Community.findOne({
|
|
282
|
+
where: {
|
|
283
|
+
id: communityId
|
|
284
|
+
},
|
|
285
|
+
include: [
|
|
286
|
+
{
|
|
287
|
+
model: models.User,
|
|
288
|
+
attributes: ['id'],
|
|
289
|
+
as: 'CommunityUsers',
|
|
290
|
+
required: true,
|
|
291
|
+
}
|
|
292
|
+
]
|
|
293
|
+
}).then(function (community) {
|
|
294
|
+
if (community && community.CommunityUsers) {
|
|
295
|
+
async.forEachSeries(community.CommunityUsers, (user, eachSeriesCallback) => {
|
|
296
|
+
saveAnonymousUser({
|
|
297
|
+
id: getEncryptedId(user.id, encryptionKey, encryptionIv)
|
|
298
|
+
}, accessKey, (error) => {
|
|
299
|
+
if (error) {
|
|
300
|
+
eachSeriesCallback(error);
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
sendAllUserActivitiesWithContent(user.id, communityId, collectedPostIds, collectedPointIds, encryptionKey, encryptionIv, accessKey, eachSeriesCallback);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}, (error) => {
|
|
307
|
+
if (error) {
|
|
308
|
+
done(error);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
sendAllCollectedPostAndPoints(accessKey, collectedPostIds, collectedPointIds, encryptionKey, encryptionIv, (error) => {
|
|
312
|
+
done(error);
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
done("Could not find community");
|
|
319
|
+
}
|
|
320
|
+
}).catch(function (error) {
|
|
321
|
+
done(error);
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
importCommunityUsersAndActivities(1017, "12345", () => {
|
|
325
|
+
fs.writeFileSync("/home/robert/Scratch/MMU/users.csv", csvUsersTxt);
|
|
326
|
+
fs.writeFileSync("/home/robert/Scratch/MMU/posts.csv", csvPostsTxt);
|
|
327
|
+
fs.writeFileSync("/home/robert/Scratch/MMU/points.csv", csvPointsTxt);
|
|
328
|
+
fs.writeFileSync("/home/robert/Scratch/MMU/activities.csv", csvActivitiesTxt);
|
|
329
|
+
process.exit();
|
|
330
|
+
});
|
|
331
|
+
module.exports = {
|
|
332
|
+
importCommunityUsersAndActivities
|
|
333
|
+
};
|
|
334
|
+
export {};
|