Skip to content

Commit

Permalink
perf(type-b): warning instead error when generate AC failed
Browse files Browse the repository at this point in the history
  • Loading branch information
SLdragon committed May 13, 2024
1 parent 7fc6b78 commit 4167473
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 43 deletions.
39 changes: 24 additions & 15 deletions packages/spec-parser/src/manifestUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ManifestUpdater {
spec: OpenAPIV3.Document,
options: ParseOptions,
authInfo?: AuthInfo
): Promise<[TeamsAppManifest, PluginManifestSchema]> {
): Promise<[TeamsAppManifest, PluginManifestSchema, WarningResult[]]> {
const manifest: TeamsAppManifest = await fs.readJSON(manifestPath);
const apiPluginRelativePath = ManifestUpdater.getRelativePath(manifestPath, apiPluginFilePath);
manifest.copilotExtensions = manifest.copilotExtensions || {};
Expand All @@ -53,7 +53,7 @@ export class ManifestUpdater {
const appName = this.removeEnvs(manifest.name.short);

const specRelativePath = ManifestUpdater.getRelativePath(manifestPath, outputSpecPath);
const apiPlugin = await ManifestUpdater.generatePluginManifestSchema(
const [apiPlugin, warnings] = await ManifestUpdater.generatePluginManifestSchema(
spec,
specRelativePath,
apiPluginFilePath,
Expand All @@ -62,7 +62,7 @@ export class ManifestUpdater {
options
);

return [manifest, apiPlugin];
return [manifest, apiPlugin, warnings];
}

static updateManifestDescription(manifest: TeamsAppManifest, spec: OpenAPIV3.Document): void {
Expand Down Expand Up @@ -99,7 +99,8 @@ export class ManifestUpdater {
appName: string,
authInfo: AuthInfo | undefined,
options: ParseOptions
): Promise<PluginManifestSchema> {
): Promise<[PluginManifestSchema, WarningResult[]]> {
const warnings: WarningResult[] = [];
const functions: FunctionObject[] = [];
const functionNames: string[] = [];
const conversationStarters: string[] = [];
Expand Down Expand Up @@ -178,16 +179,24 @@ export class ManifestUpdater {
};

if (options.allowResponseSemantics) {
const { json } = Utils.getResponseJson(operationItem);
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,
};
try {
const { json } = Utils.getResponseJson(operationItem);
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,
};
}
} catch (err) {
warnings.push({
type: WarningType.GenerateCardFailed,
content: (err as Error).toString(),
data: operationId,
});
}
}

Expand Down Expand Up @@ -292,7 +301,7 @@ export class ManifestUpdater {
}
}

return apiPlugin;
return [apiPlugin, warnings];
}

static async updateManifest(
Expand Down
19 changes: 11 additions & 8 deletions packages/spec-parser/src/specParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,17 @@ export class SpecParser {
throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
}

const [updatedManifest, apiPlugin] = await ManifestUpdater.updateManifestWithAiPlugin(
manifestPath,
outputSpecPath,
pluginFilePath,
newSpec,
this.options,
authInfo
);
const [updatedManifest, apiPlugin, warnings] =
await ManifestUpdater.updateManifestWithAiPlugin(
manifestPath,
outputSpecPath,
pluginFilePath,
newSpec,
this.options,
authInfo
);

result.warnings.push(...warnings);

await fs.outputJSON(manifestPath, updatedManifest, { spaces: 4 });
await fs.outputJSON(pluginFilePath, apiPlugin, { spaces: 4 });
Expand Down
Loading

0 comments on commit 4167473

Please sign in to comment.