Skip to content

Commit 96fbb0b

Browse files
authored
Showing old PR cards (#402)
Fixes microsoft/vscode#258668
1 parent 2690d22 commit 96fbb0b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/extension/intents/node/toolCallingLoop.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export abstract class ToolCallingLoop<TOptions extends IToolCallingLoopOptions =
170170
public async run(outputStream: ChatResponseStream | undefined, token: CancellationToken | PauseController): Promise<IToolCallLoopResult> {
171171
let i = 0;
172172
let lastResult: IToolCallSingleResult | undefined;
173+
let lastRequestMessagesStartingIndexForRun: number | undefined;
173174

174175
while (true) {
175176
if (lastResult && i++ >= this.options.toolCallLimit) {
@@ -179,6 +180,9 @@ export abstract class ToolCallingLoop<TOptions extends IToolCallingLoopOptions =
179180

180181
try {
181182
const result = await this.runOne(outputStream, i, token);
183+
if (lastRequestMessagesStartingIndexForRun === undefined) {
184+
lastRequestMessagesStartingIndexForRun = result.lastRequestMessages.length - 1;
185+
}
182186
lastResult = {
183187
...result,
184188
hadIgnoredFiles: lastResult?.hadIgnoredFiles || result.hadIgnoredFiles
@@ -203,9 +207,11 @@ export abstract class ToolCallingLoop<TOptions extends IToolCallingLoopOptions =
203207
this._logService.error('Error emitting read file trajectories', err);
204208
});
205209

206-
for (const result of Object.keys(this.toolCallResults)) {
207-
if (this.toolCallResults[result] instanceof LanguageModelToolResult2) {
208-
for (const part of this.toolCallResults[result].content) {
210+
const toolCallRoundsToDisplay = lastResult.lastRequestMessages.slice(lastRequestMessagesStartingIndexForRun ?? 0).filter((m): m is Raw.ToolChatMessage => m.role === Raw.ChatRole.Tool);
211+
for (const toolRound of toolCallRoundsToDisplay) {
212+
const result = this.toolCallResults[toolRound.toolCallId];
213+
if (result instanceof LanguageModelToolResult2) {
214+
for (const part of result.content) {
209215
if (part instanceof LanguageModelDataPart2 && part.mimeType === 'application/pull-request+json' && part.audience?.includes(ToolResultAudience.User)) {
210216
const data: { uri: string; title: string; description: string; author: string; linkTag: string } = JSON.parse(part.data.toString());
211217
outputStream?.push(new ChatResponsePullRequestPart(URI.parse(data.uri), data.title, data.description, data.author, data.linkTag));

0 commit comments

Comments
 (0)