Merge branch 'worktree-agent-a8ed2a864305c4381'

# Conflicts:
#	app/web/api.py
This commit is contained in:
Wolf committed 2026-09-25 22:03:19 +02:00
commit fe83330c82
8 files changed
+418 -319

No files matched your search

+33 -9
View File
@@ -17,7 +17,7 @@ from pydantic import BaseModel, Field
from app import jobs
from app.models import (
AFFINITY, Agent, Application, Company, Gate, Role, ScoredRole, Status, Subscription,
Weights,
Weights, company_key,
)
from app.storage import Store
from app.web.deps import ConfigDep, StoreDep
@@ -173,23 +173,43 @@ def summarise_role(uid: str, store: StoreDep, config: ConfigDep, queue: QueueDep
# --------------------------------------------------------------- companies
class CompanyOut(BaseModel):
"""A company row plus the two things only the store can join in: the ats
host it is read from, and how many of its roles are still open."""
"""A company row plus what only the store can join in: the ats host it is
read from (empty for a company known only from a search), the id of that
board's subscription, whether it is on, and how many of its roles are
still open."""
key: str
name: str
board: str
subscription_id: int | None = None
on: bool | None = None
affinity: int
open_roles: int
def _company_boards(store: Store) -> dict[str, tuple[int, str, bool]]:
"""`company_key -> (subscription id, ats host, on)`, read off each
company's own subscription. Same join as `Store.company_boards`, with the
id and switch state a company row needs to draw its own on/off control
rather than fetching `/api/sources` as well."""
boards: dict[str, tuple[int, str, bool]] = {}
for sub in store.subscriptions(source="ats"):
boards.setdefault(company_key(sub.company), (sub.id, sub.board,
bool(sub.subscribed and sub.fetch)))
return boards
@router.get("/companies")
def list_companies(store: StoreDep) -> list[CompanyOut]:
boards = store.company_boards()
boards = _company_boards(store)
counts = store.open_role_counts()
return [CompanyOut(key=c.key, name=c.name, board=boards.get(c.key, ""),
affinity=c.affinity, open_roles=counts.get(c.key, 0))
for c in store.companies()]
out = []
for c in store.companies():
sub_id, host, on = boards.get(c.key, (None, "", None))
out.append(CompanyOut(key=c.key, name=c.name, board=host,
subscription_id=sub_id, on=on, affinity=c.affinity,
open_roles=counts.get(c.key, 0)))
return out
class AffinityBody(BaseModel):
@@ -197,13 +217,17 @@ class AffinityBody(BaseModel):
@router.post("/companies/{key}/affinity")
def set_affinity(key: str, body: AffinityBody, store: StoreDep) -> Company:
def set_affinity(key: str, body: AffinityBody, store: StoreDep, queue: QueueDep) -> Company:
"""A change here is not seen in Best match until `score` has run: the
queue dedupes to a live job of that kind, so several clicks are one run."""
if body.affinity not in AFFINITY:
raise HTTPException(422, "affinity is -1, 0, 1 or 2")
try:
return store.update_company(key, affinity=body.affinity)
company = store.update_company(key, affinity=body.affinity)
except KeyError:
raise HTTPException(404, f"no such company: {key}") from None
queue.enqueue("score")
return company
# ----------------------------------------------------------------- sources