Skip to main content

simple_agents_core/
healing.rs

1//! Healing helpers and response wrappers.
2
3use simple_agent_type::coercion::CoercionResult;
4use simple_agent_type::prelude::CompletionResponse;
5use simple_agents_healing::coercion::CoercionConfig;
6use simple_agents_healing::parser::ParserConfig;
7use simple_agents_healing::parser::ParserResult;
8
9/// Healing settings for JSON parsing and coercion.
10#[derive(Debug, Clone)]
11pub struct HealingSettings {
12    /// Enable healing APIs.
13    pub enabled: bool,
14    /// Parser configuration for JSON-ish parsing.
15    pub parser_config: ParserConfig,
16    /// Coercion configuration for schema alignment.
17    pub coercion_config: CoercionConfig,
18}
19
20impl Default for HealingSettings {
21    fn default() -> Self {
22        Self {
23            enabled: true,
24            parser_config: ParserConfig::default(),
25            coercion_config: CoercionConfig::default(),
26        }
27    }
28}
29
30impl HealingSettings {
31    /// Create a new settings struct with defaults.
32    pub fn new() -> Self {
33        Self::default()
34    }
35
36    /// Disable healing APIs.
37    pub fn disabled() -> Self {
38        Self {
39            enabled: false,
40            ..Self::default()
41        }
42    }
43
44    /// Override parser configuration.
45    pub fn with_parser_config(mut self, config: ParserConfig) -> Self {
46        self.parser_config = config;
47        self
48    }
49
50    /// Override coercion configuration.
51    pub fn with_coercion_config(mut self, config: CoercionConfig) -> Self {
52        self.coercion_config = config;
53        self
54    }
55}
56
57/// JSON healing response wrapper.
58pub struct HealedJsonResponse {
59    /// Original completion response.
60    pub response: CompletionResponse,
61    /// Parsed JSON value and healing metadata.
62    pub parsed: ParserResult,
63}
64
65/// Schema-aligned healing response wrapper.
66pub struct HealedSchemaResponse {
67    /// Original completion response.
68    pub response: CompletionResponse,
69    /// Parsed JSON value and healing metadata.
70    pub parsed: ParserResult,
71    /// Schema-coerced value and healing metadata.
72    pub coerced: CoercionResult<serde_json::Value>,
73}