@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,183 +0,0 @@
|
|
|
1
|
-
import { OpenAI } from "openai";
|
|
2
|
-
const DEBUG = false;
|
|
3
|
-
const url = process.env.REDIS_MEMORY_URL ||
|
|
4
|
-
process.env.REDIS_URL ||
|
|
5
|
-
"redis://localhost:6379";
|
|
6
|
-
const tlsOptions = url.startsWith("rediss://")
|
|
7
|
-
? { rejectUnauthorized: false }
|
|
8
|
-
: undefined;
|
|
9
|
-
export class YpBaseChatBot {
|
|
10
|
-
destroy() {
|
|
11
|
-
this.wsClientSocket = undefined;
|
|
12
|
-
}
|
|
13
|
-
loadMemory() {
|
|
14
|
-
return new Promise(async (resolve, reject) => {
|
|
15
|
-
try {
|
|
16
|
-
console.log("loadMemoryWithOwnership loadMemory: redisKey: ", this.redisKey);
|
|
17
|
-
const memoryString = await this.redis.get(this.redisKey);
|
|
18
|
-
if (memoryString) {
|
|
19
|
-
const memory = JSON.parse(memoryString);
|
|
20
|
-
resolve(memory);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
console.error("loadMemoryWithOwnership loadMemory: no memory found");
|
|
24
|
-
resolve(undefined);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
console.error("loadMemoryWithOwnership loadMemory: Can't load memory from redis", error);
|
|
29
|
-
resolve(undefined);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
constructor(wsClientId, wsClients, redisConnection, redisKey) {
|
|
34
|
-
this.temperature = 0.7;
|
|
35
|
-
this.maxTokens = 16000;
|
|
36
|
-
this.llmModel = "gpt-4o";
|
|
37
|
-
this.persistMemory = false;
|
|
38
|
-
this.redis = redisConnection;
|
|
39
|
-
this.redisKey = redisKey;
|
|
40
|
-
this.wsClientId = wsClientId;
|
|
41
|
-
this.wsClientSocket = wsClients.get(this.wsClientId);
|
|
42
|
-
this.wsClients = wsClients;
|
|
43
|
-
console.log(`WebSockets: BaseChatBot constructor for ${this.wsClientId}`);
|
|
44
|
-
if (!this.wsClientSocket) {
|
|
45
|
-
console.error(`WebSockets: WS Client ${this.wsClientId} not found in streamWebSocketResponses`);
|
|
46
|
-
}
|
|
47
|
-
this.openaiClient = new OpenAI({
|
|
48
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
async saveMemory() {
|
|
52
|
-
if (this.memory) {
|
|
53
|
-
try {
|
|
54
|
-
await this.redis.set(this.redisKey, JSON.stringify(this.memory));
|
|
55
|
-
console.log(`Saved memory to redis: ${this.redisKey}`);
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
console.log("Can't save memory to redis", error);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
console.error("Memory is not initialized");
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
renderSystemPrompt() {
|
|
66
|
-
return `Please tell the user to replace this system prompt in a fun and friendly way. Encourage them to have a nice day. Lots of emojis`;
|
|
67
|
-
}
|
|
68
|
-
sendAgentStart(name, hasNoStreaming = true) {
|
|
69
|
-
const botMessage = {
|
|
70
|
-
sender: "assistant",
|
|
71
|
-
type: "agentStart",
|
|
72
|
-
data: {
|
|
73
|
-
name: name,
|
|
74
|
-
noStreaming: hasNoStreaming,
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
this.wsClientSocket.send(JSON.stringify(botMessage));
|
|
78
|
-
}
|
|
79
|
-
sendAgentCompleted(name, lastAgent = false, error = undefined) {
|
|
80
|
-
const botMessage = {
|
|
81
|
-
sender: "assistant",
|
|
82
|
-
type: "agentCompleted",
|
|
83
|
-
data: {
|
|
84
|
-
name: name,
|
|
85
|
-
results: {
|
|
86
|
-
isValid: true,
|
|
87
|
-
validationErrors: error,
|
|
88
|
-
lastAgent: lastAgent,
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
this.wsClientSocket.send(JSON.stringify(botMessage));
|
|
93
|
-
}
|
|
94
|
-
sendAgentUpdate(message) {
|
|
95
|
-
const botMessage = {
|
|
96
|
-
sender: "assistant",
|
|
97
|
-
type: "agentUpdated",
|
|
98
|
-
message: message,
|
|
99
|
-
};
|
|
100
|
-
this.wsClientSocket.send(JSON.stringify(botMessage));
|
|
101
|
-
}
|
|
102
|
-
sendToClient(sender, message, type = "stream", uniqueToken = undefined, hiddenContextMessage = false) {
|
|
103
|
-
try {
|
|
104
|
-
if (process.env.WS_DEBUG) {
|
|
105
|
-
console.log(`sendToClient: ${JSON.stringify({ sender, type, message, hiddenContextMessage }, null, 2)}`);
|
|
106
|
-
}
|
|
107
|
-
this.wsClientSocket.send(JSON.stringify({
|
|
108
|
-
sender,
|
|
109
|
-
type: type,
|
|
110
|
-
message: type === "html" ? undefined : message,
|
|
111
|
-
html: type === "html" ? message : undefined,
|
|
112
|
-
hiddenContextMessage,
|
|
113
|
-
uniqueToken,
|
|
114
|
-
avatarUrl: sender === "assistant" ? this.currentAssistantAvatarUrl : undefined,
|
|
115
|
-
}));
|
|
116
|
-
this.lastSentToUserAt = new Date();
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
console.error("Can't send message to client", error);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
async streamWebSocketResponses(stream) {
|
|
123
|
-
return new Promise(async (resolve, reject) => {
|
|
124
|
-
this.sendToClient("assistant", "", "start", this.currentAssistantAvatarUrl);
|
|
125
|
-
try {
|
|
126
|
-
let botMessage = "";
|
|
127
|
-
for await (const part of stream) {
|
|
128
|
-
this.sendToClient("assistant", part.choices[0].delta.content);
|
|
129
|
-
botMessage += part.choices[0].delta.content;
|
|
130
|
-
if (part.choices[0].finish_reason == "stop") {
|
|
131
|
-
this.memory.chatLog.push({
|
|
132
|
-
sender: "assistant",
|
|
133
|
-
message: botMessage,
|
|
134
|
-
type: "message",
|
|
135
|
-
});
|
|
136
|
-
await this.saveMemoryIfNeeded();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
console.error(error);
|
|
142
|
-
this.sendToClient("assistant", "There has been an error, please retry", "error");
|
|
143
|
-
reject();
|
|
144
|
-
}
|
|
145
|
-
finally {
|
|
146
|
-
this.sendToClient("assistant", "", "end");
|
|
147
|
-
}
|
|
148
|
-
resolve();
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
async saveMemoryIfNeeded() {
|
|
152
|
-
if (this.persistMemory) {
|
|
153
|
-
await this.saveMemory();
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
async setChatLog(chatLog) {
|
|
157
|
-
this.memory.chatLog = chatLog;
|
|
158
|
-
await this.saveMemoryIfNeeded();
|
|
159
|
-
}
|
|
160
|
-
async conversation(chatLog) {
|
|
161
|
-
this.setChatLog(chatLog);
|
|
162
|
-
let messages = chatLog.map((message) => {
|
|
163
|
-
return {
|
|
164
|
-
role: message.sender,
|
|
165
|
-
content: message.message,
|
|
166
|
-
};
|
|
167
|
-
});
|
|
168
|
-
const systemMessage = {
|
|
169
|
-
role: "system",
|
|
170
|
-
content: this.renderSystemPrompt(),
|
|
171
|
-
};
|
|
172
|
-
messages.unshift(systemMessage);
|
|
173
|
-
const stream = await this.openaiClient.chat.completions.create({
|
|
174
|
-
model: this.llmModel,
|
|
175
|
-
messages,
|
|
176
|
-
max_tokens: this.maxTokens,
|
|
177
|
-
temperature: this.temperature,
|
|
178
|
-
stream: true,
|
|
179
|
-
});
|
|
180
|
-
this.streamWebSocketResponses(stream);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
YpBaseChatBot.redisMemoryKeyPrefix = "yp-chatbot-memory-v4";
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// chatGptImageGenerator.ts
|
|
2
|
-
import { OpenAI } from "openai";
|
|
3
|
-
export class ChatGptImageGenerator {
|
|
4
|
-
constructor(openAiKey) {
|
|
5
|
-
this.maxRetryCount = 3;
|
|
6
|
-
// the SDK will fall back to process.env.OPENAI_API_KEY if nothing is passed
|
|
7
|
-
this.openAiKey = openAiKey;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Generates an image URL from a prompt using OpenAI’s gpt-image-1 model.
|
|
11
|
-
* The returned link remains live for ~60 minutes – be sure to download
|
|
12
|
-
* or cache it right away in the calling service.
|
|
13
|
-
*/
|
|
14
|
-
async generateImageUrl(prompt, type = "logo") {
|
|
15
|
-
const client = new OpenAI({ apiKey: this.openAiKey });
|
|
16
|
-
// Pick a sensible canvas size from the image type
|
|
17
|
-
let size = "1536x1024";
|
|
18
|
-
if (type === "icon")
|
|
19
|
-
size = "1024x1024";
|
|
20
|
-
else if (type === "other")
|
|
21
|
-
size = "1536x1024";
|
|
22
|
-
const finalPrompt = `
|
|
23
|
-
${prompt}
|
|
24
|
-
|
|
25
|
-
Instruction: Create a high quality logo like image for the users project and follow their style instructions. \
|
|
26
|
-
Do not add text to the images unless asked in the style instructions.
|
|
27
|
-
`;
|
|
28
|
-
let retryCount = 0;
|
|
29
|
-
while (retryCount < this.maxRetryCount) {
|
|
30
|
-
try {
|
|
31
|
-
const res = await client.images.generate({
|
|
32
|
-
model: "gpt-image-1",
|
|
33
|
-
prompt: finalPrompt,
|
|
34
|
-
quality: "medium",
|
|
35
|
-
n: 1,
|
|
36
|
-
size
|
|
37
|
-
});
|
|
38
|
-
const url = res?.data?.[0]?.url;
|
|
39
|
-
if (url)
|
|
40
|
-
return url;
|
|
41
|
-
throw new Error("No URL returned");
|
|
42
|
-
}
|
|
43
|
-
catch (err) {
|
|
44
|
-
retryCount += 1;
|
|
45
|
-
if (retryCount >= this.maxRetryCount) {
|
|
46
|
-
console.error(`ChatGptImageGenerator failed after ${retryCount} attempts`, err);
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
// Exponential back-off – starts at 5 s and grows +5 s each retry
|
|
50
|
-
await new Promise((r) => setTimeout(r, 5000 + retryCount * 5000));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export default ChatGptImageGenerator;
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import { v4 as uuidv4 } from "uuid";
|
|
4
|
-
import axios from "axios";
|
|
5
|
-
import { FluxImageGenerator } from "./fluxImageGenerator.js";
|
|
6
|
-
import { DalleImageGenerator } from "./dalleImageGenerator.js";
|
|
7
|
-
import { ImageProcessorService } from "./imageProcessorService.js";
|
|
8
|
-
import { S3Service } from "./s3Service.js";
|
|
9
|
-
// Suppose these come from your codebase
|
|
10
|
-
import models from "../../../models/index.cjs";
|
|
11
|
-
import { ImagenImageGenerator } from "./imagenImageGenerator.js";
|
|
12
|
-
import { ChatGptImageGenerator } from "./chatGptImageGenerator.js";
|
|
13
|
-
// For reference, in your code:
|
|
14
|
-
const dbModels = models;
|
|
15
|
-
const Image = dbModels.Image;
|
|
16
|
-
const AcBackgroundJob = dbModels.AcBackgroundJob;
|
|
17
|
-
const disableFlux = false;
|
|
18
|
-
const useImagen = false;
|
|
19
|
-
export class CollectionImageGenerator {
|
|
20
|
-
constructor() {
|
|
21
|
-
this.s3Service = new S3Service(process.env.CLOUDFLARE_API_KEY, process.env.CLOUDFLARE_ZONE_ID);
|
|
22
|
-
this.imageProcessorService = new ImageProcessorService();
|
|
23
|
-
// Initialize generators
|
|
24
|
-
if (!disableFlux &&
|
|
25
|
-
process.env.REPLICATE_API_TOKEN &&
|
|
26
|
-
process.env.FLUX_PRO_MODEL_NAME) {
|
|
27
|
-
this.fluxImageGenerator = new FluxImageGenerator(process.env.REPLICATE_API_TOKEN, process.env.FLUX_PRO_MODEL_NAME);
|
|
28
|
-
}
|
|
29
|
-
this.dalleImageGenerator = new DalleImageGenerator(process.env.AZURE_OPENAI_API_BASE, process.env.AZURE_OPENAI_API_KEY, process.env.AZURE_OPENAI_API_DALLE_DEPLOYMENT_NAME, process.env.OPENAI_API_KEY);
|
|
30
|
-
this.chatGptImageGenerator = new ChatGptImageGenerator(process.env.OPENAI_API_KEY);
|
|
31
|
-
if (useImagen && process.env.GOOGLE_CLOUD_PROJECT_ID) {
|
|
32
|
-
this.imagenImageGenerator = new ImagenImageGenerator(this.s3Service);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Orchestrates image generation (via Flux or DALL·E), downloads that image,
|
|
37
|
-
* uploads it to S3, and saves a record in the DB.
|
|
38
|
-
*/
|
|
39
|
-
async createCollectionImage(workPackage) {
|
|
40
|
-
return new Promise(async (resolve, reject) => {
|
|
41
|
-
let newImageUrl;
|
|
42
|
-
const imageFilePath = path.join("/tmp", `${uuidv4()}.png`);
|
|
43
|
-
const s3ImagePath = `ypGenAi/${workPackage.collectionType}/${workPackage.collectionId}/${uuidv4()}.png`;
|
|
44
|
-
try {
|
|
45
|
-
let imageGenerator;
|
|
46
|
-
// Decide which generator to use
|
|
47
|
-
if (this.imagenImageGenerator) {
|
|
48
|
-
imageGenerator = this.imagenImageGenerator;
|
|
49
|
-
console.info("Using ImagenImageGenerator");
|
|
50
|
-
}
|
|
51
|
-
else if (this.fluxImageGenerator) {
|
|
52
|
-
imageGenerator = this.fluxImageGenerator;
|
|
53
|
-
console.info("Using FluxImageGenerator");
|
|
54
|
-
}
|
|
55
|
-
else if (process.env.USE_CHATGPT_IMAGE_GENERATOR) {
|
|
56
|
-
imageGenerator = this.chatGptImageGenerator;
|
|
57
|
-
console.info("Using ChatGptImageGenerator");
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
imageGenerator = this.dalleImageGenerator;
|
|
61
|
-
console.info("Using DalleImageGenerator");
|
|
62
|
-
}
|
|
63
|
-
// 1) Generate image
|
|
64
|
-
const imageUrl = await imageGenerator.generateImageUrl(workPackage.prompt, workPackage.imageType);
|
|
65
|
-
if (!imageUrl) {
|
|
66
|
-
return reject("Error getting image URL from prompt.");
|
|
67
|
-
}
|
|
68
|
-
if (useImagen && this.imagenImageGenerator) {
|
|
69
|
-
newImageUrl = imageUrl;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
// 2) Download image to temporary location
|
|
73
|
-
await this.imageProcessorService.downloadImage(imageUrl, imageFilePath, axios);
|
|
74
|
-
console.debug(fs.existsSync(imageFilePath)
|
|
75
|
-
? "File downloaded successfully."
|
|
76
|
-
: "File download failed.");
|
|
77
|
-
// (Optional) If you want to resize the image before upload:
|
|
78
|
-
// const resizedPath = await this.imageProcessorService.resizeImage(imageFilePath, 1024, 1024);
|
|
79
|
-
// Upload the `resizedPath` instead of `imageFilePath`
|
|
80
|
-
// 3) Upload image to S3
|
|
81
|
-
await this.s3Service.uploadImageToS3(process.env.S3_BUCKET, imageFilePath, s3ImagePath);
|
|
82
|
-
// 4) Construct a public URL (optionally going through Cloudflare)
|
|
83
|
-
if (process.env.CLOUDFLARE_IMAGE_PROXY_DOMAIN) {
|
|
84
|
-
newImageUrl = `https://${process.env.CLOUDFLARE_IMAGE_PROXY_DOMAIN}/${s3ImagePath}`;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
newImageUrl = `https://${process.env
|
|
88
|
-
.S3_BUCKET}.s3.amazonaws.com/${s3ImagePath}`;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// 5) Save record in DB
|
|
92
|
-
const formats = JSON.stringify([newImageUrl]);
|
|
93
|
-
const imageRecord = await Image.build({
|
|
94
|
-
user_id: workPackage.userId,
|
|
95
|
-
s3_bucket_name: process.env.S3_BUCKET,
|
|
96
|
-
original_filename: "n/a",
|
|
97
|
-
formats,
|
|
98
|
-
user_agent: "AI worker",
|
|
99
|
-
ip_address: "127.0.0.1",
|
|
100
|
-
});
|
|
101
|
-
await imageRecord.save();
|
|
102
|
-
resolve({ imageId: imageRecord.id, imageUrl: newImageUrl });
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
reject(error);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { AzureOpenAI, OpenAI } from "openai";
|
|
2
|
-
export class DalleImageGenerator {
|
|
3
|
-
constructor(azureOpenaAiBase, azureOpenAiApiKey, azureDalleDeployment, openAiKey) {
|
|
4
|
-
this.maxRetryCount = 3;
|
|
5
|
-
this.azureOpenaAiBase = azureOpenaAiBase;
|
|
6
|
-
this.azureOpenAiApiKey = azureOpenAiApiKey;
|
|
7
|
-
this.azureDalleDeployment = azureDalleDeployment;
|
|
8
|
-
this.openAiKey = openAiKey;
|
|
9
|
-
}
|
|
10
|
-
async generateImageUrl(prompt, type = "logo") {
|
|
11
|
-
let client;
|
|
12
|
-
let result;
|
|
13
|
-
let retryCount = 0;
|
|
14
|
-
let retrying = true;
|
|
15
|
-
// Decide which client to instantiate (Azure vs. standard OpenAI)
|
|
16
|
-
if (this.azureOpenaAiBase && this.azureOpenAiApiKey && this.azureDalleDeployment) {
|
|
17
|
-
client = new AzureOpenAI({
|
|
18
|
-
apiKey: this.azureOpenAiApiKey,
|
|
19
|
-
endpoint: this.azureOpenaAiBase,
|
|
20
|
-
deployment: this.azureDalleDeployment,
|
|
21
|
-
apiVersion: "2024-10-21",
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
// fallback to standard OpenAI
|
|
26
|
-
client = new OpenAI({
|
|
27
|
-
apiKey: this.openAiKey,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
// Decide on image dimensions
|
|
31
|
-
let size = "1792x1024";
|
|
32
|
-
if (type === "logo") {
|
|
33
|
-
size = "1792x1024";
|
|
34
|
-
}
|
|
35
|
-
else if (type === "icon") {
|
|
36
|
-
size = "1024x1024";
|
|
37
|
-
}
|
|
38
|
-
const modelQuality = "standard";
|
|
39
|
-
while (retrying && retryCount < this.maxRetryCount) {
|
|
40
|
-
try {
|
|
41
|
-
// If using Azure OpenAI
|
|
42
|
-
if (this.azureOpenaAiBase && this.azureOpenAiApiKey && this.azureDalleDeployment) {
|
|
43
|
-
result = await client.images.generate({
|
|
44
|
-
prompt,
|
|
45
|
-
n: 1,
|
|
46
|
-
size,
|
|
47
|
-
quality: modelQuality,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
// Standard OpenAI
|
|
52
|
-
result = await client.images.generate({
|
|
53
|
-
model: "dall-e-3",
|
|
54
|
-
prompt,
|
|
55
|
-
n: 1,
|
|
56
|
-
size,
|
|
57
|
-
quality: modelQuality,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (result) {
|
|
61
|
-
retrying = false;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
console.debug("Result: NONE");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
console.warn("Error generating image with DALL·E, retrying...");
|
|
69
|
-
console.warn(error.stack);
|
|
70
|
-
retryCount++;
|
|
71
|
-
const sleepingFor = 5000 + retryCount * 10000;
|
|
72
|
-
console.debug(`Sleeping for ${sleepingFor} milliseconds`);
|
|
73
|
-
await new Promise((resolve) => setTimeout(resolve, sleepingFor));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (result && result.data && result.data[0].url) {
|
|
77
|
-
return result.data[0].url;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
console.error(`Error generating image after ${retryCount} retries`);
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import Replicate from "replicate";
|
|
2
|
-
export class FluxImageGenerator {
|
|
3
|
-
constructor(replicateApiKey, fluxProModelName) {
|
|
4
|
-
this.replicateApiKey = replicateApiKey;
|
|
5
|
-
this.fluxProModelName = fluxProModelName;
|
|
6
|
-
this.maxRetryCount = 3;
|
|
7
|
-
this.replicate = new Replicate({ auth: replicateApiKey });
|
|
8
|
-
}
|
|
9
|
-
async generateImageUrl(prompt, type = "logo") {
|
|
10
|
-
let retryCount = 0;
|
|
11
|
-
let retrying = true;
|
|
12
|
-
let result;
|
|
13
|
-
// Configure the input to replicate’s model
|
|
14
|
-
const input = { prompt };
|
|
15
|
-
// Assign aspect ratio depending on type
|
|
16
|
-
if (type === "logo") {
|
|
17
|
-
input.aspect_ratio = "16:9";
|
|
18
|
-
}
|
|
19
|
-
else if (type === "icon") {
|
|
20
|
-
input.aspect_ratio = "1:1";
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
input.aspect_ratio = "16:9";
|
|
24
|
-
}
|
|
25
|
-
while (retrying && retryCount < this.maxRetryCount) {
|
|
26
|
-
try {
|
|
27
|
-
result = await this.replicate.run(this.fluxProModelName, {
|
|
28
|
-
input,
|
|
29
|
-
});
|
|
30
|
-
if (result) {
|
|
31
|
-
retrying = false;
|
|
32
|
-
return result; // typically a single URL
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
console.warn("Error generating image with Flux, retrying...");
|
|
37
|
-
console.warn(error.stack);
|
|
38
|
-
retryCount++;
|
|
39
|
-
const sleepingFor = 5000 + retryCount * 10000;
|
|
40
|
-
console.debug(`Sleeping for ${sleepingFor} milliseconds`);
|
|
41
|
-
await new Promise((resolve) => setTimeout(resolve, sleepingFor));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (!result) {
|
|
45
|
-
console.error(`Error generating image after ${retryCount} retries`);
|
|
46
|
-
}
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import sharp from "sharp";
|
|
4
|
-
import { v4 as uuidv4 } from "uuid";
|
|
5
|
-
export class ImageProcessorService {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.validFormats = ["jpeg", "png", "webp", "gif", "tiff", "avif", "svg"];
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Downloads an image from a given URL into the specified filepath.
|
|
11
|
-
*/
|
|
12
|
-
async downloadImage(imageUrl, imageFilePath, axiosInstance) {
|
|
13
|
-
const response = await axiosInstance({
|
|
14
|
-
method: "GET",
|
|
15
|
-
url: imageUrl,
|
|
16
|
-
responseType: "stream",
|
|
17
|
-
});
|
|
18
|
-
const writer = fs.createWriteStream(imageFilePath);
|
|
19
|
-
response.data.pipe(writer);
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
writer.on("finish", () => resolve());
|
|
22
|
-
writer.on("error", reject);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Resizes an image to given dimensions (width x height).
|
|
27
|
-
* If the image is smaller, it won't be enlarged.
|
|
28
|
-
*/
|
|
29
|
-
async resizeImage(imagePath, width, height) {
|
|
30
|
-
const resizedImageFilePath = path.join("/tmp", `${uuidv4()}.png`);
|
|
31
|
-
try {
|
|
32
|
-
// 1) Initialize Sharp instance
|
|
33
|
-
const image = sharp(imagePath).rotate(); // rotate fixes orientation from EXIF
|
|
34
|
-
// 2) Read metadata to validate format
|
|
35
|
-
const metadata = await image.metadata();
|
|
36
|
-
if (!metadata.format || !this.validFormats.includes(metadata.format)) {
|
|
37
|
-
throw new Error(`Unsupported format: ${metadata.format} (expected one of ${this.validFormats.join(", ")})`);
|
|
38
|
-
}
|
|
39
|
-
// 3) Resize + convert
|
|
40
|
-
await image
|
|
41
|
-
.resize({
|
|
42
|
-
width,
|
|
43
|
-
height,
|
|
44
|
-
fit: "inside",
|
|
45
|
-
withoutEnlargement: true,
|
|
46
|
-
})
|
|
47
|
-
.toFormat("png", {
|
|
48
|
-
quality: 90,
|
|
49
|
-
progressive: true,
|
|
50
|
-
})
|
|
51
|
-
.toFile(resizedImageFilePath);
|
|
52
|
-
// 4) Remove the original file
|
|
53
|
-
fs.unlinkSync(imagePath);
|
|
54
|
-
return resizedImageFilePath;
|
|
55
|
-
}
|
|
56
|
-
catch (err) {
|
|
57
|
-
console.error("Error resizing image:", err);
|
|
58
|
-
if (fs.existsSync(resizedImageFilePath)) {
|
|
59
|
-
fs.unlinkSync(resizedImageFilePath);
|
|
60
|
-
}
|
|
61
|
-
throw err;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { v4 as uuidv4 } from "uuid";
|
|
4
|
-
import { PredictionServiceClient } from "@google-cloud/aiplatform";
|
|
5
|
-
import { helpers } from "@google-cloud/aiplatform";
|
|
6
|
-
export class ImagenImageGenerator {
|
|
7
|
-
constructor(s3Service) {
|
|
8
|
-
this.s3Service = s3Service;
|
|
9
|
-
this.maxRetryCount = 3;
|
|
10
|
-
// Pull these from your environment or config
|
|
11
|
-
this.projectId = process.env.GOOGLE_CLOUD_PROJECT_ID || "";
|
|
12
|
-
this.location = process.env.GOOGLE_CLOUD_IMAGEN_LOCATION || "us-east1";
|
|
13
|
-
// Matches the official endpoint for Imagen v3.0:
|
|
14
|
-
this.endpoint = `projects/${this.projectId}/locations/${this.location}/publishers/google/models/imagen-3.0-generate-002`;
|
|
15
|
-
this.s3Bucket = process.env.S3_BUCKET || "";
|
|
16
|
-
if (!this.projectId) {
|
|
17
|
-
console.warn("Warning: GOOGLE_CLOUD_PROJECT_ID is not set. Vertex AI calls may fail.");
|
|
18
|
-
}
|
|
19
|
-
if (!this.s3Bucket) {
|
|
20
|
-
console.warn("Warning: S3_BUCKET is not set. Image upload may fail.");
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Generates an image from a text prompt using Vertex AI Imagen
|
|
25
|
-
* and returns a public S3 URL to the uploaded image.
|
|
26
|
-
*/
|
|
27
|
-
async generateImageUrl(prompt, type = "logo") {
|
|
28
|
-
let retryCount = 0;
|
|
29
|
-
let finalUrl;
|
|
30
|
-
// Configure the API endpoint for Vertex AI
|
|
31
|
-
const clientOptions = {
|
|
32
|
-
apiEndpoint: `${this.location}-aiplatform.googleapis.com`,
|
|
33
|
-
};
|
|
34
|
-
const predictionServiceClient = new PredictionServiceClient(clientOptions);
|
|
35
|
-
while (retryCount < this.maxRetryCount && !finalUrl) {
|
|
36
|
-
try {
|
|
37
|
-
// 1) Prepare the prompt and parameters for Imagen
|
|
38
|
-
const promptText = {
|
|
39
|
-
prompt: prompt, // The text prompt describing what you want to see
|
|
40
|
-
};
|
|
41
|
-
const instanceValue = helpers.toValue(promptText);
|
|
42
|
-
const instances = [instanceValue];
|
|
43
|
-
const parameter = {
|
|
44
|
-
sampleCount: 1,
|
|
45
|
-
// You can tweak these settings to your needs:
|
|
46
|
-
// seed: 100,
|
|
47
|
-
// addWatermark: false,
|
|
48
|
-
aspectRatio: "16:9",
|
|
49
|
-
safetyFilterLevel: "block_some",
|
|
50
|
-
personGeneration: "allow_adult",
|
|
51
|
-
};
|
|
52
|
-
const parameters = helpers.toValue(parameter);
|
|
53
|
-
// 2) Build the predict request
|
|
54
|
-
const request = {
|
|
55
|
-
endpoint: this.endpoint,
|
|
56
|
-
instances,
|
|
57
|
-
parameters,
|
|
58
|
-
};
|
|
59
|
-
// 3) Make the API call
|
|
60
|
-
//@ts-ignore
|
|
61
|
-
const [response] = await predictionServiceClient.predict(request);
|
|
62
|
-
const predictions = response.predictions;
|
|
63
|
-
if (!predictions || predictions.length === 0) {
|
|
64
|
-
console.warn("No image was generated. Check the request parameters and prompt.");
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
// 4) Extract base64 data from the first prediction
|
|
68
|
-
const prediction = predictions[0];
|
|
69
|
-
const b64Data = prediction.structValue?.fields?.bytesBase64Encoded?.stringValue;
|
|
70
|
-
if (!b64Data) {
|
|
71
|
-
throw new Error("Prediction did not contain base64 image data.");
|
|
72
|
-
}
|
|
73
|
-
// 5) Decode and write to a temporary file
|
|
74
|
-
const buff = Buffer.from(b64Data, "base64");
|
|
75
|
-
const tmpFilePath = path.join("/tmp", `${uuidv4()}.png`);
|
|
76
|
-
fs.writeFileSync(tmpFilePath, buff);
|
|
77
|
-
// 6) Upload the image to S3
|
|
78
|
-
const s3Key = `imagenAi/${uuidv4()}.png`;
|
|
79
|
-
await this.s3Service.uploadImageToS3(this.s3Bucket, tmpFilePath, s3Key);
|
|
80
|
-
// 7) Construct a public URL (optionally using Cloudflare)
|
|
81
|
-
if (process.env.CLOUDFLARE_IMAGE_PROXY_DOMAIN) {
|
|
82
|
-
finalUrl = `https://${process.env.CLOUDFLARE_IMAGE_PROXY_DOMAIN}/${s3Key}`;
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
finalUrl = `https://${this.s3Bucket}.s3.amazonaws.com/${s3Key}`;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
console.warn("Error generating image with Vertex AI Imagen. Will retry...");
|
|
91
|
-
console.warn(error?.message || error);
|
|
92
|
-
}
|
|
93
|
-
// Retry logic
|
|
94
|
-
if (!finalUrl) {
|
|
95
|
-
retryCount++;
|
|
96
|
-
const sleepingFor = 5000 + retryCount * 10000;
|
|
97
|
-
console.debug(`Sleeping for ${sleepingFor} ms before retry #${retryCount}...`);
|
|
98
|
-
await new Promise((resolve) => setTimeout(resolve, sleepingFor));
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (!finalUrl) {
|
|
102
|
-
console.error(`Failed to generate Imagen after ${retryCount} retries.`);
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
return finalUrl;
|
|
106
|
-
}
|
|
107
|
-
}
|