@microsoft/agents-hosting 0.6.1 → 0.6.16-gc874f0c9d8
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/src/activityHandler.d.ts +29 -5
- package/dist/src/activityHandler.js +30 -6
- package/dist/src/activityHandler.js.map +1 -1
- package/dist/src/agent-client/agentClient.js +1 -1
- package/dist/src/agent-client/agentClient.js.map +1 -1
- package/dist/src/agent-client/agentResponseHandler.d.ts +34 -0
- package/dist/src/agent-client/agentResponseHandler.js +35 -1
- package/dist/src/agent-client/agentResponseHandler.js.map +1 -1
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.d.ts +23 -2
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.js.map +1 -1
- package/dist/src/app/adaptiveCards/adaptiveCardsSearchParams.d.ts +1 -1
- package/dist/src/app/agentApplication.d.ts +46 -34
- package/dist/src/app/agentApplication.js +64 -40
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +74 -13
- package/dist/src/app/appRoute.d.ts +56 -2
- package/dist/src/app/attachmentDownloader.d.ts +1 -0
- package/dist/src/app/attachmentDownloader.js +2 -1
- package/dist/src/app/attachmentDownloader.js.map +1 -1
- package/dist/src/app/authorization.d.ts +1 -1
- package/dist/src/app/authorization.js +1 -1
- package/dist/src/app/authorization.js.map +1 -1
- package/dist/src/app/extensions.d.ts +37 -1
- package/dist/src/app/extensions.js +38 -2
- package/dist/src/app/extensions.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/routeList.d.ts +13 -0
- package/dist/src/app/routeList.js +30 -0
- package/dist/src/app/routeList.js.map +1 -0
- package/dist/src/app/routeRank.d.ts +51 -0
- package/dist/src/app/routeRank.js +56 -0
- package/dist/src/app/routeRank.js.map +1 -0
- package/dist/src/app/streaming/citationUtil.d.ts +1 -1
- package/dist/src/app/streaming/streamingResponse.d.ts +1 -2
- package/dist/src/app/streaming/streamingResponse.js +29 -41
- package/dist/src/app/streaming/streamingResponse.js.map +1 -1
- package/dist/src/app/turnState.d.ts +2 -0
- package/dist/src/app/turnState.js +3 -1
- package/dist/src/app/turnState.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +4 -0
- package/dist/src/auth/authConfiguration.js +5 -1
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/authProvider.d.ts +1 -1
- package/dist/src/auth/jwt-middleware.js +1 -1
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/auth/msalTokenCredential.d.ts +14 -0
- package/dist/src/auth/msalTokenCredential.js +14 -0
- package/dist/src/auth/msalTokenCredential.js.map +1 -1
- package/dist/src/auth/msalTokenProvider.js +4 -2
- package/dist/src/auth/msalTokenProvider.js.map +1 -1
- package/dist/src/baseAdapter.d.ts +22 -1
- package/dist/src/baseAdapter.js +23 -2
- package/dist/src/baseAdapter.js.map +1 -1
- package/dist/src/cards/adaptiveCard.d.ts +2 -0
- package/dist/src/cards/animationCard.d.ts +1 -1
- package/dist/src/cards/audioCard.d.ts +1 -1
- package/dist/src/cards/cardImage.d.ts +1 -1
- package/dist/src/cards/fact.d.ts +1 -1
- package/dist/src/cards/heroCard.d.ts +1 -1
- package/dist/src/cards/o365ConnectorCardSection.d.ts +5 -0
- package/dist/src/cloudAdapter.d.ts +11 -0
- package/dist/src/cloudAdapter.js +33 -4
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/connector-client/connectorClient.js +1 -1
- package/dist/src/connector-client/connectorClient.js.map +1 -1
- package/dist/src/getProductInfo.js +2 -2
- package/dist/src/getProductInfo.js.map +1 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/middlewareSet.js +1 -1
- package/dist/src/middlewareSet.js.map +1 -1
- package/dist/src/oauth/oAuthFlow.js +1 -1
- package/dist/src/oauth/oAuthFlow.js.map +1 -1
- package/dist/src/oauth/userTokenClient.js +1 -1
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/state/agentState.js +1 -1
- package/dist/src/state/agentState.js.map +1 -1
- package/dist/src/state/agentStatePropertyAccesor.d.ts +269 -38
- package/dist/src/state/agentStatePropertyAccesor.js +269 -38
- package/dist/src/state/agentStatePropertyAccesor.js.map +1 -1
- package/dist/src/statusCodes.d.ts +30 -0
- package/dist/src/statusCodes.js +30 -0
- package/dist/src/statusCodes.js.map +1 -1
- package/dist/src/storage/fileStorage.d.ts +97 -0
- package/dist/src/storage/fileStorage.js +97 -0
- package/dist/src/storage/fileStorage.js.map +1 -1
- package/dist/src/storage/memoryStorage.d.ts +2 -1
- package/dist/src/storage/memoryStorage.js +3 -2
- package/dist/src/storage/memoryStorage.js.map +1 -1
- package/dist/src/storage/storage.d.ts +1 -0
- package/dist/src/transcript/transcriptLoggerMiddleware.js +1 -1
- package/dist/src/transcript/transcriptLoggerMiddleware.js.map +1 -1
- package/dist/src/turnContext.d.ts +1 -0
- package/dist/src/turnContext.js +1 -0
- package/dist/src/turnContext.js.map +1 -1
- package/package.json +4 -5
- package/src/activityHandler.ts +30 -6
- package/src/agent-client/agentClient.ts +1 -1
- package/src/agent-client/agentResponseHandler.ts +35 -1
- package/src/app/adaptiveCards/adaptiveCardsActions.ts +23 -2
- package/src/app/adaptiveCards/adaptiveCardsSearchParams.ts +1 -1
- package/src/app/agentApplication.ts +70 -41
- package/src/app/agentApplicationOptions.ts +75 -13
- package/src/app/appRoute.ts +57 -2
- package/src/app/attachmentDownloader.ts +2 -1
- package/src/app/authorization.ts +2 -2
- package/src/app/extensions.ts +45 -2
- package/src/app/index.ts +2 -0
- package/src/app/routeList.ts +37 -0
- package/src/app/routeRank.ts +54 -0
- package/src/app/streaming/citationUtil.ts +1 -1
- package/src/app/streaming/streamingResponse.ts +23 -71
- package/src/app/turnState.ts +3 -1
- package/src/auth/authConfiguration.ts +5 -1
- package/src/auth/authProvider.ts +1 -1
- package/src/auth/jwt-middleware.ts +1 -1
- package/src/auth/msalTokenCredential.ts +15 -0
- package/src/auth/msalTokenProvider.ts +4 -2
- package/src/baseAdapter.ts +25 -2
- package/src/cards/adaptiveCard.ts +2 -0
- package/src/cards/animationCard.ts +1 -1
- package/src/cards/audioCard.ts +1 -1
- package/src/cards/cardImage.ts +1 -1
- package/src/cards/fact.ts +1 -1
- package/src/cards/heroCard.ts +1 -1
- package/src/cards/o365ConnectorCardSection.ts +5 -0
- package/src/cloudAdapter.ts +36 -4
- package/src/connector-client/connectorClient.ts +1 -1
- package/src/getProductInfo.ts +2 -2
- package/src/index.ts +0 -2
- package/src/middlewareSet.ts +1 -1
- package/src/oauth/oAuthFlow.ts +1 -1
- package/src/oauth/userTokenClient.ts +1 -1
- package/src/state/agentState.ts +1 -1
- package/src/state/agentStatePropertyAccesor.ts +269 -38
- package/src/statusCodes.ts +30 -0
- package/src/storage/fileStorage.ts +99 -0
- package/src/storage/memoryStorage.ts +3 -2
- package/src/storage/storage.ts +1 -0
- package/src/transcript/transcriptLoggerMiddleware.ts +1 -1
- package/src/turnContext.ts +1 -0
- package/dist/src/logger.d.ts +0 -44
- package/dist/src/logger.js +0 -77
- package/dist/src/logger.js.map +0 -1
- package/src/logger.ts +0 -76
|
@@ -67,36 +67,115 @@ export interface StatePropertyAccessor<T = any> {
|
|
|
67
67
|
set(context: TurnContext, value: T): Promise<void>;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
* Provides typed access to an Agent state property with automatic state loading.
|
|
70
|
+
* Provides typed access to an Agent state property with automatic state loading and persistence management.
|
|
71
71
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* AgentStatePropertyAccessor simplifies working with persisted state by abstracting
|
|
74
|
+
* the complexity of loading state from storage and manipulating specific properties.
|
|
75
|
+
* It provides a type-safe interface for state management with automatic handling of:
|
|
75
76
|
*
|
|
76
|
-
* - Loading
|
|
77
|
-
* -
|
|
78
|
-
* -
|
|
79
|
-
* -
|
|
77
|
+
* - **Lazy Loading**: State is loaded from storage only when first accessed
|
|
78
|
+
* - **Type Safety**: Full TypeScript support with generic type parameters
|
|
79
|
+
* - **Default Values**: Automatic deep cloning of default values to prevent reference issues
|
|
80
|
+
* - **Memory Management**: Efficient in-memory caching with explicit persistence control
|
|
81
|
+
* - **Custom Keys**: Support for custom storage keys for advanced scenarios
|
|
80
82
|
*
|
|
81
|
-
*
|
|
83
|
+
* ## Key Features
|
|
82
84
|
*
|
|
85
|
+
* ### Type Safety
|
|
86
|
+
* The accessor provides compile-time type checking when using TypeScript:
|
|
83
87
|
* ```typescript
|
|
84
|
-
*
|
|
88
|
+
* interface UserProfile {
|
|
89
|
+
* name: string;
|
|
90
|
+
* preferences: { theme: string; language: string };
|
|
91
|
+
* }
|
|
85
92
|
* const userProfile = userState.createProperty<UserProfile>("userProfile");
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* ### Automatic Default Value Handling
|
|
96
|
+
* When a property doesn't exist, default values are automatically cloned and stored:
|
|
97
|
+
* ```typescript
|
|
98
|
+
* // If userProfile doesn't exist, the default will be cloned and saved
|
|
99
|
+
* const profile = await userProfile.get(context, {
|
|
100
|
+
* name: "Anonymous",
|
|
101
|
+
* preferences: { theme: "light", language: "en" }
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* ### Explicit Persistence Control
|
|
106
|
+
* Changes are kept in memory until explicitly persisted:
|
|
107
|
+
* ```typescript
|
|
108
|
+
* // Modify the state
|
|
109
|
+
* const counter = await counterProperty.get(context, 0);
|
|
110
|
+
* await counterProperty.set(context, counter + 1);
|
|
111
|
+
*
|
|
112
|
+
* // Changes are only in memory at this point
|
|
113
|
+
* // Persist to storage
|
|
114
|
+
* await userState.saveChanges(context);
|
|
115
|
+
* ```
|
|
86
116
|
*
|
|
87
|
-
*
|
|
88
|
-
* const profile = await userProfile.get(context, { name: "", preferences: {} });
|
|
117
|
+
* ## Usage Examples
|
|
89
118
|
*
|
|
90
|
-
*
|
|
119
|
+
* ### Basic Usage
|
|
120
|
+
* ```typescript
|
|
121
|
+
* // Create a property accessor
|
|
122
|
+
* const userProfile = userState.createProperty<UserProfile>("userProfile");
|
|
123
|
+
*
|
|
124
|
+
* // Get with default value
|
|
125
|
+
* const profile = await userProfile.get(context, {
|
|
126
|
+
* name: "",
|
|
127
|
+
* preferences: { theme: "light", language: "en" }
|
|
128
|
+
* });
|
|
129
|
+
*
|
|
130
|
+
* // Modify the profile
|
|
91
131
|
* profile.preferences.theme = "dark";
|
|
92
132
|
*
|
|
93
|
-
* // Save the
|
|
133
|
+
* // Save the changes
|
|
94
134
|
* await userProfile.set(context, profile);
|
|
135
|
+
* await userState.saveChanges(context); // Persist to storage
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* ### Working with Primitive Types
|
|
139
|
+
* ```typescript
|
|
140
|
+
* const counterProperty = userState.createProperty<number>("counter");
|
|
95
141
|
*
|
|
96
|
-
* //
|
|
142
|
+
* // Increment counter
|
|
143
|
+
* const currentCount = await counterProperty.get(context, 0);
|
|
144
|
+
* await counterProperty.set(context, currentCount + 1);
|
|
145
|
+
* await userState.saveChanges(context);
|
|
97
146
|
* ```
|
|
98
147
|
*
|
|
99
|
-
*
|
|
148
|
+
* ### Conditional Logic
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const settingsProperty = userState.createProperty<Settings>("settings");
|
|
151
|
+
*
|
|
152
|
+
* // Check if property exists
|
|
153
|
+
* const settings = await settingsProperty.get(context);
|
|
154
|
+
* if (settings === undefined) {
|
|
155
|
+
* // Property doesn't exist, initialize with defaults
|
|
156
|
+
* await settingsProperty.set(context, getDefaultSettings());
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* ### Custom Storage Keys
|
|
161
|
+
* ```typescript
|
|
162
|
+
* // Store state with a custom key for multi-tenant scenarios
|
|
163
|
+
* const customKey = { key: `tenant_${tenantId}` };
|
|
164
|
+
* const tenantData = await dataProperty.get(context, defaultData, customKey);
|
|
165
|
+
* await dataProperty.set(context, updatedData, customKey);
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* ## Important Notes
|
|
169
|
+
*
|
|
170
|
+
* - **Thread Safety**: This class is not thread-safe. Ensure proper synchronization in concurrent scenarios.
|
|
171
|
+
* - **Memory Usage**: State objects are kept in memory until the context is disposed.
|
|
172
|
+
* - **Persistence**: Always call `state.saveChanges(context)` to persist changes to storage.
|
|
173
|
+
* - **Deep Cloning**: Default values are deep cloned using JSON serialization, which may not work with complex objects containing functions or circular references.
|
|
174
|
+
*
|
|
175
|
+
* @typeParam T The type of the property being accessed. Can be any serializable type.
|
|
176
|
+
*
|
|
177
|
+
* @see {@link AgentState.createProperty} for creating property accessors
|
|
178
|
+
* @see {@link StatePropertyAccessor} for the interface definition
|
|
100
179
|
*/
|
|
101
180
|
export declare class AgentStatePropertyAccessor<T = any> implements StatePropertyAccessor<T> {
|
|
102
181
|
protected readonly state: AgentState;
|
|
@@ -104,45 +183,197 @@ export declare class AgentStatePropertyAccessor<T = any> implements StatePropert
|
|
|
104
183
|
/**
|
|
105
184
|
* Creates a new instance of AgentStatePropertyAccessor.
|
|
106
185
|
*
|
|
107
|
-
* @
|
|
108
|
-
*
|
|
186
|
+
* @remarks
|
|
187
|
+
* This constructor is typically not called directly. Instead, use {@link AgentState.createProperty}
|
|
188
|
+
* to create property accessors, which ensures proper integration with the state management system.
|
|
189
|
+
*
|
|
190
|
+
* @param state The agent state object that manages the backing storage for this property
|
|
191
|
+
* @param name The unique name of the property within the state object. This name is used as the key in the state storage.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* // Recommended way - use AgentState.createProperty
|
|
196
|
+
* const userProfile = userState.createProperty<UserProfile>("userProfile");
|
|
197
|
+
*
|
|
198
|
+
* // Direct construction (not recommended)
|
|
199
|
+
* const accessor = new AgentStatePropertyAccessor<UserProfile>(userState, "userProfile");
|
|
200
|
+
* ```
|
|
109
201
|
*/
|
|
110
202
|
constructor(state: AgentState, name: string);
|
|
111
203
|
/**
|
|
112
|
-
* Deletes the property from the state.
|
|
204
|
+
* Deletes the property from the state storage.
|
|
113
205
|
*
|
|
114
|
-
* This removes the property from the state object but does not
|
|
115
|
-
* persist the change to storage.
|
|
116
|
-
* persist
|
|
206
|
+
* This operation removes the property from the in-memory state object but does not
|
|
207
|
+
* automatically persist the change to the underlying storage. You must call
|
|
208
|
+
* `state.saveChanges(context)` afterwards to persist the deletion.
|
|
209
|
+
*
|
|
210
|
+
* @remarks
|
|
211
|
+
* - If the property doesn't exist, this operation is a no-op
|
|
212
|
+
* - The deletion only affects the in-memory state until `saveChanges()` is called
|
|
213
|
+
* - After deletion, subsequent `get()` calls will return `undefined` (or the default value if provided)
|
|
214
|
+
*
|
|
215
|
+
* @param context The turn context for the current conversation turn
|
|
216
|
+
* @param customKey Optional custom key for accessing state in a specific storage location.
|
|
217
|
+
* Useful for multi-tenant scenarios or when state needs to be partitioned.
|
|
117
218
|
*
|
|
118
|
-
* @param context The turn context
|
|
119
|
-
* @param customKey Optional custom key for storing the state in a specific location
|
|
120
219
|
* @returns A promise that resolves when the delete operation is complete
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const userSettings = userState.createProperty<UserSettings>("settings");
|
|
224
|
+
*
|
|
225
|
+
* // Delete the user settings
|
|
226
|
+
* await userSettings.delete(context);
|
|
227
|
+
*
|
|
228
|
+
* // Persist the deletion to storage
|
|
229
|
+
* await userState.saveChanges(context);
|
|
230
|
+
*
|
|
231
|
+
* // Verify deletion
|
|
232
|
+
* const settings = await userSettings.get(context); // Returns undefined
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* @example Custom key usage
|
|
236
|
+
* ```typescript
|
|
237
|
+
* const tenantKey = { key: `tenant_${tenantId}` };
|
|
238
|
+
* await userSettings.delete(context, tenantKey);
|
|
239
|
+
* await userState.saveChanges(context);
|
|
240
|
+
* ```
|
|
121
241
|
*/
|
|
122
242
|
delete(context: TurnContext, customKey?: CustomKey): Promise<void>;
|
|
123
243
|
/**
|
|
124
|
-
*
|
|
244
|
+
* Retrieves the value of the property from state storage.
|
|
245
|
+
*
|
|
246
|
+
* This method provides intelligent default value handling:
|
|
247
|
+
* - If the property exists, its value is returned
|
|
248
|
+
* - If the property doesn't exist and a default value is provided, the default is deep cloned,
|
|
249
|
+
* stored in state, and returned
|
|
250
|
+
* - If the property doesn't exist and no default is provided, `undefined` is returned
|
|
251
|
+
*
|
|
252
|
+
* @remarks
|
|
253
|
+
* **Deep Cloning**: Default values are deep cloned using JSON serialization to prevent
|
|
254
|
+
* reference sharing issues. This means:
|
|
255
|
+
* - Functions, symbols, and circular references will be lost
|
|
256
|
+
* - Dates become strings (use Date constructor to restore)
|
|
257
|
+
* - Complex objects with prototypes lose their prototype chain
|
|
258
|
+
*
|
|
259
|
+
* **Performance**: The first access loads state from storage; subsequent accesses use
|
|
260
|
+
* the in-memory cached version until the context is disposed.
|
|
261
|
+
*
|
|
262
|
+
* @param context The turn context for the current conversation turn
|
|
263
|
+
* @param defaultValue Optional default value to use if the property doesn't exist.
|
|
264
|
+
* When provided, this value is deep cloned and stored in state.
|
|
265
|
+
* @param customKey Optional custom key for accessing state in a specific storage location.
|
|
266
|
+
* Useful for multi-tenant scenarios or when state needs to be partitioned.
|
|
125
267
|
*
|
|
126
|
-
*
|
|
127
|
-
* of the default value will be stored in state and returned. This ensures that
|
|
128
|
-
* modifications to the returned object will be properly tracked.
|
|
268
|
+
* @returns A promise that resolves to the property value, the cloned default value, or `undefined`
|
|
129
269
|
*
|
|
130
|
-
* @
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
270
|
+
* @example Basic usage
|
|
271
|
+
* ```typescript
|
|
272
|
+
* const counterProperty = userState.createProperty<number>("counter");
|
|
273
|
+
*
|
|
274
|
+
* // Get with default value
|
|
275
|
+
* const count = await counterProperty.get(context, 0);
|
|
276
|
+
* console.log(count); // 0 if property doesn't exist, otherwise the stored value
|
|
277
|
+
* ```
|
|
278
|
+
*
|
|
279
|
+
* @example Complex object with default
|
|
280
|
+
* ```typescript
|
|
281
|
+
* interface UserProfile {
|
|
282
|
+
* name: string;
|
|
283
|
+
* preferences: { theme: string; notifications: boolean };
|
|
284
|
+
* }
|
|
285
|
+
*
|
|
286
|
+
* const userProfile = userState.createProperty<UserProfile>("profile");
|
|
287
|
+
* const profile = await userProfile.get(context, {
|
|
288
|
+
* name: "Anonymous",
|
|
289
|
+
* preferences: { theme: "light", notifications: true }
|
|
290
|
+
* });
|
|
291
|
+
* ```
|
|
292
|
+
*
|
|
293
|
+
* @example Checking for existence
|
|
294
|
+
* ```typescript
|
|
295
|
+
* const profile = await userProfile.get(context);
|
|
296
|
+
* if (profile === undefined) {
|
|
297
|
+
* console.log("Profile has not been set yet");
|
|
298
|
+
* } else {
|
|
299
|
+
* console.log(`Welcome back, ${profile.name}!`);
|
|
300
|
+
* }
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* @example Custom key usage
|
|
304
|
+
* ```typescript
|
|
305
|
+
* const tenantKey = { key: `tenant_${tenantId}` };
|
|
306
|
+
* const tenantData = await dataProperty.get(context, defaultData, tenantKey);
|
|
307
|
+
* ```
|
|
134
308
|
*/
|
|
135
309
|
get(context: TurnContext, defaultValue?: T, customKey?: CustomKey): Promise<T>;
|
|
136
310
|
/**
|
|
137
|
-
* Sets the value of the property in
|
|
311
|
+
* Sets the value of the property in state storage.
|
|
138
312
|
*
|
|
139
|
-
* This updates the property in the in-memory state object but does not
|
|
140
|
-
* persist the change to
|
|
313
|
+
* This operation updates the property in the in-memory state object but does not
|
|
314
|
+
* automatically persist the change to the underlying storage. You must call
|
|
315
|
+
* `state.saveChanges(context)` afterwards to persist the changes.
|
|
316
|
+
*
|
|
317
|
+
* @remarks
|
|
318
|
+
* **Memory vs Storage**: Changes are immediately reflected in memory and will be
|
|
319
|
+
* available to subsequent `get()` calls within the same context, but are not
|
|
320
|
+
* persisted to storage until `saveChanges()` is called.
|
|
321
|
+
*
|
|
322
|
+
* **Value References**: The exact value reference is stored (no cloning occurs).
|
|
323
|
+
* Ensure you don't modify objects after setting them unless you intend for those
|
|
324
|
+
* changes to be reflected in state.
|
|
325
|
+
*
|
|
326
|
+
* **Type Safety**: When using TypeScript, the value must match the property's
|
|
327
|
+
* declared type parameter.
|
|
328
|
+
*
|
|
329
|
+
* @param context The turn context for the current conversation turn
|
|
330
|
+
* @param value The value to assign to the property. Can be any serializable value.
|
|
331
|
+
* @param customKey Optional custom key for accessing state in a specific storage location.
|
|
332
|
+
* Useful for multi-tenant scenarios or when state needs to be partitioned.
|
|
141
333
|
*
|
|
142
|
-
* @param context The turn context
|
|
143
|
-
* @param value The value to set
|
|
144
|
-
* @param customKey Optional custom key for storing the state in a specific location
|
|
145
334
|
* @returns A promise that resolves when the set operation is complete
|
|
335
|
+
*
|
|
336
|
+
* @example Basic usage
|
|
337
|
+
* ```typescript
|
|
338
|
+
* const counterProperty = userState.createProperty<number>("counter");
|
|
339
|
+
*
|
|
340
|
+
* // Set a new value
|
|
341
|
+
* await counterProperty.set(context, 42);
|
|
342
|
+
*
|
|
343
|
+
* // Persist to storage
|
|
344
|
+
* await userState.saveChanges(context);
|
|
345
|
+
* ```
|
|
346
|
+
*
|
|
347
|
+
* @example Complex object
|
|
348
|
+
* ```typescript
|
|
349
|
+
* const userProfile = userState.createProperty<UserProfile>("profile");
|
|
350
|
+
*
|
|
351
|
+
* const newProfile: UserProfile = {
|
|
352
|
+
* name: "John Doe",
|
|
353
|
+
* preferences: { theme: "dark", notifications: false }
|
|
354
|
+
* };
|
|
355
|
+
*
|
|
356
|
+
* await userProfile.set(context, newProfile);
|
|
357
|
+
* await userState.saveChanges(context);
|
|
358
|
+
* ```
|
|
359
|
+
*
|
|
360
|
+
* @example Incremental updates
|
|
361
|
+
* ```typescript
|
|
362
|
+
* // Get current value, modify, then set
|
|
363
|
+
* const settings = await settingsProperty.get(context, getDefaultSettings());
|
|
364
|
+
* settings.theme = "dark";
|
|
365
|
+
* settings.lastUpdated = new Date();
|
|
366
|
+
*
|
|
367
|
+
* await settingsProperty.set(context, settings);
|
|
368
|
+
* await userState.saveChanges(context);
|
|
369
|
+
* ```
|
|
370
|
+
*
|
|
371
|
+
* @example Custom key usage
|
|
372
|
+
* ```typescript
|
|
373
|
+
* const tenantKey = { key: `tenant_${tenantId}` };
|
|
374
|
+
* await dataProperty.set(context, updatedData, tenantKey);
|
|
375
|
+
* await userState.saveChanges(context);
|
|
376
|
+
* ```
|
|
146
377
|
*/
|
|
147
378
|
set(context: TurnContext, value: T, customKey?: CustomKey): Promise<void>;
|
|
148
379
|
}
|