Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/automation/src/chat.ts
5241 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 { Code } from './code';
7
8
const CHAT_VIEW = 'div[id="workbench.panel.chat"]';
9
const CHAT_INPUT_EDITOR = `${CHAT_VIEW} .interactive-input-part .monaco-editor[role="code"]`;
10
const CHAT_INPUT_EDITOR_FOCUSED = `${CHAT_VIEW} .interactive-input-part .monaco-editor.focused[role="code"]`;
11
const CHAT_RESPONSE = `${CHAT_VIEW} .interactive-item-container.interactive-response`;
12
const CHAT_RESPONSE_COMPLETE = `${CHAT_RESPONSE}:not(.chat-response-loading)`;
13
const CHAT_FOOTER_DETAILS = `${CHAT_VIEW} .chat-footer-details`;
14
15
export class Chat {
16
17
constructor(private code: Code) { }
18
19
private get chatInputSelector(): string {
20
return `${CHAT_INPUT_EDITOR} ${!this.code.editContextEnabled ? 'textarea' : '.native-edit-context'}`;
21
}
22
23
async waitForChatView(): Promise<void> {
24
await this.code.waitForElement(CHAT_VIEW);
25
}
26
27
async waitForInputFocus(): Promise<void> {
28
await this.code.waitForElement(CHAT_INPUT_EDITOR_FOCUSED);
29
}
30
31
async sendMessage(message: string): Promise<void> {
32
// Click on the chat input to focus it
33
await this.code.waitAndClick(CHAT_INPUT_EDITOR);
34
35
// Wait for the editor to be focused
36
await this.waitForInputFocus();
37
38
// Type the message using pressSequentially - this works with Monaco editors
39
// Note: Newlines are replaced with spaces since Enter key submits in chat input
40
const sanitizedMessage = message.replace(/\n/g, ' ');
41
await this.code.driver.currentPage.locator(this.chatInputSelector).pressSequentially(sanitizedMessage);
42
43
// Submit the message
44
await this.code.dispatchKeybinding('enter', () => Promise.resolve());
45
}
46
47
async waitForResponse(retryCount?: number): Promise<void> {
48
49
// First wait for a response element to appear
50
await this.code.waitForElement(CHAT_RESPONSE, undefined, retryCount);
51
52
// Then wait for it to complete (not loading)
53
await this.code.waitForElement(CHAT_RESPONSE_COMPLETE, undefined, retryCount);
54
}
55
56
async waitForModelInFooter(): Promise<void> {
57
await this.code.waitForElements(CHAT_FOOTER_DETAILS, false, el => {
58
return el.some(el => {
59
const text = el && typeof el.textContent === 'string' ? el.textContent : '';
60
return !!text && text.length > 0;
61
});
62
});
63
}
64
}
65
66