@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,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ActivityPrompt = void 0;
4
+ /**
5
+ * Copyright (c) Microsoft Corporation. All rights reserved.
6
+ * Licensed under the MIT License.
7
+ */
8
+ const agents_hosting_1 = require("@microsoft/agents-hosting");
9
+ const dialog_1 = require("../dialog");
10
+ /**
11
+ * Waits for an activity to be received.
12
+ *
13
+ * @remarks
14
+ * This prompt requires a validator be passed in and is useful when waiting for non-message
15
+ * activities like an event to be received. The validator can ignore received events until the
16
+ * expected activity is received.
17
+ */
18
+ class ActivityPrompt extends dialog_1.Dialog {
19
+ /**
20
+ * Creates a new ActivityPrompt instance.
21
+ *
22
+ * @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
23
+ * @param validator Validator that will be called each time a new activity is received.
24
+ */
25
+ constructor(dialogId, validator) {
26
+ super(dialogId);
27
+ this.validator = validator;
28
+ }
29
+ /**
30
+ * Called when a prompt dialog is pushed onto the dialog stack and is being activated.
31
+ *
32
+ * @param dialogContext The DialogContext for the current
33
+ * turn of the conversation.
34
+ * @param options PromptOptions, additional
35
+ * information to pass to the prompt being started.
36
+ * @returns A `Promise` representing the asynchronous operation.
37
+ * @remarks
38
+ * If the promise is successful, the result indicates whether the prompt is still
39
+ * active after the turn has been processed by the prompt.
40
+ */
41
+ async beginDialog(dialogContext, options) {
42
+ // Ensure prompts have input hint set
43
+ const opt = { ...options };
44
+ if (opt.prompt && typeof opt.prompt === 'object' && typeof opt.prompt.inputHint !== 'string') {
45
+ opt.prompt.inputHint = agents_hosting_1.InputHints.ExpectingInput;
46
+ }
47
+ if (opt.retryPrompt && typeof opt.retryPrompt === 'object' && typeof opt.retryPrompt.inputHint !== 'string') {
48
+ opt.retryPrompt.inputHint = agents_hosting_1.InputHints.ExpectingInput;
49
+ }
50
+ // Initialize prompt state
51
+ const state = dialogContext.activeDialog.state;
52
+ state.options = opt;
53
+ state.state = {};
54
+ // Send initial prompt
55
+ await this.onPrompt(dialogContext.context, state.state, state.options, false);
56
+ return dialog_1.Dialog.EndOfTurn;
57
+ }
58
+ /**
59
+ * Called when a prompt dialog is the active dialog and the user replied with a new activity.
60
+ *
61
+ * @param dialogContext The DialogContext for the current
62
+ * turn of conversation.
63
+ * @returns A `Promise` representing the asynchronous operation.
64
+ * @remarks
65
+ * If the promise is successful, the result indicates whether the dialog is still
66
+ * active after the turn has been processed by the dialog.
67
+ * The prompt generally continues to receive the user's replies until it accepts the
68
+ * user's reply as valid input for the prompt.
69
+ */
70
+ async continueDialog(dialogContext) {
71
+ // Perform base recognition
72
+ const state = dialogContext.activeDialog.state;
73
+ const recognized = await this.onRecognize(dialogContext.context, state.state, state.options);
74
+ if (state.state['attemptCount'] === undefined) {
75
+ state.state['attemptCount'] = 0;
76
+ }
77
+ // Validate the return value
78
+ // - Unlike the other prompts a validator is required for an ActivityPrompt so we don't
79
+ // need to check for its existence before calling it.
80
+ const isValid = await this.validator({
81
+ context: dialogContext.context,
82
+ recognized,
83
+ state: state.state,
84
+ options: state.options,
85
+ attemptCount: ++state.state['attemptCount'],
86
+ });
87
+ // Return recognized value or re-prompt
88
+ if (isValid) {
89
+ return await dialogContext.endDialog(recognized.value);
90
+ }
91
+ else {
92
+ if (dialogContext.context.activity.type === agents_hosting_1.ActivityTypes.Message && !dialogContext.context.responded) {
93
+ await this.onPrompt(dialogContext.context, state.state, state.options, true);
94
+ }
95
+ return dialog_1.Dialog.EndOfTurn;
96
+ }
97
+ }
98
+ /**
99
+ * Called when a prompt dialog resumes being the active dialog on the dialog stack, such as
100
+ * when the previous active dialog on the stack completes.
101
+ *
102
+ * @param dialogContext The DialogContext for the current turn
103
+ * of the conversation.
104
+ * @param _reason DialogReason, an enum indicating why
105
+ * the dialog resumed.
106
+ * @param _result Optional. Value returned from the previous dialog on the stack.
107
+ * The type of the value returned is dependent on the previous dialog.
108
+ * @returns A `Promise` representing the asynchronous operation.
109
+ */
110
+ async resumeDialog(dialogContext, _reason, _result) {
111
+ // Prompts are typically leaf nodes on the stack but the dev is free to push other dialogs
112
+ // on top of the stack which will result in the prompt receiving an unexpected call to
113
+ // resumeDialog() when the pushed on dialog ends.
114
+ // To avoid the prompt prematurely ending we need to implement this method and
115
+ // simply re-prompt the user.
116
+ await this.repromptDialog(dialogContext.context, dialogContext.activeDialog);
117
+ return dialog_1.Dialog.EndOfTurn;
118
+ }
119
+ /**
120
+ * Called when a prompt dialog has been requested to re-prompt the user for input.
121
+ *
122
+ * @param context TurnContext, context for the current
123
+ * turn of conversation with the user.
124
+ * @param instance DialogInstance, the instance
125
+ * of the dialog on the stack.
126
+ * @returns A `Promise` representing the asynchronous operation.
127
+ */
128
+ async repromptDialog(context, instance) {
129
+ const state = instance.state;
130
+ await this.onPrompt(context, state.state, state.options, false);
131
+ }
132
+ /**
133
+ * When overridden in a derived class, prompts the user for input.
134
+ *
135
+ * @param context TurnContext, context for the current
136
+ * turn of conversation with the user.
137
+ * @param state Contains state for the current instance of the prompt on the dialog stack.
138
+ * @param options A PromptOptions object constructed
139
+ * from the options initially provided in the call to Prompt.
140
+ * @param isRetry A boolean representing if the prompt is a retry.
141
+ * @returns A `Promise` representing the asynchronous operation.
142
+ */
143
+ async onPrompt(context, state, options, isRetry) {
144
+ if (isRetry && options.retryPrompt) {
145
+ await context.sendActivity(options.retryPrompt, undefined, agents_hosting_1.InputHints.ExpectingInput);
146
+ }
147
+ else if (options.prompt) {
148
+ await context.sendActivity(options.prompt, undefined, agents_hosting_1.InputHints.ExpectingInput);
149
+ }
150
+ }
151
+ /**
152
+ * When overridden in a derived class, attempts to recognize the incoming Activity.
153
+ *
154
+ * @param context TurnContext, context for the current
155
+ * turn of conversation with the user.
156
+ * @param _state Contains state for the current instance of the prompt on the dialog stack.
157
+ * @param _options A PromptOptions object constructed
158
+ * from the options initially provided in the call to Prompt.
159
+ * @returns A `Promise` representing the asynchronous operation.
160
+ */
161
+ async onRecognize(context, _state, _options) {
162
+ return { succeeded: true, value: context.activity };
163
+ }
164
+ }
165
+ exports.ActivityPrompt = ActivityPrompt;
166
+ //# sourceMappingURL=activityPrompt.js.map
@@ -0,0 +1 @@
1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.
4
+ */
5
+ import { Attachment, TurnContext } from '@microsoft/agents-hosting';
6
+ import { Prompt, PromptOptions, PromptRecognizerResult, PromptValidator } from './prompt';
7
+ /**
8
+ * Prompts a user to upload attachments like images.
9
+ *
10
+ * @remarks
11
+ * By default the prompt will return to the calling dialog an `Attachment[]`.
12
+ */
13
+ export declare class AttachmentPrompt extends Prompt<Attachment[]> {
14
+ constructor(dialogId: string, validator?: PromptValidator<Attachment[]>);
15
+ /**
16
+ * Prompts the user for input.
17
+ *
18
+ * @param context Context for the current turn of conversation with the user.
19
+ * @param state Contains state for the current instance of the prompt on the dialog stack.
20
+ * @param options A prompt options object constructed from the options initially provided
21
+ * in the call to Prompt.
22
+ * @param isRetry `true` if this is the first time this prompt dialog instance
23
+ * on the stack is prompting the user for input; otherwise, false.
24
+ * @returns A Promise representing the asynchronous operation.
25
+ */
26
+ protected onPrompt(context: TurnContext, state: any, options: PromptOptions, isRetry: boolean): Promise<void>;
27
+ /**
28
+ * Attempts to recognize the user's input.
29
+ *
30
+ * @param context Context for the current turn of conversation with the user.
31
+ * @param _state Contains state for the current instance of the prompt on the dialog stack.
32
+ * @param _options A prompt options object constructed from the options initially provided
33
+ * in the call to Prompt.
34
+ * @returns A Promise representing the asynchronous operation.
35
+ */
36
+ protected onRecognize(context: TurnContext, _state: any, _options: PromptOptions): Promise<PromptRecognizerResult<Attachment[]>>;
37
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttachmentPrompt = void 0;
4
+ /**
5
+ * Copyright (c) Microsoft Corporation. All rights reserved.
6
+ * Licensed under the MIT License.
7
+ */
8
+ const agents_hosting_1 = require("@microsoft/agents-hosting");
9
+ const prompt_1 = require("./prompt");
10
+ /**
11
+ * Prompts a user to upload attachments like images.
12
+ *
13
+ * @remarks
14
+ * By default the prompt will return to the calling dialog an `Attachment[]`.
15
+ */
16
+ class AttachmentPrompt extends prompt_1.Prompt {
17
+ // eslint-disable-next-line @typescript-eslint/no-useless-constructor
18
+ constructor(dialogId, validator) {
19
+ super(dialogId, validator);
20
+ }
21
+ /**
22
+ * Prompts the user for input.
23
+ *
24
+ * @param context Context for the current turn of conversation with the user.
25
+ * @param state Contains state for the current instance of the prompt on the dialog stack.
26
+ * @param options A prompt options object constructed from the options initially provided
27
+ * in the call to Prompt.
28
+ * @param isRetry `true` if this is the first time this prompt dialog instance
29
+ * on the stack is prompting the user for input; otherwise, false.
30
+ * @returns A Promise representing the asynchronous operation.
31
+ */
32
+ async onPrompt(context, state, options, isRetry) {
33
+ if (isRetry && options.retryPrompt) {
34
+ await context.sendActivity(options.retryPrompt, undefined, agents_hosting_1.InputHints.ExpectingInput);
35
+ }
36
+ else if (options.prompt) {
37
+ await context.sendActivity(options.prompt, undefined, agents_hosting_1.InputHints.ExpectingInput);
38
+ }
39
+ }
40
+ /**
41
+ * Attempts to recognize the user's input.
42
+ *
43
+ * @param context Context for the current turn of conversation with the user.
44
+ * @param _state Contains state for the current instance of the prompt on the dialog stack.
45
+ * @param _options A prompt options object constructed from the options initially provided
46
+ * in the call to Prompt.
47
+ * @returns A Promise representing the asynchronous operation.
48
+ */
49
+ async onRecognize(context, _state, _options) {
50
+ const value = context.activity.attachments;
51
+ return Array.isArray(value) && value.length > 0 ? { succeeded: true, value } : { succeeded: false };
52
+ }
53
+ }
54
+ exports.AttachmentPrompt = AttachmentPrompt;
55
+ //# sourceMappingURL=attachmentPrompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachmentPrompt.js","sourceRoot":"","sources":["../../../src/prompts/attachmentPrompt.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,8DAA+E;AAC/E,qCAAyF;AAEzF;;;;;GAKG;AACH,MAAa,gBAAiB,SAAQ,eAAoB;IACxD,qEAAqE;IACrE,YAAa,QAAgB,EAAE,SAAyC;QACtE,KAAK,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;IAC5B,CAAC;IAED;;;;;;;;;;SAUK;IACK,KAAK,CAAC,QAAQ,CACtB,OAAoB,EACpB,KAAU,EACV,OAAsB,EACtB,OAAgB;QAEhB,IAAI,OAAO,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YACnC,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,EAAE,2BAAU,CAAC,cAAc,CAAC,CAAA;QACvF,CAAC;aAAM,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YAC1B,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,2BAAU,CAAC,cAAc,CAAC,CAAA;QAClF,CAAC;IACH,CAAC;IAED;;;;;;;;SAQK;IACK,KAAK,CAAC,WAAW,CACzB,OAAoB,EACpB,MAAW,EACX,QAAuB;QAEvB,MAAM,KAAK,GAAiB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAA;QAExD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;IACrG,CAAC;CACF;AAhDD,4CAgDC"}
@@ -0,0 +1,83 @@
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 { ChoiceFactoryOptions, FindChoicesOptions, FoundChoice } from '../choices';
7
+ import { ListStyle, Prompt, PromptOptions, PromptRecognizerResult, PromptValidator } from './prompt';
8
+ interface ChoiceDefaultsChoicePrompt {
9
+ [locale: string]: ChoiceFactoryOptions;
10
+ }
11
+ /**
12
+ * Prompts a user to select from a list of choices.
13
+ *
14
+ * @remarks
15
+ * By default the prompt will return to the calling dialog a `FoundChoice` object containing the
16
+ * choice that was selected.
17
+ */
18
+ export declare class ChoicePrompt extends Prompt<FoundChoice> {
19
+ /**
20
+ * A dictionary of Default Choices based on [[PromptCultureModels.getSupportedCultures()]].
21
+ * Can be replaced by user using the constructor that contains choiceDefaults.
22
+ */
23
+ private choiceDefaults;
24
+ /**
25
+ * The prompts default locale that should be recognized.
26
+ */
27
+ defaultLocale: string | undefined;
28
+ /**
29
+ * Style of the "yes" and "no" choices rendered to the user when prompting.
30
+ *
31
+ * @remarks
32
+ * Defaults to `ListStyle.auto`.
33
+ */
34
+ style: ListStyle;
35
+ /**
36
+ * Additional options passed to the `ChoiceFactory` and used to tweak the style of choices
37
+ * rendered to the user.
38
+ */
39
+ choiceOptions: ChoiceFactoryOptions | undefined;
40
+ /**
41
+ * Additional options passed to the underlying `recognizeChoices()` function.
42
+ */
43
+ recognizerOptions: FindChoicesOptions | undefined;
44
+ /**
45
+ * Creates a new `ChoicePrompt` instance.
46
+ *
47
+ * @param dialogId Unique ID of the dialog within its parent `DialogSet`.
48
+ * @param validator (Optional) validator that will be called each time the user responds to the prompt. If the validator replies with a message no additional retry prompt will be sent.
49
+ * @param defaultLocale (Optional) locale to use if `dc.context.activity.locale` not specified. Defaults to a value of `en-us`.
50
+ * @param choiceDefaults (Optional) Overrides the dictionary of Bot Framework SDK-supported _choiceDefaults (for prompt localization).
51
+ * Must be passed in to each ConfirmPrompt that needs the custom choice defaults.
52
+ */
53
+ constructor(dialogId: string, validator?: PromptValidator<FoundChoice>, defaultLocale?: string, choiceDefaults?: ChoiceDefaultsChoicePrompt);
54
+ /**
55
+ * Prompts the user for input.
56
+ *
57
+ * @param context TurnContext, context for the current
58
+ * turn of conversation with the user.
59
+ * @param state Contains state for the current instance of the prompt on the dialog stack.
60
+ * @param options A PromptOptions object constructed
61
+ * from the options initially provided in the call to Prompt.
62
+ * @param isRetry `true` if this is the first time this prompt dialog instance
63
+ * on the stack is prompting the user for input; otherwise, false.
64
+ * @returns A `Promise` representing the asynchronous operation.
65
+ */
66
+ protected onPrompt(context: TurnContext, state: any, options: PromptOptions, isRetry: boolean): Promise<void>;
67
+ /**
68
+ * Attempts to recognize the user's input.
69
+ *
70
+ * @param context TurnContext context for the current
71
+ * turn of conversation with the user.
72
+ * @param state Contains state for the current instance of the prompt on the dialog stack.
73
+ * @param options A PromptOptions object constructed
74
+ * from the options initially provided in the call to Prompt.
75
+ * @returns A `Promise` representing the asynchronous operation.
76
+ */
77
+ protected onRecognize(context: TurnContext, state: any, options: PromptOptions): Promise<PromptRecognizerResult<FoundChoice>>;
78
+ /**
79
+ * @private
80
+ */
81
+ private determineCulture;
82
+ }
83
+ export {};
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChoicePrompt = void 0;
4
+ const choices_1 = require("../choices");
5
+ const prompt_1 = require("./prompt");
6
+ const promptCultureModels_1 = require("./promptCultureModels");
7
+ /**
8
+ * Prompts a user to select from a list of choices.
9
+ *
10
+ * @remarks
11
+ * By default the prompt will return to the calling dialog a `FoundChoice` object containing the
12
+ * choice that was selected.
13
+ */
14
+ class ChoicePrompt extends prompt_1.Prompt {
15
+ /**
16
+ * Creates a new `ChoicePrompt` instance.
17
+ *
18
+ * @param dialogId Unique ID of the dialog within its parent `DialogSet`.
19
+ * @param validator (Optional) validator that will be called each time the user responds to the prompt. If the validator replies with a message no additional retry prompt will be sent.
20
+ * @param defaultLocale (Optional) locale to use if `dc.context.activity.locale` not specified. Defaults to a value of `en-us`.
21
+ * @param choiceDefaults (Optional) Overrides the dictionary of Bot Framework SDK-supported _choiceDefaults (for prompt localization).
22
+ * Must be passed in to each ConfirmPrompt that needs the custom choice defaults.
23
+ */
24
+ constructor(dialogId, validator, defaultLocale, choiceDefaults) {
25
+ super(dialogId, validator);
26
+ this.style = prompt_1.ListStyle.auto;
27
+ this.defaultLocale = defaultLocale;
28
+ if (choiceDefaults === undefined) {
29
+ const supported = {};
30
+ promptCultureModels_1.PromptCultureModels.getSupportedCultures().forEach((culture) => {
31
+ supported[culture.locale] = {
32
+ inlineSeparator: culture.separator,
33
+ inlineOr: culture.inlineOr,
34
+ inlineOrMore: culture.inlineOrMore,
35
+ includeNumbers: true,
36
+ };
37
+ });
38
+ this.choiceDefaults = supported;
39
+ }
40
+ else {
41
+ this.choiceDefaults = choiceDefaults;
42
+ }
43
+ }
44
+ /**
45
+ * Prompts the user for input.
46
+ *
47
+ * @param context TurnContext, context for the current
48
+ * turn of conversation with the user.
49
+ * @param state Contains state for the current instance of the prompt on the dialog stack.
50
+ * @param options A PromptOptions object constructed
51
+ * from the options initially provided in the call to Prompt.
52
+ * @param isRetry `true` if this is the first time this prompt dialog instance
53
+ * on the stack is prompting the user for input; otherwise, false.
54
+ * @returns A `Promise` representing the asynchronous operation.
55
+ */
56
+ async onPrompt(context, state, options, isRetry) {
57
+ // Determine locale
58
+ const locale = this.determineCulture(context.activity);
59
+ // Format prompt to send
60
+ let prompt;
61
+ const choices = (this.style === prompt_1.ListStyle.suggestedAction ? choices_1.ChoiceFactory.toChoices(options.choices) : options.choices) ||
62
+ [];
63
+ const channelId = context.activity.channelId;
64
+ const choiceOptions = this.choiceOptions || this.choiceDefaults[locale];
65
+ const choiceStyle = options.style === 0 ? 0 : options.style || this.style;
66
+ if (isRetry && options.retryPrompt) {
67
+ prompt = this.appendChoices(options.retryPrompt, channelId, choices, choiceStyle, choiceOptions);
68
+ }
69
+ else {
70
+ prompt = this.appendChoices(options.prompt, channelId, choices, choiceStyle, choiceOptions);
71
+ }
72
+ // Send prompt
73
+ await context.sendActivity(prompt);
74
+ }
75
+ /**
76
+ * Attempts to recognize the user's input.
77
+ *
78
+ * @param context TurnContext context for the current
79
+ * turn of conversation with the user.
80
+ * @param state Contains state for the current instance of the prompt on the dialog stack.
81
+ * @param options A PromptOptions object constructed
82
+ * from the options initially provided in the call to Prompt.
83
+ * @returns A `Promise` representing the asynchronous operation.
84
+ */
85
+ async onRecognize(context, state, options) {
86
+ const result = { succeeded: false };
87
+ const activity = context.activity;
88
+ const utterance = activity.text;
89
+ if (!utterance) {
90
+ return result;
91
+ }
92
+ const choices = (this.style === prompt_1.ListStyle.suggestedAction ? choices_1.ChoiceFactory.toChoices(options.choices) : options.choices) ||
93
+ [];
94
+ const opt = this.recognizerOptions || {};
95
+ opt.locale = this.determineCulture(activity, opt);
96
+ const results = (0, choices_1.recognizeChoices)(utterance, choices, opt);
97
+ if (Array.isArray(results) && results.length > 0) {
98
+ result.succeeded = true;
99
+ result.value = results[0].resolution;
100
+ }
101
+ return result;
102
+ }
103
+ /**
104
+ * @private
105
+ */
106
+ determineCulture(activity, opt) {
107
+ const optLocale = opt && opt.locale ? opt.locale : null;
108
+ let culture = promptCultureModels_1.PromptCultureModels.mapToNearestLanguage(activity.locale || optLocale || this.defaultLocale || promptCultureModels_1.PromptCultureModels.English.locale);
109
+ if (!(culture && this.choiceDefaults[culture])) {
110
+ culture = promptCultureModels_1.PromptCultureModels.English.locale;
111
+ }
112
+ return culture;
113
+ }
114
+ }
115
+ exports.ChoicePrompt = ChoicePrompt;
116
+ //# sourceMappingURL=choicePrompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"choicePrompt.js","sourceRoot":"","sources":["../../../src/prompts/choicePrompt.ts"],"names":[],"mappings":";;;AAKA,wCAAmH;AACnH,qCAAoG;AACpG,+DAA2D;AAO3D;;;;;;GAMG;AACH,MAAa,YAAa,SAAQ,eAAmB;IA+BnD;;;;;;;;SAQK;IACL,YACE,QAAgB,EAChB,SAAwC,EACxC,aAAsB,EACtB,cAA2C;QAE3C,KAAK,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;QAC1B,IAAI,CAAC,KAAK,GAAG,kBAAS,CAAC,IAAI,CAAA;QAC3B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAElC,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,SAAS,GAA+B,EAAE,CAAA;YAChD,yCAAmB,CAAC,oBAAoB,EAAE,CAAC,OAAO,CAAC,CAAC,OAAO,EAAQ,E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AAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;SAEK;IACG,gBAAgB,CAAE,QAAkB,EAAE,GAAwB;QACpE,MAAM,SAAS,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAA;QACvD,IAAI,OAAO,GAAG,yCAAmB,CAAC,oBAAoB,CACpD,QAAQ,CAAC,MAAM,IAAI,SAAS,IAAI,IAAI,CAAC,aAAa,IAAI,yCAAmB,CAAC,OAAO,CAAC,MAAM,CACzF,CAAA;QACD,IAAI,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;YAC/C,OAAO,GAAG,yCAAmB,CAAC,OAAO,CAAC,MAAM,CAAA;QAC9C,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AA1JD,oCA0JC"}
@@ -0,0 +1,82 @@
1
+ import { TurnContext } from '@microsoft/agents-hosting';
2
+ import { Choice, ChoiceFactoryOptions } from '../choices';
3
+ import { ListStyle, Prompt, PromptOptions, PromptRecognizerResult, PromptValidator } from './prompt';
4
+ interface ChoiceDefaultsConfirmPrompt {
5
+ [locale: string]: {
6
+ choices: (string | Choice)[];
7
+ options: ChoiceFactoryOptions;
8
+ };
9
+ }
10
+ /**
11
+ * Prompts a user to confirm something with a "yes" or "no" response.
12
+ *
13
+ * @remarks
14
+ * By default the prompt will return to the calling dialog a `boolean` representing the users
15
+ * selection.
16
+ */
17
+ export declare class ConfirmPrompt extends Prompt<boolean> {
18
+ /**
19
+ * A dictionary of Default Choices based on [[PromptCultureModels.getSupportedCultures()]].
20
+ * Can be replaced by user using the constructor that contains choiceDefaults.
21
+ * This is initially set in the constructor.
22
+ */
23
+ private choiceDefaults;
24
+ /**
25
+ * The prompts default locale that should be recognized.
26
+ */
27
+ defaultLocale: string | undefined;
28
+ /**
29
+ * Style of the "yes" and "no" choices rendered to the user when prompting.
30
+ *
31
+ * @remarks
32
+ * Defaults to `ListStyle.auto`.
33
+ */
34
+ style: ListStyle;
35
+ /**
36
+ * Additional options passed to the `ChoiceFactory` and used to tweak the style of choices
37
+ * rendered to the user.
38
+ */
39
+ choiceOptions: ChoiceFactoryOptions | undefined;
40
+ /**
41
+ * Custom list of choices to send for the prompt.
42
+ */
43
+ confirmChoices: (string | Choice)[] | undefined;
44
+ /**
45
+ * Creates a new ConfirmPrompt instance.
46
+ *
47
+ * @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
48
+ * @param validator (Optional) validator that will be called each time the user responds to the prompt.
49
+ * @param defaultLocale (Optional) locale to use if `TurnContext.activity.locale` is not specified. Defaults to a value of `en-us`.
50
+ * @param choiceDefaults (Optional) Overrides the dictionary of Default Choices on [[PromptCultureModels.getSupportedCultures()]].
51
+ */
52
+ constructor(dialogId: string, validator?: PromptValidator<boolean>, defaultLocale?: string, choiceDefaults?: ChoiceDefaultsConfirmPrompt);
53
+ /**
54
+ * Prompts the user for input.
55
+ *
56
+ * @param context TurnContext, context for the current
57
+ * turn of conversation with the user.
58
+ * @param state Contains state for the current instance of the prompt on the dialog stack.
59
+ * @param options A PromptOptions object constructed
60
+ * from the options initially provided in the call to Prompt.
61
+ * @param isRetry `true` if this is the first time this prompt dialog instance
62
+ * on the stack is prompting the user for input; otherwise, false.
63
+ * @returns A `Promise` representing the asynchronous operation.
64
+ */
65
+ protected onPrompt(context: TurnContext, state: any, options: PromptOptions, isRetry: boolean): Promise<void>;
66
+ /**
67
+ * Attempts to recognize the user's input.
68
+ *
69
+ * @param context TurnContext, context for the current
70
+ * turn of conversation with the user.
71
+ * @param _state Contains state for the current instance of the prompt on the dialog stack.
72
+ * @param _options A PromptOptions object constructed
73
+ * from the options initially provided in the call to Prompt.
74
+ * @returns A `Promise` representing the asynchronous operation.
75
+ */
76
+ protected onRecognize(context: TurnContext, _state: any, _options: PromptOptions): Promise<PromptRecognizerResult<boolean>>;
77
+ /**
78
+ * @private
79
+ */
80
+ private determineCulture;
81
+ }
82
+ export {};