mirror of
https://github.com/openai/codex.git
synced 2026-11-11 21:10:39 +00:00
## What changed Add `ContextWindowId` as a string-backed protocol type with UUIDv7 generation and parsing. Use it throughout compaction state, rollout reconstruction, token budget context, and request metadata in place of raw UUIDs, preserving the serialized string format and UUIDv7 validation. GitOrigin-RevId: 786b74fcc331707ca5d6765f429b6e5e322d9328
31 lines
830 B
Rust
31 lines
830 B
Rust
//! Context window identity used for compaction, rollout restoration, and request metadata.
|
|
|
|
use serde::Serialize;
|
|
use std::fmt;
|
|
use uuid::Uuid;
|
|
|
|
#[derive(derive_more::Debug, Clone, PartialEq, Eq, Serialize)]
|
|
#[debug("{_0}")]
|
|
#[serde(transparent)]
|
|
pub struct ContextWindowId(String);
|
|
|
|
impl ContextWindowId {
|
|
pub fn new_uuid_v7() -> Self {
|
|
Self(Uuid::now_v7().to_string())
|
|
}
|
|
|
|
/// Reads a persisted window ID, ignoring IDs outside the supported format.
|
|
pub fn parse(value: &str) -> Option<Self> {
|
|
Uuid::parse_str(value)
|
|
.ok()
|
|
.filter(|uuid| uuid.get_version_num() == 7)
|
|
.map(|uuid| Self(uuid.to_string()))
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for ContextWindowId {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
self.0.fmt(formatter)
|
|
}
|
|
}
|