@microsoft/agents-hosting 1.0.0 → 1.0.3-g444d99f704
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/dist/package.json +2 -2
- package/dist/src/activityHandler.d.ts +0 -1
- package/dist/src/activityHandler.js +0 -1
- package/dist/src/activityHandler.js.map +1 -1
- package/dist/src/agent-client/agentResponseHandler.d.ts +6 -6
- package/dist/src/agent-client/agentResponseHandler.js +6 -6
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.d.ts +12 -4
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.js +5 -1
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.js.map +1 -1
- package/dist/src/app/agentApplication.d.ts +24 -7
- package/dist/src/app/agentApplication.js +24 -7
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/appRoute.d.ts +8 -4
- package/dist/src/app/attachmentDownloader.d.ts +3 -1
- package/dist/src/app/attachmentDownloader.js +3 -1
- package/dist/src/app/attachmentDownloader.js.map +1 -1
- package/dist/src/app/authorization.d.ts +26 -18
- package/dist/src/app/authorization.js +26 -18
- package/dist/src/app/authorization.js.map +1 -1
- package/dist/src/app/routeRank.d.ts +10 -3
- package/dist/src/app/routeRank.js +10 -3
- package/dist/src/app/routeRank.js.map +1 -1
- package/dist/src/app/streaming/streamingResponse.d.ts +23 -2
- package/dist/src/app/streaming/streamingResponse.js +23 -2
- package/dist/src/app/streaming/streamingResponse.js.map +1 -1
- package/dist/src/app/turnState.d.ts +69 -19
- package/dist/src/app/turnState.js +69 -19
- package/dist/src/app/turnState.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +16 -9
- package/dist/src/auth/authConfiguration.js +11 -6
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js +26 -18
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/cards/adaptiveCard.d.ts +1 -1
- package/dist/src/headerPropagation.d.ts +18 -6
- package/dist/src/state/agentState.d.ts +23 -7
- package/dist/src/state/agentState.js +19 -7
- package/dist/src/state/agentState.js.map +1 -1
- package/dist/src/state/agentStatePropertyAccesor.d.ts +63 -41
- package/dist/src/state/agentStatePropertyAccesor.js +43 -32
- package/dist/src/state/agentStatePropertyAccesor.js.map +1 -1
- package/dist/src/storage/fileStorage.d.ts +8 -6
- package/dist/src/storage/fileStorage.js +8 -6
- package/dist/src/storage/fileStorage.js.map +1 -1
- package/dist/src/storage/memoryStorage.d.ts +12 -7
- package/dist/src/storage/memoryStorage.js +12 -7
- package/dist/src/storage/memoryStorage.js.map +1 -1
- package/dist/src/storage/storage.d.ts +18 -1
- package/dist/src/turnContext.d.ts +31 -20
- package/dist/src/turnContext.js +31 -20
- package/dist/src/turnContext.js.map +1 -1
- package/package.json +2 -2
- package/src/activityHandler.ts +0 -1
- package/src/agent-client/agentResponseHandler.ts +6 -6
- package/src/app/adaptiveCards/adaptiveCardsActions.ts +12 -4
- package/src/app/agentApplication.ts +24 -7
- package/src/app/appRoute.ts +8 -4
- package/src/app/attachmentDownloader.ts +3 -1
- package/src/app/authorization.ts +26 -18
- package/src/app/routeRank.ts +10 -3
- package/src/app/streaming/streamingResponse.ts +23 -2
- package/src/app/turnState.ts +69 -19
- package/src/auth/authConfiguration.ts +16 -9
- package/src/auth/jwt-middleware.ts +24 -17
- package/src/cards/adaptiveCard.ts +1 -1
- package/src/headerPropagation.ts +18 -6
- package/src/state/agentState.ts +23 -7
- package/src/state/agentStatePropertyAccesor.ts +63 -41
- package/src/storage/fileStorage.ts +8 -6
- package/src/storage/memoryStorage.ts +12 -7
- package/src/storage/storage.ts +18 -1
- package/src/turnContext.ts +31 -20
|
@@ -66,28 +66,36 @@ const authorizeJWT = (authConfig) => {
|
|
|
66
66
|
return async function (req, res, next) {
|
|
67
67
|
let failed = false;
|
|
68
68
|
logger.debug('authorizing jwt');
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const user = await verifyToken(token, authConfig);
|
|
74
|
-
logger.debug('token verified for ', user);
|
|
75
|
-
req.user = user;
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
failed = true;
|
|
79
|
-
logger.error(err);
|
|
80
|
-
res.status(401).send({ 'jwt-auth-error': err.message });
|
|
81
|
-
}
|
|
69
|
+
if (req.method !== 'POST' && req.method !== 'GET') {
|
|
70
|
+
failed = true;
|
|
71
|
+
logger.warn('Method not allowed', req.method);
|
|
72
|
+
res.status(405).send({ 'jwt-auth-error': 'Method not allowed' });
|
|
82
73
|
}
|
|
83
74
|
else {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
75
|
+
const authHeader = req.headers.authorization;
|
|
76
|
+
if (authHeader) {
|
|
77
|
+
const token = authHeader.split(' ')[1]; // Extract the token from the Bearer string
|
|
78
|
+
try {
|
|
79
|
+
const user = await verifyToken(token, authConfig);
|
|
80
|
+
logger.debug('token verified for ', user);
|
|
81
|
+
req.user = user;
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
failed = true;
|
|
85
|
+
logger.error(err);
|
|
86
|
+
res.status(401).send({ 'jwt-auth-error': err.message });
|
|
87
|
+
}
|
|
87
88
|
}
|
|
88
89
|
else {
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
if (!authConfig.clientId && process.env.NODE_ENV !== 'production') {
|
|
91
|
+
logger.info('using anonymous auth');
|
|
92
|
+
req.user = { name: 'anonymous' };
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
failed = true;
|
|
96
|
+
logger.error('authorization header not found');
|
|
97
|
+
res.status(401).send({ 'jwt-auth-error': 'authorization header not found' });
|
|
98
|
+
}
|
|
91
99
|
}
|
|
92
100
|
}
|
|
93
101
|
if (!failed) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt-middleware.js","sourceRoot":"","sources":["../../../src/auth/jwt-middleware.ts"],"names":[],"mappings":";AAAA;;;GAGG;;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CAAC,CAAA;AACH,CAAC,CAAA;AApCY,QAAA,YAAY,gBAoCxB"}
|
|
@@ -36,36 +36,48 @@ export interface HeaderPropagationDefinition {
|
|
|
36
36
|
export interface HeaderPropagationCollection {
|
|
37
37
|
/**
|
|
38
38
|
* The collection of incoming headers from the incoming request.
|
|
39
|
-
*
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* This collection is built based on the headers received in the request.
|
|
40
42
|
*/
|
|
41
43
|
incoming: Record<string, string>;
|
|
42
44
|
/**
|
|
43
45
|
* The collection of headers that will be propagated to outgoing requests.
|
|
44
|
-
*
|
|
46
|
+
*
|
|
47
|
+
* @remarks
|
|
48
|
+
* This collection is built based on the incoming headers and the definition provided.
|
|
45
49
|
*/
|
|
46
50
|
outgoing: Record<string, string>;
|
|
47
51
|
/**
|
|
48
52
|
* Propagates the incoming header value to the outgoing collection based on the header definition key.
|
|
49
53
|
* @param headers List of header keys to propagate.
|
|
50
|
-
*
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* If the header does not exist in the incoming headers, it will be ignored.
|
|
51
57
|
*/
|
|
52
58
|
propagate(headers: string[]): void;
|
|
53
59
|
/**
|
|
54
60
|
* Adds a header definition to the outgoing collection.
|
|
55
61
|
* @param headers Headers to add to the outgoing collection.
|
|
56
|
-
*
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* If the header already exists, it will not be added.
|
|
57
65
|
*/
|
|
58
66
|
add(headers: Record<string, string>): void;
|
|
59
67
|
/**
|
|
60
68
|
* Concatenates a header definition to the outgoing collection.
|
|
61
69
|
* @param headers Headers to concatenate to the outgoing collection.
|
|
62
|
-
*
|
|
70
|
+
*
|
|
71
|
+
* @remarks
|
|
72
|
+
* If the header does not exist in the incoming headers, it will be ignored. Unless the header is already present in the outgoing collection.
|
|
63
73
|
*/
|
|
64
74
|
concat(headers: Record<string, string>): void;
|
|
65
75
|
/**
|
|
66
76
|
* Overrides a header definition in the outgoing collection.
|
|
67
77
|
* @param headers Headers to override in the outgoing collection.
|
|
68
|
-
*
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* If the header does not exist in the incoming headers, it will be added to the outgoing collection.
|
|
69
81
|
*/
|
|
70
82
|
override(headers: Record<string, string>): void;
|
|
71
83
|
}
|
|
@@ -7,6 +7,8 @@ import { TurnContext } from '../turnContext';
|
|
|
7
7
|
import { AgentStatePropertyAccessor } from './agentStatePropertyAccesor';
|
|
8
8
|
/**
|
|
9
9
|
* Represents agent state that has been cached in the turn context.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
10
12
|
* Used internally to track state changes and avoid unnecessary storage operations.
|
|
11
13
|
*/
|
|
12
14
|
export interface CachedAgentState {
|
|
@@ -23,6 +25,8 @@ export interface CachedAgentState {
|
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* Represents a custom key for storing state in a specific location.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
26
30
|
* Allows state to be persisted with channel and conversation identifiers
|
|
27
31
|
* independent of the current context.
|
|
28
32
|
*/
|
|
@@ -37,7 +41,8 @@ export interface CustomKey {
|
|
|
37
41
|
conversationId: string;
|
|
38
42
|
}
|
|
39
43
|
/**
|
|
40
|
-
*
|
|
44
|
+
* Manages the state of an Agent across turns in a conversation.
|
|
45
|
+
*
|
|
41
46
|
* @remarks
|
|
42
47
|
* AgentState provides functionality to persist and retrieve state data using
|
|
43
48
|
* a storage provider. It handles caching state in the turn context for performance,
|
|
@@ -57,30 +62,36 @@ export declare class AgentState {
|
|
|
57
62
|
constructor(storage: Storage, storageKey: StorageKeyFactory);
|
|
58
63
|
/**
|
|
59
64
|
* Creates a property accessor for the specified property.
|
|
60
|
-
* Property accessors provide typed access to properties within the state object.
|
|
61
65
|
*
|
|
62
66
|
* @param name The name of the property to access
|
|
63
67
|
* @returns A property accessor for the specified property
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* Property accessors provide typed access to properties within the state object.
|
|
64
71
|
*/
|
|
65
72
|
createProperty<T = any>(name: string): AgentStatePropertyAccessor<T>;
|
|
66
73
|
/**
|
|
67
74
|
* 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
75
|
*
|
|
70
76
|
* @param context The turn context to load state into
|
|
71
77
|
* @param force If true, forces a reload from storage even if state is cached
|
|
72
78
|
* @param customKey Optional custom storage key to use instead of the default
|
|
73
79
|
* @returns A promise that resolves to the loaded state object
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* If state is already cached in the turn context and force is not set, the cached version will be used.
|
|
74
83
|
*/
|
|
75
84
|
load(context: TurnContext, force?: boolean, customKey?: CustomKey): Promise<any>;
|
|
76
85
|
/**
|
|
77
86
|
* 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
87
|
*
|
|
80
88
|
* @param context The turn context containing the state to save
|
|
81
89
|
* @param force If true, forces a save to storage even if no changes are detected
|
|
82
90
|
* @param customKey Optional custom storage key to use instead of the default
|
|
83
91
|
* @returns A promise that resolves when the save operation is complete
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* Change detection uses a hash of the state object to determine if saving is necessary.
|
|
84
95
|
*/
|
|
85
96
|
saveChanges(context: TurnContext, force?: boolean, customKey?: CustomKey): Promise<void>;
|
|
86
97
|
/**
|
|
@@ -94,11 +105,14 @@ export declare class AgentState {
|
|
|
94
105
|
private getStorageOrCustomKey;
|
|
95
106
|
/**
|
|
96
107
|
* 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
108
|
*
|
|
100
109
|
* @param context The turn context containing the state to clear
|
|
101
110
|
* @returns A promise that resolves when the clear operation is complete
|
|
111
|
+
*
|
|
112
|
+
* @remarks
|
|
113
|
+
* This does not remove the state from storage, it only clears the in-memory representation.
|
|
114
|
+
* Call saveChanges() after this to persist the empty state to storage.
|
|
115
|
+
*
|
|
102
116
|
*/
|
|
103
117
|
clear(context: TurnContext): Promise<void>;
|
|
104
118
|
/**
|
|
@@ -118,10 +132,12 @@ export declare class AgentState {
|
|
|
118
132
|
get(context: TurnContext): any | undefined;
|
|
119
133
|
/**
|
|
120
134
|
* Calculates a hash for the specified state object to detect changes.
|
|
121
|
-
* The eTag property is excluded from the hash calculation.
|
|
122
135
|
*
|
|
123
136
|
* @param item The state object to calculate the hash for
|
|
124
137
|
* @returns A string hash representing the state
|
|
138
|
+
*
|
|
139
|
+
* @remarks
|
|
140
|
+
* The eTag property is excluded from the hash calculation.
|
|
125
141
|
* @private
|
|
126
142
|
*/
|
|
127
143
|
private readonly calculateChangeHash;
|
|
@@ -10,7 +10,8 @@ const agentStatePropertyAccesor_1 = require("./agentStatePropertyAccesor");
|
|
|
10
10
|
const logger_1 = require("@microsoft/agents-activity/logger");
|
|
11
11
|
const logger = (0, logger_1.debug)('agents:state');
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Manages the state of an Agent across turns in a conversation.
|
|
14
|
+
*
|
|
14
15
|
* @remarks
|
|
15
16
|
* AgentState provides functionality to persist and retrieve state data using
|
|
16
17
|
* a storage provider. It handles caching state in the turn context for performance,
|
|
@@ -30,10 +31,12 @@ class AgentState {
|
|
|
30
31
|
this.stateKey = Symbol('state');
|
|
31
32
|
/**
|
|
32
33
|
* Calculates a hash for the specified state object to detect changes.
|
|
33
|
-
* The eTag property is excluded from the hash calculation.
|
|
34
34
|
*
|
|
35
35
|
* @param item The state object to calculate the hash for
|
|
36
36
|
* @returns A string hash representing the state
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* The eTag property is excluded from the hash calculation.
|
|
37
40
|
* @private
|
|
38
41
|
*/
|
|
39
42
|
this.calculateChangeHash = (item) => {
|
|
@@ -47,10 +50,12 @@ class AgentState {
|
|
|
47
50
|
}
|
|
48
51
|
/**
|
|
49
52
|
* Creates a property accessor for the specified property.
|
|
50
|
-
* Property accessors provide typed access to properties within the state object.
|
|
51
53
|
*
|
|
52
54
|
* @param name The name of the property to access
|
|
53
55
|
* @returns A property accessor for the specified property
|
|
56
|
+
*
|
|
57
|
+
* @remarks
|
|
58
|
+
* Property accessors provide typed access to properties within the state object.
|
|
54
59
|
*/
|
|
55
60
|
createProperty(name) {
|
|
56
61
|
const prop = new agentStatePropertyAccesor_1.AgentStatePropertyAccessor(this, name);
|
|
@@ -58,12 +63,14 @@ class AgentState {
|
|
|
58
63
|
}
|
|
59
64
|
/**
|
|
60
65
|
* 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
66
|
*
|
|
63
67
|
* @param context The turn context to load state into
|
|
64
68
|
* @param force If true, forces a reload from storage even if state is cached
|
|
65
69
|
* @param customKey Optional custom storage key to use instead of the default
|
|
66
70
|
* @returns A promise that resolves to the loaded state object
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* If state is already cached in the turn context and force is not set, the cached version will be used.
|
|
67
74
|
*/
|
|
68
75
|
async load(context, force = false, customKey) {
|
|
69
76
|
const cached = context.turnState.get(this.stateKey);
|
|
@@ -80,12 +87,14 @@ class AgentState {
|
|
|
80
87
|
}
|
|
81
88
|
/**
|
|
82
89
|
* 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
90
|
*
|
|
85
91
|
* @param context The turn context containing the state to save
|
|
86
92
|
* @param force If true, forces a save to storage even if no changes are detected
|
|
87
93
|
* @param customKey Optional custom storage key to use instead of the default
|
|
88
94
|
* @returns A promise that resolves when the save operation is complete
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
* Change detection uses a hash of the state object to determine if saving is necessary.
|
|
89
98
|
*/
|
|
90
99
|
async saveChanges(context, force = false, customKey) {
|
|
91
100
|
let cached = context.turnState.get(this.stateKey);
|
|
@@ -124,11 +133,14 @@ class AgentState {
|
|
|
124
133
|
}
|
|
125
134
|
/**
|
|
126
135
|
* 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
136
|
*
|
|
130
137
|
* @param context The turn context containing the state to clear
|
|
131
138
|
* @returns A promise that resolves when the clear operation is complete
|
|
139
|
+
*
|
|
140
|
+
* @remarks
|
|
141
|
+
* This does not remove the state from storage, it only clears the in-memory representation.
|
|
142
|
+
* Call saveChanges() after this to persist the empty state to storage.
|
|
143
|
+
*
|
|
132
144
|
*/
|
|
133
145
|
async clear(context) {
|
|
134
146
|
const emptyObjectToForceSave = { state: {}, hash: '' };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentState.js","sourceRoot":"","sources":["../../../src/state/agentState.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,6CAAwC;AACxC,2EAAwE;AACxE,8DAAyD;AAEzD,MAAM,MAAM,GAAG,IAAA,cAAK,EAAC,cAAc,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"agentState.js","sourceRoot":"","sources":["../../../src/state/agentState.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,6CAAwC;AACxC,2EAAwE;AACxE,8DAAyD;AAEzD,MAAM,MAAM,GAAG,IAAA,cAAK,EAAC,cAAc,CAAC,CAAA;AAsCpC;;;;;;;;GAQG;AACH,MAAa,UAAU;IAGrB;;;;;OAKG;IACH,YAAuB,OAAgB,EAAY,UAA6B;QAAzD,YAAO,GAAP,OAAO,CAAS;QAAY,eAAU,GAAV,UAAU,CAAmB;QAR/D,aAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;QAoJ3C;;;;;;;;;WASG;QACc,wBAAmB,GAAG,CAAC,IAAe,EAAU,EAAE;YACjE,MAAM,EAAE,IAAI,EAAE,GA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AAK,QAAQ,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;IAClG,CAAC;CAuBF;AA1KD,gCA0KC"}
|
|
@@ -7,28 +7,35 @@ import { AgentState, CustomKey } from './agentState';
|
|
|
7
7
|
/**
|
|
8
8
|
* Interface for accessing a property in state storage with type safety.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* @typeParam T The type of the property being accessed
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* This interface defines standard methods for working with persisted state properties,
|
|
11
14
|
* allowing property access with strong typing to reduce errors when working with
|
|
12
15
|
* complex state objects.
|
|
13
16
|
*
|
|
14
|
-
* @typeParam T The type of the property being accessed
|
|
15
17
|
*/
|
|
16
18
|
export interface StatePropertyAccessor<T = any> {
|
|
17
19
|
/**
|
|
18
20
|
* Deletes the persisted property from its backing storage object.
|
|
19
21
|
*
|
|
22
|
+
* @param context Context for the current turn of conversation with the user.
|
|
23
|
+
*
|
|
20
24
|
* @remarks
|
|
21
25
|
* The properties backing storage object SHOULD be loaded into memory on first access.
|
|
22
26
|
*
|
|
23
|
-
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```javascript
|
|
24
29
|
* await myProperty.delete(context);
|
|
25
30
|
* ```
|
|
26
|
-
*
|
|
31
|
+
*
|
|
27
32
|
*/
|
|
28
33
|
delete(context: TurnContext): Promise<void>;
|
|
29
34
|
/**
|
|
30
35
|
* Reads a persisted property from its backing storage object.
|
|
31
36
|
*
|
|
37
|
+
* @param context Context for the current turn of conversation with the user.
|
|
38
|
+
*
|
|
32
39
|
* @remarks
|
|
33
40
|
* The properties backing storage object SHOULD be loaded into memory on first access.
|
|
34
41
|
*
|
|
@@ -36,10 +43,11 @@ export interface StatePropertyAccessor<T = any> {
|
|
|
36
43
|
* specified, a clone of the `defaultValue` SHOULD be copied to the storage object. If a
|
|
37
44
|
* `defaultValue` has not been specified then a value of `undefined` SHOULD be returned.
|
|
38
45
|
*
|
|
39
|
-
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```javascript
|
|
40
48
|
* const value = await myProperty.get(context, { count: 0 });
|
|
41
49
|
* ```
|
|
42
|
-
*
|
|
50
|
+
*
|
|
43
51
|
*/
|
|
44
52
|
get(context: TurnContext): Promise<T | undefined>;
|
|
45
53
|
/**
|
|
@@ -52,25 +60,30 @@ export interface StatePropertyAccessor<T = any> {
|
|
|
52
60
|
/**
|
|
53
61
|
* Assigns a new value to the properties backing storage object.
|
|
54
62
|
*
|
|
63
|
+
* @param context Context for the current turn of conversation with the user.
|
|
64
|
+
* @param value Value to assign.
|
|
65
|
+
*
|
|
55
66
|
* @remarks
|
|
56
67
|
* The properties backing storage object SHOULD be loaded into memory on first access.
|
|
57
68
|
*
|
|
58
69
|
* Depending on the state systems implementation, an additional step may be required to
|
|
59
70
|
* persist the actual changes to disk.
|
|
60
71
|
*
|
|
61
|
-
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```javascript
|
|
62
74
|
* await myProperty.set(context, value);
|
|
63
75
|
* ```
|
|
64
|
-
*
|
|
65
|
-
* @param value Value to assign.
|
|
76
|
+
*
|
|
66
77
|
*/
|
|
67
78
|
set(context: TurnContext, value: T): Promise<void>;
|
|
68
79
|
}
|
|
69
80
|
/**
|
|
70
|
-
*
|
|
81
|
+
* Provides typed access to an Agent state property with automatic state loading and persistence management.
|
|
82
|
+
*
|
|
83
|
+
* @typeParam T The type of the property being accessed. Can be any serializable type.
|
|
71
84
|
*
|
|
72
85
|
* @remarks
|
|
73
|
-
* AgentStatePropertyAccessor simplifies working with persisted state by abstracting
|
|
86
|
+
* `AgentStatePropertyAccessor` simplifies working with persisted state by abstracting
|
|
74
87
|
* the complexity of loading state from storage and manipulating specific properties.
|
|
75
88
|
* It provides a type-safe interface for state management with automatic handling of:
|
|
76
89
|
*
|
|
@@ -82,6 +95,11 @@ export interface StatePropertyAccessor<T = any> {
|
|
|
82
95
|
*
|
|
83
96
|
* ### Key Features
|
|
84
97
|
*
|
|
98
|
+
* Key features of `AgentStatePropertyAccessor` include:
|
|
99
|
+
* - [Type Safety](#type-safety)
|
|
100
|
+
* - [Automatic Default Value Handling](#automatic-default-value-handling)
|
|
101
|
+
* - [Explicit Persistence Control](#explicit-persistence-control)
|
|
102
|
+
*
|
|
85
103
|
* #### Type Safety
|
|
86
104
|
* The accessor provides compile-time type checking when using TypeScript:
|
|
87
105
|
* ```typescript
|
|
@@ -172,8 +190,6 @@ export interface StatePropertyAccessor<T = any> {
|
|
|
172
190
|
* - **Persistence**: Always call `state.saveChanges(context)` to persist changes to storage.
|
|
173
191
|
* - **Deep Cloning**: Default values are deep cloned using JSON serialization, which may not work with complex objects containing functions or circular references.
|
|
174
192
|
*
|
|
175
|
-
* @typeParam T The type of the property being accessed. Can be any serializable type.
|
|
176
|
-
*
|
|
177
193
|
* @see {@link AgentState.createProperty} for creating property accessors
|
|
178
194
|
* @see {@link StatePropertyAccessor} for the interface definition
|
|
179
195
|
*/
|
|
@@ -183,13 +199,13 @@ export declare class AgentStatePropertyAccessor<T = any> implements StatePropert
|
|
|
183
199
|
/**
|
|
184
200
|
* Creates a new instance of AgentStatePropertyAccessor.
|
|
185
201
|
*
|
|
202
|
+
* @param state The agent state object that manages the backing storage for this property
|
|
203
|
+
* @param name The unique name of the property within the state object. This name is used as the key in the state storage.
|
|
204
|
+
*
|
|
186
205
|
* @remarks
|
|
187
206
|
* This constructor is typically not called directly. Instead, use {@link AgentState.createProperty}
|
|
188
207
|
* to create property accessors, which ensures proper integration with the state management system.
|
|
189
208
|
*
|
|
190
|
-
* @param state The agent state object that manages the backing storage for this property
|
|
191
|
-
* @param name The unique name of the property within the state object. This name is used as the key in the state storage.
|
|
192
|
-
*
|
|
193
209
|
* @example
|
|
194
210
|
* ```typescript
|
|
195
211
|
* // Recommended way - use AgentState.createProperty
|
|
@@ -198,10 +214,17 @@ export declare class AgentStatePropertyAccessor<T = any> implements StatePropert
|
|
|
198
214
|
* // Direct construction (not recommended)
|
|
199
215
|
* const accessor = new AgentStatePropertyAccessor<UserProfile>(userState, "userProfile");
|
|
200
216
|
* ```
|
|
217
|
+
*
|
|
201
218
|
*/
|
|
202
219
|
constructor(state: AgentState, name: string);
|
|
203
220
|
/**
|
|
204
|
-
*
|
|
221
|
+
* Deletes the property from the state storage.
|
|
222
|
+
*
|
|
223
|
+
* @param context The turn context for the current conversation turn
|
|
224
|
+
* @param customKey Optional custom key for accessing state in a specific storage location.
|
|
225
|
+
* Useful for multi-tenant scenarios or when state needs to be partitioned.
|
|
226
|
+
* @returns A promise that resolves when the delete operation is complete
|
|
227
|
+
*
|
|
205
228
|
* @remarks
|
|
206
229
|
* This operation removes the property from the in-memory state object but does not
|
|
207
230
|
* automatically persist the change to the underlying storage. You must call
|
|
@@ -211,13 +234,7 @@ export declare class AgentStatePropertyAccessor<T = any> implements StatePropert
|
|
|
211
234
|
* - The deletion only affects the in-memory state until `saveChanges()` is called
|
|
212
235
|
* - After deletion, subsequent `get()` calls will return `undefined` (or the default value if provided)
|
|
213
236
|
*
|
|
214
|
-
* @
|
|
215
|
-
* @param customKey Optional custom key for accessing state in a specific storage location.
|
|
216
|
-
* Useful for multi-tenant scenarios or when state needs to be partitioned.
|
|
217
|
-
*
|
|
218
|
-
* @returns A promise that resolves when the delete operation is complete
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
237
|
+
* @example Basic usage
|
|
221
238
|
* ```typescript
|
|
222
239
|
* const userSettings = userState.createProperty<UserSettings>("settings");
|
|
223
240
|
*
|
|
@@ -237,10 +254,20 @@ export declare class AgentStatePropertyAccessor<T = any> implements StatePropert
|
|
|
237
254
|
* await userSettings.delete(context, tenantKey);
|
|
238
255
|
* await userState.saveChanges(context);
|
|
239
256
|
* ```
|
|
257
|
+
*
|
|
240
258
|
*/
|
|
241
259
|
delete(context: TurnContext, customKey?: CustomKey): Promise<void>;
|
|
242
260
|
/**
|
|
243
|
-
*
|
|
261
|
+
* Retrieves the value of the property from state storage.
|
|
262
|
+
*
|
|
263
|
+
* @param context The turn context for the current conversation turn
|
|
264
|
+
* @param defaultValue Optional default value to use if the property doesn't exist.
|
|
265
|
+
* When provided, this value is deep cloned and stored in state.
|
|
266
|
+
* @param customKey Optional custom key for accessing state in a specific storage location.
|
|
267
|
+
* Useful for multi-tenant scenarios or when state needs to be partitioned.
|
|
268
|
+
*
|
|
269
|
+
* @returns A promise that resolves to the property value, the cloned default value, or `undefined`
|
|
270
|
+
*
|
|
244
271
|
* @remarks
|
|
245
272
|
* This method provides intelligent default value handling:
|
|
246
273
|
* - If the property exists, its value is returned
|
|
@@ -257,14 +284,6 @@ export declare class AgentStatePropertyAccessor<T = any> implements StatePropert
|
|
|
257
284
|
* **Performance**: The first access loads state from storage; subsequent accesses use
|
|
258
285
|
* the in-memory cached version until the context is disposed.
|
|
259
286
|
*
|
|
260
|
-
* @param context The turn context for the current conversation turn
|
|
261
|
-
* @param defaultValue Optional default value to use if the property doesn't exist.
|
|
262
|
-
* When provided, this value is deep cloned and stored in state.
|
|
263
|
-
* @param customKey Optional custom key for accessing state in a specific storage location.
|
|
264
|
-
* Useful for multi-tenant scenarios or when state needs to be partitioned.
|
|
265
|
-
*
|
|
266
|
-
* @returns A promise that resolves to the property value, the cloned default value, or `undefined`
|
|
267
|
-
*
|
|
268
287
|
* @example Basic usage
|
|
269
288
|
* ```typescript
|
|
270
289
|
* const counterProperty = userState.createProperty<number>("counter");
|
|
@@ -303,10 +322,19 @@ export declare class AgentStatePropertyAccessor<T = any> implements StatePropert
|
|
|
303
322
|
* const tenantKey = { key: `tenant_${tenantId}` };
|
|
304
323
|
* const tenantData = await dataProperty.get(context, defaultData, tenantKey);
|
|
305
324
|
* ```
|
|
325
|
+
*
|
|
306
326
|
*/
|
|
307
327
|
get(context: TurnContext, defaultValue?: T, customKey?: CustomKey): Promise<T>;
|
|
308
328
|
/**
|
|
309
|
-
*
|
|
329
|
+
* Sets the value of the property in state storage.
|
|
330
|
+
*
|
|
331
|
+
* @param context The turn context for the current conversation turn
|
|
332
|
+
* @param value The value to assign to the property. Can be any serializable value.
|
|
333
|
+
* @param customKey Optional custom key for accessing state in a specific storage location.
|
|
334
|
+
* Useful for multi-tenant scenarios or when state needs to be partitioned.
|
|
335
|
+
*
|
|
336
|
+
* @returns A promise that resolves when the set operation is complete
|
|
337
|
+
*
|
|
310
338
|
* @remarks
|
|
311
339
|
* This operation updates the property in the in-memory state object but does not
|
|
312
340
|
* automatically persist the change to the underlying storage. You must call
|
|
@@ -323,13 +351,6 @@ export declare class AgentStatePropertyAccessor<T = any> implements StatePropert
|
|
|
323
351
|
* **Type Safety**: When using TypeScript, the value must match the property's
|
|
324
352
|
* declared type parameter.
|
|
325
353
|
*
|
|
326
|
-
* @param context The turn context for the current conversation turn
|
|
327
|
-
* @param value The value to assign to the property. Can be any serializable value.
|
|
328
|
-
* @param customKey Optional custom key for accessing state in a specific storage location.
|
|
329
|
-
* Useful for multi-tenant scenarios or when state needs to be partitioned.
|
|
330
|
-
*
|
|
331
|
-
* @returns A promise that resolves when the set operation is complete
|
|
332
|
-
*
|
|
333
354
|
* @example Basic usage
|
|
334
355
|
* ```typescript
|
|
335
356
|
* const counterProperty = userState.createProperty<number>("counter");
|
|
@@ -371,6 +392,7 @@ export declare class AgentStatePropertyAccessor<T = any> implements StatePropert
|
|
|
371
392
|
* await dataProperty.set(context, updatedData, tenantKey);
|
|
372
393
|
* await userState.saveChanges(context);
|
|
373
394
|
* ```
|
|
395
|
+
*
|
|
374
396
|
*/
|
|
375
397
|
set(context: TurnContext, value: T, customKey?: CustomKey): Promise<void>;
|
|
376
398
|
}
|