Skip to content

Commit 4c4a677

Browse files
fix(console): show the AI-build entries only where the catalog serves build; old build threads still open (#36989)
Fixes #36969 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:在关闭了界面内 AI 搭建的环境(托管产品)里,管理员在侧边栏「添加应用」、首页和没有应用时的空白首页不再看到「用 AI 搭建」,改为「在 Studio 中新建」;Studio 里的 AI 侧栏不再出现;以前的搭建对话链接改在问数界面打开,对话内容仍在。搭建还开着的环境(自部署等)一切照旧。 - 为什么做:属于「关闭界面内 AI 搭建」专题的控制台收尾,替托管产品的用户去掉点进去只剩问数、像坏了一样的入口。 - 出错会怎样:入口看的是 AI 助手目录里有没有搭建助手;判断写错时,搭建还开着的环境会丢入口,这一面已用“目录里有搭建助手时完全不变”的测试钉住;本改动只动控制台,可直接整体撤回。 - 要你做什么:无。 ## What changes The console's AI-build entries gate on the live agent catalog serving the build agent itself, alias-aware (`build` or its legacy id), through one new pure predicate, `catalogServesBuild` in `hooks/surfaceAgent.ts`. Nothing reads a hosted or self-hosted flag. Where the catalog lists `build`, every entry is unchanged (regression pins below). 1. **Sidebar app menu, 「Add app」** (and the desktop no-apps empty state, which reads the same list): `useAddAppEntries` offers "Build with AI" only when `buildServed`; otherwise "New in Studio" (Studio's new-package flow). Template and marketplace are untouched. The signal comes from `useAiSurfaceEnabled()`, which now also returns `buildServed` (additive field on the same catalog read). 2. **Home builder chip**: the "Build an app" form needs `buildServed`; otherwise the existing empty-catalog branch ("New in Studio", hidden for a session that may not author) is taken. 3. **Studio AI dock**: chose the smaller change, **hidden**. `StudioChatDock` reports itself available only while the catalog is loading or serves `build`; the right slot then shows the properties alone, exactly as it already does for an empty catalog. No label or empty-state copy changes, no locale keys. Asking stays in the console's chat drawer. 4. **Full-page chat**: `/ai/build/ID` on a catalog without `build` now lands on `/ai/ask/ID` (it landed on `/ai/ask` and dropped the id), and that conversation is the one read. 5. **Maker convergence** (bare `/ai/ask` to `/ai/build`): confirmed it does not fire without `build`; `makerConvergedOnBuild` now reads the same predicate, and a page-level pin was added (the pure pin already existed in `surfaceAgent.test.ts`). Files to read first, by risk: 1. `ui/packages/app-shell/src/views/studio-design/StudioAiCopilot.tsx`, the `const available = agentsLoading || catalogServesBuild(agents);` hunk: hides the Studio copilot wherever `build` is not served. 2. `ui/packages/app-shell/src/console/ai/AiChatPage.tsx`, the `if (unavailableKnownAgent)` branch: the kept conversation id. 3. `ui/packages/app-shell/src/hooks/useAiSurface.ts`: the new `buildServed` field on a public hook's return. ## Tests On head `72595e8e448`: - New pins, each as a top-level `describe` in the component's existing harness (the AiChatPage routes have no shared harness, so one new file): - `SidebarAppMenu-36112.test.tsx`: catalog `ask` only, or a custom agent only: no build-with-AI door, "New in Studio" plus template and marketplace. Regression: `build` (and `metadata_assistant`) served: the door, its href, its text and the exact choice order are unchanged. The harness now runs the real `useAiSurfaceEnabled` over a stubbed `useAgents`. - `HomePage.noAgentsBuildChip-26614.test.tsx`: `ask` only or custom only: "New in Studio" to `/studio?new=package`, no "Build an app"; non-author gets no chip; legacy build id keeps "Build an app" to `/studio`. - `HomePage.desktopNoApps-36732.test.tsx`: agents served, build not: "New in Studio" door. - `studioCopilotSlotBody-12725.test.tsx`: `ask` only or custom only: renders nothing, reports `available: false`, no conversation resolved. Regression: `build` or legacy id: available, opens `app:app.crm:build`. - `useAiSurface.test.ts`: `buildServed` false for `ask` only, true for `build` and for the legacy id. - `AiChatPage.buildClosedRoutes-36969.test.tsx` (new): `/ai/build/c-42` to `/ai/ask/c-42` with `c-42` read, for a member and a maker; a maker's bare `/ai/ask` is never sent to `/ai/build`. Regression with `build` served: `/ai/build/c-42` stays; a maker's bare `/ai/ask` still converges on `/ai/build`. - Fixture triage (the gate changed, so fixtures that meant "the build agent is deployed" but named another agent were respelled; none was deleted): `HomePage.aiStudioDisabled`, `HomePage.authoringCapabilityGate`, `HomePage.marketplaceDisabled`, `HomePage.phoneTapTargets-29147` (`builder` to `build`), `HomePage.greetingAndApps-12601` (`custom_helper` plus `build`, header comment updated). Typed `AiSurfaceState` mocks in `RequireAiSurface.test.tsx` and `ObjectFormCanvas.test.tsx` gained `buildServed`. Two edited Home harnesses gained the module-top `import '@objectstack/lint'` that `check:test-source-alias` asks of edited files. <details><summary>Test runs (local, under the shared verify lock)</summary> - All 13 changed test files on `72595e8e448`: `Test Files 13 passed (13)`, `Tests 163 passed (163)`, lock VERDICT command-exit 0. - `pnpm --filter @object-ui/app-shell type-check` on `72595e8e448`: 0 `error TS`, VERDICT command-exit 0. - Narrowed app-shell run (409 test files under `packages/app-shell/src` and `apps/console/src` that reference a touched module, on `bd42518318e`): `Tests 4 failed | 3422 passed`, the 4 all in `useAiSurface.test.ts` (exact-object assertions missing the new field), fixed in the next commit and re-run green with the whole `console/home/__tests__` directory (`43 passed`, `277 passed`). - eslint over every changed app-shell file: 0 errors; per-file warning counts equal to `origin/main`'s (compared file by file). </details> <details><summary>Ablations (one per gate, via scripts/ablation-replace.mjs: anchor hit 1 to 0, blob changed, restored blob equals HEAD, git diff HEAD empty)</summary> Tests import the subjects from source, so no build leg applies. | Gate | Mutation | Result | |:--|:--|:--| | 「Add app」 list | `const { buildServed } = useAiSurfaceEnabled();` to `const { enabled: buildServed } = ...` | `SidebarAppMenu-36112`: 2 failed (ask-only, custom-only) | | Home chip | `buildServed: catalogServesBuild(agents),` to `buildServed: agents.length > 0,` in `HomePage.tsx` | `noAgentsBuildChip-26614`: 3 failed | | Studio dock | `catalogServesBuild(agents)` to `agents.length > 0` in `available` | `studioCopilotSlotBody-12725`: 2 failed | | Kept id | `const tail = urlConversationId ? ... : ''` to `const tail = ''` | `buildClosedRoutes-36969`: 2 failed | | Maker convergence | drop `&& catalogServesBuild(agents)` from `makerConvergedOnBuild` | `surfaceAgent.test.ts`: 2 failed; the page pin did not finish: the page loops `/ai/ask` to `/ai/build` to `/ai/ask`, the run was stopped after about 9.5 min | | `buildServed` source | `buildServed: catalogServesBuild(agents),` to `agents.length > 0` in `useAiSurface.ts` | `useAiSurface.test.ts`: 2 failed | </details> ## Acceptance notes - **File surface.** Beyond the claimed five files and their tests: `hooks/useAddAppEntries.ts` (the hook that owns the 「Add app」 list the sidebar menu draws, so item 1's gate lives there) and `hooks/useAiSurface.ts` (`buildServed`, so the list reads the same catalog read it already made), plus the fixture triage above. - **Catalogs with custom agents and no `build`** change too: they now get "New in Studio" and no Studio copilot. That is the card's rule (gate on `build`, not on any agent); a custom-only catalog could not build either. - **Item 4, which door is live.** The console routes every `/ai/...` address through `AiAddressRedirect` into the chat drawer, and the drawer already keeps the id: a target naming an unserved built-in agent with a conversation id falls back to the ambient agent and still requests that conversation (`requestedConversationId` in `ChatDockConversation.tsx`). `AiChatPage` is the exported full page; it is fixed as the card asks. No pin covers the drawer side; noted, not filed (no failing behaviour). - **Home's "Build with AI" CTA** reads the declared `authoring` capability, unchanged here. - **Local narrowing (declared):** the full app-shell suite (about 2,400 files) was not run locally; the 409-file set above was, and `Test UI` runs the whole package in CI. The `pnpm --dir ui exec vitest run scripts/` family went red once (1 of 5128) while it ran outside the lock beside the heavy narrowed run; re-run under the lock it was green (`5126 passed | 2 skipped`). ## Verification Two-minute check: `pnpm --dir ui exec vitest run packages/app-shell/src/console/ai/__tests__/AiChatPage.buildClosedRoutes-36969.test.tsx` from the repo root (after building the workspace deps), expect `Tests 5 passed (5)`. <details><summary>Derived gate families (local, head 72595e8)</summary> `node scripts/pm/dispatch-gates.mjs --commands` derived 38 families for this diff; all 38 exited 0 on `72595e8e448` (the `ui` scripts vitest family under the verify lock: `5126 passed | 2 skipped`). Reconciliation: `dispatch-gates --ran: 38 derived famil(ies) accounted for - 38 run, 0 NOT-MEASURED (a DERIVED zero - all 38 recorded an exit code and none of them is 3)`. `check-nul-bytes: OK`. `pnpm check:new-line-citations` (ui): 0 new citations. Every family CI runs (Lint UI, Type Check UI, Test UI and the rest) is read from this PR's check-runs. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbX11yNi4DyGhuzqBpV)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent d25d912 commit 4c4a677

20 files changed

Lines changed: 462 additions & 46 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(console): the AI-build entries show only where the agent catalog serves the build agent, and an old build conversation still opens
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A deployment can close in-app building with AI: its agent catalog then keeps `ask` and no longer lists `build`, and the chat route refuses `build`. The console's build entries now read the catalog for the build agent itself (alias-aware, `build` or its legacy id), never "any agent" and never a hosted or self-hosted guess:
11+
12+
- The sidebar app menu's 「Add app」 and the desktop's no-apps empty state offer "New in Studio" (Studio's new-package flow) instead of "Build with AI"; the template and marketplace choices stay.
13+
- Home's builder chip takes its "New in Studio" form, as it already did for an empty catalog, instead of "Build an app".
14+
- Studio's AI copilot is not drawn; the right panel shows the properties alone, as for an empty catalog. Asking stays in the console's chat drawer.
15+
- The full-page chat address `/ai/build/ID` lands on `/ai/ask/ID` and opens that conversation, instead of `/ai/ask` without it. A maker's bare `/ai/ask` is not redirected to `/ai/build`.
16+
17+
Where the catalog serves `build`, every entry behaves as before. `useAiSurfaceEnabled()` also returns `buildServed`; no locale keys change.

‎ui/packages/app-shell/src/console/__tests__/RequireAiSurface.test.tsx‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useAiSurfaceEnabled } from '../../hooks/useAiSurface';
1010
// The guard gates purely on the AI-surface signal (the agent catalog); that
1111
// hook's own plumbing is covered by useAiSurface.test.ts.
1212
vi.mock('../../hooks/useAiSurface', () => ({
13-
useAiSurfaceEnabled: vi.fn(() => ({ enabled: true, isLoading: false })),
13+
useAiSurfaceEnabled: vi.fn(() => ({ enabled: true, isLoading: false, buildServed: true })),
1414
}));
1515
const mockSurface = vi.mocked(useAiSurfaceEnabled);
1616

@@ -89,7 +89,7 @@ function renderGuardedAi(apps?: MetadataContextValue['apps']) {
8989

9090
describe('RequireAiSurface', () => {
9191
beforeEach(() => {
92-
mockSurface.mockReturnValue({ enabled: true, isLoading: false });
92+
mockSurface.mockReturnValue({ enabled: true, isLoading: false, buildServed: true });
9393
viewer.isAdmin = true;
9494
viewer.canAuthorMetadata = true;
9595
viewer.aiStudio = true;
@@ -105,7 +105,7 @@ describe('RequireAiSurface', () => {
105105
it('says in place that no assistant is enabled when no agents are served (objectstack#26614)', () => {
106106
// Community Edition. It used to redirect home, which read like a broken
107107
// link; now the URL stays and the screen says why, with the way home.
108-
mockSurface.mockReturnValue({ enabled: false, isLoading: false });
108+
mockSurface.mockReturnValue({ enabled: false, isLoading: false, buildServed: false });
109109
renderGuardedAi();
110110
expect(screen.queryByText('AI CHAT')).not.toBeInTheDocument();
111111
expect(screen.queryByText('HOME')).not.toBeInTheDocument();
@@ -117,7 +117,7 @@ describe('RequireAiSurface', () => {
117117
});
118118

119119
it('offers Studio\'s new-package flow to a session that may author (objectstack#26614)', () => {
120-
mockSurface.mockReturnValue({ enabled: false, isLoading: false });
120+
mockSurface.mockReturnValue({ enabled: false, isLoading: false, buildServed: false });
121121
renderGuardedAi();
122122
const studio = screen.getByTestId('ai-unavailable-studio');
123123
expect(studio).toHaveTextContent('«home.build.inStudio»');
@@ -130,14 +130,14 @@ describe('RequireAiSurface', () => {
130130
['a runtime that offers no authoring', () => { viewer.aiStudio = false; }],
131131
])('offers no Studio link to %s (objectstack#26614)', (_who, arrange) => {
132132
arrange();
133-
mockSurface.mockReturnValue({ enabled: false, isLoading: false });
133+
mockSurface.mockReturnValue({ enabled: false, isLoading: false, buildServed: false });
134134
renderGuardedAi();
135135
expect(screen.getByTestId('ai-unavailable')).toBeInTheDocument();
136136
expect(screen.queryByTestId('ai-unavailable-studio')).toBeNull();
137137
});
138138

139139
it('waits (neither chat nor the no-assistant screen) while the agent catalog is still resolving', () => {
140-
mockSurface.mockReturnValue({ enabled: false, isLoading: true });
140+
mockSurface.mockReturnValue({ enabled: false, isLoading: true, buildServed: false });
141141
renderGuardedAi();
142142
expect(screen.queryByText('AI CHAT')).not.toBeInTheDocument();
143143
expect(screen.queryByTestId('ai-unavailable')).not.toBeInTheDocument();
@@ -152,7 +152,7 @@ describe('RequireAiSurface', () => {
152152
// On a phone, which still has its own Home page (#36732).
153153
viewer.phone = true;
154154
const user = userEvent.setup();
155-
mockSurface.mockReturnValue({ enabled: false, isLoading: false });
155+
mockSurface.mockReturnValue({ enabled: false, isLoading: false, buildServed: false });
156156
renderGuardedAi([
157157
{ name: 'cloud_control', label: 'Cloud', isDefault: true },
158158
{ name: 'account', label: 'Account' },
@@ -168,7 +168,7 @@ describe('RequireAiSurface', () => {
168168
// on a desktop is no longer the launcher page but the resolver that lands
169169
// in the declared app once it knows.
170170
const user = userEvent.setup();
171-
mockSurface.mockReturnValue({ enabled: false, isLoading: false });
171+
mockSurface.mockReturnValue({ enabled: false, isLoading: false, buildServed: false });
172172
renderGuardedAi([
173173
{ name: 'cloud_control', label: 'Cloud', isDefault: true },
174174
{ name: 'account', label: 'Account' },
@@ -185,7 +185,7 @@ describe('RequireAiSurface', () => {
185185
// once it knows which apps a permission set hides (#36732); a guard mounted
186186
// outside a metadata provider resolves there too (every other case here).
187187
const user = userEvent.setup();
188-
mockSurface.mockReturnValue({ enabled: false, isLoading: false });
188+
mockSurface.mockReturnValue({ enabled: false, isLoading: false, buildServed: false });
189189
renderGuardedAi([{ name: 'crm', label: 'CRM' }, { name: 'setup', label: 'Setup' }]);
190190
await user.click(screen.getByTestId('ai-unavailable-home'));
191191
expect(screen.getByText('HOME')).toBeInTheDocument();

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,8 +1318,12 @@ export function AiChatPage({ apiBase: apiBaseProp, defaultAgent: defaultAgentPro
13181318
// A known agent that isn't deployed here (e.g. `/ai/build` with no cloud AI
13191319
// Studio): land cleanly on the default surface rather than treating the
13201320
// segment as a conversation id (which produced the junk `/ai/ask/build`).
1321+
// objectstack#36969 — a conversation the address names comes along
1322+
// (`/ai/build/ID` → `/ai/ask/ID`): where in-app building is closed the
1323+
// build agent leaves the catalog, and its old threads must still open.
13211324
if (unavailableKnownAgent) {
1322-
navigate(`/ai/${friendly}${preservedQuery}`, { replace: true });
1325+
const tail = urlConversationId ? `/${encodeURIComponent(urlConversationId)}` : '';
1326+
navigate(`/ai/${friendly}${tail}${preservedQuery}`, { replace: true });
13231327
return;
13241328
}
13251329
// cloud#1674 — a maker landing on BARE `/ai/ask` (no conversation) is
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#36969 — the full-page chat's addresses where the agent catalog
5+
* does not serve the build agent (in-app building closed: `build` persisted
6+
* inactive, `ask` still served), and where it does.
7+
*
8+
* - `/ai/build/ID` lands on the default surface WITH the conversation:
9+
* `/ai/ask/ID`, and that conversation is the one read, so an old build
10+
* thread still opens. It used to land on `/ai/ask` and drop the id.
11+
* - the cloud#1674 maker convergence (a maker's bare `/ai/ask` → `/ai/build`)
12+
* does not fire: there is no build to converge on.
13+
* - regression: where `build` is served, `/ai/build/ID` stays where it is and
14+
* a maker's bare `/ai/ask` still converges on `/ai/build`.
15+
*
16+
* Real subjects: `AiChatPage` under a real router, its route canonicalization
17+
* and `useChatConversation`. Stand-ins: the agent catalog, the authoring
18+
* capability, the signed-in user, the apps list, the chat transport (idle and
19+
* empty) and the side panels; `fetch` answers the conversation API from memory.
20+
*/
21+
22+
import '@testing-library/jest-dom/vitest';
23+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
24+
import { act, cleanup, render, screen, waitFor } from '@testing-library/react';
25+
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
26+
import React from 'react';
27+
28+
const state = vi.hoisted(() => ({
29+
agents: [] as Array<{ name: string; label?: string }>,
30+
canAuthor: false,
31+
}));
32+
33+
vi.mock('@object-ui/plugin-chatbot', async (importOriginal) => {
34+
const actual = await importOriginal<Record<string, unknown>>();
35+
return {
36+
...actual,
37+
useAiModels: () => ({ models: [], defaultModelId: undefined }),
38+
useHitlInChat: () => ({ decide: vi.fn(), decisions: {} }),
39+
useObjectChat: () => ({
40+
messages: [],
41+
isLoading: false,
42+
error: undefined,
43+
sendMessage: vi.fn(),
44+
stop: vi.fn(),
45+
reload: vi.fn(),
46+
clear: vi.fn(),
47+
setMessages: vi.fn(),
48+
}),
49+
};
50+
});
51+
vi.mock('@object-ui/plugin-chatbot/core', async (importOriginal) => ({
52+
...(await importOriginal<typeof import('@object-ui/plugin-chatbot/core')>()),
53+
useAgents: () => ({ agents: state.agents, isLoading: false, error: undefined, refetch: vi.fn() }),
54+
}));
55+
vi.mock('../../../hooks/useCanAuthorMetadata', () => ({
56+
useCanAuthorMetadata: () => state.canAuthor,
57+
}));
58+
vi.mock('@object-ui/auth', async (importOriginal) => ({
59+
...(await importOriginal<Record<string, unknown>>()),
60+
useAuth: () => ({ user: { id: 'u1' } }),
61+
}));
62+
vi.mock('../../../providers/MetadataProvider', async (importOriginal) => ({
63+
...(await importOriginal<Record<string, unknown>>()),
64+
useMetadata: () => ({ apps: [] }),
65+
}));
66+
vi.mock('../../../providers/AdapterProvider', async (importOriginal) => ({
67+
...(await importOriginal<Record<string, unknown>>()),
68+
useAdapter: () => null,
69+
}));
70+
vi.mock('../../../layout/AiUsageIndicator', () => ({ AiUsageIndicator: () => null }));
71+
vi.mock('../ConversationsSidebar', () => ({
72+
ConversationsSidebar: () => <div data-testid="sidebar" />,
73+
}));
74+
75+
import { I18nProvider } from '@object-ui/i18n';
76+
import { AiChatPage } from '../AiChatPage';
77+
78+
window.matchMedia = ((query: string) => ({
79+
matches: false,
80+
media: query,
81+
onchange: null,
82+
addEventListener: () => {},
83+
removeEventListener: () => {},
84+
addListener: () => {},
85+
removeListener: () => {},
86+
dispatchEvent: () => false,
87+
})) as unknown as typeof window.matchMedia;
88+
89+
const API = '/api/v1/ai';
90+
/** Every address the router showed, in order. */
91+
const visited: string[] = [];
92+
/** Every conversation id read by id. */
93+
const readIds: string[] = [];
94+
95+
function LocationProbe() {
96+
const location = useLocation();
97+
React.useEffect(() => {
98+
visited.push(location.pathname);
99+
}, [location.pathname]);
100+
return <output data-testid="location">{location.pathname}</output>;
101+
}
102+
103+
function visit(entry: string) {
104+
render(
105+
<I18nProvider config={{ defaultLanguage: 'en', detectBrowserLanguage: false }}>
106+
<MemoryRouter initialEntries={[entry]}>
107+
<Routes>
108+
<Route path="/ai/:agent/:conversationId" element={<AiChatPage apiBase={API} />} />
109+
<Route path="/ai/:agent" element={<AiChatPage apiBase={API} />} />
110+
</Routes>
111+
<LocationProbe />
112+
</MemoryRouter>
113+
</I18nProvider>,
114+
);
115+
}
116+
117+
const ASK_ONLY = [{ name: 'ask', label: 'Ask' }];
118+
const BOTH = [
119+
{ name: 'build', label: 'Build' },
120+
{ name: 'ask', label: 'Ask' },
121+
];
122+
123+
beforeEach(() => {
124+
visited.length = 0;
125+
readIds.length = 0;
126+
state.agents = ASK_ONLY;
127+
state.canAuthor = false;
128+
window.localStorage.clear();
129+
window.sessionStorage.clear();
130+
let minted = 0;
131+
vi.stubGlobal(
132+
'fetch',
133+
vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
134+
const url = String(input);
135+
const method = init?.method ?? 'GET';
136+
const json = (body: unknown) =>
137+
new Response(JSON.stringify(body), { status: 200, headers: { 'Content-Type': 'application/json' } });
138+
if (url === `${API}/conversations` && method === 'POST') {
139+
minted += 1;
140+
return json({ id: `conv-${minted}`, messages: [] });
141+
}
142+
const byId = /\/conversations\/([^/?]+)$/.exec(url);
143+
if (byId && method === 'GET') {
144+
readIds.push(decodeURIComponent(byId[1]));
145+
return json({ id: byId[1], agentId: 'build', messages: [] });
146+
}
147+
return json({ success: true, data: [] });
148+
}),
149+
);
150+
});
151+
152+
afterEach(() => {
153+
cleanup();
154+
vi.unstubAllGlobals();
155+
});
156+
157+
describe('in-app building closed: the catalog serves `ask`, not `build` (objectstack#36969)', () => {
158+
it('/ai/build/ID opens that conversation on the default surface: /ai/ask/ID', async () => {
159+
visit('/ai/build/c-42');
160+
await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent(/^\/ai\/ask\/c-42$/));
161+
await waitFor(() => expect(readIds).toContain('c-42'));
162+
expect(visited).not.toContain('/ai/ask');
163+
});
164+
165+
it('a maker gets it too', async () => {
166+
state.canAuthor = true;
167+
visit('/ai/build/c-42');
168+
await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent(/^\/ai\/ask\/c-42$/));
169+
expect(visited.some((p) => p === '/ai/build' || p === '/ai/ask')).toBe(false);
170+
});
171+
172+
it('the maker convergence (cloud#1674) never sends a maker\'s bare /ai/ask to /ai/build', async () => {
173+
state.canAuthor = true;
174+
visit('/ai/ask');
175+
// The same window in which the served-build leg below is redirected.
176+
await act(async () => {
177+
await new Promise((resolve) => setTimeout(resolve, 500));
178+
});
179+
expect(screen.getByTestId('location')).toHaveTextContent(/^\/ai\/ask/);
180+
expect(visited.some((p) => p.startsWith('/ai/build'))).toBe(false);
181+
});
182+
});
183+
184+
describe('regression: where the catalog serves `build`, the addresses are unchanged (objectstack#36969)', () => {
185+
beforeEach(() => {
186+
state.agents = BOTH;
187+
});
188+
189+
it('/ai/build/ID stays on the build conversation', async () => {
190+
visit('/ai/build/c-42');
191+
await waitFor(() => expect(readIds).toContain('c-42'));
192+
expect(screen.getByTestId('location')).toHaveTextContent(/^\/ai\/build\/c-42$/);
193+
expect(visited.every((p) => p === '/ai/build/c-42')).toBe(true);
194+
});
195+
196+
it('a maker\'s bare /ai/ask still converges on /ai/build (cloud#1674)', async () => {
197+
state.canAuthor = true;
198+
visit('/ai/ask');
199+
await waitFor(() => expect(visited.some((p) => p.startsWith('/ai/build'))).toBe(true));
200+
});
201+
});

‎ui/packages/app-shell/src/console/home/HomePage.tsx‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import { STUDIO_NEW_PACKAGE_PATH } from '../../views/studio-design/studioNewPack
9393
import { useOpenAssistant } from '../../layout/chatDockControl.js';
9494
import { isProductApp } from '../../utils/homePath.js';
9595
import { useAddAppEntries, useMayAddApp } from '../../hooks/useAddAppEntries.js';
96+
import { catalogServesBuild } from '../../hooks/surfaceAgent.js';
9697

9798
/**
9899
* Which AI home CTAs to surface, driven by the live agent catalog (the single
@@ -102,6 +103,10 @@ import { useAddAppEntries, useMayAddApp } from '../../hooks/useAddAppEntries.js'
102103
* - `buildAvailable` — a build/authoring agent is deployed → "Build with AI".
103104
* That's a cloud / AI-Studio feature, ABSENT on open-source builds.
104105
* - `aiEnabled` — any agent at all (AI is on here in some form).
106+
* - `buildServed` — the catalog lists the build agent itself, alias-aware
107+
* (`catalogServesBuild`, objectstack#36969): what the "Build an app" chip
108+
* promises. Where in-app building is closed the catalog keeps `ask` and
109+
* drops `build`, so `aiEnabled` alone would promise a build nothing serves.
105110
* All false while the catalog loads or when AI isn't enabled, so nothing
106111
* flashes and no AI CTA appears where there's no agent to back it.
107112
*
@@ -118,6 +123,7 @@ function useHomeAiAvailability(): {
118123
aiResolved: boolean;
119124
askAvailable: boolean;
120125
buildAvailable: boolean;
126+
buildServed: boolean;
121127
} {
122128
const apiBase = useMemo(() => resolveAiApiBase(), []);
123129
const { agents, isLoading } = useAgents({ apiBase });
@@ -130,6 +136,7 @@ function useHomeAiAvailability(): {
130136
askAvailable: agents.some((a) => isAskAgent(a.name)),
131137
// cloud#816 — authoring availability by DECLARED capability (name-check fallback inside).
132138
buildAvailable: agents.some((a) => agentHasCapability(agents, a.name, 'authoring')),
139+
buildServed: catalogServesBuild(agents),
133140
};
134141
}
135142

@@ -511,7 +518,7 @@ export function HomePage({ checklist }: HomePageProps = {}) {
511518
// AI CTA gating, per agent: "Build with AI" only when a build agent is
512519
// deployed (cloud / AI Studio); "Ask AI" only when a data agent is; neither
513520
// when AI isn't enabled. Community builds typically land in the ask-only state.
514-
const { aiEnabled, aiResolved, askAvailable, buildAvailable } = useHomeAiAvailability();
521+
const { aiResolved, askAvailable, buildAvailable, buildServed } = useHomeAiAvailability();
515522
// objectstack#8270 — the authoring CTAs below are gated on the SERVER's
516523
// capability answer, not on the admin ROLE: on the EE multi-tenant deploy an
517524
// `org_owner` is an admin (`isAdmin === true`) yet deliberately holds no
@@ -958,8 +965,13 @@ export function HomePage({ checklist }: HomePageProps = {}) {
958965
* may not author gets no chip rather than a dimmed one (the
959966
* template chip beside it still carries the reason). With
960967
* agents present nothing changes. The chip waits for the
961-
* catalog's answer, so neither form flashes before the other. */}
962-
{aiStudioEnabled && aiEnabled && (
968+
* catalog's answer, so neither form flashes before the other.
969+
*
970+
* objectstack#36969 — the AI form is drawn only where the
971+
* catalog serves the build agent itself (`buildServed`), not
972+
* any agent: a deployment that closed in-app building still
973+
* serves `ask`, and there the chip takes this Studio form. */}
974+
{aiStudioEnabled && buildServed && (
963975
<BuilderChip
964976
icon={Hammer}
965977
label={t('home.build.title', { defaultValue: 'Build an app' })}
@@ -970,7 +982,7 @@ export function HomePage({ checklist }: HomePageProps = {}) {
970982
testId="home-build-app"
971983
/>
972984
)}
973-
{aiStudioEnabled && aiResolved && !aiEnabled && canAuthorMetadata && (
985+
{aiStudioEnabled && aiResolved && !buildServed && canAuthorMetadata && (
974986
<BuilderChip
975987
icon={Hammer}
976988
label={t('home.build.inStudio', { defaultValue: 'New in Studio' })}

‎ui/packages/app-shell/src/console/home/__tests__/HomePage.aiStudioDisabled.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ vi.mock('@object-ui/auth', async (importOriginal) => ({
9090

9191
vi.mock('@object-ui/plugin-chatbot/core', async (importOriginal) => ({
9292
...(await importOriginal<typeof import('@object-ui/plugin-chatbot/core')>()),
93-
useAgents: () => ({ agents: [{ name: 'builder' }] }),
93+
useAgents: () => ({ agents: [{ name: 'build' }] }),
9494
isAskAgent: () => false,
9595
agentHasCapability: () => true,
9696
}));

0 commit comments

Comments
 (0)