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
14 changes: 14 additions & 0 deletions .changeset/39878-workbench-ask-box.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

feat(app-shell): the workbench home's ask-AI box — a question typed under the greeting opens the right-side AI drawer and is sent there

Clause-②: no
Metadata-protocol: none

Who sees it: everyone who opens the built-in workbench app's home, on a runtime that deploys the `ask` agent.

- **New:** under the greeting, a full-width box, 「问问你的数据,或让 AI 帮你做事…」 / "Ask about your data, or have AI do something for you…". Enter (or the send button) opens the right-side AI drawer on a new conversation whose first message is the question; the workbench page stays where it is. Shift+Enter breaks the line, and an Enter that ends an input-method composition (pinyin, kana) sends nothing. The question is asked across every app: the conversation is filed under no app, so it shows under 「All」 in the drawer's history. Where the runtime deploys no `ask` agent the box is not drawn. It replaces the 「Ask AI」 button the slot held until now.
- **Fixed:** the drawer handle's `open(target, handoff)` documented that a handoff's prompt is sent once as the target thread's first message, but nothing delivered it: the drawer body never received the handoff. The prompt is now sent as the first message of the fresh thread it was opened with, once that thread is in view with no conversation yet — never into a thread that already exists — and the body moving its own thread afterwards (its first send, a history row, +) spends it, so reopening the drawer never sends it twice.
6 changes: 6 additions & 0 deletions ui/packages/app-shell/src/console/ai/ChatPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ interface ChatPaneProps {
/** Page-owned stash for a first message sent before the conversation id resolved
* (survives this pane's id-keyed remount). See {@link useDeferredFirstSend}. */
pendingFirstMessageRef: React.MutableRefObject<PendingFirstMessage | null>;
/** Bumped by the host each time it seeds `pendingFirstMessageRef` itself (the
* drawer's handoff), so the replay runs for a seed no send of this pane made.
* See {@link useDeferredFirstSend}'s `pendingSignal`. */
pendingSignal?: number;
/** objectstack#32031 — creates the conversation on the first send (the host's
* `useChatConversation().ensureConversation`); no row exists before it.
* See {@link useDeferredFirstSend}. */
Expand Down Expand Up @@ -217,6 +221,7 @@ export function ChatPane({
conversationFocus,
initialMessages,
pendingFirstMessageRef,
pendingSignal,
ensureConversation,
conversationCreateError,
selectedModelId: hostSelectedModelId,
Expand Down Expand Up @@ -674,6 +679,7 @@ export function ChatPane({
conversationId,
pendingRef: pendingFirstMessageRef,
doSend,
pendingSignal,
// #2450 — this pane's agent surface; a stash targeted at another surface
// is held, never consumed here.
agentRoute: activeAgent ? agentRouteName(activeAgent) : undefined,
Expand Down
122 changes: 100 additions & 22 deletions ui/packages/app-shell/src/console/workbench/WorkbenchAskSlot.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,116 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* The workbench home's ask-AI slot: under the greeting, above the today
* section, the full width of the page.
* The workbench home's ask-AI box: under the greeting, above the today
* section, the full width of the page (objectstack#39878, its first slice).
*
* Today it holds the retired home's 「Ask AI」 button (`HomeAiActions`, its
* gates unchanged: drawn only where an ask agent is deployed, and not for a
* maker the build agent serves), which opens the console's right-side drawer
* in place (objectstack#34608), through the top bar's own entry
* (`useAskAiEntry`). The ask-AI box replaces this module's body; the page
* mounts the slot and owns nothing inside it.
* A question typed here and sent (Enter, or the send button) opens the
* console's right-side drawer on a new `ask` conversation whose first message
* is that question; the workbench stays where it is (objectstack#34608: AI
* lives only in the drawer). The question rides the drawer's in-memory
* handoff (`ChatDockControl.open`), never the address or storage. Under a
* layout with no drawer, `useOpenAssistant` goes to the pre-drawer address
* with the handoff in navigation state, which the console routes back into
* the drawer.
*
* The scope is every app: the workbench is a built-in app, so the drawer
* opened here is app-less (`ambientAppPackage`) and the conversation is filed
* under no app, i.e. under 「All」 in the history.
*
* Drawn only where the runtime deploys the `ask` agent; with none the slot
* collapses (`empty:hidden`). Suggestions and attachments are later slices.
*
* @module
*/

import * as React from 'react';
import { ArrowUp, MessageCircle } from 'lucide-react';
import { Button, cn } from '@object-ui/components';
import { useObjectTranslation } from '@object-ui/i18n';
import { useAskAiEntry } from '../../layout/AssistantTopBarButton.js';
import { useCanAuthorMetadata } from '../../hooks/useCanAuthorMetadata.js';
import { HomeAiActions, useHomeAiAvailability } from '../home/HomePage.js';
import { useOpenAssistant } from '../../layout/chatDockControl.js';
import { useHomeAiAvailability } from '../home/HomePage.js';

/** Lines the box grows to before it scrolls. */
const MAX_LINES = 6;

export function WorkbenchAskSlot() {
const { t } = useObjectTranslation();
const askAi = useAskAiEntry();
const { askAvailable, buildAvailable } = useHomeAiAvailability();
const canAuthorMetadata = useCanAuthorMetadata();
const { askAvailable } = useHomeAiAvailability();
return (
<section data-testid="workbench-ask-slot" data-workbench-slot="ask-ai" className="empty:hidden">
<HomeAiActions
askAvailable={askAvailable}
buildAvailable={buildAvailable}
canAuthorMetadata={canAuthorMetadata}
openAssistant={(agent) => askAi({ agent })}
t={t}
/>
{askAvailable && <WorkbenchAskBox />}
</section>
);
}

/** The box itself: a growing text area and its send button. */
export function WorkbenchAskBox() {
const { t } = useObjectTranslation();
const openAssistant = useOpenAssistant();
const [text, setText] = React.useState('');
const boxRef = React.useRef<HTMLTextAreaElement>(null);
const question = text.trim();

// Grow with the text, up to MAX_LINES, then scroll.
React.useLayoutEffect(() => {
const box = boxRef.current;
if (!box) return;
box.style.height = 'auto';
const lineHeight = Number.parseFloat(getComputedStyle(box).lineHeight) || 24;
box.style.height = `${Math.min(box.scrollHeight, lineHeight * MAX_LINES)}px`;
}, [text]);

const send = () => {
if (!question) return;
openAssistant({ agent: 'ask', fresh: true }, { handoffPrompt: question });
setText('');
};

const label = t('home.askAI', { defaultValue: 'Ask AI' });
return (
<form
data-testid="workbench-ask-box"
className={cn(
'flex items-end gap-2 rounded-xl border bg-card px-3 py-2 shadow-sm transition-shadow',
'focus-within:border-ring focus-within:ring-2 focus-within:ring-ring/20',
)}
onSubmit={(e) => {
e.preventDefault();
send();
}}
>
<MessageCircle className="mb-2.5 h-5 w-5 shrink-0 text-muted-foreground max-sm:mb-3" aria-hidden="true" />
<textarea
ref={boxRef}
rows={1}
value={text}
onChange={(e) => setText(e.target.value)}
onKeyDown={(e) => {
// Enter sends, Shift+Enter breaks the line. An Enter that ends an
// IME composition (pinyin, kana) commits the text and sends nothing.
if (e.key !== 'Enter' || e.shiftKey || e.nativeEvent.isComposing || e.keyCode === 229) return;
e.preventDefault();
send();
}}
aria-label={label}
placeholder={t('workbench.ask.placeholder', {
defaultValue: 'Ask about your data, or have AI do something for you…',
})}
className={cn(
'min-h-10 flex-1 resize-none bg-transparent py-2 text-base leading-6 outline-none',
'placeholder:text-muted-foreground max-sm:min-h-11 max-sm:py-2.5',
)}
data-testid="workbench-ask-input"
/>
<Button
type="submit"
size="icon"
disabled={!question}
aria-label={t('workbench.ask.send', { defaultValue: 'Ask' })}
className="mb-0.5 size-9 shrink-0 rounded-lg max-sm:size-11"
data-testid="workbench-ask-send"
>
<ArrowUp className="h-4 w-4" aria-hidden="true" />
</Button>
</form>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import '@testing-library/jest-dom/vitest';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import React from 'react';
import { render, screen, cleanup, within } from '@testing-library/react';
import { render, screen, cleanup, within, fireEvent } from '@testing-library/react';

const navigate = vi.fn();
vi.mock('react-router-dom', async () => {
Expand All @@ -39,6 +39,7 @@ vi.mock('@object-ui/i18n', async (importOriginal) => ({
}),
}));

let agentsFixture: { name: string }[] = [{ name: 'ask' }];
const viewer = { isAdmin: true, canAuthor: true, approvalsReadable: true, notificationsReadable: true };

vi.mock('@object-ui/auth', async (importOriginal) => ({
Expand All @@ -54,7 +55,7 @@ vi.mock('../../../hooks/useCanAuthorMetadata', () => ({

vi.mock('@object-ui/plugin-chatbot/core', async (importOriginal) => ({
...(await importOriginal<typeof import('@object-ui/plugin-chatbot/core')>()),
useAgents: () => ({ agents: [{ name: 'ask' }], isLoading: false }),
useAgents: () => ({ agents: agentsFixture, isLoading: false }),
isAskAgent: (name: string) => name === 'ask',
agentHasCapability: () => false,
}));
Expand Down Expand Up @@ -99,6 +100,8 @@ vi.mock('../../home/RecoveryPasswordReminder', () => ({ RecoveryPasswordReminder

import '@objectstack/lint';
import { WorkbenchHomePage } from '../WorkbenchHomePage';
import { WorkbenchAskSlot } from '../WorkbenchAskSlot';
import { ChatDockControlProvider, type ChatDockControl } from '../../../layout/chatDockControl';
import { getAppComponent } from '../../../services/componentRegistry';
import '../../../services/builtinComponents';

Expand All @@ -119,6 +122,7 @@ beforeEach(() => {
viewer.approvalsReadable = true;
viewer.notificationsReadable = true;
appsFixture = [SETUP, WORKBENCH, CRM];
agentsFixture = [{ name: 'ask' }];
recentFixture = [SALES_DASHBOARD];
navigate.mockReset();
});
Expand Down Expand Up @@ -155,8 +159,8 @@ describe('WorkbenchHomePage', () => {
'home-recent',
'workbench-apps-rail',
]);
// The ask slot holds the retired home's 「Ask AI」 for now.
expect(within(screen.getByTestId('workbench-ask-slot')).getByTestId('home-ask-ai')).toBeInTheDocument();
// The ask slot holds the ask-AI box (objectstack#39878).
expect(within(screen.getByTestId('workbench-ask-slot')).getByTestId('workbench-ask-box')).toBeInTheDocument();
});

it("draws today's three columns: approvals, tasks, notifications", () => {
Expand Down Expand Up @@ -244,3 +248,69 @@ describe('WorkbenchHomePage', () => {
expect(screen.getByTestId('workbench-add-apps-authoring-gate')).toHaveTextContent('«home.build.noCapability»');
});
});

describe('WorkbenchAskSlot: the ask-AI box under the greeting (objectstack#39878)', () => {
function renderInDrawerHost() {
const control: ChatDockControl = { expanded: false, fullWindow: false, toggle: vi.fn(), open: vi.fn() };
render(
<ChatDockControlProvider value={control}>
<WorkbenchAskSlot />
</ChatDockControlProvider>,
);
return control;
}
const input = () => screen.getByTestId('workbench-ask-input') as HTMLTextAreaElement;

it('draws the box with its placeholder, named Ask AI, its send button off while empty', () => {
renderInDrawerHost();
expect(input()).toHaveAttribute('placeholder', '«workbench.ask.placeholder»');
expect(input()).toHaveAccessibleName('«home.askAI»');
expect(screen.getByTestId('workbench-ask-send')).toBeDisabled();
expect(screen.getByTestId('workbench-ask-send')).toHaveAccessibleName('«workbench.ask.send»');
});

it('Enter opens the drawer on a new ask thread carrying the question, and empties the box', () => {
const control = renderInDrawerHost();
fireEvent.change(input(), { target: { value: ' Which deals close this month? ' } });
fireEvent.keyDown(input(), { key: 'Enter' });
expect(control.open).toHaveBeenCalledTimes(1);
expect(control.open).toHaveBeenCalledWith(
{ agent: 'ask', fresh: true },
{ handoffPrompt: 'Which deals close this month?' },
);
expect(input().value).toBe('');
// The workbench stays where it is: AI lives in the drawer (objectstack#34608).
expect(navigate).not.toHaveBeenCalled();
});

it('the send button sends the same way', () => {
const control = renderInDrawerHost();
fireEvent.change(input(), { target: { value: 'Overdue tasks?' } });
fireEvent.click(screen.getByTestId('workbench-ask-send'));
expect(control.open).toHaveBeenCalledWith({ agent: 'ask', fresh: true }, { handoffPrompt: 'Overdue tasks?' });
});

it('Shift+Enter, an Enter ending an IME composition, and a blank box send nothing', () => {
const control = renderInDrawerHost();
fireEvent.change(input(), { target: { value: '本月' } });
fireEvent.keyDown(input(), { key: 'Enter', shiftKey: true });
fireEvent.keyDown(input(), { key: 'Enter', isComposing: true });
fireEvent.keyDown(input(), { key: 'Enter', keyCode: 229 });
fireEvent.change(input(), { target: { value: ' ' } });
fireEvent.keyDown(input(), { key: 'Enter' });
expect(control.open).not.toHaveBeenCalled();
});

it('under a layout with no drawer, goes to the pre-drawer address with the question in navigation state', () => {
render(<WorkbenchAskSlot />);
fireEvent.change(input(), { target: { value: 'Pending approvals?' } });
fireEvent.keyDown(input(), { key: 'Enter' });
expect(navigate).toHaveBeenCalledWith('/ai/ask?new=1', { state: { handoffPrompt: 'Pending approvals?' } });
});

it('is not drawn where the runtime deploys no ask agent', () => {
agentsFixture = [];
render(<WorkbenchAskSlot />);
expect(screen.getByTestId('workbench-ask-slot')).toBeEmptyDOMElement();
});
});
11 changes: 11 additions & 0 deletions ui/packages/app-shell/src/layout/ChatDock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
readStoredDockFullWindow,
writeStoredDockFullWindow,
type ChatDockConversationActions,
type ChatDockHandoff,
type ChatDockTarget,
type ShownConversation,
} from './chatDockTarget.js';
Expand Down Expand Up @@ -271,6 +272,12 @@ export interface ChatDockThreadProps {
* so the host can record it at a close. Unused with `children`.
*/
onShownConversationChange?: (shown: ShownConversation) => void;
/**
* The host's held handoff (`ChatDockControl.open`'s second argument): its
* prompt is sent once, as the first message of the fresh thread it opened
* (see {@link ChatDockConversation}). Unused with `children`.
*/
handoff?: ChatDockHandoff;
}

export interface ChatDockPanelProps extends ChatDockThreadProps {
Expand Down Expand Up @@ -328,6 +335,7 @@ export function ChatDockPanel({
onTargetChange,
onOpenInApp,
onShownConversationChange,
handoff,
children,
}: ChatDockPanelProps) {
const { t } = useObjectTranslation();
Expand Down Expand Up @@ -426,6 +434,7 @@ export function ChatDockPanel({
shareOpen={body.shareOpen}
onShareOpenChange={body.setShareOpen}
onShownConversationChange={onShownConversationChange}
handoff={handoff}
/>
</React.Suspense>
)}
Expand Down Expand Up @@ -480,6 +489,7 @@ export function ChatDockMobileSheet({
onTargetChange,
onOpenInApp,
onShownConversationChange,
handoff,
children,
}: ChatDockMobileSheetProps) {
const { t } = useObjectTranslation();
Expand Down Expand Up @@ -546,6 +556,7 @@ export function ChatDockMobileSheet({
shareOpen={body.shareOpen}
onShareOpenChange={body.setShareOpen}
onShownConversationChange={onShownConversationChange}
handoff={handoff}
/>
</React.Suspense>
)}
Expand Down
Loading
Loading