first commit

This commit is contained in:
nBiqoz
2025-10-05 16:10:35 +02:00
parent 201fca4e68
commit 13cd637391
70 changed files with 7287 additions and 130 deletions

33
lib/db/mongodb.ts Normal file
View File

@@ -0,0 +1,33 @@
import { MongoClient, Db } from 'mongodb';
if (!process.env.MONGODB_URI) {
throw new Error('Please add your MongoDB URI to .env.local');
}
const uri = process.env.MONGODB_URI;
const options = {};
let client: MongoClient;
let clientPromise: Promise<MongoClient>;
if (process.env.NODE_ENV === 'development') {
const globalWithMongo = global as typeof globalThis & {
_mongoClientPromise?: Promise<MongoClient>;
};
if (!globalWithMongo._mongoClientPromise) {
client = new MongoClient(uri, options);
globalWithMongo._mongoClientPromise = client.connect();
}
clientPromise = globalWithMongo._mongoClientPromise;
} else {
client = new MongoClient(uri, options);
clientPromise = client.connect();
}
export async function getDatabase(): Promise<Db> {
const client = await clientPromise;
return client.db('librechat'); // Nom de votre base de données
}
export default clientPromise;

185
lib/types/index.ts Normal file
View File

@@ -0,0 +1,185 @@
// Types pour les collections MongoDB LibreChat (structure réelle)
export interface LibreChatUser extends Record<string, unknown> {
_id: string;
name: string;
username: string;
email: string;
emailVerified: boolean;
password: string;
avatar: string | null;
provider: string;
role: 'ADMIN' | 'USER';
plugins: unknown[];
twoFactorEnabled: boolean;
termsAccepted: boolean;
personalization: {
memories: boolean;
_id: string;
};
backupCodes: unknown[];
refreshToken: unknown[];
createdAt: Date;
updatedAt: Date;
__v: number;
}
export interface LibreChatConversation extends Record<string, unknown> {
_id: string;
conversationId: string;
user: string; // ObjectId du user
__v: number;
_meiliIndex: boolean;
agent_id: string;
createdAt: Date;
endpoint: string;
endpointType: string;
expiredAt: Date | null;
files: unknown[];
isArchived: boolean;
messages: string[]; // Array d'ObjectIds
model: string;
resendFiles: boolean;
tags: unknown[];
title: string;
updatedAt: Date;
}
export interface LibreChatMessage extends Record<string, unknown> {
_id: string;
messageId: string;
user: string; // ObjectId du user
__v: number;
_meiliIndex: boolean;
conversationId: string;
createdAt: Date;
endpoint: string;
error: boolean;
expiredAt: Date | null;
isCreatedByUser: boolean;
model: string | null;
parentMessageId: string;
sender: string;
text: string;
tokenCount: number;
unfinished: boolean;
updatedAt: Date;
}
export interface LibreChatTransaction extends Record<string, unknown> {
_id: string;
user: string; // ObjectId
conversationId: string;
tokenType: 'prompt' | 'completion';
model: string;
context: string;
rawAmount: number;
tokenValue: number;
rate: number;
createdAt: Date;
updatedAt: Date;
__v: number;
}
export interface LibreChatBalance extends Record<string, unknown> {
_id: string;
user: string; // ObjectId
__v: number;
autoRefillEnabled: boolean;
lastRefill: Date;
refillAmount: number;
refillIntervalUnit: string;
refillIntervalValue: number;
tokenCredits: number;
}
// Types legacy pour compatibilité
export interface User extends Record<string, unknown> {
_id: string;
name: string;
email: string;
role: string;
credits: number;
isActive: boolean;
createdAt: Date;
lastLogin?: Date;
}
export interface Conversation extends Record<string, unknown> {
_id: string;
title: string;
participants: string[];
messageCount: number;
status: 'active' | 'archived' | 'deleted';
createdAt: Date;
updatedAt: Date;
}
export interface Transaction extends Record<string, unknown> {
_id: string;
userId: string;
amount: number;
type: 'credit' | 'debit';
description: string;
createdAt: Date;
}
export interface Message extends Record<string, unknown> {
_id: string;
conversationId: string;
userId: string;
content: string;
role: 'user' | 'assistant' | 'system';
createdAt: Date;
}
export interface Balance extends Record<string, unknown> {
_id: string;
userId: string;
credits: number;
lastUpdated: Date;
}
export interface DashboardMetrics {
totalUsers: number;
activeUsers: number;
totalAdmins: number;
totalCredits: number;
activeConversations: number;
totalMessages: number;
totalTokensConsumed: number;
totalCreditsUsed: number;
recentTransactions: Transaction[];
}
// Types pour les autres collections
export interface AccessRole extends Record<string, unknown> {
_id: string;
name: string;
permissions: string[];
}
export interface Agent extends Record<string, unknown> {
_id: string;
name: string;
description: string;
category: string;
isActive: boolean;
}
export interface File extends Record<string, unknown> {
_id: string;
filename: string;
size: number;
uploadedBy: string;
uploadedAt: Date;
}
// Types génériques pour les collections MongoDB
export interface MongoDocument extends Record<string, unknown> {
_id: string;
createdAt?: Date;
updatedAt?: Date;
}
// Type utilitaire pour les collections
export type CollectionItem = MongoDocument & Record<string, unknown>;

35
lib/utils.ts Normal file
View File

@@ -0,0 +1,35 @@
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
export function formatNumber(num: number): string {
return new Intl.NumberFormat('fr-FR').format(num);
}
export function formatDate(date: Date | string | number): string {
// Convertir en objet Date si ce n'est pas déjà le cas
const dateObj = date instanceof Date ? date : new Date(date);
// Vérifier si la date est valide
if (isNaN(dateObj.getTime())) {
return 'Date invalide';
}
return new Intl.DateTimeFormat('fr-FR', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
}).format(dateObj);
}
export function formatCurrency(amount: number): string {
return new Intl.NumberFormat('fr-FR', {
style: 'currency',
currency: 'EUR'
}).format(amount);
}

27
lib/utils/index.ts Normal file
View File

@@ -0,0 +1,27 @@
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export function formatNumber(num: number): string {
return new Intl.NumberFormat('fr-FR').format(num);
}
export function formatDate(date: Date): string {
return new Intl.DateTimeFormat('fr-FR', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
}).format(date);
}
export function formatCurrency(amount: number): string {
return new Intl.NumberFormat('fr-FR', {
style: 'currency',
currency: 'EUR'
}).format(amount);
}