@yrpri/api 9.0.138 → 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.
Files changed (320) hide show
  1. package/agents/assistants/agentAssistant.js +4 -3
  2. package/agents/assistants/baseAssistant.js +72 -71
  3. package/agents/assistants/baseAssistantWithVoice.js +6 -5
  4. package/agents/assistants/modes/agentDirectConnection.js +8 -7
  5. package/agents/assistants/modes/agentSelectionMode.js +2 -1
  6. package/agents/assistants/modes/baseAssistantMode.js +3 -2
  7. package/agents/assistants/modes/tools/agentTools.js +11 -10
  8. package/agents/assistants/modes/tools/loginTools.js +7 -6
  9. package/agents/assistants/modes/tools/models/agents.js +6 -5
  10. package/agents/assistants/modes/tools/models/subscriptions.js +7 -6
  11. package/agents/assistants/modes/tools/navigationTools.js +7 -6
  12. package/agents/assistants/modes/tools/subscriptionTools.js +12 -11
  13. package/agents/assistants/modes/tools/workflowConverstationTools.js +7 -6
  14. package/agents/assistants/voiceAssistant.js +45 -44
  15. package/agents/controllers/agentProductController.js +8 -7
  16. package/agents/controllers/agentSubscriptionController.js +13 -12
  17. package/agents/controllers/assistantsController.js +45 -44
  18. package/agents/controllers/policySynthAgents.d.ts +2 -0
  19. package/agents/controllers/policySynthAgents.js +63 -31
  20. package/agents/managers/emailInvitesManager.js +4 -3
  21. package/agents/managers/newAiModelSetup.js +57 -132
  22. package/agents/managers/notificationAgentQueueManager.js +55 -54
  23. package/agents/managers/subscriptionManager.js +24 -23
  24. package/agents/models/agentProduct.js +2 -1
  25. package/agents/models/agentProductBoosterPurchase.js +2 -1
  26. package/agents/models/testData/createEvolyAgentProduct.js +7 -6
  27. package/agents/models/testData/old/updateAgentWorkflowConfiguration.js +5 -4
  28. package/agents/models/testData/updateAgentWorkflowConfiguration.js +5 -4
  29. package/agents/tools/setTemplateWorkflowCommunityId.js +6 -5
  30. package/app.d.ts +2 -1
  31. package/app.js +60 -34
  32. package/authorization.cjs +4 -4
  33. package/controllers/allOurIdeas.js +45 -44
  34. package/controllers/groups.cjs +4 -9
  35. package/controllers/images.cjs +8 -8
  36. package/controllers/index.cjs +1 -1
  37. package/controllers/points.cjs +1 -1
  38. package/controllers/posts.cjs +3 -3
  39. package/deleteUnwantedDeclerations.cjs +5 -5
  40. package/models/community.cjs +1 -1
  41. package/models/domain.cjs +7 -7
  42. package/models/image.cjs +2 -2
  43. package/models/index.cjs +8 -4
  44. package/models/post.cjs +10 -10
  45. package/models/user.cjs +1 -1
  46. package/models/video.cjs +4 -4
  47. package/package.json +5 -5
  48. package/scripts/addRatingUsersToGroup.js +1 -1
  49. package/scripts/addUserToOrganization.js +8 -8
  50. package/scripts/agents/changeModelForWorkflowGroupTemplate.js +13 -12
  51. package/scripts/agents/generateAgentWorkflowTemplateFromAgentClass.js +8 -7
  52. package/scripts/analyseRatingsForCommunity.js +2 -2
  53. package/scripts/analyzeAndFixBrokenPointUsers.js +3 -3
  54. package/scripts/analyzeEndorsementsByCountry.js +7 -7
  55. package/scripts/analyzePostsForCommunity.js +1 -1
  56. package/scripts/bulkStatusUpdates/listUpdates.js +2 -2
  57. package/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +5 -5
  58. package/scripts/bulkStatusUpdates/performUpdate.js +9 -9
  59. package/scripts/bulkStatusUpdates/performUpdateForGroup.cjs +11 -11
  60. package/scripts/bulkStatusUpdates/performUpdateForStatus.js +15 -15
  61. package/scripts/change/changeVideoAspectTo.js +3 -3
  62. package/scripts/change/setUseNewVersion.cjs +4 -4
  63. package/scripts/changeCommunityGroupcount.js +3 -3
  64. package/scripts/changeCommunityPostCount.js +3 -3
  65. package/scripts/changeGroupPostCount.js +3 -3
  66. package/scripts/changeLanguage.js +4 -4
  67. package/scripts/changeOfficalStatus.js +3 -3
  68. package/scripts/cleanups/deleteAnonNotifications.cjs +7 -7
  69. package/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +8 -8
  70. package/scripts/cleanups/deleteYearOldNotifications.cjs +5 -5
  71. package/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +5 -5
  72. package/scripts/clearAllEndorsementInGroup.js +5 -5
  73. package/scripts/cloning/clearUsersForCommunitiesFromUrl.js +3 -3
  74. package/scripts/cloning/cloneFromUrlScript.js +4 -4
  75. package/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +6 -6
  76. package/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +6 -6
  77. package/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +6 -6
  78. package/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +3 -3
  79. package/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +2 -2
  80. package/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +2 -2
  81. package/scripts/cloning/copyCommunityToDomainWithEverything.js +2 -2
  82. package/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +3 -3
  83. package/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +3 -3
  84. package/scripts/cloning/copyPostToGroupOld.js +12 -12
  85. package/scripts/cloning/copyPostVideosFromURL.js +3 -3
  86. package/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +2 -2
  87. package/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +7 -7
  88. package/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +6 -6
  89. package/scripts/cloning/setAdminsFromURL.js +5 -5
  90. package/scripts/cloning/setExternalIdsFromURL.js +3 -3
  91. package/scripts/countCommunity.js +11 -11
  92. package/scripts/countCommunityUsers.js +4 -4
  93. package/scripts/countDelayedNotifications.js +3 -3
  94. package/scripts/countGroup.js +11 -11
  95. package/scripts/countStuff.js +3 -3
  96. package/scripts/countUniqueVotersInAGroup.js +3 -3
  97. package/scripts/createInvitesAndShow.js +2 -2
  98. package/scripts/database/sync_database.js +2 -2
  99. package/scripts/database/sync_dev_database.js +3 -3
  100. package/scripts/debugNotifications.js +5 -5
  101. package/scripts/deleteAllNewsFeeds.js +2 -2
  102. package/scripts/deleteCategory.js +1 -1
  103. package/scripts/deleteOldAppActivities.js +5 -4
  104. package/scripts/deletePostContactDataForCommunity.js +5 -4
  105. package/scripts/destroy/destroy_all_but_one_domain.js +59 -59
  106. package/scripts/displayAuthorForPost.js +1 -1
  107. package/scripts/domains/createDomain.js +5 -4
  108. package/scripts/domains/importDomainsFromXls.js +7 -6
  109. package/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +2 -2
  110. package/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +9 -9
  111. package/scripts/exportAllStatusChanges.js +5 -5
  112. package/scripts/exportEndorsementsForCommunity.js +5 -5
  113. package/scripts/exportPointQualitiesForCommunity.js +5 -5
  114. package/scripts/exportPostsAndPointsForCommunity.js +9 -9
  115. package/scripts/exportPostsDataSetForDomain.js +12 -12
  116. package/scripts/exportPostsForGroup.js +7 -7
  117. package/scripts/exportRatingsForPost.js +2 -2
  118. package/scripts/exportUserEndorsementsWithUserAnalysis.js +6 -6
  119. package/scripts/exportUsersForCommunity.js +3 -3
  120. package/scripts/exportUsersForDomain.js +3 -3
  121. package/scripts/exportUsersForGroup.js +3 -3
  122. package/scripts/exports/ratingDistribution.js +6 -6
  123. package/scripts/exports/whoEndorsedWhatByCommunity.js +2 -2
  124. package/scripts/findUnusedClientImports.js +2 -2
  125. package/scripts/fixAllPostPointCounts.js +1 -1
  126. package/scripts/fixAnonNotificationsSettings.js +5 -5
  127. package/scripts/fixCountKopavogur.js +1 -1
  128. package/scripts/fixEndorsementsAfterCopyPostToGroup.js +10 -10
  129. package/scripts/fixExternalUserId.js +2 -2
  130. package/scripts/fixGroupAccess.js +3 -3
  131. package/scripts/fixGroupIdeasAndPointsCount.js +2 -2
  132. package/scripts/fixNotificationSettings.js +4 -4
  133. package/scripts/fixSurveyRadioBakedInSubCodes.js +6 -6
  134. package/scripts/fixWrongUserIdForStatusUpdates.js +6 -5
  135. package/scripts/gallery/exportGalleryData.js +2 -2
  136. package/scripts/gallery/importGalleryForCommunity.js +14 -14
  137. package/scripts/gallery/readJsonAndDownloadImagesVersion2.js +6 -6
  138. package/scripts/gallery/refreshAcApiPostIdsForCommunity.js +5 -5
  139. package/scripts/genderAnalysis.js +10 -10
  140. package/scripts/genderAnalysisByStatus.js +4 -4
  141. package/scripts/importAllLocalesFromLocalFolders.js +7 -7
  142. package/scripts/importDomain.js +131 -131
  143. package/scripts/keys/addOidcToDomain.cjs +9 -9
  144. package/scripts/landUseGame/export3Ddata.js +15 -15
  145. package/scripts/listLanguagesForGroup.js +6 -6
  146. package/scripts/loadTestCreateDummyContentForGroup.js +2 -2
  147. package/scripts/makeRecursiveMapData.js +4 -4
  148. package/scripts/mapping/community_map_csv.js +5 -5
  149. package/scripts/moveCommunityToDomain.js +3 -3
  150. package/scripts/moveGroupToCommunity.js +3 -3
  151. package/scripts/movePostToGroup.js +5 -5
  152. package/scripts/movePostsToGroupsRecountGroupFromUrl.js +6 -6
  153. package/scripts/oldMovePostToGroup.js +9 -9
  154. package/scripts/processCsvForPdfUrls.js +2 -2
  155. package/scripts/processCsvForTranslationAndToxicity.js +10 -10
  156. package/scripts/recount/recount_recursive_communities.js +6 -6
  157. package/scripts/recountALLCommunityGroupCounts.js +4 -4
  158. package/scripts/recountAll.js +3 -3
  159. package/scripts/recountCommunitesFromUrl.js +3 -3
  160. package/scripts/recountCommunity.js +2 -2
  161. package/scripts/recountGroup.js +5 -5
  162. package/scripts/recountGroupNoUserChange.js +5 -5
  163. package/scripts/resetAllEndorsementsForGroup.js +3 -3
  164. package/scripts/resetEnTranslationForGroup.js +5 -5
  165. package/scripts/setAdminOnAll.cjs +14 -14
  166. package/scripts/setDomainAdmin.cjs +6 -6
  167. package/scripts/setDomainLocales.js +2 -2
  168. package/scripts/setEarlQuestionIdOnGroup.cjs +4 -4
  169. package/scripts/setLanguageOnGroupCommunitesFromUrl.js +3 -3
  170. package/scripts/setMemberOfAll.js +14 -14
  171. package/scripts/setNewUserForContentOfCommunity.js +9 -9
  172. package/scripts/setOfficialStatusOnAllPostsForCommunity.js +1 -1
  173. package/scripts/setUserOnAll.js +14 -14
  174. package/scripts/showCategoryForGroup.js +1 -1
  175. package/scripts/showOldActivityTypes.js +3 -3
  176. package/scripts/showPostsMissingCategoryForGroup.js +2 -2
  177. package/scripts/showStatuses.js +4 -4
  178. package/scripts/showUniqueVotersInCommunity.js +4 -4
  179. package/scripts/showUserAgentsAndIpsForEmails.js +4 -4
  180. package/scripts/simpleExportForGroupsForCommunity.js +5 -5
  181. package/scripts/simpleExportForPointsForCommunity.js +5 -5
  182. package/scripts/simpleExportForPostsForCommunity.js +5 -5
  183. package/scripts/testForEndorsments.js +4 -4
  184. package/scripts/undeleteGroupAndAllContent.js +8 -8
  185. package/scripts/undeletePost.js +7 -7
  186. package/scripts/unlinkSsn.js +4 -4
  187. package/scripts/updateFromAlthingi.js +8 -8
  188. package/scripts/users/createUserAddDomain.js +6 -5
  189. package/scripts/users/importUsersForDomainsFromXls.js +4 -3
  190. package/scripts/users/listDomainUsersWithSsn.js +6 -5
  191. package/scripts/users/removeUserFromDomain.js +6 -5
  192. package/scripts/users/updatePasswordFromSsn.js +5 -4
  193. package/scripts/users/updateUserSsnFromEmail.js +5 -4
  194. package/services/controllers/activities.cjs +1 -1
  195. package/services/controllers/news_feeds.cjs +1 -1
  196. package/services/controllers/notifications.cjs +1 -1
  197. package/services/controllers/recommendations.cjs +1 -1
  198. package/services/engine/allOurIdeas/aiHelper.js +10 -9
  199. package/services/engine/analytics/export_anon_community_activities.js +3 -3
  200. package/services/engine/analytics/importer.js +10 -10
  201. package/services/engine/analytics/plausible/manager.cjs +4 -4
  202. package/services/engine/analytics/statsCalc.cjs +1 -1
  203. package/services/engine/analytics/utils.cjs +10 -10
  204. package/services/engine/moderation/fraud/CreateFraudAuditReport.cjs +2 -1
  205. package/services/engine/moderation/fraud/FraudBase.cjs +2 -2
  206. package/services/engine/moderation/fraud/FraudDeleteBase.cjs +4 -4
  207. package/services/engine/moderation/fraud/FraudGetBase.cjs +1 -1
  208. package/services/engine/moderation/fraud/FraudGetEndorsements.cjs +1 -1
  209. package/services/engine/moderation/fraud/FraudGetPointQualities.cjs +1 -1
  210. package/services/engine/moderation/fraud/FraudGetPoints.cjs +1 -1
  211. package/services/engine/moderation/fraud/FraudGetPosts.cjs +1 -1
  212. package/services/engine/moderation/fraud/FraudGetRatings.cjs +1 -1
  213. package/services/engine/moderation/fraud/FraudScannerNotifier.cjs +9 -9
  214. package/services/engine/moderation/get_moderation_items.cjs +1 -1
  215. package/services/engine/moderation/image_labeling/ImageLabelingBase.cjs +1 -1
  216. package/services/engine/moderation/process_moderation_items.cjs +1 -1
  217. package/services/engine/moderation/toxicity_analysis.cjs +1 -1
  218. package/services/engine/news_feeds/generate_dynamically.cjs +1 -1
  219. package/services/engine/news_feeds/generate_from_notifications.cjs +1 -1
  220. package/services/engine/notifications/emails_utils.cjs +2 -2
  221. package/services/engine/notifications/generate_point_notifications.cjs +1 -1
  222. package/services/engine/notifications/generate_post_notifications.cjs +1 -1
  223. package/services/engine/notifications/process_delayed_notifications.cjs +38 -38
  224. package/services/engine/old/exporters/categories_dataset.js +11 -11
  225. package/services/engine/old/exporters/sentiment_dataset.js +12 -12
  226. package/services/engine/recommendations/events_importer.cjs +5 -5
  227. package/services/engine/recommendations/events_manager.cjs +1 -1
  228. package/services/engine/reports/add_points_to_sheet.cjs +2 -2
  229. package/services/engine/reports/commonUtils.js +3 -2
  230. package/services/engine/reports/common_utils.cjs +8 -8
  231. package/services/engine/reports/docx_group_report.cjs +1 -1
  232. package/services/engine/reports/xlsAllOurIdeasExport.js +16 -15
  233. package/services/engine/reports/xls_community_users_report.cjs +2 -2
  234. package/services/engine/reports/xls_group_report.cjs +1 -1
  235. package/services/llms/baseChatBot.js +12 -11
  236. package/services/llms/imageGeneration/chatGptImageGenerator.js +3 -2
  237. package/services/llms/imageGeneration/collectionImageGenerator.js +7 -6
  238. package/services/llms/imageGeneration/dalleImageGenerator.js +6 -5
  239. package/services/llms/imageGeneration/fluxImageGenerator.js +5 -4
  240. package/services/llms/imageGeneration/imageProcessorService.js +2 -1
  241. package/services/llms/imageGeneration/imagenImageGenerator.js +8 -7
  242. package/services/llms/imageGeneration/s3Service.js +12 -11
  243. package/services/llms/llmTranslation.js +30 -29
  244. package/services/models/ac_activity.cjs +1 -1
  245. package/services/models/ac_notification.cjs +1 -1
  246. package/services/models/ac_translation_cache.cjs +11 -11
  247. package/services/scripts/analytics/setup_all_plausible_goals.cjs +2 -2
  248. package/services/scripts/fix_old_delayed_notifications.js +3 -3
  249. package/services/scripts/kue_status.js +11 -11
  250. package/services/scripts/kue_watch_stuck_jobs.js +6 -6
  251. package/services/scripts/translation_clear_language.js +21 -21
  252. package/services/scripts/translation_delete.js +4 -4
  253. package/services/scripts/translation_replace_text_from_url.js +4 -4
  254. package/services/scripts/translation_update.js +4 -4
  255. package/services/scripts/translations_list.js +5 -5
  256. package/services/utils/airbrake.cjs +2 -1
  257. package/services/utils/redisConnection.cjs +6 -5
  258. package/services/utils/translation_helpers.cjs +3 -2
  259. package/services/utils/updateAllLocalesFromEn.js +20 -19
  260. package/services/utils/updateLocaleFolders.js +7 -6
  261. package/services/workers/activity.cjs +1 -1
  262. package/services/workers/anonymizations.cjs +1 -1
  263. package/services/workers/bulk_status_update.cjs +2 -2
  264. package/services/workers/delayed_jobs.cjs +1 -1
  265. package/services/workers/deletions.cjs +1 -1
  266. package/services/workers/email.cjs +1 -1
  267. package/services/workers/fraud_management.cjs +3 -3
  268. package/services/workers/generativeAi.js +6 -5
  269. package/services/workers/main.cjs +1 -1
  270. package/services/workers/marketing.cjs +1 -1
  271. package/services/workers/moderation.cjs +1 -1
  272. package/services/workers/notification_delivery.cjs +1 -1
  273. package/services/workers/notification_news_feed.cjs +1 -1
  274. package/services/workers/queue.cjs +2 -2
  275. package/services/workers/recount.cjs +1 -1
  276. package/services/workers/reports.cjs +1 -1
  277. package/services/workers/similarities.cjs +4 -2
  278. package/services/workers/speech_to_text.cjs +1 -1
  279. package/utils/airbrake.cjs +1 -1
  280. package/utils/cjsCodeReview.js +7 -6
  281. package/utils/community_mapping_tools.cjs +2 -2
  282. package/utils/copy_utils.cjs +31 -31
  283. package/utils/export_utils.cjs +7 -7
  284. package/utils/generateDocumentation.js +10 -9
  285. package/utils/logger.cjs +2 -23
  286. package/utils/logger.d.cts +1 -1
  287. package/utils/loggerAirbrakeTransport.cjs +52 -0
  288. package/utils/loggerAirbrakeTransport.d.cts +15 -0
  289. package/utils/loggerAirbrakeTransportTs.d.ts +15 -0
  290. package/utils/loggerAirbrakeTransportTs.js +45 -0
  291. package/utils/loggerCore.cjs +29 -0
  292. package/utils/loggerCore.d.cts +2 -0
  293. package/utils/loggerCoreTs.d.ts +2 -0
  294. package/utils/loggerCoreTs.js +23 -0
  295. package/utils/loggerTs.d.ts +1 -2
  296. package/utils/loggerTs.js +2 -25
  297. package/utils/recount_utils.cjs +5 -5
  298. package/utils/seedModels.js +50 -49
  299. package/utils/sitemap_generator.cjs +4 -4
  300. package/utils/ypLanguages.js +2 -2
  301. package/webSockets.js +8 -7
  302. package/services/utils/logger.cjs +0 -25
  303. package/services/utils/logger.d.cts +0 -2
  304. package/src/agents/assistants/assistant.d.ts +0 -156
  305. package/src/controllers/audios.d.ts +0 -5
  306. package/src/controllers/categories.d.ts +0 -5
  307. package/src/controllers/communities.d.ts +0 -5
  308. package/src/controllers/domains.d.ts +0 -5
  309. package/src/controllers/groups.d.ts +0 -5
  310. package/src/controllers/images.d.ts +0 -5
  311. package/src/controllers/points.d.ts +0 -5
  312. package/src/controllers/posts.d.ts +0 -5
  313. package/src/controllers/ratings.d.ts +0 -5
  314. package/src/controllers/users.d.ts +0 -5
  315. package/src/controllers/videos.d.ts +0 -5
  316. package/src/models/index.d.ts +0 -84
  317. package/src/services/controllers/activities.d.ts +0 -5
  318. package/src/services/controllers/notifications.d.ts +0 -5
  319. package/src/utils/copy_utils.d.ts +0 -4
  320. package/src/utils/manifest_generator.d.ts +0 -18
@@ -1,6 +1,7 @@
1
1
  import express from "express";
2
2
  import { marked } from "marked";
3
3
  import HTMLtoDOCX from "html-to-docx";
4
+ import log from "../../utils/loggerTs.js";
4
5
  import auth from "../../authorization.cjs";
5
6
  import { YpAgentAssistant } from "../assistants/agentAssistant.js";
6
7
  import { YpAgentProductBundle } from "../models/agentProductBundle.js";
@@ -33,7 +34,7 @@ export class AssistantController {
33
34
  this.voiceAssistantInstances = new Map();
34
35
  this.initializeModels = async () => {
35
36
  try {
36
- console.log(`All Models Loaded Init`);
37
+ log.info(`All Models Loaded Init`);
37
38
  // Call associate method to set up associations
38
39
  for (const modelName of Object.keys(models)) {
39
40
  if (models[modelName].associate) {
@@ -41,10 +42,10 @@ export class AssistantController {
41
42
  //await models[modelName].associate(models);
42
43
  }
43
44
  }
44
- console.log("All agentmodels initialized successfully.");
45
+ log.info("All agentmodels initialized successfully.");
45
46
  }
46
47
  catch (error) {
47
- console.error("Error initializing models:", error);
48
+ log.error("Error initializing models:", error);
48
49
  process.exit(1);
49
50
  }
50
51
  };
@@ -57,28 +58,28 @@ export class AssistantController {
57
58
  }
58
59
  const regex = /<markdownReport>([\s\S]*?)<\/markdownReport>/i;
59
60
  const match = lastStatusMessage ? lastStatusMessage.match(regex) : null;
60
- console.debug(`match: ${JSON.stringify(match, null, 2)}`);
61
+ log.debug(`match: ${JSON.stringify(match, null, 2)}`);
61
62
  if (!match || match.length < 2) {
62
- console.error("No <markdownReport>...</markdownReport> content found.");
63
+ log.error("No <markdownReport>...</markdownReport> content found.");
63
64
  res
64
65
  .status(400)
65
66
  .send("No <markdownReport>...</markdownReport> content found.");
66
67
  }
67
68
  const markdownContent = match ? match[1] : null;
68
69
  if (!markdownContent) {
69
- console.error("No markdown content found.");
70
+ log.error("No markdown content found.");
70
71
  res.status(400).send("No markdown content found.");
71
72
  return;
72
73
  }
73
74
  const htmlContent = await marked(markdownContent);
74
75
  const docxBuffer = (await HTMLtoDOCX(htmlContent));
75
- console.debug(`docxBuffer: ${docxBuffer.length}`);
76
+ log.debug(`docxBuffer: ${docxBuffer.length}`);
76
77
  res.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
77
78
  res.setHeader("Content-disposition", 'attachment; filename="converted.docx"');
78
79
  res.send(docxBuffer);
79
80
  }
80
81
  catch (error) {
81
- console.error("Error converting Markdown to DOCX:", error);
82
+ log.error("Error converting Markdown to DOCX:", error);
82
83
  res.status(500).send("Server error");
83
84
  }
84
85
  };
@@ -91,7 +92,7 @@ export class AssistantController {
91
92
  res.sendStatus(200);
92
93
  }
93
94
  catch (error) {
94
- console.error("Error advancing or stopping workflow:", error);
95
+ log.error("Error advancing or stopping workflow:", error);
95
96
  res.sendStatus(500);
96
97
  }
97
98
  };
@@ -102,7 +103,7 @@ export class AssistantController {
102
103
  res.sendStatus(200);
103
104
  }
104
105
  catch (error) {
105
- console.error("Error starting next workflow step:", error);
106
+ log.error("Error starting next workflow step:", error);
106
107
  res.sendStatus(500);
107
108
  }
108
109
  };
@@ -113,7 +114,7 @@ export class AssistantController {
113
114
  res.sendStatus(200);
114
115
  }
115
116
  catch (error) {
116
- console.error("Error stopping current workflow step:", error);
117
+ log.error("Error stopping current workflow step:", error);
117
118
  res.sendStatus(500);
118
119
  }
119
120
  };
@@ -142,7 +143,7 @@ export class AssistantController {
142
143
  });
143
144
  }
144
145
  catch (error) {
145
- console.error("Error retrieving subscription agent configuration:", error);
146
+ log.error("Error retrieving subscription agent configuration:", error);
146
147
  res.status(500).json({ error: error.message });
147
148
  }
148
149
  };
@@ -174,7 +175,7 @@ export class AssistantController {
174
175
  res.send({ workflow: agentRun?.workflow, status: agentRun?.status });
175
176
  }
176
177
  catch (error) {
177
- console.error("Error getting updated workflow:", error);
178
+ log.error("Error getting updated workflow:", error);
178
179
  res.sendStatus(500);
179
180
  }
180
181
  };
@@ -186,12 +187,12 @@ export class AssistantController {
186
187
  res.sendStatus(200);
187
188
  }
188
189
  catch (error) {
189
- console.error("Error starting agent:", error);
190
+ log.error("Error starting agent:", error);
190
191
  res.sendStatus(500);
191
192
  }
192
193
  };
193
194
  this.submitAgentConfiguration = async (req, res) => {
194
- console.log(`submitAgentConfiguration: ${JSON.stringify(req.body, null, 2)}`);
195
+ log.info(`submitAgentConfiguration: ${JSON.stringify(req.body, null, 2)}`);
195
196
  const { requiredQuestionsAnswers } = req.body;
196
197
  const subscriptionId = parseInt(req.params.subscriptionId);
197
198
  try {
@@ -213,7 +214,7 @@ export class AssistantController {
213
214
  await subscription.save();
214
215
  }
215
216
  catch (error) {
216
- console.error("Error saving subscription:", error);
217
+ log.error("Error saving subscription:", error);
217
218
  res.sendStatus(500);
218
219
  }
219
220
  res.sendStatus(200);
@@ -233,7 +234,7 @@ export class AssistantController {
233
234
  res.sendStatus(200);
234
235
  }
235
236
  catch (error) {
236
- console.error("Error updating login status:", error);
237
+ log.error("Error updating login status:", error);
237
238
  res.sendStatus(500);
238
239
  }
239
240
  };
@@ -268,12 +269,12 @@ export class AssistantController {
268
269
  });
269
270
  }
270
271
  else {
271
- console.warn("No user found to clear runs for");
272
+ log.warn("No user found to clear runs for");
272
273
  }
273
274
  res.sendStatus(200);
274
275
  }
275
276
  catch (error) {
276
- console.error("Error clearing chat log:", error);
277
+ log.error("Error clearing chat log:", error);
277
278
  res.sendStatus(500);
278
279
  }
279
280
  };
@@ -281,7 +282,7 @@ export class AssistantController {
281
282
  const memory = await this.loadMemoryWithOwnership(req, res);
282
283
  if (!memory)
283
284
  return;
284
- console.log(`Getting memory at key: ${memory.redisKey}`);
285
+ log.info(`Getting memory at key: ${memory.redisKey}`);
285
286
  res.json(memory);
286
287
  };
287
288
  // New API endpoints for workflow management
@@ -299,7 +300,7 @@ export class AssistantController {
299
300
  });
300
301
  }
301
302
  catch (error) {
302
- console.error("Error retrieving running workflows:", error);
303
+ log.error("Error retrieving running workflows:", error);
303
304
  res.status(500).json({ error: error.message });
304
305
  }
305
306
  };
@@ -317,7 +318,7 @@ export class AssistantController {
317
318
  });
318
319
  }
319
320
  catch (error) {
320
- console.error("Error retrieving all workflows:", error);
321
+ log.error("Error retrieving all workflows:", error);
321
322
  res.status(500).json({ error: error.message });
322
323
  }
323
324
  };
@@ -336,7 +337,7 @@ export class AssistantController {
336
337
  });
337
338
  }
338
339
  catch (error) {
339
- console.error("Error connecting to workflow conversation:", error);
340
+ log.error("Error connecting to workflow conversation:", error);
340
341
  res.status(500).json({ error: error.message });
341
342
  }
342
343
  };
@@ -379,10 +380,10 @@ export class AssistantController {
379
380
  const callerLine = stackTrace?.split("\n")[2]; // First line is Error, second is current function, third is caller
380
381
  const callerMatch = callerLine?.match(/at\s+(.*)\s+\(/);
381
382
  const caller = callerMatch ? callerMatch[1] : "unknown";
382
- console.debug(`loadMemoryWithOwnership called by: ${caller}`);
383
- console.debug(`loadMemoryWithOwnership: ${JSON.stringify(req.body, null, 2)}`);
383
+ log.debug(`loadMemoryWithOwnership called by: ${caller}`);
384
+ log.debug(`loadMemoryWithOwnership: ${JSON.stringify(req.body, null, 2)}`);
384
385
  const redisKey = this.getMemoryRedisKey(req);
385
- console.debug(`loadMemoryWithOwnership: redisKey: ${redisKey}`);
386
+ log.debug(`loadMemoryWithOwnership: redisKey: ${redisKey}`);
386
387
  try {
387
388
  const rawMemory = await req.redisClient.get(redisKey);
388
389
  let memory = rawMemory
@@ -390,7 +391,7 @@ export class AssistantController {
390
391
  : null;
391
392
  // If no memory, create new
392
393
  if (!memory) {
393
- console.debug(`loadMemoryWithOwnership: creating new memory`);
394
+ log.debug(`loadMemoryWithOwnership: creating new memory`);
394
395
  memory = {
395
396
  redisKey,
396
397
  chatLog: [],
@@ -401,40 +402,40 @@ export class AssistantController {
401
402
  ownerUserId: null,
402
403
  };
403
404
  if (req.user) {
404
- console.debug(`loadMemoryWithOwnership: setting ownerUserId to ${req.user.id}`);
405
+ log.debug(`loadMemoryWithOwnership: setting ownerUserId to ${req.user.id}`);
405
406
  memory.ownerUserId = req.user.id;
406
407
  }
407
408
  else {
408
- console.debug(`loadMemoryWithOwnership: no user in request`);
409
+ log.debug(`loadMemoryWithOwnership: no user in request`);
409
410
  }
410
411
  await req.redisClient.set(redisKey, JSON.stringify(memory));
411
412
  const rawAfterSet = await req.redisClient.get(redisKey);
412
- console.log("loadMemoryWithOwnership: After set, raw in Redis is:", rawAfterSet);
413
- console.debug(`loadMemoryWithOwnership: returning new memory`);
413
+ log.info("loadMemoryWithOwnership: After set, raw in Redis is:", rawAfterSet);
414
+ log.debug(`loadMemoryWithOwnership: returning new memory`);
414
415
  return memory;
415
416
  }
416
417
  else {
417
- console.debug(`loadMemoryWithOwnership: memory already exists`);
418
- console.debug(`loadMemoryWithOwnership: memory: ${JSON.stringify(memory, null, 2)}`);
418
+ log.debug(`loadMemoryWithOwnership: memory already exists`);
419
+ log.debug(`loadMemoryWithOwnership: memory: ${JSON.stringify(memory, null, 2)}`);
419
420
  }
420
421
  // If memory is owned by someone
421
422
  if (memory.ownerUserId !== null) {
422
- console.debug(`loadMemoryWithOwnership: memory is owned by ${memory.ownerUserId}`);
423
+ log.debug(`loadMemoryWithOwnership: memory is owned by ${memory.ownerUserId}`);
423
424
  if (!req.user) {
424
- console.debug(`loadMemoryWithOwnership: no user in request`);
425
+ log.debug(`loadMemoryWithOwnership: no user in request`);
425
426
  res.status(401).json({ error: "Unauthorized" });
426
427
  return;
427
428
  }
428
429
  else {
429
- console.debug(`loadMemoryWithOwnership: user in request`);
430
+ log.debug(`loadMemoryWithOwnership: user in request`);
430
431
  }
431
432
  if (memory.ownerUserId !== req.user.id) {
432
- console.debug(`loadMemoryWithOwnership: ownerUserId does not match ${memory.ownerUserId} !== ${req.user.id}`);
433
+ log.debug(`loadMemoryWithOwnership: ownerUserId does not match ${memory.ownerUserId} !== ${req.user.id}`);
433
434
  res.status(403).json({ error: "Forbidden" });
434
435
  return;
435
436
  }
436
437
  else {
437
- console.debug(`loadMemoryWithOwnership: ownerUserId matches ${memory.ownerUserId} === ${req.user.id}`);
438
+ log.debug(`loadMemoryWithOwnership: ownerUserId matches ${memory.ownerUserId} === ${req.user.id}`);
438
439
  }
439
440
  // Same user => fine
440
441
  return memory;
@@ -445,16 +446,16 @@ export class AssistantController {
445
446
  // optionally upgrade
446
447
  memory.ownerUserId = req.user.id;
447
448
  await req.redisClient.set(redisKey, JSON.stringify(memory));
448
- console.debug(`loadMemoryWithOwnership: returning memory with ownerUserId ${memory.ownerUserId}`);
449
+ log.debug(`loadMemoryWithOwnership: returning memory with ownerUserId ${memory.ownerUserId}`);
449
450
  }
450
451
  else {
451
- console.debug(`loadMemoryWithOwnership: returning memory with ownerUserId null`);
452
+ log.debug(`loadMemoryWithOwnership: returning memory with ownerUserId null`);
452
453
  }
453
454
  return memory;
454
455
  }
455
456
  }
456
457
  catch (error) {
457
- console.error("Error loading memory:", error);
458
+ log.error("Error loading memory:", error);
458
459
  res.status(500).json({ error: "Internal server error" });
459
460
  return;
460
461
  }
@@ -465,7 +466,7 @@ export class AssistantController {
465
466
  const memory = await this.loadMemoryWithOwnership(req, res);
466
467
  if (!memory)
467
468
  return;
468
- console.log(`Starting chat session for client: ${wsClientId}`);
469
+ log.info(`Starting chat session for client: ${wsClientId}`);
469
470
  let oldVoiceAssistant = this.voiceAssistantInstances.get("voiceAssistant");
470
471
  if (oldVoiceAssistant) {
471
472
  oldVoiceAssistant.destroy();
@@ -485,7 +486,7 @@ export class AssistantController {
485
486
  });
486
487
  }
487
488
  catch (error) {
488
- console.error("Error starting voice session:", error);
489
+ log.error("Error starting voice session:", error);
489
490
  res.status(500).json({ error: "Internal server error" });
490
491
  }
491
492
  }
@@ -514,7 +515,7 @@ export class AssistantController {
514
515
  });
515
516
  }
516
517
  catch (error) {
517
- console.error("Error starting chat session:", error);
518
+ log.error("Error starting chat session:", error);
518
519
  res.status(500).json({ error: "Internal server error" });
519
520
  }
520
521
  }
@@ -41,6 +41,8 @@ export declare class PolicySynthAgentsController {
41
41
  controlAgent: (req: express.Request, res: express.Response) => Promise<void>;
42
42
  getAgentStatus: (req: express.Request, res: express.Response) => Promise<void>;
43
43
  updateAgentStatus: (req: express.Request, res: express.Response) => Promise<void>;
44
+ private recursiveDeleteAgent;
45
+ deleteAgent: (req: YpRequest, res: express.Response) => Promise<void>;
44
46
  startAgentProcessing: (req: express.Request, res: express.Response) => Promise<void>;
45
47
  pauseAgentProcessing: (req: express.Request, res: express.Response) => Promise<void>;
46
48
  getAgentCosts: (req: express.Request, res: express.Response) => Promise<void>;
@@ -6,6 +6,8 @@ import { AgentConnectorManager } from "@policysynth/agents/operations/agentConne
6
6
  import { AgentRegistryManager } from "@policysynth/agents/operations/agentRegistryManager.js";
7
7
  import { PsAiModel } from "@policysynth/agents/dbModels/aiModel.js";
8
8
  import auth from "../../authorization.cjs";
9
+ import log from "../../utils/loggerTs.js";
10
+ import { PsAgent } from "@policysynth/agents/dbModels/agent.js";
9
11
  import { NewAiModelSetup } from "../managers/newAiModelSetup.js";
10
12
  export class PolicySynthAgentsController {
11
13
  constructor(wsClients) {
@@ -15,9 +17,9 @@ export class PolicySynthAgentsController {
15
17
  try {
16
18
  const { groupId, agentId } = req.params;
17
19
  const memory = req.body;
18
- console.log(`Attempting to replace memory for agent ${agentId} in group ${groupId}`);
20
+ log.info(`Attempting to replace memory for agent ${agentId} in group ${groupId}`);
19
21
  if (!memory || Object.keys(memory).length === 0) {
20
- console.log(`Received empty memory for agent ${agentId}`);
22
+ log.info(`Received empty memory for agent ${agentId}`);
21
23
  res.status(400).json({ error: "Cannot save empty memory" });
22
24
  return;
23
25
  }
@@ -25,25 +27,25 @@ export class PolicySynthAgentsController {
25
27
  JSON.parse(JSON.stringify(memory));
26
28
  }
27
29
  catch (jsonError) {
28
- console.log(`Received invalid JSON for agent ${agentId}`);
30
+ log.info(`Received invalid JSON for agent ${agentId}`);
29
31
  res.status(400).json({ error: "Invalid JSON format for memory" });
30
32
  return;
31
33
  }
32
34
  const memoryKey = await this.agentManager.getSubAgentMemoryKey(groupId, parseInt(agentId));
33
35
  if (!memoryKey) {
34
- console.log(`Memory key not found for agent ${agentId}`);
36
+ log.info(`Memory key not found for agent ${agentId}`);
35
37
  res
36
38
  .status(404)
37
39
  .json({ error: "Memory key not found for the specified agent" });
38
40
  return;
39
41
  }
40
- console.log(`Memory key found: ${memoryKey}`);
42
+ log.info(`Memory key found: ${memoryKey}`);
41
43
  await req.redisClient.set(memoryKey, JSON.stringify(memory));
42
- console.log(`Memory contents replaced successfully`);
44
+ log.info(`Memory contents replaced successfully`);
43
45
  res.json({ message: "Memory replaced successfully" });
44
46
  }
45
47
  catch (error) {
46
- console.error("Error replacing agent memory:", error);
48
+ log.error("Error replacing agent memory:", error);
47
49
  if (error instanceof Error) {
48
50
  res.status(500).json({ error: error.message });
49
51
  }
@@ -81,7 +83,7 @@ export class PolicySynthAgentsController {
81
83
  });
82
84
  }
83
85
  catch (error) {
84
- console.error(`Error adding existing ${connectorId} connector:`, error);
86
+ log.error(`Error adding existing ${connectorId} connector:`, error);
85
87
  if (error instanceof Error) {
86
88
  res.status(500).json({ error: error.message });
87
89
  }
@@ -93,28 +95,28 @@ export class PolicySynthAgentsController {
93
95
  this.getAgentMemory = async (req, res) => {
94
96
  try {
95
97
  const { groupId, agentId } = req.params;
96
- console.log(`Attempting to get memory for agent ${agentId} in group ${groupId}`);
98
+ log.info(`Attempting to get memory for agent ${agentId} in group ${groupId}`);
97
99
  const memoryKey = await this.agentManager.getSubAgentMemoryKey(groupId, parseInt(agentId));
98
100
  if (!memoryKey) {
99
- console.log(`Memory key not found for agent ${agentId}`);
101
+ log.info(`Memory key not found for agent ${agentId}`);
100
102
  res
101
103
  .status(404)
102
104
  .json({ error: "Memory key not found for the specified agent" });
103
105
  return;
104
106
  }
105
- console.log(`Memory key found: ${memoryKey}`);
107
+ log.info(`Memory key found: ${memoryKey}`);
106
108
  const memoryContents = await req.redisClient.get(memoryKey);
107
109
  if (!memoryContents) {
108
- console.log(`Memory contents not found for key ${memoryKey}`);
110
+ log.info(`Memory contents not found for key ${memoryKey}`);
109
111
  res.status(404).json({ error: "Memory contents not found" });
110
112
  return;
111
113
  }
112
- console.log(`Memory contents retrieved successfully`);
114
+ log.info(`Memory contents retrieved successfully`);
113
115
  const parsedMemoryContents = JSON.parse(memoryContents);
114
116
  res.json(parsedMemoryContents);
115
117
  }
116
118
  catch (error) {
117
- console.error("Error retrieving agent memory:", error);
119
+ log.error("Error retrieving agent memory:", error);
118
120
  if (error instanceof Error) {
119
121
  res.status(500).json({ error: error.message });
120
122
  }
@@ -130,7 +132,7 @@ export class PolicySynthAgentsController {
130
132
  res.json(agent);
131
133
  }
132
134
  catch (error) {
133
- console.error("Error in getAgent:", error);
135
+ log.error("Error in getAgent:", error);
134
136
  res.status(500).send("Internal Server Error");
135
137
  return;
136
138
  }
@@ -141,7 +143,7 @@ export class PolicySynthAgentsController {
141
143
  res.json(aiModels);
142
144
  }
143
145
  catch (error) {
144
- console.error("Error fetching agent AI models:", error);
146
+ log.error("Error fetching agent AI models:", error);
145
147
  res.status(500).send("Internal Server Error");
146
148
  }
147
149
  };
@@ -151,7 +153,7 @@ export class PolicySynthAgentsController {
151
153
  res.json({ message: "AI model removed successfully" });
152
154
  }
153
155
  catch (error) {
154
- console.error("Error removing agent AI model:", error);
156
+ log.error("Error removing agent AI model:", error);
155
157
  res.status(500).send("Internal Server Error");
156
158
  }
157
159
  };
@@ -162,7 +164,7 @@ export class PolicySynthAgentsController {
162
164
  res.status(201).json({ message: "AI model added successfully" });
163
165
  }
164
166
  catch (error) {
165
- console.error("Error adding agent AI model:", error);
167
+ log.error("Error adding agent AI model:", error);
166
168
  res.status(500).send("Internal Server Error");
167
169
  }
168
170
  };
@@ -184,7 +186,7 @@ export class PolicySynthAgentsController {
184
186
  res.json({ message: `${nodeType} configuration updated successfully` });
185
187
  }
186
188
  catch (error) {
187
- console.error(`Error updating ${nodeType} configuration:`, error);
189
+ log.error(`Error updating ${nodeType} configuration:`, error);
188
190
  res.status(500).send("Internal Server Error");
189
191
  return;
190
192
  }
@@ -208,7 +210,7 @@ export class PolicySynthAgentsController {
208
210
  res.status(201).json(createdConnector);
209
211
  }
210
212
  catch (error) {
211
- console.error(`Error creating ${type} connector:`, error);
213
+ log.error(`Error creating ${type} connector:`, error);
212
214
  res.status(500).send("Internal Server Error");
213
215
  }
214
216
  };
@@ -220,7 +222,7 @@ export class PolicySynthAgentsController {
220
222
  res.json(activeAiModels);
221
223
  }
222
224
  catch (error) {
223
- console.error("Error fetching active AI models:", error);
225
+ log.error("Error fetching active AI models:", error);
224
226
  res.status(500).send("Internal Server Error");
225
227
  }
226
228
  };
@@ -230,7 +232,7 @@ export class PolicySynthAgentsController {
230
232
  res.json(activeAgentClasses);
231
233
  }
232
234
  catch (error) {
233
- console.error("Error fetching active agent classes:", error);
235
+ log.error("Error fetching active agent classes:", error);
234
236
  if (error instanceof Error) {
235
237
  res.status(500).send(`Internal Server Error: ${error.message}`);
236
238
  }
@@ -245,7 +247,7 @@ export class PolicySynthAgentsController {
245
247
  res.json(activeConnectorClasses);
246
248
  }
247
249
  catch (error) {
248
- console.error("Error fetching active connector classes:", error);
250
+ log.error("Error fetching active connector classes:", error);
249
251
  res.status(500).send("Internal Server Error");
250
252
  }
251
253
  };
@@ -256,7 +258,7 @@ export class PolicySynthAgentsController {
256
258
  res.status(201).json(createdAgent);
257
259
  }
258
260
  catch (error) {
259
- console.error("Error creating agent:", error);
261
+ log.error("Error creating agent:", error);
260
262
  if (error instanceof Error) {
261
263
  res.status(400).send(error.message);
262
264
  }
@@ -273,7 +275,7 @@ export class PolicySynthAgentsController {
273
275
  res.json({ message });
274
276
  }
275
277
  catch (error) {
276
- console.error(`Error ${action}ing agent:`, error);
278
+ log.error(`Error ${action}ing agent:`, error);
277
279
  if (error instanceof Error) {
278
280
  res.status(500).json({ error: error.message });
279
281
  }
@@ -294,7 +296,7 @@ export class PolicySynthAgentsController {
294
296
  }
295
297
  }
296
298
  catch (error) {
297
- console.error("Error getting agent status:", error);
299
+ log.error("Error getting agent status:", error);
298
300
  res.status(500).send("Internal Server Error");
299
301
  }
300
302
  };
@@ -311,10 +313,26 @@ export class PolicySynthAgentsController {
311
313
  }
312
314
  }
313
315
  catch (error) {
314
- console.error("Error updating agent status:", error);
316
+ log.error("Error updating agent status:", error);
315
317
  res.status(500).send("Internal Server Error");
316
318
  }
317
319
  };
320
+ this.deleteAgent = async (req, res) => {
321
+ try {
322
+ const agentId = parseInt(req.params.agentId);
323
+ await this.recursiveDeleteAgent(agentId);
324
+ res.json({ message: "Agent deleted" });
325
+ }
326
+ catch (error) {
327
+ log.error("Error deleting agent:", error);
328
+ if (error instanceof Error) {
329
+ res.status(500).json({ error: error.message });
330
+ }
331
+ else {
332
+ res.status(500).json({ error: "An unexpected error occurred" });
333
+ }
334
+ }
335
+ };
318
336
  this.startAgentProcessing = async (req, res) => {
319
337
  const agentId = parseInt(req.params.id);
320
338
  try {
@@ -327,7 +345,7 @@ export class PolicySynthAgentsController {
327
345
  }
328
346
  }
329
347
  catch (error) {
330
- console.error("Error starting agent processing:", error);
348
+ log.error("Error starting agent processing:", error);
331
349
  res.status(500).send("Internal Server Error");
332
350
  }
333
351
  };
@@ -343,7 +361,7 @@ export class PolicySynthAgentsController {
343
361
  }
344
362
  }
345
363
  catch (error) {
346
- console.error("Error pausing agent processing:", error);
364
+ log.error("Error pausing agent processing:", error);
347
365
  res.status(500).send("Internal Server Error");
348
366
  }
349
367
  };
@@ -354,7 +372,7 @@ export class PolicySynthAgentsController {
354
372
  res.json(totalCosts);
355
373
  }
356
374
  catch (error) {
357
- console.error("Error calculating agent costs:", error);
375
+ log.error("Error calculating agent costs:", error);
358
376
  res.status(500).send("Internal Server Error");
359
377
  }
360
378
  };
@@ -365,7 +383,7 @@ export class PolicySynthAgentsController {
365
383
  res.json(costRows);
366
384
  }
367
385
  catch (error) {
368
- console.error("Error calculating agent costs detail:", error);
386
+ log.error("Error calculating agent costs detail:", error);
369
387
  res.status(500).send("Internal Server Error");
370
388
  }
371
389
  };
@@ -409,5 +427,19 @@ export class PolicySynthAgentsController {
409
427
  this.router.get("/:groupId/:agentId/memory", auth.can("edit group"), this.getAgentMemory);
410
428
  this.router.post("/:groupId/:agentId/inputConnectors/existing", auth.can("edit group"), this.addExistingConnector);
411
429
  this.router.post("/:groupId/:agentId/outputConnectors/existing", auth.can("edit group"), this.addExistingConnector);
430
+ this.router.delete("/:groupId/:agentId", auth.can("edit group"), this.deleteAgent);
431
+ }
432
+ async recursiveDeleteAgent(agentId) {
433
+ const agent = await PsAgent.findByPk(agentId, {
434
+ include: [{ model: PsAgent, as: "SubAgents" }],
435
+ });
436
+ if (!agent)
437
+ return;
438
+ if (agent.SubAgents) {
439
+ for (const sub of agent.SubAgents) {
440
+ await this.recursiveDeleteAgent(sub.id);
441
+ }
442
+ }
443
+ await agent.destroy();
412
444
  }
413
445
  }
@@ -8,6 +8,7 @@ const Group = dbModels.Group;
8
8
  const User = dbModels.User;
9
9
  const Community = dbModels.Community;
10
10
  const Domain = dbModels.Domain;
11
+ import log from "../../utils/loggerTs.js";
11
12
  export class AgentInviteManager {
12
13
  /**
13
14
  * Send a notification email to group admins about the current workflow step or completion.
@@ -16,7 +17,7 @@ export class AgentInviteManager {
16
17
  try {
17
18
  const agentRun = await NotificationAgentQueueManager.getAgentRun(agentRunId);
18
19
  if (!agentRun) {
19
- console.error("Agent run not found");
20
+ log.error("Agent run not found");
20
21
  return;
21
22
  }
22
23
  const subject = `${agentRun?.Subscription?.Plan?.AgentProduct?.name} - ${agentRun?.workflow?.steps[agentRun?.workflow?.currentStepIndex]?.shortName} invite`;
@@ -45,10 +46,10 @@ export class AgentInviteManager {
45
46
  link: link,
46
47
  skipHeaderAndFooter: true,
47
48
  }, { priority: "high" });
48
- console.log("AgentInviteManager: Email enqueued successfully");
49
+ log.info("AgentInviteManager: Email enqueued successfully");
49
50
  }
50
51
  catch (error) {
51
- console.error("AgentInviteManager: Error sending notification email", error);
52
+ log.error("AgentInviteManager: Error sending notification email", error);
52
53
  throw error;
53
54
  }
54
55
  }