Repository navigation
Commit d8d0791
feat(plugin-chatbot): the chat draws a confirm card for a package removal (#32028)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBGKmJknJnqwh1BakWHY3yHx)_
Fixes #31025
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 改了什么:AI 聊天里,助手发起「删除软件包」时,不再只显示通用的「批准 / 拒绝」和一段
JSON,而是一张确认卡:列出每个对象及其记录数(草稿对象写明尚无数据表,数不出来的写明无法获取,都不显示成
0)、其他元数据按类型计数、总记录数(有对象数不出来时注明总数偏少),并在删表时用红字写明表会被永久删除、不进回收站;保留数据时写明表和记录都保留。批准后卡片写明已删除或部分删除(几项未能移除)。
- 为什么改:这是 #31025 的第二半(第一半 Studio 删除对话框已在 #31193 合并)。cloud 的
`delete_package` 工具(cloud#3686)已经返回 `packageRemoval`
清单,聊天却画不出来,cloud#3656(p1)卡在这里。
- 风险与回滚:只改前端渲染和文案;批准 / 拒绝仍走原来的
`/api/v1/ai/pending-actions/:id/{approve,reject}`,卡片不回传任何东西。没有
`packageRemoval` 的结果完全不受影响。回滚即还原本 PR。
-
先看:`ui/packages/plugin-chatbot/src/mapMessages.ts`(`detectPackageRemoval`:`rows`
缺失保持缺失、不当
0)、`ui/packages/plugin-chatbot/src/ChatbotEnhanced.tsx`(`data-testid="package-removal"`
那一块,`data === 'dropped'`
才画永久删除行)、`ui/packages/app-shell/src/console/ai/AiChatPage.tsx`(标签接线和刷新后的复原)。
- 两分钟验证:`pnpm --dir ui exec vitest run
packages/plugin-chatbot/src/__tests__/recordWrite-3565.test.ts
packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.recordWriteCard-3565.test.tsx`,预期
39 个用例全绿,其中「the package-removal card (objectstack#31025)」一组 10 个。
- 需要你做的:无,席位落地。
## What changes
The chat draws a confirm card for cloud's `delete_package` pending
action, built on the shape the `repo:cloud` lane put on #31025 (comment
6754040588, read at cloud `d6288d27`; tool from cloud#3686) and nothing
beyond it.
- **Parser** (`ui/packages/plugin-chatbot/src/mapMessages.ts`):
`PackageRemoval` / `PackageRemovalObject` and
`detectPackageRemoval(result)`, beside `detectSampleDataCleanup` and
built on `detectPendingApproval`. An envelope without `pendingActionId`
or without a `packageRemoval` object is not a card, so a refusal
(`success: false`) and the MCP door's `status: 'confirmation_required'`
draw none. Counts are normalised to non-negative whole numbers; an
object's `rows` that is absent (or not a usable number) stays absent,
never `0`; `totalRows` falls back to the sum of counted rows. The live
mapper carries it on the tool invocation like `sampleDataCleanup`, and
`AiChatPage`'s hydration mapper lifts it too, so the card survives a
reload. `detectPackageRemovedResult` reads the approved outcome
(`PackageRemovedResult`: `removed` or `partial` with the `failed`
count).
- **Card** (`ChatbotEnhanced.tsx`, a `packageRemoval` block beside the
`sampleDataCleanup` one, above the generic Approve / Deny strip, which
stays the decision): the package label in the title; each object with
its record count, a draft saying it has no table and an uncounted object
saying its count is unavailable (neither draws a number); the other
items by type from `items`; the total, plus a line when
`uncountedObjects > 0` that the total leaves those objects out; when
`data === 'dropped'` a destructive line that the tables are dropped
permanently and do not go to the recycle bin, and when `data === 'kept'`
a line that the tables and their records are kept. The raw pending
payload stays hidden, as for the sample-data card.
- **Outcome**: measured first. On an approved pending action the chat's
generic decision strip says "Approved — action executed." whatever the
result (`useHitlInChat` sets that text and keeps the result aside), so a
partial removal would read as fully executed. The card now adds one
line: removed, or partly removed with the number of items not removed.
Nothing larger.
- **Labels**: `packageRemoval*Label` props with English defaults, wired
from `AiChatPage` to new `console.ai.packageRemoval*` keys in every
`@object-ui/i18n` pack (zh-Hant through `gen:zh-hant`). Wording reuses
Expected 1's studio strings where the fact is the same ("Record count
unavailable", the permanent-drop sentence); type names come from the
same `translateMetadataType` table the Studio Delete package dialog
uses.
No server, `packages/spec/**` or cloud change: the payload is a
tool-result string the chat already parses.
## Tests
Both in the existing cloud#3565 harness files, each as a new top-level
`describe` (AGENTS.md: a new pin for a component that already has a
shared harness goes into that file).
- `recordWrite-3565.test.ts`: a full envelope maps (bare and
persisted-wrapper shapes); an absent `rows` stays absent while a real
`0` stays `0`; no `pendingActionId`, no `packageRemoval`, a refusal and
`confirmation_required` each map to undefined; defensive normalisation;
the live mapper lifts it beside the pending id; the outcome parser reads
`removed` / `partial` and nothing else.
- `ChatbotEnhanced.recordWriteCard-3565.test.tsx` (real mapper, real
component): objects, counts, items and total render and the generic
decision fires `onToolApprove('c1', true)`; a draft and an uncounted
object draw no digit; the permanent line renders for `dropped` (CONTROL:
`kept` draws the kept line and no permanent line); the short-total line
renders only when `uncountedObjects > 0` (CONTROL: all counted, no
line); a refusal draws no card; an approved removal says removed, a
partial one names the failed count, a rejection draws no outcome.
## Acceptance notes
- `Clause-②: yes (widening)`, measured on the diff: the published
`@object-ui/i18n` catalogue gains the `console.ai.packageRemoval*` keys
and changes none; `@object-ui/plugin-chatbot` gains exports and optional
props. The claim wrote `Clause-②: yes` without an arm; the order named
`(widening)`.
- `@object-ui/app-shell` is private, so the changeset names
`@object-ui/plugin-chatbot` and `@object-ui/i18n` only.
- eslint over the touched source files: 0 errors; `index.tsx` carries
one more `react-refresh/only-export-components` warning than on `main`
(the new `detectPackageRemoval` re-export, the same rule its siblings
already trip).
- Neither `plugin-chatbot`'s README nor `content/docs/frontend/`
documents the sibling chat cards (record write, sample-data cleanup), so
no doc page gained a section here.
- No browser leg: the agent runtime behind `/api/v1/ai/**` is not in
this repository, so the card is pinned through the real mapper and
component; the staging reading is cloud#3656's done-when.
## Verification
Head: `8d83e7c7` (the fix `44a35169`, the changeset `226b1310`,
`origin/main` `bf40cc1f` merged; nothing it brought touches these
packages). Readings on the shared box under
`scripts/pm/os-verify-lock.sh`, each exit taken from the lock's
`VERDICT` line.
<details><summary>Tests and type-check</summary>
- `pnpm --dir ui exec vitest run
packages/plugin-chatbot/src/__tests__/recordWrite-3565.test.ts
packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.recordWriteCard-3565.test.tsx`:
Test Files 2 passed (2), Tests 39 passed (39), VERDICT command-exit 0
(after the `@object-ui/app-shell^...` closure build, VERDICT 0).
- `pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-chatbot/
packages/i18n/`: Test Files 195 passed (195), Tests 2752 passed, 13
skipped, VERDICT 0.
- Every app-shell test file that names `AiChatPage` (54 files): Test
Files 54 passed (54), Tests 417 passed, VERDICT 0.
- `pnpm --filter @object-ui/plugin-chatbot --filter @object-ui/i18n
--filter @object-ui/app-shell run type-check` (each `tsc --noEmit` plus
its `tsconfig.test.json`, which compiles the harness files): all three
Done, VERDICT 0.
- `ui` `check:i18n-keys`, `check:i18n-drift` (18 en keys added, 0 en
values changed), `check:i18n-dead-keys` (no `packageRemoval` key
listed), `check:new-line-citations` (0 new): exit 0. `node
scripts/check-sdui-manifest.mjs`: exit 0.
</details>
<details><summary>Ablations (scripts/ablation-replace.mjs, each anchor
hit once, each restored with git diff HEAD empty)</summary>
- The permanent line ignores `data` (`tool.packageRemoval.data ===
'dropped'` replaced by `true`): "CONTROL: kept data draws the kept line
and no permanent line" red, 1 failed, 20 passed; restored, blob equals
HEAD `c1b46b73`.
- A missing `rows` read as `0` (the conditional spread replaced by
`rows: rows ?? 0`): four tests red ("lifts the plan…", "keeps an absent
row count absent, never 0", "normalises counts defensively…", and the
card's "a draft object … neither draws a number"), 4 failed, 35 passed;
restored, blob equals HEAD `f3e880ee`.
- `ui` vitest resolves `plugin-chatbot` from source and the harness
imports `../mapMessages` directly, so no dist preflight sits on these
paths.
</details>
<details><summary>Derived gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` at `8d83e7c7`: 40 families, each run with
its exit captured before any pipe, all 40 exit 0. `--ran`: "40 derived
famil(ies) accounted for — 40 run, 0 NOT-MEASURED". CI families are read
from this PR's check-runs, not re-run locally.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzfqZRktLWvgfHqWsyA)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent fa4cb68 commit d8d0791
18 files changed
Lines changed: 802 additions & 4 deletions
File tree
- .changeset
- ui/packages
- app-shell/src/console/ai
- i18n/src/locales
- plugin-chatbot/src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| 71 | + | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
| |||
292 | 294 | | |
293 | 295 | | |
294 | 296 | | |
| 297 | + | |
295 | 298 | | |
296 | 299 | | |
297 | 300 | | |
| |||
342 | 345 | | |
343 | 346 | | |
344 | 347 | | |
| 348 | + | |
345 | 349 | | |
346 | 350 | | |
347 | 351 | | |
| |||
1764 | 1768 | | |
1765 | 1769 | | |
1766 | 1770 | | |
1767 | | - | |
| 1771 | + | |
1768 | 1772 | | |
1769 | 1773 | | |
1770 | 1774 | | |
| |||
2768 | 2772 | | |
2769 | 2773 | | |
2770 | 2774 | | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
2771 | 2788 | | |
2772 | 2789 | | |
2773 | 2790 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2268 | 2268 | | |
2269 | 2269 | | |
2270 | 2270 | | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
2271 | 2305 | | |
2272 | 2306 | | |
2273 | 2307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2037 | 2037 | | |
2038 | 2038 | | |
2039 | 2039 | | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
2040 | 2058 | | |
2041 | 2059 | | |
2042 | 2060 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2764 | 2764 | | |
2765 | 2765 | | |
2766 | 2766 | | |
| 2767 | + | |
| 2768 | + | |
| 2769 | + | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
2767 | 2785 | | |
2768 | 2786 | | |
2769 | 2787 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2097 | 2097 | | |
2098 | 2098 | | |
2099 | 2099 | | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
2100 | 2122 | | |
2101 | 2123 | | |
2102 | 2124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2093 | 2093 | | |
2094 | 2094 | | |
2095 | 2095 | | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
2096 | 2118 | | |
2097 | 2119 | | |
2098 | 2120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2039 | 2039 | | |
2040 | 2040 | | |
2041 | 2041 | | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
2042 | 2060 | | |
2043 | 2061 | | |
2044 | 2062 | | |
| |||
0 commit comments