Files
leleka/control-plane/src/responses/impl_createrequest_2.rs
T
Pavlo Ratushnyi 3aa96fbf0e STRA-338 S21: the pure Responses protocol moves from strata-control to leleka-gateway-domain
CreateRequest, TextOptions, TextFormat, its validation and tool-choice rules, OutputItem, Usage, ResponseTrace with its
event stream, the prompt rendering (render_request_with), the output parsing and reasoning split (parse_output_items_with,
decode_generation_noted), reasoning_effort and the schema checks now live in crates/gateway-domain/src/responses/.
strata-control re-exports the types under responses::* and keeps thin wrappers with the old signatures for the places that
need a process flag, a stage span or a log line. The text of the moved functions is unchanged; the edits are listed in
docs/architecture/tech-debt.md (S21 wider).

Evidence: the golden fixture committed just before this (control-plane/tests/fixtures/golden/responses_pure.json, recorded
from the old code, 96 cases of render, validate, trace and parse) passes on the new code, and the Linux test ids of
strata-control, strata-desktop-core, leleka-gateway-text and leleka-gateway-domain are unchanged (0 changed, 0 missing).

Gate: --update-baseline --allow-increase was used for two entries. process-global:leleka-gateway-domain 0 -> 3 is the
memo of tool_schema_accepted moving with its function (process-global:strata-control fell 14 -> 11, the sum is unchanged).
render.rs is a new moved file of 405 lines (one 385-line legacy function), listed as debt.
2026-11-06 00:50:30 +01:00

71 lines
2.2 KiB
Rust

//! Request intake: the body read as traced JSON, and the decode, validation and model check of a create request.
#[allow(unused_imports)]
use super::*;
impl<S: Send + Sync> axum::extract::FromRequest<S> for TracedJson {
type Rejection = JsonRejection;
async fn from_request(
request: axum::extract::Request,
state: &S,
) -> Result<Self, Self::Rejection> {
let _span = crate::stage_trace::span("http_body_json");
Json::<Value>::from_request(request, state).await.map(Self)
}
}
pub(super) fn parse_request(
state: &AppState,
body: Result<Json<Value>, JsonRejection>,
) -> Result<CreateRequest, Box<Response>> {
let Json(body) = match body {
Ok(body) => body,
Err(error) => {
return Err(Box::new(api_error(
error.status(),
"invalid_request_error",
"invalid_json",
None,
&error.to_string(),
)));
}
};
let decode = crate::stage_trace::span("request_decode");
let request: CreateRequest = match serde_json::from_value(body) {
Ok(request) => request,
Err(error) => {
return Err(Box::new(api_error(
StatusCode::BAD_REQUEST,
"invalid_request_error",
"invalid_request",
None,
&error.to_string(),
)));
}
};
drop(decode);
let validated = crate::stage_trace::time("request_validate", || request.validate());
if let Err((param, message)) = validated {
return Err(Box::new(api_error(
StatusCode::BAD_REQUEST,
"invalid_request_error",
"invalid_request",
Some(param),
message,
)));
}
if state.model.name.as_ref().is_some_and(|model| {
model != &request.model && !state.model.aliases.contains(&request.model)
}) {
return Err(Box::new(api_error(
StatusCode::NOT_FOUND,
"invalid_request_error",
"model_not_found",
Some("model"),
"the requested model is not served by this runtime",
)));
}
Ok(request)
}