Generate the ClawShell TOML configuration content with the given key mapping.
(config: &OnboardConfig)
| 11 | |
| 12 | /// Generate the ClawShell TOML configuration content with the given key mapping. |
| 13 | pub fn generate_clawshell_config(config: &OnboardConfig) -> String { |
| 14 | let key_section = match &config.auth_method { |
| 15 | OnboardAuthMethod::OAuth { provider_id } => { |
| 16 | format!( |
| 17 | r#"[[keys]] |
| 18 | virtual_key = {virtual_key} |
| 19 | provider = {provider} |
| 20 | auth = "oauth" |
| 21 | oauth_provider = {oauth_provider} |
| 22 | "#, |
| 23 | virtual_key = toml_string(&config.virtual_api_key), |
| 24 | provider = toml_string(&config.provider), |
| 25 | oauth_provider = toml_string(provider_id), |
| 26 | ) |
| 27 | } |
| 28 | OnboardAuthMethod::StaticKey => { |
| 29 | format!( |
| 30 | r#"[[keys]] |
| 31 | virtual_key = {virtual_key} |
| 32 | real_key = {real_key} |
| 33 | provider = {provider} |
| 34 | "#, |
| 35 | virtual_key = toml_string(&config.virtual_api_key), |
| 36 | real_key = toml_string(&config.real_api_key), |
| 37 | provider = toml_string(&config.provider), |
| 38 | ) |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | let oauth_providers_section = match &config.auth_method { |
| 43 | OnboardAuthMethod::OAuth { provider_id } => { |
| 44 | format!( |
| 45 | r#" |
| 46 | [[oauth_providers]] |
| 47 | provider = {provider_id} |
| 48 | "#, |
| 49 | provider_id = toml_string(provider_id), |
| 50 | ) |
| 51 | } |
| 52 | OnboardAuthMethod::StaticKey => String::new(), |
| 53 | }; |
| 54 | |
| 55 | let mut output = format!( |
| 56 | r#"# ClawShell Configuration |
| 57 | version = "{version}" |
| 58 | log_level = "info" |
| 59 | |
| 60 | [server] |
| 61 | host = "{host}" |
| 62 | port = {port} |
| 63 | |
| 64 | [upstream] |
| 65 | openai_base_url = "https://api.openai.com" |
| 66 | openrouter_base_url = "https://openrouter.ai/api" |
| 67 | anthropic_base_url = "https://api.anthropic.com" |
| 68 | minimax_base_url = "https://api.minimax.io" |
| 69 | |
| 70 | {key_section}[dlp] |