Skip to content

Commit

Permalink
Merge state changes into 4.future (#1399)
Browse files Browse the repository at this point in the history
* Type definition fix: OAuthPromptState (#1157)

* Change PromptState.state type to `any` - Fixes #1155

Fix of #1155

* fix typedoc vulnerability

* delete unused doc references

* Add some tests for teamsCreateConversation

* synced with new dotnet changes

* added all tests

* + copyright

* touch

* [Teams] Lint Teams scenarios, minor refactor (#1283)

* add tslint.json, lint actionBasedMessagingExtension

* lint actionBasedMessagingExtension-fetchTask

* refactor actionBasedMessagingExtension index.ts files

* lint activityUpdateAndDelete

* lint AdaptiveCards

* lint cardBotframework scenario

* added test recordings

* disable failure if no emulator

* added no emulator warning

* Tests and changes

* more tests

* oauthcard tests

* [Teams] add more TeamsInfo tests (#1275)

* add more TeamsInfo tests

* update TeamsActivityHandler, add tests

* implemented @christopheranderson suggestions

* DNM: test to see if recordings used by pipeline

* DNM: try again

* fixed test recordings

* added comment for instanceId replacement

* Let WebSocketClient take in a disconnection callback

* relax the rules for what counts as a well formed guid

* Streaming: Rename botframework-streaming-extensions -> botframework-streaming

* Streaming: Move BotFrameworkStreamingAdapter to botbuilder module

* Streaming: integrate streaming into botFrameworkAdapter though useWebSocket and useNamedPipe methods

* move nock to devDependency (#1297)

* Streaming: temporary move for lower case folders

* add test for nil guid header id

* Streaming: directory casing rename part 2

* Streaming: directory renaming last part

* simplified upsert call

* Streaming: rename all files and references to proper casing

* Streaming: reference streaming without the 'lib' postfix

* normalize azure blob timestamp properties to be iso1806 format

2018-12-31T00:00:00.000Z

* remove console debug statement in unit test

* Removing unused libraries (#1298)

* removing browser-compat libs (#1300)

* add TeamsActivityHandler BadRequest tests

* add Teams ConversationUpdate tests

* add TeamsActivityHandler NotImplemented tests

* change typing and name of param in onTeamsMessagingExtensionFetchTask

* Streaming: Javascript style comments and documentation

* Streaming: Remove unnecessary logger, use http response and body to report error info

* Streaming: fix quotes

* Streaming: Improve comments and error messages

* Streaming: refactor StreamingHttpClient to a separate file

* Streaming: update tests to richer error messages

* Streaming: add more validations and test fixes

* Streaming: remove obsolete package from lerna.json and fix documentation refs

* Change ts compiler output from es5 to es6

* Transfer integration bot to js repo

* [Teams] Part of Teams Hackathon Feedback (#1308)

* add more TeamsInfo tests

* add more tests, clean lint, fix bugs, add missing method

* TeamsActivityHandler.onTurnActivity() doesn't stamp over InvokeResponses

* onTeamsTaskModuleFetch & onTeamsTaskModuleSubmit send a TaskModuleResponse

* fix adaptive cards bot

* fix taskModuleBot

* fix messagingExtensionAuthBot

* [Teams] Add teamsTenantFilteringMiddleware to roster bot scenario (#1311)

* add teamsTenantFilteringMiddleware to roster bot scenario

* fix curly braces

* Missing link unfurling scenario (#1313)

* added linkunfurling back

* updated code to match update on handler

* Addressed PR comments from stevengum

* Hide WebSocket connection behind ProcessActivity

* Change ProcessActivity to accept Union Types and introduce Type Guard to determine if a Request has been passed in.

* Better name. Maybe.

* [Teams] Rename onTeams*-Invoke methods to handleTeams*, add TeamsInfo.getTeamMembers (#1315)

* add getTeamMembers, add teamsId as parameter in TeamsInfo.getTeam*()

* rename onTeams*-Invoke methods to handleTeams*

* Adds createChildContext method to ComponentDialog

* Update manifest.json

combined manifest

* Streaming: remove isFromStreamingConnection out of TurnContext since it will need to be there forever. duplicating for now. We'll unify in 4.7 along with other refactors

* Import directly from library instead of third hand

* fix WebSocketServer.onConnectionDisconnected, fix in StreamingAdapter tests

* move isFromStreamingConnection() tests to BFStreamingAdapter tests

* fix bug in processRequest()

* Remove library specific implementation of websocket handling

* revert changing protecteds to privates

* Further cleanup websocket connection

* Update tests

* Remove no longer used import

* Use const GET instead of string GET

* fix removed internal export

* Final fixes to websocket connection for DLS compatibility.

* merge scenarios

* WIP, part way through dialogContext.ts

* Fix malformatted user agent JSON

* Add recording support for Roster API

* Fix proxy to support Roster calls

* Fix manifest domains

* updated bot with more scenarios

* Update integrationBot.ts

removed bad lines

* Finish updating DialogContext

* added BF cards + conversationupdate

* Add all settings for VSCode debugger

* added messagereactionbot

* added office365card

* Update activityHandler.ts

WIP

* added roster

* added searchbasedmessagingextension scenario

* [Streaming] create NodeWebSocketFactory, refactor code, new tests (#1331)

* create NodeWebSocketFactory, refactor code, new tests

* Set connected to true after connecting.

* Fix missing ActivityLog

* Update README for script, add initial recordings, cleanup nock helper

* Fix validation for post.

* Add channel add and delete events.  Add more comments to nock-helper

* Add member add-remove from groupchat, more cleanup for nock-helper

* More updates

* [Streaming] Add working ws websocket implementation for Node environment (#1334)

* add working ws websocket impl

* remove unused constants

* More scenarios

* Update typeDoc comments for ActivityHandler and ActivityHandlerBase

* More updates

* minor refactoring fileupload bot and added file handler for integration bot

* removed console.log

* Update README.md

* updated readme/manifest

* Update manifest.json

* Updating all libraries to output es6

* Ported DialogStateManager from C3

* copy edits

* QnaMaker: Rename Prompt -> QnAMakerPrompt

* added task module invocation, updated readme

* added promptCultureModels - parity w/ dotnet

* fixed tests

* added tests for custom defaultChoices

* removed unnecessary overrides

* update root package.json, streaming package.json

* [Streaming] Auth and browser compatibility fixes, linting, refactoring (#1338)

* patch auth in streaming to send token to channel

* apply PR feedback for BotFrameworkAdapter

* move ws server construction to wsNodeWebSocket constructor for browser compat

* cleanup and cache serviceUrl in authenticateConnection

* drop teams specific send

* Finish updating typeDoc comments for dialogContext.ts

* expand ChannelAccount to TeamsChannelAccount

* [Streaming] Pull out streaming bits from botbuilder and move to botframework-streaming (#1348)

* cleanup bf-streaming package.json

* move streaming code and tests to botframework-streaming

* remove @azure/ms-rest-js dependency from botbuilder

* Update cardFactory.ts

Update hero card helper to add optional tap parameter

* cr fk

* updated searchbased scenario to match c# (with tap/select handler)

* More robust path parsing...

* Added event emitting support

Also implemented logic to cascade cancel to parent dialogs

* Updated dialog set to support auto id's and dependencies

also replaced "null" with "undefined" htroughout code

* Updated unit tests

* final update

updated integrationbot with searchbasedmessaging extension handlers and updated manifest for file upload bot (works only in personal chat)

* Update README.md

* set bot id to empty guid per andrew's request

* helper to send a trace activity (#1355)

* added local teamsCreateConversation helper (#1357)

* [QnAMaker] Active learning low score variation multiplier value (#1359)

Active learning low score variation multiplier value
- PreviousLowScoreVariationMultiplier to 0.7
- MaxLowScoreVariationMultiplier to 1.0

* Fixed passing of CosmosClientOptions

* add random to transcript generated ids and set sent activity.id (#1344)

* add random to transcript generated ids and set sent activity.id

* cleanup and add test

* always set activity.id to resourceResponse.id in logger when present

* added test for CosmosClientOptions

* updated test recordings

* remove .js and .ts from .gitignore, change *.map to *.js.map (#1365)

* Fix integrationBot to match C# (#1379)

* Added unit test for scopes and path resolvers

Fixed issues as detected.

* Added a bunch of dialog state tests

* Added additional unit tests

- Increased code coverage for DialogStateManager
- Fixed issue detected from unit tests.

* renamed onComputeID to onComputeId

* fixed samples

* remove typescript devDependency and engine from bf-streaming (#1392)

* Tweaked settings test

* Fixed build

* fix functional test

* fixed expression test bugs around date

* Fixed merge conflict and removed old state tests

* Stubbed out test

* Removed test scripts from samples

They break "lerna run test"

* initial fixes for type loader tests

* fix (#1396)
  • Loading branch information
chon219 authored and Stevenic committed Nov 8, 2019
1 parent f29102f commit b4c7a86
Show file tree
Hide file tree
Showing 494 changed files with 47,250 additions and 9,098 deletions.
15 changes: 14 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# Blanket ignore zip files
# Related to Teams Scenarios work
*.zip
*.vscode

# User-specific files
*.suo
*.user
Expand Down Expand Up @@ -287,12 +292,20 @@ __pycache__/
*.odx.cs
*.xsd.cs
/**/node_modules
/**/.vscode

# Exception for including the ESLint extension in vscode
!.vscode/
.vscode/*
!.vscode/extensions.json

/**/*.VC.db
#coverage
/**/coverage
/**/.nyc_output

#derived
/test-runner/out
package-lock.json

*.tsbuildinfo
*.js.map
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
]
}
3 changes: 2 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
"libraries/botbuilder-dialogs",
"libraries/botbuilder-dialogs-adaptive",
"libraries/botbuilder-dialogs-declarative",
"libraries/botframework-expressions",
"libraries/botbuilder-lg",
"libraries/botbuilder-testing",
"libraries/botframework-config",
"libraries/botframework-connector",
"libraries/botframework-expressions",
"libraries/botframework-schema",
"libraries/botframework-streaming",
"libraries/functional-tests",
"libraries/testbot",
"transcripts"
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 @@ -142,7 +142,7 @@ export interface LuisRecognizerTelemetryClient {
*
* @remarks
* This class is used to recognize intents and extract entities from incoming messages.
* See this class in action [in this sample application](https://github.com/Microsoft/BotBuilder-Samples/tree/master/samples/javascript_nodejs/12.nlp-with-luis).
* See this class in action [in this sample application](https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/javascript_nodejs/14.nlp-with-dispatch).
*
* This component can be used within your bots logic by calling [recognize()](#recognize).
*/
Expand Down
45 changes: 35 additions & 10 deletions libraries/botbuilder-ai/src/qnaMaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { Activity, TurnContext, BotTelemetryClient, NullTelemetryClient } from 'botbuilder-core';
import { TurnContext, BotTelemetryClient, NullTelemetryClient } from 'botbuilder-core';

import { constants } from 'http2';
import { QnATelemetryConstants } from './qnaTelemetryConstants';
import { QnAMakerEndpoint } from './qnamaker-interfaces/qnamakerEndpoint';
import { QnAMakerMetadata } from './qnamaker-interfaces/qnamakerMetadata';
Expand All @@ -18,6 +17,7 @@ import { FeedbackRecords } from './qnamaker-interfaces/feedbackRecords';
import { GenerateAnswerUtils } from './qnamaker-utils/generateAnswerUtils';
import { ActiveLearningUtils } from './qnamaker-utils/activeLearningUtils';
import { TrainUtils } from './qnamaker-utils/trainUtils';
import { QnAMakerResults } from './qnamaker-interfaces/qnamakerResults';

export const QNAMAKER_TRACE_TYPE = 'https://www.qnamaker.ai/schemas/trace';
export const QNAMAKER_TRACE_NAME = 'QnAMaker';
Expand Down Expand Up @@ -132,25 +132,50 @@ export class QnAMaker implements QnAMakerTelemetryClient {
throw new TypeError('QnAMaker.getAnswers() requires a TurnContext.');
}

var response = await this.getAnswersRaw(context, options, telemetryProperties, telemetryMetrics);

if (!response) {
return [];
}

return response.answers;
}

public async getAnswersRaw(context: TurnContext, options?: QnAMakerOptions, telemetryProperties?: {[key: string]:string}, telemetryMetrics?: {[key: string]:number} ): Promise<QnAMakerResults> {
if (!context) {
throw new TypeError('QnAMaker.getAnswers() requires a TurnContext.');
}

const queryResult: QnAMakerResult[] = [] as QnAMakerResult[];
const question: string = this.getTrimmedMessageText(context);
const queryOptions: QnAMakerOptions = { ...this._options, ...options } as QnAMakerOptions;

this.generateAnswerUtils.validateOptions(queryOptions);

if (question.length > 0) {
const answers: QnAMakerResult[] = await this.generateAnswerUtils.queryQnaService(this.endpoint, question, queryOptions);
const sortedQnaAnswers: QnAMakerResult[] = GenerateAnswerUtils.sortAnswersWithinThreshold(answers, queryOptions);
var result: QnAMakerResults;

if (question.length > 0) {
result = await this.generateAnswerUtils.queryQnaServiceRaw(this.endpoint, question, queryOptions);

const sortedQnaAnswers: QnAMakerResult[] = GenerateAnswerUtils.sortAnswersWithinThreshold(result.answers, queryOptions);
queryResult.push(...sortedQnaAnswers);
}

if (!result) {
return result;
}

// Log telemetry
this.onQnaResults(queryResult, context, telemetryProperties, telemetryMetrics);

await this.generateAnswerUtils.emitTraceInfo(context, queryResult, queryOptions);

return queryResult;
const qnaResponse: QnAMakerResults = {
activeLearningEnabled: result.activeLearningEnabled,
answers: queryResult
}

return qnaResponse;
}

/**
Expand Down Expand Up @@ -198,10 +223,10 @@ export class QnAMaker implements QnAMakerTelemetryClient {
const trimmedAnswer: string = question ? question.trim() : '';

if (trimmedAnswer.length > 0) {
const answers: QnAMakerResult[] = await this.callService(this.endpoint, question, typeof top === 'number' ? top : 1);
const result: QnAMakerResults = await this.callService(this.endpoint, question, typeof top === 'number' ? top : 1);
const minScore: number = typeof scoreThreshold === 'number' ? scoreThreshold : 0.001;

return answers.filter(
return result.answers.filter(
(ans: QnAMakerResult) => ans.score >= minScore)
.sort((a: QnAMakerResult, b: QnAMakerResult) => b.score - a.score);
}
Expand Down Expand Up @@ -236,8 +261,8 @@ export class QnAMaker implements QnAMakerTelemetryClient {
* @remarks
* This is exposed to enable better unit testing of the service.
*/
protected async callService(endpoint: QnAMakerEndpoint, question: string, top: number): Promise<QnAMakerResult[]> {
return this.generateAnswerUtils.queryQnaService(endpoint, question, { top } as QnAMakerOptions);
protected async callService(endpoint: QnAMakerEndpoint, question: string, top: number): Promise<QnAMakerResults> {
return this.generateAnswerUtils.queryQnaServiceRaw(endpoint, question, { top } as QnAMakerOptions);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-ai/src/qnamaker-interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export * from './qnamakerEndpoint';
export * from './qnamakerMetadata';
export * from './qnamakerOptions';
export * from './qnamakerResult';
export * from './qnamakerTraceinfo';
export * from './qnamakerTraceInfo';
export * from './feedbackRecord';
export * from './feedbackRecords';
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @module botbuilder-ai
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* The context associated with QnA. Used to mark if the current prompt is relevant with a previous question or not.
*/
export interface QnARequestContext {

/**
* The previous QnA Id that was returned.
*/
previousQnAId: number;

/**
* The previous user query/question.
*/
previousUserQuery: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @module botbuilder-ai
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

import { QnAMakerPrompt } from './qnamakerPrompt';

/**
* The context associated with QnA. Used to mark if the qna response has related prompts.
*/
export interface QnAResponseContext {

/**
* The prompts collection of related prompts.
*/
prompts: QnAMakerPrompt[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { QnAMakerMetadata } from './qnamakerMetadata';
import { QnARequestContext } from './qnaRequestContext';

/**
* Additional settings used to configure a `QnAMaker` instance.
Expand Down Expand Up @@ -42,5 +43,15 @@ export interface QnAMakerOptions {
*
* @remarks Defaults to "100000" milliseconds.
*/
timeout?: number;
timeout?: number;

/**
* The context of the previous turn.
*/
context?: QnARequestContext;

/**
* Id of the current question asked.
*/
qnaId?: number;
}
32 changes: 32 additions & 0 deletions libraries/botbuilder-ai/src/qnamaker-interfaces/qnamakerPrompt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @module botbuilder-ai
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* QnAMaker Prompt Object.
*/
export interface QnAMakerPrompt {

/**
* Display Order - index of the prompt - used in ordering of the prompts.
*/
displayOrder: number;

/**
* Qna id corresponding to the prompt - if QnaId is present, QnADTO object is ignored.
*/
qnaId: number;

/**
* The QnA object returned from the API (Optional parameter).
*/
qna?: object;

/**
* Display Text - Text displayed to represent a follow up question prompt.
*/
displayText: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Licensed under the MIT License.
*/

import { QnAResponseContext } from './qnaResponseContext';

/**
* An individual answer returned by a call to the QnA Maker Service.
*/
Expand Down Expand Up @@ -39,4 +41,9 @@ export interface QnAMakerResult {
* The index of the answer in the knowledge base. V3 uses 'qnaId', V4 uses 'id'. (If any)
*/
id?: number;

/**
* Context for multi-turn responses.
*/
context?: QnAResponseContext;
}
24 changes: 24 additions & 0 deletions libraries/botbuilder-ai/src/qnamaker-interfaces/qnamakerResults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @module botbuilder-ai
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

import { QnAMakerResult } from './qnamakerResult';

/**
* An object returned by a call to the QnA Maker Service.
*/
export interface QnAMakerResults {
/**
* The answers for a user query, sorted in decreasing order of ranking score.
*/
answers?: QnAMakerResult[];

/**
* The active learning enable flag.
*/
activeLearningEnabled?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { Activity } from 'botbuilder-core';
import { QnAMakerResult } from './qnamakerResult';
import { QnARequestContext } from './qnaRequestContext';

/**
* Trace info that we collect and emit from a QnA Maker query
Expand Down Expand Up @@ -47,4 +48,14 @@ export interface QnAMakerTraceInfo {
* Metadata related to query. Not used in JavaScript SDK v4 yet.
*/
metadataBoost: any[];

/**
* The context for multi-turn responses.
*/
context?: QnARequestContext;

/**
* Id of the current question asked.
*/
qnaId?: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { QnAMakerResult } from '../qnamaker-interfaces/qnamakerResult';
const MinimumScoreForLowScoreVariation = 20;

// Previous Low Score Variation Multiplier
const PreviousLowScoreVariationMultiplier = 1.4;
const PreviousLowScoreVariationMultiplier = 0.7;

// Max Low Score Variation Multiplier
const MaxLowScoreVariationMultiplier = 2.0;
const MaxLowScoreVariationMultiplier = 1.0;

// Maximum Score For Low Score Variation
const MaximumScoreForLowScoreVariation = 95.0;
Expand Down
Loading

0 comments on commit b4c7a86

Please sign in to comment.