@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.
Files changed (139) hide show
  1. package/README.md +182 -4
  2. package/dist/package.json +3 -3
  3. package/dist/src/app/agentApplication.d.ts +4 -3
  4. package/dist/src/app/agentApplication.js +24 -21
  5. package/dist/src/app/agentApplication.js.map +1 -1
  6. package/dist/src/app/agentApplicationBuilder.d.ts +9 -2
  7. package/dist/src/app/agentApplicationBuilder.js +9 -0
  8. package/dist/src/app/agentApplicationBuilder.js.map +1 -1
  9. package/dist/src/app/agentApplicationOptions.d.ts +16 -4
  10. package/dist/src/app/auth/authorizationManager.d.ts +0 -8
  11. package/dist/src/app/auth/authorizationManager.js +104 -178
  12. package/dist/src/app/auth/authorizationManager.js.map +1 -1
  13. package/dist/src/app/auth/handlerStorage.d.ts +5 -3
  14. package/dist/src/app/auth/handlerStorage.js +36 -10
  15. package/dist/src/app/auth/handlerStorage.js.map +1 -1
  16. package/dist/src/app/auth/types.d.ts +2 -2
  17. package/dist/src/app/index.d.ts +1 -0
  18. package/dist/src/app/proactive/proactive.js +10 -6
  19. package/dist/src/app/proactive/proactive.js.map +1 -1
  20. package/dist/src/app/proactive/proactiveOptions.d.ts +2 -2
  21. package/dist/src/app/rateLimit.d.ts +315 -0
  22. package/dist/src/app/rateLimit.js +333 -0
  23. package/dist/src/app/rateLimit.js.map +1 -0
  24. package/dist/src/app/turnState.d.ts +6 -3
  25. package/dist/src/app/turnState.js +43 -4
  26. package/dist/src/app/turnState.js.map +1 -1
  27. package/dist/src/auth/authConfiguration.d.ts +10 -3
  28. package/dist/src/auth/authConfiguration.js +292 -259
  29. package/dist/src/auth/authConfiguration.js.map +1 -1
  30. package/dist/src/auth/settings.d.ts +8 -70
  31. package/dist/src/auth/settings.js +5 -67
  32. package/dist/src/auth/settings.js.map +1 -1
  33. package/dist/src/cloudAdapter.d.ts +5 -0
  34. package/dist/src/cloudAdapter.js +13 -103
  35. package/dist/src/cloudAdapter.js.map +1 -1
  36. package/dist/src/configuration/botFrameworkEnvironmentCompatibility.d.ts +23 -0
  37. package/dist/src/configuration/botFrameworkEnvironmentCompatibility.js +183 -0
  38. package/dist/src/configuration/botFrameworkEnvironmentCompatibility.js.map +1 -0
  39. package/dist/src/configuration/configuration.d.ts +83 -0
  40. package/dist/src/configuration/configuration.js +836 -0
  41. package/dist/src/configuration/configuration.js.map +1 -0
  42. package/dist/src/configuration/configurationSource.d.ts +57 -0
  43. package/dist/src/configuration/configurationSource.js +7 -0
  44. package/dist/src/configuration/configurationSource.js.map +1 -0
  45. package/dist/src/configuration/environmentConfiguration.d.ts +14 -0
  46. package/dist/src/configuration/environmentConfiguration.js +271 -0
  47. package/dist/src/configuration/environmentConfiguration.js.map +1 -0
  48. package/dist/src/configuration/index.d.ts +7 -0
  49. package/dist/src/configuration/index.js +14 -0
  50. package/dist/src/configuration/index.js.map +1 -0
  51. package/dist/src/configuration/jsonFileConfigurationSource.d.ts +15 -0
  52. package/dist/src/configuration/jsonFileConfigurationSource.js +58 -0
  53. package/dist/src/configuration/jsonFileConfigurationSource.js.map +1 -0
  54. package/dist/src/createCloudAdapter.d.ts +30 -5
  55. package/dist/src/createCloudAdapter.js +17 -10
  56. package/dist/src/createCloudAdapter.js.map +1 -1
  57. package/dist/src/errorHelper.js +117 -5
  58. package/dist/src/errorHelper.js.map +1 -1
  59. package/dist/src/index.d.ts +1 -0
  60. package/dist/src/index.js +1 -0
  61. package/dist/src/index.js.map +1 -1
  62. package/dist/src/observability/traces.d.ts +6 -4
  63. package/dist/src/observability/traces.js +10 -9
  64. package/dist/src/observability/traces.js.map +1 -1
  65. package/dist/src/outboundHostValidator.d.ts +4 -1
  66. package/dist/src/outboundHostValidator.js +25 -48
  67. package/dist/src/outboundHostValidator.js.map +1 -1
  68. package/dist/src/state/agentState.d.ts +8 -3
  69. package/dist/src/state/agentState.js +26 -8
  70. package/dist/src/state/agentState.js.map +1 -1
  71. package/dist/src/state/conversationState.d.ts +2 -2
  72. package/dist/src/state/conversationState.js.map +1 -1
  73. package/dist/src/state/userState.d.ts +2 -2
  74. package/dist/src/state/userState.js.map +1 -1
  75. package/dist/src/statusCodes.d.ts +5 -0
  76. package/dist/src/statusCodes.js +5 -0
  77. package/dist/src/statusCodes.js.map +1 -1
  78. package/dist/src/storage/fileStorage.d.ts +83 -68
  79. package/dist/src/storage/fileStorage.js +279 -105
  80. package/dist/src/storage/fileStorage.js.map +1 -1
  81. package/dist/src/storage/index.d.ts +1 -0
  82. package/dist/src/storage/index.js +1 -0
  83. package/dist/src/storage/index.js.map +1 -1
  84. package/dist/src/storage/memoryStorage.d.ts +85 -60
  85. package/dist/src/storage/memoryStorage.js +244 -87
  86. package/dist/src/storage/memoryStorage.js.map +1 -1
  87. package/dist/src/storage/storage.d.ts +100 -2
  88. package/dist/src/storage/storage.js +25 -0
  89. package/dist/src/storage/storage.js.map +1 -1
  90. package/dist/src/storage/storageCompatibility.d.ts +17 -0
  91. package/dist/src/storage/storageCompatibility.js +157 -0
  92. package/dist/src/storage/storageCompatibility.js.map +1 -0
  93. package/dist/src/storage/storageExpiry.d.ts +6 -0
  94. package/dist/src/storage/storageExpiry.js +20 -0
  95. package/dist/src/storage/storageExpiry.js.map +1 -0
  96. package/dist/src/utils/env.d.ts +43 -0
  97. package/dist/src/utils/env.js +42 -6
  98. package/dist/src/utils/env.js.map +1 -1
  99. package/dist/src/utils.d.ts +1 -0
  100. package/dist/src/utils.js +10 -1
  101. package/dist/src/utils.js.map +1 -1
  102. package/package.json +3 -3
  103. package/src/app/agentApplication.ts +27 -14
  104. package/src/app/agentApplicationBuilder.ts +13 -2
  105. package/src/app/agentApplicationOptions.ts +18 -4
  106. package/src/app/auth/authorizationManager.ts +126 -204
  107. package/src/app/auth/handlerStorage.ts +51 -7
  108. package/src/app/auth/types.ts +2 -2
  109. package/src/app/index.ts +7 -0
  110. package/src/app/proactive/proactive.ts +19 -9
  111. package/src/app/proactive/proactiveOptions.ts +2 -2
  112. package/src/app/rateLimit.ts +659 -0
  113. package/src/app/turnState.ts +50 -7
  114. package/src/auth/authConfiguration.ts +415 -260
  115. package/src/auth/settings.ts +5 -82
  116. package/src/cloudAdapter.ts +38 -113
  117. package/src/configuration/botFrameworkEnvironmentCompatibility.ts +245 -0
  118. package/src/configuration/configuration.ts +1076 -0
  119. package/src/configuration/configurationSource.ts +76 -0
  120. package/src/configuration/environmentConfiguration.ts +377 -0
  121. package/src/configuration/index.ts +19 -0
  122. package/src/configuration/jsonFileConfigurationSource.ts +74 -0
  123. package/src/createCloudAdapter.ts +52 -9
  124. package/src/errorHelper.ts +143 -5
  125. package/src/index.ts +1 -0
  126. package/src/observability/traces.ts +8 -7
  127. package/src/outboundHostValidator.ts +37 -44
  128. package/src/state/agentState.ts +39 -13
  129. package/src/state/conversationState.ts +2 -2
  130. package/src/state/userState.ts +2 -2
  131. package/src/statusCodes.ts +6 -0
  132. package/src/storage/fileStorage.ts +299 -106
  133. package/src/storage/index.ts +1 -0
  134. package/src/storage/memoryStorage.ts +268 -85
  135. package/src/storage/storage.ts +114 -2
  136. package/src/storage/storageCompatibility.ts +185 -0
  137. package/src/storage/storageExpiry.ts +21 -0
  138. package/src/utils/env.ts +63 -0
  139. 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 { Storage } from '../../storage'
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
- constructor (private storage: Storage, private context: TurnContext) { }
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
- return ongoing?.[this.key]
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
- return this.storage.write({ [this.key]: data })
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
  }
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { Activity } from '@microsoft/agents-activity'
7
- import { Storage, StoreItem } from '../../storage'
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: 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 { Storage } from '../../storage/storage'
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?: 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 (): Storage {
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 (): Storage {
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 stored = (await this.requireStorage().read([storageKey]))?.[storageKey]
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
- await this.requireStorage().delete([this._storageKey(conversationId)])
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 { Storage } from '../../storage/storage'
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?: Storage
17
+ storage?: StorageProvider
18
18
 
19
19
  /**
20
20
  * When `true` (default), `continueConversation()` throws if any requested