feat(backend): modèle unifié streaming/progress/events provider-agnostic + pont app-tauri — foundation #156 (QA verte)

This commit is contained in:
2026-08-06 13:13:17 +02:00
parent 40fa551f32
commit 918116664c
14 changed files with 630 additions and 59 deletions

View File

@ -30,7 +30,9 @@ use backend::stream::ReplayOutputBridge;
use tauri::ipc::Channel;
use domain::ids::SessionId;
use domain::ports::ReplyEvent;
use domain::ports::{
ReplyEvent, ReplyProgress, ReplyProgressKind, ReplyProgressSource, ReplyProgressStage,
};
use crate::dto::ReplyChunk;
use crate::stream::TauriChannelSink;
@ -136,6 +138,13 @@ fn reply_chunk_bytes(chunk: &ReplyChunk) -> usize {
ReplyChunk::UserPrompt { text } => text.len(),
ReplyChunk::TextDelta { text } => text.len(),
ReplyChunk::ToolActivity { label } => label.len(),
ReplyChunk::Progress { progress } => {
progress.label.len()
+ progress.text.as_ref().map_or(0, String::len)
+ progress.provider.as_ref().map_or(0, String::len)
+ progress.native_event.as_ref().map_or(0, String::len)
+ progress.tool_name.as_ref().map_or(0, String::len)
}
ReplyChunk::Final { content } => content.len(),
ReplyChunk::Error { message } => message.len(),
}
@ -154,8 +163,20 @@ fn reply_chunk_bytes(chunk: &ReplyChunk) -> usize {
#[must_use]
pub fn chunk_from_event(event: ReplyEvent) -> Option<ReplyChunk> {
match event {
ReplyEvent::Progress { progress } => Some(ReplyChunk::Progress {
progress: progress.into(),
}),
ReplyEvent::TextDelta { text } => Some(ReplyChunk::TextDelta { text }),
ReplyEvent::ToolActivity { label } => Some(ReplyChunk::ToolActivity { label }),
ReplyEvent::ToolActivity { label } => Some(ReplyChunk::Progress {
progress: ReplyProgress::new(
ReplyProgressSource::ProviderNative,
ReplyProgressKind::Tool,
ReplyProgressStage::Info,
label.clone(),
)
.with_tool_name(label)
.into(),
}),
ReplyEvent::Error { message } => Some(ReplyChunk::Error { message }),
ReplyEvent::Final { content } => {
if content.trim().is_empty() {
@ -166,7 +187,16 @@ pub fn chunk_from_event(event: ReplyEvent) -> Option<ReplyChunk> {
Some(ReplyChunk::Final { content })
}
}
ReplyEvent::Announcement { .. } => None,
ReplyEvent::Announcement { text } => Some(ReplyChunk::Progress {
progress: ReplyProgress::new(
ReplyProgressSource::ProviderNative,
ReplyProgressKind::Message,
ReplyProgressStage::Delta,
"message intermédiaire",
)
.with_text(text)
.into(),
}),
ReplyEvent::Heartbeat => None,
ReplyEvent::RateLimited { .. } => None,
}