Switch from deprecated serde_yaml to serde_yaml_ng

serde_yaml is deprecated and unmaintained. serde_yaml_ng is the community
fork with a compatible API, so this is a straightforward rename across the
codebase.
This commit is contained in:
Slavi Pantaleev
2026-02-10 14:34:57 +02:00
parent a82e9a1d1f
commit faf92cac09
11 changed files with 38 additions and 38 deletions

8
Cargo.lock generated
View File

@@ -304,7 +304,7 @@ dependencies = [
"regex", "regex",
"serde", "serde",
"serde_json", "serde_json",
"serde_yaml", "serde_yaml_ng",
"tempfile", "tempfile",
"tiktoken-rs", "tiktoken-rs",
"tokio", "tokio",
@@ -3892,10 +3892,10 @@ dependencies = [
] ]
[[package]] [[package]]
name = "serde_yaml" name = "serde_yaml_ng"
version = "0.9.34+deprecated" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" checksum = "7b4db627b98b36d4203a7b458cf3573730f2bb591b28871d916dfa9efabfd41f"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"itoa", "itoa",

View File

@@ -31,7 +31,7 @@ quick_cache = "0.6.*"
regex = "1.12.*" regex = "1.12.*"
serde = { version = "1.0.*", features = ["derive"], default-features = false } serde = { version = "1.0.*", features = ["derive"], default-features = false }
serde_json = "1.0.*" serde_json = "1.0.*"
serde_yaml = "0.9.*" serde_yaml_ng = "0.10.*"
tempfile = "3.25.*" tempfile = "3.25.*"
tiktoken-rs = { version = "0.9.*", default-features = false } tiktoken-rs = { version = "0.9.*", default-features = false }
tokio = { version = "1.49.*", features = ["rt", "rt-multi-thread", "macros"] } tokio = { version = "1.49.*", features = ["rt", "rt-multi-thread", "macros"] }

View File

@@ -33,11 +33,11 @@ pub struct AgentDefinition {
)] )]
pub provider: AgentProvider, pub provider: AgentProvider,
pub config: serde_yaml::Value, pub config: serde_yaml_ng::Value,
} }
impl AgentDefinition { impl AgentDefinition {
pub fn new(id: String, provider: AgentProvider, config: serde_yaml::Value) -> Self { pub fn new(id: String, provider: AgentProvider, config: serde_yaml_ng::Value) -> Self {
Self { Self {
id, id,
provider, provider,

View File

@@ -15,7 +15,7 @@ pub enum Error {
// Contains the error from the constructor function // Contains the error from the constructor function
ConstructionFailed(anyhow::Error), ConstructionFailed(anyhow::Error),
// Contains the error from the YAML deserialization function // Contains the error from the YAML deserialization function
Yaml(serde_yaml::Error), Yaml(serde_yaml_ng::Error),
} }
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;
@@ -69,7 +69,7 @@ pub(super) fn create(
pub fn create_from_provider_and_yaml_value_config( pub fn create_from_provider_and_yaml_value_config(
provider: &AgentProvider, provider: &AgentProvider,
identifier: &PublicIdentifier, identifier: &PublicIdentifier,
config: serde_yaml::Value, config: serde_yaml_ng::Value,
) -> Result<AgentInstance> { ) -> Result<AgentInstance> {
let definition = AgentDefinition::new(identifier.prefixless(), provider.to_owned(), config); let definition = AgentDefinition::new(identifier.prefixless(), provider.to_owned(), config);
@@ -79,7 +79,7 @@ pub fn create_from_provider_and_yaml_value_config(
fn create_controller_from_provider_and_json_value_config( fn create_controller_from_provider_and_json_value_config(
agent_id: &str, agent_id: &str,
provider: &AgentProvider, provider: &AgentProvider,
config: serde_yaml::Value, config: serde_yaml_ng::Value,
) -> Result<ControllerType> { ) -> Result<ControllerType> {
match provider { match provider {
AgentProvider::Anthropic => { AgentProvider::Anthropic => {
@@ -112,43 +112,43 @@ fn create_controller_from_provider_and_json_value_config(
} }
} }
pub fn default_config_for_provider(provider: &AgentProvider) -> serde_yaml::Value { pub fn default_config_for_provider(provider: &AgentProvider) -> serde_yaml_ng::Value {
match provider { match provider {
AgentProvider::Anthropic => { AgentProvider::Anthropic => {
let config = super::provider::anthropic::default_config(); let config = super::provider::anthropic::default_config();
serde_yaml::to_value(config).expect("Failed to serialize config") serde_yaml_ng::to_value(config).expect("Failed to serialize config")
} }
AgentProvider::Groq => { AgentProvider::Groq => {
let config = super::provider::groq::default_config(); let config = super::provider::groq::default_config();
serde_yaml::to_value(config).expect("Failed to serialize config") serde_yaml_ng::to_value(config).expect("Failed to serialize config")
} }
AgentProvider::LocalAI => { AgentProvider::LocalAI => {
let config = super::provider::localai::default_config(); let config = super::provider::localai::default_config();
serde_yaml::to_value(config).expect("Failed to serialize config") serde_yaml_ng::to_value(config).expect("Failed to serialize config")
} }
AgentProvider::Mistral => { AgentProvider::Mistral => {
let config = super::provider::mistral::default_config(); let config = super::provider::mistral::default_config();
serde_yaml::to_value(config).expect("Failed to serialize config") serde_yaml_ng::to_value(config).expect("Failed to serialize config")
} }
AgentProvider::Ollama => { AgentProvider::Ollama => {
let config = super::provider::ollama::default_config(); let config = super::provider::ollama::default_config();
serde_yaml::to_value(config).expect("Failed to serialize config") serde_yaml_ng::to_value(config).expect("Failed to serialize config")
} }
AgentProvider::OpenAI => { AgentProvider::OpenAI => {
let config = super::provider::openai::default_config(); let config = super::provider::openai::default_config();
serde_yaml::to_value(config).expect("Failed to serialize config") serde_yaml_ng::to_value(config).expect("Failed to serialize config")
} }
AgentProvider::OpenAICompat => { AgentProvider::OpenAICompat => {
let config = super::provider::openai_compat::default_config(); let config = super::provider::openai_compat::default_config();
serde_yaml::to_value(config).expect("Failed to serialize config") serde_yaml_ng::to_value(config).expect("Failed to serialize config")
} }
AgentProvider::OpenRouter => { AgentProvider::OpenRouter => {
let config = super::provider::openrouter::default_config(); let config = super::provider::openrouter::default_config();
serde_yaml::to_value(config).expect("Failed to serialize config") serde_yaml_ng::to_value(config).expect("Failed to serialize config")
} }
AgentProvider::TogetherAI => { AgentProvider::TogetherAI => {
let config = super::provider::togetherai::default_config(); let config = super::provider::togetherai::default_config();
serde_yaml::to_value(config).expect("Failed to serialize config") serde_yaml_ng::to_value(config).expect("Failed to serialize config")
} }
} }
} }

View File

@@ -12,12 +12,12 @@ use super::controller::ControllerType;
pub fn create_controller_from_yaml_value_config( pub fn create_controller_from_yaml_value_config(
agent_id: &str, agent_id: &str,
config: serde_yaml::Value, config: serde_yaml_ng::Value,
) -> AgentInstantiationResult<ControllerType> { ) -> AgentInstantiationResult<ControllerType> {
let config = match &config { let config = match &config {
serde_yaml::Value::Mapping(_) => { serde_yaml_ng::Value::Mapping(_) => {
let config: Config = let config: Config =
serde_yaml::from_value(config).map_err(AgentInstantiationError::Yaml)?; serde_yaml_ng::from_value(config).map_err(AgentInstantiationError::Yaml)?;
config config
.validate() .validate()

View File

@@ -20,12 +20,12 @@ pub const OPENAI_IMAGE_MODEL_GPT_IMAGE_1_DOT_5: &str = "gpt-image-1.5";
pub fn create_controller_from_yaml_value_config( pub fn create_controller_from_yaml_value_config(
agent_id: &str, agent_id: &str,
config: serde_yaml::Value, config: serde_yaml_ng::Value,
) -> AgentInstantiationResult<ControllerType> { ) -> AgentInstantiationResult<ControllerType> {
let config = match &config { let config = match &config {
serde_yaml::Value::Mapping(_) => { serde_yaml_ng::Value::Mapping(_) => {
let config: Config = let config: Config =
serde_yaml::from_value(config).map_err(AgentInstantiationError::Yaml)?; serde_yaml_ng::from_value(config).map_err(AgentInstantiationError::Yaml)?;
config config
.validate() .validate()

View File

@@ -26,12 +26,12 @@ use super::controller::ControllerType;
pub fn create_controller_from_yaml_value_config( pub fn create_controller_from_yaml_value_config(
agent_id: &str, agent_id: &str,
config: serde_yaml::Value, config: serde_yaml_ng::Value,
) -> AgentInstantiationResult<ControllerType> { ) -> AgentInstantiationResult<ControllerType> {
let config = match &config { let config = match &config {
serde_yaml::Value::Mapping(_) => { serde_yaml_ng::Value::Mapping(_) => {
let config: Config = let config: Config =
serde_yaml::from_value(config).map_err(AgentInstantiationError::Yaml)?; serde_yaml_ng::from_value(config).map_err(AgentInstantiationError::Yaml)?;
config config
.validate() .validate()

View File

@@ -21,7 +21,7 @@ pub fn load() -> anyhow::Result<Config> {
} }
let config_str = std::fs::read_to_string(config_file_path)?; let config_str = std::fs::read_to_string(config_file_path)?;
let mut config: Config = serde_yaml::from_str(&config_str)?; let mut config: Config = serde_yaml_ng::from_str(&config_str)?;
// Allow environment variables to override some configuration keys // Allow environment variables to override some configuration keys
for (key, value) in env::vars() { for (key, value) in env::vars() {

View File

@@ -15,7 +15,7 @@ use crate::{Bot, entity::MessageContext};
struct ParsedAgentConfig { struct ParsedAgentConfig {
agent: AgentInstance, agent: AgentInstance,
config: serde_yaml::Value, config: serde_yaml_ng::Value,
} }
pub async fn handle_room_local( pub async fn handle_room_local(
@@ -250,7 +250,7 @@ async fn send_guide(
provider: &AgentProvider, provider: &AgentProvider,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let sample_config = crate::agent::default_config_for_provider(provider); let sample_config = crate::agent::default_config_for_provider(provider);
let sample_config_pretty_yaml = serde_yaml::to_string(&sample_config)?; let sample_config_pretty_yaml = serde_yaml_ng::to_string(&sample_config)?;
bot.messaging() bot.messaging()
.send_text_markdown_no_fail( .send_text_markdown_no_fail(
@@ -263,7 +263,7 @@ async fn send_guide(
Ok(()) Ok(())
} }
fn parse_from_message_to_yaml_value(text: &str) -> Result<serde_yaml::Value, String> { fn parse_from_message_to_yaml_value(text: &str) -> Result<serde_yaml_ng::Value, String> {
let mut text = text.trim(); let mut text = text.trim();
if text.starts_with("```") { if text.starts_with("```") {
@@ -274,10 +274,10 @@ fn parse_from_message_to_yaml_value(text: &str) -> Result<serde_yaml::Value, Str
text = text.trim_end_matches("```"); text = text.trim_end_matches("```");
} }
let config: serde_yaml::Value = serde_yaml::from_str(text).map_err(|e| e.to_string())?; let config: serde_yaml_ng::Value = serde_yaml_ng::from_str(text).map_err(|e| e.to_string())?;
match config { match config {
serde_yaml::Value::Mapping(_) => {} serde_yaml_ng::Value::Mapping(_) => {}
_ => { _ => {
return Err("Not a valid YAML hashmap".to_owned()); return Err("Not a valid YAML hashmap".to_owned());
} }

View File

@@ -2,12 +2,12 @@
fn agent_config_parsing_works() { fn agent_config_parsing_works() {
struct TestCase { struct TestCase {
input: String, input: String,
expected: Option<serde_yaml::Value>, expected: Option<serde_yaml_ng::Value>,
} }
let provider = crate::agent::AgentProvider::OpenAI; let provider = crate::agent::AgentProvider::OpenAI;
let sample_config = crate::agent::default_config_for_provider(&provider); let sample_config = crate::agent::default_config_for_provider(&provider);
let sample_config_pretty_yaml = serde_yaml::to_string(&sample_config).unwrap(); let sample_config_pretty_yaml = serde_yaml_ng::to_string(&sample_config).unwrap();
let test_cases = vec![ let test_cases = vec![
// Invalid input // Invalid input

View File

@@ -64,7 +64,7 @@ pub async fn handle(
PublicIdentifier::Static(_) => {} PublicIdentifier::Static(_) => {}
}; };
let config_yaml_pretty = serde_yaml::to_string(&agent.definition().config)?; let config_yaml_pretty = serde_yaml_ng::to_string(&agent.definition().config)?;
bot.messaging() bot.messaging()
.send_text_markdown_no_fail( .send_text_markdown_no_fail(