mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 23:56:43 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Operators review tasks, agent conversations, goals, cases, and coordinator inbox decisions from both desktop and mobile viewports. > - On mobile viewports (`< 768px`), several core detail surfaces hide or disable controls that only mount in desktop sidebars: streamlined Task Detail hides both the Properties drawer trigger and the More task actions menu; Agent Chat's top-right Show properties toggle toggles a desktop-only panel; Goal Detail hides its Properties panel with no mobile drawer; Coordinator Inbox disables artifact and approval inspection; BreadcrumbBar crushes current page titles behind unshrinking ancestors; Case Detail clips long unbroken IDs; wide Markdown tables and rigid 4-column media grids overflow narrow screens. > - Mobile operators need full access to task properties, task actions, goal metadata, and decision artifacts without switching to a desktop browser or fighting horizontal page overflow. > - This pull request restores mobile sheet triggers and action menus across Task Detail, Agent Chat, Goal Detail, and Coordinator Inbox, fixes mobile breadcrumb priority and properties toggle visibility, wraps long Case Detail titles, contains wide Markdown tables inside scrollable bubble regions, updates rigid 4-column media grids to 2-to-4 responsive grids, and adds unit tests plus 390×844 Storybook mobile views. > - The benefit is complete mobile parity on Paperclip's core detail and inbox workflows with zero horizontal overflow and no regressions on desktop layouts. ## Linked Issues or Issue Description **What happened?** On viewports narrower than `768px` (such as `390×844` mobile): - Streamlined Task Detail hides both the mobile `Properties` sheet button (gated behind `!streamlinedTaskDetailEnabled`) and the `More task actions` (`...`) menu (nested inside `hidden md:flex`), making Properties, Plan, Artifacts, Subtasks, Copy, Archive, Privacy, and subtree Pause/Resume/Cancel controls unreachable. - On Agent Chat and mobile Task Detail routes, the top-right `Show properties` toggle calls `toggleTaskSidePanel`, which only toggles desktop-only `panelVisible` (`PropertiesPanel` is `hidden md:flex`) instead of opening the mobile `Sheet`. - `BreadcrumbBar` suppresses `propertiesToggle` on mobile task trails and gives ancestor segments `shrink-0`, crushing the final page label to one letter. - `GoalDetail` hides its Properties toggle (`hidden md:inline-flex`) and only writes to the desktop `PropertiesPanel`, leaving `<GoalProperties />` unreachable on mobile. - `CaseDetail` renders `<h1>` without `break-words` / `wrap-anywhere` or `min-w-0`, causing unbroken identifiers to overflow past `390px`. - `CoordinatorNeedsYou` sets `artifact = null`, disables mentioned-link interception, and sets `onViewDetails = undefined` on mobile, blocking inspection of approval details and decision artifacts. - Wide Markdown tables inside `TaskChatBubble` lack flex `min-w-0` containment and explicit `max-w-full overflow-x-auto` utility classes on the table scroll wrapper, and media grids in `IssueOutputSection`, `IssueAttachmentsSection`, and `TaskChatBubble` use rigid `grid-cols-4` on mobile. **Expected behavior** - Mobile users can open the `TaskSidePanel` `Sheet` from both the streamlined Task Detail header and the `BreadcrumbBar` top-right toggle (on both `/issues/:id` and `/chats/:agentRef`), and can open the `More task actions` (`...`) menu. - Mobile breadcrumbs keep the current page title legible by collapsing >2 leading segments and shrinking ancestor segments before the current crumb. - Mobile `GoalDetail` provides a `Properties` button that opens `<GoalProperties />` in a bottom `Sheet`. - Mobile `CaseDetail` wraps unbroken identifiers cleanly within the viewport. - Mobile `CoordinatorNeedsYou` opens approval details, artifact rows, and mentioned documents in a responsive bottom `Sheet` backed by `<CoordinatorReviewPanel />`. - Wide Markdown tables scroll horizontally within their bubble container without expanding page width, and media grids adapt from 2 columns on mobile to 4 columns on `sm+`. **Steps to reproduce** 1. Open Paperclip UI at a `390×844` viewport. 2. Visit a streamlined task detail page, an agent chat page, a goal detail page, a case detail page with a long unbroken token in its title, and the Coordinator Inbox (`/decisions`). 3. Attempt to open Properties, More task actions, Goal Properties, or an approval/plan artifact review panel, and inspect breadcrumb truncation and table overflow. **Paperclip version or commit** Reproduced on `origin/master` (`85ad16b47e`). ## What Changed - **`ui/src/pages/IssueDetail.tsx`**: Wired `toggleTaskSidePanel` and `breadcrumbPanelControl.open` to `mobilePropsOpen` when `isMobile` is true (including on `/chats/:agentRef`); moved `More task actions` (`...`) out of `hidden md:flex` so it stays reachable on mobile; added a mobile-only `Properties` button to streamlined Task Detail headers. *(Note on file size rule: `IssueDetail.tsx` already exceeded 1,000 lines; this PR adds only +36 net lines directly in the existing header and panel toggle hooks to avoid unnecessary churn.)* - **`ui/src/components/BreadcrumbBar.tsx`**: Rendered `propertiesToggle` on mobile task and chat trails whenever `showPropertiesToggle` or `breadcrumbPanelControl` is present; collapsed >2-segment mobile trails to parent + current and shrunk ancestor segments (`max-w-28`, `max-w-24` for task parents) while giving the final crumb `flex-1 min-w-0`. - **`ui/src/pages/GoalDetail.tsx`**: Added a mobile-only `Properties` trigger button and bottom `<Sheet>` rendering `<GoalProperties />`. - **`ui/src/pages/CaseDetail.tsx`**: Added `min-w-0`, `break-words`, and `wrap-anywhere` to the page container, header, and `<h1>` title. - **`ui/src/components/coordinator/CoordinatorNeedsYou.tsx`**: Removed mobile disables on `needsYouArtifact`, mentioned document clicks, and approval `onViewDetails`; guarded desktop `panelVisible` close sync with `!isMobile`; added a bottom `<Sheet>` rendering `<CoordinatorReviewPanel />` (with multi-tab switching when multiple artifacts are open). - **`ui/src/components/MarkdownBody.tsx` & `ui/src/components/task-chat/TaskChatBubble.tsx`**: Added `max-w-full overflow-x-auto` to the Markdown table scroll wrapper and `min-w-0 max-w-full` flex containment on chat bubbles. - **`ui/src/components/issue-output/IssueOutputSection.tsx`, `ui/src/components/IssueAttachmentsSection.tsx`, `ui/src/components/task-chat/TaskChatBubble.tsx`**: Updated rigid `grid-cols-4` media grids to `grid-cols-2 sm:grid-cols-4`. - **Storybook & Tests**: Added/updated 390×844 mobile Storybook exports (`TaskDetailMobile`, `AgentChatMobile`, `GoalDetailMobile`, `CaseDetailMobile`, `CoordinatorInboxMobile`) and 7 Vitest suites covering every changed surface. ## Verification - Targeted Vitest (8 files, 94 tests pass): `pnpm --filter @paperclipai/ui exec vitest run src/components/MarkdownBody.test.tsx src/components/BreadcrumbBar.mobile.test.tsx src/pages/GoalDetail.mobile.test.tsx src/pages/CaseDetail.mobile.test.tsx src/components/coordinator/CoordinatorNeedsYou.mobile.test.tsx src/components/coordinator/CoordinatorNeedsYou.toolbar.test.tsx src/components/task-chat/TaskChatBubble.mobile.test.tsx src/pages/IssueDetail.mobile.test.tsx` - Design token & sync gates (All 4 gates CLEAN + cliplab character in sync): `pnpm check:token-gates` - TypeScript build & typecheck (0 errors): `pnpm --filter @paperclipai/ui typecheck` - Storybook catalog & map checks (372 files, 3490 stories; 30/30 catalog & map tests pass): `node scripts/storybook-catalog.mjs --check && node --test scripts/check-maps.test.mjs scripts/storybook-catalog.test.mjs scripts/storybook-feature-index.test.mjs` - Revision verified: `20c7e91bdad95b4679cd1707e6881a3f414f71a4` on local macOS worktree. Full repo CI suite and visual browser checks will run in GitHub Actions. ## Risks - Low risk: all new drawer/sheet paths and breadcrumb collapsing are strictly gated to mobile (`isMobile` / `md:hidden`), preserving existing desktop layouts and behaviors. - Mobile `CoordinatorNeedsYou` review sheets intentionally bypass desktop `PropertiesPanel` so desktop `panelVisible === false` does not auto-dismiss the mobile sheet; desktop panel behavior is unchanged. ## Model Used - **Provider & Model**: Google Gemini — Gemini 4 Neon (High) - **Capabilities**: Extended reasoning/thinking, tool use, local code execution, and automated test verification. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge
529 lines
23 KiB
TypeScript
529 lines
23 KiB
TypeScript
import { CoordinatorRelativeTime } from "@/components/coordinator/CoordinatorRelativeTime";
|
|
import { useAgentChatRead } from "@/hooks/useAgentChatRead";
|
|
import { Link } from "@/lib/router";
|
|
import { useCoordinatorPresentation } from "@/components/coordinator/CoordinatorPresentation";
|
|
import { TextAttachmentContext } from "@/context/TextAttachmentContext";
|
|
import { useArtifactsV1Enabled } from "@/hooks/useArtifactsV1Enabled";
|
|
import { ArtifactRow, ArtifactRowGroup, inlineRowStyle, subjectFromAttachmentRef } from "@/components/artifacts/v1";
|
|
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 { createContext, useCallback, useContext, useState, type ReactNode } from "react";
|
|
import { useEmailComment } from "@/components/EmailMessageCard";
|
|
import type { Agent, IssueAttachment } from "@paperclipai/shared";
|
|
import { IssueGalleryContext } from "@/context/IssueGalleryContext";
|
|
import { agentRouteRef, cn } from "@/lib/utils";
|
|
import { agentDetailHref } from "@/pages/agent-detail-navigation";
|
|
import { useStreamlinedTaskChatPresentation } from "./presentation-mode";
|
|
import { MarkdownBody } from "@/components/MarkdownBody";
|
|
import {
|
|
ImageGalleryModal,
|
|
type GalleryMediaItem,
|
|
} from "@/components/ImageGalleryModal";
|
|
import {
|
|
Attachment,
|
|
AttachmentContent,
|
|
AttachmentDescription,
|
|
AttachmentGroup,
|
|
AttachmentMedia,
|
|
AttachmentTitle,
|
|
AttachmentTrigger,
|
|
} from "@/components/ui/attachment";
|
|
import {
|
|
attachmentIdFromUrl,
|
|
extractAttachmentRefs,
|
|
extractImageRefs,
|
|
fileKindForAttachment,
|
|
formatFileSize,
|
|
hydrateAttachmentRefs,
|
|
isImageAttachment,
|
|
stripStandaloneImageEmbeds,
|
|
type AttachmentRef,
|
|
} from "./task-chat-attachments";
|
|
import { TaskChatBubbleActions } from "./TaskChatBubbleActions";
|
|
import { TaskChatSystemNotice } from "./TaskChatSystemNotice";
|
|
import { RunFileCardsContext } from "./RunFileCardsContext";
|
|
import type { TaskChatMessageItem } from "./task-chat-model";
|
|
import { safeNavigableUrl } from "@/lib/safe-url";
|
|
|
|
interface TaskChatBubbleProps {
|
|
item: TaskChatMessageItem;
|
|
/** Requeues a blocked task after a no-live-execution-path recovery notice. */
|
|
onTryAgainNoLiveExecutionPath?: () => Promise<void> | void;
|
|
tryAgainNoLiveExecutionPathPending?: boolean;
|
|
/** Disable the entrance animation when replacing an already-visible live response. */
|
|
animateEntry?: boolean;
|
|
/** Action shown beside the queued state for an interruptible message. */
|
|
queuedAction?: ReactNode;
|
|
/**
|
|
* The settled run turn rendered on this bubble's footer line (round 9):
|
|
* replaces the plain timestamp with "2:34 PM · ✓ Worked · 38s · 3 tools"
|
|
* (the timestamp leads the summary), expandable to the nested tool history.
|
|
* Supplied by TaskChatThreadView when `item.attachedTurn` is set.
|
|
*/
|
|
attachedTurn?: ReactNode;
|
|
/** New-runner Worked header, rendered above the durable final response. */
|
|
beforeTurn?: ReactNode;
|
|
/** The durable runner turn already owns the shared agent identity row. */
|
|
hideAgentIdentity?: boolean;
|
|
/**
|
|
* copy · 👍 · 👎 controls for an agent bubble's footer line (PAP-413).
|
|
* Rendered here only for a runless reply (leading the bare timestamp); when
|
|
* an attached turn is present it owns these via its `leading` slot instead,
|
|
* so this bubble skips them. Human/system bubbles pass nothing.
|
|
*/
|
|
actions?: ReactNode;
|
|
attachments?: IssueAttachment[];
|
|
}
|
|
|
|
function initialsForName(name: string) {
|
|
const parts = name.trim().split(/\s+/);
|
|
if (parts.length >= 2) {
|
|
return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
|
|
}
|
|
return name.slice(0, 2).toUpperCase();
|
|
}
|
|
|
|
export const TaskTranscriptAgents = createContext<ReadonlyMap<string, Agent> | null>(null);
|
|
|
|
export function TaskChatAgentIdentity({
|
|
agentName,
|
|
agentIcon,
|
|
agent,
|
|
}: {
|
|
agentName: string;
|
|
agentIcon?: string | null;
|
|
agent?: AvatarAgent;
|
|
}) {
|
|
const taskAgents = useContext(TaskTranscriptAgents);
|
|
const identity = (
|
|
<>
|
|
<span data-testid="task-chat-agent-avatar"><AgentAvatar agent={agent} name={agentName} size={24} /></span>
|
|
<span className="text-sm font-semibold text-foreground">{agentName}</span>
|
|
</>
|
|
);
|
|
const className = "flex items-center gap-2 px-1";
|
|
if (!agent?.id) {
|
|
return <span className={className} data-testid="task-chat-agent-identity">{identity}</span>;
|
|
}
|
|
const member = taskAgents?.get(agent.id);
|
|
const agentRef = member && member.status !== "terminated" ? agentRouteRef(member) : agent.id;
|
|
return (
|
|
<Link
|
|
to={taskAgents ? `/chats/${encodeURIComponent(agentRef)}` : agentDetailHref(agent.id)}
|
|
className={cn(className, "no-underline hover:no-underline")}
|
|
data-testid="task-chat-agent-identity"
|
|
>
|
|
{identity}
|
|
</Link>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 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(
|
|
src: string,
|
|
name?: string,
|
|
attachment?: ReturnType<typeof hydrateAttachmentRefs>[number],
|
|
): GalleryMediaItem {
|
|
return {
|
|
id: attachment?.id ?? src,
|
|
contentPath: attachment?.openPath ?? src,
|
|
openPath: attachment?.openPath,
|
|
downloadPath: attachment?.downloadPath,
|
|
contentType: attachment?.contentType ?? "",
|
|
originalFilename: name?.trim() ? name : "image",
|
|
};
|
|
}
|
|
|
|
function uniqueAttachmentRefs(refs: AttachmentRef[]): AttachmentRef[] {
|
|
return refs.filter(
|
|
(ref, index) =>
|
|
refs.findIndex(
|
|
(candidate) =>
|
|
(ref.id && candidate.id === ref.id) || candidate.url === ref.url,
|
|
) === index,
|
|
);
|
|
}
|
|
|
|
export function TaskChatBubble(props: TaskChatBubbleProps) {
|
|
const email = useEmailComment(props.item.id);
|
|
return email ?? <TaskChatBubbleContent {...props} />;
|
|
}
|
|
function TaskChatBubbleContent({
|
|
item,
|
|
animateEntry = true,
|
|
queuedAction,
|
|
attachedTurn,
|
|
beforeTurn,
|
|
hideAgentIdentity = false,
|
|
actions,
|
|
attachments = [],
|
|
onTryAgainNoLiveExecutionPath,
|
|
tryAgainNoLiveExecutionPathPending,
|
|
}: TaskChatBubbleProps) {
|
|
const readRef = useAgentChatRead(item.id, item.createdAtIso, item.author === "agent" && !item.optimistic);
|
|
const streamlined = useStreamlinedTaskChatPresentation();
|
|
const coordinator = useCoordinatorPresentation();
|
|
const recordedTimestamp = item.createdAtIso ?? (typeof item.atMs === "number" && Number.isFinite(item.atMs) ? new Date(item.atMs) : null);
|
|
const timestamp = coordinator && recordedTimestamp && !item.optimistic
|
|
? <CoordinatorRelativeTime value={recordedTimestamp} /> : item.timestamp;
|
|
const { enabled: artifactsV1 } = useArtifactsV1Enabled();
|
|
const openText = useContext(TextAttachmentContext);
|
|
const runFileCards = useContext(RunFileCardsContext);
|
|
// Task attachments share the page gallery; standalone images retain the bubble viewer.
|
|
const openIssueGallery = useContext(IssueGalleryContext);
|
|
const [lightboxSrc, setLightboxSrc] = useState<string | null>(null);
|
|
// Keep MarkdownBody's memo boundary intact when only the live tail changes.
|
|
// A fresh callback here reparses every historical response on every update.
|
|
const openImage = useCallback((src: string) => {
|
|
if (!openIssueGallery?.(src)) setLightboxSrc(src);
|
|
}, [openIssueGallery]);
|
|
if (item.interstitial) {
|
|
// Interstitial updates are ephemeral (PAP-361): while streaming the text
|
|
// lives on the live parent row's line (TaskChatStatusItem.selfTalk), and
|
|
// once finished it renders nowhere — the run log / classic transcript
|
|
// remain the archive. Never rendered as a bubble.
|
|
return null;
|
|
}
|
|
|
|
if (item.author === "system") {
|
|
// Collapsed humanized one-liner, expandable to the full detail (PAP-443).
|
|
return (
|
|
<TaskChatSystemNotice
|
|
item={item}
|
|
onTryAgainNoLiveExecutionPath={onTryAgainNoLiveExecutionPath}
|
|
tryAgainNoLiveExecutionPathPending={tryAgainNoLiveExecutionPathPending}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const isHuman = item.author === "human";
|
|
const isOwnMessage = isHuman && item.isCurrentUser === true;
|
|
const sentFromIMessage = isHuman && item.sourceChannel === "imessage-photon";
|
|
// Short notes before the timestamp: the message ran as a swarm, or came from iMessage.
|
|
const footerNotes = [
|
|
isHuman && item.nativeCommand === "swarm" ? "Swarm" : null,
|
|
sentFromIMessage ? "Sent from iMessage" : null,
|
|
].filter((note): note is string => note !== null);
|
|
const footerLine = (
|
|
<>
|
|
{footerNotes.map((note, index) => (
|
|
<span key={note} data-testid={note === "Swarm" ? "task-chat-swarm-marker" : undefined}>
|
|
{index > 0 ? " · " : null}{note}
|
|
</span>
|
|
))}
|
|
{footerNotes.length > 0 && timestamp ? " · " : null}
|
|
{timestamp}
|
|
</>
|
|
);
|
|
// Non-image file references ("[name](/api/attachments/…/content)") render as
|
|
// attachment chips under the bubble; link-only lines leave the body text.
|
|
const { refs: linkedRefs, text: bodyWithoutAttachmentLinks } =
|
|
extractAttachmentRefs(item.text);
|
|
const embeddedImageRefs = extractImageRefs(bodyWithoutAttachmentLinks);
|
|
const bodyText = stripStandaloneImageEmbeds(bodyWithoutAttachmentLinks);
|
|
const hydratedLinkedRefs = hydrateAttachmentRefs(linkedRefs, attachments);
|
|
const hydratedEmbeddedRefs = hydrateAttachmentRefs(
|
|
embeddedImageRefs,
|
|
attachments,
|
|
);
|
|
const boundAttachmentRefs: AttachmentRef[] = attachments
|
|
.filter((attachment) => attachment.issueCommentId === item.id)
|
|
.map((attachment) => ({
|
|
id: attachment.id,
|
|
name: attachment.originalFilename?.trim() || "attachment",
|
|
url: attachment.contentPath,
|
|
contentType: attachment.contentType,
|
|
byteSize: attachment.byteSize,
|
|
openPath: attachment.openPath,
|
|
downloadPath: attachment.downloadPath,
|
|
}));
|
|
const notRunFileCard = (ref: AttachmentRef) => {
|
|
const id = ref.id ?? attachmentIdFromUrl(ref.url);
|
|
return !(item.author === "agent" && item.sourceRunId && id && runFileCards.get(id) === item.sourceRunId);
|
|
};
|
|
const imageRefs = uniqueAttachmentRefs([
|
|
...hydratedEmbeddedRefs,
|
|
...hydratedLinkedRefs.filter(isImageAttachment),
|
|
...boundAttachmentRefs.filter(isImageAttachment),
|
|
]).filter(notRunFileCard);
|
|
const attachmentRefs = uniqueAttachmentRefs([
|
|
...hydratedLinkedRefs.filter((ref) => !isImageAttachment(ref)),
|
|
...boundAttachmentRefs.filter((ref) => !isImageAttachment(ref)),
|
|
]).filter(notRunFileCard);
|
|
const mediaRefs = [...imageRefs, ...attachmentRefs.filter((ref) => isVideoLikeOutput(ref.contentType, ref.name))];
|
|
const galleryItems: GalleryMediaItem[] =
|
|
lightboxSrc !== null && !mediaRefs.some((ref) => ref.url === lightboxSrc)
|
|
? // A clicked image the extractor missed (e.g. inline HTML) still gets a
|
|
// single-item lightbox rather than nothing.
|
|
[galleryItemForMedia(lightboxSrc)]
|
|
: mediaRefs.map((ref) => galleryItemForMedia(ref.url, ref.name, ref));
|
|
const lightboxIndex =
|
|
lightboxSrc === null
|
|
? -1
|
|
: Math.max(0, mediaRefs.findIndex((ref) => ref.url === lightboxSrc));
|
|
return (
|
|
<div
|
|
data-conversation-message={isHuman ? "human" : "agent"}
|
|
ref={readRef}
|
|
className={cn(
|
|
"flex w-full min-w-0 flex-col gap-1",
|
|
animateEntry && "tc-enter-bubble",
|
|
isOwnMessage ? "items-end" : "items-start",
|
|
)}
|
|
>
|
|
{beforeTurn ? <div className="w-full pb-1">{beforeTurn}</div> : null}
|
|
{item.chatMessage && <Link to={`/issues/${item.chatMessage.sourceTaskIdentifier}`} className="px-1 text-xs text-muted-foreground underline underline-offset-4">
|
|
From {item.chatMessage.sourceTaskIdentifier}
|
|
</Link>}
|
|
{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}
|
|
agentIcon={item.agentIcon}
|
|
agent={item.agent}
|
|
/>
|
|
) : null}
|
|
{bodyText.length > 0 ? (
|
|
<div
|
|
data-conversation-text={isHuman ? (isOwnMessage ? "human" : "progress") : item.channel === "progress" ? "progress" : "final"}
|
|
// Stable hook so the TaskChatLab bubble-treatment explorations
|
|
// (PAP-501) can scope background/border overrides to the agent
|
|
// bubble body without touching the live thread.
|
|
data-testid={
|
|
isHuman ? "task-chat-human-bubble" : "task-chat-agent-bubble"
|
|
}
|
|
className={cn(
|
|
"min-w-0 max-w-full break-words py-2 text-sm",
|
|
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 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={isOwnMessage ? "paperclip-markdown-on-accent" : undefined}
|
|
softBreaks
|
|
linkIssueReferences
|
|
onImageClick={openImage}
|
|
>
|
|
{bodyText}
|
|
</MarkdownBody>
|
|
</div>
|
|
) : null}
|
|
{!artifactsV1 && imageRefs.length > 0 ? (
|
|
<div
|
|
className="flex max-w-(--pct-85) flex-col gap-2"
|
|
data-testid="task-chat-bubble-media"
|
|
>
|
|
<span className="text-xs text-muted-foreground">
|
|
Images · {imageRefs.length}
|
|
</span>
|
|
<div className="grid grid-cols-2 gap-2 sm:grid-cols-4">
|
|
{imageRefs
|
|
.slice(0, imageRefs.length > 4 ? 3 : 4)
|
|
.map((ref, index) => (
|
|
<button
|
|
key={ref.url}
|
|
type="button"
|
|
className="group aspect-video min-w-0 overflow-hidden rounded-md bg-muted outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
aria-label={`Open ${ref.name || `image ${index + 1}`}`}
|
|
onClick={() => openImage(ref.url)}
|
|
>
|
|
<img
|
|
src={ref.openPath ?? ref.url}
|
|
alt={ref.name}
|
|
loading="lazy"
|
|
className="h-full w-full object-cover transition-transform group-hover:scale-(--s-1_02)"
|
|
/>
|
|
</button>
|
|
))}
|
|
{imageRefs.length > 4 ? (
|
|
<button
|
|
type="button"
|
|
className="aspect-video min-w-0 rounded-md bg-muted text-sm font-semibold text-foreground outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
aria-label={`Open ${imageRefs.length - 3} more screenshots`}
|
|
onClick={() => openImage(imageRefs[3].url)}
|
|
>
|
|
+{imageRefs.length - 3}
|
|
</button>
|
|
) : null}
|
|
</div>
|
|
<span className="truncate text-xs text-muted-foreground">
|
|
{imageRefs.map((ref) => ref.name || "image").join(" · ")}
|
|
</span>
|
|
</div>
|
|
) : null}
|
|
{!artifactsV1 && attachmentRefs.length > 0 ? (
|
|
<div className="flex max-w-(--pct-85) flex-col gap-2">
|
|
<span className="text-xs text-muted-foreground">
|
|
Files · {attachmentRefs.length}
|
|
</span>
|
|
<AttachmentGroup data-testid="task-chat-bubble-attachments">
|
|
{attachmentRefs.map((ref) => {
|
|
const kind = fileKindForAttachment(ref);
|
|
const KindIcon = kind.icon;
|
|
const size = formatFileSize(ref.byteSize);
|
|
const video = isVideoLikeOutput(ref.contentType, ref.name);
|
|
return (
|
|
<Attachment key={ref.url} size="sm">
|
|
<AttachmentMedia className={video ? "aspect-video group-data-[size=sm]/attachment:w-20" : undefined}>
|
|
{video ? <ArtifactPreview artifact={{ title: ref.name, contentPath: ref.openPath ?? ref.url, mediaKind: "video" }} /> : <KindIcon aria-hidden />}
|
|
</AttachmentMedia>
|
|
<AttachmentContent>
|
|
<AttachmentTitle className="max-w-48">
|
|
{ref.name}
|
|
</AttachmentTitle>
|
|
<AttachmentDescription className="max-w-48">
|
|
{size ? `${kind.label} · ${size}` : kind.label}
|
|
</AttachmentDescription>
|
|
</AttachmentContent>
|
|
<AttachmentTrigger
|
|
aria-label={`Open ${ref.name}`}
|
|
onClick={video ? () => openImage(ref.url) : undefined}
|
|
render={video ? <button type="button" /> :
|
|
<a
|
|
href={safeNavigableUrl(ref.openPath ?? ref.url) ?? undefined}
|
|
onClick={(event) => {
|
|
if (openText && ref.id && isTextAttachment({ contentType: ref.contentType ?? "", originalFilename: ref.name }) && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) {
|
|
event.preventDefault(); openText(ref.id, ref.name);
|
|
}
|
|
}}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
/>
|
|
}
|
|
/>
|
|
</Attachment>
|
|
);
|
|
})}
|
|
</AttachmentGroup>
|
|
</div>
|
|
) : null}
|
|
{!isHuman && item.verificationCaveats?.length ? (
|
|
<div
|
|
className="mx-1 w-(--sz-calc-7) rounded-md border border-amber-500/25 bg-amber-500/5 px-3 py-2 text-xs"
|
|
data-testid="task-chat-verification-caveats"
|
|
>
|
|
<p className="font-medium text-amber-800 dark:text-amber-200">
|
|
Verification caveat
|
|
</p>
|
|
<ul className="mt-1 space-y-1 text-muted-foreground">
|
|
{item.verificationCaveats.map((caveat, index) => (
|
|
<li key={`${caveat.commandOrCheck}:${index}`}>
|
|
<span className="font-mono text-foreground">
|
|
{caveat.commandOrCheck}
|
|
</span>
|
|
{caveat.reasonCode
|
|
? ` · ${caveat.reasonCode.replaceAll("_", " ")}`
|
|
: ""}
|
|
{caveat.detail ? (
|
|
<span className="block">{caveat.detail}</span>
|
|
) : null}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
) : null}
|
|
{coordinator && recordedTimestamp && attachedTurn ? <span className="px-1 text-(length:--text-micro) text-muted-foreground"><CoordinatorRelativeTime value={recordedTimestamp!} /></span> : null}
|
|
{item.optimistic ? (
|
|
<span className="flex items-center gap-1 px-1 text-(length:--text-micro) text-muted-foreground">
|
|
<span>{item.optimistic === "queued" ? "Queued" : "Sending…"}</span>
|
|
{item.optimistic === "queued" ? queuedAction : null}
|
|
</span>
|
|
) : attachedTurn ? (
|
|
// The settled turn takes over the footer line: timestamp + "✓ Worked"
|
|
// summary, always visible; expanding stretches beneath the bubble. The
|
|
// copy/👍/👎 actions (PAP-413) ride the turn's summary row via its
|
|
// `leading` slot — not this wrapper — so they stay anchored to the
|
|
// summary line when the tool history expands beneath it.
|
|
<div
|
|
className="self-stretch"
|
|
data-testid="task-chat-bubble-attached-turn"
|
|
>
|
|
{attachedTurn}
|
|
</div>
|
|
) : isOwnMessage ? (
|
|
<div className="group/message-toolbar flex items-center gap-1">
|
|
<div className="transition-opacity motion-reduce:transition-none sm:opacity-0 sm:group-hover/message-toolbar:opacity-100 sm:group-focus-within/message-toolbar:opacity-100 pointer-coarse:opacity-100">
|
|
<TaskChatBubbleActions copyText={item.text} />
|
|
</div>
|
|
<span className="px-1 text-(length:--text-micro) text-muted-foreground">
|
|
{footerLine}
|
|
</span>
|
|
</div>
|
|
) : actions ? (
|
|
streamlined ? (
|
|
<div className="flex w-full items-center justify-between gap-2 px-1">
|
|
{timestamp ? (
|
|
<span className="text-(length:--text-micro) text-muted-foreground">
|
|
{timestamp}
|
|
</span>
|
|
) : null}
|
|
{actions}
|
|
</div>
|
|
) : (
|
|
<div className="flex items-center gap-1">
|
|
{actions}
|
|
{timestamp ? (
|
|
<span className="px-1 text-(length:--text-micro) text-muted-foreground">
|
|
{timestamp}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
)
|
|
) : timestamp || footerNotes.length > 0 ? (
|
|
// Timestamps are always visible (round 9) — no longer hover-revealed.
|
|
<span className="px-1 text-(length:--text-micro) text-muted-foreground">
|
|
{footerLine}
|
|
</span>
|
|
) : null}
|
|
{artifactsV1 && imageRefs.length + attachmentRefs.length > 0 ? (
|
|
// Artifacts V1 (doc/plans/2026-10-22-artifacts-mvp-v1.md): the files a message produced hang under its
|
|
// footer, 12px below, as rows inline at equal widths, wrapping past three. Pictures and video open the
|
|
// gallery, text opens a text tab when the panel offers one, anything else opens in a new tab.
|
|
<div className="w-full pt-2" data-testid="task-chat-bubble-artifacts-v1">
|
|
<ArtifactRowGroup>
|
|
{[...imageRefs, ...attachmentRefs].map((ref) => {
|
|
const subject = subjectFromAttachmentRef(ref);
|
|
const picture = isImageAttachment(ref) || isVideoLikeOutput(ref.contentType, ref.name);
|
|
const textTab = Boolean(openText && ref.id && isTextAttachment({ contentType: ref.contentType ?? "", originalFilename: ref.name }));
|
|
if (picture) return <ArtifactRow key={ref.url} subject={subject} onClick={() => openImage(ref.url)} style={inlineRowStyle} />;
|
|
// A text file keeps its link (modifier clicks, copying the address) while a plain click opens the text tab.
|
|
if (textTab) return <ArtifactRow key={ref.url} subject={subject} href={ref.openPath ?? ref.url} external onClick={() => openText?.(ref.id!, ref.name)} style={inlineRowStyle} />;
|
|
return <ArtifactRow key={ref.url} subject={subject} href={ref.openPath ?? ref.url} external style={inlineRowStyle} />;
|
|
})}
|
|
</ArtifactRowGroup>
|
|
</div>
|
|
) : null}
|
|
{lightboxSrc !== null && lightboxIndex >= 0 ? (
|
|
<ImageGalleryModal
|
|
items={galleryItems}
|
|
initialIndex={lightboxIndex}
|
|
open
|
|
onOpenChange={(open) => {
|
|
if (!open) setLightboxSrc(null);
|
|
}}
|
|
/>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|