feat(app): focus attention-needing agent tab on workspace navigation (#828)
When navigating to a workspace, auto-open the tab for the agent that most urgently needs attention (permission > error > finished, oldest first). Adds pickAttentionAgent + wires it into navigateToWorkspace.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import type { Agent } from "@/stores/session-store";
|
||||
|
||||
interface ShouldClearAgentAttentionInput {
|
||||
agentId: string | null | undefined;
|
||||
isConnected: boolean;
|
||||
@@ -13,6 +15,47 @@ export type AgentAttentionClearTrigger =
|
||||
| "prompt-send"
|
||||
| "agent-blur";
|
||||
|
||||
const ATTENTION_REASON_PRIORITY = {
|
||||
permission: 0,
|
||||
error: 1,
|
||||
finished: 2,
|
||||
} as const;
|
||||
|
||||
function getAttentionPriority(reason: Agent["attentionReason"]): number | null {
|
||||
if (!reason) {
|
||||
return null;
|
||||
}
|
||||
return ATTENTION_REASON_PRIORITY[reason];
|
||||
}
|
||||
|
||||
export function pickAttentionAgent(agents: Agent[]): string | null {
|
||||
let selectedAgentId: string | null = null;
|
||||
let selectedPriority = Number.POSITIVE_INFINITY;
|
||||
let selectedTimestamp = Number.POSITIVE_INFINITY;
|
||||
|
||||
for (const agent of agents) {
|
||||
if (agent.requiresAttention !== true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const priority = getAttentionPriority(agent.attentionReason);
|
||||
if (priority === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const timestamp = agent.attentionTimestamp?.getTime() ?? Number.POSITIVE_INFINITY;
|
||||
const isHigherPriority = priority < selectedPriority;
|
||||
const isOlderAtSamePriority = priority === selectedPriority && timestamp < selectedTimestamp;
|
||||
if (isHigherPriority || isOlderAtSamePriority) {
|
||||
selectedAgentId = agent.id;
|
||||
selectedPriority = priority;
|
||||
selectedTimestamp = timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
return selectedAgentId;
|
||||
}
|
||||
|
||||
export function shouldClearAgentAttention(input: ShouldClearAgentAttentionInput): boolean {
|
||||
const agentId = input.agentId?.trim();
|
||||
if (!agentId) {
|
||||
|
||||
Reference in New Issue
Block a user