Human-facing task state
This commit is contained in:
+20
-6
@@ -84,15 +84,29 @@ export function currentSession(taskId: string): AgentSession | undefined {
|
||||
return state.sessions.get(taskId)?.findLast((s) => s.state !== "completed") ?? state.sessions.get(taskId)?.at(-1);
|
||||
}
|
||||
|
||||
export function taskState(task: Task): string | undefined {
|
||||
if (task.discarding) {
|
||||
return "discarding";
|
||||
export type TaskState = { kind: "answer" | "merging" | "held" | "error" | "working" | "idle"; label: string; title: string };
|
||||
|
||||
export function taskState(task: Task): TaskState {
|
||||
const open = state.inbox.filter((item) => item.task_id === task.id);
|
||||
if (open.some((item) => item.kind === "question")) {
|
||||
return { kind: "answer", label: "Needs your answer", title: "The agent asked a question in the inbox" };
|
||||
}
|
||||
if (task.merging) {
|
||||
return "merging";
|
||||
return { kind: "merging", label: "Merging", title: "The merge turn is running" };
|
||||
}
|
||||
const s = currentSession(task.id)?.state;
|
||||
return s === "idle" && task.reviewing ? "reviewing" : s;
|
||||
if (task.merging_into_parent) {
|
||||
return { kind: "merging", label: "Merging", title: "Waiting for the parent task's agent to merge it" };
|
||||
}
|
||||
if (task.merge_queued_at !== undefined) {
|
||||
return { kind: "held", label: "Merge held", title: "Waiting for the merge in progress in this project to finish" };
|
||||
}
|
||||
if (open.length > 0) {
|
||||
return { kind: "error", label: "Error", title: "The agent's session failed or hit a rate limit; see the inbox" };
|
||||
}
|
||||
if (task.discarding || task.reviewing || currentSession(task.id)?.state === "running") {
|
||||
return { kind: "working", label: "Working", title: task.discarding ? "Discarding" : task.reviewing ? "A review is running" : "The agent is mid-turn" };
|
||||
}
|
||||
return { kind: "idle", label: "Idle", title: "Waiting for a message" };
|
||||
}
|
||||
|
||||
export function currentLead():AgentSession | undefined {
|
||||
|
||||
Reference in New Issue
Block a user