@yrpri/api 9.0.102 → 9.0.104

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
  2. package/active-citizen/llms/imageGeneration/collectionImageGenerator.js +6 -0
  3. package/agents/controllers/agentProductController.js +2 -1
  4. package/agents/controllers/agentSubscriptionController.js +20 -11
  5. package/agents/controllers/assistantsController.js +28 -18
  6. package/agents/controllers/policySynthAgents.js +33 -12
  7. package/agents/managers/newAiModelSetup.js +96 -0
  8. package/agents/managers/subscriptionManager.js +2 -2
  9. package/app.js +12 -12
  10. package/authorization.cjs +4 -0
  11. package/controllers/allOurIdeas.js +2 -1
  12. package/controllers/communities.cjs +47 -1
  13. package/controllers/groups.cjs +67 -4
  14. package/controllers/index.cjs +7 -7
  15. package/controllers/nonSpa.cjs +1 -1
  16. package/package.json +46 -44
  17. package/server.d.ts +104 -2
  18. package/utils/copy_utils.cjs +7 -1
  19. package/active-citizen/engine/allOurIdeas/aiHelper.d.ts +0 -21
  20. package/active-citizen/engine/allOurIdeas/aiHelper.d.ts.map +0 -1
  21. package/active-citizen/engine/allOurIdeas/explainAnswersAssistant.d.ts.map +0 -1
  22. package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts +0 -12
  23. package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts.map +0 -1
  24. package/active-citizen/engine/analytics/export_anon_community_activities.d.ts.map +0 -1
  25. package/active-citizen/engine/analytics/importer.d.ts.map +0 -1
  26. package/active-citizen/engine/old/exporters/categories_dataset.d.ts.map +0 -1
  27. package/active-citizen/engine/old/exporters/dataset_tools.d.ts.map +0 -1
  28. package/active-citizen/engine/old/exporters/sentiment_dataset.d.ts.map +0 -1
  29. package/active-citizen/engine/reports/xls_all_our_ideas_export.js +0 -141
  30. package/active-citizen/llms/baseChatBot.d.ts +0 -51
  31. package/active-citizen/llms/baseChatBot.d.ts.map +0 -1
  32. package/active-citizen/llms/collectionImageGenerator.js +0 -357
  33. package/active-citizen/llms/llmTranslation.d.ts +0 -24
  34. package/active-citizen/llms/llmTranslation.d.ts.map +0 -1
  35. package/active-citizen/scripts/fix_old_delayed_notifications.d.ts.map +0 -1
  36. package/active-citizen/scripts/kue_status.d.ts.map +0 -1
  37. package/active-citizen/scripts/kue_watch_stuck_jobs.d.ts.map +0 -1
  38. package/active-citizen/scripts/translation_clear_language.d.ts.map +0 -1
  39. package/active-citizen/scripts/translation_delete.d.ts.map +0 -1
  40. package/active-citizen/scripts/translation_replace_text_from_url.d.ts.map +0 -1
  41. package/active-citizen/scripts/translation_update.d.ts.map +0 -1
  42. package/active-citizen/scripts/translations_list.d.ts.map +0 -1
  43. package/active-citizen/utils/airbrake.d.ts.map +0 -1
  44. package/active-citizen/utils/airbrake.js +0 -17
  45. package/active-citizen/utils/updateAllLocalesFromEn.d.ts +0 -21
  46. package/active-citizen/utils/updateAllLocalesFromEn.d.ts.map +0 -1
  47. package/active-citizen/utils/updateLocaleFolders.d.ts +0 -2
  48. package/active-citizen/utils/updateLocaleFolders.d.ts.map +0 -1
  49. package/active-citizen/workers/cloudflare/voiceSession/worker.js +0 -213
  50. package/active-citizen/workers/generativeAi.d.ts.map +0 -1
  51. package/agents/agentProductManager.js +0 -91
  52. package/agents/assistants/agentAssistantOld.js +0 -863
  53. package/agents/assistants/modes/agentConfigurationMode.js +0 -63
  54. package/agents/assistants/modes/agentOperationsMode.js +0 -195
  55. package/agents/assistants/modes/commonTools.js +0 -58
  56. package/agents/assistants/modes/directConversationMode.js +0 -14
  57. package/agents/assistants/modes/toolHandlers/accountHandlers.js +0 -46
  58. package/agents/assistants/modes/toolHandlers/commonHandlers.js +0 -57
  59. package/agents/assistants/modes/toolHandlers/commonTools.js +0 -58
  60. package/agents/assistants/modes/toolHandlers/loginHandlers.js +0 -46
  61. package/agents/assistants/modes/toolHandlers/subscriptionHandlers.js +0 -469
  62. package/agents/assistants/modes/tools/agentConnectionTools.js +0 -326
  63. package/agents/assistants/modes/tools/commonHandlers.js +0 -57
  64. package/agents/assistants/modes/tools/loginHandlers.js +0 -46
  65. package/agents/assistants/modes/tools/subscriptionHandlers.js +0 -469
  66. package/agents/assistants/modes/tools/workflowConversationTools.js +0 -326
  67. package/agents/assistants/modes/tools/workflowTools.js +0 -112
  68. package/agents/controllers/assistantController.js +0 -243
  69. package/agents/managers/workflowManager.js +0 -76
  70. package/agents/models/testData/setupConfig.js +0 -140
  71. package/agents/models/workflow.js +0 -53
  72. package/agents/models/workflowConverstation.js +0 -53
  73. package/agents/subscriptionManager.js +0 -218
  74. package/agents/tools/updateCommunityWorkflow.js +0 -1
  75. package/agents/tools/updateTemplateWorkflow.js +0 -45
  76. package/app.d.ts +0 -40
  77. package/app.d.ts.map +0 -1
  78. package/bot_control.d.ts.map +0 -1
  79. package/migrations/200824_create_embeddings_and_org_update.cjs +0 -15
  80. package/migrations/270724_createUsersAndAdminsForClasses.cjs +0 -100
  81. package/publish.d.ts.map +0 -1
  82. package/repack.d.ts.map +0 -1
  83. package/scripts/addRatingUsersToGroup.d.ts.map +0 -1
  84. package/scripts/addUserToOrganization.d.ts.map +0 -1
  85. package/scripts/analyseRatingsForCommunity.d.ts.map +0 -1
  86. package/scripts/analyzeAndFixBrokenPointUsers.d.ts.map +0 -1
  87. package/scripts/analyzeEndorsementsByCountry.d.ts.map +0 -1
  88. package/scripts/analyzePostsForCommunity.d.ts.map +0 -1
  89. package/scripts/bulkStatusUpdates/listUpdates.d.ts.map +0 -1
  90. package/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.d.ts.map +0 -1
  91. package/scripts/bulkStatusUpdates/performUpdate.d.ts.map +0 -1
  92. package/scripts/bulkStatusUpdates/performUpdateForGroup.d.ts.map +0 -1
  93. package/scripts/bulkStatusUpdates/performUpdateForGroup.js +0 -125
  94. package/scripts/bulkStatusUpdates/performUpdateForStatus.d.ts.map +0 -1
  95. package/scripts/change/changeVideoAspectTo.d.ts.map +0 -1
  96. package/scripts/change/setDomainAdmin.cjs +0 -45
  97. package/scripts/changeCommunityGroupcount.d.ts.map +0 -1
  98. package/scripts/changeCommunityPostCount.d.ts.map +0 -1
  99. package/scripts/changeGroupPostCount.d.ts.map +0 -1
  100. package/scripts/changeLanguage.d.ts.map +0 -1
  101. package/scripts/changeOfficalStatus.d.ts.map +0 -1
  102. package/scripts/cleanups/deleteAnonNotifications.d.ts.map +0 -1
  103. package/scripts/cleanups/deleteAnonNotifications.js +0 -91
  104. package/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.d.ts.map +0 -1
  105. package/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.d.ts.map +0 -1
  106. package/scripts/clearAllEndorsementInGroup.d.ts.map +0 -1
  107. package/scripts/cloning/clearUsersForCommunitiesFromUrl.d.ts.map +0 -1
  108. package/scripts/cloning/cloneFromUrlScript.d.ts.map +0 -1
  109. package/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
  110. package/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.d.ts.map +0 -1
  111. package/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.d.ts.map +0 -1
  112. package/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.d.ts.map +0 -1
  113. package/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.d.ts.map +0 -1
  114. package/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.d.ts.map +0 -1
  115. package/scripts/cloning/copyCommunityToDomainWithEverything.d.ts.map +0 -1
  116. package/scripts/cloning/copyCommunityToDomainWithOnlyGroups.d.ts.map +0 -1
  117. package/scripts/cloning/copyGroupConfigAndTranslationsFromURL.d.ts.map +0 -1
  118. package/scripts/cloning/copyPostToGroupOld.d.ts.map +0 -1
  119. package/scripts/cloning/copyPostVideosFromURL.d.ts.map +0 -1
  120. package/scripts/cloning/copyPostWithOutAnyVotingOrActivities.d.ts.map +0 -1
  121. package/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
  122. package/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
  123. package/scripts/cloning/setAdminsFromURL.d.ts.map +0 -1
  124. package/scripts/cloning/setExternalIdsFromURL.d.ts.map +0 -1
  125. package/scripts/countCommunity.d.ts.map +0 -1
  126. package/scripts/countCommunityUsers.d.ts.map +0 -1
  127. package/scripts/countDelayedNotifications.d.ts.map +0 -1
  128. package/scripts/countGroup.d.ts.map +0 -1
  129. package/scripts/countStuff.d.ts.map +0 -1
  130. package/scripts/countUniqueVotersInAGroup.d.ts.map +0 -1
  131. package/scripts/createInvitesAndShow.d.ts.map +0 -1
  132. package/scripts/database/seedTestAiModels.js +0 -64
  133. package/scripts/database/sync_database.d.ts.map +0 -1
  134. package/scripts/database/sync_dev_database.d.ts.map +0 -1
  135. package/scripts/debugNotifications.d.ts.map +0 -1
  136. package/scripts/deleteAllNewsFeeds.d.ts.map +0 -1
  137. package/scripts/deleteCategory.d.ts.map +0 -1
  138. package/scripts/deleteOldAppActivities.d.ts.map +0 -1
  139. package/scripts/deletePostContactDataForCommunity.d.ts.map +0 -1
  140. package/scripts/destroy/destroy_all_but_one_domain.d.ts.map +0 -1
  141. package/scripts/displayAuthorForPost.d.ts.map +0 -1
  142. package/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.d.ts.map +0 -1
  143. package/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.d.ts.map +0 -1
  144. package/scripts/exportAllStatusChanges.d.ts.map +0 -1
  145. package/scripts/exportClientAcitivity.d.ts.map +0 -1
  146. package/scripts/exportEndorsementsForCommunity.d.ts.map +0 -1
  147. package/scripts/exportPointQualitiesForCommunity.d.ts.map +0 -1
  148. package/scripts/exportPostsAndPointsForCommunity.d.ts.map +0 -1
  149. package/scripts/exportPostsDataSetForDomain.d.ts.map +0 -1
  150. package/scripts/exportPostsForGroup.d.ts.map +0 -1
  151. package/scripts/exportRatingsForPost.d.ts.map +0 -1
  152. package/scripts/exportUserEndorsementsWithUserAnalysis.d.ts.map +0 -1
  153. package/scripts/exportUsersForCommunity.d.ts.map +0 -1
  154. package/scripts/exportUsersForDomain.d.ts.map +0 -1
  155. package/scripts/exportUsersForGroup.d.ts.map +0 -1
  156. package/scripts/exports/ratingDistribution.d.ts.map +0 -1
  157. package/scripts/exports/whoEndorsedWhatByCommunity.d.ts.map +0 -1
  158. package/scripts/findUnusedClientImports.d.ts.map +0 -1
  159. package/scripts/fixAllPostPointCounts.d.ts.map +0 -1
  160. package/scripts/fixAnonNotificationsSettings.d.ts.map +0 -1
  161. package/scripts/fixCountKopavogur.d.ts.map +0 -1
  162. package/scripts/fixEndorsementsAfterCopyPostToGroup.d.ts.map +0 -1
  163. package/scripts/fixExternalUserId.d.ts.map +0 -1
  164. package/scripts/fixGroupAccess.d.ts.map +0 -1
  165. package/scripts/fixGroupIdeasAndPointsCount.d.ts.map +0 -1
  166. package/scripts/fixNotificationSettings.d.ts.map +0 -1
  167. package/scripts/fixSurveyRadioBakedInSubCodes.d.ts.map +0 -1
  168. package/scripts/fixWrongUserIdForStatusUpdates.d.ts.map +0 -1
  169. package/scripts/gallery/exportGalleryData.d.ts.map +0 -1
  170. package/scripts/gallery/importGalleryForCommunity.d.ts.map +0 -1
  171. package/scripts/gallery/readJsonAndDownloadImagesVersion2.d.ts.map +0 -1
  172. package/scripts/gallery/refreshAcApiPostIdsForCommunity.d.ts.map +0 -1
  173. package/scripts/genderAnalysis.d.ts.map +0 -1
  174. package/scripts/genderAnalysisByStatus.d.ts.map +0 -1
  175. package/scripts/importAllLocalesFromLocalFolders.d.ts.map +0 -1
  176. package/scripts/importDomain.d.ts.map +0 -1
  177. package/scripts/landUseGame/export3Ddata.d.ts.map +0 -1
  178. package/scripts/listLanguagesForGroup.d.ts.map +0 -1
  179. package/scripts/loadTestCreateDummyContentForGroup.d.ts.map +0 -1
  180. package/scripts/makeRecursiveMapData.d.ts.map +0 -1
  181. package/scripts/mapping/community_map_csv.d.ts.map +0 -1
  182. package/scripts/moveCommunityToDomain.d.ts.map +0 -1
  183. package/scripts/moveGroupToCommunity.d.ts.map +0 -1
  184. package/scripts/movePostToGroup.d.ts.map +0 -1
  185. package/scripts/movePostsToGroupsRecountGroupFromUrl.d.ts.map +0 -1
  186. package/scripts/oldMovePostToGroup.d.ts.map +0 -1
  187. package/scripts/processCsvForPdfUrls.d.ts.map +0 -1
  188. package/scripts/processCsvForTranslationAndToxicity.d.ts.map +0 -1
  189. package/scripts/recount/recount_recursive_communities.d.ts.map +0 -1
  190. package/scripts/recountALLCommunityGroupCounts.d.ts.map +0 -1
  191. package/scripts/recountAll.d.ts.map +0 -1
  192. package/scripts/recountCommunitesFromUrl.d.ts.map +0 -1
  193. package/scripts/recountCommunity.d.ts.map +0 -1
  194. package/scripts/recountGroup.d.ts.map +0 -1
  195. package/scripts/recountGroupNoUserChange.d.ts.map +0 -1
  196. package/scripts/resetAllEndorsementsForGroup.d.ts.map +0 -1
  197. package/scripts/resetEnTranslationForGroup.d.ts.map +0 -1
  198. package/scripts/setDomainLocales.d.ts.map +0 -1
  199. package/scripts/setLanguageOnGroupCommunitesFromUrl.d.ts.map +0 -1
  200. package/scripts/setMemberOfAll.d.ts.map +0 -1
  201. package/scripts/setNewUserForContentOfCommunity.d.ts.map +0 -1
  202. package/scripts/setOfficialStatusOnAllPostsForCommunity.d.ts.map +0 -1
  203. package/scripts/setUserOnAll.d.ts.map +0 -1
  204. package/scripts/showCategoryForGroup.d.ts.map +0 -1
  205. package/scripts/showOldActivityTypes.d.ts.map +0 -1
  206. package/scripts/showPostsMissingCategoryForGroup.d.ts.map +0 -1
  207. package/scripts/showStatuses.d.ts.map +0 -1
  208. package/scripts/showUniqueVotersInCommunity.d.ts.map +0 -1
  209. package/scripts/showUserAgentsAndIpsForEmails.d.ts.map +0 -1
  210. package/scripts/simpleExportForGroupsForCommunity.d.ts.map +0 -1
  211. package/scripts/simpleExportForPointsForCommunity.d.ts.map +0 -1
  212. package/scripts/simpleExportForPostsForCommunity.d.ts.map +0 -1
  213. package/scripts/testForEndorsments.d.ts.map +0 -1
  214. package/scripts/undeleteGroupAndAllContent.d.ts.map +0 -1
  215. package/scripts/undeletePost.d.ts.map +0 -1
  216. package/scripts/unlinkSsn.d.ts.map +0 -1
  217. package/scripts/updateFromAlthingi.d.ts.map +0 -1
  218. package/server.d.ts.map +0 -1
  219. package/utils/copyGroup.js +0 -246
  220. package/utils/loggerTs.d.ts +0 -4
  221. package/utils/loggerTs.d.ts.map +0 -1
  222. package/utils/ypLanguages.d.ts +0 -18
  223. package/utils/ypLanguages.d.ts.map +0 -1
@@ -1,326 +0,0 @@
1
- // commonTools.ts
2
- import { SubscriptionModels } from "./models/subscriptions.js";
3
- import { BaseAssistantTools } from "./baseTools.js";
4
- export class SubscriptionTools extends BaseAssistantTools {
5
- constructor(assistant) {
6
- super(assistant);
7
- this.subscriptionModels = new SubscriptionModels(assistant);
8
- }
9
- get listMyAgentSubscriptions() {
10
- return {
11
- name: "list_my_agent_subscriptions",
12
- description: "List all agent subscriptions for the current user.",
13
- type: "function",
14
- parameters: {
15
- type: "object",
16
- properties: {},
17
- },
18
- handler: this.listMyAgentSubscriptionsHandler.bind(this),
19
- };
20
- }
21
- async listMyAgentSubscriptionsHandler(params) {
22
- params = this.assistant.getCleanedParams(params);
23
- console.log(`handler: list_my_agent_subscriptions: ${JSON.stringify(params, null, 2)}`);
24
- try {
25
- const status = await this.subscriptionModels.loadUserAgentSubscriptions();
26
- if (this.assistant.DEBUG) {
27
- console.log(`list_my_agent_subscriptions: ${JSON.stringify(status, null, 2)}`);
28
- }
29
- let agentChips = "";
30
- for (const subscription of status.availableSubscriptions) {
31
- agentChips += `<div class="agent-chips"><yp-agent-chip-for-purchase
32
- isSubscribed="${true}"
33
- type="${subscription.Plan?.configuration.type}"
34
- agentProductId="${subscription.Plan?.AgentProduct?.id}"
35
- subscriptionPlanId="${subscription.Plan?.id}"
36
- agentName="${subscription.Plan?.AgentProduct?.name}"
37
- agentDescription="${subscription.Plan?.AgentProduct?.description}"
38
- agentImageUrl="${subscription.Plan?.AgentProduct?.configuration.avatar?.imageUrl}"
39
- price="${subscription.Plan?.configuration.amount}"
40
- currency="${subscription.Plan?.configuration.currency}"
41
- maxRunsPerCycle="${subscription.Plan?.configuration.max_runs_per_cycle}"
42
- ></yp-agent-chip-for-purchase></div>`;
43
- }
44
- let html;
45
- if (status.availableSubscriptions.length > 0) {
46
- html = `<div class="agent-chips">${agentChips}</div>`;
47
- }
48
- else {
49
- this.assistant.triggerResponseIfNeeded("The user is not subscribed to any agents, offer to show available agents for purchase");
50
- }
51
- return {
52
- success: true,
53
- data: status,
54
- html,
55
- metadata: {
56
- timestamp: new Date().toISOString(),
57
- },
58
- };
59
- }
60
- catch (error) {
61
- const errorMessage = error instanceof Error ? error.message : "Failed to load agent status";
62
- console.error(`Failed to load agent status: ${errorMessage}`);
63
- return {
64
- success: false,
65
- data: errorMessage,
66
- error: errorMessage,
67
- };
68
- }
69
- }
70
- get listAllAgentsAvailableForSubscription() {
71
- return {
72
- name: "list_all_agents_available_for_subscription",
73
- description: "List all agent subscriptions available for purchase",
74
- type: "function",
75
- parameters: {
76
- type: "object",
77
- properties: {},
78
- },
79
- handler: this.listAllAgentsAvailableForSubscriptionHandler.bind(this),
80
- };
81
- }
82
- async listAllAgentsAvailableForSubscriptionHandler(params) {
83
- params = this.assistant.getCleanedParams(params);
84
- console.log(`handler: list_all_agents_available_for_purchase: ${JSON.stringify(params, null, 2)}`);
85
- try {
86
- const status = await this.subscriptionModels.loadAgentSubscriptionPlans();
87
- if (this.assistant.DEBUG) {
88
- console.log(`list_all_agents_available_for_purchase: ${JSON.stringify(status, null, 2)}`);
89
- }
90
- let agentChips = "";
91
- function planTypePriority(type) {
92
- switch (type) {
93
- case "coming_soon":
94
- return 0;
95
- case "paid":
96
- return 1;
97
- case "free_trial":
98
- return 2;
99
- default:
100
- return 999;
101
- }
102
- }
103
- // 2) Custom sort function
104
- const sortedPlans = [...status.availablePlans].sort((a, b) => {
105
- // Compare by type priority first
106
- const typeComparison = planTypePriority(a.type) - planTypePriority(b.type);
107
- if (typeComparison !== 0) {
108
- // If types differ, that decides the order
109
- return typeComparison;
110
- }
111
- // If both are the same type and it's "paid", sort by price descending
112
- if (a.type === "paid" && b.type === "paid") {
113
- return b.price - a.price;
114
- }
115
- // Otherwise keep them in the same order if they're not "paid"
116
- return 0;
117
- });
118
- for (const agent of sortedPlans) {
119
- agentChips += `<yp-agent-chip-for-purchase
120
- subscriptionPlanId="${agent.subscriptionPlanId}"
121
- type="${agent.type}"
122
- agentName="${agent.name}"
123
- agentDescription="${agent.description}"
124
- agentImageUrl="${agent.imageUrl}"
125
- price="${agent.price}"
126
- currency="${agent.currency}"
127
- maxRunsPerCycle="${agent.maxRunsPerCycle}"
128
- ></yp-agent-chip-for-purchase>`;
129
- }
130
- const html = `<div class="agent-chips">${agentChips}</div>`;
131
- return {
132
- success: true,
133
- data: {
134
- messageToAssistant: "You have shown the user the available agents for purchase with a UI widget, now the user needs to choose which one to connect to then subscribe to",
135
- status,
136
- },
137
- html,
138
- metadata: {
139
- timestamp: new Date().toISOString(),
140
- },
141
- };
142
- }
143
- catch (error) {
144
- const errorMessage = error instanceof Error ? error.message : "Failed to load agent status";
145
- console.error(`Failed to load agent status: ${errorMessage}`);
146
- return {
147
- success: false,
148
- data: errorMessage,
149
- error: errorMessage,
150
- };
151
- }
152
- }
153
- get subscribeToCurrentAgentPlan() {
154
- return {
155
- name: "subscribe_to_current_agent_plan",
156
- description: "Subscribe to the current agent plan. User must confirm subscription with the agent name before proceeding. The user needs to subscribe to the agent before it can be used so make sure to offer it to the user.",
157
- type: "function",
158
- parameters: {
159
- type: "object",
160
- properties: {
161
- useHasVerballyConfirmedSubscribeWithTheAgentName: {
162
- type: "boolean",
163
- },
164
- },
165
- required: [
166
- "useHasVerballyConfirmedSubscribeWithTheAgentName",
167
- ],
168
- },
169
- handler: this.subscribeToCurrentAgentPlanHandler.bind(this),
170
- };
171
- }
172
- async subscribeToCurrentAgentPlanHandler(params) {
173
- params = this.assistant.getCleanedParams(params);
174
- console.log(`handler: subscribe_to_current_agent_plan: ${JSON.stringify(params, null, 2)}`);
175
- try {
176
- if (!params.useHasVerballyConfirmedSubscribeWithTheAgentName) {
177
- return {
178
- success: false,
179
- error: "User must confirm subscription with the agent name before proceeding",
180
- };
181
- }
182
- console.log(`-------> ${JSON.stringify(this.assistant.memory.currentAgentStatus, null, 2)}`);
183
- const subscriptionPlan = await this.assistant.getCurrentSubscriptionPlan();
184
- if (!subscriptionPlan) {
185
- throw new Error("No subscription plan found");
186
- }
187
- if (!subscriptionPlan) {
188
- return {
189
- success: false,
190
- data: "No current agent selected",
191
- error: "No current agent selected",
192
- };
193
- }
194
- const result = await this.subscriptionModels.subscribeToAgentPlan(subscriptionPlan.AgentProduct.id, subscriptionPlan.id);
195
- if (!result.success || !result.subscription || !result.plan) {
196
- return {
197
- success: false,
198
- error: result.error || "Failed to subscribe to agent plan",
199
- };
200
- }
201
- await this.updateCurrentAgentProductPlan(result.plan, result.subscription);
202
- let html;
203
- if (result.plan?.AgentProduct) {
204
- html = `<div class="agent-chips"><yp-agent-chip-for-purchase
205
- isSubscribed="${true}"
206
- agentProductId="${result.plan.AgentProduct.id}"
207
- subscriptionPlanId="${result.plan.id}"
208
- agentName="${result.plan.AgentProduct.configuration.displayName}"
209
- agentDescription="${result.plan.AgentProduct.description}"
210
- agentImageUrl="${result.plan.AgentProduct.configuration.avatar?.imageUrl}"
211
- price="${result.plan.configuration.amount}"
212
- currency="${result.plan.configuration.currency}"
213
- maxRunsPerCycle="${result.plan.configuration.max_runs_per_cycle}"
214
- ></yp-agent-chip-for-purchase></div>`;
215
- }
216
- this.assistant.emit("update-ai-model-session", "Successfully subscribed to agent plan, now offer to show the configuration input tool/widget to configure the agent");
217
- return {
218
- success: true,
219
- html,
220
- data: {
221
- message: "Successfully subscribed to agent plan, now offer to show the configuration input tool/widget to configure the agent",
222
- subscription: result.subscription,
223
- subscriptionPlan: result.plan,
224
- },
225
- };
226
- }
227
- catch (error) {
228
- const errorMessage = error instanceof Error ? error.message : "Failed to subscribe to agent";
229
- console.error(`Failed to subscribe to agent: ${errorMessage}`);
230
- return {
231
- success: false,
232
- error: errorMessage,
233
- };
234
- }
235
- }
236
- get unsubscribeFromCurrentAgentSubscription() {
237
- return {
238
- name: "unsubscribe_from_current_agent_subscription",
239
- description: "Unsubscribe from an existing agent subscription the user is subscribed to. User must verbally confirm unsubscription with the agent name before proceeding.",
240
- type: "function",
241
- parameters: {
242
- type: "object",
243
- properties: {
244
- useHasVerballyConfirmedUnsubscribeWithTheAgentName: {
245
- type: "boolean",
246
- },
247
- },
248
- required: [
249
- "useHasVerballyConfirmedUnsubscribeWithTheAgentName",
250
- ],
251
- },
252
- handler: this.unsubscribeFromCurrentAgentSubscriptionHandler.bind(this),
253
- };
254
- }
255
- async unsubscribeFromCurrentAgentSubscriptionHandler(params) {
256
- params = this.assistant.getCleanedParams(params);
257
- console.log(`handler: unsubscribe_from_current_agent_subscription: ${JSON.stringify(params, null, 2)}`);
258
- try {
259
- if (!params.useHasVerballyConfirmedUnsubscribeWithTheAgentName) {
260
- return {
261
- success: false,
262
- error: "User must verbally confirm unsubscription with the agent name before proceeding",
263
- };
264
- }
265
- const subscriptionPlan = await this.assistant.getCurrentSubscriptionPlan();
266
- if (!subscriptionPlan) {
267
- return {
268
- success: false,
269
- data: "No current agent selected",
270
- error: "No current agent selected",
271
- };
272
- }
273
- const { plan, subscription } = await this.subscriptionModels.loadAgentProductPlanAndSubscription(subscriptionPlan.id);
274
- if (!subscription) {
275
- return {
276
- success: false,
277
- data: "No subscription found",
278
- error: "No subscription found",
279
- };
280
- }
281
- if (!plan) {
282
- return {
283
- success: false,
284
- data: "No subscription plan found",
285
- error: "No subscription plan found",
286
- };
287
- }
288
- const result = await this.subscriptionModels.unsubscribeFromAgentPlan(subscription.id);
289
- if (!result.success) {
290
- return {
291
- success: false,
292
- error: result.error,
293
- };
294
- }
295
- await this.updateCurrentAgentProductPlan(plan, subscription);
296
- const html = `<div class="agent-chips"><yp-agent-chip
297
- isUnsubscribed="${true}"
298
- agentProductId="${plan.AgentProduct?.id}"
299
- subscriptionId="${subscription.id}"
300
- agentName="${plan.AgentProduct?.name}"
301
- agentDescription="${plan.AgentProduct?.description}"
302
- agentImageUrl="${plan.AgentProduct?.configuration.avatar?.imageUrl}"
303
- ></yp-agent-chip></div>`;
304
- this.assistant.emit("update-ai-model-session", "Successfully unsubscribed from agent subscription");
305
- return {
306
- success: true,
307
- html,
308
- data: {
309
- message: "Successfully unsubscribed from agent subscription",
310
- subscriptionId: result.subscriptionId,
311
- subscriptionPlan: plan,
312
- },
313
- };
314
- }
315
- catch (error) {
316
- const errorMessage = error instanceof Error
317
- ? error.message
318
- : "Failed to unsubscribe from agent";
319
- console.error(`Failed to unsubscribe from agent: ${errorMessage}`);
320
- return {
321
- success: false,
322
- error: errorMessage,
323
- };
324
- }
325
- }
326
- }
@@ -1,57 +0,0 @@
1
- // commonTools.ts
2
- export class CommonToolHandlers {
3
- constructor(assistant) {
4
- this.assistant = assistant;
5
- }
6
- async goBackToMainAssistant() {
7
- await this.assistant.handleModeSwitch('agent_subscription_and_selection', 'User requested to return to the main assistant', {});
8
- return {
9
- success: true,
10
- data: { message: 'Returned to main assistant' },
11
- };
12
- }
13
- async connectToOneOfTheAgentsHandler(params) {
14
- params = this.assistant.getCleanedParams(params);
15
- console.log(`handler: connect_to_one_of_the_agents: ${JSON.stringify(params, null, 2)}`);
16
- try {
17
- const agent = await this.validateAndSelectAgent(params.agentProductId);
18
- const requiredQuestions = await this.getRequiredQuestions(params.agentProductId);
19
- this.currentAgentId = params.agentProductId;
20
- // If we have unanswered required questions, switch to configuration mode
21
- if (requiredQuestions && requiredQuestions.length > 0) {
22
- await this.assistant.handleModeSwitch("agent_configuration", "Required questions need to be answered", params);
23
- }
24
- else {
25
- await this.assistant.handleModeSwitch("agent_operations", "Agent ready for operations", params);
26
- }
27
- const html = `<div class="agent-chips"><yp-agent-chip
28
- isSelected
29
- agentProductId="${agent.agentProductId}"
30
- subscriptionId="${agent.subscriptionId}"
31
- agentName="${agent.name}"
32
- agentDescription="${agent.description}"
33
- agentImageUrl="${agent.imageUrl}"
34
- ></yp-agent-chip></div>`;
35
- this.assistant.triggerResponseIfNeeded("Agent selected");
36
- return {
37
- success: true,
38
- html,
39
- data: {
40
- agent,
41
- hasRequiredQuestions: requiredQuestions && requiredQuestions.length > 0,
42
- },
43
- };
44
- }
45
- catch (error) {
46
- const errorMessage = error instanceof Error
47
- ? error.message
48
- : "Failed to select agent";
49
- console.error(`Failed to select agent: ${errorMessage}`);
50
- return {
51
- success: false,
52
- data: errorMessage,
53
- error: errorMessage,
54
- };
55
- }
56
- }
57
- }
@@ -1,46 +0,0 @@
1
- // commonTools.ts
2
- export class LoginToolHandlers {
3
- constructor(assistant) {
4
- this.assistant = assistant;
5
- }
6
- async logIn(params) {
7
- // Implement log in logic
8
- const { username, password } = params;
9
- // Validate credentials
10
- /*const isValid = await this.assistant.authService.validateCredentials(username, password);
11
- if (isValid) {
12
- this.assistant.isLoggedIn = true;
13
- return {
14
- success: true,
15
- data: { message: 'Logged in successfully' },
16
- };
17
- } else {
18
- return {
19
- success: false,
20
- error: 'Invalid username or password',
21
- };
22
- }*/
23
- return {
24
- success: true,
25
- data: { message: 'Logged in successfully' },
26
- };
27
- }
28
- async logOut(params) {
29
- // Implement log out logic with confirmation
30
- const { confirmLogout } = params;
31
- if (!confirmLogout) {
32
- return {
33
- success: false,
34
- error: 'Please confirm that you want to log out',
35
- };
36
- }
37
- this.assistant.isLoggedIn = false;
38
- this.assistant.isCurrentAgentRunning = false;
39
- this.assistant.isSubscribedToCurrentAgent = false;
40
- this.assistant.hasConfiguredCurrentAgent = false;
41
- return {
42
- success: true,
43
- data: { message: 'Logged out successfully' },
44
- };
45
- }
46
- }