fix(room): include @user mentions in AI prompt context
- Extend extract_mention_context to handle user mentions - Both @[repo:xxx] and @[user:xxx] are now included in AI context
This commit is contained in:
parent
76e3d19cf5
commit
108dd714d3
@ -2,6 +2,7 @@ use db::database::AppDatabase;
|
|||||||
use models::repos::repo;
|
use models::repos::repo;
|
||||||
use models::rooms::room_ai;
|
use models::rooms::room_ai;
|
||||||
use models::rooms::room_message::{Column as RmCol, Entity as RoomMessage};
|
use models::rooms::room_message::{Column as RmCol, Entity as RoomMessage};
|
||||||
|
use models::users::user;
|
||||||
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, QueryOrder, QuerySelect};
|
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, QueryOrder, QuerySelect};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
@ -78,11 +79,16 @@ pub async fn extract_mention_context(
|
|||||||
) -> Vec<agent::chat::Mention> {
|
) -> Vec<agent::chat::Mention> {
|
||||||
let mut mentions: Vec<agent::chat::Mention> = Vec::new();
|
let mut mentions: Vec<agent::chat::Mention> = Vec::new();
|
||||||
let mut seen_repos: Vec<String> = Vec::new();
|
let mut seen_repos: Vec<String> = Vec::new();
|
||||||
|
let mut seen_users: Vec<String> = Vec::new();
|
||||||
|
|
||||||
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() == "repo" {
|
let type_str = type_m.as_str();
|
||||||
let repo_name = id_m.as_str().trim().to_string();
|
let id = id_m.as_str().trim();
|
||||||
|
|
||||||
|
match type_str {
|
||||||
|
"repo" => {
|
||||||
|
let repo_name = id.to_string();
|
||||||
if repo_name.is_empty() || seen_repos.contains(&repo_name) {
|
if repo_name.is_empty() || seen_repos.contains(&repo_name) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -97,6 +103,20 @@ pub async fn extract_mention_context(
|
|||||||
mentions.push(agent::chat::Mention::Repo(repo_model));
|
mentions.push(agent::chat::Mention::Repo(repo_model));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"user" => {
|
||||||
|
if seen_users.contains(&id.to_string()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
seen_users.push(id.to_string());
|
||||||
|
|
||||||
|
if let Ok(uuid) = Uuid::parse_str(id) {
|
||||||
|
if let Ok(Some(user_model)) = user::Entity::find_by_id(uuid).one(db).await {
|
||||||
|
mentions.push(agent::chat::Mention::User(user_model));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user