refactor: replace store-based keyboard action requests with direct dispatcher and simplify agent attention clearing

This commit is contained in:
Mohamed Boudra
2026-03-06 14:49:06 +07:00
parent 885b575d14
commit 5b270444d5
25 changed files with 617 additions and 1355 deletions
+8 -25
View File
@@ -1,13 +1,12 @@
import { describe, expect, it } from "vitest";
import { shouldClearAgentAttentionOnView } from "./agent-attention";
import { shouldClearAgentAttention } from "./agent-attention";
describe("shouldClearAgentAttentionOnView", () => {
it("returns true only when the viewed agent is focused, connected, and requires attention", () => {
describe("shouldClearAgentAttention", () => {
it("returns true only when the agent is connected and requires attention", () => {
expect(
shouldClearAgentAttentionOnView({
shouldClearAgentAttention({
agentId: "agent-1",
focusedAgentId: "agent-1",
isConnected: true,
requiresAttention: true,
attentionReason: "finished",
@@ -17,9 +16,8 @@ describe("shouldClearAgentAttentionOnView", () => {
it("returns false when the app is disconnected", () => {
expect(
shouldClearAgentAttentionOnView({
shouldClearAgentAttention({
agentId: "agent-1",
focusedAgentId: "agent-1",
isConnected: false,
requiresAttention: true,
attentionReason: "finished",
@@ -27,23 +25,10 @@ describe("shouldClearAgentAttentionOnView", () => {
).toBe(false);
});
it("returns false when the agent is not focused", () => {
expect(
shouldClearAgentAttentionOnView({
agentId: "agent-1",
focusedAgentId: "agent-2",
isConnected: true,
requiresAttention: true,
attentionReason: "finished",
})
).toBe(false);
});
it("returns false when attention is already clear", () => {
expect(
shouldClearAgentAttentionOnView({
shouldClearAgentAttention({
agentId: "agent-1",
focusedAgentId: "agent-1",
isConnected: true,
requiresAttention: false,
attentionReason: null,
@@ -53,9 +38,8 @@ describe("shouldClearAgentAttentionOnView", () => {
it("returns false for empty agent ids", () => {
expect(
shouldClearAgentAttentionOnView({
shouldClearAgentAttention({
agentId: "",
focusedAgentId: "agent-1",
isConnected: true,
requiresAttention: true,
attentionReason: "finished",
@@ -65,9 +49,8 @@ describe("shouldClearAgentAttentionOnView", () => {
it("returns false for permission-shaped attention", () => {
expect(
shouldClearAgentAttentionOnView({
shouldClearAgentAttention({
agentId: "agent-1",
focusedAgentId: "agent-1",
isConnected: true,
requiresAttention: true,
attentionReason: "permission",
+4 -5
View File
@@ -1,13 +1,12 @@
interface ShouldClearAgentAttentionOnViewInput {
interface ShouldClearAgentAttentionInput {
agentId: string | null | undefined;
focusedAgentId: string | null | undefined;
isConnected: boolean;
requiresAttention: boolean | null | undefined;
attentionReason?: "finished" | "error" | "permission" | null | undefined;
}
export function shouldClearAgentAttentionOnView(
input: ShouldClearAgentAttentionOnViewInput
export function shouldClearAgentAttention(
input: ShouldClearAgentAttentionInput
): boolean {
const agentId = input.agentId?.trim();
if (!agentId) {
@@ -22,5 +21,5 @@ export function shouldClearAgentAttentionOnView(
if (input.attentionReason === "permission") {
return false;
}
return input.focusedAgentId === agentId;
return true;
}