-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add ai search in docs #338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Build Status: Success!
📝 Latest commit: fce833e |
@claude Review |
Claude finished @DarkPhoenix2704's task —— View job Code Review Complete ✅I've reviewed the AI search feature implementation. This is a substantial addition that integrates OpenAI's GPT-4 with Typesense search to provide intelligent documentation assistance. Below is my detailed feedback: 🎯 OverviewThe PR successfully adds an AI-powered search interface that:
🔴 Critical Issues1. Hardcoded API Key in Production Code 🚨File: apiKey: process.env.TYPESENSE_API_KEY || 'lNKDTZdJrE76Sg8WEyeN9mXT29l1xq7Q', Issue: The fallback API key should never be hardcoded. This is a security vulnerability. Recommendation: const apiKey = process.env.TYPESENSE_API_KEY;
if (!apiKey) {
throw new Error('TYPESENSE_API_KEY environment variable is required');
} 2. Missing Environment Variable ValidationFile: The OpenAI API key has no fallback handling. If Recommendation: Add validation at module level or in the route handler: if (!process.env.OPENAI_API_KEY) {
console.error('Missing OPENAI_API_KEY environment variable');
} 3. Unprotected API RouteFile: The Issues:
Recommendations: export async function POST(req: Request) {
// 1. Add rate limiting (e.g., using Vercel Edge Config or Redis)
// 2. Validate request body
const reqJson = await req.json();
if (!reqJson.messages || !Array.isArray(reqJson.messages)) {
return new Response('Invalid request body', { status: 400 });
}
// 3. Consider adding API key authentication or using Next.js middleware
// to protect this route from unauthorized access
// ... rest of handler
}
|
…d add search event tracking
77434aa
to
e63a471
Compare
…er) with configurable models
@claude review this pr again |
Claude finished @rameshmane7218's task —— View job Code Review: AI Search in Docs - Follow-up ReviewI've completed a thorough re-review of this PR. Let me provide my findings on what's been addressed and what still needs attention. Summary of Changes Since Last ReviewThe team has made significant improvements to address the previous critical security and quality issues: ✅ Fixed:
🔴 CRITICAL Issues (Must Fix Before Merge)1. Hardcoded Typesense API Key 🚨File: const typesenseClient = new Client({
apiKey: 'lNKDTZdJrE76Sg8WEyeN9mXT29l1xq7Q',
nodes: [
{
host: 'rqf5uvajyeczwt3xp-1.a1.typesense.net',
port: 443,
protocol: 'https',
},
],
}); Status: ❌ NOT FIXED - This is the exact same issue from the previous review. Issue: The Typesense API key and host are hardcoded in the source code. This is a severe security vulnerability. Impact:
Required Fix: const typesenseClient = new Client({
apiKey: process.env.TYPESENSE_API_KEY || '',
nodes: [
{
host: process.env.TYPESENSE_HOST || '',
port: 443,
protocol: 'https',
},
],
});
if (!process.env.TYPESENSE_API_KEY || !process.env.TYPESENSE_HOST) {
throw new Error('TYPESENSE_API_KEY and TYPESENSE_HOST environment variables are required');
} Then add to # Typesense Configuration
TYPESENSE_API_KEY=your_typesense_key_here
TYPESENSE_HOST=your_typesense_host_here Priority: 🚨 BLOCKER - This must be fixed before merging to production. 2. Missing Input ValidationFile: let reqJson;
try {
reqJson = await req.json();
} catch {
return new Response('Invalid request', { status: 400 });
} Status: Issue: No validation that Risk: Could cause crashes if malformed data is sent. Recommended Fix: let reqJson;
try {
reqJson = await req.json();
// Validate request structure
if (!reqJson.messages || !Array.isArray(reqJson.messages)) {
return new Response('Invalid request: messages array required', { status: 400 });
}
if (reqJson.messages.length === 0) {
return new Response('Invalid request: messages cannot be empty', { status: 400 });
}
} catch {
return new Response('Invalid JSON request body', { status: 400 });
} Priority: 🔴 HIGH - Should be fixed before production deployment. 3. Unbounded Token UsageFile: Status: ❌ NOT FIXED - No limits on content size. Issue: The function fetches complete page content with no truncation or token limits: const pageContent = await getLLMText(page);
markdown += `${pageContent}\n\n[${linkIndex}]\n\n---\n\n`; Impact:
Recommended Fix: const MAX_CHARS_PER_PAGE = 8000; // ~2000 tokens
const MAX_TOTAL_CHARS = 20000; // ~5000 tokens total
let totalChars = 0;
for (const [pageUrl] of uniquePages) {
try {
const page = getPageFromUrl(pageUrl);
if (page) {
let pageContent = await getLLMText(page);
// Truncate individual page if too long
if (pageContent.length > MAX_CHARS_PER_PAGE) {
pageContent = pageContent.substring(0, MAX_CHARS_PER_PAGE) + '\n\n[Content truncated...]';
}
// Stop if we've reached total limit
if (totalChars + pageContent.length > MAX_TOTAL_CHARS) {
break;
}
markdown += `${pageContent}\n\n[${linkIndex}]\n\n---\n\n`;
totalChars += pageContent.length;
links.push({
url: page.url,
title: page.data.title,
label: linkIndex.toString(),
});
linkIndex++;
}
} catch(e) {
console.error(e);
}
} Priority: 🔴 HIGH - Important for cost control and performance. ✅ Issues Successfully Addressed1. Rate Limiting Implemented ✅File: Great work! The rate limiting implementation is solid:
Quality: Excellent. The implementation follows best practices. Note: This is an in-memory solution, so it resets on server restart and won't work in multi-instance deployments. For production with multiple servers, consider Redis-based rate limiting. 2. Error Handling with User Feedback ✅File: onError: (error) => {
toast.error("Something went wrong! Please try again later");
console.error(error);
}, Status: ✅ FIXED - Users now see friendly error messages via toast notifications. 3. Environment Variables Documented ✅File: Status: ✅ FIXED - Clear documentation of required environment variables with examples. Quality: Well done. The comments explain each provider and include example model IDs. Still Missing: Typesense environment variables (see Critical Issue #1). 4. Multiple AI Provider Support ✅File: Status: ✅ EXCELLENT ADDITION - The code now supports OpenAI, Google, and OpenRouter. Quality: Very well implemented with:
This is a great improvement that adds flexibility. 5. Analytics Hook Memoization ✅File: const trackEvent = useCallback((event: AnalyticsEvent) => {
if (pushRef.current) {
pushRef.current({
$current_url: window.location.href,
path: window.location.pathname,
hash: window.location.hash,
...event,
});
}
}, []); Status: ✅ FIXED -
|
Category | Status | Count |
---|---|---|
🔴 Critical Issues | Must Fix | 3 |
Should Fix | 0 | |
🟡 Moderate Issues | Nice to Fix | 4 |
✅ Fixed Issues | Resolved | 5 |
💡 Positive Notes | N/A | 3 |
🎯 Verdict
Status:
Reason: The hardcoded Typesense API key is a security vulnerability that must be fixed before merging.
Required Actions Before Merge:
- 🚨 Remove hardcoded Typesense credentials and use environment variables
- 🔴 Add input validation to the API route
- 🔴 Implement token/content limits for cost control
Recommended Actions:
4. 🟡 Improve error logging with context
5. 🟡 Add accessibility attributes
6. 🟡 Consider LRU cache for markdown rendering
👏 Positive Progress
The team has done an excellent job addressing most of the previous review feedback:
- Rate limiting implementation is solid
- Error handling is much improved
- Multi-provider support adds great flexibility
- Documentation is clear
- Code organization is excellent
With the critical security issue fixed, this will be a strong feature addition!
Branch: fix-blogs
No description provided.