roboticus-core 0.11.1

Shared types, config parsing, personality system, and error types for the Roboticus agent runtime
Documentation
//! Canonical utilities for parsing model identifiers.
//!
//! Model IDs use the format `"provider/model_name"` (e.g., `"openai/gpt-4o"`).
//! These functions provide a single source of truth for extracting the two
//! components, replacing 15+ ad hoc `.split('/')` calls scattered across the
//! workspace.

/// Extract the provider prefix from a model identifier.
///
/// ```
/// assert_eq!(roboticus_core::model::provider_prefix("openai/gpt-4o"), "openai");
/// assert_eq!(roboticus_core::model::provider_prefix("gpt-4o"), "gpt-4o");
/// assert_eq!(roboticus_core::model::provider_prefix(""), "unknown");
/// ```
pub fn provider_prefix(model_id: &str) -> &str {
    if model_id.is_empty() {
        return "unknown";
    }
    model_id.split('/').next().unwrap_or("unknown")
}

/// Extract the model name (without provider prefix) from a model identifier.
///
/// ```
/// assert_eq!(roboticus_core::model::model_name("openai/gpt-4o"), "gpt-4o");
/// assert_eq!(roboticus_core::model::model_name("gpt-4o"), "gpt-4o");
/// ```
pub fn model_name(model_id: &str) -> &str {
    model_id
        .split_once('/')
        .map(|(_, name)| name)
        .unwrap_or(model_id)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn provider_prefix_extracts_correctly() {
        assert_eq!(provider_prefix("openai/gpt-4o"), "openai");
        assert_eq!(provider_prefix("anthropic/claude-3-opus"), "anthropic");
        assert_eq!(provider_prefix("local/llama-3"), "local");
    }

    #[test]
    fn provider_prefix_handles_edge_cases() {
        assert_eq!(provider_prefix("gpt-4o"), "gpt-4o");
        assert_eq!(provider_prefix(""), "unknown");
        assert_eq!(provider_prefix("a/b/c"), "a");
    }

    #[test]
    fn model_name_extracts_correctly() {
        assert_eq!(model_name("openai/gpt-4o"), "gpt-4o");
        assert_eq!(model_name("anthropic/claude-3-opus"), "claude-3-opus");
    }

    #[test]
    fn model_name_handles_no_prefix() {
        assert_eq!(model_name("gpt-4o"), "gpt-4o");
        assert_eq!(model_name(""), "");
    }
}