-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dc with api plugin generator & template update (#12104)
* feat: dc with api plugin generator * refactor: more * refactor: template * refactor: templates * refactor: templates * refactor: templates * refactor: templates * test: ut * test: ut * refactor: more * refactor: more * refactor: format * refactor: pr comment * refactor: minor
- Loading branch information
1 parent
2b1b7ed
commit 64f90bb
Showing
31 changed files
with
754 additions
and
262 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
packages/fx-core/src/component/generator/copilotExtensionFromScratch/generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
/** | ||
* @author [email protected] | ||
*/ | ||
|
||
import { Context, FxError, Inputs, ok, Result } from "@microsoft/teamsfx-api"; | ||
import { DefaultTemplateGenerator } from "../templates/templateGenerator"; | ||
import { | ||
ApiAuthOptions, | ||
ApiPluginStartOptions, | ||
CapabilityOptions, | ||
ProgrammingLanguage, | ||
QuestionNames, | ||
} from "../../../question"; | ||
import { ActionContext } from "../../middleware/actionExecutionMW"; | ||
import { Generator } from "../generator"; | ||
import { merge } from "lodash"; | ||
import { TemplateNames } from "../templates/templateNames"; | ||
import { TemplateInfo } from "../templates/templateInfo"; | ||
|
||
const enum telemetryProperties { | ||
templateName = "template-name", | ||
isDeclarativeCopilot = "is-declarative-copilot", | ||
} | ||
|
||
export class CopilotExtensionFromScratchGenerator extends DefaultTemplateGenerator { | ||
componentName = "copilot-extension-from-scratch-generator"; | ||
public activate(context: Context, inputs: Inputs): boolean { | ||
return ( | ||
(inputs[QuestionNames.Capabilities] === CapabilityOptions.declarativeCopilot().id || | ||
inputs[QuestionNames.Capabilities] === CapabilityOptions.apiPlugin().id) && | ||
inputs[QuestionNames.ApiPluginType] === ApiPluginStartOptions.newApi().id | ||
); | ||
} | ||
|
||
public getTemplateInfos( | ||
context: Context, | ||
inputs: Inputs, | ||
destinationPath: string, | ||
actionContext?: ActionContext | ||
): Promise<Result<TemplateInfo[], FxError>> { | ||
const auth = inputs[QuestionNames.ApiAuth]; | ||
const appName = inputs[QuestionNames.AppName]; | ||
const language = inputs[QuestionNames.ProgrammingLanguage] as ProgrammingLanguage; | ||
const safeProjectNameFromVS = | ||
language === "csharp" ? inputs[QuestionNames.SafeProjectName] : undefined; | ||
const isDeclarativeCopilot = | ||
inputs[QuestionNames.Capabilities] === CapabilityOptions.declarativeCopilot().id; | ||
|
||
const replaceMap = { | ||
...Generator.getDefaultVariables( | ||
appName, | ||
safeProjectNameFromVS, | ||
inputs.targetFramework, | ||
inputs.placeProjectFileInSolutionDir === "true" | ||
), | ||
DeclarativeCopilot: isDeclarativeCopilot ? "true" : "", | ||
}; | ||
|
||
const filterFn = (fileName: string) => { | ||
if (fileName.includes("repairDeclarativeCopilot.json")) { | ||
return isDeclarativeCopilot; | ||
} else { | ||
return true; | ||
} | ||
}; | ||
|
||
const templateName = | ||
auth === ApiAuthOptions.apiKey().id | ||
? TemplateNames.ApiPluginFromScratchBearer | ||
: auth === ApiAuthOptions.oauth().id | ||
? TemplateNames.ApiPluginFromScratchOAuth | ||
: TemplateNames.ApiPluginFromScratch; | ||
|
||
merge(actionContext?.telemetryProps, { | ||
[telemetryProperties.templateName]: templateName, | ||
[telemetryProperties.isDeclarativeCopilot]: isDeclarativeCopilot.toString(), | ||
}); | ||
|
||
return Promise.resolve( | ||
ok([ | ||
{ | ||
templateName, | ||
language: language, | ||
replaceMap, | ||
filterFn, | ||
}, | ||
]) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
packages/fx-core/tests/component/generator/copilotExtensionFromScratchGenerator.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
/** | ||
* @author [email protected] | ||
*/ | ||
|
||
import { Inputs, Platform } from "@microsoft/teamsfx-api"; | ||
import { assert } from "chai"; | ||
import "mocha"; | ||
import { createContext } from "../../../src/common/globalVars"; | ||
import { | ||
ApiAuthOptions, | ||
ApiPluginStartOptions, | ||
CapabilityOptions, | ||
QuestionNames, | ||
} from "../../../src/question"; | ||
import { CopilotExtensionFromScratchGenerator } from "../../../src/component/generator/copilotExtensionFromScratch/generator"; | ||
describe("apiPluginFromScratch", async () => { | ||
describe("activate and get template name", async () => { | ||
it("api plugin", async () => { | ||
const generator = new CopilotExtensionFromScratchGenerator(); | ||
const context = createContext(); | ||
const inputs: Inputs = { | ||
platform: Platform.CLI, | ||
projectPath: "./", | ||
[QuestionNames.Capabilities]: CapabilityOptions.apiPlugin().id, | ||
[QuestionNames.ApiPluginType]: ApiPluginStartOptions.newApi().id, | ||
[QuestionNames.ApiAuth]: ApiAuthOptions.none().id, | ||
[QuestionNames.AppName]: "app", | ||
}; | ||
let res = await generator.activate(context, inputs); | ||
let info = await generator.getTemplateInfos(context, inputs, "."); | ||
assert.isTrue(res); | ||
assert.equal(info.isOk() && info.value[0].templateName, "api-plugin-from-scratch"); | ||
|
||
inputs[QuestionNames.ApiAuth] = ApiAuthOptions.apiKey().id; | ||
res = await generator.activate(context, inputs); | ||
info = await generator.getTemplateInfos(context, inputs, "."); | ||
assert.isTrue(res); | ||
assert.equal(info.isOk() && info.value[0].templateName, "api-plugin-from-scratch-bearer"); | ||
|
||
inputs[QuestionNames.ApiAuth] = ApiAuthOptions.oauth().id; | ||
res = await generator.activate(context, inputs); | ||
info = await generator.getTemplateInfos(context, inputs, "."); | ||
assert.isTrue(res); | ||
assert.equal(info.isOk() && info.value[0].templateName, "api-plugin-from-scratch-oauth"); | ||
if (info.isOk()) { | ||
const filterFn = info.value[0].filterFn; | ||
assert.isFalse(filterFn?.("repairDeclarativeCopilot.json")); | ||
assert.isTrue(filterFn?.("test.json")); | ||
} | ||
}); | ||
|
||
it("declarative Copilot", async () => { | ||
const generator = new CopilotExtensionFromScratchGenerator(); | ||
const context = createContext(); | ||
const inputs: Inputs = { | ||
platform: Platform.CLI, | ||
projectPath: "./", | ||
[QuestionNames.Capabilities]: CapabilityOptions.declarativeCopilot().id, | ||
[QuestionNames.ApiPluginType]: ApiPluginStartOptions.newApi().id, | ||
[QuestionNames.ApiAuth]: ApiAuthOptions.none().id, | ||
[QuestionNames.AppName]: "app", | ||
}; | ||
let res = await generator.activate(context, inputs); | ||
let info = await generator.getTemplateInfos(context, inputs, "."); | ||
assert.isTrue(res); | ||
assert.equal(info.isOk() && info.value[0].templateName, "api-plugin-from-scratch"); | ||
|
||
inputs[QuestionNames.ApiAuth] = ApiAuthOptions.apiKey().id; | ||
res = await generator.activate(context, inputs); | ||
info = await generator.getTemplateInfos(context, inputs, "."); | ||
assert.isTrue(res); | ||
assert.equal(info.isOk() && info.value[0].templateName, "api-plugin-from-scratch-bearer"); | ||
|
||
inputs[QuestionNames.ApiAuth] = ApiAuthOptions.oauth().id; | ||
res = await generator.activate(context, inputs); | ||
info = await generator.getTemplateInfos(context, inputs, "."); | ||
assert.isTrue(res); | ||
assert.equal(info.isOk() && info.value[0].templateName, "api-plugin-from-scratch-oauth"); | ||
|
||
if (info.isOk()) { | ||
const filterFn = info.value[0].filterFn; | ||
assert.isTrue(filterFn?.("repairDeclarativeCopilot.json")); | ||
assert.isTrue(filterFn?.("test.json")); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-1.21 KB
(83%)
templates/common/api-plugin-existing-api/appPackage/color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+165 Bytes
(150%)
templates/common/api-plugin-existing-api/appPackage/outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+165 Bytes
(150%)
templates/common/copilot-gpt-basic/appPackage/outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+578 Bytes
(110%)
templates/csharp/message-extension-copilot/appPackage/color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+165 Bytes
(150%)
templates/csharp/message-extension-copilot/appPackage/outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
120 changes: 0 additions & 120 deletions
120
templates/js/api-plugin-from-scratch/.vscode/launch.json
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.