prismal-server 0.2.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.
- prismal_server-0.2.0/.gitignore +224 -0
- prismal_server-0.2.0/LICENSE +21 -0
- prismal_server-0.2.0/PKG-INFO +173 -0
- prismal_server-0.2.0/README.md +118 -0
- prismal_server-0.2.0/pyproject.toml +101 -0
- prismal_server-0.2.0/src/prismal_server/__init__.py +15 -0
- prismal_server-0.2.0/src/prismal_server/app.py +163 -0
- prismal_server-0.2.0/src/prismal_server/auth/__init__.py +125 -0
- prismal_server-0.2.0/src/prismal_server/auth/base.py +42 -0
- prismal_server-0.2.0/src/prismal_server/auth/bearer.py +45 -0
- prismal_server-0.2.0/src/prismal_server/auth/noauth.py +24 -0
- prismal_server-0.2.0/src/prismal_server/auth/oidc.py +49 -0
- prismal_server-0.2.0/src/prismal_server/config.py +106 -0
- prismal_server-0.2.0/src/prismal_server/deps.py +305 -0
- prismal_server-0.2.0/src/prismal_server/errors.py +148 -0
- prismal_server-0.2.0/src/prismal_server/fake/__init__.py +35 -0
- prismal_server-0.2.0/src/prismal_server/fake/graph.py +151 -0
- prismal_server-0.2.0/src/prismal_server/fake/middleware.py +30 -0
- prismal_server-0.2.0/src/prismal_server/metrics.py +33 -0
- prismal_server-0.2.0/src/prismal_server/openapi_examples.py +370 -0
- prismal_server-0.2.0/src/prismal_server/py.typed +0 -0
- prismal_server-0.2.0/src/prismal_server/routes/__init__.py +1 -0
- prismal_server-0.2.0/src/prismal_server/routes/a2a.py +249 -0
- prismal_server-0.2.0/src/prismal_server/routes/admin.py +221 -0
- prismal_server-0.2.0/src/prismal_server/routes/agui.py +81 -0
- prismal_server-0.2.0/src/prismal_server/routes/health.py +38 -0
- prismal_server-0.2.0/src/prismal_server/routes/threads.py +343 -0
- prismal_server-0.2.0/src/prismal_server/routes/usage.py +164 -0
- prismal_server-0.2.0/src/prismal_server/routes/ws.py +262 -0
- prismal_server-0.2.0/src/prismal_server/streaming.py +361 -0
- prismal_server-0.2.0/src/prismal_server/tenancy/__init__.py +7 -0
- prismal_server-0.2.0/src/prismal_server/tenancy/config_source.py +315 -0
- prismal_server-0.2.0/src/prismal_server/tenancy/secrets.py +132 -0
- prismal_server-0.2.0/src/prismal_server/usage/__init__.py +6 -0
- prismal_server-0.2.0/src/prismal_server/usage/aggregate.py +63 -0
- prismal_server-0.2.0/src/prismal_server/usage/models.py +120 -0
- prismal_server-0.2.0/src/prismal_server/usage/store.py +239 -0
- prismal_server-0.2.0/src/prismal_server/usage/summary.py +66 -0
|
@@ -0,0 +1,224 @@
|
|
|
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
|
+
# Redis
|
|
135
|
+
*.rdb
|
|
136
|
+
*.aof
|
|
137
|
+
*.pid
|
|
138
|
+
|
|
139
|
+
# RabbitMQ
|
|
140
|
+
mnesia/
|
|
141
|
+
rabbitmq/
|
|
142
|
+
rabbitmq-data/
|
|
143
|
+
|
|
144
|
+
# ActiveMQ
|
|
145
|
+
activemq-data/
|
|
146
|
+
|
|
147
|
+
# SageMath parsed files
|
|
148
|
+
*.sage.py
|
|
149
|
+
|
|
150
|
+
# Environments
|
|
151
|
+
.env
|
|
152
|
+
.envrc
|
|
153
|
+
.venv
|
|
154
|
+
env/
|
|
155
|
+
venv/
|
|
156
|
+
ENV/
|
|
157
|
+
env.bak/
|
|
158
|
+
venv.bak/
|
|
159
|
+
|
|
160
|
+
# Spyder project settings
|
|
161
|
+
.spyderproject
|
|
162
|
+
.spyproject
|
|
163
|
+
|
|
164
|
+
# Rope project settings
|
|
165
|
+
.ropeproject
|
|
166
|
+
|
|
167
|
+
# mkdocs documentation
|
|
168
|
+
/site
|
|
169
|
+
|
|
170
|
+
# mypy
|
|
171
|
+
.mypy_cache/
|
|
172
|
+
.dmypy.json
|
|
173
|
+
dmypy.json
|
|
174
|
+
|
|
175
|
+
# Pyre type checker
|
|
176
|
+
.pyre/
|
|
177
|
+
|
|
178
|
+
# pytype static type analyzer
|
|
179
|
+
.pytype/
|
|
180
|
+
|
|
181
|
+
# Cython debug symbols
|
|
182
|
+
cython_debug/
|
|
183
|
+
|
|
184
|
+
# PyCharm
|
|
185
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
186
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
188
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
189
|
+
# .idea/
|
|
190
|
+
|
|
191
|
+
# Abstra
|
|
192
|
+
# Abstra is an AI-powered process automation framework.
|
|
193
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
194
|
+
# Learn more at https://abstra.io/docs
|
|
195
|
+
.abstra/
|
|
196
|
+
|
|
197
|
+
# Visual Studio Code
|
|
198
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
199
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
200
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
201
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
202
|
+
# .vscode/
|
|
203
|
+
# Temporary file for partial code execution
|
|
204
|
+
tempCodeRunnerFile.py
|
|
205
|
+
|
|
206
|
+
# Ruff stuff:
|
|
207
|
+
.ruff_cache/
|
|
208
|
+
|
|
209
|
+
# PyPI configuration file
|
|
210
|
+
.pypirc
|
|
211
|
+
|
|
212
|
+
# Marimo
|
|
213
|
+
marimo/_static/
|
|
214
|
+
marimo/_lsp/
|
|
215
|
+
__marimo__/
|
|
216
|
+
|
|
217
|
+
# Streamlit
|
|
218
|
+
.streamlit/secrets.toml
|
|
219
|
+
|
|
220
|
+
# Ignore JetBrains IDE project files
|
|
221
|
+
.idea/
|
|
222
|
+
|
|
223
|
+
# Engine runtime artifacts (checkpointer db, etc.)
|
|
224
|
+
data/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 prismal-ai
|
|
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,173 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: prismal-server
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Reference host for the prismal agent engine — a thin FastAPI/ASGI process serving prismal over REST/SSE and inbound A2A.
|
|
5
|
+
Project-URL: Homepage, https://github.com/prismal-ai/prismal-server
|
|
6
|
+
Project-URL: Repository, https://github.com/prismal-ai/prismal-server
|
|
7
|
+
Project-URL: Engine, https://github.com/prismal-ai/prismal
|
|
8
|
+
Project-URL: SDK, https://github.com/prismal-ai/prismal-sdk
|
|
9
|
+
Author-email: Ernesto Crespo <ecrespo@gmail.com>
|
|
10
|
+
License: MIT License
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2026 prismal-ai
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
in the Software without restriction, including without limitation the rights
|
|
17
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in all
|
|
22
|
+
copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
SOFTWARE.
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Keywords: a2a,agent,asgi,fastapi,prismal,sse
|
|
33
|
+
Classifier: Development Status :: 3 - Alpha
|
|
34
|
+
Classifier: Framework :: FastAPI
|
|
35
|
+
Classifier: Intended Audience :: Developers
|
|
36
|
+
Classifier: Programming Language :: Python :: 3
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
38
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
39
|
+
Requires-Python: >=3.13
|
|
40
|
+
Requires-Dist: aiosqlite>=0.20
|
|
41
|
+
Requires-Dist: fastapi>=0.115
|
|
42
|
+
Requires-Dist: prismal-ai<4,>=3.17
|
|
43
|
+
Requires-Dist: pydantic-settings>=2.5
|
|
44
|
+
Requires-Dist: pydantic>=2.10
|
|
45
|
+
Requires-Dist: pyyaml>=6.0
|
|
46
|
+
Requires-Dist: uvicorn[standard]>=0.30
|
|
47
|
+
Provides-Extra: dev
|
|
48
|
+
Requires-Dist: httpx>=0.27; extra == 'dev'
|
|
49
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
50
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
51
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
52
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
53
|
+
Requires-Dist: types-pyyaml>=6.0; extra == 'dev'
|
|
54
|
+
Description-Content-Type: text/markdown
|
|
55
|
+
|
|
56
|
+
# prismal-server
|
|
57
|
+
|
|
58
|
+
Reference **host** for the [`prismal`](https://github.com/prismal-ai/prismal)
|
|
59
|
+
agent engine — a thin FastAPI/ASGI process that exposes prismal over
|
|
60
|
+
**REST · SSE · WebSocket** (opt-in, `host_ws_enabled`) plus the inbound **A2A** endpoints, so
|
|
61
|
+
non-Python clients and the front-end ecosystem can build against it.
|
|
62
|
+
|
|
63
|
+
`prismal` is a pure library (no web server by design). `prismal-server` is the
|
|
64
|
+
missing process that binds a port, boots the engine once, and serves it — while
|
|
65
|
+
**reimplementing none of its logic**.
|
|
66
|
+
|
|
67
|
+
## Status
|
|
68
|
+
|
|
69
|
+
**v0.2: usage, gateways and AG-UI.** On top of the v0.1 host (streaming chat,
|
|
70
|
+
inbound A2A, auth/tenancy seams, health, release plumbing), v0.2 adds per-tenant
|
|
71
|
+
engine config and gateways, `done.usage` plus `/v1/usage` and `/v1/budget`, AG-UI 1.0
|
|
72
|
+
streaming, the A2A v1.0 dual stack, an opt-in WebSocket transport, a deterministic
|
|
73
|
+
fake-LLM mode and read-only admin endpoints. Specs:
|
|
74
|
+
[`specs/reference-host-bootstrap/`](./specs/reference-host-bootstrap/) (v0.1) and
|
|
75
|
+
[`specs/host-v0.2-usage-gateways-agui/`](./specs/host-v0.2-usage-gateways-agui/)
|
|
76
|
+
(v0.2). Release notes are in [`CHANGELOG.md`](./CHANGELOG.md).
|
|
77
|
+
|
|
78
|
+
## Quickstart
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
uv pip install -e ".[dev]"
|
|
82
|
+
uvicorn prismal_server.app:app --reload
|
|
83
|
+
curl localhost:8000/healthz # {"status":"ok"}
|
|
84
|
+
curl localhost:8000/readyz # {"status":"ready"} once the runtime composes
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Stream a chat turn (SSE):
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
tid=$(curl -sX POST localhost:8000/threads | python -c 'import sys,json;print(json.load(sys.stdin)["thread_id"])')
|
|
91
|
+
curl -N -X POST "localhost:8000/threads/$tid/messages" \
|
|
92
|
+
-H 'content-type: application/json' \
|
|
93
|
+
-d '{"content":"Hello!"}'
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Or with Docker:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
docker compose up --build
|
|
100
|
+
curl localhost:8000/healthz
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
> The image bundles the engine, which pulls heavy ML deps (embeddings, vector
|
|
104
|
+
> store) — the first build is large and slow. See
|
|
105
|
+
> [`docs/running.md`](./docs/running.md).
|
|
106
|
+
|
|
107
|
+
## HTTP surface
|
|
108
|
+
|
|
109
|
+
| Method | Path | Purpose |
|
|
110
|
+
|---|---|---|
|
|
111
|
+
| `GET` | `/healthz` · `/readyz` | Liveness / readiness |
|
|
112
|
+
| `POST` | `/threads` | Mint a new `thread_id` |
|
|
113
|
+
| `POST` | `/threads/{id}/messages` | Stream a chat turn (SSE: `token`/`tool_call`/`state`/`done`/`error`; `?protocol=ag-ui` for AG-UI) |
|
|
114
|
+
| `POST` | `/v1/agui` | AG-UI `RunAgentInput` → AG-UI event stream |
|
|
115
|
+
| `GET` | `/ws/threads/{id}` | WebSocket chat (opt-in, `host_ws_enabled`) |
|
|
116
|
+
| `GET` | `/v1/usage` · `/v1/budget` | Per-turn usage history · budget status and gateway quotas |
|
|
117
|
+
| `GET` | `/v1/admin/{tenants,audit,decisions,routing}` | Admin read endpoints (opt-in, admin scope) |
|
|
118
|
+
| `GET` | `/.well-known/agent-card.json` | A2A Agent Card (`?protocolVersion=0.3\|1.0`) |
|
|
119
|
+
| `POST` | `/a2a` · `{base}/{tenant}` | A2A JSON-RPC / SSE, v0.3 and v1.0 (delegates to `A2AServerHandler`) |
|
|
120
|
+
| `GET` | `/openapi.json` | OpenAPI with examples (for `prismal-sdk` generation) |
|
|
121
|
+
|
|
122
|
+
## Docs
|
|
123
|
+
|
|
124
|
+
| Doc | Covers |
|
|
125
|
+
|---|---|
|
|
126
|
+
| [`docs/running.md`](./docs/running.md) | Local run, Docker/compose, config, health/readiness |
|
|
127
|
+
| [`docs/auth.md`](./docs/auth.md) | The auth seam: `none` / `bearer` / `oidc`, strict mode |
|
|
128
|
+
| [`docs/tenancy.md`](./docs/tenancy.md) | `org_id` resolution (fail-closed), per-tenant runtimes, `tenant.yaml` and secrets |
|
|
129
|
+
| [`docs/usage.md`](./docs/usage.md) | `done.usage`, `/v1/usage`, `/v1/budget`, `402 budget_exceeded` |
|
|
130
|
+
| [`docs/agui.md`](./docs/agui.md) | AG-UI stream mode and `POST /v1/agui` |
|
|
131
|
+
| [`docs/websocket.md`](./docs/websocket.md) | WebSocket frames, close codes, handshake auth |
|
|
132
|
+
| [`docs/a2a.md`](./docs/a2a.md) | Inbound A2A: Agent Card, v0.3/v1.0 dual stack, tenant routes |
|
|
133
|
+
| [`docs/admin.md`](./docs/admin.md) | Admin read endpoints and their scopes |
|
|
134
|
+
| [`docs/fake-mode.md`](./docs/fake-mode.md) | Deterministic fake-LLM mode for contract tests |
|
|
135
|
+
|
|
136
|
+
## The contract with the engine
|
|
137
|
+
|
|
138
|
+
The host calls the engine only through its **public host read surface** (HRS §3)
|
|
139
|
+
plus the v0.1 entry points. Everything else it reads is a `RuntimeContext` method.
|
|
140
|
+
A static import-guard test enforces an exact per-module symbol allowlist
|
|
141
|
+
(`tests/unit/test_import_guard.py`); the rule and the review checklist live in
|
|
142
|
+
[`CLAUDE.md`](./CLAUDE.md).
|
|
143
|
+
|
|
144
|
+
- `build_runtime(...)` / `build_test_runtime(...)` → `RuntimeContext` (all ports, coordinated `aclose()`)
|
|
145
|
+
- `get_async_compiled_graph(...)` → the graph to `astream()`
|
|
146
|
+
- `A2AServerHandler` + `build_agent_card(...)` → inbound A2A
|
|
147
|
+
- `prismal.identity` `IdentityPort` / `OidcIdentityProvider` → request → identity
|
|
148
|
+
- `prismal.events.agui` (AG-UI translator) and `prismal.monitoring.get_run_summary` (usage wire)
|
|
149
|
+
|
|
150
|
+
## Development
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
uv pip install -e ".[dev]"
|
|
154
|
+
uv run pytest # unit suite (no live provider I/O)
|
|
155
|
+
uv run pytest -m contract # opt-in: against a released engine
|
|
156
|
+
uv run ruff check . && uv run ruff format --check .
|
|
157
|
+
uv run mypy src
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
The unit suite runs fully offline against engine fakes (`build_test_runtime`); the
|
|
161
|
+
`contract` suite boots a real `build_runtime()`, serves a real Agent Card, runs the
|
|
162
|
+
v0.2 surfaces (native, AG-UI, usage, A2A v1) against the released engine in fake-LLM
|
|
163
|
+
mode, and, when an LLM provider credential is present in the environment,
|
|
164
|
+
round-trips a full chat turn over SSE.
|
|
165
|
+
|
|
166
|
+
## Related repos
|
|
167
|
+
|
|
168
|
+
- [`prismal-ai/prismal`](https://github.com/prismal-ai/prismal) — the engine (pip dependency `prismal-ai`, pinned `>=3.17,<4`).
|
|
169
|
+
- [`prismal-ai/prismal-sdk`](https://github.com/prismal-ai/prismal-sdk) — thin client generated against this host's wire contract (`/openapi.json` + the A2A surface).
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
See [`LICENSE`](./LICENSE).
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# prismal-server
|
|
2
|
+
|
|
3
|
+
Reference **host** for the [`prismal`](https://github.com/prismal-ai/prismal)
|
|
4
|
+
agent engine — a thin FastAPI/ASGI process that exposes prismal over
|
|
5
|
+
**REST · SSE · WebSocket** (opt-in, `host_ws_enabled`) plus the inbound **A2A** endpoints, so
|
|
6
|
+
non-Python clients and the front-end ecosystem can build against it.
|
|
7
|
+
|
|
8
|
+
`prismal` is a pure library (no web server by design). `prismal-server` is the
|
|
9
|
+
missing process that binds a port, boots the engine once, and serves it — while
|
|
10
|
+
**reimplementing none of its logic**.
|
|
11
|
+
|
|
12
|
+
## Status
|
|
13
|
+
|
|
14
|
+
**v0.2: usage, gateways and AG-UI.** On top of the v0.1 host (streaming chat,
|
|
15
|
+
inbound A2A, auth/tenancy seams, health, release plumbing), v0.2 adds per-tenant
|
|
16
|
+
engine config and gateways, `done.usage` plus `/v1/usage` and `/v1/budget`, AG-UI 1.0
|
|
17
|
+
streaming, the A2A v1.0 dual stack, an opt-in WebSocket transport, a deterministic
|
|
18
|
+
fake-LLM mode and read-only admin endpoints. Specs:
|
|
19
|
+
[`specs/reference-host-bootstrap/`](./specs/reference-host-bootstrap/) (v0.1) and
|
|
20
|
+
[`specs/host-v0.2-usage-gateways-agui/`](./specs/host-v0.2-usage-gateways-agui/)
|
|
21
|
+
(v0.2). Release notes are in [`CHANGELOG.md`](./CHANGELOG.md).
|
|
22
|
+
|
|
23
|
+
## Quickstart
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
uv pip install -e ".[dev]"
|
|
27
|
+
uvicorn prismal_server.app:app --reload
|
|
28
|
+
curl localhost:8000/healthz # {"status":"ok"}
|
|
29
|
+
curl localhost:8000/readyz # {"status":"ready"} once the runtime composes
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Stream a chat turn (SSE):
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
tid=$(curl -sX POST localhost:8000/threads | python -c 'import sys,json;print(json.load(sys.stdin)["thread_id"])')
|
|
36
|
+
curl -N -X POST "localhost:8000/threads/$tid/messages" \
|
|
37
|
+
-H 'content-type: application/json' \
|
|
38
|
+
-d '{"content":"Hello!"}'
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Or with Docker:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
docker compose up --build
|
|
45
|
+
curl localhost:8000/healthz
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
> The image bundles the engine, which pulls heavy ML deps (embeddings, vector
|
|
49
|
+
> store) — the first build is large and slow. See
|
|
50
|
+
> [`docs/running.md`](./docs/running.md).
|
|
51
|
+
|
|
52
|
+
## HTTP surface
|
|
53
|
+
|
|
54
|
+
| Method | Path | Purpose |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| `GET` | `/healthz` · `/readyz` | Liveness / readiness |
|
|
57
|
+
| `POST` | `/threads` | Mint a new `thread_id` |
|
|
58
|
+
| `POST` | `/threads/{id}/messages` | Stream a chat turn (SSE: `token`/`tool_call`/`state`/`done`/`error`; `?protocol=ag-ui` for AG-UI) |
|
|
59
|
+
| `POST` | `/v1/agui` | AG-UI `RunAgentInput` → AG-UI event stream |
|
|
60
|
+
| `GET` | `/ws/threads/{id}` | WebSocket chat (opt-in, `host_ws_enabled`) |
|
|
61
|
+
| `GET` | `/v1/usage` · `/v1/budget` | Per-turn usage history · budget status and gateway quotas |
|
|
62
|
+
| `GET` | `/v1/admin/{tenants,audit,decisions,routing}` | Admin read endpoints (opt-in, admin scope) |
|
|
63
|
+
| `GET` | `/.well-known/agent-card.json` | A2A Agent Card (`?protocolVersion=0.3\|1.0`) |
|
|
64
|
+
| `POST` | `/a2a` · `{base}/{tenant}` | A2A JSON-RPC / SSE, v0.3 and v1.0 (delegates to `A2AServerHandler`) |
|
|
65
|
+
| `GET` | `/openapi.json` | OpenAPI with examples (for `prismal-sdk` generation) |
|
|
66
|
+
|
|
67
|
+
## Docs
|
|
68
|
+
|
|
69
|
+
| Doc | Covers |
|
|
70
|
+
|---|---|
|
|
71
|
+
| [`docs/running.md`](./docs/running.md) | Local run, Docker/compose, config, health/readiness |
|
|
72
|
+
| [`docs/auth.md`](./docs/auth.md) | The auth seam: `none` / `bearer` / `oidc`, strict mode |
|
|
73
|
+
| [`docs/tenancy.md`](./docs/tenancy.md) | `org_id` resolution (fail-closed), per-tenant runtimes, `tenant.yaml` and secrets |
|
|
74
|
+
| [`docs/usage.md`](./docs/usage.md) | `done.usage`, `/v1/usage`, `/v1/budget`, `402 budget_exceeded` |
|
|
75
|
+
| [`docs/agui.md`](./docs/agui.md) | AG-UI stream mode and `POST /v1/agui` |
|
|
76
|
+
| [`docs/websocket.md`](./docs/websocket.md) | WebSocket frames, close codes, handshake auth |
|
|
77
|
+
| [`docs/a2a.md`](./docs/a2a.md) | Inbound A2A: Agent Card, v0.3/v1.0 dual stack, tenant routes |
|
|
78
|
+
| [`docs/admin.md`](./docs/admin.md) | Admin read endpoints and their scopes |
|
|
79
|
+
| [`docs/fake-mode.md`](./docs/fake-mode.md) | Deterministic fake-LLM mode for contract tests |
|
|
80
|
+
|
|
81
|
+
## The contract with the engine
|
|
82
|
+
|
|
83
|
+
The host calls the engine only through its **public host read surface** (HRS §3)
|
|
84
|
+
plus the v0.1 entry points. Everything else it reads is a `RuntimeContext` method.
|
|
85
|
+
A static import-guard test enforces an exact per-module symbol allowlist
|
|
86
|
+
(`tests/unit/test_import_guard.py`); the rule and the review checklist live in
|
|
87
|
+
[`CLAUDE.md`](./CLAUDE.md).
|
|
88
|
+
|
|
89
|
+
- `build_runtime(...)` / `build_test_runtime(...)` → `RuntimeContext` (all ports, coordinated `aclose()`)
|
|
90
|
+
- `get_async_compiled_graph(...)` → the graph to `astream()`
|
|
91
|
+
- `A2AServerHandler` + `build_agent_card(...)` → inbound A2A
|
|
92
|
+
- `prismal.identity` `IdentityPort` / `OidcIdentityProvider` → request → identity
|
|
93
|
+
- `prismal.events.agui` (AG-UI translator) and `prismal.monitoring.get_run_summary` (usage wire)
|
|
94
|
+
|
|
95
|
+
## Development
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
uv pip install -e ".[dev]"
|
|
99
|
+
uv run pytest # unit suite (no live provider I/O)
|
|
100
|
+
uv run pytest -m contract # opt-in: against a released engine
|
|
101
|
+
uv run ruff check . && uv run ruff format --check .
|
|
102
|
+
uv run mypy src
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The unit suite runs fully offline against engine fakes (`build_test_runtime`); the
|
|
106
|
+
`contract` suite boots a real `build_runtime()`, serves a real Agent Card, runs the
|
|
107
|
+
v0.2 surfaces (native, AG-UI, usage, A2A v1) against the released engine in fake-LLM
|
|
108
|
+
mode, and, when an LLM provider credential is present in the environment,
|
|
109
|
+
round-trips a full chat turn over SSE.
|
|
110
|
+
|
|
111
|
+
## Related repos
|
|
112
|
+
|
|
113
|
+
- [`prismal-ai/prismal`](https://github.com/prismal-ai/prismal) — the engine (pip dependency `prismal-ai`, pinned `>=3.17,<4`).
|
|
114
|
+
- [`prismal-ai/prismal-sdk`](https://github.com/prismal-ai/prismal-sdk) — thin client generated against this host's wire contract (`/openapi.json` + the A2A surface).
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
See [`LICENSE`](./LICENSE).
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "prismal-server"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Reference host for the prismal agent engine — a thin FastAPI/ASGI process serving prismal over REST/SSE and inbound A2A."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
# The engine (prismal-ai) requires Python >=3.13, so the host does too.
|
|
11
|
+
requires-python = ">=3.13"
|
|
12
|
+
license = { file = "LICENSE" }
|
|
13
|
+
authors = [{ name = "Ernesto Crespo", email = "ecrespo@gmail.com" }]
|
|
14
|
+
keywords = ["prismal", "agent", "fastapi", "a2a", "sse", "asgi"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Framework :: FastAPI",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Topic :: Internet :: WWW/HTTP :: HTTP Servers",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
# The engine. PyPI distribution is `prismal-ai`; the import module is `prismal`.
|
|
25
|
+
# Pinned per SPEC-RHB-NFR-004: the host couples only to the four engine seams.
|
|
26
|
+
dependencies = [
|
|
27
|
+
"prismal-ai>=3.17,<4",
|
|
28
|
+
"fastapi>=0.115",
|
|
29
|
+
"uvicorn[standard]>=0.30",
|
|
30
|
+
"pydantic>=2.10",
|
|
31
|
+
"pydantic-settings>=2.5",
|
|
32
|
+
# Per-tenant `tenant.yaml` (RH2-01-03); parsed with `yaml.safe_load` only.
|
|
33
|
+
"pyyaml>=6.0",
|
|
34
|
+
# SQLite usage store (RH2-02-03, host_usage_store="sqlite").
|
|
35
|
+
"aiosqlite>=0.20",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[project.optional-dependencies]
|
|
39
|
+
dev = [
|
|
40
|
+
"pytest>=8.0",
|
|
41
|
+
"pytest-asyncio>=0.24",
|
|
42
|
+
"httpx>=0.27",
|
|
43
|
+
"ruff>=0.6",
|
|
44
|
+
"mypy>=1.11",
|
|
45
|
+
"types-PyYAML>=6.0",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[project.urls]
|
|
49
|
+
Homepage = "https://github.com/prismal-ai/prismal-server"
|
|
50
|
+
Repository = "https://github.com/prismal-ai/prismal-server"
|
|
51
|
+
Engine = "https://github.com/prismal-ai/prismal"
|
|
52
|
+
SDK = "https://github.com/prismal-ai/prismal-sdk"
|
|
53
|
+
|
|
54
|
+
[tool.hatch.build.targets.wheel]
|
|
55
|
+
packages = ["src/prismal_server"]
|
|
56
|
+
|
|
57
|
+
[tool.hatch.build.targets.sdist]
|
|
58
|
+
include = ["src/prismal_server", "README.md", "LICENSE"]
|
|
59
|
+
|
|
60
|
+
# ── Tooling ────────────────────────────────────────────────────────────────
|
|
61
|
+
|
|
62
|
+
[tool.ruff]
|
|
63
|
+
src = ["src", "tests"]
|
|
64
|
+
line-length = 88
|
|
65
|
+
target-version = "py313"
|
|
66
|
+
|
|
67
|
+
[tool.ruff.lint]
|
|
68
|
+
select = ["E", "F", "I", "UP", "B", "ASYNC", "W"]
|
|
69
|
+
|
|
70
|
+
[tool.ruff.lint.isort]
|
|
71
|
+
known-first-party = ["prismal_server"]
|
|
72
|
+
|
|
73
|
+
[tool.mypy]
|
|
74
|
+
python_version = "3.13"
|
|
75
|
+
mypy_path = "src"
|
|
76
|
+
packages = ["prismal_server"]
|
|
77
|
+
strict = true
|
|
78
|
+
warn_unused_ignores = true
|
|
79
|
+
warn_return_any = true
|
|
80
|
+
no_implicit_reexport = true
|
|
81
|
+
|
|
82
|
+
[[tool.mypy.overrides]]
|
|
83
|
+
# The engine ships its own types; if a released build lacks a py.typed marker,
|
|
84
|
+
# don't fail the host's type check on it.
|
|
85
|
+
module = ["prismal.*"]
|
|
86
|
+
ignore_missing_imports = true
|
|
87
|
+
|
|
88
|
+
[tool.pytest.ini_options]
|
|
89
|
+
asyncio_mode = "auto"
|
|
90
|
+
testpaths = ["tests"]
|
|
91
|
+
addopts = "-ra --strict-markers"
|
|
92
|
+
filterwarnings = [
|
|
93
|
+
# Starlette's TestClient (WebSocket tests) still runs on httpx.
|
|
94
|
+
"ignore:Using `httpx` with `starlette.testclient` is deprecated",
|
|
95
|
+
]
|
|
96
|
+
markers = [
|
|
97
|
+
"contract: opt-in smoke tests against a released prismal engine (deselected by default)",
|
|
98
|
+
]
|
|
99
|
+
# Unit suite runs with no live provider I/O; the contract suite is opt-in.
|
|
100
|
+
# Run unit only: uv run pytest -m 'not contract'
|
|
101
|
+
# Run contract suite: uv run pytest -m contract
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""prismal-server — reference host for the prismal engine.
|
|
2
|
+
|
|
3
|
+
A thin FastAPI/ASGI process that boots the engine once and serves it over
|
|
4
|
+
REST/SSE plus the inbound A2A endpoints. It orchestrates the engine through
|
|
5
|
+
exactly four seams and reimplements none of its logic (see ``CLAUDE.md``).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
__version__ = version("prismal-server")
|
|
12
|
+
except PackageNotFoundError: # pragma: no cover - source checkout without install
|
|
13
|
+
__version__ = "0.0.0.dev0"
|
|
14
|
+
|
|
15
|
+
__all__ = ["__version__"]
|