fix(webui): link automation history to the recorded chat
This commit is contained in:
1 parent
c932720b20
commit
5719ed6e16
6 files changed
+42
-11
No files matched your search
@@ -14,6 +14,7 @@ from nanobot.session.manager import (
|
||||
_metadata_title, # pyright: ignore[reportPrivateUsage]
|
||||
)
|
||||
from nanobot.triggers.local_types import LocalTrigger
|
||||
from nanobot.webui.session_identity import is_webui_session_key
|
||||
|
||||
AutomationJob = CronJob | LocalTrigger
|
||||
|
||||
@@ -176,19 +177,21 @@ def _serialize_job(
|
||||
payload["created_at_ms"] = job.created_at_ms
|
||||
payload["updated_at_ms"] = job.updated_at_ms
|
||||
payload["payload"].update({"kind": job.payload.kind})
|
||||
run_history: list[dict[str, Any]] = []
|
||||
for record in job.state.run_history[-5:]:
|
||||
session_key = record.session_key or job.payload.session_key or ""
|
||||
run_history.append({
|
||||
"run_at_ms": record.run_at_ms,
|
||||
"status": record.status,
|
||||
"duration_ms": record.duration_ms,
|
||||
"error": record.error,
|
||||
"webui_session_key": session_key if is_webui_session_key(session_key) else None,
|
||||
})
|
||||
payload["state"].update(
|
||||
{
|
||||
"last_run_at_ms": job.state.last_run_at_ms,
|
||||
"last_error": job.state.last_error,
|
||||
"run_history": [
|
||||
{
|
||||
"run_at_ms": record.run_at_ms,
|
||||
"status": record.status,
|
||||
"duration_ms": record.duration_ms,
|
||||
"error": record.error,
|
||||
}
|
||||
for record in job.state.run_history[-5:]
|
||||
],
|
||||
"run_history": run_history,
|
||||
}
|
||||
)
|
||||
payload["origin"] = _origin_payload(job, session_manager)
|
||||
|
||||
@@ -24,6 +24,7 @@ from nanobot.session.manager import SessionManager
|
||||
from nanobot.webui.automation_chats import automation_chats
|
||||
from nanobot.webui.automation_results import cron_run_response
|
||||
from nanobot.webui.gateway_services import build_gateway_services
|
||||
from nanobot.webui.session_automations import serialize_automation_jobs
|
||||
from nanobot.webui.workspaces import WebUIWorkspaceController
|
||||
|
||||
|
||||
@@ -277,6 +278,13 @@ async def test_real_gateway_move_run_reload_and_previous_result(tmp_path):
|
||||
moved = CronService(cron.store_path).get_job(job.id)
|
||||
for run in moved.state.run_history:
|
||||
assert cron_run_response(cron.store_path.parent / "runs", moved, run) == "Synthetic result"
|
||||
history = serialize_automation_jobs([moved], include_details=True)[0]["state"]["run_history"]
|
||||
assert [run["webui_session_key"] for run in history] == ["websocket:source", None]
|
||||
cron.change_binding(job.id, revision=binding_revision(moved),
|
||||
binding=CronBinding("websocket:source", "websocket", "source", {}), message="Back")
|
||||
# Moving back must not turn the external run's link into the current chat.
|
||||
history = serialize_automation_jobs([cron.get_job(job.id)], include_details=True)[0]["state"]["run_history"]
|
||||
assert [run["webui_session_key"] for run in history] == ["websocket:source", None]
|
||||
finally:
|
||||
if client is not None:
|
||||
await client.close()
|
||||
|
||||
@@ -41,6 +41,8 @@ is pending, so the PR remains a draft.
|
||||
- Each run retains its session identity. Before the first supported move, older
|
||||
run records are stamped with the known unchanged original binding. Audit result
|
||||
checks still verify job, run, session, status, and file path.
|
||||
History links use that run's WebUI chat key, not the task's current chat.
|
||||
External runs expose no recipient key and have no WebUI chat link.
|
||||
|
||||
No new execution path, agent-loop policy, dependencies, or separate CSS system
|
||||
are added. The dialog uses the existing Select, Dialog, Button, Textarea, channel
|
||||
|
||||
@@ -56,8 +56,9 @@ export function AutomationRunDialog({ token = "", job, run, locale, open, onOpen
|
||||
: run.status === "skipped" ? t("settings.automations.skipped")
|
||||
: t("settings.automations.calendar.recorded");
|
||||
const duration = run.duration_ms;
|
||||
const chatHref = job.origin?.channel === "websocket" && job.origin.session_key
|
||||
? `#/chat/${encodeURIComponent(job.origin.session_key)}` : null;
|
||||
const chatKey = run.webui_session_key !== undefined ? run.webui_session_key
|
||||
: job.origin?.channel === "websocket" ? job.origin.session_key : null;
|
||||
const chatHref = chatKey ? `#/chat/${encodeURIComponent(chatKey)}` : null;
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
|
||||
@@ -252,6 +252,7 @@ export interface SessionAutomationJob {
|
||||
status: "ok" | "error" | "skipped" | string;
|
||||
duration_ms?: number;
|
||||
error?: string | null;
|
||||
webui_session_key?: string | null; // null: external chat; absent: older host.
|
||||
}>;
|
||||
};
|
||||
origin?: {
|
||||
|
||||
@@ -323,6 +323,22 @@ describe("Automation task list and detail sheet", () => {
|
||||
expect(within(screen.getByRole("dialog", { name: "PR watch" })).getByRole("button", { name: "Edit" })).toBeVisible();
|
||||
});
|
||||
|
||||
it.each(["websocket:original-chat", null])("uses the recorded chat for a historical run (%s), not the task's current chat", async (webuiSessionKey) => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness payload={{ jobs: [{ ...task, state: { run_history: [{
|
||||
run_at_ms: now - 60_000, status: "ok", webui_session_key: webuiSessionKey,
|
||||
}] } }] }} />);
|
||||
await user.click(screen.getByRole("button", { name: /PR watch.*Completed/ }));
|
||||
const dialog = within(screen.getByRole("dialog", { name: "PR watch" }));
|
||||
if (webuiSessionKey) {
|
||||
expect(dialog.getByRole("link", { name: "Open a chat" })).toHaveAttribute(
|
||||
"href", "#/chat/websocket%3Aoriginal-chat",
|
||||
);
|
||||
} else {
|
||||
expect(dialog.queryByRole("link", { name: "Open a chat" })).not.toBeInTheDocument();
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps the selected historical result across refreshes and restores focus when its day button disappears", async () => {
|
||||
const user = userEvent.setup();
|
||||
const start = new Date(new Date(now).setHours(8, 0, 0, 0)).getTime();
|
||||
|
||||
Reference in new issue
Block a user