Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 21b37a6

Browse files
committed
fix: resolve TypeScript errors and Rollup build issue
- Fix TypeScript errors in project-faq.tsx: - Remove unused imports (cn, FAQAnswer type) - Fix RepoStats type usage (removed non-existent health/activity properties) - Properly handle pr.author object structure for contributor indexing - Remove unsupported title prop from Sparkles icon - Fix TypeScript errors in faq-service.ts: - Remove unused imports and variables - Fix type casting for cache service - Handle contributor data structure properly in reduce operations - Fix sort function type assertions - Work around Rollup conditional expression bug: - Temporarily disable treeshaking to fix build error - Added TODO to re-enable once Rollup issue is resolved - Reference: rollup/rollup#5747 Build now completes successfully with all TypeScript errors resolved.
1 parent 72e90a5 commit 21b37a6

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

src/components/insights/sections/project-faq.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import { ChevronDown, ChevronRight, HelpCircle, Sparkles } from "lucide-react";
33
import { Card } from "@/components/ui/card";
44
import { Button } from "@/components/ui/button";
55
import { Skeleton } from "@/components/ui/skeleton";
6-
import { cn } from "@/lib/utils";
76
import { useCachedRepoData } from "@/hooks/use-cached-repo-data";
8-
import { faqService, type FAQAnswer } from "@/lib/llm/faq-service";
7+
import { faqService } from "@/lib/llm/faq-service";
98

109
interface FAQ {
1110
id: string;
@@ -53,9 +52,7 @@ export function ProjectFAQ({ owner, repo, timeRange }: ProjectFAQProps) {
5352
if (useAI) {
5453
// Use AI-powered FAQ generation
5554
const repositoryData = {
56-
pullRequests: stats.pullRequests,
57-
health: stats.health,
58-
activity: stats.activity
55+
pullRequests: stats.pullRequests
5956
};
6057

6158
const aiAnswers = await faqService.generateFAQAnswers(
@@ -197,7 +194,7 @@ export function ProjectFAQ({ owner, repo, timeRange }: ProjectFAQProps) {
197194
const generateContributorCountAnswer = (): string => {
198195
if (!stats.pullRequests) return "Data is still loading...";
199196

200-
const uniqueContributors = new Set(stats.pullRequests.map(pr => pr.author)).size;
197+
const uniqueContributors = new Set(stats.pullRequests.map(pr => pr.author?.login || pr.user?.login || 'unknown')).size;
201198
const timeRangeText = getTimeRangeText();
202199

203200
return `${owner}/${repo} has ${uniqueContributors} unique contributors who have submitted pull requests ${timeRangeText}. This indicates ${uniqueContributors >= 20 ? 'a healthy and active' : uniqueContributors >= 10 ? 'a moderate' : 'a small but focused'} contributor community.`;
@@ -207,7 +204,8 @@ export function ProjectFAQ({ owner, repo, timeRange }: ProjectFAQProps) {
207204
if (!stats.pullRequests) return "Data is still loading...";
208205

209206
const contributorCounts = stats.pullRequests.reduce((acc, pr) => {
210-
acc[pr.author] = (acc[pr.author] || 0) + 1;
207+
const authorLogin = pr.author?.login || pr.user?.login || 'unknown';
208+
acc[authorLogin] = (acc[authorLogin] || 0) + 1;
211209
return acc;
212210
}, {} as Record<string, number>);
213211

@@ -236,7 +234,7 @@ export function ProjectFAQ({ owner, repo, timeRange }: ProjectFAQProps) {
236234
if (!stats.pullRequests) return "Data is still loading...";
237235

238236
const totalPRs = stats.pullRequests.length;
239-
const uniqueContributors = new Set(stats.pullRequests.map(pr => pr.author)).size;
237+
const uniqueContributors = new Set(stats.pullRequests.map(pr => pr.author?.login || pr.user?.login || 'unknown')).size;
240238
const timeRangeText = getTimeRangeText();
241239

242240
const activityLevel = totalPRs >= 50 ? 'very active' : totalPRs >= 20 ? 'moderately active' : 'lightly active';
@@ -257,7 +255,8 @@ export function ProjectFAQ({ owner, repo, timeRange }: ProjectFAQProps) {
257255
if (!stats.pullRequests) return "Data is still loading...";
258256

259257
const contributorCounts = stats.pullRequests.reduce((acc, pr) => {
260-
acc[pr.author] = (acc[pr.author] || 0) + 1;
258+
const authorLogin = pr.author?.login || pr.user?.login || 'unknown';
259+
acc[authorLogin] = (acc[authorLogin] || 0) + 1;
261260
return acc;
262261
}, {} as Record<string, number>);
263262

@@ -360,7 +359,7 @@ export function ProjectFAQ({ owner, repo, timeRange }: ProjectFAQProps) {
360359
>
361360
<span className="text-sm font-medium pr-2 flex-1">{faq.question}</span>
362361
{faq.isAIGenerated && (
363-
<Sparkles className="h-3 w-3 text-blue-500 mr-2 flex-shrink-0" title="AI-generated answer" />
362+
<Sparkles className="h-3 w-3 text-blue-500 mr-2 flex-shrink-0" />
364363
)}
365364
{expandedItems.has(faq.id) ? (
366365
<ChevronDown className="h-4 w-4 text-muted-foreground flex-shrink-0" />

src/lib/llm/faq-service.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
import { openAIService, type LLMInsight } from './openai-service';
77
import { cacheService } from './cache-service';
8-
import { generateEmbedding, prepareTextForEmbedding } from '../../../app/services/embeddings';
9-
import type { EmbeddingItem } from '../../../app/services/embeddings';
8+
import { generateEmbedding } from '../../../app/services/embeddings';
109

1110
export interface FAQQuestion {
1211
id: string;
@@ -101,7 +100,7 @@ class FAQService {
101100
// Check cache first
102101
const cached = cacheService.get(cacheKey, dataHash);
103102
if (cached) {
104-
return cached;
103+
return cached as unknown as FAQAnswer[];
105104
}
106105

107106
try {
@@ -126,7 +125,7 @@ class FAQService {
126125
}
127126

128127
// Cache successful results
129-
cacheService.set(cacheKey, answers, dataHash, 60 * 60 * 1000); // 1 hour cache
128+
cacheService.set(cacheKey, answers as unknown as LLMInsight, dataHash, 60 * 60 * 1000); // 1 hour cache
130129

131130
return answers;
132131
} catch (error) {
@@ -151,7 +150,7 @@ class FAQService {
151150

152151
try {
153152
const prompt = this.buildFAQPrompt(question, owner, repo, timeRange, repositoryData);
154-
const model = 'gpt-4o-mini'; // Use cost-effective model for FAQ answers
153+
// Use cost-effective model for FAQ answers
155154

156155
// Create a mock insight structure to work with existing OpenAI patterns
157156
const faqInsight = await this.generateFAQInsight(prompt, { owner, repo });
@@ -218,14 +217,15 @@ Answer:`;
218217
const data: string[] = [];
219218

220219
if (category === 'contributors' && repositoryData.pullRequests) {
221-
const contributors = new Set(repositoryData.pullRequests.map(pr => pr.author)).size;
220+
const contributors = new Set(repositoryData.pullRequests.map((pr: any) => pr.author?.login || pr.user?.login || 'unknown')).size;
222221
const contributorCounts = repositoryData.pullRequests.reduce((acc, pr) => {
223-
acc[pr.author] = (acc[pr.author] || 0) + 1;
222+
const authorLogin = pr.author?.login || pr.user?.login || 'unknown';
223+
acc[authorLogin] = (acc[authorLogin] || 0) + 1;
224224
return acc;
225225
}, {} as Record<string, number>);
226226

227227
const topContributors = Object.entries(contributorCounts)
228-
.sort(([, a], [, b]) => b - a)
228+
.sort(([, a], [, b]) => (b as number) - (a as number))
229229
.slice(0, 5);
230230

231231
data.push(`Total Contributors: ${contributors}`);
@@ -317,11 +317,12 @@ Answer:`;
317317
case 'top-contributors':
318318
if (repositoryData.pullRequests) {
319319
const contributorCounts = repositoryData.pullRequests.reduce((acc, pr) => {
320-
acc[pr.author] = (acc[pr.author] || 0) + 1;
320+
const authorLogin = pr.author?.login || pr.user?.login || 'unknown';
321+
acc[authorLogin] = (acc[authorLogin] || 0) + 1;
321322
return acc;
322323
}, {} as Record<string, number>);
323324
const top = Object.entries(contributorCounts)
324-
.sort(([, a], [, b]) => b - a)
325+
.sort(([, a], [, b]) => (b as number) - (a as number))
325326
.slice(0, 3)
326327
.map(([name, count]) => `${name} (${count} PRs)`);
327328
answer = `The top contributors ${timeRangeText} are: ${top.join(', ')}.`;
@@ -475,5 +476,4 @@ Answer:`;
475476
// Export singleton instance
476477
export const faqService = new FAQService();
477478

478-
// Export types
479-
export type { FAQQuestion, FAQAnswer, RepositoryData };
479+
// Types are already exported at the interface declaration

vite.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ export default defineConfig({
8888
strictRequires: 'auto'
8989
},
9090
rollupOptions: {
91+
// Workaround for Rollup conditional expression bug
92+
// TODO: Re-enable treeshaking after Rollup fixes the bug
93+
// See: https://github.com/rollup/rollup/issues/5747
94+
treeshake: false,
9195
// Remove the external configuration as it's causing build issues
9296
output: {
9397
// Ensure proper module format

0 commit comments

Comments
 (0)