Build fixes: offline-safe fonts, Next.js API route type updates, TS strict errors resolved, MUI import cleanup, chat markdown wrapper, Azure OpenAI typing, caching key + chapter API id types, and misc error-logging typings.

This commit is contained in:
andupetcu
2025-09-22 17:07:31 +03:00
parent c82b3007fd
commit 98c17d69bc
26 changed files with 106 additions and 105 deletions

View File

@@ -1,4 +1,5 @@
import { AzureOpenAI } from 'openai'
import type { ChatCompletionMessageParam } from 'openai/resources/chat/completions'
const client = new AzureOpenAI({
apiKey: process.env.AZURE_OPENAI_KEY!,
@@ -7,7 +8,7 @@ const client = new AzureOpenAI({
})
export async function generateChatResponse(
messages: Array<{ role: string; content: string }>,
messages: Array<{ role: 'user' | 'assistant'; content: string }>,
verseContext?: string
) {
try {
@@ -17,7 +18,7 @@ export async function generateChatResponse(
model: process.env.AZURE_OPENAI_DEPLOYMENT || 'gpt-4',
messages: [
{ role: 'system', content: systemPrompt },
...messages
...messages as unknown as ChatCompletionMessageParam[]
],
temperature: 0.7,
max_tokens: 1000
@@ -56,4 +57,4 @@ export async function generateEmbedding(text: string): Promise<number[]> {
// Return empty array if embedding service is not available
return []
}
}
}

View File

@@ -28,7 +28,7 @@ export async function verifyToken(token: string) {
console.log('Server: Token verification successful, userId:', payload.userId)
return payload
} catch (error) {
console.log('Server: Token verification failed:', error.message)
console.log('Server: Token verification failed:', (error as any)?.message || error)
throw new Error('Invalid token')
}
}
@@ -54,7 +54,7 @@ export async function getUserFromToken(token: string) {
}
return user
} catch (error) {
console.log('Server: getUserFromToken error:', error.message)
console.log('Server: getUserFromToken error:', (error as any)?.message || error)
return null
}
}
@@ -69,4 +69,4 @@ export function isTokenExpired(token: string): boolean {
} catch (error) {
return true
}
}
}

4
lib/cache/index.ts vendored
View File

@@ -57,7 +57,7 @@ export class CacheManager {
}
// Helper methods for specific cache patterns
static getChapterKey(bookId: number, chapterNum: number): string {
static getChapterKey(bookId: string, chapterNum: number): string {
return `chapter:${bookId}:${chapterNum}`
}
@@ -68,4 +68,4 @@ export class CacheManager {
static getUserBookmarksKey(userId: string): string {
return `bookmarks:${userId}`
}
}
}

View File

@@ -1,15 +1,25 @@
import { Merriweather, Lato } from 'next/font/google'
// Offline-safe font shim for builds without network access.
// Provides the minimal shape used by the app: `.style.fontFamily` and `.variable`.
export const merriweather = Merriweather({
subsets: ['latin'],
weight: ['300', '400', '700', '900'],
variable: '--font-merriweather',
display: 'swap',
})
type FontShim = {
style: { fontFamily: string }
variable: string
}
export const lato = Lato({
subsets: ['latin'],
weight: ['300', '400', '700', '900'],
variable: '--font-lato',
display: 'swap',
})
export const merriweather: FontShim = {
// Prefer Merriweather if available on the system, otherwise common serif fallbacks
style: {
fontFamily: 'Merriweather, Georgia, "Times New Roman", Times, serif',
},
// Not using next/font CSS variable when offline
variable: '',
}
export const lato: FontShim = {
// Prefer Lato if available on the system, otherwise robust system sans fallbacks
style: {
fontFamily:
'Lato, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',
},
variable: '',
}