@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,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findValues = findValues;
|
|
4
|
+
const tokenizer_1 = require("./tokenizer");
|
|
5
|
+
/**
|
|
6
|
+
* INTERNAL: Low-level function that searches for a set of values within an utterance. Higher level
|
|
7
|
+
* functions like `findChoices()` and `recognizeChoices()` are layered above this function. In most
|
|
8
|
+
* cases its easier to just call one of the higher level functions instead but this function contains
|
|
9
|
+
* the fuzzy search algorithm that drives choice recognition.
|
|
10
|
+
*
|
|
11
|
+
* @param utterance The text or user utterance to search over.
|
|
12
|
+
* @param values List of values to search over.
|
|
13
|
+
* @param options (Optional) options used to tweak the search that's performed.
|
|
14
|
+
* @returns A list of found values.
|
|
15
|
+
*/
|
|
16
|
+
function findValues(utterance, values, options) {
|
|
17
|
+
function indexOfToken(token, startPos) {
|
|
18
|
+
for (let i = startPos; i < tokens.length; i++) {
|
|
19
|
+
if (tokens[i].normalized === token.normalized) {
|
|
20
|
+
return i;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return -1;
|
|
24
|
+
}
|
|
25
|
+
function findExactMatch(utterance, values) {
|
|
26
|
+
const entry = values.find(({ value }) => value.toLowerCase() === utterance.toLowerCase());
|
|
27
|
+
if (!entry) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
text: utterance,
|
|
32
|
+
start: 0,
|
|
33
|
+
end: utterance.length - 1,
|
|
34
|
+
typeName: 'value',
|
|
35
|
+
resolution: {
|
|
36
|
+
value: entry.value,
|
|
37
|
+
index: entry.index,
|
|
38
|
+
score: 1,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const exactMatch = findExactMatch(utterance, values);
|
|
43
|
+
if (exactMatch) {
|
|
44
|
+
return [exactMatch];
|
|
45
|
+
}
|
|
46
|
+
function matchValue(index, value, vTokens, startPos) {
|
|
47
|
+
let matched = 0;
|
|
48
|
+
let totalDeviation = 0;
|
|
49
|
+
let start = -1;
|
|
50
|
+
let end = -1;
|
|
51
|
+
vTokens.forEach((token) => {
|
|
52
|
+
const pos = indexOfToken(token, startPos);
|
|
53
|
+
if (pos >= 0) {
|
|
54
|
+
const distance = matched > 0 ? pos - startPos : 0;
|
|
55
|
+
if (distance <= maxDistance) {
|
|
56
|
+
matched++;
|
|
57
|
+
totalDeviation += distance;
|
|
58
|
+
startPos = pos + 1;
|
|
59
|
+
if (start < 0) {
|
|
60
|
+
start = pos;
|
|
61
|
+
}
|
|
62
|
+
end = pos;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
let result;
|
|
67
|
+
if (matched > 0 && (matched === vTokens.length || opt.allowPartialMatches)) {
|
|
68
|
+
const completeness = matched / vTokens.length;
|
|
69
|
+
const accuracy = matched / (matched + totalDeviation);
|
|
70
|
+
const score = completeness * accuracy;
|
|
71
|
+
result = {
|
|
72
|
+
start,
|
|
73
|
+
end,
|
|
74
|
+
typeName: 'value',
|
|
75
|
+
resolution: {
|
|
76
|
+
value,
|
|
77
|
+
index,
|
|
78
|
+
score,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
const list = values.sort((a, b) => b.value.length - a.value.length);
|
|
85
|
+
let matches = [];
|
|
86
|
+
const opt = options || {};
|
|
87
|
+
const tokenizer = opt.tokenizer || tokenizer_1.defaultTokenizer;
|
|
88
|
+
const tokens = tokenizer(utterance, opt.locale);
|
|
89
|
+
const maxDistance = opt.maxTokenDistance !== undefined ? opt.maxTokenDistance : 2;
|
|
90
|
+
list.forEach((entry) => {
|
|
91
|
+
let startPos = 0;
|
|
92
|
+
const vTokens = tokenizer(entry.value.trim(), opt.locale);
|
|
93
|
+
while (startPos < tokens.length) {
|
|
94
|
+
const match = matchValue(entry.index, entry.value, vTokens, startPos);
|
|
95
|
+
if (match) {
|
|
96
|
+
startPos = match.end + 1;
|
|
97
|
+
matches.push(match);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
matches = matches.sort((a, b) => b.resolution.score - a.resolution.score);
|
|
105
|
+
const results = [];
|
|
106
|
+
const foundIndexes = {};
|
|
107
|
+
const usedTokens = {};
|
|
108
|
+
matches.forEach((match) => {
|
|
109
|
+
let add = !Object.prototype.hasOwnProperty.call(foundIndexes, match.resolution.index);
|
|
110
|
+
for (let i = match.start; i <= match.end; i++) {
|
|
111
|
+
if (usedTokens[i]) {
|
|
112
|
+
add = false;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (add) {
|
|
117
|
+
foundIndexes[match.resolution.index] = true;
|
|
118
|
+
for (let i = match.start; i <= match.end; i++) {
|
|
119
|
+
usedTokens[i] = true;
|
|
120
|
+
}
|
|
121
|
+
match.start = tokens[match.start].start;
|
|
122
|
+
match.end = tokens[match.end].end;
|
|
123
|
+
match.text = utterance.substring(match.start, match.end + 1);
|
|
124
|
+
results.push(match);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return results.sort((a, b) => a.start - b.start);
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=findValues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findValues.js","sourceRoot":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C,CAAA;IAEF,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAA0B,EAAE,CAA0B,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAA;AACpG,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
export * from './choice';
|
|
6
|
+
export * from './choiceFactory';
|
|
7
|
+
export * from './findChoices';
|
|
8
|
+
export * from './findValues';
|
|
9
|
+
export * from './modelResult';
|
|
10
|
+
export * from './recognizeChoices';
|
|
11
|
+
export * from './tokenizer';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/**
|
|
18
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
19
|
+
* Licensed under the MIT License.
|
|
20
|
+
*/
|
|
21
|
+
__exportStar(require("./choice"), exports);
|
|
22
|
+
__exportStar(require("./choiceFactory"), exports);
|
|
23
|
+
__exportStar(require("./findChoices"), exports);
|
|
24
|
+
__exportStar(require("./findValues"), exports);
|
|
25
|
+
__exportStar(require("./modelResult"), exports);
|
|
26
|
+
__exportStar(require("./recognizeChoices"), exports);
|
|
27
|
+
__exportStar(require("./tokenizer"), exports);
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/choices/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;GAGG;AACH,2CAAwB;AACxB,kDAA+B;AAC/B,gDAA6B;AAC7B,+CAA4B;AAC5B,gDAA6B;AAC7B,qDAAkC;AAClC,8CAA2B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
export interface ModelResult<T extends Record<string, any> = {}> {
|
|
6
|
+
text: string;
|
|
7
|
+
start: number;
|
|
8
|
+
end: number;
|
|
9
|
+
typeName: string;
|
|
10
|
+
resolution: T;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modelResult.js","sourceRoot":"","sources":["../../../src/choices/modelResult.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { FindChoicesOptions, FoundChoice } from './findChoices';
|
|
6
|
+
import { ModelResult } from './modelResult';
|
|
7
|
+
import { Choice } from './choice';
|
|
8
|
+
/**
|
|
9
|
+
* High level function for recognizing a choice in a users utterance.
|
|
10
|
+
*
|
|
11
|
+
* @param utterance The text or user utterance to search over. For an incoming 'message' activity you can simply use `context.activity.text`.
|
|
12
|
+
* @param choices List of choices to search over.
|
|
13
|
+
* @param options (Optional) options used to tweak the search that's performed.
|
|
14
|
+
* @returns A list of found choices, sorted by most relevant first.
|
|
15
|
+
*/
|
|
16
|
+
export declare function recognizeChoices(utterance: string, choices: (string | Choice)[], options?: FindChoicesOptions): ModelResult<FoundChoice>[];
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.recognizeChoices = recognizeChoices;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
6
|
+
* Licensed under the MIT License.
|
|
7
|
+
*/
|
|
8
|
+
const findChoices_1 = require("./findChoices");
|
|
9
|
+
const agents_hosting_1 = require("@microsoft/agents-hosting");
|
|
10
|
+
const logger = (0, agents_hosting_1.debug)('dialogs:recognizeChoices');
|
|
11
|
+
/**
|
|
12
|
+
* High level function for recognizing a choice in a users utterance.
|
|
13
|
+
*
|
|
14
|
+
* @param utterance The text or user utterance to search over. For an incoming 'message' activity you can simply use `context.activity.text`.
|
|
15
|
+
* @param choices List of choices to search over.
|
|
16
|
+
* @param options (Optional) options used to tweak the search that's performed.
|
|
17
|
+
* @returns A list of found choices, sorted by most relevant first.
|
|
18
|
+
*/
|
|
19
|
+
function recognizeChoices(utterance, choices, options) {
|
|
20
|
+
function matchChoiceByIndex(match) {
|
|
21
|
+
try {
|
|
22
|
+
const index = parseInt(match.resolution.value, 10) - 1;
|
|
23
|
+
if (index >= 0 && index < list.length) {
|
|
24
|
+
const choice = list[index];
|
|
25
|
+
matched.push({
|
|
26
|
+
start: match.start,
|
|
27
|
+
end: match.end,
|
|
28
|
+
typeName: 'choice',
|
|
29
|
+
text: match.text,
|
|
30
|
+
resolution: {
|
|
31
|
+
value: choice.value,
|
|
32
|
+
index,
|
|
33
|
+
score: 1,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
logger.error('Error: ', error);
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Initialize options
|
|
44
|
+
options = Object.assign({
|
|
45
|
+
locale: 'en-us',
|
|
46
|
+
recognizeNumbers: true,
|
|
47
|
+
recognizeOrdinals: true,
|
|
48
|
+
}, options);
|
|
49
|
+
// Normalize choices
|
|
50
|
+
const list = (choices || [])
|
|
51
|
+
.map((choice) => (typeof choice === 'string' ? { value: choice } : choice))
|
|
52
|
+
.filter((choice) => choice // TODO: does this do anything?
|
|
53
|
+
);
|
|
54
|
+
// Try finding choices by text search first
|
|
55
|
+
// - We only want to use a single strategy for returning results to avoid issues where utterances
|
|
56
|
+
// like the "the third one" or "the red one" or "the first division book" would miss-recognize as
|
|
57
|
+
// a numerical index or ordinal as well.
|
|
58
|
+
let matched = (0, findChoices_1.findChoices)(utterance, list, options);
|
|
59
|
+
if (matched.length === 0) {
|
|
60
|
+
// Next try finding by ordinal
|
|
61
|
+
if (options.recognizeOrdinals) {
|
|
62
|
+
// TODO: Review recognizeOrdinal function
|
|
63
|
+
// const ordinals: ModelResult[] = Recognizers.recognizeOrdinal(utterance, options.locale ?? '')
|
|
64
|
+
const ordinals = [];
|
|
65
|
+
ordinals.forEach(matchChoiceByIndex);
|
|
66
|
+
}
|
|
67
|
+
// Finally try by numerical index
|
|
68
|
+
if (matched.length === 0 && options.recognizeNumbers) {
|
|
69
|
+
// TODO: Review recognizeNumber function
|
|
70
|
+
// const numbers: ModelResult[] = Recognizers.recognizeNumber(utterance, options.locale ?? '').forEach(matchChoiceByIndex)
|
|
71
|
+
const numbers = [];
|
|
72
|
+
numbers.forEach(matchChoiceByIndex);
|
|
73
|
+
}
|
|
74
|
+
// Sort any found matches by their position within the utterance.
|
|
75
|
+
// - The results from findChoices() are already properly sorted so we just need this
|
|
76
|
+
// for ordinal & numerical lookups.
|
|
77
|
+
matched = matched.sort((a, b) => a.start - b.start);
|
|
78
|
+
}
|
|
79
|
+
return matched;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=recognizeChoices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recognizeChoices.js","sourceRoot":"","sources":["../../../src/choices/recognizeChoices.ts"],"names":[],"mappings":";;AAmBA,4CA0EC;AA7FD;;;GAGG;AACH,+CAA4E;AAG5E,8DAAiD;AAEjD,MAAM,MAAM,GAAG,IAAA,sBAAK,EAAC,0BAA0B,CAAC,CAAA;AAEhD;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAC9B,SAAiB,EACjB,OAA4B,EAC5B,OAA4B;IAE5B,SAAS,kBAAkB,CAAE,KAAuB;QAClD,IAAI,CAAC;YACH,MAAM,KAAK,GAAW,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,CAAA;YAC9D,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;gBACtC,MAAM,MAAM,GAAW,IAAI,CAAC,KAAK,CAAC,CAAA;gBAClC,OAAO,CAAC,IAAI,CAAC;oBACX,KAAK,EAAE,KAAK,CAAC,KAAK;oBAClB,GAAG,EAAE,KAAK,CAAC,GAAG;oBACd,QAAQ,EAAE,QAAQ;oBAClB,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,UAAU,EAAE;wBACV,KAAK,EAAE,MAAM,CAAC,KAAK;wBACnB,KAAK;wBACL,KAAK,EAAE,CAAC;qBACT;iBACF,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;YAC9B,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;IAED,qBAAqB;IACrB,OAAO,GAAG,MAAM,CAAC,MAAM,CACrB;QACE,MAAM,EAAE,OAAO;QACf,gBAAgB,EAAE,IAAI;QACtB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 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
export interface Token {
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
text: string;
|
|
9
|
+
normalized: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Signature for an alternate word breaker.
|
|
13
|
+
*
|
|
14
|
+
* @param TokenizerFunction.text The text to be tokenized.
|
|
15
|
+
* @param TokenizerFunction.locale (Optional) locale of the text if known.
|
|
16
|
+
*/
|
|
17
|
+
export type TokenizerFunction = (text: string, locale?: string) => Token[];
|
|
18
|
+
/**
|
|
19
|
+
* Simple tokenizer that breaks on spaces and punctuation.
|
|
20
|
+
*
|
|
21
|
+
* @param text The input text.
|
|
22
|
+
* @param _locale Optional, identifies the locale of the input text.
|
|
23
|
+
* @returns A list of tokens.
|
|
24
|
+
*/
|
|
25
|
+
export declare function defaultTokenizer(text: string, _locale?: string): Token[];
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultTokenizer = defaultTokenizer;
|
|
4
|
+
/**
|
|
5
|
+
* Simple tokenizer that breaks on spaces and punctuation.
|
|
6
|
+
*
|
|
7
|
+
* @param text The input text.
|
|
8
|
+
* @param _locale Optional, identifies the locale of the input text.
|
|
9
|
+
* @returns A list of tokens.
|
|
10
|
+
*/
|
|
11
|
+
function defaultTokenizer(text, _locale) {
|
|
12
|
+
const tokens = [];
|
|
13
|
+
let token;
|
|
14
|
+
function appendToken(end) {
|
|
15
|
+
if (token) {
|
|
16
|
+
token.end = end;
|
|
17
|
+
token.normalized = token.text.toLowerCase();
|
|
18
|
+
tokens.push(token);
|
|
19
|
+
token = undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// Parse text
|
|
23
|
+
const length = text ? text.length : 0;
|
|
24
|
+
let i = 0;
|
|
25
|
+
while (i < length) {
|
|
26
|
+
const codePoint = text.codePointAt(i) || text.charCodeAt(i);
|
|
27
|
+
const chr = String.fromCodePoint(codePoint);
|
|
28
|
+
if (isBreakingChar(codePoint)) {
|
|
29
|
+
appendToken(i - 1);
|
|
30
|
+
}
|
|
31
|
+
else if (codePoint > 0xffff) {
|
|
32
|
+
appendToken(i - 1);
|
|
33
|
+
tokens.push({
|
|
34
|
+
start: i,
|
|
35
|
+
end: i + (chr.length - 1),
|
|
36
|
+
text: chr,
|
|
37
|
+
normalized: chr,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else if (!token) {
|
|
41
|
+
token = { start: i, text: chr };
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
token.text += chr;
|
|
45
|
+
}
|
|
46
|
+
i += chr.length;
|
|
47
|
+
}
|
|
48
|
+
appendToken(length - 1);
|
|
49
|
+
return tokens;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @private
|
|
53
|
+
* @param codePoint number of character
|
|
54
|
+
*/
|
|
55
|
+
function isBreakingChar(codePoint) {
|
|
56
|
+
return (isBetween(codePoint, 0x0000, 0x002f) ||
|
|
57
|
+
isBetween(codePoint, 0x003a, 0x0040) ||
|
|
58
|
+
isBetween(codePoint, 0x005b, 0x0060) ||
|
|
59
|
+
isBetween(codePoint, 0x007b, 0x00bf) ||
|
|
60
|
+
isBetween(codePoint, 0x02b9, 0x036f) ||
|
|
61
|
+
isBetween(codePoint, 0x2000, 0x2bff) ||
|
|
62
|
+
isBetween(codePoint, 0x2e00, 0x2e7f));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @private
|
|
66
|
+
* @param value number value
|
|
67
|
+
* @param from low range
|
|
68
|
+
* @param to high range
|
|
69
|
+
*/
|
|
70
|
+
function isBetween(value, from, to) {
|
|
71
|
+
return value >= from && value <= to;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL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BACzB,IAAI,EAAE,GAAG;gBACT,UAAU,EAAE,GAAG;aAChB,CAAC,CAAA;QACJ,CAAC;aAAM,IAAI,CAAC,KAAK,EAAE,CAAC;YAClB,KAAK,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAW,CAAA;QAC1C,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,IAAI,GAAG,CAAA;QACnB,CAAC;QACD,CAAC,IAAI,GAAG,CAAC,MAAM,CAAA;IACjB,CAAC;IACD,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAEvB,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAE,SAAiB;IACxC,OAAO,CACL,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC;QAChC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC;QACpC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC;QACpC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC;QACpC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC;QACpC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC;QACpC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,CACzC,CAAA;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,SAAS,CAAE,KAAa,EAAE,IAAY,EAAE,EAAU;IACzD,OAAO,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,EAAE,CAAA;AACrC,CAAC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
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 { Dialog } from './dialog';
|
|
7
|
+
import { DialogContext } from './dialogContext';
|
|
8
|
+
import { DialogContainer } from './dialogContainer';
|
|
9
|
+
import { DialogTurnResult } from './dialogTurnResult';
|
|
10
|
+
import { DialogReason } from './dialogReason';
|
|
11
|
+
import { DialogInstance } from './dialogInstance';
|
|
12
|
+
/**
|
|
13
|
+
* Base class for a dialog that contains other child dialogs.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Component dialogs let you break your agent's logic up into components that can themselves be added
|
|
17
|
+
* as a dialog to another `ComponentDialog` or `DialogSet`. Components can also be exported as part
|
|
18
|
+
* of a node package and used within other agents.
|
|
19
|
+
*
|
|
20
|
+
* @param O (Optional) options that can be passed into the `DialogContext.beginDialog()` method.
|
|
21
|
+
*/
|
|
22
|
+
export declare class ComponentDialog<O extends object = {}> extends DialogContainer<O> {
|
|
23
|
+
/**
|
|
24
|
+
* ID of the child dialog that should be started anytime the component is started.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* This defaults to the ID of the first child dialog added using [addDialog()](#adddialog).
|
|
28
|
+
*/
|
|
29
|
+
protected initialDialogId: string;
|
|
30
|
+
/**
|
|
31
|
+
* Called when the dialog is started and pushed onto the parent's dialog stack.
|
|
32
|
+
* By default, this calls the
|
|
33
|
+
* Dialog.BeginDialogAsync(DialogContext, object, CancellationToken) method
|
|
34
|
+
* of the component dialog's initial dialog, as defined by InitialDialogId.
|
|
35
|
+
* Override this method in a derived class to implement interrupt logic.
|
|
36
|
+
*
|
|
37
|
+
* @param outerDialogContext The parent DialogContext for the current turn of conversation.
|
|
38
|
+
* @param options Optional, initial information to pass to the dialog.
|
|
39
|
+
* @returns A Promise representing the asynchronous operation.
|
|
40
|
+
* @remarks
|
|
41
|
+
* If the task is successful, the result indicates whether the dialog is still
|
|
42
|
+
* active after the turn has been processed by the dialog.
|
|
43
|
+
*/
|
|
44
|
+
beginDialog(outerDialogContext: DialogContext, options?: O): Promise<DialogTurnResult>;
|
|
45
|
+
/**
|
|
46
|
+
* Called when the dialog is _continued_, where it is the active dialog and the
|
|
47
|
+
* user replies with a new Activity.
|
|
48
|
+
* If this method is *not* overridden, the dialog automatically ends when the user replies.
|
|
49
|
+
*
|
|
50
|
+
* @param outerDialogContext The parent DialogContext for the current turn of conversation.
|
|
51
|
+
* @returns A Promise representing the asynchronous operation.
|
|
52
|
+
* @remarks
|
|
53
|
+
* If the task is successful, the result indicates whether the dialog is still
|
|
54
|
+
* active after the turn has been processed by the dialog. The result may also contain a
|
|
55
|
+
* return value.
|
|
56
|
+
*/
|
|
57
|
+
continueDialog(outerDialogContext: DialogContext): Promise<DialogTurnResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Called when a child dialog on the parent's dialog stack completed this turn, returning
|
|
60
|
+
* control to this dialog component.
|
|
61
|
+
*
|
|
62
|
+
* @param outerDialogContext The DialogContext for the current turn of conversation.
|
|
63
|
+
* @param _reason Reason why the dialog resumed.
|
|
64
|
+
* @param _result Optional, value returned from the dialog that was called. The type
|
|
65
|
+
* of the value returned is dependent on the child dialog.
|
|
66
|
+
* @returns A Promise representing the asynchronous operation.
|
|
67
|
+
* @remarks
|
|
68
|
+
* If the task is successful, the result indicates whether this dialog is still
|
|
69
|
+
* active after this dialog turn has been processed.
|
|
70
|
+
* Generally, the child dialog was started with a call to
|
|
71
|
+
* beginDialog(DialogContext, object) in the parent's
|
|
72
|
+
* context. However, if the DialogContext.replaceDialog(string, object) method
|
|
73
|
+
* is called, the logical child dialog may be different than the original.
|
|
74
|
+
* If this method is *not* overridden, the dialog automatically calls its
|
|
75
|
+
* RepromptDialog(ITurnContext, DialogInstance) when the user replies.
|
|
76
|
+
*/
|
|
77
|
+
resumeDialog(outerDialogContext: DialogContext, _reason: DialogReason, _result?: any): Promise<DialogTurnResult>;
|
|
78
|
+
/**
|
|
79
|
+
* Called when the dialog should re-prompt the user for input.
|
|
80
|
+
*
|
|
81
|
+
* @param context The TurnContext object for this turn.
|
|
82
|
+
* @param instance State information for this dialog.
|
|
83
|
+
* @returns A Promise representing the asynchronous operation.
|
|
84
|
+
*/
|
|
85
|
+
repromptDialog(context: TurnContext, instance: DialogInstance): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Called when the Dialog is ending.
|
|
88
|
+
*
|
|
89
|
+
* @param context The TurnContext object for this turn.
|
|
90
|
+
* @param instance State information associated with the instance of this component Dialog on its parent's dialog stack.
|
|
91
|
+
* @param reason Reason why the Dialog ended.
|
|
92
|
+
* @returns A Promise representing the asynchronous operation.
|
|
93
|
+
* @remarks When this method is called from the parent dialog's context, the component Dialog
|
|
94
|
+
* cancels all of the dialogs on its inner dialog stack before ending.
|
|
95
|
+
*/
|
|
96
|
+
endDialog(context: TurnContext, instance: DialogInstance, reason: DialogReason): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Adds a child Dialog or prompt to the components internal DialogSet.
|
|
99
|
+
*
|
|
100
|
+
* @param dialog The child Dialog or prompt to add.
|
|
101
|
+
* @returns The ComponentDialog after the operation is complete.
|
|
102
|
+
* @remarks
|
|
103
|
+
* The Dialog.id of the first child added to the component will be assigned to the initialDialogId property.
|
|
104
|
+
*/
|
|
105
|
+
addDialog(dialog: Dialog): this;
|
|
106
|
+
/**
|
|
107
|
+
* Creates the inner dialog context
|
|
108
|
+
*
|
|
109
|
+
* @param outerDialogContext the outer dialog context
|
|
110
|
+
* @returns The created Dialog Context.
|
|
111
|
+
*/
|
|
112
|
+
createChildContext(outerDialogContext: DialogContext): DialogContext;
|
|
113
|
+
/**
|
|
114
|
+
* Called anytime an instance of the component has been started.
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* SHOULD be overridden by components that wish to perform custom interruption logic. The
|
|
118
|
+
* default implementation calls `innerDC.beginDialog()` with the dialog assigned to
|
|
119
|
+
* initialdialogid.
|
|
120
|
+
* @param innerDialogContext Dialog context for the components internal `DialogSet`.
|
|
121
|
+
* @param options (Optional) options that were passed to the component by its parent.
|
|
122
|
+
* @returns {Promise<DialogTurnResult>} A promise resolving to the dialog turn result.
|
|
123
|
+
*/
|
|
124
|
+
protected onBeginDialog(innerDialogContext: DialogContext, options?: O): Promise<DialogTurnResult>;
|
|
125
|
+
/**
|
|
126
|
+
* Called anytime a multi-turn component receives additional activities.
|
|
127
|
+
*
|
|
128
|
+
* @remarks
|
|
129
|
+
* SHOULD be overridden by components that wish to perform custom interruption logic. The
|
|
130
|
+
* default implementation calls `innerDC.continueDialog()`.
|
|
131
|
+
* @param innerDC Dialog context for the components internal `DialogSet`.
|
|
132
|
+
* @returns {Promise<DialogTurnResult>} A promise resolving to the dialog turn result.
|
|
133
|
+
*/
|
|
134
|
+
protected onContinueDialog(innerDC: DialogContext): Promise<DialogTurnResult>;
|
|
135
|
+
/**
|
|
136
|
+
* Called when the component is ending.
|
|
137
|
+
*
|
|
138
|
+
* @remarks
|
|
139
|
+
* If the `reason` code is equal to `DialogReason.cancelCalled`, then any active child dialogs
|
|
140
|
+
* will be cancelled before this method is called.
|
|
141
|
+
* @param _context Context for the current turn of conversation.
|
|
142
|
+
* @param _instance The components instance data within its parents dialog stack.
|
|
143
|
+
* @param _reason The reason the component is ending.
|
|
144
|
+
* @returns A promise representing the asynchronous operation.
|
|
145
|
+
*/
|
|
146
|
+
protected onEndDialog(_context: TurnContext, _instance: DialogInstance, _reason: DialogReason): Promise<void>;
|
|
147
|
+
/**
|
|
148
|
+
* Called when the component has been requested to re-prompt the user for input.
|
|
149
|
+
*
|
|
150
|
+
* @remarks
|
|
151
|
+
* The active child dialog will have already been asked to reprompt before this method is called.
|
|
152
|
+
* @param _context Context for the current turn of conversation.
|
|
153
|
+
* @param _instance The instance of the current dialog.
|
|
154
|
+
* @returns A promise representing the asynchronous operation.
|
|
155
|
+
*/
|
|
156
|
+
protected onRepromptDialog(_context: TurnContext, _instance: DialogInstance): Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Called when the components last active child dialog ends and the component is ending.
|
|
159
|
+
*
|
|
160
|
+
* @remarks
|
|
161
|
+
* SHOULD be overridden by components that wish to perform custom logic before the component
|
|
162
|
+
* ends. The default implementation calls `outerDC.endDialog()` with the `result` returned
|
|
163
|
+
* from the last active child dialog.
|
|
164
|
+
* @param outerDC Dialog context for the parents `DialogSet`.
|
|
165
|
+
* @param result Result returned by the last active child dialog. Can be a value of `undefined`.
|
|
166
|
+
* @returns {Promise<DialogTurnResult>} A promise resolving to the dialog turn result.
|
|
167
|
+
*/
|
|
168
|
+
protected endComponent(outerDC: DialogContext, result: any): Promise<DialogTurnResult>;
|
|
169
|
+
/**
|
|
170
|
+
* @private
|
|
171
|
+
* @param context DialogContext for the current turn of conversation with the user.
|
|
172
|
+
* @param instance DialogInstance which contains the current state information for this dialog.
|
|
173
|
+
* @returns A new DialogContext instance.
|
|
174
|
+
* @remarks
|
|
175
|
+
* You should only call this if you don't have a dialogContext to work with (such as OnResume())
|
|
176
|
+
*/
|
|
177
|
+
private createInnerDC;
|
|
178
|
+
}
|