/ lib / chat-agent.ts
chat-agent.ts
 1  import type { SendSlideChatRequest } from './types';
 2  
 3  const MAX_HISTORY_MESSAGES = 10;
 4  
 5  export function buildSlideChatSystemPrompt(): string {
 6    return `You are a senior engineer helping a code reviewer understand a specific set of changes in a pull request. Answer follow-up questions about these code changes. Be direct and concrete. Reference the actual code when helpful. Keep answers focused on what the reviewer needs to understand.`;
 7  }
 8  
 9  export function buildSlideChatUserMessage(req: SendSlideChatRequest): string {
10    const historySlice = req.history.slice(-MAX_HISTORY_MESSAGES);
11  
12    const parts: string[] = [];
13  
14    parts.push(`<pr_context>
15  Title: ${req.prTitle}
16  Summary: ${req.summary}
17  Description: ${req.prDescription}
18  </pr_context>`);
19  
20    parts.push(`<slide_context>
21  Title: ${req.slideTitle}
22  Narrative: ${req.slideNarrative}
23  Review focus: ${req.slideReviewFocus ?? 'N/A'}
24  Affected files: ${req.affectedFiles.join(', ')}
25  </slide_context>`);
26  
27    if (req.diffContent) {
28      parts.push(`<diff>
29  ${req.diffContent}
30  </diff>`);
31    }
32  
33    if (historySlice.length > 0) {
34      const formatted = historySlice
35        .map((m) => `${m.role === 'user' ? 'Reviewer' : 'Assistant'}: ${m.content}`)
36        .join('\n\n');
37      parts.push(`<conversation_history>
38  ${formatted}
39  </conversation_history>`);
40    }
41  
42    parts.push(`Question: ${req.question}`);
43  
44    return parts.join('\n\n');
45  }