You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 531e55b
Browse filesBrowse the repository at this point in the historyBrowse files
feat(app-shell): hide the ai:chat menu entry from a member who cannot get an agent; the home falls to the next entry (#37960)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D3PqTGGb1rgoRqKj4rT4Xjk)_Fixes#37833
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:部署没开 AI、或本人没有 AI
席位的人,在应用菜单(电脑侧栏、手机应用菜单、命令面板、页面里的菜单块)里不再看到「AI
问询」项;它原本是首页时,打开应用直接进入下一个菜单项,加载期间只显示骨架、不会先闪进问询页再跳走。
- 为什么做:这是「AI 问询首页」专区的收尾一项,替拿不到 AI 的成员挡掉一个点开就是「不可用」的入口。
- 出错会怎样:最坏是有 AI 的人看不到这个入口或首页落到下一项,数据不受影响;直接撤回本 PR 即恢复原状。
- 要你做什么:无。
## What changes
- **The gate** (`useNavMemberGates.ts`, `useNavVisibilityAndReads`):
every navigation surface builds its `visible` evaluator here: the
sidebar (and so the phone's app menu it draws), the app-root landing,
the command palette and the `nav:menu` block. An `ai:chat` entry (`type:
'component'`, `componentRef: AI_CHAT_COMPONENT_REF`) is drawn only when
`useAiSurfaceEnabled` answers `enabled`, the access-filtered agent
catalog, which is empty on a deployment with no AI and for a member with
no AI seat.
- **Loading phase, chosen and pinned:** until the catalog answers, the
entry is hidden and `readEntry` reports it as `pending`. That reuses the
landing's existing pending-read hold (objectui#13097), so the app root
shows its skeleton and lands once, either on the page or on the next
entry. It never opens one and then jumps to the other. The sidebar never
draws the entry and then removes it.
- **Declared `landing`** (ruling record 6545223246, letter A) is
unchanged. `resolveDeclaredLandingRoute` looks the named entry up among
the entries the member is shown, so a landing entry whose `item` is the
gated `ai:chat` entry is passed over: the next declared entry that holds
lands, and with none, the first entry shown lands. Both are pinned.
- **A direct link** to `component/ai/chat` is not gated. The page draws
`AiUnavailable`.
- **Asked only when needed:** the catalog is read only while an app in
the list (or the gated app) carries an `ai:chat` entry, through a new
optional `useAiSurfaceEnabled({ enabled })`. Apps without one read
nothing new (pinned: no request).
- **Prerequisite fix, latch:** `useAgents` (`@object-ui/plugin-chatbot`)
now returns `settled`, true once a catalog read for the current
`apiBase` has answered or failed. It is additive, and the fields it
already returned are unchanged. `useAiSurfaceEnabled` reads it instead
of `fetchStartedRef`. See Acceptance notes.
- Changeset: `.changeset/37833-hide-ai-chat-entry-without-agent.md`
(patch, `@object-ui/app-shell` and `@object-ui/plugin-chatbot`).
### Read first (by risk)
1. `ui/packages/app-shell/src/hooks/useAiSurface.ts`: the latch now
reads `settled`. Every `useAiSurfaceEnabled` consumer reads its
`isLoading` through this line.
2. `ui/packages/app-shell/src/hooks/useNavMemberGates.ts`:
`useNavVisibilityAndReads`, the `aiChat` term in `evaluate` and in
`readEntry`.
3. `ui/packages/plugin-chatbot/src/useAgents.ts`: `settledFor` set in
the read's `.finally`.
### Two-minute verification
`pnpm --dir ui exec vitest run
packages/app-shell/src/console/__tests__/AppContent.aiChatEntryGate-37833.test.tsx`:
expect 13 passed, including the community-edition and no-seat home cases
whose router pathname log is exactly `/apps/policy`,
`/apps/policy/crm_case`.
## Tests
- `AppContent.aiChatEntryGate-37833.test.tsx` (new): real `AppContent`
landing, real `ExpressionProvider`, `MePermissionsProvider`,
`useNavMemberGates`, `useAiSurfaceEnabled`, `useAgents` over a held
`apiFetch`, and the real `AppAskPage`. The cases:
- the menu leaves the entry out on community edition (agents route 404)
and with no seat (empty catalog);
- CONTROLs: a member with an agent sees the entry, and an app list with
no `ai:chat` entry fetches nothing;
- the home is the next entry on both, with no stop on the page, and with
an agent the home is the page with no stop on the next entry;
- the two declared-landing cases;
- the direct link draws `AiUnavailable`;
- three warm-cache cases mounted with React's act environment off.
- `useAiSurface.warmCatalog-37833.test.tsx` (new): the hook on a cold
read, then on a warm one, with act off.
- `useAgents.settledWarmCache-37833.test.tsx` (new): `settled` on a cold
read, a warm read, a failed read and a disabled read, with act off.
- `useAiSurface.test.ts`: its mocked `useAgents` result now carries
`settled`, plus one case for a settled empty answer.
- `HomePage.openMarksRead.test.tsx`: its `useAiSurface` mock now also
answers `useAiSurfaceEnabled`. The Home bell's roster gates navigation
through `useNavMemberGates`, so the old mock went red here (a stale
fixture caused by this change; it was the only red in the wide run
below).
## Acceptance notes
- **Latch defect, fixed here (not filed):** with an empty catalog
answered from `useAgents`' module cache (30 s TTL), `isLoading` went
true and false within one render. `useAiSurfaceEnabled`'s
`fetchStartedRef` latch was never set, so it reported loading for ever.
Two effects for a member with no seat after the console's first catalog
read: the `ai:chat` page on a direct link stayed on its blank loading
state instead of `AiUnavailable` (a defect on `main` since the page
landed), and this PR's gate would have held the app-root landing for
good. Measured outside act; the pins below fail on the pre-fix code and
pass after.
- The app-root warm-cache landing case passes on the pre-fix code too,
in this harness: the console's other renders in that window flush the
loading render. The hook-level and page-level pins are the
discriminating ones.
- A catalog that serves agents but not `ask` still shows the entry. The
gate follows `enabled`, the same value the page's own unavailable check
reads, and the page's `AiUnavailable` covers it.
- An app whose only entry is `ai:chat` shows a member with no agent the
existing no-access empty state, the landing's rule for an app that shows
them nothing.
- `useAiSurface.ts` is also edited by #37924 (draft); the two merge
cleanly, and this edit is kept to the latch and the `enabled` option.
## Verification
All runs are on head `4ca23ec3` unless noted. The `check:*` list ran at
`ce385345`; the one later commit changes only a test mock, and the four
gates that read test files were re-run on `4ca23ec3`.
<details><summary>New and touched pins: 19 passed, and 5 of them red on
the pre-fix code</summary>
- `vitest run` over `useAgents.settledWarmCache-37833`,
`useAiSurface.warmCatalog-37833` and `AppContent.aiChatEntryGate-37833`
(`ce385345`): Test Files 3 passed (3), Tests 19 passed (19).
- **Reverse check.** `useAgents.ts` and `useAiSurface.ts` were put back
to their `868742bf` content in the working tree only (`settled` hits
0/0, latch hits 3). Result: Tests 5 failed, 14 passed (19). The five red
cases are useAgents (a), (b) and (c), the hook's warm-catalog case, and
the page's warm direct link. Restored with `git checkout HEAD`; `git
diff HEAD` empty; both blobs equal to HEAD.
- **Gate ablation** (`node scripts/ablation-replace.mjs` at `868742bf`;
anchor hits 1 to 0): the `aiChat` term of `evaluate` was replaced by
`true`. Result: Tests 8 failed, 4 passed (12). Restored blob equal to
HEAD, `git diff HEAD` empty.
</details>
<details><summary>Wide run and type-check</summary>
- `vitest run` over `packages/plugin-chatbot/` and app-shell's `hooks/`,
`console/`, `layout/`, `chrome/`, `views/__tests__/` and `providers/`
(`ce385345`): Test Files 1 failed, 807 passed (808); Tests 3 failed,
7025 passed (7028). The failing file was `HomePage.openMarksRead` (`No
"useAiSurfaceEnabled" export is defined on the mock`), repaired in
`4ca23ec3`, where it shows Tests 3 passed (3).
- This run is a declared narrowing of app-shell's suite; `Test UI` runs
all of it in CI.
- `pnpm --filter @object-ui/app-shell --filter @object-ui/plugin-chatbot
run type-check`: both Done, and `pnpm --dir ui exec vitest run scripts/`
gave Test Files 172 passed, 2 skipped. Lock VERDICT command-exit 0.
</details>
<details><summary>Derived gates (dispatch-gates --commands, 39
families)</summary>
- 38 `check:*` and script families: every one ended with exit 0, except
`check:type-check-debt`. Its first run exited 3 while it was queued
behind the verification lock; the re-run exited 0 (`--re-measure: OK`,
surplus none).
- `pnpm --dir ui exec vitest run scripts/`: passed (above).
- Reconciliation: `dispatch-gates --ran` printed 39 derived, 39 run, 0
NOT-MEASURED, 0 UNRUN.
- Re-run on `4ca23ec3`: `check:nul-bytes`, `check:test-source-alias`,
`check:cross-package-test-inputs` and `check:undeclared-dep-imports` all
exit 0.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4cwGVgec21LwQTtRY85
---------
Co-authored-by: Claude <noreply@anthropic.com>
feat(app-shell): the `ai:chat` menu entry is hidden from a member who cannot get an agent, and the app's home falls to the next entry
7
+
8
+
Clause-②: no
9
+
Metadata-protocol: none
10
+
11
+
An app's AI inquiry entry (`type: 'component'`, `componentRef: 'ai:chat'`) is now shown only to a member the access-filtered agent catalog (`GET /api/v1/ai/agents`) serves at least one agent. On a deployment with no AI, or for a member with no AI seat, the entry is left out of the sidebar, the phone's app menu, the command palette and the `nav:menu` block. If it was the app's home, the home is the next entry the member is shown.
12
+
13
+
-**A declared `landing`** still comes first. A landing entry whose `item` is the `ai:chat` entry is passed over for such a member, like any entry the member is not shown: the next declared entry that holds lands, and with none the first entry shown lands.
14
+
-**While the catalog is loading** the entry is not drawn, and the app root waits on its loading skeleton instead of opening the page or the next entry. It lands once the catalog answers, so the home never opens one page and then jumps to another.
15
+
-**A direct link to the page** is not redirected. The page draws its "AI assistant unavailable" state.
16
+
- The catalog is read only while an app in the list carries an `ai:chat` entry. Apps without one read nothing new.
17
+
-`useAiSurfaceEnabled` takes an optional `{ enabled }` and no longer reports loading for ever when the catalog is empty and is answered from the session cache. Before, a member with no seat who opened the `ai:chat` page after the console had read the catalog saw a blank loading page and never the unavailable state.
18
+
-`@object-ui/plugin-chatbot`: `useAgents` returns `settled`, true once a catalog read for the current `apiBase` has answered or failed. The fields it already returned are unchanged.
0 commit comments