mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
Plumb compaction counts to TUI clients
This commit is contained in:
@@ -313,7 +313,7 @@ Start a fresh thread when you need a new Codex conversation.
|
||||
|
||||
Valid `personality` values are `"friendly"`, `"pragmatic"`, and `"none"`. When `"none"` is selected, the personality placeholder is replaced with an empty string.
|
||||
|
||||
To continue a stored session, call `thread/resume` with the `thread.id` you previously recorded. The response shape matches `thread/start`. When the stored session includes persisted token usage, the server emits `thread/tokenUsage/updated` immediately after the response so clients can render restored usage before the next turn starts. You can also pass the same configuration overrides supported by `thread/start`, including `approvalsReviewer`.
|
||||
To continue a stored session, call `thread/resume` with the `thread.id` you previously recorded. The response shape matches `thread/start`. When the stored session includes persisted token usage, the server emits `thread/tokenUsage/updated` immediately after the response so clients can render restored usage before the next turn starts. The notification's `windowNumber` is the current zero-based context-window generation, so it also gives the number of compactions in the surviving thread history. You can also pass the same configuration overrides supported by `thread/start`, including `approvalsReviewer`.
|
||||
|
||||
By default, `thread/resume` includes the reconstructed turn history in `thread.turns`. Experimental clients can pass `excludeTurns: true` to return only thread metadata and live resume state, then call `thread/turns/list` separately if they want to page the turn history over the network. In that mode the server also skips replaying restored `thread/tokenUsage/updated`, which avoids rebuilding turns just to attribute historical usage.
|
||||
|
||||
|
||||
@@ -901,8 +901,15 @@ pub(crate) async fn apply_bespoke_event_handling(
|
||||
.await;
|
||||
}
|
||||
EventMsg::TokenCount(token_count_event) => {
|
||||
handle_token_count_event(conversation_id, event_turn_id, token_count_event, &outgoing)
|
||||
.await;
|
||||
let window_number = conversation.context_window_number().await;
|
||||
handle_token_count_event(
|
||||
conversation_id,
|
||||
event_turn_id,
|
||||
token_count_event,
|
||||
window_number,
|
||||
&outgoing,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
EventMsg::Error(ev) => {
|
||||
thread_watch_manager
|
||||
@@ -1610,6 +1617,7 @@ async fn handle_token_count_event(
|
||||
conversation_id: ThreadId,
|
||||
turn_id: String,
|
||||
token_count_event: TokenCountEvent,
|
||||
window_number: u64,
|
||||
outgoing: &ThreadScopedOutgoingMessageSender,
|
||||
) {
|
||||
let TokenCountEvent { info, rate_limits } = token_count_event;
|
||||
@@ -1618,6 +1626,7 @@ async fn handle_token_count_event(
|
||||
thread_id: conversation_id.to_string(),
|
||||
turn_id,
|
||||
token_usage,
|
||||
window_number,
|
||||
};
|
||||
outgoing
|
||||
.send_server_notification(ServerNotification::ThreadTokenUsageUpdated(notification))
|
||||
@@ -3829,6 +3838,7 @@ mod tests {
|
||||
info: Some(info),
|
||||
rate_limits: Some(rate_limits),
|
||||
},
|
||||
/*window_number*/ 7,
|
||||
&outgoing,
|
||||
)
|
||||
.await;
|
||||
@@ -3840,6 +3850,7 @@ mod tests {
|
||||
) => {
|
||||
assert_eq!(payload.thread_id, conversation_id.to_string());
|
||||
assert_eq!(payload.turn_id, turn_id);
|
||||
assert_eq!(payload.window_number, 7);
|
||||
let usage = payload.token_usage;
|
||||
assert_eq!(usage.total.total_tokens, 200);
|
||||
assert_eq!(usage.total.cached_input_tokens, 25);
|
||||
@@ -3886,6 +3897,7 @@ mod tests {
|
||||
info: None,
|
||||
rate_limits: None,
|
||||
},
|
||||
/*window_number*/ 0,
|
||||
&outgoing,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -44,10 +44,12 @@ pub(super) async fn send_thread_token_usage_update_to_connection(
|
||||
let Some(info) = conversation.token_usage_info().await else {
|
||||
return;
|
||||
};
|
||||
let window_number = conversation.context_window_number().await;
|
||||
let notification = ThreadTokenUsageUpdatedNotification {
|
||||
thread_id: thread_id.to_string(),
|
||||
turn_id: token_usage_turn_id.unwrap_or_else(|| latest_token_usage_turn_id(thread)),
|
||||
token_usage: ThreadTokenUsage::from(info),
|
||||
window_number,
|
||||
};
|
||||
outgoing
|
||||
.send_server_notification_to_connections(
|
||||
|
||||
Reference in New Issue
Block a user