@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,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,112 +0,0 @@
|
|
|
1
|
-
import { BaseAssistantTools } from "./baseTools.js";
|
|
2
|
-
export class WorkflowTools extends BaseAssistantTools {
|
|
3
|
-
constructor(assistant) {
|
|
4
|
-
super(assistant);
|
|
5
|
-
}
|
|
6
|
-
get show_running_workflow_conversations() {
|
|
7
|
-
return {
|
|
8
|
-
name: "show_running_workflow_conversations",
|
|
9
|
-
description: "Display running workflow conversations",
|
|
10
|
-
type: "function",
|
|
11
|
-
parameters: {
|
|
12
|
-
type: "object",
|
|
13
|
-
properties: {},
|
|
14
|
-
required: []
|
|
15
|
-
},
|
|
16
|
-
handler: this.showRunningWorkflowsHandler.bind(this)
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
async showRunningWorkflowsHandler(params) {
|
|
20
|
-
params = this.assistant.getCleanedParams(params);
|
|
21
|
-
console.log(`handler: show_running_workflows: ${JSON.stringify(params, null, 2)}`);
|
|
22
|
-
try {
|
|
23
|
-
const html = `<yp-workflow-widget-small running="true"></yp-workflow-widget-small>`;
|
|
24
|
-
return {
|
|
25
|
-
success: true,
|
|
26
|
-
html,
|
|
27
|
-
uniqueToken: "runningWorkflows",
|
|
28
|
-
data: { message: "Running workflows displayed successfully" },
|
|
29
|
-
metadata: { timestamp: new Date().toISOString() }
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
const errorMessage = error instanceof Error ? error.message : "Error displaying running workflows";
|
|
34
|
-
console.error(`Error in show_running_workflows: ${errorMessage}`);
|
|
35
|
-
return {
|
|
36
|
-
success: false,
|
|
37
|
-
error: errorMessage
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
get show_all_workflow_conversations() {
|
|
42
|
-
return {
|
|
43
|
-
name: "show_all_workflow_conversations",
|
|
44
|
-
description: "Display all workflow conversations",
|
|
45
|
-
type: "function",
|
|
46
|
-
parameters: {
|
|
47
|
-
type: "object",
|
|
48
|
-
properties: {},
|
|
49
|
-
required: []
|
|
50
|
-
},
|
|
51
|
-
handler: this.showAllWorkflowsHandler.bind(this)
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
async showAllWorkflowsHandler(params) {
|
|
55
|
-
params = this.assistant.getCleanedParams(params);
|
|
56
|
-
console.log(`handler: show_all_workflows: ${JSON.stringify(params, null, 2)}`);
|
|
57
|
-
try {
|
|
58
|
-
const html = `<yp-workflow-widget-small all="true"></yp-workflow-widget-small>`;
|
|
59
|
-
return {
|
|
60
|
-
success: true,
|
|
61
|
-
html,
|
|
62
|
-
uniqueToken: "allWorkflows",
|
|
63
|
-
data: { message: "All workflows displayed successfully" },
|
|
64
|
-
metadata: { timestamp: new Date().toISOString() }
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
const errorMessage = error instanceof Error ? error.message : "Error displaying all workflows";
|
|
69
|
-
console.error(`Error in show_all_workflows: ${errorMessage}`);
|
|
70
|
-
return {
|
|
71
|
-
success: false,
|
|
72
|
-
error: errorMessage
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
get connect_to_workflow_conversation() {
|
|
77
|
-
return {
|
|
78
|
-
name: "connect_to_workflow_conversation",
|
|
79
|
-
description: "Connect to an existing workflow conversation",
|
|
80
|
-
type: "function",
|
|
81
|
-
parameters: {
|
|
82
|
-
type: "object",
|
|
83
|
-
properties: {
|
|
84
|
-
workflowId: { type: "number" }
|
|
85
|
-
},
|
|
86
|
-
required: ["workflowId"]
|
|
87
|
-
},
|
|
88
|
-
handler: this.connectToWorkflowHandler.bind(this)
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
async connectToWorkflowHandler(params) {
|
|
92
|
-
params = this.assistant.getCleanedParams(params);
|
|
93
|
-
console.log(`handler: connect_to_workflow: ${JSON.stringify(params, null, 2)}`);
|
|
94
|
-
try {
|
|
95
|
-
const { workflowId } = params;
|
|
96
|
-
return {
|
|
97
|
-
success: true,
|
|
98
|
-
data: { message: `Connected to workflow ${workflowId} successfully` },
|
|
99
|
-
uniqueToken: `connectWorkflow_${workflowId}`,
|
|
100
|
-
metadata: { timestamp: new Date().toISOString() }
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
const errorMessage = error instanceof Error ? error.message : "Error connecting to workflow conversation";
|
|
105
|
-
console.error(`Error in connect_to_workflow_conversation: ${errorMessage}`);
|
|
106
|
-
return {
|
|
107
|
-
success: false,
|
|
108
|
-
error: errorMessage
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
import auth from "../../authorization.cjs";
|
|
3
|
-
import { YpAgentAssistant } from "../assistants/agentAssistant.js";
|
|
4
|
-
import { YpAgentProductBundle } from "../models/agentProductBundle.js";
|
|
5
|
-
import { YpAgentProductRun } from "../models/agentProductRun.js";
|
|
6
|
-
import { YpAgentProduct } from "../models/agentProduct.js";
|
|
7
|
-
import { YpAgentProductBoosterPurchase } from "../models/agentProductBoosterPurchase.js";
|
|
8
|
-
import { YpSubscription } from "../models/subscription.js";
|
|
9
|
-
import { YpSubscriptionPlan } from "../models/subscriptionPlan.js";
|
|
10
|
-
import { YpSubscriptionUser } from "../models/subscriptionUser.js";
|
|
11
|
-
import { YpDiscount } from "../models/discount.js";
|
|
12
|
-
import { sequelize } from "@policysynth/agents/dbModels/index.js";
|
|
13
|
-
import { NotificationAgentQueueManager } from "../managers/notificationAgentQueueManager.js";
|
|
14
|
-
const models = {
|
|
15
|
-
YpAgentProduct,
|
|
16
|
-
YpAgentProductBundle,
|
|
17
|
-
YpAgentProductBoosterPurchase,
|
|
18
|
-
YpAgentProductRun,
|
|
19
|
-
YpSubscription,
|
|
20
|
-
YpSubscriptionPlan,
|
|
21
|
-
YpSubscriptionUser,
|
|
22
|
-
YpDiscount,
|
|
23
|
-
};
|
|
24
|
-
export class AssistantController {
|
|
25
|
-
constructor(wsClients) {
|
|
26
|
-
this.path = "/api/assistants";
|
|
27
|
-
this.router = express.Router();
|
|
28
|
-
this.initializeModels = async () => {
|
|
29
|
-
try {
|
|
30
|
-
console.log(`All Models Loaded Init`);
|
|
31
|
-
// Call associate method to set up associations
|
|
32
|
-
for (const modelName of Object.keys(models)) {
|
|
33
|
-
if (models[modelName].associate) {
|
|
34
|
-
await models[modelName].associate(sequelize.models);
|
|
35
|
-
//await models[modelName].associate(models);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
console.log("All agentmodels initialized successfully.");
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
console.error("Error initializing models:", error);
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
this.startWorkflowAgent = async (req, res) => {
|
|
46
|
-
const { groupId, agentId, wsClientId } = req.params;
|
|
47
|
-
try {
|
|
48
|
-
const notificationManager = new NotificationAgentQueueManager(this.wsClients);
|
|
49
|
-
await notificationManager.startAgentProcessingWithWsClient(parseInt(agentId), parseInt(groupId), wsClientId);
|
|
50
|
-
res.sendStatus(200);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
console.error("Error starting agent:", error);
|
|
54
|
-
res.sendStatus(500);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
this.submitAgentConfiguration = async (req, res) => {
|
|
58
|
-
console.log(`submitAgentConfiguration: ${JSON.stringify(req.body, null, 2)}`);
|
|
59
|
-
const { agentProductId, subscriptionId, requiredQuestionsAnswers } = req.body;
|
|
60
|
-
try {
|
|
61
|
-
const memoryId = this.getMemoryUserId(req);
|
|
62
|
-
// Get subscription
|
|
63
|
-
const subscription = await YpSubscription.findOne({
|
|
64
|
-
where: {
|
|
65
|
-
id: subscriptionId,
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
if (!subscription) {
|
|
69
|
-
res.sendStatus(404);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
subscription.configuration.requiredQuestionsAnswered =
|
|
73
|
-
requiredQuestionsAnswers;
|
|
74
|
-
subscription.changed("configuration", true);
|
|
75
|
-
await subscription.save();
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
console.error("Error saving subscription:", error);
|
|
79
|
-
res.sendStatus(500);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
res.sendStatus(200);
|
|
83
|
-
};
|
|
84
|
-
this.updateAssistantMemoryLoginStatus = async (req, res) => {
|
|
85
|
-
if (req.user && req.params.domainId) {
|
|
86
|
-
try {
|
|
87
|
-
let memoryId = this.getMemoryUserId(req);
|
|
88
|
-
let redisKey = YpAgentAssistant.getRedisKey(memoryId);
|
|
89
|
-
console.log(`Starting to update login status for memoryId: ${memoryId} with user: ${req.user?.name}`);
|
|
90
|
-
let memory = (await YpAgentAssistant.loadMemoryFromRedis(memoryId));
|
|
91
|
-
if (memory) {
|
|
92
|
-
memory.currentUser = req.user;
|
|
93
|
-
await req.redisClient.set(redisKey, JSON.stringify(memory));
|
|
94
|
-
console.log(`Updated login status for memoryId: ${memoryId} with user: ${req.user?.name}`);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
console.error(`No memory found to update login status for id ${memoryId}`);
|
|
98
|
-
}
|
|
99
|
-
res.sendStatus(200);
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
console.error("Error updating login status:", error);
|
|
103
|
-
res.sendStatus(500);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
res.sendStatus(401);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
this.defaultStartAgentMode = "agent_selection_mode";
|
|
111
|
-
this.getMemoryUserId = (req) => {
|
|
112
|
-
const userIdentifier = req.body.clientMemoryUuid || req.query.clientMemoryUuid;
|
|
113
|
-
if (!userIdentifier) {
|
|
114
|
-
throw new Error("No user identifier found");
|
|
115
|
-
}
|
|
116
|
-
return `${req.params.domainId}-${userIdentifier}`;
|
|
117
|
-
};
|
|
118
|
-
this.clearChatLog = async (req, res) => {
|
|
119
|
-
try {
|
|
120
|
-
const memoryId = this.getMemoryUserId(req);
|
|
121
|
-
console.log(`Clearing chat log for memoryId: ${memoryId}`);
|
|
122
|
-
const redisKey = YpAgentAssistant.getRedisKey(memoryId);
|
|
123
|
-
const memory = (await YpAgentAssistant.loadMemoryFromRedis(memoryId));
|
|
124
|
-
if (memory) {
|
|
125
|
-
if (!memory.allChatLogs) {
|
|
126
|
-
memory.allChatLogs = [];
|
|
127
|
-
}
|
|
128
|
-
if (memory.chatLog) {
|
|
129
|
-
memory.allChatLogs = [...memory.allChatLogs, ...memory.chatLog];
|
|
130
|
-
}
|
|
131
|
-
memory.chatLog = [];
|
|
132
|
-
memory.currentMode = this.defaultStartAgentMode;
|
|
133
|
-
memory.haveShownConfigurationWidget = false;
|
|
134
|
-
memory.haveShownLoginWidget = false;
|
|
135
|
-
memory.currentAgentStatus = undefined;
|
|
136
|
-
if (!req.user) {
|
|
137
|
-
memory.currentUser = undefined;
|
|
138
|
-
}
|
|
139
|
-
await req.redisClient.set(redisKey, JSON.stringify(memory));
|
|
140
|
-
res.sendStatus(200);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
console.warn(`No memory found to clear for id ${memoryId}`);
|
|
144
|
-
res.sendStatus(200);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
console.error("Error clearing chat log:", error);
|
|
149
|
-
res.sendStatus(500);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
this.getMemory = async (req, res) => {
|
|
153
|
-
let memory;
|
|
154
|
-
let memoryId;
|
|
155
|
-
try {
|
|
156
|
-
memoryId = this.getMemoryUserId(req);
|
|
157
|
-
console.log(`Getting memory for memoryId: ${memoryId}`);
|
|
158
|
-
if (memoryId) {
|
|
159
|
-
memory = (await YpAgentAssistant.loadMemoryFromRedis(memoryId));
|
|
160
|
-
if (!memory) {
|
|
161
|
-
console.log(`memory not found for id ${memoryId}`);
|
|
162
|
-
memory = {
|
|
163
|
-
redisKey: YpAgentAssistant.getRedisKey(memoryId),
|
|
164
|
-
chatLog: [],
|
|
165
|
-
currentMode: this.defaultStartAgentMode,
|
|
166
|
-
modeHistory: [],
|
|
167
|
-
modeData: undefined,
|
|
168
|
-
};
|
|
169
|
-
await req.redisClient.set(memory.redisKey, JSON.stringify(memory));
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
if (req.user && !memory.currentUser) {
|
|
173
|
-
memory.currentUser = req.user;
|
|
174
|
-
await req.redisClient.set(memory.redisKey, JSON.stringify(memory));
|
|
175
|
-
}
|
|
176
|
-
else if (!req.user && memory.currentUser) {
|
|
177
|
-
memory.currentUser = undefined;
|
|
178
|
-
await req.redisClient.set(memory.redisKey, JSON.stringify(memory));
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
catch (error) {
|
|
184
|
-
console.log(error);
|
|
185
|
-
res.sendStatus(500);
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
if (memory) {
|
|
189
|
-
res.send(memory);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
console.error(`No memory found for memoryId: ${memoryId}`);
|
|
193
|
-
res.send({});
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
this.wsClients = wsClients;
|
|
197
|
-
this.initializeRoutes();
|
|
198
|
-
this.initializeModels();
|
|
199
|
-
}
|
|
200
|
-
initializeRoutes() {
|
|
201
|
-
this.router.put("/:domainId/chat", auth.can("view domain"), this.sendChatMessage.bind(this));
|
|
202
|
-
this.router.post("/:domainId/voice", auth.can("view domain"), this.startVoiceSession.bind(this));
|
|
203
|
-
this.router.get("/:domainId/memory", auth.can("view domain"), this.getMemory.bind(this));
|
|
204
|
-
this.router.delete("/:domainId/chatlog", auth.can("view domain"), this.clearChatLog.bind(this));
|
|
205
|
-
this.router.put("/:domainId/updateAssistantMemoryLoginStatus", this.updateAssistantMemoryLoginStatus.bind(this));
|
|
206
|
-
this.router.put("/:domainId/submitAgentConfiguration", this.submitAgentConfiguration.bind(this));
|
|
207
|
-
this.router.put("/:groupId/:agentId/startWorkflowAgent", this.startWorkflowAgent.bind(this));
|
|
208
|
-
}
|
|
209
|
-
async startVoiceSession(req, res) {
|
|
210
|
-
try {
|
|
211
|
-
const { wsClientId, currentMode } = req.body;
|
|
212
|
-
const memoryId = this.getMemoryUserId(req);
|
|
213
|
-
console.log(`Starting chat session for client: ${wsClientId}`);
|
|
214
|
-
const assistant = new YpAgentAssistant(wsClientId, this.wsClients, req.redisClient, true, parseInt(req.params.domainId), memoryId);
|
|
215
|
-
await assistant.initialize();
|
|
216
|
-
res.status(200).json({
|
|
217
|
-
message: "Voice session initialized",
|
|
218
|
-
wsClientId,
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
catch (error) {
|
|
222
|
-
console.error("Error starting chat session:", error);
|
|
223
|
-
res.status(500).json({ error: "Internal server error" });
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
async sendChatMessage(req, res) {
|
|
227
|
-
try {
|
|
228
|
-
const { wsClientId, chatLog, currentMode } = req.body;
|
|
229
|
-
const memoryId = this.getMemoryUserId(req);
|
|
230
|
-
console.log(`Starting chat session for client: ${wsClientId} with currentMode: ${currentMode}`);
|
|
231
|
-
const assistant = new YpAgentAssistant(wsClientId, this.wsClients, req.redisClient, false, parseInt(req.params.domainId), memoryId);
|
|
232
|
-
assistant.conversation(chatLog);
|
|
233
|
-
res.status(200).json({
|
|
234
|
-
message: "Chat session initialized",
|
|
235
|
-
wsClientId,
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
catch (error) {
|
|
239
|
-
console.error("Error starting chat session:", error);
|
|
240
|
-
res.status(500).json({ error: "Internal server error" });
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|