Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [#4759] Migrate off @azure/core-http #4834

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/botbuilder-ai/etc/botbuilder-ai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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 { RequestOptionsBase } from 'botbuilder-stdlib/lib/azureCoreHttpCompat';
import { ServiceCollection } from 'botbuilder-dialogs-adaptive-runtime-core';
import { StringExpression } from 'adaptive-expressions';
import { TemplateInterface } from 'botbuilder-dialogs';
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
}
},
"dependencies": {
"@azure/core-http": "^3.0.4",
"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",
"botbuilder-stdlib": "4.1.6",
"botframework-connector": "4.1.6",
"lodash": "^4.17.21",
"node-fetch": "^2.7.0",
Expand Down
2 changes: 1 addition & 1 deletion 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 { RequestOptionsBase } from 'botbuilder-stdlib/lib/azureCoreHttpCompat';

import Url from 'url-parse';
import { BotTelemetryClient, NullTelemetryClient, RecognizerResult, TurnContext } from 'botbuilder-core';
Expand Down
16 changes: 9 additions & 7 deletions libraries/botbuilder-ai/src/luisRuntimeClientContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
* license information.
*/

import { ServiceClient, ServiceClientCredentials, ServiceClientOptions } from '@azure/core-http';
import {
ServiceClientContext,
ServiceClientCredentials,
ServiceClientOptions,
} from 'botbuilder-stdlib/lib/azureCoreHttpCompat';

/**
* Client for LUIS context
*/
export class LUISRuntimeClientContext extends ServiceClient {
export class LUISRuntimeClientContext extends ServiceClientContext {
endpoint: string;
credentials: ServiceClientCredentials;

/**
* Initializes a new instance of the LUISRuntimeClientContext class.
Expand All @@ -33,11 +36,10 @@ export class LUISRuntimeClientContext extends ServiceClient {
options = {};
}

super(credentials, options);
const baseUri = options?.baseUri || `${endpoint}/luis/v3.0-preview`;

super(credentials, { ...options, baseUri });

this.baseUri = '{Endpoint}/luis/v3.0-preview';
this.requestContentType = 'application/json; charset=utf-8';
this.endpoint = endpoint;
this.credentials = credentials;
}
}
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 'botbuilder-stdlib/lib/azureCoreHttpCompat';

export const IntentModel: CompositeMapper = {
serializedName: 'IntentModel',
Expand Down
2 changes: 1 addition & 1 deletion 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 { RequestOptionsBase, HttpOperationResponse as HttpResponse } from 'botbuilder-stdlib/lib/azureCoreHttpCompat';

/**
* Represents an intent prediction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT License.
*/

import { OperationURLParameter, OperationQueryParameter } from '@azure/core-http';
import { OperationURLParameter, OperationQueryParameter } from 'botbuilder-stdlib/lib/azureCoreHttpCompat';

export const appId: OperationURLParameter = {
parameterPath: 'appId',
Expand Down
4 changes: 2 additions & 2 deletions libraries/botbuilder-ai/src/luisV2-models/luisPrediction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT License.
*/

import { ServiceCallback, OperationSpec, Serializer } from '@azure/core-http';
import { ServiceCallback, OperationSpec, createSerializer } from 'botbuilder-stdlib/lib/azureCoreHttpCompat';
import { LUISRuntimeClientContext } from '../luisRuntimeClientContext';
import { LuisResult, PredictionResolveOptionalParams, PredictionResolveResponse } from './luisResult';
import * as Parameters from './luisParameters';
Expand Down Expand Up @@ -83,7 +83,7 @@ export class LuisPrediction {
}

// Operation Specifications
const serializer = new Serializer(Mappers);
const serializer = createSerializer(Mappers);
const resolveOperationSpec: OperationSpec = {
httpMethod: 'POST',
path: 'apps/{appId}',
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-ai/src/luisV2-models/luisResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Sentiment } from './luisModels';
import { HttpResponse, RequestOptionsBase } from '@azure/core-http';
import { HttpOperationResponse as HttpResponse, RequestOptionsBase } from 'botbuilder-stdlib/lib/azureCoreHttpCompat';

/**
* Prediction, based on the input query, containing intent(s) and entities.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT License.
*/

import { ServiceClientCredentials, ServiceClientOptions } from '@azure/core-http';
import { ServiceClientCredentials, ServiceClientOptions } from 'botbuilder-stdlib/lib/azureCoreHttpCompat';
import * as Models from './luisResult';
import * as Mappers from './luisMappers';
import { LuisPrediction } from './luisPrediction';
Expand All @@ -30,9 +30,9 @@ class LUISRuntimeClientV2 extends LUISRuntimeClientContext {
* @param [options] The parameter options
*/
constructor(credentials: ServiceClientCredentials, endpoint: string, options?: ServiceClientOptions) {
super(credentials, endpoint, options);
const baseUri = options?.baseUri || `${endpoint}/luis/v2.0`;
super(credentials, endpoint, { ...options, baseUri });
this.prediction = new LuisPrediction(this);
super.baseUri = '{Endpoint}/luis/v2.0';
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Storage as Storage_2 } from 'botbuilder-core';
import { StoragePipelineOptions } from '@azure/storage-blob';
import { StorageSharedKeyCredential } from '@azure/storage-blob';
import { StoreItems } from 'botbuilder-core';
import { TokenCredential } from '@azure/core-http';
import { TokenCredential } from 'botbuilder-stdlib/lib/azureCoreHttpCompat';
import { TranscriptInfo } from 'botbuilder-core';
import { TranscriptStore } from 'botbuilder-core';

Expand Down
3 changes: 1 addition & 2 deletions libraries/botbuilder-azure-blobs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
"botbuilder-core": "4.1.6",
"botbuilder-stdlib": "4.1.6",
"p-map": "^4.0.0",
"zod": "^3.23.8",
"@azure/core-http": "^3.0.4"
"zod": "^3.23.8"
},
"scripts": {
"build": "tsc -b",
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-azure-blobs/src/blobsStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { Storage, StoreItems } from 'botbuilder-core';
import { ignoreError, isStatusCodeError } from './ignoreError';
import { sanitizeBlobKey } from './sanitizeBlobKey';
import { TokenCredential, isTokenCredential } from '@azure/core-http';
import { TokenCredential, isTokenCredential } from 'botbuilder-stdlib/lib/azureCoreHttpCompat';

/**
* Optional settings for BlobsStorage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
StoragePipelineOptions,
StorageSharedKeyCredential,
} from '@azure/storage-blob';
import { isTokenCredential, TokenCredential } from '@azure/core-http';
import { isTokenCredential, TokenCredential } from 'botbuilder-stdlib/lib/azureCoreHttpCompat';

// Formats a timestamp in a way that is consistent with the C# SDK
function formatTicks(timestamp: Date): string {
Expand Down
8 changes: 8 additions & 0 deletions libraries/botbuilder-stdlib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
"bugs": {
"url": "https://github.com/Microsoft/botbuilder-js/issues"
},
"dependencies": {
"@azure/core-auth": "^1.9.0",
"@azure/core-http-compat": "^2.1.2",
"@azure/core-rest-pipeline": "^1.18.1",
"@azure/core-client": "^1.9.2",
"@azure/core-tracing": "^1.2.0",
"@azure/abort-controller": "^2.1.2"
},
"repository": {
"type": "git",
"url": "https://github.com/Microsoft/botbuilder-js.git"
Expand Down
5 changes: 5 additions & 0 deletions libraries/botbuilder-stdlib/src/azureCoreHttpCompat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export * from './azureCoreHttpCompat/compat';
export * from './azureCoreHttpCompat/serviceClientContext';
59 changes: 59 additions & 0 deletions libraries/botbuilder-stdlib/src/azureCoreHttpCompat/compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export * from './interfaces';

// Re-export only ProxySettings as it is the same as the deprecated core-http library.
export { ProxySettings } from '@azure/core-rest-pipeline';

// Re-export only WebResourceLike, CompatResponse, RequestPolicy as they are the same as the deprecated core-http library.
export {
WebResourceLike,
CompatResponse as HttpOperationResponse,
RequestPolicy as HttpClient,
} from '@azure/core-http-compat';

// Re-export. Can't access the HttpHeaders directly from the @azure/core-http-compat package because it is not defined in the package.json 'exports' property.
export { HttpHeaders } from '../../node_modules/@azure/core-http-compat/dist/commonjs/util';

// Re-export only TokenCredential, isTokenCredential as they are the same as the deprecated core-http library.
export { TokenCredential, isTokenCredential } from '@azure/core-auth';

// Re-export these as they are the same as the deprecated core-http library.
export {
createSerializer,
OperationURLParameter,
OperationQueryParameter,
OperationSpec,
CompositeMapper,
} from '@azure/core-client';

import { WebResourceLike } from '@azure/core-http-compat';
import { PipelineRequestOptions, createPipelineRequest } from '@azure/core-rest-pipeline';
import { toWebResourceLike } from '../../node_modules/@azure/core-http-compat/dist/commonjs/util';

/**
* Creates a new WebResourceLike object from the provided resource.
*
* @param resource The resource to convert to a WebResourceLike object.
* @returns A new WebResourceLike object.
*/
export function createWebResource(resource?: PipelineRequestOptions): WebResourceLike {
return toWebResourceLike(createPipelineRequest(resource ?? { url: '' }));
}

/**
* A set of constants used internally when processing requests.
*/
export const Constants = {
/**
* Defines constants for use with HTTP headers.
*/
HeaderConstants: {
/**
* The Authorization header.
*/
AUTHORIZATION: 'Authorization',
AUTHORIZATION_SCHEME: 'Bearer',
},
};
Loading
Loading