Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .azdo/ci-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ steps:

- script: |
mkdir -p dist
for dir in libraries/*; do
if [ -f "$dir/pyproject.toml" ]; then
echo $(PackageVersion) > "$dir/VERSION.txt"
fi
done
for dir in libraries/*; do
if [ -f "$dir/pyproject.toml" ]; then
(cd "$dir" && python -m build --outdir ../../dist)
Expand Down
1 change: 1 addition & 0 deletions libraries/microsoft-agents-activity/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include VERSION.txt
10 changes: 8 additions & 2 deletions libraries/microsoft-agents-activity/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from os import environ
from os import environ, path
from setuptools import setup

package_version = environ.get("PackageVersion", "0.0.0")
# Try to read from VERSION.txt file first, fall back to environment variable
version_file = path.join(path.dirname(__file__), "VERSION.txt")
if path.exists(version_file):
with open(version_file, "r", encoding="utf-8") as f:
package_version = f.read().strip()
else:
package_version = environ.get("PackageVersion", "0.0.0")

setup(
version=package_version,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include VERSION.txt
10 changes: 8 additions & 2 deletions libraries/microsoft-agents-authentication-msal/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from os import environ
from os import environ, path
from setuptools import setup

package_version = environ.get("PackageVersion", "0.0.0")
# Try to read from VERSION.txt file first, fall back to environment variable
version_file = path.join(path.dirname(__file__), "VERSION.txt")
if path.exists(version_file):
with open(version_file, "r", encoding="utf-8") as f:
package_version = f.read().strip()
else:
package_version = environ.get("PackageVersion", "0.0.0")

setup(
version=package_version,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include VERSION.txt
10 changes: 8 additions & 2 deletions libraries/microsoft-agents-copilotstudio-client/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from os import environ
from os import environ, path
from setuptools import setup

package_version = environ.get("PackageVersion", "0.0.0")
# Try to read from VERSION.txt file first, fall back to environment variable
version_file = path.join(path.dirname(__file__), "VERSION.txt")
if path.exists(version_file):
with open(version_file, "r", encoding="utf-8") as f:
package_version = f.read().strip()
else:
package_version = environ.get("PackageVersion", "0.0.0")

setup(
version=package_version,
Expand Down
1 change: 1 addition & 0 deletions libraries/microsoft-agents-hosting-aiohttp/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include VERSION.txt
10 changes: 8 additions & 2 deletions libraries/microsoft-agents-hosting-aiohttp/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from os import environ
from os import environ, path
from setuptools import setup

package_version = environ.get("PackageVersion", "0.0.0")
# Try to read from VERSION.txt file first, fall back to environment variable
version_file = path.join(path.dirname(__file__), "VERSION.txt")
if path.exists(version_file):
with open(version_file, "r", encoding="utf-8") as f:
package_version = f.read().strip()
else:
package_version = environ.get("PackageVersion", "0.0.0")

setup(
version=package_version,
Expand Down
1 change: 1 addition & 0 deletions libraries/microsoft-agents-hosting-core/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include VERSION.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,27 @@

from typing import Optional

from pydantic import BaseModel

from microsoft_agents.activity import Activity

from ...storage._type_aliases import JSON
from ...storage import StoreItem


class _SignInState(StoreItem):
class _SignInState(BaseModel, StoreItem):
"""Store item for sign-in state, including tokens and continuation activity.

Used to cache tokens and keep track of activities during single and
multi-turn sign-in flows.
"""

def __init__(
self,
active_handler_id: str,
continuation_activity: Optional[Activity] = None,
) -> None:
self.active_handler_id = active_handler_id
self.continuation_activity = continuation_activity
active_handler_id: str
continuation_activity: Optional[Activity] = None

def store_item_to_json(self) -> JSON:
return {
"active_handler_id": self.active_handler_id,
"continuation_activity": self.continuation_activity,
}
return self.model_dump(mode="json", exclude_unset=True, by_alias=True)

@staticmethod
def from_json_to_store_item(json_data: JSON) -> _SignInState:
return _SignInState(
json_data["active_handler_id"], json_data.get("continuation_activity")
)
return _SignInState.model_validate(json_data)
10 changes: 8 additions & 2 deletions libraries/microsoft-agents-hosting-core/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from os import environ
from os import environ, path
from setuptools import setup

package_version = environ.get("PackageVersion", "0.0.0")
# Try to read from VERSION.txt file first, fall back to environment variable
version_file = path.join(path.dirname(__file__), "VERSION.txt")
if path.exists(version_file):
with open(version_file, "r", encoding="utf-8") as f:
package_version = f.read().strip()
else:
package_version = environ.get("PackageVersion", "0.0.0")

setup(
version=package_version,
Expand Down
1 change: 1 addition & 0 deletions libraries/microsoft-agents-hosting-fastapi/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include VERSION.txt
10 changes: 8 additions & 2 deletions libraries/microsoft-agents-hosting-fastapi/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from os import environ
from os import environ, path
from setuptools import setup

package_version = environ.get("PackageVersion", "0.0.0")
# Try to read from VERSION.txt file first, fall back to environment variable
version_file = path.join(path.dirname(__file__), "VERSION.txt")
if path.exists(version_file):
with open(version_file, "r", encoding="utf-8") as f:
package_version = f.read().strip()
else:
package_version = environ.get("PackageVersion", "0.0.0")

setup(
version=package_version,
Expand Down
1 change: 1 addition & 0 deletions libraries/microsoft-agents-hosting-teams/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include VERSION.txt
10 changes: 8 additions & 2 deletions libraries/microsoft-agents-hosting-teams/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from os import environ
from os import environ, path
from setuptools import setup

package_version = environ.get("PackageVersion", "0.0.0")
# Try to read from VERSION.txt file first, fall back to environment variable
version_file = path.join(path.dirname(__file__), "VERSION.txt")
if path.exists(version_file):
with open(version_file, "r", encoding="utf-8") as f:
package_version = f.read().strip()
else:
package_version = environ.get("PackageVersion", "0.0.0")

setup(
version=package_version,
Expand Down
1 change: 1 addition & 0 deletions libraries/microsoft-agents-storage-blob/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include VERSION.txt
10 changes: 8 additions & 2 deletions libraries/microsoft-agents-storage-blob/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from os import environ
from os import environ, path
from setuptools import setup

package_version = environ.get("PackageVersion", "0.0.0")
# Try to read from VERSION.txt file first, fall back to environment variable
version_file = path.join(path.dirname(__file__), "VERSION.txt")
if path.exists(version_file):
with open(version_file, "r", encoding="utf-8") as f:
package_version = f.read().strip()
else:
package_version = environ.get("PackageVersion", "0.0.0")

setup(
version=package_version,
Expand Down
1 change: 1 addition & 0 deletions libraries/microsoft-agents-storage-cosmos/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include VERSION.txt
10 changes: 8 additions & 2 deletions libraries/microsoft-agents-storage-cosmos/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from os import environ
from os import environ, path
from setuptools import setup

package_version = environ.get("PackageVersion", "0.0.0")
# Try to read from VERSION.txt file first, fall back to environment variable
version_file = path.join(path.dirname(__file__), "VERSION.txt")
if path.exists(version_file):
with open(version_file, "r", encoding="utf-8") as f:
package_version = f.read().strip()
else:
package_version = environ.get("PackageVersion", "0.0.0")

setup(
version=package_version,
Expand Down
8 changes: 5 additions & 3 deletions tests/hosting_core/app/_oauth/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ def create_testing_TurnContext(

turn_context = mocker.Mock()
if not activity:
turn_context.activity.channel_id = channel_id
turn_context.activity.from_property.id = user_id
turn_context.activity.type = ActivityTypes.message
turn_context.activity = Activity(
type=ActivityTypes.message,
channel_id=channel_id,
from_property={"id": user_id},
)
else:
turn_context.activity = activity
turn_context.adapter.USER_TOKEN_CLIENT_KEY = "__user_token_client"
Expand Down
43 changes: 43 additions & 0 deletions tests/hosting_core/app/_oauth/test_sign_in_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import json

from microsoft_agents.activity import Activity
from microsoft_agents.hosting.core.app.oauth._sign_in_state import _SignInState


def test_sign_in_state_serialization_deserialization(tmp_path):
original_state = _SignInState(
active_handler_id="handler_123",
continuation_activity=Activity(
type="message",
id="activity_456",
timestamp="2024-01-01T12:00:00Z",
service_url="https://service.url",
channel_id="channel_789",
from_property={"id": "user_1"},
conversation={"id": "conv_1"},
recipient={"id": "bot_1"},
text="Hello, World!",
),
)

# Serialize to JSON
json_data = original_state.store_item_to_json()

# Deserialize back to _SignInState
deserialized_state = _SignInState.from_json_to_store_item(json_data)

# Assert equality
assert deserialized_state.active_handler_id == original_state.active_handler_id
assert (
deserialized_state.continuation_activity == original_state.continuation_activity
)

with open(tmp_path / "sign_in_state.json", "w") as f:
json.dump(json_data, f)

with open(tmp_path / "sign_in_state.json", "r") as f:
loaded_json_data = json.load(f)

loaded_state = _SignInState.from_json_to_store_item(loaded_json_data)
assert loaded_state.active_handler_id == original_state.active_handler_id
assert loaded_state.continuation_activity == original_state.continuation_activity