mirror of
https://github.com/Mesh-LLM/mesh-llm.git
synced 2026-08-08 22:23:19 -04:00
feat(openai): configure trusted agent session header (#1205)
* feat(openai): configure trusted agent session header * fix(openai): warn on invalid session header configuration
This commit is contained in:
parent
915e69185f
commit
22ae6ab21a
2 changed files with 46 additions and 1 deletions
|
|
@ -50,6 +50,7 @@ For the concrete benchy command and contract, see
|
|||
| Request body limit | Supported | Configurable via `OpenAiFrontendConfig`; defaults to 4 MiB. |
|
||||
| Request IDs | Supported | Propagates or generates `x-request-id`, returns it on every response, and emits a tracing event with method, URI, status, and request ID. |
|
||||
| Backend timeout | Supported | Configurable via `OpenAiFrontendConfig`; defaults to 300 seconds and maps timeouts to OpenAI-shaped 504 errors. |
|
||||
| Agent session header | Supported | Set `MESH_AGENT_SESSION_HEADER` to accept a trusted upstream header as the stable agent-session identity. |
|
||||
| embeddings/rerank/infill/audio/vision | Out of scope | Not needed for staged text benchmark entrypoints. |
|
||||
|
||||
## Shape
|
||||
|
|
|
|||
|
|
@ -47,6 +47,37 @@ use crate::{
|
|||
sse::{done_event, json_event},
|
||||
};
|
||||
|
||||
const AGENT_SESSION_HEADER_ENV: &str = "MESH_AGENT_SESSION_HEADER";
|
||||
|
||||
fn parse_agent_session_header(value: &str) -> Option<HeaderName> {
|
||||
HeaderName::from_bytes(value.as_bytes()).ok()
|
||||
}
|
||||
|
||||
fn configured_agent_session_header() -> Option<HeaderName> {
|
||||
let value = match std::env::var(AGENT_SESSION_HEADER_ENV) {
|
||||
Ok(value) => value,
|
||||
Err(std::env::VarError::NotPresent) => return None,
|
||||
Err(std::env::VarError::NotUnicode(_)) => {
|
||||
tracing::warn!(
|
||||
env = AGENT_SESSION_HEADER_ENV,
|
||||
"ignoring non-UTF-8 trusted agent-session header configuration"
|
||||
);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
match parse_agent_session_header(&value) {
|
||||
Some(header) => Some(header),
|
||||
None => {
|
||||
tracing::warn!(
|
||||
env = AGENT_SESSION_HEADER_ENV,
|
||||
value = %value,
|
||||
"ignoring invalid trusted agent-session header configuration"
|
||||
);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct FrontendState {
|
||||
backend: SharedBackend,
|
||||
|
|
@ -92,7 +123,7 @@ impl Default for OpenAiFrontendConfig {
|
|||
Self {
|
||||
max_request_body_bytes: Self::DEFAULT_MAX_REQUEST_BODY_BYTES,
|
||||
backend_timeout: Some(Self::DEFAULT_BACKEND_TIMEOUT),
|
||||
agent_session_header: None,
|
||||
agent_session_header: configured_agent_session_header(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -715,6 +746,19 @@ mod tests {
|
|||
use tower::ServiceExt;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn trusted_agent_session_header_parser_accepts_valid_names() {
|
||||
assert_eq!(
|
||||
parse_agent_session_header("x-litellm-session-id"),
|
||||
Some(HeaderName::from_static("x-litellm-session-id"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trusted_agent_session_header_parser_rejects_invalid_names() {
|
||||
assert!(parse_agent_session_header("not a header").is_none());
|
||||
}
|
||||
use crate::{
|
||||
FinishReason,
|
||||
backend::{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue