mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-16 03:31:44 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Governed MCP access spans contracts, runtime enforcement, adapters, UI surfaces, and operator verification > - The parity reference PR #9534 is too large for effective automated or human review > - The feature therefore needs a linear stack whose individual diffs stay below the 100-file review limit > - This pull request is split 7/8 and focuses on Apps/Gateways UI and feature-flagged activation > - The benefit is a standalone, testable review boundary while preserving byte-for-byte parity at the top of the stack ## Linked Issues or Issue Description - Related parity reference: #9534 - Problem: The standalone UI foundation needs feature-flagged routes, navigation, app detail flows, gateways, Storybook scenarios, and QA configuration. - Proposed solution: Adds Apps/Gateways pages and components, navigation/route activation, remaining page integrations, Storybook stories, and QA Vite configuration. - Alternatives considered: keeping #9534 as one 403-file review, or rewriting the feature to manufacture seams; both were rejected in favor of path extraction plus compile-driven boundary moves. - Roadmap alignment: this advances the existing governed MCP/tool-access work already represented by #9534; it does not introduce a separate roadmap initiative. - Stack position: base branch is `pap10341-split/06-ui-tools-foundation`. - Merge policy: merge bottom-up, in order, only after the complete eight-PR stack has been reviewed and the top-of-stack parity gate remains empty. - Requested review: UXDesigner sanity pass on Apps/Gateways flows and flag-off behavior; Greptile on every PR. ## What Changed - Adds Apps/Gateways pages and components, navigation/route activation, remaining page integrations, Storybook stories, and QA Vite configuration. - Keeps this PR below 100 changed files and independently typecheckable. - Preserves the final tree from #9534 when combined with the other seven stack levels. ## Verification - `pnpm typecheck` - `pnpm check:token-gates` — all gates clean - Focused UI Vitest run with `NODE_ENV=test` — 17 files, 147 tests passed ## Risks - Navigation or flag regressions could expose incomplete experiences; activation remains controlled by existing experimental settings. - Stack risk: merging out of order can expose incomplete layers; mitigate by following the documented bottom-up merge policy. - Parity risk: later edits to an intermediate branch can drift from #9534; mitigate by re-running the empty top-of-stack diff before merge. > 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, exact model ID `gpt-5.4`; runtime-managed context window; medium reasoning with repository, shell, Git, GitHub CLI, and code-execution tools enabled. ## 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] Internal references are omitted except the execution-plan link explicitly required for this coordinated split stack - [x] My branch name describes the change 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 ## Stack Coordination - Internal execution plan: [PAP-13874](/PAP/issues/PAP-13874#document-plan) - Parity reference: #9534 - Stack: #9556 → #9557 → #9558 → #9559 → #9560 → #9561 → #9562 → #9563 - Merge bottom-up only after full-stack review and an empty parity diff at #9563. ## UI Evidence QA captured these from the live Garden MCP split stack at 1440px and verified clean rendering:    --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
372 lines
13 KiB
TypeScript
372 lines
13 KiB
TypeScript
import { useEffect, useMemo } from "react";
|
||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||
import type { ToolConnection } from "@paperclipai/shared";
|
||
import { Navigate, useNavigate, useParams } from "@/lib/router";
|
||
import { useCompany } from "@/context/CompanyContext";
|
||
import { useBreadcrumbs } from "@/context/BreadcrumbContext";
|
||
import { useToast } from "@/context/ToastContext";
|
||
import { queryKeys } from "@/lib/queryKeys";
|
||
import { timeAgo } from "@/lib/timeAgo";
|
||
import { toolsApi } from "@/api/tools";
|
||
import { agentsApi } from "@/api/agents";
|
||
import { Button } from "@/components/ui/button";
|
||
import { Skeleton } from "@/components/ui/skeleton";
|
||
import { AppLogo } from "./AppLogo";
|
||
import { connectionAddress, connectionTransportLabel, DangerZone } from "./AppDetail";
|
||
import { ActivityPanel } from "./app-detail/ActivityPanel";
|
||
import { ReviewPanel } from "./app-detail/ReviewPanel";
|
||
import { appApplicationTabHref, appTabHref, appTabLabel, isAppTabKey, type AppTabKey } from "./app-tabs";
|
||
|
||
export function AppNotConnected() {
|
||
const { applicationId = "", tab } = useParams<{ applicationId: string; tab?: string }>();
|
||
const navigate = useNavigate();
|
||
const queryClient = useQueryClient();
|
||
const { pushToast } = useToast();
|
||
const { selectedCompany, selectedCompanyId } = useCompany();
|
||
const { setBreadcrumbs } = useBreadcrumbs();
|
||
const activeTab: AppTabKey | null = isAppTabKey(tab) ? tab : null;
|
||
|
||
const applicationsQuery = useQuery({
|
||
queryKey: queryKeys.tools.applications(selectedCompanyId ?? "__none__"),
|
||
queryFn: () => toolsApi.listApplications(selectedCompanyId!),
|
||
enabled: !!selectedCompanyId && !!activeTab,
|
||
});
|
||
const connectionsQuery = useQuery({
|
||
queryKey: queryKeys.tools.connections(selectedCompanyId ?? "__none__"),
|
||
queryFn: () => toolsApi.listConnections(selectedCompanyId!),
|
||
enabled: !!selectedCompanyId && !!activeTab,
|
||
});
|
||
const galleryQuery = useQuery({
|
||
queryKey: queryKeys.apps.gallery(selectedCompanyId ?? "__none__"),
|
||
queryFn: () => toolsApi.listGallery(selectedCompanyId!),
|
||
enabled: !!selectedCompanyId && !!activeTab,
|
||
});
|
||
|
||
const application = useMemo(
|
||
() => (applicationsQuery.data?.applications ?? []).find((app) => app.id === applicationId),
|
||
[applicationsQuery.data, applicationId],
|
||
);
|
||
const appConnections = useMemo(
|
||
() => (connectionsQuery.data?.connections ?? []).filter((c) => c.applicationId === applicationId),
|
||
[connectionsQuery.data, applicationId],
|
||
);
|
||
const activeConnection = appConnections.find((c) => c.status !== "archived") ?? null;
|
||
const previousConnection = useMemo(() => latestArchivedConnection(appConnections), [appConnections]);
|
||
const activityQuery = useQuery({
|
||
queryKey: queryKeys.tools.connectionActivity(previousConnection?.id ?? "__none__"),
|
||
queryFn: () => toolsApi.listConnectionActivity(previousConnection!.id, 20),
|
||
enabled: !!previousConnection && activeTab === "activity",
|
||
});
|
||
const agentsQuery = useQuery({
|
||
queryKey: queryKeys.agents.list(selectedCompanyId ?? "__none__"),
|
||
queryFn: () => agentsApi.list(selectedCompanyId!),
|
||
enabled: !!selectedCompanyId && activeTab === "activity",
|
||
});
|
||
|
||
const appName = application?.name ?? "App";
|
||
useEffect(() => {
|
||
if (!activeTab) return;
|
||
setBreadcrumbs([
|
||
{ label: selectedCompany?.name ?? "Company", href: "/dashboard" },
|
||
{ label: "Apps", href: "/apps" },
|
||
{ label: appName, href: appApplicationTabHref(applicationId, "setup") },
|
||
{ label: appTabLabel(activeTab) },
|
||
]);
|
||
return () => setBreadcrumbs([]);
|
||
}, [setBreadcrumbs, selectedCompany?.name, appName, applicationId, activeTab]);
|
||
|
||
const remove = useMutation({
|
||
mutationFn: () => toolsApi.updateApplication(applicationId, { status: "archived" }),
|
||
onSuccess: () => {
|
||
queryClient.invalidateQueries({ queryKey: queryKeys.tools.applications(selectedCompanyId ?? "__none__") });
|
||
pushToast({
|
||
title: "App removed",
|
||
body: `${appName} no longer shows in your apps. You can connect it again any time.`,
|
||
tone: "success",
|
||
});
|
||
navigate("/apps");
|
||
},
|
||
onError: (error) => {
|
||
pushToast({
|
||
title: "Couldn’t remove the app",
|
||
body: error instanceof Error ? error.message : "Please try again.",
|
||
tone: "error",
|
||
});
|
||
},
|
||
});
|
||
|
||
if (!selectedCompanyId) {
|
||
return <div className="p-6 text-sm text-muted-foreground">Select a company to manage apps.</div>;
|
||
}
|
||
if (!applicationId || !activeTab) {
|
||
return <Navigate to={applicationId ? appApplicationTabHref(applicationId, "setup") : "/apps"} replace />;
|
||
}
|
||
if (applicationsQuery.isLoading || connectionsQuery.isLoading) {
|
||
return (
|
||
<div className="max-w-3xl space-y-3">
|
||
<Skeleton className="h-10 w-64" />
|
||
<Skeleton className="h-40 w-full" />
|
||
</div>
|
||
);
|
||
}
|
||
if (!application) {
|
||
return (
|
||
<div className="max-w-3xl space-y-3 p-6 text-sm text-muted-foreground">
|
||
<p>This app doesn’t exist anymore.</p>
|
||
<Button variant="outline" size="sm" onClick={() => navigate("/apps")}>Back to apps</Button>
|
||
</div>
|
||
);
|
||
}
|
||
if (activeConnection) {
|
||
return <Navigate to={appTabHref(activeConnection.id, activeTab)} replace />;
|
||
}
|
||
|
||
const gallery = galleryQuery.data?.apps ?? [];
|
||
const logoUrl =
|
||
(application.applicationKey ? gallery.find((entry) => entry.key === application.applicationKey)?.logoUrl : undefined) ??
|
||
gallery.find((entry) => entry.name.toLowerCase() === application.name.toLowerCase())?.logoUrl;
|
||
|
||
const previousAddress = previousConnection ? connectionAddress(previousConnection) : null;
|
||
const connectHref = reconnectHref({
|
||
applicationId,
|
||
appName: application.name,
|
||
previousAddress,
|
||
});
|
||
|
||
return (
|
||
<div className="max-w-3xl space-y-6 pb-12">
|
||
<ApplicationHeader applicationName={application.name} description={application.description} logoUrl={logoUrl} />
|
||
|
||
{activeTab === "setup" && (
|
||
<SetupTab
|
||
previousConnection={previousConnection}
|
||
previousAddress={previousAddress}
|
||
onConnect={() => navigate(connectHref)}
|
||
/>
|
||
)}
|
||
{activeTab === "review" && (
|
||
previousConnection ? (
|
||
<ReviewPanel connectionId={previousConnection.id} />
|
||
) : (
|
||
<EmptyTab
|
||
title="Nothing is waiting for your OK right now."
|
||
body="Review requests will appear here after this app is connected."
|
||
/>
|
||
)
|
||
)}
|
||
{activeTab === "permissions" && (
|
||
<PermissionsTab previousConnection={previousConnection} />
|
||
)}
|
||
{activeTab === "test" && (
|
||
<EmptyTab
|
||
title="Reconnect to test this app."
|
||
body="Testing becomes available after this app is connected again."
|
||
/>
|
||
)}
|
||
{activeTab === "activity" && (
|
||
previousConnection ? (
|
||
<ActivityPanel
|
||
events={activityQuery.data?.events ?? []}
|
||
lifecycleEvents={activityQuery.data?.lifecycleEvents ?? []}
|
||
issues={activityQuery.data?.issues ?? {}}
|
||
actionRequests={activityQuery.data?.actionRequests ?? {}}
|
||
loading={activityQuery.isLoading}
|
||
agents={agentsQuery.data ?? []}
|
||
connectionId={previousConnection.id}
|
||
appName={appName}
|
||
/>
|
||
) : (
|
||
<ActivityPanel
|
||
events={[]}
|
||
lifecycleEvents={[]}
|
||
issues={{}}
|
||
actionRequests={{}}
|
||
loading={false}
|
||
agents={[]}
|
||
connectionId=""
|
||
appName={appName}
|
||
/>
|
||
)
|
||
)}
|
||
{activeTab === "advanced" && (
|
||
<AdvancedTab
|
||
appName={application.name}
|
||
previousConnection={previousConnection}
|
||
previousAddress={previousAddress}
|
||
removing={remove.isPending}
|
||
onRemove={() => remove.mutate()}
|
||
/>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function ApplicationHeader({
|
||
applicationName,
|
||
description,
|
||
logoUrl,
|
||
}: {
|
||
applicationName: string;
|
||
description: string | null;
|
||
logoUrl: string | undefined;
|
||
}) {
|
||
return (
|
||
<header className="flex flex-wrap items-center gap-4">
|
||
<AppLogo name={applicationName} logoUrl={logoUrl} size={48} />
|
||
<div className="min-w-0 flex-1">
|
||
<div className="flex items-center gap-2">
|
||
<h1 className="truncate text-2xl font-bold tracking-tight">{applicationName}</h1>
|
||
<span className="inline-flex items-center rounded-full border border-border bg-background px-2 py-0.5 text-xs font-medium text-muted-foreground">
|
||
Not connected
|
||
</span>
|
||
</div>
|
||
{description && (
|
||
<p className="mt-1 text-sm text-muted-foreground">{description}</p>
|
||
)}
|
||
</div>
|
||
</header>
|
||
);
|
||
}
|
||
|
||
function SetupTab({
|
||
previousConnection,
|
||
previousAddress,
|
||
onConnect,
|
||
}: {
|
||
previousConnection: ToolConnection | null;
|
||
previousAddress: string | null;
|
||
onConnect: () => void;
|
||
}) {
|
||
return (
|
||
<div className="space-y-6">
|
||
<section className="rounded-xl border border-border bg-card px-5 py-4">
|
||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||
<div>
|
||
<h2 className="text-sm font-bold text-foreground">
|
||
{previousConnection ? "Reconnect this app" : "Connect this app"}
|
||
</h2>
|
||
<p className="mt-0.5 text-sm text-muted-foreground">
|
||
{previousConnection
|
||
? "We kept the previous setup. Add a working key to bring it back online."
|
||
: "Agents can't use it until it's connected."}
|
||
</p>
|
||
</div>
|
||
<Button onClick={onConnect}>
|
||
{previousConnection ? "Reconnect" : "Connect"}
|
||
</Button>
|
||
</div>
|
||
</section>
|
||
|
||
{previousConnection && (
|
||
<PreviousSetup connection={previousConnection} previousAddress={previousAddress} />
|
||
)}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function PreviousSetup({
|
||
connection,
|
||
previousAddress,
|
||
}: {
|
||
connection: ToolConnection;
|
||
previousAddress: string | null;
|
||
}) {
|
||
return (
|
||
<section className="rounded-xl border border-border bg-card px-5 py-4">
|
||
<h2 className="text-sm font-bold text-foreground">Previous setup</h2>
|
||
{connection.healthMessage && (
|
||
<p className="mt-2 rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-300">
|
||
Last error: {connection.healthMessage}
|
||
</p>
|
||
)}
|
||
<dl className="mt-3 grid gap-2 text-xs sm:grid-cols-(--gtc-59)">
|
||
<dt className="text-muted-foreground">Address</dt>
|
||
<dd className="break-all font-mono text-foreground">{previousAddress}</dd>
|
||
<dt className="text-muted-foreground">Connection type</dt>
|
||
<dd className="text-foreground">{connectionTransportLabel(connection.transport)}</dd>
|
||
<dt className="text-muted-foreground">Last used</dt>
|
||
<dd className="text-foreground">
|
||
{connection.lastUsedAt ? timeAgo(connection.lastUsedAt) : "Never"}
|
||
</dd>
|
||
</dl>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function PermissionsTab({ previousConnection }: { previousConnection: ToolConnection | null }) {
|
||
return (
|
||
<section className="rounded-xl border border-border bg-card px-5 py-4">
|
||
<h2 className="text-sm font-bold text-foreground">Permissions paused</h2>
|
||
<p className="mt-1 text-sm text-muted-foreground">
|
||
Reconnect this app to edit who can use it and which actions need a human first.
|
||
</p>
|
||
{previousConnection && (
|
||
<p className="mt-3 text-xs text-muted-foreground">
|
||
Previous setup is retained for reconnect, but access controls stay read-only until the app is online.
|
||
</p>
|
||
)}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function AdvancedTab({
|
||
appName,
|
||
previousConnection,
|
||
previousAddress,
|
||
removing,
|
||
onRemove,
|
||
}: {
|
||
appName: string;
|
||
previousConnection: ToolConnection | null;
|
||
previousAddress: string | null;
|
||
removing: boolean;
|
||
onRemove: () => void;
|
||
}) {
|
||
return (
|
||
<div className="space-y-6">
|
||
{previousConnection ? (
|
||
<PreviousSetup connection={previousConnection} previousAddress={previousAddress} />
|
||
) : (
|
||
<EmptyTab
|
||
title="No previous connection details"
|
||
body="Technical details will appear here after this app is connected."
|
||
/>
|
||
)}
|
||
<DangerZone appName={appName} removing={removing} onRemove={onRemove} />
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function EmptyTab({ title, body }: { title: string; body: string }) {
|
||
return (
|
||
<section className="rounded-xl border border-border bg-card px-5 py-4">
|
||
<h2 className="text-sm font-bold text-foreground">{title}</h2>
|
||
<p className="mt-1 text-sm text-muted-foreground">{body}</p>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function latestArchivedConnection(connections: ToolConnection[]): ToolConnection | null {
|
||
const archived = connections.filter((c) => c.status === "archived");
|
||
if (archived.length === 0) return null;
|
||
return archived.reduce((latest, connection) => {
|
||
const latestTime = new Date(latest.updatedAt ?? latest.createdAt ?? 0).getTime();
|
||
const connectionTime = new Date(connection.updatedAt ?? connection.createdAt ?? 0).getTime();
|
||
return connectionTime > latestTime ? connection : latest;
|
||
});
|
||
}
|
||
|
||
function reconnectHref({
|
||
applicationId,
|
||
appName,
|
||
previousAddress,
|
||
}: {
|
||
applicationId: string;
|
||
appName: string;
|
||
previousAddress: string | null;
|
||
}): string {
|
||
const params = new URLSearchParams({ byo: "1", applicationId, name: appName });
|
||
if (previousAddress && /^https?:\/\//i.test(previousAddress)) params.set("link", previousAddress);
|
||
return `/apps/connect?${params.toString()}`;
|
||
}
|