@microsoft/agents-hosting 1.1.0-alpha.2 → 1.1.0-alpha.58

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 (150) hide show
  1. package/dist/package.json +10 -6
  2. package/dist/src/activityWireCompat.js +8 -3
  3. package/dist/src/activityWireCompat.js.map +1 -1
  4. package/dist/src/agent-client/agentClient.js +7 -3
  5. package/dist/src/agent-client/agentClient.js.map +1 -1
  6. package/dist/src/agent-client/agentResponseHandler.js +6 -2
  7. package/dist/src/agent-client/agentResponseHandler.js.map +1 -1
  8. package/dist/src/app/agentApplication.d.ts +26 -11
  9. package/dist/src/app/agentApplication.js +94 -86
  10. package/dist/src/app/agentApplication.js.map +1 -1
  11. package/dist/src/app/agentApplicationBuilder.d.ts +2 -2
  12. package/dist/src/app/agentApplicationBuilder.js.map +1 -1
  13. package/dist/src/app/agentApplicationOptions.d.ts +9 -2
  14. package/dist/src/app/appRoute.d.ts +7 -0
  15. package/dist/src/app/attachmentDownloader.d.ts +13 -3
  16. package/dist/src/app/attachmentDownloader.js +16 -3
  17. package/dist/src/app/attachmentDownloader.js.map +1 -1
  18. package/dist/src/app/{authorization.d.ts → auth/authorization.d.ts} +33 -139
  19. package/dist/src/app/auth/authorization.js +188 -0
  20. package/dist/src/app/auth/authorization.js.map +1 -0
  21. package/dist/src/app/auth/authorizationManager.d.ts +71 -0
  22. package/dist/src/app/auth/authorizationManager.js +170 -0
  23. package/dist/src/app/auth/authorizationManager.js.map +1 -0
  24. package/dist/src/app/auth/handlerStorage.d.ts +36 -0
  25. package/dist/src/app/auth/handlerStorage.js +62 -0
  26. package/dist/src/app/auth/handlerStorage.js.map +1 -0
  27. package/dist/src/app/auth/handlers/agenticAuthorization.d.ts +97 -0
  28. package/dist/src/app/auth/handlers/agenticAuthorization.js +145 -0
  29. package/dist/src/app/auth/handlers/agenticAuthorization.js.map +1 -0
  30. package/dist/src/app/auth/handlers/azureBotAuthorization.d.ts +222 -0
  31. package/dist/src/app/auth/handlers/azureBotAuthorization.js +428 -0
  32. package/dist/src/app/auth/handlers/azureBotAuthorization.js.map +1 -0
  33. package/dist/src/app/auth/handlers/index.d.ts +2 -0
  34. package/dist/src/app/auth/handlers/index.js +19 -0
  35. package/dist/src/app/auth/handlers/index.js.map +1 -0
  36. package/dist/src/app/auth/index.d.ts +2 -0
  37. package/dist/src/app/auth/index.js +19 -0
  38. package/dist/src/app/auth/index.js.map +1 -0
  39. package/dist/src/app/auth/types.d.ts +104 -0
  40. package/dist/src/app/auth/types.js +24 -0
  41. package/dist/src/app/auth/types.js.map +1 -0
  42. package/dist/src/app/index.d.ts +2 -3
  43. package/dist/src/app/index.js +2 -3
  44. package/dist/src/app/index.js.map +1 -1
  45. package/dist/src/app/inputFileDownloader.d.ts +10 -3
  46. package/dist/src/app/routeList.d.ts +1 -1
  47. package/dist/src/app/routeList.js +22 -5
  48. package/dist/src/app/routeList.js.map +1 -1
  49. package/dist/src/app/streaming/streamingResponse.d.ts +11 -1
  50. package/dist/src/app/streaming/streamingResponse.js +17 -2
  51. package/dist/src/app/streaming/streamingResponse.js.map +1 -1
  52. package/dist/src/app/turnState.d.ts +2 -38
  53. package/dist/src/app/turnState.js +1 -46
  54. package/dist/src/app/turnState.js.map +1 -1
  55. package/dist/src/auth/MemoryCache.d.ts +16 -0
  56. package/dist/src/auth/MemoryCache.js +58 -0
  57. package/dist/src/auth/MemoryCache.js.map +1 -0
  58. package/dist/src/auth/authConfiguration.d.ts +44 -2
  59. package/dist/src/auth/authConfiguration.js +218 -53
  60. package/dist/src/auth/authConfiguration.js.map +1 -1
  61. package/dist/src/auth/authConstants.d.ts +11 -0
  62. package/dist/src/auth/authConstants.js +15 -0
  63. package/dist/src/auth/authConstants.js.map +1 -0
  64. package/dist/src/auth/authProvider.d.ts +23 -0
  65. package/dist/src/auth/connections.d.ts +40 -0
  66. package/dist/src/auth/connections.js +7 -0
  67. package/dist/src/auth/connections.js.map +1 -0
  68. package/dist/src/auth/index.d.ts +2 -0
  69. package/dist/src/auth/index.js +2 -0
  70. package/dist/src/auth/index.js.map +1 -1
  71. package/dist/src/auth/jwt-middleware.js +31 -18
  72. package/dist/src/auth/jwt-middleware.js.map +1 -1
  73. package/dist/src/auth/msalConnectionManager.d.ts +63 -0
  74. package/dist/src/auth/msalConnectionManager.js +124 -0
  75. package/dist/src/auth/msalConnectionManager.js.map +1 -0
  76. package/dist/src/auth/msalTokenProvider.d.ts +31 -0
  77. package/dist/src/auth/msalTokenProvider.js +167 -16
  78. package/dist/src/auth/msalTokenProvider.js.map +1 -1
  79. package/dist/src/baseAdapter.d.ts +10 -25
  80. package/dist/src/baseAdapter.js +2 -15
  81. package/dist/src/baseAdapter.js.map +1 -1
  82. package/dist/src/cloudAdapter.d.ts +40 -23
  83. package/dist/src/cloudAdapter.js +132 -56
  84. package/dist/src/cloudAdapter.js.map +1 -1
  85. package/dist/src/connector-client/connectorClient.d.ts +9 -0
  86. package/dist/src/connector-client/connectorClient.js +39 -9
  87. package/dist/src/connector-client/connectorClient.js.map +1 -1
  88. package/dist/src/index.d.ts +0 -1
  89. package/dist/src/index.js +0 -1
  90. package/dist/src/index.js.map +1 -1
  91. package/dist/src/oauth/index.d.ts +0 -1
  92. package/dist/src/oauth/index.js +0 -1
  93. package/dist/src/oauth/index.js.map +1 -1
  94. package/dist/src/oauth/userTokenClient.d.ts +30 -13
  95. package/dist/src/oauth/userTokenClient.js +64 -26
  96. package/dist/src/oauth/userTokenClient.js.map +1 -1
  97. package/dist/src/oauth/userTokenClient.types.d.ts +19 -6
  98. package/dist/src/turnContext.d.ts +7 -1
  99. package/dist/src/turnContext.js +11 -4
  100. package/dist/src/turnContext.js.map +1 -1
  101. package/package.json +10 -6
  102. package/src/activityWireCompat.ts +8 -3
  103. package/src/agent-client/agentClient.ts +9 -3
  104. package/src/agent-client/agentResponseHandler.ts +5 -2
  105. package/src/app/agentApplication.ts +98 -79
  106. package/src/app/agentApplicationBuilder.ts +2 -2
  107. package/src/app/agentApplicationOptions.ts +10 -2
  108. package/src/app/appRoute.ts +8 -0
  109. package/src/app/attachmentDownloader.ts +18 -3
  110. package/src/app/auth/authorization.ts +252 -0
  111. package/src/app/auth/authorizationManager.ts +213 -0
  112. package/src/app/auth/handlerStorage.ts +61 -0
  113. package/src/app/auth/handlers/agenticAuthorization.ts +194 -0
  114. package/src/app/auth/handlers/azureBotAuthorization.ts +599 -0
  115. package/src/app/auth/handlers/index.ts +2 -0
  116. package/src/app/auth/index.ts +2 -0
  117. package/src/app/auth/types.ts +111 -0
  118. package/src/app/index.ts +2 -3
  119. package/src/app/inputFileDownloader.ts +11 -3
  120. package/src/app/routeList.ts +24 -5
  121. package/src/app/streaming/streamingResponse.ts +20 -3
  122. package/src/app/turnState.ts +2 -61
  123. package/src/auth/MemoryCache.ts +59 -0
  124. package/src/auth/authConfiguration.ts +258 -52
  125. package/src/auth/authConstants.ts +11 -0
  126. package/src/auth/authProvider.ts +31 -0
  127. package/src/auth/connections.ts +46 -0
  128. package/src/auth/index.ts +2 -0
  129. package/src/auth/jwt-middleware.ts +38 -21
  130. package/src/auth/msalConnectionManager.ts +150 -0
  131. package/src/auth/msalTokenProvider.ts +209 -9
  132. package/src/baseAdapter.ts +10 -29
  133. package/src/cloudAdapter.ts +192 -67
  134. package/src/connector-client/connectorClient.ts +49 -10
  135. package/src/index.ts +0 -1
  136. package/src/oauth/index.ts +0 -1
  137. package/src/oauth/userTokenClient.ts +79 -23
  138. package/src/oauth/userTokenClient.types.ts +20 -8
  139. package/src/turnContext.ts +16 -5
  140. package/dist/src/app/authorization.js +0 -387
  141. package/dist/src/app/authorization.js.map +0 -1
  142. package/dist/src/claimsIdentity.d.ts +0 -35
  143. package/dist/src/claimsIdentity.js +0 -43
  144. package/dist/src/claimsIdentity.js.map +0 -1
  145. package/dist/src/oauth/oAuthFlow.d.ts +0 -119
  146. package/dist/src/oauth/oAuthFlow.js +0 -316
  147. package/dist/src/oauth/oAuthFlow.js.map +0 -1
  148. package/src/app/authorization.ts +0 -432
  149. package/src/claimsIdentity.ts +0 -47
  150. package/src/oauth/oAuthFlow.ts +0 -378
@@ -2,15 +2,13 @@
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { AuthConfiguration } from './auth/authConfiguration';
6
- import { AuthProvider } from './auth/authProvider';
7
5
  import { Middleware, MiddlewareHandler, MiddlewareSet } from './middlewareSet';
8
6
  import { TurnContext } from './turnContext';
9
7
  import { Activity, ConversationReference } from '@microsoft/agents-activity';
10
8
  import { ResourceResponse } from './connector-client/resourceResponse';
11
9
  import { AttachmentData } from './connector-client/attachmentData';
12
10
  import { AttachmentInfo } from './connector-client/attachmentInfo';
13
- import { UserTokenClient } from './oauth';
11
+ import { JwtPayload } from 'jsonwebtoken';
14
12
  /**
15
13
  * Abstract base class for all adapters in the Agents framework.
16
14
  *
@@ -32,30 +30,14 @@ export declare abstract class BaseAdapter {
32
30
  */
33
31
  protected middleware: MiddlewareSet;
34
32
  private turnError;
35
- /**
36
- * Symbol key used to store agent identity information in the TurnContext.
37
- */
38
- readonly AgentIdentityKey: symbol;
39
33
  /**
40
34
  * Symbol key used to store connector client instances in the TurnContext.
41
35
  */
42
36
  readonly ConnectorClientKey: symbol;
43
37
  /**
44
- * Symbol key used to store OAuth scope information in the TurnContext.
45
- */
46
- readonly OAuthScopeKey: symbol;
47
- /**
48
- * The authentication provider used for token management.
49
- */
50
- authProvider: AuthProvider;
51
- /**
52
- * The user token client used for managing user tokens.
53
- */
54
- userTokenClient: UserTokenClient | null;
55
- /**
56
- * The authentication configuration for the adapter.
38
+ * Symbol key used to store User Token Client instances in the TurnContext.
57
39
  */
58
- abstract authConfig: AuthConfiguration;
40
+ readonly UserTokenClientKey: symbol;
59
41
  /**
60
42
  * Sends a set of activities to the conversation.
61
43
  * @param context - The TurnContext for the current turn.
@@ -83,27 +65,30 @@ export declare abstract class BaseAdapter {
83
65
  * @param logic - The logic to execute.
84
66
  * @returns A promise representing the completion of the continue operation.
85
67
  */
86
- abstract continueConversation(reference: Partial<ConversationReference>, logic: (revocableContext: TurnContext) => Promise<void>): Promise<void>;
68
+ abstract continueConversation(botAppIdOrIdentity: string | JwtPayload, reference: Partial<ConversationReference>, logic: (revocableContext: TurnContext) => Promise<void>): Promise<void>;
87
69
  /**
70
+ * @deprecated This function will not be supported in future versions. Use TurnContext.turnState.get<ConnectorClient>(CloudAdapter.ConnectorClientKey).
88
71
  * Uploads an attachment.
89
72
  * @param conversationId - The conversation ID.
90
73
  * @param attachmentData - The attachment data.
91
74
  * @returns A promise representing the ResourceResponse for the uploaded attachment.
92
75
  */
93
- abstract uploadAttachment(conversationId: string, attachmentData: AttachmentData): Promise<ResourceResponse>;
76
+ abstract uploadAttachment(context: TurnContext, conversationId: string, attachmentData: AttachmentData): Promise<ResourceResponse>;
94
77
  /**
78
+ * @deprecated This function will not be supported in future versions. Use TurnContext.turnState.get<ConnectorClient>(CloudAdapter.ConnectorClientKey).
95
79
  * Gets attachment information.
96
80
  * @param attachmentId - The attachment ID.
97
81
  * @returns A promise representing the AttachmentInfo for the requested attachment.
98
82
  */
99
- abstract getAttachmentInfo(attachmentId: string): Promise<AttachmentInfo>;
83
+ abstract getAttachmentInfo(context: TurnContext, attachmentId: string): Promise<AttachmentInfo>;
100
84
  /**
85
+ * @deprecated This function will not be supported in future versions. Use TurnContext.turnState.get<ConnectorClient>(CloudAdapter.ConnectorClientKey).
101
86
  * Gets an attachment.
102
87
  * @param attachmentId - The attachment ID.
103
88
  * @param viewId - The view ID.
104
89
  * @returns A promise representing the NodeJS.ReadableStream for the requested attachment.
105
90
  */
106
- abstract getAttachment(attachmentId: string, viewId: string): Promise<NodeJS.ReadableStream>;
91
+ abstract getAttachment(context: TurnContext, attachmentId: string, viewId: string): Promise<NodeJS.ReadableStream>;
107
92
  /**
108
93
  * Gets the error handler for the adapter.
109
94
  * @returns The current error handler function.
@@ -5,7 +5,6 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.BaseAdapter = void 0;
8
- const msalTokenProvider_1 = require("./auth/msalTokenProvider");
9
8
  const middlewareSet_1 = require("./middlewareSet");
10
9
  const logger_1 = require("@microsoft/agents-activity/logger");
11
10
  const logger = (0, logger_1.debug)('agents:base-adapter');
@@ -38,26 +37,14 @@ class BaseAdapter {
38
37
  await context.sendActivity('The agent encountered an error or bug.');
39
38
  await context.sendActivity('To continue to run this agent, please fix the source code.');
40
39
  };
41
- /**
42
- * Symbol key used to store agent identity information in the TurnContext.
43
- */
44
- this.AgentIdentityKey = Symbol('AgentIdentity');
45
40
  /**
46
41
  * Symbol key used to store connector client instances in the TurnContext.
47
42
  */
48
43
  this.ConnectorClientKey = Symbol('ConnectorClient');
49
44
  /**
50
- * Symbol key used to store OAuth scope information in the TurnContext.
51
- */
52
- this.OAuthScopeKey = Symbol('OAuthScope');
53
- /**
54
- * The authentication provider used for token management.
55
- */
56
- this.authProvider = new msalTokenProvider_1.MsalTokenProvider();
57
- /**
58
- * The user token client used for managing user tokens.
45
+ * Symbol key used to store User Token Client instances in the TurnContext.
59
46
  */
60
- this.userTokenClient = null;
47
+ this.UserTokenClientKey = Symbol('UserTokenClient');
61
48
  }
62
49
  /**
63
50
  * Gets the error handler for the adapter.
@@ -1 +1 @@
1
- {"version":3,"file":"baseAdapter.js","sourceRoot":"","sources":["../../src/baseAdapter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,gEAA4D;AAC5D,mDAA8E;AAE9E,8DAAyD;AAOzD,MAAM,MAAM,GAAG,IAAA,cAAK,EAAC,qBAAqB,CAAC,CAAA;AAE3C;;;;;;;;;;;;;;GAcG;AACH,MAAsB,WAAW;IAAjC;QACE;;WAEG;QACO,eAAU,GAAkB,IAAI,6BAAa,EAAE,CAAA;QAEjD,cAAS,GAA0D,KAAK,EAAE,OAAoB,EAAE,KAAY,EAAE,EAAE;YACtH,MAAM,CAAC,KAAK,CAAC,qCAAqC,KAAK,E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2EAA2E;QAC7E,CAAC;IACH,CAAC;CACF;AAxLD,kCAwLC"}
@@ -10,6 +10,7 @@ import { Request } from './auth/request';
10
10
  import { ConnectorClient } from './connector-client/connectorClient';
11
11
  import { AuthConfiguration } from './auth/authConfiguration';
12
12
  import { AuthProvider } from './auth/authProvider';
13
+ import { MsalConnectionManager } from './auth/msalConnectionManager';
13
14
  import { Activity, ConversationReference, ConversationParameters } from '@microsoft/agents-activity';
14
15
  import { ResourceResponse } from './connector-client/resourceResponse';
15
16
  import { InvokeResponse } from './invoke/invokeResponse';
@@ -17,25 +18,25 @@ import { AttachmentInfo } from './connector-client/attachmentInfo';
17
18
  import { AttachmentData } from './connector-client/attachmentData';
18
19
  import { UserTokenClient } from './oauth';
19
20
  import { HeaderPropagationCollection, HeaderPropagationDefinition } from './headerPropagation';
21
+ import { JwtPayload } from 'jsonwebtoken';
20
22
  /**
21
23
  * Adapter for handling agent interactions with various channels through cloud-based services.
22
24
  *
23
25
  * @remarks
24
- * CloudAdapter processes incoming HTTP requests from Microsoft Bot Framework channels,
26
+ * CloudAdapter processes incoming HTTP requests from Azure Bot Service channels,
25
27
  * authenticates them, and generates outgoing responses. It manages the communication
26
28
  * flow between agents and users across different channels, handling activities, attachments,
27
29
  * and conversation continuations.
28
30
  */
29
31
  export declare class CloudAdapter extends BaseAdapter {
30
32
  /**
31
- * Client for connecting to the Bot Framework Connector service
33
+ * Client for connecting to the Azure Bot Service
32
34
  */
33
- connectorClient: ConnectorClient;
34
- authConfig: AuthConfiguration;
35
+ connectionManager: MsalConnectionManager;
35
36
  /**
36
37
  * Creates an instance of CloudAdapter.
37
38
  * @param authConfig - The authentication configuration for securing communications
38
- * @param authProvider - Optional custom authentication provider. If not specified, a default MsalTokenProvider will be used
39
+ * @param authProvider - No longer used
39
40
  */
40
41
  constructor(authConfig?: AuthConfiguration, authProvider?: AuthProvider, userTokenClient?: UserTokenClient);
41
42
  /**
@@ -57,22 +58,41 @@ export declare class CloudAdapter extends BaseAdapter {
57
58
  * @returns A promise that resolves to a ConnectorClient instance
58
59
  * @protected
59
60
  */
60
- protected createConnectorClient(serviceUrl: string, scope: string, headers?: HeaderPropagationCollection): Promise<ConnectorClient>;
61
+ protected createConnectorClient(serviceUrl: string, scope: string, audience: string, headers?: HeaderPropagationCollection): Promise<ConnectorClient>;
62
+ protected createConnectorClientWithIdentity(identity: JwtPayload, activity: Activity, scope: string, headers?: HeaderPropagationCollection): Promise<ConnectorClient>;
63
+ static createIdentity(appId: string): JwtPayload;
61
64
  /**
62
65
  * Sets the connector client on the turn context.
63
66
  *
64
67
  * @param context - The current turn context
65
68
  * @protected
66
69
  */
67
- protected setConnectorClient(context: TurnContext): void;
70
+ protected setConnectorClient(context: TurnContext, connectorClient?: ConnectorClient): void;
68
71
  /**
72
+ * Creates a user token client for a specific service URL and scope.
73
+ *
74
+ * @param serviceUrl - The URL of the service to connect to
75
+ * @param scope - The authentication scope to use
76
+ * @param headers - Optional headers to propagate in the request
77
+ * @returns A promise that resolves to a ConnectorClient instance
78
+ * @protected
79
+ */
80
+ protected createUserTokenClient(tokenServiceEndpoint?: string, scope?: string, audience?: string, headers?: HeaderPropagationCollection): Promise<UserTokenClient>;
81
+ /**
82
+ * Sets the user token client on the turn context.
83
+ *
84
+ * @param context - The current turn context
85
+ * @protected
86
+ */
87
+ protected setUserTokenClient(context: TurnContext, userTokenClient?: UserTokenClient): void;
88
+ /**
89
+ * @deprecated This function will not be supported in future versions. Create TurnContext directly.
69
90
  * Creates a TurnContext for the given activity and logic.
70
91
  * @param activity - The activity to process.
71
92
  * @param logic - The logic to execute.
72
93
  * @returns The created TurnContext.
73
94
  */
74
- createTurnContext(activity: Activity, logic: AgentHandler): TurnContext;
75
- createTurnContextWithScope(activity: Activity, logic: AgentHandler, scope: string): Promise<TurnContext>;
95
+ createTurnContext(activity: Activity, logic: AgentHandler, identity?: JwtPayload): TurnContext;
76
96
  /**
77
97
  * Sends multiple activities to the conversation.
78
98
  * @param context - The TurnContext for the current turn.
@@ -80,12 +100,6 @@ export declare class CloudAdapter extends BaseAdapter {
80
100
  * @returns A promise representing the array of ResourceResponses for the sent activities.
81
101
  */
82
102
  sendActivities(context: TurnContext, activities: Activity[]): Promise<ResourceResponse[]>;
83
- /**
84
- * Replies to an activity.
85
- * @param activity - The activity to reply to.
86
- * @returns A promise representing the ResourceResponse for the sent activity.
87
- */
88
- replyToActivity(activity: Activity): Promise<ResourceResponse>;
89
103
  /**
90
104
  * Processes an incoming request and sends the response.
91
105
  * @param request - The incoming request.
@@ -115,12 +129,12 @@ export declare class CloudAdapter extends BaseAdapter {
115
129
  * @param logic - The logic to execute.
116
130
  * @returns A promise representing the completion of the continue operation.
117
131
  */
118
- continueConversation(reference: ConversationReference, logic: (revocableContext: TurnContext) => Promise<void>, isResponse?: Boolean): Promise<void>;
132
+ continueConversation(botAppIdOrIdentity: string | JwtPayload, reference: ConversationReference, logic: (revocableContext: TurnContext) => Promise<void>, isResponse?: Boolean): Promise<void>;
119
133
  /**
120
- * Processes the turn results and returns an InvokeResponse if applicable.
121
- * @param context - The TurnContext for the current turn.
122
- * @returns The InvokeResponse if applicable, otherwise undefined.
123
- */
134
+ * Processes the turn results and returns an InvokeResponse if applicable.
135
+ * @param context - The TurnContext for the current turn.
136
+ * @returns The InvokeResponse if applicable, otherwise undefined.
137
+ */
124
138
  protected processTurnResults(context: TurnContext): InvokeResponse | undefined;
125
139
  /**
126
140
  * Creates an activity to represent the result of creating a conversation.
@@ -143,23 +157,26 @@ export declare class CloudAdapter extends BaseAdapter {
143
157
  */
144
158
  createConversationAsync(agentAppId: string, channelId: string, serviceUrl: string, audience: string, conversationParameters: ConversationParameters, logic: (context: TurnContext) => Promise<void>): Promise<void>;
145
159
  /**
160
+ * @deprecated This function will not be supported in future versions. Use TurnContext.turnState.get<ConnectorClient>(CloudAdapter.ConnectorClientKey).
146
161
  * Uploads an attachment.
147
162
  * @param conversationId - The conversation ID.
148
163
  * @param attachmentData - The attachment data.
149
164
  * @returns A promise representing the ResourceResponse for the uploaded attachment.
150
165
  */
151
- uploadAttachment(conversationId: string, attachmentData: AttachmentData): Promise<ResourceResponse>;
166
+ uploadAttachment(context: TurnContext, conversationId: string, attachmentData: AttachmentData): Promise<ResourceResponse>;
152
167
  /**
168
+ * @deprecated This function will not be supported in future versions. Use TurnContext.turnState.get<ConnectorClient>(CloudAdapter.ConnectorClientKey).
153
169
  * Gets attachment information.
154
170
  * @param attachmentId - The attachment ID.
155
171
  * @returns A promise representing the AttachmentInfo for the requested attachment.
156
172
  */
157
- getAttachmentInfo(attachmentId: string): Promise<AttachmentInfo>;
173
+ getAttachmentInfo(context: TurnContext, attachmentId: string): Promise<AttachmentInfo>;
158
174
  /**
175
+ * @deprecated This function will not be supported in future versions. Use TurnContext.turnState.get<ConnectorClient>(CloudAdapter.ConnectorClientKey).
159
176
  * Gets an attachment.
160
177
  * @param attachmentId - The attachment ID.
161
178
  * @param viewId - The view ID.
162
179
  * @returns A promise representing the NodeJS.ReadableStream for the requested attachment.
163
180
  */
164
- getAttachment(attachmentId: string, viewId: string): Promise<NodeJS.ReadableStream>;
181
+ getAttachment(context: TurnContext, attachmentId: string, viewId: string): Promise<NodeJS.ReadableStream>;
165
182
  }
@@ -43,8 +43,9 @@ const baseAdapter_1 = require("./baseAdapter");
43
43
  const turnContext_1 = require("./turnContext");
44
44
  const connectorClient_1 = require("./connector-client/connectorClient");
45
45
  const authConfiguration_1 = require("./auth/authConfiguration");
46
+ const authConstants_1 = require("./auth/authConstants");
47
+ const msalConnectionManager_1 = require("./auth/msalConnectionManager");
46
48
  const agents_activity_1 = require("@microsoft/agents-activity");
47
- const msalTokenProvider_1 = require("./auth/msalTokenProvider");
48
49
  const uuid = __importStar(require("uuid"));
49
50
  const logger_1 = require("@microsoft/agents-activity/logger");
50
51
  const statusCodes_1 = require("./statusCodes");
@@ -56,7 +57,7 @@ const logger = (0, logger_1.debug)('agents:cloud-adapter');
56
57
  * Adapter for handling agent interactions with various channels through cloud-based services.
57
58
  *
58
59
  * @remarks
59
- * CloudAdapter processes incoming HTTP requests from Microsoft Bot Framework channels,
60
+ * CloudAdapter processes incoming HTTP requests from Azure Bot Service channels,
60
61
  * authenticates them, and generates outgoing responses. It manages the communication
61
62
  * flow between agents and users across different channels, handling activities, attachments,
62
63
  * and conversation continuations.
@@ -65,13 +66,12 @@ class CloudAdapter extends baseAdapter_1.BaseAdapter {
65
66
  /**
66
67
  * Creates an instance of CloudAdapter.
67
68
  * @param authConfig - The authentication configuration for securing communications
68
- * @param authProvider - Optional custom authentication provider. If not specified, a default MsalTokenProvider will be used
69
+ * @param authProvider - No longer used
69
70
  */
70
71
  constructor(authConfig, authProvider, userTokenClient) {
71
72
  super();
72
- this.authConfig = authConfig !== null && authConfig !== void 0 ? authConfig : (0, authConfiguration_1.loadAuthConfigFromEnv)();
73
- this.authProvider = authProvider !== null && authProvider !== void 0 ? authProvider : new msalTokenProvider_1.MsalTokenProvider();
74
- this.userTokenClient = userTokenClient !== null && userTokenClient !== void 0 ? userTokenClient : new oauth_1.UserTokenClient(this.authConfig.clientId);
73
+ authConfig = (0, authConfiguration_1.getAuthConfigWithDefaults)(authConfig);
74
+ this.connectionManager = new msalConnectionManager_1.MsalConnectionManager(undefined, undefined, authConfig);
75
75
  }
76
76
  /**
77
77
  * Determines whether a connector client is needed based on the delivery mode and service URL of the given activity.
@@ -107,8 +107,53 @@ class CloudAdapter extends baseAdapter_1.BaseAdapter {
107
107
  * @returns A promise that resolves to a ConnectorClient instance
108
108
  * @protected
109
109
  */
110
- async createConnectorClient(serviceUrl, scope, headers) {
111
- return connectorClient_1.ConnectorClient.createClientWithAuth(serviceUrl, this.authConfig, this.authProvider, scope, headers);
110
+ async createConnectorClient(serviceUrl, scope, audience, headers) {
111
+ // get the correct token provider
112
+ const tokenProvider = this.connectionManager.getTokenProvider(audience, serviceUrl);
113
+ const token = await tokenProvider.getAccessToken(scope);
114
+ return connectorClient_1.ConnectorClient.createClientWithToken(serviceUrl, token, headers);
115
+ }
116
+ async createConnectorClientWithIdentity(identity, activity, scope, headers) {
117
+ var _a, _b, _c, _d, _e, _f, _g, _h;
118
+ let audience;
119
+ if (Array.isArray(identity.aud)) {
120
+ audience = identity.aud[0];
121
+ }
122
+ else {
123
+ audience = identity.aud;
124
+ }
125
+ if (!audience) {
126
+ // anonymous
127
+ return connectorClient_1.ConnectorClient.createClientWithToken(activity.serviceUrl, null, headers);
128
+ }
129
+ let connectorClient;
130
+ const tokenProvider = this.connectionManager.getTokenProvider(audience, (_a = activity.serviceUrl) !== null && _a !== void 0 ? _a : '');
131
+ if (activity.isAgenticRequest()) {
132
+ logger.debug('Activity is from an agentic source, using special scope', activity.recipient);
133
+ if (((_b = activity.recipient) === null || _b === void 0 ? void 0 : _b.role) === agents_activity_1.RoleTypes.AgenticIdentity && activity.getAgenticInstanceId()) {
134
+ // get agentic instance token
135
+ const token = await tokenProvider.getAgenticInstanceToken((_c = activity.getAgenticInstanceId()) !== null && _c !== void 0 ? _c : '');
136
+ connectorClient = connectorClient_1.ConnectorClient.createClientWithToken(activity.serviceUrl, token, headers);
137
+ }
138
+ else if (((_d = activity.recipient) === null || _d === void 0 ? void 0 : _d.role) === agents_activity_1.RoleTypes.AgenticUser && activity.getAgenticInstanceId() && activity.getAgenticUser()) {
139
+ const scope = (_f = (_e = tokenProvider.connectionSettings) === null || _e === void 0 ? void 0 : _e.scope) !== null && _f !== void 0 ? _f : authConstants_1.ApxProductionScope;
140
+ const token = await tokenProvider.getAgenticUserToken((_g = activity.getAgenticInstanceId()) !== null && _g !== void 0 ? _g : '', (_h = activity.getAgenticUser()) !== null && _h !== void 0 ? _h : '', [scope]);
141
+ connectorClient = connectorClient_1.ConnectorClient.createClientWithToken(activity.serviceUrl, token, headers);
142
+ }
143
+ else {
144
+ throw new Error('Could not create connector client for agentic user');
145
+ }
146
+ }
147
+ else {
148
+ const token = await tokenProvider.getAccessToken(scope);
149
+ connectorClient = connectorClient_1.ConnectorClient.createClientWithToken(activity.serviceUrl, token, headers);
150
+ }
151
+ return connectorClient;
152
+ }
153
+ static createIdentity(appId) {
154
+ return {
155
+ aud: appId
156
+ };
112
157
  }
113
158
  /**
114
159
  * Sets the connector client on the turn context.
@@ -116,21 +161,41 @@ class CloudAdapter extends baseAdapter_1.BaseAdapter {
116
161
  * @param context - The current turn context
117
162
  * @protected
118
163
  */
119
- setConnectorClient(context) {
120
- context.turnState.set('connectorClient', this.connectorClient);
164
+ setConnectorClient(context, connectorClient) {
165
+ context.turnState.set(this.ConnectorClientKey, connectorClient);
166
+ }
167
+ /**
168
+ * Creates a user token client for a specific service URL and scope.
169
+ *
170
+ * @param serviceUrl - The URL of the service to connect to
171
+ * @param scope - The authentication scope to use
172
+ * @param headers - Optional headers to propagate in the request
173
+ * @returns A promise that resolves to a ConnectorClient instance
174
+ * @protected
175
+ */
176
+ async createUserTokenClient(tokenServiceEndpoint = 'https://api.botframework.com', scope = 'https://api.botframework.com', audience = 'https://api.botframework.com', headers) {
177
+ // get the correct token provider
178
+ const tokenProvider = this.connectionManager.getTokenProvider(audience, tokenServiceEndpoint);
179
+ return oauth_1.UserTokenClient.createClientWithScope(tokenServiceEndpoint, tokenProvider, scope, headers);
180
+ }
181
+ /**
182
+ * Sets the user token client on the turn context.
183
+ *
184
+ * @param context - The current turn context
185
+ * @protected
186
+ */
187
+ setUserTokenClient(context, userTokenClient) {
188
+ context.turnState.set(this.UserTokenClientKey, userTokenClient);
121
189
  }
122
190
  /**
191
+ * @deprecated This function will not be supported in future versions. Create TurnContext directly.
123
192
  * Creates a TurnContext for the given activity and logic.
124
193
  * @param activity - The activity to process.
125
194
  * @param logic - The logic to execute.
126
195
  * @returns The created TurnContext.
127
196
  */
128
- createTurnContext(activity, logic) {
129
- return new turnContext_1.TurnContext(this, activity);
130
- }
131
- async createTurnContextWithScope(activity, logic, scope) {
132
- this.connectorClient = await connectorClient_1.ConnectorClient.createClientWithAuth(activity.serviceUrl, this.authConfig, this.authProvider, scope);
133
- return new turnContext_1.TurnContext(this, activity);
197
+ createTurnContext(activity, logic, identity) {
198
+ return new turnContext_1.TurnContext(this, activity, identity);
134
199
  }
135
200
  /**
136
201
  * Sends multiple activities to the conversation.
@@ -166,12 +231,11 @@ class CloudAdapter extends baseAdapter_1.BaseAdapter {
166
231
  if (!activity.serviceUrl || (activity.conversation == null) || !activity.conversation.id) {
167
232
  throw new Error('Invalid activity object');
168
233
  }
169
- this.connectorClient = await this.createConnectorClient(activity.serviceUrl, 'https://api.botframework.com');
170
234
  if (activity.replyToId) {
171
- response = await this.connectorClient.replyToActivity(activity.conversation.id, activity.replyToId, activity);
235
+ response = await context.turnState.get(this.ConnectorClientKey).replyToActivity(activity.conversation.id, activity.replyToId, activity);
172
236
  }
173
237
  else {
174
- response = await this.connectorClient.sendToConversation(activity.conversation.id, activity);
238
+ response = await context.turnState.get(this.ConnectorClientKey).sendToConversation(activity.conversation.id, activity);
175
239
  }
176
240
  }
177
241
  if (!response) {
@@ -181,17 +245,6 @@ class CloudAdapter extends baseAdapter_1.BaseAdapter {
181
245
  }
182
246
  return responses;
183
247
  }
184
- /**
185
- * Replies to an activity.
186
- * @param activity - The activity to reply to.
187
- * @returns A promise representing the ResourceResponse for the sent activity.
188
- */
189
- async replyToActivity(activity) {
190
- if (!activity.serviceUrl || (activity.conversation == null) || !activity.conversation.id || !activity.id) {
191
- throw new Error('Invalid activity object');
192
- }
193
- return await this.connectorClient.replyToActivity(activity.conversation.id, activity.id, activity);
194
- }
195
248
  /**
196
249
  * Processes an incoming request and sends the response.
197
250
  * @param request - The incoming request.
@@ -226,13 +279,16 @@ class CloudAdapter extends baseAdapter_1.BaseAdapter {
226
279
  return end(statusCodes_1.StatusCodes.BAD_REQUEST);
227
280
  }
228
281
  logger.debug('Received activity: ', activity);
229
- const context = this.createTurnContext(activity, logic);
282
+ const context = new turnContext_1.TurnContext(this, activity, request.user);
230
283
  const scope = (_d = (_b = (_a = request.user) === null || _a === void 0 ? void 0 : _a.azp) !== null && _b !== void 0 ? _b : (_c = request.user) === null || _c === void 0 ? void 0 : _c.appid) !== null && _d !== void 0 ? _d : 'https://api.botframework.com';
231
284
  // if Delivery Mode == ExpectReplies, we don't need a connector client.
232
285
  if (this.resolveIfConnectorClientIsNeeded(activity)) {
233
- logger.debug('Creating connector client with scope: ', scope);
234
- this.connectorClient = await this.createConnectorClient(activity.serviceUrl, scope, headers);
235
- this.setConnectorClient(context);
286
+ const connectorClient = await this.createConnectorClientWithIdentity(request.user, activity, scope, headers);
287
+ this.setConnectorClient(context, connectorClient);
288
+ }
289
+ if (!activity.isAgenticRequest()) {
290
+ const userTokenClient = await this.createUserTokenClient();
291
+ this.setUserTokenClient(context, userTokenClient);
236
292
  }
237
293
  if ((activity === null || activity === void 0 ? void 0 : activity.type) === agents_activity_1.ActivityTypes.InvokeResponse ||
238
294
  (activity === null || activity === void 0 ? void 0 : activity.type) === agents_activity_1.ActivityTypes.Invoke ||
@@ -278,7 +334,7 @@ class CloudAdapter extends baseAdapter_1.BaseAdapter {
278
334
  if (!activity.serviceUrl || (activity.conversation == null) || !activity.conversation.id || !activity.id) {
279
335
  throw new Error('Invalid activity object');
280
336
  }
281
- const response = await this.connectorClient.updateActivity(activity.conversation.id, activity.id, activity);
337
+ const response = await context.turnState.get(this.ConnectorClientKey).updateActivity(activity.conversation.id, activity.id, activity);
282
338
  return response.id ? { id: response.id } : undefined;
283
339
  }
284
340
  /**
@@ -294,7 +350,7 @@ class CloudAdapter extends baseAdapter_1.BaseAdapter {
294
350
  if (!reference || !reference.serviceUrl || (reference.conversation == null) || !reference.conversation.id || !reference.activityId) {
295
351
  throw new Error('Invalid conversation reference object');
296
352
  }
297
- await this.connectorClient.deleteActivity(reference.conversation.id, reference.activityId);
353
+ await context.turnState.get(this.ConnectorClientKey).deleteActivity(reference.conversation.id, reference.activityId);
298
354
  }
299
355
  /**
300
356
  * Continues a conversation.
@@ -302,24 +358,29 @@ class CloudAdapter extends baseAdapter_1.BaseAdapter {
302
358
  * @param logic - The logic to execute.
303
359
  * @returns A promise representing the completion of the continue operation.
304
360
  */
305
- async continueConversation(reference, logic, isResponse = false) {
361
+ async continueConversation(botAppIdOrIdentity, reference, logic, isResponse = false) {
362
+ var _a, _b;
306
363
  if (!reference || !reference.serviceUrl || (reference.conversation == null) || !reference.conversation.id) {
307
364
  throw new Error('Invalid conversation reference object');
308
365
  }
309
- let context;
310
- if (isResponse) {
311
- context = await this.createTurnContextWithScope(agents_activity_1.Activity.getContinuationActivity(reference), logic, 'https://api.botframework.com');
312
- }
313
- else {
314
- context = this.createTurnContext(agents_activity_1.Activity.getContinuationActivity(reference), logic);
315
- }
366
+ const botAppId = typeof botAppIdOrIdentity === 'string' ? botAppIdOrIdentity : botAppIdOrIdentity.aud;
367
+ const identity = typeof botAppIdOrIdentity !== 'string'
368
+ ? botAppIdOrIdentity
369
+ : CloudAdapter.createIdentity(botAppId);
370
+ const continuationActivity = agents_activity_1.Activity.getContinuationActivity(reference);
371
+ const context = new turnContext_1.TurnContext(this, agents_activity_1.Activity.getContinuationActivity(reference), identity);
372
+ const scope = (_b = (_a = identity.azp) !== null && _a !== void 0 ? _a : identity.appid) !== null && _b !== void 0 ? _b : 'https://api.botframework.com';
373
+ const connectorClient = await this.createConnectorClientWithIdentity(identity, continuationActivity, scope);
374
+ this.setConnectorClient(context, connectorClient);
375
+ const userTokenClient = await this.createUserTokenClient();
376
+ this.setUserTokenClient(context, userTokenClient);
316
377
  await this.runMiddleware(context, logic);
317
378
  }
318
379
  /**
319
- * Processes the turn results and returns an InvokeResponse if applicable.
320
- * @param context - The TurnContext for the current turn.
321
- * @returns The InvokeResponse if applicable, otherwise undefined.
322
- */
380
+ * Processes the turn results and returns an InvokeResponse if applicable.
381
+ * @param context - The TurnContext for the current turn.
382
+ * @returns The InvokeResponse if applicable, otherwise undefined.
383
+ */
323
384
  processTurnResults(context) {
324
385
  logger.info('<--Sending back turn results');
325
386
  // Handle ExpectedReplies scenarios where all activities have been buffered and sent back at once in an invoke response.
@@ -386,52 +447,67 @@ class CloudAdapter extends baseAdapter_1.BaseAdapter {
386
447
  throw new TypeError('`conversationParameters` must be defined');
387
448
  if (!logic)
388
449
  throw new TypeError('`logic` must be defined');
389
- const restClient = await this.createConnectorClient(serviceUrl, audience);
450
+ const restClient = await this.createConnectorClient(serviceUrl, audience, audience);
451
+ const userTokenClient = await this.createUserTokenClient();
390
452
  const createConversationResult = await restClient.createConversation(conversationParameters);
391
453
  const createActivity = this.createCreateActivity(createConversationResult.id, channelId, serviceUrl, conversationParameters);
392
- const context = new turnContext_1.TurnContext(this, createActivity);
454
+ const context = new turnContext_1.TurnContext(this, createActivity, CloudAdapter.createIdentity(agentAppId));
455
+ this.setConnectorClient(context, restClient);
456
+ this.setUserTokenClient(context, userTokenClient);
393
457
  await this.runMiddleware(context, logic);
394
458
  }
395
459
  /**
460
+ * @deprecated This function will not be supported in future versions. Use TurnContext.turnState.get<ConnectorClient>(CloudAdapter.ConnectorClientKey).
396
461
  * Uploads an attachment.
397
462
  * @param conversationId - The conversation ID.
398
463
  * @param attachmentData - The attachment data.
399
464
  * @returns A promise representing the ResourceResponse for the uploaded attachment.
400
465
  */
401
- async uploadAttachment(conversationId, attachmentData) {
466
+ async uploadAttachment(context, conversationId, attachmentData) {
467
+ if (context === undefined) {
468
+ throw new Error('context is required');
469
+ }
402
470
  if (conversationId === undefined) {
403
471
  throw new Error('conversationId is required');
404
472
  }
405
473
  if (attachmentData === undefined) {
406
474
  throw new Error('attachmentData is required');
407
475
  }
408
- return await this.connectorClient.uploadAttachment(conversationId, attachmentData);
476
+ return await context.turnState.get(this.ConnectorClientKey).uploadAttachment(conversationId, attachmentData);
409
477
  }
410
478
  /**
479
+ * @deprecated This function will not be supported in future versions. Use TurnContext.turnState.get<ConnectorClient>(CloudAdapter.ConnectorClientKey).
411
480
  * Gets attachment information.
412
481
  * @param attachmentId - The attachment ID.
413
482
  * @returns A promise representing the AttachmentInfo for the requested attachment.
414
483
  */
415
- async getAttachmentInfo(attachmentId) {
484
+ async getAttachmentInfo(context, attachmentId) {
485
+ if (context === undefined) {
486
+ throw new Error('context is required');
487
+ }
416
488
  if (attachmentId === undefined) {
417
489
  throw new Error('attachmentId is required');
418
490
  }
419
- return await this.connectorClient.getAttachmentInfo(attachmentId);
491
+ return await context.turnState.get(this.ConnectorClientKey).getAttachmentInfo(attachmentId);
420
492
  }
421
493
  /**
494
+ * @deprecated This function will not be supported in future versions. Use TurnContext.turnState.get<ConnectorClient>(CloudAdapter.ConnectorClientKey).
422
495
  * Gets an attachment.
423
496
  * @param attachmentId - The attachment ID.
424
497
  * @param viewId - The view ID.
425
498
  * @returns A promise representing the NodeJS.ReadableStream for the requested attachment.
426
499
  */
427
- async getAttachment(attachmentId, viewId) {
500
+ async getAttachment(context, attachmentId, viewId) {
501
+ if (context === undefined) {
502
+ throw new Error('context is required');
503
+ }
428
504
  if (attachmentId === undefined) {
429
505
  throw new Error('attachmentId is required');
430
506
  }
431
507
  if (viewId === undefined) {
432
508
  throw new Error('viewId is required');
433
509
  }
434
- return await this.connectorClient.getAttachment(attachmentId, viewId);
510
+ return await context.turnState.get(this.ConnectorClientKey).getAttachment(attachmentId, viewId);
435
511
  }
436
512
  }
437
513
  exports.CloudAdapter = CloudAdapter;