@microsoft/agents-hosting 0.2.10-g3ac88ff25e → 0.3.5

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 (128) hide show
  1. package/README.md +17 -1
  2. package/dist/src/activityHandler.d.ts +304 -46
  3. package/dist/src/activityHandler.js +298 -45
  4. package/dist/src/activityHandler.js.map +1 -1
  5. package/dist/src/agent-client/agentClient.d.ts +50 -0
  6. package/dist/src/agent-client/agentClient.js +28 -0
  7. package/dist/src/agent-client/agentClient.js.map +1 -1
  8. package/dist/src/app/agentApplication.d.ts +272 -7
  9. package/dist/src/app/agentApplication.js +278 -12
  10. package/dist/src/app/agentApplication.js.map +1 -1
  11. package/dist/src/app/agentApplicationBuilder.d.ts +34 -3
  12. package/dist/src/app/agentApplicationBuilder.js +38 -6
  13. package/dist/src/app/agentApplicationBuilder.js.map +1 -1
  14. package/dist/src/app/agentApplicationOptions.d.ts +26 -2
  15. package/dist/src/app/appMemory.d.ts +34 -0
  16. package/dist/src/app/{memory.js → appMemory.js} +1 -1
  17. package/dist/src/app/appMemory.js.map +1 -0
  18. package/dist/src/app/appRoute.d.ts +6 -0
  19. package/dist/src/app/attachmentDownloader.d.ts +18 -0
  20. package/dist/src/app/attachmentDownloader.js +18 -0
  21. package/dist/src/app/attachmentDownloader.js.map +1 -1
  22. package/dist/src/app/conversationUpdateEvents.d.ts +6 -0
  23. package/dist/src/app/index.d.ts +4 -1
  24. package/dist/src/app/index.js +4 -1
  25. package/dist/src/app/index.js.map +1 -1
  26. package/dist/src/app/inputFileDownloader.d.ts +22 -0
  27. package/dist/src/app/oauth/authorization.d.ts +87 -0
  28. package/dist/src/app/oauth/authorization.js +135 -0
  29. package/dist/src/app/oauth/authorization.js.map +1 -0
  30. package/dist/src/app/routeHandler.d.ts +8 -0
  31. package/dist/src/app/routeSelector.d.ts +9 -0
  32. package/dist/src/app/turnEvents.d.ts +6 -0
  33. package/dist/src/app/turnState.d.ts +152 -2
  34. package/dist/src/app/turnState.js +125 -0
  35. package/dist/src/app/turnState.js.map +1 -1
  36. package/dist/src/app/turnStateEntry.d.ts +32 -0
  37. package/dist/src/app/turnStateEntry.js +32 -0
  38. package/dist/src/app/turnStateEntry.js.map +1 -1
  39. package/dist/src/auth/authConfiguration.d.ts +24 -0
  40. package/dist/src/auth/authConfiguration.js.map +1 -1
  41. package/dist/src/auth/request.d.ts +12 -0
  42. package/dist/src/baseAdapter.d.ts +17 -0
  43. package/dist/src/baseAdapter.js +17 -0
  44. package/dist/src/baseAdapter.js.map +1 -1
  45. package/dist/src/cards/cardFactory.d.ts +3 -0
  46. package/dist/src/cards/cardFactory.js +3 -0
  47. package/dist/src/cards/cardFactory.js.map +1 -1
  48. package/dist/src/cards/index.d.ts +1 -0
  49. package/dist/src/cards/index.js +1 -0
  50. package/dist/src/cards/index.js.map +1 -1
  51. package/dist/src/cards/o365ConnectorCardActionBase.d.ts +8 -0
  52. package/dist/src/cloudAdapter.d.ts +25 -3
  53. package/dist/src/cloudAdapter.js +25 -3
  54. package/dist/src/cloudAdapter.js.map +1 -1
  55. package/dist/src/getProductInfo.d.ts +6 -0
  56. package/dist/src/getProductInfo.js +6 -0
  57. package/dist/src/getProductInfo.js.map +1 -1
  58. package/dist/src/logger.d.ts +34 -2
  59. package/dist/src/logger.js +35 -0
  60. package/dist/src/logger.js.map +1 -1
  61. package/dist/src/oauth/oAuthFlow.d.ts +32 -3
  62. package/dist/src/oauth/oAuthFlow.js +38 -14
  63. package/dist/src/oauth/oAuthFlow.js.map +1 -1
  64. package/dist/src/oauth/userTokenClient.d.ts +2 -2
  65. package/dist/src/oauth/userTokenClient.js +3 -3
  66. package/dist/src/oauth/userTokenClient.js.map +1 -1
  67. package/dist/src/state/agentState.d.ts +79 -27
  68. package/dist/src/state/agentState.js +58 -27
  69. package/dist/src/state/agentState.js.map +1 -1
  70. package/dist/src/state/agentStatePropertyAccesor.d.ts +67 -11
  71. package/dist/src/state/agentStatePropertyAccesor.js +58 -11
  72. package/dist/src/state/agentStatePropertyAccesor.js.map +1 -1
  73. package/dist/src/statusCodes.d.ts +39 -0
  74. package/dist/src/statusCodes.js +39 -0
  75. package/dist/src/statusCodes.js.map +1 -1
  76. package/dist/src/storage/memoryStorage.d.ts +48 -14
  77. package/dist/src/storage/memoryStorage.js +48 -14
  78. package/dist/src/storage/memoryStorage.js.map +1 -1
  79. package/dist/src/storage/storage.d.ts +43 -13
  80. package/dist/src/tokenResponseEventName.d.ts +3 -0
  81. package/dist/src/tokenResponseEventName.js +3 -0
  82. package/dist/src/tokenResponseEventName.js.map +1 -1
  83. package/dist/src/turnContext.d.ts +142 -56
  84. package/dist/src/turnContext.js +123 -53
  85. package/dist/src/turnContext.js.map +1 -1
  86. package/package.json +6 -6
  87. package/src/activityHandler.ts +304 -46
  88. package/src/agent-client/agentClient.ts +55 -5
  89. package/src/app/agentApplication.ts +283 -15
  90. package/src/app/agentApplicationBuilder.ts +39 -7
  91. package/src/app/agentApplicationOptions.ts +33 -2
  92. package/src/app/appMemory.ts +38 -0
  93. package/src/app/appRoute.ts +7 -0
  94. package/src/app/attachmentDownloader.ts +18 -0
  95. package/src/app/conversationUpdateEvents.ts +6 -0
  96. package/src/app/index.ts +4 -1
  97. package/src/app/inputFileDownloader.ts +24 -0
  98. package/src/app/oauth/authorization.ts +162 -0
  99. package/src/app/routeHandler.ts +8 -0
  100. package/src/app/routeSelector.ts +9 -0
  101. package/src/app/turnEvents.ts +6 -0
  102. package/src/app/turnState.ts +153 -3
  103. package/src/app/turnStateEntry.ts +32 -0
  104. package/src/auth/authConfiguration.ts +32 -1
  105. package/src/auth/request.ts +15 -0
  106. package/src/baseAdapter.ts +18 -0
  107. package/src/cards/cardFactory.ts +3 -0
  108. package/src/cards/index.ts +1 -0
  109. package/src/cards/o365ConnectorCardActionBase.ts +8 -0
  110. package/src/cloudAdapter.ts +28 -3
  111. package/src/getProductInfo.ts +7 -0
  112. package/src/logger.ts +34 -1
  113. package/src/oauth/oAuthFlow.ts +59 -18
  114. package/src/oauth/userTokenClient.ts +4 -4
  115. package/src/state/agentState.ts +81 -29
  116. package/src/state/agentStatePropertyAccesor.ts +67 -11
  117. package/src/statusCodes.ts +51 -0
  118. package/src/storage/memoryStorage.ts +48 -14
  119. package/src/storage/storage.ts +51 -18
  120. package/src/tokenResponseEventName.ts +3 -0
  121. package/src/turnContext.ts +142 -56
  122. package/dist/src/app/memory.d.ts +0 -10
  123. package/dist/src/app/memory.js.map +0 -1
  124. package/dist/src/app/oauth/userIdentity.d.ts +0 -43
  125. package/dist/src/app/oauth/userIdentity.js +0 -54
  126. package/dist/src/app/oauth/userIdentity.js.map +0 -1
  127. package/src/app/memory.ts +0 -14
  128. package/src/app/oauth/userIdentity.ts +0 -78
@@ -8,22 +8,37 @@ import { AttachmentInfo } from './connector-client/attachmentInfo'
8
8
  import { AttachmentData } from './connector-client/attachmentData'
9
9
 
10
10
  /**
11
- * Defines a handler for sending activities.
11
+ * Defines a handler for processing and sending activities.
12
+ * Used for middleware that needs to intercept or modify activities being sent.
13
+ *
14
+ * @param context The current turn context
15
+ * @param activities The activities being sent
16
+ * @param next Function to call to continue the middleware chain
12
17
  */
13
18
  export type SendActivitiesHandler = (context: TurnContext, activities: Activity[], next: () => Promise<ResourceResponse[]>) => Promise<ResourceResponse[]>
14
19
 
15
20
  /**
16
21
  * Defines a handler for updating an activity.
22
+ * Used for middleware that needs to intercept or modify activity updates.
23
+ *
24
+ * @param context The current turn context
25
+ * @param activity The activity being updated
26
+ * @param next Function to call to continue the middleware chain
17
27
  */
18
28
  export type UpdateActivityHandler = (context: TurnContext, activity: Activity, next: () => Promise<void>) => Promise<void>
19
29
 
20
30
  /**
21
31
  * Defines a handler for deleting an activity.
32
+ * Used for middleware that needs to intercept or handle activity deletions.
33
+ *
34
+ * @param context The current turn context
35
+ * @param reference Reference to the activity being deleted
36
+ * @param next Function to call to continue the middleware chain
22
37
  */
23
38
  export type DeleteActivityHandler = (context: TurnContext, reference: ConversationReference, next: () => Promise<void>) => Promise<void>
24
39
 
25
40
  /**
26
- * Key for the agent callback handler.
41
+ * Key for the agent callback handler in TurnState collection.
27
42
  */
28
43
  export const AgentCallbackHandlerKey = 'agentCallbackHandler'
29
44
 
@@ -33,7 +48,20 @@ export const AgentCallbackHandlerKey = 'agentCallbackHandler'
33
48
  export interface TurnContext {}
34
49
 
35
50
  /**
36
- * Represents the context object for a turn of an Agent.
51
+ * Represents the context for a single turn in a conversation between a user and an agent.
52
+ *
53
+ * TurnContext is a central concept in the Agents framework - it contains:
54
+ * - The incoming activity that started the turn
55
+ * - Access to the adapter that can be used to send responses
56
+ * - A state collection for storing information during the turn
57
+ * - Methods for sending, updating, and deleting activities
58
+ * - Middleware hooks for intercepting activity operations
59
+ *
60
+ * The TurnContext object is created by the adapter when an activity is received
61
+ * and is passed to the agent's logic to process the turn. It maintains information
62
+ * about the conversation and provides methods to send responses.
63
+ *
64
+ * This class follows the builder pattern for registering middleware handlers.
37
65
  */
38
66
  export class TurnContext {
39
67
  private readonly _adapter?: BaseAdapter
@@ -48,8 +76,9 @@ export class TurnContext {
48
76
 
49
77
  /**
50
78
  * Initializes a new instance of the TurnContext class.
51
- * @param adapterOrContext The adapter or context for the turn.
52
- * @param request The activity for the turn.
79
+ *
80
+ * @param adapterOrContext The adapter that created this context, or another TurnContext to clone
81
+ * @param request The activity for the turn (required when first parameter is an adapter)
53
82
  */
54
83
  constructor (adapterOrContext: BaseAdapter, request: Activity)
55
84
  constructor (adapterOrContext: TurnContext)
@@ -63,17 +92,24 @@ export class TurnContext {
63
92
  }
64
93
 
65
94
  /**
66
- * A list of buffered reply activities.
95
+ * A list of reply activities that are buffered until the end of the turn.
96
+ *
97
+ * This is primarily used with the 'expectReplies' delivery mode where all
98
+ * activities during a turn are collected and returned as a single response.
67
99
  */
68
100
  readonly bufferedReplyActivities: Activity[] = []
69
101
 
70
102
  /**
71
- * Sends a trace activity.
72
- * @param name The name of the trace activity.
73
- * @param value The value of the trace activity.
74
- * @param valueType The value type of the trace activity.
75
- * @param label The label of the trace activity.
76
- * @returns The resource response.
103
+ * Sends a trace activity for debugging purposes.
104
+ *
105
+ * Trace activities are typically used for debugging and are only visible in
106
+ * channels that support them, like the Bot Framework Emulator.
107
+ *
108
+ * @param name The name/category of the trace
109
+ * @param value The value/data to include in the trace
110
+ * @param valueType Optional type name for the value
111
+ * @param label Optional descriptive label for the trace
112
+ * @returns A promise that resolves to the resource response or undefined
77
113
  */
78
114
  async sendTraceActivity (name: string, value?: any, valueType?: string, label?: string): Promise<ResourceResponse | undefined> {
79
115
  const traceActivityObj = {
@@ -89,11 +125,16 @@ export class TurnContext {
89
125
  }
90
126
 
91
127
  /**
92
- * Sends an activity.
93
- * @param activityOrText The activity or text to send.
94
- * @param speak The text to speak.
95
- * @param inputHint The input hint.
96
- * @returns The resource response.
128
+ * Sends an activity to the sender of the incoming activity.
129
+ *
130
+ * This is the primary method used to respond to the user. It automatically
131
+ * addresses the response to the correct conversation and recipient using
132
+ * information from the incoming activity.
133
+ *
134
+ * @param activityOrText The activity to send or a string for a simple message
135
+ * @param speak Optional text to be spoken by the agent
136
+ * @param inputHint Optional input hint to indicate if the agent is expecting input
137
+ * @returns A promise that resolves to the resource response or undefined
97
138
  */
98
139
  async sendActivity (activityOrText: string | Activity, speak?: string, inputHint?: string): Promise<ResourceResponse | undefined> {
99
140
  let activityObject: {}
@@ -112,9 +153,14 @@ export class TurnContext {
112
153
  }
113
154
 
114
155
  /**
115
- * Sends multiple activities.
116
- * @param activities The activities to send.
117
- * @returns The resource responses.
156
+ * Sends multiple activities to the sender of the incoming activity.
157
+ *
158
+ * This method applies conversation references to each activity and
159
+ * emits them through the middleware chain before sending them to
160
+ * the adapter.
161
+ *
162
+ * @param activities The array of activities to send
163
+ * @returns A promise that resolves to an array of resource responses
118
164
  */
119
165
  async sendActivities (activities: Activity[]): Promise<ResourceResponse[]> {
120
166
  let sentNonTraceActivity = false
@@ -164,9 +210,13 @@ export class TurnContext {
164
210
  }
165
211
 
166
212
  /**
167
- * Updates an activity.
168
- * @param activity The activity to update.
169
- * @returns A promise representing the asynchronous operation.
213
+ * Updates an existing activity in the conversation.
214
+ *
215
+ * This can be used to edit previously sent activities, for example to
216
+ * update the content of an adaptive card or change a message.
217
+ *
218
+ * @param activity The activity to update with its ID specified
219
+ * @returns A promise that resolves when the activity has been updated
170
220
  */
171
221
  async updateActivity (activity: Activity): Promise<void> {
172
222
  const ref: ConversationReference = this.activity.getConversationReference()
@@ -177,9 +227,10 @@ export class TurnContext {
177
227
  }
178
228
 
179
229
  /**
180
- * Deletes an activity.
181
- * @param idOrReference The ID or reference of the activity to delete.
182
- * @returns A promise representing the asynchronous operation.
230
+ * Deletes an activity from the conversation.
231
+ *
232
+ * @param idOrReference The ID of the activity to delete or a conversation reference
233
+ * @returns A promise that resolves when the activity has been deleted
183
234
  */
184
235
  async deleteActivity (idOrReference: string | ConversationReference): Promise<void> {
185
236
  let reference: ConversationReference
@@ -193,38 +244,45 @@ export class TurnContext {
193
244
  }
194
245
 
195
246
  /**
196
- * Uploads an attachment.
197
- * @param conversationId The conversation ID.
198
- * @param attachmentData The attachment data.
199
- * @returns The resource response.
247
+ * Uploads an attachment to the conversation.
248
+ *
249
+ * @param conversationId The ID of the conversation
250
+ * @param attachmentData The attachment data to upload
251
+ * @returns A promise that resolves to the resource response
200
252
  */
201
253
  async uploadAttachment (conversationId: string, attachmentData: AttachmentData): Promise<ResourceResponse> {
202
254
  return await this.adapter.uploadAttachment(conversationId, attachmentData)
203
255
  }
204
256
 
205
257
  /**
206
- * Gets attachment information.
207
- * @param attachmentId The attachment ID.
208
- * @returns The attachment information.
258
+ * Gets information about an attachment.
259
+ *
260
+ * @param attachmentId The ID of the attachment
261
+ * @returns A promise that resolves to the attachment information
209
262
  */
210
263
  async getAttachmentInfo (attachmentId: string): Promise<AttachmentInfo> {
211
264
  return await this.adapter.getAttachmentInfo(attachmentId)
212
265
  }
213
266
 
214
267
  /**
215
- * Gets an attachment.
216
- * @param attachmentId The attachment ID.
217
- * @param viewId The view ID.
218
- * @returns The readable stream of the attachment.
268
+ * Gets the content of an attachment.
269
+ *
270
+ * @param attachmentId The ID of the attachment
271
+ * @param viewId The view to get
272
+ * @returns A promise that resolves to a readable stream of the attachment content
219
273
  */
220
274
  async getAttachment (attachmentId: string, viewId: string): Promise<NodeJS.ReadableStream> {
221
275
  return await this.adapter.getAttachment(attachmentId, viewId)
222
276
  }
223
277
 
224
278
  /**
225
- * Registers a handler for sending activities.
226
- * @param handler The handler to register.
227
- * @returns The current TurnContext instance.
279
+ * Registers a handler for intercepting and processing activities being sent.
280
+ *
281
+ * This method follows a middleware pattern, allowing multiple handlers to
282
+ * be chained together. Handlers can modify activities or inject new ones.
283
+ *
284
+ * @param handler The handler to register
285
+ * @returns The current TurnContext instance for chaining
228
286
  */
229
287
  onSendActivities (handler: SendActivitiesHandler): this {
230
288
  this._onSendActivities.push(handler)
@@ -232,9 +290,10 @@ export class TurnContext {
232
290
  }
233
291
 
234
292
  /**
235
- * Registers a handler for updating activities.
236
- * @param handler The handler to register.
237
- * @returns The current TurnContext instance.
293
+ * Registers a handler for intercepting activity updates.
294
+ *
295
+ * @param handler The handler to register
296
+ * @returns The current TurnContext instance for chaining
238
297
  */
239
298
  onUpdateActivity (handler: UpdateActivityHandler): this {
240
299
  this._onUpdateActivity.push(handler)
@@ -242,9 +301,10 @@ export class TurnContext {
242
301
  }
243
302
 
244
303
  /**
245
- * Registers a handler for deleting activities.
246
- * @param handler The handler to register.
247
- * @returns The current TurnContext instance.
304
+ * Registers a handler for intercepting activity deletions.
305
+ *
306
+ * @param handler The handler to register
307
+ * @returns The current TurnContext instance for chaining
248
308
  */
249
309
  onDeleteActivity (handler: DeleteActivityHandler): this {
250
310
  this._onDeleteActivity.push(handler)
@@ -253,28 +313,41 @@ export class TurnContext {
253
313
 
254
314
  /**
255
315
  * Copies the properties of this TurnContext to another TurnContext.
256
- * @param context The context to copy to.
316
+ *
317
+ * Used internally when cloning contexts.
318
+ *
319
+ * @param context The context to copy to
320
+ * @protected
257
321
  */
258
322
  protected copyTo (context: TurnContext): void {
259
323
  ['_adapter', '_activity', '_respondedRef', '_services', '_onSendActivities', '_onUpdateActivity', '_onDeleteActivity'].forEach((prop: string) => ((context as any)[prop] = (this as any)[prop]))
260
324
  }
261
325
 
262
326
  /**
263
- * Gets the adapter for the turn.
327
+ * Gets the adapter that created this context.
328
+ *
329
+ * The adapter is responsible for sending and receiving activities
330
+ * to and from the user's channel.
264
331
  */
265
332
  get adapter (): BaseAdapter {
266
333
  return this._adapter as BaseAdapter
267
334
  }
268
335
 
269
336
  /**
270
- * Gets the activity for the turn.
337
+ * Gets the incoming activity that started this turn.
338
+ *
339
+ * This is the activity that was received from the user or channel
340
+ * and triggered the creation of this context.
271
341
  */
272
342
  get activity (): Activity {
273
343
  return this._activity as Activity
274
344
  }
275
345
 
276
346
  /**
277
- * Gets or sets whether the turn has responded.
347
+ * Gets or sets whether the turn has sent a response to the user.
348
+ *
349
+ * This is used to track whether the agent has responded to the user's
350
+ * activity. Once set to true, it cannot be set back to false.
278
351
  */
279
352
  get responded (): boolean {
280
353
  return this._respondedRef.responded
@@ -289,6 +362,9 @@ export class TurnContext {
289
362
 
290
363
  /**
291
364
  * Gets or sets the locale for the turn.
365
+ *
366
+ * The locale affects language-dependent operations like
367
+ * formatting dates or numbers.
292
368
  */
293
369
  get locale (): string | undefined {
294
370
  const turnObj = this._turnState.get(this._turn)
@@ -309,18 +385,28 @@ export class TurnContext {
309
385
  }
310
386
 
311
387
  /**
312
- * Gets the turn state collection.
388
+ * Gets the turn state collection for storing data during the turn.
389
+ *
390
+ * The turn state collection provides a dictionary-like interface
391
+ * for storing arbitrary data that needs to be accessible during
392
+ * the processing of the current turn.
313
393
  */
314
394
  get turnState (): TurnContextStateCollection {
315
395
  return this._turnState
316
396
  }
317
397
 
318
398
  /**
319
- * Emits events to the registered handlers.
320
- * @param handlers The handlers to emit to.
321
- * @param arg The argument to pass to the handlers.
322
- * @param next The next function to call.
323
- * @returns The result of the handlers.
399
+ * Emits events to registered middleware handlers.
400
+ *
401
+ * This internal method implements the middleware pattern, allowing
402
+ * handlers to be chained together with each having the option to
403
+ * short-circuit the chain.
404
+ *
405
+ * @param handlers Array of handlers to execute
406
+ * @param arg The argument to pass to each handler
407
+ * @param next The function to execute at the end of the middleware chain
408
+ * @returns A promise that resolves to the result from the handlers or next function
409
+ * @private
324
410
  */
325
411
  private async emit<A, T>(handlers: Array<(context: TurnContext, arg: A, next: () => Promise<T>) => Promise<T>>, arg: A, next: () => Promise<T>): Promise<T> {
326
412
  const runHandlers = async ([handler, ...remaining]: typeof handlers): Promise<T> => {
@@ -1,10 +0,0 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- export interface Memory {
6
- deleteValue(path: string): void;
7
- hasValue(path: string): boolean;
8
- getValue<TValue = unknown>(path: string): TValue;
9
- setValue(path: string, value: unknown): void;
10
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/app/memory.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
@@ -1,43 +0,0 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { TurnContext } from '../../turnContext';
6
- import { TurnState } from '../turnState';
7
- import { Storage } from '../../storage';
8
- import { OAuthFlow, TokenResponse } from '../../oauth';
9
- /**
10
- * Options for configuring user identity.
11
- * Contains settings related to Single Sign-On (SSO) authentication.
12
- */
13
- export interface UserIdentityOptions {
14
- /**
15
- * Determines whether Single Sign-On (SSO) is enabled for user authentication.
16
- */
17
- enableSSO: boolean;
18
- /**
19
- * The name of the SSO connection to use when SSO is enabled.
20
- * Only applicable when enableSSO is set to true.
21
- */
22
- ssoConnectionName?: string;
23
- }
24
- export declare class UserIdentity {
25
- oAuthFlow: OAuthFlow;
26
- /**
27
- * Creates a new instance of UserAuthorization.
28
- * @param {Storage} storage - The storage system to use for state management.
29
- */
30
- constructor(storage: Storage, connectionName: string);
31
- getToken(context: TurnContext): Promise<TokenResponse>;
32
- authenticate(context: TurnContext, state: TurnState): Promise<TokenResponse>;
33
- /**
34
- * Signs out the current user.
35
- * This method clears the user's token and resets the SSO state.
36
- *
37
- * @param {TurnContext} context - The context object for the current turn.
38
- * @param {TurnState} state - The state object for the current turn.
39
- */
40
- signOut(context: TurnContext, state: TurnState): Promise<void>;
41
- _signInHandler: ((context: TurnContext, state: TurnState) => void) | null;
42
- onSignInSuccess(handler: (context: TurnContext, state: TurnState) => void): void;
43
- }
@@ -1,54 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.UserIdentity = void 0;
8
- const oauth_1 = require("../../oauth");
9
- const state_1 = require("../../state");
10
- class UserIdentity {
11
- /**
12
- * Creates a new instance of UserAuthorization.
13
- * @param {Storage} storage - The storage system to use for state management.
14
- */
15
- constructor(storage, connectionName) {
16
- this._signInHandler = null;
17
- const userState = new state_1.UserState(storage);
18
- this.oAuthFlow = new oauth_1.OAuthFlow(userState, connectionName);
19
- }
20
- async getToken(context) {
21
- return await this.oAuthFlow.getUserToken(context);
22
- }
23
- async authenticate(context, state) {
24
- var _a;
25
- let tokenResponse;
26
- if (((_a = this.oAuthFlow.state) === null || _a === void 0 ? void 0 : _a.flowStarted) === false) {
27
- tokenResponse = await this.oAuthFlow.beginFlow(context);
28
- }
29
- else {
30
- tokenResponse = await this.oAuthFlow.continueFlow(context);
31
- if (tokenResponse.status === oauth_1.TokenRequestStatus.Success) {
32
- if (this._signInHandler) {
33
- await this._signInHandler(context, state);
34
- }
35
- }
36
- }
37
- return tokenResponse;
38
- }
39
- /**
40
- * Signs out the current user.
41
- * This method clears the user's token and resets the SSO state.
42
- *
43
- * @param {TurnContext} context - The context object for the current turn.
44
- * @param {TurnState} state - The state object for the current turn.
45
- */
46
- async signOut(context, state) {
47
- await this.oAuthFlow.signOut(context);
48
- }
49
- onSignInSuccess(handler) {
50
- this._signInHandler = handler;
51
- }
52
- }
53
- exports.UserIdentity = UserIdentity;
54
- //# sourceMappingURL=userIdentity.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"userIdentity.js","sourceRoot":"","sources":["../../../../src/app/oauth/userIdentity.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAMH,uCAA0E;AAC1E,uCAAuC;AAqBvC,MAAa,YAAY;IAGvB;;;OAGG;IACH,YAAa,OAAgB,EAAE,cAAsB;QAmCrD,mBAAc,GAA8D,IAAI,CAAA;QAlC9E,MAAM,SAAS,GAAG,IAAI,iBAAS,CAAC,OAAO,CAAC,CAAA;QACxC,IAAI,CAAC,SAAS,GAAG,IAAI,iBAAS,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;IAC3D,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAE,OAAoB;QACzC,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;IACnD,CAAC;IAEM,KAAK,CAAC,YAAY,CAAE,OAAoB,EAAE,KAAgB;;QAC/D,IAAI,aAA4B,CAAA;QAChC,IAAI,CAAA,MAAA,IAAI,CAAC,SAAS,CAAC,KAAK,0CAAE,WAAW,MAAK,KAAK,EAAE,CAAC;YAChD,aAAa,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;QACzD,CAAC;aAAM,CAAC;YACN,aAAa,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;YAC1D,IAAI,aAAa,CAAC,MAAM,KAAK,0BAAkB,CAAC,OAAO,EAAE,CAAC;gBACxD,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;oBACxB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;gBAC3C,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,aAAa,CAAA;IACtB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,CAAE,OAAoB,EAAE,KAAgB;QACnD,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC;IAGM,eAAe,CAAE,OAAyD;QAC/E,IAAI,CAAC,cAAc,GAAG,OAAO,CAAA;IAC/B,CAAC;CACF;AA9CD,oCA8CC"}
package/src/app/memory.ts DELETED
@@ -1,14 +0,0 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- export interface Memory {
7
- deleteValue(path: string): void;
8
-
9
- hasValue(path: string): boolean;
10
-
11
- getValue<TValue = unknown>(path: string): TValue;
12
-
13
- setValue(path: string, value: unknown): void;
14
- }
@@ -1,78 +0,0 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { TurnContext } from '../../turnContext'
7
- // import { debug } from '../../logger'
8
- import { TurnState } from '../turnState'
9
- import { Storage } from '../../storage'
10
- import { OAuthFlow, TokenRequestStatus, TokenResponse } from '../../oauth'
11
- import { UserState } from '../../state'
12
-
13
- // const logger = debug('agents:user-identity')
14
-
15
- /**
16
- * Options for configuring user identity.
17
- * Contains settings related to Single Sign-On (SSO) authentication.
18
- */
19
- export interface UserIdentityOptions {
20
- /**
21
- * Determines whether Single Sign-On (SSO) is enabled for user authentication.
22
- */
23
- enableSSO: boolean;
24
-
25
- /**
26
- * The name of the SSO connection to use when SSO is enabled.
27
- * Only applicable when enableSSO is set to true.
28
- */
29
- ssoConnectionName?: string;
30
- }
31
-
32
- export class UserIdentity {
33
- oAuthFlow: OAuthFlow
34
-
35
- /**
36
- * Creates a new instance of UserAuthorization.
37
- * @param {Storage} storage - The storage system to use for state management.
38
- */
39
- constructor (storage: Storage, connectionName: string) {
40
- const userState = new UserState(storage)
41
- this.oAuthFlow = new OAuthFlow(userState, connectionName)
42
- }
43
-
44
- public async getToken (context: TurnContext): Promise<TokenResponse> {
45
- return await this.oAuthFlow.getUserToken(context)
46
- }
47
-
48
- public async authenticate (context: TurnContext, state: TurnState) : Promise<TokenResponse> {
49
- let tokenResponse: TokenResponse
50
- if (this.oAuthFlow.state?.flowStarted === false) {
51
- tokenResponse = await this.oAuthFlow.beginFlow(context)
52
- } else {
53
- tokenResponse = await this.oAuthFlow.continueFlow(context)
54
- if (tokenResponse.status === TokenRequestStatus.Success) {
55
- if (this._signInHandler) {
56
- await this._signInHandler(context, state)
57
- }
58
- }
59
- }
60
- return tokenResponse
61
- }
62
-
63
- /**
64
- * Signs out the current user.
65
- * This method clears the user's token and resets the SSO state.
66
- *
67
- * @param {TurnContext} context - The context object for the current turn.
68
- * @param {TurnState} state - The state object for the current turn.
69
- */
70
- async signOut (context: TurnContext, state: TurnState) {
71
- await this.oAuthFlow.signOut(context)
72
- }
73
-
74
- _signInHandler: ((context: TurnContext, state: TurnState) => void) | null = null
75
- public onSignInSuccess (handler: (context: TurnContext, state: TurnState) => void) {
76
- this._signInHandler = handler
77
- }
78
- }