3tears-channels 0.14.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 (46) hide show
  1. 3tears_channels-0.14.0/.gitignore +216 -0
  2. 3tears_channels-0.14.0/LICENSE +21 -0
  3. 3tears_channels-0.14.0/PKG-INFO +56 -0
  4. 3tears_channels-0.14.0/README.md +30 -0
  5. 3tears_channels-0.14.0/pyproject.toml +46 -0
  6. 3tears_channels-0.14.0/src/threetears/channels/__init__.py +133 -0
  7. 3tears_channels-0.14.0/src/threetears/channels/delivery.py +75 -0
  8. 3tears_channels-0.14.0/src/threetears/channels/discord.py +316 -0
  9. 3tears_channels-0.14.0/src/threetears/channels/formatting.py +584 -0
  10. 3tears_channels-0.14.0/src/threetears/channels/frames.py +280 -0
  11. 3tears_channels-0.14.0/src/threetears/channels/presence/__init__.py +56 -0
  12. 3tears_channels-0.14.0/src/threetears/channels/presence/collection.py +516 -0
  13. 3tears_channels-0.14.0/src/threetears/channels/presence/entities.py +82 -0
  14. 3tears_channels-0.14.0/src/threetears/channels/presence/fanout.py +267 -0
  15. 3tears_channels-0.14.0/src/threetears/channels/presence/l1_cache.py +113 -0
  16. 3tears_channels-0.14.0/src/threetears/channels/presence/room_state.py +338 -0
  17. 3tears_channels-0.14.0/src/threetears/channels/presence/sweeper.py +208 -0
  18. 3tears_channels-0.14.0/src/threetears/channels/presence/wire.py +60 -0
  19. 3tears_channels-0.14.0/src/threetears/channels/protocol.py +160 -0
  20. 3tears_channels-0.14.0/src/threetears/channels/slack.py +354 -0
  21. 3tears_channels-0.14.0/src/threetears/channels/webhook.py +467 -0
  22. 3tears_channels-0.14.0/src/threetears/channels/websocket.py +950 -0
  23. 3tears_channels-0.14.0/tests/__init__.py +0 -0
  24. 3tears_channels-0.14.0/tests/integration/channels/conftest.py +91 -0
  25. 3tears_channels-0.14.0/tests/integration/channels/presence/conftest.py +105 -0
  26. 3tears_channels-0.14.0/tests/integration/channels/presence/test_presence_cross_pod.py +366 -0
  27. 3tears_channels-0.14.0/tests/integration/channels/presence/test_room_fanout_cross_pod.py +140 -0
  28. 3tears_channels-0.14.0/tests/integration/channels/test_webhook_e2e.py +508 -0
  29. 3tears_channels-0.14.0/tests/integration/channels/test_websocket_cross_pod.py +516 -0
  30. 3tears_channels-0.14.0/tests/unit/__init__.py +0 -0
  31. 3tears_channels-0.14.0/tests/unit/channels/__init__.py +0 -0
  32. 3tears_channels-0.14.0/tests/unit/channels/presence/__init__.py +0 -0
  33. 3tears_channels-0.14.0/tests/unit/channels/presence/conftest.py +138 -0
  34. 3tears_channels-0.14.0/tests/unit/channels/presence/test_collection.py +286 -0
  35. 3tears_channels-0.14.0/tests/unit/channels/presence/test_enforcement.py +121 -0
  36. 3tears_channels-0.14.0/tests/unit/channels/presence/test_fanout.py +322 -0
  37. 3tears_channels-0.14.0/tests/unit/channels/presence/test_room_state.py +207 -0
  38. 3tears_channels-0.14.0/tests/unit/channels/presence/test_sweeper.py +100 -0
  39. 3tears_channels-0.14.0/tests/unit/channels/test_discord.py +1168 -0
  40. 3tears_channels-0.14.0/tests/unit/channels/test_formatting.py +299 -0
  41. 3tears_channels-0.14.0/tests/unit/channels/test_frames.py +170 -0
  42. 3tears_channels-0.14.0/tests/unit/channels/test_protocol.py +351 -0
  43. 3tears_channels-0.14.0/tests/unit/channels/test_slack.py +1037 -0
  44. 3tears_channels-0.14.0/tests/unit/channels/test_webhook.py +930 -0
  45. 3tears_channels-0.14.0/tests/unit/channels/test_websocket.py +1087 -0
  46. 3tears_channels-0.14.0/tests/unit/channels/test_websocket_task03.py +785 -0
@@ -0,0 +1,216 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
208
+
209
+ # Claude Code local state
210
+ .claude/
211
+
212
+ # prawduct session evidence (local governance artifacts, never shipped)
213
+ .prawduct/
214
+
215
+ # macOS folder metadata
216
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mark Pace
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,56 @@
1
+ Metadata-Version: 2.4
2
+ Name: 3tears-channels
3
+ Version: 0.14.0
4
+ Summary: Unified message protocol for channel adapters in the 3tears platform
5
+ Project-URL: Repository, https://github.com/pacepace/3tears
6
+ Author: pace
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Requires-Python: >=3.14
10
+ Requires-Dist: 3tears
11
+ Requires-Dist: 3tears-agent-acl
12
+ Requires-Dist: 3tears-nats
13
+ Requires-Dist: 3tears-observe
14
+ Provides-Extra: discord
15
+ Requires-Dist: discord-py>=2.7; extra == 'discord'
16
+ Provides-Extra: slack
17
+ Requires-Dist: aiohttp>=3.9; extra == 'slack'
18
+ Requires-Dist: slack-bolt>=1.28; extra == 'slack'
19
+ Requires-Dist: slack-sdk>=3.41; extra == 'slack'
20
+ Provides-Extra: webhook
21
+ Requires-Dist: 3tears-agent-wake>=0.9.0; extra == 'webhook'
22
+ Requires-Dist: fastapi>=0.110; extra == 'webhook'
23
+ Provides-Extra: websocket
24
+ Requires-Dist: starlette>=0.36; extra == 'websocket'
25
+ Description-Content-Type: text/markdown
26
+
27
+ # 3tears-channels
28
+
29
+ A unified message protocol for the 3tears framework, with adapters for Slack, Discord, and WebSocket clients. Write your agent logic once and deliver it across channels.
30
+
31
+ ```bash
32
+ pip install 3tears-channels
33
+ ```
34
+
35
+ ## What you get
36
+
37
+ - **One message model** -- `ChannelMessage`, `ChannelResponse`, `ChannelDeliveryMessage`, and `Attachment` carry a request and its reply regardless of channel.
38
+ - **Routing** -- `ChannelRouter` and `StreamingChannelRouter` dispatch inbound messages and stream responses back.
39
+ - **Slack and Discord** -- payload and rich-formatting builders (`build_slack_blocks`, `build_slack_payload`, `build_discord_embed`, `build_discord_payload`) plus a `should_use_rich_formatting` helper.
40
+ - **WebSocket** -- `WebSocketHandler`, `WebSocketProtocol`, a `ConnectionRegistry`, and frame primitives for real-time clients.
41
+ - **Rooms and presence** -- `RoomFanout`, `RoomState`, `RoomIndexCollection`, and a three-tier-backed `PresenceCollection` with a `PresenceSweeper` for connection liveness.
42
+
43
+ ## Quickstart
44
+
45
+ ```python
46
+ from threetears.channels import ChannelRouter, ChannelMessage, build_slack_blocks
47
+
48
+ router = ChannelRouter(...)
49
+ response = await router.dispatch(ChannelMessage(text="hello", channel="slack", ...))
50
+
51
+ blocks = build_slack_blocks(response)
52
+ ```
53
+
54
+ ## License
55
+
56
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,30 @@
1
+ # 3tears-channels
2
+
3
+ A unified message protocol for the 3tears framework, with adapters for Slack, Discord, and WebSocket clients. Write your agent logic once and deliver it across channels.
4
+
5
+ ```bash
6
+ pip install 3tears-channels
7
+ ```
8
+
9
+ ## What you get
10
+
11
+ - **One message model** -- `ChannelMessage`, `ChannelResponse`, `ChannelDeliveryMessage`, and `Attachment` carry a request and its reply regardless of channel.
12
+ - **Routing** -- `ChannelRouter` and `StreamingChannelRouter` dispatch inbound messages and stream responses back.
13
+ - **Slack and Discord** -- payload and rich-formatting builders (`build_slack_blocks`, `build_slack_payload`, `build_discord_embed`, `build_discord_payload`) plus a `should_use_rich_formatting` helper.
14
+ - **WebSocket** -- `WebSocketHandler`, `WebSocketProtocol`, a `ConnectionRegistry`, and frame primitives for real-time clients.
15
+ - **Rooms and presence** -- `RoomFanout`, `RoomState`, `RoomIndexCollection`, and a three-tier-backed `PresenceCollection` with a `PresenceSweeper` for connection liveness.
16
+
17
+ ## Quickstart
18
+
19
+ ```python
20
+ from threetears.channels import ChannelRouter, ChannelMessage, build_slack_blocks
21
+
22
+ router = ChannelRouter(...)
23
+ response = await router.dispatch(ChannelMessage(text="hello", channel="slack", ...))
24
+
25
+ blocks = build_slack_blocks(response)
26
+ ```
27
+
28
+ ## License
29
+
30
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,46 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "3tears-channels"
7
+ version = "0.14.0"
8
+ description = "Unified message protocol for channel adapters in the 3tears platform"
9
+ readme = "README.md"
10
+ requires-python = ">=3.14"
11
+ authors = [{name = "pace"}]
12
+ license = "MIT"
13
+ license-files = ["LICENSE"]
14
+ dependencies = [
15
+ "3tears",
16
+ "3tears-agent-acl",
17
+ "3tears-nats",
18
+ "3tears-observe",
19
+ ]
20
+
21
+ [project.optional-dependencies]
22
+ slack = ["slack-bolt>=1.28", "slack-sdk>=3.41", "aiohttp>=3.9"]
23
+ discord = ["discord.py>=2.7"]
24
+ websocket = ["starlette>=0.36"]
25
+ # webhook receiver depends on:
26
+ # * fastapi -- the route-mount target (consumers register the
27
+ # receiver on their FastAPI app via ``add_api_route``)
28
+ # * 3tears-agent-wake -- ``webhook_receive`` is the verify+rate-limit+
29
+ # dispatch entry point the receiver delegates to. This creates a
30
+ # one-direction edge: channels -> agent-wake -> conversations +
31
+ # agent-skills. agent-wake does NOT depend on channels (the wake
32
+ # adapter is a function the channels-side HTTP shim calls into).
33
+ webhook = ["fastapi>=0.110", "3tears-agent-wake>=0.9.0"]
34
+
35
+ [project.urls]
36
+ Repository = "https://github.com/pacepace/3tears"
37
+
38
+ [tool.hatch.build.targets.wheel]
39
+ packages = ["src/threetears"]
40
+
41
+ [tool.uv.sources]
42
+ 3tears = { workspace = true }
43
+ 3tears-agent-acl = { workspace = true }
44
+ 3tears-nats = { workspace = true }
45
+ 3tears-observe = { workspace = true }
46
+ 3tears-agent-wake = { workspace = true }
@@ -0,0 +1,133 @@
1
+ """3tears-channels: unified message protocol for channel adapters."""
2
+
3
+ from __future__ import annotations
4
+
5
+ # Version derived from pyproject.toml so the metadata is the single
6
+ # source of truth -- a future release that bumps pyproject without
7
+ # updating ``__init__.py`` can't drift the runtime ``__version__``.
8
+ # The except guard handles the rare case where the package isn't
9
+ # installed via importlib.metadata (e.g. running directly from a
10
+ # checked-out source tree without ``uv sync``); the fallback keeps
11
+ # imports working but reports ``unknown`` rather than crashing.
12
+ from importlib.metadata import PackageNotFoundError as _PackageNotFoundError
13
+ from importlib.metadata import version as _version
14
+
15
+ try:
16
+ __version__ = _version("3tears-channels")
17
+ except _PackageNotFoundError: # pragma: no cover - dev fallback
18
+ __version__ = "unknown"
19
+
20
+ from threetears.channels.formatting import (
21
+ build_discord_embed,
22
+ build_discord_payload,
23
+ build_slack_blocks,
24
+ build_slack_payload,
25
+ should_use_rich_formatting,
26
+ )
27
+ from threetears.channels.frames import (
28
+ Frame,
29
+ FrameHandler,
30
+ NsEntity,
31
+ NsResolver,
32
+ OpHandler,
33
+ OpRejected,
34
+ OpResult,
35
+ ReplaySource,
36
+ )
37
+ from threetears.channels.delivery import (
38
+ ChannelDeliveryMessage,
39
+ )
40
+ from threetears.channels.protocol import (
41
+ Attachment,
42
+ ChannelMessage,
43
+ ChannelResponse,
44
+ ChannelRouter,
45
+ )
46
+ from threetears.channels.presence import (
47
+ PRESENCE_L1_METADATA,
48
+ PRESENCE_L1_TABLE_NAMES,
49
+ PresenceCollection,
50
+ PresenceConnectionCollection,
51
+ PresenceConnectionEntity,
52
+ PresenceSweeper,
53
+ RoomFanout,
54
+ RoomFrame,
55
+ RoomIndexCollection,
56
+ RoomIndexEntity,
57
+ RoomMember,
58
+ RoomState,
59
+ create_presence_l1_backend,
60
+ )
61
+ from threetears.channels.websocket import (
62
+ ConnectionRegistry,
63
+ StreamingChannelRouter,
64
+ WebSocketHandler,
65
+ WebSocketProtocol,
66
+ )
67
+
68
+ __all__ = [
69
+ "PRESENCE_L1_METADATA",
70
+ "PRESENCE_L1_TABLE_NAMES",
71
+ "Attachment",
72
+ "ChannelDeliveryMessage",
73
+ "ChannelMessage",
74
+ "ChannelResponse",
75
+ "ChannelRouter",
76
+ "ConnectionRegistry",
77
+ "Frame",
78
+ "FrameHandler",
79
+ "NsEntity",
80
+ "NsResolver",
81
+ "OpHandler",
82
+ "OpRejected",
83
+ "OpResult",
84
+ "PresenceCollection",
85
+ "PresenceConnectionCollection",
86
+ "PresenceConnectionEntity",
87
+ "PresenceSweeper",
88
+ "ReplaySource",
89
+ "RoomFanout",
90
+ "RoomFrame",
91
+ "RoomIndexCollection",
92
+ "RoomIndexEntity",
93
+ "RoomMember",
94
+ "RoomState",
95
+ "StreamingChannelRouter",
96
+ "WebSocketHandler",
97
+ "WebSocketProtocol",
98
+ "build_discord_embed",
99
+ "build_discord_payload",
100
+ "build_slack_blocks",
101
+ "build_slack_payload",
102
+ "create_presence_l1_backend",
103
+ "should_use_rich_formatting",
104
+ ]
105
+
106
+ try:
107
+ from threetears.channels.slack import SlackAdapter # noqa: F401
108
+
109
+ __all__.append("SlackAdapter")
110
+ except ImportError:
111
+ pass
112
+
113
+ try:
114
+ from threetears.channels.discord import DiscordAdapter # noqa: F401
115
+
116
+ __all__.append("DiscordAdapter")
117
+ except ImportError:
118
+ pass
119
+
120
+ # The webhook receiver requires the ``webhook`` extra (fastapi +
121
+ # 3tears-agent-wake). Guarded the same way as the slack / discord
122
+ # adapters so consumers without the extra installed can still import
123
+ # the rest of the channels package.
124
+ try:
125
+ from threetears.channels.webhook import ( # noqa: F401
126
+ Verifier,
127
+ WebhookReceiver,
128
+ verify_generic_hmac_sha256,
129
+ )
130
+
131
+ __all__.extend(["Verifier", "WebhookReceiver", "verify_generic_hmac_sha256"])
132
+ except ImportError:
133
+ pass
@@ -0,0 +1,75 @@
1
+ """durable channel-delivery wire model.
2
+
3
+ the agent publishes a finished answer to the durable JetStream delivery subject
4
+ (:func:`threetears.nats.Subjects.channels_deliver`) with the channel routing
5
+ lifted off the inbound message; the channel adapter durable-consumes it and
6
+ posts it to the destination thread. this is the typed wire envelope for that
7
+ hand-off -- a Pydantic model because it crosses the NATS boundary (the channel
8
+ ``protocol`` dataclasses are internal working objects, never serialized).
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from datetime import UTC, datetime
14
+ from uuid import UUID
15
+
16
+ from pydantic import BaseModel, Field
17
+
18
+ __all__ = ["ChannelDeliveryMessage"]
19
+
20
+
21
+ class ChannelDeliveryMessage(BaseModel):
22
+ """a finished agent answer awaiting durable delivery to a channel thread.
23
+
24
+ carries the answer content plus exactly the routing the adapter needs to
25
+ post out-of-band: the channel family, the workspace / channel / thread refs
26
+ (lifted off the inbound message's metadata), and the dedup coordinates.
27
+
28
+ :param correlation_id: per-turn correlation id of the originating request;
29
+ with ``conversation_id`` forms the dedup key so a JetStream redelivery
30
+ (or a second adapter replica) never double-posts
31
+ :ptype correlation_id: UUID
32
+ :param conversation_id: derived conversation id the answer belongs to
33
+ :ptype conversation_id: UUID
34
+ :param agent_id: agent that produced the answer
35
+ :ptype agent_id: UUID
36
+ :param channel_type: channel family (``slack``, ``discord``, ...)
37
+ :ptype channel_type: str
38
+ :param workspace_ref: platform workspace / team reference (slack ``team``);
39
+ the adapter maps this to the right bot token
40
+ :ptype workspace_ref: str | None
41
+ :param channel_ref: platform channel reference to post into
42
+ :ptype channel_ref: str | None
43
+ :param thread_ref: platform thread reference to reply in (slack ``thread_ts``)
44
+ :ptype thread_ref: str | None
45
+ :param content: answer text in markdown
46
+ :ptype content: str
47
+ :param date_created: answer-ready timestamp (timezone-aware UTC)
48
+ :ptype date_created: datetime
49
+ """
50
+
51
+ correlation_id: UUID
52
+ conversation_id: UUID
53
+ agent_id: UUID
54
+ channel_type: str
55
+ workspace_ref: str | None = None
56
+ channel_ref: str | None = None
57
+ thread_ref: str | None = None
58
+ content: str
59
+ date_created: datetime = Field(default_factory=lambda: datetime.now(UTC))
60
+
61
+ @property
62
+ def dedup_key(self) -> str:
63
+ """return deterministic dedup key for at-least-once delivery.
64
+
65
+ keyed on ``(conversation, correlation)`` so the same answer redelivered
66
+ by JetStream -- or drained by a second adapter replica -- is posted at
67
+ most once. the separator is ``-`` (not ``:``) because this string is a
68
+ NATS KV key, and KV keys admit only ``[-/_=.a-zA-Z0-9]`` -- a colon
69
+ raises ``InvalidKeyError``. both halves are 32-char hex, so ``-`` is
70
+ unambiguous.
71
+
72
+ :return: dedup key ``{conversation_hex}-{correlation_hex}``
73
+ :rtype: str
74
+ """
75
+ return f"{self.conversation_id.hex}-{self.correlation_id.hex}"