Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/sessions/contrib/agentFeedback/browser/agentFeedbackAttachmentWidget.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import './media/agentFeedbackAttachment.css';
7
import * as dom from '../../../../base/browser/dom.js';
8
import { Codicon } from '../../../../base/common/codicons.js';
9
import { ThemeIcon } from '../../../../base/common/themables.js';
10
import { Disposable } from '../../../../base/common/lifecycle.js';
11
import * as event from '../../../../base/common/event.js';
12
import { localize } from '../../../../nls.js';
13
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
14
import { IAgentFeedbackVariableEntry } from '../../../../workbench/contrib/chat/common/attachments/chatVariableEntries.js';
15
import { AgentFeedbackHover } from './agentFeedbackHover.js';
16
17
/**
18
* Attachment widget that renders "N comments" with a comment icon
19
* and a custom hover showing all feedback items with actions.
20
*/
21
export class AgentFeedbackAttachmentWidget extends Disposable {
22
23
readonly element: HTMLElement;
24
25
private readonly _onDidDelete = this._store.add(new event.Emitter<Event>());
26
readonly onDidDelete = this._onDidDelete.event;
27
28
private readonly _onDidOpen = this._store.add(new event.Emitter<void>());
29
readonly onDidOpen = this._onDidOpen.event;
30
31
constructor(
32
private readonly _attachment: IAgentFeedbackVariableEntry,
33
options: { shouldFocusClearButton: boolean; supportsDeletion: boolean },
34
container: HTMLElement,
35
@IInstantiationService private readonly _instantiationService: IInstantiationService,
36
) {
37
super();
38
39
this.element = dom.append(container, dom.$('.chat-attached-context-attachment.agent-feedback-attachment'));
40
this.element.tabIndex = 0;
41
this.element.role = 'button';
42
43
// Icon
44
const iconSpan = dom.$('span');
45
iconSpan.classList.add(...ThemeIcon.asClassNameArray(Codicon.comment));
46
const pillIcon = dom.$('div.chat-attached-context-pill', {}, iconSpan);
47
this.element.appendChild(pillIcon);
48
49
// Label
50
const label = dom.$('span.chat-attached-context-custom-text', {}, this._attachment.name);
51
this.element.appendChild(label);
52
53
const deletionCurrentlyNotSupported = true;
54
55
// Clear button
56
if (options.supportsDeletion && !deletionCurrentlyNotSupported) {
57
const clearBtn = dom.append(this.element, dom.$('.chat-attached-context-clear-button'));
58
const clearIcon = dom.$('span');
59
clearIcon.classList.add(...ThemeIcon.asClassNameArray(Codicon.close));
60
clearBtn.appendChild(clearIcon);
61
clearBtn.title = localize('removeAttachment', "Remove");
62
this._store.add(dom.addDisposableListener(clearBtn, dom.EventType.CLICK, (e) => {
63
e.preventDefault();
64
e.stopPropagation();
65
this._onDidDelete.fire(e);
66
}));
67
if (options.shouldFocusClearButton) {
68
clearBtn.focus();
69
}
70
}
71
72
// Aria label
73
this.element.ariaLabel = localize('chat.agentFeedback', "Attached agent feedback, {0}", this._attachment.name);
74
75
// Custom interactive hover
76
this._store.add(this._instantiationService.createInstance(AgentFeedbackHover, this.element, this._attachment, options.supportsDeletion));
77
}
78
}
79
80