From 9ce43f925c94b9cb988b16f92bffd92a54405670 Mon Sep 17 00:00:00 2001 From: Kaige-Gao Date: Thu, 17 Sep 2026 16:40:13 +0800 Subject: [PATCH 1/2] feat(web): add feedback to session header menu --- ...8-feedback-dialog-and-categories.i18n.yaml | 4 +-- ...26-09-08-feedback-dialog-and-categories.md | 2 ++ ...09-08-feedback-dialog-and-categories.zh.md | 2 ++ apps/web/tests/message-feedback.e2e.ts | 36 +++++++++++++++++++ .../ui-message-feedback/README.i18n.yaml | 4 +-- packages/client/ui-message-feedback/README.md | 4 +-- .../client/ui-message-feedback/README.zh.md | 4 +-- .../ui-message-feedback/src/client/index.ts | 22 +++++++++++- .../tests/browser-plugin.client.spec.tsx | 14 ++++++++ .../session-log-export/README.i18n.yaml | 4 +-- .../session-log-export/README.md | 2 ++ .../session-log-export/README.zh.md | 2 ++ .../session-log-export/package.json | 1 + .../src/client/HeaderAction.tsx | 33 +++++++++++++---- .../session-log-export/src/client/index.ts | 17 ++++++--- .../session-log-export/src/client/locales.ts | 2 ++ .../tests/client-apply.client.spec.tsx | 21 +++++++++++ .../tests/header-action.client.spec.tsx | 32 ++++++++++++++--- .../session-log-export/tsconfig.client.json | 1 + pnpm-lock.yaml | 3 ++ scripts/gen-cordis-catalog.ts | 1 + 21 files changed, 184 insertions(+), 27 deletions(-) diff --git a/.agents/notes/implemented/feature/2026-09-08-feedback-dialog-and-categories.i18n.yaml b/.agents/notes/implemented/feature/2026-09-08-feedback-dialog-and-categories.i18n.yaml index 16c17f3405..ad7aa6aa6e 100644 --- a/.agents/notes/implemented/feature/2026-09-08-feedback-dialog-and-categories.i18n.yaml +++ b/.agents/notes/implemented/feature/2026-09-08-feedback-dialog-and-categories.i18n.yaml @@ -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: 271eb080dcca866ddbb5fee9df2d72ef9a1300ee +2026-09-08-feedback-dialog-and-categories.zh.md: 10f662e7d020c283bc250ffc75d71f757ddd6516 diff --git a/.agents/notes/implemented/feature/2026-09-08-feedback-dialog-and-categories.md b/.agents/notes/implemented/feature/2026-09-08-feedback-dialog-and-categories.md index ee656946a9..271eb080dc 100644 --- a/.agents/notes/implemented/feature/2026-09-08-feedback-dialog-and-categories.md +++ b/.agents/notes/implemented/feature/2026-09-08-feedback-dialog-and-categories.md @@ -14,6 +14,8 @@ 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 ` 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 diff --git a/.agents/notes/implemented/feature/2026-09-08-feedback-dialog-and-categories.zh.md b/.agents/notes/implemented/feature/2026-09-08-feedback-dialog-and-categories.zh.md index ef2b2d4670..10f662e7d0 100644 --- a/.agents/notes/implemented/feature/2026-09-08-feedback-dialog-and-categories.zh.md +++ b/.agents/notes/implemented/feature/2026-09-08-feedback-dialog-and-categories.zh.md @@ -14,6 +14,8 @@ Web 客户端有两条互不相连的反馈路径,且都没有可见结果。` `ui-message-feedback` 成为 Web 反馈界面。每个 Session 一个 `FeedbackSurface`,拥有消息反馈控制器、负责草稿、提交与 toast 序号的 `FeedbackDialogController`,以及两者之间的路由:消息目标经消息控制器 put 一条带弹窗分类与备注的所选评分,Session 目标经 `ctx.remote.sessionFeedback` 记录。`conversation.input.overlay` 的 `FeedbackDialog` 条目从弹窗 store 渲染 Modal 与 Toast 基元。宿主 `feedback` 命令上的装饰让菜单选中或不带参数的回车为 Session 打开弹窗,而 `/feedback ` 仍到达宿主;它使用 `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 展示本地化错误。 ## 考虑过的替代方案 diff --git a/apps/web/tests/message-feedback.e2e.ts b/apps/web/tests/message-feedback.e2e.ts index df89180c18..f26202d4b8 100644 --- a/apps/web/tests/message-feedback.e2e.ts +++ b/apps/web/tests/message-feedback.e2e.ts @@ -145,4 +145,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) }) diff --git a/packages/client/ui-message-feedback/README.i18n.yaml b/packages/client/ui-message-feedback/README.i18n.yaml index bdd5f1e664..642559b51f 100644 --- a/packages/client/ui-message-feedback/README.i18n.yaml +++ b/packages/client/ui-message-feedback/README.i18n.yaml @@ -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: bc33b02c6966bfa851614ef616c1ff9c583ae67d +README.zh.md: 88c1ba476c1a9c2a2df4b6cad471d78af65b83c9 diff --git a/packages/client/ui-message-feedback/README.md b/packages/client/ui-message-feedback/README.md index b37278e8d1..bc33b02c69 100644 --- a/packages/client/ui-message-feedback/README.md +++ b/packages/client/ui-message-feedback/README.md @@ -25,7 +25,7 @@ This package is the Web GUI's feedback surface: the Like/Dislike pair in the fin ## 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 ` 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 either the composer menu or the Session Header’s more-actions menu opens the same 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 ` 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
Implementation internals — click to expand -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. diff --git a/packages/client/ui-message-feedback/README.zh.md b/packages/client/ui-message-feedback/README.zh.md index cd23306164..88c1ba476c 100644 --- a/packages/client/ui-message-feedback/README.zh.md +++ b/packages/client/ui-message-feedback/README.zh.md @@ -25,7 +25,7 @@ kind: "package-reference" ## 使用本包 -与 `ui-conversation`、`ui-commands` 一起挂载本插件;Like/Dislike 对随即出现在每个轮次收尾助手消息的动作行中,位于复制与分支之间,输入框菜单里的「反馈」行则打开弹窗。已记录的评分显示实心图标,不需要悬停也一直可见。点赞和点踩都会打开弹窗:七个分类标签和一个详情框都可不填;提交后才会记录带所填内容的对应评分并弹出感谢 toast,对话日志随每个反馈事件一起投递。再次点击已记录的评分会直接撤回,不打开弹窗。不带文本的 `/feedback`,无论是从菜单选中还是直接输入后发送,都会为 Session 打开同一个弹窗;`/feedback ` 仍走宿主命令路径并显示确认行。 +与 `ui-conversation`、`ui-commands` 一起挂载本插件;Like/Dislike 对随即出现在每个轮次收尾助手消息的动作行中,位于复制与分支之间,输入框菜单或会话标题栏更多操作菜单里的「反馈」会打开同一个弹窗。已记录的评分显示实心图标,不需要悬停也一直可见。点赞和点踩都会打开弹窗:七个分类标签和一个详情框都可不填;提交后才会记录带所填内容的对应评分并弹出感谢 toast,对话日志随每个反馈事件一起投递。再次点击已记录的评分会直接撤回,不打开弹窗。不带文本的 `/feedback`,无论是从菜单选中还是直接输入后发送,都会为 Session 打开同一个弹窗;`/feedback ` 仍走宿主命令路径并显示确认行。 ### 失败 @@ -39,7 +39,7 @@ kind: "package-reference"
实现细节——点击展开 -本包贡献 `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。 diff --git a/packages/client/ui-message-feedback/src/client/index.ts b/packages/client/ui-message-feedback/src/client/index.ts index 91e6718f62..d421bf4d72 100644 --- a/packages/client/ui-message-feedback/src/client/index.ts +++ b/packages/client/ui-message-feedback/src/client/index.ts @@ -37,6 +37,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' @@ -65,6 +80,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 +134,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') }) } diff --git a/packages/client/ui-message-feedback/tests/browser-plugin.client.spec.tsx b/packages/client/ui-message-feedback/tests/browser-plugin.client.spec.tsx index 2bad94b036..e41e7d599a 100644 --- a/packages/client/ui-message-feedback/tests/browser-plugin.client.spec.tsx +++ b/packages/client/ui-message-feedback/tests/browser-plugin.client.spec.tsx @@ -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() diff --git a/packages/session-query/session-log-export/README.i18n.yaml b/packages/session-query/session-log-export/README.i18n.yaml index ae845c1725..3e072029dd 100644 --- a/packages/session-query/session-log-export/README.i18n.yaml +++ b/packages/session-query/session-log-export/README.i18n.yaml @@ -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: 23388e10b9c64071a666e9842a669e37d6b9545d +README.zh.md: 2af96f8621745fd6393f03905e4c6a978dbaf400 diff --git a/packages/session-query/session-log-export/README.md b/packages/session-query/session-log-export/README.md index 8697b0c2c1..23388e10b9 100644 --- a/packages/session-query/session-log-export/README.md +++ b/packages/session-query/session-log-export/README.md @@ -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-.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. diff --git a/packages/session-query/session-log-export/README.zh.md b/packages/session-query/session-log-export/README.zh.md index fe60c6ab8c..2af96f8621 100644 --- a/packages/session-query/session-log-export/README.zh.md +++ b/packages/session-query/session-log-export/README.zh.md @@ -27,6 +27,8 @@ kind: "package-reference" 当 Web bundle 需要让用户导出会话日志时使用本包。它需要 Connection、命令注册表、Session 查询与持久化以及附件服务。挂载插件,然后在 Session Header 的更多操作菜单中选择 `下载 Session 日志` 或输入 `/export`;浏览器会下载 `dsh-session-.zip`。 +挂载 `ui-message-feedback` 时,同一菜单还提供“反馈”,打开已有的 Session 反馈弹窗。打开或关闭该弹窗不会导出 Session 或提交反馈。反馈入口随反馈插件的可用状态显示;导出功能保持独立可用。 + ### 何时选择 为需要带可见下载弹窗的面向用户的会话导出的 Web 部署选择它。需要程序化或 Host 侧导出时避免使用:本包产生的是浏览器下载,而非 Host 路径写入。日志从持久化读句柄序列化而来,因此任何已挂载后端都受支持。 diff --git a/packages/session-query/session-log-export/package.json b/packages/session-query/session-log-export/package.json index 75d743253d..5edbe45d8e 100644 --- a/packages/session-query/session-log-export/package.json +++ b/packages/session-query/session-log-export/package.json @@ -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:^", diff --git a/packages/session-query/session-log-export/src/client/HeaderAction.tsx b/packages/session-query/session-log-export/src/client/HeaderAction.tsx index cb20cb9f9d..5e5b472659 100644 --- a/packages/session-query/session-log-export/src/client/HeaderAction.tsx +++ b/packages/session-query/session-log-export/src/client/HeaderAction.tsx @@ -1,16 +1,31 @@ import { useState } from 'react' import type { ReactNode } from 'react' -import { IconDownloadOutline16, IconEllipsisOutline16, 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 { IconDownloadOutline16, IconEllipsisOutline16, IconPaperPlaneOutline14, 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' +/** The optional feedback plugin controls whether the Header offers its form. */ +export interface SessionLogDownloadHeaderInjected extends SessionLogDownloadDialogInjected { + hooks: SessionLogDownloadDialogInjected['hooks'] & { feedbackAvailable: ObservableSnapshot } + /** @param sessionId - Session whose existing feedback form to open. */ + openFeedback: (sessionId: SessionId) => void +} + +/** Session download props plus the optional feedback action. */ +export type SessionLogDownloadHeaderProps = SessionLogDownloadDialogProps & InjectFace + /** - * 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 +37,14 @@ export function SessionLogDownloadHeaderAction(props: SessionLogDownloadDialogPr align="end" dense onClose={() => { setOpen(false) }} - items={[{ id: 'download', label: t('menu.download'), icon: , disabled: busy }]} - onSelect={() => { + items={[ + { id: 'download', label: t('menu.download'), icon: , disabled: busy }, + ...feedbackAvailable ? [{ id: 'feedback', label: t('menu.feedback'), icon: }] : [], + ]} + onSelect={(id) => { setOpen(false) - void request(sessionId) + if (id === 'feedback') openFeedback(sessionId) + else void request(sessionId) }} anchor={(
-**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. diff --git a/packages/client/ui-message-feedback/README.zh.md b/packages/client/ui-message-feedback/README.zh.md index 88c1ba476c..a294c73c87 100644 --- a/packages/client/ui-message-feedback/README.zh.md +++ b/packages/client/ui-message-feedback/README.zh.md @@ -25,7 +25,7 @@ kind: "package-reference" ## 使用本包 -与 `ui-conversation`、`ui-commands` 一起挂载本插件;Like/Dislike 对随即出现在每个轮次收尾助手消息的动作行中,位于复制与分支之间,输入框菜单或会话标题栏更多操作菜单里的「反馈」会打开同一个弹窗。已记录的评分显示实心图标,不需要悬停也一直可见。点赞和点踩都会打开弹窗:七个分类标签和一个详情框都可不填;提交后才会记录带所填内容的对应评分并弹出感谢 toast,对话日志随每个反馈事件一起投递。再次点击已记录的评分会直接撤回,不打开弹窗。不带文本的 `/feedback`,无论是从菜单选中还是直接输入后发送,都会为 Session 打开同一个弹窗;`/feedback ` 仍走宿主命令路径并显示确认行。 +与 `ui-conversation`、`ui-commands` 一起挂载本插件;Like/Dislike 对随即出现在每个轮次收尾助手消息的动作行中,位于复制与分支之间,输入框菜单里的「反馈」会打开同一个弹窗。挂载 `session-log-export` 后,会话标题栏的更多操作菜单也会增加「反馈」。已记录的评分显示实心图标,不需要悬停也一直可见。点赞和点踩都会打开弹窗:七个分类标签和一个详情框都可不填;提交后才会记录带所填内容的对应评分并弹出感谢 toast,对话日志随每个反馈事件一起投递。再次点击已记录的评分会直接撤回,不打开弹窗。不带文本的 `/feedback`,无论是从菜单选中还是直接输入后发送,都会为 Session 打开同一个弹窗;`/feedback ` 仍走宿主命令路径并显示确认行。 ### 失败 @@ -90,4 +90,4 @@ kind: "package-reference"
-**运行时不变式:** 不发布伴生入口。插件持有两个 slot 注册、一个命令装饰,以及一个按 Session 划分的控制器对 map;它们都由插件 fiber 的同一个 effect disposer 释放。生命周期规格测试证明,所属 fiber 释放时会撤销所有注册并丢弃所有控制器,因此不存在需要在运行时检查的第二权威来源。 +**运行时不变式:** 不发布伴生入口。插件持有两个 slot 注册、一个命令装饰、`feedbackUi` 服务,以及一个按 Session 划分的控制器对 map;它们都随所属插件 fiber 释放。生命周期规格测试验证,fiber 释放时会撤销所有注册和服务并丢弃所有控制器,因此不存在需要在运行时检查的第二权威来源。 diff --git a/packages/client/ui-message-feedback/src/client/index.ts b/packages/client/ui-message-feedback/src/client/index.ts index d421bf4d72..4f26c3bb0d 100644 --- a/packages/client/ui-message-feedback/src/client/index.ts +++ b/packages/client/ui-message-feedback/src/client/index.ts @@ -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 */ @@ -60,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 { diff --git a/packages/session-query/session-log-export/README.i18n.yaml b/packages/session-query/session-log-export/README.i18n.yaml index 3e072029dd..87ba87930a 100644 --- a/packages/session-query/session-log-export/README.i18n.yaml +++ b/packages/session-query/session-log-export/README.i18n.yaml @@ -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: 23388e10b9c64071a666e9842a669e37d6b9545d +README.md: fb07e9bf00127ebea991a7bf10a8de8e35ad1210 README.zh.md: 2af96f8621745fd6393f03905e4c6a978dbaf400 diff --git a/packages/session-query/session-log-export/README.md b/packages/session-query/session-log-export/README.md index 23388e10b9..fb07e9bf00 100644 --- a/packages/session-query/session-log-export/README.md +++ b/packages/session-query/session-log-export/README.md @@ -27,7 +27,7 @@ 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-.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 `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 diff --git a/packages/session-query/session-log-export/src/client/HeaderAction.tsx b/packages/session-query/session-log-export/src/client/HeaderAction.tsx index 464647c96d..9810fb86d3 100644 --- a/packages/session-query/session-log-export/src/client/HeaderAction.tsx +++ b/packages/session-query/session-log-export/src/client/HeaderAction.tsx @@ -8,10 +8,13 @@ import { SessionLogDownloadDialog, type SessionLogDownloadDialogProps } from './ import type { SessionLogDownloadDialogInjected } from './Dialog.tsx' import css from './HeaderAction.module.css' -/** The optional feedback plugin controls whether the Header offers its form. */ +/** Session download controls with observable feedback availability and a Session feedback action. */ export interface SessionLogDownloadHeaderInjected extends SessionLogDownloadDialogInjected { hooks: SessionLogDownloadDialogInjected['hooks'] & { feedbackAvailable: ObservableSnapshot } - /** @param sessionId - Session whose existing feedback form to open. */ + /** + * 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 } diff --git a/packages/session-query/session-log-export/src/client/index.ts b/packages/session-query/session-log-export/src/client/index.ts index 9a26097148..bcba0dd581 100644 --- a/packages/session-query/session-log-export/src/client/index.ts +++ b/packages/session-query/session-log-export/src/client/index.ts @@ -56,6 +56,7 @@ export function apply(ctx: ClientContext): void { 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)) diff --git a/packages/session-query/session-log-export/tests/header-action.client.spec.tsx b/packages/session-query/session-log-export/tests/header-action.client.spec.tsx index eeb388670c..dc0da23e36 100644 --- a/packages/session-query/session-log-export/tests/header-action.client.spec.tsx +++ b/packages/session-query/session-log-export/tests/header-action.client.spec.tsx @@ -1,8 +1,9 @@ // @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 { SessionLogDownloadHeaderProps } from '../src/client/HeaderAction.tsx' @@ -10,11 +11,11 @@ import { en } from '../src/client/locales.ts' const SID = 'session-export-header' as SessionId -function bindSessionExport(controller: SessionLogDownloadController) { - return function useSessionLogDownload(selector: (state: ReturnType) => T): T { +function bindSnapshot(store: ObservableSnapshot) { + return function useSnapshot(selector: (state: State) => T): T { return useSyncExternalStore( - listener => controller.store.subscribe(listener), - () => selector(controller.store.getSnapshot()), + listener => store.subscribe(listener), + () => selector(store.getSnapshot()), ) } } @@ -24,18 +25,19 @@ function bench(feedbackAvailable = false) { const request = vi.fn((sessionId: SessionId) => controller.download(sessionId)) const dismiss = vi.fn((sessionId: SessionId) => { controller.dismiss(sessionId) }) const openFeedback = vi.fn() - const useSessionLogDownload = bindSessionExport(controller) + const feedback = createSnapshotStore(feedbackAvailable) + const useSessionLogDownload = bindSnapshot(controller.store) const props = { sessionId: SID, useSessionLogDownload, - useFeedbackAvailable: (select: (available: boolean) => unknown) => select(feedbackAvailable), + useFeedbackAvailable: bindSnapshot(feedback), openFeedback, request, dismiss, t: (key: keyof typeof en): string => en[key], } as unknown as SessionLogDownloadHeaderProps const view = render() - return { controller, request, openFeedback, view } + return { controller, request, openFeedback, feedback, view } } afterEach(cleanup) @@ -57,6 +59,24 @@ describe('Session export Header action', () => { 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' }) @@ -80,15 +100,15 @@ 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((resolve) => { release = resolve }) const controller = new SessionLogDownloadController(() => pending, vi.fn()) - const useSessionLogDownload = bindSessionExport(controller) + const useSessionLogDownload = bindSnapshot(controller.store) b.view.rerender( unknown) => select(true), + useFeedbackAvailable: bindSnapshot(b.feedback), openFeedback: b.openFeedback, request: (sessionId: SessionId) => controller.download(sessionId), dismiss: (sessionId: SessionId) => { controller.dismiss(sessionId) },