@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,151 @@
|
|
|
1
|
+
import { TurnContext } from '../turnContext'
|
|
2
|
+
import { ResourceResponse } from '../connector-client'
|
|
3
|
+
import { Middleware } from '../middlewareSet'
|
|
4
|
+
import { TranscriptLogger } from './transcriptLogger'
|
|
5
|
+
import { Activity, ActivityEventNames, ActivityTypes, ConversationReference, RoleTypes } from '@microsoft/agents-activity'
|
|
6
|
+
import { debug } from '../logger'
|
|
7
|
+
|
|
8
|
+
const appLogger = debug('agents:rest-client')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Middleware for logging agent conversations to a transcript logger.
|
|
12
|
+
*/
|
|
13
|
+
export class TranscriptLoggerMiddleware implements Middleware {
|
|
14
|
+
private logger: TranscriptLogger
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new instance of the TranscriptLoggerMiddleware class.
|
|
18
|
+
* @param logger The transcript logger to use.
|
|
19
|
+
* @throws Will throw an error if the logger is not provided.
|
|
20
|
+
*/
|
|
21
|
+
constructor (logger: TranscriptLogger) {
|
|
22
|
+
if (!logger) {
|
|
23
|
+
throw new Error('TranscriptLoggerMiddleware requires a TranscriptLogger instance.')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.logger = logger
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Called each time the agent processes a turn.
|
|
31
|
+
* @param context The context object for the turn.
|
|
32
|
+
* @param next The next middleware or handler to call.
|
|
33
|
+
*/
|
|
34
|
+
async onTurn (context: TurnContext, next: () => Promise<void>): Promise<void> {
|
|
35
|
+
const transcript: Activity[] = []
|
|
36
|
+
if (context.activity && context.activity.from) {
|
|
37
|
+
if (!context.activity.from.role) {
|
|
38
|
+
context.activity.from.role = RoleTypes.User
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.logActivity(transcript, this.cloneActivity(context.activity))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
context.onSendActivities(
|
|
45
|
+
async (ctx: TurnContext, activities: Partial<Activity>[], next: () => Promise<ResourceResponse[]>) => {
|
|
46
|
+
const responses = await next()
|
|
47
|
+
|
|
48
|
+
activities.forEach((activity, index) => {
|
|
49
|
+
const clonedActivity = this.cloneActivity(activity)
|
|
50
|
+
clonedActivity.id = responses && responses[index] ? responses[index].id : clonedActivity.id
|
|
51
|
+
|
|
52
|
+
if (!clonedActivity.id) {
|
|
53
|
+
const prefix = `g_${Math.random().toString(36).slice(2, 8)}`
|
|
54
|
+
if (clonedActivity.timestamp) {
|
|
55
|
+
clonedActivity.id = `${prefix}${new Date(clonedActivity.timestamp).getTime().toString()}`
|
|
56
|
+
} else {
|
|
57
|
+
clonedActivity.id = `${prefix}${new Date().getTime().toString()}`
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.logActivity(transcript, clonedActivity)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
return responses
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
context.onUpdateActivity(async (ctx: TurnContext, activity: Partial<Activity>, next: () => Promise<void>) => {
|
|
69
|
+
const response: void = await next()
|
|
70
|
+
|
|
71
|
+
const updateActivity = this.cloneActivity(activity)
|
|
72
|
+
updateActivity.type = ActivityTypes.MessageUpdate
|
|
73
|
+
this.logActivity(transcript, updateActivity)
|
|
74
|
+
|
|
75
|
+
return response
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
context.onDeleteActivity(
|
|
79
|
+
async (ctx: TurnContext, reference: Partial<ConversationReference>, next: () => Promise<void>) => {
|
|
80
|
+
await next()
|
|
81
|
+
|
|
82
|
+
// const deleteActivity = TurnContext.applyConversationReference(
|
|
83
|
+
// {
|
|
84
|
+
// type: ActivityTypes.MessageDelete,
|
|
85
|
+
// id: reference.activityId,
|
|
86
|
+
// },
|
|
87
|
+
// reference,
|
|
88
|
+
// false,
|
|
89
|
+
// );
|
|
90
|
+
|
|
91
|
+
// this.logActivity(transcript, this.cloneActivity(deleteActivity));
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
await next()
|
|
96
|
+
|
|
97
|
+
while (transcript.length) {
|
|
98
|
+
try {
|
|
99
|
+
const activity = transcript.shift()
|
|
100
|
+
if (activity) {
|
|
101
|
+
const maybePromise = this.logger.logActivity(activity)
|
|
102
|
+
|
|
103
|
+
if (maybePromise instanceof Promise) {
|
|
104
|
+
maybePromise.catch((err) => {
|
|
105
|
+
this.transcriptLoggerErrorHandler(err)
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} catch (err) {
|
|
110
|
+
this.transcriptLoggerErrorHandler(err)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Logs an activity to the transcript.
|
|
117
|
+
* @param transcript The transcript array to log the activity to.
|
|
118
|
+
* @param activity The activity to log.
|
|
119
|
+
*/
|
|
120
|
+
private logActivity (transcript: Activity[], activity: Activity): void {
|
|
121
|
+
if (!activity.timestamp) {
|
|
122
|
+
activity.timestamp = new Date()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!(activity.type === ActivityTypes.Event && activity.name === ActivityEventNames.ContinueConversation)) {
|
|
126
|
+
transcript.push(activity)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Creates a deep copy of an activity.
|
|
132
|
+
* @param activity The activity to clone.
|
|
133
|
+
* @returns A deep copy of the activity.
|
|
134
|
+
*/
|
|
135
|
+
private cloneActivity (activity: Partial<Activity>): Activity {
|
|
136
|
+
return Object.assign(<Activity>{}, activity)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Handles errors that occur during logging.
|
|
141
|
+
* @param err The error that occurred.
|
|
142
|
+
*/
|
|
143
|
+
private transcriptLoggerErrorHandler (err: Error | any): void {
|
|
144
|
+
if (err instanceof Error) {
|
|
145
|
+
appLogger.error(`TranscriptLoggerMiddleware logActivity failed: "${err.message}"`)
|
|
146
|
+
appLogger.error(JSON.stringify(err.stack))
|
|
147
|
+
} else {
|
|
148
|
+
appLogger.error(`TranscriptLoggerMiddleware logActivity failed: "${JSON.stringify(err)}"`)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Activity } from '@microsoft/agents-activity'
|
|
2
|
+
import { PagedResult, TranscriptInfo, TranscriptLogger } from './transcriptLogger'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Interface for storing and managing transcripts.
|
|
6
|
+
*/
|
|
7
|
+
export interface TranscriptStore extends TranscriptLogger {
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves activities from a transcript.
|
|
10
|
+
* @param channelId - The ID of the channel.
|
|
11
|
+
* @param conversationId - The ID of the conversation.
|
|
12
|
+
* @param continuationToken - Optional. The continuation token for pagination.
|
|
13
|
+
* @param startDate - Optional. The start date to filter activities.
|
|
14
|
+
* @returns A promise that resolves to a paged result of activities.
|
|
15
|
+
*/
|
|
16
|
+
getTranscriptActivities(
|
|
17
|
+
channelId: string,
|
|
18
|
+
conversationId: string,
|
|
19
|
+
continuationToken?: string,
|
|
20
|
+
startDate?: Date,
|
|
21
|
+
): Promise<PagedResult<Activity>>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Lists transcripts for a channel.
|
|
25
|
+
* @param channelId - The ID of the channel.
|
|
26
|
+
* @param continuationToken - Optional. The continuation token for pagination.
|
|
27
|
+
* @returns A promise that resolves to a paged result of transcript information.
|
|
28
|
+
*/
|
|
29
|
+
listTranscripts(channelId: string, continuationToken?: string): Promise<PagedResult<TranscriptInfo>>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Deletes a transcript.
|
|
33
|
+
* @param channelId - The ID of the channel.
|
|
34
|
+
* @param conversationId - The ID of the conversation.
|
|
35
|
+
* @returns A promise that resolves when the transcript is deleted.
|
|
36
|
+
*/
|
|
37
|
+
deleteTranscript(channelId: string, conversationId: string): Promise<void>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */
|
|
2
|
+
import { INVOKE_RESPONSE_KEY } from './activityHandler'
|
|
3
|
+
import { BaseAdapter } from './baseAdapter'
|
|
4
|
+
import { Activity, ActivityTypes, ConversationReference, DeliveryModes, InputHints } from '@microsoft/agents-activity'
|
|
5
|
+
import { ResourceResponse } from './connector-client/resourceResponse'
|
|
6
|
+
import { TurnContextStateCollection } from './turnContextStateCollection'
|
|
7
|
+
import { AttachmentInfo } from './connector-client/attachmentInfo'
|
|
8
|
+
import { AttachmentData } from './connector-client/attachmentData'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Defines a handler for sending activities.
|
|
12
|
+
*/
|
|
13
|
+
export type SendActivitiesHandler = (context: TurnContext, activities: Activity[], next: () => Promise<ResourceResponse[]>) => Promise<ResourceResponse[]>
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Defines a handler for updating an activity.
|
|
17
|
+
*/
|
|
18
|
+
export type UpdateActivityHandler = (context: TurnContext, activity: Activity, next: () => Promise<void>) => Promise<void>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Defines a handler for deleting an activity.
|
|
22
|
+
*/
|
|
23
|
+
export type DeleteActivityHandler = (context: TurnContext, reference: ConversationReference, next: () => Promise<void>) => Promise<void>
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Key for the agent callback handler.
|
|
27
|
+
*/
|
|
28
|
+
export const AgentCallbackHandlerKey = 'agentCallbackHandler'
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Interface for TurnContext.
|
|
32
|
+
*/
|
|
33
|
+
export interface TurnContext {}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Represents the context object for a turn of an Agent.
|
|
37
|
+
*/
|
|
38
|
+
export class TurnContext {
|
|
39
|
+
private readonly _adapter?: BaseAdapter
|
|
40
|
+
private readonly _activity?: Activity
|
|
41
|
+
private readonly _respondedRef: { responded: boolean } = { responded: false }
|
|
42
|
+
private readonly _turnState = new TurnContextStateCollection()
|
|
43
|
+
private readonly _onSendActivities: SendActivitiesHandler[] = []
|
|
44
|
+
private readonly _onUpdateActivity: UpdateActivityHandler[] = []
|
|
45
|
+
private readonly _onDeleteActivity: DeleteActivityHandler[] = []
|
|
46
|
+
private readonly _turn = 'turn'
|
|
47
|
+
private readonly _locale = 'locale'
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Initializes a new instance of the TurnContext class.
|
|
51
|
+
* @param adapterOrContext The adapter or context for the turn.
|
|
52
|
+
* @param request The activity for the turn.
|
|
53
|
+
*/
|
|
54
|
+
constructor (adapterOrContext: BaseAdapter, request: Activity)
|
|
55
|
+
constructor (adapterOrContext: TurnContext)
|
|
56
|
+
constructor (adapterOrContext: BaseAdapter | TurnContext, request?: Activity) {
|
|
57
|
+
if (adapterOrContext instanceof TurnContext) {
|
|
58
|
+
adapterOrContext.copyTo(this)
|
|
59
|
+
} else {
|
|
60
|
+
this._adapter = adapterOrContext
|
|
61
|
+
this._activity = request as Activity
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A list of buffered reply activities.
|
|
67
|
+
*/
|
|
68
|
+
readonly bufferedReplyActivities: Activity[] = []
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Sends a trace activity.
|
|
72
|
+
* @param name The name of the trace activity.
|
|
73
|
+
* @param value The value of the trace activity.
|
|
74
|
+
* @param valueType The value type of the trace activity.
|
|
75
|
+
* @param label The label of the trace activity.
|
|
76
|
+
* @returns The resource response.
|
|
77
|
+
*/
|
|
78
|
+
async sendTraceActivity (name: string, value?: any, valueType?: string, label?: string): Promise<ResourceResponse | undefined> {
|
|
79
|
+
const traceActivityObj = {
|
|
80
|
+
type: ActivityTypes.Trace,
|
|
81
|
+
timestamp: new Date().toISOString(),
|
|
82
|
+
name,
|
|
83
|
+
value,
|
|
84
|
+
valueType,
|
|
85
|
+
label
|
|
86
|
+
}
|
|
87
|
+
const traceActivity = Activity.fromObject(traceActivityObj)
|
|
88
|
+
return await this.sendActivity(traceActivity)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Sends an activity.
|
|
93
|
+
* @param activityOrText The activity or text to send.
|
|
94
|
+
* @param speak The text to speak.
|
|
95
|
+
* @param inputHint The input hint.
|
|
96
|
+
* @returns The resource response.
|
|
97
|
+
*/
|
|
98
|
+
async sendActivity (activityOrText: string | Activity, speak?: string, inputHint?: string): Promise<ResourceResponse | undefined> {
|
|
99
|
+
let activityObject: {}
|
|
100
|
+
if (typeof activityOrText === 'string') {
|
|
101
|
+
activityObject = { type: ActivityTypes.Message, text: activityOrText, inputHint: inputHint || InputHints.AcceptingInput }
|
|
102
|
+
if (speak) {
|
|
103
|
+
activityObject = { ...activityObject, speak }
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
activityObject = activityOrText
|
|
107
|
+
}
|
|
108
|
+
const activity = Activity.fromObject(activityObject)
|
|
109
|
+
|
|
110
|
+
const responses = (await this.sendActivities([activity])) || []
|
|
111
|
+
return responses[0]
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Sends multiple activities.
|
|
116
|
+
* @param activities The activities to send.
|
|
117
|
+
* @returns The resource responses.
|
|
118
|
+
*/
|
|
119
|
+
async sendActivities (activities: Activity[]): Promise<ResourceResponse[]> {
|
|
120
|
+
let sentNonTraceActivity = false
|
|
121
|
+
const ref = this.activity.getConversationReference()
|
|
122
|
+
const output = activities.map((activity) => {
|
|
123
|
+
const result = activity.applyConversationReference(ref)
|
|
124
|
+
if (!result.type) {
|
|
125
|
+
result.type = ActivityTypes.Message
|
|
126
|
+
}
|
|
127
|
+
if (result.type === ActivityTypes.InvokeResponse) {
|
|
128
|
+
this.turnState.set(INVOKE_RESPONSE_KEY, activity)
|
|
129
|
+
}
|
|
130
|
+
if (result.type !== ActivityTypes.Trace) {
|
|
131
|
+
sentNonTraceActivity = true
|
|
132
|
+
}
|
|
133
|
+
if (result.id) {
|
|
134
|
+
delete result.id
|
|
135
|
+
}
|
|
136
|
+
return result
|
|
137
|
+
})
|
|
138
|
+
return await this.emit(this._onSendActivities, output, async () => {
|
|
139
|
+
if (this.activity.deliveryMode === DeliveryModes.ExpectReplies) {
|
|
140
|
+
const responses: ResourceResponse[] = []
|
|
141
|
+
output.forEach((a) => {
|
|
142
|
+
this.bufferedReplyActivities.push(a)
|
|
143
|
+
if (a.type === ActivityTypes.InvokeResponse) {
|
|
144
|
+
this.turnState.set(INVOKE_RESPONSE_KEY, a)
|
|
145
|
+
}
|
|
146
|
+
responses.push({ id: '' })
|
|
147
|
+
})
|
|
148
|
+
if (sentNonTraceActivity) {
|
|
149
|
+
this.responded = true
|
|
150
|
+
}
|
|
151
|
+
return responses
|
|
152
|
+
} else {
|
|
153
|
+
const responses = await this.adapter.sendActivities(this, output)
|
|
154
|
+
for (let index = 0; index < responses?.length; index++) {
|
|
155
|
+
const activity = output[index]
|
|
156
|
+
activity.id = responses[index].id
|
|
157
|
+
}
|
|
158
|
+
if (sentNonTraceActivity) {
|
|
159
|
+
this.responded = true
|
|
160
|
+
}
|
|
161
|
+
return responses
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Updates an activity.
|
|
168
|
+
* @param activity The activity to update.
|
|
169
|
+
* @returns A promise representing the asynchronous operation.
|
|
170
|
+
*/
|
|
171
|
+
async updateActivity (activity: Activity): Promise<void> {
|
|
172
|
+
const ref: ConversationReference = this.activity.getConversationReference()
|
|
173
|
+
const a: Activity = activity.applyConversationReference(ref)
|
|
174
|
+
return await this.emit(this._onUpdateActivity, a, async () =>
|
|
175
|
+
await this.adapter.updateActivity(this, a).then(() => {})
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Deletes an activity.
|
|
181
|
+
* @param idOrReference The ID or reference of the activity to delete.
|
|
182
|
+
* @returns A promise representing the asynchronous operation.
|
|
183
|
+
*/
|
|
184
|
+
async deleteActivity (idOrReference: string | ConversationReference): Promise<void> {
|
|
185
|
+
let reference: ConversationReference
|
|
186
|
+
if (typeof idOrReference === 'string') {
|
|
187
|
+
reference = this.activity.getConversationReference()
|
|
188
|
+
reference.activityId = idOrReference
|
|
189
|
+
} else {
|
|
190
|
+
reference = idOrReference
|
|
191
|
+
}
|
|
192
|
+
return await this.emit(this._onDeleteActivity, reference, async () => await this.adapter.deleteActivity(this, reference))
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Uploads an attachment.
|
|
197
|
+
* @param conversationId The conversation ID.
|
|
198
|
+
* @param attachmentData The attachment data.
|
|
199
|
+
* @returns The resource response.
|
|
200
|
+
*/
|
|
201
|
+
async uploadAttachment (conversationId: string, attachmentData: AttachmentData): Promise<ResourceResponse> {
|
|
202
|
+
return await this.adapter.uploadAttachment(conversationId, attachmentData)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Gets attachment information.
|
|
207
|
+
* @param attachmentId The attachment ID.
|
|
208
|
+
* @returns The attachment information.
|
|
209
|
+
*/
|
|
210
|
+
async getAttachmentInfo (attachmentId: string): Promise<AttachmentInfo> {
|
|
211
|
+
return await this.adapter.getAttachmentInfo(attachmentId)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Gets an attachment.
|
|
216
|
+
* @param attachmentId The attachment ID.
|
|
217
|
+
* @param viewId The view ID.
|
|
218
|
+
* @returns The readable stream of the attachment.
|
|
219
|
+
*/
|
|
220
|
+
async getAttachment (attachmentId: string, viewId: string): Promise<NodeJS.ReadableStream> {
|
|
221
|
+
return await this.adapter.getAttachment(attachmentId, viewId)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Registers a handler for sending activities.
|
|
226
|
+
* @param handler The handler to register.
|
|
227
|
+
* @returns The current TurnContext instance.
|
|
228
|
+
*/
|
|
229
|
+
onSendActivities (handler: SendActivitiesHandler): this {
|
|
230
|
+
this._onSendActivities.push(handler)
|
|
231
|
+
return this
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Registers a handler for updating activities.
|
|
236
|
+
* @param handler The handler to register.
|
|
237
|
+
* @returns The current TurnContext instance.
|
|
238
|
+
*/
|
|
239
|
+
onUpdateActivity (handler: UpdateActivityHandler): this {
|
|
240
|
+
this._onUpdateActivity.push(handler)
|
|
241
|
+
return this
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Registers a handler for deleting activities.
|
|
246
|
+
* @param handler The handler to register.
|
|
247
|
+
* @returns The current TurnContext instance.
|
|
248
|
+
*/
|
|
249
|
+
onDeleteActivity (handler: DeleteActivityHandler): this {
|
|
250
|
+
this._onDeleteActivity.push(handler)
|
|
251
|
+
return this
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Copies the properties of this TurnContext to another TurnContext.
|
|
256
|
+
* @param context The context to copy to.
|
|
257
|
+
*/
|
|
258
|
+
protected copyTo (context: TurnContext): void {
|
|
259
|
+
['_adapter', '_activity', '_respondedRef', '_services', '_onSendActivities', '_onUpdateActivity', '_onDeleteActivity'].forEach((prop: string) => ((context as any)[prop] = (this as any)[prop]))
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Gets the adapter for the turn.
|
|
264
|
+
*/
|
|
265
|
+
get adapter (): BaseAdapter {
|
|
266
|
+
return this._adapter as BaseAdapter
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Gets the activity for the turn.
|
|
271
|
+
*/
|
|
272
|
+
get activity (): Activity {
|
|
273
|
+
return this._activity as Activity
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Gets or sets whether the turn has responded.
|
|
278
|
+
*/
|
|
279
|
+
get responded (): boolean {
|
|
280
|
+
return this._respondedRef.responded
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
set responded (value: boolean) {
|
|
284
|
+
if (!value) {
|
|
285
|
+
throw new Error("TurnContext: cannot set 'responded' to a value of 'false'.")
|
|
286
|
+
}
|
|
287
|
+
this._respondedRef.responded = true
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Gets or sets the locale for the turn.
|
|
292
|
+
*/
|
|
293
|
+
get locale (): string | undefined {
|
|
294
|
+
const turnObj = this._turnState.get(this._turn)
|
|
295
|
+
if (turnObj && typeof turnObj[this._locale] === 'string') {
|
|
296
|
+
return turnObj[this._locale]
|
|
297
|
+
}
|
|
298
|
+
return undefined
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
set locale (value: string | undefined) {
|
|
302
|
+
let turnObj = this._turnState.get(this._turn)
|
|
303
|
+
if (turnObj) {
|
|
304
|
+
turnObj[this._locale] = value
|
|
305
|
+
} else {
|
|
306
|
+
turnObj = { [this._locale]: value }
|
|
307
|
+
this._turnState.set(this._turn, turnObj)
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Gets the turn state collection.
|
|
313
|
+
*/
|
|
314
|
+
get turnState (): TurnContextStateCollection {
|
|
315
|
+
return this._turnState
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Emits events to the registered handlers.
|
|
320
|
+
* @param handlers The handlers to emit to.
|
|
321
|
+
* @param arg The argument to pass to the handlers.
|
|
322
|
+
* @param next The next function to call.
|
|
323
|
+
* @returns The result of the handlers.
|
|
324
|
+
*/
|
|
325
|
+
private async emit<A, T>(handlers: Array<(context: TurnContext, arg: A, next: () => Promise<T>) => Promise<T>>, arg: A, next: () => Promise<T>): Promise<T> {
|
|
326
|
+
const runHandlers = async ([handler, ...remaining]: typeof handlers): Promise<T> => {
|
|
327
|
+
try {
|
|
328
|
+
return handler ? await handler(this, arg, async () => await runHandlers(remaining)) : await Promise.resolve(next())
|
|
329
|
+
} catch (err) {
|
|
330
|
+
return await Promise.reject(err)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return await runHandlers(handlers)
|
|
334
|
+
}
|
|
335
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
const TURN_STATE_SCOPE_CACHE = Symbol('turnStateScopeCache')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A collection for managing state within a turn context.
|
|
9
|
+
*/
|
|
10
|
+
export class TurnContextStateCollection extends Map<any, any> {
|
|
11
|
+
/**
|
|
12
|
+
* Gets the value associated with the specified key.
|
|
13
|
+
* @param key The key of the element to get.
|
|
14
|
+
* @returns The element associated with the specified key, or undefined if the key does not exist.
|
|
15
|
+
*/
|
|
16
|
+
get<T = any>(key: any): T
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Gets the value associated with the specified key.
|
|
20
|
+
* @param key The key of the element to get.
|
|
21
|
+
* @returns The element associated with the specified key, or undefined if the key does not exist.
|
|
22
|
+
*/
|
|
23
|
+
get (key: any): any
|
|
24
|
+
|
|
25
|
+
get (key: any): unknown {
|
|
26
|
+
return super.get(key)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Pushes a value onto the stack for the specified key.
|
|
31
|
+
* @param key The key of the element to push.
|
|
32
|
+
* @param value The value to push onto the stack.
|
|
33
|
+
*/
|
|
34
|
+
push (key: any, value: any): void {
|
|
35
|
+
const current = this.get(key)
|
|
36
|
+
const cache: Map<any, any[]> = this.get(TURN_STATE_SCOPE_CACHE) || new Map<any, any[]>()
|
|
37
|
+
if (cache.has(key)) {
|
|
38
|
+
cache.get(key)?.push(current)
|
|
39
|
+
} else {
|
|
40
|
+
cache.set(key, [current])
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (value === undefined) {
|
|
44
|
+
value = current
|
|
45
|
+
}
|
|
46
|
+
this.set(key, value)
|
|
47
|
+
this.set(TURN_STATE_SCOPE_CACHE, cache)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Pops a value from the stack for the specified key.
|
|
52
|
+
* @param key The key of the element to pop.
|
|
53
|
+
* @returns The value that was popped from the stack.
|
|
54
|
+
*/
|
|
55
|
+
pop (key: any): any {
|
|
56
|
+
const current = this.get(key)
|
|
57
|
+
|
|
58
|
+
let previous: any
|
|
59
|
+
const cache: Map<any, any[]> = this.get(TURN_STATE_SCOPE_CACHE) || new Map<any, any[]>()
|
|
60
|
+
if (cache.has(key)) {
|
|
61
|
+
previous = cache.get(key)?.pop()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this.set(key, previous)
|
|
65
|
+
this.set(TURN_STATE_SCOPE_CACHE, cache)
|
|
66
|
+
|
|
67
|
+
return current
|
|
68
|
+
}
|
|
69
|
+
}
|