-
Notifications
You must be signed in to change notification settings - Fork 295
DialogManager #1409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
DialogManager #1409
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3d20366
Initial commit for dialog manager **WIP state**
axelsrz 7e884bb
Adding more memory classes
axelsrz faf1b54
memory scopes and path resolvers added
axelsrz e867a0e
Updates on try_get_value
axelsrz 3abc979
DialogStateManager code complete
axelsrz 40fa13d
Dialog manager code complete (tests pending)
axelsrz 80f2ba5
Solved circular dependency issues, bugfix in DialogCOmponentRegistration
axelsrz 6153d76
Pylint compliance and bugfixing
axelsrz a3f08b8
Reverting regression in DialogManager
axelsrz ff3f5b5
Compatibility with 3.6 typing
axelsrz 6311528
Merge branch 'main' into axsuarez/DialogManager
axelsrz d353076
General DialogManager testing added. Several bugfixes
axelsrz d9919fb
Added tests for Dialog Manager
axelsrz 7d40eed
Fixing ClassMemoryScope binding, adding tests for scopes classes
axelsrz 17c343f
ConversationState scope test
axelsrz ef26d5f
Adding more scopes tests
axelsrz 1961529
Added all scopes tests
axelsrz 5b40e2d
Merge branch 'main' into axsuarez/DialogManager
axelsrz ec96e65
Fixing printing because of merge conflict
axelsrz 9538fc6
PR comments fixes
axelsrz a76883b
Merge branch 'main' into axsuarez/DialogManager
axelsrz 1ac9243
Merge branch 'main' into axsuarez/DialogManager
tracyboehrer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
libraries/botbuilder-core/botbuilder/core/component_registration.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
from typing import Dict, Iterable, Type | ||
|
||
|
||
class ComponentRegistration: | ||
@staticmethod | ||
def get_components() -> Iterable["ComponentRegistration"]: | ||
return _components.values() | ||
|
||
@staticmethod | ||
def add(component_registration: "ComponentRegistration"): | ||
_components[component_registration.__class__] = component_registration | ||
|
||
|
||
_components: Dict[Type, ComponentRegistration] = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_container.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
|
||
from .dialog import Dialog | ||
from .dialog_context import DialogContext | ||
from .dialog_event import DialogEvent | ||
from .dialog_events import DialogEvents | ||
from .dialog_set import DialogSet | ||
|
||
|
||
class DialogContainer(Dialog, ABC): | ||
def __init__(self, dialog_id: str = None): | ||
super().__init__(dialog_id) | ||
|
||
self.dialogs = DialogSet() | ||
|
||
@abstractmethod | ||
def create_child_context(self, dialog_context: DialogContext) -> DialogContext: | ||
raise NotImplementedError() | ||
|
||
def find_dialog(self, dialog_id: str) -> Dialog: | ||
# TODO: deprecate DialogSet.find | ||
return self.dialogs.find_dialog(dialog_id) | ||
|
||
async def on_dialog_event( | ||
self, dialog_context: DialogContext, dialog_event: DialogEvent | ||
) -> bool: | ||
""" | ||
Called when an event has been raised, using `DialogContext.emitEvent()`, by either the current dialog or a | ||
dialog that the current dialog started. | ||
:param dialog_context: The dialog context for the current turn of conversation. | ||
:param dialog_event: The event being raised. | ||
:return: True if the event is handled by the current dialog and bubbling should stop. | ||
""" | ||
handled = await super().on_dialog_event(dialog_context, dialog_event) | ||
|
||
# Trace unhandled "versionChanged" events. | ||
if not handled and dialog_event.name == DialogEvents.version_changed: | ||
|
||
trace_message = ( | ||
f"Unhandled dialog event: {dialog_event.name}. Active Dialog: " | ||
f"{dialog_context.active_dialog.id}" | ||
) | ||
|
||
await dialog_context.context.send_trace_activity(trace_message) | ||
|
||
return handled | ||
|
||
def get_internal_version(self) -> str: | ||
""" | ||
GetInternalVersion - Returns internal version identifier for this container. | ||
DialogContainers detect changes of all sub-components in the container and map that to an DialogChanged event. | ||
Because they do this, DialogContainers "hide" the internal changes and just have the .id. This isolates changes | ||
to the container level unless a container doesn't handle it. To support this DialogContainers define a | ||
protected virtual method GetInternalVersion() which computes if this dialog or child dialogs have changed | ||
which is then examined via calls to check_for_version_change_async(). | ||
:return: version which represents the change of the internals of this container. | ||
""" | ||
return self.dialogs.get_version() | ||
|
||
async def check_for_version_change_async(self, dialog_context: DialogContext): | ||
""" | ||
:param dialog_context: dialog context. | ||
:return: task. | ||
Checks to see if a containers child dialogs have changed since the current dialog instance | ||
was started. | ||
|
||
This should be called at the start of `beginDialog()`, `continueDialog()`, and `resumeDialog()`. | ||
""" | ||
current = dialog_context.active_dialog.version | ||
dialog_context.active_dialog.version = self.get_internal_version() | ||
|
||
# Check for change of previously stored hash | ||
if current and current != dialog_context.active_dialog.version: | ||
# Give bot an opportunity to handle the change. | ||
# - If bot handles it the changeHash will have been updated as to avoid triggering the | ||
# change again. | ||
await dialog_context.emit_event( | ||
DialogEvents.version_changed, self.id, True, False | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.