feat: pass sessionId to voice API calls for usage cost attribution - #320
feat: pass sessionId to voice API calls for usage cost attribution#320VISHNUDAS-tunerlabs wants to merge 1 commit into
Conversation
…o backend for usage costing of voices
|
Important Review skippedNo new commits to review since the last review. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThree AI4Bharat API functions ( ChangesSession/Profile Context in AI4Bharat APIs
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/pages/ai-creation/apiServices/ai4bharat_services.js`:
- Around line 4-12: The new sessionId parameter in handleAI4BharatTTSRequest is
being populated by an outdated positional caller, causing storedRoute to be
passed as the wrong argument. Update the remaining call site in audio_service.js
to pass sessionId and profileId in the correct positions, or switch that caller
to an object/explicit arguments so the 8th and 9th parameters are not
misaligned. Use handleAI4BharatTTSRequest and the audio service caller as the
symbols to locate and fix the mismatch.
In `@src/pages/ai-creation/components/textarea-with-mic/index.jsx`:
- Around line 164-169: The AI-creation ASR call in textarea-with-mic’s audio
submission flow only passes sessionId, so fallback attribution is missing when
getSession() is unavailable. Update the ai4BharatASRApi invocation in the
textarea-with-mic component to also pass the fallback profile/user identifier
(profileId) alongside sessionRoute and sessionId, using the same identifier
source already added elsewhere in the PR so requests remain attributed when no
session exists.
In
`@src/pages/ai-creation/pages/shikshalokam-mitra/mitra-pages/components/ChatBox.jsx`:
- Around line 177-182: The ASR request in ChatBox still omits the fallback
attribution identifier, so voice usage can be detached when the session store is
unavailable. Update the ai4BharatASRApi call in ChatBox to pass the new
profileId fallback alongside sessionId, using the same identifier selection
logic already used elsewhere so UsageCostLog can always attribute the request.
In
`@src/pages/ai-creation/pages/shikshalokam-mitra/mitra-pages/components/VoiceChat.jsx`:
- Around line 135-139: The ai4BharatASRApi call in VoiceChat currently forwards
only sessionId, which can leave ASR requests unattributed when the session is
not yet set. Update the VoiceChat component to pass the same fallback
profile/user identifier used elsewhere in this flow, alongside sessionId, so the
ASR request always has a valid attribution source even when the session is
unavailable.
In `@src/pages/shikshagraha-repository/listing/Filters.jsx`:
- Line 163: The repository ASR call in Filters.jsx is still passing only
sessionId, so the fallback identifier is missing when sessionId is unavailable.
Update the ai4BharatASRApi invocation in the listing Filters flow to include the
fallback profile/user identifier used elsewhere on this page, preserving
attribution when sessionId is absent. Use the existing variables around
transcriptResult and ai4BharatASRApi to locate the call and make sure the
backend receives a non-null identifier consistently.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: dd087b3a-0f4c-4cda-8362-422aea3a55d2
📒 Files selected for processing (11)
src/api/endpoints/ai.jssrc/pages/ShikshalokamVoiceChat/dynamic-voice-chat.jssrc/pages/ShikshalokamVoiceChat/voice-chat.jssrc/pages/UnifiedChat/UnifiedVoiceBasedChat.jsxsrc/pages/ai-creation/apiServices/ai4bharat_services.jssrc/pages/ai-creation/components/textarea-with-mic/index.jsxsrc/pages/ai-creation/pages/shikshalokam-mitra/mitra-pages/components/ChatBox.jsxsrc/pages/ai-creation/pages/shikshalokam-mitra/mitra-pages/components/VoiceChat.jsxsrc/pages/shikshagraha-repository/listing/Filters.jsxsrc/services/api.service.jssrc/services/audio_service.js
| export const handleAI4BharatTTSRequest = async (text, id, language, audioCache, setAudioCache, audioRef, setIsBotTalking, sessionId = null, profileId = null) => { | ||
|
|
||
| try { | ||
| let cachedAudioUrl = audioCache[id]; | ||
| let audio_result = ""; | ||
| let audio; | ||
|
|
||
| if (!cachedAudioUrl) { | ||
| audio_result = await getAI4BharatAudioApi(text, language, bot_routes.mitra_create); | ||
| audio_result = await getAI4BharatAudioApi(text, language, bot_routes.mitra_create, sessionId, profileId); |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Update the remaining positional caller before this ships.
Line 4 adds a real 8th parameter, but src/services/audio_service.js:30 still passes storedRoute in that slot. That value will now be forwarded as sessionId, so TTS usage from that path will be tagged with the route string instead of the chat session.
Also applies to: 31-31
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/pages/ai-creation/apiServices/ai4bharat_services.js` around lines 4 - 12,
The new sessionId parameter in handleAI4BharatTTSRequest is being populated by
an outdated positional caller, causing storedRoute to be passed as the wrong
argument. Update the remaining call site in audio_service.js to pass sessionId
and profileId in the correct positions, or switch that caller to an
object/explicit arguments so the 8th and 9th parameters are not misaligned. Use
handleAI4BharatTTSRequest and the audio service caller as the symbols to locate
and fix the mismatch.
| const transcript = await ai4BharatASRApi( | ||
| s3Url, | ||
| languageToUse, | ||
| sessionRoute | ||
| sessionRoute, | ||
| sessionId | ||
| ); |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Forward the fallback profile/user identifier here too.
Line 164 only adds sessionId. When getSession() is falsy, ai4BharatASRApi will omit sessionid, and this caller still never supplies the new profileId fallback that the endpoint now supports. That leaves AI-creation ASR requests unattributed in exactly the case this PR is trying to fix.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/pages/ai-creation/components/textarea-with-mic/index.jsx` around lines
164 - 169, The AI-creation ASR call in textarea-with-mic’s audio submission flow
only passes sessionId, so fallback attribution is missing when getSession() is
unavailable. Update the ai4BharatASRApi invocation in the textarea-with-mic
component to also pass the fallback profile/user identifier (profileId)
alongside sessionRoute and sessionId, using the same identifier source already
added elsewhere in the PR so requests remain attributed when no session exists.
| transcriptResult = await ai4BharatASRApi( | ||
| s3Url, | ||
| languageToUse, | ||
| sessionRoute | ||
| sessionRoute, | ||
| sessionId | ||
| ); |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
This ASR path still drops the fallback attribution key.
Line 177 forwards sessionId, but not the new profileId fallback supported by ai4BharatASRApi. If the session store is empty or not initialized yet, this request still goes out without an identifier, so voice usage for this flow will remain detached from UsageCostLog.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@src/pages/ai-creation/pages/shikshalokam-mitra/mitra-pages/components/ChatBox.jsx`
around lines 177 - 182, The ASR request in ChatBox still omits the fallback
attribution identifier, so voice usage can be detached when the session store is
unavailable. Update the ai4BharatASRApi call in ChatBox to pass the new
profileId fallback alongside sessionId, using the same identifier selection
logic already used elsewhere so UsageCostLog can always attribute the request.
| transcriptResult = await ai4BharatASRApi( | ||
| s3Url, | ||
| languageToUse, | ||
| storedRoute | ||
| storedRoute, | ||
| sessionId |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Forward the fallback profile/user identifier here too.
This call only adds sessionId, but the stated contract for this PR is sessionId with a profile/user fallback. If the ai-creation session is still unset, ASR usage from this component will still miss session attribution.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@src/pages/ai-creation/pages/shikshalokam-mitra/mitra-pages/components/VoiceChat.jsx`
around lines 135 - 139, The ai4BharatASRApi call in VoiceChat currently forwards
only sessionId, which can leave ASR requests unattributed when the session is
not yet set. Update the VoiceChat component to pass the same fallback
profile/user identifier used elsewhere in this flow, alongside sessionId, so the
ASR request always has a valid attribution source even when the session is
unavailable.
| let storedRoute = bot_routes.search_bot | ||
|
|
||
| transcriptResult = await ai4BharatASRApi(s3Url, languageToUse, storedRoute) | ||
| transcriptResult = await ai4BharatASRApi(s3Url, languageToUse, storedRoute, sessionId) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
This repository ASR path still misses the fallback identifier.
Line 163 forwards only sessionId. On this page that value can be absent, so voice-search costs will still be logged without the profile/user context the backend needs for attribution.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/pages/shikshagraha-repository/listing/Filters.jsx` at line 163, The
repository ASR call in Filters.jsx is still passing only sessionId, so the
fallback identifier is missing when sessionId is unavailable. Update the
ai4BharatASRApi invocation in the listing Filters flow to include the fallback
profile/user identifier used elsewhere on this page, preserving attribution when
sessionId is absent. Use the existing variables around transcriptResult and
ai4BharatASRApi to locate the call and make sure the backend receives a non-null
identifier consistently.
Summary
sessionId(oruserIdas fallback) in the request payload sent to the backend
Transliteration costs to the right
ChatSessioninUsageCostLogUsage Cost Dashboard would show $0 for all voice call types
Context
Part of the Usage Cost (Phase 2) feature. The backend now records a
UsageCostLogrow after every voice provider call, but it needs asession_idfrom the client to link the cost to the correct session. This change supplies
that identifier from the frontend.
Summary by CodeRabbit
New Features
Bug Fixes