From 382c70cb035332e8bfb495a2a6684d7aea16896f Mon Sep 17 00:00:00 2001 From: Danyang Chen Date: Fri, 20 Nov 2026 15:38:50 +0800 Subject: [PATCH] Read a remote file chip's download title in the window's language (#3114) Docs-not-needed: one dictionary entry and one draw site in the chat cells; no architecture change. --- changelog.d/3114-remote-file-chip-zh.fixed.md | 1 + core/client.js | 6 ++- core/src/client/cells.js | 2 +- core/src/client/i18n.js | 4 ++ core/test/empty-message-cell.test.js | 43 ++++++++++++++++++- patches/ds-bot/0001-core-fixes.patch | 6 ++- patches/ds-bot/0003-flybot-api-client.patch | 2 +- patches/ds-bot/0008-client-bundle.patch | 8 +++- .../files/test/empty-message-cell.test.js | 43 ++++++++++++++++++- 9 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 changelog.d/3114-remote-file-chip-zh.fixed.md diff --git a/changelog.d/3114-remote-file-chip-zh.fixed.md b/changelog.d/3114-remote-file-chip-zh.fixed.md new file mode 100644 index 000000000..32ccfb87a --- /dev/null +++ b/changelog.d/3114-remote-file-chip-zh.fixed.md @@ -0,0 +1 @@ +A remote file chip in a chat now explains its download in a zh window: the hover title says the file comes from a remote Bot and is untrusted, while the file name stays exactly as the sender sent it ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)). diff --git a/core/client.js b/core/client.js index 9a9bfa9a0..5e98643ff 100644 --- a/core/client.js +++ b/core/client.js @@ -1069,6 +1069,10 @@ var ZH = { Reactions: "表情", "Message actions": "消息操作", Download: "下载", + // #3114 cut 32: the remote file chip's hover title. The name is the sender's data and is filled + // in untranslated; the two words that make the chip safe to click — untrusted, and a remote Bot — + // stay in the sentence. + "Download {name} (untrusted file from a remote Bot)": "下载 {name}(来自远程 Bot 的不可信文件)", "Clipboard unavailable": "剪贴板不可用,请手动选择文字复制", "Could not copy message": "未能复制消息,请重试或手动选择文字复制", "Could not download message": "未能下载消息,请重试或复制正文", @@ -8238,7 +8242,7 @@ function RemoteFiles({ files, plugin, botId }) { { className: "bt-file-chips" }, files.map((file) => (0, import_react12.createElement)( "button", - { key: file.id, type: "button", className: "bt-file-chip", disabled: busy === file.id, title: `Download ${file.name} (untrusted file from a remote Bot)`, onClick: () => download2(file) }, + { key: file.id, type: "button", className: "bt-file-chip", disabled: busy === file.id, title: t("Download {name} (untrusted file from a remote Bot)", { name: file.name }), onClick: () => download2(file) }, `📎 ${file.name} · ${fileSize(file.size)}` )), error ? (0, import_react12.createElement)("span", { className: "bt-file-error", role: "alert" }, error) : null diff --git a/core/src/client/cells.js b/core/src/client/cells.js index 378c1ea30..03b13e624 100644 --- a/core/src/client/cells.js +++ b/core/src/client/cells.js @@ -460,7 +460,7 @@ function RemoteFiles({ files, plugin, botId }) { } } return h('div', { className: 'bt-file-chips' }, - files.map(file => h('button', { key: file.id, type: 'button', className: 'bt-file-chip', disabled: busy === file.id, title: `Download ${file.name} (untrusted file from a remote Bot)`, onClick: () => download(file) }, + files.map(file => h('button', { key: file.id, type: 'button', className: 'bt-file-chip', disabled: busy === file.id, title: t('Download {name} (untrusted file from a remote Bot)', { name: file.name }), onClick: () => download(file) }, `📎 ${file.name} · ${fileSize(file.size)}`)), error ? h('span', { className: 'bt-file-error', role: 'alert' }, error) : null) } diff --git a/core/src/client/i18n.js b/core/src/client/i18n.js index 80a7370d6..37ec5c435 100644 --- a/core/src/client/i18n.js +++ b/core/src/client/i18n.js @@ -1019,6 +1019,10 @@ const ZH = { Reactions: '表情', 'Message actions': '消息操作', Download: '下载', + // #3114 cut 32: the remote file chip's hover title. The name is the sender's data and is filled + // in untranslated; the two words that make the chip safe to click — untrusted, and a remote Bot — + // stay in the sentence. + 'Download {name} (untrusted file from a remote Bot)': '下载 {name}(来自远程 Bot 的不可信文件)', 'Clipboard unavailable': '剪贴板不可用,请手动选择文字复制', 'Could not copy message': '未能复制消息,请重试或手动选择文字复制', 'Could not download message': '未能下载消息,请重试或复制正文', diff --git a/core/test/empty-message-cell.test.js b/core/test/empty-message-cell.test.js index 0e4fbc979..13ea8c00e 100644 --- a/core/test/empty-message-cell.test.js +++ b/core/test/empty-message-cell.test.js @@ -8,8 +8,15 @@ import { build } from 'esbuild' // with nothing in it, under the trace row of the turn that produced it. The draw is checked where a // person reads it: the bubbles of one message (a Bot's own chat) and a group chat's reply rows. async function load(entry) { + // #3114 cut 32: one entry exports the cells and the dictionary they read, so `installLocale` binds + // the copy `t` reaches. Two separate bundles would bind a dictionary no cell ever looks at. const bundle = await build({ - entryPoints: [fileURLToPath(new URL(`../src/client/${entry}`, import.meta.url))], + stdin: { + contents: `export * from ${JSON.stringify(fileURLToPath(new URL(`../src/client/${entry}`, import.meta.url)))}\nexport { DICTIONARY, installLocale } from ${JSON.stringify(fileURLToPath(new URL('../src/client/i18n.js', import.meta.url)))}`, + resolveDir: fileURLToPath(new URL('../src/client', import.meta.url)), + sourcefile: 'cells-and-dictionary.js', + loader: 'js', + }, bundle: true, format: 'cjs', platform: 'node', write: false, external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'], }) @@ -46,7 +53,7 @@ const find = (node, match) => { } const count = (node, cls) => find(node, item => String(item.props?.className ?? '').split(/\s+/).includes(cls)).length -const { Bubbles, GroupReplies, RemoteMessage } = await load('cells.js') +const { Bubbles, GroupReplies, RemoteMessage, DICTIONARY, installLocale } = await load('cells.js') const chief = { id: 'chief', name: 'Chief', color: 'green' } const writer = { id: 'writer', name: 'Writer', color: 'blue' } @@ -91,3 +98,35 @@ test("#2123: a friend's line with no text keeps its files and draws no empty bub assert.equal(count(attached, 'bt-bubble'), 0, 'the attachment stays, the empty bubble does not') assert.equal(count(attached, 'bt-remote-msg'), 1) }) + +// #3114 cut 32: the chips' hover title is a sentence, so the window's language decides it; the file +// name is the sender's data and rides through `{name}` untranslated. +const CHIP_FILES = [ + { id: 'f1', name: 'log.txt', size: 12, mime: 'text/plain' }, + { id: 'f2', name: '报告 2026.pdf', size: 2048, mime: 'application/pdf' }, +] +const fill = (text, params) => text.replace(/\{(\w+)\}/g, (match, name) => (name in params ? String(params[name]) : match)) +const inLang = (active, draw) => { + const zh = key => active.startsWith('zh') ? DICTIONARY.zh[key] ?? key : key + const off = installLocale({ register: () => () => {}, bind: () => (key, params) => fill(zh(key), params ?? {}), getLocale: () => ({ active }) }) + try { return draw() } finally { off() } +} +const chipTitles = files => find(expand(RemoteMessage({ + source: { remote: { handle: '@coder.bob.home', senderName: 'Bob’s Coder' }, senderName: 'Bob’s Coder', attachments: files }, + text: '', roster, actions, sessionId: 'chat', msgKey: 'chat:turn:3', +}), ['RemoteFiles']), node => node.props?.className === 'bt-file-chip').map(node => node.props.title) + +test('#3114 cut 32: a zh window reads the remote file chip as an untrusted file from a remote Bot', () => { + assert.deepEqual(inLang('zh-CN', () => chipTitles(CHIP_FILES)), [ + '下载 log.txt(来自远程 Bot 的不可信文件)', + '下载 报告 2026.pdf(来自远程 Bot 的不可信文件)', + ]) +}) + +test('#3114 cut 32: an English window keeps the chip title exactly as it reads today', () => { + assert.deepEqual(inLang('en', () => chipTitles(CHIP_FILES)), [ + 'Download log.txt (untrusted file from a remote Bot)', + 'Download 报告 2026.pdf (untrusted file from a remote Bot)', + ]) + assert.equal(DICTIONARY.zh['Download {name} (untrusted file from a remote Bot)'], '下载 {name}(来自远程 Bot 的不可信文件)') +}) diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index e6cf9882b..e2062654a 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -1587,7 +1587,7 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js // Bot exchange 'Bot exchange': 'Bot 间对话', -@@ -390,11 +390,18 @@ const ZH = { +@@ -390,11 +390,22 @@ const ZH = { Reply: '回复', 'More message actions': '更多操作', More: '更多', @@ -1595,6 +1595,10 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js Reactions: '表情', 'Message actions': '消息操作', Download: '下载', ++ // #3114 cut 32: the remote file chip's hover title. The name is the sender's data and is filled ++ // in untranslated; the two words that make the chip safe to click — untrusted, and a remote Bot — ++ // stay in the sentence. ++ 'Download {name} (untrusted file from a remote Bot)': '下载 {name}(来自远程 Bot 的不可信文件)', + 'Clipboard unavailable': '剪贴板不可用,请手动选择文字复制', + 'Could not copy message': '未能复制消息,请重试或手动选择文字复制', + 'Could not download message': '未能下载消息,请重试或复制正文', diff --git a/patches/ds-bot/0003-flybot-api-client.patch b/patches/ds-bot/0003-flybot-api-client.patch index 245afe481..a4467dc37 100644 --- a/patches/ds-bot/0003-flybot-api-client.patch +++ b/patches/ds-bot/0003-flybot-api-client.patch @@ -1054,7 +1054,7 @@ diff --git a/src/client/cells.js b/src/client/cells.js + } + } + return h('div', { className: 'bt-file-chips' }, -+ files.map(file => h('button', { key: file.id, type: 'button', className: 'bt-file-chip', disabled: busy === file.id, title: `Download ${file.name} (untrusted file from a remote Bot)`, onClick: () => download(file) }, ++ files.map(file => h('button', { key: file.id, type: 'button', className: 'bt-file-chip', disabled: busy === file.id, title: t('Download {name} (untrusted file from a remote Bot)', { name: file.name }), onClick: () => download(file) }, + `📎 ${file.name} · ${fileSize(file.size)}`)), + error ? h('span', { className: 'bt-file-error', role: 'alert' }, error) : null) +} diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index dde84df05..9fd143980 100644 --- a/patches/ds-bot/0008-client-bundle.patch +++ b/patches/ds-bot/0008-client-bundle.patch @@ -842,7 +842,7 @@ diff --git a/client.js b/client.js // Bot exchange "Bot exchange": "Bot 间对话", "Bot exchange transcript": "Bot 间对话记录", -@@ -446,11 +446,18 @@ var ZH = { +@@ -446,11 +446,22 @@ var ZH = { Reply: "回复", "More message actions": "更多操作", More: "更多", @@ -850,6 +850,10 @@ diff --git a/client.js b/client.js Reactions: "表情", "Message actions": "消息操作", Download: "下载", ++ // #3114 cut 32: the remote file chip's hover title. The name is the sender's data and is filled ++ // in untranslated; the two words that make the chip safe to click — untrusted, and a remote Bot — ++ // stay in the sentence. ++ "Download {name} (untrusted file from a remote Bot)": "下载 {name}(来自远程 Bot 的不可信文件)", + "Clipboard unavailable": "剪贴板不可用,请手动选择文字复制", + "Could not copy message": "未能复制消息,请重试或手动选择文字复制", + "Could not download message": "未能下载消息,请重试或复制正文", @@ -9255,7 +9259,7 @@ diff --git a/client.js b/client.js + { className: "bt-file-chips" }, + files.map((file) => (0, import_react12.createElement)( + "button", -+ { key: file.id, type: "button", className: "bt-file-chip", disabled: busy === file.id, title: `Download ${file.name} (untrusted file from a remote Bot)`, onClick: () => download2(file) }, ++ { key: file.id, type: "button", className: "bt-file-chip", disabled: busy === file.id, title: t("Download {name} (untrusted file from a remote Bot)", { name: file.name }), onClick: () => download2(file) }, + `📎 ${file.name} · ${fileSize(file.size)}` + )), + error ? (0, import_react12.createElement)("span", { className: "bt-file-error", role: "alert" }, error) : null diff --git a/patches/ds-bot/files/test/empty-message-cell.test.js b/patches/ds-bot/files/test/empty-message-cell.test.js index 0e4fbc979..13ea8c00e 100644 --- a/patches/ds-bot/files/test/empty-message-cell.test.js +++ b/patches/ds-bot/files/test/empty-message-cell.test.js @@ -8,8 +8,15 @@ import { build } from 'esbuild' // with nothing in it, under the trace row of the turn that produced it. The draw is checked where a // person reads it: the bubbles of one message (a Bot's own chat) and a group chat's reply rows. async function load(entry) { + // #3114 cut 32: one entry exports the cells and the dictionary they read, so `installLocale` binds + // the copy `t` reaches. Two separate bundles would bind a dictionary no cell ever looks at. const bundle = await build({ - entryPoints: [fileURLToPath(new URL(`../src/client/${entry}`, import.meta.url))], + stdin: { + contents: `export * from ${JSON.stringify(fileURLToPath(new URL(`../src/client/${entry}`, import.meta.url)))}\nexport { DICTIONARY, installLocale } from ${JSON.stringify(fileURLToPath(new URL('../src/client/i18n.js', import.meta.url)))}`, + resolveDir: fileURLToPath(new URL('../src/client', import.meta.url)), + sourcefile: 'cells-and-dictionary.js', + loader: 'js', + }, bundle: true, format: 'cjs', platform: 'node', write: false, external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'], }) @@ -46,7 +53,7 @@ const find = (node, match) => { } const count = (node, cls) => find(node, item => String(item.props?.className ?? '').split(/\s+/).includes(cls)).length -const { Bubbles, GroupReplies, RemoteMessage } = await load('cells.js') +const { Bubbles, GroupReplies, RemoteMessage, DICTIONARY, installLocale } = await load('cells.js') const chief = { id: 'chief', name: 'Chief', color: 'green' } const writer = { id: 'writer', name: 'Writer', color: 'blue' } @@ -91,3 +98,35 @@ test("#2123: a friend's line with no text keeps its files and draws no empty bub assert.equal(count(attached, 'bt-bubble'), 0, 'the attachment stays, the empty bubble does not') assert.equal(count(attached, 'bt-remote-msg'), 1) }) + +// #3114 cut 32: the chips' hover title is a sentence, so the window's language decides it; the file +// name is the sender's data and rides through `{name}` untranslated. +const CHIP_FILES = [ + { id: 'f1', name: 'log.txt', size: 12, mime: 'text/plain' }, + { id: 'f2', name: '报告 2026.pdf', size: 2048, mime: 'application/pdf' }, +] +const fill = (text, params) => text.replace(/\{(\w+)\}/g, (match, name) => (name in params ? String(params[name]) : match)) +const inLang = (active, draw) => { + const zh = key => active.startsWith('zh') ? DICTIONARY.zh[key] ?? key : key + const off = installLocale({ register: () => () => {}, bind: () => (key, params) => fill(zh(key), params ?? {}), getLocale: () => ({ active }) }) + try { return draw() } finally { off() } +} +const chipTitles = files => find(expand(RemoteMessage({ + source: { remote: { handle: '@coder.bob.home', senderName: 'Bob’s Coder' }, senderName: 'Bob’s Coder', attachments: files }, + text: '', roster, actions, sessionId: 'chat', msgKey: 'chat:turn:3', +}), ['RemoteFiles']), node => node.props?.className === 'bt-file-chip').map(node => node.props.title) + +test('#3114 cut 32: a zh window reads the remote file chip as an untrusted file from a remote Bot', () => { + assert.deepEqual(inLang('zh-CN', () => chipTitles(CHIP_FILES)), [ + '下载 log.txt(来自远程 Bot 的不可信文件)', + '下载 报告 2026.pdf(来自远程 Bot 的不可信文件)', + ]) +}) + +test('#3114 cut 32: an English window keeps the chip title exactly as it reads today', () => { + assert.deepEqual(inLang('en', () => chipTitles(CHIP_FILES)), [ + 'Download log.txt (untrusted file from a remote Bot)', + 'Download 报告 2026.pdf (untrusted file from a remote Bot)', + ]) + assert.equal(DICTIONARY.zh['Download {name} (untrusted file from a remote Bot)'], '下载 {name}(来自远程 Bot 的不可信文件)') +})