feat: Load session tools in WebSocket connection
Some checks failed
BotServer CI / build (push) Has been cancelled
Some checks failed
BotServer CI / build (push) Has been cancelled
This loads and sends the available tools to the client when establishing a WebSocket connection. Tools are loaded based on the bot configuration and sent in the initial welcome message. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
0a1bd25869
commit
8257d49967
1 changed files with 24 additions and 1 deletions
|
|
@ -1033,12 +1033,35 @@ async fn handle_websocket(
|
||||||
session_id, user_id, bot_id
|
session_id, user_id, bot_id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Get bot_name for tools loading
|
||||||
|
let bot_name_result = {
|
||||||
|
let conn = state.conn.get().ok();
|
||||||
|
if let Some(mut db_conn) = conn {
|
||||||
|
use crate::core::shared::models::schema::bots::dsl::*;
|
||||||
|
bots.filter(id.eq(bot_id))
|
||||||
|
.select(name)
|
||||||
|
.first::<String>(&mut db_conn)
|
||||||
|
.ok()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Load session tools
|
||||||
|
let tools = if let Some(bot_name) = bot_name_result {
|
||||||
|
get_session_tools(&state.conn, &bot_name, &session_id)
|
||||||
|
.unwrap_or_default()
|
||||||
|
} else {
|
||||||
|
vec![]
|
||||||
|
};
|
||||||
|
|
||||||
let welcome = serde_json::json!({
|
let welcome = serde_json::json!({
|
||||||
"type": "connected",
|
"type": "connected",
|
||||||
"session_id": session_id,
|
"session_id": session_id,
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"bot_id": bot_id,
|
"bot_id": bot_id,
|
||||||
"message": "Connected to bot server"
|
"message": "Connected to bot server",
|
||||||
|
"tools": tools
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Ok(welcome_str) = serde_json::to_string(&welcome) {
|
if let Ok(welcome_str) = serde_json::to_string(&welcome) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue