@microsoft/agents-hosting 1.9.0-beta.8.gf58e66b2ee → 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/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/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 +117 -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/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/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 +143 -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
|
@@ -5,10 +5,19 @@
|
|
|
5
5
|
|
|
6
6
|
import { ActiveAuthorizationHandler } from './types'
|
|
7
7
|
import { TurnContext } from '../../turnContext'
|
|
8
|
-
import {
|
|
8
|
+
import { StorageProvider, StorageV2 } from '../../storage'
|
|
9
|
+
import {
|
|
10
|
+
asStorageV2,
|
|
11
|
+
assertStorageDeleteSucceeded,
|
|
12
|
+
assertStorageWriteSucceeded,
|
|
13
|
+
getStorageReadValue,
|
|
14
|
+
} from '../../storage/storageCompatibility'
|
|
9
15
|
import { ExceptionHelper } from '@microsoft/agents-activity'
|
|
10
16
|
import { Errors } from '../../errorHelper'
|
|
11
17
|
|
|
18
|
+
// Version metadata only bridges reads and writes in one turn. Cloned contexts share turnState.
|
|
19
|
+
const HANDLER_STORAGE_VERSIONS = Symbol('handlerStorageVersions')
|
|
20
|
+
|
|
12
21
|
/**
|
|
13
22
|
* Storage manager for handler state.
|
|
14
23
|
*/
|
|
@@ -18,7 +27,11 @@ export class HandlerStorage<TActiveHandler extends ActiveAuthorizationHandler =
|
|
|
18
27
|
* @param storage The storage provider.
|
|
19
28
|
* @param context The turn context.
|
|
20
29
|
*/
|
|
21
|
-
|
|
30
|
+
private readonly storage: StorageV2
|
|
31
|
+
|
|
32
|
+
constructor (storage: StorageProvider, private context: TurnContext) {
|
|
33
|
+
this.storage = asStorageV2(storage)
|
|
34
|
+
}
|
|
22
35
|
|
|
23
36
|
/**
|
|
24
37
|
* Gets the unique key for a handler session.
|
|
@@ -36,15 +49,23 @@ export class HandlerStorage<TActiveHandler extends ActiveAuthorizationHandler =
|
|
|
36
49
|
* Reads the active handler state from storage.
|
|
37
50
|
*/
|
|
38
51
|
public async read (): Promise<TActiveHandler | undefined> {
|
|
39
|
-
const ongoing = await this.storage.read([this.key])
|
|
40
|
-
|
|
52
|
+
const ongoing = await this.storage.read<TActiveHandler>([this.key])
|
|
53
|
+
const value = getStorageReadValue(ongoing, this.key)
|
|
54
|
+
this.version = ongoing[this.key]?.version
|
|
55
|
+
return value
|
|
41
56
|
}
|
|
42
57
|
|
|
43
58
|
/**
|
|
44
59
|
* Writes handler state to storage.
|
|
45
60
|
*/
|
|
46
|
-
public write (data: TActiveHandler) : Promise<void> {
|
|
47
|
-
|
|
61
|
+
public async write (data: TActiveHandler) : Promise<void> {
|
|
62
|
+
const { eTag: _eTag, ...value } = data
|
|
63
|
+
const results = await this.storage.write(
|
|
64
|
+
{ [this.key]: value },
|
|
65
|
+
this.version === undefined ? undefined : { expectedVersion: this.version }
|
|
66
|
+
)
|
|
67
|
+
assertStorageWriteSucceeded(results, [this.key])
|
|
68
|
+
this.version = results[this.key]?.version
|
|
48
69
|
}
|
|
49
70
|
|
|
50
71
|
/**
|
|
@@ -52,7 +73,9 @@ export class HandlerStorage<TActiveHandler extends ActiveAuthorizationHandler =
|
|
|
52
73
|
*/
|
|
53
74
|
public async delete (): Promise<void> {
|
|
54
75
|
try {
|
|
55
|
-
await this.storage.delete([this.key])
|
|
76
|
+
const results = await this.storage.delete([this.key])
|
|
77
|
+
assertStorageDeleteSucceeded(results, [this.key])
|
|
78
|
+
this.version = undefined
|
|
56
79
|
} catch (error) {
|
|
57
80
|
if (error instanceof Error && 'code' in error && error.code === 404) {
|
|
58
81
|
return
|
|
@@ -60,4 +83,25 @@ export class HandlerStorage<TActiveHandler extends ActiveAuthorizationHandler =
|
|
|
60
83
|
throw error
|
|
61
84
|
}
|
|
62
85
|
}
|
|
86
|
+
|
|
87
|
+
private get version (): string | undefined {
|
|
88
|
+
return this.context.turnState.get<Map<string, string>>(HANDLER_STORAGE_VERSIONS)?.get(this.key)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private set version (value: string | undefined) {
|
|
92
|
+
let versions = this.context.turnState.get<Map<string, string>>(HANDLER_STORAGE_VERSIONS)
|
|
93
|
+
if (value === undefined) {
|
|
94
|
+
versions?.delete(this.key)
|
|
95
|
+
if (versions?.size === 0) {
|
|
96
|
+
this.context.turnState.delete(HANDLER_STORAGE_VERSIONS)
|
|
97
|
+
}
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!versions) {
|
|
102
|
+
versions = new Map<string, string>()
|
|
103
|
+
this.context.turnState.set(HANDLER_STORAGE_VERSIONS, versions)
|
|
104
|
+
}
|
|
105
|
+
versions.set(this.key, value)
|
|
106
|
+
}
|
|
63
107
|
}
|
package/src/app/auth/types.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { Activity } from '@microsoft/agents-activity'
|
|
7
|
-
import {
|
|
7
|
+
import { StorageProvider, StoreItem } from '../../storage'
|
|
8
8
|
import { TurnContext } from '../../turnContext'
|
|
9
9
|
import { AgenticAuthorizationOptions, AzureBotAuthorizationOptions } from './handlers'
|
|
10
10
|
import { TokenResponse } from '../../oauth'
|
|
@@ -97,7 +97,7 @@ export interface AuthorizationHandlerSettings {
|
|
|
97
97
|
/**
|
|
98
98
|
* Storage instance for persisting handler state.
|
|
99
99
|
*/
|
|
100
|
-
storage:
|
|
100
|
+
storage: StorageProvider
|
|
101
101
|
/**
|
|
102
102
|
* Connections instance for managing authentication connections.
|
|
103
103
|
*/
|
package/src/app/index.ts
CHANGED
|
@@ -28,3 +28,10 @@ export * from './streaming/streamingResponse'
|
|
|
28
28
|
export * from './streaming/citation'
|
|
29
29
|
export * from './teamsAttachmentDownloader'
|
|
30
30
|
export * from './proactive'
|
|
31
|
+
export type {
|
|
32
|
+
RateLimitMessageFactory,
|
|
33
|
+
RateLimitResult,
|
|
34
|
+
RateLimitRule,
|
|
35
|
+
RateLimitScope,
|
|
36
|
+
RateLimitStorageErrorBehavior
|
|
37
|
+
} from './rateLimit'
|
|
@@ -7,7 +7,13 @@ import type { BaseAdapter } from '../../baseAdapter'
|
|
|
7
7
|
import type { TurnContext } from '../../turnContext'
|
|
8
8
|
import type { TurnState } from '../turnState'
|
|
9
9
|
import type { RouteHandler } from '../routeHandler'
|
|
10
|
-
import type {
|
|
10
|
+
import type { StorageV2 } from '../../storage/storage'
|
|
11
|
+
import {
|
|
12
|
+
asStorageV2,
|
|
13
|
+
assertStorageDeleteSucceeded,
|
|
14
|
+
assertStorageWriteSucceeded,
|
|
15
|
+
getStorageReadValue,
|
|
16
|
+
} from '../../storage/storageCompatibility'
|
|
11
17
|
import type { AgentApplication } from '../agentApplication'
|
|
12
18
|
import type { ProactiveOptions } from './proactiveOptions'
|
|
13
19
|
import type { CreateConversationOptions } from './createConversationOptions'
|
|
@@ -41,31 +47,31 @@ export class Proactive<TState extends TurnState> {
|
|
|
41
47
|
|
|
42
48
|
private readonly _app: AgentApplication<TState>
|
|
43
49
|
private readonly _options: ProactiveOptions
|
|
44
|
-
private readonly _storage?:
|
|
50
|
+
private readonly _storage?: StorageV2
|
|
45
51
|
|
|
46
52
|
constructor (app: AgentApplication<TState>, options: ProactiveOptions) {
|
|
47
53
|
this._app = app
|
|
48
54
|
this._options = options
|
|
49
|
-
this._storage = options.storage
|
|
55
|
+
this._storage = options.storage ? asStorageV2(options.storage) : undefined
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
private _storageKey (conversationId: string): string {
|
|
53
59
|
return `${STORAGE_KEY_PREFIX}${conversationId}`
|
|
54
60
|
}
|
|
55
61
|
|
|
56
|
-
private requireStorage ():
|
|
62
|
+
private requireStorage (): StorageV2 {
|
|
57
63
|
if (!this._storage) {
|
|
58
64
|
throw ExceptionHelper.generateException(Error, Errors.ProactiveStorageRequired)
|
|
59
65
|
}
|
|
60
66
|
return this._storage
|
|
61
67
|
}
|
|
62
68
|
|
|
63
|
-
private requireAppStorage ():
|
|
69
|
+
private requireAppStorage (): StorageV2 {
|
|
64
70
|
const storage = this._app.options.storage
|
|
65
71
|
if (!storage) {
|
|
66
72
|
throw ExceptionHelper.generateException(Error, Errors.ProactiveAppStorageRequired)
|
|
67
73
|
}
|
|
68
|
-
return storage
|
|
74
|
+
return asStorageV2(storage)
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
// ---------------------------------------------------------------------------
|
|
@@ -120,7 +126,8 @@ export class Proactive<TState extends TurnState> {
|
|
|
120
126
|
const key = this._storageKey(id)
|
|
121
127
|
record({ conversationId: id })
|
|
122
128
|
const linkedItem = await actions.link(storage, key)
|
|
123
|
-
await storage.write({ [key]: { ...linkedItem, reference: conv.reference, claims: conv.claims } })
|
|
129
|
+
const results = await storage.write({ [key]: { ...linkedItem, reference: conv.reference, claims: conv.claims } })
|
|
130
|
+
assertStorageWriteSucceeded(results, [key])
|
|
124
131
|
return id
|
|
125
132
|
})
|
|
126
133
|
}
|
|
@@ -142,7 +149,8 @@ export class Proactive<TState extends TurnState> {
|
|
|
142
149
|
return trace(ProactiveTraceDefinitions.getConversation, async ({ record }) => {
|
|
143
150
|
record({ conversationId })
|
|
144
151
|
const storageKey = this._storageKey(conversationId)
|
|
145
|
-
const
|
|
152
|
+
const results = await this.requireStorage().read<Conversation>([storageKey])
|
|
153
|
+
const stored = getStorageReadValue(results, storageKey)
|
|
146
154
|
if (!stored) {
|
|
147
155
|
record({ found: false })
|
|
148
156
|
return undefined
|
|
@@ -193,7 +201,9 @@ export class Proactive<TState extends TurnState> {
|
|
|
193
201
|
async deleteConversation (conversationId: string): Promise<void> {
|
|
194
202
|
return trace(ProactiveTraceDefinitions.deleteConversation, async ({ record }) => {
|
|
195
203
|
record({ conversationId })
|
|
196
|
-
|
|
204
|
+
const key = this._storageKey(conversationId)
|
|
205
|
+
const results = await this.requireStorage().delete([key])
|
|
206
|
+
assertStorageDeleteSucceeded(results, [key])
|
|
197
207
|
})
|
|
198
208
|
}
|
|
199
209
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { StorageProvider } from '../../storage/storage'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Configuration for the proactive messaging subsystem.
|
|
@@ -14,7 +14,7 @@ export interface ProactiveOptions {
|
|
|
14
14
|
* A warning is logged when the fallback is used.
|
|
15
15
|
* Throws at initialization time if neither is configured.
|
|
16
16
|
*/
|
|
17
|
-
storage?:
|
|
17
|
+
storage?: StorageProvider
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* When `true` (default), `continueConversation()` throws if any requested
|