File tree Expand file tree Collapse file tree
packages/compass-assistant/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,11 +9,7 @@ import { FOLLOW_UP_QUESTIONS_HEADER } from '../prompts';
99
1010const { MessagePrompts, MessagePrompt } = LgChatMessagePrompts ;
1111
12- /**
13- * Parses follow-up questions from the "### Follow-Up Questions" section at
14- * the end of an AI response. Returns the text with that section removed and
15- * the extracted questions.
16- */
12+ /** Strips the FOLLOW_UP_QUESTIONS_HEADER section from the text and returns the extracted questions. */
1713export function parseFollowUpQuestions ( text : string ) : {
1814 strippedText : string ;
1915 questions : string [ ] ;
@@ -24,17 +20,11 @@ export function parseFollowUpQuestions(text: string): {
2420 return { strippedText : text , questions : [ ] } ;
2521 }
2622
27- const afterHeader = text . slice ( headerIndex ) ;
28- // Match everything after the header line; the header is a single line so we
29- // skip to the first newline after it.
30- const contentMatch = afterHeader . match ( / \n [ ^ \n ] + \n ( [ \s \S ] * ) / ) ;
31- if ( ! contentMatch ) {
32- return { strippedText : text , questions : [ ] } ;
33- }
34-
35- const questions = contentMatch [ 1 ]
23+ const contentStart = text . indexOf ( '\n' , headerIndex + 1 ) + 1 ;
24+ const questions = text
25+ . slice ( contentStart )
3626 . split ( '\n' )
37- . map ( ( line ) => line . replace ( / ^ \s * \ d+ \. \s * | ^ \s * [ - * ] \s * / , '' ) . trim ( ) )
27+ . map ( ( line ) => line . trim ( ) . replace ( / ^ \d + \. \s * / , '' ) )
3828 . filter ( ( q ) => q . length > 0 ) ;
3929
4030 if ( questions . length === 0 ) {
Original file line number Diff line number Diff line change @@ -11,11 +11,6 @@ import { redactConnectionString } from 'mongodb-connection-string-url';
1111import type { AssistantMessage } from './compass-assistant-provider' ;
1212import { AVAILABLE_TOOLS } from '@mongodb-js/compass-generative-ai/provider' ;
1313
14- /**
15- * The markdown header used to delimit the follow-up questions section in AI
16- * responses. The parser in follow-up-prompts.tsx looks for this exact string,
17- * so any change here must be reflected there (and vice-versa).
18- */
1914export const FOLLOW_UP_QUESTIONS_HEADER = '### Follow-Up Questions' ;
2015
2116export type EntryPointMessage = {
@@ -121,6 +116,9 @@ Tell the user if indexes need to be created or modified to enable any recommenda
121116
122117${ FOLLOW_UP_QUESTIONS_HEADER }
123118[Provide 3 follow-up questions you think the user might want to ask after reading this response]
119+ 1. [First follow-up question]
120+ 2. [Second follow-up question]
121+ 3. [Third follow-up question]
124122</output-format>
125123
126124<guidelines>
You can’t perform that action at this time.
0 commit comments