mirror of
https://github.com/openai/codex.git
synced 2026-12-05 01:00:54 +00:00
Add typed item lifecycle events to the cloud client (#59066)
## What changed Decode live item start and completion notifications as `TranscriptUpdate::ItemStarted` and `TranscriptUpdate::ItemCompleted`, with turn identity, lifecycle timestamps, and summaries for user messages, agent messages, reasoning, commands, and file changes. Preserve structured agent questions even when message text is empty, optional command output and exit details, and command or patch status independently of lifecycle completion. Keep unsupported or incomplete items as opaque notifications and redact summary fields in debug output. ## Testing Add fixtures covering lifecycle ordering alongside deltas, identity and timestamps, status and optional-field preservation, structured questions, opaque fallback, malformed payloads, thread ownership, and debug redaction. GitOrigin-RevId: d6bf2d25ee85be17d895726c5072850a9851b55f
This commit is contained in:
committed by
copyberry
parent
dbaead0106
commit
7ee5efad4a
@@ -14,6 +14,8 @@ pub struct TranscriptEvent {
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub enum TranscriptUpdate {
|
||||
ItemStarted(crate::ItemLifecycle),
|
||||
ItemCompleted(crate::ItemLifecycle),
|
||||
AgentMessageDelta(ItemDelta),
|
||||
CommandOutputDelta(ItemDelta),
|
||||
FileChangeOutputDelta(ItemDelta),
|
||||
@@ -97,13 +99,16 @@ redacted_debug!(
|
||||
// Field numbers in the ASB Notification.value oneof.
|
||||
const TURN_STARTED: u32 = 21;
|
||||
const TURN_COMPLETED: u32 = 23;
|
||||
pub(super) const ITEM_STARTED: u32 = 27;
|
||||
const ITEM_COMPLETED: u32 = 31;
|
||||
const ITEM_AGENT_MESSAGE_DELTA: u32 = 32;
|
||||
const ITEM_COMMAND_EXECUTION_OUTPUT_DELTA: u32 = 37;
|
||||
const ITEM_FILE_CHANGE_OUTPUT_DELTA: u32 = 39;
|
||||
const ITEM_FILE_CHANGE_PATCH_UPDATED: u32 = 40;
|
||||
|
||||
enum DecodeFailure {
|
||||
pub(super) enum DecodeFailure {
|
||||
MissingField,
|
||||
UnsupportedCommandSource,
|
||||
InvalidResponse,
|
||||
}
|
||||
|
||||
@@ -113,14 +118,14 @@ impl From<prost::DecodeError> for DecodeFailure {
|
||||
}
|
||||
}
|
||||
|
||||
fn required<T>(value: Option<T>) -> Result<T, DecodeFailure> {
|
||||
pub(super) fn required<T>(value: Option<T>) -> Result<T, DecodeFailure> {
|
||||
value.ok_or(DecodeFailure::MissingField)
|
||||
}
|
||||
impl TranscriptEvent {
|
||||
pub(crate) fn decode(thread_id: &str, payload: &[u8]) -> Result<Option<Self>, Error> {
|
||||
match Self::decode_present_fields(thread_id, payload) {
|
||||
Ok(event) => Ok(event),
|
||||
Err(DecodeFailure::MissingField) => Ok(None),
|
||||
Err(DecodeFailure::MissingField | DecodeFailure::UnsupportedCommandSource) => Ok(None),
|
||||
Err(DecodeFailure::InvalidResponse) => Err(Error::InvalidResponse),
|
||||
}
|
||||
}
|
||||
@@ -133,6 +138,10 @@ impl TranscriptEvent {
|
||||
return Ok(None);
|
||||
};
|
||||
let (owner, emitted_at_ms, update) = match tag {
|
||||
ITEM_STARTED | ITEM_COMPLETED => match crate::items::decode(tag, values)? {
|
||||
Some(decoded) => decoded,
|
||||
None => return Ok(None),
|
||||
},
|
||||
ITEM_AGENT_MESSAGE_DELTA
|
||||
| ITEM_COMMAND_EXECUTION_OUTPUT_DELTA
|
||||
| ITEM_FILE_CHANGE_OUTPUT_DELTA => {
|
||||
@@ -159,22 +168,9 @@ impl TranscriptEvent {
|
||||
let changes = required(params.changes)?
|
||||
.values
|
||||
.into_iter()
|
||||
.map(|change| {
|
||||
let kind = match required(change.kind)?.value {
|
||||
Some(wire::Kind::Add(_)) => PatchKind::Add,
|
||||
Some(wire::Kind::Delete(_)) => PatchKind::Delete,
|
||||
Some(wire::Kind::Update(value)) => PatchKind::Update {
|
||||
move_path: value.move_path,
|
||||
},
|
||||
None => PatchKind::Unknown,
|
||||
};
|
||||
Ok(FileUpdate {
|
||||
path: required(change.path)?,
|
||||
diff: required(change.diff)?,
|
||||
kind,
|
||||
})
|
||||
})
|
||||
.map(FileUpdate::try_from)
|
||||
.collect::<Result<_, DecodeFailure>>()?;
|
||||
|
||||
let update = PatchUpdate {
|
||||
item_id: required(params.item_id)?,
|
||||
turn_id: required(params.turn_id)?,
|
||||
@@ -239,3 +235,22 @@ impl TranscriptEvent {
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<wire::Change> for FileUpdate {
|
||||
type Error = DecodeFailure;
|
||||
fn try_from(change: wire::Change) -> Result<Self, DecodeFailure> {
|
||||
let kind = match required(change.kind)?.value {
|
||||
Some(wire::Kind::Add(_)) => PatchKind::Add,
|
||||
Some(wire::Kind::Delete(_)) => PatchKind::Delete,
|
||||
Some(wire::Kind::Update(value)) => PatchKind::Update {
|
||||
move_path: value.move_path,
|
||||
},
|
||||
None => PatchKind::Unknown,
|
||||
};
|
||||
Ok(Self {
|
||||
path: required(change.path)?,
|
||||
diff: required(change.diff)?,
|
||||
kind,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user