feat: add structured session picker
This commit is contained in:
@@ -218,6 +218,15 @@ pub enum QueueAcpPrompt {
|
||||
Failed(String),
|
||||
}
|
||||
|
||||
/// Result of changing a live structured session option.
|
||||
#[derive(Debug)]
|
||||
pub enum SetAcpConfig {
|
||||
Updated,
|
||||
InvalidValue,
|
||||
Unavailable,
|
||||
Failed(String),
|
||||
}
|
||||
|
||||
impl SessionError {
|
||||
pub fn to_error_info(&self) -> ErrorInfo {
|
||||
let code = match self {
|
||||
@@ -850,6 +859,48 @@ impl SessionManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// Change one option on a live ACP session and wait for the agent to
|
||||
/// acknowledge it. The adapter's returned option set is projected by the
|
||||
/// normal event pump before this request completes.
|
||||
pub async fn set_acp_config(
|
||||
&self,
|
||||
id: Uuid,
|
||||
config_id: String,
|
||||
value: serde_json::Value,
|
||||
) -> Result<SetAcpConfig, SessionError> {
|
||||
let (acp, stream) = {
|
||||
let sessions = self.inner.sessions.lock().await;
|
||||
let record = sessions.get(&id).ok_or(SessionError::NotFound(id))?;
|
||||
if !record.is_live_structured() {
|
||||
return Ok(SetAcpConfig::Unavailable);
|
||||
}
|
||||
(record.acp.clone(), record.acp_events.clone())
|
||||
};
|
||||
let (Some(acp), Some(stream)) = (acp, stream) else {
|
||||
return Ok(SetAcpConfig::Unavailable);
|
||||
};
|
||||
let value = match value {
|
||||
serde_json::Value::String(value) => {
|
||||
maestro_acp::schema::SessionConfigOptionValue::value_id(value)
|
||||
}
|
||||
serde_json::Value::Bool(value) => {
|
||||
maestro_acp::schema::SessionConfigOptionValue::boolean(value)
|
||||
}
|
||||
_ => return Ok(SetAcpConfig::InvalidValue),
|
||||
};
|
||||
let operation = stream.lock().await.operation.clone();
|
||||
let _operation = operation.lock().await;
|
||||
let done = match acp.set_config(config_id, value) {
|
||||
Ok(done) => done,
|
||||
Err(message) => return Ok(SetAcpConfig::Failed(message)),
|
||||
};
|
||||
match done.await {
|
||||
Ok(Ok(())) => Ok(SetAcpConfig::Updated),
|
||||
Ok(Err(message)) => Ok(SetAcpConfig::Failed(message)),
|
||||
Err(_) => Ok(SetAcpConfig::Failed("ACP connection is closed".into())),
|
||||
}
|
||||
}
|
||||
|
||||
/// Cancel an ACP turn and immediately clear its client-facing lifecycle.
|
||||
pub async fn cancel_acp_turn(&self, id: Uuid) -> Result<bool, SessionError> {
|
||||
let (acp, stream) = {
|
||||
|
||||
Reference in New Issue
Block a user