fast-chat-server 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 (152) hide show
  1. fast_chat_server-0.1.0/.gitignore +16 -0
  2. fast_chat_server-0.1.0/LICENSE +202 -0
  3. fast_chat_server-0.1.0/PKG-INFO +400 -0
  4. fast_chat_server-0.1.0/README.md +337 -0
  5. fast_chat_server-0.1.0/docs/PLAN.md +622 -0
  6. fast_chat_server-0.1.0/docs/README.md +35 -0
  7. fast_chat_server-0.1.0/docs/ROADMAP.md +264 -0
  8. fast_chat_server-0.1.0/docs/admin.md +411 -0
  9. fast_chat_server-0.1.0/docs/agents.md +484 -0
  10. fast_chat_server-0.1.0/docs/architecture.md +177 -0
  11. fast_chat_server-0.1.0/docs/authentication.md +393 -0
  12. fast_chat_server-0.1.0/docs/bus.md +208 -0
  13. fast_chat_server-0.1.0/docs/client-api.md +470 -0
  14. fast_chat_server-0.1.0/docs/configuration.md +361 -0
  15. fast_chat_server-0.1.0/docs/core.md +321 -0
  16. fast_chat_server-0.1.0/docs/events-and-state.md +386 -0
  17. fast_chat_server-0.1.0/docs/federation.md +331 -0
  18. fast_chat_server-0.1.0/docs/frontend-guide.md +208 -0
  19. fast_chat_server-0.1.0/docs/media.md +140 -0
  20. fast_chat_server-0.1.0/docs/observability.md +342 -0
  21. fast_chat_server-0.1.0/docs/quickstart.md +192 -0
  22. fast_chat_server-0.1.0/docs/releasing.md +93 -0
  23. fast_chat_server-0.1.0/docs/storage.md +335 -0
  24. fast_chat_server-0.1.0/docs/testing.md +203 -0
  25. fast_chat_server-0.1.0/pyproject.toml +139 -0
  26. fast_chat_server-0.1.0/src/fast_chat_server/__init__.py +26 -0
  27. fast_chat_server-0.1.0/src/fast_chat_server/agents/__init__.py +23 -0
  28. fast_chat_server-0.1.0/src/fast_chat_server/agents/agent.py +145 -0
  29. fast_chat_server-0.1.0/src/fast_chat_server/agents/api.py +31 -0
  30. fast_chat_server-0.1.0/src/fast_chat_server/agents/context.py +105 -0
  31. fast_chat_server-0.1.0/src/fast_chat_server/agents/history.py +53 -0
  32. fast_chat_server-0.1.0/src/fast_chat_server/agents/runtime.py +734 -0
  33. fast_chat_server-0.1.0/src/fast_chat_server/agents/triggers.py +120 -0
  34. fast_chat_server-0.1.0/src/fast_chat_server/api/__init__.py +0 -0
  35. fast_chat_server-0.1.0/src/fast_chat_server/api/admin.py +152 -0
  36. fast_chat_server-0.1.0/src/fast_chat_server/api/client/__init__.py +0 -0
  37. fast_chat_server-0.1.0/src/fast_chat_server/api/client/auth.py +157 -0
  38. fast_chat_server-0.1.0/src/fast_chat_server/api/client/misc.py +231 -0
  39. fast_chat_server-0.1.0/src/fast_chat_server/api/client/rooms.py +457 -0
  40. fast_chat_server-0.1.0/src/fast_chat_server/api/client/spaces.py +31 -0
  41. fast_chat_server-0.1.0/src/fast_chat_server/api/client/sync.py +75 -0
  42. fast_chat_server-0.1.0/src/fast_chat_server/api/client/versions.py +14 -0
  43. fast_chat_server-0.1.0/src/fast_chat_server/api/deps.py +83 -0
  44. fast_chat_server-0.1.0/src/fast_chat_server/api/fcs.py +33 -0
  45. fast_chat_server-0.1.0/src/fast_chat_server/api/federation/__init__.py +0 -0
  46. fast_chat_server-0.1.0/src/fast_chat_server/api/federation/server.py +392 -0
  47. fast_chat_server-0.1.0/src/fast_chat_server/api/federation/version.py +14 -0
  48. fast_chat_server-0.1.0/src/fast_chat_server/api/keys.py +16 -0
  49. fast_chat_server-0.1.0/src/fast_chat_server/api/media.py +106 -0
  50. fast_chat_server-0.1.0/src/fast_chat_server/api/metrics.py +41 -0
  51. fast_chat_server-0.1.0/src/fast_chat_server/api/well_known.py +21 -0
  52. fast_chat_server-0.1.0/src/fast_chat_server/app.py +464 -0
  53. fast_chat_server-0.1.0/src/fast_chat_server/bus/__init__.py +13 -0
  54. fast_chat_server-0.1.0/src/fast_chat_server/bus/base.py +43 -0
  55. fast_chat_server-0.1.0/src/fast_chat_server/bus/factory.py +30 -0
  56. fast_chat_server-0.1.0/src/fast_chat_server/bus/memory.py +74 -0
  57. fast_chat_server-0.1.0/src/fast_chat_server/bus/redis.py +73 -0
  58. fast_chat_server-0.1.0/src/fast_chat_server/cli.py +142 -0
  59. fast_chat_server-0.1.0/src/fast_chat_server/core/__init__.py +1 -0
  60. fast_chat_server-0.1.0/src/fast_chat_server/core/auth_rules.py +374 -0
  61. fast_chat_server-0.1.0/src/fast_chat_server/core/canonical_json.py +58 -0
  62. fast_chat_server-0.1.0/src/fast_chat_server/core/encoding.py +25 -0
  63. fast_chat_server-0.1.0/src/fast_chat_server/core/hashing.py +80 -0
  64. fast_chat_server-0.1.0/src/fast_chat_server/core/ids.py +147 -0
  65. fast_chat_server-0.1.0/src/fast_chat_server/core/redaction.py +102 -0
  66. fast_chat_server-0.1.0/src/fast_chat_server/core/redirects.py +70 -0
  67. fast_chat_server-0.1.0/src/fast_chat_server/core/room_versions.py +98 -0
  68. fast_chat_server-0.1.0/src/fast_chat_server/core/signing.py +149 -0
  69. fast_chat_server-0.1.0/src/fast_chat_server/core/state_res.py +217 -0
  70. fast_chat_server-0.1.0/src/fast_chat_server/errors.py +102 -0
  71. fast_chat_server-0.1.0/src/fast_chat_server/federation/__init__.py +1 -0
  72. fast_chat_server-0.1.0/src/fast_chat_server/federation/auth.py +82 -0
  73. fast_chat_server-0.1.0/src/fast_chat_server/federation/backfill.py +318 -0
  74. fast_chat_server-0.1.0/src/fast_chat_server/federation/client.py +173 -0
  75. fast_chat_server-0.1.0/src/fast_chat_server/federation/inbound.py +477 -0
  76. fast_chat_server-0.1.0/src/fast_chat_server/federation/keyring.py +205 -0
  77. fast_chat_server-0.1.0/src/fast_chat_server/federation/membership.py +450 -0
  78. fast_chat_server-0.1.0/src/fast_chat_server/federation/outbound.py +329 -0
  79. fast_chat_server-0.1.0/src/fast_chat_server/federation/service.py +37 -0
  80. fast_chat_server-0.1.0/src/fast_chat_server/observability.py +398 -0
  81. fast_chat_server-0.1.0/src/fast_chat_server/py.typed +0 -0
  82. fast_chat_server-0.1.0/src/fast_chat_server/services/__init__.py +1 -0
  83. fast_chat_server-0.1.0/src/fast_chat_server/services/admin.py +559 -0
  84. fast_chat_server-0.1.0/src/fast_chat_server/services/auth.py +405 -0
  85. fast_chat_server-0.1.0/src/fast_chat_server/services/ephemeral.py +168 -0
  86. fast_chat_server-0.1.0/src/fast_chat_server/services/events.py +570 -0
  87. fast_chat_server-0.1.0/src/fast_chat_server/services/media.py +128 -0
  88. fast_chat_server-0.1.0/src/fast_chat_server/services/notifier.py +90 -0
  89. fast_chat_server-0.1.0/src/fast_chat_server/services/rooms.py +551 -0
  90. fast_chat_server-0.1.0/src/fast_chat_server/services/serialize.py +111 -0
  91. fast_chat_server-0.1.0/src/fast_chat_server/services/spaces.py +208 -0
  92. fast_chat_server-0.1.0/src/fast_chat_server/services/sso.py +212 -0
  93. fast_chat_server-0.1.0/src/fast_chat_server/services/state.py +168 -0
  94. fast_chat_server-0.1.0/src/fast_chat_server/services/sync.py +596 -0
  95. fast_chat_server-0.1.0/src/fast_chat_server/services/util.py +38 -0
  96. fast_chat_server-0.1.0/src/fast_chat_server/settings.py +204 -0
  97. fast_chat_server-0.1.0/src/fast_chat_server/storage/__init__.py +3 -0
  98. fast_chat_server-0.1.0/src/fast_chat_server/storage/database.py +94 -0
  99. fast_chat_server-0.1.0/src/fast_chat_server/storage/migrate.py +52 -0
  100. fast_chat_server-0.1.0/src/fast_chat_server/storage/migrations/__init__.py +0 -0
  101. fast_chat_server-0.1.0/src/fast_chat_server/storage/migrations/env.py +48 -0
  102. fast_chat_server-0.1.0/src/fast_chat_server/storage/migrations/script.py.mako +25 -0
  103. fast_chat_server-0.1.0/src/fast_chat_server/storage/migrations/versions/0001_initial_schema.py +269 -0
  104. fast_chat_server-0.1.0/src/fast_chat_server/storage/migrations/versions/0002_phase_1_tables.py +132 -0
  105. fast_chat_server-0.1.0/src/fast_chat_server/storage/migrations/versions/0003_agent_runs.py +78 -0
  106. fast_chat_server-0.1.0/src/fast_chat_server/storage/migrations/versions/0004_federation_and_state_groups.py +84 -0
  107. fast_chat_server-0.1.0/src/fast_chat_server/storage/migrations/versions/0005_admin_api.py +59 -0
  108. fast_chat_server-0.1.0/src/fast_chat_server/storage/migrations/versions/0006_agent_run_active_time.py +28 -0
  109. fast_chat_server-0.1.0/src/fast_chat_server/storage/migrations/versions/0007_forgotten_rooms.py +31 -0
  110. fast_chat_server-0.1.0/src/fast_chat_server/storage/models.py +443 -0
  111. fast_chat_server-0.1.0/src/fast_chat_server/storage/streams.py +44 -0
  112. fast_chat_server-0.1.0/src/fast_chat_server/testing/__init__.py +1 -0
  113. fast_chat_server-0.1.0/src/fast_chat_server/testing/harness.py +303 -0
  114. fast_chat_server-0.1.0/src/fast_chat_server/testing/mock_oidc.py +159 -0
  115. fast_chat_server-0.1.0/tests/__init__.py +0 -0
  116. fast_chat_server-0.1.0/tests/conftest.py +56 -0
  117. fast_chat_server-0.1.0/tests/e2e/__init__.py +0 -0
  118. fast_chat_server-0.1.0/tests/e2e/js/.gitignore +1 -0
  119. fast_chat_server-0.1.0/tests/e2e/js/e2e.mjs +185 -0
  120. fast_chat_server-0.1.0/tests/e2e/js/package-lock.json +180 -0
  121. fast_chat_server-0.1.0/tests/e2e/js/package.json +12 -0
  122. fast_chat_server-0.1.0/tests/e2e/test_matrix_js_sdk.py +108 -0
  123. fast_chat_server-0.1.0/tests/integration/__init__.py +0 -0
  124. fast_chat_server-0.1.0/tests/integration/conftest.py +42 -0
  125. fast_chat_server-0.1.0/tests/integration/test_admin.py +251 -0
  126. fast_chat_server-0.1.0/tests/integration/test_agents.py +316 -0
  127. fast_chat_server-0.1.0/tests/integration/test_agents_fixes.py +339 -0
  128. fast_chat_server-0.1.0/tests/integration/test_api_ops_fixes.py +223 -0
  129. fast_chat_server-0.1.0/tests/integration/test_app.py +209 -0
  130. fast_chat_server-0.1.0/tests/integration/test_dev_login.py +95 -0
  131. fast_chat_server-0.1.0/tests/integration/test_federation.py +229 -0
  132. fast_chat_server-0.1.0/tests/integration/test_federation_backfill.py +144 -0
  133. fast_chat_server-0.1.0/tests/integration/test_federation_fixes.py +302 -0
  134. fast_chat_server-0.1.0/tests/integration/test_login.py +109 -0
  135. fast_chat_server-0.1.0/tests/integration/test_observability.py +238 -0
  136. fast_chat_server-0.1.0/tests/integration/test_openapi.py +52 -0
  137. fast_chat_server-0.1.0/tests/integration/test_rooms.py +356 -0
  138. fast_chat_server-0.1.0/tests/integration/test_security.py +356 -0
  139. fast_chat_server-0.1.0/tests/integration/test_spaces.py +158 -0
  140. fast_chat_server-0.1.0/tests/unit/__init__.py +0 -0
  141. fast_chat_server-0.1.0/tests/unit/core/__init__.py +0 -0
  142. fast_chat_server-0.1.0/tests/unit/core/test_auth_rules.py +218 -0
  143. fast_chat_server-0.1.0/tests/unit/core/test_core_misc.py +268 -0
  144. fast_chat_server-0.1.0/tests/unit/core/test_old_room_versions.py +84 -0
  145. fast_chat_server-0.1.0/tests/unit/core/test_redaction.py +176 -0
  146. fast_chat_server-0.1.0/tests/unit/core/test_redirects.py +64 -0
  147. fast_chat_server-0.1.0/tests/unit/core/test_signing_spec_vectors.py +144 -0
  148. fast_chat_server-0.1.0/tests/unit/core/test_state_res.py +220 -0
  149. fast_chat_server-0.1.0/tests/unit/storage/__init__.py +0 -0
  150. fast_chat_server-0.1.0/tests/unit/storage/test_storage.py +90 -0
  151. fast_chat_server-0.1.0/tests/unit/test_bus.py +76 -0
  152. fast_chat_server-0.1.0/tests/unit/test_cli.py +44 -0
@@ -0,0 +1,16 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ dist/
8
+ build/
9
+ *.egg-info/
10
+ *.db
11
+ *.db-wal
12
+ *.db-shm
13
+ *.signing.key
14
+ .env
15
+ dump.rdb
16
+ *.log
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,400 @@
1
+ Metadata-Version: 2.5
2
+ Name: fast-chat-server
3
+ Version: 0.1.0
4
+ Summary: A Matrix homeserver packaged as a mountable FastAPI sub-application, with Pydantic AI agents.
5
+ Project-URL: Homepage, https://github.com/hanku4u/fast-chat-server
6
+ Project-URL: Documentation, https://github.com/hanku4u/fast-chat-server/tree/HEAD/docs
7
+ Project-URL: Source, https://github.com/hanku4u/fast-chat-server
8
+ Project-URL: Issues, https://github.com/hanku4u/fast-chat-server/issues
9
+ Project-URL: Changelog, https://github.com/hanku4u/fast-chat-server/releases
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: ai-agents,chat,fastapi,federation,homeserver,matrix
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Framework :: AsyncIO
15
+ Classifier: Framework :: FastAPI
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Communications :: Chat
24
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.11
27
+ Requires-Dist: aiosqlite>=0.20
28
+ Requires-Dist: alembic>=1.13
29
+ Requires-Dist: fastapi>=0.115
30
+ Requires-Dist: httpx>=0.27
31
+ Requires-Dist: joserfc>=1.0
32
+ Requires-Dist: pydantic-settings>=2.4
33
+ Requires-Dist: pydantic>=2.7
34
+ Requires-Dist: pynacl>=1.5
35
+ Requires-Dist: sqlalchemy[asyncio]>=2.0.30
36
+ Provides-Extra: agents
37
+ Requires-Dist: pydantic-ai-slim>=1.0; extra == 'agents'
38
+ Provides-Extra: all
39
+ Requires-Dist: asgi-lifespan>=2.1; extra == 'all'
40
+ Requires-Dist: asyncpg>=0.29; extra == 'all'
41
+ Requires-Dist: opentelemetry-api>=1.25; extra == 'all'
42
+ Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.25; extra == 'all'
43
+ Requires-Dist: opentelemetry-sdk>=1.25; extra == 'all'
44
+ Requires-Dist: prometheus-client>=0.20; extra == 'all'
45
+ Requires-Dist: pydantic-ai-slim>=1.0; extra == 'all'
46
+ Requires-Dist: redis>=5.0; extra == 'all'
47
+ Requires-Dist: uvicorn[standard]>=0.30; extra == 'all'
48
+ Provides-Extra: metrics
49
+ Requires-Dist: prometheus-client>=0.20; extra == 'metrics'
50
+ Provides-Extra: postgres
51
+ Requires-Dist: asyncpg>=0.29; extra == 'postgres'
52
+ Provides-Extra: redis
53
+ Requires-Dist: redis>=5.0; extra == 'redis'
54
+ Provides-Extra: server
55
+ Requires-Dist: uvicorn[standard]>=0.30; extra == 'server'
56
+ Provides-Extra: testing
57
+ Requires-Dist: asgi-lifespan>=2.1; extra == 'testing'
58
+ Provides-Extra: tracing
59
+ Requires-Dist: opentelemetry-api>=1.25; extra == 'tracing'
60
+ Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.25; extra == 'tracing'
61
+ Requires-Dist: opentelemetry-sdk>=1.25; extra == 'tracing'
62
+ Description-Content-Type: text/markdown
63
+
64
+ # fast-chat-server
65
+
66
+ A [Matrix](https://spec.matrix.org) homeserver packaged as a mountable FastAPI
67
+ sub-application. It's built for small deployments (departments inside a large
68
+ company): each department runs its own server, servers federate with each other,
69
+ and frontend teams build their own clients with `matrix-js-sdk`.
70
+
71
+ - **Storage:** SQLite (single process, zero ops) or Postgres (multiple workers).
72
+ - **Optional Redis or Dragonfly** for shared caches and cross-worker notifications.
73
+ - **Login:** GitLab SSO (OpenID Connect), limited to configured GitLab groups.
74
+ - **LLM agents** defined in Python on top of Pydantic AI. They appear in rooms as
75
+ ordinary users.
76
+
77
+ New here? Start with the [quick start](https://github.com/hanku4u/fast-chat-server/blob/v0.1.0/docs/quickstart.md). Developer
78
+ documentation, one page per part of the code, is in [`docs/`](https://github.com/hanku4u/fast-chat-server/blob/v0.1.0/docs/README.md). What is missing and planned next is in
79
+ [`docs/ROADMAP.md`](https://github.com/hanku4u/fast-chat-server/blob/v0.1.0/docs/ROADMAP.md); the original design and decisions log is
80
+ [`docs/PLAN.md`](https://github.com/hanku4u/fast-chat-server/blob/v0.1.0/docs/PLAN.md).
81
+
82
+ > **Status: prototype.** Servers work end to end with `matrix-js-sdk`: SSO login,
83
+ > rooms, messages, sync, media and agents. Department servers federate with each
84
+ > other: invites, joins, messages, state and typing cross servers, and conflicting
85
+ > changes are settled with state resolution v2. Frontend teams should start with
86
+ > [`docs/frontend-guide.md`](https://github.com/hanku4u/fast-chat-server/blob/v0.1.0/docs/frontend-guide.md) and the Vue example in
87
+ > [`examples/vue-client`](https://github.com/hanku4u/fast-chat-server/blob/v0.1.0/examples/vue-client).
88
+
89
+ ## Quick start
90
+
91
+ [`docs/quickstart.md`](https://github.com/hanku4u/fast-chat-server/blob/v0.1.0/docs/quickstart.md) gets you from nothing to chatting
92
+ with an agent in a few minutes, three ways: the Docker demo, the demo from a
93
+ checkout, or the server mounted in your own FastAPI app. The fastest:
94
+
95
+ ```bash
96
+ docker compose -f examples/demo/docker-compose.yml up --build
97
+ ```
98
+
99
+ This starts two department servers that federate with each other, each serving
100
+ the example web client with two scripted demo agents (no LLM key needed):
101
+ `eng.localhost` on http://localhost:8008 (sign in as alice, bob or admin) and
102
+ `sales.localhost` on http://localhost:8009 (carol). The mock GitLab has no
103
+ passwords. [`examples/demo`](https://github.com/hanku4u/fast-chat-server/blob/v0.1.0/examples/demo) has a tour, and steps to run one
104
+ server without Docker.
105
+
106
+ ## Mounting into an existing FastAPI app
107
+
108
+ ```python
109
+ from fastapi import FastAPI
110
+ from fast_chat_server import MatrixServer, Settings
111
+
112
+ app = FastAPI()
113
+
114
+ matrix = MatrixServer(
115
+ Settings(
116
+ server_name="eng.corp.example",
117
+ database_url="postgresql+asyncpg://fcs:secret@db/fcs",
118
+ signing_key_path="/secrets/signing.key", # created on first start if missing
119
+ redis_url="redis://dragonfly:6379/0", # optional
120
+ )
121
+ )
122
+ matrix.install(app, client_prefix="/chat")
123
+ ```
124
+
125
+ `install()` mounts these paths, ahead of the host's own routes:
126
+
127
+ | Path | Purpose |
128
+ |---|---|
129
+ | `/.well-known/matrix/*` | discovery for clients and servers |
130
+ | `/chat/_matrix/client/*` | Client-Server API (the prefix is up to you) |
131
+ | `/chat/_matrix/media/*` | legacy media paths: upload and config (download only with `media.allow_unauthenticated_download`); authenticated downloads use `/chat/_matrix/client/v1/media/*` |
132
+ | `/chat/_fcs/v1/*` | extensions: SSO callback, server info, agent catalogue |
133
+ | `/_matrix/key/*` | this server's signing keys |
134
+ | `/_matrix/federation/*` | Server-Server API |
135
+
136
+ Matrix requires the well-known, key and federation paths at the domain root, so
137
+ only the client API takes the prefix. The server starts and stops with the host
138
+ app's lifespan. Matrix routes have their own error handlers and CORS settings, so
139
+ the host app's middleware choices don't change the Matrix wire format.
140
+
141
+ ## Login with GitLab
142
+
143
+ ```python
144
+ Settings(
145
+ ...,
146
+ auth={
147
+ "gitlab": {
148
+ "issuer": "https://gitlab.corp.example",
149
+ "client_id": "...",
150
+ "client_secret_file": "/secrets/gitlab-client-secret",
151
+ "allowed_groups": ["eng"], # who may log in (subgroups included)
152
+ "admin_groups": ["eng/chat-admins"],
153
+ },
154
+ "sso_redirect_allowlist": ["https://chat.eng.corp.example/*"],
155
+ },
156
+ )
157
+ ```
158
+
159
+ Create the GitLab application with the scopes `openid profile email` and the
160
+ redirect URI `https://<host>/chat/_fcs/v1/sso/callback`. Clients use the standard
161
+ Matrix SSO flow (`m.login.sso`, then `m.login.token`). Membership in an allowed
162
+ group is read from the ID token's `groups_direct` claim.
163
+
164
+ ## LLM agents
165
+
166
+ Install `fast-chat-server[agents]`, then define agents next to your app:
167
+
168
+ ```python
169
+ from pydantic_ai import RunContext
170
+ from fast_chat_server.agents import AgentContext, MatrixAgent, on
171
+
172
+ helpdesk = MatrixAgent(
173
+ localpart="helpdesk", # becomes @helpdesk:eng.corp.example
174
+ display_name="Helpdesk",
175
+ model="anthropic:claude-sonnet-5-5", # any Pydantic AI model
176
+ instructions="You are the IT helpdesk for Engineering. Be brief.",
177
+ triggers=[on.mention(), on.direct_message(), on.command("!ticket")],
178
+ deps_factory=lambda ctx: TicketService(), # your own dependencies → ctx.deps.app
179
+ )
180
+
181
+
182
+ @helpdesk.tool
183
+ async def ticket_status(ctx: RunContext[AgentContext[TicketService]], ticket_id: int) -> str:
184
+ """Look up a ticket's status."""
185
+ return await ctx.deps.app.status(ticket_id, asked_by=ctx.deps.sender)
186
+
187
+
188
+ @helpdesk.tool(requires_approval=True) # someone with power level ≥ 50 must approve
189
+ async def close_ticket(ctx: RunContext[AgentContext[TicketService]], ticket_id: int) -> str:
190
+ """Close a ticket."""
191
+ return await ctx.deps.app.close(ticket_id)
192
+
193
+
194
+ matrix.agents.register(helpdesk) # before the app starts (before or after install())
195
+ ```
196
+
197
+ - Invite the agent to a room, or start a direct chat with it. It joins on its own.
198
+ - It answers when its trigger matches: a mention, any message in a direct chat, a
199
+ command prefix, every message (`on.message()`) or a custom event
200
+ (`on.event(type, predicate)`). In group rooms it replies in a thread.
201
+ - The model sees the room's (or thread's) recent messages as conversation history,
202
+ with each person's name in front of their message.
203
+ - `ctx.deps` is an `AgentContext`: `sender`, `event`, `room` (send messages, read
204
+ state and members), `run_id`, and `app`, your dependencies.
205
+ - Tools marked `requires_approval=True` pause the run. The agent posts a notice and
206
+ resumes when someone with enough power reacts ✅ (or ❌ to deny), or replies
207
+ "approve" or "deny". The requester may always deny. Pending approvals are stored
208
+ in the database, so they survive restarts.
209
+ - Every run is recorded in the `agent_runs` table, including token usage. Agent
210
+ messages carry an `fcs.agent` field (`run_id`, `status`, `model`) for frontends.
211
+ `GET /chat/_fcs/v1/agents` lists the agents with their triggers and tools.
212
+ - Test agents without an LLM using Pydantic AI's `TestModel` or `FunctionModel`
213
+ and `fast_chat_server.testing.harness.TestHomeserver(agents=[...])`, as in
214
+ `tests/integration/test_agents.py`.
215
+
216
+ ## Running standalone
217
+
218
+ ```bash
219
+ pip install 'fast-chat-server[server]'
220
+ export FCS_SERVER_NAME=eng.corp.example
221
+ export FCS_DATABASE_URL=sqlite+aiosqlite:///./fcs.db
222
+ export FCS_SIGNING_KEY_PATH=./signing.key
223
+ fcs run --host 0.0.0.0 --port 8008
224
+ ```
225
+
226
+ Extras add optional parts: `server` (uvicorn, for `fcs run`), `postgres`,
227
+ `redis`, `agents` (Pydantic AI), `metrics`, `tracing`, `testing` (the mock GitLab
228
+ and `TestHomeserver`), and `all`. For example
229
+ `pip install 'fast-chat-server[server,postgres,redis]'`.
230
+
231
+ Other commands: `fcs migrate` applies database migrations (they also run at
232
+ startup unless `FCS_AUTO_MIGRATE=false`), and `fcs gen-key` creates a signing key.
233
+
234
+ ## Configuration
235
+
236
+ All settings can be passed to `Settings(...)` or set as `FCS_*` environment
237
+ variables. Nested settings use `__`, for example `FCS_FEDERATION__MODE=open`.
238
+ See `src/fast_chat_server/settings.py` for the full list.
239
+
240
+ | Setting | Default | Notes |
241
+ |---|---|---|
242
+ | `server_name` | (required) | the domain in user IDs, e.g. `@alice:eng.corp.example` |
243
+ | `public_baseurl` | `https://<server_name><prefix>` | the client base URL in `.well-known` |
244
+ | `database_url` | `sqlite+aiosqlite:///./fcs.db` | or `postgresql+asyncpg://...` |
245
+ | `redis_url` | unset | Redis or Dragonfly. Without it, everything runs in-process |
246
+ | `signing_key_path` / `signing_key` | ephemeral key, with a warning | always set this in production |
247
+ | `federation.mode` | `allowlist` | `allowlist`, `open` or `disabled` |
248
+ | `federation.allowlist` | `[]` | other department servers |
249
+ | `federation.servers` | `{}` | static routes, server name → base URL (skips discovery) |
250
+ | `federation.public_host` | `<server_name>:443` | served as `m.server` in `/.well-known/matrix/server` |
251
+ | `cors.allow_origins` | `["*"]` | narrow this to your frontends' origins |
252
+ | `encryption` | `disabled` | no end-to-end encrypted rooms in v1 |
253
+ | `metrics.enabled` | `false` | Prometheus endpoint (needs the `metrics` extra) |
254
+ | `metrics.path` / `metrics.bearer_token` | `/_fcs/metrics` / unset | on the host app's root; set a token or keep it off the internet |
255
+ | `tracing.enabled` | `false` | OpenTelemetry spans (needs the `tracing` extra) |
256
+ | `tracing.exporter` | `global` | `global` (the host's provider), `otlp` or `console` |
257
+ | `tracing.agent_content` | `false` | put prompts and model replies on agent spans |
258
+
259
+ ## Federation between departments
260
+
261
+ Each department runs its own server. With `federation.mode="allowlist"` (the
262
+ default) a server only talks to the servers in `federation.allowlist`:
263
+
264
+ ```python
265
+ Settings(
266
+ server_name="eng.corp.example",
267
+ federation={
268
+ "allowlist": ["sales.corp.example", "hr.corp.example"],
269
+ # Optional: skip discovery for servers you know the address of.
270
+ "servers": {"sales.corp.example": "https://matrix.sales.corp.example"},
271
+ },
272
+ )
273
+ ```
274
+
275
+ Other servers are found through `federation.servers`, then
276
+ `https://<name>/.well-known/matrix/server`, then `https://<name>:8448`. Users
277
+ invite and join across servers with the normal client API (`#room:sales.corp.example`
278
+ aliases work too). Events to a server that is down are kept and delivered, in
279
+ order, once it is back, even across restarts.
280
+
281
+ `fast_chat_server.testing.harness.FederationNetwork` runs several servers in one
282
+ process for tests, including partitions between them (see
283
+ `tests/integration/test_federation.py`).
284
+
285
+ ## Metrics and tracing
286
+
287
+ Install `fast-chat-server[metrics,tracing]` (both are in `all`) and set
288
+ `FCS_METRICS__ENABLED=true` and/or `FCS_TRACING__ENABLED=true`.
289
+
290
+ **Prometheus** scrapes `GET /_fcs/metrics` (with `Authorization: Bearer <token>`
291
+ if `metrics.bearer_token` is set). Routes are labelled by template, never by
292
+ room or user ID. Main series:
293
+
294
+ | Metric | Labels |
295
+ |---|---|
296
+ | `fcs_info` | `server_name`, `version` (always 1) |
297
+ | `fcs_http_requests_total` | `api` (client, federation, media, admin...), `method`, `route`, `status` |
298
+ | `fcs_http_request_duration_seconds` | `api`, `method`, `route` |
299
+ | `fcs_http_requests_in_flight` | `api` (open `/sync` long-polls included) |
300
+ | `fcs_events_persisted_total` | `source` (local, federation, backfill), `type` |
301
+ | `fcs_federation_outgoing_requests_total` | `destination`, `endpoint`, `result` |
302
+ | `fcs_federation_outgoing_request_duration_seconds` | `destination`, `endpoint` |
303
+ | `fcs_federation_pdus_received_total` | `origin`, `result` (accepted, rejected) |
304
+ | `fcs_federation_pdus_sent_total`, `fcs_federation_edus_sent_total` | `destination` |
305
+ | `fcs_federation_destination_backing_off` | `destination` (1 while deliveries fail) |
306
+ | `fcs_agent_runs_total`, `fcs_agent_run_duration_seconds`, `fcs_agent_tokens_total` | `agent`, `status` / `kind` |
307
+ | `fcs_agent_approval_requests_total` | `agent` (runs that paused for a human's approval) |
308
+
309
+ With several worker processes, set `PROMETHEUS_MULTIPROC_DIR` to a shared,
310
+ empty directory: every worker then serves the totals of all of them.
311
+
312
+ See [`docs/observability.md`](https://github.com/hanku4u/fast-chat-server/blob/v0.1.0/docs/observability.md) for every series, scrape
313
+ config and alert examples.
314
+
315
+ **OpenTelemetry**: with `tracing.exporter=global` (the default) spans go to the
316
+ tracer provider the host app set up, so they join the host's own traces. Use
317
+ `otlp` to have the server send them itself (configured by the standard
318
+ `OTEL_EXPORTER_OTLP_*` variables), or call
319
+ `matrix.tracing.use_provider(provider)`. You get a span per request, per
320
+ outgoing federation request, per incoming PDU and per `/sync`, plus Pydantic
321
+ AI's spans for each agent run (model calls, tool calls). Trace context is sent
322
+ along with federation requests, so a message can be followed from one
323
+ department's server into the next. Prompts and replies stay out of spans unless
324
+ `tracing.agent_content` is on.
325
+
326
+ ## Server administration
327
+
328
+ Users in one of `auth.gitlab.admin_groups` (checked at each sign-in) can use the
329
+ admin API at `{prefix}/_fcs/admin/v1` with their normal access token. Every
330
+ change is recorded in an audit log.
331
+
332
+ | Endpoint | What it does |
333
+ | --- | --- |
334
+ | `GET /server` | Version, backends, counts of users, rooms, events, media, failing federation links |
335
+ | `GET /users?search=&deactivated=` | Local users (paged with `limit` and `from`) |
336
+ | `GET /users/{user_id}` | Devices, GitLab identity, rooms |
337
+ | `POST /users/{user_id}/deactivate` | Revoke all tokens, leave all rooms (`{"leave_rooms": false}` to keep them); signing in again is refused even if GitLab allows it |
338
+ | `POST /users/{user_id}/reactivate` | Allow signing in again |
339
+ | `POST /users/{user_id}/logout` | Revoke every token of the user |
340
+ | `GET /rooms?search=` | Rooms with name, alias, members and block status |
341
+ | `GET /rooms/{room_id}` | Members, aliases, full current state |
342
+ | `POST /rooms/{room_id}/shutdown` | Every local member leaves, aliases and directory entry are removed, and local users can no longer join or be invited (`{"reason": "..."}`) |
343
+ | `POST /rooms/{room_id}/unblock` | Lift the block (nobody is rejoined) |
344
+ | `GET /media?user_id=&quarantined=` | Uploaded media |
345
+ | `POST /media/{media_id}/quarantine`, `/unquarantine` | Hide or restore a file |
346
+ | `DELETE /media/{media_id}` | Delete the file |
347
+ | `GET /federation/destinations` | Per-server delivery status: failures, backoff, stream lag |
348
+ | `POST /federation/destinations/{server}/retry` | Retry a server now instead of waiting for the backoff |
349
+ | `GET /audit?target=` | Who changed what, newest first |
350
+
351
+ Admin status itself is managed in GitLab, not through this API. A shutdown
352
+ only affects this server's users: members on other servers stay in the room.
353
+
354
+ ## Known limitations of the prototype
355
+
356
+ The [roadmap](https://github.com/hanku4u/fast-chat-server/blob/v0.1.0/docs/ROADMAP.md) has the full list, with priorities.
357
+
358
+ - Federation: history from before you joined a room on another server is
359
+ fetched when you paginate back in `/messages`. Gaps in the middle of a
360
+ timeline (after a long partition) aren't filled, and backfilled events are
361
+ checked against their auth events only. No notary key servers, no SRV
362
+ lookups, no presence, to-device or device-list EDUs. Rooms of versions 1 and 2
363
+ can't be joined over federation.
364
+ - History visibility is always treated as `shared`. Presence is always offline.
365
+ Push rules are a stub. Thumbnails return the original image. No to-device
366
+ messages, lazy-loading of members, or end-to-end encryption.
367
+ - Typing notifications and agent jobs live in the process that handles them. With
368
+ several workers, typing is per worker, and a room's agent jobs are ordered per
369
+ worker only.
370
+ - GitLab group membership is checked at login, not when tokens are refreshed.
371
+ - `docker-compose.yml` has been run end to end (SSO login, rooms, messages) with
372
+ Redis standing in for Dragonfly; the Dragonfly image itself is untested.
373
+
374
+ ## Development
375
+
376
+ ```bash
377
+ uv sync --all-extras
378
+ uv run pytest # SQLite + in-memory bus
379
+ uv run ruff check src tests && uv run ruff format --check src tests && uv run mypy
380
+ ```
381
+
382
+ To also run every database and bus test against real services:
383
+
384
+ ```bash
385
+ export FCS_TEST_DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/fcs_test
386
+ export FCS_TEST_REDIS_URL=redis://localhost:6379/0 # Redis or Dragonfly
387
+ uv run pytest
388
+ ```
389
+
390
+ The Postgres test database is wiped before each test, so use a dedicated
391
+ database. CI runs the matrix {SQLite, Postgres} × {in-memory, Redis, Dragonfly}.
392
+
393
+ To create a migration after changing `storage/models.py`:
394
+
395
+ ```bash
396
+ FCS_DATABASE_URL=sqlite+aiosqlite:///./dev.db uv run alembic upgrade head
397
+ FCS_DATABASE_URL=sqlite+aiosqlite:///./dev.db uv run alembic revision --autogenerate -m "..."
398
+ ```
399
+
400
+ `tests/unit/storage` fails if the migrations and the models drift apart.