fix(room): require @ai mention to trigger AI response
- process_message_ai now returns early if no @ai mention is found - Verify mentioned AI exists in the room before responding
This commit is contained in:
parent
55d33862f6
commit
76e3d19cf5
@ -321,8 +321,48 @@ impl RoomService {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let Some(ai_config) = self.get_room_ai_config(room_id).await? else {
|
||||
return Ok(());
|
||||
// Extract mentioned AI model ID from content
|
||||
let mentioned_model_id = {
|
||||
let mut found = None;
|
||||
for cap in mention_bracket_re().captures_iter(&content) {
|
||||
if let (Some(type_m), Some(id_m)) = (cap.get(1), cap.get(2)) {
|
||||
if type_m.as_str() == "ai" {
|
||||
if let Ok(uuid) = Uuid::parse_str(id_m.as_str().trim()) {
|
||||
found = Some(uuid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if found.is_none() {
|
||||
for cap in mention_tag_re().captures_iter(&content) {
|
||||
if let (Some(type_m), Some(id_m)) = (cap.get(1), cap.get(2)) {
|
||||
if type_m.as_str() == "ai" {
|
||||
if let Ok(uuid) = Uuid::parse_str(id_m.as_str().trim()) {
|
||||
found = Some(uuid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
found
|
||||
};
|
||||
|
||||
let model_id = match mentioned_model_id {
|
||||
Some(id) => id,
|
||||
None => return Ok(()), // No @ai mention, don't respond
|
||||
};
|
||||
|
||||
// Verify the mentioned AI exists in this room
|
||||
let ai_config = match room_ai::Entity::find()
|
||||
.filter(room_ai::Column::Room.eq(room_id))
|
||||
.filter(room_ai::Column::Model.eq(model_id))
|
||||
.one(&self.db)
|
||||
.await?
|
||||
{
|
||||
Some(c) => c,
|
||||
None => return Ok(()), // Mentioned AI not in this room
|
||||
};
|
||||
|
||||
let Some(lock_guard) =
|
||||
@ -337,23 +377,6 @@ impl RoomService {
|
||||
.one(&self.db)
|
||||
.await?
|
||||
.ok_or_else(|| RoomError::NotFound("Project not found".to_string()))?;
|
||||
|
||||
let mentioned_model_id = {
|
||||
let mut found = None;
|
||||
for cap in mention_bracket_re().captures_iter(&content) {
|
||||
if let (Some(type_m), Some(id_m)) = (cap.get(1), cap.get(2)) {
|
||||
if type_m.as_str() == "ai" {
|
||||
if let Ok(uuid) = Uuid::parse_str(id_m.as_str().trim()) {
|
||||
found = Some(uuid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
found
|
||||
};
|
||||
|
||||
let model_id = mentioned_model_id.unwrap_or(ai_config.model);
|
||||
let model = models::agents::model::Entity::find_by_id(model_id)
|
||||
.one(&self.db)
|
||||
.await?
|
||||
|
||||
Loading…
Reference in New Issue
Block a user