@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,459 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { Activity, ActivityTypes, InputHints, MessageFactory, TurnContext } from '@microsoft/agents-hosting'
6
+ import { Choice, ChoiceFactory, ChoiceFactoryOptions } from '../choices'
7
+ import { Dialog } from '../dialog'
8
+ import { DialogContext } from '../dialogContext'
9
+ import { DialogInstance } from '../dialogInstance'
10
+ import { DialogTurnResult } from '../dialogTurnResult'
11
+ import { DialogReason } from '../dialogReason'
12
+ import { DialogEvent } from '../dialogEvent'
13
+
14
+ /**
15
+ * Controls the way that choices for a `ChoicePrompt` or yes/no options for a `ConfirmPrompt` are
16
+ * presented to a user.
17
+ */
18
+ export enum ListStyle {
19
+ /**
20
+ * Don't include any choices for prompt.
21
+ */
22
+ none,
23
+
24
+ /**
25
+ * Automatically select the appropriate style for the current channel.
26
+ */
27
+ auto,
28
+
29
+ /**
30
+ * Add choices to prompt as an inline list.
31
+ */
32
+ inline,
33
+
34
+ /**
35
+ * Add choices to prompt as a numbered list.
36
+ */
37
+ list,
38
+
39
+ /**
40
+ * Add choices to prompt as suggested actions.
41
+ */
42
+ suggestedAction,
43
+
44
+ /**
45
+ * Add choices to prompt as a HeroCard with buttons.
46
+ */
47
+ heroCard,
48
+ }
49
+
50
+ /**
51
+ * Basic configuration options supported by all prompts.
52
+ */
53
+ export interface PromptOptions {
54
+ /**
55
+ * (Optional) Initial prompt to send the user.
56
+ */
57
+ prompt?: string | Activity;
58
+
59
+ /**
60
+ * (Optional) Retry prompt to send the user.
61
+ */
62
+ retryPrompt?: string | Activity;
63
+
64
+ /**
65
+ * (Optional) List of choices associated with the prompt.
66
+ */
67
+ choices?: (string | Choice)[];
68
+
69
+ /**
70
+ * (Optional) Property that can be used to override or set the value of ChoicePrompt.Style
71
+ * when the prompt is executed using DialogContext.prompt.
72
+ */
73
+ style?: ListStyle;
74
+
75
+ /**
76
+ * (Optional) Additional validation rules to pass the prompts validator routine.
77
+ */
78
+ validations?: object;
79
+
80
+ /**
81
+ * The locale to be use for recognizing the utterance.
82
+ */
83
+ recognizeLanguage?: string;
84
+ }
85
+
86
+ /**
87
+ * Result returned by a prompts recognizer function.
88
+ *
89
+ * @param T Type of value being recognized.
90
+ */
91
+ export interface PromptRecognizerResult<T> {
92
+ /**
93
+ * If `true` the users utterance was successfully recognized and [value](#value) contains the
94
+ * recognized result.
95
+ */
96
+ succeeded: boolean;
97
+
98
+ /**
99
+ * Value that was recognized if [succeeded](#succeeded) is `true`.
100
+ */
101
+ value?: T;
102
+ }
103
+
104
+ /**
105
+ * Function signature for providing a custom prompt validator.
106
+ *
107
+ * ```TypeScript
108
+ * type PromptValidator<T> = (prompt: PromptValidatorContext<T>) => Promise<boolean>;
109
+ * ```
110
+ *
111
+ * @remarks
112
+ * The validator should be an asynchronous function that returns `true` if
113
+ * `prompt.recognized.value` is valid and the prompt should end.
114
+ *
115
+ * > [!NOTE]
116
+ * > If the validator returns `false` the prompts default re-prompt logic will be run unless the
117
+ * > validator sends a custom re-prompt to the user using `prompt.context.sendActivity()`. In that
118
+ * > case the prompts default re-rpompt logic will not be run.
119
+ * @param T Type of recognizer result being validated.
120
+ * @param PromptValidator.prompt Contextual information containing the recognizer result and original options passed to the prompt.
121
+ */
122
+ export type PromptValidator<T> = (prompt: PromptValidatorContext<T>) => Promise<boolean>
123
+
124
+ /**
125
+ * Contextual information passed to a custom `PromptValidator`.
126
+ *
127
+ * @param T Type of recognizer result being validated.
128
+ */
129
+ export interface PromptValidatorContext<T> {
130
+ /**
131
+ * The context for the current turn of conversation with the user.
132
+ *
133
+ * @remarks
134
+ * The validator can use this to re-prompt the user.
135
+ */
136
+ readonly context: TurnContext;
137
+
138
+ /**
139
+ * Result returned from the prompts recognizer function.
140
+ *
141
+ * @remarks
142
+ * The `prompt.recognized.succeeded` field can be checked to determine of the recognizer found
143
+ * anything and then the value can be retrieved from `prompt.recognized.value`.
144
+ */
145
+ readonly recognized: PromptRecognizerResult<T>;
146
+
147
+ /**
148
+ * A dictionary of values persisted for each conversational turn while the prompt is active.
149
+ *
150
+ * @remarks
151
+ * The validator can use this to persist things like turn counts or other state information.
152
+ */
153
+ readonly state: object;
154
+
155
+ /**
156
+ * Original set of options passed to the prompt by the calling dialog.
157
+ *
158
+ * @remarks
159
+ * The validator can extend this interface to support additional prompt options.
160
+ */
161
+ readonly options: PromptOptions;
162
+
163
+ /**
164
+ * A count of the number of times the prompt has been executed.
165
+ *
166
+ * A number indicating how many times the prompt was invoked (starting at 1 for the first time it was invoked).
167
+ */
168
+ readonly attemptCount: number;
169
+ }
170
+
171
+ /**
172
+ * Base class for all prompts.
173
+ *
174
+ * @param T Type of value being returned by the prompts recognizer function.
175
+ */
176
+ export abstract class Prompt<T> extends Dialog {
177
+ /**
178
+ * Creates a new Prompt instance.
179
+ *
180
+ * @param dialogId Unique ID of the prompt within its parent `DialogSet` or `ComponentDialog`.
181
+ * @param validator (Optional) custom validator used to provide additional validation and re-prompting logic for the prompt.
182
+ */
183
+ protected constructor (
184
+ dialogId: string,
185
+ private validator?: PromptValidator<T>
186
+ ) {
187
+ super(dialogId)
188
+ }
189
+
190
+ /**
191
+ * Called when a prompt dialog is pushed onto the dialog stack and is being activated.
192
+ *
193
+ * @param dialogContext The DialogContext for the current
194
+ * turn of the conversation.
195
+ * @param options Optional. PromptOptions,
196
+ * additional information to pass to the prompt being started.
197
+ * @returns A `Promise` representing the asynchronous operation.
198
+ * @remarks
199
+ * If the task is successful, the result indicates whether the prompt is still
200
+ * active after the turn has been processed by the prompt.
201
+ */
202
+ async beginDialog (dialogContext: DialogContext, options: PromptOptions): Promise<DialogTurnResult> {
203
+ // Ensure prompts have input hint set
204
+ const opt: Partial<PromptOptions> = { ...options }
205
+ if (opt.prompt && typeof opt.prompt === 'object' && typeof opt.prompt.inputHint !== 'string') {
206
+ opt.prompt.inputHint = InputHints.ExpectingInput
207
+ }
208
+ if (opt.retryPrompt && typeof opt.retryPrompt === 'object' && typeof opt.retryPrompt.inputHint !== 'string') {
209
+ opt.retryPrompt.inputHint = InputHints.ExpectingInput
210
+ }
211
+
212
+ // Initialize prompt state
213
+ const state: PromptState = dialogContext.activeDialog.state as PromptState
214
+ state.options = opt
215
+ state.state = {}
216
+
217
+ // Send initial prompt
218
+ await this.onPrompt(dialogContext.context, state.state, state.options, false)
219
+
220
+ return Dialog.EndOfTurn
221
+ }
222
+
223
+ /**
224
+ * Called when a prompt dialog is the active dialog and the user replied with a new activity.
225
+ *
226
+ * @param dialogContext The DialogContext for the current turn of conversation.
227
+ * @returns A `Promise` representing the asynchronous operation.
228
+ * @remarks
229
+ * If the task is successful, the result indicates whether the dialog is still
230
+ * active after the turn has been processed by the dialog.
231
+ * The prompt generally continues to receive the user's replies until it accepts the
232
+ * user's reply as valid input for the prompt.
233
+ */
234
+ async continueDialog (dialogContext: DialogContext): Promise<DialogTurnResult> {
235
+ // Don't do anything for non-message activities
236
+ if (dialogContext.context.activity.type !== ActivityTypes.Message) {
237
+ return Dialog.EndOfTurn
238
+ }
239
+
240
+ // Are we being continued after an interruption?
241
+ // - The stepCount will be 1 or more if we're running in the context of an AdaptiveDialog
242
+ // and we're coming back from an interruption.
243
+ const stepCount = dialogContext.state.getValue('turn.stepCount')
244
+ if (typeof stepCount === 'number' && stepCount > 0) {
245
+ // re-prompt and then end
246
+ await this.repromptDialog(dialogContext.context, dialogContext.activeDialog)
247
+ return Dialog.EndOfTurn
248
+ }
249
+
250
+ // Perform base recognition
251
+ const state: PromptState = dialogContext.activeDialog.state as PromptState
252
+ const recognized: PromptRecognizerResult<T> = await this.onRecognize(dialogContext.context, state.state, state.options)
253
+
254
+ // Validate the return value
255
+ let isValid = false
256
+ if (this.validator) {
257
+ if (state.state['attemptCount'] === undefined) {
258
+ state.state['attemptCount'] = 0
259
+ }
260
+ isValid = await this.validator({
261
+ context: dialogContext.context,
262
+ recognized,
263
+ state: state.state,
264
+ options: state.options,
265
+ attemptCount: ++state.state['attemptCount'],
266
+ })
267
+ } else if (recognized.succeeded) {
268
+ isValid = true
269
+ }
270
+
271
+ // Return recognized value or re-prompt
272
+ if (isValid) {
273
+ return await dialogContext.endDialog(recognized.value)
274
+ } else {
275
+ if (!dialogContext.context.responded) {
276
+ await this.onPrompt(dialogContext.context, state.state, state.options, true)
277
+ }
278
+
279
+ return Dialog.EndOfTurn
280
+ }
281
+ }
282
+
283
+ /**
284
+ * Called before an event is bubbled to its parent.
285
+ *
286
+ * @param dialogContext The DialogContext for the current turn of conversation.
287
+ * @param event DialogEvent, the event being raised.
288
+ * @returns Whether the event is handled by the current dialog and further processing should stop.
289
+ * @remarks
290
+ * This is a good place to perform interception of an event as returning `true` will prevent
291
+ * any further bubbling of the event to the dialogs parents and will also prevent any child
292
+ * dialogs from performing their default processing.
293
+ */
294
+ protected async onPreBubbleEvent (dialogContext: DialogContext, event: DialogEvent): Promise<boolean> {
295
+ if (event.name === 'activityReceived' && dialogContext.context.activity.type === ActivityTypes.Message) {
296
+ // Perform base recognition
297
+ const state: PromptState = dialogContext.activeDialog.state as PromptState
298
+ const recognized: PromptRecognizerResult<T> = await this.onRecognize(
299
+ dialogContext.context,
300
+ state.state,
301
+ state.options
302
+ )
303
+ return recognized.succeeded
304
+ }
305
+
306
+ return false
307
+ }
308
+
309
+ /**
310
+ * Called when a prompt dialog resumes being the active dialog on the dialog stack, such as
311
+ * when the previous active dialog on the stack completes.
312
+ *
313
+ * @param dialogContext The DialogContext for the current turn of the conversation.
314
+ * @param _reason An enum indicating why the dialog resumed.
315
+ * @param _result Optional, value returned from the previous dialog on the stack.
316
+ * The type of the value returned is dependent on the previous dialog.
317
+ * @returns A Promise representing the asynchronous operation.
318
+ * @remarks
319
+ * If the task is successful, the result indicates whether the dialog is still
320
+ * active after the turn has been processed by the dialog.
321
+ */
322
+ async resumeDialog (dialogContext: DialogContext, _reason: DialogReason, _result?: any): Promise<DialogTurnResult> {
323
+ // Prompts are typically leaf nodes on the stack but the dev is free to push other dialogs
324
+ // on top of the stack which will result in the prompt receiving an unexpected call to
325
+ // resumeDialog() when the pushed on dialog ends.
326
+ // To avoid the prompt prematurely ending we need to implement this method and
327
+ // simply re-prompt the user.
328
+ await this.repromptDialog(dialogContext.context, dialogContext.activeDialog)
329
+
330
+ return Dialog.EndOfTurn
331
+ }
332
+
333
+ /**
334
+ * Called when a prompt dialog has been requested to re-prompt the user for input.
335
+ *
336
+ * @param context TurnContext, context for the current
337
+ * turn of conversation with the user.
338
+ * @param instance DialogInstance, the instance
339
+ * of the dialog on the stack.
340
+ * @returns A `Promise` representing the asynchronous operation.
341
+ */
342
+ async repromptDialog (context: TurnContext, instance: DialogInstance): Promise<void> {
343
+ const state: PromptState = instance.state as PromptState
344
+ await this.onPrompt(context, state.state, state.options, false)
345
+ }
346
+
347
+ /**
348
+ * Called anytime the derived class should send the user a prompt.
349
+ *
350
+ * @param context Context for the current turn of conversation with the user.
351
+ * @param state Additional state being persisted for the prompt.
352
+ * @param options Options that the prompt was started with in the call to `DialogContext.prompt()`.
353
+ * @param isRetry If `true` the users response wasn't recognized and the re-prompt should be sent.
354
+ */
355
+ protected abstract onPrompt (
356
+ context: TurnContext,
357
+ state: object,
358
+ options: PromptOptions,
359
+ isRetry: boolean,
360
+ ): Promise<void>
361
+
362
+ /**
363
+ * Called to recognize an utterance received from the user.
364
+ *
365
+ * @remarks
366
+ * The Prompt class filters out non-message activities so its safe to assume that the users
367
+ * utterance can be retrieved from `context.activity.text`.
368
+ * @param context Context for the current turn of conversation with the user.
369
+ * @param state Additional state being persisted for the prompt.
370
+ * @param options Options that the prompt was started with in the call to `DialogContext.prompt()`.
371
+ */
372
+ protected abstract onRecognize (
373
+ context: TurnContext,
374
+ state: object,
375
+ options: PromptOptions,
376
+ ): Promise<PromptRecognizerResult<T>>
377
+
378
+ /**
379
+ * Helper function to compose an output activity containing a set of choices.
380
+ *
381
+ * @param prompt The prompt to append the users choices to.
382
+ * @param channelId ID of the channel the prompt is being sent to.
383
+ * @param choices List of choices to append.
384
+ * @param style Configured style for the list of choices.
385
+ * @param options (Optional) options to configure the underlying ChoiceFactory call.
386
+ * @returns The composed activity ready to send to the user.
387
+ */
388
+ protected appendChoices (
389
+ prompt: string | Activity,
390
+ channelId: string,
391
+ choices: (string | Choice)[],
392
+ style: ListStyle,
393
+ options?: ChoiceFactoryOptions
394
+ ): Activity {
395
+ // Get base prompt text (if any)
396
+ let text = ''
397
+ if (typeof prompt === 'string') {
398
+ text = prompt
399
+ } else if (prompt && prompt.text) {
400
+ text = prompt.text
401
+ }
402
+
403
+ // Create temporary msg
404
+ let msg: Activity
405
+ switch (style) {
406
+ case ListStyle.inline:
407
+ msg = ChoiceFactory.inline(choices, text, undefined, options)
408
+ break
409
+
410
+ case ListStyle.list:
411
+ msg = ChoiceFactory.list(choices, text, undefined, options)
412
+ break
413
+
414
+ case ListStyle.none:
415
+ msg = MessageFactory.text(text)
416
+ break
417
+
418
+ default:
419
+ msg = ChoiceFactory.forChannel(channelId, choices, text, undefined, options)
420
+ break
421
+ }
422
+
423
+ // Update prompt with text, actions and attachments
424
+ if (typeof prompt === 'object') {
425
+ // Clone the prompt Activity as to not modify the original prompt.
426
+ prompt = JSON.parse(JSON.stringify(prompt)) as Activity
427
+ prompt.text = msg.text
428
+ if (
429
+ msg.suggestedActions &&
430
+ Array.isArray(msg.suggestedActions.actions) &&
431
+ msg.suggestedActions.actions.length > 0
432
+ ) {
433
+ prompt.suggestedActions = msg.suggestedActions
434
+ }
435
+
436
+ if (msg.attachments) {
437
+ if (prompt.attachments) {
438
+ prompt.attachments = prompt.attachments.concat(msg.attachments)
439
+ } else {
440
+ prompt.attachments = msg.attachments
441
+ }
442
+ }
443
+
444
+ return prompt
445
+ } else {
446
+ msg.inputHint = InputHints.ExpectingInput
447
+
448
+ return msg
449
+ }
450
+ }
451
+ }
452
+
453
+ /**
454
+ * @private
455
+ */
456
+ interface PromptState {
457
+ state: any;
458
+ options: PromptOptions;
459
+ }
@@ -0,0 +1,178 @@
1
+ import { Culture } from '@microsoft/recognizers-text-suite'
2
+
3
+ export interface PromptCultureModel {
4
+ /**
5
+ * Culture Model's Locale.
6
+ *
7
+ * @example
8
+ * "en-US"
9
+ */
10
+ locale: string;
11
+ /**
12
+ * Culture Model's InlineSeparator.
13
+ *
14
+ * @example
15
+ * ", "
16
+ */
17
+ separator: string;
18
+ /**
19
+ * Culture Model's InlineOr.
20
+ *
21
+ * @example
22
+ * " or "
23
+ */
24
+ inlineOr: string;
25
+ /**
26
+ * Culture Model's InlineOrMore.
27
+ *
28
+ * @example
29
+ * ", or "
30
+ */
31
+ inlineOrMore: string;
32
+ /**
33
+ * Equivalent of "Yes" in Culture Model's Language.
34
+ *
35
+ * @example
36
+ * "Yes"
37
+ */
38
+ yesInLanguage: string;
39
+ /**
40
+ * Equivalent of "No" in Culture Model's Language.
41
+ *
42
+ * @example
43
+ * "No"
44
+ */
45
+ noInLanguage: string;
46
+ }
47
+
48
+ /**
49
+ * Class container for currently-supported Culture Models in Confirm and Choice Prompt.
50
+ */
51
+ export class PromptCultureModels {
52
+ static Chinese: PromptCultureModel = {
53
+ locale: Culture.Chinese,
54
+ separator: ', ',
55
+ inlineOr: ' 要么 ',
56
+ inlineOrMore: ', 要么 ',
57
+ yesInLanguage: '是的',
58
+ noInLanguage: '不',
59
+ }
60
+
61
+ static Dutch: PromptCultureModel = {
62
+ locale: Culture.Dutch,
63
+ separator: ', ',
64
+ inlineOr: ' of ',
65
+ inlineOrMore: ', of ',
66
+ yesInLanguage: 'Ja',
67
+ noInLanguage: 'Nee',
68
+ }
69
+
70
+ static English: PromptCultureModel = {
71
+ locale: Culture.English,
72
+ separator: ', ',
73
+ inlineOr: ' or ',
74
+ inlineOrMore: ', or ',
75
+ yesInLanguage: 'Yes',
76
+ noInLanguage: 'No',
77
+ }
78
+
79
+ static French: PromptCultureModel = {
80
+ locale: Culture.French,
81
+ separator: ', ',
82
+ inlineOr: ' ou ',
83
+ inlineOrMore: ', ou ',
84
+ yesInLanguage: 'Oui',
85
+ noInLanguage: 'Non',
86
+ }
87
+
88
+ static German: PromptCultureModel = {
89
+ locale: Culture.German,
90
+ separator: ', ',
91
+ inlineOr: ' oder ',
92
+ inlineOrMore: ', oder ',
93
+ yesInLanguage: 'Ja',
94
+ noInLanguage: 'Nein',
95
+ }
96
+
97
+ static Italian: PromptCultureModel = {
98
+ locale: Culture.Italian,
99
+ separator: ', ',
100
+ inlineOr: ' o ',
101
+ inlineOrMore: ' o ',
102
+ yesInLanguage: 'Si',
103
+ noInLanguage: 'No',
104
+ }
105
+
106
+ static Japanese: PromptCultureModel = {
107
+ locale: Culture.Japanese,
108
+ separator: '、 ',
109
+ inlineOr: ' または ',
110
+ inlineOrMore: '、 または ',
111
+ yesInLanguage: 'はい',
112
+ noInLanguage: 'いいえ',
113
+ }
114
+
115
+ static Portuguese: PromptCultureModel = {
116
+ locale: Culture.Portuguese,
117
+ separator: ', ',
118
+ inlineOr: ' ou ',
119
+ inlineOrMore: ', ou ',
120
+ yesInLanguage: 'Sim',
121
+ noInLanguage: 'Não',
122
+ }
123
+
124
+ static Spanish: PromptCultureModel = {
125
+ locale: Culture.Spanish,
126
+ separator: ', ',
127
+ inlineOr: ' o ',
128
+ inlineOrMore: ', o ',
129
+ yesInLanguage: 'Sí',
130
+ noInLanguage: 'No',
131
+ }
132
+
133
+ /**
134
+ * @private
135
+ */
136
+ private static getSupportedCultureCodes (): string[] {
137
+ return this.getSupportedCultures().map((c): string => c.locale)
138
+ }
139
+
140
+ /**
141
+ * Use Recognizers-Text to normalize various potential Locale strings to a standard.
142
+ *
143
+ * @remarks This is mostly a copy/paste from https://github.com/microsoft/Recognizers-Text/blob/master/JavaScript/packages/recognizers-text/src/culture.ts#L39
144
+ * This doesn't directly use Recognizers-Text's MapToNearestLanguage because if they add language support before we do, it will break our prompts.
145
+ * @param cultureCode Represents locale. Examples: "en-US, en-us, EN".
146
+ * @returns Normalized locale.
147
+ */
148
+ static mapToNearestLanguage (cultureCode: string): string {
149
+ if (cultureCode) {
150
+ cultureCode = cultureCode.toLowerCase()
151
+ const supportedCultureCodes = this.getSupportedCultureCodes()
152
+
153
+ if (supportedCultureCodes.indexOf(cultureCode) < 0) {
154
+ const culturePrefix = cultureCode.split('-')[0].trim()
155
+
156
+ supportedCultureCodes.forEach(function (supportedCultureCode): void {
157
+ if (supportedCultureCode.startsWith(culturePrefix)) {
158
+ cultureCode = supportedCultureCode
159
+ }
160
+ })
161
+ }
162
+ }
163
+
164
+ return cultureCode
165
+ }
166
+
167
+ static getSupportedCultures = (): PromptCultureModel[] => [
168
+ PromptCultureModels.Chinese,
169
+ PromptCultureModels.Dutch,
170
+ PromptCultureModels.English,
171
+ PromptCultureModels.French,
172
+ PromptCultureModels.German,
173
+ PromptCultureModels.Italian,
174
+ PromptCultureModels.Japanese,
175
+ PromptCultureModels.Portuguese,
176
+ PromptCultureModels.Spanish,
177
+ ]
178
+ }