Enable automatic web search by default; improve toggle behavior and search planning.
This commit is contained in:
@@ -111,6 +111,7 @@ export function createChatStatements(db) {
|
||||
LIMIT 1
|
||||
`),
|
||||
updateChatSessionTitle: db.prepare("UPDATE chat_sessions SET title = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? AND username = ?"),
|
||||
updateChatUserPersona: db.prepare("UPDATE chat_sessions SET user_persona_id = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? AND username = ?"),
|
||||
updateChatSessionScene: db.prepare("UPDATE chat_sessions SET scenario_prompt = ?, scenario_summary = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? AND username = ?"),
|
||||
updateChatContextSummary: db.prepare("UPDATE chat_sessions SET context_summary = ?, context_summary_message_id = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? AND username = ?"),
|
||||
updateChatGenerationSettings: db.prepare(`
|
||||
@@ -432,6 +433,7 @@ const failChatTurnTransaction = db.transaction((chatId, userMessageId, errorMess
|
||||
return statements.getChatSession.get(chatId, username);
|
||||
},
|
||||
updateChatTitle: (chatId, username, title) => statements.updateChatSessionTitle.run(title, chatId, username),
|
||||
updateChatUserPersona: (chatId, username, personaId) => statements.updateChatUserPersona.run(personaId ?? null, chatId, username),
|
||||
updateChatScene: (chatId, username, scenarioPrompt, scenarioSummary) => statements.updateChatSessionScene.run(scenarioPrompt, scenarioSummary, chatId, username),
|
||||
updateChatContextSummary: (chatId, username, summary, messageId) => statements.updateChatContextSummary.run(summary, Number(messageId || 0), chatId, username),
|
||||
getPersonaChatState: (chatId, username) => statements.getPersonaChatState.get(chatId, username) || null,
|
||||
|
||||
@@ -116,6 +116,13 @@ const preferredModelValidator = (body) => {
|
||||
return {value: {model}};
|
||||
};
|
||||
|
||||
const userPersonaValidator = (body) => {
|
||||
if (body?.userPersonaId == null || body.userPersonaId === "") return {value: {userPersonaId: null}};
|
||||
const userPersonaId = Number(body.userPersonaId);
|
||||
if (!Number.isInteger(userPersonaId) || userPersonaId < 1) return {error: "Invalid user persona"};
|
||||
return {value: {userPersonaId}};
|
||||
};
|
||||
|
||||
export function createChatsRouter({repositories, chatService, modelService, config, chatRateLimiters, attachmentService}) {
|
||||
const router = express.Router();
|
||||
router.use(requireLogin);
|
||||
@@ -272,6 +279,32 @@ export function createChatsRouter({repositories, chatService, modelService, conf
|
||||
return res.json({chat: repositories.getChat(chatId, req.session.user)});
|
||||
});
|
||||
|
||||
router.put("/chats/:id/user-persona", validateBody(userPersonaValidator), (req, res) => {
|
||||
const chatId = Number(req.params.id);
|
||||
const user = req.session.user;
|
||||
const chat = repositories.getChat(chatId, user);
|
||||
if (!chat) return res.status(404).json({error: "Chat not found"});
|
||||
const {userPersonaId} = req.validatedBody;
|
||||
if (userPersonaId) {
|
||||
const persona = repositories.getPersona(userPersonaId, user);
|
||||
if (!persona || persona.persona_type !== "user") return res.status(404).json({error: "User persona not found"});
|
||||
}
|
||||
repositories.updateChatUserPersona(chatId, user, userPersonaId);
|
||||
if (chat.assistant_persona_id) {
|
||||
const assistantPersona = repositories.getPersona(chat.assistant_persona_id, user);
|
||||
const userPersona = userPersonaId ? repositories.getPersona(userPersonaId, user) : null;
|
||||
if (assistantPersona) {
|
||||
repositories.updateChatScene(
|
||||
chatId,
|
||||
user,
|
||||
chat.scenario_prompt,
|
||||
chatService.buildRoleplaySceneSummary(assistantPersona, userPersona, chat.scenario_prompt)
|
||||
);
|
||||
}
|
||||
}
|
||||
return res.json({chat: repositories.getChat(chatId, user)});
|
||||
});
|
||||
|
||||
router.post("/chats/:id/branches/:messageId/activate", (req, res) => {
|
||||
const result = chatService.activateBranch({
|
||||
user: req.session.user,
|
||||
|
||||
Reference in New Issue
Block a user