@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.
- package/README.md +18 -10
- package/dist/package.json +3 -3
- package/dist/src/app/agentApplication.d.ts +1 -0
- package/dist/src/app/agentApplication.js +18 -5
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationBuilder.d.ts +9 -2
- package/dist/src/app/agentApplicationBuilder.js +9 -0
- package/dist/src/app/agentApplicationBuilder.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +10 -4
- package/dist/src/app/auth/handlerStorage.d.ts +5 -3
- package/dist/src/app/auth/handlerStorage.js +36 -10
- package/dist/src/app/auth/handlerStorage.js.map +1 -1
- package/dist/src/app/auth/types.d.ts +2 -2
- package/dist/src/app/index.d.ts +1 -0
- package/dist/src/app/proactive/proactive.js +10 -6
- package/dist/src/app/proactive/proactive.js.map +1 -1
- package/dist/src/app/proactive/proactiveOptions.d.ts +2 -2
- package/dist/src/app/rateLimit.d.ts +315 -0
- package/dist/src/app/rateLimit.js +333 -0
- package/dist/src/app/rateLimit.js.map +1 -0
- package/dist/src/app/turnState.d.ts +6 -3
- package/dist/src/app/turnState.js +43 -4
- package/dist/src/app/turnState.js.map +1 -1
- package/dist/src/errorHelper.js +40 -9
- package/dist/src/errorHelper.js.map +1 -1
- package/dist/src/observability/traces.d.ts +6 -4
- package/dist/src/observability/traces.js +10 -9
- package/dist/src/observability/traces.js.map +1 -1
- package/dist/src/state/agentState.d.ts +8 -3
- package/dist/src/state/agentState.js +26 -8
- package/dist/src/state/agentState.js.map +1 -1
- package/dist/src/state/conversationState.d.ts +2 -2
- package/dist/src/state/conversationState.js.map +1 -1
- package/dist/src/state/userState.d.ts +2 -2
- package/dist/src/state/userState.js.map +1 -1
- package/dist/src/statusCodes.d.ts +5 -0
- package/dist/src/statusCodes.js +5 -0
- package/dist/src/statusCodes.js.map +1 -1
- package/dist/src/storage/fileStorage.d.ts +83 -71
- package/dist/src/storage/fileStorage.js +272 -136
- package/dist/src/storage/fileStorage.js.map +1 -1
- package/dist/src/storage/memoryStorage.d.ts +85 -62
- package/dist/src/storage/memoryStorage.js +240 -109
- package/dist/src/storage/memoryStorage.js.map +1 -1
- package/dist/src/storage/storage.d.ts +101 -16
- package/dist/src/storage/storage.js +25 -0
- package/dist/src/storage/storage.js.map +1 -1
- package/dist/src/storage/storageCompatibility.d.ts +17 -0
- package/dist/src/storage/storageCompatibility.js +157 -0
- package/dist/src/storage/storageCompatibility.js.map +1 -0
- package/package.json +3 -3
- package/src/app/agentApplication.ts +16 -0
- package/src/app/agentApplicationBuilder.ts +13 -2
- package/src/app/agentApplicationOptions.ts +11 -4
- package/src/app/auth/handlerStorage.ts +51 -7
- package/src/app/auth/types.ts +2 -2
- package/src/app/index.ts +7 -0
- package/src/app/proactive/proactive.ts +19 -9
- package/src/app/proactive/proactiveOptions.ts +2 -2
- package/src/app/rateLimit.ts +659 -0
- package/src/app/turnState.ts +50 -7
- package/src/errorHelper.ts +46 -8
- package/src/observability/traces.ts +8 -7
- package/src/state/agentState.ts +39 -13
- package/src/state/conversationState.ts +2 -2
- package/src/state/userState.ts +2 -2
- package/src/statusCodes.ts +6 -0
- package/src/storage/fileStorage.ts +289 -134
- package/src/storage/memoryStorage.ts +266 -109
- package/src/storage/storage.ts +115 -17
- 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 {
|
|
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
|
|
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
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* wrapped in Promise interfaces
|
|
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,
|
|
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
|
|
46
|
+
* const legacyStorage = new FileStorage('./data')
|
|
47
|
+
* const storageV2 = new FileStorageV2('./data-v2')
|
|
31
48
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* 'conversation456': { turn: 5, context: 'discussing weather' }
|
|
36
|
-
* });
|
|
49
|
+
* await storageV2.write({
|
|
50
|
+
* user123: { name: 'John', lastSeen: new Date().toISOString() }
|
|
51
|
+
* })
|
|
37
52
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* console.log(data.user123); // { name: 'John', lastSeen: '...' }
|
|
53
|
+
* const result = await storageV2.read(['user123'])
|
|
54
|
+
* console.log(result.user123.value)
|
|
41
55
|
*
|
|
42
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
66
|
+
read(keys: string[]): Promise<StoreItem>;
|
|
65
67
|
/**
|
|
66
|
-
*
|
|
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
|
-
|
|
73
|
+
write(changes: StoreItem): Promise<void>;
|
|
79
74
|
/**
|
|
80
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
95
|
+
* Creates a V2 file storage provider.
|
|
98
96
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
|
|
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<
|
|
111
|
-
private isExpired;
|
|
112
|
-
private writeFiles;
|
|
123
|
+
delete(keys: string[], options?: StorageDeleteOptions): Promise<StorageDeleteResults>;
|
|
113
124
|
}
|
|
125
|
+
export {};
|