diff --git a/changelog.d/3243-3114-cut-29-feishu.fixed.md b/changelog.d/3243-3114-cut-29-feishu.fixed.md new file mode 100644 index 000000000..822c1c4c9 --- /dev/null +++ b/changelog.d/3243-3114-cut-29-feishu.fixed.md @@ -0,0 +1 @@ +The Connectors page's Feishu row reads in the window's language — its failed-connect line, and the sentence a refused connect, disconnect, mode, allowed-sender or send leaves — together with the Composio search hint and app-limit sentence; the host's own data (address, status code, open_id) stays exactly as the host wrote it ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)). diff --git a/core/client.js b/core/client.js index 77c6cbf19..d34c634bd 100644 --- a/core/client.js +++ b/core/client.js @@ -1752,7 +1752,18 @@ var HOST_ERRORS = [ [/^A binding needs the member id$/, "绑定需要 member id"], [/^A Project memory entry needs text$/, "项目记忆条目需要文字"], [/^A Project memory entry is at most (\d+) characters$/, "项目记忆条目最多 $1 个字符"], - [/^Unknown Project (\S+)$/, "找不到项目 $1"] + [/^Unknown Project (\S+)$/, "找不到项目 $1"], + // #3114 cut 29: the Connectors page's Feishu row, and two Composio leftovers on the same page. + // The four below carry the host's own data — a webhook origin, a status code, Feishu's own error + // code, Composio's message — and copy it through: data is never translated. + [/^A Feishu webhook must be https on (.+)$/, "飞书 webhook 必须是 $1 上的 https 地址"], + [/^Feishu answered (\d+)$/, "飞书返回了 $1"], + [/^Feishu did not accept the webhook \((.+)\)$/, "飞书不接受这个 webhook($1)"], + [/^Not sent: Feishu refused the answer \((.+)\)$/, "没发出去:飞书拒收($1)"], + // `connector-send` names the notifier's own refusal, and its fallback literal, in the brackets. + [/^Feishu refused the message \((.+)\)$/, "飞书拒收这条消息($1)"], + [/^Pick up to (\d+) apps$/, "最多选 $1 个应用"], + [/^Composio answered (\d+)([\s\S]*)$/, "Composio 返回了 $1$2"] ]; var HOST_ZH = { "Request failed": "请求失败", @@ -1840,7 +1851,30 @@ var HOST_ZH = { "In use in {n} room: ": "正在 {n} 个房间里使用:", "In use in {n} rooms: ": "正在 {n} 个房间里使用:", "This room only: ": "只在这个房间使用:", - " +{n} more": ",还有 {n} 个" + " +{n} more": ",还有 {n} 个", + // #3114 cut 29: the Connectors page's Feishu row in a Chinese window — the line under a failed + // connect, and the sentence a refused connect, disconnect, mode, allowed-sender or send leaves. + // A sentence with data in it is one of the HOST_ERRORS patterns above, not an entry here. + "Could not reach Feishu": "连不上飞书", + "Feishu addresses must start with https://": "飞书地址必须以 https:// 开头", + "A Feishu App ID and App Secret are both needed before the long connection can dial.": "自建应用的长连接需要飞书 App ID 和 App Secret 才能拨号", + "the Feishu long connection did not open": "飞书长连接没有建立", + "Paste the webhook URL Feishu gave you": "请粘贴飞书给你的 webhook 地址", + "Feishu did not answer in time — the test message may already be in the chat; check before connecting again": "飞书没有及时答复——测试消息可能已经发到群里;再连接前先确认一下", + "Feishu did not answer in time — the message may already be in the chat; check before sending again": "飞书没有及时答复——消息可能已经发到群里;再发送前先确认一下", + "Feishu is rate-limiting this webhook; try again in a minute": "飞书正在限流这个 webhook;请过一分钟再试", + "Paste the App ID and App Secret Feishu gave the app": "请粘贴飞书给这个应用的 App ID 和 App Secret", + "Feishu did not accept this App ID and App Secret": "飞书不接受这个 App ID 和 App Secret", + "Choose how to connect Feishu first": "请先选择飞书的连接方式", + "This connector has no allowed senders": "这个连接器没有允许发送的人", + "Paste the open_id of the sender to allow": "请粘贴要允许的发送者 open_id", + "Connect Feishu as an app first": "请先把飞书按自建应用连接", + "Type a message first": "请先输入消息", + "Not sent: could not reach Feishu": "没发出去:连不上飞书", + "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": "请先连接飞书" }; Object.assign(ZH, HOST_ZH); var fill = (text2, params) => params ? text2.replace(/\{(\w+)\}/g, (match, name) => name in params ? String(params[name]) : match) : text2; @@ -19826,7 +19860,7 @@ var ABOUT = { }; function statusText2(connector) { if (connector.state === "connecting") return t("Connecting…"); - if (connector.state === "error") return t("Could not connect: {error}", { error: connector.error ?? "" }); + if (connector.state === "error") return t("Could not connect: {error}", { error: hostText(connector.error ?? "") }); if (connector.state === "ready" && connector.kind === "channel") { return connector.mode === "app" ? t("Connected: app, over the long connection") : t("Connected: custom bot webhook"); } @@ -19950,7 +19984,7 @@ function AppPicker({ apps, onChange, search, statuses = {} }) { { className: "bt-connector-apps" }, apps.length > 0 ? (0, import_react42.createElement)("div", { className: "bt-states", "aria-label": t("Picked apps") }, apps.map((slug) => (0, import_react42.createElement)(AppChip, { key: slug, name: nameOf(slug), status: statuses[slug], onRemove: () => onChange(apps.filter((app) => app !== slug)) }))) : null, (0, import_react42.createElement)("input", { className: "bt-input", type: "search", value: query, spellCheck: false, "aria-label": t("Search apps"), placeholder: t("Search Composio apps"), onChange: (event) => setQuery(event.target.value) }), - failed ? (0, import_react42.createElement)("span", { className: "bt-set-hint" }, t("Could not search Composio: {error}", { error: failed })) : null, + failed ? (0, import_react42.createElement)("span", { className: "bt-set-hint" }, t("Could not search Composio: {error}", { error: hostText(failed) })) : null, (0, import_react42.createElement)("div", { className: "bt-states", "aria-label": t("Apps to add") }, results.length === 0 ? (0, import_react42.createElement)("span", { className: "bt-set-hint" }, t("No apps match")) : results.map((app) => (0, import_react42.createElement)("button", { key: app.slug, type: "button", className: "bt-state", "aria-pressed": false, onClick: () => { names.current.set(app.slug, app.name); onChange([...apps, app.slug]); @@ -20150,7 +20184,7 @@ function ConnectorRow({ connector, roster, actions }) { (0, import_react42.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", disabled: busy || apps.length === 0, onClick: saveApps }, busy ? t("Connecting…") : t("Save")) ) ) : null, - error ? (0, import_react42.createElement)("div", { className: "bt-connector-error", role: "alert" }, error) : null + error ? (0, import_react42.createElement)("div", { className: "bt-connector-error", role: "alert" }, hostText(error)) : null ); } function ConnectorsPage({ roster, actions }) { diff --git a/core/src/client/connectors.js b/core/src/client/connectors.js index b253bc5a2..a04db36df 100644 --- a/core/src/client/connectors.js +++ b/core/src/client/connectors.js @@ -5,7 +5,7 @@ import { ConnectorIcon } from './icons.js' import { SwitchRow } from './bot-settings.js' import { lockedWindow } from './schedules.js' import { ConnectorBots, usageText } from './connector-bots.js' -import { t } from './i18n.js' +import { hostText, t } from './i18n.js' import { copiedToClipboard } from '../shared/remote-label.js' const TOKEN_URL = 'https://github.com/settings/personal-access-tokens/new' @@ -42,7 +42,9 @@ const ABOUT = { function statusText(connector) { if (connector.state === 'connecting') return t('Connecting…') - if (connector.state === 'error') return t('Could not connect: {error}', { error: connector.error ?? '' }) + // The host wrote the failure; a zh window reads it in Chinese, and the host's own data inside it + // (an origin, a status code, an open_id) is copied through as written (#3243). + if (connector.state === 'error') return t('Could not connect: {error}', { error: hostText(connector.error ?? '') }) if (connector.state === 'ready' && connector.kind === 'channel') { return connector.mode === 'app' ? t('Connected: app, over the long connection') : t('Connected: custom bot webhook') } @@ -138,7 +140,7 @@ export function AppPicker({ apps, onChange, search, statuses = {} }) { apps.length > 0 ? h('div', { className: 'bt-states', 'aria-label': t('Picked apps') }, apps.map(slug => h(AppChip, { key: slug, name: nameOf(slug), status: statuses[slug], onRemove: () => onChange(apps.filter(app => app !== slug)) }))) : null, h('input', { className: 'bt-input', type: 'search', value: query, spellCheck: false, 'aria-label': t('Search apps'), placeholder: t('Search Composio apps'), onChange: event => setQuery(event.target.value) }), - failed ? h('span', { className: 'bt-set-hint' }, t('Could not search Composio: {error}', { error: failed })) : null, + failed ? h('span', { className: 'bt-set-hint' }, t('Could not search Composio: {error}', { error: hostText(failed) })) : null, h('div', { className: 'bt-states', 'aria-label': t('Apps to add') }, results.length === 0 ? h('span', { className: 'bt-set-hint' }, t('No apps match')) : results.map(app => h('button', { key: app.slug, type: 'button', className: 'bt-state', 'aria-pressed': false, onClick: () => { names.current.set(app.slug, app.name); onChange([...apps, app.slug]) } }, app.name)))) @@ -275,7 +277,7 @@ function ConnectorRow({ connector, roster, actions }) { h('span', { className: 'bt-connector-link' }), h('button', { type: 'button', className: 'bt-soft bt-soft-sm', disabled: busy, onClick: () => { setPicking(false); setError(null) } }, t('Cancel')), h('button', { type: 'button', className: 'bt-soft bt-soft-sm', disabled: busy || apps.length === 0, onClick: saveApps }, busy ? t('Connecting…') : t('Save')))) : null, - error ? h('div', { className: 'bt-connector-error', role: 'alert' }, error) : null) + error ? h('div', { className: 'bt-connector-error', role: 'alert' }, hostText(error)) : null) } // Settings → Connectors: one row per connector. diff --git a/core/src/client/i18n.js b/core/src/client/i18n.js index 8244287d7..c82089bdc 100644 --- a/core/src/client/i18n.js +++ b/core/src/client/i18n.js @@ -1713,6 +1713,17 @@ const HOST_ERRORS = [ [/^A Project memory entry needs text$/, '项目记忆条目需要文字'], [/^A Project memory entry is at most (\d+) characters$/, '项目记忆条目最多 $1 个字符'], [/^Unknown Project (\S+)$/, '找不到项目 $1'], + // #3114 cut 29: the Connectors page's Feishu row, and two Composio leftovers on the same page. + // The four below carry the host's own data — a webhook origin, a status code, Feishu's own error + // code, Composio's message — and copy it through: data is never translated. + [/^A Feishu webhook must be https on (.+)$/, '飞书 webhook 必须是 $1 上的 https 地址'], + [/^Feishu answered (\d+)$/, '飞书返回了 $1'], + [/^Feishu did not accept the webhook \((.+)\)$/, '飞书不接受这个 webhook($1)'], + [/^Not sent: Feishu refused the answer \((.+)\)$/, '没发出去:飞书拒收($1)'], + // `connector-send` names the notifier's own refusal, and its fallback literal, in the brackets. + [/^Feishu refused the message \((.+)\)$/, '飞书拒收这条消息($1)'], + [/^Pick up to (\d+) apps$/, '最多选 $1 个应用'], + [/^Composio answered (\d+)([\s\S]*)$/, 'Composio 返回了 $1$2'], ] const HOST_ZH = { 'Request failed': '请求失败', @@ -1801,6 +1812,29 @@ const HOST_ZH = { 'In use in {n} rooms: ': '正在 {n} 个房间里使用:', 'This room only: ': '只在这个房间使用:', ' +{n} more': ',还有 {n} 个', + // #3114 cut 29: the Connectors page's Feishu row in a Chinese window — the line under a failed + // connect, and the sentence a refused connect, disconnect, mode, allowed-sender or send leaves. + // A sentence with data in it is one of the HOST_ERRORS patterns above, not an entry here. + 'Could not reach Feishu': '连不上飞书', + 'Feishu addresses must start with https://': '飞书地址必须以 https:// 开头', + 'A Feishu App ID and App Secret are both needed before the long connection can dial.': '自建应用的长连接需要飞书 App ID 和 App Secret 才能拨号', + 'the Feishu long connection did not open': '飞书长连接没有建立', + 'Paste the webhook URL Feishu gave you': '请粘贴飞书给你的 webhook 地址', + 'Feishu did not answer in time — the test message may already be in the chat; check before connecting again': '飞书没有及时答复——测试消息可能已经发到群里;再连接前先确认一下', + 'Feishu did not answer in time — the message may already be in the chat; check before sending again': '飞书没有及时答复——消息可能已经发到群里;再发送前先确认一下', + 'Feishu is rate-limiting this webhook; try again in a minute': '飞书正在限流这个 webhook;请过一分钟再试', + 'Paste the App ID and App Secret Feishu gave the app': '请粘贴飞书给这个应用的 App ID 和 App Secret', + 'Feishu did not accept this App ID and App Secret': '飞书不接受这个 App ID 和 App Secret', + 'Choose how to connect Feishu first': '请先选择飞书的连接方式', + 'This connector has no allowed senders': '这个连接器没有允许发送的人', + 'Paste the open_id of the sender to allow': '请粘贴要允许的发送者 open_id', + 'Connect Feishu as an app first': '请先把飞书按自建应用连接', + 'Type a message first': '请先输入消息', + 'Not sent: could not reach Feishu': '没发出去:连不上飞书', + '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': '请先连接飞书', } Object.assign(ZH, HOST_ZH) diff --git a/core/test/connectors-feishu-zh.test.js b/core/test/connectors-feishu-zh.test.js new file mode 100644 index 000000000..9a2b081a1 --- /dev/null +++ b/core/test/connectors-feishu-zh.test.js @@ -0,0 +1,329 @@ +// #3243 (#3114 cut 29). In a Chinese window the Connectors page's Feishu row was half English: the +// card's titles and buttons were translated, but the row's own state line and the sentence under a +// refused action were the host's wording — `Could not connect: Could not reach Feishu`, and +// `Feishu addresses must start with https://` as the line itself. `hostText()` is where a host +// sentence becomes Chinese, and neither place asked it. The Composio row's two leftovers ride the +// same path: `Composio answered 422…` and `Pick up to 40 apps`. A host error's own data (host, +// status code, open_id) is not copy: it stays exactly as the host wrote it, inside Chinese words. +import { test } from 'node:test' +import assert from 'node:assert/strict' +import { fileURLToPath } from 'node:url' +import { runInNewContext } from 'node:vm' +import { build } from 'esbuild' + +const { outputFiles } = await build({ + stdin: { + contents: "export { ConnectorsPage, AppPicker } from './src/client/connectors.js'; export { DICTIONARY, hostText, installLocale } from './src/client/i18n.js'", + resolveDir: fileURLToPath(new URL('..', import.meta.url)), + }, + bundle: true, format: 'cjs', platform: 'browser', write: false, logLevel: 'silent', + external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'], +}) + +const h = (type, props, ...children) => ({ type, props: { ...props, children } }) +// One component instance's hook slots, reused by every redraw. Effects run after a render, and a +// `useState` setter redraws at once, the way React would after a click or a landed promise — so +// what the row says after an action is what the test reads. +const instance = { cursor: 0, hooks: [], pending: [], rendering: false, rerun: false, effectStates: [], effectCursor: 0 } +let root = null +let live = null +const react = { + createElement: h, + Fragment: Symbol('F'), + useLayoutEffect() {}, + useEffect(effect, deps) { instance.pending.push({ effect, deps }) }, + useRef(current) { const slot = instance.hooks[instance.cursor++] ??= { current }; return slot }, + useState(initial) { + const slot = instance.hooks[instance.cursor++] ??= { value: typeof initial === 'function' ? initial() : initial } + const set = next => { + const value = typeof next === 'function' ? next(slot.value) : next + if (Object.is(value, slot.value)) return + slot.value = value + render() + } + return [slot.value, set] + }, + useMemo(factory) { instance.cursor += 1; return factory() }, + useCallback(fn) { instance.cursor += 1; return fn }, + useSyncExternalStore(_subscribe, get) { instance.cursor += 1; return get() }, +} +const render = () => { + if (instance.rendering) { instance.rerun = true; return } + instance.rendering = true + do { + instance.rerun = false + instance.cursor = 0 + instance.pending = [] + live = root.type(root.props) + for (const { effect, deps } of instance.pending.splice(0)) { + const at = instance.effectCursor + instance.effectCursor += 1 + const state = instance.effectStates[at] ??= { ran: false, cleanup: null, deps: undefined } + const changed = !state.ran || deps === undefined || (deps.length > 0 && !deps.every((dep, index) => Object.is(dep, state.deps?.[index]))) + if (!changed) continue + state.cleanup?.() + state.cleanup = effect() ?? null + state.ran = true + state.deps = deps + } + instance.effectCursor = 0 + } while (instance.rerun) + instance.rendering = false +} + +const sandbox = { + module: { exports: {} }, + exports: {}, + document: { hidden: false, addEventListener() {}, removeEventListener() {} }, + navigator: { language: 'en' }, + localStorage: { getItem: () => null, setItem() {} }, + window: { matchMedia: () => ({ matches: true, addEventListener() {}, removeEventListener() {} }) }, + setTimeout, + clearTimeout, + requestAnimationFrame: run => { run(); return 0 }, + cancelAnimationFrame() {}, + require: (name) => { + if (name === 'react') return react + if (name === 'react-dom') return { createPortal: node => node } + if (name === '@deepseek-ai/dsh-client-ui-primitives') return {} + throw new Error(`Unexpected platform module ${name}`) + }, +} +sandbox.module.exports = sandbox.exports +runInNewContext(outputFiles[0].text, sandbox) +const { ConnectorsPage, AppPicker, DICTIONARY, hostText, installLocale } = sandbox.module.exports + +// The DSH locale service, as the app hands it to `installLocale`. +function 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 }), + } +} +const inLang = (active, run) => { + const off = installLocale(fakeLocale(active)) + try { return run() } finally { off() } +} +// A raised action answers on a promise: the language stays bound until it lands. +const inLangAsync = async (active, run) => { + const off = installLocale(fakeLocale(active)) + try { return await run() } finally { off() } +} + +const mount = (type, props) => { + instance.hooks = [] + instance.effectStates = [] + instance.effectCursor = 0 + root = { type, props } + render() + return { node: () => live } +} +const all = (node, out = []) => { + if (Array.isArray(node)) { for (const child of node) all(child, out); return out } + if (node && typeof node === 'object') { out.push(node); all(node.props?.children, out) } + return out +} +const texts = (node, out = []) => { + if (typeof node === 'string' || typeof node === 'number') { out.push(String(node)); return out } + if (Array.isArray(node)) { for (const child of node) texts(child, out); return out } + if (node && typeof node === 'object') texts(node.props?.children, out) + return out +} +const byClass = (node, className) => all(node).find(element => element.props?.className === className) +const labelOf = button => texts(button.props?.children).join('') +const buttonsOf = node => all(node).filter(element => element.type === 'button') +const buttonNamed = (node, label) => buttonsOf(node).find(button => labelOf(button) === label) +const settle = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms)) + +const roster = { bots: [], connectors: [], self: { memberId: 'me' } } +// `ConnectorsPage` draws one `ConnectorRow` element per connector; the row is where the hooks and +// the failure text live, so the row is what a test mounts. +const mountRow = (connector, acts) => { + const page = ConnectorsPage({ roster: { ...roster, connectors: [connector] }, actions: acts }) + const row = all(page).find(element => typeof element.type === 'function') + return mount(row.type, row.props) +} +const actions = () => ({ connectorRetry: () => Promise.resolve(), connectorDisconnect: () => Promise.resolve() }) +const feishu = (over = {}) => ({ id: 'feishu', name: 'Feishu', kind: 'channel', mode: 'webhook', state: 'off', modes: [{ id: 'webhook', label: 'Custom bot webhook', credentials: [] }], ...over }) + +// Every fixed sentence this screen can show, with the Chinese it must read as. A host sentence with +// data in it is not here: it goes through one of the patterns, and its data is checked below. +const FIXED = [ + ['Could not reach Feishu', '连不上飞书'], + ['Feishu addresses must start with https://', '飞书地址必须以 https:// 开头'], + ['A Feishu App ID and App Secret are both needed before the long connection can dial.', '自建应用的长连接需要飞书 App ID 和 App Secret 才能拨号'], + ['the Feishu long connection did not open', '飞书长连接没有建立'], + ['Paste the webhook URL Feishu gave you', '请粘贴飞书给你的 webhook 地址'], + ['Feishu did not answer in time — the test message may already be in the chat; check before connecting again', '飞书没有及时答复——测试消息可能已经发到群里;再连接前先确认一下'], + ['Feishu is rate-limiting this webhook; try again in a minute', '飞书正在限流这个 webhook;请过一分钟再试'], + ['Paste the App ID and App Secret Feishu gave the app', '请粘贴飞书给这个应用的 App ID 和 App Secret'], + ['Feishu did not accept this App ID and App Secret', '飞书不接受这个 App ID 和 App Secret'], + ['Choose how to connect Feishu first', '请先选择飞书的连接方式'], + ['This connector has no allowed senders', '这个连接器没有允许发送的人'], + ['Paste the open_id of the sender to allow', '请粘贴要允许的发送者 open_id'], + ['Connect Feishu as an app first', '请先把飞书按自建应用连接'], + ['Type a message first', '请先输入消息'], + ['Not sent: could not reach Feishu', '没发出去:连不上飞书'], + ['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', '请先连接飞书'], + ['Feishu did not answer in time — the message may already be in the chat; check before sending again', '飞书没有及时答复——消息可能已经发到群里;再发送前先确认一下'], +] + +// A host sentence that carries data: the words become Chinese, the data is copied through. +const WITH_DATA = [ + ['Feishu answered 500', '飞书返回了 500', '500'], + ['A Feishu webhook must be https on https://open.feishu.cn', '飞书 webhook 必须是 https://open.feishu.cn 上的 https 地址', 'https://open.feishu.cn'], + ['Feishu did not accept the webhook (feishu/19024)', '飞书不接受这个 webhook(feishu/19024)', 'feishu/19024'], + ['Not sent: Feishu refused the answer (feishu/99991663)', '没发出去:飞书拒收(feishu/99991663)', 'feishu/99991663'], + ['Composio answered 422: the apps are wrong', 'Composio 返回了 422: the apps are wrong', '422: the apps are wrong'], + ['Pick up to 40 apps', '最多选 40 个应用', '40'], + ['Feishu refused the message (feishu/99991663)', '飞书拒收这条消息(feishu/99991663)', 'feishu/99991663'], + // `connector-send` falls back to this literal when the notifier names neither an error nor a + // reason; it is the host's data, so it is copied through inside the Chinese words. + ['Feishu refused the message (no answer)', '飞书拒收这条消息(no answer)', 'no answer'], +] + +test('#3243: every fixed Feishu row failure is a Chinese sentence in a zh window', () => { + for (const [raw, zh] of FIXED) { + assert.equal(DICTIONARY.zh[raw], zh, `the dictionary holds "${raw}"`) + assert.match(zh, /[\u4e00-\u9fff]/, `"${raw}" reads Chinese, not a copied English line`) + } + inLang('zh', () => { + for (const [raw, zh] of FIXED) assert.equal(hostText(raw), zh, `hostText reads "${raw}" in Chinese`) + }) +}) + +test('#3243: an English window reads every one of them unchanged', () => { + inLang('en', () => { + for (const [raw] of FIXED) assert.equal(hostText(raw), raw) + for (const [raw] of WITH_DATA) assert.equal(hostText(raw), raw) + }) +}) + +test('#3243: a host sentence keeps its own data inside the Chinese words', () => { + inLang('zh', () => { + for (const [raw, zh, data] of WITH_DATA) { + const read = hostText(raw) + assert.equal(read, zh, `"${raw}" reads Chinese`) + assert.equal(read.includes(data), true, `"${data}" is copied through, not translated`) + } + // The one data word that is also an adjective in the copy: open_id stays the field's name. + assert.equal(hostText('Paste the open_id of the sender to allow').includes('open_id'), true) + }) +}) + +test('#3243: the Feishu row states its own failure in the window’s language', () => { + const statusOf = connector => texts(byClass(mountRow(connector, actions()).node(), 'bt-connector-status')).join('') + inLang('zh', () => { + assert.equal(statusOf(feishu({ state: 'error', error: 'Could not reach Feishu' })), '连接失败:连不上飞书') + assert.equal(statusOf(feishu({ state: 'error', error: 'Feishu addresses must start with https://' })), '连接失败:飞书地址必须以 https:// 开头') + }) + inLang('en', () => { + assert.equal(statusOf(feishu({ state: 'error', error: 'Could not reach Feishu' })), 'Could not connect: Could not reach Feishu') + }) +}) + +test('#3243: a refused action inside the row reads in the window’s language too', async () => { + const refusing = (error) => ({ + connectorRetry: () => Promise.resolve(), + connectorDisconnect: () => Promise.reject(new Error(error)), + connectorSend: () => Promise.reject(new Error(error)), + }) + await inLangAsync('zh', async () => { + const view = mountRow(feishu({ state: 'ready' }), refusing('Could not reach Feishu')) + buttonNamed(view.node(), '断开').props.onClick() + await settle() + assert.equal(texts(byClass(view.node(), 'bt-connector-error')).join(''), '连不上飞书') + }) + await inLangAsync('en', async () => { + const view = mountRow(feishu({ state: 'ready' }), refusing('Could not reach Feishu')) + buttonNamed(view.node(), 'Disconnect').props.onClick() + await settle() + assert.equal(texts(byClass(view.node(), 'bt-connector-error')).join(''), 'Could not reach Feishu') + }) +}) + +test('#3243: a refused send says so in the window’s language, data untouched', async () => { + await inLangAsync('zh', async () => { + const view = mountRow(feishu({ state: 'ready' }), { + connectorRetry: () => Promise.resolve(), + connectorDisconnect: () => Promise.resolve(), + connectorSend: () => Promise.reject(new Error('Not sent: Feishu refused the answer (feishu/99991663)')), + }) + const field = all(view.node()).find(element => element.props?.['aria-label'] === '要发到飞书的消息') + assert.ok(field, 'the send field is drawn in the row') + field.props.onChange({ target: { value: 'hello' } }) + buttonNamed(view.node(), '发送').props.onClick() + await settle() + assert.equal(texts(byClass(view.node(), 'bt-connector-error')).join(''), '没发出去:飞书拒收(feishu/99991663)') + }) +}) + +// `connector-send` (the row's send button) raises its own two sentences, separate from the room's +// `Not sent: …` answer: the notifier's refusal and its timeout. +test('#3243: a message the row could not send says so in the window’s language', async () => { + const sendFails = (error, labels) => { + const view = mountRow(feishu({ state: 'ready' }), { + connectorRetry: () => Promise.resolve(), + connectorDisconnect: () => Promise.resolve(), + connectorSend: () => Promise.reject(new Error(error)), + }) + const field = all(view.node()).find(element => element.props?.['aria-label'] === labels.field) + field.props.onChange({ target: { value: 'hello' } }) + buttonNamed(view.node(), labels.send).props.onClick() + return view + } + const zh = { field: '要发到飞书的消息', send: '发送' } + const en = { field: 'Message to send to Feishu', send: 'Send' } + const errorLine = view => texts(byClass(view.node(), 'bt-connector-error')).join('') + await inLangAsync('zh', async () => { + const refused = sendFails('Feishu refused the message (feishu/99991663)', zh) + await settle() + assert.equal(errorLine(refused), '飞书拒收这条消息(feishu/99991663)') + const noAnswer = sendFails('Feishu refused the message (no answer)', zh) + await settle() + assert.equal(errorLine(noAnswer), '飞书拒收这条消息(no answer)') + const timedOut = sendFails('Feishu did not answer in time — the message may already be in the chat; check before sending again', zh) + await settle() + assert.equal(errorLine(timedOut), '飞书没有及时答复——消息可能已经发到群里;再发送前先确认一下') + }) + await inLangAsync('en', async () => { + const view = sendFails('Feishu refused the message (feishu/99991663)', en) + await settle() + assert.equal(errorLine(view), 'Feishu refused the message (feishu/99991663)') + const timedOut = sendFails('Feishu did not answer in time — the message may already be in the chat; check before sending again', en) + await settle() + assert.equal(errorLine(timedOut), 'Feishu did not answer in time — the message may already be in the chat; check before sending again') + }) +}) + +// The Composio row's search hint is the one place `Composio answered 422…` surfaced unread. +test('#3243: the Composio search hint reads its host sentence in the window’s language', async () => { + const search = () => Promise.reject(new Error('Composio answered 422: the apps are wrong')) + const typed = () => { + const view = mount(AppPicker, { apps: [], onChange: () => {}, search }) + const field = all(view.node()).find(element => element.props?.className === 'bt-input' && element.props?.type === 'search') + field.props.onChange({ target: { value: 'gmail' } }) + return view + } + const hintOf = view => texts(all(view.node()).find(element => element.props?.className === 'bt-set-hint')).join('') + // The search is debounced and answers on a promise: the language stays bound until the hint is + // drawn, the way the window keeps its language while a row waits for the host. + await inLangAsync('zh', async () => { + const view = typed() + await settle(350) + assert.equal(hintOf(view), '无法搜索 Composio:Composio 返回了 422: the apps are wrong') + }) + await inLangAsync('en', async () => { + const view = typed() + await settle(350) + assert.equal(hintOf(view), 'Could not search Composio: Composio answered 422: the apps are wrong') + }) +}) diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index 71b38ccdb..0c9a39cf5 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -272,16 +272,17 @@ diff --git a/src/client/browser-pane.js b/src/client/browser-pane.js diff --git a/src/client/connectors.js b/src/client/connectors.js --- a/src/client/connectors.js +++ b/src/client/connectors.js -@@ -1,41 +1,233 @@ +@@ -1,41 +1,235 @@ -import { createElement as h, useRef, useState } from 'react' +import { createElement as h, useCallback, useEffect, useRef, useState } from 'react' import { useMorph } from './motion.js' import { MaskedInput } from './secret-card.js' +-import { t } from './i18n.js' +import { ConnectorIcon } from './icons.js' +import { SwitchRow } from './bot-settings.js' +import { lockedWindow } from './schedules.js' +import { ConnectorBots, usageText } from './connector-bots.js' - import { t } from './i18n.js' ++import { hostText, t } from './i18n.js' +import { copiedToClipboard } from '../shared/remote-label.js' const TOKEN_URL = 'https://github.com/settings/personal-access-tokens/new' @@ -320,7 +321,10 @@ diff --git a/src/client/connectors.js b/src/client/connectors.js function statusText(connector) { if (connector.state === 'connecting') return t('Connecting…') - if (connector.state === 'error') return t('Could not connect: {error}', { error: connector.error ?? '' }) +- if (connector.state === 'error') return t('Could not connect: {error}', { error: connector.error ?? '' }) ++ // The host wrote the failure; a zh window reads it in Chinese, and the host's own data inside it ++ // (an origin, a status code, an open_id) is copied through as written (#3243). ++ if (connector.state === 'error') return t('Could not connect: {error}', { error: hostText(connector.error ?? '') }) + if (connector.state === 'ready' && connector.kind === 'channel') { + return connector.mode === 'app' ? t('Connected: app, over the long connection') : t('Connected: custom bot webhook') + } @@ -417,7 +421,7 @@ diff --git a/src/client/connectors.js b/src/client/connectors.js + apps.length > 0 ? h('div', { className: 'bt-states', 'aria-label': t('Picked apps') }, apps.map(slug => + h(AppChip, { key: slug, name: nameOf(slug), status: statuses[slug], onRemove: () => onChange(apps.filter(app => app !== slug)) }))) : null, + h('input', { className: 'bt-input', type: 'search', value: query, spellCheck: false, 'aria-label': t('Search apps'), placeholder: t('Search Composio apps'), onChange: event => setQuery(event.target.value) }), -+ failed ? h('span', { className: 'bt-set-hint' }, t('Could not search Composio: {error}', { error: failed })) : null, ++ failed ? h('span', { className: 'bt-set-hint' }, t('Could not search Composio: {error}', { error: hostText(failed) })) : null, + h('div', { className: 'bt-states', 'aria-label': t('Apps to add') }, results.length === 0 + ? h('span', { className: 'bt-set-hint' }, t('No apps match')) + : results.map(app => h('button', { key: app.slug, type: 'button', className: 'bt-state', 'aria-pressed': false, onClick: () => { names.current.set(app.slug, app.name); onChange([...apps, app.slug]) } }, app.name)))) @@ -549,6 +553,7 @@ diff --git a/src/client/connectors.js b/src/client/connectors.js - h('a', { className: 'bt-connector-link', href: TOKEN_URL, target: '_blank', rel: 'noopener noreferrer' }, t('Create a token on GitHub')), - h('button', { type: 'button', className: 'bt-soft bt-soft-sm', disabled: busy, onClick: () => { setForm(false); setToken(''); setError(null) } }, t('Cancel')), - h('button', { type: 'button', className: 'bt-soft bt-soft-sm', disabled: busy || token.trim() === '', onClick: connect }, busy ? t('Connecting…') : t('Connect')))) : null, +- error ? h('div', { className: 'bt-connector-error', role: 'alert' }, error) : null) + h('a', { className: 'bt-connector-link', href: channel ? (chosen?.link ?? FEISHU_WEBHOOK_URL) : gateway ? COMPOSIO_KEY_URL : TOKEN_URL, target: '_blank', rel: 'noopener noreferrer' }, + channel ? t(chosen?.linkLabel ?? 'Get a webhook URL in Feishu') : gateway ? t('Get a Composio API key') : t('Create a token on GitHub')), + h('button', { type: 'button', className: 'bt-soft bt-soft-sm', disabled: busy, onClick: () => { setForm(false); setToken(''); setValues({}); setError(null) } }, t('Cancel')), @@ -560,7 +565,7 @@ diff --git a/src/client/connectors.js b/src/client/connectors.js + h('span', { className: 'bt-connector-link' }), + h('button', { type: 'button', className: 'bt-soft bt-soft-sm', disabled: busy, onClick: () => { setPicking(false); setError(null) } }, t('Cancel')), + h('button', { type: 'button', className: 'bt-soft bt-soft-sm', disabled: busy || apps.length === 0, onClick: saveApps }, busy ? t('Connecting…') : t('Save')))) : null, - error ? h('div', { className: 'bt-connector-error', role: 'alert' }, error) : null) ++ error ? h('div', { className: 'bt-connector-error', role: 'alert' }, hostText(error)) : null) } // Settings → Connectors: one row per connector. @@ -2027,7 +2032,7 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js [/^HTTP (\d+)$/, '请求失败(HTTP $1)'], [/^GitHub answered (\d+)$/, 'GitHub 返回了 $1'], [/^Keep the name under (\d+) characters$/, '名字不能超过 $1 个字'], -@@ -872,6 +872,16 @@ const HOST_ERRORS = [ +@@ -872,6 +872,27 @@ const HOST_ERRORS = [ [/^No entry in [\s\S]* matches "([\s\S]*)"\.[\s\S]*$/, '找不到「$1」这条记忆'], [/^"([\s\S]*)" matches (\d+) entries in [\s\S]*$/, '「$1」对应了 $2 条记忆,请说得更具体'], [/^Memory cannot change now: [\s\S]*$/, '现在不能修改记忆:另一个 dsh 正在使用这个 Bot 团队'], @@ -2041,6 +2046,17 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js + [/^A Project memory entry needs text$/, '项目记忆条目需要文字'], + [/^A Project memory entry is at most (\d+) characters$/, '项目记忆条目最多 $1 个字符'], + [/^Unknown Project (\S+)$/, '找不到项目 $1'], ++ // #3114 cut 29: the Connectors page's Feishu row, and two Composio leftovers on the same page. ++ // The four below carry the host's own data — a webhook origin, a status code, Feishu's own error ++ // code, Composio's message — and copy it through: data is never translated. ++ [/^A Feishu webhook must be https on (.+)$/, '飞书 webhook 必须是 $1 上的 https 地址'], ++ [/^Feishu answered (\d+)$/, '飞书返回了 $1'], ++ [/^Feishu did not accept the webhook \((.+)\)$/, '飞书不接受这个 webhook($1)'], ++ [/^Not sent: Feishu refused the answer \((.+)\)$/, '没发出去:飞书拒收($1)'], ++ // `connector-send` names the notifier's own refusal, and its fallback literal, in the brackets. ++ [/^Feishu refused the message \((.+)\)$/, '飞书拒收这条消息($1)'], ++ [/^Pick up to (\d+) apps$/, '最多选 $1 个应用'], ++ [/^Composio answered (\d+)([\s\S]*)$/, 'Composio 返回了 $1$2'], ] const HOST_ZH = { 'Request failed': '请求失败', @@ -2065,7 +2081,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,47 @@ const HOST_ZH = { +@@ -905,6 +905,70 @@ 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 不能列出文件夹', @@ -2110,6 +2126,29 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js + 'In use in {n} rooms: ': '正在 {n} 个房间里使用:', + 'This room only: ': '只在这个房间使用:', + ' +{n} more': ',还有 {n} 个', ++ // #3114 cut 29: the Connectors page's Feishu row in a Chinese window — the line under a failed ++ // connect, and the sentence a refused connect, disconnect, mode, allowed-sender or send leaves. ++ // A sentence with data in it is one of the HOST_ERRORS patterns above, not an entry here. ++ 'Could not reach Feishu': '连不上飞书', ++ 'Feishu addresses must start with https://': '飞书地址必须以 https:// 开头', ++ 'A Feishu App ID and App Secret are both needed before the long connection can dial.': '自建应用的长连接需要飞书 App ID 和 App Secret 才能拨号', ++ 'the Feishu long connection did not open': '飞书长连接没有建立', ++ 'Paste the webhook URL Feishu gave you': '请粘贴飞书给你的 webhook 地址', ++ 'Feishu did not answer in time — the test message may already be in the chat; check before connecting again': '飞书没有及时答复——测试消息可能已经发到群里;再连接前先确认一下', ++ 'Feishu did not answer in time — the message may already be in the chat; check before sending again': '飞书没有及时答复——消息可能已经发到群里;再发送前先确认一下', ++ 'Feishu is rate-limiting this webhook; try again in a minute': '飞书正在限流这个 webhook;请过一分钟再试', ++ 'Paste the App ID and App Secret Feishu gave the app': '请粘贴飞书给这个应用的 App ID 和 App Secret', ++ 'Feishu did not accept this App ID and App Secret': '飞书不接受这个 App ID 和 App Secret', ++ 'Choose how to connect Feishu first': '请先选择飞书的连接方式', ++ 'This connector has no allowed senders': '这个连接器没有允许发送的人', ++ 'Paste the open_id of the sender to allow': '请粘贴要允许的发送者 open_id', ++ 'Connect Feishu as an app first': '请先把飞书按自建应用连接', ++ 'Type a message first': '请先输入消息', ++ 'Not sent: could not reach Feishu': '没发出去:连不上飞书', ++ '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': '请先连接飞书', } Object.assign(ZH, HOST_ZH) diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index 19bccd803..064c1b433 100644 --- a/patches/ds-bot/0008-client-bundle.patch +++ b/patches/ds-bot/0008-client-bundle.patch @@ -1287,7 +1287,7 @@ diff --git a/client.js b/client.js [/^HTTP (\d+)$/, "请求失败(HTTP $1)"], [/^GitHub answered (\d+)$/, "GitHub 返回了 $1"], [/^Keep the name under (\d+) characters$/, "名字不能超过 $1 个字"], -@@ -918,7 +918,17 @@ var HOST_ERRORS = [ +@@ -918,7 +918,28 @@ var HOST_ERRORS = [ [/^There is no entry (.+)\.$/, "没有第 $1 条"], [/^No entry in [\s\S]* matches "([\s\S]*)"\.[\s\S]*$/, "找不到「$1」这条记忆"], [/^"([\s\S]*)" matches (\d+) entries in [\s\S]*$/, "「$1」对应了 $2 条记忆,请说得更具体"], @@ -1302,7 +1302,18 @@ diff --git a/client.js b/client.js + [/^A binding needs the member id$/, "绑定需要 member id"], + [/^A Project memory entry needs text$/, "项目记忆条目需要文字"], + [/^A Project memory entry is at most (\d+) characters$/, "项目记忆条目最多 $1 个字符"], -+ [/^Unknown Project (\S+)$/, "找不到项目 $1"] ++ [/^Unknown Project (\S+)$/, "找不到项目 $1"], ++ // #3114 cut 29: the Connectors page's Feishu row, and two Composio leftovers on the same page. ++ // The four below carry the host's own data — a webhook origin, a status code, Feishu's own error ++ // code, Composio's message — and copy it through: data is never translated. ++ [/^A Feishu webhook must be https on (.+)$/, "飞书 webhook 必须是 $1 上的 https 地址"], ++ [/^Feishu answered (\d+)$/, "飞书返回了 $1"], ++ [/^Feishu did not accept the webhook \((.+)\)$/, "飞书不接受这个 webhook($1)"], ++ [/^Not sent: Feishu refused the answer \((.+)\)$/, "没发出去:飞书拒收($1)"], ++ // `connector-send` names the notifier's own refusal, and its fallback literal, in the brackets. ++ [/^Feishu refused the message \((.+)\)$/, "飞书拒收这条消息($1)"], ++ [/^Pick up to (\d+) apps$/, "最多选 $1 个应用"], ++ [/^Composio answered (\d+)([\s\S]*)$/, "Composio 返回了 $1$2"] ]; var HOST_ZH = { "Request failed": "请求失败", @@ -1327,7 +1338,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,51 @@ var HOST_ZH = { +@@ -951,10 +951,74 @@ var HOST_ZH = { "The model wrote nothing": "模型没有输出内容", "Write the entry to save.": "请写下要保存的内容。", "This DeepSeek Harness has no folder chooser": "这个 DeepSeek Harness 没有文件夹选择窗口", @@ -1373,7 +1384,30 @@ diff --git a/client.js b/client.js + "In use in {n} room: ": "正在 {n} 个房间里使用:", + "In use in {n} rooms: ": "正在 {n} 个房间里使用:", + "This room only: ": "只在这个房间使用:", -+ " +{n} more": ",还有 {n} 个" ++ " +{n} more": ",还有 {n} 个", ++ // #3114 cut 29: the Connectors page's Feishu row in a Chinese window — the line under a failed ++ // connect, and the sentence a refused connect, disconnect, mode, allowed-sender or send leaves. ++ // A sentence with data in it is one of the HOST_ERRORS patterns above, not an entry here. ++ "Could not reach Feishu": "连不上飞书", ++ "Feishu addresses must start with https://": "飞书地址必须以 https:// 开头", ++ "A Feishu App ID and App Secret are both needed before the long connection can dial.": "自建应用的长连接需要飞书 App ID 和 App Secret 才能拨号", ++ "the Feishu long connection did not open": "飞书长连接没有建立", ++ "Paste the webhook URL Feishu gave you": "请粘贴飞书给你的 webhook 地址", ++ "Feishu did not answer in time — the test message may already be in the chat; check before connecting again": "飞书没有及时答复——测试消息可能已经发到群里;再连接前先确认一下", ++ "Feishu did not answer in time — the message may already be in the chat; check before sending again": "飞书没有及时答复——消息可能已经发到群里;再发送前先确认一下", ++ "Feishu is rate-limiting this webhook; try again in a minute": "飞书正在限流这个 webhook;请过一分钟再试", ++ "Paste the App ID and App Secret Feishu gave the app": "请粘贴飞书给这个应用的 App ID 和 App Secret", ++ "Feishu did not accept this App ID and App Secret": "飞书不接受这个 App ID 和 App Secret", ++ "Choose how to connect Feishu first": "请先选择飞书的连接方式", ++ "This connector has no allowed senders": "这个连接器没有允许发送的人", ++ "Paste the open_id of the sender to allow": "请粘贴要允许的发送者 open_id", ++ "Connect Feishu as an app first": "请先把飞书按自建应用连接", ++ "Type a message first": "请先输入消息", ++ "Not sent: could not reach Feishu": "没发出去:连不上飞书", ++ "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": "请先连接飞书" }; Object.assign(ZH, HOST_ZH); -var fill = (text, params) => params ? text.replace(/\{(\w+)\}/g, (match, name) => name in params ? String(params[name]) : match) : text; @@ -24791,7 +24825,8 @@ diff --git a/client.js b/client.js +}; function statusText2(connector) { if (connector.state === "connecting") return t("Connecting…"); - if (connector.state === "error") return t("Could not connect: {error}", { error: connector.error ?? "" }); +- if (connector.state === "error") return t("Could not connect: {error}", { error: connector.error ?? "" }); ++ if (connector.state === "error") return t("Could not connect: {error}", { error: hostText(connector.error ?? "") }); + if (connector.state === "ready" && connector.kind === "channel") { + return connector.mode === "app" ? t("Connected: app, over the long connection") : t("Connected: custom bot webhook"); + } @@ -24920,7 +24955,7 @@ diff --git a/client.js b/client.js + { className: "bt-connector-apps" }, + apps.length > 0 ? (0, import_react42.createElement)("div", { className: "bt-states", "aria-label": t("Picked apps") }, apps.map((slug) => (0, import_react42.createElement)(AppChip, { key: slug, name: nameOf(slug), status: statuses[slug], onRemove: () => onChange(apps.filter((app) => app !== slug)) }))) : null, + (0, import_react42.createElement)("input", { className: "bt-input", type: "search", value: query, spellCheck: false, "aria-label": t("Search apps"), placeholder: t("Search Composio apps"), onChange: (event) => setQuery(event.target.value) }), -+ failed ? (0, import_react42.createElement)("span", { className: "bt-set-hint" }, t("Could not search Composio: {error}", { error: failed })) : null, ++ failed ? (0, import_react42.createElement)("span", { className: "bt-set-hint" }, t("Could not search Composio: {error}", { error: hostText(failed) })) : null, + (0, import_react42.createElement)("div", { className: "bt-states", "aria-label": t("Apps to add") }, results.length === 0 ? (0, import_react42.createElement)("span", { className: "bt-set-hint" }, t("No apps match")) : results.map((app) => (0, import_react42.createElement)("button", { key: app.slug, type: "button", className: "bt-state", "aria-pressed": false, onClick: () => { + names.current.set(app.slug, app.name); + onChange([...apps, app.slug]); @@ -25140,7 +25175,7 @@ diff --git a/client.js b/client.js ) ) : null, - error ? (0, import_react25.createElement)("div", { className: "bt-connector-error", role: "alert" }, error) : null -+ error ? (0, import_react42.createElement)("div", { className: "bt-connector-error", role: "alert" }, error) : null ++ error ? (0, import_react42.createElement)("div", { className: "bt-connector-error", role: "alert" }, hostText(error)) : null ); } function ConnectorsPage({ roster, actions }) { diff --git a/patches/ds-bot/files/test/connectors-feishu-zh.test.js b/patches/ds-bot/files/test/connectors-feishu-zh.test.js new file mode 100644 index 000000000..9a2b081a1 --- /dev/null +++ b/patches/ds-bot/files/test/connectors-feishu-zh.test.js @@ -0,0 +1,329 @@ +// #3243 (#3114 cut 29). In a Chinese window the Connectors page's Feishu row was half English: the +// card's titles and buttons were translated, but the row's own state line and the sentence under a +// refused action were the host's wording — `Could not connect: Could not reach Feishu`, and +// `Feishu addresses must start with https://` as the line itself. `hostText()` is where a host +// sentence becomes Chinese, and neither place asked it. The Composio row's two leftovers ride the +// same path: `Composio answered 422…` and `Pick up to 40 apps`. A host error's own data (host, +// status code, open_id) is not copy: it stays exactly as the host wrote it, inside Chinese words. +import { test } from 'node:test' +import assert from 'node:assert/strict' +import { fileURLToPath } from 'node:url' +import { runInNewContext } from 'node:vm' +import { build } from 'esbuild' + +const { outputFiles } = await build({ + stdin: { + contents: "export { ConnectorsPage, AppPicker } from './src/client/connectors.js'; export { DICTIONARY, hostText, installLocale } from './src/client/i18n.js'", + resolveDir: fileURLToPath(new URL('..', import.meta.url)), + }, + bundle: true, format: 'cjs', platform: 'browser', write: false, logLevel: 'silent', + external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'], +}) + +const h = (type, props, ...children) => ({ type, props: { ...props, children } }) +// One component instance's hook slots, reused by every redraw. Effects run after a render, and a +// `useState` setter redraws at once, the way React would after a click or a landed promise — so +// what the row says after an action is what the test reads. +const instance = { cursor: 0, hooks: [], pending: [], rendering: false, rerun: false, effectStates: [], effectCursor: 0 } +let root = null +let live = null +const react = { + createElement: h, + Fragment: Symbol('F'), + useLayoutEffect() {}, + useEffect(effect, deps) { instance.pending.push({ effect, deps }) }, + useRef(current) { const slot = instance.hooks[instance.cursor++] ??= { current }; return slot }, + useState(initial) { + const slot = instance.hooks[instance.cursor++] ??= { value: typeof initial === 'function' ? initial() : initial } + const set = next => { + const value = typeof next === 'function' ? next(slot.value) : next + if (Object.is(value, slot.value)) return + slot.value = value + render() + } + return [slot.value, set] + }, + useMemo(factory) { instance.cursor += 1; return factory() }, + useCallback(fn) { instance.cursor += 1; return fn }, + useSyncExternalStore(_subscribe, get) { instance.cursor += 1; return get() }, +} +const render = () => { + if (instance.rendering) { instance.rerun = true; return } + instance.rendering = true + do { + instance.rerun = false + instance.cursor = 0 + instance.pending = [] + live = root.type(root.props) + for (const { effect, deps } of instance.pending.splice(0)) { + const at = instance.effectCursor + instance.effectCursor += 1 + const state = instance.effectStates[at] ??= { ran: false, cleanup: null, deps: undefined } + const changed = !state.ran || deps === undefined || (deps.length > 0 && !deps.every((dep, index) => Object.is(dep, state.deps?.[index]))) + if (!changed) continue + state.cleanup?.() + state.cleanup = effect() ?? null + state.ran = true + state.deps = deps + } + instance.effectCursor = 0 + } while (instance.rerun) + instance.rendering = false +} + +const sandbox = { + module: { exports: {} }, + exports: {}, + document: { hidden: false, addEventListener() {}, removeEventListener() {} }, + navigator: { language: 'en' }, + localStorage: { getItem: () => null, setItem() {} }, + window: { matchMedia: () => ({ matches: true, addEventListener() {}, removeEventListener() {} }) }, + setTimeout, + clearTimeout, + requestAnimationFrame: run => { run(); return 0 }, + cancelAnimationFrame() {}, + require: (name) => { + if (name === 'react') return react + if (name === 'react-dom') return { createPortal: node => node } + if (name === '@deepseek-ai/dsh-client-ui-primitives') return {} + throw new Error(`Unexpected platform module ${name}`) + }, +} +sandbox.module.exports = sandbox.exports +runInNewContext(outputFiles[0].text, sandbox) +const { ConnectorsPage, AppPicker, DICTIONARY, hostText, installLocale } = sandbox.module.exports + +// The DSH locale service, as the app hands it to `installLocale`. +function 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 }), + } +} +const inLang = (active, run) => { + const off = installLocale(fakeLocale(active)) + try { return run() } finally { off() } +} +// A raised action answers on a promise: the language stays bound until it lands. +const inLangAsync = async (active, run) => { + const off = installLocale(fakeLocale(active)) + try { return await run() } finally { off() } +} + +const mount = (type, props) => { + instance.hooks = [] + instance.effectStates = [] + instance.effectCursor = 0 + root = { type, props } + render() + return { node: () => live } +} +const all = (node, out = []) => { + if (Array.isArray(node)) { for (const child of node) all(child, out); return out } + if (node && typeof node === 'object') { out.push(node); all(node.props?.children, out) } + return out +} +const texts = (node, out = []) => { + if (typeof node === 'string' || typeof node === 'number') { out.push(String(node)); return out } + if (Array.isArray(node)) { for (const child of node) texts(child, out); return out } + if (node && typeof node === 'object') texts(node.props?.children, out) + return out +} +const byClass = (node, className) => all(node).find(element => element.props?.className === className) +const labelOf = button => texts(button.props?.children).join('') +const buttonsOf = node => all(node).filter(element => element.type === 'button') +const buttonNamed = (node, label) => buttonsOf(node).find(button => labelOf(button) === label) +const settle = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms)) + +const roster = { bots: [], connectors: [], self: { memberId: 'me' } } +// `ConnectorsPage` draws one `ConnectorRow` element per connector; the row is where the hooks and +// the failure text live, so the row is what a test mounts. +const mountRow = (connector, acts) => { + const page = ConnectorsPage({ roster: { ...roster, connectors: [connector] }, actions: acts }) + const row = all(page).find(element => typeof element.type === 'function') + return mount(row.type, row.props) +} +const actions = () => ({ connectorRetry: () => Promise.resolve(), connectorDisconnect: () => Promise.resolve() }) +const feishu = (over = {}) => ({ id: 'feishu', name: 'Feishu', kind: 'channel', mode: 'webhook', state: 'off', modes: [{ id: 'webhook', label: 'Custom bot webhook', credentials: [] }], ...over }) + +// Every fixed sentence this screen can show, with the Chinese it must read as. A host sentence with +// data in it is not here: it goes through one of the patterns, and its data is checked below. +const FIXED = [ + ['Could not reach Feishu', '连不上飞书'], + ['Feishu addresses must start with https://', '飞书地址必须以 https:// 开头'], + ['A Feishu App ID and App Secret are both needed before the long connection can dial.', '自建应用的长连接需要飞书 App ID 和 App Secret 才能拨号'], + ['the Feishu long connection did not open', '飞书长连接没有建立'], + ['Paste the webhook URL Feishu gave you', '请粘贴飞书给你的 webhook 地址'], + ['Feishu did not answer in time — the test message may already be in the chat; check before connecting again', '飞书没有及时答复——测试消息可能已经发到群里;再连接前先确认一下'], + ['Feishu is rate-limiting this webhook; try again in a minute', '飞书正在限流这个 webhook;请过一分钟再试'], + ['Paste the App ID and App Secret Feishu gave the app', '请粘贴飞书给这个应用的 App ID 和 App Secret'], + ['Feishu did not accept this App ID and App Secret', '飞书不接受这个 App ID 和 App Secret'], + ['Choose how to connect Feishu first', '请先选择飞书的连接方式'], + ['This connector has no allowed senders', '这个连接器没有允许发送的人'], + ['Paste the open_id of the sender to allow', '请粘贴要允许的发送者 open_id'], + ['Connect Feishu as an app first', '请先把飞书按自建应用连接'], + ['Type a message first', '请先输入消息'], + ['Not sent: could not reach Feishu', '没发出去:连不上飞书'], + ['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', '请先连接飞书'], + ['Feishu did not answer in time — the message may already be in the chat; check before sending again', '飞书没有及时答复——消息可能已经发到群里;再发送前先确认一下'], +] + +// A host sentence that carries data: the words become Chinese, the data is copied through. +const WITH_DATA = [ + ['Feishu answered 500', '飞书返回了 500', '500'], + ['A Feishu webhook must be https on https://open.feishu.cn', '飞书 webhook 必须是 https://open.feishu.cn 上的 https 地址', 'https://open.feishu.cn'], + ['Feishu did not accept the webhook (feishu/19024)', '飞书不接受这个 webhook(feishu/19024)', 'feishu/19024'], + ['Not sent: Feishu refused the answer (feishu/99991663)', '没发出去:飞书拒收(feishu/99991663)', 'feishu/99991663'], + ['Composio answered 422: the apps are wrong', 'Composio 返回了 422: the apps are wrong', '422: the apps are wrong'], + ['Pick up to 40 apps', '最多选 40 个应用', '40'], + ['Feishu refused the message (feishu/99991663)', '飞书拒收这条消息(feishu/99991663)', 'feishu/99991663'], + // `connector-send` falls back to this literal when the notifier names neither an error nor a + // reason; it is the host's data, so it is copied through inside the Chinese words. + ['Feishu refused the message (no answer)', '飞书拒收这条消息(no answer)', 'no answer'], +] + +test('#3243: every fixed Feishu row failure is a Chinese sentence in a zh window', () => { + for (const [raw, zh] of FIXED) { + assert.equal(DICTIONARY.zh[raw], zh, `the dictionary holds "${raw}"`) + assert.match(zh, /[\u4e00-\u9fff]/, `"${raw}" reads Chinese, not a copied English line`) + } + inLang('zh', () => { + for (const [raw, zh] of FIXED) assert.equal(hostText(raw), zh, `hostText reads "${raw}" in Chinese`) + }) +}) + +test('#3243: an English window reads every one of them unchanged', () => { + inLang('en', () => { + for (const [raw] of FIXED) assert.equal(hostText(raw), raw) + for (const [raw] of WITH_DATA) assert.equal(hostText(raw), raw) + }) +}) + +test('#3243: a host sentence keeps its own data inside the Chinese words', () => { + inLang('zh', () => { + for (const [raw, zh, data] of WITH_DATA) { + const read = hostText(raw) + assert.equal(read, zh, `"${raw}" reads Chinese`) + assert.equal(read.includes(data), true, `"${data}" is copied through, not translated`) + } + // The one data word that is also an adjective in the copy: open_id stays the field's name. + assert.equal(hostText('Paste the open_id of the sender to allow').includes('open_id'), true) + }) +}) + +test('#3243: the Feishu row states its own failure in the window’s language', () => { + const statusOf = connector => texts(byClass(mountRow(connector, actions()).node(), 'bt-connector-status')).join('') + inLang('zh', () => { + assert.equal(statusOf(feishu({ state: 'error', error: 'Could not reach Feishu' })), '连接失败:连不上飞书') + assert.equal(statusOf(feishu({ state: 'error', error: 'Feishu addresses must start with https://' })), '连接失败:飞书地址必须以 https:// 开头') + }) + inLang('en', () => { + assert.equal(statusOf(feishu({ state: 'error', error: 'Could not reach Feishu' })), 'Could not connect: Could not reach Feishu') + }) +}) + +test('#3243: a refused action inside the row reads in the window’s language too', async () => { + const refusing = (error) => ({ + connectorRetry: () => Promise.resolve(), + connectorDisconnect: () => Promise.reject(new Error(error)), + connectorSend: () => Promise.reject(new Error(error)), + }) + await inLangAsync('zh', async () => { + const view = mountRow(feishu({ state: 'ready' }), refusing('Could not reach Feishu')) + buttonNamed(view.node(), '断开').props.onClick() + await settle() + assert.equal(texts(byClass(view.node(), 'bt-connector-error')).join(''), '连不上飞书') + }) + await inLangAsync('en', async () => { + const view = mountRow(feishu({ state: 'ready' }), refusing('Could not reach Feishu')) + buttonNamed(view.node(), 'Disconnect').props.onClick() + await settle() + assert.equal(texts(byClass(view.node(), 'bt-connector-error')).join(''), 'Could not reach Feishu') + }) +}) + +test('#3243: a refused send says so in the window’s language, data untouched', async () => { + await inLangAsync('zh', async () => { + const view = mountRow(feishu({ state: 'ready' }), { + connectorRetry: () => Promise.resolve(), + connectorDisconnect: () => Promise.resolve(), + connectorSend: () => Promise.reject(new Error('Not sent: Feishu refused the answer (feishu/99991663)')), + }) + const field = all(view.node()).find(element => element.props?.['aria-label'] === '要发到飞书的消息') + assert.ok(field, 'the send field is drawn in the row') + field.props.onChange({ target: { value: 'hello' } }) + buttonNamed(view.node(), '发送').props.onClick() + await settle() + assert.equal(texts(byClass(view.node(), 'bt-connector-error')).join(''), '没发出去:飞书拒收(feishu/99991663)') + }) +}) + +// `connector-send` (the row's send button) raises its own two sentences, separate from the room's +// `Not sent: …` answer: the notifier's refusal and its timeout. +test('#3243: a message the row could not send says so in the window’s language', async () => { + const sendFails = (error, labels) => { + const view = mountRow(feishu({ state: 'ready' }), { + connectorRetry: () => Promise.resolve(), + connectorDisconnect: () => Promise.resolve(), + connectorSend: () => Promise.reject(new Error(error)), + }) + const field = all(view.node()).find(element => element.props?.['aria-label'] === labels.field) + field.props.onChange({ target: { value: 'hello' } }) + buttonNamed(view.node(), labels.send).props.onClick() + return view + } + const zh = { field: '要发到飞书的消息', send: '发送' } + const en = { field: 'Message to send to Feishu', send: 'Send' } + const errorLine = view => texts(byClass(view.node(), 'bt-connector-error')).join('') + await inLangAsync('zh', async () => { + const refused = sendFails('Feishu refused the message (feishu/99991663)', zh) + await settle() + assert.equal(errorLine(refused), '飞书拒收这条消息(feishu/99991663)') + const noAnswer = sendFails('Feishu refused the message (no answer)', zh) + await settle() + assert.equal(errorLine(noAnswer), '飞书拒收这条消息(no answer)') + const timedOut = sendFails('Feishu did not answer in time — the message may already be in the chat; check before sending again', zh) + await settle() + assert.equal(errorLine(timedOut), '飞书没有及时答复——消息可能已经发到群里;再发送前先确认一下') + }) + await inLangAsync('en', async () => { + const view = sendFails('Feishu refused the message (feishu/99991663)', en) + await settle() + assert.equal(errorLine(view), 'Feishu refused the message (feishu/99991663)') + const timedOut = sendFails('Feishu did not answer in time — the message may already be in the chat; check before sending again', en) + await settle() + assert.equal(errorLine(timedOut), 'Feishu did not answer in time — the message may already be in the chat; check before sending again') + }) +}) + +// The Composio row's search hint is the one place `Composio answered 422…` surfaced unread. +test('#3243: the Composio search hint reads its host sentence in the window’s language', async () => { + const search = () => Promise.reject(new Error('Composio answered 422: the apps are wrong')) + const typed = () => { + const view = mount(AppPicker, { apps: [], onChange: () => {}, search }) + const field = all(view.node()).find(element => element.props?.className === 'bt-input' && element.props?.type === 'search') + field.props.onChange({ target: { value: 'gmail' } }) + return view + } + const hintOf = view => texts(all(view.node()).find(element => element.props?.className === 'bt-set-hint')).join('') + // The search is debounced and answers on a promise: the language stays bound until the hint is + // drawn, the way the window keeps its language while a row waits for the host. + await inLangAsync('zh', async () => { + const view = typed() + await settle(350) + assert.equal(hintOf(view), '无法搜索 Composio:Composio 返回了 422: the apps are wrong') + }) + await inLangAsync('en', async () => { + const view = typed() + await settle(350) + assert.equal(hintOf(view), 'Could not search Composio: Composio answered 422: the apps are wrong') + }) +}) diff --git a/patches/ds-bot/topics.json b/patches/ds-bot/topics.json index 1fe42273a..17b2e4bfd 100644 --- a/patches/ds-bot/topics.json +++ b/patches/ds-bot/topics.json @@ -30,6 +30,7 @@ "src/host/usage.js", "src/client/connectors.js", "test/connectors.test.js", + "test/connectors-feishu-zh.test.js", "test/work-dir.test.js", "src/client/schedules.js", "README.md",