Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions src/vs/workbench/contrib/chat/browser/widget/input/chatInputPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Emitter, Event } from '../../../../../../base/common/event.js';
import { Iterable } from '../../../../../../base/common/iterator.js';
import { KeyCode } from '../../../../../../base/common/keyCodes.js';
import { Lazy } from '../../../../../../base/common/lazy.js';
import { Disposable, DisposableMap, DisposableStore, IDisposable, MutableDisposable, toDisposable } from '../../../../../../base/common/lifecycle.js';
import { combinedDisposable, Disposable, DisposableMap, DisposableStore, IDisposable, MutableDisposable, toDisposable } from '../../../../../../base/common/lifecycle.js';
import { ResourceSet } from '../../../../../../base/common/map.js';
import { MarshalledId } from '../../../../../../base/common/marshallingIds.js';
import { Schemas } from '../../../../../../base/common/network.js';
Expand Down Expand Up @@ -312,6 +312,10 @@ const emptyInputAttachments = observableMemento<readonly IChatRequestVariableEnt
fromStorage: deserializeUntitledInputAttachments,
});

interface IChatToolConfirmationCarouselEntry extends IDisposable {
readonly part: ChatToolConfirmationCarouselPart;
}

export class ChatInputPart extends Disposable implements IHistoryNavigationWidget {
private static _counter = 0;

Expand All @@ -326,7 +330,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
private readonly _chatPlanReviewWidgets = this._register(new DisposableMap<string, ChatPlanReviewPart>());
private readonly _planReviewResponseIds = new Map<string, string>();
private readonly _planReviewSessionResources = new Map<string, URI>();
private readonly _chatToolConfirmationCarousels = this._register(new DisposableMap<string, ChatToolConfirmationCarouselPart>());
private readonly _chatToolConfirmationCarousels = this._register(new DisposableMap<string, IChatToolConfirmationCarouselEntry>());
private readonly _onDidChangeActiveConfirmationSubagent = this._register(new Emitter<string | undefined>());
readonly onDidChangeActiveConfirmationSubagent = this._onDidChangeActiveConfirmationSubagent.event;
private readonly _chatEditingTodosDisposables = this._register(new DisposableStore());
Expand Down Expand Up @@ -3965,7 +3969,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge

private get _currentToolConfirmationCarousel(): ChatToolConfirmationCarouselPart | undefined {
const key = this._currentSessionKey;
return key ? this._chatToolConfirmationCarousels.get(key) : undefined;
return key ? this._chatToolConfirmationCarousels.get(key)?.part : undefined;
}

renderToolConfirmationCarousel(tool: IChatToolInvocation, factory: ToolInvocationPartFactory, subAgentInvocationId?: string, agentName?: string, revealSubagent?: RevealSubagentCallback, revealSubagentLabel?: string, toolPart?: ChatToolInvocationPart): ChatToolConfirmationCarouselPart {
Expand All @@ -3983,28 +3987,28 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge

const part = new ChatToolConfirmationCarouselPart(factory, [], revealSubagent, revealSubagentLabel, subAgentInvocationId, agentName);
part.addToolInvocation(tool, subAgentInvocationId, agentName, revealSubagent, revealSubagentLabel, toolPart);
this._chatToolConfirmationCarousels.set(key, part);
const capturedKey = key;
this._register(part.onDidChangeActiveSubagent(id => {
const activeSubagentListener = part.onDidChangeActiveSubagent(id => {
if (this._currentSessionKey === capturedKey) {
this._onDidChangeActiveConfirmationSubagent.fire(id);
}
}));
if (this._currentSessionKey === capturedKey) {
this._onDidChangeActiveConfirmationSubagent.fire(part.activeSubAgentInvocationId);
}
dom.append(this.chatToolConfirmationCarouselContainer, part.domNode);
dom.show(this.chatToolConfirmationCarouselContainer);
this.updateToolConfirmationCarouselMaxHeight();

this._register(Event.once(part.onDidEmpty)(() => {
});
const emptyListener = Event.once(part.onDidEmpty)(() => {
this._chatToolConfirmationCarousels.deleteAndDispose(capturedKey);
if (this._currentSessionKey === capturedKey) {
this._onDidChangeActiveConfirmationSubagent.fire(undefined);
dom.clearNode(this.chatToolConfirmationCarouselContainer);
dom.hide(this.chatToolConfirmationCarouselContainer);
}
}));
});
const disposable = combinedDisposable(part, activeSubagentListener, emptyListener);
this._chatToolConfirmationCarousels.set(key, { part, dispose: () => disposable.dispose() });
if (this._currentSessionKey === capturedKey) {
this._onDidChangeActiveConfirmationSubagent.fire(part.activeSubAgentInvocationId);
}
dom.append(this.chatToolConfirmationCarouselContainer, part.domNode);
dom.show(this.chatToolConfirmationCarouselContainer);
this.updateToolConfirmationCarouselMaxHeight();

return part;
}
Expand Down