@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.
Files changed (325) hide show
  1. package/dist/index.js +20 -0
  2. package/dist/src/agentComponent.d.ts +18 -0
  3. package/dist/src/agentComponent.js +55 -0
  4. package/dist/src/agentComponent.js.map +1 -0
  5. package/dist/src/agentStateSet.d.ts +48 -0
  6. package/dist/src/agentStateSet.js +66 -0
  7. package/dist/src/agentStateSet.js.map +1 -0
  8. package/dist/src/choices/choice.d.ts +14 -0
  9. package/dist/src/choices/choice.js +7 -0
  10. package/dist/src/choices/choice.js.map +1 -0
  11. package/dist/src/choices/choiceFactory.d.ts +81 -0
  12. package/dist/src/choices/choiceFactory.js +133 -0
  13. package/dist/src/choices/choiceFactory.js.map +1 -0
  14. package/dist/src/choices/findChoices.d.ts +28 -0
  15. package/dist/src/choices/findChoices.js +46 -0
  16. package/dist/src/choices/findChoices.js.map +1 -0
  17. package/dist/src/choices/findValues.d.ts +36 -0
  18. package/dist/src/choices/findValues.js +129 -0
  19. package/dist/src/choices/findValues.js.map +1 -0
  20. package/dist/src/choices/index.d.ts +11 -0
  21. package/dist/src/choices/index.js +28 -0
  22. package/dist/src/choices/index.js.map +1 -0
  23. package/dist/src/choices/modelResult.d.ts +11 -0
  24. package/dist/src/choices/modelResult.js +3 -0
  25. package/dist/src/choices/modelResult.js.map +1 -0
  26. package/dist/src/choices/recognizeChoices.d.ts +16 -0
  27. package/dist/src/choices/recognizeChoices.js +81 -0
  28. package/dist/src/choices/recognizeChoices.js.map +1 -0
  29. package/dist/src/choices/tokenizer.d.ts +25 -0
  30. package/dist/src/choices/tokenizer.js +73 -0
  31. package/dist/src/choices/tokenizer.js.map +1 -0
  32. package/dist/src/componentDialog.d.ts +178 -0
  33. package/dist/src/componentDialog.js +252 -0
  34. package/dist/src/componentDialog.js.map +1 -0
  35. package/dist/src/componentRegistration.d.ts +22 -0
  36. package/dist/src/componentRegistration.js +32 -0
  37. package/dist/src/componentRegistration.js.map +1 -0
  38. package/dist/src/configurable.d.ts +22 -0
  39. package/dist/src/configurable.js +60 -0
  40. package/dist/src/configurable.js.map +1 -0
  41. package/dist/src/configuration.d.ts +11 -0
  42. package/dist/src/configuration.js +17 -0
  43. package/dist/src/configuration.js.map +1 -0
  44. package/dist/src/converter.d.ts +13 -0
  45. package/dist/src/converter.js +7 -0
  46. package/dist/src/converter.js.map +1 -0
  47. package/dist/src/dialog.d.ts +184 -0
  48. package/dist/src/dialog.js +201 -0
  49. package/dist/src/dialog.js.map +1 -0
  50. package/dist/src/dialogContainer.d.ts +61 -0
  51. package/dist/src/dialogContainer.js +82 -0
  52. package/dist/src/dialogContainer.js.map +1 -0
  53. package/dist/src/dialogContext.d.ts +272 -0
  54. package/dist/src/dialogContext.js +444 -0
  55. package/dist/src/dialogContext.js.map +1 -0
  56. package/dist/src/dialogContextError.d.ts +27 -0
  57. package/dist/src/dialogContextError.js +39 -0
  58. package/dist/src/dialogContextError.js.map +1 -0
  59. package/dist/src/dialogEvent.d.ts +20 -0
  60. package/dist/src/dialogEvent.js +3 -0
  61. package/dist/src/dialogEvent.js.map +1 -0
  62. package/dist/src/dialogEvents.d.ts +15 -0
  63. package/dist/src/dialogEvents.js +20 -0
  64. package/dist/src/dialogEvents.js.map +1 -0
  65. package/dist/src/dialogHelper.d.ts +32 -0
  66. package/dist/src/dialogHelper.js +116 -0
  67. package/dist/src/dialogHelper.js.map +1 -0
  68. package/dist/src/dialogInstance.d.ts +30 -0
  69. package/dist/src/dialogInstance.js +3 -0
  70. package/dist/src/dialogInstance.js.map +1 -0
  71. package/dist/src/dialogManager.d.ts +73 -0
  72. package/dist/src/dialogManager.js +156 -0
  73. package/dist/src/dialogManager.js.map +1 -0
  74. package/dist/src/dialogReason.d.ts +35 -0
  75. package/dist/src/dialogReason.js +40 -0
  76. package/dist/src/dialogReason.js.map +1 -0
  77. package/dist/src/dialogSet.d.ts +85 -0
  78. package/dist/src/dialogSet.js +138 -0
  79. package/dist/src/dialogSet.js.map +1 -0
  80. package/dist/src/dialogTurnResult.d.ts +34 -0
  81. package/dist/src/dialogTurnResult.js +3 -0
  82. package/dist/src/dialogTurnResult.js.map +1 -0
  83. package/dist/src/dialogTurnStateConstants.d.ts +12 -0
  84. package/dist/src/dialogTurnStateConstants.js +17 -0
  85. package/dist/src/dialogTurnStateConstants.js.map +1 -0
  86. package/dist/src/dialogTurnStatus.d.ts +34 -0
  87. package/dist/src/dialogTurnStatus.js +39 -0
  88. package/dist/src/dialogTurnStatus.js.map +1 -0
  89. package/dist/src/dialogsAgentComponent.d.ts +17 -0
  90. package/dist/src/dialogsAgentComponent.js +65 -0
  91. package/dist/src/dialogsAgentComponent.js.map +1 -0
  92. package/dist/src/dialogsComponentRegistration.d.ts +28 -0
  93. package/dist/src/dialogsComponentRegistration.js +45 -0
  94. package/dist/src/dialogsComponentRegistration.js.map +1 -0
  95. package/dist/src/i18n.d.ts +15 -0
  96. package/dist/src/i18n.js +28 -0
  97. package/dist/src/i18n.js.map +1 -0
  98. package/dist/src/index.d.ts +29 -0
  99. package/dist/src/index.js +48 -0
  100. package/dist/src/index.js.map +1 -0
  101. package/dist/src/intentScore.d.ts +11 -0
  102. package/dist/src/intentScore.js +3 -0
  103. package/dist/src/intentScore.js.map +1 -0
  104. package/dist/src/memory/componentMemoryScopes.d.ts +18 -0
  105. package/dist/src/memory/componentMemoryScopes.js +54 -0
  106. package/dist/src/memory/componentMemoryScopes.js.map +1 -0
  107. package/dist/src/memory/componentPathResolvers.d.ts +18 -0
  108. package/dist/src/memory/componentPathResolvers.js +52 -0
  109. package/dist/src/memory/componentPathResolvers.js.map +1 -0
  110. package/dist/src/memory/dialogPath.d.ts +17 -0
  111. package/dist/src/memory/dialogPath.js +30 -0
  112. package/dist/src/memory/dialogPath.js.map +1 -0
  113. package/dist/src/memory/dialogStateManager.d.ts +156 -0
  114. package/dist/src/memory/dialogStateManager.js +598 -0
  115. package/dist/src/memory/dialogStateManager.js.map +1 -0
  116. package/dist/src/memory/index.d.ts +12 -0
  117. package/dist/src/memory/index.js +29 -0
  118. package/dist/src/memory/index.js.map +1 -0
  119. package/dist/src/memory/pathResolvers/aliasPathResolver.d.ts +25 -0
  120. package/dist/src/memory/pathResolvers/aliasPathResolver.js +37 -0
  121. package/dist/src/memory/pathResolvers/aliasPathResolver.js.map +1 -0
  122. package/dist/src/memory/pathResolvers/atAtPathResolver.d.ts +11 -0
  123. package/dist/src/memory/pathResolvers/atAtPathResolver.js +18 -0
  124. package/dist/src/memory/pathResolvers/atAtPathResolver.js.map +1 -0
  125. package/dist/src/memory/pathResolvers/atPathResolver.d.ts +20 -0
  126. package/dist/src/memory/pathResolvers/atPathResolver.js +46 -0
  127. package/dist/src/memory/pathResolvers/atPathResolver.js.map +1 -0
  128. package/dist/src/memory/pathResolvers/dollarPathResolver.d.ts +11 -0
  129. package/dist/src/memory/pathResolvers/dollarPathResolver.js +18 -0
  130. package/dist/src/memory/pathResolvers/dollarPathResolver.js.map +1 -0
  131. package/dist/src/memory/pathResolvers/hashPathResolver.d.ts +11 -0
  132. package/dist/src/memory/pathResolvers/hashPathResolver.js +18 -0
  133. package/dist/src/memory/pathResolvers/hashPathResolver.js.map +1 -0
  134. package/dist/src/memory/pathResolvers/index.d.ts +11 -0
  135. package/dist/src/memory/pathResolvers/index.js +28 -0
  136. package/dist/src/memory/pathResolvers/index.js.map +1 -0
  137. package/dist/src/memory/pathResolvers/pathResolver.d.ts +13 -0
  138. package/dist/src/memory/pathResolvers/pathResolver.js +7 -0
  139. package/dist/src/memory/pathResolvers/pathResolver.js.map +1 -0
  140. package/dist/src/memory/pathResolvers/percentPathResolver.d.ts +11 -0
  141. package/dist/src/memory/pathResolvers/percentPathResolver.js +18 -0
  142. package/dist/src/memory/pathResolvers/percentPathResolver.js.map +1 -0
  143. package/dist/src/memory/scopePath.d.ts +18 -0
  144. package/dist/src/memory/scopePath.js +23 -0
  145. package/dist/src/memory/scopePath.js.map +1 -0
  146. package/dist/src/memory/scopes/agentStateMemoryScope.d.ts +53 -0
  147. package/dist/src/memory/scopes/agentStateMemoryScope.js +82 -0
  148. package/dist/src/memory/scopes/agentStateMemoryScope.js.map +1 -0
  149. package/dist/src/memory/scopes/classMemoryScope.d.ts +29 -0
  150. package/dist/src/memory/scopes/classMemoryScope.js +65 -0
  151. package/dist/src/memory/scopes/classMemoryScope.js.map +1 -0
  152. package/dist/src/memory/scopes/conversationMemoryScope.d.ts +15 -0
  153. package/dist/src/memory/scopes/conversationMemoryScope.js +23 -0
  154. package/dist/src/memory/scopes/conversationMemoryScope.js.map +1 -0
  155. package/dist/src/memory/scopes/dialogClassMemoryScope.d.ts +19 -0
  156. package/dist/src/memory/scopes/dialogClassMemoryScope.js +42 -0
  157. package/dist/src/memory/scopes/dialogClassMemoryScope.js.map +1 -0
  158. package/dist/src/memory/scopes/dialogContextMemoryScope.d.ts +19 -0
  159. package/dist/src/memory/scopes/dialogContextMemoryScope.js +48 -0
  160. package/dist/src/memory/scopes/dialogContextMemoryScope.js.map +1 -0
  161. package/dist/src/memory/scopes/dialogMemoryScope.d.ts +32 -0
  162. package/dist/src/memory/scopes/dialogMemoryScope.js +74 -0
  163. package/dist/src/memory/scopes/dialogMemoryScope.js.map +1 -0
  164. package/dist/src/memory/scopes/index.d.ts +15 -0
  165. package/dist/src/memory/scopes/index.js +32 -0
  166. package/dist/src/memory/scopes/index.js.map +1 -0
  167. package/dist/src/memory/scopes/memoryScope.d.ts +52 -0
  168. package/dist/src/memory/scopes/memoryScope.js +54 -0
  169. package/dist/src/memory/scopes/memoryScope.js.map +1 -0
  170. package/dist/src/memory/scopes/settingsMemoryScope.d.ts +68 -0
  171. package/dist/src/memory/scopes/settingsMemoryScope.js +216 -0
  172. package/dist/src/memory/scopes/settingsMemoryScope.js.map +1 -0
  173. package/dist/src/memory/scopes/thisMemoryScope.d.ts +26 -0
  174. package/dist/src/memory/scopes/thisMemoryScope.js +43 -0
  175. package/dist/src/memory/scopes/thisMemoryScope.js.map +1 -0
  176. package/dist/src/memory/scopes/turnMemoryScope.d.ts +29 -0
  177. package/dist/src/memory/scopes/turnMemoryScope.js +52 -0
  178. package/dist/src/memory/scopes/turnMemoryScope.js.map +1 -0
  179. package/dist/src/memory/scopes/userMemoryScope.d.ts +15 -0
  180. package/dist/src/memory/scopes/userMemoryScope.js +23 -0
  181. package/dist/src/memory/scopes/userMemoryScope.js.map +1 -0
  182. package/dist/src/memory/turnPath.d.ts +21 -0
  183. package/dist/src/memory/turnPath.js +38 -0
  184. package/dist/src/memory/turnPath.js.map +1 -0
  185. package/dist/src/prompts/activityPrompt.d.ts +101 -0
  186. package/dist/src/prompts/activityPrompt.js +166 -0
  187. package/dist/src/prompts/activityPrompt.js.map +1 -0
  188. package/dist/src/prompts/attachmentPrompt.d.ts +37 -0
  189. package/dist/src/prompts/attachmentPrompt.js +55 -0
  190. package/dist/src/prompts/attachmentPrompt.js.map +1 -0
  191. package/dist/src/prompts/choicePrompt.d.ts +83 -0
  192. package/dist/src/prompts/choicePrompt.js +116 -0
  193. package/dist/src/prompts/choicePrompt.js.map +1 -0
  194. package/dist/src/prompts/confirmPrompt.d.ts +82 -0
  195. package/dist/src/prompts/confirmPrompt.js +163 -0
  196. package/dist/src/prompts/confirmPrompt.js.map +1 -0
  197. package/dist/src/prompts/datetimePrompt.d.ts +65 -0
  198. package/dist/src/prompts/datetimePrompt.js +109 -0
  199. package/dist/src/prompts/datetimePrompt.js.map +1 -0
  200. package/dist/src/prompts/index.d.ts +13 -0
  201. package/dist/src/prompts/index.js +30 -0
  202. package/dist/src/prompts/index.js.map +1 -0
  203. package/dist/src/prompts/numberPrompt.d.ts +55 -0
  204. package/dist/src/prompts/numberPrompt.js +134 -0
  205. package/dist/src/prompts/numberPrompt.js.map +1 -0
  206. package/dist/src/prompts/prompt.d.ts +256 -0
  207. package/dist/src/prompts/prompt.js +260 -0
  208. package/dist/src/prompts/prompt.js.map +1 -0
  209. package/dist/src/prompts/promptCultureModels.d.ts +72 -0
  210. package/dist/src/prompts/promptCultureModels.js +123 -0
  211. package/dist/src/prompts/promptCultureModels.js.map +1 -0
  212. package/dist/src/prompts/textPrompt.d.ts +54 -0
  213. package/dist/src/prompts/textPrompt.js +72 -0
  214. package/dist/src/prompts/textPrompt.js.map +1 -0
  215. package/dist/src/recognizer.d.ts +43 -0
  216. package/dist/src/recognizer.js +104 -0
  217. package/dist/src/recognizer.js.map +1 -0
  218. package/dist/src/recognizerResult.d.ts +19 -0
  219. package/dist/src/recognizerResult.js +24 -0
  220. package/dist/src/recognizerResult.js.map +1 -0
  221. package/dist/src/serviceCollection.d.ts +112 -0
  222. package/dist/src/serviceCollection.js +209 -0
  223. package/dist/src/serviceCollection.js.map +1 -0
  224. package/dist/src/stringUtils.d.ts +36 -0
  225. package/dist/src/stringUtils.js +62 -0
  226. package/dist/src/stringUtils.js.map +1 -0
  227. package/dist/src/template.d.ts +18 -0
  228. package/dist/src/template.js +7 -0
  229. package/dist/src/template.js.map +1 -0
  230. package/dist/src/waterfallDialog.d.ts +101 -0
  231. package/dist/src/waterfallDialog.js +179 -0
  232. package/dist/src/waterfallDialog.js.map +1 -0
  233. package/dist/src/waterfallStepContext.d.ts +71 -0
  234. package/dist/src/waterfallStepContext.js +78 -0
  235. package/dist/src/waterfallStepContext.js.map +1 -0
  236. package/package.json +49 -0
  237. package/src/agentComponent.ts +23 -0
  238. package/src/agentStateSet.ts +75 -0
  239. package/src/choices/choice.ts +16 -0
  240. package/src/choices/choiceFactory.ts +189 -0
  241. package/src/choices/findChoices.ts +70 -0
  242. package/src/choices/findValues.ts +179 -0
  243. package/src/choices/index.ts +11 -0
  244. package/src/choices/modelResult.ts +11 -0
  245. package/src/choices/recognizeChoices.ts +94 -0
  246. package/src/choices/tokenizer.ts +93 -0
  247. package/src/componentDialog.ts +306 -0
  248. package/src/componentRegistration.ts +30 -0
  249. package/src/configurable.ts +55 -0
  250. package/src/configuration.ts +22 -0
  251. package/src/converter.ts +15 -0
  252. package/src/dialog.ts +243 -0
  253. package/src/dialogContainer.ts +90 -0
  254. package/src/dialogContext.ts +607 -0
  255. package/src/dialogContextError.ts +50 -0
  256. package/src/dialogEvent.ts +23 -0
  257. package/src/dialogEvents.ts +16 -0
  258. package/src/dialogHelper.ts +154 -0
  259. package/src/dialogInstance.ts +32 -0
  260. package/src/dialogManager.ts +202 -0
  261. package/src/dialogReason.ts +40 -0
  262. package/src/dialogSet.ts +168 -0
  263. package/src/dialogTurnResult.ts +37 -0
  264. package/src/dialogTurnStateConstants.ts +13 -0
  265. package/src/dialogTurnStatus.ts +38 -0
  266. package/src/dialogsAgentComponent.ts +71 -0
  267. package/src/dialogsComponentRegistration.ts +49 -0
  268. package/src/i18n.ts +17 -0
  269. package/src/index.ts +31 -0
  270. package/src/intentScore.ts +11 -0
  271. package/src/memory/componentMemoryScopes.ts +28 -0
  272. package/src/memory/componentPathResolvers.ts +29 -0
  273. package/src/memory/dialogPath.ts +33 -0
  274. package/src/memory/dialogStateManager.ts +661 -0
  275. package/src/memory/index.ts +12 -0
  276. package/src/memory/pathResolvers/aliasPathResolver.ts +44 -0
  277. package/src/memory/pathResolvers/atAtPathResolver.ts +14 -0
  278. package/src/memory/pathResolvers/atPathResolver.ts +45 -0
  279. package/src/memory/pathResolvers/dollarPathResolver.ts +14 -0
  280. package/src/memory/pathResolvers/hashPathResolver.ts +14 -0
  281. package/src/memory/pathResolvers/index.ts +11 -0
  282. package/src/memory/pathResolvers/pathResolver.ts +14 -0
  283. package/src/memory/pathResolvers/percentPathResolver.ts +14 -0
  284. package/src/memory/scopePath.ts +19 -0
  285. package/src/memory/scopes/agentStateMemoryScope.ts +92 -0
  286. package/src/memory/scopes/classMemoryScope.ts +71 -0
  287. package/src/memory/scopes/conversationMemoryScope.ts +19 -0
  288. package/src/memory/scopes/dialogClassMemoryScope.ts +43 -0
  289. package/src/memory/scopes/dialogContextMemoryScope.ts +51 -0
  290. package/src/memory/scopes/dialogMemoryScope.ts +79 -0
  291. package/src/memory/scopes/index.ts +15 -0
  292. package/src/memory/scopes/memoryScope.ts +70 -0
  293. package/src/memory/scopes/settingsMemoryScope.ts +239 -0
  294. package/src/memory/scopes/thisMemoryScope.ts +44 -0
  295. package/src/memory/scopes/turnMemoryScope.ts +54 -0
  296. package/src/memory/scopes/userMemoryScope.ts +19 -0
  297. package/src/memory/turnPath.ts +45 -0
  298. package/src/prompts/activityPrompt.ts +202 -0
  299. package/src/prompts/attachmentPrompt.ts +62 -0
  300. package/src/prompts/choicePrompt.ts +176 -0
  301. package/src/prompts/confirmPrompt.ts +182 -0
  302. package/src/prompts/datetimePrompt.ts +110 -0
  303. package/src/prompts/index.ts +13 -0
  304. package/src/prompts/numberPrompt.ts +117 -0
  305. package/src/prompts/prompt.ts +459 -0
  306. package/src/prompts/promptCultureModels.ts +178 -0
  307. package/src/prompts/textPrompt.ts +82 -0
  308. package/src/recognizer.ts +127 -0
  309. package/src/recognizerResult.ts +37 -0
  310. package/src/serviceCollection.ts +305 -0
  311. package/src/stringUtils.ts +62 -0
  312. package/src/template.ts +20 -0
  313. package/src/waterfallDialog.ts +215 -0
  314. package/src/waterfallStepContext.ts +96 -0
  315. package/vendor/cldr-data/README.md +5 -0
  316. package/vendor/cldr-data/main/de/numbers.json +156 -0
  317. package/vendor/cldr-data/main/en/numbers.json +159 -0
  318. package/vendor/cldr-data/main/es/numbers.json +156 -0
  319. package/vendor/cldr-data/main/fr/numbers.json +157 -0
  320. package/vendor/cldr-data/main/ja/numbers.json +120 -0
  321. package/vendor/cldr-data/main/nl/numbers.json +156 -0
  322. package/vendor/cldr-data/main/pt/numbers.json +156 -0
  323. package/vendor/cldr-data/main/zh/numbers.json +214 -0
  324. package/vendor/cldr-data/supplemental/likelySubtags.json +1844 -0
  325. 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":"","sources":["../../../src/choices/findValues.ts"],"names":[],"mappings":";;AAuCA,gCA2IC;AA7KD,2CAAwE;AAuBxE;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,SAAiB,EACjB,MAAqB,EACrB,OAA2B;I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
@@ -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,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=modelResult.js.map
@@ -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,gBAA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
@@ -0,0 +1,25 @@
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=tokenizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokenizer.js","sourceRoot":"","sources":["../../../src/choices/tokenizer.ts"],"names":[],"mappings":";;AA0BA,4CAwCC;AA/CD;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAAE,IAAY,EAAE,OAAgB;IAC9D,MAAM,MAAM,GAAY,EAAE,CAAA;IAC1B,IAAI,KAAwB,CAAA;IAE5B,SAAS,WAAW,CAAE,GAAW;QAC/B,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,CAAC,GAAG,GAAG,GAAG,CAAA;YACf,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAA;YAC3C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YAClB,KAAK,GAAG,SAAS,CAAA;QACnB,CAAC;IACH,CAAC;IAED,aAAa;IACb,MAAM,MAAM,GAAW,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;IAC7C,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,OAAO,CAAC,GAAG,MAAM,EAAE,C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M,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
+ }