Skip to content

Commit

Permalink
fix: copilot agents naming
Browse files Browse the repository at this point in the history
  • Loading branch information
anchenyi committed Sep 27, 2024
1 parent 36df05c commit f5c09e2
Show file tree
Hide file tree
Showing 17 changed files with 950 additions and 16 deletions.
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();
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 @@ -315,7 +315,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
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 f5c09e2

Please sign in to comment.