-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Handle agent management view updates based on event type #9866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: lucie/app-4329-conversation-update-details
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,8 @@ use warpui::ui_components::button::ButtonVariant; | |
| use crate::ai::agent::conversation::AIConversationId; | ||
| use crate::ai::agent_conversations_model::{ | ||
| AgentConversationsModel, AgentConversationsModelEvent, AgentManagementFilters, ArtifactFilter, | ||
| ConversationOrTask, CreatedOnFilter, CreatorFilter, EnvironmentFilter, HarnessFilter, | ||
| OwnerFilter, SessionStatus, SourceFilter, StatusFilter, | ||
| ConversationOrTask, ConversationUpdateKind, CreatedOnFilter, CreatorFilter, EnvironmentFilter, | ||
| HarnessFilter, OwnerFilter, SessionStatus, SourceFilter, StatusFilter, | ||
| }; | ||
| use crate::ai::agent_management::agent_type_selector::{ | ||
| AgentType, AgentTypeSelector, AgentTypeSelectorEvent, | ||
|
|
@@ -1237,10 +1237,11 @@ impl AgentManagementView { | |
| self.refresh_details_panel_if_needed(ctx); | ||
| self.get_tasks_from_model(ctx); | ||
| } | ||
| AgentConversationsModelEvent::ConversationUpdated { .. } => { | ||
| self.get_tasks_from_model(ctx); | ||
| self.refresh_details_panel_if_needed(ctx); | ||
| ctx.notify(); | ||
| AgentConversationsModelEvent::ConversationUpdated { | ||
| conversation_id, | ||
| kind, | ||
| } => { | ||
| self.handle_conversation_updated(*conversation_id, *kind, ctx); | ||
| } | ||
| // TaskManuallyOpened is handled by the conversation list view, not here. | ||
| AgentConversationsModelEvent::TaskManuallyOpened => {} | ||
|
|
@@ -1258,6 +1259,95 @@ impl AgentManagementView { | |
| } | ||
| } | ||
|
|
||
| /// Decide how much work a `ConversationUpdated` event requires, based on its kind and the | ||
| /// active status filter: | ||
| /// * `Restored`: the underlying status didn't change, so the visible cards don't change | ||
| /// either. Just refresh the details panel. | ||
| /// * `StatusSet` that crosses the active status filter: rebuild the | ||
| /// card list via `get_tasks_from_model`. | ||
| /// * `StatusSet` that doesn't cross the active filter (or `All` is active): targeted | ||
| /// refresh of the affected card via `update_card_for_conversation` (no-op when the card | ||
| /// is not visible) plus a re-render so the status icon picks up the new value. | ||
| fn handle_conversation_updated( | ||
| &mut self, | ||
| conversation_id: AIConversationId, | ||
| kind: ConversationUpdateKind, | ||
| ctx: &mut ViewContext<Self>, | ||
| ) { | ||
| match kind { | ||
| ConversationUpdateKind::Restored => { | ||
| self.refresh_details_panel_if_needed(ctx); | ||
| } | ||
| ConversationUpdateKind::StatusSet { | ||
| prev_filter, | ||
| new_filter, | ||
| } => { | ||
| let crossed_active_filter = self | ||
| .filters | ||
| .status | ||
| .is_membership_crossed(prev_filter, new_filter); | ||
|
|
||
| if crossed_active_filter { | ||
| self.get_tasks_from_model(ctx); | ||
| self.refresh_details_panel_if_needed(ctx); | ||
| } else { | ||
| self.update_card_for_conversation(conversation_id, ctx); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| self.refresh_details_panel_if_needed(ctx); | ||
| ctx.notify(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Update the action-buttons config for the card backing a given conversation, without | ||
| /// rebuilding the entire list. If no matching card is currently visible, this is a no-op. | ||
| fn update_card_for_conversation( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't actually think this function is necessary—we read the status for the card at render time, so if we haven't crossed a filter boundary, we shouldn't actually need to rebuild the card at all. A status change for a local conversation (which is the only type triggered from the |
||
| &mut self, | ||
| conversation_id: AIConversationId, | ||
| ctx: &mut ViewContext<Self>, | ||
| ) { | ||
| let model = AgentConversationsModel::as_ref(ctx); | ||
| let history_model = BlocklistAIHistoryModel::as_ref(ctx); | ||
|
|
||
| let target_index = self.items.iter().position(|card| match &card.item_id { | ||
| ManagementCardItemId::Conversation(id) => *id == conversation_id, | ||
| ManagementCardItemId::Task(task_id) => model | ||
| .get_task_data(task_id) | ||
| .and_then(|task| { | ||
| AgentConversationsModel::conversation_id_shadowed_by_task(&task, history_model) | ||
| }) | ||
| .is_some_and(|id| id == conversation_id), | ||
| }); | ||
|
|
||
| let Some(index) = target_index else { return }; | ||
|
|
||
| let card_state = &self.items[index]; | ||
| let card_data = match &card_state.item_id { | ||
| ManagementCardItemId::Task(task_id) => model.get_task(task_id), | ||
| ManagementCardItemId::Conversation(conv_id) => model.get_conversation(conv_id), | ||
| }; | ||
| let Some(card_data) = card_data else { return }; | ||
|
|
||
| let copy_link_url = card_data.session_or_conversation_link(ctx); | ||
| let mut config = match &card_data { | ||
| ConversationOrTask::Task(task) => ActionButtonsConfig::for_task( | ||
| task.task_id, | ||
| &card_data.display_status(ctx), | ||
| None, | ||
| copy_link_url, | ||
| ), | ||
| ConversationOrTask::Conversation(conversation) => { | ||
| ActionButtonsConfig::for_conversation(conversation.nav_data.id, None, copy_link_url) | ||
| } | ||
| }; | ||
| if FeatureFlag::AgentManagementDetailsView.is_enabled() { | ||
| config.view_details_item_id = Some(card_state.item_id.clone()); | ||
| } | ||
|
|
||
| let action_buttons_view = card_state.action_buttons_view.clone(); | ||
| action_buttons_view.update(ctx, |row, ctx| row.set_config(config, ctx)); | ||
| } | ||
|
|
||
| /// Update the details panel with fresh data for the given item. | ||
| fn update_details_panel_for_item( | ||
| &mut self, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!