@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,44 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { PathResolver } from './pathResolver'
6
+
7
+ export class AliasPathResolver implements PathResolver {
8
+ private readonly alias: string
9
+ private readonly prefix: string
10
+ private readonly postfix: string
11
+
12
+ /**
13
+ * Initializes a new instance of the AliasPathResolver class.
14
+ *
15
+ * @param alias Alias name.
16
+ * @param prefix Prefix name.
17
+ * @param postfix Postfix name.
18
+ */
19
+ constructor (alias: string, prefix: string, postfix?: string) {
20
+ this.alias = alias.trim()
21
+ this.prefix = prefix.trim()
22
+ this.postfix = postfix ? postfix.trim() : ''
23
+ }
24
+
25
+ /**
26
+ * Transforms the path.
27
+ *
28
+ * @param path Path to inspect.
29
+ * @returns The transformed path.
30
+ */
31
+ transformPath (path: string): string {
32
+ const start = path.indexOf(this.alias)
33
+ if (start === 0) {
34
+ // here we only deals with trailing alias, alias in middle be handled in further breakdown
35
+ // $xxx -> path.xxx
36
+ path = `${this.prefix}${path.substr(start + this.alias.length)}${this.postfix}`
37
+ if (path.endsWith('.')) {
38
+ path = path.substr(0, path.length - 1)
39
+ }
40
+ }
41
+
42
+ return path
43
+ }
44
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { AliasPathResolver } from './aliasPathResolver'
6
+
7
+ export class AtAtPathResolver extends AliasPathResolver {
8
+ /**
9
+ * Initializes a new instance of the AtAtPathResolver class.
10
+ */
11
+ constructor () {
12
+ super('@@', 'turn.recognized.entities.')
13
+ }
14
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { AliasPathResolver } from './aliasPathResolver'
6
+
7
+ export class AtPathResolver extends AliasPathResolver {
8
+ private readonly _prefix = 'turn.recognized.entities.'
9
+ private readonly _delims = ['.', '[']
10
+
11
+ /**
12
+ * Initializes a new instance of the AtPathResolver class.
13
+ */
14
+ constructor () {
15
+ super('@', '')
16
+ }
17
+
18
+ /**
19
+ * Transforms the path.
20
+ *
21
+ * @param path Path to inspect.
22
+ * @returns The transformed path.
23
+ */
24
+ transformPath (path: string): string {
25
+ path = path.trim()
26
+ if (path.startsWith('@') && path.length > 1 && !path.startsWith('@@')) {
27
+ let end = -1
28
+ for (let i = 0; i < this._delims.length; i++) {
29
+ const indexOfDelim = path.indexOf(this._delims[i])
30
+ if (indexOfDelim >= 0) {
31
+ end = indexOfDelim
32
+ break
33
+ }
34
+ }
35
+ if (end === -1) {
36
+ end = path.length
37
+ }
38
+ const property = path.substr(1, end - 1)
39
+ const suffix = path.substr(end)
40
+ path = `${this._prefix}${property}.first()${suffix}`
41
+ }
42
+
43
+ return path
44
+ }
45
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { AliasPathResolver } from './aliasPathResolver'
6
+
7
+ export class DollarPathResolver extends AliasPathResolver {
8
+ /**
9
+ * Initializes a new instance of the DollarPathResolver class.
10
+ */
11
+ constructor () {
12
+ super('$', 'dialog.')
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { AliasPathResolver } from './aliasPathResolver'
6
+
7
+ export class HashPathResolver extends AliasPathResolver {
8
+ /**
9
+ * Initializes a new instance of the HashPathResolver class.
10
+ */
11
+ constructor () {
12
+ super('#', 'turn.recognized.intents.')
13
+ }
14
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export * from './aliasPathResolver'
6
+ export * from './atAtPathResolver'
7
+ export * from './atPathResolver'
8
+ export * from './dollarPathResolver'
9
+ export * from './hashPathResolver'
10
+ export * from './pathResolver'
11
+ export * from './percentPathResolver'
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ export interface PathResolver {
7
+ /**
8
+ * Transform the path
9
+ *
10
+ * @param path Path to inspect.
11
+ * @returns Transformed path
12
+ */
13
+ transformPath(path: string): string;
14
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { AliasPathResolver } from './aliasPathResolver'
6
+
7
+ export class PercentPathResolver extends AliasPathResolver {
8
+ /**
9
+ * Initializes a new instance of the PercentPathResolver class.
10
+ */
11
+ constructor () {
12
+ super('%', 'class.')
13
+ }
14
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /**
7
+ * Defines paths for the available scopes.
8
+ */
9
+ export class ScopePath {
10
+ static readonly user = 'user'
11
+ static readonly conversation = 'conversation'
12
+ static readonly dialog = 'dialog'
13
+ static readonly dialogClass = 'dialogClass'
14
+ static readonly dialogContext = 'dialogContext'
15
+ static readonly this = 'this'
16
+ static readonly class = 'class'
17
+ static readonly settings = 'settings'
18
+ static readonly turn = 'turn'
19
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { AgentState } from '@microsoft/agents-hosting'
6
+ import { MemoryScope } from './memoryScope'
7
+ import { DialogContext } from '../../dialogContext'
8
+
9
+ /**
10
+ * Base class for memory scopes based on AgentState.
11
+ */
12
+ export class AgentStateMemoryScope extends MemoryScope {
13
+ protected stateKey: string
14
+
15
+ /**
16
+ * Initializes a new instance of the AgentStateMemoryScope class.
17
+ *
18
+ * @param name name of the property.
19
+ */
20
+ constructor (name: string) {
21
+ super(name, true)
22
+ }
23
+
24
+ /**
25
+ * Get the backing memory for this scope.
26
+ *
27
+ * @param dialogContext current dialog context.
28
+ * @returns Memory for the scope.
29
+ */
30
+ getMemory (dialogContext: DialogContext): object {
31
+ const agentState: AgentState = dialogContext.context.turnState.get(this.stateKey)
32
+ if (agentState) {
33
+ return agentState.get(dialogContext.context)
34
+ }
35
+
36
+ return undefined
37
+ }
38
+
39
+ /**
40
+ * Changes the backing object for the memory scope.
41
+ *
42
+ * @param dialogContext current dialog context
43
+ * @param _memory memory
44
+ */
45
+ setMemory (dialogContext: DialogContext, _memory: object): void {
46
+ const agentState = dialogContext.context.turnState.get(this.stateKey)
47
+ if (!agentState) {
48
+ throw new Error(`${this.stateKey} is not available.`)
49
+ }
50
+ throw new Error('You cannot replace the root AgentState object.')
51
+ }
52
+
53
+ /**
54
+ * Populates the state cache for this AgentState from the storage layer.
55
+ *
56
+ * @param dialogContext The DialogContext object for this turn.
57
+ * @param force Optional, `true` to overwrite any existing state cache;
58
+ * or `false` to load state from storage only if the cache doesn't already exist.
59
+ * @returns A Promise that represents the work queued to execute.
60
+ */
61
+ async load (dialogContext: DialogContext, force = false): Promise<void> {
62
+ const agentState: AgentState = dialogContext.context.turnState.get(this.stateKey)
63
+ if (agentState) {
64
+ await agentState.load(dialogContext.context, force)
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Writes the state cache for this AgentState to the storage layer.
70
+ *
71
+ * @param dialogContext The DialogContext object for this turn.
72
+ * @param force Optional, `true` to save the state cache to storage;
73
+ * or `false` to save state to storage only if a property in the cache has changed.
74
+ * @returns A Promise that represents the work queued to execute.
75
+ */
76
+ async saveChanges (dialogContext: DialogContext, force = false): Promise<void> {
77
+ const agentState: AgentState = dialogContext.context.turnState.get(this.stateKey)
78
+ if (agentState) {
79
+ await agentState.saveChanges(dialogContext.context, force)
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Deletes any state in storage and the cache for this AgentState.
85
+ *
86
+ * @param _dialogContext The DialogContext object for this turn.
87
+ * @returns A Promise that represents the work queued to execute.
88
+ */
89
+ async delete (_dialogContext: DialogContext): Promise<void> {
90
+ return Promise.resolve()
91
+ }
92
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { MemoryScope } from './memoryScope'
6
+ import { ScopePath } from '../scopePath'
7
+ import { DialogContext } from '../../dialogContext'
8
+ import { Dialog } from '../../dialog'
9
+
10
+ export class ClassMemoryScope extends MemoryScope {
11
+ /**
12
+ * Initializes a new instance of the ClassMemoryScope class.
13
+ *
14
+ * @param name Name of the scope class.
15
+ */
16
+ constructor (name = ScopePath.class) {
17
+ super(name, false)
18
+ }
19
+
20
+ /**
21
+ * Gets the backing memory for this scope.
22
+ *
23
+ * @param dialogContext The DialogContext object for this turn.
24
+ * @returns The memory for the scope.
25
+ */
26
+ getMemory (dialogContext: DialogContext): object {
27
+ // if active dialog is a container dialog then "dialog" binds to it
28
+ if (dialogContext.activeDialog) {
29
+ const dialog = this.onFindDialog(dialogContext)
30
+ if (dialog !== undefined) {
31
+ // Clone properties
32
+ const clone: object = {}
33
+ for (const key in dialog) {
34
+ const prop = dialog[key]
35
+ if (Object.prototype.hasOwnProperty.call(dialog, key) && typeof prop !== 'function') {
36
+ if (isExpression(prop)) {
37
+ const { value, error } = prop.tryGetValue(dialogContext.state)
38
+ if (!error) {
39
+ clone[key] = value
40
+ }
41
+ } else {
42
+ clone[key] = prop
43
+ }
44
+ }
45
+ }
46
+
47
+ return clone
48
+ }
49
+ }
50
+
51
+ return {}
52
+ }
53
+
54
+ /**
55
+ * Override to find the dialog instance referenced by the scope.
56
+ *
57
+ * @param dialogContext Current dialog context.
58
+ * @returns The dialog instance referenced by the scope.
59
+ */
60
+ protected onFindDialog (dialogContext: DialogContext): Dialog | undefined {
61
+ return dialogContext.findDialog(dialogContext.activeDialog.id)
62
+ }
63
+ }
64
+
65
+ function isExpression (prop: any): prop is ExpressionResolver {
66
+ return typeof prop === 'object' && typeof prop['tryGetValue'] === 'function'
67
+ }
68
+
69
+ interface ExpressionResolver {
70
+ tryGetValue(data: object): { value: any; error: Error };
71
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { AgentStateMemoryScope } from './agentStateMemoryScope'
6
+ import { ScopePath } from '../scopePath'
7
+
8
+ /**
9
+ * Memory that's scoped to the current conversation.
10
+ */
11
+ export class ConversationMemoryScope extends AgentStateMemoryScope {
12
+ protected stateKey = 'ConversationState'
13
+ /**
14
+ * Initializes a new instance of the ConversationMemoryScope class.
15
+ */
16
+ constructor () {
17
+ super(ScopePath.conversation)
18
+ }
19
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { ClassMemoryScope } from './classMemoryScope'
6
+ import { ScopePath } from '../scopePath'
7
+ import { DialogContext } from '../../dialogContext'
8
+ import { Dialog } from '../../dialog'
9
+ import { DialogContainer } from '../../dialogContainer'
10
+
11
+ export class DialogClassMemoryScope extends ClassMemoryScope {
12
+ /**
13
+ * Initializes a new instance of the DialogClassMemoryScope class.
14
+ */
15
+ constructor () {
16
+ super(ScopePath.dialogClass)
17
+ }
18
+
19
+ /**
20
+ * @protected
21
+ * @param dialogContext The DialogContext object for this turn.
22
+ * @returns The current Dialog.
23
+ */
24
+ protected onFindDialog (dialogContext: DialogContext): Dialog | undefined {
25
+ // Is the active dialog a container?
26
+ const dialog = dialogContext.findDialog(dialogContext.activeDialog.id)
27
+ if (dialog && dialog instanceof DialogContainer) {
28
+ return dialog
29
+ }
30
+
31
+ // Return parent dialog if there is one?
32
+ const parent = dialogContext.parent
33
+ if (parent && parent.activeDialog) {
34
+ const parentDialog = parent.findDialog(parent.activeDialog.id)
35
+ if (parentDialog) {
36
+ return parentDialog
37
+ }
38
+ }
39
+
40
+ // Fallback to returning current dialog
41
+ return dialog
42
+ }
43
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { DialogContext } from '../../dialogContext'
7
+ import { MemoryScope } from './memoryScope'
8
+ import { ScopePath } from '../scopePath'
9
+
10
+ export class DialogContextMemoryScope extends MemoryScope {
11
+ /**
12
+ * Initializes a new instance of the `DialogContextMemoryScope` class.
13
+ */
14
+ constructor () {
15
+ super(ScopePath.dialogContext, false)
16
+ }
17
+
18
+ /**
19
+ * Gets the backing memory for this scope.
20
+ *
21
+ * @param dialogContext The `DialogContext` object for this turn.
22
+ * @returns Memory for the scope.
23
+ */
24
+ getMemory (dialogContext: DialogContext): Record<'stack' | 'activeDialog' | 'parent', unknown> {
25
+ const stack = []
26
+ let currentDialogContext: DialogContext | undefined = dialogContext
27
+
28
+ // go to leaf node
29
+ while (currentDialogContext.child) {
30
+ currentDialogContext = currentDialogContext.child
31
+ }
32
+
33
+ while (currentDialogContext) {
34
+ for (let i = currentDialogContext.stack.length - 1; i >= 0; i--) {
35
+ const item = currentDialogContext.stack[i]
36
+ // filter out ActionScope items because they are internal bookkeeping.
37
+ if (!item.id.startsWith('ActionScope[')) {
38
+ stack.push(item.id)
39
+ }
40
+ }
41
+
42
+ currentDialogContext = currentDialogContext.parent
43
+ }
44
+
45
+ return {
46
+ stack,
47
+ activeDialog: dialogContext.activeDialog && dialogContext.activeDialog.id,
48
+ parent: dialogContext.parent && dialogContext.parent.activeDialog && dialogContext.parent.activeDialog.id,
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { MemoryScope } from './memoryScope'
6
+ import { ScopePath } from '../scopePath'
7
+ import { DialogContext } from '../../dialogContext'
8
+ import { DialogContainer } from '../../dialogContainer'
9
+
10
+ export class DialogMemoryScope extends MemoryScope {
11
+ /**
12
+ * Initializes a new instance of the DialogMemoryScope class.
13
+ */
14
+ constructor () {
15
+ super(ScopePath.dialog)
16
+ }
17
+
18
+ /**
19
+ * Gets the backing memory for this scope.
20
+ *
21
+ * @param dialogContext The DialogContext object for this turn.
22
+ * @returns The memory for the scope.
23
+ */
24
+ getMemory (dialogContext: DialogContext): object {
25
+ // If active dialog is a container dialog then "dialog" binds to it.
26
+ // Otherwise the "dialog" will bind to the dialogs parent assuming it
27
+ // is a container.
28
+ let parent: DialogContext = dialogContext
29
+ if (!this.isContainer(parent) && parent.parent && this.isContainer(parent.parent)) {
30
+ parent = parent.parent
31
+ }
32
+
33
+ // If there's no active dialog then return undefined.
34
+ return parent.activeDialog ? parent.activeDialog.state : {}
35
+ }
36
+
37
+ /**
38
+ * Changes the backing object for the memory scope.
39
+ *
40
+ * @param dialogContext The DialogContext object for this turn.
41
+ * @param memory Memory object to set for the scope.
42
+ */
43
+ setMemory (dialogContext: DialogContext, memory: object): void {
44
+ if (memory === undefined) {
45
+ throw new Error('DialogMemoryScope.setMemory: undefined memory object passed in.')
46
+ }
47
+
48
+ // If active dialog is a container dialog then "dialog" binds to it.
49
+ // Otherwise the "dialog" will bind to the dialogs parent assuming it
50
+ // is a container.
51
+ let parent: DialogContext = dialogContext
52
+ if (!this.isContainer(parent) && parent.parent && this.isContainer(parent.parent)) {
53
+ parent = parent.parent
54
+ }
55
+
56
+ // If there's no active dialog then throw an error.
57
+ if (!parent.activeDialog) {
58
+ throw new Error('DialogMemoryScope.setMemory: no active dialog found.')
59
+ }
60
+
61
+ parent.activeDialog.state = memory
62
+ }
63
+
64
+ /**
65
+ * @private
66
+ * @param dialogContext The DialogContext object for this turn.
67
+ * @returns A boolean indicating whether is a cointainer or not.
68
+ */
69
+ private isContainer (dialogContext: DialogContext): boolean {
70
+ if (dialogContext !== undefined && dialogContext.activeDialog !== undefined) {
71
+ const dialog = dialogContext.findDialog(dialogContext.activeDialog.id)
72
+ if (dialog instanceof DialogContainer) {
73
+ return true
74
+ }
75
+ }
76
+
77
+ return false
78
+ }
79
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export * from './agentStateMemoryScope'
6
+ export * from './classMemoryScope'
7
+ export * from './conversationMemoryScope'
8
+ export * from './dialogClassMemoryScope'
9
+ export * from './dialogContextMemoryScope'
10
+ export * from './dialogMemoryScope'
11
+ export * from './memoryScope'
12
+ export * from './settingsMemoryScope'
13
+ export * from './thisMemoryScope'
14
+ export * from './turnMemoryScope'
15
+ export * from './userMemoryScope'
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { DialogContext } from '../../dialogContext'
6
+
7
+ /**
8
+ * Abstract base class for all memory scopes.
9
+ */
10
+ export abstract class MemoryScope {
11
+ /**
12
+ * Initializes a new instance of the MemoryScope class.
13
+ *
14
+ * @param name Name of the scope.
15
+ * @param includeInSnapshot Boolean value indicating whether this memory
16
+ * should be included in snapshot. Default value is true.
17
+ */
18
+ constructor (name: string, includeInSnapshot = true) {
19
+ this.includeInSnapshot = includeInSnapshot
20
+ this.name = name
21
+ }
22
+
23
+ readonly name: string
24
+ readonly includeInSnapshot: boolean
25
+
26
+ /**
27
+ * Get the backing memory for this scope
28
+ *
29
+ * @param dialogContext Current dialog context.
30
+ * @returns memory for the scope
31
+ */
32
+ abstract getMemory (dialogContext: DialogContext): object
33
+
34
+ /**
35
+ * Changes the backing object for the memory scope.
36
+ *
37
+ * @param _dialogContext Current dialog context
38
+ * @param _memory memory to assign
39
+ */
40
+ setMemory (_dialogContext: DialogContext, _memory: object): void {
41
+ throw new Error(`MemoryScope.setMemory: The '${this.name}' memory scope is read-only.`)
42
+ }
43
+
44
+ /**
45
+ * Loads a scopes backing memory at the start of a turn.
46
+ *
47
+ * @param _dialogContext Current dialog context.
48
+ */
49
+ async load (_dialogContext: DialogContext): Promise<void> {
50
+ // No initialization by default.
51
+ }
52
+
53
+ /**
54
+ * Saves a scopes backing memory at the end of a turn.
55
+ *
56
+ * @param _dialogContext Current dialog context.
57
+ */
58
+ async saveChanges (_dialogContext: DialogContext): Promise<void> {
59
+ // No initialization by default.
60
+ }
61
+
62
+ /**
63
+ * Deletes the backing memory for a scope.
64
+ *
65
+ * @param _dialogContext Current dialog context.
66
+ */
67
+ async delete (_dialogContext: DialogContext): Promise<void> {
68
+ throw new Error(`MemoryScope.delete: The '${this.name}' memory scope can't be deleted.`)
69
+ }
70
+ }