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
18 changes: 18 additions & 0 deletions .changeset/37862-empty-conversation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@object-ui/app-shell': patch
'@object-ui/plugin-chatbot': patch
'@object-ui/i18n': patch
---

feat(app-shell): one empty-conversation layout for the AI home, the full-window drawer and the narrow drawer

Clause-②: yes (widening) — `@object-ui/plugin-chatbot` `ChatbotEnhancedProps` gains the optional `renderEmptyState`; `@object-ui/i18n` gains `console.ai.suggestionsLabel` and `console.ai.suggestions.page.*` (eight keys) in every locale
Metadata-protocol: none

A conversation with no message now shows the same layout in all three places: a greeting, a line on what to ask, suggested questions and the recent conversations with their titles.

- **The AI home page** (an app's `ai:chat` entry) keeps its large question box, its suggestions that send and its recent conversations that open on the page. Its heading is the entry's declared `title`; with none it now greets the user by the time of day and name, as Home does, where it read "Ask your data".
- **The console's assistant drawer** draws the layout before the first message: large when the drawer fills the window, compact in the side rail and the phone sheet. The composer stays where it is, under the conversation. The `ask` assistant's suggestions follow the page in view: on a record, "Summarize this record" and "What is related to this record?" put their text in the composer for the user to finish; on a list, a dashboard or a report, the page's two questions send at once. Elsewhere, and for other assistants, the starter questions are the ones they had. The recent conversations list the drawer assistant's last three (five in the full window), not the AI home's own, and open in the drawer.
- **`@object-ui/plugin-chatbot`.** `ChatbotEnhanced` takes `renderEmptyState`: a host's empty conversation drawn in place of the built-in one, given `send` (sends a text) and `fill` (puts it in the composer, focused, sending nothing).

Nothing to migrate.
170 changes: 68 additions & 102 deletions ui/packages/app-shell/src/console/ai/AppAskPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
* (`recentAskPageConversations`). A drawer thread is never one of them. Opening one
* writes its `?c=`, so it is restored the way a reload restores it.
*
* The home state is the shared empty conversation (`EmptyConversation`,
* objectstack#37862), large, with this page's own question box in its
* composer slot: the drawer draws the same layout. Its heading is the entry's
* declared title, else the time-of-day greeting; the entry's suggestions send.
*
* The page is the one ask conversation on its screen: while it is the active
* route the console's drawer stays closed and its triggers are hidden or inert
* (`useConsoleChatDock`'s `askPageActive`). A build hand-off from here still
Expand All @@ -34,10 +39,10 @@

import * as React from 'react';
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
import { ArrowUp, MessageSquare, Plus, Sparkles } from 'lucide-react';
import { ArrowUp, Plus, Sparkles } from 'lucide-react';
import { useAuth } from '@object-ui/auth';
import { Badge, Button, Textarea, cn } from '@object-ui/components';
import { useDisplayLocale, useObjectTranslation } from '@object-ui/i18n';
import { Badge, Button, Textarea } from '@object-ui/components';
import { useObjectTranslation } from '@object-ui/i18n';
import { resolveNavItemLabel } from '@object-ui/layout';
import type { NavigationItem } from '@object-ui/types';
import { resolveAgentParam, useAgents } from '@object-ui/plugin-chatbot/core';
Expand All @@ -58,7 +63,8 @@ import { useChatConversation, type HydratedUIMessage } from '../../hooks/useChat
import { fetchConversation } from '../../hooks/useChatConversation.js';
import { useAiSurfaceEnabled } from '../../hooks/useAiSurface.js';
import { useConversationList } from '../../hooks/useConversationList.js';
import { timeAgo } from '../../utils/relativeTime.js';
import { EmptyConversation, EmptyConversationGreeting, RecentConversationList } from './EmptyConversation.js';
import { appHomeSuggestions } from './emptyConversationModel.js';
import { useHomePath } from '../../hooks/useHomePath.js';
import { useMetadata } from '../../providers/MetadataProvider.js';
import { useNavigationContext } from '../../context/NavigationContext.js';
Expand Down Expand Up @@ -90,6 +96,8 @@ export function AppAskPage() {
const entry = React.useMemo(() => findAiChatNavEntry(app), [app]);
const copy = React.useMemo(() => readAiChatPageCopy(entry), [entry]);
const pageLabel = entry ? resolveNavItemLabel(entry as unknown as NavigationItem, t, undefined, language) : '';
// The page header's name when the entry has no label: the declared title,
// else the neutral one. The home state's heading greets instead (below).
const title = copy.title ?? t('console.ai.empty.ask.title', { defaultValue: 'Ask your data' });
const subtitle = copy.subtitle ?? t('console.ai.empty.ask.description', {
defaultValue:
Expand Down Expand Up @@ -272,7 +280,7 @@ export function AppAskPage() {
} else {
body = (
<AskHome
title={title}
heading={copy.title ?? <EmptyConversationGreeting />}
subtitle={subtitle}
placeholder={placeholder}
suggestions={copy.suggestions}
Expand Down Expand Up @@ -311,7 +319,7 @@ export function AppAskPage() {
function noop() {}

interface AskHomeProps {
title: string;
heading: React.ReactNode;
subtitle: string;
placeholder: string;
suggestions: string[];
Expand All @@ -322,77 +330,65 @@ interface AskHomeProps {
recent?: React.ReactNode;
}

/** The home state: the welcome, the large question box and the suggested questions. */
function AskHome({ title, subtitle, placeholder, suggestions, scopeLabel, sendLabel, onAsk, recent }: AskHomeProps) {
/**
* The home state: the shared empty conversation, large, with this page's
* question box in its composer slot. The entry's suggestions send.
*/
function AskHome({ heading, subtitle, placeholder, suggestions, scopeLabel, sendLabel, onAsk, recent }: AskHomeProps) {
const [text, setText] = React.useState('');
const submit = () => {
if (text.trim()) onAsk(text);
};
const homeSuggestions = React.useMemo(() => appHomeSuggestions(suggestions), [suggestions]);
return (
<div className="flex flex-1 flex-col items-center overflow-y-auto px-4 py-10 sm:py-16" data-testid="app-ask-home">
<div className="flex w-full max-w-2xl flex-col items-center gap-6">
<div className="flex flex-col items-center gap-2 text-center">
<h1 className="text-2xl font-semibold tracking-tight sm:text-3xl" data-testid="app-ask-title">
{title}
</h1>
<p className="max-w-xl text-sm text-muted-foreground sm:text-base" data-testid="app-ask-subtitle">
{subtitle}
</p>
</div>
<form
className="w-full rounded-2xl border bg-background p-3 shadow-sm focus-within:ring-2 focus-within:ring-ring"
onSubmit={(event) => {
event.preventDefault();
submit();
}}
>
<Textarea
value={text}
onChange={(event) => setText(event.target.value)}
onKeyDown={(event) => {
if (event.key !== 'Enter' || event.shiftKey || event.nativeEvent.isComposing) return;
<div className="flex flex-1 flex-col items-center overflow-y-auto" data-testid="app-ask-home">
<EmptyConversation
size="large"
heading={heading}
subtitle={subtitle}
suggestions={homeSuggestions}
onSuggestion={(suggestion) => onAsk(suggestion.text)}
recent={recent}
composer={
<form
className="w-full rounded-2xl border bg-background p-3 shadow-sm focus-within:ring-2 focus-within:ring-ring"
onSubmit={(event) => {
event.preventDefault();
submit();
}}
placeholder={placeholder}
aria-label={placeholder}
rows={3}
className="min-h-24 resize-none border-0 bg-transparent p-1 text-base shadow-none focus-visible:ring-0"
data-testid="app-ask-input"
/>
<div className="mt-2 flex items-center justify-between gap-2">
<Badge variant="secondary" className="font-normal" data-testid="app-ask-scope">
{scopeLabel}
</Badge>
<Button
type="submit"
size="icon"
className="h-9 w-9 rounded-full"
disabled={!text.trim()}
aria-label={sendLabel}
data-testid="app-ask-send"
>
<ArrowUp className="h-4 w-4" />
</Button>
</div>
</form>
{suggestions.length > 0 ? (
<div className={cn('grid w-full gap-2', suggestions.length > 1 && 'sm:grid-cols-2')} data-testid="app-ask-suggestions">
{suggestions.map((suggestion) => (
>
<Textarea
value={text}
onChange={(event) => setText(event.target.value)}
onKeyDown={(event) => {
if (event.key !== 'Enter' || event.shiftKey || event.nativeEvent.isComposing) return;
event.preventDefault();
submit();
}}
placeholder={placeholder}
aria-label={placeholder}
rows={3}
className="min-h-24 resize-none border-0 bg-transparent p-1 text-base shadow-none focus-visible:ring-0"
data-testid="app-ask-input"
/>
<div className="mt-2 flex items-center justify-between gap-2">
<Badge variant="secondary" className="font-normal" data-testid="app-ask-scope">
{scopeLabel}
</Badge>
<Button
key={suggestion}
type="button"
variant="outline"
className="h-auto justify-start whitespace-normal px-3 py-2 text-left text-sm font-normal"
onClick={() => onAsk(suggestion)}
type="submit"
size="icon"
className="h-9 w-9 rounded-full"
disabled={!text.trim()}
aria-label={sendLabel}
data-testid="app-ask-send"
>
{suggestion}
<ArrowUp className="h-4 w-4" />
</Button>
))}
</div>
) : null}
{recent}
</div>
</div>
</form>
}
/>
</div>
);
}
Expand All @@ -411,47 +407,17 @@ interface RecentAskConversationsProps {
*/
function RecentAskConversations({ userId, apiBase, packageId, onOpen }: RecentAskConversationsProps) {
const { t } = useObjectTranslation();
const displayLocale = useDisplayLocale();
const { conversations, isLoading, error } = useConversationList({ userId, apiBase, limit: ASK_RECENT_FETCH_LIMIT });
const recent = React.useMemo(() => recentAskPageConversations(conversations, packageId), [conversations, packageId]);
// A list that has not answered, or failed, draws nothing: never an empty state it cannot vouch for.
if (isLoading || error) return null;
return (
<section className="flex w-full flex-col gap-2" data-testid="app-ask-recent" aria-label={t('console.ai.askPage.recentTitle', { defaultValue: 'Recent conversations' })}>
<h2 className="px-1 text-sm font-medium text-muted-foreground">
{t('console.ai.askPage.recentTitle', { defaultValue: 'Recent conversations' })}
</h2>
{recent.length === 0 ? (
<p className="px-1 text-sm text-muted-foreground" data-testid="app-ask-recent-empty">
{t('console.ai.askPage.recentEmpty', { defaultValue: 'Questions you ask here will appear here.' })}
</p>
) : (
<ul className="flex flex-col divide-y rounded-xl border" data-testid="app-ask-recent-list">
{recent.map((conversation) => {
const label =
conversation.title?.trim() ||
conversation.preview?.trim() ||
t('console.ai.newConversation', { defaultValue: 'New conversation' });
const when = timeAgo(conversation.updatedAt ?? conversation.createdAt, displayLocale);
return (
<li key={conversation.id}>
<button
type="button"
className="flex w-full items-center gap-3 px-3 py-2 text-left text-sm hover:bg-muted/50 focus-visible:bg-muted/50 focus-visible:outline-none"
onClick={() => onOpen(conversation.id)}
data-testid="app-ask-recent-item"
data-conversation={conversation.id}
>
<MessageSquare className="h-4 w-4 shrink-0 text-muted-foreground" aria-hidden="true" />
<span className="min-w-0 flex-1 truncate">{label}</span>
{when ? <span className="shrink-0 text-xs text-muted-foreground">{when}</span> : null}
</button>
</li>
);
})}
</ul>
)}
</section>
<RecentConversationList
size="large"
conversations={recent}
emptyText={t('console.ai.askPage.recentEmpty', { defaultValue: 'Questions you ask here will appear here.' })}
onOpen={(conversation) => onOpen(conversation.id)}
/>
);
}

Expand Down
57 changes: 57 additions & 0 deletions ui/packages/app-shell/src/console/ai/ChatPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ import { isSpreadsheetAttachment, uploadChatAttachments, chatAttachmentNotes } f
import { listLinkTarget, recordOpenTarget, nextSectionOpening } from './aiChatLinks.js';
import { hydratedMessagesToChatMessages } from './aiChatHydration.js';
import { localizeAgentLabel, agentEmptyState, buildAgentSuggestions } from './agentCopy.js';
import { drawerSuggestions, type EmptyConversationSize } from './emptyConversationModel.js';
import { DrawerRecentConversations, EmptyConversation, EmptyConversationGreeting } from './EmptyConversation.js';
import {
useDeferredFirstSend,
useComposerDraftHandoff,
Expand Down Expand Up @@ -163,6 +165,20 @@ interface ChatPaneProps {
* @default false
*/
actionsInHost?: boolean;
/**
* objectstack#37862 — the host draws the shared empty conversation before
* the first message (`EmptyConversation`): the greeting, what to ask, the
* page's suggestions and 「最近会话」, `large` where the chat fills the
* window and `compact` in the rail and the phone sheet. `userId` and
* `onOpenConversation` list the recent conversations and open one where the
* host shows conversations; without them the section is not drawn. Absent,
* the pane keeps the chat's built-in empty state.
*/
emptyConversation?: {
size: EmptyConversationSize;
userId?: string;
onOpenConversation?: (conversation: { id: string; agentId?: string }) => void;
};
}

export function ChatPane({
Expand All @@ -188,6 +204,7 @@ export function ChatPane({
onShare,
hideHeader = false,
actionsInHost = false,
emptyConversation,
}: ChatPaneProps) {
const { t, language } = useObjectTranslation();
const navigate = useNavigate();
Expand Down Expand Up @@ -603,6 +620,45 @@ export function ChatPane({
);
const emptyState = useMemo(() => agentEmptyState(t, activeAgent), [t, activeAgent]);

// objectstack#37862 — the shared empty conversation, where the host asks for
// it. The page's suggestions read the surface the agent is sent; one about
// the record in view fills the composer, the rest send.
const emptySuggestions = useMemo(
() =>
emptyConversation
? drawerSuggestions(t, { agentName: activeAgent, agentLabel: activeAgentLabel, surface: surfaceContext })
: [],
[emptyConversation, t, activeAgent, activeAgentLabel, surfaceContext],
);
const emptySize = emptyConversation?.size;
const recentUserId = emptyConversation?.userId;
const openRecentConversation = emptyConversation?.onOpenConversation;
const renderEmptyState = useMemo(() => {
if (!emptySize) return undefined;
return (actions: { send: (text: string) => void; fill: (text: string) => void }) => (
<EmptyConversation
size={emptySize}
heading={<EmptyConversationGreeting />}
subtitle={emptyState.description}
suggestions={emptySuggestions}
onSuggestion={(suggestion) =>
suggestion.mode === 'fill' ? actions.fill(suggestion.text) : actions.send(suggestion.text)
}
recent={
recentUserId && openRecentConversation ? (
<DrawerRecentConversations
size={emptySize}
userId={recentUserId}
apiBase={apiBase}
agentName={activeAgent}
onOpen={openRecentConversation}
/>
) : null
}
/>
);
}, [emptySize, emptyState.description, emptySuggestions, recentUserId, openRecentConversation, apiBase, activeAgent]);

// objectstack#37146 — with one launchable agent there is nothing to switch,
// so the row names no agent (it read only 「提问」 once the in-app build
// entry closed). Where the host lifts Share into its own title bar (the
Expand Down Expand Up @@ -844,6 +900,7 @@ export function ChatPane({
onModelChange={setSelectedModelId}
allowanceUsedFraction={allowanceUsedFraction}
suggestions={suggestions}
renderEmptyState={renderEmptyState}
onSendMessage={handleSend}
// objectstack#32749 — the attach button and the attachment chips: the
// send reads spreadsheets, images and PDFs (see `doSend`), and a file
Expand Down
Loading
Loading