feat(room): add attachment_ids to messages, pass AppConfig, increase max_tool_depth to 1000
This commit is contained in:
parent
dee79f3f7f
commit
b23c6a03c3
@ -74,6 +74,7 @@ impl From<room_message::Model> for super::RoomMessageResponse {
|
|||||||
revoked_by: value.revoked_by,
|
revoked_by: value.revoked_by,
|
||||||
in_reply_to: value.in_reply_to,
|
in_reply_to: value.in_reply_to,
|
||||||
highlighted_content: None,
|
highlighted_content: None,
|
||||||
|
attachment_ids: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -431,6 +432,7 @@ impl RoomService {
|
|||||||
revoked_by: msg.revoked_by,
|
revoked_by: msg.revoked_by,
|
||||||
in_reply_to: msg.in_reply_to,
|
in_reply_to: msg.in_reply_to,
|
||||||
highlighted_content: None,
|
highlighted_content: None,
|
||||||
|
attachment_ids: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,10 +2,10 @@ use crate::error::RoomError;
|
|||||||
use crate::service::RoomService;
|
use crate::service::RoomService;
|
||||||
use crate::ws_context::WsUserContext;
|
use crate::ws_context::WsUserContext;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use models::rooms::{room, room_message, room_thread};
|
use models::rooms::{room, room_attachment, room_message, room_thread};
|
||||||
use models::users::user as user_model;
|
use models::users::user as user_model;
|
||||||
use queue::RoomMessageEnvelope;
|
use queue::RoomMessageEnvelope;
|
||||||
use sea_orm::*;
|
use sea_orm::{sea_query::Expr, *};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
@ -97,11 +97,34 @@ impl RoomService {
|
|||||||
revoked: msg.revoked,
|
revoked: msg.revoked,
|
||||||
revoked_by: msg.revoked_by,
|
revoked_by: msg.revoked_by,
|
||||||
highlighted_content: None,
|
highlighted_content: None,
|
||||||
|
attachment_ids: Vec::new(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
messages.reverse();
|
messages.reverse();
|
||||||
|
|
||||||
|
// Batch-load attachment IDs for all returned messages
|
||||||
|
if !messages.is_empty() {
|
||||||
|
let msg_ids: Vec<Uuid> = messages.iter().map(|m| m.id).collect();
|
||||||
|
let attachments = room_attachment::Entity::find()
|
||||||
|
.filter(room_attachment::Column::Message.is_in(msg_ids))
|
||||||
|
.all(&self.db)
|
||||||
|
.await
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let mut attachment_map: std::collections::HashMap<Uuid, Vec<Uuid>> =
|
||||||
|
std::collections::HashMap::new();
|
||||||
|
for att in attachments {
|
||||||
|
attachment_map.entry(att.message).or_default().push(att.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
for msg in &mut messages {
|
||||||
|
if let Some(ids) = attachment_map.remove(&msg.id) {
|
||||||
|
msg.attachment_ids = ids;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(super::RoomMessageListResponse { messages, total })
|
Ok(super::RoomMessageListResponse { messages, total })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,6 +221,27 @@ impl RoomService {
|
|||||||
|
|
||||||
txn.commit().await?;
|
txn.commit().await?;
|
||||||
|
|
||||||
|
// Link uploaded attachments to this message
|
||||||
|
let attachment_ids = request.attachment_ids.clone();
|
||||||
|
if !attachment_ids.is_empty() {
|
||||||
|
if let Err(e) = room_attachment::Entity::update_many()
|
||||||
|
.col_expr(
|
||||||
|
room_attachment::Column::Message,
|
||||||
|
Expr::value(Some(id)),
|
||||||
|
)
|
||||||
|
.filter(room_attachment::Column::Id.is_in(attachment_ids.clone()))
|
||||||
|
.exec(&self.db)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
slog::warn!(
|
||||||
|
self.log,
|
||||||
|
"Failed to link attachments to message {}: {}",
|
||||||
|
id,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.publish_room_event(
|
self.publish_room_event(
|
||||||
project_id,
|
project_id,
|
||||||
super::RoomEventType::NewMessage,
|
super::RoomEventType::NewMessage,
|
||||||
@ -278,6 +322,7 @@ impl RoomService {
|
|||||||
revoked: None,
|
revoked: None,
|
||||||
revoked_by: None,
|
revoked_by: None,
|
||||||
highlighted_content: None,
|
highlighted_content: None,
|
||||||
|
attachment_ids,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -326,6 +326,7 @@ impl RoomService {
|
|||||||
revoked: msg.revoked,
|
revoked: msg.revoked,
|
||||||
revoked_by: msg.revoked_by,
|
revoked_by: msg.revoked_by,
|
||||||
highlighted_content: None,
|
highlighted_content: None,
|
||||||
|
attachment_ids: Vec::new(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
|||||||
@ -53,6 +53,7 @@ static MENTION_BRACKET_RE: LazyLock<regex_lite::Regex, fn() -> regex_lite::Regex
|
|||||||
pub struct RoomService {
|
pub struct RoomService {
|
||||||
pub db: AppDatabase,
|
pub db: AppDatabase,
|
||||||
pub cache: AppCache,
|
pub cache: AppCache,
|
||||||
|
pub config: config::AppConfig,
|
||||||
pub room_manager: Arc<RoomConnectionManager>,
|
pub room_manager: Arc<RoomConnectionManager>,
|
||||||
pub queue: MessageProducer,
|
pub queue: MessageProducer,
|
||||||
pub redis_url: String,
|
pub redis_url: String,
|
||||||
@ -68,6 +69,7 @@ impl RoomService {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
db: AppDatabase,
|
db: AppDatabase,
|
||||||
cache: AppCache,
|
cache: AppCache,
|
||||||
|
config: config::AppConfig,
|
||||||
queue: MessageProducer,
|
queue: MessageProducer,
|
||||||
room_manager: Arc<RoomConnectionManager>,
|
room_manager: Arc<RoomConnectionManager>,
|
||||||
redis_url: String,
|
redis_url: String,
|
||||||
@ -82,6 +84,7 @@ impl RoomService {
|
|||||||
Self {
|
Self {
|
||||||
db,
|
db,
|
||||||
cache,
|
cache,
|
||||||
|
config,
|
||||||
room_manager,
|
room_manager,
|
||||||
queue,
|
queue,
|
||||||
redis_url,
|
redis_url,
|
||||||
@ -898,6 +901,7 @@ impl RoomService {
|
|||||||
let request = AiRequest {
|
let request = AiRequest {
|
||||||
db: self.db.clone(),
|
db: self.db.clone(),
|
||||||
cache: self.cache.clone(),
|
cache: self.cache.clone(),
|
||||||
|
config: self.config.clone(),
|
||||||
model,
|
model,
|
||||||
project: project.clone(),
|
project: project.clone(),
|
||||||
sender,
|
sender,
|
||||||
@ -913,7 +917,7 @@ impl RoomService {
|
|||||||
presence_penalty: 0.0,
|
presence_penalty: 0.0,
|
||||||
think: ai_config.think,
|
think: ai_config.think,
|
||||||
tools: Some(chat_service.tools()),
|
tools: Some(chat_service.tools()),
|
||||||
max_tool_depth: 3,
|
max_tool_depth: 1000,
|
||||||
};
|
};
|
||||||
|
|
||||||
let use_streaming = ai_config.stream;
|
let use_streaming = ai_config.stream;
|
||||||
|
|||||||
@ -185,6 +185,8 @@ pub struct RoomMessageCreateRequest {
|
|||||||
#[serde(rename = "thread_id")]
|
#[serde(rename = "thread_id")]
|
||||||
pub thread: Option<Uuid>,
|
pub thread: Option<Uuid>,
|
||||||
pub in_reply_to: Option<Uuid>,
|
pub in_reply_to: Option<Uuid>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub attachment_ids: Vec<Uuid>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, utoipa::ToSchema)]
|
#[derive(Debug, Clone, Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
@ -222,6 +224,8 @@ pub struct RoomMessageResponse {
|
|||||||
/// Highlighted content with <mark> tags around matched terms (for search results)
|
/// Highlighted content with <mark> tags around matched terms (for search results)
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub highlighted_content: Option<String>,
|
pub highlighted_content: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub attachment_ids: Vec<Uuid>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Search result wrapper (keeps API compatibility)
|
/// Search result wrapper (keeps API compatibility)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user