Skip to content

Commit

Permalink
Merge pull request #12379 from OfficeDev/main
Browse files Browse the repository at this point in the history
build: prerelease Sep 04
  • Loading branch information
MSFT-yiz authored Sep 12, 2024
2 parents bc1eb6c + fddd364 commit ea03ef7
Show file tree
Hide file tree
Showing 93 changed files with 870 additions and 289 deletions.
2 changes: 1 addition & 1 deletion packages/api/src/qm/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export interface SingleSelectQuestion extends UserInputQuestion {
* if true: single select question will be automatically answered with the single option;
* if false: use still need to do the selection manually even there is no other choice.
*/
skipSingleOption?: boolean;
skipSingleOption?: boolean | LocalFunc<boolean>;

/**
* the command is only for CLI option description
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export interface CreateProjectResult {
warnings?: Warning[];
shouldInvokeTeamsAgent?: boolean;
projectId?: string;
createProjectForKiota?: boolean;
lastCommand?: string;
}

export interface TeamsAppInputs extends InputsWithProjectPath {
Expand Down
7 changes: 1 addition & 6 deletions packages/cli/src/commands/models/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ import { CLICommand } from "@microsoft/teamsfx-api";
import { commands } from "../../resource";
import { addSPFxWebpartCommand } from "./addSPFxWebpart";
import { addPluginCommand } from "./addPlugin";
import { isCopilotExtensionEnabled } from "@microsoft/teamsfx-core";

const adjustCommands = (): CLICommand[] => {
if (isCopilotExtensionEnabled()) {
return [addSPFxWebpartCommand, addPluginCommand];
} else {
return [addSPFxWebpartCommand];
}
return [addSPFxWebpartCommand, addPluginCommand];
};
export function addCommand(): CLICommand {
return {
Expand Down
21 changes: 10 additions & 11 deletions packages/cli/src/commands/models/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
CliQuestionName,
CreateProjectInputs,
CreateProjectOptions,
isCopilotExtensionEnabled,
MeArchitectureOptions,
QuestionNames,
} from "@microsoft/teamsfx-core";
Expand Down Expand Up @@ -45,16 +44,16 @@ function adjustOptions(options: CLICommandOption[]) {
}
}

if (!isCopilotExtensionEnabled()) {
//skip Copilot extension questions if the feature flag is not enabled.
const questionsToDelete = [
QuestionNames.ApiPluginType,
QuestionNames.WithPlugin,
QuestionNames.PluginManifestFilePath,
QuestionNames.PluginOpenApiSpecFilePath,
];
options = options.filter((option) => !questionsToDelete.includes(option.name as QuestionNames));
}
// if (!isCopilotExtensionEnabled()) {
// //skip Copilot extension questions if the feature flag is not enabled.
// const questionsToDelete = [
// QuestionNames.ApiPluginType,
// QuestionNames.WithPlugin,
// QuestionNames.PluginManifestFilePath,
// QuestionNames.PluginOpenApiSpecFilePath,
// ];
// options = options.filter((option) => !questionsToDelete.includes(option.name as QuestionNames));
// }

return options;
}
Expand Down
34 changes: 0 additions & 34 deletions packages/cli/tests/unit/commands.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,40 +99,6 @@ describe("CLI commands", () => {
telemetryProperties: {},
};

const filteredQuestionNames = [
QuestionNames.WithPlugin.toString(),
QuestionNames.ApiPluginType.toString(),
];
assert.isTrue(
ctx.command.options?.filter((o) => filteredQuestionNames.includes(o.name)).length === 0
);

const res = await getCreateCommand().handler!(ctx);
assert.isTrue(res.isOk());
});

it("createProjectOptions - need to adjust options when feature flag is enabled", async () => {
mockedEnvRestore = mockedEnv({
[FeatureFlags.CopilotExtension.name]: "true",
});
sandbox.stub(activate, "getFxCore").returns(new FxCore({} as any));
sandbox.stub(FxCore.prototype, "createProject").resolves(ok({ projectPath: "..." }));

const ctx: CLIContext = {
command: { ...getCreateCommand(), fullName: "new" },
optionValues: {},
globalOptionValues: {},
argumentValues: [],
telemetryProperties: {},
};

const filteredQuestionNames = [
QuestionNames.WithPlugin.toString(),
QuestionNames.ApiPluginType.toString(),
];
assert.isTrue(
ctx.command.options?.filter((o) => filteredQuestionNames.includes(o.name)).length === 2
);
const res = await getCreateCommand().handler!(ctx);
assert.isTrue(res.isOk());
});
Expand Down
13 changes: 6 additions & 7 deletions packages/fx-core/src/common/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export class FeatureFlagName {
static readonly OfficeMetaOS = "TEAMSFX_OFFICE_METAOS";
static readonly CopilotExtension = "DEVELOP_COPILOT_EXTENSION";
static readonly CopilotPlugin = "DEVELOP_COPILOT_PLUGIN";
static readonly DeclarativeCopilot = "TEAMSFX_DECLARATIVE_COPILOT";
static readonly SampleConfigBranch = "TEAMSFX_SAMPLE_CONFIG_BRANCH";
static readonly TestTool = "TEAMSFX_TEST_TOOL";
static readonly METestTool = "TEAMSFX_ME_TEST_TOOL";
Expand All @@ -33,6 +32,7 @@ export class FeatureFlagName {
static readonly SyncManifest = "TEAMSFX_SYNC_MANIFEST";
static readonly EnvFileFunc = "TEAMSFX_ENV_FILE_FUNC";
static readonly KiotaIntegration = "TEAMSFX_KIOTA_INTEGRATION";
static readonly ApiPluginAAD = "TEAMSFX_API_PLUGIN_AAD";
}

export interface FeatureFlag {
Expand All @@ -51,10 +51,6 @@ export class FeatureFlags {
name: FeatureFlagName.CopilotPlugin,
defaultValue: "false",
}; // old feature flag. Keep it for backwards compatibility.
static readonly DeclarativeCopilot = {
name: FeatureFlagName.DeclarativeCopilot,
defaultValue: "false",
}; // old feature flag. Keep it for backwards compatibility.
static readonly TestTool = { name: FeatureFlagName.TestTool, defaultValue: "true" };
static readonly METestTool = { name: FeatureFlagName.METestTool, defaultValue: "true" };
static readonly OfficeAddin = { name: FeatureFlagName.OfficeAddin, defaultValue: "false" };
Expand Down Expand Up @@ -104,13 +100,16 @@ export class FeatureFlags {
name: FeatureFlagName.KiotaIntegration,
defaultValue: "false",
};
static readonly ApiPluginAAD = {
name: FeatureFlagName.ApiPluginAAD,
defaultValue: "false",
};
}

export function isCopilotExtensionEnabled(): boolean {
return (
featureFlagManager.getBooleanValue(FeatureFlags.CopilotExtension) ||
featureFlagManager.getBooleanValue(FeatureFlags.CopilotPlugin) ||
featureFlagManager.getBooleanValue(FeatureFlags.DeclarativeCopilot)
featureFlagManager.getBooleanValue(FeatureFlags.CopilotPlugin)
);
}

Expand Down
5 changes: 5 additions & 0 deletions packages/fx-core/src/component/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,8 @@ export enum BotScenario {
export const AadConstants = {
DefaultTemplateFileName: "aad.manifest.json",
};

export const KiotaLastCommands = {
createPluginWithManifest: "createPluginWithManifest",
createDeclarativeCopilotWithManifest: "createDeclarativeCopilotWithManifest",
};
13 changes: 10 additions & 3 deletions packages/fx-core/src/component/coordinator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ import { LifeCycleUndefinedError } from "../../error/yml";
import {
ApiPluginStartOptions,
AppNamePattern,
CapabilityOptions,
ProjectTypeOptions,
QuestionNames,
ScratchOptions,
} from "../../question/constants";
import { ExecutionError, ExecutionOutput, ILifecycle } from "../configManager/interface";
import { Lifecycle } from "../configManager/lifecycle";
import { CoordinatorSource } from "../constants";
import { CoordinatorSource, KiotaLastCommands } from "../constants";
import { deployUtils } from "../deployUtils";
import { developerPortalScaffoldUtils } from "../developerPortalScaffoldUtils";
import { DriverContext } from "../driver/interface/commonArgs";
Expand Down Expand Up @@ -97,9 +98,15 @@ class Coordinator {
inputs.platform === Platform.VSCode &&
featureFlagManager.getBooleanValue(FeatureFlags.KiotaIntegration) &&
inputs[QuestionNames.ApiPluginType] === ApiPluginStartOptions.apiSpec().id &&
!inputs[QuestionNames.ApiPluginManifestPath]
!inputs[QuestionNames.ApiPluginManifestPath] &&
(inputs[QuestionNames.Capabilities] === CapabilityOptions.apiPlugin().id ||
inputs[QuestionNames.Capabilities] === CapabilityOptions.declarativeCopilot().id)
) {
return ok({ projectPath: "", createProjectForKiota: true });
const lastCommand =
inputs[QuestionNames.Capabilities] === CapabilityOptions.apiPlugin().id
? KiotaLastCommands.createPluginWithManifest
: KiotaLastCommands.createDeclarativeCopilotWithManifest;
return ok({ projectPath: "", lastCommand: lastCommand });
}

let folder = inputs["folder"] as string;
Expand Down
25 changes: 25 additions & 0 deletions packages/fx-core/src/component/generator/apiSpec/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ResponseTemplatesFolderName,
Result,
SystemError,
UserError,
Warning,
err,
ok,
Expand Down Expand Up @@ -56,6 +57,7 @@ import {
generateScaffoldingSummary,
getEnvName,
getParserOptions,
listOperations,
updateForCustomApi,
} from "./helper";
import { copilotGptManifestUtils } from "../../driver/teamsApp/utils/CopilotGptManifestUtils";
Expand Down Expand Up @@ -167,6 +169,29 @@ export class SpecGenerator extends DefaultTemplateGenerator {
[telemetryProperties.templateName]: getTemplateInfosState.templateName,
[telemetryProperties.isDeclarativeCopilot]: isDeclarativeCopilot.toString(),
});

// For Kiota integration, we need to get auth info here
if (
featureFlagManager.getBooleanValue(FeatureFlags.KiotaIntegration) &&
inputs[QuestionNames.ApiPluginManifestPath]
) {
const operationsResult = await listOperations(
context,
inputs[QuestionNames.ApiSpecLocation],
inputs
);
if (operationsResult.isErr()) {
const msg = operationsResult.error.map((e) => e.content).join("\n");
return err(new UserError("generator", "ListOperationsFailed", msg));
}

const operations = operationsResult.value;
const authApi = operations.find((api) => !!api.data.authName);
if (authApi) {
authData = authApi.data;
}
}

const appName = inputs[QuestionNames.AppName];
let language = inputs[QuestionNames.ProgrammingLanguage] as ProgrammingLanguage;
if (getTemplateInfosState.templateName !== forCustomCopilotRagCustomApi) {
Expand Down
1 change: 1 addition & 0 deletions packages/fx-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,4 @@ export * from "./question/options";
export * from "./component/middleware/actionExecutionMW";
export { TemplateInfo } from "./component/generator/templates/templateInfo";
export { AadSet } from "./common/globalVars";
export { KiotaLastCommands } from "./component/constants";
15 changes: 9 additions & 6 deletions packages/fx-core/src/question/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,16 @@ export class CapabilityOptions {
return items;
}

static copilotExtensions(inputs?: Inputs): OptionItem[] {
static copilotExtensions(inputs?: Inputs, isStatic?: boolean): OptionItem[] {
if (isStatic) {
return [CapabilityOptions.apiPlugin(), CapabilityOptions.declarativeCopilot()];
}
if (inputs && getRuntime(inputs) === RuntimeOptions.DotNet().id) {
return [CapabilityOptions.apiPlugin()];
} else {
} else if (isCopilotExtensionEnabled()) {
return [CapabilityOptions.apiPlugin(), CapabilityOptions.declarativeCopilot()];
} else {
return [CapabilityOptions.declarativeCopilot()];
}
}

Expand Down Expand Up @@ -654,7 +659,7 @@ export class CapabilityOptions {
...CapabilityOptions.bots(inputs),
...CapabilityOptions.tabs(),
...CapabilityOptions.collectMECaps(),
...CapabilityOptions.copilotExtensions(inputs),
...CapabilityOptions.copilotExtensions(inputs, true),
...CapabilityOptions.customCopilots(),
...CapabilityOptions.tdpIntegrationCapabilities(),
];
Expand All @@ -674,9 +679,7 @@ export class CapabilityOptions {
...CapabilityOptions.tabs(),
...CapabilityOptions.collectMECaps(),
];
if (isCopilotExtensionEnabled()) {
capabilityOptions.push(...CapabilityOptions.copilotExtensions());
}
capabilityOptions.push(...CapabilityOptions.copilotExtensions());
capabilityOptions.push(...CapabilityOptions.customCopilots());
if (featureFlagManager.getBooleanValue(FeatureFlags.TdpTemplateCliTest)) {
// test templates that are used by TDP integration only
Expand Down
Loading

0 comments on commit ea03ef7

Please sign in to comment.