@microsoft/agents-hosting 1.9.0-beta.18.g6b8111bba5 → 1.9.0-beta.20.g0c48a31a21

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 (71) hide show
  1. package/README.md +18 -10
  2. package/dist/package.json +3 -3
  3. package/dist/src/app/agentApplication.d.ts +1 -0
  4. package/dist/src/app/agentApplication.js +18 -5
  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 +10 -4
  10. package/dist/src/app/auth/handlerStorage.d.ts +5 -3
  11. package/dist/src/app/auth/handlerStorage.js +36 -10
  12. package/dist/src/app/auth/handlerStorage.js.map +1 -1
  13. package/dist/src/app/auth/types.d.ts +2 -2
  14. package/dist/src/app/index.d.ts +1 -0
  15. package/dist/src/app/proactive/proactive.js +10 -6
  16. package/dist/src/app/proactive/proactive.js.map +1 -1
  17. package/dist/src/app/proactive/proactiveOptions.d.ts +2 -2
  18. package/dist/src/app/rateLimit.d.ts +315 -0
  19. package/dist/src/app/rateLimit.js +333 -0
  20. package/dist/src/app/rateLimit.js.map +1 -0
  21. package/dist/src/app/turnState.d.ts +6 -3
  22. package/dist/src/app/turnState.js +43 -4
  23. package/dist/src/app/turnState.js.map +1 -1
  24. package/dist/src/errorHelper.js +40 -9
  25. package/dist/src/errorHelper.js.map +1 -1
  26. package/dist/src/observability/traces.d.ts +6 -4
  27. package/dist/src/observability/traces.js +10 -9
  28. package/dist/src/observability/traces.js.map +1 -1
  29. package/dist/src/state/agentState.d.ts +8 -3
  30. package/dist/src/state/agentState.js +26 -8
  31. package/dist/src/state/agentState.js.map +1 -1
  32. package/dist/src/state/conversationState.d.ts +2 -2
  33. package/dist/src/state/conversationState.js.map +1 -1
  34. package/dist/src/state/userState.d.ts +2 -2
  35. package/dist/src/state/userState.js.map +1 -1
  36. package/dist/src/statusCodes.d.ts +5 -0
  37. package/dist/src/statusCodes.js +5 -0
  38. package/dist/src/statusCodes.js.map +1 -1
  39. package/dist/src/storage/fileStorage.d.ts +83 -71
  40. package/dist/src/storage/fileStorage.js +272 -136
  41. package/dist/src/storage/fileStorage.js.map +1 -1
  42. package/dist/src/storage/memoryStorage.d.ts +85 -62
  43. package/dist/src/storage/memoryStorage.js +240 -109
  44. package/dist/src/storage/memoryStorage.js.map +1 -1
  45. package/dist/src/storage/storage.d.ts +101 -16
  46. package/dist/src/storage/storage.js +25 -0
  47. package/dist/src/storage/storage.js.map +1 -1
  48. package/dist/src/storage/storageCompatibility.d.ts +17 -0
  49. package/dist/src/storage/storageCompatibility.js +157 -0
  50. package/dist/src/storage/storageCompatibility.js.map +1 -0
  51. package/package.json +3 -3
  52. package/src/app/agentApplication.ts +16 -0
  53. package/src/app/agentApplicationBuilder.ts +13 -2
  54. package/src/app/agentApplicationOptions.ts +11 -4
  55. package/src/app/auth/handlerStorage.ts +51 -7
  56. package/src/app/auth/types.ts +2 -2
  57. package/src/app/index.ts +7 -0
  58. package/src/app/proactive/proactive.ts +19 -9
  59. package/src/app/proactive/proactiveOptions.ts +2 -2
  60. package/src/app/rateLimit.ts +659 -0
  61. package/src/app/turnState.ts +50 -7
  62. package/src/errorHelper.ts +46 -8
  63. package/src/observability/traces.ts +8 -7
  64. package/src/state/agentState.ts +39 -13
  65. package/src/state/conversationState.ts +2 -2
  66. package/src/state/userState.ts +2 -2
  67. package/src/statusCodes.ts +6 -0
  68. package/src/storage/fileStorage.ts +289 -134
  69. package/src/storage/memoryStorage.ts +266 -109
  70. package/src/storage/storage.ts +115 -17
  71. package/src/storage/storageCompatibility.ts +185 -0
@@ -2,112 +2,124 @@
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { Storage, StoreItem, StorageWriteOptions } from './storage';
5
+ import { StorageDeleteOptions, StorageDeleteResults, StorageReadResults, StorageWriteOptions, StorageWriteResults, Storage, StorageV2, StoreItem } from './storage';
6
+ declare class FileStorageInternals {
7
+ private readonly statePath;
8
+ private readonly versionsPath;
9
+ private readonly expirationsPath;
10
+ readonly state: Record<string, unknown>;
11
+ readonly versions: Record<string, string>;
12
+ readonly expirations: Record<string, number>;
13
+ constructor(folder: string);
14
+ flush(): void;
15
+ getOrCreateVersion(key: string): string;
16
+ isExpired(key: string): boolean;
17
+ remove(key: string): void;
18
+ }
6
19
  /**
7
20
  * A file-based storage implementation that persists data to the local filesystem.
8
21
  *
9
22
  * @remarks
10
- * FileStorage stores all data in a single JSON file named 'state.json' within a specified folder.
23
+ * FileStorage stores all data in a single JSON file named `state.json` within a specified folder.
11
24
  * This implementation is suitable for development scenarios, local testing, and single-instance
12
25
  * deployments where shared state across multiple instances is not required.
13
26
  *
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.
27
+ * Values remain a key-value JSON object in `state.json`. V2 keeps generated storage versions in
28
+ * `state.versions.json` so a value's own `eTag` property is not changed. All operations use
29
+ * synchronous file I/O wrapped in Promise interfaces. Use {@link FileStorageV2} for the
30
+ * structured StorageV2 contract.
31
+ * V2 supports create-only, replace, and expected-version conditions.
32
+ *
33
+ * The inherited constructor creates the folder and `state.json` when needed, then loads values
34
+ * and V2 version metadata into memory. It creates `state.versions.json` on the first V2 write.
17
35
  *
18
36
  * ### Warning
19
37
  * This implementation does not provide:
20
38
  * - Thread safety for concurrent access
21
- * - Optimistic concurrency control (eTag support)
22
39
  * - Atomic operations across multiple keys
23
40
  * - Scale for large datasets
24
41
  *
25
- * For production scenarios requiring these features, consider using
26
- * database-backed storage implementations instead.
42
+ * For production scenarios requiring these features, use a database-backed storage implementation.
27
43
  *
28
44
  * @example
29
45
  * ```typescript
30
- * const storage = new FileStorage('./data');
46
+ * const legacyStorage = new FileStorage('./data')
47
+ * const storageV2 = new FileStorageV2('./data-v2')
31
48
  *
32
- * // Write some data
33
- * await storage.write({
34
- * 'user123': { name: 'John', lastSeen: new Date().toISOString() },
35
- * 'conversation456': { turn: 5, context: 'discussing weather' }
36
- * });
49
+ * await storageV2.write({
50
+ * user123: { name: 'John', lastSeen: new Date().toISOString() }
51
+ * })
37
52
  *
38
- * // Read specific keys
39
- * const data = await storage.read(['user123']);
40
- * console.log(data.user123); // { name: 'John', lastSeen: '...' }
53
+ * const result = await storageV2.read(['user123'])
54
+ * console.log(result.user123.value)
41
55
  *
42
- * // Delete data
43
- * await storage.delete(['conversation456']);
56
+ * await storageV2.delete(['user123'])
44
57
  * ```
45
- *
46
58
  */
47
- export declare class FileStorage implements Storage {
48
- private _folder;
49
- private _stateFile;
50
- private _metadataFile;
59
+ export declare class FileStorage extends FileStorageInternals implements Storage {
51
60
  /**
52
- * Creates a new FileStorage instance that stores data in the specified folder.
53
- *
54
- * @param folder The absolute or relative path to the folder where the state.json file will be stored
55
- * @throws May throw filesystem errors if the folder cannot be created or accessed
56
- *
57
- * @remarks
58
- * The constructor performs the following initialization steps:
59
- * 1. Creates the target folder if it doesn't exist (including parent directories)
60
- * 2. Creates an empty state.json file if it doesn't exist
61
- * 3. Loads existing data from state.json into memory for fast access
61
+ * Reads legacy items from `state.json`.
62
62
  *
63
+ * @param keys The keys to read; must not be empty.
64
+ * @returns Existing items keyed by storage key. Missing keys are omitted.
63
65
  */
64
- constructor(folder: string);
66
+ read(keys: string[]): Promise<StoreItem>;
65
67
  /**
66
- * Reads store items from the filesystem storage.
67
- *
68
- * @param keys Array of keys to read from storage
69
- * @returns Promise resolving to an object containing the requested items (keys that don't exist are omitted)
70
- * @throws ReferenceError if keys array is empty or undefined
71
- *
72
- * @remarks
73
- * This method reads from the in-memory cache that was loaded during construction,
74
- * making it very fast but potentially returning stale data if the file was
75
- * modified by external processes.
68
+ * Writes legacy items to `state.json`.
76
69
  *
70
+ * @param changes The items to write, keyed by storage key.
71
+ * @throws If `changes` is invalid or the file cannot be written.
77
72
  */
78
- read(keys: string[]): Promise<StoreItem>;
73
+ write(changes: StoreItem): Promise<void>;
79
74
  /**
80
- * Writes store items to the filesystem storage.
81
- *
82
- * @param changes Object containing key-value pairs to write to storage
83
- * @returns Promise that resolves when the write operation completes
84
- *
85
- * @remarks
86
- * This method updates both the in-memory cache and writes the entire state
87
- * to the state.json file. The file is written with pretty-printing (2-space indentation)
88
- * for better readability during development and debugging.
89
- *
90
- * > [!NOTE]
91
- * > This implementation does not support eTag-based optimistic concurrency control.
92
- * > Any eTag values in the changes object are ignored.
75
+ * Deletes legacy items from `state.json`.
93
76
  *
77
+ * @param keys The keys to delete; must not be empty. Missing keys are ignored.
94
78
  */
95
- write(changes: StoreItem, options?: StorageWriteOptions): Promise<void>;
79
+ delete(keys: string[]): Promise<void>;
80
+ }
81
+ /**
82
+ * A file-backed provider for the structured {@link StorageV2} contract.
83
+ *
84
+ * This is the V2 counterpart to {@link FileStorage}. Values are stored in `state.json`, while
85
+ * generated storage versions are stored separately in `state.versions.json`; an `eTag` property
86
+ * in an application value is therefore preserved. Reads and mutations return a result for every
87
+ * requested key and support create-only, replace, and expected-version conditions.
88
+ *
89
+ * Like {@link FileStorage}, this provider is for development, local testing, and single-instance
90
+ * deployments. It does not provide cross-process concurrency or multi-key atomicity.
91
+ */
92
+ export declare class FileStorageV2 extends StorageV2 {
93
+ private readonly internals;
96
94
  /**
97
- * Deletes store items from the filesystem storage.
95
+ * Creates a V2 file storage provider.
98
96
  *
99
- * @param keys Array of keys to delete from storage
100
- * @returns Promise that resolves when the delete operation completes
97
+ * @param folder The absolute or relative folder where `state.json` is stored.
98
+ * @throws May throw filesystem errors if the folder or state file cannot be created or read.
99
+ */
100
+ constructor(folder: string);
101
+ /**
102
+ * Reads items and their stored versions from the local state files.
101
103
  *
102
- * @throws ReferenceError if keys array is empty or undefined
104
+ * @param keys The keys to read. Empty batches are valid.
105
+ * @returns A result for every key, with `notFound` for missing items. Returned values are cloned.
106
+ */
107
+ read<T extends object = Record<string, unknown>>(keys: string[]): Promise<StorageReadResults<T>>;
108
+ /**
109
+ * Writes cloned items and generated versions to the local state files.
103
110
  *
104
- * @remarks
105
- * This method removes the specified keys from both the in-memory cache
106
- * and writes the updated state to the state.json file. Keys that don't
107
- * exist in storage are silently ignored.
111
+ * @param changes The values to write, keyed by storage key.
112
+ * @param options Create-only, replace, or expected-version conditions.
113
+ * @returns A result for every supplied key, including concurrency-condition outcomes.
114
+ */
115
+ write<T extends object = Record<string, unknown>>(changes: Record<string, T>, options?: StorageWriteOptions): Promise<StorageWriteResults>;
116
+ /**
117
+ * Deletes items and their versions from the local state files.
108
118
  *
119
+ * @param keys The keys to delete. Empty batches are valid.
120
+ * @param options An optional expected storage version.
121
+ * @returns A result for every supplied key.
109
122
  */
110
- delete(keys: string[]): Promise<void>;
111
- private isExpired;
112
- private writeFiles;
123
+ delete(keys: string[], options?: StorageDeleteOptions): Promise<StorageDeleteResults>;
113
124
  }
125
+ export {};