@microsoft/agents-hosting 1.9.0-beta.3.gb2d23c1c44 → 1.9.1
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/README.md +182 -4
- package/dist/package.json +3 -3
- package/dist/src/app/agentApplication.d.ts +4 -3
- package/dist/src/app/agentApplication.js +24 -21
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationBuilder.d.ts +9 -2
- package/dist/src/app/agentApplicationBuilder.js +9 -0
- package/dist/src/app/agentApplicationBuilder.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +16 -4
- package/dist/src/app/auth/authorization.d.ts +54 -0
- package/dist/src/app/auth/authorization.js +63 -2
- package/dist/src/app/auth/authorization.js.map +1 -1
- package/dist/src/app/auth/authorizationManager.d.ts +0 -8
- package/dist/src/app/auth/authorizationManager.js +104 -178
- package/dist/src/app/auth/authorizationManager.js.map +1 -1
- package/dist/src/app/auth/handlerStorage.d.ts +5 -3
- package/dist/src/app/auth/handlerStorage.js +36 -10
- package/dist/src/app/auth/handlerStorage.js.map +1 -1
- package/dist/src/app/auth/types.d.ts +2 -2
- package/dist/src/app/index.d.ts +1 -0
- package/dist/src/app/proactive/proactive.js +10 -6
- package/dist/src/app/proactive/proactive.js.map +1 -1
- package/dist/src/app/proactive/proactiveOptions.d.ts +2 -2
- package/dist/src/app/rateLimit.d.ts +315 -0
- package/dist/src/app/rateLimit.js +333 -0
- package/dist/src/app/rateLimit.js.map +1 -0
- package/dist/src/app/turnState.d.ts +6 -3
- package/dist/src/app/turnState.js +43 -4
- package/dist/src/app/turnState.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +10 -3
- package/dist/src/auth/authConfiguration.js +292 -259
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/delegatedTokenCredential.d.ts +29 -0
- package/dist/src/auth/delegatedTokenCredential.js +49 -0
- package/dist/src/auth/delegatedTokenCredential.js.map +1 -0
- package/dist/src/auth/msal/msalTokenCredential.js +1 -1
- package/dist/src/auth/msal/msalTokenCredential.js.map +1 -1
- package/dist/src/auth/settings.d.ts +8 -70
- package/dist/src/auth/settings.js +5 -67
- package/dist/src/auth/settings.js.map +1 -1
- package/dist/src/cloudAdapter.d.ts +5 -0
- package/dist/src/cloudAdapter.js +13 -103
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/configuration/botFrameworkEnvironmentCompatibility.d.ts +23 -0
- package/dist/src/configuration/botFrameworkEnvironmentCompatibility.js +183 -0
- package/dist/src/configuration/botFrameworkEnvironmentCompatibility.js.map +1 -0
- package/dist/src/configuration/configuration.d.ts +83 -0
- package/dist/src/configuration/configuration.js +836 -0
- package/dist/src/configuration/configuration.js.map +1 -0
- package/dist/src/configuration/configurationSource.d.ts +57 -0
- package/dist/src/configuration/configurationSource.js +7 -0
- package/dist/src/configuration/configurationSource.js.map +1 -0
- package/dist/src/configuration/environmentConfiguration.d.ts +14 -0
- package/dist/src/configuration/environmentConfiguration.js +271 -0
- package/dist/src/configuration/environmentConfiguration.js.map +1 -0
- package/dist/src/configuration/index.d.ts +7 -0
- package/dist/src/configuration/index.js +14 -0
- package/dist/src/configuration/index.js.map +1 -0
- package/dist/src/configuration/jsonFileConfigurationSource.d.ts +15 -0
- package/dist/src/configuration/jsonFileConfigurationSource.js +58 -0
- package/dist/src/configuration/jsonFileConfigurationSource.js.map +1 -0
- package/dist/src/createCloudAdapter.d.ts +30 -5
- package/dist/src/createCloudAdapter.js +17 -10
- package/dist/src/createCloudAdapter.js.map +1 -1
- package/dist/src/errorHelper.js +124 -5
- package/dist/src/errorHelper.js.map +1 -1
- 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/observability/traces.d.ts +6 -4
- package/dist/src/observability/traces.js +10 -9
- package/dist/src/observability/traces.js.map +1 -1
- package/dist/src/outboundHostValidator.d.ts +4 -1
- package/dist/src/outboundHostValidator.js +25 -48
- package/dist/src/outboundHostValidator.js.map +1 -1
- package/dist/src/state/agentState.d.ts +8 -3
- package/dist/src/state/agentState.js +26 -8
- package/dist/src/state/agentState.js.map +1 -1
- package/dist/src/state/conversationState.d.ts +2 -2
- package/dist/src/state/conversationState.js.map +1 -1
- package/dist/src/state/userState.d.ts +2 -2
- package/dist/src/state/userState.js.map +1 -1
- package/dist/src/statusCodes.d.ts +5 -0
- package/dist/src/statusCodes.js +5 -0
- package/dist/src/statusCodes.js.map +1 -1
- package/dist/src/storage/fileStorage.d.ts +83 -68
- package/dist/src/storage/fileStorage.js +279 -105
- package/dist/src/storage/fileStorage.js.map +1 -1
- package/dist/src/storage/index.d.ts +1 -0
- package/dist/src/storage/index.js +1 -0
- package/dist/src/storage/index.js.map +1 -1
- package/dist/src/storage/memoryStorage.d.ts +85 -60
- package/dist/src/storage/memoryStorage.js +244 -87
- package/dist/src/storage/memoryStorage.js.map +1 -1
- package/dist/src/storage/storage.d.ts +100 -2
- package/dist/src/storage/storage.js +25 -0
- package/dist/src/storage/storage.js.map +1 -1
- package/dist/src/storage/storageCompatibility.d.ts +17 -0
- package/dist/src/storage/storageCompatibility.js +157 -0
- package/dist/src/storage/storageCompatibility.js.map +1 -0
- package/dist/src/storage/storageExpiry.d.ts +6 -0
- package/dist/src/storage/storageExpiry.js +20 -0
- package/dist/src/storage/storageExpiry.js.map +1 -0
- package/dist/src/utils/env.d.ts +43 -0
- package/dist/src/utils/env.js +42 -6
- package/dist/src/utils/env.js.map +1 -1
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.js +10 -1
- package/dist/src/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/app/agentApplication.ts +27 -14
- package/src/app/agentApplicationBuilder.ts +13 -2
- package/src/app/agentApplicationOptions.ts +18 -4
- package/src/app/auth/authorization.ts +67 -2
- package/src/app/auth/authorizationManager.ts +126 -204
- package/src/app/auth/handlerStorage.ts +51 -7
- package/src/app/auth/types.ts +2 -2
- package/src/app/index.ts +7 -0
- package/src/app/proactive/proactive.ts +19 -9
- package/src/app/proactive/proactiveOptions.ts +2 -2
- package/src/app/rateLimit.ts +659 -0
- package/src/app/turnState.ts +50 -7
- package/src/auth/authConfiguration.ts +415 -260
- package/src/auth/delegatedTokenCredential.ts +49 -0
- package/src/auth/msal/msalTokenCredential.ts +1 -1
- package/src/auth/settings.ts +5 -82
- package/src/cloudAdapter.ts +38 -113
- package/src/configuration/botFrameworkEnvironmentCompatibility.ts +245 -0
- package/src/configuration/configuration.ts +1076 -0
- package/src/configuration/configurationSource.ts +76 -0
- package/src/configuration/environmentConfiguration.ts +377 -0
- package/src/configuration/index.ts +19 -0
- package/src/configuration/jsonFileConfigurationSource.ts +74 -0
- package/src/createCloudAdapter.ts +52 -9
- package/src/errorHelper.ts +151 -5
- package/src/index.ts +1 -0
- package/src/observability/traces.ts +8 -7
- package/src/outboundHostValidator.ts +37 -44
- package/src/state/agentState.ts +39 -13
- package/src/state/conversationState.ts +2 -2
- package/src/state/userState.ts +2 -2
- package/src/statusCodes.ts +6 -0
- package/src/storage/fileStorage.ts +299 -106
- package/src/storage/index.ts +1 -0
- package/src/storage/memoryStorage.ts +268 -85
- package/src/storage/storage.ts +114 -2
- package/src/storage/storageCompatibility.ts +185 -0
- package/src/storage/storageExpiry.ts +21 -0
- package/src/utils/env.ts +63 -0
- package/src/utils.ts +10 -0
package/src/app/turnState.ts
CHANGED
|
@@ -3,7 +3,14 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { StorageOperationStatus, StorageProvider, StorageReadResults, StorageWriteMode, StoreItems } from '../storage'
|
|
7
|
+
import {
|
|
8
|
+
asStorageV2,
|
|
9
|
+
assertAgentStateWriteSucceeded,
|
|
10
|
+
assertStorageDeleteSucceeded,
|
|
11
|
+
getStorageReadValue,
|
|
12
|
+
isStorageV2,
|
|
13
|
+
} from '../storage/storageCompatibility'
|
|
7
14
|
import { AppMemory } from './appMemory'
|
|
8
15
|
import { TurnStateEntry } from './turnStateEntry'
|
|
9
16
|
import { TurnContext } from '../turnContext'
|
|
@@ -73,6 +80,8 @@ export class TurnState<
|
|
|
73
80
|
TUserState = DefaultUserState
|
|
74
81
|
> implements AppMemory {
|
|
75
82
|
private _scopes: Record<string, TurnStateEntry> = {}
|
|
83
|
+
private _versions: Record<string, string | undefined> = {}
|
|
84
|
+
private _missingStorageKeys = new Set<string>()
|
|
76
85
|
private _isLoaded = false
|
|
77
86
|
private _loadingPromise?: Promise<boolean>
|
|
78
87
|
|
|
@@ -256,7 +265,7 @@ export class TurnState<
|
|
|
256
265
|
* @param force - If true, forces a reload from storage even if state is already loaded
|
|
257
266
|
* @returns Promise that resolves to true if state was loaded, false if it was already loaded
|
|
258
267
|
*/
|
|
259
|
-
public load (context: TurnContext, storage?:
|
|
268
|
+
public load (context: TurnContext, storage?: StorageProvider, force: boolean = false): Promise<boolean> {
|
|
260
269
|
if (this._isLoaded && !force) {
|
|
261
270
|
return Promise.resolve(false)
|
|
262
271
|
}
|
|
@@ -274,13 +283,21 @@ export class TurnState<
|
|
|
274
283
|
}
|
|
275
284
|
}
|
|
276
285
|
|
|
277
|
-
const items
|
|
286
|
+
const items: StorageReadResults<Record<string, unknown>> | undefined = storage
|
|
287
|
+
? await asStorageV2(storage).read<Record<string, unknown>>(keys)
|
|
288
|
+
: undefined
|
|
278
289
|
|
|
279
290
|
for (const key in scopes) {
|
|
280
291
|
if (Object.prototype.hasOwnProperty.call(scopes, key)) {
|
|
281
292
|
const storageKey = scopes[key]
|
|
282
|
-
const value = items
|
|
293
|
+
const value = storage ? getStorageReadValue(items, storageKey) : undefined
|
|
283
294
|
this._scopes[key] = new TurnStateEntry(value, storageKey)
|
|
295
|
+
this._versions[storageKey] = items?.[storageKey]?.version
|
|
296
|
+
if (items?.[storageKey]?.status === StorageOperationStatus.NotFound) {
|
|
297
|
+
this._missingStorageKeys.add(storageKey)
|
|
298
|
+
} else {
|
|
299
|
+
this._missingStorageKeys.delete(storageKey)
|
|
300
|
+
}
|
|
284
301
|
}
|
|
285
302
|
}
|
|
286
303
|
|
|
@@ -311,7 +328,7 @@ export class TurnState<
|
|
|
311
328
|
* @remarks
|
|
312
329
|
* Only changed scopes will be persisted.
|
|
313
330
|
*/
|
|
314
|
-
public async save (context: TurnContext, storage?:
|
|
331
|
+
public async save (context: TurnContext, storage?: StorageProvider): Promise<void> {
|
|
315
332
|
if (!this._isLoaded && this._loadingPromise) {
|
|
316
333
|
await this._loadingPromise
|
|
317
334
|
}
|
|
@@ -346,12 +363,34 @@ export class TurnState<
|
|
|
346
363
|
|
|
347
364
|
if (storage) {
|
|
348
365
|
const promises: Promise<void>[] = []
|
|
366
|
+
const storageV2 = asStorageV2(storage)
|
|
349
367
|
if (changes) {
|
|
350
|
-
|
|
368
|
+
for (const [key, value] of Object.entries(changes)) {
|
|
369
|
+
const expectedVersion = this._versions[key]
|
|
370
|
+
const options = expectedVersion !== undefined
|
|
371
|
+
? { expectedVersion }
|
|
372
|
+
: isStorageV2(storage) && this._missingStorageKeys.has(key)
|
|
373
|
+
? { mode: StorageWriteMode.CreateOnly }
|
|
374
|
+
: undefined
|
|
375
|
+
promises.push(storageV2.write(
|
|
376
|
+
{ [key]: value },
|
|
377
|
+
options
|
|
378
|
+
).then(results => {
|
|
379
|
+
assertAgentStateWriteSucceeded(results, key, this.getStorageScopeName(key))
|
|
380
|
+
this._versions[key] = results?.[key]?.version
|
|
381
|
+
this._missingStorageKeys.delete(key)
|
|
382
|
+
}))
|
|
383
|
+
}
|
|
351
384
|
}
|
|
352
385
|
|
|
353
386
|
if (deletions) {
|
|
354
|
-
promises.push(
|
|
387
|
+
promises.push(storageV2.delete(deletions).then(results => {
|
|
388
|
+
assertStorageDeleteSucceeded(results, deletions)
|
|
389
|
+
for (const key of deletions) {
|
|
390
|
+
delete this._versions[key]
|
|
391
|
+
this._missingStorageKeys.delete(key)
|
|
392
|
+
}
|
|
393
|
+
}))
|
|
355
394
|
}
|
|
356
395
|
|
|
357
396
|
if (promises.length > 0) {
|
|
@@ -360,6 +399,10 @@ export class TurnState<
|
|
|
360
399
|
}
|
|
361
400
|
}
|
|
362
401
|
|
|
402
|
+
private getStorageScopeName (storageKey: string): string {
|
|
403
|
+
return Object.entries(this._scopes).find(([, entry]) => entry.storageKey === storageKey)?.[0] ?? this.constructor.name
|
|
404
|
+
}
|
|
405
|
+
|
|
363
406
|
/**
|
|
364
407
|
* Computes the storage keys for each scope based on the turn context.
|
|
365
408
|
*
|