Files
codex/codex-rs/cloud-client/src/wire.rs
T
Benjamin Carlsson b016cd1847 Enable automatic titles for Cloud conversations (#61600)
## Why

Cloud conversations previously skipped TUI title generation, leaving them without automatically saved names.

## What changed

- Generate structured titles using the selected Cloud account and its backend routing, without agent tools or a temporary conversation.
- Read and save names outside the conversation command queue without replacing the active attachment. Preserve an existing name if it no longer matches the expected value.
- Fall back to the first-message title when generation is unavailable, and allow up to three seconds for pending saves during shutdown.
- Report a retryable error when a manual rename encounters an automatic save in progress, keeping the UI responsive.

## Testing

Add coverage for selected-account title generation, saved-name reads without attachment, first-message fallback persistence, and manual rename retries after automatic saves.

GitOrigin-RevId: 48030cc0b75e790a2004af018f54e5751665b760
2026-11-15 03:17:50 +00:00

93 lines
2.5 KiB
Rust

//! Minimal ThreadService protobuf envelopes; field numbers are the wire contract.
//! Length-delimited nested events remain intact, including unknown protobuf fields.
use bytes::Buf;
use bytes::Bytes;
use prost::Message;
use std::marker::PhantomData;
use tonic::codec::Codec;
#[derive(Clone, prost::Message)]
pub(crate) struct EmptyResponse {}
#[derive(Clone, prost::Message)]
pub(crate) struct ThreadIdRequest {
#[prost(string, tag = "1")]
pub thread_id: String,
}
#[derive(Clone, prost::Message)]
pub(crate) struct SetThreadNameRequest {
#[prost(string, tag = "1")]
pub thread_id: String,
#[prost(string, tag = "2")]
pub name: String,
}
#[derive(Clone, prost::Message)]
pub(crate) struct ReadThreadResponse {
#[prost(message, optional, tag = "1")]
pub thread: Option<ThreadName>,
}
#[derive(Clone, prost::Message)]
#[prost(skip_debug)]
pub(crate) struct ThreadName {
#[prost(string, optional, tag = "14")]
pub id: Option<String>,
#[prost(string, optional, tag = "17")]
pub name: Option<String>,
}
impl std::fmt::Debug for ThreadName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("ThreadName([redacted])")
}
}
#[derive(Clone, prost::Message)]
pub(crate) struct UnarchiveResponse {
#[prost(bytes = "bytes", optional, tag = "1")]
pub thread: Option<Bytes>,
}
#[derive(Clone, prost::Message)]
pub(crate) struct AttachResponse {
#[prost(oneof = "Payload", tags = "1, 2")]
pub event: Option<Payload>,
}
#[derive(Clone, prost::Oneof)]
pub(crate) enum Payload {
#[prost(bytes = "bytes", tag = "1")]
Notification(bytes::Bytes),
#[prost(bytes = "bytes", tag = "2")]
ServerRequest(bytes::Bytes),
}
// Tonic enforces message bounds and status trailers while callers decode the raw payload.
pub(super) struct RawResponseCodec<T>(pub PhantomData<T>);
impl<T: Message + Send + 'static> Codec for RawResponseCodec<T> {
type Encode = T;
type Decode = Bytes;
type Encoder = tonic_prost::ProstEncoder<T>;
type Decoder = RawDecoder;
fn encoder(&mut self) -> Self::Encoder {
tonic_prost::ProstCodec::<T, EmptyResponse>::default().encoder()
}
fn decoder(&mut self) -> Self::Decoder {
RawDecoder
}
}
pub(super) struct RawDecoder;
impl tonic::codec::Decoder for RawDecoder {
type Item = Bytes;
type Error = tonic::Status;
fn decode(
&mut self,
buffer: &mut tonic::codec::DecodeBuf<'_>,
) -> Result<Option<Bytes>, tonic::Status> {
Ok(Some(buffer.copy_to_bytes(buffer.remaining())))
}
}