chore: import upstream snapshot with attribution
CI / Run CI (push) Has been cancelled
CI / check-backend (push) Has been cancelled
CI / check-frontend (push) Has been cancelled
CI / tests (push) Has been cancelled
CI / e2e-tests (push) Has been cancelled
Copilot Setup Steps / copilot-setup-steps (push) Has been cancelled
CI / Run CI (push) Has been cancelled
CI / check-backend (push) Has been cancelled
CI / check-frontend (push) Has been cancelled
CI / tests (push) Has been cancelled
CI / e2e-tests (push) Has been cancelled
Copilot Setup Steps / copilot-setup-steps (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import functools
|
||||
from collections import deque
|
||||
|
||||
from chainlit.context import context
|
||||
from chainlit.session import WebsocketSession
|
||||
|
||||
|
||||
def queue_until_user_message():
|
||||
def decorator(method):
|
||||
@functools.wraps(method)
|
||||
async def wrapper(self, *args, **kwargs):
|
||||
if (
|
||||
isinstance(context.session, WebsocketSession)
|
||||
and not context.session.has_first_interaction
|
||||
):
|
||||
# Queue the method invocation waiting for the first user message
|
||||
queues = context.session.thread_queues
|
||||
method_name = method.__name__
|
||||
if method_name not in queues:
|
||||
queues[method_name] = deque()
|
||||
queues[method_name].append((method, self, args, kwargs))
|
||||
|
||||
else:
|
||||
# Otherwise, Execute the method immediately
|
||||
return await method(self, *args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
Reference in New Issue
Block a user