chatevent 0.0.1__py3-none-any.whl
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.
- chatevent/__init__.py +8 -0
- chatevent/model.py +65 -0
- chatevent/monitor.py +21 -0
- chatevent/py.typed +1 -0
- chatevent-0.0.1.dist-info/METADATA +85 -0
- chatevent-0.0.1.dist-info/RECORD +9 -0
- chatevent-0.0.1.dist-info/WHEEL +5 -0
- chatevent-0.0.1.dist-info/licenses/LICENSE +22 -0
- chatevent-0.0.1.dist-info/top_level.txt +1 -0
chatevent/__init__.py
ADDED
chatevent/model.py
ADDED
|
@@ -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
|
+
|
chatevent/monitor.py
ADDED
|
@@ -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
|
+
|
chatevent/py.typed
ADDED
|
@@ -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,9 @@
|
|
|
1
|
+
chatevent/__init__.py,sha256=DSK53htIX9Nh6TAbJVbCIvunqvQ4utX2laICGHLBADc,188
|
|
2
|
+
chatevent/model.py,sha256=FV8BN6g-ArfCUaJKSjj8G4o6bAO6Fk78KufLDyMKjFY,1948
|
|
3
|
+
chatevent/monitor.py,sha256=xSLKPkcAFkZtjYna_27e5kmKF7Dg0cs1hcuQSDcqdFY,500
|
|
4
|
+
chatevent/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
5
|
+
chatevent-0.0.1.dist-info/licenses/LICENSE,sha256=sDWCc1XORwxjrZIzXJaEMOxFIwBJDFa4CyGc6WQBA6g,1066
|
|
6
|
+
chatevent-0.0.1.dist-info/METADATA,sha256=ud2SUB0KF5sOoVi3eWHXMCOn1GZhjW312sJeOFuEvAQ,2257
|
|
7
|
+
chatevent-0.0.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
8
|
+
chatevent-0.0.1.dist-info/top_level.txt,sha256=5STX44ckdRG83SMXX5UaHoeLkXv2wdoXBYDHVGPf9CM,10
|
|
9
|
+
chatevent-0.0.1.dist-info/RECORD,,
|
|
@@ -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 @@
|
|
|
1
|
+
chatevent
|