Skip to content

Commit 7d9aa7e

Browse files
authored
update task handling in ChatStickyTaskWidget and ChatWidget (microsoft#257942)
1 parent f496271 commit 7d9aa7e

File tree

2 files changed

+27
-35
lines changed

2 files changed

+27
-35
lines changed

src/vs/workbench/contrib/chat/browser/chatContentParts/chatStickyTaskWidget.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as dom from '../../../../../base/browser/dom.js';
77
import { Emitter, Event } from '../../../../../base/common/event.js';
88
import { Disposable } from '../../../../../base/common/lifecycle.js';
99
import { localize } from '../../../../../nls.js';
10-
import { IChatTasksContent } from '../../common/chatService.js';
10+
import { IChatTasksService, IChatTask } from '../../common/chatTasksService.js';
1111

1212
export class ChatStickyTaskWidget extends Disposable {
1313
public readonly domNode: HTMLElement;
@@ -18,9 +18,11 @@ export class ChatStickyTaskWidget extends Disposable {
1818
private _isExpanded: boolean = true;
1919
private expandoElement!: HTMLElement;
2020
private taskListContainer!: HTMLElement;
21-
private _taskData: IChatTasksContent | undefined;
21+
private _currentSessionId: string | undefined;
2222

23-
constructor() {
23+
constructor(
24+
@IChatTasksService private readonly chatTasksService: IChatTasksService
25+
) {
2426
super();
2527

2628
this.domNode = this.createStickyTaskWidget();
@@ -68,11 +70,23 @@ export class ChatStickyTaskWidget extends Disposable {
6870
return container;
6971
}
7072

71-
public updateTaskData(taskData: IChatTasksContent | undefined): void {
72-
this._taskData = taskData;
73+
public updateSessionId(sessionId: string | undefined): void {
74+
this._currentSessionId = sessionId;
75+
this.updateTaskDisplay();
76+
}
77+
78+
private updateTaskDisplay(): void {
79+
if (!this._currentSessionId) {
80+
this.domNode.style.display = 'none';
81+
this._onDidChangeHeight.fire();
82+
return;
83+
}
7384

74-
if (taskData && taskData.tasks.length > 0) {
75-
this.renderTaskList();
85+
const taskStorage = this.chatTasksService.getChatTasksStorage();
86+
const tasks = taskStorage.getTasks(this._currentSessionId);
87+
88+
if (tasks.length > 0) {
89+
this.renderTaskList(tasks);
7690
this.domNode.style.display = 'block';
7791
} else {
7892
this.domNode.style.display = 'none';
@@ -81,19 +95,15 @@ export class ChatStickyTaskWidget extends Disposable {
8195
this._onDidChangeHeight.fire();
8296
}
8397

84-
private renderTaskList(): void {
85-
if (!this._taskData || !this._taskData.tasks.length) {
86-
return;
87-
}
88-
98+
private renderTaskList(tasks: IChatTask[]): void {
8999
this.taskListContainer.textContent = '';
90100

91101
const titleElement = this.expandoElement.querySelector('.task-title') as HTMLElement;
92102
if (titleElement) {
93103
titleElement.textContent = `${localize('chat.task.title', 'Tasks')}`;
94104
}
95105

96-
this._taskData.tasks.forEach((task, index) => {
106+
tasks.forEach((task, index) => {
97107
const taskElement = dom.$('.task-item');
98108

99109
const statusIcon = dom.$('.task-status-icon.codicon');

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

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import { applyingChatEditsFailedContextKey, decidedChatEditingResourceContextKey
4545
import { ChatPauseState, IChatModel, IChatResponseModel } from '../common/chatModel.js';
4646
import { chatAgentLeader, ChatRequestAgentPart, ChatRequestDynamicVariablePart, ChatRequestSlashPromptPart, ChatRequestToolPart, ChatRequestToolSetPart, chatSubcommandLeader, formatChatQuestion, IParsedChatRequest } from '../common/chatParserTypes.js';
4747
import { ChatRequestParser } from '../common/chatRequestParser.js';
48-
import { IChatLocationData, IChatSendRequestOptions, IChatService, IChatTasksContent } from '../common/chatService.js';
48+
import { IChatLocationData, IChatSendRequestOptions, IChatService } from '../common/chatService.js';
4949
import { IChatSlashCommandService } from '../common/chatSlashCommands.js';
5050
import { ChatViewModel, IChatRequestViewModel, IChatResponseViewModel, isRequestVM, isResponseVM } from '../common/chatViewModel.js';
5151
import { IChatInputState } from '../common/chatWidgetHistoryService.js';
@@ -68,13 +68,13 @@ import { ChatViewWelcomePart, IChatSuggestedPrompts, IChatViewWelcomeContent } f
6868
import { MicrotaskDelay } from '../../../../base/common/symbols.js';
6969
import { IChatRequestVariableEntry, ChatRequestVariableSet as ChatRequestVariableSet, isPromptFileVariableEntry, toPromptFileVariableEntry, PromptFileVariableKind, isPromptTextVariableEntry } from '../common/chatVariableEntries.js';
7070
import { ChatStickyTaskWidget } from './chatContentParts/chatStickyTaskWidget.js';
71-
import { ManageToolSettingId } from '../common/tools/manageTasksTool.js';
7271
import { PromptsConfig } from '../common/promptSyntax/config/config.js';
7372
import { CancellationToken } from '../../../../base/common/cancellation.js';
7473
import { ComputeAutomaticInstructions } from '../common/promptSyntax/computeAutomaticInstructions.js';
7574
import { startupExpContext, StartupExperimentGroup } from '../../../services/coreExperimentation/common/coreExperimentationService.js';
7675
import { IWorkspaceContextService, WorkbenchState } from '../../../../platform/workspace/common/workspace.js';
7776
import { IMouseWheelEvent } from '../../../../base/browser/mouseEvent.js';
77+
import { ManageToolSettingId } from '../common/tools/manageTasksTool.js';
7878

7979
const $ = dom.$;
8080

@@ -829,27 +829,9 @@ export class ChatWidget extends Disposable implements IChatWidget {
829829

830830
private renderStickyTaskWidget(): void {
831831
const isManageTasksToolEnabled = this.configurationService.getValue<boolean>(ManageToolSettingId) === true;
832-
if (!this.viewModel || !isManageTasksToolEnabled) {
833-
this.stickyTaskWidget.updateTaskData(undefined);
834-
return;
835-
}
836-
837-
let latestTaskData: IChatTasksContent | undefined;
838-
for (const item of this.viewModel.getItems().slice().reverse()) {
839-
if (isResponseVM(item)) {
840-
for (const content of item.response.value) {
841-
if (content.kind === 'toolInvocation' &&
842-
content.toolSpecificData?.kind === 'tasks') {
843-
latestTaskData = content.toolSpecificData;
844-
break;
845-
}
846-
}
847-
if (latestTaskData) {
848-
break;
849-
}
850-
}
832+
if (isManageTasksToolEnabled) {
833+
this.stickyTaskWidget.updateSessionId(this.viewModel?.sessionId);
851834
}
852-
this.stickyTaskWidget.updateTaskData(latestTaskData);
853835
}
854836

855837
private getWelcomeViewContent(additionalMessage: string | IMarkdownString | undefined, expEmptyState?: boolean): IChatViewWelcomeContent {

0 commit comments

Comments
 (0)