@yrpri/api 9.0.139 → 9.0.140
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/agents/assistants/agentAssistant.js +4 -3
- package/agents/assistants/baseAssistant.js +72 -71
- package/agents/assistants/baseAssistantWithVoice.js +6 -5
- package/agents/assistants/modes/agentDirectConnection.js +8 -7
- package/agents/assistants/modes/agentSelectionMode.js +2 -1
- package/agents/assistants/modes/baseAssistantMode.js +3 -2
- package/agents/assistants/modes/tools/agentTools.js +11 -10
- package/agents/assistants/modes/tools/loginTools.js +7 -6
- package/agents/assistants/modes/tools/models/agents.js +6 -5
- package/agents/assistants/modes/tools/models/subscriptions.js +7 -6
- package/agents/assistants/modes/tools/navigationTools.js +7 -6
- package/agents/assistants/modes/tools/subscriptionTools.js +12 -11
- package/agents/assistants/modes/tools/workflowConverstationTools.js +7 -6
- package/agents/assistants/voiceAssistant.js +45 -44
- package/agents/controllers/agentProductController.js +8 -7
- package/agents/controllers/agentSubscriptionController.js +13 -12
- package/agents/controllers/assistantsController.js +45 -44
- package/agents/controllers/policySynthAgents.js +33 -32
- package/agents/managers/emailInvitesManager.js +4 -3
- package/agents/managers/newAiModelSetup.js +45 -44
- package/agents/managers/notificationAgentQueueManager.js +55 -54
- package/agents/managers/subscriptionManager.js +24 -23
- package/agents/models/agentProduct.js +2 -1
- package/agents/models/agentProductBoosterPurchase.js +2 -1
- package/agents/models/testData/createEvolyAgentProduct.js +7 -6
- package/agents/models/testData/old/updateAgentWorkflowConfiguration.js +5 -4
- package/agents/models/testData/updateAgentWorkflowConfiguration.js +5 -4
- package/agents/tools/setTemplateWorkflowCommunityId.js +6 -5
- package/app.d.ts +2 -1
- package/app.js +60 -34
- package/authorization.cjs +4 -4
- package/controllers/allOurIdeas.js +45 -44
- package/controllers/groups.cjs +4 -9
- package/controllers/images.cjs +8 -8
- package/controllers/index.cjs +1 -1
- package/controllers/points.cjs +1 -1
- package/controllers/posts.cjs +3 -3
- package/deleteUnwantedDeclerations.cjs +5 -5
- package/models/community.cjs +1 -1
- package/models/domain.cjs +7 -7
- package/models/image.cjs +2 -2
- package/models/index.cjs +8 -4
- package/models/post.cjs +10 -10
- package/models/user.cjs +1 -1
- package/models/video.cjs +4 -4
- package/package.json +5 -5
- package/scripts/addRatingUsersToGroup.js +1 -1
- package/scripts/addUserToOrganization.js +8 -8
- package/scripts/agents/changeModelForWorkflowGroupTemplate.js +13 -12
- package/scripts/agents/generateAgentWorkflowTemplateFromAgentClass.js +5 -4
- package/scripts/analyseRatingsForCommunity.js +2 -2
- package/scripts/analyzeAndFixBrokenPointUsers.js +3 -3
- package/scripts/analyzeEndorsementsByCountry.js +7 -7
- package/scripts/analyzePostsForCommunity.js +1 -1
- package/scripts/bulkStatusUpdates/listUpdates.js +2 -2
- package/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +5 -5
- package/scripts/bulkStatusUpdates/performUpdate.js +9 -9
- package/scripts/bulkStatusUpdates/performUpdateForGroup.cjs +11 -11
- package/scripts/bulkStatusUpdates/performUpdateForStatus.js +15 -15
- package/scripts/change/changeVideoAspectTo.js +3 -3
- package/scripts/change/setUseNewVersion.cjs +4 -4
- package/scripts/changeCommunityGroupcount.js +3 -3
- package/scripts/changeCommunityPostCount.js +3 -3
- package/scripts/changeGroupPostCount.js +3 -3
- package/scripts/changeLanguage.js +4 -4
- package/scripts/changeOfficalStatus.js +3 -3
- package/scripts/cleanups/deleteAnonNotifications.cjs +7 -7
- package/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +8 -8
- package/scripts/cleanups/deleteYearOldNotifications.cjs +5 -5
- package/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +5 -5
- package/scripts/clearAllEndorsementInGroup.js +5 -5
- package/scripts/cloning/clearUsersForCommunitiesFromUrl.js +3 -3
- package/scripts/cloning/cloneFromUrlScript.js +4 -4
- package/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +6 -6
- package/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +6 -6
- package/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +6 -6
- package/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +3 -3
- package/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +2 -2
- package/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +2 -2
- package/scripts/cloning/copyCommunityToDomainWithEverything.js +2 -2
- package/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +3 -3
- package/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +3 -3
- package/scripts/cloning/copyPostToGroupOld.js +12 -12
- package/scripts/cloning/copyPostVideosFromURL.js +3 -3
- package/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +2 -2
- package/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +7 -7
- package/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +6 -6
- package/scripts/cloning/setAdminsFromURL.js +5 -5
- package/scripts/cloning/setExternalIdsFromURL.js +3 -3
- package/scripts/countCommunity.js +11 -11
- package/scripts/countCommunityUsers.js +4 -4
- package/scripts/countDelayedNotifications.js +3 -3
- package/scripts/countGroup.js +11 -11
- package/scripts/countStuff.js +3 -3
- package/scripts/countUniqueVotersInAGroup.js +3 -3
- package/scripts/createInvitesAndShow.js +2 -2
- package/scripts/database/sync_database.js +2 -2
- package/scripts/database/sync_dev_database.js +3 -3
- package/scripts/debugNotifications.js +5 -5
- package/scripts/deleteAllNewsFeeds.js +2 -2
- package/scripts/deleteCategory.js +1 -1
- package/scripts/deleteOldAppActivities.js +5 -4
- package/scripts/deletePostContactDataForCommunity.js +5 -4
- package/scripts/destroy/destroy_all_but_one_domain.js +59 -59
- package/scripts/displayAuthorForPost.js +1 -1
- package/scripts/domains/createDomain.js +5 -4
- package/scripts/domains/importDomainsFromXls.js +7 -6
- package/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +2 -2
- package/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +9 -9
- package/scripts/exportAllStatusChanges.js +5 -5
- package/scripts/exportEndorsementsForCommunity.js +5 -5
- package/scripts/exportPointQualitiesForCommunity.js +5 -5
- package/scripts/exportPostsAndPointsForCommunity.js +9 -9
- package/scripts/exportPostsDataSetForDomain.js +12 -12
- package/scripts/exportPostsForGroup.js +7 -7
- package/scripts/exportRatingsForPost.js +2 -2
- package/scripts/exportUserEndorsementsWithUserAnalysis.js +6 -6
- package/scripts/exportUsersForCommunity.js +3 -3
- package/scripts/exportUsersForDomain.js +3 -3
- package/scripts/exportUsersForGroup.js +3 -3
- package/scripts/exports/ratingDistribution.js +6 -6
- package/scripts/exports/whoEndorsedWhatByCommunity.js +2 -2
- package/scripts/findUnusedClientImports.js +2 -2
- package/scripts/fixAllPostPointCounts.js +1 -1
- package/scripts/fixAnonNotificationsSettings.js +5 -5
- package/scripts/fixCountKopavogur.js +1 -1
- package/scripts/fixEndorsementsAfterCopyPostToGroup.js +10 -10
- package/scripts/fixExternalUserId.js +2 -2
- package/scripts/fixGroupAccess.js +3 -3
- package/scripts/fixGroupIdeasAndPointsCount.js +2 -2
- package/scripts/fixNotificationSettings.js +4 -4
- package/scripts/fixSurveyRadioBakedInSubCodes.js +6 -6
- package/scripts/fixWrongUserIdForStatusUpdates.js +6 -5
- package/scripts/gallery/exportGalleryData.js +2 -2
- package/scripts/gallery/importGalleryForCommunity.js +14 -14
- package/scripts/gallery/readJsonAndDownloadImagesVersion2.js +6 -6
- package/scripts/gallery/refreshAcApiPostIdsForCommunity.js +5 -5
- package/scripts/genderAnalysis.js +10 -10
- package/scripts/genderAnalysisByStatus.js +4 -4
- package/scripts/importAllLocalesFromLocalFolders.js +7 -7
- package/scripts/importDomain.js +131 -131
- package/scripts/keys/addOidcToDomain.cjs +9 -9
- package/scripts/landUseGame/export3Ddata.js +15 -15
- package/scripts/listLanguagesForGroup.js +6 -6
- package/scripts/loadTestCreateDummyContentForGroup.js +2 -2
- package/scripts/makeRecursiveMapData.js +4 -4
- package/scripts/mapping/community_map_csv.js +5 -5
- package/scripts/moveCommunityToDomain.js +3 -3
- package/scripts/moveGroupToCommunity.js +3 -3
- package/scripts/movePostToGroup.js +5 -5
- package/scripts/movePostsToGroupsRecountGroupFromUrl.js +6 -6
- package/scripts/oldMovePostToGroup.js +9 -9
- package/scripts/processCsvForPdfUrls.js +2 -2
- package/scripts/processCsvForTranslationAndToxicity.js +10 -10
- package/scripts/recount/recount_recursive_communities.js +6 -6
- package/scripts/recountALLCommunityGroupCounts.js +4 -4
- package/scripts/recountAll.js +3 -3
- package/scripts/recountCommunitesFromUrl.js +3 -3
- package/scripts/recountCommunity.js +2 -2
- package/scripts/recountGroup.js +5 -5
- package/scripts/recountGroupNoUserChange.js +5 -5
- package/scripts/resetAllEndorsementsForGroup.js +3 -3
- package/scripts/resetEnTranslationForGroup.js +5 -5
- package/scripts/setAdminOnAll.cjs +14 -14
- package/scripts/setDomainAdmin.cjs +6 -6
- package/scripts/setDomainLocales.js +2 -2
- package/scripts/setEarlQuestionIdOnGroup.cjs +4 -4
- package/scripts/setLanguageOnGroupCommunitesFromUrl.js +3 -3
- package/scripts/setMemberOfAll.js +14 -14
- package/scripts/setNewUserForContentOfCommunity.js +9 -9
- package/scripts/setOfficialStatusOnAllPostsForCommunity.js +1 -1
- package/scripts/setUserOnAll.js +14 -14
- package/scripts/showCategoryForGroup.js +1 -1
- package/scripts/showOldActivityTypes.js +3 -3
- package/scripts/showPostsMissingCategoryForGroup.js +2 -2
- package/scripts/showStatuses.js +4 -4
- package/scripts/showUniqueVotersInCommunity.js +4 -4
- package/scripts/showUserAgentsAndIpsForEmails.js +4 -4
- package/scripts/simpleExportForGroupsForCommunity.js +5 -5
- package/scripts/simpleExportForPointsForCommunity.js +5 -5
- package/scripts/simpleExportForPostsForCommunity.js +5 -5
- package/scripts/testForEndorsments.js +4 -4
- package/scripts/undeleteGroupAndAllContent.js +8 -8
- package/scripts/undeletePost.js +7 -7
- package/scripts/unlinkSsn.js +4 -4
- package/scripts/updateFromAlthingi.js +8 -8
- package/scripts/users/createUserAddDomain.js +6 -5
- package/scripts/users/importUsersForDomainsFromXls.js +4 -3
- package/scripts/users/listDomainUsersWithSsn.js +6 -5
- package/scripts/users/removeUserFromDomain.js +6 -5
- package/scripts/users/updatePasswordFromSsn.js +5 -4
- package/scripts/users/updateUserSsnFromEmail.js +5 -4
- package/services/controllers/activities.cjs +1 -1
- package/services/controllers/news_feeds.cjs +1 -1
- package/services/controllers/notifications.cjs +1 -1
- package/services/controllers/recommendations.cjs +1 -1
- package/services/engine/allOurIdeas/aiHelper.js +10 -9
- package/services/engine/analytics/export_anon_community_activities.js +3 -3
- package/services/engine/analytics/importer.js +10 -10
- package/services/engine/analytics/plausible/manager.cjs +4 -4
- package/services/engine/analytics/statsCalc.cjs +1 -1
- package/services/engine/analytics/utils.cjs +10 -10
- package/services/engine/moderation/fraud/CreateFraudAuditReport.cjs +2 -1
- package/services/engine/moderation/fraud/FraudBase.cjs +2 -2
- package/services/engine/moderation/fraud/FraudDeleteBase.cjs +4 -4
- package/services/engine/moderation/fraud/FraudGetBase.cjs +1 -1
- package/services/engine/moderation/fraud/FraudGetEndorsements.cjs +1 -1
- package/services/engine/moderation/fraud/FraudGetPointQualities.cjs +1 -1
- package/services/engine/moderation/fraud/FraudGetPoints.cjs +1 -1
- package/services/engine/moderation/fraud/FraudGetPosts.cjs +1 -1
- package/services/engine/moderation/fraud/FraudGetRatings.cjs +1 -1
- package/services/engine/moderation/fraud/FraudScannerNotifier.cjs +9 -9
- package/services/engine/moderation/get_moderation_items.cjs +1 -1
- package/services/engine/moderation/image_labeling/ImageLabelingBase.cjs +1 -1
- package/services/engine/moderation/process_moderation_items.cjs +1 -1
- package/services/engine/moderation/toxicity_analysis.cjs +1 -1
- package/services/engine/news_feeds/generate_dynamically.cjs +1 -1
- package/services/engine/news_feeds/generate_from_notifications.cjs +1 -1
- package/services/engine/notifications/emails_utils.cjs +2 -2
- package/services/engine/notifications/generate_point_notifications.cjs +1 -1
- package/services/engine/notifications/generate_post_notifications.cjs +1 -1
- package/services/engine/notifications/process_delayed_notifications.cjs +38 -38
- package/services/engine/old/exporters/categories_dataset.js +11 -11
- package/services/engine/old/exporters/sentiment_dataset.js +12 -12
- package/services/engine/recommendations/events_importer.cjs +5 -5
- package/services/engine/recommendations/events_manager.cjs +1 -1
- package/services/engine/reports/add_points_to_sheet.cjs +2 -2
- package/services/engine/reports/commonUtils.js +3 -2
- package/services/engine/reports/common_utils.cjs +8 -8
- package/services/engine/reports/docx_group_report.cjs +1 -1
- package/services/engine/reports/xlsAllOurIdeasExport.js +16 -15
- package/services/engine/reports/xls_community_users_report.cjs +2 -2
- package/services/engine/reports/xls_group_report.cjs +1 -1
- package/services/llms/baseChatBot.js +12 -11
- package/services/llms/imageGeneration/chatGptImageGenerator.js +3 -2
- package/services/llms/imageGeneration/collectionImageGenerator.js +7 -6
- package/services/llms/imageGeneration/dalleImageGenerator.js +6 -5
- package/services/llms/imageGeneration/fluxImageGenerator.js +5 -4
- package/services/llms/imageGeneration/imageProcessorService.js +2 -1
- package/services/llms/imageGeneration/imagenImageGenerator.js +8 -7
- package/services/llms/imageGeneration/s3Service.js +12 -11
- package/services/llms/llmTranslation.js +30 -29
- package/services/models/ac_activity.cjs +1 -1
- package/services/models/ac_notification.cjs +1 -1
- package/services/models/ac_translation_cache.cjs +11 -11
- package/services/scripts/analytics/setup_all_plausible_goals.cjs +2 -2
- package/services/scripts/fix_old_delayed_notifications.js +3 -3
- package/services/scripts/kue_status.js +11 -11
- package/services/scripts/kue_watch_stuck_jobs.js +6 -6
- package/services/scripts/translation_clear_language.js +21 -21
- package/services/scripts/translation_delete.js +4 -4
- package/services/scripts/translation_replace_text_from_url.js +4 -4
- package/services/scripts/translation_update.js +4 -4
- package/services/scripts/translations_list.js +5 -5
- package/services/utils/airbrake.cjs +2 -1
- package/services/utils/redisConnection.cjs +6 -5
- package/services/utils/translation_helpers.cjs +3 -2
- package/services/utils/updateAllLocalesFromEn.js +20 -19
- package/services/utils/updateLocaleFolders.js +7 -6
- package/services/workers/activity.cjs +1 -1
- package/services/workers/anonymizations.cjs +1 -1
- package/services/workers/bulk_status_update.cjs +2 -2
- package/services/workers/delayed_jobs.cjs +1 -1
- package/services/workers/deletions.cjs +1 -1
- package/services/workers/email.cjs +1 -1
- package/services/workers/fraud_management.cjs +3 -3
- package/services/workers/generativeAi.js +6 -5
- package/services/workers/main.cjs +1 -1
- package/services/workers/marketing.cjs +1 -1
- package/services/workers/moderation.cjs +1 -1
- package/services/workers/notification_delivery.cjs +1 -1
- package/services/workers/notification_news_feed.cjs +1 -1
- package/services/workers/queue.cjs +2 -2
- package/services/workers/recount.cjs +1 -1
- package/services/workers/reports.cjs +1 -1
- package/services/workers/similarities.cjs +4 -2
- package/services/workers/speech_to_text.cjs +1 -1
- package/utils/airbrake.cjs +1 -1
- package/utils/cjsCodeReview.js +7 -6
- package/utils/community_mapping_tools.cjs +2 -2
- package/utils/copy_utils.cjs +31 -31
- package/utils/export_utils.cjs +7 -7
- package/utils/generateDocumentation.js +10 -9
- package/utils/logger.cjs +2 -23
- package/utils/logger.d.cts +1 -1
- package/utils/loggerAirbrakeTransport.cjs +52 -0
- package/utils/loggerAirbrakeTransport.d.cts +15 -0
- package/utils/loggerAirbrakeTransportTs.d.ts +15 -0
- package/utils/loggerAirbrakeTransportTs.js +45 -0
- package/utils/loggerCore.cjs +29 -0
- package/utils/loggerCore.d.cts +2 -0
- package/utils/loggerCoreTs.d.ts +2 -0
- package/utils/loggerCoreTs.js +23 -0
- package/utils/loggerTs.d.ts +1 -2
- package/utils/loggerTs.js +2 -25
- package/utils/recount_utils.cjs +5 -5
- package/utils/seedModels.js +50 -49
- package/utils/sitemap_generator.cjs +4 -4
- package/utils/ypLanguages.js +2 -2
- package/webSockets.js +8 -7
- package/services/utils/logger.cjs +0 -25
- package/services/utils/logger.d.cts +0 -2
- package/src/agents/assistants/assistant.d.ts +0 -156
- package/src/controllers/audios.d.ts +0 -5
- package/src/controllers/categories.d.ts +0 -5
- package/src/controllers/communities.d.ts +0 -5
- package/src/controllers/domains.d.ts +0 -5
- package/src/controllers/groups.d.ts +0 -5
- package/src/controllers/images.d.ts +0 -5
- package/src/controllers/points.d.ts +0 -5
- package/src/controllers/posts.d.ts +0 -5
- package/src/controllers/ratings.d.ts +0 -5
- package/src/controllers/users.d.ts +0 -5
- package/src/controllers/videos.d.ts +0 -5
- package/src/models/index.d.ts +0 -84
- package/src/services/controllers/activities.d.ts +0 -5
- package/src/services/controllers/notifications.d.ts +0 -5
- package/src/utils/copy_utils.d.ts +0 -4
- package/src/utils/manifest_generator.d.ts +0 -18
|
@@ -10,6 +10,7 @@ import { YpSubscription } from "../models/subscription.js";
|
|
|
10
10
|
import { YpAgentProductBundle } from "../models/agentProductBundle.js";
|
|
11
11
|
import queue from "../../services/workers/queue.cjs";
|
|
12
12
|
import { EmailTemplateRenderer } from "./emailTemplateRenderer.js";
|
|
13
|
+
import log from "../../utils/loggerTs.js";
|
|
13
14
|
const dbModels = models;
|
|
14
15
|
const Group = dbModels.Group;
|
|
15
16
|
const User = dbModels.User;
|
|
@@ -18,13 +19,13 @@ const Domain = dbModels.Domain;
|
|
|
18
19
|
export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
19
20
|
constructor(wsClients) {
|
|
20
21
|
super();
|
|
21
|
-
|
|
22
|
+
log.info("NotificationAgentQueueManager: Initializing");
|
|
22
23
|
this.initializeRedis();
|
|
23
24
|
this.queues = new Map();
|
|
24
25
|
this.wsClients = wsClients;
|
|
25
26
|
}
|
|
26
27
|
async sendNotification(agent, agentRun, action, wsClientId, status, result, agentRunId, updatedWorkflow) {
|
|
27
|
-
|
|
28
|
+
log.info("NotificationAgentQueueManager: Sending notification", agentRunId, updatedWorkflow);
|
|
28
29
|
const wsClient = this.wsClients.get(wsClientId);
|
|
29
30
|
if (wsClient) {
|
|
30
31
|
const currentWorkflowStep = updatedWorkflow?.steps[updatedWorkflow?.currentStepIndex];
|
|
@@ -42,13 +43,13 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
42
43
|
}));
|
|
43
44
|
}
|
|
44
45
|
else {
|
|
45
|
-
|
|
46
|
+
log.error(`NotificationAgentQueueManager: WebSocket client with ID ${wsClientId} not found`);
|
|
46
47
|
}
|
|
47
48
|
if (updatedWorkflow) {
|
|
48
49
|
await this.sendNotificationEmail(agent, agentRun, updatedWorkflow);
|
|
49
50
|
}
|
|
50
51
|
else {
|
|
51
|
-
|
|
52
|
+
log.error("NotificationAgentQueueManager: No updated workflow found");
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
async sendNotificationEmail(agent, agentRun, updatedWorkflow) {
|
|
@@ -95,7 +96,7 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
else {
|
|
98
|
-
|
|
99
|
+
log.error("No group admins with email found");
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
102
|
}
|
|
@@ -105,13 +106,13 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
105
106
|
attributes: ["id", "workflow", "status"],
|
|
106
107
|
});
|
|
107
108
|
if (!agentRun || !agentRun.workflow) {
|
|
108
|
-
|
|
109
|
+
log.error(`NotificationAgentQueueManager: Agent run ${agentRunId} or its workflow not found`);
|
|
109
110
|
return;
|
|
110
111
|
}
|
|
111
112
|
const workflowConfig = agentRun.workflow;
|
|
112
113
|
if (currentWorkflowStepIndex !== undefined &&
|
|
113
114
|
currentWorkflowStepIndex !== workflowConfig.currentStepIndex) {
|
|
114
|
-
|
|
115
|
+
log.error("NotificationAgentQueueManager: Current workflow step index is undefined or matches the current step index, not advancing to the next step");
|
|
115
116
|
return;
|
|
116
117
|
}
|
|
117
118
|
if (currentWorkflowStepIndex === 0) {
|
|
@@ -136,7 +137,7 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
136
137
|
}
|
|
137
138
|
async advanceWorkflowStepOrCompleteAgentRun(agentRunId, status, wsClientId, currentWorkflowStepIndex = undefined) {
|
|
138
139
|
try {
|
|
139
|
-
|
|
140
|
+
log.info("NotificationAgentQueueManager: Advancing workflow step or completing agent run", agentRunId, status);
|
|
140
141
|
// Get the agent run record
|
|
141
142
|
const agentRun = await YpAgentProductRun.findByPk(agentRunId, {
|
|
142
143
|
attributes: ["id", "workflow", "status"],
|
|
@@ -149,7 +150,7 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
149
150
|
],
|
|
150
151
|
});
|
|
151
152
|
if (!agentRun || !agentRun.workflow) {
|
|
152
|
-
|
|
153
|
+
log.error(`NotificationAgentQueueManager: Agent run ${agentRunId} or its workflow not found`);
|
|
153
154
|
return;
|
|
154
155
|
}
|
|
155
156
|
const workflowConfig = agentRun.workflow;
|
|
@@ -160,7 +161,7 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
160
161
|
}
|
|
161
162
|
if (currentWorkflowStepIndex !== undefined &&
|
|
162
163
|
currentWorkflowStepIndex !== workflowConfig.currentStepIndex) {
|
|
163
|
-
|
|
164
|
+
log.error("NotificationAgentQueueManager: Current workflow step index is undefined or matches the current step index, not advancing to the next step");
|
|
164
165
|
return;
|
|
165
166
|
}
|
|
166
167
|
// Check if there are more steps
|
|
@@ -180,7 +181,7 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
180
181
|
agentRun.changed("workflow", true);
|
|
181
182
|
await agentRun.save();
|
|
182
183
|
//TODO: UPDATE AGENT MEMORY, Maybe
|
|
183
|
-
|
|
184
|
+
log.info("NotificationAgentQueueManager: Updated workflow for agent run", agentRunId, status, workflowConfig);
|
|
184
185
|
}
|
|
185
186
|
else {
|
|
186
187
|
// This was the last step, mark the workflow as completed
|
|
@@ -188,12 +189,12 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
188
189
|
agentRun.changed("status", true);
|
|
189
190
|
await agentRun.save();
|
|
190
191
|
await agentRun.update({ status: "completed", completedAt: new Date() });
|
|
191
|
-
|
|
192
|
+
log.info("NotificationAgentQueueManager: Updated workflow for agent run", agentRunId, "to completed");
|
|
192
193
|
}
|
|
193
194
|
return workflowConfig;
|
|
194
195
|
}
|
|
195
196
|
catch (error) {
|
|
196
|
-
|
|
197
|
+
log.error(`NotificationAgentQueueManager: Error in advanceWorkflowStepOrCompleteAgentRun:`, error);
|
|
197
198
|
}
|
|
198
199
|
}
|
|
199
200
|
static async getAgentRun(agentRunId) {
|
|
@@ -231,17 +232,17 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
231
232
|
});
|
|
232
233
|
}
|
|
233
234
|
getQueue(queueName) {
|
|
234
|
-
|
|
235
|
+
log.info(`NotificationAgentQueueManager: Getting queue for ${queueName}`);
|
|
235
236
|
if (!this.queues.has(queueName)) {
|
|
236
|
-
|
|
237
|
+
log.info(`NotificationAgentQueueManager: Creating new queue for ${queueName}`);
|
|
237
238
|
const newQueue = new Queue(queueName, {
|
|
238
239
|
connection: this.redisClient,
|
|
239
240
|
});
|
|
240
241
|
newQueue.on("error", (error) => {
|
|
241
|
-
|
|
242
|
+
log.info(`NotificationAgentQueueManager: Error in queue ${queueName}:`, error);
|
|
242
243
|
});
|
|
243
244
|
newQueue.on("waiting", (jobId) => {
|
|
244
|
-
|
|
245
|
+
log.info(`Job ${jobId} is waiting in queue ${queueName}`);
|
|
245
246
|
});
|
|
246
247
|
// Create QueueEvents instance for global events
|
|
247
248
|
const queueEvents = new QueueEvents(queueName, {
|
|
@@ -249,31 +250,31 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
249
250
|
});
|
|
250
251
|
// Add event listeners for debugging
|
|
251
252
|
queueEvents.on("waiting", ({ jobId }) => {
|
|
252
|
-
|
|
253
|
+
log.info(`Job ${jobId} is waiting in queue ${queueName}`);
|
|
253
254
|
});
|
|
254
255
|
queueEvents.on("active", ({ jobId, prev }) => {
|
|
255
|
-
|
|
256
|
+
log.info(`Job ${jobId} is active in queue ${queueName} (prev state: ${prev})`);
|
|
256
257
|
});
|
|
257
258
|
queueEvents.on("completed", async ({ jobId, returnvalue }) => {
|
|
258
|
-
|
|
259
|
+
log.info(`Job ${jobId} completed in queue ${queueName}. Result:`, returnvalue);
|
|
259
260
|
try {
|
|
260
|
-
|
|
261
|
+
log.info("NotificationAgentQueueManager: Job completed in queue", queueName, jobId);
|
|
261
262
|
// Retrieve the job instance
|
|
262
263
|
const job = await newQueue.getJob(jobId);
|
|
263
264
|
if (job) {
|
|
264
265
|
const { agentId, type, wsClientId, agentRunId, currentWorkflowStepIndex, } = job.data;
|
|
265
|
-
|
|
266
|
-
|
|
266
|
+
log.info("NotificationAgentQueueManager: Job data", job.data);
|
|
267
|
+
log.info("NotificationAgentQueueManager: currentWorkflowStepIndex", currentWorkflowStepIndex);
|
|
267
268
|
// Load the agent database record
|
|
268
269
|
const agent = await PsAgent.findByPk(agentId, {
|
|
269
270
|
include: [{ model: PsAgentClass, as: "Class" }],
|
|
270
271
|
});
|
|
271
272
|
const agentRun = await NotificationAgentQueueManager.getAgentRun(agentRunId);
|
|
272
273
|
if (!agentRun) {
|
|
273
|
-
|
|
274
|
+
log.error(`NotificationAgentQueueManager: Agent run with ID ${agentRunId} not found.`);
|
|
274
275
|
return;
|
|
275
276
|
}
|
|
276
|
-
|
|
277
|
+
log.info("NotificationAgentQueueManager: Agent", agent);
|
|
277
278
|
let updatedWorkflow;
|
|
278
279
|
if (agentRun.status === "running" ||
|
|
279
280
|
agentRun.status === "waiting_on_user") {
|
|
@@ -282,14 +283,14 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
282
283
|
await this.advanceWorkflowStepOrCompleteAgentRun(agentRunId, agentRun.status, wsClientId, currentWorkflowStepIndex);
|
|
283
284
|
}
|
|
284
285
|
else {
|
|
285
|
-
|
|
286
|
+
log.error(`NotificationAgentQueueManager: Agent run ID ${agentRunId} not found.`);
|
|
286
287
|
}
|
|
287
288
|
if (agent) {
|
|
288
289
|
// Send notification
|
|
289
290
|
await this.sendNotification(agent, agentRun, type, wsClientId, agentRun.status, returnvalue, agentRunId, updatedWorkflow);
|
|
290
291
|
}
|
|
291
292
|
else {
|
|
292
|
-
|
|
293
|
+
log.error(`NotificationAgentQueueManager: Agent with ID ${agentId} not found.`);
|
|
293
294
|
}
|
|
294
295
|
}
|
|
295
296
|
else if (agentRun.status === "stopped") {
|
|
@@ -297,29 +298,29 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
297
298
|
updatedWorkflow = await this.goBackOneWorkflowStepIfNeeded(agentRunId, agentRun.status, wsClientId, currentWorkflowStepIndex);
|
|
298
299
|
}
|
|
299
300
|
else {
|
|
300
|
-
|
|
301
|
+
log.error(`NotificationAgentQueueManager: Agent run ID ${agentRunId} not found.`);
|
|
301
302
|
}
|
|
302
303
|
}
|
|
303
304
|
else {
|
|
304
|
-
|
|
305
|
+
log.error(`NotificationAgentQueueManager: Agent run ${agentRunId} is not completed, status ${agentRun.status} but the job completed`);
|
|
305
306
|
}
|
|
306
307
|
}
|
|
307
308
|
else {
|
|
308
|
-
|
|
309
|
+
log.error(`NotificationAgentQueueManager: Job with ID ${jobId} not found.`);
|
|
309
310
|
}
|
|
310
311
|
}
|
|
311
312
|
catch (error) {
|
|
312
|
-
|
|
313
|
+
log.error(`NotificationAgentQueueManager: Error handling job completion for job ${jobId}:`, error);
|
|
313
314
|
}
|
|
314
315
|
});
|
|
315
316
|
queueEvents.on("failed", async ({ jobId, failedReason }) => {
|
|
316
|
-
|
|
317
|
+
log.info(`Job ${jobId} failed in queue ${queueName}. Reason:`, failedReason);
|
|
317
318
|
try {
|
|
318
319
|
// Retrieve the job instance
|
|
319
320
|
const job = await newQueue.getJob(jobId);
|
|
320
321
|
if (job) {
|
|
321
322
|
const { agentId, type, wsClientId, agentRunId } = job.data;
|
|
322
|
-
|
|
323
|
+
log.info("NotificationAgentQueueManager: FAILED Job data", job.data);
|
|
323
324
|
// Load the agent database record
|
|
324
325
|
const agent = await PsAgent.findByPk(agentId, {
|
|
325
326
|
include: [{ model: PsAgentClass, as: "Class" }],
|
|
@@ -340,10 +341,10 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
340
341
|
);*/
|
|
341
342
|
}
|
|
342
343
|
else {
|
|
343
|
-
|
|
344
|
+
log.error(`NotificationAgentQueueManager: Agent with ID ${agentId} not found.`);
|
|
344
345
|
}
|
|
345
346
|
if (!agentRun) {
|
|
346
|
-
|
|
347
|
+
log.error(`NotificationAgentQueueManager: Agent run with ID ${agentRunId} not found.`);
|
|
347
348
|
return;
|
|
348
349
|
}
|
|
349
350
|
agentRun.workflow.steps[agentRun.workflow.currentStepIndex].endTime = new Date();
|
|
@@ -354,68 +355,68 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
354
355
|
await agentRun.save();
|
|
355
356
|
}
|
|
356
357
|
else {
|
|
357
|
-
|
|
358
|
+
log.error(`Job with ID ${jobId} not found.`);
|
|
358
359
|
}
|
|
359
360
|
}
|
|
360
361
|
catch (error) {
|
|
361
|
-
|
|
362
|
+
log.error(`Error handling job failure for job ${jobId}:`, error);
|
|
362
363
|
}
|
|
363
364
|
});
|
|
364
365
|
queueEvents.on("progress", ({ jobId, data }) => {
|
|
365
|
-
|
|
366
|
+
log.info(`Job ${jobId} reported progress in queue ${queueName}:`, data);
|
|
366
367
|
});
|
|
367
368
|
queueEvents.on("removed", ({ jobId }) => {
|
|
368
|
-
|
|
369
|
+
log.info(`Job ${jobId} was removed from queue ${queueName}`);
|
|
369
370
|
});
|
|
370
371
|
queueEvents.on("drained", () => {
|
|
371
|
-
|
|
372
|
+
log.info(`Queue ${queueName} was drained`);
|
|
372
373
|
});
|
|
373
374
|
queueEvents.on("error", (error) => {
|
|
374
|
-
|
|
375
|
+
log.info(`Error in queue ${queueName}:`, error);
|
|
375
376
|
});
|
|
376
377
|
this.queues.set(queueName, newQueue);
|
|
377
378
|
}
|
|
378
379
|
return this.queues.get(queueName);
|
|
379
380
|
}
|
|
380
381
|
async controlAgent(agentId, action) {
|
|
381
|
-
|
|
382
|
+
log.info(`AgentQueueManager: Controlling agent ${agentId} with action ${action}`);
|
|
382
383
|
const agent = await PsAgent.findByPk(agentId, {
|
|
383
384
|
include: [{ model: PsAgentClass, as: "Class" }],
|
|
384
385
|
});
|
|
385
386
|
if (!agent || !agent.Class) {
|
|
386
|
-
|
|
387
|
+
log.error(`AgentQueueManager: Agent or Agent Class not found for agent ${agentId}`);
|
|
387
388
|
throw new Error("Agent or Agent Class not found");
|
|
388
389
|
}
|
|
389
390
|
const queueName = agent.Class.configuration.queueName;
|
|
390
391
|
if (!queueName) {
|
|
391
|
-
|
|
392
|
+
log.error(`AgentQueueManager: Queue name not defined for agent class ${agent.Class.id}`);
|
|
392
393
|
throw new Error("Queue name not defined for this agent class");
|
|
393
394
|
}
|
|
394
395
|
const queue = this.getQueue(queueName);
|
|
395
|
-
|
|
396
|
+
log.info(`AgentQueueManager: Adding ${action} job to queue ${queueName} for agent ${agentId}`);
|
|
396
397
|
await queue.add(`${action}Agent`, { agentId, action });
|
|
397
398
|
const message = `${action.charAt(0).toUpperCase() + action.slice(1)} request for agent ${agentId} queued in ${queueName}`;
|
|
398
|
-
|
|
399
|
+
log.info(`AgentQueueManager: ${message}`);
|
|
399
400
|
return message;
|
|
400
401
|
}
|
|
401
402
|
async startAgentProcessingWithWsClient(agentId, agentRunId, wsClientId, structuredAnswersOverrides) {
|
|
402
|
-
|
|
403
|
+
log.info(`NotificationAgentQueueManager: Starting agent processing for agent ${agentId}`);
|
|
403
404
|
const agent = await PsAgent.findByPk(agentId, {
|
|
404
405
|
include: [{ model: PsAgentClass, as: "Class" }],
|
|
405
406
|
});
|
|
406
407
|
if (!agent || !agent.Class) {
|
|
407
|
-
|
|
408
|
+
log.error(`NotificationAgentQueueManager: Agent or Agent Class not found for agent ${agentId}`);
|
|
408
409
|
return undefined;
|
|
409
410
|
}
|
|
410
411
|
const agentRun = await NotificationAgentQueueManager.getAgentRun(agentRunId);
|
|
411
412
|
if (!agentRun) {
|
|
412
|
-
|
|
413
|
+
log.error(`NotificationAgentQueueManager: Agent run with ID ${agentRunId} not found.`);
|
|
413
414
|
return undefined;
|
|
414
415
|
}
|
|
415
416
|
const currentWorkflow = agentRun.workflow;
|
|
416
417
|
const queueName = agent.Class.configuration.queueName;
|
|
417
418
|
const queue = this.getQueue(queueName);
|
|
418
|
-
|
|
419
|
+
log.info(`NotificationAgentQueueManager: Adding start-processing job to queue ${queueName} for agent ${agentId}`);
|
|
419
420
|
const action = "start";
|
|
420
421
|
const job = await queue.add("control-message", {
|
|
421
422
|
type: `${action}Agent${agent.id}`,
|
|
@@ -426,12 +427,12 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
426
427
|
structuredAnswersOverrides: structuredAnswersOverrides,
|
|
427
428
|
currentWorkflowStepIndex: currentWorkflow.currentStepIndex,
|
|
428
429
|
});
|
|
429
|
-
|
|
430
|
+
log.info(`NotificationAgentQueueManager: Updating agent ${agentId} status to running`);
|
|
430
431
|
await this.updateAgentStatus(agent.id, "running");
|
|
431
432
|
return job.id;
|
|
432
433
|
}
|
|
433
434
|
async stopAgentProcessing(agentId, wsClientId, agentRunId) {
|
|
434
|
-
|
|
435
|
+
log.info(`NotificationAgentQueueManager: Stopping agent processing for agent ${agentId}`);
|
|
435
436
|
const agent = await PsAgent.findByPk(agentId, {
|
|
436
437
|
include: [{ model: PsAgentClass, as: "Class" }],
|
|
437
438
|
});
|
|
@@ -440,14 +441,14 @@ export class NotificationAgentQueueManager extends AgentQueueManager {
|
|
|
440
441
|
}
|
|
441
442
|
const agentRun = await NotificationAgentQueueManager.getAgentRun(agentRunId);
|
|
442
443
|
if (!agentRun) {
|
|
443
|
-
|
|
444
|
+
log.error(`NotificationAgentQueueManager: Agent run with ID ${agentRunId} not found.`);
|
|
444
445
|
return false;
|
|
445
446
|
}
|
|
446
447
|
const currentWorkflow = agentRun.workflow;
|
|
447
448
|
const queueName = agent.Class.configuration.queueName;
|
|
448
449
|
const queue = this.getQueue(queueName);
|
|
449
450
|
const action = "stop";
|
|
450
|
-
|
|
451
|
+
log.info(`NotificationAgentQueueManager: Adding stop-processing job to queue ${queueName} for agent ${agentId} ${action}`);
|
|
451
452
|
await queue.add("control-message", {
|
|
452
453
|
type: `${action}Agent${agent.id}`,
|
|
453
454
|
agentId: agent.id,
|
|
@@ -12,6 +12,7 @@ import { PsAgent } from "@policysynth/agents/dbModels/agent.js";
|
|
|
12
12
|
import { PsAgentClass, PsAiModel } from "@policysynth/agents/dbModels/index.js";
|
|
13
13
|
import { NotificationAgentQueueManager } from "./notificationAgentQueueManager.js";
|
|
14
14
|
import models from "../../models/index.cjs";
|
|
15
|
+
import log from "../../utils/loggerTs.js";
|
|
15
16
|
const dbModels = models;
|
|
16
17
|
const YpGroup = dbModels.Group;
|
|
17
18
|
export class SubscriptionManager {
|
|
@@ -51,7 +52,7 @@ export class SubscriptionManager {
|
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
async cloneCommunityTemplate(communityTemplateId, toDomainId) {
|
|
54
|
-
|
|
55
|
+
log.info("cloneCommunityTemplate", communityTemplateId, toDomainId);
|
|
55
56
|
return new Promise((resolve, reject) => {
|
|
56
57
|
copyCommunity(communityTemplateId, toDomainId, {
|
|
57
58
|
copyGroups: true,
|
|
@@ -73,15 +74,15 @@ export class SubscriptionManager {
|
|
|
73
74
|
});
|
|
74
75
|
}
|
|
75
76
|
async cloneCommunityWorkflowTemplate(agentProduct, domainId, currentUser) {
|
|
76
|
-
|
|
77
|
+
log.info("cloneCommunityWorkflowTemplate", agentProduct, domainId);
|
|
77
78
|
let newCommunity = await this.cloneCommunityTemplate(agentProduct.configuration.templateWorkflowCommunityId, domainId);
|
|
78
|
-
|
|
79
|
+
log.info("newCommunity", newCommunity);
|
|
79
80
|
const groups = await YpGroup.findAll({
|
|
80
81
|
where: {
|
|
81
82
|
community_id: newCommunity.id
|
|
82
83
|
}
|
|
83
84
|
});
|
|
84
|
-
|
|
85
|
+
log.info("groups", groups);
|
|
85
86
|
// Find the workflow group
|
|
86
87
|
const workflowGroup = groups.find((group) => group.configuration.groupType == 3);
|
|
87
88
|
if (!workflowGroup) {
|
|
@@ -101,32 +102,32 @@ export class SubscriptionManager {
|
|
|
101
102
|
const hasCommunityUser = await newCommunity.hasCommunityUsers(userInstance);
|
|
102
103
|
if (!hasCommunityUser) {
|
|
103
104
|
await newCommunity.addCommunityUsers(userInstance);
|
|
104
|
-
|
|
105
|
+
log.info("Added current user as community user", userInstance.id);
|
|
105
106
|
}
|
|
106
107
|
else {
|
|
107
|
-
|
|
108
|
+
log.info("Community already has the user as user", userInstance.id);
|
|
108
109
|
}
|
|
109
110
|
for (const group of groups) {
|
|
110
111
|
const hasGroupAdmin = await group.hasGroupAdmins(userInstance);
|
|
111
112
|
if (!hasGroupAdmin) {
|
|
112
113
|
await group.addGroupAdmins(userInstance);
|
|
113
|
-
|
|
114
|
+
log.info("Added current user as group admin", userInstance.id);
|
|
114
115
|
}
|
|
115
116
|
else {
|
|
116
|
-
|
|
117
|
+
log.info("Group already has the user as admin", userInstance.id);
|
|
117
118
|
}
|
|
118
119
|
const hasGroupUser = await group.hasGroupUsers(userInstance);
|
|
119
120
|
if (!hasGroupUser) {
|
|
120
121
|
await group.addGroupUsers(userInstance);
|
|
121
|
-
|
|
122
|
+
log.info("Added current user as group user", userInstance.id);
|
|
122
123
|
}
|
|
123
124
|
else {
|
|
124
|
-
|
|
125
|
+
log.info("Group already has the user as user", userInstance.id);
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
// Create a map of old group IDs to new group IDs
|
|
128
129
|
const groupIdMap = newCommunity.groupMapping;
|
|
129
|
-
|
|
130
|
+
log.info("groupIdMap", groupIdMap);
|
|
130
131
|
// Get the original top level agent and all its sub-agents
|
|
131
132
|
const originalTopLevelAgent = await PsAgent.findByPk(topLevelAgentId, {
|
|
132
133
|
include: [
|
|
@@ -178,9 +179,9 @@ export class SubscriptionManager {
|
|
|
178
179
|
group_id: workflowGroup.id,
|
|
179
180
|
parent_agent_id: undefined
|
|
180
181
|
});
|
|
181
|
-
|
|
182
|
+
log.info("clonedTopLevelAgent", clonedTopLevelAgent);
|
|
182
183
|
if (originalTopLevelAgent.Class?.class_base_id) {
|
|
183
|
-
|
|
184
|
+
log.info("Setting agentUuidMap", originalTopLevelAgent.Class.class_base_id, clonedTopLevelAgent.id);
|
|
184
185
|
agentUuidMap.set(originalTopLevelAgent.Class.class_base_id, clonedTopLevelAgent.id);
|
|
185
186
|
}
|
|
186
187
|
const agentInputConnectorGroupsIds = new Map();
|
|
@@ -199,7 +200,7 @@ export class SubscriptionManager {
|
|
|
199
200
|
if (subAgent.Class?.class_base_id) {
|
|
200
201
|
agentUuidMap.set(subAgent.Class.class_base_id, clonedSubAgent.id);
|
|
201
202
|
}
|
|
202
|
-
|
|
203
|
+
log.info("agentUuidMap", agentUuidMap);
|
|
203
204
|
const subAgentAiModels = await subAgent.getAiModels();
|
|
204
205
|
if (subAgentAiModels && subAgentAiModels.length > 0) {
|
|
205
206
|
await clonedSubAgent.setAiModels(subAgentAiModels);
|
|
@@ -208,7 +209,7 @@ export class SubscriptionManager {
|
|
|
208
209
|
for (const connector of (subAgent.InputConnectors ??
|
|
209
210
|
[])) {
|
|
210
211
|
const connectorConfig = { ...connector.configuration };
|
|
211
|
-
|
|
212
|
+
log.info("connectorConfig", connectorConfig);
|
|
212
213
|
// Update the group ID if it exists in the map
|
|
213
214
|
if (connectorConfig.groupId &&
|
|
214
215
|
groupIdMap.has(connectorConfig.groupId)) {
|
|
@@ -231,7 +232,7 @@ export class SubscriptionManager {
|
|
|
231
232
|
for (const connector of (subAgent.OutputConnectors ??
|
|
232
233
|
[])) {
|
|
233
234
|
const connectorConfig = { ...connector.configuration };
|
|
234
|
-
|
|
235
|
+
log.info("connectorConfig", connectorConfig);
|
|
235
236
|
// Update the group ID if it exists in the map
|
|
236
237
|
if (connectorConfig.groupId &&
|
|
237
238
|
groupIdMap.has(connectorConfig.groupId)) {
|
|
@@ -253,7 +254,7 @@ export class SubscriptionManager {
|
|
|
253
254
|
}
|
|
254
255
|
// Update the workflow group configuration
|
|
255
256
|
workflowGroup.configuration.agents.topLevelAgentId = clonedTopLevelAgent.id;
|
|
256
|
-
|
|
257
|
+
log.info(`Set top level agent id to ${clonedTopLevelAgent.id} for workflow group ${workflowGroup.id}`);
|
|
257
258
|
workflowGroup.changed('configuration', true);
|
|
258
259
|
await workflowGroup.save();
|
|
259
260
|
if (agentProduct.configuration.structuredAnswersOverride) {
|
|
@@ -264,11 +265,11 @@ export class SubscriptionManager {
|
|
|
264
265
|
...(originalTopLevelAgent.SubAgents ?? []),
|
|
265
266
|
originalTopLevelAgent,
|
|
266
267
|
]) {
|
|
267
|
-
|
|
268
|
+
log.info("update answers for agent", agent);
|
|
268
269
|
if (agent.configuration?.answers) {
|
|
269
270
|
const answerIndex = agent.configuration.answers.findIndex((a) => a.uniqueId === override.uniqueId);
|
|
270
271
|
if (answerIndex !== -1) {
|
|
271
|
-
|
|
272
|
+
log.info("update answers for agent", agent.configuration.answers[answerIndex], override);
|
|
272
273
|
agent.configuration.answers[answerIndex] = {
|
|
273
274
|
...agent.configuration.answers[answerIndex],
|
|
274
275
|
...override,
|
|
@@ -286,7 +287,7 @@ export class SubscriptionManager {
|
|
|
286
287
|
newStep.agentId = agentUuidMap.get(step.agentClassUuid);
|
|
287
288
|
}
|
|
288
289
|
else if (step.agentClassUuid) {
|
|
289
|
-
|
|
290
|
+
log.error("agentClassUuid not found in agentUuidMap", step.agentClassUuid);
|
|
290
291
|
}
|
|
291
292
|
if (newStep.type === "engagmentFromInputConnector" && newStep.agentId) {
|
|
292
293
|
newStep.groupId = agentInputConnectorGroupsIds.get(newStep.agentId);
|
|
@@ -297,7 +298,7 @@ export class SubscriptionManager {
|
|
|
297
298
|
return newStep;
|
|
298
299
|
});
|
|
299
300
|
updatedWorkflow.workflowGroupId = workflowGroup.id;
|
|
300
|
-
|
|
301
|
+
log.info("updatedWorkflow", updatedWorkflow);
|
|
301
302
|
return {
|
|
302
303
|
workflow: updatedWorkflow,
|
|
303
304
|
requiredQuestions: agentProduct.configuration.requiredStructuredQuestions,
|
|
@@ -460,7 +461,7 @@ export class SubscriptionManager {
|
|
|
460
461
|
}
|
|
461
462
|
}
|
|
462
463
|
catch (error) {
|
|
463
|
-
|
|
464
|
+
log.error("Error starting agent processing:", error);
|
|
464
465
|
return false;
|
|
465
466
|
}
|
|
466
467
|
}
|
|
@@ -515,7 +516,7 @@ export class SubscriptionManager {
|
|
|
515
516
|
let runsUsed = subscription.metadata?.runs_used || 0;
|
|
516
517
|
runsUsed += 1;
|
|
517
518
|
if (runsUsed > plan.configuration.max_runs_per_cycle) {
|
|
518
|
-
|
|
519
|
+
log.error("Maximum runs per cycle exceeded");
|
|
519
520
|
//TODO: Look into activating this again !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
|
|
520
521
|
//throw new Error("Maximum runs per cycle exceeded");
|
|
521
522
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DataTypes, Model } from "sequelize";
|
|
2
2
|
import { sequelize } from "@policysynth/agents/dbModels/sequelize.js";
|
|
3
|
+
import log from "../../utils/loggerTs.js";
|
|
3
4
|
export class YpAgentProduct extends Model {
|
|
4
5
|
}
|
|
5
6
|
YpAgentProduct.init({
|
|
@@ -70,7 +71,7 @@ YpAgentProduct.init({
|
|
|
70
71
|
underscored: true,
|
|
71
72
|
});
|
|
72
73
|
YpAgentProduct.associate = (models) => {
|
|
73
|
-
|
|
74
|
+
log.info(`YpAgentProduct.associate`);
|
|
74
75
|
YpAgentProduct.belongsTo(models.YpSubscriptionUser, {
|
|
75
76
|
foreignKey: "user_id",
|
|
76
77
|
as: "User",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DataTypes, Model } from 'sequelize';
|
|
2
2
|
import { sequelize } from "@policysynth/agents/dbModels/sequelize.js";
|
|
3
|
+
import log from "../../utils/loggerTs.js";
|
|
3
4
|
export class YpAgentProductBoosterPurchase extends Model {
|
|
4
5
|
}
|
|
5
6
|
YpAgentProductBoosterPurchase.init({
|
|
@@ -38,7 +39,7 @@ YpAgentProductBoosterPurchase.init({
|
|
|
38
39
|
});
|
|
39
40
|
// Associations
|
|
40
41
|
YpAgentProductBoosterPurchase.associate = (models) => {
|
|
41
|
-
|
|
42
|
+
log.info('YpAgentProductBoosterPurchase.associate');
|
|
42
43
|
YpAgentProductBoosterPurchase.belongsTo(models.YpSubscriptionUser, {
|
|
43
44
|
foreignKey: 'user_id',
|
|
44
45
|
as: 'User'
|
|
@@ -5,12 +5,13 @@ import { YpSubscriptionPlan } from "../subscriptionPlan.js";
|
|
|
5
5
|
import { YpSubscriptionUser } from "../subscriptionUser.js";
|
|
6
6
|
import { YpSubscription } from "../subscription.js";
|
|
7
7
|
import { YpAgentProductBundle } from "../agentProductBundle.js";
|
|
8
|
+
import log from "../../../utils/loggerTs.js";
|
|
8
9
|
async function createAgentProductsAndPlans() {
|
|
9
10
|
let transaction;
|
|
10
11
|
try {
|
|
11
12
|
// Connect to the database
|
|
12
13
|
await sequelize.authenticate();
|
|
13
|
-
|
|
14
|
+
log.info("Connection has been established successfully.");
|
|
14
15
|
// Start transaction
|
|
15
16
|
transaction = await sequelize.transaction();
|
|
16
17
|
// Define the user and domain (assuming they exist or create them)
|
|
@@ -428,7 +429,7 @@ async function createAgentProductsAndPlans() {
|
|
|
428
429
|
runs_used: 0,
|
|
429
430
|
extra_runs_purchased: 0,
|
|
430
431
|
}, { transaction });
|
|
431
|
-
|
|
432
|
+
log.info(`Created Agent Product: ${agentData.name} (ID: ${agentProduct.id})`);
|
|
432
433
|
// Create the Subscription Plan associated with this Agent Product
|
|
433
434
|
const planData = agentData.subscriptionPlan;
|
|
434
435
|
const subscriptionPlan = await YpSubscriptionPlan.create({
|
|
@@ -454,19 +455,19 @@ async function createAgentProductsAndPlans() {
|
|
|
454
455
|
runs_remaining: planData.configuration.max_runs_per_cycle,
|
|
455
456
|
},
|
|
456
457
|
}, { transaction });
|
|
457
|
-
|
|
458
|
+
log.info(`Created Free Trial Subscription (ID: ${subscription.id})`);
|
|
458
459
|
}
|
|
459
|
-
|
|
460
|
+
log.info(`Created Subscription Plan: ${planData.name} (ID: ${subscriptionPlan.id})`);
|
|
460
461
|
}
|
|
461
462
|
// Commit the transaction
|
|
462
463
|
await transaction.commit();
|
|
463
|
-
|
|
464
|
+
log.info("All Agent Products and Subscription Plans have been created.");
|
|
464
465
|
}
|
|
465
466
|
catch (error) {
|
|
466
467
|
// Rollback the transaction if there's an error
|
|
467
468
|
if (transaction)
|
|
468
469
|
await transaction.rollback();
|
|
469
|
-
|
|
470
|
+
log.error("Error creating Agent Products and Subscription Plans:", error);
|
|
470
471
|
throw error; // Re-throw the error to handle it at a higher level if needed
|
|
471
472
|
}
|
|
472
473
|
finally {
|