Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
acp_thread: Link the two views of an ACP session message (#66101)
Ben Brandtd697904d0eaa
diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rsindex 4f42585751d..a16ce3147ef 100644--- a/crates/acp_thread/src/acp_thread.rs+++ b/crates/acp_thread/src/acp_thread.rs@@ -376,11 +376,45 @@ pub struct SessionMessage {pub identity: MessageIdentity,pub sender_session_id: Option<acp_v2::SessionId>,pub recipient_session_id: Option<acp_v2::SessionId>,+ /// On an incoming view, the ID of the outgoing view in the sender's transcript.+ pub sender_message_id: Option<acp_v2::MessageId>,+ /// On an outgoing view, the ID of the incoming view in the recipient's transcript.+ pub recipient_message_id: Option<acp_v2::MessageId>,pub meta: Option<acp_v2::Meta>,pub content: MessageContent,}+/// Which side of a session message a transcript shows, and the other participant when it+/// is known.+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub enum SessionMessageSide<'a> {+ Outgoing {+ recipient: Option<&'a acp_v2::SessionId>,+ },+ Incoming {+ sender: Option<&'a acp_v2::SessionId>,+ },+ Unknown,+}+impl SessionMessage {+ /// The side of this message that the transcript of `own_session_id` shows. That session+ /// is always one participant, so a single known participant that is another session+ /// also tells the direction.+ pub fn side<'a>(&'a self, own_session_id: &acp_v2::SessionId) -> SessionMessageSide<'a> {+ let sender = self.sender_session_id.as_ref();+ let recipient = self.recipient_session_id.as_ref();+ if sender == Some(own_session_id) {+ SessionMessageSide::Outgoing { recipient }+ } else if recipient == Some(own_session_id) || sender.is_some() {+ SessionMessageSide::Incoming { sender }+ } else if recipient.is_some() {+ SessionMessageSide::Outgoing { recipient }+ } else {+ SessionMessageSide::Unknown+ }+ }+fn to_markdown(&self, cx: &App) -> String {let heading = match (&self.sender_session_id, &self.recipient_session_id) {(Some(sender), Some(recipient)) => {@@ -4927,6 +4961,16 @@ impl AcpThread {.recipient_session_id.map_value(|id| acp_v2::SessionId::new(id.0)),)+ .sender_message_id(+ message+ .sender_message_id+ .map_value(|id| acp_v2::MessageId::new(id.0)),+ )+ .recipient_message_id(+ message+ .recipient_message_id+ .map_value(|id| acp_v2::MessageId::new(id.0)),+ ).content(content).meta(message.meta),MetadataUpdate::V1,@@ -5006,12 +5050,25 @@ impl AcpThread {cx: &mut Context<Self>,) -> Result<()> {let previous_entry_count = self.entries.len();- let location = self.session_message_location(- update.message_id,- update.sender_session_id,- update.recipient_session_id,- cx,- )?;+ let location = self.keyed_message_location(MessageKind::Session, update.message_id, cx)?;+ let Some(AgentThreadEntry::SessionMessage(message)) =+ self.entries.get_mut(location.entry_index())+ else {+ anyhow::bail!("session message disappeared during update");+ };+ // Omitted keeps the stored value, `null` clears it, and a value replaces it.+ update+ .sender_session_id+ .update_to(&mut message.sender_session_id);+ update+ .recipient_session_id+ .update_to(&mut message.recipient_session_id);+ update+ .sender_message_id+ .update_to(&mut message.sender_message_id);+ update+ .recipient_message_id+ .update_to(&mut message.recipient_message_id);self.replace_message_content(location,MessageKind::Session,@@ -5022,6 +5079,83 @@ impl AcpThread {)}+ /// The index of this transcript's view of `message`, a session message whose other view+ /// is in the transcript of `message_session_id`. The views are linked by `message`'s+ /// reference to the view here or, when it has none, by a view here that refers back to+ /// it. Views whose references name other messages are unlinked, and a referenced view+ /// that has not arrived yet is not found.+ pub fn linked_session_message(+ &self,+ message: &SessionMessage,+ message_session_id: &acp_v2::SessionId,+ ) -> Option<usize> {+ let MessageIdentity::Keyed(message_id) = &message.identity else {+ return None;+ };+ let own_session_id = self.session_id();+ let (reference, other_participant, message_is_outgoing) =+ match message.side(message_session_id) {+ SessionMessageSide::Outgoing { recipient } => {+ (message.recipient_message_id.as_ref(), recipient, true)+ }+ SessionMessageSide::Incoming { sender } => {+ (message.sender_message_id.as_ref(), sender, false)+ }+ SessionMessageSide::Unknown => return None,+ };+ if other_participant.is_some_and(|participant| participant != own_session_id) {+ return None;+ }+ /// A view of the same message here is on the other side. Returns that view's+ /// participant in `message_session_id`'s place, when known, and its reference back.+ fn other_view<'a>(+ view: &'a SessionMessage,+ own_session_id: &acp_v2::SessionId,+ message_is_outgoing: bool,+ ) -> Option<(Option<&'a acp_v2::SessionId>, Option<&'a acp_v2::MessageId>)> {+ match view.side(own_session_id) {+ SessionMessageSide::Incoming { sender } if message_is_outgoing => {+ Some((sender, view.sender_message_id.as_ref()))+ }+ SessionMessageSide::Outgoing { recipient } if !message_is_outgoing => {+ Some((recipient, view.recipient_message_id.as_ref()))+ }+ SessionMessageSide::Unknown if message_is_outgoing => {+ Some((None, view.sender_message_id.as_ref()))+ }+ SessionMessageSide::Unknown => Some((None, view.recipient_message_id.as_ref())),+ _ => None,+ }+ }+ let mut session_messages =+ self.entries+ .iter()+ .enumerate()+ .filter_map(|(entry_ix, entry)| match entry {+ AgentThreadEntry::SessionMessage(view) => Some((entry_ix, view)),+ _ => None,+ });+ if let Some(reference) = reference {+ let (entry_ix, view) = session_messages.find(+ |(_, view)| matches!(&view.identity, MessageIdentity::Keyed(id) if id == reference),+ )?;+ let (participant, back_reference) =+ other_view(view, own_session_id, message_is_outgoing)?;+ (participant.is_none_or(|participant| participant == message_session_id)+ && back_reference.is_none_or(|back_reference| back_reference == message_id))+ .then_some(entry_ix)+ } else {+ // The view's reference is a message ID in `message_session_id`'s transcript, so+ // it only identifies `message` when that participant is known.+ session_messages.find_map(|(entry_ix, view)| {+ let (participant, back_reference) =+ other_view(view, own_session_id, message_is_outgoing)?;+ (participant == Some(message_session_id) && back_reference == Some(message_id))+ .then_some(entry_ix)+ })+ }+ }+pub fn append_session_message_chunk(&mut self,chunk: acp_v2::SessionMessageChunk,@@ -5039,32 +5173,6 @@ impl AcpThread {)}- fn session_message_location(- &mut self,- id: acp_v2::MessageId,- sender: MaybeUndefined<acp_v2::SessionId>,- recipient: MaybeUndefined<acp_v2::SessionId>,- cx: &mut Context<Self>,- ) -> Result<MessageLocation> {- let location = self.keyed_message_location(MessageKind::Session, id, cx)?;- let Some(AgentThreadEntry::SessionMessage(message)) =- self.entries.get_mut(location.entry_index())- else {- anyhow::bail!("session message disappeared during update");- };- for (stored, reported) in [- (&mut message.sender_session_id, sender),- (&mut message.recipient_session_id, recipient),- ] {- match reported {- MaybeUndefined::Undefined => {}- MaybeUndefined::Null => *stored = None,- MaybeUndefined::Value(reported) => *stored = Some(reported),- }- }- Ok(location)- }-fn update_keyed_message(&mut self,kind: MessageKind,@@ -5256,6 +5364,8 @@ impl AcpThread {identity,sender_session_id: None,recipient_session_id: None,+ sender_message_id: None,+ recipient_message_id: None,meta: None,content: MessageContent::default(),}));@@ -13662,7 +13772,9 @@ mod tests {}#[gpui::test]- async fn test_session_messages_patch_participants_and_convert_from_v1(cx: &mut TestAppContext) {+ async fn test_session_messages_patch_participants_and_references_and_convert_from_v1(+ cx: &mut TestAppContext,+ ) {init_test(cx);let thread = new_test_thread(cx).await;thread.update(cx, |thread, cx| {@@ -13699,6 +13811,25 @@ mod tests {cx,).expect("null clears a participant");+ thread+ .upsert_session_message(+ acp_v2::SessionMessage::new("task")+ .sender_message_id(acp_v2::MessageId::new("sent"))+ .recipient_message_id(acp_v2::MessageId::new("received")),+ cx,+ )+ .expect("references can arrive after the message started");+ thread+ .upsert_session_message(acp_v2::SessionMessage::new("task"), cx)+ .expect("an update without references keeps them");+ thread+ .upsert_session_message(+ acp_v2::SessionMessage::new("task")+ .sender_message_id(MaybeUndefined::Null)+ .recipient_message_id(acp_v2::MessageId::new("replaced")),+ cx,+ )+ .expect("null clears a reference, and a value replaces it");thread.upsert_assistant_message(acp_v2::AgentMessage::new("task").content(vec!["answer".into()]),@@ -13716,6 +13847,8 @@ mod tests {assert_eq!(message.identity, MessageIdentity::Keyed("task".into()));assert_eq!(message.sender_session_id, Some("other".into()));assert_eq!(message.recipient_session_id, None);+ assert_eq!(message.sender_message_id, None);+ assert_eq!(message.recipient_message_id, Some("replaced".into()));assert_eq!(message.content.source_blocks(),&["Start by ".into(), "reproducing".into()]@@ -13737,6 +13870,7 @@ mod tests {"sessionUpdate": "session_message","messageId": "reply","recipientSessionId": "parent",+ "senderMessageId": "sent","_meta": {"second": true},}),json!({@@ -13756,6 +13890,7 @@ mod tests {};assert_eq!(message.sender_session_id, Some("child".into()));assert_eq!(message.recipient_session_id, Some("parent".into()));+ assert_eq!(message.sender_message_id, Some("sent".into()));assert_eq!(message.meta,Some(acp_v2::Meta::from_iter([("second".into(), json!(true))]))@@ -13767,6 +13902,209 @@ mod tests {});}+ #[test]+ fn session_message_side_follows_the_transcripts_own_session() {+ let own = acp_v2::SessionId::new("own");+ let other = acp_v2::SessionId::new("other");+ for (sender, recipient, expected) in [+ (+ Some("own"),+ Some("other"),+ SessionMessageSide::Outgoing {+ recipient: Some(&other),+ },+ ),+ (+ Some("own"),+ None,+ SessionMessageSide::Outgoing { recipient: None },+ ),+ (+ Some("other"),+ Some("own"),+ SessionMessageSide::Incoming {+ sender: Some(&other),+ },+ ),+ (+ None,+ Some("own"),+ SessionMessageSide::Incoming { sender: None },+ ),+ (+ Some("other"),+ None,+ SessionMessageSide::Incoming {+ sender: Some(&other),+ },+ ),+ (+ None,+ Some("other"),+ SessionMessageSide::Outgoing {+ recipient: Some(&other),+ },+ ),+ (None, None, SessionMessageSide::Unknown),+ ] {+ let message = SessionMessage {+ identity: MessageIdentity::Keyed("message".into()),+ sender_session_id: sender.map(acp_v2::SessionId::new),+ recipient_session_id: recipient.map(acp_v2::SessionId::new),+ sender_message_id: None,+ recipient_message_id: None,+ meta: None,+ content: MessageContent::default(),+ };+ assert_eq!(message.side(&own), expected, "{sender:?} -> {recipient:?}");+ }+ }++ #[gpui::test]+ async fn test_linked_session_message_follows_references(cx: &mut TestAppContext) {+ init_test(cx);+ let parent = new_test_thread(cx).await;+ let child = new_test_thread(cx).await;+ let parent_id = parent.read_with(cx, |thread, _| thread.session_id().clone());+ let child_id = child.read_with(cx, |thread, _| thread.session_id().clone());+ assert_ne!(parent_id, child_id);+ let send = |thread: &Entity<AcpThread>,+ message: acp_v2::SessionMessage,+ cx: &mut TestAppContext| {+ thread.update(cx, |thread, cx| {+ thread+ .upsert_session_message(message.content(vec!["text".into()]), cx)+ .expect("session message")+ });+ };+ // Both views of a message from the parent to the child have the same participants.+ let to_child = |message_id: &str| {+ acp_v2::SessionMessage::new(message_id)+ .sender_session_id(parent_id.clone())+ .recipient_session_id(child_id.clone())+ };++ // Both views name each other.+ send(+ &parent,+ to_child("out-1").recipient_message_id(acp_v2::MessageId::new("in-1")),+ cx,+ );+ send(+ &child,+ to_child("in-1").sender_message_id(acp_v2::MessageId::new("out-1")),+ cx,+ );+ // Only the incoming view names the outgoing one.+ send(&parent, to_child("out-2"), cx);+ send(+ &child,+ to_child("in-2").sender_message_id(acp_v2::MessageId::new("out-2")),+ cx,+ );+ // The incoming view names another message.+ send(+ &parent,+ to_child("out-3").recipient_message_id(acp_v2::MessageId::new("in-3")),+ cx,+ );+ send(+ &child,+ to_child("in-3").sender_message_id(acp_v2::MessageId::new("out-other")),+ cx,+ );+ // The referenced view has not arrived yet.+ send(+ &parent,+ to_child("out-4").recipient_message_id(acp_v2::MessageId::new("in-4")),+ cx,+ );+ // A reference back from a view with no known sender is a message ID in an unknown+ // transcript.+ send(&parent, to_child("out-5"), cx);+ send(+ &child,+ acp_v2::SessionMessage::new("in-5").sender_message_id(acp_v2::MessageId::new("out-5")),+ cx,+ );+ // A message to another session.+ send(+ &parent,+ acp_v2::SessionMessage::new("out-6")+ .sender_session_id(parent_id.clone())+ .recipient_session_id(acp_v2::SessionId::new("other-child"))+ .recipient_message_id(acp_v2::MessageId::new("in-1")),+ cx,+ );++ let linked = |from: &Entity<AcpThread>,+ message_id: &str,+ to: &Entity<AcpThread>,+ cx: &mut TestAppContext| {+ let from = from.read_with(cx, |thread, _| thread.session_id().clone());+ let message_ix = |thread: &AcpThread, message_id: &str| {+ thread.entries().iter().position(|entry| {+ matches!(+ entry,+ AgentThreadEntry::SessionMessage(message)+ if message.identity == MessageIdentity::Keyed(message_id.into())+ )+ })+ };+ let source = if from == parent_id { &parent } else { &child };+ source.read_with(cx, |source, cx| {+ let entry_ix = message_ix(source, message_id).expect("message");+ let Some(AgentThreadEntry::SessionMessage(message)) =+ source.entries().get(entry_ix)+ else {+ panic!("expected a session message");+ };+ let target = to.read(cx);+ target+ .linked_session_message(message, &from)+ .map(|linked_ix| match target.entries().get(linked_ix) {+ Some(AgentThreadEntry::SessionMessage(view)) => match &view.identity {+ MessageIdentity::Keyed(id) => id.to_string(),+ other => panic!("unexpected identity {other:?}"),+ },+ other => panic!("expected a session message, got {other:?}"),+ })+ })+ };+ for (message_id, expected) in [+ ("out-1", Some("in-1")),+ ("out-2", Some("in-2")),+ ("out-3", None),+ ("out-4", None),+ ("out-5", None),+ ("out-6", None),+ ] {+ assert_eq!(+ linked(&parent, message_id, &child, cx).as_deref(),+ expected,+ "{message_id}"+ );+ }+ for (message_id, expected) in [+ ("in-1", Some("out-1")),+ ("in-2", Some("out-2")),+ ("in-3", None),+ ] {+ assert_eq!(+ linked(&child, message_id, &parent, cx).as_deref(),+ expected,+ "{message_id}"+ );+ }++ send(&child, to_child("in-4"), cx);+ assert_eq!(+ linked(&parent, "out-4", &child, cx).as_deref(),+ Some("in-4"),+ "a referenced view links once it arrives"+ );+ }+#[gpui::test]async fn test_v2_entity_metadata_patches_by_key(cx: &mut TestAppContext) {init_test(cx);diff --git a/crates/agent_ui/src/conversation_view.rs b/crates/agent_ui/src/conversation_view.rsindex 07e627ca320..b6f53e76f07 100644--- a/crates/agent_ui/src/conversation_view.rs+++ b/crates/agent_ui/src/conversation_view.rs@@ -20323,68 +20323,6 @@ pub(crate) mod tests {assert_eq!(label(&acp_child, cx), "Parent title");}- #[test]- fn session_message_side_follows_the_transcripts_own_session() {- use thread_view::{SessionMessageSide, session_message_side};-- let own = acp_v2::SessionId::new("own");- let other = acp_v2::SessionId::new("other");- for (sender, recipient, expected) in [- (- Some("own"),- Some("other"),- SessionMessageSide::Outgoing {- recipient: Some(&other),- },- ),- (- Some("own"),- None,- SessionMessageSide::Outgoing { recipient: None },- ),- (- Some("other"),- Some("own"),- SessionMessageSide::Incoming {- sender: Some(&other),- },- ),- (- None,- Some("own"),- SessionMessageSide::Incoming { sender: None },- ),- (- Some("other"),- None,- SessionMessageSide::Incoming {- sender: Some(&other),- },- ),- (- None,- Some("other"),- SessionMessageSide::Outgoing {- recipient: Some(&other),- },- ),- (None, None, SessionMessageSide::Unknown),- ] {- let message = acp_thread::SessionMessage {- identity: acp_thread::MessageIdentity::Keyed("message".into()),- sender_session_id: sender.map(acp_v2::SessionId::new),- recipient_session_id: recipient.map(acp_v2::SessionId::new),- meta: None,- content: acp_thread::MessageContent::default(),- };- assert_eq!(- session_message_side(&message, &own),- expected,- "{sender:?} -> {recipient:?}"- );- }- }-#[gpui::test]async fn test_session_message_participant_opens_its_session(cx: &mut TestAppContext) {init_test(cx);@@ -20414,12 +20352,36 @@ pub(crate) mod tests {});// Each ACP notification is applied in its own update, as here.root.update(cx, |root, cx| root.register_subagent(child.clone(), cx));+ // The subagent's own view of its reply sits between entries that overflow the view.+ let long_text = vec!["Working on it"; 40].join("\n\n");+ for message_id in ["work-1", "work-2", "work-3", "reply", "work-4", "work-5"] {+ child+ .update(cx, |child, cx| {+ if message_id == "reply" {+ child.upsert_session_message(+ acp_v2::SessionMessage::new("reply")+ .sender_session_id(acp_v2::SessionId::new("child"))+ .recipient_session_id(root_session_id.clone())+ .content(vec!["Found it".into()]),+ cx,+ )+ } else {+ child.upsert_user_message(+ acp_v2::UserMessage::new(message_id)+ .content(vec![long_text.as_str().into()]),+ cx,+ )+ }+ })+ .expect("subagent entry");+ }// An outgoing message to a subagent is its card, so this test uses its reply.root.update(cx, |root, cx| {root.upsert_session_message(acp_v2::SessionMessage::new("from-child").sender_session_id(acp_v2::SessionId::new("child")).recipient_session_id(root_session_id.clone())+ .sender_message_id(acp_v2::MessageId::new("reply")).content(vec!["Found it".into()]),cx,)@@ -20459,9 +20421,18 @@ pub(crate) mod tests {.expect("the sender links to its session");cx.simulate_click(link.center(), gpui::Modifiers::default());cx.run_until_parked();- let active_session_id = active_thread(&conversation_view, cx)- .read_with(cx, |view, cx| view.thread.read(cx).session_id().clone());+ let (active_session_id, scroll_top) =+ active_thread(&conversation_view, cx).read_with(cx, |view, cx| {+ (+ view.thread.read(cx).session_id().clone(),+ view.list_state.logical_scroll_top().item_ix,+ )+ });assert_eq!(active_session_id, acp_v2::SessionId::new("child"));+ assert_eq!(+ scroll_top, 3,+ "the link opens the subagent at its view of the message"+ );}#[gpui::test]diff --git a/crates/agent_ui/src/conversation_view/subagent_card.rs b/crates/agent_ui/src/conversation_view/subagent_card.rsindex 119e3871c82..094e7adad73 100644--- a/crates/agent_ui/src/conversation_view/subagent_card.rs+++ b/crates/agent_ui/src/conversation_view/subagent_card.rs@@ -1,12 +1,12 @@use acp_thread::{- AcpThread, AgentThreadEntry, MessageIdentity, SessionMessage, ToolCall, ToolCallContent,- ToolCallStatus,+ AcpThread, AgentThreadEntry, MessageIdentity, SessionMessage, SessionMessageSide, ToolCall,+ ToolCallContent, ToolCallStatus,};use agent_client_protocol::schema::v2 as acp_v2;use gpui::{App, Entity, SharedString};use std::{fmt, ops::Range};-use super::thread_view::{SessionMessageSide, session_message_side, subagent_label};+use super::thread_view::subagent_label;/// Native subagent tool calls report a user cancellation as output with this text.const USER_CANCELED_OUTPUT: &str = "User canceled";@@ -43,7 +43,7 @@ pub(crate) fn acp_subagent_card(let own_session_id = thread.session_id();let SessionMessageSide::Outgoing {recipient: Some(recipient),- } = session_message_side(message, own_session_id)+ } = message.side(own_session_id)else {return None;};@@ -55,7 +55,7 @@ pub(crate) fn acp_subagent_card(matches!(entry,AgentThreadEntry::SessionMessage(earlier)- if session_message_side(earlier, own_session_id)+ if earlier.side(own_session_id)== SessionMessageSide::Outgoing { recipient: Some(recipient) })});diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rsindex 999dc9c500c..740791f56b5 100644--- a/crates/agent_ui/src/conversation_view/thread_view.rs+++ b/crates/agent_ui/src/conversation_view/thread_view.rs@@ -11,7 +11,8 @@ use std::{cell::RefCell, path::Path};use acp_thread::{Elicitation, ElicitationEntryId, ElicitationStatus, ForegroundActivity, OutputTokensUpdate,SandboxAuthorizationDetails, SandboxFallbackAuthorizationDetails, SandboxNotAppliedReason,- SubmissionId, SubmissionResponse, SubmissionState, ToolCallLocation, decode_path_escapes,+ SessionMessageSide, SubmissionId, SubmissionResponse, SubmissionState, ToolCallLocation,+ decode_path_escapes,};use agent::{SandboxStatusKey, SandboxStatusRefresh, SkillLoadingIssue, SkillLoadingIssueKind,@@ -58,38 +59,6 @@ use super::elicitation::{use super::subagent_card::{SubagentCardId, SubagentCardState, SubagentStatus, acp_subagent_card};use super::*;-/// Which side of a session message a transcript shows, and the other participant when it-/// is known.-#[derive(Clone, Copy, Debug, PartialEq, Eq)]-pub(super) enum SessionMessageSide<'a> {- Outgoing {- recipient: Option<&'a acp_v2::SessionId>,- },- Incoming {- sender: Option<&'a acp_v2::SessionId>,- },- Unknown,-}--/// The transcript's own session is always one participant, so a single known participant-/// that is another session also tells the direction.-pub(super) fn session_message_side<'a>(- message: &'a acp_thread::SessionMessage,- own_session_id: &acp_v2::SessionId,-) -> SessionMessageSide<'a> {- let sender = message.sender_session_id.as_ref();- let recipient = message.recipient_session_id.as_ref();- if sender == Some(own_session_id) {- SessionMessageSide::Outgoing { recipient }- } else if recipient == Some(own_session_id) || sender.is_some() {- SessionMessageSide::Incoming { sender }- } else if recipient.is_some() {- SessionMessageSide::Outgoing { recipient }- } else {- SessionMessageSide::Unknown- }-}-/// How a parent's view names a subagent. An ACP parent's own title for the subagent/// describes it in that view, so it wins over the subagent's title for itself.pub(super) fn subagent_label(thread: &AcpThread) -> SharedString {@@ -8151,6 +8120,14 @@ impl ThreadView {cx.notify();}+ pub(crate) fn scroll_to_entry(&mut self, entry_ix: usize, cx: &mut Context<Self>) {+ self.list_state.scroll_to(ListOffset {+ item_ix: entry_ix,+ offset_in_item: px(0.),+ });+ cx.notify();+ }+fn handle_feedback_click(&mut self,feedback: ThreadFeedback,@@ -8910,7 +8887,7 @@ impl ThreadView {cx: &Context<Self>,) -> Div {let own_session_id = self.thread.read(cx).session_id().clone();- let (icon, direction, participant) = match session_message_side(message, &own_session_id) {+ let (icon, direction, participant) = match message.side(&own_session_id) {SessionMessageSide::Outgoing { recipient } => (IconName::Send, "To", recipient),SessionMessageSide::Incoming { sender } => (IconName::Envelope, "From", sender),SessionMessageSide::Unknown => (IconName::Envelope, "Message between sessions", None),@@ -8926,11 +8903,12 @@ impl ThreadView {.on_click(cx.listener({let session_id = session_id.clone();move |this, _, window, cx| {- this.server_view- .update(cx, |view, cx| {- view.navigate_to_thread(session_id.clone(), window, cx)- })- .log_err();+ this.open_session_message_participant(+ entry_ix,+ &session_id,+ window,+ cx,+ );}})),)@@ -9002,6 +8980,41 @@ impl ThreadView {.child(content)}+ /// Opens the other participant of the session message at `entry_ix`, at its view of the+ /// message when the two views are linked.+ fn open_session_message_participant(+ &mut self,+ entry_ix: usize,+ session_id: &acp_v2::SessionId,+ window: &mut Window,+ cx: &mut Context<Self>,+ ) {+ let Some(server_view) = self.server_view.upgrade() else {+ return;+ };+ let participant_view = server_view.read(cx).thread_view(session_id);+ let thread = self.thread.read(cx);+ let linked_entry_ix = participant_view.as_ref().and_then(|participant_view| {+ let Some(AgentThreadEntry::SessionMessage(message)) = thread.entries().get(entry_ix)+ else {+ return None;+ };+ participant_view+ .read(cx)+ .thread+ .read(cx)+ .linked_session_message(message, thread.session_id())+ });+ server_view.update(cx, |view, cx| {+ view.navigate_to_thread(session_id.clone(), window, cx)+ });+ if let Some(participant_view) = participant_view+ && let Some(linked_entry_ix) = linked_entry_ix+ {+ participant_view.update(cx, |view, cx| view.scroll_to_entry(linked_entry_ix, cx));+ }+ }+/// How this conversation names another of its sessions, or `None` when it has no thread/// for that session.pub(super) fn session_participant_label(