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
55 lines
1.7 KiB
Rust
55 lines
1.7 KiB
Rust
//! A single model-context fragment for independent model and instruction changes.
|
|
|
|
use super::ContextualUserFragment;
|
|
use codex_protocol::models::ContentItem;
|
|
use codex_protocol::models::ContentItemKind;
|
|
use codex_protocol::models::input_text;
|
|
|
|
const REPLACEMENT_NOTICE: &str =
|
|
"The following instructions replace the previous base instructions:";
|
|
const REMOVAL_NOTICE: &str =
|
|
"The previous base instructions no longer apply. No replacement base instructions are active.";
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub(crate) struct ModelInstructions {
|
|
pub(crate) model: Option<String>,
|
|
/// None leaves instructions unchanged; Some replaces them, including an empty value.
|
|
pub(crate) instructions: Option<String>,
|
|
}
|
|
|
|
impl ContextualUserFragment for ModelInstructions {
|
|
fn content_kind(&self) -> ContentItemKind {
|
|
ContentItemKind("model.instructions".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) {
|
|
("<model_instructions>", "</model_instructions>")
|
|
}
|
|
|
|
fn body(&self) -> ContentItem {
|
|
let mut body = String::from("\n");
|
|
if let Some(model) = &self.model {
|
|
body.push_str(&format!("The current model is {model}.\n"));
|
|
}
|
|
match &self.instructions {
|
|
Some(instructions) if instructions.is_empty() => {
|
|
body.push_str(REMOVAL_NOTICE);
|
|
body.push('\n');
|
|
}
|
|
Some(instructions) => {
|
|
body.push_str(&format!("{REPLACEMENT_NOTICE}\n\n{instructions}\n"));
|
|
}
|
|
None => {}
|
|
}
|
|
input_text(body)
|
|
}
|
|
}
|