@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,863 +0,0 @@
|
|
|
1
|
-
import { YpBaseAssistantWithVoice } from "./baseAssistantWithVoice.js";
|
|
2
|
-
import { YpAgentProductRun } from "../models/agentProductRun.js";
|
|
3
|
-
import { YpAgentProduct } from "../models/agentProduct.js";
|
|
4
|
-
import { YpAgentProductBundle } from "../models/agentProductBundle.js";
|
|
5
|
-
import { YpSubscription } from "../models/subscription.js";
|
|
6
|
-
import { YpSubscriptionPlan } from "../models/subscriptionPlan.js";
|
|
7
|
-
import { NotificationAgentQueueManager } from "../managers/notificationAgentQueueManager.js";
|
|
8
|
-
import { DEBUG } from "bunyan";
|
|
9
|
-
export class YpAgentAssistantOld extends YpBaseAssistantWithVoice {
|
|
10
|
-
constructor() {
|
|
11
|
-
super(...arguments);
|
|
12
|
-
this.availableAgents = [];
|
|
13
|
-
this.runningAgents = [];
|
|
14
|
-
}
|
|
15
|
-
renderAllAgentsStatus() {
|
|
16
|
-
if (this.availableAgents?.length === 0 && this.runningAgents?.length === 0) {
|
|
17
|
-
return "";
|
|
18
|
-
}
|
|
19
|
-
return `<availableAgents>${JSON.stringify(this.availableAgents, null, 2)}</availableAgents>
|
|
20
|
-
<runningAgents>${JSON.stringify(this.runningAgents, null, 2)}</runningAgents> `;
|
|
21
|
-
}
|
|
22
|
-
renderCurrentWorkflowStatus() {
|
|
23
|
-
if (!this.currentWorkflow) {
|
|
24
|
-
return "";
|
|
25
|
-
}
|
|
26
|
-
return `<currentWorkflow>${JSON.stringify(this.currentWorkflow, null, 2)}</currentWorkflow>`;
|
|
27
|
-
}
|
|
28
|
-
renderCurrentAgent() {
|
|
29
|
-
if (!this.currentAgent) {
|
|
30
|
-
return "";
|
|
31
|
-
}
|
|
32
|
-
return `<currentAgent>${JSON.stringify(this.currentAgent, null, 2)}</currentAgent>`;
|
|
33
|
-
}
|
|
34
|
-
renderCommon() {
|
|
35
|
-
if (!this.memory.currentMode) {
|
|
36
|
-
return "";
|
|
37
|
-
}
|
|
38
|
-
console.log(`renderCommon: currentConversationMode ${this.memory.currentMode}`);
|
|
39
|
-
return `<currentConversationMode>${this.memory.currentMode}</currentConversationMode>`;
|
|
40
|
-
}
|
|
41
|
-
defineAvailableModes() {
|
|
42
|
-
return [
|
|
43
|
-
{
|
|
44
|
-
name: "agent_selection",
|
|
45
|
-
systemPrompt: `You are an AI agent assistant. Help users select and manage their AI agents.
|
|
46
|
-
Available commands:
|
|
47
|
-
- List available agents you are subscribed to
|
|
48
|
-
- List available agents available for purchase
|
|
49
|
-
- Select an agent you are subscribed to to work with
|
|
50
|
-
Current system status and available agents are provided via functions.
|
|
51
|
-
${this.renderCommon()}
|
|
52
|
-
${this.renderAllAgentsStatus()}`,
|
|
53
|
-
description: "List, browse and select agents",
|
|
54
|
-
functions: [
|
|
55
|
-
{
|
|
56
|
-
name: "list_my_agent_subscriptions",
|
|
57
|
-
description: "List all agent subscriptions for the current user.",
|
|
58
|
-
type: "function",
|
|
59
|
-
parameters: {
|
|
60
|
-
type: "object",
|
|
61
|
-
properties: {
|
|
62
|
-
includeDetails: { type: "boolean" },
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
/*resultSchema: {
|
|
66
|
-
type: "object",
|
|
67
|
-
properties: {
|
|
68
|
-
availableAgents: { type: "array", items: { type: "object" } },
|
|
69
|
-
runningAgents: { type: "array", items: { type: "object" } },
|
|
70
|
-
systemStatus: { type: "object" },
|
|
71
|
-
},
|
|
72
|
-
},*/
|
|
73
|
-
handler: async (params) => {
|
|
74
|
-
params = this.getCleanedParams(params);
|
|
75
|
-
console.log(`handler: list_my_agent_subscriptions: ${JSON.stringify(params, null, 2)}`);
|
|
76
|
-
try {
|
|
77
|
-
const status = (await this.loadMyAgentSubscriptions());
|
|
78
|
-
if (DEBUG) {
|
|
79
|
-
console.log(`list_my_agent_subscriptions: ${JSON.stringify(status, null, 2)}`);
|
|
80
|
-
}
|
|
81
|
-
let agentChips = ``;
|
|
82
|
-
for (const agent of status.availableAgents) {
|
|
83
|
-
agentChips += `<yp-agent-chip
|
|
84
|
-
agentId="${agent.id}"
|
|
85
|
-
agentName="${agent.name}"
|
|
86
|
-
agentDescription="${agent.description}"
|
|
87
|
-
agentImageUrl="${agent.imageUrl}"
|
|
88
|
-
></yp-agent-chip>`;
|
|
89
|
-
}
|
|
90
|
-
const html = `<div class="agent-chips">${agentChips}</div>`;
|
|
91
|
-
return {
|
|
92
|
-
success: true,
|
|
93
|
-
data: status,
|
|
94
|
-
html,
|
|
95
|
-
metadata: {
|
|
96
|
-
timestamp: new Date().toISOString(),
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
const errorMessage = error instanceof Error
|
|
102
|
-
? error.message
|
|
103
|
-
: "Failed to load agent status";
|
|
104
|
-
console.error(`Failed to load agent status: ${errorMessage}`);
|
|
105
|
-
return {
|
|
106
|
-
success: false,
|
|
107
|
-
data: errorMessage,
|
|
108
|
-
error: errorMessage,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: "list_all_agents_available_for_purchase",
|
|
115
|
-
description: "List all agent subscriptions available for purchase",
|
|
116
|
-
type: "function",
|
|
117
|
-
parameters: {
|
|
118
|
-
type: "object",
|
|
119
|
-
properties: {
|
|
120
|
-
includeDetails: { type: "boolean" },
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
/*resultSchema: {
|
|
124
|
-
type: "object",
|
|
125
|
-
properties: {
|
|
126
|
-
availableAgents: { type: "array", items: { type: "object" } },
|
|
127
|
-
runningAgents: { type: "array", items: { type: "object" } },
|
|
128
|
-
systemStatus: { type: "object" },
|
|
129
|
-
},
|
|
130
|
-
},*/
|
|
131
|
-
handler: async (params) => {
|
|
132
|
-
params = this.getCleanedParams(params);
|
|
133
|
-
console.log(`handler: list_all_agents_available_for_purchase: ${JSON.stringify(params, null, 2)}`);
|
|
134
|
-
try {
|
|
135
|
-
const status = (await this.loadAllAgentPlans());
|
|
136
|
-
if (DEBUG) {
|
|
137
|
-
console.log(`list_all_agents_available_for_purchase: ${JSON.stringify(status, null, 2)}`);
|
|
138
|
-
}
|
|
139
|
-
let agentChips = ``;
|
|
140
|
-
for (const agent of status.availablePlans) {
|
|
141
|
-
agentChips += `<yp-agent-chip-for-purchase
|
|
142
|
-
agentId="${agent.id}"
|
|
143
|
-
agentName="${agent.name}"
|
|
144
|
-
agentDescription="${agent.description}"
|
|
145
|
-
agentImageUrl="${agent.imageUrl}"
|
|
146
|
-
price="${agent.price}"
|
|
147
|
-
currency="${agent.currency}"
|
|
148
|
-
maxRunsPerCycle="${agent.maxRunsPerCycle}"
|
|
149
|
-
></yp-agent-chip-for-purchase>`;
|
|
150
|
-
}
|
|
151
|
-
const html = `<div class="agent-chips">${agentChips}</div>`;
|
|
152
|
-
return {
|
|
153
|
-
success: true,
|
|
154
|
-
data: status,
|
|
155
|
-
html,
|
|
156
|
-
metadata: {
|
|
157
|
-
timestamp: new Date().toISOString(),
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
catch (error) {
|
|
162
|
-
const errorMessage = error instanceof Error
|
|
163
|
-
? error.message
|
|
164
|
-
: "Failed to load agent status";
|
|
165
|
-
console.error(`Failed to load agent status: ${errorMessage}`);
|
|
166
|
-
return {
|
|
167
|
-
success: false,
|
|
168
|
-
data: errorMessage,
|
|
169
|
-
error: errorMessage,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
name: "select_agent",
|
|
176
|
-
description: "Select an agent to work with",
|
|
177
|
-
type: "function",
|
|
178
|
-
parameters: {
|
|
179
|
-
type: "object",
|
|
180
|
-
properties: {
|
|
181
|
-
agentProductId: { type: "number" },
|
|
182
|
-
},
|
|
183
|
-
required: ["agentProductId"],
|
|
184
|
-
},
|
|
185
|
-
handler: async (params) => {
|
|
186
|
-
console.log(`handler: select_agent: ${JSON.stringify(params, null, 2)}`);
|
|
187
|
-
try {
|
|
188
|
-
let cleanedParams = typeof params === "string" ? JSON.parse(params) : params;
|
|
189
|
-
const agent = await this.validateAndSelectAgent(cleanedParams.agentProductId);
|
|
190
|
-
const requiredQuestions = await this.getRequiredQuestions(cleanedParams.agentProductId);
|
|
191
|
-
this.currentAgentId = cleanedParams.agentProductId;
|
|
192
|
-
// If we have unanswered required questions, switch to configuration mode
|
|
193
|
-
if (requiredQuestions && requiredQuestions.length > 0) {
|
|
194
|
-
await this.handleModeSwitch("agent_configuration", "Required questions need to be answered");
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
await this.handleModeSwitch("agent_operations", "Agent ready for operations");
|
|
198
|
-
}
|
|
199
|
-
const html = `<div class="agent-chips"><yp-agent-chip
|
|
200
|
-
isSelected="true"
|
|
201
|
-
agentId="${agent.id}"
|
|
202
|
-
agentName="${agent.name}"
|
|
203
|
-
agentDescription="${agent.description}"
|
|
204
|
-
agentImageUrl="${agent.imageUrl}"
|
|
205
|
-
></yp-agent-chip></div>`;
|
|
206
|
-
return {
|
|
207
|
-
success: true,
|
|
208
|
-
html,
|
|
209
|
-
data: {
|
|
210
|
-
agent,
|
|
211
|
-
hasRequiredQuestions: requiredQuestions && requiredQuestions.length > 0,
|
|
212
|
-
},
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
catch (error) {
|
|
216
|
-
const errorMessage = error instanceof Error
|
|
217
|
-
? error.message
|
|
218
|
-
: "Failed to select agent";
|
|
219
|
-
console.error(`Failed to select agent: ${errorMessage}`);
|
|
220
|
-
return {
|
|
221
|
-
success: false,
|
|
222
|
-
data: errorMessage,
|
|
223
|
-
error: errorMessage,
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
},
|
|
228
|
-
],
|
|
229
|
-
allowedTransitions: ["agent_configuration", "agent_operations"],
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
name: "agent_configuration",
|
|
233
|
-
systemPrompt: `Help the user configure the selected agent by collecting required information.
|
|
234
|
-
Review the required questions and guide the user through answering them.
|
|
235
|
-
${this.renderCommon()}
|
|
236
|
-
${this.renderCurrentAgent()}`,
|
|
237
|
-
description: "Configure agent parameters and requirements",
|
|
238
|
-
functions: [
|
|
239
|
-
{
|
|
240
|
-
name: "show_question_form",
|
|
241
|
-
description: "Display form for required questions",
|
|
242
|
-
type: "function",
|
|
243
|
-
parameters: {
|
|
244
|
-
type: "object",
|
|
245
|
-
properties: {
|
|
246
|
-
agentProductId: { type: "number" },
|
|
247
|
-
},
|
|
248
|
-
required: ["agentProductId"],
|
|
249
|
-
},
|
|
250
|
-
handler: async (params) => {
|
|
251
|
-
params = this.getCleanedParams(params);
|
|
252
|
-
console.log(`handler: show_question_form: ${JSON.stringify(params, null, 2)}`);
|
|
253
|
-
try {
|
|
254
|
-
const questions = await this.getRequiredQuestions(params.agentProductId);
|
|
255
|
-
// Create HTML element for questions
|
|
256
|
-
let html = questions
|
|
257
|
-
.map((question) => `
|
|
258
|
-
<yp-structured-question
|
|
259
|
-
.question="${JSON.stringify(question)}"
|
|
260
|
-
></yp-structured-question>
|
|
261
|
-
`)
|
|
262
|
-
.join("\n");
|
|
263
|
-
return {
|
|
264
|
-
success: true,
|
|
265
|
-
data: questions,
|
|
266
|
-
html,
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
catch (error) {
|
|
270
|
-
const errorMessage = error instanceof Error
|
|
271
|
-
? error.message
|
|
272
|
-
: "Failed to show questions";
|
|
273
|
-
console.error(`Failed to show questions: ${errorMessage}`);
|
|
274
|
-
return {
|
|
275
|
-
success: false,
|
|
276
|
-
data: errorMessage,
|
|
277
|
-
error: errorMessage,
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
},
|
|
281
|
-
},
|
|
282
|
-
],
|
|
283
|
-
allowedTransitions: ["agent_operations"],
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
name: "agent_operations",
|
|
287
|
-
systemPrompt: `Help the user manage the selected agent's operations.
|
|
288
|
-
Available commands:
|
|
289
|
-
- Start/stop agent
|
|
290
|
-
- Get current status
|
|
291
|
-
- Handle engagement requests
|
|
292
|
-
- Show workflow
|
|
293
|
-
- Show workflow step details
|
|
294
|
-
Current agent status and workflow state are provided via functions.
|
|
295
|
-
${this.renderCommon()}
|
|
296
|
-
${this.renderAllAgentsStatus()}
|
|
297
|
-
${this.renderCurrentAgent()}
|
|
298
|
-
${this.renderCurrentWorkflowStatus()}`,
|
|
299
|
-
description: "Manage agent operations",
|
|
300
|
-
functions: [
|
|
301
|
-
{
|
|
302
|
-
name: "run_agent_next_workflow_step",
|
|
303
|
-
description: "Run the next step in the selected agent's workflow",
|
|
304
|
-
type: "function",
|
|
305
|
-
parameters: {
|
|
306
|
-
type: "object",
|
|
307
|
-
properties: {
|
|
308
|
-
configuration: { type: "object" },
|
|
309
|
-
},
|
|
310
|
-
},
|
|
311
|
-
handler: async (params) => {
|
|
312
|
-
params = this.getCleanedParams(params);
|
|
313
|
-
try {
|
|
314
|
-
if (!this.currentAgentId) {
|
|
315
|
-
throw new Error("No agent selected");
|
|
316
|
-
}
|
|
317
|
-
const result = await this.runAgentNextWorkflowStep(this.currentAgentId, params.configuration);
|
|
318
|
-
return {
|
|
319
|
-
success: true,
|
|
320
|
-
data: result,
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
catch (error) {
|
|
324
|
-
const errorMessage = error instanceof Error
|
|
325
|
-
? error.message
|
|
326
|
-
: "Failed to start agent";
|
|
327
|
-
console.error(`Failed to start agent: ${errorMessage}`);
|
|
328
|
-
return {
|
|
329
|
-
success: false,
|
|
330
|
-
data: errorMessage,
|
|
331
|
-
error: errorMessage,
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
},
|
|
335
|
-
},
|
|
336
|
-
{
|
|
337
|
-
name: "show_engagement_group",
|
|
338
|
-
description: "Show group for human engagement",
|
|
339
|
-
type: "function",
|
|
340
|
-
parameters: {
|
|
341
|
-
type: "object",
|
|
342
|
-
properties: {
|
|
343
|
-
groupId: { type: "number" },
|
|
344
|
-
},
|
|
345
|
-
required: ["groupId"],
|
|
346
|
-
},
|
|
347
|
-
handler: async (params) => {
|
|
348
|
-
params = this.getCleanedParams(params);
|
|
349
|
-
console.log(`handler: show_engagement_group: ${JSON.stringify(params, null, 2)}`);
|
|
350
|
-
try {
|
|
351
|
-
// Create HTML element for group
|
|
352
|
-
const html = `<div class="group-container"><yp-group
|
|
353
|
-
.groupId="${params.groupId}"
|
|
354
|
-
.configuration="${JSON.stringify(params.configuration)}"
|
|
355
|
-
></yp-group></div>`;
|
|
356
|
-
return {
|
|
357
|
-
success: true,
|
|
358
|
-
html,
|
|
359
|
-
data: {
|
|
360
|
-
groupId: params.groupId,
|
|
361
|
-
},
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
catch (error) {
|
|
365
|
-
const errorMessage = error instanceof Error
|
|
366
|
-
? error.message
|
|
367
|
-
: "Failed to show group";
|
|
368
|
-
console.error(`Failed to show group: ${errorMessage}`);
|
|
369
|
-
return {
|
|
370
|
-
success: false,
|
|
371
|
-
data: errorMessage,
|
|
372
|
-
error: errorMessage,
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
},
|
|
376
|
-
},
|
|
377
|
-
{
|
|
378
|
-
name: "stop_agent",
|
|
379
|
-
description: "Stop the currently running agent",
|
|
380
|
-
type: "function",
|
|
381
|
-
parameters: {
|
|
382
|
-
type: "object",
|
|
383
|
-
properties: {
|
|
384
|
-
reason: { type: "string" },
|
|
385
|
-
},
|
|
386
|
-
},
|
|
387
|
-
/*resultSchema: {
|
|
388
|
-
type: "object",
|
|
389
|
-
properties: {
|
|
390
|
-
agentId: { type: "number" },
|
|
391
|
-
stopTime: { type: "string" },
|
|
392
|
-
finalStatus: { type: "string" },
|
|
393
|
-
},
|
|
394
|
-
},*/
|
|
395
|
-
handler: async (params) => {
|
|
396
|
-
params = this.getCleanedParams(params);
|
|
397
|
-
console.log(`handler: stop_agent: ${JSON.stringify(params, null, 2)}`);
|
|
398
|
-
try {
|
|
399
|
-
if (!this.currentAgentId) {
|
|
400
|
-
throw new Error("No agent selected");
|
|
401
|
-
}
|
|
402
|
-
const result = await this.stopAgent(this.currentAgentId, params.reason);
|
|
403
|
-
return {
|
|
404
|
-
success: true,
|
|
405
|
-
data: {
|
|
406
|
-
agentId: this.currentAgentId,
|
|
407
|
-
stopTime: new Date().toISOString(),
|
|
408
|
-
finalStatus: result.status,
|
|
409
|
-
},
|
|
410
|
-
metadata: {
|
|
411
|
-
reason: params.reason,
|
|
412
|
-
},
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
catch (error) {
|
|
416
|
-
const errorMessage = error instanceof Error
|
|
417
|
-
? error.message
|
|
418
|
-
: "Failed to stop agent";
|
|
419
|
-
console.error(`Failed to stop agent: ${errorMessage}`);
|
|
420
|
-
return {
|
|
421
|
-
success: false,
|
|
422
|
-
data: errorMessage,
|
|
423
|
-
error: errorMessage,
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
},
|
|
427
|
-
},
|
|
428
|
-
{
|
|
429
|
-
name: "show_workflow_for_selected_agent",
|
|
430
|
-
description: "Display the workflow for the selected agent",
|
|
431
|
-
type: "function",
|
|
432
|
-
parameters: {
|
|
433
|
-
type: "object",
|
|
434
|
-
properties: {
|
|
435
|
-
agentProductId: { type: "number" },
|
|
436
|
-
},
|
|
437
|
-
required: ["agentProductId"],
|
|
438
|
-
},
|
|
439
|
-
/*resultSchema: {
|
|
440
|
-
type: "object",
|
|
441
|
-
properties: {
|
|
442
|
-
workflow: {
|
|
443
|
-
type: "object",
|
|
444
|
-
properties: {
|
|
445
|
-
steps: {
|
|
446
|
-
type: "array",
|
|
447
|
-
items: {
|
|
448
|
-
type: "object",
|
|
449
|
-
properties: {
|
|
450
|
-
id: { type: "number" },
|
|
451
|
-
name: { type: "string" },
|
|
452
|
-
status: { type: "string" },
|
|
453
|
-
type: { type: "string" },
|
|
454
|
-
completed: { type: "boolean" },
|
|
455
|
-
currentStep: { type: "boolean" },
|
|
456
|
-
},
|
|
457
|
-
},
|
|
458
|
-
},
|
|
459
|
-
currentStepId: { type: "number" },
|
|
460
|
-
progress: { type: "number" },
|
|
461
|
-
},
|
|
462
|
-
},
|
|
463
|
-
visualizationHtml: { type: "string" },
|
|
464
|
-
},
|
|
465
|
-
},*/
|
|
466
|
-
handler: async (params) => {
|
|
467
|
-
params = this.getCleanedParams(params);
|
|
468
|
-
console.log(`handler: show_workflow: ${JSON.stringify(params, null, 2)}`);
|
|
469
|
-
try {
|
|
470
|
-
if (!params.agentProductId) {
|
|
471
|
-
throw new Error("No agent selected");
|
|
472
|
-
}
|
|
473
|
-
const workflow = await this.getWorkflowStatus(params.agentProductId);
|
|
474
|
-
// Create visualization HTML
|
|
475
|
-
const html = `<div class="group-container"><yp-group
|
|
476
|
-
collectionId="31042"
|
|
477
|
-
></yp-group></div>`;
|
|
478
|
-
return {
|
|
479
|
-
success: true,
|
|
480
|
-
html,
|
|
481
|
-
data: { workFlowFound: true, workFlowDisplayed: true },
|
|
482
|
-
metadata: {
|
|
483
|
-
lastUpdated: new Date().toISOString(),
|
|
484
|
-
includesHistory: params.includeHistory,
|
|
485
|
-
showingDetails: params.showDetails,
|
|
486
|
-
},
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
catch (error) {
|
|
490
|
-
const errorMessage = error instanceof Error
|
|
491
|
-
? error.message
|
|
492
|
-
: "Failed to show workflow";
|
|
493
|
-
console.error(`Failed to show workflow: ${errorMessage}`);
|
|
494
|
-
return {
|
|
495
|
-
success: false,
|
|
496
|
-
data: errorMessage,
|
|
497
|
-
error: errorMessage,
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
},
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
name: "get_workflow_step_details",
|
|
504
|
-
description: "Get detailed information about a specific workflow step",
|
|
505
|
-
type: "function",
|
|
506
|
-
parameters: {
|
|
507
|
-
type: "object",
|
|
508
|
-
properties: {
|
|
509
|
-
stepId: { type: "number" },
|
|
510
|
-
includeArtifacts: { type: "boolean" },
|
|
511
|
-
},
|
|
512
|
-
required: ["stepId"],
|
|
513
|
-
},
|
|
514
|
-
/*resultSchema: {
|
|
515
|
-
type: "object",
|
|
516
|
-
properties: {
|
|
517
|
-
step: {
|
|
518
|
-
type: "object",
|
|
519
|
-
properties: {
|
|
520
|
-
id: { type: "number" },
|
|
521
|
-
name: { type: "string" },
|
|
522
|
-
type: { type: "string" },
|
|
523
|
-
status: { type: "string" },
|
|
524
|
-
startTime: { type: "string" },
|
|
525
|
-
endTime: { type: "string" },
|
|
526
|
-
duration: { type: "number" },
|
|
527
|
-
artifacts: {
|
|
528
|
-
type: "array",
|
|
529
|
-
items: { type: "object" },
|
|
530
|
-
},
|
|
531
|
-
},
|
|
532
|
-
},
|
|
533
|
-
},
|
|
534
|
-
},*/
|
|
535
|
-
handler: async (params) => {
|
|
536
|
-
console.log(`handler: get_workflow_step_details: ${JSON.stringify(params, null, 2)}`);
|
|
537
|
-
try {
|
|
538
|
-
if (!this.currentAgentId) {
|
|
539
|
-
throw new Error("No agent selected");
|
|
540
|
-
}
|
|
541
|
-
const stepDetails = await this.getWorkflowStepDetails(this.currentAgentId, params.stepId, params.includeArtifacts);
|
|
542
|
-
return {
|
|
543
|
-
success: true,
|
|
544
|
-
data: {
|
|
545
|
-
step: stepDetails,
|
|
546
|
-
},
|
|
547
|
-
metadata: {
|
|
548
|
-
requestedAt: new Date().toISOString(),
|
|
549
|
-
includesArtifacts: params.includeArtifacts,
|
|
550
|
-
},
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
catch (error) {
|
|
554
|
-
const errorMessage = error instanceof Error
|
|
555
|
-
? error.message
|
|
556
|
-
: "Failed to get step details";
|
|
557
|
-
console.error(`Failed to get step details: ${errorMessage}`);
|
|
558
|
-
return {
|
|
559
|
-
success: false,
|
|
560
|
-
data: errorMessage,
|
|
561
|
-
error: errorMessage,
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
},
|
|
565
|
-
},
|
|
566
|
-
],
|
|
567
|
-
allowedTransitions: ["agent_selection"],
|
|
568
|
-
},
|
|
569
|
-
];
|
|
570
|
-
}
|
|
571
|
-
async loadAllAgentPlans() {
|
|
572
|
-
try {
|
|
573
|
-
// Get all available subscription plans with their associated agent products
|
|
574
|
-
const availablePlans = await YpSubscriptionPlan.findAll({
|
|
575
|
-
where: {
|
|
576
|
-
// status: 'active', // Only get active plans
|
|
577
|
-
},
|
|
578
|
-
include: [
|
|
579
|
-
{
|
|
580
|
-
model: YpAgentProduct,
|
|
581
|
-
as: "AgentProduct",
|
|
582
|
-
attributes: {
|
|
583
|
-
exclude: ["created_at", "updated_at"],
|
|
584
|
-
},
|
|
585
|
-
include: [
|
|
586
|
-
{
|
|
587
|
-
model: YpAgentProductBundle,
|
|
588
|
-
as: "Bundles",
|
|
589
|
-
required: false,
|
|
590
|
-
attributes: {
|
|
591
|
-
exclude: ["created_at", "updated_at"],
|
|
592
|
-
},
|
|
593
|
-
},
|
|
594
|
-
],
|
|
595
|
-
},
|
|
596
|
-
],
|
|
597
|
-
});
|
|
598
|
-
return {
|
|
599
|
-
availablePlans: availablePlans.map((plan) => ({
|
|
600
|
-
id: plan.AgentProduct?.id || 0,
|
|
601
|
-
name: plan.AgentProduct?.name || plan.name,
|
|
602
|
-
description: plan.AgentProduct?.description || "No description available",
|
|
603
|
-
imageUrl: plan.configuration?.imageUrl || "",
|
|
604
|
-
price: plan.configuration?.amount || 0,
|
|
605
|
-
currency: plan.configuration?.currency || "USD",
|
|
606
|
-
maxRunsPerCycle: plan.configuration?.max_runs_per_cycle || 0,
|
|
607
|
-
})),
|
|
608
|
-
systemStatus: {
|
|
609
|
-
healthy: true,
|
|
610
|
-
lastUpdated: new Date(),
|
|
611
|
-
},
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
catch (error) {
|
|
615
|
-
console.error("Error loading available subscription plans:", error);
|
|
616
|
-
return {
|
|
617
|
-
availablePlans: [],
|
|
618
|
-
systemStatus: {
|
|
619
|
-
healthy: false,
|
|
620
|
-
lastUpdated: new Date(),
|
|
621
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
622
|
-
},
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
async loadMyAgentSubscriptions() {
|
|
627
|
-
try {
|
|
628
|
-
// Get available agent products from user's subscriptions for their domain
|
|
629
|
-
const availableAgents = await YpSubscription.findAll({
|
|
630
|
-
where: {
|
|
631
|
-
//domain_id: this.domainId, //TODO: get working
|
|
632
|
-
status: "active", // Only get active subscriptions
|
|
633
|
-
},
|
|
634
|
-
include: [
|
|
635
|
-
{
|
|
636
|
-
model: YpSubscriptionPlan,
|
|
637
|
-
as: "Plan",
|
|
638
|
-
},
|
|
639
|
-
{
|
|
640
|
-
model: YpAgentProduct,
|
|
641
|
-
as: "AgentProduct",
|
|
642
|
-
attributes: {
|
|
643
|
-
exclude: ["created_at", "updated_at"],
|
|
644
|
-
},
|
|
645
|
-
include: [
|
|
646
|
-
{
|
|
647
|
-
model: YpAgentProductBundle,
|
|
648
|
-
as: "Bundles",
|
|
649
|
-
required: false,
|
|
650
|
-
attributes: {
|
|
651
|
-
exclude: ["created_at", "updated_at"],
|
|
652
|
-
},
|
|
653
|
-
},
|
|
654
|
-
],
|
|
655
|
-
},
|
|
656
|
-
],
|
|
657
|
-
});
|
|
658
|
-
// Get currently running agents for the domain
|
|
659
|
-
const runningAgents = await YpAgentProductRun.findAll({
|
|
660
|
-
where: {
|
|
661
|
-
//domain_id: this.domainId, //TODO: get working
|
|
662
|
-
status: "running",
|
|
663
|
-
},
|
|
664
|
-
include: [
|
|
665
|
-
{
|
|
666
|
-
model: YpSubscription,
|
|
667
|
-
as: "Subscription",
|
|
668
|
-
//where: {
|
|
669
|
-
// domain_id: this.domainId
|
|
670
|
-
//},
|
|
671
|
-
include: [
|
|
672
|
-
{
|
|
673
|
-
model: YpAgentProduct,
|
|
674
|
-
as: "AgentProduct",
|
|
675
|
-
},
|
|
676
|
-
{
|
|
677
|
-
model: YpSubscriptionPlan,
|
|
678
|
-
as: "Plan",
|
|
679
|
-
},
|
|
680
|
-
],
|
|
681
|
-
},
|
|
682
|
-
],
|
|
683
|
-
});
|
|
684
|
-
return {
|
|
685
|
-
availableAgents: availableAgents.map((subscription) => ({
|
|
686
|
-
id: subscription.AgentProduct.id,
|
|
687
|
-
name: subscription.AgentProduct.name,
|
|
688
|
-
description: subscription.AgentProduct.description,
|
|
689
|
-
imageUrl: subscription.Plan.configuration.imageUrl || "",
|
|
690
|
-
isRunning: runningAgents.some((run) => run.Subscription?.AgentProduct?.id ===
|
|
691
|
-
subscription.AgentProduct.id),
|
|
692
|
-
})),
|
|
693
|
-
runningAgents: runningAgents.map((run) => ({
|
|
694
|
-
runId: run.id,
|
|
695
|
-
agentId: run.Subscription?.AgentProduct?.id || 0,
|
|
696
|
-
agentName: run.Subscription?.AgentProduct?.name || "",
|
|
697
|
-
startTime: run.start_time,
|
|
698
|
-
status: run.status,
|
|
699
|
-
workflow: run.workflow,
|
|
700
|
-
subscriptionId: run.subscription_id,
|
|
701
|
-
})),
|
|
702
|
-
systemStatus: {
|
|
703
|
-
healthy: true,
|
|
704
|
-
lastUpdated: new Date(),
|
|
705
|
-
},
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
catch (error) {
|
|
709
|
-
console.error("Error loading agent status:", error);
|
|
710
|
-
return {
|
|
711
|
-
availableAgents: [],
|
|
712
|
-
runningAgents: [],
|
|
713
|
-
systemStatus: {
|
|
714
|
-
healthy: false,
|
|
715
|
-
lastUpdated: new Date(),
|
|
716
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
717
|
-
},
|
|
718
|
-
};
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
async validateAndSelectAgent(agentId) {
|
|
722
|
-
// Implement agent validation logic
|
|
723
|
-
const status = await this.loadMyAgentSubscriptions();
|
|
724
|
-
const agent = status.availableAgents.find((a) => a.id === agentId);
|
|
725
|
-
if (!agent) {
|
|
726
|
-
throw new Error(`The users agent with agentProductId ${agentId} not found or not available in ${JSON.stringify(status.availableAgents, null, 2)}`);
|
|
727
|
-
}
|
|
728
|
-
return agent;
|
|
729
|
-
}
|
|
730
|
-
async stopAgent(agentId, reason) {
|
|
731
|
-
// Implement agent stop logic
|
|
732
|
-
// This should communicate with your backend API
|
|
733
|
-
const status = await this.loadMyAgentSubscriptions();
|
|
734
|
-
const runningAgent = status.runningAgents.find((a) => a.agentId === agentId);
|
|
735
|
-
if (!runningAgent) {
|
|
736
|
-
throw new Error("Agent is not running");
|
|
737
|
-
}
|
|
738
|
-
// Call your backend API to stop the agent
|
|
739
|
-
// This is a placeholder - implement actual API call
|
|
740
|
-
const stopResult = { status: "stopped", timestamp: new Date() };
|
|
741
|
-
// Update Redis status
|
|
742
|
-
runningAgent.status = "cancelled";
|
|
743
|
-
await this.redis.set("agent_status", JSON.stringify(status));
|
|
744
|
-
return stopResult;
|
|
745
|
-
}
|
|
746
|
-
async getRequiredQuestions(agentProductId) {
|
|
747
|
-
/*const status = await this.loadMyAgentSubscriptions();
|
|
748
|
-
const agent = status.availableAgents.find((a: any) => a.id === agentProductId);
|
|
749
|
-
|
|
750
|
-
if (!agent || !agent.configuration) {
|
|
751
|
-
return [];
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
const config = agent.configuration as YpAgentProductConfiguration;
|
|
755
|
-
return config.requiredStructuredQuestions || [];*/
|
|
756
|
-
return [];
|
|
757
|
-
}
|
|
758
|
-
async runAgentNextWorkflowStep(agentId, agentProductRunId) {
|
|
759
|
-
try {
|
|
760
|
-
// Get the agent product run to access the workflow
|
|
761
|
-
const agentProductRun = await YpAgentProductRun.findByPk(agentProductRunId);
|
|
762
|
-
if (!agentProductRun || !agentProductRun.workflow) {
|
|
763
|
-
throw new Error("Agent product run or workflow not found");
|
|
764
|
-
}
|
|
765
|
-
// Check if there's a next step
|
|
766
|
-
const nextStep = agentProductRun.workflow.steps[agentProductRun.workflow.currentStepIndex + 1];
|
|
767
|
-
if (!nextStep) {
|
|
768
|
-
// This was the last step, mark the run as completed
|
|
769
|
-
agentProductRun.status = "completed";
|
|
770
|
-
agentProductRun.end_time = new Date();
|
|
771
|
-
agentProductRun.duration = Math.floor((agentProductRun.end_time.getTime() -
|
|
772
|
-
agentProductRun.start_time.getTime()) /
|
|
773
|
-
1000);
|
|
774
|
-
await agentProductRun.save();
|
|
775
|
-
return { status: "completed", message: "Workflow completed" };
|
|
776
|
-
}
|
|
777
|
-
// Start the next agent in the workflow
|
|
778
|
-
const agentQueueManager = new NotificationAgentQueueManager(this.wsClients);
|
|
779
|
-
let success = false;
|
|
780
|
-
if (nextStep.agentId && this.wsClientId) {
|
|
781
|
-
success = await agentQueueManager.startAgentProcessingWithWsClient(nextStep.agentId, agentProductRunId, this.wsClientId);
|
|
782
|
-
}
|
|
783
|
-
if (!success) {
|
|
784
|
-
return {
|
|
785
|
-
status: "failed",
|
|
786
|
-
message: "Failed to start next workflow step",
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
else {
|
|
790
|
-
return {
|
|
791
|
-
status: "started",
|
|
792
|
-
agentId: nextStep.agentId,
|
|
793
|
-
message: "Next workflow step started",
|
|
794
|
-
};
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
catch (error) {
|
|
798
|
-
console.error("Error running next workflow step:", error);
|
|
799
|
-
throw new Error(`Failed to run next workflow step: ${error.message}`);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
async handleQuestionsSubmitted(event) {
|
|
803
|
-
const answers = event.detail;
|
|
804
|
-
if (this.currentAgentId) {
|
|
805
|
-
await this.redis.set(`agent:${this.currentAgentId}:answers`, JSON.stringify(answers));
|
|
806
|
-
await this.handleModeSwitch("agent_operations", "Configuration completed");
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
async getWorkflowStatus(agentId) {
|
|
810
|
-
// Get workflow configuration and current status
|
|
811
|
-
const configKey = `agent:${agentId}:workflow_config`;
|
|
812
|
-
const statusKey = `agent:${agentId}:workflow_status`;
|
|
813
|
-
const [configStr, statusStr] = await Promise.all([
|
|
814
|
-
this.redis.get(configKey),
|
|
815
|
-
this.redis.get(statusKey),
|
|
816
|
-
]);
|
|
817
|
-
const config = configStr
|
|
818
|
-
? JSON.parse(configStr)
|
|
819
|
-
: { steps: [] };
|
|
820
|
-
const status = statusStr
|
|
821
|
-
? JSON.parse(statusStr)
|
|
822
|
-
: {
|
|
823
|
-
currentStepId: config.steps[0]?.id,
|
|
824
|
-
progress: 0,
|
|
825
|
-
};
|
|
826
|
-
// Enhance steps with status information
|
|
827
|
-
const enhancedSteps = config.steps.map((step) => ({
|
|
828
|
-
...step,
|
|
829
|
-
status: step.id === status.currentStepId
|
|
830
|
-
? "active"
|
|
831
|
-
: step.id < status.currentStepId
|
|
832
|
-
? "completed"
|
|
833
|
-
: "pending",
|
|
834
|
-
completed: step.id < status.currentStepId,
|
|
835
|
-
currentStep: step.id === status.currentStepId,
|
|
836
|
-
}));
|
|
837
|
-
return {
|
|
838
|
-
...config,
|
|
839
|
-
steps: enhancedSteps,
|
|
840
|
-
currentStepId: status.currentStepId,
|
|
841
|
-
progress: status.progress,
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
async getWorkflowStepDetails(agentId, stepId, includeArtifacts) {
|
|
845
|
-
const key = `agent:${agentId}:step:${stepId}`;
|
|
846
|
-
const detailsStr = await this.redis.get(key);
|
|
847
|
-
const details = detailsStr ? JSON.parse(detailsStr) : null;
|
|
848
|
-
if (!details) {
|
|
849
|
-
throw new Error("Step details not found");
|
|
850
|
-
}
|
|
851
|
-
if (includeArtifacts) {
|
|
852
|
-
const artifactsKey = `agent:${agentId}:step:${stepId}:artifacts`;
|
|
853
|
-
const artifactsStr = await this.redis.get(artifactsKey);
|
|
854
|
-
details.artifacts = artifactsStr ? JSON.parse(artifactsStr) : [];
|
|
855
|
-
}
|
|
856
|
-
return details;
|
|
857
|
-
}
|
|
858
|
-
handleWorkflowStepSelected(event) {
|
|
859
|
-
const stepId = event.detail.stepId;
|
|
860
|
-
// Handle step selection - could trigger get_workflow_step_details
|
|
861
|
-
// or show specific UI components based on step type
|
|
862
|
-
}
|
|
863
|
-
}
|