@microsoft/agents-hosting 0.1.49
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/README.md +57 -0
- package/dist/src/activityHandler.d.ts +108 -0
- package/dist/src/activityHandler.js +395 -0
- package/dist/src/activityHandler.js.map +1 -0
- package/dist/src/agent-client/agentClient.d.ts +13 -0
- package/dist/src/agent-client/agentClient.js +75 -0
- package/dist/src/agent-client/agentClient.js.map +1 -0
- package/dist/src/agent-client/expressApi.d.ts +4 -0
- package/dist/src/agent-client/expressApi.js +50 -0
- package/dist/src/agent-client/expressApi.js.map +1 -0
- package/dist/src/agent-client/index.d.ts +2 -0
- package/dist/src/agent-client/index.js +19 -0
- package/dist/src/agent-client/index.js.map +1 -0
- package/dist/src/app/agentApplication.d.ts +47 -0
- package/dist/src/app/agentApplication.js +317 -0
- package/dist/src/app/agentApplication.js.map +1 -0
- package/dist/src/app/appRoute.d.ts +11 -0
- package/dist/src/app/appRoute.js +7 -0
- package/dist/src/app/appRoute.js.map +1 -0
- package/dist/src/app/applicationBuilder.d.ts +18 -0
- package/dist/src/app/applicationBuilder.js +37 -0
- package/dist/src/app/applicationBuilder.js.map +1 -0
- package/dist/src/app/applicationOptions.d.ts +19 -0
- package/dist/src/app/applicationOptions.js +7 -0
- package/dist/src/app/applicationOptions.js.map +1 -0
- package/dist/src/app/attachmentDownloader.d.ts +13 -0
- package/dist/src/app/attachmentDownloader.js +72 -0
- package/dist/src/app/attachmentDownloader.js.map +1 -0
- package/dist/src/app/conversationUpdateEvents.d.ts +5 -0
- package/dist/src/app/conversationUpdateEvents.js +7 -0
- package/dist/src/app/conversationUpdateEvents.js.map +1 -0
- package/dist/src/app/index.d.ts +10 -0
- package/dist/src/app/index.js +27 -0
- package/dist/src/app/index.js.map +1 -0
- package/dist/src/app/inputFileDownloader.d.ts +14 -0
- package/dist/src/app/inputFileDownloader.js +7 -0
- package/dist/src/app/inputFileDownloader.js.map +1 -0
- package/dist/src/app/memory.d.ts +10 -0
- package/dist/src/app/memory.js +7 -0
- package/dist/src/app/memory.js.map +1 -0
- package/dist/src/app/oauth/authenticationOptions.d.ts +7 -0
- package/dist/src/app/oauth/authenticationOptions.js +7 -0
- package/dist/src/app/oauth/authenticationOptions.js.map +1 -0
- package/dist/src/app/oauth/webChatOAuthFlowAppStyle.d.ts +11 -0
- package/dist/src/app/oauth/webChatOAuthFlowAppStyle.js +85 -0
- package/dist/src/app/oauth/webChatOAuthFlowAppStyle.js.map +1 -0
- package/dist/src/app/routeHandler.d.ts +7 -0
- package/dist/src/app/routeHandler.js +7 -0
- package/dist/src/app/routeHandler.js.map +1 -0
- package/dist/src/app/routeSelector.d.ts +7 -0
- package/dist/src/app/routeSelector.js +7 -0
- package/dist/src/app/routeSelector.js.map +1 -0
- package/dist/src/app/turnEvents.d.ts +5 -0
- package/dist/src/app/turnEvents.js +7 -0
- package/dist/src/app/turnEvents.js.map +1 -0
- package/dist/src/app/turnState.d.ts +85 -0
- package/dist/src/app/turnState.js +274 -0
- package/dist/src/app/turnState.js.map +1 -0
- package/dist/src/app/turnStateEntry.d.ts +17 -0
- package/dist/src/app/turnStateEntry.js +39 -0
- package/dist/src/app/turnStateEntry.js.map +1 -0
- package/dist/src/auth/authConfiguration.d.ts +29 -0
- package/dist/src/auth/authConfiguration.js +58 -0
- package/dist/src/auth/authConfiguration.js.map +1 -0
- package/dist/src/auth/authProvider.d.ts +17 -0
- package/dist/src/auth/authProvider.js +7 -0
- package/dist/src/auth/authProvider.js.map +1 -0
- package/dist/src/auth/index.d.ts +4 -0
- package/dist/src/auth/index.js +21 -0
- package/dist/src/auth/index.js.map +1 -0
- package/dist/src/auth/jwt-middleware.d.ts +13 -0
- package/dist/src/auth/jwt-middleware.js +97 -0
- package/dist/src/auth/jwt-middleware.js.map +1 -0
- package/dist/src/auth/msalTokenProvider.d.ts +53 -0
- package/dist/src/auth/msalTokenProvider.js +198 -0
- package/dist/src/auth/msalTokenProvider.js.map +1 -0
- package/dist/src/auth/request.d.ts +15 -0
- package/dist/src/auth/request.js +7 -0
- package/dist/src/auth/request.js.map +1 -0
- package/dist/src/baseAdapter.d.ts +88 -0
- package/dist/src/baseAdapter.js +94 -0
- package/dist/src/baseAdapter.js.map +1 -0
- package/dist/src/cards/animationCard.d.ts +36 -0
- package/dist/src/cards/animationCard.js +7 -0
- package/dist/src/cards/animationCard.js.map +1 -0
- package/dist/src/cards/audioCard.d.ts +36 -0
- package/dist/src/cards/audioCard.js +7 -0
- package/dist/src/cards/audioCard.js.map +1 -0
- package/dist/src/cards/cardFactory.d.ts +123 -0
- package/dist/src/cards/cardFactory.js +225 -0
- package/dist/src/cards/cardFactory.js.map +1 -0
- package/dist/src/cards/cardImage.d.ts +16 -0
- package/dist/src/cards/cardImage.js +7 -0
- package/dist/src/cards/cardImage.js.map +1 -0
- package/dist/src/cards/fact.d.ts +13 -0
- package/dist/src/cards/fact.js +7 -0
- package/dist/src/cards/fact.js.map +1 -0
- package/dist/src/cards/heroCard.d.ts +23 -0
- package/dist/src/cards/heroCard.js +7 -0
- package/dist/src/cards/heroCard.js.map +1 -0
- package/dist/src/cards/index.d.ts +17 -0
- package/dist/src/cards/index.js +34 -0
- package/dist/src/cards/index.js.map +1 -0
- package/dist/src/cards/mediaUrl.d.ts +17 -0
- package/dist/src/cards/mediaUrl.js +7 -0
- package/dist/src/cards/mediaUrl.js.map +1 -0
- package/dist/src/cards/o365ConnectorCard.d.ts +35 -0
- package/dist/src/cards/o365ConnectorCard.js +7 -0
- package/dist/src/cards/o365ConnectorCard.js.map +1 -0
- package/dist/src/cards/o365ConnectorCardActionBase.d.ts +22 -0
- package/dist/src/cards/o365ConnectorCardActionBase.js +7 -0
- package/dist/src/cards/o365ConnectorCardActionBase.js.map +1 -0
- package/dist/src/cards/o365ConnectorCardFact.d.ts +17 -0
- package/dist/src/cards/o365ConnectorCardFact.js +7 -0
- package/dist/src/cards/o365ConnectorCardFact.js.map +1 -0
- package/dist/src/cards/o365ConnectorCardImage.d.ts +17 -0
- package/dist/src/cards/o365ConnectorCardImage.js +7 -0
- package/dist/src/cards/o365ConnectorCardImage.js.map +1 -0
- package/dist/src/cards/o365ConnectorCardSection.d.ts +57 -0
- package/dist/src/cards/o365ConnectorCardSection.js +7 -0
- package/dist/src/cards/o365ConnectorCardSection.js.map +1 -0
- package/dist/src/cards/receiptCard.d.ts +44 -0
- package/dist/src/cards/receiptCard.js +7 -0
- package/dist/src/cards/receiptCard.js.map +1 -0
- package/dist/src/cards/receiptItem.d.ts +39 -0
- package/dist/src/cards/receiptItem.js +7 -0
- package/dist/src/cards/receiptItem.js.map +1 -0
- package/dist/src/cards/signinCard.d.ts +14 -0
- package/dist/src/cards/signinCard.js +5 -0
- package/dist/src/cards/signinCard.js.map +1 -0
- package/dist/src/cards/taskModuleAction.d.ts +43 -0
- package/dist/src/cards/taskModuleAction.js +30 -0
- package/dist/src/cards/taskModuleAction.js.map +1 -0
- package/dist/src/cards/thumbnailCard.d.ts +35 -0
- package/dist/src/cards/thumbnailCard.js +7 -0
- package/dist/src/cards/thumbnailCard.js.map +1 -0
- package/dist/src/cards/thumbnailUrl.d.ts +17 -0
- package/dist/src/cards/thumbnailUrl.js +7 -0
- package/dist/src/cards/thumbnailUrl.js.map +1 -0
- package/dist/src/cards/videoCard.d.ts +60 -0
- package/dist/src/cards/videoCard.js +7 -0
- package/dist/src/cards/videoCard.js.map +1 -0
- package/dist/src/claimsIdentity.d.ts +35 -0
- package/dist/src/claimsIdentity.js +43 -0
- package/dist/src/claimsIdentity.js.map +1 -0
- package/dist/src/cloudAdapter.d.ts +128 -0
- package/dist/src/cloudAdapter.js +376 -0
- package/dist/src/cloudAdapter.js.map +1 -0
- package/dist/src/connector-client/attachmentData.d.ts +25 -0
- package/dist/src/connector-client/attachmentData.js +7 -0
- package/dist/src/connector-client/attachmentData.js.map +1 -0
- package/dist/src/connector-client/attachmentInfo.d.ts +22 -0
- package/dist/src/connector-client/attachmentInfo.js +7 -0
- package/dist/src/connector-client/attachmentInfo.js.map +1 -0
- package/dist/src/connector-client/attachmentView.d.ts +17 -0
- package/dist/src/connector-client/attachmentView.js +7 -0
- package/dist/src/connector-client/attachmentView.js.map +1 -0
- package/dist/src/connector-client/connectorClient.d.ts +93 -0
- package/dist/src/connector-client/connectorClient.js +249 -0
- package/dist/src/connector-client/connectorClient.js.map +1 -0
- package/dist/src/connector-client/conversationMembers.d.ts +18 -0
- package/dist/src/connector-client/conversationMembers.js +7 -0
- package/dist/src/connector-client/conversationMembers.js.map +1 -0
- package/dist/src/connector-client/conversationParameters.d.ts +38 -0
- package/dist/src/connector-client/conversationParameters.js +7 -0
- package/dist/src/connector-client/conversationParameters.js.map +1 -0
- package/dist/src/connector-client/conversationResourceResponse.d.ts +21 -0
- package/dist/src/connector-client/conversationResourceResponse.js +7 -0
- package/dist/src/connector-client/conversationResourceResponse.js.map +1 -0
- package/dist/src/connector-client/conversationsResult.d.ts +18 -0
- package/dist/src/connector-client/conversationsResult.js +7 -0
- package/dist/src/connector-client/conversationsResult.js.map +1 -0
- package/dist/src/connector-client/index.d.ts +9 -0
- package/dist/src/connector-client/index.js +26 -0
- package/dist/src/connector-client/index.js.map +1 -0
- package/dist/src/connector-client/resourceResponse.d.ts +13 -0
- package/dist/src/connector-client/resourceResponse.js +7 -0
- package/dist/src/connector-client/resourceResponse.js.map +1 -0
- package/dist/src/index.d.ts +26 -0
- package/dist/src/index.js +45 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/invoke/adaptiveCardAuthentication.d.ts +10 -0
- package/dist/src/invoke/adaptiveCardAuthentication.js +7 -0
- package/dist/src/invoke/adaptiveCardAuthentication.js.map +1 -0
- package/dist/src/invoke/adaptiveCardInvokeResponse.d.ts +21 -0
- package/dist/src/invoke/adaptiveCardInvokeResponse.js +7 -0
- package/dist/src/invoke/adaptiveCardInvokeResponse.js.map +1 -0
- package/dist/src/invoke/adaptiveCardInvokeValue.d.ts +23 -0
- package/dist/src/invoke/adaptiveCardInvokeValue.js +7 -0
- package/dist/src/invoke/adaptiveCardInvokeValue.js.map +1 -0
- package/dist/src/invoke/index.d.ts +9 -0
- package/dist/src/invoke/index.js +26 -0
- package/dist/src/invoke/index.js.map +1 -0
- package/dist/src/invoke/invokeException.d.ts +24 -0
- package/dist/src/invoke/invokeException.js +35 -0
- package/dist/src/invoke/invokeException.js.map +1 -0
- package/dist/src/invoke/invokeResponse.d.ts +17 -0
- package/dist/src/invoke/invokeResponse.js +7 -0
- package/dist/src/invoke/invokeResponse.js.map +1 -0
- package/dist/src/invoke/searchInvokeOptions.d.ts +17 -0
- package/dist/src/invoke/searchInvokeOptions.js +7 -0
- package/dist/src/invoke/searchInvokeOptions.js.map +1 -0
- package/dist/src/invoke/searchInvokeResponse.d.ts +10 -0
- package/dist/src/invoke/searchInvokeResponse.js +7 -0
- package/dist/src/invoke/searchInvokeResponse.js.map +1 -0
- package/dist/src/invoke/searchInvokeValue.d.ts +26 -0
- package/dist/src/invoke/searchInvokeValue.js +7 -0
- package/dist/src/invoke/searchInvokeValue.js.map +1 -0
- package/dist/src/invoke/tokenExchangeInvokeRequest.d.ts +21 -0
- package/dist/src/invoke/tokenExchangeInvokeRequest.js +7 -0
- package/dist/src/invoke/tokenExchangeInvokeRequest.js.map +1 -0
- package/dist/src/logger.d.ts +12 -0
- package/dist/src/logger.js +42 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/messageFactory.d.ts +62 -0
- package/dist/src/messageFactory.js +143 -0
- package/dist/src/messageFactory.js.map +1 -0
- package/dist/src/middlewareSet.d.ts +43 -0
- package/dist/src/middlewareSet.js +57 -0
- package/dist/src/middlewareSet.js.map +1 -0
- package/dist/src/oauth/index.d.ts +7 -0
- package/dist/src/oauth/index.js +24 -0
- package/dist/src/oauth/index.js.map +1 -0
- package/dist/src/oauth/oauthCard.d.ts +28 -0
- package/dist/src/oauth/oauthCard.js +5 -0
- package/dist/src/oauth/oauthCard.js.map +1 -0
- package/dist/src/oauth/signingResource.d.ts +19 -0
- package/dist/src/oauth/signingResource.js +5 -0
- package/dist/src/oauth/signingResource.js.map +1 -0
- package/dist/src/oauth/tokenExchangeRequest.d.ts +17 -0
- package/dist/src/oauth/tokenExchangeRequest.js +5 -0
- package/dist/src/oauth/tokenExchangeRequest.js.map +1 -0
- package/dist/src/oauth/tokenExchangeResource.d.ts +17 -0
- package/dist/src/oauth/tokenExchangeResource.js +5 -0
- package/dist/src/oauth/tokenExchangeResource.js.map +1 -0
- package/dist/src/oauth/tokenPostResource.d.ts +9 -0
- package/dist/src/oauth/tokenPostResource.js +5 -0
- package/dist/src/oauth/tokenPostResource.js.map +1 -0
- package/dist/src/oauth/userTokenClient.d.ts +49 -0
- package/dist/src/oauth/userTokenClient.js +117 -0
- package/dist/src/oauth/userTokenClient.js.map +1 -0
- package/dist/src/oauth/webChatOAuthFlow.d.ts +41 -0
- package/dist/src/oauth/webChatOAuthFlow.js +117 -0
- package/dist/src/oauth/webChatOAuthFlow.js.map +1 -0
- package/dist/src/state/agentState.d.ts +71 -0
- package/dist/src/state/agentState.js +122 -0
- package/dist/src/state/agentState.js.map +1 -0
- package/dist/src/state/agentStatePropertyAccesor.d.ts +39 -0
- package/dist/src/state/agentStatePropertyAccesor.js +60 -0
- package/dist/src/state/agentStatePropertyAccesor.js.map +1 -0
- package/dist/src/state/conversationState.d.ts +18 -0
- package/dist/src/state/conversationState.js +38 -0
- package/dist/src/state/conversationState.js.map +1 -0
- package/dist/src/state/index.d.ts +4 -0
- package/dist/src/state/index.js +21 -0
- package/dist/src/state/index.js.map +1 -0
- package/dist/src/state/userState.d.ts +18 -0
- package/dist/src/state/userState.js +38 -0
- package/dist/src/state/userState.js.map +1 -0
- package/dist/src/statusCodes.d.ts +19 -0
- package/dist/src/statusCodes.js +24 -0
- package/dist/src/statusCodes.js.map +1 -0
- package/dist/src/storage/index.d.ts +2 -0
- package/dist/src/storage/index.js +19 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/src/storage/memoryStorage.d.ts +50 -0
- package/dist/src/storage/memoryStorage.js +100 -0
- package/dist/src/storage/memoryStorage.js.map +1 -0
- package/dist/src/storage/storage.d.ts +47 -0
- package/dist/src/storage/storage.js +7 -0
- package/dist/src/storage/storage.js.map +1 -0
- package/dist/src/tokenResponseEventName.d.ts +5 -0
- package/dist/src/tokenResponseEventName.js +9 -0
- package/dist/src/tokenResponseEventName.js.map +1 -0
- package/dist/src/transcript/consoleTranscriptLogger.d.ts +13 -0
- package/dist/src/transcript/consoleTranscriptLogger.js +21 -0
- package/dist/src/transcript/consoleTranscriptLogger.js.map +1 -0
- package/dist/src/transcript/index.d.ts +4 -0
- package/dist/src/transcript/index.js +21 -0
- package/dist/src/transcript/index.js.map +1 -0
- package/dist/src/transcript/transcriptLogger.d.ts +42 -0
- package/dist/src/transcript/transcriptLogger.js +3 -0
- package/dist/src/transcript/transcriptLogger.js.map +1 -0
- package/dist/src/transcript/transcriptLoggerMiddleware.d.ts +38 -0
- package/dist/src/transcript/transcriptLoggerMiddleware.js +126 -0
- package/dist/src/transcript/transcriptLoggerMiddleware.js.map +1 -0
- package/dist/src/transcript/transcriptStore.d.ts +30 -0
- package/dist/src/transcript/transcriptStore.js +3 -0
- package/dist/src/transcript/transcriptStore.js.map +1 -0
- package/dist/src/turnContext.d.ts +160 -0
- package/dist/src/turnContext.js +286 -0
- package/dist/src/turnContext.js.map +1 -0
- package/dist/src/turnContextStateCollection.d.ts +29 -0
- package/dist/src/turnContextStateCollection.js +56 -0
- package/dist/src/turnContextStateCollection.js.map +1 -0
- package/package.json +48 -0
- package/src/activityHandler.ts +461 -0
- package/src/agent-client/agentClient.ts +84 -0
- package/src/agent-client/expressApi.ts +59 -0
- package/src/agent-client/index.ts +2 -0
- package/src/app/agentApplication.ts +401 -0
- package/src/app/appRoute.ts +13 -0
- package/src/app/applicationBuilder.ts +42 -0
- package/src/app/applicationOptions.ts +21 -0
- package/src/app/attachmentDownloader.ts +83 -0
- package/src/app/conversationUpdateEvents.ts +8 -0
- package/src/app/index.ts +10 -0
- package/src/app/inputFileDownloader.ts +17 -0
- package/src/app/memory.ts +14 -0
- package/src/app/oauth/authenticationOptions.ts +8 -0
- package/src/app/oauth/webChatOAuthFlowAppStyle.ts +90 -0
- package/src/app/routeHandler.ts +9 -0
- package/src/app/routeSelector.ts +10 -0
- package/src/app/turnEvents.ts +6 -0
- package/src/app/turnState.ts +338 -0
- package/src/app/turnStateEntry.ts +46 -0
- package/src/auth/authConfiguration.ts +68 -0
- package/src/auth/authProvider.ts +19 -0
- package/src/auth/index.ts +4 -0
- package/src/auth/jwt-middleware.ts +99 -0
- package/src/auth/msalTokenProvider.ts +202 -0
- package/src/auth/request.ts +20 -0
- package/src/baseAdapter.ts +174 -0
- package/src/cards/animationCard.ts +38 -0
- package/src/cards/audioCard.ts +38 -0
- package/src/cards/cardFactory.ts +276 -0
- package/src/cards/cardImage.ts +18 -0
- package/src/cards/fact.ts +14 -0
- package/src/cards/heroCard.ts +25 -0
- package/src/cards/index.ts +17 -0
- package/src/cards/mediaUrl.ts +18 -0
- package/src/cards/o365ConnectorCard.ts +37 -0
- package/src/cards/o365ConnectorCardActionBase.ts +24 -0
- package/src/cards/o365ConnectorCardFact.ts +18 -0
- package/src/cards/o365ConnectorCardImage.ts +18 -0
- package/src/cards/o365ConnectorCardSection.ts +60 -0
- package/src/cards/receiptCard.ts +46 -0
- package/src/cards/receiptItem.ts +41 -0
- package/src/cards/signinCard.ts +18 -0
- package/src/cards/taskModuleAction.ts +61 -0
- package/src/cards/thumbnailCard.ts +37 -0
- package/src/cards/thumbnailUrl.ts +18 -0
- package/src/cards/videoCard.ts +62 -0
- package/src/claimsIdentity.ts +47 -0
- package/src/cloudAdapter.ts +431 -0
- package/src/connector-client/attachmentData.ts +26 -0
- package/src/connector-client/attachmentInfo.ts +24 -0
- package/src/connector-client/attachmentView.ts +18 -0
- package/src/connector-client/connectorClient.ts +295 -0
- package/src/connector-client/conversationMembers.ts +20 -0
- package/src/connector-client/conversationParameters.ts +40 -0
- package/src/connector-client/conversationResourceResponse.ts +22 -0
- package/src/connector-client/conversationsResult.ts +20 -0
- package/src/connector-client/index.ts +9 -0
- package/src/connector-client/resourceResponse.ts +14 -0
- package/src/index.ts +31 -0
- package/src/invoke/adaptiveCardAuthentication.ts +13 -0
- package/src/invoke/adaptiveCardInvokeResponse.ts +22 -0
- package/src/invoke/adaptiveCardInvokeValue.ts +25 -0
- package/src/invoke/index.ts +9 -0
- package/src/invoke/invokeException.ts +33 -0
- package/src/invoke/invokeResponse.ts +18 -0
- package/src/invoke/searchInvokeOptions.ts +18 -0
- package/src/invoke/searchInvokeResponse.ts +11 -0
- package/src/invoke/searchInvokeValue.ts +28 -0
- package/src/invoke/tokenExchangeInvokeRequest.ts +22 -0
- package/src/logger.ts +43 -0
- package/src/messageFactory.ts +177 -0
- package/src/middlewareSet.ts +76 -0
- package/src/oauth/index.ts +7 -0
- package/src/oauth/oauthCard.ts +32 -0
- package/src/oauth/signingResource.ts +23 -0
- package/src/oauth/tokenExchangeRequest.ts +20 -0
- package/src/oauth/tokenExchangeResource.ts +20 -0
- package/src/oauth/tokenPostResource.ts +12 -0
- package/src/oauth/userTokenClient.ts +116 -0
- package/src/oauth/webChatOAuthFlow.ts +123 -0
- package/src/state/agentState.ts +142 -0
- package/src/state/agentStatePropertyAccesor.ts +61 -0
- package/src/state/conversationState.ts +42 -0
- package/src/state/index.ts +4 -0
- package/src/state/userState.ts +43 -0
- package/src/statusCodes.ts +20 -0
- package/src/storage/index.ts +2 -0
- package/src/storage/memoryStorage.ts +105 -0
- package/src/storage/storage.ts +52 -0
- package/src/tokenResponseEventName.ts +6 -0
- package/src/transcript/consoleTranscriptLogger.ts +20 -0
- package/src/transcript/index.ts +4 -0
- package/src/transcript/transcriptLogger.ts +45 -0
- package/src/transcript/transcriptLoggerMiddleware.ts +151 -0
- package/src/transcript/transcriptStore.ts +38 -0
- package/src/turnContext.ts +335 -0
- package/src/turnContextStateCollection.ts +69 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { debug } from './logger'
|
|
6
|
+
import { TurnContext } from './turnContext'
|
|
7
|
+
import { Activity, ActivityTypes, Channels } from '@microsoft/agents-activity'
|
|
8
|
+
import { StatusCodes } from './statusCodes'
|
|
9
|
+
import { InvokeResponse } from './invoke/invokeResponse'
|
|
10
|
+
import { InvokeException } from './invoke/invokeException'
|
|
11
|
+
import { AdaptiveCardInvokeValue } from './invoke/adaptiveCardInvokeValue'
|
|
12
|
+
import { SearchInvokeValue } from './invoke/searchInvokeValue'
|
|
13
|
+
import { SearchInvokeResponse } from './invoke/searchInvokeResponse'
|
|
14
|
+
import { AdaptiveCardInvokeResponse } from './invoke/adaptiveCardInvokeResponse'
|
|
15
|
+
import { tokenResponseEventName } from './tokenResponseEventName'
|
|
16
|
+
|
|
17
|
+
/** Symbol key for invoke response */
|
|
18
|
+
export const INVOKE_RESPONSE_KEY = Symbol('invokeResponse')
|
|
19
|
+
|
|
20
|
+
/** Type definition for agent handler function */
|
|
21
|
+
export type AgentHandler = (context: TurnContext, next: () => Promise<void>) => Promise<any>
|
|
22
|
+
|
|
23
|
+
const logger = debug('agents:activity-handler')
|
|
24
|
+
|
|
25
|
+
/** * Handles various activity types and dispatches them to the appropriate handlers. */
|
|
26
|
+
export class ActivityHandler {
|
|
27
|
+
protected readonly handlers: { [type: string]: AgentHandler[] } = {}
|
|
28
|
+
|
|
29
|
+
/** * Registers a handler for the Turn activity type. */
|
|
30
|
+
onTurn (handler: AgentHandler): this {
|
|
31
|
+
return this.on('Turn', handler)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** * Registers a handler for the MembersAdded activity type. */
|
|
35
|
+
onMembersAdded (handler: AgentHandler): this {
|
|
36
|
+
return this.on('MembersAdded', handler)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** * Registers a handler for the MembersRemoved activity type. */
|
|
40
|
+
onMembersRemoved (handler: AgentHandler): this {
|
|
41
|
+
return this.on('MembersRemoved', handler)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** * Registers a handler for the Message activity type. */
|
|
45
|
+
onMessage (handler: AgentHandler): this {
|
|
46
|
+
return this.on('Message', handler)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** * Registers a handler for the MessageUpdate activity type. */
|
|
50
|
+
onMessageUpdate (handler: AgentHandler): this {
|
|
51
|
+
return this.on('MessageUpdate', handler)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** * Registers a handler for the MessageDelete activity type. */
|
|
55
|
+
onMessageDelete (handler: AgentHandler): this {
|
|
56
|
+
return this.on('MessageDelete', handler)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** * Registers a handler for the ConversationUpdate activity type. */
|
|
60
|
+
onConversationUpdate (handler: AgentHandler): this {
|
|
61
|
+
return this.on('ConversationUpdate', handler)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** * Registers a handler for the MessageReaction activity type. */
|
|
65
|
+
onMessageReaction (handler: AgentHandler): this {
|
|
66
|
+
return this.on('MessageReaction', handler)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** * Registers a handler for the ReactionsAdded activity type. */
|
|
70
|
+
onReactionsAdded (handler: AgentHandler): this {
|
|
71
|
+
return this.on('ReactionsAdded', handler)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** * Registers a handler for the ReactionsRemoved activity type. */
|
|
75
|
+
onReactionsRemoved (handler: AgentHandler): this {
|
|
76
|
+
return this.on('ReactionsRemoved', handler)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** * Registers a handler for the Typing activity type. */
|
|
80
|
+
onTyping (handler: AgentHandler): this {
|
|
81
|
+
return this.on('Typing', handler)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** * Registers a handler for the InstallationUpdate activity type. */
|
|
85
|
+
onInstallationUpdate (handler: AgentHandler): this {
|
|
86
|
+
return this.on('InstallationUpdate', handler)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** * Registers a handler for the InstallationUpdateAdd activity type. */
|
|
90
|
+
onInstallationUpdateAdd (handler: AgentHandler): this {
|
|
91
|
+
return this.on('InstallationUpdateAdd', handler)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** * Registers a handler for the InstallationUpdateRemove activity type. */
|
|
95
|
+
onInstallationUpdateRemove (handler: AgentHandler): this {
|
|
96
|
+
return this.on('InstallationUpdateRemove', handler)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** * Registers a handler for the EndOfConversation activity type. */
|
|
100
|
+
onEndOfConversation (handler: AgentHandler): this {
|
|
101
|
+
return this.on('EndOfConversation', handler)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** * Registers a handler for the SignInInvoke activity type. */
|
|
105
|
+
onSignInInvoke (handler: AgentHandler): this {
|
|
106
|
+
return this.on('SignInInvoke', handler)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** * Registers a handler for unrecognized activity types. */
|
|
110
|
+
onUnrecognizedActivityType (handler: AgentHandler): this {
|
|
111
|
+
return this.on('UnrecognizedActivityType', handler)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** * Registers an activity event handler for the _dialog_ event, emitted as the last event for an incoming activity. */
|
|
115
|
+
onDialog (handler: AgentHandler): this {
|
|
116
|
+
return this.on('Default', handler)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** * Runs the activity handler pipeline. */
|
|
120
|
+
async run (context: TurnContext): Promise<void> {
|
|
121
|
+
if (!context) throw new Error('Missing TurnContext parameter')
|
|
122
|
+
if (!context.activity) throw new Error('TurnContext does not include an activity')
|
|
123
|
+
if (!context.activity.type) throw new Error('Activity is missing its type')
|
|
124
|
+
|
|
125
|
+
await this.onTurnActivity(context)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** * Handles the Turn activity. */
|
|
129
|
+
protected async onTurnActivity (context: TurnContext): Promise<void> {
|
|
130
|
+
switch (context.activity.type) {
|
|
131
|
+
case ActivityTypes.Message:
|
|
132
|
+
await this.onMessageActivity(context)
|
|
133
|
+
break
|
|
134
|
+
case ActivityTypes.MessageUpdate:
|
|
135
|
+
await this.onMessageUpdateActivity(context)
|
|
136
|
+
break
|
|
137
|
+
case ActivityTypes.MessageDelete:
|
|
138
|
+
await this.onMessageDeleteActivity(context)
|
|
139
|
+
break
|
|
140
|
+
case ActivityTypes.ConversationUpdate:
|
|
141
|
+
await this.onConversationUpdateActivity(context)
|
|
142
|
+
break
|
|
143
|
+
|
|
144
|
+
case ActivityTypes.Invoke: {
|
|
145
|
+
const invokeResponse = await this.onInvokeActivity(context)
|
|
146
|
+
if (invokeResponse && !context.turnState.get(INVOKE_RESPONSE_KEY)) {
|
|
147
|
+
const activity = Activity.fromObject({ value: invokeResponse, type: 'invokeResponse' })
|
|
148
|
+
await context.sendActivity(activity)
|
|
149
|
+
}
|
|
150
|
+
break
|
|
151
|
+
}
|
|
152
|
+
case ActivityTypes.MessageReaction:
|
|
153
|
+
await this.onMessageReactionActivity(context)
|
|
154
|
+
break
|
|
155
|
+
case ActivityTypes.Typing:
|
|
156
|
+
await this.onTypingActivity(context)
|
|
157
|
+
break
|
|
158
|
+
case ActivityTypes.InstallationUpdate:
|
|
159
|
+
await this.onInstallationUpdateActivity(context)
|
|
160
|
+
break
|
|
161
|
+
case ActivityTypes.EndOfConversation:
|
|
162
|
+
await this.onEndOfConversationActivity(context)
|
|
163
|
+
break
|
|
164
|
+
default:
|
|
165
|
+
await this.onUnrecognizedActivity(context)
|
|
166
|
+
break
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** * Handles the Message activity. */
|
|
171
|
+
protected async onMessageActivity (context: TurnContext): Promise<void> {
|
|
172
|
+
await this.handle(context, 'Message', this.defaultNextEvent(context))
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** * Handles the MessageUpdate activity. */
|
|
176
|
+
protected async onMessageUpdateActivity (context: TurnContext): Promise<void> {
|
|
177
|
+
await this.handle(context, 'MessageUpdate', async () => {
|
|
178
|
+
await this.dispatchMessageUpdateActivity(context)
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** * Handles the MessageDelete activity. */
|
|
183
|
+
protected async onMessageDeleteActivity (context: TurnContext): Promise<void> {
|
|
184
|
+
await this.handle(context, 'MessageDelete', async () => {
|
|
185
|
+
await this.dispatchMessageDeleteActivity(context)
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** * Handles the ConversationUpdate activity. */
|
|
190
|
+
protected async onConversationUpdateActivity (context: TurnContext): Promise<void> {
|
|
191
|
+
await this.handle(context, 'ConversationUpdate', async () => {
|
|
192
|
+
await this.dispatchConversationUpdateActivity(context)
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** * Handles the SignInInvoke activity. */
|
|
197
|
+
protected async onSigninInvokeActivity (context: TurnContext): Promise<void> {
|
|
198
|
+
await this.handle(context, 'SignInInvoke', this.defaultNextEvent(context))
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** * Handles the Invoke activity. */
|
|
202
|
+
protected async onInvokeActivity (context: TurnContext): Promise<InvokeResponse> {
|
|
203
|
+
try {
|
|
204
|
+
switch (context.activity.name) {
|
|
205
|
+
case 'application/search': {
|
|
206
|
+
const invokeValue = this.getSearchInvokeValue(context.activity)
|
|
207
|
+
const response = await this.onSearchInvoke(context, invokeValue)
|
|
208
|
+
return { status: response.statusCode, body: response }
|
|
209
|
+
}
|
|
210
|
+
case 'adaptiveCard/action': {
|
|
211
|
+
const invokeValue = this.getAdaptiveCardInvokeValue(context.activity)
|
|
212
|
+
const response = await this.onAdaptiveCardInvoke(context, invokeValue)
|
|
213
|
+
return { status: response.statusCode, body: response }
|
|
214
|
+
}
|
|
215
|
+
case 'signin/verifyState':
|
|
216
|
+
case 'signin/tokenExchange':
|
|
217
|
+
await this.onSigninInvokeActivity(context)
|
|
218
|
+
return { status: StatusCodes.OK }
|
|
219
|
+
default:
|
|
220
|
+
throw new InvokeException(StatusCodes.NOT_IMPLEMENTED)
|
|
221
|
+
}
|
|
222
|
+
} catch (err) {
|
|
223
|
+
const error = err as Error
|
|
224
|
+
if (error.message === 'NotImplemented') {
|
|
225
|
+
return { status: StatusCodes.NOT_IMPLEMENTED }
|
|
226
|
+
}
|
|
227
|
+
if (err instanceof InvokeException) {
|
|
228
|
+
return err.createInvokeResponse()
|
|
229
|
+
}
|
|
230
|
+
throw err
|
|
231
|
+
} finally {
|
|
232
|
+
this.defaultNextEvent(context)()
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** * Handles the AdaptiveCardInvoke activity. */
|
|
237
|
+
protected async onAdaptiveCardInvoke (
|
|
238
|
+
_context: TurnContext,
|
|
239
|
+
_invokeValue: AdaptiveCardInvokeValue
|
|
240
|
+
): Promise<AdaptiveCardInvokeResponse> {
|
|
241
|
+
return await Promise.reject(new InvokeException(StatusCodes.NOT_IMPLEMENTED))
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** * Handles the SearchInvoke activity. */
|
|
245
|
+
protected async onSearchInvoke (_context: TurnContext, _invokeValue: SearchInvokeValue): Promise<SearchInvokeResponse> {
|
|
246
|
+
return await Promise.reject(new InvokeException(StatusCodes.NOT_IMPLEMENTED))
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** * Retrieves the SearchInvoke value from the activity. */
|
|
250
|
+
private getSearchInvokeValue (activity: Activity): SearchInvokeValue {
|
|
251
|
+
const value = activity.value as SearchInvokeValue
|
|
252
|
+
if (!value) {
|
|
253
|
+
const response = this.createAdaptiveCardInvokeErrorResponse(
|
|
254
|
+
StatusCodes.BAD_REQUEST,
|
|
255
|
+
'BadRequest',
|
|
256
|
+
'Missing value property for search'
|
|
257
|
+
)
|
|
258
|
+
throw new InvokeException(StatusCodes.BAD_REQUEST, response)
|
|
259
|
+
}
|
|
260
|
+
if (!value.kind) {
|
|
261
|
+
if (activity.channelId === Channels.Msteams) {
|
|
262
|
+
value.kind = 'search'
|
|
263
|
+
} else {
|
|
264
|
+
const response = this.createAdaptiveCardInvokeErrorResponse(
|
|
265
|
+
StatusCodes.BAD_REQUEST,
|
|
266
|
+
'BadRequest',
|
|
267
|
+
'Missing kind property for search.'
|
|
268
|
+
)
|
|
269
|
+
throw new InvokeException(StatusCodes.BAD_REQUEST, response)
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (!value.queryText) {
|
|
273
|
+
const response = this.createAdaptiveCardInvokeErrorResponse(
|
|
274
|
+
StatusCodes.BAD_REQUEST,
|
|
275
|
+
'BadRequest',
|
|
276
|
+
'Missing queryText for search.'
|
|
277
|
+
)
|
|
278
|
+
throw new InvokeException(StatusCodes.BAD_REQUEST, response)
|
|
279
|
+
}
|
|
280
|
+
return value
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** * Retrieves the AdaptiveCardInvoke value from the activity. */
|
|
284
|
+
private getAdaptiveCardInvokeValue (activity: Activity): AdaptiveCardInvokeValue {
|
|
285
|
+
const value = activity.value as AdaptiveCardInvokeValue
|
|
286
|
+
if (!value) {
|
|
287
|
+
const response = this.createAdaptiveCardInvokeErrorResponse(
|
|
288
|
+
StatusCodes.BAD_REQUEST,
|
|
289
|
+
'BadRequest',
|
|
290
|
+
'Missing value property'
|
|
291
|
+
)
|
|
292
|
+
throw new InvokeException(StatusCodes.BAD_REQUEST, response)
|
|
293
|
+
}
|
|
294
|
+
if (value.action.type !== 'Action.Execute') {
|
|
295
|
+
const response = this.createAdaptiveCardInvokeErrorResponse(
|
|
296
|
+
StatusCodes.BAD_REQUEST,
|
|
297
|
+
'NotSupported',
|
|
298
|
+
`The action '${value.action.type}' is not supported.`
|
|
299
|
+
)
|
|
300
|
+
throw new InvokeException(StatusCodes.BAD_REQUEST, response)
|
|
301
|
+
}
|
|
302
|
+
const { action, authentication, state } = value
|
|
303
|
+
const { data, id: actionId, type, verb } = action ?? {}
|
|
304
|
+
const { connectionName, id: authenticationId, token } = authentication ?? {}
|
|
305
|
+
return {
|
|
306
|
+
action: {
|
|
307
|
+
data,
|
|
308
|
+
id: actionId,
|
|
309
|
+
type,
|
|
310
|
+
verb
|
|
311
|
+
},
|
|
312
|
+
authentication: {
|
|
313
|
+
connectionName,
|
|
314
|
+
id: authenticationId,
|
|
315
|
+
token
|
|
316
|
+
},
|
|
317
|
+
state
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** * Creates an error response for AdaptiveCardInvoke. */
|
|
322
|
+
private createAdaptiveCardInvokeErrorResponse (
|
|
323
|
+
statusCode: StatusCodes,
|
|
324
|
+
code: string,
|
|
325
|
+
message: string
|
|
326
|
+
): AdaptiveCardInvokeResponse {
|
|
327
|
+
return {
|
|
328
|
+
statusCode,
|
|
329
|
+
type: 'application/vnd.microsoft.error',
|
|
330
|
+
value: { code, message }
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** * Handles the MessageReaction activity. */
|
|
335
|
+
protected async onMessageReactionActivity (context: TurnContext): Promise<void> {
|
|
336
|
+
await this.handle(context, 'MessageReaction', async () => {
|
|
337
|
+
await this.dispatchMessageReactionActivity(context)
|
|
338
|
+
})
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** * Handles the EndOfConversation activity. */
|
|
342
|
+
protected async onEndOfConversationActivity (context: TurnContext): Promise<void> {
|
|
343
|
+
await this.handle(context, 'EndOfConversation', this.defaultNextEvent(context))
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** * Handles the Typing activity. */
|
|
347
|
+
protected async onTypingActivity (context: TurnContext): Promise<void> {
|
|
348
|
+
await this.handle(context, 'Typing', this.defaultNextEvent(context))
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** * Handles the InstallationUpdate activity. */
|
|
352
|
+
protected async onInstallationUpdateActivity (context: TurnContext): Promise<void> {
|
|
353
|
+
switch (context.activity.action) {
|
|
354
|
+
case 'add':
|
|
355
|
+
case 'add-upgrade':
|
|
356
|
+
await this.handle(context, 'InstallationUpdateAdd', this.defaultNextEvent(context))
|
|
357
|
+
return
|
|
358
|
+
case 'remove':
|
|
359
|
+
case 'remove-upgrade':
|
|
360
|
+
await this.handle(context, 'InstallationUpdateRemove', this.defaultNextEvent(context))
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** * Handles unrecognized activity types. */
|
|
365
|
+
protected async onUnrecognizedActivity (context: TurnContext): Promise<void> {
|
|
366
|
+
await this.handle(context, 'UnrecognizedActivityType', this.defaultNextEvent(context))
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** * Dispatches the ConversationUpdate activity. */
|
|
370
|
+
protected async dispatchConversationUpdateActivity (context: TurnContext): Promise<void> {
|
|
371
|
+
if ((context.activity.membersAdded != null) && context.activity.membersAdded.length > 0) {
|
|
372
|
+
await this.handle(context, 'MembersAdded', this.defaultNextEvent(context))
|
|
373
|
+
} else if ((context.activity.membersRemoved != null) && context.activity.membersRemoved.length > 0) {
|
|
374
|
+
await this.handle(context, 'MembersRemoved', this.defaultNextEvent(context))
|
|
375
|
+
} else {
|
|
376
|
+
await this.defaultNextEvent(context)()
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** * Dispatches the MessageReaction activity. */
|
|
381
|
+
protected async dispatchMessageReactionActivity (context: TurnContext): Promise<void> {
|
|
382
|
+
if ((context.activity.reactionsAdded != null) || (context.activity.reactionsRemoved != null)) {
|
|
383
|
+
if (context.activity.reactionsAdded?.length) {
|
|
384
|
+
await this.handle(context, 'ReactionsAdded', this.defaultNextEvent(context))
|
|
385
|
+
}
|
|
386
|
+
if (context.activity.reactionsRemoved?.length) {
|
|
387
|
+
await this.handle(context, 'ReactionsRemoved', this.defaultNextEvent(context))
|
|
388
|
+
}
|
|
389
|
+
} else {
|
|
390
|
+
await this.defaultNextEvent(context)()
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/** * Dispatches the MessageUpdate activity. */
|
|
395
|
+
protected async dispatchMessageUpdateActivity (context: TurnContext): Promise<void> {
|
|
396
|
+
await this.defaultNextEvent(context)()
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** * Dispatches the MessageDelete activity. */
|
|
400
|
+
protected async dispatchMessageDeleteActivity (context: TurnContext): Promise<void> {
|
|
401
|
+
await this.defaultNextEvent(context)()
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Returns the default next event handler.
|
|
406
|
+
*/
|
|
407
|
+
protected defaultNextEvent (context: TurnContext): () => Promise<void> {
|
|
408
|
+
const defaultHandler = async (): Promise<void> => {
|
|
409
|
+
await this.handle(context, 'Default', async () => {
|
|
410
|
+
// noop
|
|
411
|
+
})
|
|
412
|
+
}
|
|
413
|
+
return defaultHandler
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** * Registers a handler for a specific activity type. */
|
|
417
|
+
protected on (type: string, handler: AgentHandler) {
|
|
418
|
+
if (!this.handlers[type]) {
|
|
419
|
+
this.handlers[type] = [handler]
|
|
420
|
+
} else {
|
|
421
|
+
this.handlers[type].push(handler)
|
|
422
|
+
}
|
|
423
|
+
return this
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** * Executes the handlers for a specific activity type. */
|
|
427
|
+
protected async handle (context: TurnContext, type: string, onNext: () => Promise<void>): Promise<any> {
|
|
428
|
+
let returnValue: any = null
|
|
429
|
+
async function runHandler (index: number): Promise<void> {
|
|
430
|
+
if (index < handlers.length) {
|
|
431
|
+
const val = await handlers[index](context, async () => await runHandler(index + 1))
|
|
432
|
+
if (typeof val !== 'undefined' && returnValue === null) {
|
|
433
|
+
returnValue = val
|
|
434
|
+
}
|
|
435
|
+
} else {
|
|
436
|
+
const val = await onNext()
|
|
437
|
+
if (typeof val !== 'undefined') {
|
|
438
|
+
returnValue = val
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
logger.info(`${type} handler called`)
|
|
443
|
+
const handlers = this.handlers[type] || []
|
|
444
|
+
await runHandler(0)
|
|
445
|
+
return returnValue
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/** * Creates an InvokeResponse object. */
|
|
449
|
+
protected static createInvokeResponse (body?: any): InvokeResponse {
|
|
450
|
+
return { status: 200, body }
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/** * Dispatches the Event activity. */
|
|
454
|
+
protected async dispatchEventActivity (context: TurnContext): Promise<void> {
|
|
455
|
+
if (context.activity.name === tokenResponseEventName) {
|
|
456
|
+
await this.handle(context, 'TokenResponseEvent', this.defaultNextEvent(context))
|
|
457
|
+
} else {
|
|
458
|
+
await this.defaultNextEvent(context)()
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { AuthConfiguration, MsalTokenProvider } from '../auth'
|
|
2
|
+
import { Activity, RoleTypes } from '@microsoft/agents-activity'
|
|
3
|
+
import { v4 } from 'uuid'
|
|
4
|
+
import { debug } from '../logger'
|
|
5
|
+
import { MemoryStorage, StoreItem } from '../storage'
|
|
6
|
+
|
|
7
|
+
const logger = debug('agents:agent-client')
|
|
8
|
+
|
|
9
|
+
export interface AgentClientConfig {
|
|
10
|
+
endPoint: string
|
|
11
|
+
clientId: string
|
|
12
|
+
serviceUrl: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class AgentClient {
|
|
16
|
+
agentClientConfig: AgentClientConfig
|
|
17
|
+
|
|
18
|
+
public constructor (agentConfigKey: string) {
|
|
19
|
+
this.agentClientConfig = this.loadAgentClientConfig(agentConfigKey)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public async postActivity (activity: Activity, authConfig: AuthConfiguration): Promise<string> {
|
|
23
|
+
const activityCopy = activity.clone()
|
|
24
|
+
activityCopy.serviceUrl = this.agentClientConfig.serviceUrl
|
|
25
|
+
activityCopy.recipient = { ...activityCopy.recipient, role: RoleTypes.Skill }
|
|
26
|
+
activityCopy.relatesTo = {
|
|
27
|
+
serviceUrl: activity.serviceUrl,
|
|
28
|
+
activityId: activityCopy.id,
|
|
29
|
+
channelId: activityCopy.channelId!,
|
|
30
|
+
locale: activityCopy.locale,
|
|
31
|
+
conversation: {
|
|
32
|
+
id: activity.conversation!.id,
|
|
33
|
+
...activityCopy.conversation
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
activityCopy.conversation!.id = v4()
|
|
37
|
+
|
|
38
|
+
const memory = MemoryStorage.getSingleInstance()
|
|
39
|
+
const changes: StoreItem = {} as StoreItem
|
|
40
|
+
changes[activityCopy.conversation!.id] = {
|
|
41
|
+
conversationReference: activity.getConversationReference()
|
|
42
|
+
}
|
|
43
|
+
await memory.write(changes)
|
|
44
|
+
const memoryChanges = JSON.stringify(changes)
|
|
45
|
+
logger.debug('memoryChanges: ', memoryChanges)
|
|
46
|
+
|
|
47
|
+
const authProvider = new MsalTokenProvider()
|
|
48
|
+
const token = await authProvider.getAccessToken(authConfig, this.agentClientConfig.clientId)
|
|
49
|
+
|
|
50
|
+
logger.debug('agent request: ', activityCopy)
|
|
51
|
+
|
|
52
|
+
const response = await fetch(this.agentClientConfig.endPoint, {
|
|
53
|
+
method: 'POST',
|
|
54
|
+
headers: {
|
|
55
|
+
'Content-Type': 'application/json',
|
|
56
|
+
Authorization: `Bearer ${token}`,
|
|
57
|
+
'x-ms-conversation-id': activityCopy.conversation!.id
|
|
58
|
+
},
|
|
59
|
+
body: JSON.stringify(activityCopy)
|
|
60
|
+
})
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
throw new Error(`Failed to post activity to agent: ${response.statusText}`)
|
|
63
|
+
}
|
|
64
|
+
return response.statusText
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private loadAgentClientConfig (agentName: string): AgentClientConfig {
|
|
68
|
+
if (agentName) {
|
|
69
|
+
if (process.env[`${agentName}_endpoint`] !== undefined &&
|
|
70
|
+
process.env[`${agentName}_clientId`] !== undefined &&
|
|
71
|
+
process.env[`${agentName}_serviceUrl`] !== undefined) {
|
|
72
|
+
return {
|
|
73
|
+
endPoint: process.env[`${agentName}_endpoint`]!,
|
|
74
|
+
clientId: process.env[`${agentName}_clientId`]!,
|
|
75
|
+
serviceUrl: process.env[`${agentName}_serviceUrl`]!
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
throw new Error(`Missing agent client config for agent ${agentName}`)
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
throw new Error('Agent name is required')
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Activity, ActivityTypes } from '@microsoft/agents-activity'
|
|
2
|
+
import { ActivityHandler } from '../activityHandler'
|
|
3
|
+
import { CloudAdapter } from '../cloudAdapter'
|
|
4
|
+
import { Request, Response, Application } from 'express'
|
|
5
|
+
import { MemoryStorage } from '../storage'
|
|
6
|
+
import { TurnContext } from '../turnContext'
|
|
7
|
+
import { v4 } from 'uuid'
|
|
8
|
+
import { debug } from '../logger'
|
|
9
|
+
|
|
10
|
+
const logger = debug('agents:agent-client')
|
|
11
|
+
|
|
12
|
+
export const configureResponseController = (app: Application, adapter: CloudAdapter, agent: ActivityHandler) => {
|
|
13
|
+
app.post('/api/botresponse/v3/conversations/:conversationId/activities/:activityId', handleResponse(adapter, agent))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const handleResponse = (adapter: CloudAdapter, handler: ActivityHandler) => async (req: Request, res: Response) => {
|
|
17
|
+
const activity = Activity.fromObject(req.body!)
|
|
18
|
+
|
|
19
|
+
logger.debug('received response: ', activity)
|
|
20
|
+
|
|
21
|
+
const requestData = await MemoryStorage.getSingleInstance().read([req.params!.conversationId])
|
|
22
|
+
const conversationReference = requestData[req.params!.conversationId].conversationReference
|
|
23
|
+
logger.debug('memoryChanges: ', requestData)
|
|
24
|
+
|
|
25
|
+
const callback = async (turnContext: TurnContext) => {
|
|
26
|
+
activity.applyConversationReference(conversationReference)
|
|
27
|
+
turnContext.activity.id = req.params!.activityId
|
|
28
|
+
|
|
29
|
+
let response
|
|
30
|
+
if (activity.type === ActivityTypes.EndOfConversation) {
|
|
31
|
+
await MemoryStorage.getSingleInstance().delete([activity.conversation!.id])
|
|
32
|
+
|
|
33
|
+
applyActivityToTurnContext(turnContext, activity)
|
|
34
|
+
await handler.run(turnContext)
|
|
35
|
+
|
|
36
|
+
response = v4().replace(/-/g, '')
|
|
37
|
+
} else {
|
|
38
|
+
response = await turnContext.sendActivity(activity)
|
|
39
|
+
}
|
|
40
|
+
res.status(200).send(response)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
await adapter.continueConversation(conversationReference, callback, true)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const applyActivityToTurnContext = (turnContext : TurnContext, activity : Activity) => {
|
|
47
|
+
turnContext.activity.channelData = activity.channelData
|
|
48
|
+
turnContext.activity.code = activity.code
|
|
49
|
+
turnContext.activity.entities = activity.entities
|
|
50
|
+
turnContext.activity.locale = activity.locale
|
|
51
|
+
turnContext.activity.localTimestamp = activity.localTimestamp
|
|
52
|
+
turnContext.activity.name = activity.name
|
|
53
|
+
turnContext.activity.relatesTo = activity.relatesTo
|
|
54
|
+
turnContext.activity.replyToId = activity.replyToId
|
|
55
|
+
turnContext.activity.timestamp = activity.timestamp
|
|
56
|
+
turnContext.activity.text = activity.text
|
|
57
|
+
turnContext.activity.type = activity.type
|
|
58
|
+
turnContext.activity.value = activity.value
|
|
59
|
+
}
|