@yrpri/api 9.0.103 → 9.0.104
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 -1
- 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,110 +0,0 @@
|
|
|
1
|
-
import AWS from "aws-sdk";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import axios from "axios";
|
|
4
|
-
export class S3Service {
|
|
5
|
-
constructor(cloudflareApiKey, cloudflareZoneId) {
|
|
6
|
-
this.cloudflareApiKey = cloudflareApiKey;
|
|
7
|
-
this.cloudflareZoneId = cloudflareZoneId;
|
|
8
|
-
}
|
|
9
|
-
async uploadImageToS3(bucket, filePath, key) {
|
|
10
|
-
const s3 = new AWS.S3();
|
|
11
|
-
const fileContent = fs.readFileSync(filePath);
|
|
12
|
-
const params = {
|
|
13
|
-
Bucket: bucket,
|
|
14
|
-
Key: key,
|
|
15
|
-
Body: fileContent,
|
|
16
|
-
ACL: "public-read",
|
|
17
|
-
ContentType: "image/png",
|
|
18
|
-
ContentDisposition: "inline",
|
|
19
|
-
};
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
s3.upload(params, (err, data) => {
|
|
22
|
-
if (err) {
|
|
23
|
-
reject(err);
|
|
24
|
-
}
|
|
25
|
-
fs.unlinkSync(filePath);
|
|
26
|
-
resolve(data);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
async deleteS3Url(imageUrl) {
|
|
31
|
-
const { bucket, key } = this.parseImageUrl(imageUrl);
|
|
32
|
-
if (!bucket || !key) {
|
|
33
|
-
throw new Error("Could not parse bucket or key from URL");
|
|
34
|
-
}
|
|
35
|
-
const s3 = new AWS.S3();
|
|
36
|
-
const params = {
|
|
37
|
-
Bucket: bucket,
|
|
38
|
-
Key: key,
|
|
39
|
-
ACL: "private",
|
|
40
|
-
};
|
|
41
|
-
console.log(`Disabling/Deleting Key from S3: ${JSON.stringify(params)}`);
|
|
42
|
-
return new Promise((resolve, reject) => {
|
|
43
|
-
s3.putObjectAcl(params, (err, data) => {
|
|
44
|
-
if (err) {
|
|
45
|
-
console.error(`Error deleting image from S3: ${err}`);
|
|
46
|
-
reject(err);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
console.log(`Deleted image from S3: ${imageUrl}`, data);
|
|
50
|
-
if (this.cloudflareApiKey && this.cloudflareZoneId) {
|
|
51
|
-
console.log("Purging Cloudflare cache for image:", imageUrl);
|
|
52
|
-
axios
|
|
53
|
-
.post(`https://api.cloudflare.com/client/v4/zones/${this.cloudflareZoneId}/purge_cache`, { files: [imageUrl] }, {
|
|
54
|
-
headers: {
|
|
55
|
-
Authorization: `Bearer ${this.cloudflareApiKey}`,
|
|
56
|
-
"Content-Type": "application/json",
|
|
57
|
-
},
|
|
58
|
-
})
|
|
59
|
-
.then((response) => {
|
|
60
|
-
console.log("Cloudflare cache purged:", response.data);
|
|
61
|
-
resolve(data);
|
|
62
|
-
})
|
|
63
|
-
.catch((error) => {
|
|
64
|
-
if (error.response) {
|
|
65
|
-
console.error("Error purging Cloudflare cache:", error.response.data);
|
|
66
|
-
console.error("Status code:", error.response.status);
|
|
67
|
-
console.error("Headers:", error.response.headers);
|
|
68
|
-
}
|
|
69
|
-
else if (error.request) {
|
|
70
|
-
console.error("No response received:", error.request);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
console.error("Error setting up request:", error.message);
|
|
74
|
-
}
|
|
75
|
-
resolve(data);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
resolve(data);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
parseImageUrl(imageUrl) {
|
|
86
|
-
let bucket, key;
|
|
87
|
-
const cfImageProxyDomain = process.env.CLOUDFLARE_IMAGE_PROXY_DOMAIN;
|
|
88
|
-
const s3Bucket = process.env.S3_BUCKET;
|
|
89
|
-
if (cfImageProxyDomain && imageUrl.includes(cfImageProxyDomain)) {
|
|
90
|
-
const urlPath = new URL(imageUrl).pathname;
|
|
91
|
-
const [, ...pathParts] = urlPath.split("/");
|
|
92
|
-
bucket = s3Bucket;
|
|
93
|
-
key = pathParts.join("/");
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
const match = imageUrl.match(/https:\/\/(.+?)\.s3\.amazonaws\.com\/(.+)/);
|
|
97
|
-
if (match) {
|
|
98
|
-
bucket = match[1];
|
|
99
|
-
key = match[2];
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return { bucket, key };
|
|
103
|
-
}
|
|
104
|
-
async deleteMediaFormatsUrls(formats) {
|
|
105
|
-
for (const url of formats) {
|
|
106
|
-
await this.deleteS3Url(url);
|
|
107
|
-
console.log(`Deleted image from S3: ${url}`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,472 +0,0 @@
|
|
|
1
|
-
import { jsonrepair } from "jsonrepair";
|
|
2
|
-
import { OpenAI } from "openai";
|
|
3
|
-
import { YpLanguages } from "../../utils/ypLanguages.js";
|
|
4
|
-
import * as cheerio from "cheerio";
|
|
5
|
-
export class YpLlmTranslation {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.modelName = "gpt-4o";
|
|
8
|
-
this.maxTokens = 4000;
|
|
9
|
-
this.temperature = 0.0;
|
|
10
|
-
this.openaiClient = new OpenAI({
|
|
11
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
extractHtmlStrings(html) {
|
|
15
|
-
const $ = cheerio.load(html);
|
|
16
|
-
const strings = [];
|
|
17
|
-
// Function to recursively extract text from all elements
|
|
18
|
-
function recursivelyExtractText(elements) {
|
|
19
|
-
elements.each((index, element) => {
|
|
20
|
-
if (element.tagName.toLowerCase() === "script" ||
|
|
21
|
-
element.tagName.toLowerCase().indexOf("icon") > -1) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
// Check if the element itself contains a direct text node
|
|
25
|
-
$(element)
|
|
26
|
-
.contents()
|
|
27
|
-
.filter((idx, content) => {
|
|
28
|
-
// Ensure that content is a text node and not empty
|
|
29
|
-
return (content.type === "text" && $(content).text().trim().length > 0);
|
|
30
|
-
})
|
|
31
|
-
.each((idx, content) => {
|
|
32
|
-
const text = $(content).text().trim();
|
|
33
|
-
if (text) {
|
|
34
|
-
strings.push(text);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
// Recursively extract text from child elements
|
|
38
|
-
recursivelyExtractText($(element).children());
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
// Start the recursive text extraction from the body or root of the document
|
|
42
|
-
recursivelyExtractText($("body").length ? $("body") : $.root());
|
|
43
|
-
// Attributes with user-facing text
|
|
44
|
-
$("input[placeholder], input[value]").each((index, element) => {
|
|
45
|
-
const placeholder = $(element).attr("placeholder");
|
|
46
|
-
if (placeholder && placeholder.trim().length > 0) {
|
|
47
|
-
strings.push(placeholder.trim());
|
|
48
|
-
}
|
|
49
|
-
const value = $(element).attr("value");
|
|
50
|
-
if (value &&
|
|
51
|
-
$(element).attr("type") !== "text" &&
|
|
52
|
-
value.trim().length > 0) {
|
|
53
|
-
strings.push(value.trim());
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
$('[label]').each((index, element) => {
|
|
57
|
-
const label = $(element).attr('label')?.trim();
|
|
58
|
-
if (label && label.length > 0) {
|
|
59
|
-
strings.push(label);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
// Return unique non-empty strings
|
|
63
|
-
return [...new Set(strings)];
|
|
64
|
-
}
|
|
65
|
-
replaceHtmlStrings(html, originalStrings, translatedStrings) {
|
|
66
|
-
const $ = cheerio.load(html);
|
|
67
|
-
// Function to replace attribute values safely
|
|
68
|
-
function replaceAttributeValues(container) {
|
|
69
|
-
$(container)
|
|
70
|
-
.find("input, textarea, select, [label]")
|
|
71
|
-
.each(function () {
|
|
72
|
-
const element = $(this);
|
|
73
|
-
// Replace placeholder attribute for input, textarea, and select
|
|
74
|
-
const placeholder = element.attr("placeholder");
|
|
75
|
-
if (placeholder) {
|
|
76
|
-
const index = originalStrings.indexOf(placeholder.trim());
|
|
77
|
-
if (index > -1 && translatedStrings[index]) {
|
|
78
|
-
element.attr("placeholder", translatedStrings[index]);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
// Replace value attribute for inputs that are not of type text, email, etc.
|
|
82
|
-
if (element.is('input[type="button"], input[type="submit"]')) {
|
|
83
|
-
const value = element.val();
|
|
84
|
-
if (typeof value === "string") {
|
|
85
|
-
const index = originalStrings.indexOf(value.trim());
|
|
86
|
-
if (index > -1 && translatedStrings[index]) {
|
|
87
|
-
element.val(translatedStrings[index]);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// Replace label attribute for any element with a label
|
|
92
|
-
if (element.is('[label]')) {
|
|
93
|
-
const label = element.attr('label');
|
|
94
|
-
if (label) {
|
|
95
|
-
const index = originalStrings.indexOf(label.trim());
|
|
96
|
-
if (index > -1 && translatedStrings[index]) {
|
|
97
|
-
element.attr('label', translatedStrings[index]);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
// Function to safely replace text without disrupting child elements
|
|
104
|
-
function safelyReplaceText(container) {
|
|
105
|
-
$(container)
|
|
106
|
-
.contents()
|
|
107
|
-
.each(function () {
|
|
108
|
-
// If the node is a text node
|
|
109
|
-
if (this.type === "text") {
|
|
110
|
-
let text = $(this).text();
|
|
111
|
-
originalStrings.forEach((str, index) => {
|
|
112
|
-
// Replace text if it exactly matches the original string (considering whitespace)
|
|
113
|
-
if (text.trim() === str.trim() && translatedStrings[index]) {
|
|
114
|
-
text = text.replace(str, translatedStrings[index]);
|
|
115
|
-
$(this).replaceWith(text);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
else if (this.type === "tag") {
|
|
120
|
-
// Recursively handle nested elements
|
|
121
|
-
safelyReplaceText(this);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
// Replace attribute values before replacing text
|
|
126
|
-
replaceAttributeValues($.root());
|
|
127
|
-
// Initiate replacement from the root element for text nodes
|
|
128
|
-
safelyReplaceText($.root());
|
|
129
|
-
return $.html();
|
|
130
|
-
}
|
|
131
|
-
// System messages
|
|
132
|
-
renderSchemaSystemMessage(jsonInSchema, jsonOutSchema, lengthInfo) {
|
|
133
|
-
return `You are a helpful answer translation assistant that knows all the world languages.
|
|
134
|
-
INPUTS:
|
|
135
|
-
The user will tell us the Language to translate to.
|
|
136
|
-
|
|
137
|
-
The user will let you know what the question is but you do not need to translate that one.
|
|
138
|
-
|
|
139
|
-
You will get JSON input with the string to be translated: ${jsonInSchema}
|
|
140
|
-
|
|
141
|
-
OUTPUT:
|
|
142
|
-
You will output JSON format with the translation. ${jsonOutSchema}
|
|
143
|
-
|
|
144
|
-
INSTRUCTIONS:
|
|
145
|
-
The translated text MUST NEVER be more than ${lengthInfo}, otherwise it wont fit the UI.
|
|
146
|
-
Please count the words and never go over the limit. Leave some things out off the translation it's going to be too long.
|
|
147
|
-
Translate the tone of the original language also.
|
|
148
|
-
Always output only JSON.`;
|
|
149
|
-
}
|
|
150
|
-
renderSchemaTryAgainSystemMessage(jsonInSchema, jsonOutSchema, lengthInfo, currentToLong) {
|
|
151
|
-
return `You are a helpful answer translation assistant that knows all the world languages.
|
|
152
|
-
INPUTS:
|
|
153
|
-
The user will tell us the Language to translate to.
|
|
154
|
-
|
|
155
|
-
The user will let you know what the question is but you do not need to translate that one.
|
|
156
|
-
|
|
157
|
-
You will get JSON input with the string to be translated: ${jsonInSchema}
|
|
158
|
-
|
|
159
|
-
OUTPUT:
|
|
160
|
-
You will output JSON format with the translation. ${jsonOutSchema}
|
|
161
|
-
|
|
162
|
-
INSTRUCTIONS:
|
|
163
|
-
The translated text MUST NEVER be more than ${lengthInfo}, otherwise it wont fit the UI.
|
|
164
|
-
Please count the words and never go over the limit. Leave some things out off the translation it's going to be too long.
|
|
165
|
-
Translate the tone of the original language also.
|
|
166
|
-
Always output only JSON.
|
|
167
|
-
|
|
168
|
-
IMPORTANT INSTRUCTIONS:
|
|
169
|
-
You have already attempted to translate the string user is submitting and it is too long, see here:
|
|
170
|
-
${currentToLong}
|
|
171
|
-
It MUST be shorter than this. Please try again and make it shorter.
|
|
172
|
-
`;
|
|
173
|
-
}
|
|
174
|
-
renderOneTranslationSystemMessage() {
|
|
175
|
-
return `You are a helpful answer translation assistant that knows all the world languages.
|
|
176
|
-
INPUTS:
|
|
177
|
-
The user will tell us the Language to translate to.
|
|
178
|
-
The user will give you a string to be translated.
|
|
179
|
-
|
|
180
|
-
OUTPUT:
|
|
181
|
-
You will output only the translated string.
|
|
182
|
-
|
|
183
|
-
INSTRUCTIONS:
|
|
184
|
-
Keep it similar length as the original text.
|
|
185
|
-
Translate the tone of the original language also.
|
|
186
|
-
NEVER output anything else than the translated string.`;
|
|
187
|
-
}
|
|
188
|
-
renderListTranslationSystemMessage() {
|
|
189
|
-
return `You are a helpful translation assistant that knows all the world languages.
|
|
190
|
-
|
|
191
|
-
INPUTS:
|
|
192
|
-
The user will tell us the Language to translate to.
|
|
193
|
-
|
|
194
|
-
You will get JSON with an array of strings to translate:
|
|
195
|
-
[
|
|
196
|
-
"string",
|
|
197
|
-
...
|
|
198
|
-
]
|
|
199
|
-
|
|
200
|
-
OUTPUT:
|
|
201
|
-
You will output JSON string array in the same order as the input array.
|
|
202
|
-
[
|
|
203
|
-
"string",
|
|
204
|
-
...
|
|
205
|
-
]
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
INSTRUCTIONS:
|
|
209
|
-
Do not translate brand names including ours: All Our Ideas and Your Priorities except it is a well known brand in the target language.
|
|
210
|
-
Always output only a JSON string array.`;
|
|
211
|
-
}
|
|
212
|
-
// User messages
|
|
213
|
-
renderOneTranslationUserMessage(language, stringToTranslate) {
|
|
214
|
-
return `Language to translate to: ${language}
|
|
215
|
-
String to translate:
|
|
216
|
-
${stringToTranslate}
|
|
217
|
-
Your translated string:`;
|
|
218
|
-
}
|
|
219
|
-
renderListTranslationUserMessage(language, textsToTranslate) {
|
|
220
|
-
return `Language to translate to: ${language}
|
|
221
|
-
Texts to translate in JSON string array:
|
|
222
|
-
${JSON.stringify(textsToTranslate, null, 2)}
|
|
223
|
-
|
|
224
|
-
Your ${language} translations as JSON string array:`;
|
|
225
|
-
}
|
|
226
|
-
renderAnswersUserMessage(language, question, answer) {
|
|
227
|
-
return `Language to translate to: ${language}
|
|
228
|
-
|
|
229
|
-
Question:
|
|
230
|
-
${question}
|
|
231
|
-
|
|
232
|
-
Answers to translate in JSON Input:
|
|
233
|
-
${JSON.stringify(answer, null, 2)}
|
|
234
|
-
|
|
235
|
-
Your ${language} JSON output:`;
|
|
236
|
-
}
|
|
237
|
-
renderQuestionUserMessage(language, question, questionData) {
|
|
238
|
-
return `Language to translate to: ${language}
|
|
239
|
-
|
|
240
|
-
Question to translate in JSON format:
|
|
241
|
-
${JSON.stringify(questionData, null, 2)}
|
|
242
|
-
|
|
243
|
-
Your ${language} JSON output:`;
|
|
244
|
-
}
|
|
245
|
-
async getModerationFlag(content) {
|
|
246
|
-
const moderationResponse = await this.openaiClient.moderations.create({
|
|
247
|
-
input: content,
|
|
248
|
-
});
|
|
249
|
-
console.log("Moderation response:", moderationResponse);
|
|
250
|
-
const flagged = moderationResponse.results[0].flagged;
|
|
251
|
-
return flagged;
|
|
252
|
-
}
|
|
253
|
-
async getHtmlTranslation(languageIsoCode, htmlToTranslate) {
|
|
254
|
-
try {
|
|
255
|
-
const originalStrings = this.extractHtmlStrings(htmlToTranslate);
|
|
256
|
-
if (originalStrings.length === 0) {
|
|
257
|
-
console.warn("No HTML strings to translate");
|
|
258
|
-
return htmlToTranslate;
|
|
259
|
-
}
|
|
260
|
-
const batchSize = 10;
|
|
261
|
-
const translatedStrings = [];
|
|
262
|
-
for (let i = 0; i < originalStrings.length; i += batchSize) {
|
|
263
|
-
const batch = originalStrings.slice(i, i + batchSize);
|
|
264
|
-
const translatedBatch = await this.getListTranslation(languageIsoCode, batch);
|
|
265
|
-
if (translatedBatch) {
|
|
266
|
-
translatedStrings.push(...translatedBatch);
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
console.error("Failed to translate batch:", batch);
|
|
270
|
-
return undefined;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
// Replace original strings in HTML with their translations
|
|
274
|
-
const translatedHtml = this.replaceHtmlStrings(htmlToTranslate, originalStrings, translatedStrings);
|
|
275
|
-
return translatedHtml;
|
|
276
|
-
}
|
|
277
|
-
catch (error) {
|
|
278
|
-
console.error("Error in getHtmlTranslation:", error);
|
|
279
|
-
return undefined;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
async getOneTranslation(languageIsoCode, stringToTranslate) {
|
|
283
|
-
try {
|
|
284
|
-
console.log(`getOneTranslation: ${stringToTranslate} ${languageIsoCode}`);
|
|
285
|
-
const languageName = YpLanguages.getEnglishName(languageIsoCode) || languageIsoCode;
|
|
286
|
-
return (await this.callSimpleLlm(languageName, stringToTranslate, false, this.renderOneTranslationSystemMessage, this.renderOneTranslationUserMessage));
|
|
287
|
-
}
|
|
288
|
-
catch (error) {
|
|
289
|
-
console.error("Error in getAnswerIdeas:", error);
|
|
290
|
-
return undefined;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
async getListTranslation(languageIsoCode, stringsToTranslate) {
|
|
294
|
-
try {
|
|
295
|
-
console.log(`getOneTranslation: ${languageIsoCode}`);
|
|
296
|
-
const languageName = YpLanguages.getEnglishName(languageIsoCode) || languageIsoCode;
|
|
297
|
-
if (await this.getModerationFlag(stringsToTranslate.join(" "))) {
|
|
298
|
-
console.error("Flagged:", stringsToTranslate);
|
|
299
|
-
return null;
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
return (await this.callSimpleLlm(languageName, stringsToTranslate, true, this.renderListTranslationSystemMessage, this.renderListTranslationUserMessage));
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
catch (error) {
|
|
306
|
-
console.error("Error in getAnswerIdeas:", error);
|
|
307
|
-
return undefined;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
async getChoiceTranslation(languageIsoCode, answerContent, maxCharactersInTranslation = 140) {
|
|
311
|
-
try {
|
|
312
|
-
console.log(`async getChoiceTranslation: ${answerContent}`);
|
|
313
|
-
const languageName = YpLanguages.getEnglishName(languageIsoCode) || languageIsoCode;
|
|
314
|
-
if (await this.getModerationFlag(answerContent)) {
|
|
315
|
-
console.error("Flagged:", answerContent);
|
|
316
|
-
return null;
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
const inAnswer = {
|
|
320
|
-
answerToTranslate: answerContent,
|
|
321
|
-
};
|
|
322
|
-
const jsonInSchema = `{ answerToTranslate: string}`;
|
|
323
|
-
const jsonOutSchema = `{ translatedContent: string}`;
|
|
324
|
-
const lengthInfo = `26 words long or 140 characters`;
|
|
325
|
-
return await this.callSchemaLlm(jsonInSchema, jsonOutSchema, lengthInfo, languageName, "", inAnswer, maxCharactersInTranslation, this.renderSchemaSystemMessage, this.renderAnswersUserMessage);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
catch (error) {
|
|
329
|
-
console.error("Error in getAnswerIdeas:", error);
|
|
330
|
-
return undefined;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
async getQuestionTranslation(languageIsoCode, question, maxCharactersInTranslation = 300) {
|
|
334
|
-
try {
|
|
335
|
-
console.log(`getQuestionTranslation: ${question} ${languageIsoCode}`);
|
|
336
|
-
const languageName = YpLanguages.getEnglishName(languageIsoCode) || languageIsoCode;
|
|
337
|
-
if (await this.getModerationFlag(question)) {
|
|
338
|
-
console.error("Flagged:", question);
|
|
339
|
-
return null;
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
342
|
-
const inQuestion = {
|
|
343
|
-
questionToTranslate: question,
|
|
344
|
-
};
|
|
345
|
-
const jsonInSchema = `{ questionToTranslate: string}`;
|
|
346
|
-
const jsonOutSchema = `{ translatedContent: string}`;
|
|
347
|
-
const lengthInfo = `40 words long or 250 characters`;
|
|
348
|
-
return await this.callSchemaLlm(jsonInSchema, jsonOutSchema, lengthInfo, languageName, question, inQuestion, maxCharactersInTranslation, this.renderSchemaSystemMessage, this.renderQuestionUserMessage);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
catch (error) {
|
|
352
|
-
console.error("Error in getAnswerIdeas:", error);
|
|
353
|
-
return undefined;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
async callSimpleLlm(languageName, toTranslate, parseJson, systemRenderer, userRenderer) {
|
|
357
|
-
const messages = [
|
|
358
|
-
{
|
|
359
|
-
role: "system",
|
|
360
|
-
content: systemRenderer(),
|
|
361
|
-
},
|
|
362
|
-
{
|
|
363
|
-
role: "user",
|
|
364
|
-
content: userRenderer(languageName, toTranslate),
|
|
365
|
-
},
|
|
366
|
-
];
|
|
367
|
-
const maxRetries = 3;
|
|
368
|
-
let retries = 0;
|
|
369
|
-
let running = true;
|
|
370
|
-
while (running) {
|
|
371
|
-
try {
|
|
372
|
-
console.log(`Messages ${retries}:`, messages);
|
|
373
|
-
const results = await this.openaiClient.chat.completions.create({
|
|
374
|
-
model: this.modelName,
|
|
375
|
-
messages,
|
|
376
|
-
max_tokens: this.maxTokens,
|
|
377
|
-
temperature: this.temperature,
|
|
378
|
-
});
|
|
379
|
-
console.log("Results:", results);
|
|
380
|
-
let llmOutput = results.choices[0].message.content;
|
|
381
|
-
console.log("Return text:", llmOutput);
|
|
382
|
-
if (parseJson) {
|
|
383
|
-
if (llmOutput) {
|
|
384
|
-
llmOutput = llmOutput.replace(/```json/g, "");
|
|
385
|
-
llmOutput = llmOutput.replace(/```/g, "");
|
|
386
|
-
return JSON.parse(jsonrepair(llmOutput));
|
|
387
|
-
}
|
|
388
|
-
{
|
|
389
|
-
console.error("No content in response");
|
|
390
|
-
return undefined;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
else {
|
|
394
|
-
return llmOutput;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
catch (error) {
|
|
398
|
-
console.error("Error in getChoiceTranslation:", error);
|
|
399
|
-
retries++;
|
|
400
|
-
if (retries > maxRetries) {
|
|
401
|
-
running = false;
|
|
402
|
-
return undefined;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
async callSchemaLlm(jsonInSchema, jsonOutSchema, lengthInfo, languageName, question, toTranslate, maxCharactersInTranslation, systemRenderer, userRenderer) {
|
|
408
|
-
console.log("Call schema LLM:", jsonInSchema, jsonOutSchema, lengthInfo, languageName, question, toTranslate, maxCharactersInTranslation);
|
|
409
|
-
const messages = [
|
|
410
|
-
{
|
|
411
|
-
role: "system",
|
|
412
|
-
content: this.renderSchemaSystemMessage(jsonInSchema, jsonOutSchema, lengthInfo),
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
role: "user",
|
|
416
|
-
content: userRenderer(languageName, question, toTranslate),
|
|
417
|
-
},
|
|
418
|
-
];
|
|
419
|
-
const maxRetries = 5;
|
|
420
|
-
let retries = 0;
|
|
421
|
-
let running = true;
|
|
422
|
-
while (running) {
|
|
423
|
-
try {
|
|
424
|
-
console.log(`Messages ${retries}:`, messages);
|
|
425
|
-
const results = await this.openaiClient.chat.completions.create({
|
|
426
|
-
model: this.modelName,
|
|
427
|
-
messages,
|
|
428
|
-
max_tokens: this.maxTokens,
|
|
429
|
-
temperature: this.temperature,
|
|
430
|
-
});
|
|
431
|
-
console.log("Results:", results);
|
|
432
|
-
let textJson = results.choices[0].message.content;
|
|
433
|
-
console.log("Text JSON:", textJson);
|
|
434
|
-
if (textJson) {
|
|
435
|
-
textJson = textJson.replace(/```json/g, "");
|
|
436
|
-
textJson = textJson.replace(/```/g, "");
|
|
437
|
-
const translationData = JSON.parse(jsonrepair(textJson));
|
|
438
|
-
if (translationData && translationData.translatedContent) {
|
|
439
|
-
if (maxCharactersInTranslation &&
|
|
440
|
-
translationData.translatedContent.length >
|
|
441
|
-
maxCharactersInTranslation) {
|
|
442
|
-
console.log("Translation too long retrying:", translationData.translatedContent);
|
|
443
|
-
messages[0].content = this.renderSchemaTryAgainSystemMessage(jsonInSchema, jsonOutSchema, lengthInfo, translationData.translatedContent);
|
|
444
|
-
throw new Error("Translation too long");
|
|
445
|
-
}
|
|
446
|
-
running = false;
|
|
447
|
-
console.log("Return text " + translationData.translatedContent);
|
|
448
|
-
return translationData.translatedContent;
|
|
449
|
-
}
|
|
450
|
-
else {
|
|
451
|
-
this.temperature = Math.random() * 0.99;
|
|
452
|
-
console.log("No content in response. Temperature set to: " + this.temperature);
|
|
453
|
-
throw new Error("No content in response");
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
this.temperature = Math.random() * 0.99;
|
|
458
|
-
console.log("No content in response. Temperature set to:" + this.temperature);
|
|
459
|
-
throw new Error("No content in response");
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
catch (error) {
|
|
463
|
-
console.error("Error in callSchemaLlm:", error);
|
|
464
|
-
retries++;
|
|
465
|
-
if (retries > maxRetries) {
|
|
466
|
-
running = false;
|
|
467
|
-
return undefined;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
}
|