@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,213 +0,0 @@
|
|
|
1
|
-
function base64ToWav(base64Audio, sampleRate = 16000) {
|
|
2
|
-
const audioData = Uint8Array.from(atob(base64Audio), (c) => c.charCodeAt(0));
|
|
3
|
-
// WAV header
|
|
4
|
-
const header = new ArrayBuffer(44);
|
|
5
|
-
const view = new DataView(header);
|
|
6
|
-
// "RIFF" chunk descriptor
|
|
7
|
-
view.setUint32(0, 0x52494646, false); // "RIFF"
|
|
8
|
-
view.setUint32(4, 36 + audioData.length, true); // file size
|
|
9
|
-
view.setUint32(8, 0x57415645, false); // "WAVE"
|
|
10
|
-
// "fmt " sub-chunk
|
|
11
|
-
view.setUint32(12, 0x666d7420, false); // "fmt "
|
|
12
|
-
view.setUint32(16, 16, true); // subchunk size
|
|
13
|
-
view.setUint16(20, 3, true); // audio format (3 = IEEE float)
|
|
14
|
-
view.setUint16(22, 1, true); // num channels
|
|
15
|
-
view.setUint32(24, sampleRate, true); // sample rate
|
|
16
|
-
view.setUint32(28, sampleRate * 4, true); // byte rate
|
|
17
|
-
view.setUint16(32, 4, true); // block align
|
|
18
|
-
view.setUint16(34, 32, true); // bits per sample
|
|
19
|
-
// "data" sub-chunk
|
|
20
|
-
view.setUint32(36, 0x64617461, false); // "data"
|
|
21
|
-
view.setUint32(40, audioData.length, true); // subchunk size
|
|
22
|
-
// Combine header and audio data
|
|
23
|
-
const wavFile = new Uint8Array(header.byteLength + audioData.length);
|
|
24
|
-
wavFile.set(new Uint8Array(header), 0);
|
|
25
|
-
wavFile.set(audioData, header.byteLength);
|
|
26
|
-
return wavFile.buffer;
|
|
27
|
-
}
|
|
28
|
-
async function handleGetConfig(request, env) {
|
|
29
|
-
try {
|
|
30
|
-
const config = await request.json();
|
|
31
|
-
// Get HeyGen token
|
|
32
|
-
const response = await fetch("https://api.heygen.com/v1/streaming.create_token", {
|
|
33
|
-
method: "POST",
|
|
34
|
-
headers: {
|
|
35
|
-
"x-api-key": env.HEYGEN_API_KEY,
|
|
36
|
-
"Content-Type": "application/json",
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
if (!response.ok) {
|
|
40
|
-
throw new Error(`Failed to get HeyGen token: ${response.statusText}`);
|
|
41
|
-
}
|
|
42
|
-
const { data } = await response.json();
|
|
43
|
-
const token = data.token; // Extract token from nested data object
|
|
44
|
-
console.log(`token: ${token}`);
|
|
45
|
-
// Initialize session using a single write operation
|
|
46
|
-
const stmt = env.D1_AVATAR_SESSIONS.prepare(`
|
|
47
|
-
INSERT INTO sessions (id, audio_data, chat_data, created_at)
|
|
48
|
-
VALUES (?, '', '', ?)
|
|
49
|
-
`);
|
|
50
|
-
await stmt.bind(config.sessionId, Date.now()).run();
|
|
51
|
-
return new Response(JSON.stringify({
|
|
52
|
-
token,
|
|
53
|
-
knowledgeId: config.knowledgeId,
|
|
54
|
-
knowledgeBase: config.knowledgeBase,
|
|
55
|
-
}), {
|
|
56
|
-
headers: { "Content-Type": "application/json" },
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
console.error("Error in get config:", error);
|
|
61
|
-
return new Response(JSON.stringify({ error: "Internal Server Error" }), {
|
|
62
|
-
status: 500,
|
|
63
|
-
headers: { "Content-Type": "application/json" },
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
async function handleConversationBackup(request, env) {
|
|
68
|
-
try {
|
|
69
|
-
const { sessionId, messages } = await request.json();
|
|
70
|
-
const messageText = messages
|
|
71
|
-
.map((msg) => msg.message)
|
|
72
|
-
.join("\n");
|
|
73
|
-
// Use batch operation for atomic transaction
|
|
74
|
-
const statements = [
|
|
75
|
-
// Check if session exists
|
|
76
|
-
env.D1_AVATAR_SESSIONS.prepare("SELECT id FROM sessions WHERE id = ?").bind(sessionId),
|
|
77
|
-
// Update the chat data
|
|
78
|
-
env.D1_AVATAR_SESSIONS.prepare("UPDATE sessions SET chat_data = chat_data || ? WHERE id = ?").bind(messageText + "\n", sessionId),
|
|
79
|
-
];
|
|
80
|
-
const [selectResult] = await env.D1_AVATAR_SESSIONS.batch(statements);
|
|
81
|
-
if (!selectResult.results?.length) {
|
|
82
|
-
return new Response(JSON.stringify({ error: "Session not found" }), {
|
|
83
|
-
status: 404,
|
|
84
|
-
headers: { "Content-Type": "application/json" },
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
return new Response(JSON.stringify({ success: true }), {
|
|
88
|
-
headers: { "Content-Type": "application/json" },
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
console.error("Error in conversation backup:", error);
|
|
93
|
-
return new Response(JSON.stringify({ error: "Internal Server Error" }), {
|
|
94
|
-
status: 500,
|
|
95
|
-
headers: { "Content-Type": "application/json" },
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
async function handleAudioBackup(request, env) {
|
|
100
|
-
try {
|
|
101
|
-
const { sessionId, audioData } = await request.json();
|
|
102
|
-
// Use batch operation for atomic transaction
|
|
103
|
-
const statements = [
|
|
104
|
-
// Check if session exists
|
|
105
|
-
env.D1_AVATAR_SESSIONS.prepare("SELECT id FROM sessions WHERE id = ?").bind(sessionId),
|
|
106
|
-
// Update the audio data
|
|
107
|
-
env.D1_AVATAR_SESSIONS.prepare("UPDATE sessions SET audio_data = audio_data || ? WHERE id = ?").bind(audioData, sessionId),
|
|
108
|
-
];
|
|
109
|
-
const [selectResult] = await env.D1_AVATAR_SESSIONS.batch(statements);
|
|
110
|
-
if (!selectResult.results?.length) {
|
|
111
|
-
return new Response(JSON.stringify({ error: "Session not found" }), {
|
|
112
|
-
status: 404,
|
|
113
|
-
headers: { "Content-Type": "application/json" },
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
return new Response(JSON.stringify({ success: true }), {
|
|
117
|
-
headers: { "Content-Type": "application/json" },
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
console.error("Error in audio backup:", error);
|
|
122
|
-
return new Response(JSON.stringify({ error: "Internal Server Error" }), {
|
|
123
|
-
status: 500,
|
|
124
|
-
headers: { "Content-Type": "application/json" },
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
async function handleEndSession(request, env) {
|
|
129
|
-
try {
|
|
130
|
-
const { sessionId } = await request.json();
|
|
131
|
-
// Use batch operation for atomic transaction
|
|
132
|
-
const statements = [
|
|
133
|
-
// Get the session data
|
|
134
|
-
env.D1_AVATAR_SESSIONS.prepare("SELECT audio_data FROM sessions WHERE id = ?").bind(sessionId),
|
|
135
|
-
// Update the session end time
|
|
136
|
-
env.D1_AVATAR_SESSIONS.prepare("UPDATE sessions SET ended_at = ? WHERE id = ?").bind(Date.now(), sessionId),
|
|
137
|
-
];
|
|
138
|
-
const [selectResult] = await env.D1_AVATAR_SESSIONS.batch(statements);
|
|
139
|
-
if (!selectResult.results?.length) {
|
|
140
|
-
return new Response(JSON.stringify({ error: "Session not found" }), {
|
|
141
|
-
status: 404,
|
|
142
|
-
headers: { "Content-Type": "application/json" },
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
const session = selectResult.results[0];
|
|
146
|
-
// Convert and store in R2
|
|
147
|
-
const wavFile = base64ToWav(session.audio_data);
|
|
148
|
-
// Store in R2 with proper content type and metadata
|
|
149
|
-
await env.R2_AVATAR_SESSIONS.put(`${sessionId}.wav`, wavFile, {
|
|
150
|
-
httpMetadata: {
|
|
151
|
-
contentType: "audio/wav",
|
|
152
|
-
},
|
|
153
|
-
customMetadata: {
|
|
154
|
-
sessionId,
|
|
155
|
-
createdAt: Date.now().toString(),
|
|
156
|
-
},
|
|
157
|
-
});
|
|
158
|
-
return new Response(JSON.stringify({ success: true }), {
|
|
159
|
-
headers: { "Content-Type": "application/json" },
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
catch (error) {
|
|
163
|
-
console.error("Error in end session:", error);
|
|
164
|
-
return new Response(JSON.stringify({ error: "Internal Server Error" }), {
|
|
165
|
-
status: 500,
|
|
166
|
-
headers: { "Content-Type": "application/json" },
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
export default {
|
|
171
|
-
async fetch(request, env, ctx) {
|
|
172
|
-
try {
|
|
173
|
-
const url = new URL(request.url);
|
|
174
|
-
// CORS headers
|
|
175
|
-
const corsHeaders = {
|
|
176
|
-
"Access-Control-Allow-Origin": "*",
|
|
177
|
-
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
178
|
-
"Access-Control-Allow-Headers": "Content-Type, Authorization",
|
|
179
|
-
};
|
|
180
|
-
// Handle OPTIONS requests
|
|
181
|
-
if (request.method === "OPTIONS") {
|
|
182
|
-
return new Response(null, { headers: corsHeaders });
|
|
183
|
-
}
|
|
184
|
-
// Route requests
|
|
185
|
-
let response;
|
|
186
|
-
switch (url.pathname) {
|
|
187
|
-
case "/api/users/get_hey_gen_config":
|
|
188
|
-
response = await handleGetConfig(request, env);
|
|
189
|
-
break;
|
|
190
|
-
case "/api/users/hey_gen_conversation_backup":
|
|
191
|
-
response = await handleConversationBackup(request, env);
|
|
192
|
-
break;
|
|
193
|
-
case "/api/users/hey_gen_audio_backup":
|
|
194
|
-
response = await handleAudioBackup(request, env);
|
|
195
|
-
break;
|
|
196
|
-
case "/api/users/hey_gen_end_session":
|
|
197
|
-
response = await handleEndSession(request, env);
|
|
198
|
-
break;
|
|
199
|
-
default:
|
|
200
|
-
response = new Response("Not Found", { status: 404 });
|
|
201
|
-
}
|
|
202
|
-
// Add CORS headers to response
|
|
203
|
-
Object.entries(corsHeaders).forEach(([key, value]) => {
|
|
204
|
-
response.headers.set(key, value);
|
|
205
|
-
});
|
|
206
|
-
return response;
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
console.error("Worker error:", error);
|
|
210
|
-
return new Response("Internal Server Error", { status: 500 });
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generativeAi.d.ts","sourceRoot":"","sources":["../../../active-citizen/workers/generativeAi.ts"],"names":[],"mappings":";AAQA,qBAAa,kBAAkB;IACvB,OAAO,CAAC,WAAW,EAAE,6BAA6B,EAAE,QAAQ,EAAE,GAAG;CA8CxE"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
// AgentProductManager.ts
|
|
2
|
-
import { YpAgentProduct } from './models/agentProduct.js';
|
|
3
|
-
import { YpAgentProductRun } from './models/agentProductRun.js';
|
|
4
|
-
export class AgentProductManager {
|
|
5
|
-
constructor() {
|
|
6
|
-
// Initialize if necessary
|
|
7
|
-
}
|
|
8
|
-
// Get all agent products, with optional filters
|
|
9
|
-
async getAgentProducts(filters = {}) {
|
|
10
|
-
try {
|
|
11
|
-
const agentProducts = await YpAgentProduct.findAll({ where: filters });
|
|
12
|
-
return agentProducts;
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
throw new Error(`Error fetching agent products: ${error.message}`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
// Get a specific agent product
|
|
19
|
-
async getAgentProduct(agentProductId) {
|
|
20
|
-
try {
|
|
21
|
-
const agentProduct = await YpAgentProduct.findByPk(agentProductId);
|
|
22
|
-
return agentProduct;
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
throw new Error(`Error fetching agent product: ${error.message}`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
// Create a new agent product
|
|
29
|
-
async createAgentProduct(data) {
|
|
30
|
-
try {
|
|
31
|
-
const agentProduct = await YpAgentProduct.create(data);
|
|
32
|
-
return agentProduct;
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
throw new Error(`Error creating agent product: ${error.message}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
// Update an existing agent product
|
|
39
|
-
async updateAgentProduct(agentProductId, updates) {
|
|
40
|
-
try {
|
|
41
|
-
const agentProduct = await YpAgentProduct.findByPk(agentProductId);
|
|
42
|
-
if (!agentProduct) {
|
|
43
|
-
throw new Error('Agent product not found');
|
|
44
|
-
}
|
|
45
|
-
Object.assign(agentProduct, updates);
|
|
46
|
-
await agentProduct.save();
|
|
47
|
-
return agentProduct;
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
throw new Error(`Error updating agent product: ${error.message}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// Delete an agent product
|
|
54
|
-
async deleteAgentProduct(agentProductId) {
|
|
55
|
-
try {
|
|
56
|
-
const agentProduct = await YpAgentProduct.findByPk(agentProductId);
|
|
57
|
-
if (!agentProduct) {
|
|
58
|
-
throw new Error('Agent product not found');
|
|
59
|
-
}
|
|
60
|
-
await agentProduct.destroy();
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
throw new Error(`Error deleting agent product: ${error.message}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// Get runs associated with an agent product
|
|
67
|
-
async getAgentProductRuns(agentProductId) {
|
|
68
|
-
try {
|
|
69
|
-
const runs = await YpAgentProductRun.findAll({
|
|
70
|
-
where: { agent_product_id: agentProductId },
|
|
71
|
-
});
|
|
72
|
-
return runs;
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
throw new Error(`Error fetching agent product runs: ${error.message}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
// Get the status of an agent product
|
|
79
|
-
async getAgentProductStatus(agentProductId) {
|
|
80
|
-
try {
|
|
81
|
-
const agentProduct = await YpAgentProduct.findByPk(agentProductId);
|
|
82
|
-
if (!agentProduct) {
|
|
83
|
-
throw new Error('Agent product not found');
|
|
84
|
-
}
|
|
85
|
-
return agentProduct.status;
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
throw new Error(`Error fetching agent product status: ${error.message}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|