mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-10 11:01:23 +01:00
## Thinking Path > - Paperclip lets people manage agent work through the board. > - The board reads task, agent, settings, plugin, and run data from the server. > - A deploy can interrupt those reads after content is already visible. > - Local error branches can replace that content with an error or show raw codes. > - This pull request moves the remaining reads to the shared recovery behavior. > - The query-error guard prevents new local error patterns from returning. ## Linked Issues or Issue Description **What happened?** Loaded lists, settings, task panels, and manual reads could clear their content or show errors during a server restart. Some reads also disabled the shared retry policy. **Expected behavior** Keep loaded content during a temporary failure. Show the shared connection banner. Retry reads after recovery. Replace content after a real access denial or missing resource, with readable copy. **Steps to reproduce** Open a task, settings page, or run log. Return 503 with `tenant_app_unavailable` from the API. Restore the API and check that content refreshes. Repeat with 403 and 404 to check the failure state. Related merged work: Refs #15754, Refs #15772, Refs #17960. This change covers remaining reads and enforcement. Browser persistence and the outage browser suite follow separately. ## What Changed - Repair an existing PostgreSQL deadline fixture at UTC boundaries. A daily cap defers a heartbeat until both its original interval and the next UTC day allow it. Keep the counted run in its seeded day and cover noon, just before midnight and the first second after midnight with explicit clocks and real PostgreSQL. Production scheduling is unchanged. - Integrate the saved list, settings, shell, task, and manual-read recovery changes against current master. Preserve the current task, Inbox, and run-log structure. - Add `useResilientFetch` for component-local reads. Preserve loaded data, cancel stale requests, and retry through the shared connectivity policy. Keep browser and pairing capabilities in memory. - Retain run log chunks across stream changes and catch up after recovery without duplicate chunks or stalled requests. - Keep genuine authorization and missing-resource failures visible. Translate known single-word codes such as `forbidden`. Show known skills and disconnected-app failures before sibling loading states. Keep Retry bound to its failed request. - Make the query-error guard enforce by default and run it in the CI policy job. Document the narrow exceptions and the read recovery contract. - Invalidate pending OAuth discovery when the operator leaves setup or its context changes. Keep reserved-popup cleanup bound to the current attempt. ## Verification - Current read head `09d1db29dea` is merge-ready: all 59 check runs are completed (54 successful, three skipped, two neutral), the legacy Snyk status is successful, and both required `ci / verify` and `ci / e2e` gates pass. Greptile Apex reviewed this exact head at 5/5 with no unresolved threads; the branch has no merge conflicts. The current CI run is `41748339602`. - Current read head `09d1db29dea` includes master `683fa4725e9`. The latest change touches only the existing server deadline test fixture. Application source remains the previously verified `86376fa751e` revision: all 60 affected skills/disconnected-app tests and both application UI typechecks passed, along with token gates and the enforcing query-error guard. Those UI suites were not repeated for this test-only repair. - The fixture repair passes all seven deadline integration cases and the complete server typecheck, including the server test layer. The old assertion deterministically fails at 23:59:06.888 UTC; its one-second-old run also fails the first-second-of-day probe. The corrected fixture passes noon and both midnight probes. The permanent three-case coverage uses seeded 2099 clocks. - Twelve new regressions fail against the previous implementation. Both skills variants and disconnected-app pages show either request's 403 or 429 while the sibling pauses or remains fetching. Permission failures stay visible. Retry stays usable for its failed request and recovers independently. An initial test-fixture query-key typo was corrected before the passing run. The finding is replied to and resolved. Greptile reviewed prior application revision `86376fa751e` at 5/5 with no new actionable findings or unresolved threads. The current test-only head has now received its own Apex 5/5 review with no unresolved threads, and its CI is successful as recorded above. - The preceding OAuth fix passed all 237 setup tests on both application branches. Its ten regressions prove that Back, Cancel, unmount, or context changes retire initial discovery without creating a connection, caching old identities, navigating an abandoned popup, or closing a newer attempt. - Earlier master integration `e992f770339` passed all 309 tests across eight affected Slack, recovery, retry, submission and task files, plus UI typecheck, token gates, enforcing query-error scan and seven guard tests. The integration preserves Slack workspace reconnect and shared recovery, readable execution errors, source-inspection company scoping, and current submission behavior. Newly inherited retained-file recovery controls keep cached data through transient failures and hide it after definitive denial. - The preceding cache head `97c0bc3966f` passed 1,038 focused cache/write/editor/account/task/API tests. All 22 built-UI outage/write/loading cases passed in 4.7 minutes on exact browser head `b7deaaee5da`, with strict checking of all three specs. The latest skills/app rendering fix is covered by its affected component suites; those broader cases were not repeated for this separate read path. - Historical broader UI, CLI and build results and unresolved aggregate server/DB/adapter failures remain in the PR discussion. Interrupted CI runs were audited and recorded separately; they are not counted as passes. Controlled local outages do not prove hosted authentication or a real Cloud restart/deploy. Real hosted acceptance remains required after merge and deployment. Commands for the latest fix: ```sh pnpm --filter @paperclipai/ui exec vitest run src/pages/CompanySkills.test.tsx src/pages/apps/AppNotConnected.test.tsx pnpm --filter @paperclipai/ui typecheck pnpm check:token-gates node scripts/check-query-error-rendering.mjs --enforce --summary ``` ## Risks This migration touches many read surfaces. The main risks are initial loading, request cancellation, retained authorization state, and run-log paging. The tests cover those states. There are no server, schema, dependency, or API contract changes. The follow-up browser suite and hosted deploy acceptance are required before release acceptance. Recovered commits retain their original authors. If squash-merging, preserve `Co-Authored-By: Bender (Fable) <bender@agents.paperclip.ing>` and the Paperclip trailer. ## Model Used OpenAI `gpt-6.1-sol` through Codex, with xhigh reasoning effort, tool use, and code execution. The context window size is not exposed. Saved source commits keep their original authorship. ## 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 described the issue in-PR following the bug report template - [x] I have not referenced internal/instance-local Paperclip issues or links - [x] My branch name describes the change and contains no internal ticket id - [x] The affected local tests pass; broader limitations are recorded above - [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 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: devinfoley <139239+devinfoley@users.noreply.github.com> Co-authored-by: Paperclip <noreply@paperclip.ing> Co-authored-by: Bender (Fable) <bender@agents.paperclip.ing> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
505 lines
20 KiB
TypeScript
505 lines
20 KiB
TypeScript
import { useEffect, useMemo, useState } from "react";
|
|
import { Link } from "@/lib/router";
|
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import type {
|
|
SummarySlotDocument,
|
|
SummarySlotIssueRef,
|
|
SummarySlotKey,
|
|
SummarySlotRevision,
|
|
SummarySlotScopeKind,
|
|
} from "@paperclipai/shared";
|
|
import { Bot, Clock3, History, Loader2, RefreshCw, Sparkles } from "lucide-react";
|
|
|
|
import { agentsApi } from "@/api/agents";
|
|
import { builtInAgentsApi, type BuiltInAgentState } from "@/api/builtInAgents";
|
|
import { instanceSettingsApi } from "@/api/instanceSettings";
|
|
import { summarySlotsApi, type SummarySlotSelector } from "@/api/summarySlots";
|
|
import { MarkdownBody } from "@/components/MarkdownBody";
|
|
import { QueryErrorState, useQueryView } from "@/components/QueryView";
|
|
import { ConfigureBuiltInAgentModal } from "@/components/ConfigureBuiltInAgentModal";
|
|
import { InlineBanner } from "@/components/InlineBanner";
|
|
import { describeError } from "@/api/errors";
|
|
import { useSummaryDraftStream } from "@/components/useSummaryDraftStream";
|
|
import { useCompanyLiveEvent } from "@/context/LiveUpdatesProvider";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Select, SelectContent, SelectItem, SelectSeparator, SelectTrigger, SelectValue } from "@/components/ui/select";
|
|
import { queryKeys } from "@/lib/queryKeys";
|
|
import { cn, formatDateTime, relativeTime } from "@/lib/utils";
|
|
|
|
const SUMMARIZER_KEY = "summarizer";
|
|
const TERMINAL_ISSUE_STATUSES = new Set(["done", "cancelled"]);
|
|
const LATEST_REVISION_SELECT_VALUE = "__latest__";
|
|
const MAX_REVISION_OPTIONS = 30;
|
|
|
|
export interface SummarySlotCardProps {
|
|
companyId: string | null | undefined;
|
|
scopeKind: SummarySlotScopeKind;
|
|
scopeId?: string | null;
|
|
slotKey?: SummarySlotKey;
|
|
title: string;
|
|
description?: string;
|
|
className?: string;
|
|
}
|
|
|
|
function issueLabel(issue: SummarySlotIssueRef) {
|
|
return issue.identifier ? `${issue.identifier}: ${issue.title}` : issue.title;
|
|
}
|
|
|
|
function revisionLabel(revision: SummarySlotRevision) {
|
|
return `Rev ${revision.revisionNumber}`;
|
|
}
|
|
|
|
function formatRevisionTimestamp(date: Date | string) {
|
|
return new Intl.DateTimeFormat("en-US", {
|
|
month: "short",
|
|
day: "numeric",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
hourCycle: "h23",
|
|
}).format(new Date(date)).replace(",", "");
|
|
}
|
|
|
|
function revisionOptionLabel(revision: SummarySlotRevision) {
|
|
return `${revisionLabel(revision)} - ${formatRevisionTimestamp(revision.createdAt)}`;
|
|
}
|
|
|
|
function latestRevisionOptionLabel(
|
|
document: SummarySlotDocument,
|
|
revision: SummarySlotRevision | null,
|
|
) {
|
|
return `Latest (Rev ${document.latestRevisionNumber}) - ${
|
|
formatRevisionTimestamp(revision?.createdAt ?? document.updatedAt)
|
|
}`;
|
|
}
|
|
|
|
interface LiveGenerationStatus {
|
|
message: string | null;
|
|
currentToolName: string | null;
|
|
lastAssistantSnippet: string | null;
|
|
}
|
|
|
|
function readPayloadString(value: unknown): string | null {
|
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
}
|
|
|
|
/**
|
|
* Pick the single most useful line to show while a summary is generating.
|
|
* Prefers the server-derived status `message`, then the last streamed
|
|
* assistant snippet, then the active tool name. Returns null when nothing
|
|
* has streamed yet so the card falls back to its static generating text.
|
|
*/
|
|
export function resolveGenerationStatusLine(status: LiveGenerationStatus | null): string | null {
|
|
if (!status) return null;
|
|
if (status.message) return status.message;
|
|
if (status.lastAssistantSnippet) return status.lastAssistantSnippet;
|
|
if (status.currentToolName) return `Working with ${status.currentToolName}`;
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Subscribe to the shared LiveUpdates socket and track the generation run's
|
|
* live status derived from `heartbeat.run.progress` events matching the slot's
|
|
* generating issue. Resets whenever the tracked generation changes, and stays
|
|
* null (static fallback) when no events arrive.
|
|
*/
|
|
function useGenerationStatus(generatingIssueId: string | null): LiveGenerationStatus | null {
|
|
const [status, setStatus] = useState<LiveGenerationStatus | null>(null);
|
|
|
|
useEffect(() => {
|
|
setStatus(null);
|
|
}, [generatingIssueId]);
|
|
|
|
useCompanyLiveEvent((event) => {
|
|
if (!generatingIssueId) return;
|
|
if (event.type !== "heartbeat.run.progress") return;
|
|
const payload = event.payload ?? {};
|
|
if (payload.issueId !== generatingIssueId) return;
|
|
setStatus({
|
|
message: readPayloadString(payload.message),
|
|
currentToolName: readPayloadString(payload.currentToolName),
|
|
lastAssistantSnippet: readPayloadString(payload.lastAssistantSnippet),
|
|
});
|
|
});
|
|
|
|
return generatingIssueId ? status : null;
|
|
}
|
|
|
|
function setupState(state: BuiltInAgentState | undefined) {
|
|
if (!state) return null;
|
|
return state.status === "not_provisioned"
|
|
|| state.status === "needs_setup"
|
|
|| state.status === "pending_approval"
|
|
? state
|
|
: null;
|
|
}
|
|
|
|
export function SummarySlotCard({
|
|
companyId,
|
|
scopeKind,
|
|
scopeId = null,
|
|
slotKey = "header",
|
|
title,
|
|
description,
|
|
className,
|
|
}: SummarySlotCardProps) {
|
|
const queryClient = useQueryClient();
|
|
const [selectedRevisionId, setSelectedRevisionId] = useState<string | null>(null);
|
|
const [configureOpen, setConfigureOpen] = useState(false);
|
|
const [actionError, setActionError] = useState<string | null>(null);
|
|
const selector: SummarySlotSelector | null = companyId
|
|
? { companyId, scopeKind, scopeId, slotKey }
|
|
: null;
|
|
|
|
const experimentalQuery = useQuery({
|
|
queryKey: queryKeys.instance.experimentalSettings,
|
|
queryFn: () => instanceSettingsApi.getExperimental(),
|
|
});
|
|
const summariesEnabled = experimentalQuery.data?.enableSummaries === true;
|
|
const builtInAgentsEnabled = experimentalQuery.data?.enableBuiltInAgents === true;
|
|
|
|
const builtInAgentsQuery = useQuery({
|
|
queryKey: queryKeys.builtInAgents.list(companyId ?? "__none__"),
|
|
queryFn: () => builtInAgentsApi.list(companyId!),
|
|
enabled: Boolean(companyId && summariesEnabled && builtInAgentsEnabled),
|
|
});
|
|
|
|
const summarizerState = builtInAgentsQuery.data?.find(
|
|
(entry) => entry.definition.key === SUMMARIZER_KEY,
|
|
);
|
|
const needsSetup = setupState(summarizerState);
|
|
|
|
const slotQueryKey = selector
|
|
? queryKeys.summarySlots.detail(selector.companyId, selector.scopeKind, selector.slotKey, selector.scopeId)
|
|
: queryKeys.summarySlots.detail("__none__", scopeKind, slotKey, scopeId);
|
|
const revisionsQueryKey = selector
|
|
? queryKeys.summarySlots.revisions(selector.companyId, selector.scopeKind, selector.slotKey, selector.scopeId)
|
|
: queryKeys.summarySlots.revisions("__none__", scopeKind, slotKey, scopeId);
|
|
|
|
const slotQuery = useQuery({
|
|
queryKey: slotQueryKey,
|
|
queryFn: () => summarySlotsApi.get(selector!),
|
|
enabled: Boolean(selector && summariesEnabled),
|
|
refetchInterval: (query) => query.state.data?.slot?.status === "generating" ? 3_000 : false,
|
|
});
|
|
const slotView = useQueryView(slotQuery);
|
|
const slotReady = slotView.kind === "ready" || slotView.kind === "stale";
|
|
|
|
const revisionsQuery = useQuery({
|
|
queryKey: revisionsQueryKey,
|
|
queryFn: () => summarySlotsApi.revisions(selector!),
|
|
enabled: Boolean(selector && summariesEnabled && slotQuery.data?.document),
|
|
});
|
|
|
|
const generateMutation = useMutation({
|
|
mutationFn: () => summarySlotsApi.generate(selector!),
|
|
onMutate: () => setActionError(null),
|
|
onSuccess: async () => {
|
|
setSelectedRevisionId(null);
|
|
await Promise.all([
|
|
queryClient.invalidateQueries({ queryKey: slotQueryKey }),
|
|
queryClient.invalidateQueries({ queryKey: revisionsQueryKey }),
|
|
]);
|
|
},
|
|
onError: (error) => {
|
|
setActionError(error instanceof Error ? error.message : "Summary generation could not be started.");
|
|
},
|
|
});
|
|
|
|
const resumeSummarizer = useMutation({
|
|
mutationFn: (agentId: string) => agentsApi.resume(agentId, companyId ?? undefined),
|
|
onSuccess: async () => {
|
|
if (companyId) {
|
|
await queryClient.invalidateQueries({ queryKey: queryKeys.builtInAgents.list(companyId) });
|
|
}
|
|
},
|
|
});
|
|
|
|
const revisions = revisionsQuery.data?.revisions ?? [];
|
|
const latestDocument = slotQuery.data?.document ?? null;
|
|
const selectedRevision = useMemo(
|
|
() => revisions.find((revision) => revision.id === selectedRevisionId) ?? null,
|
|
[revisions, selectedRevisionId],
|
|
);
|
|
const latestRevision = latestDocument
|
|
? revisions.find((revision) => revision.id === latestDocument.latestRevisionId) ?? null
|
|
: null;
|
|
const historicalRevision = selectedRevision && selectedRevision.id !== latestDocument?.latestRevisionId
|
|
? selectedRevision
|
|
: null;
|
|
const displayedBody = historicalRevision?.body ?? latestDocument?.body ?? "";
|
|
const displayingHistoricalRevision = Boolean(historicalRevision);
|
|
const historicalRevisionOptions = (latestDocument
|
|
? revisions.filter((revision) => revision.id !== latestDocument.latestRevisionId)
|
|
: revisions)
|
|
.toSorted((left, right) => right.revisionNumber - left.revisionNumber)
|
|
.slice(0, MAX_REVISION_OPTIONS - (latestDocument ? 1 : 0));
|
|
const revisionSelectValue = historicalRevision?.id ?? LATEST_REVISION_SELECT_VALUE;
|
|
const latestSelectLabel = latestDocument ? latestRevisionOptionLabel(latestDocument, latestRevision) : "Latest";
|
|
const generatingIssue = slotQuery.data?.generatingIssue ?? null;
|
|
const liveStatusLine = resolveGenerationStatusLine(useGenerationStatus(generatingIssue?.id ?? null));
|
|
const draftStream = useSummaryDraftStream(companyId, generatingIssue);
|
|
// The token-streamed STATUS line is more responsive than the server-derived
|
|
// progress snippet; prefer it and fall back to the Phase 1 status line.
|
|
const generationStatusLine = draftStream.statusLine ?? liveStatusLine;
|
|
const isGenerating = slotQuery.data?.slot?.status === "generating"
|
|
&& generatingIssue
|
|
&& !TERMINAL_ISSUE_STATUSES.has(generatingIssue.status);
|
|
const generationFailed = slotQuery.data?.slot?.status === "failed";
|
|
const canGenerateFirstSummary = summarizerState?.status === "ready";
|
|
|
|
if (experimentalQuery.isLoading || !summariesEnabled) return null;
|
|
|
|
const startGeneration = () => {
|
|
if (!selector || generateMutation.isPending) return;
|
|
generateMutation.mutate();
|
|
};
|
|
|
|
return (
|
|
<section className={cn("space-y-4", className)}>
|
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
|
|
<div className="min-w-0 space-y-1">
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<Sparkles className="h-4 w-4 text-muted-foreground" aria-hidden="true" />
|
|
<h2 className="text-sm font-semibold">{title}</h2>
|
|
{isGenerating ? <Badge variant="secondary">Generating</Badge> : null}
|
|
{displayingHistoricalRevision ? <Badge variant="outline">Historical revision</Badge> : null}
|
|
{latestDocument && !displayingHistoricalRevision ? <Badge variant="outline">Latest revision</Badge> : null}
|
|
</div>
|
|
{description ? <p className="text-sm text-muted-foreground">{description}</p> : null}
|
|
</div>
|
|
<div className="flex shrink-0 flex-wrap items-center gap-2">
|
|
{displayingHistoricalRevision ? (
|
|
<Button
|
|
type="button"
|
|
size="sm"
|
|
variant="outline"
|
|
onClick={() => setSelectedRevisionId(null)}
|
|
>
|
|
Latest
|
|
</Button>
|
|
) : null}
|
|
{latestDocument && !generationFailed ? (
|
|
<Button
|
|
type="button"
|
|
size="sm"
|
|
variant="outline"
|
|
onClick={startGeneration}
|
|
disabled={!selector || generateMutation.isPending || Boolean(isGenerating)}
|
|
>
|
|
{generateMutation.isPending ? <Loader2 className="animate-spin" /> : <RefreshCw />}
|
|
Refresh
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
|
|
{needsSetup ? (
|
|
<>
|
|
<div className="flex flex-col items-start gap-3 rounded-lg border border-border bg-muted/30 p-4 sm:flex-row sm:items-center sm:justify-between">
|
|
<div className="flex items-start gap-3">
|
|
{needsSetup.status === "pending_approval" ? (
|
|
<Clock3 className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />
|
|
) : (
|
|
<Bot className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />
|
|
)}
|
|
<div className="space-y-1 text-sm">
|
|
<p className="font-medium text-foreground">
|
|
{needsSetup.status === "pending_approval"
|
|
? "Summarizer setup is pending approval"
|
|
: "Set up the Summarizer"}
|
|
</p>
|
|
<p className="text-muted-foreground">
|
|
Summaries are generated by Paperclip's built-in Summarizer agent. Configure its adapter and model
|
|
before requesting this summary.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
{needsSetup.status === "pending_approval" ? null : (
|
|
<Button type="button" size="sm" onClick={() => setConfigureOpen(true)}>
|
|
Set up Summarizer
|
|
</Button>
|
|
)}
|
|
</div>
|
|
{companyId ? (
|
|
<ConfigureBuiltInAgentModal
|
|
companyId={companyId}
|
|
state={needsSetup}
|
|
open={configureOpen}
|
|
onOpenChange={setConfigureOpen}
|
|
onConfigured={() => setActionError(null)}
|
|
/>
|
|
) : null}
|
|
</>
|
|
) : null}
|
|
|
|
{!needsSetup && summarizerState?.status === "paused" && summarizerState.agent ? (
|
|
<InlineBanner
|
|
tone="warning"
|
|
title="Summarizer is paused"
|
|
actions={
|
|
<Button
|
|
type="button"
|
|
size="sm"
|
|
onClick={() => summarizerState.agent && resumeSummarizer.mutate(summarizerState.agent.id)}
|
|
disabled={resumeSummarizer.isPending}
|
|
>
|
|
{resumeSummarizer.isPending ? "Resuming..." : "Resume agent"}
|
|
</Button>
|
|
}
|
|
>
|
|
Existing summaries remain readable, but new summaries will not be generated until the agent resumes.
|
|
</InlineBanner>
|
|
) : null}
|
|
|
|
{actionError ? (
|
|
<InlineBanner tone="warning" title="Summary request failed">
|
|
{actionError}
|
|
</InlineBanner>
|
|
) : null}
|
|
|
|
{slotView.kind === "error" ? (
|
|
<QueryErrorState
|
|
size="panel"
|
|
error={slotView.error}
|
|
action="load the summary"
|
|
onRetry={slotView.retry}
|
|
retrying={slotView.isFetching}
|
|
/>
|
|
) : null}
|
|
|
|
{slotReady && generationFailed ? (
|
|
<InlineBanner
|
|
tone="danger"
|
|
title="Summary generation failed"
|
|
actions={
|
|
<Button
|
|
type="button"
|
|
size="sm"
|
|
onClick={startGeneration}
|
|
disabled={!selector || generateMutation.isPending}
|
|
>
|
|
{generateMutation.isPending ? "Retrying..." : "Retry"}
|
|
</Button>
|
|
}
|
|
>
|
|
{slotQuery.data?.slot?.failureReason ?? "The generation task ended before writing a summary."}
|
|
</InlineBanner>
|
|
) : null}
|
|
|
|
{slotReady && isGenerating && generatingIssue ? (
|
|
<div className="flex items-start gap-3 text-sm">
|
|
<Loader2 className="mt-0.5 h-4 w-4 shrink-0 animate-spin text-muted-foreground" />
|
|
<div className="min-w-0 space-y-1">
|
|
<p className="font-medium text-foreground">Generating summary</p>
|
|
{generationStatusLine ? (
|
|
<p
|
|
className="animate-pulse truncate text-muted-foreground"
|
|
aria-live="polite"
|
|
data-testid="summary-generation-status-line"
|
|
title={generationStatusLine}
|
|
>
|
|
{generationStatusLine}
|
|
</p>
|
|
) : null}
|
|
{draftStream.draft ? (
|
|
<div
|
|
className="mt-2 rounded-md border border-border bg-muted/20 p-3"
|
|
data-testid="summary-generation-draft"
|
|
aria-live="polite"
|
|
>
|
|
<MarkdownBody className="text-sm leading-7 text-foreground">
|
|
{draftStream.draft}
|
|
</MarkdownBody>
|
|
{!draftStream.draftClosed ? (
|
|
<span
|
|
className="mt-1 inline-block h-4 w-px animate-pulse bg-foreground align-text-bottom"
|
|
aria-hidden="true"
|
|
data-testid="summary-generation-caret"
|
|
/>
|
|
) : null}
|
|
</div>
|
|
) : null}
|
|
<p className="text-muted-foreground">
|
|
Summarizer is working in{" "}
|
|
<Link className="underline" to={`/issues/${generatingIssue.identifier ?? generatingIssue.id}`}>
|
|
{issueLabel(generatingIssue)}
|
|
</Link>
|
|
.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
|
|
{slotReady && !latestDocument && !isGenerating && !generationFailed && canGenerateFirstSummary ? (
|
|
<div className="flex flex-col items-start gap-3 rounded-lg border border-border bg-muted/30 p-4 sm:flex-row sm:items-center sm:justify-between">
|
|
<div className="space-y-1 text-sm">
|
|
<p className="font-medium text-foreground">No summary yet</p>
|
|
<p className="text-muted-foreground">Generate a concise status snapshot for this surface.</p>
|
|
</div>
|
|
<Button
|
|
type="button"
|
|
size="sm"
|
|
onClick={startGeneration}
|
|
disabled={!selector || generateMutation.isPending}
|
|
>
|
|
{generateMutation.isPending ? <Loader2 className="animate-spin" /> : <Sparkles />}
|
|
{generateMutation.isPending ? "Generating..." : "Generate summary"}
|
|
</Button>
|
|
</div>
|
|
) : null}
|
|
|
|
{latestDocument ? (
|
|
<div className="space-y-4">
|
|
<MarkdownBody className="text-sm leading-7 text-foreground">
|
|
{displayedBody}
|
|
</MarkdownBody>
|
|
|
|
<div className="flex flex-col gap-3 text-xs text-muted-foreground sm:flex-row sm:items-center sm:justify-between">
|
|
<span title={formatDateTime(historicalRevision?.createdAt ?? latestRevision?.createdAt ?? latestDocument.updatedAt)}>
|
|
Updated {relativeTime(historicalRevision?.createdAt ?? latestRevision?.createdAt ?? latestDocument.updatedAt)}
|
|
</span>
|
|
|
|
{revisions.length > 1 ? (
|
|
<Select
|
|
value={revisionSelectValue}
|
|
onValueChange={(value) => {
|
|
setSelectedRevisionId(value === LATEST_REVISION_SELECT_VALUE ? null : value);
|
|
}}
|
|
>
|
|
<SelectTrigger
|
|
size="sm"
|
|
className="h-auto border-0 bg-transparent p-0 text-xs shadow-none hover:text-foreground focus-visible:ring-0"
|
|
aria-label="Select summary revision"
|
|
title={historicalRevision ? revisionOptionLabel(historicalRevision) : latestSelectLabel}
|
|
>
|
|
<SelectValue>
|
|
<History className="size-3.5" aria-hidden="true" />
|
|
<span>{revisions.length} revisions</span>
|
|
</SelectValue>
|
|
</SelectTrigger>
|
|
<SelectContent align="end" position="popper">
|
|
<SelectItem value={LATEST_REVISION_SELECT_VALUE} className="text-xs">
|
|
{latestSelectLabel}
|
|
</SelectItem>
|
|
{historicalRevisionOptions.length > 0 ? <SelectSeparator /> : null}
|
|
{historicalRevisionOptions.map((revision) => (
|
|
<SelectItem
|
|
key={revision.id}
|
|
value={revision.id}
|
|
className="text-xs"
|
|
title={formatDateTime(revision.createdAt)}
|
|
>
|
|
{revisionOptionLabel(revision)}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
</section>
|
|
);
|
|
}
|