@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.
- package/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
- package/active-citizen/llms/imageGeneration/collectionImageGenerator.js +6 -0
- package/agents/controllers/agentProductController.js +2 -1
- package/agents/controllers/agentSubscriptionController.js +20 -11
- package/agents/controllers/assistantsController.js +28 -18
- package/agents/controllers/policySynthAgents.js +33 -12
- package/agents/managers/newAiModelSetup.js +96 -0
- package/agents/managers/subscriptionManager.js +2 -2
- package/app.js +12 -12
- package/authorization.cjs +4 -0
- package/controllers/allOurIdeas.js +2 -1
- package/controllers/communities.cjs +47 -1
- package/controllers/groups.cjs +67 -4
- package/controllers/index.cjs +7 -7
- package/controllers/nonSpa.cjs +1 -1
- package/package.json +46 -44
- package/server.d.ts +104 -2
- package/utils/copy_utils.cjs +7 -1
- package/active-citizen/engine/allOurIdeas/aiHelper.d.ts +0 -21
- package/active-citizen/engine/allOurIdeas/aiHelper.d.ts.map +0 -1
- package/active-citizen/engine/allOurIdeas/explainAnswersAssistant.d.ts.map +0 -1
- package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts +0 -12
- package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts.map +0 -1
- package/active-citizen/engine/analytics/export_anon_community_activities.d.ts.map +0 -1
- package/active-citizen/engine/analytics/importer.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/categories_dataset.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/dataset_tools.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/sentiment_dataset.d.ts.map +0 -1
- package/active-citizen/engine/reports/xls_all_our_ideas_export.js +0 -141
- package/active-citizen/llms/baseChatBot.d.ts +0 -51
- package/active-citizen/llms/baseChatBot.d.ts.map +0 -1
- package/active-citizen/llms/collectionImageGenerator.js +0 -357
- package/active-citizen/llms/llmTranslation.d.ts +0 -24
- package/active-citizen/llms/llmTranslation.d.ts.map +0 -1
- package/active-citizen/scripts/fix_old_delayed_notifications.d.ts.map +0 -1
- package/active-citizen/scripts/kue_status.d.ts.map +0 -1
- package/active-citizen/scripts/kue_watch_stuck_jobs.d.ts.map +0 -1
- package/active-citizen/scripts/translation_clear_language.d.ts.map +0 -1
- package/active-citizen/scripts/translation_delete.d.ts.map +0 -1
- package/active-citizen/scripts/translation_replace_text_from_url.d.ts.map +0 -1
- package/active-citizen/scripts/translation_update.d.ts.map +0 -1
- package/active-citizen/scripts/translations_list.d.ts.map +0 -1
- package/active-citizen/utils/airbrake.d.ts.map +0 -1
- package/active-citizen/utils/airbrake.js +0 -17
- package/active-citizen/utils/updateAllLocalesFromEn.d.ts +0 -21
- package/active-citizen/utils/updateAllLocalesFromEn.d.ts.map +0 -1
- package/active-citizen/utils/updateLocaleFolders.d.ts +0 -2
- package/active-citizen/utils/updateLocaleFolders.d.ts.map +0 -1
- package/active-citizen/workers/cloudflare/voiceSession/worker.js +0 -213
- package/active-citizen/workers/generativeAi.d.ts.map +0 -1
- package/agents/agentProductManager.js +0 -91
- package/agents/assistants/agentAssistantOld.js +0 -863
- package/agents/assistants/modes/agentConfigurationMode.js +0 -63
- package/agents/assistants/modes/agentOperationsMode.js +0 -195
- package/agents/assistants/modes/commonTools.js +0 -58
- package/agents/assistants/modes/directConversationMode.js +0 -14
- package/agents/assistants/modes/toolHandlers/accountHandlers.js +0 -46
- package/agents/assistants/modes/toolHandlers/commonHandlers.js +0 -57
- package/agents/assistants/modes/toolHandlers/commonTools.js +0 -58
- package/agents/assistants/modes/toolHandlers/loginHandlers.js +0 -46
- package/agents/assistants/modes/toolHandlers/subscriptionHandlers.js +0 -469
- package/agents/assistants/modes/tools/agentConnectionTools.js +0 -326
- package/agents/assistants/modes/tools/commonHandlers.js +0 -57
- package/agents/assistants/modes/tools/loginHandlers.js +0 -46
- package/agents/assistants/modes/tools/subscriptionHandlers.js +0 -469
- package/agents/assistants/modes/tools/workflowConversationTools.js +0 -326
- package/agents/assistants/modes/tools/workflowTools.js +0 -112
- package/agents/controllers/assistantController.js +0 -243
- package/agents/managers/workflowManager.js +0 -76
- package/agents/models/testData/setupConfig.js +0 -140
- package/agents/models/workflow.js +0 -53
- package/agents/models/workflowConverstation.js +0 -53
- package/agents/subscriptionManager.js +0 -218
- package/agents/tools/updateCommunityWorkflow.js +0 -1
- package/agents/tools/updateTemplateWorkflow.js +0 -45
- package/app.d.ts +0 -40
- package/app.d.ts.map +0 -1
- package/bot_control.d.ts.map +0 -1
- package/migrations/200824_create_embeddings_and_org_update.cjs +0 -15
- package/migrations/270724_createUsersAndAdminsForClasses.cjs +0 -100
- package/publish.d.ts.map +0 -1
- package/repack.d.ts.map +0 -1
- package/scripts/addRatingUsersToGroup.d.ts.map +0 -1
- package/scripts/addUserToOrganization.d.ts.map +0 -1
- package/scripts/analyseRatingsForCommunity.d.ts.map +0 -1
- package/scripts/analyzeAndFixBrokenPointUsers.d.ts.map +0 -1
- package/scripts/analyzeEndorsementsByCountry.d.ts.map +0 -1
- package/scripts/analyzePostsForCommunity.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/listUpdates.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdate.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdateForGroup.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdateForGroup.js +0 -125
- package/scripts/bulkStatusUpdates/performUpdateForStatus.d.ts.map +0 -1
- package/scripts/change/changeVideoAspectTo.d.ts.map +0 -1
- package/scripts/change/setDomainAdmin.cjs +0 -45
- package/scripts/changeCommunityGroupcount.d.ts.map +0 -1
- package/scripts/changeCommunityPostCount.d.ts.map +0 -1
- package/scripts/changeGroupPostCount.d.ts.map +0 -1
- package/scripts/changeLanguage.d.ts.map +0 -1
- package/scripts/changeOfficalStatus.d.ts.map +0 -1
- package/scripts/cleanups/deleteAnonNotifications.d.ts.map +0 -1
- package/scripts/cleanups/deleteAnonNotifications.js +0 -91
- package/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.d.ts.map +0 -1
- package/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.d.ts.map +0 -1
- package/scripts/clearAllEndorsementInGroup.d.ts.map +0 -1
- package/scripts/cloning/clearUsersForCommunitiesFromUrl.d.ts.map +0 -1
- package/scripts/cloning/cloneFromUrlScript.d.ts.map +0 -1
- package/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.d.ts.map +0 -1
- package/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainWithEverything.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainWithOnlyGroups.d.ts.map +0 -1
- package/scripts/cloning/copyGroupConfigAndTranslationsFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyPostToGroupOld.d.ts.map +0 -1
- package/scripts/cloning/copyPostVideosFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyPostWithOutAnyVotingOrActivities.d.ts.map +0 -1
- package/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/setAdminsFromURL.d.ts.map +0 -1
- package/scripts/cloning/setExternalIdsFromURL.d.ts.map +0 -1
- package/scripts/countCommunity.d.ts.map +0 -1
- package/scripts/countCommunityUsers.d.ts.map +0 -1
- package/scripts/countDelayedNotifications.d.ts.map +0 -1
- package/scripts/countGroup.d.ts.map +0 -1
- package/scripts/countStuff.d.ts.map +0 -1
- package/scripts/countUniqueVotersInAGroup.d.ts.map +0 -1
- package/scripts/createInvitesAndShow.d.ts.map +0 -1
- package/scripts/database/seedTestAiModels.js +0 -64
- package/scripts/database/sync_database.d.ts.map +0 -1
- package/scripts/database/sync_dev_database.d.ts.map +0 -1
- package/scripts/debugNotifications.d.ts.map +0 -1
- package/scripts/deleteAllNewsFeeds.d.ts.map +0 -1
- package/scripts/deleteCategory.d.ts.map +0 -1
- package/scripts/deleteOldAppActivities.d.ts.map +0 -1
- package/scripts/deletePostContactDataForCommunity.d.ts.map +0 -1
- package/scripts/destroy/destroy_all_but_one_domain.d.ts.map +0 -1
- package/scripts/displayAuthorForPost.d.ts.map +0 -1
- package/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.d.ts.map +0 -1
- package/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.d.ts.map +0 -1
- package/scripts/exportAllStatusChanges.d.ts.map +0 -1
- package/scripts/exportClientAcitivity.d.ts.map +0 -1
- package/scripts/exportEndorsementsForCommunity.d.ts.map +0 -1
- package/scripts/exportPointQualitiesForCommunity.d.ts.map +0 -1
- package/scripts/exportPostsAndPointsForCommunity.d.ts.map +0 -1
- package/scripts/exportPostsDataSetForDomain.d.ts.map +0 -1
- package/scripts/exportPostsForGroup.d.ts.map +0 -1
- package/scripts/exportRatingsForPost.d.ts.map +0 -1
- package/scripts/exportUserEndorsementsWithUserAnalysis.d.ts.map +0 -1
- package/scripts/exportUsersForCommunity.d.ts.map +0 -1
- package/scripts/exportUsersForDomain.d.ts.map +0 -1
- package/scripts/exportUsersForGroup.d.ts.map +0 -1
- package/scripts/exports/ratingDistribution.d.ts.map +0 -1
- package/scripts/exports/whoEndorsedWhatByCommunity.d.ts.map +0 -1
- package/scripts/findUnusedClientImports.d.ts.map +0 -1
- package/scripts/fixAllPostPointCounts.d.ts.map +0 -1
- package/scripts/fixAnonNotificationsSettings.d.ts.map +0 -1
- package/scripts/fixCountKopavogur.d.ts.map +0 -1
- package/scripts/fixEndorsementsAfterCopyPostToGroup.d.ts.map +0 -1
- package/scripts/fixExternalUserId.d.ts.map +0 -1
- package/scripts/fixGroupAccess.d.ts.map +0 -1
- package/scripts/fixGroupIdeasAndPointsCount.d.ts.map +0 -1
- package/scripts/fixNotificationSettings.d.ts.map +0 -1
- package/scripts/fixSurveyRadioBakedInSubCodes.d.ts.map +0 -1
- package/scripts/fixWrongUserIdForStatusUpdates.d.ts.map +0 -1
- package/scripts/gallery/exportGalleryData.d.ts.map +0 -1
- package/scripts/gallery/importGalleryForCommunity.d.ts.map +0 -1
- package/scripts/gallery/readJsonAndDownloadImagesVersion2.d.ts.map +0 -1
- package/scripts/gallery/refreshAcApiPostIdsForCommunity.d.ts.map +0 -1
- package/scripts/genderAnalysis.d.ts.map +0 -1
- package/scripts/genderAnalysisByStatus.d.ts.map +0 -1
- package/scripts/importAllLocalesFromLocalFolders.d.ts.map +0 -1
- package/scripts/importDomain.d.ts.map +0 -1
- package/scripts/landUseGame/export3Ddata.d.ts.map +0 -1
- package/scripts/listLanguagesForGroup.d.ts.map +0 -1
- package/scripts/loadTestCreateDummyContentForGroup.d.ts.map +0 -1
- package/scripts/makeRecursiveMapData.d.ts.map +0 -1
- package/scripts/mapping/community_map_csv.d.ts.map +0 -1
- package/scripts/moveCommunityToDomain.d.ts.map +0 -1
- package/scripts/moveGroupToCommunity.d.ts.map +0 -1
- package/scripts/movePostToGroup.d.ts.map +0 -1
- package/scripts/movePostsToGroupsRecountGroupFromUrl.d.ts.map +0 -1
- package/scripts/oldMovePostToGroup.d.ts.map +0 -1
- package/scripts/processCsvForPdfUrls.d.ts.map +0 -1
- package/scripts/processCsvForTranslationAndToxicity.d.ts.map +0 -1
- package/scripts/recount/recount_recursive_communities.d.ts.map +0 -1
- package/scripts/recountALLCommunityGroupCounts.d.ts.map +0 -1
- package/scripts/recountAll.d.ts.map +0 -1
- package/scripts/recountCommunitesFromUrl.d.ts.map +0 -1
- package/scripts/recountCommunity.d.ts.map +0 -1
- package/scripts/recountGroup.d.ts.map +0 -1
- package/scripts/recountGroupNoUserChange.d.ts.map +0 -1
- package/scripts/resetAllEndorsementsForGroup.d.ts.map +0 -1
- package/scripts/resetEnTranslationForGroup.d.ts.map +0 -1
- package/scripts/setDomainLocales.d.ts.map +0 -1
- package/scripts/setLanguageOnGroupCommunitesFromUrl.d.ts.map +0 -1
- package/scripts/setMemberOfAll.d.ts.map +0 -1
- package/scripts/setNewUserForContentOfCommunity.d.ts.map +0 -1
- package/scripts/setOfficialStatusOnAllPostsForCommunity.d.ts.map +0 -1
- package/scripts/setUserOnAll.d.ts.map +0 -1
- package/scripts/showCategoryForGroup.d.ts.map +0 -1
- package/scripts/showOldActivityTypes.d.ts.map +0 -1
- package/scripts/showPostsMissingCategoryForGroup.d.ts.map +0 -1
- package/scripts/showStatuses.d.ts.map +0 -1
- package/scripts/showUniqueVotersInCommunity.d.ts.map +0 -1
- package/scripts/showUserAgentsAndIpsForEmails.d.ts.map +0 -1
- package/scripts/simpleExportForGroupsForCommunity.d.ts.map +0 -1
- package/scripts/simpleExportForPointsForCommunity.d.ts.map +0 -1
- package/scripts/simpleExportForPostsForCommunity.d.ts.map +0 -1
- package/scripts/testForEndorsments.d.ts.map +0 -1
- package/scripts/undeleteGroupAndAllContent.d.ts.map +0 -1
- package/scripts/undeletePost.d.ts.map +0 -1
- package/scripts/unlinkSsn.d.ts.map +0 -1
- package/scripts/updateFromAlthingi.d.ts.map +0 -1
- package/server.d.ts.map +0 -1
- package/utils/copyGroup.js +0 -246
- package/utils/loggerTs.d.ts +0 -4
- package/utils/loggerTs.d.ts.map +0 -1
- package/utils/ypLanguages.d.ts +0 -18
- package/utils/ypLanguages.d.ts.map +0 -1
|
@@ -1,469 +0,0 @@
|
|
|
1
|
-
// commonTools.ts
|
|
2
|
-
import { YpSubscription } from "agents/models/subscription.js";
|
|
3
|
-
import { YpSubscriptionPlan } from "agents/models/subscriptionPlan.js";
|
|
4
|
-
import { YpAgentProduct } from "agents/models/agentProduct.js";
|
|
5
|
-
import { YpAgentProductBundle } from "agents/models/agentProductBundle.js";
|
|
6
|
-
import { YpAgentProductRun } from "agents/models/agentProductRun.js";
|
|
7
|
-
export class SubscriptionToolHandlers {
|
|
8
|
-
constructor(assistant) {
|
|
9
|
-
this.assistant = assistant;
|
|
10
|
-
}
|
|
11
|
-
get listMyAgentSubscriptionsTool() {
|
|
12
|
-
return {
|
|
13
|
-
name: "list_my_agent_subscriptions",
|
|
14
|
-
description: "List all agent subscriptions for the current user.",
|
|
15
|
-
type: "function",
|
|
16
|
-
parameters: {
|
|
17
|
-
type: "object",
|
|
18
|
-
properties: {},
|
|
19
|
-
},
|
|
20
|
-
handler: this.listMyAgentSubscriptionsHandler.bind(this),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
async listMyAgentSubscriptionsHandler(params) {
|
|
24
|
-
params = this.assistant.getCleanedParams(params);
|
|
25
|
-
console.log(`handler: list_my_agent_subscriptions: ${JSON.stringify(params, null, 2)}`);
|
|
26
|
-
try {
|
|
27
|
-
const status = await this.loadMyAgentSubscriptions();
|
|
28
|
-
if (this.assistant.DEBUG) {
|
|
29
|
-
console.log(`list_my_agent_subscriptions: ${JSON.stringify(status, null, 2)}`);
|
|
30
|
-
}
|
|
31
|
-
let agentChips = "";
|
|
32
|
-
for (const agent of status.availableAgents) {
|
|
33
|
-
agentChips += `<yp-agent-chip
|
|
34
|
-
agentProductId="${agent.agentProductId}"
|
|
35
|
-
subscriptionId="${agent.subscriptionId}"
|
|
36
|
-
agentName="${agent.name}"
|
|
37
|
-
agentDescription="${agent.description}"
|
|
38
|
-
agentImageUrl="${agent.imageUrl}"
|
|
39
|
-
></yp-agent-chip>`;
|
|
40
|
-
}
|
|
41
|
-
let html;
|
|
42
|
-
if (status.availableAgents.length > 0) {
|
|
43
|
-
html = `<div class="agent-chips">${agentChips}</div>`;
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
this.assistant.triggerResponseIfNeeded("The user is not subscribed to any agents, offer to show available agents for purchase");
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
success: true,
|
|
50
|
-
data: status,
|
|
51
|
-
html,
|
|
52
|
-
metadata: {
|
|
53
|
-
timestamp: new Date().toISOString(),
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
const errorMessage = error instanceof Error
|
|
59
|
-
? error.message
|
|
60
|
-
: "Failed to load agent status";
|
|
61
|
-
console.error(`Failed to load agent status: ${errorMessage}`);
|
|
62
|
-
return {
|
|
63
|
-
success: false,
|
|
64
|
-
data: errorMessage,
|
|
65
|
-
error: errorMessage,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
get listAllAgentsAvailableForSubscriptionTool() {
|
|
70
|
-
return {
|
|
71
|
-
name: "list_all_agents_available_for_subscription",
|
|
72
|
-
description: "List all agent subscriptions available for purchase",
|
|
73
|
-
type: "function",
|
|
74
|
-
parameters: {
|
|
75
|
-
type: "object",
|
|
76
|
-
properties: {},
|
|
77
|
-
},
|
|
78
|
-
handler: this.listAllAgentsAvailableForSubscriptionHandler.bind(this),
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
async listAllAgentsAvailableForSubscriptionHandler(params) {
|
|
82
|
-
params = this.assistant.getCleanedParams(params);
|
|
83
|
-
console.log(`handler: list_all_agents_available_for_purchase: ${JSON.stringify(params, null, 2)}`);
|
|
84
|
-
try {
|
|
85
|
-
const status = await this.loadAllAgentPlans();
|
|
86
|
-
if (this.assistant.DEBUG) {
|
|
87
|
-
console.log(`list_all_agents_available_for_purchase: ${JSON.stringify(status, null, 2)}`);
|
|
88
|
-
}
|
|
89
|
-
let agentChips = "";
|
|
90
|
-
for (const agent of status.availablePlans) {
|
|
91
|
-
agentChips += `<yp-agent-chip-for-purchase
|
|
92
|
-
agentProductId="${agent.agentProductId}"
|
|
93
|
-
subscriptionPlanId="${agent.subscriptionPlanId}"
|
|
94
|
-
agentName="${agent.name}"
|
|
95
|
-
agentDescription="${agent.description}"
|
|
96
|
-
agentImageUrl="${agent.imageUrl}"
|
|
97
|
-
price="${agent.price}"
|
|
98
|
-
currency="${agent.currency}"
|
|
99
|
-
maxRunsPerCycle="${agent.maxRunsPerCycle}"
|
|
100
|
-
></yp-agent-chip-for-purchase>`;
|
|
101
|
-
}
|
|
102
|
-
const html = `<div class="agent-chips">${agentChips}</div>`;
|
|
103
|
-
return {
|
|
104
|
-
success: true,
|
|
105
|
-
data: status,
|
|
106
|
-
html,
|
|
107
|
-
metadata: {
|
|
108
|
-
timestamp: new Date().toISOString(),
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
const errorMessage = error instanceof Error
|
|
114
|
-
? error.message
|
|
115
|
-
: "Failed to load agent status";
|
|
116
|
-
console.error(`Failed to load agent status: ${errorMessage}`);
|
|
117
|
-
return {
|
|
118
|
-
success: false,
|
|
119
|
-
data: errorMessage,
|
|
120
|
-
error: errorMessage,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async subscribeToOneOfTheAvailableAgentPlansHandler(params) {
|
|
125
|
-
params = this.assistant.getCleanedParams(params);
|
|
126
|
-
console.log(`handler: subscribe_to_one_of_the_available_agent_plans: ${JSON.stringify(params, null, 2)}`);
|
|
127
|
-
try {
|
|
128
|
-
if (!params.useHasVerballyConfirmedSubscribeWithTheAgentName) {
|
|
129
|
-
return {
|
|
130
|
-
success: false,
|
|
131
|
-
error: "User must confirm subscription with the agent name before proceeding",
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
const result = await this.subscribeToAgentPlan(params.agentProductId, params.subscriptionPlanId);
|
|
135
|
-
if (!result.success) {
|
|
136
|
-
return {
|
|
137
|
-
success: false,
|
|
138
|
-
error: result.error,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
const agentPlans = await this.loadAllAgentPlans();
|
|
142
|
-
const agent = agentPlans.availablePlans.find((a) => a.subscriptionPlanId === result.subscriptionPlanId);
|
|
143
|
-
let html;
|
|
144
|
-
if (agent) {
|
|
145
|
-
html = `<div class="agent-chips"><yp-agent-chip-for-purchase
|
|
146
|
-
isSubscribed="${true}"
|
|
147
|
-
agentProductId="${agent.agentProductId}"
|
|
148
|
-
subscriptionPlanId="${result.subscriptionPlanId}"
|
|
149
|
-
agentName="${agent.name}"
|
|
150
|
-
agentDescription="${agent.description}"
|
|
151
|
-
agentImageUrl="${agent.imageUrl}"
|
|
152
|
-
price="${agent.price}"
|
|
153
|
-
currency="${agent.currency}"
|
|
154
|
-
maxRunsPerCycle="${agent.maxRunsPerCycle}"
|
|
155
|
-
></yp-agent-chip-for-purchase></div>`;
|
|
156
|
-
}
|
|
157
|
-
this.assistant.triggerResponseIfNeeded("Successfully subscribed to agent plan");
|
|
158
|
-
return {
|
|
159
|
-
success: true,
|
|
160
|
-
html,
|
|
161
|
-
data: {
|
|
162
|
-
message: "Successfully subscribed to agent plan",
|
|
163
|
-
subscriptionId: result.subscriptionId,
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
catch (error) {
|
|
168
|
-
const errorMessage = error instanceof Error
|
|
169
|
-
? error.message
|
|
170
|
-
: "Failed to subscribe to agent";
|
|
171
|
-
console.error(`Failed to subscribe to agent: ${errorMessage}`);
|
|
172
|
-
return {
|
|
173
|
-
success: false,
|
|
174
|
-
error: errorMessage,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
async unsubscribeFromOneOfMySubscribedAgentsHandler(params) {
|
|
179
|
-
params = this.assistant.getCleanedParams(params);
|
|
180
|
-
console.log(`handler: unsubscribe_from_one_of_my_subscribed_agents: ${JSON.stringify(params, null, 2)}`);
|
|
181
|
-
try {
|
|
182
|
-
if (!params.useHasVerballyConfirmedUnsubscribeWithTheAgentName) {
|
|
183
|
-
return {
|
|
184
|
-
success: false,
|
|
185
|
-
error: "User must verbally confirm unsubscription with the agent name before proceeding",
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
const agent = await this.validateAndSelectAgent(params.agentProductId);
|
|
189
|
-
const result = await this.unsubscribeFromAgentPlan(params.subscriptionId);
|
|
190
|
-
if (!result.success) {
|
|
191
|
-
return {
|
|
192
|
-
success: false,
|
|
193
|
-
error: result.error,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
const html = `<div class="agent-chips"><yp-agent-chip
|
|
197
|
-
isUnsubscribed="${true}"
|
|
198
|
-
agentProductId="${agent.agentProductId}"
|
|
199
|
-
subscriptionId="${params.subscriptionId}"
|
|
200
|
-
agentName="${agent.name}"
|
|
201
|
-
agentDescription="${agent.description}"
|
|
202
|
-
agentImageUrl="${agent.imageUrl}"
|
|
203
|
-
></yp-agent-chip></div>`;
|
|
204
|
-
this.assistant.triggerResponseIfNeeded("Successfully unsubscribed from agent subscription");
|
|
205
|
-
return {
|
|
206
|
-
success: true,
|
|
207
|
-
html,
|
|
208
|
-
data: {
|
|
209
|
-
message: "Successfully unsubscribed from agent subscription",
|
|
210
|
-
subscriptionId: result.subscriptionId,
|
|
211
|
-
},
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
catch (error) {
|
|
215
|
-
const errorMessage = error instanceof Error
|
|
216
|
-
? error.message
|
|
217
|
-
: "Failed to unsubscribe from agent";
|
|
218
|
-
console.error(`Failed to unsubscribe from agent: ${errorMessage}`);
|
|
219
|
-
return {
|
|
220
|
-
success: false,
|
|
221
|
-
error: errorMessage,
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
async loadAllAgentPlans() {
|
|
226
|
-
try {
|
|
227
|
-
const firstBundle = await YpAgentProductBundle.findOne({
|
|
228
|
-
where: {
|
|
229
|
-
//TODO: get working
|
|
230
|
-
//domain_id: this.domainId,
|
|
231
|
-
},
|
|
232
|
-
});
|
|
233
|
-
// Get all available subscription plans with their associated agent products
|
|
234
|
-
const availablePlans = await YpSubscriptionPlan.findAll({
|
|
235
|
-
where: {
|
|
236
|
-
// status: 'active', // Only get active plans
|
|
237
|
-
},
|
|
238
|
-
include: [
|
|
239
|
-
{
|
|
240
|
-
model: YpAgentProduct,
|
|
241
|
-
as: "AgentProduct",
|
|
242
|
-
attributes: {
|
|
243
|
-
exclude: ["created_at", "updated_at"],
|
|
244
|
-
},
|
|
245
|
-
include: [
|
|
246
|
-
{
|
|
247
|
-
model: YpAgentProductBundle,
|
|
248
|
-
as: "AgentBundles",
|
|
249
|
-
required: false,
|
|
250
|
-
attributes: {
|
|
251
|
-
exclude: ["created_at", "updated_at"],
|
|
252
|
-
},
|
|
253
|
-
},
|
|
254
|
-
],
|
|
255
|
-
},
|
|
256
|
-
],
|
|
257
|
-
});
|
|
258
|
-
console.log(`-----------XXXXXXXXXXXXXXXx----------_> ${JSON.stringify(availablePlans, null, 2)}`);
|
|
259
|
-
return {
|
|
260
|
-
availablePlans: availablePlans.map((plan) => ({
|
|
261
|
-
agentProductId: plan.AgentProduct?.id || 0,
|
|
262
|
-
subscriptionPlanId: plan.id,
|
|
263
|
-
name: plan.AgentProduct?.name || plan.name,
|
|
264
|
-
description: plan.AgentProduct?.description || "No description available",
|
|
265
|
-
imageUrl: plan.configuration?.imageUrl || "",
|
|
266
|
-
price: plan.configuration?.amount || 0,
|
|
267
|
-
currency: plan.configuration?.currency || "USD",
|
|
268
|
-
maxRunsPerCycle: plan.configuration?.max_runs_per_cycle || 0,
|
|
269
|
-
})),
|
|
270
|
-
availableBundle: firstBundle
|
|
271
|
-
? {
|
|
272
|
-
agentBundleId: firstBundle.id,
|
|
273
|
-
name: firstBundle.name,
|
|
274
|
-
description: firstBundle.description || "",
|
|
275
|
-
imageUrl: firstBundle.configuration?.imageUrl || "",
|
|
276
|
-
}
|
|
277
|
-
: "No bundle available",
|
|
278
|
-
systemStatus: {
|
|
279
|
-
healthy: true,
|
|
280
|
-
lastUpdated: new Date(),
|
|
281
|
-
},
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
catch (error) {
|
|
285
|
-
console.error("Error loading available subscription plans:", error);
|
|
286
|
-
return {
|
|
287
|
-
availablePlans: [],
|
|
288
|
-
availableBundle: "No bundle available",
|
|
289
|
-
systemStatus: {
|
|
290
|
-
healthy: false,
|
|
291
|
-
lastUpdated: new Date(),
|
|
292
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
293
|
-
},
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
async loadMyAgentSubscriptions() {
|
|
298
|
-
try {
|
|
299
|
-
// Get available agent products from user's subscriptions for their domain
|
|
300
|
-
const availableAgents = await YpSubscription.findAll({
|
|
301
|
-
where: {
|
|
302
|
-
//domain_id: this.domainId, //TODO: get working
|
|
303
|
-
status: "active", // Only get active subscriptions
|
|
304
|
-
},
|
|
305
|
-
include: [
|
|
306
|
-
{
|
|
307
|
-
model: YpSubscriptionPlan,
|
|
308
|
-
as: "Plan",
|
|
309
|
-
},
|
|
310
|
-
{
|
|
311
|
-
model: YpAgentProduct,
|
|
312
|
-
as: "AgentProduct",
|
|
313
|
-
attributes: {
|
|
314
|
-
exclude: ["created_at", "updated_at"],
|
|
315
|
-
},
|
|
316
|
-
include: [
|
|
317
|
-
{
|
|
318
|
-
model: YpAgentProductBundle,
|
|
319
|
-
as: "AgentBundles",
|
|
320
|
-
required: false,
|
|
321
|
-
attributes: {
|
|
322
|
-
exclude: ["created_at", "updated_at"],
|
|
323
|
-
},
|
|
324
|
-
},
|
|
325
|
-
],
|
|
326
|
-
},
|
|
327
|
-
],
|
|
328
|
-
});
|
|
329
|
-
// Get currently running agents for the domain
|
|
330
|
-
const runningAgents = await YpAgentProductRun.findAll({
|
|
331
|
-
where: {
|
|
332
|
-
//domain_id: this.domainId, //TODO: get working
|
|
333
|
-
status: "running",
|
|
334
|
-
},
|
|
335
|
-
include: [
|
|
336
|
-
{
|
|
337
|
-
model: YpSubscription,
|
|
338
|
-
as: "Subscription",
|
|
339
|
-
//where: {
|
|
340
|
-
// domain_id: this.domainId
|
|
341
|
-
//},
|
|
342
|
-
include: [
|
|
343
|
-
{
|
|
344
|
-
model: YpAgentProduct,
|
|
345
|
-
as: "AgentProduct",
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
model: YpSubscriptionPlan,
|
|
349
|
-
as: "Plan",
|
|
350
|
-
},
|
|
351
|
-
],
|
|
352
|
-
},
|
|
353
|
-
],
|
|
354
|
-
});
|
|
355
|
-
return {
|
|
356
|
-
availableAgents: availableAgents.map((subscription) => ({
|
|
357
|
-
agentProductId: subscription.AgentProduct.id,
|
|
358
|
-
subscriptionId: subscription.id,
|
|
359
|
-
name: subscription.AgentProduct.name,
|
|
360
|
-
description: subscription.AgentProduct.description,
|
|
361
|
-
imageUrl: subscription.Plan.configuration.imageUrl || "",
|
|
362
|
-
isRunning: runningAgents.some((run) => run.Subscription?.AgentProduct?.id ===
|
|
363
|
-
subscription.AgentProduct.id),
|
|
364
|
-
})),
|
|
365
|
-
runningAgents: runningAgents.map((run) => ({
|
|
366
|
-
runId: run.id,
|
|
367
|
-
agentProductId: run.Subscription?.AgentProduct?.id || 0,
|
|
368
|
-
agentRunId: run.id,
|
|
369
|
-
agentName: run.Subscription?.AgentProduct?.name || "",
|
|
370
|
-
startTime: run.start_time,
|
|
371
|
-
status: run.status,
|
|
372
|
-
workflow: run.workflow,
|
|
373
|
-
subscriptionId: run.subscription_id,
|
|
374
|
-
})),
|
|
375
|
-
systemStatus: {
|
|
376
|
-
healthy: true,
|
|
377
|
-
lastUpdated: new Date(),
|
|
378
|
-
},
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
catch (error) {
|
|
382
|
-
console.error("Error loading agent status:", error);
|
|
383
|
-
return {
|
|
384
|
-
availableAgents: [],
|
|
385
|
-
runningAgents: [],
|
|
386
|
-
systemStatus: {
|
|
387
|
-
healthy: false,
|
|
388
|
-
lastUpdated: new Date(),
|
|
389
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
390
|
-
},
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
async unsubscribeFromAgentPlan(subscriptionId) {
|
|
395
|
-
try {
|
|
396
|
-
const subscription = await YpSubscription.findOne({
|
|
397
|
-
where: {
|
|
398
|
-
id: subscriptionId,
|
|
399
|
-
domain_id: this.assistant.domainId,
|
|
400
|
-
status: "active",
|
|
401
|
-
},
|
|
402
|
-
});
|
|
403
|
-
if (!subscription) {
|
|
404
|
-
return {
|
|
405
|
-
success: false,
|
|
406
|
-
error: "Subscription not found or already inactive",
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
subscription.status = "cancelled";
|
|
410
|
-
subscription.configuration = {
|
|
411
|
-
cancelledAt: new Date(),
|
|
412
|
-
cancelledByUserId: this.assistant.userId,
|
|
413
|
-
};
|
|
414
|
-
subscription.end_date = new Date();
|
|
415
|
-
subscription.changed("configuration", true);
|
|
416
|
-
await subscription.save();
|
|
417
|
-
return {
|
|
418
|
-
success: true,
|
|
419
|
-
subscriptionId: subscription.id,
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
catch (error) {
|
|
423
|
-
const errorMessage = error instanceof Error
|
|
424
|
-
? error.message
|
|
425
|
-
: "Failed to unsubscribe from agent plan";
|
|
426
|
-
console.error(`Database error in unsubscribeFromAgentPlan: ${errorMessage}`);
|
|
427
|
-
return {
|
|
428
|
-
success: false,
|
|
429
|
-
error: errorMessage,
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
async subscribeToAgentPlan(agentProductId, subscriptionPlanId) {
|
|
434
|
-
try {
|
|
435
|
-
const plan = await YpSubscriptionPlan.findByPk(subscriptionPlanId);
|
|
436
|
-
if (!plan) {
|
|
437
|
-
return {
|
|
438
|
-
success: false,
|
|
439
|
-
error: "Subscription plan not found",
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
const subscription = await YpSubscription.create({
|
|
443
|
-
subscription_plan_id: subscriptionPlanId,
|
|
444
|
-
agent_product_id: agentProductId,
|
|
445
|
-
user_id: this.assistant.userId,
|
|
446
|
-
domain_id: this.assistant.domainId,
|
|
447
|
-
next_billing_date: new Date(),
|
|
448
|
-
status: "active",
|
|
449
|
-
start_date: new Date(),
|
|
450
|
-
configuration: plan.configuration,
|
|
451
|
-
});
|
|
452
|
-
return {
|
|
453
|
-
success: true,
|
|
454
|
-
subscriptionId: subscription.id,
|
|
455
|
-
subscriptionPlanId: subscriptionPlanId,
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
catch (error) {
|
|
459
|
-
const errorMessage = error instanceof Error
|
|
460
|
-
? error.message
|
|
461
|
-
: "Failed to subscribe to agent plan";
|
|
462
|
-
console.error(`Database error in subscribeToAgentPlan: ${errorMessage}`);
|
|
463
|
-
return {
|
|
464
|
-
success: false,
|
|
465
|
-
error: errorMessage,
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|