@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,651 @@
|
|
|
1
|
+
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
2
|
+
import { useLocation, useNavigate } from 'react-router-dom';
|
|
3
|
+
import { Check, Copy, X } from 'lucide-react';
|
|
4
|
+
import {
|
|
5
|
+
KNOWLEDGE_BASE_DIR,
|
|
6
|
+
currentBranchModel,
|
|
7
|
+
currentKbLayout,
|
|
8
|
+
isPersonalPluginDir,
|
|
9
|
+
type FileTreeEntry,
|
|
10
|
+
} from '@bevel-software/platform-shared';
|
|
11
|
+
import { Button, IconButton, buttonClasses } from '../../../shared/components';
|
|
12
|
+
import { cn } from '../../../lib/utils';
|
|
13
|
+
import { copyToClipboard } from '../../../lib/clipboard';
|
|
14
|
+
import { useAdmin } from '../../admin/state/admin.context';
|
|
15
|
+
import { listAccounts } from '../../auth/services/account.api';
|
|
16
|
+
import { listPlugins, type PluginSummary } from '../../library/services/plugins.api';
|
|
17
|
+
import { LIBRARY_ROOT, isLibraryLocation } from '../../library/routes/library-paths';
|
|
18
|
+
import { usePluginsRevision } from '../../library/state/plugins-revision';
|
|
19
|
+
import { useMediaQuery } from '../../layout/hooks/useMediaQuery';
|
|
20
|
+
import { SETUP_COLUMN_HIDDEN_QUERY } from '../../layout/breakpoints';
|
|
21
|
+
import { useWorkspace } from '../../workspace/state/workspace.context';
|
|
22
|
+
import { useMergedWorkspaceTree } from '../../workspace/hooks/useMergedWorkspaceTree';
|
|
23
|
+
import { useFileNav } from '../../workspace/routing/kb-routes';
|
|
24
|
+
import { useCreatePage } from '../../workspace/hooks/useCreatePage';
|
|
25
|
+
import { findEntryByPath, pathExistsInTree } from '../../workspace/utils/fileTree';
|
|
26
|
+
import { useOnboarding, useSetupChecklist } from '../state/onboarding';
|
|
27
|
+
import { useAgentConnection } from '../state/agent-connection';
|
|
28
|
+
import { chatGptPromptUrl, claudePromptUrl, firstPagePromptFor, firstPageRoute } from '../first-page-prompt';
|
|
29
|
+
import { useStarterPacks } from '../state/starter-packs';
|
|
30
|
+
import { useInviteDialog } from '../state/invite-dialog.context';
|
|
31
|
+
import { WELCOME_PATH } from '../paths';
|
|
32
|
+
import { COMMAND_MENU_SHORTCUT_LABEL, openCommandMenu } from '../../toolbar/commands/command-menu';
|
|
33
|
+
|
|
34
|
+
/** The starter page every new knowledge base is seeded with (`kb-template/`). */
|
|
35
|
+
const GUIDE_FILE = 'How to get started.md';
|
|
36
|
+
|
|
37
|
+
interface SetupAction {
|
|
38
|
+
label: string;
|
|
39
|
+
onClick(): void;
|
|
40
|
+
primary?: boolean;
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface SetupItem {
|
|
45
|
+
id: string;
|
|
46
|
+
title: string;
|
|
47
|
+
done: boolean;
|
|
48
|
+
hint?: string;
|
|
49
|
+
action?: SetupAction;
|
|
50
|
+
/** Anything the step offers beyond one button, under it. */
|
|
51
|
+
extra?: ReactNode;
|
|
52
|
+
/** Why the step's action just failed, said on the step itself. */
|
|
53
|
+
error?: string | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether the Knowledge folder holds anything a person put there: any file
|
|
58
|
+
* other than the starter guide, the repository's dot-files and the folder
|
|
59
|
+
* access rules. A dropped PDF counts — "write your first page" is about the
|
|
60
|
+
* knowledge base having the team's content in it, not about Markdown. A
|
|
61
|
+
* starter pack's page still as the pack wrote it (`placeholders`) is a task
|
|
62
|
+
* to fill in, not content, so it does not count either.
|
|
63
|
+
*/
|
|
64
|
+
function hasOwnContent(
|
|
65
|
+
entry: FileTreeEntry | null | undefined,
|
|
66
|
+
guidePath: string,
|
|
67
|
+
placeholders: ReadonlySet<string> = new Set(),
|
|
68
|
+
): boolean {
|
|
69
|
+
if (!entry) return false;
|
|
70
|
+
for (const child of entry.children ?? []) {
|
|
71
|
+
if (child.name.startsWith('.')) continue;
|
|
72
|
+
if (child.type === 'directory') {
|
|
73
|
+
if (hasOwnContent(child, guidePath, placeholders)) return true;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
// Exactly `access.md`: the platform reserves that name and no other
|
|
77
|
+
// spelling, so an `Access.md` someone wrote is a page like any other.
|
|
78
|
+
if (child.relativePath === guidePath || child.name === 'access.md') continue;
|
|
79
|
+
if (placeholders.has(child.relativePath)) continue;
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** A plugin for a team, not somebody's personal shelf. */
|
|
86
|
+
function isTeamPlugin(plugin: PluginSummary): boolean {
|
|
87
|
+
const layout = currentKbLayout();
|
|
88
|
+
return plugin.folders.some((folder) => !isPersonalPluginDir(folder, layout));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* "Is there a team plugin yet?", asked of `GET /api/plugins` — the same
|
|
93
|
+
* catalog the Library reads, fetched here on its own because the Library's
|
|
94
|
+
* provider only exists under its routes and this column sits beside both
|
|
95
|
+
* apps. Asked again whenever `refreshKey` moves — on entering Skills & Tools,
|
|
96
|
+
* and when this tab creates a plugin — and never again once the answer is
|
|
97
|
+
* yes.
|
|
98
|
+
*/
|
|
99
|
+
function useTeamPluginExists(enabled: boolean, refreshKey: string): { found: boolean; settled: boolean } {
|
|
100
|
+
const [found, setFound] = useState(false);
|
|
101
|
+
const [settled, setSettled] = useState(false);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (!enabled || found) return;
|
|
104
|
+
let cancelled = false;
|
|
105
|
+
listPlugins()
|
|
106
|
+
.then((plugins) => {
|
|
107
|
+
if (!cancelled && plugins.some(isTeamPlugin)) setFound(true);
|
|
108
|
+
})
|
|
109
|
+
.catch(() => {
|
|
110
|
+
/* unanswered is "not yet": the step stays open, nothing breaks */
|
|
111
|
+
})
|
|
112
|
+
.finally(() => {
|
|
113
|
+
if (!cancelled) setSettled(true);
|
|
114
|
+
});
|
|
115
|
+
return () => {
|
|
116
|
+
cancelled = true;
|
|
117
|
+
};
|
|
118
|
+
}, [enabled, found, refreshKey]);
|
|
119
|
+
// A yes is an answer. Finding it re-runs the effect, whose cleanup cancels
|
|
120
|
+
// the `finally` that would have settled, so `found` settles by itself.
|
|
121
|
+
return { found, settled: settled || found };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* "Is anybody else here yet?" — more than one account a person signs in
|
|
126
|
+
* with. The platform's own machine accounts (`isSystem`) are not a team, and
|
|
127
|
+
* a switched-off account is nobody who can join. An invited account that has
|
|
128
|
+
* not signed in yet DOES count: the step is "Invite your team", and inviting
|
|
129
|
+
* is what the admin can do — when each person first signs in is theirs.
|
|
130
|
+
* Re-asked whenever the invite dialog created somebody.
|
|
131
|
+
*/
|
|
132
|
+
function useHasTeammate(enabled: boolean, revision: number): { found: boolean; settled: boolean } {
|
|
133
|
+
const [found, setFound] = useState(false);
|
|
134
|
+
const [settled, setSettled] = useState(false);
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
if (!enabled || found) return;
|
|
137
|
+
let cancelled = false;
|
|
138
|
+
listAccounts()
|
|
139
|
+
.then((accounts) => {
|
|
140
|
+
if (!cancelled && accounts.filter((a) => !a.isSystem && !a.deactivatedAt).length > 1) setFound(true);
|
|
141
|
+
})
|
|
142
|
+
.catch(() => {
|
|
143
|
+
/* as above: unknown leaves the step open */
|
|
144
|
+
})
|
|
145
|
+
.finally(() => {
|
|
146
|
+
if (!cancelled) setSettled(true);
|
|
147
|
+
});
|
|
148
|
+
return () => {
|
|
149
|
+
cancelled = true;
|
|
150
|
+
};
|
|
151
|
+
}, [enabled, found, revision]);
|
|
152
|
+
// Settled by a yes, as above.
|
|
153
|
+
return { found, settled: settled || found };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The "Get set up" column: a short checklist beside both apps that ticks
|
|
158
|
+
* itself off from what the app already knows, rather than from clicks on it.
|
|
159
|
+
*
|
|
160
|
+
* Every tick is DERIVED — the server's onboarding flag, the file tree, the
|
|
161
|
+
* plugin catalog, the account list — so doing a step anywhere in the app
|
|
162
|
+
* counts, and the column never claims something the workspace does not show.
|
|
163
|
+
* Only "read the guide" and "open the command menu" have no server fact
|
|
164
|
+
* behind them; those two, and the two ways of closing the column, are
|
|
165
|
+
* per-browser notes (see `useSetupChecklist`).
|
|
166
|
+
*
|
|
167
|
+
* It gets out of the way on its own terms: on the welcome page (which is the
|
|
168
|
+
* same instructions, full-size), below the width where a 288px column still
|
|
169
|
+
* leaves a readable page, and for good once closed. Finishing every step does
|
|
170
|
+
* not make it vanish mid-sentence: it says "You're set up" first, and goes
|
|
171
|
+
* once that is closed.
|
|
172
|
+
* The admin-only steps (storage, plugin, invite) are hidden from members,
|
|
173
|
+
* whose checklist is about using the workspace, not setting it up.
|
|
174
|
+
*/
|
|
175
|
+
export function GetStartedColumn() {
|
|
176
|
+
const { pathname } = useLocation();
|
|
177
|
+
const navigate = useNavigate();
|
|
178
|
+
const tooNarrow = useMediaQuery(SETUP_COLUMN_HIDDEN_QUERY);
|
|
179
|
+
const onboarding = useOnboarding();
|
|
180
|
+
const checklist = useSetupChecklist();
|
|
181
|
+
const { isAdmin, isAdminLoading = false } = useAdmin();
|
|
182
|
+
const { kbDirName, openFilePath, workspaceBranch } = useWorkspace();
|
|
183
|
+
const { tree } = useMergedWorkspaceTree();
|
|
184
|
+
const { openWorkspacePath } = useFileNav();
|
|
185
|
+
const { createPage } = useCreatePage();
|
|
186
|
+
const invite = useInviteDialog();
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Whether the person's agent has reached the platform — told by the
|
|
190
|
+
* server's `agent-connected` event, and asked on mount and again when the
|
|
191
|
+
* person comes back to the tab, never on a timer — so someone who
|
|
192
|
+
* connected without ever opening the welcome page still gets the tick.
|
|
193
|
+
* Connecting is what the onboarding asked for, so it concludes it too: the
|
|
194
|
+
* pill goes. Once per mount, for the reason the welcome page gives.
|
|
195
|
+
*/
|
|
196
|
+
const gone = checklist.dismissed || checklist.completionClosed;
|
|
197
|
+
const agent = useAgentConnection({ enabled: !gone });
|
|
198
|
+
const concluded = useRef(false);
|
|
199
|
+
const { showPill, markDone } = onboarding;
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
if (!agent.connected || !showPill || concluded.current) return;
|
|
202
|
+
concluded.current = true;
|
|
203
|
+
markDone();
|
|
204
|
+
}, [agent.connected, showPill, markDone]);
|
|
205
|
+
|
|
206
|
+
const onWelcome = pathname === WELCOME_PATH;
|
|
207
|
+
const askServer = isAdmin && !gone;
|
|
208
|
+
/**
|
|
209
|
+
* The plugin question's refresh: once per ENTRY into Skills & Tools (that
|
|
210
|
+
* is where a plugin gets made), and whenever this tab creates one — not on
|
|
211
|
+
* every move between its pages, which for a new workspace is the same
|
|
212
|
+
* empty catalog asked for over and over. Counted in state, adjusted while
|
|
213
|
+
* rendering, so the count moves in the same render as the path.
|
|
214
|
+
*/
|
|
215
|
+
const inLibrary = isLibraryLocation(pathname);
|
|
216
|
+
const [libraryEntries, setLibraryEntries] = useState({ inLibrary, count: 0 });
|
|
217
|
+
if (libraryEntries.inLibrary !== inLibrary) {
|
|
218
|
+
setLibraryEntries({ inLibrary, count: libraryEntries.count + (inLibrary ? 1 : 0) });
|
|
219
|
+
}
|
|
220
|
+
const pluginsCreated = usePluginsRevision();
|
|
221
|
+
const plugin = useTeamPluginExists(askServer, `${libraryEntries.count}:${pluginsCreated}`);
|
|
222
|
+
const teammate = useHasTeammate(askServer, invite?.invitedRevision ?? 0);
|
|
223
|
+
|
|
224
|
+
const knowledgeRoot = kbDirName ? `${kbDirName}/${KNOWLEDGE_BASE_DIR}` : null;
|
|
225
|
+
const guidePath = knowledgeRoot ? `${knowledgeRoot}/${GUIDE_FILE}` : null;
|
|
226
|
+
const guideExists = guidePath !== null && pathExistsInTree(tree, guidePath);
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* The starter pack the team chose, if any: its first-page request replaces
|
|
230
|
+
* the generic one, and its pages stay placeholders — not a first page —
|
|
231
|
+
* until someone fills one in. Which are still untouched is the server's
|
|
232
|
+
* answer (it compares them with the pack), asked again whenever the tree
|
|
233
|
+
* changes while any are left. That answer describes the DEFAULT branch,
|
|
234
|
+
* where the pack landed; the tree here is the branch on screen, so on any
|
|
235
|
+
* other branch the step reads that tree alone rather than apply the
|
|
236
|
+
* default branch's placeholders to pages that may well be filled in there.
|
|
237
|
+
*/
|
|
238
|
+
const starter = useStarterPacks({ enabled: !gone });
|
|
239
|
+
const chosenPack = starter.answer?.chosenPack ?? null;
|
|
240
|
+
const onDefaultBranch = workspaceBranch !== null && workspaceBranch === currentBranchModel().defaultBranch;
|
|
241
|
+
const placeholders = new Set(onDefaultBranch ? (chosenPack?.starterPages ?? []) : []);
|
|
242
|
+
const { reload: reloadStarter } = starter;
|
|
243
|
+
const waitingOnPlaceholders = placeholders.size > 0;
|
|
244
|
+
const firstTree = useRef(tree);
|
|
245
|
+
useEffect(() => {
|
|
246
|
+
if (!waitingOnPlaceholders || tree === firstTree.current) return;
|
|
247
|
+
void reloadStarter();
|
|
248
|
+
}, [tree, waitingOnPlaceholders, reloadStarter]);
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* "New page": create a Markdown page in the Knowledge folder and open it
|
|
252
|
+
* already in the editor (`useCreatePage`, shared with the command menu). The failure is kept here and shown on the step
|
|
253
|
+
* because nothing else would say it — toasts only speak inside the
|
|
254
|
+
* Library, and a refusal (a protected branch's write gate) is exactly what
|
|
255
|
+
* the person needs to read.
|
|
256
|
+
*/
|
|
257
|
+
const [newPage, setNewPage] = useState<{ busy: boolean; error: string | null }>({ busy: false, error: null });
|
|
258
|
+
const createFirstPage = async () => {
|
|
259
|
+
if (!knowledgeRoot || newPage.busy) return;
|
|
260
|
+
setNewPage({ busy: true, error: null });
|
|
261
|
+
try {
|
|
262
|
+
// The step ticks itself from the refreshed tree (any page but the guide
|
|
263
|
+
// counts); the page opens in the editor with the cursor in it.
|
|
264
|
+
await createPage();
|
|
265
|
+
setNewPage({ busy: false, error: null });
|
|
266
|
+
} catch (err) {
|
|
267
|
+
setNewPage({ busy: false, error: err instanceof Error ? err.message : String(err) });
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// Opening the guide by any route counts — the tree, a link, this column.
|
|
272
|
+
const { readGuide, markGuideRead } = checklist;
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
if (guidePath && openFilePath === guidePath && !readGuide) markGuideRead();
|
|
275
|
+
}, [guidePath, openFilePath, readGuide, markGuideRead]);
|
|
276
|
+
|
|
277
|
+
const items: SetupItem[] = [
|
|
278
|
+
{ id: 'workspace', title: 'Create your workspace', done: true },
|
|
279
|
+
];
|
|
280
|
+
if (isAdmin) {
|
|
281
|
+
// Reaching this column at all means the setup gate let you through, and
|
|
282
|
+
// the gate's last question is where the knowledge lives.
|
|
283
|
+
items.push({ id: 'storage', title: 'Choose where your knowledge lives', done: true });
|
|
284
|
+
}
|
|
285
|
+
items.push({
|
|
286
|
+
id: 'agent',
|
|
287
|
+
title: 'Connect your agent',
|
|
288
|
+
done: !showPill || agent.connected,
|
|
289
|
+
hint: 'So it can read and write this knowledge base.',
|
|
290
|
+
action: { label: 'Connect', onClick: () => navigate(WELCOME_PATH), primary: true },
|
|
291
|
+
});
|
|
292
|
+
if (guideExists && guidePath) {
|
|
293
|
+
items.push({
|
|
294
|
+
id: 'guide',
|
|
295
|
+
title: 'Read “How to get started”',
|
|
296
|
+
done: readGuide,
|
|
297
|
+
hint: 'Two minutes on how pages, plugins and change requests fit together.',
|
|
298
|
+
action: {
|
|
299
|
+
label: 'Open it',
|
|
300
|
+
onClick: () => {
|
|
301
|
+
markGuideRead();
|
|
302
|
+
openWorkspacePath(guidePath);
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
const newPageAction: SetupAction | undefined = knowledgeRoot
|
|
308
|
+
? {
|
|
309
|
+
label: newPage.busy ? 'Creating…' : 'New page',
|
|
310
|
+
onClick: () => void createFirstPage(),
|
|
311
|
+
disabled: newPage.busy,
|
|
312
|
+
}
|
|
313
|
+
: undefined;
|
|
314
|
+
/**
|
|
315
|
+
* With an agent connected, the quickest first page is one it writes: a new
|
|
316
|
+
* chat with the request already typed (or the request to paste, for an
|
|
317
|
+
* agent no link can open), and the tick arrives by itself when the page
|
|
318
|
+
* lands in the tree. Before then that button would open a chat
|
|
319
|
+
* that cannot reach this knowledge base, so the step says what connecting
|
|
320
|
+
* would add instead.
|
|
321
|
+
*
|
|
322
|
+
* Not ticked before the starter-pack answer is in: until then a pack's
|
|
323
|
+
* untouched pages would read as content, and a fast tree could complete
|
|
324
|
+
* the whole list — and let it be closed — on the strength of placeholders.
|
|
325
|
+
* A failed request settles too, and the pages count as the app counted
|
|
326
|
+
* them before there were packs.
|
|
327
|
+
*/
|
|
328
|
+
items.push({
|
|
329
|
+
id: 'page',
|
|
330
|
+
title: 'Write your first page',
|
|
331
|
+
done:
|
|
332
|
+
knowledgeRoot !== null &&
|
|
333
|
+
guidePath !== null &&
|
|
334
|
+
starter.settled &&
|
|
335
|
+
hasOwnContent(findEntryByPath(tree, knowledgeRoot), guidePath, placeholders),
|
|
336
|
+
...(agent.connected
|
|
337
|
+
? {
|
|
338
|
+
hint: 'Have your agent write it, or start one here.',
|
|
339
|
+
extra: (
|
|
340
|
+
<FirstPagePromptActions
|
|
341
|
+
client={agent.client}
|
|
342
|
+
kind={agent.kind}
|
|
343
|
+
prompt={firstPagePromptFor(chosenPack)}
|
|
344
|
+
newPage={newPageAction}
|
|
345
|
+
/>
|
|
346
|
+
),
|
|
347
|
+
}
|
|
348
|
+
: {
|
|
349
|
+
hint: 'Start one here, or drop files into the file tree.',
|
|
350
|
+
action: newPageAction,
|
|
351
|
+
extra: <span className="text-meta text-ink-faint">Connect your agent and it can write pages for you.</span>,
|
|
352
|
+
}),
|
|
353
|
+
error: newPage.error,
|
|
354
|
+
});
|
|
355
|
+
/**
|
|
356
|
+
* The command menu is how anything else gets found or done, so the list
|
|
357
|
+
* teaches it — by having it opened, which is the whole lesson. The tick is
|
|
358
|
+
* raised by the palette itself on ANY open (the box, the shortcut, this
|
|
359
|
+
* button), so someone who already knew the shortcut is never asked to.
|
|
360
|
+
*/
|
|
361
|
+
items.push({
|
|
362
|
+
id: 'command-menu',
|
|
363
|
+
title: `Find or do anything with ${COMMAND_MENU_SHORTCUT_LABEL}`,
|
|
364
|
+
done: checklist.openedCommandMenu,
|
|
365
|
+
hint: 'Type what you want: a page, a skill, or an action like Invite people.',
|
|
366
|
+
action: { label: 'Try it', onClick: openCommandMenu },
|
|
367
|
+
});
|
|
368
|
+
if (isAdmin) {
|
|
369
|
+
items.push({
|
|
370
|
+
id: 'plugin',
|
|
371
|
+
title: 'Create a plugin for your team',
|
|
372
|
+
done: plugin.found,
|
|
373
|
+
hint: 'A shared place for your team’s skills and tools.',
|
|
374
|
+
action: { label: 'Open Skills & Tools', onClick: () => navigate(LIBRARY_ROOT) },
|
|
375
|
+
});
|
|
376
|
+
items.push({
|
|
377
|
+
id: 'invite',
|
|
378
|
+
title: 'Invite your team',
|
|
379
|
+
done: teammate.found,
|
|
380
|
+
hint: 'They sign in with their work account.',
|
|
381
|
+
action: invite ? { label: 'Invite people', onClick: invite.open } : undefined,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const doneCount = items.filter((i) => i.done).length;
|
|
386
|
+
// Until the admin verdict and its two questions are answered, the list is
|
|
387
|
+
// not known — and showing a half-ticked list for a moment to an admin who
|
|
388
|
+
// has done everything would be a column that flashes on every load.
|
|
389
|
+
const settled = !isAdminLoading && (!isAdmin || (plugin.settled && teammate.settled));
|
|
390
|
+
const allDone = doneCount === items.length;
|
|
391
|
+
// The completion line says whether the agent can reach the knowledge base,
|
|
392
|
+
// so it waits for that answer rather than rewriting itself under the reader.
|
|
393
|
+
// So does the list for the file tree: before it loads, the guide reads as
|
|
394
|
+
// absent and the first page as unwritten — a shorter list, falsely open.
|
|
395
|
+
if (onWelcome || tooNarrow || gone || tree === null || !settled || (allDone && !agent.settled)) {
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (allDone) {
|
|
400
|
+
return (
|
|
401
|
+
<SetupComplete agentConnected={agent.connected} team={isAdmin} onClose={checklist.closeCompletion} />
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return (
|
|
406
|
+
<aside
|
|
407
|
+
aria-label="Get set up"
|
|
408
|
+
className="w-72 flex-none overflow-y-auto border-l border-line bg-canvas px-4.5 py-4"
|
|
409
|
+
>
|
|
410
|
+
<div className="flex h-8 items-center gap-2">
|
|
411
|
+
<h2 className="text-strong font-semibold text-ink">Get set up</h2>
|
|
412
|
+
<span className="ml-auto text-meta text-ink-faint tabular-nums">
|
|
413
|
+
{doneCount} of {items.length}
|
|
414
|
+
</span>
|
|
415
|
+
<IconButton size={24} aria-label="Dismiss Get set up" title="Dismiss" onClick={checklist.dismiss}>
|
|
416
|
+
<X size={14} aria-hidden />
|
|
417
|
+
</IconButton>
|
|
418
|
+
</div>
|
|
419
|
+
<div
|
|
420
|
+
role="progressbar"
|
|
421
|
+
aria-label="Setup progress"
|
|
422
|
+
aria-valuemin={0}
|
|
423
|
+
aria-valuemax={items.length}
|
|
424
|
+
aria-valuenow={doneCount}
|
|
425
|
+
className="mt-1.5 mb-1 h-1 overflow-hidden rounded-full bg-line"
|
|
426
|
+
>
|
|
427
|
+
<div
|
|
428
|
+
className="h-full bg-ok transition-[width] duration-300 motion-reduce:transition-none"
|
|
429
|
+
style={{ width: `${(doneCount / items.length) * 100}%` }}
|
|
430
|
+
/>
|
|
431
|
+
</div>
|
|
432
|
+
<ul>
|
|
433
|
+
{items.map((item) => (
|
|
434
|
+
<li
|
|
435
|
+
key={item.id}
|
|
436
|
+
className="grid grid-cols-[18px_minmax(0,1fr)] gap-2.5 border-t border-line py-2.5 first:border-t-0"
|
|
437
|
+
>
|
|
438
|
+
<span
|
|
439
|
+
aria-hidden
|
|
440
|
+
className={cn(
|
|
441
|
+
'mt-0.5 flex size-4 items-center justify-center rounded-full border-[1.5px]',
|
|
442
|
+
item.done ? 'border-ok bg-ok text-white' : 'border-line-strong',
|
|
443
|
+
)}
|
|
444
|
+
>
|
|
445
|
+
{item.done && <Check size={10} strokeWidth={3} />}
|
|
446
|
+
</span>
|
|
447
|
+
<div className="min-w-0">
|
|
448
|
+
<div
|
|
449
|
+
className={cn(
|
|
450
|
+
'text-ui',
|
|
451
|
+
item.done ? 'font-medium text-ink-faint line-through' : 'font-semibold text-ink',
|
|
452
|
+
)}
|
|
453
|
+
>
|
|
454
|
+
{item.title}
|
|
455
|
+
{item.done && <span className="sr-only"> (done)</span>}
|
|
456
|
+
</div>
|
|
457
|
+
{!item.done && (item.hint || item.action || item.extra) && (
|
|
458
|
+
<div className="mt-1 grid justify-items-start gap-2 text-detail text-ink-muted">
|
|
459
|
+
{item.hint && <span>{item.hint}</span>}
|
|
460
|
+
{item.action && (
|
|
461
|
+
<Button
|
|
462
|
+
size="sm"
|
|
463
|
+
variant={item.action.primary ? 'primary' : 'outline'}
|
|
464
|
+
onClick={item.action.onClick}
|
|
465
|
+
disabled={item.action.disabled}
|
|
466
|
+
>
|
|
467
|
+
{item.action.label}
|
|
468
|
+
</Button>
|
|
469
|
+
)}
|
|
470
|
+
{item.extra}
|
|
471
|
+
{item.error && (
|
|
472
|
+
<span role="alert" className="text-danger">
|
|
473
|
+
{item.error}
|
|
474
|
+
</span>
|
|
475
|
+
)}
|
|
476
|
+
</div>
|
|
477
|
+
)}
|
|
478
|
+
</div>
|
|
479
|
+
</li>
|
|
480
|
+
))}
|
|
481
|
+
</ul>
|
|
482
|
+
</aside>
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* The column's last state: every step is done. Shown when the last tick lands
|
|
488
|
+
* — or on arrival, for a list finished elsewhere and never celebrated — and
|
|
489
|
+
* kept until Close, which retires the column for good on this browser.
|
|
490
|
+
*
|
|
491
|
+
* The line says only what is true: "Connect your agent" also ticks when the
|
|
492
|
+
* onboarding was concluded without an agent ever calling in, and members
|
|
493
|
+
* have no team step. A status region, so the change is announced without
|
|
494
|
+
* moving anyone's focus; the entrance is the welcome page's own, motion-safe.
|
|
495
|
+
*/
|
|
496
|
+
function SetupComplete({
|
|
497
|
+
agentConnected,
|
|
498
|
+
team,
|
|
499
|
+
onClose,
|
|
500
|
+
}: {
|
|
501
|
+
agentConnected: boolean;
|
|
502
|
+
team: boolean;
|
|
503
|
+
onClose(): void;
|
|
504
|
+
}) {
|
|
505
|
+
const ready = agentConnected
|
|
506
|
+
? 'Your agent can read and write your knowledge base'
|
|
507
|
+
: 'Your knowledge base is ready';
|
|
508
|
+
return (
|
|
509
|
+
<aside
|
|
510
|
+
aria-label="Get set up"
|
|
511
|
+
className="w-72 flex-none overflow-y-auto border-l border-line bg-canvas px-4.5 py-4"
|
|
512
|
+
>
|
|
513
|
+
<div role="status" className="grid justify-items-start gap-2 motion-safe:animate-onboarding-greeting">
|
|
514
|
+
<span aria-hidden className="flex size-8 items-center justify-center rounded-full bg-ok text-white">
|
|
515
|
+
<Check size={16} strokeWidth={3} />
|
|
516
|
+
</span>
|
|
517
|
+
<h2 className="text-strong font-semibold text-ink">You’re set up</h2>
|
|
518
|
+
<p className="text-detail text-ink-muted">
|
|
519
|
+
{ready}
|
|
520
|
+
{team ? ', and your team can join you.' : '.'}
|
|
521
|
+
</p>
|
|
522
|
+
<Button size="sm" variant="outline" onClick={onClose}>
|
|
523
|
+
Close
|
|
524
|
+
</Button>
|
|
525
|
+
</div>
|
|
526
|
+
</aside>
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/** The prompt opened in a new chat, as a real link (see `FirstPagePromptActions`). */
|
|
531
|
+
function PromptLink({ href, primary, children }: { href: string; primary?: boolean; children: ReactNode }) {
|
|
532
|
+
return (
|
|
533
|
+
<a
|
|
534
|
+
href={href}
|
|
535
|
+
target="_blank"
|
|
536
|
+
rel="noopener noreferrer"
|
|
537
|
+
className={
|
|
538
|
+
primary
|
|
539
|
+
? buttonClasses({ variant: 'primary', size: 'sm' })
|
|
540
|
+
: 'text-ink-muted transition-colors hover:text-ink'
|
|
541
|
+
}
|
|
542
|
+
>
|
|
543
|
+
{children}
|
|
544
|
+
</a>
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* The agent's way to the first-page prompt, led by the one that suits the
|
|
550
|
+
* agent that connected (`firstPageRoute`), with the others quiet beneath it.
|
|
551
|
+
*
|
|
552
|
+
* Claude's and ChatGPT's connectors get "Ask … to write it", a new chat with
|
|
553
|
+
* the prompt typed. Every other agent — Claude Code, Cursor, anything on the
|
|
554
|
+
* local server, a connection key, an unknown name — has no link that would
|
|
555
|
+
* reach it, so Copy prompt leads there and says where to paste; the two web
|
|
556
|
+
* links stay as quiet extras for someone who uses those too.
|
|
557
|
+
*
|
|
558
|
+
* Real links rather than buttons that call `window.open`: a new tab is what
|
|
559
|
+
* they are, so they should say so to the browser — middle-click, "copy link",
|
|
560
|
+
* and the status-bar preview of where they go all work.
|
|
561
|
+
*
|
|
562
|
+
* Copying answers on the button itself and in a live region; there is no
|
|
563
|
+
* toast to fall back on out here (toasts speak inside the Library only).
|
|
564
|
+
*/
|
|
565
|
+
function FirstPagePromptActions({
|
|
566
|
+
client,
|
|
567
|
+
kind,
|
|
568
|
+
prompt,
|
|
569
|
+
newPage,
|
|
570
|
+
}: {
|
|
571
|
+
client?: string;
|
|
572
|
+
kind?: 'agent' | 'key';
|
|
573
|
+
/** The request: the chosen starter pack's, or the generic one. */
|
|
574
|
+
prompt: string;
|
|
575
|
+
newPage?: SetupAction;
|
|
576
|
+
}) {
|
|
577
|
+
const [copied, setCopied] = useState<'idle' | 'ok' | 'fail'>('idle');
|
|
578
|
+
const resetTimer = useRef<number | undefined>(undefined);
|
|
579
|
+
useEffect(() => () => window.clearTimeout(resetTimer.current), []);
|
|
580
|
+
const { primary, agentName } = firstPageRoute(client, kind);
|
|
581
|
+
|
|
582
|
+
async function copy() {
|
|
583
|
+
const ok = await copyToClipboard(prompt);
|
|
584
|
+
window.clearTimeout(resetTimer.current);
|
|
585
|
+
setCopied(ok ? 'ok' : 'fail');
|
|
586
|
+
resetTimer.current = window.setTimeout(() => setCopied('idle'), 1500);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
const copyButton = (lead: boolean) => (
|
|
590
|
+
<Button
|
|
591
|
+
size={lead ? 'sm' : 'tiny'}
|
|
592
|
+
variant={lead ? 'primary' : 'quiet'}
|
|
593
|
+
onClick={() => void copy()}
|
|
594
|
+
leadingIcon={
|
|
595
|
+
copied === 'ok' ? (
|
|
596
|
+
<Check size={12} aria-hidden className={lead ? undefined : 'text-ok'} />
|
|
597
|
+
) : copied === 'fail' ? (
|
|
598
|
+
<X size={12} aria-hidden className={lead ? undefined : 'text-danger'} />
|
|
599
|
+
) : (
|
|
600
|
+
<Copy size={12} aria-hidden />
|
|
601
|
+
)
|
|
602
|
+
}
|
|
603
|
+
>
|
|
604
|
+
Copy prompt
|
|
605
|
+
</Button>
|
|
606
|
+
);
|
|
607
|
+
const claudeLink = (lead: boolean) => (
|
|
608
|
+
<PromptLink href={claudePromptUrl(prompt)} primary={lead}>
|
|
609
|
+
{lead ? 'Ask Claude to write it' : 'Open in Claude'}
|
|
610
|
+
</PromptLink>
|
|
611
|
+
);
|
|
612
|
+
const chatGptLink = (lead: boolean) => (
|
|
613
|
+
<PromptLink href={chatGptPromptUrl(prompt)} primary={lead}>
|
|
614
|
+
{lead ? 'Ask ChatGPT to write it' : 'Open in ChatGPT'}
|
|
615
|
+
</PromptLink>
|
|
616
|
+
);
|
|
617
|
+
|
|
618
|
+
const lead = primary === 'claude' ? claudeLink(true) : primary === 'chatgpt' ? chatGptLink(true) : copyButton(true);
|
|
619
|
+
const quiet =
|
|
620
|
+
primary === 'claude'
|
|
621
|
+
? [chatGptLink(false), copyButton(false)]
|
|
622
|
+
: primary === 'chatgpt'
|
|
623
|
+
? [claudeLink(false), copyButton(false)]
|
|
624
|
+
: [claudeLink(false), chatGptLink(false)];
|
|
625
|
+
|
|
626
|
+
return (
|
|
627
|
+
<div className="grid justify-items-start gap-1.5">
|
|
628
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
629
|
+
{lead}
|
|
630
|
+
{newPage && (
|
|
631
|
+
<Button size="sm" variant="outline" onClick={newPage.onClick} disabled={newPage.disabled}>
|
|
632
|
+
{newPage.label}
|
|
633
|
+
</Button>
|
|
634
|
+
)}
|
|
635
|
+
</div>
|
|
636
|
+
{primary === 'copy' && (
|
|
637
|
+
<span className="text-meta text-ink-faint">Paste it into {agentName ?? 'your agent'}.</span>
|
|
638
|
+
)}
|
|
639
|
+
<div className="flex items-center gap-1 text-meta">
|
|
640
|
+
{quiet[0]}
|
|
641
|
+
<span aria-hidden className="text-ink-faint">
|
|
642
|
+
·
|
|
643
|
+
</span>
|
|
644
|
+
{quiet[1]}
|
|
645
|
+
<span role="status" aria-live="polite" className="sr-only">
|
|
646
|
+
{copied === 'ok' ? 'Prompt copied' : copied === 'fail' ? 'Couldn’t copy the prompt' : ''}
|
|
647
|
+
</span>
|
|
648
|
+
</div>
|
|
649
|
+
</div>
|
|
650
|
+
);
|
|
651
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Users } from 'lucide-react';
|
|
2
|
+
import { Button, IconButton } from '../../../shared/components';
|
|
3
|
+
import { useAdmin } from '../../admin/state/admin.context';
|
|
4
|
+
import { useInviteDialog } from '../state/invite-dialog.context';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The toolbar's Invite button — admins only, because creating accounts is an
|
|
8
|
+
* admin act and a button that answers "Admins only" is worse than none.
|
|
9
|
+
* Opens the same dialog as the "Get set up" column's invite step.
|
|
10
|
+
*
|
|
11
|
+
* `compact` is the toolbar's narrow layout, where every control shares one
|
|
12
|
+
* row with the essentials: the button sheds its word and keeps the icon, so
|
|
13
|
+
* it cannot push the profile menu off-screen. Its name stays "Invite" either
|
|
14
|
+
* way — the label carries it where the word is gone.
|
|
15
|
+
*
|
|
16
|
+
* Renders nothing outside an invite provider: the toolbar is mounted bare in
|
|
17
|
+
* tests and by hosts, and a button with nothing to open is a dead control.
|
|
18
|
+
*/
|
|
19
|
+
export function InviteButton({ compact = false }: { compact?: boolean }) {
|
|
20
|
+
const { isAdmin } = useAdmin();
|
|
21
|
+
const invite = useInviteDialog();
|
|
22
|
+
if (!isAdmin || !invite) return null;
|
|
23
|
+
if (compact) {
|
|
24
|
+
return (
|
|
25
|
+
<IconButton aria-label="Invite" title="Invite" onClick={invite.open}>
|
|
26
|
+
<Users size={16} aria-hidden />
|
|
27
|
+
</IconButton>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return (
|
|
31
|
+
<Button size="sm" leadingIcon={<Users size={14} aria-hidden />} onClick={invite.open}>
|
|
32
|
+
Invite
|
|
33
|
+
</Button>
|
|
34
|
+
);
|
|
35
|
+
}
|