use std::path::Path;
use crate::AppModel;
use crate::boundary::Query;
use crate::boundary::reply::Reply;
use crate::config_edit::branch::GoverningConfig;
use crate::files_view::{FilesView, Preview};
use crate::inboxview::InboxEntry;
use crate::rail::Rail;
use crate::shell::wire::{Landed, ask};
use crate::steps_view::{StepDetail, StepsView};
use crate::transcript::Transcript;
fn at(model: &AppModel, ws: &Path, agent: &str) -> (String, String) {
(model.snap.ws_name(ws), agent.to_owned())
}
pub(in crate::shell) fn transcript(
model: &mut AppModel,
ws: &Path,
agent: &str,
) -> Landed<Transcript> {
let (workspace, agent) = at(model, ws, agent);
ask(
model,
Query::Transcript { workspace, agent },
|reply| match reply {
Reply::Transcript(tx) => Some(tx),
_ => None,
},
)
}
pub(in crate::shell) fn steps(model: &mut AppModel, ws: &Path, agent: &str) -> Landed<StepsView> {
let (workspace, agent) = at(model, ws, agent);
ask(
model,
Query::Steps { workspace, agent },
|reply| match reply {
Reply::Steps(view) => Some(view),
_ => None,
},
)
}
pub(super) fn detail(
model: &mut AppModel,
ws: &Path,
agent: &str,
seq: &str,
) -> Landed<StepDetail> {
let (workspace, agent) = at(model, ws, agent);
let seq = seq.to_owned();
ask(
model,
Query::Step {
workspace,
agent,
seq,
},
|reply| match reply {
Reply::Step(detail) => Some(detail),
_ => None,
},
)
}
pub(super) fn files(
model: &mut AppModel,
ws: &Path,
agent: &str,
path: Option<String>,
commit: Option<String>,
) -> Landed<(FilesView, Option<Preview>)> {
let (workspace, agent) = at(model, ws, agent);
ask(
model,
Query::Files {
workspace,
agent,
path,
at: commit,
},
|reply| match reply {
Reply::Files { view, preview } => Some((view, preview)),
_ => None,
},
)
}
pub(super) fn rail(model: &mut AppModel, ws: &Path, agent: &str) -> Landed<Rail> {
let (workspace, agent) = at(model, ws, agent);
ask(
model,
Query::Rail { workspace, agent },
|reply| match reply {
Reply::Rail(rail) => Some(rail),
_ => None,
},
)
}
pub(in crate::shell) fn inbox(
model: &mut AppModel,
ws: &Path,
agent: &str,
) -> Landed<Vec<InboxEntry>> {
let (workspace, agent) = at(model, ws, agent);
ask(
model,
Query::Inbox { workspace, agent },
|reply| match reply {
Reply::Inbox(entries) => Some(entries),
_ => None,
},
)
}
pub(super) fn governing(
model: &mut AppModel,
ws: &Path,
agent: &str,
commit: Option<String>,
) -> Landed<GoverningConfig> {
let (workspace, agent) = at(model, ws, agent);
ask(
model,
Query::Governing {
workspace,
agent,
at: commit,
},
|reply| match reply {
Reply::Governing(gov) => Some(gov),
_ => None,
},
)
}