@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,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { DialogContext } from '../../dialogContext'
|
|
7
|
+
import { DialogTurnStateConstants } from '../../dialogTurnStateConstants'
|
|
8
|
+
import { MemoryScope } from './memoryScope'
|
|
9
|
+
import { ScopePath } from '../scopePath'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The setting node.
|
|
13
|
+
*/
|
|
14
|
+
class Node {
|
|
15
|
+
constructor (public value?: string) {}
|
|
16
|
+
children: Node[] = []
|
|
17
|
+
isLeaf (): boolean {
|
|
18
|
+
return this.children.length === 0
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class SettingsMemoryScope extends MemoryScope {
|
|
23
|
+
private static readonly blockingList = [
|
|
24
|
+
'MicrosoftAppPassword',
|
|
25
|
+
'cosmosDb:authKey',
|
|
26
|
+
'blobStorage:connectionString',
|
|
27
|
+
'BlobsStorage:connectionString',
|
|
28
|
+
'CosmosDbPartitionedStorage:authKey',
|
|
29
|
+
'applicationInsights:connectionString',
|
|
30
|
+
'applicationInsights:InstrumentationKey',
|
|
31
|
+
'runtimeSettings:telemetry:options:connectionString',
|
|
32
|
+
'runtimeSettings:telemetry:options:instrumentationKey',
|
|
33
|
+
'runtimeSettings:features:blobTranscript:connectionString',
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Initializes a new instance of the SettingsMemoryScope class.
|
|
38
|
+
*
|
|
39
|
+
* @param initialSettings initial set of settings to supply
|
|
40
|
+
*/
|
|
41
|
+
constructor (private readonly initialSettings?: Record<string, unknown>) {
|
|
42
|
+
super(ScopePath.settings, false)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Gets the backing memory for this scope.
|
|
47
|
+
*
|
|
48
|
+
* @param {DialogContext} dialogContext The DialogContext object for this turn.
|
|
49
|
+
* @returns {Record<string, ?>} The memory for the scope.
|
|
50
|
+
*/
|
|
51
|
+
getMemory (dialogContext: DialogContext): Record<string, unknown> {
|
|
52
|
+
if (dialogContext.context.turnState.has(ScopePath.settings)) {
|
|
53
|
+
return dialogContext.context.turnState.get(ScopePath.settings) ?? {}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const configuration = dialogContext.context.turnState.get(DialogTurnStateConstants.configuration) ?? {}
|
|
57
|
+
|
|
58
|
+
Object.entries(process.env).reduce((result, [key, value]) => {
|
|
59
|
+
result[`${key}`] = value
|
|
60
|
+
return result
|
|
61
|
+
}, configuration)
|
|
62
|
+
|
|
63
|
+
const settings = SettingsMemoryScope.loadSettings(configuration)
|
|
64
|
+
dialogContext.context.turnState.set(ScopePath.settings, settings)
|
|
65
|
+
|
|
66
|
+
return settings
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param dialogContext Current dialog context.
|
|
71
|
+
*/
|
|
72
|
+
async load (dialogContext: DialogContext): Promise<void> {
|
|
73
|
+
if (this.initialSettings) {
|
|
74
|
+
// filter initialSettings
|
|
75
|
+
const filteredSettings = SettingsMemoryScope.filterSettings(this.initialSettings)
|
|
76
|
+
dialogContext.context.turnState.set(ScopePath.settings, filteredSettings)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
await super.load(dialogContext)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Build a dictionary view of configuration providers.
|
|
84
|
+
*
|
|
85
|
+
* @param {Record<string, string>} configuration The configuration that we are running with.
|
|
86
|
+
* @returns {Record<string, ?>} Projected dictionary for settings.
|
|
87
|
+
*/
|
|
88
|
+
protected static loadSettings (configuration: Record<string, string>): Record<string, unknown> {
|
|
89
|
+
let settings = {}
|
|
90
|
+
|
|
91
|
+
if (configuration) {
|
|
92
|
+
// load configuration into settings
|
|
93
|
+
const root = this.convertFlattenSettingToNode(Object.entries(configuration))
|
|
94
|
+
settings = root.children.reduce(
|
|
95
|
+
(acc, child) => ({ ...acc, [child.value ?? '']: this.convertNodeToObject(child) }),
|
|
96
|
+
settings
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// filter env configuration settings
|
|
101
|
+
return this.filterSettings(settings)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Generate a node tree with the flatten settings.
|
|
106
|
+
* For example:
|
|
107
|
+
* {
|
|
108
|
+
* "array":["item1", "item2"],
|
|
109
|
+
* "object":{"array":["item1"], "2":"numberkey"}
|
|
110
|
+
* }
|
|
111
|
+
*
|
|
112
|
+
* Would generate a flatten settings like:
|
|
113
|
+
* array:0 item1
|
|
114
|
+
* array:1 item2
|
|
115
|
+
* object:array:0 item1
|
|
116
|
+
* object:2 numberkey
|
|
117
|
+
*
|
|
118
|
+
* After Converting it from flatten settings into node tree, would get:
|
|
119
|
+
*
|
|
120
|
+
* null
|
|
121
|
+
* | |
|
|
122
|
+
* array object
|
|
123
|
+
* | | | |
|
|
124
|
+
* 0 1 array 2
|
|
125
|
+
* | | | |
|
|
126
|
+
* item1 item2 0 numberkey
|
|
127
|
+
* |
|
|
128
|
+
* item1
|
|
129
|
+
* The result is a Tree.
|
|
130
|
+
*
|
|
131
|
+
* @param {Array<[string, string]>} kvs Configurations with key value pairs.
|
|
132
|
+
* @returns {Node} The root node of the tree.
|
|
133
|
+
*/
|
|
134
|
+
private static convertFlattenSettingToNode (kvs: Array<[key: string, value: string]>): Node {
|
|
135
|
+
const root = new Node()
|
|
136
|
+
|
|
137
|
+
kvs.forEach(([key, value]) => {
|
|
138
|
+
const keyChain = key.split(':')
|
|
139
|
+
let currentNode = root
|
|
140
|
+
keyChain.forEach((item) => {
|
|
141
|
+
const matchItem = currentNode.children.find((u) => u?.value === item)
|
|
142
|
+
if (!matchItem) {
|
|
143
|
+
// Remove all the leaf children
|
|
144
|
+
currentNode.children = currentNode.children.filter((u) => u.children.length !== 0)
|
|
145
|
+
|
|
146
|
+
// Append new child into current node
|
|
147
|
+
const node = new Node(item)
|
|
148
|
+
currentNode.children.push(node)
|
|
149
|
+
currentNode = node
|
|
150
|
+
} else {
|
|
151
|
+
currentNode = matchItem
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
currentNode.children.push(new Node(value))
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
return root
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private static convertNodeToObject (node: Node): unknown {
|
|
162
|
+
if (!node.children.length) {
|
|
163
|
+
return {}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// If the child is leaf node, return its value directly.
|
|
167
|
+
if (node.children.length === 1 && node.children[0].isLeaf()) {
|
|
168
|
+
return node.children[0].value
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// check if all the children are number format.
|
|
172
|
+
let pureNumberIndex = true
|
|
173
|
+
const indexArray: number[] = []
|
|
174
|
+
let indexMax = -1
|
|
175
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
176
|
+
const child = node.children[Number(i)]
|
|
177
|
+
if (child.value && /^-?\d+$/.test(child.value)) {
|
|
178
|
+
const num = parseInt(child.value, 10)
|
|
179
|
+
if (!isNaN(num) && num >= 0) {
|
|
180
|
+
indexArray.push(num)
|
|
181
|
+
if (num > indexMax) {
|
|
182
|
+
indexMax = num
|
|
183
|
+
}
|
|
184
|
+
continue
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
pureNumberIndex = false
|
|
188
|
+
break
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (pureNumberIndex) {
|
|
192
|
+
// all children are int numbers, treat it as array.
|
|
193
|
+
const listResult = new Array(indexMax + 1)
|
|
194
|
+
node.children.forEach((child, index) => {
|
|
195
|
+
listResult[indexArray[Number(index)]] = this.convertNodeToObject(child)
|
|
196
|
+
})
|
|
197
|
+
return listResult
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Convert all child into dictionary
|
|
201
|
+
return node.children.reduce((result: Record<string, any>, child: Node) => {
|
|
202
|
+
if (child.value) {
|
|
203
|
+
result[child.value] = this.convertNodeToObject(child)
|
|
204
|
+
}
|
|
205
|
+
return result
|
|
206
|
+
}, {})
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private static filterSettings (settings: Record<string, unknown>): Record<string, unknown> {
|
|
210
|
+
const result = Object.assign({}, settings)
|
|
211
|
+
this.blockingList.forEach((path) => this.deletePropertyPath(result, path))
|
|
212
|
+
return result
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private static deletePropertyPath (obj: Record<string, any>, path: string): void {
|
|
216
|
+
if (!obj || !path?.length) {
|
|
217
|
+
return
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const pathArray = path.split(':')
|
|
221
|
+
|
|
222
|
+
for (let i = 0; i < pathArray.length - 1; i++) {
|
|
223
|
+
const realKey = Object.keys(obj).find((key) => key.toLowerCase() === pathArray[i].toLowerCase())
|
|
224
|
+
if (realKey) {
|
|
225
|
+
obj = obj[realKey]
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!obj) {
|
|
229
|
+
return
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const lastPath = pathArray.pop()?.toLowerCase()
|
|
234
|
+
const lastKey = Object.keys(obj).find((key) => key.toLowerCase() === lastPath)
|
|
235
|
+
if (lastKey) {
|
|
236
|
+
delete obj[lastKey]
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { MemoryScope } from './memoryScope'
|
|
6
|
+
import { ScopePath } from '../scopePath'
|
|
7
|
+
import { DialogContext } from '../../dialogContext'
|
|
8
|
+
|
|
9
|
+
export class ThisMemoryScope extends MemoryScope {
|
|
10
|
+
/**
|
|
11
|
+
* Initializes a new instance of the ThisMemoryScope class.
|
|
12
|
+
*/
|
|
13
|
+
constructor () {
|
|
14
|
+
super(ScopePath.this)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Gets the backing memory for this scope.
|
|
19
|
+
*
|
|
20
|
+
* @param dialogContext The DialogContext object for this turn.
|
|
21
|
+
* @returns The memory for the scope.
|
|
22
|
+
*/
|
|
23
|
+
getMemory (dialogContext: DialogContext): object {
|
|
24
|
+
return dialogContext.activeDialog ? dialogContext.activeDialog.state : {}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Changes the backing object for the memory scope.
|
|
29
|
+
*
|
|
30
|
+
* @param dialogContext The DialogContext object for this turn.
|
|
31
|
+
* @param memory Memory object to set for the scope.
|
|
32
|
+
*/
|
|
33
|
+
setMemory (dialogContext: DialogContext, memory: object): void {
|
|
34
|
+
if (memory === undefined) {
|
|
35
|
+
throw new Error('ThisMemoryScope.setMemory: undefined memory object passed in.')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!dialogContext.activeDialog) {
|
|
39
|
+
throw new Error('ThisMemoryScope.setMemory: no active dialog found.')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
dialogContext.activeDialog.state = memory
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { MemoryScope } from './memoryScope'
|
|
6
|
+
import { ScopePath } from '../scopePath'
|
|
7
|
+
import { DialogContext } from '../../dialogContext'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
const TURN_STATE = 'turn'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* TurnMemoryScope represents memory scoped to the current turn.
|
|
16
|
+
*/
|
|
17
|
+
export class TurnMemoryScope extends MemoryScope {
|
|
18
|
+
/**
|
|
19
|
+
* Initializes a new instance of the TurnMemoryScope class.
|
|
20
|
+
*/
|
|
21
|
+
constructor () {
|
|
22
|
+
super(ScopePath.turn, true)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get the backing memory for this scope.
|
|
27
|
+
*
|
|
28
|
+
* @param dialogContext The DialogContext for this turn.
|
|
29
|
+
* @returns The memory for the scope.
|
|
30
|
+
*/
|
|
31
|
+
getMemory (dialogContext: DialogContext): object {
|
|
32
|
+
let memory = dialogContext.context.turnState.get(TURN_STATE)
|
|
33
|
+
if (typeof memory !== 'object') {
|
|
34
|
+
memory = {}
|
|
35
|
+
dialogContext.context.turnState.set(TURN_STATE, memory)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return memory
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Changes the backing object for the memory scope.
|
|
43
|
+
*
|
|
44
|
+
* @param dialogContext The DialogContext for this turn.
|
|
45
|
+
* @param memory Memory object to set for the scope.
|
|
46
|
+
*/
|
|
47
|
+
setMemory (dialogContext: DialogContext, memory: object): void {
|
|
48
|
+
if (memory === undefined) {
|
|
49
|
+
throw new Error('TurnMemoryScope.setMemory: undefined memory object passed in.')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
dialogContext.context.turnState.set(TURN_STATE, memory)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { AgentStateMemoryScope } from './agentStateMemoryScope'
|
|
6
|
+
import { ScopePath } from '../scopePath'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Memory that's scoped to the current user.
|
|
10
|
+
*/
|
|
11
|
+
export class UserMemoryScope extends AgentStateMemoryScope {
|
|
12
|
+
protected stateKey = 'UserState'
|
|
13
|
+
/**
|
|
14
|
+
* Initializes a new instance of the UserMemoryScope class.
|
|
15
|
+
*/
|
|
16
|
+
constructor () {
|
|
17
|
+
super(ScopePath.user)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Defines path for avaiable turns.
|
|
8
|
+
*/
|
|
9
|
+
export class TurnPath {
|
|
10
|
+
/// The result from the last dialog that was called.
|
|
11
|
+
static readonly lastResult = 'turn.lastresult'
|
|
12
|
+
|
|
13
|
+
/// The current activity for the turn.
|
|
14
|
+
static readonly activity = 'turn.activity'
|
|
15
|
+
|
|
16
|
+
/// The recognized result for the current turn.
|
|
17
|
+
static readonly recognized = 'turn.recognized'
|
|
18
|
+
|
|
19
|
+
/// Path to the top intent.
|
|
20
|
+
static readonly topIntent = 'turn.recognized.intent'
|
|
21
|
+
|
|
22
|
+
/// Path to the top score.
|
|
23
|
+
static readonly topScore = 'turn.recognized.score'
|
|
24
|
+
|
|
25
|
+
/// Original text.
|
|
26
|
+
static readonly text = 'turn.recognized.text'
|
|
27
|
+
|
|
28
|
+
/// Original utterance split into unrecognized strings.
|
|
29
|
+
static readonly unrecognizedText = 'turn.unrecognizedText'
|
|
30
|
+
|
|
31
|
+
/// Entities that were recognized from text.
|
|
32
|
+
static readonly recognizedEntities = 'turn.recognizedEntities'
|
|
33
|
+
|
|
34
|
+
/// If true an interruption has occured.
|
|
35
|
+
static readonly interrupted = 'turn.interrupted'
|
|
36
|
+
|
|
37
|
+
/// The current dialog event (set during event processings).
|
|
38
|
+
static readonly dialogEvent = 'turn.dialogEvent'
|
|
39
|
+
|
|
40
|
+
/// Used to track that we don't end up in infinite loop of RepeatDialogs().
|
|
41
|
+
static readonly repeatedIds = 'turn.repeatedIds'
|
|
42
|
+
|
|
43
|
+
/// This is a bool which if set means that the turncontext.activity has been consumed by some component in the system.
|
|
44
|
+
static readonly activityProcessed = 'turn.activityProcessed'
|
|
45
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { Activity, InputHints, TurnContext, ActivityTypes } from '@microsoft/agents-hosting'
|
|
6
|
+
import { Dialog } from '../dialog'
|
|
7
|
+
import { DialogContext } from '../dialogContext'
|
|
8
|
+
import { PromptOptions, PromptRecognizerResult, PromptValidator } from './prompt'
|
|
9
|
+
import { DialogInstance } from '../dialogInstance'
|
|
10
|
+
import { DialogReason } from '../dialogReason'
|
|
11
|
+
import { DialogTurnResult } from '../dialogTurnResult'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Waits for an activity to be received.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* This prompt requires a validator be passed in and is useful when waiting for non-message
|
|
18
|
+
* activities like an event to be received. The validator can ignore received events until the
|
|
19
|
+
* expected activity is received.
|
|
20
|
+
*/
|
|
21
|
+
export class ActivityPrompt extends Dialog {
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new ActivityPrompt instance.
|
|
24
|
+
*
|
|
25
|
+
* @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
|
|
26
|
+
* @param validator Validator that will be called each time a new activity is received.
|
|
27
|
+
*/
|
|
28
|
+
constructor (
|
|
29
|
+
dialogId: string,
|
|
30
|
+
private validator: PromptValidator<Activity>
|
|
31
|
+
) {
|
|
32
|
+
super(dialogId)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Called when a prompt dialog is pushed onto the dialog stack and is being activated.
|
|
37
|
+
*
|
|
38
|
+
* @param dialogContext The DialogContext for the current
|
|
39
|
+
* turn of the conversation.
|
|
40
|
+
* @param options PromptOptions, additional
|
|
41
|
+
* information to pass to the prompt being started.
|
|
42
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
43
|
+
* @remarks
|
|
44
|
+
* If the promise is successful, the result indicates whether the prompt is still
|
|
45
|
+
* active after the turn has been processed by the prompt.
|
|
46
|
+
*/
|
|
47
|
+
async beginDialog (dialogContext: DialogContext, options: PromptOptions): Promise<DialogTurnResult> {
|
|
48
|
+
// Ensure prompts have input hint set
|
|
49
|
+
const opt: Partial<PromptOptions> = { ...options }
|
|
50
|
+
if (opt.prompt && typeof opt.prompt === 'object' && typeof opt.prompt.inputHint !== 'string') {
|
|
51
|
+
opt.prompt.inputHint = InputHints.ExpectingInput
|
|
52
|
+
}
|
|
53
|
+
if (opt.retryPrompt && typeof opt.retryPrompt === 'object' && typeof opt.retryPrompt.inputHint !== 'string') {
|
|
54
|
+
opt.retryPrompt.inputHint = InputHints.ExpectingInput
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Initialize prompt state
|
|
58
|
+
const state: any = dialogContext.activeDialog.state as ActivityPromptState
|
|
59
|
+
state.options = opt
|
|
60
|
+
state.state = {}
|
|
61
|
+
|
|
62
|
+
// Send initial prompt
|
|
63
|
+
await this.onPrompt(dialogContext.context, state.state, state.options, false)
|
|
64
|
+
|
|
65
|
+
return Dialog.EndOfTurn
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Called when a prompt dialog is the active dialog and the user replied with a new activity.
|
|
70
|
+
*
|
|
71
|
+
* @param dialogContext The DialogContext for the current
|
|
72
|
+
* turn of conversation.
|
|
73
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
74
|
+
* @remarks
|
|
75
|
+
* If the promise is successful, the result indicates whether the dialog is still
|
|
76
|
+
* active after the turn has been processed by the dialog.
|
|
77
|
+
* The prompt generally continues to receive the user's replies until it accepts the
|
|
78
|
+
* user's reply as valid input for the prompt.
|
|
79
|
+
*/
|
|
80
|
+
async continueDialog (dialogContext: DialogContext): Promise<DialogTurnResult> {
|
|
81
|
+
// Perform base recognition
|
|
82
|
+
const state: any = dialogContext.activeDialog.state as ActivityPromptState
|
|
83
|
+
const recognized: PromptRecognizerResult<Activity> = await this.onRecognize(
|
|
84
|
+
dialogContext.context,
|
|
85
|
+
state.state,
|
|
86
|
+
state.options
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
if (state.state['attemptCount'] === undefined) {
|
|
90
|
+
state.state['attemptCount'] = 0
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Validate the return value
|
|
94
|
+
// - Unlike the other prompts a validator is required for an ActivityPrompt so we don't
|
|
95
|
+
// need to check for its existence before calling it.
|
|
96
|
+
const isValid: boolean = await this.validator({
|
|
97
|
+
context: dialogContext.context,
|
|
98
|
+
recognized,
|
|
99
|
+
state: state.state,
|
|
100
|
+
options: state.options,
|
|
101
|
+
attemptCount: ++state.state['attemptCount'],
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
// Return recognized value or re-prompt
|
|
105
|
+
if (isValid) {
|
|
106
|
+
return await dialogContext.endDialog(recognized.value)
|
|
107
|
+
} else {
|
|
108
|
+
if (dialogContext.context.activity.type === ActivityTypes.Message && !dialogContext.context.responded) {
|
|
109
|
+
await this.onPrompt(dialogContext.context, state.state, state.options, true)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return Dialog.EndOfTurn
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Called when a prompt dialog resumes being the active dialog on the dialog stack, such as
|
|
118
|
+
* when the previous active dialog on the stack completes.
|
|
119
|
+
*
|
|
120
|
+
* @param dialogContext The DialogContext for the current turn
|
|
121
|
+
* of the conversation.
|
|
122
|
+
* @param _reason DialogReason, an enum indicating why
|
|
123
|
+
* the dialog resumed.
|
|
124
|
+
* @param _result Optional. Value returned from the previous dialog on the stack.
|
|
125
|
+
* The type of the value returned is dependent on the previous dialog.
|
|
126
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
127
|
+
*/
|
|
128
|
+
async resumeDialog (dialogContext: DialogContext, _reason: DialogReason, _result?: any): Promise<DialogTurnResult> {
|
|
129
|
+
// Prompts are typically leaf nodes on the stack but the dev is free to push other dialogs
|
|
130
|
+
// on top of the stack which will result in the prompt receiving an unexpected call to
|
|
131
|
+
// resumeDialog() when the pushed on dialog ends.
|
|
132
|
+
// To avoid the prompt prematurely ending we need to implement this method and
|
|
133
|
+
// simply re-prompt the user.
|
|
134
|
+
await this.repromptDialog(dialogContext.context, dialogContext.activeDialog)
|
|
135
|
+
|
|
136
|
+
return Dialog.EndOfTurn
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Called when a prompt dialog has been requested to re-prompt the user for input.
|
|
141
|
+
*
|
|
142
|
+
* @param context TurnContext, context for the current
|
|
143
|
+
* turn of conversation with the user.
|
|
144
|
+
* @param instance DialogInstance, the instance
|
|
145
|
+
* of the dialog on the stack.
|
|
146
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
147
|
+
*/
|
|
148
|
+
async repromptDialog (context: TurnContext, instance: DialogInstance): Promise<void> {
|
|
149
|
+
const state: ActivityPromptState = instance.state as ActivityPromptState
|
|
150
|
+
await this.onPrompt(context, state.state, state.options, false)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* When overridden in a derived class, prompts the user for input.
|
|
155
|
+
*
|
|
156
|
+
* @param context TurnContext, context for the current
|
|
157
|
+
* turn of conversation with the user.
|
|
158
|
+
* @param state Contains state for the current instance of the prompt on the dialog stack.
|
|
159
|
+
* @param options A PromptOptions object constructed
|
|
160
|
+
* from the options initially provided in the call to Prompt.
|
|
161
|
+
* @param isRetry A boolean representing if the prompt is a retry.
|
|
162
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
163
|
+
*/
|
|
164
|
+
protected async onPrompt (
|
|
165
|
+
context: TurnContext,
|
|
166
|
+
state: object,
|
|
167
|
+
options: PromptOptions,
|
|
168
|
+
isRetry: boolean
|
|
169
|
+
): Promise<void> {
|
|
170
|
+
if (isRetry && options.retryPrompt) {
|
|
171
|
+
await context.sendActivity(options.retryPrompt, undefined, InputHints.ExpectingInput)
|
|
172
|
+
} else if (options.prompt) {
|
|
173
|
+
await context.sendActivity(options.prompt, undefined, InputHints.ExpectingInput)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* When overridden in a derived class, attempts to recognize the incoming Activity.
|
|
179
|
+
*
|
|
180
|
+
* @param context TurnContext, context for the current
|
|
181
|
+
* turn of conversation with the user.
|
|
182
|
+
* @param _state Contains state for the current instance of the prompt on the dialog stack.
|
|
183
|
+
* @param _options A PromptOptions object constructed
|
|
184
|
+
* from the options initially provided in the call to Prompt.
|
|
185
|
+
* @returns A `Promise` representing the asynchronous operation.
|
|
186
|
+
*/
|
|
187
|
+
protected async onRecognize (
|
|
188
|
+
context: TurnContext,
|
|
189
|
+
_state: object,
|
|
190
|
+
_options: PromptOptions
|
|
191
|
+
): Promise<PromptRecognizerResult<Activity>> {
|
|
192
|
+
return { succeeded: true, value: context.activity }
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @private
|
|
198
|
+
*/
|
|
199
|
+
interface ActivityPromptState {
|
|
200
|
+
state: object;
|
|
201
|
+
options: PromptOptions;
|
|
202
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { Attachment, InputHints, TurnContext } from '@microsoft/agents-hosting'
|
|
6
|
+
import { Prompt, PromptOptions, PromptRecognizerResult, PromptValidator } from './prompt'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Prompts a user to upload attachments like images.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* By default the prompt will return to the calling dialog an `Attachment[]`.
|
|
13
|
+
*/
|
|
14
|
+
export class AttachmentPrompt extends Prompt<Attachment[]> {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
16
|
+
constructor (dialogId: string, validator?: PromptValidator<Attachment[]>) {
|
|
17
|
+
super(dialogId, validator)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Prompts the user for input.
|
|
22
|
+
*
|
|
23
|
+
* @param context Context for the current turn of conversation with the user.
|
|
24
|
+
* @param state Contains state for the current instance of the prompt on the dialog stack.
|
|
25
|
+
* @param options A prompt options object constructed from the options initially provided
|
|
26
|
+
* in the call to Prompt.
|
|
27
|
+
* @param isRetry `true` if this is the first time this prompt dialog instance
|
|
28
|
+
* on the stack is prompting the user for input; otherwise, false.
|
|
29
|
+
* @returns A Promise representing the asynchronous operation.
|
|
30
|
+
*/
|
|
31
|
+
protected async onPrompt (
|
|
32
|
+
context: TurnContext,
|
|
33
|
+
state: any,
|
|
34
|
+
options: PromptOptions,
|
|
35
|
+
isRetry: boolean
|
|
36
|
+
): Promise<void> {
|
|
37
|
+
if (isRetry && options.retryPrompt) {
|
|
38
|
+
await context.sendActivity(options.retryPrompt, undefined, InputHints.ExpectingInput)
|
|
39
|
+
} else if (options.prompt) {
|
|
40
|
+
await context.sendActivity(options.prompt, undefined, InputHints.ExpectingInput)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Attempts to recognize the user's input.
|
|
46
|
+
*
|
|
47
|
+
* @param context Context for the current turn of conversation with the user.
|
|
48
|
+
* @param _state Contains state for the current instance of the prompt on the dialog stack.
|
|
49
|
+
* @param _options A prompt options object constructed from the options initially provided
|
|
50
|
+
* in the call to Prompt.
|
|
51
|
+
* @returns A Promise representing the asynchronous operation.
|
|
52
|
+
*/
|
|
53
|
+
protected async onRecognize (
|
|
54
|
+
context: TurnContext,
|
|
55
|
+
_state: any,
|
|
56
|
+
_options: PromptOptions
|
|
57
|
+
): Promise<PromptRecognizerResult<Attachment[]>> {
|
|
58
|
+
const value: Attachment[] = context.activity.attachments
|
|
59
|
+
|
|
60
|
+
return Array.isArray(value) && value.length > 0 ? { succeeded: true, value } : { succeeded: false }
|
|
61
|
+
}
|
|
62
|
+
}
|