mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-04 04:29:01 +01:00
Keep agent pause status inline with the name
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
7e025ae65f
commit
08f808cb7f
3 files changed
+100
-11
No files matched your search
@@ -1,19 +1,20 @@
|
||||
import { useLayoutEffect, useRef } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { agentsApi } from "../api/agents";
|
||||
import { queryKeys } from "../lib/queryKeys";
|
||||
import type { Agent, AgentLifecycleState } from "@paperclipai/shared";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { Loader2, Pause } from "lucide-react";
|
||||
import { Badge } from "./ui/badge";
|
||||
import { Button } from "./ui/button";
|
||||
|
||||
const phases = {
|
||||
preparing: ["Preparing agent", "Required resources are being prepared. Work stays queued."],
|
||||
verifying: ["Verifying agent", "The saved execution configuration is being checked. Work stays queued."],
|
||||
pausing: ["Pausing agent", "Waiting for execution and required resources to stop."],
|
||||
resuming: ["Resuming agent", "Required resources are being started. Work stays queued."],
|
||||
pausing: ["Pausing agent"],
|
||||
resuming: ["Resuming agent"],
|
||||
terminating: ["Terminating agent", "Stopping execution before resource cleanup."],
|
||||
cleaning_up: ["Cleaning up agent", "Required resources are being removed. Termination is not complete."],
|
||||
} satisfies Partial<Record<AgentLifecycleState, [string, string]>>;
|
||||
} satisfies Partial<Record<AgentLifecycleState, [string, string?]>>;
|
||||
|
||||
const failedPhases = {
|
||||
preparing: "Agent preparation failed", verifying: "Agent verification failed",
|
||||
@@ -45,13 +46,49 @@ export function useAgentLifecycleStatus(agent?: Agent) {
|
||||
});
|
||||
}
|
||||
|
||||
type PauseState = "pausing" | "paused" | "resuming";
|
||||
|
||||
export function AgentPausePill({ state }: { state?: PauseState }) {
|
||||
const shell = useRef<HTMLSpanElement>(null);
|
||||
useLayoutEffect(() => {
|
||||
const element = shell.current;
|
||||
const label = element?.querySelector<HTMLElement>('[data-active="true"]');
|
||||
if (!element || !label) return;
|
||||
const measure = () => element.style.setProperty("--pause-label-width", `${label.getBoundingClientRect().width}px`);
|
||||
measure();
|
||||
const observer = new ResizeObserver(measure);
|
||||
observer.observe(label);
|
||||
return () => observer.disconnect();
|
||||
}, [state]);
|
||||
|
||||
return (
|
||||
<span role="status" aria-live="polite" className="relative inline-flex shrink-0 items-center">
|
||||
<span className="sr-only">{state === "paused" ? "Paused" : state && phases[state][0]}</span>
|
||||
<span ref={shell} aria-hidden="true" data-visible={Boolean(state)}
|
||||
className="agent-pause-status relative inline-flex h-6 min-w-6 items-center overflow-hidden rounded-full bg-secondary px-2 text-xs font-medium whitespace-nowrap text-secondary-foreground">
|
||||
{(["pausing", "paused", "resuming"] as const).map((phase) => {
|
||||
const label = phase === "paused" ? "Paused" : phases[phase][0];
|
||||
const Icon = phase === "paused" ? Pause : Loader2;
|
||||
return (
|
||||
<span key={phase} data-active={phase === state} className="agent-pause-label absolute inset-y-0 left-2 flex w-max items-center gap-1">
|
||||
<Icon className={phase !== "paused" && phase === state ? "size-3 motion-safe:animate-spin" : "size-3"} />
|
||||
{label}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export function AgentLifecycleStatus({ agent, onRetry, retryPending, refreshError = false }: {
|
||||
agent: Pick<Agent, "lifecycleState" | "lifecycleError">;
|
||||
onRetry: () => void;
|
||||
retryPending: boolean;
|
||||
refreshError?: boolean;
|
||||
}) {
|
||||
const phase = pendingPhase(agent.lifecycleState);
|
||||
const inline = !agent.lifecycleError && (agent.lifecycleState === "pausing" || agent.lifecycleState === "resuming");
|
||||
const phase = inline ? undefined : pendingPhase(agent.lifecycleState);
|
||||
if (!phase && !refreshError) return null;
|
||||
return <div role="status" aria-live="polite" className="space-y-2 text-sm">
|
||||
{refreshError && <p className="text-destructive">Could not refresh agent lifecycle status.</p>}
|
||||
@@ -60,7 +97,7 @@ export function AgentLifecycleStatus({ agent, onRetry, retryPending, refreshErro
|
||||
{!agent.lifecycleError && <Loader2 aria-hidden="true" className="mr-1 size-3 animate-spin motion-reduce:animate-none" />}
|
||||
{agent.lifecycleError ? failedPhases[agent.lifecycleState as keyof typeof failedPhases] : phase[0]}
|
||||
</Badge>
|
||||
{!agent.lifecycleError && <span className="text-muted-foreground">{phase[1]}</span>}
|
||||
{!agent.lifecycleError && phase[1] && <span className="text-muted-foreground">{phase[1]}</span>}
|
||||
</div>}
|
||||
{phase && agent.lifecycleError && <div className="flex flex-wrap items-center gap-2 text-destructive">
|
||||
<span>{agent.lifecycleError}</span>
|
||||
|
||||
+27
-1
@@ -481,7 +481,8 @@
|
||||
--motion-pane-reveal: var(--motion-duration-slow);
|
||||
--motion-ease-pane-reveal: var(--motion-ease-out-expo);
|
||||
--motion-pane-width-reset: 200ms;
|
||||
--motion-ease-pane-width-reset: ease-in-out;
|
||||
--motion-ease-in-out: ease-in-out;
|
||||
--motion-ease-pane-width-reset: var(--motion-ease-in-out);
|
||||
--motion-side-panel-tab: var(--motion-duration-fast);
|
||||
|
||||
/* Portable side-panel geometry and hierarchy. These stay centralized so
|
||||
@@ -5725,6 +5726,31 @@ html:has(.design-proposal-theme) .agent-markdown-name-field [data-slot="input"],
|
||||
|
||||
.agent-identity-preview-title { font-weight: var(--agent-identity-preview-title-weight); }
|
||||
|
||||
.agent-pause-status {
|
||||
--pause-travel-duration: calc(var(--motion-duration-instant) * 3);
|
||||
width: calc(var(--pause-label-width, 0px) + var(--spacing) * 4);
|
||||
}
|
||||
.agent-pause-status[data-visible="false"] {
|
||||
width: calc(var(--spacing) * 6);
|
||||
opacity: 0;
|
||||
}
|
||||
.agent-pause-label { opacity: 0; }
|
||||
.agent-pause-label[data-active="true"] { opacity: 1; }
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.agent-pause-status {
|
||||
transition: width var(--pause-travel-duration) var(--motion-ease-in-out),
|
||||
opacity var(--pause-travel-duration) linear;
|
||||
}
|
||||
.agent-pause-label {
|
||||
transition: opacity calc(var(--motion-duration-instant) / 2) linear;
|
||||
}
|
||||
.agent-pause-label[data-active="true"] {
|
||||
transition-duration: var(--motion-duration-instant);
|
||||
transition-delay: var(--motion-duration-fast);
|
||||
}
|
||||
}
|
||||
|
||||
/* Tighten the header’s surrounding vertical space by one spacing step per edge. */
|
||||
.agent-character-header {
|
||||
margin-block-start: calc(var(--spacing) * -1);
|
||||
|
||||
@@ -48,7 +48,7 @@ import { useAdapterCapabilities } from "@/adapters/use-adapter-capabilities";
|
||||
import { MarkdownEditor } from "../components/MarkdownEditor";
|
||||
import { assetsApi } from "../api/assets";
|
||||
import { StatusBadge } from "../components/StatusBadge";
|
||||
import { AgentLifecycleStatus, useAgentLifecycleStatus } from "../components/AgentLifecycleStatus";
|
||||
import { AgentPausePill, AgentLifecycleStatus, useAgentLifecycleStatus } from "../components/AgentLifecycleStatus";
|
||||
import { MarkdownBody } from "../components/MarkdownBody";
|
||||
import { CopyText } from "../components/CopyText";
|
||||
import { IssueRow } from "../components/IssueRow";
|
||||
@@ -351,6 +351,14 @@ export function AgentDetail() {
|
||||
const queryClient = useQueryClient();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const previewPause = import.meta.env.DEV && new URLSearchParams(location.search).get("preview") === "pause";
|
||||
const [previewPhase, setPreviewPhase] = useState<"ready" | "pausing" | "paused" | "resuming">("ready");
|
||||
const previewPending = previewPhase === "pausing" || previewPhase === "resuming";
|
||||
useEffect(() => {
|
||||
if (!previewPause || (previewPhase !== "pausing" && previewPhase !== "resuming")) return;
|
||||
const timer = window.setTimeout(() => setPreviewPhase(previewPhase === "pausing" ? "paused" : "ready"), 1800);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [previewPause, previewPhase]);
|
||||
const [actionError, setActionError] = useState<string | null>(null);
|
||||
const [dismissedLeftAgentIds, setDismissedLeftAgentIds] = useState<Set<string>>(() => new Set());
|
||||
const activeView: AgentDetailView = urlRunId ? "run-detail"
|
||||
@@ -792,6 +800,10 @@ export function AgentDetail() {
|
||||
const agentStarPending = agentMembershipPending && membershipMutation.variables?.starred !== undefined;
|
||||
const agentJoinLeavePending = agentMembershipPending && membershipMutation.variables?.starred === undefined;
|
||||
|
||||
const pauseState = previewPause ? previewPhase : currentAgent.lifecycleState ?? currentAgent.status;
|
||||
const showPausePill = (previewPause || !currentAgent.lifecycleError)
|
||||
&& (pauseState === "pausing" || pauseState === "paused" || pauseState === "resuming");
|
||||
|
||||
return (
|
||||
<div className={cn("agent-settings-content mx-auto max-w-5xl space-y-8", `agent-settings-${activeView}`, showConfigActionBar && "agent-settings-with-save-bar")}>
|
||||
{showLeftAgentNotice ? (
|
||||
@@ -874,6 +886,7 @@ export function AgentDetail() {
|
||||
onSave={(name) => saveHeaderField({ name })}
|
||||
/>
|
||||
<PrimaryAgentCrownButton agent={agent} />
|
||||
<AgentPausePill state={showPausePill ? pauseState : undefined} />
|
||||
</div>
|
||||
<div className="mt-1 flex min-w-0 items-center gap-2 text-sm leading-5 text-muted-foreground">
|
||||
<Link
|
||||
@@ -896,9 +909,22 @@ export function AgentDetail() {
|
||||
onSave={(title) => saveHeaderField({ title: title || null })}
|
||||
/>
|
||||
</div>
|
||||
<AgentLifecycleStatus agent={currentAgent} refreshError={lifecycle.isError} onRetry={() => agentAction.mutate("retryLifecycle")} retryPending={agentAction.isPending} />
|
||||
<AgentLifecycleStatus
|
||||
agent={currentAgent}
|
||||
refreshError={lifecycle.isError}
|
||||
onRetry={() => agentAction.mutate("retryLifecycle")}
|
||||
retryPending={agentAction.isPending}
|
||||
/>
|
||||
</div>
|
||||
<AgentActionButtons
|
||||
{previewPause ? (
|
||||
<Button
|
||||
variant="outline"
|
||||
disabled={previewPending}
|
||||
onClick={() => setPreviewPhase(previewPhase === "paused" ? "resuming" : "pausing")}
|
||||
>
|
||||
{previewPhase === "paused" || previewPhase === "resuming" ? "Preview resume" : "Preview pause"}
|
||||
</Button>
|
||||
) : <AgentActionButtons
|
||||
agent={currentAgent}
|
||||
companyId={resolvedCompanyId}
|
||||
assignLabel="New task"
|
||||
@@ -943,7 +969,7 @@ export function AgentDetail() {
|
||||
<span className="text-(length:--text-micro) font-medium text-blue-600 dark:text-blue-400">Live</span>
|
||||
</Link>
|
||||
)}
|
||||
</AgentActionButtons>
|
||||
</AgentActionButtons>}
|
||||
</header>
|
||||
<AgentHistoryDialog agent={agent} companyId={resolvedCompanyId ?? undefined} open={historyOpen} onOpenChange={setHistoryOpen} />
|
||||
<AlertDialog open={pendingLeave !== null} onOpenChange={(open) => (open ? undefined : setPendingLeave(null))}>
|
||||
|
||||
Reference in new issue
Block a user