diff --git a/src/app/api/chat/route.ts b/src/app/api/chat/route.ts index b1af3279..7d381f15 100644 --- a/src/app/api/chat/route.ts +++ b/src/app/api/chat/route.ts @@ -142,7 +142,9 @@ CRITICAL INSTRUCTIONS FOR WORKSPACE CURATION: - Use \`updateNote\` tool for notes - Use \`updateFlashcards\` tool for flashcard sets - Use \`updateQuiz\` tool for quizzes -2. **Be thorough but focused** - Provide a solid foundation for understanding the topic without being overwhelming. +2. **Be thorough and exhaustive** - Provide deep, academic, and comprehensive coverage. Notes must be detailed and extensive. Avoid summaries. + - **Structure**: Use H2/H3 headers, bullet points, and **bold** text for readability. + - **Math**: Use block math \`$$...$$\` for equations. 3. **Do NOT ask the user questions** - This is an automated initialization, proceed directly with updating the workspace. QUALITY GUIDELINES FOR CONTENT: @@ -185,7 +187,18 @@ When creating/updating notes with research: Rules: - Use chunk.web.uri exactly as provided (even redirect URLs) - Never make up or hallucinate URLs -- Include article dates in responses when available`); +- Include article dates in responses when available + +CONTENT GENERATION RULE: +When creating or updating notes, your goal is to be **exhaustive** and **well-structured**. +- **Length**: Write long, detailed paragraphs. Never trade depth for brevity. +- **Headers**: Use H2 (\`##\`) and H3 (\`###\`) to organize sections. +- **Formatting**: **Bold** key terms and defined concepts. +- **Lists**: Use bullet points for steps, features, or lists to improve readability. +- **Math**: Use block math (\`$$...$$\`) for important equations so they render centered. **DO NOT use quadruple dollar signs (\`$$$$\`).** +- **Callouts**: Use blockquotes (\`>\`) for key takeaways or definitions. +- Include code examples and historical context where relevant. +`); // Add file detection hint if file URLs are present diff --git a/src/components/assistant-ui/markdown-text.tsx b/src/components/assistant-ui/markdown-text.tsx index a2392037..aa27371c 100644 --- a/src/components/assistant-ui/markdown-text.tsx +++ b/src/components/assistant-ui/markdown-text.tsx @@ -159,6 +159,8 @@ export const MarkdownText = memo(MarkdownTextImpl); function normalizeCustomMathTags(input: string): string { return (input + // Fix quadruple dollar signs (often generated by AI) to double dollar signs + .replace(/\${4}/g, '$$') // Convert \( ... \) to $$...$$ (inline math) - streamdown uses $$ for both, inline has no newlines .replace(/\\{1,2}\(([\s\S]*?)\\{1,2}\)/g, (_, content) => `$$${content.trim()}$$`) // Convert \[ ... \] to $$...$$ (block math) - streamdown needs newlines for block triggers diff --git a/src/components/assistant-ui/standalone-markdown.tsx b/src/components/assistant-ui/standalone-markdown.tsx index d4619035..3b725625 100644 --- a/src/components/assistant-ui/standalone-markdown.tsx +++ b/src/components/assistant-ui/standalone-markdown.tsx @@ -59,6 +59,8 @@ const CodeHeader: FC<{ language?: string; code: string }> = ({ language, code }) function normalizeCustomMathTags(input: string): string { return ( input + // Fix quadruple dollar signs (often generated by AI) to double dollar signs + .replace(/\${4}/g, '$$') // Convert [/math]...[/math] to $$...$$ (legacy block math format) .replace(/\[\/math\]([\s\S]*?)\[\/math\]/g, (_, content) => `$$${content.trim()}$$`) // Convert [/inline]...[/inline] to $...$ (legacy inline format - ReactMarkdown uses $ for inline) @@ -67,8 +69,8 @@ function normalizeCustomMathTags(input: string): string { .replace(/\\{1,2}\(([\s\S]*?)\\{1,2}\)/g, (_, content) => `$${content.trim()}$`) // Convert \[ ... \] to $$...$$ (LaTeX block math) .replace(/\\{1,2}\[([\s\S]*?)\\{1,2}\]/g, (_, content) => `$$${content.trim()}$$`) - // Note: We DON'T convert $...$ to $$ here because ReactMarkdown with remark-math expects - // single dollar signs for inline math and double dollar signs for block math + // Note: We DON'T convert $...$ to $$ here because ReactMarkdown with remark-math expects + // single dollar signs for inline math and double dollar signs for block math ); } diff --git a/src/lib/ai/tools/workspace-tools.ts b/src/lib/ai/tools/workspace-tools.ts index 13a979ec..50881d04 100644 --- a/src/lib/ai/tools/workspace-tools.ts +++ b/src/lib/ai/tools/workspace-tools.ts @@ -22,7 +22,7 @@ export function createNoteTool(ctx: WorkspaceToolContext) { inputSchema: zodSchema( z.object({ title: z.string().describe("The title of the note card"), - content: z.string().describe("The markdown body content. DO NOT repeat title in content. Start with subheadings/text. No Mermaid. Use $$...$$ for ALL math (both inline and block). Single $ is for currency only."), + content: z.string().describe("The markdown body content. Must be detailed, comprehensive, and long-form. **Structure with H2/H3 headers, bullet points, and bold key terms**. Use block math $$...$$ for equations (do not use $$$$). Minimum 3-4 paragraphs."), sources: z.array( z.object({ title: z.string().describe("Title of the source page"), @@ -76,7 +76,7 @@ export function createUpdateNoteTool(ctx: WorkspaceToolContext) { inputSchema: zodSchema( z.object({ noteName: z.string().describe("The name of the note to update (will be matched using fuzzy search)"), - content: z.string().describe("The full note body ONLY (do not include the title as a header). Use $$...$$ for ALL math."), + content: z.string().describe("The full note body ONLY (do not include the title as a header). Must be detailed, comprehensive, and long-form. **Structure with H2/H3 headers, bullet points, and bold key terms**. Use block math $$...$$ for equations (do not use $$$$)."), title: z.string().optional().describe("New title for the note. If not provided, the existing title will be preserved."), sources: z.array( z.object({