Repository navigation
Commit b3c3acd
feat(app-shell): send the console UI language as context.uiLocale on the AI chat request (#34845)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBNgJrQDxaUNx2so1ektgf6A)_
Fixes #34639
Clause-②: no
Metadata-protocol: none
## 维护者速读
- **改了什么**:AI 对话请求的 `body.context` 新增
`uiLocale`,值为控制台当前解析出的界面语言(`useObjectTranslation().language`),其余字段不变。
- **为什么改**:服务端此前只看得到浏览器的 `Accept-Language`,中文提问 +
英文控制台时,回复让用户点「开始搭建」,而计划卡按钮显示的是 "Build it";cloud PR #4815 的
`consoleUiLocaleOf` 读这个键来选按钮文案。
- **风险与回滚**:风险低,只是请求体多一个字符串键,服务端自行校验、不认识就丢弃;回滚即 revert 本
PR,服务端退回按回复语言选文案(今天的行为)。
-
**先看**:`ui/packages/app-shell/src/console/ai/AiChatPage.tsx`(`useObjectChat`
的 `body.context` 末尾新增的 `uiLocale: language`
一行);`ui/packages/app-shell/src/console/ai/__tests__/AiChatPage.uiLocale-34639.test.tsx`。
- **两分钟验证**:`pnpm --dir ui exec vitest run
packages/app-shell/src/console/ai/__tests__/AiChatPage.uiLocale-34639.test.tsx`,预期
5 个测试全部通过。
- **需要你做的**:无,席位落地。
## What changes
- `ChatPane` (`AiChatPage.tsx`) already read `const { t, language } =
useObjectTranslation()`. The `useObjectChat({ body: { context } })` call
now adds `uiLocale: language` beside `activeApp`, `agentName`,
`autoPublishAiBuilds`, `packageId` and `surface`. The value is sent as
is; there is no client-side normalisation, because the consumer
(objectstack-ai/cloud PR #4815, `consoleUiLocaleOf`) validates it.
- Console dock: read `ui/packages/app-shell/src/layout/ChatDock.tsx` and
`ChatDockConversation.tsx`. The dock does not build its own chat
request. It mounts the same `ChatPane`, so this one change covers the
dock too. No dock file is edited. The only non-test `useObjectChat(`
call sites under `ui/packages` are `AiChatPage.tsx` and the SDUI
`plugin-chatbot` renderer, which is not the console's AI chat.
- Changeset: `.changeset/34639-ai-chat-ui-locale.md`,
`@object-ui/app-shell` patch.
## Tests
New file `AiChatPage.uiLocale-34639.test.tsx`. It renders `ChatPane`
with a real `I18nProvider` and with `useObjectChat` replaced by an
options recorder, the same harness as
`AiChatPage.surfaceChipLabel-8219.test.tsx`. The expected value is read
from a probe under the same provider, so the pin does not depend on how
the provider spells a tag. It checks:
1. `en` / `zh` / `de` consoles: `context.uiLocale` equals the resolved
UI language (non-empty string).
2. Chinese thread under an English console versus a Chinese console:
each sends its own console's language, and the two values differ.
3. The rest of the context is unchanged: keys are exactly `agentName`,
`autoPublishAiBuilds`, `uiLocale` for a pane with no app, package or
surface.
No shared ChatPane harness file exists under `console/ai/__tests__/`, so
the pin is its own card-named file.
<details><summary>Targeted run on head 82eed1d (after merging
origin/main dfbc316)</summary>
```
pnpm --dir ui exec vitest run --maxWorkers=2 \
packages/app-shell/src/console/ai/__tests__/AiChatPage.uiLocale-34639.test.tsx \
packages/app-shell/src/console/ai/__tests__/AiChatPage.surfaceChipLabel-8219.test.tsx \
packages/app-shell/src/console/ai/__tests__/AiChatPage.planCardLocale.test.tsx
Test Files 3 passed (3)
Tests 26 passed (26)
pnpm --filter @object-ui/app-shell run type-check (tsc --noEmit && tsc -p tsconfig.test.json)
os-verify-lock: VERDICT command-exit 0
```
</details>
<details><summary>Ablation (fix committed first; mutation through
scripts/ablation-replace.mjs)</summary>
Deleted the line `uiLocale: language,` (anchor 1 -> 0, blob 6e4da2c ->
e6d51027). The test imports `../AiChatPage` from source, so no build
step sits between the mutation and the run.
```
× en console: context.uiLocale is the resolved UI language expected undefined to be 'en'
× zh console: context.uiLocale is the resolved UI language expected undefined to be 'zh'
× de console: context.uiLocale is the resolved UI language expected undefined to be 'de'
× the value follows the console, not the conversation ... expected undefined to be 'en'
× the rest of the context is unchanged beside it expected [ 'agentName', 'autoPublishAiBuilds' ] to deeply equal [ 'agentName', …(2) ]
Tests 5 failed (5)
restore: blob after restore 6e4da2c == blob at HEAD; git diff HEAD empty
```
</details>
## Acceptance notes
- PR #34713, which rewrote `AiChatPage.tsx`, merged before this PR
opened. The branch merged origin/main (dfbc316) cleanly.
`overlap-check` on head 82eed1d reported `VERDICT clean exit 0`
(origin/main merges cleanly, 0 overlapping PR heads).
- The console's own language resolution (browser vs environment default)
is out of scope, as the card says.
## Verification
<details><summary>Local gate families on head 82eed1d (dispatch-gates
--commands, 38 derived)</summary>
- All 38 derived commands exited 0. Exit codes were captured before any
pipe and are recorded per command. They include `pnpm --dir ui exec
vitest run scripts/` (Tests 5077 passed, 2 skipped), `pnpm
check:nul-bytes`, `pnpm check:cross-package-test-inputs`, `pnpm
check:test-source-alias`, `pnpm check:type-check-coverage`, `pnpm
check:type-check-debt`, `node scripts/check-adr-0087-registration.mjs
--base origin/main`, `node scripts/check-empty-changeset.mjs --base
origin/main` and `node scripts/check-sdui-manifest.mjs`.
- `dispatch-gates --ran`: `38 derived famil(ies) accounted for — 38 run,
0 NOT-MEASURED`.
- Extra runs: `pnpm check:changeset-fixed` (its roster sits under
`.changeset/`) exit 0. `pnpm check:new-line-citations` (ui) gave
`VERDICT new-cross-file-line-citations: 0 new citation(s)`.
- Full repo-wide families, the type-check lanes and `test:repo` belong
to CI.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzfrh8TiPJf1i2kMSoa)_
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufzfrh8TiPJf1i2kMSoa -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6e2838c commit b3c3acd
3 files changed
Lines changed: 164 additions & 0 deletions
File tree
- .changeset
- ui/packages/app-shell/src/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 | |
|---|---|---|---|
| |||
2050 | 2050 | | |
2051 | 2051 | | |
2052 | 2052 | | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
2053 | 2057 | | |
2054 | 2058 | | |
2055 | 2059 | | |
| |||
| 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 | + | |
0 commit comments