From 4430bb0ccfaf31f7761c30e39b5a60131998ca2d Mon Sep 17 00:00:00 2001 From: Kaige-Gao <102539609+Kaige-Gao@users.noreply.github.com> Date: Mon, 16 Nov 2026 20:55:19 +0800 Subject: [PATCH] fix(client): refresh file reference menus on locale changes --- .../src/client/contract/input.ts | 12 +++--- packages/client/ui-reference/README.i18n.yaml | 4 +- packages/client/ui-reference/README.md | 2 +- packages/client/ui-reference/README.zh.md | 2 +- .../ui-reference/src/client/context-menu.ts | 6 +-- .../tests/context-menu.client.spec.ts | 37 +++++++++++++++++-- 6 files changed, 47 insertions(+), 16 deletions(-) diff --git a/packages/client/ui-conversation/src/client/contract/input.ts b/packages/client/ui-conversation/src/client/contract/input.ts index e1a9c0cf6e..c2362f438e 100644 --- a/packages/client/ui-conversation/src/client/contract/input.ts +++ b/packages/client/ui-conversation/src/client/contract/input.ts @@ -1,10 +1,10 @@ /** - * Frozen input-machine contract. Types - * only. Three-tier visibility: business packages see InputState via the - * InputZone currency; the scoped input events carry the mutation verbs; the - * conversation wiring layer alone sees the full SessionInput. The draft text - * and its reference chips live in the shell's Lexical editor; the machine - * here is the submit plane (phase, claim, attempt) alone. + * Input-machine types and Session-addressed draft operations. Business packages + * read InputState through InputZone and use scoped input events for guarded + * mutations. Conversation wiring and direct draft consumers resolve SessionInput + * through conversation.input.for(), including file insertion through addFiles. + * Draft text and reference chips live in the shell's Lexical editor; the machine + * here owns submission state (phase, claim, attempt). */ import type { Context } from '@deepseek-ai/cordis' import type { SessionBinding } from '@deepseek-ai/dsh-api-session-controller/client' diff --git a/packages/client/ui-reference/README.i18n.yaml b/packages/client/ui-reference/README.i18n.yaml index 8c7cbebdd2..229d0d9363 100644 --- a/packages/client/ui-reference/README.i18n.yaml +++ b/packages/client/ui-reference/README.i18n.yaml @@ -18,8 +18,8 @@ en: 779a9a534eaad38b zh: 3dd159a2c35702d6 /deepseek-ai-dsh-client-ui-reference/use-this-package/what-a-pick-inserts: - en: 817aa123e8033ff7 - zh: 19e6593b61e8b5b7 + en: 27ca6ef7a0fbe913 + zh: aa413e010a563593 /deepseek-ai-dsh-client-ui-reference/use-this-package/failure-behavior: en: 386bbd9dc0a2c322 zh: 3014a367157532b7 diff --git a/packages/client/ui-reference/README.md b/packages/client/ui-reference/README.md index ed3c545b1d..96f4cc47e5 100644 --- a/packages/client/ui-reference/README.md +++ b/packages/client/ui-reference/README.md @@ -33,7 +33,7 @@ A file closes completion as an atomic inline reference displayed with a file gly A session pick inserts an atomic inline reference whose hidden `ref` and clipboard representation is the canonical `@[label](dsh-session:…)` mention returned by the Host; its visible form is a chat-bubble glyph plus the session title. Sending carries the mention through `session.prompt`, and the session-reference service validates it and captures model context at `agent/pre-step`. -The shared file context menu ends with **Add to chat**. It inserts the clicked file as the same kind of reference into that Session’s draft, preserves existing text and selection, and returns focus without sending. The reference captures the resolved absolute path; line numbers are not included. The action is disabled when the Session cannot be edited or the path cannot use the mention grammar. +The shared file context menu ends with **Add to chat**. It inserts the clicked file as the same kind of reference into that Session’s draft, preserves existing text and selection, and returns focus without sending. The reference captures the resolved absolute path; line numbers are not included. The action is disabled when the Session cannot be edited or the path cannot use the mention grammar. An open menu updates its label and failure feedback when the interface language changes. ### Failure behavior diff --git a/packages/client/ui-reference/README.zh.md b/packages/client/ui-reference/README.zh.md index ba9a3d24a6..b08b9164fe 100644 --- a/packages/client/ui-reference/README.zh.md +++ b/packages/client/ui-reference/README.zh.md @@ -33,7 +33,7 @@ Web 用户需要从同一个 `@` 补全菜单提及文件、文件夹或会话 选择会话会插入一个原子的行内引用,其隐藏 `ref` 与剪贴板表示均为宿主返回的规范 `@[label](dsh-session:…)` mention;可见形式为聊天气泡图标加会话标题。发送会经 `session.prompt` 携带该 mention,session-reference 服务会在 `agent/pre-step` 校验它并捕获模型上下文。 -共享文件右键菜单最底部提供**添加到对话**。它将所选文件作为同类引用插入该 Session 的草稿,保留现有文字和选中内容,恢复输入焦点但不发送。引用记录解析后的绝对路径,不包含行号。Session 不可编辑或路径无法用 mention 语法表示时,此入口不可用。 +共享文件右键菜单最底部提供**添加到对话**。它将所选文件作为同类引用插入该 Session 的草稿,保留现有文字和选中内容,恢复输入焦点但不发送。引用记录解析后的绝对路径,不包含行号。Session 不可编辑或路径无法用 mention 语法表示时,此入口不可用。切换界面语言时,已打开菜单的标题和失败提示随之更新。 ### 失败行为 diff --git a/packages/client/ui-reference/src/client/context-menu.ts b/packages/client/ui-reference/src/client/context-menu.ts index 8bad653ddd..2786d3de9d 100644 --- a/packages/client/ui-reference/src/client/context-menu.ts +++ b/packages/client/ui-reference/src/client/context-menu.ts @@ -4,7 +4,7 @@ import type { ContextMenuTargetMap } from '@deepseek-ai/dsh-client-ui-context-me import type {} from '@deepseek-ai/dsh-client-ui-conversation/client' import { IconPlusOutlineRegular } from '@deepseek-ai/dsh-client-ui-primitives' import { formatFileMention } from '@deepseek-ai/dsh-file-reference/grammar' -import { resolveWorkspacePath } from '@deepseek-ai/dsh-util-workspace-path' +import { resolveWorkspacePath, workspaceTitleOf } from '@deepseek-ai/dsh-util-workspace-path' import type { ReferenceKey } from './locales.ts' /** @@ -34,7 +34,7 @@ export function registerReferenceMenu(ctx: Context, t: (key: ReferenceKey) => st id: 'reference.file', target: 'file', order: 300, observe: (target) => { const current = targetInput(target) - return current === undefined ? [] : [current.binding.session, current.input.state, current.blocks] + return current === undefined ? [ctx.locale] : [ctx.locale, current.binding.session, current.input.state, current.blocks] }, resolve: (target) => { const current = targetInput(target) @@ -47,7 +47,7 @@ export function registerReferenceMenu(ctx: Context, t: (key: ReferenceKey) => st run: () => { if (mention === undefined || current === undefined || !current.editable() || !current.input.addFiles([{ - source: 'reference', ref: mention, label: path.slice(Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\')) + 1), + source: 'reference', ref: mention, label: workspaceTitleOf(path), appearance: 'file', clipboardText: mention, }], [])) throw new Error('File reference insertion unavailable') current.input.focus() diff --git a/packages/client/ui-reference/tests/context-menu.client.spec.ts b/packages/client/ui-reference/tests/context-menu.client.spec.ts index 1ad5986881..5530747b41 100644 --- a/packages/client/ui-reference/tests/context-menu.client.spec.ts +++ b/packages/client/ui-reference/tests/context-menu.client.spec.ts @@ -5,6 +5,7 @@ import { SlotTestRuntime } from '@deepseek-ai/dsh-client-test-runtime' import { MenuRegistry } from '@deepseek-ai/dsh-client-ui-context-menu/src/client/registry.ts' import { SessionInputShell } from '@deepseek-ai/dsh-client-ui-conversation/src/client/input/facade.ts' import { ComposerBlockRegistry } from '@deepseek-ai/dsh-client-ui-conversation/src/client/input/blocks.ts' +import { LocaleRuntime } from '@deepseek-ai/dsh-client-locale/client' import type { SessionId } from '@deepseek-ai/dsh-session/types' import type { ContextMenuTargetMap } from '@deepseek-ai/dsh-client-ui-context-menu/client' import { registerReferenceMenu } from '../src/client/context-menu.ts' @@ -16,6 +17,10 @@ const actionId = 'reference.file/addToChat' async function bench() { const runtime = await SlotTestRuntime.create() onTestFinished(() => runtime.dispose()) + const locale = new LocaleRuntime(runtime.ctx) + runtime.ctx.provide('locale', locale) + runtime.ctx.effect(() => locale.register('reference', { en, zh })) + locale.setLocale('en') await runtime.declare({ 'contextMenu.icon': { kind: 'keyed', scope: 'root', inline: true } }) await runtime.sessions.add({ id, summary: { cwd: '/workspace' } }) const owner = runtime.sessions.retain(id) @@ -36,8 +41,8 @@ async function bench() { onTestFinished(() => { menus.dispose() }) runtime.ctx.provide('contextMenus', { register: menus.register.bind(menus) }) const fiber = runtime.ctx.plugin({ - inject: ['slots', 'sessions', 'conversation', 'contextMenus'], - apply: (ctx) => { registerReferenceMenu(ctx, key => en[key]) }, + inject: ['slots', 'sessions', 'conversation', 'contextMenus', 'locale'], + apply: (ctx) => { registerReferenceMenu(ctx, locale.bind('reference')) }, }) await fiber.await() const menu = async (value: Partial = {}) => { @@ -46,7 +51,7 @@ async function bench() { await result.ready return result } - return { runtime, owner, binding, shell, sink, focus, blocks, resolveInput, failed, menus, fiber, menu } + return { runtime, locale, owner, binding, shell, sink, focus, blocks, resolveInput, failed, menus, fiber, menu } } it('appends the final action after other providers and inserts the captured file without sending', async () => { @@ -158,6 +163,32 @@ it('withdraws open menu actions and their icon on plugin disposal', async () => expect(zh['menu.addToChat']).toBe('添加到对话') }) +it('refreshes open labels and failure feedback when the locale changes', async () => { + const b = await bench() + const menu = await b.menu() + const unavailable = await b.menu({ sessionId: 'absent' as SessionId }) + expect(menu.source.getSnapshot()[0]?.label).toBe(en['menu.addToChat']) + expect(unavailable.source.getSnapshot()[0]?.label).toBe(en['menu.addToChat']) + b.locale.setLocale('zh') + expect(menu.source.getSnapshot()[0]?.label).toBe(zh['menu.addToChat']) + expect(unavailable.source.getSnapshot()[0]?.label).toBe(zh['menu.addToChat']) + vi.spyOn(b.shell, 'addFiles').mockReturnValue(false) + menu.select(actionId) + expect(b.failed).toHaveBeenCalledWith(zh['menu.addToChatFailed']) + await b.fiber.dispose() + b.locale.setLocale('en') + expect(unavailable.source.getSnapshot()).toEqual([]) +}) + +it.each(['/work/a b.md', 'C:\\work\\a b.md', '\\\\server\\share\\a b.md', '/work/a b.md/'])( + 'uses the final nonempty path segment as the reference label: %j', async (path) => { + const b = await bench() + const menu = await b.menu({ path }) + menu.select(actionId) + expect(b.shell.snapshot.occurrences).toMatchObject([{ label: 'a b.md', ref: `@"${path}"` }]) + }, +) + it('refuses direct file insertion after the draft editor is disposed', async () => { const b = await bench() b.shell.setDraft('Keep this')