Merge pull request #4448 from deepseek-harness/feat/session-header-feedback

feat(web): add feedback to session header menu
This commit is contained in:
Kaige-Gao authored and GitHub committed 2026-09-18 18:01:38 +08:00
commit 0ed5151d0b
25 files changed
+247 -49

No files matched your search

@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write .agents/notes/implemented/feature/2026-09-08-feedback-dialog-and-categories.md
2026-09-08-feedback-dialog-and-categories.md: ee656946a9e5d2921a02a1b642041e5965661f31
2026-09-08-feedback-dialog-and-categories.zh.md: ef2b2d4670aad12398125925dd1e1a7e7c10a5f0
2026-09-08-feedback-dialog-and-categories.md: 1d544e6ef978c10008ac62768b6faaf9eaaf8b73
2026-09-08-feedback-dialog-and-categories.zh.md: 6e58820bf308a3a9f7d15b64027f90e7e6771bd4
@@ -14,10 +14,14 @@ The Web client had two disconnected feedback paths with no visible outcome. `/fe
`ui-message-feedback` becomes the Web feedback surface. A per-session `FeedbackSurface` owns the message-feedback controller, a `FeedbackDialogController` for the draft, the submission, and the toast sequence, and the routing between them: a message target puts its selected judgment with the dialog's category and note through the message controller, while the Session target records through `ctx.remote.sessionFeedback`. A `FeedbackDialog` entry of `conversation.input.overlay` renders the Modal and Toast primitives from the dialog store. A decoration on the Host's `feedback` command opens the dialog for the Session from a menu pick or a bare Enter while `/feedback <text>` still reaches the Host; it uses the `action` kind in `CommandUiSpec`, which consumes the trigger token and runs a client callback without submitting anything. The later [symmetric message feedback submission](2026-09-10-symmetric-message-feedback-submission.md) decision owns the rating entry rule: either unrecorded rating opens the dialog, while clicking the recorded rating retracts it. The note popover, `clearNote`, and `clear` remain absent because the dialog is the only note editor.
The Session Header's more-actions menu also opens the Session dialog through the `feedbackUi.openSession` Client service. The menu remains owned by `session-log-export`, while the existing per-session feedback controller owns the draft and submission. An observable tracks the optional feedback plugin's availability, so unloading feedback removes only its menu row and leaves export usable. Opening or dismissing the form writes no feedback event; Submit records one Session remark.
The dialog is the shared Modal card at the design's width; the design's checkbox for including the conversation log is not built, because the log travels with every feedback event and is not optional. An oversized description still fails on submit with `note-too-large`; the dialog stays open with its draft and a warning toast presents the localized failure.
## Alternatives considered
**A child slot for Header menu actions.** A slot would let each plugin own its menu row, but requires a shared menu-item API beyond the feedback entry requested in #4445. The optional `feedbackUi` service keeps this change local while leaving dialog state and submission in the feedback plugin.
**Encode the category into the note text.** A prefix in free text is not filterable without parsing and would leak into the verbatim note that telemetry uploads; a durable id in the payload is what a consumer can group by.
**Submit the dialog through the command plane as `/feedback <text>`.** The command rejects empty text, cannot carry a category, and writes an acknowledgement row the design replaces with a toast; the Remote records the same event with neither constraint.
@@ -14,10 +14,14 @@ Web 客户端有两条互不相连的反馈路径,且都没有可见结果。`
`ui-message-feedback` 成为 Web 反馈界面。每个 Session 一个 `FeedbackSurface`,拥有消息反馈控制器、负责草稿、提交与 toast 序号的 `FeedbackDialogController`,以及两者之间的路由:消息目标经消息控制器 put 一条带弹窗分类与备注的所选评分,Session 目标经 `ctx.remote.sessionFeedback` 记录。`conversation.input.overlay` 的 `FeedbackDialog` 条目从弹窗 store 渲染 Modal 与 Toast 基元。宿主 `feedback` 命令上的装饰让菜单选中或不带参数的回车为 Session 打开弹窗,而 `/feedback <text>` 仍到达宿主;它使用 `CommandUiSpec` 中的 `action` 种类:裸调用消费触发 token 后运行一个客户端回调,不提交任何内容。后续的[对称消息反馈提交](2026-09-10-symmetric-message-feedback-submission.zh.md)决策拥有评分入口规则:任一未记录的评分都会打开弹窗,再次点击已记录的评分则撤回。备注浮层、`clearNote` 与 `clear` 继续保持移除,因为弹窗是唯一的备注编辑器。
会话标题栏的更多操作菜单也通过 `feedbackUi.openSession` Client 服务打开 Session 弹窗。菜单仍由 `session-log-export` 持有,现有的逐 Session 反馈控制器持有草稿与提交。一个可观察值跟踪可选反馈插件的可用状态,因此卸载反馈插件只移除其菜单行,导出仍然可用。打开或关闭表单不写反馈事件;点击提交才记录一条 Session 反馈。
弹窗是共用的 Modal 卡片,宽度按设计稿;设计稿里「包括当前对话的日志」复选框不做,因为日志随每个反馈事件一起投递,不是可选项。超长描述仍在提交时以 `note-too-large` 失败;弹窗保留草稿并通过警告 toast 展示本地化错误。
## 考虑过的替代方案
**为标题栏菜单动作声明子 slot。** slot 可以让每个插件持有自己的菜单行,但需要共享菜单项 API,超出 #4445 所需反馈入口的范围。可选的 `feedbackUi` 服务将改动限制在局部,同时让弹窗状态与提交继续由反馈插件持有。
**把分类编进备注文本。** 自由文本里的前缀不解析就无法过滤,还会混进遥测上传的原样备注;载荷里的持久 id 才是消费方能分组的东西。
**让弹窗经命令平面以 `/feedback <text>` 提交。** 命令拒绝空文本、带不了分类,还会写一行设计稿已用 toast 取代的确认;Remote 记录同一个事件且没有这两个约束。
+14 -1
View File
@@ -47,7 +47,20 @@ describe('packaging run records', () => {
cwd: root, env: environment,
})).rejects.toThrow('fatal failed')
const descendant = JSON.parse(await readFile(join(run.directory, 'descendant.json'), 'utf8')) as { pid: number }
expect(() => process.kill(descendant.pid, 0)).toThrow()
// Linux can retain a dead descendant as a zombie until its new parent reaps it.
await expect.poll(async () => {
try {
if (process.platform === 'linux') {
const status = await readFile(`/proc/${descendant.pid}/status`, 'utf8')
return /^State:\s+[ZXx]\b/m.test(status)
}
process.kill(descendant.pid, 0)
return false
} catch (error) {
if (['ENOENT', 'ESRCH'].includes((error as NodeJS.ErrnoException).code ?? '')) return true
throw error
}
}, { timeout: 5_000 }).toBe(true)
const events = (await readFile(join(run.directory, 'events.jsonl'), 'utf8')).trim().split('\n').map(line => JSON.parse(line) as { type: string; fatalObserved?: boolean; terminationError?: boolean })
expect(events.at(-1)).toMatchObject({ type: 'stage-end', fatalObserved: true, terminationError: false })
run.finish(false)
+39 -5
View File
@@ -1,8 +1,6 @@
// Keyless browser regression for durable per-message feedback. Cold-seeds a
// settled two-turn transcript (zero model calls), records a Like through the
// feedback dialog, replaces it through the same dialog with a Dislike, proves
// the judgment survives a full page reload from the Host's canonical log, then
// retracts it.
// Keyless browser regression for durable message and Session feedback. A
// cold-seeded, settled two-turn transcript avoids model calls while exercising
// message ratings and the Session Header dialog against the Host's canonical log.
import { readFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'
import type { Browser, Page } from 'playwright'
@@ -145,4 +143,40 @@ describe('web e2e: durable per-message feedback', () => {
expect(tripwire.pageErrors).toEqual([])
expect(tripwire.warnings).toEqual([])
})
it.skipIf(MODE === 'record')('opens the shared dialog from the header and records Session feedback only on submit', async () => {
onTestFailed(() => saveFailureShot(page, 'web-e2e-header-feedback'))
await openSeededSession()
await page.getByText('DONE', { exact: true }).waitFor({ timeout: 30_000 })
const agent = scaffold.ctx.agents.get(SessionId(SEED_ID))
if (agent === undefined) throw new Error('seeded session did not attach an agent')
const feedbackEvents = () => agent.session.snapshotEvents().filter(event => event.type.startsWith('feedback/'))
const before = feedbackEvents().length
const dialog = page.getByRole('dialog', { name: 'Submit feedback' })
await page.getByRole('button', { name: 'More actions', exact: true }).click()
await page.getByRole('menuitem', { name: 'Download session log' }).waitFor()
await page.getByRole('menuitem', { name: 'Feedback', exact: true }).click()
await dialog.waitFor()
expect(await page.getByRole('menu').count()).toBe(0)
expect(feedbackEvents()).toHaveLength(before)
await dialog.getByRole('textbox', { name: 'Feedback details' }).fill('discarded draft')
await dialog.getByRole('button', { name: 'Close', exact: true }).click()
expect(feedbackEvents()).toHaveLength(before)
await page.getByRole('button', { name: 'More actions', exact: true }).click()
await page.getByRole('menuitem', { name: 'Feedback', exact: true }).click()
await dialog.waitFor()
expect(await dialog.getByRole('textbox', { name: 'Feedback details' }).inputValue()).toBe('')
await dialog.getByRole('button', { name: 'Product features and interaction', exact: true }).click()
await dialog.getByRole('textbox', { name: 'Feedback details' }).fill('Feedback from the Session menu.')
await dialog.getByRole('button', { name: 'Submit', exact: true }).click()
await expect.poll(() => dialog.count()).toBe(0)
await page.getByRole('alert').filter({ hasText: 'Thanks for your feedback' }).waitFor()
expect(feedbackEvents().slice(before)).toMatchObject([
{ type: 'feedback/record', data: { category: 'product-interaction', text: 'Feedback from the Session menu.' } },
])
expect(tripwire.pageErrors).toEqual([])
expect(tripwire.warnings).toEqual([])
}, 60_000)
})
+2 -2
View File
@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/client/README.md
README.md: 310147c8f767b8d68fb149de4c462a0a8154663b
README.zh.md: 0d3e90a87cb99676a51696e753a45d1a35a2e4d1
README.md: 3d8e52fe6dfc3e517c09f772e63c073957e41cd9
README.zh.md: 4a547889b9a12af7e65a671bef9176075d55ebc1
+1 -1
View File
@@ -76,7 +76,7 @@ The kernel packages boot and serve the page; the UI feature packages present it.
| [`ui-plugin-manager/`](ui-plugin-manager/README.md) | Contributes the sidebar Plugins panel: install, enable, disable, retry, and compose installed packages | — |
| [`ui-settings-plugin-inventory/`](ui-settings-plugin-inventory/README.md) | Contributes the read-only Host Loader inventory tab to Plugins settings | — |
| [`ui-deliverables/`](ui-deliverables/README.md) | Produces the changed-files card with its comparison tabs, delivery cards, and clickable final-response file references | — |
| [`ui-message-feedback/`](ui-message-feedback/README.md) | The feedback surface: per-message Like/Dislike in the assistant-message action strip, and the feedback dialog behind both ratings and `/feedback` | — |
| [`ui-message-feedback/`](ui-message-feedback/README.md) | Provides message ratings and feedback dialogs opened from ratings, `/feedback`, or the Session Header menu | `ctx.feedbackUi` |
| [`ui-directory-picker-browse/`](ui-directory-picker-browse/README.md) | In-app directory browsing surface for the workspace directory flow | — |
| [`ui-directory-picker-native/`](ui-directory-picker-native/README.md) | Native directory-picker surface driving the local Desktop or Host OS chooser | — |
| [`ui-open-in-app/`](ui-open-in-app/README.md) | Session-header split button opening the workspace directory in an installed application, and the document preview's default-application controls for one file | — |
+1 -1
View File
@@ -76,7 +76,7 @@ kind: "package-group"
| [`ui-plugin-manager/`](ui-plugin-manager/README.zh.md) | 贡献侧栏的“插件”面板:安装、启用、停用、重试与组合已安装的包 | — |
| [`ui-settings-plugin-inventory/`](ui-settings-plugin-inventory/README.zh.md) | 向「插件」设置贡献只读的 Host Loader 清单标签页 | — |
| [`ui-deliverables/`](ui-deliverables/README.zh.md) | 生成改动文件卡片及其对比 tab、交付文件卡片与可点击的最终响应文件引用 | — |
| [`ui-message-feedback/`](ui-message-feedback/README.zh.md) | 反馈界面:助手消息操作条中的逐消息赞踩,以及点赞、点踩与 `/feedback` 背后的反馈弹窗 | — |
| [`ui-message-feedback/`](ui-message-feedback/README.zh.md) | 提供消息赞踩,以及从赞踩、`/feedback` 或会话标题栏菜单打开的反馈弹窗 | `ctx.feedbackUi` |
| [`ui-directory-picker-browse/`](ui-directory-picker-browse/README.zh.md) | 面向工作区目录流程的应用内目录浏览界面 | — |
| [`ui-directory-picker-native/`](ui-directory-picker-native/README.zh.md) | 驱动本地 Desktop 或 Host OS 选择器的原生目录选择界面 | — |
| [`ui-open-in-app/`](ui-open-in-app/README.zh.md) | 在已安装应用中打开工作区目录的会话标题栏拆分按钮,以及文档预览里用默认应用打开单个文件的控件 | — |
@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/client/ui-message-feedback/README.md
README.md: b37278e8d115a2ad61bb17ef8d884b0d888cd6a7
README.zh.md: cd233061640f5e52ea9ca54ffe973bff3b957197
README.md: b6c6f227ebbeb3d6862d10658b1b125517b25581
README.zh.md: a294c73c87e8e2da8139fe965e70d9eaf34096a6
@@ -25,7 +25,7 @@ This package is the Web GUI's feedback surface: the Like/Dislike pair in the fin
<a id="use-this-package"></a>
## Use this package
Mount this plugin alongside `ui-conversation` and `ui-commands`; the Like/Dislike pair then appears in the action row of each turn's closing assistant message, between copy and branch, and the Feedback row of the composer menu opens the dialog. A recorded rating shows the filled glyph and stays visible without hover. Like and Dislike both open the dialog: seven category chips and a detail box are optional, and Submit records the selected judgment with whatever was filled in before the toast thanks the user; the conversation log travels with every feedback event. Clicking the recorded rating retracts it without opening the dialog. A bare `/feedback`, picked from the menu or typed and sent without text, opens the same dialog for the Session; `/feedback <text>` keeps the Host command path and its acknowledgement row.
Mount this plugin alongside `ui-conversation` and `ui-commands`; the Like/Dislike pair then appears in the action row of each turn's closing assistant message, between copy and branch, and Feedback in the composer menu opens the same dialog. Mounting `session-log-export` also adds Feedback to the Session Header's more-actions menu. A recorded rating shows the filled glyph and stays visible without hover. Like and Dislike both open the dialog: seven category chips and a detail box are optional, and Submit records the selected judgment with whatever was filled in before the toast thanks the user; the conversation log travels with every feedback event. Clicking the recorded rating retracts it without opening the dialog. A bare `/feedback`, picked from the menu or typed and sent without text, opens the same dialog for the Session; `/feedback <text>` keeps the Host command path and its acknowledgement row.
### Failures
@@ -39,7 +39,7 @@ A rating or list-load failure shows inline in the row; a submission failure show
<details>
<summary>Implementation internals — click to expand</summary>
The package contributes the `feedback` entry (order 10) of `conversation.chat.assistant-actions`, declared by ui-conversation and rendered inside the finalized assistant message's IconActions row, and the `feedback-dialog` entry (order 2) of `conversation.input.overlay`, which renders the Modal and Toast primitives through body portals and centers the toast over the composer card it mounts inside. The `/feedback` decoration is an `action` registered through `ctx.commandUi.decorate`, so a menu pick or a bare Enter consumes the trigger token and opens the dialog while an argued line still reaches the Host command.
The package contributes the `feedback` entry (order 10) of `conversation.chat.assistant-actions`, declared by ui-conversation and rendered inside the finalized assistant message's IconActions row, and the `feedback-dialog` entry (order 2) of `conversation.input.overlay`, which renders the Modal and Toast primitives through body portals and centers the toast over the composer card it mounts inside. The `feedbackUi.openSession(sessionId)` Client service opens that same Session-scoped dialog without recording feedback; the Header menu and command decoration both use it. The `/feedback` decoration is an `action` registered through `ctx.commandUi.decorate`, so a menu pick or a bare Enter consumes the trigger token and opens the dialog while an argued line still reaches the Host command.
Per Session, one `MessageFeedbackController` backs every message control and one `FeedbackDialogController` owns the dialog draft, the submission, and the toast sequence. The message controller reads `messageFeedback.list` once, deferred to the first hover or focus rather than fired on mount, and serializes mutations so each carries the version last observed; a `version-conflict` reply carries the authoritative item and reconciles the view without refetching. Before either rating action proceeds, the row checks the committed item: the matching rating calls `retract`, which rechecks the rating in the serialized queue and becomes a no-op after a concurrent change, while any other state opens the dialog with the requested rating. The dialog controller submits by target: a message target puts that rating with the dialog's note and category through the message controller, and the Session target records through `ctx.remote.sessionFeedback`. Success closes the draft and raises the acknowledgement toast; a late success from a superseded draft raises that toast without closing the new draft; a failure keeps the draft open and raises a longer-lived warning toast.
@@ -90,4 +90,4 @@ None.
</details>
**Runtime invariant:** No companion is published. The plugin owns two slot registrations, one command decoration, and one per-session controller-pair map, all released by the plugin fiber's effect disposers. The lifecycle spec proves the registrations are withdrawn and every controller pair is dropped when the owning fiber is disposed, so no second authority exists to check at runtime.
**Runtime invariant:** No companion is published. The plugin owns two slot registrations, one command decoration, the `feedbackUi` service, and one per-session controller-pair map, all released with the owning plugin fiber. The lifecycle spec verifies that the registrations and service are withdrawn and every controller pair is dropped when the fiber is disposed, so no second authority exists to check at runtime.
@@ -25,7 +25,7 @@ kind: "package-reference"
<a id="use-this-package"></a>
## 使用本包
与 `ui-conversation`、`ui-commands` 一起挂载本插件;Like/Dislike 对随即出现在每个轮次收尾助手消息的动作行中,位于复制与分支之间,输入框菜单里的「反馈」行则打开弹窗。已记录的评分显示实心图标,不需要悬停也一直可见。点赞和点踩都会打开弹窗:七个分类标签和一个详情框都可不填;提交后才会记录带所填内容的对应评分并弹出感谢 toast,对话日志随每个反馈事件一起投递。再次点击已记录的评分会直接撤回,不打开弹窗。不带文本的 `/feedback`,无论是从菜单选中还是直接输入后发送,都会为 Session 打开同一个弹窗;`/feedback <text>` 仍走宿主命令路径并显示确认行。
与 `ui-conversation`、`ui-commands` 一起挂载本插件;Like/Dislike 对随即出现在每个轮次收尾助手消息的动作行中,位于复制与分支之间,输入框菜单里的「反馈」会打开同一个弹窗。挂载 `session-log-export` 后,会话标题栏的更多操作菜单也会增加「反馈」。已记录的评分显示实心图标,不需要悬停也一直可见。点赞和点踩都会打开弹窗:七个分类标签和一个详情框都可不填;提交后才会记录带所填内容的对应评分并弹出感谢 toast,对话日志随每个反馈事件一起投递。再次点击已记录的评分会直接撤回,不打开弹窗。不带文本的 `/feedback`,无论是从菜单选中还是直接输入后发送,都会为 Session 打开同一个弹窗;`/feedback <text>` 仍走宿主命令路径并显示确认行。
### 失败
@@ -39,7 +39,7 @@ kind: "package-reference"
<details>
<summary>实现细节——点击展开</summary>
本包贡献 `conversation.chat.assistant-actions` 的 `feedback` 条目(order 10),由 ui-conversation 声明并渲染在已定稿助手消息的 IconActions 行内;同时贡献 `conversation.input.overlay` 的 `feedback-dialog` 条目(order 2),它通过 body portal 渲染 Modal 与 Toast 基元,并让 toast 以其所在的输入框卡片为中心。`/feedback` 装饰是经 `ctx.commandUi.decorate` 注册的 `action`,因此菜单选中或不带参数的回车会消费触发 token 并打开弹窗,而带参数的命令行仍到达宿主命令。
本包贡献 `conversation.chat.assistant-actions` 的 `feedback` 条目(order 10),由 ui-conversation 声明并渲染在已定稿助手消息的 IconActions 行内;同时贡献 `conversation.input.overlay` 的 `feedback-dialog` 条目(order 2),它通过 body portal 渲染 Modal 与 Toast 基元,并让 toast 以其所在的输入框卡片为中心。`feedbackUi.openSession(sessionId)` Client 服务打开同一个 Session 级弹窗,不记录反馈;标题栏菜单和命令装饰共用此方法。`/feedback` 装饰是经 `ctx.commandUi.decorate` 注册的 `action`,因此菜单选中或不带参数的回车会消费触发 token 并打开弹窗,而带参数的命令行仍到达宿主命令。
每个 Session 有一个 `MessageFeedbackController` 支撑所有消息控件,以及一个 `FeedbackDialogController` 拥有弹窗草稿、提交与 toast 序号。消息控制器只读取一次 `messageFeedback.list`,且延迟到首次 hover 或 focus 才发起,而非挂载时触发;变更串行执行,每次都携带最后观察到的版本,`version-conflict` 响应带回权威条目,据此对账视图而不重新拉取。任一评分操作执行前,该行都会检查已提交条目:评分相同则调用 `retract`,它会在串行队列内重新检查评分并在并发变更后变为无操作;其他状态则携带所选评分打开弹窗。弹窗控制器按目标提交:消息目标通过消息控制器 put 一条带弹窗备注与分类的对应评分,Session 目标通过 `ctx.remote.sessionFeedback` 记录。成功会关闭草稿并弹出确认 toast;被替换的旧草稿迟到的成功只弹确认 toast、不关闭新草稿;失败会保留弹窗并弹出停留时间更长的警告 toast。
@@ -90,4 +90,4 @@ kind: "package-reference"
</details>
**运行时不变式:** 不发布伴生入口。插件持有两个 slot 注册、一个命令装饰,以及一个按 Session 划分的控制器对 map;它们都由插件 fiber 的同一个 effect disposer 释放。生命周期规格测试证明,所属 fiber 释放时会撤销所有注册并丢弃所有控制器,因此不存在需要在运行时检查的第二权威来源。
**运行时不变式:** 不发布伴生入口。插件持有两个 slot 注册、一个命令装饰、`feedbackUi` 服务,以及一个按 Session 划分的控制器对 map;它们都随所属插件 fiber 释放。生命周期规格测试验证,fiber 释放时会撤销所有注册和服务并丢弃所有控制器,因此不存在需要在运行时检查的第二权威来源。
@@ -3,7 +3,8 @@
* conversation.chat.assistant-actions strip, the feedback dialog and its
* acknowledgement and failure toasts in conversation.input.overlay, and the `/feedback`
* decoration that opens the dialog from the composer menu or a bare typed
* command. One FeedbackSurface per Session backs every entry in that Session.
* command. The feedbackUi service opens the same dialog for other plugins.
* One FeedbackSurface per Session backs every entry in that Session.
* @module @deepseek-ai/dsh-client-ui-message-feedback/client
*/
@@ -37,6 +38,21 @@ export type {
} from './slots.ts'
export type { MessageFeedbackKey } from './locales.ts'
/** Opens the existing Session feedback form without submitting feedback. */
export interface FeedbackUi {
/**
* Open the Session feedback draft without recording feedback.
* @param sessionId - Session whose feedback draft to open.
*/
openSession(sessionId: SessionId): void
}
declare module '@deepseek-ai/cordis' {
interface Context {
feedbackUi: FeedbackUi
}
}
/** Dictionary namespace owned by this plugin. */
const NS = 'feedback'
@@ -45,7 +61,8 @@ export const inject = ['slots', 'remote', 'remote.messageFeedback', 'remote.sess
/**
* Client plugin body: the per-message feedback entry, the Session's dialog
* entry, the `/feedback` decoration, and their per-session surfaces.
* entry, the `feedbackUi` service, the `/feedback` decoration, and their
* per-session surfaces.
* @param ctx - client root context.
*/
export function apply(ctx: ClientContext): void {
@@ -65,6 +82,11 @@ export function apply(ctx: ClientContext): void {
surfaces.clear()
}, 'ui-message-feedback: per-session surfaces')
const feedbackUi: FeedbackUi = {
openSession: (sessionId) => { surfaceFor(sessionId).dialog.open({ kind: 'session' }) },
}
ctx.provide('feedbackUi', feedbackUi)
// A reconnect can only invalidate what was already read; a cold Session
// stays cold until something asks for it.
ctx.on('connection/reset', () => {
@@ -114,7 +136,7 @@ export function apply(ctx: ClientContext): void {
scope.effect(() => scope.commandUi.decorate({
name: 'feedback',
available: () => true,
ui: { kind: 'action', run: (session) => { surfaceFor(session.sessionId).dialog.open({ kind: 'session' }) } },
ui: { kind: 'action', run: (session) => { feedbackUi.openSession(session.sessionId) } },
}), 'ui-message-feedback: /feedback decoration')
})
}
@@ -164,6 +164,20 @@ describe('ui-message-feedback browser plugin', () => {
expect(b.dialogEntry()!.inject!(sid('s2')).hooks.dialog.getSnapshot()).toMatchObject({ target: null, toast: 0 })
})
it('opens the shared Session dialog through feedbackUi without recording anything', async () => {
const b = await bench()
await b.fiber.await()
const dialog = b.dialogEntry()!.inject!(sid('s1'))
b.ctx.feedbackUi.openSession(sid('s1'))
expect(dialog.hooks.dialog.getSnapshot().target).toEqual({ kind: 'session' })
expect(b.dialogEntry()!.inject!(sid('s2')).hooks.dialog.getSnapshot().target).toBeNull()
expect(b.calls).toEqual([])
dialog.dismiss()
expect(b.calls).toEqual([])
await b.fiber.dispose()
expect(b.ctx.get('feedbackUi')).toBeUndefined()
})
it('records a Session remark through the sessionFeedback Remote and a message judgment through put', async () => {
const b = await bench()
await b.fiber.await()
@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/session-query/session-log-export/README.md
README.md: 8697b0c2c105c928f5325f953b7fb663ae68e18e
README.zh.md: fe60c6ab8cc8d2d5e7515416bb72624584c11b9d
README.md: fb07e9bf00127ebea991a7bf10a8de8e35ad1210
README.zh.md: 2af96f8621745fd6393f03905e4c6a978dbaf400
@@ -27,6 +27,8 @@ English | [中文](README.zh.md)
Use this package when the Web bundle should let users export a session log. It requires Connection, the command registry, Session query and persistence, and attachments. Mount the plugin, then choose `Download session log` from the Session Header's more-actions menu or type `/export`; the browser downloads `dsh-session-<id>.zip`.
When `ui-message-feedback` is mounted, the same menu also offers `Feedback`, which opens its existing Session feedback dialog. Opening or dismissing that form does not export the Session or submit feedback. The feedback row follows the feedback plugin's availability; export remains available independently.
### When to choose it
Choose it for a Web deployment that needs user-facing session export with a visible download dialog. Avoid it when a programmatic or Host-side export is needed: this package produces a browser download, not a Host path write. The logs are serialized from persistence read handles, so any mounted backend is supported.
@@ -27,6 +27,8 @@ kind: "package-reference"
当 Web bundle 需要让用户导出会话日志时使用本包。它需要 Connection、命令注册表、Session 查询与持久化以及附件服务。挂载插件,然后在 Session Header 的更多操作菜单中选择 `下载 Session 日志` 或输入 `/export`;浏览器会下载 `dsh-session-<id>.zip`。
挂载 `ui-message-feedback` 时,同一菜单还提供“反馈”,打开已有的 Session 反馈弹窗。打开或关闭该弹窗不会导出 Session 或提交反馈。反馈入口随反馈插件的可用状态显示;导出功能保持独立可用。
### 何时选择
为需要带可见下载弹窗的面向用户的会话导出的 Web 部署选择它。需要程序化或 Host 侧导出时避免使用:本包产生的是浏览器下载,而非 Host 路径写入。日志从持久化读句柄序列化而来,因此任何已挂载后端都受支持。
@@ -56,6 +56,7 @@
"@deepseek-ai/dsh-client-store": "workspace:^",
"@deepseek-ai/dsh-client-ui-commands": "workspace:^",
"@deepseek-ai/dsh-client-ui-conversation": "workspace:^",
"@deepseek-ai/dsh-client-ui-message-feedback": "workspace:^",
"@deepseek-ai/dsh-client-ui-primitives": "workspace:^",
"@deepseek-ai/dsh-client-ui-renderer": "workspace:^",
"@deepseek-ai/dsh-client-ui-session": "workspace:^",
@@ -1,16 +1,34 @@
import { useState } from 'react'
import type { ReactNode } from 'react'
import { IconDownloadOutlineRegular, IconEllipsisOutlineRegular, Menu } from '@deepseek-ai/dsh-client-ui-primitives'
import type { ObservableSnapshot } from '@deepseek-ai/dsh-client-store'
import type { InjectFace } from '@deepseek-ai/dsh-client-ui-slots'
import type { SessionId } from '@deepseek-ai/dsh-session/types'
import { IconDownloadOutlineRegular, IconEllipsisOutlineRegular, IconPaperPlaneOutlineRegular, Menu } from '@deepseek-ai/dsh-client-ui-primitives'
import { SessionLogDownloadDialog, type SessionLogDownloadDialogProps } from './Dialog.tsx'
import type { SessionLogDownloadDialogInjected } from './Dialog.tsx'
import css from './HeaderAction.module.css'
/** Session download controls with observable feedback availability and a Session feedback action. */
export interface SessionLogDownloadHeaderInjected extends SessionLogDownloadDialogInjected {
hooks: SessionLogDownloadDialogInjected['hooks'] & { feedbackAvailable: ObservableSnapshot<boolean> }
/**
* Open the existing Session feedback draft without recording feedback; no-op after the feedback plugin unloads.
* @param sessionId - Session whose feedback form to open.
*/
openFeedback: (sessionId: SessionId) => void
}
/** Session download props plus the optional feedback action. */
export type SessionLogDownloadHeaderProps = SessionLogDownloadDialogProps & InjectFace<SessionLogDownloadHeaderInjected>
/**
* Render the Session Header more-actions icon button, its download menu, and the shared result dialog.
* Render the Session Header menu with download and optional feedback actions.
* @param props - Session runtime, download controller, and localized copy.
* @returns the persistent Header action and Session-scoped dialog.
*/
export function SessionLogDownloadHeaderAction(props: SessionLogDownloadDialogProps): ReactNode {
const { sessionId, useSessionLogDownload, request, t } = props
export function SessionLogDownloadHeaderAction(props: SessionLogDownloadHeaderProps): ReactNode {
const { sessionId, useSessionLogDownload, useFeedbackAvailable, request, openFeedback, t } = props
const feedbackAvailable = useFeedbackAvailable(value => value)
const entry = useSessionLogDownload(state => state.bySession[String(sessionId)])
const busy = entry?.status === 'downloading'
const [open, setOpen] = useState(false)
@@ -22,10 +40,14 @@ export function SessionLogDownloadHeaderAction(props: SessionLogDownloadDialogPr
align="end"
dense
onClose={() => { setOpen(false) }}
items={[{ id: 'download', label: t('menu.download'), icon: <IconDownloadOutlineRegular />, disabled: busy }]}
onSelect={() => {
items={[
{ id: 'download', label: t('menu.download'), icon: <IconDownloadOutlineRegular />, disabled: busy },
...feedbackAvailable ? [{ id: 'feedback', label: t('menu.feedback'), icon: <IconPaperPlaneOutlineRegular /> }] : [],
]}
onSelect={(id) => {
setOpen(false)
void request(sessionId)
if (id === 'feedback') openFeedback(sessionId)
else void request(sessionId)
}}
anchor={(
<button
@@ -7,9 +7,10 @@ import type {} from '@deepseek-ai/dsh-client-ui-commands/client'
import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
import type {} from '@deepseek-ai/dsh-client-ui-session/client'
import type {} from '@deepseek-ai/dsh-client-ui-message-feedback/client'
import { createSnapshotStore } from '@deepseek-ai/dsh-client-store'
import { SessionLogDownloadController } from './controller.ts'
import type { SessionLogDownloadDialogInjected } from './Dialog.tsx'
import { SessionLogDownloadHeaderAction } from './HeaderAction.tsx'
import { SessionLogDownloadHeaderAction, type SessionLogDownloadHeaderInjected } from './HeaderAction.tsx'
import { en, NS, zh, type SessionLogDownloadKey } from './locales.ts'
declare module '@deepseek-ai/cordis' {
@@ -37,6 +38,13 @@ export function apply(ctx: ClientContext): void {
ctx.provide('sessionLogDownload', controller)
ctx.effect(() => async () => { await controller.dispose() }, 'session-log-download: browser download lifecycle')
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'session-log-download: browser dictionaries')
const feedbackAvailable = createSnapshotStore(false)
ctx.inject(['feedbackUi'], (scope: ClientContext) => {
scope.effect(() => {
feedbackAvailable.set(true)
return () => { feedbackAvailable.set(false) }
}, 'session-log-download: feedback availability')
})
ctx.on('command/executed', (sessionId, commandName, result) => {
if (commandName === 'export' && result.kind === 'success') void controller.download(sessionId)
})
@@ -44,10 +52,12 @@ export function apply(ctx: ClientContext): void {
name: 'conversation.session.header.utilities',
id: 'session-log-download',
locale: NS,
inject: (): SessionLogDownloadDialogInjected => ({
hooks: { sessionLogDownload: controller.store },
inject: (): SessionLogDownloadHeaderInjected => ({
hooks: { sessionLogDownload: controller.store, feedbackAvailable },
request: (sessionId: SessionId) => controller.download(sessionId),
dismiss: (sessionId: SessionId) => { controller.dismiss(sessionId) },
// The feedback plugin can unload between the menu render and this click.
openFeedback: (sessionId: SessionId) => { ctx.get('feedbackUi')?.openSession(sessionId) },
}),
}, SessionLogDownloadHeaderAction))
}
@@ -5,6 +5,7 @@ export const NS = 'session-log-download'
export const zh = {
'header.more': '更多操作',
'menu.download': '下载 Session 日志',
'menu.feedback': '反馈',
'dialog.preparingTitle': '正在导出 Session',
'dialog.preparingDescription': '正在准备包含当前 Session、子 Session 和附件的 ZIP 文件。',
'dialog.successTitle': 'Session 导出已开始下载',
@@ -18,6 +19,7 @@ export const zh = {
export const en: Record<keyof typeof zh, string> = {
'header.more': 'More actions',
'menu.download': 'Download session log',
'menu.feedback': 'Feedback',
'dialog.preparingTitle': 'Exporting Session',
'dialog.preparingDescription': 'Preparing a ZIP containing this Session, its sub-Sessions, and attachments.',
'dialog.successTitle': 'Session download started',
@@ -6,6 +6,7 @@ import { LocaleRuntime } from '@deepseek-ai/dsh-client-locale/client'
import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
import { SessionLogDownloadHeaderAction } from '../src/client/HeaderAction.tsx'
import { apply, inject } from '../src/client/index.ts'
import type { SessionLogDownloadHeaderInjected } from '../src/client/HeaderAction.tsx'
const SID = 'session-export-apply' as SessionId
@@ -33,6 +34,26 @@ async function bench() {
}
describe('session-log-download browser plugin', () => {
it('follows feedback plugin availability and opens the selected Session form', async () => {
const b = await bench()
const entry = b.slots.entries('conversation.session.header.utilities')[0]!
const injected = (entry.inject as unknown as () => SessionLogDownloadHeaderInjected)()
expect(injected.hooks.feedbackAvailable.getSnapshot()).toBe(false)
injected.openFeedback(SID)
const openSession = vi.fn()
const feedback = b.ctx.plugin((ctx) => { ctx.provide('feedbackUi', { openSession }) })
await feedback.await()
await vi.waitFor(() => { expect(injected.hooks.feedbackAvailable.getSnapshot()).toBe(true) })
injected.openFeedback(SID)
expect(openSession).toHaveBeenCalledWith(SID)
await feedback.dispose()
await vi.waitFor(() => { expect(injected.hooks.feedbackAvailable.getSnapshot()).toBe(false) })
expect(b.slots.entries('conversation.session.header.utilities')).toHaveLength(1)
await b.fiber.dispose()
})
it('provides one controller and removes its Header contribution on disposal', async () => {
vi.stubGlobal('fetch', vi.fn(async () => new Response('', { status: 500 })))
const b = await bench()
@@ -1,43 +1,82 @@
// @vitest-environment jsdom
import { cleanup, fireEvent, render, waitFor } from '@testing-library/react'
import { act, cleanup, fireEvent, render, waitFor } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { useSyncExternalStore } from 'react'
import type { SessionId } from '@deepseek-ai/dsh-session/types'
import { createSnapshotStore, type ObservableSnapshot } from '@deepseek-ai/dsh-client-store'
import { SessionLogDownloadController } from '../src/client/controller.ts'
import { SessionLogDownloadHeaderAction } from '../src/client/HeaderAction.tsx'
import type { SessionLogDownloadDialogProps } from '../src/client/Dialog.tsx'
import type { SessionLogDownloadHeaderProps } from '../src/client/HeaderAction.tsx'
import { en } from '../src/client/locales.ts'
const SID = 'session-export-header' as SessionId
function bindSessionExport(controller: SessionLogDownloadController) {
return function useSessionLogDownload<T>(selector: (state: ReturnType<typeof controller.store.getSnapshot>) => T): T {
function bindSnapshot<State>(store: ObservableSnapshot<State>) {
return function useSnapshot<T>(selector: (state: State) => T): T {
return useSyncExternalStore(
listener => controller.store.subscribe(listener),
() => selector(controller.store.getSnapshot()),
listener => store.subscribe(listener),
() => selector(store.getSnapshot()),
)
}
}
function bench() {
function bench(feedbackAvailable = false) {
const controller = new SessionLogDownloadController(async () => new Response('zip'), vi.fn())
const request = vi.fn((sessionId: SessionId) => controller.download(sessionId))
const dismiss = vi.fn((sessionId: SessionId) => { controller.dismiss(sessionId) })
const useSessionLogDownload = bindSessionExport(controller)
const openFeedback = vi.fn()
const feedback = createSnapshotStore(feedbackAvailable)
const useSessionLogDownload = bindSnapshot(controller.store)
const props = {
sessionId: SID,
useSessionLogDownload,
useFeedbackAvailable: bindSnapshot(feedback),
openFeedback,
request,
dismiss,
t: (key: keyof typeof en): string => en[key],
} as unknown as SessionLogDownloadDialogProps
} as unknown as SessionLogDownloadHeaderProps
const view = render(<SessionLogDownloadHeaderAction {...props} />)
return { controller, request, view }
return { controller, request, openFeedback, feedback, view }
}
afterEach(cleanup)
describe('Session export Header action', () => {
it('opens Session feedback and closes the menu without starting a download', () => {
const b = bench(true)
fireEvent.click(b.view.getByRole('button', { name: 'More actions' }))
fireEvent.click(b.view.getByRole('menuitem', { name: 'Feedback' }))
expect(b.openFeedback).toHaveBeenCalledWith(SID)
expect(b.request).not.toHaveBeenCalled()
expect(b.view.queryByRole('menu')).toBeNull()
})
it('keeps export available without the feedback plugin', () => {
const b = bench()
fireEvent.click(b.view.getByRole('button', { name: 'More actions' }))
expect(b.view.queryByRole('menuitem', { name: 'Feedback' })).toBeNull()
expect(b.view.getByRole('menuitem', { name: 'Download session log' })).toBeTruthy()
})
it('updates the open menu when feedback becomes available, unloads, and reloads', () => {
const b = bench()
fireEvent.click(b.view.getByRole('button', { name: 'More actions' }))
expect(b.view.queryByRole('menuitem', { name: 'Feedback' })).toBeNull()
act(() => { b.feedback.set(true) })
expect(b.view.getByRole('menuitem', { name: 'Feedback' })).toBeTruthy()
act(() => { b.feedback.set(false) })
expect(b.view.queryByRole('menuitem', { name: 'Feedback' })).toBeNull()
expect(b.view.getByRole('menuitem', { name: 'Download session log' })).toBeTruthy()
act(() => { b.feedback.set(true) })
fireEvent.click(b.view.getByRole('menuitem', { name: 'Feedback' }))
expect(b.openFeedback).toHaveBeenCalledWith(SID)
expect(b.request).not.toHaveBeenCalled()
expect(b.view.queryByRole('menu')).toBeNull()
})
it('opens the more-actions menu and downloads through the shared controller', async () => {
const b = bench()
const button = b.view.getByRole('button', { name: 'More actions' })
@@ -61,18 +100,20 @@ describe('Session export Header action', () => {
})
it('disables the download row while either entry path downloads this Session', async () => {
const b = bench()
const b = bench(true)
let release!: (response: Response) => void
const pending = new Promise<Response>((resolve) => { release = resolve })
const controller = new SessionLogDownloadController(() => pending, vi.fn())
const useSessionLogDownload = bindSessionExport(controller)
const useSessionLogDownload = bindSnapshot(controller.store)
b.view.rerender(<SessionLogDownloadHeaderAction {...({
sessionId: SID,
useSessionLogDownload,
useFeedbackAvailable: bindSnapshot(b.feedback),
openFeedback: b.openFeedback,
request: (sessionId: SessionId) => controller.download(sessionId),
dismiss: (sessionId: SessionId) => { controller.dismiss(sessionId) },
t: (key: keyof typeof en): string => en[key],
} as unknown as SessionLogDownloadDialogProps)} />)
} as unknown as SessionLogDownloadHeaderProps)} />)
const download = controller.download(SID)
const button = b.view.getByRole('button', { name: 'More actions' })
@@ -80,6 +121,7 @@ describe('Session export Header action', () => {
fireEvent.click(button)
const item = b.view.getByRole('menuitem', { name: 'Download session log' })
expect((item as HTMLButtonElement).disabled).toBe(true)
expect((b.view.getByRole('menuitem', { name: 'Feedback' }) as HTMLButtonElement).disabled).toBe(false)
release(new Response('zip'))
await download
await waitFor(() => { expect(button.getAttribute('aria-busy')).toBe('false') })
@@ -19,6 +19,7 @@
{ "path": "../../client/store" },
{ "path": "../../client/ui-commands" },
{ "path": "../../client/ui-conversation" },
{ "path": "../../client/ui-message-feedback" },
{ "path": "../../client/ui-primitives" },
{ "path": "../../client/ui-renderer" },
{ "path": "../../client/ui-session" },
+3
View File
@@ -9125,6 +9125,9 @@ importers:
'@deepseek-ai/dsh-client-ui-conversation':
specifier: workspace:^
version: link:../../client/ui-conversation
'@deepseek-ai/dsh-client-ui-message-feedback':
specifier: workspace:^
version: link:../../client/ui-message-feedback
'@deepseek-ai/dsh-client-ui-primitives':
specifier: workspace:^
version: link:../../client/ui-primitives
+1
View File
@@ -175,6 +175,7 @@ export const SERVICE_WALK_EXEMPTIONS: Record<string, string> = {
settingsScope: 'client-side settings-namespace transport service — packages/client/ui-settings/README.md owns the API',
chatFileMentions: 'client-side slot-contract accessor (ChatFileMentions) — packages/client/ui-chat/README.md owns the API',
commandUi: 'client-side interface-typed browser service — packages/client/ui-commands/README.md owns the API',
feedbackUi: 'client-side feedback dialog service — packages/client/ui-message-feedback/README.md owns the API',
conversation: 'client-side interface-typed browser service — packages/client/ui-conversation/README.md owns the API',
layout: 'client-side interface-typed browser service — packages/client/ui-layout/README.md owns the API',
locale: 'client-side interface-typed browser service — packages/client/locale/README.md owns the API',