fix(daemon): persist structured user prompts
This commit is contained in:
@@ -18,8 +18,8 @@ use chrono::Utc;
|
||||
use maestro_acp::{AcpSession, PermissionRequest, SpawnConfig};
|
||||
use maestro_protocol::{
|
||||
ActivityState, CatalogEvent, CreateSessionRequest, ErrorInfo, NameSource, Session,
|
||||
SessionStatus, SessionView, StructuredReplayEvent, TranscriptDelta, WorktreeSpec, NAME_KEY,
|
||||
NAME_SOURCE_KEY,
|
||||
SessionStatus, SessionView, StructuredReplayEvent, TranscriptDelta, TranscriptRow,
|
||||
TranscriptRowKind, WorktreeSpec, NAME_KEY, NAME_SOURCE_KEY,
|
||||
};
|
||||
use tokio::sync::{broadcast, oneshot, watch, Mutex, Notify};
|
||||
use uuid::Uuid;
|
||||
@@ -719,6 +719,27 @@ impl SessionManager {
|
||||
if stream.projection.turn_active() {
|
||||
return Ok(QueueAcpPrompt::InFlight);
|
||||
}
|
||||
let row = TranscriptRow {
|
||||
id: format!("user:{}", Uuid::new_v4()),
|
||||
kind: TranscriptRowKind::User,
|
||||
data: serde_json::json!({
|
||||
"content": {"type": "text", "text": text},
|
||||
}),
|
||||
};
|
||||
let event = PersistedEvent::User { row: row.clone() };
|
||||
let seq = match stream.log.append(&event) {
|
||||
Ok(seq) => seq,
|
||||
Err(error) => {
|
||||
if matches!(error, AppendError::Fatal { .. }) {
|
||||
stream.dispatch.failed = true;
|
||||
}
|
||||
return Ok(QueueAcpPrompt::Failed(error.to_string()));
|
||||
}
|
||||
};
|
||||
let logged = LoggedEvent { seq, event };
|
||||
let projected = stream.projection.restore_row(row);
|
||||
let _ = stream.live.send(logged);
|
||||
let _ = stream.projected_live.send(projected);
|
||||
let (turn, update) = stream.projection.begin_turn();
|
||||
let _ = stream.projected_live.send(update);
|
||||
match acp.prompt(text.clone(), turn) {
|
||||
@@ -2118,7 +2139,9 @@ fn start_acp_event_pump(
|
||||
fn apply_persisted_event(projection: &mut Projection, event: &LoggedEvent) -> ProjectionUpdate {
|
||||
match &event.event {
|
||||
PersistedEvent::Notification(notification) => projection.apply(event.seq, notification),
|
||||
PersistedEvent::Approval { row } => projection.restore_approval(row.clone()),
|
||||
PersistedEvent::User { row } | PersistedEvent::Approval { row } => {
|
||||
projection.restore_row(row.clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user