fix: never auto-rename real case files from chat's first-message title
chatMessage() was auto-generating and overwriting cases.title from the first chat message for ANY case_id, including real UYAP-imported dava dosyaları (kind='case') — not just the chat-only "Yeni Sohbet" threads (kind='chat') this was built for. Asking a real case a single question in Sohbet silently destroyed its court-derived title. Now gated on kind === 'chat'. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
fa01432ffe
commit
79b2bad396
@@ -97,6 +97,12 @@ export const chatMessage = async (req: AuthenticatedRequest, res: Response) => {
|
||||
});
|
||||
}
|
||||
|
||||
// kind='case' olan gerçek dava dosyalarının başlığı UYAP'tan/kullanıcıdan geliyor —
|
||||
// bu asla otomatik yeniden adlandırılmamalı. Otomatik başlık üretimi SADECE
|
||||
// kind='chat' (Sohbet'teki "Yeni Sohbet") kayıtları için geçerli.
|
||||
const { data: caseRow } = await supabase.from('cases').select('kind').eq('id', caseId).maybeSingle();
|
||||
const caseKind = caseRow?.kind || 'case';
|
||||
|
||||
const { data: userMessage, error: userMsgError } = await supabase
|
||||
.from('chat_messages')
|
||||
.insert([{ case_id: caseId, user_id: userId, role: 'user', content }])
|
||||
@@ -170,11 +176,12 @@ export const chatMessage = async (req: AuthenticatedRequest, res: Response) => {
|
||||
.select().single();
|
||||
if (aiMsgError) throw aiMsgError;
|
||||
|
||||
// Bu dosyanın ilk mesajıysa (kullanıcının bu isteklen önce hiç mesajı yoktu),
|
||||
// ilk mesajdan kısa bir başlık üretip dosyayı yeniden adlandır.
|
||||
// Bu dosyanın ilk mesajıysa (kullanıcının bu isteklen önce hiç mesajı yoktu) VE
|
||||
// bu gerçek bir dava dosyası değil de dosyasız bir sohbetse, ilk mesajdan kısa
|
||||
// bir başlık üretip yeniden adlandır.
|
||||
let newTitle: string | null = null;
|
||||
const isFirstMessage = !pastMessages || pastMessages.length <= 1;
|
||||
if (isFirstMessage) {
|
||||
if (isFirstMessage && caseKind === 'chat') {
|
||||
newTitle = await generateCaseTitle(content);
|
||||
if (newTitle) {
|
||||
const { error: titleError } = await supabase
|
||||
|
||||
Reference in New Issue
Block a user