feat(backend,frontend): lot utilisateur #310 #311 #312 #313 — horodatage conversation, stop agent robuste, préférence terminal par défaut, paramètres projet (QA verte)
- #310: horodatage de tous les messages et événements de conversation visibles — composant partagé EntryTimestamp, timestamps propagés dans le transcript chat, les annonces inter-agent et le viewer de conversation, normalisation côté domain/adapters (conversation_log, paginate). - #311: stop d'agent robuste pour PTY non monté, sessions headless et CLI custom — lifecycle/orchestrator durcis, ponts chat app-tauri/web-server alignés, arrêt fiable sans session orpheline. - #312: préférence globale d'interface terminal par défaut — nouveau store settings (domain/application/infrastructure + tests), DTO et commandes backend, adapter frontend userSettings, panneau TerminalSettings dans les paramètres globaux. - #313: Paramètres du projet — contexte de projet éditable et couleur de thème par projet (ProjectSettingsPanel + projectTheme), teinte des onglets projet, persistance via DTO projet. QA verte (GO QA sur feature/batch-310-311-312-313-chat-stop-prefs-theme) — vérifications Git: git diff --cached --check OK; staging borné à crates/ et frontend/ (74 fichiers, +2105/-531), commit unique de lot conforme à la convention des lots (précédents batch-151/158/159, batch-210/211/212) car les fichiers partagés (dto.rs, commands.rs, CustomAgentChatView) entrelacent les 4 tickets. fichiers .ideai/* (agents/test.md, chat-drafts.json, system-permissions.json, tickets/counter.json, tickets/index.json, tickets/308-313/), attachments/ et scripts/ hors périmètre et préservés en worktree ; aucun push. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -344,6 +344,7 @@ fn progress_entity_key(progress: &ReplyProgressDto) -> Option<String> {
|
||||
fn reply_chunk_bytes(chunk: &ReplyChunk) -> usize {
|
||||
match chunk {
|
||||
ReplyChunk::UserPrompt {
|
||||
at_ms: _,
|
||||
text,
|
||||
attachments,
|
||||
attachment_refs,
|
||||
@ -360,8 +361,8 @@ fn reply_chunk_bytes(chunk: &ReplyChunk) -> usize {
|
||||
})
|
||||
.sum::<usize>()
|
||||
}
|
||||
ReplyChunk::TextDelta { text } => text.len(),
|
||||
ReplyChunk::ToolActivity { label } => label.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)
|
||||
@ -369,8 +370,8 @@ fn reply_chunk_bytes(chunk: &ReplyChunk) -> usize {
|
||||
+ 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(),
|
||||
ReplyChunk::Final { content, .. } => content.len(),
|
||||
ReplyChunk::Error { message, .. } => message.len(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -386,40 +387,57 @@ fn reply_chunk_bytes(chunk: &ReplyChunk) -> usize {
|
||||
/// too. Every content-bearing event still maps to exactly one chunk.
|
||||
#[must_use]
|
||||
pub fn chunk_from_event(event: ReplyEvent) -> Option<ReplyChunk> {
|
||||
chunk_from_event_at(event, None)
|
||||
}
|
||||
|
||||
/// Maps a domain reply event while preserving the backend acceptance time.
|
||||
#[must_use]
|
||||
pub fn chunk_from_event_at(event: ReplyEvent, at_ms: Option<u64>) -> Option<ReplyChunk> {
|
||||
match event {
|
||||
ReplyEvent::Progress { progress } => Some(ReplyChunk::Progress {
|
||||
progress: progress.into(),
|
||||
}),
|
||||
ReplyEvent::TextDelta { text } => Some(ReplyChunk::TextDelta { text }),
|
||||
ReplyEvent::Progress { progress } => {
|
||||
let mut progress: ReplyProgressDto = progress.into();
|
||||
progress.occurred_at_ms = at_ms;
|
||||
Some(ReplyChunk::Progress { progress })
|
||||
}
|
||||
ReplyEvent::TextDelta { text } => Some(ReplyChunk::TextDelta { text, at_ms }),
|
||||
ReplyEvent::ToolActivity { label } => Some(ReplyChunk::Progress {
|
||||
progress: ReplyProgress::new(
|
||||
ReplyProgressSource::ProviderNative,
|
||||
ReplyProgressKind::Tool,
|
||||
ReplyProgressStage::Info,
|
||||
label.clone(),
|
||||
)
|
||||
.with_tool_name(label)
|
||||
.into(),
|
||||
progress: {
|
||||
let mut progress: ReplyProgressDto = ReplyProgress::new(
|
||||
ReplyProgressSource::ProviderNative,
|
||||
ReplyProgressKind::Tool,
|
||||
ReplyProgressStage::Info,
|
||||
label.clone(),
|
||||
)
|
||||
.with_tool_name(label)
|
||||
.into();
|
||||
progress.occurred_at_ms = at_ms;
|
||||
progress
|
||||
},
|
||||
}),
|
||||
ReplyEvent::Error { message } => Some(ReplyChunk::Error { message }),
|
||||
ReplyEvent::Error { message } => Some(ReplyChunk::Error { message, at_ms }),
|
||||
ReplyEvent::Final { content } => {
|
||||
if content.trim().is_empty() {
|
||||
Some(ReplyChunk::Error {
|
||||
message: "Réponse vide du modèle.".to_owned(),
|
||||
at_ms,
|
||||
})
|
||||
} else {
|
||||
Some(ReplyChunk::Final { content })
|
||||
Some(ReplyChunk::Final { content, at_ms })
|
||||
}
|
||||
}
|
||||
ReplyEvent::Announcement { text } => Some(ReplyChunk::Progress {
|
||||
progress: ReplyProgress::new(
|
||||
ReplyProgressSource::ProviderNative,
|
||||
ReplyProgressKind::Message,
|
||||
ReplyProgressStage::Delta,
|
||||
"message intermédiaire",
|
||||
)
|
||||
.with_text(text)
|
||||
.into(),
|
||||
progress: {
|
||||
let mut progress: ReplyProgressDto = ReplyProgress::new(
|
||||
ReplyProgressSource::ProviderNative,
|
||||
ReplyProgressKind::Message,
|
||||
ReplyProgressStage::Delta,
|
||||
"message intermédiaire",
|
||||
)
|
||||
.with_text(text)
|
||||
.into();
|
||||
progress.occurred_at_ms = at_ms;
|
||||
progress
|
||||
},
|
||||
}),
|
||||
ReplyEvent::Heartbeat => None,
|
||||
ReplyEvent::RateLimited { .. } => None,
|
||||
@ -432,5 +450,20 @@ pub fn chunk_from_event(event: ReplyEvent) -> Option<ReplyChunk> {
|
||||
pub fn unfinished_turn_chunk() -> ReplyChunk {
|
||||
ReplyChunk::Error {
|
||||
message: MODEL_RESPONSE_NOT_FINALIZED_MESSAGE.to_owned(),
|
||||
at_ms: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Assigns an acceptance timestamp to a transport-created chunk.
|
||||
#[must_use]
|
||||
pub fn with_chunk_timestamp(mut chunk: ReplyChunk, at_ms: Option<u64>) -> ReplyChunk {
|
||||
match &mut chunk {
|
||||
ReplyChunk::UserPrompt { at_ms: value, .. }
|
||||
| ReplyChunk::TextDelta { at_ms: value, .. }
|
||||
| ReplyChunk::ToolActivity { at_ms: value, .. }
|
||||
| ReplyChunk::Final { at_ms: value, .. }
|
||||
| ReplyChunk::Error { at_ms: value, .. } => *value = at_ms,
|
||||
ReplyChunk::Progress { progress } => progress.occurred_at_ms = at_ms,
|
||||
}
|
||||
chunk
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ use crate::dto::{
|
||||
MemoryIndexDto, MemoryLinksDto, MemoryListDto, ModelServerConfigDto, ModelServerConfigListDto,
|
||||
OpenCodeProviderListDto, OpenProjectRestoreStateDto, OpenTerminalRequestDto,
|
||||
PreviewModelServerCommandDto, ProfileDto, ProfileListDto, ProfileModelCatalogDto, ProjectDto,
|
||||
ProjectListDto, ProjectMcpToolPermissionsDto, ProjectPermissionsDto,
|
||||
ProjectListDto, ProjectMcpToolPermissionsDto, ProjectPermissionsDto, ProjectSettingsDto,
|
||||
ProjectSystemPermissionsDto, ProjectWorkStateDto, ReadAgentContextResponseDto,
|
||||
ReadChatDraftResponseDto, ReadConversationPageRequestDto, ReattachChatDto, ReattachResultDto,
|
||||
RecallMemoryRequestDto, RemoveOpenProjectRestoreEntryRequestDto, RemoveProjectRequestDto,
|
||||
@ -86,8 +86,8 @@ use crate::dto::{
|
||||
UpdateAgentSystemPermissionsRequestDto, UpdateMemoryRequestDto, UpdateProjectContextRequestDto,
|
||||
UpdateProjectMcpToolPermissionsRequestDto, UpdateProjectOrchestratorRequestDto,
|
||||
UpdateProjectOrchestratorResponseDto, UpdateProjectPermissionsRequestDto,
|
||||
UpdateProjectSystemPermissionsRequestDto, UpdateSkillRequestDto, UpdateTemplateRequestDto,
|
||||
WriteTerminalRequestDto,
|
||||
UpdateProjectSettingsRequestDto, UpdateProjectSystemPermissionsRequestDto,
|
||||
UpdateSkillRequestDto, UpdateTemplateRequestDto, UserSettingsDto, WriteTerminalRequestDto,
|
||||
};
|
||||
use crate::embedded_server::{
|
||||
EmbeddedServerStatusDto, ServerExposurePreviewDto, ServerExposureSettingsDto,
|
||||
@ -815,6 +815,66 @@ pub async fn update_project_context(
|
||||
.map_err(ErrorDto::from)
|
||||
}
|
||||
|
||||
/// Reads global machine-local IdeA preferences.
|
||||
#[tauri::command]
|
||||
pub async fn read_user_settings(state: State<'_, AppState>) -> Result<UserSettingsDto, ErrorDto> {
|
||||
state
|
||||
.read_user_settings
|
||||
.execute()
|
||||
.await
|
||||
.map(Into::into)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Replaces global machine-local IdeA preferences.
|
||||
#[tauri::command]
|
||||
pub async fn update_user_settings(
|
||||
request: UserSettingsDto,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<UserSettingsDto, ErrorDto> {
|
||||
state
|
||||
.update_user_settings
|
||||
.execute(request.into())
|
||||
.await
|
||||
.map(Into::into)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Reads project-owned settings without creating a legacy-missing file.
|
||||
#[tauri::command]
|
||||
pub async fn read_project_settings(
|
||||
project_id: String,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<ProjectSettingsDto, ErrorDto> {
|
||||
let project = resolve_project(&project_id, &state).await?;
|
||||
state
|
||||
.read_project_settings
|
||||
.execute(&project)
|
||||
.await
|
||||
.map(Into::into)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Validates and replaces project-owned settings.
|
||||
#[tauri::command]
|
||||
pub async fn update_project_settings(
|
||||
request: UpdateProjectSettingsRequestDto,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<ProjectSettingsDto, ErrorDto> {
|
||||
let project = resolve_project(&request.project_id, &state).await?;
|
||||
let theme_color = request
|
||||
.theme_color
|
||||
.map(domain::ThemeColor::new)
|
||||
.transpose()
|
||||
.map_err(|message| ErrorDto::from(AppError::Invalid(message)))?;
|
||||
state
|
||||
.update_project_settings
|
||||
.execute(&project, domain::ProjectSettings { theme_color })
|
||||
.await
|
||||
.map(Into::into)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// `get_project_permissions` — read `.ideai/permissions.json`.
|
||||
///
|
||||
/// # Errors
|
||||
@ -2198,7 +2258,11 @@ pub async fn stop_live_agent(
|
||||
}
|
||||
state
|
||||
.stop_live_agent
|
||||
.execute(StopLiveAgentInput { project, agent_id })
|
||||
.execute(StopLiveAgentInput {
|
||||
project,
|
||||
agent_id,
|
||||
reason: request.reason,
|
||||
})
|
||||
.await
|
||||
.map(StopLiveAgentResponseDto::from)
|
||||
.map_err(ErrorDto::from)
|
||||
@ -2372,6 +2436,10 @@ pub async fn launch_agent(
|
||||
mcp_runtime,
|
||||
allow_structured_alongside_pty: false,
|
||||
require_structured: request.cell_kind == Some(CellKind::Chat),
|
||||
terminal_interface: request.cell_kind.map(|kind| match kind {
|
||||
CellKind::Pty => domain::DefaultAgentTerminalInterface::NativeTui,
|
||||
CellKind::Chat => domain::DefaultAgentTerminalInterface::IdeaCli,
|
||||
}),
|
||||
fresh_start: request.fresh_start,
|
||||
managed_temp_exposure: application::ManagedTempExposureRequest::default(),
|
||||
})
|
||||
@ -2781,6 +2849,7 @@ pub async fn agent_send(
|
||||
let _ = state.chat_bridge.send_output(
|
||||
&sid,
|
||||
ReplyChunk::UserPrompt {
|
||||
at_ms: u64::try_from(state.clock.now_millis()).ok(),
|
||||
text: prompt.clone(),
|
||||
attachments: attachment_labels,
|
||||
attachment_refs,
|
||||
@ -2793,6 +2862,7 @@ pub async fn agent_send(
|
||||
// still running.
|
||||
let (tap_tx, tap_rx) = std::sync::mpsc::channel();
|
||||
let tap_bridge = std::sync::Arc::clone(&state.chat_bridge);
|
||||
let tap_clock = std::sync::Arc::clone(&state.clock);
|
||||
let tap_sid = sid;
|
||||
let tap_turn_guard = turn_guard.as_ref().map(|guard| guard.liveness_handle());
|
||||
let tap_pump = std::thread::spawn(move || {
|
||||
@ -2803,7 +2873,9 @@ pub async fn agent_send(
|
||||
guard.mark_alive();
|
||||
}
|
||||
}
|
||||
let Some(chunk) = crate::chat::chunk_from_event(event) else {
|
||||
let Some(chunk) =
|
||||
crate::chat::chunk_from_event_at(event, u64::try_from(tap_clock.now_millis()).ok())
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
if matches!(chunk, ReplyChunk::Final { .. } | ReplyChunk::Error { .. }) {
|
||||
@ -2842,6 +2914,7 @@ pub async fn agent_send(
|
||||
// `Final` event (or stream end / superseded channel), then detaches *only its
|
||||
// own* generation so a concurrent re-attach is never torn down.
|
||||
let bridge = std::sync::Arc::clone(&state.chat_bridge);
|
||||
let clock = std::sync::Arc::clone(&state.clock);
|
||||
// Level-1 session-limit tap (§21, niveau 1 — structuré). Resolve the agent, host
|
||||
// cell and engine conversation once from the live registry; a `RateLimited` turn
|
||||
// event then feeds the service (détecter→planifier). Without a conversation id the
|
||||
@ -2879,7 +2952,10 @@ pub async fn agent_send(
|
||||
let _ = bridge.send_output_settled(
|
||||
&sid,
|
||||
&mut settler,
|
||||
ReplyChunk::Error { message },
|
||||
ReplyChunk::Error {
|
||||
message,
|
||||
at_ms: u64::try_from(clock.now_millis()).ok(),
|
||||
},
|
||||
);
|
||||
break 'logical_turn;
|
||||
}
|
||||
@ -2920,7 +2996,9 @@ pub async fn agent_send(
|
||||
}
|
||||
// Heartbeats carry no chat content (readiness/heartbeat lot 1) ⇒ no wire
|
||||
// chunk; skip them while still draining so the turn runs to its `Final`.
|
||||
let Some(chunk) = crate::chat::chunk_from_event(event) else {
|
||||
let Some(chunk) =
|
||||
crate::chat::chunk_from_event_at(event, u64::try_from(clock.now_millis()).ok())
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
if matches!(chunk, ReplyChunk::Final { .. } | ReplyChunk::Error { .. }) {
|
||||
@ -2946,7 +3024,10 @@ pub async fn agent_send(
|
||||
let _ = bridge.send_output_settled(
|
||||
&sid,
|
||||
&mut settler,
|
||||
ReplyChunk::Error { message },
|
||||
ReplyChunk::Error {
|
||||
message,
|
||||
at_ms: u64::try_from(clock.now_millis()).ok(),
|
||||
},
|
||||
);
|
||||
}
|
||||
backend::StructuredHumanTurnTransition::Cancelled => {
|
||||
@ -2971,6 +3052,7 @@ pub async fn agent_send(
|
||||
ReplyChunk::Error {
|
||||
message: "Le redémarrage n'a pas fourni de session de remplacement."
|
||||
.to_owned(),
|
||||
at_ms: u64::try_from(clock.now_millis()).ok(),
|
||||
},
|
||||
);
|
||||
break;
|
||||
@ -2991,6 +3073,7 @@ pub async fn agent_send(
|
||||
&mut settler,
|
||||
ReplyChunk::Error {
|
||||
message: error.to_string(),
|
||||
at_ms: u64::try_from(clock.now_millis()).ok(),
|
||||
},
|
||||
);
|
||||
break;
|
||||
@ -2998,7 +3081,10 @@ pub async fn agent_send(
|
||||
}
|
||||
}
|
||||
if !terminal_visible {
|
||||
let chunk = crate::chat::unfinished_turn_chunk();
|
||||
let chunk = crate::chat::with_chunk_timestamp(
|
||||
crate::chat::unfinished_turn_chunk(),
|
||||
u64::try_from(clock.now_millis()).ok(),
|
||||
);
|
||||
let _ = bridge.send_output_settled(&sid, &mut settler, chunk);
|
||||
}
|
||||
if let Some(guard) = &turn_guard {
|
||||
@ -3421,7 +3507,11 @@ pub async fn cancel_agent_chat(
|
||||
}
|
||||
state
|
||||
.stop_live_agent
|
||||
.execute(StopLiveAgentInput { project, agent_id })
|
||||
.execute(StopLiveAgentInput {
|
||||
project,
|
||||
agent_id,
|
||||
reason: Some("fermeture de la session chat".to_owned()),
|
||||
})
|
||||
.await
|
||||
.map(|_| ())
|
||||
.map_err(ErrorDto::from)
|
||||
|
||||
@ -263,6 +263,10 @@ pub fn run() {
|
||||
commands::list_projects,
|
||||
commands::read_project_context,
|
||||
commands::update_project_context,
|
||||
commands::read_user_settings,
|
||||
commands::update_user_settings,
|
||||
commands::read_project_settings,
|
||||
commands::update_project_settings,
|
||||
commands::get_project_permissions,
|
||||
commands::update_project_permissions,
|
||||
commands::update_agent_permissions,
|
||||
|
||||
@ -48,17 +48,22 @@ fn sid() -> SessionId {
|
||||
}
|
||||
|
||||
fn delta(s: &str) -> ReplyChunk {
|
||||
ReplyChunk::TextDelta { text: s.to_owned() }
|
||||
ReplyChunk::TextDelta {
|
||||
at_ms: None,
|
||||
text: s.to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
fn final_chunk(s: &str) -> ReplyChunk {
|
||||
ReplyChunk::Final {
|
||||
at_ms: None,
|
||||
content: s.to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
fn error_chunk(s: &str) -> ReplyChunk {
|
||||
ReplyChunk::Error {
|
||||
at_ms: None,
|
||||
message: s.to_owned(),
|
||||
}
|
||||
}
|
||||
@ -70,6 +75,7 @@ fn progress_chunk(
|
||||
) -> ReplyChunk {
|
||||
ReplyChunk::Progress {
|
||||
progress: ReplyProgressDto {
|
||||
occurred_at_ms: None,
|
||||
progress_id: None,
|
||||
source: ReplyProgressSourceDto::ProviderNative,
|
||||
kind,
|
||||
@ -91,6 +97,7 @@ fn progress_chunk_with_id(
|
||||
) -> ReplyChunk {
|
||||
ReplyChunk::Progress {
|
||||
progress: ReplyProgressDto {
|
||||
occurred_at_ms: None,
|
||||
progress_id: Some(progress_id.to_owned()),
|
||||
source: ReplyProgressSourceDto::ProviderNative,
|
||||
kind,
|
||||
@ -107,6 +114,7 @@ fn progress_chunk_with_id(
|
||||
fn chunk_bytes(chunk: &ReplyChunk) -> usize {
|
||||
match chunk {
|
||||
ReplyChunk::UserPrompt {
|
||||
at_ms: _,
|
||||
text,
|
||||
attachments,
|
||||
attachment_refs,
|
||||
@ -123,13 +131,13 @@ fn chunk_bytes(chunk: &ReplyChunk) -> usize {
|
||||
})
|
||||
.sum::<usize>()
|
||||
}
|
||||
ReplyChunk::TextDelta { text } => text.len(),
|
||||
ReplyChunk::ToolActivity { label } => label.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)
|
||||
}
|
||||
ReplyChunk::Final { content } => content.len(),
|
||||
ReplyChunk::Error { message } => message.len(),
|
||||
ReplyChunk::Final { content, .. } => content.len(),
|
||||
ReplyChunk::Error { message, .. } => message.len(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,11 +145,32 @@ fn chunk_bytes(chunk: &ReplyChunk) -> usize {
|
||||
// chunk_from_event — exhaustive mapping (zone 6)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn accepted_reply_events_keep_the_backend_timestamp() {
|
||||
let chunk = app_tauri_lib::chat::chunk_from_event_at(
|
||||
ReplyEvent::Final {
|
||||
content: "done".to_owned(),
|
||||
},
|
||||
Some(42_424),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
chunk,
|
||||
ReplyChunk::Final {
|
||||
at_ms: Some(42_424),
|
||||
content: "done".to_owned()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chunk_from_event_maps_text_delta() {
|
||||
assert_eq!(
|
||||
chunk_from_event(ReplyEvent::TextDelta { text: "hi".into() }),
|
||||
Some(ReplyChunk::TextDelta { text: "hi".into() })
|
||||
Some(ReplyChunk::TextDelta {
|
||||
at_ms: None,
|
||||
text: "hi".into()
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@ -202,6 +231,7 @@ fn chunk_from_event_maps_final() {
|
||||
content: "done".into()
|
||||
}),
|
||||
Some(ReplyChunk::Final {
|
||||
at_ms: None,
|
||||
content: "done".into()
|
||||
})
|
||||
);
|
||||
@ -236,7 +266,10 @@ fn pump_turn(bridge: &ChatBridge, session: &SessionId, gen: u64, events: Vec<Rep
|
||||
for event in events {
|
||||
// Mirror the real pump: heartbeats map to no chunk and are skipped.
|
||||
if let Some(chunk) = chunk_from_event(event) {
|
||||
if matches!(chunk, ReplyChunk::Final { .. } | ReplyChunk::Error { .. }) {
|
||||
if matches!(
|
||||
chunk,
|
||||
ReplyChunk::Final { at_ms: None, .. } | ReplyChunk::Error { at_ms: None, .. }
|
||||
) {
|
||||
terminal_visible = true;
|
||||
}
|
||||
let _ = bridge.send_output(session, chunk);
|
||||
@ -277,10 +310,13 @@ fn pump_delivers_deltas_then_exactly_one_final_in_order() {
|
||||
// Exactly one Final, and it is last (deterministic terminal chunk).
|
||||
let finals = got
|
||||
.iter()
|
||||
.filter(|c| matches!(c, ReplyChunk::Final { .. }))
|
||||
.filter(|c| matches!(c, ReplyChunk::Final { at_ms: None, .. }))
|
||||
.count();
|
||||
assert_eq!(finals, 1, "exactly one Final per turn");
|
||||
assert!(matches!(got.last(), Some(ReplyChunk::Final { .. })));
|
||||
assert!(matches!(
|
||||
got.last(),
|
||||
Some(ReplyChunk::Final { at_ms: None, .. })
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -490,6 +526,7 @@ fn scrollback_accumulates_every_routed_chunk_in_order() {
|
||||
.map(|chunk| match chunk {
|
||||
ReplyChunk::Progress { progress } => {
|
||||
ReplyChunk::ToolActivity {
|
||||
at_ms: None,
|
||||
label: progress.label,
|
||||
}
|
||||
}
|
||||
@ -499,6 +536,7 @@ fn scrollback_accumulates_every_routed_chunk_in_order() {
|
||||
vec![
|
||||
delta("x"),
|
||||
ReplyChunk::ToolActivity {
|
||||
at_ms: None,
|
||||
label: "runs".into()
|
||||
},
|
||||
final_chunk("x"),
|
||||
@ -756,15 +794,15 @@ fn scrollback_drops_oldest_whole_chunks_when_byte_cap_is_exceeded() {
|
||||
assert_eq!(scrollback.len(), 4);
|
||||
assert!(matches!(
|
||||
scrollback.first(),
|
||||
Some(ReplyChunk::TextDelta { text }) if text.starts_with("02:")
|
||||
Some(ReplyChunk::TextDelta { text, .. }) if text.starts_with("02:")
|
||||
));
|
||||
assert!(matches!(
|
||||
scrollback.last(),
|
||||
Some(ReplyChunk::TextDelta { text }) if text.starts_with("05:")
|
||||
Some(ReplyChunk::TextDelta { text, .. }) if text.starts_with("05:")
|
||||
));
|
||||
assert!(scrollback.iter().all(|chunk| matches!(
|
||||
chunk,
|
||||
ReplyChunk::TextDelta { text } if text.len() == chunk_size
|
||||
ReplyChunk::TextDelta { text, .. } if text.len() == chunk_size
|
||||
)));
|
||||
}
|
||||
|
||||
@ -781,6 +819,7 @@ fn truncated_scrollback_replays_valid_unmodified_chunks_in_order() {
|
||||
bridge.send_output(
|
||||
&session,
|
||||
ReplyChunk::ToolActivity {
|
||||
at_ms: None,
|
||||
label: "tool".into(),
|
||||
},
|
||||
);
|
||||
@ -793,6 +832,7 @@ fn truncated_scrollback_replays_valid_unmodified_chunks_in_order() {
|
||||
&scrollback[(MAX_CHAT_SCROLLBACK_CHUNKS - 2)..],
|
||||
&[
|
||||
ReplyChunk::ToolActivity {
|
||||
at_ms: None,
|
||||
label: "tool".into()
|
||||
},
|
||||
final_chunk("done")
|
||||
|
||||
@ -444,7 +444,7 @@ fn project_work_state_dto_serialises_conversations_camelcase() {
|
||||
source: TicketWorkSource::Agent {
|
||||
agent_id: requester,
|
||||
},
|
||||
at_ms: 1_700,
|
||||
at_ms: Some(1_700),
|
||||
text_preview: "Analyse le module".to_owned(),
|
||||
text_len: 17,
|
||||
}],
|
||||
@ -715,6 +715,7 @@ fn stop_live_agent_request_deserialises_camelcase() {
|
||||
#[test]
|
||||
fn stop_live_agent_response_serialises_camelcase_with_kind() {
|
||||
use app_tauri_lib::dto::StopLiveAgentResponseDto;
|
||||
use application::terminal::StoppedAgentRuntime;
|
||||
use application::{LiveSessionKind, StopLiveAgentOutput};
|
||||
|
||||
let agent = AgentId::from_uuid(Uuid::from_u128(11));
|
||||
@ -722,17 +723,21 @@ fn stop_live_agent_response_serialises_camelcase_with_kind() {
|
||||
let session = SessionId::from_uuid(Uuid::from_u128(13));
|
||||
let dto = StopLiveAgentResponseDto::from(StopLiveAgentOutput {
|
||||
agent_id: agent,
|
||||
node_id: node,
|
||||
session_id: session,
|
||||
kind: LiveSessionKind::Structured,
|
||||
runtime_state: LiveRuntimeState::Stopped,
|
||||
stopped: vec![StoppedAgentRuntime {
|
||||
agent_id: agent,
|
||||
node_id: node,
|
||||
session_id: session,
|
||||
kind: LiveSessionKind::Structured,
|
||||
state: LiveRuntimeState::Stopped,
|
||||
}],
|
||||
already_stopped: false,
|
||||
});
|
||||
|
||||
let v = serde_json::to_value(&dto).unwrap();
|
||||
assert_eq!(v["agentId"], agent.to_string());
|
||||
assert_eq!(v["sessionId"], session.to_string());
|
||||
assert_eq!(v["kind"], "structured");
|
||||
assert_eq!(v["runtimeState"], "stopped");
|
||||
assert!(v.get("nodeId").is_none());
|
||||
assert_eq!(v["stopped"][0]["sessionId"], session.to_string());
|
||||
assert_eq!(v["stopped"][0]["kind"], "structured");
|
||||
assert_eq!(v["stopped"][0]["runtimeState"], "stopped");
|
||||
assert_eq!(v["alreadyStopped"], false);
|
||||
assert!(v.get("session_id").is_none());
|
||||
}
|
||||
|
||||
@ -26,17 +26,22 @@ use uuid::Uuid;
|
||||
#[test]
|
||||
fn reply_chunk_user_prompt_serialises_exact_camel_case() {
|
||||
let v = serde_json::to_value(ReplyChunk::UserPrompt {
|
||||
at_ms: None,
|
||||
text: "run tests".into(),
|
||||
attachments: Vec::new(),
|
||||
attachment_refs: Vec::new(),
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(v, json!({ "kind": "userPrompt", "text": "run tests" }));
|
||||
assert_eq!(
|
||||
v,
|
||||
json!({ "kind": "userPrompt", "text": "run tests", "atMs": null })
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reply_chunk_user_prompt_serialises_attachment_labels() {
|
||||
let v = serde_json::to_value(ReplyChunk::UserPrompt {
|
||||
at_ms: None,
|
||||
text: "describe this".into(),
|
||||
attachments: vec!["clipboard.png".into()],
|
||||
attachment_refs: vec![ChatPromptAttachmentDto {
|
||||
@ -52,6 +57,7 @@ fn reply_chunk_user_prompt_serialises_attachment_labels() {
|
||||
v,
|
||||
json!({
|
||||
"kind": "userPrompt",
|
||||
"atMs": null,
|
||||
"text": "describe this",
|
||||
"attachments": ["clipboard.png"],
|
||||
"attachmentRefs": [{
|
||||
@ -68,25 +74,50 @@ fn reply_chunk_user_prompt_serialises_attachment_labels() {
|
||||
#[test]
|
||||
fn reply_chunk_text_delta_serialises_exact_camel_case() {
|
||||
let v = serde_json::to_value(ReplyChunk::TextDelta {
|
||||
at_ms: None,
|
||||
text: "hello".into(),
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(v, json!({ "kind": "textDelta", "text": "hello" }));
|
||||
assert_eq!(
|
||||
v,
|
||||
json!({ "kind": "textDelta", "text": "hello", "atMs": null })
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_reply_chunk_without_timestamp_deserialises_as_none() {
|
||||
let chunk: ReplyChunk = serde_json::from_value(json!({
|
||||
"kind": "final",
|
||||
"content": "legacy"
|
||||
}))
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
chunk,
|
||||
ReplyChunk::Final {
|
||||
at_ms: None,
|
||||
content: "legacy".into()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reply_chunk_tool_activity_serialises_exact_camel_case() {
|
||||
let v = serde_json::to_value(ReplyChunk::ToolActivity {
|
||||
at_ms: None,
|
||||
label: "reads file".into(),
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(v, json!({ "kind": "toolActivity", "label": "reads file" }));
|
||||
assert_eq!(
|
||||
v,
|
||||
json!({ "kind": "toolActivity", "label": "reads file", "atMs": null })
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reply_chunk_progress_serialises_exact_camel_case() {
|
||||
let v = serde_json::to_value(ReplyChunk::Progress {
|
||||
progress: ReplyProgressDto {
|
||||
occurred_at_ms: None,
|
||||
progress_id: Some("codex:item:tool0".into()),
|
||||
source: ReplyProgressSourceDto::IdeaLocal,
|
||||
kind: ReplyProgressKindDto::Mcp,
|
||||
@ -105,6 +136,7 @@ fn reply_chunk_progress_serialises_exact_camel_case() {
|
||||
"kind": "progress",
|
||||
"progress": {
|
||||
"source": "ideaLocal",
|
||||
"occurredAtMs": null,
|
||||
"kind": "mcp",
|
||||
"progressId": "codex:item:tool0",
|
||||
"stage": "started",
|
||||
@ -119,21 +151,26 @@ fn reply_chunk_progress_serialises_exact_camel_case() {
|
||||
#[test]
|
||||
fn reply_chunk_final_serialises_exact_camel_case() {
|
||||
let v = serde_json::to_value(ReplyChunk::Final {
|
||||
at_ms: None,
|
||||
content: "done".into(),
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(v, json!({ "kind": "final", "content": "done" }));
|
||||
assert_eq!(
|
||||
v,
|
||||
json!({ "kind": "final", "content": "done", "atMs": null })
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reply_chunk_error_serialises_exact_camel_case() {
|
||||
let v = serde_json::to_value(ReplyChunk::Error {
|
||||
at_ms: None,
|
||||
message: "Réponse vide du modèle.".into(),
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
v,
|
||||
json!({ "kind": "error", "message": "Réponse vide du modèle." })
|
||||
json!({ "kind": "error", "message": "Réponse vide du modèle.", "atMs": null })
|
||||
);
|
||||
}
|
||||
|
||||
@ -141,6 +178,7 @@ fn reply_chunk_error_serialises_exact_camel_case() {
|
||||
fn reply_chunk_round_trips_through_json_for_every_variant() {
|
||||
for chunk in [
|
||||
ReplyChunk::UserPrompt {
|
||||
at_ms: None,
|
||||
text: "u".into(),
|
||||
attachments: vec!["clipboard.png".into()],
|
||||
attachment_refs: vec![ChatPromptAttachmentDto {
|
||||
@ -152,12 +190,17 @@ fn reply_chunk_round_trips_through_json_for_every_variant() {
|
||||
.into(),
|
||||
}],
|
||||
},
|
||||
ReplyChunk::TextDelta { text: "x".into() },
|
||||
ReplyChunk::TextDelta {
|
||||
at_ms: None,
|
||||
text: "x".into(),
|
||||
},
|
||||
ReplyChunk::ToolActivity {
|
||||
at_ms: None,
|
||||
label: "runs".into(),
|
||||
},
|
||||
ReplyChunk::Progress {
|
||||
progress: ReplyProgressDto {
|
||||
occurred_at_ms: None,
|
||||
progress_id: None,
|
||||
source: ReplyProgressSourceDto::ProviderNative,
|
||||
kind: ReplyProgressKindDto::Turn,
|
||||
@ -170,9 +213,11 @@ fn reply_chunk_round_trips_through_json_for_every_variant() {
|
||||
},
|
||||
},
|
||||
ReplyChunk::Final {
|
||||
at_ms: None,
|
||||
content: "y".into(),
|
||||
},
|
||||
ReplyChunk::Error {
|
||||
at_ms: None,
|
||||
message: "empty".into(),
|
||||
},
|
||||
] {
|
||||
@ -190,6 +235,7 @@ fn reply_chunk_deserialises_from_camel_case_wire_payload() {
|
||||
assert_eq!(
|
||||
back,
|
||||
ReplyChunk::UserPrompt {
|
||||
at_ms: None,
|
||||
text: "hi".into(),
|
||||
attachments: Vec::new(),
|
||||
attachment_refs: Vec::new()
|
||||
@ -366,12 +412,17 @@ fn reattach_chat_dto_serialises_camel_case_with_typed_scrollback() {
|
||||
conversation_id: Some("conv-1".into()),
|
||||
scrollback: vec![
|
||||
ReplyChunk::UserPrompt {
|
||||
at_ms: None,
|
||||
text: "Hi".into(),
|
||||
attachments: Vec::new(),
|
||||
attachment_refs: Vec::new(),
|
||||
},
|
||||
ReplyChunk::TextDelta { text: "Hi".into() },
|
||||
ReplyChunk::TextDelta {
|
||||
at_ms: None,
|
||||
text: "Hi".into(),
|
||||
},
|
||||
ReplyChunk::Final {
|
||||
at_ms: None,
|
||||
content: "Hi".into(),
|
||||
},
|
||||
],
|
||||
@ -383,9 +434,9 @@ fn reattach_chat_dto_serialises_camel_case_with_typed_scrollback() {
|
||||
"sessionId": "sess-1",
|
||||
"conversationId": "conv-1",
|
||||
"scrollback": [
|
||||
{ "kind": "userPrompt", "text": "Hi" },
|
||||
{ "kind": "textDelta", "text": "Hi" },
|
||||
{ "kind": "final", "content": "Hi" },
|
||||
{ "kind": "userPrompt", "text": "Hi", "atMs": null },
|
||||
{ "kind": "textDelta", "text": "Hi", "atMs": null },
|
||||
{ "kind": "final", "content": "Hi", "atMs": null },
|
||||
],
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user