Bind audio.transcribe hydration to current message turn
This commit is contained in:
+23
-2
@@ -215,6 +215,26 @@ function persistLatestAudioAttachment(
|
||||
}
|
||||
}
|
||||
|
||||
function extractLatestAudioToolInput(audioAttachments: Attachment[]): { data?: string; url?: string; mime_type?: string } | undefined {
|
||||
const latest = [...audioAttachments].reverse().find((att) => (
|
||||
(typeof att.data === 'string' && att.data.length > 0)
|
||||
|| (typeof att.url === 'string' && att.url.length > 0)
|
||||
));
|
||||
if (!latest) {
|
||||
return undefined;
|
||||
}
|
||||
const data = typeof latest.data === 'string' && latest.data.length > 0 ? latest.data : undefined;
|
||||
const url = typeof latest.url === 'string' && latest.url.length > 0 ? latest.url : undefined;
|
||||
if (!data && !url) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
...(data ? { data } : {}),
|
||||
...(url ? { url } : {}),
|
||||
mime_type: latest.mimeType,
|
||||
};
|
||||
}
|
||||
|
||||
function isTtsEnabledForChannel(config: Config, channel: string): boolean {
|
||||
if (!config.tts?.enabled) {
|
||||
return false;
|
||||
@@ -1317,6 +1337,7 @@ export function createMessageRouter(deps: {
|
||||
let messageText = incomingText;
|
||||
let attachments = msg.attachments;
|
||||
const audioAttachments = (msg.attachments ?? []).filter((a: Attachment) => isSupportedAudio(a));
|
||||
const turnAudioToolInput = extractLatestAudioToolInput(audioAttachments);
|
||||
if (audioAttachments.length > 0) {
|
||||
persistLatestAudioAttachment(session, audioAttachments);
|
||||
}
|
||||
@@ -1424,7 +1445,7 @@ export function createMessageRouter(deps: {
|
||||
let response: string;
|
||||
activeRuns.set(sessionIdForRun, agent);
|
||||
try {
|
||||
response = await agent.process(messageText, attachments);
|
||||
response = await agent.process(messageText, attachments, turnAudioToolInput);
|
||||
} catch (error) {
|
||||
const currentTier = agent.getModelTier();
|
||||
const canEscalate = deps.config.agents.auto_escalate && currentTier !== 'complex';
|
||||
@@ -1434,7 +1455,7 @@ export function createMessageRouter(deps: {
|
||||
|
||||
console.warn(`Auto-escalating session ${msg.channel}:${msg.senderId} from ${currentTier} to complex after processing failure.`);
|
||||
agent.setModelTier('complex');
|
||||
response = await agent.process(messageText, attachments);
|
||||
response = await agent.process(messageText, attachments, turnAudioToolInput);
|
||||
}
|
||||
const outboundAttachments = collector.drain();
|
||||
const ttsAttachment = await maybeBuildTtsAttachment(response, msg.channel);
|
||||
|
||||
Reference in New Issue
Block a user