@yrpri/api 9.0.101 → 9.0.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +11 -1
- package/active-citizen/llms/baseChatBot.js +8 -75
- package/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
- package/active-citizen/llms/imageGeneration/collectionImageGenerator.js +6 -0
- package/agents/assistants/agentAssistant.js +3 -2
- package/agents/assistants/baseAssistant.js +7 -30
- package/agents/assistants/baseAssistantWithVoice.js +3 -3
- package/agents/assistants/voiceAssistant.js +2 -2
- package/agents/controllers/agentProductController.js +2 -1
- package/agents/controllers/agentSubscriptionController.js +20 -11
- package/agents/controllers/assistantsController.js +171 -127
- package/agents/controllers/policySynthAgents.js +33 -12
- package/agents/managers/newAiModelSetup.js +96 -0
- package/agents/managers/subscriptionManager.js +2 -2
- package/app.js +12 -12
- package/authorization.cjs +4 -0
- package/controllers/allOurIdeas.js +2 -1
- package/controllers/communities.cjs +47 -1
- package/controllers/groups.cjs +67 -4
- package/controllers/index.cjs +7 -7
- package/controllers/nonSpa.cjs +1 -1
- package/dist/active-citizen/controllers/activities.cjs +174 -0
- package/dist/active-citizen/controllers/news_feeds.cjs +96 -0
- package/dist/active-citizen/controllers/notifications.cjs +243 -0
- package/dist/active-citizen/controllers/recommendations.cjs +280 -0
- package/dist/active-citizen/engine/allOurIdeas/aiHelper.js +204 -0
- package/dist/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +66 -0
- package/dist/active-citizen/engine/allOurIdeas/iconGenerator.js +38 -0
- package/dist/active-citizen/engine/analytics/export_anon_community_activities.js +334 -0
- package/dist/active-citizen/engine/analytics/importer.js +308 -0
- package/dist/active-citizen/engine/analytics/manager.cjs +377 -0
- package/dist/active-citizen/engine/analytics/plausible/manager.cjs +500 -0
- package/dist/active-citizen/engine/analytics/statsCalc.cjs +194 -0
- package/dist/active-citizen/engine/analytics/utils.cjs +369 -0
- package/dist/active-citizen/engine/marketing/campaign.cjs +90 -0
- package/dist/active-citizen/engine/moderation/fraud/CreateFraudAuditReport.cjs +313 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudBase.cjs +239 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteBase.cjs +211 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteEndorsements.cjs +120 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePointQualities.cjs +114 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePoints.cjs +101 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePosts.cjs +84 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteRatings.cjs +15 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetBase.cjs +133 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetEndorsements.cjs +185 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPointQualities.cjs +184 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPoints.cjs +170 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPosts.cjs +109 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetRatings.cjs +140 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudScannerNotifier.cjs +279 -0
- package/dist/active-citizen/engine/moderation/get_moderation_items.cjs +386 -0
- package/dist/active-citizen/engine/moderation/image_labeling/CommunityLabeling.cjs +49 -0
- package/dist/active-citizen/engine/moderation/image_labeling/GroupLabeling.cjs +68 -0
- package/dist/active-citizen/engine/moderation/image_labeling/ImageLabelingBase.cjs +288 -0
- package/dist/active-citizen/engine/moderation/image_labeling/PointLabeling.cjs +33 -0
- package/dist/active-citizen/engine/moderation/image_labeling/PostLabeling.cjs +56 -0
- package/dist/active-citizen/engine/moderation/perspective_api_client.cjs +106 -0
- package/dist/active-citizen/engine/moderation/process_moderation_items.cjs +344 -0
- package/dist/active-citizen/engine/moderation/toxicity_analysis.cjs +810 -0
- package/dist/active-citizen/engine/news_feeds/activity_and_item_index_definitions.cjs +15 -0
- package/dist/active-citizen/engine/news_feeds/generate_dynamically.cjs +362 -0
- package/dist/active-citizen/engine/news_feeds/generate_from_notifications.cjs +268 -0
- package/dist/active-citizen/engine/news_feeds/news_feeds_utils.cjs +439 -0
- package/dist/active-citizen/engine/notifications/emails_utils.cjs +569 -0
- package/dist/active-citizen/engine/notifications/generate_point_notifications.cjs +233 -0
- package/dist/active-citizen/engine/notifications/generate_post_notifications.cjs +118 -0
- package/dist/active-citizen/engine/notifications/generate_post_status_change_notifications.cjs +41 -0
- package/dist/active-citizen/engine/notifications/notifications_utils.cjs +148 -0
- package/dist/active-citizen/engine/notifications/point_delivery.cjs +54 -0
- package/dist/active-citizen/engine/notifications/post_delivery.cjs +31 -0
- package/dist/active-citizen/engine/notifications/process_delayed_notifications.cjs +471 -0
- package/dist/active-citizen/engine/notifications/process_general_notifications.cjs +212 -0
- package/dist/active-citizen/engine/old/exporters/categories_dataset.js +153 -0
- package/dist/active-citizen/engine/old/exporters/dataset_tools.js +80 -0
- package/dist/active-citizen/engine/old/exporters/sentiment_dataset.js +157 -0
- package/dist/active-citizen/engine/recommendations/events_importer.cjs +139 -0
- package/dist/active-citizen/engine/recommendations/events_manager.cjs +212 -0
- package/dist/active-citizen/engine/reports/add_points_to_sheet.cjs +83 -0
- package/dist/active-citizen/engine/reports/commonUtils.js +75 -0
- package/dist/active-citizen/engine/reports/common_utils.cjs +740 -0
- package/dist/active-citizen/engine/reports/docx_group_report.cjs +596 -0
- package/dist/active-citizen/engine/reports/xlsAllOurIdeasExport.js +232 -0
- package/dist/active-citizen/engine/reports/xls_community_users_report.cjs +277 -0
- package/dist/active-citizen/engine/reports/xls_group_report.cjs +718 -0
- package/dist/active-citizen/llms/baseChatBot.js +183 -0
- package/dist/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
- package/dist/active-citizen/llms/imageGeneration/collectionImageGenerator.js +109 -0
- package/dist/active-citizen/llms/imageGeneration/dalleImageGenerator.js +84 -0
- package/dist/active-citizen/llms/imageGeneration/fluxImageGenerator.js +49 -0
- package/dist/active-citizen/llms/imageGeneration/imageProcessorService.js +64 -0
- package/dist/active-citizen/llms/imageGeneration/imagenImageGenerator.js +107 -0
- package/dist/active-citizen/llms/imageGeneration/s3Service.js +110 -0
- package/dist/active-citizen/llms/llmTranslation.js +472 -0
- package/dist/active-citizen/models/ac_activity.cjs +216 -0
- package/dist/active-citizen/models/ac_background_job.cjs +109 -0
- package/dist/active-citizen/models/ac_campaign.cjs +97 -0
- package/dist/active-citizen/models/ac_client_activity.cjs +23 -0
- package/dist/active-citizen/models/ac_delayed_notification.cjs +43 -0
- package/dist/active-citizen/models/ac_following.cjs +43 -0
- package/dist/active-citizen/models/ac_list.cjs +68 -0
- package/dist/active-citizen/models/ac_list_users.cjs +19 -0
- package/dist/active-citizen/models/ac_mute.cjs +27 -0
- package/dist/active-citizen/models/ac_news_feed_item.cjs +57 -0
- package/dist/active-citizen/models/ac_news_feed_processed_range.cjs +59 -0
- package/dist/active-citizen/models/ac_notification.cjs +292 -0
- package/dist/active-citizen/models/ac_translation_cache.cjs +750 -0
- package/dist/active-citizen/models/ac_watching.cjs +31 -0
- package/dist/active-citizen/scripts/analytics/setup_all_plausible_goals.cjs +13 -0
- package/dist/active-citizen/scripts/fix_old_delayed_notifications.js +63 -0
- package/dist/active-citizen/scripts/kue_status.js +31 -0
- package/dist/active-citizen/scripts/kue_watch_stuck_jobs.js +24 -0
- package/dist/active-citizen/scripts/translation_clear_language.js +117 -0
- package/dist/active-citizen/scripts/translation_delete.js +27 -0
- package/dist/active-citizen/scripts/translation_replace_text_from_url.js +180 -0
- package/dist/active-citizen/scripts/translation_update.js +28 -0
- package/dist/active-citizen/scripts/translations_list.js +27 -0
- package/{active-citizen/utils/airbrake.js → dist/active-citizen/utils/airbrake.cjs} +1 -1
- package/dist/active-citizen/utils/get_anonymous_system_user.cjs +21 -0
- package/dist/active-citizen/utils/i18n.cjs +3 -0
- package/dist/active-citizen/utils/logger.cjs +25 -0
- package/dist/active-citizen/utils/redisConnection.cjs +29 -0
- package/dist/active-citizen/utils/to_json.cjs +9 -0
- package/dist/active-citizen/utils/translation_cloning.cjs +171 -0
- package/dist/active-citizen/utils/translation_helpers.cjs +534 -0
- package/dist/active-citizen/utils/truncate_text.cjs +21 -0
- package/dist/active-citizen/utils/updateAllLocalesFromEn.js +253 -0
- package/dist/active-citizen/utils/updateLocaleFolders.js +34 -0
- package/dist/active-citizen/workers/activity.cjs +189 -0
- package/dist/active-citizen/workers/anonymizations.cjs +734 -0
- package/dist/active-citizen/workers/bulk_status_update.cjs +458 -0
- package/dist/active-citizen/workers/delayed_jobs.cjs +244 -0
- package/dist/active-citizen/workers/deletions.cjs +1911 -0
- package/dist/active-citizen/workers/email.cjs +9 -0
- package/dist/active-citizen/workers/fraud_management.cjs +109 -0
- package/dist/active-citizen/workers/generativeAi.js +56 -0
- package/dist/active-citizen/workers/main.cjs +89 -0
- package/dist/active-citizen/workers/marketing.cjs +25 -0
- package/dist/active-citizen/workers/moderation.cjs +73 -0
- package/dist/active-citizen/workers/notification_delivery.cjs +368 -0
- package/dist/active-citizen/workers/notification_news_feed.cjs +142 -0
- package/dist/active-citizen/workers/queue.cjs +99 -0
- package/dist/active-citizen/workers/recount.cjs +74 -0
- package/dist/active-citizen/workers/reports.cjs +42 -0
- package/dist/active-citizen/workers/similarities.cjs +21 -0
- package/dist/active-citizen/workers/speech_to_text.cjs +482 -0
- package/dist/agents/assistants/agentAssistant.js +88 -0
- package/dist/agents/assistants/baseAssistant.js +888 -0
- package/dist/agents/assistants/baseAssistantWithVoice.js +150 -0
- package/dist/agents/assistants/modes/agentDirectConnection.js +84 -0
- package/dist/agents/assistants/modes/agentSelectionMode.js +44 -0
- package/dist/agents/assistants/modes/baseAssistantMode.js +54 -0
- package/dist/agents/assistants/modes/tools/agentTools.js +447 -0
- package/dist/agents/assistants/modes/tools/baseTools.js +58 -0
- package/dist/agents/assistants/modes/tools/loginTools.js +156 -0
- package/dist/agents/assistants/modes/tools/models/agents.js +146 -0
- package/dist/agents/assistants/modes/tools/models/subscriptions.js +332 -0
- package/dist/agents/assistants/modes/tools/models/users.js +11 -0
- package/dist/agents/assistants/modes/tools/navigationTools.js +166 -0
- package/{agents/assistants/modes/tools/workflowConversationTools.js → dist/agents/assistants/modes/tools/subscriptionTools.js} +1 -4
- package/{agents/assistants/modes/tools/workflowTools.js → dist/agents/assistants/modes/tools/workflowConverstationTools.js} +1 -1
- package/dist/agents/assistants/voiceAssistant.js +619 -0
- package/dist/agents/controllers/agentProductController.js +103 -0
- package/dist/agents/controllers/agentSubscriptionController.js +261 -0
- package/dist/agents/controllers/assistantsController.js +511 -0
- package/dist/agents/controllers/policySynthAgents.js +395 -0
- package/{agents → dist/agents/managers}/agentProductManager.js +2 -2
- package/dist/agents/managers/emailInvitesManager.js +55 -0
- package/dist/agents/managers/emailTemplateRenderer.js +362 -0
- package/dist/agents/managers/newAiModelSetup.js +650 -0
- package/dist/agents/managers/notificationAgentQueueManager.js +510 -0
- package/dist/agents/managers/subscriptionManager.js +535 -0
- package/dist/agents/managers/workflowConversationManager.js +79 -0
- package/dist/agents/models/agentProduct.js +116 -0
- package/dist/agents/models/agentProductBoosterPurchase.js +58 -0
- package/dist/agents/models/agentProductBundle.js +68 -0
- package/dist/agents/models/agentProductRun.js +52 -0
- package/dist/agents/models/discount.js +88 -0
- package/dist/agents/models/subscription.js +79 -0
- package/dist/agents/models/subscriptionPlan.js +46 -0
- package/dist/agents/models/subscriptionUser.js +27 -0
- package/dist/agents/models/testData/createEvolyAgentProduct.js +477 -0
- package/dist/agents/models/testData/old/updateAgentWorkflowConfiguration.js +230 -0
- package/dist/agents/models/testData/setupEvolyAgentProductConfig.js +233 -0
- package/dist/agents/models/testData/updateAgentWorkflowConfiguration.js +230 -0
- package/{agents/models/workflowConverstation.js → dist/agents/models/workflowConversation.js} +1 -1
- package/{agents/tools/updateTemplateWorkflow.js → dist/agents/tools/setTemplateWorkflowCommunityId.js} +1 -0
- package/dist/app.js +943 -0
- package/dist/authorization.cjs +1860 -0
- package/dist/bot_control.js +1930 -0
- package/dist/config/config.cjs +14 -0
- package/dist/config/config.js +14 -0
- package/dist/controllers/allOurIdeas.js +696 -0
- package/dist/controllers/audios.cjs +100 -0
- package/dist/controllers/bulkStatusUpdates.cjs +202 -0
- package/dist/controllers/categories.cjs +199 -0
- package/dist/controllers/communities.cjs +2996 -0
- package/dist/controllers/domains.cjs +1341 -0
- package/dist/controllers/externalIds.cjs +223 -0
- package/dist/controllers/groups.cjs +4309 -0
- package/dist/controllers/images.cjs +499 -0
- package/dist/controllers/index.cjs +449 -0
- package/dist/controllers/legacyPages.cjs +35 -0
- package/dist/controllers/legacyPosts.cjs +56 -0
- package/dist/controllers/legacyUsers.cjs +36 -0
- package/dist/controllers/nonSpa.cjs +574 -0
- package/dist/controllers/organizations.cjs +250 -0
- package/dist/controllers/points.cjs +1137 -0
- package/dist/controllers/posts.cjs +2036 -0
- package/dist/controllers/ratings.cjs +234 -0
- package/dist/controllers/users.cjs +2255 -0
- package/dist/controllers/videos.cjs +226 -0
- package/dist/deleteUnwantedDeclerations.cjs +55 -0
- package/dist/migrations/agentAuditLogs.cjs +46 -0
- package/dist/migrations/agentClasses.cjs +60 -0
- package/dist/migrations/agentConnectorClasses.cjs +61 -0
- package/dist/migrations/agentConnectors.cjs +50 -0
- package/dist/migrations/agentEvals.cjs +45 -0
- package/dist/migrations/agentRegistries.cjs +40 -0
- package/dist/migrations/agents.cjs +54 -0
- package/dist/migrations/aiModels.cjs +49 -0
- package/dist/migrations/apiUsage.cjs +47 -0
- package/dist/migrations/apis.cjs +49 -0
- package/dist/migrations/groupPrivateData.cjs +30 -0
- package/dist/migrations/modelUsage.cjs +60 -0
- package/dist/migrations/oldMigrations/2019/20181030020612-AddActivitiesIndex.js +23 -0
- package/dist/migrations/oldMigrations/2019/20181102210612-AddFirstVideoFeatures.js +360 -0
- package/dist/migrations/oldMigrations/2019/20181212210612-ModerationFeatures.js +29 -0
- package/dist/migrations/oldMigrations/2019/2019010610612-CommunityFolders.js +43 -0
- package/dist/migrations/oldMigrations/2019/20190117020612-AddMissingIndexes.js +24 -0
- package/dist/migrations/oldMigrations/2019/20190117020612-RemoveUnusedIndexes.js +29 -0
- package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartThree.js +22 -0
- package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartTwo.js +23 -0
- package/{migrations/200824_create_embeddings_and_org_update.cjs → dist/migrations/oldMigrations/2019/20190223020612-AddPrivateProfileDataToUsers.js} +6 -3
- package/dist/migrations/oldMigrations/2019/20190706210612-AddCustomRatings.js +43 -0
- package/dist/migrations/oldMigrations/2019/20190829210612-AddGeneralStore.js +36 -0
- package/dist/migrations/oldMigrations/2019/20192811210612-AddAcClientActivities.js +41 -0
- package/dist/migrations/oldMigrations/2020/20190527020612-WorkOnIndexes.js +88 -0
- package/dist/migrations/oldMigrations/2020/20200409020612-AddBackgroundJob.js +33 -0
- package/dist/migrations/oldMigrations/2020/20200716210612-AddDataToCollections.js +38 -0
- package/dist/migrations/oldMigrations/2022/20220215100612-AddDataToEndorsements.js +19 -0
- package/dist/migrations/oldMigrations/2022/20220220100612-AddDataForFraudDetection.js +19 -0
- package/dist/migrations/oldMigrations/2022/20220903100612-AddPromotionFeatures.js +127 -0
- package/dist/migrations/oldMigrations/2022/onHold/20200527020612-AddCampaigns.js +68 -0
- package/dist/migrations/oldMigrations/2024/20241304175112-AddMediaSupportForHtmlGroups.cjs +63 -0
- package/dist/migrations/oldMigrations/older/20160511172514-AddNotificationFeatures.js +14 -0
- package/dist/migrations/oldMigrations/older/20161030020612-AddBulkStatusUpdate.js +71 -0
- package/dist/migrations/oldMigrations/older/20170514035258-add-metadata-to-invites.js +12 -0
- package/dist/migrations/oldMigrations/older/20180216020612-AddTranslationCaches.js +46 -0
- package/dist/migrations/oldMigrations/older/20180218210612-AddTranslationAndLanguages.js +46 -0
- package/dist/migrations/privateAccessStore.cjs +55 -0
- package/dist/migrations/zzz_associations.cjs +154 -0
- package/dist/migrations/zzzzz_create_agent_runs.cjs +606 -0
- package/dist/migrations/zzzzzz_create_agent_runs_fix.cjs +11 -0
- package/dist/migrations/zzzzzzz_create_trees.cjs +81 -0
- package/dist/models/audio.cjs +430 -0
- package/dist/models/bulk_status_update.cjs +58 -0
- package/dist/models/campaign.cjs +78 -0
- package/dist/models/category.cjs +94 -0
- package/dist/models/community.cjs +337 -0
- package/dist/models/domain.cjs +486 -0
- package/dist/models/endorsement.cjs +39 -0
- package/dist/models/general_data_store.cjs +20 -0
- package/dist/models/group.cjs +728 -0
- package/dist/models/image.cjs +579 -0
- package/dist/models/index.cjs +186 -0
- package/dist/models/invite.cjs +48 -0
- package/dist/models/iso_country.cjs +16 -0
- package/dist/models/organization.cjs +122 -0
- package/dist/models/page.cjs +273 -0
- package/dist/models/point.cjs +622 -0
- package/dist/models/point_quality.cjs +39 -0
- package/dist/models/point_revision.cjs +47 -0
- package/dist/models/post.cjs +680 -0
- package/dist/models/post_revision.cjs +38 -0
- package/dist/models/post_status_change.cjs +35 -0
- package/dist/models/promotion.cjs +34 -0
- package/dist/models/rating.cjs +51 -0
- package/dist/models/relationship.cjs +19 -0
- package/dist/models/request_to_join.cjs +20 -0
- package/dist/models/user.cjs +604 -0
- package/dist/models/user_legacy_password.cjs +13 -0
- package/dist/models/video.cjs +1137 -0
- package/dist/publish.js +40 -0
- package/dist/repack.js +53 -0
- package/dist/scripts/addRatingUsersToGroup.js +51 -0
- package/dist/scripts/addUserToOrganization.js +71 -0
- package/dist/scripts/analyseRatingsForCommunity.js +150 -0
- package/dist/scripts/analyzeAndFixBrokenPointUsers.js +28 -0
- package/dist/scripts/analyzeEndorsementsByCountry.js +70 -0
- package/dist/scripts/analyzePostsForCommunity.js +185 -0
- package/dist/scripts/bulkStatusUpdates/listUpdates.js +14 -0
- package/dist/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +110 -0
- package/dist/scripts/bulkStatusUpdates/performUpdate.js +116 -0
- package/{scripts/bulkStatusUpdates/performUpdateForGroup.js → dist/scripts/bulkStatusUpdates/performUpdateForGroup.cjs} +1 -2
- package/dist/scripts/bulkStatusUpdates/performUpdateForStatus.js +141 -0
- package/dist/scripts/change/changeVideoAspectTo.js +34 -0
- package/dist/scripts/change/setUseNewVersion.cjs +22 -0
- package/dist/scripts/changeCommunityGroupcount.js +30 -0
- package/dist/scripts/changeCommunityPostCount.js +30 -0
- package/dist/scripts/changeGroupPostCount.js +30 -0
- package/dist/scripts/changeLanguage.js +50 -0
- package/dist/scripts/changeOfficalStatus.js +30 -0
- package/{scripts/cleanups/deleteAnonNotifications.js → dist/scripts/cleanups/deleteAnonNotifications.cjs} +1 -1
- package/dist/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +62 -0
- package/dist/scripts/cleanups/deleteYearOldNotifications.cjs +72 -0
- package/dist/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +43 -0
- package/dist/scripts/clearAllEndorsementInGroup.js +50 -0
- package/dist/scripts/cloning/clearUsersForCommunitiesFromUrl.js +129 -0
- package/dist/scripts/cloning/cloneFromUrlScript.js +65 -0
- package/dist/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +140 -0
- package/dist/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +140 -0
- package/dist/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +131 -0
- package/dist/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +173 -0
- package/dist/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +18 -0
- package/dist/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +17 -0
- package/dist/scripts/cloning/copyCommunityToDomainWithEverything.js +17 -0
- package/dist/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +26 -0
- package/dist/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +205 -0
- package/dist/scripts/cloning/copyPostToGroupOld.js +397 -0
- package/dist/scripts/cloning/copyPostVideosFromURL.js +236 -0
- package/dist/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +17 -0
- package/dist/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +131 -0
- package/dist/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +139 -0
- package/dist/scripts/cloning/setAdminsFromURL.js +161 -0
- package/dist/scripts/cloning/setExternalIdsFromURL.js +129 -0
- package/dist/scripts/countCommunity.js +291 -0
- package/dist/scripts/countCommunityUsers.js +152 -0
- package/dist/scripts/countDelayedNotifications.js +18 -0
- package/dist/scripts/countGroup.js +246 -0
- package/dist/scripts/countStuff.js +67 -0
- package/dist/scripts/countUniqueVotersInAGroup.js +48 -0
- package/dist/scripts/createInvitesAndShow.js +75 -0
- package/dist/scripts/database/sync_database.js +14 -0
- package/dist/scripts/database/sync_dev_database.js +17 -0
- package/dist/scripts/debugNotifications.js +58 -0
- package/dist/scripts/deleteAllNewsFeeds.js +10 -0
- package/dist/scripts/deleteCategory.js +13 -0
- package/dist/scripts/deleteOldAppActivities.js +40 -0
- package/dist/scripts/deletePostContactDataForCommunity.js +53 -0
- package/dist/scripts/destroy/destroy_all_but_one_domain.js +1026 -0
- package/dist/scripts/displayAuthorForPost.js +16 -0
- package/dist/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +183 -0
- package/dist/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +208 -0
- package/dist/scripts/exportAllStatusChanges.js +36 -0
- package/dist/scripts/exportClientAcitivity.js +36 -0
- package/dist/scripts/exportEndorsementsForCommunity.js +79 -0
- package/dist/scripts/exportPointQualitiesForCommunity.js +84 -0
- package/dist/scripts/exportPostsAndPointsForCommunity.js +147 -0
- package/dist/scripts/exportPostsDataSetForDomain.js +244 -0
- package/dist/scripts/exportPostsForGroup.js +173 -0
- package/dist/scripts/exportRatingsForPost.js +15 -0
- package/dist/scripts/exportUserEndorsementsWithUserAnalysis.js +123 -0
- package/dist/scripts/exportUsersForCommunity.js +24 -0
- package/dist/scripts/exportUsersForDomain.js +24 -0
- package/dist/scripts/exportUsersForGroup.js +24 -0
- package/dist/scripts/exports/ratingDistribution.js +71 -0
- package/dist/scripts/exports/whoEndorsedWhatByCommunity.js +56 -0
- package/dist/scripts/findUnusedClientImports.js +56 -0
- package/dist/scripts/fixAllPostPointCounts.js +22 -0
- package/dist/scripts/fixAnonNotificationsSettings.js +48 -0
- package/dist/scripts/fixCountKopavogur.js +9 -0
- package/dist/scripts/fixEndorsementsAfterCopyPostToGroup.js +190 -0
- package/dist/scripts/fixExternalUserId.js +24 -0
- package/dist/scripts/fixGroupAccess.js +16 -0
- package/dist/scripts/fixGroupIdeasAndPointsCount.js +49 -0
- package/dist/scripts/fixNotificationSettings.js +39 -0
- package/dist/scripts/fixSurveyRadioBakedInSubCodes.js +64 -0
- package/dist/scripts/fixWrongUserIdForStatusUpdates.js +49 -0
- package/dist/scripts/gallery/exportGalleryData.js +40 -0
- package/dist/scripts/gallery/importGalleryForCommunity.js +168 -0
- package/dist/scripts/gallery/readJsonAndDownloadImagesVersion2.js +55 -0
- package/dist/scripts/gallery/refreshAcApiPostIdsForCommunity.js +58 -0
- package/dist/scripts/genderAnalysis.js +63 -0
- package/dist/scripts/genderAnalysisByStatus.js +62 -0
- package/dist/scripts/importAllLocalesFromLocalFolders.js +55 -0
- package/dist/scripts/importDomain.js +1652 -0
- package/dist/scripts/keys/addOidcToDomain.cjs +61 -0
- package/dist/scripts/landUseGame/export3Ddata.js +162 -0
- package/dist/scripts/listLanguagesForGroup.js +54 -0
- package/dist/scripts/loadTestCreateDummyContentForGroup.js +27 -0
- package/dist/scripts/makeRecursiveMapData.js +103 -0
- package/dist/scripts/mapping/community_map_csv.js +145 -0
- package/dist/scripts/moveCommunityToDomain.js +22 -0
- package/dist/scripts/moveGroupToCommunity.js +23 -0
- package/dist/scripts/movePostToGroup.js +101 -0
- package/dist/scripts/movePostsToGroupsRecountGroupFromUrl.js +297 -0
- package/dist/scripts/oldMovePostToGroup.js +153 -0
- package/dist/scripts/processCsvForPdfUrls.js +37 -0
- package/dist/scripts/processCsvForTranslationAndToxicity.js +125 -0
- package/dist/scripts/recount/recount_recursive_communities.js +125 -0
- package/dist/scripts/recountALLCommunityGroupCounts.js +37 -0
- package/dist/scripts/recountAll.js +97 -0
- package/dist/scripts/recountCommunitesFromUrl.js +58 -0
- package/dist/scripts/recountCommunity.js +19 -0
- package/dist/scripts/recountGroup.js +218 -0
- package/dist/scripts/recountGroupNoUserChange.js +219 -0
- package/dist/scripts/resetAllEndorsementsForGroup.js +57 -0
- package/dist/scripts/resetEnTranslationForGroup.js +45 -0
- package/dist/scripts/setAdminOnAll.cjs +107 -0
- package/{scripts/change → dist/scripts}/setDomainAdmin.cjs +0 -2
- package/dist/scripts/setDomainLocales.js +33 -0
- package/dist/scripts/setEarlQuestionIdOnGroup.cjs +29 -0
- package/dist/scripts/setLanguageOnGroupCommunitesFromUrl.js +86 -0
- package/dist/scripts/setMemberOfAll.js +101 -0
- package/dist/scripts/setNewUserForContentOfCommunity.js +189 -0
- package/dist/scripts/setOfficialStatusOnAllPostsForCommunity.js +35 -0
- package/dist/scripts/setUserOnAll.js +101 -0
- package/dist/scripts/showCategoryForGroup.js +18 -0
- package/dist/scripts/showOldActivityTypes.js +14 -0
- package/dist/scripts/showPostsMissingCategoryForGroup.js +17 -0
- package/dist/scripts/showStatuses.js +17 -0
- package/dist/scripts/showUniqueVotersInCommunity.js +61 -0
- package/dist/scripts/showUserAgentsAndIpsForEmails.js +66 -0
- package/dist/scripts/simpleExportForGroupsForCommunity.js +46 -0
- package/dist/scripts/simpleExportForPointsForCommunity.js +82 -0
- package/dist/scripts/simpleExportForPostsForCommunity.js +61 -0
- package/dist/scripts/testForEndorsments.js +21 -0
- package/dist/scripts/undeleteGroupAndAllContent.js +151 -0
- package/dist/scripts/undeletePost.js +135 -0
- package/dist/scripts/unlinkSsn.js +23 -0
- package/dist/scripts/updateFromAlthingi.js +303 -0
- package/dist/server.js +3 -0
- package/dist/utils/airbrake.cjs +17 -0
- package/dist/utils/cjsCodeReview.js +99 -0
- package/dist/utils/community_mapping_tools.cjs +124 -0
- package/dist/utils/copy_utils.cjs +1399 -0
- package/dist/utils/docx_utils.cjs +464 -0
- package/dist/utils/export_utils.cjs +491 -0
- package/dist/utils/i18n.cjs +17 -0
- package/dist/utils/is_valid_db_id.cjs +28 -0
- package/dist/utils/logger.cjs +25 -0
- package/dist/utils/loggerTs.js +26 -0
- package/dist/utils/manifest_generator.cjs +104 -0
- package/dist/utils/parse_domain.cjs +16 -0
- package/dist/utils/recount_utils.cjs +415 -0
- package/dist/utils/sharing_parameters.cjs +111 -0
- package/dist/utils/sitemap_generator.cjs +286 -0
- package/dist/utils/to_json.cjs +14 -0
- package/dist/utils/ypLanguages.js +747 -0
- package/dist/webSockets.js +77 -0
- package/package.json +46 -44
- package/server.d.ts +104 -2
- package/utils/copy_utils.cjs +7 -1
- package/active-citizen/engine/allOurIdeas/aiHelper.d.ts +0 -21
- package/active-citizen/engine/allOurIdeas/aiHelper.d.ts.map +0 -1
- package/active-citizen/engine/allOurIdeas/explainAnswersAssistant.d.ts.map +0 -1
- package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts +0 -12
- package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts.map +0 -1
- package/active-citizen/engine/analytics/export_anon_community_activities.d.ts.map +0 -1
- package/active-citizen/engine/analytics/importer.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/categories_dataset.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/dataset_tools.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/sentiment_dataset.d.ts.map +0 -1
- package/active-citizen/engine/reports/xls_all_our_ideas_export.js +0 -141
- package/active-citizen/llms/baseChatBot.d.ts +0 -51
- package/active-citizen/llms/baseChatBot.d.ts.map +0 -1
- package/active-citizen/llms/collectionImageGenerator.js +0 -357
- package/active-citizen/llms/llmTranslation.d.ts +0 -24
- package/active-citizen/llms/llmTranslation.d.ts.map +0 -1
- package/active-citizen/scripts/fix_old_delayed_notifications.d.ts.map +0 -1
- package/active-citizen/scripts/kue_status.d.ts.map +0 -1
- package/active-citizen/scripts/kue_watch_stuck_jobs.d.ts.map +0 -1
- package/active-citizen/scripts/translation_clear_language.d.ts.map +0 -1
- package/active-citizen/scripts/translation_delete.d.ts.map +0 -1
- package/active-citizen/scripts/translation_replace_text_from_url.d.ts.map +0 -1
- package/active-citizen/scripts/translation_update.d.ts.map +0 -1
- package/active-citizen/scripts/translations_list.d.ts.map +0 -1
- package/active-citizen/utils/airbrake.d.ts.map +0 -1
- package/active-citizen/utils/updateAllLocalesFromEn.d.ts +0 -21
- package/active-citizen/utils/updateAllLocalesFromEn.d.ts.map +0 -1
- package/active-citizen/utils/updateLocaleFolders.d.ts +0 -2
- package/active-citizen/utils/updateLocaleFolders.d.ts.map +0 -1
- package/active-citizen/workers/cloudflare/voiceSession/worker.js +0 -213
- package/active-citizen/workers/generativeAi.d.ts.map +0 -1
- package/agents/assistants/agentAssistantOld.js +0 -863
- package/agents/assistants/modes/agentConfigurationMode.js +0 -63
- package/agents/assistants/modes/agentOperationsMode.js +0 -195
- package/agents/assistants/modes/commonTools.js +0 -58
- package/agents/assistants/modes/directConversationMode.js +0 -14
- package/agents/assistants/modes/toolHandlers/accountHandlers.js +0 -46
- package/agents/assistants/modes/toolHandlers/commonHandlers.js +0 -57
- package/agents/assistants/modes/toolHandlers/commonTools.js +0 -58
- package/agents/assistants/modes/toolHandlers/loginHandlers.js +0 -46
- package/agents/assistants/modes/toolHandlers/subscriptionHandlers.js +0 -469
- package/agents/assistants/modes/tools/agentConnectionTools.js +0 -326
- package/agents/assistants/modes/tools/commonHandlers.js +0 -57
- package/agents/assistants/modes/tools/loginHandlers.js +0 -46
- package/agents/assistants/modes/tools/subscriptionHandlers.js +0 -469
- package/agents/controllers/assistantController.js +0 -243
- package/agents/managers/workflowManager.js +0 -76
- package/agents/models/testData/setupConfig.js +0 -140
- package/agents/models/workflow.js +0 -53
- package/agents/subscriptionManager.js +0 -218
- package/app.d.ts +0 -40
- package/app.d.ts.map +0 -1
- package/bot_control.d.ts.map +0 -1
- package/publish.d.ts.map +0 -1
- package/repack.d.ts.map +0 -1
- package/scripts/addRatingUsersToGroup.d.ts.map +0 -1
- package/scripts/addUserToOrganization.d.ts.map +0 -1
- package/scripts/analyseRatingsForCommunity.d.ts.map +0 -1
- package/scripts/analyzeAndFixBrokenPointUsers.d.ts.map +0 -1
- package/scripts/analyzeEndorsementsByCountry.d.ts.map +0 -1
- package/scripts/analyzePostsForCommunity.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/listUpdates.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdate.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdateForGroup.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdateForStatus.d.ts.map +0 -1
- package/scripts/change/changeVideoAspectTo.d.ts.map +0 -1
- package/scripts/changeCommunityGroupcount.d.ts.map +0 -1
- package/scripts/changeCommunityPostCount.d.ts.map +0 -1
- package/scripts/changeGroupPostCount.d.ts.map +0 -1
- package/scripts/changeLanguage.d.ts.map +0 -1
- package/scripts/changeOfficalStatus.d.ts.map +0 -1
- package/scripts/cleanups/deleteAnonNotifications.d.ts.map +0 -1
- package/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.d.ts.map +0 -1
- package/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.d.ts.map +0 -1
- package/scripts/clearAllEndorsementInGroup.d.ts.map +0 -1
- package/scripts/cloning/clearUsersForCommunitiesFromUrl.d.ts.map +0 -1
- package/scripts/cloning/cloneFromUrlScript.d.ts.map +0 -1
- package/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.d.ts.map +0 -1
- package/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainWithEverything.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainWithOnlyGroups.d.ts.map +0 -1
- package/scripts/cloning/copyGroupConfigAndTranslationsFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyPostToGroupOld.d.ts.map +0 -1
- package/scripts/cloning/copyPostVideosFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyPostWithOutAnyVotingOrActivities.d.ts.map +0 -1
- package/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/setAdminsFromURL.d.ts.map +0 -1
- package/scripts/cloning/setExternalIdsFromURL.d.ts.map +0 -1
- package/scripts/countCommunity.d.ts.map +0 -1
- package/scripts/countCommunityUsers.d.ts.map +0 -1
- package/scripts/countDelayedNotifications.d.ts.map +0 -1
- package/scripts/countGroup.d.ts.map +0 -1
- package/scripts/countStuff.d.ts.map +0 -1
- package/scripts/countUniqueVotersInAGroup.d.ts.map +0 -1
- package/scripts/createInvitesAndShow.d.ts.map +0 -1
- package/scripts/database/seedTestAiModels.js +0 -64
- package/scripts/database/sync_database.d.ts.map +0 -1
- package/scripts/database/sync_dev_database.d.ts.map +0 -1
- package/scripts/debugNotifications.d.ts.map +0 -1
- package/scripts/deleteAllNewsFeeds.d.ts.map +0 -1
- package/scripts/deleteCategory.d.ts.map +0 -1
- package/scripts/deleteOldAppActivities.d.ts.map +0 -1
- package/scripts/deletePostContactDataForCommunity.d.ts.map +0 -1
- package/scripts/destroy/destroy_all_but_one_domain.d.ts.map +0 -1
- package/scripts/displayAuthorForPost.d.ts.map +0 -1
- package/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.d.ts.map +0 -1
- package/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.d.ts.map +0 -1
- package/scripts/exportAllStatusChanges.d.ts.map +0 -1
- package/scripts/exportClientAcitivity.d.ts.map +0 -1
- package/scripts/exportEndorsementsForCommunity.d.ts.map +0 -1
- package/scripts/exportPointQualitiesForCommunity.d.ts.map +0 -1
- package/scripts/exportPostsAndPointsForCommunity.d.ts.map +0 -1
- package/scripts/exportPostsDataSetForDomain.d.ts.map +0 -1
- package/scripts/exportPostsForGroup.d.ts.map +0 -1
- package/scripts/exportRatingsForPost.d.ts.map +0 -1
- package/scripts/exportUserEndorsementsWithUserAnalysis.d.ts.map +0 -1
- package/scripts/exportUsersForCommunity.d.ts.map +0 -1
- package/scripts/exportUsersForDomain.d.ts.map +0 -1
- package/scripts/exportUsersForGroup.d.ts.map +0 -1
- package/scripts/exports/ratingDistribution.d.ts.map +0 -1
- package/scripts/exports/whoEndorsedWhatByCommunity.d.ts.map +0 -1
- package/scripts/findUnusedClientImports.d.ts.map +0 -1
- package/scripts/fixAllPostPointCounts.d.ts.map +0 -1
- package/scripts/fixAnonNotificationsSettings.d.ts.map +0 -1
- package/scripts/fixCountKopavogur.d.ts.map +0 -1
- package/scripts/fixEndorsementsAfterCopyPostToGroup.d.ts.map +0 -1
- package/scripts/fixExternalUserId.d.ts.map +0 -1
- package/scripts/fixGroupAccess.d.ts.map +0 -1
- package/scripts/fixGroupIdeasAndPointsCount.d.ts.map +0 -1
- package/scripts/fixNotificationSettings.d.ts.map +0 -1
- package/scripts/fixSurveyRadioBakedInSubCodes.d.ts.map +0 -1
- package/scripts/fixWrongUserIdForStatusUpdates.d.ts.map +0 -1
- package/scripts/gallery/exportGalleryData.d.ts.map +0 -1
- package/scripts/gallery/importGalleryForCommunity.d.ts.map +0 -1
- package/scripts/gallery/readJsonAndDownloadImagesVersion2.d.ts.map +0 -1
- package/scripts/gallery/refreshAcApiPostIdsForCommunity.d.ts.map +0 -1
- package/scripts/genderAnalysis.d.ts.map +0 -1
- package/scripts/genderAnalysisByStatus.d.ts.map +0 -1
- package/scripts/importAllLocalesFromLocalFolders.d.ts.map +0 -1
- package/scripts/importDomain.d.ts.map +0 -1
- package/scripts/landUseGame/export3Ddata.d.ts.map +0 -1
- package/scripts/listLanguagesForGroup.d.ts.map +0 -1
- package/scripts/loadTestCreateDummyContentForGroup.d.ts.map +0 -1
- package/scripts/makeRecursiveMapData.d.ts.map +0 -1
- package/scripts/mapping/community_map_csv.d.ts.map +0 -1
- package/scripts/moveCommunityToDomain.d.ts.map +0 -1
- package/scripts/moveGroupToCommunity.d.ts.map +0 -1
- package/scripts/movePostToGroup.d.ts.map +0 -1
- package/scripts/movePostsToGroupsRecountGroupFromUrl.d.ts.map +0 -1
- package/scripts/oldMovePostToGroup.d.ts.map +0 -1
- package/scripts/processCsvForPdfUrls.d.ts.map +0 -1
- package/scripts/processCsvForTranslationAndToxicity.d.ts.map +0 -1
- package/scripts/recount/recount_recursive_communities.d.ts.map +0 -1
- package/scripts/recountALLCommunityGroupCounts.d.ts.map +0 -1
- package/scripts/recountAll.d.ts.map +0 -1
- package/scripts/recountCommunitesFromUrl.d.ts.map +0 -1
- package/scripts/recountCommunity.d.ts.map +0 -1
- package/scripts/recountGroup.d.ts.map +0 -1
- package/scripts/recountGroupNoUserChange.d.ts.map +0 -1
- package/scripts/resetAllEndorsementsForGroup.d.ts.map +0 -1
- package/scripts/resetEnTranslationForGroup.d.ts.map +0 -1
- package/scripts/setDomainLocales.d.ts.map +0 -1
- package/scripts/setLanguageOnGroupCommunitesFromUrl.d.ts.map +0 -1
- package/scripts/setMemberOfAll.d.ts.map +0 -1
- package/scripts/setNewUserForContentOfCommunity.d.ts.map +0 -1
- package/scripts/setOfficialStatusOnAllPostsForCommunity.d.ts.map +0 -1
- package/scripts/setUserOnAll.d.ts.map +0 -1
- package/scripts/showCategoryForGroup.d.ts.map +0 -1
- package/scripts/showOldActivityTypes.d.ts.map +0 -1
- package/scripts/showPostsMissingCategoryForGroup.d.ts.map +0 -1
- package/scripts/showStatuses.d.ts.map +0 -1
- package/scripts/showUniqueVotersInCommunity.d.ts.map +0 -1
- package/scripts/showUserAgentsAndIpsForEmails.d.ts.map +0 -1
- package/scripts/simpleExportForGroupsForCommunity.d.ts.map +0 -1
- package/scripts/simpleExportForPointsForCommunity.d.ts.map +0 -1
- package/scripts/simpleExportForPostsForCommunity.d.ts.map +0 -1
- package/scripts/testForEndorsments.d.ts.map +0 -1
- package/scripts/undeleteGroupAndAllContent.d.ts.map +0 -1
- package/scripts/undeletePost.d.ts.map +0 -1
- package/scripts/unlinkSsn.d.ts.map +0 -1
- package/scripts/updateFromAlthingi.d.ts.map +0 -1
- package/server.d.ts.map +0 -1
- package/utils/copyGroup.js +0 -246
- package/utils/loggerTs.d.ts +0 -4
- package/utils/loggerTs.d.ts.map +0 -1
- package/utils/ypLanguages.d.ts +0 -18
- package/utils/ypLanguages.d.ts.map +0 -1
- /package/{agents/tools/updateCommunityWorkflow.js → dist/active-citizen/llms/imageGeneration/iImageGenerator.js} +0 -0
- /package/{migrations/270724_createUsersAndAdminsForClasses.cjs → dist/migrations/zzzz_createUsersAndAdminsForClasses.cjs} +0 -0
|
@@ -0,0 +1,183 @@
|
|
|
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";
|
|
@@ -0,0 +1,56 @@
|
|
|
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;
|
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
}
|