From c92f9983aa676861f9a8c42175d7cf074ba61563 Mon Sep 17 00:00:00 2001 From: Cecilia Avila <44245136+ceciliaavila@users.noreply.github.com> Date: Fri, 22 Nov 2024 11:41:37 -0300 Subject: [PATCH] fix: [#4684] ESLint issues in botbuilder-ai (#4790) * Fix eslint issues in botbuilder-ai * Add build step to lint GitHub action --- .github/workflows/lint.yml | 3 ++ libraries/botbuilder-ai/eslint.config.cjs | 11 ----- libraries/botbuilder-ai/package.json | 3 +- libraries/botbuilder-ai/src/custom.window.ts | 2 +- .../src/customQuestionAnswering.ts | 20 ++++----- libraries/botbuilder-ai/src/globals.ts | 6 +-- libraries/botbuilder-ai/src/instanceData.ts | 2 +- libraries/botbuilder-ai/src/intentData.ts | 2 +- .../src/luisAdaptivePredictionOptions.ts | 3 +- .../src/luisAdaptiveRecognizer.ts | 8 ++-- .../botbuilder-ai/src/luisBotComponent.ts | 2 +- libraries/botbuilder-ai/src/luisRecognizer.ts | 25 ++++++----- .../src/luisRecognizerOptions.ts | 5 ++- .../src/luisRecognizerOptionsV2.ts | 35 ++++++--------- .../src/luisRecognizerOptionsV3.ts | 8 ++-- libraries/botbuilder-ai/src/luisSchema.d.ts | 2 +- .../src/luisV2-models/luisPrediction.ts | 8 ++-- libraries/botbuilder-ai/src/qnaCardBuilder.ts | 4 +- libraries/botbuilder-ai/src/qnaMaker.ts | 26 +++++------ .../botbuilder-ai/src/qnaMakerBotComponent.ts | 2 +- libraries/botbuilder-ai/src/qnaMakerDialog.ts | 43 +++++++++---------- .../botbuilder-ai/src/qnaMakerRecognizer.ts | 12 +++--- .../src/qnamaker-interfaces/qnamakerPrompt.ts | 2 +- .../src/qnamaker-interfaces/qnamakerResult.ts | 2 +- .../qnamaker-interfaces/qnamakerTraceInfo.ts | 4 +- .../src/qnamaker-utils/activeLearningUtils.ts | 4 +- .../src/qnamaker-utils/bindToActivity.ts | 1 - .../src/qnamaker-utils/generateAnswerUtils.ts | 27 ++++++------ .../src/qnamaker-utils/httpRequestUtils.ts | 4 +- .../qnamaker-utils/languageServiceUtils.ts | 18 ++++---- .../tests/languageService.test.js | 22 +++++----- .../tests/luisRecognizer.test.js | 40 ++++++++--------- libraries/botbuilder-ai/tests/luisSdk.test.js | 10 ++++- .../tests/luisV3OracleTests.test.js | 8 ++-- .../botbuilder-ai/tests/qnaMaker.test.js | 28 ++++++------ .../tests/qnaMakerDialog.test.js | 24 +++++------ .../tests/qnaMakerRecognizer.test.js | 2 +- 37 files changed, 209 insertions(+), 219 deletions(-) delete mode 100644 libraries/botbuilder-ai/eslint.config.cjs diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 66438a7fd4..11c8564e67 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -38,5 +38,8 @@ jobs: - name: yarn run: yarn --frozen-lockfile + - name: yarn build + run: yarn build + - name: yarn lint run: yarn lint diff --git a/libraries/botbuilder-ai/eslint.config.cjs b/libraries/botbuilder-ai/eslint.config.cjs deleted file mode 100644 index c56fd90ec6..0000000000 --- a/libraries/botbuilder-ai/eslint.config.cjs +++ /dev/null @@ -1,11 +0,0 @@ -const onlyWarn = require("eslint-plugin-only-warn"); -const sharedConfig = require("../../eslint.config.cjs") - -module.exports = [ - ...sharedConfig, - { - plugins: { - "only-warn": onlyWarn, - }, - } -] diff --git a/libraries/botbuilder-ai/package.json b/libraries/botbuilder-ai/package.json index 89baf54afc..01c382a39f 100644 --- a/libraries/botbuilder-ai/package.json +++ b/libraries/botbuilder-ai/package.json @@ -34,7 +34,6 @@ "botbuilder-dialogs-adaptive-runtime-core": "4.1.6", "botbuilder-dialogs-declarative": "4.1.6", "botframework-connector": "4.1.6", - "eslint-plugin-only-warn": "^1.1.0", "lodash": "^4.17.21", "node-fetch": "^2.7.0", "url-parse": "^1.5.10", @@ -51,7 +50,7 @@ "build:rollup": "yarn clean && yarn build && api-extractor run --verbose --local", "clean": "rimraf _ts3.4 lib tsconfig.tsbuildinfo", "depcheck": "depcheck --config ../../.depcheckrc", - "lint": "eslint .", + "lint": "eslint . --config ../../eslint.config.cjs", "postbuild": "downlevel-dts lib _ts3.4/lib --checksum", "test": "npm-run-all build test:mocha", "test:mocha": "nyc mocha tests", diff --git a/libraries/botbuilder-ai/src/custom.window.ts b/libraries/botbuilder-ai/src/custom.window.ts index 4e48cd248d..de0985b441 100644 --- a/libraries/botbuilder-ai/src/custom.window.ts +++ b/libraries/botbuilder-ai/src/custom.window.ts @@ -7,7 +7,7 @@ */ declare global { - interface Window {} // eslint-disable-line @typescript-eslint/no-empty-interface + interface Window {} // eslint-disable-line @typescript-eslint/no-empty-object-type } export type window = Window; diff --git a/libraries/botbuilder-ai/src/customQuestionAnswering.ts b/libraries/botbuilder-ai/src/customQuestionAnswering.ts index b1a8023139..53a1b08af0 100644 --- a/libraries/botbuilder-ai/src/customQuestionAnswering.ts +++ b/libraries/botbuilder-ai/src/customQuestionAnswering.ts @@ -43,7 +43,7 @@ export interface QnAMakerClient { turnContext: TurnContext, options?: QnAMakerOptions, telemetryProperties?: Record, - telemetryMetrics?: Record + telemetryMetrics?: Record, ): Promise; /** @@ -59,7 +59,7 @@ export interface QnAMakerClient { turnContext: TurnContext, options?: QnAMakerOptions, telemetryProperties?: Record, - telemetryMetrics?: Record + telemetryMetrics?: Record, ): Promise; /** @@ -111,7 +111,7 @@ export interface QnAMakerTelemetryClient { context: TurnContext, options?: QnAMakerOptions, telemetryProperties?: { [key: string]: string }, - telemetryMetrics?: { [key: string]: number } + telemetryMetrics?: { [key: string]: number }, ): Promise; } @@ -142,7 +142,7 @@ export class CustomQuestionAnswering implements QnAMakerClient, QnAMakerTelemetr private readonly endpoint: QnAMakerEndpoint, options: QnAMakerOptions = {}, telemetryClient?: BotTelemetryClient, - logPersonalInformation?: boolean + logPersonalInformation?: boolean, ) { if (!endpoint) { throw new TypeError('QnAMaker requires valid QnAMakerEndpoint.'); @@ -215,7 +215,7 @@ export class CustomQuestionAnswering implements QnAMakerClient, QnAMakerTelemetr context: TurnContext, options?: QnAMakerOptions, telemetryProperties?: { [key: string]: string }, - telemetryMetrics?: { [key: string]: number } + telemetryMetrics?: { [key: string]: number }, ): Promise { if (!context) { throw new TypeError('QnAMaker.getAnswers() requires a TurnContext.'); @@ -243,7 +243,7 @@ export class CustomQuestionAnswering implements QnAMakerClient, QnAMakerTelemetr context: TurnContext, options: QnAMakerOptions, telemetryProperties: { [key: string]: string }, - telemetryMetrics: { [key: string]: number } + telemetryMetrics: { [key: string]: number }, ): Promise { if (!context) { throw new TypeError('CustomQuestionAnswering.getAnswersRaw() requires a TurnContext.'); @@ -266,7 +266,7 @@ export class CustomQuestionAnswering implements QnAMakerClient, QnAMakerTelemetr context: TurnContext, options: QnAMakerOptions, telemetryProperties: { [key: string]: string }, - telemetryMetrics: { [key: string]: number } + telemetryMetrics: { [key: string]: number }, ): Promise { const question: string = this.getTrimmedMessageText(context); const userId = context?.activity?.from?.id; @@ -327,13 +327,13 @@ export class CustomQuestionAnswering implements QnAMakerClient, QnAMakerTelemetr qnaResults: QnAMakerResult[], turnContext: TurnContext, telemetryProperties?: { [key: string]: string }, - telemetryMetrics?: { [key: string]: number } + telemetryMetrics?: { [key: string]: number }, ): Promise { const [properties, metrics] = await this.fillQnAEvent( qnaResults, turnContext, telemetryProperties, - telemetryMetrics + telemetryMetrics, ); this.telemetryClient.trackEvent({ @@ -357,7 +357,7 @@ export class CustomQuestionAnswering implements QnAMakerClient, QnAMakerTelemetr qnaResults: QnAMakerResult[], turnContext: TurnContext, telemetryProperties?: Record, - telemetryMetrics?: Record + telemetryMetrics?: Record, ): Promise<[Record, Record]> { const properties: Record = { [QnATelemetryConstants.knowledgeBaseIdProperty]: this.endpoint.knowledgeBaseId, diff --git a/libraries/botbuilder-ai/src/globals.ts b/libraries/botbuilder-ai/src/globals.ts index 28009caf19..c82e62318c 100644 --- a/libraries/botbuilder-ai/src/globals.ts +++ b/libraries/botbuilder-ai/src/globals.ts @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/explicit-function-return-type */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /** * @module botbuilder */ @@ -8,7 +6,7 @@ * Licensed under the MIT License. */ -// eslint-disable-next-line @typescript-eslint/no-var-requires +// eslint-disable-next-line @typescript-eslint/no-require-imports const window = require('./custom.window'); /** @@ -18,7 +16,7 @@ const window = require('./custom.window'); */ export function getFetch() { if (global) { - return (global.fetch = require('node-fetch')); + return (global.fetch = require('node-fetch')); // eslint-disable-line @typescript-eslint/no-require-imports } return window?.fetch; diff --git a/libraries/botbuilder-ai/src/instanceData.ts b/libraries/botbuilder-ai/src/instanceData.ts index e39f53987a..68b9d765fa 100644 --- a/libraries/botbuilder-ai/src/instanceData.ts +++ b/libraries/botbuilder-ai/src/instanceData.ts @@ -33,5 +33,5 @@ export interface InstanceData { /** * Any extra properties. */ - [propName: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any + [propName: string]: any; } diff --git a/libraries/botbuilder-ai/src/intentData.ts b/libraries/botbuilder-ai/src/intentData.ts index ce285188c1..48a4b615ee 100644 --- a/libraries/botbuilder-ai/src/intentData.ts +++ b/libraries/botbuilder-ai/src/intentData.ts @@ -18,5 +18,5 @@ export interface IntentData { /** * Any extra properties. */ - [propName: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any + [propName: string]: any; } diff --git a/libraries/botbuilder-ai/src/luisAdaptivePredictionOptions.ts b/libraries/botbuilder-ai/src/luisAdaptivePredictionOptions.ts index 3fefd876aa..4ca608b352 100644 --- a/libraries/botbuilder-ai/src/luisAdaptivePredictionOptions.ts +++ b/libraries/botbuilder-ai/src/luisAdaptivePredictionOptions.ts @@ -63,7 +63,8 @@ export interface LuisAdaptivePredictionOptionsConfiguration { * Converts optional parameters for a LUIS prediction request. */ export class LuisAdaptivePredictionOptionsConverter - implements Converter { + implements Converter +{ /** * Converts the provided options configuration into an object of [LuisAdaptivePredictionOptions](xref:botbuilder-ai.LuisAdaptivePredictionOptions) type. * diff --git a/libraries/botbuilder-ai/src/luisAdaptiveRecognizer.ts b/libraries/botbuilder-ai/src/luisAdaptiveRecognizer.ts index 2350150f8b..08c7a200c1 100644 --- a/libraries/botbuilder-ai/src/luisAdaptiveRecognizer.ts +++ b/libraries/botbuilder-ai/src/luisAdaptiveRecognizer.ts @@ -102,7 +102,7 @@ export class LuisAdaptiveRecognizer extends Recognizer implements LuisAdaptiveRe * The flag to indicate in personal information should be logged in telemetry. */ logPersonalInformation: BoolExpression = new BoolExpression( - '=settings.runtimeSettings.telemetry.logPersonalInformation' + '=settings.runtimeSettings.telemetry.logPersonalInformation', ); /** @@ -140,7 +140,7 @@ export class LuisAdaptiveRecognizer extends Recognizer implements LuisAdaptiveRe dialogContext: DialogContext, activity: Activity, telemetryProperties?: Record, - telemetryMetrics?: Record + telemetryMetrics?: Record, ): Promise { // Validate passed in activity matches turn activity const context = dialogContext.context; @@ -167,7 +167,7 @@ export class LuisAdaptiveRecognizer extends Recognizer implements LuisAdaptiveRe dialogContext, 'LuisResult', this.fillRecognizerResultTelemetryProperties(result, telemetryProperties, dialogContext), - telemetryMetrics + telemetryMetrics, ); return result; @@ -231,7 +231,7 @@ export class LuisAdaptiveRecognizer extends Recognizer implements LuisAdaptiveRe protected fillRecognizerResultTelemetryProperties( recognizerResult: RecognizerResult, telemetryProperties: { [key: string]: string }, - dialogContext: DialogContext + dialogContext: DialogContext, ): { [key: string]: string } { const logPersonalInfo = this.logPersonalInformation.tryGetValue(dialogContext.state); const applicationId = this.applicationId.tryGetValue(dialogContext.state); diff --git a/libraries/botbuilder-ai/src/luisBotComponent.ts b/libraries/botbuilder-ai/src/luisBotComponent.ts index f0a4ec698d..4fe60d490c 100644 --- a/libraries/botbuilder-ai/src/luisBotComponent.ts +++ b/libraries/botbuilder-ai/src/luisBotComponent.ts @@ -25,7 +25,7 @@ export class LuisBotComponent extends BotComponent { }, ]; }, - }) + }), ); } } diff --git a/libraries/botbuilder-ai/src/luisRecognizer.ts b/libraries/botbuilder-ai/src/luisRecognizer.ts index 7f8b7458a7..a40b8afb6e 100644 --- a/libraries/botbuilder-ai/src/luisRecognizer.ts +++ b/libraries/botbuilder-ai/src/luisRecognizer.ts @@ -117,7 +117,7 @@ export interface LuisRecognizerTelemetryClient { recognize( context: TurnContext, telemetryProperties?: { [key: string]: string }, - telemetryMetrics?: { [key: string]: number } + telemetryMetrics?: { [key: string]: number }, ): Promise; } @@ -246,7 +246,7 @@ const UnsafeLuisRecognizerUnion = z.custom, telemetryMetrics?: Record, - options?: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions + options?: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions, ): Promise; /** @@ -451,7 +451,7 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient { */ async recognize( utterance: string, - options?: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions + options?: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions, ): Promise; /** @@ -465,7 +465,7 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient { | LuisRecognizerOptionsV3 | LuisPredictionOptions, maybeTelemetryMetrics?: Record, - maybeOptions?: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions + maybeOptions?: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions, ): Promise { // This type check, when true, logically implies that the function is being invoked as the two-argument string + optional options overload variant. if (typeof contextOrUtterance === 'string') { @@ -544,7 +544,7 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient { recognizerResult: RecognizerResult, turnContext: TurnContext, telemetryProperties?: { [key: string]: string }, - telemetryMetrics?: { [key: string]: number } + telemetryMetrics?: { [key: string]: number }, ): Promise { await this.fillTelemetryProperties(recognizerResult, turnContext, telemetryProperties).then((props) => { this.telemetryClient.trackEvent({ @@ -566,7 +566,7 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient { protected async fillTelemetryProperties( recognizerResult: RecognizerResult, turnContext: TurnContext, - telemetryProperties?: { [key: string]: string } + telemetryProperties?: { [key: string]: string }, ): Promise<{ [key: string]: string }> { const [firstIntent, secondIntent] = LuisRecognizer.sortedIntents(recognizerResult); @@ -617,7 +617,6 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient { // If the `error` received is a azure-cognitiveservices-luis-runtime error, // it may have a `response` property and `response.statusCode`. // If these properties exist, we should populate the error with a correct and informative error message. - // eslint-disable-next-line @typescript-eslint/no-explicit-any const response: Record<'status', number> = (error as any).response; if (response?.status) { @@ -660,7 +659,7 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient { // Merges the default options set by the Recognizer contructor with the 'user' options passed into the 'recognize' method private setLuisPredictionOptions( defaultOptions: LuisPredictionOptions, - userOptions: LuisPredictionOptions + userOptions: LuisPredictionOptions, ): LuisPredictionOptions { return Object.assign(defaultOptions, userOptions); } @@ -669,19 +668,19 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient { private validateLuisApplication(): void { if (!this.application.applicationId) { throw new Error( - `Invalid \`applicationId\` value detected: ${this.application.applicationId}\nPlease make sure your applicationId is a valid LUIS Application Id, e.g. "b31aeaf3-3511-495b-a07f-571fc873214b".` + `Invalid \`applicationId\` value detected: ${this.application.applicationId}\nPlease make sure your applicationId is a valid LUIS Application Id, e.g. "b31aeaf3-3511-495b-a07f-571fc873214b".`, ); } if (!this.application.endpointKey) { throw new Error( - `Invalid \`endpointKey\` value detected: ${this.application.endpointKey}\nPlease make sure your endpointKey is a valid LUIS Endpoint Key, e.g. "048ec46dc58e495482b0c447cfdbd291".` + `Invalid \`endpointKey\` value detected: ${this.application.endpointKey}\nPlease make sure your endpointKey is a valid LUIS Endpoint Key, e.g. "048ec46dc58e495482b0c447cfdbd291".`, ); } } // Builds a LuisRecognizer Strategy depending on the options passed private buildRecognizer( - userOptions: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions + userOptions: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions, ): LuisRecognizerV3 | LuisRecognizerV2 { if (isLuisRecognizerOptionsV3(userOptions)) { return new LuisRecognizerV3(this.application, userOptions); diff --git a/libraries/botbuilder-ai/src/luisRecognizerOptions.ts b/libraries/botbuilder-ai/src/luisRecognizerOptions.ts index c402b65396..afc7575d27 100644 --- a/libraries/botbuilder-ai/src/luisRecognizerOptions.ts +++ b/libraries/botbuilder-ai/src/luisRecognizerOptions.ts @@ -20,7 +20,10 @@ export abstract class LuisRecognizerInternal { * @param {LuisApplication} application An object conforming to the [LuisApplication](xref:botbuilder-ai.LuisApplication) definition. * @param {LuisRecognizerOptions} _options Optional. Options object used to control predictions. Should conform to the [LuisRecognizerOptions](xref:botbuilder-ai.LuisRecognizerOptions) definition. */ - constructor(public application: LuisApplication, _options?: LuisRecognizerOptions) { + constructor( + public application: LuisApplication, + _options?: LuisRecognizerOptions, + ) { if (!application) { throw new Error('Null Application\n'); } diff --git a/libraries/botbuilder-ai/src/luisRecognizerOptionsV2.ts b/libraries/botbuilder-ai/src/luisRecognizerOptionsV2.ts index 68ce30cb7b..b7b413aba3 100644 --- a/libraries/botbuilder-ai/src/luisRecognizerOptionsV2.ts +++ b/libraries/botbuilder-ai/src/luisRecognizerOptionsV2.ts @@ -15,7 +15,7 @@ import { LuisRecognizerInternal } from './luisRecognizerOptions'; import { NullTelemetryClient, TurnContext, RecognizerResult } from 'botbuilder-core'; import { DialogContext } from 'botbuilder-dialogs'; -// eslint-disable-next-line @typescript-eslint/no-var-requires +// eslint-disable-next-line @typescript-eslint/no-require-imports const pjson: Record<'name' | 'version', string> = require('../package.json'); const LUIS_TRACE_TYPE = 'https://www.luis.ai/schemas/trace'; @@ -29,7 +29,6 @@ const LUIS_TRACE_LABEL = 'Luis Trace'; * @returns {boolean} A boolean value that indicates param options is a [LuisRecognizerOptionsV2](xref:botbuilder-ai.LuisRecognizerOptionsV2). */ export function isLuisRecognizerOptionsV2(options: unknown): options is LuisRecognizerOptionsV2 { - // eslint-disable-next-line @typescript-eslint/no-explicit-any return (options as any).apiVersion && (options as any).apiVersion === 'v2'; } @@ -52,7 +51,7 @@ export class LuisRecognizerV2 extends LuisRecognizerInternal { // shouldn't effect production bots. const creds = new TokenCredentials(application.endpointKey); const baseUri = application.endpoint || 'https://westus.api.cognitive.microsoft.com'; - // eslint-disable-next-line @typescript-eslint/no-explicit-any + this.luisClient = new LuisClient(creds as any, baseUri); this.options = { @@ -123,7 +122,7 @@ export class LuisRecognizerV2 extends LuisRecognizerInternal { 'User-Agent': this.getUserAgent(), }, ...luisPredictionOptions, - } + }, ); // Map results const result = { @@ -133,7 +132,7 @@ export class LuisRecognizerV2 extends LuisRecognizerInternal { entities: this.getEntitiesAndMetadata( luisResult.entities, luisResult.compositeEntities, - luisPredictionOptions.includeInstanceData === undefined || luisPredictionOptions.includeInstanceData + luisPredictionOptions.includeInstanceData === undefined || luisPredictionOptions.includeInstanceData, ), sentiment: this.getSentiment(luisResult), luisResult: luisPredictionOptions.includeAPIResults ? luisResult : null, @@ -170,17 +169,15 @@ export class LuisRecognizerV2 extends LuisRecognizerInternal { private getEntitiesAndMetadata( entities: EntityModel[], compositeEntities: CompositeEntityModel[] | undefined, - verbose: boolean - // eslint-disable-next-line @typescript-eslint/no-explicit-any + verbose: boolean, ): any { - // eslint-disable-next-line @typescript-eslint/no-explicit-any const entitiesAndMetadata: any = verbose ? { $instance: {} } : {}; let compositeEntityTypes: string[] = []; // We start by populating composite entities so that entities covered by them are removed from the entities list if (compositeEntities) { compositeEntityTypes = compositeEntities.map( - (compositeEntity: CompositeEntityModel) => compositeEntity.parentType + (compositeEntity: CompositeEntityModel) => compositeEntity.parentType, ); compositeEntities.forEach((compositeEntity: CompositeEntityModel) => { entities = this.populateCompositeEntity(compositeEntity, entities, entitiesAndMetadata, verbose); @@ -200,7 +197,7 @@ export class LuisRecognizerV2 extends LuisRecognizerInternal { this.addProperty( entitiesAndMetadata.$instance, this.getNormalizedEntityName(entity), - this.getEntityMetadata(entity) + this.getEntityMetadata(entity), ); } } @@ -212,12 +209,10 @@ export class LuisRecognizerV2 extends LuisRecognizerInternal { private populateCompositeEntity( compositeEntity: CompositeEntityModel, entities: EntityModel[], - entitiesAndMetadata: any, // eslint-disable-line @typescript-eslint/no-explicit-any - verbose: boolean + entitiesAndMetadata: any, + verbose: boolean, ): EntityModel[] { - // eslint-disable-next-line @typescript-eslint/no-explicit-any const childrenEntities: any = verbose ? { $instance: {} } : {}; - // eslint-disable-next-line @typescript-eslint/no-explicit-any let childrenEntitiesMetadata: any = {}; // This is now implemented as O(n^2) search and can be reduced to O(2n) using a map as an optimization if n grows @@ -258,7 +253,7 @@ export class LuisRecognizerV2 extends LuisRecognizerInternal { this.addProperty( childrenEntities.$instance, this.getNormalizedEntityName(entity), - this.getEntityMetadata(entity) + this.getEntityMetadata(entity), ); } } @@ -278,14 +273,13 @@ export class LuisRecognizerV2 extends LuisRecognizerInternal { this.addProperty( entitiesAndMetadata.$instance, this.getNormalizedEntityName(compositeEntityMetadata), - childrenEntitiesMetadata + childrenEntitiesMetadata, ); } return filteredEntities; } - // eslint-disable-next-line @typescript-eslint/no-explicit-any private getEntityValue(entity: EntityModel): any { if (entity.type.startsWith('builtin.geographyV2.')) { return { @@ -310,13 +304,9 @@ export class LuisRecognizerV2 extends LuisRecognizerInternal { return entity.resolution; } - // eslint-disable-next-line @typescript-eslint/no-explicit-any const vals: any = entity.resolution.values; - // eslint-disable-next-line @typescript-eslint/no-explicit-any const type = vals[0].type; - // eslint-disable-next-line @typescript-eslint/no-explicit-any const timexes = vals.map((t: any) => t.timex); - // eslint-disable-next-line @typescript-eslint/no-explicit-any const distinct = timexes.filter((v, i, a) => a.indexOf(v) === i); return { type: type, timex: distinct }; @@ -391,7 +381,6 @@ export class LuisRecognizerV2 extends LuisRecognizerInternal { } // If a property doesn't exist add it to a new array, otherwise append it to the existing array - // eslint-disable-next-line @typescript-eslint/ban-types private addProperty(obj: object, key: string, value: unknown): void { if (key in obj) { obj[key] = obj[key].concat(value); @@ -423,7 +412,7 @@ export class LuisRecognizerV2 extends LuisRecognizerInternal { private emitTraceInfo( context: TurnContext, luisResult: LuisResult, - recognizerResult: RecognizerResult + recognizerResult: RecognizerResult, ): Promise { const traceInfo = { recognizerResult: recognizerResult, diff --git a/libraries/botbuilder-ai/src/luisRecognizerOptionsV3.ts b/libraries/botbuilder-ai/src/luisRecognizerOptionsV3.ts index bfaff2c5b6..99cd407695 100644 --- a/libraries/botbuilder-ai/src/luisRecognizerOptionsV3.ts +++ b/libraries/botbuilder-ai/src/luisRecognizerOptionsV3.ts @@ -6,8 +6,7 @@ * Licensed under the MIT License. */ -import fetch from 'node-fetch'; -import { RequestInfo, RequestInit } from 'node-fetch'; +import fetch, { RequestInfo, RequestInit } from 'node-fetch'; import { LuisApplication, LuisRecognizerOptionsV3 } from './luisRecognizer'; import { LuisResult } from './luisV2-models/luisResult'; import { LuisRecognizerInternal } from './luisRecognizerOptions'; @@ -31,7 +30,6 @@ const MetadataKey = '$instance'; * @returns {boolean} A boolean value that indicates param options is a [LuisRecognizerOptionsV3](xref:botbuilder-ai.LuisRecognizerOptionsV3). */ export function isLuisRecognizerOptionsV3(options: unknown): options is LuisRecognizerOptionsV3 { - // eslint-disable-next-line @typescript-eslint/no-explicit-any return (options as any).apiVersion && (options as any).apiVersion === 'v3'; } @@ -143,7 +141,7 @@ export class LuisRecognizerV3 extends LuisRecognizerInternal { private async recognize( context: TurnContext, utterance: string, - options: LuisRecognizerOptionsV3 + options: LuisRecognizerOptionsV3, ): Promise { if (!utterance.trim()) { // Bypass LUIS if the activity's text is null or whitespace @@ -240,7 +238,7 @@ export class LuisRecognizerV3 extends LuisRecognizerInternal { context: TurnContext, luisResult: LuisResult, recognizerResult: RecognizerResult, - options: LuisRecognizerOptionsV3 + options: LuisRecognizerOptionsV3, ): Promise { const traceInfo = { recognizerResult: recognizerResult, diff --git a/libraries/botbuilder-ai/src/luisSchema.d.ts b/libraries/botbuilder-ai/src/luisSchema.d.ts index 2914c7df8f..0f73aebb49 100644 --- a/libraries/botbuilder-ai/src/luisSchema.d.ts +++ b/libraries/botbuilder-ai/src/luisSchema.d.ts @@ -30,7 +30,7 @@ export interface Entity { startIndex?: number; endIndex?: number; score?: number; - resolution?: { [propertyName: string]: any }; // eslint-disable-line @typescript-eslint/no-explicit-any + resolution?: { [propertyName: string]: any }; } /** diff --git a/libraries/botbuilder-ai/src/luisV2-models/luisPrediction.ts b/libraries/botbuilder-ai/src/luisV2-models/luisPrediction.ts index 5ed5aa9648..54c1e950d8 100644 --- a/libraries/botbuilder-ai/src/luisV2-models/luisPrediction.ts +++ b/libraries/botbuilder-ai/src/luisV2-models/luisPrediction.ts @@ -37,7 +37,7 @@ export class LuisPrediction { resolve( appId: string, query: string, - options?: PredictionResolveOptionalParams + options?: PredictionResolveOptionalParams, ): Promise; /** * @param appId The LUIS application ID (Guid). @@ -55,7 +55,7 @@ export class LuisPrediction { appId: string, query: string, options: PredictionResolveOptionalParams, - callback: ServiceCallback + callback: ServiceCallback, ): void; /** * @param appId The LUIS application ID (Guid). @@ -68,7 +68,7 @@ export class LuisPrediction { appId: string, query: string, options?: PredictionResolveOptionalParams | ServiceCallback, - callback?: ServiceCallback + callback?: ServiceCallback, ): Promise { return this.client.sendOperationRequest( { @@ -77,7 +77,7 @@ export class LuisPrediction { options, }, resolveOperationSpec, - callback + callback, ) as Promise; } } diff --git a/libraries/botbuilder-ai/src/qnaCardBuilder.ts b/libraries/botbuilder-ai/src/qnaCardBuilder.ts index 3a9d6a1e5a..bb1bdff412 100644 --- a/libraries/botbuilder-ai/src/qnaCardBuilder.ts +++ b/libraries/botbuilder-ai/src/qnaCardBuilder.ts @@ -26,7 +26,7 @@ export class QnACardBuilder { suggestionsList: string[], cardTitle: string, cardNoMatchText: string, - useTeamsAdaptiveCard = false + useTeamsAdaptiveCard = false, ): Partial { if (!Array.isArray(suggestionsList)) { throw new Error('Missing suggestionsList'); @@ -76,7 +76,7 @@ export class QnACardBuilder { static getQnAAnswerCard( result: QnAMakerResult, displayPreciseAnswerOnly: boolean, - useTeamsAdaptiveCard = false + useTeamsAdaptiveCard = false, ): Partial { if (!result) { throw new Error('Missing QnAMaker result'); diff --git a/libraries/botbuilder-ai/src/qnaMaker.ts b/libraries/botbuilder-ai/src/qnaMaker.ts index 5d8b266184..b9ecdbc6b9 100644 --- a/libraries/botbuilder-ai/src/qnaMaker.ts +++ b/libraries/botbuilder-ai/src/qnaMaker.ts @@ -46,7 +46,7 @@ export interface QnAMakerClient { turnContext: TurnContext, options?: QnAMakerOptions, telemetryProperties?: Record, - telemetryMetrics?: Record + telemetryMetrics?: Record, ): Promise; /** @@ -62,7 +62,7 @@ export interface QnAMakerClient { turnContext: TurnContext, options?: QnAMakerOptions, telemetryProperties?: Record, - telemetryMetrics?: Record + telemetryMetrics?: Record, ): Promise; /** @@ -114,7 +114,7 @@ export interface QnAMakerTelemetryClient { context: TurnContext, options?: QnAMakerOptions, telemetryProperties?: { [key: string]: string }, - telemetryMetrics?: { [key: string]: number } + telemetryMetrics?: { [key: string]: number }, ): Promise; } @@ -146,7 +146,7 @@ export class QnAMaker implements QnAMakerClient, QnAMakerTelemetryClient { private readonly endpoint: QnAMakerEndpoint, options: QnAMakerOptions = {}, telemetryClient?: BotTelemetryClient, - logPersonalInformation?: boolean + logPersonalInformation?: boolean, ) { if (!endpoint) { throw new TypeError('QnAMaker requires valid QnAMakerEndpoint.'); @@ -216,7 +216,7 @@ export class QnAMaker implements QnAMakerClient, QnAMakerTelemetryClient { context: TurnContext, options?: QnAMakerOptions, telemetryProperties?: { [key: string]: string }, - telemetryMetrics?: { [key: string]: number } + telemetryMetrics?: { [key: string]: number }, ): Promise { if (!context) { throw new TypeError('QnAMaker.getAnswers() requires a TurnContext.'); @@ -244,7 +244,7 @@ export class QnAMaker implements QnAMakerClient, QnAMakerTelemetryClient { context: TurnContext, options: QnAMakerOptions, telemetryProperties: { [key: string]: string }, - telemetryMetrics: { [key: string]: number } + telemetryMetrics: { [key: string]: number }, ): Promise { if (!context) { throw new TypeError('QnAMaker.getAnswersRaw() requires a TurnContext.'); @@ -266,7 +266,7 @@ export class QnAMaker implements QnAMakerClient, QnAMakerTelemetryClient { context: TurnContext, options?: QnAMakerOptions, telemetryProperties?: { [key: string]: string }, - telemetryMetrics?: { [key: string]: number } + telemetryMetrics?: { [key: string]: number }, ): Promise { const question: string = this.getTrimmedMessageText(context); const queryOptions: QnAMakerOptions = { ...this._options, ...options } as QnAMakerOptions; @@ -282,7 +282,7 @@ export class QnAMaker implements QnAMakerClient, QnAMakerTelemetryClient { const sortedQnaAnswers: QnAMakerResult[] = GenerateAnswerUtils.sortAnswersWithinThreshold( result?.answers, - queryOptions + queryOptions, ); queryResult.push(...sortedQnaAnswers); @@ -351,7 +351,7 @@ export class QnAMaker implements QnAMakerClient, QnAMakerTelemetryClient { async generateAnswer( question: string | undefined, top?: number, - _scoreThreshold?: number + _scoreThreshold?: number, ): Promise { const trimmedAnswer: string = question ? question.trim() : ''; @@ -359,7 +359,7 @@ export class QnAMaker implements QnAMakerClient, QnAMakerTelemetryClient { const result: QnAMakerResults = await this.callService( this.endpoint, question, - typeof top === 'number' ? top : 1 + typeof top === 'number' ? top : 1, ); return result.answers.sort((a: QnAMakerResult, b: QnAMakerResult) => b.score - a.score); @@ -417,13 +417,13 @@ export class QnAMaker implements QnAMakerClient, QnAMakerTelemetryClient { qnaResults: QnAMakerResult[], turnContext: TurnContext, telemetryProperties?: { [key: string]: string }, - telemetryMetrics?: { [key: string]: number } + telemetryMetrics?: { [key: string]: number }, ): Promise { const [properties, metrics] = await this.fillQnAEvent( qnaResults, turnContext, telemetryProperties, - telemetryMetrics + telemetryMetrics, ); this.telemetryClient.trackEvent({ @@ -447,7 +447,7 @@ export class QnAMaker implements QnAMakerClient, QnAMakerTelemetryClient { qnaResults: QnAMakerResult[], turnContext: TurnContext, telemetryProperties?: Record, - telemetryMetrics?: Record + telemetryMetrics?: Record, ): Promise<[Record, Record]> { const properties: Record = { [QnATelemetryConstants.knowledgeBaseIdProperty]: this.endpoint.knowledgeBaseId, diff --git a/libraries/botbuilder-ai/src/qnaMakerBotComponent.ts b/libraries/botbuilder-ai/src/qnaMakerBotComponent.ts index d0ae9099f2..ff17fc4309 100644 --- a/libraries/botbuilder-ai/src/qnaMakerBotComponent.ts +++ b/libraries/botbuilder-ai/src/qnaMakerBotComponent.ts @@ -30,7 +30,7 @@ export class QnAMakerBotComponent extends BotComponent { }, ]; }, - }) + }), ); } } diff --git a/libraries/botbuilder-ai/src/qnaMakerDialog.ts b/libraries/botbuilder-ai/src/qnaMakerDialog.ts index bb55911565..df5e4f19e7 100644 --- a/libraries/botbuilder-ai/src/qnaMakerDialog.ts +++ b/libraries/botbuilder-ai/src/qnaMakerDialog.ts @@ -59,9 +59,10 @@ import { CustomQuestionAnswering } from './customQuestionAnswering'; import { ServiceType } from './qnamaker-interfaces/serviceType'; class QnAMakerDialogActivityConverter - implements Converter, DialogStateManager>> { + implements Converter, DialogStateManager>> +{ convert( - value: string | TemplateInterface, DialogStateManager> + value: string | TemplateInterface, DialogStateManager>, ): TemplateInterface, DialogStateManager> { if (typeof value === 'string') { return new BindToActivity(MessageFactory.text(value) as Activity); @@ -239,7 +240,7 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon * Gets or sets the template to send to the user when QnA Maker does not find an answer. */ noAnswer: TemplateInterface, DialogStateManager> = new BindToActivity( - MessageFactory.text(this.defaultNoAnswer) + MessageFactory.text(this.defaultNoAnswer), ); /** @@ -262,7 +263,7 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon * active learning card. */ cardNoMatchResponse: TemplateInterface, DialogStateManager> = new BindToActivity( - MessageFactory.text(this.defaultCardNoMatchResponse) + MessageFactory.text(this.defaultCardNoMatchResponse), ); /** @@ -364,7 +365,7 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon enablePreciseAnswer?: boolean, displayPreciseAnswerOnly?: boolean, qnaServiceType?: ServiceType, - useTeamsAdaptiveCard?: boolean + useTeamsAdaptiveCard?: boolean, ); /** @@ -401,7 +402,7 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon enablePreciseAnswer?: boolean, displayPreciseAnswerOnly?: boolean, qnaServiceType?: ServiceType, - useTeamsAdaptiveCard?: boolean + useTeamsAdaptiveCard?: boolean, ); /** @@ -426,7 +427,7 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon enablePreciseAnswer?: boolean, displayPreciseAnswerOnly?: boolean, qnaServiceType?: ServiceType, - useTeamsAdaptiveCard?: boolean + useTeamsAdaptiveCard?: boolean, ) { super(dialogId); if (knowledgeBaseId) { @@ -448,9 +449,8 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon if (top) { this.top = new IntExpression(top); } - const qnaSuggestionsActivityFactoryParsed = qnaSuggestionsActivityFactory.safeParse( - activeLearningTitleOrFactory - ); + const qnaSuggestionsActivityFactoryParsed = + qnaSuggestionsActivityFactory.safeParse(activeLearningTitleOrFactory); if (qnaSuggestionsActivityFactoryParsed.success) { if (!cardNoMatchText) { // Without a developer-provided cardNoMatchText, the end user will not be able to tell the convey to the bot and QnA Maker that the suggested alternative questions were not correct. @@ -461,7 +461,7 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon this.suggestionsActivityFactory = qnaSuggestionsActivityFactoryParsed.data; } else { this.activeLearningCardTitle = new StringExpression( - activeLearningTitleOrFactory?.toString() ?? this.defaultCardTitle + activeLearningTitleOrFactory?.toString() ?? this.defaultCardTitle, ); } @@ -482,7 +482,7 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon } this.cardNoMatchResponse = new BindToActivity( - cardNoMatchResponse ?? MessageFactory.text(this.defaultCardNoMatchResponse) + cardNoMatchResponse ?? MessageFactory.text(this.defaultCardNoMatchResponse), ); if (enablePreciseAnswer != undefined) { @@ -559,7 +559,6 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon * @param {object} options (Optional) Initial information to pass to the dialog. * @returns {Promise} A promise resolving to the turn result */ - // eslint-disable-next-line @typescript-eslint/ban-types async beginDialog(dc: DialogContext, options?: object): Promise { if (!dc) { throw new Error('Missing DialogContext'); @@ -636,7 +635,7 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon this.resetOptions(dc, dialogOptions); const response = await qnaClient.getAnswersRaw(dc.context, dialogOptions.qnaMakerOptions); // disable interruption if we have answers. - return response.answers?.length > 0 ?? false; + return response.answers?.length > 0; } } @@ -672,14 +671,14 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon endpoint, await this.getQnAMakerOptions(dc), this.telemetryClient, - logPersonalInformation + logPersonalInformation, ); } else { return new QnAMaker( endpoint, await this.getQnAMakerOptions(dc), this.telemetryClient, - logPersonalInformation + logPersonalInformation, ); } } @@ -728,7 +727,7 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon * * @param {WaterfallStepContext} step the waterfall step context * @returns {Promise} a promise resolving to the dialog turn result - **/ + */ protected async displayQnAResult(step: WaterfallStepContext): Promise { const dialogOptions: QnAMakerDialogOptions = step.activeDialog.state[this.options]; const reply = step.context.activity.text; @@ -757,7 +756,7 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon const message = QnACardBuilder.getQnAAnswerCard( response[0], this.displayPreciseAnswerOnly, - this.useTeamsAdaptiveCard + this.useTeamsAdaptiveCard, ); await step.context.sendActivity(message); } else { @@ -767,7 +766,7 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon const message = QnACardBuilder.getQnAAnswerCard( response[0], this.displayPreciseAnswerOnly, - this.useTeamsAdaptiveCard + this.useTeamsAdaptiveCard, ); await step.context.sendActivity(message); } @@ -861,13 +860,13 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon const message = this.suggestionsActivityFactory?.( suggestedQuestions, - dialogOptions.qnaDialogResponseOptions.cardNoMatchText + dialogOptions.qnaDialogResponseOptions.cardNoMatchText, ) ?? QnACardBuilder.getSuggestionsCard( suggestedQuestions, dialogOptions.qnaDialogResponseOptions.activeLearningCardTitle, dialogOptions.qnaDialogResponseOptions.cardNoMatchText, - this.useTeamsAdaptiveCard + this.useTeamsAdaptiveCard, ); z.record(z.unknown()).parse(message, { path: ['message'] }); @@ -961,7 +960,7 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon const message = QnACardBuilder.getQnAAnswerCard( answer, this.displayPreciseAnswerOnly, - this.useTeamsAdaptiveCard + this.useTeamsAdaptiveCard, ); await step.context.sendActivity(message); return Dialog.EndOfTurn; diff --git a/libraries/botbuilder-ai/src/qnaMakerRecognizer.ts b/libraries/botbuilder-ai/src/qnaMakerRecognizer.ts index 335ac94547..f5afb504b4 100644 --- a/libraries/botbuilder-ai/src/qnaMakerRecognizer.ts +++ b/libraries/botbuilder-ai/src/qnaMakerRecognizer.ts @@ -124,7 +124,7 @@ export class QnAMakerRecognizer extends Recognizer implements QnAMakerRecognizer * The flag to indicate if personal information should be logged in telemetry. */ logPersonalInformation: BoolExpression = new BoolExpression( - '=settings.runtimeSettings.telemetry.logPersonalInformation' + '=settings.runtimeSettings.telemetry.logPersonalInformation', ); /** @@ -193,7 +193,7 @@ export class QnAMakerRecognizer extends Recognizer implements QnAMakerRecognizer dc: DialogContext, activity: Activity, telemetryProperties?: { [key: string]: string }, - telemetryMetrics?: { [key: string]: number } + telemetryMetrics?: { [key: string]: number }, ): Promise { // identify matched intents const recognizerResult: RecognizerResult = { @@ -270,7 +270,7 @@ export class QnAMakerRecognizer extends Recognizer implements QnAMakerRecognizer dc, 'QnAMakerRecognizerResult', this.fillRecognizerResultTelemetryProperties(recognizerResult, telemetryProperties, dc), - telemetryMetrics + telemetryMetrics, ); return recognizerResult; } @@ -344,11 +344,11 @@ export class QnAMakerRecognizer extends Recognizer implements QnAMakerRecognizer protected fillRecognizerResultTelemetryProperties( recognizerResult: RecognizerResult, telemetryProperties: Record, - dc: DialogContext + dc: DialogContext, ): Record { if (!dc) { throw new Error( - 'DialogContext needed for state in AdaptiveRecognizer.fillRecognizerResultTelemetryProperties method.' + 'DialogContext needed for state in AdaptiveRecognizer.fillRecognizerResultTelemetryProperties method.', ); } const { intent, score } = getTopScoringIntent(recognizerResult); @@ -359,7 +359,7 @@ export class QnAMakerRecognizer extends Recognizer implements QnAMakerRecognizer Intents: intentsCount > 0 ? JSON.stringify(recognizerResult.intents) : undefined, Entities: recognizerResult.entities ? JSON.stringify(recognizerResult.entities) : undefined, AdditionalProperties: JSON.stringify( - omit(recognizerResult, ['text', 'alteredText', 'intents', 'entities']) + omit(recognizerResult, ['text', 'alteredText', 'intents', 'entities']), ), }; diff --git a/libraries/botbuilder-ai/src/qnamaker-interfaces/qnamakerPrompt.ts b/libraries/botbuilder-ai/src/qnamaker-interfaces/qnamakerPrompt.ts index 79f9a73b88..25777f0f9a 100644 --- a/libraries/botbuilder-ai/src/qnamaker-interfaces/qnamakerPrompt.ts +++ b/libraries/botbuilder-ai/src/qnamaker-interfaces/qnamakerPrompt.ts @@ -22,7 +22,7 @@ export interface QnAMakerPrompt { /** * The QnA object returned from the API (Optional parameter). */ - qna?: object; // eslint-disable-line @typescript-eslint/ban-types + qna?: object; /** * Display Text - Text displayed to represent a follow up question prompt. diff --git a/libraries/botbuilder-ai/src/qnamaker-interfaces/qnamakerResult.ts b/libraries/botbuilder-ai/src/qnamaker-interfaces/qnamakerResult.ts index 98343eff62..6f51a21e4b 100644 --- a/libraries/botbuilder-ai/src/qnamaker-interfaces/qnamakerResult.ts +++ b/libraries/botbuilder-ai/src/qnamaker-interfaces/qnamakerResult.ts @@ -31,7 +31,7 @@ export interface QnAMakerResult { /** * Metadata associated with the answer (If any) */ - metadata?: any; // eslint-disable-line @typescript-eslint/no-explicit-any + metadata?: any; /** * The source from which the QnA was extracted (If any) diff --git a/libraries/botbuilder-ai/src/qnamaker-interfaces/qnamakerTraceInfo.ts b/libraries/botbuilder-ai/src/qnamaker-interfaces/qnamakerTraceInfo.ts index 44d83c7972..6046249f22 100644 --- a/libraries/botbuilder-ai/src/qnamaker-interfaces/qnamakerTraceInfo.ts +++ b/libraries/botbuilder-ai/src/qnamaker-interfaces/qnamakerTraceInfo.ts @@ -42,12 +42,12 @@ export interface QnAMakerTraceInfo { /** * Filters used on query. Not used in JavaScript SDK v4 yet. */ - strictFilters: any[]; // eslint-disable-line @typescript-eslint/no-explicit-any + strictFilters: any[]; /** * Metadata related to query. Not used in JavaScript SDK v4 yet. */ - metadataBoost: any[]; // eslint-disable-line @typescript-eslint/no-explicit-any + metadataBoost: any[]; /** * The context for multi-turn responses. diff --git a/libraries/botbuilder-ai/src/qnamaker-utils/activeLearningUtils.ts b/libraries/botbuilder-ai/src/qnamaker-utils/activeLearningUtils.ts index fae501adf6..dfe2175722 100644 --- a/libraries/botbuilder-ai/src/qnamaker-utils/activeLearningUtils.ts +++ b/libraries/botbuilder-ai/src/qnamaker-utils/activeLearningUtils.ts @@ -59,12 +59,12 @@ export class ActiveLearningUtils { ActiveLearningUtils.includeForClustering( prevScore, qnaSearchResults[i].score * 100, - ActiveLearningUtils.PreviousLowScoreVariationMultiplier + ActiveLearningUtils.PreviousLowScoreVariationMultiplier, ) && this.includeForClustering( topAnswerScore, qnaSearchResults[i].score * 100, - ActiveLearningUtils.MaxLowScoreVariationMultiplier + ActiveLearningUtils.MaxLowScoreVariationMultiplier, ) ) { prevScore = qnaSearchResults[i].score * 100; diff --git a/libraries/botbuilder-ai/src/qnamaker-utils/bindToActivity.ts b/libraries/botbuilder-ai/src/qnamaker-utils/bindToActivity.ts index 099115bb8b..926ecda725 100644 --- a/libraries/botbuilder-ai/src/qnamaker-utils/bindToActivity.ts +++ b/libraries/botbuilder-ai/src/qnamaker-utils/bindToActivity.ts @@ -28,7 +28,6 @@ export class BindToActivity implements TemplateInterface> { * @param _data Data to bind to. If Null, then dc.State will be used. * @returns The linked activity. */ - // eslint-disable-next-line @typescript-eslint/ban-types async bind(_context: DialogContext, _data?: object): Promise> { return this.activity; } diff --git a/libraries/botbuilder-ai/src/qnamaker-utils/generateAnswerUtils.ts b/libraries/botbuilder-ai/src/qnamaker-utils/generateAnswerUtils.ts index 92deee4b51..60cd458a42 100644 --- a/libraries/botbuilder-ai/src/qnamaker-utils/generateAnswerUtils.ts +++ b/libraries/botbuilder-ai/src/qnamaker-utils/generateAnswerUtils.ts @@ -34,7 +34,10 @@ export class GenerateAnswerUtils { * @param {QnAMakerOptions} _options Settings used to configure the instance. * @param {QnAMakerEndpoint} endpoint The endpoint of the knowledge base to query. */ - constructor(public _options: QnAMakerOptions, private readonly endpoint: QnAMakerEndpoint) { + constructor( + public _options: QnAMakerOptions, + private readonly endpoint: QnAMakerEndpoint, + ) { this.httpRequestUtils = new HttpRequestUtils(); this.validateOptions(this._options); @@ -47,11 +50,11 @@ export class GenerateAnswerUtils { * @param {string} question Question which need to be queried. * @param {QnAMakerOptions} options (Optional) The options for the QnA Maker knowledge base. If null, constructor option is used for this instance. * @returns {Promise} a promise that resolves to the query results. - .*/ + */ async queryQnaService( endpoint: QnAMakerEndpoint, question: string, - options?: QnAMakerOptions + options?: QnAMakerOptions, ): Promise { const result = await this.queryQnaServiceRaw(endpoint, question, options); @@ -69,7 +72,7 @@ export class GenerateAnswerUtils { async queryQnaServiceRaw( endpoint: QnAMakerEndpoint, question: string, - options?: QnAMakerOptions + options?: QnAMakerOptions, ): Promise { const url = `${endpoint.host}/knowledgebases/${endpoint.knowledgeBaseId}/generateanswer`; const queryOptions: QnAMakerOptions = { ...this._options, ...options } as QnAMakerOptions; @@ -77,7 +80,7 @@ export class GenerateAnswerUtils { const legacyMetadata = this.getMetadata( queryOptions.strictFilters, queryOptions.strictFiltersJoinOperator, - queryOptions.filters + queryOptions.filters, ); queryOptions.strictFilters = legacyMetadata.metadata; queryOptions.filters = null; @@ -94,7 +97,7 @@ export class GenerateAnswerUtils { url, payloadBody, this.endpoint, - queryOptions.timeout + queryOptions.timeout, ); if (Array.isArray(qnaResults?.answers)) { @@ -115,8 +118,7 @@ export class GenerateAnswerUtils { async emitTraceInfo( turnContext: TurnContext, answers: QnAMakerResult[], - queryOptions?: QnAMakerOptions - // eslint-disable-next-line @typescript-eslint/no-explicit-any + queryOptions?: QnAMakerOptions, ): Promise { const requestOptions: QnAMakerOptions = { ...this._options, ...queryOptions }; const { scoreThreshold, top, strictFilters, metadataBoost, context, qnaId } = requestOptions; @@ -169,7 +171,7 @@ export class GenerateAnswerUtils { */ static sortAnswersWithinThreshold( answers: QnAMakerResult[] = [] as QnAMakerResult[], - queryOptions: QnAMakerOptions + queryOptions: QnAMakerOptions, ): QnAMakerResult[] { const minScore: number = typeof queryOptions.scoreThreshold === 'number' ? queryOptions.scoreThreshold : 0.001; @@ -183,7 +185,6 @@ export class GenerateAnswerUtils { .sort((a: QnAMakerResult, b: QnAMakerResult) => b.score - a.score); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any private formatQnaResult(qnaResult: QnAMakerResults | any): QnAMakerResults { qnaResult.answers = qnaResult.answers.map((answer: QnAMakerResult & { qnaId?: number }) => { answer.score = answer.score / 100; @@ -204,7 +205,7 @@ export class GenerateAnswerUtils { private validateScoreThreshold(scoreThreshold: number): void { if (typeof scoreThreshold !== 'number' || !(scoreThreshold > 0 && scoreThreshold <= 1)) { throw new TypeError( - `"${scoreThreshold}" is an invalid scoreThreshold. QnAMakerOptions.scoreThreshold must have a value between 0 and 1.` + `"${scoreThreshold}" is an invalid scoreThreshold. QnAMakerOptions.scoreThreshold must have a value between 0 and 1.`, ); } } @@ -212,7 +213,7 @@ export class GenerateAnswerUtils { private validateTop(qnaOptionTop: number): void { if (!Number.isInteger(qnaOptionTop) || qnaOptionTop < 1) { throw new RangeError( - `"${qnaOptionTop}" is an invalid top value. QnAMakerOptions.top must be an integer greater than 0.` + `"${qnaOptionTop}" is an invalid top value. QnAMakerOptions.top must be an integer greater than 0.`, ); } } @@ -220,7 +221,7 @@ export class GenerateAnswerUtils { private getMetadata( strictFilters: QnAMakerMetadata[], operator: JoinOperator, - filters: Filters + filters: Filters, ): { metadata: QnAMakerMetadata[]; compoundOperation: JoinOperator } { if (!strictFilters) { return { metadata: strictFilters, compoundOperation: operator ? operator : JoinOperator.AND }; diff --git a/libraries/botbuilder-ai/src/qnamaker-utils/httpRequestUtils.ts b/libraries/botbuilder-ai/src/qnamaker-utils/httpRequestUtils.ts index a799437409..cbb8005ec1 100644 --- a/libraries/botbuilder-ai/src/qnamaker-utils/httpRequestUtils.ts +++ b/libraries/botbuilder-ai/src/qnamaker-utils/httpRequestUtils.ts @@ -15,7 +15,7 @@ import { QnAMakerResults } from '../qnamaker-interfaces/qnamakerResults'; import { getFetch } from '../globals'; const fetch = getFetch(); -// eslint-disable-next-line @typescript-eslint/no-var-requires +// eslint-disable-next-line @typescript-eslint/no-require-imports const pjson: Record<'name' | 'version', string> = require('../../package.json'); /** * Http request utils class. @@ -37,7 +37,7 @@ export class HttpRequestUtils { requestUrl: string, payloadBody: string, endpoint: QnAMakerEndpoint, - timeout?: number + timeout?: number, ): Promise { if (!requestUrl) { throw new TypeError('Request url cannot be null.'); diff --git a/libraries/botbuilder-ai/src/qnamaker-utils/languageServiceUtils.ts b/libraries/botbuilder-ai/src/qnamaker-utils/languageServiceUtils.ts index 237a255000..ba3d016946 100644 --- a/libraries/botbuilder-ai/src/qnamaker-utils/languageServiceUtils.ts +++ b/libraries/botbuilder-ai/src/qnamaker-utils/languageServiceUtils.ts @@ -46,7 +46,10 @@ export class LanguageServiceUtils { * @param {QnAMakerOptions} _options Settings used to configure the instance. * @param {QnAMakerEndpoint} endpoint The endpoint of the knowledge base to query. */ - constructor(public _options: QnAMakerOptions, readonly endpoint: QnAMakerEndpoint) { + constructor( + public _options: QnAMakerOptions, + readonly endpoint: QnAMakerEndpoint, + ) { this.httpRequestUtils = new HttpRequestUtils(); this.validateOptions(this._options); @@ -92,7 +95,7 @@ export class LanguageServiceUtils { filters: this.getFilters( queryOptions.strictFilters, queryOptions.strictFiltersJoinOperator, - queryOptions.filters + queryOptions.filters, ), qnaId: queryOptions.qnaId, rankerType: queryOptions.rankerType, @@ -106,7 +109,7 @@ export class LanguageServiceUtils { url, payloadBody, this.endpoint, - queryOptions.timeout + queryOptions.timeout, ); if (Array.isArray(qnaResults?.answers)) { @@ -127,8 +130,7 @@ export class LanguageServiceUtils { async emitTraceInfo( turnContext: TurnContext, answers: QnAMakerResult[], - queryOptions?: QnAMakerOptions - // eslint-disable-next-line @typescript-eslint/no-explicit-any + queryOptions?: QnAMakerOptions, ): Promise { const requestOptions: QnAMakerOptions = { ...this._options, ...queryOptions }; const { scoreThreshold, top, strictFilters, metadataBoost, context, qnaId } = requestOptions; @@ -216,7 +218,7 @@ export class LanguageServiceUtils { private validateScoreThreshold(scoreThreshold: number): void { if (typeof scoreThreshold !== 'number' || !(scoreThreshold > 0 && scoreThreshold <= 1)) { throw new TypeError( - `"${scoreThreshold}" is an invalid scoreThreshold. QnAMakerOptions.scoreThreshold must have a value between 0 and 1.` + `"${scoreThreshold}" is an invalid scoreThreshold. QnAMakerOptions.scoreThreshold must have a value between 0 and 1.`, ); } } @@ -224,7 +226,7 @@ export class LanguageServiceUtils { private validateTop(qnaOptionTop: number): void { if (!Number.isInteger(qnaOptionTop) || qnaOptionTop < 1) { throw new RangeError( - `"${qnaOptionTop}" is an invalid top value. QnAMakerOptions.top must be an integer greater than 0.` + `"${qnaOptionTop}" is an invalid top value. QnAMakerOptions.top must be an integer greater than 0.`, ); } } @@ -232,7 +234,7 @@ export class LanguageServiceUtils { private getFilters( strictFilters: QnAMakerMetadata[], metadataJoinOperator: JoinOperator, - filters: Filters + filters: Filters, ): Filters { if (filters) { return filters; diff --git a/libraries/botbuilder-ai/tests/languageService.test.js b/libraries/botbuilder-ai/tests/languageService.test.js index df5812f6e7..a78f0ca309 100644 --- a/libraries/botbuilder-ai/tests/languageService.test.js +++ b/libraries/botbuilder-ai/tests/languageService.test.js @@ -50,6 +50,7 @@ describe('LanguageService', function () { }; let sandbox; + beforeEach(function () { sandbox = sinon.createSandbox(); nock.cleanAll(); @@ -63,7 +64,7 @@ describe('LanguageService', function () { nock(`https://${hostname}.cognitiveservices.azure.com`) .matchHeader('user-Agent', /botbuilder-ai\/4.*/) .post( - `/language/:query-knowledgebases?projectName=${knowledgeBaseId}&deploymentName=production&api-version=2021-10-01` + `/language/:query-knowledgebases?projectName=${knowledgeBaseId}&deploymentName=production&api-version=2021-10-01`, ) .replyWithFile(200, `${filePath}${file}`); }); @@ -160,7 +161,7 @@ describe('LanguageService', function () { sinon.match({ telemetryClient: sinon.match.instanceOf(NullTelemetryClient), logPersonalInformation: false, - }) + }), ); }); @@ -173,7 +174,7 @@ describe('LanguageService', function () { sinon.match({ telemetryClient: sinon.match.instanceOf(NullTelemetryClient), logPersonalInformation: false, - }) + }), ); }); }); @@ -425,7 +426,7 @@ describe('LanguageService', function () { metrics: sinon.match({ score: sinon.match.number, }), - }) + }), ) .once(); @@ -457,7 +458,7 @@ describe('LanguageService', function () { questionId: '-1', username: sinon.match.string, }), - }) + }), ) .once(); @@ -491,7 +492,7 @@ describe('LanguageService', function () { metrics: sinon.match({ score: sinon.match.number, }), - }) + }), ) .once(); @@ -518,7 +519,7 @@ describe('LanguageService', function () { foo: 'bar', ImportantProperty: 'ImportantValue', }), - }) + }), ) .once(); @@ -538,7 +539,7 @@ describe('LanguageService', function () { metrics: sinon.match({ score: sinon.match.number, }), - }) + }), ) .once(); @@ -573,7 +574,7 @@ describe('LanguageService', function () { username: sinon.match.string, }), metrics: sinon.match({ score }), - }) + }), ) .once(); @@ -584,7 +585,7 @@ describe('LanguageService', function () { context, null, { question: 'OVERRIDE', MyImportantProperty: 'MyImportantValue' }, - { score } + { score }, ); sandbox.verify(); @@ -701,6 +702,7 @@ describe('LanguageService', function () { }); }); }); + describe('QnAMakerDialog', function () { it('Construct QnAMakerDialog constructor with new LanguageService parameters', async function () { const strictFilters = [ diff --git a/libraries/botbuilder-ai/tests/luisRecognizer.test.js b/libraries/botbuilder-ai/tests/luisRecognizer.test.js index 466f49bead..3534b341c0 100644 --- a/libraries/botbuilder-ai/tests/luisRecognizer.test.js +++ b/libraries/botbuilder-ai/tests/luisRecognizer.test.js @@ -1,4 +1,3 @@ -/* eslint-disable security/detect-non-literal-fs-filename */ const assert = require('assert'); const fs = require('fs-extra'); const nock = require('nock'); @@ -30,7 +29,7 @@ class ThrowErrorRecognizer extends LuisRecognizer { super( { applicationId: luisAppId, endpointKey: endpointKey }, { includeAllIntents: true, includeInstanceData: true }, - true + true, ); } @@ -138,7 +137,6 @@ function getExpectedData(oracle) { const query = 'verbose=(true|false)&staging=false&spellCheck=false&log=true'; const path = `/luis/v2\\.0/apps/${luisAppId}`; const pattern = `${path}\\?${query}`; - // eslint-disable-next-line security/detect-non-literal-regexp const uri = new RegExp(pattern); const requestContent = expectedData.text != undefined ? `"${expectedData.text}"` : undefined; const responseBody = expectedData.v2; @@ -171,7 +169,7 @@ async function testJson( telemetryClient, telemetryMetrics, telemetryProperties, - } = {} + } = {}, ) { const expectedPath = getExpectedPath(file); const expectedData = getExpectedData(expectedPath); @@ -187,7 +185,7 @@ async function testJson( logPersonalInformation, telemetryClient, }, - true + true, ); const result = await recognizer.recognize(context, telemetryProperties, telemetryMetrics); @@ -209,7 +207,7 @@ describe('LuisRecognizer', function () { const recognizer = new LuisRecognizer( { applicationId: luisAppId, endpointKey: endpointKey }, { includeAllIntents: true }, - true + true, ); const maybeIt = !mockLuis && endpointKey === 'MockedKey' ? it.skip : it; @@ -401,7 +399,7 @@ describe('LuisRecognizer', function () { assert(res.entities.Address[0].$instance.State[0].score); assert( res.entities.Address[0].$instance.State[0].score > 0 && - res.entities.Address[0].$instance.State[0].score <= 1 + res.entities.Address[0].$instance.State[0].score <= 1, ); }); @@ -410,7 +408,7 @@ describe('LuisRecognizer', function () { const recognizer = new LuisRecognizer( { applicationId: luisAppId, endpointKey: endpointKey }, - { includeAllIntents: true, apiVersion: 'v2', includeAPIResults: true } + { includeAllIntents: true, apiVersion: 'v2', includeAPIResults: true }, ); const context = new TestContext({ text: expectedData.text }); @@ -601,7 +599,7 @@ describe('LuisRecognizer', function () { const recognizer = new ThrowErrorRecognizer(); const context = new TestContext({ text: 'Hello world!' }); await assert.rejects(recognizer.recognize(context), Error('Test')); - } + }, ); maybeIt('should send user-agent header.', async () => { @@ -634,8 +632,8 @@ describe('LuisRecognizer', function () { assert.throws( () => new LuisRecognizer(endpointWithNoSubscriptionKey), new Error( - `Invalid \`endpointKey\` value detected: ${expectedSubscriptionKey}\nPlease make sure your endpointKey is a valid LUIS Endpoint Key, e.g. "048ec46dc58e495482b0c447cfdbd291".` - ) + `Invalid \`endpointKey\` value detected: ${expectedSubscriptionKey}\nPlease make sure your endpointKey is a valid LUIS Endpoint Key, e.g. "048ec46dc58e495482b0c447cfdbd291".`, + ), ); }); @@ -646,8 +644,8 @@ describe('LuisRecognizer', function () { assert.throws( () => new LuisRecognizer(endpointWithNoAppId), new Error( - `Invalid \`applicationId\` value detected: ${expectedApplicationId}\nPlease make sure your applicationId is a valid LUIS Application Id, e.g. "b31aeaf3-3511-495b-a07f-571fc873214b".` - ) + `Invalid \`applicationId\` value detected: ${expectedApplicationId}\nPlease make sure your applicationId is a valid LUIS Application Id, e.g. "b31aeaf3-3511-495b-a07f-571fc873214b".`, + ), ); }); @@ -655,8 +653,8 @@ describe('LuisRecognizer', function () { assert.throws( () => new LuisRecognizer('this.is.not.a.url'), new Error( - `Invalid \`applicationId\` value detected: ${expectedApplicationId}\nPlease make sure your applicationId is a valid LUIS Application Id, e.g. "b31aeaf3-3511-495b-a07f-571fc873214b".` - ) + `Invalid \`applicationId\` value detected: ${expectedApplicationId}\nPlease make sure your applicationId is a valid LUIS Application Id, e.g. "b31aeaf3-3511-495b-a07f-571fc873214b".`, + ), ); }); @@ -917,7 +915,7 @@ describe('LuisRecognizer', function () { telemetryClient: telemetryClient, logPersonalInformation: true, }, - true + true, ); const res = await recognizer.recognize(context, properties, metrics); @@ -998,7 +996,7 @@ describe('LuisRecognizer', function () { telemetryClient: telemetryClient, logPersonalInformation: true, }, - true + true, ); const res = await recognizer.recognize(context, properties, metrics); @@ -1037,7 +1035,7 @@ describe('LuisRecognizer', function () { const recognizer = new LuisRecognizer( { applicationId: luisAppId, endpointKey: endpointKey }, luisPredictionDefaultOptions, - true + true, ); const mergedOptions = luisPredictionUserOptions ? recognizer.setLuisPredictionOptions(recognizer.options, luisPredictionUserOptions) @@ -1060,7 +1058,7 @@ describe('LuisRecognizer', function () { const recognizer = new LuisRecognizer( { applicationId: luisAppId, endpointKey: endpointKey }, luisPredictionDefaultOptions, - true + true, ); const mergedOptions = recognizer.buildRecognizer(luisPredictionUserOptions); assert.strictEqual(mergedOptions.predictionOptions.includeAllIntents, false); @@ -1081,7 +1079,7 @@ describe('LuisRecognizer', function () { const recognizer = new LuisRecognizer( { applicationId: luisAppId, endpointKey: endpointKey }, luisPredictionDefaultOptions, - true + true, ); const mergedOptions = recognizer.buildRecognizer(luisPredictionUserOptions); assert.strictEqual(mergedOptions.options.includeAllIntents, false); @@ -1098,7 +1096,7 @@ describe('LuisRecognizer', function () { const recognizer = new LuisRecognizer( { applicationId: luisAppId, endpointKey: endpointKey }, luisPredictionDefaultOptions, - true + true, ); const mergedOptions = luisPredictionUserOptions ? recognizer.setLuisPredictionOptions(recognizer.options, luisPredictionUserOptions) diff --git a/libraries/botbuilder-ai/tests/luisSdk.test.js b/libraries/botbuilder-ai/tests/luisSdk.test.js index 8ecf61352a..c5d9668c02 100644 --- a/libraries/botbuilder-ai/tests/luisSdk.test.js +++ b/libraries/botbuilder-ai/tests/luisSdk.test.js @@ -25,7 +25,7 @@ function GetExpected(oracle) { const query = 'verbose=(true|false)(&staging=false&spellCheck=false&log=true|)'; const path = `/luis/v2\\.0/apps/${applicationId}`; const pattern = `${path}\\?${query}`; - const uri = new RegExp(pattern); // eslint-disable-line security/detect-non-literal-regexp + const uri = new RegExp(pattern); const requestContent = expected.text != undefined ? `"${expected.text}"` : undefined; const responseBody = expected; @@ -145,25 +145,31 @@ describe('LuisPredict', function () { this.timeout(10000); if (!mockLuis && k === 'MockedKey') { console.warn( - 'WARNING: skipping LuisRecognizer test suite because the LUISAPPKEY environment variable is not defined' + 'WARNING: skipping LuisRecognizer test suite because the LUISAPPKEY environment variable is not defined', ); return; } + it('test built-ins composite1', async function () { await TestJson('Composite1.json'); }); + it('test built-ins composite2', async function () { await TestJson('Composite2.json'); }); + it('test built-ins composite3', async function () { await TestJson('Composite3.json'); }); + it('test built-ins prebuilt', async function () { await TestJson('Prebuilt.json'); }); + it('test patterns', async function () { await TestJson('Patterns.json'); }); + it('should return single intent and a simple entity', async function () { const result = await TestJson('SingleIntent_SimplyEntity.json', false); diff --git a/libraries/botbuilder-ai/tests/luisV3OracleTests.test.js b/libraries/botbuilder-ai/tests/luisV3OracleTests.test.js index 4f52838edb..2148ada608 100644 --- a/libraries/botbuilder-ai/tests/luisV3OracleTests.test.js +++ b/libraries/botbuilder-ai/tests/luisV3OracleTests.test.js @@ -30,7 +30,7 @@ async function TestJson( telemetryProperties, telemetryMetrics, logPersonalInformation, - useUtteranceInsteadOfContext = false + useUtteranceInsteadOfContext = false, ) { if (includeAllIntents === undefined) includeAllIntents = true; if (includeInstance === undefined) includeInstance = true; @@ -117,7 +117,7 @@ describe('LuisRecognizer V3', function () { if (!mockLuis && endpointKey === 'MockedKey') { console.warn( - 'WARNING: skipping LuisRecognizer test suite because the LUISAPPKEY environment variable is not defined' + 'WARNING: skipping LuisRecognizer test suite because the LUISAPPKEY environment variable is not defined', ); return; } @@ -136,7 +136,7 @@ describe('LuisRecognizer V3', function () { undefined, undefined, undefined, - useUtteranceInsteadOfContext + useUtteranceInsteadOfContext, ); }); @@ -154,7 +154,7 @@ describe('LuisRecognizer V3', function () { undefined, undefined, undefined, - useUtteranceInsteadOfContext + useUtteranceInsteadOfContext, ); }); diff --git a/libraries/botbuilder-ai/tests/qnaMaker.test.js b/libraries/botbuilder-ai/tests/qnaMaker.test.js index 8c3c2eede4..63a376a796 100644 --- a/libraries/botbuilder-ai/tests/qnaMaker.test.js +++ b/libraries/botbuilder-ai/tests/qnaMaker.test.js @@ -49,6 +49,7 @@ describe('QnAMaker', function () { }; let sandbox; + beforeEach(function () { sandbox = sinon.createSandbox(); nock.cleanAll(); @@ -157,7 +158,7 @@ describe('QnAMaker', function () { sinon.match({ telemetryClient: sinon.match.instanceOf(NullTelemetryClient), logPersonalInformation: false, - }) + }), ); }); @@ -170,7 +171,7 @@ describe('QnAMaker', function () { sinon.match({ telemetryClient: sinon.match.instanceOf(NullTelemetryClient), logPersonalInformation: false, - }) + }), ); }); }); @@ -195,6 +196,7 @@ describe('QnAMaker', function () { assert.deepStrictEqual(results[0].metadata, filters.metadataFilter.metadata); }); + it('returns answer with strictFilters specified', async function () { const qna = new QnAMaker(endpoint); const context = new TestContext({ text: 'where are the unicorns?' }); @@ -214,6 +216,7 @@ describe('QnAMaker', function () { assert.deepStrictEqual(results[0].metadata, strictFilters); }); + it('returns answer without any options specified', async function () { const qna = new QnAMaker(endpoint); const context = new TestContext({ text: 'where are the unicorns?' }); @@ -361,7 +364,7 @@ describe('QnAMaker', function () { sinon.match({ id: qnaId, qnaId: sinon.match.undefined, - }) + }), ); }); @@ -432,7 +435,7 @@ describe('QnAMaker', function () { metrics: sinon.match({ score: sinon.match.number, }), - }) + }), ) .once(); @@ -464,7 +467,7 @@ describe('QnAMaker', function () { articleFound: 'true', }), metrics: { score: 0 }, - }) + }), ) .once(); @@ -499,7 +502,7 @@ describe('QnAMaker', function () { metrics: sinon.match({ score: sinon.match.number, }), - }) + }), ) .once(); @@ -526,7 +529,7 @@ describe('QnAMaker', function () { foo: 'bar', ImportantProperty: 'ImportantValue', }), - }) + }), ) .once(); @@ -546,7 +549,7 @@ describe('QnAMaker', function () { metrics: sinon.match({ score: sinon.match.number, }), - }) + }), ) .once(); @@ -581,7 +584,7 @@ describe('QnAMaker', function () { username: sinon.match.string, }), metrics: sinon.match({ score }), - }) + }), ) .once(); @@ -592,7 +595,7 @@ describe('QnAMaker', function () { context, null, { question: 'OVERRIDE', MyImportantProperty: 'MyImportantValue' }, - { score } + { score }, ); sandbox.verify(); @@ -610,6 +613,7 @@ describe('QnAMaker', function () { message: 'QnAMaker.getAnswers() requires a TurnContext.', }); }); + it('throws TypeError if context is undefined in getAnswersRaw', async function () { const qna = new QnAMaker(endpoint); @@ -703,7 +707,7 @@ describe('QnAMaker', function () { assert(found); const traceActivity = context.sent.find( - (activity) => activity.type === 'trace' && activity.name === 'QnAMaker' + (activity) => activity.type === 'trace' && activity.name === 'QnAMaker', ); sinon.assert.match( @@ -719,7 +723,7 @@ describe('QnAMaker', function () { knowledgeBaseId, scoreThreshold: sinon.match.number, }), - }) + }), ); }); diff --git a/libraries/botbuilder-ai/tests/qnaMakerDialog.test.js b/libraries/botbuilder-ai/tests/qnaMakerDialog.test.js index 77d9db5f5f..8e6e084267 100644 --- a/libraries/botbuilder-ai/tests/qnaMakerDialog.test.js +++ b/libraries/botbuilder-ai/tests/qnaMakerDialog.test.js @@ -20,8 +20,7 @@ const { const KB_ID = process.env.QNAKNOWLEDGEBASEID; const ENDPOINT_KEY = process.env.QNAENDPOINTKEY; const HOSTNAME = process.env.QNAHOSTNAME || 'test-qna-app'; -const isMockQna = false || !(KB_ID && ENDPOINT_KEY); - +const isMockQna = !(KB_ID && ENDPOINT_KEY); const beginMessage = { text: 'begin', type: 'message' }; describe('QnAMakerDialog', function () { @@ -297,6 +296,7 @@ describe('QnAMakerDialog', function () { describe('Active Learning', function () { let sandbox; const testFilesPath = `${__dirname}/TestData/QnAMakerDialog/`; + beforeEach(function () { nock.cleanAll(); nock(`https://${HOSTNAME}.azurewebsites.net`) @@ -329,7 +329,7 @@ describe('QnAMakerDialog', function () { undefined, undefined, activeLearningCardTitle, - cardNoMatchText + cardNoMatchText, ); dm.rootDialog = qnaDialog; @@ -386,7 +386,7 @@ describe('QnAMakerDialog', function () { undefined, undefined, activeLearningCardTitle, - cardNoMatchText + cardNoMatchText, ); qnaDialog.useTeamsAdaptiveCard = true; @@ -447,7 +447,7 @@ describe('QnAMakerDialog', function () { strictEqual(noMatchingQuestionsText, cardNoMatchText); return MessageFactory.suggestedActions(suggestionsList, noMatchingQuestionsText); }, - cardNoMatchText + cardNoMatchText, ); dm.rootDialog = qnaDialog; @@ -470,7 +470,7 @@ describe('QnAMakerDialog', function () { const endpointKey = 'dummyEndpointKey'; throws( () => new QnAMakerDialog(kbId, endpointKey, HOSTNAME, undefined, undefined, (_) => {}, undefined), - new Error('cardNoMatchText is required when using the suggestionsActivityFactory.') + new Error('cardNoMatchText is required when using the suggestionsActivityFactory.'), ); }); @@ -493,7 +493,7 @@ describe('QnAMakerDialog', function () { strictEqual(noMatchingQuestionsText, cardNoMatchText); return 1; }, - cardNoMatchText + cardNoMatchText, ); dm.rootDialog = qnaDialog; @@ -506,7 +506,7 @@ describe('QnAMakerDialog', function () { (thrown) => thrown.message.includes('invalid_type') && thrown.message.includes('"expected": "object"') && - thrown.message.includes('"received": "number"') + thrown.message.includes('"received": "number"'), ); }); @@ -535,7 +535,7 @@ describe('QnAMakerDialog', function () { undefined, undefined, suggestionsCardTitle, - cardNoMatchText + cardNoMatchText, ); dm.rootDialog = qnaDialog; @@ -545,7 +545,7 @@ describe('QnAMakerDialog', function () { await rejects( adapter.send('QnaMaker_TopNAnswer.json').startTest(), - (thrown) => thrown.message.includes('invalid_type') && thrown.message.includes('Required') + (thrown) => thrown.message.includes('invalid_type') && thrown.message.includes('Required'), ); sandbox.verify(); @@ -576,7 +576,7 @@ describe('QnAMakerDialog', function () { undefined, undefined, suggestionsCardTitle, - cardNoMatchText + cardNoMatchText, ); qnaDialog.useTeamsAdaptiveCard = true; @@ -587,7 +587,7 @@ describe('QnAMakerDialog', function () { await rejects( adapter.send('QnaMaker_TopNAnswer.json').startTest(), - (thrown) => thrown.message.includes('invalid_type') && thrown.message.includes('Required') + (thrown) => thrown.message.includes('invalid_type') && thrown.message.includes('Required'), ); sandbox.verify(); diff --git a/libraries/botbuilder-ai/tests/qnaMakerRecognizer.test.js b/libraries/botbuilder-ai/tests/qnaMakerRecognizer.test.js index eab050fd35..cd00ef2cd3 100644 --- a/libraries/botbuilder-ai/tests/qnaMakerRecognizer.test.js +++ b/libraries/botbuilder-ai/tests/qnaMakerRecognizer.test.js @@ -42,7 +42,7 @@ const validateAnswers = (result) => { strictEqual( Object.entries(result.entities.answer).length, 1, - 'if there is a match there should only be 1 top answer' + 'if there is a match there should only be 1 top answer', ); strictEqual(result.entities.$instance.answer[0].startIndex, 0); ok(result.entities.$instance.answer[0].endIndex);