Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions apps/app/src/components/commands/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ import {
} from "@/lib/command-palette/palette-recents";
import {
buildPluginComposerCommandActions,
buildPluginPaletteActions,
buildFocusedSurfacePaletteActions,
} from "@/lib/command-palette/palette-plugin-actions";
import { usePluginSlotKind } from "@/lib/plugin-slots";
import { getFocusedAppPanelController } from "@/lib/app-fixed-tab-navigation";
import { pluginListQueryOptions } from "@/hooks/queries/plugin-settings-queries";
import type { PluginSettingsCandidate } from "@/components/settings/plugin-settings-entries";
import { appQueryClient } from "@/lib/app-query-client";
Expand Down Expand Up @@ -112,11 +111,10 @@ export function CommandPalette({ threadId, projectId }: CommandPaletteProps) {
useIndexedAppCommandHandlers(appPluginCommandIds, (index) => {
const slot = appPluginCommands[index];
if (!slot) return false;
const action = buildPluginPaletteActions({
const action = buildFocusedSurfacePaletteActions({
slots: [slot],
threadId,
projectId,
panel: getFocusedAppPanelController(),
})[0];
if (!action) return false;
action.run();
Expand All @@ -134,11 +132,10 @@ export function CommandPalette({ threadId, projectId }: CommandPaletteProps) {
shortcuts,
}),
...[
...buildPluginPaletteActions({
...buildFocusedSurfacePaletteActions({
slots: appPluginCommands,
threadId,
projectId,
panel: getFocusedAppPanelController(),
}),
...buildPluginComposerCommandActions({
slots: composerPluginCommands,
Expand Down
11 changes: 3 additions & 8 deletions apps/app/src/components/plugin/PluginMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type {
import { getEnvironmentFilePreviewSourceAtRef } from "@bb/client-core";
import { normalizeAbsoluteFilePath } from "@bb/shared-ui/lib/absolute-file-path";
import {
AUTHORED_MARKDOWN_THREAD_MENTIONS,
MarkdownPreview,
type MarkdownThreadMentions,
} from "@/components/ui/markdown-preview";
import { buildMarkdownFileRouting } from "@/components/ui/markdown-file-routing";
import { WithoutCodeFenceRenderers } from "@/components/ui/markdown-code-fence-renderers";
Expand All @@ -30,11 +30,6 @@ import { normalizeExperimentalLiveFileTarget } from "@/lib/live-file-navigation"
import { useLocalFileLinkOpener } from "@/hooks/useLocalFileLinkOpener";
import { useResolvedLiveFileRoot } from "@/hooks/useResolvedLiveFileTarget";

const PLUGIN_MARKDOWN_THREAD_MENTIONS: MarkdownThreadMentions = {
mentions: [],
preserveSoftBreaks: false,
};

function parsePluginMarkdownDocument(
document: NonNullable<MarkdownProps["experimental_document"]>,
) {
Expand Down Expand Up @@ -124,7 +119,7 @@ function PluginDocumentMarkdown({
className={className}
linkRouting={linkRouting}
messageDirectives={messageDirectives}
threadMentions={PLUGIN_MARKDOWN_THREAD_MENTIONS}
threadMentions={AUTHORED_MARKDOWN_THREAD_MENTIONS}
/>
);
}
Expand Down Expand Up @@ -162,7 +157,7 @@ function PluginMarkdownBody({
className={className}
linkRouting={document === null ? {} : messageRouting}
messageDirectives={messageDirectives}
threadMentions={PLUGIN_MARKDOWN_THREAD_MENTIONS}
threadMentions={AUTHORED_MARKDOWN_THREAD_MENTIONS}
/>
);
}
Expand Down
50 changes: 48 additions & 2 deletions apps/app/src/components/plugin/PluginNewThreadComposer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import {
useEffect,
useLayoutEffect,
useState,
useSyncExternalStore,
type ReactNode,
Expand Down Expand Up @@ -53,7 +54,10 @@ import {
setPluginSlotRegistrations,
} from "@/lib/plugin-slots";
import { encodeReuseValue } from "@/components/pickers/environment-picker-value";
import { useRootComposeReuseEnvironment } from "@/lib/root-compose-selection";
import {
useRootComposeReuseEnvironment,
useSetRootComposeProjectId,
} from "@/lib/root-compose-selection";
import { getPromptDraftAccessor } from "@/hooks/usePromptDraftStorage";
import { makeThreadListEntry } from "@bb/test-helpers/domain-fixtures";
import { createDeferredPromise } from "@bb/test-helpers";
Expand All @@ -71,7 +75,7 @@ import {
serializeFixedPanelTabsState,
} from "@/lib/fixed-panel-tabs-state";
import { buildPluginPaletteActions } from "@/lib/command-palette/palette-plugin-actions";
import { getFocusedAppPanelController } from "@/lib/app-fixed-tab-navigation";
import { getFocusedAppPanelController } from "@/lib/app-navigation-host";
import { useFixedPanelTabsState } from "@/lib/fixed-panel-tabs";
import { openPluginDetailsInWorkspace } from "./plugin-detail-opener";
import { PluginNewThreadComposer } from "./PluginNewThreadComposer";
Expand Down Expand Up @@ -1542,6 +1546,48 @@ describe("PluginNewThreadComposer seeding", () => {
});
});

it("starts an unseeded composer on the remembered New thread project, as bb's New thread does", async () => {
function PickInNewThread() {
const setRootComposeProjectId = useSetRootComposeProjectId();
useLayoutEffect(() => setRootComposeProjectId("proj_1"));
return null;
}
const submitted: NewThreadRequest[] = [];
const composer = (
<PluginNewThreadComposer
draftKey="unseeded-project"
initialPrompt="hello"
onSubmit={(request) => {
submitted.push(request);
}}
/>
);
const view = render(
<Provider>
<MemoryRouter>
<PickInNewThread />
</MemoryRouter>
</Provider>,
);
view.rerender(
<Provider>
<MemoryRouter>
<PickInNewThread />
{composer}
</MemoryRouter>
</Provider>,
);

await waitFor(() => {
expect(latestPromptBoxProps().project.value).toBe("proj_1");
expect(latestPromptBoxProps().disabled).toBe(false);
});
await submit();

expect(submitted).toHaveLength(1);
expect(submitted[0]?.projectId).toBe("proj_1");
});

it("keeps project defaults when no seed props are passed", async () => {
const submitted: NewThreadRequest[] = [];
render(
Expand Down
8 changes: 5 additions & 3 deletions apps/app/src/components/plugin/PluginNewThreadComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "@/components/promptbox/NewThreadComposer";
import { PluginContext } from "@/components/plugin/plugin-context";
import { useQuickCreateProjectController } from "@/hooks/useQuickCreateProject";
import { useRootComposeProjectId } from "@/lib/root-compose-selection";

export function PluginNewThreadComposer({
defaultProjectId,
Expand All @@ -29,14 +30,15 @@ export function PluginNewThreadComposer({
}: PluginComposerProps) {
const pluginId = useContext(PluginContext);
const quickCreateProject = useQuickCreateProjectController();
const [pickedProjectId, setPickedProjectId] = useState<string | null>(
defaultProjectId ?? null,
const [rememberedProjectId] = useRootComposeProjectId();
const [pickedProjectId, setPickedProjectId] = useState<string>(
defaultProjectId ?? rememberedProjectId,
);
const [seededDefaultProjectId, setSeededDefaultProjectId] =
useState(defaultProjectId);
if (seededDefaultProjectId !== defaultProjectId) {
setSeededDefaultProjectId(defaultProjectId);
setPickedProjectId(defaultProjectId ?? null);
setPickedProjectId(defaultProjectId ?? rememberedProjectId);
}

const seed: NewThreadComposerSeed = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
collectPluginAppRegistrations,
definePluginApp,
} from "@/lib/plugin-app-definition";
import { resetFocusedAppPanelControllersForTest } from "@/lib/app-fixed-tab-navigation";
import { resetFocusedAppNavigationSurfacesForTest } from "@/lib/app-navigation-host";
import { RouteNavigationProvider } from "@/components/ui/app-route-anchor";
import {
CONTRACT_PLUGIN_ID,
Expand All @@ -29,12 +29,14 @@ import {
contractActionPanelTabId,
contractTarget,
describePanelControllerContract,
readContractNavigate,
readContractPanel,
readContractTabs,
snapshotFromState,
type ContractPanelRef,
type ContractStateSink,
} from "@/test/panel-controller-contract";
import { makeTerminalSession } from "@/test/fixtures/terminal-sessions";
import { PluginContext } from "./plugin-context";
import { getPluginPagePanelStateId } from "./plugin-page-panel-state";
import { PluginPanelRightPanelHost } from "./PluginPanelRightPanelHost";
Expand Down Expand Up @@ -64,9 +66,10 @@ vi.mock("@/hooks/queries/host-queries", () => ({
vi.mock("@/hooks/queries/system-queries", () => ({
useSystemConfig: () => ({ data: { primaryHostId: null } }),
}));
vi.mock("@/lib/bb-desktop", () => ({
vi.mock("@/lib/bb-desktop", async (importOriginal) => ({
...(await importOriginal<typeof import("@/lib/bb-desktop")>()),
getDesktopBrowserApi: () => null,
isDesktopBrowserAvailable: () => false,
isDesktopBrowserAvailable: () => true,
}));
vi.mock("react-resizable-panels", async (importOriginal) => ({
...(await importOriginal<typeof import("react-resizable-panels")>()),
Expand Down Expand Up @@ -169,12 +172,12 @@ beforeEach(() => {
afterEach(() => {
cleanup();
removePluginSlotRegistrations(CONTRACT_PLUGIN_ID);
resetFocusedAppPanelControllersForTest();
resetFocusedAppNavigationSurfacesForTest();
});

describePanelControllerContract(
"plugin nav-panel page",
{ fixedTabs: true },
{ fixedTabs: true, actionTabs: true, navigation: true },
async () => {
const probe: ContractPanelRef = { current: null };
const sink: ContractStateSink = { current: null };
Expand Down Expand Up @@ -217,6 +220,22 @@ describePanelControllerContract(
);
return {
panel: () => readContractPanel(probe),
navigation: {
navigate: () => readContractNavigate(probe),
open: {
terminal: makeTerminalSession({
id: "term_contract",
threadId: null,
environmentId: null,
hostId: "host_contract",
}),
file: {
target: { kind: "host", hostId: "host_contract", path: "/a.md" },
location: null,
},
url: "https://example.com/contract",
},
},
snapshot: () => snapshotFromState(sink),
tabs: () => readContractTabs(probe),
renderedTabVisible: () =>
Expand Down
19 changes: 15 additions & 4 deletions apps/app/src/components/plugin/PluginPanelRightPanelHost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ import {
} from "@/lib/bb-desktop";
import { useIsSidebarFramed } from "@/components/ui/sidebar.js";
import { UrlOpenRoutingProvider } from "@/lib/url-open-routing";
import type { MarkdownPreviewLinkHandler } from "@/components/ui/markdown-link";
import { usePluginSlotKind } from "@/lib/plugin-slots";
import { AppNavigationHostProvider } from "@/lib/app-navigation-host";
import { AppNavigationSurfaceProvider } from "@/lib/app-navigation-host";
import {
FixedTabTargetScope,
getPluginFixedTabOwnerId,
Expand Down Expand Up @@ -471,7 +472,6 @@ export function PluginPanelRightPanelHost({
activeTabId: isOpen ? (activeTab?.id ?? null) : null,
close: hidePanel,
destinations: panelDestinations,
isFocused: isFocused && panel !== null,
});
const pluginActions = useMemo(
() =>
Expand Down Expand Up @@ -574,6 +574,11 @@ export function PluginPanelRightPanelHost({
reveal: revealPanel,
});
const openBrowser = panelBrowser.open;
const openBrowserUrl = panelBrowser.openUrl;
const handleOpenPanelLink = useCallback<MarkdownPreviewLinkHandler>(
({ href }) => openBrowserUrl(href),
[openBrowserUrl],
);

const fixedTabs = useMemo<readonly SecondaryPanelFixedTab[]>(
() =>
Expand Down Expand Up @@ -649,7 +654,9 @@ export function PluginPanelRightPanelHost({
isPanelPersistedOpen={panelState.secondary.isOpen}
onAutoFocusHandled={terminals.handleAutoFocusHandled}
onCloseStart={() => terminals.close(tab.terminalId)}
onOpenLink={handleOpenPanelLink}
onRetryStart={() => terminals.retryStart(tab.terminalId)}
onSelectionAddToChat={null}
target={tab.target}
terminalId={tab.terminalId}
/>
Expand Down Expand Up @@ -724,6 +731,7 @@ export function PluginPanelRightPanelHost({
},
[
activateTab,
handleOpenPanelLink,
pluginActions,
panel,
panelPath,
Expand Down Expand Up @@ -948,7 +956,10 @@ export function PluginPanelRightPanelHost({

return (
<UrlOpenRoutingProvider openInAppBrowser={openBrowser}>
<AppNavigationHostProvider capabilities={navigationCapabilities}>
<AppNavigationSurfaceProvider
capabilities={navigationCapabilities}
isFocused={isFocused && panel !== null}
>
<AppPanelTabsPublisher
publish={panelController.publishTabs}
activeTabId={activeTab?.id ?? null}
Expand All @@ -963,7 +974,7 @@ export function PluginPanelRightPanelHost({
{registeredTabs.observers}
{routedPage}
</PluginDetailRouteNavigationProvider>
</AppNavigationHostProvider>
</AppNavigationSurfaceProvider>
</UrlOpenRoutingProvider>
);
}
1 change: 0 additions & 1 deletion apps/app/src/components/plugin/PluginThreadChat.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ describe("PluginThreadChat", () => {
unknown
>;
expect(timelineHost.leadingContent).toBeTruthy();
expect(timelineHost.includePluginMessageActions).toBe(false);
const actions = timelineHost.consumerMessageActions as Array<
Record<string, unknown>
>;
Expand Down
Loading
Loading