acp_thread: Make UserMessageId required in AgentConnection::prompt (#53850)
The `user_message_id` parameter on `AgentConnection::prompt` was `Option<UserMessageId>`, but `NativeAgentConnection::prompt` immediately called `.expect()` on it, crashing when the value was `None`. Because the `expect` message said `UserMessageId` was required, this PR makes the parameter not optional which makes the panic impossible. This means we also need to unconditionally generate an ID in `send`, where before we gated this on whether `truncate` returned `Some`. Generating IDs unconditionally should be find, especially because the prompt requires them. Release Notes: - N/A
This commit is contained in:
1 parent
2065099bc8
commit
549db9fbb3
6 files changed
+16
-21
No files matched your search
@@ -2162,17 +2162,13 @@ impl AcpThread {
|
||||
let request = acp::PromptRequest::new(self.session_id.clone(), message.clone());
|
||||
let git_store = self.project.read(cx).git_store().clone();
|
||||
|
||||
let message_id = if self.connection.truncate(&self.session_id, cx).is_some() {
|
||||
Some(UserMessageId::new())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let message_id = UserMessageId::new();
|
||||
|
||||
self.run_turn(cx, async move |this, cx| {
|
||||
this.update(cx, |this, cx| {
|
||||
this.push_entry(
|
||||
AgentThreadEntry::UserMessage(UserMessage {
|
||||
id: message_id.clone(),
|
||||
id: Some(message_id.clone()),
|
||||
content: block,
|
||||
chunks: message,
|
||||
checkpoint: None,
|
||||
@@ -4469,7 +4465,7 @@ mod tests {
|
||||
|
||||
fn prompt(
|
||||
&self,
|
||||
_id: Option<UserMessageId>,
|
||||
_id: UserMessageId,
|
||||
params: acp::PromptRequest,
|
||||
cx: &mut App,
|
||||
) -> Task<gpui::Result<acp::PromptResponse>> {
|
||||
|
||||
@@ -125,7 +125,7 @@ pub trait AgentConnection {
|
||||
|
||||
fn prompt(
|
||||
&self,
|
||||
user_message_id: Option<UserMessageId>,
|
||||
user_message_id: UserMessageId,
|
||||
params: acp::PromptRequest,
|
||||
cx: &mut App,
|
||||
) -> Task<Result<acp::PromptResponse>>;
|
||||
@@ -875,7 +875,7 @@ mod test_support {
|
||||
|
||||
fn prompt(
|
||||
&self,
|
||||
_id: Option<UserMessageId>,
|
||||
_id: UserMessageId,
|
||||
params: acp::PromptRequest,
|
||||
cx: &mut App,
|
||||
) -> Task<gpui::Result<acp::PromptResponse>> {
|
||||
|
||||
@@ -1489,11 +1489,10 @@ impl acp_thread::AgentConnection for NativeAgentConnection {
|
||||
|
||||
fn prompt(
|
||||
&self,
|
||||
id: Option<acp_thread::UserMessageId>,
|
||||
id: acp_thread::UserMessageId,
|
||||
params: acp::PromptRequest,
|
||||
cx: &mut App,
|
||||
) -> Task<Result<acp::PromptResponse>> {
|
||||
let id = id.expect("UserMessageId is required");
|
||||
let session_id = params.session_id.clone();
|
||||
log::info!("Received prompt request for session: {}", session_id);
|
||||
log::debug!("Prompt blocks count: {}", params.prompt.len());
|
||||
|
||||
@@ -3350,7 +3350,7 @@ async fn test_agent_connection(cx: &mut TestAppContext) {
|
||||
let result = cx
|
||||
.update(|cx| {
|
||||
connection.prompt(
|
||||
Some(acp_thread::UserMessageId::new()),
|
||||
acp_thread::UserMessageId::new(),
|
||||
acp::PromptRequest::new(session_id.clone(), vec!["ghi".into()]),
|
||||
cx,
|
||||
)
|
||||
|
||||
@@ -955,7 +955,7 @@ impl AgentConnection for AcpConnection {
|
||||
|
||||
fn prompt(
|
||||
&self,
|
||||
_id: Option<acp_thread::UserMessageId>,
|
||||
_id: acp_thread::UserMessageId,
|
||||
params: acp::PromptRequest,
|
||||
cx: &mut App,
|
||||
) -> Task<Result<acp::PromptResponse>> {
|
||||
|
||||
@@ -3252,7 +3252,7 @@ pub(crate) mod tests {
|
||||
|
||||
fn prompt(
|
||||
&self,
|
||||
_id: Option<acp_thread::UserMessageId>,
|
||||
_id: acp_thread::UserMessageId,
|
||||
_params: acp::PromptRequest,
|
||||
_cx: &mut App,
|
||||
) -> Task<gpui::Result<acp::PromptResponse>> {
|
||||
@@ -4314,7 +4314,7 @@ pub(crate) mod tests {
|
||||
|
||||
fn prompt(
|
||||
&self,
|
||||
_id: Option<acp_thread::UserMessageId>,
|
||||
_id: acp_thread::UserMessageId,
|
||||
_params: acp::PromptRequest,
|
||||
_cx: &mut App,
|
||||
) -> Task<anyhow::Result<acp::PromptResponse>> {
|
||||
@@ -4387,7 +4387,7 @@ pub(crate) mod tests {
|
||||
|
||||
fn prompt(
|
||||
&self,
|
||||
_id: Option<acp_thread::UserMessageId>,
|
||||
_id: acp_thread::UserMessageId,
|
||||
_params: acp::PromptRequest,
|
||||
_cx: &mut App,
|
||||
) -> Task<gpui::Result<acp::PromptResponse>> {
|
||||
@@ -4486,7 +4486,7 @@ pub(crate) mod tests {
|
||||
|
||||
fn prompt(
|
||||
&self,
|
||||
_id: Option<acp_thread::UserMessageId>,
|
||||
_id: acp_thread::UserMessageId,
|
||||
_params: acp::PromptRequest,
|
||||
_cx: &mut App,
|
||||
) -> Task<gpui::Result<acp::PromptResponse>> {
|
||||
@@ -4555,7 +4555,7 @@ pub(crate) mod tests {
|
||||
|
||||
fn prompt(
|
||||
&self,
|
||||
_id: Option<acp_thread::UserMessageId>,
|
||||
_id: acp_thread::UserMessageId,
|
||||
_params: acp::PromptRequest,
|
||||
_cx: &mut App,
|
||||
) -> Task<gpui::Result<acp::PromptResponse>> {
|
||||
@@ -4625,7 +4625,7 @@ pub(crate) mod tests {
|
||||
|
||||
fn prompt(
|
||||
&self,
|
||||
_id: Option<acp_thread::UserMessageId>,
|
||||
_id: acp_thread::UserMessageId,
|
||||
_params: acp::PromptRequest,
|
||||
_cx: &mut App,
|
||||
) -> Task<gpui::Result<acp::PromptResponse>> {
|
||||
@@ -4741,7 +4741,7 @@ pub(crate) mod tests {
|
||||
|
||||
fn prompt(
|
||||
&self,
|
||||
_id: Option<acp_thread::UserMessageId>,
|
||||
_id: acp_thread::UserMessageId,
|
||||
_params: acp::PromptRequest,
|
||||
_cx: &mut App,
|
||||
) -> Task<gpui::Result<acp::PromptResponse>> {
|
||||
@@ -7343,7 +7343,7 @@ pub(crate) mod tests {
|
||||
|
||||
fn prompt(
|
||||
&self,
|
||||
_id: Option<acp_thread::UserMessageId>,
|
||||
_id: acp_thread::UserMessageId,
|
||||
_params: acp::PromptRequest,
|
||||
_cx: &mut App,
|
||||
) -> Task<gpui::Result<acp::PromptResponse>> {
|
||||
|
||||
Reference in new issue
Block a user