interloper-api 0.132.0__tar.gz → 0.134.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 (42) hide show
  1. {interloper_api-0.132.0 → interloper_api-0.134.0}/PKG-INFO +2 -2
  2. {interloper_api-0.132.0 → interloper_api-0.134.0}/pyproject.toml +5 -6
  3. {interloper_api-0.132.0 → interloper_api-0.134.0}/pyproject.toml.orig +5 -6
  4. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/app.py +77 -67
  5. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/authorization.py +282 -3
  6. interloper_api-0.134.0/src/interloper_api/cli.py +204 -0
  7. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/dependencies/__init__.py +4 -0
  8. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/dependencies/state.py +30 -30
  9. interloper_api-0.134.0/src/interloper_api/extension.yaml +10 -0
  10. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/login.py +5 -3
  11. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/notifications/base.py +4 -5
  12. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/notifications/invitations.py +0 -3
  13. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/notifications/super_admins.py +0 -3
  14. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/admin.py +111 -285
  15. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/agent.py +5 -6
  16. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/apps.py +9 -3
  17. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/auth.py +7 -7
  18. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/authorization.py +12 -4
  19. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/components.py +4 -3
  20. interloper_api-0.134.0/src/interloper_api/routes/extensions.py +112 -0
  21. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/oauth.py +2 -2
  22. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/overview.py +2 -2
  23. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/tokens.py +2 -2
  24. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/websocket.py +106 -30
  25. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/server.py +4 -3
  26. interloper_api-0.134.0/src/interloper_api/settings.py +162 -0
  27. interloper_api-0.132.0/src/interloper_api/cli.py +0 -161
  28. {interloper_api-0.132.0 → interloper_api-0.134.0}/README.md +0 -0
  29. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/__init__.py +0 -0
  30. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/dependencies/auth.py +0 -0
  31. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/dependencies/rbac.py +0 -0
  32. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/notifications/__init__.py +0 -0
  33. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/__init__.py +0 -0
  34. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/backfills.py +0 -0
  35. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/catalog.py +0 -0
  36. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/executions.py +0 -0
  37. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/health.py +0 -0
  38. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/organisations.py +0 -0
  39. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/relations.py +0 -0
  40. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/routes/runs.py +0 -0
  41. {interloper_api-0.132.0 → interloper_api-0.134.0}/src/interloper_api/utils/__init__.py +0 -0
  42. {interloper_api-0.132.0 → interloper_api-0.134.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.132.0
3
+ Version: 0.134.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.10
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.132.0"
3
+ version = "0.134.0"
4
4
  description = "Interloper FastAPI routes"
5
5
  readme = "README.md"
6
- requires-python = ">=3.10"
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.cli"]
34
- api = "interloper_api.cli:register"
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.12.9,<0.13"]
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.132.0"
6
+ version = "0.134.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"
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.cli"]
34
- api = "interloper_api.cli:register"
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.12.9,<0.13"]
37
+ requires = ["uv_build>=0.13.7,<0.14"]
39
38
  build-backend = "uv_build"
40
39
 
41
40
  [tool.uv.sources]
@@ -3,11 +3,11 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import logging
6
- from collections.abc import AsyncIterator
6
+ from collections.abc import AsyncGenerator
7
7
  from contextlib import asynccontextmanager
8
8
  from typing import Any
9
9
 
10
- from fastapi import APIRouter, FastAPI, Request
10
+ from fastapi import APIRouter, Depends, FastAPI, Request
11
11
  from fastapi.middleware.cors import CORSMiddleware
12
12
  from fastapi.responses import JSONResponse
13
13
  from interloper.catalog import Catalog
@@ -24,7 +24,7 @@ from interloper_db import (
24
24
  from starlette.concurrency import run_in_threadpool
25
25
 
26
26
  from interloper_api.authorization import AuthorizationServer, CrossOriginMiddleware
27
- from interloper_api.dependencies import State
27
+ from interloper_api.dependencies import State, require_viewer
28
28
  from interloper_api.login import GoogleLogin
29
29
  from interloper_api.routes import (
30
30
  admin,
@@ -34,6 +34,7 @@ from interloper_api.routes import (
34
34
  backfills,
35
35
  components,
36
36
  executions,
37
+ extensions,
37
38
  health,
38
39
  oauth,
39
40
  organisations,
@@ -44,11 +45,13 @@ from interloper_api.routes import (
44
45
  websocket,
45
46
  )
46
47
  from interloper_api.routes import catalog as catalog_routes
48
+ from interloper_api.settings import ApiSettings
47
49
 
48
50
  logger = logging.getLogger(__name__)
49
51
 
50
52
  #: Routers mounted under ``/api`` for every deployment: the caller's own, the
51
- #: organisation management and super-admin ones, a run's ingest, and the probes.
53
+ #: organisation management and super-admin ones, the installed extensions, a
54
+ #: run's ingest, and the probes.
52
55
  _ROUTERS: tuple[APIRouter, ...] = (
53
56
  auth.router,
54
57
  authorization.router,
@@ -57,13 +60,14 @@ _ROUTERS: tuple[APIRouter, ...] = (
57
60
  oauth.router,
58
61
  tokens.router,
59
62
  apps.router,
63
+ extensions.router,
60
64
  runs.router,
61
65
  health.router,
62
66
  )
63
67
 
64
68
  #: Routers acting in one organisation, mounted under ``/api/organisations/{org_id}``.
65
- #: The agent router is absent by design: it is optional and mounted by
66
- #: :func:`_mount_agent`.
69
+ #: The agent's and the extensions' are absent by design: they are optional and
70
+ #: mounted by :func:`_mount_agent` and :func:`_mount_extensions`.
67
71
  _ORG_ROUTERS: tuple[APIRouter, ...] = (
68
72
  organisations.org_router,
69
73
  catalog_routes.org_router,
@@ -176,24 +180,25 @@ def install_error_handlers(app: FastAPI) -> None:
176
180
 
177
181
 
178
182
  def create_app(
179
- store: Store | None = None,
180
- catalog: Catalog | None = None,
181
- settings: Any | None = None,
183
+ store: Store,
184
+ catalog: Catalog,
185
+ settings: ApiSettings,
182
186
  cors_origins: list[str] | None = None,
183
187
  **kwargs: Any,
184
188
  ) -> FastAPI:
185
189
  """Create the FastAPI application with all routes.
186
190
 
187
- On startup the application promotes the configured super-admins and
188
- starts the realtime listener.
191
+ The routes the installed packages declare mount under
192
+ ``/api/organisations/{org_id}/ext/<name>``. On startup the application
193
+ promotes the configured super-admins and starts the realtime listener.
189
194
 
190
195
  Args:
191
196
  store: The ``Store`` instance for persistence.
192
197
  catalog: Catalog instance.
193
- settings: Full ``AppSettings``; the factory slices what it needs
194
- (auth, smtp, agent) and builds the secrets-redacted snapshot for
195
- the super-admin ``/admin/config`` view. The agent routes mount
196
- only when enabled (or with no settings) and the ``agent`` extra
198
+ settings: Every section the API reads; the factory also builds the
199
+ secrets-redacted snapshot of every declared section for the
200
+ super-admin ``/admin/config`` view. The agent routes
201
+ mount only when they enable the agent and the ``agent`` extra
197
202
  is installed.
198
203
  cors_origins: Allowed CORS origins. Only needed in dev mode for direct
199
204
  WebSocket connections that bypass the Vite proxy.
@@ -225,11 +230,12 @@ def create_app(
225
230
  api.include_router(router)
226
231
  for org_router in _ORG_ROUTERS:
227
232
  api.include_router(org_router, prefix=ORG_PREFIX)
228
- agent_available = _mount_agent(api, settings)
233
+ agent_model = _mount_agent(api, settings)
234
+ _mount_extensions(api)
229
235
  app.include_router(api)
230
236
  app.include_router(authorization.well_known_router)
231
237
 
232
- app.state.interloper = _state(store, catalog, settings, agent_available=agent_available, google_login=google_login)
238
+ app.state.interloper = _state(store, catalog, settings, agent_model=agent_model, google_login=google_login)
233
239
 
234
240
  oauth.log_provider_status()
235
241
 
@@ -240,7 +246,7 @@ def create_app(
240
246
 
241
247
 
242
248
  @asynccontextmanager
243
- async def _lifespan(app: FastAPI) -> AsyncIterator[None]:
249
+ async def _lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
244
250
  """Promote the configured super-admins, then serve with the realtime listener running.
245
251
 
246
252
  ``auth.super_admin_emails`` is applied here as well as at login, so a
@@ -249,38 +255,35 @@ async def _lifespan(app: FastAPI) -> AsyncIterator[None]:
249
255
 
250
256
  Args:
251
257
  app: The application being started; its state carries the store and
252
- the settings, and an app built without either promotes no one.
258
+ the settings.
253
259
 
254
260
  Yields:
255
261
  None, while the application serves.
256
262
  """
257
263
  state: State = app.state.interloper
258
- if state.store is not None and state.settings is not None:
259
- promoted = await run_in_threadpool(
260
- state.store.profiles.promote_super_admins, state.settings.auth.super_admin_emails
261
- )
262
- for profile in promoted:
263
- logger.info("Promoted profile %s to super-admin.", profile.id)
264
+ emails = state.settings.auth.super_admin_emails
265
+ promoted = await run_in_threadpool(state.store.profiles.promote_super_admins, emails)
266
+ for profile in promoted:
267
+ logger.info("Promoted profile %s to super-admin.", profile.id)
264
268
  async with websocket.realtime_lifespan(app):
265
269
  yield
266
270
 
267
271
 
268
- def _mount_agent(api: APIRouter, settings: Any | None) -> bool:
269
- """Mount the optional agent routes, reporting whether they are available.
272
+ def _mount_agent(api: APIRouter, settings: ApiSettings) -> str | None:
273
+ """Mount the optional agent routes when the settings enable the agent.
270
274
 
271
275
  The conversation routes go under the organisation prefix, the tool list outside it.
272
276
 
273
277
  Args:
274
278
  api: The ``/api`` router to mount onto.
275
- settings: Full ``AppSettings``, or ``None`` to mount whenever the
276
- extra is installed.
279
+ settings: The API's settings; ``agent`` is ``None`` without the agent package.
277
280
 
278
281
  Returns:
279
- True when the agent routes are mounted.
282
+ The model the mounted agent runs on, or ``None`` when the routes are not mounted.
280
283
  """
281
- if settings is not None and not settings.agent.enabled:
282
- logger.info("Agent routes not mounted: disabled via settings.")
283
- return False
284
+ if settings.agent is None or not settings.agent.enabled:
285
+ logger.info("Agent routes not mounted: the agent is not enabled (agent.enabled).")
286
+ return None
284
287
 
285
288
  try:
286
289
  from interloper_api.routes import agent as agent_routes
@@ -289,90 +292,97 @@ def _mount_agent(api: APIRouter, settings: Any | None) -> bool:
289
292
  "Agent routes not mounted: the 'agent' extra is not installed "
290
293
  "(install interloper-api[agent]); /agent endpoints will return 404."
291
294
  )
292
- return False
295
+ return None
293
296
 
294
297
  api.include_router(agent_routes.router)
295
298
  api.include_router(agent_routes.org_router, prefix=ORG_PREFIX)
296
- return True
299
+ return settings.agent.model
300
+
301
+
302
+ def _mount_extensions(api: APIRouter) -> None:
303
+ """Mount every router the installed packages declare, the viewer role its floor.
304
+
305
+ A router that fails to load is skipped and recorded, so the listing and
306
+ the configuration page name it while every other one serves.
307
+
308
+ Args:
309
+ api: The ``/api`` router to mount onto.
310
+ """
311
+ for name, router in extensions.EXTENSION_ROUTERS.items():
312
+ api.include_router(router, prefix=f"{ORG_PREFIX}/ext/{name}", dependencies=[Depends(require_viewer)])
313
+ logger.info("Extension routes '%s' mounted at /api%s/ext/%s.", name, ORG_PREFIX, name)
297
314
 
298
315
 
299
316
  def _state(
300
- store: Store | None,
301
- catalog: Catalog | None,
302
- settings: Any | None,
317
+ store: Store,
318
+ catalog: Catalog,
319
+ settings: ApiSettings,
303
320
  *,
304
- agent_available: bool,
321
+ agent_model: str | None,
305
322
  google_login: GoogleLogin | None,
306
323
  ) -> State:
307
324
  """Build the state the request dependencies read back.
308
325
 
309
326
  Args:
310
- store: The ``Store`` instance, or ``None``.
311
- catalog: Catalog instance, or ``None``.
312
- settings: Full ``AppSettings``, or ``None`` for neither an
313
- authorization server nor an admin config snapshot.
314
- agent_available: Whether the agent routes mounted, recorded as a
315
- feature flag and in the admin config snapshot.
327
+ store: The ``Store`` instance.
328
+ catalog: Catalog instance.
329
+ settings: The API's settings.
330
+ agent_model: The model the mounted agent runs on, or ``None`` when
331
+ the agent routes are not mounted; recorded as a feature flag and
332
+ in the admin config snapshot.
316
333
  google_login: The Google login, already installed on the app, or
317
334
  ``None``.
318
335
 
319
336
  Returns:
320
337
  The state.
321
338
  """
322
- features = {"agent": agent_available}
339
+ features = {"agent": agent_model is not None}
323
340
  agent = None
324
- if agent_available:
325
- from interloper.settings import AgentSettings
341
+ if agent_model is not None:
326
342
  from interloper_agent import build_agent
327
343
 
328
- agent = build_agent(settings.agent.model if settings else AgentSettings().model)
329
- if settings is None:
330
- return State(store=store, catalog=catalog, agent=agent, features=features)
344
+ agent = build_agent(agent_model)
331
345
  return State(
332
346
  store=store,
333
347
  catalog=catalog,
334
348
  settings=settings,
349
+ admin_config=admin.AdminConfigResponse.from_declared(features=features, catalog=catalog),
335
350
  agent=agent,
336
351
  features=features,
337
- admin_config=admin.AdminConfigResponse.from_settings(settings, features=features, catalog=catalog),
338
352
  authorization_server=_authorization_server(store, settings),
339
353
  google_login=google_login,
340
354
  )
341
355
 
342
356
 
343
- def _google_login(settings: Any | None) -> GoogleLogin | None:
357
+ def _google_login(settings: ApiSettings) -> GoogleLogin | None:
344
358
  """Build the Google login, when the deployment can run one.
345
359
 
346
360
  Args:
347
- settings: Full ``AppSettings``, or ``None``.
361
+ settings: The API's settings.
348
362
 
349
363
  Returns:
350
- The login, or ``None`` without settings, without a Google client, or
351
- without an encryption key (which signs the cookie the login keeps
352
- between Google's two legs).
364
+ The login, or ``None`` without a Google client or without an
365
+ encryption key (which signs the cookie the login keeps between
366
+ Google's two legs).
353
367
  """
354
- if settings is None:
355
- return None
356
368
  google_login = GoogleLogin.from_settings(settings)
357
369
  if google_login is None and settings.auth.google_client_id and not settings.encryption.key:
358
370
  logger.warning("Google login unavailable: INTERLOPER_ENCRYPTION_KEY is not configured.")
359
371
  return google_login
360
372
 
361
373
 
362
- def _authorization_server(store: Store | None, settings: Any) -> AuthorizationServer | None:
374
+ def _authorization_server(store: Store, settings: ApiSettings) -> AuthorizationServer | None:
363
375
  """Build the OAuth authorization server, when the deployment can run one.
364
376
 
365
377
  Args:
366
- store: The ``Store`` instance, or ``None``.
367
- settings: Full ``AppSettings``.
378
+ store: The ``Store`` instance.
379
+ settings: The API's settings.
368
380
 
369
381
  Returns:
370
- The server, or ``None`` without a store, without an encryption key
371
- (which seals the authorization request while the user decides), or
372
- when the issuer is refused (plain http on a non-loopback host).
382
+ The server, or ``None`` without an encryption key (which seals the
383
+ authorization request while the user decides), or when the issuer is
384
+ refused (plain http on a non-loopback host).
373
385
  """
374
- if store is None:
375
- return None
376
386
  if not settings.encryption.key:
377
387
  logger.warning("OAuth authorization server not mounted: INTERLOPER_ENCRYPTION_KEY is not configured.")
378
388
  return None