@microsoft/agents-hosting-dialogs 0.1.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +20 -0
- package/dist/src/agentComponent.d.ts +18 -0
- package/dist/src/agentComponent.js +55 -0
- package/dist/src/agentComponent.js.map +1 -0
- package/dist/src/agentStateSet.d.ts +48 -0
- package/dist/src/agentStateSet.js +66 -0
- package/dist/src/agentStateSet.js.map +1 -0
- package/dist/src/choices/choice.d.ts +14 -0
- package/dist/src/choices/choice.js +7 -0
- package/dist/src/choices/choice.js.map +1 -0
- package/dist/src/choices/choiceFactory.d.ts +81 -0
- package/dist/src/choices/choiceFactory.js +133 -0
- package/dist/src/choices/choiceFactory.js.map +1 -0
- package/dist/src/choices/findChoices.d.ts +28 -0
- package/dist/src/choices/findChoices.js +46 -0
- package/dist/src/choices/findChoices.js.map +1 -0
- package/dist/src/choices/findValues.d.ts +36 -0
- package/dist/src/choices/findValues.js +129 -0
- package/dist/src/choices/findValues.js.map +1 -0
- package/dist/src/choices/index.d.ts +11 -0
- package/dist/src/choices/index.js +28 -0
- package/dist/src/choices/index.js.map +1 -0
- package/dist/src/choices/modelResult.d.ts +11 -0
- package/dist/src/choices/modelResult.js +3 -0
- package/dist/src/choices/modelResult.js.map +1 -0
- package/dist/src/choices/recognizeChoices.d.ts +16 -0
- package/dist/src/choices/recognizeChoices.js +81 -0
- package/dist/src/choices/recognizeChoices.js.map +1 -0
- package/dist/src/choices/tokenizer.d.ts +25 -0
- package/dist/src/choices/tokenizer.js +73 -0
- package/dist/src/choices/tokenizer.js.map +1 -0
- package/dist/src/componentDialog.d.ts +178 -0
- package/dist/src/componentDialog.js +252 -0
- package/dist/src/componentDialog.js.map +1 -0
- package/dist/src/componentRegistration.d.ts +22 -0
- package/dist/src/componentRegistration.js +32 -0
- package/dist/src/componentRegistration.js.map +1 -0
- package/dist/src/configurable.d.ts +22 -0
- package/dist/src/configurable.js +60 -0
- package/dist/src/configurable.js.map +1 -0
- package/dist/src/configuration.d.ts +11 -0
- package/dist/src/configuration.js +17 -0
- package/dist/src/configuration.js.map +1 -0
- package/dist/src/converter.d.ts +13 -0
- package/dist/src/converter.js +7 -0
- package/dist/src/converter.js.map +1 -0
- package/dist/src/dialog.d.ts +184 -0
- package/dist/src/dialog.js +201 -0
- package/dist/src/dialog.js.map +1 -0
- package/dist/src/dialogContainer.d.ts +61 -0
- package/dist/src/dialogContainer.js +82 -0
- package/dist/src/dialogContainer.js.map +1 -0
- package/dist/src/dialogContext.d.ts +272 -0
- package/dist/src/dialogContext.js +444 -0
- package/dist/src/dialogContext.js.map +1 -0
- package/dist/src/dialogContextError.d.ts +27 -0
- package/dist/src/dialogContextError.js +39 -0
- package/dist/src/dialogContextError.js.map +1 -0
- package/dist/src/dialogEvent.d.ts +20 -0
- package/dist/src/dialogEvent.js +3 -0
- package/dist/src/dialogEvent.js.map +1 -0
- package/dist/src/dialogEvents.d.ts +15 -0
- package/dist/src/dialogEvents.js +20 -0
- package/dist/src/dialogEvents.js.map +1 -0
- package/dist/src/dialogHelper.d.ts +32 -0
- package/dist/src/dialogHelper.js +116 -0
- package/dist/src/dialogHelper.js.map +1 -0
- package/dist/src/dialogInstance.d.ts +30 -0
- package/dist/src/dialogInstance.js +3 -0
- package/dist/src/dialogInstance.js.map +1 -0
- package/dist/src/dialogManager.d.ts +73 -0
- package/dist/src/dialogManager.js +156 -0
- package/dist/src/dialogManager.js.map +1 -0
- package/dist/src/dialogReason.d.ts +35 -0
- package/dist/src/dialogReason.js +40 -0
- package/dist/src/dialogReason.js.map +1 -0
- package/dist/src/dialogSet.d.ts +85 -0
- package/dist/src/dialogSet.js +138 -0
- package/dist/src/dialogSet.js.map +1 -0
- package/dist/src/dialogTurnResult.d.ts +34 -0
- package/dist/src/dialogTurnResult.js +3 -0
- package/dist/src/dialogTurnResult.js.map +1 -0
- package/dist/src/dialogTurnStateConstants.d.ts +12 -0
- package/dist/src/dialogTurnStateConstants.js +17 -0
- package/dist/src/dialogTurnStateConstants.js.map +1 -0
- package/dist/src/dialogTurnStatus.d.ts +34 -0
- package/dist/src/dialogTurnStatus.js +39 -0
- package/dist/src/dialogTurnStatus.js.map +1 -0
- package/dist/src/dialogsAgentComponent.d.ts +17 -0
- package/dist/src/dialogsAgentComponent.js +65 -0
- package/dist/src/dialogsAgentComponent.js.map +1 -0
- package/dist/src/dialogsComponentRegistration.d.ts +28 -0
- package/dist/src/dialogsComponentRegistration.js +45 -0
- package/dist/src/dialogsComponentRegistration.js.map +1 -0
- package/dist/src/i18n.d.ts +15 -0
- package/dist/src/i18n.js +28 -0
- package/dist/src/i18n.js.map +1 -0
- package/dist/src/index.d.ts +29 -0
- package/dist/src/index.js +48 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/intentScore.d.ts +11 -0
- package/dist/src/intentScore.js +3 -0
- package/dist/src/intentScore.js.map +1 -0
- package/dist/src/memory/componentMemoryScopes.d.ts +18 -0
- package/dist/src/memory/componentMemoryScopes.js +54 -0
- package/dist/src/memory/componentMemoryScopes.js.map +1 -0
- package/dist/src/memory/componentPathResolvers.d.ts +18 -0
- package/dist/src/memory/componentPathResolvers.js +52 -0
- package/dist/src/memory/componentPathResolvers.js.map +1 -0
- package/dist/src/memory/dialogPath.d.ts +17 -0
- package/dist/src/memory/dialogPath.js +30 -0
- package/dist/src/memory/dialogPath.js.map +1 -0
- package/dist/src/memory/dialogStateManager.d.ts +156 -0
- package/dist/src/memory/dialogStateManager.js +598 -0
- package/dist/src/memory/dialogStateManager.js.map +1 -0
- package/dist/src/memory/index.d.ts +12 -0
- package/dist/src/memory/index.js +29 -0
- package/dist/src/memory/index.js.map +1 -0
- package/dist/src/memory/pathResolvers/aliasPathResolver.d.ts +25 -0
- package/dist/src/memory/pathResolvers/aliasPathResolver.js +37 -0
- package/dist/src/memory/pathResolvers/aliasPathResolver.js.map +1 -0
- package/dist/src/memory/pathResolvers/atAtPathResolver.d.ts +11 -0
- package/dist/src/memory/pathResolvers/atAtPathResolver.js +18 -0
- package/dist/src/memory/pathResolvers/atAtPathResolver.js.map +1 -0
- package/dist/src/memory/pathResolvers/atPathResolver.d.ts +20 -0
- package/dist/src/memory/pathResolvers/atPathResolver.js +46 -0
- package/dist/src/memory/pathResolvers/atPathResolver.js.map +1 -0
- package/dist/src/memory/pathResolvers/dollarPathResolver.d.ts +11 -0
- package/dist/src/memory/pathResolvers/dollarPathResolver.js +18 -0
- package/dist/src/memory/pathResolvers/dollarPathResolver.js.map +1 -0
- package/dist/src/memory/pathResolvers/hashPathResolver.d.ts +11 -0
- package/dist/src/memory/pathResolvers/hashPathResolver.js +18 -0
- package/dist/src/memory/pathResolvers/hashPathResolver.js.map +1 -0
- package/dist/src/memory/pathResolvers/index.d.ts +11 -0
- package/dist/src/memory/pathResolvers/index.js +28 -0
- package/dist/src/memory/pathResolvers/index.js.map +1 -0
- package/dist/src/memory/pathResolvers/pathResolver.d.ts +13 -0
- package/dist/src/memory/pathResolvers/pathResolver.js +7 -0
- package/dist/src/memory/pathResolvers/pathResolver.js.map +1 -0
- package/dist/src/memory/pathResolvers/percentPathResolver.d.ts +11 -0
- package/dist/src/memory/pathResolvers/percentPathResolver.js +18 -0
- package/dist/src/memory/pathResolvers/percentPathResolver.js.map +1 -0
- package/dist/src/memory/scopePath.d.ts +18 -0
- package/dist/src/memory/scopePath.js +23 -0
- package/dist/src/memory/scopePath.js.map +1 -0
- package/dist/src/memory/scopes/agentStateMemoryScope.d.ts +53 -0
- package/dist/src/memory/scopes/agentStateMemoryScope.js +82 -0
- package/dist/src/memory/scopes/agentStateMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/classMemoryScope.d.ts +29 -0
- package/dist/src/memory/scopes/classMemoryScope.js +65 -0
- package/dist/src/memory/scopes/classMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/conversationMemoryScope.d.ts +15 -0
- package/dist/src/memory/scopes/conversationMemoryScope.js +23 -0
- package/dist/src/memory/scopes/conversationMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/dialogClassMemoryScope.d.ts +19 -0
- package/dist/src/memory/scopes/dialogClassMemoryScope.js +42 -0
- package/dist/src/memory/scopes/dialogClassMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/dialogContextMemoryScope.d.ts +19 -0
- package/dist/src/memory/scopes/dialogContextMemoryScope.js +48 -0
- package/dist/src/memory/scopes/dialogContextMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/dialogMemoryScope.d.ts +32 -0
- package/dist/src/memory/scopes/dialogMemoryScope.js +74 -0
- package/dist/src/memory/scopes/dialogMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/index.d.ts +15 -0
- package/dist/src/memory/scopes/index.js +32 -0
- package/dist/src/memory/scopes/index.js.map +1 -0
- package/dist/src/memory/scopes/memoryScope.d.ts +52 -0
- package/dist/src/memory/scopes/memoryScope.js +54 -0
- package/dist/src/memory/scopes/memoryScope.js.map +1 -0
- package/dist/src/memory/scopes/settingsMemoryScope.d.ts +68 -0
- package/dist/src/memory/scopes/settingsMemoryScope.js +216 -0
- package/dist/src/memory/scopes/settingsMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/thisMemoryScope.d.ts +26 -0
- package/dist/src/memory/scopes/thisMemoryScope.js +43 -0
- package/dist/src/memory/scopes/thisMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/turnMemoryScope.d.ts +29 -0
- package/dist/src/memory/scopes/turnMemoryScope.js +52 -0
- package/dist/src/memory/scopes/turnMemoryScope.js.map +1 -0
- package/dist/src/memory/scopes/userMemoryScope.d.ts +15 -0
- package/dist/src/memory/scopes/userMemoryScope.js +23 -0
- package/dist/src/memory/scopes/userMemoryScope.js.map +1 -0
- package/dist/src/memory/turnPath.d.ts +21 -0
- package/dist/src/memory/turnPath.js +38 -0
- package/dist/src/memory/turnPath.js.map +1 -0
- package/dist/src/prompts/activityPrompt.d.ts +101 -0
- package/dist/src/prompts/activityPrompt.js +166 -0
- package/dist/src/prompts/activityPrompt.js.map +1 -0
- package/dist/src/prompts/attachmentPrompt.d.ts +37 -0
- package/dist/src/prompts/attachmentPrompt.js +55 -0
- package/dist/src/prompts/attachmentPrompt.js.map +1 -0
- package/dist/src/prompts/choicePrompt.d.ts +83 -0
- package/dist/src/prompts/choicePrompt.js +116 -0
- package/dist/src/prompts/choicePrompt.js.map +1 -0
- package/dist/src/prompts/confirmPrompt.d.ts +82 -0
- package/dist/src/prompts/confirmPrompt.js +163 -0
- package/dist/src/prompts/confirmPrompt.js.map +1 -0
- package/dist/src/prompts/datetimePrompt.d.ts +65 -0
- package/dist/src/prompts/datetimePrompt.js +109 -0
- package/dist/src/prompts/datetimePrompt.js.map +1 -0
- package/dist/src/prompts/index.d.ts +13 -0
- package/dist/src/prompts/index.js +30 -0
- package/dist/src/prompts/index.js.map +1 -0
- package/dist/src/prompts/numberPrompt.d.ts +55 -0
- package/dist/src/prompts/numberPrompt.js +134 -0
- package/dist/src/prompts/numberPrompt.js.map +1 -0
- package/dist/src/prompts/prompt.d.ts +256 -0
- package/dist/src/prompts/prompt.js +260 -0
- package/dist/src/prompts/prompt.js.map +1 -0
- package/dist/src/prompts/promptCultureModels.d.ts +72 -0
- package/dist/src/prompts/promptCultureModels.js +123 -0
- package/dist/src/prompts/promptCultureModels.js.map +1 -0
- package/dist/src/prompts/textPrompt.d.ts +54 -0
- package/dist/src/prompts/textPrompt.js +72 -0
- package/dist/src/prompts/textPrompt.js.map +1 -0
- package/dist/src/recognizer.d.ts +43 -0
- package/dist/src/recognizer.js +104 -0
- package/dist/src/recognizer.js.map +1 -0
- package/dist/src/recognizerResult.d.ts +19 -0
- package/dist/src/recognizerResult.js +24 -0
- package/dist/src/recognizerResult.js.map +1 -0
- package/dist/src/serviceCollection.d.ts +112 -0
- package/dist/src/serviceCollection.js +209 -0
- package/dist/src/serviceCollection.js.map +1 -0
- package/dist/src/stringUtils.d.ts +36 -0
- package/dist/src/stringUtils.js +62 -0
- package/dist/src/stringUtils.js.map +1 -0
- package/dist/src/template.d.ts +18 -0
- package/dist/src/template.js +7 -0
- package/dist/src/template.js.map +1 -0
- package/dist/src/waterfallDialog.d.ts +101 -0
- package/dist/src/waterfallDialog.js +179 -0
- package/dist/src/waterfallDialog.js.map +1 -0
- package/dist/src/waterfallStepContext.d.ts +71 -0
- package/dist/src/waterfallStepContext.js +78 -0
- package/dist/src/waterfallStepContext.js.map +1 -0
- package/package.json +49 -0
- package/src/agentComponent.ts +23 -0
- package/src/agentStateSet.ts +75 -0
- package/src/choices/choice.ts +16 -0
- package/src/choices/choiceFactory.ts +189 -0
- package/src/choices/findChoices.ts +70 -0
- package/src/choices/findValues.ts +179 -0
- package/src/choices/index.ts +11 -0
- package/src/choices/modelResult.ts +11 -0
- package/src/choices/recognizeChoices.ts +94 -0
- package/src/choices/tokenizer.ts +93 -0
- package/src/componentDialog.ts +306 -0
- package/src/componentRegistration.ts +30 -0
- package/src/configurable.ts +55 -0
- package/src/configuration.ts +22 -0
- package/src/converter.ts +15 -0
- package/src/dialog.ts +243 -0
- package/src/dialogContainer.ts +90 -0
- package/src/dialogContext.ts +607 -0
- package/src/dialogContextError.ts +50 -0
- package/src/dialogEvent.ts +23 -0
- package/src/dialogEvents.ts +16 -0
- package/src/dialogHelper.ts +154 -0
- package/src/dialogInstance.ts +32 -0
- package/src/dialogManager.ts +202 -0
- package/src/dialogReason.ts +40 -0
- package/src/dialogSet.ts +168 -0
- package/src/dialogTurnResult.ts +37 -0
- package/src/dialogTurnStateConstants.ts +13 -0
- package/src/dialogTurnStatus.ts +38 -0
- package/src/dialogsAgentComponent.ts +71 -0
- package/src/dialogsComponentRegistration.ts +49 -0
- package/src/i18n.ts +17 -0
- package/src/index.ts +31 -0
- package/src/intentScore.ts +11 -0
- package/src/memory/componentMemoryScopes.ts +28 -0
- package/src/memory/componentPathResolvers.ts +29 -0
- package/src/memory/dialogPath.ts +33 -0
- package/src/memory/dialogStateManager.ts +661 -0
- package/src/memory/index.ts +12 -0
- package/src/memory/pathResolvers/aliasPathResolver.ts +44 -0
- package/src/memory/pathResolvers/atAtPathResolver.ts +14 -0
- package/src/memory/pathResolvers/atPathResolver.ts +45 -0
- package/src/memory/pathResolvers/dollarPathResolver.ts +14 -0
- package/src/memory/pathResolvers/hashPathResolver.ts +14 -0
- package/src/memory/pathResolvers/index.ts +11 -0
- package/src/memory/pathResolvers/pathResolver.ts +14 -0
- package/src/memory/pathResolvers/percentPathResolver.ts +14 -0
- package/src/memory/scopePath.ts +19 -0
- package/src/memory/scopes/agentStateMemoryScope.ts +92 -0
- package/src/memory/scopes/classMemoryScope.ts +71 -0
- package/src/memory/scopes/conversationMemoryScope.ts +19 -0
- package/src/memory/scopes/dialogClassMemoryScope.ts +43 -0
- package/src/memory/scopes/dialogContextMemoryScope.ts +51 -0
- package/src/memory/scopes/dialogMemoryScope.ts +79 -0
- package/src/memory/scopes/index.ts +15 -0
- package/src/memory/scopes/memoryScope.ts +70 -0
- package/src/memory/scopes/settingsMemoryScope.ts +239 -0
- package/src/memory/scopes/thisMemoryScope.ts +44 -0
- package/src/memory/scopes/turnMemoryScope.ts +54 -0
- package/src/memory/scopes/userMemoryScope.ts +19 -0
- package/src/memory/turnPath.ts +45 -0
- package/src/prompts/activityPrompt.ts +202 -0
- package/src/prompts/attachmentPrompt.ts +62 -0
- package/src/prompts/choicePrompt.ts +176 -0
- package/src/prompts/confirmPrompt.ts +182 -0
- package/src/prompts/datetimePrompt.ts +110 -0
- package/src/prompts/index.ts +13 -0
- package/src/prompts/numberPrompt.ts +117 -0
- package/src/prompts/prompt.ts +459 -0
- package/src/prompts/promptCultureModels.ts +178 -0
- package/src/prompts/textPrompt.ts +82 -0
- package/src/recognizer.ts +127 -0
- package/src/recognizerResult.ts +37 -0
- package/src/serviceCollection.ts +305 -0
- package/src/stringUtils.ts +62 -0
- package/src/template.ts +20 -0
- package/src/waterfallDialog.ts +215 -0
- package/src/waterfallStepContext.ts +96 -0
- package/vendor/cldr-data/README.md +5 -0
- package/vendor/cldr-data/main/de/numbers.json +156 -0
- package/vendor/cldr-data/main/en/numbers.json +159 -0
- package/vendor/cldr-data/main/es/numbers.json +156 -0
- package/vendor/cldr-data/main/fr/numbers.json +157 -0
- package/vendor/cldr-data/main/ja/numbers.json +120 -0
- package/vendor/cldr-data/main/nl/numbers.json +156 -0
- package/vendor/cldr-data/main/pt/numbers.json +156 -0
- package/vendor/cldr-data/main/zh/numbers.json +214 -0
- package/vendor/cldr-data/supplemental/likelySubtags.json +1844 -0
- package/vendor/cldr-data/supplemental/numberingSystems.json +343 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { InputHints, TurnContext } from '@microsoft/agents-hosting'
|
|
6
|
+
import { Prompt, PromptOptions, PromptRecognizerResult, PromptValidator } from './prompt'
|
|
7
|
+
import { DialogContext } from '../dialogContext'
|
|
8
|
+
import { DialogEvent } from '../dialogEvent'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Prompts a user to enter some text.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* By default the prompt will return to the calling dialog a `string` representing the users reply.
|
|
15
|
+
*/
|
|
16
|
+
export class TextPrompt extends Prompt<string> {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
18
|
+
constructor (dialogId?: string, validator?: PromptValidator<string>) {
|
|
19
|
+
super(dialogId, validator)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Prompts the user for input.
|
|
24
|
+
*
|
|
25
|
+
* @param context TurnContext, context for the current
|
|
26
|
+
* turn of conversation with the user.
|
|
27
|
+
* @param state Contains state for the current instance of the prompt on the dialog stack.
|
|
28
|
+
* @param options A PromptOptions object constructed
|
|
29
|
+
* from the options initially provided in the call to Prompt.
|
|
30
|
+
* @param isRetry `true` if this is the first time this prompt dialog instance
|
|
31
|
+
* on the stack is prompting the user for input; otherwise, false.
|
|
32
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
33
|
+
*/
|
|
34
|
+
protected async onPrompt (
|
|
35
|
+
context: TurnContext,
|
|
36
|
+
state: any,
|
|
37
|
+
options: PromptOptions,
|
|
38
|
+
isRetry: boolean
|
|
39
|
+
): Promise<void> {
|
|
40
|
+
if (isRetry && options.retryPrompt) {
|
|
41
|
+
await context.sendActivity(options.retryPrompt, undefined, InputHints.ExpectingInput)
|
|
42
|
+
} else if (options.prompt) {
|
|
43
|
+
await context.sendActivity(options.prompt, undefined, InputHints.ExpectingInput)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Attempts to recognize the user's input.
|
|
49
|
+
*
|
|
50
|
+
* @param context TurnContext, context for the current
|
|
51
|
+
* turn of conversation with the user.
|
|
52
|
+
* @param _state Contains state for the current instance of the prompt on the dialog stack.
|
|
53
|
+
* @param _options A PromptOptions object constructed
|
|
54
|
+
* from the options initially provided in the call to Prompt.
|
|
55
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
56
|
+
*/
|
|
57
|
+
protected async onRecognize (
|
|
58
|
+
context: TurnContext,
|
|
59
|
+
_state: any,
|
|
60
|
+
_options: PromptOptions
|
|
61
|
+
): Promise<PromptRecognizerResult<string>> {
|
|
62
|
+
const value: string = context.activity.text
|
|
63
|
+
|
|
64
|
+
return typeof value === 'string' && value.length > 0 ? { succeeded: true, value } : { succeeded: false }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Called before an event is bubbled to its parent.
|
|
69
|
+
*
|
|
70
|
+
* @param _dc The DialogContext for the current
|
|
71
|
+
* turn of conversation.
|
|
72
|
+
* @param _event DialogEvent, the event being raised.
|
|
73
|
+
* @returns Whether the event is handled by the current dialog and further processing should stop.
|
|
74
|
+
* @remarks
|
|
75
|
+
* This is a good place to perform interception of an event as returning `true` will prevent
|
|
76
|
+
* any further bubbling of the event to the dialogs parents and will also prevent any child
|
|
77
|
+
* dialogs from performing their default processing.
|
|
78
|
+
*/
|
|
79
|
+
protected async onPreBubbleEvent (_dc: DialogContext, _event: DialogEvent): Promise<boolean> {
|
|
80
|
+
return false
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { Activity } from '@microsoft/agents-hosting'
|
|
6
|
+
import { Configurable } from './configurable'
|
|
7
|
+
import { DialogContext } from './dialogContext'
|
|
8
|
+
import omit from 'lodash/omit'
|
|
9
|
+
import { RecognizerResult, getTopScoringIntent } from './recognizerResult'
|
|
10
|
+
|
|
11
|
+
export interface RecognizerConfiguration {
|
|
12
|
+
id?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Recognizer base class.
|
|
17
|
+
*/
|
|
18
|
+
export class Recognizer extends Configurable implements RecognizerConfiguration {
|
|
19
|
+
id?: string
|
|
20
|
+
/**
|
|
21
|
+
* To recognize intents and entities in a users utterance.
|
|
22
|
+
*
|
|
23
|
+
* @param {DialogContext} _dialogContext Dialog Context.
|
|
24
|
+
* @param {Partial<Activity>} _activity Activity.
|
|
25
|
+
* @param {Record<string, string>} _telemetryProperties Additional properties to be logged to telemetry with event.
|
|
26
|
+
* @param {Record<string, number>} _telemetryMetrics Additional metrics to be logged to telemetry with event.
|
|
27
|
+
*/
|
|
28
|
+
recognize (
|
|
29
|
+
_dialogContext: DialogContext,
|
|
30
|
+
_activity: Partial<Activity>,
|
|
31
|
+
_telemetryProperties?: Record<string, string>,
|
|
32
|
+
_telemetryMetrics?: Record<string, number>
|
|
33
|
+
): Promise<RecognizerResult> {
|
|
34
|
+
throw new Error('Please implement recognize function.')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates choose intent result in the case that there are conflicting or ambiguous signals from the recognizers.
|
|
39
|
+
*
|
|
40
|
+
* @param {Record<string, RecognizerResult>} recognizerResults A group of recognizer results.
|
|
41
|
+
* @returns {RecognizerResult} Recognizer result which is ChooseIntent.
|
|
42
|
+
*/
|
|
43
|
+
protected createChooseIntentResult (recognizerResults: Record<string, RecognizerResult>): RecognizerResult {
|
|
44
|
+
let text: string = ''
|
|
45
|
+
let sentiment: Record<string, any> = {}
|
|
46
|
+
type candidateType = { id: string; intent: string; score: number; result: RecognizerResult }
|
|
47
|
+
const candidates = Object.entries(recognizerResults).reduce((candidates: candidateType[], [key, result]) => {
|
|
48
|
+
text = result.text
|
|
49
|
+
sentiment = result.sentiment
|
|
50
|
+
const { intent, score } = getTopScoringIntent(result)
|
|
51
|
+
if (intent !== 'None') {
|
|
52
|
+
candidates.push({
|
|
53
|
+
id: key,
|
|
54
|
+
intent,
|
|
55
|
+
score,
|
|
56
|
+
result,
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
return candidates
|
|
60
|
+
}, [])
|
|
61
|
+
|
|
62
|
+
if (candidates.length) {
|
|
63
|
+
const recognizerResult: RecognizerResult = {
|
|
64
|
+
text,
|
|
65
|
+
intents: { ChooseIntent: { score: 1.0 } },
|
|
66
|
+
candidates,
|
|
67
|
+
entities: {},
|
|
68
|
+
}
|
|
69
|
+
return recognizerResult
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// just return a `None` intent.
|
|
73
|
+
const recognizerResult: RecognizerResult = {
|
|
74
|
+
text,
|
|
75
|
+
intents: { None: { score: 1.0 } },
|
|
76
|
+
entities: {},
|
|
77
|
+
sentiment,
|
|
78
|
+
}
|
|
79
|
+
return recognizerResult
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Uses the RecognizerResult to create a list of properties to be included when tracking the result in telemetry.
|
|
84
|
+
*
|
|
85
|
+
* @param {RecognizerResult} recognizerResult Recognizer Result.
|
|
86
|
+
* @param {Record<string, string>} telemetryProperties A list of properties to append or override the properties created using the RecognizerResult.
|
|
87
|
+
* @param {DialogContext} _dialogContext Dialog Context.
|
|
88
|
+
* @returns {Record<string, string>} A collection of properties that can be included when calling the TrackEvent method on the TelemetryClient.
|
|
89
|
+
*/
|
|
90
|
+
protected fillRecognizerResultTelemetryProperties (
|
|
91
|
+
recognizerResult: RecognizerResult,
|
|
92
|
+
telemetryProperties: Record<string, string>,
|
|
93
|
+
_dialogContext?: DialogContext
|
|
94
|
+
): Record<string, string> {
|
|
95
|
+
const { intent, score } = getTopScoringIntent(recognizerResult)
|
|
96
|
+
const intents = Object.entries(recognizerResult.intents)
|
|
97
|
+
|
|
98
|
+
const properties: Record<string, string > = {
|
|
99
|
+
Text: recognizerResult.text,
|
|
100
|
+
AlteredText: recognizerResult.alteredText ?? '',
|
|
101
|
+
TopIntent: intents.length > 0 ? intent : '',
|
|
102
|
+
TopIntentScore: intents.length > 0 ? score.toString() : '',
|
|
103
|
+
Intents: intents.length > 0 ? JSON.stringify(recognizerResult.intents) : '',
|
|
104
|
+
Entities: recognizerResult.entities ? JSON.stringify(recognizerResult.entities) : '',
|
|
105
|
+
AdditionalProperties: JSON.stringify(
|
|
106
|
+
omit(recognizerResult, ['text', 'alteredText', 'intents', 'entities'])
|
|
107
|
+
),
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (telemetryProperties) {
|
|
111
|
+
return Object.assign({}, properties, telemetryProperties)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return properties
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
protected stringifyAdditionalPropertiesOfRecognizerResult (recognizerResult: RecognizerResult): string {
|
|
118
|
+
const generalProperties = new Set(['text', 'alteredText', 'intents', 'entities'])
|
|
119
|
+
const additionalProperties: { [key: string]: string } = {}
|
|
120
|
+
for (const key in recognizerResult) {
|
|
121
|
+
if (!generalProperties.has(key)) {
|
|
122
|
+
additionalProperties[key] = recognizerResult[key]
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return Object.keys(additionalProperties).length > 0 ? JSON.stringify(additionalProperties) : ''
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IntentScore } from './intentScore'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Value returned from a recognizer.
|
|
9
|
+
*/
|
|
10
|
+
export interface RecognizerResult {
|
|
11
|
+
text: string;
|
|
12
|
+
alteredText?: string;
|
|
13
|
+
intents: Record<string, IntentScore>;
|
|
14
|
+
entities?: any;
|
|
15
|
+
[propName: string]: any;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const getTopScoringIntent = (result: RecognizerResult): { intent: string; score: number } => {
|
|
19
|
+
if (!result || !result.intents) {
|
|
20
|
+
throw new Error('result is empty')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let topIntent = ''
|
|
24
|
+
let topScore = -1
|
|
25
|
+
for (const [intentName, intent] of Object.entries(result.intents)) {
|
|
26
|
+
const score = intent.score ?? -1
|
|
27
|
+
if (!topIntent || score > topScore) {
|
|
28
|
+
topIntent = intentName
|
|
29
|
+
topScore = score
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
intent: topIntent,
|
|
35
|
+
score: topScore,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import assert, { ok } from 'assert'
|
|
5
|
+
import { DepGraph } from 'dependency-graph'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Factory describes a generic factory function signature. The type is generic over a few parameters:
|
|
9
|
+
*
|
|
10
|
+
* @template Type type the factory produces
|
|
11
|
+
* @template Initial true if the `initialValue` passed to the factory must be defined
|
|
12
|
+
*/
|
|
13
|
+
export type Factory<Type, Initial extends boolean> = (
|
|
14
|
+
initialValue: Initial extends true ? Type : Type | undefined,
|
|
15
|
+
) => Type
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* DependencyFactory is a function signature that produces an instance that depends on a set of
|
|
19
|
+
* other services. The type is generic over a few parameters:
|
|
20
|
+
*
|
|
21
|
+
* @template Type type the factory produces
|
|
22
|
+
* @template Dependencies the services this factory function depends on
|
|
23
|
+
* @template Initial true if the `initialValue` passed to the factory must be defined
|
|
24
|
+
*/
|
|
25
|
+
export type DependencyFactory<Type, Dependencies, Initial extends boolean> = (
|
|
26
|
+
dependencies: Dependencies,
|
|
27
|
+
initialValue: Initial extends true ? Type : Type | undefined,
|
|
28
|
+
) => Type
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* ServiceCollection is an interface that describes a set of methods to register services. This, in a lighter way,
|
|
32
|
+
* mimics the .NET dependency injection service collection functionality, except for instances rather than types.
|
|
33
|
+
*/
|
|
34
|
+
export class ServiceCollection {
|
|
35
|
+
// We store the full set of dependencies as a workaround to the fact that `DepGraph` throws an error if you
|
|
36
|
+
// attempt to register a dependency to a node that does not yet exist.
|
|
37
|
+
private readonly dependencies: Map<string, string[]> = new Map<string, string[]>()
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* `DepGraph` is a dependency graph data structure. In our case, the services we support are encoded as a
|
|
41
|
+
* dependency graph where nodes are named with a key and store a list of factory methods.
|
|
42
|
+
*/
|
|
43
|
+
private readonly graph = new DepGraph<Array<DependencyFactory<unknown, Record<string, unknown>, true>>>()
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Cache constructed instances for reuse
|
|
47
|
+
*/
|
|
48
|
+
private cache: Record<string, unknown> = {}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Construct a Providers instance
|
|
52
|
+
*
|
|
53
|
+
* @template S services interface
|
|
54
|
+
* @param defaultServices default set of services
|
|
55
|
+
*/
|
|
56
|
+
constructor (defaultServices: Record<string, unknown> = {}) {
|
|
57
|
+
Object.entries(defaultServices).forEach(([key, instance]) => {
|
|
58
|
+
this.addInstance(key, instance)
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Register an instance by key. This will overwrite existing instances.
|
|
64
|
+
*
|
|
65
|
+
* @param key key of the instance being provided
|
|
66
|
+
* @param instance instance to provide
|
|
67
|
+
* @returns this for chaining
|
|
68
|
+
*/
|
|
69
|
+
addInstance<InstanceType>(key: string, instance: InstanceType): this {
|
|
70
|
+
if (this.graph.hasNode(key)) {
|
|
71
|
+
this.graph.removeNode(key)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.graph.addNode(key, [() => instance])
|
|
75
|
+
return this
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Register a factory for a key.
|
|
80
|
+
*
|
|
81
|
+
* @param key key that factory will provide
|
|
82
|
+
* @param factory function that creates an instance to provide
|
|
83
|
+
* @returns this for chaining
|
|
84
|
+
*/
|
|
85
|
+
addFactory<InstanceType>(key: string, factory: Factory<InstanceType, false>): this
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Register a factory for a key with a set of dependencies.
|
|
89
|
+
*
|
|
90
|
+
* @param key key that factory will provide
|
|
91
|
+
* @param dependencies set of things this instance depends on. Will be provided to factory function via `services`.
|
|
92
|
+
* @param factory function that creates an instance to provide
|
|
93
|
+
* @returns this for chaining
|
|
94
|
+
*/
|
|
95
|
+
addFactory<InstanceType, Dependencies>(
|
|
96
|
+
key: string,
|
|
97
|
+
dependencies: string[],
|
|
98
|
+
factory: DependencyFactory<InstanceType, Dependencies, false>,
|
|
99
|
+
): this
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
104
|
+
addFactory<InstanceType, Dependencies>(
|
|
105
|
+
key: string,
|
|
106
|
+
depsOrFactory: string[] | Factory<InstanceType, false>,
|
|
107
|
+
maybeFactory?: DependencyFactory<InstanceType, Dependencies, false>
|
|
108
|
+
): this {
|
|
109
|
+
const dependencies = Array.isArray(depsOrFactory) ? depsOrFactory : undefined
|
|
110
|
+
|
|
111
|
+
let factory: DependencyFactory<InstanceType, Dependencies, false> | undefined = maybeFactory
|
|
112
|
+
if (!factory && typeof depsOrFactory === 'function') {
|
|
113
|
+
factory = (_services, value) => depsOrFactory(value)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Asserts factory is not undefined
|
|
117
|
+
ok(factory, 'illegal invocation with undefined factory')
|
|
118
|
+
|
|
119
|
+
if (dependencies) {
|
|
120
|
+
this.dependencies.set(key, dependencies)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// If the graph already has this key, fetch its data and remove it (to be replaced)
|
|
124
|
+
let factories: unknown[] = []
|
|
125
|
+
if (this.graph.hasNode(key)) {
|
|
126
|
+
factories = this.graph.getNodeData(key)
|
|
127
|
+
this.graph.removeNode(key)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.graph.addNode(key, factories.concat(factory) as any)
|
|
131
|
+
|
|
132
|
+
return this
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Register a factory (that expects the initial value that is not undefined) for a key.
|
|
137
|
+
*
|
|
138
|
+
* @param key key of the instance being provided
|
|
139
|
+
* @param instance instance to provide
|
|
140
|
+
* @returns this for chaining
|
|
141
|
+
*/
|
|
142
|
+
composeFactory<InstanceType>(key: string, factory: Factory<InstanceType, true>): this
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Register a factory (that expects an initial value that is not undefined) for a key
|
|
146
|
+
* with a set of dependencies.
|
|
147
|
+
*
|
|
148
|
+
* @param key key that factory will provide
|
|
149
|
+
* @param dependencies set of things this instance depends on. Will be provided to factory function via `services`.
|
|
150
|
+
* @param factory function that creates an instance to provide
|
|
151
|
+
* @returns this for chaining
|
|
152
|
+
*/
|
|
153
|
+
composeFactory<InstanceType, Dependencies>(
|
|
154
|
+
key: string,
|
|
155
|
+
dependencies: string[],
|
|
156
|
+
factory: DependencyFactory<InstanceType, Dependencies, true>,
|
|
157
|
+
): this
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
162
|
+
composeFactory<InstanceType, Dependencies>(
|
|
163
|
+
key: string,
|
|
164
|
+
depsOrFactory: string[] | Factory<InstanceType, true>,
|
|
165
|
+
maybeFactory?: DependencyFactory<InstanceType, Dependencies, true>
|
|
166
|
+
): this {
|
|
167
|
+
if (maybeFactory) {
|
|
168
|
+
return this.addFactory<InstanceType, Dependencies>(
|
|
169
|
+
key,
|
|
170
|
+
Array.isArray(depsOrFactory) ? depsOrFactory : [],
|
|
171
|
+
(dependencies, value) => {
|
|
172
|
+
ok(value, `unable to create ${key}, initial value undefined`)
|
|
173
|
+
|
|
174
|
+
return maybeFactory(dependencies, value)
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
} else {
|
|
178
|
+
ok(typeof depsOrFactory === 'function', 'illegal invocation with undefined factory')
|
|
179
|
+
|
|
180
|
+
return this.addFactory<InstanceType>(key, (value) => {
|
|
181
|
+
ok(value, `unable to create ${key}, initial value undefined`)
|
|
182
|
+
|
|
183
|
+
return depsOrFactory(value)
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Register dependencies and then build nodes. Note: `nodes` is a function because ordering may
|
|
189
|
+
// depend on results of dependency registration
|
|
190
|
+
private buildNodes<ReturnType = Record<string, unknown>>(
|
|
191
|
+
generateNodes: () => string[],
|
|
192
|
+
reuseServices: Record<string, unknown> = {}
|
|
193
|
+
): ReturnType {
|
|
194
|
+
// Consume all dependencies and then reset so updating registrations without re-registering
|
|
195
|
+
// dependencies works
|
|
196
|
+
this.dependencies.forEach((dependencies, node) =>
|
|
197
|
+
dependencies.forEach((dependency) => this.graph.addDependency(node, dependency))
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
// Generate nodes after registering dependencies so ordering is correct
|
|
201
|
+
const nodes = generateNodes()
|
|
202
|
+
|
|
203
|
+
const services = nodes.reduce(
|
|
204
|
+
(services, service) => {
|
|
205
|
+
// Extra precaution
|
|
206
|
+
if (!this.graph.hasNode(service)) {
|
|
207
|
+
return services
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Helper to generate return value
|
|
211
|
+
const assignValue = (value: unknown) => ({
|
|
212
|
+
...services,
|
|
213
|
+
[service]: value,
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
// Optionally reuse existing service
|
|
217
|
+
const reusedService = reuseServices[service]
|
|
218
|
+
if (reusedService !== undefined) {
|
|
219
|
+
return assignValue(reusedService)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Each node stores a list of factory methods.
|
|
223
|
+
const factories = this.graph.getNodeData(service)
|
|
224
|
+
|
|
225
|
+
// Produce the instance by reducing those factories, passing the instance along for composition.
|
|
226
|
+
const instance = factories.reduce(
|
|
227
|
+
(value, factory) => factory(services, value),
|
|
228
|
+
<unknown>services[service]
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
return assignValue(instance)
|
|
232
|
+
},
|
|
233
|
+
<Record<string, unknown>>{}
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
// Cache results for subsequent invocations that may desire pre-constructed instances
|
|
237
|
+
Object.assign(this.cache, services)
|
|
238
|
+
|
|
239
|
+
return services as ReturnType
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Build a single service.
|
|
244
|
+
*
|
|
245
|
+
* @param key service to build
|
|
246
|
+
* @param deep reconstruct all dependencies
|
|
247
|
+
* @returns the service instance, or undefined
|
|
248
|
+
*/
|
|
249
|
+
makeInstance<InstanceType = unknown>(key: string, deep = false): InstanceType | undefined {
|
|
250
|
+
// If this is not a deep reconstruction, reuse any services that `key` depends on
|
|
251
|
+
let initialServices: Record<string, unknown> | undefined
|
|
252
|
+
if (!deep) {
|
|
253
|
+
const { [key]: _, ...cached } = this.cache
|
|
254
|
+
initialServices = cached
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const services = this.buildNodes<Record<string, InstanceType | undefined>>(
|
|
258
|
+
() => this.graph.dependenciesOf(key).concat(key),
|
|
259
|
+
initialServices
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
return services[key]
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Build a single service and assert that it is not undefined.
|
|
267
|
+
*
|
|
268
|
+
* @param key service to build
|
|
269
|
+
* @param deep reconstruct all dependencies
|
|
270
|
+
* @returns the service instance
|
|
271
|
+
*/
|
|
272
|
+
mustMakeInstance<InstanceType = unknown>(key: string, deep = false): InstanceType {
|
|
273
|
+
const instance = this.makeInstance<InstanceType>(key, deep)
|
|
274
|
+
assert.ok(instance, `\`${key}\` instance undefined!`)
|
|
275
|
+
|
|
276
|
+
return instance
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Build the full set of services.
|
|
281
|
+
*
|
|
282
|
+
* @returns all resolved services
|
|
283
|
+
*/
|
|
284
|
+
makeInstances<InstancesType>(): InstancesType {
|
|
285
|
+
return this.buildNodes<InstancesType>(() => this.graph.overallOrder())
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Build the full set of services, asserting that the specified keys are not undefined.
|
|
290
|
+
*
|
|
291
|
+
* @param keys instances that must be not undefined
|
|
292
|
+
* @returns all resolve services
|
|
293
|
+
*/
|
|
294
|
+
mustMakeInstances<InstancesType extends Record<string, unknown> = Record<string, unknown>>(
|
|
295
|
+
...keys: string[]
|
|
296
|
+
): InstancesType {
|
|
297
|
+
const instances = this.makeInstances<InstancesType>()
|
|
298
|
+
|
|
299
|
+
keys.forEach((key) => {
|
|
300
|
+
assert.ok(instances[key], `\`${key}\` instance undefined!`)
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
return instances
|
|
304
|
+
}
|
|
305
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Helper class containing string utility methods.
|
|
8
|
+
*/
|
|
9
|
+
export class StringUtils {
|
|
10
|
+
/**
|
|
11
|
+
* Truncate string with ...
|
|
12
|
+
*
|
|
13
|
+
* @param text Text.
|
|
14
|
+
* @param length Length to truncate text.
|
|
15
|
+
* @returns Original string modified.
|
|
16
|
+
*/
|
|
17
|
+
static ellipsis (text: string, length: number): string {
|
|
18
|
+
text = text || ''
|
|
19
|
+
if (text.length <= length) {
|
|
20
|
+
return text
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return `${text.substr(0, length)}...`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* UniqueHash - create a unique hash from a string.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* The source for this function was derived from the following article:
|
|
31
|
+
*
|
|
32
|
+
* https://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
|
|
33
|
+
* @param text Text to hash.
|
|
34
|
+
* @returns A string which is an unique hash.
|
|
35
|
+
*/
|
|
36
|
+
static hash (text: string): string {
|
|
37
|
+
const length = text.length
|
|
38
|
+
let hash = 0
|
|
39
|
+
for (let i = 0; i < length; i++) {
|
|
40
|
+
const chr = text.charCodeAt(i)
|
|
41
|
+
hash = (hash << 5) - hash + chr
|
|
42
|
+
hash |= 0 // Convert to 32 bit integer
|
|
43
|
+
}
|
|
44
|
+
return hash.toString()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* EllipsisHash - create truncated string with unique hash for the truncated part.
|
|
49
|
+
*
|
|
50
|
+
* @param text Text to truncate.
|
|
51
|
+
* @param length Length to truncate at.
|
|
52
|
+
* @returns The truncated string with unique hash for the truncated part.
|
|
53
|
+
*/
|
|
54
|
+
static ellipsisHash (text: string, length: number): string {
|
|
55
|
+
text = text || ''
|
|
56
|
+
if (text.length <= length) {
|
|
57
|
+
return text
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return `${this.ellipsis(text, length)}${this.hash(text)}`
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/template.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { DialogContext } from './dialogContext'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Defines Template interface for binding data to T.
|
|
10
|
+
*/
|
|
11
|
+
export interface TemplateInterface<T, D = Record<string, unknown>> {
|
|
12
|
+
/**
|
|
13
|
+
* Given the turn context bind to the data to create the object
|
|
14
|
+
*
|
|
15
|
+
* @param dialogContext DialogContext.
|
|
16
|
+
* @param data Data to bind to.
|
|
17
|
+
* @returns Instance of T.
|
|
18
|
+
*/
|
|
19
|
+
bind(dialogContext: DialogContext, data?: D): Promise<T>;
|
|
20
|
+
}
|