diff --git a/packages/spec-parser/src/manifestUpdater.ts b/packages/spec-parser/src/manifestUpdater.ts index fbd1bb81e3..02af8cf1f5 100644 --- a/packages/spec-parser/src/manifestUpdater.ts +++ b/packages/spec-parser/src/manifestUpdater.ts @@ -182,6 +182,8 @@ export class ManifestUpdater { if (json.schema) { const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operationItem); + + card.body = card.body?.slice(0, 5); const responseSemantic = wrapResponseSemantics(card, jsonPath); funcObj.capabilities = { response_semantics: responseSemantic, diff --git a/packages/spec-parser/test/manifestUpdater.test.ts b/packages/spec-parser/test/manifestUpdater.test.ts index 90dbfbd8da..070c9e48a7 100644 --- a/packages/spec-parser/test/manifestUpdater.test.ts +++ b/packages/spec-parser/test/manifestUpdater.test.ts @@ -282,6 +282,180 @@ describe("updateManifestWithAiPlugin", () => { expect(manifest).to.deep.equal(expectedManifest); expect(apiPlugin).to.deep.equal(expectedPlugins); }); + + it("should keep at most 5 properties in response semantics", async () => { + const spec: any = { + openapi: "3.0.2", + info: { + title: "My API", + description: "My API description", + }, + servers: [ + { + url: "/v3", + }, + ], + paths: { + "/pets": { + get: { + operationId: "getPets", + summary: "Get all pets", + description: "Returns all pets from the system that the user has access to", + parameters: [ + { + name: "limit", + description: "Maximum number of pets to return", + required: true, + schema: { + type: "integer", + }, + }, + ], + responses: { + 200: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + name: { + type: "string", + }, + description: { + type: "string", + }, + imageUrl: { + type: "string", + }, + id: { + type: "string", + }, + age: { + type: "string", + }, + status: { + type: "string", + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }; + const manifestPath = "/path/to/your/manifest.json"; + const outputSpecPath = "/path/to/your/spec/outputSpec.yaml"; + const pluginFilePath = "/path/to/your/ai-plugin.json"; + + const originalManifest = { + name: { short: "Original Name", full: "Original Full Name" }, + description: { short: "Original Short Description", full: "Original Full Description" }, + }; + const expectedManifest = { + name: { short: "Original Name", full: "Original Full Name" }, + description: { short: "My API", full: "My API description" }, + copilotExtensions: { + plugins: [ + { + file: "ai-plugin.json", + id: "plugin_1", + }, + ], + }, + }; + + const expectedPlugins: PluginManifestSchema = { + schema_version: "v2.1", + name_for_human: "Original Name", + namespace: "originalname", + description_for_human: "My API description", + functions: [ + { + name: "getPets", + description: "Returns all pets from the system that the user has access to", + capabilities: { + response_semantics: { + data_path: "$", + properties: { + subtitle: "$.description", + title: "$.name", + url: "$.imageUrl", + }, + static_template: { + $schema: "http://adaptivecards.io/schemas/adaptive-card.json", + body: [ + { + text: "name: ${if(name, name, 'N/A')}", + type: "TextBlock", + wrap: true, + }, + { + text: "description: ${if(description, description, 'N/A')}", + type: "TextBlock", + wrap: true, + }, + { + $when: "${imageUrl != null}", + type: "Image", + url: "${imageUrl}", + }, + { + text: "id: ${if(id, id, 'N/A')}", + type: "TextBlock", + wrap: true, + }, + { + text: "age: ${if(age, age, 'N/A')}", + type: "TextBlock", + wrap: true, + }, + ], + type: "AdaptiveCard", + version: "1.5", + }, + }, + }, + }, + ], + runtimes: [ + { + type: "OpenApi", + auth: { + type: "None", + }, + spec: { + url: "spec/outputSpec.yaml", + }, + run_for_functions: ["getPets"], + }, + ], + }; + sinon.stub(fs, "readJSON").resolves(originalManifest); + sinon + .stub(fs, "pathExists") + .withArgs(manifestPath) + .resolves(true) + .withArgs(pluginFilePath) + .resolves(false); + + const options: ParseOptions = { + allowMethods: ["get", "post"], + allowResponseSemantics: true, + }; + const [manifest, apiPlugin] = await ManifestUpdater.updateManifestWithAiPlugin( + manifestPath, + outputSpecPath, + pluginFilePath, + spec, + options + ); + + expect(manifest).to.deep.equal(expectedManifest); + expect(apiPlugin).to.deep.equal(expectedPlugins); + }); }); describe("auth", () => {