Repository navigation
Commit f926dfa
refactor(app-shell): split AiChatPage into ChatPane and helper modules, move-only (#37803)
<!-- claude-projects-attribution: {"github_login":"hotlong"} -->
_Requested by **Jack** · [project
thread](https://claude.ai/code/project/chan_01EF41AQooqveF2DGD8nqPzS?thread=cmsg_01EF41AQooqveF2DGD8nqPzS5ABkjZhavN8ufqbqE2sRDe)_
Fixes #37730
## 维护者速读
- 用户看到的变化:没有。全页 AI 对话和侧边停靠的对话照常工作,只是代码换了文件放。
- 为什么:`AiChatPage.tsx` 删完 build 后还有 2152 行,后续对话界面改进都要改它,先拆开减少冲突。
- 出问题会怎样:只搬代码不改逻辑,最坏是某个导入断了,类型检查和测试会直接红;回滚这一个合并即可。
- 需要你做的:改动行数 3305(搬家导致增删各一遍)超过 3000 行的人合门槛,按规定需要你点批准或亲手合并;其余照席位流程走。
## What changes
`ui/packages/app-shell/src/console/ai/AiChatPage.tsx` goes from 2152 to
652 lines. It keeps `AiChatPage`, `AiChatPageProps`,
`EMPTY_INITIAL_MESSAGES`, the `useHomePath()` call and the top bar
`<header>`. Everything else moves byte for byte into six modules in the
same directory:
| New module | What moved |
|:---|:---|
| `ChatPane.tsx` | `ChatPane`, `ChatPaneProps` |
| `aiChatHydration.ts` | `hydratedMessagesToChatMessages`,
`partToolState`, `partApproval`, `partString`, `firstUserMessageText` |
| `aiChatLinks.ts` | `listLinkTarget`, `recordOpenTarget`,
`nextSectionOpening` and the module counter `sectionOpenings` |
| `useDeferredFirstSend.ts` | `PendingFirstMessage`,
`useDeferredFirstSend`, `isSameFile`, `isSameFirstSend`,
`useComposerDraftHandoff`, `ComposerDraftHandoff`, the module
`composerDraftHandoffs` WeakMap |
| `aiChatChrome.ts` | `matchAiChatShortcut`, `AiChatShortcut`,
`TOGGLE_CHATS_LIST_SHORTCUT`, `NEW_CHAT_SHORTCUT`,
`useCollapsibleChatsList`, `CollapsibleChatsList`,
`CHATS_COLLAPSED_STORAGE_KEY`, `resolveCollapseToDockTarget` |
| `agentCopy.ts` | `agentEmptyState`, `localizeAgentLabel`,
`PLATFORM_AGENT_LABEL_KEYS`, `buildAgentSuggestions`,
`genericSuggestions`, `dataChatSuggestions`, `TranslationFn` |
- Every name `AiChatPage.tsx` exported is re-exported from it by name
(`export { … } from`, `export type { … } from`; no `export *`), so every
import path stands. `ChatDockConversation.tsx` still imports `ChatPane`
from `AiChatPage.js`, so the four ChatDock tests that mock that path,
and the dock's `React.lazy` boundary, are unchanged.
- `ui/packages/app-shell/src/index.ts`,
`ui/packages/plugin-chatbot/src/index.tsx` and
`ui/packages/plugin-chatbot/src/core.ts` are untouched.
- The two module-level singletons (`sectionOpenings`,
`composerDraftHandoffs`) exist once, in their new modules.
- No new module imports `AiChatPage.tsx`. The graph is `AiChatPage →
ChatPane → {aiChatLinks, aiChatHydration, agentCopy,
useDeferredFirstSend}`, plus `AiChatPage → {aiChatChrome,
aiChatHydration, useDeferredFirstSend}`.
- Three helpers that were file-private now cross a module boundary and
gained `export` in their new module: `nextSectionOpening`,
`firstUserMessageText`, `localizeAgentLabel`. They are not re-exported
from `AiChatPage.tsx`, because they were never exported from it.
### What is not a moved line
Apart from moved lines, the diff is only: import lists, the re-export
block, a short header comment on each new module, and the three `export`
keywords above. Checked by comparing the multiset of removed lines with
the multiset of added lines over `console/ai/*.ts(x)`: everything left
over on either side is one of those kinds. The import of
`ChatbotEnhancedMessage as ChatMessage` keeps its long comment in
`aiChatHydration.ts`, the file that produces those messages;
`ChatPane.tsx` carries a two-line pointer to it.
```
git diff --color-moved=zebra --stat origin/main...HEAD
.changeset/37730-ai-chat-page-split.md | 10 +
.../homeRecoveryRedirectsFollowDeclaration-7373.test.ts | 10 +-
ui/packages/app-shell/src/console/ai/AiChatPage.tsx | 1618 +-----
ui/packages/app-shell/src/console/ai/ChatPane.tsx | 869 ++++
.../ai/__tests__/AiChatPage.runtimeMessageSeam.test.tsx | 5 +-
ui/packages/app-shell/src/console/ai/agentCopy.ts | 82 +
ui/packages/app-shell/src/console/ai/aiChatChrome.ts | 131 +
ui/packages/app-shell/src/console/ai/aiChatHydration.ts | 195 +
ui/packages/app-shell/src/console/ai/aiChatLinks.ts | 52 +
ui/packages/app-shell/src/console/ai/useDeferredFirstSend.ts | 333 ++
10 files changed, 1716 insertions(+), 1589 deletions(-)
```
### Tests
Only the two read-scope changes the card allows; no assertion changed:
1. `console/ai/__tests__/AiChatPage.runtimeMessageSeam.test.tsx`, the
"#4437 source net": reads `AiChatPage.tsx` and `ChatPane.tsx` joined,
since `const runtimeMessages = useMemo(() =>
toRuntimeMessages(messages), [messages]);` now lives in `ChatPane`.
2. `__tests__/homeRecoveryRedirectsFollowDeclaration-7373.test.ts`: the
AiChatPage site lists the six new modules under its existing
`alsoReads`.
## Why
Card #37730 under epic #37690 (split C). The plan was reviewed against
the code before the card was filed. Behaviour does not change; this only
makes the next AI chat changes conflict less and review smaller.
## Verification
Clause-②: no
Metadata-protocol: none
Read first: the re-export block at the top of `AiChatPage.tsx`, then
`ChatPane.tsx`'s import list.
Two-minute check: `pnpm --dir ui exec vitest run
packages/app-shell/src/console/ai/__tests__/AiChatPage.runtimeMessageSeam.test.tsx
packages/app-shell/src/__tests__/homeRecoveryRedirectsFollowDeclaration-7373.test.ts`.
<details><summary>Local readings (objectstack-ai/objectstack, branch
head on main 6e8f663)</summary>
- `tsc --noEmit` in `ui/packages/app-shell`, `tsconfig.json` and
`tsconfig.test.json`: exit 0.
- `eslint --quiet packages/app-shell/src/console/ai/` plus the 7373
test: exit 0. Without `--quiet`, the warnings over the page and the six
modules are 16, against 18 on the page before the split
(`react-refresh/only-export-components` 13 → 11; the rest unchanged).
- vitest over `console/ai/`, `layout/__tests__/`,
`KeyboardShortcutsDialog.wiredOnly-11674`, `useChatConversation`,
`homeRecoveryRedirectsFollowDeclaration-7373` and i18n
`console-namespace-3546`: 203 files, 1768 tests passed.
- `pnpm console:build`: exit 0. `pnpm --dir ui check:eager-closure`:
exit 0; the eager closure's only chat chunk is `plugin-chatbot-core`;
`@object-ui/plugin-chatbot`, `ChatDockConversation` and the split
modules stay lazy. In this build the shared lazy chunk that holds
`useChatConversation` takes its name from `aiChatHydration` (rolldown's
naming pick, not a membership change the budget gate saw).
- dispatch-gates: all 38 derived commands ran and exit 0;
`dispatch-gates --ran` reconciles 38 of 38, 0 NOT-MEASURED.
- `overlap-check`: merges cleanly with `origin/main`; no open PR shares
a file.
- The full ui suite was not run locally (it does not finish in this
container); CI's sharded Test UI is the verdict.
</details>
## Acceptance notes
- Size: 3305 changed lines (+1716 / -1589), over the 3000-line
threshold, so this lands the Tier H way (an authorized approval, or the
maintainer's merge or enqueue), although the change is move-only.
- `react-refresh/only-export-components` warnings over the page and the
six modules drop from 13 to 11, because the non-component exports left
the page file; no new lint warning class appears.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [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: its generated artifacts are
regenerated and committed. (Not touched.)
- [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)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 754e216 commit f926dfa
10 files changed
Lines changed: 1715 additions & 1588 deletions
File tree
- .changeset
- ui/packages/app-shell/src
- __tests__
- console/ai
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
134 | 142 | | |
135 | 143 | | |
136 | 144 | | |
| |||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
301 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
302 | 305 | | |
303 | 306 | | |
304 | 307 | | |
| |||
| 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 | + | |
| 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 | + | |
0 commit comments