- Add GUIDE.md: complete user documentation covering installation, Docker deployment, AI providers, MCP server, N8N integration, email config, admin panel, env var reference, troubleshooting - Add mcp-server/.env.example with all MCP-specific variables - Update .env.docker.example with all 42 environment variables - Fix docker-compose.yml: parameterize PostgreSQL credentials, add missing env vars (CUSTOM_OPENAI, AI_PROVIDER_CHAT, ALLOW_REGISTRATION, RESEND_API_KEY) - Track memento-note/.env.example
75 lines
1.8 KiB
TypeScript
75 lines
1.8 KiB
TypeScript
import { useState, useEffect } from 'react'
|
|
import { useDebounce } from './use-debounce'
|
|
|
|
export interface TitleSuggestion {
|
|
title: string
|
|
confidence: number
|
|
reasoning?: string
|
|
}
|
|
|
|
interface UseTitleSuggestionsProps {
|
|
content: string
|
|
enabled?: boolean
|
|
}
|
|
|
|
export function useTitleSuggestions({ content, enabled = true }: UseTitleSuggestionsProps) {
|
|
const [suggestions, setSuggestions] = useState<TitleSuggestion[]>([])
|
|
const [isAnalyzing, setIsAnalyzing] = useState(false)
|
|
const [error, setError] = useState<string | null>(null)
|
|
|
|
// Debounce content by 2s to avoid excessive API calls
|
|
const debouncedContent = useDebounce(content, 2000)
|
|
|
|
useEffect(() => {
|
|
if (!enabled || !debouncedContent) {
|
|
setSuggestions([])
|
|
return
|
|
}
|
|
|
|
const wordCount = debouncedContent.split(/\s+/).length
|
|
|
|
// Need at least 10 words
|
|
if (wordCount < 10) {
|
|
setSuggestions([])
|
|
return
|
|
}
|
|
|
|
|
|
const generateTitles = async () => {
|
|
setIsAnalyzing(true)
|
|
setError(null)
|
|
|
|
try {
|
|
const response = await fetch('/api/ai/title-suggestions', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ content: debouncedContent }),
|
|
})
|
|
|
|
|
|
if (!response.ok) {
|
|
const errorData = await response.json()
|
|
throw new Error(errorData.error || 'Error generating title suggestions')
|
|
}
|
|
|
|
const data = await response.json()
|
|
setSuggestions(data.suggestions || [])
|
|
} catch (err) {
|
|
console.error('❌ Title suggestions error:', err)
|
|
setError('Failed to generate title suggestions')
|
|
} finally {
|
|
setIsAnalyzing(false)
|
|
}
|
|
}
|
|
|
|
generateTitles()
|
|
}, [debouncedContent, enabled])
|
|
|
|
return {
|
|
suggestions,
|
|
isAnalyzing,
|
|
error,
|
|
clearSuggestions: () => setSuggestions([])
|
|
}
|
|
}
|