Skip to content

Commit

Permalink
[microsoft#4759] Fix issue core-http deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
germanandu committed Nov 15, 2024
1 parent 2b01751 commit bade4ac
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 94 deletions.
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 { RequestOptionsBase } from '@azure/core-http';
import { PipelineRequestOptions } from '@azure/core-rest-pipeline';

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 RequestOptionsBase {
export interface LuisPredictionOptions extends PipelineRequestOptions {
/**
* If true, return all intents instead of just the top scoring intent.
*/
Expand Down
15 changes: 8 additions & 7 deletions libraries/botbuilder-ai/src/luisRuntimeClientContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
* license information.
*/

import { ServiceClient, ServiceClientCredentials, ServiceClientOptions } from '@azure/core-http';

//import { ServiceClient, ServiceClientCredentials, ServiceClientOptions } from '@azure/core-http';
import { ServiceClientOptions, ServiceClient } from '@azure/core-client';
import { TokenCredential } from '@azure/identity';
/**
* Client for LUIS context
*/
export class LUISRuntimeClientContext extends ServiceClient {
endpoint: string;
credentials: ServiceClientCredentials;
credentials: TokenCredential;

/**
* Initializes a new instance of the LUISRuntimeClientContext class.
Expand All @@ -21,7 +22,7 @@ export class LUISRuntimeClientContext extends ServiceClient {
* https://westus.api.cognitive.microsoft.com).
* @param [options] The parameter options
*/
constructor(credentials: ServiceClientCredentials, endpoint: string, options?: ServiceClientOptions) {
constructor(credentials: TokenCredential, endpoint: string, options?: ServiceClientOptions) {
if (endpoint == undefined) {
throw new Error("'endpoint' cannot be null.");
}
Expand All @@ -33,10 +34,10 @@ export class LUISRuntimeClientContext extends ServiceClient {
options = {};
}

super(credentials, options);
super(options);

this.baseUri = '{Endpoint}/luis/v3.0-preview';
this.requestContentType = 'application/json; charset=utf-8';
//this.baseUri = '{Endpoint}/luis/v3.0-preview';
//this.requestContentType = 'application/json; charset=utf-8';
this.endpoint = endpoint;
this.credentials = credentials;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-ai/src/luisV2-models/luisMappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT License.
*/

import { CompositeMapper } from '@azure/core-http';
import { CompositeMapper } from '@azure/core-client';

export const IntentModel: CompositeMapper = {
serializedName: 'IntentModel',
Expand Down
10 changes: 5 additions & 5 deletions libraries/botbuilder-ai/src/luisV2-models/luisModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* license information.
*/

import { RequestOptionsBase, HttpResponse } from '@azure/core-http';
import { PipelineRequestOptions, PipelineResponse } from '@azure/core-rest-pipeline';

/**
* Represents an intent prediction.
Expand Down Expand Up @@ -194,7 +194,7 @@ export interface PredictionRequest {
/**
* Optional Parameters.
*/
export interface PredictionGetVersionPredictionOptionalParams extends RequestOptionsBase {
export interface PredictionGetVersionPredictionOptionalParams extends PipelineRequestOptions {
/**
* Indicates whether to get extra metadata for the entities predictions or not.
*/
Expand All @@ -212,7 +212,7 @@ export interface PredictionGetVersionPredictionOptionalParams extends RequestOpt
/**
* Optional Parameters.
*/
export interface PredictionGetSlotPredictionOptionalParams extends RequestOptionsBase {
export interface PredictionGetSlotPredictionOptionalParams extends PipelineRequestOptions {
/**
* Indicates whether to get extra metadata for the entities predictions or not.
*/
Expand All @@ -234,7 +234,7 @@ export type PredictionGetVersionPredictionResponse = PredictionResponse & {
/**
* The underlying HTTP response.
*/
_response: HttpResponse & {
_response: PipelineResponse & {
/**
* The response body as text (string format)
*/
Expand All @@ -254,7 +254,7 @@ export type PredictionGetSlotPredictionResponse = PredictionResponse & {
/**
* The underlying HTTP response.
*/
_response: HttpResponse & {
_response: PipelineResponse & {
/**
* The response body as text (string format)
*/
Expand Down
5 changes: 2 additions & 3 deletions libraries/botbuilder-ai/src/luisV2-models/luisResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/

import { Sentiment } from './luisModels';
import { RequestOptionsBase } from '@azure/core-http';
import { PipelineResponse } from '@azure/core-rest-pipeline';
import { PipelineRequestOptions, PipelineResponse } from '@azure/core-rest-pipeline';

/**
* Prediction, based on the input query, containing intent(s) and entities.
Expand Down Expand Up @@ -123,7 +122,7 @@ export interface CompositeChildModel {
/**
* Optional Parameters.
*/
export interface PredictionResolveOptionalParams extends RequestOptionsBase {
export interface PredictionResolveOptionalParams extends PipelineRequestOptions {
/**
* The timezone offset for the location of the request.
*/
Expand Down
3 changes: 3 additions & 0 deletions libraries/botbuilder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
}
},
"dependencies": {
"@azure/core-client": "^1.9.2",
"@azure/core-http": "^3.0.4",
"@azure/core-rest-pipeline": "^1.17.0",
"@azure/identity": "^4.5.0",
"@azure/msal-node": "^2.13.1",
"axios": "^1.7.7",
"botbuilder-core": "4.1.6",
Expand Down
3 changes: 2 additions & 1 deletion libraries/botbuilder/src/botFrameworkAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import * as z from 'zod';
import { BotFrameworkHttpAdapter } from './botFrameworkHttpAdapter';
import { ConnectorClientBuilder, Request, Response, ResponseT, WebRequest, WebResponse } from './interfaces';
import { HttpClient, RequestPolicyFactory, userAgentPolicy } from '@azure/core-http';
import { RequestPolicyFactory, userAgentPolicy } from '@azure/core-http';
import { HttpClient } from '@azure/core-rest-pipeline';
import { INodeBufferT, INodeSocketT, LogicT } from './zod';
import { arch, release, type } from 'os';
import { delay, retry } from 'botbuilder-stdlib';
Expand Down
12 changes: 6 additions & 6 deletions libraries/botbuilder/src/cloudAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as z from 'zod';
import type { BotFrameworkHttpAdapter } from './botFrameworkHttpAdapter';
import { Activity, CloudAdapterBase, InvokeResponse, StatusCodes, TurnContext } from 'botbuilder-core';
import { GET, POST, VERSION_PATH } from './streaming';
import { HttpClient, HttpHeaders, HttpOperationResponse, WebResource } from '@azure/core-http';
import { HttpClient, PipelineRequest, PipelineResponse, createHttpHeaders } from '@azure/core-rest-pipeline';
import { INodeBufferT, INodeSocketT, LogicT } from './zod';
import { Request, Response, ResponseT } from './interfaces';
import { USER_AGENT } from './botFrameworkAdapter';
Expand Down Expand Up @@ -393,13 +393,13 @@ class StreamingConnectorFactory implements ConnectorFactory {
class StreamingHttpClient implements HttpClient {
constructor(private readonly requestHandler: StreamingRequestHandler) {}

async sendRequest(httpRequest: WebResource): Promise<HttpOperationResponse> {
async sendRequest(httpRequest: PipelineRequest): Promise<PipelineResponse> {
const streamingRequest = this.createStreamingRequest(httpRequest);
const receiveResponse = await this.requestHandler.server?.send(streamingRequest);
return this.createHttpResponse(receiveResponse, httpRequest);
}

private createStreamingRequest(httpRequest: WebResource): StreamingRequest {
private createStreamingRequest(httpRequest: PipelineRequest): StreamingRequest {
const verb = httpRequest.method.toString();
const path = httpRequest.url.slice(httpRequest.url.indexOf('/v3'));

Expand All @@ -411,14 +411,14 @@ class StreamingHttpClient implements HttpClient {

private async createHttpResponse(
receiveResponse: IReceiveResponse,
httpRequest: WebResource
): Promise<HttpOperationResponse> {
httpRequest: PipelineRequest
): Promise<PipelineResponse> {
const [bodyAsText] =
(await Promise.all(receiveResponse.streams?.map((stream) => stream.readAsString()) ?? [])) ?? [];

return {
bodyAsText,
headers: new HttpHeaders(),
headers: createHttpHeaders(),
request: httpRequest,
status: receiveResponse.statusCode,
};
Expand Down
6 changes: 3 additions & 3 deletions libraries/botbuilder/src/streaming/streamingHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT License.
*/

import { WebResource, HttpOperationResponse, HttpClient } from '@azure/core-http';
import { HttpClient, PipelineRequest, PipelineResponse } from '@azure/core-rest-pipeline';
import { IStreamingTransportServer, StreamingRequest } from 'botframework-streaming';

/**
Expand Down Expand Up @@ -35,7 +35,7 @@ export class StreamingHttpClient implements HttpClient {
* @param httpRequest The outgoing request created by the BotframeworkAdapter.
* @returns The streaming transport compatible response to send back to the client.
*/
async sendRequest(httpRequest: WebResource): Promise<HttpOperationResponse> {
async sendRequest(httpRequest: PipelineRequest): Promise<PipelineResponse> {
if (!httpRequest) {
throw new Error('StreamingHttpClient.sendRequest(): missing "httpRequest" parameter');
}
Expand All @@ -59,7 +59,7 @@ export class StreamingHttpClient implements HttpClient {
/**
* @private
*/
private mapHttpRequestToProtocolRequest(httpRequest: WebResource): StreamingRequest {
private mapHttpRequestToProtocolRequest(httpRequest: PipelineRequest): StreamingRequest {
return StreamingRequest.create(httpRequest.method, httpRequest.url, httpRequest.body);
}
}
6 changes: 3 additions & 3 deletions libraries/botbuilder/tests/botFrameworkAdapter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const sinon = require('sinon');
const { BotFrameworkAdapter } = require('../');
const { Conversations } = require('botframework-connector/lib/connectorApi/operations');
const { UserToken, BotSignIn } = require('botframework-connector/lib/tokenApi/operations');
const { userAgentPolicy, HttpHeaders } = require('@azure/core-http');
const { userAgentPolicy, createHttpHeaders } = require('@azure/core-rest-pipeline');

const {
ActivityTypes,
Expand Down Expand Up @@ -480,7 +480,7 @@ describe('BotFrameworkAdapter', function () {
Promise.resolve({
request,
status: 200,
headers: new HttpHeaders(),
headers: createHttpHeaders(),
readableStreamBody: undefined,
bodyAsText: '',
})
Expand Down Expand Up @@ -536,7 +536,7 @@ describe('BotFrameworkAdapter', function () {
const length = client._requestPolicyFactories.length;
for (let i = 0; i < length; i++) {
const mockHttp = {
headers: new HttpHeaders(),
headers: createHttpHeaders(),
};

const result = client._requestPolicyFactories[i].create(mockNextPolicy);
Expand Down
3 changes: 2 additions & 1 deletion libraries/botframework-connector/src/auth/appCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { ConfidentialClientApplication } from '@azure/msal-node';
import { ServiceClientCredentials, WebResource } from '@azure/core-http';
import { PipelineRequest } from '@azure/core-rest-pipeline';
import { TokenCredentials } from './tokenCredentials';
import { AuthenticationConstants } from './authenticationConstants';
import { AuthenticatorResult } from './authenticatorResult';
Expand Down Expand Up @@ -149,7 +150,7 @@ export abstract class AppCredentials implements ServiceClientCredentials {
* @param webResource The WebResource HTTP request.
* @returns A Promise representing the asynchronous operation.
*/
async signRequest(webResource: WebResource): Promise<WebResource> {
async signRequest(webResource: PipelineRequest): Promise<PipelineRequest> {
if (this.shouldSetToken()) {
return new TokenCredentials(await this.getToken()).signRequest(webResource);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { ServiceClientCredentials } from '@azure/core-http';
import { TokenCredential } from '@azure/identity';

// Export underlying type for convenience
export { ServiceClientCredentials };
export { TokenCredential };

/**
* The ServiceClientCredentialsFactory abstract class that allows Bots to provide their own
Expand Down Expand Up @@ -33,12 +33,12 @@ export abstract class ServiceClientCredentialsFactory {
* @param audience The audience.
* @param loginEndpoint The login url.
* @param validateAuthority The validate authority value to use.
* @returns {Promise<ServiceClientCredentials>} A [ServiceClientCredentials](xref:botframework-connector.ServiceClientCredentials).
* @returns {Promise<TokenCredential>} A [ServiceClientCredentials](xref:botframework-connector.ServiceClientCredentials).
*/
abstract createCredentials(
appId: string,
audience: string | undefined,
loginEndpoint: string,
validateAuthority: boolean
): Promise<ServiceClientCredentials>;
): Promise<TokenCredential>;
}
Loading

0 comments on commit bade4ac

Please sign in to comment.