use ai_profile::{parse_profiles, to_profile, ParseError, Protocol};
fn main() {
let shared = to_profile(
"我的 DeepSeek",
Protocol::OpenAiCompatible,
"https://api.deepseek.com/v1",
"sk-示例密钥",
"deepseek-flash",
);
println!("分享出去的内容:\n{shared}\n");
import(&shared);
import(
r#"{"kind":"ai.profile","v":1,"data":{"name":"中转","provider":"anthropic","baseURL":"https://relay.example.com","apiKey":"sk-x","model":"claude-opus-5"}}"#,
);
import(r#"{"hello":"world"}"#);
import("");
}
fn import(text: &str) {
match parse_profiles(text, "deepseek-flash") {
Ok(r) => {
for p in &r.profiles {
println!(
"导入:{} [{}] {} / {}{}",
p.name,
p.protocol.as_str(),
p.base_url,
p.model,
if p.model_fallback {
"(模型为兜底值)"
} else {
""
}
);
}
if r.skipped > 0 {
println!("跳过 {} 条(设备绑定的登录凭据)", r.skipped);
}
}
Err(e) => {
let hint = match &e {
ParseError::Empty => "剪贴板是空的",
ParseError::NotAiProfile { .. } => "这不是 ai.profile 配置",
ParseError::EmptyBundle { .. } => "打包里没有能导入的配置",
_ => "配置格式不对",
};
println!("导入失败:{hint}({e})");
}
}
println!();
}