[feat](trx-server): auto-generate rig IDs from model name if not specified
Allow rigs to have empty IDs in config; auto-generate from backend model name with numeric suffix (e.g., 'ft817_0', 'ft817_1', 'soapysdr_0'). This makes config more concise when using multiple instances of the same model without explicit ID assignment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -503,11 +503,11 @@ impl ServerConfig {
|
|||||||
let mut seen_ids: std::collections::HashSet<String> = std::collections::HashSet::new();
|
let mut seen_ids: std::collections::HashSet<String> = std::collections::HashSet::new();
|
||||||
let mut seen_ports: std::collections::HashSet<u16> = std::collections::HashSet::new();
|
let mut seen_ports: std::collections::HashSet<u16> = std::collections::HashSet::new();
|
||||||
for rig in &self.rigs {
|
for rig in &self.rigs {
|
||||||
if rig.id.trim().is_empty() {
|
// Check for explicit duplicate IDs (empty IDs are auto-generated later).
|
||||||
return Err("[[rigs]] entry has an empty id".to_string());
|
if !rig.id.trim().is_empty() {
|
||||||
}
|
if !seen_ids.insert(rig.id.clone()) {
|
||||||
if !seen_ids.insert(rig.id.clone()) {
|
return Err(format!("[[rigs]] duplicate rig id: \"{}\"", rig.id));
|
||||||
return Err(format!("[[rigs]] duplicate rig id: \"{}\"", rig.id));
|
}
|
||||||
}
|
}
|
||||||
if rig.audio.enabled {
|
if rig.audio.enabled {
|
||||||
if !seen_ports.insert(rig.audio.port) {
|
if !seen_ports.insert(rig.audio.port) {
|
||||||
@@ -626,7 +626,31 @@ impl ServerConfig {
|
|||||||
/// into a single `RigInstanceConfig` with `id = "default"`.
|
/// into a single `RigInstanceConfig` with `id = "default"`.
|
||||||
pub fn resolved_rigs(&self) -> Vec<RigInstanceConfig> {
|
pub fn resolved_rigs(&self) -> Vec<RigInstanceConfig> {
|
||||||
if !self.rigs.is_empty() {
|
if !self.rigs.is_empty() {
|
||||||
return self.rigs.clone();
|
// Auto-generate IDs for rigs that don't have explicit ones.
|
||||||
|
return self
|
||||||
|
.rigs
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(idx, rig)| {
|
||||||
|
let id = if rig.id.trim().is_empty() {
|
||||||
|
// Generate ID from model name with counter.
|
||||||
|
let model = rig
|
||||||
|
.rig
|
||||||
|
.model
|
||||||
|
.as_deref()
|
||||||
|
.unwrap_or("unknown")
|
||||||
|
.to_lowercase();
|
||||||
|
format!("{}_{}", model, idx)
|
||||||
|
} else {
|
||||||
|
rig.id.clone()
|
||||||
|
};
|
||||||
|
|
||||||
|
RigInstanceConfig {
|
||||||
|
id,
|
||||||
|
..rig.clone()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
}
|
}
|
||||||
vec![RigInstanceConfig {
|
vec![RigInstanceConfig {
|
||||||
id: "default".to_string(),
|
id: "default".to_string(),
|
||||||
|
|||||||
Reference in New Issue
Block a user