@microsoft/agents-hosting 0.2.14 → 0.4.1

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 (84) hide show
  1. package/README.md +17 -1
  2. package/dist/src/app/agentApplication.d.ts +27 -15
  3. package/dist/src/app/agentApplication.js +36 -31
  4. package/dist/src/app/agentApplication.js.map +1 -1
  5. package/dist/src/app/agentApplicationBuilder.d.ts +3 -4
  6. package/dist/src/app/agentApplicationBuilder.js +7 -7
  7. package/dist/src/app/agentApplicationBuilder.js.map +1 -1
  8. package/dist/src/app/agentApplicationOptions.d.ts +26 -2
  9. package/dist/src/app/appRoute.d.ts +6 -0
  10. package/dist/src/app/attachmentDownloader.d.ts +18 -0
  11. package/dist/src/app/attachmentDownloader.js +18 -0
  12. package/dist/src/app/attachmentDownloader.js.map +1 -1
  13. package/dist/src/app/conversationUpdateEvents.d.ts +6 -0
  14. package/dist/src/app/index.d.ts +1 -1
  15. package/dist/src/app/index.js +1 -1
  16. package/dist/src/app/index.js.map +1 -1
  17. package/dist/src/app/inputFileDownloader.d.ts +22 -0
  18. package/dist/src/app/oauth/authorization.d.ts +87 -0
  19. package/dist/src/app/oauth/authorization.js +135 -0
  20. package/dist/src/app/oauth/authorization.js.map +1 -0
  21. package/dist/src/app/routeHandler.d.ts +8 -0
  22. package/dist/src/app/routeSelector.d.ts +9 -0
  23. package/dist/src/app/turnState.d.ts +128 -15
  24. package/dist/src/app/turnState.js +114 -16
  25. package/dist/src/app/turnState.js.map +1 -1
  26. package/dist/src/auth/authConfiguration.d.ts +24 -0
  27. package/dist/src/auth/authConfiguration.js.map +1 -1
  28. package/dist/src/auth/request.d.ts +12 -0
  29. package/dist/src/baseAdapter.d.ts +17 -0
  30. package/dist/src/baseAdapter.js +17 -0
  31. package/dist/src/baseAdapter.js.map +1 -1
  32. package/dist/src/cards/cardFactory.d.ts +3 -0
  33. package/dist/src/cards/cardFactory.js +3 -0
  34. package/dist/src/cards/cardFactory.js.map +1 -1
  35. package/dist/src/cards/o365ConnectorCardActionBase.d.ts +8 -0
  36. package/dist/src/oauth/oAuthFlow.d.ts +32 -3
  37. package/dist/src/oauth/oAuthFlow.js +38 -14
  38. package/dist/src/oauth/oAuthFlow.js.map +1 -1
  39. package/dist/src/oauth/userTokenClient.d.ts +2 -2
  40. package/dist/src/oauth/userTokenClient.js +3 -3
  41. package/dist/src/oauth/userTokenClient.js.map +1 -1
  42. package/dist/src/state/agentStatePropertyAccesor.d.ts +1 -1
  43. package/dist/src/state/agentStatePropertyAccesor.js +1 -1
  44. package/dist/src/statusCodes.d.ts +39 -0
  45. package/dist/src/statusCodes.js +39 -0
  46. package/dist/src/statusCodes.js.map +1 -1
  47. package/dist/src/storage/fileStorage.d.ts +9 -0
  48. package/dist/src/storage/fileStorage.js +62 -0
  49. package/dist/src/storage/fileStorage.js.map +1 -0
  50. package/dist/src/storage/index.d.ts +1 -0
  51. package/dist/src/storage/index.js +1 -0
  52. package/dist/src/storage/index.js.map +1 -1
  53. package/dist/src/tokenResponseEventName.d.ts +3 -0
  54. package/dist/src/tokenResponseEventName.js +3 -0
  55. package/dist/src/tokenResponseEventName.js.map +1 -1
  56. package/package.json +4 -4
  57. package/src/app/agentApplication.ts +36 -32
  58. package/src/app/agentApplicationBuilder.ts +8 -8
  59. package/src/app/agentApplicationOptions.ts +33 -2
  60. package/src/app/appRoute.ts +7 -0
  61. package/src/app/attachmentDownloader.ts +18 -0
  62. package/src/app/conversationUpdateEvents.ts +6 -0
  63. package/src/app/index.ts +1 -1
  64. package/src/app/inputFileDownloader.ts +24 -0
  65. package/src/app/oauth/authorization.ts +162 -0
  66. package/src/app/routeHandler.ts +8 -0
  67. package/src/app/routeSelector.ts +9 -0
  68. package/src/app/turnState.ts +129 -33
  69. package/src/auth/authConfiguration.ts +32 -1
  70. package/src/auth/request.ts +15 -0
  71. package/src/baseAdapter.ts +18 -0
  72. package/src/cards/cardFactory.ts +3 -0
  73. package/src/cards/o365ConnectorCardActionBase.ts +8 -0
  74. package/src/oauth/oAuthFlow.ts +59 -18
  75. package/src/oauth/userTokenClient.ts +4 -4
  76. package/src/state/agentStatePropertyAccesor.ts +1 -1
  77. package/src/statusCodes.ts +51 -0
  78. package/src/storage/fileStorage.ts +59 -0
  79. package/src/storage/index.ts +1 -0
  80. package/src/tokenResponseEventName.ts +3 -0
  81. package/dist/src/app/oauth/userIdentity.d.ts +0 -43
  82. package/dist/src/app/oauth/userIdentity.js +0 -54
  83. package/dist/src/app/oauth/userIdentity.js.map +0 -1
  84. package/src/app/oauth/userIdentity.ts +0 -78
@@ -4,11 +4,33 @@
4
4
  */
5
5
  import { TurnContext } from '../turnContext';
6
6
  import { TurnState } from './turnState';
7
+ /**
8
+ * Represents a file input with its content, type, and optional URL.
9
+ */
7
10
  export interface InputFile {
11
+ /**
12
+ * The content of the file as a Buffer.
13
+ */
8
14
  content: Buffer;
15
+ /**
16
+ * The MIME type of the file content.
17
+ */
9
18
  contentType: string;
19
+ /**
20
+ * An optional URL pointing to the file content.
21
+ */
10
22
  contentUrl?: string;
11
23
  }
24
+ /**
25
+ * Interface for downloading input files in a specific turn context and state.
26
+ */
12
27
  export interface InputFileDownloader<TState extends TurnState = TurnState> {
28
+ /**
29
+ * Downloads files based on the provided turn context and state.
30
+ *
31
+ * @param context - The turn context for the current operation.
32
+ * @param state - The state associated with the current turn.
33
+ * @returns A promise that resolves to an array of input files.
34
+ */
13
35
  downloadFiles(context: TurnContext, state: TState): Promise<InputFile[]>;
14
36
  }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { TurnContext } from '../../turnContext';
6
+ import { TurnState } from '../turnState';
7
+ import { Storage } from '../../storage';
8
+ import { OAuthFlow, TokenResponse } from '../../oauth';
9
+ /**
10
+ * Interface defining an authorization handler for OAuth flows
11
+ * @interface AuthHandler
12
+ */
13
+ export interface AuthHandler {
14
+ /** Connection name for the auth provider */
15
+ name?: string;
16
+ /** Whether authorization should be triggered automatically */
17
+ auto?: boolean;
18
+ /** The OAuth flow implementation */
19
+ flow?: OAuthFlow;
20
+ /** Title to display on auth cards/UI */
21
+ title?: string;
22
+ /** Text to display on auth cards/UI */
23
+ text?: string;
24
+ }
25
+ /**
26
+ * Options for configuring user authorization.
27
+ * Contains settings to configure OAuth connections.
28
+ */
29
+ export interface AuthorizationHandlers extends Record<string, AuthHandler> {
30
+ }
31
+ /**
32
+ * Class responsible for managing authorization and OAuth flows
33
+ * @class Authorization
34
+ */
35
+ export declare class Authorization {
36
+ _authHandlers: AuthorizationHandlers;
37
+ /**
38
+ * Creates a new instance of UserAuthorization.
39
+ * @param {Storage} storage - The storage system to use for state management.
40
+ * @param {AuthorizationHandlers} authHandlers - Configuration for OAuth providers
41
+ * @throws {Error} If storage is null/undefined or no auth handlers are provided
42
+ */
43
+ constructor(storage: Storage, authHandlers: AuthorizationHandlers);
44
+ /**
45
+ * Gets the token for a specific auth handler
46
+ * @param {TurnContext} context - The context object for the current turn
47
+ * @param {string} [authHandlerId] - Optional ID of the auth handler to use, defaults to first handler
48
+ * @returns {Promise<TokenResponse>} The token response from the OAuth provider
49
+ */
50
+ getToken(context: TurnContext, authHandlerId?: string): Promise<TokenResponse>;
51
+ /**
52
+ * Begins or continues an OAuth flow
53
+ * @param {TurnContext} context - The context object for the current turn
54
+ * @param {TurnState} state - The state object for the current turn
55
+ * @param {string} [authHandlerId] - Optional ID of the auth handler to use, defaults to first handler
56
+ * @returns {Promise<TokenResponse>} The token response from the OAuth provider
57
+ */
58
+ beginOrContinueFlow(context: TurnContext, state: TurnState, authHandlerId?: string): Promise<TokenResponse>;
59
+ /**
60
+ * Gets the current state of the OAuth flow
61
+ * @param {string} [authHandlerId] - Optional ID of the auth handler to check, defaults to first handler
62
+ * @returns {boolean} Whether the flow has started
63
+ */
64
+ getFlowState(authHandlerId?: string): boolean;
65
+ /**
66
+ * Resolves the auth handler to use based on the provided ID
67
+ * @param {string} [authHandlerId] - Optional ID of the auth handler to resolve, defaults to first handler
68
+ * @returns {AuthHandler} The resolved auth handler
69
+ */
70
+ resolverHandler: (authHandlerId?: string) => AuthHandler;
71
+ /**
72
+ * Signs out the current user.
73
+ * This method clears the user's token and resets the SSO state.
74
+ *
75
+ * @param {TurnContext} context - The context object for the current turn.
76
+ * @param {TurnState} state - The state object for the current turn.
77
+ * @param {string} [authHandlerId] - Optional ID of the auth handler to use for sign out
78
+ * @returns {Promise<void>}
79
+ */
80
+ signOut(context: TurnContext, state: TurnState, authHandlerId?: string): Promise<void>;
81
+ _signInHandler: ((context: TurnContext, state: TurnState, authHandlerId?: string) => void) | null;
82
+ /**
83
+ * Sets a handler to be called when sign-in is successfully completed
84
+ * @param {Function} handler - The handler function to call on successful sign-in
85
+ */
86
+ onSignInSuccess(handler: (context: TurnContext, state: TurnState, authHandlerId?: string) => void): void;
87
+ }
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.Authorization = void 0;
8
+ const logger_1 = require("../../logger");
9
+ const oauth_1 = require("../../oauth");
10
+ const state_1 = require("../../state");
11
+ const logger = (0, logger_1.debug)('agents:authorization');
12
+ /**
13
+ * Class responsible for managing authorization and OAuth flows
14
+ * @class Authorization
15
+ */
16
+ class Authorization {
17
+ /**
18
+ * Creates a new instance of UserAuthorization.
19
+ * @param {Storage} storage - The storage system to use for state management.
20
+ * @param {AuthorizationHandlers} authHandlers - Configuration for OAuth providers
21
+ * @throws {Error} If storage is null/undefined or no auth handlers are provided
22
+ */
23
+ constructor(storage, authHandlers) {
24
+ var _a, _b, _c, _d;
25
+ /**
26
+ * Resolves the auth handler to use based on the provided ID
27
+ * @param {string} [authHandlerId] - Optional ID of the auth handler to resolve, defaults to first handler
28
+ * @returns {AuthHandler} The resolved auth handler
29
+ */
30
+ this.resolverHandler = (authHandlerId) => {
31
+ if (authHandlerId) {
32
+ return this._authHandlers[authHandlerId];
33
+ }
34
+ return this._authHandlers[Object.keys(this._authHandlers)[0]];
35
+ };
36
+ this._signInHandler = null;
37
+ if (storage === undefined || storage === null) {
38
+ throw new Error('Storage is required for UserAuthorization');
39
+ }
40
+ const userState = new state_1.UserState(storage);
41
+ if (authHandlers === undefined || Object.keys(authHandlers).length === 0) {
42
+ throw new Error('The authorization does not have any auth handlers');
43
+ }
44
+ this._authHandlers = authHandlers;
45
+ for (const ah in this._authHandlers) {
46
+ if (this._authHandlers[ah].name === undefined && process.env[ah + '_connectionName'] === undefined) {
47
+ throw new Error(`AuthHandler name ${ah}_connectionName not set in autorization and not found in env vars.`);
48
+ }
49
+ const currentAuthHandler = this._authHandlers[ah];
50
+ currentAuthHandler.name = (_a = currentAuthHandler.name) !== null && _a !== void 0 ? _a : process.env[ah + '_connectionName'];
51
+ currentAuthHandler.title = (_b = currentAuthHandler.title) !== null && _b !== void 0 ? _b : process.env[ah + '_connectionTitle'];
52
+ currentAuthHandler.text = (_c = currentAuthHandler.text) !== null && _c !== void 0 ? _c : process.env[ah + '_connectionText'];
53
+ currentAuthHandler.auto = (_d = currentAuthHandler.auto) !== null && _d !== void 0 ? _d : process.env[ah + '_connectionAuto'] === 'true';
54
+ currentAuthHandler.flow = new oauth_1.OAuthFlow(userState, currentAuthHandler.name, null, currentAuthHandler.title, currentAuthHandler.text);
55
+ }
56
+ logger.info('Authorization handlers configured with', this._authHandlers.length, 'handlers');
57
+ }
58
+ /**
59
+ * Gets the token for a specific auth handler
60
+ * @param {TurnContext} context - The context object for the current turn
61
+ * @param {string} [authHandlerId] - Optional ID of the auth handler to use, defaults to first handler
62
+ * @returns {Promise<TokenResponse>} The token response from the OAuth provider
63
+ */
64
+ async getToken(context, authHandlerId) {
65
+ var _a;
66
+ logger.info('getToken from user token service for authHandlerId:', authHandlerId);
67
+ const authHandler = this.resolverHandler(authHandlerId);
68
+ return await ((_a = authHandler.flow) === null || _a === void 0 ? void 0 : _a.getUserToken(context));
69
+ }
70
+ /**
71
+ * Begins or continues an OAuth flow
72
+ * @param {TurnContext} context - The context object for the current turn
73
+ * @param {TurnState} state - The state object for the current turn
74
+ * @param {string} [authHandlerId] - Optional ID of the auth handler to use, defaults to first handler
75
+ * @returns {Promise<TokenResponse>} The token response from the OAuth provider
76
+ */
77
+ async beginOrContinueFlow(context, state, authHandlerId) {
78
+ logger.info('beginOrContinueFlow for authHandlerId:', authHandlerId);
79
+ const flow = this.resolverHandler(authHandlerId).flow;
80
+ let tokenResponse;
81
+ if (flow.state.flowStarted === false) {
82
+ tokenResponse = await flow.beginFlow(context);
83
+ }
84
+ else {
85
+ tokenResponse = await flow.continueFlow(context);
86
+ if (tokenResponse.status === oauth_1.TokenRequestStatus.Success) {
87
+ if (this._signInHandler) {
88
+ await this._signInHandler(context, state, authHandlerId);
89
+ }
90
+ }
91
+ }
92
+ return tokenResponse;
93
+ }
94
+ /**
95
+ * Gets the current state of the OAuth flow
96
+ * @param {string} [authHandlerId] - Optional ID of the auth handler to check, defaults to first handler
97
+ * @returns {boolean} Whether the flow has started
98
+ */
99
+ getFlowState(authHandlerId) {
100
+ var _a;
101
+ const flow = this.resolverHandler(authHandlerId).flow;
102
+ return (_a = flow.state) === null || _a === void 0 ? void 0 : _a.flowStarted;
103
+ }
104
+ /**
105
+ * Signs out the current user.
106
+ * This method clears the user's token and resets the SSO state.
107
+ *
108
+ * @param {TurnContext} context - The context object for the current turn.
109
+ * @param {TurnState} state - The state object for the current turn.
110
+ * @param {string} [authHandlerId] - Optional ID of the auth handler to use for sign out
111
+ * @returns {Promise<void>}
112
+ */
113
+ async signOut(context, state, authHandlerId) {
114
+ var _a;
115
+ logger.info('signOut for authHandlerId:', authHandlerId);
116
+ if (authHandlerId === undefined) { // aw
117
+ for (const ah in this._authHandlers) {
118
+ const flow = this._authHandlers[ah].flow;
119
+ await (flow === null || flow === void 0 ? void 0 : flow.signOut(context));
120
+ }
121
+ }
122
+ else {
123
+ await ((_a = this.resolverHandler(authHandlerId).flow) === null || _a === void 0 ? void 0 : _a.signOut(context));
124
+ }
125
+ }
126
+ /**
127
+ * Sets a handler to be called when sign-in is successfully completed
128
+ * @param {Function} handler - The handler function to call on successful sign-in
129
+ */
130
+ onSignInSuccess(handler) {
131
+ this._signInHandler = handler;
132
+ }
133
+ }
134
+ exports.Authorization = Authorization;
135
+ //# sourceMappingURL=authorization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../../src/app/oauth/authorization.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,yCAAoC;AAGpC,uCAA0E;AAC1E,uCAAuC;AAEvC,MAAM,MAAM,GAAG,IAAA,cAAK,EAAC,sBAAsB,CAAC,CAAA;AAyB5C;;;GAGG;AACH,MAAa,aAAa;IAGxB;;;;;OAKG;IACH,YAAa,OAAgB,EAAE,YAAmC;;QAqElE;;;;WAIG;QACH,oBAAe,GAAG,CAAC,aAAsB,EAAgB,EAAE;YACzD,IAAI,aAAa,EAAE,CAAC;gBAClB,OAAO,IAAI,CAAC,aAAc,CAAC,aAAa,CAAC,CAAA;YAC3C,CAAC;YACD,OAAO,IAAI,CAAC,aAAc,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAChE,CAAC,CAAA;QAuBD,mBAAc,GAAsF,IAAI,CAAA;QArGtG,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;QAC9D,CAAC;QACD,MAAM,SAAS,GAAG,IAAI,iBAAS,CAAC,OAAO,CAAC,CAAA;QACxC,IAAI,YAAY,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzE,MAAM,IA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;;;;OAQG;IACH,KAAK,CAAC,OAAO,CAAE,OAAoB,EAAE,KAAgB,EAAE,aAAsB;;QAC3E,MAAM,CAAC,IAAI,CAAC,4BAA4B,EAAE,aAAa,CAAC,CAAA;QACxD,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC,CAAC,KAAK;YACtC,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;gBACpC,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,IAAI,CAAA;gBACxC,MAAM,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,CAAC,OAAO,CAAC,CAAA,CAAA;YAC9B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAA,MAAA,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,IAAI,0CAAE,OAAO,CAAC,OAAO,CAAC,CAAA,CAAA;QAClE,CAAC;IACH,CAAC;IAID;;;OAGG;IACI,eAAe,CAAE,OAAiF;QACvG,IAAI,CAAC,cAAc,GAAG,OAAO,CAAA;IAC/B,CAAC;CACF;AAxHD,sCAwHC"}
@@ -4,4 +4,12 @@
4
4
  */
5
5
  import { TurnContext } from '../turnContext';
6
6
  import { TurnState } from './turnState';
7
+ /**
8
+ * A handler function for routing operations in a specific turn context and state.
9
+ *
10
+ * @typeParam TState - The type of the turn state.
11
+ * @param context - The turn context for the current operation.
12
+ * @param state - The state associated with the current turn.
13
+ * @returns A promise that resolves when the routing operation is complete.
14
+ */
7
15
  export type RouteHandler<TState extends TurnState> = (context: TurnContext, state: TState) => Promise<void>;
@@ -3,5 +3,14 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { TurnContext } from '../turnContext';
6
+ /**
7
+ * A function that determines whether a specific condition is met in the given turn context.
8
+ *
9
+ * @param context - The turn context for the current operation.
10
+ * @returns A promise that resolves to a boolean indicating whether the condition is met.
11
+ */
6
12
  export type Selector = (context: TurnContext) => Promise<boolean>;
13
+ /**
14
+ * A specialized selector for routing operations.
15
+ */
7
16
  export type RouteSelector = Selector;
@@ -7,24 +7,25 @@ import { AppMemory } from './appMemory';
7
7
  import { InputFile } from './inputFileDownloader';
8
8
  import { TurnStateEntry } from './turnStateEntry';
9
9
  import { TurnContext } from '../turnContext';
10
+ /**
11
+ * Default interface for conversation state.
12
+ * Extend this interface to define custom conversation state properties.
13
+ */
10
14
  export interface DefaultConversationState {
11
15
  }
16
+ /**
17
+ * Default interface for user state.
18
+ * Extend this interface to define custom user state properties.
19
+ */
12
20
  export interface DefaultUserState {
13
21
  }
22
+ /**
23
+ * Default interface for temporary state that persists only during the current turn.
24
+ * Contains properties used for handling user input, file attachments, and OAuth flows.
25
+ */
14
26
  export interface DefaultTempState {
15
- input: string;
27
+ /** Collection of files attached to the current message */
16
28
  inputFiles: InputFile[];
17
- lastOutput: string;
18
- actionOutputs: Record<string, string>;
19
- authTokens: {
20
- [key: string]: string;
21
- };
22
- duplicateTokenExchange?: boolean;
23
- }
24
- export interface DefaultSSOState {
25
- flowStarted: boolean;
26
- userToken: string;
27
- flowExpires: number;
28
29
  }
29
30
  /**
30
31
  * Base class defining a collection of turn state scopes.
@@ -55,31 +56,143 @@ export interface DefaultSSOState {
55
56
  * }
56
57
  * }
57
58
  * ```
59
+ * @template TConversationState - Type for conversation-scoped state
60
+ * @template TUserState - Type for user-scoped state
61
+ * @template TTempState - Type for temporary state that exists only for the current turn
62
+ * @template TSSOState - Type for Single Sign-On (SSO) state
58
63
  */
59
- export declare class TurnState<TConversationState = DefaultConversationState, TUserState = DefaultUserState, TTempState = DefaultTempState, TSSOState = DefaultSSOState> implements AppMemory {
64
+ export declare class TurnState<TConversationState = DefaultConversationState, TUserState = DefaultUserState, TTempState = DefaultTempState> implements AppMemory {
60
65
  private _scopes;
61
66
  private _isLoaded;
62
67
  private _loadingPromise?;
63
68
  private _stateNotLoadedString;
69
+ /**
70
+ * Gets the conversation-scoped state.
71
+ * This state is shared by all users in the same conversation.
72
+ * @returns The conversation state object
73
+ * @throws Error if state hasn't been loaded
74
+ */
64
75
  get conversation(): TConversationState;
76
+ /**
77
+ * Sets the conversation-scoped state.
78
+ * @param value - The new conversation state object
79
+ * @throws Error if state hasn't been loaded
80
+ */
65
81
  set conversation(value: TConversationState);
82
+ /**
83
+ * Gets whether the state has been loaded from storage
84
+ * @returns True if the state has been loaded, false otherwise
85
+ */
66
86
  get isLoaded(): boolean;
87
+ /**
88
+ * Gets the temporary state for the current turn.
89
+ * This state is not persisted between turns.
90
+ * @returns The temporary state object
91
+ * @throws Error if state hasn't been loaded
92
+ */
67
93
  get temp(): TTempState;
94
+ /**
95
+ * Sets the temporary state for the current turn.
96
+ * @param value - The new temporary state object
97
+ * @throws Error if state hasn't been loaded
98
+ */
68
99
  set temp(value: TTempState);
100
+ /**
101
+ * Gets the user-scoped state.
102
+ * This state is unique to each user and persists across conversations.
103
+ * @returns The user state object
104
+ * @throws Error if state hasn't been loaded
105
+ */
69
106
  get user(): TUserState;
107
+ /**
108
+ * Sets the user-scoped state.
109
+ * @param value - The new user state object
110
+ * @throws Error if state hasn't been loaded
111
+ */
70
112
  set user(value: TUserState);
71
- get sso(): TSSOState;
72
- set sso(value: TSSOState);
113
+ /**
114
+ * Marks the conversation state for deletion.
115
+ * The state will be deleted from storage on the next call to save().
116
+ * @throws Error if state hasn't been loaded
117
+ */
73
118
  deleteConversationState(): void;
119
+ /**
120
+ * Marks the temporary state for deletion.
121
+ * Since temporary state is not persisted, this just clears the in-memory object.
122
+ * @throws Error if state hasn't been loaded
123
+ */
74
124
  deleteTempState(): void;
125
+ /**
126
+ * Marks the user state for deletion.
127
+ * The state will be deleted from storage on the next call to save().
128
+ * @throws Error if state hasn't been loaded
129
+ */
75
130
  deleteUserState(): void;
131
+ /**
132
+ * Gets a specific state scope by name.
133
+ * @param scope - The name of the scope to retrieve
134
+ * @returns The state entry for the scope, or undefined if not found
135
+ */
76
136
  getScope(scope: string): TurnStateEntry | undefined;
137
+ /**
138
+ * Deletes a value from state by dot-notation path.
139
+ * Format: "scope.property" or just "property" (defaults to temp scope)
140
+ * @param path - The path to the value to delete
141
+ */
77
142
  deleteValue(path: string): void;
143
+ /**
144
+ * Checks if a value exists in state by dot-notation path.
145
+ * Format: "scope.property" or just "property" (defaults to temp scope)
146
+ * @param path - The path to check
147
+ * @returns True if the value exists, false otherwise
148
+ */
78
149
  hasValue(path: string): boolean;
150
+ /**
151
+ * Gets a value from state by dot-notation path.
152
+ * Format: "scope.property" or just "property" (defaults to temp scope)
153
+ * @template TValue - The type of the value to retrieve
154
+ * @param path - The path to the value
155
+ * @returns The value at the specified path
156
+ */
79
157
  getValue<TValue = unknown>(path: string): TValue;
158
+ /**
159
+ * Sets a value in state by dot-notation path.
160
+ * Format: "scope.property" or just "property" (defaults to temp scope)
161
+ * @param path - The path to set
162
+ * @param value - The value to set
163
+ */
80
164
  setValue(path: string, value: unknown): void;
165
+ /**
166
+ * Loads state from storage into memory.
167
+ * @param context - The turn context
168
+ * @param storage - Optional storage provider (if not provided, state will be in-memory only)
169
+ * @param force - If true, forces a reload from storage even if state is already loaded
170
+ * @returns Promise that resolves to true if state was loaded, false if it was already loaded
171
+ */
81
172
  load(context: TurnContext, storage?: Storage, force?: boolean): Promise<boolean>;
173
+ /**
174
+ * Saves state changes to storage.
175
+ * Only changed scopes will be persisted.
176
+ * @param context - The turn context
177
+ * @param storage - Optional storage provider (if not provided, state changes won't be persisted)
178
+ * @returns Promise that resolves when the save operation is complete
179
+ * @throws Error if state hasn't been loaded
180
+ */
82
181
  save(context: TurnContext, storage?: Storage): Promise<void>;
182
+ /**
183
+ * Computes the storage keys for each scope based on the turn context.
184
+ * Override this method in derived classes to add or modify storage keys.
185
+ * @param context - The turn context
186
+ * @returns Promise that resolves to a dictionary of scope names to storage keys
187
+ * @protected
188
+ */
83
189
  protected onComputeStorageKeys(context: TurnContext): Promise<Record<string, string>>;
190
+ /**
191
+ * Parses a dot-notation path into scope and property name.
192
+ * If no scope is specified, defaults to the temp scope.
193
+ * @param path - The path to parse (format: "scope.property" or just "property")
194
+ * @returns Object containing the scope entry and property name
195
+ * @private
196
+ */
84
197
  private getScopeAndName;
85
198
  }