@microsoft/agents-hosting 0.2.10-g3ac88ff25e → 0.2.14

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 (70) hide show
  1. package/dist/src/activityHandler.d.ts +304 -46
  2. package/dist/src/activityHandler.js +298 -45
  3. package/dist/src/activityHandler.js.map +1 -1
  4. package/dist/src/agent-client/agentClient.d.ts +50 -0
  5. package/dist/src/agent-client/agentClient.js +28 -0
  6. package/dist/src/agent-client/agentClient.js.map +1 -1
  7. package/dist/src/app/agentApplication.d.ts +256 -3
  8. package/dist/src/app/agentApplication.js +256 -0
  9. package/dist/src/app/agentApplication.js.map +1 -1
  10. package/dist/src/app/agentApplicationBuilder.d.ts +32 -0
  11. package/dist/src/app/agentApplicationBuilder.js +32 -0
  12. package/dist/src/app/agentApplicationBuilder.js.map +1 -1
  13. package/dist/src/app/appMemory.d.ts +34 -0
  14. package/dist/src/app/{memory.js → appMemory.js} +1 -1
  15. package/dist/src/app/appMemory.js.map +1 -0
  16. package/dist/src/app/index.d.ts +3 -0
  17. package/dist/src/app/index.js +3 -0
  18. package/dist/src/app/index.js.map +1 -1
  19. package/dist/src/app/turnEvents.d.ts +6 -0
  20. package/dist/src/app/turnState.d.ts +2 -2
  21. package/dist/src/app/turnStateEntry.d.ts +32 -0
  22. package/dist/src/app/turnStateEntry.js +32 -0
  23. package/dist/src/app/turnStateEntry.js.map +1 -1
  24. package/dist/src/cards/index.d.ts +1 -0
  25. package/dist/src/cards/index.js +1 -0
  26. package/dist/src/cards/index.js.map +1 -1
  27. package/dist/src/cloudAdapter.d.ts +25 -3
  28. package/dist/src/cloudAdapter.js +25 -3
  29. package/dist/src/cloudAdapter.js.map +1 -1
  30. package/dist/src/getProductInfo.d.ts +6 -0
  31. package/dist/src/getProductInfo.js +6 -0
  32. package/dist/src/getProductInfo.js.map +1 -1
  33. package/dist/src/logger.d.ts +34 -2
  34. package/dist/src/logger.js +35 -0
  35. package/dist/src/logger.js.map +1 -1
  36. package/dist/src/state/agentState.d.ts +79 -27
  37. package/dist/src/state/agentState.js +58 -27
  38. package/dist/src/state/agentState.js.map +1 -1
  39. package/dist/src/state/agentStatePropertyAccesor.d.ts +67 -11
  40. package/dist/src/state/agentStatePropertyAccesor.js +58 -11
  41. package/dist/src/state/agentStatePropertyAccesor.js.map +1 -1
  42. package/dist/src/storage/memoryStorage.d.ts +48 -14
  43. package/dist/src/storage/memoryStorage.js +48 -14
  44. package/dist/src/storage/memoryStorage.js.map +1 -1
  45. package/dist/src/storage/storage.d.ts +43 -13
  46. package/dist/src/turnContext.d.ts +142 -56
  47. package/dist/src/turnContext.js +123 -53
  48. package/dist/src/turnContext.js.map +1 -1
  49. package/package.json +5 -5
  50. package/src/activityHandler.ts +304 -46
  51. package/src/agent-client/agentClient.ts +55 -5
  52. package/src/app/agentApplication.ts +259 -2
  53. package/src/app/agentApplicationBuilder.ts +32 -0
  54. package/src/app/appMemory.ts +38 -0
  55. package/src/app/index.ts +3 -0
  56. package/src/app/turnEvents.ts +6 -0
  57. package/src/app/turnState.ts +2 -2
  58. package/src/app/turnStateEntry.ts +32 -0
  59. package/src/cards/index.ts +1 -0
  60. package/src/cloudAdapter.ts +28 -3
  61. package/src/getProductInfo.ts +7 -0
  62. package/src/logger.ts +34 -1
  63. package/src/state/agentState.ts +81 -29
  64. package/src/state/agentStatePropertyAccesor.ts +67 -11
  65. package/src/storage/memoryStorage.ts +48 -14
  66. package/src/storage/storage.ts +51 -18
  67. package/src/turnContext.ts +142 -56
  68. package/dist/src/app/memory.d.ts +0 -10
  69. package/dist/src/app/memory.js.map +0 -1
  70. package/src/app/memory.ts +0 -14
@@ -3,9 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Logger = void 0;
6
7
  exports.debug = debug;
7
8
  const debug_1 = __importDefault(require("debug"));
9
+ /**
10
+ * Logger class that provides colored logging functionality using the debug package.
11
+ * Supports different log levels: info, warn, error, and debug.
12
+ */
8
13
  class Logger {
14
+ /**
15
+ * Creates a new Logger instance with the specified namespace.
16
+ * @param namespace The namespace to use for the logger
17
+ */
9
18
  constructor(namespace = '') {
10
19
  this.loggers = {};
11
20
  this.levelColors = {
@@ -23,19 +32,45 @@ class Logger {
23
32
  this.loggers[level] = logger;
24
33
  }
25
34
  }
35
+ /**
36
+ * Logs an informational message.
37
+ * @param message The message to log
38
+ * @param args Additional arguments to include in the log
39
+ */
26
40
  info(message, ...args) {
27
41
  this.loggers.info(message, ...args);
28
42
  }
43
+ /**
44
+ * Logs a warning message.
45
+ * @param message The message to log
46
+ * @param args Additional arguments to include in the log
47
+ */
29
48
  warn(message, ...args) {
30
49
  this.loggers.warn(message, ...args);
31
50
  }
51
+ /**
52
+ * Logs an error message.
53
+ * @param message The message to log
54
+ * @param args Additional arguments to include in the log
55
+ */
32
56
  error(message, ...args) {
33
57
  this.loggers.error(message, ...args);
34
58
  }
59
+ /**
60
+ * Logs a debug message.
61
+ * @param message The message to log
62
+ * @param args Additional arguments to include in the log
63
+ */
35
64
  debug(message, ...args) {
36
65
  this.loggers.debug(message, ...args);
37
66
  }
38
67
  }
68
+ exports.Logger = Logger;
69
+ /**
70
+ * Creates a new Logger instance with the specified namespace.
71
+ * @param namespace The namespace to use for the logger
72
+ * @returns A new Logger instance
73
+ */
39
74
  function debug(namespace) {
40
75
  return new Logger(namespace);
41
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":";;;;;AAwCA,sBAEC;AA1CD,kDAA6C;AAE7C,MAAM,MAAM;IASV,YAAa,YAAoB,EAAE;QAR3B,YAAO,GAAkC,EAAE,CAAA;QAClC,gBAAW,GAAgC;YAC1D,IAAI,EAAE,GAAG,EAAE,QAAQ;YACnB,IAAI,EAAE,GAAG,EAAE,SAAS;YACpB,KAAK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AO,EAAE,GAAG,IAAI,CAAC,CAAA;IACtC,CAAC;CACF;AA5DD,wBA4DC;AAED;;;;GAIG;AACH,SAAgB,KAAK,CAAE,SAAiB;IACtC,OAAO,IAAI,MAAM,CAAC,SAAS,CAAC,CAAA;AAC9B,CAAC"}
@@ -5,72 +5,124 @@
5
5
  import { Storage, StorageKeyFactory } from '../storage/storage';
6
6
  import { TurnContext } from '../turnContext';
7
7
  import { AgentStatePropertyAccessor } from './agentStatePropertyAccesor';
8
+ /**
9
+ * Represents agent state that has been cached in the turn context.
10
+ * Used internally to track state changes and avoid unnecessary storage operations.
11
+ */
8
12
  export interface CachedAgentState {
13
+ /**
14
+ * The state object containing all properties and their values
15
+ */
9
16
  state: {
10
17
  [id: string]: any;
11
18
  };
19
+ /**
20
+ * Hash of the state used to detect changes
21
+ */
12
22
  hash: string;
13
23
  }
24
+ /**
25
+ * Represents a custom key for storing state in a specific location.
26
+ * Allows state to be persisted with channel and conversation identifiers
27
+ * independent of the current context.
28
+ */
14
29
  export interface CustomKey {
30
+ /**
31
+ * The ID of the channel where the state should be stored
32
+ */
15
33
  channelId: string;
34
+ /**
35
+ * The ID of the conversation where the state should be stored
36
+ */
16
37
  conversationId: string;
17
38
  }
18
39
  /**
19
- * Manages the state of an Agent.
40
+ * Manages the state of an Agent across turns in a conversation.
41
+ *
42
+ * AgentState provides functionality to persist and retrieve state data using
43
+ * a storage provider. It handles caching state in the turn context for performance,
44
+ * calculating change hashes to detect modifications, and managing property accessors
45
+ * for typed access to state properties.
20
46
  */
21
47
  export declare class AgentState {
22
48
  protected storage: Storage;
23
49
  protected storageKey: StorageKeyFactory;
24
50
  private readonly stateKey;
25
51
  /**
26
- * Creates a new instance of AgentState.
27
- * @param storage The storage provider.
28
- * @param storageKey The storage key factory.
29
- */
52
+ * Creates a new instance of AgentState.
53
+ *
54
+ * @param storage The storage provider used to persist state between turns
55
+ * @param storageKey A factory function that generates keys for storing state data
56
+ */
30
57
  constructor(storage: Storage, storageKey: StorageKeyFactory);
31
58
  /**
32
59
  * Creates a property accessor for the specified property.
33
- * @param name The name of the property.
34
- * @returns A property accessor for the specified property.
60
+ * Property accessors provide typed access to properties within the state object.
61
+ *
62
+ * @param name The name of the property to access
63
+ * @returns A property accessor for the specified property
35
64
  */
36
65
  createProperty<T = any>(name: string): AgentStatePropertyAccessor<T>;
37
66
  /**
38
- * Loads the state from storage.
39
- * @param context The turn context.
40
- * @param force Whether to force loading the state.
41
- * @returns A promise that resolves to the loaded state.
67
+ * Loads the state from storage into the turn context.
68
+ * If state is already cached in the turn context and force is not set, the cached version will be used.
69
+ *
70
+ * @param context The turn context to load state into
71
+ * @param force If true, forces a reload from storage even if state is cached
72
+ * @param customKey Optional custom storage key to use instead of the default
73
+ * @returns A promise that resolves to the loaded state object
42
74
  */
43
75
  load(context: TurnContext, force?: boolean, customKey?: CustomKey): Promise<any>;
44
76
  /**
45
- * Saves the state to storage.
46
- * @param context The turn context.
47
- * @param force Whether to force saving the state.
48
- * @returns A promise that resolves when the save operation is complete.
77
+ * Saves the state to storage if it has changed since it was loaded.
78
+ * Change detection uses a hash of the state object to determine if saving is necessary.
79
+ *
80
+ * @param context The turn context containing the state to save
81
+ * @param force If true, forces a save to storage even if no changes are detected
82
+ * @param customKey Optional custom storage key to use instead of the default
83
+ * @returns A promise that resolves when the save operation is complete
49
84
  */
50
85
  saveChanges(context: TurnContext, force?: boolean, customKey?: CustomKey): Promise<void>;
86
+ /**
87
+ * Determines whether to use a custom key or generate one from the context.
88
+ *
89
+ * @param customKey Optional custom key with channel and conversation IDs
90
+ * @param context The turn context used to generate a key if no custom key is provided
91
+ * @returns The storage key to use
92
+ * @private
93
+ */
51
94
  private getStorageOrCustomKey;
52
95
  /**
53
- * Clears the state from the turn context.
54
- * @param context The turn context.
55
- * @returns A promise that resolves when the clear operation is complete.
96
+ * Clears the state by setting it to an empty object in the turn context.
97
+ * Note: This does not remove the state from storage, it only clears the in-memory representation.
98
+ * Call saveChanges() after this to persist the empty state to storage.
99
+ *
100
+ * @param context The turn context containing the state to clear
101
+ * @returns A promise that resolves when the clear operation is complete
56
102
  */
57
103
  clear(context: TurnContext): Promise<void>;
58
104
  /**
59
- * Deletes the state from storage.
60
- * @param context The turn context.
61
- * @returns A promise that resolves when the delete operation is complete.
105
+ * Deletes the state from both the turn context and storage.
106
+ *
107
+ * @param context The turn context containing the state to delete
108
+ * @param customKey Optional custom storage key to use instead of the default
109
+ * @returns A promise that resolves when the delete operation is complete
62
110
  */
63
111
  delete(context: TurnContext, customKey?: CustomKey): Promise<void>;
64
112
  /**
65
- * Gets the state from the turn context.
66
- * @param context The turn context.
67
- * @returns The state, or undefined if the state is not found.
113
+ * Gets the state from the turn context without loading it from storage.
114
+ *
115
+ * @param context The turn context containing the state to get
116
+ * @returns The state object, or undefined if no state is found in the turn context
68
117
  */
69
118
  get(context: TurnContext): any | undefined;
70
119
  /**
71
- * Calculates the change hash for the specified item.
72
- * @param item The item to calculate the hash for.
73
- * @returns The calculated hash.
120
+ * Calculates a hash for the specified state object to detect changes.
121
+ * The eTag property is excluded from the hash calculation.
122
+ *
123
+ * @param item The state object to calculate the hash for
124
+ * @returns A string hash representing the state
125
+ * @private
74
126
  */
75
127
  private readonly calculateChangeHash;
76
128
  }
@@ -10,22 +10,31 @@ const agentStatePropertyAccesor_1 = require("./agentStatePropertyAccesor");
10
10
  const logger_1 = require("../logger");
11
11
  const logger = (0, logger_1.debug)('agents:state');
12
12
  /**
13
- * Manages the state of an Agent.
13
+ * Manages the state of an Agent across turns in a conversation.
14
+ *
15
+ * AgentState provides functionality to persist and retrieve state data using
16
+ * a storage provider. It handles caching state in the turn context for performance,
17
+ * calculating change hashes to detect modifications, and managing property accessors
18
+ * for typed access to state properties.
14
19
  */
15
20
  class AgentState {
16
21
  /**
17
- * Creates a new instance of AgentState.
18
- * @param storage The storage provider.
19
- * @param storageKey The storage key factory.
20
- */
22
+ * Creates a new instance of AgentState.
23
+ *
24
+ * @param storage The storage provider used to persist state between turns
25
+ * @param storageKey A factory function that generates keys for storing state data
26
+ */
21
27
  constructor(storage, storageKey) {
22
28
  this.storage = storage;
23
29
  this.storageKey = storageKey;
24
30
  this.stateKey = Symbol('state');
25
31
  /**
26
- * Calculates the change hash for the specified item.
27
- * @param item The item to calculate the hash for.
28
- * @returns The calculated hash.
32
+ * Calculates a hash for the specified state object to detect changes.
33
+ * The eTag property is excluded from the hash calculation.
34
+ *
35
+ * @param item The state object to calculate the hash for
36
+ * @returns A string hash representing the state
37
+ * @private
29
38
  */
30
39
  this.calculateChangeHash = (item) => {
31
40
  const { eTag, ...rest } = item;
@@ -38,18 +47,23 @@ class AgentState {
38
47
  }
39
48
  /**
40
49
  * Creates a property accessor for the specified property.
41
- * @param name The name of the property.
42
- * @returns A property accessor for the specified property.
50
+ * Property accessors provide typed access to properties within the state object.
51
+ *
52
+ * @param name The name of the property to access
53
+ * @returns A property accessor for the specified property
43
54
  */
44
55
  createProperty(name) {
45
56
  const prop = new agentStatePropertyAccesor_1.AgentStatePropertyAccessor(this, name);
46
57
  return prop;
47
58
  }
48
59
  /**
49
- * Loads the state from storage.
50
- * @param context The turn context.
51
- * @param force Whether to force loading the state.
52
- * @returns A promise that resolves to the loaded state.
60
+ * Loads the state from storage into the turn context.
61
+ * If state is already cached in the turn context and force is not set, the cached version will be used.
62
+ *
63
+ * @param context The turn context to load state into
64
+ * @param force If true, forces a reload from storage even if state is cached
65
+ * @param customKey Optional custom storage key to use instead of the default
66
+ * @returns A promise that resolves to the loaded state object
53
67
  */
54
68
  async load(context, force = false, customKey) {
55
69
  const cached = context.turnState.get(this.stateKey);
@@ -65,10 +79,13 @@ class AgentState {
65
79
  return cached.state;
66
80
  }
67
81
  /**
68
- * Saves the state to storage.
69
- * @param context The turn context.
70
- * @param force Whether to force saving the state.
71
- * @returns A promise that resolves when the save operation is complete.
82
+ * Saves the state to storage if it has changed since it was loaded.
83
+ * Change detection uses a hash of the state object to determine if saving is necessary.
84
+ *
85
+ * @param context The turn context containing the state to save
86
+ * @param force If true, forces a save to storage even if no changes are detected
87
+ * @param customKey Optional custom storage key to use instead of the default
88
+ * @returns A promise that resolves when the save operation is complete
72
89
  */
73
90
  async saveChanges(context, force = false, customKey) {
74
91
  let cached = context.turnState.get(this.stateKey);
@@ -86,6 +103,14 @@ class AgentState {
86
103
  context.turnState.set(this.stateKey, cached);
87
104
  }
88
105
  }
106
+ /**
107
+ * Determines whether to use a custom key or generate one from the context.
108
+ *
109
+ * @param customKey Optional custom key with channel and conversation IDs
110
+ * @param context The turn context used to generate a key if no custom key is provided
111
+ * @returns The storage key to use
112
+ * @private
113
+ */
89
114
  async getStorageOrCustomKey(customKey, context) {
90
115
  let key;
91
116
  if (customKey && customKey.channelId && customKey.conversationId) {
@@ -98,18 +123,23 @@ class AgentState {
98
123
  return key;
99
124
  }
100
125
  /**
101
- * Clears the state from the turn context.
102
- * @param context The turn context.
103
- * @returns A promise that resolves when the clear operation is complete.
126
+ * Clears the state by setting it to an empty object in the turn context.
127
+ * Note: This does not remove the state from storage, it only clears the in-memory representation.
128
+ * Call saveChanges() after this to persist the empty state to storage.
129
+ *
130
+ * @param context The turn context containing the state to clear
131
+ * @returns A promise that resolves when the clear operation is complete
104
132
  */
105
133
  async clear(context) {
106
134
  const emptyObjectToForceSave = { state: {}, hash: '' };
107
135
  context.turnState.set(this.stateKey, emptyObjectToForceSave);
108
136
  }
109
137
  /**
110
- * Deletes the state from storage.
111
- * @param context The turn context.
112
- * @returns A promise that resolves when the delete operation is complete.
138
+ * Deletes the state from both the turn context and storage.
139
+ *
140
+ * @param context The turn context containing the state to delete
141
+ * @param customKey Optional custom storage key to use instead of the default
142
+ * @returns A promise that resolves when the delete operation is complete
113
143
  */
114
144
  async delete(context, customKey) {
115
145
  if (context.turnState.has(this.stateKey)) {
@@ -120,9 +150,10 @@ class AgentState {
120
150
  await this.storage.delete([key]);
121
151
  }
122
152
  /**
123
- * Gets the state from the turn context.
124
- * @param context The turn context.
125
- * @returns The state, or undefined if the state is not found.
153
+ * Gets the state from the turn context without loading it from storage.
154
+ *
155
+ * @param context The turn context containing the state to get
156
+ * @returns The state object, or undefined if no state is found in the turn context
126
157
  */
127
158
  get(context) {
128
159
  const cached = context.turnState.get(this.stateKey);
@@ -1 +1 @@
1
- {"version":3,"file":"agentState.js","sourceRoot":"","sources":["../../../src/state/agentState.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,6CAAwC;AACxC,2EAAwE;AACxE,sCAAiC;AAEjC,MAAM,MAAM,GAAG,IAAA,cAAK,EAAC,cAAc,CAAC,CAAA;AAapC;;GAEG;AACH,MAAa,UAAU;IAGrB;;;;QAII;IACJ,YAAuB,OAAgB,EAAY,UAA6B;QAAzD,YAAO,GAAP,OAAO,CAAS;QAAY,eAAU,GAAV,UAAU,CAAmB;QAP/D,aAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;QAoH3C;;;;WAIG;QACc,wBAAmB,GAAG,CAAC,IAAe,EAAU,EAAE;YACjE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAA;YAE9B,sCAAsC;YACtC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;YAEnC,MAAM,IAAI,GAAG,IAAA,wBAAU,EAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAA;YACxD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAEhD,OAAO,MAAM,CAAA;QACf,CAAC,CAAA;IA5HmF,CAAC;IAErF;;;;OAIG;IACH,cAAc,CAAU,IAAY;QAClC,MAAM,IAAI,GAAkC,IAAI,sDAA0B,CAAI,IAAI,EAAE,IAAI,CAAC,CAAA;QACzF,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,IAAI,CAAE,OAAoB,EAAE,KAAK,GAAG,KAAK,EAA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AAQ,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;IAClG,CAAC;CAqBF;AA/JD,gCA+JC"}
@@ -4,6 +4,15 @@
4
4
  */
5
5
  import { TurnContext } from '../turnContext';
6
6
  import { AgentState, CustomKey } from './agentState';
7
+ /**
8
+ * Interface for accessing a property in state storage with type safety.
9
+ *
10
+ * The interface defines standard methods for working with persisted state properties,
11
+ * allowing property access with strong typing to reduce errors when working with
12
+ * complex state objects.
13
+ *
14
+ * @typeParam T The type of the property being accessed
15
+ */
7
16
  export interface StatePropertyAccessor<T = any> {
8
17
  /**
9
18
  * Deletes the persisted property from its backing storage object.
@@ -58,35 +67,82 @@ export interface StatePropertyAccessor<T = any> {
58
67
  set(context: TurnContext, value: T): Promise<void>;
59
68
  }
60
69
  /**
61
- * Provides access to an Agent state property.
70
+ * Provides typed access to an Agent state property with automatic state loading.
71
+ *
72
+ * The AgentStatePropertyAccessor simplifies working with state by abstracting
73
+ * the details of loading state from storage and manipulating specific properties.
74
+ * It automatically handles:
75
+ *
76
+ * - Loading state when needed
77
+ * - Deep cloning of default values to prevent reference issues
78
+ * - Type checking for properties (when using TypeScript)
79
+ * - Ensuring properties exist before access
80
+ *
81
+ * Property accessors are created through the AgentState.createProperty() method:
82
+ *
83
+ * ```typescript
84
+ * // Create a property accessor for a user profile
85
+ * const userProfile = userState.createProperty<UserProfile>("userProfile");
86
+ *
87
+ * // Get the profile with a default if not exists
88
+ * const profile = await userProfile.get(context, { name: "", preferences: {} });
89
+ *
90
+ * // Update a value
91
+ * profile.preferences.theme = "dark";
92
+ *
93
+ * // Save the change
94
+ * await userProfile.set(context, profile);
95
+ *
96
+ * // Later, call userState.saveChanges(context) to persist to storage
97
+ * ```
98
+ *
99
+ * @typeParam T The type of the property being accessed
62
100
  */
63
101
  export declare class AgentStatePropertyAccessor<T = any> implements StatePropertyAccessor<T> {
64
102
  protected readonly state: AgentState;
65
103
  readonly name: string;
66
104
  /**
67
105
  * Creates a new instance of AgentStatePropertyAccessor.
68
- * @param state The agent state.
69
- * @param name The name of the property.
106
+ *
107
+ * @param state The agent state object that will contain this property
108
+ * @param name The name of the property in the state object
70
109
  */
71
110
  constructor(state: AgentState, name: string);
72
111
  /**
73
112
  * Deletes the property from the state.
74
- * @param context The turn context.
75
- * @returns A promise that resolves when the delete operation is complete.
113
+ *
114
+ * This removes the property from the state object but does not automatically
115
+ * persist the change to storage. Call state.saveChanges() afterwards to
116
+ * persist changes.
117
+ *
118
+ * @param context The turn context
119
+ * @param customKey Optional custom key for storing the state in a specific location
120
+ * @returns A promise that resolves when the delete operation is complete
76
121
  */
77
122
  delete(context: TurnContext, customKey?: CustomKey): Promise<void>;
78
123
  /**
79
124
  * Gets the value of the property from the state.
80
- * @param context The turn context.
81
- * @param defaultValue The default value to return if the property is not found.
82
- * @returns A promise that resolves to the value of the property.
125
+ *
126
+ * If the property doesn't exist and a default value is provided, a deep clone
127
+ * of the default value will be stored in state and returned. This ensures that
128
+ * modifications to the returned object will be properly tracked.
129
+ *
130
+ * @param context The turn context
131
+ * @param defaultValue Optional default value to use if the property doesn't exist
132
+ * @param customKey Optional custom key for storing the state in a specific location
133
+ * @returns A promise that resolves to the value of the property or undefined
83
134
  */
84
135
  get(context: TurnContext, defaultValue?: T, customKey?: CustomKey): Promise<T>;
85
136
  /**
86
137
  * Sets the value of the property in the state.
87
- * @param context The turn context.
88
- * @param value The value to set.
89
- * @returns A promise that resolves when the set operation is complete.
138
+ *
139
+ * This updates the property in the in-memory state object but does not automatically
140
+ * persist the change to storage. Call state.saveChanges() afterwards to persist changes.
141
+ *
142
+ * @param context The turn context
143
+ * @param value The value to set
144
+ * @param customKey Optional custom key for storing the state in a specific location
145
+ * @returns A promise that resolves when the set operation is complete
90
146
  */
91
147
  set(context: TurnContext, value: T, customKey?: CustomKey): Promise<void>;
92
148
  }
@@ -6,13 +6,43 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.AgentStatePropertyAccessor = void 0;
8
8
  /**
9
- * Provides access to an Agent state property.
9
+ * Provides typed access to an Agent state property with automatic state loading.
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:
14
+ *
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
19
+ *
20
+ * Property accessors are created through the AgentState.createProperty() method:
21
+ *
22
+ * ```typescript
23
+ * // Create a property accessor for a user profile
24
+ * const userProfile = userState.createProperty<UserProfile>("userProfile");
25
+ *
26
+ * // Get the profile with a default if not exists
27
+ * const profile = await userProfile.get(context, { name: "", preferences: {} });
28
+ *
29
+ * // Update a value
30
+ * profile.preferences.theme = "dark";
31
+ *
32
+ * // Save the change
33
+ * await userProfile.set(context, profile);
34
+ *
35
+ * // Later, call userState.saveChanges(context) to persist to storage
36
+ * ```
37
+ *
38
+ * @typeParam T The type of the property being accessed
10
39
  */
11
40
  class AgentStatePropertyAccessor {
12
41
  /**
13
42
  * Creates a new instance of AgentStatePropertyAccessor.
14
- * @param state The agent state.
15
- * @param name The name of the property.
43
+ *
44
+ * @param state The agent state object that will contain this property
45
+ * @param name The name of the property in the state object
16
46
  */
17
47
  constructor(state, name) {
18
48
  this.state = state;
@@ -20,8 +50,14 @@ class AgentStatePropertyAccessor {
20
50
  }
21
51
  /**
22
52
  * Deletes the property from the state.
23
- * @param context The turn context.
24
- * @returns A promise that resolves when the delete operation is complete.
53
+ *
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.
57
+ *
58
+ * @param context The turn context
59
+ * @param customKey Optional custom key for storing the state in a specific location
60
+ * @returns A promise that resolves when the delete operation is complete
25
61
  */
26
62
  async delete(context, customKey) {
27
63
  const obj = await this.state.load(context, false, customKey);
@@ -31,9 +67,15 @@ class AgentStatePropertyAccessor {
31
67
  }
32
68
  /**
33
69
  * Gets the value of the property from the state.
34
- * @param context The turn context.
35
- * @param defaultValue The default value to return if the property is not found.
36
- * @returns A promise that resolves to the value of the property.
70
+ *
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.
74
+ *
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
37
79
  */
38
80
  async get(context, defaultValue, customKey) {
39
81
  const obj = await this.state.load(context, false, customKey);
@@ -47,9 +89,14 @@ class AgentStatePropertyAccessor {
47
89
  }
48
90
  /**
49
91
  * Sets the value of the property in the state.
50
- * @param context The turn context.
51
- * @param value The value to set.
52
- * @returns A promise that resolves when the set operation is complete.
92
+ *
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.
95
+ *
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
+ * @returns A promise that resolves when the set operation is complete
53
100
  */
54
101
  async set(context, value, customKey) {
55
102
  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;;;AA8DH;;GAEG;AACH,MAAa,0BAA0B;IACrC;;;;OAIG;IACH,YAAgC,KAAiB,EAAkB,IAAY;QAA/C,UAAK,GAAL,KAAK,CAAY;QAAkB,SAAI,GAAJ,IAAI,CAAQ;IAAI,CAAC;IAEpF;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAE,OAAoB,EAAE,SAAqB;QACvD,MAAM,GAAG,GAAQ,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EA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