From 94013e94077242c2b0f60560e234b3cbda38acca Mon Sep 17 00:00:00 2001 From: Alive-Fish Date: Fri, 17 May 2024 10:39:03 +0800 Subject: [PATCH 1/2] fix: check vscode.version to enable teams participant (#11621) * fix: check vscode.version to enable teams participant * fix: cd adjustment * fix: ff for sample gallery * fix: cd content --------- Co-authored-by: Yuqi Zhou --- .github/workflows/cd.yml | 6 ++-- packages/vscode-extension/package.json | 4 +++ packages/vscode-extension/pnpm-lock.yaml | 12 ++++++- .../commands/create/createCommandHandler.ts | 4 +-- .../nextstep/nextstepCommandHandler.ts | 2 +- packages/vscode-extension/src/chat/prompts.ts | 36 ++++++++++--------- .../src/controls/declarations.d.ts | 1 + .../vscode-extension/src/controls/index.tsx | 6 +++- .../controls/sampleGallery/SampleGallery.tsx | 11 +++--- .../src/controls/webviewPanel.ts | 10 +++++- packages/vscode-extension/src/extension.ts | 12 ++++--- .../create/officeCreateCommandHandler.ts | 2 +- .../src/officeChat/officePrompts.ts | 9 ++--- 13 files changed, 77 insertions(+), 38 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 17714d5878b..4147ac1abc6 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -189,11 +189,11 @@ jobs: git commit -m "build: replace sideloading placeholders" - name: disable chat participant environment variable - if: ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.preid != 'alpha') }} + if: ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.preid != 'alpha' && github.event.inputs.preid != 'beta') }} run: bash .github/scripts/chat-participant-disabled.sh - name: disable api proposals in package.json - if: ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.preid != 'alpha') }} + if: ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.preid != 'alpha' && github.event.inputs.preid != 'beta') }} uses: jossef/action-set-json-field@v2.1 with: file: packages/vscode-extension/package.json @@ -202,7 +202,7 @@ jobs: parse_json: true - name: disable chat participant in package.json - if: ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.preid != 'alpha') }} + if: ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.preid != 'alpha' && github.event.inputs.preid != 'beta') }} uses: jossef/action-set-json-field@v2.1 with: file: packages/vscode-extension/package.json diff --git a/packages/vscode-extension/package.json b/packages/vscode-extension/package.json index 324701e5cdc..b4c8f5c0dce 100644 --- a/packages/vscode-extension/package.json +++ b/packages/vscode-extension/package.json @@ -1440,6 +1440,7 @@ "id": "ms-teams-vscode-extension.teams", "name": "teams", "description": "%teamstoolkit.chatParticipants.teams.description%", + "when": "fx-extension.isChatParticipantEnabled", "commands": [ { "name": "create", @@ -1455,6 +1456,7 @@ "id": "ms-teams-vscode-extension.office", "name": "office", "description": "%teamstoolkit.chatParticipants.officeAddIn.description%", + "when": "fx-extension.isChatParticipantEnabled", "commands": [ { "name": "create", @@ -1523,6 +1525,7 @@ "@types/react-dom": "^17.0.2", "@types/react-router-dom": "^5.1.7", "@types/react-syntax-highlighter": "^15.5.5", + "@types/semver": "^7.3.4", "@types/sinon": "^9.0.9", "@types/string-similarity": "^4.0.2", "@types/tmp": "^0.2.0", @@ -1615,6 +1618,7 @@ "react-collapsible": "^2.10.0", "react-copy-to-clipboard": "^5.1.0", "react-syntax-highlighter": "^15.5.0", + "semver": "^7.5.2", "string-similarity": "^4.0.4", "tmp": "^0.2.1", "validator": "^13.7.0", diff --git a/packages/vscode-extension/pnpm-lock.yaml b/packages/vscode-extension/pnpm-lock.yaml index 268262eb558..7b426f8be2b 100644 --- a/packages/vscode-extension/pnpm-lock.yaml +++ b/packages/vscode-extension/pnpm-lock.yaml @@ -98,6 +98,9 @@ dependencies: react-syntax-highlighter: specifier: ^15.5.0 version: 15.5.0(react@17.0.2) + semver: + specifier: ^7.5.2 + version: 7.5.4 string-similarity: specifier: ^4.0.4 version: 4.0.4 @@ -175,6 +178,9 @@ devDependencies: '@types/react-syntax-highlighter': specifier: ^15.5.5 version: 15.5.5 + '@types/semver': + specifier: ^7.3.4 + version: 7.5.8 '@types/sinon': specifier: ^9.0.9 version: 9.0.9 @@ -2799,6 +2805,10 @@ packages: resolution: {integrity: sha512-WZLiwShhwLRmeV6zH+GkbOFT6Z6VklCItrDioxUnv+u4Ll+8vKeFySoFyK/0ctcRpOmwAicELfmys1sDc/Rw+A==} dev: true + /@types/semver@7.5.8: + resolution: {integrity: sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==} + dev: true + /@types/send@0.17.4: resolution: {integrity: sha512-x2EM6TJOybec7c52BX0ZspPodMsQUd5L6PRwOunVyVUhXiBSKf3AezDL8Dgvgt5o0UfKNfuA0eMLr2wLT4AiBA==} dependencies: @@ -7336,7 +7346,7 @@ packages: jws: 3.2.2 lodash: 4.17.21 ms: 2.1.3 - semver: 7.5.1 + semver: 7.5.4 dev: true /jsonwebtoken@9.0.2: diff --git a/packages/vscode-extension/src/chat/commands/create/createCommandHandler.ts b/packages/vscode-extension/src/chat/commands/create/createCommandHandler.ts index fba8d87c371..df80155dcbc 100644 --- a/packages/vscode-extension/src/chat/commands/create/createCommandHandler.ts +++ b/packages/vscode-extension/src/chat/commands/create/createCommandHandler.ts @@ -73,7 +73,7 @@ export default async function createCommandHandler( response.markdown(localize("teamstoolkit.chatParticipants.create.oneMatched")); const firstMatch = matchedResult[0]; const describeProjectChatMessages = [ - describeProjectSystemPrompt, + describeProjectSystemPrompt(), new LanguageModelChatMessage( LanguageModelChatMessageRole.User, `The project you are looking for is '${JSON.stringify({ @@ -130,7 +130,7 @@ export default async function createCommandHandler( response.markdown(`- ${project.name}: `); const brieflyDescribeProjectChatMessages = [ - brieflyDescribeProjectSystemPrompt, + brieflyDescribeProjectSystemPrompt(), new LanguageModelChatMessage( LanguageModelChatMessageRole.User, `The project you are looking for is '${JSON.stringify(project)}'.` diff --git a/packages/vscode-extension/src/chat/commands/nextstep/nextstepCommandHandler.ts b/packages/vscode-extension/src/chat/commands/nextstep/nextstepCommandHandler.ts index da363b8b042..6456498b63d 100644 --- a/packages/vscode-extension/src/chat/commands/nextstep/nextstepCommandHandler.ts +++ b/packages/vscode-extension/src/chat/commands/nextstep/nextstepCommandHandler.ts @@ -112,7 +112,7 @@ export async function describeStep( telemetryMetadata: IChatTelemetryData ): Promise { const messages = [ - describeStepSystemPrompt, + describeStepSystemPrompt(), new LanguageModelChatMessage( LanguageModelChatMessageRole.User, `The content is '${JSON.stringify({ diff --git a/packages/vscode-extension/src/chat/prompts.ts b/packages/vscode-extension/src/chat/prompts.ts index 6ad90c69e4b..4169620481a 100644 --- a/packages/vscode-extension/src/chat/prompts.ts +++ b/packages/vscode-extension/src/chat/prompts.ts @@ -38,22 +38,26 @@ export const defaultSystemPrompt = () => { ); }; -export const describeProjectSystemPrompt = new vscode.LanguageModelChatMessage( - vscode.LanguageModelChatMessageRole.System, - `You are an advisor for Teams App developers. You need to describe the project based on the name and description field of user's JSON content. You should control the output between 50 and 80 words.` -); -export const brieflyDescribeProjectSystemPrompt = new vscode.LanguageModelChatMessage( - vscode.LanguageModelChatMessageRole.System, - `You are an advisor for Teams App developers. You need to describe the project based on the name and description field of user's JSON content. You should control the output between 30 and 40 words.` -); -export const describeScenarioSystemPrompt = new vscode.LanguageModelChatMessage( - vscode.LanguageModelChatMessageRole.System, - `You are an advisor for Teams App developers. You need to describe the project based on the name and description field of user's JSON content. You should control the output between 50 and 80 words.` -); -export const describeStepSystemPrompt = new vscode.LanguageModelChatMessage( - vscode.LanguageModelChatMessageRole.System, - `You are an advisor for Teams App developers. You need to reorganize the content. You should control the output between 30 and 50 words. Don't split the content into multiple sentences.` -); +export const describeProjectSystemPrompt = () => + new vscode.LanguageModelChatMessage( + vscode.LanguageModelChatMessageRole.System, + `You are an advisor for Teams App developers. You need to describe the project based on the name and description field of user's JSON content. You should control the output between 50 and 80 words.` + ); +export const brieflyDescribeProjectSystemPrompt = () => + new vscode.LanguageModelChatMessage( + vscode.LanguageModelChatMessageRole.System, + `You are an advisor for Teams App developers. You need to describe the project based on the name and description field of user's JSON content. You should control the output between 30 and 40 words.` + ); +export const describeScenarioSystemPrompt = () => + new vscode.LanguageModelChatMessage( + vscode.LanguageModelChatMessageRole.System, + `You are an advisor for Teams App developers. You need to describe the project based on the name and description field of user's JSON content. You should control the output between 50 and 80 words.` + ); +export const describeStepSystemPrompt = () => + new vscode.LanguageModelChatMessage( + vscode.LanguageModelChatMessageRole.System, + `You are an advisor for Teams App developers. You need to reorganize the content. You should control the output between 30 and 50 words. Don't split the content into multiple sentences.` + ); export function getTemplateMatchChatMessages( projectMetadata: ProjectMetadata[], diff --git a/packages/vscode-extension/src/controls/declarations.d.ts b/packages/vscode-extension/src/controls/declarations.d.ts index e1ccdfbc8cb..ecf42b8549b 100644 --- a/packages/vscode-extension/src/controls/declarations.d.ts +++ b/packages/vscode-extension/src/controls/declarations.d.ts @@ -14,3 +14,4 @@ declare const mermaid: { }; declare const panelType: string; declare const containerType: string; +declare const shouldShowChat: string; diff --git a/packages/vscode-extension/src/controls/index.tsx b/packages/vscode-extension/src/controls/index.tsx index 814dac60295..5a3bdada380 100644 --- a/packages/vscode-extension/src/controls/index.tsx +++ b/packages/vscode-extension/src/controls/index.tsx @@ -38,6 +38,7 @@ function App(props: any) { } else if (panelType === PanelType.RestifyServerNotificationBotReadme) { initialIndex = 5; } + return ( - + } + /> diff --git a/packages/vscode-extension/src/controls/sampleGallery/SampleGallery.tsx b/packages/vscode-extension/src/controls/sampleGallery/SampleGallery.tsx index cb0b8b8f233..3f6a1b93f82 100644 --- a/packages/vscode-extension/src/controls/sampleGallery/SampleGallery.tsx +++ b/packages/vscode-extension/src/controls/sampleGallery/SampleGallery.tsx @@ -21,9 +21,12 @@ import SampleCard from "./sampleCard"; import SampleDetailPage from "./sampleDetailPage"; import SampleFilter from "./sampleFilter"; import SampleListItem from "./sampleListItem"; -import { IsChatParticipantEnabled } from "../../chat/consts"; -export default class SampleGallery extends React.Component { +interface SampleGalleryProps { + shouldShowChat: string; +} + +export default class SampleGallery extends React.Component { private samples: SampleInfo[] = []; private filterOptions: SampleFilterOptionType = { capabilities: [], @@ -31,7 +34,7 @@ export default class SampleGallery extends React.Component

Samples

- {IsChatParticipantEnabled ? ( + {this.props.shouldShowChat === "true" ? (

Explore our sample gallery filled with solutions that work seamlessly with Teams Toolkit. Need help choosing? Let{" "} diff --git a/packages/vscode-extension/src/controls/webviewPanel.ts b/packages/vscode-extension/src/controls/webviewPanel.ts index a718a2c904c..7a547842528 100644 --- a/packages/vscode-extension/src/controls/webviewPanel.ts +++ b/packages/vscode-extension/src/controls/webviewPanel.ts @@ -4,7 +4,12 @@ import * as path from "path"; import * as vscode from "vscode"; -import { Correlator, SampleConfig, sampleProvider } from "@microsoft/teamsfx-core"; +import { + Correlator, + SampleConfig, + isChatParticipantEnabled, + sampleProvider, +} from "@microsoft/teamsfx-core"; import * as extensionPackage from "../../package.json"; import { TreatmentVariableValue } from "../exp/treatmentVariables"; @@ -312,6 +317,8 @@ export class WebviewPanel { vscode.Uri.joinPath(globalVariables.context.extensionUri, "out", "resource", "mermaid.min.js") ); + const allowChat = isChatParticipantEnabled(); + // Use a nonce to to only allow specific scripts to be run const nonce = this.getNonce(); return ` @@ -328,6 +335,7 @@ export class WebviewPanel { diff --git a/packages/vscode-extension/src/extension.ts b/packages/vscode-extension/src/extension.ts index 2e2021ecaf1..572d2be597e 100644 --- a/packages/vscode-extension/src/extension.ts +++ b/packages/vscode-extension/src/extension.ts @@ -4,6 +4,7 @@ "use strict"; import * as vscode from "vscode"; +import * as semver from "semver"; import { AppPackageFolderName, @@ -18,6 +19,7 @@ import { Correlator, VersionState, initializePreviewFeatureFlags, + isChatParticipantEnabled, setRegion, } from "@microsoft/teamsfx-core"; @@ -105,6 +107,9 @@ import { registerOfficeTaskAndDebugEvents } from "./debug/officeTaskHandler"; export let VS_CODE_UI: VsCodeUI; export async function activate(context: vscode.ExtensionContext) { + process.env[FeatureFlags.ChatParticipant] = ( + IsChatParticipantEnabled && semver.gte(vscode.version, "1.90.0-insider") + ).toString(); initializePreviewFeatureFlags(); configMgr.registerConfigChangeCallback(); @@ -123,8 +128,9 @@ export async function activate(context: vscode.ExtensionContext) { registerInternalCommands(context); - if (IsChatParticipantEnabled) { + if (isChatParticipantEnabled()) { registerChatParticipant(context); + registerOfficeChatParticipant(context); } @@ -149,11 +155,9 @@ export async function activate(context: vscode.ExtensionContext) { await vscode.commands.executeCommand( "setContext", "fx-extension.isChatParticipantEnabled", - IsChatParticipantEnabled + isChatParticipantEnabled() ); - process.env[FeatureFlags.ChatParticipant] = IsChatParticipantEnabled.toString(); - await vscode.commands.executeCommand( "setContext", "fx-extension.isOfficeAddIn", diff --git a/packages/vscode-extension/src/officeChat/commands/create/officeCreateCommandHandler.ts b/packages/vscode-extension/src/officeChat/commands/create/officeCreateCommandHandler.ts index 24278285271..9a76930f3b0 100644 --- a/packages/vscode-extension/src/officeChat/commands/create/officeCreateCommandHandler.ts +++ b/packages/vscode-extension/src/officeChat/commands/create/officeCreateCommandHandler.ts @@ -64,7 +64,7 @@ export default async function officeCreateCommandHandler( localize("teamstoolkit.chatParticipants.officeAddIn.create.projectMatched") ); const describeProjectChatMessages = [ - describeOfficeProjectSystemPrompt, + describeOfficeProjectSystemPrompt(), new LanguageModelChatMessage( LanguageModelChatMessageRole.User, `The project you are looking for is '${JSON.stringify(matchedResult)}'.` diff --git a/packages/vscode-extension/src/officeChat/officePrompts.ts b/packages/vscode-extension/src/officeChat/officePrompts.ts index c3ac6031f57..010f1b3bcc7 100644 --- a/packages/vscode-extension/src/officeChat/officePrompts.ts +++ b/packages/vscode-extension/src/officeChat/officePrompts.ts @@ -70,10 +70,11 @@ export const defaultOfficeSystemPrompt = () => { ); }; -export const describeOfficeProjectSystemPrompt = new vscode.LanguageModelChatMessage( - vscode.LanguageModelChatMessageRole.System, - `You are an advisor for Office Add-in developers. You need to describe the project based on the name and description field of user's JSON content. You should control the output between 50 and 80 words.` -); +export const describeOfficeProjectSystemPrompt = () => + new vscode.LanguageModelChatMessage( + vscode.LanguageModelChatMessageRole.System, + `You are an advisor for Office Add-in developers. You need to describe the project based on the name and description field of user's JSON content. You should control the output between 50 and 80 words.` + ); export const excelSystemPrompt = ` The following content written using Markdown syntax, using "Bold" style to highlight the key information. From adb9d39256d32fb41d828578f7af69f5f6c6b7c5 Mon Sep 17 00:00:00 2001 From: Ning Tang Date: Fri, 17 May 2024 14:11:26 +0800 Subject: [PATCH 2/2] fix(chat): string (#11505) * fix(chat): string * fix: restrict template match number * fix: ut * fix: ut coverage * fix: comment * fix: string and API change * fix: ut --- packages/vscode-extension/package.nls.json | 2 +- .../api/vscode.proposed.languageModels.d.ts | 5 ++- .../src/chat/commands/create/helper.ts | 5 ++- packages/vscode-extension/src/chat/utils.ts | 8 ++-- .../create/createCommandHandler.test.ts | 2 +- .../test/chat/commands/create/helper.test.ts | 41 +++++++++++++++++++ .../vscode-extension/test/chat/utils.test.ts | 4 +- .../mocks/localTuning/utilFunctions.ts | 2 +- 8 files changed, 58 insertions(+), 11 deletions(-) diff --git a/packages/vscode-extension/package.nls.json b/packages/vscode-extension/package.nls.json index 2bb2c8a4719..f95c770f70b 100644 --- a/packages/vscode-extension/package.nls.json +++ b/packages/vscode-extension/package.nls.json @@ -468,7 +468,7 @@ "teamstoolkit.chatParticipants.nextStep.whatsNext": "What should I do next?", "teamstoolkit.chatParticipants.create.sample": "Scaffold this sample", "teamstoolkit.chatParticipants.create.template": "Create this template", - "teamstoolkit.chatParticipants.create.tooGeneric": "Your app description is too generic. To find relevant templates or samples, give specific details of your app's capabilities or technologies.\n\nE.g. Instead of saying 'create a chat bot', you could specify 'create a chat bot that answers FAQs for customer support.'", + "teamstoolkit.chatParticipants.create.tooGeneric": "Your app description is too generic. To find relevant templates or samples, give specific details of your app's capabilities or technologies.\n\nE.g. Instead of saying 'create a bot', you could specify 'create a bot template' or 'create a notification bot that sends user the stock updates'.", "teamstoolkit.chatParticipants.create.oneMatched": "We've found 1 project that matches your description. Take a look at it below.\n\n", "teamstoolkit.chatParticipants.create.multipleMatched": "We've found %d projects that match your description. Take a look at them below.\n", "teamstoolkit.chatParticipants.create.noMatched": "I cannot find any matching templates or samples. Refine your app description or explore other templates.", diff --git a/packages/vscode-extension/src/chat/api/vscode.proposed.languageModels.d.ts b/packages/vscode-extension/src/chat/api/vscode.proposed.languageModels.d.ts index 17115a67305..8fc2c884137 100644 --- a/packages/vscode-extension/src/chat/api/vscode.proposed.languageModels.d.ts +++ b/packages/vscode-extension/src/chat/api/vscode.proposed.languageModels.d.ts @@ -95,8 +95,11 @@ declare module 'vscode' { * console.error(e); * } * ``` + * + * To cancel the stream, the consumer can {@link CancellationTokenSource.cancel cancel} the token that was used to make the request + * or break from the for-loop. */ - stream: AsyncIterable; + text: AsyncIterable; } /** diff --git a/packages/vscode-extension/src/chat/commands/create/helper.ts b/packages/vscode-extension/src/chat/commands/create/helper.ts index c1708553402..117de68ecdc 100644 --- a/packages/vscode-extension/src/chat/commands/create/helper.ts +++ b/packages/vscode-extension/src/chat/commands/create/helper.ts @@ -45,8 +45,11 @@ export async function matchProject( if (!request.prompt.includes("template")) { // also search in samples matchedProjects.push(...(await matchSamples(request, token, telemetryMetadata))); + matchedProjects.sort((a, b) => b.score - a.score); + } else { + matchedProjects.sort((a, b) => b.score - a.score); + matchedProjects.splice(2); } - matchedProjects.sort((a, b) => b.score - a.score); const result: ProjectMetadata[] = []; const matchedProjectIds = new Set(); for (const { id, score } of matchedProjects) { diff --git a/packages/vscode-extension/src/chat/utils.ts b/packages/vscode-extension/src/chat/utils.ts index 6e3608a68e3..445f814a728 100644 --- a/packages/vscode-extension/src/chat/utils.ts +++ b/packages/vscode-extension/src/chat/utils.ts @@ -19,8 +19,8 @@ export async function verbatimCopilotInteraction( if (!familyMatch) { throw new Error("No chat models available for the specified family"); } - const chatRequest = await familyMatch.sendRequest(messages, {}, token); - for await (const fragment of chatRequest.stream) { + const chatResponse = await familyMatch.sendRequest(messages, {}, token); + for await (const fragment of chatResponse.text) { response.markdown(fragment); } } @@ -36,9 +36,9 @@ export async function getCopilotResponseAsString( if (!familyMatch) { throw new Error("No chat models available for the specified family"); } - const chatRequest = await familyMatch.sendRequest(messages, {}, token); + const chatResponse = await familyMatch.sendRequest(messages, {}, token); let response = ""; - for await (const fragment of chatRequest.stream) { + for await (const fragment of chatResponse.text) { response += fragment; } return response; diff --git a/packages/vscode-extension/test/chat/commands/create/createCommandHandler.test.ts b/packages/vscode-extension/test/chat/commands/create/createCommandHandler.test.ts index e4b074f1451..112d5acad73 100644 --- a/packages/vscode-extension/test/chat/commands/create/createCommandHandler.test.ts +++ b/packages/vscode-extension/test/chat/commands/create/createCommandHandler.test.ts @@ -282,7 +282,7 @@ describe("chat create command", () => { chai.assert.isTrue(showFileTreeStub.notCalled); chai.assert.isTrue( response.markdown.calledOnceWith( - "Your app description is too generic. To find relevant templates or samples, give specific details of your app's capabilities or technologies.\n\nE.g. Instead of saying 'create a chat bot', you could specify 'create a chat bot that answers FAQs for customer support.'" + "Your app description is too generic. To find relevant templates or samples, give specific details of your app's capabilities or technologies.\n\nE.g. Instead of saying 'create a bot', you could specify 'create a bot template' or 'create a notification bot that sends user the stock updates'." ) ); }); diff --git a/packages/vscode-extension/test/chat/commands/create/helper.test.ts b/packages/vscode-extension/test/chat/commands/create/helper.test.ts index 36f88861f99..eee8bf179b7 100644 --- a/packages/vscode-extension/test/chat/commands/create/helper.test.ts +++ b/packages/vscode-extension/test/chat/commands/create/helper.test.ts @@ -65,6 +65,47 @@ describe("chat create helper", () => { chai.assert.strictEqual(result.length, 1); chai.assert.strictEqual(result[0].id, "test1"); }); + + it("has matched template project", async () => { + const chatTelemetryDataMock = sandbox.createStubInstance(telemetry.ChatTelemetryData); + sandbox.stub(chatTelemetryDataMock, "properties").get(function getterFn() { + return undefined; + }); + sandbox.stub(chatTelemetryDataMock, "measurements").get(function getterFn() { + return undefined; + }); + sandbox.stub(sampleProvider, "SampleCollection").get(function getterFn() { + return { + samples: [ + { + id: "test1", + title: "test1", + fullDescription: "test1", + }, + ], + }; + }); + chatTelemetryDataMock.chatMessages = []; + sandbox + .stub(telemetry.ChatTelemetryData, "createByParticipant") + .returns(chatTelemetryDataMock); + const sendTelemetryEventStub = sandbox.stub(ExtTelemetry, "sendTelemetryEvent"); + sandbox + .stub(util, "getCopilotResponseAsString") + .onFirstCall() + .resolves('{"app":[{"id": "bot", "score": 1.0}]}') + .onSecondCall() + .resolves('{"app":[{"id": "test2", "score": 0.5}]}'); + + const token = new CancellationToken(); + const result = await helper.matchProject( + { prompt: "test template" } as vscode.ChatRequest, + token, + chatTelemetryDataMock + ); + chai.assert.strictEqual(result.length, 1); + chai.assert.strictEqual(result[0].id, "bot"); + }); }); describe("showFileTree()", () => { diff --git a/packages/vscode-extension/test/chat/utils.test.ts b/packages/vscode-extension/test/chat/utils.test.ts index ef61a5ebc5b..11e22b97eae 100644 --- a/packages/vscode-extension/test/chat/utils.test.ts +++ b/packages/vscode-extension/test/chat/utils.test.ts @@ -30,7 +30,7 @@ describe("chat utils", () => { const token = new CancellationToken(); const chatModel: vscode.LanguageModelChat = { sendRequest: sandbox.stub().resolves({ - stream: asyncIterator, + text: asyncIterator, }), id: "", vendor: "", @@ -77,7 +77,7 @@ describe("chat utils", () => { const token = new CancellationToken(); const chatModel: vscode.LanguageModelChat = { sendRequest: sandbox.stub().resolves({ - stream: asyncIterator, + text: asyncIterator, }), id: "", vendor: "", diff --git a/packages/vscode-extension/test/officeChat/mocks/localTuning/utilFunctions.ts b/packages/vscode-extension/test/officeChat/mocks/localTuning/utilFunctions.ts index 41be59a0430..ff903f65f8e 100644 --- a/packages/vscode-extension/test/officeChat/mocks/localTuning/utilFunctions.ts +++ b/packages/vscode-extension/test/officeChat/mocks/localTuning/utilFunctions.ts @@ -75,7 +75,7 @@ export async function getCopilotResponseAsString( } const chatRequest = await familyMatch.sendRequest(messages, {}, token); let response = ""; - for await (const fragment of chatRequest.stream) { + for await (const fragment of chatRequest.text) { response += fragment; } return response;