feat: harden community production foundation through story 1.5

This commit is contained in:
bsodfather committed 2026-08-14 00:21:59 +03:00
1 parent c30461cc92
commit f6fc2e5c9b
161 files changed
+16758 -2515

No files matched your search

+32 -9
View File
@@ -4,7 +4,10 @@ use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::{AgentId, InvocationSource, Protocol, Target, WorkspaceId};
use crate::{
AgentId, CorrelationContext, InvocationSource, Protocol, RequestId, Target, TraceContext,
WorkspaceId,
};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
@@ -20,8 +23,8 @@ pub struct ResponseCacheScope {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct RuntimeRequestContext {
pub request_id: String,
pub correlation_id: String,
pub request_id: RequestId,
pub trace_context: TraceContext,
pub response_cache_scope: Option<ResponseCacheScope>,
pub metering_context: Option<MeteringContext>,
}
@@ -34,10 +37,10 @@ pub struct MeteringContext {
}
impl RuntimeRequestContext {
pub fn new(request_id: impl Into<String>, correlation_id: impl Into<String>) -> Self {
pub fn new(request_id: RequestId, trace_context: TraceContext) -> Self {
Self {
request_id: request_id.into(),
correlation_id: correlation_id.into(),
request_id,
trace_context,
response_cache_scope: None,
metering_context: None,
}
@@ -45,13 +48,33 @@ impl RuntimeRequestContext {
pub fn from_request_id(request_id: impl Into<String>) -> Self {
let request_id = request_id.into();
Self::new(request_id.clone(), request_id)
Self::new(
RequestId::resolve(Some(&request_id)),
TraceContext::generate(),
)
}
pub fn from_correlation(context: &CorrelationContext) -> Self {
Self::new(
context.request_id().clone(),
context.trace_context().clone(),
)
}
pub fn outbound_headers(&self) -> BTreeMap<String, String> {
BTreeMap::from([
("x-request-id".to_owned(), self.request_id.clone()),
("x-correlation-id".to_owned(), self.correlation_id.clone()),
("x-request-id".to_owned(), self.request_id.to_string()),
(
"x-trace-id".to_owned(),
self.trace_context.trace_id().to_string(),
),
(
"traceparent".to_owned(),
self.trace_context.traceparent().to_owned(),
),
// Compatibility alias only. It is intentionally the product Request ID,
// never the W3C Trace ID.
("x-correlation-id".to_owned(), self.request_id.to_string()),
])
}