mirror of
https://github.com/openai/codex.git
synced 2026-12-06 01:10:58 +00:00
## Why Contextual fragments and extension-owned world-state sections currently return strings, limiting them to text content. ## What changed - Return `ContentItem` from fragment bodies and rendering, preserving classification and attribution. Apply text markers only to `InputText`; pass other content through unchanged. - Allow extension prompt and world-state contributions to carry typed content, and preserve media in context-window hints. - Hash non-text world-state fragments by their serialized content and role while retaining the existing text hashing behavior. - Add shared content-to-tool-output conversion that preserves image references, image detail, and audio. ## Testing Add coverage for typed world-state hashing and preservation of image content and attribution. Expand code-mode output tests to cover input text, output text, file-backed and inline images, and audio. GitOrigin-RevId: 2ed00d466a3f169b151202f3eef71e667ea64be1
62 lines
1.7 KiB
Rust
62 lines
1.7 KiB
Rust
//! Initial base instructions, recorded in history for incremental-tools windows.
|
|
|
|
use super::ContextualUserFragment;
|
|
use codex_protocol::models::ContentItem;
|
|
use codex_protocol::models::ContentItemKind;
|
|
use codex_protocol::models::ResponseItem;
|
|
use codex_protocol::models::input_text;
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub(crate) struct BaseInstructionsFragment(pub(crate) String);
|
|
|
|
impl BaseInstructionsFragment {
|
|
pub(crate) const KIND: &str = "model.base_instructions";
|
|
|
|
/// Reads only a dedicated, harness-classified base item, including an explicitly empty base.
|
|
pub(crate) fn text_from_item(item: &ResponseItem) -> Option<&str> {
|
|
let ResponseItem::Message {
|
|
role,
|
|
content,
|
|
internal_chat_message_metadata_passthrough: Some(metadata),
|
|
..
|
|
} = item
|
|
else {
|
|
return None;
|
|
};
|
|
match (
|
|
role.as_str(),
|
|
content.as_slice(),
|
|
metadata.content_item_kinds.as_deref(),
|
|
) {
|
|
("developer", [ContentItem::InputText { text }], Some([kind]))
|
|
if kind.as_str() == Self::KIND =>
|
|
{
|
|
Some(text)
|
|
}
|
|
_ => None,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ContextualUserFragment for BaseInstructionsFragment {
|
|
fn content_kind(&self) -> ContentItemKind {
|
|
ContentItemKind(Self::KIND.to_string())
|
|
}
|
|
|
|
fn role(&self) -> &'static str {
|
|
"developer"
|
|
}
|
|
|
|
fn markers(&self) -> (&'static str, &'static str) {
|
|
Self::type_markers()
|
|
}
|
|
|
|
fn type_markers() -> (&'static str, &'static str) {
|
|
("", "")
|
|
}
|
|
|
|
fn body(&self) -> ContentItem {
|
|
input_text(self.0.clone())
|
|
}
|
|
}
|