Skip to content
Merged
19 changes: 19 additions & 0 deletions .changeset/37858-ask-ai-entry-button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@object-ui/app-shell': patch
'@object-ui/plugin-report': patch
---

feat(app-shell): the assistant's entry is an outlined 「Ask AI」 button at the end of every page's top-right group, and a route with no page header gets it in its corner

Clause-②: no
Metadata-protocol: none

The assistant's one standing entry was a 32 px transparent robot icon named only by its tooltip. It is now an outlined button with a chat-bubble icon and the words 「Ask AI」 (「问 AI」 in Chinese), read from the string Home's own 「Ask AI」 button already carries in every built-in pack (`home.askAI`), so no language pack changes. The words are the platform's; no app renames them.

- **Where it sits.** Last in the page's top-right button group (comments, help, Ask AI), so it ends the page header's row and the record page's navigation row; after help on Home's bar and in the phone's top bar. A route whose page draws no button group (search results, a component page, the app editor) gets the same button over the empty top end corner of its content (top-right; top-left in a right-to-left language), and loses it as soon as its page draws a group. A page that keeps its own controls in that corner draws the group in its own top bar instead, so the button never covers them: the report builder (a new report, and a report's Edit) ends its header with Discard, Save, help, Ask AI, and the inbox ends its header row with its own buttons, help, Ask AI.
- **When the header runs out of room.** The console page header now measures whether its title (and, on a page that offers the folded actions, its description) still fits beside the words; when it does not, the words are hidden first and the icon stays, before the page's own actions fold and before the title is cut. They come back once there is room again, after any fold has opened. The decision reads the header's own width, never a breakpoint, so a longer translation hides its words sooner.
- **Phone.** The icon alone, a 44 px target.
- **Accessibility.** With its words shown the words are the button's accessible name; with the icon alone `aria-label` carries the same words. On a Mac the tooltip shows ⌘⇧I and the button declares `aria-keyshortcuts="Meta+Shift+I"`; on other platforms, where Ctrl+Shift+I opens the browser's developer tools, no shortcut is shown or declared.
- **Home.** Home's 「Ask AI」 opens the drawer through the same entry hook as the page's button (`useAskAiEntry`), still on the ask agent.

`useShellPageActionsSlot()`'s render function takes one more optional prop, `assistantIconOnly`, which a header that measures its own width passes; a header that passes nothing gets the button with its words, as before. `ReportBuilder` (`@object-ui/plugin-report`) takes an optional `headerEnd`, drawn after Save at the end of its header; without it the header ends with Save, as before. The drawer keeps its title for now.
10 changes: 6 additions & 4 deletions ui/packages/app-shell/src/console/home/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import { fetchPackages } from '../../views/studio-design/packages-io.js';
import { resolveAiApiBase } from '../../hooks/useAiSurface.js';
import { isAiStudioEnabled, isMarketplaceEnabled } from '../../runtime-config.js';
import { useNewPackageDoorPath } from '../../hooks/useNewPackageDoorPath.js';
import { useOpenAssistant } from '../../layout/chatDockControl.js';
import { useAskAiEntry } from '../../layout/AssistantTopBarButton.js';
import { isProductApp } from '../../utils/homePath.js';
import { useAddAppEntries, useMayAddApp } from '../../hooks/useAddAppEntries.js';
import { catalogServesBuild } from '../../hooks/surfaceAgent.js';
Expand Down Expand Up @@ -454,9 +454,11 @@ export { readRecentObjects, type RecentObjectReading };
export function HomePage({ checklist }: HomePageProps = {}) {
const navigate = useNavigate();
// objectstack#34608 — the Home AI buttons open the same right-side drawer
// every console page has (in place, no navigation).
const openAssistant = useOpenAssistant();
const openHomeAssistant = (agent: 'ask') => openAssistant({ agent });
// every console page has (in place, no navigation). objectstack#37858 —
// through the Ask AI entry the top bar's button opens it with, so the two
// change together when opening comes to mean a new conversation.
const askAi = useAskAiEntry();
const openHomeAssistant = (agent: 'ask') => askAi({ agent });
const { t, language } = useObjectTranslation();
const metadata = useMetadata();
const { apps, loading } = metadata;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* objectstack#37858 — Home's 「Ask AI」 opens the assistant through the same
* entry as the page's Ask AI button (`useAskAiEntry`), so when opening comes
* to mean "a new conversation" the two change together. Today it still asks
* the `ask` agent, as it did.
*
* Real subject: `HomePage`, with the stand-ins of
* `HomePage.phoneTapTargets-29147.test.tsx` (the catalog moves the way the
* real `useAgents` does); the entry is observed, not run.
*/

import '@testing-library/jest-dom/vitest';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import React from 'react';
import { render, screen, cleanup, fireEvent } from '@testing-library/react';

const navigateMock = vi.fn();

const state = vi.hoisted(() => ({
apps: [] as Array<Record<string, unknown>>,
/** The catalog's answer, once it has answered. */
agents: [] as Array<{ name: string }>,
askAgent: false,
buildAgent: false,
/** Set once the stand-in has drawn the catalog's answer (objectstack#37227). */
answered: false,
}));

vi.mock('react-router-dom', async () => {
const { createElement } = await import('react');
return {
useNavigate: () => navigateMock,
Link: ({ to, ...rest }: { to: string } & Record<string, unknown>) =>
createElement('a', { ...rest, href: to }),
};
});

vi.mock('@object-ui/i18n', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useObjectTranslation: () => ({ t: (key: string) => `«${key}»`, language: 'en' }),
useObjectLabel: () => {
const label = (x: { name?: string; label?: string }) => String(x?.label || x?.name || '');
return {
appLabel: label,
objectLabel: label,
objectPluralLabel: label,
dashboardLabel: label,
pageLabel: label,
reportLabel: label,
viewLabel: (_object: string, _view: string, fallback?: string) => fallback ?? '',
};
},
}));

vi.mock('@object-ui/auth', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useAuth: () => ({ user: { id: 'u1', name: 'Dev Admin', email: 'dev.admin@example.com' } }),
useWorkspaceAdminStatus: () => ({ isAdmin: true, isResolved: true }),
}));

// The catalog moves the way the real `useAgents` does: an empty first frame,
// then loading, then the answer.
vi.mock('@object-ui/plugin-chatbot/core', async (importOriginal) => {
const { useEffect, useState } = await import('react');
return {
...(await importOriginal<typeof import('@object-ui/plugin-chatbot/core')>()),
useAgents: () => {
const [phase, setPhase] = useState<'idle' | 'loading' | 'answered'>('idle');
useEffect(() => {
if (phase === 'idle') setPhase('loading');
else if (phase === 'loading') setPhase('answered');
}, [phase]);
if (phase === 'answered') state.answered = true;
return { agents: phase === 'answered' ? state.agents : [], isLoading: phase === 'loading' };
},
isAskAgent: () => state.askAgent,
agentHasCapability: () => state.buildAgent,
};
});

vi.mock('../../../providers/MetadataProvider', () => ({
useMetadata: () => ({ apps: state.apps, objects: [], dashboards: [], pages: [], reports: [], loading: false }),
}));
vi.mock('../../../context/NavigationContext', () => ({
useNavigationContext: () => ({ currentAppName: 'crm' }),
}));
vi.mock('../../../hooks/useCanAuthorMetadata', () => ({
useCanAuthorMetadata: () => true,
useCanReadPendingDrafts: () => true,
}));
vi.mock('../../../runtime-config', () => ({
getRuntimeConfig: () => ({ branding: { productName: 'ObjectStack' } }),
isMarketplaceEnabled: () => true,
isAiStudioEnabled: () => true,
}));

const now = new Date().toISOString();
vi.mock('../../../hooks/useHomeInbox', () => ({
useHomeInbox: () => ({
pendingApprovals: [{ id: 'apr_1', processLabel: 'Discount approval', recordTitle: 'QUO-0007', createdAt: now }],
pendingApprovalsCount: 1,
pendingApprovalsStatus: 'ready',
pendingApprovalsReadable: true,
notifications: [{ id: 'n1', title: 'Lead assigned', createdAt: now }],
unreadTopicCount: 1,
notificationsStatus: 'ready',
notificationsReadable: true,
activity: {
value: [{ id: 'a1', user: 'Ada', description: 'updated a lead', timestamp: now, objectName: 'crm_lead' }],
status: 'ready',
readable: true,
},
}),
}));
vi.mock('../../../hooks/useRecentItems', () => ({
useRecentItems: () => ({
recentItems: [{ id: 'object:crm_lead', type: 'object', name: 'crm_lead', href: '/apps/crm/crm_lead', visitedAt: now }],
}),
}));
vi.mock('../../../hooks/useFavorites', () => ({ useFavorites: () => ({ favorites: [] }) }));
vi.mock('../../../hooks/useAiSurface', () => ({ resolveAiApiBase: () => '' }));
vi.mock('../../../preview/usePendingDrafts', () => ({
usePendingDrafts: () => ({ count: 1, entries: [{ name: 'crm_lead', label: 'Lead' }] }),
}));
vi.mock('../../../preview/usePublishAllDrafts', () => ({
usePublishAllDrafts: () => ({ publishAll: async () => ({ ok: true }), publishing: false }),
}));
vi.mock('../../../hooks/useInboxBell', () => ({ useInboxBell: () => ({ markRead: vi.fn() }) }));
vi.mock('../../../layout/ActivityObjectLabel', () => ({ ActivityObjectLabel: () => null }));

// objectstack#37858 — the entry the top bar's Ask AI button opens the drawer
// through, observed: Home's button must reach the drawer by the same door.
const askAiEntry = vi.hoisted(() => ({ calls: [] as unknown[] }));
vi.mock('../../../layout/AssistantTopBarButton', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useAskAiEntry: () => (target?: unknown) => {
askAiEntry.calls.push(target);
},
}));

// The deployment notice reads its own state from the server for an administrator
// (objectstack#30120); its fetch, its gate and its copy are pinned in
// `deployment-notice/__tests__/DeploymentNotice.test.tsx`, so it is stubbed here
// like every other source this page reads.
vi.mock('../../deployment-notice/DeploymentNotice', () => ({ DeploymentNotice: () => null }));

// The page reaches `capabilityLint`'s dynamic `@objectstack/lint` import; its
// first load is paid here, at collection, never inside a case's clock
// (`check:test-source-alias`).
import '@objectstack/lint';
import { HomePage } from '../HomePage';

beforeEach(() => {
navigateMock.mockReset();
askAiEntry.calls = [];
state.apps = [{ name: 'crm', label: 'CRM', icon: 'Box' }];
state.agents = [{ name: 'ask' }];
state.askAgent = true;
state.buildAgent = false;
state.answered = false;
});

afterEach(() => {
cleanup();
});

describe("Home's Ask AI opens the assistant's one entry (objectstack#37858)", () => {
it('a click goes through the entry, on the ask agent, and navigates nowhere', async () => {
render(<HomePage />);
fireEvent.click(await screen.findByTestId('home-ask-ai'));
expect(askAiEntry.calls).toEqual([{ agent: 'ask' }]);
expect(navigateMock).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,9 @@ function MarketplacePackagePageBody() {
if (error || !data) {
return (
<div className="mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6">
<Button variant="ghost" size="sm" onClick={() => navigate(`${basePath}/system/marketplace`)}>
{/* Sized to its words, as on the loaded page: stretched across the
row it would run under the shell's corner Ask AI button. */}
<Button variant="ghost" size="sm" className="self-start -ml-2 text-muted-foreground hover:text-foreground" onClick={() => navigate(`${basePath}/system/marketplace`)}>
<ArrowLeft className="h-4 w-4 mr-1.5" aria-hidden="true" />
{t('marketplace.back')}
</Button>
Expand Down
12 changes: 7 additions & 5 deletions ui/packages/app-shell/src/layout/AppHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -988,11 +988,6 @@ export function AppHeader({
*/}
{!phoneTab && <InboxBell activities={activities} />}

{/* AI Assistant — only when the runtime serves AI (hidden on
Community Edition so it can't dead-end on an agent-less chat).
objectstack#34608: it opens and closes the drawer in place. */}
{aiEnabled && <AssistantTopBarButton />}

{/* Help & Documentation — the shared 「?」 menu (objectstack#36111:
the page's button group draws the same component). The
left-sidebar already links the hub, so this entry point earns
Expand All @@ -1002,6 +997,13 @@ export function AppHeader({
appPackageId={currentAppPackageId}
triggerClassName="h-8 w-8 hidden md:flex shrink-0"
/>

{/* Ask AI — only when the runtime serves AI (hidden on Community
Edition so it can't dead-end on an agent-less chat).
objectstack#34608: it opens and closes the drawer in place.
objectstack#37858: after help, as in the page's button group;
with its words on Home's bar, its icon alone (44 px) on a phone. */}
{aiEnabled && <AssistantTopBarButton className="md:ml-1" />}
</div>

{/* Group 3: Account (theme + lang moved into avatar dropdown) */}
Expand Down
Loading
Loading