@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.
Files changed (148) hide show
  1. package/dist/src/activityHandler.d.ts +29 -5
  2. package/dist/src/activityHandler.js +30 -6
  3. package/dist/src/activityHandler.js.map +1 -1
  4. package/dist/src/agent-client/agentClient.js +1 -1
  5. package/dist/src/agent-client/agentClient.js.map +1 -1
  6. package/dist/src/agent-client/agentResponseHandler.d.ts +34 -0
  7. package/dist/src/agent-client/agentResponseHandler.js +35 -1
  8. package/dist/src/agent-client/agentResponseHandler.js.map +1 -1
  9. package/dist/src/app/adaptiveCards/adaptiveCardsActions.d.ts +23 -2
  10. package/dist/src/app/adaptiveCards/adaptiveCardsActions.js.map +1 -1
  11. package/dist/src/app/adaptiveCards/adaptiveCardsSearchParams.d.ts +1 -1
  12. package/dist/src/app/agentApplication.d.ts +46 -34
  13. package/dist/src/app/agentApplication.js +64 -40
  14. package/dist/src/app/agentApplication.js.map +1 -1
  15. package/dist/src/app/agentApplicationOptions.d.ts +74 -13
  16. package/dist/src/app/appRoute.d.ts +56 -2
  17. package/dist/src/app/attachmentDownloader.d.ts +1 -0
  18. package/dist/src/app/attachmentDownloader.js +2 -1
  19. package/dist/src/app/attachmentDownloader.js.map +1 -1
  20. package/dist/src/app/authorization.d.ts +1 -1
  21. package/dist/src/app/authorization.js +1 -1
  22. package/dist/src/app/authorization.js.map +1 -1
  23. package/dist/src/app/extensions.d.ts +37 -1
  24. package/dist/src/app/extensions.js +38 -2
  25. package/dist/src/app/extensions.js.map +1 -1
  26. package/dist/src/app/index.d.ts +2 -0
  27. package/dist/src/app/index.js +2 -0
  28. package/dist/src/app/index.js.map +1 -1
  29. package/dist/src/app/routeList.d.ts +13 -0
  30. package/dist/src/app/routeList.js +30 -0
  31. package/dist/src/app/routeList.js.map +1 -0
  32. package/dist/src/app/routeRank.d.ts +51 -0
  33. package/dist/src/app/routeRank.js +56 -0
  34. package/dist/src/app/routeRank.js.map +1 -0
  35. package/dist/src/app/streaming/citationUtil.d.ts +1 -1
  36. package/dist/src/app/streaming/streamingResponse.d.ts +1 -2
  37. package/dist/src/app/streaming/streamingResponse.js +29 -41
  38. package/dist/src/app/streaming/streamingResponse.js.map +1 -1
  39. package/dist/src/app/turnState.d.ts +2 -0
  40. package/dist/src/app/turnState.js +3 -1
  41. package/dist/src/app/turnState.js.map +1 -1
  42. package/dist/src/auth/authConfiguration.d.ts +4 -0
  43. package/dist/src/auth/authConfiguration.js +5 -1
  44. package/dist/src/auth/authConfiguration.js.map +1 -1
  45. package/dist/src/auth/authProvider.d.ts +1 -1
  46. package/dist/src/auth/jwt-middleware.js +1 -1
  47. package/dist/src/auth/jwt-middleware.js.map +1 -1
  48. package/dist/src/auth/msalTokenCredential.d.ts +14 -0
  49. package/dist/src/auth/msalTokenCredential.js +14 -0
  50. package/dist/src/auth/msalTokenCredential.js.map +1 -1
  51. package/dist/src/auth/msalTokenProvider.js +4 -2
  52. package/dist/src/auth/msalTokenProvider.js.map +1 -1
  53. package/dist/src/baseAdapter.d.ts +22 -1
  54. package/dist/src/baseAdapter.js +23 -2
  55. package/dist/src/baseAdapter.js.map +1 -1
  56. package/dist/src/cards/adaptiveCard.d.ts +2 -0
  57. package/dist/src/cards/animationCard.d.ts +1 -1
  58. package/dist/src/cards/audioCard.d.ts +1 -1
  59. package/dist/src/cards/cardImage.d.ts +1 -1
  60. package/dist/src/cards/fact.d.ts +1 -1
  61. package/dist/src/cards/heroCard.d.ts +1 -1
  62. package/dist/src/cards/o365ConnectorCardSection.d.ts +5 -0
  63. package/dist/src/cloudAdapter.d.ts +11 -0
  64. package/dist/src/cloudAdapter.js +33 -4
  65. package/dist/src/cloudAdapter.js.map +1 -1
  66. package/dist/src/connector-client/connectorClient.js +1 -1
  67. package/dist/src/connector-client/connectorClient.js.map +1 -1
  68. package/dist/src/getProductInfo.js +2 -2
  69. package/dist/src/getProductInfo.js.map +1 -1
  70. package/dist/src/index.d.ts +0 -2
  71. package/dist/src/index.js +0 -2
  72. package/dist/src/index.js.map +1 -1
  73. package/dist/src/middlewareSet.js +1 -1
  74. package/dist/src/middlewareSet.js.map +1 -1
  75. package/dist/src/oauth/oAuthFlow.js +1 -1
  76. package/dist/src/oauth/oAuthFlow.js.map +1 -1
  77. package/dist/src/oauth/userTokenClient.js +1 -1
  78. package/dist/src/oauth/userTokenClient.js.map +1 -1
  79. package/dist/src/state/agentState.js +1 -1
  80. package/dist/src/state/agentState.js.map +1 -1
  81. package/dist/src/state/agentStatePropertyAccesor.d.ts +269 -38
  82. package/dist/src/state/agentStatePropertyAccesor.js +269 -38
  83. package/dist/src/state/agentStatePropertyAccesor.js.map +1 -1
  84. package/dist/src/statusCodes.d.ts +30 -0
  85. package/dist/src/statusCodes.js +30 -0
  86. package/dist/src/statusCodes.js.map +1 -1
  87. package/dist/src/storage/fileStorage.d.ts +97 -0
  88. package/dist/src/storage/fileStorage.js +97 -0
  89. package/dist/src/storage/fileStorage.js.map +1 -1
  90. package/dist/src/storage/memoryStorage.d.ts +2 -1
  91. package/dist/src/storage/memoryStorage.js +3 -2
  92. package/dist/src/storage/memoryStorage.js.map +1 -1
  93. package/dist/src/storage/storage.d.ts +1 -0
  94. package/dist/src/transcript/transcriptLoggerMiddleware.js +1 -1
  95. package/dist/src/transcript/transcriptLoggerMiddleware.js.map +1 -1
  96. package/dist/src/turnContext.d.ts +1 -0
  97. package/dist/src/turnContext.js +1 -0
  98. package/dist/src/turnContext.js.map +1 -1
  99. package/package.json +4 -5
  100. package/src/activityHandler.ts +30 -6
  101. package/src/agent-client/agentClient.ts +1 -1
  102. package/src/agent-client/agentResponseHandler.ts +35 -1
  103. package/src/app/adaptiveCards/adaptiveCardsActions.ts +23 -2
  104. package/src/app/adaptiveCards/adaptiveCardsSearchParams.ts +1 -1
  105. package/src/app/agentApplication.ts +70 -41
  106. package/src/app/agentApplicationOptions.ts +75 -13
  107. package/src/app/appRoute.ts +57 -2
  108. package/src/app/attachmentDownloader.ts +2 -1
  109. package/src/app/authorization.ts +2 -2
  110. package/src/app/extensions.ts +45 -2
  111. package/src/app/index.ts +2 -0
  112. package/src/app/routeList.ts +37 -0
  113. package/src/app/routeRank.ts +54 -0
  114. package/src/app/streaming/citationUtil.ts +1 -1
  115. package/src/app/streaming/streamingResponse.ts +23 -71
  116. package/src/app/turnState.ts +3 -1
  117. package/src/auth/authConfiguration.ts +5 -1
  118. package/src/auth/authProvider.ts +1 -1
  119. package/src/auth/jwt-middleware.ts +1 -1
  120. package/src/auth/msalTokenCredential.ts +15 -0
  121. package/src/auth/msalTokenProvider.ts +4 -2
  122. package/src/baseAdapter.ts +25 -2
  123. package/src/cards/adaptiveCard.ts +2 -0
  124. package/src/cards/animationCard.ts +1 -1
  125. package/src/cards/audioCard.ts +1 -1
  126. package/src/cards/cardImage.ts +1 -1
  127. package/src/cards/fact.ts +1 -1
  128. package/src/cards/heroCard.ts +1 -1
  129. package/src/cards/o365ConnectorCardSection.ts +5 -0
  130. package/src/cloudAdapter.ts +36 -4
  131. package/src/connector-client/connectorClient.ts +1 -1
  132. package/src/getProductInfo.ts +2 -2
  133. package/src/index.ts +0 -2
  134. package/src/middlewareSet.ts +1 -1
  135. package/src/oauth/oAuthFlow.ts +1 -1
  136. package/src/oauth/userTokenClient.ts +1 -1
  137. package/src/state/agentState.ts +1 -1
  138. package/src/state/agentStatePropertyAccesor.ts +269 -38
  139. package/src/statusCodes.ts +30 -0
  140. package/src/storage/fileStorage.ts +99 -0
  141. package/src/storage/memoryStorage.ts +3 -2
  142. package/src/storage/storage.ts +1 -0
  143. package/src/transcript/transcriptLoggerMiddleware.ts +1 -1
  144. package/src/turnContext.ts +1 -0
  145. package/dist/src/logger.d.ts +0 -44
  146. package/dist/src/logger.js +0 -77
  147. package/dist/src/logger.js.map +0 -1
  148. package/src/logger.ts +0 -76
@@ -6,58 +6,178 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.AgentStatePropertyAccessor = void 0;
8
8
  /**
9
- * Provides typed access to an Agent state property with automatic state loading.
9
+ * Provides typed access to an Agent state property with automatic state loading and persistence management.
10
10
  *
11
- * The AgentStatePropertyAccessor simplifies working with state by abstracting
12
- * the details of loading state from storage and manipulating specific properties.
13
- * It automatically handles:
11
+ * @remarks
12
+ * AgentStatePropertyAccessor simplifies working with persisted state by abstracting
13
+ * the complexity of loading state from storage and manipulating specific properties.
14
+ * It provides a type-safe interface for state management with automatic handling of:
14
15
  *
15
- * - Loading state when needed
16
- * - Deep cloning of default values to prevent reference issues
17
- * - Type checking for properties (when using TypeScript)
18
- * - Ensuring properties exist before access
16
+ * - **Lazy Loading**: State is loaded from storage only when first accessed
17
+ * - **Type Safety**: Full TypeScript support with generic type parameters
18
+ * - **Default Values**: Automatic deep cloning of default values to prevent reference issues
19
+ * - **Memory Management**: Efficient in-memory caching with explicit persistence control
20
+ * - **Custom Keys**: Support for custom storage keys for advanced scenarios
19
21
  *
20
- * Property accessors are created through the {@link AgentState.createProperty} method:
22
+ * ## Key Features
21
23
  *
24
+ * ### Type Safety
25
+ * The accessor provides compile-time type checking when using TypeScript:
22
26
  * ```typescript
23
- * // Create a property accessor for a user profile
27
+ * interface UserProfile {
28
+ * name: string;
29
+ * preferences: { theme: string; language: string };
30
+ * }
24
31
  * const userProfile = userState.createProperty<UserProfile>("userProfile");
32
+ * ```
33
+ *
34
+ * ### Automatic Default Value Handling
35
+ * When a property doesn't exist, default values are automatically cloned and stored:
36
+ * ```typescript
37
+ * // If userProfile doesn't exist, the default will be cloned and saved
38
+ * const profile = await userProfile.get(context, {
39
+ * name: "Anonymous",
40
+ * preferences: { theme: "light", language: "en" }
41
+ * });
42
+ * ```
43
+ *
44
+ * ### Explicit Persistence Control
45
+ * Changes are kept in memory until explicitly persisted:
46
+ * ```typescript
47
+ * // Modify the state
48
+ * const counter = await counterProperty.get(context, 0);
49
+ * await counterProperty.set(context, counter + 1);
50
+ *
51
+ * // Changes are only in memory at this point
52
+ * // Persist to storage
53
+ * await userState.saveChanges(context);
54
+ * ```
25
55
  *
26
- * // Get the profile with a default if not exists
27
- * const profile = await userProfile.get(context, { name: "", preferences: {} });
56
+ * ## Usage Examples
28
57
  *
29
- * // Update a value
58
+ * ### Basic Usage
59
+ * ```typescript
60
+ * // Create a property accessor
61
+ * const userProfile = userState.createProperty<UserProfile>("userProfile");
62
+ *
63
+ * // Get with default value
64
+ * const profile = await userProfile.get(context, {
65
+ * name: "",
66
+ * preferences: { theme: "light", language: "en" }
67
+ * });
68
+ *
69
+ * // Modify the profile
30
70
  * profile.preferences.theme = "dark";
31
71
  *
32
- * // Save the change
72
+ * // Save the changes
33
73
  * await userProfile.set(context, profile);
74
+ * await userState.saveChanges(context); // Persist to storage
75
+ * ```
76
+ *
77
+ * ### Working with Primitive Types
78
+ * ```typescript
79
+ * const counterProperty = userState.createProperty<number>("counter");
34
80
  *
35
- * // Later, call userState.saveChanges(context) to persist to storage
81
+ * // Increment counter
82
+ * const currentCount = await counterProperty.get(context, 0);
83
+ * await counterProperty.set(context, currentCount + 1);
84
+ * await userState.saveChanges(context);
36
85
  * ```
37
86
  *
38
- * @typeParam T The type of the property being accessed
87
+ * ### Conditional Logic
88
+ * ```typescript
89
+ * const settingsProperty = userState.createProperty<Settings>("settings");
90
+ *
91
+ * // Check if property exists
92
+ * const settings = await settingsProperty.get(context);
93
+ * if (settings === undefined) {
94
+ * // Property doesn't exist, initialize with defaults
95
+ * await settingsProperty.set(context, getDefaultSettings());
96
+ * }
97
+ * ```
98
+ *
99
+ * ### Custom Storage Keys
100
+ * ```typescript
101
+ * // Store state with a custom key for multi-tenant scenarios
102
+ * const customKey = { key: `tenant_${tenantId}` };
103
+ * const tenantData = await dataProperty.get(context, defaultData, customKey);
104
+ * await dataProperty.set(context, updatedData, customKey);
105
+ * ```
106
+ *
107
+ * ## Important Notes
108
+ *
109
+ * - **Thread Safety**: This class is not thread-safe. Ensure proper synchronization in concurrent scenarios.
110
+ * - **Memory Usage**: State objects are kept in memory until the context is disposed.
111
+ * - **Persistence**: Always call `state.saveChanges(context)` to persist changes to storage.
112
+ * - **Deep Cloning**: Default values are deep cloned using JSON serialization, which may not work with complex objects containing functions or circular references.
113
+ *
114
+ * @typeParam T The type of the property being accessed. Can be any serializable type.
115
+ *
116
+ * @see {@link AgentState.createProperty} for creating property accessors
117
+ * @see {@link StatePropertyAccessor} for the interface definition
39
118
  */
40
119
  class AgentStatePropertyAccessor {
41
120
  /**
42
121
  * Creates a new instance of AgentStatePropertyAccessor.
43
122
  *
44
- * @param state The agent state object that will contain this property
45
- * @param name The name of the property in the state object
123
+ * @remarks
124
+ * This constructor is typically not called directly. Instead, use {@link AgentState.createProperty}
125
+ * to create property accessors, which ensures proper integration with the state management system.
126
+ *
127
+ * @param state The agent state object that manages the backing storage for this property
128
+ * @param name The unique name of the property within the state object. This name is used as the key in the state storage.
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * // Recommended way - use AgentState.createProperty
133
+ * const userProfile = userState.createProperty<UserProfile>("userProfile");
134
+ *
135
+ * // Direct construction (not recommended)
136
+ * const accessor = new AgentStatePropertyAccessor<UserProfile>(userState, "userProfile");
137
+ * ```
46
138
  */
47
139
  constructor(state, name) {
48
140
  this.state = state;
49
141
  this.name = name;
50
142
  }
51
143
  /**
52
- * Deletes the property from the state.
144
+ * Deletes the property from the state storage.
145
+ *
146
+ * This operation removes the property from the in-memory state object but does not
147
+ * automatically persist the change to the underlying storage. You must call
148
+ * `state.saveChanges(context)` afterwards to persist the deletion.
53
149
  *
54
- * This removes the property from the state object but does not automatically
55
- * persist the change to storage. Call state.saveChanges() afterwards to
56
- * persist changes.
150
+ * @remarks
151
+ * - If the property doesn't exist, this operation is a no-op
152
+ * - The deletion only affects the in-memory state until `saveChanges()` is called
153
+ * - After deletion, subsequent `get()` calls will return `undefined` (or the default value if provided)
154
+ *
155
+ * @param context The turn context for the current conversation turn
156
+ * @param customKey Optional custom key for accessing state in a specific storage location.
157
+ * Useful for multi-tenant scenarios or when state needs to be partitioned.
57
158
  *
58
- * @param context The turn context
59
- * @param customKey Optional custom key for storing the state in a specific location
60
159
  * @returns A promise that resolves when the delete operation is complete
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * const userSettings = userState.createProperty<UserSettings>("settings");
164
+ *
165
+ * // Delete the user settings
166
+ * await userSettings.delete(context);
167
+ *
168
+ * // Persist the deletion to storage
169
+ * await userState.saveChanges(context);
170
+ *
171
+ * // Verify deletion
172
+ * const settings = await userSettings.get(context); // Returns undefined
173
+ * ```
174
+ *
175
+ * @example Custom key usage
176
+ * ```typescript
177
+ * const tenantKey = { key: `tenant_${tenantId}` };
178
+ * await userSettings.delete(context, tenantKey);
179
+ * await userState.saveChanges(context);
180
+ * ```
61
181
  */
62
182
  async delete(context, customKey) {
63
183
  const obj = await this.state.load(context, false, customKey);
@@ -66,16 +186,70 @@ class AgentStatePropertyAccessor {
66
186
  }
67
187
  }
68
188
  /**
69
- * Gets the value of the property from the state.
189
+ * Retrieves the value of the property from state storage.
190
+ *
191
+ * This method provides intelligent default value handling:
192
+ * - If the property exists, its value is returned
193
+ * - If the property doesn't exist and a default value is provided, the default is deep cloned,
194
+ * stored in state, and returned
195
+ * - If the property doesn't exist and no default is provided, `undefined` is returned
196
+ *
197
+ * @remarks
198
+ * **Deep Cloning**: Default values are deep cloned using JSON serialization to prevent
199
+ * reference sharing issues. This means:
200
+ * - Functions, symbols, and circular references will be lost
201
+ * - Dates become strings (use Date constructor to restore)
202
+ * - Complex objects with prototypes lose their prototype chain
203
+ *
204
+ * **Performance**: The first access loads state from storage; subsequent accesses use
205
+ * the in-memory cached version until the context is disposed.
206
+ *
207
+ * @param context The turn context for the current conversation turn
208
+ * @param defaultValue Optional default value to use if the property doesn't exist.
209
+ * When provided, this value is deep cloned and stored in state.
210
+ * @param customKey Optional custom key for accessing state in a specific storage location.
211
+ * Useful for multi-tenant scenarios or when state needs to be partitioned.
212
+ *
213
+ * @returns A promise that resolves to the property value, the cloned default value, or `undefined`
214
+ *
215
+ * @example Basic usage
216
+ * ```typescript
217
+ * const counterProperty = userState.createProperty<number>("counter");
218
+ *
219
+ * // Get with default value
220
+ * const count = await counterProperty.get(context, 0);
221
+ * console.log(count); // 0 if property doesn't exist, otherwise the stored value
222
+ * ```
223
+ *
224
+ * @example Complex object with default
225
+ * ```typescript
226
+ * interface UserProfile {
227
+ * name: string;
228
+ * preferences: { theme: string; notifications: boolean };
229
+ * }
70
230
  *
71
- * If the property doesn't exist and a default value is provided, a deep clone
72
- * of the default value will be stored in state and returned. This ensures that
73
- * modifications to the returned object will be properly tracked.
231
+ * const userProfile = userState.createProperty<UserProfile>("profile");
232
+ * const profile = await userProfile.get(context, {
233
+ * name: "Anonymous",
234
+ * preferences: { theme: "light", notifications: true }
235
+ * });
236
+ * ```
74
237
  *
75
- * @param context The turn context
76
- * @param defaultValue Optional default value to use if the property doesn't exist
77
- * @param customKey Optional custom key for storing the state in a specific location
78
- * @returns A promise that resolves to the value of the property or undefined
238
+ * @example Checking for existence
239
+ * ```typescript
240
+ * const profile = await userProfile.get(context);
241
+ * if (profile === undefined) {
242
+ * console.log("Profile has not been set yet");
243
+ * } else {
244
+ * console.log(`Welcome back, ${profile.name}!`);
245
+ * }
246
+ * ```
247
+ *
248
+ * @example Custom key usage
249
+ * ```typescript
250
+ * const tenantKey = { key: `tenant_${tenantId}` };
251
+ * const tenantData = await dataProperty.get(context, defaultData, tenantKey);
252
+ * ```
79
253
  */
80
254
  async get(context, defaultValue, customKey) {
81
255
  const obj = await this.state.load(context, false, customKey);
@@ -88,15 +262,72 @@ class AgentStatePropertyAccessor {
88
262
  return obj[this.name];
89
263
  }
90
264
  /**
91
- * Sets the value of the property in the state.
265
+ * Sets the value of the property in state storage.
266
+ *
267
+ * This operation updates the property in the in-memory state object but does not
268
+ * automatically persist the change to the underlying storage. You must call
269
+ * `state.saveChanges(context)` afterwards to persist the changes.
270
+ *
271
+ * @remarks
272
+ * **Memory vs Storage**: Changes are immediately reflected in memory and will be
273
+ * available to subsequent `get()` calls within the same context, but are not
274
+ * persisted to storage until `saveChanges()` is called.
275
+ *
276
+ * **Value References**: The exact value reference is stored (no cloning occurs).
277
+ * Ensure you don't modify objects after setting them unless you intend for those
278
+ * changes to be reflected in state.
92
279
  *
93
- * This updates the property in the in-memory state object but does not automatically
94
- * persist the change to storage. Call state.saveChanges() afterwards to persist changes.
280
+ * **Type Safety**: When using TypeScript, the value must match the property's
281
+ * declared type parameter.
282
+ *
283
+ * @param context The turn context for the current conversation turn
284
+ * @param value The value to assign to the property. Can be any serializable value.
285
+ * @param customKey Optional custom key for accessing state in a specific storage location.
286
+ * Useful for multi-tenant scenarios or when state needs to be partitioned.
95
287
  *
96
- * @param context The turn context
97
- * @param value The value to set
98
- * @param customKey Optional custom key for storing the state in a specific location
99
288
  * @returns A promise that resolves when the set operation is complete
289
+ *
290
+ * @example Basic usage
291
+ * ```typescript
292
+ * const counterProperty = userState.createProperty<number>("counter");
293
+ *
294
+ * // Set a new value
295
+ * await counterProperty.set(context, 42);
296
+ *
297
+ * // Persist to storage
298
+ * await userState.saveChanges(context);
299
+ * ```
300
+ *
301
+ * @example Complex object
302
+ * ```typescript
303
+ * const userProfile = userState.createProperty<UserProfile>("profile");
304
+ *
305
+ * const newProfile: UserProfile = {
306
+ * name: "John Doe",
307
+ * preferences: { theme: "dark", notifications: false }
308
+ * };
309
+ *
310
+ * await userProfile.set(context, newProfile);
311
+ * await userState.saveChanges(context);
312
+ * ```
313
+ *
314
+ * @example Incremental updates
315
+ * ```typescript
316
+ * // Get current value, modify, then set
317
+ * const settings = await settingsProperty.get(context, getDefaultSettings());
318
+ * settings.theme = "dark";
319
+ * settings.lastUpdated = new Date();
320
+ *
321
+ * await settingsProperty.set(context, settings);
322
+ * await userState.saveChanges(context);
323
+ * ```
324
+ *
325
+ * @example Custom key usage
326
+ * ```typescript
327
+ * const tenantKey = { key: `tenant_${tenantId}` };
328
+ * await dataProperty.set(context, updatedData, tenantKey);
329
+ * await userState.saveChanges(context);
330
+ * ```
100
331
  */
101
332
  async set(context, value, customKey) {
102
333
  const obj = await this.state.load(context, false, customKey);
@@ -1 +1 @@
1
- {"version":3,"file":"agentStatePropertyAccesor.js","sourceRoot":"","sources":["../../../src/state/agentStatePropertyAccesor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAuEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAa,0BAA0B;IACrC;;;;;OAKG;IACH,YAAgC,KAAiB,EAAkB,IAAY;QAA/C,UAAK,GAAL,KAAK,CAAY;QAAkB,SAAI,GAAJ,IAAI,CAAQ;IAAI,CAAC;IAEpF;;;;;;;;;;OAUG;IACH,KAAK,CAAC,MAAM,CAAE,OAAoB,EAAE,SAAqB;QACvD,MAAM,GAAG,GAAQ,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;QACjE,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACzD,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACvB,CAAC;IACH,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,GAAG,CAAE,OAAoB,EAAE,YAAgB,EAAE,SAAqB;QACtE,MAAM,GAAG,GAAQ,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;QACjE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YACxF,MAAM,KAAK,GACT,OAAO,YAAY,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;gBAC7D,CAAC,CAAC,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87 @@
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ /**
6
+ * HTTP status codes enumeration for agent hosting responses.
7
+ *
8
+ * This enum provides a comprehensive set of HTTP status codes commonly used
9
+ * in agent hosting scenarios, including success, redirection, client error,
10
+ * and server error status codes.
11
+ */
5
12
  export declare enum StatusCodes {
6
13
  /**
7
14
  * The request has succeeded.
15
+ * Standard response for successful HTTP requests.
8
16
  */
9
17
  OK = 200,
10
18
  /**
11
19
  * The request has been fulfilled and resulted in a new resource being created.
20
+ * Typically returned when a new agent, conversation, or resource is successfully created.
12
21
  */
13
22
  CREATED = 201,
14
23
  /**
15
24
  * Indicates multiple options for the resource that the client may follow.
25
+ * Used when there are multiple possible responses or resource locations available.
16
26
  */
17
27
  MULTIPLE_CHOICES = 300,
18
28
  /**
19
29
  * The server cannot or will not process the request due to a client error.
30
+ * Returned when the request contains invalid syntax, malformed parameters,
31
+ * or violates agent hosting protocol requirements.
20
32
  */
21
33
  BAD_REQUEST = 400,
22
34
  /**
23
35
  * The request requires user authentication.
36
+ * Indicates that the client must authenticate itself to get the requested response.
37
+ * Common in agent scenarios requiring valid authentication tokens or credentials.
24
38
  */
25
39
  UNAUTHORIZED = 401,
26
40
  /**
27
41
  * The requested resource could not be found.
42
+ * Returned when the specified agent, conversation, or endpoint does not exist
43
+ * or is not accessible with the current permissions.
28
44
  */
29
45
  NOT_FOUND = 404,
30
46
  /**
31
47
  * The request method is not allowed for the requested resource.
48
+ * Indicates that the HTTP method used is not supported for the specific
49
+ * agent endpoint or resource being accessed.
32
50
  */
33
51
  METHOD_NOT_ALLOWED = 405,
34
52
  /**
35
53
  * The request could not be completed due to a conflict with the current state of the resource.
54
+ * Common when attempting to create duplicate resources or when agent state
55
+ * conflicts prevent the operation from completing.
36
56
  */
37
57
  CONFLICT = 409,
38
58
  /**
39
59
  * The server does not meet one of the preconditions specified by the client.
60
+ * Returned when conditional requests fail, such as when required headers
61
+ * or agent capabilities are not present or valid.
40
62
  */
41
63
  PRECONDITION_FAILED = 412,
42
64
  /**
43
65
  * The client should switch to a different protocol.
66
+ * Used to indicate that the agent hosting service requires a protocol upgrade
67
+ * or different communication method to fulfill the request.
44
68
  */
45
69
  UPGRADE_REQUIRED = 426,
46
70
  /**
47
71
  * The server encountered an unexpected condition that prevented it from fulfilling the request.
72
+ * Generic error message when an unexpected agent hosting error occurs
73
+ * and no more specific message is suitable.
48
74
  */
49
75
  INTERNAL_SERVER_ERROR = 500,
50
76
  /**
51
77
  * The server does not support the functionality required to fulfill the request.
78
+ * Returned when the agent hosting service does not implement the requested
79
+ * feature or capability.
52
80
  */
53
81
  NOT_IMPLEMENTED = 501,
54
82
  /**
55
83
  * The server received an invalid response from the upstream server.
84
+ * Common when agent hosting services depend on external services
85
+ * that return invalid or malformed responses.
56
86
  */
57
87
  BAD_GATEWAY = 502
58
88
  }
@@ -5,58 +5,88 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.StatusCodes = void 0;
8
+ /**
9
+ * HTTP status codes enumeration for agent hosting responses.
10
+ *
11
+ * This enum provides a comprehensive set of HTTP status codes commonly used
12
+ * in agent hosting scenarios, including success, redirection, client error,
13
+ * and server error status codes.
14
+ */
8
15
  var StatusCodes;
9
16
  (function (StatusCodes) {
10
17
  /**
11
18
  * The request has succeeded.
19
+ * Standard response for successful HTTP requests.
12
20
  */
13
21
  StatusCodes[StatusCodes["OK"] = 200] = "OK";
14
22
  /**
15
23
  * The request has been fulfilled and resulted in a new resource being created.
24
+ * Typically returned when a new agent, conversation, or resource is successfully created.
16
25
  */
17
26
  StatusCodes[StatusCodes["CREATED"] = 201] = "CREATED";
18
27
  /**
19
28
  * Indicates multiple options for the resource that the client may follow.
29
+ * Used when there are multiple possible responses or resource locations available.
20
30
  */
21
31
  StatusCodes[StatusCodes["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
22
32
  /**
23
33
  * The server cannot or will not process the request due to a client error.
34
+ * Returned when the request contains invalid syntax, malformed parameters,
35
+ * or violates agent hosting protocol requirements.
24
36
  */
25
37
  StatusCodes[StatusCodes["BAD_REQUEST"] = 400] = "BAD_REQUEST";
26
38
  /**
27
39
  * The request requires user authentication.
40
+ * Indicates that the client must authenticate itself to get the requested response.
41
+ * Common in agent scenarios requiring valid authentication tokens or credentials.
28
42
  */
29
43
  StatusCodes[StatusCodes["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
30
44
  /**
31
45
  * The requested resource could not be found.
46
+ * Returned when the specified agent, conversation, or endpoint does not exist
47
+ * or is not accessible with the current permissions.
32
48
  */
33
49
  StatusCodes[StatusCodes["NOT_FOUND"] = 404] = "NOT_FOUND";
34
50
  /**
35
51
  * The request method is not allowed for the requested resource.
52
+ * Indicates that the HTTP method used is not supported for the specific
53
+ * agent endpoint or resource being accessed.
36
54
  */
37
55
  StatusCodes[StatusCodes["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
38
56
  /**
39
57
  * The request could not be completed due to a conflict with the current state of the resource.
58
+ * Common when attempting to create duplicate resources or when agent state
59
+ * conflicts prevent the operation from completing.
40
60
  */
41
61
  StatusCodes[StatusCodes["CONFLICT"] = 409] = "CONFLICT";
42
62
  /**
43
63
  * The server does not meet one of the preconditions specified by the client.
64
+ * Returned when conditional requests fail, such as when required headers
65
+ * or agent capabilities are not present or valid.
44
66
  */
45
67
  StatusCodes[StatusCodes["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
46
68
  /**
47
69
  * The client should switch to a different protocol.
70
+ * Used to indicate that the agent hosting service requires a protocol upgrade
71
+ * or different communication method to fulfill the request.
48
72
  */
49
73
  StatusCodes[StatusCodes["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
50
74
  /**
51
75
  * The server encountered an unexpected condition that prevented it from fulfilling the request.
76
+ * Generic error message when an unexpected agent hosting error occurs
77
+ * and no more specific message is suitable.
52
78
  */
53
79
  StatusCodes[StatusCodes["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
54
80
  /**
55
81
  * The server does not support the functionality required to fulfill the request.
82
+ * Returned when the agent hosting service does not implement the requested
83
+ * feature or capability.
56
84
  */
57
85
  StatusCodes[StatusCodes["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
58
86
  /**
59
87
  * The server received an invalid response from the upstream server.
88
+ * Common when agent hosting services depend on external services
89
+ * that return invalid or malformed responses.
60
90
  */
61
91
  StatusCodes[StatusCodes["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
62
92
  })(StatusCodes || (exports.StatusCodes = StatusCodes = {}));
@@ -1 +1 @@
1
- {"version":3,"file":"statusCodes.js","sourceRoot":"","sources":["../../src/statusCodes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,IAAY,WAiEX;AAjED,WAAY,WAAW;IACrB;;OAEG;IACH,2CAAQ,CAAA;IAER;;OAEG;IACH,qDAAa,CAAA;IAEb;;OAEG;IACH,uEAAsB,CAAA;IAEtB;;OAEG;IACH,6DAAiB,CAAA;IAEjB;;OAEG;IACH,+DAAkB,CAAA;IAElB;;OAEG;IACH,yDAAe,CAAA;IAEf;;OAEG;IACH,2EAAwB,CAAA;IAExB;;OAEG;IACH,uDAAc,CAAA;IAEd;;OAEG;IACH,6EAAyB,CAAA;IAEzB;;OAEG;IACH,uEAAsB,CAAA;IAEtB;;OAEG;IACH,iFAA2B,CAAA;IAE3B;;OAEG;IACH,qEAAqB,CAAA;IAErB;;OAEG;IACH,6DAAiB,CAAA;AACnB,CAAC,EAjEW,WAAW,2BAAX,WAAW,QAiEtB"}
1
+ {"version":3,"file":"statusCodes.js","sourceRoot":"","sources":["../../src/statusCodes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;GAMG;AACH,IAAY,WAwFX;AAxFD,WAAY,WAAW;IACrB;;;OAGG;IACH,2CAAQ,CAAA;IAER;;;OAGG;IACH,qDAAa,CAAA;IAEb;;;OAGG;IACH,uEAAsB,CAAA;IAEtB;;;;OAIG;IACH,6DAAiB,CAAA;IAEjB;;;;OAIG;IACH,+DAAkB,CAAA;IAElB;;;;OAIG;IACH,yDAAe,CAAA;IAEf;;;;OAIG;IACH,2EAAwB,CAAA;IAExB;;;;OAIG;IACH,uDAAc,CAAA;IAEd;;;;OAIG;IACH,6EAAyB,CAAA;IAEzB;;;;OAIG;IACH,uEAAsB,CAAA;IAEtB;;;;OAIG;IACH,iFAA2B,CAAA;IAE3B;;;;OAIG;IACH,qEAAqB,CAAA;IAErB;;;;OAIG;IACH,6DAAiB,CAAA;AACnB,CAAC,EAxFW,WAAW,2BAAX,WAAW,QAwFtB"}
@@ -1,9 +1,106 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
1
5
  import { Storage, StoreItem } from './storage';
6
+ /**
7
+ * A file-based storage implementation that persists data to the local filesystem.
8
+ *
9
+ * @remarks
10
+ * FileStorage stores all data in a single JSON file named 'state.json' within a specified folder.
11
+ * This implementation is suitable for development scenarios, local testing, and single-instance
12
+ * deployments where shared state across multiple instances is not required.
13
+ *
14
+ * The storage format is a simple key-value JSON object where keys are strings and values
15
+ * can be any JSON-serializable data. All operations are synchronous file I/O operations
16
+ * wrapped in Promise interfaces to match the Storage contract.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const storage = new FileStorage('./data');
21
+ *
22
+ * // Write some data
23
+ * await storage.write({
24
+ * 'user123': { name: 'John', lastSeen: new Date().toISOString() },
25
+ * 'conversation456': { turn: 5, context: 'discussing weather' }
26
+ * });
27
+ *
28
+ * // Read specific keys
29
+ * const data = await storage.read(['user123']);
30
+ * console.log(data.user123); // { name: 'John', lastSeen: '...' }
31
+ *
32
+ * // Delete data
33
+ * await storage.delete(['conversation456']);
34
+ * ```
35
+ *
36
+ * @warning
37
+ * This implementation does not provide:
38
+ * - Thread safety for concurrent access
39
+ * - Optimistic concurrency control (eTag support)
40
+ * - Atomic operations across multiple keys
41
+ * - Scale for large datasets
42
+ *
43
+ * For production scenarios requiring these features, consider using
44
+ * database-backed storage implementations instead.
45
+ */
2
46
  export declare class FileStorage implements Storage {
3
47
  private _folder;
4
48
  private _stateFile;
49
+ /**
50
+ * Creates a new FileStorage instance that stores data in the specified folder.
51
+ *
52
+ * @param folder The absolute or relative path to the folder where the state.json file will be stored
53
+ *
54
+ * @remarks
55
+ * The constructor performs the following initialization steps:
56
+ * 1. Creates the target folder if it doesn't exist (including parent directories)
57
+ * 2. Creates an empty state.json file if it doesn't exist
58
+ * 3. Loads existing data from state.json into memory for fast access
59
+ *
60
+ * @throws May throw filesystem errors if the folder cannot be created or accessed
61
+ */
5
62
  constructor(folder: string);
63
+ /**
64
+ * Reads store items from the filesystem storage.
65
+ *
66
+ * @param keys Array of keys to read from storage
67
+ * @returns Promise resolving to an object containing the requested items (keys that don't exist are omitted)
68
+ *
69
+ * @throws ReferenceError if keys array is empty or undefined
70
+ *
71
+ * @remarks
72
+ * This method reads from the in-memory cache that was loaded during construction,
73
+ * making it very fast but potentially returning stale data if the file was
74
+ * modified by external processes.
75
+ */
6
76
  read(keys: string[]): Promise<StoreItem>;
77
+ /**
78
+ * Writes store items to the filesystem storage.
79
+ *
80
+ * @param changes Object containing key-value pairs to write to storage
81
+ * @returns Promise that resolves when the write operation completes
82
+ *
83
+ * @remarks
84
+ * This method updates both the in-memory cache and writes the entire state
85
+ * to the state.json file. The file is written with pretty-printing (2-space indentation)
86
+ * for better readability during development and debugging.
87
+ *
88
+ * Note: This implementation does not support eTag-based optimistic concurrency control.
89
+ * Any eTag values in the changes object are ignored.
90
+ */
7
91
  write(changes: StoreItem): Promise<void>;
92
+ /**
93
+ * Deletes store items from the filesystem storage.
94
+ *
95
+ * @param keys Array of keys to delete from storage
96
+ * @returns Promise that resolves when the delete operation completes
97
+ *
98
+ * @throws ReferenceError if keys array is empty or undefined
99
+ *
100
+ * @remarks
101
+ * This method removes the specified keys from both the in-memory cache
102
+ * and writes the updated state to the state.json file. Keys that don't
103
+ * exist in storage are silently ignored.
104
+ */
8
105
  delete(keys: string[]): Promise<void>;
9
106
  }