feat(voice): specialize prompt for Isfahan Industrial Parks, emit source excerpts, and bound generation
- Specialize voice assistant identity and agent system prompt for «شرکت شهرکهای صنعتی اصفهان» (English instructions with Persian proper names) - Emit bounded chunk text excerpts (up to 2000 chars) and identify primary_source in realtime sources events - Bound OpenAI output generation via OPENAI_REALTIME_MAX_OUTPUT_TOKENS and add answer_limited event - Handle old-turn search cancellation safely on turn supersession - Add end-to-end search tracing pipeline and diagnostic CLI - Add database organization title and settings update script
This commit is contained in:
@@ -10,14 +10,27 @@ export class VoiceTranscripts {
|
||||
this.store(key, {...row, status: 'interrupted'});
|
||||
return this.rows.get(key);
|
||||
}
|
||||
if (event.type === 'answer_limited') {
|
||||
if (typeof event.turn_ref !== 'string' || !event.turn_ref || event.reason !== 'output_token_limit') throw new Error('INVALID_TRANSCRIPT');
|
||||
const key = event.turn_ref + ':assistant';
|
||||
const row = this.rows.get(key) || {turn_ref: event.turn_ref, role: 'assistant', text: ''};
|
||||
if (row.status !== 'interrupted') this.store(key, {...row, status: 'limited'});
|
||||
return this.rows.get(key);
|
||||
}
|
||||
if (event.type !== 'transcript') return null;
|
||||
const {turn_ref, role, text, status} = event;
|
||||
if (typeof turn_ref !== 'string' || !turn_ref || !['user', 'assistant'].includes(role)
|
||||
|| typeof text !== 'string' || !['partial', 'completed', 'interrupted'].includes(status)) {
|
||||
|| typeof text !== 'string' || !['partial', 'completed', 'limited', 'interrupted'].includes(status)) {
|
||||
throw new Error('INVALID_TRANSCRIPT');
|
||||
}
|
||||
const key = turn_ref + ':' + role, previous = this.rows.get(key);
|
||||
if (previous?.status === 'interrupted') return previous;
|
||||
if (status === 'limited' && role !== 'assistant') throw new Error('INVALID_TRANSCRIPT');
|
||||
if (previous?.status === 'limited') {
|
||||
if (status !== 'limited') return previous;
|
||||
this.store(key, {turn_ref, role, text, status});
|
||||
return this.rows.get(key);
|
||||
}
|
||||
if (previous?.status === 'completed') {
|
||||
if (status === 'completed' && text === previous.text) return previous;
|
||||
throw new Error('TRANSCRIPT_AFTER_COMPLETION');
|
||||
|
||||
Reference in New Issue
Block a user