@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,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ComponentRegistration is a signature class for discovering assets from components.
|
|
8
|
+
*/
|
|
9
|
+
export class ComponentRegistration {
|
|
10
|
+
private static readonly _components: Map<string, ComponentRegistration> = new Map<string, ComponentRegistration>()
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Gets list of all ComponentRegistration objects registered.
|
|
14
|
+
*
|
|
15
|
+
* @returns A list of ComponentRegistration objects.
|
|
16
|
+
*/
|
|
17
|
+
static get components (): ComponentRegistration[] {
|
|
18
|
+
return Array.from(ComponentRegistration._components.values())
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Add a component, only one instance per type is allowed for components.
|
|
23
|
+
*
|
|
24
|
+
* @param componentRegistration The component to be registered.
|
|
25
|
+
*/
|
|
26
|
+
static add (componentRegistration: ComponentRegistration): void {
|
|
27
|
+
const name = componentRegistration.constructor.name
|
|
28
|
+
ComponentRegistration._components.set(name, componentRegistration)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Converter, ConverterFactory } from './converter'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Base class for all configurable classes.
|
|
10
|
+
*/
|
|
11
|
+
export abstract class Configurable {
|
|
12
|
+
/**
|
|
13
|
+
* Fluent method for configuring the object.
|
|
14
|
+
*
|
|
15
|
+
* @param config Configuration settings to apply.
|
|
16
|
+
* @returns The Configurable after the operation is complete.
|
|
17
|
+
*/
|
|
18
|
+
configure (config: Record<string, unknown>): this {
|
|
19
|
+
for (const key in config) {
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(config, key)) {
|
|
21
|
+
const setting = config[`${key}`]
|
|
22
|
+
const converter = this.getConverter(key)
|
|
23
|
+
if (converter && typeof converter === 'object') {
|
|
24
|
+
this[`${key}`] = converter.convert(setting)
|
|
25
|
+
} else {
|
|
26
|
+
if (Array.isArray(setting)) {
|
|
27
|
+
this[`${key}`] = setting
|
|
28
|
+
} else if (typeof setting === 'object') {
|
|
29
|
+
if (typeof this[`${key}`] === 'object') {
|
|
30
|
+
// Apply as a map update
|
|
31
|
+
for (const child in setting) {
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(setting, child)) {
|
|
33
|
+
this[`${key}`][`${child}`] = setting[`${child}`]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
this[`${key}`] = setting
|
|
38
|
+
}
|
|
39
|
+
} else if (setting !== undefined) {
|
|
40
|
+
this[`${key}`] = setting
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return this
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param _property The key of the conditional selector configuration.
|
|
50
|
+
* @returns The converter for the selector configuration.
|
|
51
|
+
*/
|
|
52
|
+
getConverter (_property: string): Converter | ConverterFactory {
|
|
53
|
+
return undefined
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration is an interface that is used to obtain configurable values
|
|
6
|
+
*/
|
|
7
|
+
export interface Configuration {
|
|
8
|
+
get<T = unknown>(path?: string[]): T | undefined;
|
|
9
|
+
set(path: string[], value: unknown): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Useful for shimming Components into ComponentRegistrations
|
|
14
|
+
*/
|
|
15
|
+
export const noOpConfiguration: Configuration = {
|
|
16
|
+
get (_path) {
|
|
17
|
+
return undefined
|
|
18
|
+
},
|
|
19
|
+
set (_path, _value) {
|
|
20
|
+
// no-op
|
|
21
|
+
},
|
|
22
|
+
}
|
package/src/converter.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The converter converts object from one type to another.
|
|
8
|
+
*/
|
|
9
|
+
export interface Converter<From = unknown, To = unknown> {
|
|
10
|
+
convert(value: From | To): To;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type ConverterFactory<From = unknown, To = unknown> = {
|
|
14
|
+
new (...args: unknown[]): Converter<From, To>;
|
|
15
|
+
}
|
package/src/dialog.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { TurnContext } from '@microsoft/agents-hosting'
|
|
6
|
+
import { DialogContext } from './dialogContext'
|
|
7
|
+
import { Configurable } from './configurable'
|
|
8
|
+
import { DialogTurnResult } from './dialogTurnResult'
|
|
9
|
+
import { DialogEvent } from './dialogEvent'
|
|
10
|
+
import { DialogReason } from './dialogReason'
|
|
11
|
+
import { DialogInstance } from './dialogInstance'
|
|
12
|
+
import { DialogTurnStatus } from './dialogTurnStatus'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Defines the core behavior for all dialogs.
|
|
16
|
+
*/
|
|
17
|
+
export abstract class Dialog<O extends object = {}> extends Configurable {
|
|
18
|
+
private _id: string
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Gets a default end-of-turn result.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* This result indicates that a dialog (or a logical step within a dialog) has completed
|
|
25
|
+
* processing for the current turn, is still active, and is waiting for more input.
|
|
26
|
+
*/
|
|
27
|
+
static EndOfTurn: DialogTurnResult = { status: DialogTurnStatus.waiting }
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new instance of the Dialog class.
|
|
31
|
+
*
|
|
32
|
+
* @param dialogId Optional. unique ID of the dialog.
|
|
33
|
+
*/
|
|
34
|
+
constructor (dialogId?: string) {
|
|
35
|
+
super()
|
|
36
|
+
this.id = dialogId
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Unique ID of the dialog.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* This will be automatically generated if not specified.
|
|
44
|
+
* @returns The Id for the dialog.
|
|
45
|
+
*/
|
|
46
|
+
get id (): string {
|
|
47
|
+
if (this._id === undefined) {
|
|
48
|
+
this._id = this.onComputeId()
|
|
49
|
+
}
|
|
50
|
+
return this._id
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Sets the unique ID of the dialog.
|
|
55
|
+
*/
|
|
56
|
+
set id (value: string) {
|
|
57
|
+
this._id = value
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* An encoded string used to aid in the detection of agent changes on re-deployment.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* This defaults to returning the dialogs [id](#id) but can be overridden to provide more
|
|
65
|
+
* precise change detection logic. Any dialog on the stack that has its version change will
|
|
66
|
+
* result in a `versionChanged` event will be raised. If this event is not handled by the agent,
|
|
67
|
+
* an error will be thrown resulting in the agent error handler logic being run.
|
|
68
|
+
*
|
|
69
|
+
* Returning an empty string will disable version tracking for the component all together.
|
|
70
|
+
* @returns Unique string which should only change when dialog has changed in a way that should restart the dialog.
|
|
71
|
+
*/
|
|
72
|
+
getVersion (): string {
|
|
73
|
+
return this.id
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* When overridden in a derived class, starts the dialog.
|
|
78
|
+
*
|
|
79
|
+
* @param dc The context for the current dialog turn.
|
|
80
|
+
* @param options Optional. Arguments to use when the dialog starts.
|
|
81
|
+
*
|
|
82
|
+
* @remarks
|
|
83
|
+
* Derived dialogs must override this method.
|
|
84
|
+
*
|
|
85
|
+
* The DialogContext calls this method when it creates
|
|
86
|
+
* a new DialogInstance for this dialog, pushes it
|
|
87
|
+
* onto the dialog stack, and starts the dialog.
|
|
88
|
+
*
|
|
89
|
+
* A dialog that represents a single-turn conversation should await
|
|
90
|
+
* DialogContext.endDialog before exiting this method.
|
|
91
|
+
*
|
|
92
|
+
*/
|
|
93
|
+
abstract beginDialog (dc: DialogContext, options?: O): Promise<DialogTurnResult>
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* When overridden in a derived class, continues the dialog.
|
|
97
|
+
*
|
|
98
|
+
* @param dc The context for the current dialog turn.
|
|
99
|
+
*
|
|
100
|
+
* @remarks
|
|
101
|
+
* Derived dialogs that support multiple-turn conversations should override this method.
|
|
102
|
+
* By default, this method signals that the dialog is complete and returns.
|
|
103
|
+
*
|
|
104
|
+
* The DialogContext calls this method when it continues
|
|
105
|
+
* the dialog.
|
|
106
|
+
*
|
|
107
|
+
* To signal to the dialog context that this dialog has completed, await
|
|
108
|
+
* DialogContext.endDialog before exiting this method.
|
|
109
|
+
*
|
|
110
|
+
* @returns {Promise<DialogTurnResult>} A promise resolving to the dialog turn result.
|
|
111
|
+
*/
|
|
112
|
+
async continueDialog (dc: DialogContext): Promise<DialogTurnResult> {
|
|
113
|
+
// By default just end the current dialog.
|
|
114
|
+
return dc.endDialog()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* When overridden in a derived class, resumes the dialog after the dialog above it on the stack completes.
|
|
119
|
+
*
|
|
120
|
+
* @param dc The context for the current dialog turn.
|
|
121
|
+
* @param reason The reason the dialog is resuming. This will typically be DialogReason.endCalled
|
|
122
|
+
* @param result Optional. The return value, if any, from the dialog that ended.
|
|
123
|
+
*
|
|
124
|
+
* @remarks
|
|
125
|
+
* Derived dialogs that support multiple-turn conversations should override this method.
|
|
126
|
+
* By default, this method signals that the dialog is complete and returns.
|
|
127
|
+
*
|
|
128
|
+
* The DialogContext calls this method when it resumes
|
|
129
|
+
* the dialog. If the previous dialog on the stack returned a value, that value is in the `result`
|
|
130
|
+
* parameter.
|
|
131
|
+
*
|
|
132
|
+
* To start a _child_ dialog, use DialogContext.beginDialog or DialogContext.prompt; however, this dialog will not
|
|
133
|
+
* necessarily be the one that started the child dialog.
|
|
134
|
+
* To signal to the dialog context that this dialog has completed, await DialogContext.endDialog before exiting this method.
|
|
135
|
+
*
|
|
136
|
+
* @returns {Promise<DialogTurnResult>} A promise resolving to the dialog turn result.
|
|
137
|
+
*/
|
|
138
|
+
async resumeDialog (dc: DialogContext, reason: DialogReason, result?: any): Promise<DialogTurnResult> {
|
|
139
|
+
// By default just end the current dialog and return result to parent.
|
|
140
|
+
return dc.endDialog(result)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* When overridden in a derived class, reprompts the user for input.
|
|
145
|
+
*
|
|
146
|
+
* @param _context The context object for the turn.
|
|
147
|
+
* @param _instance Current state information for this dialog.
|
|
148
|
+
*
|
|
149
|
+
* @remarks
|
|
150
|
+
* Derived dialogs that support validation and re-prompt logic should override this method.
|
|
151
|
+
* By default, this method has no effect.
|
|
152
|
+
*
|
|
153
|
+
* The DialogContext calls this method when the current
|
|
154
|
+
* dialog should re-request input from the user. This method is implemented for prompt dialogs.
|
|
155
|
+
*
|
|
156
|
+
*/
|
|
157
|
+
async repromptDialog (_context: TurnContext, _instance: DialogInstance): Promise<void> {
|
|
158
|
+
// No-op by default
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* When overridden in a derived class, performs clean up for the dialog before it ends.
|
|
163
|
+
*
|
|
164
|
+
* @param _context The context object for the turn.
|
|
165
|
+
* @param _instance Current state information for this dialog.
|
|
166
|
+
* @param _reason The reason the dialog is ending.
|
|
167
|
+
*
|
|
168
|
+
* @remarks
|
|
169
|
+
* Derived dialogs that need to perform logging or cleanup before ending should override this method.
|
|
170
|
+
* By default, this method has no effect.
|
|
171
|
+
*
|
|
172
|
+
* The DialogContext calls this method when the current
|
|
173
|
+
* dialog is ending.
|
|
174
|
+
*
|
|
175
|
+
*/
|
|
176
|
+
async endDialog (_context: TurnContext, _instance: DialogInstance, _reason: DialogReason): Promise<void> {
|
|
177
|
+
// No-op by default
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Called when an event has been raised, using `DialogContext.emitEvent()`, by either the current dialog or a dialog that the current dialog started.
|
|
182
|
+
*
|
|
183
|
+
* @param dialogContext - The dialog context for the current turn of conversation.
|
|
184
|
+
* @param event - The event being raised.
|
|
185
|
+
* @returns True if the event is handled by the current dialog and bubbling should stop.
|
|
186
|
+
*/
|
|
187
|
+
async onDialogEvent (dialogContext: DialogContext, event: DialogEvent): Promise<boolean> {
|
|
188
|
+
// Before bubble
|
|
189
|
+
let handled = await this.onPreBubbleEvent(dialogContext, event)
|
|
190
|
+
|
|
191
|
+
// Bubble as needed
|
|
192
|
+
if (!handled && event.bubble && dialogContext.parent !== undefined) {
|
|
193
|
+
handled = await dialogContext.parent.emitEvent(event.name, event.value, true, false)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Post bubble
|
|
197
|
+
if (!handled) {
|
|
198
|
+
handled = await this.onPostBubbleEvent(dialogContext, event)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return handled
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Called before an event is bubbled to its parent.
|
|
206
|
+
*
|
|
207
|
+
* @remarks
|
|
208
|
+
* This is a good place to perform interception of an event as returning `true` will prevent
|
|
209
|
+
* any further bubbling of the event to the dialogs parents and will also prevent any child
|
|
210
|
+
* dialogs from performing their default processing.
|
|
211
|
+
* @param _dc The dialog context for the current turn of conversation.
|
|
212
|
+
* @param _e The event being raised.
|
|
213
|
+
* @returns Whether the event is handled by the current dialog and further processing should stop.
|
|
214
|
+
*/
|
|
215
|
+
protected async onPreBubbleEvent (_dc: DialogContext, _e: DialogEvent): Promise<boolean> {
|
|
216
|
+
return false
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Called after an event was bubbled to all parents and wasn't handled.
|
|
221
|
+
*
|
|
222
|
+
* @remarks
|
|
223
|
+
* This is a good place to perform default processing logic for an event. Returning `true` will
|
|
224
|
+
* prevent any processing of the event by child dialogs.
|
|
225
|
+
* @param _dc The dialog context for the current turn of conversation.
|
|
226
|
+
* @param _e The event being raised.
|
|
227
|
+
* @returns Whether the event is handled by the current dialog and further processing should stop.
|
|
228
|
+
*/
|
|
229
|
+
protected async onPostBubbleEvent (_dc: DialogContext, _e: DialogEvent): Promise<boolean> {
|
|
230
|
+
return false
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Called when a unique ID needs to be computed for a dialog.
|
|
235
|
+
*
|
|
236
|
+
* @remarks
|
|
237
|
+
* SHOULD be overridden to provide a more contextually relevant ID. The preferred pattern for
|
|
238
|
+
* ID's is `<dialog type>(this.hashedLabel('<dialog args>'))`.
|
|
239
|
+
*/
|
|
240
|
+
protected onComputeId (): string {
|
|
241
|
+
throw new Error('Dialog.onComputeId(): not implemented.')
|
|
242
|
+
}
|
|
243
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { Dialog } from './dialog'
|
|
6
|
+
import { DialogSet } from './dialogSet'
|
|
7
|
+
import { DialogContext } from './dialogContext'
|
|
8
|
+
import { DialogEvents } from './dialogEvents'
|
|
9
|
+
import { DialogEvent } from './dialogEvent'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A container for a set of Dialogs.
|
|
13
|
+
*/
|
|
14
|
+
export abstract class DialogContainer<O extends object = {}> extends Dialog<O> {
|
|
15
|
+
/**
|
|
16
|
+
* The containers dialog set.
|
|
17
|
+
*/
|
|
18
|
+
readonly dialogs = new DialogSet(undefined)
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates an inner dialog context for the containers active child.
|
|
22
|
+
*
|
|
23
|
+
* @param dialogContext Parents dialog context.
|
|
24
|
+
* @returns A new dialog context for the active child or `undefined` if there is no active child.
|
|
25
|
+
*/
|
|
26
|
+
abstract createChildContext (dialogContext: DialogContext): DialogContext | undefined
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Finds a child dialog that was previously added to the container.
|
|
30
|
+
*
|
|
31
|
+
* @param dialogId ID of the dialog to lookup.
|
|
32
|
+
* @returns The Dialog if found; otherwise null.
|
|
33
|
+
*/
|
|
34
|
+
findDialog (dialogId: string): Dialog | undefined {
|
|
35
|
+
return this.dialogs.find(dialogId)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Called when an event has been raised, using `DialogContext.emitEvent()`,
|
|
40
|
+
* by either the current dialog or a dialog that the current dialog started.
|
|
41
|
+
*
|
|
42
|
+
* @param dialogContext The dialog context for the current turn of conversation.
|
|
43
|
+
* @param event The event being raised.
|
|
44
|
+
* @returns True if the event is handled by the current dialog and bubbling should stop.
|
|
45
|
+
*/
|
|
46
|
+
async onDialogEvent (dialogContext: DialogContext, event: DialogEvent): Promise<boolean> {
|
|
47
|
+
const handled = await super.onDialogEvent(dialogContext, event)
|
|
48
|
+
if (!handled && event.name === DialogEvents.versionChanged) {
|
|
49
|
+
const traceMessage = `Unhandled dialog event: ${event.name}. Active Dialog: ${dialogContext.activeDialog.id}`
|
|
50
|
+
await dialogContext.context.sendTraceActivity(traceMessage)
|
|
51
|
+
}
|
|
52
|
+
return handled
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Returns internal version identifier for this container.
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* DialogContainers detect changes of all sub-components in the container and map that to a `versionChanged` event.
|
|
60
|
+
* Because they do this, DialogContainers "hide" the internal changes and just have the .id. This isolates changes
|
|
61
|
+
* to the container level unless a container doesn't handle it. To support this DialogContainers define a
|
|
62
|
+
* protected method getInternalVersion() which computes if this dialog or child dialogs have changed
|
|
63
|
+
* which is then examined via calls to checkForVersionChange().
|
|
64
|
+
* @returns Version which represents the change of the internals of this container.
|
|
65
|
+
*/
|
|
66
|
+
protected getInternalVersion (): string {
|
|
67
|
+
return this.dialogs.getVersion()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Checks to see if a containers child dialogs have changed since the current dialog instance
|
|
72
|
+
* was started.
|
|
73
|
+
*
|
|
74
|
+
* @remarks
|
|
75
|
+
* This should be called at the start of `beginDialog()`, `continueDialog()`, and `resumeDialog()`.
|
|
76
|
+
* @param dialogContext Current dialog context.
|
|
77
|
+
*/
|
|
78
|
+
protected async checkForVersionChange (dialogContext: DialogContext): Promise<void> {
|
|
79
|
+
const current = dialogContext.activeDialog.version
|
|
80
|
+
dialogContext.activeDialog.version = this.getInternalVersion()
|
|
81
|
+
|
|
82
|
+
// Check for change of previously stored hash
|
|
83
|
+
if (current && current !== dialogContext.activeDialog.version) {
|
|
84
|
+
// Give agent an opportunity to handle the change.
|
|
85
|
+
// - If agent handles it the changeHash will have been updated as to avoid triggering the
|
|
86
|
+
// change again.
|
|
87
|
+
await dialogContext.emitEvent(DialogEvents.versionChanged, this.id, true, false)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|