Repository navigation
Commit e50ab8f
feat(app-shell): an app's AI inquiry page (ai:chat) — home state, conversation, drawer closed there (#37889)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D71daFMSfEFsgPq1ECrMYCy)_
Fixes #37788
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 是什么:平台通用的「AI 问询」页面上线。应用在菜单里放一个 `ai:chat` 入口(按应用现有的首页规则:没声明 landing
时,电脑上放第一位就是首页;手机上应用首页是菜单),进来先看到应用配置的欢迎语、大输入框和推荐问题;提问后同一页变成对话,刷新能恢复。
- 为什么:落地 ADR-0057 修订 A4(#37825
已合)。以前这个入口会显示「组件未注册」;现在有页面,而且这一页上右上角机器人隐藏、快捷键无效,不会出现两个对话。
- 出错会怎样:只影响菜单里放了 `ai:chat` 的应用;其他页面抽屉照旧。没开 AI 或没席位的人看到现有的「AI 助手不可用」页。
- 要你做的:无,区内复审后交座位。
## What changes
The `ai:chat` component ref (`AI_CHAT_COMPONENT_REF`,
`@objectstack/spec/ui`) gets its page, per ui ADR-0057 Amendment A4 as
merged in #37825.
- **`console/ai/AppAskPage.tsx`** (new, +370) — the page, registered
lazily in `services/builtinComponents.tsx` (`registerAppComponent` +
`lazyPage`, so it stays out of the eager closure; the console build's
declared-lazy check passes). Home state: title, subtitle, placeholder
and up to four suggestions from the entry's `params`, read through
`AiChatNavParamsSchema`; a key the entry omits falls back to neutral
platform copy, and nothing is read from the URL. A static badge,
「Answers prefer this app」. Enter sends, Shift+Enter and IME composition
do not. The first question turns the same page into the conversation:
the existing `ChatPane` (header hidden) on the `ask` agent, a maker
included, bound to the app's package (`activeAppPackageId`), under the
conversation key `app:PKG:ask`. The first message is held and replayed
by the pane's existing deferred-first-send path, so the conversation row
is created on first send.
- **`?c=ID`** — once the conversation exists the address carries it
(`replace`), so a reload restores it. A `?c=` the page did not create is
checked with the existing `GET /conversations/:id`: one whose
`metadata.activePackageId` is not this app's package, or one that is not
the caller's (403/404), opens the home state and is removed from the
address; nothing of it is drawn. 「New conversation」 in the page header
returns to the home state.
- **`console/ai/appAskPageModel.ts`** (new, +128) — the rules without
React: finding the app's `ai:chat` entry (navigation, then
`areas[].navigation`, through `children`), reading its copy (a record
the schema refuses is read as declaring nothing, with one console
warning), the conversation key, the create metadata, and the
belongs-to-this-app test.
- **`hooks/useChatConversation.ts`** — an optional `createMetadata`; the
first-send create sends `{ metadata }` when it is set. Only the page
sets it (`{ activePackageId: PKG }`); every other caller still sends
`{}`. `ServerConversation` gains the `metadata` the GET contract already
returns.
- **Drawer rule, `layout/**`** — `isAppAskPagePath`
(`consoleRoutePaths.ts`) names the page's route; `ConsoleLayout` passes
`askPageActive` to `useConsoleChatDock`. While it holds: the drawer
renders closed (the stored preference is untouched and comes back off
the page), `open()` and the assistant bus are inert, the
Ctrl/Cmd+Shift+I effect is not bound, and `AssistantTopBarButton`
returns `null` (`ChatDockControl.askPageActive`). A build hand-off still
opens the drawer: `open()` with a handoff or a build-agent target passes
(`opensBesideAskPage`), and the drawer stays open until it is collapsed
or the user leaves the page. On a phone, arriving on the page with the
sheet stored open collapses it, so the next page does not bring it back
(the sheet already closes on any move away, #37556); the desktop rail
keeps its stored state.
- **`@object-ui/i18n`** — one key, `console.ai.askPage.scopeBadge`, in
all 11 packs. The other strings reuse existing keys
(`console.ai.empty.ask.*`, `console.ai.askAnything`,
`console.ai.submit`, `console.ai.newConversation`).
- One changeset (`@object-ui/app-shell` and `@object-ui/i18n`, patch).
Not touched: `AiChatPage.tsx`, `ChatbotEnhanced.tsx`, `ui/docs/adr/**`,
`packages/spec/src`.
## Tests
- `console/ai/__tests__/AppAskPage-37788.test.tsx` (11) — the real page,
the real `useChatConversation` over a stubbed `fetch`, the real router
and registry; stand-ins for the agent catalog, the AI gate, app
metadata, `ChatPane` and `AiUnavailable`. It covers: the registry entry;
declared copy; fallback copy; no copy from the URL; a suggestion asks it
(pane on `ask`, bound to the package, the create body `{ metadata: {
activePackageId } }`, the address gains `?c=`); a maker gets `ask`; a
reload restores from `?c=`; another app's conversation opens the home
state and leaves the address; a 403 opens the home state; New
conversation; and the unavailable state.
- `console/ai/__tests__/appAskPageModel.test.ts` — finding the entry,
copy and fallback, the warning on a refused record, the key,
belongs-to-this-app, and `isAppAskPagePath` agreeing with
`componentRefToUrlSegments(AI_CHAT_COMPONENT_REF)`.
-
`layout/__tests__/useConsoleChatDock.phoneCollapseOnNavigate-37556.test.tsx`
(+7, real dock + control provider + top-bar button): the drawer is
closed on the page and back off it; the robot is hidden on the page
only; the toggle chord and `ask` opens are inert on the page; control:
the chord works off it; a build open still opens the drawer; on a phone,
a sheet open on arrival is closed by the page and stays closed on the
next page; on a phone, a build hand-off still opens the sheet.
- `layout/__tests__/ConsoleLayout.askPageHidesEntry-37788.test.tsx`
(new, 2): through the real `ConsoleLayout` wiring, the entry is not
drawn on the `ai:chat` route and is back on another; a drawer open
elsewhere is closed on the route and comes back after it.
- `hooks/__tests__/useChatConversation.test.tsx` (+2): `createMetadata`
reaches the create body; the drawer's create is still `{}`.
- Ablations: with `AssistantTopBarButton`'s `askPageActive` return
removed, "the robot is hidden on the page only" fails; with the
phone-collapse branch disabled, the phone case fails (1 failed / 15
passed); with `ConsoleLayout`'s `askPageActive` set to `false`, both
wiring cases fail. Restored, all pass.
## Acceptance notes
- **Item 10, `context.surface`: not tagged, and why.** A cheap hook does
exist: `ChatPane` takes `surfaceContext` and sends it as
`context.surface`, and the spec's `pillar` is a free advisory string
(`packages/spec/src/contracts/ai-service.ts`, `surfaceContext`). It is
left out because the shape is cloud#1610's, and cloud's agent route
sanitizes it field by field
(`ui/packages/app-shell/src/layout/chatSurfaceContext.ts`, module doc).
Which `pillar` value that sanitizer keeps cannot be read from here: the
cloud repository is out of this seat's reach. So the page sends no value
that cloud might drop, and the console invents no new vocabulary. Evals
can still split these turns: every conversation the page creates carries
`metadata.activePackageId`, which only this page sets. Once cloud names
a value, tagging is a one-prop change on `ChatPane`.
- **Location-state hand-offs.** A `/ai…` address with handoff state that
lands on the page does not open the drawer. Only `open()` with a build
target or a handoff does.
- **Phone root** is out of scope, as the ADR names it.
- **The entry stays hidden after a hand-off opens the drawer on the
page.** That is A4's rule: on the page the triggers are hidden or inert.
The drawer closes with its own control, and reopening it there would put
a second conversation on the page.
- **L1 nits not taken in this delta**, to keep it to the dock hook, the
tests, the changeset and this body. They are: a transient error on the
`?c=` check is read as foreign; the check fetches the full conversation
to read `metadata`; an app with no `_packageId` gets no message;
duplicate suggestions share a React key. Each one touches
`AppAskPage.tsx`.
- **Beyond the order's file list:** the 11 locale packs (one key), the
model module `appAskPageModel.ts`, and four files under `layout/**`
(`consoleRoutePaths.ts`, `chatDockControl.tsx`,
`AssistantTopBarButton.tsx`, `ConsoleLayout.tsx`). ui AGENTS asks for
docs updates (README, `content/docs/frontend`); those are outside this
PR's surface and are left for a follow-up.
- **Overlap:** #37885 (Ask AI entry button) rewrites
`AssistantTopBarButton.tsx`, so the two PRs conflict textually there.
The conflict is one early return plus a doc line: `if
(control?.askPageActive) return null;` goes at the top of the rewritten
component. With #37885, the entry also appears in page headers, and this
return hides it on the page too. Whichever PR lands second rebases. With
`origin/main` and #37676 this branch merges cleanly.
## Verification
- At `df8d6f75`: `pnpm exec vitest run` of the AppAskPage, dock, the two
ConsoleLayout and the model/conversation test files: all green
(AppAskPage 11/11, dock 16/16, ConsoleLayout wiring 2/2, robot 2/2).
`app-shell` type-check, both programs: exit 0. eslint on the changed
files: 0 errors.
- The derived gates (`dispatch-gates --ran`: 41 of 41 run), plus the
i18n keys, drift, dead-keys, all-locales parity, product-neutral
ratchet, eslint on the changed files and `check:new-line-citations`: all
exit 0 (re-read after the L1 delta: the changeset gates,
`check:test-source-alias`, cross-package test inputs, the timer probe,
ceremony text, the role word and new-line citations, all exit 0).
`check:test-source-alias` first flagged that the two edited test files
reach `AiChatPage`'s lazy `import('@object-ui/plugin-grid')`; fixed by
loading it at module top, as the gate prescribes.
- Full `pnpm build`: exit 0.
- **Browser** (showcase app, `pnpm dev --fresh`, console on Vite): an
`ai:chat` entry was injected first in `showcase_app`'s navigation
through a Playwright route on `/api/v1/meta/app`, with no source edit.
`/api/v1/ai/**` was stubbed, since OSS has no AI. Results:
- The home state draws the declared copy, the badge and four
suggestions.
- `?c=conv-1` restores the conversation (user question plus a markdown
answer) with 「New conversation」 in the header.
- The top-bar Ask AI entry counts 0 on the page and 1 on the Capability
Map page.
- Screenshots, at 1440×900 @2x, of the home state and the restored
conversation, are kept with the project. The relay cannot upload images.
Both were viewed at L1 (comment 7215194705).
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4czF5gqc48r9LUsmRpw)_
<!-- signed: repo:objectstack#1 · os-elon-musk ·
session_016WV4czF5gqc48r9LUsmRpw -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 0a3ea67 commit e50ab8f
26 files changed
Lines changed: 1311 additions & 15 deletions
File tree
- .changeset
- ui/packages
- app-shell/src
- console/ai
- __tests__
- hooks
- __tests__
- layout
- __tests__
- services
- i18n/src/locales
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
0 commit comments