tango-app-api-audio-analytics 1.0.16 → 1.0.17

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.16",
3
+ "version": "1.0.17",
4
4
  "description": "audioAnalytics",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -418,18 +418,31 @@ Only return the JSON array, no other text.`;
418
418
  } );
419
419
 
420
420
  const result = await model.generateContent( suggestionPrompt );
421
- const responseText = result.response.text().trim();
422
- logger.info( { responseText } );
421
+ let responseText = result.response.text().trim();
422
+ logger.info( { message: 'Raw Gemini response', responseText } );
423
+
424
+ // Remove markdown code fences (```json ... ```)
425
+ responseText = responseText.replace( /^```(?:json)?\s*/i, '' ).replace( /\s*```$/, '' ).trim();
426
+ logger.info( { message: 'Cleaned response', responseText } );
427
+
423
428
  // Parse the JSON array response
424
429
  let suggestionsArray = [];
425
- suggestionsArray = JSON.parse( responseText );
426
- logger.info( { suggestionsArray } );
430
+ try {
431
+ suggestionsArray = JSON.parse( responseText );
427
432
 
428
- if ( !Array.isArray( suggestionsArray ) ) {
429
- suggestionsArray = [];
433
+ if ( !Array.isArray( suggestionsArray ) ) {
434
+ suggestionsArray = [];
435
+ }
436
+ } catch ( parseError ) {
437
+ logger.warn( { message: 'Failed to parse Gemini response as JSON', error: parseError.message, responseText } );
438
+ // Fallback: try to extract suggestions from text
439
+ suggestionsArray = responseText.split( '\n' ).filter( ( line ) => line.trim() ).map( ( text, index ) => ( {
440
+ id: index + 1,
441
+ text: text.replace( /^\d+\.\s*/, '' ).trim(),
442
+ category: 'general',
443
+ } ) );
430
444
  }
431
445
 
432
-
433
446
  logger.info( { message: 'Gemini autocomplete suggestions generated', context, suggestionCount: suggestionsArray.length } );
434
447
 
435
448
  return res.sendSuccess( { suggestions: suggestionsArray } );
@@ -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, chatHistoryListValid, getChatValid, getGeminiResponseValid } from '../dtos/audioAnalytics.dtos.js';
6
- import { createCohort, createBulkCohort, updateCohort, deleteCohort, getCohort, listCohortsByClient, chatStream, chatHistoryList, getChat, getGeminiResponse } from '../controllers/audioAnalytics.controller.js';
5
+ import { cohortAnalysisCardValid, conversationsListValid, conversationDetailsValid, chatHistoryListValid, getChatValid, getGeminiResponseValid } from '../dtos/audioAnalytics.dtos.js';
6
+ import { createCohort, createBulkCohort, updateCohort, deleteCohort, getCohort, listCohortsByClient, chatHistoryList, getChat, getGeminiResponse } 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
 
@@ -32,8 +32,6 @@ audioAnalyticsrouter.post( '/cohort-analysis-card', validate( cohortAnalysisCard
32
32
  audioAnalyticsrouter.post( '/conversations/list', validate( conversationsListValid ), getConversationsList );
33
33
  audioAnalyticsrouter.post( '/conversations/:conversationId', validate( conversationDetailsValid ), getConversationDetails );
34
34
 
35
- // Chat Stream API Route
36
- audioAnalyticsrouter.post( '/chat/stream', validate( chatStreamValid ), chatStream );
37
35
 
38
36
  // Gemini Suggestion Prompts API Route
39
37
  audioAnalyticsrouter.post( '/gemini/suggestions', validate( getGeminiResponseValid ), getGeminiResponse );