@microsoft/agents-hosting 0.4.3 → 0.5.1-g2e246ff274

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 (75) hide show
  1. package/dist/src/activityWireCompat.js +1 -1
  2. package/dist/src/activityWireCompat.js.map +1 -1
  3. package/dist/src/app/adaptiveCards/activityValueParsers.d.ts +115 -0
  4. package/dist/src/app/adaptiveCards/activityValueParsers.js +224 -0
  5. package/dist/src/app/adaptiveCards/activityValueParsers.js.map +1 -0
  6. package/dist/src/app/adaptiveCards/adaptiveCardActionExecuteResponseType.d.ts +21 -0
  7. package/dist/src/app/adaptiveCards/adaptiveCardActionExecuteResponseType.js +26 -0
  8. package/dist/src/app/adaptiveCards/adaptiveCardActionExecuteResponseType.js.map +1 -0
  9. package/dist/src/app/adaptiveCards/adaptiveCardsActions.d.ts +57 -0
  10. package/dist/src/app/adaptiveCards/adaptiveCardsActions.js +272 -0
  11. package/dist/src/app/adaptiveCards/adaptiveCardsActions.js.map +1 -0
  12. package/dist/src/app/adaptiveCards/adaptiveCardsOptions.d.ts +20 -0
  13. package/dist/src/app/adaptiveCards/adaptiveCardsOptions.js +7 -0
  14. package/dist/src/app/adaptiveCards/adaptiveCardsOptions.js.map +1 -0
  15. package/dist/src/app/adaptiveCards/adaptiveCardsSearchParams.d.ts +31 -0
  16. package/dist/src/app/adaptiveCards/adaptiveCardsSearchParams.js +16 -0
  17. package/dist/src/app/adaptiveCards/adaptiveCardsSearchParams.js.map +1 -0
  18. package/dist/src/app/adaptiveCards/index.d.ts +3 -0
  19. package/dist/src/app/adaptiveCards/index.js +20 -0
  20. package/dist/src/app/adaptiveCards/index.js.map +1 -0
  21. package/dist/src/app/adaptiveCards/query.d.ts +22 -0
  22. package/dist/src/app/adaptiveCards/query.js +7 -0
  23. package/dist/src/app/adaptiveCards/query.js.map +1 -0
  24. package/dist/src/app/agentApplication.d.ts +56 -8
  25. package/dist/src/app/agentApplication.js +88 -11
  26. package/dist/src/app/agentApplication.js.map +1 -1
  27. package/dist/src/app/agentApplicationBuilder.d.ts +2 -2
  28. package/dist/src/app/agentApplicationBuilder.js.map +1 -1
  29. package/dist/src/app/agentApplicationOptions.d.ts +17 -2
  30. package/dist/src/app/appRoute.d.ts +5 -0
  31. package/dist/src/app/attachmentDownloader.js +1 -0
  32. package/dist/src/app/attachmentDownloader.js.map +1 -1
  33. package/dist/src/app/extensions.d.ts +9 -0
  34. package/dist/src/app/extensions.js +16 -0
  35. package/dist/src/app/extensions.js.map +1 -0
  36. package/dist/src/app/index.d.ts +2 -0
  37. package/dist/src/app/index.js +2 -0
  38. package/dist/src/app/index.js.map +1 -1
  39. package/dist/src/auth/jwt-middleware.js +1 -0
  40. package/dist/src/auth/jwt-middleware.js.map +1 -1
  41. package/dist/src/baseAdapter.js +1 -1
  42. package/dist/src/baseAdapter.js.map +1 -1
  43. package/dist/src/cards/adaptiveCard.d.ts +15 -0
  44. package/dist/src/cards/adaptiveCard.js +7 -0
  45. package/dist/src/cards/adaptiveCard.js.map +1 -0
  46. package/dist/src/cards/index.d.ts +1 -0
  47. package/dist/src/cards/index.js +1 -0
  48. package/dist/src/cards/index.js.map +1 -1
  49. package/dist/src/cloudAdapter.js +6 -7
  50. package/dist/src/cloudAdapter.js.map +1 -1
  51. package/dist/src/connector-client/connectorClient.d.ts +6 -4
  52. package/dist/src/connector-client/connectorClient.js +34 -17
  53. package/dist/src/connector-client/connectorClient.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/activityWireCompat.ts +1 -1
  56. package/src/app/adaptiveCards/activityValueParsers.ts +249 -0
  57. package/src/app/adaptiveCards/adaptiveCardActionExecuteResponseType.ts +24 -0
  58. package/src/app/adaptiveCards/adaptiveCardsActions.ts +320 -0
  59. package/src/app/adaptiveCards/adaptiveCardsOptions.ts +23 -0
  60. package/src/app/adaptiveCards/adaptiveCardsSearchParams.ts +28 -0
  61. package/src/app/adaptiveCards/index.ts +3 -0
  62. package/src/app/adaptiveCards/query.ts +25 -0
  63. package/src/app/agentApplication.ts +109 -29
  64. package/src/app/agentApplicationBuilder.ts +2 -2
  65. package/src/app/agentApplicationOptions.ts +20 -2
  66. package/src/app/appRoute.ts +6 -0
  67. package/src/app/attachmentDownloader.ts +1 -0
  68. package/src/app/extensions.ts +19 -0
  69. package/src/app/index.ts +2 -0
  70. package/src/auth/jwt-middleware.ts +1 -1
  71. package/src/baseAdapter.ts +2 -2
  72. package/src/cards/adaptiveCard.ts +16 -0
  73. package/src/cards/index.ts +1 -0
  74. package/src/cloudAdapter.ts +5 -7
  75. package/src/connector-client/connectorClient.ts +38 -19
@@ -17,4 +17,10 @@ export interface AppRoute<TState extends TurnState> {
17
17
  * The handler function that processes the activity if the selector matches.
18
18
  */
19
19
  handler: RouteHandler<TState>;
20
+
21
+ /**
22
+ * Indicates whether this route is an invoke route.
23
+ * Invoke routes are used for specific types of activities, such as messaging extensions.
24
+ */
25
+ isInvokeRoute?: boolean;
20
26
  }
@@ -46,6 +46,7 @@ export class AttachmentDownloader<TState extends TurnState = TurnState> implemen
46
46
  return Promise.resolve([])
47
47
  }
48
48
 
49
+ // TODO: from adapter
49
50
  const authProvider: AuthProvider = new MsalTokenProvider()
50
51
 
51
52
  const accessToken = await authProvider.getAccessToken(loadAuthConfigFromEnv(), 'https://api.botframework.com')
@@ -0,0 +1,19 @@
1
+ import { TurnContext } from '../turnContext'
2
+ import { AgentApplication } from './agentApplication'
3
+ import { RouteHandler } from './routeHandler'
4
+ import { RouteSelector } from './routeSelector'
5
+ import { TurnState } from './turnState'
6
+
7
+ export class AgentExtension<TState extends TurnState> {
8
+ channelId: string
9
+ constructor (channelId: string) {
10
+ this.channelId = channelId
11
+ }
12
+
13
+ addRoute (app: AgentApplication<TState>, routeSelector: RouteSelector, routeHandler: RouteHandler<TurnState>, isInvokeRoute: boolean = false) {
14
+ const ensureChannelMatches = async (context: TurnContext) => {
15
+ return context.activity.channelId === this.channelId && routeSelector(context)
16
+ }
17
+ app.addRoute(ensureChannelMatches, routeHandler)
18
+ }
19
+ }
package/src/app/index.ts CHANGED
@@ -12,3 +12,5 @@ export * from './turnEvents'
12
12
  export * from './turnStateEntry'
13
13
  export * from './inputFileDownloader'
14
14
  export * from './appMemory'
15
+ export * from './extensions'
16
+ export * from './adaptiveCards'
@@ -21,7 +21,7 @@ const logger = debug('agents:jwt-middleware')
21
21
  const verifyToken = async (raw: string, config: AuthConfiguration): Promise<JwtPayload> => {
22
22
  const getKey: GetPublicKeyOrSecret = (header: JwtHeader, callback: SignCallback) => {
23
23
  const payload = jwt.decode(raw) as JwtPayload
24
-
24
+ logger.info('jwt.decode ', JSON.stringify(payload))
25
25
  const jwksUri: string = payload.iss === 'https://api.botframework.com'
26
26
  ? 'https://login.botframework.com/v1/.well-known/keys'
27
27
  : `https://login.microsoftonline.com/${config.tenantId}/discovery/v2.0/keys`
@@ -175,12 +175,12 @@ export abstract class BaseAdapter {
175
175
 
176
176
  try {
177
177
  await this.middleware.run(pContext.proxy, async () => await next(pContext.proxy))
178
- } catch (err) {
178
+ } catch (err: Error | any) {
179
179
  if (this.onTurnError) {
180
180
  if (err instanceof Error) {
181
181
  await this.onTurnError(pContext.proxy, err)
182
182
  } else {
183
- throw new Error('Unknown error type')
183
+ throw new Error('Unknown error type: ' + err.message)
184
184
  }
185
185
  } else {
186
186
  throw err
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /**
7
+ * Represents an Adaptive Card, which is a card framework that enables developers to exchange UI content in a common and consistent way.
8
+ * @see {@link https://learn.microsoft.com/adaptive-cards/ | Adaptive Cards Documentation}
9
+ */
10
+ export interface AdaptiveCard {
11
+ /**
12
+ * The type of the card, which must always be 'AdaptiveCard'.
13
+ */
14
+ type: 'AdaptiveCard'
15
+ [key: string]: any
16
+ }
@@ -16,3 +16,4 @@ export * from './taskModuleAction'
16
16
  export * from './thumbnailCard'
17
17
  export * from './videoCard'
18
18
  export * from './thumbnailUrl'
19
+ export * from './adaptiveCard'
@@ -198,25 +198,23 @@ export class CloudAdapter extends BaseAdapter {
198
198
  }
199
199
 
200
200
  logger.debug('Received activity: ', activity)
201
+ const context = this.createTurnContext(activity, logic)
202
+ const scope = request.user?.azp ?? request.user?.appid ?? 'https://api.botframework.com'
203
+ logger.debug('Creating connector client with scope: ', scope)
204
+ this.connectorClient = await this.createConnectorClient(activity.serviceUrl!, scope)
205
+ this.setConnectorClient(context)
201
206
 
202
207
  if (
203
208
  activity?.type === ActivityTypes.InvokeResponse ||
204
209
  activity?.type === ActivityTypes.Invoke ||
205
210
  activity?.deliveryMode === DeliveryModes.ExpectReplies
206
211
  ) {
207
- const context = this.createTurnContext(activity, logic)
208
212
  await this.runMiddleware(context, logic)
209
213
  const invokeResponse = this.processTurnResults(context)
210
214
  logger.debug('Activity Response (invoke/expect replies): ', invokeResponse)
211
215
  return end(invokeResponse?.status ?? StatusCodes.OK, JSON.stringify(invokeResponse?.body), true)
212
216
  }
213
217
 
214
- const scope = request.user?.azp ?? request.user?.appid ?? 'https://api.botframework.com'
215
- logger.debug('Creating connector client with scope: ', scope)
216
- this.connectorClient = await this.createConnectorClient(activity.serviceUrl!, scope)
217
-
218
- const context = this.createTurnContext(activity, logic)
219
- this.setConnectorClient(context)
220
218
  await this.runMiddleware(context, logic)
221
219
  const invokeResponse = this.processTurnResults(context)
222
220
 
@@ -3,7 +3,7 @@ import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
3
3
  import { AuthConfiguration } from '../auth/authConfiguration'
4
4
  import { AuthProvider } from '../auth/authProvider'
5
5
  import { debug } from '../logger'
6
- import { Activity, ConversationParameters } from '@microsoft/agents-activity'
6
+ import { Activity, ChannelAccount, ConversationParameters } from '@microsoft/agents-activity'
7
7
  import { ConversationsResult } from './conversationsResult'
8
8
  import { ConversationResourceResponse } from './conversationResourceResponse'
9
9
  import { ResourceResponse } from './resourceResponse'
@@ -19,21 +19,21 @@ export { getProductInfo }
19
19
  * ConnectorClient is a client for interacting with the Microsoft Connector API.
20
20
  */
21
21
  export class ConnectorClient {
22
- protected readonly client: AxiosInstance
22
+ protected readonly _axiosInstance: AxiosInstance
23
23
 
24
24
  /**
25
25
  * Private constructor for the ConnectorClient.
26
- * @param client - The AxiosInstance to use for HTTP requests.
26
+ * @param axInstance - The AxiosInstance to use for HTTP requests.
27
27
  */
28
- protected constructor (client: AxiosInstance) {
29
- this.client = client
30
- this.client.interceptors.response.use(
28
+ protected constructor (axInstance: AxiosInstance) {
29
+ this._axiosInstance = axInstance
30
+ this._axiosInstance.interceptors.response.use(
31
31
  (config) => {
32
32
  const { status, statusText, config: requestConfig } = config
33
33
  logger.debug('Response: ', {
34
34
  status,
35
35
  statusText,
36
- host: this.client.getUri(),
36
+ host: this._axiosInstance.getUri(),
37
37
  url: requestConfig?.url,
38
38
  data: config.config.data,
39
39
  method: requestConfig?.method,
@@ -41,14 +41,14 @@ export class ConnectorClient {
41
41
  return config
42
42
  },
43
43
  (error) => {
44
- const { code, message, stack } = error
44
+ const { code, message, stack, response } = error
45
45
  const errorDetails = {
46
46
  code,
47
- host: this.client.getUri(),
47
+ host: this._axiosInstance.getUri(),
48
48
  url: error.config.url,
49
49
  method: error.config.method,
50
50
  data: error.config.data,
51
- message,
51
+ message: message + JSON.stringify(response?.data),
52
52
  stack,
53
53
  }
54
54
  return Promise.reject(errorDetails)
@@ -56,6 +56,10 @@ export class ConnectorClient {
56
56
  )
57
57
  }
58
58
 
59
+ public get axiosInstance (): AxiosInstance {
60
+ return this._axiosInstance
61
+ }
62
+
59
63
  /**
60
64
  * Creates a new instance of ConnectorClient with authentication.
61
65
  * @param baseURL - The base URL for the API.
@@ -100,7 +104,22 @@ export class ConnectorClient {
100
104
  url: '/v3/conversations',
101
105
  params: continuationToken ? { continuationToken } : undefined
102
106
  }
103
- const response = await this.client(config)
107
+ const response = await this._axiosInstance(config)
108
+ return response.data
109
+ }
110
+
111
+ public async getConversationMember (userId: string, conversationId: string): Promise<ChannelAccount> {
112
+ if (!userId || !conversationId) {
113
+ throw new Error('userId and conversationId are required')
114
+ }
115
+ const config: AxiosRequestConfig = {
116
+ method: 'get',
117
+ url: `v3/conversations/${conversationId}/members/${userId}`,
118
+ headers: {
119
+ 'Content-Type': 'application/json'
120
+ }
121
+ }
122
+ const response = await this._axiosInstance(config)
104
123
  return response.data
105
124
  }
106
125
 
@@ -119,7 +138,7 @@ export class ConnectorClient {
119
138
  },
120
139
  data: body
121
140
  }
122
- const response: AxiosResponse = await this.client(config)
141
+ const response: AxiosResponse = await this._axiosInstance(config)
123
142
  return response.data
124
143
  }
125
144
 
@@ -147,7 +166,7 @@ export class ConnectorClient {
147
166
  },
148
167
  data: body
149
168
  }
150
- const response = await this.client(config)
169
+ const response = await this._axiosInstance(config)
151
170
  logger.info('Reply to conversation/activity: ', response.data.id!, activityId)
152
171
  return response.data
153
172
  }
@@ -174,7 +193,7 @@ export class ConnectorClient {
174
193
  },
175
194
  data: body
176
195
  }
177
- const response = await this.client(config)
196
+ const response = await this._axiosInstance(config)
178
197
  return response.data
179
198
  }
180
199
 
@@ -201,7 +220,7 @@ export class ConnectorClient {
201
220
  },
202
221
  data: body
203
222
  }
204
- const response = await this.client(config)
223
+ const response = await this._axiosInstance(config)
205
224
  return response.data
206
225
  }
207
226
 
@@ -225,7 +244,7 @@ export class ConnectorClient {
225
244
  'Content-Type': 'application/json'
226
245
  }
227
246
  }
228
- const response = await this.client(config)
247
+ const response = await this._axiosInstance(config)
229
248
  return response.data
230
249
  }
231
250
 
@@ -250,7 +269,7 @@ export class ConnectorClient {
250
269
  },
251
270
  data: body
252
271
  }
253
- const response = await this.client(config)
272
+ const response = await this._axiosInstance(config)
254
273
  return response.data
255
274
  }
256
275
 
@@ -272,7 +291,7 @@ export class ConnectorClient {
272
291
  'Content-Type': 'application/json'
273
292
  }
274
293
  }
275
- const response = await this.client(config)
294
+ const response = await this._axiosInstance(config)
276
295
  return response.data
277
296
  }
278
297
 
@@ -299,7 +318,7 @@ export class ConnectorClient {
299
318
  'Content-Type': 'application/json'
300
319
  }
301
320
  }
302
- const response = await this.client(config)
321
+ const response = await this._axiosInstance(config)
303
322
  return response.data
304
323
  }
305
324
  }