@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.
- package/dist/src/activityWireCompat.js +1 -1
- package/dist/src/activityWireCompat.js.map +1 -1
- package/dist/src/app/adaptiveCards/activityValueParsers.d.ts +115 -0
- package/dist/src/app/adaptiveCards/activityValueParsers.js +224 -0
- package/dist/src/app/adaptiveCards/activityValueParsers.js.map +1 -0
- package/dist/src/app/adaptiveCards/adaptiveCardActionExecuteResponseType.d.ts +21 -0
- package/dist/src/app/adaptiveCards/adaptiveCardActionExecuteResponseType.js +26 -0
- package/dist/src/app/adaptiveCards/adaptiveCardActionExecuteResponseType.js.map +1 -0
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.d.ts +57 -0
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.js +272 -0
- package/dist/src/app/adaptiveCards/adaptiveCardsActions.js.map +1 -0
- package/dist/src/app/adaptiveCards/adaptiveCardsOptions.d.ts +20 -0
- package/dist/src/app/adaptiveCards/adaptiveCardsOptions.js +7 -0
- package/dist/src/app/adaptiveCards/adaptiveCardsOptions.js.map +1 -0
- package/dist/src/app/adaptiveCards/adaptiveCardsSearchParams.d.ts +31 -0
- package/dist/src/app/adaptiveCards/adaptiveCardsSearchParams.js +16 -0
- package/dist/src/app/adaptiveCards/adaptiveCardsSearchParams.js.map +1 -0
- package/dist/src/app/adaptiveCards/index.d.ts +3 -0
- package/dist/src/app/adaptiveCards/index.js +20 -0
- package/dist/src/app/adaptiveCards/index.js.map +1 -0
- package/dist/src/app/adaptiveCards/query.d.ts +22 -0
- package/dist/src/app/adaptiveCards/query.js +7 -0
- package/dist/src/app/adaptiveCards/query.js.map +1 -0
- package/dist/src/app/agentApplication.d.ts +56 -8
- package/dist/src/app/agentApplication.js +88 -11
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationBuilder.d.ts +2 -2
- package/dist/src/app/agentApplicationBuilder.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +17 -2
- package/dist/src/app/appRoute.d.ts +5 -0
- package/dist/src/app/attachmentDownloader.js +1 -0
- package/dist/src/app/attachmentDownloader.js.map +1 -1
- package/dist/src/app/extensions.d.ts +9 -0
- package/dist/src/app/extensions.js +16 -0
- package/dist/src/app/extensions.js.map +1 -0
- package/dist/src/app/index.d.ts +2 -0
- package/dist/src/app/index.js +2 -0
- package/dist/src/app/index.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js +1 -0
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/baseAdapter.js +1 -1
- package/dist/src/baseAdapter.js.map +1 -1
- package/dist/src/cards/adaptiveCard.d.ts +15 -0
- package/dist/src/cards/adaptiveCard.js +7 -0
- package/dist/src/cards/adaptiveCard.js.map +1 -0
- package/dist/src/cards/index.d.ts +1 -0
- package/dist/src/cards/index.js +1 -0
- package/dist/src/cards/index.js.map +1 -1
- package/dist/src/cloudAdapter.js +6 -7
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/connector-client/connectorClient.d.ts +6 -4
- package/dist/src/connector-client/connectorClient.js +34 -17
- package/dist/src/connector-client/connectorClient.js.map +1 -1
- package/package.json +2 -2
- package/src/activityWireCompat.ts +1 -1
- package/src/app/adaptiveCards/activityValueParsers.ts +249 -0
- package/src/app/adaptiveCards/adaptiveCardActionExecuteResponseType.ts +24 -0
- package/src/app/adaptiveCards/adaptiveCardsActions.ts +320 -0
- package/src/app/adaptiveCards/adaptiveCardsOptions.ts +23 -0
- package/src/app/adaptiveCards/adaptiveCardsSearchParams.ts +28 -0
- package/src/app/adaptiveCards/index.ts +3 -0
- package/src/app/adaptiveCards/query.ts +25 -0
- package/src/app/agentApplication.ts +109 -29
- package/src/app/agentApplicationBuilder.ts +2 -2
- package/src/app/agentApplicationOptions.ts +20 -2
- package/src/app/appRoute.ts +6 -0
- package/src/app/attachmentDownloader.ts +1 -0
- package/src/app/extensions.ts +19 -0
- package/src/app/index.ts +2 -0
- package/src/auth/jwt-middleware.ts +1 -1
- package/src/baseAdapter.ts +2 -2
- package/src/cards/adaptiveCard.ts +16 -0
- package/src/cards/index.ts +1 -0
- package/src/cloudAdapter.ts +5 -7
- package/src/connector-client/connectorClient.ts +38 -19
package/src/app/appRoute.ts
CHANGED
|
@@ -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
|
@@ -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`
|
package/src/baseAdapter.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/cards/index.ts
CHANGED
package/src/cloudAdapter.ts
CHANGED
|
@@ -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
|
|
22
|
+
protected readonly _axiosInstance: AxiosInstance
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Private constructor for the ConnectorClient.
|
|
26
|
-
* @param
|
|
26
|
+
* @param axInstance - The AxiosInstance to use for HTTP requests.
|
|
27
27
|
*/
|
|
28
|
-
protected constructor (
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
321
|
+
const response = await this._axiosInstance(config)
|
|
303
322
|
return response.data
|
|
304
323
|
}
|
|
305
324
|
}
|