Files
Momento/memento-note/app/actions/chat-actions.ts
Antigravity 88a7d2ad0a
All checks were successful
CI / Lint, Unit Tests & Build (push) Successful in 7m59s
CI / Deploy production (on server) (push) Successful in 24s
fix(audit): nettoyage accès, garde-fous build, unification quotas
Semaine 1 — fuites et accès :
- /archive rendu accessible via sidebar (était invisible)
- Suppression pages orphelines : /chat, /graph, /support, test-title-suggestions
- Fixes i18n : search-modal (clé non interpolée), sidebar tooltips, export PDF
- 15 locales mises à jour

Semaine 2 — garde-fous :
- 8 erreurs TS fixees → ignoreBuildErrors: false (build type-safe)
- reactStrictMode: true (dev-only, zero impact prod)
- reserveUsageOrThrow → wrapper deprecie vers reserveAiUsageOrThrow
- auth-guard.ts : requireAuthOrResponse() + requireAdminOrResponse()

Tests 212/212 | Lint 0 erreur | Build OK | tsc 0 erreur
2026-07-17 18:47:44 +00:00

71 lines
1.9 KiB
TypeScript

'use server'
import { chatService } from '@/lib/ai/services'
import { auth } from '@/auth'
import { prisma } from '@/lib/prisma'
/**
* Create a new empty conversation and return its id.
* Called before streaming so the client knows the conversationId upfront.
*/
export async function createConversation(title: string, notebookId?: string) {
const session = await auth()
if (!session?.user?.id) throw new Error('Unauthorized')
const conversation = await prisma.conversation.create({
data: {
userId: session.user.id,
notebookId: notebookId || null,
title: title.substring(0, 80) + (title.length > 80 ? '...' : ''),
},
})
return { id: conversation.id, title: conversation.title }
}
/**
* @deprecated Use the streaming API route /api/chat instead.
* Kept for backward compatibility with the debug route.
*/
export async function sendChatMessage(
message: string,
conversationId?: string,
notebookId?: string
) {
const session = await auth()
if (!session?.user?.id) throw new Error('Unauthorized')
try {
const result = await chatService.chat(message, conversationId, notebookId)
return { success: true, ...result }
} catch (error: any) {
console.error('[ChatAction] Error:', error)
return { success: false, error: error.message }
}
}
export async function getConversations() {
const session = await auth()
if (!session?.user?.id) return []
return chatService.listConversations(session.user.id)
}
export async function getConversationDetails(id: string) {
const session = await auth()
if (!session?.user?.id) return null
return chatService.getHistory(id)
}
export async function deleteConversation(id: string) {
const session = await auth()
if (!session?.user?.id) throw new Error('Unauthorized')
await prisma.conversation.delete({
where: { id, userId: session.user.id }
})
return { success: true }
}