From 0ec5261b93df89feefbaed3482e5da577418241f Mon Sep 17 00:00:00 2001 From: 苏向夜 Date: Sat, 16 Dec 2023 20:37:07 +0800 Subject: :recycle: 允许业务函数返回事件实例 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/infini/event.py | 16 ++++++++++++++-- src/infini/typing.py | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/infini/event.py b/src/infini/event.py index 7ff276d8..d33a9c3c 100644 --- a/src/infini/event.py +++ b/src/infini/event.py @@ -1,5 +1,6 @@ from abc import ABCMeta from .register import Events +from .typing import Dict, Any __all__ = ["InfiniEvent", "MessageEvent", "WorkflowEvent", "MatcherEvent", "events"] @@ -8,6 +9,7 @@ class InfiniEvent(metaclass=ABCMeta): """Inifni 事件基类""" name: str + kwargs: Dict[str, Any] def __repr__(self) -> str: raise NotImplementedError @@ -21,6 +23,12 @@ class MessageEvent(InfiniEvent): name: str output: str + kwargs: Dict[str, Any] + + def __init__(self, name: str, output: str, **kwargs) -> None: + self.name = name + self.output = output + self.kwargs = kwargs def __repr__(self) -> str: return f"" @@ -30,7 +38,11 @@ class WorkflowEvent(InfiniEvent): """Workflow 事件""" name: str - kwargs: dict + kwargs: Dict[str, Any] + + def __init__(self, name: str, **kwargs) -> None: + self.name = name + self.kwargs = kwargs def __repr__(self) -> str: return f"" @@ -49,7 +61,7 @@ class MatcherEvent(InfiniEvent): name: str prefix: str string: str - kwargs: dict + kwargs: Dict[str, Any] def __init__( self, diff --git a/src/infini/typing.py b/src/infini/typing.py index df495707..0055d816 100644 --- a/src/infini/typing.py +++ b/src/infini/typing.py @@ -1,5 +1,6 @@ from typing import ( Dict as Dict, + Any as Any, TYPE_CHECKING as TYPE_CHECKING, TypeVar as TypeVar, Callable as Callable, -- cgit v1.2.3-70-g09d2