diff --git a/libraries/botbuilder-ai/etc/botbuilder-ai.api.md b/libraries/botbuilder-ai/etc/botbuilder-ai.api.md index 9bf6f33b32..780e37e44e 100644 --- a/libraries/botbuilder-ai/etc/botbuilder-ai.api.md +++ b/libraries/botbuilder-ai/etc/botbuilder-ai.api.md @@ -23,12 +23,12 @@ import { DialogTurnResult } from 'botbuilder-dialogs'; import { EnumExpression } from 'adaptive-expressions'; import { Expression } from 'adaptive-expressions'; import { IntExpression } from 'adaptive-expressions'; -import * as msRest from '@azure/ms-rest-js'; import { NumberExpression } from 'adaptive-expressions'; import { ObjectExpression } from 'adaptive-expressions'; import { Recognizer } from 'botbuilder-dialogs'; import { RecognizerConfiguration } from 'botbuilder-dialogs'; import { RecognizerResult } from 'botbuilder-core'; +import { RequestOptionsBase } from '@azure/core-http'; import { ServiceCollection } from 'botbuilder-dialogs-adaptive-runtime-core'; import { StringExpression } from 'adaptive-expressions'; import { TemplateInterface } from 'botbuilder-dialogs'; @@ -290,7 +290,7 @@ export class LuisComponentRegistration extends ComponentRegistration { } // @public -export interface LuisPredictionOptions extends msRest.RequestOptionsBase { +export interface LuisPredictionOptions extends RequestOptionsBase { bingSpellCheckSubscriptionKey?: string; includeAllIntents?: boolean; includeInstanceData?: boolean; diff --git a/libraries/botbuilder-ai/package.json b/libraries/botbuilder-ai/package.json index 4691e52198..b8ff15a736 100644 --- a/libraries/botbuilder-ai/package.json +++ b/libraries/botbuilder-ai/package.json @@ -27,13 +27,13 @@ } }, "dependencies": { - "@azure/cognitiveservices-luis-runtime": "^4.0.0", - "@azure/ms-rest-js": "^2.7.0", + "@azure/core-http": "^3.0.2", "adaptive-expressions": "4.1.6", "botbuilder-core": "4.1.6", "botbuilder-dialogs": "4.1.6", "botbuilder-dialogs-adaptive-runtime-core": "4.1.6", "botbuilder-dialogs-declarative": "4.1.6", + "botframework-connector": "4.1.6", "lodash": "^4.17.21", "node-fetch": "^2.6.7", "url-parse": "^1.5.9", diff --git a/libraries/botbuilder-ai/src/luisRecognizer.ts b/libraries/botbuilder-ai/src/luisRecognizer.ts index 14a0647247..7f8b7458a7 100644 --- a/libraries/botbuilder-ai/src/luisRecognizer.ts +++ b/libraries/botbuilder-ai/src/luisRecognizer.ts @@ -5,7 +5,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import * as msRest from '@azure/ms-rest-js'; +import { RequestOptionsBase } from '@azure/core-http'; import Url from 'url-parse'; import { BotTelemetryClient, NullTelemetryClient, RecognizerResult, TurnContext } from 'botbuilder-core'; @@ -41,7 +41,7 @@ export interface LuisApplication { * * Options per LUIS prediction. */ -export interface LuisPredictionOptions extends msRest.RequestOptionsBase { +export interface LuisPredictionOptions extends RequestOptionsBase { /** * If true, return all intents instead of just the top scoring intent. */ diff --git a/libraries/botbuilder-ai/src/luisRecognizerOptionsV2.ts b/libraries/botbuilder-ai/src/luisRecognizerOptionsV2.ts index 9467d15ef4..68ce30cb7b 100644 --- a/libraries/botbuilder-ai/src/luisRecognizerOptionsV2.ts +++ b/libraries/botbuilder-ai/src/luisRecognizerOptionsV2.ts @@ -6,7 +6,7 @@ * Licensed under the MIT License. */ -import * as msRest from '@azure/ms-rest-js'; +import { TokenCredentials } from 'botframework-connector'; import * as os from 'os'; import { LuisApplication, LuisRecognizerOptionsV2 } from './luisRecognizer'; import { CompositeChildModel, CompositeEntityModel, EntityModel, LuisResult } from './luisV2-models/luisResult'; @@ -50,7 +50,7 @@ export class LuisRecognizerV2 extends LuisRecognizerInternal { // - We have to cast "creds as any" to avoid a build break relating to different versions // of autorest being used by our various components. This is just a build issue and // shouldn't effect production bots. - const creds = new msRest.TokenCredentials(application.endpointKey); + 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); diff --git a/libraries/botbuilder-ai/src/luisRuntimeClientContext.ts b/libraries/botbuilder-ai/src/luisRuntimeClientContext.ts new file mode 100644 index 0000000000..c7df9e844c --- /dev/null +++ b/libraries/botbuilder-ai/src/luisRuntimeClientContext.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +import { ServiceClient, ServiceClientCredentials, ServiceClientOptions } from '@azure/core-http'; + +/** + * Client for LUIS context + */ +export class LUISRuntimeClientContext extends ServiceClient { + endpoint: string; + credentials: ServiceClientCredentials; + + /** + * Initializes a new instance of the LUISRuntimeClientContext class. + * + * @param credentials Subscription credentials which uniquely identify client subscription. + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param [options] The parameter options + */ + constructor(credentials: ServiceClientCredentials, endpoint: string, options?: ServiceClientOptions) { + if (endpoint == undefined) { + throw new Error("'endpoint' cannot be null."); + } + if (credentials == undefined) { + throw new Error("'credentials' cannot be null."); + } + + if (!options) { + options = {}; + } + + super(credentials, options); + + this.baseUri = '{Endpoint}/luis/v3.0-preview'; + this.requestContentType = 'application/json; charset=utf-8'; + this.endpoint = endpoint; + this.credentials = credentials; + } +} diff --git a/libraries/botbuilder-ai/src/luisV2-models/luisMappers.ts b/libraries/botbuilder-ai/src/luisV2-models/luisMappers.ts index fedb748c69..a33169405b 100644 --- a/libraries/botbuilder-ai/src/luisV2-models/luisMappers.ts +++ b/libraries/botbuilder-ai/src/luisV2-models/luisMappers.ts @@ -6,9 +6,9 @@ * Licensed under the MIT License. */ -import * as msRest from '@azure/ms-rest-js'; +import { CompositeMapper } from '@azure/core-http'; -export const IntentModel: msRest.CompositeMapper = { +export const IntentModel: CompositeMapper = { serializedName: 'IntentModel', type: { name: 'Composite', @@ -34,7 +34,7 @@ export const IntentModel: msRest.CompositeMapper = { }, }; -export const EntityModel: msRest.CompositeMapper = { +export const EntityModel: CompositeMapper = { serializedName: 'EntityModel', type: { name: 'Composite', @@ -77,7 +77,7 @@ export const EntityModel: msRest.CompositeMapper = { }, }; -export const CompositeChildModel: msRest.CompositeMapper = { +export const CompositeChildModel: CompositeMapper = { serializedName: 'CompositeChildModel', type: { name: 'Composite', @@ -101,7 +101,7 @@ export const CompositeChildModel: msRest.CompositeMapper = { }, }; -export const CompositeEntityModel: msRest.CompositeMapper = { +export const CompositeEntityModel: CompositeMapper = { serializedName: 'CompositeEntityModel', type: { name: 'Composite', @@ -138,7 +138,7 @@ export const CompositeEntityModel: msRest.CompositeMapper = { }, }; -export const Sentiment: msRest.CompositeMapper = { +export const Sentiment: CompositeMapper = { serializedName: 'Sentiment', type: { name: 'Composite', @@ -160,7 +160,7 @@ export const Sentiment: msRest.CompositeMapper = { }, }; -export const LuisResult: msRest.CompositeMapper = { +export const LuisResult: CompositeMapper = { serializedName: 'LuisResult', type: { name: 'Composite', @@ -244,7 +244,7 @@ export const LuisResult: msRest.CompositeMapper = { }, }; -export const EntityWithScore: msRest.CompositeMapper = { +export const EntityWithScore: CompositeMapper = { serializedName: 'EntityWithScore', type: { name: 'Composite', @@ -267,7 +267,7 @@ export const EntityWithScore: msRest.CompositeMapper = { }, }; -export const EntityWithResolution: msRest.CompositeMapper = { +export const EntityWithResolution: CompositeMapper = { serializedName: 'EntityWithResolution', type: { name: 'Composite', @@ -286,7 +286,7 @@ export const EntityWithResolution: msRest.CompositeMapper = { }, }; -export const APIError: msRest.CompositeMapper = { +export const APIError: CompositeMapper = { serializedName: 'APIError', type: { name: 'Composite', diff --git a/libraries/botbuilder-ai/src/luisV2-models/luisModels.ts b/libraries/botbuilder-ai/src/luisV2-models/luisModels.ts new file mode 100644 index 0000000000..367bb25983 --- /dev/null +++ b/libraries/botbuilder-ai/src/luisV2-models/luisModels.ts @@ -0,0 +1,268 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +import { RequestOptionsBase, HttpResponse } from '@azure/core-http'; + +/** + * Represents an intent prediction. + */ +export interface Intent { + /** + * The score of the fired intent. + */ + score?: number; + /** + * The prediction of the dispatched application. + */ + childApp?: Prediction; +} + +/** + * The result of the sentiment analysis. + */ +export interface Sentiment { + /** + * The label of the sentiment analysis result. + */ + label?: string; + /** + * The sentiment score of the query. + */ + score: number; +} + +/** + * Represents the prediction of a query. + */ +export interface Prediction { + /** + * The query after pre-processing and normalization. + */ + normalizedQuery: string; + /** + * The query after spell checking. Only set if spell check was enabled and a spelling mistake was + * found. + */ + alteredQuery?: string; + /** + * The name of the top scoring intent. + */ + topIntent: string; + /** + * A dictionary representing the intents that fired. + */ + intents: { [propertyName: string]: Intent }; + /** + * The dictionary representing the entities that fired. + */ + entities: { [propertyName: string]: any }; + /** + * The result of the sentiment analysis. + */ + sentiment?: Sentiment; +} + +/** + * Represents the prediction response. + */ +export interface PredictionResponse { + /** + * The query used in the prediction. + */ + query: string; + /** + * The prediction of the requested query. + */ + prediction: Prediction; +} + +/** + * Represents the definition of the error that occurred. + */ +export interface ErrorBody { + /** + * The error code. + */ + code: string; + /** + * The error message. + */ + message: string; +} + +/** + * Represents the error that occurred. + */ +export interface ErrorModel { + error: ErrorBody; +} + +/** + * The custom options for the prediction request. + */ +export interface PredictionRequestOptions { + /** + * The reference DateTime used for predicting datetime entities. + */ + datetimeReference?: Date; + /** + * Whether to make the external entities resolution override the predictions if an overlap + * occurs. + */ + overridePredictions?: boolean; +} + +/** + * Defines a user predicted entity that extends an already existing one. + */ +export interface ExternalEntity { + /** + * The name of the entity to extend. + */ + entityName: string; + /** + * The start character index of the predicted entity. + */ + startIndex: number; + /** + * The length of the predicted entity. + */ + entityLength: number; + /** + * A user supplied custom resolution to return as the entity's prediction. + */ + resolution?: any; +} + +/** + * Defines a sub-list to append to an existing list entity. + */ +export interface RequestList { + /** + * The name of the sub-list. + */ + name?: string; + /** + * The canonical form of the sub-list. + */ + canonicalForm: string; + /** + * The synonyms of the canonical form. + */ + synonyms?: string[]; +} + +/** + * Defines an extension for a list entity. + */ +export interface DynamicList { + /** + * The name of the list entity to extend. + */ + listEntityName: string; + /** + * The lists to append on the extended list entity. + */ + requestLists: RequestList[]; +} + +/** + * Represents the prediction request parameters. + */ +export interface PredictionRequest { + /** + * The query to predict. + */ + query: string; + /** + * The custom options defined for this request. + */ + options?: PredictionRequestOptions; + /** + * The externally predicted entities for this request. + */ + externalEntities?: ExternalEntity[]; + /** + * The dynamically created list entities for this request. + */ + dynamicLists?: DynamicList[]; +} + +/** + * Optional Parameters. + */ +export interface PredictionGetVersionPredictionOptionalParams extends RequestOptionsBase { + /** + * Indicates whether to get extra metadata for the entities predictions or not. + */ + verbose?: boolean; + /** + * Indicates whether to return all the intents in the response or just the top intent. + */ + showAllIntents?: boolean; + /** + * Indicates whether to log the endpoint query or not. + */ + log?: boolean; +} + +/** + * Optional Parameters. + */ +export interface PredictionGetSlotPredictionOptionalParams extends RequestOptionsBase { + /** + * Indicates whether to get extra metadata for the entities predictions or not. + */ + verbose?: boolean; + /** + * Indicates whether to return all the intents in the response or just the top intent. + */ + showAllIntents?: boolean; + /** + * Indicates whether to log the endpoint query or not. + */ + log?: boolean; +} + +/** + * Contains response data for the getVersionPrediction operation. + */ +export type PredictionGetVersionPredictionResponse = PredictionResponse & { + /** + * The underlying HTTP response. + */ + _response: HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: PredictionResponse; + }; +}; + +/** + * Contains response data for the getSlotPrediction operation. + */ +export type PredictionGetSlotPredictionResponse = PredictionResponse & { + /** + * The underlying HTTP response. + */ + _response: HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: PredictionResponse; + }; +}; diff --git a/libraries/botbuilder-ai/src/luisV2-models/luisParameters.ts b/libraries/botbuilder-ai/src/luisV2-models/luisParameters.ts index 4cd610964b..8ff31939a0 100644 --- a/libraries/botbuilder-ai/src/luisV2-models/luisParameters.ts +++ b/libraries/botbuilder-ai/src/luisV2-models/luisParameters.ts @@ -6,9 +6,9 @@ * Licensed under the MIT License. */ -import * as msRest from '@azure/ms-rest-js'; +import { OperationURLParameter, OperationQueryParameter } from '@azure/core-http'; -export const appId: msRest.OperationURLParameter = { +export const appId: OperationURLParameter = { parameterPath: 'appId', mapper: { required: true, @@ -18,7 +18,7 @@ export const appId: msRest.OperationURLParameter = { }, }, }; -export const bingSpellCheckSubscriptionKey: msRest.OperationQueryParameter = { +export const bingSpellCheckSubscriptionKey: OperationQueryParameter = { parameterPath: ['options', 'bingSpellCheckSubscriptionKey'], mapper: { serializedName: 'bing-spell-check-subscription-key', @@ -27,7 +27,7 @@ export const bingSpellCheckSubscriptionKey: msRest.OperationQueryParameter = { }, }, }; -export const endpoint: msRest.OperationURLParameter = { +export const endpoint: OperationURLParameter = { parameterPath: 'endpoint', mapper: { required: true, @@ -39,7 +39,7 @@ export const endpoint: msRest.OperationURLParameter = { }, skipEncoding: true, }; -export const log: msRest.OperationQueryParameter = { +export const log: OperationQueryParameter = { parameterPath: ['options', 'log'], mapper: { serializedName: 'log', @@ -48,7 +48,7 @@ export const log: msRest.OperationQueryParameter = { }, }, }; -export const spellCheck: msRest.OperationQueryParameter = { +export const spellCheck: OperationQueryParameter = { parameterPath: ['options', 'spellCheck'], mapper: { serializedName: 'spellCheck', @@ -57,7 +57,7 @@ export const spellCheck: msRest.OperationQueryParameter = { }, }, }; -export const staging: msRest.OperationQueryParameter = { +export const staging: OperationQueryParameter = { parameterPath: ['options', 'staging'], mapper: { serializedName: 'staging', @@ -66,7 +66,7 @@ export const staging: msRest.OperationQueryParameter = { }, }, }; -export const timezoneOffset: msRest.OperationQueryParameter = { +export const timezoneOffset: OperationQueryParameter = { parameterPath: ['options', 'timezoneOffset'], mapper: { serializedName: 'timezoneOffset', @@ -75,7 +75,7 @@ export const timezoneOffset: msRest.OperationQueryParameter = { }, }, }; -export const verbose: msRest.OperationQueryParameter = { +export const verbose: OperationQueryParameter = { parameterPath: ['options', 'verbose'], mapper: { serializedName: 'verbose', diff --git a/libraries/botbuilder-ai/src/luisV2-models/luisPrediction.ts b/libraries/botbuilder-ai/src/luisV2-models/luisPrediction.ts index 08644a3114..5ed5aa9648 100644 --- a/libraries/botbuilder-ai/src/luisV2-models/luisPrediction.ts +++ b/libraries/botbuilder-ai/src/luisV2-models/luisPrediction.ts @@ -6,8 +6,8 @@ * Licensed under the MIT License. */ -import * as msRest from '@azure/ms-rest-js'; -import { LUISRuntimeClientContext } from '@azure/cognitiveservices-luis-runtime'; +import { ServiceCallback, OperationSpec, Serializer } from '@azure/core-http'; +import { LUISRuntimeClientContext } from '../luisRuntimeClientContext'; import { LuisResult, PredictionResolveOptionalParams, PredictionResolveResponse } from './luisResult'; import * as Parameters from './luisParameters'; import * as Mappers from './luisMappers'; @@ -44,7 +44,7 @@ export class LuisPrediction { * @param query The utterance to predict. * @param callback The callback */ - resolve(appId: string, query: string, callback: msRest.ServiceCallback): void; + resolve(appId: string, query: string, callback: ServiceCallback): void; /** * @param appId The LUIS application ID (Guid). * @param query The utterance to predict. @@ -55,7 +55,7 @@ export class LuisPrediction { appId: string, query: string, options: PredictionResolveOptionalParams, - callback: msRest.ServiceCallback + callback: ServiceCallback ): void; /** * @param appId The LUIS application ID (Guid). @@ -67,8 +67,8 @@ export class LuisPrediction { resolve( appId: string, query: string, - options?: PredictionResolveOptionalParams | msRest.ServiceCallback, - callback?: msRest.ServiceCallback + options?: PredictionResolveOptionalParams | ServiceCallback, + callback?: ServiceCallback ): Promise { return this.client.sendOperationRequest( { @@ -83,8 +83,8 @@ export class LuisPrediction { } // Operation Specifications -const serializer = new msRest.Serializer(Mappers); -const resolveOperationSpec: msRest.OperationSpec = { +const serializer = new Serializer(Mappers); +const resolveOperationSpec: OperationSpec = { httpMethod: 'POST', path: 'apps/{appId}', urlParameters: [Parameters.endpoint, Parameters.appId], diff --git a/libraries/botbuilder-ai/src/luisV2-models/luisResult.ts b/libraries/botbuilder-ai/src/luisV2-models/luisResult.ts index e29a2bb851..3c4feb8ffd 100644 --- a/libraries/botbuilder-ai/src/luisV2-models/luisResult.ts +++ b/libraries/botbuilder-ai/src/luisV2-models/luisResult.ts @@ -6,8 +6,8 @@ * Licensed under the MIT License. */ -import { LUISRuntimeModels as LuisModels } from '@azure/cognitiveservices-luis-runtime'; -import * as msRest from '@azure/ms-rest-js'; +import { Sentiment } from './luisModels'; +import { HttpResponse, RequestOptionsBase } from '@azure/core-http'; /** * Prediction, based on the input query, containing intent(s) and entities. @@ -40,7 +40,7 @@ export interface LuisResult { /** * Sentiment of the input utterance. */ - sentimentAnalysis?: LuisModels.Sentiment; + sentimentAnalysis?: Sentiment; /** * Prediction, based on the input query, containing intents and entities. */ @@ -122,7 +122,7 @@ export interface CompositeChildModel { /** * Optional Parameters. */ -export interface PredictionResolveOptionalParams extends msRest.RequestOptionsBase { +export interface PredictionResolveOptionalParams extends RequestOptionsBase { /** * The timezone offset for the location of the request. */ @@ -156,7 +156,7 @@ export type PredictionResolveResponse = LuisResult & { /** * The underlying HTTP response. */ - _response: msRest.HttpResponse & { + _response: HttpResponse & { /** * The response body as text (string format) */ diff --git a/libraries/botbuilder-ai/src/luisV2-models/luisRuntimeClientV2.ts b/libraries/botbuilder-ai/src/luisV2-models/luisRuntimeClientV2.ts index 6a6c0529a4..8e1ee25a77 100644 --- a/libraries/botbuilder-ai/src/luisV2-models/luisRuntimeClientV2.ts +++ b/libraries/botbuilder-ai/src/luisV2-models/luisRuntimeClientV2.ts @@ -6,11 +6,11 @@ * Licensed under the MIT License. */ -import * as msRest from '@azure/ms-rest-js'; +import { ServiceClientCredentials, ServiceClientOptions } from '@azure/core-http'; import * as Models from './luisResult'; import * as Mappers from './luisMappers'; import { LuisPrediction } from './luisPrediction'; -import { LUISRuntimeClientContext } from '@azure/cognitiveservices-luis-runtime'; +import { LUISRuntimeClientContext } from '../luisRuntimeClientContext'; /** * Represents the LUIS client for V2 of the runtime. @@ -29,7 +29,7 @@ class LUISRuntimeClientV2 extends LUISRuntimeClientContext { * https://westus.api.cognitive.microsoft.com). * @param [options] The parameter options */ - constructor(credentials: msRest.ServiceClientCredentials, endpoint: string, options?: msRest.ServiceClientOptions) { + constructor(credentials: ServiceClientCredentials, endpoint: string, options?: ServiceClientOptions) { super(credentials, endpoint, options); this.prediction = new LuisPrediction(this); super.baseUri = '{Endpoint}/luis/v2.0'; diff --git a/libraries/botbuilder-ai/tests/luisRecognizer.test.js b/libraries/botbuilder-ai/tests/luisRecognizer.test.js index e2f5334b41..466f49bead 100644 --- a/libraries/botbuilder-ai/tests/luisRecognizer.test.js +++ b/libraries/botbuilder-ai/tests/luisRecognizer.test.js @@ -500,69 +500,86 @@ describe('LuisRecognizer', function () { returnStatusCode(400); const context = new TestContext({ text: 'Hello world!' }); - await assert.rejects( - recognizer.recognize(context), - new Error( - "Response 400: The request's body or parameters are incorrect, meaning they are missing, malformed, or too large." - ) - ); + const errorResponse = + "Response 400: The request's body or parameters are incorrect, meaning they are missing, malformed, or too large."; + try { + await recognizer.recognize(context); + } catch (error) { + assert.deepEqual(errorResponse, error.message); + } }); maybeIt('should throw expected 401 error message.', async () => { returnStatusCode(401); const context = new TestContext({ text: 'Hello world!' }); - await assert.rejects( - recognizer.recognize(context), - new Error("Response 401: The key used is invalid, malformed, empty, or doesn't match the region.") - ); + const errorResponse = "Response 401: The key used is invalid, malformed, empty, or doesn't match the region."; + try { + await recognizer.recognize(context); + } catch (error) { + assert.deepEqual(errorResponse, error.message); + } }); maybeIt('should throw expected 403 error message.', async () => { returnStatusCode(403); const context = new TestContext({ text: 'Hello world!' }); - await assert.rejects( - recognizer.recognize(context), - new Error('Response 403: Total monthly key quota limit exceeded.') - ); + const errorResponse = 'Response 403: Total monthly key quota limit exceeded.'; + try { + await recognizer.recognize(context); + } catch (error) { + assert.deepEqual(errorResponse, error.message); + } }); maybeIt('should throw expected 409 error message.', async () => { returnStatusCode(409); const context = new TestContext({ text: 'Hello world!' }); - await assert.rejects( - recognizer.recognize(context), - new Error('Response 409: Application loading in progress, please try again.') - ); + const errorResponse = 'Response 409: Application loading in progress, please try again.'; + try { + await recognizer.recognize(context); + } catch (error) { + assert.deepEqual(errorResponse, error.message); + } }); maybeIt('should throw expected 410 error message.', async () => { returnStatusCode(410); const context = new TestContext({ text: 'Hello world!' }); - await assert.rejects( - recognizer.recognize(context), - new Error('Response 410: Please retrain and republish your application.') - ); + const errorResponse = 'Response 410: Please retrain and republish your application.'; + try { + await recognizer.recognize(context); + } catch (error) { + assert.deepEqual(errorResponse, error.message); + } }); maybeIt('should throw expected 414 error message.', async () => { returnStatusCode(414); const context = new TestContext({ text: 'Hello world!' }); - await assert.rejects( - recognizer.recognize(context), - new Error('Response 414: The query is too long. Please reduce the query length to 500 or less characters.') - ); + const errorResponse = + 'Response 414: The query is too long. Please reduce the query length to 500 or less characters.'; + try { + await recognizer.recognize(context); + } catch (error) { + assert.deepEqual(errorResponse, error.message); + } }); maybeIt('should throw expected 429 error m`essage.', async () => { returnStatusCode(429); const context = new TestContext({ text: 'Hello world!' }); - await assert.rejects(recognizer.recognize(context), Error('Response 429: Too many requests.')); + const errorResponse = 'Response 429: Too many requests.'; + try { + await recognizer.recognize(context); + } catch (error) { + assert.deepEqual(errorResponse, error.message); + } }); maybeIt('should throw unexpected error message with correct status code.', async () => { @@ -570,12 +587,12 @@ describe('LuisRecognizer', function () { returnStatusCode(statusCode); const context = new TestContext({ text: 'Hello world!' }); - await assert.rejects( - recognizer.recognize(context), - new Error( - `Response ${statusCode}: Unexpected status code received. Please verify that your LUIS application is properly setup.` - ) - ); + const errorResponse = `Response ${statusCode}: Unexpected status code received. Please verify that your LUIS application is properly setup.`; + try { + await recognizer.recognize(context); + } catch (error) { + assert.deepEqual(errorResponse, error.message); + } }); maybeIt( diff --git a/libraries/botbuilder-ai/tests/luisSdk.test.js b/libraries/botbuilder-ai/tests/luisSdk.test.js index e29047459a..8ecf61352a 100644 --- a/libraries/botbuilder-ai/tests/luisSdk.test.js +++ b/libraries/botbuilder-ai/tests/luisSdk.test.js @@ -2,7 +2,7 @@ const assert = require('assert'); const fs = require('fs-extra'); const nock = require('nock'); const { LUISRuntimeClientV2 } = require('../lib/luisV2-models/luisRuntimeClientV2'); -const msRest = require('@azure/ms-rest-js'); +const { TokenCredentials } = require('botframework-connector'); const applicationId = '00000000-0000-0000-0000-000000000000'; // This can be any endpoint key for calling LUIS @@ -13,7 +13,7 @@ const k = process.env.LUISAPPKEY || 'test'; const mockLuis = true; const baseUrl = 'https://westus.api.cognitive.microsoft.com'; -const creds = new msRest.TokenCredentials(k); +const creds = new TokenCredentials(k); function ExpectedPath(file) { return __dirname + '/TestData/LuisSdk/' + file; diff --git a/libraries/botframework-connector/package.json b/libraries/botframework-connector/package.json index b5773a0a25..cb27058bf6 100644 --- a/libraries/botframework-connector/package.json +++ b/libraries/botframework-connector/package.json @@ -30,6 +30,7 @@ "@azure/core-http": "^3.0.2", "@azure/identity": "^2.0.4", "@azure/msal-node": "^1.2.0", + "@azure/core-http": "^3.0.2", "axios": "^0.25.0", "base64url": "^3.0.0", "botbuilder-stdlib": "4.1.6", diff --git a/yarn.lock b/yarn.lock index 515ef834f8..600a86b34c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17,28 +17,11 @@ dependencies: tslib "^1.9.3" -"@azure/cognitiveservices-luis-runtime@^4.0.0": - version "4.0.1" - resolved "https://registry.yarnpkg.com/@azure/cognitiveservices-luis-runtime/-/cognitiveservices-luis-runtime-4.0.1.tgz#7c49b0a98af2b3d1c76e2fee64b1270769de1b25" - integrity sha512-W5oDt1LvJQmtxCIDq1aFh8R4W+5ZKSTC+9So9DIGVZmy29SMxBNyTf8OTliHDv0L+P6Y2XBySoGCliPYfTyrhQ== - dependencies: - "@azure/ms-rest-js" "^2.0.3" - tslib "^1.10.0" - "@azure/core-asynciterator-polyfill@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@azure/core-asynciterator-polyfill/-/core-asynciterator-polyfill-1.0.0.tgz#dcccebb88406e5c76e0e1d52e8cc4c43a68b3ee7" integrity sha512-kmv8CGrPfN9SwMwrkiBK9VTQYxdFQEGe0BmQk+M8io56P9KNzpAxcWE/1fxJj7uouwN4kXF0BHW8DNlgx+wtCg== -"@azure/core-auth@^1.1.4": - version "1.5.0" - resolved "https://registry.yarnpkg.com/@azure/core-auth/-/core-auth-1.5.0.tgz#a41848c5c31cb3b7c84c409885267d55a2c92e44" - integrity sha512-udzoBuYG1VBoHVohDTrvKjyzel34zt77Bhp7dQntVGGD0ehVq48owENbBG8fIgkHRNUBQH5k1r0hpoMu5L8+kw== - dependencies: - "@azure/abort-controller" "^1.0.0" - "@azure/core-util" "^1.1.0" - tslib "^2.2.0" - "@azure/core-auth@^1.2.0", "@azure/core-auth@^1.4.0": version "1.4.0" resolved "https://registry.yarnpkg.com/@azure/core-auth/-/core-auth-1.4.0.tgz#6fa9661c1705857820dbc216df5ba5665ac36a9e" @@ -152,7 +135,7 @@ "@opentelemetry/api" "^0.10.2" tslib "^2.0.0" -"@azure/core-util@^1.0.0-beta.1", "@azure/core-util@^1.1.0", "@azure/core-util@^1.1.1", "@azure/core-util@^1.2.0": +"@azure/core-util@^1.0.0-beta.1", "@azure/core-util@^1.1.1", "@azure/core-util@^1.2.0": version "1.5.0" resolved "https://registry.yarnpkg.com/@azure/core-util/-/core-util-1.5.0.tgz#ffe49c3e867044da67daeb8122143fa065e1eb0e" integrity sha512-GZBpVFDtQ/15hW1OgBcRdT4Bl7AEpcEZqLfbAvOtm1CQUncKWiYapFHVD588hmlV27NbOOtSm3cnLF3lvoHi4g== @@ -224,20 +207,6 @@ resolved "https://registry.yarnpkg.com/@azure/ms-rest-azure-env/-/ms-rest-azure-env-2.0.0.tgz#45809f89763a480924e21d3c620cd40866771625" integrity sha512-dG76W7ElfLi+fbTjnZVGj+M9e0BIEJmRxU6fHaUQ12bZBe8EJKYb2GV50YWNaP2uJiVQ5+7nXEVj1VN1UQtaEw== -"@azure/ms-rest-js@^2.0.3", "@azure/ms-rest-js@^2.7.0": - version "2.7.0" - resolved "https://registry.yarnpkg.com/@azure/ms-rest-js/-/ms-rest-js-2.7.0.tgz#8639065577ffdf4946951e1d246334ebfd72d537" - integrity sha512-ngbzWbqF+NmztDOpLBVDxYM+XLcUj7nKhxGbSU9WtIsXfRB//cf2ZbAG5HkOrhU9/wd/ORRB6lM/d69RKVjiyA== - dependencies: - "@azure/core-auth" "^1.1.4" - abort-controller "^3.0.0" - form-data "^2.5.0" - node-fetch "^2.6.7" - tslib "^1.10.0" - tunnel "0.0.6" - uuid "^8.3.2" - xml2js "^0.5.0" - "@azure/msal-browser@^2.16.0": version "2.17.0" resolved "https://registry.yarnpkg.com/@azure/msal-browser/-/msal-browser-2.17.0.tgz#beb7d91e6123534b42c0d2ce85eda42a136a8555" @@ -2734,13 +2703,6 @@ abbrev@1: resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q== -abort-controller@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392" - integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg== - dependencies: - event-target-shim "^5.0.0" - accepts@^1.3.7, accepts@~1.3.8: version "1.3.8" resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.8.tgz#0bf0be125b67014adcb0b0921e62db7bffe16b2e" @@ -5985,11 +5947,6 @@ event-emitter@~0.3.5: d "1" es5-ext "~0.10.14" -event-target-shim@^5.0.0: - version "5.0.1" - resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789" - integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ== - events@^3.0.0: version "3.2.0" resolved "https://registry.yarnpkg.com/events/-/events-3.2.0.tgz#93b87c18f8efcd4202a461aec4dfc0556b639379" @@ -13035,7 +12992,7 @@ tsconfig-paths@^3.9.0: minimist "^1.2.0" strip-bom "^3.0.0" -tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: +tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== @@ -13072,7 +13029,7 @@ tty-browserify@0.0.1: resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.1.tgz#3f05251ee17904dfd0677546670db9651682b811" integrity sha512-C3TaO7K81YvjCgQH9Q1S3R3P3BtN3RIM8n+OvX4il1K1zgE8ZhI0op7kClgkxtutIE8hQrcrHBXvIheqKUUCxw== -tunnel@0.0.6, tunnel@^0.0.6: +tunnel@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c" integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==