feat(injects,conversations,scheduler,gateway_tools,api): wake priority, master and parent aliases, scheduled injects start a turn

This commit is contained in:
hh
2026-08-30 20:34:12 +02:00
parent 064379ca90
commit a8491330fa
11 changed files with 215 additions and 47 deletions
+18 -9
View File
@@ -93,6 +93,9 @@ class JobRun:
) -> bool:
master = await self.master()
if master is None:
_log.error(
"job %s: no open master, inject lost: %s", self.job.name, text[:200]
)
return False
await self.conversations.inject(
master, text, urgency=urgency, origin=origin or self.job.name
@@ -311,9 +314,14 @@ class Scheduler:
at: str,
text: str,
*,
urgency: Priority = "normal",
urgency: Priority = "wake",
dedupe_key: str | None = None,
) -> tuple[int | None, datetime]:
"""A deferred inject.
``wake`` by default: it was promised for a time, so it starts a turn
then instead of waiting for the normal window.
"""
if self._queries is None:
msg = "scheduler needs postgres; `schedule` is unavailable"
raise RuntimeError(msg)
@@ -355,19 +363,20 @@ class Scheduler:
async def _deliver(self, job: PgJob) -> None:
data = _decode(job.payload)
conv = await self.conversations.get(str(data.get("conversation", "")))
if conv is not None and conv.status != "open" and conv.kind == "master":
masters = await self.conversations.find(
kind="master", status="open", limit=1
)
conv = masters[0] if masters else None
key = str(data.get("conversation", ""))
conv = await self.conversations.resolve(key)
if conv is None:
_log.warning("scheduled inject #%s: conversation gone", job.id)
_log.error(
"scheduled inject #%s lost: conversation %r is gone: %s",
job.id,
key,
str(data.get("text", ""))[:200],
)
return
await self.conversations.inject(
conv,
str(data.get("text", "")),
urgency=cast("Priority", data.get("urgency") or "normal"),
urgency=cast("Priority", data.get("urgency") or "wake"),
origin="schedule",
)