clawdesk-discovery
Service and model discovery for dynamically finding available providers, models, and peer ClawDesk instances. Supports local discovery (scanning configuration) and network discovery (multicast, registry lookup).
Dependencies
Internal: clawdesk-types
External: reqwest, tokio, serde, tracing, thiserror
Modules
| Module | Description |
|---|---|
service | Service discovery — find peer ClawDesk instances |
model | Model discovery — enumerate available models across providers |
local | Local discovery from configuration files |
network | Network-based discovery (mDNS, registry) |
Key Types
/// Discovered service instance
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServiceInstance {
pub id: String,
pub name: String,
pub endpoint: String,
pub version: String,
pub capabilities: Vec<String>,
pub discovered_at: chrono::DateTime<chrono::Utc>,
}
/// Discovered model
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiscoveredModel {
pub id: String,
pub provider: String,
pub capabilities: Vec<String>,
pub context_window: usize,
pub available: bool,
}
/// Service discovery engine
pub struct DiscoveryEngine {
local: LocalDiscovery,
network: Option<NetworkDiscovery>,
}
impl DiscoveryEngine {
/// Discover all available services
pub async fn discover_services(&self) -> Result<Vec<ServiceInstance>, DiscoveryError> {
let mut services = self.local.discover().await?;
if let Some(network) = &self.network {
services.extend(network.discover().await?);
}
Ok(services)
}
/// Discover all available models
pub async fn discover_models(&self) -> Result<Vec<DiscoveredModel>, DiscoveryError> {
// Enumerate models from all known providers
}
/// Refresh the discovery cache
pub async fn refresh(&self) -> Result<(), DiscoveryError> { /* ... */ }
}
/// Local discovery from config
pub struct LocalDiscovery {
config: AppConfig,
}
/// Network discovery via mDNS or registry
pub struct NetworkDiscovery {
registry_url: Option<String>,
mdns_enabled: bool,
}
Example Usage
use clawdesk_discovery::{DiscoveryEngine, LocalDiscovery};
let engine = DiscoveryEngine::new(
LocalDiscovery::from_config(&config),
None, // No network discovery
);
// Discover available models
let models = engine.discover_models().await?;
for model in &models {
println!(
"{} ({}) - ctx: {} - available: {}",
model.id, model.provider, model.context_window, model.available
);
}
// Discover peer instances
let services = engine.discover_services().await?;
for svc in &services {
println!("{} @ {}", svc.name, svc.endpoint);
}
Configuration
[discovery]
enabled = true
refresh_interval_secs = 300
[discovery.network]
mdns_enabled = false
registry_url = "https://registry.clawdesk.dev"
tip
Model discovery runs automatically on gateway startup and caches results. Use the refresh interval or the /api/v1/models endpoint to get updated availability.