Skip to content

Commit 564d6ae

Browse files
authored
Remove internal implementation of ChatAgentTask (#202908)
* Get rid of chat progress Task * Remove internal implementation of ChatAgentTask * Clean up more
1 parent 68f4339 commit 564d6ae

File tree

6 files changed

+13
-114
lines changed

6 files changed

+13
-114
lines changed

src/vs/workbench/api/browser/mainThreadChatAgents2.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { DeferredPromise } from 'vs/base/common/async';
76
import { CancellationToken } from 'vs/base/common/cancellation';
8-
import { IMarkdownString } from 'vs/base/common/htmlContent';
97
import { Disposable, DisposableMap, IDisposable } from 'vs/base/common/lifecycle';
108
import { revive } from 'vs/base/common/marshalling';
119
import { escapeRegExpCharacters } from 'vs/base/common/strings';
@@ -23,7 +21,7 @@ import { AddDynamicVariableAction, IAddDynamicVariableContext } from 'vs/workben
2321
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
2422
import { ChatRequestAgentPart } from 'vs/workbench/contrib/chat/common/chatParserTypes';
2523
import { ChatRequestParser } from 'vs/workbench/contrib/chat/common/chatRequestParser';
26-
import { IChatFollowup, IChatProgress, IChatService, IChatTreeData } from 'vs/workbench/contrib/chat/common/chatService';
24+
import { IChatFollowup, IChatProgress, IChatService } from 'vs/workbench/contrib/chat/common/chatService';
2725
import { IExtHostContext, extHostNamedCustomer } from 'vs/workbench/services/extensions/common/extHostCustomers';
2826

2927
type AgentData = {
@@ -42,9 +40,6 @@ export class MainThreadChatAgents2 extends Disposable implements MainThreadChatA
4240
private readonly _pendingProgress = new Map<string, (part: IChatProgress) => void>();
4341
private readonly _proxy: ExtHostChatAgentsShape2;
4442

45-
private _responsePartHandlePool = 0;
46-
private readonly _activeResponsePartPromises = new Map<string, DeferredPromise<string | IMarkdownString | IChatTreeData>>();
47-
4843
constructor(
4944
extHostContext: IExtHostContext,
5045
@IChatAgentService private readonly _chatAgentService: IChatAgentService,
@@ -123,29 +118,7 @@ export class MainThreadChatAgents2 extends Disposable implements MainThreadChatA
123118
this._chatAgentService.updateAgent(data.name, revive(metadataUpdate));
124119
}
125120

126-
async $handleProgressChunk(requestId: string, progress: IChatProgressDto, responsePartHandle?: number): Promise<number | void> {
127-
if (progress.kind === 'asyncContent') {
128-
const handle = ++this._responsePartHandlePool;
129-
const responsePartId = `${requestId}_${handle}`;
130-
const deferredContentPromise = new DeferredPromise<string | IMarkdownString | IChatTreeData>();
131-
this._activeResponsePartPromises.set(responsePartId, deferredContentPromise);
132-
this._pendingProgress.get(requestId)?.({ ...progress, resolvedContent: deferredContentPromise.p });
133-
return handle;
134-
} else if (typeof responsePartHandle === 'number') {
135-
// Complete an existing deferred promise with resolved content
136-
const responsePartId = `${requestId}_${responsePartHandle}`;
137-
const deferredContentPromise = this._activeResponsePartPromises.get(responsePartId);
138-
if (deferredContentPromise && progress.kind === 'treeData') {
139-
const withRevivedUris = revive<IChatTreeData>(progress);
140-
deferredContentPromise.complete(withRevivedUris);
141-
this._activeResponsePartPromises.delete(responsePartId);
142-
} else if (deferredContentPromise && progress.kind === 'content') {
143-
deferredContentPromise.complete(progress.content);
144-
this._activeResponsePartPromises.delete(responsePartId);
145-
}
146-
return responsePartHandle;
147-
}
148-
121+
async $handleProgressChunk(requestId: string, progress: IChatProgressDto): Promise<number | void> {
149122
const revivedProgress = revive(progress);
150123
this._pendingProgress.get(requestId)?.(revivedProgress as IChatProgress);
151124
}

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import { CallHierarchyItem } from 'vs/workbench/contrib/callHierarchy/common/cal
5353
import { IChatAgentCommand, IChatAgentMetadata, IChatAgentRequest, IChatAgentResult } from 'vs/workbench/contrib/chat/common/chatAgents';
5454
import { IChatProgressResponseContent } from 'vs/workbench/contrib/chat/common/chatModel';
5555
import { IChatMessage, IChatResponseFragment, IChatResponseProviderMetadata } from 'vs/workbench/contrib/chat/common/chatProvider';
56-
import { IChatAsyncContent, IChatDynamicRequest, IChatFollowup, IChatProgress, IChatReplyFollowup, IChatResponseErrorDetails, IChatUserActionEvent, InteractiveSessionVoteDirection } from 'vs/workbench/contrib/chat/common/chatService';
56+
import { IChatDynamicRequest, IChatFollowup, IChatProgress, IChatReplyFollowup, IChatResponseErrorDetails, IChatUserActionEvent, InteractiveSessionVoteDirection } from 'vs/workbench/contrib/chat/common/chatService';
5757
import { IChatRequestVariableValue, IChatVariableData } from 'vs/workbench/contrib/chat/common/chatVariables';
5858
import { DebugConfigurationProviderTriggerKind, MainThreadDebugVisualization, IAdapterDescriptor, IConfig, IDebugSessionReplMode, IDebugVisualization, IDebugVisualizationContext } from 'vs/workbench/contrib/debug/common/debug';
5959
import { IInlineChatBulkEditResponse, IInlineChatEditResponse, IInlineChatProgressItem, IInlineChatRequest, IInlineChatSession, InlineChatResponseFeedbackKind } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
@@ -1195,7 +1195,7 @@ export interface MainThreadChatAgentsShape2 extends IDisposable {
11951195
$unregisterAgentCompletionsProvider(handle: number): void;
11961196
$updateAgent(handle: number, metadataUpdate: IExtensionChatAgentMetadata): void;
11971197
$unregisterAgent(handle: number): void;
1198-
$handleProgressChunk(requestId: string, chunk: IChatProgressDto, responsePartHandle?: number): Promise<number | void>;
1198+
$handleProgressChunk(requestId: string, chunk: IChatProgressDto): Promise<number | void>;
11991199
}
12001200

12011201
export interface IChatAgentCompletionItem {
@@ -1207,8 +1207,7 @@ export interface IChatAgentCompletionItem {
12071207
}
12081208

12091209
export type IChatContentProgressDto =
1210-
| Dto<Exclude<IChatProgressResponseContent, IChatAsyncContent>>
1211-
| IChatAsyncContentDto;
1210+
| Dto<IChatProgressResponseContent>;
12121211

12131212
export type IChatAgentHistoryEntryDto = {
12141213
request: IChatAgentRequest;
@@ -1293,11 +1292,8 @@ export type IDocumentContextDto = {
12931292
ranges: IRange[];
12941293
};
12951294

1296-
export type IChatAsyncContentDto = Dto<Omit<IChatAsyncContent, 'resolvedContent'>>;
1297-
12981295
export type IChatProgressDto =
1299-
| Dto<Exclude<IChatProgress, IChatAsyncContent>>
1300-
| IChatAsyncContentDto;
1296+
| Dto<IChatProgress>;
13011297

13021298
export interface MainThreadChatShape extends IDisposable {
13031299
$registerChatProvider(handle: number, id: string): Promise<void>;

src/vs/workbench/contrib/chat/browser/chatListRenderer.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,8 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
442442
? this.renderTreeData(data.treeData, element, templateData, fileTreeIndex++)
443443
: data.kind === 'markdownContent'
444444
? this.renderMarkdown(data.content, element, templateData, fillInIncompleteTokens)
445-
: data.kind === 'asyncContent' ? this.renderPlaceholder(new MarkdownString(data.content), templateData)
446-
: onlyProgressMessagesAfterI(value, index) ? this.renderProgressMessage(data, false)
447-
: undefined;
445+
: onlyProgressMessagesAfterI(value, index) ? this.renderProgressMessage(data, false)
446+
: undefined;
448447
if (result) {
449448
templateData.value.appendChild(result.element);
450449
templateData.elementDisposables.add(result);
@@ -572,11 +571,6 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
572571
}
573572
}
574573

575-
// Did this part go from being a placeholder string to resolved tree data?
576-
else if (part.kind === 'treeData' && !isInteractiveProgressTreeData(renderedPart)) {
577-
partsToRender[index] = part.treeData;
578-
}
579-
580574
// Did this part's content change?
581575
else if (part.kind !== 'treeData' && !isInteractiveProgressTreeData(renderedPart) && !isProgressMessageRenderData(renderedPart)) {
582576
const wordCountResult = this.getDataForProgressiveRender(element, contentToMarkdown(part.content), renderedPart);
@@ -638,9 +632,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
638632
// Avoid doing progressive rendering for multiple markdown parts simultaneously
639633
else if (!hasRenderedOneMarkdownBlock && wordCountResults[index]) {
640634
const { value } = wordCountResults[index];
641-
result = renderableResponse[index].kind === 'asyncContent'
642-
? this.renderPlaceholder(new MarkdownString(value), templateData)
643-
: this.renderMarkdown(new MarkdownString(value), element, templateData, true);
635+
result = this.renderMarkdown(new MarkdownString(value), element, templateData, true);
644636
hasRenderedOneMarkdownBlock = true;
645637
}
646638

@@ -820,18 +812,6 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
820812
element.ariaLabel = expanded ? localize('usedReferencesExpanded', "{0}, expanded", label) : localize('usedReferencesCollapsed', "{0}, collapsed", label);
821813
}
822814

823-
private renderPlaceholder(markdown: IMarkdownString, templateData: IChatListItemTemplate): IMarkdownRenderResult {
824-
const codicon = $('.interactive-response-codicon-details', undefined, renderIcon({ id: 'sync~spin' }));
825-
codicon.classList.add('interactive-response-placeholder-codicon');
826-
const result = dom.append(templateData.value, codicon);
827-
828-
const content = this.renderer.render(markdown);
829-
content.element.className = 'interactive-response-placeholder-content';
830-
result.appendChild(content.element);
831-
832-
return { element: result, dispose: () => content.dispose() };
833-
}
834-
835815
private renderProgressMessage(progress: IChatProgressMessage, showSpinner: boolean): IMarkdownRenderResult {
836816
if (showSpinner) {
837817
// this step is in progress, communicate it to SR users

src/vs/workbench/contrib/chat/common/chatModel.ts

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { OffsetRange } from 'vs/editor/common/core/offsetRange';
1616
import { ILogService } from 'vs/platform/log/common/log';
1717
import { IChatAgentCommand, IChatAgentData, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
1818
import { ChatRequestTextPart, IParsedChatRequest, reviveParsedChatRequest } from 'vs/workbench/contrib/chat/common/chatParserTypes';
19-
import { IChat, IChatAgentMarkdownContentWithVulnerability, IChatAsyncContent, IChatContent, IChatContentInlineReference, IChatContentReference, IChatFollowup, IChatMarkdownContent, IChatProgress, IChatProgressMessage, IChatReplyFollowup, IChatResponse, IChatResponseErrorDetails, IChatResponseProgressFileTreeData, IChatTreeData, IChatUsedContext, InteractiveSessionVoteDirection, isIUsedContext } from 'vs/workbench/contrib/chat/common/chatService';
19+
import { IChat, IChatAgentMarkdownContentWithVulnerability, IChatContent, IChatContentInlineReference, IChatContentReference, IChatFollowup, IChatMarkdownContent, IChatProgress, IChatProgressMessage, IChatReplyFollowup, IChatResponse, IChatResponseErrorDetails, IChatResponseProgressFileTreeData, IChatTreeData, IChatUsedContext, InteractiveSessionVoteDirection, isIUsedContext } from 'vs/workbench/contrib/chat/common/chatService';
2020
import { IChatRequestVariableValue } from 'vs/workbench/contrib/chat/common/chatVariables';
2121

2222
export interface IChatRequestVariableData {
@@ -42,7 +42,6 @@ export type IChatProgressResponseContent =
4242
| IChatMarkdownContent
4343
| IChatAgentMarkdownContentWithVulnerability
4444
| IChatTreeData
45-
| IChatAsyncContent
4645
| IChatContentInlineReference
4746
| IChatProgressMessage;
4847

@@ -160,22 +159,6 @@ export class Response implements IResponse {
160159
}
161160

162161
this._updateRepr(quiet);
163-
} else if (progress.kind === 'asyncContent') {
164-
// Add a new resolving part
165-
const responsePosition = this._responseParts.push(progress) - 1;
166-
this._updateRepr(quiet);
167-
168-
progress.resolvedContent?.then((content) => {
169-
// Replace the resolving part's content with the resolved response
170-
if (typeof content === 'string') {
171-
this._responseParts[responsePosition] = { content: new MarkdownString(content), kind: 'markdownContent' };
172-
} else if (isMarkdownString(content)) {
173-
this._responseParts[responsePosition] = { content, kind: 'markdownContent' };
174-
} else {
175-
this._responseParts[responsePosition] = content;
176-
}
177-
this._updateRepr(quiet);
178-
});
179162
} else if (progress.kind === 'treeData' || progress.kind === 'inlineReference' || progress.kind === 'markdownVuln' || progress.kind === 'progressMessage') {
180163
this._responseParts.push(progress);
181164
this._updateRepr(quiet);
@@ -188,8 +171,6 @@ export class Response implements IResponse {
188171
return '';
189172
} else if (part.kind === 'inlineReference') {
190173
return basename('uri' in part.inlineReference ? part.inlineReference.uri : part.inlineReference);
191-
} else if (part.kind === 'asyncContent') {
192-
return part.content;
193174
} else {
194175
return part.content.value;
195176
}
@@ -303,15 +284,12 @@ export class ChatResponseModel extends Disposable implements IChatResponseModel
303284
/**
304285
* Apply one of the progress updates that are not part of the actual response content.
305286
*/
306-
applyReference(progress: IChatUsedContext | IChatContentReference | IChatProgressMessage) {
287+
applyReference(progress: IChatUsedContext | IChatContentReference) {
307288
if (progress.kind === 'usedContext') {
308289
this._usedContext = progress;
309290
} else if (progress.kind === 'reference') {
310291
this._contentReferences.push(progress);
311292
this._onDidChange.fire();
312-
} else if (progress.kind === 'progressMessage') {
313-
// this._progressMessages.push(progress);
314-
// this._onDidChange.fire();
315293
}
316294
}
317295

@@ -667,9 +645,8 @@ export class ChatModel extends Disposable implements IChatModel {
667645
}
668646

669647
if (progress.kind === 'vulnerability') {
670-
// TODO@roblourens ChatModel should just work with strings
671648
request.response.updateContent({ kind: 'markdownVuln', content: { value: progress.content }, vulnerabilities: progress.vulnerabilities }, quiet);
672-
} else if (progress.kind === 'content' || progress.kind === 'markdownContent' || progress.kind === 'asyncContent' || progress.kind === 'treeData' || progress.kind === 'inlineReference' || progress.kind === 'markdownVuln' || progress.kind === 'progressMessage') {
649+
} else if (progress.kind === 'content' || progress.kind === 'markdownContent' || progress.kind === 'treeData' || progress.kind === 'inlineReference' || progress.kind === 'markdownVuln' || progress.kind === 'progressMessage') {
673650
request.response.updateContent(progress, quiet);
674651
} else if (progress.kind === 'usedContext' || progress.kind === 'reference') {
675652
request.response.applyReference(progress);
@@ -758,8 +735,6 @@ export class ChatModel extends Disposable implements IChatModel {
758735
return item.treeData;
759736
} else if (item.kind === 'markdownContent') {
760737
return item.content;
761-
} else if (item.kind === 'asyncContent') {
762-
return new MarkdownString(item.content);
763738
} else {
764739
return item as any; // TODO
765740
}

src/vs/workbench/contrib/chat/common/chatService.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,6 @@ export interface IChatTreeData {
119119
kind: 'treeData';
120120
}
121121

122-
export interface IChatAsyncContent {
123-
/**
124-
* The placeholder to show while the content is loading
125-
*/
126-
content: string;
127-
resolvedContent: Promise<string | IMarkdownString | IChatTreeData>;
128-
kind: 'asyncContent';
129-
}
130-
131122
export interface IChatProgressMessage {
132123
content: IMarkdownString;
133124
kind: 'progressMessage';
@@ -157,7 +148,6 @@ export type IChatProgress =
157148
| IChatAgentContentWithVulnerabilities
158149
| IChatAgentMarkdownContentWithVulnerability
159150
| IChatTreeData
160-
| IChatAsyncContent
161151
| IChatUsedContext
162152
| IChatContentReference
163153
| IChatContentInlineReference

src/vs/workbench/contrib/chat/test/common/chatModel.test.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as assert from 'assert';
7-
import { DeferredPromise, timeout } from 'vs/base/common/async';
7+
import { timeout } from 'vs/base/common/async';
88
import { MarkdownString } from 'vs/base/common/htmlContent';
99
import { URI } from 'vs/base/common/uri';
1010
import { assertSnapshot } from 'vs/base/test/common/snapshot';
@@ -17,7 +17,6 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
1717
import { ChatAgentService, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
1818
import { ChatModel, Response } from 'vs/workbench/contrib/chat/common/chatModel';
1919
import { ChatRequestTextPart } from 'vs/workbench/contrib/chat/common/chatParserTypes';
20-
import { IChatTreeData } from 'vs/workbench/contrib/chat/common/chatService';
2120
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
2221
import { TestExtensionService, TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
2322

@@ -140,20 +139,6 @@ suite('Response', () => {
140139
await assertSnapshot(response.value);
141140
});
142141

143-
test('async content', async () => {
144-
const response = new Response([]);
145-
const deferred = new DeferredPromise<string>();
146-
const deferred2 = new DeferredPromise<IChatTreeData>();
147-
response.updateContent({ resolvedContent: deferred.p, content: 'text', kind: 'asyncContent' });
148-
response.updateContent({ resolvedContent: deferred2.p, content: 'text2', kind: 'asyncContent' });
149-
await assertSnapshot(response.value);
150-
151-
await deferred2.complete({ kind: 'treeData', treeData: { label: 'label', uri: URI.parse('https://microsoft.com') } });
152-
await deferred.complete('resolved');
153-
await assertSnapshot(response.value);
154-
});
155-
156-
157142
test('inline reference', async () => {
158143
const response = new Response([]);
159144
response.updateContent({ content: 'text before', kind: 'content' });

0 commit comments

Comments
 (0)