mirror of
https://github.com/openai/codex.git
synced 2026-11-30 15:39:17 +00:00
Add a realtime delegation acknowledgement control (#36413)
## What changed - Add the optional `delegationAckFiller` field to `thread/realtime/start`. - Forward explicit `true` or `false` values to V3 Frameless Bidi session payloads as `delegation.ack_filler`; leave the field absent when unspecified so the Realtime API default is preserved. - Document that V1 and V2 ignore this setting. ## Testing - Cover both boolean values in Frameless Bidi serialization and verify the WebRTC V3 session creation payload. GitOrigin-RevId: 9fe8efd14e42738c3e86e3e9a8af81d0f4521244
This commit is contained in:
1 parent
4c219fdb1a
commit
6751b54cae
21 files changed
+162
-7
No files matched your search
@@ -389,6 +389,7 @@ mod tests {
|
||||
RealtimeSessionConfig {
|
||||
instructions: "hi".to_string(),
|
||||
initial_items: Vec::new(),
|
||||
delegation_ack_filler: None,
|
||||
model: Some("gpt-realtime".to_string()),
|
||||
session_id: Some(session_id.to_string()),
|
||||
event_parser: RealtimeEventParser::V1,
|
||||
|
||||
@@ -384,6 +384,7 @@ impl RealtimeWebsocketWriter {
|
||||
session_mode: RealtimeSessionMode,
|
||||
output_modality: RealtimeOutputModality,
|
||||
voice: RealtimeVoice,
|
||||
delegation_ack_filler: Option<bool>,
|
||||
) -> Result<(), ApiError> {
|
||||
let session_mode = normalized_session_mode(self.event_parser, session_mode);
|
||||
let message = session_update_message(
|
||||
@@ -393,6 +394,7 @@ impl RealtimeWebsocketWriter {
|
||||
session_mode,
|
||||
output_modality,
|
||||
voice,
|
||||
delegation_ack_filler,
|
||||
);
|
||||
self.send_json(&message).await
|
||||
}
|
||||
@@ -868,6 +870,7 @@ impl RealtimeWebsocketClient {
|
||||
config.session_mode,
|
||||
config.output_modality,
|
||||
config.voice,
|
||||
config.delegation_ack_filler,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
@@ -2019,6 +2022,7 @@ mod tests {
|
||||
RealtimeSessionConfig {
|
||||
instructions: "backend prompt".to_string(),
|
||||
initial_items: Vec::new(),
|
||||
delegation_ack_filler: None,
|
||||
model: Some("realtime-test-model".to_string()),
|
||||
session_id: Some("conv_1".to_string()),
|
||||
event_parser: RealtimeEventParser::V1,
|
||||
@@ -2344,6 +2348,7 @@ mod tests {
|
||||
RealtimeSessionConfig {
|
||||
instructions: "backend prompt".to_string(),
|
||||
initial_items: Vec::new(),
|
||||
delegation_ack_filler: None,
|
||||
model: Some("realtime-test-model".to_string()),
|
||||
session_id: Some("conv_1".to_string()),
|
||||
event_parser: RealtimeEventParser::RealtimeV2,
|
||||
@@ -2470,6 +2475,7 @@ mod tests {
|
||||
RealtimeSessionConfig {
|
||||
instructions: "backend prompt".to_string(),
|
||||
initial_items: Vec::new(),
|
||||
delegation_ack_filler: None,
|
||||
model: Some("realtime-test-model".to_string()),
|
||||
session_id: Some("conv_1".to_string()),
|
||||
event_parser: RealtimeEventParser::RealtimeV2,
|
||||
@@ -2575,6 +2581,7 @@ mod tests {
|
||||
RealtimeSessionConfig {
|
||||
instructions: "backend prompt".to_string(),
|
||||
initial_items: Vec::new(),
|
||||
delegation_ack_filler: None,
|
||||
model: Some("realtime-test-model".to_string()),
|
||||
session_id: Some("conv_1".to_string()),
|
||||
event_parser: RealtimeEventParser::V1,
|
||||
@@ -2666,6 +2673,7 @@ mod tests {
|
||||
RealtimeSessionConfig {
|
||||
instructions: "backend prompt".to_string(),
|
||||
initial_items: Vec::new(),
|
||||
delegation_ack_filler: None,
|
||||
model: Some("realtime-test-model".to_string()),
|
||||
session_id: Some("conv_1".to_string()),
|
||||
event_parser: RealtimeEventParser::V1,
|
||||
|
||||
@@ -118,15 +118,19 @@ pub(super) fn session_update_message(
|
||||
session_mode: RealtimeSessionMode,
|
||||
output_modality: RealtimeOutputModality,
|
||||
voice: RealtimeVoice,
|
||||
delegation_ack_filler: Option<bool>,
|
||||
) -> RealtimeOutboundMessage {
|
||||
let session_mode = normalized_session_mode(wire_adapter, session_mode);
|
||||
match wire_adapter {
|
||||
RealtimeWireAdapter::V1 => RealtimeOutboundMessage::SessionUpdate {
|
||||
session: v1_session_update_session(instructions, voice),
|
||||
},
|
||||
RealtimeWireAdapter::FramelessBidi => {
|
||||
frameless_session_update_message(instructions, initial_items, voice)
|
||||
}
|
||||
RealtimeWireAdapter::FramelessBidi => frameless_session_update_message(
|
||||
instructions,
|
||||
initial_items,
|
||||
voice,
|
||||
delegation_ack_filler,
|
||||
),
|
||||
RealtimeWireAdapter::RealtimeV2 => RealtimeOutboundMessage::SessionUpdate {
|
||||
session: v2_session_update_session(instructions, session_mode, output_modality, voice),
|
||||
},
|
||||
@@ -157,6 +161,7 @@ pub fn session_update_session_json(config: RealtimeSessionConfig) -> JsonResult<
|
||||
config.instructions,
|
||||
config.initial_items,
|
||||
config.voice,
|
||||
config.delegation_ack_filler,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,51 @@
|
||||
use super::conversation_function_call_output_message;
|
||||
use super::conversation_handoff_append_message;
|
||||
use super::session_update_message;
|
||||
use super::standalone_handoff_message;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeContextAppendChannel;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeOutputModality;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeSessionMode;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeVoice;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeWireAdapter;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use serde_json::to_value;
|
||||
|
||||
#[test]
|
||||
fn frameless_session_update_encodes_explicit_delegation_ack_filler() {
|
||||
for delegation_ack_filler in [false, true] {
|
||||
let message = session_update_message(
|
||||
RealtimeWireAdapter::FramelessBidi,
|
||||
"instructions".to_string(),
|
||||
Vec::new(),
|
||||
RealtimeSessionMode::Conversational,
|
||||
RealtimeOutputModality::Audio,
|
||||
RealtimeVoice::Marin,
|
||||
Some(delegation_ack_filler),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
to_value(message).expect("frameless session update should serialize"),
|
||||
json!({
|
||||
"type": "session.update",
|
||||
"session": {
|
||||
"instructions": "instructions",
|
||||
"audio": {
|
||||
"output": {
|
||||
"voice": "marin",
|
||||
},
|
||||
},
|
||||
"delegation": {
|
||||
"type": "client",
|
||||
"ack_filler": delegation_ack_filler,
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn context_append_channel_only_encodes_for_frameless_handoff_output() {
|
||||
let legacy = conversation_handoff_append_message(
|
||||
|
||||
@@ -36,9 +36,16 @@ pub(super) fn session_update_message(
|
||||
instructions: String,
|
||||
initial_items: Vec<ConversationTextParams>,
|
||||
voice: RealtimeVoice,
|
||||
delegation_ack_filler: Option<bool>,
|
||||
) -> RealtimeOutboundMessage {
|
||||
RealtimeOutboundMessage::FramelessSessionUpdate {
|
||||
session: session_json(/*model*/ None, instructions, initial_items, voice),
|
||||
session: session_json(
|
||||
/*model*/ None,
|
||||
instructions,
|
||||
initial_items,
|
||||
voice,
|
||||
delegation_ack_filler,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +54,7 @@ pub(super) fn session_json(
|
||||
instructions: String,
|
||||
initial_items: Vec<ConversationTextParams>,
|
||||
voice: RealtimeVoice,
|
||||
delegation_ack_filler: Option<bool>,
|
||||
) -> Value {
|
||||
let mut session = json!({
|
||||
"instructions": instructions,
|
||||
@@ -62,6 +70,9 @@ pub(super) fn session_json(
|
||||
if let Some(model) = model {
|
||||
session["model"] = Value::String(model);
|
||||
}
|
||||
if let Some(delegation_ack_filler) = delegation_ack_filler {
|
||||
session["delegation"]["ack_filler"] = Value::Bool(delegation_ack_filler);
|
||||
}
|
||||
if !initial_items.is_empty() {
|
||||
session["initial_items"] = Value::Array(
|
||||
initial_items
|
||||
|
||||
@@ -27,6 +27,7 @@ fn session_json_omits_initial_items_when_empty() {
|
||||
"instructions".to_string(),
|
||||
Vec::new(),
|
||||
RealtimeVoice::Marin,
|
||||
/*delegation_ack_filler*/ None,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@@ -66,6 +67,7 @@ fn session_json_encodes_role_bearing_initial_items() {
|
||||
},
|
||||
],
|
||||
RealtimeVoice::Marin,
|
||||
/*delegation_ack_filler*/ None,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
|
||||
@@ -38,6 +38,7 @@ pub enum RealtimeContextAppendChannel {
|
||||
pub struct RealtimeSessionConfig {
|
||||
pub instructions: String,
|
||||
pub initial_items: Vec<ConversationTextParams>,
|
||||
pub delegation_ack_filler: Option<bool>,
|
||||
pub model: Option<String>,
|
||||
pub session_id: Option<String>,
|
||||
pub event_parser: RealtimeEventParser,
|
||||
|
||||
Reference in new issue
Block a user