-
Notifications
You must be signed in to change notification settings - Fork 42
TypingIndicator simplification #212
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,9 +4,9 @@ | |||||
| """ | ||||||
|
|
||||||
| from __future__ import annotations | ||||||
| import asyncio | ||||||
| import logging | ||||||
|
|
||||||
| from threading import Timer | ||||||
| from typing import Optional | ||||||
|
|
||||||
| from microsoft_agents.hosting.core import TurnContext | ||||||
|
|
@@ -20,59 +20,36 @@ class TypingIndicator: | |||||
| Encapsulates the logic for sending "typing" activity to the user. | ||||||
| """ | ||||||
|
|
||||||
| def __init__(self, intervalSeconds=1) -> None: | ||||||
| self._intervalSeconds = intervalSeconds | ||||||
| self._task: Optional[asyncio.Task] = None | ||||||
| self._running: bool = False | ||||||
| self._lock = asyncio.Lock() | ||||||
| _interval: int | ||||||
| _timer: Optional[Timer] = None | ||||||
|
|
||||||
| async def start(self, context: TurnContext) -> None: | ||||||
| async with self._lock: | ||||||
| if self._running: | ||||||
| return | ||||||
| def __init__(self, interval=10) -> None: | ||||||
|
||||||
| self._interval = interval | ||||||
|
|
||||||
| logger.debug( | ||||||
| f"Starting typing indicator with interval: {self._intervalSeconds} seconds" | ||||||
| ) | ||||||
| self._running = True | ||||||
| self._task = asyncio.create_task(self._typing_loop(context)) | ||||||
| async def start(self, context: TurnContext) -> None: | ||||||
| if self._timer is not None: | ||||||
| return | ||||||
|
|
||||||
| async def stop(self) -> None: | ||||||
| async with self._lock: | ||||||
| if not self._running: | ||||||
| return | ||||||
| logger.debug(f"Starting typing indicator with interval: {self._interval} ms") | ||||||
|
||||||
| logger.debug(f"Starting typing indicator with interval: {self._interval} ms") | |
| logger.debug(f"Starting typing indicator with interval: {self._interval} seconds") |
Copilot
AI
Oct 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Timer is created with an async function but Timer expects a synchronous callable. When the timer expires, it will try to call the async function synchronously, which will not execute the coroutine properly. Additionally, the timer only fires once and won't send recurring typing indicators as the original implementation did.
Copilot
AI
Oct 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stop method signature changed from async def to def, but it's still called with await typing.stop() in agent_application.py line 736. This will cause a runtime error since you cannot await a non-coroutine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
_timerclass attribute will be shared across all instances ofTypingIndicator. This should be an instance attribute initialized in__init__to avoid state being shared between different instances.