fix(webui): show per-run automation replies and simplify details
This commit is contained in:
1 parent
e7da868574
commit
037438e7d1
28 files changed
+985
-183
No files matched your search
@@ -12,7 +12,7 @@ from nanobot.agent.tools.cron import CronTool
|
||||
from nanobot.bus.events import InboundMessage, OutboundMessage
|
||||
from nanobot.cron.session_delivery import origin_delivery_context
|
||||
from nanobot.cron.session_turns import CRON_DEFER_UNTIL_IDLE_META, CRON_TRIGGER_META
|
||||
from nanobot.cron.types import CronJob
|
||||
from nanobot.cron.types import CronJob, CronRunResult
|
||||
from nanobot.cron.webui_metadata import cron_proactive_delivery_metadata
|
||||
from nanobot.utils.prompt_templates import render_template
|
||||
|
||||
@@ -67,7 +67,7 @@ async def run_bound_cron_job(
|
||||
*,
|
||||
agent: BoundCronAgent,
|
||||
cron: CronRunRecorder,
|
||||
) -> str | None:
|
||||
) -> CronRunResult:
|
||||
"""Execute a session-bound cron job as a normal agent session turn."""
|
||||
session_key = job.payload.session_key
|
||||
if not session_key:
|
||||
@@ -151,4 +151,4 @@ async def run_bound_cron_job(
|
||||
"response": response,
|
||||
},
|
||||
)
|
||||
return response
|
||||
return CronRunResult(run_id=run_id, response=response)
|
||||
@@ -22,6 +22,7 @@ from nanobot.cron.types import (
|
||||
CronJobState,
|
||||
CronPayload,
|
||||
CronRunRecord,
|
||||
CronRunResult,
|
||||
CronSchedule,
|
||||
CronStore,
|
||||
)
|
||||
@@ -176,7 +177,7 @@ class CronService:
|
||||
def __init__(
|
||||
self,
|
||||
store_path: Path,
|
||||
on_job: Callable[[CronJob], Coroutine[Any, Any, str | None]] | None = None,
|
||||
on_job: Callable[[CronJob], Coroutine[Any, Any, str | CronRunResult | None]] | None = None,
|
||||
max_sleep_ms: int = 300_000, # 5 minutes
|
||||
):
|
||||
self.store_path = store_path
|
||||
@@ -413,6 +414,7 @@ class CronService:
|
||||
"status": r.status,
|
||||
"durationMs": r.duration_ms,
|
||||
"error": r.error,
|
||||
"runId": r.run_id,
|
||||
}
|
||||
for r in j.state.run_history
|
||||
],
|
||||
@@ -586,10 +588,11 @@ class CronService:
|
||||
"""Execute a single job."""
|
||||
start_ms = _now_ms()
|
||||
logger.info("Cron: executing job '{}' ({})", job.name, job.id)
|
||||
result: str | CronRunResult | None = None
|
||||
|
||||
try:
|
||||
if self.on_job:
|
||||
await self.on_job(job)
|
||||
result = await self.on_job(job)
|
||||
|
||||
job.state.last_status = "ok"
|
||||
job.state.last_error = None
|
||||
@@ -620,6 +623,7 @@ class CronService:
|
||||
status=job.state.last_status,
|
||||
duration_ms=end_ms - start_ms,
|
||||
error=job.state.last_error,
|
||||
run_id=result.run_id if isinstance(result, CronRunResult) else None,
|
||||
))
|
||||
job.state.run_history = job.state.run_history[-self._MAX_RUN_HISTORY:]
|
||||
|
||||
|
||||
@@ -82,6 +82,14 @@ class CronPayload:
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class CronRunResult:
|
||||
"""Result and durable record identity returned by a cron executor."""
|
||||
|
||||
run_id: str
|
||||
response: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class CronRunRecord:
|
||||
"""A single execution record for a cron job."""
|
||||
@@ -89,14 +97,17 @@ class CronRunRecord:
|
||||
status: Literal["ok", "error", "skipped"]
|
||||
duration_ms: int = 0
|
||||
error: str | None = None
|
||||
run_id: str | None = None
|
||||
|
||||
@classmethod
|
||||
def from_store_dict(cls, data: dict[str, Any]) -> CronRunRecord:
|
||||
run_id = get_camel_snake(data, "runId", "run_id")
|
||||
return cls(
|
||||
run_at_ms=_store_int(get_camel_snake(data, "runAtMs", "run_at_ms", 0)),
|
||||
status=data["status"],
|
||||
duration_ms=_store_int(get_camel_snake(data, "durationMs", "duration_ms", 0)),
|
||||
error=data.get("error"),
|
||||
run_id=run_id if isinstance(run_id, str) else None,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user