feat: 8 AI providers, rich text editor, agent notifications, UI contrast & font settings
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 1m25s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 1m25s
- Add DeepSeek, OpenRouter, Mistral, Z.AI, LM Studio as AI providers with editable model names via Combobox in admin settings - Fix OpenRouter broken by normalizeProvider bug in config.ts - Convert agent-created notes from Markdown to HTML (TipTap rich text) - Add Notification model + in-app notifications for agent results - Agent notification click opens the created note directly - Add note count display on notebook and inbox headers - Fix checklist toggle in card view (persist state via localCheckItems) - Add checklist creation option in tabs/list view (dropdown on + button) - Fix image description ENOENT error with HTTP fallback - Improve UI contrast across all themes (input, border, checkbox visibility) - Add font family setting (Inter vs System Default) in Appearance settings - Fix CSS font-sans variable conflict (removed dead Geist references) - Update README with new features and 8 providers Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
/**
|
||||
* Detect user's preferred language from their existing notes
|
||||
* Uses a single DB-level GROUP BY query — no note content is loaded
|
||||
* Detect user's preferred language.
|
||||
* Priority:
|
||||
* 1. Most common language among user's notes (DB GROUP BY)
|
||||
* 2. Browser language hint (passed from server component via Accept-Language)
|
||||
* 3. Default: 'en'
|
||||
*/
|
||||
|
||||
import { auth } from '@/auth'
|
||||
@@ -10,10 +13,37 @@ import { SupportedLanguage } from './load-translations'
|
||||
|
||||
const SUPPORTED_LANGUAGES = new Set(['en', 'fr', 'es', 'de', 'fa', 'it', 'pt', 'ru', 'zh', 'ja', 'ko', 'ar', 'hi', 'nl', 'pl'])
|
||||
|
||||
/**
|
||||
* Parse an Accept-Language header string and find the best matching supported language
|
||||
*/
|
||||
export function parseAcceptLanguage(acceptLanguage: string | null): SupportedLanguage | null {
|
||||
if (!acceptLanguage) return null
|
||||
|
||||
// Parse Accept-Language: "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7"
|
||||
const languages = acceptLanguage
|
||||
.split(',')
|
||||
.map(lang => {
|
||||
const [code, q] = lang.trim().split(';q=')
|
||||
return { code: code.trim().toLowerCase(), quality: q ? parseFloat(q) : 1.0 }
|
||||
})
|
||||
.sort((a, b) => b.quality - a.quality)
|
||||
|
||||
for (const { code } of languages) {
|
||||
if (SUPPORTED_LANGUAGES.has(code)) {
|
||||
return code as SupportedLanguage
|
||||
}
|
||||
const base = code.split('-')[0]
|
||||
if (SUPPORTED_LANGUAGES.has(base)) {
|
||||
return base as SupportedLanguage
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
const getCachedUserLanguage = unstable_cache(
|
||||
async (userId: string): Promise<SupportedLanguage> => {
|
||||
async (userId: string): Promise<SupportedLanguage | null> => {
|
||||
try {
|
||||
// Single aggregated query — no notes are fetched, only language counts
|
||||
const result = await prisma.note.groupBy({
|
||||
by: ['language'],
|
||||
where: {
|
||||
@@ -33,22 +63,39 @@ const getCachedUserLanguage = unstable_cache(
|
||||
}
|
||||
}
|
||||
|
||||
return 'en'
|
||||
return null
|
||||
} catch (error) {
|
||||
console.error('Error detecting user language:', error)
|
||||
return 'en'
|
||||
console.error('Error detecting user language from notes:', error)
|
||||
return null
|
||||
}
|
||||
},
|
||||
['user-language'],
|
||||
{ tags: ['user-language'] }
|
||||
)
|
||||
|
||||
export async function detectUserLanguage(): Promise<SupportedLanguage> {
|
||||
/**
|
||||
* Detect user language.
|
||||
* @param browserLanguageHint - Optional browser language parsed from Accept-Language header.
|
||||
* Should be passed from server components that have access to headers().
|
||||
*/
|
||||
export async function detectUserLanguage(browserLanguageHint?: SupportedLanguage | null): Promise<SupportedLanguage> {
|
||||
const session = await auth()
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return 'en'
|
||||
return browserLanguageHint || 'en'
|
||||
}
|
||||
|
||||
return getCachedUserLanguage(session.user.id)
|
||||
// 1. Try to detect from user's notes
|
||||
const noteLanguage = await getCachedUserLanguage(session.user.id)
|
||||
if (noteLanguage) {
|
||||
return noteLanguage
|
||||
}
|
||||
|
||||
// 2. Fall back to browser language hint
|
||||
if (browserLanguageHint) {
|
||||
return browserLanguageHint
|
||||
}
|
||||
|
||||
// 3. Default
|
||||
return 'en'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user