mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-27 20:09:10 +01:00
## Thinking Path > - People use Paperclip to manage AI agents at work. > - New users now meet their agent in chat after setup. > - The Connectors card previously checked for an open onboarding task. > - Chat-first onboarding creates no such task, so the card could appear three seconds into a first visit. > - This change holds that promotion until the person returns after 30 minutes of inactivity. ## Linked Issues or Issue Description Refs: #19514, #22077 **What happened?** On master at `11cfe0910d`, a new user could see the Connectors card in their first agent chat. **Expected behavior** The card stays hidden through the first visit and can appear when the user returns after a 30-minute gap in activity. **Steps to reproduce** With the Connectors announcement active, finish chat-first onboarding in a fresh browser profile and wait for the announcement delay. ## What Changed - Track the first visible board visit per account in browser storage. Local input and visits in other tabs extend the first session. After the first qualifying return, the browser remembers eligibility and stops tracking input. - Apply this rule to the published Connectors announcement ID. The existing checks for dismissal, open dialogs, and legacy onboarding tasks still apply. - Exercise the onboarding chat, reload, idle return, account isolation, and activity in another tab. ## Verification - Before the fix, the Vitest regression displayed `2026-09-14-connectors` on the first visit. - The announcement and workspace identity Vitest suites passed locally (28 tests). The UI typecheck passed. - Chromium passed all four tests in `announcement-first-session.spec.ts` and `announcement-placement.spec.ts` against a local test server. - A second red-green regression covers dismissal in another browser while the first tab sits idle. The return triggers a fresh check and keeps the card hidden until it succeeds. - At `8fab1932fa`, GitHub reported 73 successful checks and three skipped checks. [CI run](https://github.com/paperclipai/paperclip/actions/runs/45449353624) ## Risks A new browser profile or cleared site data starts the visit history again. Storage failures keep the Connectors card hidden. Existing users start accumulating visit history when they first use this version. ## Model Used OpenAI Codex, GPT-6.2 Astra (`gpt-6.2-astra`), with shell, Vitest, and Playwright. ## 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: Scott Tong <scott@scotts-mbp-m5-max.local> Co-authored-by: Paperclip <noreply@paperclip.ing>
85 lines
4.2 KiB
TypeScript
85 lines
4.2 KiB
TypeScript
import { useEffect, useState } from "react";
|
||
import { useQuery } from "@tanstack/react-query";
|
||
import { ONBOARDING_FIRST_TASK_ORIGIN_KIND } from "@paperclipai/shared";
|
||
import { cn } from "@/lib/utils";
|
||
import { useAccountIdentity } from "@/api/companies-query";
|
||
import type { HealthStatus } from "@/api/health";
|
||
import { issuesApi } from "@/api/issues";
|
||
import { useCompany } from "@/context/CompanyContext";
|
||
import { useDialogState } from "@/context/DialogContext";
|
||
import { useOptionalToastActions, useOptionalToastState } from "@/context/ToastContext";
|
||
import { useAnnouncement } from "@/hooks/useAnnouncement";
|
||
import { queryKeys } from "@/lib/queryKeys";
|
||
import { AnnouncementCard } from "./AnnouncementCard";
|
||
|
||
// Includes the command palette, sheets and dialogs created outside DialogContext.
|
||
export const MODAL_SELECTOR = '[role="dialog"][data-state="open"], [role="alertdialog"][data-state="open"], [aria-modal="true"]:not([data-state="closed"]), dialog[open]';
|
||
export function useModalOpen(enabled: boolean, selector = MODAL_SELECTOR) {
|
||
const [open, setOpen] = useState(false);
|
||
useEffect(() => {
|
||
if (!enabled) return;
|
||
const scan = () => setOpen(Boolean(document.querySelector(selector)));
|
||
scan();
|
||
const observer = new MutationObserver(scan);
|
||
observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ["data-state", "aria-modal", "open"] });
|
||
return () => observer.disconnect();
|
||
}, [enabled, selector]);
|
||
return open;
|
||
}
|
||
|
||
const FINISHED_ONBOARDING_STATUSES = new Set(["done", "cancelled"]);
|
||
|
||
export function useOnboardingInProgress(companyId: string | null) {
|
||
const query = useQuery({
|
||
queryKey: queryKeys.issues.onboardingFirstTask(companyId ?? "__none__"),
|
||
queryFn: ({ signal }) => issuesApi.list(companyId!, { originKind: ONBOARDING_FIRST_TASK_ORIGIN_KIND, limit: 1 }, { signal }),
|
||
enabled: Boolean(companyId),
|
||
staleTime: 60_000,
|
||
});
|
||
if (!companyId) return false;
|
||
if (!query.isSuccess) return true;
|
||
return query.data.some((issue) => issue.originKind === ONBOARDING_FIRST_TASK_ORIGIN_KIND && !FINISHED_ONBOARDING_STATUSES.has(issue.status));
|
||
}
|
||
|
||
/**
|
||
* Where the card lives. `sidebar` docks it in the desktop sidebar column, in
|
||
* normal layout flow, so it never covers the task thread or composer.
|
||
* `floating` keeps the mobile placement above the bottom navigation.
|
||
*/
|
||
export type AnnouncementPlacement = "sidebar" | "floating";
|
||
|
||
export function AnnouncementWell({ health, placement = "floating" }: { health?: HealthStatus; placement?: AnnouncementPlacement }) {
|
||
const { userId: accountId, settled } = useAccountIdentity();
|
||
const { selectedCompanyId, loading } = useCompany();
|
||
const { onboardingOpen } = useDialogState();
|
||
const toastActions = useOptionalToastActions();
|
||
const toasts = useOptionalToastState();
|
||
const onboardingInProgress = useOnboardingInProgress(selectedCompanyId);
|
||
const userId = health?.deploymentMode === "local_trusted" ? "local-board" : (settled ? accountId : null);
|
||
const { announcement, dismiss } = useAnnouncement({
|
||
userId, companyId: selectedCompanyId,
|
||
enabled: Boolean(userId && !loading && selectedCompanyId && !onboardingOpen && !onboardingInProgress),
|
||
onSaveFailure: (savedLocally) => toastActions?.pushToast({
|
||
title: savedLocally ? "Dismissed in this browser" : "Dismissed for this visit",
|
||
body: "Couldn’t save across devices. We’ll retry when you reconnect or return.",
|
||
tone: "info", dedupeKey: "announcement-dismissal-sync",
|
||
}),
|
||
});
|
||
const modalOpen = useModalOpen(Boolean(announcement));
|
||
if (!announcement || modalOpen || (toasts?.length ?? 0) > 0) return null;
|
||
return (
|
||
<aside
|
||
aria-label="Paperclip announcements"
|
||
data-placement={placement}
|
||
className={cn(
|
||
"announcement-well",
|
||
placement === "sidebar"
|
||
? "shrink-0 overflow-y-auto px-3 pb-2 max-h-(--announcement-sidebar-max-height)"
|
||
: "fixed left-3 bottom-(--announcement-mobile-bottom) z-40 w-(--announcement-available-width) max-w-(--announcement-width) max-h-(--announcement-mobile-max-height) overflow-y-auto md:bottom-3 md:max-h-(--announcement-max-height)",
|
||
)}
|
||
>
|
||
<AnnouncementCard key={announcement.id} announcement={announcement} onDismiss={() => dismiss(announcement.id)} />
|
||
</aside>
|
||
);
|
||
}
|