Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(web_chat): add content check for chat submission

Steven Enamakelaec952fdd540
diff --git a/crates/openhuman-core/src/web_chat/ops/start_chat.rs b/crates/openhuman-core/src/web_chat/ops/start_chat.rs
index 49fe1870fa..39c1e1bb9b 100644
--- a/crates/openhuman-core/src/web_chat/ops/start_chat.rs
+++ b/crates/openhuman-core/src/web_chat/ops/start_chat.rs
@@ -69,6 +69,16 @@ fn guardrail_verdict_user_message(verdict: &str) -> &'static str {
}
}
+fn submission_has_content(
+ message: &str,
+ stored_attachments: Option<&crate::agent::queued_turn::StoredAttachmentInput>,
+ attachment_uploads: Option<&[tinychannels_bus::ContentPart]>,
+) -> bool {
+ !message.trim().is_empty()
+ || stored_attachments.is_some_and(|input| !input.parts.is_empty())
+ || attachment_uploads.is_some_and(|parts| !parts.is_empty())
+}
+
impl std::error::Error for StartChatError {}
impl From<String> for StartChatError {
@@ -331,7 +341,11 @@ async fn start_chat_inner(
if thread_id.is_empty() {
return Err(StartChatError::Other("thread_id is required".to_string()));
}
- if message.is_empty() {
+ if !submission_has_content(
+ &message,
+ stored_attachments.as_ref(),
+ attachment_uploads.as_deref(),
+ ) {
return Err(StartChatError::Other("message is required".to_string()));
}
// A profile this node no longer hosts (its lease was lost or released)
diff --git a/crates/openhuman-core/src/web_chat/ops/start_chat_tests.rs b/crates/openhuman-core/src/web_chat/ops/start_chat_tests.rs
index 008c1a5e7f..1bf6e08f66 100644
--- a/crates/openhuman-core/src/web_chat/ops/start_chat_tests.rs
+++ b/crates/openhuman-core/src/web_chat/ops/start_chat_tests.rs
@@ -76,6 +76,27 @@ fn plain_string_conversions_build_other_variant() {
assert!(matches!(from_borrowed, StartChatError::Other(ref m) if m == "message is required"));
}
+#[test]
+fn typed_media_is_valid_chat_input_without_caption_text() {
+ let image = tinychannels_bus::ContentPart::Image {
+ media: tinychannels_bus::MediaReference::default(),
+ caption: None,
+ alt_text: None,
+ };
+ let stored = crate::agent::queued_turn::StoredAttachmentInput {
+ persisted_message_id: "user:row-1".into(),
+ parts: vec![image.clone()],
+ };
+ assert!(submission_has_content("", Some(&stored), None));
+ assert!(submission_has_content(" ", None, Some(std::slice::from_ref(&image))));
+ assert!(!submission_has_content(" ", None, None));
+ assert!(!submission_has_content(
+ "",
+ Some(&crate::agent::queued_turn::StoredAttachmentInput::default()),
+ Some(&[]),
+ ));
+}
+
#[tokio::test]
async fn voice_note_turn_id_is_bound_to_its_exact_user_row_before_admission() {
use crate::core::runtime::{ContextOverlay, CoreContext, DispatchCtx, DomainSet};