feat: Set chat name (#4974)
Set chat name with `/name` so they appear in the codex resume page: https://github.com/user-attachments/assets/c0252bba-3a53-44c7-a740-f4690a3ad405
This commit is contained in:
@@ -1104,6 +1104,7 @@ impl ChatWidget {
|
||||
return;
|
||||
}
|
||||
match cmd {
|
||||
SlashCommand::Name => self.open_name_popup(),
|
||||
SlashCommand::New => {
|
||||
self.app_event_tx.send(AppEvent::NewSession);
|
||||
}
|
||||
@@ -1251,6 +1252,29 @@ impl ChatWidget {
|
||||
return;
|
||||
}
|
||||
|
||||
// Intercept '/name <new name>' as a local rename command (no images allowed).
|
||||
if image_paths.is_empty()
|
||||
&& let Some((cmd, rest)) = crate::bottom_pane::prompt_args::parse_slash_name(&text)
|
||||
&& cmd == "name"
|
||||
{
|
||||
let name = rest.trim();
|
||||
if name.is_empty() {
|
||||
// Provide a brief usage hint.
|
||||
self.add_to_history(history_cell::new_info_event(
|
||||
"Usage: /name <new name>".to_string(),
|
||||
None,
|
||||
));
|
||||
self.request_redraw();
|
||||
} else {
|
||||
// Send the rename op; persistence and ack come as an event.
|
||||
let name_str = name.to_string();
|
||||
self.codex_op_tx
|
||||
.send(Op::SetSessionName { name: name_str })
|
||||
.unwrap_or_else(|e| tracing::error!("failed to send SetSessionName op: {e}"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
self.capture_ghost_snapshot();
|
||||
|
||||
let mut items: Vec<InputItem> = Vec::new();
|
||||
@@ -1443,6 +1467,13 @@ impl ChatWidget {
|
||||
self.app_event_tx
|
||||
.send(crate::app_event::AppEvent::ConversationHistory(ev));
|
||||
}
|
||||
EventMsg::SessionRenamed(ev) => {
|
||||
self.add_to_history(history_cell::new_info_event(
|
||||
format!("Named this chat: {}", ev.name),
|
||||
None,
|
||||
));
|
||||
self.request_redraw();
|
||||
}
|
||||
EventMsg::EnteredReviewMode(review_request) => {
|
||||
self.on_entered_review_mode(review_request)
|
||||
}
|
||||
@@ -2081,6 +2112,33 @@ impl ChatWidget {
|
||||
self.bottom_pane.show_view(Box::new(view));
|
||||
}
|
||||
|
||||
pub(crate) fn open_name_popup(&mut self) {
|
||||
let tx = self.app_event_tx.clone();
|
||||
let view = CustomPromptView::new(
|
||||
"Name this chat".to_string(),
|
||||
"Type a name and press Enter".to_string(),
|
||||
None,
|
||||
Box::new(move |name: String| {
|
||||
let trimmed = name.trim().to_string();
|
||||
if trimmed.is_empty() {
|
||||
return;
|
||||
}
|
||||
tx.send(AppEvent::SetSessionName(trimmed));
|
||||
}),
|
||||
);
|
||||
self.bottom_pane.show_view(Box::new(view));
|
||||
}
|
||||
|
||||
pub(crate) fn begin_set_session_name(&mut self, name: String) {
|
||||
let trimmed = name.trim().to_string();
|
||||
if trimmed.is_empty() {
|
||||
return;
|
||||
}
|
||||
self.codex_op_tx
|
||||
.send(Op::SetSessionName { name: trimmed })
|
||||
.unwrap_or_else(|e| tracing::error!("failed to send SetSessionName op: {e}"));
|
||||
}
|
||||
|
||||
/// Programmatically submit a user text message as if typed in the
|
||||
/// composer. The text will be added to conversation history and sent to
|
||||
/// the agent.
|
||||
|
||||
Reference in New Issue
Block a user