chatevent 0.0.1__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.
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rex Wang
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.
22
+
@@ -0,0 +1,85 @@
1
+ Metadata-Version: 2.4
2
+ Name: chatevent
3
+ Version: 0.0.1
4
+ Summary: Normalized events and async capture interfaces for collaboration platforms
5
+ Author-email: Rex Wang <1073853456@qq.com>
6
+ License-Expression: MIT
7
+ Keywords: agent,event,webhook,zulip,discourse,gitea
8
+ Classifier: Development Status :: 2 - Pre-Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Topic :: Communications
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Provides-Extra: test
19
+ Requires-Dist: pytest>=8; extra == "test"
20
+ Dynamic: license-file
21
+
22
+ # ChatEvent
23
+
24
+ `chatevent` provides a small, typed event envelope and capture interface for
25
+ collaboration platforms such as Zulip, Discourse, Gitea, GitHub, and blogs.
26
+
27
+ It is intended to sit at the Event Capture boundary of an agent system:
28
+
29
+ ```text
30
+ platform events -> ChatEvent -> gateway/router -> agent execution
31
+ ```
32
+
33
+ ## Install
34
+
35
+ ```bash
36
+ pip install chatevent
37
+ ```
38
+
39
+ ## Define a normalized event
40
+
41
+ ```python
42
+ from datetime import datetime, timezone
43
+
44
+ from chatevent import CaptureMode, ChatEvent
45
+
46
+ event = ChatEvent(
47
+ id="42",
48
+ source="gitea",
49
+ kind="issue.opened",
50
+ occurred_at=datetime.now(timezone.utc),
51
+ capture_mode=CaptureMode.PUSH,
52
+ conversation_id="owner/repo#42",
53
+ payload={"title": "Investigate event routing"},
54
+ )
55
+
56
+ assert event.dedupe_key == "gitea:42"
57
+ ```
58
+
59
+ ## Implement a monitor
60
+
61
+ An adapter exposes an asynchronous stream. It may receive pushed events or
62
+ poll a platform with an incremental cursor.
63
+
64
+ ```python
65
+ from collections.abc import AsyncIterator
66
+
67
+ from chatevent import CaptureMode, ChatEvent, EventMonitor
68
+
69
+
70
+ class GiteaMonitor:
71
+ source = "gitea"
72
+ mode = CaptureMode.PULL
73
+
74
+ async def events(self, *, cursor: str | None = None) -> AsyncIterator[ChatEvent]:
75
+ if False: # Replace with incremental API reads.
76
+ yield
77
+
78
+
79
+ monitor: EventMonitor = GiteaMonitor()
80
+ ```
81
+
82
+ The initial release deliberately contains no platform SDK or runtime
83
+ dependency. Platform adapters, persistence, filtering, and delivery guarantees
84
+ can evolve independently around this stable boundary.
85
+
@@ -0,0 +1,64 @@
1
+ # ChatEvent
2
+
3
+ `chatevent` provides a small, typed event envelope and capture interface for
4
+ collaboration platforms such as Zulip, Discourse, Gitea, GitHub, and blogs.
5
+
6
+ It is intended to sit at the Event Capture boundary of an agent system:
7
+
8
+ ```text
9
+ platform events -> ChatEvent -> gateway/router -> agent execution
10
+ ```
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ pip install chatevent
16
+ ```
17
+
18
+ ## Define a normalized event
19
+
20
+ ```python
21
+ from datetime import datetime, timezone
22
+
23
+ from chatevent import CaptureMode, ChatEvent
24
+
25
+ event = ChatEvent(
26
+ id="42",
27
+ source="gitea",
28
+ kind="issue.opened",
29
+ occurred_at=datetime.now(timezone.utc),
30
+ capture_mode=CaptureMode.PUSH,
31
+ conversation_id="owner/repo#42",
32
+ payload={"title": "Investigate event routing"},
33
+ )
34
+
35
+ assert event.dedupe_key == "gitea:42"
36
+ ```
37
+
38
+ ## Implement a monitor
39
+
40
+ An adapter exposes an asynchronous stream. It may receive pushed events or
41
+ poll a platform with an incremental cursor.
42
+
43
+ ```python
44
+ from collections.abc import AsyncIterator
45
+
46
+ from chatevent import CaptureMode, ChatEvent, EventMonitor
47
+
48
+
49
+ class GiteaMonitor:
50
+ source = "gitea"
51
+ mode = CaptureMode.PULL
52
+
53
+ async def events(self, *, cursor: str | None = None) -> AsyncIterator[ChatEvent]:
54
+ if False: # Replace with incremental API reads.
55
+ yield
56
+
57
+
58
+ monitor: EventMonitor = GiteaMonitor()
59
+ ```
60
+
61
+ The initial release deliberately contains no platform SDK or runtime
62
+ dependency. Platform adapters, persistence, filtering, and delivery guarantees
63
+ can evolve independently around this stable boundary.
64
+
@@ -0,0 +1,37 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "chatevent"
7
+ version = "0.0.1"
8
+ authors = [
9
+ {name = "Rex Wang", email = "1073853456@qq.com"},
10
+ ]
11
+ description = "Normalized events and async capture interfaces for collaboration platforms"
12
+ readme = "README.md"
13
+ requires-python = ">=3.10"
14
+ license = "MIT"
15
+ keywords = ["agent", "event", "webhook", "zulip", "discourse", "gitea"]
16
+ classifiers = [
17
+ "Development Status :: 2 - Pre-Alpha",
18
+ "Intended Audience :: Developers",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Topic :: Communications",
23
+ "Typing :: Typed",
24
+ ]
25
+ dependencies = []
26
+
27
+ [project.optional-dependencies]
28
+ test = ["pytest>=8"]
29
+
30
+ [tool.setuptools.packages.find]
31
+ where = ["src"]
32
+
33
+ [tool.setuptools.package-data]
34
+ chatevent = ["py.typed"]
35
+
36
+ [tool.pytest.ini_options]
37
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,8 @@
1
+ """Public API for ChatEvent."""
2
+
3
+ from .model import CaptureMode, ChatEvent
4
+ from .monitor import EventMonitor
5
+
6
+ __all__ = ["CaptureMode", "ChatEvent", "EventMonitor"]
7
+ __version__ = "0.0.1"
8
+
@@ -0,0 +1,65 @@
1
+ """Normalized event model shared by platform adapters."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+ from datetime import datetime
7
+ from enum import Enum
8
+ from typing import Any, Mapping
9
+
10
+
11
+ class CaptureMode(str, Enum):
12
+ """How an event entered the capture layer."""
13
+
14
+ PUSH = "push"
15
+ PULL = "pull"
16
+
17
+
18
+ @dataclass(frozen=True, slots=True)
19
+ class ChatEvent:
20
+ """A platform-neutral event envelope.
21
+
22
+ Event IDs only need to be stable within a source. Platform-specific data
23
+ stays in ``payload`` so the core model can evolve independently of SDKs.
24
+ """
25
+
26
+ id: str
27
+ source: str
28
+ kind: str
29
+ occurred_at: datetime
30
+ capture_mode: CaptureMode
31
+ payload: Mapping[str, Any] = field(default_factory=dict)
32
+ actor_id: str | None = None
33
+ conversation_id: str | None = None
34
+ url: str | None = None
35
+ cursor: str | None = None
36
+
37
+ def __post_init__(self) -> None:
38
+ for name in ("id", "source", "kind"):
39
+ if not getattr(self, name).strip():
40
+ raise ValueError(f"{name} must not be empty")
41
+ if self.occurred_at.tzinfo is None or self.occurred_at.utcoffset() is None:
42
+ raise ValueError("occurred_at must be timezone-aware")
43
+
44
+ @property
45
+ def dedupe_key(self) -> str:
46
+ """Return the default stable key used to suppress duplicate delivery."""
47
+
48
+ return f"{self.source}:{self.id}"
49
+
50
+ def to_dict(self) -> dict[str, Any]:
51
+ """Return a JSON-compatible representation of the envelope."""
52
+
53
+ return {
54
+ "id": self.id,
55
+ "source": self.source,
56
+ "kind": self.kind,
57
+ "occurred_at": self.occurred_at.isoformat(),
58
+ "capture_mode": self.capture_mode.value,
59
+ "payload": dict(self.payload),
60
+ "actor_id": self.actor_id,
61
+ "conversation_id": self.conversation_id,
62
+ "url": self.url,
63
+ "cursor": self.cursor,
64
+ }
65
+
@@ -0,0 +1,21 @@
1
+ """Extension protocol for event capture adapters."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import AsyncIterator
6
+ from typing import Protocol
7
+
8
+ from .model import CaptureMode, ChatEvent
9
+
10
+
11
+ class EventMonitor(Protocol):
12
+ """An asynchronous source of normalized events."""
13
+
14
+ source: str
15
+ mode: CaptureMode
16
+
17
+ def events(self, *, cursor: str | None = None) -> AsyncIterator[ChatEvent]:
18
+ """Yield new events, optionally continuing from a source cursor."""
19
+
20
+ ...
21
+
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,85 @@
1
+ Metadata-Version: 2.4
2
+ Name: chatevent
3
+ Version: 0.0.1
4
+ Summary: Normalized events and async capture interfaces for collaboration platforms
5
+ Author-email: Rex Wang <1073853456@qq.com>
6
+ License-Expression: MIT
7
+ Keywords: agent,event,webhook,zulip,discourse,gitea
8
+ Classifier: Development Status :: 2 - Pre-Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Topic :: Communications
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Provides-Extra: test
19
+ Requires-Dist: pytest>=8; extra == "test"
20
+ Dynamic: license-file
21
+
22
+ # ChatEvent
23
+
24
+ `chatevent` provides a small, typed event envelope and capture interface for
25
+ collaboration platforms such as Zulip, Discourse, Gitea, GitHub, and blogs.
26
+
27
+ It is intended to sit at the Event Capture boundary of an agent system:
28
+
29
+ ```text
30
+ platform events -> ChatEvent -> gateway/router -> agent execution
31
+ ```
32
+
33
+ ## Install
34
+
35
+ ```bash
36
+ pip install chatevent
37
+ ```
38
+
39
+ ## Define a normalized event
40
+
41
+ ```python
42
+ from datetime import datetime, timezone
43
+
44
+ from chatevent import CaptureMode, ChatEvent
45
+
46
+ event = ChatEvent(
47
+ id="42",
48
+ source="gitea",
49
+ kind="issue.opened",
50
+ occurred_at=datetime.now(timezone.utc),
51
+ capture_mode=CaptureMode.PUSH,
52
+ conversation_id="owner/repo#42",
53
+ payload={"title": "Investigate event routing"},
54
+ )
55
+
56
+ assert event.dedupe_key == "gitea:42"
57
+ ```
58
+
59
+ ## Implement a monitor
60
+
61
+ An adapter exposes an asynchronous stream. It may receive pushed events or
62
+ poll a platform with an incremental cursor.
63
+
64
+ ```python
65
+ from collections.abc import AsyncIterator
66
+
67
+ from chatevent import CaptureMode, ChatEvent, EventMonitor
68
+
69
+
70
+ class GiteaMonitor:
71
+ source = "gitea"
72
+ mode = CaptureMode.PULL
73
+
74
+ async def events(self, *, cursor: str | None = None) -> AsyncIterator[ChatEvent]:
75
+ if False: # Replace with incremental API reads.
76
+ yield
77
+
78
+
79
+ monitor: EventMonitor = GiteaMonitor()
80
+ ```
81
+
82
+ The initial release deliberately contains no platform SDK or runtime
83
+ dependency. Platform adapters, persistence, filtering, and delivery guarantees
84
+ can evolve independently around this stable boundary.
85
+
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/chatevent/__init__.py
5
+ src/chatevent/model.py
6
+ src/chatevent/monitor.py
7
+ src/chatevent/py.typed
8
+ src/chatevent.egg-info/PKG-INFO
9
+ src/chatevent.egg-info/SOURCES.txt
10
+ src/chatevent.egg-info/dependency_links.txt
11
+ src/chatevent.egg-info/requires.txt
12
+ src/chatevent.egg-info/top_level.txt
13
+ tests/test_model.py
@@ -0,0 +1,3 @@
1
+
2
+ [test]
3
+ pytest>=8
@@ -0,0 +1 @@
1
+ chatevent
@@ -0,0 +1,45 @@
1
+ from datetime import datetime, timezone
2
+ import unittest
3
+
4
+ from chatevent import CaptureMode, ChatEvent
5
+
6
+
7
+ class ChatEventTests(unittest.TestCase):
8
+ def test_event_has_stable_dedupe_key_and_serializes(self) -> None:
9
+ event = ChatEvent(
10
+ id="42",
11
+ source="gitea",
12
+ kind="issue.opened",
13
+ occurred_at=datetime(2026, 8, 18, tzinfo=timezone.utc),
14
+ capture_mode=CaptureMode.PUSH,
15
+ payload={"title": "Investigate event routing"},
16
+ )
17
+
18
+ self.assertEqual(event.dedupe_key, "gitea:42")
19
+ self.assertEqual(event.to_dict()["capture_mode"], "push")
20
+ self.assertEqual(event.to_dict()["occurred_at"], "2026-08-18T00:00:00+00:00")
21
+
22
+ def test_event_rejects_naive_datetime(self) -> None:
23
+ with self.assertRaisesRegex(ValueError, "timezone-aware"):
24
+ ChatEvent(
25
+ id="42",
26
+ source="gitea",
27
+ kind="issue.opened",
28
+ occurred_at=datetime(2026, 8, 18),
29
+ capture_mode=CaptureMode.PULL,
30
+ )
31
+
32
+ def test_event_rejects_empty_identity_fields(self) -> None:
33
+ with self.assertRaisesRegex(ValueError, "source must not be empty"):
34
+ ChatEvent(
35
+ id="42",
36
+ source=" ",
37
+ kind="issue.opened",
38
+ occurred_at=datetime(2026, 8, 18, tzinfo=timezone.utc),
39
+ capture_mode=CaptureMode.PULL,
40
+ )
41
+
42
+
43
+ if __name__ == "__main__":
44
+ unittest.main()
45
+