mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
Use ChatGPT account preferences for Codex voice chat (#63810)
## Why Codex stored voice selections in `realtime.voice` and supplied voice overrides when starting realtime sessions. Reading and saving the ChatGPT account preference lets Codex use the same voice selection as ChatGPT. ## What changed - Add experimental `account/voiceSettings/read` and `account/voiceSettings/write` methods. The terminal voice picker shows the selected voice and available display names, then saves the chosen voice ID to the connected app server's ChatGPT account, including when the server is remote. - Require ChatGPT sign-in for terminal voice chat and create its WebRTC calls through the ChatGPT backend. - Remove voice overrides from realtime session startup. Existing `realtime.voice` entries still parse but are ignored. ## Testing Cover voice picker loading and saving, remote catalog failures, the ChatGPT sign-in requirement for local calls, and omission of voice overrides from realtime call payloads. GitOrigin-RevId: 9e6f30b8020c47701d3c1604075063924f191685
This commit is contained in:
@@ -3202,46 +3202,6 @@
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"RealtimeVoice": {
|
||||
"enum": [
|
||||
"alloy",
|
||||
"arbor",
|
||||
"ash",
|
||||
"aube",
|
||||
"ballad",
|
||||
"breeze",
|
||||
"bubbie",
|
||||
"cedar",
|
||||
"coral",
|
||||
"cove",
|
||||
"echo",
|
||||
"ember",
|
||||
"haetsal",
|
||||
"hanul",
|
||||
"himari",
|
||||
"juniper",
|
||||
"leher",
|
||||
"maple",
|
||||
"marin",
|
||||
"miko",
|
||||
"neer",
|
||||
"porto",
|
||||
"rindo",
|
||||
"rio",
|
||||
"rivage",
|
||||
"sage",
|
||||
"selva",
|
||||
"shimmer",
|
||||
"sol",
|
||||
"sonna",
|
||||
"spruce",
|
||||
"tinta",
|
||||
"vale",
|
||||
"verse",
|
||||
"viola"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ReasoningEffort": {
|
||||
"description": "A non-empty reasoning effort value advertised by the model.",
|
||||
"minLength": 1,
|
||||
|
||||
+15
@@ -7404,6 +7404,21 @@
|
||||
"title": "AccountUpdatedNotification",
|
||||
"type": "object"
|
||||
},
|
||||
"AccountVoiceOption": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"voice": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"voice"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ActivePermissionProfile": {
|
||||
"properties": {
|
||||
"extends": {
|
||||
|
||||
+15
@@ -394,6 +394,21 @@
|
||||
"title": "AccountUpdatedNotification",
|
||||
"type": "object"
|
||||
},
|
||||
"AccountVoiceOption": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"voice": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"voice"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ActivePermissionProfile": {
|
||||
"properties": {
|
||||
"extends": {
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type AccountVoiceOption = { voice: string, name: string, };
|
||||
@@ -13,6 +13,7 @@ export type { AccountTokenUsageDailyBucket } from "./AccountTokenUsageDailyBucke
|
||||
export type { AccountTokenUsageSummary } from "./AccountTokenUsageSummary";
|
||||
export type { AccountUpdateReason } from "./AccountUpdateReason";
|
||||
export type { AccountUpdatedNotification } from "./AccountUpdatedNotification";
|
||||
export type { AccountVoiceOption } from "./AccountVoiceOption";
|
||||
export type { ActivePermissionProfile } from "./ActivePermissionProfile";
|
||||
export type { AddCreditsNudgeCreditType } from "./AddCreditsNudgeCreditType";
|
||||
export type { AddCreditsNudgeEmailStatus } from "./AddCreditsNudgeEmailStatus";
|
||||
|
||||
@@ -1495,6 +1495,19 @@ client_request_definitions! {
|
||||
response: v2::GetAccountTokenUsageResponse,
|
||||
},
|
||||
|
||||
#[experimental("account/voiceSettings/read")]
|
||||
AccountVoiceSettingsRead => "account/voiceSettings/read" {
|
||||
params: #[ts(type = "undefined")] #[serde(skip_serializing_if = "Option::is_none")] Option<()>,
|
||||
serialization: None,
|
||||
response: v2::AccountVoiceSettingsReadResponse,
|
||||
},
|
||||
#[experimental("account/voiceSettings/write")]
|
||||
AccountVoiceSettingsWrite => "account/voiceSettings/write" {
|
||||
params: v2::AccountVoiceSettingsWriteParams,
|
||||
serialization: global("account-auth"),
|
||||
response: v2::AccountVoiceSettingsWriteResponse,
|
||||
},
|
||||
|
||||
GetWorkspaceMessages => "account/workspaceMessages/read" {
|
||||
params: #[ts(type = "undefined")] #[serde(skip_serializing_if = "Option::is_none")] Option<()>,
|
||||
serialization: None,
|
||||
@@ -2252,7 +2265,6 @@ mod tests {
|
||||
use codex_protocol::protocol::ConversationTextRole;
|
||||
use codex_protocol::protocol::RealtimeConversationVersion;
|
||||
use codex_protocol::protocol::RealtimeOutputModality;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_absolute_path::test_support::PathBufExt;
|
||||
use codex_utils_absolute_path::test_support::test_path_buf;
|
||||
@@ -4224,7 +4236,6 @@ mod tests {
|
||||
voice_session_id: Some("voice_789".to_string()),
|
||||
transport: None,
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
voice: Some(RealtimeVoice::Marin),
|
||||
},
|
||||
};
|
||||
assert_eq!(
|
||||
@@ -4263,8 +4274,7 @@ mod tests {
|
||||
"realtimeSessionId": "sess_456",
|
||||
"voiceSessionId": "voice_789",
|
||||
"transport": null,
|
||||
"version": "v3",
|
||||
"voice": "marin"
|
||||
"version": "v3"
|
||||
}
|
||||
}),
|
||||
serde_json::to_value(&request)?,
|
||||
@@ -4297,7 +4307,6 @@ mod tests {
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
},
|
||||
};
|
||||
assert_eq!(
|
||||
@@ -4322,8 +4331,7 @@ mod tests {
|
||||
"realtimeSessionId": null,
|
||||
"voiceSessionId": null,
|
||||
"transport": null,
|
||||
"version": null,
|
||||
"voice": null
|
||||
"version": null
|
||||
}
|
||||
}),
|
||||
serde_json::to_value(&default_prompt_request)?,
|
||||
@@ -4352,7 +4360,6 @@ mod tests {
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
},
|
||||
};
|
||||
assert_eq!(
|
||||
@@ -4378,8 +4385,7 @@ mod tests {
|
||||
"realtimeSessionId": null,
|
||||
"voiceSessionId": null,
|
||||
"transport": null,
|
||||
"version": null,
|
||||
"voice": null
|
||||
"version": null
|
||||
}
|
||||
}),
|
||||
serde_json::to_value(&null_prompt_request)?,
|
||||
@@ -4394,8 +4400,7 @@ mod tests {
|
||||
"codexResponseHandoffPrefix": "",
|
||||
"outputModality": "audio",
|
||||
"realtimeSessionId": null,
|
||||
"transport": null,
|
||||
"voice": null
|
||||
"transport": null
|
||||
}
|
||||
});
|
||||
assert_eq!(
|
||||
@@ -4411,8 +4416,7 @@ mod tests {
|
||||
"outputModality": "audio",
|
||||
"prompt": null,
|
||||
"realtimeSessionId": null,
|
||||
"transport": null,
|
||||
"voice": null
|
||||
"transport": null
|
||||
}
|
||||
});
|
||||
assert_eq!(
|
||||
|
||||
@@ -494,6 +494,34 @@ pub struct GetAccountTokenUsageResponse {
|
||||
pub thread_usage: Option<ThreadUsage>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct AccountVoiceSettingsReadResponse {
|
||||
pub selected: String,
|
||||
pub voices: Vec<AccountVoiceOption>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct AccountVoiceOption {
|
||||
pub voice: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct AccountVoiceSettingsWriteParams {
|
||||
pub voice: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct AccountVoiceSettingsWriteResponse {}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
|
||||
@@ -5,7 +5,6 @@ use codex_protocol::protocol::ConversationTextRole;
|
||||
use codex_protocol::protocol::RealtimeAudioFrame as CoreRealtimeAudioFrame;
|
||||
use codex_protocol::protocol::RealtimeConversationVersion;
|
||||
use codex_protocol::protocol::RealtimeOutputModality;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
use codex_protocol::protocol::RealtimeVoicesList;
|
||||
use codex_protocol::realtime::BemItemPresentation as CoreBemItemPresentation;
|
||||
use codex_protocol::realtime::RealtimeHandoffMode as CoreRealtimeHandoffMode;
|
||||
@@ -351,8 +350,7 @@ pub struct ThreadRealtimeStartParams {
|
||||
/// Overrides the configured realtime model for this session only.
|
||||
#[ts(optional = nullable)]
|
||||
pub model: Option<String>,
|
||||
/// Selects text or audio output for the realtime session. Transport and voice stay
|
||||
/// independent so clients can choose how they connect separately from what the model emits.
|
||||
/// Selects text or audio output for the realtime session.
|
||||
pub output_modality: RealtimeOutputModality,
|
||||
/// Set to false to start without Codex's startup context. Omitted or null includes it.
|
||||
#[ts(optional = nullable)]
|
||||
@@ -387,8 +385,6 @@ pub struct ThreadRealtimeStartParams {
|
||||
/// Overrides the configured realtime protocol version for this session only.
|
||||
#[ts(optional = nullable)]
|
||||
pub version: Option<RealtimeConversationVersion>,
|
||||
#[ts(optional = nullable)]
|
||||
pub voice: Option<RealtimeVoice>,
|
||||
}
|
||||
|
||||
/// EXPERIMENTAL - role-bearing text item included when a realtime V3 session starts.
|
||||
|
||||
@@ -692,6 +692,8 @@ return `null`. The ID belongs to the same account snapshot as the rest of the
|
||||
response. Clients should also accept an absent field from older app servers.
|
||||
PAT sessions continue to return no bearer token from `getAuthStatus`.
|
||||
|
||||
The experimental `account/voiceSettings/read` method returns the selected ChatGPT voice and the available voice IDs and display names. Pass an ID as `{ "voice": "juniper" }` to `account/voiceSettings/write` to save it. Both methods use the connected app-server's ChatGPT account, including when the client connects to a remote host.
|
||||
|
||||
# Selected workspace routing
|
||||
|
||||
`account/securitySetup/read` returns an optional backend-owned security reminder for the saved ChatGPT login. A returned notice includes its account and user IDs; clients must discard it after an account change and validate its copy and action URL before rendering. Ineligible, unavailable, and timed-out reads return `notice: null`. Older app-servers may not support this optional read.
|
||||
|
||||
@@ -2071,6 +2071,12 @@ impl MessageProcessor {
|
||||
ClientRequest::GetAccountTokenUsage { params, .. } => {
|
||||
self.account_processor.get_account_token_usage(params).await
|
||||
}
|
||||
ClientRequest::AccountVoiceSettingsRead { .. } => {
|
||||
self.account_processor.read_voice_settings().await
|
||||
}
|
||||
ClientRequest::AccountVoiceSettingsWrite { params, .. } => {
|
||||
self.account_processor.write_voice_settings(params).await
|
||||
}
|
||||
ClientRequest::GetWorkspaceMessages { .. } => {
|
||||
self.account_processor.get_workspace_messages().await
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ mod gateway_oauth;
|
||||
mod gcp_setup;
|
||||
mod rate_limit_resets;
|
||||
mod security_setup;
|
||||
mod voice_settings;
|
||||
mod workspace_routing;
|
||||
mod workspace_switching;
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
//! Read and save voice preferences with this app-server's ChatGPT account.
|
||||
|
||||
use super::*;
|
||||
use codex_app_server_protocol::AccountVoiceOption;
|
||||
use codex_app_server_protocol::AccountVoiceSettingsReadResponse;
|
||||
use codex_app_server_protocol::AccountVoiceSettingsWriteParams;
|
||||
use codex_app_server_protocol::AccountVoiceSettingsWriteResponse;
|
||||
|
||||
impl AccountRequestProcessor {
|
||||
async fn voice_settings_client(&self) -> Result<BackendClient, JSONRPCErrorError> {
|
||||
let (auth, factory) = self
|
||||
.auth_manager
|
||||
.auth_with_http_client_factory()
|
||||
.await
|
||||
.filter(|(auth, _)| auth.is_chatgpt_auth())
|
||||
.ok_or_else(|| invalid_request("ChatGPT authentication required for voice settings"))?;
|
||||
let config = self.load_latest_config().await;
|
||||
let url = config.chatgpt_backend_url();
|
||||
let root = url
|
||||
.resolve(&auth)
|
||||
.trim_end_matches('/')
|
||||
.trim_end_matches("/backend-api");
|
||||
let runtime = self
|
||||
.thread_manager
|
||||
.runtime_auth_for_config(&config)
|
||||
.map_err(|err| internal_error(err.to_string()))?;
|
||||
BackendClient::from_auth_with_runtime_without_redirects(
|
||||
format!("{root}/backend-api"),
|
||||
&auth,
|
||||
factory,
|
||||
runtime.as_ref(),
|
||||
&Default::default(),
|
||||
)
|
||||
.await
|
||||
.map_err(|err| internal_error(err.to_string()))
|
||||
}
|
||||
|
||||
pub(crate) async fn read_voice_settings(
|
||||
&self,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
let settings = self
|
||||
.voice_settings_client()
|
||||
.await?
|
||||
.get_voice_settings()
|
||||
.await
|
||||
.map_err(|err| internal_error(err.to_string()))?;
|
||||
let voices = settings
|
||||
.voices
|
||||
.into_iter()
|
||||
.map(|option| AccountVoiceOption {
|
||||
name: option.name.unwrap_or_else(|| option.voice.clone()),
|
||||
voice: option.voice,
|
||||
})
|
||||
.collect();
|
||||
Ok(Some(
|
||||
AccountVoiceSettingsReadResponse {
|
||||
selected: settings.selected,
|
||||
voices,
|
||||
}
|
||||
.into(),
|
||||
))
|
||||
}
|
||||
|
||||
pub(crate) async fn write_voice_settings(
|
||||
&self,
|
||||
params: AccountVoiceSettingsWriteParams,
|
||||
) -> Result<Option<ClientResponsePayload>, JSONRPCErrorError> {
|
||||
self.voice_settings_client()
|
||||
.await?
|
||||
.set_voice(¶ms.voice)
|
||||
.await
|
||||
.map_err(|err| internal_error(err.to_string()))?;
|
||||
Ok(Some(AccountVoiceSettingsWriteResponse {}.into()))
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@ use codex_protocol::models::FunctionCallOutputBody;
|
||||
use codex_protocol::models::FunctionCallOutputContentItem;
|
||||
use codex_protocol::models::FunctionCallOutputPayload;
|
||||
use codex_protocol::models::ImageReference as CoreImageReference;
|
||||
use codex_protocol::protocol::RealtimeConversationVersion;
|
||||
use codex_protocol::protocol::TurnEnvironmentRequests;
|
||||
use codex_protocol::protocol::TurnSettingsUpdate;
|
||||
use codex_protocol::protocol::TurnSettingsUpdateOutcome;
|
||||
@@ -1377,8 +1376,6 @@ impl TurnRequestProcessor {
|
||||
Some("initialItems")
|
||||
} else if params.model.is_some() {
|
||||
Some("model")
|
||||
} else if params.voice.is_some() {
|
||||
Some("voice")
|
||||
} else if params.delegation_ack_filler.is_some() {
|
||||
Some("delegationAckFiller")
|
||||
} else {
|
||||
@@ -1396,23 +1393,6 @@ impl TurnRequestProcessor {
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
let voice = match params.voice {
|
||||
Some(voice) => Some(Some(voice)),
|
||||
None if !attaches_existing_call
|
||||
&& params.version == Some(RealtimeConversationVersion::V3) =>
|
||||
{
|
||||
let current = thread.config().await;
|
||||
let latest = Box::pin(self.config_manager.load_latest_config_with_session_layers(
|
||||
¤t.config_layer_stack,
|
||||
¤t.cwd,
|
||||
))
|
||||
.await
|
||||
.map_err(|error| config_load_error(&error))?;
|
||||
// Preserve a cleared preference instead of inheriting the thread's old voice.
|
||||
Some(latest.realtime.voice)
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
self.submit_core_op(
|
||||
request_id,
|
||||
thread.as_ref(),
|
||||
@@ -1462,7 +1442,6 @@ impl TurnRequestProcessor {
|
||||
}
|
||||
}),
|
||||
version: params.version,
|
||||
voice,
|
||||
}),
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -154,7 +154,6 @@ async fn realtime_conversation_start_requires_experimental_api_capability() -> R
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
})
|
||||
.await?;
|
||||
let error = timeout(
|
||||
@@ -302,7 +301,6 @@ async fn realtime_webrtc_start_requires_experimental_api_capability() -> Result<
|
||||
sdp: "v=offer\r\n".to_string(),
|
||||
}),
|
||||
version: None,
|
||||
voice: None,
|
||||
})
|
||||
.await?;
|
||||
let error = timeout(
|
||||
|
||||
@@ -420,7 +420,6 @@ impl RealtimeE2eHarness {
|
||||
sdp: offer_sdp.to_string(),
|
||||
}),
|
||||
version: Some(version),
|
||||
voice: None,
|
||||
})
|
||||
.await?;
|
||||
let _: ThreadRealtimeStartResponse =
|
||||
@@ -481,7 +480,6 @@ impl RealtimeE2eHarness {
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
})
|
||||
.await?;
|
||||
let _: ThreadRealtimeStartResponse =
|
||||
@@ -520,7 +518,6 @@ impl RealtimeE2eHarness {
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
voice: None,
|
||||
})
|
||||
.await?;
|
||||
let _: ThreadRealtimeStartResponse =
|
||||
@@ -740,7 +737,6 @@ async fn realtime_conversation_streams_timeline_items() -> Result<()> {
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
})
|
||||
.await?;
|
||||
let _: ThreadRealtimeStartResponse =
|
||||
@@ -942,7 +938,6 @@ async fn realtime_conversation_streams_v2_notifications() -> Result<()> {
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: Some(RealtimeVoice::Cedar),
|
||||
})
|
||||
.await?;
|
||||
let _: ThreadRealtimeStartResponse =
|
||||
@@ -964,7 +959,7 @@ async fn realtime_conversation_streams_v2_notifications() -> Result<()> {
|
||||
);
|
||||
assert_eq!(
|
||||
startup_context_request.body_json()["session"]["audio"]["output"]["voice"],
|
||||
"cedar"
|
||||
"marin"
|
||||
);
|
||||
assert_eq!(
|
||||
realtime_server.single_handshake().uri(),
|
||||
@@ -1536,7 +1531,6 @@ async fn realtime_start_can_skip_startup_context() -> Result<()> {
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
})
|
||||
.await?;
|
||||
let _: ThreadRealtimeStartResponse =
|
||||
@@ -1635,7 +1629,6 @@ async fn realtime_text_output_modality_requests_text_output_and_final_transcript
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
})
|
||||
.await?;
|
||||
let _: ThreadRealtimeStartResponse =
|
||||
@@ -1854,7 +1847,6 @@ async fn realtime_conversation_stop_emits_closed_notification(
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: Some(RealtimeConversationVersion::V1),
|
||||
voice: None,
|
||||
})
|
||||
.await?;
|
||||
let _: ThreadRealtimeStartResponse =
|
||||
@@ -2063,7 +2055,6 @@ async fn realtime_mode_uses_client_instructions_on_entry_and_exit() -> Result<()
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
})
|
||||
.await?;
|
||||
let _: ThreadRealtimeStartResponse =
|
||||
@@ -2352,7 +2343,6 @@ async fn realtime_webrtc_start_emits_sdp_notification() -> Result<()> {
|
||||
sdp: "v=offer\r\n".to_string(),
|
||||
}),
|
||||
version: Some(RealtimeConversationVersion::V1),
|
||||
voice: None,
|
||||
})
|
||||
.await?;
|
||||
let _: ThreadRealtimeStartResponse =
|
||||
@@ -2580,7 +2570,6 @@ async fn existing_call_attaches_without_reinitializing_the_client_session(
|
||||
call_id: "rtc_existing".to_string(),
|
||||
}),
|
||||
version,
|
||||
voice: None,
|
||||
})
|
||||
.await?;
|
||||
let _: ThreadRealtimeStartResponse =
|
||||
@@ -2643,7 +2632,6 @@ async fn existing_call_attaches_without_reinitializing_the_client_session(
|
||||
#[test_case("prompt"; "rejects prompt")]
|
||||
#[test_case("initialItems"; "rejects initial items")]
|
||||
#[test_case("model"; "rejects model")]
|
||||
#[test_case("voice"; "rejects voice")]
|
||||
#[test_case("delegationAckFiller"; "rejects delegation acknowledgement filler")]
|
||||
#[tokio::test]
|
||||
async fn existing_call_rejects_client_owned_session_configuration(option: &str) -> Result<()> {
|
||||
@@ -2678,7 +2666,6 @@ async fn existing_call_rejects_client_owned_session_configuration(option: &str)
|
||||
call_id: "rtc_existing".to_string(),
|
||||
}),
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
voice: None,
|
||||
};
|
||||
match option {
|
||||
"includeStartupContext" => params.include_startup_context = Some(true),
|
||||
@@ -2690,7 +2677,6 @@ async fn existing_call_rejects_client_owned_session_configuration(option: &str)
|
||||
}]);
|
||||
}
|
||||
"model" => params.model = Some("another-model".to_string()),
|
||||
"voice" => params.voice = Some(RealtimeVoice::Cove),
|
||||
"delegationAckFiller" => params.delegation_ack_filler = Some(true),
|
||||
option => anyhow::bail!("unsupported test option: {option}"),
|
||||
}
|
||||
@@ -2762,7 +2748,7 @@ async fn webrtc_v3_start_posts_live_session_and_joins_without_session_update() -
|
||||
assert_call_create_multipart(
|
||||
harness.call_capture.single_request(),
|
||||
"v=offer\r\n",
|
||||
r#"{"audio":{"output":{"voice":"marin"}},"delegation":{"ack_filler":false,"type":"client"},"instructions":"backend prompt\n\nstartup context","model":"gpt-live-1.1-codex"}"#,
|
||||
r#"{"delegation":{"ack_filler":false,"type":"client"},"instructions":"backend prompt\n\nstartup context","model":"gpt-live-1.1-codex"}"#,
|
||||
"/v1/live",
|
||||
)?;
|
||||
assert!(
|
||||
@@ -2793,75 +2779,6 @@ async fn webrtc_v3_start_posts_live_session_and_joins_without_session_update() -
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(None, None, "marin"; "cleared setting uses API default")]
|
||||
#[test_case(Some("maple"), None, "maple"; "changed setting takes effect")]
|
||||
#[test_case(Some("maple"), Some("marin"), "marin"; "explicit voice overrides setting")]
|
||||
#[tokio::test]
|
||||
async fn webrtc_v3_uses_current_voice_setting(
|
||||
saved_voice: Option<&str>,
|
||||
requested_voice: Option<&str>,
|
||||
expected_voice: &str,
|
||||
) -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let mut harness = RealtimeE2eHarness::new(
|
||||
RealtimeTestVersion::V1,
|
||||
no_main_loop_responses(),
|
||||
realtime_sideband(vec![open_realtime_sideband_connection(vec![vec![]])]),
|
||||
)
|
||||
.await?;
|
||||
let config_path = harness._codex_home.path().join("config.toml");
|
||||
let original_config = std::fs::read_to_string(&config_path)?;
|
||||
std::fs::write(
|
||||
&config_path,
|
||||
original_config.replace("[realtime]", "[realtime]\nvoice = \"cove\""),
|
||||
)?;
|
||||
let request_id = harness
|
||||
.mcp
|
||||
.send_thread_start_request_with_auto_env(ThreadStartParams::default())
|
||||
.await?;
|
||||
let thread: ThreadStartResponse =
|
||||
timeout(DEFAULT_TIMEOUT, harness.mcp.read_response(request_id)).await??;
|
||||
|
||||
// The thread retains Cove. The next call must use the current setting, including removal.
|
||||
let updated_config = match saved_voice {
|
||||
Some(voice) => {
|
||||
original_config.replace("[realtime]", &format!("[realtime]\nvoice = {voice:?}"))
|
||||
}
|
||||
None => original_config,
|
||||
};
|
||||
std::fs::write(config_path, updated_config)?;
|
||||
let request_id = harness
|
||||
.mcp
|
||||
.send_thread_realtime_start_request(serde_json::from_value(json!({
|
||||
"threadId": thread.thread.id,
|
||||
"version": "v3",
|
||||
"transport": {"type": "webrtc", "sdp": "v=offer\r\n"},
|
||||
"outputModality": "audio",
|
||||
"includeStartupContext": false,
|
||||
"prompt": "voice selection test",
|
||||
"voice": requested_voice,
|
||||
}))?)
|
||||
.await?;
|
||||
let _: ThreadRealtimeStartResponse =
|
||||
timeout(DEFAULT_TIMEOUT, harness.mcp.read_response(request_id)).await??;
|
||||
let _: ThreadRealtimeSdpNotification = harness.read_notification("thread/realtime/sdp").await?;
|
||||
assert_call_create_multipart(
|
||||
harness.call_capture.single_request(),
|
||||
"v=offer\r\n",
|
||||
&json!({
|
||||
"audio": {"output": {"voice": expected_voice}},
|
||||
"delegation": {"type": "client"},
|
||||
"instructions": "backend prompt",
|
||||
"model": "gpt-live-1.1-codex",
|
||||
})
|
||||
.to_string(),
|
||||
"/v1/live",
|
||||
)?;
|
||||
harness.shutdown().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn webrtc_v1_default_automatic_output_uses_handoff_append() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
@@ -4308,7 +4225,6 @@ async fn realtime_webrtc_start_surfaces_backend_error() -> Result<()> {
|
||||
sdp: "v=offer\r\n".to_string(),
|
||||
}),
|
||||
version: Some(RealtimeConversationVersion::V1),
|
||||
voice: None,
|
||||
})
|
||||
.await?;
|
||||
let _: ThreadRealtimeStartResponse =
|
||||
@@ -4845,7 +4761,6 @@ async fn realtime_requests_use_runtime_auth(transport: &str, mode: &str) -> Resu
|
||||
} else {
|
||||
RealtimeConversationVersion::V2
|
||||
}),
|
||||
voice: None,
|
||||
})
|
||||
.await?;
|
||||
let _: ThreadRealtimeStartResponse =
|
||||
|
||||
@@ -15,6 +15,8 @@ use codex_features::RuntimeAuthMode;
|
||||
use codex_http_client::CHATGPT_ACCOUNT_ID_HEADER;
|
||||
use codex_http_client::ClientRouteClass;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::HttpError;
|
||||
use codex_http_client::HttpResponse;
|
||||
use codex_http_client::OutboundProxyPolicy;
|
||||
use codex_http_client::RequestBuilder;
|
||||
use codex_http_client::RouteAwareClientPool;
|
||||
@@ -559,6 +561,41 @@ impl Client {
|
||||
Ok(self.get_rate_limits_with_reset_credits().await?.rate_limits)
|
||||
}
|
||||
|
||||
pub async fn get_voice_settings(&self) -> Result<crate::VoiceSettings> {
|
||||
let response = self
|
||||
.voice_settings_request(Method::GET, "settings/voices", &[("voice_mode", "wingman")])
|
||||
.await?;
|
||||
Ok(response.json().await.map_err(HttpError::without_url)?)
|
||||
}
|
||||
|
||||
pub async fn set_voice(&self, voice: &str) -> Result<()> {
|
||||
self.voice_settings_request(
|
||||
Method::PATCH,
|
||||
"settings/account_user_setting",
|
||||
&[("feature", "voice_name"), ("value", voice)],
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn voice_settings_request(
|
||||
&self,
|
||||
method: Method,
|
||||
path: &str,
|
||||
query: &[(&str, &str)],
|
||||
) -> Result<HttpResponse> {
|
||||
let url = format!("{}/{path}", self.base_url);
|
||||
let request = self
|
||||
.request(method, &url)
|
||||
.headers(self.headers().await?)
|
||||
.query(query);
|
||||
self.auth.validate_destination(&self.base_url, &url)?;
|
||||
let response = request.send().await.map_err(HttpError::without_url)?;
|
||||
let status = response.status();
|
||||
anyhow::ensure!(status.is_success(), "HTTP {status}");
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub async fn get_accounts_check(
|
||||
&self,
|
||||
) -> std::result::Result<AccountsCheckResponse, RequestError> {
|
||||
|
||||
@@ -48,6 +48,8 @@ pub use types::TokenUsageProfile;
|
||||
pub use types::TokenUsageProfileDailyBucket;
|
||||
pub use types::TokenUsageProfileStats;
|
||||
pub use types::TurnAttemptsSiblingTurnsResponse;
|
||||
pub use types::VoiceOption;
|
||||
pub use types::VoiceSettings;
|
||||
|
||||
pub use client::plan_history::PlanLimitBreakdown;
|
||||
pub use client::plan_history::PlanLimitDimension;
|
||||
|
||||
@@ -90,6 +90,18 @@ pub struct CodexUserSettingsResponse {
|
||||
pub commit_attribution_enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct VoiceSettings {
|
||||
pub selected: String,
|
||||
pub voices: Vec<VoiceOption>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct VoiceOption {
|
||||
pub voice: String,
|
||||
pub name: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
|
||||
pub struct CodexWorkspaceMessage {
|
||||
pub message_id: String,
|
||||
|
||||
@@ -10,7 +10,6 @@ use codex_client::HttpTransport;
|
||||
use codex_client::Request;
|
||||
use codex_client::RequestBody;
|
||||
use codex_client::RequestTelemetry;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
use http::HeaderMap;
|
||||
use http::HeaderValue;
|
||||
use http::Method;
|
||||
@@ -130,7 +129,7 @@ impl<T: HttpTransport> RealtimeCallClient<T> {
|
||||
pub async fn create_with_session_and_headers(
|
||||
&self,
|
||||
sdp: String,
|
||||
mut session_config: RealtimeSessionConfig,
|
||||
session_config: RealtimeSessionConfig,
|
||||
extra_headers: HeaderMap,
|
||||
) -> Result<RealtimeCallResponse, ApiError> {
|
||||
trace!(target: "codex_api::realtime_websocket::wire", "realtime call request SDP: {sdp}");
|
||||
@@ -138,10 +137,6 @@ impl<T: HttpTransport> RealtimeCallClient<T> {
|
||||
// session payload is sent with call creation. Legacy sidebands still send session.update
|
||||
// after joining; Frameless sidebands attach to the session that is already running.
|
||||
validate_avas_session_config(&session_config)?;
|
||||
if self.uses_backend_request_shape() {
|
||||
// ChatGPT keeps its own default; API calls use the wire adapter's default.
|
||||
session_config.voice.get_or_insert(RealtimeVoice::Cove);
|
||||
}
|
||||
let event_parser = session_config.event_parser;
|
||||
let path = self.path_for_session(event_parser);
|
||||
let mut session = realtime_session_json(session_config)?;
|
||||
@@ -312,7 +307,6 @@ mod tests {
|
||||
use codex_client::TransportError;
|
||||
use codex_protocol::protocol::ConversationTextParams;
|
||||
use codex_protocol::protocol::ConversationTextRole;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
use http::StatusCode;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::sync::Mutex;
|
||||
@@ -401,14 +395,12 @@ mod tests {
|
||||
event_parser: RealtimeEventParser::V1,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Cove),
|
||||
}
|
||||
}
|
||||
|
||||
fn realtime_v2_session_config(session_id: &str) -> RealtimeSessionConfig {
|
||||
RealtimeSessionConfig {
|
||||
event_parser: RealtimeEventParser::RealtimeV2,
|
||||
voice: Some(RealtimeVoice::Marin),
|
||||
..realtime_session_config(session_id)
|
||||
}
|
||||
}
|
||||
@@ -564,38 +556,37 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn sends_frameless_session_call_to_live_without_legacy_query_params() {
|
||||
for (voice, expected_voice) in [
|
||||
(None, "marin"),
|
||||
(Some(RealtimeVoice::Marin), "marin"),
|
||||
(Some(RealtimeVoice::Cove), "cove"),
|
||||
] {
|
||||
let transport = CapturingTransport::with_location("/v1/live/rtc_frameless");
|
||||
let client = RealtimeCallClient::new(
|
||||
transport.clone(),
|
||||
provider("https://api.openai.com/v1"),
|
||||
Arc::new(DummyAuth),
|
||||
);
|
||||
let transport = CapturingTransport::with_location("/v1/live/rtc_frameless");
|
||||
let client = RealtimeCallClient::new(
|
||||
transport.clone(),
|
||||
provider("https://api.openai.com/v1"),
|
||||
Arc::new(DummyAuth),
|
||||
);
|
||||
|
||||
let mut session_config = frameless_bidi_session_config("sess-api");
|
||||
session_config.voice = voice;
|
||||
let response = client
|
||||
.create_with_session("v=offer\r\n".to_string(), session_config)
|
||||
.await
|
||||
.expect("request should succeed");
|
||||
let session_config = frameless_bidi_session_config("sess-api");
|
||||
let response = client
|
||||
.create_with_session("v=offer\r\n".to_string(), session_config)
|
||||
.await
|
||||
.expect("request should succeed");
|
||||
|
||||
assert_eq!(response.call_id, "rtc_frameless");
|
||||
let request = transport.last_request.lock().unwrap().clone().unwrap();
|
||||
assert_eq!(request.method, Method::POST);
|
||||
assert_eq!(request.url, "https://api.openai.com/v1/live");
|
||||
let Some(RequestBody::Raw(body)) = request.body else {
|
||||
panic!("multipart body should be raw");
|
||||
};
|
||||
let body = std::str::from_utf8(&body).expect("multipart body should be utf-8");
|
||||
assert!(body.contains("\"model\":\"gpt-realtime\""));
|
||||
assert!(body.contains("\"delegation\":{\"type\":\"client\"}"));
|
||||
assert!(!body.contains("\"id\":\"sess-api\""));
|
||||
assert!(body.contains(&format!("\"voice\":\"{expected_voice}\"")));
|
||||
}
|
||||
assert_eq!(response.call_id, "rtc_frameless");
|
||||
let request = transport.last_request.lock().unwrap().clone().unwrap();
|
||||
assert_eq!(request.method, Method::POST);
|
||||
assert_eq!(request.url, "https://api.openai.com/v1/live");
|
||||
let Some(RequestBody::Raw(body)) = request.body else {
|
||||
panic!("multipart body should be raw");
|
||||
};
|
||||
let body = std::str::from_utf8(&body).expect("multipart body should be utf-8");
|
||||
assert!(body.contains("\"model\":\"gpt-realtime\""));
|
||||
assert!(body.contains("\"delegation\":{\"type\":\"client\"}"));
|
||||
assert!(!body.contains("\"id\":\"sess-api\""));
|
||||
let session: Value = serde_json::from_str(
|
||||
body.lines()
|
||||
.find(|line| line.starts_with('{'))
|
||||
.expect("multipart body should contain session JSON"),
|
||||
)
|
||||
.expect("session should be JSON");
|
||||
assert!(session.pointer("/audio/output/voice").is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -707,60 +698,57 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn sends_backend_frameless_session_call_to_realtime_calls() {
|
||||
for (voice, expected_voice) in [(None, "cove"), (Some(RealtimeVoice::Maple), "maple")] {
|
||||
let transport = CapturingTransport::with_location("/v1/live/rtc_backend_frameless");
|
||||
let client = RealtimeCallClient::new(
|
||||
transport.clone(),
|
||||
provider("https://chatgpt.com/backend-api/codex"),
|
||||
Arc::new(DummyAuth),
|
||||
);
|
||||
let mut session_config = frameless_bidi_session_config("sess-backend");
|
||||
session_config.voice = voice;
|
||||
session_config.initial_items = vec![
|
||||
ConversationTextParams {
|
||||
text: "Remember this.".to_string(),
|
||||
role: ConversationTextRole::Developer,
|
||||
},
|
||||
ConversationTextParams {
|
||||
text: "Understood.".to_string(),
|
||||
role: ConversationTextRole::Assistant,
|
||||
},
|
||||
];
|
||||
let transport = CapturingTransport::with_location("/v1/live/rtc_backend_frameless");
|
||||
let client = RealtimeCallClient::new(
|
||||
transport.clone(),
|
||||
provider("https://chatgpt.com/backend-api/codex"),
|
||||
Arc::new(DummyAuth),
|
||||
);
|
||||
let mut session_config = frameless_bidi_session_config("sess-backend");
|
||||
session_config.initial_items = vec![
|
||||
ConversationTextParams {
|
||||
text: "Remember this.".to_string(),
|
||||
role: ConversationTextRole::Developer,
|
||||
},
|
||||
ConversationTextParams {
|
||||
text: "Understood.".to_string(),
|
||||
role: ConversationTextRole::Assistant,
|
||||
},
|
||||
];
|
||||
|
||||
let response = client
|
||||
.create_with_session("v=offer\r\n".to_string(), session_config)
|
||||
.await
|
||||
.expect("request should succeed");
|
||||
let response = client
|
||||
.create_with_session("v=offer\r\n".to_string(), session_config)
|
||||
.await
|
||||
.expect("request should succeed");
|
||||
|
||||
assert_eq!(response.call_id, "rtc_backend_frameless");
|
||||
let request = transport.last_request.lock().unwrap().clone().unwrap();
|
||||
assert_eq!(request.method, Method::POST);
|
||||
assert_eq!(
|
||||
request.url,
|
||||
"https://chatgpt.com/backend-api/codex/realtime/calls?intent=quicksilver&architecture=avas"
|
||||
);
|
||||
let Some(RequestBody::Json(body)) = request.body else {
|
||||
panic!("backend request body should be JSON");
|
||||
};
|
||||
assert_eq!(body["session"]["delegation"]["type"], "client");
|
||||
assert_eq!(body["session"]["audio"]["output"]["voice"], expected_voice);
|
||||
assert!(body["session"].get("id").is_none());
|
||||
assert_eq!(
|
||||
body["session"]["initial_items"],
|
||||
serde_json::json!([
|
||||
{
|
||||
"type": "message",
|
||||
"role": "developer",
|
||||
"content": [{"type": "input_text", "text": "Remember this."}],
|
||||
},
|
||||
{
|
||||
"type": "message",
|
||||
"role": "assistant",
|
||||
"content": [{"type": "output_text", "text": "Understood."}],
|
||||
},
|
||||
])
|
||||
);
|
||||
}
|
||||
assert_eq!(response.call_id, "rtc_backend_frameless");
|
||||
let request = transport.last_request.lock().unwrap().clone().unwrap();
|
||||
assert_eq!(request.method, Method::POST);
|
||||
assert_eq!(
|
||||
request.url,
|
||||
"https://chatgpt.com/backend-api/codex/realtime/calls?intent=quicksilver&architecture=avas"
|
||||
);
|
||||
let Some(RequestBody::Json(body)) = request.body else {
|
||||
panic!("backend request body should be JSON");
|
||||
};
|
||||
assert_eq!(body["session"]["delegation"]["type"], "client");
|
||||
assert!(body.pointer("/session/audio/output/voice").is_none());
|
||||
assert!(body["session"].get("id").is_none());
|
||||
assert_eq!(
|
||||
body["session"]["initial_items"],
|
||||
serde_json::json!([
|
||||
{
|
||||
"type": "message",
|
||||
"role": "developer",
|
||||
"content": [{"type": "input_text", "text": "Remember this."}],
|
||||
},
|
||||
{
|
||||
"type": "message",
|
||||
"role": "assistant",
|
||||
"content": [{"type": "output_text", "text": "Understood."}],
|
||||
},
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -17,7 +17,6 @@ use crate::endpoint::realtime_websocket::protocol::RealtimeOutputModality;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeSessionConfig;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeSessionMode;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeTranscriptEntry;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeVoice;
|
||||
use crate::endpoint::realtime_websocket::protocol::parse_realtime_event;
|
||||
use crate::error::ApiError;
|
||||
use crate::provider::Provider;
|
||||
@@ -438,7 +437,6 @@ impl RealtimeWebsocketWriter {
|
||||
initial_items: Vec<ConversationTextParams>,
|
||||
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);
|
||||
@@ -448,7 +446,6 @@ impl RealtimeWebsocketWriter {
|
||||
initial_items,
|
||||
session_mode,
|
||||
output_modality,
|
||||
voice,
|
||||
delegation_ack_filler,
|
||||
);
|
||||
self.send_json(&message).await
|
||||
@@ -1154,7 +1151,6 @@ impl RealtimeWebsocketClient {
|
||||
RealtimeSessionInitialization::ExistingCall => false,
|
||||
};
|
||||
if initialize_session {
|
||||
let voice = config.voice_or_default();
|
||||
debug!(
|
||||
session_id = config.session_id.as_deref().unwrap_or("<none>"),
|
||||
"realtime websocket sending session.update"
|
||||
@@ -1166,7 +1162,6 @@ impl RealtimeWebsocketClient {
|
||||
config.initial_items,
|
||||
config.session_mode,
|
||||
config.output_modality,
|
||||
voice,
|
||||
config.delegation_ack_filler,
|
||||
)
|
||||
.await?;
|
||||
@@ -1383,7 +1378,6 @@ mod tests {
|
||||
use codex_protocol::protocol::RealtimeResponseDone;
|
||||
use codex_protocol::protocol::RealtimeTranscriptDelta;
|
||||
use codex_protocol::protocol::RealtimeTranscriptDone;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
use http::HeaderValue;
|
||||
use http::StatusCode;
|
||||
use pretty_assertions::assert_eq;
|
||||
@@ -2431,7 +2425,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
first_json["session"]["audio"]["output"]["voice"],
|
||||
Value::String("breeze".to_string())
|
||||
Value::String("cove".to_string())
|
||||
);
|
||||
|
||||
ws.send(Message::Text(
|
||||
@@ -2591,7 +2585,6 @@ mod tests {
|
||||
event_parser: RealtimeEventParser::V1,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Breeze),
|
||||
},
|
||||
HeaderMap::new(),
|
||||
HeaderMap::new(),
|
||||
@@ -2784,7 +2777,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
first_json["session"]["audio"]["output"]["voice"],
|
||||
Value::String("cedar".to_string())
|
||||
Value::String("marin".to_string())
|
||||
);
|
||||
assert_eq!(
|
||||
first_json["session"]["tools"][0]["type"],
|
||||
@@ -2917,7 +2910,6 @@ mod tests {
|
||||
event_parser: RealtimeEventParser::RealtimeV2,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Cedar),
|
||||
},
|
||||
HeaderMap::new(),
|
||||
HeaderMap::new(),
|
||||
@@ -3044,7 +3036,6 @@ mod tests {
|
||||
event_parser: RealtimeEventParser::RealtimeV2,
|
||||
session_mode: RealtimeSessionMode::Transcription,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Marin),
|
||||
},
|
||||
HeaderMap::new(),
|
||||
HeaderMap::new(),
|
||||
@@ -3150,7 +3141,6 @@ mod tests {
|
||||
event_parser: RealtimeEventParser::V1,
|
||||
session_mode: RealtimeSessionMode::Transcription,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Cove),
|
||||
},
|
||||
HeaderMap::new(),
|
||||
HeaderMap::new(),
|
||||
@@ -3242,7 +3232,6 @@ mod tests {
|
||||
event_parser: RealtimeEventParser::V1,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Cove),
|
||||
},
|
||||
HeaderMap::new(),
|
||||
HeaderMap::new(),
|
||||
|
||||
@@ -70,7 +70,6 @@ fn session() -> RealtimeSessionConfig {
|
||||
event_parser: RealtimeEventParser::V1,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Cedar),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ use crate::endpoint::realtime_websocket::protocol::RealtimeOutboundMessage;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeOutputModality;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeSessionConfig;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeSessionMode;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeVoice;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeWireAdapter;
|
||||
use codex_protocol::protocol::ConversationTextParams;
|
||||
use codex_protocol::protocol::ConversationTextRole;
|
||||
@@ -117,37 +116,31 @@ pub(super) fn session_update_message(
|
||||
initial_items: Vec<ConversationTextParams>,
|
||||
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),
|
||||
session: v1_session_update_session(instructions),
|
||||
},
|
||||
RealtimeWireAdapter::FramelessBidi => frameless_session_update_message(
|
||||
instructions,
|
||||
initial_items,
|
||||
voice,
|
||||
delegation_ack_filler,
|
||||
),
|
||||
RealtimeWireAdapter::FramelessBidi => {
|
||||
frameless_session_update_message(instructions, initial_items, delegation_ack_filler)
|
||||
}
|
||||
RealtimeWireAdapter::RealtimeV2 => RealtimeOutboundMessage::SessionUpdate {
|
||||
session: v2_session_update_session(instructions, session_mode, output_modality, voice),
|
||||
session: v2_session_update_session(instructions, session_mode, output_modality),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn session_update_session_json(config: RealtimeSessionConfig) -> JsonResult<Value> {
|
||||
let voice = config.voice_or_default();
|
||||
match config.event_parser {
|
||||
RealtimeWireAdapter::V1 | RealtimeWireAdapter::RealtimeV2 => {
|
||||
let mut session = match config.event_parser {
|
||||
RealtimeWireAdapter::V1 => v1_session_update_session(config.instructions, voice),
|
||||
RealtimeWireAdapter::V1 => v1_session_update_session(config.instructions),
|
||||
RealtimeWireAdapter::RealtimeV2 => v2_session_update_session(
|
||||
config.instructions,
|
||||
config.session_mode,
|
||||
config.output_modality,
|
||||
voice,
|
||||
),
|
||||
RealtimeWireAdapter::FramelessBidi => unreachable!(),
|
||||
};
|
||||
@@ -159,7 +152,6 @@ pub fn session_update_session_json(config: RealtimeSessionConfig) -> JsonResult<
|
||||
config.model,
|
||||
config.instructions,
|
||||
config.initial_items,
|
||||
voice,
|
||||
config.delegation_ack_filler,
|
||||
)),
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ 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;
|
||||
@@ -21,7 +20,6 @@ fn frameless_session_update_encodes_explicit_delegation_ack_filler() {
|
||||
Vec::new(),
|
||||
RealtimeSessionMode::Conversational,
|
||||
RealtimeOutputModality::Audio,
|
||||
RealtimeVoice::Marin,
|
||||
Some(delegation_ack_filler),
|
||||
);
|
||||
|
||||
@@ -31,11 +29,6 @@ fn frameless_session_update_encodes_explicit_delegation_ack_filler() {
|
||||
"type": "session.update",
|
||||
"session": {
|
||||
"instructions": "instructions",
|
||||
"audio": {
|
||||
"output": {
|
||||
"voice": "marin",
|
||||
},
|
||||
},
|
||||
"delegation": {
|
||||
"type": "client",
|
||||
"ack_filler": delegation_ack_filler,
|
||||
|
||||
@@ -2,7 +2,6 @@ use crate::endpoint::realtime_websocket::protocol::FramelessContentType;
|
||||
use crate::endpoint::realtime_websocket::protocol::FramelessInputTextContent;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeContextAppendChannel;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeOutboundMessage;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeVoice;
|
||||
use codex_protocol::protocol::ConversationTextParams;
|
||||
use codex_protocol::protocol::ConversationTextRole;
|
||||
use serde_json::Value;
|
||||
@@ -35,7 +34,6 @@ pub(super) fn session_context_append_message(
|
||||
pub(super) fn session_update_message(
|
||||
instructions: String,
|
||||
initial_items: Vec<ConversationTextParams>,
|
||||
voice: RealtimeVoice,
|
||||
delegation_ack_filler: Option<bool>,
|
||||
) -> RealtimeOutboundMessage {
|
||||
RealtimeOutboundMessage::FramelessSessionUpdate {
|
||||
@@ -43,7 +41,6 @@ pub(super) fn session_update_message(
|
||||
/*model*/ None,
|
||||
instructions,
|
||||
initial_items,
|
||||
voice,
|
||||
delegation_ack_filler,
|
||||
),
|
||||
}
|
||||
@@ -53,19 +50,11 @@ pub(super) fn session_json(
|
||||
model: Option<String>,
|
||||
instructions: String,
|
||||
initial_items: Vec<ConversationTextParams>,
|
||||
voice: RealtimeVoice,
|
||||
delegation_ack_filler: Option<bool>,
|
||||
) -> Value {
|
||||
let mut session = json!({
|
||||
"instructions": instructions,
|
||||
"audio": {
|
||||
"output": {
|
||||
"voice": voice,
|
||||
},
|
||||
},
|
||||
"delegation": {
|
||||
"type": "client",
|
||||
},
|
||||
"delegation": { "type": "client" },
|
||||
});
|
||||
if let Some(model) = model {
|
||||
session["model"] = Value::String(model);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use super::CONTEXT_APPEND_MAX_BYTES;
|
||||
use super::context_append_chunks;
|
||||
use super::session_json;
|
||||
use crate::endpoint::realtime_websocket::protocol::RealtimeVoice;
|
||||
use codex_protocol::protocol::ConversationTextParams;
|
||||
use codex_protocol::protocol::ConversationTextRole;
|
||||
use pretty_assertions::assert_eq;
|
||||
@@ -26,7 +25,6 @@ fn session_json_omits_initial_items_when_empty() {
|
||||
Some("gpt-live".to_string()),
|
||||
"instructions".to_string(),
|
||||
Vec::new(),
|
||||
RealtimeVoice::Marin,
|
||||
/*delegation_ack_filler*/ None,
|
||||
);
|
||||
|
||||
@@ -35,11 +33,6 @@ fn session_json_omits_initial_items_when_empty() {
|
||||
json!({
|
||||
"model": "gpt-live",
|
||||
"instructions": "instructions",
|
||||
"audio": {
|
||||
"output": {
|
||||
"voice": "marin",
|
||||
},
|
||||
},
|
||||
"delegation": {
|
||||
"type": "client",
|
||||
},
|
||||
@@ -66,7 +59,6 @@ fn session_json_encodes_role_bearing_initial_items() {
|
||||
role: ConversationTextRole::Assistant,
|
||||
},
|
||||
],
|
||||
RealtimeVoice::Marin,
|
||||
/*delegation_ack_filler*/ None,
|
||||
);
|
||||
|
||||
|
||||
@@ -48,10 +48,7 @@ pub(super) fn conversation_handoff_append_message(
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn session_update_session(
|
||||
instructions: String,
|
||||
voice: RealtimeVoice,
|
||||
) -> SessionUpdateSession {
|
||||
pub(super) fn session_update_session(instructions: String) -> SessionUpdateSession {
|
||||
SessionUpdateSession {
|
||||
id: None,
|
||||
r#type: SessionType::Quicksilver,
|
||||
@@ -70,7 +67,7 @@ pub(super) fn session_update_session(
|
||||
},
|
||||
output: Some(SessionAudioOutput {
|
||||
format: None,
|
||||
voice,
|
||||
voice: RealtimeVoice::Cove,
|
||||
}),
|
||||
},
|
||||
tools: None,
|
||||
|
||||
@@ -76,7 +76,6 @@ pub(super) fn session_update_session(
|
||||
instructions: String,
|
||||
session_mode: RealtimeSessionMode,
|
||||
output_modality: RealtimeOutputModality,
|
||||
voice: RealtimeVoice,
|
||||
) -> SessionUpdateSession {
|
||||
match session_mode {
|
||||
RealtimeSessionMode::Conversational => SessionUpdateSession {
|
||||
@@ -109,7 +108,7 @@ pub(super) fn session_update_session(
|
||||
r#type: AudioFormatType::AudioPcm,
|
||||
rate: REALTIME_AUDIO_SAMPLE_RATE,
|
||||
}),
|
||||
voice,
|
||||
voice: RealtimeVoice::Marin,
|
||||
}),
|
||||
},
|
||||
tools: Some(vec![
|
||||
|
||||
@@ -44,19 +44,6 @@ pub struct RealtimeSessionConfig {
|
||||
pub event_parser: RealtimeEventParser,
|
||||
pub session_mode: RealtimeSessionMode,
|
||||
pub output_modality: RealtimeOutputModality,
|
||||
/// Leave unset to select the default for the API or ChatGPT call destination.
|
||||
pub voice: Option<RealtimeVoice>,
|
||||
}
|
||||
|
||||
impl RealtimeSessionConfig {
|
||||
pub(super) fn voice_or_default(&self) -> RealtimeVoice {
|
||||
self.voice.unwrap_or(match self.event_parser {
|
||||
RealtimeEventParser::V1 => RealtimeVoice::Cove,
|
||||
RealtimeEventParser::FramelessBidi | RealtimeEventParser::RealtimeV2 => {
|
||||
RealtimeVoice::Marin
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
||||
@@ -20,7 +20,6 @@ use codex_protocol::protocol::RealtimeHandoffRequested;
|
||||
use codex_protocol::protocol::RealtimeTranscriptDelta;
|
||||
use codex_protocol::protocol::RealtimeTranscriptDone;
|
||||
use codex_protocol::protocol::RealtimeTranscriptEntry;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
use futures::SinkExt;
|
||||
use futures::StreamExt;
|
||||
use http::HeaderMap;
|
||||
@@ -162,7 +161,6 @@ async fn realtime_ws_e2e_session_create_and_event_flow() {
|
||||
event_parser: RealtimeEventParser::V1,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Cove),
|
||||
},
|
||||
HeaderMap::new(),
|
||||
HeaderMap::new(),
|
||||
@@ -268,7 +266,6 @@ async fn realtime_ws_connect_webrtc_sideband_retries_join_until_server_is_availa
|
||||
event_parser: RealtimeEventParser::RealtimeV2,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Marin),
|
||||
},
|
||||
"rtc_test",
|
||||
HeaderMap::new(),
|
||||
@@ -349,7 +346,6 @@ async fn realtime_ws_existing_call_retries_activation_404_with_a_bounded_budget(
|
||||
event_parser: RealtimeEventParser::RealtimeV2,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Marin),
|
||||
},
|
||||
"rtc_prepared",
|
||||
HeaderMap::new(),
|
||||
@@ -405,7 +401,6 @@ async fn realtime_ws_existing_call_transport_close_preserves_session() {
|
||||
event_parser,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Marin),
|
||||
},
|
||||
"rtc_frontend_owned",
|
||||
HeaderMap::new(),
|
||||
@@ -461,7 +456,6 @@ async fn realtime_ws_frameless_session_close_still_ends_session() {
|
||||
event_parser: RealtimeEventParser::FramelessBidi,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Marin),
|
||||
},
|
||||
"rtc_session_owner",
|
||||
HeaderMap::new(),
|
||||
@@ -525,7 +519,6 @@ async fn realtime_ws_e2e_send_while_next_event_waits() {
|
||||
event_parser: RealtimeEventParser::V1,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Cove),
|
||||
},
|
||||
HeaderMap::new(),
|
||||
HeaderMap::new(),
|
||||
@@ -595,7 +588,6 @@ async fn realtime_ws_e2e_disconnected_emitted_once() {
|
||||
event_parser: RealtimeEventParser::V1,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Cove),
|
||||
},
|
||||
HeaderMap::new(),
|
||||
HeaderMap::new(),
|
||||
@@ -661,7 +653,6 @@ async fn realtime_ws_e2e_ignores_unknown_text_events() {
|
||||
event_parser: RealtimeEventParser::V1,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Cove),
|
||||
},
|
||||
HeaderMap::new(),
|
||||
HeaderMap::new(),
|
||||
@@ -770,7 +761,6 @@ async fn realtime_ws_e2e_realtime_v2_parser_emits_handoff_requested() {
|
||||
event_parser: RealtimeEventParser::RealtimeV2,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Marin),
|
||||
},
|
||||
HeaderMap::new(),
|
||||
HeaderMap::new(),
|
||||
|
||||
@@ -17,7 +17,6 @@ use codex_api::RealtimeWebsocketClient;
|
||||
use codex_api::RetryConfig;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::OutboundProxyPolicy;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
use http::HeaderMap;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
@@ -145,7 +144,6 @@ async fn check_connection(address: String) {
|
||||
event_parser: RealtimeEventParser::V1,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice: Some(RealtimeVoice::Cove),
|
||||
},
|
||||
HeaderMap::new(),
|
||||
HeaderMap::new(),
|
||||
|
||||
@@ -686,7 +686,6 @@ pub enum RealtimeTransport {
|
||||
}
|
||||
|
||||
pub use codex_protocol::protocol::RealtimeConversationVersion as RealtimeWsVersion;
|
||||
pub use codex_protocol::protocol::RealtimeVoice;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
@@ -695,7 +694,6 @@ pub struct RealtimeConfig {
|
||||
#[serde(rename = "type")]
|
||||
pub session_type: RealtimeWsMode,
|
||||
pub transport: RealtimeTransport,
|
||||
pub voice: Option<RealtimeVoice>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
@@ -705,7 +703,9 @@ pub struct RealtimeToml {
|
||||
#[serde(rename = "type")]
|
||||
pub session_type: Option<RealtimeWsMode>,
|
||||
pub transport: Option<RealtimeTransport>,
|
||||
pub voice: Option<RealtimeVoice>,
|
||||
#[serde(rename = "voice", skip_serializing)]
|
||||
#[schemars(skip)]
|
||||
pub legacy_voice: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
|
||||
@@ -4739,9 +4739,6 @@
|
||||
},
|
||||
"version": {
|
||||
"$ref": "#/definitions/RealtimeConversationVersion"
|
||||
},
|
||||
"voice": {
|
||||
"$ref": "#/definitions/RealtimeVoice"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
@@ -4753,46 +4750,6 @@
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"RealtimeVoice": {
|
||||
"enum": [
|
||||
"alloy",
|
||||
"arbor",
|
||||
"ash",
|
||||
"aube",
|
||||
"ballad",
|
||||
"breeze",
|
||||
"bubbie",
|
||||
"cedar",
|
||||
"coral",
|
||||
"cove",
|
||||
"echo",
|
||||
"ember",
|
||||
"haetsal",
|
||||
"hanul",
|
||||
"himari",
|
||||
"juniper",
|
||||
"leher",
|
||||
"maple",
|
||||
"marin",
|
||||
"miko",
|
||||
"neer",
|
||||
"porto",
|
||||
"rindo",
|
||||
"rio",
|
||||
"rivage",
|
||||
"sage",
|
||||
"selva",
|
||||
"shimmer",
|
||||
"sol",
|
||||
"sonna",
|
||||
"spruce",
|
||||
"tinta",
|
||||
"vale",
|
||||
"verse",
|
||||
"viola"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"RealtimeWsMode": {
|
||||
"enum": [
|
||||
"conversational",
|
||||
|
||||
@@ -2432,7 +2432,6 @@ async fn realtime_call_preserves_captured_account_binding(change: RealtimeCreden
|
||||
event_parser: codex_api::RealtimeEventParser::V1,
|
||||
session_mode: codex_api::RealtimeSessionMode::Conversational,
|
||||
output_modality: codex_protocol::protocol::RealtimeOutputModality::Audio,
|
||||
voice: Some(codex_protocol::protocol::RealtimeVoice::Cove),
|
||||
},
|
||||
http::HeaderMap::new(),
|
||||
Some(api_provider),
|
||||
@@ -2765,7 +2764,6 @@ async fn realtime_custom_call_keeps_selected_key_for_openai_sideband(mode: Runti
|
||||
event_parser: codex_api::RealtimeEventParser::V1,
|
||||
session_mode: codex_api::RealtimeSessionMode::Conversational,
|
||||
output_modality: codex_protocol::protocol::RealtimeOutputModality::Audio,
|
||||
voice: Some(codex_protocol::protocol::RealtimeVoice::Cove),
|
||||
},
|
||||
http::HeaderMap::new(),
|
||||
Some(call_provider),
|
||||
|
||||
@@ -101,7 +101,6 @@ use codex_protocol::permissions::FileSystemSandboxPolicy;
|
||||
use codex_protocol::permissions::FileSystemSpecialPath;
|
||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_protocol_test_support::ContentItemTestExt;
|
||||
use codex_utils_path_uri::LegacyAppPathString;
|
||||
@@ -14098,30 +14097,21 @@ experimental_realtime_ws_model = "realtime-test-model"
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn realtime_config_partial_table_uses_realtime_defaults() -> std::io::Result<()> {
|
||||
let cfg: ConfigToml = toml::from_str(
|
||||
r#"
|
||||
[realtime]
|
||||
voice = "marin"
|
||||
"#,
|
||||
)
|
||||
.expect("TOML deserialization should succeed");
|
||||
|
||||
async fn realtime_config_with_legacy_voice_uses_realtime_defaults() -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let config = Config::load_from_base_config_with_overrides(
|
||||
cfg,
|
||||
ConfigOverrides::default(),
|
||||
codex_home.abs(),
|
||||
)
|
||||
.await?;
|
||||
std::fs::write(
|
||||
codex_home.path().join(CONFIG_TOML_FILE),
|
||||
"[realtime]\nvoice = \"marin\"",
|
||||
)?;
|
||||
let config = ConfigBuilder::default()
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.fallback_cwd(Some(codex_home.path().to_path_buf()))
|
||||
.loader_overrides(LoaderOverrides::without_managed_config_for_tests())
|
||||
.strict_config(/*strict_config*/ true)
|
||||
.build()
|
||||
.await?;
|
||||
|
||||
assert_eq!(
|
||||
config.realtime,
|
||||
RealtimeConfig {
|
||||
voice: Some(RealtimeVoice::Marin),
|
||||
..RealtimeConfig::default()
|
||||
}
|
||||
);
|
||||
assert_eq!(config.realtime, RealtimeConfig::default());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -14133,7 +14123,6 @@ async fn realtime_loads_from_config_toml() -> std::io::Result<()> {
|
||||
version = "v2"
|
||||
type = "transcription"
|
||||
transport = "webrtc"
|
||||
voice = "cedar"
|
||||
"#,
|
||||
)
|
||||
.expect("TOML deserialization should succeed");
|
||||
@@ -14144,7 +14133,7 @@ voice = "cedar"
|
||||
version: Some(RealtimeWsVersion::V2),
|
||||
session_type: Some(RealtimeWsMode::Transcription),
|
||||
transport: Some(RealtimeTransport::WebRtc),
|
||||
voice: Some(RealtimeVoice::Cedar),
|
||||
..RealtimeToml::default()
|
||||
})
|
||||
);
|
||||
|
||||
@@ -14162,7 +14151,6 @@ voice = "cedar"
|
||||
version: RealtimeWsVersion::V2,
|
||||
session_type: RealtimeWsMode::Transcription,
|
||||
transport: RealtimeTransport::WebRtc,
|
||||
voice: Some(RealtimeVoice::Cedar),
|
||||
}
|
||||
);
|
||||
Ok(())
|
||||
|
||||
@@ -4956,7 +4956,6 @@ impl Config {
|
||||
version: realtime.version.unwrap_or(defaults.version),
|
||||
session_type: realtime.session_type.unwrap_or(defaults.session_type),
|
||||
transport: realtime.transport.unwrap_or(defaults.transport),
|
||||
voice: realtime.voice,
|
||||
}
|
||||
}),
|
||||
experimental_realtime_ws_backend_prompt: cfg.experimental_realtime_ws_backend_prompt,
|
||||
|
||||
@@ -63,8 +63,6 @@ use codex_protocol::protocol::RealtimeExistingCallAuth;
|
||||
use codex_protocol::protocol::RealtimeHandoffRequested;
|
||||
use codex_protocol::protocol::RealtimeOutputModality;
|
||||
use codex_protocol::protocol::RealtimeTranscriptEntry;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
use codex_protocol::protocol::RealtimeVoicesList;
|
||||
use codex_utils_output_truncation::approx_bytes_for_tokens;
|
||||
use codex_utils_string::approx_token_count;
|
||||
use codex_utils_string::take_bytes_at_char_boundary;
|
||||
@@ -1739,12 +1737,6 @@ struct PreparedRealtimeConversationStart {
|
||||
auth_context: codex_model_provider::ProviderAuthContext,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) enum ConfiguredRealtimeVoice {
|
||||
Use,
|
||||
Ignore,
|
||||
}
|
||||
|
||||
async fn prepare_realtime_start(
|
||||
sess: &Arc<Session>,
|
||||
params: ConversationStartParams,
|
||||
@@ -1833,7 +1825,6 @@ async fn prepare_realtime_start(
|
||||
|| params.prompt.is_some()
|
||||
|| !params.initial_items.is_empty()
|
||||
|| params.model.is_some()
|
||||
|| params.voice.is_some()
|
||||
|| params.delegation_ack_filler.is_some()
|
||||
{
|
||||
return Err(CodexErr::InvalidRequest(
|
||||
@@ -1844,15 +1835,7 @@ async fn prepare_realtime_start(
|
||||
}
|
||||
ConversationStartTransport::Websocket => {}
|
||||
}
|
||||
let configured_voice = match (&transport, params.version) {
|
||||
(ConversationStartTransport::ExistingCall { .. }, _)
|
||||
| (ConversationStartTransport::Webrtc { .. }, None) => ConfiguredRealtimeVoice::Ignore,
|
||||
(ConversationStartTransport::Webrtc { .. } | ConversationStartTransport::Websocket, _) => {
|
||||
ConfiguredRealtimeVoice::Use
|
||||
}
|
||||
};
|
||||
let session_config =
|
||||
build_realtime_session_config(sess, ¶ms, version, configured_voice).await?;
|
||||
let session_config = build_realtime_session_config(sess, ¶ms, version).await?;
|
||||
let requested_realtime_session_id = session_config.session_id.clone();
|
||||
let event_parser = session_config.event_parser;
|
||||
let originator = sess.originator().await;
|
||||
@@ -1971,7 +1954,6 @@ pub(crate) async fn build_realtime_session_config(
|
||||
sess: &Arc<Session>,
|
||||
params: &ConversationStartParams,
|
||||
version: RealtimeWsVersion,
|
||||
configured_voice: ConfiguredRealtimeVoice,
|
||||
) -> CodexResult<RealtimeSessionConfig> {
|
||||
for (name, instructions) in [
|
||||
(
|
||||
@@ -2066,14 +2048,6 @@ pub(crate) async fn build_realtime_session_config(
|
||||
RealtimeWsMode::Conversational => RealtimeSessionMode::Conversational,
|
||||
RealtimeWsMode::Transcription => RealtimeSessionMode::Transcription,
|
||||
};
|
||||
let config_voice = match configured_voice {
|
||||
ConfiguredRealtimeVoice::Use => config.realtime.voice,
|
||||
ConfiguredRealtimeVoice::Ignore => None,
|
||||
};
|
||||
let voice = params.voice.unwrap_or(config_voice);
|
||||
if let Some(voice) = voice {
|
||||
validate_realtime_voice(version, voice)?;
|
||||
}
|
||||
Ok(RealtimeSessionConfig {
|
||||
instructions: prompt,
|
||||
initial_items: params.initial_items.clone(),
|
||||
@@ -2092,7 +2066,6 @@ pub(crate) async fn build_realtime_session_config(
|
||||
event_parser,
|
||||
session_mode,
|
||||
output_modality: params.output_modality,
|
||||
voice,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2116,33 +2089,6 @@ fn realtime_backend_item(text: String, prefix: Option<&str>) -> String {
|
||||
truncate_realtime_text_to_token_budget(&text, REALTIME_ASSISTANT_OUTPUT_TOKEN_BUDGET)
|
||||
}
|
||||
|
||||
fn validate_realtime_voice(version: RealtimeWsVersion, voice: RealtimeVoice) -> CodexResult<()> {
|
||||
let voices = RealtimeVoicesList::builtin();
|
||||
let allowed = match version {
|
||||
RealtimeWsVersion::V1 => &voices.v1,
|
||||
RealtimeWsVersion::V2 => &voices.v2,
|
||||
RealtimeWsVersion::V3 => &voices.v3,
|
||||
};
|
||||
if allowed.contains(&voice) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let version = match version {
|
||||
RealtimeWsVersion::V1 => "v1",
|
||||
RealtimeWsVersion::V2 => "v2",
|
||||
RealtimeWsVersion::V3 => "v3",
|
||||
};
|
||||
let allowed = allowed
|
||||
.iter()
|
||||
.map(|voice| voice.wire_name())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
Err(CodexErr::InvalidRequest(format!(
|
||||
"realtime voice `{}` is not supported for {version}; supported voices: {allowed}",
|
||||
voice.wire_name()
|
||||
)))
|
||||
}
|
||||
|
||||
async fn handle_start_inner(
|
||||
sess: &Arc<Session>,
|
||||
sub_id: &str,
|
||||
|
||||
@@ -65,7 +65,6 @@ fn websocket_start_params() -> ConversationStartParams {
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: Some(RealtimeConversationVersion::V1),
|
||||
voice: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,6 @@ async fn start_realtime_conversation(codex: &codex_core::CodexThread) -> Result<
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -1048,7 +1048,6 @@ fn params(session: &str, url: &str) -> ConversationStartParams {
|
||||
sideband_base_url: Some(url.to_owned()),
|
||||
}),
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
voice: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ use codex_protocol::protocol::RealtimeHandoffRequested;
|
||||
use codex_protocol::protocol::RealtimeNoopRequested;
|
||||
use codex_protocol::protocol::RealtimeOutputModality;
|
||||
use codex_protocol::protocol::RealtimeTranscriptEntry;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::ThreadHistoryMode;
|
||||
use codex_protocol::protocol::ThreadSource;
|
||||
@@ -343,7 +342,6 @@ async fn conversation_start_audio_text_close_round_trip() -> Result<()> {
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -538,7 +536,6 @@ async fn conversation_records_history_without_an_event_observer(
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
let items = timeout(Duration::from_secs(10), async {
|
||||
@@ -657,7 +654,6 @@ async fn conversation_start_defaults_to_v2_and_gpt_realtime_1_5() -> Result<()>
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -753,7 +749,6 @@ async fn conversation_websocket_transports_send_codex_headers_without_creating_a
|
||||
voice_session_id: None,
|
||||
transport: Some(transport.clone()),
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -928,7 +923,6 @@ async fn conversation_webrtc_frameless_chatgpt_sends_codex_headers_to_backend(
|
||||
sdp: "v=offer\r\n".to_string(),
|
||||
}),
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -1008,15 +1002,14 @@ async fn conversation_webrtc_frameless_chatgpt_sends_codex_headers_to_backend(
|
||||
"sdp": body["sdp"],
|
||||
"delegation": body["session"]["delegation"]["type"],
|
||||
"model": body["session"]["model"],
|
||||
"voice": body["session"]["audio"]["output"]["voice"],
|
||||
}),
|
||||
json!({
|
||||
"sdp": "v=offer\r\n",
|
||||
"delegation": "client",
|
||||
"model": expected_model,
|
||||
"voice": "cove",
|
||||
})
|
||||
);
|
||||
assert!(body["session"].pointer("/audio/output/voice").is_none());
|
||||
|
||||
codex.submit(Op::RealtimeConversationClose).await?;
|
||||
let _closed = wait_for_event_match(codex, |msg| match msg {
|
||||
@@ -1095,7 +1088,6 @@ async fn conversation_webrtc_start_posts_generated_session() -> Result<()> {
|
||||
sdp: "v=offer\r\n".to_string(),
|
||||
}),
|
||||
version: Some(RealtimeConversationVersion::V1),
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -1463,7 +1455,6 @@ async fn conversation_webrtc_live_reconnects_sideband_after_unclean_disconnect(
|
||||
voice_session_id: None,
|
||||
transport: Some(transport),
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
timeout(Duration::from_secs(5), inbound_flood_started_rx)
|
||||
@@ -1618,7 +1609,6 @@ async fn conversation_webrtc_start_uses_avas_query() -> Result<()> {
|
||||
sdp: "v=offer\r\n".to_string(),
|
||||
}),
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -1666,7 +1656,7 @@ async fn conversation_webrtc_start_uses_avas_query() -> Result<()> {
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn conversation_webrtc_default_v1_ignores_configured_v2_voice() -> Result<()> {
|
||||
async fn conversation_webrtc_default_v1_uses_cove() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = start_mock_server().await;
|
||||
@@ -1697,7 +1687,6 @@ async fn conversation_webrtc_default_v1_ignores_configured_v2_voice() -> Result<
|
||||
config.experimental_realtime_ws_backend_prompt = Some("backend prompt".to_string());
|
||||
config.experimental_realtime_ws_base_url = Some(realtime_ws_base_url);
|
||||
config.realtime.version = RealtimeWsVersion::V2;
|
||||
config.realtime.voice = Some(RealtimeVoice::Cedar);
|
||||
});
|
||||
let test = builder.build(&server).await?;
|
||||
|
||||
@@ -1725,7 +1714,6 @@ async fn conversation_webrtc_default_v1_ignores_configured_v2_voice() -> Result<
|
||||
sdp: "v=offer\r\n".to_string(),
|
||||
}),
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -1742,7 +1730,6 @@ async fn conversation_webrtc_default_v1_ignores_configured_v2_voice() -> Result<
|
||||
let body = String::from_utf8(request.body).context("multipart body should be utf-8")?;
|
||||
assert!(body.contains(r#""type":"quicksilver""#));
|
||||
assert!(body.contains(r#""voice":"cove""#));
|
||||
assert!(!body.contains(r#""voice":"cedar""#));
|
||||
|
||||
let session_update = wait_for_websocket_request(
|
||||
&realtime_server,
|
||||
@@ -1760,55 +1747,6 @@ async fn conversation_webrtc_default_v1_ignores_configured_v2_voice() -> Result<
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn conversation_webrtc_default_v1_rejects_explicit_v2_voice() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let api_server = start_mock_server().await;
|
||||
let mut builder = test_codex().with_config(|config| {
|
||||
config.realtime.version = RealtimeWsVersion::V2;
|
||||
});
|
||||
let test = builder.build(&api_server).await?;
|
||||
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationStart(ConversationStartParams {
|
||||
client_managed_handoffs: false,
|
||||
delegation_ack_filler: None,
|
||||
flush_transcript_tail_on_session_end: false,
|
||||
codex_responses_as_items: false,
|
||||
codex_response_item_prefix: None,
|
||||
codex_response_handoff_mode:
|
||||
codex_protocol::protocol::CodexResponseHandoffMode::Thinking,
|
||||
backend_reasoning_status: false,
|
||||
codex_response_handoff_channel_prefixes: None,
|
||||
model: None,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
include_startup_context: true,
|
||||
initial_items: Vec::new(),
|
||||
realtime_start_instructions: None,
|
||||
realtime_end_instructions: None,
|
||||
prompt: Some(Some("backend prompt".to_string())),
|
||||
realtime_session_id: None,
|
||||
voice_session_id: None,
|
||||
transport: Some(ConversationStartTransport::Webrtc {
|
||||
sdp: "v=offer\r\n".to_string(),
|
||||
}),
|
||||
version: None,
|
||||
voice: Some(Some(RealtimeVoice::Cedar)),
|
||||
}))
|
||||
.await?;
|
||||
|
||||
let error = wait_for_event_match(&test.codex, |msg| match msg {
|
||||
EventMsg::RealtimeConversationRealtime(RealtimeConversationRealtimeEvent {
|
||||
payload: RealtimeEvent::Error(message),
|
||||
}) => Some(message.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert!(error.contains("realtime voice `cedar` is not supported for v1"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn conversation_webrtc_start_uses_configured_call_base_url_for_avas() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
@@ -1873,7 +1811,6 @@ async fn conversation_webrtc_start_uses_configured_call_base_url_for_avas() -> R
|
||||
sdp: "v=offer\r\n".to_string(),
|
||||
}),
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -1967,7 +1904,6 @@ async fn conversation_existing_call_stop_closes_only_observer_transport(
|
||||
sideband_base_url: None,
|
||||
}),
|
||||
version: Some(version),
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
@@ -2063,7 +1999,6 @@ async fn conversation_webrtc_close_while_sideband_connecting_drops_pending_join(
|
||||
sdp: "v=offer\r\n".to_string(),
|
||||
}),
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -2172,7 +2107,6 @@ async fn conversation_webrtc_sideband_connect_failure_closes_with_error() -> Res
|
||||
sdp: "v=offer\r\n".to_string(),
|
||||
}),
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -2279,7 +2213,6 @@ async fn conversation_start_uses_openai_env_key_fallback_with_chatgpt_auth() ->
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -2381,7 +2314,6 @@ async fn two_existing_calls_on_one_thread_keep_distinct_openings_and_saved_tails
|
||||
sideband_base_url: None,
|
||||
}),
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
let started = wait_for_event_match(&test.codex, |msg| match msg {
|
||||
@@ -2526,7 +2458,6 @@ async fn assert_transport_close_tail_flush(
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -2682,7 +2613,6 @@ async fn conversation_start_preflight_failure_emits_realtime_error_only() -> Res
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -2742,7 +2672,6 @@ async fn conversation_start_connect_failure_emits_realtime_error_only() -> Resul
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -2856,7 +2785,6 @@ async fn conversation_second_start_replaces_runtime() -> Result<()> {
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
wait_for_event_match(&test.codex, |msg| match msg {
|
||||
@@ -2895,7 +2823,6 @@ async fn conversation_second_start_replaces_runtime() -> Result<()> {
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
wait_for_event_match(&test.codex, |msg| match msg {
|
||||
@@ -3006,7 +2933,6 @@ async fn conversation_uses_experimental_realtime_ws_base_url_override() -> Resul
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -3087,7 +3013,6 @@ async fn conversation_uses_default_realtime_backend_prompt() -> Result<()> {
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -3179,7 +3104,6 @@ async fn conversation_uses_empty_instructions_for_null_or_empty_prompt() -> Resu
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -3218,28 +3142,14 @@ async fn conversation_uses_empty_instructions_for_null_or_empty_prompt() -> Resu
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(RealtimeConversationVersion::V1, None, Some(RealtimeVoice::Breeze), "breeze"; "v1 explicit voice")]
|
||||
#[test_case(RealtimeConversationVersion::V3, None, None, "marin"; "v3 API default")]
|
||||
#[test_case(RealtimeConversationVersion::V3, None, Some(RealtimeVoice::Marin), "marin"; "v3 explicit API voice")]
|
||||
#[test_case(RealtimeConversationVersion::V3, Some(RealtimeVoice::Cove), Some(RealtimeVoice::Marin), "marin"; "explicit voice overrides config")]
|
||||
#[test_case(RealtimeConversationVersion::V3, Some(RealtimeVoice::Cove), None, "cove"; "v3 configured voice")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn conversation_selects_realtime_voice(
|
||||
version: RealtimeConversationVersion,
|
||||
configured_voice: Option<RealtimeVoice>,
|
||||
voice: Option<RealtimeVoice>,
|
||||
expected_voice: &str,
|
||||
) -> Result<()> {
|
||||
async fn conversation_uses_default_realtime_voice() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
// Responses prewarm can reconnect; give realtime its own scripted connections.
|
||||
let startup_server = start_websocket_server(vec![vec![]]).await;
|
||||
let server = start_websocket_server(vec![vec![vec![json!({
|
||||
"type": if version == RealtimeConversationVersion::V3 {
|
||||
"session.started"
|
||||
} else {
|
||||
"session.updated"
|
||||
},
|
||||
"type": "session.started",
|
||||
"session": { "id": "sess_voice", "instructions": "backend prompt" }
|
||||
})]]])
|
||||
.await;
|
||||
@@ -3247,7 +3157,6 @@ async fn conversation_selects_realtime_voice(
|
||||
let realtime_base_url = server.uri().to_string();
|
||||
move |config| {
|
||||
config.experimental_realtime_ws_base_url = Some(realtime_base_url);
|
||||
config.realtime.voice = configured_voice;
|
||||
}
|
||||
});
|
||||
let test = builder.build_with_websocket_server(&startup_server).await?;
|
||||
@@ -3278,8 +3187,7 @@ async fn conversation_selects_realtime_voice(
|
||||
realtime_session_id: None,
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: Some(version),
|
||||
voice: voice.map(Some),
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -3297,84 +3205,11 @@ async fn conversation_selects_realtime_voice(
|
||||
assert_eq!(session_updated, "sess_voice");
|
||||
|
||||
let connections = server.connections();
|
||||
assert_eq!(
|
||||
connections[0][0].body_json()["session"]["audio"]["output"]["voice"],
|
||||
expected_voice
|
||||
);
|
||||
|
||||
startup_server.shutdown().await;
|
||||
server.shutdown().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn conversation_uses_configured_realtime_voice() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
// Responses prewarm can reconnect; give realtime its own scripted connections.
|
||||
let startup_server = start_websocket_server(vec![vec![]]).await;
|
||||
let server = start_websocket_server(vec![vec![vec![json!({
|
||||
"type": "session.updated",
|
||||
"session": { "id": "sess_config_voice", "instructions": "backend prompt" }
|
||||
})]]])
|
||||
.await;
|
||||
let mut builder = test_codex().with_config({
|
||||
let realtime_base_url = server.uri().to_string();
|
||||
move |config| {
|
||||
config.experimental_realtime_ws_base_url = Some(realtime_base_url);
|
||||
config.realtime.voice = Some(RealtimeVoice::Cove);
|
||||
}
|
||||
});
|
||||
let test = builder.build_with_websocket_server(&startup_server).await?;
|
||||
assert!(
|
||||
startup_server
|
||||
.wait_for_handshakes(/*expected*/ 1, Duration::from_secs(2))
|
||||
.await
|
||||
);
|
||||
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationStart(ConversationStartParams {
|
||||
client_managed_handoffs: false,
|
||||
delegation_ack_filler: None,
|
||||
flush_transcript_tail_on_session_end: false,
|
||||
codex_responses_as_items: false,
|
||||
codex_response_item_prefix: None,
|
||||
codex_response_handoff_mode:
|
||||
codex_protocol::protocol::CodexResponseHandoffMode::Thinking,
|
||||
backend_reasoning_status: false,
|
||||
codex_response_handoff_channel_prefixes: None,
|
||||
model: None,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
include_startup_context: true,
|
||||
initial_items: Vec::new(),
|
||||
realtime_start_instructions: None,
|
||||
realtime_end_instructions: None,
|
||||
prompt: Some(Some("backend prompt".to_string())),
|
||||
realtime_session_id: None,
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
let session_updated = wait_for_event_match(&test.codex, |msg| match msg {
|
||||
EventMsg::RealtimeConversationRealtime(RealtimeConversationRealtimeEvent {
|
||||
payload:
|
||||
RealtimeEvent::SessionUpdated {
|
||||
realtime_session_id: session_id,
|
||||
..
|
||||
},
|
||||
}) => Some(session_id.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!(session_updated, "sess_config_voice");
|
||||
|
||||
let connections = server.connections();
|
||||
assert_eq!(
|
||||
connections[0][0].body_json()["session"]["audio"]["output"]["voice"],
|
||||
"cove"
|
||||
connections[0][0]
|
||||
.body_json()
|
||||
.pointer("/session/audio/output/voice")
|
||||
.is_none()
|
||||
);
|
||||
|
||||
startup_server.shutdown().await;
|
||||
@@ -3382,53 +3217,6 @@ async fn conversation_uses_configured_realtime_voice() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn conversation_rejects_voice_for_wrong_realtime_version() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let api_server = start_mock_server().await;
|
||||
let mut builder = test_codex().with_config(|config| {
|
||||
config.realtime.version = RealtimeWsVersion::V2;
|
||||
});
|
||||
let test = builder.build(&api_server).await?;
|
||||
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationStart(ConversationStartParams {
|
||||
client_managed_handoffs: false,
|
||||
delegation_ack_filler: None,
|
||||
flush_transcript_tail_on_session_end: false,
|
||||
codex_responses_as_items: false,
|
||||
codex_response_item_prefix: None,
|
||||
codex_response_handoff_mode:
|
||||
codex_protocol::protocol::CodexResponseHandoffMode::Thinking,
|
||||
backend_reasoning_status: false,
|
||||
codex_response_handoff_channel_prefixes: None,
|
||||
model: None,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
include_startup_context: true,
|
||||
initial_items: Vec::new(),
|
||||
realtime_start_instructions: None,
|
||||
realtime_end_instructions: None,
|
||||
prompt: Some(Some("backend prompt".to_string())),
|
||||
realtime_session_id: None,
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: Some(Some(RealtimeVoice::Cove)),
|
||||
}))
|
||||
.await?;
|
||||
|
||||
let error = wait_for_event_match(&test.codex, |msg| match msg {
|
||||
EventMsg::RealtimeConversationRealtime(RealtimeConversationRealtimeEvent {
|
||||
payload: RealtimeEvent::Error(message),
|
||||
}) => Some(message.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert!(error.contains("realtime voice `cove` is not supported for v2"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn conversation_uses_experimental_realtime_ws_backend_prompt_override() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
@@ -3477,7 +3265,6 @@ async fn conversation_uses_experimental_realtime_ws_backend_prompt_override() ->
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -3564,7 +3351,6 @@ async fn conversation_uses_experimental_realtime_ws_startup_context_override() -
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -3644,7 +3430,6 @@ async fn conversation_disables_realtime_startup_context_with_empty_override() ->
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -3717,7 +3502,6 @@ async fn conversation_start_injects_startup_context_from_thread_history() -> Res
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -3852,7 +3636,6 @@ async fn conversation_startup_context_current_thread_selects_many_turns_by_budge
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -3973,7 +3756,6 @@ async fn conversation_startup_context_falls_back_to_workspace_map() -> Result<()
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -4046,7 +3828,6 @@ async fn conversation_startup_context_is_truncated_and_sent_once_per_start() ->
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -4156,7 +3937,6 @@ async fn conversation_user_text_turn_is_not_sent_to_realtime(ephemeral: bool) ->
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -4343,7 +4123,6 @@ async fn realtime_v2_noop_tool_call_returns_empty_function_output_without_respon
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -4462,7 +4241,6 @@ async fn conversation_mirrors_assistant_message_text_to_realtime_handoff(
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -4601,7 +4379,6 @@ async fn conversation_relays_only_public_reasoning_as_quiet_status(enabled: bool
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
@@ -4794,7 +4571,6 @@ async fn conversation_routes_assistant_messages_for_v3_handoff(
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -4989,7 +4765,6 @@ async fn conversation_handoff_persists_across_item_done_until_turn_complete(
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -5214,7 +4989,6 @@ async fn realtime_handoff_history_scenario_inner(
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -5558,7 +5332,6 @@ async fn explicit_recovery_dispatches_the_committed_handoff_on_its_receiving_tur
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
let observed_at_ms = wait_for_event_match(&resumed, |msg| match msg {
|
||||
@@ -5659,7 +5432,6 @@ async fn inbound_handoff_request_uses_active_transcript() -> Result<()> {
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -5775,7 +5547,6 @@ async fn inbound_handoff_request_sends_transcript_delta_after_each_handoff() ->
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -5921,7 +5692,6 @@ async fn conversation_close_routes_only_remaining_transcript_tail_once() -> Resu
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -6030,7 +5800,6 @@ async fn inbound_conversation_item_does_not_start_turn_and_still_forwards_audio(
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -6166,7 +5935,6 @@ async fn delegated_turn_user_role_echo_does_not_redelegate_and_still_forwards_au
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -6332,7 +6100,6 @@ async fn inbound_handoff_request_does_not_block_realtime_event_forwarding() -> R
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
@@ -6528,7 +6295,6 @@ async fn inbound_handoff_request_updates_realtime_state_during_active_turn(
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
let _ = wait_for_event_match(&test.codex, |msg| match msg {
|
||||
@@ -6798,7 +6564,6 @@ async fn inbound_handoff_request_starts_turn_and_does_not_block_realtime_audio()
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -230,6 +230,5 @@ fn start_params(version: RealtimeConversationVersion) -> ConversationStartParams
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: Some(version),
|
||||
voice: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,6 @@ async fn misalignment_retires_late_voice_handoff_before_it_starts_a_turn() -> Re
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@ fn observer_params(sideband_base_url: Option<String>) -> ConversationStartParams
|
||||
sideband_base_url,
|
||||
}),
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
voice: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,7 +454,6 @@ async fn existing_call_uses_selected_endpoint_and_runtime_auth(
|
||||
},
|
||||
}),
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -155,7 +155,6 @@ async fn webrtc_sideband_honors_configured_system_proxy() -> Result<()> {
|
||||
sdp: "v=offer\r\n".to_string(),
|
||||
}),
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -596,7 +596,6 @@ async fn host_drain_closes_realtime_after_handoff_error() -> anyhow::Result<()>
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
for expected in [
|
||||
|
||||
@@ -32,7 +32,6 @@ fn realtime_start_debug_redacts_text_and_transport() {
|
||||
voice_session_id: Some(secret.to_owned()),
|
||||
transport: None,
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
voice: None,
|
||||
};
|
||||
for transport in [
|
||||
ConversationStartTransport::ExistingCall {
|
||||
|
||||
@@ -224,8 +224,6 @@ pub struct ConversationStartParams {
|
||||
pub transport: Option<ConversationStartTransport>,
|
||||
/// Overrides the configured realtime protocol version for this session only.
|
||||
pub version: Option<RealtimeConversationVersion>,
|
||||
/// None inherits the thread setting; Some(None) selects the provider default.
|
||||
pub voice: Option<Option<RealtimeVoice>>,
|
||||
}
|
||||
|
||||
/// Authentication selected by the embedding host for an existing call.
|
||||
@@ -337,48 +335,6 @@ pub enum RealtimeVoice {
|
||||
Viola,
|
||||
}
|
||||
|
||||
impl RealtimeVoice {
|
||||
pub fn wire_name(self) -> &'static str {
|
||||
match self {
|
||||
Self::Alloy => "alloy",
|
||||
Self::Arbor => "arbor",
|
||||
Self::Ash => "ash",
|
||||
Self::Aube => "aube",
|
||||
Self::Ballad => "ballad",
|
||||
Self::Breeze => "breeze",
|
||||
Self::Bubbie => "bubbie",
|
||||
Self::Cedar => "cedar",
|
||||
Self::Coral => "coral",
|
||||
Self::Cove => "cove",
|
||||
Self::Echo => "echo",
|
||||
Self::Ember => "ember",
|
||||
Self::Haetsal => "haetsal",
|
||||
Self::Hanul => "hanul",
|
||||
Self::Himari => "himari",
|
||||
Self::Juniper => "juniper",
|
||||
Self::Leher => "leher",
|
||||
Self::Maple => "maple",
|
||||
Self::Marin => "marin",
|
||||
Self::Miko => "miko",
|
||||
Self::Neer => "neer",
|
||||
Self::Porto => "porto",
|
||||
Self::Rindo => "rindo",
|
||||
Self::Rio => "rio",
|
||||
Self::Rivage => "rivage",
|
||||
Self::Sage => "sage",
|
||||
Self::Selva => "selva",
|
||||
Self::Shimmer => "shimmer",
|
||||
Self::Sol => "sol",
|
||||
Self::Sonna => "sonna",
|
||||
Self::Spruce => "spruce",
|
||||
Self::Tinta => "tinta",
|
||||
Self::Vale => "vale",
|
||||
Self::Verse => "verse",
|
||||
Self::Viola => "viola",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(rename_all = "camelCase")]
|
||||
|
||||
@@ -568,6 +568,7 @@ pub(crate) struct App {
|
||||
statusline_metrics: crate::statusline_metrics::StatuslineMetrics,
|
||||
provider_writes: HashMap<crate::backend_id::BackendId, crate::model_catalog::ProviderWrite>,
|
||||
feature_write_lock: Arc<tokio::sync::Mutex<()>>,
|
||||
voice_settings_pending: bool,
|
||||
config_notification_test_generation: u64,
|
||||
config_notification_test_pending: Option<u64>,
|
||||
model_catalog: Arc<ModelCatalog>,
|
||||
@@ -1336,7 +1337,7 @@ impl App {
|
||||
}
|
||||
}
|
||||
if let TuiEvent::Key(key_event) = &event
|
||||
&& self.handle_voice_toggle_key(tui, *key_event)
|
||||
&& self.handle_voice_toggle_key(tui, *key_event).await
|
||||
{
|
||||
return Ok(AppRunControl::Continue);
|
||||
}
|
||||
@@ -1348,7 +1349,8 @@ impl App {
|
||||
&& self.keymap.chat.toggle_voice_mute.is_pressed(*key_event)
|
||||
{
|
||||
if !self.chat_widget.handle_startup_submission_key(*key_event) {
|
||||
self.control_voice(crate::app_event::VoiceControl::Mute);
|
||||
self.control_voice(crate::app_event::VoiceControl::Mute)
|
||||
.await;
|
||||
}
|
||||
return Ok(AppRunControl::Continue);
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ impl App {
|
||||
let Some(key) = self.route_key_chord_event(tui, key) else {
|
||||
return;
|
||||
};
|
||||
if self.handle_voice_toggle_key(tui, key) {
|
||||
if self.handle_voice_toggle_key(tui, key).await {
|
||||
return;
|
||||
}
|
||||
if self
|
||||
|
||||
@@ -346,10 +346,10 @@ impl App {
|
||||
AppEvent::ChooseNewSessionCheckout { name }
|
||||
| AppEvent::NewSession { name }
|
||||
| AppEvent::NewSessionInCurrentWorktree { name } => {
|
||||
self.start_fresh_session(
|
||||
crate::boxed_future!(self.start_fresh_session(
|
||||
tui, app_server, FreshSessionStart::NewConversation,
|
||||
/*initial_user_message*/ None, name,
|
||||
)
|
||||
))
|
||||
.await;
|
||||
if self.chat_widget.has_misalignment_policy_violation() {
|
||||
self.chat_widget.show_misalignment_policy_precaution();
|
||||
@@ -373,13 +373,13 @@ impl App {
|
||||
"Read {name} and let’s continue where we left off.\n\nSaved conversation: {}",
|
||||
path.display(),
|
||||
);
|
||||
self.start_fresh_session(
|
||||
crate::boxed_future!(self.start_fresh_session(
|
||||
tui,
|
||||
app_server,
|
||||
FreshSessionStart::PreserveCurrentView(None),
|
||||
/*initial_user_message*/ None,
|
||||
/*new_thread_name*/ None,
|
||||
)
|
||||
))
|
||||
.await;
|
||||
if self
|
||||
.chat_widget
|
||||
@@ -677,13 +677,13 @@ impl App {
|
||||
self.clear_terminal_ui(tui, /*redraw_header*/ false)?;
|
||||
self.reset_app_ui_state_after_clear();
|
||||
|
||||
self.start_fresh_session(
|
||||
crate::boxed_future!(self.start_fresh_session(
|
||||
tui,
|
||||
app_server,
|
||||
FreshSessionStart::PreserveCurrentView(Some(ThreadStartSource::Clear)),
|
||||
/*initial_user_message*/ None,
|
||||
name,
|
||||
)
|
||||
))
|
||||
.await;
|
||||
}
|
||||
AppEvent::RawOutputModeChanged { enabled } => {
|
||||
@@ -2653,7 +2653,7 @@ impl App {
|
||||
}
|
||||
AppEvent::VoiceControl { thread_id, control } => {
|
||||
if thread_id == self.chat_widget.thread_id() || self.voice_owner_thread_id().is_some() {
|
||||
self.control_voice(control);
|
||||
crate::boxed_future!(self.control_voice(control)).await;
|
||||
}
|
||||
}
|
||||
AppEvent::RealtimeSessionLockStopped { thread_id } => {
|
||||
@@ -3208,9 +3208,35 @@ impl App {
|
||||
}
|
||||
self.chat_widget.on_plugin_mentions_loaded(plugins);
|
||||
}
|
||||
AppEvent::OpenRealtimeSettings => self.chat_widget.open_realtime_settings(),
|
||||
AppEvent::OpenRealtimeSettings => {
|
||||
if crate::boxed_future!(self.ensure_voice_account()).await {
|
||||
self.chat_widget.open_realtime_settings();
|
||||
}
|
||||
}
|
||||
AppEvent::OpenRealtimeSoundDevices => self.chat_widget.open_realtime_sound_devices(),
|
||||
AppEvent::OpenRealtimeVoices => self.open_realtime_voices(app_server).await,
|
||||
AppEvent::OpenRealtimeVoices | AppEvent::PersistRealtimeVoiceSelection { .. }
|
||||
if self.voice_settings_pending =>
|
||||
{
|
||||
self.chat_widget.add_info_message(
|
||||
"Voice settings request in progress.".to_owned(),
|
||||
/*hint*/ None,
|
||||
);
|
||||
}
|
||||
AppEvent::OpenRealtimeVoices => self.load_realtime_voices(app_server),
|
||||
AppEvent::RealtimeVoicesLoaded { origin, result } => {
|
||||
self.voice_settings_pending = false;
|
||||
if origin == self.active_thread_id {
|
||||
match result {
|
||||
Ok(settings) => {
|
||||
self.chat_widget.open_realtime_voices(settings);
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::warn!(%error, "failed to read voice settings");
|
||||
self.chat_widget.add_error_message("Failed to read voice settings".to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
AppEvent::OpenRealtimeDevicePicker { kind } => self.list_realtime_devices(kind),
|
||||
AppEvent::OpenRealtimeInputChannels { device } => self.chat_widget.open_realtime_input_channels(device),
|
||||
AppEvent::RealtimeDevicesListed { origin, kind, result } => {
|
||||
@@ -3228,7 +3254,22 @@ impl App {
|
||||
self.persist_realtime_input_channel(channel).await;
|
||||
}
|
||||
AppEvent::PersistRealtimeVoiceSelection { voice } => {
|
||||
self.persist_realtime_voice(app_server, voice).await;
|
||||
self.persist_realtime_voice(app_server, voice);
|
||||
}
|
||||
AppEvent::RealtimeVoiceSaved { origin, result } => {
|
||||
self.voice_settings_pending = false;
|
||||
if origin == self.active_thread_id {
|
||||
match result {
|
||||
Ok(name) => self.chat_widget.add_info_message(
|
||||
format!("Voice set to {name}."),
|
||||
/*hint*/ None,
|
||||
),
|
||||
Err(error) => {
|
||||
tracing::warn!(%error, "failed to save voice");
|
||||
self.chat_widget.add_error_message("Failed to save voice".to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
AppEvent::ToggleCloudServiceTier { thread_id, tier } => {
|
||||
if self.active_thread_id == Some(thread_id)
|
||||
|
||||
@@ -405,13 +405,18 @@ impl App {
|
||||
&& self.keymap.chat.toggle_voice.is_pressed(key)
|
||||
}
|
||||
|
||||
pub(super) fn handle_voice_toggle_key(&mut self, tui: &mut tui::Tui, key: KeyEvent) -> bool {
|
||||
pub(super) async fn handle_voice_toggle_key(
|
||||
&mut self,
|
||||
tui: &mut tui::Tui,
|
||||
key: KeyEvent,
|
||||
) -> bool {
|
||||
if !self.voice_toggle_pressed(key) {
|
||||
return false;
|
||||
}
|
||||
self.cancel_transcript_browsing(tui);
|
||||
if !self.chat_widget.handle_startup_submission_key(key) {
|
||||
self.control_voice(crate::app_event::VoiceControl::Toggle);
|
||||
self.control_voice(crate::app_event::VoiceControl::Toggle)
|
||||
.await;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
@@ -2,29 +2,19 @@
|
||||
|
||||
use super::*;
|
||||
use crate::legacy_core::config::edit::ConfigEdit;
|
||||
use codex_app_server_protocol::ClientRequest;
|
||||
use codex_app_server_protocol::RequestId;
|
||||
use codex_app_server_protocol::ThreadRealtimeListVoicesParams;
|
||||
use codex_app_server_protocol::ThreadRealtimeListVoicesResponse;
|
||||
use codex_app_server_protocol::AccountVoiceOption;
|
||||
use codex_app_server_protocol::AccountVoiceSettingsWriteParams;
|
||||
use codex_app_server_protocol::AccountVoiceSettingsWriteResponse;
|
||||
use codex_config::config_toml::MicrophoneChannels;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
use codex_protocol::protocol::RealtimeVoicesList;
|
||||
use codex_realtime_webrtc::AudioDeviceKind;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Display the saved preference without guessing a provider-specific default.
|
||||
fn configured_voice(config: &codex_app_server_protocol::Config) -> Result<Option<RealtimeVoice>> {
|
||||
let value = config
|
||||
.additional
|
||||
.get("realtime")
|
||||
.and_then(|realtime| realtime.get("voice"));
|
||||
match value {
|
||||
None | Some(serde_json::Value::Null) => Ok(None),
|
||||
Some(value @ serde_json::Value::String(_)) => {
|
||||
Ok(serde_json::from_value(value.clone()).ok())
|
||||
}
|
||||
Some(value) => Ok(Some(serde_json::from_value(value.clone())?)),
|
||||
}
|
||||
const VOICE_SETTINGS_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(15);
|
||||
|
||||
async fn voice_settings_request<T: serde::de::DeserializeOwned>(
|
||||
handle: AppServerRequestHandle,
|
||||
request: ClientRequest,
|
||||
) -> anyhow::Result<T> {
|
||||
Ok(tokio::time::timeout(VOICE_SETTINGS_TIMEOUT, handle.request_typed(request)).await??)
|
||||
}
|
||||
|
||||
impl App {
|
||||
@@ -175,96 +165,47 @@ impl App {
|
||||
});
|
||||
}
|
||||
|
||||
pub(super) async fn realtime_voices(
|
||||
app_server: &AppServerSession,
|
||||
) -> Result<RealtimeVoicesList> {
|
||||
let response = app_server
|
||||
.request_handle()
|
||||
.request_typed::<ThreadRealtimeListVoicesResponse>(
|
||||
ClientRequest::ThreadRealtimeListVoices {
|
||||
request_id: RequestId::String(format!("tui-voice-list-{}", Uuid::new_v4())),
|
||||
params: ThreadRealtimeListVoicesParams {},
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
Ok(response.voices)
|
||||
pub(super) async fn ensure_voice_account(&mut self) -> bool {
|
||||
if let Err(error) = self.realtime_call_client.voice_provider(&self.config).await {
|
||||
self.chat_widget.add_error_message(error.to_string());
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub(super) async fn effective_realtime_voice(
|
||||
app_server: &AppServerSession,
|
||||
cwd: &std::path::Path,
|
||||
) -> Result<Option<RealtimeVoice>> {
|
||||
// Session setup installs the active conversation cwd for both server modes.
|
||||
let config = crate::config_update::read_effective_config_if_supported(
|
||||
app_server.request_handle(),
|
||||
cwd,
|
||||
)
|
||||
.await?;
|
||||
config
|
||||
.as_ref()
|
||||
.map(|config| configured_voice(&config.config))
|
||||
.transpose()
|
||||
.map(Option::flatten)
|
||||
}
|
||||
|
||||
pub(super) async fn open_realtime_voices(&mut self, app_server: &AppServerSession) {
|
||||
let voices = match Self::realtime_voices(app_server).await {
|
||||
Ok(voices) => voices,
|
||||
Err(error) => {
|
||||
self.chat_widget
|
||||
.add_error_message(format!("Failed to list voices: {error}"));
|
||||
return;
|
||||
}
|
||||
pub(super) fn load_realtime_voices(&mut self, app_server: &mut AppServerSession) {
|
||||
self.voice_settings_pending = true;
|
||||
let origin = self.active_thread_id;
|
||||
let handle = app_server.request_handle();
|
||||
let request = ClientRequest::AccountVoiceSettingsRead {
|
||||
request_id: app_server.next_request_id(),
|
||||
params: None,
|
||||
};
|
||||
match Self::effective_realtime_voice(app_server, &self.chat_widget.config_ref().cwd).await {
|
||||
Ok(voice) => self.chat_widget.open_realtime_voices(voice, voices),
|
||||
Err(error) => self
|
||||
.chat_widget
|
||||
.add_error_message(format!("Failed to read voice settings: {error}")),
|
||||
}
|
||||
let tx = self.app_event_tx.clone();
|
||||
tokio::spawn(async move {
|
||||
let result = voice_settings_request(handle, request).await;
|
||||
tx.send(AppEvent::RealtimeVoicesLoaded { origin, result });
|
||||
});
|
||||
}
|
||||
|
||||
pub(super) async fn persist_realtime_voice(
|
||||
pub(super) fn persist_realtime_voice(
|
||||
&mut self,
|
||||
app_server: &AppServerSession,
|
||||
voice: RealtimeVoice,
|
||||
app_server: &mut AppServerSession,
|
||||
voice: AccountVoiceOption,
|
||||
) {
|
||||
match crate::config_update::write_config_batch(
|
||||
app_server.request_handle(),
|
||||
vec![crate::config_update::replace_config_value(
|
||||
"realtime.voice",
|
||||
serde_json::json!(voice),
|
||||
)],
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(response) => {
|
||||
let effective = crate::config_update::read_effective_config_if_supported(
|
||||
app_server.request_handle(), &self.chat_widget.config_ref().cwd,
|
||||
).await.and_then(|config| match config.as_ref() {
|
||||
Some(config) => configured_voice(&config.config),
|
||||
None if response.status == codex_app_server_protocol::WriteStatus::OkOverridden => Err(color_eyre::eyre::eyre!("the saved voice is overridden, but this server cannot read effective settings")),
|
||||
None => Ok(Some(voice)),
|
||||
});
|
||||
match effective {
|
||||
Ok(effective_voice) => {
|
||||
self.config.realtime.voice = effective_voice;
|
||||
self.chat_widget.set_realtime_voice(effective_voice);
|
||||
if effective_voice == Some(voice) {
|
||||
self.chat_widget.on_realtime_voice_saved(voice);
|
||||
} else {
|
||||
self.chat_widget.add_error_message(format!(
|
||||
"Voice preference was saved but not applied: {}",
|
||||
super::config_persistence::overridden_write_message(&response),
|
||||
));
|
||||
}
|
||||
}
|
||||
Err(error) => self.chat_widget.add_error_message(format!("Voice preference was saved, but effective settings could not be read: {error}")),
|
||||
}
|
||||
}
|
||||
Err(error) => self
|
||||
.chat_widget
|
||||
.add_error_message(format!("Failed to save voice: {error}")),
|
||||
}
|
||||
self.voice_settings_pending = true;
|
||||
let origin = self.active_thread_id;
|
||||
let handle = app_server.request_handle();
|
||||
let request = ClientRequest::AccountVoiceSettingsWrite {
|
||||
request_id: app_server.next_request_id(),
|
||||
params: AccountVoiceSettingsWriteParams { voice: voice.voice },
|
||||
};
|
||||
let tx = self.app_event_tx.clone();
|
||||
tokio::spawn(async move {
|
||||
let result = voice_settings_request(handle, request)
|
||||
.await
|
||||
.map(|_: AccountVoiceSettingsWriteResponse| voice.name);
|
||||
tx.send(AppEvent::RealtimeVoiceSaved { origin, result });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1055,6 +1055,7 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
statusline_metrics,
|
||||
provider_writes,
|
||||
feature_write_lock: Arc::default(),
|
||||
voice_settings_pending: false,
|
||||
config_notification_test_generation: 0,
|
||||
config_notification_test_pending: None,
|
||||
model_catalog,
|
||||
|
||||
@@ -57,6 +57,7 @@ pub(crate) async fn make_test_app() -> Box<App> {
|
||||
statusline_metrics: Default::default(),
|
||||
provider_writes: HashMap::new(),
|
||||
feature_write_lock: Arc::default(),
|
||||
voice_settings_pending: false,
|
||||
config_notification_test_generation: 0,
|
||||
config_notification_test_pending: None,
|
||||
model_catalog: chat_widget.model_catalog(),
|
||||
|
||||
@@ -81,11 +81,8 @@ mod history_hydration_tests;
|
||||
mod permission_shortcuts_tests;
|
||||
mod plugin_catalog;
|
||||
mod rate_limits;
|
||||
#[path = "tests/realtime_handoff_e2e.rs"]
|
||||
mod realtime_handoff_e2e;
|
||||
#[path = "tests/realtime_requests.rs"]
|
||||
mod realtime_requests;
|
||||
#[path = "tests/realtime_start.rs"]
|
||||
mod realtime_start;
|
||||
#[path = "tests/reasoning_resume_tests.rs"]
|
||||
mod reasoning_resume_tests;
|
||||
@@ -9138,6 +9135,7 @@ async fn make_test_app() -> Box<App> {
|
||||
provider_writes: HashMap::new(),
|
||||
realtime_call_client: Arc::default(),
|
||||
feature_write_lock: Arc::default(),
|
||||
voice_settings_pending: false,
|
||||
config_notification_test_generation: 0,
|
||||
config_notification_test_pending: None,
|
||||
model_catalog: chat_widget.model_catalog(),
|
||||
@@ -9287,6 +9285,7 @@ pub(super) async fn make_test_app_with_channels() -> (
|
||||
provider_writes: HashMap::new(),
|
||||
realtime_call_client: Arc::default(),
|
||||
feature_write_lock: Arc::default(),
|
||||
voice_settings_pending: false,
|
||||
config_notification_test_generation: 0,
|
||||
config_notification_test_pending: None,
|
||||
model_catalog: chat_widget.model_catalog(),
|
||||
|
||||
@@ -19,6 +19,7 @@ use std::time::Duration;
|
||||
use tokio::time::timeout;
|
||||
use wiremock::Mock;
|
||||
use wiremock::ResponseTemplate;
|
||||
use wiremock::matchers::header;
|
||||
use wiremock::matchers::method;
|
||||
use wiremock::matchers::path;
|
||||
|
||||
@@ -50,7 +51,16 @@ async fn delegated_core_events_keep_private_output_hidden_and_deliver_final_spee
|
||||
])
|
||||
.await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/v1/live"))
|
||||
.and(path("/backend-api/codex/realtime/calls"))
|
||||
.and(header("authorization", "Bearer local-voice-token"))
|
||||
.and(|request: &wiremock::Request| {
|
||||
request.body_json::<serde_json::Value>().is_ok_and(|body| {
|
||||
let session = &body["session"];
|
||||
session["delegation"]["type"] == "client"
|
||||
&& session.get("model").is_none()
|
||||
&& session.pointer("/audio/output/voice").is_none()
|
||||
})
|
||||
})
|
||||
.respond_with(
|
||||
ResponseTemplate::new(200)
|
||||
.insert_header("Location", "/v1/live/rtc_tui_handoff")
|
||||
@@ -91,11 +101,12 @@ async fn delegated_core_events_keep_private_output_hidden_and_deliver_final_spee
|
||||
let codex_home = tempfile::tempdir()?;
|
||||
MockResponsesConfig::new(&model_server.uri())
|
||||
.with_root_config(&format!(
|
||||
"experimental_realtime_ws_base_url = {:?}\nexperimental_realtime_webrtc_call_base_url = {:?}",
|
||||
"experimental_realtime_ws_base_url = {:?}",
|
||||
realtime_server.uri(),
|
||||
format!("{}/v1", model_server.uri()),
|
||||
))
|
||||
.with_extra_config("[realtime]\nversion = \"v3\"\ntype = \"conversational\"")
|
||||
.with_extra_config(
|
||||
"[realtime]\nversion = \"v3\"\ntype = \"conversational\"\nvoice = \"cedar\"",
|
||||
)
|
||||
.write(codex_home.path())?;
|
||||
codex_login::login_with_api_key(
|
||||
codex_home.path(),
|
||||
@@ -107,37 +118,43 @@ async fn delegated_core_events_keep_private_output_hidden_and_deliver_final_spee
|
||||
app.config.sqlite = codex_state::SqliteConfig::new_for_testing(codex_home.path().abs());
|
||||
app.config.cli_auth_credentials_store_mode = AuthCredentialsStoreMode::File;
|
||||
app.config.model = Some("mock-model".to_string());
|
||||
app.config.model_provider_id = "mock_provider".to_string();
|
||||
app.config.model_provider = ModelProviderInfo {
|
||||
name: "Mock provider for test".to_string(),
|
||||
base_url: Some(format!("{}/v1", model_server.uri())),
|
||||
request_max_retries: Some(0),
|
||||
stream_max_retries: Some(0),
|
||||
..ModelProviderInfo::default()
|
||||
};
|
||||
app.config.model_provider_id = codex_model_provider_info::OPENAI_PROVIDER_ID.to_string();
|
||||
app.config.model_provider =
|
||||
ModelProviderInfo::create_openai_provider(Some(format!("{}/v1", model_server.uri())));
|
||||
app.config.experimental_realtime_ws_base_url = Some(realtime_server.uri().to_string());
|
||||
app.config.experimental_realtime_webrtc_call_base_url =
|
||||
Some(format!("{}/v1", model_server.uri()));
|
||||
|
||||
let mut app_server = Box::pin(crate::start_embedded_app_server_for_picker(&app.config)).await?;
|
||||
let started = app_server.start_thread(&app.config).await?;
|
||||
let thread_id = started.session.thread_id;
|
||||
app.enqueue_primary_thread_session(started.session, started.turns)
|
||||
.await?;
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
while app_events.try_recv().is_ok() {}
|
||||
for event in [
|
||||
AppEvent::OpenRealtimeSettings,
|
||||
AppEvent::VoiceControl {
|
||||
thread_id: Some(thread_id),
|
||||
control: crate::app_event::VoiceControl::Toggle,
|
||||
},
|
||||
] {
|
||||
Box::pin(app.handle_event(&mut tui, &mut app_server, event)).await?;
|
||||
assert_eq!(
|
||||
next_history_message(&mut app_events),
|
||||
"■ Sign in with ChatGPT to use voice chat."
|
||||
);
|
||||
}
|
||||
assert!(!app.chat_widget.has_active_view());
|
||||
assert!(!app.chat_widget.realtime_conversation_is_running());
|
||||
|
||||
super::realtime_requests::use_local_voice_account(&mut app.config, &model_server.uri());
|
||||
crate::chatwidget::activate_voice_for_thread(&mut app.chat_widget, thread_id);
|
||||
while ops.try_recv().is_ok() {}
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
let thread = app_server
|
||||
.thread_read(thread_id, /*include_turns*/ false)
|
||||
.await?;
|
||||
let call = app
|
||||
.realtime_call_client
|
||||
.create(
|
||||
&app.config,
|
||||
&thread,
|
||||
"v=offer\r\n".to_string(),
|
||||
/*voice*/ None,
|
||||
)
|
||||
.create(&app.config, &thread, "v=offer\r\n".to_string())
|
||||
.await?;
|
||||
assert_eq!(String::from(call.answer_sdp), "v=answer\r\n");
|
||||
app_server
|
||||
|
||||
@@ -8,6 +8,8 @@ use crate::app::tests::session_lifecycle_requests::start_recording_remote_app_se
|
||||
use crate::chatwidget::commit_realtime_history_events;
|
||||
use crate::chatwidget::tests::make_chatwidget_manual_with_sender;
|
||||
use crate::local_settings::LocalSettings;
|
||||
use app_test_support::ChatGptAuthFixture;
|
||||
use app_test_support::write_chatgpt_auth;
|
||||
use codex_app_server_protocol::ItemCompletedNotification;
|
||||
use codex_app_server_protocol::ItemStartedNotification;
|
||||
use codex_app_server_protocol::ServerNotification;
|
||||
@@ -18,6 +20,7 @@ use codex_app_server_protocol::TurnCompletedNotification;
|
||||
use codex_app_server_protocol::TurnItemsView;
|
||||
use codex_app_server_protocol::TurnStatus;
|
||||
use codex_app_server_protocol::UserInput;
|
||||
use codex_login::AuthCredentialsStoreMode;
|
||||
use codex_protocol::models::MessagePhase;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::path::Path;
|
||||
@@ -85,76 +88,71 @@ enum ItemEventKind {
|
||||
Completed,
|
||||
}
|
||||
|
||||
async fn mock_voice_calls(
|
||||
pub(super) fn use_local_voice_account(
|
||||
config: &mut crate::legacy_core::config::Config,
|
||||
base_path: &str,
|
||||
) -> wiremock::MockServer {
|
||||
let server = wiremock::MockServer::start().await;
|
||||
let path = if base_path == "/v1" {
|
||||
"/v1/live"
|
||||
} else {
|
||||
"/backend-api/realtime/calls"
|
||||
};
|
||||
wiremock::Mock::given(wiremock::matchers::method("POST"))
|
||||
.and(wiremock::matchers::path(path))
|
||||
.respond_with(
|
||||
wiremock::ResponseTemplate::new(201)
|
||||
.insert_header("Location", "/realtime/calls/rtc_tui")
|
||||
.set_body_string("v=answer\r\n"),
|
||||
)
|
||||
.mount(&server)
|
||||
.await;
|
||||
config.experimental_realtime_webrtc_call_base_url =
|
||||
Some(format!("{}{base_path}", server.uri()));
|
||||
server
|
||||
backend: &str,
|
||||
) {
|
||||
config.chatgpt_base_url = format!("{backend}/backend-api");
|
||||
config.cli_auth_credentials_store_mode = AuthCredentialsStoreMode::File;
|
||||
write_chatgpt_auth(
|
||||
&config.codex_home,
|
||||
ChatGptAuthFixture::new("local-voice-token").account_id("local-voice-account"),
|
||||
AuthCredentialsStoreMode::File,
|
||||
)
|
||||
.expect("write local ChatGPT voice account");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_voice_start_routes_v3_offer_and_effective_preference() -> Result<()> {
|
||||
use super::session_lifecycle_requests::HistoryCapabilities;
|
||||
for (capabilities, expected_voice) in [
|
||||
(HistoryCapabilities::Current, Some("juniper")),
|
||||
(HistoryCapabilities::ConfigReadUnsupported(-32601), None),
|
||||
(HistoryCapabilities::Current, Some("cove")),
|
||||
(HistoryCapabilities::VoiceCatalogCustom, None),
|
||||
(HistoryCapabilities::ConfigReadUnknownVoice, None),
|
||||
] {
|
||||
check_remote_voice_start(capabilities, expected_voice, "/backend-api").await?;
|
||||
}
|
||||
check_remote_voice_start(
|
||||
HistoryCapabilities::Current,
|
||||
/*expected_voice*/ None,
|
||||
"/v1",
|
||||
fn configure_voice_settings_server(
|
||||
config: &mut crate::legacy_core::config::Config,
|
||||
backend: &str,
|
||||
) -> Result<()> {
|
||||
config.chatgpt_base_url = format!("{backend}/backend-api");
|
||||
config.cli_auth_credentials_store_mode = AuthCredentialsStoreMode::File;
|
||||
write_chatgpt_auth(
|
||||
&config.codex_home,
|
||||
ChatGptAuthFixture::new("server-token").account_id("server-account"),
|
||||
AuthCredentialsStoreMode::File,
|
||||
)
|
||||
.await?;
|
||||
.expect("write server ChatGPT login");
|
||||
std::fs::write(
|
||||
config.codex_home.join("config.toml"),
|
||||
format!(
|
||||
"chatgpt_base_url = '{backend}/backend-api'\ncli_auth_credentials_store = 'file'\n"
|
||||
),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn next_call_result(
|
||||
async fn next_voice_event(
|
||||
events: &mut tokio::sync::mpsc::UnboundedReceiver<AppEvent>,
|
||||
) -> Result<AppEvent> {
|
||||
tokio::time::timeout(std::time::Duration::from_secs(10), async {
|
||||
while let Some(event) = events.recv().await {
|
||||
if matches!(event, AppEvent::RealtimeCallCreated { .. }) {
|
||||
if matches!(
|
||||
event,
|
||||
AppEvent::RealtimeCallCreated { .. }
|
||||
| AppEvent::RealtimeVoicesLoaded { .. }
|
||||
| AppEvent::PersistRealtimeVoiceSelection { .. }
|
||||
| AppEvent::RealtimeVoiceSaved { .. }
|
||||
) {
|
||||
return Ok(event);
|
||||
}
|
||||
}
|
||||
color_eyre::eyre::bail!("app event channel closed during call startup");
|
||||
color_eyre::eyre::bail!("app event channel closed during voice request");
|
||||
})
|
||||
.await?
|
||||
}
|
||||
|
||||
async fn check_remote_voice_start(
|
||||
capabilities: super::session_lifecycle_requests::HistoryCapabilities,
|
||||
expected_voice: Option<&str>,
|
||||
base_path: &str,
|
||||
) -> Result<()> {
|
||||
#[tokio::test]
|
||||
async fn remote_voice_start_routes_v3_offer_and_effective_preference() -> Result<()> {
|
||||
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
|
||||
let calls = mock_voice_calls(&mut app.config, base_path).await;
|
||||
let mut remote = make_test_app().await;
|
||||
let settings_backend = wiremock::MockServer::start().await;
|
||||
configure_voice_settings_server(&mut remote.config, &settings_backend.uri())?;
|
||||
let (mut app_server, requests, proxy) =
|
||||
super::session_lifecycle_requests::start_recording_app_server_with_realtime_speech(
|
||||
&app.config,
|
||||
capabilities,
|
||||
&remote.config,
|
||||
super::session_lifecycle_requests::HistoryCapabilities::ConfigReadFails,
|
||||
/*blocked_thread_list*/ None,
|
||||
/*failed_thread_name*/ None,
|
||||
crate::app_server_session::ThreadParamsMode::Remote,
|
||||
@@ -162,45 +160,78 @@ async fn check_remote_voice_start(
|
||||
codex_config::LoaderOverrides::default(),
|
||||
)
|
||||
.await?;
|
||||
let calls = wiremock::MockServer::start().await;
|
||||
wiremock::Mock::given(wiremock::matchers::method("POST"))
|
||||
.and(wiremock::matchers::path(
|
||||
"/backend-api/codex/realtime/calls",
|
||||
))
|
||||
.respond_with(
|
||||
wiremock::ResponseTemplate::new(201)
|
||||
.insert_header("Location", "/realtime/calls/rtc_tui")
|
||||
.set_body_string("v=answer\r\n"),
|
||||
)
|
||||
.mount(&calls)
|
||||
.await;
|
||||
use_local_voice_account(&mut app.config, &calls.uri());
|
||||
app.config.experimental_realtime_webrtc_call_base_url = Some(format!("{}/v1", calls.uri()));
|
||||
app.config.experimental_realtime_ws_model = Some("realtime-test-model".to_string());
|
||||
let started = app_server.start_thread(&app.config).await?;
|
||||
let thread_id = started.session.thread_id;
|
||||
app.active_thread_id = Some(thread_id);
|
||||
app.chat_widget.handle_thread_session_quiet(started.session);
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
app.config.model_provider.requires_openai_auth = false;
|
||||
app.config.model_provider.http_headers =
|
||||
Some([("x-test-provider".into(), "custom".into())].into());
|
||||
app.config.model_provider.query_params =
|
||||
Some([("provider_option".into(), "custom".into())].into());
|
||||
wiremock::Mock::given(wiremock::matchers::method("GET"))
|
||||
.and(wiremock::matchers::header(
|
||||
"authorization",
|
||||
"Bearer server-token",
|
||||
))
|
||||
.and(wiremock::matchers::path("/backend-api/settings/voices"))
|
||||
.respond_with(wiremock::ResponseTemplate::new(200).set_body_json(
|
||||
serde_json::json!({"selected": "juniper", "voices": [{"voice":"juniper"}]}),
|
||||
))
|
||||
.mount(&settings_backend)
|
||||
.await;
|
||||
wiremock::Mock::given(wiremock::matchers::method("PATCH"))
|
||||
.and(wiremock::matchers::header(
|
||||
"authorization",
|
||||
"Bearer server-token",
|
||||
))
|
||||
.and(wiremock::matchers::path(
|
||||
"/backend-api/settings/account_user_setting",
|
||||
))
|
||||
.and(wiremock::matchers::query_param("value", "juniper"))
|
||||
.respond_with(wiremock::ResponseTemplate::new(200))
|
||||
.expect(1)
|
||||
.mount(&settings_backend)
|
||||
.await;
|
||||
Box::pin(app.handle_event(&mut tui, &mut app_server, AppEvent::OpenRealtimeVoices)).await?;
|
||||
Box::pin(app.handle_event(
|
||||
&mut tui,
|
||||
&mut app_server,
|
||||
AppEvent::PersistRealtimeVoiceSelection {
|
||||
voice: codex_protocol::protocol::RealtimeVoice::Juniper,
|
||||
},
|
||||
next_voice_event(&mut events).await?,
|
||||
))
|
||||
.await?;
|
||||
if capabilities == super::session_lifecycle_requests::HistoryCapabilities::Current {
|
||||
assert_eq!(
|
||||
(
|
||||
app.config.realtime.voice,
|
||||
app.chat_widget.config_ref().realtime.voice
|
||||
),
|
||||
(
|
||||
Some(codex_protocol::protocol::RealtimeVoice::Juniper),
|
||||
Some(codex_protocol::protocol::RealtimeVoice::Juniper)
|
||||
)
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
recorded_params(&requests, "config/batchWrite")[0]["edits"],
|
||||
serde_json::json!([{"keyPath": "realtime.voice", "value": "juniper", "mergeStrategy": "replace"}]),
|
||||
);
|
||||
if expected_voice != Some("juniper") {
|
||||
std::fs::write(
|
||||
app.config.codex_home.join("config.toml"),
|
||||
"[realtime]\ntype = \"conversational\"\n",
|
||||
)?;
|
||||
}
|
||||
// A reconnected TUI can retain a different local preference from its server.
|
||||
app.config.realtime.voice = Some(codex_protocol::protocol::RealtimeVoice::Maple);
|
||||
app.chat_widget
|
||||
.on_realtime_voice_saved(codex_protocol::protocol::RealtimeVoice::Maple);
|
||||
.handle_key_event(KeyEvent::from(KeyCode::Home));
|
||||
app.chat_widget
|
||||
.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
||||
Box::pin(app.handle_event(
|
||||
&mut tui,
|
||||
&mut app_server,
|
||||
next_voice_event(&mut events).await?,
|
||||
))
|
||||
.await?;
|
||||
Box::pin(app.handle_event(
|
||||
&mut tui,
|
||||
&mut app_server,
|
||||
next_voice_event(&mut events).await?,
|
||||
))
|
||||
.await?;
|
||||
crate::chatwidget::start_voice_attempt_for_test(
|
||||
&mut app.chat_widget,
|
||||
thread_id,
|
||||
@@ -220,34 +251,39 @@ async fn check_remote_voice_start(
|
||||
Box::pin(app.handle_event(
|
||||
&mut tui,
|
||||
&mut app_server,
|
||||
next_call_result(&mut events).await?,
|
||||
next_voice_event(&mut events).await?,
|
||||
))
|
||||
.await?;
|
||||
let calls = calls.received_requests().await.unwrap();
|
||||
assert_eq!(calls.len(), 1);
|
||||
assert_eq!(calls[0].headers["thread-id"], thread_id.to_string());
|
||||
assert_eq!(calls[0].headers["session-id"], thread_id.to_string());
|
||||
let voice_session_id = calls[0].headers["voice-session-id"].to_str()?;
|
||||
for request in &calls {
|
||||
assert!(!request.headers.contains_key("x-test-provider"));
|
||||
assert!(
|
||||
!request
|
||||
.url
|
||||
.query_pairs()
|
||||
.any(|(key, _)| key == "provider_option")
|
||||
);
|
||||
}
|
||||
let call = &calls[0];
|
||||
assert_eq!(call.headers["thread-id"], thread_id.to_string());
|
||||
assert_eq!(call.headers["session-id"], thread_id.to_string());
|
||||
assert_eq!(call.headers["chatgpt-account-id"], "local-voice-account");
|
||||
assert_eq!(call.headers["authorization"], "Bearer local-voice-token");
|
||||
let voice_session_id = call.headers["voice-session-id"].to_str()?;
|
||||
let uuid = uuid::Uuid::parse_str(voice_session_id)?;
|
||||
assert_eq!(uuid.get_version(), Some(uuid::Version::Random));
|
||||
assert_eq!(uuid.to_string(), voice_session_id);
|
||||
assert_ne!(voice_session_id, thread_id.to_string());
|
||||
if base_path == "/v1" {
|
||||
let body = std::str::from_utf8(&calls[0].body)?;
|
||||
assert!(body.contains(r#""voice":"marin""#));
|
||||
assert!(body.contains(r#""model":"gpt-live-1.1-codex""#));
|
||||
} else {
|
||||
let body = calls[0].body_json::<serde_json::Value>()?;
|
||||
assert_eq!(body["sdp"], "v=0\r\n");
|
||||
assert_eq!(body["session"]["model"], "gpt-live-1.1-codex");
|
||||
assert_eq!(
|
||||
body["session"]["audio"]["output"]["voice"],
|
||||
expected_voice.unwrap_or("cove")
|
||||
);
|
||||
}
|
||||
let body = call.body_json::<serde_json::Value>()?;
|
||||
assert_eq!(body["sdp"], "v=0\r\n");
|
||||
assert!(body["session"].get("model").is_none());
|
||||
assert!(body["session"].pointer("/audio/output/voice").is_none());
|
||||
assert!(recorded_params(&requests, "thread/realtime/listVoices").is_empty());
|
||||
let starts = recorded_params(&requests, "thread/realtime/start");
|
||||
assert_eq!(starts.len(), 1);
|
||||
let start = &starts[0];
|
||||
assert!(start.get("voice").is_none());
|
||||
assert_eq!(start["realtimeSessionId"], "rtc_tui");
|
||||
assert_eq!(start["voiceSessionId"], voice_session_id);
|
||||
assert_eq!(
|
||||
@@ -257,7 +293,6 @@ async fn check_remote_voice_start(
|
||||
"includeStartupContext": start["includeStartupContext"],
|
||||
"outputModality": start["outputModality"],
|
||||
"version": start["version"],
|
||||
"voice": start["voice"],
|
||||
"transport": start["transport"],
|
||||
}),
|
||||
serde_json::json!({
|
||||
@@ -266,7 +301,6 @@ async fn check_remote_voice_start(
|
||||
"includeStartupContext": false,
|
||||
"outputModality": "audio",
|
||||
"version": "v3",
|
||||
"voice": null,
|
||||
"transport": {"type": "existingCall", "callId": "rtc_tui"},
|
||||
})
|
||||
);
|
||||
@@ -282,10 +316,10 @@ async fn voice_cancel_restart_only_attaches_the_new_attempt() -> Result<()> {
|
||||
let (mut app, mut events, mut ops) = make_test_app_with_channels().await;
|
||||
let (request_tx, mut requests) = tokio::sync::mpsc::unbounded_channel();
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?;
|
||||
app.config.experimental_realtime_webrtc_call_base_url =
|
||||
Some(format!("http://{}/backend-api", listener.local_addr()?));
|
||||
let backend = format!("http://{}", listener.local_addr()?);
|
||||
use_local_voice_account(&mut app.config, &backend);
|
||||
let provider = axum::Router::new().route(
|
||||
"/backend-api/realtime/calls",
|
||||
"/backend-api/codex/realtime/calls",
|
||||
axum::routing::post(move || {
|
||||
let request_tx = request_tx.clone();
|
||||
async move {
|
||||
@@ -340,7 +374,7 @@ async fn voice_cancel_restart_only_attaches_the_new_attempt() -> Result<()> {
|
||||
(Some(first), None)
|
||||
} else {
|
||||
first.send("/realtime/calls/rtc_old").unwrap();
|
||||
(None, Some(next_call_result(&mut events).await?))
|
||||
(None, Some(next_voice_event(&mut events).await?))
|
||||
};
|
||||
Box::pin(app.handle_event(
|
||||
&mut tui,
|
||||
@@ -366,7 +400,7 @@ async fn voice_cancel_restart_only_attaches_the_new_attempt() -> Result<()> {
|
||||
Box::pin(app.handle_event(&mut tui, &mut server, stale)).await?;
|
||||
}
|
||||
second.send("/realtime/calls/rtc_new").unwrap();
|
||||
Box::pin(app.handle_event(&mut tui, &mut server, next_call_result(&mut events).await?))
|
||||
Box::pin(app.handle_event(&mut tui, &mut server, next_voice_event(&mut events).await?))
|
||||
.await?;
|
||||
let starts = recorded_params(&rpc, "thread/realtime/start");
|
||||
assert_eq!(starts.len(), 1);
|
||||
@@ -1926,336 +1960,90 @@ async fn delegated_final_speech_reaches_app_server_once_and_stale_speech_is_reje
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn rejected_voice_setting_preserves_current_selection() -> Result<()> {
|
||||
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
|
||||
let (mut app_server, _requests, proxy) = start_recording_remote_app_server(&app.config).await?;
|
||||
let previous = (
|
||||
app.config.realtime.voice,
|
||||
app.chat_widget.config_ref().realtime.voice,
|
||||
);
|
||||
std::fs::write(app.config.codex_home.join("config.toml"), "realtime = [")?;
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
Box::pin(app.handle_event(
|
||||
&mut tui,
|
||||
&mut app_server,
|
||||
AppEvent::PersistRealtimeVoiceSelection {
|
||||
voice: codex_protocol::protocol::RealtimeVoice::Juniper,
|
||||
},
|
||||
))
|
||||
.await?;
|
||||
assert_eq!(
|
||||
(
|
||||
app.config.realtime.voice,
|
||||
app.chat_widget.config_ref().realtime.voice
|
||||
),
|
||||
previous,
|
||||
);
|
||||
let messages = std::iter::from_fn(|| events.try_recv().ok())
|
||||
.filter_map(|event| match event {
|
||||
AppEvent::InsertHistoryCell(cell) => Some(
|
||||
cell.display_lines(/*width*/ 80)
|
||||
.into_iter()
|
||||
.map(|line| line.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
assert!(messages.contains("Failed to save voice"));
|
||||
app_server.shutdown().await?;
|
||||
proxy.await??;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_voice_config_read_failure_does_not_start_with_local_voice() -> Result<()> {
|
||||
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
|
||||
let (mut app_server, requests, proxy) = start_recording_remote_app_server(&app.config).await?;
|
||||
std::fs::write(app.config.codex_home.join("config.toml"), "realtime = [")?;
|
||||
let thread_id = ThreadId::new();
|
||||
crate::chatwidget::start_voice_attempt_for_test(
|
||||
&mut app.chat_widget,
|
||||
thread_id,
|
||||
/*attempt_id*/ 1,
|
||||
);
|
||||
app.try_submit_active_thread_op_via_app_server(
|
||||
&mut app_server,
|
||||
thread_id,
|
||||
&AppCommand::RealtimeConversationStart {
|
||||
thread_id,
|
||||
attempt_id: 1,
|
||||
offer_sdp: String::from("v=0\r\n").into(),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
let AppEvent::RealtimeCallCreated {
|
||||
result: Err(error), ..
|
||||
} = next_call_result(&mut events).await?
|
||||
else {
|
||||
panic!("invalid server config must not fall back to local voice");
|
||||
};
|
||||
assert!(error.to_string().contains("config/read"));
|
||||
assert!(recorded_params(&requests, "thread/realtime/start").is_empty());
|
||||
app_server.shutdown().await?;
|
||||
proxy.await??;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn embedded_voice_settings_follow_project_after_thread_switch() -> Result<()> {
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
|
||||
let calls = mock_voice_calls(&mut app.config, "/backend-api").await;
|
||||
let projects = tempfile::tempdir()?;
|
||||
for voice in [RealtimeVoice::Maple, RealtimeVoice::Sol] {
|
||||
let cwd = projects.path().join(voice.wire_name());
|
||||
std::fs::create_dir_all(cwd.join(".codex"))?;
|
||||
std::fs::write(
|
||||
cwd.join(".codex/config.toml"),
|
||||
format!("[realtime]\nvoice = \"{}\"\n", voice.wire_name()),
|
||||
)?;
|
||||
crate::legacy_core::config::set_project_trust_level(
|
||||
&app.config.codex_home,
|
||||
&cwd,
|
||||
codex_protocol::config_types::TrustLevel::Trusted,
|
||||
)
|
||||
.map_err(|error| color_eyre::eyre::eyre!(error.to_string()))?;
|
||||
}
|
||||
app.config.realtime.voice = Some(RealtimeVoice::Maple);
|
||||
let (mut server, requests, proxy) = start_recording_realtime_speech_app_server(
|
||||
&app.config,
|
||||
RealtimeRequestBehavior::AcceptStart,
|
||||
)
|
||||
.await?;
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
let mut threads = Vec::new();
|
||||
for voice in [RealtimeVoice::Maple, RealtimeVoice::Sol] {
|
||||
let cwd = projects.path().join(voice.wire_name());
|
||||
let config = app.rebuild_config_for_cwd(cwd).await?;
|
||||
let started = server.start_thread(&config).await?;
|
||||
let thread_id = started.session.thread_id;
|
||||
app.thread_event_channels.insert(
|
||||
thread_id,
|
||||
ThreadEventChannel::new_with_session(
|
||||
THREAD_EVENT_CHANNEL_CAPACITY,
|
||||
started.session,
|
||||
Vec::new(),
|
||||
),
|
||||
);
|
||||
threads.push((thread_id, voice));
|
||||
}
|
||||
for (thread_id, voice) in [threads[0], threads[1], threads[0]] {
|
||||
Box::pin(app.select_agent_thread(&mut tui, &mut server, thread_id)).await?;
|
||||
app.open_realtime_voices(&server).await;
|
||||
let popup = crate::chatwidget::tests::helpers::render_bottom_popup(
|
||||
&app.chat_widget,
|
||||
/*width*/ 80,
|
||||
);
|
||||
assert!(
|
||||
popup.contains(&format!("{} (current)", voice.wire_name())),
|
||||
"{popup}"
|
||||
);
|
||||
crate::chatwidget::start_voice_attempt_for_test(
|
||||
&mut app.chat_widget,
|
||||
thread_id,
|
||||
/*attempt_id*/ 1,
|
||||
);
|
||||
app.try_submit_active_thread_op_via_app_server(
|
||||
&mut server,
|
||||
thread_id,
|
||||
&AppCommand::RealtimeConversationStart {
|
||||
thread_id,
|
||||
attempt_id: 1,
|
||||
offer_sdp: String::from("v=0\r\n").into(),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
Box::pin(app.handle_event(&mut tui, &mut server, next_call_result(&mut events).await?))
|
||||
.await?;
|
||||
app.chat_widget.reset_realtime_conversation();
|
||||
let calls = calls.received_requests().await.unwrap();
|
||||
let body = calls.last().unwrap().body_json::<serde_json::Value>()?;
|
||||
assert_eq!(
|
||||
body["session"]["audio"]["output"]["voice"],
|
||||
serde_json::json!(voice)
|
||||
);
|
||||
assert_eq!(
|
||||
recorded_params(&requests, "thread/realtime/start")
|
||||
.last()
|
||||
.unwrap()["transport"]["callId"],
|
||||
"rtc_tui"
|
||||
);
|
||||
}
|
||||
server.shutdown().await?;
|
||||
proxy.await??;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_voice_picker_reads_server_preference() -> Result<()> {
|
||||
let (mut app, _events, _ops) = make_test_app_with_channels().await;
|
||||
std::fs::write(
|
||||
app.config.codex_home.join("config.toml"),
|
||||
"[realtime]\nvoice = \"sol\"\n",
|
||||
)?;
|
||||
app.chat_widget
|
||||
.set_realtime_voice(Some(codex_protocol::protocol::RealtimeVoice::Maple));
|
||||
let (server, requests, proxy) = start_recording_remote_app_server(&app.config).await?;
|
||||
app.open_realtime_voices(&server).await;
|
||||
assert_eq!(
|
||||
recorded_params(&requests, "thread/realtime/listVoices").len(),
|
||||
1
|
||||
);
|
||||
insta::assert_snapshot!(
|
||||
"remote_voice_picker",
|
||||
crate::chatwidget::tests::helpers::render_bottom_popup(&app.chat_widget, /*width*/ 80)
|
||||
);
|
||||
server.shutdown().await?;
|
||||
proxy.await??;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remote_voice_catalog_success_and_failure() -> Result<()> {
|
||||
use super::session_lifecycle_requests::HistoryCapabilities;
|
||||
for (capabilities, expected_catalog) in [
|
||||
(HistoryCapabilities::VoiceCatalogCustom, true),
|
||||
(HistoryCapabilities::VoiceCatalogUnavailable, false),
|
||||
] {
|
||||
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
|
||||
let (server, requests, proxy) =
|
||||
super::session_lifecycle_requests::start_recording_app_server_with_realtime_speech(
|
||||
&app.config,
|
||||
capabilities,
|
||||
/*blocked_thread_list*/ None,
|
||||
/*failed_thread_name*/ None,
|
||||
crate::app_server_session::ThreadParamsMode::Remote,
|
||||
RealtimeRequestBehavior::Forward,
|
||||
codex_config::LoaderOverrides::default(),
|
||||
)
|
||||
.await?;
|
||||
while events.try_recv().is_ok() {}
|
||||
app.open_realtime_voices(&server).await;
|
||||
let popup = crate::chatwidget::tests::helpers::render_bottom_popup(
|
||||
&app.chat_widget,
|
||||
/*width*/ 80,
|
||||
);
|
||||
assert_eq!(popup.contains("1. maple"), expected_catalog);
|
||||
assert!(!popup.contains("(current)"));
|
||||
assert!(!popup.contains(" 3. spruce"));
|
||||
if expected_catalog {
|
||||
insta::assert_snapshot!("remote_voice_picker_server_default", popup);
|
||||
}
|
||||
assert_eq!(
|
||||
recorded_params(&requests, "thread/realtime/listVoices").len(),
|
||||
1
|
||||
);
|
||||
if !expected_catalog {
|
||||
assert!(!app.chat_widget.has_active_view());
|
||||
let messages = std::iter::from_fn(|| events.try_recv().ok())
|
||||
.filter_map(|event| match event {
|
||||
AppEvent::InsertHistoryCell(cell) => Some(
|
||||
cell.display_lines(/*width*/ 80)
|
||||
.into_iter()
|
||||
.map(|line| line.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
insta::assert_snapshot!("voice_catalog_failure_picker", messages);
|
||||
}
|
||||
server.shutdown().await?;
|
||||
proxy.await??;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn overridden_voice_save_keeps_effective_voice() -> Result<()> {
|
||||
for project_override in [false, true] {
|
||||
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
|
||||
let project = tempfile::tempdir()?;
|
||||
let overrides = if project_override {
|
||||
std::fs::create_dir_all(project.path().join(".codex"))?;
|
||||
std::fs::write(
|
||||
project.path().join(".codex/config.toml"),
|
||||
"[realtime]\nvoice = \"maple\"\n",
|
||||
)?;
|
||||
crate::legacy_core::config::set_project_trust_level(
|
||||
&app.config.codex_home,
|
||||
project.path(),
|
||||
codex_protocol::config_types::TrustLevel::Trusted,
|
||||
)
|
||||
.map_err(|error| color_eyre::eyre::eyre!(error.to_string()))?;
|
||||
app.config.cwd = AbsolutePathBuf::from_absolute_path(project.path())?;
|
||||
app.chat_widget
|
||||
.handle_thread_session_quiet(test_thread_session(
|
||||
ThreadId::new(),
|
||||
project.path().to_path_buf(),
|
||||
));
|
||||
Vec::new()
|
||||
} else {
|
||||
vec![(
|
||||
"realtime.voice".to_string(),
|
||||
toml::Value::String("maple".to_string()),
|
||||
)]
|
||||
};
|
||||
let client = crate::start_embedded_app_server(
|
||||
codex_arg0::Arg0DispatchPaths::default(),
|
||||
app.config.clone(),
|
||||
overrides,
|
||||
codex_config::LoaderOverrides::without_managed_config_for_tests(),
|
||||
/*strict_config*/ false,
|
||||
codex_config::CloudConfigBundleLoader::default(),
|
||||
codex_feedback::CodexFeedback::new(),
|
||||
/*log_db*/ None,
|
||||
/*state_db*/ None,
|
||||
Arc::new(codex_exec_server::EnvironmentManager::default_for_tests()),
|
||||
Default::default(),
|
||||
)
|
||||
.await?;
|
||||
let server = AppServerSession::new(
|
||||
crate::backend_id::BackendId::new(),
|
||||
codex_app_server_client::AppServerClient::InProcess(client),
|
||||
crate::app_server_session::ThreadParamsMode::Embedded,
|
||||
);
|
||||
while events.try_recv().is_ok() {}
|
||||
app.persist_realtime_voice(&server, codex_protocol::protocol::RealtimeVoice::Juniper)
|
||||
for status in [200, 403] {
|
||||
let (mut app, mut events, _) = make_test_app_with_channels().await;
|
||||
let backend = wiremock::MockServer::start().await;
|
||||
configure_voice_settings_server(&mut app.config, &backend.uri())?;
|
||||
wiremock::Mock::given(wiremock::matchers::method("GET"))
|
||||
.and(wiremock::matchers::path("/backend-api/settings/voices"))
|
||||
.respond_with(wiremock::ResponseTemplate::new(status).set_body_json(
|
||||
serde_json::json!({
|
||||
"selected": "glimmer",
|
||||
"voices": [
|
||||
{"voice": "glimmer", "name": "Sol"},
|
||||
{"voice": "xiaoman", "name": "Xiaoman"}
|
||||
]
|
||||
}),
|
||||
))
|
||||
.mount(&backend)
|
||||
.await;
|
||||
assert_eq!(
|
||||
(
|
||||
app.config.realtime.voice,
|
||||
app.chat_widget.config_ref().realtime.voice
|
||||
),
|
||||
(
|
||||
Some(codex_protocol::protocol::RealtimeVoice::Maple),
|
||||
Some(codex_protocol::protocol::RealtimeVoice::Maple)
|
||||
),
|
||||
);
|
||||
let message = std::iter::from_fn(|| events.try_recv().ok())
|
||||
.filter_map(|event| match event {
|
||||
AppEvent::InsertHistoryCell(cell) => Some(
|
||||
cell.display_lines(/*width*/ 80)
|
||||
.into_iter()
|
||||
.map(|line| line.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
assert!(message.contains("saved but not applied"));
|
||||
if !project_override {
|
||||
insta::assert_snapshot!("overridden_voice_save", message);
|
||||
|
||||
let mut app_server =
|
||||
Box::pin(crate::start_embedded_app_server_for_picker(&app.config)).await?;
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
futures::FutureExt::now_or_never(Box::pin(app.handle_event(
|
||||
&mut tui,
|
||||
&mut app_server,
|
||||
AppEvent::OpenRealtimeVoices,
|
||||
)))
|
||||
.expect("opening the picker must return before the catalog responds")?;
|
||||
Box::pin(app.handle_event(
|
||||
&mut tui,
|
||||
&mut app_server,
|
||||
next_voice_event(&mut events).await?,
|
||||
))
|
||||
.await?;
|
||||
if status == 200 {
|
||||
let popup = crate::chatwidget::tests::helpers::render_bottom_popup(
|
||||
&app.chat_widget,
|
||||
/*width*/ 80,
|
||||
);
|
||||
insta::assert_snapshot!("remote_voice_picker_server_default", popup);
|
||||
wiremock::Mock::given(wiremock::matchers::method("PATCH"))
|
||||
.and(wiremock::matchers::path(
|
||||
"/backend-api/settings/account_user_setting",
|
||||
))
|
||||
.respond_with(
|
||||
wiremock::ResponseTemplate::new(403).set_body_string("backend details"),
|
||||
)
|
||||
.mount(&backend)
|
||||
.await;
|
||||
app.chat_widget
|
||||
.handle_key_event(KeyEvent::from(KeyCode::Home));
|
||||
app.chat_widget
|
||||
.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
||||
let selection = next_voice_event(&mut events).await?;
|
||||
futures::FutureExt::now_or_never(Box::pin(app.handle_event(
|
||||
&mut tui,
|
||||
&mut app_server,
|
||||
selection,
|
||||
)))
|
||||
.expect("selecting a voice must return before the save responds")?;
|
||||
Box::pin(app.handle_event(
|
||||
&mut tui,
|
||||
&mut app_server,
|
||||
next_voice_event(&mut events).await?,
|
||||
))
|
||||
.await?;
|
||||
assert_eq!(next_history_message(&mut events), "■ Failed to save voice");
|
||||
assert!(
|
||||
backend
|
||||
.received_requests()
|
||||
.await
|
||||
.unwrap()
|
||||
.iter()
|
||||
.all(|r| r.headers["chatgpt-account-id"] == "server-account")
|
||||
);
|
||||
} else {
|
||||
assert!(!app.chat_widget.has_active_view());
|
||||
assert_eq!(
|
||||
next_history_message(&mut events),
|
||||
"■ Failed to read voice settings"
|
||||
);
|
||||
}
|
||||
server.shutdown().await?;
|
||||
app_server.shutdown().await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1841,9 +1841,6 @@ pub(super) enum HistoryCapabilities {
|
||||
ConfigReadUnsupported(i64),
|
||||
ConfigReadFails,
|
||||
SuperBindingsUnsupported,
|
||||
ConfigReadUnknownVoice,
|
||||
VoiceCatalogCustom,
|
||||
VoiceCatalogUnavailable,
|
||||
}
|
||||
|
||||
/// Returns and resets `(thread/loaded/list, thread/read)` request counts.
|
||||
@@ -2137,17 +2134,6 @@ pub(super) async fn start_recording_app_server_with_realtime_speech(
|
||||
.to_string(),
|
||||
},
|
||||
})
|
||||
} else if history_capabilities == HistoryCapabilities::VoiceCatalogUnavailable
|
||||
&& request.method == "thread/realtime/listVoices"
|
||||
{
|
||||
JSONRPCMessage::Error(JSONRPCError {
|
||||
id: request_id,
|
||||
error: JSONRPCErrorError {
|
||||
code: -32601,
|
||||
data: None,
|
||||
message: "method not found".to_string(),
|
||||
},
|
||||
})
|
||||
} else if matches!(
|
||||
history_capabilities,
|
||||
HistoryCapabilities::ThreadStartFails
|
||||
@@ -2284,27 +2270,10 @@ pub(super) async fn start_recording_app_server_with_realtime_speech(
|
||||
},
|
||||
})
|
||||
} else {
|
||||
let unknown_voice = history_capabilities
|
||||
== HistoryCapabilities::ConfigReadUnknownVoice
|
||||
&& matches!(&request, ClientRequest::ConfigRead { .. });
|
||||
let custom_voice_catalog = history_capabilities
|
||||
== HistoryCapabilities::VoiceCatalogCustom
|
||||
&& matches!(
|
||||
&request,
|
||||
ClientRequest::ThreadRealtimeListVoices { .. }
|
||||
);
|
||||
let mut result = embedded.request(request).await?;
|
||||
if advertise_paginated && let Ok(value) = &mut result {
|
||||
value["thread"]["historyMode"] = serde_json::json!("paginated");
|
||||
}
|
||||
if unknown_voice && let Ok(value) = &mut result {
|
||||
value["config"]["realtime"]["voice"] =
|
||||
serde_json::json!("future_voice");
|
||||
}
|
||||
if custom_voice_catalog && let Ok(value) = &mut result {
|
||||
value["voices"]["v3"] =
|
||||
serde_json::json!(["maple", "cove", "juniper"]);
|
||||
}
|
||||
if background {
|
||||
let terminal = r#"{"data":[{"itemId":"x","processId":"x","command":"x","cwd":"/"}],"nextCursor":null}"#;
|
||||
result = Ok(serde_json::from_str(terminal)?);
|
||||
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
---
|
||||
source: tui/src/app/tests/realtime_requests.rs
|
||||
assertion_line: 1679
|
||||
expression: message
|
||||
---
|
||||
■ Voice preference was saved but not applied: Overridden by session flags
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
---
|
||||
source: tui/src/app/tests/realtime_requests.rs
|
||||
expression: "crate::chatwidget::tests::helpers::render_bottom_popup(&app.chat_widget, 80)"
|
||||
---
|
||||
Select voice
|
||||
Applies to your next voice conversation.
|
||||
|
||||
|
||||
1. juniper
|
||||
2. maple
|
||||
3. spruce
|
||||
4. ember
|
||||
5. vale
|
||||
6. breeze
|
||||
7. arbor
|
||||
› 8. sol (current)
|
||||
↓
|
||||
enter select · esc back
|
||||
+3
-4
@@ -6,9 +6,8 @@ expression: popup
|
||||
Applies to your next voice conversation.
|
||||
|
||||
|
||||
› 1. maple
|
||||
2. cove
|
||||
3. juniper
|
||||
4. Back
|
||||
› 1. Sol (current)
|
||||
2. Xiaoman
|
||||
3. Back
|
||||
|
||||
enter select · esc back
|
||||
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
---
|
||||
source: tui/src/app/tests/realtime_requests.rs
|
||||
expression: messages
|
||||
---
|
||||
■ Failed to list voices: thread/realtime/listVoices failed: method not found (code -32601)
|
||||
@@ -926,17 +926,15 @@ impl App {
|
||||
let registration = self.chat_widget.begin_call_negotiation();
|
||||
let mut server = app_server.request_view();
|
||||
let config = self.config.clone();
|
||||
let cwd = self.chat_widget.config_ref().cwd.clone();
|
||||
let offer = String::from(offer_sdp.clone());
|
||||
let call_client = Arc::clone(&self.realtime_call_client);
|
||||
let tx = self.app_event_tx.clone();
|
||||
tokio::spawn(async move {
|
||||
let create = async {
|
||||
let voice = Self::effective_realtime_voice(&server, &cwd).await?;
|
||||
let thread = server
|
||||
.thread_read(thread_id, /*include_turns*/ false)
|
||||
.await?;
|
||||
call_client.create(&config, &thread, offer, voice).await
|
||||
call_client.create(&config, &thread, offer).await
|
||||
};
|
||||
if let Ok(result) = futures::future::Abortable::new(create, registration).await
|
||||
{
|
||||
|
||||
@@ -48,7 +48,7 @@ impl App {
|
||||
(self.chat_widget.thread_id() == Some(thread_id)).then_some(&mut self.chat_widget)
|
||||
}
|
||||
|
||||
pub(super) fn control_voice(&mut self, control: VoiceControl) {
|
||||
pub(super) async fn control_voice(&mut self, control: VoiceControl) {
|
||||
if let Some(thread_id) = self.voice_owner_thread_id()
|
||||
&& let Some(owner) = self.voice_widget_for_thread(thread_id)
|
||||
{
|
||||
@@ -57,7 +57,10 @@ impl App {
|
||||
VoiceControl::Stop => owner.stop_realtime_conversation(),
|
||||
VoiceControl::Mute => owner.toggle_realtime_microphone(),
|
||||
}
|
||||
} else if matches!(control, VoiceControl::Toggle) && !self.reconnect.offline {
|
||||
} else if matches!(control, VoiceControl::Toggle)
|
||||
&& !self.reconnect.offline
|
||||
&& self.ensure_voice_account().await
|
||||
{
|
||||
// Preserve the ended owner's transcript before allowing another call.
|
||||
self.retire_background_voice();
|
||||
self.chat_widget.toggle_realtime_conversation();
|
||||
|
||||
@@ -1582,7 +1582,6 @@ pub(crate) enum AppEvent {
|
||||
/// Show the cyber auto-review notice after the model selection confirmation.
|
||||
CyberModelAutoReviewNotice,
|
||||
|
||||
/// Read the owning server preference before showing the voice picker.
|
||||
OpenRealtimeSettings,
|
||||
OpenRealtimeSoundDevices,
|
||||
OpenRealtimeVoices,
|
||||
@@ -1605,9 +1604,16 @@ pub(crate) enum AppEvent {
|
||||
channel: Option<codex_config::config_toml::MicrophoneChannels>,
|
||||
},
|
||||
|
||||
/// Save the voice for subsequent conversations through the app server.
|
||||
RealtimeVoicesLoaded {
|
||||
origin: Option<ThreadId>,
|
||||
result: anyhow::Result<codex_app_server_protocol::AccountVoiceSettingsReadResponse>,
|
||||
},
|
||||
PersistRealtimeVoiceSelection {
|
||||
voice: codex_protocol::protocol::RealtimeVoice,
|
||||
voice: codex_app_server_protocol::AccountVoiceOption,
|
||||
},
|
||||
RealtimeVoiceSaved {
|
||||
origin: Option<ThreadId>,
|
||||
result: anyhow::Result<String>,
|
||||
},
|
||||
|
||||
/// Toggle the service tier staged for the next Cloud submission.
|
||||
|
||||
@@ -52,7 +52,6 @@ impl AppServerSession {
|
||||
call_id,
|
||||
}),
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
voice: None,
|
||||
},
|
||||
})
|
||||
.await
|
||||
|
||||
@@ -375,11 +375,6 @@ impl ChatWidget {
|
||||
self.on_shutdown_complete();
|
||||
}
|
||||
}
|
||||
ServerNotification::ThreadRealtimeSdp(notification) => {
|
||||
if !from_replay {
|
||||
self.on_realtime_conversation_sdp(notification.sdp);
|
||||
}
|
||||
}
|
||||
ServerNotification::ThreadRealtimeStarted(_) => {
|
||||
if !from_replay {
|
||||
self.on_realtime_conversation_started();
|
||||
@@ -438,6 +433,7 @@ impl ChatWidget {
|
||||
| ServerNotification::ThreadSearchPartial(_)
|
||||
| ServerNotification::FuzzyFileSearchSessionUpdated(_)
|
||||
| ServerNotification::FuzzyFileSearchSessionCompleted(_)
|
||||
| ServerNotification::ThreadRealtimeSdp(_)
|
||||
| ServerNotification::ThreadRealtimeItemAdded(_)
|
||||
| ServerNotification::ThreadRealtimeItemStarted(_)
|
||||
| ServerNotification::ThreadRealtimeItemTranscriptDelta(_)
|
||||
|
||||
@@ -477,13 +477,6 @@ impl ChatWidget {
|
||||
|
||||
pub(crate) fn accept_realtime_call(&mut self, answer: crate::app_command::RealtimeSdp) {
|
||||
self.realtime_conversation.startup_abort = None;
|
||||
self.on_realtime_conversation_sdp(answer.into());
|
||||
}
|
||||
|
||||
pub(crate) fn on_realtime_conversation_sdp(&mut self, answer_sdp: String) {
|
||||
if self.realtime_conversation.phase != RealtimeConversationPhase::Starting {
|
||||
return;
|
||||
}
|
||||
let Some(handle) = self.realtime_conversation.handle.clone() else {
|
||||
return;
|
||||
};
|
||||
@@ -493,7 +486,7 @@ impl ChatWidget {
|
||||
let attempt_id = self.realtime_conversation.attempt_id;
|
||||
let app_event_tx = self.app_event_tx.clone();
|
||||
std::thread::spawn(move || {
|
||||
let result = handle.apply_answer_sdp(answer_sdp);
|
||||
let result = handle.apply_answer_sdp(answer.into());
|
||||
app_event_tx.send(AppEvent::RealtimeWebrtcConnected {
|
||||
thread_id,
|
||||
attempt_id,
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
use super::*;
|
||||
use crate::bottom_pane::MultiSelectItem;
|
||||
use crate::bottom_pane::MultiSelectPicker;
|
||||
use codex_app_server_protocol::AccountVoiceSettingsReadResponse;
|
||||
use codex_config::config_toml::MicrophoneChannels;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
use codex_protocol::protocol::RealtimeVoicesList;
|
||||
use codex_realtime_webrtc::AudioDevice;
|
||||
use codex_realtime_webrtc::AudioDeviceKind;
|
||||
|
||||
@@ -53,19 +52,17 @@ impl ChatWidget {
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn open_realtime_voices(
|
||||
&mut self,
|
||||
current: Option<RealtimeVoice>,
|
||||
voices: RealtimeVoicesList,
|
||||
) {
|
||||
let mut items: Vec<SelectionItem> = voices
|
||||
.v3
|
||||
pub(crate) fn open_realtime_voices(&mut self, settings: AccountVoiceSettingsReadResponse) {
|
||||
let mut items: Vec<SelectionItem> = settings
|
||||
.voices
|
||||
.into_iter()
|
||||
.map(|voice| SelectionItem {
|
||||
name: voice.wire_name().to_string(),
|
||||
is_current: Some(voice) == current,
|
||||
name: voice.name.clone(),
|
||||
is_current: voice.voice == settings.selected,
|
||||
actions: vec![Box::new(move |tx| {
|
||||
tx.send(AppEvent::PersistRealtimeVoiceSelection { voice });
|
||||
tx.send(AppEvent::PersistRealtimeVoiceSelection {
|
||||
voice: voice.clone(),
|
||||
});
|
||||
})],
|
||||
dismiss_on_select: true,
|
||||
..Default::default()
|
||||
@@ -74,7 +71,7 @@ impl ChatWidget {
|
||||
items.push(back_item(|| AppEvent::OpenRealtimeSettings));
|
||||
self.bottom_pane.show_selection_view(SelectionViewParams {
|
||||
title: Some("Select voice".to_string()),
|
||||
subtitle: Some("Applies to your next voice conversation.".to_string()),
|
||||
subtitle: Some("Applies to your next voice conversation.".into()),
|
||||
footer_hint: Some(standard_popup_hint_line()),
|
||||
items,
|
||||
on_cancel: Some(Box::new(|tx| tx.send(AppEvent::OpenRealtimeSettings))),
|
||||
@@ -267,21 +264,6 @@ impl ChatWidget {
|
||||
.build();
|
||||
self.bottom_pane.show_view(Box::new(picker));
|
||||
}
|
||||
|
||||
pub(crate) fn set_realtime_voice(&mut self, voice: Option<RealtimeVoice>) {
|
||||
self.config.realtime.voice = voice;
|
||||
}
|
||||
|
||||
pub(crate) fn on_realtime_voice_saved(&mut self, voice: RealtimeVoice) {
|
||||
self.set_realtime_voice(Some(voice));
|
||||
self.add_info_message(
|
||||
format!(
|
||||
"Voice set to {}. Applies to your next voice conversation.",
|
||||
voice.wire_name()
|
||||
),
|
||||
/*hint*/ None,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use super::*;
|
||||
use crate::chatwidget::tests::make_chatwidget_manual_with_sender;
|
||||
use crate::chatwidget::tests::render_bottom_popup;
|
||||
use codex_app_server_protocol::AccountVoiceOption;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyModifiers;
|
||||
@@ -11,7 +12,6 @@ use pretty_assertions::assert_eq;
|
||||
#[tokio::test]
|
||||
async fn voice_settings_selects_a_voice_without_starting_audio() {
|
||||
let (mut chat, _sender, mut events, mut ops) = make_chatwidget_manual_with_sender().await;
|
||||
chat.config.realtime.voice = Some(RealtimeVoice::Maple);
|
||||
chat.dispatch_command_with_args(SlashCommand::Voice, "settings".to_string(), Vec::new());
|
||||
assert!(
|
||||
std::iter::from_fn(|| events.try_recv().ok())
|
||||
@@ -27,55 +27,29 @@ async fn voice_settings_selects_a_voice_without_starting_audio() {
|
||||
std::iter::from_fn(|| events.try_recv().ok())
|
||||
.any(|event| matches!(event, AppEvent::OpenRealtimeVoices))
|
||||
);
|
||||
chat.open_realtime_voices(Some(RealtimeVoice::Maple), RealtimeVoicesList::builtin());
|
||||
insta::assert_snapshot!("voice_choices", render_bottom_popup(&chat, /*width*/ 80));
|
||||
chat.open_realtime_voices(AccountVoiceSettingsReadResponse {
|
||||
selected: "maple".into(),
|
||||
voices: ["juniper", "maple"]
|
||||
.into_iter()
|
||||
.map(|voice| AccountVoiceOption {
|
||||
voice: voice.into(),
|
||||
name: voice.into(),
|
||||
})
|
||||
.collect(),
|
||||
});
|
||||
chat.bottom_pane
|
||||
.handle_key_event(KeyEvent::new(KeyCode::Home, KeyModifiers::NONE));
|
||||
chat.bottom_pane
|
||||
.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
let voice = std::iter::from_fn(|| events.try_recv().ok()).find_map(|event| match event {
|
||||
AppEvent::PersistRealtimeVoiceSelection { voice } => Some(voice),
|
||||
AppEvent::PersistRealtimeVoiceSelection { voice, .. } => Some(voice.voice),
|
||||
_ => None,
|
||||
});
|
||||
assert_eq!(voice, Some(RealtimeVoice::Juniper));
|
||||
assert_eq!(chat.config.realtime.voice, Some(RealtimeVoice::Maple));
|
||||
assert_eq!(voice.as_deref(), Some("juniper"));
|
||||
assert!(ops.try_recv().is_err());
|
||||
assert!(!chat.realtime_conversation_is_running());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn saved_voice_confirmation_snapshot() {
|
||||
let (mut chat, _sender, mut events, _ops) = make_chatwidget_manual_with_sender().await;
|
||||
while events.try_recv().is_ok() {}
|
||||
chat.on_realtime_voice_saved(RealtimeVoice::Juniper);
|
||||
let lines = std::iter::from_fn(|| events.try_recv().ok())
|
||||
.filter_map(|event| match event {
|
||||
AppEvent::InsertHistoryCell(cell) => Some(cell.display_lines(/*width*/ 80)),
|
||||
_ => None,
|
||||
})
|
||||
.flatten()
|
||||
.map(|line| line.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
insta::assert_snapshot!("saved_voice_confirmation", lines);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn voice_settings_uses_server_catalog() {
|
||||
let (mut chat, _sender, _events, _ops) = make_chatwidget_manual_with_sender().await;
|
||||
chat.open_realtime_voices(
|
||||
Some(RealtimeVoice::Cove),
|
||||
RealtimeVoicesList {
|
||||
v3: vec![RealtimeVoice::Cove, RealtimeVoice::Maple],
|
||||
..RealtimeVoicesList::builtin()
|
||||
},
|
||||
);
|
||||
insta::assert_snapshot!(
|
||||
"voice_settings_server_catalog",
|
||||
render_bottom_popup(&chat, /*width*/ 80)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn microphone_channel_picker_routes_selection_without_starting_audio() {
|
||||
let (mut chat, _sender, mut events, mut ops) = make_chatwidget_manual_with_sender().await;
|
||||
@@ -196,7 +170,12 @@ async fn submenus_return_to_their_parent_with_back_or_escape() {
|
||||
type OpenMenu = fn(&mut ChatWidget);
|
||||
let menus: [(OpenMenu, bool); 3] = [
|
||||
(
|
||||
|chat| chat.open_realtime_voices(/*current*/ None, RealtimeVoicesList::builtin()),
|
||||
|chat| {
|
||||
chat.open_realtime_voices(AccountVoiceSettingsReadResponse {
|
||||
selected: String::new(),
|
||||
voices: Vec::new(),
|
||||
})
|
||||
},
|
||||
false,
|
||||
),
|
||||
(ChatWidget::open_realtime_sound_devices, false),
|
||||
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
---
|
||||
source: tui/src/chatwidget/realtime_settings_tests.rs
|
||||
assertion_line: 46
|
||||
expression: lines
|
||||
---
|
||||
• Voice set to juniper. Applies to your next voice conversation.
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
---
|
||||
source: tui/src/chatwidget/realtime_settings_tests.rs
|
||||
expression: "render_bottom_popup(&chat, 80)"
|
||||
---
|
||||
Select voice
|
||||
Applies to your next voice conversation.
|
||||
|
||||
|
||||
1. juniper
|
||||
› 2. maple (current)
|
||||
3. spruce
|
||||
4. ember
|
||||
5. vale
|
||||
6. breeze
|
||||
7. arbor
|
||||
8. sol
|
||||
↓
|
||||
enter select · esc back
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
---
|
||||
source: tui/src/chatwidget/realtime_settings_tests.rs
|
||||
expression: "render_bottom_popup(&chat, 80)"
|
||||
---
|
||||
Select voice
|
||||
Applies to your next voice conversation.
|
||||
|
||||
|
||||
› 1. cove (current)
|
||||
2. maple
|
||||
3. Back
|
||||
|
||||
enter select · esc back
|
||||
@@ -14,10 +14,11 @@ use codex_login::default_client::ClientRedirectPolicy;
|
||||
use codex_login::default_client::add_originator_header;
|
||||
use codex_login::default_client::originator;
|
||||
use codex_model_provider::LocalProviderAuth;
|
||||
use codex_model_provider::SharedModelProvider;
|
||||
use codex_model_provider::resolve_request;
|
||||
use codex_model_provider_info::ModelProviderInfo;
|
||||
use codex_prompts::prepare_realtime_backend_prompt;
|
||||
use codex_protocol::protocol::RealtimeOutputModality;
|
||||
use codex_protocol::protocol::RealtimeVoice;
|
||||
use color_eyre::eyre::Result;
|
||||
use color_eyre::eyre::ensure;
|
||||
use http::HeaderValue;
|
||||
@@ -37,21 +38,15 @@ pub(crate) struct CreatedCall {
|
||||
}
|
||||
|
||||
impl Client {
|
||||
pub(crate) async fn create(
|
||||
&self,
|
||||
config: &Config,
|
||||
thread: &Thread,
|
||||
offer: String,
|
||||
voice: Option<RealtimeVoice>,
|
||||
) -> Result<CreatedCall> {
|
||||
ensure!(
|
||||
config.realtime.session_type == RealtimeWsMode::Conversational,
|
||||
"AVAS realtime calls require conversational realtime"
|
||||
);
|
||||
let mut info = config.model_provider.clone();
|
||||
if let Some(url) = &config.experimental_realtime_webrtc_call_base_url {
|
||||
info.base_url = Some(url.clone());
|
||||
}
|
||||
pub(crate) async fn voice_provider(&self, config: &Config) -> Result<SharedModelProvider> {
|
||||
let root = config
|
||||
.chatgpt_base_url
|
||||
.trim_end_matches('/')
|
||||
.trim_end_matches("/backend-api");
|
||||
let info = ModelProviderInfo {
|
||||
env_http_headers: None,
|
||||
..ModelProviderInfo::create_openai_provider(Some(format!("{root}/backend-api/codex")))
|
||||
};
|
||||
let runtime_auth_mode = config
|
||||
.features
|
||||
.enabled(Feature::RuntimeAgentInstances)
|
||||
@@ -60,6 +55,27 @@ impl Client {
|
||||
.auth
|
||||
.model_provider(info, config.auth_config(), runtime_auth_mode)
|
||||
.await?;
|
||||
ensure!(
|
||||
provider
|
||||
.auth()
|
||||
.await
|
||||
.is_some_and(|auth| auth.is_chatgpt_auth()),
|
||||
"Sign in with ChatGPT to use voice chat."
|
||||
);
|
||||
Ok(provider)
|
||||
}
|
||||
|
||||
pub(crate) async fn create(
|
||||
&self,
|
||||
config: &Config,
|
||||
thread: &Thread,
|
||||
offer: String,
|
||||
) -> Result<CreatedCall> {
|
||||
ensure!(
|
||||
config.realtime.session_type == RealtimeWsMode::Conversational,
|
||||
"AVAS realtime calls require conversational realtime"
|
||||
);
|
||||
let provider = self.voice_provider(config).await?;
|
||||
let mut request = resolve_request(
|
||||
provider.as_ref(),
|
||||
/*scope*/ None,
|
||||
@@ -69,15 +85,14 @@ impl Client {
|
||||
.await?;
|
||||
request.redirect_policy = ClientRedirectPolicy::Reject;
|
||||
let transport = request.http_transport("realtime/calls")?;
|
||||
let id = thread.id.clone();
|
||||
let voice_session_id = Uuid::new_v4();
|
||||
let mut headers = build_realtime_thread_headers(
|
||||
thread.session_id.clone(),
|
||||
id.clone(),
|
||||
thread.id.clone(),
|
||||
thread.thread_source.clone().map(Into::into),
|
||||
);
|
||||
headers.insert("openai-alpha", HeaderValue::from_static("quicksilver=v2"));
|
||||
headers.insert("x-session-id", HeaderValue::from_str(&id)?);
|
||||
headers.insert("x-session-id", HeaderValue::from_str(&thread.id)?);
|
||||
headers.insert(
|
||||
"voice-session-id",
|
||||
HeaderValue::from_str(&voice_session_id.to_string())?,
|
||||
@@ -90,17 +105,11 @@ impl Client {
|
||||
),
|
||||
initial_items: Vec::new(),
|
||||
delegation_ack_filler: None,
|
||||
model: Some(
|
||||
config
|
||||
.experimental_realtime_ws_model
|
||||
.clone()
|
||||
.unwrap_or_else(|| "gpt-live-1.1-codex".to_string()),
|
||||
),
|
||||
session_id: Some(id),
|
||||
model: None,
|
||||
session_id: None,
|
||||
event_parser: RealtimeEventParser::FramelessBidi,
|
||||
session_mode: RealtimeSessionMode::Conversational,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
voice,
|
||||
};
|
||||
let call = RealtimeCallClient::new(transport, request.api_provider, request.api_auth)
|
||||
.create_with_session_and_headers(offer, session, headers)
|
||||
|
||||
@@ -7,6 +7,8 @@ use crate::legacy_core::config::Config;
|
||||
use crate::legacy_core::config::ConfigBuilder;
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use app_test_support::ChatGptAuthFixture;
|
||||
use app_test_support::write_chatgpt_auth;
|
||||
use base64::Engine;
|
||||
use codex_app_server_protocol::Thread;
|
||||
use codex_config::LoaderOverrides;
|
||||
@@ -38,13 +40,14 @@ const KEY_A: &str = "test-realtime-key-a";
|
||||
const KEY_B: &str = "test-realtime-key-b";
|
||||
|
||||
fn sign_in(config: &Config, key: &str) -> Result<()> {
|
||||
login_with_api_key(
|
||||
write_chatgpt_auth(
|
||||
config.codex_home.as_path(),
|
||||
key,
|
||||
ChatGptAuthFixture::new(key)
|
||||
.account_id(key)
|
||||
.chatgpt_account_id(key)
|
||||
.chatgpt_user_id(key),
|
||||
config.cli_auth_credentials_store_mode,
|
||||
config.auth_keyring_backend_kind(),
|
||||
)?;
|
||||
Ok(())
|
||||
)
|
||||
}
|
||||
|
||||
async fn create_call(client: &Client, config: &Config) -> Result<()> {
|
||||
@@ -56,12 +59,7 @@ async fn create_call(client: &Client, config: &Config) -> Result<()> {
|
||||
"cwd": config.cwd, "cliVersion": "test", "source": "cli", "turns": [],
|
||||
}))?;
|
||||
let call = client
|
||||
.create(
|
||||
config,
|
||||
&thread,
|
||||
"offer-sdp".to_string(),
|
||||
/*voice*/ None,
|
||||
)
|
||||
.create(config, &thread, "offer-sdp".to_string())
|
||||
.await
|
||||
.map_err(|error| anyhow::anyhow!("{error:#}"))?;
|
||||
assert_eq!(
|
||||
@@ -94,7 +92,7 @@ async fn local_calls_share_runtime_and_follow_auth_changes() -> Result<()> {
|
||||
config.application_network_policy = policy.clone();
|
||||
sign_in(&config, KEY_A)?;
|
||||
assert!(controller.publish(policy.revision(), DestinationPolicy::Unrestricted));
|
||||
let destination = "https://api.openai.com/v1/live".parse()?;
|
||||
let destination = "https://chatgpt.com/backend-api/codex/realtime/calls".parse()?;
|
||||
let account_a_permit = policy.acquire(&destination)?;
|
||||
let client = Client::default();
|
||||
create_call(&client, &config).await?;
|
||||
@@ -118,7 +116,7 @@ async fn local_calls_share_runtime_and_follow_auth_changes() -> Result<()> {
|
||||
config.experimental_realtime_webrtc_call_base_url = Some(format!("{server}/v1"));
|
||||
create_call(&client, &config).await?;
|
||||
|
||||
config.forced_login_method = Some(ForcedLoginMethod::Chatgpt);
|
||||
config.forced_login_method = Some(ForcedLoginMethod::Api);
|
||||
assert!(create_call(&client, &config).await.is_err());
|
||||
}
|
||||
return Ok(());
|
||||
@@ -133,21 +131,20 @@ async fn local_calls_share_runtime_and_follow_auth_changes() -> Result<()> {
|
||||
))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
|
||||
"runtime_agent_instance_id": runtime, "agent_host_id": "host-tui",
|
||||
"actor": {"kind": "platform", "user_id": "user-tui",
|
||||
"organization_id": "org-tui", "project_id": "proj-tui"},
|
||||
"actor": {"kind": "chatgpt", "user_id": key, "account_id": key},
|
||||
})))
|
||||
.expect(2)
|
||||
.mount(&server)
|
||||
.await;
|
||||
}
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/v1/live"))
|
||||
.and(path("/backend-api/codex/realtime/calls"))
|
||||
.respond_with(|request: &wiremock::Request| {
|
||||
if !request.headers.contains_key("authorization") {
|
||||
return ResponseTemplate::new(401);
|
||||
}
|
||||
ResponseTemplate::new(201)
|
||||
.insert_header("location", "/v1/live/rtc_tui")
|
||||
.insert_header("location", "/realtime/calls/rtc_tui")
|
||||
.set_body_string("answer-sdp")
|
||||
})
|
||||
.mount(&server)
|
||||
@@ -170,7 +167,7 @@ async fn local_calls_share_runtime_and_follow_auth_changes() -> Result<()> {
|
||||
.context("captured requests")?;
|
||||
let calls = requests
|
||||
.iter()
|
||||
.filter(|request| request.url.path() == "/v1/live")
|
||||
.filter(|request| request.url.path() == "/backend-api/codex/realtime/calls")
|
||||
.collect::<Vec<_>>();
|
||||
for request in &calls {
|
||||
if !request.headers.contains_key("authorization") {
|
||||
@@ -187,7 +184,7 @@ async fn local_calls_share_runtime_and_follow_auth_changes() -> Result<()> {
|
||||
for (index, request) in calls.iter().enumerate() {
|
||||
let key = if index < 3 { KEY_A } else { KEY_B };
|
||||
let authorization = request.headers["authorization"].to_str()?;
|
||||
if matches!(index, 0 | 4 | 5) {
|
||||
if matches!(index, 0 | 4) {
|
||||
assert_eq!(authorization, format!("Bearer {key}"));
|
||||
assert!(!request.headers.contains_key("x-openai-agent-assertion"));
|
||||
continue;
|
||||
@@ -227,7 +224,7 @@ async fn local_calls_share_runtime_and_follow_auth_changes() -> Result<()> {
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn local_calls_use_provider_credentials_when_login_storage_fails() -> Result<()> {
|
||||
async fn local_calls_require_chatgpt_even_with_provider_credentials() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
if std::env::var(PROBE_SERVER).is_ok() {
|
||||
let home = tempfile::tempdir()?;
|
||||
@@ -241,18 +238,25 @@ async fn local_calls_use_provider_credentials_when_login_storage_fails() -> Resu
|
||||
config
|
||||
.features
|
||||
.set_enabled(Feature::RuntimeAgentInstances, /*enabled*/ false)?;
|
||||
sign_in(&config, KEY_A)?;
|
||||
let client = Client::default();
|
||||
login_with_api_key(
|
||||
config.codex_home.as_path(),
|
||||
KEY_A,
|
||||
config.cli_auth_credentials_store_mode,
|
||||
config.auth_keyring_backend_kind(),
|
||||
)?;
|
||||
assert!(create_call(&client, &config).await.is_err());
|
||||
sign_in(&config, KEY_A)?;
|
||||
create_call(&client, &config).await?;
|
||||
std::fs::write(home.path().join("auth.json"), "malformed credentials")?;
|
||||
|
||||
let original_provider = config.model_provider.clone();
|
||||
config.model_provider.experimental_bearer_token = Some(KEY_B.into());
|
||||
create_call(&client, &config).await?;
|
||||
assert!(create_call(&client, &config).await.is_err());
|
||||
|
||||
config.model_provider = original_provider.clone();
|
||||
config.model_provider.env_key = Some("TUI_TEST_PROVIDER_KEY".to_string());
|
||||
create_call(&client, &config).await?;
|
||||
assert!(create_call(&client, &config).await.is_err());
|
||||
|
||||
config.model_provider = original_provider.clone();
|
||||
config.model_provider.requires_openai_auth = false;
|
||||
@@ -268,7 +272,7 @@ async fn local_calls_use_provider_credentials_when_login_storage_fails() -> Resu
|
||||
refresh_interval_ms: 300_000,
|
||||
cwd: config.cwd.clone(),
|
||||
});
|
||||
create_call(&client, &config).await?;
|
||||
assert!(create_call(&client, &config).await.is_err());
|
||||
|
||||
config.model_provider = original_provider;
|
||||
assert!(create_call(&client, &config).await.is_err());
|
||||
@@ -276,16 +280,16 @@ async fn local_calls_use_provider_credentials_when_login_storage_fails() -> Resu
|
||||
}
|
||||
|
||||
let server = MockServer::start().await;
|
||||
for (key, calls) in [(KEY_A, 1), (KEY_B, 3)] {
|
||||
for (key, calls) in [(KEY_A, 1), (KEY_B, 0)] {
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/v1/live"))
|
||||
.and(path("/backend-api/codex/realtime/calls"))
|
||||
.and(wiremock::matchers::header(
|
||||
"authorization",
|
||||
format!("Bearer {key}"),
|
||||
))
|
||||
.respond_with(
|
||||
ResponseTemplate::new(201)
|
||||
.insert_header("location", "/v1/live/rtc_tui")
|
||||
.insert_header("location", "/realtime/calls/rtc_tui")
|
||||
.set_body_string("answer-sdp"),
|
||||
)
|
||||
.expect(calls)
|
||||
@@ -294,7 +298,7 @@ async fn local_calls_use_provider_credentials_when_login_storage_fails() -> Resu
|
||||
}
|
||||
run_harness_through_proxy_with_env(
|
||||
&server,
|
||||
"realtime_call::tests::local_calls_use_provider_credentials_when_login_storage_fails",
|
||||
"realtime_call::tests::local_calls_require_chatgpt_even_with_provider_credentials",
|
||||
/*realtime_target*/ None,
|
||||
&[
|
||||
("CODEX_API_KEY", None),
|
||||
|
||||
@@ -100,6 +100,14 @@ class AccountUpdateReason(Enum):
|
||||
unknown = "unknown"
|
||||
|
||||
|
||||
class AccountVoiceOption(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
)
|
||||
name: str
|
||||
voice: str
|
||||
|
||||
|
||||
class ActivePermissionProfile(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
|
||||
Reference in New Issue
Block a user