diff --git a/changelog.d/3114-capabilities-zh.fixed.md b/changelog.d/3114-capabilities-zh.fixed.md new file mode 100644 index 000000000..3b6f1eb3d --- /dev/null +++ b/changelog.d/3114-capabilities-zh.fixed.md @@ -0,0 +1 @@ +The Capabilities page now reads Chinese in a zh window: the Description label, and the six fixed refusals a failed save leaves — the capability name rule and a fixed kind, a missing MCP command, a bad HTTP(S) URL, and non-text environment or header values. diff --git a/core/client.js b/core/client.js index 9a9bfa9a0..93640c75d 100644 --- a/core/client.js +++ b/core/client.js @@ -426,6 +426,8 @@ var ZH = { "Add capability": "添加能力", "No capabilities saved": "还没有保存能力", Type: "类型", + // #3114: the Description field of the capability form (capability-settings.js:69) is a label. + Description: "描述", "MCP server": "MCP 服务", Skill: "技能", Pack: "能力包", @@ -1882,7 +1884,15 @@ var HOST_ZH = { "Not sent: Feishu refused the app token while sending the answer": "没发出去:发送时飞书不认这个应用 token", "Not sent: this answer has no Feishu chat to go to.": "没发出去:这条回答没有可去的飞书群。", "Not sent: connect Feishu first, so the answer has a way out.": "没发出去:请先连接飞书,回答才有出去的路。", - "Connect Feishu first": "请先连接飞书" + "Connect Feishu first": "请先连接飞书", + // #3114: the six fixed sentences a refused capability save leaves on the form. The two + // "text values" sentences are the host's template filled with its own field name. + 'Use a capability name with lowercase letters, digits, and single hyphens; "github" and "composio" are reserved.': "能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。", + "Enter a command for the MCP server.": "请填写 MCP 服务器的命令。", + "Enter a valid HTTP or HTTPS URL.": "请填写有效的 HTTP 或 HTTPS 地址。", + "A capability cannot change its kind. Delete it and save a new one.": "能力类型不能改。请删掉它,再新建一个。", + "Environment variables must contain text values.": "环境变量里只能填文本值。", + "Headers must contain text values.": "请求头里只能填文本值。" }; Object.assign(ZH, HOST_ZH); var fill = (text2, params) => params ? text2.replace(/\{(\w+)\}/g, (match, name) => name in params ? String(params[name]) : match) : text2; diff --git a/core/src/client/i18n.js b/core/src/client/i18n.js index 80a7370d6..a2f7f6a64 100644 --- a/core/src/client/i18n.js +++ b/core/src/client/i18n.js @@ -393,6 +393,8 @@ const ZH = { 'Add capability': '添加能力', 'No capabilities saved': '还没有保存能力', Type: '类型', + // #3114: the Description field of the capability form (capability-settings.js:69) is a label. + Description: '描述', 'MCP server': 'MCP 服务', Skill: '技能', Pack: '能力包', @@ -1843,6 +1845,14 @@ const HOST_ZH = { 'Not sent: this answer has no Feishu chat to go to.': '没发出去:这条回答没有可去的飞书群。', 'Not sent: connect Feishu first, so the answer has a way out.': '没发出去:请先连接飞书,回答才有出去的路。', 'Connect Feishu first': '请先连接飞书', + // #3114: the six fixed sentences a refused capability save leaves on the form. The two + // "text values" sentences are the host's template filled with its own field name. + 'Use a capability name with lowercase letters, digits, and single hyphens; "github" and "composio" are reserved.': '能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。', + 'Enter a command for the MCP server.': '请填写 MCP 服务器的命令。', + 'Enter a valid HTTP or HTTPS URL.': '请填写有效的 HTTP 或 HTTPS 地址。', + 'A capability cannot change its kind. Delete it and save a new one.': '能力类型不能改。请删掉它,再新建一个。', + 'Environment variables must contain text values.': '环境变量里只能填文本值。', + 'Headers must contain text values.': '请求头里只能填文本值。', } Object.assign(ZH, HOST_ZH) diff --git a/core/test/settings-error-placement.test.js b/core/test/settings-error-placement.test.js index e5e5c054a..355d606a3 100644 --- a/core/test/settings-error-placement.test.js +++ b/core/test/settings-error-placement.test.js @@ -10,7 +10,11 @@ import { build } from 'esbuild' const { outputFiles } = await build({ stdin: { - contents: "export { SettingsDialog } from './src/client/settings.js'", + contents: [ + "export { SettingsDialog } from './src/client/settings.js'", + "export { CapabilitiesPage } from './src/client/capability-settings.js'", + "export { hostText, installLocale } from './src/client/i18n.js'", + ].join('\n'), resolveDir: fileURLToPath(new URL('..', import.meta.url)), }, bundle: true, format: 'cjs', platform: 'browser', write: false, logLevel: 'silent', @@ -51,7 +55,7 @@ runInNewContext(outputFiles[0].text, { throw new Error(`Unexpected platform module ${name}`) }, }) -const { SettingsDialog } = module.exports +const { SettingsDialog, CapabilitiesPage, hostText, installLocale } = module.exports const render = (component, props) => { index = 0; return component(props) } const flush = async () => { @@ -96,3 +100,99 @@ test('a refused write in Settings stays in view instead of scrolling away with t assert.ok(scrolling, 'the page is the scrolling box under the dialog heading') assert.equal(inside(alert, scrolling), false, 'the refusal must sit outside the scrolling page, not above it') }) + +// #3114 cut 31: the Capabilities form and the six fixed refusals its save can leave. The page +// already draws `t(label)` (capability-settings.js:19) and the host sentence is translated before it +// is thrown (api.js:38), so the dictionary is the only place these cases can be red. +const REFUSALS = [ + ['Use a capability name with lowercase letters, digits, and single hyphens; "github" and "composio" are reserved.', + '能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。'], + ['Enter a command for the MCP server.', '请填写 MCP 服务器的命令。'], + ['Enter a valid HTTP or HTTPS URL.', '请填写有效的 HTTP 或 HTTPS 地址。'], + ['A capability cannot change its kind. Delete it and save a new one.', '能力类型不能改。请删掉它,再新建一个。'], + ['Environment variables must contain text values.', '环境变量里只能填文本值。'], + ['Headers must contain text values.', '请求头里只能填文本值。'], +] + +const fakeLocale = (active) => { + const dicts = new Map() + return { + register: (ns, locale, dict) => { dicts.set(`${ns}:${locale}`, dict); return () => dicts.delete(`${ns}:${locale}`) }, + bind: ns => (key, params) => { + const text = (active === 'zh' ? dicts.get(`${ns}:zh`)?.[key] : undefined) ?? key + return params ? text.replace(/\{(\w+)\}/g, (match, name) => (name in params ? String(params[name]) : match)) : text + }, + getLocale: () => ({ active }), + } +} + +// The locale service is global to the bundled i18n module: open the window, then close it again. +const inLang = async (active, body) => { + const off = installLocale(fakeLocale(active)) + try { await body() } finally { off() } +} + +// A fresh hook board for the component under test, so one case cannot read the last one's state. +const expand = (component, props) => { slots = []; index = 0; effects = []; return render(component, props) } + +// A field is a component: its label is on screen only once the field itself is drawn. +const nameOf = (root, label) => all(root) + .filter(node => typeof node?.type === 'function' && typeof node?.props?.label === 'string').some(node => text(node.type(node.props)) === label) + +const capabilityProps = (saveCapability) => ({ + roster: { ...roster, capabilities: [] }, + actions: { saveCapability, deleteCapability: async () => {}, approveCapability: async () => {} }, + run: () => {}, +}) + +// React is handed the form as a component, and this harness draws only what a test names: press +// Add capability, take the node the page drew, and draw that component by hand. +const capabilityForm = (saveCapability) => { + const props = capabilityProps(saveCapability) + const add = all(expand(CapabilitiesPage, props)).find(node => node?.props?.onClick) + assert.ok(add, 'the page draws its Add capability button') + add.props.onClick() + const opened = all(render(CapabilitiesPage, props)).find(node => node?.props?.draft && typeof node.props.setDraft === 'function') + assert.ok(opened, 'Add capability opens the form') + return opened +} + +// A save the host refused. api.js:38 translates the host's sentence before it throws, so the stub +// does the same and the form draws what it drew in the window: the refusal, not the raw host text. +const refusedForm = async (raw) => { + const opened = capabilityForm(async () => { throw new Error(hostText(raw)) }) + const form = all(expand(opened.type, opened.props)).find(node => node?.type === 'form') + assert.ok(form, 'the form draws itself') + await form.props.onSubmit({ preventDefault() {} }) + const alert = all(render(opened.type, opened.props)).find(node => node?.props?.role === 'alert') + return alert ? text(alert) : '' +} + +test('#3114 cut 31: a zh window reads the capability form labels in Chinese', async () => { + await inLang('zh', async () => { + const opened = capabilityForm(async () => {}) + const tree = expand(opened.type, opened.props) + assert.equal(nameOf(tree, '描述'), true, 'the Description label is a Chinese word') + assert.equal(nameOf(tree, '参数(每行一个)'), true, 'the rest of the form reads Chinese too') + assert.equal(nameOf(tree, 'Description'), false, 'no English Description label is left') + }) +}) + +test('#3114 cut 31: a zh window reads every fixed host refusal on the form in Chinese', async () => { + await inLang('zh', async () => { + for (const [raw, chinese] of REFUSALS) { + assert.equal(await refusedForm(raw), chinese, `"${raw}" reads Chinese where the host wrote it`) + } + }) +}) + +test('#3114 cut 31: an English window reads the same form and the same refusals unchanged', async () => { + const opened = capabilityForm(async () => {}) + const tree = expand(opened.type, opened.props) + assert.equal(nameOf(tree, 'Description'), true, 'the Description label is still English') + assert.equal(nameOf(tree, 'Arguments (one per line)'), true, 'the rest of the form is still English') + for (const [raw] of REFUSALS) { + assert.equal(hostText(raw), raw, `"${raw}" is untouched without a zh window`) + assert.equal(await refusedForm(raw), raw, `"${raw}" draws exactly as the host wrote it`) + } +}) diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index e6cf9882b..968582adb 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -1119,6 +1119,15 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js Connectors: '连接器', 'Search connectors': '搜索连接器', 'No connectors': '暂无连接器', +@@ -65,6 +65,8 @@ const ZH = { + 'Add capability': '添加能力', + 'No capabilities saved': '还没有保存能力', + Type: '类型', ++ // #3114: the Description field of the capability form (capability-settings.js:69) is a label. ++ Description: '描述', + 'MCP server': 'MCP 服务', + Skill: '技能', + Pack: '能力包', @@ -93,6 +93,62 @@ const ZH = { 'Connecting…': '正在连接…', 'Could not connect: {error}': '连接失败:{error}', @@ -2089,7 +2098,7 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js 'The admin must be a member of the group': '管理员必须是群成员', 'Unknown group chat': '找不到这个群聊', 'Hand the admin role to another member instead of leaving the group without one': '请把管理员交给其他成员,不要让群聊没有管理员', -@@ -905,6 +905,70 @@ const HOST_ZH = { +@@ -905,6 +905,78 @@ const HOST_ZH = { 'Write the entry to save.': '请写下要保存的内容。', 'This DeepSeek Harness has no folder chooser': '这个 DeepSeek Harness 没有文件夹选择窗口', 'This DeepSeek Harness cannot list folders': '这个 DeepSeek Harness 不能列出文件夹', @@ -2157,6 +2166,14 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js + 'Not sent: this answer has no Feishu chat to go to.': '没发出去:这条回答没有可去的飞书群。', + 'Not sent: connect Feishu first, so the answer has a way out.': '没发出去:请先连接飞书,回答才有出去的路。', + 'Connect Feishu first': '请先连接飞书', ++ // #3114: the six fixed sentences a refused capability save leaves on the form. The two ++ // "text values" sentences are the host's template filled with its own field name. ++ 'Use a capability name with lowercase letters, digits, and single hyphens; "github" and "composio" are reserved.': '能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。', ++ 'Enter a command for the MCP server.': '请填写 MCP 服务器的命令。', ++ 'Enter a valid HTTP or HTTPS URL.': '请填写有效的 HTTP 或 HTTPS 地址。', ++ 'A capability cannot change its kind. Delete it and save a new one.': '能力类型不能改。请删掉它,再新建一个。', ++ 'Environment variables must contain text values.': '环境变量里只能填文本值。', ++ 'Headers must contain text values.': '请求头里只能填文本值。', } Object.assign(ZH, HOST_ZH) diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index dde84df05..87ba1e232 100644 --- a/patches/ds-bot/0008-client-bundle.patch +++ b/patches/ds-bot/0008-client-bundle.patch @@ -378,6 +378,15 @@ diff --git a/client.js b/client.js Connectors: "连接器", "Search connectors": "搜索连接器", "No connectors": "暂无连接器", +@@ -101,6 +101,8 @@ var ZH = { + "Add capability": "添加能力", + "No capabilities saved": "还没有保存能力", + Type: "类型", ++ // #3114: the Description field of the capability form (capability-settings.js:69) is a label. ++ Description: "描述", + "MCP server": "MCP 服务", + Skill: "技能", + Pack: "能力包", @@ -129,6 +129,62 @@ var ZH = { "Connecting…": "正在连接…", "Could not connect: {error}": "连接失败:{error}", @@ -1346,7 +1355,7 @@ diff --git a/client.js b/client.js "The admin must be a member of the group": "管理员必须是群成员", "Unknown group chat": "找不到这个群聊", "Hand the admin role to another member instead of leaving the group without one": "请把管理员交给其他成员,不要让群聊没有管理员", -@@ -951,10 +951,74 @@ var HOST_ZH = { +@@ -951,10 +951,82 @@ var HOST_ZH = { "The model wrote nothing": "模型没有输出内容", "Write the entry to save.": "请写下要保存的内容。", "This DeepSeek Harness has no folder chooser": "这个 DeepSeek Harness 没有文件夹选择窗口", @@ -1415,7 +1424,15 @@ diff --git a/client.js b/client.js + "Not sent: Feishu refused the app token while sending the answer": "没发出去:发送时飞书不认这个应用 token", + "Not sent: this answer has no Feishu chat to go to.": "没发出去:这条回答没有可去的飞书群。", + "Not sent: connect Feishu first, so the answer has a way out.": "没发出去:请先连接飞书,回答才有出去的路。", -+ "Connect Feishu first": "请先连接飞书" ++ "Connect Feishu first": "请先连接飞书", ++ // #3114: the six fixed sentences a refused capability save leaves on the form. The two ++ // "text values" sentences are the host's template filled with its own field name. ++ 'Use a capability name with lowercase letters, digits, and single hyphens; "github" and "composio" are reserved.': "能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。", ++ "Enter a command for the MCP server.": "请填写 MCP 服务器的命令。", ++ "Enter a valid HTTP or HTTPS URL.": "请填写有效的 HTTP 或 HTTPS 地址。", ++ "A capability cannot change its kind. Delete it and save a new one.": "能力类型不能改。请删掉它,再新建一个。", ++ "Environment variables must contain text values.": "环境变量里只能填文本值。", ++ "Headers must contain text values.": "请求头里只能填文本值。" }; Object.assign(ZH, HOST_ZH); -var fill = (text, params) => params ? text.replace(/\{(\w+)\}/g, (match, name) => name in params ? String(params[name]) : match) : text; diff --git a/patches/ds-bot/files/test/settings-error-placement.test.js b/patches/ds-bot/files/test/settings-error-placement.test.js index e5e5c054a..355d606a3 100644 --- a/patches/ds-bot/files/test/settings-error-placement.test.js +++ b/patches/ds-bot/files/test/settings-error-placement.test.js @@ -10,7 +10,11 @@ import { build } from 'esbuild' const { outputFiles } = await build({ stdin: { - contents: "export { SettingsDialog } from './src/client/settings.js'", + contents: [ + "export { SettingsDialog } from './src/client/settings.js'", + "export { CapabilitiesPage } from './src/client/capability-settings.js'", + "export { hostText, installLocale } from './src/client/i18n.js'", + ].join('\n'), resolveDir: fileURLToPath(new URL('..', import.meta.url)), }, bundle: true, format: 'cjs', platform: 'browser', write: false, logLevel: 'silent', @@ -51,7 +55,7 @@ runInNewContext(outputFiles[0].text, { throw new Error(`Unexpected platform module ${name}`) }, }) -const { SettingsDialog } = module.exports +const { SettingsDialog, CapabilitiesPage, hostText, installLocale } = module.exports const render = (component, props) => { index = 0; return component(props) } const flush = async () => { @@ -96,3 +100,99 @@ test('a refused write in Settings stays in view instead of scrolling away with t assert.ok(scrolling, 'the page is the scrolling box under the dialog heading') assert.equal(inside(alert, scrolling), false, 'the refusal must sit outside the scrolling page, not above it') }) + +// #3114 cut 31: the Capabilities form and the six fixed refusals its save can leave. The page +// already draws `t(label)` (capability-settings.js:19) and the host sentence is translated before it +// is thrown (api.js:38), so the dictionary is the only place these cases can be red. +const REFUSALS = [ + ['Use a capability name with lowercase letters, digits, and single hyphens; "github" and "composio" are reserved.', + '能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。'], + ['Enter a command for the MCP server.', '请填写 MCP 服务器的命令。'], + ['Enter a valid HTTP or HTTPS URL.', '请填写有效的 HTTP 或 HTTPS 地址。'], + ['A capability cannot change its kind. Delete it and save a new one.', '能力类型不能改。请删掉它,再新建一个。'], + ['Environment variables must contain text values.', '环境变量里只能填文本值。'], + ['Headers must contain text values.', '请求头里只能填文本值。'], +] + +const fakeLocale = (active) => { + const dicts = new Map() + return { + register: (ns, locale, dict) => { dicts.set(`${ns}:${locale}`, dict); return () => dicts.delete(`${ns}:${locale}`) }, + bind: ns => (key, params) => { + const text = (active === 'zh' ? dicts.get(`${ns}:zh`)?.[key] : undefined) ?? key + return params ? text.replace(/\{(\w+)\}/g, (match, name) => (name in params ? String(params[name]) : match)) : text + }, + getLocale: () => ({ active }), + } +} + +// The locale service is global to the bundled i18n module: open the window, then close it again. +const inLang = async (active, body) => { + const off = installLocale(fakeLocale(active)) + try { await body() } finally { off() } +} + +// A fresh hook board for the component under test, so one case cannot read the last one's state. +const expand = (component, props) => { slots = []; index = 0; effects = []; return render(component, props) } + +// A field is a component: its label is on screen only once the field itself is drawn. +const nameOf = (root, label) => all(root) + .filter(node => typeof node?.type === 'function' && typeof node?.props?.label === 'string').some(node => text(node.type(node.props)) === label) + +const capabilityProps = (saveCapability) => ({ + roster: { ...roster, capabilities: [] }, + actions: { saveCapability, deleteCapability: async () => {}, approveCapability: async () => {} }, + run: () => {}, +}) + +// React is handed the form as a component, and this harness draws only what a test names: press +// Add capability, take the node the page drew, and draw that component by hand. +const capabilityForm = (saveCapability) => { + const props = capabilityProps(saveCapability) + const add = all(expand(CapabilitiesPage, props)).find(node => node?.props?.onClick) + assert.ok(add, 'the page draws its Add capability button') + add.props.onClick() + const opened = all(render(CapabilitiesPage, props)).find(node => node?.props?.draft && typeof node.props.setDraft === 'function') + assert.ok(opened, 'Add capability opens the form') + return opened +} + +// A save the host refused. api.js:38 translates the host's sentence before it throws, so the stub +// does the same and the form draws what it drew in the window: the refusal, not the raw host text. +const refusedForm = async (raw) => { + const opened = capabilityForm(async () => { throw new Error(hostText(raw)) }) + const form = all(expand(opened.type, opened.props)).find(node => node?.type === 'form') + assert.ok(form, 'the form draws itself') + await form.props.onSubmit({ preventDefault() {} }) + const alert = all(render(opened.type, opened.props)).find(node => node?.props?.role === 'alert') + return alert ? text(alert) : '' +} + +test('#3114 cut 31: a zh window reads the capability form labels in Chinese', async () => { + await inLang('zh', async () => { + const opened = capabilityForm(async () => {}) + const tree = expand(opened.type, opened.props) + assert.equal(nameOf(tree, '描述'), true, 'the Description label is a Chinese word') + assert.equal(nameOf(tree, '参数(每行一个)'), true, 'the rest of the form reads Chinese too') + assert.equal(nameOf(tree, 'Description'), false, 'no English Description label is left') + }) +}) + +test('#3114 cut 31: a zh window reads every fixed host refusal on the form in Chinese', async () => { + await inLang('zh', async () => { + for (const [raw, chinese] of REFUSALS) { + assert.equal(await refusedForm(raw), chinese, `"${raw}" reads Chinese where the host wrote it`) + } + }) +}) + +test('#3114 cut 31: an English window reads the same form and the same refusals unchanged', async () => { + const opened = capabilityForm(async () => {}) + const tree = expand(opened.type, opened.props) + assert.equal(nameOf(tree, 'Description'), true, 'the Description label is still English') + assert.equal(nameOf(tree, 'Arguments (one per line)'), true, 'the rest of the form is still English') + for (const [raw] of REFUSALS) { + assert.equal(hostText(raw), raw, `"${raw}" is untouched without a zh window`) + assert.equal(await refusedForm(raw), raw, `"${raw}" draws exactly as the host wrote it`) + } +})