export const ANALYSIS_PROMPTS = {
FULL_ANALYSIS: `You are analyzing documentation content to help users understand and navigate it effectively.
Please analyze the following content and provide a structured response in JSON format with these fields:
{
"summary": "A concise 2-3 sentence summary of the main content",
"keyPoints": ["Array of 3-5 key points or takeaways"],
"contentType": "One of: tutorial, reference, api_docs, guide, example, overview, troubleshooting, other",
"relevantLinks": [
{
"url": "link_url",
"title": "link_title",
"relevance": 0.9,
"reason": "Why this link is relevant",
"category": "One of: related_topic, prerequisite, next_step, reference, example, external"
}
],
"codeExamples": [
{
"language": "programming_language",
"code": "actual_code_content",
"description": "Brief description of what this code does",
"category": "One of: api_call, configuration, implementation, usage_example, snippet, complete_example, other"
}
],
"confidence": 0.85
}
Focus on:
- Extract the core concepts and purpose
- Identify the most valuable links for users to explore next
- Classify content type accurately
- Rate link relevance from 0.0 to 1.0
- Extract ALL code examples found in the content (code blocks, inline code, configuration examples)
- Categorize code examples appropriately (API calls, configuration, usage examples, etc.)
- Preserve exact code formatting and syntax
- Only include confidence score from 0.0 to 1.0
For code examples:
- Include code from <code>, <pre>, triple-backtick language blocks, and other code formatting
- Detect programming language from context or syntax highlighting
- Provide clear descriptions of what each code example demonstrates
- Categorize as: api_call, configuration, implementation, usage_example, snippet, complete_example, or other
Respond only with valid JSON, no additional text.`,
SUMMARY_ONLY: `Please provide a concise 2-3 sentence summary of this documentation content.
Focus on:
- The main purpose or topic covered
- Key concepts or features described
- Who this content is intended for
Respond with just the summary text, no additional formatting.`,
LINKS_ANALYSIS: `Analyze the provided content and identify the most relevant links for users to explore.
Content context: This is from a documentation website about [topic will be provided].
Please return a JSON array of the most relevant links (maximum 10) in this format:
[
{
"url": "link_url",
"title": "link_title_or_text",
"relevance": 0.9,
"reason": "Brief explanation of why this link is valuable",
"category": "One of: related_topic, prerequisite, next_step, reference, example, external"
}
]
Prioritize links that:
- Are most relevant to the main content topic
- Provide logical next steps for learning
- Offer important reference material
- Show practical examples
Only include links with relevance score 0.6 or higher.
Respond only with valid JSON array, no additional text.`,
CONTENT_CLASSIFICATION: `Classify this documentation content into one of these categories:
- tutorial: Step-by-step learning content
- reference: Technical specifications, API docs, parameter lists
- api_docs: Specific API endpoint documentation
- guide: How-to guides for specific tasks
- example: Code examples or sample implementations
- overview: High-level introductions or summaries
- troubleshooting: Problem-solving and debugging content
- other: Content that doesn't fit other categories
Consider:
- The content structure and format
- The intended use case
- The level of detail provided
- Whether it's instructional or reference material
Respond with just the category name, nothing else.`,
CODE_EXAMPLES_ONLY: `Extract and analyze all code examples from this documentation content.
Please return a JSON array of code examples in this format:
[
{
"language": "programming_language_name",
"code": "exact_code_content_with_proper_formatting",
"description": "Clear description of what this code does or demonstrates",
"category": "One of: api_call, configuration, implementation, usage_example, snippet, complete_example, other"
}
]
Instructions:
- Find ALL code examples including: code blocks, inline code snippets, configuration examples, command-line examples
- Preserve exact formatting, indentation, and syntax
- Detect programming language from syntax highlighting, file extensions, or context clues
- For unknown languages, use descriptive names like "bash", "json", "yaml", "plaintext"
- Provide meaningful descriptions that explain the purpose or functionality
- Categorize appropriately:
* api_call: API requests, SDK calls, HTTP requests
* configuration: Config files, settings, environment setup
* implementation: Complete functions, classes, modules
* usage_example: How to use a feature or library
* snippet: Small code fragments or utilities
* complete_example: Full working examples or applications
* other: Code that doesn't fit other categories
If no code examples are found, return an empty array [].
Respond only with valid JSON array, no additional text.`,
};
export function buildAnalysisPrompt(
analysisType: 'full' | 'summary' | 'links' | 'classification' | 'code_examples',
context?: { url?: string; title?: string; domain?: string }
): string {
let prompt = '';
switch (analysisType) {
case 'full':
prompt = ANALYSIS_PROMPTS.FULL_ANALYSIS;
break;
case 'summary':
prompt = ANALYSIS_PROMPTS.SUMMARY_ONLY;
break;
case 'links':
prompt = ANALYSIS_PROMPTS.LINKS_ANALYSIS;
break;
case 'classification':
prompt = ANALYSIS_PROMPTS.CONTENT_CLASSIFICATION;
break;
case 'code_examples':
prompt = ANALYSIS_PROMPTS.CODE_EXAMPLES_ONLY;
break;
}
// add context if provided
if (context) {
if (context.domain) {
prompt = prompt.replace('[topic will be provided]', context.domain);
}
if (context.url && context.title) {
prompt += `\n\nPage context: "${context.title}" from ${context.url}`;
}
}
return prompt;
}