Prompt Kit & Markdown Rendering
Relevant source files
The following files were used as context for generating this wiki page:
The Prompt Kit and Markdown Rendering system provides the foundational infrastructure for generating system instructions and displaying AI-generated content. It encompasses the logic for constructing complex system prompts based on user personas and environmental context, as well as a robust React-based rendering engine that handles LaTeX, code blocks, and streaming animations.
This module ensures that AI responses are not only contextually accurate through strict system_prompt definitions but also visually structured and interactive for the end-user.
Prompt Configuration & Personalization
The system utilizes a structured approach to building prompts, incorporating user profiles, timezones, and functional modes (e.g., email or task mode). Central to this is the PERSONAS configuration, which defines specific behavioral traits for the AI assistant.
Persona Architecture
Personas are defined with unique identifiers, labels, and specific instructional prompts that dictate the AI's tone and expertise level.
| Persona ID | Label | Primary Behavioral Instruction |
|---|---|---|
companion | Companion | Warm, authentic, conversational friend using "hmm" or "you know?". |
researcher | Researcher | Nuanced, intellectual curiosity, acknowledging limitations and evidence. |
teacher | Teacher | Encouraging educator, uses relatable examples, asks guiding questions. |
software-engineer | Software Engineer | Pragmatic senior developer, values maintainability and considers trade-offs. |
creative-writer | Creative Writer | Distinct voice, varied structures, focus on narrative resonance. |
Sources: src/lib/prompt_config.ts:24-81
Dynamic Prompt Construction
The buildSystemPrompt function assembles the final instruction set by combining several modular components:
- Base Identity: General persona or task-specific identity.
- Context: Current date and time formatted to the user's specific timezone.
- Formatting Rules: Strict guidelines for LaTeX ($$ content $$) and code blocks.
- Capability Instructions: Specific blocks for web search and tool calling.
- User Traits: Injected personal details such as occupation and preferred name.
Markdown Rendering Engine
The rendering system transforms raw markdown strings into interactive React components using streamdown and react-markdown. It supports specialized plugins for mathematical notation, code syntax highlighting, and CJK text.
Component Integration
The Markdown component leverages a specific set of plugins to enhance standard output:
- Math: Powered by
katexand@streamdown/math. - Code: Syntax highlighting with
vitesse-lightandvitesse-darkthemes. - Mermaid: Rendering of diagrams within the chat.
- Animations: Word-by-word "blurIn" animation during streaming.
Sources: src/components/prompt-kit/markdown.tsx:1-26
Custom Renderers
The system overrides default HTML element rendering to provide rich UI elements. For example, links (<a>) are intercepted to check for HTTP protocols; if found, they are rendered as a Source component containing favicons and metadata triggers.
Input & Formatting Standards
The project enforces strict formatting rules through the system prompt to ensure consistency across different AI models and rendering environments.
Technical Constraints
| Category | Requirement | Source Citation |
|---|---|---|
| LaTeX | Inline and display math MUST use double dollar signs ($$). | src/lib/prompt_config.ts:175-180 |
| Code Blocks | Must use triple backticks with language identifiers (e.g., ```ts). | src/lib/prompt_config.ts:187-190 |
| Shell/CLI | Must be copy-pasteable without leading "$ " prompts. | src/lib/prompt_config.ts:192-193 |
| Math Special Chars | Characters like &, %, $, # must be escaped with \. | src/lib/prompt_config.ts:181-184 |
UI Configuration Interface
Users can customize the appearance of these rendered elements through the Customization settings. This includes selecting font categories (sans, mono) and previewing how code blocks will appear in the chat interface.
Sources: src/routes/settings/customization.tsx:280-315
Summary
The Prompt Kit & Markdown Rendering module bridges the gap between raw AI instructions and user-facing presentation. By combining a flexible, multi-persona prompt builder in src/lib/prompt_config.ts with a specialized, plugin-rich markdown renderer in src/components/prompt-kit/markdown.tsx, the system maintains high technical standards for mathematical and code content while allowing for a highly personalized user experience.