@bevel-software/platform-core-frontend 0.25.2 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +87 -25
- package/src/core/ProductName.tsx +49 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
- package/src/core/__tests__/core-contributions.test.ts +16 -0
- package/src/core/core-contributions.ts +17 -0
- package/src/core/registry.ts +51 -1
- package/src/index.css +23 -5
- package/src/index.ts +5 -0
- package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
- package/src/modules/access/components/ManageAccessDialog.tsx +1 -1
- package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
- package/src/modules/auth/components/LoginScreen.tsx +4 -1
- package/src/modules/auth/services/account.api.ts +28 -1
- package/src/modules/auth/services/sso.ts +1 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
- package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
- package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
- package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
- package/src/modules/change-requests/services/change-requests.api.ts +15 -2
- package/src/modules/change-requests/utils/readFailure.ts +22 -0
- package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
- package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
- package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
- package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
- package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
- package/src/modules/embed/__tests__/mount.test.tsx +157 -0
- package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
- package/src/modules/embed/components/EmbedView.tsx +545 -0
- package/src/modules/embed/embed-config.ts +132 -0
- package/src/modules/embed/embed-host.ts +120 -0
- package/src/modules/embed/mount.tsx +80 -0
- package/src/modules/embed/services/embed-token.ts +22 -0
- package/src/modules/embed/services/embed.api.ts +158 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
- package/src/modules/git/branch-delete-menu-item.tsx +24 -0
- package/src/modules/git/components/BranchSwitcher.tsx +29 -5
- package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
- package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
- package/src/modules/git/components/PullNeededBanner.tsx +15 -49
- package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
- package/src/modules/git/index.ts +15 -0
- package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
- package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
- package/src/modules/git/services/error-messages.ts +58 -1
- package/src/modules/git/services/pull-failure.ts +68 -0
- package/src/modules/git/state/branch-delete-confirm.ts +46 -0
- package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
- package/src/modules/layout/breakpoints.ts +8 -0
- package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
- package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
- package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
- package/src/modules/library/__tests__/ToolPage.test.tsx +53 -0
- package/src/modules/library/components/LibraryPage.tsx +22 -0
- package/src/modules/library/components/PluginExtras.tsx +23 -6
- package/src/modules/library/components/PluginPage.tsx +6 -1
- package/src/modules/library/components/tool-page/ToolPage.tsx +45 -1
- package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
- package/src/modules/library/services/plugins.api.ts +4 -1
- package/src/modules/library/services/tools.api.ts +27 -0
- package/src/modules/library/state/plugins-revision.ts +28 -0
- package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
- package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +109 -0
- package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1001 -0
- package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +392 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
- package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
- package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
- package/src/modules/onboarding/components/GetStartedColumn.tsx +651 -0
- package/src/modules/onboarding/components/InviteButton.tsx +35 -0
- package/src/modules/onboarding/components/InviteDialog.tsx +424 -0
- package/src/modules/onboarding/components/RootLanding.tsx +8 -24
- package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
- package/src/modules/onboarding/first-page-prompt.ts +89 -0
- package/src/modules/onboarding/invite-emails.ts +175 -0
- package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
- package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
- package/src/modules/onboarding/state/agent-connection.ts +167 -0
- package/src/modules/onboarding/state/invite-dialog.context.ts +32 -0
- package/src/modules/onboarding/state/invite-dialog.tsx +31 -0
- package/src/modules/onboarding/state/onboarding.ts +133 -59
- package/src/modules/onboarding/state/starter-packs.ts +169 -0
- package/src/modules/settings/settings-nav-items.tsx +8 -3
- package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
- package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
- package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
- package/src/modules/setup/__tests__/setup.test.tsx +65 -81
- package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
- package/src/modules/setup/components/SetupGate.tsx +46 -1
- package/src/modules/setup/components/SetupScreen.tsx +92 -152
- package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
- package/src/modules/setup/services/setup.api.ts +3 -3
- package/src/modules/setup/utils/suggested-branch.ts +27 -0
- package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
- package/src/modules/toolbar/commands/actions.tsx +324 -0
- package/src/modules/toolbar/commands/command-menu.ts +44 -0
- package/src/modules/toolbar/commands/useCommandActions.ts +69 -0
- package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +106 -22
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
- package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
- package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
- package/src/modules/toolbar/components/Toolbar.tsx +10 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +187 -54
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +4 -4
- package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
- package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +832 -0
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
- package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
- package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
- package/src/modules/toolbar/search/rank.ts +111 -0
- package/src/modules/toolbar/search/sources.ts +169 -0
- package/src/modules/workflow/hooks/useFileLock.ts +10 -7
- package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
- package/src/modules/workflow/services/lock.api.ts +17 -2
- package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
- package/src/modules/workspace/components/EditorTabs.tsx +39 -15
- package/src/modules/workspace/components/FileExplorer.tsx +39 -6
- package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
- package/src/modules/workspace/components/FileRoute.tsx +12 -7
- package/src/modules/workspace/components/FileViewer.tsx +271 -74
- package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +101 -11
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
- package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
- package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
- package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
- package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
- package/src/modules/workspace/components/renderers/index.ts +26 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
- package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
- package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
- package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
- package/src/modules/workspace/hooks/useCreatePage.ts +116 -0
- package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
- package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
- package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
- package/src/modules/workspace/routing/kb-routes.ts +66 -12
- package/src/modules/workspace/state/editable-page.ts +42 -0
- package/src/modules/workspace/state/workspace.context.ts +13 -4
- package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +26 -14
- package/src/modules/workspace/utils/display-file-name.ts +102 -0
- package/src/modules/workspace/utils/fileTree.ts +49 -14
- package/src/modules/workspace/utils/treeConfirm.ts +22 -5
- package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
- package/src/shared/components/ConfirmProvider.tsx +156 -0
- package/src/shared/components/Dialog.tsx +7 -0
- package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
- package/src/shared/components/confirm-context.ts +94 -0
- package/src/shared/components/index.ts +3 -0
- package/src/shared/mcp/__tests__/connect-snippets.test.ts +2 -2
- package/src/shared/mcp/connect-snippets.ts +8 -5
- package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
- package/src/modules/onboarding/welcome-state.ts +0 -36
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { authFetch } from '../../../lib/api';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The starter-pack question — `GET /api/onboarding/starter-packs` and
|
|
5
|
+
* `POST /api/onboarding/starter-pack`. MIRRORS the backend's
|
|
6
|
+
* `StarterPacksAnswer` / `StarterPackApplied`
|
|
7
|
+
* (`modules/onboarding/starter-pack.service.ts`).
|
|
8
|
+
*/
|
|
9
|
+
export interface StarterPackSummary {
|
|
10
|
+
id: string;
|
|
11
|
+
/** The chip's label. */
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
order: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ChosenStarterPack {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
/** The team's own "write your first page" request. */
|
|
21
|
+
firstPagePrompt: string;
|
|
22
|
+
/** The pack's pages still exactly as it wrote them (workspace-relative): placeholders, not pages. */
|
|
23
|
+
starterPages: string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface StarterPacksAnswer {
|
|
27
|
+
/** Ask this person: an admin, nobody has answered, the knowledge base is still new. */
|
|
28
|
+
offered: boolean;
|
|
29
|
+
/** A pack's id, `none` for a skip, or null while unanswered. */
|
|
30
|
+
chosen: string | null;
|
|
31
|
+
packs: StarterPackSummary[];
|
|
32
|
+
chosenPack: ChosenStarterPack | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface StarterPackApplied {
|
|
36
|
+
id: string;
|
|
37
|
+
name: string | null;
|
|
38
|
+
pages: number;
|
|
39
|
+
skills: number;
|
|
40
|
+
/** "Added 4 pages and 4 skills for Engineering." — empty for a skip. */
|
|
41
|
+
summary: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The id that answers "Skip, I'll start from scratch". */
|
|
45
|
+
export const SKIP_STARTER_PACK = 'none';
|
|
46
|
+
|
|
47
|
+
/** A refusal, with the server's own sentence. */
|
|
48
|
+
export class StarterPackApiError extends Error {
|
|
49
|
+
readonly status: number;
|
|
50
|
+
constructor(message: string, status: number) {
|
|
51
|
+
super(message);
|
|
52
|
+
this.name = 'StarterPackApiError';
|
|
53
|
+
this.status = status;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function errorOf(res: Response, fallback: string): Promise<StarterPackApiError> {
|
|
58
|
+
const body = (await res.json().catch(() => null)) as { error?: unknown } | null;
|
|
59
|
+
return new StarterPackApiError(typeof body?.error === 'string' ? body.error : fallback, res.status);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function fetchStarterPacks(): Promise<StarterPacksAnswer> {
|
|
63
|
+
const res = await authFetch('/api/onboarding/starter-packs');
|
|
64
|
+
if (!res.ok) throw await errorOf(res, `starter-packs: ${res.status}`);
|
|
65
|
+
const body = (await res.json()) as Partial<StarterPacksAnswer>;
|
|
66
|
+
return {
|
|
67
|
+
offered: body.offered === true,
|
|
68
|
+
chosen: typeof body.chosen === 'string' ? body.chosen : null,
|
|
69
|
+
packs: Array.isArray(body.packs) ? body.packs : [],
|
|
70
|
+
chosenPack: body.chosenPack ?? null,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Choose `id` (or {@link SKIP_STARTER_PACK}). Throws {@link StarterPackApiError} with the server's reason. */
|
|
75
|
+
export async function chooseStarterPack(id: string): Promise<StarterPackApplied> {
|
|
76
|
+
const res = await authFetch('/api/onboarding/starter-pack', {
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: { 'Content-Type': 'application/json' },
|
|
79
|
+
body: JSON.stringify({ id }),
|
|
80
|
+
});
|
|
81
|
+
if (!res.ok) throw await errorOf(res, 'Couldn’t add the starter pages. Try again.');
|
|
82
|
+
return (await res.json()) as StarterPackApplied;
|
|
83
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { useContext, useEffect, useState, useSyncExternalStore } from 'react';
|
|
2
|
+
import { AuthContext } from '../../auth/state/auth.context';
|
|
3
|
+
import { useEventBus } from '../../workflow/state/event-bus.context';
|
|
4
|
+
import { fetchAgentConnection, type AgentConnection } from '../services/agent-connection.api';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* "Is your agent connected yet?", shared by the connect-your-agent page and
|
|
8
|
+
* the Get set up list.
|
|
9
|
+
*
|
|
10
|
+
* The server SAYS when it happens: an agent's first authenticated request
|
|
11
|
+
* stamps its connection or key, and the stamp paths emit `agent-connected`
|
|
12
|
+
* for the owner over the event stream every tab holds. So this hook listens,
|
|
13
|
+
* and asks the server only on arrival and when the person comes back to the
|
|
14
|
+
* tab — for an agent that connected before this tab existed, or while its
|
|
15
|
+
* stream was down. Never on a timer.
|
|
16
|
+
*
|
|
17
|
+
* A "yes" is remembered for the session, PER SIGNED-IN USER — the record
|
|
18
|
+
* hangs off the auth context's user object, which the session holds for as
|
|
19
|
+
* long as that person is signed in — and every mounted reader hears it: the
|
|
20
|
+
* page that saw the agent arrive hands the answer to the list it navigates
|
|
21
|
+
* back to, instead of the list showing "not yet" until its own request
|
|
22
|
+
* comes back. A "not yet" is never remembered — it is exactly the answer
|
|
23
|
+
* expected to change. A fresh session starts from nothing.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The shortest gap between two asks prompted by coming back to the tab:
|
|
28
|
+
* switching windows a dozen times a minute is not a dozen questions.
|
|
29
|
+
*/
|
|
30
|
+
export const AGENT_RECHECK_MS = 30_000;
|
|
31
|
+
|
|
32
|
+
interface Known {
|
|
33
|
+
connection: AgentConnection | null;
|
|
34
|
+
version: number;
|
|
35
|
+
listeners: Set<() => void>;
|
|
36
|
+
subscribe(listener: () => void): () => void;
|
|
37
|
+
snapshot(): number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const known = new WeakMap<object, Known>();
|
|
41
|
+
|
|
42
|
+
function knownFor(user: object): Known {
|
|
43
|
+
const found = known.get(user);
|
|
44
|
+
if (found) return found;
|
|
45
|
+
const record: Known = {
|
|
46
|
+
connection: null,
|
|
47
|
+
version: 0,
|
|
48
|
+
listeners: new Set(),
|
|
49
|
+
subscribe(listener) {
|
|
50
|
+
record.listeners.add(listener);
|
|
51
|
+
return () => record.listeners.delete(listener);
|
|
52
|
+
},
|
|
53
|
+
snapshot: () => record.version,
|
|
54
|
+
};
|
|
55
|
+
known.set(user, record);
|
|
56
|
+
return record;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function rememberConnected(record: Known, connection: AgentConnection): void {
|
|
60
|
+
record.connection = connection;
|
|
61
|
+
record.version++;
|
|
62
|
+
record.listeners.forEach((l) => l());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const nobody = {
|
|
66
|
+
subscribe: () => () => {},
|
|
67
|
+
snapshot: () => 0,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export interface AgentConnectionState extends AgentConnection {
|
|
71
|
+
/** The first answer is in (a failed request counts as "not yet"). */
|
|
72
|
+
settled: boolean;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const UNKNOWN: AgentConnectionState = { connected: false, settled: false };
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The signed-in person's agent connection.
|
|
79
|
+
*
|
|
80
|
+
* Told by the server's `agent-connected` event the moment an agent of theirs
|
|
81
|
+
* makes its first call. Asked once on mount, and again when the person comes
|
|
82
|
+
* back to the tab — at most once per {@link AGENT_RECHECK_MS} — so an agent
|
|
83
|
+
* connected before this tab opened, or while its event stream was down, still
|
|
84
|
+
* counts. A failed ask reads as "not yet".
|
|
85
|
+
*
|
|
86
|
+
* Nothing is asked or listened for while `enabled` is false, or signed out.
|
|
87
|
+
*/
|
|
88
|
+
export function useAgentConnection({ enabled = true }: { enabled?: boolean } = {}): AgentConnectionState {
|
|
89
|
+
const auth = useContext(AuthContext);
|
|
90
|
+
const user = auth?.user ?? null;
|
|
91
|
+
const userId = user?.id ?? null;
|
|
92
|
+
const record = user ? knownFor(user) : null;
|
|
93
|
+
const bus = useEventBus();
|
|
94
|
+
useSyncExternalStore(record?.subscribe ?? nobody.subscribe, record?.snapshot ?? nobody.snapshot, nobody.snapshot);
|
|
95
|
+
// Keyed by the record, so a tab that switches accounts never shows one
|
|
96
|
+
// person's answer to the next.
|
|
97
|
+
const [answer, setAnswer] = useState<{ record: Known; state: AgentConnectionState } | null>(null);
|
|
98
|
+
|
|
99
|
+
// The server's word, the moment it happens. The bus is already filtered to
|
|
100
|
+
// this account's sessions; the check here covers a tab that switched
|
|
101
|
+
// accounts while the subscription stood. An event older than what is
|
|
102
|
+
// remembered (a replay on reconnect, a key's first use landing after a
|
|
103
|
+
// newer connection's) changes nothing: the newest use names the client the
|
|
104
|
+
// first-page prompt should address.
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!enabled || !record || !userId || !bus) return;
|
|
107
|
+
return bus.subscribe('agent-connected', (event) => {
|
|
108
|
+
if (event.forUserId !== userId) return;
|
|
109
|
+
const current = record.connection;
|
|
110
|
+
if (current?.at && event.at <= current.at) return;
|
|
111
|
+
rememberConnected(record, { connected: true, at: event.at, client: event.client, kind: event.agentKind });
|
|
112
|
+
});
|
|
113
|
+
}, [enabled, record, userId, bus]);
|
|
114
|
+
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
// Same gate as the listener above: no account to ask about, no ask.
|
|
117
|
+
if (!enabled || !record || !userId || record.connection) return;
|
|
118
|
+
let cancelled = false;
|
|
119
|
+
let inFlight = false;
|
|
120
|
+
let lastAsked = 0;
|
|
121
|
+
|
|
122
|
+
const check = async () => {
|
|
123
|
+
// Another reader may have heard the yes first; it is remembered for everyone.
|
|
124
|
+
if (cancelled || inFlight || record.connection) return;
|
|
125
|
+
inFlight = true;
|
|
126
|
+
lastAsked = Date.now();
|
|
127
|
+
let result: AgentConnection;
|
|
128
|
+
try {
|
|
129
|
+
result = await fetchAgentConnection();
|
|
130
|
+
} catch {
|
|
131
|
+
// A refusal or a blip reads as "not yet" on screen; the event, or
|
|
132
|
+
// the next return to the tab, says otherwise.
|
|
133
|
+
result = { connected: false };
|
|
134
|
+
}
|
|
135
|
+
inFlight = false;
|
|
136
|
+
if (cancelled) return;
|
|
137
|
+
if (result.connected) {
|
|
138
|
+
rememberConnected(record, result);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
setAnswer({ record, state: { connected: false, settled: true } });
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The person is back: the tab was shown, or the window focused. Asked
|
|
146
|
+
* again if it has not been lately — an agent that connected while the
|
|
147
|
+
* stream was down, or in a window this tab never heard from.
|
|
148
|
+
*/
|
|
149
|
+
const onReturn = () => {
|
|
150
|
+
if (document.hidden || inFlight || record.connection) return;
|
|
151
|
+
if (Date.now() - lastAsked >= AGENT_RECHECK_MS) void check();
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
void check();
|
|
155
|
+
document.addEventListener('visibilitychange', onReturn);
|
|
156
|
+
window.addEventListener('focus', onReturn);
|
|
157
|
+
return () => {
|
|
158
|
+
cancelled = true;
|
|
159
|
+
document.removeEventListener('visibilitychange', onReturn);
|
|
160
|
+
window.removeEventListener('focus', onReturn);
|
|
161
|
+
};
|
|
162
|
+
}, [enabled, record, userId]);
|
|
163
|
+
|
|
164
|
+
if (!record) return UNKNOWN;
|
|
165
|
+
if (record.connection) return { ...record.connection, connected: true, settled: true };
|
|
166
|
+
return answer?.record === record ? answer.state : UNKNOWN;
|
|
167
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The invite dialog's channel, split out from the provider that renders it so
|
|
5
|
+
* the provider module exports only a component (Fast Refresh; the same split
|
|
6
|
+
* as `library/state/toast.context.ts` / `toast.tsx`). The provider lives in
|
|
7
|
+
* `./invite-dialog.tsx`.
|
|
8
|
+
*
|
|
9
|
+
* What the invite entry points share: a way to open THE invite dialog, and a
|
|
10
|
+
* counter that moves every time it invited somebody.
|
|
11
|
+
*
|
|
12
|
+
* Two places open it — the toolbar's Invite button and the "Get set up"
|
|
13
|
+
* column — and they must open the same dialog rather than one each, or the
|
|
14
|
+
* column's "Invite your team" would tick from one and not the other. The
|
|
15
|
+
* counter is how the column hears about it: it re-reads the account list
|
|
16
|
+
* when `invitedRevision` moves instead of polling for a change it caused.
|
|
17
|
+
*/
|
|
18
|
+
export interface InviteDialogController {
|
|
19
|
+
open(): void;
|
|
20
|
+
invitedRevision: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const InviteDialogContext = createContext<InviteDialogController | null>(null);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The shared controller, or null outside a provider. Null rather than a throw
|
|
27
|
+
* because the toolbar is rendered bare in its own tests, and an entry point
|
|
28
|
+
* with nothing to open should simply not be offered.
|
|
29
|
+
*/
|
|
30
|
+
export function useInviteDialog(): InviteDialogController | null {
|
|
31
|
+
return useContext(InviteDialogContext);
|
|
32
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState, type ReactNode } from 'react';
|
|
2
|
+
import { InviteDialog } from '../components/InviteDialog';
|
|
3
|
+
import { InviteDialogContext } from './invite-dialog.context';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hosts the invite dialog for everything below it (see
|
|
7
|
+
* `invite-dialog.context.ts` for what it shares). Mounted in `AppChrome`, so
|
|
8
|
+
* the dialog renders INSIDE the registry's providers — the `inviteExtras`
|
|
9
|
+
* slot it carries may read state a distribution provides there.
|
|
10
|
+
*
|
|
11
|
+
* The dialog only mounts while open, so the provider costs nothing — and
|
|
12
|
+
* reads nothing, not even the admin verdict — until somebody asks for it.
|
|
13
|
+
*/
|
|
14
|
+
export function InviteDialogProvider({ children }: { children: ReactNode }) {
|
|
15
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
16
|
+
const [invitedRevision, setInvitedRevision] = useState(0);
|
|
17
|
+
const open = useCallback(() => setIsOpen(true), []);
|
|
18
|
+
const value = useMemo(() => ({ open, invitedRevision }), [open, invitedRevision]);
|
|
19
|
+
return (
|
|
20
|
+
<InviteDialogContext.Provider value={value}>
|
|
21
|
+
{children}
|
|
22
|
+
{isOpen && (
|
|
23
|
+
<InviteDialog
|
|
24
|
+
open
|
|
25
|
+
onClose={() => setIsOpen(false)}
|
|
26
|
+
onInvited={() => setInvitedRevision((r) => r + 1)}
|
|
27
|
+
/>
|
|
28
|
+
)}
|
|
29
|
+
</InviteDialogContext.Provider>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -16,70 +16,97 @@ import { authFetch } from '../../../lib/api';
|
|
|
16
16
|
* absent field must never resurrect the welcome flow for an account that
|
|
17
17
|
* finished it.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
19
|
+
* One client-side piece around the server truth: `doneLocally`, an
|
|
20
|
+
* optimistic session override. The auth context's user object is a snapshot
|
|
21
|
+
* from sign-in; after POSTing we don't refetch it, we just remember the
|
|
22
|
+
* answer. A failed POST logs and DROPS the override at once, so the pill
|
|
23
|
+
* comes back immediately rather than reappearing at the next sign-in with no
|
|
24
|
+
* account of why it left.
|
|
20
25
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* at once, so the pill comes back immediately rather than reappearing at
|
|
25
|
-
* the next sign-in with no account of why it left.
|
|
26
|
-
* - `welcomed` (localStorage, per account) — "the welcome page was shown
|
|
27
|
-
* once". The auto-redirect there happens on the FIRST sign-in only;
|
|
28
|
-
* the pill, not the router, is the standing reminder. Per-browser by
|
|
29
|
-
* nature, which is fine: being greeted once per new machine is a welcome,
|
|
30
|
-
* not a bug.
|
|
26
|
+
* Nothing here sends anyone to the welcome page. `/` lands on Knowledge for
|
|
27
|
+
* everyone (see `RootLanding`); the pill and the Get set up list are the
|
|
28
|
+
* reminder, and the page is theirs to open.
|
|
31
29
|
*/
|
|
32
30
|
|
|
33
|
-
const WELCOMED_PREFIX = 'bevel.onboarding.welcomed.';
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The storage key holding "this account has seen the welcome page", keyed by
|
|
37
|
-
* lower-cased email so `Juan@…` and `juan@…` are one person rather than two
|
|
38
|
-
* greetings.
|
|
39
|
-
*/
|
|
40
|
-
const welcomedKey = (email: string) => `${WELCOMED_PREFIX}${email.toLowerCase()}`;
|
|
41
|
-
|
|
42
31
|
const doneLocally = new Set<string>();
|
|
43
|
-
|
|
32
|
+
/** Full storage keys set this session — see {@link setFlag}. */
|
|
33
|
+
const flagsLocally = new Set<string>();
|
|
44
34
|
const listeners = new Set<() => void>();
|
|
35
|
+
/** Bumped when ANOTHER tab changes one of the notes below — see {@link onStorage}. */
|
|
36
|
+
let storageVersion = 0;
|
|
45
37
|
|
|
46
38
|
/** Tell every mounted `useOnboarding` that the overrides above moved. */
|
|
47
39
|
function emit(): void {
|
|
48
40
|
listeners.forEach((l) => l());
|
|
49
41
|
}
|
|
50
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Another tab raised (or cleared) one of the notes. `setFlag` only wakes this
|
|
45
|
+
* tab's listeners, and the browser tells the OTHER tabs through `storage` —
|
|
46
|
+
* so a guide read, or a column closed, in one tab reaches every tab already
|
|
47
|
+
* open, rather than waiting for their next reload. A `null` key is the whole
|
|
48
|
+
* storage cleared.
|
|
49
|
+
*/
|
|
50
|
+
function onStorage(event: StorageEvent): void {
|
|
51
|
+
const { key } = event;
|
|
52
|
+
if (key !== null && !FLAG_PREFIXES.some((prefix) => key.startsWith(prefix))) return;
|
|
53
|
+
storageVersion++;
|
|
54
|
+
emit();
|
|
55
|
+
}
|
|
56
|
+
|
|
51
57
|
/**
|
|
52
58
|
* The `useSyncExternalStore` half of the subscription: register a listener and
|
|
53
59
|
* hand back its unsubscribe, so a hook that unmounts stops being notified.
|
|
60
|
+
* The window's `storage` listener lives exactly as long as there is somebody
|
|
61
|
+
* to tell.
|
|
54
62
|
*/
|
|
55
63
|
function subscribe(listener: () => void): () => void {
|
|
64
|
+
if (listeners.size === 0) window.addEventListener('storage', onStorage);
|
|
56
65
|
listeners.add(listener);
|
|
57
|
-
return () =>
|
|
66
|
+
return () => {
|
|
67
|
+
listeners.delete(listener);
|
|
68
|
+
if (listeners.size === 0) window.removeEventListener('storage', onStorage);
|
|
69
|
+
};
|
|
58
70
|
}
|
|
59
71
|
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
|
|
63
|
-
|
|
72
|
+
/**
|
|
73
|
+
* The "Get set up" column's per-account notes: the starter guide has been
|
|
74
|
+
* opened, the command menu has been opened, the column was dismissed, and its
|
|
75
|
+
* "You're set up" was seen and closed. All per-browser conveniences, not server truth, so they live beside
|
|
76
|
+
* the session override and wake the same listeners, through one tiny flag
|
|
77
|
+
* pair rather than a hand-written copy of the read/write/try-catch dance per
|
|
78
|
+
* note.
|
|
79
|
+
*/
|
|
80
|
+
const READ_GUIDE_PREFIX = 'bevel.onboarding.readGuide.';
|
|
81
|
+
const COMMAND_MENU_PREFIX = 'bevel.onboarding.commandMenuOpened.';
|
|
82
|
+
const SETUP_DISMISSED_PREFIX = 'bevel.onboarding.setupDismissed.';
|
|
83
|
+
const SETUP_COMPLETE_PREFIX = 'bevel.onboarding.setupCompleteClosed.';
|
|
84
|
+
const FLAG_PREFIXES = [READ_GUIDE_PREFIX, COMMAND_MENU_PREFIX, SETUP_DISMISSED_PREFIX, SETUP_COMPLETE_PREFIX];
|
|
85
|
+
|
|
86
|
+
/** Storage is best-effort: private-mode Safari throws, and a lost flag costs
|
|
87
|
+
* one extra row on screen, not a failure. */
|
|
88
|
+
function hasFlag(key: string): boolean {
|
|
89
|
+
if (flagsLocally.has(key)) return true;
|
|
64
90
|
try {
|
|
65
|
-
return window.localStorage.getItem(
|
|
91
|
+
return window.localStorage.getItem(key) === '1';
|
|
66
92
|
} catch {
|
|
67
93
|
return false;
|
|
68
94
|
}
|
|
69
95
|
}
|
|
70
96
|
|
|
71
97
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* touching storage or waking
|
|
98
|
+
* Raise a one-way flag. Remembered in memory as well as storage so a browser
|
|
99
|
+
* that refuses the write still honours it for the rest of the session.
|
|
100
|
+
* Idempotent: a raised flag returns without touching storage or waking
|
|
101
|
+
* listeners.
|
|
75
102
|
*/
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
|
|
103
|
+
function setFlag(key: string): void {
|
|
104
|
+
if (hasFlag(key)) return;
|
|
105
|
+
flagsLocally.add(key);
|
|
79
106
|
try {
|
|
80
|
-
window.localStorage.setItem(
|
|
107
|
+
window.localStorage.setItem(key, '1');
|
|
81
108
|
} catch {
|
|
82
|
-
/*
|
|
109
|
+
/* held in memory for this session */
|
|
83
110
|
}
|
|
84
111
|
emit();
|
|
85
112
|
}
|
|
@@ -123,42 +150,39 @@ export function markOnboardingDone(userId: string, email: string): void {
|
|
|
123
150
|
}
|
|
124
151
|
|
|
125
152
|
/**
|
|
126
|
-
* Test seam: forget the session overrides and the
|
|
153
|
+
* Test seam: forget the session overrides and the per-browser notes.
|
|
127
154
|
*
|
|
128
|
-
* Scans storage by PREFIX rather than walking `
|
|
129
|
-
* set is not a record of what is in storage. `
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* next "greets ONCE" assertion would then read "already welcomed" and fail on
|
|
134
|
-
* a state no test put there.
|
|
155
|
+
* Scans storage by PREFIX rather than walking `flagsLocally`, because that
|
|
156
|
+
* set is not a record of what is in storage. `setFlag` returns early when the
|
|
157
|
+
* key is already there, so a flag raised by an earlier test file — or by an
|
|
158
|
+
* earlier run against the same jsdom `localStorage` — never enters the set,
|
|
159
|
+
* and its key would survive a reset that only knew about the set.
|
|
135
160
|
*/
|
|
136
161
|
export function resetOnboardingForTests(): void {
|
|
137
162
|
try {
|
|
138
163
|
for (const key of Object.keys(window.localStorage)) {
|
|
139
|
-
if (key.startsWith(
|
|
164
|
+
if (FLAG_PREFIXES.some((prefix) => key.startsWith(prefix))) window.localStorage.removeItem(key);
|
|
140
165
|
}
|
|
141
166
|
} catch {
|
|
142
167
|
/* ignore */
|
|
143
168
|
}
|
|
144
169
|
doneLocally.clear();
|
|
145
|
-
|
|
170
|
+
flagsLocally.clear();
|
|
146
171
|
emit();
|
|
147
172
|
}
|
|
148
173
|
|
|
149
174
|
export interface OnboardingController {
|
|
150
175
|
/** The reminder is alive: the server says onboarding is not done. */
|
|
151
176
|
showPill: boolean;
|
|
152
|
-
/** First sign-in, still unanswered: drives the ONE-TIME redirect to the welcome page. */
|
|
153
|
-
shouldWelcome: boolean;
|
|
154
|
-
markWelcomed(): void;
|
|
155
177
|
markDone(): void;
|
|
156
178
|
}
|
|
157
179
|
|
|
180
|
+
/** The subscription's version counter: every override and note, in this tab or another, changes it. */
|
|
181
|
+
const snapshot = () => `${doneLocally.size}:${flagsLocally.size}:${storageVersion}`;
|
|
182
|
+
const serverSnapshot = () => '0:0:0';
|
|
183
|
+
|
|
158
184
|
const SIGNED_OUT: OnboardingController = {
|
|
159
185
|
showPill: false,
|
|
160
|
-
shouldWelcome: false,
|
|
161
|
-
markWelcomed: () => {},
|
|
162
186
|
markDone: () => {},
|
|
163
187
|
};
|
|
164
188
|
|
|
@@ -172,20 +196,70 @@ const SIGNED_OUT: OnboardingController = {
|
|
|
172
196
|
export function useOnboarding(): OnboardingController {
|
|
173
197
|
const auth = useContext(AuthContext);
|
|
174
198
|
const user = auth?.user ?? null;
|
|
175
|
-
// The subscription's version counter: overrides and
|
|
176
|
-
|
|
177
|
-
useSyncExternalStore(
|
|
178
|
-
subscribe,
|
|
179
|
-
() => `${doneLocally.size}:${welcomedLocally.size}`,
|
|
180
|
-
() => '0:0',
|
|
181
|
-
);
|
|
199
|
+
// The subscription's version counter: overrides and notes change under it. The snapshot is a cheap string so identity comparison is exact.
|
|
200
|
+
useSyncExternalStore(subscribe, snapshot, serverSnapshot);
|
|
182
201
|
if (!user) return SIGNED_OUT;
|
|
183
202
|
const email = user.email;
|
|
184
203
|
const done = user.onboardingDone !== false || doneLocally.has(email);
|
|
185
204
|
return {
|
|
186
205
|
showPill: !done,
|
|
187
|
-
shouldWelcome: !done && !hasBeenWelcomed(email),
|
|
188
|
-
markWelcomed: () => markWelcomed(email),
|
|
189
206
|
markDone: () => markOnboardingDone(user.id, email),
|
|
190
207
|
};
|
|
191
208
|
}
|
|
209
|
+
|
|
210
|
+
export interface SetupChecklistState {
|
|
211
|
+
/** The starter guide ("How to get started") has been opened on this browser. */
|
|
212
|
+
readGuide: boolean;
|
|
213
|
+
/** The command menu (Ctrl/⌘K) has been opened on this browser, by any route. */
|
|
214
|
+
openedCommandMenu: boolean;
|
|
215
|
+
/** The person closed the "Get set up" column; it stays closed. */
|
|
216
|
+
dismissed: boolean;
|
|
217
|
+
/**
|
|
218
|
+
* The person closed the column's "You're set up" — the list was finished
|
|
219
|
+
* and celebrated, and the column is gone for good.
|
|
220
|
+
*/
|
|
221
|
+
completionClosed: boolean;
|
|
222
|
+
markGuideRead(): void;
|
|
223
|
+
markCommandMenuOpened(): void;
|
|
224
|
+
dismiss(): void;
|
|
225
|
+
closeCompletion(): void;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const NO_CHECKLIST: SetupChecklistState = {
|
|
229
|
+
readGuide: false,
|
|
230
|
+
openedCommandMenu: false,
|
|
231
|
+
dismissed: false,
|
|
232
|
+
completionClosed: false,
|
|
233
|
+
markGuideRead: () => {},
|
|
234
|
+
markCommandMenuOpened: () => {},
|
|
235
|
+
dismiss: () => {},
|
|
236
|
+
closeCompletion: () => {},
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* The client-side half of the "Get set up" column: the tick the server has no
|
|
241
|
+
* field for, and the column's two ways of going away. Keyed by lower-cased email, so `Juan@…` and `juan@…` are
|
|
242
|
+
* one person, and tolerant of a missing auth provider for the same reason
|
|
243
|
+
* {@link useOnboarding} is.
|
|
244
|
+
*/
|
|
245
|
+
export function useSetupChecklist(): SetupChecklistState {
|
|
246
|
+
const auth = useContext(AuthContext);
|
|
247
|
+
const user = auth?.user ?? null;
|
|
248
|
+
useSyncExternalStore(subscribe, snapshot, serverSnapshot);
|
|
249
|
+
if (!user) return NO_CHECKLIST;
|
|
250
|
+
const email = user.email.toLowerCase();
|
|
251
|
+
const readKey = `${READ_GUIDE_PREFIX}${email}`;
|
|
252
|
+
const commandMenuKey = `${COMMAND_MENU_PREFIX}${email}`;
|
|
253
|
+
const dismissedKey = `${SETUP_DISMISSED_PREFIX}${email}`;
|
|
254
|
+
const completeKey = `${SETUP_COMPLETE_PREFIX}${email}`;
|
|
255
|
+
return {
|
|
256
|
+
readGuide: hasFlag(readKey),
|
|
257
|
+
openedCommandMenu: hasFlag(commandMenuKey),
|
|
258
|
+
dismissed: hasFlag(dismissedKey),
|
|
259
|
+
completionClosed: hasFlag(completeKey),
|
|
260
|
+
markGuideRead: () => setFlag(readKey),
|
|
261
|
+
markCommandMenuOpened: () => setFlag(commandMenuKey),
|
|
262
|
+
dismiss: () => setFlag(dismissedKey),
|
|
263
|
+
closeCompletion: () => setFlag(completeKey),
|
|
264
|
+
};
|
|
265
|
+
}
|