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

- 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:
Sepehr Ramezani
2026-05-01 16:14:07 +02:00
parent 1345403a31
commit dbd49d6fcb
64 changed files with 4124 additions and 1392 deletions

View File

@@ -3,7 +3,36 @@ import { OllamaProvider } from './providers/ollama';
import { CustomOpenAIProvider } from './providers/custom-openai';
import { AIProvider } from './types';
type ProviderType = 'ollama' | 'openai' | 'custom' | 'deepseek' | 'openrouter';
type ProviderType = 'ollama' | 'openai' | 'custom' | 'deepseek' | 'openrouter' | 'mistral' | 'zai' | 'lmstudio';
// --- Provider defaults ---
const PROVIDER_DEFAULTS: Record<string, { baseUrl: string; model: string; embeddingModel: string }> = {
deepseek: {
baseUrl: 'https://api.deepseek.com/v1',
model: 'deepseek-chat',
embeddingModel: '',
},
openrouter: {
baseUrl: 'https://openrouter.ai/api/v1',
model: 'openai/gpt-4o-mini',
embeddingModel: 'openai/text-embedding-3-small',
},
mistral: {
baseUrl: 'https://api.mistral.ai/v1',
model: 'mistral-small-latest',
embeddingModel: 'mistral-embed',
},
zai: {
baseUrl: 'https://api.zukijourney.com/v1',
model: 'gpt-4o-mini',
embeddingModel: 'text-embedding-3-small',
},
lmstudio: {
baseUrl: 'http://localhost:1234/v1',
model: '',
embeddingModel: '',
},
};
function createOllamaProvider(config: Record<string, string>, modelName: string, embeddingModelName: string, baseUrlOverride?: string): OllamaProvider {
let baseUrl = baseUrlOverride || config?.OLLAMA_BASE_URL || process.env.OLLAMA_BASE_URL
@@ -19,7 +48,7 @@ function createOllamaProvider(config: Record<string, string>, modelName: string,
// Ensure baseUrl doesn't end with /api, we'll add it in OllamaProvider
if (baseUrl.endsWith('/api')) {
baseUrl = baseUrl.slice(0, -4); // Remove /api
baseUrl = baseUrl.slice(0, -4);
}
return new OllamaProvider(baseUrl, modelName, embeddingModelName);
@@ -51,15 +80,39 @@ function createCustomOpenAIProvider(config: Record<string, string>, modelName: s
}
function createDeepSeekProvider(config: Record<string, string>, modelName: string, embeddingModelName: string): CustomOpenAIProvider {
const apiKey = config?.DEEPSEEK_API_KEY || config?.CUSTOM_OPENAI_API_KEY || process.env.DEEPSEEK_API_KEY || process.env.CUSTOM_OPENAI_API_KEY || '';
const apiKey = config?.DEEPSEEK_API_KEY || process.env.DEEPSEEK_API_KEY || '';
if (!apiKey) throw new Error('DEEPSEEK_API_KEY is required when using DeepSeek provider');
return new CustomOpenAIProvider(apiKey, 'https://api.deepseek.com/v1', modelName, embeddingModelName);
const defaults = PROVIDER_DEFAULTS.deepseek;
return new CustomOpenAIProvider(apiKey, defaults.baseUrl, modelName || defaults.model, embeddingModelName || defaults.embeddingModel);
}
function createOpenRouterProvider(config: Record<string, string>, modelName: string, embeddingModelName: string): CustomOpenAIProvider {
const apiKey = config?.OPENROUTER_API_KEY || config?.CUSTOM_OPENAI_API_KEY || process.env.OPENROUTER_API_KEY || process.env.CUSTOM_OPENAI_API_KEY || '';
const apiKey = config?.OPENROUTER_API_KEY || process.env.OPENROUTER_API_KEY || '';
if (!apiKey) throw new Error('OPENROUTER_API_KEY is required when using OpenRouter provider');
return new CustomOpenAIProvider(apiKey, 'https://openrouter.ai/api/v1', modelName, embeddingModelName);
const defaults = PROVIDER_DEFAULTS.openrouter;
return new CustomOpenAIProvider(apiKey, defaults.baseUrl, modelName || defaults.model, embeddingModelName || defaults.embeddingModel);
}
function createMistralProvider(config: Record<string, string>, modelName: string, embeddingModelName: string): CustomOpenAIProvider {
const apiKey = config?.MISTRAL_API_KEY || process.env.MISTRAL_API_KEY || '';
if (!apiKey) throw new Error('MISTRAL_API_KEY is required when using Mistral provider');
const defaults = PROVIDER_DEFAULTS.mistral;
return new CustomOpenAIProvider(apiKey, defaults.baseUrl, modelName || defaults.model, embeddingModelName || defaults.embeddingModel);
}
function createZAIProvider(config: Record<string, string>, modelName: string, embeddingModelName: string): CustomOpenAIProvider {
const apiKey = config?.ZAI_API_KEY || process.env.ZAI_API_KEY || '';
if (!apiKey) throw new Error('ZAI_API_KEY is required when using Z.AI provider');
const defaults = PROVIDER_DEFAULTS.zai;
return new CustomOpenAIProvider(apiKey, defaults.baseUrl, modelName || defaults.model, embeddingModelName || defaults.embeddingModel);
}
function createLMStudioProvider(config: Record<string, string>, modelName: string, embeddingModelName: string): CustomOpenAIProvider {
const baseUrl = config?.LMSTUDIO_BASE_URL || process.env.LMSTUDIO_BASE_URL || PROVIDER_DEFAULTS.lmstudio.baseUrl;
// LM Studio doesn't require an API key, but the CustomOpenAI provider needs one
// Use a dummy key if not provided
const apiKey = config?.LMSTUDIO_API_KEY || process.env.LMSTUDIO_API_KEY || 'lm-studio';
return new CustomOpenAIProvider(apiKey, baseUrl, modelName, embeddingModelName);
}
function getProviderInstance(providerType: ProviderType, config: Record<string, string>, modelName: string, embeddingModelName: string, ollamaBaseUrl?: string): AIProvider {
@@ -74,28 +127,47 @@ function getProviderInstance(providerType: ProviderType, config: Record<string,
return createDeepSeekProvider(config, modelName, embeddingModelName);
case 'openrouter':
return createOpenRouterProvider(config, modelName, embeddingModelName);
case 'mistral':
return createMistralProvider(config, modelName, embeddingModelName);
case 'zai':
return createZAIProvider(config, modelName, embeddingModelName);
case 'lmstudio':
return createLMStudioProvider(config, modelName, embeddingModelName);
default:
return createOllamaProvider(config, modelName, embeddingModelName, ollamaBaseUrl);
}
}
// Resolve the effective provider type and config keys for a given provider
// Returns { providerType, apiKeyConfigKey, baseUrlConfigKey }
function getProviderConfigKeys(providerType: string): { apiKeyConfigKey: string; baseUrlConfigKey: string } {
switch (providerType) {
case 'deepseek': return { apiKeyConfigKey: 'DEEPSEEK_API_KEY', baseUrlConfigKey: '' };
case 'openrouter': return { apiKeyConfigKey: 'OPENROUTER_API_KEY', baseUrlConfigKey: '' };
case 'mistral': return { apiKeyConfigKey: 'MISTRAL_API_KEY', baseUrlConfigKey: '' };
case 'zai': return { apiKeyConfigKey: 'ZAI_API_KEY', baseUrlConfigKey: '' };
case 'lmstudio': return { apiKeyConfigKey: 'LMSTUDIO_API_KEY', baseUrlConfigKey: 'LMSTUDIO_BASE_URL' };
case 'openai': return { apiKeyConfigKey: 'OPENAI_API_KEY', baseUrlConfigKey: '' };
case 'custom': return { apiKeyConfigKey: 'CUSTOM_OPENAI_API_KEY', baseUrlConfigKey: 'CUSTOM_OPENAI_BASE_URL' };
default: return { apiKeyConfigKey: '', baseUrlConfigKey: 'OLLAMA_BASE_URL' };
}
}
export function getTagsProvider(config?: Record<string, string>): AIProvider {
// Check database config first, then environment variables
const providerType = (
config?.AI_PROVIDER_TAGS ||
config?.AI_PROVIDER_EMBEDDING ||
config?.AI_PROVIDER_TAGS ||
config?.AI_PROVIDER_EMBEDDING ||
config?.AI_PROVIDER ||
process.env.AI_PROVIDER_TAGS ||
process.env.AI_PROVIDER_EMBEDDING ||
process.env.AI_PROVIDER
);
// If no provider is configured, throw a clear error
if (!providerType) {
console.error('[getTagsProvider] FATAL: No provider configured. Config received:', config);
throw new Error(
'AI_PROVIDER_TAGS is not configured. Please set it in the admin settings or environment variables. ' +
'Options: ollama, openai, custom'
'Options: ollama, openai, deepseek, openrouter, mistral, zai, lmstudio, custom'
);
}
@@ -108,22 +180,20 @@ export function getTagsProvider(config?: Record<string, string>): AIProvider {
}
export function getEmbeddingsProvider(config?: Record<string, string>): AIProvider {
// Check database config first, then environment variables
const providerType = (
config?.AI_PROVIDER_EMBEDDING ||
config?.AI_PROVIDER_TAGS ||
config?.AI_PROVIDER_EMBEDDING ||
config?.AI_PROVIDER_TAGS ||
config?.AI_PROVIDER ||
process.env.AI_PROVIDER_EMBEDDING ||
process.env.AI_PROVIDER_TAGS ||
process.env.AI_PROVIDER
);
// If no provider is configured, throw a clear error
if (!providerType) {
console.error('[getEmbeddingsProvider] FATAL: No provider configured. Config received:', config);
throw new Error(
'AI_PROVIDER_EMBEDDING is not configured. Please set it in the admin settings or environment variables. ' +
'Options: ollama, openai, custom'
'Options: ollama, openai, deepseek, openrouter, mistral, zai, lmstudio, custom'
);
}
@@ -140,8 +210,6 @@ export function getAIProvider(config?: Record<string, string>): AIProvider {
}
export function getChatProvider(config?: Record<string, string>): AIProvider {
// Check database config first, then environment variables
// Fallback cascade: chat -> tags -> embeddings
const providerType = (
config?.AI_PROVIDER_CHAT ||
config?.AI_PROVIDER_TAGS ||
@@ -153,12 +221,11 @@ export function getChatProvider(config?: Record<string, string>): AIProvider {
process.env.AI_PROVIDER
);
// If no provider is configured, throw a clear error
if (!providerType) {
console.error('[getChatProvider] FATAL: No provider configured. Config received:', config);
throw new Error(
'AI_PROVIDER_CHAT is not configured. Please set it in the admin settings or environment variables. ' +
'Options: ollama, openai, custom'
'Options: ollama, openai, deepseek, openrouter, mistral, zai, lmstudio, custom'
);
}
@@ -173,3 +240,6 @@ export function getChatProvider(config?: Record<string, string>): AIProvider {
return getProviderInstance(provider, config || {}, modelName, embeddingModelName, ollamaBaseUrl);
}
// Export for use by admin settings form and deploy scripts
export { PROVIDER_DEFAULTS, getProviderConfigKeys };

View File

@@ -15,6 +15,8 @@ import { sendEmail } from '@/lib/mail'
import { getAgentEmailTemplate } from '@/lib/agent-email-template'
import { extractAndDownloadImages, extractImageUrlsFromHtml, downloadImage } from '../tools/extract-images'
import { calculateNextRun } from '@/lib/agents/schedule'
import { markdownToHtml } from '@/lib/markdown-to-html'
import { createNotification } from '@/app/actions/notifications'
// Import tools for side-effect registration
import '../tools'
@@ -30,6 +32,32 @@ export interface AgentExecutionResult {
error?: string
}
// --- Note creation helper ---
/** Create an agent note as rich text (TipTap-compatible HTML).
* Converts the markdown content to HTML and sets type='richtext'. */
async function createAgentNote(data: {
title: string
content: string
userId: string
notebookId: string | null
autoGenerated?: boolean
}) {
const htmlContent = markdownToHtml(data.content)
return prisma.note.create({
data: {
title: data.title,
content: htmlContent,
type: 'richtext',
isMarkdown: false,
autoGenerated: data.autoGenerated ?? true,
userId: data.userId,
notebookId: data.notebookId,
},
select: { id: true },
})
}
// --- Language Helper ---
type Lang = 'fr' | 'en'
@@ -324,15 +352,11 @@ async function executeScraperAgent(
const title = await generateTitle(fullContent, agent.name, lang)
const note = await prisma.note.create({
data: {
title,
content: fullContent,
isMarkdown: true,
autoGenerated: true,
userId: agent.userId,
notebookId: agent.targetNotebookId,
}
const note = await createAgentNote({
title,
content: fullContent,
userId: agent.userId,
notebookId: agent.targetNotebookId,
})
const logMsg = lang === 'fr'
@@ -424,15 +448,11 @@ async function executeResearcherAgent(
const title = await generateTitle(fullContent, agent.name, lang)
const note = await prisma.note.create({
data: {
title,
content: fullContent,
isMarkdown: true,
autoGenerated: true,
userId: agent.userId,
notebookId: agent.targetNotebookId,
}
const note = await createAgentNote({
title,
content: fullContent,
userId: agent.userId,
notebookId: agent.targetNotebookId,
})
const logMsg = lang === 'fr'
@@ -526,15 +546,11 @@ async function executeMonitorAgent(
const title = await generateTitle(fullContent, agent.name, lang)
const note = await prisma.note.create({
data: {
title,
content: fullContent,
isMarkdown: true,
autoGenerated: true,
userId: agent.userId,
notebookId: agent.targetNotebookId,
}
const note = await createAgentNote({
title,
content: fullContent,
userId: agent.userId,
notebookId: agent.targetNotebookId,
})
const logMsg = lang === 'fr' ? `Analyse de ${notes.length} notes. Note créée: ${note.id}` : `Analyzed ${notes.length} notes. Note created: ${note.id}`
@@ -597,15 +613,11 @@ async function executeCustomAgent(
const title = await generateTitle(fullContent, agent.name, lang)
const note = await prisma.note.create({
data: {
title,
content: fullContent,
isMarkdown: true,
autoGenerated: true,
userId: agent.userId,
notebookId: agent.targetNotebookId,
}
const note = await createAgentNote({
title,
content: fullContent,
userId: agent.userId,
notebookId: agent.targetNotebookId,
})
const toolLogData = JSON.stringify([{
@@ -966,15 +978,11 @@ async function executeToolUseAgent(
const fullContent = `# ${agent.name}\n\n${text}\n\n---\n\n_Agent execution: ${totalToolCalls} tool calls in ${Math.round(duration / 1000)}s_`
const title = await generateTitle(fullContent, agent.name, lang)
const note = await prisma.note.create({
data: {
title,
content: fullContent,
isMarkdown: true,
autoGenerated: true,
userId: agent.userId,
notebookId: agent.targetNotebookId || null,
}
const note = await createAgentNote({
title,
content: fullContent,
userId: agent.userId,
notebookId: agent.targetNotebookId || null,
})
noteId = note.id
}
@@ -1119,6 +1127,20 @@ export async function executeAgent(agentId: string, userId: string, promptOverri
}
}
// Create in-app notification for agent result
if (result.success) {
await createNotification({
userId,
type: 'agent_success',
title: agent.name,
message: result.noteId
? (lang === 'fr' ? `L'agent a terminé avec succès — note créée.` : `Agent completed successfully — note created.`)
: (lang === 'fr' ? `L'agent a terminé avec succès.` : `Agent completed successfully.`),
actionUrl: result.noteId ? `/?openNote=${result.noteId}` : '/agents',
relatedId: result.noteId || agentId,
})
}
return result
} catch (error) {
const message = error instanceof Error ? error.message : 'Unknown error'
@@ -1129,6 +1151,16 @@ export async function executeAgent(agentId: string, userId: string, promptOverri
data: { status: 'failure', log: message }
})
// Notify user of agent failure
await createNotification({
userId,
type: 'agent_failure',
title: agent?.name || 'Agent',
message: message.length > 200 ? message.substring(0, 200) + '...' : message,
actionUrl: '/agents',
relatedId: agentId,
})
return { success: false, actionId: action.id, error: message }
}
}

View File

@@ -19,23 +19,43 @@ export interface ImageDescriptionResult {
const UPLOAD_DIR = path.join(process.cwd(), 'data', 'uploads')
async function resolveImageAsBase64(imageUrl: string): Promise<string> {
async function resolveImageAsBase64(imageUrl: string): Promise<string | null> {
const localMatch = imageUrl.match(/\/uploads\/(.+)/)
if (localMatch) {
const filePath = path.join(UPLOAD_DIR, localMatch[1])
const buffer = await readFile(filePath)
const ext = path.extname(imageUrl).toLowerCase()
const mime = ext === '.png' ? 'image/png' : ext === '.gif' ? 'image/gif' : ext === '.webp' ? 'image/webp' : 'image/jpeg'
return `data:${mime};base64,${buffer.toString('base64')}`
// Try reading from filesystem first
try {
const filePath = path.join(UPLOAD_DIR, localMatch[1])
const buffer = await readFile(filePath)
const ext = path.extname(imageUrl).toLowerCase()
const mime = ext === '.png' ? 'image/png' : ext === '.gif' ? 'image/gif' : ext === '.webp' ? 'image/webp' : 'image/jpeg'
return `data:${mime};base64,${buffer.toString('base64')}`
} catch {
// File not on disk — fallback to internal HTTP API (same path the browser uses)
try {
const baseUrl = process.env.NEXTAUTH_URL || process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'
const res = await fetch(`${baseUrl}${imageUrl}`)
if (!res.ok) return null
const contentType = res.headers.get('content-type') || 'image/jpeg'
const arrayBuffer = await res.arrayBuffer()
const base64 = Buffer.from(arrayBuffer).toString('base64')
return `data:${contentType};base64,${base64}`
} catch {
return null
}
}
}
// Remote URL — fetch and convert
const res = await fetch(imageUrl)
if (!res.ok) throw new Error(`Failed to fetch image: ${imageUrl}`)
const contentType = res.headers.get('content-type') || 'image/jpeg'
const arrayBuffer = await res.arrayBuffer()
const base64 = Buffer.from(arrayBuffer).toString('base64')
return `data:${contentType};base64,${base64}`
try {
const res = await fetch(imageUrl)
if (!res.ok) return null
const contentType = res.headers.get('content-type') || 'image/jpeg'
const arrayBuffer = await res.arrayBuffer()
const base64 = Buffer.from(arrayBuffer).toString('base64')
return `data:${contentType};base64,${base64}`
} catch {
return null
}
}
export async function describeImages(
@@ -55,8 +75,9 @@ export async function describeImages(
}
const langName = langMap[language] || 'English'
// Resolve all images as base64 data URLs (same approach as the chat route)
const imageDataUrls = await Promise.all(imageUrls.map(url => resolveImageAsBase64(url)))
// Resolve all images as base64 data URLs — skip any that can't be found
const resolved = await Promise.all(imageUrls.map(url => resolveImageAsBase64(url)))
const imageDataUrls = resolved.filter((d): d is string => d !== null)
if (isTitleMode) {
const prompt = imageUrls.length === 1

View File

@@ -7,6 +7,7 @@ import { tool } from 'ai'
import { z } from 'zod'
import { toolRegistry } from './registry'
import { prisma } from '@/lib/prisma'
import { markdownToHtml } from '@/lib/markdown-to-html'
// --- note_read ---
toolRegistry.register({
@@ -50,11 +51,13 @@ toolRegistry.register({
}),
execute: async ({ title, content, notebookId, images }) => {
try {
const htmlContent = markdownToHtml(content)
const note = await prisma.note.create({
data: {
title,
content,
isMarkdown: true,
content: htmlContent,
type: 'richtext',
isMarkdown: false,
autoGenerated: true,
userId: ctx.userId,
notebookId: notebookId || null,