diff options
| author | 2023-12-16 20:37:07 +0800 | |
|---|---|---|
| committer | 2023-12-16 20:37:07 +0800 | |
| commit | 0ec5261b93df89feefbaed3482e5da577418241f (patch) | |
| tree | 70f9085157943ab0f77885cf9844cccd9fb88c1a | |
| parent | 607035aaab3c1143cdbc593ac98554d72588a12f (diff) | |
| download | infini-0ec5261b93df89feefbaed3482e5da577418241f.tar.gz infini-0ec5261b93df89feefbaed3482e5da577418241f.zip | |
:recycle: 允许业务函数返回事件实例
| -rw-r--r-- | src/infini/event.py | 16 | ||||
| -rw-r--r-- | 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"<MessageEvent [{self.name}]>" @@ -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"<WorkflowEvent [{self.name}]>" @@ -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, |
