- expose command-monitor conversations and preserve visible agent transcripts - add bounded polling and a dedicated shell interrupt tool - improve direct-provider images, skills, tool history, and usage handling - package and brand Galaxy Control across releases, installers, persistence, and docs
59 lines
1.8 KiB
Rust
59 lines
1.8 KiB
Rust
//! Instance selection helpers for local-control clients.
|
|
use crate::discovery::{InstanceId, InstanceRecord};
|
|
use crate::protocol::{ControlError, ErrorCode};
|
|
|
|
/// CLI-level selector for choosing one discovered Galaxy instance.
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub enum InstanceSelector {
|
|
Active,
|
|
Id(InstanceId),
|
|
Pid(u32),
|
|
}
|
|
|
|
pub fn select_instance(
|
|
records: &[InstanceRecord],
|
|
selector: &InstanceSelector,
|
|
) -> Result<InstanceRecord, ControlError> {
|
|
match selector {
|
|
InstanceSelector::Active => select_active(records),
|
|
InstanceSelector::Id(instance_id) => records
|
|
.iter()
|
|
.find(|record| &record.instance_id == instance_id)
|
|
.cloned()
|
|
.ok_or_else(|| {
|
|
ControlError::new(
|
|
ErrorCode::NoInstance,
|
|
format!("no Galaxy instance with id {}", instance_id.0),
|
|
)
|
|
}),
|
|
InstanceSelector::Pid(pid) => records
|
|
.iter()
|
|
.find(|record| record.pid == *pid)
|
|
.cloned()
|
|
.ok_or_else(|| {
|
|
ControlError::new(
|
|
ErrorCode::NoInstance,
|
|
format!("no Galaxy instance with pid {pid}"),
|
|
)
|
|
}),
|
|
}
|
|
}
|
|
|
|
fn select_active(records: &[InstanceRecord]) -> Result<InstanceRecord, ControlError> {
|
|
match records {
|
|
[] => Err(ControlError::new(
|
|
ErrorCode::NoInstance,
|
|
"no local Galaxy instances with Galaxy Control enabled were discovered",
|
|
)),
|
|
[record] => Ok(record.clone()),
|
|
_ => Err(ControlError::new(
|
|
ErrorCode::AmbiguousInstance,
|
|
"multiple local Galaxy instances with Galaxy Control enabled were discovered; pass --instance",
|
|
)),
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "selection_tests.rs"]
|
|
mod tests;
|