refactor: stream text segments for TTS preparation

Refactor LLM streaming to emit complete text segments before tool calls for future TTS integration. Moves from step-based callbacks to chunk-based streaming with text buffering and segment flushing at tool boundaries.
```
This commit is contained in:
Mohamed Boudra
2025-10-19 17:22:43 +02:00
parent 81bdba0d48
commit d7a387d911
2 changed files with 53 additions and 25 deletions
@@ -77,6 +77,18 @@ export async function processUserMessage(params: {
});
}
},
onTextSegment: (segment) => {
// Broadcast complete text segments (for future TTS integration)
if (params.wsServer) {
params.wsServer.broadcastActivityLog({
id: uuidv4(),
timestamp: new Date(),
type: "system",
content: `Text segment: ${segment}`,
metadata: { segment, readyForTTS: true },
});
}
},
onToolCall: (toolName, args) => {
// Broadcast tool call to WebSocket
if (params.wsServer) {
@@ -126,7 +138,7 @@ export async function processUserMessage(params: {
id: uuidv4(),
timestamp: new Date(),
type: "error",
content: `Error: ${error.message}`,
content: `Error: ${error instanceof Error ? error.message : String(error)}`,
});
}
throw error;