@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,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
Activity,
|
|
8
|
+
ActivityTypes,
|
|
9
|
+
AgentStatePropertyAccessor,
|
|
10
|
+
TurnContext
|
|
11
|
+
} from '@microsoft/agents-hosting'
|
|
12
|
+
import { Dialog } from './dialog'
|
|
13
|
+
import { DialogContext, DialogState } from './dialogContext'
|
|
14
|
+
import { DialogEvents } from './dialogEvents'
|
|
15
|
+
import { DialogSet } from './dialogSet'
|
|
16
|
+
import { DialogStateManager, DialogStateManagerConfiguration } from './memory'
|
|
17
|
+
import { DialogTurnResult } from './dialogTurnResult'
|
|
18
|
+
import { DialogTurnStatus } from './dialogTurnStatus'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Runs a dialog from a given context and accessor.
|
|
22
|
+
*
|
|
23
|
+
* @param dialog The Dialog to run.
|
|
24
|
+
* @param context TurnContext object for the current turn of conversation with the user.
|
|
25
|
+
* @param accessor Defined methods for accessing the state property created in a State object.
|
|
26
|
+
*/
|
|
27
|
+
export async function runDialog (
|
|
28
|
+
dialog: Dialog,
|
|
29
|
+
context: TurnContext,
|
|
30
|
+
accessor: AgentStatePropertyAccessor<DialogState>
|
|
31
|
+
): Promise<void> {
|
|
32
|
+
if (!dialog) {
|
|
33
|
+
throw new Error('runDialog(): missing dialog')
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!context) {
|
|
37
|
+
throw new Error('runDialog(): missing context')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!context.activity) {
|
|
41
|
+
throw new Error('runDialog(): missing context.activity')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!accessor) {
|
|
45
|
+
throw new Error('runDialog(): missing accessor')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const dialogSet = new DialogSet(accessor)
|
|
49
|
+
dialogSet.add(dialog)
|
|
50
|
+
|
|
51
|
+
const dialogContext = await dialogSet.createContext(context)
|
|
52
|
+
|
|
53
|
+
await internalRun(context, dialog.id, dialogContext)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param context The TurnContext for the turn.
|
|
58
|
+
* @param dialogId The dialog ID.
|
|
59
|
+
* @param dialogContext The DialogContext for the current turn of conversation.
|
|
60
|
+
* @param dialogStateManagerConfiguration Configuration for the dialog state manager.
|
|
61
|
+
* @returns {Promise<DialogTurnResult>} a promise resolving to the dialog turn result.
|
|
62
|
+
*/
|
|
63
|
+
export async function internalRun (
|
|
64
|
+
context: TurnContext,
|
|
65
|
+
dialogId: string,
|
|
66
|
+
dialogContext: DialogContext,
|
|
67
|
+
dialogStateManagerConfiguration?: DialogStateManagerConfiguration
|
|
68
|
+
): Promise<DialogTurnResult> {
|
|
69
|
+
// map TurnState into root dialog context.services
|
|
70
|
+
context.turnState.forEach((service, key) => {
|
|
71
|
+
dialogContext.services.push(key, service)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const dialogStateManager = new DialogStateManager(dialogContext, dialogStateManagerConfiguration)
|
|
75
|
+
|
|
76
|
+
await dialogStateManager.loadAllScopes()
|
|
77
|
+
dialogContext.context.turnState.push('DialogStateManager', dialogStateManager)
|
|
78
|
+
let dialogTurnResult: DialogTurnResult = null
|
|
79
|
+
|
|
80
|
+
// Loop as long as we are getting valid OnError handled we should continue executing the actions for the turn.
|
|
81
|
+
// NOTE: We loop around this block because each pass through we either complete the turn and break out of the loop
|
|
82
|
+
// or we have had an exception AND there was an OnError action which captured the error. We need to continue the
|
|
83
|
+
// turn based on the actions the OnError handler introduced.
|
|
84
|
+
let endOfTurn = false
|
|
85
|
+
while (!endOfTurn) {
|
|
86
|
+
try {
|
|
87
|
+
dialogTurnResult = await innerRun(context, dialogId, dialogContext)
|
|
88
|
+
|
|
89
|
+
// turn successfully completed, break the loop
|
|
90
|
+
endOfTurn = true
|
|
91
|
+
} catch (err) {
|
|
92
|
+
// fire error event, bubbling from the leaf.
|
|
93
|
+
const handled = await dialogContext.emitEvent(DialogEvents.error, err, true, true)
|
|
94
|
+
|
|
95
|
+
if (!handled) {
|
|
96
|
+
// error was NOT handled, throw the exception and end the turn.
|
|
97
|
+
// (This will trigger the Adapter.OnError handler and end the entire dialog stack)
|
|
98
|
+
throw err
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// save all state scopes to their respective agentState locations.
|
|
104
|
+
await dialogStateManager.saveAllChanges()
|
|
105
|
+
|
|
106
|
+
// return the redundant result because the DialogManager contract expects it
|
|
107
|
+
return dialogTurnResult
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function innerRun (
|
|
111
|
+
context: TurnContext,
|
|
112
|
+
dialogId: string,
|
|
113
|
+
dialogContext: DialogContext
|
|
114
|
+
): Promise<DialogTurnResult> {
|
|
115
|
+
// Continue or start the dialog.
|
|
116
|
+
let result = await dialogContext.continueDialog()
|
|
117
|
+
if (result.status === DialogTurnStatus.empty) {
|
|
118
|
+
result = await dialogContext.beginDialog(dialogId)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
await sendStateSnapshotTrace(dialogContext)
|
|
122
|
+
|
|
123
|
+
return result
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Recursively walk up the dialog context stack to find the active DC.
|
|
128
|
+
*
|
|
129
|
+
* @param dialogContext DialogContext for the current turn of conversation with the user.
|
|
130
|
+
* @returns Active DialogContext.
|
|
131
|
+
*/
|
|
132
|
+
export function getActiveDialogContext (dialogContext: DialogContext): DialogContext {
|
|
133
|
+
const child = dialogContext.child
|
|
134
|
+
if (!child) {
|
|
135
|
+
return dialogContext
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return getActiveDialogContext(child)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Helper to send a trace activity with a memory snapshot of the active dialog DC.
|
|
142
|
+
const sendStateSnapshotTrace = async (dialogContext: DialogContext): Promise<void> => {
|
|
143
|
+
const traceLabel = 'Agent State'
|
|
144
|
+
|
|
145
|
+
// Send trace of memory
|
|
146
|
+
const snapshot = getActiveDialogContext(dialogContext).state.getMemorySnapshot()
|
|
147
|
+
const traceActivity = new Activity(ActivityTypes.Trace)
|
|
148
|
+
traceActivity.name = 'AgentState'
|
|
149
|
+
traceActivity.label = 'https://www.botframework.com/schemas/botState'
|
|
150
|
+
traceActivity.value = snapshot
|
|
151
|
+
traceActivity.label = traceLabel
|
|
152
|
+
|
|
153
|
+
await dialogContext.context.sendActivity(traceActivity)
|
|
154
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains state information for an instance of a dialog on the stack.
|
|
3
|
+
*
|
|
4
|
+
* @template T Optional. The type that represents state information for the dialog.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* This contains information for a specific instance of a dialog on a dialog stack.
|
|
8
|
+
* The dialog stack is associated with a specific dialog context and dialog set.
|
|
9
|
+
* Information about the dialog stack as a whole is persisted to storage using a dialog state object.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export interface DialogInstance<T = any> {
|
|
13
|
+
/**
|
|
14
|
+
* ID of this dialog
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Dialog state is associated with a specific dialog set.
|
|
18
|
+
* This ID is the the dialog's Dialog.id within that dialog set.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
id: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The state information for this instance of this dialog.
|
|
25
|
+
*/
|
|
26
|
+
state: T;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Hash code used to detect that a dialog has changed since the curent instance was started.
|
|
30
|
+
*/
|
|
31
|
+
version?: string;
|
|
32
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
TurnContext,
|
|
8
|
+
AgentState,
|
|
9
|
+
ConversationState,
|
|
10
|
+
UserState,
|
|
11
|
+
TurnContextStateCollection,
|
|
12
|
+
} from '@microsoft/agents-hosting'
|
|
13
|
+
import { AgentStateSet } from './agentStateSet'
|
|
14
|
+
import { Configurable } from './configurable'
|
|
15
|
+
import { DialogContainer } from './dialogContainer'
|
|
16
|
+
import { DialogContext, DialogState } from './dialogContext'
|
|
17
|
+
import { internalRun } from './dialogHelper'
|
|
18
|
+
import { DialogSet } from './dialogSet'
|
|
19
|
+
import { DialogTurnStateConstants } from './dialogTurnStateConstants'
|
|
20
|
+
import { Dialog } from './dialog'
|
|
21
|
+
import { DialogStateManagerConfiguration } from './memory'
|
|
22
|
+
import { DialogTurnResult } from './dialogTurnResult'
|
|
23
|
+
|
|
24
|
+
const LAST_ACCESS = '_lastAccess'
|
|
25
|
+
const CONVERSATION_STATE = 'ConversationState'
|
|
26
|
+
const USER_STATE = 'UserState'
|
|
27
|
+
|
|
28
|
+
export interface DialogManagerResult {
|
|
29
|
+
turnResult: DialogTurnResult;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface DialogManagerConfiguration {
|
|
33
|
+
conversationState: AgentState;
|
|
34
|
+
rootDialog: Dialog;
|
|
35
|
+
userState?: UserState;
|
|
36
|
+
expireAfter?: number;
|
|
37
|
+
stateConfiguration?: DialogStateManagerConfiguration;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Class which runs the dialog system.
|
|
42
|
+
*
|
|
43
|
+
* @deprecated This class will be deprecated.
|
|
44
|
+
*/
|
|
45
|
+
export class DialogManager extends Configurable {
|
|
46
|
+
private _rootDialogId: string
|
|
47
|
+
private readonly _dialogStateProperty: string
|
|
48
|
+
private readonly _initialTurnState: TurnContextStateCollection = new TurnContextStateCollection()
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Creates an instance of the DialogManager class.
|
|
52
|
+
*
|
|
53
|
+
* @param rootDialog Optional, root Dialog to use.
|
|
54
|
+
* @param dialogStateProperty Optional, alternate name for the dialogState property. (Default is "DialogStateProperty")
|
|
55
|
+
*/
|
|
56
|
+
constructor (rootDialog?: Dialog, dialogStateProperty?: string) {
|
|
57
|
+
super()
|
|
58
|
+
if (rootDialog) {
|
|
59
|
+
this.rootDialog = rootDialog
|
|
60
|
+
}
|
|
61
|
+
this._dialogStateProperty = dialogStateProperty ?? 'DialogState'
|
|
62
|
+
this._initialTurnState.set(DialogTurnStateConstants.dialogManager, this)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
conversationState: ConversationState
|
|
66
|
+
userState?: UserState
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Values that will be copied to the `TurnContext.turnState` at the beginning of each turn.
|
|
70
|
+
*
|
|
71
|
+
* @returns The turn state collection.
|
|
72
|
+
*/
|
|
73
|
+
get initialTurnState (): TurnContextStateCollection {
|
|
74
|
+
return this._initialTurnState
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Root dialog to start from [onTurn()](#onturn) method.
|
|
79
|
+
*/
|
|
80
|
+
set rootDialog (value: Dialog) {
|
|
81
|
+
this.dialogs = new DialogSet()
|
|
82
|
+
if (value) {
|
|
83
|
+
this._rootDialogId = value.id
|
|
84
|
+
this.dialogs.add(value)
|
|
85
|
+
this.registerContainerDialogs(this.rootDialog, false)
|
|
86
|
+
} else {
|
|
87
|
+
this._rootDialogId = undefined
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Gets the root Dialog ID.
|
|
93
|
+
*
|
|
94
|
+
* @returns The root Dialog ID.
|
|
95
|
+
*/
|
|
96
|
+
get rootDialog (): Dialog {
|
|
97
|
+
return this._rootDialogId ? this.dialogs.find(this._rootDialogId) : undefined
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
dialogs: DialogSet = new DialogSet()
|
|
101
|
+
stateConfiguration?: DialogStateManagerConfiguration
|
|
102
|
+
expireAfter?: number
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Set configuration settings.
|
|
106
|
+
*
|
|
107
|
+
* @param config Configuration settings to apply.
|
|
108
|
+
* @returns The cofigured DialogManager context.
|
|
109
|
+
*/
|
|
110
|
+
configure (config: Partial<DialogManagerConfiguration>): this {
|
|
111
|
+
return super.configure(config)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Runs dialog system in the context of a TurnContext.
|
|
116
|
+
*
|
|
117
|
+
* @param context TurnContext for the current turn of conversation with the user.
|
|
118
|
+
* @returns Result of running the logic against the activity.
|
|
119
|
+
*/
|
|
120
|
+
async onTurn (context: TurnContext): Promise<DialogManagerResult> {
|
|
121
|
+
// Ensure properly configured
|
|
122
|
+
if (!this._rootDialogId) {
|
|
123
|
+
throw new Error("DialogManager.onTurn: the agent's 'rootDialog' has not been configured.")
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Copy initial turn state to context
|
|
127
|
+
this.initialTurnState.forEach((value, key): void => {
|
|
128
|
+
context.turnState.set(key, value)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
const agentStateSet = new AgentStateSet()
|
|
132
|
+
|
|
133
|
+
if (!this.conversationState) {
|
|
134
|
+
this.conversationState = context.turnState.get(CONVERSATION_STATE)
|
|
135
|
+
} else {
|
|
136
|
+
context.turnState.set(CONVERSATION_STATE, this.conversationState)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!this.conversationState) {
|
|
140
|
+
throw new Error("DialogManager.onTurn: the agent's 'conversationState' has not been configured.")
|
|
141
|
+
}
|
|
142
|
+
agentStateSet.add(this.conversationState)
|
|
143
|
+
|
|
144
|
+
if (!this.userState) {
|
|
145
|
+
this.userState = context.turnState.get(USER_STATE)
|
|
146
|
+
} else {
|
|
147
|
+
context.turnState.set(USER_STATE, this.userState)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (this.userState) {
|
|
151
|
+
agentStateSet.add(this.userState)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Get last access
|
|
155
|
+
const lastAccessProperty = this.conversationState.createProperty(LAST_ACCESS)
|
|
156
|
+
const lastAccess = new Date(await lastAccessProperty.get(context, new Date().toISOString()))
|
|
157
|
+
|
|
158
|
+
// Check for expired conversation
|
|
159
|
+
const now = new Date()
|
|
160
|
+
if (this.expireAfter !== undefined && now.getTime() - lastAccess.getTime() >= this.expireAfter) {
|
|
161
|
+
// Clear conversation state
|
|
162
|
+
await this.conversationState.clear(context)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Update last access time
|
|
166
|
+
await lastAccessProperty.set(context, lastAccess.toISOString())
|
|
167
|
+
|
|
168
|
+
// get dialog stack
|
|
169
|
+
const dialogsProperty = this.conversationState.createProperty(this._dialogStateProperty)
|
|
170
|
+
const dialogState: DialogState = await dialogsProperty.get(context, {})
|
|
171
|
+
|
|
172
|
+
// Create DialogContext
|
|
173
|
+
const dc = new DialogContext(this.dialogs, context, dialogState)
|
|
174
|
+
|
|
175
|
+
// Call the common dialog "continue/begin" execution pattern shared with the classic RunAsync extension method
|
|
176
|
+
const turnResult = await internalRun(context, this._rootDialogId, dc, this.stateConfiguration)
|
|
177
|
+
|
|
178
|
+
// Save agentState changes
|
|
179
|
+
await agentStateSet.saveAllChanges(dc.context, false)
|
|
180
|
+
|
|
181
|
+
return { turnResult }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Recursively traverses the dialog tree and registers intances of `DialogContainer` in the `DialogSet`
|
|
185
|
+
// for this `DialogManager` instance.
|
|
186
|
+
private registerContainerDialogs (dialog: Dialog, registerRoot = true): void {
|
|
187
|
+
if (!(dialog instanceof DialogContainer)) {
|
|
188
|
+
return
|
|
189
|
+
}
|
|
190
|
+
const container = dialog
|
|
191
|
+
if (registerRoot) {
|
|
192
|
+
if (this.dialogs.getDialogs().find((dlg) => dlg === container)) {
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
this.dialogs.add(container)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
container.dialogs.getDialogs().forEach((inner) => {
|
|
199
|
+
this.registerContainerDialogs(inner)
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Indicates why a dialog method is being called.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Use a dialog context to control the dialogs in a dialog set. The dialog context will pass a reference to itself
|
|
6
|
+
* to the dialog method it calls. It also passes in the _reason_ why the specific method is being called.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
export enum DialogReason {
|
|
10
|
+
/**
|
|
11
|
+
* The dialog is being started from DialogContext.beginDialog or DialogContext.replaceDialog.
|
|
12
|
+
*/
|
|
13
|
+
beginCalled = 'beginCalled',
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The dialog is being continued from DialogContext.continueDialog.
|
|
17
|
+
*/
|
|
18
|
+
continueCalled = 'continueCalled',
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The dialog is being ended from DialogContext.endDialog.
|
|
22
|
+
*/
|
|
23
|
+
endCalled = 'endCalled',
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The dialog is being ended from DialogContext.replaceDialog.
|
|
27
|
+
*/
|
|
28
|
+
replaceCalled = 'replaceCalled',
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The dialog is being cancelled from DialogContext.cancelAllDialogs.
|
|
32
|
+
*/
|
|
33
|
+
cancelCalled = 'cancelCalled',
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A step in a WaterfallDialog is being called
|
|
37
|
+
* because the previous step in the waterfall dialog called WaterfallStepContext.next.
|
|
38
|
+
*/
|
|
39
|
+
nextCalled = 'nextCalled',
|
|
40
|
+
}
|
package/src/dialogSet.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import {
|
|
6
|
+
AgentStatePropertyAccessor,
|
|
7
|
+
TurnContext
|
|
8
|
+
} from '@microsoft/agents-hosting'
|
|
9
|
+
|
|
10
|
+
import { Dialog } from './dialog'
|
|
11
|
+
import { DialogContext, DialogState } from './dialogContext'
|
|
12
|
+
import { StringUtils } from './stringUtils'
|
|
13
|
+
|
|
14
|
+
export interface DialogDependencies {
|
|
15
|
+
/**
|
|
16
|
+
* Returns a dialogs child dialog dependencies so they can be added to a containers dialog set.
|
|
17
|
+
*/
|
|
18
|
+
getDependencies(): Dialog[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A related set of dialogs that can all call each other.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* The constructor for the dialog set should be passed a state property that will be used to
|
|
26
|
+
* persist the dialog stack for the set:
|
|
27
|
+
*
|
|
28
|
+
* To interact with the sets dialogs you can call createcontext with the
|
|
29
|
+
* current `TurnContext`. That will create a `DialogContext` that can be used to start or continue
|
|
30
|
+
* execution of the sets dialogs:
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
export class DialogSet {
|
|
34
|
+
private readonly dialogs: { [id: string]: Dialog } = {}
|
|
35
|
+
private readonly dialogState: AgentStatePropertyAccessor<DialogState>
|
|
36
|
+
private _version: string
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new DialogSet instance.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* If the `dialogState` property is not passed in, calls to createcontext
|
|
43
|
+
* will return an error. You will need to create a `DialogContext` for the set manually and
|
|
44
|
+
* pass in your own state object for persisting the sets dialog stack:
|
|
45
|
+
*
|
|
46
|
+
* @param dialogState (Optional) state property used to persist the sets dialog stack.
|
|
47
|
+
*/
|
|
48
|
+
constructor (dialogState?: AgentStatePropertyAccessor<DialogState>) {
|
|
49
|
+
this.dialogState = dialogState
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Returns a 32-bit hash of the all the `Dialog.version` values in the set.
|
|
54
|
+
*
|
|
55
|
+
* @returns A version that will change when any of the child dialogs version changes.
|
|
56
|
+
* @remarks
|
|
57
|
+
* This hash is persisted to state storage and used to detect changes to a dialog set.
|
|
58
|
+
*/
|
|
59
|
+
getVersion (): string {
|
|
60
|
+
if (!this._version) {
|
|
61
|
+
let versions = ''
|
|
62
|
+
for (const id in this.dialogs) {
|
|
63
|
+
const v = this.dialogs[id].getVersion()
|
|
64
|
+
if (v) {
|
|
65
|
+
versions += `|${v}`
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
this._version = StringUtils.hash(versions)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return this._version
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Adds a new dialog or prompt to the set.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* If the `Dialog.id` being added already exists in the set, the dialogs id will be updated to
|
|
79
|
+
* include a suffix which makes it unique. So adding 2 dialogs named "duplicate" to the set
|
|
80
|
+
* would result in the first one having an id of "duplicate" and the second one having an id
|
|
81
|
+
* of "duplicate2".
|
|
82
|
+
* @param dialog The dialog or prompt to add.
|
|
83
|
+
* If a telemetryClient is present on the dialog set, it will be added to each dialog.
|
|
84
|
+
* @returns The dialog set after the operation is complete.
|
|
85
|
+
*/
|
|
86
|
+
add<T extends Dialog>(dialog: T): this {
|
|
87
|
+
if (!(dialog instanceof Dialog)) {
|
|
88
|
+
throw new Error('DialogSet.add(): Invalid dialog being added.')
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Ensure new version hash is computed
|
|
92
|
+
this._version = undefined
|
|
93
|
+
|
|
94
|
+
// Ensure dialogs ID is unique.
|
|
95
|
+
if (Object.prototype.hasOwnProperty.call(this.dialogs, dialog.id)) {
|
|
96
|
+
// If we are trying to add the same exact instance, it's not a name collision.
|
|
97
|
+
// No operation required since the instance is already in the dialog set.
|
|
98
|
+
if (this.dialogs[dialog.id] === dialog) {
|
|
99
|
+
return this
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// If we are adding a new dialog with a conflicting name, add a suffix to avoid
|
|
103
|
+
// dialog name collisions.
|
|
104
|
+
let nextSuffix = 2
|
|
105
|
+
|
|
106
|
+
while (true) {
|
|
107
|
+
const suffixId = dialog.id + nextSuffix.toString()
|
|
108
|
+
if (!Object.prototype.hasOwnProperty.call(this.dialogs, suffixId)) {
|
|
109
|
+
dialog.id = suffixId
|
|
110
|
+
break
|
|
111
|
+
} else {
|
|
112
|
+
nextSuffix++
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Save dialog reference
|
|
118
|
+
this.dialogs[dialog.id] = dialog
|
|
119
|
+
|
|
120
|
+
// Automatically add any child dependencies the dialog might have
|
|
121
|
+
if (typeof (dialog as any as DialogDependencies).getDependencies === 'function') {
|
|
122
|
+
(dialog as any as DialogDependencies).getDependencies().forEach((child: Dialog): void => {
|
|
123
|
+
this.add(child)
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return this
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Creates a dialog context which can be used to work with the dialogs in the set.
|
|
132
|
+
*
|
|
133
|
+
* @param context Context for the current turn of conversation with the user.
|
|
134
|
+
* @returns A promise representing the asynchronous operation.
|
|
135
|
+
*/
|
|
136
|
+
async createContext (context: TurnContext): Promise<DialogContext> {
|
|
137
|
+
if (!this.dialogState) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
'DialogSet.createContext(): the dialog set was not bound to a stateProperty when constructed.'
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
const state: DialogState = await this.dialogState.get(context, { dialogStack: [] } as DialogState)
|
|
143
|
+
|
|
144
|
+
return new DialogContext(this, context, state)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Finds a dialog that was previously added to the set using add.
|
|
149
|
+
*
|
|
150
|
+
* @remarks
|
|
151
|
+
* This example finds a dialog named "greeting":
|
|
152
|
+
*
|
|
153
|
+
* @param dialogId ID of the dialog or prompt to lookup.
|
|
154
|
+
* @returns The dialog if found; otherwise undefined.
|
|
155
|
+
*/
|
|
156
|
+
find (dialogId: string): Dialog | undefined {
|
|
157
|
+
return Object.prototype.hasOwnProperty.call(this.dialogs, dialogId) ? this.dialogs[dialogId] : undefined
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Gets the Dialogs of the set.
|
|
162
|
+
*
|
|
163
|
+
* @returns {Dialog} An array of Dialog.
|
|
164
|
+
*/
|
|
165
|
+
getDialogs (): Dialog[] {
|
|
166
|
+
return Object.values(this.dialogs)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { DialogTurnStatus } from './dialogTurnStatus'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents the result of a dialog context's attempt to begin, continue,
|
|
5
|
+
* or otherwise manipulate one or more dialogs.
|
|
6
|
+
*
|
|
7
|
+
* @template T Optional. The type that represents a result returned by the active dialog when it
|
|
8
|
+
* successfully completes.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* This can be used to determine if a dialog completed and a result is available, or if the stack
|
|
12
|
+
* was initially empty and a dialog should be started.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export interface DialogTurnResult<T = any> {
|
|
16
|
+
/**
|
|
17
|
+
* The state of the dialog stack after a dialog context's attempt.
|
|
18
|
+
*/
|
|
19
|
+
status: DialogTurnStatus;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The result, if any, returned by the last dialog on the stack.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* A result value is available only if
|
|
26
|
+
* the stack is now empty,
|
|
27
|
+
* the last dialog on the stack completed normally,
|
|
28
|
+
* and the last dialog returned a result to the dialog context.
|
|
29
|
+
*/
|
|
30
|
+
result?: T;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* If true, a `DialogCommand` has ended its parent container and the parent should not perform
|
|
34
|
+
* any further processing.
|
|
35
|
+
*/
|
|
36
|
+
parentEnded?: boolean;
|
|
37
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Defines dialog turn state constants.
|
|
8
|
+
*/
|
|
9
|
+
export class DialogTurnStateConstants {
|
|
10
|
+
static configuration = Symbol('configuration')
|
|
11
|
+
static dialogManager = Symbol('dialogManager')
|
|
12
|
+
static queueStorage = Symbol('queueStorage')
|
|
13
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the state of the dialog stack after a dialog context attempts to begin, continue,
|
|
3
|
+
* or otherwise manipulate one or more dialogs.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export enum DialogTurnStatus {
|
|
7
|
+
/**
|
|
8
|
+
* The dialog stack is empty.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Indicates that the dialog stack was initially empty when the operation was attempted.
|
|
12
|
+
*/
|
|
13
|
+
empty = 'empty',
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The active dialog on top of the stack is waiting for a response from the user.
|
|
17
|
+
*/
|
|
18
|
+
waiting = 'waiting',
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The last dialog on the stack completed successfully.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Indicates that a result might be available and the stack is now empty.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
complete = 'complete',
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* All dialogs on the stack were cancelled and the stack is empty.
|
|
31
|
+
*/
|
|
32
|
+
cancelled = 'cancelled',
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Current dialog completed successfully, but turn should end.
|
|
36
|
+
*/
|
|
37
|
+
completeAndWait = 'completeAndWait',
|
|
38
|
+
}
|