@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.
- package/README.md +17 -1
- package/dist/src/activityHandler.d.ts +304 -46
- package/dist/src/activityHandler.js +298 -45
- package/dist/src/activityHandler.js.map +1 -1
- package/dist/src/agent-client/agentClient.d.ts +50 -0
- package/dist/src/agent-client/agentClient.js +28 -0
- package/dist/src/agent-client/agentClient.js.map +1 -1
- package/dist/src/app/agentApplication.d.ts +272 -7
- package/dist/src/app/agentApplication.js +278 -12
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationBuilder.d.ts +34 -3
- package/dist/src/app/agentApplicationBuilder.js +38 -6
- package/dist/src/app/agentApplicationBuilder.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +26 -2
- package/dist/src/app/appMemory.d.ts +34 -0
- package/dist/src/app/{memory.js → appMemory.js} +1 -1
- package/dist/src/app/appMemory.js.map +1 -0
- package/dist/src/app/appRoute.d.ts +6 -0
- package/dist/src/app/attachmentDownloader.d.ts +18 -0
- package/dist/src/app/attachmentDownloader.js +18 -0
- package/dist/src/app/attachmentDownloader.js.map +1 -1
- package/dist/src/app/conversationUpdateEvents.d.ts +6 -0
- package/dist/src/app/index.d.ts +4 -1
- package/dist/src/app/index.js +4 -1
- package/dist/src/app/index.js.map +1 -1
- package/dist/src/app/inputFileDownloader.d.ts +22 -0
- package/dist/src/app/oauth/authorization.d.ts +87 -0
- package/dist/src/app/oauth/authorization.js +135 -0
- package/dist/src/app/oauth/authorization.js.map +1 -0
- package/dist/src/app/routeHandler.d.ts +8 -0
- package/dist/src/app/routeSelector.d.ts +9 -0
- package/dist/src/app/turnEvents.d.ts +6 -0
- package/dist/src/app/turnState.d.ts +152 -2
- package/dist/src/app/turnState.js +125 -0
- package/dist/src/app/turnState.js.map +1 -1
- package/dist/src/app/turnStateEntry.d.ts +32 -0
- package/dist/src/app/turnStateEntry.js +32 -0
- package/dist/src/app/turnStateEntry.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +24 -0
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/request.d.ts +12 -0
- package/dist/src/baseAdapter.d.ts +17 -0
- package/dist/src/baseAdapter.js +17 -0
- package/dist/src/baseAdapter.js.map +1 -1
- package/dist/src/cards/cardFactory.d.ts +3 -0
- package/dist/src/cards/cardFactory.js +3 -0
- package/dist/src/cards/cardFactory.js.map +1 -1
- package/dist/src/cards/index.d.ts +1 -0
- package/dist/src/cards/index.js +1 -0
- package/dist/src/cards/index.js.map +1 -1
- package/dist/src/cards/o365ConnectorCardActionBase.d.ts +8 -0
- package/dist/src/cloudAdapter.d.ts +25 -3
- package/dist/src/cloudAdapter.js +25 -3
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/getProductInfo.d.ts +6 -0
- package/dist/src/getProductInfo.js +6 -0
- package/dist/src/getProductInfo.js.map +1 -1
- package/dist/src/logger.d.ts +34 -2
- package/dist/src/logger.js +35 -0
- package/dist/src/logger.js.map +1 -1
- package/dist/src/oauth/oAuthFlow.d.ts +32 -3
- package/dist/src/oauth/oAuthFlow.js +38 -14
- package/dist/src/oauth/oAuthFlow.js.map +1 -1
- package/dist/src/oauth/userTokenClient.d.ts +2 -2
- package/dist/src/oauth/userTokenClient.js +3 -3
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/state/agentState.d.ts +79 -27
- package/dist/src/state/agentState.js +58 -27
- package/dist/src/state/agentState.js.map +1 -1
- package/dist/src/state/agentStatePropertyAccesor.d.ts +67 -11
- package/dist/src/state/agentStatePropertyAccesor.js +58 -11
- package/dist/src/state/agentStatePropertyAccesor.js.map +1 -1
- package/dist/src/statusCodes.d.ts +39 -0
- package/dist/src/statusCodes.js +39 -0
- package/dist/src/statusCodes.js.map +1 -1
- package/dist/src/storage/memoryStorage.d.ts +48 -14
- package/dist/src/storage/memoryStorage.js +48 -14
- package/dist/src/storage/memoryStorage.js.map +1 -1
- package/dist/src/storage/storage.d.ts +43 -13
- package/dist/src/tokenResponseEventName.d.ts +3 -0
- package/dist/src/tokenResponseEventName.js +3 -0
- package/dist/src/tokenResponseEventName.js.map +1 -1
- package/dist/src/turnContext.d.ts +142 -56
- package/dist/src/turnContext.js +123 -53
- package/dist/src/turnContext.js.map +1 -1
- package/package.json +6 -6
- package/src/activityHandler.ts +304 -46
- package/src/agent-client/agentClient.ts +55 -5
- package/src/app/agentApplication.ts +283 -15
- package/src/app/agentApplicationBuilder.ts +39 -7
- package/src/app/agentApplicationOptions.ts +33 -2
- package/src/app/appMemory.ts +38 -0
- package/src/app/appRoute.ts +7 -0
- package/src/app/attachmentDownloader.ts +18 -0
- package/src/app/conversationUpdateEvents.ts +6 -0
- package/src/app/index.ts +4 -1
- package/src/app/inputFileDownloader.ts +24 -0
- package/src/app/oauth/authorization.ts +162 -0
- package/src/app/routeHandler.ts +8 -0
- package/src/app/routeSelector.ts +9 -0
- package/src/app/turnEvents.ts +6 -0
- package/src/app/turnState.ts +153 -3
- package/src/app/turnStateEntry.ts +32 -0
- package/src/auth/authConfiguration.ts +32 -1
- package/src/auth/request.ts +15 -0
- package/src/baseAdapter.ts +18 -0
- package/src/cards/cardFactory.ts +3 -0
- package/src/cards/index.ts +1 -0
- package/src/cards/o365ConnectorCardActionBase.ts +8 -0
- package/src/cloudAdapter.ts +28 -3
- package/src/getProductInfo.ts +7 -0
- package/src/logger.ts +34 -1
- package/src/oauth/oAuthFlow.ts +59 -18
- package/src/oauth/userTokenClient.ts +4 -4
- package/src/state/agentState.ts +81 -29
- package/src/state/agentStatePropertyAccesor.ts +67 -11
- package/src/statusCodes.ts +51 -0
- package/src/storage/memoryStorage.ts +48 -14
- package/src/storage/storage.ts +51 -18
- package/src/tokenResponseEventName.ts +3 -0
- package/src/turnContext.ts +142 -56
- package/dist/src/app/memory.d.ts +0 -10
- package/dist/src/app/memory.js.map +0 -1
- package/dist/src/app/oauth/userIdentity.d.ts +0 -43
- package/dist/src/app/oauth/userIdentity.js +0 -54
- package/dist/src/app/oauth/userIdentity.js.map +0 -1
- package/src/app/memory.ts +0 -14
- package/src/app/oauth/userIdentity.ts +0 -78
|
@@ -6,6 +6,15 @@
|
|
|
6
6
|
import { TurnContext } from '../turnContext'
|
|
7
7
|
import { AgentState, CustomKey } from './agentState'
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Interface for accessing a property in state storage with type safety.
|
|
11
|
+
*
|
|
12
|
+
* The interface defines standard methods for working with persisted state properties,
|
|
13
|
+
* allowing property access with strong typing to reduce errors when working with
|
|
14
|
+
* complex state objects.
|
|
15
|
+
*
|
|
16
|
+
* @typeParam T The type of the property being accessed
|
|
17
|
+
*/
|
|
9
18
|
export interface StatePropertyAccessor<T = any> {
|
|
10
19
|
/**
|
|
11
20
|
* Deletes the persisted property from its backing storage object.
|
|
@@ -64,20 +73,56 @@ export interface StatePropertyAccessor<T = any> {
|
|
|
64
73
|
}
|
|
65
74
|
|
|
66
75
|
/**
|
|
67
|
-
* Provides access to an Agent state property.
|
|
76
|
+
* Provides typed access to an Agent state property with automatic state loading.
|
|
77
|
+
*
|
|
78
|
+
* The AgentStatePropertyAccessor simplifies working with state by abstracting
|
|
79
|
+
* the details of loading state from storage and manipulating specific properties.
|
|
80
|
+
* It automatically handles:
|
|
81
|
+
*
|
|
82
|
+
* - Loading state when needed
|
|
83
|
+
* - Deep cloning of default values to prevent reference issues
|
|
84
|
+
* - Type checking for properties (when using TypeScript)
|
|
85
|
+
* - Ensuring properties exist before access
|
|
86
|
+
*
|
|
87
|
+
* Property accessors are created through the {@link AgentState.createProperty} method:
|
|
88
|
+
*
|
|
89
|
+
* ```typescript
|
|
90
|
+
* // Create a property accessor for a user profile
|
|
91
|
+
* const userProfile = userState.createProperty<UserProfile>("userProfile");
|
|
92
|
+
*
|
|
93
|
+
* // Get the profile with a default if not exists
|
|
94
|
+
* const profile = await userProfile.get(context, { name: "", preferences: {} });
|
|
95
|
+
*
|
|
96
|
+
* // Update a value
|
|
97
|
+
* profile.preferences.theme = "dark";
|
|
98
|
+
*
|
|
99
|
+
* // Save the change
|
|
100
|
+
* await userProfile.set(context, profile);
|
|
101
|
+
*
|
|
102
|
+
* // Later, call userState.saveChanges(context) to persist to storage
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @typeParam T The type of the property being accessed
|
|
68
106
|
*/
|
|
69
107
|
export class AgentStatePropertyAccessor<T = any> implements StatePropertyAccessor<T> {
|
|
70
108
|
/**
|
|
71
109
|
* Creates a new instance of AgentStatePropertyAccessor.
|
|
72
|
-
*
|
|
73
|
-
* @param
|
|
110
|
+
*
|
|
111
|
+
* @param state The agent state object that will contain this property
|
|
112
|
+
* @param name The name of the property in the state object
|
|
74
113
|
*/
|
|
75
114
|
constructor (protected readonly state: AgentState, public readonly name: string) { }
|
|
76
115
|
|
|
77
116
|
/**
|
|
78
117
|
* Deletes the property from the state.
|
|
79
|
-
*
|
|
80
|
-
*
|
|
118
|
+
*
|
|
119
|
+
* This removes the property from the state object but does not automatically
|
|
120
|
+
* persist the change to storage. Call state.saveChanges() afterwards to
|
|
121
|
+
* persist changes.
|
|
122
|
+
*
|
|
123
|
+
* @param context The turn context
|
|
124
|
+
* @param customKey Optional custom key for storing the state in a specific location
|
|
125
|
+
* @returns A promise that resolves when the delete operation is complete
|
|
81
126
|
*/
|
|
82
127
|
async delete (context: TurnContext, customKey?: CustomKey): Promise<void> {
|
|
83
128
|
const obj: any = await this.state.load(context, false, customKey)
|
|
@@ -88,9 +133,15 @@ export class AgentStatePropertyAccessor<T = any> implements StatePropertyAccesso
|
|
|
88
133
|
|
|
89
134
|
/**
|
|
90
135
|
* Gets the value of the property from the state.
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
136
|
+
*
|
|
137
|
+
* If the property doesn't exist and a default value is provided, a deep clone
|
|
138
|
+
* of the default value will be stored in state and returned. This ensures that
|
|
139
|
+
* modifications to the returned object will be properly tracked.
|
|
140
|
+
*
|
|
141
|
+
* @param context The turn context
|
|
142
|
+
* @param defaultValue Optional default value to use if the property doesn't exist
|
|
143
|
+
* @param customKey Optional custom key for storing the state in a specific location
|
|
144
|
+
* @returns A promise that resolves to the value of the property or undefined
|
|
94
145
|
*/
|
|
95
146
|
async get (context: TurnContext, defaultValue?: T, customKey?: CustomKey): Promise<T> {
|
|
96
147
|
const obj: any = await this.state.load(context, false, customKey)
|
|
@@ -107,9 +158,14 @@ export class AgentStatePropertyAccessor<T = any> implements StatePropertyAccesso
|
|
|
107
158
|
|
|
108
159
|
/**
|
|
109
160
|
* Sets the value of the property in the state.
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
161
|
+
*
|
|
162
|
+
* This updates the property in the in-memory state object but does not automatically
|
|
163
|
+
* persist the change to storage. Call state.saveChanges() afterwards to persist changes.
|
|
164
|
+
*
|
|
165
|
+
* @param context The turn context
|
|
166
|
+
* @param value The value to set
|
|
167
|
+
* @param customKey Optional custom key for storing the state in a specific location
|
|
168
|
+
* @returns A promise that resolves when the set operation is complete
|
|
113
169
|
*/
|
|
114
170
|
async set (context: TurnContext, value: T, customKey?: CustomKey): Promise<void> {
|
|
115
171
|
const obj: any = await this.state.load(context, false, customKey)
|
package/src/statusCodes.ts
CHANGED
|
@@ -4,17 +4,68 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
export enum StatusCodes {
|
|
7
|
+
/**
|
|
8
|
+
* The request has succeeded.
|
|
9
|
+
*/
|
|
7
10
|
OK = 200,
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The request has been fulfilled and resulted in a new resource being created.
|
|
14
|
+
*/
|
|
8
15
|
CREATED = 201,
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Indicates multiple options for the resource that the client may follow.
|
|
19
|
+
*/
|
|
9
20
|
MULTIPLE_CHOICES = 300,
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The server cannot or will not process the request due to a client error.
|
|
24
|
+
*/
|
|
10
25
|
BAD_REQUEST = 400,
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The request requires user authentication.
|
|
29
|
+
*/
|
|
11
30
|
UNAUTHORIZED = 401,
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The requested resource could not be found.
|
|
34
|
+
*/
|
|
12
35
|
NOT_FOUND = 404,
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The request method is not allowed for the requested resource.
|
|
39
|
+
*/
|
|
13
40
|
METHOD_NOT_ALLOWED = 405,
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The request could not be completed due to a conflict with the current state of the resource.
|
|
44
|
+
*/
|
|
14
45
|
CONFLICT = 409,
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The server does not meet one of the preconditions specified by the client.
|
|
49
|
+
*/
|
|
15
50
|
PRECONDITION_FAILED = 412,
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The client should switch to a different protocol.
|
|
54
|
+
*/
|
|
16
55
|
UPGRADE_REQUIRED = 426,
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The server encountered an unexpected condition that prevented it from fulfilling the request.
|
|
59
|
+
*/
|
|
17
60
|
INTERNAL_SERVER_ERROR = 500,
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The server does not support the functionality required to fulfill the request.
|
|
64
|
+
*/
|
|
18
65
|
NOT_IMPLEMENTED = 501,
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The server received an invalid response from the upstream server.
|
|
69
|
+
*/
|
|
19
70
|
BAD_GATEWAY = 502,
|
|
20
71
|
}
|
|
@@ -9,20 +9,39 @@ import { debug } from '../logger'
|
|
|
9
9
|
const logger = debug('agents:memory-storage')
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* A simple in-memory storage provider.
|
|
12
|
+
* A simple in-memory storage provider that implements the Storage interface.
|
|
13
|
+
*
|
|
14
|
+
* This class provides a volatile storage solution that keeps data in memory,
|
|
15
|
+
* which means data is lost when the process terminates. It's primarily useful for:
|
|
16
|
+
* - Development and testing scenarios
|
|
17
|
+
* - Simple applications that don't require data persistence across restarts
|
|
18
|
+
* - Stateless environments where external storage isn't available
|
|
19
|
+
*
|
|
20
|
+
* MemoryStorage supports optimistic concurrency control through eTags and
|
|
21
|
+
* can be used as a singleton through the getSingleInstance() method to
|
|
22
|
+
* share state across different parts of an application.
|
|
13
23
|
*/
|
|
14
24
|
export class MemoryStorage implements Storage {
|
|
15
25
|
private static instance: MemoryStorage
|
|
26
|
+
/**
|
|
27
|
+
* Counter used to generate unique eTags for stored items
|
|
28
|
+
*/
|
|
16
29
|
private etag: number = 1
|
|
17
30
|
|
|
18
31
|
/**
|
|
19
32
|
* Creates a new instance of the MemoryStorage class.
|
|
20
|
-
*
|
|
33
|
+
*
|
|
34
|
+
* @param memory An optional initial memory store to seed the storage with data
|
|
21
35
|
*/
|
|
22
36
|
constructor (private memory: { [k: string]: string } = {}) { }
|
|
23
37
|
|
|
24
38
|
/**
|
|
25
|
-
* Gets a single instance of the MemoryStorage class.
|
|
39
|
+
* Gets a single shared instance of the MemoryStorage class.
|
|
40
|
+
*
|
|
41
|
+
* Using this method ensures that the same storage instance is used across
|
|
42
|
+
* the application, allowing for shared state without passing references.
|
|
43
|
+
*
|
|
44
|
+
* @returns The singleton instance of MemoryStorage
|
|
26
45
|
*/
|
|
27
46
|
static getSingleInstance (): MemoryStorage {
|
|
28
47
|
if (!MemoryStorage.instance) {
|
|
@@ -33,9 +52,10 @@ export class MemoryStorage implements Storage {
|
|
|
33
52
|
|
|
34
53
|
/**
|
|
35
54
|
* Reads storage items from memory.
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
38
|
-
* @
|
|
55
|
+
*
|
|
56
|
+
* @param keys The keys of the items to read
|
|
57
|
+
* @returns A promise that resolves to the read items
|
|
58
|
+
* @throws Will throw an error if keys are not provided or the array is empty
|
|
39
59
|
*/
|
|
40
60
|
async read (keys: string[]): Promise<StoreItem> {
|
|
41
61
|
if (!keys || keys.length === 0) {
|
|
@@ -56,9 +76,15 @@ export class MemoryStorage implements Storage {
|
|
|
56
76
|
|
|
57
77
|
/**
|
|
58
78
|
* Writes storage items to memory.
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
79
|
+
*
|
|
80
|
+
* This method supports optimistic concurrency control through eTags.
|
|
81
|
+
* If an item has an eTag, it will only be updated if the existing item
|
|
82
|
+
* has the same eTag. If an item has an eTag of '*' or no eTag, it will
|
|
83
|
+
* always be written regardless of the current state.
|
|
84
|
+
*
|
|
85
|
+
* @param changes The items to write, indexed by key
|
|
86
|
+
* @returns A promise that resolves when the write operation is complete
|
|
87
|
+
* @throws Will throw an error if changes are not provided or if there's an eTag conflict
|
|
62
88
|
*/
|
|
63
89
|
async write (changes: StoreItem): Promise<void> {
|
|
64
90
|
if (!changes || changes.length === 0) {
|
|
@@ -83,8 +109,9 @@ export class MemoryStorage implements Storage {
|
|
|
83
109
|
|
|
84
110
|
/**
|
|
85
111
|
* Deletes storage items from memory.
|
|
86
|
-
*
|
|
87
|
-
* @
|
|
112
|
+
*
|
|
113
|
+
* @param keys The keys of the items to delete
|
|
114
|
+
* @returns A promise that resolves when the delete operation is complete
|
|
88
115
|
*/
|
|
89
116
|
async delete (keys: string[]): Promise<void> {
|
|
90
117
|
logger.info(`Deleting keys: ${keys.join(', ')}`)
|
|
@@ -94,9 +121,16 @@ export class MemoryStorage implements Storage {
|
|
|
94
121
|
}
|
|
95
122
|
|
|
96
123
|
/**
|
|
97
|
-
* Saves an item to memory.
|
|
98
|
-
*
|
|
99
|
-
*
|
|
124
|
+
* Saves an item to memory with a new eTag.
|
|
125
|
+
*
|
|
126
|
+
* This private method handles the details of:
|
|
127
|
+
* - Creating a clone of the item to prevent modification of the original
|
|
128
|
+
* - Generating a new eTag for optimistic concurrency control
|
|
129
|
+
* - Converting the item to a JSON string for storage
|
|
130
|
+
*
|
|
131
|
+
* @param key The key of the item to save
|
|
132
|
+
* @param item The item to save
|
|
133
|
+
* @private
|
|
100
134
|
*/
|
|
101
135
|
private saveItem (key: string, item: unknown): void {
|
|
102
136
|
const clone = Object.assign({}, item, { eTag: (this.etag++).toString() })
|
package/src/storage/storage.ts
CHANGED
|
@@ -6,47 +6,80 @@
|
|
|
6
6
|
import { TurnContext } from '../turnContext'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Represents an item to be stored.
|
|
9
|
+
* Represents an item to be stored in a storage provider.
|
|
10
|
+
* Each item can contain arbitrary data along with an optional eTag for optimistic concurrency control.
|
|
10
11
|
*/
|
|
11
12
|
export interface StoreItem {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Optional eTag used for optimistic concurrency control.
|
|
15
|
+
* When set to '*', it indicates that the write should proceed regardless of existing data.
|
|
16
|
+
* When comparing eTags, exact string matching is used to determine if data has changed.
|
|
17
|
+
*/
|
|
18
|
+
eTag?: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Additional properties can be stored in the item.
|
|
22
|
+
* Each storage provider may have specific requirements or limitations on property names and values.
|
|
23
|
+
*/
|
|
24
|
+
[key: string]: any;
|
|
14
25
|
}
|
|
15
26
|
|
|
16
27
|
/**
|
|
17
|
-
* Represents a collection of store items.
|
|
28
|
+
* Represents a collection of store items indexed by key.
|
|
29
|
+
* Used as the return type for storage read operations.
|
|
18
30
|
*/
|
|
19
31
|
export interface StoreItems {
|
|
32
|
+
/**
|
|
33
|
+
* Keys are the storage item identifiers, and values are the stored items.
|
|
34
|
+
* If a requested key is not found during a read operation, it will not appear in this collection.
|
|
35
|
+
*/
|
|
20
36
|
[key: string]: any;
|
|
21
37
|
}
|
|
22
38
|
|
|
23
39
|
/**
|
|
24
|
-
* A factory function to generate storage keys based on the context.
|
|
25
|
-
*
|
|
26
|
-
*
|
|
40
|
+
* A factory function to generate storage keys based on the conversation context.
|
|
41
|
+
* Allows different storage strategies based on the conversation state.
|
|
42
|
+
*
|
|
43
|
+
* @param context The TurnContext for the current turn of conversation
|
|
44
|
+
* @returns A string key for storage that uniquely identifies where to store the data
|
|
27
45
|
*/
|
|
28
|
-
export type StorageKeyFactory = (context: TurnContext) => string
|
|
46
|
+
export type StorageKeyFactory = (context: TurnContext) => string | Promise<string>
|
|
29
47
|
|
|
30
48
|
/**
|
|
31
|
-
* Defines the interface for storage operations.
|
|
49
|
+
* Defines the interface for storage operations in the Agents platform.
|
|
50
|
+
*
|
|
51
|
+
* Storage providers persist state data across conversation turns, enabling
|
|
52
|
+
* agents to maintain context over time. Different implementations may store
|
|
53
|
+
* data in memory, databases, blob storage, or other persistence mechanisms.
|
|
54
|
+
*
|
|
55
|
+
* The interface is designed to be simple with just three core operations:
|
|
56
|
+
* read, write, and delete. All operations are asynchronous to support both
|
|
57
|
+
* in-memory and remote storage providers.
|
|
32
58
|
*/
|
|
33
59
|
export interface Storage {
|
|
34
60
|
/**
|
|
35
61
|
* Reads store items from storage.
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
62
|
+
*
|
|
63
|
+
* @param keys The keys of the items to read
|
|
64
|
+
* @returns A promise that resolves to the store items. Items that don't exist in storage will not be included in the result.
|
|
65
|
+
* @throws If the keys array is empty or undefined
|
|
38
66
|
*/
|
|
39
|
-
read: (keys: string[]) => Promise<StoreItem
|
|
67
|
+
read: (keys: string[]) => Promise<StoreItem>;
|
|
68
|
+
|
|
40
69
|
/**
|
|
41
70
|
* Writes store items to storage.
|
|
42
|
-
*
|
|
43
|
-
* @
|
|
71
|
+
*
|
|
72
|
+
* @param changes The items to write to storage, indexed by key
|
|
73
|
+
* @returns A promise that resolves when the write operation is complete
|
|
74
|
+
* @throws If the changes object is empty or undefined, or if an eTag conflict occurs and optimistic concurrency is enabled
|
|
44
75
|
*/
|
|
45
|
-
write: (changes: StoreItem) => Promise<void
|
|
76
|
+
write: (changes: StoreItem) => Promise<void>;
|
|
77
|
+
|
|
46
78
|
/**
|
|
47
79
|
* Deletes store items from storage.
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
80
|
+
*
|
|
81
|
+
* @param keys The keys of the items to delete
|
|
82
|
+
* @returns A promise that resolves when the delete operation is complete
|
|
50
83
|
*/
|
|
51
|
-
delete: (keys: string[]) => Promise<void
|
|
84
|
+
delete: (keys: string[]) => Promise<void>;
|
|
52
85
|
}
|