Skip to content

Commit 3b336e6

Browse files
Merge pull request #35 from gitcoder89431/29-provider-configuration-foundation
🏗️ Provider Configuration Foundation
2 parents 02e5e2f + d59f7b1 commit 3b336e6

File tree

2 files changed

+490
-14
lines changed

2 files changed

+490
-14
lines changed

examples/issue_29_demo.rs

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
//! Issue #29 Demo: Provider Configuration Foundation
2+
//!
3+
//! Demonstrates the new provider configuration system for LOCAL and OPENROUTER providers.
4+
5+
use agentic::settings::{
6+
ProviderConfig, ProviderField, Settings, SettingsAction, ValidationStatus,
7+
};
8+
9+
fn main() {
10+
println!("🏗️ Issue #29 Demo: Provider Configuration Foundation");
11+
println!("==================================================");
12+
13+
println!("\n✅ Provider Configuration Foundation Features:");
14+
15+
// 1. Create settings with provider configurations
16+
println!("1. Creating settings with default provider configurations...");
17+
let mut settings = Settings::new();
18+
19+
println!(
20+
" Local provider configured: {}",
21+
settings.local_provider.is_configured()
22+
);
23+
println!(
24+
" OpenRouter provider configured: {}",
25+
settings.openrouter_provider.is_configured()
26+
);
27+
println!(
28+
" Selected provider: {}",
29+
settings.get_provider_name(settings.selected_provider_index)
30+
);
31+
32+
// 2. Test provider type creation
33+
println!("\n2. Testing provider configuration types...");
34+
let local_config = ProviderConfig::new_local();
35+
let openrouter_config = ProviderConfig::new_openrouter();
36+
37+
println!(" Local default endpoint: {:?}", local_config.endpoint_url);
38+
println!(" Local API key: {:?}", local_config.api_key);
39+
println!(
40+
" OpenRouter endpoint: {:?}",
41+
openrouter_config.endpoint_url
42+
);
43+
println!(" OpenRouter API key: {:?}", openrouter_config.api_key);
44+
45+
// 3. Test validation status system
46+
println!("\n3. Testing validation status system...");
47+
for status in [
48+
ValidationStatus::Unchecked,
49+
ValidationStatus::Checking,
50+
ValidationStatus::Valid,
51+
ValidationStatus::Invalid,
52+
] {
53+
println!(
54+
" Status: {:?} → Icon: {}",
55+
status,
56+
Settings::get_validation_status_icon(&status)
57+
);
58+
}
59+
60+
// 4. Test field updates
61+
println!("\n4. Testing field update actions...");
62+
settings.handle_action(SettingsAction::UpdateField(
63+
ProviderField::LocalEndpoint,
64+
"http://localhost:8080".to_string(),
65+
));
66+
println!(
67+
" Updated local endpoint: {:?}",
68+
settings.local_provider.endpoint_url
69+
);
70+
71+
settings.handle_action(SettingsAction::UpdateField(
72+
ProviderField::OpenRouterApiKey,
73+
"sk-or-demo123456789012345".to_string(),
74+
));
75+
println!(
76+
" Updated OpenRouter API key: {:?}",
77+
settings.openrouter_provider.api_key
78+
);
79+
println!(
80+
" Masked API key display: {:?}",
81+
settings.openrouter_provider.get_masked_api_key()
82+
);
83+
84+
// 5. Test provider navigation
85+
println!("\n5. Testing provider navigation...");
86+
println!(
87+
" Current provider index: {}",
88+
settings.selected_provider_index
89+
);
90+
settings.handle_action(SettingsAction::NavigateProviderNext);
91+
println!(
92+
" After next: {} ({})",
93+
settings.selected_provider_index,
94+
settings.get_provider_name(settings.selected_provider_index)
95+
);
96+
settings.handle_action(SettingsAction::NavigateProviderNext);
97+
println!(
98+
" After next (wrap): {} ({})",
99+
settings.selected_provider_index,
100+
settings.get_provider_name(settings.selected_provider_index)
101+
);
102+
103+
// 6. Test validation
104+
println!("\n6. Testing configuration validation...");
105+
match settings.validate() {
106+
Ok(()) => println!(" ✅ Configuration is valid"),
107+
Err(e) => println!(" ❌ Configuration error: {}", e),
108+
}
109+
110+
// Test with invalid configuration
111+
let mut invalid_settings = Settings::new();
112+
invalid_settings.local_provider.endpoint_url = None;
113+
invalid_settings.openrouter_provider.api_key = None;
114+
match invalid_settings.validate() {
115+
Ok(()) => println!(" ❌ Should have failed validation"),
116+
Err(e) => println!(" ✅ Correctly caught error: {}", e),
117+
}
118+
119+
// 7. Test security features
120+
println!("\n7. Testing security features...");
121+
let mut secure_config = ProviderConfig::new_openrouter();
122+
secure_config.set_api_key("sk-or-very-long-secret-key-12345".to_string());
123+
println!(" Full key: {:?}", secure_config.api_key);
124+
println!(
125+
" Masked display: {:?}",
126+
secure_config.get_masked_api_key()
127+
);
128+
129+
println!("\n🎯 Success Criteria Verification:");
130+
println!("✅ Provider configuration data structures defined");
131+
println!("✅ Validation status management system ready");
132+
println!("✅ Settings actions support provider operations");
133+
println!("✅ Clean separation between LOCAL and OPENROUTER configs");
134+
println!("✅ Extensible architecture for future providers");
135+
println!("✅ Secure handling of sensitive data (API keys)");
136+
137+
println!("\n🎨 Provider Configuration Workflow:");
138+
println!("• Settings contains both Local and OpenRouter providers");
139+
println!("• Each provider tracks validation status independently");
140+
println!("• API keys are masked for security in UI display");
141+
println!("• Configuration validation ensures at least one provider");
142+
println!("• Field focus management for input handling");
143+
println!("• Non-blocking async validation architecture ready");
144+
145+
println!("\n🚀 Issue #29 Provider Configuration Foundation: COMPLETE!");
146+
println!(" The foundation is ready for backend communication settings");
147+
println!(" and extensible for future provider types!");
148+
}

0 commit comments

Comments
 (0)