systemprompt-api 0.9.0

Axum-based HTTP server and API gateway for systemprompt.io AI governance infrastructure. Exposes governed agents, MCP, A2A, and admin endpoints with rate limiting and RBAC.
Documentation
use super::captures::{CapturedToolUse, CapturedUsage};
use super::protocol::canonical::CanonicalContent;
use super::protocol::canonical_response::CanonicalResponse;

pub fn extract_from_canonical(
    response: &CanonicalResponse,
) -> (CapturedUsage, Vec<CapturedToolUse>) {
    let usage = CapturedUsage {
        input_tokens: response.usage.input_tokens,
        output_tokens: response.usage.output_tokens,
    };
    let mut tool_calls = Vec::new();
    for part in &response.content {
        if let CanonicalContent::ToolUse { id, name, input } = part {
            tool_calls.push(CapturedToolUse {
                ai_tool_call_id: id.clone(),
                tool_name: name.clone(),
                tool_input: serde_json::to_string(input).unwrap_or_default(),
            });
        }
    }
    (usage, tool_calls)
}

pub fn extract_assistant_text(response: &CanonicalResponse) -> Option<String> {
    let mut out = String::new();
    for part in &response.content {
        if let CanonicalContent::Text(t) = part {
            if !out.is_empty() {
                out.push('\n');
            }
            out.push_str(t);
        }
    }
    if out.is_empty() { None } else { Some(out) }
}