Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/agent/channel_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,24 @@ fn extract_reply_content_from_cancelled_history(
if let Some(content_value) = tool_call.function.arguments.get("content")
&& let Some(text) = content_value.as_str()
{
return Some(text.to_string());
// Also extract card descriptions so the full response
// (not just the short content text) is preserved in
// conversation history for the webchat frontend.
let card_text = tool_call
.function
.arguments
.get("cards")
.and_then(|v| serde_json::from_value::<Vec<crate::Card>>(v.clone()).ok())
.map(|cards| crate::OutboundResponse::text_from_cards(&cards))
.unwrap_or_default();

if card_text.is_empty() {
return Some(text.to_string());
} else if text.trim().is_empty() {
return Some(card_text);
} else {
return Some(format!("{}\n\n{}", text, card_text));
}
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ fn forward_sse_event(
) {
match response {
spacebot::OutboundResponse::Text(text)
| spacebot::OutboundResponse::RichMessage { text, .. }
| spacebot::OutboundResponse::ThreadReply { text, .. } => {
api_event_tx
.send(spacebot::api::ApiEvent::OutboundMessage {
Expand All @@ -285,6 +284,25 @@ fn forward_sse_event(
})
.ok();
}
spacebot::OutboundResponse::RichMessage { text, cards, .. } => {
// Flatten card content into the text so the webchat frontend
// (which doesn't support rich embeds) shows the full response.
let card_text = spacebot::OutboundResponse::text_from_cards(cards);
let full_text = if card_text.is_empty() {
text.clone()
} else if text.trim().is_empty() {
card_text
} else {
format!("{}\n\n{}", text, card_text)
};
api_event_tx
.send(spacebot::api::ApiEvent::OutboundMessage {
agent_id: agent_id.to_string(),
channel_id: channel_id.to_string(),
text: full_text,
})
.ok();
}
spacebot::OutboundResponse::Status(spacebot::StatusUpdate::Thinking) => {
api_event_tx
.send(spacebot::api::ApiEvent::TypingState {
Expand Down
13 changes: 12 additions & 1 deletion src/messaging/webchat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,18 @@ impl Messaging for WebChatAdapter {
async fn broadcast(&self, target: &str, response: OutboundResponse) -> crate::Result<()> {
let text = match &response {
OutboundResponse::Text(text) => text.clone(),
OutboundResponse::RichMessage { text, .. } => text.clone(),
OutboundResponse::RichMessage { text, cards, .. } => {
// Flatten card content into the text so the webchat frontend
// (which doesn't support rich embeds) shows the full response.
let card_text = OutboundResponse::text_from_cards(cards);
if card_text.is_empty() {
text.clone()
} else if text.trim().is_empty() {
card_text
} else {
format!("{}\n\n{}", text, card_text)
}
}
_ => return Ok(()),
};

Expand Down
24 changes: 21 additions & 3 deletions src/tools/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,25 +460,43 @@ impl Tool for ReplyTool {
text: converted_content.clone(),
}
} else if args.cards.is_some() || args.interactive_elements.is_some() || poll.is_some() {
let cards = args.cards.unwrap_or_default();
let interactive_elements = args.interactive_elements.unwrap_or_default();
OutboundResponse::RichMessage {
text: converted_content.clone(),
blocks: vec![],
cards: args.cards.unwrap_or_default(),
interactive_elements: args.interactive_elements.unwrap_or_default(),
cards,
interactive_elements,
poll,
}
} else {
OutboundResponse::Text(converted_content.clone())
};

// For the conversation log, include flattened card content so that
// the webchat history (which doesn't support rich embeds) shows the
// full response when messages are loaded from the database.
let logged_content = if let OutboundResponse::RichMessage { cards, .. } = &response {
let card_text = OutboundResponse::text_from_cards(cards);
if card_text.is_empty() {
converted_content.clone()
} else if converted_content.trim().is_empty() {
card_text
} else {
format!("{}\n\n{}", converted_content, card_text)
}
} else {
converted_content.clone()
};

self.response_tx
.send(response)
.await
.map_err(|e| ReplyError(format!("failed to send reply: {e}")))?;

self.conversation_logger.log_bot_message_with_name(
&self.channel_id,
&converted_content,
&logged_content,
Some(&self.agent_display_name),
);

Expand Down
Loading