Skip to content

Commit 8e5ad14

Browse files
fix(console): AI pane names no lone agent; the drawer drops the empty header row (#37160)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8Ew4Ge2RjXufCRJ9pCgKWSC)_ Fixes #37146 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:右侧 AI 助手只有一个智能体时,顶部不再出现只写着「提问」的那一行,对话区直接从标题栏下面开始;有两个及以上智能体时,切换器照旧。 - 为什么做:AI 搭建入口关闭后,目录里只剩「提问」一个,这一行没有东西可切,只是占地方(卡上你的原话)。 - 出错会怎样:只影响助手顶部这一行画不画;不改请求、不改数据,可直接整体撤回。 - 要你做什么:无。 ## What changes `ui/packages/app-shell/src/console/ai/AiChatPage.tsx`, the pane's `headerSlot`: - With one launchable agent (`showAgentLauncher` false) the row no longer draws a `span` with the agent's name. The switcher arms (Tabs for up to three agents, Select above) are unchanged. - `headerHasContent` = a switcher, or the build package chip (`isBuildSurface`), or Share/Doctor still in the row (`!actionsInHost`), or the offline note (`agentsError`). When none holds, `ChatPane` passes no `headerSlot`, so `ChatbotEnhanced` draws no wrapper, no band and no border. That is the drawer case: its host lifts Share and the Build Doctor into the drawer's title bar (`actionsInHost`, objectstack#35445). - The full-page assistant follows the same rule. It keeps its row because Share (and the Doctor where offered) sit there, now with no agent name beside them. - The row gets `data-testid="ai-chat-header"` so the test can name it. Changeset: `.changeset/37146-ai-pane-lone-agent-header.md` (`@object-ui/app-shell` patch). ## Why Since the in-app build entry closed, the catalog usually serves only the ask agent. The row had nothing to switch and read only 「提问」. ## Verification New `ui/packages/app-shell/src/console/ai/__tests__/AiChatPage.loneAgentHeader-37146.test.tsx` renders the real `ChatPane` and the real `ChatbotEnhanced`. Only the chat transport, the models list and the metadata and adapter providers are stand-ins: - drawer (actions lifted), one agent: no `ai-chat-agent-picker`, no agent-name span, no header row; - full page, one agent: no picker, the row holds Share, and no "Ask" text; - drawer and full page, two agents: the switcher renders; - drawer, one agent on the build surface: the row stays for the package chip. Screenshots, right-side drawer at 1280×720, zh-CN, one `ask` agent served. These are a scratch dev-server fixture (the real `ChatDockPanel` + `ChatDockConversation`, with the AI endpoints answered in the browser) and are not committed. The project thread carries the image files: 1. Before (main `6f3a8da2`): under the 「AI 助手」 title bar, a bordered row holding only 「提问」. 2. After: the empty state starts right under the title bar, with no row. <details><summary>Readings (head b0c6e50)</summary> - `pnpm --dir ui exec vitest run packages/app-shell/src/console/ai/__tests__/AiChatPage.loneAgentHeader-37146.test.tsx` → 5 passed. - Ablation: `AiChatPage.tsx` back to main's `headerSlot` (testid kept) → the two one-agent cases go red (2 failed, 3 passed); the fixed file restored → 5 passed. - `pnpm --dir ui exec vitest run packages/app-shell/src/console/ai/ packages/app-shell/src/layout/` → Test Files 221 passed, Tests 1805 passed. - `pnpm exec turbo run type-check --filter=@object-ui/app-shell` → 69/69 tasks successful. - `node scripts/pm/dispatch-gates.mjs --commands` (merge base 6f3a8da, 3 paths) → 38 commands, all 38 exit 0 (incl. `pnpm --dir ui exec vitest run scripts/`, `check:type-check-debt`, `check:changeset-gate-self-tests`). </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (untouched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: n/a. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbWzzVHDadsqECHsTmd)_ <!-- signed: repo:cloud#1 · os-warren · session_01JQwxbWzzVHDadsqECHsTmd --> Co-authored-by: Claude <noreply@anthropic.com>
1 parent c063734 commit 8e5ad14

3 files changed

Lines changed: 171 additions & 7 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
Clause-②: no
6+
Metadata-protocol: none
7+
8+
The AI assistant no longer names the agent in its header when only one agent is offered: there is nothing to switch, so the row read only "Ask". In the right-side drawer, where Share and the Build Doctor sit in the drawer's own title bar, that leaves the row empty, so it is not drawn at all. With two or more agents the switcher is unchanged; the full-page assistant keeps its row for Share.

‎ui/packages/app-shell/src/console/ai/AiChatPage.tsx‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2782,8 +2782,19 @@ export function ChatPane({
27822782
return Array.from(byPackage, ([id, label]) => ({ id, label }));
27832783
}, [metadataApps, appLabel, t]);
27842784

2785+
// objectstack#37146 — with one launchable agent there is nothing to switch,
2786+
// so the row names no agent (it read only 「提问」 once the in-app build
2787+
// entry closed). Where the host lifts Share and the Build Doctor into its
2788+
// own title bar (the drawer, objectstack#35445) and nothing else is left —
2789+
// no switcher, no build package chip, no offline note — the row is not
2790+
// drawn at all, so no empty band or border remains.
2791+
const headerHasContent =
2792+
showAgentLauncher || isBuildSurface || !actionsInHost || Boolean(agentsError);
2793+
27852794
const headerSlot = (
2786-
<div className="flex flex-wrap items-center justify-between gap-2 border-b border-border/50 px-4 pb-2 pt-3 sm:px-6">
2795+
<div
2796+
data-testid="ai-chat-header"
2797+
className="flex flex-wrap items-center justify-between gap-2 border-b border-border/50 px-4 pb-2 pt-3 sm:px-6">
27872798
<div className="flex min-w-0 flex-1 items-center gap-2">
27882799
{showAgentLauncher ? (
27892800
launcherAgents.length <= 3 ? (
@@ -2842,11 +2853,7 @@ export function ChatPane({
28422853
</SelectContent>
28432854
</Select>
28442855
)
2845-
) : (
2846-
<span className="truncate text-xs font-medium text-foreground/85">
2847-
{activeAgentLabel}
2848-
</span>
2849-
)}
2856+
) : null}
28502857
{isBuildSurface ? (
28512858
// A1.b — the binding chip is a SWITCHER now: each app gets its own
28522859
// build conversation (the scope is per-package), so picking one here
@@ -3082,7 +3089,7 @@ export function ChatPane({
30823089
packageRemovalPartialLabel={(failed) => t('console.ai.packageRemovalPartial', { count: failed })}
30833090
surface="plain"
30843091
maxHeight="100%"
3085-
headerSlot={hideHeader ? undefined : headerSlot}
3092+
headerSlot={hideHeader || !headerHasContent ? undefined : headerSlot}
30863093
// objectui#12978 — the drafts line (`pendingDraftsBar` above) is a row
30873094
// of the composer's own area, in
30883095
// flow above the input. The bar used to float (`absolute bottom-20`)
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#37146 — the AI pane's header row with one launchable agent.
5+
*
6+
* Since the in-app build entry closed, the agent catalog usually offers only
7+
* the ask agent. The header row then had nothing to switch, and drew the lone
8+
* agent's name (「提问」 / "Ask") as plain text. In the right-side drawer the
9+
* host lifts Share and the Build Doctor into its own title bar
10+
* (`actionsInHost`, objectstack#35445), so that name was the row's only
11+
* content.
12+
*
13+
* - one agent: no switcher and no agent name; in the drawer (actions lifted)
14+
* no header row at all; on the full page the row stays for Share.
15+
* - two agents: the switcher renders, in the drawer and on the full page.
16+
* - one agent on the build surface: the row stays for the package chip.
17+
*
18+
* Real subjects: `ChatPane` and the real `ChatbotEnhanced` that draws its
19+
* `headerSlot`. Stand-ins: the chat transport (idle and empty), the models
20+
* list, the metadata and adapter providers.
21+
*/
22+
23+
import '@testing-library/jest-dom/vitest';
24+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
25+
import { cleanup, render, screen } from '@testing-library/react';
26+
import { MemoryRouter } from 'react-router-dom';
27+
import React from 'react';
28+
29+
vi.mock('@object-ui/plugin-chatbot', async (importOriginal) => {
30+
const actual = await importOriginal<Record<string, unknown>>();
31+
return {
32+
...actual,
33+
useObjectChat: () => ({
34+
messages: [],
35+
isLoading: false,
36+
error: undefined,
37+
sendMessage: vi.fn(),
38+
stop: vi.fn(),
39+
reload: vi.fn(),
40+
clear: vi.fn(),
41+
setMessages: vi.fn(),
42+
}),
43+
useAiModels: () => ({ models: [], defaultModelId: undefined }),
44+
useHitlInChat: () => ({ decide: vi.fn(), decisions: {} }),
45+
};
46+
});
47+
vi.mock('../../../providers/MetadataProvider', async (importOriginal) => ({
48+
...(await importOriginal<Record<string, unknown>>()),
49+
useMetadata: () => ({ apps: [] }),
50+
}));
51+
vi.mock('../../../providers/AdapterProvider', async (importOriginal) => ({
52+
...(await importOriginal<Record<string, unknown>>()),
53+
useAdapter: () => null,
54+
}));
55+
// A user who may not author metadata: for a maker, a served build agent
56+
// converges the catalog onto build alone (`makerVisibleAgents`), which would
57+
// leave one launchable agent in the two-agent cases.
58+
vi.mock('../../../hooks/useCanAuthorMetadata', () => ({
59+
useCanAuthorMetadata: () => false,
60+
}));
61+
62+
import { I18nProvider } from '@object-ui/i18n';
63+
import type { AgentDescriptor } from '@object-ui/plugin-chatbot';
64+
import { ChatPane } from '../AiChatPage';
65+
66+
window.matchMedia = ((query: string) => ({
67+
matches: false,
68+
media: query,
69+
onchange: null,
70+
addEventListener: () => {},
71+
removeEventListener: () => {},
72+
addListener: () => {},
73+
removeListener: () => {},
74+
dispatchEvent: () => false,
75+
})) as unknown as typeof window.matchMedia;
76+
77+
const ASK = { name: 'ask', label: 'Ask' } as unknown as AgentDescriptor;
78+
const BUILD = { name: 'build', label: 'Build' } as unknown as AgentDescriptor;
79+
80+
function renderPane(opts: { agents: AgentDescriptor[]; activeAgent: string; actionsInHost: boolean }) {
81+
return render(
82+
<I18nProvider config={{ defaultLanguage: 'en', detectBrowserLanguage: false }}>
83+
<MemoryRouter initialEntries={['/apps/crm']}>
84+
<ChatPane
85+
agents={opts.agents}
86+
agentsLoading={false}
87+
agentsError={undefined}
88+
activeAgent={opts.activeAgent}
89+
chatApi={`/api/v1/ai/agents/${opts.activeAgent}/chat`}
90+
apiBase="/api/v1/ai"
91+
conversationId="conv-1"
92+
initialMessages={[]}
93+
pendingFirstMessageRef={{ current: null }}
94+
onSent={vi.fn()}
95+
onShare={vi.fn()}
96+
actionsInHost={opts.actionsInHost}
97+
/>
98+
</MemoryRouter>
99+
</I18nProvider>,
100+
);
101+
}
102+
103+
/** The pane's header row (`headerSlot`). */
104+
const headerRow = () => screen.queryByTestId('ai-chat-header');
105+
106+
beforeEach(() => {
107+
window.localStorage.clear();
108+
window.sessionStorage.clear();
109+
});
110+
afterEach(() => cleanup());
111+
112+
describe('AI pane header with one launchable agent (objectstack#37146)', () => {
113+
it('drawer (actions lifted), one agent: no switcher, no agent name, no header row', () => {
114+
renderPane({ agents: [ASK], activeAgent: 'ask', actionsInHost: true });
115+
expect(screen.queryByTestId('ai-chat-agent-picker')).not.toBeInTheDocument();
116+
expect(headerRow()).toBeNull();
117+
// The name is gone from the header; the composer still names the agent
118+
// in its placeholder, so the assertion is scoped to the absent row.
119+
expect(screen.queryByText('Ask', { selector: 'span' })).not.toBeInTheDocument();
120+
});
121+
122+
it('full page, one agent: no switcher and no agent name; the row stays for Share', () => {
123+
renderPane({ agents: [ASK], activeAgent: 'ask', actionsInHost: false });
124+
expect(screen.queryByTestId('ai-chat-agent-picker')).not.toBeInTheDocument();
125+
const row = headerRow();
126+
expect(row).not.toBeNull();
127+
expect(row).toContainElement(screen.getByTestId('ai-chat-share-button'));
128+
expect(row).not.toHaveTextContent('Ask');
129+
});
130+
131+
it('drawer, two agents: the switcher renders', () => {
132+
renderPane({ agents: [BUILD, ASK], activeAgent: 'ask', actionsInHost: true });
133+
expect(headerRow()).not.toBeNull();
134+
expect(screen.getByTestId('ai-chat-agent-picker')).toBeInTheDocument();
135+
});
136+
137+
it('full page, two agents: the switcher renders beside Share', () => {
138+
renderPane({ agents: [BUILD, ASK], activeAgent: 'ask', actionsInHost: false });
139+
expect(screen.getByTestId('ai-chat-agent-picker')).toBeInTheDocument();
140+
expect(screen.getByTestId('ai-chat-share-button')).toBeInTheDocument();
141+
});
142+
143+
it('drawer, one agent on the build surface: the row stays for the package chip', () => {
144+
renderPane({ agents: [BUILD], activeAgent: 'build', actionsInHost: true });
145+
expect(screen.queryByTestId('ai-chat-agent-picker')).not.toBeInTheDocument();
146+
expect(headerRow()).not.toBeNull();
147+
expect(screen.getByTestId('ai-build-package-chip')).toBeInTheDocument();
148+
});
149+
});

0 commit comments

Comments
 (0)