@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,401 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { TurnState } from './turnState'
|
|
7
|
+
import { BaseAdapter } from '../baseAdapter'
|
|
8
|
+
import { Activity, ActivityTypes, ConversationReference } from '@microsoft/agents-activity'
|
|
9
|
+
import { ApplicationOptions } from './applicationOptions'
|
|
10
|
+
import { RouteSelector } from './routeSelector'
|
|
11
|
+
import { RouteHandler } from './routeHandler'
|
|
12
|
+
import { ConversationUpdateEvents } from './conversationUpdateEvents'
|
|
13
|
+
import { TurnEvents } from './turnEvents'
|
|
14
|
+
import { AppRoute } from './appRoute'
|
|
15
|
+
import { TurnContext } from '../turnContext'
|
|
16
|
+
import { ResourceResponse } from '../connector-client'
|
|
17
|
+
import { debug } from '../logger'
|
|
18
|
+
import { WebChatOAuthFlowAppStyle } from './oauth/webChatOAuthFlowAppStyle'
|
|
19
|
+
import { MemoryStorage } from '../storage'
|
|
20
|
+
|
|
21
|
+
const logger = debug('agents:agent-application')
|
|
22
|
+
|
|
23
|
+
const TYPING_TIMER_DELAY = 1000
|
|
24
|
+
type ApplicationEventHandler<TState extends TurnState> = (context: TurnContext, state: TState) => Promise<boolean>
|
|
25
|
+
|
|
26
|
+
export class AgentApplication<TState extends TurnState> {
|
|
27
|
+
protected readonly _options: ApplicationOptions<TState>
|
|
28
|
+
protected readonly _routes: AppRoute<TState>[] = []
|
|
29
|
+
protected readonly _beforeTurn: ApplicationEventHandler<TState>[] = []
|
|
30
|
+
protected readonly _afterTurn: ApplicationEventHandler<TState>[] = []
|
|
31
|
+
private readonly _adapter?: BaseAdapter
|
|
32
|
+
private _typingTimer: any
|
|
33
|
+
private readonly _authManager?: WebChatOAuthFlowAppStyle
|
|
34
|
+
|
|
35
|
+
public constructor (options?: Partial<ApplicationOptions<TState>>) {
|
|
36
|
+
this._options = {
|
|
37
|
+
...options,
|
|
38
|
+
turnStateFactory: options?.turnStateFactory || (() => new TurnState() as TState),
|
|
39
|
+
startTypingTimer: options?.startTypingTimer !== undefined ? options.startTypingTimer : true,
|
|
40
|
+
longRunningMessages: options?.longRunningMessages !== undefined ? options.longRunningMessages : false
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (this._options.adapter) {
|
|
44
|
+
this._adapter = this._options.adapter
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (this._options.authentication && this._options.authentication.enableSSO) {
|
|
48
|
+
this._authManager = new WebChatOAuthFlowAppStyle(this._options.storage ?? new MemoryStorage())
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (this._options.longRunningMessages && !this._adapter && !this._options.agentAppId) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
'The Application.longRunningMessages property is unavailable because no adapter or agentAppId was configured.'
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public get adapter (): BaseAdapter {
|
|
59
|
+
if (!this._adapter) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
'The Application.adapter property is unavailable because it was not configured when creating the Application.'
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return this._adapter
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public get authManager (): WebChatOAuthFlowAppStyle {
|
|
69
|
+
if (!this._authManager) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
'The Application.authentication property is unavailable because no authentication options were configured.'
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return this._authManager
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public get options (): ApplicationOptions<TState> {
|
|
79
|
+
return this._options
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public error (handler: (context: TurnContext, error: Error) => Promise<void>): this {
|
|
83
|
+
if (this._adapter) {
|
|
84
|
+
this._adapter.onTurnError = handler
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return this
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public addRoute (selector: RouteSelector, handler: RouteHandler<TState>): this {
|
|
91
|
+
this._routes.push({ selector, handler })
|
|
92
|
+
return this
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public activity (
|
|
96
|
+
type: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[],
|
|
97
|
+
handler: (context: TurnContext, state: TState) => Promise<void>
|
|
98
|
+
): this {
|
|
99
|
+
(Array.isArray(type) ? type : [type]).forEach((t) => {
|
|
100
|
+
const selector = this.createActivitySelector(t)
|
|
101
|
+
this.addRoute(selector, handler)
|
|
102
|
+
})
|
|
103
|
+
return this
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public conversationUpdate (
|
|
107
|
+
event: ConversationUpdateEvents,
|
|
108
|
+
handler: (context: TurnContext, state: TState) => Promise<void>
|
|
109
|
+
): this {
|
|
110
|
+
if (typeof handler !== 'function') {
|
|
111
|
+
throw new Error(
|
|
112
|
+
`ConversationUpdate 'handler' for ${event} is ${typeof handler}. Type of 'handler' must be a function.`
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const selector = this.createConversationUpdateSelector(event)
|
|
117
|
+
this.addRoute(selector, handler)
|
|
118
|
+
return this
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
protected async continueConversationAsync (
|
|
122
|
+
conversationReferenceOrContext: ConversationReference | TurnContext,
|
|
123
|
+
logic: (context: TurnContext) => Promise<void>
|
|
124
|
+
): Promise<void> {
|
|
125
|
+
if (!this._adapter) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
"You must configure the Application with an 'adapter' before calling Application.continueConversationAsync()"
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!this.options.agentAppId) {
|
|
132
|
+
console.warn(
|
|
133
|
+
"Calling Application.continueConversationAsync() without a configured 'agentAppId'. In production environments, a 'agentAppId' is required."
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let reference: ConversationReference
|
|
138
|
+
|
|
139
|
+
if ('activity' in conversationReferenceOrContext) {
|
|
140
|
+
reference = conversationReferenceOrContext.activity.getConversationReference()
|
|
141
|
+
} else {
|
|
142
|
+
reference = conversationReferenceOrContext
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
await this._adapter.continueConversation(reference, logic)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public message (
|
|
149
|
+
keyword: string | RegExp | RouteSelector | (string | RegExp | RouteSelector)[],
|
|
150
|
+
handler: (context: TurnContext, state: TState) => Promise<void>
|
|
151
|
+
): this {
|
|
152
|
+
(Array.isArray(keyword) ? keyword : [keyword]).forEach((k) => {
|
|
153
|
+
const selector = this.createMessageSelector(k)
|
|
154
|
+
this.addRoute(selector, handler)
|
|
155
|
+
})
|
|
156
|
+
return this
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public async run (turnContext: TurnContext): Promise<boolean> {
|
|
160
|
+
return await this.startLongRunningCall(turnContext, async (context) => {
|
|
161
|
+
this.startTypingTimer(context)
|
|
162
|
+
try {
|
|
163
|
+
const { storage, turnStateFactory } = this._options
|
|
164
|
+
const state = turnStateFactory()
|
|
165
|
+
await state.load(context, storage)
|
|
166
|
+
|
|
167
|
+
if (!(await this.callEventHandlers(context, state, this._beforeTurn))) {
|
|
168
|
+
await state.save(context, storage)
|
|
169
|
+
return false
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (typeof state.temp.input !== 'string') {
|
|
173
|
+
state.temp.input = context.activity.text ?? ''
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (Array.isArray(this._options.fileDownloaders) && this._options.fileDownloaders.length > 0) {
|
|
177
|
+
const inputFiles = state.temp.inputFiles ?? []
|
|
178
|
+
for (let i = 0; i < this._options.fileDownloaders.length; i++) {
|
|
179
|
+
const files = await this._options.fileDownloaders[i].downloadFiles(context, state)
|
|
180
|
+
inputFiles.push(...files)
|
|
181
|
+
}
|
|
182
|
+
state.temp.inputFiles = inputFiles
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (state.temp.actionOutputs === undefined) {
|
|
186
|
+
state.temp.actionOutputs = {}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
for (let i = 0; i < this._routes.length; i++) {
|
|
190
|
+
const route = this._routes[i]
|
|
191
|
+
if (await route.selector(context)) {
|
|
192
|
+
await route.handler(context, state)
|
|
193
|
+
|
|
194
|
+
if (await this.callEventHandlers(context, state, this._afterTurn)) {
|
|
195
|
+
await state.save(context, storage)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return true
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (await this.callEventHandlers(context, state, this._afterTurn)) {
|
|
203
|
+
await state.save(context, storage)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return false
|
|
207
|
+
} catch (err: any) {
|
|
208
|
+
logger.error(err)
|
|
209
|
+
throw err
|
|
210
|
+
} finally {
|
|
211
|
+
this.stopTypingTimer()
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
public async sendProactiveActivity (
|
|
217
|
+
context: TurnContext | ConversationReference,
|
|
218
|
+
activityOrText: string | Activity,
|
|
219
|
+
speak?: string,
|
|
220
|
+
inputHint?: string
|
|
221
|
+
): Promise<ResourceResponse | undefined> {
|
|
222
|
+
let response: ResourceResponse | undefined
|
|
223
|
+
await this.continueConversationAsync(context, async (ctx) => {
|
|
224
|
+
response = await ctx.sendActivity(activityOrText, speak, inputHint)
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
return response
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
public startTypingTimer (context: TurnContext): void {
|
|
231
|
+
if (context.activity.type === ActivityTypes.Message && !this._typingTimer) {
|
|
232
|
+
let timerRunning = true
|
|
233
|
+
context.onSendActivities(async (context, activities, next) => {
|
|
234
|
+
if (timerRunning) {
|
|
235
|
+
for (let i = 0; i < activities.length; i++) {
|
|
236
|
+
if (activities[i].type === ActivityTypes.Message || activities[i].channelData?.streamType) {
|
|
237
|
+
this.stopTypingTimer()
|
|
238
|
+
timerRunning = false
|
|
239
|
+
await lastSend
|
|
240
|
+
break
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return next()
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
let lastSend: Promise<any> = Promise.resolve()
|
|
249
|
+
const onTimeout = async () => {
|
|
250
|
+
try {
|
|
251
|
+
lastSend = context.sendActivity(Activity.fromObject({ type: ActivityTypes.Typing }))
|
|
252
|
+
await lastSend
|
|
253
|
+
} catch (err: any) {
|
|
254
|
+
logger.error(err)
|
|
255
|
+
this._typingTimer = undefined
|
|
256
|
+
timerRunning = false
|
|
257
|
+
lastSend = Promise.resolve()
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (timerRunning) {
|
|
261
|
+
this._typingTimer = setTimeout(onTimeout, TYPING_TIMER_DELAY)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
this._typingTimer = setTimeout(onTimeout, TYPING_TIMER_DELAY)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
public stopTypingTimer (): void {
|
|
269
|
+
if (this._typingTimer) {
|
|
270
|
+
clearTimeout(this._typingTimer)
|
|
271
|
+
this._typingTimer = undefined
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
public turn (
|
|
276
|
+
event: TurnEvents | TurnEvents[],
|
|
277
|
+
handler: (context: TurnContext, state: TState) => Promise<boolean>
|
|
278
|
+
): this {
|
|
279
|
+
(Array.isArray(event) ? event : [event]).forEach((e) => {
|
|
280
|
+
switch (e) {
|
|
281
|
+
case 'beforeTurn':
|
|
282
|
+
break
|
|
283
|
+
case 'afterTurn':
|
|
284
|
+
this._afterTurn.push(handler)
|
|
285
|
+
break
|
|
286
|
+
default:
|
|
287
|
+
this._beforeTurn.push(handler)
|
|
288
|
+
break
|
|
289
|
+
}
|
|
290
|
+
})
|
|
291
|
+
return this
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
protected async callEventHandlers (
|
|
295
|
+
context: TurnContext,
|
|
296
|
+
state: TState,
|
|
297
|
+
handlers: ApplicationEventHandler<TState>[]
|
|
298
|
+
): Promise<boolean> {
|
|
299
|
+
for (let i = 0; i < handlers.length; i++) {
|
|
300
|
+
const continueExecution = await handlers[i](context, state)
|
|
301
|
+
if (!continueExecution) {
|
|
302
|
+
return false
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return true
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
protected startLongRunningCall (
|
|
310
|
+
context: TurnContext,
|
|
311
|
+
handler: (context: TurnContext) => Promise<boolean>
|
|
312
|
+
): Promise<boolean> {
|
|
313
|
+
if (context.activity.type === ActivityTypes.Message && this._options.longRunningMessages) {
|
|
314
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
315
|
+
this.continueConversationAsync(context, async (ctx) => {
|
|
316
|
+
try {
|
|
317
|
+
for (const key in context.activity) {
|
|
318
|
+
(ctx.activity as any)[key] = (context.activity as any)[key]
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const result = await handler(ctx)
|
|
322
|
+
resolve(result)
|
|
323
|
+
} catch (err: any) {
|
|
324
|
+
logger.error(err)
|
|
325
|
+
reject(err)
|
|
326
|
+
}
|
|
327
|
+
})
|
|
328
|
+
})
|
|
329
|
+
} else {
|
|
330
|
+
return handler(context)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
private createActivitySelector (type: string | RegExp | RouteSelector): RouteSelector {
|
|
335
|
+
if (typeof type === 'function') {
|
|
336
|
+
return type
|
|
337
|
+
} else if (type instanceof RegExp) {
|
|
338
|
+
return (context: TurnContext) => {
|
|
339
|
+
return Promise.resolve(context?.activity?.type ? type.test(context.activity.type) : false)
|
|
340
|
+
}
|
|
341
|
+
} else {
|
|
342
|
+
const typeName = type.toString().toLocaleLowerCase()
|
|
343
|
+
return (context: TurnContext) => {
|
|
344
|
+
return Promise.resolve(
|
|
345
|
+
context?.activity?.type ? context.activity.type.toLocaleLowerCase() === typeName : false
|
|
346
|
+
)
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
private createConversationUpdateSelector (event: ConversationUpdateEvents): RouteSelector {
|
|
352
|
+
switch (event) {
|
|
353
|
+
case 'membersAdded':
|
|
354
|
+
return (context: TurnContext): Promise<boolean> => {
|
|
355
|
+
return Promise.resolve(
|
|
356
|
+
context?.activity?.type === ActivityTypes.ConversationUpdate &&
|
|
357
|
+
Array.isArray(context?.activity?.membersAdded) &&
|
|
358
|
+
context.activity.membersAdded.length > 0
|
|
359
|
+
)
|
|
360
|
+
}
|
|
361
|
+
case 'membersRemoved':
|
|
362
|
+
return (context: TurnContext): Promise<boolean> => {
|
|
363
|
+
return Promise.resolve(
|
|
364
|
+
context?.activity?.type === ActivityTypes.ConversationUpdate &&
|
|
365
|
+
Array.isArray(context?.activity?.membersRemoved) &&
|
|
366
|
+
context.activity.membersRemoved.length > 0
|
|
367
|
+
)
|
|
368
|
+
}
|
|
369
|
+
default:
|
|
370
|
+
return (context: TurnContext): Promise<boolean> => {
|
|
371
|
+
return Promise.resolve(
|
|
372
|
+
context?.activity?.type === ActivityTypes.ConversationUpdate &&
|
|
373
|
+
context?.activity?.channelData?.eventType === event
|
|
374
|
+
)
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
private createMessageSelector (keyword: string | RegExp | RouteSelector): RouteSelector {
|
|
380
|
+
if (typeof keyword === 'function') {
|
|
381
|
+
return keyword
|
|
382
|
+
} else if (keyword instanceof RegExp) {
|
|
383
|
+
return (context: TurnContext) => {
|
|
384
|
+
if (context?.activity?.type === ActivityTypes.Message && context.activity.text) {
|
|
385
|
+
return Promise.resolve(keyword.test(context.activity.text))
|
|
386
|
+
} else {
|
|
387
|
+
return Promise.resolve(false)
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
} else {
|
|
391
|
+
const k = keyword.toString().toLocaleLowerCase()
|
|
392
|
+
return (context: TurnContext) => {
|
|
393
|
+
if (context?.activity?.type === ActivityTypes.Message && context.activity.text) {
|
|
394
|
+
return Promise.resolve(context.activity.text.toLocaleLowerCase().indexOf(k) >= 0)
|
|
395
|
+
} else {
|
|
396
|
+
return Promise.resolve(false)
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { RouteHandler } from './routeHandler'
|
|
7
|
+
import { RouteSelector } from './routeSelector'
|
|
8
|
+
import { TurnState } from './turnState'
|
|
9
|
+
|
|
10
|
+
export interface AppRoute<TState extends TurnState> {
|
|
11
|
+
selector: RouteSelector;
|
|
12
|
+
handler: RouteHandler<TState>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { AgentApplication } from './agentApplication'
|
|
7
|
+
import { ApplicationOptions } from './applicationOptions'
|
|
8
|
+
import { TurnState } from './turnState'
|
|
9
|
+
import { Storage } from '../storage'
|
|
10
|
+
import { AuthenticationOptions } from './oauth/authenticationOptions'
|
|
11
|
+
|
|
12
|
+
export class ApplicationBuilder<TState extends TurnState = TurnState> {
|
|
13
|
+
protected _options: Partial<ApplicationOptions<TState>> = {}
|
|
14
|
+
|
|
15
|
+
protected get options () {
|
|
16
|
+
return this._options
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public withStorage (storage: Storage): this {
|
|
20
|
+
this._options.storage = storage
|
|
21
|
+
return this
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public withTurnStateFactory (turnStateFactory: () => TState): this {
|
|
25
|
+
this._options.turnStateFactory = turnStateFactory
|
|
26
|
+
return this
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public setStartTypingTimer (startTypingTimer: boolean): this {
|
|
30
|
+
this._options.startTypingTimer = startTypingTimer
|
|
31
|
+
return this
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public withAuthentication (authenticationOptions: AuthenticationOptions): this {
|
|
35
|
+
this._options.authentication = authenticationOptions
|
|
36
|
+
return this
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public build (): AgentApplication<TState> {
|
|
40
|
+
return new AgentApplication(this._options)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { CloudAdapter } from '../cloudAdapter'
|
|
7
|
+
import { InputFileDownloader } from './inputFileDownloader'
|
|
8
|
+
import { TurnState } from './turnState'
|
|
9
|
+
import { Storage } from '../storage'
|
|
10
|
+
import { AuthenticationOptions } from './oauth/authenticationOptions'
|
|
11
|
+
|
|
12
|
+
export interface ApplicationOptions<TState extends TurnState> {
|
|
13
|
+
adapter?: CloudAdapter;
|
|
14
|
+
agentAppId?: string;
|
|
15
|
+
storage?: Storage;
|
|
16
|
+
startTypingTimer: boolean;
|
|
17
|
+
longRunningMessages: boolean;
|
|
18
|
+
turnStateFactory: () => TState;
|
|
19
|
+
fileDownloaders?: InputFileDownloader<TState>[];
|
|
20
|
+
authentication?: AuthenticationOptions;
|
|
21
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import axios, { AxiosInstance } from 'axios'
|
|
7
|
+
import { InputFile, InputFileDownloader } from './inputFileDownloader'
|
|
8
|
+
import { TurnState } from './turnState'
|
|
9
|
+
import { TurnContext } from '../turnContext'
|
|
10
|
+
import { Attachment } from '@microsoft/agents-activity'
|
|
11
|
+
import { AuthProvider } from '../auth/authProvider'
|
|
12
|
+
import { debug } from '../logger'
|
|
13
|
+
import { loadAuthConfigFromEnv, MsalTokenProvider } from '../auth'
|
|
14
|
+
|
|
15
|
+
const logger = debug('agents:attachmentDownloader')
|
|
16
|
+
|
|
17
|
+
export class AttachmentDownloader<TState extends TurnState = TurnState> implements InputFileDownloader<TState> {
|
|
18
|
+
private _httpClient: AxiosInstance
|
|
19
|
+
|
|
20
|
+
public constructor () {
|
|
21
|
+
this._httpClient = axios.create()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public async downloadFiles (context: TurnContext, state: TState): Promise<InputFile[]> {
|
|
25
|
+
const attachments = context.activity.attachments?.filter((a) => !a.contentType.startsWith('text/html'))
|
|
26
|
+
if (!attachments || attachments.length === 0) {
|
|
27
|
+
logger.info('No Attachments to download')
|
|
28
|
+
return Promise.resolve([])
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const authProvider: AuthProvider = new MsalTokenProvider()
|
|
32
|
+
|
|
33
|
+
const accessToken = await authProvider.getAccessToken(loadAuthConfigFromEnv(), 'https://api.botframework.com')
|
|
34
|
+
|
|
35
|
+
const files: InputFile[] = []
|
|
36
|
+
for (const attachment of attachments) {
|
|
37
|
+
const file = await this.downloadFile(attachment, accessToken)
|
|
38
|
+
if (file) {
|
|
39
|
+
files.push(file)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
logger.info('Attachments downloaded')
|
|
44
|
+
return files
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private async downloadFile (attachment: Attachment, accessToken: string): Promise<InputFile | undefined> {
|
|
48
|
+
if (
|
|
49
|
+
(attachment.contentUrl && attachment.contentUrl.startsWith('https://')) ||
|
|
50
|
+
(attachment.contentUrl && attachment.contentUrl.startsWith('http://localhost'))
|
|
51
|
+
) {
|
|
52
|
+
let headers
|
|
53
|
+
if (accessToken.length > 0) {
|
|
54
|
+
headers = {
|
|
55
|
+
Authorization: `Bearer ${accessToken}`
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const response = await this._httpClient.get(attachment.contentUrl, {
|
|
59
|
+
headers,
|
|
60
|
+
responseType: 'arraybuffer'
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const content = Buffer.from(response.data, 'binary')
|
|
64
|
+
|
|
65
|
+
let contentType = attachment.contentType
|
|
66
|
+
if (contentType === 'image/*') {
|
|
67
|
+
contentType = 'image/png'
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
content,
|
|
72
|
+
contentType,
|
|
73
|
+
contentUrl: attachment.contentUrl
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
return {
|
|
77
|
+
content: Buffer.from(attachment.content as any),
|
|
78
|
+
contentType: attachment.contentType,
|
|
79
|
+
contentUrl: attachment.contentUrl
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/app/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './agentApplication'
|
|
2
|
+
export * from './applicationBuilder'
|
|
3
|
+
export * from './applicationOptions'
|
|
4
|
+
export * from './appRoute'
|
|
5
|
+
export * from './attachmentDownloader'
|
|
6
|
+
export * from './oauth/webChatOAuthFlowAppStyle'
|
|
7
|
+
export * from './conversationUpdateEvents'
|
|
8
|
+
export * from './routeHandler'
|
|
9
|
+
export * from './routeSelector'
|
|
10
|
+
export * from './turnState'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { TurnContext } from '../turnContext'
|
|
7
|
+
import { TurnState } from './turnState'
|
|
8
|
+
|
|
9
|
+
export interface InputFile {
|
|
10
|
+
content: Buffer;
|
|
11
|
+
contentType: string;
|
|
12
|
+
contentUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface InputFileDownloader<TState extends TurnState = TurnState> {
|
|
16
|
+
downloadFiles(context: TurnContext, state: TState): Promise<InputFile[]>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface Memory {
|
|
7
|
+
deleteValue(path: string): void;
|
|
8
|
+
|
|
9
|
+
hasValue(path: string): boolean;
|
|
10
|
+
|
|
11
|
+
getValue<TValue = unknown>(path: string): TValue;
|
|
12
|
+
|
|
13
|
+
setValue(path: string, value: unknown): void;
|
|
14
|
+
}
|