mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 17:54:40 +01:00
Fix human author identity and viewer-relative alignment in task chat (#15494)
Preserve human author identity in task chat and align only the current viewer on the right. Show other humans and agents on the left with their own identity. Include mixed-author Storybook journeys and regression coverage. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
ed2c22ea8c
commit
26d71d8def
15 files changed
+353
-35
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { resolveIssueChatHumanAuthor } from "@/lib/issue-chat-human-author";
|
||||
import { useWorkspaceBaseRefRecovery } from "./WorkspaceBaseRefRecovery";
|
||||
import { WorkspaceBaseRefRecoveryNotice } from "./WorkspaceBaseRefRecoveryNotice";
|
||||
import { DispositionRecoveryNotice, useDispositionRecoverySnapshot } from "./DispositionRecoveryNotice";
|
||||
@@ -1165,30 +1166,7 @@ function formatInteractionActorLabel(args: {
|
||||
return "System";
|
||||
}
|
||||
|
||||
export function resolveIssueChatHumanAuthor(args: {
|
||||
authorName?: string | null;
|
||||
authorUserId?: string | null;
|
||||
currentUserId?: string | null;
|
||||
userProfileMap?: ReadonlyMap<string, CompanyUserProfile> | null;
|
||||
}) {
|
||||
const { authorName, authorUserId, currentUserId, userProfileMap } = args;
|
||||
const profile = authorUserId
|
||||
? (userProfileMap?.get(authorUserId) ?? null)
|
||||
: null;
|
||||
const isCurrentUser = Boolean(
|
||||
authorUserId && currentUserId && authorUserId === currentUserId,
|
||||
);
|
||||
const resolvedAuthorName =
|
||||
profile?.label?.trim() ||
|
||||
authorName?.trim() ||
|
||||
(authorUserId === "local-board" ? "Board" : isCurrentUser ? "You" : "User");
|
||||
|
||||
return {
|
||||
isCurrentUser,
|
||||
authorName: resolvedAuthorName,
|
||||
avatarUrl: profile?.image ?? null,
|
||||
};
|
||||
}
|
||||
export { resolveIssueChatHumanAuthor } from "@/lib/issue-chat-human-author";
|
||||
|
||||
function toolCountSummary(toolParts: ToolCallMessagePart[]): string | null {
|
||||
if (toolParts.length === 0) return null;
|
||||
|
||||
@@ -864,6 +864,7 @@ export function TaskChatThread(props: TaskChatThreadProps) {
|
||||
commentsToTaskChatItems(projectedComments, {
|
||||
agentMap,
|
||||
userLabelMap,
|
||||
userProfileMap,
|
||||
currentUserId,
|
||||
issueAssigneeAgentId,
|
||||
verificationCaveatsByRunId,
|
||||
@@ -872,6 +873,7 @@ export function TaskChatThread(props: TaskChatThreadProps) {
|
||||
projectedComments,
|
||||
agentMap,
|
||||
userLabelMap,
|
||||
userProfileMap,
|
||||
currentUserId,
|
||||
issueAssigneeAgentId,
|
||||
verificationCaveatsByRunId,
|
||||
|
||||
@@ -8,6 +8,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { ThemeProvider } from "@/context/ThemeContext";
|
||||
import { IssueGalleryContext } from "@/context/IssueGalleryContext";
|
||||
import { TaskChatBubble } from "./TaskChatBubble";
|
||||
import { paperclipHumanAvatarUrl } from "@/lib/issue-chat-human-author";
|
||||
import type { TaskChatMessageItem } from "./task-chat-model";
|
||||
|
||||
describe("TaskChatBubble attachment chips", () => {
|
||||
@@ -41,6 +42,46 @@ describe("TaskChatBubble attachment chips", () => {
|
||||
);
|
||||
}
|
||||
|
||||
it("renders another human on the left like an agent, and moves them right when they become the viewer", () => {
|
||||
const item: TaskChatMessageItem = {
|
||||
id: "sam-comment", kind: "message", author: "human", text: "I still see the old task title.",
|
||||
authorUserId: "sam", authorName: "Sam Rivera", isCurrentUser: false,
|
||||
};
|
||||
const render = (isCurrentUser: boolean) => flushSync(() => root!.render(
|
||||
<ThemeProvider><TaskChatBubble item={{ ...item, isCurrentUser }} /></ThemeProvider>,
|
||||
));
|
||||
render(false);
|
||||
const identity = container.querySelector('[data-testid="task-chat-human-identity"]');
|
||||
expect(identity?.textContent).toContain("Sam Rivera");
|
||||
expect(identity?.querySelector('[data-slot="avatar-fallback"]')?.textContent).toBe("SR");
|
||||
expect(identity?.getAttribute("data-author-user-id")).toBe("sam");
|
||||
expect(container.querySelector('[data-testid="task-chat-human-bubble"]')?.parentElement?.classList.contains("items-start")).toBe(true);
|
||||
const bubble = container.querySelector('[data-testid="task-chat-human-bubble"]');
|
||||
expect(bubble?.className).toContain("bg-transparent");
|
||||
expect(bubble?.className).not.toContain("bg-(--liveness-blue)");
|
||||
expect(bubble?.querySelector(".paperclip-markdown")?.className).not.toContain("paperclip-markdown-on-accent");
|
||||
render(true);
|
||||
expect(bubble?.parentElement?.classList.contains("items-end")).toBe(true);
|
||||
expect(bubble?.className).toContain("bg-(--liveness-blue)");
|
||||
expect(container.querySelector('[data-testid="task-chat-human-identity"]')).toBeNull();
|
||||
expect(container.textContent).toContain("I still see the old task title.");
|
||||
});
|
||||
|
||||
it("uses initials instead of loading an external human avatar", () => {
|
||||
flushSync(() => root!.render(
|
||||
<ThemeProvider><TaskChatBubble item={{
|
||||
id: "external-avatar", kind: "message", author: "human", text: "Please check this.",
|
||||
authorName: "Sam Rivera", authorAvatarUrl: "https://example.com/track.png", isCurrentUser: false,
|
||||
}} /></ThemeProvider>,
|
||||
));
|
||||
const identity = container.querySelector('[data-testid="task-chat-human-identity"]');
|
||||
expect(identity?.querySelector("img")).toBeNull();
|
||||
expect(identity?.querySelector('[data-slot="avatar-fallback"]')?.textContent).toBe("SR");
|
||||
expect(paperclipHumanAvatarUrl("/api/assets/sam/content")).toBe("/api/assets/sam/content");
|
||||
expect(paperclipHumanAvatarUrl("https://example.com/track.png")).toBeNull();
|
||||
expect(paperclipHumanAvatarUrl("//example.com/track.png")).toBeNull();
|
||||
});
|
||||
|
||||
it("shows persistent iMessage attribution only on inbound human bubbles", () => {
|
||||
for (const author of ["human", "agent"] as const) {
|
||||
flushSync(() => root!.render(
|
||||
@@ -295,8 +336,8 @@ describe("TaskChatBubble accent-bubble text color", () => {
|
||||
);
|
||||
}
|
||||
|
||||
it("marks the human bubble's markdown as on-accent so prose text follows text-white", () => {
|
||||
render({ id: "m1", kind: "message", author: "human", text: "when a new task is created…" });
|
||||
it("marks the own-message markdown as on-accent so prose text follows text-white", () => {
|
||||
render({ id: "m1", kind: "message", author: "human", isCurrentUser: true, text: "when a new task is created…" });
|
||||
const body = container.querySelector(".paperclip-markdown");
|
||||
expect(body).not.toBeNull();
|
||||
// Without this class the light-mode prose body color reads as black on blue.
|
||||
|
||||
@@ -3,6 +3,8 @@ import { isTextAttachment } from "@/lib/issue-attachments";
|
||||
import { ArtifactPreview } from "@/components/artifacts/ArtifactCard";
|
||||
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 { useEmailComment } from "@/components/EmailMessageCard";
|
||||
import type { IssueAttachment } from "@paperclipai/shared";
|
||||
@@ -95,9 +97,9 @@ export function TaskChatAgentIdentity({
|
||||
}
|
||||
|
||||
/**
|
||||
* Author-typed message row — the primary legibility signal. Human messages sit
|
||||
* right in a solid accent bubble; agent messages sit directly on the page
|
||||
* surface with an avatar author header (the agent's assigned icon + name);
|
||||
* Viewer-relative message row — the primary legibility signal. Own messages sit
|
||||
* right in a solid accent bubble; agents and other humans sit on the left
|
||||
* directly on the page surface with their own avatar and name;
|
||||
* system notices are centered and recede.
|
||||
*/
|
||||
function galleryItemForMedia(
|
||||
@@ -171,6 +173,7 @@ function TaskChatBubbleContent({
|
||||
}
|
||||
|
||||
const isHuman = item.author === "human";
|
||||
const isOwnMessage = isHuman && item.isCurrentUser === true;
|
||||
const sentFromIMessage = isHuman && item.sourceChannel === "imessage-photon";
|
||||
// Non-image file references ("[name](/api/attachments/…/content)") render as
|
||||
// attachment chips under the bubble; link-only lines leave the body text.
|
||||
@@ -219,10 +222,15 @@ function TaskChatBubbleContent({
|
||||
className={cn(
|
||||
"flex w-full flex-col gap-1",
|
||||
animateEntry && "tc-enter-bubble",
|
||||
isHuman ? "items-end" : "items-start",
|
||||
isOwnMessage ? "items-end" : "items-start",
|
||||
)}
|
||||
>
|
||||
{beforeTurn ? <div className="w-full pb-1">{beforeTurn}</div> : null}
|
||||
{isHuman && !item.isCurrentUser && item.authorName ? (
|
||||
<span className="px-1 text-sm font-semibold text-foreground" data-testid="task-chat-human-identity" data-author-user-id={item.authorUserId}>
|
||||
<Identity name={item.authorName} avatarUrl={paperclipHumanAvatarUrl(item.authorAvatarUrl)} size="default" className="gap-2" />
|
||||
</span>
|
||||
) : null}
|
||||
{!isHuman && item.authorName && !hideAgentIdentity ? (
|
||||
<TaskChatAgentIdentity
|
||||
agentName={item.authorName}
|
||||
@@ -240,19 +248,19 @@ function TaskChatBubbleContent({
|
||||
}
|
||||
className={cn(
|
||||
"break-words py-2 text-sm",
|
||||
isHuman
|
||||
isOwnMessage
|
||||
? "max-w-(--pct-85) rounded-2xl rounded-br-sm bg-(--liveness-blue) px-3.5 text-white"
|
||||
: "w-full bg-transparent px-1 text-foreground",
|
||||
)}
|
||||
>
|
||||
<MarkdownBody
|
||||
// The human bubble sits on the solid --liveness-blue accent, so the
|
||||
// The own-message bubble sits on the solid --liveness-blue accent, so the
|
||||
// prose body text must follow the bubble's `text-white` rather than
|
||||
// the default light-mode prose color (which reads as black on blue).
|
||||
// `paperclip-markdown-on-accent` flips prose tokens to currentColor
|
||||
// (== inherited white) in both themes; dark mode was already correct
|
||||
// only because `prose-invert` happened to lighten the text.
|
||||
className={isHuman ? "paperclip-markdown-on-accent" : undefined}
|
||||
className={isOwnMessage ? "paperclip-markdown-on-accent" : undefined}
|
||||
softBreaks
|
||||
linkIssueReferences
|
||||
onImageClick={openImage}
|
||||
|
||||
@@ -6,6 +6,40 @@ import {
|
||||
} from "./task-chat-adapter";
|
||||
|
||||
describe("commentsToTaskChatItems", () => {
|
||||
it("preserves distinct human IDs, photos and viewer ownership, including after a profile refresh", () => {
|
||||
const comments = ["alex", "sam"].map(authorUserId => ({
|
||||
id: `comment-${authorUserId}`, authorType: "user", authorUserId,
|
||||
authorAgentId: null, body: "A human message", createdAt: "2026-10-09T20:42:00Z",
|
||||
} as unknown as IssueChatComment));
|
||||
const userProfileMap = new Map([
|
||||
["alex", { label: "Alex Morgan", image: "/alex.png" }],
|
||||
["sam", { label: "Sam Rivera", image: "/sam.png" }],
|
||||
]);
|
||||
expect(commentsToTaskChatItems(comments, { currentUserId: "alex", userProfileMap })).toMatchObject([
|
||||
{ authorUserId: "alex", authorName: "Alex Morgan", authorAvatarUrl: "/alex.png", isCurrentUser: true },
|
||||
{ authorUserId: "sam", authorName: "Sam Rivera", authorAvatarUrl: "/sam.png", isCurrentUser: false },
|
||||
]);
|
||||
expect(commentsToTaskChatItems(comments, { currentUserId: "sam", userProfileMap })).toMatchObject([
|
||||
{ authorUserId: "alex", isCurrentUser: false },
|
||||
{ authorUserId: "sam", isCurrentUser: true },
|
||||
]);
|
||||
expect(commentsToTaskChatItems(comments, { currentUserId: "alex" })).toMatchObject([
|
||||
{ authorName: "You", isCurrentUser: true, authorAvatarUrl: null },
|
||||
{ authorName: "User", isCurrentUser: false, authorAvatarUrl: null },
|
||||
]);
|
||||
// Directory hydration changes presentation without changing canonical message IDs.
|
||||
expect(commentsToTaskChatItems(comments, { currentUserId: "alex", userProfileMap })[1]).toMatchObject({
|
||||
id: "comment-sam", authorName: "Sam Rivera", authorAvatarUrl: "/sam.png",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not infer ownership from matching names or an unresolved viewer", () => {
|
||||
const comment = { id: "other", authorType: "user", authorUserId: "other", body: "Hello" } as IssueChatComment;
|
||||
expect(commentsToTaskChatItems([comment], {
|
||||
currentUserId: "me", userLabelMap: new Map([["me", "Alex"], ["other", "Alex"]]),
|
||||
})[0]).toMatchObject({ authorName: "Alex", isCurrentUser: false });
|
||||
expect(commentsToTaskChatItems([comment])[0]).toMatchObject({ authorName: "User", isCurrentUser: false });
|
||||
});
|
||||
it("carries inbound channel attribution into the human bubble", () => {
|
||||
expect(commentsToTaskChatItems([{
|
||||
id: "photon-comment",
|
||||
@@ -165,6 +199,26 @@ describe("commentsToTaskChatItems", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves human identity for steered and ordinary messages", () => {
|
||||
const comment = {
|
||||
id: "steered-by-colleague", body: "Check the latest result.",
|
||||
authorType: "user", authorUserId: "colleague", steeredIntoRunId: "run-1",
|
||||
createdAt: "2026-09-04T14:09:33.000Z",
|
||||
} as unknown as IssueChatComment;
|
||||
const ctx = {
|
||||
currentUserId: "viewer",
|
||||
userProfileMap: new Map([["colleague", { label: "Sam Rivera", image: "/api/assets/sam/content" }]]),
|
||||
};
|
||||
for (const steeredIntoRunId of ["run-1", null]) {
|
||||
expect(commentsToTaskChatItems([{ ...comment, steeredIntoRunId }], ctx)[0]).toMatchObject({
|
||||
authorName: "Sam Rivera", authorAvatarUrl: "/api/assets/sam/content", isCurrentUser: false,
|
||||
});
|
||||
}
|
||||
expect(commentsToTaskChatItems([{ ...comment, authorUserId: "viewer" }], ctx)[0]).toMatchObject({
|
||||
isCurrentUser: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps the regular comment time for a successor-run follow-up", () => {
|
||||
const createdAt = "2026-09-04T14:09:33.000Z";
|
||||
const conversationAnchorAt = "2026-09-04T14:10:35.000Z";
|
||||
|
||||
@@ -10,11 +10,14 @@
|
||||
import type { Agent } from "@paperclipai/shared";
|
||||
import type { IssueChatComment } from "@/lib/issue-chat-messages";
|
||||
import { resolveCommentAttribution } from "@/lib/comment-attribution";
|
||||
import { resolveIssueChatHumanAuthor } from "@/lib/issue-chat-human-author";
|
||||
import type { CompanyUserProfile } from "@/lib/company-members";
|
||||
import type { TaskChatAuthorKind, TaskChatItem, TaskChatMessageItem } from "./task-chat-model";
|
||||
|
||||
export interface TaskChatAdapterContext {
|
||||
agentMap?: Map<string, Agent>;
|
||||
userLabelMap?: ReadonlyMap<string, string> | null;
|
||||
userProfileMap?: ReadonlyMap<string, CompanyUserProfile> | null;
|
||||
currentUserId?: string | null;
|
||||
/**
|
||||
* Task's current assignee. Agent comments from anyone else are cross-issue
|
||||
@@ -78,6 +81,12 @@ export function commentsToTaskChatItems(
|
||||
let authorName: string | undefined;
|
||||
let agentIcon: string | null | undefined;
|
||||
let onBehalfOfUserName: string | undefined;
|
||||
const humanAuthor = kind === "human" ? resolveIssueChatHumanAuthor({
|
||||
authorUserId: comment.authorUserId,
|
||||
authorName: comment.authorUserId ? ctx.userLabelMap?.get(comment.authorUserId) : null,
|
||||
currentUserId: ctx.currentUserId,
|
||||
userProfileMap: ctx.userProfileMap,
|
||||
}) : undefined;
|
||||
if (kind === "agent") {
|
||||
const agentId = effectiveAgentId(comment);
|
||||
authorName = (agentId && ctx.agentMap?.get(agentId)?.name) || "Agent";
|
||||
@@ -89,8 +98,7 @@ export function commentsToTaskChatItems(
|
||||
resolveUserLabel: (userId) => ctx.userLabelMap?.get(userId),
|
||||
})?.userName;
|
||||
} else if (kind === "human") {
|
||||
authorName =
|
||||
(comment.authorUserId && ctx.userLabelMap?.get(comment.authorUserId)) || undefined;
|
||||
authorName = humanAuthor!.authorName;
|
||||
}
|
||||
const queued = comment.queueState === "queued" || comment.clientStatus === "queued";
|
||||
const optimistic =
|
||||
@@ -120,6 +128,11 @@ export function commentsToTaskChatItems(
|
||||
kind: "message",
|
||||
author: kind,
|
||||
authorName,
|
||||
...(humanAuthor ? {
|
||||
authorUserId: comment.authorUserId,
|
||||
authorAvatarUrl: humanAuthor.avatarUrl,
|
||||
isCurrentUser: humanAuthor.isCurrentUser,
|
||||
} : {}),
|
||||
agent: effectiveAgentId(comment) ? ctx.agentMap?.get(effectiveAgentId(comment)!) ?? { id: effectiveAgentId(comment)! } : undefined,
|
||||
text: comment.body,
|
||||
sourceChannel: kind === "human" ? comment.metadata?.sourceChannel : undefined,
|
||||
|
||||
@@ -107,6 +107,10 @@ export interface TaskChatMessageItem {
|
||||
kind: "message";
|
||||
author: TaskChatAuthorKind;
|
||||
authorName?: string;
|
||||
/** Human identity comes from the company directory, matched by stored user ID. */
|
||||
authorUserId?: string | null;
|
||||
authorAvatarUrl?: string | null;
|
||||
isCurrentUser?: boolean;
|
||||
text: string;
|
||||
/** Runner-authored output channel. Legacy adapters leave this unset. */
|
||||
channel?: "progress" | "final" | "unknown";
|
||||
|
||||
Reference in new issue
Block a user