Skip to content

Commit dd7599d

Browse files
authored
Read a remote file chip's download title in the window's language (#3114) (#3259)
Written-by: Dev Fixes #3258 Part of #3114 Owner: Dev Reviewer: Reviewer Docs-not-needed: one dictionary entry and one draw site in the chat cells; no architecture change. ## What changed Before: hovering a remote file chip in a zh window read `Download log.txt (untrusted file from a remote Bot)`. After: it reads `下载 log.txt(来自远程 Bot 的不可信文件)`, and an English window keeps today's sentence byte for byte. `core/src/client/cells.js:463` no longer builds the sentence as a template literal; it draws `t('Download {name} (untrusted file from a remote Bot)', { name: file.name })`, and `core/src/client/i18n.js` gains that key right after `Download: '下载',`. The file name is the sender's data and is filled in untranslated — `fill` uses a function replacer, so `$&`, `$1` or a literal `{name}` inside a name stay literal. Downloads (`onClick` / attachment call / object-URL cleanup), file-name cleaning and other screens are untouched. ## Verification at the tip Tip SHA: `382c70cb035332e8bfb495a2a6684d7aea16896f` Ran: - `(cd core && TZ=UTC node --test test/empty-message-cell.test.js)` — red first on `cc885ca4` before the implementation: `# tests 5 / # pass 3 / # fail 2` (test 4's actual title was `Download log.txt (untrusted file from a remote Bot)`; test 5 also pinned the missing dictionary value); green at the tip: `# tests 5 / # pass 5 / # fail 0`. - `(cd core && TZ=UTC node --test test/i18n.test.js)` — 3/3/0 (dictionary gate: every drawn `t('…')` has an entry). - Five i18n gates: `test/i18n.test.js test/i18n-missing-entries.test.js test/i18n-template-draws.test.js test/i18n-plugins.test.js test/i18n-plugins-missing-zh.test.js` — 39/39/0; three baselines 12 / 9 / 46 ok. - `(cd core && npm run build)` then `node scripts/ds-bot-patches.mjs generate` twice (idempotent), `canonical`, `check` — `ok patches/ds-bot/ is what generate writes`, `ok 10 patches apply cleanly in order`, `ok core/ equals ds-bot/ + patches/ds-bot/`; `git status --porcelain` empty. - `node core/scripts/build-client.mjs --check` — rc 0; `git diff --exit-code -- core/client.js` rc 0. - `node .github/scripts/changelog.mjs check` — `12 fragment(s) ... well formed`; `node .github/scripts/check-mojibake.mjs --check` — 0 occurrences of U+FFFD in 1781 text files. - `ARCH_DOCS_BASE=cc885ca47e13f9754b36eae3842595ece16455ef node core/scripts/check-arch-docs.mjs` — `arch-docs: OK (9 changed file(s))`. - `risk-gate.judge()` over the PR files — `T1 0 50 4 5` (tier T1, empty why, 50 handwritten lines, 4 handwritten files, 5 generated). Generated artifacts: `core/client.js` (+5/−1), `patches/ds-bot/0001-core-fixes.patch` (+5/−1), `0003-flybot-api-client.patch` (+1/−1), `0008-client-bundle.patch` (+6/−2), `files/test/empty-message-cell.test.js` (+41/−2); `patches/ds-bot/topics.json` untouched. Not run (and why): - `npm run verify` — the shared `@deepseek-ai` harness install is not usable on this machine (`core/node_modules` is the build-only esbuild install), so the full suite would be red for reasons unrelated to this change. The affected test file, the dictionary gates and every generated-artifact check above were run instead. - Smoke test and Desktop — not needed for a client copy change with no host or component structure change. ## Checkpoint <!-- flybot:checkpoint --> ```json { "pr": 3259, "claim": "Dev", "issue": 3258, "summary": "Remote file chips in a chat now read their hover title from the dictionary, so a zh window says the file comes from a remote Bot and is untrusted while an English window keeps today's sentence. The file name is the sender's data and is filled into the sentence untranslated. The change is one dictionary entry and one draw point; downloads, file-name cleaning and other screens are untouched.", "files": ["core/src/client/i18n.js", "core/src/client/cells.js", "core/test/empty-message-cell.test.js", "changelog.d/3114-remote-file-chip-zh.fixed.md"], "checks": { "ran": "cd core && TZ=UTC node --test test/empty-message-cell.test.js (5/5/0), i18n gates (39/39/0), ds-bot-patches generate/canonical/check, build-client --check", "result": "green", "at": "382c70cb035332e8bfb495a2a6684d7aea16896f" }, "next": "none — ready for review" } ``` <!-- /flybot:checkpoint -->
1 parent f920d3c commit dd7599d

9 files changed

Lines changed: 105 additions & 10 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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)).

‎core/client.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,10 @@ var ZH = {
10711071
Reactions: "表情",
10721072
"Message actions": "消息操作",
10731073
Download: "下载",
1074+
// #3114 cut 32: the remote file chip's hover title. The name is the sender's data and is filled
1075+
// in untranslated; the two words that make the chip safe to click — untrusted, and a remote Bot —
1076+
// stay in the sentence.
1077+
"Download {name} (untrusted file from a remote Bot)": "下载 {name}(来自远程 Bot 的不可信文件)",
10741078
"Clipboard unavailable": "剪贴板不可用,请手动选择文字复制",
10751079
"Could not copy message": "未能复制消息,请重试或手动选择文字复制",
10761080
"Could not download message": "未能下载消息,请重试或复制正文",
@@ -8248,7 +8252,7 @@ function RemoteFiles({ files, plugin, botId }) {
82488252
{ className: "bt-file-chips" },
82498253
files.map((file) => (0, import_react12.createElement)(
82508254
"button",
8251-
{ 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) },
8255+
{ 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) },
82528256
`📎 ${file.name} · ${fileSize(file.size)}`
82538257
)),
82548258
error ? (0, import_react12.createElement)("span", { className: "bt-file-error", role: "alert" }, error) : null

‎core/src/client/cells.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ function RemoteFiles({ files, plugin, botId }) {
460460
}
461461
}
462462
return h('div', { className: 'bt-file-chips' },
463-
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) },
463+
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) },
464464
`📎 ${file.name} · ${fileSize(file.size)}`)),
465465
error ? h('span', { className: 'bt-file-error', role: 'alert' }, error) : null)
466466
}

‎core/src/client/i18n.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,10 @@ const ZH = {
10211021
Reactions: '表情',
10221022
'Message actions': '消息操作',
10231023
Download: '下载',
1024+
// #3114 cut 32: the remote file chip's hover title. The name is the sender's data and is filled
1025+
// in untranslated; the two words that make the chip safe to click — untrusted, and a remote Bot —
1026+
// stay in the sentence.
1027+
'Download {name} (untrusted file from a remote Bot)': '下载 {name}(来自远程 Bot 的不可信文件)',
10241028
'Clipboard unavailable': '剪贴板不可用,请手动选择文字复制',
10251029
'Could not copy message': '未能复制消息,请重试或手动选择文字复制',
10261030
'Could not download message': '未能下载消息,请重试或复制正文',

‎core/test/empty-message-cell.test.js‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ import { build } from 'esbuild'
88
// with nothing in it, under the trace row of the turn that produced it. The draw is checked where a
99
// person reads it: the bubbles of one message (a Bot's own chat) and a group chat's reply rows.
1010
async function load(entry) {
11+
// #3114 cut 32: one entry exports the cells and the dictionary they read, so `installLocale` binds
12+
// the copy `t` reaches. Two separate bundles would bind a dictionary no cell ever looks at.
1113
const bundle = await build({
12-
entryPoints: [fileURLToPath(new URL(`../src/client/${entry}`, import.meta.url))],
14+
stdin: {
15+
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)))}`,
16+
resolveDir: fileURLToPath(new URL('../src/client', import.meta.url)),
17+
sourcefile: 'cells-and-dictionary.js',
18+
loader: 'js',
19+
},
1320
bundle: true, format: 'cjs', platform: 'node', write: false,
1421
external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'],
1522
})
@@ -46,7 +53,7 @@ const find = (node, match) => {
4653
}
4754
const count = (node, cls) => find(node, item => String(item.props?.className ?? '').split(/\s+/).includes(cls)).length
4855

49-
const { Bubbles, GroupReplies, RemoteMessage } = await load('cells.js')
56+
const { Bubbles, GroupReplies, RemoteMessage, DICTIONARY, installLocale } = await load('cells.js')
5057

5158
const chief = { id: 'chief', name: 'Chief', color: 'green' }
5259
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
9198
assert.equal(count(attached, 'bt-bubble'), 0, 'the attachment stays, the empty bubble does not')
9299
assert.equal(count(attached, 'bt-remote-msg'), 1)
93100
})
101+
102+
// #3114 cut 32: the chips' hover title is a sentence, so the window's language decides it; the file
103+
// name is the sender's data and rides through `{name}` untranslated.
104+
const CHIP_FILES = [
105+
{ id: 'f1', name: 'log.txt', size: 12, mime: 'text/plain' },
106+
{ id: 'f2', name: '报告 2026.pdf', size: 2048, mime: 'application/pdf' },
107+
]
108+
const fill = (text, params) => text.replace(/\{(\w+)\}/g, (match, name) => (name in params ? String(params[name]) : match))
109+
const inLang = (active, draw) => {
110+
const zh = key => active.startsWith('zh') ? DICTIONARY.zh[key] ?? key : key
111+
const off = installLocale({ register: () => () => {}, bind: () => (key, params) => fill(zh(key), params ?? {}), getLocale: () => ({ active }) })
112+
try { return draw() } finally { off() }
113+
}
114+
const chipTitles = files => find(expand(RemoteMessage({
115+
source: { remote: { handle: '@coder.bob.home', senderName: 'Bob’s Coder' }, senderName: 'Bob’s Coder', attachments: files },
116+
text: '', roster, actions, sessionId: 'chat', msgKey: 'chat:turn:3',
117+
}), ['RemoteFiles']), node => node.props?.className === 'bt-file-chip').map(node => node.props.title)
118+
119+
test('#3114 cut 32: a zh window reads the remote file chip as an untrusted file from a remote Bot', () => {
120+
assert.deepEqual(inLang('zh-CN', () => chipTitles(CHIP_FILES)), [
121+
'下载 log.txt(来自远程 Bot 的不可信文件)',
122+
'下载 报告 2026.pdf(来自远程 Bot 的不可信文件)',
123+
])
124+
})
125+
126+
test('#3114 cut 32: an English window keeps the chip title exactly as it reads today', () => {
127+
assert.deepEqual(inLang('en', () => chipTitles(CHIP_FILES)), [
128+
'Download log.txt (untrusted file from a remote Bot)',
129+
'Download 报告 2026.pdf (untrusted file from a remote Bot)',
130+
])
131+
assert.equal(DICTIONARY.zh['Download {name} (untrusted file from a remote Bot)'], '下载 {name}(来自远程 Bot 的不可信文件)')
132+
})

‎patches/ds-bot/0001-core-fixes.patch‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,14 +1596,18 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js
15961596

15971597
// Bot exchange
15981598
'Bot exchange': 'Bot 间对话',
1599-
@@ -390,11 +390,18 @@ const ZH = {
1599+
@@ -390,11 +390,22 @@ const ZH = {
16001600
Reply: '回复',
16011601
'More message actions': '更多操作',
16021602
More: '更多',
16031603
+ Sharing: '分享',
16041604
Reactions: '表情',
16051605
'Message actions': '消息操作',
16061606
Download: '下载',
1607+
+ // #3114 cut 32: the remote file chip's hover title. The name is the sender's data and is filled
1608+
+ // in untranslated; the two words that make the chip safe to click — untrusted, and a remote Bot —
1609+
+ // stay in the sentence.
1610+
+ 'Download {name} (untrusted file from a remote Bot)': '下载 {name}(来自远程 Bot 的不可信文件)',
16071611
+ 'Clipboard unavailable': '剪贴板不可用,请手动选择文字复制',
16081612
+ 'Could not copy message': '未能复制消息,请重试或手动选择文字复制',
16091613
+ 'Could not download message': '未能下载消息,请重试或复制正文',

‎patches/ds-bot/0003-flybot-api-client.patch‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ diff --git a/src/client/cells.js b/src/client/cells.js
10541054
+ }
10551055
+ }
10561056
+ return h('div', { className: 'bt-file-chips' },
1057-
+ 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) },
1057+
+ 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) },
10581058
+ `📎 ${file.name} · ${fileSize(file.size)}`)),
10591059
+ error ? h('span', { className: 'bt-file-error', role: 'alert' }, error) : null)
10601060
+}

‎patches/ds-bot/0008-client-bundle.patch‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,14 +851,18 @@ diff --git a/client.js b/client.js
851851
// Bot exchange
852852
"Bot exchange": "Bot 间对话",
853853
"Bot exchange transcript": "Bot 间对话记录",
854-
@@ -446,11 +446,18 @@ var ZH = {
854+
@@ -446,11 +446,22 @@ var ZH = {
855855
Reply: "回复",
856856
"More message actions": "更多操作",
857857
More: "更多",
858858
+ Sharing: "分享",
859859
Reactions: "表情",
860860
"Message actions": "消息操作",
861861
Download: "下载",
862+
+ // #3114 cut 32: the remote file chip's hover title. The name is the sender's data and is filled
863+
+ // in untranslated; the two words that make the chip safe to click — untrusted, and a remote Bot —
864+
+ // stay in the sentence.
865+
+ "Download {name} (untrusted file from a remote Bot)": "下载 {name}(来自远程 Bot 的不可信文件)",
862866
+ "Clipboard unavailable": "剪贴板不可用,请手动选择文字复制",
863867
+ "Could not copy message": "未能复制消息,请重试或手动选择文字复制",
864868
+ "Could not download message": "未能下载消息,请重试或复制正文",
@@ -9272,7 +9276,7 @@ diff --git a/client.js b/client.js
92729276
+ { className: "bt-file-chips" },
92739277
+ files.map((file) => (0, import_react12.createElement)(
92749278
+ "button",
9275-
+ { 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) },
9279+
+ { 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) },
92769280
+ `📎 ${file.name} · ${fileSize(file.size)}`
92779281
+ )),
92789282
+ error ? (0, import_react12.createElement)("span", { className: "bt-file-error", role: "alert" }, error) : null

‎patches/ds-bot/files/test/empty-message-cell.test.js‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ import { build } from 'esbuild'
88
// with nothing in it, under the trace row of the turn that produced it. The draw is checked where a
99
// person reads it: the bubbles of one message (a Bot's own chat) and a group chat's reply rows.
1010
async function load(entry) {
11+
// #3114 cut 32: one entry exports the cells and the dictionary they read, so `installLocale` binds
12+
// the copy `t` reaches. Two separate bundles would bind a dictionary no cell ever looks at.
1113
const bundle = await build({
12-
entryPoints: [fileURLToPath(new URL(`../src/client/${entry}`, import.meta.url))],
14+
stdin: {
15+
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)))}`,
16+
resolveDir: fileURLToPath(new URL('../src/client', import.meta.url)),
17+
sourcefile: 'cells-and-dictionary.js',
18+
loader: 'js',
19+
},
1320
bundle: true, format: 'cjs', platform: 'node', write: false,
1421
external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'],
1522
})
@@ -46,7 +53,7 @@ const find = (node, match) => {
4653
}
4754
const count = (node, cls) => find(node, item => String(item.props?.className ?? '').split(/\s+/).includes(cls)).length
4855

49-
const { Bubbles, GroupReplies, RemoteMessage } = await load('cells.js')
56+
const { Bubbles, GroupReplies, RemoteMessage, DICTIONARY, installLocale } = await load('cells.js')
5057

5158
const chief = { id: 'chief', name: 'Chief', color: 'green' }
5259
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
9198
assert.equal(count(attached, 'bt-bubble'), 0, 'the attachment stays, the empty bubble does not')
9299
assert.equal(count(attached, 'bt-remote-msg'), 1)
93100
})
101+
102+
// #3114 cut 32: the chips' hover title is a sentence, so the window's language decides it; the file
103+
// name is the sender's data and rides through `{name}` untranslated.
104+
const CHIP_FILES = [
105+
{ id: 'f1', name: 'log.txt', size: 12, mime: 'text/plain' },
106+
{ id: 'f2', name: '报告 2026.pdf', size: 2048, mime: 'application/pdf' },
107+
]
108+
const fill = (text, params) => text.replace(/\{(\w+)\}/g, (match, name) => (name in params ? String(params[name]) : match))
109+
const inLang = (active, draw) => {
110+
const zh = key => active.startsWith('zh') ? DICTIONARY.zh[key] ?? key : key
111+
const off = installLocale({ register: () => () => {}, bind: () => (key, params) => fill(zh(key), params ?? {}), getLocale: () => ({ active }) })
112+
try { return draw() } finally { off() }
113+
}
114+
const chipTitles = files => find(expand(RemoteMessage({
115+
source: { remote: { handle: '@coder.bob.home', senderName: 'Bob’s Coder' }, senderName: 'Bob’s Coder', attachments: files },
116+
text: '', roster, actions, sessionId: 'chat', msgKey: 'chat:turn:3',
117+
}), ['RemoteFiles']), node => node.props?.className === 'bt-file-chip').map(node => node.props.title)
118+
119+
test('#3114 cut 32: a zh window reads the remote file chip as an untrusted file from a remote Bot', () => {
120+
assert.deepEqual(inLang('zh-CN', () => chipTitles(CHIP_FILES)), [
121+
'下载 log.txt(来自远程 Bot 的不可信文件)',
122+
'下载 报告 2026.pdf(来自远程 Bot 的不可信文件)',
123+
])
124+
})
125+
126+
test('#3114 cut 32: an English window keeps the chip title exactly as it reads today', () => {
127+
assert.deepEqual(inLang('en', () => chipTitles(CHIP_FILES)), [
128+
'Download log.txt (untrusted file from a remote Bot)',
129+
'Download 报告 2026.pdf (untrusted file from a remote Bot)',
130+
])
131+
assert.equal(DICTIONARY.zh['Download {name} (untrusted file from a remote Bot)'], '下载 {name}(来自远程 Bot 的不可信文件)')
132+
})

0 commit comments

Comments
 (0)