@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,30 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /**
7
+ * ComponentRegistration is a signature class for discovering assets from components.
8
+ */
9
+ export class ComponentRegistration {
10
+ private static readonly _components: Map<string, ComponentRegistration> = new Map<string, ComponentRegistration>()
11
+
12
+ /**
13
+ * Gets list of all ComponentRegistration objects registered.
14
+ *
15
+ * @returns A list of ComponentRegistration objects.
16
+ */
17
+ static get components (): ComponentRegistration[] {
18
+ return Array.from(ComponentRegistration._components.values())
19
+ }
20
+
21
+ /**
22
+ * Add a component, only one instance per type is allowed for components.
23
+ *
24
+ * @param componentRegistration The component to be registered.
25
+ */
26
+ static add (componentRegistration: ComponentRegistration): void {
27
+ const name = componentRegistration.constructor.name
28
+ ComponentRegistration._components.set(name, componentRegistration)
29
+ }
30
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { Converter, ConverterFactory } from './converter'
7
+
8
+ /**
9
+ * Base class for all configurable classes.
10
+ */
11
+ export abstract class Configurable {
12
+ /**
13
+ * Fluent method for configuring the object.
14
+ *
15
+ * @param config Configuration settings to apply.
16
+ * @returns The Configurable after the operation is complete.
17
+ */
18
+ configure (config: Record<string, unknown>): this {
19
+ for (const key in config) {
20
+ if (Object.prototype.hasOwnProperty.call(config, key)) {
21
+ const setting = config[`${key}`]
22
+ const converter = this.getConverter(key)
23
+ if (converter && typeof converter === 'object') {
24
+ this[`${key}`] = converter.convert(setting)
25
+ } else {
26
+ if (Array.isArray(setting)) {
27
+ this[`${key}`] = setting
28
+ } else if (typeof setting === 'object') {
29
+ if (typeof this[`${key}`] === 'object') {
30
+ // Apply as a map update
31
+ for (const child in setting) {
32
+ if (Object.prototype.hasOwnProperty.call(setting, child)) {
33
+ this[`${key}`][`${child}`] = setting[`${child}`]
34
+ }
35
+ }
36
+ } else {
37
+ this[`${key}`] = setting
38
+ }
39
+ } else if (setting !== undefined) {
40
+ this[`${key}`] = setting
41
+ }
42
+ }
43
+ }
44
+ }
45
+ return this
46
+ }
47
+
48
+ /**
49
+ * @param _property The key of the conditional selector configuration.
50
+ * @returns The converter for the selector configuration.
51
+ */
52
+ getConverter (_property: string): Converter | ConverterFactory {
53
+ return undefined
54
+ }
55
+ }
@@ -0,0 +1,22 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ /**
5
+ * Configuration is an interface that is used to obtain configurable values
6
+ */
7
+ export interface Configuration {
8
+ get<T = unknown>(path?: string[]): T | undefined;
9
+ set(path: string[], value: unknown): void;
10
+ }
11
+
12
+ /**
13
+ * Useful for shimming Components into ComponentRegistrations
14
+ */
15
+ export const noOpConfiguration: Configuration = {
16
+ get (_path) {
17
+ return undefined
18
+ },
19
+ set (_path, _value) {
20
+ // no-op
21
+ },
22
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /**
7
+ * The converter converts object from one type to another.
8
+ */
9
+ export interface Converter<From = unknown, To = unknown> {
10
+ convert(value: From | To): To;
11
+ }
12
+
13
+ export type ConverterFactory<From = unknown, To = unknown> = {
14
+ new (...args: unknown[]): Converter<From, To>;
15
+ }
package/src/dialog.ts ADDED
@@ -0,0 +1,243 @@
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 { DialogContext } from './dialogContext'
7
+ import { Configurable } from './configurable'
8
+ import { DialogTurnResult } from './dialogTurnResult'
9
+ import { DialogEvent } from './dialogEvent'
10
+ import { DialogReason } from './dialogReason'
11
+ import { DialogInstance } from './dialogInstance'
12
+ import { DialogTurnStatus } from './dialogTurnStatus'
13
+
14
+ /**
15
+ * Defines the core behavior for all dialogs.
16
+ */
17
+ export abstract class Dialog<O extends object = {}> extends Configurable {
18
+ private _id: string
19
+
20
+ /**
21
+ * Gets a default end-of-turn result.
22
+ *
23
+ * @remarks
24
+ * This result indicates that a dialog (or a logical step within a dialog) has completed
25
+ * processing for the current turn, is still active, and is waiting for more input.
26
+ */
27
+ static EndOfTurn: DialogTurnResult = { status: DialogTurnStatus.waiting }
28
+
29
+ /**
30
+ * Creates a new instance of the Dialog class.
31
+ *
32
+ * @param dialogId Optional. unique ID of the dialog.
33
+ */
34
+ constructor (dialogId?: string) {
35
+ super()
36
+ this.id = dialogId
37
+ }
38
+
39
+ /**
40
+ * Unique ID of the dialog.
41
+ *
42
+ * @remarks
43
+ * This will be automatically generated if not specified.
44
+ * @returns The Id for the dialog.
45
+ */
46
+ get id (): string {
47
+ if (this._id === undefined) {
48
+ this._id = this.onComputeId()
49
+ }
50
+ return this._id
51
+ }
52
+
53
+ /**
54
+ * Sets the unique ID of the dialog.
55
+ */
56
+ set id (value: string) {
57
+ this._id = value
58
+ }
59
+
60
+ /**
61
+ * An encoded string used to aid in the detection of agent changes on re-deployment.
62
+ *
63
+ * @remarks
64
+ * This defaults to returning the dialogs [id](#id) but can be overridden to provide more
65
+ * precise change detection logic. Any dialog on the stack that has its version change will
66
+ * result in a `versionChanged` event will be raised. If this event is not handled by the agent,
67
+ * an error will be thrown resulting in the agent error handler logic being run.
68
+ *
69
+ * Returning an empty string will disable version tracking for the component all together.
70
+ * @returns Unique string which should only change when dialog has changed in a way that should restart the dialog.
71
+ */
72
+ getVersion (): string {
73
+ return this.id
74
+ }
75
+
76
+ /**
77
+ * When overridden in a derived class, starts the dialog.
78
+ *
79
+ * @param dc The context for the current dialog turn.
80
+ * @param options Optional. Arguments to use when the dialog starts.
81
+ *
82
+ * @remarks
83
+ * Derived dialogs must override this method.
84
+ *
85
+ * The DialogContext calls this method when it creates
86
+ * a new DialogInstance for this dialog, pushes it
87
+ * onto the dialog stack, and starts the dialog.
88
+ *
89
+ * A dialog that represents a single-turn conversation should await
90
+ * DialogContext.endDialog before exiting this method.
91
+ *
92
+ */
93
+ abstract beginDialog (dc: DialogContext, options?: O): Promise<DialogTurnResult>
94
+
95
+ /**
96
+ * When overridden in a derived class, continues the dialog.
97
+ *
98
+ * @param dc The context for the current dialog turn.
99
+ *
100
+ * @remarks
101
+ * Derived dialogs that support multiple-turn conversations should override this method.
102
+ * By default, this method signals that the dialog is complete and returns.
103
+ *
104
+ * The DialogContext calls this method when it continues
105
+ * the dialog.
106
+ *
107
+ * To signal to the dialog context that this dialog has completed, await
108
+ * DialogContext.endDialog before exiting this method.
109
+ *
110
+ * @returns {Promise<DialogTurnResult>} A promise resolving to the dialog turn result.
111
+ */
112
+ async continueDialog (dc: DialogContext): Promise<DialogTurnResult> {
113
+ // By default just end the current dialog.
114
+ return dc.endDialog()
115
+ }
116
+
117
+ /**
118
+ * When overridden in a derived class, resumes the dialog after the dialog above it on the stack completes.
119
+ *
120
+ * @param dc The context for the current dialog turn.
121
+ * @param reason The reason the dialog is resuming. This will typically be DialogReason.endCalled
122
+ * @param result Optional. The return value, if any, from the dialog that ended.
123
+ *
124
+ * @remarks
125
+ * Derived dialogs that support multiple-turn conversations should override this method.
126
+ * By default, this method signals that the dialog is complete and returns.
127
+ *
128
+ * The DialogContext calls this method when it resumes
129
+ * the dialog. If the previous dialog on the stack returned a value, that value is in the `result`
130
+ * parameter.
131
+ *
132
+ * To start a _child_ dialog, use DialogContext.beginDialog or DialogContext.prompt; however, this dialog will not
133
+ * necessarily be the one that started the child dialog.
134
+ * To signal to the dialog context that this dialog has completed, await DialogContext.endDialog before exiting this method.
135
+ *
136
+ * @returns {Promise<DialogTurnResult>} A promise resolving to the dialog turn result.
137
+ */
138
+ async resumeDialog (dc: DialogContext, reason: DialogReason, result?: any): Promise<DialogTurnResult> {
139
+ // By default just end the current dialog and return result to parent.
140
+ return dc.endDialog(result)
141
+ }
142
+
143
+ /**
144
+ * When overridden in a derived class, reprompts the user for input.
145
+ *
146
+ * @param _context The context object for the turn.
147
+ * @param _instance Current state information for this dialog.
148
+ *
149
+ * @remarks
150
+ * Derived dialogs that support validation and re-prompt logic should override this method.
151
+ * By default, this method has no effect.
152
+ *
153
+ * The DialogContext calls this method when the current
154
+ * dialog should re-request input from the user. This method is implemented for prompt dialogs.
155
+ *
156
+ */
157
+ async repromptDialog (_context: TurnContext, _instance: DialogInstance): Promise<void> {
158
+ // No-op by default
159
+ }
160
+
161
+ /**
162
+ * When overridden in a derived class, performs clean up for the dialog before it ends.
163
+ *
164
+ * @param _context The context object for the turn.
165
+ * @param _instance Current state information for this dialog.
166
+ * @param _reason The reason the dialog is ending.
167
+ *
168
+ * @remarks
169
+ * Derived dialogs that need to perform logging or cleanup before ending should override this method.
170
+ * By default, this method has no effect.
171
+ *
172
+ * The DialogContext calls this method when the current
173
+ * dialog is ending.
174
+ *
175
+ */
176
+ async endDialog (_context: TurnContext, _instance: DialogInstance, _reason: DialogReason): Promise<void> {
177
+ // No-op by default
178
+ }
179
+
180
+ /**
181
+ * Called when an event has been raised, using `DialogContext.emitEvent()`, by either the current dialog or a dialog that the current dialog started.
182
+ *
183
+ * @param dialogContext - The dialog context for the current turn of conversation.
184
+ * @param event - The event being raised.
185
+ * @returns True if the event is handled by the current dialog and bubbling should stop.
186
+ */
187
+ async onDialogEvent (dialogContext: DialogContext, event: DialogEvent): Promise<boolean> {
188
+ // Before bubble
189
+ let handled = await this.onPreBubbleEvent(dialogContext, event)
190
+
191
+ // Bubble as needed
192
+ if (!handled && event.bubble && dialogContext.parent !== undefined) {
193
+ handled = await dialogContext.parent.emitEvent(event.name, event.value, true, false)
194
+ }
195
+
196
+ // Post bubble
197
+ if (!handled) {
198
+ handled = await this.onPostBubbleEvent(dialogContext, event)
199
+ }
200
+
201
+ return handled
202
+ }
203
+
204
+ /**
205
+ * Called before an event is bubbled to its parent.
206
+ *
207
+ * @remarks
208
+ * This is a good place to perform interception of an event as returning `true` will prevent
209
+ * any further bubbling of the event to the dialogs parents and will also prevent any child
210
+ * dialogs from performing their default processing.
211
+ * @param _dc The dialog context for the current turn of conversation.
212
+ * @param _e The event being raised.
213
+ * @returns Whether the event is handled by the current dialog and further processing should stop.
214
+ */
215
+ protected async onPreBubbleEvent (_dc: DialogContext, _e: DialogEvent): Promise<boolean> {
216
+ return false
217
+ }
218
+
219
+ /**
220
+ * Called after an event was bubbled to all parents and wasn't handled.
221
+ *
222
+ * @remarks
223
+ * This is a good place to perform default processing logic for an event. Returning `true` will
224
+ * prevent any processing of the event by child dialogs.
225
+ * @param _dc The dialog context for the current turn of conversation.
226
+ * @param _e The event being raised.
227
+ * @returns Whether the event is handled by the current dialog and further processing should stop.
228
+ */
229
+ protected async onPostBubbleEvent (_dc: DialogContext, _e: DialogEvent): Promise<boolean> {
230
+ return false
231
+ }
232
+
233
+ /**
234
+ * Called when a unique ID needs to be computed for a dialog.
235
+ *
236
+ * @remarks
237
+ * SHOULD be overridden to provide a more contextually relevant ID. The preferred pattern for
238
+ * ID's is `<dialog type>(this.hashedLabel('<dialog args>'))`.
239
+ */
240
+ protected onComputeId (): string {
241
+ throw new Error('Dialog.onComputeId(): not implemented.')
242
+ }
243
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { Dialog } from './dialog'
6
+ import { DialogSet } from './dialogSet'
7
+ import { DialogContext } from './dialogContext'
8
+ import { DialogEvents } from './dialogEvents'
9
+ import { DialogEvent } from './dialogEvent'
10
+
11
+ /**
12
+ * A container for a set of Dialogs.
13
+ */
14
+ export abstract class DialogContainer<O extends object = {}> extends Dialog<O> {
15
+ /**
16
+ * The containers dialog set.
17
+ */
18
+ readonly dialogs = new DialogSet(undefined)
19
+
20
+ /**
21
+ * Creates an inner dialog context for the containers active child.
22
+ *
23
+ * @param dialogContext Parents dialog context.
24
+ * @returns A new dialog context for the active child or `undefined` if there is no active child.
25
+ */
26
+ abstract createChildContext (dialogContext: DialogContext): DialogContext | undefined
27
+
28
+ /**
29
+ * Finds a child dialog that was previously added to the container.
30
+ *
31
+ * @param dialogId ID of the dialog to lookup.
32
+ * @returns The Dialog if found; otherwise null.
33
+ */
34
+ findDialog (dialogId: string): Dialog | undefined {
35
+ return this.dialogs.find(dialogId)
36
+ }
37
+
38
+ /**
39
+ * Called when an event has been raised, using `DialogContext.emitEvent()`,
40
+ * by either the current dialog or a dialog that the current dialog started.
41
+ *
42
+ * @param dialogContext The dialog context for the current turn of conversation.
43
+ * @param event The event being raised.
44
+ * @returns True if the event is handled by the current dialog and bubbling should stop.
45
+ */
46
+ async onDialogEvent (dialogContext: DialogContext, event: DialogEvent): Promise<boolean> {
47
+ const handled = await super.onDialogEvent(dialogContext, event)
48
+ if (!handled && event.name === DialogEvents.versionChanged) {
49
+ const traceMessage = `Unhandled dialog event: ${event.name}. Active Dialog: ${dialogContext.activeDialog.id}`
50
+ await dialogContext.context.sendTraceActivity(traceMessage)
51
+ }
52
+ return handled
53
+ }
54
+
55
+ /**
56
+ * Returns internal version identifier for this container.
57
+ *
58
+ * @remarks
59
+ * DialogContainers detect changes of all sub-components in the container and map that to a `versionChanged` event.
60
+ * Because they do this, DialogContainers "hide" the internal changes and just have the .id. This isolates changes
61
+ * to the container level unless a container doesn't handle it. To support this DialogContainers define a
62
+ * protected method getInternalVersion() which computes if this dialog or child dialogs have changed
63
+ * which is then examined via calls to checkForVersionChange().
64
+ * @returns Version which represents the change of the internals of this container.
65
+ */
66
+ protected getInternalVersion (): string {
67
+ return this.dialogs.getVersion()
68
+ }
69
+
70
+ /**
71
+ * Checks to see if a containers child dialogs have changed since the current dialog instance
72
+ * was started.
73
+ *
74
+ * @remarks
75
+ * This should be called at the start of `beginDialog()`, `continueDialog()`, and `resumeDialog()`.
76
+ * @param dialogContext Current dialog context.
77
+ */
78
+ protected async checkForVersionChange (dialogContext: DialogContext): Promise<void> {
79
+ const current = dialogContext.activeDialog.version
80
+ dialogContext.activeDialog.version = this.getInternalVersion()
81
+
82
+ // Check for change of previously stored hash
83
+ if (current && current !== dialogContext.activeDialog.version) {
84
+ // Give agent an opportunity to handle the change.
85
+ // - If agent handles it the changeHash will have been updated as to avoid triggering the
86
+ // change again.
87
+ await dialogContext.emitEvent(DialogEvents.versionChanged, this.id, true, false)
88
+ }
89
+ }
90
+ }