Repository navigation
Commit bcb7e7f
feat(plugin-chatbot): save an answer as a question, the member's view, or a report / dashboard widget draft, and run saved questions again (#38582)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Jianguo** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbDEm1zkAJG5c8WSuRMDdo6S)_
Fixes #31889
Clause-②: yes
Metadata-protocol: none
## 维护者速读
- 成员在控制台 AI
对话里,可以把一条用数据回答的问题保存下来,或另存为自己的视图、报表草稿、仪表板组件草稿;输入框旁新增"已保存的问题"侧栏,可再次运行看最新结果或删除。
- 属于 AI 问答改进(问数回答的后续动作),接口契约、SDK 方法和回答评分三张前置卡都已合并。
-
报表和组件只生成草稿,聊天里不发布任何东西;没有管理元数据权限的成员会看到服务端的拒绝原因,之后不再出现这两个按钮;保存失败只在该回答下提示,不影响对话。
- 无。
## What changes
- **Save actions** (`ui/packages/plugin-chatbot`): `ChatbotEnhanced`
with `saveAnswers` and a `conversationId` draws a Save button in the
action bar of each finished assistant answer whose turn ran an object
query (a data tool answered a `source` block). It opens a row under the
answer: "Save question", "Save as my view", "Save as report draft", "Add
as dashboard widget draft", with the line "Report and dashboard widget
results are saved as drafts. Nothing is published from the chat." (the
card's ruling).
- **Routes**: `chat/answerSave.ts` calls `POST {base}/saved-questions`
(`conversationId`, `turnId`, `toolCallId`) and `POST
{base}/conversations/:id/turns/:turnId/artifact` (`kind` view / report /
widget, `toolCallId`), plus `GET`, `DELETE …/:id` and `POST …/:id/run`
for the list. Typed from the spec's `ai-answer.zod.ts` shapes
(`@objectstack/spec/api`), pure fetch through the host's `apiFetch`, the
`answerFeedback.ts` precedent. The tool call is the turn's last
object-query `source`; a dataset answer's `provenance` is not one, so
such a turn gets no Save button.
- **Refusals**: `report_authoring_requires_manage_metadata` shows
"Saving report and dashboard drafts needs permission to manage
metadata." and the chat stops offering the two draft actions on every
answer of the mounted chat. Any other refusal shows the server's
`error.message` (its `details.reason` rides `data-answer-save-refusal`).
- **Saved questions panel** (`chat/SavedQuestionsPanel.tsx`): with
`saveAnswers`, the composer draws a "Saved questions" button that opens
a right side sheet. The list is read each time it opens; each question
can be run again (the fresh result drawn with the chat's own
`SmartToolOutput`) or deleted. `saved_question_has_no_query` gets its
own sentence; other run refusals show the server's message.
- **Where it is drawn**: off unless the host passes `saveAnswers`; never
on a `readOnly` transcript, without a `conversationId`, while an answer
streams, on an answer with no turn, or on a turn without an object-query
source. A turn stored as several assistant messages draws one Save
button, on its last message, beside the rating thumbs.
- **Console**: `ChatPane` passes `saveAnswers` and
`answerSaveApiBase={apiBase}` (switch-on only).
- **i18n**: `chatbot.answerSave.*` (12 keys) and
`chatbot.savedQuestions.*` (10 keys) in every pack; zh-Hant generated.
## Tests
-
`plugin-chatbot/src/__tests__/ChatbotEnhanced.answerSave-31889.test.tsx`
(23 tests): Save question posts the turn and tool call (nothing sent
before the click); view / report / widget each post the artifact route
with `kind` and the tool call, and say the draft names and "It is not
published"; the drafts line; the manage-metadata refusal shown and the
draft actions gone on that answer and the next; any other refusal shows
the server's message; a message-less failure; the host's API base; one
Save button per turn keeping the turn's last query; none on a turn
without a source, a dataset-only turn, `readOnly`, saving off, no
conversation, streaming, a restored answer with no turn; Save beside the
thumbs. Panel: list read on open, run shows the fresh result, delete
drops the row, both run refusals, empty and unreadable list, no panel
with saving off.
- Ablation (restored from the committed state): letting a dataset
provenance count, dropping the `readOnly` gate and ignoring the refusal
flag reds 3 tests.
<details><summary>Local runs (head cf4103d unless named)</summary>
- `pnpm --dir ui exec vitest run packages/i18n/
packages/plugin-chatbot/` at cf4103d: 195 files, 2688 passed, 13
skipped.
- At f927454 (before the de wording fix): the same two packages plus
`packages/app-shell/src/console/ai/` and the ADR-0060 ratchet test, 232
files; only `de-quote-pairing-3876` red (two new German quote pairs
moved its pinned counts), fixed by rewording the two de values, then
that file 9/9.
- `turbo run type-check` for plugin-chatbot, app-shell and i18n: 75/75
tasks at 96c7eb4.
- `pnpm --dir ui exec vitest run scripts/`: 172 files passed, 2 skipped,
at 96c7eb4.
- Derived gates (`dispatch-gates --commands`): 41 run, each exit 0, at
96c7eb4; `dispatch-gates --ran`: 41 derived, 41 run, 0 NOT-MEASURED.
`check:new-line-citations` 0, `check:spec-symbols` 0.
- The merge of main (cf4103d) brought service-queue and
service-knowledge commits only; none touches the packages here.
- Dogfood battery: n/a (no `!` in the title and no narrowing arm).
</details>
## Acceptance notes
- The card's "shown only when the server says the caller may author":
the spec has no capability probe for these routes, so the draft actions
are offered until the server answers the named refusal, which the chat
then shows and stops offering them. A capability read would need a
contract card.
- Reloaded answers carry a turn only once the cloud store maps `turn_id`
(named on #38572); until then the Save button shows on live answers
only, the same as the rating.
- The run result is drawn with the chat's generic tool-result renderer:
the spec does not type the data tools' result bodies, so nothing
table-specific is guessed.
- `ui/AGENTS.md` #2 asks for README / `content/docs/frontend/` updates;
both are outside the claim's surface and are left for the seat to route.
## Verification
- Files to read first:
`ui/packages/plugin-chatbot/src/chat/AnswerSaveActions.tsx` (the
actions, the refusal handling),
`ui/packages/plugin-chatbot/src/ChatbotEnhanced.tsx` `savedAnswerOfTurn`
and `renderActionBar` (which turn and tool call, where it is drawn),
`ui/packages/plugin-chatbot/src/chat/SavedQuestionsPanel.tsx`.
- Two-minute check: `pnpm --dir ui exec vitest run
packages/plugin-chatbot/src/__tests__/ChatbotEnhanced.answerSave-31889.test.tsx`;
expect 23 passed.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QsR2jS7nvVoXN3JBtKGhtu)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QsR2jS7nvVoXN3JBtKGhtu
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent d55ee70 commit bcb7e7f
19 files changed
Lines changed: 1497 additions & 22 deletions
File tree
- .changeset
- ui/packages
- app-shell/src/console/ai
- i18n/src/locales
- plugin-chatbot/src
- __tests__
- chat
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
860 | 860 | | |
861 | 861 | | |
862 | 862 | | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
863 | 867 | | |
864 | 868 | | |
865 | 869 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5011 | 5011 | | |
5012 | 5012 | | |
5013 | 5013 | | |
| 5014 | + | |
| 5015 | + | |
| 5016 | + | |
| 5017 | + | |
| 5018 | + | |
| 5019 | + | |
| 5020 | + | |
| 5021 | + | |
| 5022 | + | |
| 5023 | + | |
| 5024 | + | |
| 5025 | + | |
| 5026 | + | |
| 5027 | + | |
| 5028 | + | |
| 5029 | + | |
| 5030 | + | |
| 5031 | + | |
| 5032 | + | |
| 5033 | + | |
| 5034 | + | |
| 5035 | + | |
| 5036 | + | |
| 5037 | + | |
| 5038 | + | |
| 5039 | + | |
| 5040 | + | |
| 5041 | + | |
| 5042 | + | |
5014 | 5043 | | |
5015 | 5044 | | |
5016 | 5045 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4637 | 4637 | | |
4638 | 4638 | | |
4639 | 4639 | | |
| 4640 | + | |
| 4641 | + | |
| 4642 | + | |
| 4643 | + | |
| 4644 | + | |
| 4645 | + | |
| 4646 | + | |
| 4647 | + | |
| 4648 | + | |
| 4649 | + | |
| 4650 | + | |
| 4651 | + | |
| 4652 | + | |
| 4653 | + | |
| 4654 | + | |
| 4655 | + | |
| 4656 | + | |
| 4657 | + | |
| 4658 | + | |
| 4659 | + | |
| 4660 | + | |
| 4661 | + | |
| 4662 | + | |
| 4663 | + | |
| 4664 | + | |
| 4665 | + | |
| 4666 | + | |
| 4667 | + | |
| 4668 | + | |
4640 | 4669 | | |
4641 | 4670 | | |
4642 | 4671 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5576 | 5576 | | |
5577 | 5577 | | |
5578 | 5578 | | |
| 5579 | + | |
| 5580 | + | |
| 5581 | + | |
| 5582 | + | |
| 5583 | + | |
| 5584 | + | |
| 5585 | + | |
| 5586 | + | |
| 5587 | + | |
| 5588 | + | |
| 5589 | + | |
| 5590 | + | |
| 5591 | + | |
| 5592 | + | |
| 5593 | + | |
| 5594 | + | |
| 5595 | + | |
| 5596 | + | |
| 5597 | + | |
| 5598 | + | |
| 5599 | + | |
| 5600 | + | |
| 5601 | + | |
| 5602 | + | |
| 5603 | + | |
| 5604 | + | |
| 5605 | + | |
| 5606 | + | |
| 5607 | + | |
5579 | 5608 | | |
5580 | 5609 | | |
5581 | 5610 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4731 | 4731 | | |
4732 | 4732 | | |
4733 | 4733 | | |
| 4734 | + | |
| 4735 | + | |
| 4736 | + | |
| 4737 | + | |
| 4738 | + | |
| 4739 | + | |
| 4740 | + | |
| 4741 | + | |
| 4742 | + | |
| 4743 | + | |
| 4744 | + | |
| 4745 | + | |
| 4746 | + | |
| 4747 | + | |
| 4748 | + | |
| 4749 | + | |
| 4750 | + | |
| 4751 | + | |
| 4752 | + | |
| 4753 | + | |
| 4754 | + | |
| 4755 | + | |
| 4756 | + | |
| 4757 | + | |
| 4758 | + | |
| 4759 | + | |
| 4760 | + | |
| 4761 | + | |
| 4762 | + | |
4734 | 4763 | | |
4735 | 4764 | | |
4736 | 4765 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4727 | 4727 | | |
4728 | 4728 | | |
4729 | 4729 | | |
| 4730 | + | |
| 4731 | + | |
| 4732 | + | |
| 4733 | + | |
| 4734 | + | |
| 4735 | + | |
| 4736 | + | |
| 4737 | + | |
| 4738 | + | |
| 4739 | + | |
| 4740 | + | |
| 4741 | + | |
| 4742 | + | |
| 4743 | + | |
| 4744 | + | |
| 4745 | + | |
| 4746 | + | |
| 4747 | + | |
| 4748 | + | |
| 4749 | + | |
| 4750 | + | |
| 4751 | + | |
| 4752 | + | |
| 4753 | + | |
| 4754 | + | |
| 4755 | + | |
| 4756 | + | |
| 4757 | + | |
| 4758 | + | |
4730 | 4759 | | |
4731 | 4760 | | |
4732 | 4761 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4639 | 4639 | | |
4640 | 4640 | | |
4641 | 4641 | | |
| 4642 | + | |
| 4643 | + | |
| 4644 | + | |
| 4645 | + | |
| 4646 | + | |
| 4647 | + | |
| 4648 | + | |
| 4649 | + | |
| 4650 | + | |
| 4651 | + | |
| 4652 | + | |
| 4653 | + | |
| 4654 | + | |
| 4655 | + | |
| 4656 | + | |
| 4657 | + | |
| 4658 | + | |
| 4659 | + | |
| 4660 | + | |
| 4661 | + | |
| 4662 | + | |
| 4663 | + | |
| 4664 | + | |
| 4665 | + | |
| 4666 | + | |
| 4667 | + | |
| 4668 | + | |
| 4669 | + | |
| 4670 | + | |
4642 | 4671 | | |
4643 | 4672 | | |
4644 | 4673 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4636 | 4636 | | |
4637 | 4637 | | |
4638 | 4638 | | |
| 4639 | + | |
| 4640 | + | |
| 4641 | + | |
| 4642 | + | |
| 4643 | + | |
| 4644 | + | |
| 4645 | + | |
| 4646 | + | |
| 4647 | + | |
| 4648 | + | |
| 4649 | + | |
| 4650 | + | |
| 4651 | + | |
| 4652 | + | |
| 4653 | + | |
| 4654 | + | |
| 4655 | + | |
| 4656 | + | |
| 4657 | + | |
| 4658 | + | |
| 4659 | + | |
| 4660 | + | |
| 4661 | + | |
| 4662 | + | |
| 4663 | + | |
| 4664 | + | |
| 4665 | + | |
| 4666 | + | |
| 4667 | + | |
4639 | 4668 | | |
4640 | 4669 | | |
4641 | 4670 | | |
| |||
0 commit comments