Skip to content

Commit

Permalink
update ts user-agent implementation to match dotnet
Browse files Browse the repository at this point in the history
  • Loading branch information
aacebo committed Jan 16, 2024
1 parent 879a019 commit 34fe477
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 207 deletions.
22 changes: 4 additions & 18 deletions js/packages/teams-ai/src/Application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ import {
FileConsentCardResponse
} from 'botbuilder';

import { PasswordServiceClientCredentialFactory } from 'botframework-connector';

import { Application, ConversationUpdateEvents, MessageReactionEvents, TeamsMessageEvents } from './Application';
import { AdaptiveCardsOptions } from './AdaptiveCards';
import { AIOptions } from './AI';
import { TaskModulesOptions } from './TaskModules';
import { TurnState } from './TurnState';
import { createTestConversationUpdate, createTestInvoke } from './internals';
import { TestPlanner } from './planners/TestPlanner';
import { TeamsBotFrameworkAuthentication } from './TeamsBotFrameworkAuthentication';
import { TeamsAdapter } from './TeamsAdapter';

class MockUserTokenClient {
/**
Expand Down Expand Up @@ -158,11 +156,7 @@ describe('Application', () => {

describe('botAuthentication', () => {
const app = new Application({
adapter: {
authentication: new TeamsBotFrameworkAuthentication({
credentialsFactory: new PasswordServiceClientCredentialFactory('', '')
})
}
adapter: new TeamsAdapter()
});

it('should initialize `CloudAdapter`', () => {
Expand Down Expand Up @@ -244,11 +238,7 @@ describe('Application', () => {

beforeEach(() => {
app = new Application({
adapter: {
authentication: new TeamsBotFrameworkAuthentication({
credentialsFactory: new PasswordServiceClientCredentialFactory('', '')
})
},
adapter: new TeamsAdapter(),
authentication: authenticationSettings
});

Expand All @@ -272,11 +262,7 @@ describe('Application', () => {
it('should start signin flow', async () => {
const authSettings = { ...authenticationSettings, autoSignIn: true };
const app = new Application({
adapter: {
authentication: new TeamsBotFrameworkAuthentication({
credentialsFactory: new PasswordServiceClientCredentialFactory('', '')
})
},
adapter: new TeamsAdapter(),
authentication: authSettings
});

Expand Down
13 changes: 3 additions & 10 deletions js/packages/teams-ai/src/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Activity,
ActivityTypes,
BotAdapter,
CloudAdapter,
ConversationReference,
FileConsentCardResponse,
O365ConnectorCardActionQuery,
Expand All @@ -36,7 +35,7 @@ import {
setUserInSignInFlow,
userInSignInFlow
} from './authentication/BotAuthenticationBase';
import { BotAdapterOptions } from './BotAdapterOptions';
import { TeamsAdapter } from './TeamsAdapter';

/**
* @private
Expand Down Expand Up @@ -72,7 +71,7 @@ export interface ApplicationOptions<TState extends TurnState> {
/**
* Optional. Options used to initialize your `BotAdapter`
*/
adapter?: BotAdapter | BotAdapterOptions;
adapter?: TeamsAdapter;

/**
* Optional. OAuth prompt settings to use for authentication.
Expand Down Expand Up @@ -247,13 +246,7 @@ export class Application<TState extends TurnState = TurnState> {

// Create Adapter
if (this._options.adapter) {
if ('authentication' in this._options.adapter) {
if (this._options.adapter?.authentication) {
this._adapter = new CloudAdapter(this._options.adapter.authentication);
}
} else {
this._adapter = this._options.adapter as BotAdapter;
}
this._adapter = this._options.adapter;
}

// Create AI component if configured with a planner
Expand Down
11 changes: 2 additions & 9 deletions js/packages/teams-ai/src/ApplicationBuilder.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import { strict as assert } from 'assert';
import { MemoryStorage } from 'botbuilder';
import { PasswordServiceClientCredentialFactory } from 'botframework-connector';

import { ApplicationBuilder } from './ApplicationBuilder';
import { AdaptiveCardsOptions } from './AdaptiveCards';
import { AIOptions } from './AI';
import { TurnState } from './TurnState';
import { TestPlanner } from './planners';
import { TaskModulesOptions } from './TaskModules';
import { BotAdapterOptions } from './BotAdapterOptions';
import { TeamsBotFrameworkAuthentication } from './TeamsBotFrameworkAuthentication';
import { TeamsAdapter } from './TeamsAdapter';

describe('ApplicationBuilder', () => {
const botAppId = 'testBot';
const adapter: BotAdapterOptions = {
authentication: new TeamsBotFrameworkAuthentication({
credentialsFactory: new PasswordServiceClientCredentialFactory('', '')
})
};

const adapter = new TeamsAdapter();
const adaptiveCards: AdaptiveCardsOptions = { actionSubmitFilter: 'cardFilter' };
const ai: AIOptions<TurnState> = { planner: new TestPlanner() };
const longRunningMessages = true;
Expand Down
15 changes: 6 additions & 9 deletions js/packages/teams-ai/src/ApplicationBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Storage, BotAdapter } from 'botbuilder';
import { Storage } from 'botbuilder';

import { Application, ApplicationOptions } from './Application';
import { BotAdapterOptions } from './BotAdapterOptions';
import { TeamsAdapter } from './TeamsAdapter';
import { AIOptions } from './AI';
import { TurnState } from './TurnState';
import { AdaptiveCardsOptions } from './AdaptiveCards';
Expand All @@ -18,11 +18,11 @@ export class ApplicationBuilder<TState extends TurnState = TurnState> {
/**
* Configures the application to use long running messages.
* Default state for longRunningMessages is false
* @param {BotAdapter | BotAdapterOptions} adapter The adapter to use for routing incoming requests.
* @param {TeamsAdapter} adapter The adapter to use for routing incoming requests.
* @param {string} botAppId The Microsoft App ID for the bot.
* @returns {this} The ApplicationBuilder instance.
*/
public withLongRunningMessages(adapter: BotAdapter | BotAdapterOptions, botAppId: string): this {
public withLongRunningMessages(adapter: TeamsAdapter, botAppId: string): this {
if (!botAppId) {
throw new Error(
`The Application.longRunningMessages property is unavailable because botAppId cannot be null or undefined.`
Expand Down Expand Up @@ -77,14 +77,11 @@ export class ApplicationBuilder<TState extends TurnState = TurnState> {

/**
* Configures user authentication settings.
* @param {BotAdapter | BotAdapterOptions} adapter The adapter to use for user authentication.
* @param {TeamsAdapter} adapter The adapter to use for user authentication.
* @param {AuthenticationOptions} authenticationOptions The options to configure the authentication manager.
* @returns {this} The ApplicationBuilder instance.
*/
public withAuthentication(
adapter: BotAdapter | BotAdapterOptions,
authenticationOptions: AuthenticationOptions
): this {
public withAuthentication(adapter: TeamsAdapter, authenticationOptions: AuthenticationOptions): this {
this._options.adapter = adapter;
this._options.authentication = authenticationOptions;
return this;
Expand Down
21 changes: 0 additions & 21 deletions js/packages/teams-ai/src/BotAdapterOptions.ts

This file was deleted.

41 changes: 41 additions & 0 deletions js/packages/teams-ai/src/TeamsAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
CloudAdapter,
ConfigurationBotFrameworkAuthentication,
ConfigurationBotFrameworkAuthenticationOptions
} from 'botbuilder';

import {
AuthenticationConfiguration,
ConnectorClientOptions,
ServiceClientCredentialsFactory
} from 'botframework-connector';

import packageInfo from '../package.json';

const USER_AGENT = `teamsai-js/${packageInfo.version}`;

/**
* An adapter that implements the Bot Framework Protocol and can be hosted in different cloud environments both public and private.
*/
export class TeamsAdapter extends CloudAdapter {
constructor(
botFrameworkAuthConfig?: ConfigurationBotFrameworkAuthenticationOptions,
credentialsFactory?: ServiceClientCredentialsFactory,
authConfiguration?: AuthenticationConfiguration,
connectorClientOptions?: ConnectorClientOptions
) {
super(
new ConfigurationBotFrameworkAuthentication(
botFrameworkAuthConfig || {},
credentialsFactory,
authConfiguration,
undefined,
{
...(connectorClientOptions || {}),
userAgent: USER_AGENT,
userAgentHeaderName: undefined
}
)
);
}
}
18 changes: 0 additions & 18 deletions js/packages/teams-ai/src/TeamsBotFrameworkAuthentication.spec.ts

This file was deleted.

120 changes: 0 additions & 120 deletions js/packages/teams-ai/src/TeamsBotFrameworkAuthentication.ts

This file was deleted.

3 changes: 1 addition & 2 deletions js/packages/teams-ai/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ export * from './TestTurnState';
export * from './TurnState';
export * from './Utilities';
export * from './authentication/TeamsBotSsoPrompt';
export * from './TeamsBotFrameworkAuthentication';
export * from './BotAdapterOptions';
export * from './TeamsAdapter';

0 comments on commit 34fe477

Please sign in to comment.