@@ -13,6 +13,8 @@ export interface PromptArgsBase {
13
13
} ;
14
14
context ?: vscode . ChatContext ;
15
15
connectionNames ?: string [ ] ;
16
+ databaseName ?: string ;
17
+ collectionName ?: string ;
16
18
}
17
19
18
20
export interface UserPromptResponse {
@@ -163,16 +165,27 @@ export abstract class PromptBase<TArgs extends PromptArgsBase> {
163
165
protected getHistoryMessages ( {
164
166
connectionNames,
165
167
context,
168
+ databaseName,
169
+ collectionName,
166
170
} : {
167
171
connectionNames ?: string [ ] ; // Used to scrape the connecting messages from the history.
168
172
context ?: vscode . ChatContext ;
173
+ databaseName ?: string ;
174
+ collectionName ?: string ;
169
175
} ) : vscode . LanguageModelChatMessage [ ] {
170
176
const messages : vscode . LanguageModelChatMessage [ ] = [ ] ;
171
177
172
178
if ( ! context ) {
173
179
return [ ] ;
174
180
}
175
181
182
+ let previousItem :
183
+ | vscode . ChatRequestTurn
184
+ | vscode . ChatResponseTurn
185
+ | undefined = undefined ;
186
+
187
+ const namespaceIsKnown =
188
+ databaseName !== undefined && collectionName !== undefined ;
176
189
for ( const historyItem of context . history ) {
177
190
if ( historyItem instanceof vscode . ChatRequestTurn ) {
178
191
if (
@@ -181,9 +194,21 @@ export abstract class PromptBase<TArgs extends PromptArgsBase> {
181
194
) {
182
195
// When the message is empty or a connection name then we skip it.
183
196
// It's probably going to be the response to the connect step.
197
+ previousItem = historyItem ;
184
198
continue ;
185
199
}
186
200
201
+ if ( previousItem instanceof vscode . ChatResponseTurn ) {
202
+ const responseIntent = ( previousItem . result as ChatResult ) . metadata
203
+ ?. intent ;
204
+
205
+ // If the namespace is already known, skip responses to prompts asking for it.
206
+ if ( responseIntent === 'askForNamespace' && namespaceIsKnown ) {
207
+ previousItem = historyItem ;
208
+ continue ;
209
+ }
210
+ }
211
+
187
212
// eslint-disable-next-line new-cap
188
213
messages . push ( vscode . LanguageModelChatMessage . User ( historyItem . prompt ) ) ;
189
214
}
@@ -206,11 +231,17 @@ export abstract class PromptBase<TArgs extends PromptArgsBase> {
206
231
'emptyRequest' ,
207
232
'askToConnect' ,
208
233
] ;
209
- if (
210
- responseTypesToSkip . indexOf (
211
- ( historyItem . result as ChatResult ) ?. metadata ?. intent
212
- ) > - 1
213
- ) {
234
+
235
+ const responseType = ( historyItem . result as ChatResult ) ?. metadata
236
+ ?. intent ;
237
+ if ( responseTypesToSkip . includes ( responseType ) ) {
238
+ previousItem = historyItem ;
239
+ continue ;
240
+ }
241
+
242
+ // If the namespace is already known, skip including prompts asking for it.
243
+ if ( responseType === 'askForNamespace' && namespaceIsKnown ) {
244
+ previousItem = historyItem ;
214
245
continue ;
215
246
}
216
247
@@ -232,6 +263,7 @@ export abstract class PromptBase<TArgs extends PromptArgsBase> {
232
263
// eslint-disable-next-line new-cap
233
264
messages . push ( vscode . LanguageModelChatMessage . Assistant ( message ) ) ;
234
265
}
266
+ previousItem = historyItem ;
235
267
}
236
268
237
269
return messages ;
0 commit comments