weft_core/layers/
key_selector.rs1use crate::config::ApiKeyConfig;
2use anyhow::Result;
3use async_trait::async_trait;
4
5#[derive(Debug, Clone)]
7pub struct ApiKeyState {
8 pub index: usize,
9 pub value: String,
10 pub label: Option<String>,
11 pub enabled: bool,
12 pub failed: bool,
13 pub usage_count: u64,
14}
15
16impl From<(usize, &ApiKeyConfig)> for ApiKeyState {
17 fn from((index, cfg): (usize, &ApiKeyConfig)) -> Self {
18 Self {
19 index,
20 value: cfg.value.clone(),
21 label: cfg.label.clone(),
22 enabled: cfg.enabled,
23 failed: false,
24 usage_count: 0,
25 }
26 }
27}
28
29#[async_trait]
30pub trait KeySelectorLayer: Send + Sync {
31 async fn select(&self, provider: &str, keys: &[ApiKeyState]) -> Result<usize>; fn mark_failed(&self, provider: &str, index: usize);
36
37 fn mark_success(&self, provider: &str, index: usize);
39}