fix: agent notes default to markdown, add convert-to-rich-text option
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 45s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 45s
- Agent-created notes are now type 'markdown' by default (raw markdown content) - Switching note type from markdown → richtext auto-converts content to HTML via /api/ai/convert-markdown endpoint using the existing markdownToHtml utility - Users can freely switch between markdown and richtext in the note type selector Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
22
memento-note/app/api/ai/convert-markdown/route.ts
Normal file
22
memento-note/app/api/ai/convert-markdown/route.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
|
import { auth } from '@/auth'
|
||||||
|
import { markdownToHtml } from '@/lib/markdown-to-html'
|
||||||
|
|
||||||
|
export async function POST(request: NextRequest) {
|
||||||
|
try {
|
||||||
|
const session = await auth()
|
||||||
|
if (!session?.user?.id) {
|
||||||
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const { content } = await request.json()
|
||||||
|
if (!content || typeof content !== 'string') {
|
||||||
|
return NextResponse.json({ error: 'Content is required' }, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const html = markdownToHtml(content)
|
||||||
|
return NextResponse.json({ html })
|
||||||
|
} catch (error: any) {
|
||||||
|
return NextResponse.json({ error: error.message || 'Conversion failed' }, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -495,10 +495,36 @@ export function NoteInlineEditor({
|
|||||||
|
|
||||||
<NoteTypeSelector
|
<NoteTypeSelector
|
||||||
value={noteType}
|
value={noteType}
|
||||||
onChange={(newType) => {
|
onChange={async (newType) => {
|
||||||
|
const oldType = noteType
|
||||||
setNoteType(newType)
|
setNoteType(newType)
|
||||||
if (newType === 'markdown') setShowMarkdownPreview(true)
|
if (newType === 'markdown') setShowMarkdownPreview(true)
|
||||||
else setShowMarkdownPreview(false)
|
else setShowMarkdownPreview(false)
|
||||||
|
|
||||||
|
// When switching from markdown to richtext, convert content to HTML
|
||||||
|
if (oldType === 'markdown' && newType === 'richtext') {
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/ai/convert-markdown', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ content }),
|
||||||
|
})
|
||||||
|
if (res.ok) {
|
||||||
|
const { html } = await res.json()
|
||||||
|
setContent(html)
|
||||||
|
saveInline(note.id, {
|
||||||
|
type: 'richtext',
|
||||||
|
isMarkdown: false,
|
||||||
|
content: html,
|
||||||
|
}).catch(() => {})
|
||||||
|
onChange?.(note.id, { type: 'richtext', isMarkdown: false, content: html })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Fall through to save without conversion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Persist both type and isMarkdown immediately
|
// Persist both type and isMarkdown immediately
|
||||||
saveInline(note.id, {
|
saveInline(note.id, {
|
||||||
type: newType,
|
type: newType,
|
||||||
|
|||||||
@@ -43,13 +43,12 @@ async function createAgentNote(data: {
|
|||||||
notebookId: string | null
|
notebookId: string | null
|
||||||
autoGenerated?: boolean
|
autoGenerated?: boolean
|
||||||
}) {
|
}) {
|
||||||
const htmlContent = markdownToHtml(data.content)
|
|
||||||
return prisma.note.create({
|
return prisma.note.create({
|
||||||
data: {
|
data: {
|
||||||
title: data.title,
|
title: data.title,
|
||||||
content: htmlContent,
|
content: data.content,
|
||||||
type: 'richtext',
|
type: 'markdown',
|
||||||
isMarkdown: false,
|
isMarkdown: true,
|
||||||
autoGenerated: data.autoGenerated ?? true,
|
autoGenerated: data.autoGenerated ?? true,
|
||||||
userId: data.userId,
|
userId: data.userId,
|
||||||
notebookId: data.notebookId,
|
notebookId: data.notebookId,
|
||||||
|
|||||||
@@ -51,13 +51,12 @@ toolRegistry.register({
|
|||||||
}),
|
}),
|
||||||
execute: async ({ title, content, notebookId, images }) => {
|
execute: async ({ title, content, notebookId, images }) => {
|
||||||
try {
|
try {
|
||||||
const htmlContent = markdownToHtml(content)
|
|
||||||
const note = await prisma.note.create({
|
const note = await prisma.note.create({
|
||||||
data: {
|
data: {
|
||||||
title,
|
title,
|
||||||
content: htmlContent,
|
content,
|
||||||
type: 'richtext',
|
type: 'markdown',
|
||||||
isMarkdown: false,
|
isMarkdown: true,
|
||||||
autoGenerated: true,
|
autoGenerated: true,
|
||||||
userId: ctx.userId,
|
userId: ctx.userId,
|
||||||
notebookId: notebookId || null,
|
notebookId: notebookId || null,
|
||||||
|
|||||||
Reference in New Issue
Block a user