@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,91 +2,114 @@
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
+ interface MemoryStorageState {
7
+ memory: {
8
+ [key: string]: string;
9
+ };
10
+ versions: {
11
+ [key: string]: string;
12
+ };
13
+ expirations: {
14
+ [key: string]: number;
15
+ };
16
+ etag: number;
17
+ }
18
+ declare class MemoryStorageInternals {
19
+ private static readonly states;
20
+ readonly state: MemoryStorageState;
21
+ /**
22
+ * Creates an internal in-memory provider for the selected storage contract.
23
+ */
24
+ constructor(memory?: {
25
+ [key: string]: string;
26
+ });
27
+ save(key: string, item: unknown, expiresAt?: number): string;
28
+ getVersion(key: string, value: StoreItem): string | undefined;
29
+ isExpired(key: string): boolean;
30
+ remove(key: string): void;
31
+ }
6
32
  /**
7
- * A simple in-memory storage provider that implements the Storage interface.
33
+ * A simple in-memory storage provider for development and testing.
8
34
  *
9
- * @remarks
10
- * This class provides a volatile storage solution that keeps data in memory,
11
- * which means data is lost when the process terminates. It's primarily useful for:
12
- * - Development and testing scenarios
13
- * - Simple applications that don't require data persistence across restarts
14
- * - Stateless environments where external storage isn't available
15
- *
16
- * MemoryStorage supports optimistic concurrency control through eTags and
17
- * can be used as a singleton through the {@link MemoryStorage.getSingleInstance | getSingleInstance() method} to
18
- * share state across different parts of an application.
35
+ * This class implements the legacy {@link Storage} contract. Use
36
+ * {@link MemoryStorageV2} for the structured StorageV2 contract.
19
37
  */
20
- export declare class MemoryStorage implements Storage {
21
- private memory;
38
+ export declare class MemoryStorage extends MemoryStorageInternals implements Storage {
22
39
  private static instance;
23
- private expirations;
40
+ constructor(memory?: {
41
+ [key: string]: string;
42
+ });
24
43
  /**
25
- * Counter used to generate unique eTags for stored items
44
+ * Reads legacy items from process-local memory.
45
+ *
46
+ * @param keys The keys to read; must not be empty.
47
+ * @returns Existing items keyed by storage key. Missing keys are omitted and returned items
48
+ * include their legacy `eTag`.
26
49
  */
27
- private etag;
50
+ read(keys: string[]): Promise<StoreItem>;
28
51
  /**
29
- * Creates a new instance of the MemoryStorage class.
52
+ * Writes legacy items to process-local memory.
30
53
  *
31
- * @param memory An optional initial memory store to seed the storage with data
54
+ * @param changes The items to write, keyed by storage key.
55
+ * @throws If `changes` is invalid or an item supplies a stale legacy `eTag`.
32
56
  */
33
- constructor(memory?: {
34
- [k: string]: string;
35
- });
57
+ write(changes: StoreItem): Promise<void>;
36
58
  /**
37
- * Gets a single shared instance of the MemoryStorage class.
38
- *
39
- * @returns The singleton instance of MemoryStorage
40
- *
41
- * @remarks
42
- * Using this method ensures that the same storage instance is used across
43
- * the application, allowing for shared state without passing references.
59
+ * Deletes legacy items from process-local memory.
44
60
  *
61
+ * @param keys The keys to delete. Missing keys are ignored.
45
62
  */
63
+ delete(keys: string[]): Promise<void>;
46
64
  static getSingleInstance(): MemoryStorage;
65
+ }
66
+ /**
67
+ * An in-memory provider for the structured {@link StorageV2} contract.
68
+ *
69
+ * Unlike {@link MemoryStorage}, every read returns an outcome for every requested key, and every
70
+ * write and delete returns an outcome for every supplied key. Storage versions are returned
71
+ * separately from application values, so an `eTag` property in a value is preserved. Use
72
+ * {@link StorageWriteMode.CreateOnly}, {@link StorageWriteMode.Replace}, or `expectedVersion` to
73
+ * guard concurrent writes.
74
+ *
75
+ * This provider is intended for development and testing only; state is process-local.
76
+ */
77
+ export declare class MemoryStorageV2 extends StorageV2 {
78
+ private static instance;
79
+ private readonly internals;
47
80
  /**
48
- * Reads storage items from memory.
81
+ * Creates a V2 in-memory storage provider.
49
82
  *
50
- * @param keys The keys of the items to read
51
- * @returns A promise that resolves to the read items
52
- * @throws Will throw an error if keys are not provided or the array is empty
83
+ * @param memory Optional backing store to share with another in-memory storage instance.
53
84
  */
54
- read(keys: string[]): Promise<StoreItem>;
85
+ constructor(memory?: {
86
+ [key: string]: string;
87
+ });
55
88
  /**
56
- * Writes storage items to memory.
57
- *
58
- * @param changes The items to write, indexed by key
59
- * @returns A promise that resolves when the write operation is complete
60
- * @throws Will throw an error if changes are not provided or if there's an eTag conflict
89
+ * Reads items from process-local memory.
61
90
  *
62
- * @remarks
63
- * This method supports optimistic concurrency control through eTags.
64
- * If an item has an eTag, it will only be updated if the existing item
65
- * has the same eTag. If an item has an eTag of '*' or no eTag, it will
66
- * always be written regardless of the current state.
91
+ * @param keys The keys to read. Empty batches are valid.
92
+ * @returns A result for every key, with `notFound` for missing items and a separate storage
93
+ * version for successful reads.
67
94
  */
68
- write(changes: StoreItem, options?: StorageWriteOptions): Promise<void>;
95
+ read<T extends object = Record<string, unknown>>(keys: string[]): Promise<StorageReadResults<T>>;
69
96
  /**
70
- * Deletes storage items from memory.
97
+ * Writes items to process-local memory with optional concurrency conditions.
71
98
  *
72
- * @param keys The keys of the items to delete
73
- * @returns A promise that resolves when the delete operation is complete
99
+ * @param changes The values to write, keyed by storage key.
100
+ * @param options Create-only, replace, or expected-version conditions.
101
+ * @returns A result for every supplied key, including `conflict` or `conditionNotMet` when a
102
+ * condition cannot be satisfied.
74
103
  */
75
- delete(keys: string[]): Promise<void>;
104
+ write<T extends object = Record<string, unknown>>(changes: Record<string, T>, options?: StorageWriteOptions): Promise<StorageWriteResults>;
76
105
  /**
77
- * Saves an item to memory with a new eTag.
78
- *
79
- * @param key The key of the item to save
80
- * @param item The item to save
81
- *
82
- * @remarks
83
- * This private method handles the details of:
84
- * - Creating a clone of the item to prevent modification of the original
85
- * - Generating a new eTag for optimistic concurrency control
86
- * - Converting the item to a JSON string for storage
106
+ * Deletes items from process-local memory with an optional version condition.
87
107
  *
88
- * @private
108
+ * @param keys The keys to delete. Empty batches are valid.
109
+ * @param options An optional expected storage version.
110
+ * @returns A result for every supplied key.
89
111
  */
90
- private saveItem;
91
- private isExpired;
112
+ delete(keys: string[], options?: StorageDeleteOptions): Promise<StorageDeleteResults>;
113
+ static getSingleInstance(): MemoryStorageV2;
92
114
  }
115
+ export {};
@@ -4,176 +4,307 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.MemoryStorage = void 0;
8
- const agents_telemetry_1 = require("@microsoft/agents-telemetry");
7
+ exports.MemoryStorageV2 = exports.MemoryStorage = void 0;
9
8
  const agents_activity_1 = require("@microsoft/agents-activity");
9
+ const agents_telemetry_1 = require("@microsoft/agents-telemetry");
10
+ const errorHelper_1 = require("../errorHelper");
10
11
  const observability_1 = require("../observability");
11
12
  const storageExpiry_1 = require("./storageExpiry");
12
- const agents_telemetry_2 = require("@microsoft/agents-telemetry");
13
- const errorHelper_1 = require("../errorHelper");
14
- const logger = (0, agents_telemetry_2.debug)('agents:memory-storage');
13
+ const storage_1 = require("./storage");
14
+ const logger = (0, agents_telemetry_1.debug)('agents:memory-storage');
15
+ class MemoryStorageInternals {
16
+ /**
17
+ * Creates an internal in-memory provider for the selected storage contract.
18
+ */
19
+ constructor(memory = {}) {
20
+ let state = MemoryStorageInternals.states.get(memory);
21
+ if (!state) {
22
+ state = { memory, versions: {}, expirations: {}, etag: getNextETag(memory) };
23
+ MemoryStorageInternals.states.set(memory, state);
24
+ }
25
+ this.state = state;
26
+ }
27
+ save(key, item, expiresAt) {
28
+ const version = (this.state.etag++).toString();
29
+ this.state.memory[key] = JSON.stringify(item);
30
+ this.state.versions[key] = version;
31
+ if (expiresAt === undefined)
32
+ delete this.state.expirations[key];
33
+ else
34
+ this.state.expirations[key] = expiresAt;
35
+ return version;
36
+ }
37
+ getVersion(key, value) {
38
+ var _a;
39
+ return (_a = this.state.versions[key]) !== null && _a !== void 0 ? _a : value.eTag;
40
+ }
41
+ isExpired(key) {
42
+ const expiresAt = this.state.expirations[key];
43
+ return expiresAt !== undefined && expiresAt <= Date.now();
44
+ }
45
+ remove(key) {
46
+ delete this.state.memory[key];
47
+ delete this.state.versions[key];
48
+ delete this.state.expirations[key];
49
+ }
50
+ }
51
+ MemoryStorageInternals.states = new WeakMap();
15
52
  /**
16
- * A simple in-memory storage provider that implements the Storage interface.
53
+ * A simple in-memory storage provider for development and testing.
17
54
  *
18
- * @remarks
19
- * This class provides a volatile storage solution that keeps data in memory,
20
- * which means data is lost when the process terminates. It's primarily useful for:
21
- * - Development and testing scenarios
22
- * - Simple applications that don't require data persistence across restarts
23
- * - Stateless environments where external storage isn't available
24
- *
25
- * MemoryStorage supports optimistic concurrency control through eTags and
26
- * can be used as a singleton through the {@link MemoryStorage.getSingleInstance | getSingleInstance() method} to
27
- * share state across different parts of an application.
55
+ * This class implements the legacy {@link Storage} contract. Use
56
+ * {@link MemoryStorageV2} for the structured StorageV2 contract.
28
57
  */
29
- class MemoryStorage {
58
+ class MemoryStorage extends MemoryStorageInternals {
59
+ constructor(memory = {}) {
60
+ super(memory);
61
+ }
30
62
  /**
31
- * Creates a new instance of the MemoryStorage class.
63
+ * Reads legacy items from process-local memory.
32
64
  *
33
- * @param memory An optional initial memory store to seed the storage with data
65
+ * @param keys The keys to read; must not be empty.
66
+ * @returns Existing items keyed by storage key. Missing keys are omitted and returned items
67
+ * include their legacy `eTag`.
34
68
  */
35
- constructor(memory = {}) {
36
- this.memory = memory;
37
- this.expirations = {};
38
- /**
39
- * Counter used to generate unique eTags for stored items
40
- */
41
- this.etag = 1;
69
+ async read(keys) {
70
+ return (0, agents_telemetry_1.trace)(observability_1.StorageTraceDefinitions.read, async ({ record }) => {
71
+ record({ keyCount: keys === null || keys === void 0 ? void 0 : keys.length });
72
+ if (!keys || keys.length === 0) {
73
+ throw agents_activity_1.ExceptionHelper.generateException(ReferenceError, errorHelper_1.Errors.StorageReadKeysRequired);
74
+ }
75
+ const data = {};
76
+ for (const key of keys) {
77
+ logger.debug(`Reading key: ${key}`);
78
+ const item = this.state.memory[key];
79
+ if (item) {
80
+ const value = JSON.parse(item);
81
+ const version = this.getVersion(key, value);
82
+ data[key] = version === undefined ? value : { ...value, eTag: version };
83
+ }
84
+ }
85
+ return data;
86
+ });
42
87
  }
43
88
  /**
44
- * Gets a single shared instance of the MemoryStorage class.
45
- *
46
- * @returns The singleton instance of MemoryStorage
89
+ * Writes legacy items to process-local memory.
47
90
  *
48
- * @remarks
49
- * Using this method ensures that the same storage instance is used across
50
- * the application, allowing for shared state without passing references.
91
+ * @param changes The items to write, keyed by storage key.
92
+ * @throws If `changes` is invalid or an item supplies a stale legacy `eTag`.
93
+ */
94
+ async write(changes) {
95
+ return (0, agents_telemetry_1.trace)(observability_1.StorageTraceDefinitions.write, async ({ record }) => {
96
+ record({ keyCount: changes ? Object.keys(changes).length : undefined });
97
+ if (!changes || typeof changes !== 'object' || Array.isArray(changes)) {
98
+ throw agents_activity_1.ExceptionHelper.generateException(ReferenceError, errorHelper_1.Errors.StorageWriteChangesRequired);
99
+ }
100
+ for (const [key, newItem] of Object.entries(changes)) {
101
+ logger.debug(`Writing key: ${key}`);
102
+ const oldItemStr = this.state.memory[key];
103
+ if (!oldItemStr || newItem.eTag === '*' || !newItem.eTag) {
104
+ const { eTag: _eTag, ...value } = newItem;
105
+ this.save(key, { ...value, eTag: (this.state.etag).toString() });
106
+ continue;
107
+ }
108
+ const oldItem = JSON.parse(oldItemStr);
109
+ if (newItem.eTag === this.getVersion(key, oldItem)) {
110
+ const { eTag: _eTag, ...value } = newItem;
111
+ this.save(key, { ...value, eTag: (this.state.etag).toString() });
112
+ }
113
+ else {
114
+ throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.StorageETagConflict, undefined, { key });
115
+ }
116
+ }
117
+ });
118
+ }
119
+ /**
120
+ * Deletes legacy items from process-local memory.
51
121
  *
122
+ * @param keys The keys to delete. Missing keys are ignored.
52
123
  */
124
+ async delete(keys) {
125
+ return (0, agents_telemetry_1.trace)(observability_1.StorageTraceDefinitions.delete, async ({ record }) => {
126
+ record({ keyCount: keys === null || keys === void 0 ? void 0 : keys.length });
127
+ logger.debug(`Deleting keys: ${keys.join(', ')}`);
128
+ for (const key of keys) {
129
+ this.remove(key);
130
+ }
131
+ });
132
+ }
53
133
  static getSingleInstance() {
54
- if (!MemoryStorage.instance) {
134
+ if (!MemoryStorage.instance)
55
135
  MemoryStorage.instance = new MemoryStorage();
56
- }
57
136
  return MemoryStorage.instance;
58
137
  }
138
+ }
139
+ exports.MemoryStorage = MemoryStorage;
140
+ /**
141
+ * An in-memory provider for the structured {@link StorageV2} contract.
142
+ *
143
+ * Unlike {@link MemoryStorage}, every read returns an outcome for every requested key, and every
144
+ * write and delete returns an outcome for every supplied key. Storage versions are returned
145
+ * separately from application values, so an `eTag` property in a value is preserved. Use
146
+ * {@link StorageWriteMode.CreateOnly}, {@link StorageWriteMode.Replace}, or `expectedVersion` to
147
+ * guard concurrent writes.
148
+ *
149
+ * This provider is intended for development and testing only; state is process-local.
150
+ */
151
+ class MemoryStorageV2 extends storage_1.StorageV2 {
152
+ /**
153
+ * Creates a V2 in-memory storage provider.
154
+ *
155
+ * @param memory Optional backing store to share with another in-memory storage instance.
156
+ */
157
+ constructor(memory = {}) {
158
+ super();
159
+ this.internals = new MemoryStorageInternals(memory);
160
+ }
59
161
  /**
60
- * Reads storage items from memory.
162
+ * Reads items from process-local memory.
61
163
  *
62
- * @param keys The keys of the items to read
63
- * @returns A promise that resolves to the read items
64
- * @throws Will throw an error if keys are not provided or the array is empty
164
+ * @param keys The keys to read. Empty batches are valid.
165
+ * @returns A result for every key, with `notFound` for missing items and a separate storage
166
+ * version for successful reads.
65
167
  */
66
168
  async read(keys) {
67
169
  return (0, agents_telemetry_1.trace)(observability_1.StorageTraceDefinitions.read, async ({ record }) => {
68
170
  record({ keyCount: keys === null || keys === void 0 ? void 0 : keys.length });
69
- if (!keys || keys.length === 0) {
171
+ if (!Array.isArray(keys)) {
70
172
  throw agents_activity_1.ExceptionHelper.generateException(ReferenceError, errorHelper_1.Errors.StorageReadKeysRequired);
71
173
  }
72
- const data = {};
174
+ if (keys.some(key => typeof key !== 'string' || key.trim() === '')) {
175
+ throw agents_activity_1.ExceptionHelper.generateException(ReferenceError, errorHelper_1.Errors.StorageV2KeyRequired);
176
+ }
177
+ const results = {};
73
178
  for (const key of keys) {
74
179
  logger.debug(`Reading key: ${key}`);
75
- if (this.isExpired(key)) {
180
+ if (this.internals.isExpired(key)) {
76
181
  logger.info('Item expired, deleting from memory', { key: (0, agents_telemetry_1.redactString)(key, true) });
77
- delete this.memory[key];
78
- delete this.expirations[key];
79
- continue;
182
+ this.internals.remove(key);
80
183
  }
81
- const item = this.memory[key];
82
- if (item) {
83
- data[key] = JSON.parse(item);
184
+ const item = this.internals.state.memory[key];
185
+ if (!item) {
186
+ results[key] = { key, status: storage_1.StorageOperationStatus.NotFound };
187
+ continue;
84
188
  }
189
+ const value = JSON.parse(item);
190
+ results[key] = { key, status: storage_1.StorageOperationStatus.Succeeded, value, version: this.internals.getVersion(key, value) };
85
191
  }
86
- return data;
192
+ return results;
87
193
  });
88
194
  }
89
195
  /**
90
- * Writes storage items to memory.
91
- *
92
- * @param changes The items to write, indexed by key
93
- * @returns A promise that resolves when the write operation is complete
94
- * @throws Will throw an error if changes are not provided or if there's an eTag conflict
196
+ * Writes items to process-local memory with optional concurrency conditions.
95
197
  *
96
- * @remarks
97
- * This method supports optimistic concurrency control through eTags.
98
- * If an item has an eTag, it will only be updated if the existing item
99
- * has the same eTag. If an item has an eTag of '*' or no eTag, it will
100
- * always be written regardless of the current state.
198
+ * @param changes The values to write, keyed by storage key.
199
+ * @param options Create-only, replace, or expected-version conditions.
200
+ * @returns A result for every supplied key, including `conflict` or `conditionNotMet` when a
201
+ * condition cannot be satisfied.
101
202
  */
102
203
  async write(changes, options) {
103
204
  return (0, agents_telemetry_1.trace)(observability_1.StorageTraceDefinitions.write, async ({ record }) => {
104
- const keys = changes ? Object.keys(changes) : [];
105
- if (!changes || keys.length === 0) {
205
+ var _a;
206
+ record({ keyCount: changes ? Object.keys(changes).length : undefined });
207
+ if ((options === null || options === void 0 ? void 0 : options.expectedVersion) === '') {
208
+ throw agents_activity_1.ExceptionHelper.generateException(RangeError, errorHelper_1.Errors.StorageV2ExpectedVersionEmpty);
209
+ }
210
+ if (!changes || typeof changes !== 'object' || Array.isArray(changes)) {
106
211
  throw agents_activity_1.ExceptionHelper.generateException(ReferenceError, errorHelper_1.Errors.StorageWriteChangesRequired);
107
212
  }
213
+ if (Object.values(changes).some(value => value === null || typeof value !== 'object' || Array.isArray(value))) {
214
+ throw agents_activity_1.ExceptionHelper.generateException(TypeError, errorHelper_1.Errors.StorageV2ValueRequired);
215
+ }
216
+ if (Object.keys(changes).some(key => key.trim() === '')) {
217
+ throw agents_activity_1.ExceptionHelper.generateException(ReferenceError, errorHelper_1.Errors.StorageV2KeyRequired);
218
+ }
219
+ const results = {};
108
220
  const expiresAt = (0, storageExpiry_1.getStorageWriteExpiry)(options);
109
- record({ keyCount: keys.length });
221
+ const mode = (_a = options === null || options === void 0 ? void 0 : options.mode) !== null && _a !== void 0 ? _a : storage_1.StorageWriteMode.Upsert;
222
+ if (!Object.values(storage_1.StorageWriteMode).includes(mode)) {
223
+ throw agents_activity_1.ExceptionHelper.generateException(RangeError, errorHelper_1.Errors.StorageV2WriteModeUnsupported, undefined, { mode: String(mode) });
224
+ }
110
225
  for (const [key, newItem] of Object.entries(changes)) {
111
- logger.debug(`Writing key: ${key}`);
112
- if (this.isExpired(key)) {
226
+ if (this.internals.isExpired(key)) {
113
227
  logger.info('Item expired, deleting from memory', { key: (0, agents_telemetry_1.redactString)(key, true) });
114
- delete this.memory[key];
115
- delete this.expirations[key];
228
+ this.internals.remove(key);
116
229
  }
117
- const oldItemStr = this.memory[key];
118
- if (!oldItemStr || newItem.eTag === '*' || !newItem.eTag) {
119
- this.saveItem(key, newItem, expiresAt);
230
+ const oldItemStr = this.internals.state.memory[key];
231
+ const oldItem = oldItemStr ? JSON.parse(oldItemStr) : undefined;
232
+ const currentVersion = oldItem ? this.internals.getVersion(key, oldItem) : undefined;
233
+ if (mode === storage_1.StorageWriteMode.CreateOnly && oldItemStr) {
234
+ results[key] = { key, status: storage_1.StorageOperationStatus.Conflict, version: currentVersion };
235
+ }
236
+ else if (mode === storage_1.StorageWriteMode.Replace && !oldItemStr) {
237
+ results[key] = { key, status: storage_1.StorageOperationStatus.NotFound };
238
+ }
239
+ else if ((options === null || options === void 0 ? void 0 : options.expectedVersion) !== undefined && options.expectedVersion !== currentVersion) {
240
+ results[key] = { key, status: storage_1.StorageOperationStatus.ConditionNotMet, version: currentVersion };
120
241
  }
121
242
  else {
122
- const oldItem = JSON.parse(oldItemStr);
123
- if (newItem.eTag === oldItem.eTag) {
124
- this.saveItem(key, newItem, expiresAt);
125
- }
126
- else {
127
- throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.StorageETagConflict, undefined, { key });
128
- }
243
+ results[key] = { key, status: storage_1.StorageOperationStatus.Succeeded, version: this.internals.save(key, newItem, expiresAt) };
129
244
  }
130
245
  }
246
+ return results;
131
247
  });
132
248
  }
133
249
  /**
134
- * Deletes storage items from memory.
250
+ * Deletes items from process-local memory with an optional version condition.
135
251
  *
136
- * @param keys The keys of the items to delete
137
- * @returns A promise that resolves when the delete operation is complete
252
+ * @param keys The keys to delete. Empty batches are valid.
253
+ * @param options An optional expected storage version.
254
+ * @returns A result for every supplied key.
138
255
  */
139
- async delete(keys) {
256
+ async delete(keys, options) {
140
257
  return (0, agents_telemetry_1.trace)(observability_1.StorageTraceDefinitions.delete, async ({ record }) => {
141
258
  record({ keyCount: keys === null || keys === void 0 ? void 0 : keys.length });
142
- logger.debug(`Deleting keys: ${keys.join(', ')}`);
259
+ if ((options === null || options === void 0 ? void 0 : options.expectedVersion) === '') {
260
+ throw agents_activity_1.ExceptionHelper.generateException(RangeError, errorHelper_1.Errors.StorageV2ExpectedVersionEmpty);
261
+ }
262
+ if (!Array.isArray(keys)) {
263
+ throw agents_activity_1.ExceptionHelper.generateException(ReferenceError, errorHelper_1.Errors.StorageReadKeysRequired);
264
+ }
265
+ if (keys.some(key => typeof key !== 'string' || key.trim() === '')) {
266
+ throw agents_activity_1.ExceptionHelper.generateException(ReferenceError, errorHelper_1.Errors.StorageV2KeyRequired);
267
+ }
268
+ const results = {};
143
269
  for (const key of keys) {
144
- delete this.memory[key];
145
- delete this.expirations[key];
270
+ if (this.internals.isExpired(key)) {
271
+ logger.info('Item expired, deleting from memory', { key: (0, agents_telemetry_1.redactString)(key, true) });
272
+ this.internals.remove(key);
273
+ }
274
+ const item = this.internals.state.memory[key];
275
+ if (!item) {
276
+ results[key] = { key, status: storage_1.StorageOperationStatus.NotFound };
277
+ continue;
278
+ }
279
+ const value = JSON.parse(item);
280
+ const version = this.internals.getVersion(key, value);
281
+ if ((options === null || options === void 0 ? void 0 : options.expectedVersion) !== undefined && options.expectedVersion !== version) {
282
+ results[key] = { key, status: storage_1.StorageOperationStatus.ConditionNotMet, version };
283
+ continue;
284
+ }
285
+ this.internals.remove(key);
286
+ results[key] = { key, status: storage_1.StorageOperationStatus.Succeeded, version };
146
287
  }
288
+ return results;
147
289
  });
148
290
  }
149
- /**
150
- * Saves an item to memory with a new eTag.
151
- *
152
- * @param key The key of the item to save
153
- * @param item The item to save
154
- *
155
- * @remarks
156
- * This private method handles the details of:
157
- * - Creating a clone of the item to prevent modification of the original
158
- * - Generating a new eTag for optimistic concurrency control
159
- * - Converting the item to a JSON string for storage
160
- *
161
- * @private
162
- */
163
- saveItem(key, item, expiresAt) {
164
- const clone = Object.assign({}, item, { eTag: (this.etag++).toString() });
165
- this.memory[key] = JSON.stringify(clone);
166
- if (expiresAt === undefined) {
167
- delete this.expirations[key];
291
+ static getSingleInstance() {
292
+ if (!MemoryStorageV2.instance)
293
+ MemoryStorageV2.instance = new MemoryStorageV2();
294
+ return MemoryStorageV2.instance;
295
+ }
296
+ }
297
+ exports.MemoryStorageV2 = MemoryStorageV2;
298
+ function getNextETag(memory) {
299
+ return Object.values(memory).reduce((next, item) => {
300
+ var _a;
301
+ try {
302
+ const version = Number((_a = JSON.parse(item)) === null || _a === void 0 ? void 0 : _a.eTag);
303
+ return Number.isSafeInteger(version) && version >= next ? version + 1 : next;
168
304
  }
169
- else {
170
- this.expirations[key] = expiresAt;
305
+ catch {
306
+ return next;
171
307
  }
172
- }
173
- isExpired(key) {
174
- const expiresAt = this.expirations[key];
175
- return expiresAt !== undefined && expiresAt <= Date.now();
176
- }
308
+ }, 1);
177
309
  }
178
- exports.MemoryStorage = MemoryStorage;
179
310
  //# sourceMappingURL=memoryStorage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"memoryStorage.js","sourceRoot":"","sources":["../../../src/storage/memoryStorage.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAiE;AACjE,gEAA4D;AAC5D,oDAA0D;AAE1D,mDAAuD;AACvD,kEAAmD;AACnD,gDAAuC;AAEvC,MAAM,MAAM,GAAG,IAAA,wBAAK,EAAC,uBAAuB,CAAC,CAAA;AAE7C;;;;;;;;;;;;;GAaG;AACH;IAQE;;;;OAIG;IACH,YAAqB,MAAM,GAA4B,EAAE;QAApC,WAAM,GAAN,MAAM,CAA8B;QAXjD,gBAAW,GAA4B,EAAE,CAAA;QACjD;;WAEG;QACK,SAAI,GAAW,CAAC,CAAA;IAOqC,CAAC;IAE9D;;;;;;;;;OASG;IACH,MAAM,CAAC,iBAAiB;QACtB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC5B,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAA;QAC9C,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAA;IAC/B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,CAAE,IAAc;QACxB,OAAO,IAAA,wBAAK,EAAC,uCAAuB,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YAC9D,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,EAAE,CAAC,CAAA;YAClC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC/B,MAAM,iCAAe,CAAC,iBAAiB,CAAC,cAAc,EAAE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