59 lines
2.0 KiB
Markdown
59 lines
2.0 KiB
Markdown
|
|
# Task ID: 42
|
||
|
|
|
||
|
|
**Title:** Implement prompt summary generation service
|
||
|
|
|
||
|
|
**Status:** done
|
||
|
|
|
||
|
|
**Dependencies:** 37 ✓
|
||
|
|
|
||
|
|
**Priority:** high
|
||
|
|
|
||
|
|
**Description:** Create a service that auto-generates summary (20 words) and chapters (key sections) for prompts, using fast LLM when available or regex fallback.
|
||
|
|
|
||
|
|
**Details:**
|
||
|
|
|
||
|
|
1. Create `/src/mcpd/src/services/prompt-summary.service.ts`:
|
||
|
|
```typescript
|
||
|
|
export class PromptSummaryService {
|
||
|
|
constructor(
|
||
|
|
private llmClient: LlmClient | null,
|
||
|
|
private promptRepo: IPromptRepository
|
||
|
|
) {}
|
||
|
|
|
||
|
|
async generateSummary(content: string): Promise<{ summary: string; chapters: string[] }> {
|
||
|
|
if (this.llmClient) {
|
||
|
|
return this.generateWithLlm(content);
|
||
|
|
}
|
||
|
|
return this.generateWithRegex(content);
|
||
|
|
}
|
||
|
|
|
||
|
|
private async generateWithLlm(content: string): Promise<...> {
|
||
|
|
// Send content to fast LLM with prompt:
|
||
|
|
// "Generate a 20-word summary and extract key section topics..."
|
||
|
|
}
|
||
|
|
|
||
|
|
private generateWithRegex(content: string): { summary: string; chapters: string[] } {
|
||
|
|
// summary: first sentence of content (truncated to ~20 words)
|
||
|
|
// chapters: extract markdown headings via regex /^#+\s+(.+)$/gm
|
||
|
|
}
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
2. Integrate with PromptService:
|
||
|
|
- Call generateSummary on prompt create
|
||
|
|
- Call generateSummary on prompt update (when content changes)
|
||
|
|
- Cache results on the prompt record
|
||
|
|
|
||
|
|
3. Handle LLM availability check via existing LlmConfig patterns
|
||
|
|
|
||
|
|
**Test Strategy:**
|
||
|
|
|
||
|
|
- Unit test: generateWithRegex extracts first sentence as summary
|
||
|
|
- Unit test: generateWithRegex extracts markdown headings as chapters
|
||
|
|
- Unit test: generateWithLlm calls LLM with correct prompt (mock LLM)
|
||
|
|
- Unit test: generateSummary uses LLM when available
|
||
|
|
- Unit test: generateSummary falls back to regex when no LLM
|
||
|
|
- Unit test: Empty content handled gracefully
|
||
|
|
- Unit test: Content without headings returns empty chapters array
|
||
|
|
- Integration test: Creating prompt triggers summary generation
|