mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-03 21:03:08 +00:00
refactor: Remove redundant count normalization in suggestion parsing
- Removed the suggestionCount variable that was re-clamping the count parameter - Removed default values from function parameters (count: number = 10 → count: number)
This commit is contained in:
@@ -840,20 +840,19 @@ ${contextSection}${existingWorkSection}`;
|
|||||||
private parseSuggestionsFromResponse(
|
private parseSuggestionsFromResponse(
|
||||||
response: string,
|
response: string,
|
||||||
category: IdeaCategory,
|
category: IdeaCategory,
|
||||||
count: number = 10
|
count: number
|
||||||
): AnalysisSuggestion[] {
|
): AnalysisSuggestion[] {
|
||||||
const suggestionCount = Math.min(Math.max(Math.floor(count ?? 10), 1), 20);
|
|
||||||
try {
|
try {
|
||||||
// Try to extract JSON from the response
|
// Try to extract JSON from the response
|
||||||
const jsonMatch = response.match(/\[[\s\S]*\]/);
|
const jsonMatch = response.match(/\[[\s\S]*\]/);
|
||||||
if (!jsonMatch) {
|
if (!jsonMatch) {
|
||||||
logger.warn('No JSON array found in response, falling back to text parsing');
|
logger.warn('No JSON array found in response, falling back to text parsing');
|
||||||
return this.parseTextResponse(response, category, suggestionCount);
|
return this.parseTextResponse(response, category, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsed = JSON.parse(jsonMatch[0]);
|
const parsed = JSON.parse(jsonMatch[0]);
|
||||||
if (!Array.isArray(parsed)) {
|
if (!Array.isArray(parsed)) {
|
||||||
return this.parseTextResponse(response, category, suggestionCount);
|
return this.parseTextResponse(response, category, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsed
|
return parsed
|
||||||
@@ -866,10 +865,10 @@ ${contextSection}${existingWorkSection}`;
|
|||||||
priority: item.priority || 'medium',
|
priority: item.priority || 'medium',
|
||||||
relatedFiles: item.relatedFiles || [],
|
relatedFiles: item.relatedFiles || [],
|
||||||
}))
|
}))
|
||||||
.slice(0, suggestionCount);
|
.slice(0, count);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn('Failed to parse JSON response:', error);
|
logger.warn('Failed to parse JSON response:', error);
|
||||||
return this.parseTextResponse(response, category, suggestionCount);
|
return this.parseTextResponse(response, category, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -879,9 +878,8 @@ ${contextSection}${existingWorkSection}`;
|
|||||||
private parseTextResponse(
|
private parseTextResponse(
|
||||||
response: string,
|
response: string,
|
||||||
category: IdeaCategory,
|
category: IdeaCategory,
|
||||||
count: number = 10
|
count: number
|
||||||
): AnalysisSuggestion[] {
|
): AnalysisSuggestion[] {
|
||||||
const suggestionCount = Math.min(Math.max(Math.floor(count ?? 10), 1), 20);
|
|
||||||
const suggestions: AnalysisSuggestion[] = [];
|
const suggestions: AnalysisSuggestion[] = [];
|
||||||
|
|
||||||
// Try to find numbered items or headers
|
// Try to find numbered items or headers
|
||||||
@@ -941,7 +939,7 @@ ${contextSection}${existingWorkSection}`;
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return suggestions.slice(0, suggestionCount);
|
return suggestions.slice(0, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user