Add a wrapper around raw response items (#5923)
We currently have nested enums when sending raw response items in the app-server protocol. This makes downstream schemas confusing because we need to embed `type`-discriminated enums within each other. This PR adds a small wrapper around the response item so we can keep the schemas separate
This commit is contained in:
@@ -16,6 +16,7 @@ use codex_app_server_protocol::SendUserMessageResponse;
|
|||||||
use codex_protocol::ConversationId;
|
use codex_protocol::ConversationId;
|
||||||
use codex_protocol::models::ContentItem;
|
use codex_protocol::models::ContentItem;
|
||||||
use codex_protocol::models::ResponseItem;
|
use codex_protocol::models::ResponseItem;
|
||||||
|
use codex_protocol::protocol::RawResponseItemEvent;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
@@ -294,7 +295,9 @@ async fn read_raw_response_item(
|
|||||||
.cloned()
|
.cloned()
|
||||||
.expect("raw response item should include msg payload");
|
.expect("raw response item should include msg payload");
|
||||||
|
|
||||||
serde_json::from_value(msg_value).expect("deserialize raw response item")
|
let event: RawResponseItemEvent =
|
||||||
|
serde_json::from_value(msg_value).expect("deserialize raw response item");
|
||||||
|
event.item
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assert_instructions_message(item: &ResponseItem) {
|
fn assert_instructions_message(item: &ResponseItem) {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ use codex_protocol::items::TurnItem;
|
|||||||
use codex_protocol::protocol::ExitedReviewModeEvent;
|
use codex_protocol::protocol::ExitedReviewModeEvent;
|
||||||
use codex_protocol::protocol::ItemCompletedEvent;
|
use codex_protocol::protocol::ItemCompletedEvent;
|
||||||
use codex_protocol::protocol::ItemStartedEvent;
|
use codex_protocol::protocol::ItemStartedEvent;
|
||||||
|
use codex_protocol::protocol::RawResponseItemEvent;
|
||||||
use codex_protocol::protocol::ReviewRequest;
|
use codex_protocol::protocol::ReviewRequest;
|
||||||
use codex_protocol::protocol::RolloutItem;
|
use codex_protocol::protocol::RolloutItem;
|
||||||
use codex_protocol::protocol::SessionSource;
|
use codex_protocol::protocol::SessionSource;
|
||||||
@@ -987,8 +988,11 @@ impl Session {
|
|||||||
|
|
||||||
async fn send_raw_response_items(&self, turn_context: &TurnContext, items: &[ResponseItem]) {
|
async fn send_raw_response_items(&self, turn_context: &TurnContext, items: &[ResponseItem]) {
|
||||||
for item in items {
|
for item in items {
|
||||||
self.send_event(turn_context, EventMsg::RawResponseItem(item.clone()))
|
self.send_event(
|
||||||
.await;
|
turn_context,
|
||||||
|
EventMsg::RawResponseItem(RawResponseItemEvent { item: item.clone() }),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -542,12 +542,17 @@ pub enum EventMsg {
|
|||||||
/// Exited review mode with an optional final result to apply.
|
/// Exited review mode with an optional final result to apply.
|
||||||
ExitedReviewMode(ExitedReviewModeEvent),
|
ExitedReviewMode(ExitedReviewModeEvent),
|
||||||
|
|
||||||
RawResponseItem(ResponseItem),
|
RawResponseItem(RawResponseItemEvent),
|
||||||
|
|
||||||
ItemStarted(ItemStartedEvent),
|
ItemStarted(ItemStartedEvent),
|
||||||
ItemCompleted(ItemCompletedEvent),
|
ItemCompleted(ItemCompletedEvent),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize, Serialize, TS, JsonSchema)]
|
||||||
|
pub struct RawResponseItemEvent {
|
||||||
|
pub item: ResponseItem,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, TS, JsonSchema)]
|
#[derive(Debug, Clone, Deserialize, Serialize, TS, JsonSchema)]
|
||||||
pub struct ItemStartedEvent {
|
pub struct ItemStartedEvent {
|
||||||
pub thread_id: ConversationId,
|
pub thread_id: ConversationId,
|
||||||
|
|||||||
Reference in New Issue
Block a user