tinkerfin-messaging 0.1.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.
- tinkerfin_messaging-0.1.1/LICENSE +201 -0
- tinkerfin_messaging-0.1.1/MANIFEST.in +1 -0
- tinkerfin_messaging-0.1.1/PKG-INFO +162 -0
- tinkerfin_messaging-0.1.1/README.md +131 -0
- tinkerfin_messaging-0.1.1/pyproject.toml +48 -0
- tinkerfin_messaging-0.1.1/setup.cfg +4 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/__init__.py +228 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_agui_channel.py +281 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_capacity.py +48 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_identity.py +69 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_message_channel.py +1491 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_messaging_boundary.py +397 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_messaging_ledger.py +979 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_messaging_transition.py +1106 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_producer_runtime.py +945 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_redis_capacity.py +53 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_redis_control.py +1638 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_redis_journal.py +591 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_redis_notifications.py +332 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_redis_scripts.py +1130 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_sql_records.py +249 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_sql_schema.py +486 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/_tasks.py +174 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/agui.py +468 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/backend.py +1004 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/backend_contract.py +766 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/errors.py +480 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/limits.py +57 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/messaging.py +1242 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/models.py +114 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/native.py +77 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/protocols.py +158 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/py.typed +1 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/redis.py +1619 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/retention.py +70 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/sources.py +741 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/sqlalchemy.py +1197 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/sse.py +32 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging/testing.py +224 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging.egg-info/PKG-INFO +162 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging.egg-info/SOURCES.txt +59 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging.egg-info/dependency_links.txt +1 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging.egg-info/requires.txt +15 -0
- tinkerfin_messaging-0.1.1/src/tinkerfin_messaging.egg-info/top_level.txt +1 -0
- tinkerfin_messaging-0.1.1/tests/backend_harness.py +213 -0
- tinkerfin_messaging-0.1.1/tests/test_channel_preflight.py +466 -0
- tinkerfin_messaging-0.1.1/tests/test_channel_reads.py +195 -0
- tinkerfin_messaging-0.1.1/tests/test_journal.py +556 -0
- tinkerfin_messaging-0.1.1/tests/test_messaging_runtime.py +426 -0
- tinkerfin_messaging-0.1.1/tests/test_messaging_sql_backend.py +372 -0
- tinkerfin_messaging-0.1.1/tests/test_messaging_sql_failures.py +255 -0
- tinkerfin_messaging-0.1.1/tests/test_namespace_isolation.py +72 -0
- tinkerfin_messaging-0.1.1/tests/test_publication.py +241 -0
- tinkerfin_messaging-0.1.1/tests/test_recoverable_runtime.py +247 -0
- tinkerfin_messaging-0.1.1/tests/test_request_binding.py +96 -0
- tinkerfin_messaging-0.1.1/tests/test_retention.py +23 -0
- tinkerfin_messaging-0.1.1/tests/test_runtime_agui_integration.py +874 -0
- tinkerfin_messaging-0.1.1/tests/test_runtime_cancel_and_failure.py +545 -0
- tinkerfin_messaging-0.1.1/tests/test_runtime_lifecycle.py +137 -0
- tinkerfin_messaging-0.1.1/tests/test_stream_deletion.py +296 -0
- tinkerfin_messaging-0.1.1/tests/test_total_capacity.py +274 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include tests/backend_harness.py
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tinkerfin-messaging
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Replayable messaging for TinkerFin Native and AG-UI streams.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/tinkerfin-ai/tinkerfin-harness
|
|
7
|
+
Project-URL: Repository, https://github.com/tinkerfin-ai/tinkerfin-harness
|
|
8
|
+
Project-URL: Issues, https://github.com/tinkerfin-ai/tinkerfin-harness/issues
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: pydantic<3,>=2
|
|
20
|
+
Requires-Dist: tinkerfin-contracts==0.1.1
|
|
21
|
+
Provides-Extra: redis
|
|
22
|
+
Requires-Dist: redis<9,>=6; extra == "redis"
|
|
23
|
+
Provides-Extra: sqlalchemy
|
|
24
|
+
Requires-Dist: sqlalchemy[asyncio]<3,>=2.0.52; extra == "sqlalchemy"
|
|
25
|
+
Requires-Dist: tinkerfin-sqlalchemy==0.1.1; extra == "sqlalchemy"
|
|
26
|
+
Provides-Extra: agui
|
|
27
|
+
Requires-Dist: ag-ui-protocol==0.1.19; extra == "agui"
|
|
28
|
+
Provides-Extra: native
|
|
29
|
+
Requires-Dist: tinkerfin-native-stream==0.1.1; extra == "native"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# tinkerfin-messaging
|
|
33
|
+
|
|
34
|
+
`tinkerfin-messaging` persists and replays asynchronous object streams. It supports
|
|
35
|
+
reconnection, shared producer ownership, remote cancellation, and recovery from saved
|
|
36
|
+
source positions. Storage and message formats are independently replaceable.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install tinkerfin-messaging
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Install the integrations you use:
|
|
45
|
+
|
|
46
|
+
| Extra | Capability |
|
|
47
|
+
| --- | --- |
|
|
48
|
+
| `[agui]` | AG-UI encoding, replay and SSE |
|
|
49
|
+
| `[native]` | TinkerFin Native encoding, replay and SSE |
|
|
50
|
+
| `[sqlalchemy]` | SQLite, MySQL or PostgreSQL storage; install an async driver separately |
|
|
51
|
+
| `[redis]` | Shared Redis storage |
|
|
52
|
+
|
|
53
|
+
## Quick Start
|
|
54
|
+
|
|
55
|
+
This example streams a Runtime's output as durable SSE. Install the AG-UI and
|
|
56
|
+
OpenAI integrations, set `OPENAI_API_KEY`, and choose a model available to your account:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install "tinkerfin[agui]" "tinkerfin-messaging[agui]" langchain-openai
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import asyncio
|
|
64
|
+
from contextlib import aclosing
|
|
65
|
+
|
|
66
|
+
from tinkerfin import TinkerFin
|
|
67
|
+
from tinkerfin_messaging import Messaging
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
async def main() -> None:
|
|
71
|
+
runtime = TinkerFin().with_namespace("customer-1").build(model="openai:gpt-5.4")
|
|
72
|
+
source = runtime.open_agui_run(
|
|
73
|
+
thread_id="thread-1",
|
|
74
|
+
run_id="run-1",
|
|
75
|
+
messages=[{"id": "message-1", "role": "user", "content": "Hello"}],
|
|
76
|
+
)
|
|
77
|
+
async with Messaging() as messaging:
|
|
78
|
+
channel = messaging.channel(name="agent-events")
|
|
79
|
+
body = await channel.open_sse(source, after=0)
|
|
80
|
+
async with aclosing(body):
|
|
81
|
+
async for frame in body:
|
|
82
|
+
print(frame.decode("utf-8"), end="")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
asyncio.run(main())
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Runtime supplies identity and codec. Messaging opens the Agent or Sandbox only after
|
|
89
|
+
selecting this lazy, single-use source as producer. Another request can attach to the
|
|
90
|
+
same run without repeating that work. Pass object streams directly; Messaging creates
|
|
91
|
+
the durable SSE bytes. Your application supplies authentication and the HTTP response.
|
|
92
|
+
|
|
93
|
+
Close the returned body on early exit or failed HTTP setup. Closing a subscription
|
|
94
|
+
only detaches its reader. The producer remains owned by Messaging until it settles
|
|
95
|
+
or Messaging closes; request cancellation explicitly through the channel.
|
|
96
|
+
|
|
97
|
+
## Replay and command identity
|
|
98
|
+
|
|
99
|
+
A channel is a named stream family with one stable codec. A complete `RunIdentity`
|
|
100
|
+
contains the application's namespace, thread ID, and run ID. Reuse it to retry or
|
|
101
|
+
attach to the same run; use a new run ID for new input. Hosts authorize identities.
|
|
102
|
+
|
|
103
|
+
An optional lowercase SHA-256 `request_digest` binds complete command content while
|
|
104
|
+
the run record is retained. A changed binding, including a bound/unbound pair, raises
|
|
105
|
+
`RunRequestConflict`. Hosts calculate their own digest; use
|
|
106
|
+
[Gateway](https://github.com/tinkerfin-ai/tinkerfin-harness/tree/main/packages/tinkerfin-gateway)
|
|
107
|
+
for Runtime commands with automatic content binding. External side effects still
|
|
108
|
+
require application-level idempotency.
|
|
109
|
+
|
|
110
|
+
`after=None` starts at the tail observed during preparation, `after=0` replays all
|
|
111
|
+
retained messages, and `after=N` returns positions greater than `N`. Negative cursors
|
|
112
|
+
and cursors beyond the current tail raise `InvalidCursor`. Use `channel.read()` for
|
|
113
|
+
a finite page or `channel.follow()` to replay and wait for a selected run to finish.
|
|
114
|
+
|
|
115
|
+
## Storage and resource ownership
|
|
116
|
+
|
|
117
|
+
| Backend | Scope |
|
|
118
|
+
| --- | --- |
|
|
119
|
+
| `MemoryBackend` | One process; the default |
|
|
120
|
+
| `SqlAlchemyBackend(engine)` | Shared SQLite, MySQL or PostgreSQL database |
|
|
121
|
+
| `RedisBackend(client)` | Shared Redis storage under a configurable `key_prefix` |
|
|
122
|
+
|
|
123
|
+
Pass the backend to `Messaging(backend=...)`. SQL tables are prepared automatically.
|
|
124
|
+
For SQLite, install `"tinkerfin-messaging[sqlalchemy]" aiosqlite`; PostgreSQL uses
|
|
125
|
+
`asyncpg` and MySQL uses `asyncmy`. The application owns its `AsyncEngine` or Redis
|
|
126
|
+
client and closes it after Messaging. Configure connection and statement timeouts
|
|
127
|
+
on the Engine. Workers sharing SQL storage must use equal backend settings.
|
|
128
|
+
Unknown commit outcomes are reported without replaying the operation.
|
|
129
|
+
|
|
130
|
+
In-memory SQLite requires `AsyncAdaptedQueuePool` with `pool_size=1, max_overflow=0`.
|
|
131
|
+
Redis clients must return bytes (`decode_responses=False`). Custom storage, codecs,
|
|
132
|
+
and recoverable sources are covered in the storage and recovery guides below.
|
|
133
|
+
|
|
134
|
+
## Capacity, retention, and shutdown
|
|
135
|
+
|
|
136
|
+
Storage is bounded by `MessagingLimits`. Limits count logical payload and control
|
|
137
|
+
records, not process memory. `MessagingQuotaExceeded` identifies an exhausted
|
|
138
|
+
resource; cancellation, settlement, and deletion remain available.
|
|
139
|
+
|
|
140
|
+
Retention is disabled by default. `MessagingRetentionPolicy.expire_after(seconds)`
|
|
141
|
+
sets the replay window after a thread becomes terminal. A new run before expiry
|
|
142
|
+
continues that history. Active or unexpired history is not evicted to admit new data.
|
|
143
|
+
An expired generation raises `StreamExpired`; starting with `after=0` can create its
|
|
144
|
+
replacement. Explicit deletion requires no live producer and causes old handles to
|
|
145
|
+
raise `StreamDeleted`. Replacement generations restart sequence numbering at one.
|
|
146
|
+
|
|
147
|
+
`Messaging(settlement_timeout=...)` limits a caller's wait for shutdown. A timeout
|
|
148
|
+
does not release ownership of accepted work: await `aclose()` again before closing
|
|
149
|
+
borrowed resources. Async delivery callbacks must bound their I/O. Callback failure
|
|
150
|
+
cannot undo an already committed message; replay does not repeat commit callbacks.
|
|
151
|
+
|
|
152
|
+
## Documentation
|
|
153
|
+
|
|
154
|
+
- [Messaging basics](https://github.com/tinkerfin-ai/tinkerfin-harness/blob/main/docs/en/messaging/index.md)
|
|
155
|
+
- [Delivery and replay](https://github.com/tinkerfin-ai/tinkerfin-harness/blob/main/docs/en/messaging/delivery-and-replay.md)
|
|
156
|
+
- [Cancellation and recovery](https://github.com/tinkerfin-ai/tinkerfin-harness/blob/main/docs/en/messaging/cancellation-and-recovery.md)
|
|
157
|
+
- [Storage and codecs](https://github.com/tinkerfin-ai/tinkerfin-harness/blob/main/docs/en/messaging/backends-and-codecs.md)
|
|
158
|
+
- [API reference](https://github.com/tinkerfin-ai/tinkerfin-harness/blob/main/docs/en/messaging/api-reference.md)
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
[Apache License 2.0](https://github.com/tinkerfin-ai/tinkerfin-harness/blob/main/LICENSE)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# tinkerfin-messaging
|
|
2
|
+
|
|
3
|
+
`tinkerfin-messaging` persists and replays asynchronous object streams. It supports
|
|
4
|
+
reconnection, shared producer ownership, remote cancellation, and recovery from saved
|
|
5
|
+
source positions. Storage and message formats are independently replaceable.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install tinkerfin-messaging
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Install the integrations you use:
|
|
14
|
+
|
|
15
|
+
| Extra | Capability |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
| `[agui]` | AG-UI encoding, replay and SSE |
|
|
18
|
+
| `[native]` | TinkerFin Native encoding, replay and SSE |
|
|
19
|
+
| `[sqlalchemy]` | SQLite, MySQL or PostgreSQL storage; install an async driver separately |
|
|
20
|
+
| `[redis]` | Shared Redis storage |
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
This example streams a Runtime's output as durable SSE. Install the AG-UI and
|
|
25
|
+
OpenAI integrations, set `OPENAI_API_KEY`, and choose a model available to your account:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install "tinkerfin[agui]" "tinkerfin-messaging[agui]" langchain-openai
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import asyncio
|
|
33
|
+
from contextlib import aclosing
|
|
34
|
+
|
|
35
|
+
from tinkerfin import TinkerFin
|
|
36
|
+
from tinkerfin_messaging import Messaging
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
async def main() -> None:
|
|
40
|
+
runtime = TinkerFin().with_namespace("customer-1").build(model="openai:gpt-5.4")
|
|
41
|
+
source = runtime.open_agui_run(
|
|
42
|
+
thread_id="thread-1",
|
|
43
|
+
run_id="run-1",
|
|
44
|
+
messages=[{"id": "message-1", "role": "user", "content": "Hello"}],
|
|
45
|
+
)
|
|
46
|
+
async with Messaging() as messaging:
|
|
47
|
+
channel = messaging.channel(name="agent-events")
|
|
48
|
+
body = await channel.open_sse(source, after=0)
|
|
49
|
+
async with aclosing(body):
|
|
50
|
+
async for frame in body:
|
|
51
|
+
print(frame.decode("utf-8"), end="")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
asyncio.run(main())
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Runtime supplies identity and codec. Messaging opens the Agent or Sandbox only after
|
|
58
|
+
selecting this lazy, single-use source as producer. Another request can attach to the
|
|
59
|
+
same run without repeating that work. Pass object streams directly; Messaging creates
|
|
60
|
+
the durable SSE bytes. Your application supplies authentication and the HTTP response.
|
|
61
|
+
|
|
62
|
+
Close the returned body on early exit or failed HTTP setup. Closing a subscription
|
|
63
|
+
only detaches its reader. The producer remains owned by Messaging until it settles
|
|
64
|
+
or Messaging closes; request cancellation explicitly through the channel.
|
|
65
|
+
|
|
66
|
+
## Replay and command identity
|
|
67
|
+
|
|
68
|
+
A channel is a named stream family with one stable codec. A complete `RunIdentity`
|
|
69
|
+
contains the application's namespace, thread ID, and run ID. Reuse it to retry or
|
|
70
|
+
attach to the same run; use a new run ID for new input. Hosts authorize identities.
|
|
71
|
+
|
|
72
|
+
An optional lowercase SHA-256 `request_digest` binds complete command content while
|
|
73
|
+
the run record is retained. A changed binding, including a bound/unbound pair, raises
|
|
74
|
+
`RunRequestConflict`. Hosts calculate their own digest; use
|
|
75
|
+
[Gateway](https://github.com/tinkerfin-ai/tinkerfin-harness/tree/main/packages/tinkerfin-gateway)
|
|
76
|
+
for Runtime commands with automatic content binding. External side effects still
|
|
77
|
+
require application-level idempotency.
|
|
78
|
+
|
|
79
|
+
`after=None` starts at the tail observed during preparation, `after=0` replays all
|
|
80
|
+
retained messages, and `after=N` returns positions greater than `N`. Negative cursors
|
|
81
|
+
and cursors beyond the current tail raise `InvalidCursor`. Use `channel.read()` for
|
|
82
|
+
a finite page or `channel.follow()` to replay and wait for a selected run to finish.
|
|
83
|
+
|
|
84
|
+
## Storage and resource ownership
|
|
85
|
+
|
|
86
|
+
| Backend | Scope |
|
|
87
|
+
| --- | --- |
|
|
88
|
+
| `MemoryBackend` | One process; the default |
|
|
89
|
+
| `SqlAlchemyBackend(engine)` | Shared SQLite, MySQL or PostgreSQL database |
|
|
90
|
+
| `RedisBackend(client)` | Shared Redis storage under a configurable `key_prefix` |
|
|
91
|
+
|
|
92
|
+
Pass the backend to `Messaging(backend=...)`. SQL tables are prepared automatically.
|
|
93
|
+
For SQLite, install `"tinkerfin-messaging[sqlalchemy]" aiosqlite`; PostgreSQL uses
|
|
94
|
+
`asyncpg` and MySQL uses `asyncmy`. The application owns its `AsyncEngine` or Redis
|
|
95
|
+
client and closes it after Messaging. Configure connection and statement timeouts
|
|
96
|
+
on the Engine. Workers sharing SQL storage must use equal backend settings.
|
|
97
|
+
Unknown commit outcomes are reported without replaying the operation.
|
|
98
|
+
|
|
99
|
+
In-memory SQLite requires `AsyncAdaptedQueuePool` with `pool_size=1, max_overflow=0`.
|
|
100
|
+
Redis clients must return bytes (`decode_responses=False`). Custom storage, codecs,
|
|
101
|
+
and recoverable sources are covered in the storage and recovery guides below.
|
|
102
|
+
|
|
103
|
+
## Capacity, retention, and shutdown
|
|
104
|
+
|
|
105
|
+
Storage is bounded by `MessagingLimits`. Limits count logical payload and control
|
|
106
|
+
records, not process memory. `MessagingQuotaExceeded` identifies an exhausted
|
|
107
|
+
resource; cancellation, settlement, and deletion remain available.
|
|
108
|
+
|
|
109
|
+
Retention is disabled by default. `MessagingRetentionPolicy.expire_after(seconds)`
|
|
110
|
+
sets the replay window after a thread becomes terminal. A new run before expiry
|
|
111
|
+
continues that history. Active or unexpired history is not evicted to admit new data.
|
|
112
|
+
An expired generation raises `StreamExpired`; starting with `after=0` can create its
|
|
113
|
+
replacement. Explicit deletion requires no live producer and causes old handles to
|
|
114
|
+
raise `StreamDeleted`. Replacement generations restart sequence numbering at one.
|
|
115
|
+
|
|
116
|
+
`Messaging(settlement_timeout=...)` limits a caller's wait for shutdown. A timeout
|
|
117
|
+
does not release ownership of accepted work: await `aclose()` again before closing
|
|
118
|
+
borrowed resources. Async delivery callbacks must bound their I/O. Callback failure
|
|
119
|
+
cannot undo an already committed message; replay does not repeat commit callbacks.
|
|
120
|
+
|
|
121
|
+
## Documentation
|
|
122
|
+
|
|
123
|
+
- [Messaging basics](https://github.com/tinkerfin-ai/tinkerfin-harness/blob/main/docs/en/messaging/index.md)
|
|
124
|
+
- [Delivery and replay](https://github.com/tinkerfin-ai/tinkerfin-harness/blob/main/docs/en/messaging/delivery-and-replay.md)
|
|
125
|
+
- [Cancellation and recovery](https://github.com/tinkerfin-ai/tinkerfin-harness/blob/main/docs/en/messaging/cancellation-and-recovery.md)
|
|
126
|
+
- [Storage and codecs](https://github.com/tinkerfin-ai/tinkerfin-harness/blob/main/docs/en/messaging/backends-and-codecs.md)
|
|
127
|
+
- [API reference](https://github.com/tinkerfin-ai/tinkerfin-harness/blob/main/docs/en/messaging/api-reference.md)
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
[Apache License 2.0](https://github.com/tinkerfin-ai/tinkerfin-harness/blob/main/LICENSE)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tinkerfin-messaging"
|
|
3
|
+
version = "0.1.1"
|
|
4
|
+
description = "Replayable messaging for TinkerFin Native and AG-UI streams."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 3 - Alpha",
|
|
11
|
+
"Programming Language :: Python :: 3",
|
|
12
|
+
"Programming Language :: Python :: 3.11",
|
|
13
|
+
"Programming Language :: Python :: 3.12",
|
|
14
|
+
"Programming Language :: Python :: 3.13",
|
|
15
|
+
"Programming Language :: Python :: 3.14",
|
|
16
|
+
"Typing :: Typed",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
dependencies = [
|
|
20
|
+
"pydantic>=2,<3",
|
|
21
|
+
"tinkerfin-contracts==0.1.1",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.optional-dependencies]
|
|
25
|
+
redis = ["redis>=6,<9"]
|
|
26
|
+
sqlalchemy = ["sqlalchemy[asyncio]>=2.0.52,<3", "tinkerfin-sqlalchemy==0.1.1"]
|
|
27
|
+
agui = ["ag-ui-protocol==0.1.19"]
|
|
28
|
+
native = ["tinkerfin-native-stream==0.1.1"]
|
|
29
|
+
|
|
30
|
+
[tool.uv.sources]
|
|
31
|
+
tinkerfin-contracts = { workspace = true }
|
|
32
|
+
tinkerfin-native-stream = { workspace = true }
|
|
33
|
+
tinkerfin-sqlalchemy = { workspace = true }
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/tinkerfin-ai/tinkerfin-harness"
|
|
37
|
+
Repository = "https://github.com/tinkerfin-ai/tinkerfin-harness"
|
|
38
|
+
Issues = "https://github.com/tinkerfin-ai/tinkerfin-harness/issues"
|
|
39
|
+
|
|
40
|
+
[build-system]
|
|
41
|
+
requires = ["setuptools>=77"]
|
|
42
|
+
build-backend = "setuptools.build_meta"
|
|
43
|
+
|
|
44
|
+
[tool.setuptools.packages.find]
|
|
45
|
+
where = ["src"]
|
|
46
|
+
|
|
47
|
+
[tool.setuptools.package-data]
|
|
48
|
+
tinkerfin_messaging = ["py.typed"]
|