@microsoft/agents-hosting 1.0.0 → 1.0.7-g73d3d58001
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.
- package/dist/package.json +3 -3
- package/dist/src/activityHandler.d.ts +0 -1
- package/dist/src/activityHandler.js +0 -1
- package/dist/src/activityHandler.js.map +1 -1
- package/dist/src/agent-client/agentResponseHandler.d.ts +6 -6
- package/dist/src/agent-client/agentResponseHandler.js +6 -6
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.d.ts +12 -4
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.js +5 -1
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.js.map +1 -1
- package/dist/src/app/adaptiveCards/index.d.ts +2 -0
- package/dist/src/app/adaptiveCards/index.js +2 -0
- package/dist/src/app/adaptiveCards/index.js.map +1 -1
- package/dist/src/app/agentApplication.d.ts +24 -7
- package/dist/src/app/agentApplication.js +24 -7
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +1 -1
- package/dist/src/app/appRoute.d.ts +8 -4
- package/dist/src/app/attachmentDownloader.d.ts +3 -1
- package/dist/src/app/attachmentDownloader.js +3 -1
- package/dist/src/app/attachmentDownloader.js.map +1 -1
- package/dist/src/app/authorization.d.ts +26 -18
- package/dist/src/app/authorization.js +26 -18
- package/dist/src/app/authorization.js.map +1 -1
- package/dist/src/app/index.d.ts +2 -0
- package/dist/src/app/index.js +2 -0
- package/dist/src/app/index.js.map +1 -1
- package/dist/src/app/routeRank.d.ts +10 -3
- package/dist/src/app/routeRank.js +10 -3
- package/dist/src/app/routeRank.js.map +1 -1
- package/dist/src/app/streaming/streamingResponse.d.ts +23 -2
- package/dist/src/app/streaming/streamingResponse.js +23 -2
- package/dist/src/app/streaming/streamingResponse.js.map +1 -1
- package/dist/src/app/turnState.d.ts +69 -19
- package/dist/src/app/turnState.js +69 -19
- package/dist/src/app/turnState.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +16 -9
- package/dist/src/auth/authConfiguration.js +11 -6
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js +26 -18
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/cards/adaptiveCard.d.ts +1 -1
- package/dist/src/cloudAdapter.js +1 -0
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/headerPropagation.d.ts +18 -6
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/oauth/userTokenClient.d.ts +2 -2
- package/dist/src/oauth/userTokenClient.js +2 -2
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/state/agentState.d.ts +23 -7
- package/dist/src/state/agentState.js +19 -7
- package/dist/src/state/agentState.js.map +1 -1
- package/dist/src/state/agentStatePropertyAccesor.d.ts +63 -41
- package/dist/src/state/agentStatePropertyAccesor.js +43 -32
- package/dist/src/state/agentStatePropertyAccesor.js.map +1 -1
- package/dist/src/storage/fileStorage.d.ts +8 -6
- package/dist/src/storage/fileStorage.js +8 -6
- package/dist/src/storage/fileStorage.js.map +1 -1
- package/dist/src/storage/memoryStorage.d.ts +12 -7
- package/dist/src/storage/memoryStorage.js +12 -7
- package/dist/src/storage/memoryStorage.js.map +1 -1
- package/dist/src/storage/storage.d.ts +18 -1
- package/dist/src/turnContext.d.ts +31 -25
- package/dist/src/turnContext.js +31 -20
- package/dist/src/turnContext.js.map +1 -1
- package/package.json +3 -3
- package/src/activityHandler.ts +0 -1
- package/src/agent-client/agentResponseHandler.ts +6 -6
- package/src/app/adaptiveCards/adaptiveCardsActions.ts +12 -4
- package/src/app/adaptiveCards/index.ts +2 -0
- package/src/app/agentApplication.ts +24 -7
- package/src/app/agentApplicationOptions.ts +1 -1
- package/src/app/appRoute.ts +8 -4
- package/src/app/attachmentDownloader.ts +3 -1
- package/src/app/authorization.ts +26 -18
- package/src/app/index.ts +2 -0
- package/src/app/routeRank.ts +10 -3
- package/src/app/streaming/streamingResponse.ts +23 -2
- package/src/app/turnState.ts +69 -19
- package/src/auth/authConfiguration.ts +16 -9
- package/src/auth/jwt-middleware.ts +24 -17
- package/src/cards/adaptiveCard.ts +1 -1
- package/src/cloudAdapter.ts +2 -0
- package/src/headerPropagation.ts +18 -6
- package/src/index.ts +1 -0
- package/src/oauth/userTokenClient.ts +2 -2
- package/src/state/agentState.ts +23 -7
- package/src/state/agentStatePropertyAccesor.ts +63 -41
- package/src/storage/fileStorage.ts +8 -6
- package/src/storage/memoryStorage.ts +12 -7
- package/src/storage/storage.ts +18 -1
- package/src/turnContext.ts +31 -25
package/src/app/turnState.ts
CHANGED
|
@@ -40,12 +40,18 @@ export interface DefaultTempState {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Base class defining a collection of turn state scopes.
|
|
44
|
+
*
|
|
45
|
+
* @typeParam TConversationState - Type for conversation-scoped state
|
|
46
|
+
* @typeParam TUserState - Type for user-scoped state
|
|
47
|
+
* @typeParam TTempState - Type for temporary state that exists only for the current turn
|
|
48
|
+
* @typeParam TSSOState - Type for Single Sign-On (SSO) state
|
|
49
|
+
*
|
|
44
50
|
* @remarks
|
|
45
51
|
* Developers can create a derived class that extends `TurnState` to add additional state scopes.
|
|
46
52
|
*
|
|
47
53
|
* @example
|
|
48
|
-
* ```
|
|
54
|
+
* ```javascript
|
|
49
55
|
* class MyTurnState extends TurnState {
|
|
50
56
|
* protected async onComputeStorageKeys(context) {
|
|
51
57
|
* const keys = await super.onComputeStorageKeys(context);
|
|
@@ -70,10 +76,7 @@ export interface DefaultTempState {
|
|
|
70
76
|
* }
|
|
71
77
|
* }
|
|
72
78
|
* ```
|
|
73
|
-
*
|
|
74
|
-
* @typeParam TUserState - Type for user-scoped state
|
|
75
|
-
* @typeParam TTempState - Type for temporary state that exists only for the current turn
|
|
76
|
-
* @typeParam TSSOState - Type for Single Sign-On (SSO) state
|
|
79
|
+
*
|
|
77
80
|
*/
|
|
78
81
|
export class TurnState<
|
|
79
82
|
TConversationState = DefaultConversationState,
|
|
@@ -87,9 +90,12 @@ export class TurnState<
|
|
|
87
90
|
|
|
88
91
|
/**
|
|
89
92
|
* Gets the conversation-scoped state.
|
|
90
|
-
*
|
|
93
|
+
*
|
|
91
94
|
* @returns The conversation state object
|
|
92
95
|
* @throws Error if state hasn't been loaded
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* This state is shared by all users in the same conversation.
|
|
93
99
|
*/
|
|
94
100
|
public get conversation (): TConversationState {
|
|
95
101
|
const scope = this.getScope(CONVERSATION_SCOPE)
|
|
@@ -101,6 +107,7 @@ export class TurnState<
|
|
|
101
107
|
|
|
102
108
|
/**
|
|
103
109
|
* Sets the conversation-scoped state.
|
|
110
|
+
*
|
|
104
111
|
* @param value - The new conversation state object
|
|
105
112
|
* @throws Error if state hasn't been loaded
|
|
106
113
|
*/
|
|
@@ -114,6 +121,7 @@ export class TurnState<
|
|
|
114
121
|
|
|
115
122
|
/**
|
|
116
123
|
* Gets whether the state has been loaded from storage
|
|
124
|
+
*
|
|
117
125
|
* @returns True if the state has been loaded, false otherwise
|
|
118
126
|
*/
|
|
119
127
|
public get isLoaded (): boolean {
|
|
@@ -122,9 +130,12 @@ export class TurnState<
|
|
|
122
130
|
|
|
123
131
|
/**
|
|
124
132
|
* Gets the temporary state for the current turn.
|
|
125
|
-
*
|
|
133
|
+
*
|
|
126
134
|
* @returns The temporary state object
|
|
127
135
|
* @throws Error if state hasn't been loaded
|
|
136
|
+
*
|
|
137
|
+
* @remarks
|
|
138
|
+
* This state is not persisted between turns.
|
|
128
139
|
*/
|
|
129
140
|
public get temp (): TTempState {
|
|
130
141
|
const scope = this.getScope(TEMP_SCOPE)
|
|
@@ -136,6 +147,7 @@ export class TurnState<
|
|
|
136
147
|
|
|
137
148
|
/**
|
|
138
149
|
* Sets the temporary state for the current turn.
|
|
150
|
+
*
|
|
139
151
|
* @param value - The new temporary state object
|
|
140
152
|
* @throws Error if state hasn't been loaded
|
|
141
153
|
*/
|
|
@@ -149,9 +161,12 @@ export class TurnState<
|
|
|
149
161
|
|
|
150
162
|
/**
|
|
151
163
|
* Gets the user-scoped state.
|
|
152
|
-
*
|
|
164
|
+
*
|
|
153
165
|
* @returns The user state object
|
|
154
166
|
* @throws Error if state hasn't been loaded
|
|
167
|
+
*
|
|
168
|
+
* @remarks
|
|
169
|
+
* This state is unique to each user and persists across conversations.
|
|
155
170
|
*/
|
|
156
171
|
public get user (): TUserState {
|
|
157
172
|
const scope = this.getScope(USER_SCOPE)
|
|
@@ -163,6 +178,7 @@ export class TurnState<
|
|
|
163
178
|
|
|
164
179
|
/**
|
|
165
180
|
* Sets the user-scoped state.
|
|
181
|
+
*
|
|
166
182
|
* @param value - The new user state object
|
|
167
183
|
* @throws Error if state hasn't been loaded
|
|
168
184
|
*/
|
|
@@ -176,8 +192,11 @@ export class TurnState<
|
|
|
176
192
|
|
|
177
193
|
/**
|
|
178
194
|
* Marks the conversation state for deletion.
|
|
179
|
-
*
|
|
195
|
+
*
|
|
180
196
|
* @throws Error if state hasn't been loaded
|
|
197
|
+
*
|
|
198
|
+
* @remarks
|
|
199
|
+
* The state will be deleted from storage on the next call to save().
|
|
181
200
|
*/
|
|
182
201
|
public deleteConversationState (): void {
|
|
183
202
|
const scope = this.getScope(CONVERSATION_SCOPE)
|
|
@@ -189,8 +208,11 @@ export class TurnState<
|
|
|
189
208
|
|
|
190
209
|
/**
|
|
191
210
|
* Marks the temporary state for deletion.
|
|
192
|
-
*
|
|
211
|
+
*
|
|
193
212
|
* @throws Error if state hasn't been loaded
|
|
213
|
+
*
|
|
214
|
+
* @remarks
|
|
215
|
+
* Since temporary state is not persisted, this just clears the in-memory object.
|
|
194
216
|
*/
|
|
195
217
|
public deleteTempState (): void {
|
|
196
218
|
const scope = this.getScope(TEMP_SCOPE)
|
|
@@ -202,8 +224,11 @@ export class TurnState<
|
|
|
202
224
|
|
|
203
225
|
/**
|
|
204
226
|
* Marks the user state for deletion.
|
|
205
|
-
*
|
|
227
|
+
*
|
|
206
228
|
* @throws Error if state hasn't been loaded
|
|
229
|
+
*
|
|
230
|
+
* @remarks
|
|
231
|
+
* The state will be deleted from storage on the next call to save().
|
|
207
232
|
*/
|
|
208
233
|
public deleteUserState (): void {
|
|
209
234
|
const scope = this.getScope(USER_SCOPE)
|
|
@@ -215,6 +240,7 @@ export class TurnState<
|
|
|
215
240
|
|
|
216
241
|
/**
|
|
217
242
|
* Gets a specific state scope by name.
|
|
243
|
+
*
|
|
218
244
|
* @param scope - The name of the scope to retrieve
|
|
219
245
|
* @returns The state entry for the scope, or undefined if not found
|
|
220
246
|
*/
|
|
@@ -224,8 +250,11 @@ export class TurnState<
|
|
|
224
250
|
|
|
225
251
|
/**
|
|
226
252
|
* Deletes a value from state by dot-notation path.
|
|
227
|
-
*
|
|
253
|
+
*
|
|
228
254
|
* @param path - The path to the value to delete
|
|
255
|
+
*
|
|
256
|
+
* @remarks
|
|
257
|
+
* Format: "scope.property" or just "property" (defaults to temp scope)
|
|
229
258
|
*/
|
|
230
259
|
public deleteValue (path: string): void {
|
|
231
260
|
const { scope, name } = this.getScopeAndName(path)
|
|
@@ -236,9 +265,12 @@ export class TurnState<
|
|
|
236
265
|
|
|
237
266
|
/**
|
|
238
267
|
* Checks if a value exists in state by dot-notation path.
|
|
239
|
-
*
|
|
268
|
+
*
|
|
240
269
|
* @param path - The path to check
|
|
241
270
|
* @returns True if the value exists, false otherwise
|
|
271
|
+
*
|
|
272
|
+
* @remarks
|
|
273
|
+
* Format: "scope.property" or just "property" (defaults to temp scope)
|
|
242
274
|
*/
|
|
243
275
|
public hasValue (path: string): boolean {
|
|
244
276
|
const { scope, name } = this.getScopeAndName(path)
|
|
@@ -247,10 +279,13 @@ export class TurnState<
|
|
|
247
279
|
|
|
248
280
|
/**
|
|
249
281
|
* Gets a value from state by dot-notation path.
|
|
250
|
-
*
|
|
282
|
+
*
|
|
251
283
|
* @typeParam TValue - The type of the value to retrieve
|
|
252
284
|
* @param path - The path to the value
|
|
253
285
|
* @returns The value at the specified path
|
|
286
|
+
*
|
|
287
|
+
* @remarks
|
|
288
|
+
* Format: "scope.property" or just "property" (defaults to temp scope)
|
|
254
289
|
*/
|
|
255
290
|
public getValue<TValue = unknown>(path: string): TValue {
|
|
256
291
|
const { scope, name } = this.getScopeAndName(path)
|
|
@@ -259,9 +294,12 @@ export class TurnState<
|
|
|
259
294
|
|
|
260
295
|
/**
|
|
261
296
|
* Sets a value in state by dot-notation path.
|
|
262
|
-
*
|
|
297
|
+
*
|
|
263
298
|
* @param path - The path to set
|
|
264
299
|
* @param value - The value to set
|
|
300
|
+
*
|
|
301
|
+
* @remarks
|
|
302
|
+
* Format: "scope.property" or just "property" (defaults to temp scope)
|
|
265
303
|
*/
|
|
266
304
|
public setValue (path: string, value: unknown): void {
|
|
267
305
|
const { scope, name } = this.getScopeAndName(path)
|
|
@@ -270,6 +308,7 @@ export class TurnState<
|
|
|
270
308
|
|
|
271
309
|
/**
|
|
272
310
|
* Loads state from storage into memory.
|
|
311
|
+
*
|
|
273
312
|
* @param context - The turn context
|
|
274
313
|
* @param storage - Optional storage provider (if not provided, state will be in-memory only)
|
|
275
314
|
* @param force - If true, forces a reload from storage even if state is already loaded
|
|
@@ -321,11 +360,14 @@ export class TurnState<
|
|
|
321
360
|
|
|
322
361
|
/**
|
|
323
362
|
* Saves state changes to storage.
|
|
324
|
-
*
|
|
363
|
+
*
|
|
325
364
|
* @param context - The turn context
|
|
326
365
|
* @param storage - Optional storage provider (if not provided, state changes won't be persisted)
|
|
327
366
|
* @returns Promise that resolves when the save operation is complete
|
|
328
367
|
* @throws Error if state hasn't been loaded
|
|
368
|
+
*
|
|
369
|
+
* @remarks
|
|
370
|
+
* Only changed scopes will be persisted.
|
|
329
371
|
*/
|
|
330
372
|
public async save (context: TurnContext, storage?: Storage): Promise<void> {
|
|
331
373
|
if (!this._isLoaded && this._loadingPromise) {
|
|
@@ -378,9 +420,13 @@ export class TurnState<
|
|
|
378
420
|
|
|
379
421
|
/**
|
|
380
422
|
* Computes the storage keys for each scope based on the turn context.
|
|
381
|
-
*
|
|
423
|
+
*
|
|
382
424
|
* @param context - The turn context
|
|
383
425
|
* @returns Promise that resolves to a dictionary of scope names to storage keys
|
|
426
|
+
*
|
|
427
|
+
* @remarks
|
|
428
|
+
* Override this method in derived classes to add or modify storage keys.
|
|
429
|
+
*
|
|
384
430
|
* @protected
|
|
385
431
|
*/
|
|
386
432
|
protected onComputeStorageKeys (context: TurnContext): Promise<Record<string, string>> {
|
|
@@ -414,9 +460,13 @@ export class TurnState<
|
|
|
414
460
|
|
|
415
461
|
/**
|
|
416
462
|
* Parses a dot-notation path into scope and property name.
|
|
417
|
-
*
|
|
463
|
+
*
|
|
418
464
|
* @param path - The path to parse (format: "scope.property" or just "property")
|
|
419
465
|
* @returns Object containing the scope entry and property name
|
|
466
|
+
*
|
|
467
|
+
* @remarks
|
|
468
|
+
* If no scope is specified, defaults to the temp scope.
|
|
469
|
+
*
|
|
420
470
|
* @private
|
|
421
471
|
*/
|
|
422
472
|
private getScopeAndName (path: string): { scope: TurnStateEntry; name: string } {
|
|
@@ -48,10 +48,12 @@ export interface AuthConfiguration {
|
|
|
48
48
|
FICClientId?: string,
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
* Entra Authentication Endpoint to use
|
|
51
|
+
* Entra Authentication Endpoint to use.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* If not populated the Entra Public Cloud endpoint is assumed.
|
|
52
55
|
* This example of Public Cloud Endpoint is https://login.microsoftonline.com
|
|
53
|
-
|
|
54
|
-
see also https://learn.microsoft.com/entra/identity-platform/authentication-national-cloud
|
|
56
|
+
* see also https://learn.microsoft.com/entra/identity-platform/authentication-national-cloud
|
|
55
57
|
*/
|
|
56
58
|
authority?: string
|
|
57
59
|
}
|
|
@@ -59,6 +61,12 @@ export interface AuthConfiguration {
|
|
|
59
61
|
/**
|
|
60
62
|
* Loads the authentication configuration from environment variables.
|
|
61
63
|
*
|
|
64
|
+
* @returns The authentication configuration.
|
|
65
|
+
* @throws Will throw an error if clientId is not provided in production.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* - `clientId` is required
|
|
69
|
+
*
|
|
62
70
|
* @example
|
|
63
71
|
* ```
|
|
64
72
|
* tenantId=your-tenant-id
|
|
@@ -73,10 +81,7 @@ export interface AuthConfiguration {
|
|
|
73
81
|
* connectionName=your-connection-name
|
|
74
82
|
* authority=your-authority-endpoint
|
|
75
83
|
* ```
|
|
76
|
-
*
|
|
77
|
-
* - `clientId` is required
|
|
78
|
-
* @returns The authentication configuration.
|
|
79
|
-
* @throws Will throw an error if clientId is not provided in production.
|
|
84
|
+
*
|
|
80
85
|
*/
|
|
81
86
|
export const loadAuthConfigFromEnv: (cnxName?: string) => AuthConfiguration = (cnxName?: string) => {
|
|
82
87
|
if (cnxName === undefined) {
|
|
@@ -122,14 +127,16 @@ export const loadAuthConfigFromEnv: (cnxName?: string) => AuthConfiguration = (c
|
|
|
122
127
|
/**
|
|
123
128
|
* Loads the agent authentication configuration from previous version environment variables.
|
|
124
129
|
*
|
|
130
|
+
* @returns The agent authentication configuration.
|
|
131
|
+
* @throws Will throw an error if MicrosoftAppId is not provided in production.
|
|
132
|
+
*
|
|
125
133
|
* @example
|
|
126
134
|
* ```
|
|
127
135
|
* MicrosoftAppId=your-client-id
|
|
128
136
|
* MicrosoftAppPassword=your-client-secret
|
|
129
137
|
* MicrosoftAppTenantId=your-tenant-id
|
|
130
138
|
* ```
|
|
131
|
-
*
|
|
132
|
-
* @throws Will throw an error if MicrosoftAppId is not provided in production.
|
|
139
|
+
*
|
|
133
140
|
*/
|
|
134
141
|
export const loadPrevAuthConfigFromEnv: () => AuthConfiguration = () => {
|
|
135
142
|
if (process.env.MicrosoftAppId === undefined && process.env.NODE_ENV === 'production') {
|
|
@@ -72,25 +72,32 @@ export const authorizeJWT = (authConfig: AuthConfiguration) => {
|
|
|
72
72
|
return async function (req: Request, res: Response, next: NextFunction) {
|
|
73
73
|
let failed = false
|
|
74
74
|
logger.debug('authorizing jwt')
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const user = await verifyToken(token, authConfig)
|
|
80
|
-
logger.debug('token verified for ', user)
|
|
81
|
-
req.user = user
|
|
82
|
-
} catch (err: Error | any) {
|
|
83
|
-
failed = true
|
|
84
|
-
logger.error(err)
|
|
85
|
-
res.status(401).send({ 'jwt-auth-error': err.message })
|
|
86
|
-
}
|
|
75
|
+
if (req.method !== 'POST' && req.method !== 'GET') {
|
|
76
|
+
failed = true
|
|
77
|
+
logger.warn('Method not allowed', req.method)
|
|
78
|
+
res.status(405).send({ 'jwt-auth-error': 'Method not allowed' })
|
|
87
79
|
} else {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
80
|
+
const authHeader = req.headers.authorization as string
|
|
81
|
+
if (authHeader) {
|
|
82
|
+
const token: string = authHeader.split(' ')[1] // Extract the token from the Bearer string
|
|
83
|
+
try {
|
|
84
|
+
const user = await verifyToken(token, authConfig)
|
|
85
|
+
logger.debug('token verified for ', user)
|
|
86
|
+
req.user = user
|
|
87
|
+
} catch (err: Error | any) {
|
|
88
|
+
failed = true
|
|
89
|
+
logger.error(err)
|
|
90
|
+
res.status(401).send({ 'jwt-auth-error': err.message })
|
|
91
|
+
}
|
|
91
92
|
} else {
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
if (!authConfig.clientId && process.env.NODE_ENV !== 'production') {
|
|
94
|
+
logger.info('using anonymous auth')
|
|
95
|
+
req.user = { name: 'anonymous' }
|
|
96
|
+
} else {
|
|
97
|
+
failed = true
|
|
98
|
+
logger.error('authorization header not found')
|
|
99
|
+
res.status(401).send({ 'jwt-auth-error': 'authorization header not found' })
|
|
100
|
+
}
|
|
94
101
|
}
|
|
95
102
|
}
|
|
96
103
|
if (!failed) {
|
package/src/cloudAdapter.ts
CHANGED
|
@@ -165,6 +165,8 @@ export class CloudAdapter extends BaseAdapter {
|
|
|
165
165
|
throw new Error('Invalid activity object')
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
this.connectorClient = await this.createConnectorClient(activity.serviceUrl, 'https://api.botframework.com')
|
|
169
|
+
|
|
168
170
|
if (activity.replyToId) {
|
|
169
171
|
response = await this.connectorClient.replyToActivity(activity.conversation.id, activity.replyToId, activity)
|
|
170
172
|
} else {
|
package/src/headerPropagation.ts
CHANGED
|
@@ -94,36 +94,48 @@ export interface HeaderPropagationDefinition {
|
|
|
94
94
|
export interface HeaderPropagationCollection {
|
|
95
95
|
/**
|
|
96
96
|
* The collection of incoming headers from the incoming request.
|
|
97
|
-
*
|
|
97
|
+
*
|
|
98
|
+
* @remarks
|
|
99
|
+
* This collection is built based on the headers received in the request.
|
|
98
100
|
*/
|
|
99
101
|
incoming: Record<string, string>
|
|
100
102
|
/**
|
|
101
103
|
* The collection of headers that will be propagated to outgoing requests.
|
|
102
|
-
*
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* This collection is built based on the incoming headers and the definition provided.
|
|
103
107
|
*/
|
|
104
108
|
outgoing: Record<string, string>
|
|
105
109
|
/**
|
|
106
110
|
* Propagates the incoming header value to the outgoing collection based on the header definition key.
|
|
107
111
|
* @param headers List of header keys to propagate.
|
|
108
|
-
*
|
|
112
|
+
*
|
|
113
|
+
* @remarks
|
|
114
|
+
* If the header does not exist in the incoming headers, it will be ignored.
|
|
109
115
|
*/
|
|
110
116
|
propagate(headers: string[]): void
|
|
111
117
|
/**
|
|
112
118
|
* Adds a header definition to the outgoing collection.
|
|
113
119
|
* @param headers Headers to add to the outgoing collection.
|
|
114
|
-
*
|
|
120
|
+
*
|
|
121
|
+
* @remarks
|
|
122
|
+
* If the header already exists, it will not be added.
|
|
115
123
|
*/
|
|
116
124
|
add(headers: Record<string, string>): void
|
|
117
125
|
/**
|
|
118
126
|
* Concatenates a header definition to the outgoing collection.
|
|
119
127
|
* @param headers Headers to concatenate to the outgoing collection.
|
|
120
|
-
*
|
|
128
|
+
*
|
|
129
|
+
* @remarks
|
|
130
|
+
* If the header does not exist in the incoming headers, it will be ignored. Unless the header is already present in the outgoing collection.
|
|
121
131
|
*/
|
|
122
132
|
concat(headers: Record<string, string>): void
|
|
123
133
|
/**
|
|
124
134
|
* Overrides a header definition in the outgoing collection.
|
|
125
135
|
* @param headers Headers to override in the outgoing collection.
|
|
126
|
-
*
|
|
136
|
+
*
|
|
137
|
+
* @remarks
|
|
138
|
+
* If the header does not exist in the incoming headers, it will be added to the outgoing collection.
|
|
127
139
|
*/
|
|
128
140
|
override(headers: Record<string, string>): void
|
|
129
141
|
}
|
package/src/index.ts
CHANGED
|
@@ -17,7 +17,6 @@ export class UserTokenClient {
|
|
|
17
17
|
client: AxiosInstance
|
|
18
18
|
/**
|
|
19
19
|
* Creates a new instance of UserTokenClient.
|
|
20
|
-
* @param token The token to use for authentication.
|
|
21
20
|
* @param msAppId The Microsoft application ID.
|
|
22
21
|
*/
|
|
23
22
|
constructor (private msAppId: string) {
|
|
@@ -116,7 +115,8 @@ export class UserTokenClient {
|
|
|
116
115
|
* Gets the sign-in resource.
|
|
117
116
|
* @param msAppId The application ID.
|
|
118
117
|
* @param connectionName The connection name.
|
|
119
|
-
* @param
|
|
118
|
+
* @param conversation The conversation reference.
|
|
119
|
+
* @param relatesTo Optional. The related conversation reference.
|
|
120
120
|
* @returns A promise that resolves to the signing resource.
|
|
121
121
|
*/
|
|
122
122
|
async getSignInResource (msAppId: string, connectionName: string, conversation: ConversationReference, relatesTo?: ConversationReference) : Promise<SignInResource> {
|
package/src/state/agentState.ts
CHANGED
|
@@ -13,6 +13,8 @@ const logger = debug('agents:state')
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Represents agent state that has been cached in the turn context.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
16
18
|
* Used internally to track state changes and avoid unnecessary storage operations.
|
|
17
19
|
*/
|
|
18
20
|
export interface CachedAgentState {
|
|
@@ -28,6 +30,8 @@ export interface CachedAgentState {
|
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* Represents a custom key for storing state in a specific location.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
31
35
|
* Allows state to be persisted with channel and conversation identifiers
|
|
32
36
|
* independent of the current context.
|
|
33
37
|
*/
|
|
@@ -44,7 +48,8 @@ export interface CustomKey {
|
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
/**
|
|
47
|
-
*
|
|
51
|
+
* Manages the state of an Agent across turns in a conversation.
|
|
52
|
+
*
|
|
48
53
|
* @remarks
|
|
49
54
|
* AgentState provides functionality to persist and retrieve state data using
|
|
50
55
|
* a storage provider. It handles caching state in the turn context for performance,
|
|
@@ -64,10 +69,12 @@ export class AgentState {
|
|
|
64
69
|
|
|
65
70
|
/**
|
|
66
71
|
* Creates a property accessor for the specified property.
|
|
67
|
-
* Property accessors provide typed access to properties within the state object.
|
|
68
72
|
*
|
|
69
73
|
* @param name The name of the property to access
|
|
70
74
|
* @returns A property accessor for the specified property
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* Property accessors provide typed access to properties within the state object.
|
|
71
78
|
*/
|
|
72
79
|
createProperty<T = any>(name: string): AgentStatePropertyAccessor<T> {
|
|
73
80
|
const prop: AgentStatePropertyAccessor<T> = new AgentStatePropertyAccessor<T>(this, name)
|
|
@@ -76,12 +83,14 @@ export class AgentState {
|
|
|
76
83
|
|
|
77
84
|
/**
|
|
78
85
|
* Loads the state from storage into the turn context.
|
|
79
|
-
* If state is already cached in the turn context and force is not set, the cached version will be used.
|
|
80
86
|
*
|
|
81
87
|
* @param context The turn context to load state into
|
|
82
88
|
* @param force If true, forces a reload from storage even if state is cached
|
|
83
89
|
* @param customKey Optional custom storage key to use instead of the default
|
|
84
90
|
* @returns A promise that resolves to the loaded state object
|
|
91
|
+
*
|
|
92
|
+
* @remarks
|
|
93
|
+
* If state is already cached in the turn context and force is not set, the cached version will be used.
|
|
85
94
|
*/
|
|
86
95
|
public async load (context: TurnContext, force = false, customKey?: CustomKey): Promise<any> {
|
|
87
96
|
const cached: CachedAgentState = context.turnState.get(this.stateKey)
|
|
@@ -103,12 +112,14 @@ export class AgentState {
|
|
|
103
112
|
|
|
104
113
|
/**
|
|
105
114
|
* Saves the state to storage if it has changed since it was loaded.
|
|
106
|
-
* Change detection uses a hash of the state object to determine if saving is necessary.
|
|
107
115
|
*
|
|
108
116
|
* @param context The turn context containing the state to save
|
|
109
117
|
* @param force If true, forces a save to storage even if no changes are detected
|
|
110
118
|
* @param customKey Optional custom storage key to use instead of the default
|
|
111
119
|
* @returns A promise that resolves when the save operation is complete
|
|
120
|
+
*
|
|
121
|
+
* @remarks
|
|
122
|
+
* Change detection uses a hash of the state object to determine if saving is necessary.
|
|
112
123
|
*/
|
|
113
124
|
public async saveChanges (context: TurnContext, force = false, customKey?: CustomKey): Promise<void> {
|
|
114
125
|
let cached: CachedAgentState = context.turnState.get(this.stateKey)
|
|
@@ -151,11 +162,14 @@ export class AgentState {
|
|
|
151
162
|
|
|
152
163
|
/**
|
|
153
164
|
* Clears the state by setting it to an empty object in the turn context.
|
|
154
|
-
* Note: This does not remove the state from storage, it only clears the in-memory representation.
|
|
155
|
-
* Call saveChanges() after this to persist the empty state to storage.
|
|
156
165
|
*
|
|
157
166
|
* @param context The turn context containing the state to clear
|
|
158
167
|
* @returns A promise that resolves when the clear operation is complete
|
|
168
|
+
*
|
|
169
|
+
* @remarks
|
|
170
|
+
* This does not remove the state from storage, it only clears the in-memory representation.
|
|
171
|
+
* Call saveChanges() after this to persist the empty state to storage.
|
|
172
|
+
*
|
|
159
173
|
*/
|
|
160
174
|
public async clear (context: TurnContext): Promise<void> {
|
|
161
175
|
const emptyObjectToForceSave = { state: {}, hash: '' }
|
|
@@ -193,10 +207,12 @@ export class AgentState {
|
|
|
193
207
|
|
|
194
208
|
/**
|
|
195
209
|
* Calculates a hash for the specified state object to detect changes.
|
|
196
|
-
* The eTag property is excluded from the hash calculation.
|
|
197
210
|
*
|
|
198
211
|
* @param item The state object to calculate the hash for
|
|
199
212
|
* @returns A string hash representing the state
|
|
213
|
+
*
|
|
214
|
+
* @remarks
|
|
215
|
+
* The eTag property is excluded from the hash calculation.
|
|
200
216
|
* @private
|
|
201
217
|
*/
|
|
202
218
|
private readonly calculateChangeHash = (item: StoreItem): string => {
|