interloper-api 0.131.0__tar.gz → 0.133.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.
- {interloper_api-0.131.0 → interloper_api-0.133.0}/PKG-INFO +2 -2
- {interloper_api-0.131.0 → interloper_api-0.133.0}/pyproject.toml +5 -6
- {interloper_api-0.131.0 → interloper_api-0.133.0}/pyproject.toml.orig +5 -6
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/app.py +77 -54
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/authorization.py +289 -13
- interloper_api-0.133.0/src/interloper_api/cli.py +204 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/dependencies/__init__.py +4 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/dependencies/auth.py +3 -7
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/dependencies/state.py +30 -30
- interloper_api-0.133.0/src/interloper_api/extension.yaml +10 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/login.py +7 -5
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/notifications/base.py +4 -5
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/notifications/invitations.py +0 -3
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/notifications/super_admins.py +0 -3
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/admin.py +88 -293
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/agent.py +5 -6
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/apps.py +9 -3
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/auth.py +8 -8
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/authorization.py +12 -4
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/catalog.py +7 -2
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/components.py +4 -3
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/oauth.py +2 -2
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/overview.py +2 -2
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/tokens.py +2 -2
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/websocket.py +106 -30
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/server.py +4 -3
- interloper_api-0.133.0/src/interloper_api/settings.py +162 -0
- interloper_api-0.131.0/src/interloper_api/cli.py +0 -156
- {interloper_api-0.131.0 → interloper_api-0.133.0}/README.md +0 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/__init__.py +0 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/dependencies/rbac.py +0 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/notifications/__init__.py +0 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/__init__.py +0 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/backfills.py +0 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/executions.py +0 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/health.py +0 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/organisations.py +0 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/relations.py +0 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/routes/runs.py +0 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/utils/__init__.py +0 -0
- {interloper_api-0.131.0 → interloper_api-0.133.0}/src/interloper_api/utils/time.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: interloper-api
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.133.0
|
|
4
4
|
Summary: Interloper FastAPI routes
|
|
5
5
|
Author: Guillaume Onfroy
|
|
6
6
|
Author-email: Guillaume Onfroy <guillaume@digitlcloud.com>
|
|
@@ -19,7 +19,7 @@ Requires-Dist: joserfc>=1.7
|
|
|
19
19
|
Requires-Dist: interloper-agent ; extra == 'agent'
|
|
20
20
|
Requires-Dist: interloper-core[otel] ; extra == 'otel'
|
|
21
21
|
Requires-Dist: opentelemetry-instrumentation-fastapi>=0.65b0 ; extra == 'otel'
|
|
22
|
-
Requires-Python: >=3.
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
23
|
Provides-Extra: agent
|
|
24
24
|
Provides-Extra: otel
|
|
25
25
|
Description-Content-Type: text/markdown
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "interloper-api"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.133.0"
|
|
4
4
|
description = "Interloper FastAPI routes"
|
|
5
5
|
readme = "README.md"
|
|
6
|
-
requires-python = ">=3.
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
7
|
dependencies = [
|
|
8
8
|
"interloper-core",
|
|
9
9
|
"interloper-db",
|
|
@@ -30,12 +30,11 @@ otel = [
|
|
|
30
30
|
"opentelemetry-instrumentation-fastapi>=0.65b0",
|
|
31
31
|
]
|
|
32
32
|
|
|
33
|
-
[project.entry-points."interloper.
|
|
34
|
-
api = "interloper_api
|
|
35
|
-
oauth = "interloper_api.cli:register_oauth"
|
|
33
|
+
[project.entry-points."interloper.extensions"]
|
|
34
|
+
api = "interloper_api"
|
|
36
35
|
|
|
37
36
|
[build-system]
|
|
38
|
-
requires = ["uv_build>=0.
|
|
37
|
+
requires = ["uv_build>=0.13.7,<0.14"]
|
|
39
38
|
build-backend = "uv_build"
|
|
40
39
|
|
|
41
40
|
[tool.uv.sources.interloper-core]
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
# ###############
|
|
4
4
|
[project]
|
|
5
5
|
name = "interloper-api"
|
|
6
|
-
version = "0.
|
|
6
|
+
version = "0.133.0"
|
|
7
7
|
description = "Interloper FastAPI routes"
|
|
8
8
|
readme = "README.md"
|
|
9
9
|
authors = [{ name = "Guillaume Onfroy", email = "guillaume@digitlcloud.com" }]
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
11
|
dependencies = [
|
|
12
12
|
"interloper-core",
|
|
13
13
|
"interloper-db",
|
|
@@ -30,12 +30,11 @@ otel = [
|
|
|
30
30
|
"opentelemetry-instrumentation-fastapi>=0.65b0",
|
|
31
31
|
]
|
|
32
32
|
|
|
33
|
-
[project.entry-points."interloper.
|
|
34
|
-
api = "interloper_api
|
|
35
|
-
oauth = "interloper_api.cli:register_oauth"
|
|
33
|
+
[project.entry-points."interloper.extensions"]
|
|
34
|
+
api = "interloper_api"
|
|
36
35
|
|
|
37
36
|
[build-system]
|
|
38
|
-
requires = ["uv_build>=0.
|
|
37
|
+
requires = ["uv_build>=0.13.7,<0.14"]
|
|
39
38
|
build-backend = "uv_build"
|
|
40
39
|
|
|
41
40
|
[tool.uv.sources]
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import logging
|
|
6
|
+
from collections.abc import AsyncGenerator
|
|
7
|
+
from contextlib import asynccontextmanager
|
|
6
8
|
from typing import Any
|
|
7
9
|
|
|
8
10
|
from fastapi import APIRouter, FastAPI, Request
|
|
@@ -19,6 +21,7 @@ from interloper_db import (
|
|
|
19
21
|
QuotaExceededError,
|
|
20
22
|
Store,
|
|
21
23
|
)
|
|
24
|
+
from starlette.concurrency import run_in_threadpool
|
|
22
25
|
|
|
23
26
|
from interloper_api.authorization import AuthorizationServer, CrossOriginMiddleware
|
|
24
27
|
from interloper_api.dependencies import State
|
|
@@ -41,6 +44,7 @@ from interloper_api.routes import (
|
|
|
41
44
|
websocket,
|
|
42
45
|
)
|
|
43
46
|
from interloper_api.routes import catalog as catalog_routes
|
|
47
|
+
from interloper_api.settings import ApiSettings
|
|
44
48
|
|
|
45
49
|
logger = logging.getLogger(__name__)
|
|
46
50
|
|
|
@@ -173,21 +177,24 @@ def install_error_handlers(app: FastAPI) -> None:
|
|
|
173
177
|
|
|
174
178
|
|
|
175
179
|
def create_app(
|
|
176
|
-
store: Store
|
|
177
|
-
catalog: Catalog
|
|
178
|
-
settings:
|
|
180
|
+
store: Store,
|
|
181
|
+
catalog: Catalog,
|
|
182
|
+
settings: ApiSettings,
|
|
179
183
|
cors_origins: list[str] | None = None,
|
|
180
184
|
**kwargs: Any,
|
|
181
185
|
) -> FastAPI:
|
|
182
186
|
"""Create the FastAPI application with all routes.
|
|
183
187
|
|
|
188
|
+
On startup the application promotes the configured super-admins and
|
|
189
|
+
starts the realtime listener.
|
|
190
|
+
|
|
184
191
|
Args:
|
|
185
192
|
store: The ``Store`` instance for persistence.
|
|
186
193
|
catalog: Catalog instance.
|
|
187
|
-
settings:
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
only when
|
|
194
|
+
settings: Every section the API reads; the factory also builds the
|
|
195
|
+
secrets-redacted snapshot of every declared section for the
|
|
196
|
+
super-admin ``/admin/config`` view. The agent routes
|
|
197
|
+
mount only when they enable the agent and the ``agent`` extra
|
|
191
198
|
is installed.
|
|
192
199
|
cors_origins: Allowed CORS origins. Only needed in dev mode for direct
|
|
193
200
|
WebSocket connections that bypass the Vite proxy.
|
|
@@ -196,7 +203,7 @@ def create_app(
|
|
|
196
203
|
Returns:
|
|
197
204
|
The configured FastAPI application.
|
|
198
205
|
"""
|
|
199
|
-
app = FastAPI(title="Interloper API", lifespan=
|
|
206
|
+
app = FastAPI(title="Interloper API", lifespan=_lifespan, **kwargs)
|
|
200
207
|
|
|
201
208
|
install_error_handlers(app)
|
|
202
209
|
|
|
@@ -219,11 +226,11 @@ def create_app(
|
|
|
219
226
|
api.include_router(router)
|
|
220
227
|
for org_router in _ORG_ROUTERS:
|
|
221
228
|
api.include_router(org_router, prefix=ORG_PREFIX)
|
|
222
|
-
|
|
229
|
+
agent_model = _mount_agent(api, settings)
|
|
223
230
|
app.include_router(api)
|
|
224
231
|
app.include_router(authorization.well_known_router)
|
|
225
232
|
|
|
226
|
-
app.state.interloper = _state(store, catalog, settings,
|
|
233
|
+
app.state.interloper = _state(store, catalog, settings, agent_model=agent_model, google_login=google_login)
|
|
227
234
|
|
|
228
235
|
oauth.log_provider_status()
|
|
229
236
|
|
|
@@ -233,22 +240,45 @@ def create_app(
|
|
|
233
240
|
# -- Internals -----------------------------------------------------------------
|
|
234
241
|
|
|
235
242
|
|
|
236
|
-
|
|
237
|
-
|
|
243
|
+
@asynccontextmanager
|
|
244
|
+
async def _lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
|
245
|
+
"""Promote the configured super-admins, then serve with the realtime listener running.
|
|
246
|
+
|
|
247
|
+
``auth.super_admin_emails`` is applied here as well as at login, so a
|
|
248
|
+
deployment shipping a new list promotes the profiles that already exist
|
|
249
|
+
without waiting for them to sign in again.
|
|
250
|
+
|
|
251
|
+
Args:
|
|
252
|
+
app: The application being started; its state carries the store and
|
|
253
|
+
the settings.
|
|
254
|
+
|
|
255
|
+
Yields:
|
|
256
|
+
None, while the application serves.
|
|
257
|
+
"""
|
|
258
|
+
state: State = app.state.interloper
|
|
259
|
+
emails = state.settings.auth.super_admin_emails
|
|
260
|
+
promoted = await run_in_threadpool(state.store.profiles.promote_super_admins, emails)
|
|
261
|
+
for profile in promoted:
|
|
262
|
+
logger.info("Promoted profile %s to super-admin.", profile.id)
|
|
263
|
+
async with websocket.realtime_lifespan(app):
|
|
264
|
+
yield
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def _mount_agent(api: APIRouter, settings: ApiSettings) -> str | None:
|
|
268
|
+
"""Mount the optional agent routes when the settings enable the agent.
|
|
238
269
|
|
|
239
270
|
The conversation routes go under the organisation prefix, the tool list outside it.
|
|
240
271
|
|
|
241
272
|
Args:
|
|
242
273
|
api: The ``/api`` router to mount onto.
|
|
243
|
-
settings:
|
|
244
|
-
extra is installed.
|
|
274
|
+
settings: The API's settings; ``agent`` is ``None`` without the agent package.
|
|
245
275
|
|
|
246
276
|
Returns:
|
|
247
|
-
|
|
277
|
+
The model the mounted agent runs on, or ``None`` when the routes are not mounted.
|
|
248
278
|
"""
|
|
249
|
-
if settings is
|
|
250
|
-
logger.info("Agent routes not mounted:
|
|
251
|
-
return
|
|
279
|
+
if settings.agent is None or not settings.agent.enabled:
|
|
280
|
+
logger.info("Agent routes not mounted: the agent is not enabled (agent.enabled).")
|
|
281
|
+
return None
|
|
252
282
|
|
|
253
283
|
try:
|
|
254
284
|
from interloper_api.routes import agent as agent_routes
|
|
@@ -257,91 +287,84 @@ def _mount_agent(api: APIRouter, settings: Any | None) -> bool:
|
|
|
257
287
|
"Agent routes not mounted: the 'agent' extra is not installed "
|
|
258
288
|
"(install interloper-api[agent]); /agent endpoints will return 404."
|
|
259
289
|
)
|
|
260
|
-
return
|
|
290
|
+
return None
|
|
261
291
|
|
|
262
292
|
api.include_router(agent_routes.router)
|
|
263
293
|
api.include_router(agent_routes.org_router, prefix=ORG_PREFIX)
|
|
264
|
-
return
|
|
294
|
+
return settings.agent.model
|
|
265
295
|
|
|
266
296
|
|
|
267
297
|
def _state(
|
|
268
|
-
store: Store
|
|
269
|
-
catalog: Catalog
|
|
270
|
-
settings:
|
|
298
|
+
store: Store,
|
|
299
|
+
catalog: Catalog,
|
|
300
|
+
settings: ApiSettings,
|
|
271
301
|
*,
|
|
272
|
-
|
|
302
|
+
agent_model: str | None,
|
|
273
303
|
google_login: GoogleLogin | None,
|
|
274
304
|
) -> State:
|
|
275
305
|
"""Build the state the request dependencies read back.
|
|
276
306
|
|
|
277
307
|
Args:
|
|
278
|
-
store: The ``Store`` instance
|
|
279
|
-
catalog: Catalog instance
|
|
280
|
-
settings:
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
308
|
+
store: The ``Store`` instance.
|
|
309
|
+
catalog: Catalog instance.
|
|
310
|
+
settings: The API's settings.
|
|
311
|
+
agent_model: The model the mounted agent runs on, or ``None`` when
|
|
312
|
+
the agent routes are not mounted; recorded as a feature flag and
|
|
313
|
+
in the admin config snapshot.
|
|
284
314
|
google_login: The Google login, already installed on the app, or
|
|
285
315
|
``None``.
|
|
286
316
|
|
|
287
317
|
Returns:
|
|
288
318
|
The state.
|
|
289
319
|
"""
|
|
290
|
-
features = {"agent":
|
|
320
|
+
features = {"agent": agent_model is not None}
|
|
291
321
|
agent = None
|
|
292
|
-
if
|
|
293
|
-
from interloper.settings import AgentSettings
|
|
322
|
+
if agent_model is not None:
|
|
294
323
|
from interloper_agent import build_agent
|
|
295
324
|
|
|
296
|
-
agent = build_agent(
|
|
297
|
-
if settings is None:
|
|
298
|
-
return State(store=store, catalog=catalog, agent=agent, features=features)
|
|
325
|
+
agent = build_agent(agent_model)
|
|
299
326
|
return State(
|
|
300
327
|
store=store,
|
|
301
328
|
catalog=catalog,
|
|
302
329
|
settings=settings,
|
|
330
|
+
admin_config=admin.AdminConfigResponse.from_declared(features=features, catalog=catalog),
|
|
303
331
|
agent=agent,
|
|
304
332
|
features=features,
|
|
305
|
-
admin_config=admin.AdminConfigResponse.from_settings(settings, features=features, catalog=catalog),
|
|
306
333
|
authorization_server=_authorization_server(store, settings),
|
|
307
334
|
google_login=google_login,
|
|
308
335
|
)
|
|
309
336
|
|
|
310
337
|
|
|
311
|
-
def _google_login(settings:
|
|
338
|
+
def _google_login(settings: ApiSettings) -> GoogleLogin | None:
|
|
312
339
|
"""Build the Google login, when the deployment can run one.
|
|
313
340
|
|
|
314
341
|
Args:
|
|
315
|
-
settings:
|
|
342
|
+
settings: The API's settings.
|
|
316
343
|
|
|
317
344
|
Returns:
|
|
318
|
-
The login, or ``None`` without
|
|
319
|
-
|
|
320
|
-
|
|
345
|
+
The login, or ``None`` without a Google client or without an
|
|
346
|
+
encryption key (which signs the cookie the login keeps between
|
|
347
|
+
Google's two legs).
|
|
321
348
|
"""
|
|
322
|
-
if settings is None:
|
|
323
|
-
return None
|
|
324
349
|
google_login = GoogleLogin.from_settings(settings)
|
|
325
|
-
if google_login is None and settings.auth.google_client_id and not settings.
|
|
350
|
+
if google_login is None and settings.auth.google_client_id and not settings.encryption.key:
|
|
326
351
|
logger.warning("Google login unavailable: INTERLOPER_ENCRYPTION_KEY is not configured.")
|
|
327
352
|
return google_login
|
|
328
353
|
|
|
329
354
|
|
|
330
|
-
def _authorization_server(store: Store
|
|
355
|
+
def _authorization_server(store: Store, settings: ApiSettings) -> AuthorizationServer | None:
|
|
331
356
|
"""Build the OAuth authorization server, when the deployment can run one.
|
|
332
357
|
|
|
333
358
|
Args:
|
|
334
|
-
store: The ``Store`` instance
|
|
335
|
-
settings:
|
|
359
|
+
store: The ``Store`` instance.
|
|
360
|
+
settings: The API's settings.
|
|
336
361
|
|
|
337
362
|
Returns:
|
|
338
|
-
The server, or ``None`` without
|
|
339
|
-
|
|
340
|
-
|
|
363
|
+
The server, or ``None`` without an encryption key (which seals the
|
|
364
|
+
authorization request while the user decides), or when the issuer is
|
|
365
|
+
refused (plain http on a non-loopback host).
|
|
341
366
|
"""
|
|
342
|
-
if
|
|
343
|
-
return None
|
|
344
|
-
if not settings.secrets.encryption_key:
|
|
367
|
+
if not settings.encryption.key:
|
|
345
368
|
logger.warning("OAuth authorization server not mounted: INTERLOPER_ENCRYPTION_KEY is not configured.")
|
|
346
369
|
return None
|
|
347
370
|
try:
|