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::rooms::room_ai;
|
||||
use models::rooms::room_message::{Column as RmCol, Entity as RoomMessage};
|
||||
use models::users::user;
|
||||
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, QueryOrder, QuerySelect};
|
||||
use uuid::Uuid;
|
||||
|
||||
@ -78,24 +79,43 @@ pub async fn extract_mention_context(
|
||||
) -> Vec<agent::chat::Mention> {
|
||||
let mut mentions: Vec<agent::chat::Mention> = 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) {
|
||||
if let (Some(type_m), Some(id_m)) = (cap.get(1), cap.get(2)) {
|
||||
if type_m.as_str() == "repo" {
|
||||
let repo_name = id_m.as_str().trim().to_string();
|
||||
if repo_name.is_empty() || seen_repos.contains(&repo_name) {
|
||||
continue;
|
||||
}
|
||||
seen_repos.push(repo_name.clone());
|
||||
let type_str = type_m.as_str();
|
||||
let id = id_m.as_str().trim();
|
||||
|
||||
if let Ok(Some(repo_model)) = repo::Entity::find()
|
||||
.filter(repo::Column::Project.eq(project_id))
|
||||
.filter(repo::Column::RepoName.eq(&repo_name))
|
||||
.one(db)
|
||||
.await
|
||||
{
|
||||
mentions.push(agent::chat::Mention::Repo(repo_model));
|
||||
match type_str {
|
||||
"repo" => {
|
||||
let repo_name = id.to_string();
|
||||
if repo_name.is_empty() || seen_repos.contains(&repo_name) {
|
||||
continue;
|
||||
}
|
||||
seen_repos.push(repo_name.clone());
|
||||
|
||||
if let Ok(Some(repo_model)) = repo::Entity::find()
|
||||
.filter(repo::Column::Project.eq(project_id))
|
||||
.filter(repo::Column::RepoName.eq(&repo_name))
|
||||
.one(db)
|
||||
.await
|
||||
{
|
||||
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