From edf6101277450d9b849f329cdfe27ad204c84392 Mon Sep 17 00:00:00 2001 From: 苏向夜 Date: Mon, 4 Mar 2024 17:54:47 +0800 Subject: feat(workflow): supports blocked workflow --- src/infini/core.py | 35 +++++++++++++++++++++++++++-------- src/infini/input.py | 3 +-- src/infini/output.py | 5 ++--- 3 files changed, 30 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/infini/core.py b/src/infini/core.py index 7c84a15f..0de6034c 100644 --- a/src/infini/core.py +++ b/src/infini/core.py @@ -15,9 +15,7 @@ class Core: interceptor: Interceptor injector: Injector - def input( - self, input: Input - ) -> GeneratorT[Union[str, Output], Any, None]: + def input(self, input: Input) -> GeneratorT[Union[str, Output], Any, None]: for pre_intercepted_stream in self.pre_intercept(input): if isinstance(pre_intercepted_stream, Output): if not isinstance(pre_intercepted_stream, Output): @@ -26,7 +24,15 @@ class Core: ) if pre_intercepted_stream.is_empty(): return - yield self.generate(pre_intercepted_stream) + if pre_intercepted_stream.type == "workflow": + yield pre_intercepted_stream + if pre_intercepted_stream.block: + while pre_intercepted_stream.status != 0: + pass + continue + else: + yield self.generate(pre_intercepted_stream) # TODO 拦截拦截器文本 + if pre_intercepted_stream.block: return else: @@ -39,14 +45,27 @@ class Core: ) if handled_stream.is_empty(): return - outcome = self.generate(handled_stream) + if handled_stream.type == "workflow": + yield handled_stream + if handled_stream.block: + while handled_stream.status != 0: + pass + continue + else: + outcome = self.generate(handled_stream) for stream in self.intercept(handled_stream, outcome): if isinstance(stream, Output): if stream.is_empty(): return - yield self.generate(stream) - if stream.block: - return + if stream.type == "workflow": + yield stream + if stream.block: + while stream.status != 0: + pass + else: + yield self.generate(stream) + if stream.block: + return continue outcome = stream yield outcome diff --git a/src/infini/input.py b/src/infini/input.py index 30683a4b..0bbb3f2f 100644 --- a/src/infini/input.py +++ b/src/infini/input.py @@ -32,10 +32,9 @@ class Input(Generic[T]): type: Literal["text", "workflow"], name: str, *, - status: int = 0, block: bool = False, variables: Dict[str, Any] = {}, ): vars = self.variables.copy() vars.update(variables) - return Output(type, name, status=status, block=block, variables=vars) + return Output(type, name, block=block, variables=vars) diff --git a/src/infini/output.py b/src/infini/output.py index 13f26d47..6520d9b4 100644 --- a/src/infini/output.py +++ b/src/infini/output.py @@ -14,19 +14,18 @@ class Output: type: Union[Literal["null", "text", "workflow"], str], name: str, *, - status: int = 0, block: bool = False, variables: Dict[str, Any] = {}, ) -> None: self.type = type self.name = name - self.status = status + self.status = 1 self.block = block self.variables = variables @classmethod def empty(cls) -> "Output": - return cls("null", "null", status=0, block=True) + return cls("null", "null", block=True) def is_empty(self) -> bool: return self.type == "null" -- cgit v1.2.3-70-g09d2 From 5b778ed5ea34862969653a4fc4e72d1debe09ee1 Mon Sep 17 00:00:00 2001 From: 苏向夜 Date: Mon, 4 Mar 2024 17:55:52 +0800 Subject: style(exception): fix annocation --- src/infini/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/infini/exceptions.py b/src/infini/exceptions.py index 2e2b0197..ac9c3d22 100644 --- a/src/infini/exceptions.py +++ b/src/infini/exceptions.py @@ -11,7 +11,7 @@ class UnknownEvent(InfiniException): class UnknownEventType(InfiniException, TypeError): - """文本事件不存在""" + """事件类型不存在""" class ValueError(InfiniException, ValueError): -- cgit v1.2.3-70-g09d2 From a937d5d3ed0e2bec8e813cd6dfd4c408d902a92b Mon Sep 17 00:00:00 2001 From: 苏向夜 Date: Mon, 4 Mar 2024 17:56:54 +0800 Subject: feat(loader): supports hot module reload --- src/infini/loader.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/infini/loader.py b/src/infini/loader.py index 07ebe0a8..f02dd910 100644 --- a/src/infini/loader.py +++ b/src/infini/loader.py @@ -82,10 +82,7 @@ class InfiniLoader(importlib.abc.Loader): def _install(): - if not sys.meta_path: - raise OSError("Var 'sys.meta_path' is empty, since Python is stop.") - if not isinstance(sys.meta_path[0], InfiniMetaFinder): - sys.meta_path.insert(0, InfiniMetaFinder()) + sys.meta_path.insert(0, InfiniMetaFinder()) def _uninstall(): -- cgit v1.2.3-70-g09d2