Skip to content

Commit d290681

Browse files
committed
feat(messages): display agent names in collab tool call titles
1 parent 04554fb commit d290681

File tree

3 files changed

+60
-8
lines changed

3 files changed

+60
-8
lines changed

src/features/messages/utils/messageRenderUtils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,14 @@ export function buildToolSummary(
330330
}
331331
}
332332

333+
if (item.toolType === "collabToolCall") {
334+
return {
335+
label: "",
336+
value: item.title,
337+
output: item.output || "",
338+
};
339+
}
340+
333341
return {
334342
label: "tool",
335343
value: item.title || "",

src/utils/threadItems.test.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,14 +611,48 @@ describe("threadItems", () => {
611611
receiverThreadIds: ["thread-b"],
612612
newThreadId: "thread-c",
613613
prompt: "Coordinate work",
614-
agentStatus: { "agent-1": { status: "running" } },
614+
agentStatus: { explore: { status: "running" } },
615615
});
616616
expect(item).not.toBeNull();
617617
if (item && item.kind === "tool") {
618-
expect(item.title).toBe("Collab: handoff");
618+
expect(item.title).toBe("Explore Agent");
619619
expect(item.detail).toContain("From thread-a");
620620
expect(item.detail).toContain("thread-b, thread-c");
621-
expect(item.output).toBe("Coordinate work\n\nagent-1: running");
621+
expect(item.output).toBe("Coordinate work\n\nexplore: running");
622+
}
623+
});
624+
625+
it("formats collab tool calls with multiple agents", () => {
626+
const item = buildConversationItem({
627+
type: "collabToolCall",
628+
id: "collab-2",
629+
tool: "task",
630+
status: "ok",
631+
senderThreadId: "thread-a",
632+
prompt: "Run parallel agents",
633+
agentStatus: {
634+
explore: { status: "running" },
635+
librarian: { status: "completed" },
636+
},
637+
});
638+
expect(item).not.toBeNull();
639+
if (item && item.kind === "tool") {
640+
expect(item.title).toBe("Explore Agent, Librarian Agent");
641+
}
642+
});
643+
644+
it("formats collab tool calls with fallback when no agent status", () => {
645+
const item = buildConversationItem({
646+
type: "collabToolCall",
647+
id: "collab-3",
648+
tool: "task",
649+
status: "ok",
650+
senderThreadId: "thread-a",
651+
prompt: "Unknown agent",
652+
});
653+
expect(item).not.toBeNull();
654+
if (item && item.kind === "tool") {
655+
expect(item.title).toBe("Subagent");
622656
}
623657
});
624658

src/utils/threadItems.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ function formatCollabAgentStates(value: unknown) {
8484
return entries.join("\n");
8585
}
8686

87+
function formatCollabAgentTitle(agentStatus: unknown): string {
88+
if (!agentStatus || typeof agentStatus !== "object") {
89+
return "Subagent";
90+
}
91+
const agents = Object.keys(agentStatus as Record<string, unknown>)
92+
.map((name) => name.charAt(0).toUpperCase() + name.slice(1) + " Agent")
93+
.filter(Boolean);
94+
95+
if (agents.length === 0) return "Subagent";
96+
return agents.join(", ");
97+
}
98+
8799
export function normalizeItem(item: ConversationItem): ConversationItem {
88100
if (item.kind === "message") {
89101
return { ...item, text: truncateText(item.text) };
@@ -743,7 +755,6 @@ export function buildConversationItem(
743755
};
744756
}
745757
if (type === "collabToolCall" || type === "collabAgentToolCall") {
746-
const tool = asString(item.tool ?? "");
747758
const status = asString(item.status ?? "");
748759
const sender = asString(item.senderThreadId ?? item.sender_thread_id ?? "");
749760
const receivers = [
@@ -752,9 +763,8 @@ export function buildConversationItem(
752763
...normalizeStringList(item.newThreadId ?? item.new_thread_id),
753764
];
754765
const prompt = asString(item.prompt ?? "");
755-
const agentsState = formatCollabAgentStates(
756-
item.agentStatus ?? item.agentsStates ?? item.agents_states,
757-
);
766+
const agentStatusObj = item.agentStatus ?? item.agentsStates ?? item.agents_states;
767+
const agentsState = formatCollabAgentStates(agentStatusObj);
758768
const detailParts = [sender ? `From ${sender}` : ""]
759769
.concat(receivers.length > 0 ? `→ ${receivers.join(", ")}` : "")
760770
.filter(Boolean);
@@ -763,7 +773,7 @@ export function buildConversationItem(
763773
id,
764774
kind: "tool",
765775
toolType: "collabToolCall",
766-
title: tool ? `Collab: ${tool}` : "Collab tool call",
776+
title: formatCollabAgentTitle(agentStatusObj),
767777
detail: detailParts.join(" "),
768778
status,
769779
output: outputParts.join("\n\n"),

0 commit comments

Comments
 (0)