use serde_json::Value;
use crate::boundary::{BoundaryFailure, BoundaryFailureKind, BoundaryId};
fn report(detail: String, element: &Value) {
BoundaryFailure::new(
BoundaryId::ResponseContentExtraction,
BoundaryFailureKind::Unrecognized,
detail,
)
.with_excerpt(&element.to_string())
.report();
}
fn named(kind: Option<&str>) -> &str {
kind.unwrap_or("<none>")
}
pub(super) fn unhandled_content_block(provider: &str, kind: Option<&str>, block: &Value) {
report(
format!(
"{provider} response content block type `{}` has no handler",
named(kind)
),
block,
);
}
pub(super) fn unhandled_output_item(kind: &str, item: &Value) {
report(
format!("openai-responses output item type `{kind}` has no handler"),
item,
);
}
pub(super) fn unhandled_message_part(kind: Option<&str>, content: &Value) {
report(
format!(
"openai-responses message part type `{}` has no handler",
named(kind)
),
content,
);
}
pub(super) fn unreadable_message_part(kind: Option<&str>, content: &Value) {
report(
format!(
"openai-responses message part of type `{}` carries no string text",
named(kind)
),
content,
);
}
pub(super) fn discarded_choices(provider: &str, choices: &[Value]) {
if choices.len() < 2 {
return;
}
report(
format!(
"{provider} returned {} choices; only choices[0] is read",
choices.len()
),
&Value::Array(choices[1..].to_vec()),
);
}
#[cfg(test)]
mod tests;