soliplex 0.91__tar.gz → 0.92__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 (132) hide show
  1. {soliplex-0.91/src/soliplex.egg-info → soliplex-0.92}/PKG-INFO +2 -2
  2. {soliplex-0.91 → soliplex-0.92}/pyproject.toml +2 -2
  3. {soliplex-0.91 → soliplex-0.92}/src/soliplex/agui/__init__.py +135 -1
  4. {soliplex-0.91 → soliplex-0.92}/src/soliplex/agui/persistence.py +278 -0
  5. {soliplex-0.91 → soliplex-0.92}/src/soliplex/agui/schema.py +59 -0
  6. {soliplex-0.91 → soliplex-0.92}/src/soliplex/agui/util.py +3 -0
  7. soliplex-0.92/src/soliplex/alembic_migrations/versions/98cd91f27cb5_soliplex_v0_92.py +99 -0
  8. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/completions.py +29 -3
  9. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/installation.py +30 -2
  10. soliplex-0.92/src/soliplex/cli/audit/non_local_paths.py +139 -0
  11. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/rooms.py +57 -2
  12. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/_utils.py +22 -0
  13. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/agents.py +42 -16
  14. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/exceptions.py +9 -0
  15. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/installation.py +7 -0
  16. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/rooms.py +4 -1
  17. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/routing.py +1 -0
  18. {soliplex-0.91 → soliplex-0.92}/src/soliplex/installation.py +18 -57
  19. soliplex-0.92/src/soliplex/labels.py +140 -0
  20. {soliplex-0.91 → soliplex-0.92}/src/soliplex/loggers.py +11 -0
  21. {soliplex-0.91 → soliplex-0.92}/src/soliplex/models.py +105 -0
  22. {soliplex-0.91 → soliplex-0.92}/src/soliplex/quizzes.py +3 -0
  23. {soliplex-0.91 → soliplex-0.92}/src/soliplex/titles.py +12 -4
  24. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/agui.py +158 -7
  25. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/authz.py +35 -0
  26. soliplex-0.92/src/soliplex/views/labels.py +187 -0
  27. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/rooms.py +6 -1
  28. {soliplex-0.91 → soliplex-0.92/src/soliplex.egg-info}/PKG-INFO +2 -2
  29. {soliplex-0.91 → soliplex-0.92}/src/soliplex.egg-info/SOURCES.txt +4 -0
  30. {soliplex-0.91 → soliplex-0.92}/src/soliplex.egg-info/requires.txt +1 -1
  31. {soliplex-0.91 → soliplex-0.92}/LICENSE +0 -0
  32. {soliplex-0.91 → soliplex-0.92}/MANIFEST.in +0 -0
  33. {soliplex-0.91 → soliplex-0.92}/README.md +0 -0
  34. {soliplex-0.91 → soliplex-0.92}/example/skills/bare-bones/SKILL.md +0 -0
  35. {soliplex-0.91 → soliplex-0.92}/example/skills/stanzas/SKILL.md +0 -0
  36. {soliplex-0.91 → soliplex-0.92}/setup.cfg +0 -0
  37. {soliplex-0.91 → soliplex-0.92}/skills/soliplex-docs/SKILL.md +0 -0
  38. {soliplex-0.91 → soliplex-0.92}/src/soliplex/agents.py +0 -0
  39. {soliplex-0.91 → soliplex-0.92}/src/soliplex/agui/parser.py +0 -0
  40. {soliplex-0.91 → soliplex-0.92}/src/soliplex/agui/sse_delivery.py +0 -0
  41. {soliplex-0.91 → soliplex-0.92}/src/soliplex/alembic_migrations/__init__.py +0 -0
  42. {soliplex-0.91 → soliplex-0.92}/src/soliplex/alembic_migrations/env.py +0 -0
  43. {soliplex-0.91 → soliplex-0.92}/src/soliplex/alembic_migrations/versions/216d48e1e2e5_soliplex_v0_53.py +0 -0
  44. {soliplex-0.91 → soliplex-0.92}/src/soliplex/alembic_migrations/versions/4b63e5f3f39e_soliplex_v0_51_1.py +0 -0
  45. {soliplex-0.91 → soliplex-0.92}/src/soliplex/alembic_migrations/versions/63edaa5987f6_soliplex_v0_67.py +0 -0
  46. {soliplex-0.91 → soliplex-0.92}/src/soliplex/alembic_migrations/versions/a1c7d3e90b42_soliplex_v0_80.py +0 -0
  47. {soliplex-0.91 → soliplex-0.92}/src/soliplex/alembic_migrations/versions/b7e2f41c9d05_soliplex_v0_82.py +0 -0
  48. {soliplex-0.91 → soliplex-0.92}/src/soliplex/alembic_migrations/versions/d5009d4f9874_soliplex_v0_44.py +0 -0
  49. {soliplex-0.91 → soliplex-0.92}/src/soliplex/alembic_migrations/versions/f13fea6c1953_soliplex_v0_86.py +0 -0
  50. {soliplex-0.91 → soliplex-0.92}/src/soliplex/authn.py +0 -0
  51. {soliplex-0.91 → soliplex-0.92}/src/soliplex/authz/__init__.py +0 -0
  52. {soliplex-0.91 → soliplex-0.92}/src/soliplex/authz/persistence.py +0 -0
  53. {soliplex-0.91 → soliplex-0.92}/src/soliplex/authz/schema.py +0 -0
  54. {soliplex-0.91 → soliplex-0.92}/src/soliplex/capabilities/filesystem.py +0 -0
  55. {soliplex-0.91 → soliplex-0.92}/src/soliplex/capabilities/rag_audit.py +0 -0
  56. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/admin_users.py +0 -0
  57. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/ask.py +0 -0
  58. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/__init__.py +0 -0
  59. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/_common.py +0 -0
  60. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/admin_users.py +0 -0
  61. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/databases.py +0 -0
  62. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/environment.py +0 -0
  63. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/interpolation.py +0 -0
  64. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/logfire.py +0 -0
  65. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/logging.py +0 -0
  66. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/oidc.py +0 -0
  67. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/ollama.py +0 -0
  68. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/quizzes.py +0 -0
  69. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/room_authz.py +0 -0
  70. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/secrets.py +0 -0
  71. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/audit/skills.py +0 -0
  72. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/cli_util.py +0 -0
  73. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/database.py +0 -0
  74. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/main.py +0 -0
  75. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/ollama.py +0 -0
  76. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/room_authz.py +0 -0
  77. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/serve.py +0 -0
  78. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/service_token.py +0 -0
  79. {soliplex-0.91 → soliplex-0.92}/src/soliplex/cli/types.py +0 -0
  80. {soliplex-0.91 → soliplex-0.92}/src/soliplex/completions.py +0 -0
  81. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/__init__.py +0 -0
  82. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/agui.py +0 -0
  83. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/authsystem.py +0 -0
  84. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/completions.py +0 -0
  85. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/interpolation.py +0 -0
  86. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/logfire.py +0 -0
  87. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/meta.py +0 -0
  88. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/middleware.py +0 -0
  89. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/quizzes.py +0 -0
  90. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/rag.py +0 -0
  91. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/secrets.py +0 -0
  92. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/skills.py +0 -0
  93. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/sse_delivery.py +0 -0
  94. {soliplex-0.91 → soliplex-0.92}/src/soliplex/config/tools.py +0 -0
  95. {soliplex-0.91 → soliplex-0.92}/src/soliplex/examples.py +0 -0
  96. {soliplex-0.91 → soliplex-0.92}/src/soliplex/log_ingest.py +0 -0
  97. {soliplex-0.91 → soliplex-0.92}/src/soliplex/main.py +0 -0
  98. {soliplex-0.91 → soliplex-0.92}/src/soliplex/mcp_auth.py +0 -0
  99. {soliplex-0.91 → soliplex-0.92}/src/soliplex/mcp_client.py +0 -0
  100. {soliplex-0.91 → soliplex-0.92}/src/soliplex/mcp_server.py +0 -0
  101. {soliplex-0.91 → soliplex-0.92}/src/soliplex/ollama.py +0 -0
  102. {soliplex-0.91 → soliplex-0.92}/src/soliplex/rag_audit.py +0 -0
  103. {soliplex-0.91 → soliplex-0.92}/src/soliplex/sandbox_audit.py +0 -0
  104. {soliplex-0.91 → soliplex-0.92}/src/soliplex/secrets.py +0 -0
  105. {soliplex-0.91 → soliplex-0.92}/src/soliplex/skills/bwrap_sandbox/SKILL.md +0 -0
  106. {soliplex-0.91 → soliplex-0.92}/src/soliplex/skills/bwrap_sandbox/__init__.py +0 -0
  107. {soliplex-0.91 → soliplex-0.92}/src/soliplex/token_mint.py +0 -0
  108. {soliplex-0.91 → soliplex-0.92}/src/soliplex/tools/__init__.py +0 -0
  109. {soliplex-0.91 → soliplex-0.92}/src/soliplex/tools/agui_run_feedback.py +0 -0
  110. {soliplex-0.91 → soliplex-0.92}/src/soliplex/tools/file_uploads.py +0 -0
  111. {soliplex-0.91 → soliplex-0.92}/src/soliplex/tools/rag.py +0 -0
  112. {soliplex-0.91 → soliplex-0.92}/src/soliplex/tui/cli.py +0 -0
  113. {soliplex-0.91 → soliplex-0.92}/src/soliplex/tui/main.py +0 -0
  114. {soliplex-0.91 → soliplex-0.92}/src/soliplex/tui/rest_api.py +0 -0
  115. {soliplex-0.91 → soliplex-0.92}/src/soliplex/tui/serve.py +0 -0
  116. {soliplex-0.91 → soliplex-0.92}/src/soliplex/util.py +0 -0
  117. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/__init__.py +0 -0
  118. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/authn.py +0 -0
  119. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/completions.py +0 -0
  120. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/installation.py +0 -0
  121. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/log_ingest.py +0 -0
  122. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/quizzes.py +0 -0
  123. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/room_file_uploads.py +0 -0
  124. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/sandbox_workdirs.py +0 -0
  125. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/stats.py +0 -0
  126. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/streaming.py +0 -0
  127. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/templates/consent.html.mako +0 -0
  128. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/templates/cookie-too-large.html.mako +0 -0
  129. {soliplex-0.91 → soliplex-0.92}/src/soliplex/views/thread_file_uploads.py +0 -0
  130. {soliplex-0.91 → soliplex-0.92}/src/soliplex.egg-info/dependency_links.txt +0 -0
  131. {soliplex-0.91 → soliplex-0.92}/src/soliplex.egg-info/entry_points.txt +0 -0
  132. {soliplex-0.91 → soliplex-0.92}/src/soliplex.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: soliplex
3
- Version: 0.91
3
+ Version: 0.92
4
4
  Summary: An AI-powered Retrieval-Augmented Generation (RAG) system with a modern web interface.
5
5
  Author-email: Enfold <info@enfoldsystems.net>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -20,7 +20,7 @@ Requires-Dist: fakeredis!=2.35.0
20
20
  Requires-Dist: fastapi
21
21
  Requires-Dist: fastmcp<5.0,>=4.1.2
22
22
  Requires-Dist: greenlet
23
- Requires-Dist: haiku.rag-slim<0.109,>=0.108.0
23
+ Requires-Dist: haiku.rag-slim<0.111,>=0.110.0
24
24
  Requires-Dist: idna>=3.15
25
25
  Requires-Dist: itsdangerous
26
26
  Requires-Dist: joserfc<1.8,>=1.7.5
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "soliplex"
7
- version = "0.91"
7
+ version = "0.92"
8
8
  description = "An AI-powered Retrieval-Augmented Generation (RAG) system with a modern web interface."
9
9
  authors = [{ name = "Enfold", email = "info@enfoldsystems.net" }]
10
10
  readme = "README.md"
@@ -26,7 +26,7 @@ dependencies = [
26
26
  "fastapi",
27
27
  "fastmcp >= 4.1.2, < 5.0",
28
28
  "greenlet",
29
- "haiku.rag-slim >= 0.108.0, < 0.109",
29
+ "haiku.rag-slim >= 0.110.0, < 0.111",
30
30
  "idna >= 3.15",
31
31
  "itsdangerous",
32
32
  "joserfc >= 1.7.5, < 1.8", # CVE-2026-11928{3,4}
@@ -38,6 +38,24 @@ class UnknownRun(AGUI_Exception):
38
38
  )
39
39
 
40
40
 
41
+ class UnknownLabel(AGUI_Exception):
42
+ status_code = 404
43
+
44
+ def __init__(self, label_id: int): # pragma: NO COVER
45
+ self.label_id = label_id
46
+ super().__init__(f"Unknown label: {label_id}")
47
+
48
+
49
+ class DuplicateLabel(AGUI_Exception):
50
+ status_code = 409
51
+
52
+ def __init__(self, name: str): # pragma: NO COVER
53
+ self.name = name
54
+ super().__init__(
55
+ f"A label named '{name}' already exists (label names ignore case)"
56
+ )
57
+
58
+
41
59
  class ThreadRoomMismatch(AGUI_Exception):
42
60
  def __init__(self, room_id: str, thread_room_id: str): # pragma: NO COVER
43
61
  self.room_id = room_id
@@ -229,6 +247,32 @@ class ThreadMetadata(abc.ABC):
229
247
  """Description for the thread"""
230
248
 
231
249
 
250
+ class Label(abc.ABC):
251
+ """A category which may be attached to threads
252
+
253
+ Labels are global to the installation and curated by administrators.
254
+ """
255
+
256
+ id_: int
257
+ """Unique ID for the label
258
+
259
+ Allocated per deployment, so nothing portable between installations
260
+ may key on it.
261
+ """
262
+
263
+ name: str
264
+ """Name for the label, as people read and type it"""
265
+
266
+ name_key: str
267
+ """'name' folded to lower case; label names ignore case"""
268
+
269
+ color: str
270
+ """'#RRGGBB' swatch for the label"""
271
+
272
+ created: datetime.datetime
273
+ """Timestamp"""
274
+
275
+
232
276
  class Thread(abc.ABC):
233
277
  """Hold a set of AGUI runs sharing the same 'thread_id'
234
278
 
@@ -297,6 +341,9 @@ class ThreadStorage(abc.ABC):
297
341
  room_ids: list[str],
298
342
  limit: int,
299
343
  after: ThreadPagePosition | None = None,
344
+ label_ids: list[int] = None,
345
+ unlabeled: bool = False,
346
+ name_query: str = None,
300
347
  ) -> tuple[
301
348
  list[tuple[Thread, datetime.datetime]],
302
349
  ThreadPagePosition | None,
@@ -314,12 +361,99 @@ class ThreadStorage(abc.ABC):
314
361
  start), falling back to the thread's creation for a thread with
315
362
  no runs. Each thread comes back paired with that time.
316
363
 
364
+ 'label_ids', when given, keeps only threads carrying *any* of
365
+ those labels -- the "any of" reading people know from chip
366
+ filters elsewhere. An empty list means the same as omitting it.
367
+
368
+ 'unlabeled', when true, keeps threads carrying no label at all.
369
+ It joins 'label_ids' as one more alternative: passing both keeps
370
+ threads carrying any of those labels *or* none.
371
+
372
+ 'name_query', when given, keeps only threads whose name contains
373
+ it, case-insensitively. The two filters combine: passing both
374
+ keeps threads that match the name *and* carry one of the labels.
375
+
317
376
  Paging is by position rather than by offset: 'after' is the
318
377
  position of the last thread on the previous page, and the second
319
378
  element returned is the position to pass for the next page, or
320
379
  'None' when this page is the last. A thread created, deleted or
321
380
  moved to the top by new activity between two requests therefore
322
- never shifts the rest of the listing under the reader.
381
+ never shifts the rest of the listing under the reader. The
382
+ filters must be the same on every page.
383
+ """
384
+
385
+ @abc.abstractmethod
386
+ async def list_labels(self) -> list[Label]:
387
+ """Return the installation's whole label catalogue, by name."""
388
+
389
+ @abc.abstractmethod
390
+ async def get_label_usage_counts(self) -> dict[int, int]:
391
+ """Return how many threads carry each label, keyed by label ID.
392
+
393
+ Counts span every user's threads. Labels nothing carries are
394
+ omitted.
395
+ """
396
+
397
+ @abc.abstractmethod
398
+ async def create_label(self, *, name: str, color: str = None) -> Label:
399
+ """Add a label to the catalogue and return it.
400
+
401
+ 'color' defaults to 'util.DEFAULT_LABEL_COLOR', a neutral grey.
402
+ Raises 'DuplicateLabel' if a label with that name -- ignoring
403
+ case -- already exists.
404
+ """
405
+
406
+ @abc.abstractmethod
407
+ async def update_label(
408
+ self,
409
+ *,
410
+ label_id: int,
411
+ name: str = None,
412
+ color: str = None,
413
+ ) -> Label:
414
+ """Rename and/or recolor a label, returning it.
415
+
416
+ Each of 'name' and 'color' is left alone when omitted. Raises
417
+ 'UnknownLabel' if no such label exists, or 'DuplicateLabel' if
418
+ the new name collides with another label's.
419
+ """
420
+
421
+ @abc.abstractmethod
422
+ async def delete_label(self, *, label_id: int) -> None:
423
+ """Remove a label from the catalogue.
424
+
425
+ Detaches it from every thread carrying it; the threads
426
+ themselves are untouched. Raises 'UnknownLabel' if no such label
427
+ exists.
428
+ """
429
+
430
+ @abc.abstractmethod
431
+ async def set_thread_labels(
432
+ self,
433
+ *,
434
+ user_name: str,
435
+ room_id: str,
436
+ thread_id: str,
437
+ label_ids: list[int],
438
+ ) -> Thread:
439
+ """Replace the labels carried by one of the user's threads.
440
+
441
+ Labels are only ever selected from the existing catalogue --
442
+ assigning does not create. Raises 'UnknownLabel' if any ID names
443
+ no label.
444
+ """
445
+
446
+ @abc.abstractmethod
447
+ async def get_threads_labels(
448
+ self,
449
+ *,
450
+ thread_ids: list[str],
451
+ ) -> dict[str, list[Label]]:
452
+ """Return the labels carried by each of several threads.
453
+
454
+ Keyed by thread_id (the AG-UI protocol ID); threads carrying no
455
+ labels are omitted. Batched so that listing a page of threads
456
+ costs one query rather than one per thread.
323
457
  """
324
458
 
325
459
  @abc.abstractmethod
@@ -48,6 +48,60 @@ _LAST_ACTIVITY = sqla_sql.func.max(
48
48
  )
49
49
  )
50
50
 
51
+ _LIKE_ESCAPE = "\\"
52
+
53
+
54
+ def _like_escape(value: str) -> str:
55
+ """Neutralise LIKE's wildcards in a user-supplied search term.
56
+
57
+ Without this, searching for '100%' matches every thread, '_' matches
58
+ any single character, and a trailing backslash makes the pattern
59
+ unparseable. The backslash pass has to come first, or it would
60
+ escape the escapes added after it.
61
+ """
62
+ for char in (_LIKE_ESCAPE, "%", "_"):
63
+ value = value.replace(char, _LIKE_ESCAPE + char)
64
+ return value
65
+
66
+
67
+ def _name_key(name: str) -> str:
68
+ """Fold a label name to its case-insensitive key.
69
+
70
+ 'str.lower' rather than 'str.casefold': the clients fold with
71
+ JavaScript/Dart 'toLowerCase', and casefold disagrees with those on
72
+ characters such as 'ss', which would let a name look free in the
73
+ autocomplete and then collide on save.
74
+ """
75
+ return name.lower()
76
+
77
+
78
+ # SQLite's built-in 'lower()' folds only ASCII, so on SQLite the name
79
+ # search calls this Python fold instead, registered on the connection.
80
+ _SQLITE_LOWER = "soliplex_lower"
81
+
82
+
83
+ def _sqlite_lower(value: str | None) -> str | None:
84
+ return None if value is None else value.lower()
85
+
86
+
87
+ async def _name_fold(session):
88
+ """Return the SQL function that folds a name as 'str.lower' does.
89
+
90
+ On PostgreSQL that is 'lower()', which folds by the database's
91
+ 'LC_CTYPE': under the 'C' or 'POSIX' locale it folds only ASCII, as
92
+ SQLite's built-in does, so a non-ASCII search is then case-sensitive.
93
+ """
94
+ connection = await session.connection()
95
+
96
+ if connection.dialect.name != "sqlite":
97
+ return sqla_sql.func.lower
98
+
99
+ raw = await connection.get_raw_connection()
100
+ await raw.driver_connection.create_function(
101
+ _SQLITE_LOWER, 1, _sqlite_lower, deterministic=True
102
+ )
103
+ return getattr(sqla_sql.func, _SQLITE_LOWER)
104
+
51
105
 
52
106
  class ThreadStorage(agui.ThreadStorage):
53
107
  def __init__(self, session: sqla_asyncio.AsyncSession):
@@ -132,6 +186,9 @@ class ThreadStorage(agui.ThreadStorage):
132
186
  room_ids: list[str],
133
187
  limit: int,
134
188
  after: agui.ThreadPagePosition | None = None,
189
+ label_ids: list[int] = None,
190
+ unlabeled: bool = False,
191
+ name_query: str = None,
135
192
  ) -> tuple[
136
193
  list[tuple[agui_schema.Thread, datetime.datetime]],
137
194
  agui.ThreadPagePosition | None,
@@ -175,6 +232,64 @@ class ThreadStorage(agui.ThreadStorage):
175
232
  .where(agui_schema.Thread.room_id.in_(room_ids))
176
233
  )
177
234
 
235
+ def carries(*conditions):
236
+ # A semi-join, not 'JOIN ... DISTINCT': joining the
237
+ # association multiplies a thread by however many of the
238
+ # requested labels it carries, which corrupts LIMIT. The
239
+ # usual 'DISTINCT' repair does not fit either --
240
+ # PostgreSQL requires every ORDER BY expression in the
241
+ # select list, and the ordering below is a computed one.
242
+ # EXISTS multiplies nothing.
243
+ return (
244
+ sqla_sql.select(sqla_sql.literal(1))
245
+ .select_from(agui_schema.ThreadLabel)
246
+ .where(
247
+ agui_schema.ThreadLabel.thread_id_
248
+ == agui_schema.Thread.id_,
249
+ *conditions,
250
+ )
251
+ # Correlate explicitly: left to itself SQLAlchemy
252
+ # correlates away every table the outer query also
253
+ # selects from, which can leave the subquery with no
254
+ # FROM clause at all.
255
+ .correlate(agui_schema.Thread)
256
+ .exists()
257
+ )
258
+
259
+ # Both read as alternatives, so passing both widens rather
260
+ # than narrows: carrying one of the labels, *or* none at all.
261
+ label_filters = []
262
+ if label_ids:
263
+ label_filters.append(
264
+ carries(
265
+ agui_schema.ThreadLabel.label_id_.in_(label_ids),
266
+ )
267
+ )
268
+ if unlabeled:
269
+ label_filters.append(~carries())
270
+ if label_filters:
271
+ query = query.where(sqla_sql.or_(*label_filters))
272
+
273
+ if name_query:
274
+ # Correlated rather than joined to 'thread_metadata',
275
+ # which is optional: a never-titled thread has no row,
276
+ # and must still appear in an unfiltered listing.
277
+ fold = await _name_fold(session)
278
+ pattern = f"%{_like_escape(name_query).lower()}%"
279
+ query = query.where(
280
+ sqla_sql.select(sqla_sql.literal(1))
281
+ .select_from(agui_schema.ThreadMetadata)
282
+ .where(
283
+ agui_schema.ThreadMetadata.thread_id_
284
+ == agui_schema.Thread.id_,
285
+ fold(agui_schema.ThreadMetadata.name).like(
286
+ pattern, escape=_LIKE_ESCAPE
287
+ ),
288
+ )
289
+ .correlate(agui_schema.Thread)
290
+ .exists()
291
+ )
292
+
178
293
  if after is not None:
179
294
  # Strictly past the previous page's last thread in the
180
295
  # same order the page is sorted in; spelled out rather
@@ -279,6 +394,169 @@ class ThreadStorage(agui.ThreadStorage):
279
394
  rows = (await session.execute(query)).all()
280
395
  return {thread_id: _as_utc(activity) for thread_id, activity in rows}
281
396
 
397
+ async def _find_label(self, *, label_id: int, session):
398
+ label = await session.get(agui_schema.Label, label_id)
399
+
400
+ if label is None:
401
+ raise agui.UnknownLabel(label_id)
402
+
403
+ return label
404
+
405
+ async def _flush_label(self, *, name: str, session):
406
+ """Flush a label write, raising 'DuplicateLabel' on a name clash.
407
+
408
+ The unique constraint on 'name_key' is the only check, so two
409
+ concurrent writes of one name cannot both pass it.
410
+ """
411
+ try:
412
+ await session.flush()
413
+ except sqla_exc.IntegrityError:
414
+ raise agui.DuplicateLabel(name) from None
415
+
416
+ async def list_labels(self) -> list[agui_schema.Label]:
417
+ async with self.session as session:
418
+ query = sqla_sql.select(agui_schema.Label).order_by(
419
+ agui_schema.Label.name_key
420
+ )
421
+ labels = list(await session.scalars(query))
422
+
423
+ return labels
424
+
425
+ async def get_label_usage_counts(self) -> dict[int, int]:
426
+ async with self.session as session:
427
+ query = sqla_sql.select(
428
+ agui_schema.ThreadLabel.label_id_,
429
+ sqla_sql.func.count(),
430
+ ).group_by(agui_schema.ThreadLabel.label_id_)
431
+ rows = (await session.execute(query)).all()
432
+
433
+ return {label_id: count for label_id, count in rows}
434
+
435
+ async def create_label(
436
+ self,
437
+ *,
438
+ name: str,
439
+ color: str = None,
440
+ ) -> agui_schema.Label:
441
+ async with self.session as session:
442
+ label = agui_schema.Label(
443
+ name=name,
444
+ name_key=_name_key(name),
445
+ color=(
446
+ color
447
+ if color is not None
448
+ else agui_util.DEFAULT_LABEL_COLOR
449
+ ),
450
+ )
451
+ session.add(label)
452
+ await self._flush_label(name=name, session=session)
453
+
454
+ return label
455
+
456
+ async def update_label(
457
+ self,
458
+ *,
459
+ label_id: int,
460
+ name: str = None,
461
+ color: str = None,
462
+ ) -> agui_schema.Label:
463
+ async with self.session as session:
464
+ label = await self._find_label(
465
+ label_id=label_id,
466
+ session=session,
467
+ )
468
+
469
+ if name is not None:
470
+ label.name = name
471
+ label.name_key = _name_key(name)
472
+
473
+ if color is not None:
474
+ label.color = color
475
+
476
+ await self._flush_label(name=label.name, session=session)
477
+
478
+ return label
479
+
480
+ async def delete_label(self, *, label_id: int) -> None:
481
+ async with self.session as session:
482
+ label = await self._find_label(
483
+ label_id=label_id,
484
+ session=session,
485
+ )
486
+ await session.delete(label)
487
+
488
+ async def set_thread_labels(
489
+ self,
490
+ *,
491
+ user_name: str,
492
+ room_id: str,
493
+ thread_id: str,
494
+ label_ids: list[int],
495
+ ) -> agui_schema.Thread:
496
+ async with self.session as session:
497
+ thread = await self._find_user_thread(
498
+ user_name=user_name,
499
+ room_id=room_id,
500
+ thread_id=thread_id,
501
+ session=session,
502
+ )
503
+
504
+ labels = [
505
+ await self._find_label(label_id=label_id, session=session)
506
+ for label_id in dict.fromkeys(label_ids)
507
+ ]
508
+
509
+ # Load before assigning: under 'AsyncSession' the collection
510
+ # is lazy, and replacing it without awaiting it first raises
511
+ # 'MissingGreenlet' as SQLAlchemy tries to fetch the old
512
+ # contents from inside the assignment.
513
+ await thread.awaitable_attrs.labels
514
+ thread.labels = labels
515
+
516
+ # Reload so the caller sees the relationship's order, as a
517
+ # later read would, rather than the order of 'label_ids'.
518
+ await session.flush()
519
+ await session.refresh(thread, attribute_names=["labels"])
520
+
521
+ return thread
522
+
523
+ async def get_threads_labels(
524
+ self,
525
+ *,
526
+ thread_ids: list[str],
527
+ ) -> dict[str, list[agui_schema.Label]]:
528
+ thread_ids = list(thread_ids)
529
+
530
+ if not thread_ids:
531
+ return {}
532
+
533
+ async with self.session as session:
534
+ query = (
535
+ sqla_sql.select(
536
+ agui_schema.Thread.thread_id,
537
+ agui_schema.Label,
538
+ )
539
+ .join(
540
+ agui_schema.ThreadLabel,
541
+ agui_schema.ThreadLabel.thread_id_
542
+ == agui_schema.Thread.id_,
543
+ )
544
+ .join(
545
+ agui_schema.Label,
546
+ agui_schema.Label.id_ == agui_schema.ThreadLabel.label_id_,
547
+ )
548
+ .where(agui_schema.Thread.thread_id.in_(thread_ids))
549
+ .order_by(agui_schema.Label.name_key)
550
+ )
551
+ rows = (await session.execute(query)).all()
552
+
553
+ found: dict[str, list[agui_schema.Label]] = {}
554
+
555
+ for thread_id, label in rows:
556
+ found.setdefault(thread_id, []).append(label)
557
+
558
+ return found
559
+
282
560
  async def new_thread(
283
561
  self,
284
562
  *,
@@ -101,6 +101,14 @@ class Thread(Base):
101
101
  passive_deletes=True,
102
102
  )
103
103
 
104
+ # One-way: 'Label' has no 'threads' collection. 'passive_deletes'
105
+ # leaves the association rows to the database's 'ON DELETE CASCADE'.
106
+ labels: Mapped[list[Label]] = relationship(
107
+ secondary="thread_label",
108
+ order_by="Label.name_key",
109
+ passive_deletes=True,
110
+ )
111
+
104
112
  async def list_runs(self):
105
113
  runs = []
106
114
 
@@ -143,6 +151,57 @@ class ThreadMetadata(Base):
143
151
  description: Mapped[str | None] = mapped_column()
144
152
 
145
153
 
154
+ class Label(Base):
155
+ """A category which may be attached to threads.
156
+
157
+ Labels are global to the installation -- one namespace shared by
158
+ every room -- and are curated by administrators; ordinary users may
159
+ only attach existing ones to their own threads.
160
+
161
+ 'name' is what people read and type; 'name_key' is that name folded
162
+ to lower case and carries the uniqueness constraint, so 'Urgent' and
163
+ 'urgent' are the same label.
164
+
165
+ 'color' is a '#RRGGBB' string, defaulting to the neutral grey in
166
+ 'agui.util.DEFAULT_LABEL_COLOR' and thereafter editable.
167
+ """
168
+
169
+ __tablename__ = "label"
170
+
171
+ # Without AUTOINCREMENT, SQLite reuses 'max(id) + 1', so a new label
172
+ # could take a deleted one's ID and a stale client catalogue would
173
+ # paint the wrong chip. No-op on PostgreSQL.
174
+ __table_args__ = {"sqlite_autoincrement": True}
175
+
176
+ id_: Mapped[int] = mapped_column(primary_key=True)
177
+ created: Mapped[datetime.datetime] = mapped_column(
178
+ sqla_sqltypes.TIMESTAMP(timezone=True),
179
+ default=agui_util._timestamp,
180
+ )
181
+
182
+ name: Mapped[str] = mapped_column()
183
+ name_key: Mapped[str] = mapped_column(unique=True)
184
+ color: Mapped[str] = mapped_column()
185
+
186
+
187
+ class ThreadLabel(Base):
188
+ """Associate a 'Thread' with a 'Label' it carries."""
189
+
190
+ __tablename__ = "thread_label"
191
+
192
+ thread_id_: Mapped[int] = mapped_column(
193
+ ForeignKey("thread.id_", ondelete="CASCADE"),
194
+ primary_key=True,
195
+ )
196
+ # The composite primary key does not serve lookups by label alone,
197
+ # which the label filter and the usage count both make.
198
+ label_id_: Mapped[int] = mapped_column(
199
+ ForeignKey("label.id_", ondelete="CASCADE"),
200
+ primary_key=True,
201
+ index=True,
202
+ )
203
+
204
+
146
205
  class Run(Base):
147
206
  """Hold information about an AG-UI runs.
148
207
 
@@ -1,6 +1,9 @@
1
1
  import datetime
2
2
  import uuid
3
3
 
4
+ # The neutral grey a label carries until someone colors it.
5
+ DEFAULT_LABEL_COLOR = "#808080"
6
+
4
7
 
5
8
  def _make_uuid_str() -> str:
6
9
  return str(uuid.uuid4())
@@ -0,0 +1,99 @@
1
+ """soliplex-v0.92
2
+
3
+ Threads: add the label catalogue, 'Label' and 'ThreadLabel'
4
+
5
+ Revision ID: 98cd91f27cb5
6
+ Revises: f13fea6c1953
7
+ Create Date: 2026-08-14 17:30:32.840043
8
+
9
+ """
10
+
11
+ import typing
12
+
13
+ import sqlalchemy as sa
14
+ from alembic import op
15
+
16
+ # revision identifiers, used by Alembic.
17
+ revision: str = "98cd91f27cb5"
18
+ down_revision: str | typing.Sequence[str] | None = "f13fea6c1953"
19
+ branch_labels: str | typing.Sequence[str] | None = None
20
+ depends_on: str | typing.Sequence[str] | None = None
21
+
22
+
23
+ def upgrade(engine_name: str) -> None:
24
+ """Upgrade schema."""
25
+ globals()[f"upgrade_{engine_name}"]()
26
+
27
+
28
+ def downgrade(engine_name: str) -> None:
29
+ """Downgrade schema."""
30
+ globals()[f"downgrade_{engine_name}"]()
31
+
32
+
33
+ def upgrade_agui() -> None:
34
+ """Upgrade agui schema."""
35
+ # ### commands auto generated by Alembic - please adjust! ###
36
+ op.create_table(
37
+ "label",
38
+ sa.Column("id_", sa.Integer(), nullable=False),
39
+ sa.Column("created", sa.TIMESTAMP(timezone=True), nullable=False),
40
+ sa.Column("name", sa.String(), nullable=False),
41
+ sa.Column("name_key", sa.String(), nullable=False),
42
+ sa.Column("color", sa.String(), nullable=False),
43
+ sa.PrimaryKeyConstraint("id_", name=op.f("pk_label")),
44
+ sa.UniqueConstraint("name_key", name=op.f("uq_label_name_key")),
45
+ # Matches 'Label.__table_args__': without it SQLite reuses
46
+ # 'max(id) + 1', so a new label can inherit a deleted one's ID
47
+ # and any stale client catalogue would then paint the wrong chip.
48
+ sqlite_autoincrement=True,
49
+ )
50
+ op.create_table(
51
+ "thread_label",
52
+ sa.Column("thread_id_", sa.Integer(), nullable=False),
53
+ sa.Column("label_id_", sa.Integer(), nullable=False),
54
+ sa.ForeignKeyConstraint(
55
+ ["label_id_"],
56
+ ["label.id_"],
57
+ name=op.f("fk_thread_label_label_id__label"),
58
+ ondelete="CASCADE",
59
+ ),
60
+ sa.ForeignKeyConstraint(
61
+ ["thread_id_"],
62
+ ["thread.id_"],
63
+ name=op.f("fk_thread_label_thread_id__thread"),
64
+ ondelete="CASCADE",
65
+ ),
66
+ sa.PrimaryKeyConstraint(
67
+ "thread_id_", "label_id_", name=op.f("pk_thread_label")
68
+ ),
69
+ )
70
+ op.create_index(
71
+ op.f("ix_thread_label_label_id_"),
72
+ "thread_label",
73
+ ["label_id_"],
74
+ unique=False,
75
+ )
76
+ # ### end Alembic commands ###
77
+
78
+
79
+ def downgrade_agui() -> None:
80
+ """Downgrade agui schema."""
81
+ # ### commands auto generated by Alembic - please adjust! ###
82
+ op.drop_index(op.f("ix_thread_label_label_id_"), table_name="thread_label")
83
+ op.drop_table("thread_label")
84
+ op.drop_table("label")
85
+ # ### end Alembic commands ###
86
+
87
+
88
+ def upgrade_authz() -> None:
89
+ """Upgrade authz schema."""
90
+ # ### commands auto generated by Alembic - please adjust! ###
91
+ pass
92
+ # ### end Alembic commands ###
93
+
94
+
95
+ def downgrade_authz() -> None:
96
+ """Downgrade authz schema."""
97
+ # ### commands auto generated by Alembic - please adjust! ###
98
+ pass
99
+ # ### end Alembic commands ###