Skip to content

Commit

Permalink
Merge pull request #12542 from OfficeDev/long/main
Browse files Browse the repository at this point in the history
build: merge main back to dev
  • Loading branch information
MSFT-yiz authored Oct 18, 2024
2 parents c1ca4fa + b3fa29b commit cd55ff4
Show file tree
Hide file tree
Showing 56 changed files with 1,712 additions and 133 deletions.
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/teamsfx-api",
"version": "0.23.1",
"version": "0.23.2",
"description": "teamsfx framework api",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/teamsapp-cli",
"version": "3.0.3",
"version": "3.0.4",
"author": "Microsoft Corporation",
"description": "",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/fx-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/teamsfx-core",
"version": "2.0.10",
"version": "2.0.11",
"main": "build/index.js",
"types": "build/index.d.ts",
"license": "MIT",
Expand Down
14 changes: 14 additions & 0 deletions packages/fx-core/src/common/projectTypeChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,20 @@ export function getCapabilities(manifest: any): string[] {
) {
capabilities.push("copilotGpt");
}
if (
manifest.copilotAgents?.plugins &&
manifest.copilotAgents.plugins.length > 0 &&
!capabilities.includes("plugin")
) {
capabilities.push("plugin");
}
if (
manifest.copilotAgents?.declarativeAgents &&
manifest.copilotAgents.declarativeAgents.length > 0 &&
!capabilities.includes("copilotGpt")
) {
capabilities.push("copilotGpt");
}
return capabilities;
}
export const projectTypeChecker = new ProjectTypeChecker();
4 changes: 2 additions & 2 deletions packages/fx-core/src/common/templates-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "~4.2",
"localVersion": "4.2.4",
"version": "~4.3",
"localVersion": "4.3.0",
"tagPrefix": "templates@",
"tagListURL": "https://github.com/OfficeDev/TeamsFx/releases/download/template-tag-list/template-tags.txt",
"templateDownloadBaseURL": "https://github.com/OfficeDev/TeamsFx/releases/download",
Expand Down
34 changes: 30 additions & 4 deletions packages/fx-core/src/component/driver/teamsApp/createAppPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ export class CreateAppPackageDriver implements StepDriver {
}
}
}
if (manifest.localizationInfo && manifest.localizationInfo.defaultLanguageFile) {
const file = manifest.localizationInfo.defaultLanguageFile;
const fileName = `${appDirectory}/${file}`;
if (!(await fs.pathExists(fileName))) {
return err(
new FileNotFoundError(
actionName,
fileName,
"https://aka.ms/teamsfx-actions/teamsapp-zipAppPackage"
)
);
}
}

const zip = new AdmZip();
zip.addFile(Constants.MANIFEST_FILE, Buffer.from(JSON.stringify(manifest, null, 4)));
Expand Down Expand Up @@ -166,6 +179,16 @@ export class CreateAppPackageDriver implements StepDriver {
zip.addLocalFile(fileName, dir === "." ? "" : dir);
}
}
if (manifest.localizationInfo && manifest.localizationInfo.defaultLanguageFile) {
const file = manifest.localizationInfo.defaultLanguageFile;
const fileName = path.resolve(appDirectory, file);
const relativePath = path.relative(appDirectory, fileName);
if (relativePath.startsWith("..")) {
return err(new InvalidFileOutsideOfTheDirectotryError(fileName));
}
const dir = path.dirname(file);
zip.addLocalFile(fileName, dir === "." ? "" : dir);
}

// API ME, API specification and Adaptive card templates
if (
Expand Down Expand Up @@ -218,9 +241,11 @@ export class CreateAppPackageDriver implements StepDriver {
}
}

const plugins = manifest.copilotExtensions?.plugins;
// API plugin
const plugins = manifest.copilotExtensions
? manifest.copilotExtensions.plugins
: manifest.copilotAgents?.plugins;
if (plugins?.length && plugins[0].file) {
// API plugin
const addFilesRes = await this.addPlugin(
zip,
plugins[0].file,
Expand All @@ -233,8 +258,9 @@ export class CreateAppPackageDriver implements StepDriver {
}
}

const declarativeCopilots = manifest.copilotExtensions?.declarativeCopilots;

const declarativeCopilots = manifest.copilotExtensions
? manifest.copilotExtensions.declarativeCopilots
: manifest.copilotAgents?.declarativeAgents;
// Copilot GPT
if (declarativeCopilots?.length && declarativeCopilots[0].file) {
const copilotGptManifestFile = path.resolve(appDirectory, declarativeCopilots[0].file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ export class CopilotGptManifestUtils {
if (teamsManifestRes.isErr()) {
return err(teamsManifestRes.error);
}
const filePath = teamsManifestRes.value.copilotExtensions?.declarativeCopilots?.[0].file;
const filePath = teamsManifestRes.value.copilotExtensions
? teamsManifestRes.value.copilotExtensions.declarativeCopilots?.[0].file
: teamsManifestRes.value.copilotAgents?.declarativeAgents?.[0].file;
if (!filePath) {
return err(
AppStudioResultFactory.UserError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ export class ManifestUtils {
manifest: TeamsAppManifest,
manifestPath: string
): Promise<Result<string, FxError>> {
const pluginFile = manifest.copilotExtensions?.plugins?.[0]?.file;
const pluginFile = manifest.copilotExtensions
? manifest.copilotExtensions.plugins?.[0]?.file
: manifest.copilotAgents?.plugins?.[0]?.file;
if (pluginFile) {
const plugin = path.resolve(path.dirname(manifestPath), pluginFile);
const doesFileExist = await fs.pathExists(plugin);
Expand Down
16 changes: 10 additions & 6 deletions packages/fx-core/src/component/driver/teamsApp/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ export class ValidateManifestDriver implements StepDriver {
let declarativeCopilotValidationResult;
let pluginValidationResult;
let pluginPath = "";
if (manifest.copilotExtensions) {
if (manifest.copilotExtensions || manifest.copilotAgents) {
// plugin
const plugins = manifest.copilotExtensions.plugins;
const plugins = manifest.copilotExtensions
? manifest.copilotExtensions.plugins
: manifest.copilotAgents!.plugins;
if (plugins?.length && plugins[0].file) {
pluginPath = path.join(path.dirname(manifestPath), plugins[0].file);

Expand All @@ -122,15 +124,17 @@ export class ValidateManifestDriver implements StepDriver {
}

// Declarative Copilot
const declaraitveCopilots = manifest.copilotExtensions.declarativeCopilots;
if (declaraitveCopilots?.length && declaraitveCopilots[0].file) {
const declarativeCopilots = manifest.copilotExtensions
? manifest.copilotExtensions.declarativeCopilots
: manifest.copilotAgents!.declarativeAgents;
if (declarativeCopilots?.length && declarativeCopilots[0].file) {
const declarativeCopilotPath = path.join(
path.dirname(manifestPath),
declaraitveCopilots[0].file
declarativeCopilots[0].file
);

const declarativeCopilotValidationRes = await copilotGptManifestUtils.validateAgainstSchema(
declaraitveCopilots[0],
declarativeCopilots[0],
declarativeCopilotPath,
context
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
ok,
} from "@microsoft/teamsfx-api";
import * as childProcess from "child_process";
import fse from "fs-extra";
import { toLower } from "lodash";
import { OfficeAddinManifest } from "office-addin-manifest";
import { convertProject } from "office-addin-project";
Expand Down
4 changes: 3 additions & 1 deletion packages/fx-core/src/core/FxCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,9 @@ export class FxCore {
}

const teamsManifest = manifestRes.value;
const declarativeGpt = teamsManifest.copilotExtensions?.declarativeCopilots?.[0];
const declarativeGpt = teamsManifest.copilotExtensions
? teamsManifest.copilotExtensions.declarativeCopilots?.[0]
: teamsManifest.copilotAgents?.declarativeAgents?.[0];
if (!declarativeGpt?.file) {
return err(
AppStudioResultFactory.UserError(
Expand Down
14 changes: 14 additions & 0 deletions packages/fx-core/tests/common/projectTypeChecker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ describe("ProjectTypeChecker", () => {
plugins: [1],
declarativeCopilots: [1],
},
copilotAgents: {
plugins: [1],
declarativeAgents: [1],
},
};
const capabilities = getCapabilities(manifest);
assert.deepEqual(capabilities, [
Expand All @@ -124,6 +128,16 @@ describe("ProjectTypeChecker", () => {
"copilotGpt",
]);
});
it("copilot agents", async () => {
const manifest = {
copilotAgents: {
plugins: [1],
declarativeAgents: [1],
},
};
const capabilities = getCapabilities(manifest);
assert.deepEqual(capabilities, ["plugin", "copilotGpt"]);
});
it("empty manifest", async () => {
const manifest = {
staticTabs: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,65 @@ describe("copilotGptManifestUtils", () => {
}
});

it("get manifest success - copilot agent", async () => {
sandbox.stub(manifestUtils, "_readAppManifest").resolves(
ok({
copilotAgents: {
declarativeAgents: [
{
file: "test",
id: "1",
},
],
},
} as any)
);
sandbox.stub(path, "dirname").returns("testFolder");
sandbox.stub(path, "resolve").returns("testFolder/test");

const res = await copilotGptManifestUtils.getManifestPath("testPath");

chai.assert.isTrue(res.isOk());
if (res.isOk()) {
chai.assert.equal(res.value, "testFolder/test");
}
});

it("declarativeAgents error 1", async () => {
sandbox.stub(manifestUtils, "_readAppManifest").resolves(
ok({
copilotAgents: {},
} as any)
);
const res = await copilotGptManifestUtils.getManifestPath("testPath");
chai.assert.isTrue(res.isErr());
if (res.isErr()) {
chai.assert.isTrue(res.error instanceof UserError);
}
});

it("declarativeAgents error 2", async () => {
sandbox.stub(manifestUtils, "_readAppManifest").resolves(ok({} as any));
const res = await copilotGptManifestUtils.getManifestPath("testPath");
chai.assert.isTrue(res.isErr());
if (res.isErr()) {
chai.assert.isTrue(res.error instanceof UserError);
}
});

it("declarativeCopilots error 1", async () => {
sandbox.stub(manifestUtils, "_readAppManifest").resolves(
ok({
copilotExtensions: {},
} as any)
);
const res = await copilotGptManifestUtils.getManifestPath("testPath");
chai.assert.isTrue(res.isErr());
if (res.isErr()) {
chai.assert.isTrue(res.error instanceof UserError);
}
});

it("read Teams manifest error", async () => {
sandbox
.stub(manifestUtils, "_readAppManifest")
Expand Down
Loading

0 comments on commit cd55ff4

Please sign in to comment.