Fix bulk actions, create chats lazily, rework the UI
Seven reported problems.
**Bulk model actions 404'd.** /admin/models/{model_id} was registered
before /admin/models/bulk, and FastAPI matches in registration order, so
"bulk" was parsed as a model id. Moved above the parameterised route,
with a comment saying why, and a regression test.
**Empty chats piled up.** There is now no endpoint that creates one.
"New chat" is a link to /chat, which renders a composer with no row
behind it, and POST /api/chats/start writes the chat together with its
first message. Opening one and walking away leaves nothing.
**Pinning meant two different things.** The picker is now always in the
administrator's position order; pinned models get shortcuts in the chat
sidebar and nothing else. A picker whose order silently differs from the
admin screen is just confusing.
**Model images were missing in chat.** Assistant bubbles now show the
avatar of the model that actually wrote the turn -- which is not always
the model the chat is set to now -- falling back to the LLeMbas mark.
The picker shows it too.
**No global or per-model system prompt.** Three layers now: instance
(Admin -> General), model (Admin -> Models), chat. Precedence, not
concatenation: most specific wins outright. Stacking them reads well in
a settings screen and badly in practice, because two layers that
disagree give the model contradictory instructions and nobody can tell
which is losing. The chat panel shows the inherited prompt as
placeholder text so "leave empty to inherit" is not a guess.
**Alignment and button sizing.** Added --control-h and friends to
tokens.css; every button, input and select takes its height from them,
so a mixed row is flush by construction rather than by per-instance
nudging. Icon buttons are square at that height. Added .btn-row,
.card__header/.card__footer and .grid so pages stop carrying inline
styles, and moved every admin page onto them.
**Settings needed structure.** The user settings page is now tabbed
(Account / Models / Appearance / Security) using radio inputs and
sibling selectors -- no JavaScript, and the browser keeps the chosen tab
across a re-render.
Caught while checking: the chat.css surgery had deleted the attachment,
chip and dropzone rules. Restored, and there is now a check that every
literal class used in a template has a CSS rule.
197 tests, ruff clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -83,6 +83,43 @@ def registered(client: TestClient) -> dict[str, str]:
|
||||
return credentials
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def make_chat(db: Session):
|
||||
"""Create a chat row directly, as scaffolding for other tests.
|
||||
|
||||
Chats are normally created by POST /api/chats/start along with their first
|
||||
exchange -- there is deliberately no endpoint that makes an empty one. Most
|
||||
tests want a chat to act on, not that flow, so they get one straight from
|
||||
the database rather than having to subtract an opening turn from every
|
||||
assertion. The flow itself is covered in test_chat.py.
|
||||
"""
|
||||
from sqlalchemy import select
|
||||
|
||||
from lembas.db.models import Chat, Model, User
|
||||
|
||||
def _create(email: str | None = None, model_id: str | None = None) -> str:
|
||||
user = (
|
||||
db.scalar(select(User).where(User.email == email))
|
||||
if email
|
||||
else db.scalars(select(User).order_by(User.created_at)).first()
|
||||
)
|
||||
model = (
|
||||
db.scalar(select(Model).where(Model.model_id == model_id))
|
||||
if model_id
|
||||
else db.scalars(select(Model).order_by(Model.position)).first()
|
||||
)
|
||||
chat = Chat(
|
||||
user_id=user.id,
|
||||
model_id=model.model_id if model else "",
|
||||
connection_id=model.connection_id if model else None,
|
||||
)
|
||||
db.add(chat)
|
||||
db.commit()
|
||||
return chat.id
|
||||
|
||||
return _create
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user_id(db: Session, registered: dict[str, str]) -> str:
|
||||
"""The registered user's id.
|
||||
|
||||
Reference in New Issue
Block a user