@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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { YpBaseChatBot } from "../../services/llms/baseChatBot.js";
|
|
2
2
|
import WebSocket from "ws";
|
|
3
|
+
import log from "../../utils/loggerTs.js";
|
|
3
4
|
// Extend the base class with voice capabilities
|
|
4
5
|
export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
5
6
|
constructor(wsClientId, wsClients, redisKey, redisConnection, voiceEnabled = false, parentAssistant) {
|
|
@@ -27,8 +28,8 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
27
28
|
this.parentAssistant.on("update-ai-model-session", this.updateAiModelSession.bind(this));
|
|
28
29
|
}
|
|
29
30
|
async updateAiModelSession(message) {
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
log.info(`voiceAssistant: updateAiModelSession: ${message}`);
|
|
32
|
+
log.info(`--------------------> Logged in memory user: ${this.parentAssistant.memory.currentUser
|
|
32
33
|
?.name}`);
|
|
33
34
|
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
34
35
|
await this.initializeVoiceSession(message);
|
|
@@ -36,7 +37,7 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
36
37
|
async initializeMainAssistantVoiceConnection() {
|
|
37
38
|
if (!this.voiceEnabled)
|
|
38
39
|
return;
|
|
39
|
-
|
|
40
|
+
log.info("initializeVoiceConnection");
|
|
40
41
|
const url = "wss://api.openai.com/v1/realtime";
|
|
41
42
|
const wsConfig = {
|
|
42
43
|
headers: {
|
|
@@ -47,7 +48,7 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
47
48
|
try {
|
|
48
49
|
const ws = new WebSocket(`${url}?model=${this.voiceConfig.model}`, wsConfig);
|
|
49
50
|
ws.on("open", () => {
|
|
50
|
-
|
|
51
|
+
log.info("Voice connection established");
|
|
51
52
|
this.assistantVoiceConnection = {
|
|
52
53
|
ws,
|
|
53
54
|
connected: true,
|
|
@@ -57,17 +58,17 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
57
58
|
this.initializeVoiceSession();
|
|
58
59
|
});
|
|
59
60
|
ws.on("close", () => {
|
|
60
|
-
|
|
61
|
+
log.info("Voice connection to OpenAI closed");
|
|
61
62
|
this.assistantVoiceConnection = undefined;
|
|
62
63
|
});
|
|
63
64
|
ws.on("error", (error) => {
|
|
64
|
-
|
|
65
|
+
log.error("Voice connection error:", error);
|
|
65
66
|
this.assistantVoiceConnection = undefined;
|
|
66
67
|
});
|
|
67
68
|
this.setupVoiceMessageHandlers(ws, true);
|
|
68
69
|
}
|
|
69
70
|
catch (error) {
|
|
70
|
-
|
|
71
|
+
log.error("Failed to initialize voice connection:", error);
|
|
71
72
|
throw error;
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -86,10 +87,10 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
86
87
|
}
|
|
87
88
|
this.sendToClient("assistant", "", "clear_audio_buffer");
|
|
88
89
|
if (this.directAgentVoiceConnection) {
|
|
89
|
-
|
|
90
|
+
log.info("Direct agent voice connection already initialized, closing");
|
|
90
91
|
this.destroyDirectAgentVoiceConnection();
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
+
log.info("initializeDirectAgentVoiceConnection");
|
|
93
94
|
const url = "wss://api.openai.com/v1/realtime";
|
|
94
95
|
const wsConfig = {
|
|
95
96
|
headers: {
|
|
@@ -100,7 +101,7 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
100
101
|
try {
|
|
101
102
|
const ws = new WebSocket(`${url}?model=${this.voiceConfig.model}`, wsConfig);
|
|
102
103
|
ws.on("open", () => {
|
|
103
|
-
|
|
104
|
+
log.info("Agent voice connection established");
|
|
104
105
|
this.directAgentVoiceConnection = {
|
|
105
106
|
ws,
|
|
106
107
|
connected: true,
|
|
@@ -110,17 +111,17 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
110
111
|
this.initializeVoiceSession("Say hi and welcome the user, offer to explain and show the user a workflow overview with the 'show_agent_workflow_overview_widget' function/tool you have access to call");
|
|
111
112
|
});
|
|
112
113
|
ws.on("close", () => {
|
|
113
|
-
|
|
114
|
+
log.info("Agent voice connection to OpenAI closed");
|
|
114
115
|
this.directAgentVoiceConnection = undefined;
|
|
115
116
|
});
|
|
116
117
|
ws.on("error", (error) => {
|
|
117
|
-
|
|
118
|
+
log.error("Agent voice connection error:", error);
|
|
118
119
|
this.directAgentVoiceConnection = undefined;
|
|
119
120
|
});
|
|
120
121
|
this.setupVoiceMessageHandlers(ws, false);
|
|
121
122
|
}
|
|
122
123
|
catch (error) {
|
|
123
|
-
|
|
124
|
+
log.error("Failed to initialize voice connection:", error);
|
|
124
125
|
throw error;
|
|
125
126
|
}
|
|
126
127
|
}
|
|
@@ -161,11 +162,11 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
161
162
|
try {
|
|
162
163
|
const event = JSON.parse(data.toString());
|
|
163
164
|
if (disableWhenAgentIsSpeaking && this.directAgentVoiceConnection) {
|
|
164
|
-
|
|
165
|
+
log.info("Voice message received but agent is speaking, ignoring", event.type);
|
|
165
166
|
return;
|
|
166
167
|
}
|
|
167
168
|
if (this.DEBUG) {
|
|
168
|
-
|
|
169
|
+
log.info("voiceMessage: ", event.type);
|
|
169
170
|
}
|
|
170
171
|
switch (event.type) {
|
|
171
172
|
case "session.created":
|
|
@@ -189,7 +190,7 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
189
190
|
await this.handleSpeechStopped();
|
|
190
191
|
break;
|
|
191
192
|
case "response.cancelled":
|
|
192
|
-
|
|
193
|
+
log.info("response.cancelled");
|
|
193
194
|
this.isWaitingOnCancelResponseCompleted = false;
|
|
194
195
|
break;
|
|
195
196
|
case "conversation.item.input_audio_transcription.completed":
|
|
@@ -212,16 +213,16 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
212
213
|
break;
|
|
213
214
|
default:
|
|
214
215
|
if (this.DEBUG) {
|
|
215
|
-
|
|
216
|
+
log.info("Unhandled voice event type:", event.type);
|
|
216
217
|
}
|
|
217
218
|
if (event.type === "error") {
|
|
218
|
-
|
|
219
|
+
log.info(JSON.stringify(event, null, 2));
|
|
219
220
|
}
|
|
220
221
|
break;
|
|
221
222
|
}
|
|
222
223
|
}
|
|
223
224
|
catch (error) {
|
|
224
|
-
|
|
225
|
+
log.error("Error handling voice message:", error);
|
|
225
226
|
}
|
|
226
227
|
};
|
|
227
228
|
// Attach it
|
|
@@ -259,7 +260,7 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
259
260
|
this.parentAssistant.addAssistantMessage(event.item.content[0].transcript);
|
|
260
261
|
}
|
|
261
262
|
else {
|
|
262
|
-
|
|
263
|
+
log.error("No text in response.done event");
|
|
263
264
|
}
|
|
264
265
|
}
|
|
265
266
|
async handleAudioTranscriptDone(event) {
|
|
@@ -275,14 +276,14 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
275
276
|
const tools = this.parentAssistant.getCurrentModeFunctions();
|
|
276
277
|
if (!tools)
|
|
277
278
|
return;
|
|
278
|
-
//
|
|
279
|
+
//log.info("callFunctionHandler event: ", JSON.stringify(event, null, 2));
|
|
279
280
|
const tool = tools.find((t) => t.name === event.name);
|
|
280
281
|
if (!tool) {
|
|
281
|
-
|
|
282
|
+
log.info("Tool not found: ", event.name);
|
|
282
283
|
return;
|
|
283
284
|
}
|
|
284
285
|
const toolName = tool.name;
|
|
285
|
-
|
|
286
|
+
log.info("Calling tool handler: ", toolName);
|
|
286
287
|
const result = await tool.handler(event.arguments);
|
|
287
288
|
// Store the result in memory for context
|
|
288
289
|
if (result.success && result.data) {
|
|
@@ -313,21 +314,21 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
313
314
|
await this.saveMemoryIfNeeded();*/
|
|
314
315
|
}
|
|
315
316
|
else {
|
|
316
|
-
|
|
317
|
+
log.error(`No data returned from tool execution: ${event.name}`);
|
|
317
318
|
}
|
|
318
319
|
if (result.html) {
|
|
319
|
-
|
|
320
|
+
log.info("--------------------------------============================> handleResponseDone result.html with token: ", result.uniqueToken);
|
|
320
321
|
this.sendToClient("assistant", result.html, "html", result.uniqueToken, true);
|
|
321
322
|
this.parentAssistant.addAssistantHtmlMessage(result.html, result.uniqueToken);
|
|
322
323
|
}
|
|
323
324
|
if (result.clientEvents) {
|
|
324
|
-
|
|
325
|
+
log.info(`clientEvents: ${JSON.stringify(result.clientEvents, null, 2)}`);
|
|
325
326
|
for (const clientEvent of result.clientEvents) {
|
|
326
327
|
this.sendToClient("assistant", clientEvent.details, clientEvent.name);
|
|
327
328
|
}
|
|
328
329
|
}
|
|
329
330
|
if (!result.success) {
|
|
330
|
-
|
|
331
|
+
log.error(`Tool execution failed: ${event.name} ${result.error}`);
|
|
331
332
|
}
|
|
332
333
|
const responseEvent = {
|
|
333
334
|
type: "conversation.item.create",
|
|
@@ -358,8 +359,8 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
358
359
|
.join("");
|
|
359
360
|
}
|
|
360
361
|
async proxyToClient(event) {
|
|
361
|
-
|
|
362
|
-
|
|
362
|
+
log.info("proxyToClient: ", event.type);
|
|
363
|
+
log.info(JSON.stringify(event, null, 2));
|
|
363
364
|
const proxyMessage = {
|
|
364
365
|
sender: "assistant",
|
|
365
366
|
type: event.type,
|
|
@@ -369,7 +370,7 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
369
370
|
}
|
|
370
371
|
// Handle incoming audio from client
|
|
371
372
|
async handleIncomingAudio(audioData) {
|
|
372
|
-
//
|
|
373
|
+
//log.info(`handleIncomingAudio: ${audioData.length} ${this.voiceEnabled} ${this.assistantVoiceConnection?.ws}`);
|
|
373
374
|
if (!this.assistantVoiceConnection?.ws || !this.voiceEnabled)
|
|
374
375
|
return;
|
|
375
376
|
this.voiceState.lastAudioTimestamp = Date.now();
|
|
@@ -387,7 +388,7 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
387
388
|
event_id: `bufferAppend_${this.getRandomStringAscii(10)}`,
|
|
388
389
|
audio: Buffer.from(audioData).toString("base64"),
|
|
389
390
|
};
|
|
390
|
-
//
|
|
391
|
+
//log.info("Sending audio message to server:");
|
|
391
392
|
this.sendToVoiceConnection(audioMessage);
|
|
392
393
|
}
|
|
393
394
|
// Handle Voice Activity Detection silence
|
|
@@ -457,7 +458,7 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
457
458
|
new Promise((resolve) => {
|
|
458
459
|
const checkFlag = () => {
|
|
459
460
|
if (!this.isWaitingOnCancelResponseCompleted) {
|
|
460
|
-
|
|
461
|
+
log.info("Cancel response completed from event");
|
|
461
462
|
resolve(true);
|
|
462
463
|
}
|
|
463
464
|
else {
|
|
@@ -468,7 +469,7 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
468
469
|
}),
|
|
469
470
|
new Promise((resolve) => setTimeout(resolve, 75)),
|
|
470
471
|
]);
|
|
471
|
-
|
|
472
|
+
log.info("Cancel response completed from timeout");
|
|
472
473
|
}
|
|
473
474
|
async sendCancelResponse() {
|
|
474
475
|
const cancelResponse = {
|
|
@@ -476,18 +477,18 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
476
477
|
event_id: `sendCancelResponse_${this.getRandomStringAscii(10)}`,
|
|
477
478
|
};
|
|
478
479
|
this.sendToVoiceConnection(cancelResponse);
|
|
479
|
-
|
|
480
|
+
log.info("Have sent cancel response");
|
|
480
481
|
await this.waitForCancelResponseCompleted();
|
|
481
482
|
}
|
|
482
483
|
async initializeVoiceSession(customResponseMessage) {
|
|
483
484
|
if (!this.assistantVoiceConnection?.ws) {
|
|
484
|
-
|
|
485
|
+
log.error("No voice connection");
|
|
485
486
|
return;
|
|
486
487
|
}
|
|
487
488
|
await this.parentAssistant.initializeModes();
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
489
|
+
log.info("======================> initializeVoiceSession current mode", this.parentAssistant.memory.currentMode);
|
|
490
|
+
log.info("======================> initializeVoiceSession system prompt", this.parentAssistant.getCurrentSystemPrompt());
|
|
491
|
+
log.info("======================> initializeVoiceSession functions", this.parentAssistant.getCurrentModeFunctions());
|
|
491
492
|
let chatHistory;
|
|
492
493
|
if (this.parentAssistant.memory &&
|
|
493
494
|
this.parentAssistant.memory.chatLog &&
|
|
@@ -501,7 +502,7 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
501
502
|
})));
|
|
502
503
|
}
|
|
503
504
|
let instructions = this.parentAssistant.getCurrentSystemPrompt() || "";
|
|
504
|
-
//
|
|
505
|
+
//log.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< initializeVoiceSession current mode", JSON.stringify(this.parentAssistant.memory, null, 2));
|
|
505
506
|
let voiceName = this.voiceConfig.voice;
|
|
506
507
|
const subscriptionPlan = await this.parentAssistant.getCurrentSubscriptionPlan();
|
|
507
508
|
if (this.parentAssistant.memory.currentMode ===
|
|
@@ -518,7 +519,7 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
518
519
|
instructions += `\n\n<ImportantPreviousChatHistory>\n${chatHistory}\n</ImportantPreviousChatHistory>`;
|
|
519
520
|
}
|
|
520
521
|
if (this.DEBUG) {
|
|
521
|
-
|
|
522
|
+
log.info("initializeVoiceSession final instructions", instructions);
|
|
522
523
|
}
|
|
523
524
|
// Then update the session with full configuration
|
|
524
525
|
const sessionConfig = {
|
|
@@ -544,7 +545,7 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
544
545
|
},
|
|
545
546
|
};
|
|
546
547
|
if (this.DEBUG) {
|
|
547
|
-
|
|
548
|
+
log.info("Sending session config to server:", JSON.stringify(sessionConfig, null, 2));
|
|
548
549
|
}
|
|
549
550
|
this.sendToVoiceConnection(sessionConfig);
|
|
550
551
|
setTimeout(() => {
|
|
@@ -567,7 +568,7 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
567
568
|
}, 200);
|
|
568
569
|
}
|
|
569
570
|
async triggerResponse(message, cancelResponse = true) {
|
|
570
|
-
|
|
571
|
+
log.info("triggerResponse: ", message);
|
|
571
572
|
const createResponse = {
|
|
572
573
|
type: "response.create",
|
|
573
574
|
event_id: `triggerResponse_${this.getRandomStringAscii(10)}`,
|
|
@@ -583,11 +584,11 @@ export class YpBaseChatBotWithVoice extends YpBaseChatBot {
|
|
|
583
584
|
}
|
|
584
585
|
// Handle voice-specific events
|
|
585
586
|
async handleVoiceSessionCreated(event) {
|
|
586
|
-
|
|
587
|
+
log.info("Voice session created:", event.session.id);
|
|
587
588
|
// Additional session initialization if needed
|
|
588
589
|
}
|
|
589
590
|
async handleVoiceSessionError(event) {
|
|
590
|
-
|
|
591
|
+
log.error("Voice session error:", event.error);
|
|
591
592
|
this.sendToClient("system", "Voice processing error occurred", "error");
|
|
592
593
|
}
|
|
593
594
|
async handleVoiceResponseStatus(event) {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import { AgentProductManager } from '../managers/agentProductManager.js';
|
|
4
4
|
import auth from '../../authorization.cjs';
|
|
5
|
+
import log from "../../utils/loggerTs.js";
|
|
5
6
|
export class AgentProductController {
|
|
6
7
|
constructor() {
|
|
7
8
|
this.path = '/api/agent-products';
|
|
@@ -13,7 +14,7 @@ export class AgentProductController {
|
|
|
13
14
|
res.json(agentProducts);
|
|
14
15
|
}
|
|
15
16
|
catch (error) {
|
|
16
|
-
|
|
17
|
+
log.error('Error fetching agent products:', error);
|
|
17
18
|
res.status(500).json({ error: error.message });
|
|
18
19
|
}
|
|
19
20
|
};
|
|
@@ -28,7 +29,7 @@ export class AgentProductController {
|
|
|
28
29
|
res.json(agentProduct);
|
|
29
30
|
}
|
|
30
31
|
catch (error) {
|
|
31
|
-
|
|
32
|
+
log.error('Error fetching agent product:', error);
|
|
32
33
|
res.status(500).json({ error: error.message });
|
|
33
34
|
}
|
|
34
35
|
};
|
|
@@ -40,7 +41,7 @@ export class AgentProductController {
|
|
|
40
41
|
res.status(201).json(agentProduct);
|
|
41
42
|
}
|
|
42
43
|
catch (error) {
|
|
43
|
-
|
|
44
|
+
log.error('Error creating agent product:', error);
|
|
44
45
|
res.status(500).json({ error: error.message });
|
|
45
46
|
}
|
|
46
47
|
};
|
|
@@ -52,7 +53,7 @@ export class AgentProductController {
|
|
|
52
53
|
res.json(agentProduct);
|
|
53
54
|
}
|
|
54
55
|
catch (error) {
|
|
55
|
-
|
|
56
|
+
log.error('Error updating agent product:', error);
|
|
56
57
|
res.status(500).json({ error: error.message });
|
|
57
58
|
}
|
|
58
59
|
};
|
|
@@ -63,7 +64,7 @@ export class AgentProductController {
|
|
|
63
64
|
res.status(200).json({ message: 'Agent product deleted successfully' });
|
|
64
65
|
}
|
|
65
66
|
catch (error) {
|
|
66
|
-
|
|
67
|
+
log.error('Error deleting agent product:', error);
|
|
67
68
|
res.status(500).json({ error: error.message });
|
|
68
69
|
}
|
|
69
70
|
};
|
|
@@ -74,7 +75,7 @@ export class AgentProductController {
|
|
|
74
75
|
res.json(runs);
|
|
75
76
|
}
|
|
76
77
|
catch (error) {
|
|
77
|
-
|
|
78
|
+
log.error('Error fetching agent product runs:', error);
|
|
78
79
|
res.status(500).json({ error: error.message });
|
|
79
80
|
}
|
|
80
81
|
};
|
|
@@ -85,7 +86,7 @@ export class AgentProductController {
|
|
|
85
86
|
res.json(status);
|
|
86
87
|
}
|
|
87
88
|
catch (error) {
|
|
88
|
-
|
|
89
|
+
log.error('Error fetching agent product status:', error);
|
|
89
90
|
res.status(500).json({ error: error.message });
|
|
90
91
|
}
|
|
91
92
|
};
|
|
@@ -4,6 +4,7 @@ import { SubscriptionManager } from "../managers/subscriptionManager.js";
|
|
|
4
4
|
import auth from "../../authorization.cjs";
|
|
5
5
|
import { YpSubscription } from "../models/subscription.js";
|
|
6
6
|
import Stripe from "stripe";
|
|
7
|
+
import log from "../../utils/loggerTs.js";
|
|
7
8
|
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
|
|
8
9
|
export class AgentSubscriptionController {
|
|
9
10
|
constructor(wsClients) {
|
|
@@ -38,7 +39,7 @@ export class AgentSubscriptionController {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
catch (error) {
|
|
41
|
-
|
|
42
|
+
log.error("Error retrieving subscription agent configuration:", error);
|
|
42
43
|
res.status(500).json({ error: error.message });
|
|
43
44
|
}
|
|
44
45
|
};
|
|
@@ -63,7 +64,7 @@ export class AgentSubscriptionController {
|
|
|
63
64
|
res.status(200);
|
|
64
65
|
}
|
|
65
66
|
catch (error) {
|
|
66
|
-
|
|
67
|
+
log.error("Error updating agent configuration:", error);
|
|
67
68
|
res.status(500).json({ error: error.message });
|
|
68
69
|
}
|
|
69
70
|
};
|
|
@@ -73,7 +74,7 @@ export class AgentSubscriptionController {
|
|
|
73
74
|
res.json(plans);
|
|
74
75
|
}
|
|
75
76
|
catch (error) {
|
|
76
|
-
|
|
77
|
+
log.error("Error fetching plans:", error);
|
|
77
78
|
res.status(500).json({ error: error.message });
|
|
78
79
|
}
|
|
79
80
|
};
|
|
@@ -101,7 +102,7 @@ export class AgentSubscriptionController {
|
|
|
101
102
|
});
|
|
102
103
|
}
|
|
103
104
|
catch (error) {
|
|
104
|
-
|
|
105
|
+
log.error("Error creating free trial subscription:", error);
|
|
105
106
|
res.status(500).json({ error: error.message });
|
|
106
107
|
}
|
|
107
108
|
};
|
|
@@ -114,7 +115,7 @@ export class AgentSubscriptionController {
|
|
|
114
115
|
res.status(201).json({ agentRun, subscription });
|
|
115
116
|
}
|
|
116
117
|
catch (error) {
|
|
117
|
-
|
|
118
|
+
log.error("Error starting agent run:", error);
|
|
118
119
|
res.status(500).json({ error: error.message });
|
|
119
120
|
}
|
|
120
121
|
};
|
|
@@ -125,7 +126,7 @@ export class AgentSubscriptionController {
|
|
|
125
126
|
res.status(200).json({ message: "Agent run stopped successfully" });
|
|
126
127
|
}
|
|
127
128
|
catch (error) {
|
|
128
|
-
|
|
129
|
+
log.error("Error stopping agent run:", error);
|
|
129
130
|
res.status(500).json({ error: error.message });
|
|
130
131
|
}
|
|
131
132
|
};
|
|
@@ -139,7 +140,7 @@ export class AgentSubscriptionController {
|
|
|
139
140
|
res.json(subscriptions);
|
|
140
141
|
}
|
|
141
142
|
catch (error) {
|
|
142
|
-
|
|
143
|
+
log.error("Error fetching subscriptions:", error);
|
|
143
144
|
res.status(500).json({ error: error.message });
|
|
144
145
|
}
|
|
145
146
|
};
|
|
@@ -159,7 +160,7 @@ export class AgentSubscriptionController {
|
|
|
159
160
|
res.status(200).json({ message: "Subscription cancelled successfully" });
|
|
160
161
|
}
|
|
161
162
|
catch (error) {
|
|
162
|
-
|
|
163
|
+
log.error("Error cancelling subscription:", error);
|
|
163
164
|
res.status(500).json({ error: error.message });
|
|
164
165
|
}
|
|
165
166
|
};
|
|
@@ -181,7 +182,7 @@ export class AgentSubscriptionController {
|
|
|
181
182
|
res.status(200).json(subscription);
|
|
182
183
|
}
|
|
183
184
|
catch (error) {
|
|
184
|
-
|
|
185
|
+
log.error("Error updating subscription:", error);
|
|
185
186
|
res.status(500).json({ error: error.message });
|
|
186
187
|
}
|
|
187
188
|
};
|
|
@@ -203,7 +204,7 @@ export class AgentSubscriptionController {
|
|
|
203
204
|
return;
|
|
204
205
|
}
|
|
205
206
|
catch (error) {
|
|
206
|
-
|
|
207
|
+
log.error("Error creating payment intent:", error);
|
|
207
208
|
res.status(500).json({ error: error.message });
|
|
208
209
|
}
|
|
209
210
|
};
|
|
@@ -222,14 +223,14 @@ export class AgentSubscriptionController {
|
|
|
222
223
|
case "payment_intent.payment_failed":
|
|
223
224
|
const failedPayment = event.data.object;
|
|
224
225
|
// You might want to implement handling failed payments
|
|
225
|
-
|
|
226
|
+
log.error("Payment failed:", failedPayment.id);
|
|
226
227
|
break;
|
|
227
228
|
// Add other event types as needed
|
|
228
229
|
}
|
|
229
230
|
res.json({ received: true });
|
|
230
231
|
}
|
|
231
232
|
catch (error) {
|
|
232
|
-
|
|
233
|
+
log.error("Webhook error:", error);
|
|
233
234
|
res.status(400).json({ error: error.message });
|
|
234
235
|
}
|
|
235
236
|
};
|