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:
@@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user