diff --git a/core/llm/llms/Mock.ts b/core/llm/llms/Mock.ts index 811ecba94..236af9824 100644 --- a/core/llm/llms/Mock.ts +++ b/core/llm/llms/Mock.ts @@ -1,10 +1,19 @@ -import { ChatMessage, CompletionOptions } from "../../index.js"; +import { ChatMessage, CompletionOptions, LLMOptions } from "../../index.js"; import { BaseLLM } from "../index.js"; +type MockMessage = ChatMessage | "REPEAT_LAST_MSG"; + class MockLLM extends BaseLLM { public completion: string = "Test Completion"; + public chatStreams: MockMessage[][] | undefined; static providerName = "mock"; + constructor(options: LLMOptions) { + super(options); + this.templateMessages = undefined; + this.chatStreams = options.requestOptions?.extraBodyProperties?.chatStream; + } + protected async *_streamComplete( prompt: string, signal: AbortSignal, @@ -18,6 +27,29 @@ class MockLLM extends BaseLLM { signal: AbortSignal, options: CompletionOptions, ): AsyncGenerator { + if (this.chatStreams) { + const chatStream = + this.chatStreams?.[ + messages.filter((m) => m.role === "user" || m.role === "tool") + .length - 1 + ]; + if (chatStream) { + for (const message of chatStream) { + switch (message) { + case "REPEAT_LAST_MSG": + yield { + role: "assistant", + content: messages[messages.length - 1].content, + }; + break; + default: + yield message; + } + } + } + return; + } + for (const char of this.completion) { yield { role: "assistant", diff --git a/extensions/vscode/e2e/README.md b/extensions/vscode/e2e/README.md index ea873e910..2af3c5312 100644 --- a/extensions/vscode/e2e/README.md +++ b/extensions/vscode/e2e/README.md @@ -1,6 +1,6 @@ ### Setup -When running e2e tests for the first time: +When running e2e tests for the first time, or after changing non-test source code: ```bash npm run e2e:all @@ -8,7 +8,7 @@ npm run e2e:all ### Run -Afterward, you can run the tests with: +Afterward, you can run the tests with as long as you've only changed the e2e test code: ```bash npm run e2e:quick diff --git a/extensions/vscode/e2e/selectors/GUI.selectors.ts b/extensions/vscode/e2e/selectors/GUI.selectors.ts index 82c0292b4..16c7b39d9 100644 --- a/extensions/vscode/e2e/selectors/GUI.selectors.ts +++ b/extensions/vscode/e2e/selectors/GUI.selectors.ts @@ -1,4 +1,4 @@ -import { By, until, WebDriver, WebView } from "vscode-extension-tester"; +import { By, WebDriver, WebView } from "vscode-extension-tester"; import { SelectorUtils } from "./SelectorUtils"; export class GUISelectors { @@ -30,6 +30,13 @@ export class GUISelectors { return SelectorUtils.getElementByDataTestId(view, "submit-input-button"); } + public static getAcceptToolCallButton(view: WebView) { + return SelectorUtils.getElementByDataTestId( + view, + "accept-tool-call-button", + ); + } + public static getModelDropdownButton(view: WebView) { return SelectorUtils.getElementByDataTestId(view, "model-select-button"); } diff --git a/extensions/vscode/e2e/test-continue/config.json b/extensions/vscode/e2e/test-continue/config.json index 0160335f5..a8932322a 100644 --- a/extensions/vscode/e2e/test-continue/config.json +++ b/extensions/vscode/e2e/test-continue/config.json @@ -12,6 +12,38 @@ "title": "Mock", "provider": "mock", "model": "this field is not used" + }, + { + "provider": "mock", + "title": "TOOL MOCK LLM", + "model": "claude-3-5-sonnet-latest", + "requestOptions": { + "extraBodyProperties": { + "chatStream": [ + [ + { + "role": "assistant", + "content": "I'm going to call a tool:" + }, + { + "role": "assistant", + "content": "", + "toolCalls": [ + { + "id": "test_id", + "type": "function", + "function": { + "name": "builtin_exact_search", + "arguments": "{\"query\": \"\\\" won't be matched because of escaped quotes \\\"\"}" + } + } + ] + } + ], + ["REPEAT_LAST_MSG"] + ] + } + } } ], "analytics": { diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index c3c2cdf7e..4e84f7d22 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -1,17 +1,17 @@ +import { expect } from "chai"; import { EditorView, - WebView, - WebDriver, Key, - WebElement, VSBrowser, + WebDriver, + WebElement, + WebView, } from "vscode-extension-tester"; -import { expect } from "chai"; +import { GlobalActions } from "../actions/Global.actions"; import { GUIActions } from "../actions/GUI.actions"; +import { DEFAULT_TIMEOUT } from "../constants"; import { GUISelectors } from "../selectors/GUI.selectors"; import { TestUtils } from "../TestUtils"; -import { DEFAULT_TIMEOUT } from "../constants"; -import { GlobalActions } from "../actions/Global.actions"; describe("GUI Test", () => { let view: WebView; @@ -191,6 +191,20 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.XL); }); + describe("Chat with tools", () => { + it("should render tool call", async () => { + await GUIActions.selectModelFromDropdown(view, "TOOL MOCK LLM"); + + const [messageInput] = await GUISelectors.getMessageInputFields(view); + await messageInput.sendKeys("Hello"); + await messageInput.sendKeys(Key.ENTER); + + await TestUtils.waitForSuccess( + () => GUISelectors.getThreadMessageByText(view, "No matches found"), // Defined in extensions/vscode/e2e/test-continue/config.json's TOOL MOCK LLM that we are calling the exact search tool + ); + }); + }); + describe("Chat Paths", () => { it("Open chat and type → open history → cmd+l → chat opens, empty and in focus", async () => { const originalTextInput = await GUISelectors.getMessageInputFieldAtIndex( diff --git a/extensions/vscode/e2e/tests/PromptFile.test.ts b/extensions/vscode/e2e/tests/PromptFile.test.ts index 266329681..7cf87fd54 100644 --- a/extensions/vscode/e2e/tests/PromptFile.test.ts +++ b/extensions/vscode/e2e/tests/PromptFile.test.ts @@ -10,7 +10,7 @@ import { import { GlobalActions } from "../actions/Global.actions"; import { DEFAULT_TIMEOUT } from "../constants"; -describe.only("Prompt file", () => { +describe("Prompt file", () => { let editor: TextEditor; beforeEach(async function () { diff --git a/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx b/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx index 9d4528f33..956b98158 100644 --- a/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx +++ b/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx @@ -7,10 +7,10 @@ import { vscButtonForeground, } from "../../../components"; import Spinner from "../../../components/gui/Spinner"; +import { useAppDispatch } from "../../../redux/hooks"; import { selectCurrentToolCall } from "../../../redux/selectors/selectCurrentToolCall"; import { callTool } from "../../../redux/thunks/callTool"; import { cancelTool } from "../../../redux/thunks/cancelTool"; -import { useAppDispatch } from "../../../redux/hooks"; const ButtonContainer = styled.div` display: flex; @@ -75,7 +75,10 @@ export function ToolCallButtons(props: ToolCallButtonsProps) { dispatch(cancelTool())}> Cancel - dispatch(callTool())}> + dispatch(callTool())} + data-testid="accept-tool-call-button" + > Continue