@yrpri/api 9.0.139 → 9.0.140
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/assistants/agentAssistant.js +4 -3
- package/agents/assistants/baseAssistant.js +72 -71
- package/agents/assistants/baseAssistantWithVoice.js +6 -5
- package/agents/assistants/modes/agentDirectConnection.js +8 -7
- package/agents/assistants/modes/agentSelectionMode.js +2 -1
- package/agents/assistants/modes/baseAssistantMode.js +3 -2
- package/agents/assistants/modes/tools/agentTools.js +11 -10
- package/agents/assistants/modes/tools/loginTools.js +7 -6
- package/agents/assistants/modes/tools/models/agents.js +6 -5
- package/agents/assistants/modes/tools/models/subscriptions.js +7 -6
- package/agents/assistants/modes/tools/navigationTools.js +7 -6
- package/agents/assistants/modes/tools/subscriptionTools.js +12 -11
- package/agents/assistants/modes/tools/workflowConverstationTools.js +7 -6
- package/agents/assistants/voiceAssistant.js +45 -44
- package/agents/controllers/agentProductController.js +8 -7
- package/agents/controllers/agentSubscriptionController.js +13 -12
- package/agents/controllers/assistantsController.js +45 -44
- package/agents/controllers/policySynthAgents.js +33 -32
- package/agents/managers/emailInvitesManager.js +4 -3
- package/agents/managers/newAiModelSetup.js +45 -44
- package/agents/managers/notificationAgentQueueManager.js +55 -54
- package/agents/managers/subscriptionManager.js +24 -23
- package/agents/models/agentProduct.js +2 -1
- package/agents/models/agentProductBoosterPurchase.js +2 -1
- package/agents/models/testData/createEvolyAgentProduct.js +7 -6
- package/agents/models/testData/old/updateAgentWorkflowConfiguration.js +5 -4
- package/agents/models/testData/updateAgentWorkflowConfiguration.js +5 -4
- package/agents/tools/setTemplateWorkflowCommunityId.js +6 -5
- package/app.d.ts +2 -1
- package/app.js +60 -34
- package/authorization.cjs +4 -4
- package/controllers/allOurIdeas.js +45 -44
- package/controllers/groups.cjs +4 -9
- package/controllers/images.cjs +8 -8
- package/controllers/index.cjs +1 -1
- package/controllers/points.cjs +1 -1
- package/controllers/posts.cjs +3 -3
- package/deleteUnwantedDeclerations.cjs +5 -5
- package/models/community.cjs +1 -1
- package/models/domain.cjs +7 -7
- package/models/image.cjs +2 -2
- package/models/index.cjs +8 -4
- package/models/post.cjs +10 -10
- package/models/user.cjs +1 -1
- package/models/video.cjs +4 -4
- package/package.json +5 -5
- package/scripts/addRatingUsersToGroup.js +1 -1
- package/scripts/addUserToOrganization.js +8 -8
- package/scripts/agents/changeModelForWorkflowGroupTemplate.js +13 -12
- package/scripts/agents/generateAgentWorkflowTemplateFromAgentClass.js +5 -4
- package/scripts/analyseRatingsForCommunity.js +2 -2
- package/scripts/analyzeAndFixBrokenPointUsers.js +3 -3
- package/scripts/analyzeEndorsementsByCountry.js +7 -7
- package/scripts/analyzePostsForCommunity.js +1 -1
- package/scripts/bulkStatusUpdates/listUpdates.js +2 -2
- package/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +5 -5
- package/scripts/bulkStatusUpdates/performUpdate.js +9 -9
- package/scripts/bulkStatusUpdates/performUpdateForGroup.cjs +11 -11
- package/scripts/bulkStatusUpdates/performUpdateForStatus.js +15 -15
- package/scripts/change/changeVideoAspectTo.js +3 -3
- package/scripts/change/setUseNewVersion.cjs +4 -4
- package/scripts/changeCommunityGroupcount.js +3 -3
- package/scripts/changeCommunityPostCount.js +3 -3
- package/scripts/changeGroupPostCount.js +3 -3
- package/scripts/changeLanguage.js +4 -4
- package/scripts/changeOfficalStatus.js +3 -3
- package/scripts/cleanups/deleteAnonNotifications.cjs +7 -7
- package/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +8 -8
- package/scripts/cleanups/deleteYearOldNotifications.cjs +5 -5
- package/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +5 -5
- package/scripts/clearAllEndorsementInGroup.js +5 -5
- package/scripts/cloning/clearUsersForCommunitiesFromUrl.js +3 -3
- package/scripts/cloning/cloneFromUrlScript.js +4 -4
- package/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +6 -6
- package/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +6 -6
- package/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +6 -6
- package/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +3 -3
- package/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +2 -2
- package/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +2 -2
- package/scripts/cloning/copyCommunityToDomainWithEverything.js +2 -2
- package/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +3 -3
- package/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +3 -3
- package/scripts/cloning/copyPostToGroupOld.js +12 -12
- package/scripts/cloning/copyPostVideosFromURL.js +3 -3
- package/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +2 -2
- package/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +7 -7
- package/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +6 -6
- package/scripts/cloning/setAdminsFromURL.js +5 -5
- package/scripts/cloning/setExternalIdsFromURL.js +3 -3
- package/scripts/countCommunity.js +11 -11
- package/scripts/countCommunityUsers.js +4 -4
- package/scripts/countDelayedNotifications.js +3 -3
- package/scripts/countGroup.js +11 -11
- package/scripts/countStuff.js +3 -3
- package/scripts/countUniqueVotersInAGroup.js +3 -3
- package/scripts/createInvitesAndShow.js +2 -2
- package/scripts/database/sync_database.js +2 -2
- package/scripts/database/sync_dev_database.js +3 -3
- package/scripts/debugNotifications.js +5 -5
- package/scripts/deleteAllNewsFeeds.js +2 -2
- package/scripts/deleteCategory.js +1 -1
- package/scripts/deleteOldAppActivities.js +5 -4
- package/scripts/deletePostContactDataForCommunity.js +5 -4
- package/scripts/destroy/destroy_all_but_one_domain.js +59 -59
- package/scripts/displayAuthorForPost.js +1 -1
- package/scripts/domains/createDomain.js +5 -4
- package/scripts/domains/importDomainsFromXls.js +7 -6
- package/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +2 -2
- package/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +9 -9
- package/scripts/exportAllStatusChanges.js +5 -5
- package/scripts/exportEndorsementsForCommunity.js +5 -5
- package/scripts/exportPointQualitiesForCommunity.js +5 -5
- package/scripts/exportPostsAndPointsForCommunity.js +9 -9
- package/scripts/exportPostsDataSetForDomain.js +12 -12
- package/scripts/exportPostsForGroup.js +7 -7
- package/scripts/exportRatingsForPost.js +2 -2
- package/scripts/exportUserEndorsementsWithUserAnalysis.js +6 -6
- package/scripts/exportUsersForCommunity.js +3 -3
- package/scripts/exportUsersForDomain.js +3 -3
- package/scripts/exportUsersForGroup.js +3 -3
- package/scripts/exports/ratingDistribution.js +6 -6
- package/scripts/exports/whoEndorsedWhatByCommunity.js +2 -2
- package/scripts/findUnusedClientImports.js +2 -2
- package/scripts/fixAllPostPointCounts.js +1 -1
- package/scripts/fixAnonNotificationsSettings.js +5 -5
- package/scripts/fixCountKopavogur.js +1 -1
- package/scripts/fixEndorsementsAfterCopyPostToGroup.js +10 -10
- package/scripts/fixExternalUserId.js +2 -2
- package/scripts/fixGroupAccess.js +3 -3
- package/scripts/fixGroupIdeasAndPointsCount.js +2 -2
- package/scripts/fixNotificationSettings.js +4 -4
- package/scripts/fixSurveyRadioBakedInSubCodes.js +6 -6
- package/scripts/fixWrongUserIdForStatusUpdates.js +6 -5
- package/scripts/gallery/exportGalleryData.js +2 -2
- package/scripts/gallery/importGalleryForCommunity.js +14 -14
- package/scripts/gallery/readJsonAndDownloadImagesVersion2.js +6 -6
- package/scripts/gallery/refreshAcApiPostIdsForCommunity.js +5 -5
- package/scripts/genderAnalysis.js +10 -10
- package/scripts/genderAnalysisByStatus.js +4 -4
- package/scripts/importAllLocalesFromLocalFolders.js +7 -7
- package/scripts/importDomain.js +131 -131
- package/scripts/keys/addOidcToDomain.cjs +9 -9
- package/scripts/landUseGame/export3Ddata.js +15 -15
- package/scripts/listLanguagesForGroup.js +6 -6
- package/scripts/loadTestCreateDummyContentForGroup.js +2 -2
- package/scripts/makeRecursiveMapData.js +4 -4
- package/scripts/mapping/community_map_csv.js +5 -5
- package/scripts/moveCommunityToDomain.js +3 -3
- package/scripts/moveGroupToCommunity.js +3 -3
- package/scripts/movePostToGroup.js +5 -5
- package/scripts/movePostsToGroupsRecountGroupFromUrl.js +6 -6
- package/scripts/oldMovePostToGroup.js +9 -9
- package/scripts/processCsvForPdfUrls.js +2 -2
- package/scripts/processCsvForTranslationAndToxicity.js +10 -10
- package/scripts/recount/recount_recursive_communities.js +6 -6
- package/scripts/recountALLCommunityGroupCounts.js +4 -4
- package/scripts/recountAll.js +3 -3
- package/scripts/recountCommunitesFromUrl.js +3 -3
- package/scripts/recountCommunity.js +2 -2
- package/scripts/recountGroup.js +5 -5
- package/scripts/recountGroupNoUserChange.js +5 -5
- package/scripts/resetAllEndorsementsForGroup.js +3 -3
- package/scripts/resetEnTranslationForGroup.js +5 -5
- package/scripts/setAdminOnAll.cjs +14 -14
- package/scripts/setDomainAdmin.cjs +6 -6
- package/scripts/setDomainLocales.js +2 -2
- package/scripts/setEarlQuestionIdOnGroup.cjs +4 -4
- package/scripts/setLanguageOnGroupCommunitesFromUrl.js +3 -3
- package/scripts/setMemberOfAll.js +14 -14
- package/scripts/setNewUserForContentOfCommunity.js +9 -9
- package/scripts/setOfficialStatusOnAllPostsForCommunity.js +1 -1
- package/scripts/setUserOnAll.js +14 -14
- package/scripts/showCategoryForGroup.js +1 -1
- package/scripts/showOldActivityTypes.js +3 -3
- package/scripts/showPostsMissingCategoryForGroup.js +2 -2
- package/scripts/showStatuses.js +4 -4
- package/scripts/showUniqueVotersInCommunity.js +4 -4
- package/scripts/showUserAgentsAndIpsForEmails.js +4 -4
- package/scripts/simpleExportForGroupsForCommunity.js +5 -5
- package/scripts/simpleExportForPointsForCommunity.js +5 -5
- package/scripts/simpleExportForPostsForCommunity.js +5 -5
- package/scripts/testForEndorsments.js +4 -4
- package/scripts/undeleteGroupAndAllContent.js +8 -8
- package/scripts/undeletePost.js +7 -7
- package/scripts/unlinkSsn.js +4 -4
- package/scripts/updateFromAlthingi.js +8 -8
- package/scripts/users/createUserAddDomain.js +6 -5
- package/scripts/users/importUsersForDomainsFromXls.js +4 -3
- package/scripts/users/listDomainUsersWithSsn.js +6 -5
- package/scripts/users/removeUserFromDomain.js +6 -5
- package/scripts/users/updatePasswordFromSsn.js +5 -4
- package/scripts/users/updateUserSsnFromEmail.js +5 -4
- package/services/controllers/activities.cjs +1 -1
- package/services/controllers/news_feeds.cjs +1 -1
- package/services/controllers/notifications.cjs +1 -1
- package/services/controllers/recommendations.cjs +1 -1
- package/services/engine/allOurIdeas/aiHelper.js +10 -9
- package/services/engine/analytics/export_anon_community_activities.js +3 -3
- package/services/engine/analytics/importer.js +10 -10
- package/services/engine/analytics/plausible/manager.cjs +4 -4
- package/services/engine/analytics/statsCalc.cjs +1 -1
- package/services/engine/analytics/utils.cjs +10 -10
- package/services/engine/moderation/fraud/CreateFraudAuditReport.cjs +2 -1
- package/services/engine/moderation/fraud/FraudBase.cjs +2 -2
- package/services/engine/moderation/fraud/FraudDeleteBase.cjs +4 -4
- package/services/engine/moderation/fraud/FraudGetBase.cjs +1 -1
- package/services/engine/moderation/fraud/FraudGetEndorsements.cjs +1 -1
- package/services/engine/moderation/fraud/FraudGetPointQualities.cjs +1 -1
- package/services/engine/moderation/fraud/FraudGetPoints.cjs +1 -1
- package/services/engine/moderation/fraud/FraudGetPosts.cjs +1 -1
- package/services/engine/moderation/fraud/FraudGetRatings.cjs +1 -1
- package/services/engine/moderation/fraud/FraudScannerNotifier.cjs +9 -9
- package/services/engine/moderation/get_moderation_items.cjs +1 -1
- package/services/engine/moderation/image_labeling/ImageLabelingBase.cjs +1 -1
- package/services/engine/moderation/process_moderation_items.cjs +1 -1
- package/services/engine/moderation/toxicity_analysis.cjs +1 -1
- package/services/engine/news_feeds/generate_dynamically.cjs +1 -1
- package/services/engine/news_feeds/generate_from_notifications.cjs +1 -1
- package/services/engine/notifications/emails_utils.cjs +2 -2
- package/services/engine/notifications/generate_point_notifications.cjs +1 -1
- package/services/engine/notifications/generate_post_notifications.cjs +1 -1
- package/services/engine/notifications/process_delayed_notifications.cjs +38 -38
- package/services/engine/old/exporters/categories_dataset.js +11 -11
- package/services/engine/old/exporters/sentiment_dataset.js +12 -12
- package/services/engine/recommendations/events_importer.cjs +5 -5
- package/services/engine/recommendations/events_manager.cjs +1 -1
- package/services/engine/reports/add_points_to_sheet.cjs +2 -2
- package/services/engine/reports/commonUtils.js +3 -2
- package/services/engine/reports/common_utils.cjs +8 -8
- package/services/engine/reports/docx_group_report.cjs +1 -1
- package/services/engine/reports/xlsAllOurIdeasExport.js +16 -15
- package/services/engine/reports/xls_community_users_report.cjs +2 -2
- package/services/engine/reports/xls_group_report.cjs +1 -1
- package/services/llms/baseChatBot.js +12 -11
- package/services/llms/imageGeneration/chatGptImageGenerator.js +3 -2
- package/services/llms/imageGeneration/collectionImageGenerator.js +7 -6
- package/services/llms/imageGeneration/dalleImageGenerator.js +6 -5
- package/services/llms/imageGeneration/fluxImageGenerator.js +5 -4
- package/services/llms/imageGeneration/imageProcessorService.js +2 -1
- package/services/llms/imageGeneration/imagenImageGenerator.js +8 -7
- package/services/llms/imageGeneration/s3Service.js +12 -11
- package/services/llms/llmTranslation.js +30 -29
- package/services/models/ac_activity.cjs +1 -1
- package/services/models/ac_notification.cjs +1 -1
- package/services/models/ac_translation_cache.cjs +11 -11
- package/services/scripts/analytics/setup_all_plausible_goals.cjs +2 -2
- package/services/scripts/fix_old_delayed_notifications.js +3 -3
- package/services/scripts/kue_status.js +11 -11
- package/services/scripts/kue_watch_stuck_jobs.js +6 -6
- package/services/scripts/translation_clear_language.js +21 -21
- package/services/scripts/translation_delete.js +4 -4
- package/services/scripts/translation_replace_text_from_url.js +4 -4
- package/services/scripts/translation_update.js +4 -4
- package/services/scripts/translations_list.js +5 -5
- package/services/utils/airbrake.cjs +2 -1
- package/services/utils/redisConnection.cjs +6 -5
- package/services/utils/translation_helpers.cjs +3 -2
- package/services/utils/updateAllLocalesFromEn.js +20 -19
- package/services/utils/updateLocaleFolders.js +7 -6
- package/services/workers/activity.cjs +1 -1
- package/services/workers/anonymizations.cjs +1 -1
- package/services/workers/bulk_status_update.cjs +2 -2
- package/services/workers/delayed_jobs.cjs +1 -1
- package/services/workers/deletions.cjs +1 -1
- package/services/workers/email.cjs +1 -1
- package/services/workers/fraud_management.cjs +3 -3
- package/services/workers/generativeAi.js +6 -5
- package/services/workers/main.cjs +1 -1
- package/services/workers/marketing.cjs +1 -1
- package/services/workers/moderation.cjs +1 -1
- package/services/workers/notification_delivery.cjs +1 -1
- package/services/workers/notification_news_feed.cjs +1 -1
- package/services/workers/queue.cjs +2 -2
- package/services/workers/recount.cjs +1 -1
- package/services/workers/reports.cjs +1 -1
- package/services/workers/similarities.cjs +4 -2
- package/services/workers/speech_to_text.cjs +1 -1
- package/utils/airbrake.cjs +1 -1
- package/utils/cjsCodeReview.js +7 -6
- package/utils/community_mapping_tools.cjs +2 -2
- package/utils/copy_utils.cjs +31 -31
- package/utils/export_utils.cjs +7 -7
- package/utils/generateDocumentation.js +10 -9
- package/utils/logger.cjs +2 -23
- package/utils/logger.d.cts +1 -1
- package/utils/loggerAirbrakeTransport.cjs +52 -0
- package/utils/loggerAirbrakeTransport.d.cts +15 -0
- package/utils/loggerAirbrakeTransportTs.d.ts +15 -0
- package/utils/loggerAirbrakeTransportTs.js +45 -0
- package/utils/loggerCore.cjs +29 -0
- package/utils/loggerCore.d.cts +2 -0
- package/utils/loggerCoreTs.d.ts +2 -0
- package/utils/loggerCoreTs.js +23 -0
- package/utils/loggerTs.d.ts +1 -2
- package/utils/loggerTs.js +2 -25
- package/utils/recount_utils.cjs +5 -5
- package/utils/seedModels.js +50 -49
- package/utils/sitemap_generator.cjs +4 -4
- package/utils/ypLanguages.js +2 -2
- package/webSockets.js +8 -7
- package/services/utils/logger.cjs +0 -25
- package/services/utils/logger.d.cts +0 -2
- package/src/agents/assistants/assistant.d.ts +0 -156
- package/src/controllers/audios.d.ts +0 -5
- package/src/controllers/categories.d.ts +0 -5
- package/src/controllers/communities.d.ts +0 -5
- package/src/controllers/domains.d.ts +0 -5
- package/src/controllers/groups.d.ts +0 -5
- package/src/controllers/images.d.ts +0 -5
- package/src/controllers/points.d.ts +0 -5
- package/src/controllers/posts.d.ts +0 -5
- package/src/controllers/ratings.d.ts +0 -5
- package/src/controllers/users.d.ts +0 -5
- package/src/controllers/videos.d.ts +0 -5
- package/src/models/index.d.ts +0 -84
- package/src/services/controllers/activities.d.ts +0 -5
- package/src/services/controllers/notifications.d.ts +0 -5
- package/src/utils/copy_utils.d.ts +0 -4
- package/src/utils/manifest_generator.d.ts +0 -18
|
@@ -3,6 +3,7 @@ import { YpBaseAssistantWithVoice } from "./baseAssistantWithVoice.js";
|
|
|
3
3
|
import { AgentSelectionMode } from "./modes/agentSelectionMode.js";
|
|
4
4
|
import { DirectConversationMode } from "./modes/agentDirectConnection.js";
|
|
5
5
|
import { SubscriptionManager } from "../managers/subscriptionManager.js";
|
|
6
|
+
import log from "../../utils/loggerTs.js";
|
|
6
7
|
export class YpAgentAssistant extends YpBaseAssistantWithVoice {
|
|
7
8
|
constructor(wsClientId, wsClients, redis, voiceEnabled, redisKey, domainId) {
|
|
8
9
|
super(wsClientId, wsClients, redis, voiceEnabled, redisKey, domainId);
|
|
@@ -30,7 +31,7 @@ export class YpAgentAssistant extends YpBaseAssistantWithVoice {
|
|
|
30
31
|
}
|
|
31
32
|
handleMemoryChanged(memory) {
|
|
32
33
|
if (this.DEBUG) {
|
|
33
|
-
|
|
34
|
+
log.info(`Sending memory changed to client: ${JSON.stringify(this.simplifiedMemory, null, 2)}`);
|
|
34
35
|
}
|
|
35
36
|
this.sendToClient("system", JSON.stringify(this.simplifiedMemory), "memory-changed");
|
|
36
37
|
}
|
|
@@ -39,12 +40,12 @@ export class YpAgentAssistant extends YpBaseAssistantWithVoice {
|
|
|
39
40
|
}
|
|
40
41
|
get isSubscribedToCurrentAgentProduct() {
|
|
41
42
|
if (this.DEBUG) {
|
|
42
|
-
|
|
43
|
+
log.info(`-------------------------------------------> isSubscribedToCurrentAgent: ${JSON.stringify(this.memory.currentAgentStatus, null, 2)}`);
|
|
43
44
|
}
|
|
44
45
|
return this.memory.currentAgentStatus?.subscriptionId != undefined;
|
|
45
46
|
}
|
|
46
47
|
get hasConfiguredcurrentAgentProduct() {
|
|
47
|
-
|
|
48
|
+
log.info(`configuration: ${this.redisKey}: ${JSON.stringify(this.memory.currentAgentStatus, null, 2)}`);
|
|
48
49
|
return this.memory.currentAgentStatus?.configurationState === "configured";
|
|
49
50
|
}
|
|
50
51
|
async isCurrentAgentRunning() {
|
|
@@ -5,6 +5,7 @@ import { YpAgentProduct } from "../models/agentProduct.js";
|
|
|
5
5
|
import { YpSubscription } from "../models/subscription.js";
|
|
6
6
|
import { YpSubscriptionPlan } from "../models/subscriptionPlan.js";
|
|
7
7
|
import { YpAgentProductRun } from "../models/agentProductRun.js";
|
|
8
|
+
import log from "../../utils/loggerTs.js";
|
|
8
9
|
/**
|
|
9
10
|
* Common modes that implementations might use
|
|
10
11
|
*/
|
|
@@ -76,22 +77,22 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
76
77
|
const message = JSON.parse(data.toString());
|
|
77
78
|
switch (message.type) {
|
|
78
79
|
case "client_system_message":
|
|
79
|
-
|
|
80
|
+
log.info("WebSockets: Processing client_system_message:", message);
|
|
80
81
|
this.processClientSystemMessage(message);
|
|
81
82
|
break;
|
|
82
83
|
default:
|
|
83
|
-
//
|
|
84
|
+
//log.info('Unhandled message type:', message.type);
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
catch (error) {
|
|
87
|
-
|
|
88
|
+
log.error("Error processing message:", error);
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
setupClientSystemMessageListener() {
|
|
91
|
-
|
|
92
|
+
log.info("WebSockets: setupClientSystemMessageListener called for wsClientId:", this.wsClientId, this.clientSystemMessageListener);
|
|
92
93
|
this.wsClientSocket.on("message", this.clientSystemMessageListener);
|
|
93
94
|
const listenerCountAfter = this.wsClientSocket.listenerCount("message");
|
|
94
|
-
|
|
95
|
+
log.info('Number of "message" listeners after adding:', listenerCountAfter);
|
|
95
96
|
}
|
|
96
97
|
async getCurrentAgentProduct() {
|
|
97
98
|
if (this.memory.currentAgentStatus?.subscriptionPlanId) {
|
|
@@ -109,7 +110,7 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
109
110
|
return subscriptionPlan?.AgentProduct;
|
|
110
111
|
}
|
|
111
112
|
else {
|
|
112
|
-
|
|
113
|
+
log.error("--------------------> No subscription plan found");
|
|
113
114
|
}
|
|
114
115
|
return undefined;
|
|
115
116
|
}
|
|
@@ -142,30 +143,30 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
142
143
|
}));
|
|
143
144
|
}
|
|
144
145
|
else {
|
|
145
|
-
|
|
146
|
+
log.error("No active agent run found");
|
|
146
147
|
}
|
|
147
148
|
return undefined;
|
|
148
149
|
}
|
|
149
150
|
async updateAiModelSession(message) {
|
|
150
|
-
|
|
151
|
+
log.info(`updateAiModelSession: ${message}`);
|
|
151
152
|
}
|
|
152
153
|
async maybeSendTextResponse(message) {
|
|
153
154
|
if (!this.voiceEnabled) {
|
|
154
155
|
this.sendToClient("assistant", message, "message");
|
|
155
156
|
await this.addAssistantMessage(message);
|
|
156
|
-
|
|
157
|
+
log.debug(`Sent text message to client: ${message}`);
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
async processClientSystemMessage(clientEvent) {
|
|
160
|
-
|
|
161
|
+
log.info(`processClientSystemMessage: ${JSON.stringify(clientEvent, null, 2)}`);
|
|
161
162
|
await this.loadMemoryAsync();
|
|
162
163
|
if (clientEvent.message === "user_logged_in") {
|
|
163
|
-
|
|
164
|
+
log.info(`user_logged_in emitting`);
|
|
164
165
|
this.emit("update-ai-model-session", "User is logged in, lets move to the next step");
|
|
165
166
|
await this.maybeSendTextResponse("Logged in, ready to move on to the next step.");
|
|
166
167
|
}
|
|
167
168
|
else if (clientEvent.message === "agent_configuration_submitted") {
|
|
168
|
-
|
|
169
|
+
log.info(`agent_configuration_submitted emitting`);
|
|
169
170
|
try {
|
|
170
171
|
if (!this.memory.currentAgentStatus.subscriptionId) {
|
|
171
172
|
throw new Error("No subscription found");
|
|
@@ -190,13 +191,13 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
190
191
|
await this.maybeSendTextResponse("The agent configuration was submitted successfully and the agent is ready to create its first agent run.");
|
|
191
192
|
}
|
|
192
193
|
catch (error) {
|
|
193
|
-
|
|
194
|
+
log.error(`Error finding subscription: ${error}`);
|
|
194
195
|
this.emit("update-ai-model-session", `Failed to submit agent configuration: ${error}`);
|
|
195
196
|
}
|
|
196
197
|
}
|
|
197
198
|
else if (clientEvent.message === "agent_run_changed") {
|
|
198
199
|
try {
|
|
199
|
-
|
|
200
|
+
log.info(`agent_run_changed`);
|
|
200
201
|
if (!this.memory.currentAgentStatus?.activeAgentRunId) {
|
|
201
202
|
throw new Error("No active agent run found");
|
|
202
203
|
}
|
|
@@ -208,12 +209,12 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
208
209
|
if (!agentRun) {
|
|
209
210
|
throw new Error("No agent run found");
|
|
210
211
|
}
|
|
211
|
-
|
|
212
|
+
log.info(`agent_run_changed emitting`);
|
|
212
213
|
const currentWorkflowStep = agentRun.workflow?.steps[agentRun.workflow?.currentStepIndex];
|
|
213
214
|
this.emit("update-ai-model-session", `The agent run status has been updated to ${agentRun.status} ${JSON.stringify({ workflow: agentRun.workflow, currentWorkflowStep }, null, 2)} offer the user assistance with this next step in the workflow`);
|
|
214
215
|
}
|
|
215
216
|
catch (error) {
|
|
216
|
-
|
|
217
|
+
log.error(`Error finding agent run: ${error}`);
|
|
217
218
|
this.emit("update-ai-model-session", `Failed to update agent run status: ${error}`);
|
|
218
219
|
}
|
|
219
220
|
}
|
|
@@ -254,7 +255,7 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
254
255
|
? "configured"
|
|
255
256
|
: "not_configured",
|
|
256
257
|
};
|
|
257
|
-
|
|
258
|
+
log.info(`updateCurrentAgentProductPlan: ${JSON.stringify(this.memory.currentAgentStatus, null, 2)}`);
|
|
258
259
|
await this.saveMemory();
|
|
259
260
|
}
|
|
260
261
|
/**
|
|
@@ -262,7 +263,7 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
262
263
|
*/
|
|
263
264
|
convertToolResultToMessage(toolCall, result) {
|
|
264
265
|
if (this.DEBUG) {
|
|
265
|
-
|
|
266
|
+
log.info(`convertToolResultToMessage: ${JSON.stringify(toolCall, null, 2)}`);
|
|
266
267
|
}
|
|
267
268
|
return {
|
|
268
269
|
role: "tool",
|
|
@@ -276,7 +277,7 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
276
277
|
*/
|
|
277
278
|
async handleToolCalls(toolCalls) {
|
|
278
279
|
if (this.DEBUG) {
|
|
279
|
-
|
|
280
|
+
log.info(`====================================> handleToolCalls: ${JSON.stringify(Array.from(toolCalls.values()), null, 2)}`);
|
|
280
281
|
}
|
|
281
282
|
const toolResponses = [];
|
|
282
283
|
for (const toolCall of toolCalls.values()) {
|
|
@@ -295,7 +296,7 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
295
296
|
// Execute the function and get result
|
|
296
297
|
const result = await func.handler(parsedArgs);
|
|
297
298
|
if (this.DEBUG) {
|
|
298
|
-
|
|
299
|
+
log.info(`----------------------------------> Tool execution result:`, JSON.stringify(result, null, 2));
|
|
299
300
|
}
|
|
300
301
|
// Store the result in memory for context
|
|
301
302
|
if (result.success && result.data) {
|
|
@@ -319,7 +320,7 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
319
320
|
await this.saveMemoryIfNeeded();
|
|
320
321
|
}
|
|
321
322
|
else {
|
|
322
|
-
|
|
323
|
+
log.error(`No data returned from tool execution: ${toolCall.name}`);
|
|
323
324
|
}
|
|
324
325
|
if (result.html) {
|
|
325
326
|
this.sendToClient("assistant", result.html, "html", result.uniqueToken, true);
|
|
@@ -327,7 +328,7 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
327
328
|
}
|
|
328
329
|
if (result.clientEvents) {
|
|
329
330
|
if (this.DEBUG) {
|
|
330
|
-
|
|
331
|
+
log.info(`clientEvents: ${JSON.stringify(result.clientEvents, null, 2)}`);
|
|
331
332
|
}
|
|
332
333
|
for (const clientEvent of result.clientEvents) {
|
|
333
334
|
this.sendToClient("assistant", clientEvent.details, clientEvent.name);
|
|
@@ -335,12 +336,12 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
335
336
|
}
|
|
336
337
|
// If error, throw it after recording the result
|
|
337
338
|
if (!result.success) {
|
|
338
|
-
|
|
339
|
+
log.error(`Unknown error in tool execution: ${result.error}`);
|
|
339
340
|
}
|
|
340
341
|
}
|
|
341
342
|
catch (error) {
|
|
342
343
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
343
|
-
|
|
344
|
+
log.error(`Error executing tool ${toolCall.name}: ${errorMessage}`);
|
|
344
345
|
throw error;
|
|
345
346
|
}
|
|
346
347
|
}
|
|
@@ -354,7 +355,7 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
354
355
|
*/
|
|
355
356
|
async handleToolResponses(toolResponses) {
|
|
356
357
|
if (this.DEBUG) {
|
|
357
|
-
|
|
358
|
+
log.info(`handleToolResponses: ${JSON.stringify(toolResponses, null, 2)}`);
|
|
358
359
|
}
|
|
359
360
|
// Get existing chat messages
|
|
360
361
|
const messages = [
|
|
@@ -378,7 +379,7 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
378
379
|
},
|
|
379
380
|
...toolResponses,
|
|
380
381
|
];
|
|
381
|
-
|
|
382
|
+
log.info(`handleToolResponses: ${JSON.stringify(messages, null, 2)}`);
|
|
382
383
|
try {
|
|
383
384
|
const stream = await this.openaiClient.chat.completions.create({
|
|
384
385
|
model: this.modelName,
|
|
@@ -397,17 +398,17 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
397
398
|
await this.streamWebSocketResponses(stream);
|
|
398
399
|
}
|
|
399
400
|
catch (error) {
|
|
400
|
-
|
|
401
|
+
log.error("Error handling tool responses:", error);
|
|
401
402
|
throw error;
|
|
402
403
|
}
|
|
403
404
|
}
|
|
404
405
|
async setupMemoryAsync() {
|
|
405
406
|
if (!this.memory) {
|
|
406
|
-
|
|
407
|
+
log.info("loadMemoryWithOwnership: loading memory");
|
|
407
408
|
this.memory = (await this.loadMemory());
|
|
408
409
|
}
|
|
409
410
|
if (!this.memory) {
|
|
410
|
-
|
|
411
|
+
log.error("loadMemoryWithOwnership: No memory found!!!");
|
|
411
412
|
}
|
|
412
413
|
}
|
|
413
414
|
async loadMemoryAsync() {
|
|
@@ -418,10 +419,10 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
418
419
|
}
|
|
419
420
|
async setCurrentMode(mode) {
|
|
420
421
|
if (mode) {
|
|
421
|
-
|
|
422
|
+
log.info(`Setting currentMode to ${mode} it was ${this.memory.currentMode}`);
|
|
422
423
|
}
|
|
423
424
|
else {
|
|
424
|
-
|
|
425
|
+
log.info(`No currentMode provided, keeping ${this.memory.currentMode}`);
|
|
425
426
|
}
|
|
426
427
|
await this.loadMemoryAsync();
|
|
427
428
|
this.memory.currentMode = mode;
|
|
@@ -431,13 +432,13 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
431
432
|
* Initialize modes from subclass definitions
|
|
432
433
|
*/
|
|
433
434
|
async initializeModes() {
|
|
434
|
-
|
|
435
|
+
log.info("---------------------> initializeModes");
|
|
435
436
|
await this.setupMemoryAsync();
|
|
436
437
|
this.availableTools.clear();
|
|
437
438
|
const modes = await this.defineAvailableModes();
|
|
438
439
|
for (const mode of modes) {
|
|
439
440
|
this.modes.set(mode.name, mode);
|
|
440
|
-
|
|
441
|
+
log.info(`initializeModes: ${mode.name}`);
|
|
441
442
|
// Register mode's functions
|
|
442
443
|
for (const func of mode.tools) {
|
|
443
444
|
this.availableTools.set(func.name, func);
|
|
@@ -455,7 +456,7 @@ Never engage in off topic conversations, always politely steer the conversation
|
|
|
455
456
|
getCurrentModeFunctions() {
|
|
456
457
|
const currentMode = this.modes.get(this.memory.currentMode);
|
|
457
458
|
if (!currentMode) {
|
|
458
|
-
|
|
459
|
+
log.error(`No current mode found: ${this.memory.currentMode}`);
|
|
459
460
|
return [];
|
|
460
461
|
}
|
|
461
462
|
// Combine mode-specific functions with core functions
|
|
@@ -480,7 +481,7 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
480
481
|
getCurrentSystemPrompt() {
|
|
481
482
|
const currentMode = this.modes.get(this.memory.currentMode);
|
|
482
483
|
if (!currentMode) {
|
|
483
|
-
|
|
484
|
+
log.error(`No current mode found: ${this.memory.currentMode}`);
|
|
484
485
|
return `${this.defaultSystemPrompt}\n\n${this.renderLoginStatus()}`;
|
|
485
486
|
}
|
|
486
487
|
return `${this.defaultSystemPrompt}\n\n${this.renderLoginStatus()}\n\n<furtherAgentInstructions>\n${currentMode.systemPrompt}\n</furtherAgentInstructions>`;
|
|
@@ -587,11 +588,11 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
587
588
|
parameters: f.parameters,
|
|
588
589
|
},
|
|
589
590
|
}));
|
|
590
|
-
|
|
591
|
+
log.info("======================> conversation currentMode", this.memory?.currentMode);
|
|
591
592
|
if (this.DEBUG) {
|
|
592
|
-
|
|
593
|
+
log.info("======================> conversation", JSON.stringify(messages, null, 2));
|
|
593
594
|
}
|
|
594
|
-
|
|
595
|
+
log.info("======================> conversation", JSON.stringify(tools, null, 2));
|
|
595
596
|
const stream = await this.openaiClient.chat.completions.create({
|
|
596
597
|
model: this.modelName,
|
|
597
598
|
messages,
|
|
@@ -602,7 +603,7 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
602
603
|
await this.streamWebSocketResponses(stream);
|
|
603
604
|
}
|
|
604
605
|
catch (error) {
|
|
605
|
-
|
|
606
|
+
log.error("Error in conversation:", error);
|
|
606
607
|
this.sendToClient("assistant", "Error processing request", "error");
|
|
607
608
|
}
|
|
608
609
|
}
|
|
@@ -612,7 +613,7 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
612
613
|
return agentProduct;
|
|
613
614
|
}
|
|
614
615
|
catch (error) {
|
|
615
|
-
|
|
616
|
+
log.error(`Error getting agent product for ${agentProductId}: ${error}`);
|
|
616
617
|
return null;
|
|
617
618
|
}
|
|
618
619
|
}
|
|
@@ -627,7 +628,7 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
627
628
|
return { role: message.sender, content: message.message };
|
|
628
629
|
}
|
|
629
630
|
else {
|
|
630
|
-
|
|
631
|
+
log.debug("Message content is null, message: " + JSON.stringify(message));
|
|
631
632
|
return null;
|
|
632
633
|
}
|
|
633
634
|
})
|
|
@@ -638,17 +639,17 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
638
639
|
*/
|
|
639
640
|
async handleModeSwitch(newMode, reason, params) {
|
|
640
641
|
await this.loadMemoryAsync();
|
|
641
|
-
|
|
642
|
+
log.info(`handleModeSwitch: ${newMode}${reason ? ": " + reason : ""}`);
|
|
642
643
|
const oldMode = this.memory.currentMode;
|
|
643
644
|
if (!this.modes.has(newMode)) {
|
|
644
645
|
throw new Error(`Invalid mode: ${newMode}`);
|
|
645
646
|
}
|
|
646
647
|
if (oldMode === newMode) {
|
|
647
|
-
|
|
648
|
+
log.error(`Trying to switch to the same mode: ${oldMode} to ${newMode}`);
|
|
648
649
|
return;
|
|
649
650
|
}
|
|
650
651
|
if (oldMode && !this.validateModeTransition(oldMode, newMode)) {
|
|
651
|
-
|
|
652
|
+
log.warn(`Invalid mode transition from ${oldMode} to ${newMode}`);
|
|
652
653
|
}
|
|
653
654
|
// Perform cleanup of old mode
|
|
654
655
|
if (oldMode) {
|
|
@@ -671,7 +672,7 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
671
672
|
mode: this.memory.currentMode,
|
|
672
673
|
}));
|
|
673
674
|
await this.saveMemory();
|
|
674
|
-
|
|
675
|
+
log.info("handleModeSwitch: CurrentMode after save", this.memory.currentMode);
|
|
675
676
|
this.sendToClient("system", newMode, "modeChange", undefined, true);
|
|
676
677
|
}
|
|
677
678
|
async addUserMessage(message) {
|
|
@@ -710,7 +711,7 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
710
711
|
async streamWebSocketResponses(stream) {
|
|
711
712
|
return new Promise(async (resolve, reject) => {
|
|
712
713
|
if (this.DEBUG)
|
|
713
|
-
|
|
714
|
+
log.info("Starting streamWebSocketResponses");
|
|
714
715
|
this.sendToClient("assistant", "", "start");
|
|
715
716
|
try {
|
|
716
717
|
let botMessage = "";
|
|
@@ -719,32 +720,32 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
719
720
|
let currentToolCallId = null;
|
|
720
721
|
for await (const part of stream) {
|
|
721
722
|
if (this.DEBUG) {
|
|
722
|
-
|
|
723
|
+
log.info("Received stream part:", JSON.stringify(part, null, 2));
|
|
723
724
|
}
|
|
724
725
|
if (!part.choices?.[0]?.delta) {
|
|
725
726
|
if (this.DEBUG)
|
|
726
|
-
|
|
727
|
+
log.info("Skipping invalid stream part - no choices or delta");
|
|
727
728
|
continue;
|
|
728
729
|
}
|
|
729
730
|
const delta = part.choices[0].delta;
|
|
730
731
|
if (this.DEBUG) {
|
|
731
|
-
|
|
732
|
+
log.info("Processing delta:", JSON.stringify(delta, null, 2));
|
|
732
733
|
}
|
|
733
734
|
if ("tool_calls" in delta && delta.tool_calls) {
|
|
734
735
|
if (this.DEBUG)
|
|
735
|
-
|
|
736
|
+
log.info("Processing tool calls in delta");
|
|
736
737
|
for (const toolCall of delta.tool_calls) {
|
|
737
738
|
// If we have a new tool call ID, update the current ID
|
|
738
739
|
if (toolCall.id) {
|
|
739
740
|
if (this.DEBUG)
|
|
740
|
-
|
|
741
|
+
log.info(`Setting current tool call ID to: ${toolCall.id}`);
|
|
741
742
|
currentToolCallId = toolCall.id;
|
|
742
743
|
}
|
|
743
744
|
// Always use the currentToolCallId for processing
|
|
744
745
|
if (currentToolCallId) {
|
|
745
746
|
const now = Date.now();
|
|
746
747
|
if (this.DEBUG) {
|
|
747
|
-
|
|
748
|
+
log.info(`Processing tool call ${currentToolCallId}:`, {
|
|
748
749
|
name: toolCall.function?.name,
|
|
749
750
|
newArguments: toolCall.function?.arguments,
|
|
750
751
|
exists: toolCalls.has(currentToolCallId),
|
|
@@ -753,7 +754,7 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
753
754
|
// Initialize tool call if it's new
|
|
754
755
|
if (!toolCalls.has(currentToolCallId)) {
|
|
755
756
|
if (this.DEBUG)
|
|
756
|
-
|
|
757
|
+
log.info(`Initializing new tool call ${currentToolCallId}`);
|
|
757
758
|
toolCalls.set(currentToolCallId, {
|
|
758
759
|
id: currentToolCallId,
|
|
759
760
|
name: toolCall.function?.name ?? "",
|
|
@@ -766,13 +767,13 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
766
767
|
// Check timeout
|
|
767
768
|
if (now - existingCall.startTime > this.toolCallTimeout) {
|
|
768
769
|
if (this.DEBUG)
|
|
769
|
-
|
|
770
|
+
log.info(`Tool call timeout for ${existingCall.name}`);
|
|
770
771
|
throw new Error(`Tool call timeout for ${existingCall.name}`);
|
|
771
772
|
}
|
|
772
773
|
// Update name if provided
|
|
773
774
|
if (toolCall.function?.name) {
|
|
774
775
|
if (this.DEBUG)
|
|
775
|
-
|
|
776
|
+
log.info(`Updating tool call name to ${toolCall.function.name}`);
|
|
776
777
|
existingCall.name = toolCall.function.name;
|
|
777
778
|
}
|
|
778
779
|
// Concatenate arguments if provided
|
|
@@ -780,7 +781,7 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
780
781
|
const currentArgs = toolCallArguments.get(currentToolCallId) || "";
|
|
781
782
|
const newArgs = currentArgs + toolCall.function.arguments;
|
|
782
783
|
if (this.DEBUG) {
|
|
783
|
-
|
|
784
|
+
log.info(`Updating arguments for ${currentToolCallId}:`, {
|
|
784
785
|
previous: currentArgs,
|
|
785
786
|
new: toolCall.function.arguments,
|
|
786
787
|
combined: newArgs,
|
|
@@ -791,7 +792,7 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
791
792
|
}
|
|
792
793
|
toolCalls.set(currentToolCallId, existingCall);
|
|
793
794
|
if (this.DEBUG) {
|
|
794
|
-
|
|
795
|
+
log.info(`Current state of tool call ${currentToolCallId}:`, {
|
|
795
796
|
name: existingCall.name,
|
|
796
797
|
arguments: existingCall.arguments,
|
|
797
798
|
});
|
|
@@ -799,22 +800,22 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
799
800
|
}
|
|
800
801
|
else {
|
|
801
802
|
if (this.DEBUG)
|
|
802
|
-
|
|
803
|
+
log.info("No current tool call ID available");
|
|
803
804
|
}
|
|
804
805
|
}
|
|
805
806
|
}
|
|
806
807
|
else if ("content" in delta && delta.content) {
|
|
807
808
|
if (this.DEBUG)
|
|
808
|
-
|
|
809
|
+
log.info("Processing content:", delta.content);
|
|
809
810
|
const content = delta.content;
|
|
810
811
|
this.sendToClient("assistant", content);
|
|
811
812
|
botMessage += content;
|
|
812
813
|
}
|
|
813
814
|
const finishReason = part.choices[0].finish_reason;
|
|
814
815
|
if (this.DEBUG) {
|
|
815
|
-
|
|
816
|
+
log.info("Finish reason:", finishReason);
|
|
816
817
|
if (finishReason === "tool_calls") {
|
|
817
|
-
|
|
818
|
+
log.info("Final state of all tool calls:", Object.fromEntries(toolCalls.entries()));
|
|
818
819
|
}
|
|
819
820
|
}
|
|
820
821
|
if (finishReason === "tool_calls") {
|
|
@@ -824,7 +825,7 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
824
825
|
for (const [id, call] of toolCalls) {
|
|
825
826
|
try {
|
|
826
827
|
if (this.DEBUG) {
|
|
827
|
-
|
|
828
|
+
log.info(`Validating JSON for tool call ${id}:`, call.arguments);
|
|
828
829
|
}
|
|
829
830
|
// Handle empty arguments case
|
|
830
831
|
if (!call.arguments.trim()) {
|
|
@@ -834,24 +835,24 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
834
835
|
}
|
|
835
836
|
catch (e) {
|
|
836
837
|
if (this.DEBUG) {
|
|
837
|
-
|
|
838
|
-
|
|
838
|
+
log.error(`JSON validation failed for ${id}:`, e);
|
|
839
|
+
log.info("Invalid arguments:", call.arguments);
|
|
839
840
|
}
|
|
840
841
|
throw new Error(`Invalid JSON in function arguments for ${call.name}: ${call.arguments}`);
|
|
841
842
|
}
|
|
842
843
|
}
|
|
843
844
|
if (this.DEBUG)
|
|
844
|
-
|
|
845
|
+
log.info("Executing tool calls");
|
|
845
846
|
await this.handleToolCalls(toolCalls);
|
|
846
847
|
if (this.DEBUG)
|
|
847
|
-
|
|
848
|
+
log.info("Clearing tool calls and arguments");
|
|
848
849
|
toolCalls.clear();
|
|
849
850
|
toolCallArguments.clear();
|
|
850
851
|
}
|
|
851
852
|
else if (finishReason === "stop") {
|
|
852
853
|
if (botMessage) {
|
|
853
854
|
if (this.DEBUG)
|
|
854
|
-
|
|
855
|
+
log.info("Saving bot message to chat log");
|
|
855
856
|
this.memory.chatLog.push({
|
|
856
857
|
sender: "assistant",
|
|
857
858
|
message: botMessage,
|
|
@@ -864,22 +865,22 @@ ${this.isLoggedIn ? "The user is logged in." : "The user is not logged in."}
|
|
|
864
865
|
}
|
|
865
866
|
}
|
|
866
867
|
catch (error) {
|
|
867
|
-
|
|
868
|
+
log.error("Stream processing error:", error);
|
|
868
869
|
// Attempt to switch to error recovery mode
|
|
869
870
|
try {
|
|
870
871
|
if (this.DEBUG)
|
|
871
|
-
|
|
872
|
+
log.info("Attempting to switch to error recovery mode");
|
|
872
873
|
await this.handleModeSwitch("error_recovery", error instanceof Error ? error.message : "Unknown error", {});
|
|
873
874
|
}
|
|
874
875
|
catch (e) {
|
|
875
|
-
|
|
876
|
+
log.error("Failed to switch to error recovery mode:", e);
|
|
876
877
|
}
|
|
877
878
|
this.sendToClient("assistant", "There has been an error, please retry", "error");
|
|
878
879
|
reject(error);
|
|
879
880
|
}
|
|
880
881
|
finally {
|
|
881
882
|
if (this.DEBUG)
|
|
882
|
-
|
|
883
|
+
log.info("Finalizing stream response");
|
|
883
884
|
this.sendToClient("assistant", "", "end");
|
|
884
885
|
resolve();
|
|
885
886
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { YpBaseAssistant } from "./baseAssistant.js";
|
|
2
2
|
import { YpBaseChatBotWithVoice } from "./voiceAssistant.js";
|
|
3
|
+
import log from "../../utils/loggerTs.js";
|
|
3
4
|
export class YpBaseAssistantWithVoice extends YpBaseAssistant {
|
|
4
5
|
constructor(wsClientId, wsClients, redis, voiceEnabled, redisKey, domainId) {
|
|
5
6
|
super(wsClientId, wsClients, redis, redisKey, domainId);
|
|
@@ -59,13 +60,13 @@ export class YpBaseAssistantWithVoice extends YpBaseAssistant {
|
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
catch (error) {
|
|
62
|
-
|
|
63
|
+
log.error("Error processing message:", error);
|
|
63
64
|
}
|
|
64
65
|
};
|
|
65
66
|
ws.on("message", this.mainBotWsHandler);
|
|
66
67
|
}
|
|
67
68
|
else {
|
|
68
|
-
|
|
69
|
+
log.error("No WebSocket found for client: ", this.wsClientId);
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
destroyVoiceBot() {
|
|
@@ -102,7 +103,7 @@ export class YpBaseAssistantWithVoice extends YpBaseAssistant {
|
|
|
102
103
|
this.sendToClient(event.sender || "bot", event.message || "", event.type);
|
|
103
104
|
}
|
|
104
105
|
catch (error) {
|
|
105
|
-
|
|
106
|
+
log.error("Error forwarding voice event:", error);
|
|
106
107
|
}
|
|
107
108
|
};
|
|
108
109
|
this.voiceBot?.wsClientSocket?.on("message", this.forwardEventHandler);
|
|
@@ -125,7 +126,7 @@ export class YpBaseAssistantWithVoice extends YpBaseAssistant {
|
|
|
125
126
|
tools: this.getCurrentModeFunctions(),
|
|
126
127
|
modalities: ["text", "audio"]
|
|
127
128
|
});
|
|
128
|
-
|
|
129
|
+
log.info("handleModeSwitch", newMode, params);
|
|
129
130
|
if (newMode === "agent_direct_connection_mode") {
|
|
130
131
|
this.voiceBot?.initializeDirectAgentVoiceConnection();
|
|
131
132
|
}
|
|
@@ -137,7 +138,7 @@ export class YpBaseAssistantWithVoice extends YpBaseAssistant {
|
|
|
137
138
|
}
|
|
138
139
|
async conversation(chatLog) {
|
|
139
140
|
if (this.voiceEnabled) {
|
|
140
|
-
|
|
141
|
+
log.info("voiceEnabled: Updating voice config");
|
|
141
142
|
await this.voiceBot?.updateVoiceConfig({
|
|
142
143
|
instructions: this.getCurrentSystemPrompt(),
|
|
143
144
|
tools: this.getCurrentModeFunctions(),
|