@microsoft/agents-hosting-dialogs 1.1.4-g8d884129e7 → 1.2.0-alpha.18.g3c104e426a

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 (68) hide show
  1. package/dist/src/agentStateSet.js +3 -1
  2. package/dist/src/agentStateSet.js.map +1 -1
  3. package/dist/src/choices/choiceFactory.d.ts +42 -1
  4. package/dist/src/choices/choiceFactory.js +128 -4
  5. package/dist/src/choices/choiceFactory.js.map +1 -1
  6. package/dist/src/dialog.js +3 -1
  7. package/dist/src/dialog.js.map +1 -1
  8. package/dist/src/dialogContextError.js +4 -2
  9. package/dist/src/dialogContextError.js.map +1 -1
  10. package/dist/src/dialogHelper.js +6 -5
  11. package/dist/src/dialogHelper.js.map +1 -1
  12. package/dist/src/dialogManager.js +4 -2
  13. package/dist/src/dialogManager.js.map +1 -1
  14. package/dist/src/dialogSet.js +4 -2
  15. package/dist/src/dialogSet.js.map +1 -1
  16. package/dist/src/errorHelper.d.ts +19 -0
  17. package/dist/src/errorHelper.js +236 -0
  18. package/dist/src/errorHelper.js.map +1 -0
  19. package/dist/src/index.d.ts +1 -0
  20. package/dist/src/index.js +3 -1
  21. package/dist/src/index.js.map +1 -1
  22. package/dist/src/memory/dialogStateManager.js +10 -8
  23. package/dist/src/memory/dialogStateManager.js.map +1 -1
  24. package/dist/src/memory/scopes/agentStateMemoryScope.js +4 -2
  25. package/dist/src/memory/scopes/agentStateMemoryScope.js.map +1 -1
  26. package/dist/src/memory/scopes/dialogMemoryScope.js +4 -2
  27. package/dist/src/memory/scopes/dialogMemoryScope.js.map +1 -1
  28. package/dist/src/memory/scopes/memoryScope.js +4 -2
  29. package/dist/src/memory/scopes/memoryScope.js.map +1 -1
  30. package/dist/src/memory/scopes/thisMemoryScope.js +4 -2
  31. package/dist/src/memory/scopes/thisMemoryScope.js.map +1 -1
  32. package/dist/src/memory/scopes/turnMemoryScope.js +3 -1
  33. package/dist/src/memory/scopes/turnMemoryScope.js.map +1 -1
  34. package/dist/src/prompts/choicePrompt.js +4 -2
  35. package/dist/src/prompts/choicePrompt.js.map +1 -1
  36. package/dist/src/prompts/confirmPrompt.js +4 -2
  37. package/dist/src/prompts/confirmPrompt.js.map +1 -1
  38. package/dist/src/prompts/prompt.d.ts +2 -1
  39. package/dist/src/prompts/prompt.js +9 -2
  40. package/dist/src/prompts/prompt.js.map +1 -1
  41. package/dist/src/recognizer.js +7 -1
  42. package/dist/src/recognizer.js.map +1 -1
  43. package/dist/src/recognizerResult.js +3 -1
  44. package/dist/src/recognizerResult.js.map +1 -1
  45. package/dist/src/waterfallDialog.js +2 -1
  46. package/dist/src/waterfallDialog.js.map +1 -1
  47. package/package.json +3 -3
  48. package/src/agentStateSet.ts +6 -1
  49. package/src/choices/choiceFactory.ts +151 -4
  50. package/src/dialog.ts +6 -1
  51. package/src/dialogContextError.ts +10 -2
  52. package/src/dialogHelper.ts +18 -5
  53. package/src/dialogManager.ts +10 -2
  54. package/src/dialogSet.ts +9 -3
  55. package/src/errorHelper.ts +263 -0
  56. package/src/index.ts +1 -0
  57. package/src/memory/dialogStateManager.ts +46 -10
  58. package/src/memory/scopes/agentStateMemoryScope.ts +12 -2
  59. package/src/memory/scopes/dialogMemoryScope.ts +12 -2
  60. package/src/memory/scopes/memoryScope.ts +14 -2
  61. package/src/memory/scopes/thisMemoryScope.ts +12 -2
  62. package/src/memory/scopes/turnMemoryScope.ts +8 -1
  63. package/src/prompts/choicePrompt.ts +3 -2
  64. package/src/prompts/confirmPrompt.ts +3 -2
  65. package/src/prompts/prompt.ts +12 -2
  66. package/src/recognizer.ts +6 -2
  67. package/src/recognizerResult.ts +6 -1
  68. package/src/waterfallDialog.ts +7 -3
@@ -0,0 +1,263 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ import { AgentErrorDefinition } from '@microsoft/agents-activity'
5
+
6
+ /**
7
+ * Error definitions for the Dialogs system.
8
+ * This contains localized error codes for the Dialogs subsystem of the AgentSDK.
9
+ *
10
+ * Each error definition includes an error code (starting from -130000), a description, and a help link
11
+ * pointing to an AKA link to get help for the given error.
12
+ *
13
+ * Usage example:
14
+ * ```
15
+ * throw ExceptionHelper.generateException(
16
+ * Error,
17
+ * Errors.MissingDialog
18
+ * );
19
+ * ```
20
+ */
21
+ export const Errors: { [key: string]: AgentErrorDefinition } = {
22
+ // Dialog Helper Errors (-130000 to -130003)
23
+ /**
24
+ * Error thrown when dialog parameter is missing.
25
+ */
26
+ MissingDialog: {
27
+ code: -130000,
28
+ description: 'runDialog(): missing dialog'
29
+ },
30
+
31
+ /**
32
+ * Error thrown when context parameter is missing.
33
+ */
34
+ MissingContext: {
35
+ code: -130001,
36
+ description: 'runDialog(): missing context'
37
+ },
38
+
39
+ /**
40
+ * Error thrown when context.activity is missing.
41
+ */
42
+ MissingContextActivity: {
43
+ code: -130002,
44
+ description: 'runDialog(): missing context.activity'
45
+ },
46
+
47
+ /**
48
+ * Error thrown when accessor parameter is missing.
49
+ */
50
+ MissingAccessor: {
51
+ code: -130003,
52
+ description: 'runDialog(): missing accessor'
53
+ },
54
+
55
+ // Dialog Manager Errors (-130004 to -130005)
56
+ /**
57
+ * Error thrown when root dialog has not been configured.
58
+ */
59
+ RootDialogNotConfigured: {
60
+ code: -130004,
61
+ description: "DialogManager.onTurn: the agent's 'rootDialog' has not been configured.",
62
+ },
63
+
64
+ /**
65
+ * Error thrown when conversationState has not been configured.
66
+ */
67
+ ConversationStateNotConfigured: {
68
+ code: -130005,
69
+ description: "DialogManager.onTurn: the agent's 'conversationState' has not been configured.",
70
+ },
71
+
72
+ // Recognizer Errors (-130006 to -130007)
73
+ /**
74
+ * Error thrown when recognizer result is empty.
75
+ */
76
+ EmptyRecognizerResult: {
77
+ code: -130006,
78
+ description: 'result is empty'
79
+ },
80
+
81
+ /**
82
+ * Error thrown when recognize function is not implemented.
83
+ */
84
+ RecognizeFunctionNotImplemented: {
85
+ code: -130007,
86
+ description: 'Please implement recognize function.'
87
+ },
88
+
89
+ // Dialog State Manager Errors (-130008 to -130013)
90
+ /**
91
+ * Error thrown when path is not specified in setValue.
92
+ */
93
+ PathNotSpecified: {
94
+ code: -130008,
95
+ description: "DialogStateManager.setValue: path wasn't specified.",
96
+ },
97
+
98
+ /**
99
+ * Error thrown when memory scope is not found in setValue.
100
+ */
101
+ ScopeNotFound: {
102
+ code: -130009,
103
+ description: "DialogStateManager.setValue: a scope of '{scope}' wasn't found.",
104
+ },
105
+
106
+ /**
107
+ * Error thrown when unable to update value with negative index.
108
+ */
109
+ NegativeIndexNotAllowed: {
110
+ code: -130010,
111
+ description: "DialogStateManager.setValue: unable to update value for '{path}'. Negative indexes aren't allowed.",
112
+ },
113
+
114
+ /**
115
+ * Error thrown when unable to update value for path.
116
+ */
117
+ UnableToUpdateValue: {
118
+ code: -130011,
119
+ description: "DialogStateManager.setValue: unable to update value for '{path}'.",
120
+ },
121
+
122
+ /**
123
+ * Error thrown when invalid path in deleteValue.
124
+ */
125
+ InvalidDeletePath: {
126
+ code: -130012,
127
+ description: "DialogStateManager.deleteValue: invalid path of '{path}'.",
128
+ },
129
+
130
+ /**
131
+ * Error thrown when scope not found in deleteValue.
132
+ */
133
+ ScopeNotFoundForDelete: {
134
+ code: -130013,
135
+ description: "DialogStateManager.deleteValue: a scope of '{scope}' wasn't found.",
136
+ },
137
+
138
+ /**
139
+ * Error thrown when path contains invalid characters.
140
+ */
141
+ InvalidPathCharacters: {
142
+ code: -130014,
143
+ description: "DialogStateManager: path '{path}' contains invalid characters.",
144
+ },
145
+
146
+ /**
147
+ * Error thrown when path resolution fails.
148
+ */
149
+ PathResolutionFailed: {
150
+ code: -130015,
151
+ description: "DialogStateManager: unable to resolve path '{path}'.",
152
+ },
153
+
154
+ // Dialog Set Errors (-130016 to -130017)
155
+ /**
156
+ * Error thrown when invalid dialog is being added to DialogSet.
157
+ */
158
+ InvalidDialogBeingAdded: {
159
+ code: -130016,
160
+ description: 'DialogSet.add(): Invalid dialog being added.'
161
+ },
162
+
163
+ /**
164
+ * Error thrown when DialogSet was not bound to a stateProperty.
165
+ */
166
+ DialogSetNotBound: {
167
+ code: -130017,
168
+ description: 'DialogSet.createContext(): the dialog set was not bound to a stateProperty when constructed.'
169
+ },
170
+
171
+ // Dialog Context Error Errors (-130018 to -130019)
172
+ /**
173
+ * Error thrown when error argument is not an Error or string.
174
+ */
175
+ InvalidErrorArgument: {
176
+ code: -130018,
177
+ description: '`error` argument must be an Error or a string'
178
+ },
179
+
180
+ /**
181
+ * Error thrown when dialogContext argument is not of type DialogContext.
182
+ */
183
+ InvalidDialogContextArgument: {
184
+ code: -130019,
185
+ description: '`dialogContext` argument must be of type DialogContext'
186
+ },
187
+
188
+ // Dialog Errors (-130020)
189
+ /**
190
+ * Error thrown when onComputeId is not implemented.
191
+ */
192
+ OnComputeIdNotImplemented: {
193
+ code: -130020,
194
+ description: 'Dialog.onComputeId(): not implemented.'
195
+ },
196
+
197
+ // Agent State Set Errors (-130021)
198
+ /**
199
+ * Error thrown when non-AgentState object is added to AgentStateSet.
200
+ */
201
+ InvalidAgentStateObject: {
202
+ code: -130021,
203
+ description: "AgentStateSet: a object was added that isn't an instance of AgentStateSet.",
204
+ },
205
+
206
+ // Memory Scope Errors (-130022 to -130029)
207
+ /**
208
+ * Error thrown when state key is not available in memory scope.
209
+ */
210
+ StateKeyNotAvailable: {
211
+ code: -130022,
212
+ description: '{stateKey} is not available.'
213
+ },
214
+
215
+ /**
216
+ * Error thrown when attempting to replace root AgentState object.
217
+ */
218
+ CannotReplaceRootAgentState: {
219
+ code: -130023,
220
+ description: 'You cannot replace the root AgentState object.'
221
+ },
222
+
223
+ /**
224
+ * Error thrown when undefined memory object passed to setMemory.
225
+ */
226
+ UndefinedMemoryObject: {
227
+ code: -130024,
228
+ description: '{scopeName}.setMemory: undefined memory object passed in.'
229
+ },
230
+
231
+ /**
232
+ * Error thrown when activeDialog is undefined.
233
+ */
234
+ ActiveDialogUndefined: {
235
+ code: -130025,
236
+ description: 'DialogMemoryScope: activeDialog is undefined.'
237
+ },
238
+
239
+ /**
240
+ * Error thrown when memory scope operation is not supported.
241
+ */
242
+ MemoryScopeOperationNotSupported: {
243
+ code: -130026,
244
+ description: '{scopeName}: {operation} is not supported.'
245
+ },
246
+
247
+ /**
248
+ * Error thrown when attempting unsupported memory scope operation.
249
+ */
250
+ UnsupportedMemoryScopeOperation: {
251
+ code: -130027,
252
+ description: 'MemoryScope.{operation}(): operation not supported for this scope.'
253
+ },
254
+
255
+ // Waterfall Dialog Errors (-130028)
256
+ /**
257
+ * Error thrown when waterfall step error occurs.
258
+ */
259
+ WaterfallStepError: {
260
+ code: -130028,
261
+ description: 'WaterfallDialog: error in step {stepIndex}.'
262
+ }
263
+ }
package/src/index.ts CHANGED
@@ -32,6 +32,7 @@ export { Configuration } from './configuration'
32
32
  export * from './intentScore'
33
33
 
34
34
  export { runDialog } from './dialogHelper'
35
+ export { Errors as DialogErrors } from './errorHelper'
35
36
 
36
37
  // Type-only re-export to avoid TypeDoc issues
37
38
  export type { TurnContext } from '@microsoft/agents-hosting'
@@ -6,6 +6,8 @@
6
6
  import { ComponentMemoryScopes, isComponentMemoryScopes } from './componentMemoryScopes'
7
7
  import { ComponentPathResolvers, isComponentPathResolvers } from './componentPathResolvers'
8
8
  import { ComponentRegistration } from '../componentRegistration'
9
+ import { ExceptionHelper } from '@microsoft/agents-activity'
10
+ import { Errors } from '../errorHelper'
9
11
  import { DialogContext } from '../dialogContext'
10
12
  import { DialogPath } from './dialogPath'
11
13
  import { DialogsComponentRegistration } from '../dialogsComponentRegistration'
@@ -176,7 +178,10 @@ export class DialogStateManager {
176
178
  const tpath = this.transformPath(pathExpression)
177
179
  const segments = this.parsePath(tpath)
178
180
  if (segments.length < 1) {
179
- throw new Error("DialogStateManager.setValue: path wasn't specified.")
181
+ throw ExceptionHelper.generateException(
182
+ Error,
183
+ Errors.PathNotSpecified
184
+ )
180
185
  }
181
186
 
182
187
  // Track changes
@@ -185,7 +190,12 @@ export class DialogStateManager {
185
190
  // Get memory scope to update
186
191
  const scope = this.getMemoryScope(segments[0].toString())
187
192
  if (scope === undefined) {
188
- throw new Error(`DialogStateManager.setValue: a scope of '${segments[0]}' wasn't found.`)
193
+ throw ExceptionHelper.generateException(
194
+ Error,
195
+ Errors.ScopeNotFound,
196
+ undefined,
197
+ { scope: segments[0].toString() }
198
+ )
189
199
  }
190
200
 
191
201
  // Update memory
@@ -203,8 +213,11 @@ export class DialogStateManager {
203
213
  if (typeof key === 'number' && Array.isArray(memory)) {
204
214
  // Only allow positive indexes
205
215
  if (key < 0) {
206
- throw new Error(
207
- `DialogStateManager.setValue: unable to update value for '${pathExpression}'. Negative indexes aren't allowed.`
216
+ throw ExceptionHelper.generateException(
217
+ Error,
218
+ Errors.NegativeIndexNotAllowed,
219
+ undefined,
220
+ { path: pathExpression }
208
221
  )
209
222
  }
210
223
 
@@ -224,7 +237,12 @@ export class DialogStateManager {
224
237
  key = this.findObjectKey(memory, key) || key
225
238
  memory[key] = value
226
239
  } else {
227
- throw new Error(`DialogStateManager.setValue: unable to update value for '${pathExpression}'.`)
240
+ throw ExceptionHelper.generateException(
241
+ Error,
242
+ Errors.UnableToUpdateValue,
243
+ undefined,
244
+ { path: pathExpression }
245
+ )
228
246
  }
229
247
  } else {
230
248
  // Just update memory scope
@@ -242,7 +260,12 @@ export class DialogStateManager {
242
260
  const tpath = this.transformPath(pathExpression)
243
261
  const segments = this.parsePath(tpath)
244
262
  if (segments.length < 2) {
245
- throw new Error(`DialogStateManager.deleteValue: invalid path of '${pathExpression}'.`)
263
+ throw ExceptionHelper.generateException(
264
+ Error,
265
+ Errors.InvalidDeletePath,
266
+ undefined,
267
+ { path: pathExpression }
268
+ )
246
269
  }
247
270
 
248
271
  // Track change
@@ -251,7 +274,12 @@ export class DialogStateManager {
251
274
  // Get memory scope to update
252
275
  const scope = this.getMemoryScope(segments[0].toString())
253
276
  if (scope === undefined) {
254
- throw new Error(`DialogStateManager.deleteValue: a scope of '${segments[0]}' wasn't found.`)
277
+ throw ExceptionHelper.generateException(
278
+ Error,
279
+ Errors.ScopeNotFoundForDelete,
280
+ undefined,
281
+ { scope: segments[0].toString() }
282
+ )
255
283
  }
256
284
 
257
285
  // Find value up to last key
@@ -422,8 +450,11 @@ export class DialogStateManager {
422
450
  } else if (isValidPathChar(c)) {
423
451
  segment += c
424
452
  } else {
425
- throw new Error(
426
- `DialogStateManager.normalizePath: Invalid path detected - ${pathExpression}`
453
+ throw ExceptionHelper.generateException(
454
+ Error,
455
+ Errors.InvalidPathCharacters,
456
+ undefined,
457
+ { path: pathExpression }
427
458
  )
428
459
  }
429
460
  break
@@ -431,7 +462,12 @@ export class DialogStateManager {
431
462
  }
432
463
  }
433
464
  if (depth > 0) {
434
- throw new Error(`DialogStateManager.normalizePath: Invalid path detected - ${pathExpression}`)
465
+ throw ExceptionHelper.generateException(
466
+ Error,
467
+ Errors.InvalidPathCharacters,
468
+ undefined,
469
+ { path: pathExpression }
470
+ )
435
471
  } else if (segment.length > 0) {
436
472
  output.push(segment)
437
473
  }
@@ -3,6 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { AgentState } from '@microsoft/agents-hosting'
6
+ import { ExceptionHelper } from '@microsoft/agents-activity'
7
+ import { Errors } from '../../errorHelper'
6
8
  import { MemoryScope } from './memoryScope'
7
9
  import { DialogContext } from '../../dialogContext'
8
10
 
@@ -45,9 +47,17 @@ export class AgentStateMemoryScope extends MemoryScope {
45
47
  setMemory (dialogContext: DialogContext, _memory: object): void {
46
48
  const agentState = dialogContext.context.turnState.get(this.stateKey)
47
49
  if (!agentState) {
48
- throw new Error(`${this.stateKey} is not available.`)
50
+ throw ExceptionHelper.generateException(
51
+ Error,
52
+ Errors.StateKeyNotAvailable,
53
+ undefined,
54
+ { stateKey: this.stateKey }
55
+ )
49
56
  }
50
- throw new Error('You cannot replace the root AgentState object.')
57
+ throw ExceptionHelper.generateException(
58
+ Error,
59
+ Errors.CannotReplaceRootAgentState
60
+ )
51
61
  }
52
62
 
53
63
  /**
@@ -3,6 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { MemoryScope } from './memoryScope'
6
+ import { ExceptionHelper } from '@microsoft/agents-activity'
7
+ import { Errors } from '../../errorHelper'
6
8
  import { ScopePath } from '../scopePath'
7
9
  import { DialogContext } from '../../dialogContext'
8
10
  import { DialogContainer } from '../../dialogContainer'
@@ -47,7 +49,12 @@ export class DialogMemoryScope extends MemoryScope {
47
49
  */
48
50
  setMemory (dialogContext: DialogContext, memory: object): void {
49
51
  if (memory === undefined) {
50
- throw new Error('DialogMemoryScope.setMemory: undefined memory object passed in.')
52
+ throw ExceptionHelper.generateException(
53
+ Error,
54
+ Errors.UndefinedMemoryObject,
55
+ undefined,
56
+ { scopeName: 'DialogMemoryScope' }
57
+ )
51
58
  }
52
59
 
53
60
  // If active dialog is a container dialog then "dialog" binds to it.
@@ -60,7 +67,10 @@ export class DialogMemoryScope extends MemoryScope {
60
67
 
61
68
  // If there's no active dialog then throw an error.
62
69
  if (!parent.activeDialog) {
63
- throw new Error('DialogMemoryScope.setMemory: no active dialog found.')
70
+ throw ExceptionHelper.generateException(
71
+ Error,
72
+ Errors.ActiveDialogUndefined
73
+ )
64
74
  }
65
75
 
66
76
  parent.activeDialog.state = memory
@@ -3,6 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { DialogContext } from '../../dialogContext'
6
+ import { ExceptionHelper } from '@microsoft/agents-activity'
7
+ import { Errors } from '../../errorHelper'
6
8
 
7
9
  /**
8
10
  * Abstract base class for all memory scopes.
@@ -38,7 +40,12 @@ export abstract class MemoryScope {
38
40
  * @param _memory memory to assign
39
41
  */
40
42
  setMemory (_dialogContext: DialogContext, _memory: object): void {
41
- throw new Error(`MemoryScope.setMemory: The '${this.name}' memory scope is read-only.`)
43
+ throw ExceptionHelper.generateException(
44
+ Error,
45
+ Errors.MemoryScopeOperationNotSupported,
46
+ undefined,
47
+ { scopeName: this.name, operation: 'setMemory' }
48
+ )
42
49
  }
43
50
 
44
51
  /**
@@ -65,6 +72,11 @@ export abstract class MemoryScope {
65
72
  * @param _dialogContext Current dialog context.
66
73
  */
67
74
  async delete (_dialogContext: DialogContext): Promise<void> {
68
- throw new Error(`MemoryScope.delete: The '${this.name}' memory scope can't be deleted.`)
75
+ throw ExceptionHelper.generateException(
76
+ Error,
77
+ Errors.MemoryScopeOperationNotSupported,
78
+ undefined,
79
+ { scopeName: this.name, operation: 'delete' }
80
+ )
69
81
  }
70
82
  }
@@ -3,6 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { MemoryScope } from './memoryScope'
6
+ import { ExceptionHelper } from '@microsoft/agents-activity'
7
+ import { Errors } from '../../errorHelper'
6
8
  import { ScopePath } from '../scopePath'
7
9
  import { DialogContext } from '../../dialogContext'
8
10
 
@@ -32,11 +34,19 @@ export class ThisMemoryScope extends MemoryScope {
32
34
  */
33
35
  setMemory (dialogContext: DialogContext, memory: object): void {
34
36
  if (memory === undefined) {
35
- throw new Error('ThisMemoryScope.setMemory: undefined memory object passed in.')
37
+ throw ExceptionHelper.generateException(
38
+ Error,
39
+ Errors.UndefinedMemoryObject,
40
+ undefined,
41
+ { scopeName: 'ThisMemoryScope' }
42
+ )
36
43
  }
37
44
 
38
45
  if (!dialogContext.activeDialog) {
39
- throw new Error('ThisMemoryScope.setMemory: no active dialog found.')
46
+ throw ExceptionHelper.generateException(
47
+ Error,
48
+ Errors.ActiveDialogUndefined
49
+ )
40
50
  }
41
51
 
42
52
  dialogContext.activeDialog.state = memory
@@ -3,6 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { MemoryScope } from './memoryScope'
6
+ import { ExceptionHelper } from '@microsoft/agents-activity'
7
+ import { Errors } from '../../errorHelper'
6
8
  import { ScopePath } from '../scopePath'
7
9
  import { DialogContext } from '../../dialogContext'
8
10
 
@@ -47,7 +49,12 @@ export class TurnMemoryScope extends MemoryScope {
47
49
  */
48
50
  setMemory (dialogContext: DialogContext, memory: object): void {
49
51
  if (memory === undefined) {
50
- throw new Error('TurnMemoryScope.setMemory: undefined memory object passed in.')
52
+ throw ExceptionHelper.generateException(
53
+ Error,
54
+ Errors.UndefinedMemoryObject,
55
+ undefined,
56
+ { scopeName: 'TurnMemoryScope' }
57
+ )
51
58
  }
52
59
 
53
60
  dialogContext.context.turnState.set(TURN_STATE, memory)
@@ -134,10 +134,11 @@ export class ChoicePrompt extends Prompt<FoundChoice> {
134
134
  const channelId = context.activity.channelId
135
135
  const choiceOptions = this.choiceOptions || this.choiceDefaults[locale]
136
136
  const choiceStyle: ListStyle = options.style === 0 ? 0 : options.style || this.style
137
+ const conversationType = context.activity.conversation?.conversationType
137
138
  if (isRetry && options.retryPrompt) {
138
- prompt = this.appendChoices(options.retryPrompt, channelId, choices, choiceStyle, choiceOptions)
139
+ prompt = this.appendChoices(options.retryPrompt, channelId, choices, choiceStyle, choiceOptions, conversationType)
139
140
  } else {
140
- prompt = this.appendChoices(options.prompt, channelId, choices, choiceStyle, choiceOptions)
141
+ prompt = this.appendChoices(options.prompt, channelId, choices, choiceStyle, choiceOptions, conversationType)
141
142
  }
142
143
 
143
144
  // Send prompt
@@ -167,10 +167,11 @@ export class ConfirmPrompt extends Prompt<boolean> {
167
167
  const culture = this.determineCulture(context.activity)
168
168
  const choiceOptions = this.choiceOptions || this.choiceDefaults[culture].options
169
169
  const choices = this.confirmChoices || this.choiceDefaults[culture].choices
170
+ const conversationType = context.activity.conversation?.conversationType
170
171
  if (isRetry && options.retryPrompt) {
171
- prompt = this.appendChoices(options.retryPrompt, channelId, choices, this.style, choiceOptions)
172
+ prompt = this.appendChoices(options.retryPrompt, channelId, choices, this.style, choiceOptions, conversationType)
172
173
  } else {
173
- prompt = this.appendChoices(options.prompt, channelId, choices, this.style, choiceOptions)
174
+ prompt = this.appendChoices(options.prompt, channelId, choices, this.style, choiceOptions, conversationType)
174
175
  }
175
176
 
176
177
  // Send prompt
@@ -401,6 +401,7 @@ export abstract class Prompt<T> extends Dialog {
401
401
  * @param choices List of choices to append.
402
402
  * @param style Configured style for the list of choices.
403
403
  * @param options (Optional) options to configure the underlying ChoiceFactory call.
404
+ * @param conversationType (Optional) the type of the conversation.
404
405
  * @returns The composed activity ready to send to the user.
405
406
  */
406
407
  protected appendChoices (
@@ -408,7 +409,8 @@ export abstract class Prompt<T> extends Dialog {
408
409
  channelId: string,
409
410
  choices: (string | Choice)[],
410
411
  style: ListStyle,
411
- options?: ChoiceFactoryOptions
412
+ options?: ChoiceFactoryOptions,
413
+ conversationType?: string
412
414
  ): Activity {
413
415
  // Get base prompt text (if any)
414
416
  let text = ''
@@ -429,12 +431,20 @@ export abstract class Prompt<T> extends Dialog {
429
431
  msg = ChoiceFactory.list(choices, text, undefined, options)
430
432
  break
431
433
 
434
+ case ListStyle.suggestedAction:
435
+ msg = ChoiceFactory.suggestedActions(choices, text)
436
+ break
437
+
438
+ case ListStyle.heroCard:
439
+ msg = ChoiceFactory.heroCard(choices, text)
440
+ break
441
+
432
442
  case ListStyle.none:
433
443
  msg = MessageFactory.text(text)
434
444
  break
435
445
 
436
446
  default:
437
- msg = ChoiceFactory.forChannel(channelId, choices, text, undefined, options)
447
+ msg = ChoiceFactory.forChannel(channelId, choices, text, undefined, options, conversationType)
438
448
  break
439
449
  }
440
450
 
package/src/recognizer.ts CHANGED
@@ -2,7 +2,8 @@
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { Activity } from '@microsoft/agents-activity'
5
+ import { Activity, ExceptionHelper } from '@microsoft/agents-activity'
6
+ import { Errors } from './errorHelper'
6
7
  import { Configurable } from './configurable'
7
8
  import { DialogContext } from './dialogContext'
8
9
  import omit from 'lodash/omit'
@@ -58,7 +59,10 @@ export class Recognizer extends Configurable implements RecognizerConfiguration
58
59
  _telemetryProperties?: Record<string, string>,
59
60
  _telemetryMetrics?: Record<string, number>
60
61
  ): Promise<RecognizerResult> {
61
- throw new Error('Please implement recognize function.')
62
+ throw ExceptionHelper.generateException(
63
+ Error,
64
+ Errors.RecognizeFunctionNotImplemented
65
+ )
62
66
  }
63
67
 
64
68
  /**
@@ -3,6 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { IntentScore } from './intentScore'
6
+ import { ExceptionHelper } from '@microsoft/agents-activity'
7
+ import { Errors } from './errorHelper'
6
8
 
7
9
  /**
8
10
  * Value returned from a recognizer.
@@ -64,7 +66,10 @@ export interface RecognizerResult {
64
66
  */
65
67
  export const getTopScoringIntent = (result: RecognizerResult): { intent: string; score: number } => {
66
68
  if (!result || !result.intents) {
67
- throw new Error('result is empty')
69
+ throw ExceptionHelper.generateException(
70
+ Error,
71
+ Errors.EmptyRecognizerResult
72
+ )
68
73
  }
69
74
 
70
75
  let topIntent = ''
@@ -3,7 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { v4 as uuidv4 } from 'uuid'
6
- import { ActivityTypes } from '@microsoft/agents-activity'
6
+ import { ActivityTypes, ExceptionHelper } from '@microsoft/agents-activity'
7
+ import { Errors } from './errorHelper'
7
8
  import { Dialog } from './dialog'
8
9
  import { DialogContext } from './dialogContext'
9
10
  import { WaterfallStepContext } from './waterfallStepContext'
@@ -172,8 +173,11 @@ export class WaterfallDialog<O extends object = {}> extends Dialog<O> {
172
173
  values: state.values,
173
174
  onNext: async (stepResult?: any): Promise<DialogTurnResult<any>> => {
174
175
  if (nextCalled) {
175
- throw new Error(
176
- `WaterfallStepContext.next(): method already called for dialog and step '${this.id}[${index}]'.`
176
+ throw ExceptionHelper.generateException(
177
+ Error,
178
+ Errors.WaterfallStepError,
179
+ undefined,
180
+ { stepIndex: index.toString() }
177
181
  )
178
182
  }
179
183
  nextCalled = true