Files
multica/packages
Naiyuan Qing 274b342db6 fix(chat): handle unavailable agent end-to-end
Previously several failure modes leaked through silently:
- Workspace with no agents → input still writable, send did nothing
- Session's agent archived → the fallback avatar UI disagreed with
  what the session was actually bound to; send then threw in the
  console with no user feedback
- Any backend send failure (archived, no runtime, …) → no toast

Replaces the ad-hoc `activeAgent` with a derived `agentState`:

  { agent: Agent | null, canSend: boolean, reason?: "no_agents"
    | "archived" | "missing" }

Priority when resolving:
1. If a session is active, bind to its agent from the FULL agent list
   (so archived agents are still rendered, read-only).
2. Otherwise pick the preferred agent from available ones, falling
   back to first-available or null.

UI consumes it uniformly:
- Input is disabled whenever canSend is false
- Placeholder explains why (archived / no agents / missing)
- Empty state replaces starter prompts with a "create an agent" hint
  when the workspace has none
- handleSend wraps the API call in try/catch and surfaces the error
  via sonner; optimistic user bubble is cleared on failure

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 19:06:47 +08:00
..