tango-app-api-audio-analytics 1.0.14 → 1.0.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audio-analytics",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "audioAnalytics",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -234,6 +234,94 @@ export async function listCohortsByClient( req, res ) {
234
234
  }
235
235
  }
236
236
 
237
+
238
+ export async function chatHistoryList( req, res ) {
239
+ try {
240
+ /* eslint-disable camelcase */
241
+ const { userId, limit = 10, offset = 0 } = req.body;
242
+
243
+ logger.info( { message: 'Fetching chat history', userId, limit, offset } );
244
+
245
+ // Build OpenSearch query to filter by user_id
246
+ const query = {
247
+ query: {
248
+ match: {
249
+ user_id: userId,
250
+ },
251
+ },
252
+ _source: [ 'session_id', 'session_title' ], // Only fetch required fields
253
+ size: Number( limit ),
254
+ from: Number( offset ),
255
+ sort: [ { session_date: { order: 'desc' } } ], // Sort by creation date, most recent first
256
+ };
257
+
258
+ // Search in tango-ai-session index
259
+ const result = await searchOpenSearchData( 'tango-ai-sessions', query );
260
+ logger.info( { message: 'Chat history search result', resultHits: result?.body?.hits?.hits?.length } );
261
+
262
+ if ( !result || !result.body || !result.body.hits ) {
263
+ return res.sendError( 'Failed to fetch chat history', 500 );
264
+ }
265
+
266
+ const total = result.body.hits.total?.value || 0;
267
+ const sessions = ( result.body.hits.hits || [] ).map( ( hit ) => ( {
268
+ session_id: hit._source.session_id,
269
+ session_title: hit._source.session_title,
270
+ } ) );
271
+ /* eslint-enable camelcase */
272
+
273
+ return res.sendSuccess( {
274
+ sessions,
275
+ count: total,
276
+ // pagination: {
277
+ // total,
278
+ // limit: Number( limit ),
279
+ // offset: Number( offset ),
280
+ // hasMore: Number( offset ) + Number( limit ) < total,
281
+ // },
282
+ } );
283
+ } catch ( error ) {
284
+ const err = error.message || 'Internal Server Error';
285
+ logger.error( { error, message: req.body, function: 'chatHistoryList' } );
286
+ return res.sendError( err, 500 );
287
+ }
288
+ }
289
+
290
+ export async function getChat( req, res ) {
291
+ try {
292
+ /* eslint-disable camelcase */
293
+ const { sessionId } = req.body;
294
+
295
+ logger.info( { message: 'Fetching chat details', sessionId } );
296
+
297
+ // Build OpenSearch query to find by session_id
298
+ const query = {
299
+ query: {
300
+ match: {
301
+ session_id: sessionId,
302
+ },
303
+ },
304
+ };
305
+
306
+ // Search in tango-ai-sessions index
307
+ const result = await searchOpenSearchData( 'tango-ai-sessions', query );
308
+ logger.info( { message: 'Chat details search result', found: result?.body?.hits?.hits?.length > 0 } );
309
+
310
+ if ( !result || !result.body || !result.body.hits || result.body.hits.hits.length === 0 ) {
311
+ return res.sendError( 'Chat session not found', 404 );
312
+ }
313
+
314
+ const chatSession = result.body.hits.hits[0]._source;
315
+ /* eslint-enable camelcase */
316
+
317
+ return res.sendSuccess( chatSession );
318
+ } catch ( error ) {
319
+ const err = error.message || 'Internal Server Error';
320
+ logger.error( { error, message: req.body, function: 'getChat' } );
321
+ return res.sendError( err, 500 );
322
+ }
323
+ }
324
+
237
325
  export const callExternalStreamAPI = async ( req, res ) => {
238
326
  try {
239
327
  const { prompt, storeId, productModule, country, region, fromDate, toDate, clusters } = req.body;
@@ -380,3 +468,4 @@ export async function chatStream( req, res ) {
380
468
  }
381
469
  }
382
470
 
471
+
@@ -686,3 +686,33 @@ const chatStreamSchema = joi.object( {
686
686
  export const chatStreamValid = {
687
687
  body: chatStreamSchema,
688
688
  };
689
+
690
+ // ======================= CHAT HISTORY LIST API SCHEMA =======================
691
+
692
+ /**
693
+ * Chat History List Request Schema
694
+ * For fetching session history by user_id from tango-ai-session index
695
+ */
696
+ const chatHistoryListSchema = joi.object( {
697
+ userId: joi.string().required().description( 'User ID to fetch session history for' ),
698
+ limit: joi.number().integer().min( 1 ).max( 1000 ).optional().default( 10 ).description( 'Pagination limit' ),
699
+ offset: joi.number().integer().min( 0 ).optional().default( 0 ).description( 'Pagination offset' ),
700
+ } ).strict();
701
+
702
+ export const chatHistoryListValid = {
703
+ body: chatHistoryListSchema,
704
+ };
705
+
706
+ // ======================= GET SINGLE CHAT API SCHEMA =======================
707
+
708
+ /**
709
+ * Get Single Chat Request Schema
710
+ * For fetching a single session by session_id from tango-ai-sessions index
711
+ */
712
+ const getChatSchema = joi.object( {
713
+ sessionId: joi.string().required().description( 'Session ID to fetch' ),
714
+ } ).strict();
715
+
716
+ export const getChatValid = {
717
+ body: getChatSchema,
718
+ };
@@ -2,8 +2,8 @@
2
2
  import express from 'express';
3
3
  import { validate } from 'tango-app-api-middleware';
4
4
  import { createCohortValid, createBulkCohortValid, updateCohortValid, getCohortValid, listCohortsByClientValid, deleteCohortValid } from '../dtos/audioAnalytics.dtos.js';
5
- import { cohortAnalysisCardValid, conversationsListValid, conversationDetailsValid, chatStreamValid } from '../dtos/audioAnalytics.dtos.js';
6
- import { createCohort, createBulkCohort, updateCohort, deleteCohort, getCohort, listCohortsByClient, chatStream } from '../controllers/audioAnalytics.controller.js';
5
+ import { cohortAnalysisCardValid, conversationsListValid, conversationDetailsValid, chatStreamValid, chatHistoryListValid, getChatValid } from '../dtos/audioAnalytics.dtos.js';
6
+ import { createCohort, createBulkCohort, updateCohort, deleteCohort, getCohort, listCohortsByClient, chatStream, chatHistoryList, getChat } from '../controllers/audioAnalytics.controller.js';
7
7
  import { getCohortAnalysisCard } from '../controllers/cohortAnalytics.controller.js';
8
8
  import { getConversationsList, getConversationDetails } from '../controllers/conversationAnalytics.controller.js';
9
9
 
@@ -23,6 +23,8 @@ audioAnalyticsrouter.post( '/update-cohort', validate( updateCohortValid ), upda
23
23
  audioAnalyticsrouter.get( '/get-cohort/:cohortId', validate( getCohortValid ), getCohort );
24
24
  audioAnalyticsrouter.get( '/list-cohorts', validate( listCohortsByClientValid ), listCohortsByClient );
25
25
 
26
+ audioAnalyticsrouter.post( '/chat-history-list', validate( chatHistoryListValid ), chatHistoryList );
27
+ audioAnalyticsrouter.post( '/get-chat', validate( getChatValid ), getChat );
26
28
  // Cohort Analytics Routes
27
29
  audioAnalyticsrouter.post( '/cohort-analysis-card', validate( cohortAnalysisCardValid ), getCohortAnalysisCard );
28
30