mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 09:39:53 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The task thread lets an operator add guidance while an agent run is active > - A new message can wait behind that active run as a queued message > - The classic task view lets the operator interrupt the target run from that queued message > - The redesigned task view did not expose the same action > - This pull request restores the action and keeps it bound to the exact target run > - The benefit is that operators can apply urgent guidance without switching task views ## Linked Issues or Issue Description **What happened?** The redesigned task view showed `Queued` for a queued operator message, but it did not show the existing interrupt action. **Expected behavior** The queued message must show `Interrupt` next to `Queued`. The action must stop the exact run that the message is waiting behind. **Steps to reproduce** 1. Open a task in the redesigned task view while an agent run is active. 2. Send a new operator message so it enters the queued state. 3. Observe that the queued message has no interrupt action. **Paperclip version or commit** `bc0b5a1642` **Deployment mode** All deployment modes that use the redesigned task view. ## What Changed - Preserve persisted queued state and the target run ID in the redesigned thread model. - Render a token-compliant `Interrupt` action beside the queued state. - Reuse the existing exact-run interrupt callback and show a disabled `Interrupting…` state during the request. - Keep an assigned queue target immutable so an in-flight comment cannot rebind its interrupt action to a replacement run. - Add regression tests for persisted queued messages, replacement-run races, and the in-progress action state. - No documentation update was required because this restores existing behavior. ## Verification - `pnpm exec vitest run ui/src/components/TaskChatThread.test.tsx` - `pnpm exec vitest run ui/src/components/TaskChatThread.test.tsx ui/src/components/task-chat/task-chat-adapter.test.ts ui/src/pages/IssueDetail.test.tsx -t 'queued message actions|queues messages against a queued live run and interrupts that exact run|commentsToTaskChatItems'` - `pnpm exec vitest run ui/src/pages/IssueDetail.test.tsx -t 'queued message|queues messages'` - `pnpm exec vitest run ui/src/pages/IssueDetail.test.tsx` (52 passed) - `pnpm -r typecheck` - `pnpm test:run` (all server and UI groups passed; the CLI group passed after inherited static AWS credential variables were omitted) - `env -u AWS_ACCESS_KEY_ID -u AWS_SECRET_ACCESS_KEY pnpm exec vitest run cli/src/__tests__/secrets.test.ts` - `pnpm build` - `pnpm check:token-gates` ## Risks Low risk. The change only adds an action to queued messages that have a target run and an interrupt callback. Messages without both values keep the current rendering. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used OpenAI Codex with GPT-5. The runtime does not expose a more specific deployment ID or context-window size. The model used reasoning, repository tools, code execution, and test execution. ## 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 - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
219 lines
9.3 KiB
TypeScript
219 lines
9.3 KiB
TypeScript
import { useState, type ReactNode } from "react";
|
|
import { cn } from "@/lib/utils";
|
|
import { MarkdownBody } from "@/components/MarkdownBody";
|
|
import { ImageGalleryModal, type GalleryMediaItem } from "@/components/ImageGalleryModal";
|
|
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
|
|
import { AgentIcon } from "@/components/AgentIconPicker";
|
|
import { CommentAttributionChip } from "@/components/CommentAttributionChip";
|
|
import {
|
|
Attachment,
|
|
AttachmentContent,
|
|
AttachmentDescription,
|
|
AttachmentGroup,
|
|
AttachmentMedia,
|
|
AttachmentTitle,
|
|
AttachmentTrigger,
|
|
} from "@/components/ui/attachment";
|
|
import { extractAttachmentRefs, extractImageRefs, fileKindForName } from "./task-chat-attachments";
|
|
import { TaskChatSystemNotice } from "./TaskChatSystemNotice";
|
|
import type { TaskChatMessageItem } from "./task-chat-model";
|
|
|
|
interface TaskChatBubbleProps {
|
|
item: TaskChatMessageItem;
|
|
/** 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;
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
* system notices are centered and recede.
|
|
*/
|
|
function galleryItemForImage(src: string, name?: string): GalleryMediaItem {
|
|
return {
|
|
id: src,
|
|
contentPath: src,
|
|
// The modal only inspects contentType/filename to spot videos; embedded
|
|
// markdown images are always images, so an empty type is safe here.
|
|
contentType: "",
|
|
originalFilename: name?.trim() ? name : "image",
|
|
};
|
|
}
|
|
|
|
export function TaskChatBubble({ item, queuedAction, attachedTurn, actions }: TaskChatBubbleProps) {
|
|
// Clicking an embedded image opens the full-screen lightbox (with download);
|
|
// arrow keys walk across the other images in the same bubble.
|
|
const [lightboxSrc, setLightboxSrc] = useState<string | null>(null);
|
|
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} />;
|
|
}
|
|
|
|
const isHuman = item.author === "human";
|
|
// Non-image file references ("[name](/api/attachments/…/content)") render as
|
|
// attachment chips under the bubble; link-only lines leave the body text.
|
|
const { refs: attachmentRefs, text: bodyText } = extractAttachmentRefs(item.text);
|
|
const imageRefs = extractImageRefs(bodyText);
|
|
const galleryItems: GalleryMediaItem[] =
|
|
lightboxSrc !== null && !imageRefs.some((ref) => ref.url === lightboxSrc)
|
|
// A clicked image the extractor missed (e.g. inline HTML) still gets a
|
|
// single-item lightbox rather than nothing.
|
|
? [galleryItemForImage(lightboxSrc)]
|
|
: imageRefs.map((ref) => galleryItemForImage(ref.url, ref.name));
|
|
const lightboxIndex = lightboxSrc === null
|
|
? -1
|
|
: Math.max(0, galleryItems.findIndex((galleryItem) => galleryItem.contentPath === lightboxSrc));
|
|
return (
|
|
<div className={cn("tc-enter-bubble flex w-full flex-col gap-1", isHuman ? "items-end" : "items-start")}>
|
|
{!isHuman && item.authorName ? (
|
|
<span className="flex items-center gap-2 px-1">
|
|
<Avatar size="sm" className="shrink-0" data-testid="task-chat-agent-avatar">
|
|
{item.agentIcon ? (
|
|
<AvatarFallback>
|
|
<AgentIcon icon={item.agentIcon} className="h-3.5 w-3.5" />
|
|
</AvatarFallback>
|
|
) : (
|
|
<AvatarFallback>{initialsForName(item.authorName)}</AvatarFallback>
|
|
)}
|
|
</Avatar>
|
|
<span className="text-sm font-semibold text-foreground">{item.authorName}</span>
|
|
{item.onBehalfOfUserName ? (
|
|
<CommentAttributionChip
|
|
agentName={item.authorName}
|
|
userName={item.onBehalfOfUserName}
|
|
/>
|
|
) : null}
|
|
</span>
|
|
) : null}
|
|
{bodyText.length > 0 ? (
|
|
<div
|
|
// 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(
|
|
"break-words py-2 text-sm",
|
|
isHuman
|
|
? "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",
|
|
item.optimistic ? "opacity-80" : null,
|
|
)}
|
|
>
|
|
<MarkdownBody
|
|
// The human 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}
|
|
softBreaks
|
|
linkIssueReferences
|
|
onImageClick={setLightboxSrc}
|
|
>
|
|
{bodyText}
|
|
</MarkdownBody>
|
|
</div>
|
|
) : null}
|
|
{attachmentRefs.length > 0 ? (
|
|
<AttachmentGroup
|
|
className="max-w-(--pct-85)"
|
|
data-testid="task-chat-bubble-attachments"
|
|
>
|
|
{attachmentRefs.map((ref) => {
|
|
const kind = fileKindForName(ref.name);
|
|
const KindIcon = kind.icon;
|
|
return (
|
|
<Attachment key={ref.url} size="sm" className={cn(item.optimistic && "opacity-80")}>
|
|
<AttachmentMedia>
|
|
<KindIcon aria-hidden />
|
|
</AttachmentMedia>
|
|
<AttachmentContent>
|
|
<AttachmentTitle className="max-w-48">{ref.name}</AttachmentTitle>
|
|
<AttachmentDescription className="max-w-48">{kind.label}</AttachmentDescription>
|
|
</AttachmentContent>
|
|
<AttachmentTrigger
|
|
aria-label={`Open ${ref.name}`}
|
|
render={<a href={ref.url} target="_blank" rel="noreferrer" />}
|
|
/>
|
|
</Attachment>
|
|
);
|
|
})}
|
|
</AttachmentGroup>
|
|
) : 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>
|
|
) : actions ? (
|
|
// Agent reply without run activity: the actions still lead the footer,
|
|
// with the always-visible timestamp trailing (PAP-413).
|
|
<div className="flex items-center gap-1">
|
|
{actions}
|
|
{item.timestamp ? (
|
|
<span className="px-1 text-(length:--text-micro) text-muted-foreground">
|
|
{item.timestamp}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
) : item.timestamp ? (
|
|
// Timestamps are always visible (round 9) — no longer hover-revealed.
|
|
<span className="px-1 text-(length:--text-micro) text-muted-foreground">
|
|
{item.timestamp}
|
|
</span>
|
|
) : null}
|
|
{lightboxSrc !== null && lightboxIndex >= 0 ? (
|
|
<ImageGalleryModal
|
|
items={galleryItems}
|
|
initialIndex={lightboxIndex}
|
|
open
|
|
onOpenChange={(open) => {
|
|
if (!open) setLightboxSrc(null);
|
|
}}
|
|
/>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|