systemprompt-wire 0.67.0

Canonical AI wire types and per-protocol codecs for systemprompt.io AI governance infrastructure. Anthropic, OpenAI Chat, OpenAI Responses and Gemini request, response and SSE shapes shared by the gateway and the agent provider clients.
Documentation
//! `OpenAI` Responses wire codec.
//!
//! Builds an `OpenAI` Responses upstream request from a
//! [`crate::canonical::CanonicalRequest`], parses the buffered reply into
//! a [`crate::canonical::CanonicalResponse`], and maps Responses SSE
//! bytes to [`crate::canonical::CanonicalEvent`]s.
//!
//! Every public function here is a pure codec over [`serde_json::Value`] or a
//! byte stream; transport, auth, and HTTP status handling stay in the gateway
//! adapter that calls these. The `request` submodule owns the request build,
//! `response` the buffered-reply parse, `streaming` the SSE-to-event pipeline,
//! and `slot` the per-output-item slot state machine the streaming pass tracks.
//!
//! Copyright (c) systemprompt.io — Business Source License 1.1.
//! See <https://systemprompt.io> for licensing details.

mod request;
mod response;
mod slot;
mod streaming;

use crate::canonical::CanonicalStopReason;

// Why: Responses has no finish-reason field: tool use is a `function_call`
// output item, and truncation is reported in `incomplete_details.reason`.
fn derive_stop_reason(has_tool_use: bool, incomplete_reason: Option<&str>) -> CanonicalStopReason {
    match incomplete_reason {
        Some("max_output_tokens") => CanonicalStopReason::MaxTokens,
        Some(_) => CanonicalStopReason::Other.with_tool_use(has_tool_use),
        None => CanonicalStopReason::EndTurn.with_tool_use(has_tool_use),
    }
}

pub use request::build_request_body;
pub use response::{buffered_defect, parse_response_object};
pub use streaming::sse_to_canonical_events;