diff --git a/tests/e2e/agent-chat-messages.spec.ts b/tests/e2e/agent-chat-messages.spec.ts index 0a1e3714c45..210ea374aca 100644 --- a/tests/e2e/agent-chat-messages.spec.ts +++ b/tests/e2e/agent-chat-messages.spec.ts @@ -63,7 +63,15 @@ test("a routine delivers a first digest, unread state, source link and replyable await expect.poll(async () => (await json(await request.get(f.chatPath))).isUnreadForMe).toBe(false); await sourceLink.click(); await expect(page).toHaveURL(new RegExp(`/issues/${source.identifier}`)); - await page.goto(f.route); + await expect(page.getByText("Digest delivered.", { exact: true })).toBeVisible(); + const identity = page.getByTestId("task-chat-agent-identity").filter({ hasText: f.agent.name }).first(); + const chatPath = `/${f.company.issuePrefix}/chats/${f.agent.urlKey}`; + await expect(identity).toHaveAccessibleName(f.agent.name); + await expect(identity).toHaveAttribute("href", chatPath); + await identity.click(); + await expect(page).toHaveURL(chatPath); + await expect(page.getByText("Morning PR digest", { exact: true })).toBeVisible(); + await expect(identity).toHaveAttribute("href", `/${f.company.issuePrefix}/agents/${f.agent.id}/overview`); await send(page, { action: "digest-followup", text: "Which was the first PR?" }); await idle(request, f.chatPath, 2); await expect(page.getByText("The first PR in your morning digest is PR 123.", { exact: true })).toBeVisible({ timeout: 45_000 }); diff --git a/ui/src/components/TaskChatThread.test.tsx b/ui/src/components/TaskChatThread.test.tsx index c08e0a41417..9ef38051af0 100644 --- a/ui/src/components/TaskChatThread.test.tsx +++ b/ui/src/components/TaskChatThread.test.tsx @@ -15,6 +15,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { ConnectivityProvider, createConnectivityStore } from "@/lib/connectivity"; import { INITIAL_TRANSCRIPT_REVEAL_BUDGET_MS, TaskChatThread } from "./TaskChatThread"; import { IssueChatThread } from "./IssueChatThread"; +import { TaskChatAgentIdentity, TaskTranscriptAgents } from "./task-chat/TaskChatBubble"; import type { Agent, IssueDocument, @@ -184,6 +185,21 @@ async function settleThreadLayout() { }); } +it("opens the agent's chat from a task and settings from the direct chat", () => { + const agent = { id: "agent-id", name: "Mira Vale", urlKey: "mira-vale-2" } as Agent; + const identity = ; + const link = () => container.querySelector("a")?.getAttribute("href"); + + render({identity}); + expect(link()).toBe("/chats/mira-vale-2"); + + render({identity}); + expect(link()).toBe("/chats/agent-id"); + + render(identity); + expect(link()).toBe("/agents/agent-id/overview"); +}); + describe.each(["legacy", "native"] as const)("historical %s system status", (runtimeMode) => { const run = (id: string, status: string, minute: number) => ({ runId: id, status, runtimeMode, agentId: "agent", agentName: "Assistant", diff --git a/ui/src/components/task-chat/TaskChatBubble.tsx b/ui/src/components/task-chat/TaskChatBubble.tsx index 30a9765074b..780aad8f305 100644 --- a/ui/src/components/task-chat/TaskChatBubble.tsx +++ b/ui/src/components/task-chat/TaskChatBubble.tsx @@ -11,11 +11,11 @@ import { isVideoLikeOutput } from "@/lib/issue-output"; import { AgentAvatar, type AvatarAgent } from "../AgentAvatar"; import { Identity } from "../Identity"; import { paperclipHumanAvatarUrl } from "@/lib/issue-chat-human-author"; -import { useCallback, useContext, useState, type ReactNode } from "react"; +import { createContext, useCallback, useContext, useState, type ReactNode } from "react"; import { useEmailComment } from "@/components/EmailMessageCard"; -import type { IssueAttachment } from "@paperclipai/shared"; +import type { Agent, IssueAttachment } from "@paperclipai/shared"; import { IssueGalleryContext } from "@/context/IssueGalleryContext"; -import { cn } from "@/lib/utils"; +import { agentRouteRef, cn } from "@/lib/utils"; import { agentDetailHref } from "@/pages/agent-detail-navigation"; import { useStreamlinedTaskChatPresentation } from "./presentation-mode"; import { MarkdownBody } from "@/components/MarkdownBody"; @@ -87,6 +87,8 @@ function initialsForName(name: string) { return name.slice(0, 2).toUpperCase(); } +export const TaskTranscriptAgents = createContext | null>(null); + export function TaskChatAgentIdentity({ agentName, agentIcon, @@ -96,6 +98,7 @@ export function TaskChatAgentIdentity({ agentIcon?: string | null; agent?: AvatarAgent; }) { + const taskAgents = useContext(TaskTranscriptAgents); const identity = ( <> @@ -103,18 +106,19 @@ export function TaskChatAgentIdentity({ ); const className = "flex items-center gap-2 px-1"; - return agent?.id ? ( + if (!agent?.id) { + return {identity}; + } + const member = taskAgents?.get(agent.id); + const agentRef = member && member.status !== "terminated" ? agentRouteRef(member) : agent.id; + return ( {identity} - ) : ( - - {identity} - ); } diff --git a/ui/src/pages/IssueDetail.tsx b/ui/src/pages/IssueDetail.tsx index c727d0857be..156e436a985 100644 --- a/ui/src/pages/IssueDetail.tsx +++ b/ui/src/pages/IssueDetail.tsx @@ -38,6 +38,7 @@ import type { TaskComposerPause } from "../components/task-chat/TaskChatPausedTa import { TaskDetailTasksPanel } from "@/components/task-detail/TaskDetailTasksPanel"; import { IssueCreatedFromNote } from "@/components/task-detail/IssueCreatedFromNote"; import { EmailThreadProvider } from "../components/EmailMessageCard"; +import { TaskTranscriptAgents } from "../components/task-chat/TaskChatBubble"; import { EmailTaskActivity } from "../components/EmailTaskActivity"; import { TaskChatScrollNavigation, taskChatScrollEntry } from "@/components/task-chat/scroll-navigation"; import { @@ -2671,6 +2672,7 @@ const IssueDetailChatTab = memo(function IssueDetailChatTab({ }} > + + )}