Remove unused persona marketplace and discover page files.
This commit is contained in:
+22
-20
@@ -10,11 +10,12 @@ import {requireLogin} from "../middleware/auth.js";
|
||||
import {validateBody} from "../middleware/validate.js";
|
||||
import {validateWorkspaceImport} from "../services/workspaceImportService.js";
|
||||
import {createWorkspaceArchive, parseWorkspaceArchive, MAX_ARCHIVE_BYTES} from "../services/workspaceArchive.js";
|
||||
import {getPersonality, listPersonalities, DEFAULT_PERSONALITY_ID} from "../services/personalityRegistry.js";
|
||||
|
||||
const createChatValidator = (body) => ({
|
||||
value: {
|
||||
title: String(body?.title || "New chat").trim() || "New chat",
|
||||
assistantPersonaId: body?.assistantPersonaId ? Number(body.assistantPersonaId) : null
|
||||
personalityId: body?.personalityId == null ? DEFAULT_PERSONALITY_ID : String(body.personalityId)
|
||||
}
|
||||
});
|
||||
|
||||
@@ -165,34 +166,35 @@ export function createChatsRouter({repositories, chatService, modelService, conf
|
||||
}));
|
||||
|
||||
router.get("/chats", (req, res) => res.json({chats: repositories.listChats(req.session.user)}));
|
||||
router.get("/personalities", (_req, res) => res.json({personalities: listPersonalities(), defaultPersonalityId: DEFAULT_PERSONALITY_ID}));
|
||||
router.get("/personalities/:id", (req, res) => {
|
||||
const personality = listPersonalities().find(item => item.id === req.params.id);
|
||||
return personality ? res.json({personality}) : res.status(404).json({error: "Personality not found"});
|
||||
});
|
||||
router.get("/chats/search", (req, res) => res.json({chats: repositories.searchChats(req.session.user, req.query.q || "")}));
|
||||
|
||||
router.post("/chats", validateBody(createChatValidator), (req, res) => {
|
||||
const user = req.session.user;
|
||||
const {assistantPersonaId, title} = req.validatedBody;
|
||||
|
||||
if (assistantPersonaId) {
|
||||
const persona = repositories.getPersona(assistantPersonaId, user);
|
||||
if (!persona || persona.persona_type !== "assistant") {
|
||||
return res.status(404).json({error: "AI Character not found"});
|
||||
}
|
||||
const existingChat = repositories.getChatByParticipants(user, assistantPersonaId, null);
|
||||
try {
|
||||
const chat = chatService.getOrCreatePersonaChat(user, persona, null);
|
||||
return res.json({chat, existing: Boolean(existingChat)});
|
||||
} catch (error) {
|
||||
if (error.message === "CHAT_LIMIT_REACHED") {
|
||||
return res.status(400).json({error: `Maximum of ${config.chatLimit} active chats reached. Archive or delete an active chat to create a new one.`});
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
const {personalityId, title} = req.validatedBody;
|
||||
if (!getPersonality(personalityId)) return res.status(400).json({error: "Unknown personality"});
|
||||
|
||||
if (repositories.countChats(user) >= config.chatLimit) {
|
||||
return res.status(400).json({error: `Maximum of ${config.chatLimit} active chats reached. Archive or delete an active chat to create a new one.`});
|
||||
}
|
||||
|
||||
return res.json({chat: repositories.createChat(user, title), existing: false});
|
||||
const chat = repositories.createChat(user, title);
|
||||
repositories.updateChatPersonality(chat.id, user, personalityId);
|
||||
return res.json({chat: repositories.getChat(chat.id, user), existing: false});
|
||||
});
|
||||
|
||||
router.put("/chats/:id/personality", (req, res) => {
|
||||
const chatId = Number(req.params.id);
|
||||
const chat = repositories.getChat(chatId, req.session.user);
|
||||
if (!chat) return res.status(404).json({error: "Chat not found"});
|
||||
const personalityId = String(req.body?.personalityId || "");
|
||||
if (!getPersonality(personalityId)) return res.status(400).json({error: "Unknown personality"});
|
||||
repositories.updateChatPersonality(chatId, req.session.user, personalityId);
|
||||
return res.json({chat: repositories.getChat(chatId, req.session.user), personality: listPersonalities().find(item => item.id === personalityId)});
|
||||
});
|
||||
|
||||
router.put("/chats/:id", validateBody((body) => {
|
||||
|
||||
Reference in New Issue
Block a user