From c21acf17cef39d95a617b4a7963770cd8a70b4b2 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 07:49:53 +0000 Subject: [PATCH 1/7] feat(app-shell): the assistant entry reads Ask AI, ends the page's button group, and yields its words first Claude-Session: https://claude.ai/code/session_01L9qibwhwiMRQSuaJ1wVVcU Co-authored-by: Claude --- .../app-shell/src/console/home/HomePage.tsx | 10 +- .../app-shell/src/layout/AppHeader.tsx | 12 +- .../src/layout/AssistantTopBarButton.tsx | 167 ++++++++++++++---- .../app-shell/src/layout/ConsoleLayout.tsx | 5 +- .../app-shell/src/layout/PageHeader.tsx | 106 +++++++++-- .../app-shell/src/layout/ShellPageActions.tsx | 66 ++++++- ...ChatDock.titleMatchesTopBar-34827.test.tsx | 29 ++- .../src/layout/shellPageActionsSlot.ts | 6 + ui/packages/i18n/src/locales/ar.ts | 1 + ui/packages/i18n/src/locales/de.ts | 1 + ui/packages/i18n/src/locales/en.ts | 1 + ui/packages/i18n/src/locales/es.ts | 1 + ui/packages/i18n/src/locales/fr.ts | 1 + ui/packages/i18n/src/locales/ja.ts | 1 + ui/packages/i18n/src/locales/ko.ts | 1 + ui/packages/i18n/src/locales/pt-BR.ts | 1 + ui/packages/i18n/src/locales/ru.ts | 1 + ui/packages/i18n/src/locales/zh-Hans.ts | 1 + ui/packages/i18n/src/locales/zh-Hant.ts | 1 + 19 files changed, 342 insertions(+), 70 deletions(-) diff --git a/ui/packages/app-shell/src/console/home/HomePage.tsx b/ui/packages/app-shell/src/console/home/HomePage.tsx index 1f30b198684..6760f624442 100644 --- a/ui/packages/app-shell/src/console/home/HomePage.tsx +++ b/ui/packages/app-shell/src/console/home/HomePage.tsx @@ -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'; @@ -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; diff --git a/ui/packages/app-shell/src/layout/AppHeader.tsx b/ui/packages/app-shell/src/layout/AppHeader.tsx index 59eaa172201..e945760ddac 100644 --- a/ui/packages/app-shell/src/layout/AppHeader.tsx +++ b/ui/packages/app-shell/src/layout/AppHeader.tsx @@ -988,11 +988,6 @@ export function AppHeader({ */} {!phoneTab && } - {/* 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 && } - {/* 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 @@ -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 && } {/* Group 3: Account (theme + lang moved into avatar dropdown) */} diff --git a/ui/packages/app-shell/src/layout/AssistantTopBarButton.tsx b/ui/packages/app-shell/src/layout/AssistantTopBarButton.tsx index a5b3b0df514..a6c81351973 100644 --- a/ui/packages/app-shell/src/layout/AssistantTopBarButton.tsx +++ b/ui/packages/app-shell/src/layout/AssistantTopBarButton.tsx @@ -2,65 +2,168 @@ * ObjectUI * Copyright (c) 2024-present ObjectStack Inc. * - * objectstack#34608 (ui ADR-0057 as amended) — the top-bar robot, the AI - * assistant's ONE standing entry: it opens and closes the right-side drawer - * without leaving the page. The floating bottom-right button it replaces is - * gone; what that button carried moved here: + * objectstack#34608 (ui ADR-0057 as amended) — the AI assistant's ONE standing + * entry: it opens and closes the right-side drawer without leaving the page. + * The floating bottom-right button it replaces is gone; what that button + * carried moved here: * - objectui#11666 — while a proposed plan awaits the user's approval the - * robot carries a marker, so a user who closed the chat still sees the + * entry carries a marker, so a user who closed the chat still sees the * assistant is waiting on them. Read off the assistant bus; only a change * of the plan's state clears it, never opening the chat. * + * objectstack#37858 — the entry is an outlined button that says what it does, + * 「问 AI」 (`topbar.askAi`), beside a chat-bubble icon, on every page: the + * page header's button group, the record page's navigation row, the phone's + * top bar, Home's bar, and the corner button of a route with no shell header. + * The words are the platform's: no app renames them. Two faces: + * - with its text, the text is the accessible name (no `aria-label`); + * - icon only — a phone (a 44 px target), or a header that ran out of room + * and asked for it (`iconOnly`) — `aria-label` carries the same words. + * The tooltip names the ⌘⇧I shortcut on a Mac only: on other platforms + * Ctrl+Shift+I opens the browser's developer tools first, so no shortcut is + * advertised there and `aria-keyshortcuts` is not set. + * * Under a layout with no drawer it is a link to the pre-drawer address, which * the console routes back into the drawer. */ import * as React from 'react'; import { Link } from 'react-router-dom'; -import { Bot } from 'lucide-react'; -import { Button, cn } from '@object-ui/components'; +import { MessageCircle } from 'lucide-react'; +import { Button, Kbd, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, cn } from '@object-ui/components'; import { useObjectTranslation } from '@object-ui/i18n'; import { usePlanApprovalPending } from '../assistant/assistantBus.js'; -import { useChatDockControl } from './chatDockControl.js'; +import { useChatDockControl, useOpenAssistant } from './chatDockControl.js'; +import type { ChatDockTarget } from './chatDockTarget.js'; +import { usePhoneViewport } from '../hooks/usePhoneViewport.js'; + +/** The drawer's shortcut in `aria-keyshortcuts` syntax; advertised on a Mac only. */ +export const ASK_AI_MAC_KEY_SHORTCUTS = 'Meta+Shift+I'; +/** The same shortcut as the tooltip's keycaps. */ +const ASK_AI_MAC_KEYCAPS = ['⌘', '⇧', 'I'] as const; + +/** Whether this browser runs on a Mac, where ⌘⇧I is free for the drawer. */ +export function isMacPlatform(): boolean { + if (typeof navigator === 'undefined') return false; + const platform = + (navigator as Navigator & { userAgentData?: { platform?: string } }).userAgentData?.platform ?? + navigator.platform ?? + ''; + return /mac/i.test(platform); +} + +/** + * The 「问 AI」 entry's opening half, shared by every button that asks the + * assistant from a page — this one when the drawer is closed, and Home's + * 「Ask AI」 — so what opening means is decided in one place. Absent a target + * it opens the drawer on whatever it shows now, exactly as the drawer's own + * toggle does (a handoff it still holds is kept); with one, on that target. + * Under no drawer host it goes to the pre-drawer address. + */ +export function useAskAiEntry(): (target?: ChatDockTarget) => void { + const control = useChatDockControl(); + const openAssistant = useOpenAssistant(); + return React.useCallback( + (target?: ChatDockTarget) => { + if (control && target === undefined) { + if (!control.expanded) control.toggle(); + return; + } + openAssistant(target); + }, + [control, openAssistant], + ); +} -export function AssistantTopBarButton({ className }: { className?: string }) { +export interface AssistantTopBarButtonProps { + className?: string; + /** + * Draw the icon alone, named by `aria-label`: the header placing the button + * measured that its own content no longer fits beside the words. A phone + * draws the icon alone whatever this says. + */ + iconOnly?: boolean; +} + +export function AssistantTopBarButton({ className, iconOnly = false }: AssistantTopBarButtonProps) { const { t } = useObjectTranslation(); const control = useChatDockControl(); + const askAi = useAskAiEntry(); const planPending = usePlanApprovalPending(); + const phone = usePhoneViewport(); + const mac = React.useMemo(isMacPlatform, []); const markerId = React.useId(); - const label = t('topbar.aiAssistant', { defaultValue: 'AI Assistant' }); + const label = t('topbar.askAi', { defaultValue: 'Ask AI' }); + const iconAlone = iconOnly || phone; + // `aria-hidden` keeps the marker's words out of the name a text face takes + // from its content; the button still reads them as its description, which + // names the marker by id. const marker = planPending ? ( - -