Skip to content

Commit

Permalink
fix: check vscode.version to enable teams participant (#11621)
Browse files Browse the repository at this point in the history
* fix: check vscode.version to enable teams participant

* fix: cd adjustment

* fix: ff for sample gallery

* fix: cd content

---------

Co-authored-by: Yuqi Zhou <yuqzho@microsoft.com>
  • Loading branch information
Alive-Fish and yuqizhou77 committed May 17, 2024
1 parent 3518702 commit 63925ea
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 38 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,7 @@
"id": "ms-teams-vscode-extension.teams",
"name": "teams",
"description": "%teamstoolkit.chatParticipants.teams.description%",
"when": "fx-extension.isChatParticipantEnabled",
"commands": [
{
"name": "create",
Expand All @@ -1455,6 +1456,7 @@
"id": "ms-teams-vscode-extension.office",
"name": "office",
"description": "%teamstoolkit.chatParticipants.officeAddIn.description%",
"when": "fx-extension.isChatParticipantEnabled",
"commands": [
{
"name": "create",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion packages/vscode-extension/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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)}'.`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export async function describeStep(
telemetryMetadata: IChatTelemetryData
): Promise<string> {
const messages = [
describeStepSystemPrompt,
describeStepSystemPrompt(),
new LanguageModelChatMessage(
LanguageModelChatMessageRole.User,
`The content is '${JSON.stringify({
Expand Down
36 changes: 20 additions & 16 deletions packages/vscode-extension/src/chat/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down
1 change: 1 addition & 0 deletions packages/vscode-extension/src/controls/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ declare const mermaid: {
};
declare const panelType: string;
declare const containerType: string;
declare const shouldShowChat: string;
6 changes: 5 additions & 1 deletion packages/vscode-extension/src/controls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function App(props: any) {
} else if (panelType === PanelType.RestifyServerNotificationBotReadme) {
initialIndex = 5;
}

return (
<MemoryRouter
initialEntries={[
Expand All @@ -50,7 +51,10 @@ function App(props: any) {
]}
initialIndex={initialIndex}
>
<Route path="/sample-gallery" component={SampleGallery} />
<Route
path="/sample-gallery"
render={() => <SampleGallery shouldShowChat={shouldShowChat} />}
/>
<Route path="/survey" component={Survey} />
<Route path="/respond-to-card-actions" component={WorkflowBot} />
<Route path="/account-help" component={AccountHelp} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ 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<unknown, SampleGalleryState> {
interface SampleGalleryProps {
shouldShowChat: string;
}

export default class SampleGallery extends React.Component<SampleGalleryProps, SampleGalleryState> {
private samples: SampleInfo[] = [];
private filterOptions: SampleFilterOptionType = {
capabilities: [],
languages: [],
technologies: [],
};

constructor(props: unknown) {
constructor(props: SampleGalleryProps) {
super(props);
this.state = {
loading: true,
Expand Down Expand Up @@ -62,7 +65,7 @@ export default class SampleGallery extends React.Component<unknown, SampleGaller
</div>
<div className="title">
<h1>Samples</h1>
{IsChatParticipantEnabled ? (
{this.props.shouldShowChat === "true" ? (
<h3>
Explore our sample gallery filled with solutions that work seamlessly with Teams
Toolkit. Need help choosing? Let{" "}
Expand Down
10 changes: 9 additions & 1 deletion packages/vscode-extension/src/controls/webviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 `<!DOCTYPE html>
Expand All @@ -328,6 +335,7 @@ export class WebviewPanel {
<script>
const vscode = acquireVsCodeApi();
const panelType = '${panelType}';
const shouldShowChat = '${allowChat ? "true" : "false"}';
</script>
<script nonce="${nonce}" type="module" src="${scriptUri.toString()}"></script>
<script nonce="${nonce}" type="text/javascript" src="${dompurifyUri.toString()}"></script>
Expand Down
12 changes: 8 additions & 4 deletions packages/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"use strict";

import * as vscode from "vscode";
import * as semver from "semver";

import {
AppPackageFolderName,
Expand All @@ -18,6 +19,7 @@ import {
Correlator,
VersionState,
initializePreviewFeatureFlags,
isChatParticipantEnabled,
setRegion,
} from "@microsoft/teamsfx-core";

Expand Down Expand Up @@ -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();
Expand All @@ -123,8 +128,9 @@ export async function activate(context: vscode.ExtensionContext) {

registerInternalCommands(context);

if (IsChatParticipantEnabled) {
if (isChatParticipantEnabled()) {
registerChatParticipant(context);

registerOfficeChatParticipant(context);
}

Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}'.`
Expand Down
9 changes: 5 additions & 4 deletions packages/vscode-extension/src/officeChat/officePrompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 63925ea

Please sign in to comment.