diff --git a/docs/webui.md b/docs/webui.md index e3010056a..179a6403b 100644 --- a/docs/webui.md +++ b/docs/webui.md @@ -231,6 +231,8 @@ During a response, desktop Enter appends input to one waiting message, preservin Automatic sending continues across topic switches and short reconnects while the page stays live. Reloading, reopening, leaving the page, or the browser freezing it restores waiting content for manual sending; choose **Send now** or edit and send it when ready. +When you send a follow-up while the agent is busy, a dashed edge shows that the message is waiting for the model. The usual edge returns when the request that answers that message begins. This live hint is cleared on Stop or disconnect and is not restored from history. + For image generation, configure an image provider first and then use the WebUI image mode from the composer. See [`image-generation.md`](./image-generation.md) for provider setup and output behavior. ## Channels diff --git a/nanobot/channels/websocket/tests/test_websocket_channel.py b/nanobot/channels/websocket/tests/test_websocket_channel.py index a37de0b1f..41075043a 100644 --- a/nanobot/channels/websocket/tests/test_websocket_channel.py +++ b/nanobot/channels/websocket/tests/test_websocket_channel.py @@ -5434,6 +5434,7 @@ async def test_user_messages_fan_out_to_other_clients_on_the_same_chat( "chat_id": "shared-chat", "text": "one more detail", "starts_turn": False, + "waiting_for_model": True, "turn_id": "steer-a", "input_id": "user:steer-a", "active_turn_id": "turn-a", @@ -5446,12 +5447,13 @@ async def test_user_messages_fan_out_to_other_clients_on_the_same_chat( payload["turn_id"], payload["starts_turn"], payload["active_turn_id"], + payload.get("waiting_for_model"), ) for payload in origin_payloads if payload["event"] == "message_accepted" ] == [ - ("message_accepted", "turn-a", True, "turn-a"), - ("message_accepted", "steer-a", False, "turn-a"), + ("message_accepted", "turn-a", True, "turn-a", None), + ("message_accepted", "steer-a", False, "turn-a", True), ] outsider.send.assert_not_awaited() assert bus.publish_inbound.await_count == 2 diff --git a/nanobot/webui/inbound_commands.py b/nanobot/webui/inbound_commands.py index b5d931f4a..771ce3cbc 100644 --- a/nanobot/webui/inbound_commands.py +++ b/nanobot/webui/inbound_commands.py @@ -248,6 +248,7 @@ class WebUICommandRouter: *, turn_id: str | None, starts_turn: bool, + waiting_for_model: bool, media: list[dict[str, Any]], cli_apps: list[dict[str, Any]], mcp_presets: list[dict[str, Any]], @@ -262,6 +263,8 @@ class WebUICommandRouter: if turn_id is not None: body["turn_id"] = turn_id body["input_id"] = f"user:{turn_id}" + if waiting_for_model: + body["waiting_for_model"] = True if media: body["media_urls"] = media if cli_apps: @@ -812,6 +815,12 @@ class WebUICommandRouter: if queued_owner is not None: metadata[WEBSOCKET_TURN_OWNER_METADATA_KEY] = queued_owner + # Live presentation only: a follow-up accepted while another turn owns the chat. + waiting_for_model = ( + is_webui and temporary_policy is None and turn_id is not None + and not restart_control and not is_user_shell and not content.lstrip().startswith("/") + and queued_owner is None and websocket_turn_id(chat_id) is not None + ) accepted = False session_generation: str | None = None session_created = False @@ -905,6 +914,7 @@ class WebUICommandRouter: content, turn_id=turn_id, starts_turn=queued_owner is not None, + waiting_for_model=waiting_for_model, media=media, cli_apps=cli_apps, mcp_presets=mcp_presets, @@ -919,6 +929,7 @@ class WebUICommandRouter: chat_id=chat_id, turn_id=turn_id, starts_turn=queued_owner is not None, + **({"waiting_for_model": True} if waiting_for_model else {}), **({"media_urls": media} if media else {}), **( {"active_turn_id": active_turn_id} diff --git a/tests/agent/test_session_inputs.py b/tests/agent/test_session_inputs.py index c64bf2d99..957d08fd7 100644 --- a/tests/agent/test_session_inputs.py +++ b/tests/agent/test_session_inputs.py @@ -102,11 +102,11 @@ async def test_session_message_text_is_not_dispatched_as_a_slash_command( loop: AgentLoop, ) -> None: loop.sessions.save(loop.sessions.get_or_create("telegram:target")) - await loop._dispatch_inbound(_message("/stop")) - await asyncio.wait_for( - asyncio.gather(*loop._active_tasks["telegram:target"]), timeout=2, - ) - response = await asyncio.wait_for(loop.bus.consume_outbound(), timeout=2) + # Bound hangs without imposing a tight deadline on SQLite checkpoint writes. + async with asyncio.timeout(10): + await loop._dispatch_inbound(_message("/stop")) + await asyncio.gather(*loop._active_tasks["telegram:target"]) + response = loop.bus.outbound.get_nowait() assert response.content == "Reviewed" loop.provider.chat_stream_with_retry.assert_awaited_once() diff --git a/webui/browser/attachment-layout-fixture.tsx b/webui/browser/attachment-layout-fixture.tsx index b34f58201..a38c7b4a2 100644 --- a/webui/browser/attachment-layout-fixture.tsx +++ b/webui/browser/attachment-layout-fixture.tsx @@ -59,8 +59,16 @@ const samples: { label: string; message: UIMessage }[] = [ ]; export function AttachmentLayoutFixture() { + const processingSamples: typeof samples = (["pending", "consumed"] as const).map((status) => ({ + label: `Attachments: ${status}`, + message: { + id: `attachments-${status}`, role: "user", content: "", createdAt: 8, processingStatus: status, + media: [archive, image("Study.svg", "#83a9d8"), { kind: "video", name: "sample.webm", url: sampleVideo }], + }, + })); + const messages = new URLSearchParams(window.location.search).has("processing") ? processingSamples : samples; return
- {samples.map(({ label, message }) =>
+ {messages.map(({ label, message }) =>

{label}

)} diff --git a/webui/browser/attachment-layout.spec.ts b/webui/browser/attachment-layout.spec.ts index 11b1ca7ea..dd1db3248 100644 --- a/webui/browser/attachment-layout.spec.ts +++ b/webui/browser/attachment-layout.spec.ts @@ -150,6 +150,31 @@ for (const width of [1024, 360]) { } } +test("attachment-only pending messages keep static dashed edges in forced colors", async ({ page }) => { + await page.addInitScript(() => localStorage.setItem("nanobot.locale", "en")); + await page.emulateMedia({ forcedColors: "active", reducedMotion: "no-preference", colorScheme: "dark" }); + await page.goto("/browser/fixture.html?case=attachments&processing"); + + const solid = page.getByRole("region", { name: "Attachments: consumed" }); + const fileSurface = "[data-file-attachment] > span"; + await expect(solid.locator(fileSurface)).toHaveCSS("border-top-style", "solid"); + await expect(solid.locator("[data-pending-edge-overlay]")).toHaveCount(0); + + const region = page.getByRole("region", { name: "Attachments: pending" }); + const card = region.locator(fileSurface); + await expect(card).toHaveCSS("border-top-style", "dashed"); + await expect(card.locator("[data-pending-edge-overlay]")).toBeHidden(); + const box = await bounds(card); + expect({ width: box.width, height: box.height }).toEqual({ width: 96, height: 96 }); + const mediaEdges = region.locator('[data-solid-tone="media"] > .pending-edge-layer-dashed'); + await expect(mediaEdges).toHaveCount(2); + for (const edge of await mediaEdges.all()) { + await expect(edge).toBeVisible(); + await expect(edge).toHaveCSS("border-top-style", "dashed"); + await expect(edge).toHaveCSS("animation-name", "none"); + } +}); + test("image lightbox and file download remain keyboard accessible", async ({ page }, testInfo) => { await page.route("**/fixture/retry.webm", (route) => route.fulfill({ status: 503, body: "Temporarily unavailable" })); await openAttachments(page); diff --git a/webui/src/components/AttachmentCard.tsx b/webui/src/components/AttachmentCard.tsx index b896822f9..eff2c897b 100644 --- a/webui/src/components/AttachmentCard.tsx +++ b/webui/src/components/AttachmentCard.tsx @@ -2,6 +2,7 @@ import { useState, type ReactNode } from "react"; import { FileText, ImageIcon, Video } from "lucide-react"; import { useTranslation } from "react-i18next"; +import { PendingEdgeOverlay, type PendingEdgeState } from "@/components/PendingEdgeOverlay"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import type { UIMediaKind } from "@/lib/types"; @@ -10,12 +11,14 @@ import { cn } from "@/lib/utils"; export const attachmentCardActionClassName = "absolute right-0 top-0 grid h-11 w-11 place-items-center rounded-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"; /** The card owns only its information surface; callers own removal, download, and status. */ -export function AttachmentCard({ name, description, children, action, invalid = false }: { +export function AttachmentCard({ name, description, children, action, invalid = false, edgeState = "solid", onSealEnd }: { name: string; description?: string; children: ReactNode; action?: ReactNode; invalid?: boolean; + edgeState?: PendingEdgeState; + onSealEnd?: () => void; }) { const [detailsOpen, setDetailsOpen] = useState(false); const [hintOpen, setHintOpen] = useState(false); @@ -28,7 +31,9 @@ export function AttachmentCard({ name, description, children, action, invalid = return + diff --git a/webui/src/components/AttachmentTile.tsx b/webui/src/components/AttachmentTile.tsx index 0294f55c5..6387f24ab 100644 --- a/webui/src/components/AttachmentTile.tsx +++ b/webui/src/components/AttachmentTile.tsx @@ -8,6 +8,7 @@ import { ImageThumbnail } from "@/components/ImageGallery"; import { ImageLightbox } from "@/components/ImageLightbox"; import { useRegisterInlineImage } from "@/components/InlineImageContext"; import { AttachmentCard, AttachmentTypeFace, attachmentCardActionClassName } from "@/components/AttachmentCard"; +import { PendingEdgeOverlay, type PendingEdgeState } from "@/components/PendingEdgeOverlay"; interface AttachmentTileProps { attachment: UIMediaAttachment; @@ -15,9 +16,11 @@ interface AttachmentTileProps { inline?: boolean; variant?: "default" | "compact"; pending?: boolean; + edgeState?: PendingEdgeState; + onSealEnd?: () => void; } -export function AttachmentTile({ attachment, className, inline = false, variant = "default", pending = false }: AttachmentTileProps) { +export function AttachmentTile({ attachment, className, inline = false, variant = "default", pending = false, edgeState = "solid", onSealEnd }: AttachmentTileProps) { const { t } = useTranslation(); const videoUrl = attachment.url; const [failedUrl, setFailedUrl] = useState(undefined); @@ -31,7 +34,7 @@ export function AttachmentTile({ attachment, className, inline = false, variant return ( setImageOpen(true)} onError={() => setFailedUrl(attachment.url)} /> {}} onOpenChange={setImageOpen} /> @@ -46,6 +49,8 @@ export function AttachmentTile({ attachment, className, inline = false, variant className={className} inline={inline} variant={variant} + edgeState={edgeState} + onSealEnd={onSealEnd} >