mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
add uuid to metadata
This commit is contained in:
@@ -46,7 +46,12 @@ pub struct Prompt {
|
||||
|
||||
impl Prompt {
|
||||
pub(crate) fn get_formatted_input(&self) -> Vec<ResponseItem> {
|
||||
let mut input = self.input.clone();
|
||||
let mut input: Vec<ResponseItem> = self
|
||||
.input
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(ResponseItem::with_generated_metadata_uuid)
|
||||
.collect();
|
||||
|
||||
// when using the *Freeform* apply_patch tool specifically, tool outputs
|
||||
// should be structured text, not json. Do NOT reserialize when using
|
||||
|
||||
@@ -3,7 +3,10 @@ use codex_api::common::OpenAiVerbosity;
|
||||
use codex_api::common::TextControls;
|
||||
use codex_api::create_text_param_for_request;
|
||||
use codex_protocol::config_types::ServiceTier;
|
||||
use codex_protocol::models::ContentItem;
|
||||
use codex_protocol::models::FunctionCallOutputPayload;
|
||||
use codex_protocol::models::ResponseItemMetadata;
|
||||
use codex_protocol::models::UserMessageType;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::*;
|
||||
@@ -196,6 +199,39 @@ fn reserializes_shell_outputs_for_function_and_custom_tool_calls() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formatted_input_generates_message_metadata_uuid() {
|
||||
let prompt = Prompt {
|
||||
input: vec![ResponseItem::Message {
|
||||
id: Some("msg_123".to_string()),
|
||||
role: "user".to_string(),
|
||||
content: vec![ContentItem::InputText {
|
||||
text: "hello".to_string(),
|
||||
}],
|
||||
metadata: Some(ResponseItemMetadata {
|
||||
user_message_type: Some(UserMessageType::Prompt),
|
||||
uuid: None,
|
||||
}),
|
||||
end_turn: None,
|
||||
phase: None,
|
||||
}],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let formatted = prompt.get_formatted_input();
|
||||
assert_eq!(formatted.len(), 1);
|
||||
|
||||
match &formatted[0] {
|
||||
ResponseItem::Message { metadata, .. } => {
|
||||
let metadata = metadata.as_ref().expect("metadata should be present");
|
||||
assert_eq!(metadata.user_message_type, Some(UserMessageType::Prompt));
|
||||
let uuid = metadata.uuid.as_deref().expect("uuid should be present");
|
||||
uuid::Uuid::parse_str(uuid).expect("uuid should be valid");
|
||||
}
|
||||
other => panic!("expected message item, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_search_output_namespace_serializes_with_deferred_child_tools() {
|
||||
let namespace = tools::ToolSearchOutputTool::Namespace(tools::ResponsesApiNamespace {
|
||||
|
||||
@@ -3277,9 +3277,14 @@ impl Session {
|
||||
turn_context: &TurnContext,
|
||||
items: &[ResponseItem],
|
||||
) {
|
||||
self.record_into_history(items, turn_context).await;
|
||||
self.persist_rollout_response_items(items).await;
|
||||
self.send_raw_response_items(turn_context, items).await;
|
||||
let items: Vec<ResponseItem> = items
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(ResponseItem::with_generated_metadata_uuid)
|
||||
.collect();
|
||||
self.record_into_history(&items, turn_context).await;
|
||||
self.persist_rollout_response_items(&items).await;
|
||||
self.send_raw_response_items(turn_context, &items).await;
|
||||
}
|
||||
|
||||
/// Append ResponseItems to the in-memory conversation history only.
|
||||
|
||||
Reference in New Issue
Block a user