diff --git a/src/vs/workbench/contrib/chat/browser/actions/codeBlockOperations.ts b/src/vs/workbench/contrib/chat/browser/actions/codeBlockOperations.ts index 3149f453..947199fc 100644 --- a/src/vs/workbench/contrib/chat/browser/actions/codeBlockOperations.ts +++ b/src/vs/workbench/contrib/chat/browser/actions/codeBlockOperations.ts @@ -11,6 +11,7 @@ import { ResourceMap } from '../../../../../base/common/map.js'; import { isEqual } from '../../../../../base/common/resources.js'; import * as strings from '../../../../../base/common/strings.js'; import { URI } from '../../../../../base/common/uri.js'; +import { stripThinkTags } from '../../common/chatModel.js'; import { IActiveCodeEditor, isCodeEditor, isDiffEditor } from '../../../../../editor/browser/editorBrowser.js'; import { IBulkEditService, ResourceTextEdit } from '../../../../../editor/browser/services/bulkEditService.js'; import { ICodeEditorService } from '../../../../../editor/browser/services/codeEditorService.js'; @@ -382,13 +383,11 @@ function collectDocumentContextFromContext(context: ICodeBlockActionContext, res } function getChatConversation(context: ICodeBlockActionContext): (ConversationRequest | ConversationResponse)[] { - // TODO@aeschli for now create a conversation with just the current element - // this will be expanded in the future to include the request and any other responses - if (isResponseVM(context.element)) { return [{ type: 'response', - message: context.element.response.toMarkdown(), + // Strip think tags before computing diffs + message: stripThinkTags(context.element.response.toMarkdown()), references: getReferencesAsDocumentContext(context.element.contentReferences) }]; } else if (isRequestVM(context.element)) { diff --git a/src/vs/workbench/contrib/chat/common/chatModel.ts b/src/vs/workbench/contrib/chat/common/chatModel.ts index f11a40b7..ecb4d205 100644 --- a/src/vs/workbench/contrib/chat/common/chatModel.ts +++ b/src/vs/workbench/contrib/chat/common/chatModel.ts @@ -354,6 +354,36 @@ export class Response extends Disposable implements IResponse { } } +/** + * Strips tags and their content from a text string. + * Handles nested tags using a stack-based approach. + * @param text The text to strip tags from + * @returns The text with all tags and their content removed + */ +export function stripThinkTags(text: string): string { + // Handle nested tags with a stack-based approach + let result = ''; + let depth = 0; + let i = 0; + + while (i < text.length) { + if (text.startsWith('', i)) { + depth++; + i += 7; // length of '' + } else if (text.startsWith('', i)) { + depth--; + i += 8; // length of '' + } else if (depth === 0) { + result += text[i]; + i++; + } else { + i++; + } + } + + return result; +} + export class ChatResponseModel extends Disposable implements IChatResponseModel { private readonly _onDidChange = this._register(new Emitter()); readonly onDidChange = this._onDidChange.event;