Skip to content

Commit

Permalink
fix: manifest update
Browse files Browse the repository at this point in the history
refactor: file forget to add

test: ut

test: ut

test: ut

test: ut

test: ut

refactor: minor

test: ut

refactor: more
  • Loading branch information
yuqizhou77 committed May 8, 2024
1 parent 8fd2a40 commit 59d50ce
Show file tree
Hide file tree
Showing 20 changed files with 476 additions and 353 deletions.
2 changes: 1 addition & 1 deletion packages/fx-core/src/common/m365/packageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class PackageService {
"MeetingExtensionDefinition",
"OpenAIPlugins",
"Gpts",
"DeclarativeCopilots ",
"DeclarativeCopilots",
"Plugins",
],
},
Expand Down
7 changes: 5 additions & 2 deletions packages/fx-core/src/common/projectTypeChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,13 @@ export function getCapabilities(manifest: any): string[] {
if (manifest.extensions && manifest.extensions.length > 0) {
capabilities.push("extension");
}
if (manifest.plugins && manifest.plugins.length > 0) {
if (manifest.copilotExtensions?.plugins && manifest.copilotExtensions.plugins.length > 0) {
capabilities.push("plugin");
}
if (manifest.copilotGpts && manifest.copilotGpts.length > 0) {
if (
manifest.copilotExtensions?.declarativeCopilots &&
manifest.copilotExtensions.declarativeCopilots > 0
) {
capabilities.push("copilotGpt");
}
return capabilities;
Expand Down
20 changes: 9 additions & 11 deletions packages/fx-core/src/component/driver/teamsApp/createAppPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,20 @@ export class CreateAppPackageDriver implements StepDriver {
}
}

const plugins = manifest.copilotExtensions?.plugins;
// API plugin
if (manifest.plugins && manifest.plugins.length > 0 && manifest.plugins[0].file) {
const addFilesRes = await this.addPlugin(
zip,
manifest.plugins[0].file,
appDirectory,
context
);
if (plugins?.length && plugins[0].file) {
const addFilesRes = await this.addPlugin(zip, plugins[0].file, appDirectory, context);
if (addFilesRes.isErr()) {
return err(addFilesRes.error);
}
}

const declarativeCopilots = manifest.copilotExtensions?.declarativeCopilots;

// Copilot GPT
if (manifest.copilotGpts && manifest.copilotGpts.length > 0 && manifest.copilotGpts[0].file) {
const copilotGptManifestFile = path.resolve(appDirectory, manifest.copilotGpts[0].file);
if (declarativeCopilots?.length && declarativeCopilots[0].file) {
const copilotGptManifestFile = path.resolve(appDirectory, declarativeCopilots[0].file);
const checkExistenceRes = await this.validateReferencedFile(
copilotGptManifestFile,
appDirectory
Expand All @@ -244,7 +242,7 @@ export class CreateAppPackageDriver implements StepDriver {

const addFileWithVariableRes = await this.addFileWithVariable(
zip,
manifest.copilotGpts[0].file,
declarativeCopilots[0].file,
copilotGptManifestFile,
TelemetryPropertyKey.customizedAIPluginKeys,
context
Expand All @@ -268,7 +266,7 @@ export class CreateAppPackageDriver implements StepDriver {
);

const pluginFileRelativePath = path.relative(appDirectory, pluginFileAbsolutePath);
const useForwardSlash = manifest.copilotGpts[0].file.concat(pluginFile).includes("/");
const useForwardSlash = declarativeCopilots[0].file.concat(pluginFile).includes("/");

const addPluginRes = await this.addPlugin(
zip,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { FxError, Result, err, ok, CopilotGptManifestSchema } from "@microsoft/teamsfx-api";
import { FxError, Result, err, ok, DeclarativeCopilotManifestSchema } from "@microsoft/teamsfx-api";
import fs from "fs-extra";
import { FileNotFoundError, JSONSyntaxError, WriteFileError } from "../../../../error/common";
import stripBom from "strip-bom";

export class CopilotGptManifestUtils {
public async readCopilotGptManifestFile(
path: string
): Promise<Result<CopilotGptManifestSchema, FxError>> {
): Promise<Result<DeclarativeCopilotManifestSchema, FxError>> {
if (!(await fs.pathExists(path))) {
return err(new FileNotFoundError("CopilotGptManifestUtils", path));
}
Expand All @@ -19,15 +19,15 @@ export class CopilotGptManifestUtils {
content = stripBom(content);

try {
const manifest = JSON.parse(content) as CopilotGptManifestSchema;
const manifest = JSON.parse(content) as DeclarativeCopilotManifestSchema;
return ok(manifest);
} catch (e) {
return err(new JSONSyntaxError(path, e, "CopilotGptManifestUtils"));
}
}

public async writeCopilotGptManifestFile(
manifest: CopilotGptManifestSchema,
manifest: DeclarativeCopilotManifestSchema,
path: string
): Promise<Result<undefined, FxError>> {
const content = JSON.stringify(manifest, undefined, 4);
Expand All @@ -43,7 +43,7 @@ export class CopilotGptManifestUtils {
copilotGptPath: string,
id: string,
pluginFile: string
): Promise<Result<CopilotGptManifestSchema, FxError>> {
): Promise<Result<DeclarativeCopilotManifestSchema, FxError>> {
const gptManifestRes = await copilotGptManifestUtils.readCopilotGptManifestFile(copilotGptPath);
if (gptManifestRes.isErr()) {
return err(gptManifestRes.error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class ManifestUtils {
manifest: TeamsAppManifest,
manifestPath: string
): Promise<Result<string, FxError>> {
const pluginFile = manifest.plugins?.[0]?.file;
const pluginFile = manifest.copilotExtensions?.plugins?.[0]?.file;
if (pluginFile) {
const plugin = path.resolve(path.dirname(manifestPath), pluginFile);
const doesFileExist = await fs.pathExists(plugin);
Expand Down
18 changes: 13 additions & 5 deletions packages/fx-core/src/core/FxCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1536,15 +1536,19 @@ export class FxCore {
}

const teamsManifest = manifestRes.value;
if (!teamsManifest.copilotGpts?.[0].file) {
const declarativeGpt = teamsManifest.copilotExtensions?.declarativeCopilots?.[0];
if (!declarativeGpt?.file) {
return err(
AppStudioResultFactory.UserError(
AppStudioError.TeamsAppRequiredPropertyMissingError.name,
AppStudioError.TeamsAppRequiredPropertyMissingError.message("copilotGpts", manifestPath)
AppStudioError.TeamsAppRequiredPropertyMissingError.message(
"declarativeCopilots",
manifestPath
)
)
);
}
const gptManifestFilePath = path.join(appPackageFolder, teamsManifest.copilotGpts[0].file);
const gptManifestFilePath = path.join(appPackageFolder, declarativeGpt.file);
const gptManifestRes = await copilotGptManifestUtils.readCopilotGptManifestFile(
gptManifestFilePath
);
Expand Down Expand Up @@ -1638,11 +1642,15 @@ export class FxCore {

// update Teams manifest
if (needAddCopilotPlugin) {
teamsManifest.plugins = teamsManifest.plugins || [];
teamsManifest.plugins.push({
const plugins = teamsManifest.copilotExtensions?.plugins || [];
plugins.push({
id: "plugin_1", // Teams manifest can have only one plugin.
file: pluginManifestName,
});
teamsManifest.copilotExtensions = {
...teamsManifest.copilotExtensions,
plugins,
};
const updateManifestRes = await manifestUtils._writeAppManifest(teamsManifest, manifestPath);
if (updateManifestRes.isErr()) {
return err(updateManifestRes.error);
Expand Down
2 changes: 1 addition & 1 deletion packages/fx-core/src/question/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ export function selectPluginAvailabilityQuestion(): SingleSelectQuestion {
throw AppStudioResultFactory.UserError(
AppStudioError.TeamsAppRequiredPropertyMissingError.name,
AppStudioError.TeamsAppRequiredPropertyMissingError.message(
"copilotGpts",
"declarativeCopilots",
teamsManifestPath
)
);
Expand Down
6 changes: 4 additions & 2 deletions packages/fx-core/tests/common/projectTypeChecker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ describe("ProjectTypeChecker", () => {
bots: [1],
composeExtensions: [1],
extensions: [1],
plugins: [1],
copilotGpts: [1],
copilotExtensions: {
plugins: [1],
declarativeCopilots: [1],
},
};
const capabilities = getCapabilities(manifest);
assert.deepEqual(capabilities, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "mocha";
import * as sinon from "sinon";
import chai from "chai";
import fs from "fs-extra";
import { CopilotGptManifestSchema } from "@microsoft/teamsfx-api";
import { DeclarativeCopilotManifestSchema } from "@microsoft/teamsfx-api";
import { copilotGptManifestUtils } from "../../../../src/component/driver/teamsApp/utils/CopilotGptManifestUtils";
import { FileNotFoundError, WriteFileError } from "../../../../src/error";

Expand All @@ -16,7 +16,7 @@ describe("copilotGptManifestUtils", () => {
sandbox.restore();
});

const gptManifest: CopilotGptManifestSchema = {
const gptManifest: DeclarativeCopilotManifestSchema = {
name: "name",
description: "description",
};
Expand Down
Loading

0 comments on commit 59d50ce

Please sign in to comment.