Enable automatic web search by default; improve toggle behavior and search planning.
This commit is contained in:
@@ -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