fix(room): support multiple AIs per room in should_ai_respond
- Add get_room_ai_configs() to fetch all AI configs for a room - Check all AI model IDs against @ai mentions
This commit is contained in:
parent
46a0bdc21e
commit
55d33862f6
@ -59,6 +59,18 @@ pub async fn get_room_ai_config(
|
|||||||
Ok(ai_config)
|
Ok(ai_config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_room_ai_configs(
|
||||||
|
db: &AppDatabase,
|
||||||
|
room_id: Uuid,
|
||||||
|
) -> Result<Vec<room_ai::Model>, RoomError> {
|
||||||
|
let ai_configs = room_ai::Entity::find()
|
||||||
|
.filter(room_ai::Column::Room.eq(room_id))
|
||||||
|
.all(db)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(ai_configs)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn extract_mention_context(
|
pub async fn extract_mention_context(
|
||||||
db: &AppDatabase,
|
db: &AppDatabase,
|
||||||
project_id: Uuid,
|
project_id: Uuid,
|
||||||
|
|||||||
@ -258,17 +258,20 @@ impl RoomService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn should_ai_respond(&self, room_id: Uuid, content: &str) -> Result<bool, RoomError> {
|
pub async fn should_ai_respond(&self, room_id: Uuid, content: &str) -> Result<bool, RoomError> {
|
||||||
let ai_config = history::get_room_ai_config(&self.db, room_id).await?;
|
let ai_configs = history::get_room_ai_configs(&self.db, room_id).await?;
|
||||||
let config = match ai_config {
|
if ai_configs.is_empty() {
|
||||||
Some(c) => c,
|
return Ok(false);
|
||||||
None => return Ok(false),
|
}
|
||||||
};
|
|
||||||
|
|
||||||
let model_id_str = config.model.to_string();
|
// Collect all model IDs in this room
|
||||||
|
let model_ids: std::collections::HashSet<String> = ai_configs
|
||||||
|
.iter()
|
||||||
|
.map(|c| c.model.to_string())
|
||||||
|
.collect();
|
||||||
|
|
||||||
for cap in mention_bracket_re().captures_iter(content) {
|
for cap in mention_bracket_re().captures_iter(content) {
|
||||||
if let (Some(type_m), Some(id_m)) = (cap.get(1), cap.get(2)) {
|
if let (Some(type_m), Some(id_m)) = (cap.get(1), cap.get(2)) {
|
||||||
if type_m.as_str() == "ai" && id_m.as_str().trim() == model_id_str {
|
if type_m.as_str() == "ai" && model_ids.contains(id_m.as_str().trim()) {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,7 +279,7 @@ impl RoomService {
|
|||||||
|
|
||||||
for cap in mention_tag_re().captures_iter(content) {
|
for cap in mention_tag_re().captures_iter(content) {
|
||||||
if let (Some(type_m), Some(id_m)) = (cap.get(1), cap.get(2)) {
|
if let (Some(type_m), Some(id_m)) = (cap.get(1), cap.get(2)) {
|
||||||
if type_m.as_str() == "ai" && id_m.as_str().trim() == model_id_str {
|
if type_m.as_str() == "ai" && model_ids.contains(id_m.as_str().trim()) {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user