mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
Seed realtime V3 sessions with initial text items (#34067)
## What changed - Add an optional `initialItems` field to `thread/realtime/start` for seeding realtime V3 session history with `user`, `developer`, and `assistant` text. - Encode the items in Frameless Bidi session bootstrap payloads for websocket and WebRTC transports while preserving existing payloads when the list is omitted or empty. - Reject non-empty initial items for V1 and V2, more than 128 items, any item over 8,192 estimated tokens, or a combined total over 8,192 estimated tokens. ## Testing - Cover protocol serialization, app-server forwarding, websocket and WebRTC payloads, empty-list compatibility, version checks, and size limits. GitOrigin-RevId: 09af367f9a07543e3f8d59b7fa5387f932dc5a6a
This commit is contained in:
committed by
copyberry
parent
35eaf3ffb0
commit
312caf176a
@@ -1772,6 +1772,7 @@ mod tests {
|
||||
use codex_protocol::models::BUILT_IN_PERMISSION_PROFILE_READ_ONLY;
|
||||
use codex_protocol::parse_command::ParsedCommand;
|
||||
use codex_protocol::protocol::CodexResponseHandoffMode;
|
||||
use codex_protocol::protocol::ConversationTextRole;
|
||||
use codex_protocol::protocol::RealtimeConversationVersion;
|
||||
use codex_protocol::protocol::RealtimeOutputModality;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
@@ -3403,6 +3404,16 @@ mod tests {
|
||||
model: Some("realtime-treatment-model".to_string()),
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
include_startup_context: Some(false),
|
||||
initial_items: Some(vec![
|
||||
v2::ThreadRealtimeInitialItem {
|
||||
role: ConversationTextRole::Developer,
|
||||
text: "Remember this.".to_string(),
|
||||
},
|
||||
v2::ThreadRealtimeInitialItem {
|
||||
role: ConversationTextRole::Assistant,
|
||||
text: "Understood.".to_string(),
|
||||
},
|
||||
]),
|
||||
prompt: Some(Some("You are on a call".to_string())),
|
||||
realtime_session_id: Some("sess_456".to_string()),
|
||||
transport: None,
|
||||
@@ -3424,6 +3435,16 @@ mod tests {
|
||||
"model": "realtime-treatment-model",
|
||||
"outputModality": "audio",
|
||||
"includeStartupContext": false,
|
||||
"initialItems": [
|
||||
{
|
||||
"role": "developer",
|
||||
"text": "Remember this."
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"text": "Understood."
|
||||
}
|
||||
],
|
||||
"prompt": "You are on a call",
|
||||
"realtimeSessionId": "sess_456",
|
||||
"transport": null,
|
||||
@@ -3450,6 +3471,7 @@ mod tests {
|
||||
model: None,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
include_startup_context: None,
|
||||
initial_items: None,
|
||||
prompt: None,
|
||||
realtime_session_id: None,
|
||||
transport: None,
|
||||
@@ -3471,6 +3493,7 @@ mod tests {
|
||||
"model": null,
|
||||
"outputModality": "audio",
|
||||
"includeStartupContext": null,
|
||||
"initialItems": null,
|
||||
"realtimeSessionId": null,
|
||||
"transport": null,
|
||||
"version": null,
|
||||
@@ -3492,6 +3515,7 @@ mod tests {
|
||||
model: None,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
include_startup_context: None,
|
||||
initial_items: None,
|
||||
prompt: Some(None),
|
||||
realtime_session_id: None,
|
||||
transport: None,
|
||||
@@ -3513,6 +3537,7 @@ mod tests {
|
||||
"model": null,
|
||||
"outputModality": "audio",
|
||||
"includeStartupContext": null,
|
||||
"initialItems": null,
|
||||
"prompt": null,
|
||||
"realtimeSessionId": null,
|
||||
"transport": null,
|
||||
@@ -3734,6 +3759,7 @@ mod tests {
|
||||
model: None,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
include_startup_context: None,
|
||||
initial_items: None,
|
||||
prompt: Some(Some("You are on a call".to_string())),
|
||||
realtime_session_id: None,
|
||||
transport: None,
|
||||
|
||||
@@ -96,6 +96,11 @@ pub struct ThreadRealtimeStartParams {
|
||||
/// Set to false to start without Codex's startup context. Omitted or null includes it.
|
||||
#[ts(optional = nullable)]
|
||||
pub include_startup_context: Option<bool>,
|
||||
/// Adds complete role-bearing text items to the initial Frameless Bidi session history.
|
||||
/// This is only supported by realtime V3 and is sent during session startup. Requests are
|
||||
/// limited to 128 items and 8,192 estimated text tokens in total.
|
||||
#[ts(optional = nullable)]
|
||||
pub initial_items: Option<Vec<ThreadRealtimeInitialItem>>,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "crate::protocol::serde_helpers::deserialize_double_option",
|
||||
@@ -115,6 +120,15 @@ pub struct ThreadRealtimeStartParams {
|
||||
pub voice: Option<RealtimeVoice>,
|
||||
}
|
||||
|
||||
/// EXPERIMENTAL - role-bearing text item included when a realtime V3 session starts.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct ThreadRealtimeInitialItem {
|
||||
pub role: ConversationTextRole,
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
/// EXPERIMENTAL - transport used by thread realtime.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(tag = "type", rename_all = "camelCase")]
|
||||
|
||||
@@ -4375,3 +4375,14 @@ fn realtime_append_text_defaults_role_to_user() {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn realtime_start_omitted_initial_items_remain_none() {
|
||||
let params = serde_json::from_value::<ThreadRealtimeStartParams>(json!({
|
||||
"threadId": "thread_123",
|
||||
"outputModality": "audio",
|
||||
}))
|
||||
.expect("params should deserialize");
|
||||
|
||||
assert_eq!(params.initial_items, None);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user