Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(spec-parser): add confirmation for type b plugin #11416

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/spec-parser/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ export interface ParseOptions {
*/
allowResponseSemantics?: boolean;

/**
* If true, the paser will allow confirmation in plugin file. Only take effect in Copilot project
*/
allowConfirmation?: boolean;

/**
* The type of project that the parser is being used for.
* Project can be SME/Copilot/TeamsAi
Expand Down
29 changes: 28 additions & 1 deletion packages/spec-parser/src/manifestUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export class ManifestUpdater {
for (const method in operations) {
if (options.allowMethods!.includes(method)) {
const operationItem = (operations as any)[method] as OpenAPIV3.OperationObject;
const confirmationBodies: string[] = [];
if (operationItem) {
const operationId = operationItem.operationId!;
const description = operationItem.description ?? "";
Expand All @@ -181,6 +182,8 @@ export class ManifestUpdater {
pathUrl
);

confirmationBodies.push(ManifestUpdater.getConfirmationBodyItem(param.name));

if (param.required) {
parameters.required.push(param.name);
}
Expand All @@ -207,6 +210,8 @@ export class ManifestUpdater {
method,
pathUrl
);

confirmationBodies.push(ManifestUpdater.getConfirmationBodyItem(property));
}
} else {
throw new SpecParserError(
Expand All @@ -224,9 +229,12 @@ export class ManifestUpdater {
const funcObj: FunctionObject = {
name: operationId,
description: description,
parameters: parameters,
};

if (paramObject || requestBody) {
funcObj.parameters = parameters;
}

if (options.allowResponseSemantics) {
const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operationItem);
const responseSemantic = wrapResponseSemantics(card, jsonPath);
Expand All @@ -235,6 +243,21 @@ export class ManifestUpdater {
};
}

if (options.allowConfirmation && method !== ConstantString.GetMethod) {
if (!funcObj.capabilities) {
funcObj.capabilities = {};
}

funcObj.capabilities.confirmation = {
type: "AdaptiveCard",
title: operationItem.summary ?? description,
};

if (confirmationBodies.length > 0) {
funcObj.capabilities.confirmation.body = confirmationBodies.join("\n");
}
}

functions.push(funcObj);
functionNames.push(operationId);
if (description) {
Expand Down Expand Up @@ -471,4 +494,8 @@ export class ManifestUpdater {
static removeAllSpecialCharacters(str: string): string {
return str.toLowerCase().replace(/[^a-z0-9]/g, "");
}

static getConfirmationBodyItem(paramName: string): string {
return `* **${Utils.updateFirstLetter(paramName)}**: {{function.parameters.${paramName}}}`;
}
}
1 change: 1 addition & 0 deletions packages/spec-parser/src/specParser.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class SpecParser {
allowMethods: ["get", "post"],
allowConversationStarters: false,
allowResponseSemantics: false,
allowConfirmation: false,
projectType: ProjectType.SME,
};

Expand Down
1 change: 1 addition & 0 deletions packages/spec-parser/src/specParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class SpecParser {
allowMethods: ["get", "post"],
allowConversationStarters: false,
allowResponseSemantics: false,
allowConfirmation: false,
projectType: ProjectType.SME,
};

Expand Down
Loading
Loading