mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-19 16:29:42 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Hosted Paperclip Cloud records browser sessions with PostHog session replay > - Replay masked all text and showed only an allowlist of chrome, so most replays showed only stars > - The team cannot see how people use the board, and the allowlist needed a review for each new label > - The owner decided to show text by default and mask only marked customer content, the way PostHog normally works > - This pull request flips the default, removes the allowlist, and marks every surface that can show connected-account content > - The benefit is readable replays, while Google user data and Slack data stay masked ## Linked Issues or Issue Description **Subsystem affected** Hosted Cloud browser analytics: PostHog session replay in the board UI (`ui/src/lib/analytics/`). **Problem or motivation** Replay masked every text node. Only sidebar items and opt-in components showed text. Replays were almost unreadable. Each new label needed an `analyticsChrome` opt-in and an allowlist review. **Proposed solution** Record text as it is. Mask text only inside `ph-mask` (customer content), `ph-no-capture` (secrets, blocked) and editable content. Add `ANALYTICS_MASK_CLASS` to every surface that can show connected-account content (Gmail, Calendar, Drive and Docs, Slack) or other free-form text from agents or customers. **Alternatives considered** Keep "mask all" and grow the allowlist. This needs a review for each label and still hides most of the board. ## What Changed - `privacy.ts`: `ANALYTICS_MASK_TEXT_SELECTOR` is now `.ph-mask, .ph-no-capture, [contenteditable]:not([contenteditable="false"])`. rrweb masks a text node only when its parent or an ancestor matches the selector. Removed `maskReplayText`, `isReplayTextRevealed`, `ANALYTICS_UNMASK_ATTRIBUTE` and `ANALYTICS_UNMASK_PROPS`. - `product-analytics.ts`: removed `maskTextFn`, so rrweb uses its default star masking. `maskAllInputs`, `blockClass`, `maskAttributeFn`, `mask_all_text` and `mask_all_element_attributes` do not change. - Removed the `analyticsChrome` prop from `Button`, `Label`, `TabsTrigger`, `EmptyState` and `SidebarNavItem`, and from all sidebar call sites. - Added `ANALYTICS_MASK_CLASS` to the content element (not the chrome) of these surfaces: - Link preview cards, task quicklook description, external object pills and rows, related-work titles. - Email message cards and email send intents. - Connected account names and email addresses (Browse, Connections, app detail headers, app sidebar, connection choice list, connection access and repair cards), GitHub login and repositories, Slack workspace names, chat channel and linked user labels. - Inbox and decision rows (subject and detail), obligation evidence, Needs You notes and receipts, decision options and result summaries, and the interaction card roots (questions, options, answers, tool action requests, suggested tasks). - Approval payloads, action card input and reason, recovery card headline, evidence and options, run ledger retry detail, interrupt handoff previews. - Run transcripts, run failure details and run events on the agent page. - Search result snippets, toast bodies, voice and call transcripts, case summary, files and fields, attachment previews, artifact previews (text, tables, patches and documents). - Replaced `unmask-allowlist.test.ts` with `replay-masking.test.tsx`. It checks that unmarked chrome records as it is, that each marker masks, that a rendered voice transcript and run transcript mask, that each surface above has the class, and that autocapture records no element text. Updated `privacy.test.ts`, `shared-chrome.test.tsx` and `product-analytics.test.ts`. - Updated `doc/cloud-browser-analytics.md`: new default, marker classes, masked surfaces, and residual risk. ## Verification - `pnpm exec vitest run src/lib/analytics` in `ui/`: 83 tests pass. - Vitest for the 48 test files next to the changed components: 994 tests pass. - `tsc --noEmit -p ui/tsconfig.json`: no new errors (only the existing generated Storybook catalog errors). - `pnpm verify` exits 2 because a doc is a global CI input. Required CI supplies the broad coverage. - Manual: I ran an isolated local instance with a Cloud-like browser analytics config. `PAPERCLIP_POSTHOG_HOST` pointed to a local capture server, not PostHog. I opened a task page in headless Chromium, hovered a GitHub pull request link, and decoded the captured `/s/` replay payloads: - Clear text: sidebar (`New task`, `Chat`, `Tasks`, `Inbox`, `More`), breadcrumb, task title `Quarterly launch checklist`, `REP-1`, the Connectors promo heading and button. - Masked (stars only): the markdown task body, the chat comment, the link preview card (pull request title, author, URL, status), and the company menu. - Marker strings in the body, comment and preview never appeared in clear text in any payload. - The page `<title>` (task title and company name) is in the replay head. This is accepted residual risk. ## Risks - Text that is not marked is now recorded. Task titles, agent names, project names, company names, routine names, artifact and document titles, and activity rows are visible in replays. The owner accepted this. An agent can copy email or Slack text into a task title. - A new surface that shows connected-account content without `ANALYTICS_MASK_CLASS` is recorded until somebody marks it. `replay-masking.test.tsx` and the doc list the marked surfaces. - The masking options in `posthog.init` take precedence over the PostHog project masking settings (posthog-js 1.450), so a dashboard change cannot unmask content. Keep the project settings empty to avoid a console warning. - Some masked areas also mask nearby fixed labels (for example the interaction card buttons). This is safe. - Analytics is off on self-hosted and local installs, so they see no change. > 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 - Claude Opus 5.5 (claude-opus-5-5), Anthropic, with tool use and code execution in Claude Code. ## 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 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
592 lines
25 KiB
TypeScript
592 lines
25 KiB
TypeScript
/**
|
|
* @fileoverview Plugin Manager page — admin UI for discovering,
|
|
* installing, enabling/disabling, and uninstalling plugins.
|
|
*
|
|
* @see PLUGIN_SPEC.md §9 — Plugin Marketplace / Manager
|
|
*/
|
|
import { useEffect, useMemo, useState } from "react";
|
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
import type { PluginRecord } from "@paperclipai/shared";
|
|
import { Link } from "@/lib/router";
|
|
import { AlertTriangle, FlaskConical, Plus, Power, Puzzle, Settings, Trash } from "lucide-react";
|
|
import { useCompany } from "@/context/CompanyContext";
|
|
import { useBreadcrumbs } from "@/context/BreadcrumbContext";
|
|
import { pluginsApi } from "@/api/plugins";
|
|
import { queryKeys } from "@/lib/queryKeys";
|
|
import { QueryErrorState, useQueryView } from "@/components/QueryView";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Label } from "@/components/ui/label";
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
} from "@/components/ui/dialog";
|
|
import { useToastActions } from "@/context/ToastContext";
|
|
import { cn } from "@/lib/utils";
|
|
import { ANALYTICS_MASK_CLASS } from "@/lib/analytics/privacy";
|
|
|
|
function firstNonEmptyLine(value: string | null | undefined): string | null {
|
|
if (!value) return null;
|
|
const line = value
|
|
.split(/\r?\n/)
|
|
.map((entry) => entry.trim())
|
|
.find(Boolean);
|
|
return line ?? null;
|
|
}
|
|
|
|
function getPluginErrorSummary(plugin: PluginRecord): string {
|
|
return firstNonEmptyLine(plugin.lastError) ?? "Plugin entered an error state without a stored error message.";
|
|
}
|
|
|
|
function isExperimentalPluginIdentity(input: {
|
|
packageName?: string | null;
|
|
packagePath?: string | null;
|
|
manifestJson?: PluginRecord["manifestJson"] | null;
|
|
bundledExperimental?: boolean;
|
|
}) {
|
|
if (input.bundledExperimental) return true;
|
|
|
|
const packageName = input.packageName ?? "";
|
|
const packagePath = input.packagePath ?? "";
|
|
if (packageName.includes("sandbox") || packagePath.includes("sandbox")) return true;
|
|
return input.manifestJson?.environmentDrivers?.some((driver) => driver.kind === "sandbox_provider") === true;
|
|
}
|
|
|
|
function ExperimentalBadge() {
|
|
return (
|
|
<Badge
|
|
variant="outline"
|
|
className="border-amber-500/30 bg-amber-500/10 text-amber-700 hover:bg-amber-500/10 dark:text-amber-200"
|
|
>
|
|
Experimental
|
|
</Badge>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* PluginManager page component.
|
|
*
|
|
* Provides a management UI for the Paperclip plugin system:
|
|
* - Lists all installed plugins with their status, version, and category badges.
|
|
* - Allows installing new plugins by npm package name.
|
|
* - Provides per-plugin actions: enable, disable, navigate to settings.
|
|
* - Uninstall with a two-step confirmation dialog to prevent accidental removal.
|
|
*
|
|
* Data flow:
|
|
* - Reads from `GET /api/plugins` via `pluginsApi.list()`.
|
|
* - Mutations (install / uninstall / enable / disable) invalidate
|
|
* `queryKeys.plugins.all` so the list refreshes automatically.
|
|
*
|
|
* @see PluginSettings — linked from the Settings icon on each plugin row.
|
|
* @see doc/plugins/PLUGIN_SPEC.md §3 — Plugin Lifecycle for status semantics.
|
|
*/
|
|
export function PluginManager() {
|
|
const { selectedCompany } = useCompany();
|
|
const { setBreadcrumbs } = useBreadcrumbs();
|
|
const queryClient = useQueryClient();
|
|
const { pushToast } = useToastActions();
|
|
|
|
const [installPackage, setInstallPackage] = useState("");
|
|
const [installDialogOpen, setInstallDialogOpen] = useState(false);
|
|
const [uninstallPluginId, setUninstallPluginId] = useState<string | null>(null);
|
|
const [uninstallPluginName, setUninstallPluginName] = useState<string>("");
|
|
const [errorDetailsPlugin, setErrorDetailsPlugin] = useState<PluginRecord | null>(null);
|
|
|
|
useEffect(() => {
|
|
setBreadcrumbs([
|
|
{ label: selectedCompany?.name ?? "Organization", href: "/dashboard" },
|
|
{ label: "Settings", href: "/company/settings" },
|
|
{ label: "Plugins" },
|
|
]);
|
|
}, [selectedCompany?.name, setBreadcrumbs]);
|
|
|
|
const pluginsQuery = useQuery({
|
|
queryKey: queryKeys.plugins.all,
|
|
queryFn: () => pluginsApi.list(),
|
|
});
|
|
const { data: plugins, isLoading, error } = pluginsQuery;
|
|
const pluginsView = useQueryView(pluginsQuery);
|
|
|
|
const bundledQuery = useQuery({
|
|
queryKey: queryKeys.plugins.examples,
|
|
queryFn: () => pluginsApi.listBundled(),
|
|
});
|
|
const bundledView = useQueryView(bundledQuery);
|
|
|
|
const invalidatePluginQueries = () => {
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.plugins.all });
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.plugins.examples });
|
|
queryClient.invalidateQueries({ queryKey: queryKeys.plugins.uiContributions });
|
|
};
|
|
|
|
const installMutation = useMutation({
|
|
mutationFn: (params: { packageName: string; version?: string; isLocalPath?: boolean }) =>
|
|
pluginsApi.install(params),
|
|
onSuccess: () => {
|
|
invalidatePluginQueries();
|
|
setInstallDialogOpen(false);
|
|
setInstallPackage("");
|
|
pushToast({ title: "Plugin installed successfully", tone: "success" });
|
|
},
|
|
onError: (err: Error) => {
|
|
pushToast({ title: "Failed to install plugin", body: err.message, tone: "error" });
|
|
},
|
|
});
|
|
|
|
const uninstallMutation = useMutation({
|
|
mutationFn: (pluginId: string) => pluginsApi.uninstall(pluginId),
|
|
onSuccess: () => {
|
|
invalidatePluginQueries();
|
|
pushToast({ title: "Plugin uninstalled successfully", tone: "success" });
|
|
},
|
|
onError: (err: Error) => {
|
|
pushToast({ title: "Failed to uninstall plugin", body: err.message, tone: "error" });
|
|
},
|
|
});
|
|
|
|
const enableMutation = useMutation({
|
|
mutationFn: (pluginId: string) => pluginsApi.enable(pluginId),
|
|
onSuccess: () => {
|
|
invalidatePluginQueries();
|
|
pushToast({ title: "Plugin enabled", tone: "success" });
|
|
},
|
|
onError: (err: Error) => {
|
|
pushToast({ title: "Failed to enable plugin", body: err.message, tone: "error" });
|
|
},
|
|
});
|
|
|
|
const disableMutation = useMutation({
|
|
mutationFn: (pluginId: string) => pluginsApi.disable(pluginId),
|
|
onSuccess: () => {
|
|
invalidatePluginQueries();
|
|
pushToast({ title: "Plugin disabled", tone: "info" });
|
|
},
|
|
onError: (err: Error) => {
|
|
pushToast({ title: "Failed to disable plugin", body: err.message, tone: "error" });
|
|
},
|
|
});
|
|
|
|
const installedPlugins = plugins ?? [];
|
|
const bundledPlugins = bundledQuery.data ?? [];
|
|
const installedByPackageName = new Map(installedPlugins.map((plugin) => [plugin.packageName, plugin]));
|
|
const bundledByPackageName = new Map(bundledPlugins.map((plugin) => [plugin.packageName, plugin]));
|
|
// Scope the in-section banner to bundled (local-path) installs so an npm-dialog
|
|
// install failure does not surface its error in the bundled-plugins section.
|
|
const installErrorMessage = installMutation.variables?.isLocalPath
|
|
? installMutation.error?.message ?? null
|
|
: null;
|
|
const errorSummaryByPluginId = useMemo(
|
|
() =>
|
|
new Map(
|
|
installedPlugins.map((plugin) => [plugin.id, getPluginErrorSummary(plugin)])
|
|
),
|
|
[installedPlugins]
|
|
);
|
|
|
|
if (isLoading || pluginsView.kind === "reconnecting") {
|
|
return <div className="p-4 text-sm text-muted-foreground">Loading plugins...</div>;
|
|
}
|
|
if (pluginsView.kind === "error") {
|
|
return (
|
|
<QueryErrorState
|
|
size="page"
|
|
error={error}
|
|
action="load plugins"
|
|
onRetry={pluginsView.retry}
|
|
retrying={pluginsView.isFetching}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="max-w-6xl space-y-6">
|
|
<div className="flex items-center justify-between">
|
|
<div className="flex items-center gap-2">
|
|
<Puzzle className="h-6 w-6 text-muted-foreground" />
|
|
<h1 className="text-xl font-semibold">Plugin Manager</h1>
|
|
</div>
|
|
|
|
<Dialog open={installDialogOpen} onOpenChange={setInstallDialogOpen}>
|
|
<DialogTrigger asChild>
|
|
<Button size="sm" className="gap-2">
|
|
<Plus className="h-4 w-4" />
|
|
Install Plugin
|
|
</Button>
|
|
</DialogTrigger>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>Install Plugin</DialogTitle>
|
|
<DialogDescription>
|
|
Enter the npm package name of the plugin you wish to install.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<div className="grid gap-4 py-4">
|
|
<div className="grid gap-2">
|
|
<Label htmlFor="packageName">npm Package Name</Label>
|
|
<Input
|
|
id="packageName"
|
|
placeholder="@paperclipai/plugin-example"
|
|
value={installPackage}
|
|
onChange={(e) => setInstallPackage(e.target.value)}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<DialogFooter>
|
|
<Button variant="outline" onClick={() => setInstallDialogOpen(false)}>Cancel</Button>
|
|
<Button
|
|
onClick={() => installMutation.mutate({ packageName: installPackage })}
|
|
disabled={!installPackage || installMutation.isPending}
|
|
>
|
|
{installMutation.isPending ? "Installing..." : "Install"}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
</div>
|
|
|
|
<div className="rounded-lg border border-amber-500/30 bg-amber-500/5 px-4 py-3">
|
|
<div className="flex items-start gap-3">
|
|
<AlertTriangle className="mt-0.5 h-4 w-4 shrink-0 text-amber-700" />
|
|
<div className="space-y-1 text-sm">
|
|
<p className="font-medium text-foreground">Plugins are alpha.</p>
|
|
<p className="text-muted-foreground">
|
|
The plugin runtime and API surface are still changing. Expect breaking changes while this feature settles.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<section className="space-y-3">
|
|
<div className="flex items-center gap-2">
|
|
<FlaskConical className="h-5 w-5 text-muted-foreground" />
|
|
<h2 className="text-base font-semibold">Available Plugins</h2>
|
|
<Badge variant="outline">Bundled</Badge>
|
|
</div>
|
|
|
|
{installErrorMessage && (
|
|
<div className="rounded-md border border-destructive/25 bg-destructive/[0.06] px-4 py-3 text-sm text-destructive whitespace-pre-wrap break-words">
|
|
{installErrorMessage}
|
|
</div>
|
|
)}
|
|
|
|
{bundledQuery.isLoading || bundledView.kind === "reconnecting" ? (
|
|
<div className="text-sm text-muted-foreground">Loading bundled plugins...</div>
|
|
) : bundledView.kind === "error" ? (
|
|
<QueryErrorState
|
|
error={bundledQuery.error}
|
|
action="load bundled plugins"
|
|
onRetry={bundledView.retry}
|
|
retrying={bundledView.isFetching}
|
|
/>
|
|
) : bundledPlugins.length === 0 ? (
|
|
<div className="rounded-md border border-dashed px-4 py-3 text-sm text-muted-foreground">
|
|
No bundled plugins were found in this checkout.
|
|
</div>
|
|
) : (
|
|
<Card className="block py-0">
|
|
<ul className="divide-y">
|
|
{bundledPlugins.map((bundledPlugin) => {
|
|
const installedPlugin = installedByPackageName.get(bundledPlugin.packageName);
|
|
const installPending =
|
|
installMutation.isPending &&
|
|
installMutation.variables?.isLocalPath &&
|
|
installMutation.variables.packageName === bundledPlugin.localPath;
|
|
|
|
return (
|
|
<li key={bundledPlugin.packageName}>
|
|
<div className="flex items-center gap-4 px-4 py-3">
|
|
<div className="min-w-0 flex-1">
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<span className="font-medium">{bundledPlugin.displayName}</span>
|
|
<Badge variant="outline">
|
|
{bundledPlugin.tag === "first-party" ? "First-party" : "Example"}
|
|
</Badge>
|
|
{isExperimentalPluginIdentity({
|
|
packageName: bundledPlugin.packageName,
|
|
packagePath: bundledPlugin.localPath,
|
|
bundledExperimental: bundledPlugin.experimental,
|
|
}) && <ExperimentalBadge />}
|
|
{installedPlugin ? (
|
|
<Badge
|
|
variant={installedPlugin.status === "ready" ? "default" : "secondary"}
|
|
className={installedPlugin.status === "ready" ? "bg-green-600 hover:bg-green-700" : ""}
|
|
>
|
|
{installedPlugin.status}
|
|
</Badge>
|
|
) : (
|
|
<Badge variant="secondary">Not installed</Badge>
|
|
)}
|
|
</div>
|
|
<p className="mt-1 text-sm text-muted-foreground">{bundledPlugin.description}</p>
|
|
<p className="mt-1 text-xs text-muted-foreground">{bundledPlugin.packageName}</p>
|
|
{installPending && !bundledPlugin.hasBuiltEntrypoints && (
|
|
<p className="mt-2 text-xs text-muted-foreground">Building plugin...</p>
|
|
)}
|
|
</div>
|
|
<div className="flex items-center gap-2 shrink-0">
|
|
{installedPlugin ? (
|
|
<>
|
|
{installedPlugin.status !== "ready" && (
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
disabled={enableMutation.isPending}
|
|
onClick={() => enableMutation.mutate(installedPlugin.id)}
|
|
>
|
|
Enable
|
|
</Button>
|
|
)}
|
|
<Button variant="outline" size="sm" asChild>
|
|
<Link to={`/company/settings/instance/plugins/${installedPlugin.id}`}>
|
|
{installedPlugin.status === "ready" ? "Open Settings" : "Review"}
|
|
</Link>
|
|
</Button>
|
|
</>
|
|
) : (
|
|
<Button
|
|
size="sm"
|
|
disabled={installPending || installMutation.isPending}
|
|
onClick={() =>
|
|
installMutation.mutate({
|
|
packageName: bundledPlugin.localPath,
|
|
isLocalPath: true,
|
|
})
|
|
}
|
|
>
|
|
{installPending ? "Installing..." : "Install"}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</li>
|
|
);
|
|
})}
|
|
</ul>
|
|
</Card>
|
|
)}
|
|
</section>
|
|
|
|
<section className="space-y-3">
|
|
<div className="flex items-center gap-2">
|
|
<Puzzle className="h-5 w-5 text-muted-foreground" />
|
|
<h2 className="text-base font-semibold">Installed Plugins</h2>
|
|
</div>
|
|
|
|
{!installedPlugins.length ? (
|
|
<Card className="bg-muted/30">
|
|
<CardContent className="flex flex-col items-center justify-center py-10">
|
|
<Puzzle className="h-10 w-10 text-muted-foreground mb-4" />
|
|
<p className="text-sm font-medium">No plugins installed</p>
|
|
<p className="text-xs text-muted-foreground mt-1">
|
|
Install a plugin to extend functionality.
|
|
</p>
|
|
</CardContent>
|
|
</Card>
|
|
) : (
|
|
<Card className="block py-0">
|
|
<ul className="divide-y">
|
|
{installedPlugins.map((plugin) => (
|
|
<li key={plugin.id}>
|
|
<div className="flex items-start gap-4 px-4 py-3">
|
|
<div className="min-w-0 flex-1">
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<Link
|
|
to={`/company/settings/instance/plugins/${plugin.id}`}
|
|
className="font-medium hover:underline truncate block"
|
|
title={plugin.manifestJson.displayName ?? plugin.packageName}
|
|
>
|
|
{plugin.manifestJson.displayName ?? plugin.packageName}
|
|
</Link>
|
|
{bundledByPackageName.has(plugin.packageName) && (
|
|
<Badge variant="outline">
|
|
{bundledByPackageName.get(plugin.packageName)?.tag === "first-party"
|
|
? "First-party"
|
|
: "Example"}
|
|
</Badge>
|
|
)}
|
|
{isExperimentalPluginIdentity({
|
|
packageName: plugin.packageName,
|
|
packagePath: plugin.packagePath,
|
|
manifestJson: plugin.manifestJson,
|
|
bundledExperimental: bundledByPackageName.get(plugin.packageName)?.experimental,
|
|
}) && <ExperimentalBadge />}
|
|
</div>
|
|
<div>
|
|
<p className="text-xs text-muted-foreground mt-0.5 truncate" title={plugin.packageName}>
|
|
{plugin.packageName} · v{plugin.manifestJson.version ?? plugin.version}
|
|
</p>
|
|
</div>
|
|
<p className="text-sm text-muted-foreground truncate mt-0.5" title={plugin.manifestJson.description}>
|
|
{plugin.manifestJson.description || "No description provided."}
|
|
</p>
|
|
{plugin.status === "error" && (
|
|
<div className="mt-3 rounded-md border border-red-500/25 bg-red-500/[0.06] px-3 py-2">
|
|
<div className="flex flex-wrap items-start gap-3">
|
|
<div className="min-w-0 flex-1">
|
|
<div className="flex items-center gap-2 text-sm font-medium text-red-700 dark:text-red-300">
|
|
<AlertTriangle className="h-4 w-4 shrink-0" />
|
|
<span>Plugin error</span>
|
|
</div>
|
|
<p
|
|
className="mt-1 text-sm text-red-700/90 dark:text-red-200/90 break-words"
|
|
title={plugin.lastError ?? undefined}
|
|
>
|
|
{errorSummaryByPluginId.get(plugin.id)}
|
|
</p>
|
|
</div>
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
className="border-red-500/30 bg-background/60 text-red-700 hover:bg-red-500/10 hover:text-red-800 dark:text-red-200 dark:hover:text-red-100"
|
|
onClick={() => setErrorDetailsPlugin(plugin)}
|
|
>
|
|
View full error
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
<div className="flex shrink-0 self-center">
|
|
<div className="flex flex-col items-end gap-2">
|
|
<div className="flex items-center gap-2">
|
|
<Badge
|
|
variant={
|
|
plugin.status === "ready"
|
|
? "default"
|
|
: plugin.status === "error"
|
|
? "destructive"
|
|
: "secondary"
|
|
}
|
|
className={cn(
|
|
"shrink-0",
|
|
plugin.status === "ready" ? "bg-green-600 hover:bg-green-700" : ""
|
|
)}
|
|
>
|
|
{plugin.status}
|
|
</Badge>
|
|
<Button
|
|
variant="outline"
|
|
size="icon-sm"
|
|
className="h-8 w-8"
|
|
title={plugin.status === "ready" ? "Disable" : "Enable"}
|
|
onClick={() => {
|
|
if (plugin.status === "ready") {
|
|
disableMutation.mutate(plugin.id);
|
|
} else {
|
|
enableMutation.mutate(plugin.id);
|
|
}
|
|
}}
|
|
disabled={enableMutation.isPending || disableMutation.isPending}
|
|
>
|
|
<Power className={cn("h-4 w-4", plugin.status === "ready" ? "text-green-600" : "")} />
|
|
</Button>
|
|
<Button
|
|
variant="outline"
|
|
size="icon-sm"
|
|
className="h-8 w-8 text-destructive hover:text-destructive"
|
|
title="Uninstall"
|
|
onClick={() => {
|
|
setUninstallPluginId(plugin.id);
|
|
setUninstallPluginName(plugin.manifestJson.displayName ?? plugin.packageName);
|
|
}}
|
|
disabled={uninstallMutation.isPending}
|
|
>
|
|
<Trash className="h-4 w-4" />
|
|
</Button>
|
|
</div>
|
|
<Button variant="outline" size="sm" className="mt-2 h-8" asChild>
|
|
<Link to={`/company/settings/instance/plugins/${plugin.id}`}>
|
|
<Settings className="h-4 w-4" />
|
|
Configure
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</Card>
|
|
)}
|
|
</section>
|
|
|
|
<Dialog
|
|
open={uninstallPluginId !== null}
|
|
onOpenChange={(open) => { if (!open) setUninstallPluginId(null); }}
|
|
>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>Uninstall Plugin</DialogTitle>
|
|
<DialogDescription>
|
|
Are you sure you want to uninstall <strong>{uninstallPluginName}</strong>? This action cannot be undone.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<DialogFooter>
|
|
<Button variant="outline" onClick={() => setUninstallPluginId(null)}>Cancel</Button>
|
|
<Button
|
|
variant="destructive"
|
|
disabled={uninstallMutation.isPending}
|
|
onClick={() => {
|
|
if (uninstallPluginId) {
|
|
uninstallMutation.mutate(uninstallPluginId, {
|
|
onSettled: () => setUninstallPluginId(null),
|
|
});
|
|
}
|
|
}}
|
|
>
|
|
{uninstallMutation.isPending ? "Uninstalling..." : "Uninstall"}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
|
|
<Dialog
|
|
open={errorDetailsPlugin !== null}
|
|
onOpenChange={(open) => { if (!open) setErrorDetailsPlugin(null); }}
|
|
>
|
|
<DialogContent className="sm:max-w-2xl">
|
|
<DialogHeader>
|
|
<DialogTitle>Error Details</DialogTitle>
|
|
<DialogDescription>
|
|
{errorDetailsPlugin?.manifestJson.displayName ?? errorDetailsPlugin?.packageName ?? "Plugin"} hit an error state.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<div className="space-y-4">
|
|
<div className="rounded-md border border-red-500/25 bg-red-500/[0.06] px-4 py-3">
|
|
<div className="flex items-start gap-3">
|
|
<AlertTriangle className="mt-0.5 h-4 w-4 shrink-0 text-red-700 dark:text-red-300" />
|
|
<div className="space-y-1 text-sm">
|
|
<p className="font-medium text-red-700 dark:text-red-300">
|
|
What errored
|
|
</p>
|
|
<p className="text-red-700/90 dark:text-red-200/90 break-words">
|
|
{errorDetailsPlugin ? getPluginErrorSummary(errorDetailsPlugin) : "No error summary available."}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<p className="text-sm font-medium">Full error output</p>
|
|
<pre className={cn("max-h-(--sz-50vh) overflow-auto rounded-md border bg-muted/40 p-3 text-xs leading-5 whitespace-pre-wrap break-words", ANALYTICS_MASK_CLASS)}>
|
|
{errorDetailsPlugin?.lastError ?? "No stored error message."}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
<DialogFooter>
|
|
<Button variant="outline" onClick={() => setErrorDetailsPlugin(null)}>
|
|
Close
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
</div>
|
|
);
|
|
}
|