mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
refactor: separate voice sessions from protocol adapters
This commit is contained in:
1 parent
584c9608d5
commit
4507f3a1d0
13 files changed
+735
-62
No files matched your search
@@ -0,0 +1,45 @@
|
||||
/** Only this adapter knows the Realtime transcript and response event names. */
|
||||
export function realtimeSessionEvent(payload) {
|
||||
const type = payload?.type;
|
||||
if (type === 'input_audio_buffer.speech_started')
|
||||
return { type: 'interruption', reason: 'user-speech' };
|
||||
if (type === 'conversation.item.input_audio_transcription.completed')
|
||||
return {
|
||||
type: 'transcript',
|
||||
role: 'user',
|
||||
text: payload.transcript || '',
|
||||
final: true,
|
||||
itemId: payload.item_id || null,
|
||||
};
|
||||
if (
|
||||
[
|
||||
'response.output_audio_transcript.delta',
|
||||
'response.output_audio_transcript.done',
|
||||
'response.output_text.delta',
|
||||
'response.output_text.done',
|
||||
'response.audio_transcript.delta',
|
||||
'response.audio_transcript.done',
|
||||
'response.text.delta',
|
||||
'response.text.done',
|
||||
].includes(type)
|
||||
) {
|
||||
const final = type.endsWith('.done');
|
||||
return {
|
||||
type: 'transcript',
|
||||
role: 'assistant',
|
||||
text: final
|
||||
? (payload.transcript ?? payload.text ?? '')
|
||||
: payload.delta || '',
|
||||
final,
|
||||
itemId: payload.item_id || null,
|
||||
responseId: payload.response_id || null,
|
||||
};
|
||||
}
|
||||
if (type === 'response.done')
|
||||
return {
|
||||
type: 'completion',
|
||||
responseId: payload.response?.id || null,
|
||||
status: payload.response?.status || 'unknown',
|
||||
};
|
||||
return null;
|
||||
}
|
||||
Reference in new issue
Block a user