Skip to content

Commit

Permalink
fix: [#4470] Migrate off @azure/ms-rest-js botbuilder-ai (#4577)
Browse files Browse the repository at this point in the history
* update yarn lock without ms-rest-js

* remove ms-rest-js in botbuilder-ai

* update lint formats

* add @azure/core-util to resolutions

* change models class name

* remove core-util of resolutions
  • Loading branch information
JhontSouth committed Dec 7, 2023
1 parent 20ac13a commit f3db3e9
Show file tree
Hide file tree
Showing 15 changed files with 410 additions and 124 deletions.
4 changes: 2 additions & 2 deletions libraries/botbuilder-ai/etc/botbuilder-ai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions libraries/botbuilder-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions libraries/botbuilder-ai/src/luisRecognizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
*/
Expand Down
4 changes: 2 additions & 2 deletions libraries/botbuilder-ai/src/luisRecognizerOptionsV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
43 changes: 43 additions & 0 deletions libraries/botbuilder-ai/src/luisRuntimeClientContext.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
20 changes: 10 additions & 10 deletions libraries/botbuilder-ai/src/luisV2-models/luisMappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -34,7 +34,7 @@ export const IntentModel: msRest.CompositeMapper = {
},
};

export const EntityModel: msRest.CompositeMapper = {
export const EntityModel: CompositeMapper = {
serializedName: 'EntityModel',
type: {
name: 'Composite',
Expand Down Expand Up @@ -77,7 +77,7 @@ export const EntityModel: msRest.CompositeMapper = {
},
};

export const CompositeChildModel: msRest.CompositeMapper = {
export const CompositeChildModel: CompositeMapper = {
serializedName: 'CompositeChildModel',
type: {
name: 'Composite',
Expand All @@ -101,7 +101,7 @@ export const CompositeChildModel: msRest.CompositeMapper = {
},
};

export const CompositeEntityModel: msRest.CompositeMapper = {
export const CompositeEntityModel: CompositeMapper = {
serializedName: 'CompositeEntityModel',
type: {
name: 'Composite',
Expand Down Expand Up @@ -138,7 +138,7 @@ export const CompositeEntityModel: msRest.CompositeMapper = {
},
};

export const Sentiment: msRest.CompositeMapper = {
export const Sentiment: CompositeMapper = {
serializedName: 'Sentiment',
type: {
name: 'Composite',
Expand All @@ -160,7 +160,7 @@ export const Sentiment: msRest.CompositeMapper = {
},
};

export const LuisResult: msRest.CompositeMapper = {
export const LuisResult: CompositeMapper = {
serializedName: 'LuisResult',
type: {
name: 'Composite',
Expand Down Expand Up @@ -244,7 +244,7 @@ export const LuisResult: msRest.CompositeMapper = {
},
};

export const EntityWithScore: msRest.CompositeMapper = {
export const EntityWithScore: CompositeMapper = {
serializedName: 'EntityWithScore',
type: {
name: 'Composite',
Expand All @@ -267,7 +267,7 @@ export const EntityWithScore: msRest.CompositeMapper = {
},
};

export const EntityWithResolution: msRest.CompositeMapper = {
export const EntityWithResolution: CompositeMapper = {
serializedName: 'EntityWithResolution',
type: {
name: 'Composite',
Expand All @@ -286,7 +286,7 @@ export const EntityWithResolution: msRest.CompositeMapper = {
},
};

export const APIError: msRest.CompositeMapper = {
export const APIError: CompositeMapper = {
serializedName: 'APIError',
type: {
name: 'Composite',
Expand Down

0 comments on commit f3db3e9

Please sign in to comment.