mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
0b460eda32
This will be fixed once this is settled: https://www.notion.so/openai/Artificial-context-management-2fb8e50b62b080db8b8ed93b3b19d1a2#2fb8e50b62b080d2bffce2dd1e60972b
27 lines
1.1 KiB
Rust
27 lines
1.1 KiB
Rust
use codex_protocol::models::ContentItem;
|
|
|
|
/// Helpers for identifying model-visible "session prefix" messages.
|
|
///
|
|
/// A session prefix is a user-role message that carries configuration or state needed by
|
|
/// follow-up turns (e.g. `<environment_context>`, `<turn_aborted>`). These items are persisted in
|
|
/// history so the model can see them, but they are not user intent and must not create user-turn
|
|
/// boundaries.
|
|
pub(crate) const ENVIRONMENT_CONTEXT_OPEN_TAG: &str = "<environment_context>";
|
|
pub(crate) const TURN_ABORTED_OPEN_TAG: &str = "<turn_aborted>";
|
|
|
|
/// Returns true if `text` starts with a session prefix marker (case-insensitive).
|
|
pub(crate) fn is_session_prefix(text: &str) -> bool {
|
|
let trimmed = text.trim_start();
|
|
let lowered = trimmed.to_ascii_lowercase();
|
|
lowered.starts_with(ENVIRONMENT_CONTEXT_OPEN_TAG) || lowered.starts_with(TURN_ABORTED_OPEN_TAG)
|
|
}
|
|
|
|
/// Returns true if `text` starts with a session prefix marker (case-insensitive).
|
|
pub(crate) fn is_session_prefix_content(content: &[ContentItem]) -> bool {
|
|
if let [ContentItem::InputText { text }] = content {
|
|
is_session_prefix(text)
|
|
} else {
|
|
false
|
|
}
|
|
}
|