fabricatio 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. fabricatio-0.1.0/.github/workflows/build-package.yaml +58 -0
  2. fabricatio-0.1.0/.github/workflows/pre-commit.yaml +25 -0
  3. fabricatio-0.1.0/.gitignore +11 -0
  4. fabricatio-0.1.0/.python-version +1 -0
  5. fabricatio-0.1.0/LICENSE +21 -0
  6. fabricatio-0.1.0/PKG-INFO +46 -0
  7. fabricatio-0.1.0/README.md +0 -0
  8. fabricatio-0.1.0/pyproject.toml +67 -0
  9. fabricatio-0.1.0/src/fabricatio/__init__.py +18 -0
  10. fabricatio-0.1.0/src/fabricatio/config.py +122 -0
  11. fabricatio-0.1.0/src/fabricatio/core.py +148 -0
  12. fabricatio-0.1.0/src/fabricatio/fs.py +1 -0
  13. fabricatio-0.1.0/src/fabricatio/logger.py +16 -0
  14. fabricatio-0.1.0/src/fabricatio/models/action.py +22 -0
  15. fabricatio-0.1.0/src/fabricatio/models/events.py +68 -0
  16. fabricatio-0.1.0/src/fabricatio/models/generic.py +310 -0
  17. fabricatio-0.1.0/src/fabricatio/models/role.py +14 -0
  18. fabricatio-0.1.0/src/fabricatio/models/tool.py +80 -0
  19. fabricatio-0.1.0/src/fabricatio/models/utils.py +81 -0
  20. fabricatio-0.1.0/src/fabricatio/py.typed +0 -0
  21. fabricatio-0.1.0/tests/__init__.py +0 -0
  22. fabricatio-0.1.0/tests/conftest.py +8 -0
  23. fabricatio-0.1.0/tests/test_config.py +27 -0
  24. fabricatio-0.1.0/tests/test_core.py +50 -0
  25. fabricatio-0.1.0/tests/test_logger.py +14 -0
  26. fabricatio-0.1.0/tests/test_models/test_action.py +25 -0
  27. fabricatio-0.1.0/tests/test_models/test_events.py +29 -0
  28. fabricatio-0.1.0/tests/test_models/test_generic.py +25 -0
  29. fabricatio-0.1.0/tests/test_models/test_role.py +15 -0
  30. fabricatio-0.1.0/tests/test_models/test_tool.py +30 -0
  31. fabricatio-0.1.0/tests/test_models/test_utils.py +19 -0
  32. fabricatio-0.1.0/uv.lock +1295 -0
@@ -0,0 +1,58 @@
1
+ name: Build and Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ check-and-release:
10
+ runs-on: windows-latest
11
+ steps:
12
+ - name: Checkout repository
13
+ uses: actions/checkout@v4
14
+
15
+ - name: Install the latest version of uv
16
+ uses: astral-sh/setup-uv@v5
17
+ with:
18
+ version: "latest"
19
+
20
+ - name: Build
21
+ run: |
22
+ uv build
23
+
24
+ - name: Get current version
25
+ id: get_version
26
+ run: |
27
+ CURRENT_VERSION=$(grep '^version' pyproject.toml | cut -d '"' -f 2)
28
+ echo "CURRENT_VERSION=v$CURRENT_VERSION" >> $GITHUB_OUTPUT
29
+ shell: bash
30
+ - name: Get latest tag
31
+ uses: JinoArch/get-latest-tag@latest
32
+ id: tag
33
+
34
+ - name: Check if version has changed
35
+ id: check_version_change
36
+ run: |
37
+ LATEST_TAG=${{ steps.tag.outputs.latestTag }}
38
+ echo "Latest tag is $LATEST_TAG"
39
+ echo "Current version is ${{ steps.get_version.outputs.CURRENT_VERSION }}"
40
+ if [ "$LATEST_TAG" != "${{ steps.get_version.outputs.CURRENT_VERSION }}" ]; then
41
+ echo "VERSION_CHANGED=true" >> $GITHUB_OUTPUT
42
+ else
43
+ echo "VERSION_CHANGED=false" >> $GITHUB_OUTPUT
44
+ fi
45
+ shell: bash
46
+
47
+
48
+ - name: Create Release and upload assets
49
+ if: ${{ steps.check_version_change.outputs.VERSION_CHANGED == 'true' }}
50
+ id: create_release
51
+ uses: softprops/action-gh-release@v2
52
+ with:
53
+ tag_name: ${{ steps.get_version.outputs.CURRENT_VERSION }}
54
+ name: ${{ steps.get_version.outputs.CURRENT_VERSION }}
55
+ files: |
56
+ dist/*
57
+ env:
58
+ GITHUB_TOKEN: ${{ secrets.PAT }}
@@ -0,0 +1,25 @@
1
+ name: Pre-commit checks
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - '**'
7
+ push:
8
+ branches:
9
+ - '**'
10
+
11
+ jobs:
12
+ pre-commit-check:
13
+ runs-on: ubuntu-latest
14
+ environment: pre-commit
15
+ steps:
16
+ - name: Checkout repository
17
+ uses: actions/checkout@v4
18
+ - name: Install the latest version of uv
19
+ uses: astral-sh/setup-uv@v5
20
+ with:
21
+ version: "latest"
22
+ - name: Initialize pre-commit
23
+ run: uvx pre-commit install
24
+ - name: Run pre-commit hooks
25
+ run: uvx pre-commit run --all-files
@@ -0,0 +1,11 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+ .idea
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Whth Yotta
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.4
2
+ Name: fabricatio
3
+ Version: 0.1.0
4
+ Summary: A LLM multi-agent framework.
5
+ Author-email: Whth <zettainspector@foxmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Whth Yotta
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ License-File: LICENSE
28
+ Classifier: Framework :: AsyncIO
29
+ Classifier: Framework :: Pydantic :: 2
30
+ Classifier: License :: OSI Approved :: MIT License
31
+ Classifier: Programming Language :: Python :: 3.12
32
+ Classifier: Programming Language :: Python :: Implementation :: CPython
33
+ Classifier: Typing :: Typed
34
+ Requires-Python: >=3.12
35
+ Requires-Dist: aiohttp>=3.11.11
36
+ Requires-Dist: aiomultiprocess>=0.9.1
37
+ Requires-Dist: appdirs>=1.4.4
38
+ Requires-Dist: asyncio>=3.4.3
39
+ Requires-Dist: litellm>=1.60.0
40
+ Requires-Dist: loguru>=0.7.3
41
+ Requires-Dist: pydantic-settings>=2.7.1
42
+ Requires-Dist: pydantic>=2.10.6
43
+ Requires-Dist: pymitter>=1.0.0
44
+ Requires-Dist: rich>=13.9.4
45
+ Provides-Extra: cli
46
+ Requires-Dist: typer>=0.15.1; extra == 'cli'
File without changes
@@ -0,0 +1,67 @@
1
+ [project]
2
+ name = "fabricatio"
3
+ version = "0.1.0"
4
+ description = "A LLM multi-agent framework."
5
+ readme = "README.md"
6
+ license = { file = "LICENSE" }
7
+ authors = [
8
+ { name = "Whth", email = "zettainspector@foxmail.com" }
9
+ ]
10
+ classifiers = [
11
+ "License :: OSI Approved :: MIT License",
12
+ "Programming Language :: Python :: 3.12",
13
+ "Programming Language :: Python :: Implementation :: CPython",
14
+ "Framework :: AsyncIO",
15
+ "Framework :: Pydantic :: 2",
16
+ "Typing :: Typed",
17
+ ]
18
+ requires-python = ">=3.12"
19
+ dependencies = [
20
+ "aiohttp>=3.11.11",
21
+ "aiomultiprocess>=0.9.1",
22
+ "appdirs>=1.4.4",
23
+ "asyncio>=3.4.3",
24
+ "litellm>=1.60.0",
25
+ "loguru>=0.7.3",
26
+ "pydantic>=2.10.6",
27
+ "pydantic-settings>=2.7.1",
28
+ "pymitter>=1.0.0",
29
+ "rich>=13.9.4",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ cli = [
34
+ "typer>=0.15.1",
35
+ ]
36
+
37
+ [build-system]
38
+ requires = ["hatchling"]
39
+ build-backend = "hatchling.build"
40
+
41
+
42
+ [dependency-groups]
43
+ dev = [
44
+ "pytest>=8.3.4",
45
+ "pytest-cov>=6.0.0",
46
+ "pytest-env>=1.1.5",
47
+ "pytest-flake8>=1.3.0",
48
+ "pytest-mock>=3.14.0",
49
+ "pytest-rerunfailures>=15.0",
50
+ "pytest-xdist>=3.6.1",
51
+ ]
52
+ cli = [
53
+ "click>=8.1.8",
54
+ ]
55
+
56
+ [[tool.uv.index]]
57
+ url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
58
+
59
+ [[tool.uv.index]]
60
+ url = "https://mirrors.huaweicloud.com/repository/pypi/simple"
61
+
62
+ [[tool.uv.index]]
63
+ url = "https://mirrors.aliyun.com/pypi/simple/"
64
+
65
+ [[tool.uv.index]]
66
+ url = "https://mirrors.bfsu.edu.cn/pypi/web/simple"
67
+ default = true
@@ -0,0 +1,18 @@
1
+ from fabricatio.core import Env
2
+ from fabricatio.logger import logger
3
+ from fabricatio.models.action import Action, WorkFlow
4
+ from fabricatio.models.events import Event
5
+ from fabricatio.models.role import Role
6
+ from fabricatio.models.tool import ToolBox
7
+ from fabricatio.models.utils import Messages
8
+
9
+ __all__ = [
10
+ "Env",
11
+ "logger",
12
+ "Action",
13
+ "Event",
14
+ "Messages",
15
+ "Role",
16
+ "ToolBox",
17
+ "WorkFlow",
18
+ ]
@@ -0,0 +1,122 @@
1
+ from typing import Literal
2
+
3
+ from appdirs import user_config_dir
4
+ from pydantic import BaseModel, HttpUrl, SecretStr, PositiveInt, NonNegativeFloat, Field, FilePath
5
+ from pydantic_settings import (
6
+ BaseSettings,
7
+ SettingsConfigDict,
8
+ PydanticBaseSettingsSource,
9
+ TomlConfigSettingsSource,
10
+ PyprojectTomlConfigSettingsSource,
11
+ EnvSettingsSource,
12
+ DotEnvSettingsSource,
13
+ )
14
+
15
+
16
+ class LLMConfig(BaseModel):
17
+ api_endpoint: HttpUrl = Field(default=HttpUrl("https://api.openai.com"))
18
+ """
19
+ OpenAI API Endpoint.
20
+ """
21
+
22
+ api_key: SecretStr = Field(default=SecretStr(""))
23
+ """
24
+ OpenAI API key. Empty by default for security reasons, should be set before use.
25
+ """
26
+
27
+ timeout: PositiveInt = Field(default=300)
28
+ """
29
+ The timeout of the LLM model in seconds. Default is 300 seconds as per request.
30
+ """
31
+
32
+ max_retries: PositiveInt = Field(default=3)
33
+ """
34
+ The maximum number of retries. Default is 3 retries.
35
+ """
36
+
37
+ model: str = Field(default="gpt-3.5-turbo")
38
+ """
39
+ The LLM model name. Set to 'gpt-3.5-turbo' as per request.
40
+ """
41
+
42
+ temperature: NonNegativeFloat = Field(default=1.0)
43
+ """
44
+ The temperature of the LLM model. Controls randomness in generation. Set to 1.0 as per request.
45
+ """
46
+
47
+ stop_sign: str = Field(default="")
48
+ """
49
+ The stop sign of the LLM model. No default stop sign specified.
50
+ """
51
+
52
+ top_p: NonNegativeFloat = Field(default=0.35)
53
+ """
54
+ The top p of the LLM model. Controls diversity via nucleus sampling. Set to 0.35 as per request.
55
+ """
56
+
57
+ generation_count: PositiveInt = Field(default=1)
58
+ """
59
+ The number of generations to generate. Default is 1.
60
+ """
61
+
62
+ stream: bool = Field(default=False)
63
+ """
64
+ Whether to stream the LLM model's response. Default is False.
65
+ """
66
+
67
+ max_tokens: PositiveInt = Field(default=8192)
68
+ """
69
+ The maximum number of tokens to generate. Set to 8192 as per request.
70
+ """
71
+
72
+
73
+ class DebugConfig(BaseModel):
74
+ log_level: Literal["DEBUG", "INFO", "SUCCESS", "WARNING", "ERROR", "CRITICAL"] = Field(default="INFO")
75
+ """
76
+ The log level of the application.
77
+ """
78
+
79
+ log_file: FilePath = Field(default=f"{user_config_dir("fabricatio", roaming=True)}.log")
80
+ """
81
+ The log file of the application.
82
+ """
83
+
84
+
85
+ class Settings(BaseSettings):
86
+ model_config = SettingsConfigDict(
87
+ env_prefix="FABRIK_",
88
+ env_nested_delimiter="__",
89
+ pyproject_toml_depth=1,
90
+ toml_file=["fabricatio.toml", f"{user_config_dir("fabricatio", roaming=True)}.toml"],
91
+ env_file=[".env", ".envrc"],
92
+ use_attribute_docstrings=True,
93
+ )
94
+
95
+ llm: LLMConfig = Field(default_factory=LLMConfig)
96
+ """
97
+ LLM Configuration
98
+ """
99
+
100
+ debug: DebugConfig = Field(default_factory=DebugConfig)
101
+ """
102
+ Debug Configuration
103
+ """
104
+
105
+ @classmethod
106
+ def settings_customise_sources(
107
+ cls,
108
+ settings_cls: type[BaseSettings],
109
+ init_settings: PydanticBaseSettingsSource,
110
+ env_settings: PydanticBaseSettingsSource,
111
+ dotenv_settings: PydanticBaseSettingsSource,
112
+ file_secret_settings: PydanticBaseSettingsSource,
113
+ ) -> tuple[PydanticBaseSettingsSource, ...]:
114
+ return (
115
+ DotEnvSettingsSource(settings_cls),
116
+ EnvSettingsSource(settings_cls),
117
+ TomlConfigSettingsSource(settings_cls),
118
+ PyprojectTomlConfigSettingsSource(settings_cls),
119
+ )
120
+
121
+
122
+ configs: Settings = Settings()
@@ -0,0 +1,148 @@
1
+ from typing import Callable, Self, overload
2
+
3
+ from pydantic import BaseModel, ConfigDict, PrivateAttr
4
+ from pymitter import EventEmitter
5
+
6
+ from fabricatio.models.events import Event
7
+
8
+
9
+ class Env(BaseModel):
10
+ """
11
+ Environment class that manages event handling using EventEmitter.
12
+
13
+ Attributes:
14
+ _ee (EventEmitter): Private attribute for event handling.
15
+ """
16
+
17
+ model_config = ConfigDict(use_attribute_docstrings=True)
18
+ _ee: EventEmitter = PrivateAttr(default_factory=EventEmitter)
19
+
20
+ @overload
21
+ def on(self, event: str | Event, /, ttl: int = -1) -> Self:
22
+ """
23
+ Registers an event listener that listens indefinitely or for a specified number of times.
24
+
25
+ Args:
26
+ event (str | Event): The event to listen for.
27
+ ttl (int): Time-to-live for the listener. If -1, the listener will listen indefinitely.
28
+
29
+ Returns:
30
+ Self: The current instance of Env.
31
+ """
32
+ ...
33
+
34
+ @overload
35
+ def on[**P, R](
36
+ self, event: str | Event, func: Callable[P, R] = None, /, ttl: int = -1
37
+ ) -> Callable[[Callable[P, R]], Callable[P, R]]:
38
+ """
39
+ Registers an event listener with a specific function that listens indefinitely or for a specified number of times.
40
+
41
+ Args:
42
+ event (str | Event): The event to listen for.
43
+ func (Callable[P, R]): The function to be called when the event is emitted.
44
+ ttl (int): Time-to-live for the listener. If -1, the listener will listen indefinitely.
45
+
46
+ Returns:
47
+ Callable[[Callable[P, R]], Callable[P, R]]: A decorator that registers the function as an event listener.
48
+ """
49
+ ...
50
+
51
+ def on[**P, R](
52
+ self,
53
+ event: str | Event,
54
+ func: Callable[P, R] = None,
55
+ /,
56
+ ttl=-1,
57
+ ) -> Callable[[Callable[P, R]], Callable[P, R]] | Self:
58
+ """
59
+ Registers an event listener with a specific function that listens indefinitely or for a specified number of times.
60
+ Args:
61
+ event (str | Event): The event to listen for.
62
+ func (Callable[P, R]): The function to be called when the event is emitted.
63
+ ttl (int): Time-to-live for the listener. If -1, the listener will listen indefinitely.
64
+
65
+ Returns:
66
+ Callable[[Callable[P, R]], Callable[P, R]] | Self: A decorator that registers the function as an event listener or the current instance of Env.
67
+ """
68
+ if isinstance(event, Event):
69
+ event = event.collapse()
70
+ if func is None:
71
+ return self._ee.on(event, ttl=ttl)
72
+
73
+ else:
74
+ self._ee.on(event, func, ttl=ttl)
75
+ return self
76
+
77
+ @overload
78
+ def once[**P, R](
79
+ self,
80
+ event: str | Event,
81
+ ) -> Callable[[Callable[P, R]], Callable[P, R]]:
82
+ """
83
+ Registers an event listener that listens only once.
84
+
85
+ Args:
86
+ event (str | Event): The event to listen for.
87
+
88
+ Returns:
89
+ Callable[[Callable[P, R]], Callable[P, R]]: A decorator that registers the function as an event listener.
90
+ """
91
+ ...
92
+
93
+ @overload
94
+ def once[**P, R](self, event: str | Event, func: Callable[[Callable[P, R]], Callable[P, R]]) -> Self:
95
+ """
96
+ Registers an event listener with a specific function that listens only once.
97
+
98
+ Args:
99
+ event (str | Event): The event to listen for.
100
+ func (Callable[P, R]): The function to be called when the event is emitted.
101
+
102
+ Returns:
103
+ Self: The current instance of Env.
104
+ """
105
+ ...
106
+
107
+ def once[**P, R](
108
+ self, event: str | Event, func: Callable[P, R] = None
109
+ ) -> Callable[[Callable[P, R]], Callable[P, R]] | Self:
110
+ """
111
+
112
+ Args:
113
+ event (str | Event): The event to listen for.
114
+ func (Callable[P, R]): The function to be called when the event is emitted.
115
+
116
+ Returns:
117
+ Callable[[Callable[P, R]], Callable[P, R]] | Self: A decorator that registers the function as an event listener or the current instance
118
+ """
119
+ if isinstance(event, Event):
120
+ event = event.collapse()
121
+ if func is None:
122
+ return self._ee.once(event)
123
+
124
+ else:
125
+ self._ee.once(event, func)
126
+ return self
127
+
128
+ def emit[**P](self, event: str | Event, *args: P.args, **kwargs: P.kwargs) -> None:
129
+ """
130
+ Emits an event to all registered listeners.
131
+
132
+ Args:
133
+ event (str | Event): The event to emit.
134
+ *args: Positional arguments to pass to the listeners.
135
+ **kwargs: Keyword arguments to pass to the listeners.
136
+ """
137
+ self._ee.emit(event, *args, **kwargs)
138
+
139
+ async def emit_async[**P](self, event: str | Event, *args: P.args, **kwargs: P.kwargs) -> None:
140
+ """
141
+ Asynchronously emits an event to all registered listeners.
142
+
143
+ Args:
144
+ event (str | Event): The event to emit.
145
+ *args: Positional arguments to pass to the listeners.
146
+ **kwargs: Keyword arguments to pass to the listeners.
147
+ """
148
+ return await self._ee.emit_async(event, *args, **kwargs)
@@ -0,0 +1 @@
1
+ # TODO: fs capabilities impl
@@ -0,0 +1,16 @@
1
+ from loguru import logger
2
+ from rich import traceback
3
+
4
+ from fabricatio.config import configs
5
+
6
+ traceback.install()
7
+ logger.level(configs.debug.log_level)
8
+ logger.add(configs.debug.log_file, rotation="1 weeks", retention="1 month", compression="zip")
9
+
10
+ if __name__ == "__main__":
11
+ logger.debug("This is a trace message.")
12
+ logger.info("This is an information message.")
13
+ logger.success("This is a success message.")
14
+ logger.warning("This is a warning message.")
15
+ logger.error("This is an error message.")
16
+ logger.critical("This is a critical message.")
@@ -0,0 +1,22 @@
1
+ from abc import abstractmethod
2
+ from typing import Tuple
3
+
4
+ from pydantic import Field
5
+
6
+ from fabricatio.models.generic import WithBriefing, LLMUsage
7
+
8
+
9
+ class Action(WithBriefing, LLMUsage):
10
+
11
+ @abstractmethod
12
+ async def execute(self, *args, **kwargs):
13
+ pass
14
+
15
+
16
+ class WorkFlow(WithBriefing, LLMUsage):
17
+ steps: Tuple[Action, ...] = Field(default=())
18
+
19
+ async def execute(self, *args, **kwargs):
20
+ # TODO dispatch params to each step according to the step's signature
21
+ for step in self.steps:
22
+ await step.execute(*args, **kwargs)
@@ -0,0 +1,68 @@
1
+ from typing import List, Self
2
+
3
+ from pydantic import BaseModel, ConfigDict, Field
4
+
5
+
6
+ class Event(BaseModel):
7
+ model_config = ConfigDict(use_attribute_docstrings=True)
8
+ delimiter: str = Field(default=".", frozen=True)
9
+ """ The delimiter used to separate the event name into segments."""
10
+
11
+ segments: List[str] = Field(default_factory=list, frozen=True)
12
+ """ The segments of the namespaces."""
13
+
14
+ @classmethod
15
+ def from_string(cls, event: str, delimiter: str = ".") -> Self:
16
+ """
17
+ Create an Event instance from a string.
18
+
19
+ Args:
20
+ event (str): The event string.
21
+ delimiter (str): The delimiter used to separate the event name into segments.
22
+
23
+ Returns:
24
+ Event: The Event instance.
25
+ """
26
+ return cls(delimiter=delimiter, segments=event.split(delimiter))
27
+
28
+ def collapse(self) -> str:
29
+ """
30
+ Collapse the event into a string.
31
+ """
32
+ return self.delimiter.join(self.segments)
33
+
34
+ def clone(self) -> Self:
35
+ """
36
+ Clone the event.
37
+ """
38
+ return Event(delimiter=self.delimiter, segments=[segment for segment in self.segments])
39
+
40
+ def push(self, segment: str) -> Self:
41
+ """
42
+ Push a segment to the event.
43
+ """
44
+ assert segment, "The segment must not be empty."
45
+ assert self.delimiter not in segment, "The segment must not contain the delimiter."
46
+
47
+ self.segments.append(segment)
48
+ return self
49
+
50
+ def pop(self) -> str:
51
+ """
52
+ Pop a segment from the event.
53
+ """
54
+ return self.segments.pop()
55
+
56
+ def clear(self) -> Self:
57
+ """
58
+ Clear the event.
59
+ """
60
+ self.segments.clear()
61
+ return self
62
+
63
+ def concat(self, event: Self) -> Self:
64
+ """
65
+ Concatenate another event to this event.
66
+ """
67
+ self.segments.extend(event.segments)
68
+ return self