From 35572a4c6f49235abe389ec8dc57629a7a69f1bf Mon Sep 17 00:00:00 2001 From: Day Dreamer <87640074+HugoXK@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:12:47 +0800 Subject: [PATCH] Translate the approval notes with the window's language The waiting notice and the reject note the host writes beside an approval card were English constants, so a Chinese window read a Chinese card with English system lines next to it. The host has no translator of its own: it now reads the DSH interface language the last browser reported (`flybot.uiLanguage`, the same locale the card is drawn in) and picks the Chinese pair for `zh`/`zh-*`. Every other or unknown locale, and a host no window has asked yet, keeps today's English words unchanged. The plugin API gains `uiLanguage()` in core/src/host/hooks.js, mirrored into patches/ds-bot/files; both subsystem docs record it, and one changelog fragment names the user-visible part. The notes are chosen when they are posted, so a note already in the history reads as it was written. Fixes #3124 --- .../3124-approval-note-language.fixed.md | 1 + core/src/host/hooks.js | 1 + core/types/flybot.d.ts | 2 + docs/subsystems/plugin-runtime.md | 1 + docs/subsystems/social.md | 1 + patches/ds-bot/files/src/host/hooks.js | 1 + patches/ds-bot/files/types/flybot.d.ts | 2 + plugins/social/src/hidden-remotes.js | 9 +++ plugins/social/src/social.js | 12 ++-- plugins/social/test/social.test.js | 58 +++++++++++++++++++ 10 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 changelog.d/3124-approval-note-language.fixed.md diff --git a/changelog.d/3124-approval-note-language.fixed.md b/changelog.d/3124-approval-note-language.fixed.md new file mode 100644 index 000000000..6849dd96d --- /dev/null +++ b/changelog.d/3124-approval-note-language.fixed.md @@ -0,0 +1 @@ +Notes the host writes beside an approval card now follow the window's language: a Chinese window reads 等待主人批准 and 已拒绝。 instead of the English sentences, while every other language keeps the English words ([#3124](https://github.com/ThinkFlowLab/FlyBot/issues/3124)). diff --git a/core/src/host/hooks.js b/core/src/host/hooks.js index 753ca762c..67f01b495 100644 --- a/core/src/host/hooks.js +++ b/core/src/host/hooks.js @@ -1270,6 +1270,7 @@ export function install(rt) { // True while a FlyBot window on screen reads the team (#497): a plugin that polls a remote inbox // reads it at its live cadence then, so what arrives shows in that window within seconds. watched: () => rt.watched?.() === true, + uiLanguage: () => rt.uiLanguage?.() ?? 'English', // Resolves once ds-bot's saved team is loaded, so bot.list() has every Bot. ready: () => rt.load().then(() => undefined), on: onFor(plugin), diff --git a/core/types/flybot.d.ts b/core/types/flybot.d.ts index 22ecbe28f..cb0de25cc 100644 --- a/core/types/flybot.d.ts +++ b/core/types/flybot.d.ts @@ -396,6 +396,8 @@ export interface FlyBot { ready(): Promise /** True while another dsh holds the team: no polling, no writes. */ readOnly(): boolean + /** The DSH interface language the last browser that asked for the team reported, e.g. `Chinese (简体中文)`; `English` until a window asks (#3124). */ + uiLanguage(): string /** * The Project domain host seam (#2830), for `plugins/project` only: the runtime the domain * installs its seams on (`rt.projectBoard`, `rt.projectChief`, `rt.projectTeam`, diff --git a/docs/subsystems/plugin-runtime.md b/docs/subsystems/plugin-runtime.md index 661d687fa..7bcdc2287 100644 --- a/docs/subsystems/plugin-runtime.md +++ b/docs/subsystems/plugin-runtime.md @@ -76,6 +76,7 @@ FlyBot's plugin API surface on top of the patched core: host hooks, client slots - `flybot.chatApprovals.setProvider` attaches pending Bot Social holds to a 1:1 friend's-Bot chat the same way `roomApprovals` does for groups, and to a local Bot for its own held sends (#371). The team view puts `pendingCount` on that bot; the sidebar paints the gold wait dot. `flybot.chatApprovals.changed()` tells the host the list changed (a hold arrived or was decided), so the badge refreshes at once instead of on the next unrelated revision (#226). Still not team mode. - `flybot.watched()` is true while a FlyBot window on screen reads the team (its roster poll, within the last 8 s; a hidden window does not count, #497). A plugin that polls a remote inbox reads it at its live cadence then, so what arrives reaches the open window within seconds; with no window it keeps its idle cadence. It only observes the client polls and changes nothing. +- `flybot.uiLanguage()` is the DSH interface language the last browser that asked for the team reported (`rt.uiLanguage()`: the `locale` of its `state` read, e.g. `Chinese (简体中文)`; `English` until a window asks, #3124). A plugin that writes host text into a chat — no translator of its own — picks its words by it, the same locale the window draws that plugin's cards in. ### Sidebar + friend actions diff --git a/docs/subsystems/social.md b/docs/subsystems/social.md index 77820c040..6e87a5bc2 100644 --- a/docs/subsystems/social.md +++ b/docs/subsystems/social.md @@ -159,6 +159,7 @@ Creating a group opens its Session with zero turns, and the host draws no sessio - **#139:** **Remove this Bot** asks once, inline in the friend Bot's settings (`Remove Helper (Bob) from your list? Your own Bots stay shared. Bob can share it again.` · **Remove** · **Keep**, #230, #496; never the browser `confirm()`); when the roster still lists another Bot of that friend, the question names the link that keeps the friend instead of leaving the surviving row unexplained (`Bob stays a friend: still shared through Writer.`, #1001; the names are the roster's own, so a friend with no other Bot listed keeps the sentence above), and the friend's **Auto-send** checkbox says what it covers (`Auto-send my Bots' replies to Bob` with a one-line hint, #417) and calls `decline_bot_grant { grant_id, bot_id }` (`DELETE /v1/remote-bots/{grantId}`) so the owner's Manage access drops it. `grant_not_found` is treated as already removed. An older server (404 on the tool/endpoint) falls back to the local hide. Re-joining after a decline may return `regranted: true` on the existing friendship; live access still answers `409 relationship_exists`; a spent invite is `410 invite_unavailable`. Copy stays English (“You already have Helper (Bob).”, “This invite was already used.”). Re-joining an existing friendship unhides only that invite's Bot/peer home. - **#496:** re-accepting an invite for a Bot this home already has is a result, not an error. On `409 relationship_exists` `social/join-invite` answers `{ alreadyHave: true, status: 'active', bot, botName, ownerName, restored: [{ handle, name, owner }] }`. Bot Social's 409 names no Bot, so the plugin reads the public invite info (`GET /v1/invites/{code}`, `inviteInfo` in `mcp-client.js`, sent without a token) for the invite's Bot and owner. `restored` lists only Bots that were locally hidden or declined and are listed again after the unhide. The panel shows neutral text `You already have Chief (SelfA1233).` (Bot first, owner in parentheses, #384), or `Chief (SelfA1233) is back in your list.` when something really came back; never red. Without a home (legacy) the join still throws, with the neutral `You already have this friend's Bot.`. **#1000:** that path — and a `/join_invite` that answers `regranted: true` on a relationship that already exists — also grants the joining Bot back to the inviter's Bot (`grant_bot_to_friend`, `chat.public`), because Bot Social applies neither half of an invite again on an existing relationship: the inviter's first line to the joining Bot was held as an unknown recipient until that side shared again. It is the half only the joining home can create, so it is best effort — a server without the tool or REST route leaves the accept successful and `sharedBack` absent — and the Add friend line says `Your is shared back, so they can reach you too.` — `Your Bot` when the server names none — instead of only `You already have …`. Bot Social takes the friend by bot id, never by home (`grant_bot_to_friend` sends `friend_bot_id` / `friend_owner_id`, and the REST body keeps only those two), so when the invite info names no `bot_id` the plugin resolves it from `list_friends` (`peer.bot_id`, the field `friendsOverview` already reads): first the Bot whose handle is the one the invite named, else the only active friendship of the inviter's home. A friend running two Bots under one home is not granted at all when the invite names no Bot, and `sharedBack` stays absent, so no Bot the invite did not name is given access (#1024). It names the **joining** side because both homes can run a Bot with the same name: a bare `Chief is shared back` reads as the friend's Chief being shared twice (#1026). A name the owner already gave as `Your …` is printed as it is, so a Bot named `Your Bot` keeps its one `Your` instead of reading as `Your Your Bot` (#1037). - **#140:** Auto-send defaults off. Accepting a friend request uses that relationship's peer home for Auto-send, not the first roster entry. The owner sees Approve / Reject in the chat, not “Waiting for the owner's approval.” Composer drafts are labelled You. +- A note the host writes beside a card follows the window's language (#3124): `zh`/`zh-*`, the `locale` the browser's `state` read carries (`flybot.uiLanguage()`), gets 等待主人批准 and 已拒绝。 for the two notes, the same words the card is drawn in. Every other or unknown locale, and a host no window has asked yet, keeps today's English `Waiting for the owner's approval` and `Rejected.` unchanged; the text is chosen when the note is posted and stored as it reads then. - **#136 (suffix):** Onboard retries truncate the sanitized handle body so `Name2` / `Name3` still change within the 32-character `homeHandleOf` limit. - **#666:** A friendship can be removed outside this plugin — the agent's `remove_friend` tool, or the Bot Social console — and the cached roster used to keep that Bot for up to `REMOTE_TTL_MS` (30 s). A send in that window was accepted and held, and approving it lost the line: Bot Social answered `send_as_member: no active relationship between these bots`. The send policy now asks Bot Social about the friendship itself before it asks the owner: `friendshipActive` reads `list_friends` for the home and for the sending Bot's own member identity (a per-Bot friendship, #420, is listed there), accepts only an entry whose `status` is `active` (or absent) and whose peer handle belongs to that friend's home, and caches the answer for 2 s so a burst of lines costs one call per friend, not one per line. No answer at all (an older server, a link that is down) keeps the roster's verdict: the check catches a removal, it does not invent one. When the friendship is gone the send is denied with the usual *is not a Bot a friend shared with you* reason, above the hold and Auto-send branches, and `forgetFriendHome` drops that friend from the cached roster and republishes, so the list and the picker stop offering a Bot that can no longer be reached. Room lines (`via: room` / `room-share`) skip the check. The other half is the cache: a `relationship.changed` event in either direction now invalidates the roster (`fetchedAt = 0`) **and** every cached friendship answer (`forgetFriendStatus`), so a send in the same millisecond is judged on a fresh answer rather than the two-second one — the earlier version only dropped the roster, and a send 500 ms after the event still read "still friends". Two more holes close with it (#666 review): an answer without a `friends` array is not evidence of a removal (it keeps the roster's verdict, or one server that changed shape would unfriend everyone), and releasing a held card re-asks `list_friends` with `{ fresh: true }` — bypassing the two-second answer at the moment the owner approves — so a card held before the removal fails with the *is not a Bot a friend shared with you* reason instead of being handed to a server that refuses it with `no active relationship`. The probe also carries its own `FRIEND_CALL_MS = 1.5 s` deadline through `callTool(name, args, { timeoutMs })`, because it runs on the send path and must not add the client's 30 s deadline to every line when Bot Social is down. Tests: `plugins/social/test/social.test.js` (`#666`, including the +0 ms and +500 ms cases). diff --git a/patches/ds-bot/files/src/host/hooks.js b/patches/ds-bot/files/src/host/hooks.js index 753ca762c..67f01b495 100644 --- a/patches/ds-bot/files/src/host/hooks.js +++ b/patches/ds-bot/files/src/host/hooks.js @@ -1270,6 +1270,7 @@ export function install(rt) { // True while a FlyBot window on screen reads the team (#497): a plugin that polls a remote inbox // reads it at its live cadence then, so what arrives shows in that window within seconds. watched: () => rt.watched?.() === true, + uiLanguage: () => rt.uiLanguage?.() ?? 'English', // Resolves once ds-bot's saved team is loaded, so bot.list() has every Bot. ready: () => rt.load().then(() => undefined), on: onFor(plugin), diff --git a/patches/ds-bot/files/types/flybot.d.ts b/patches/ds-bot/files/types/flybot.d.ts index 22ecbe28f..cb0de25cc 100644 --- a/patches/ds-bot/files/types/flybot.d.ts +++ b/patches/ds-bot/files/types/flybot.d.ts @@ -396,6 +396,8 @@ export interface FlyBot { ready(): Promise /** True while another dsh holds the team: no polling, no writes. */ readOnly(): boolean + /** The DSH interface language the last browser that asked for the team reported, e.g. `Chinese (简体中文)`; `English` until a window asks (#3124). */ + uiLanguage(): string /** * The Project domain host seam (#2830), for `plugins/project` only: the runtime the domain * installs its seams on (`rt.projectBoard`, `rt.projectChief`, `rt.projectTeam`, diff --git a/plugins/social/src/hidden-remotes.js b/plugins/social/src/hidden-remotes.js index d542bb481..6c2cadb88 100644 --- a/plugins/social/src/hidden-remotes.js +++ b/plugins/social/src/hidden-remotes.js @@ -125,6 +125,15 @@ export const WAITING_OWNER = 'Waiting for approval' export const WAITING_OTHERS = "Waiting for the owner's approval" export const REJECT_NOTE = 'Rejected.' +// #3124: the two notes the host writes beside an approval card follow the window's language, the +// same one the card itself is drawn in. The card is translated in the browser; the host has no +// translator, so it picks the words by the interface language the last window reported +// (`flybot.uiLanguage`, a language name such as `Chinese (简体中文)`) and the Chinese pair lives +// here, beside its English one. An unknown language keeps English, the host's own fallback. +const chineseUi = (language) => /^(zh|chinese)/i.test(String(language ?? '')) +export const waitingNote = (language) => (chineseUi(language) ? '等待主人批准' : WAITING_OTHERS) +export const rejectNote = (language) => (chineseUi(language) ? '已拒绝。' : REJECT_NOTE) + export function chatApprovalTitle(canDecide) { return canDecide ? WAITING_OWNER : WAITING_OTHERS } diff --git a/plugins/social/src/social.js b/plugins/social/src/social.js index f4a65ee61..468540bfc 100644 --- a/plugins/social/src/social.js +++ b/plugins/social/src/social.js @@ -72,8 +72,8 @@ import { isHomeLevelHandle, isHiddenRemote, revealHiddenIfPresent, - WAITING_OTHERS, - REJECT_NOTE, + waitingNote, + rejectNote, } from './hidden-remotes.js' export const NS = 'social' @@ -3515,6 +3515,10 @@ export function createSocial(service, config = {}, { client: given, api: givenAp } return pick(openable) } + // #3124: the notes written beside an approval card follow the window's language, the same one + // the card is drawn in. The host reads it from the interface language the last browser reported; + // a host without that seam keeps the English notes. + const noteLanguage = () => flybot.uiLanguage?.() async function postChatNote(item, text, { chats: toChats = true } = {}) { for (const room of roomsForApproval(item)) { try { flybot.rooms.postNotice?.(room.id, text) } catch (error) { warn('approval notice not posted', error) } @@ -3551,7 +3555,7 @@ export function createSocial(service, config = {}, { client: given, api: givenAp // The owner of a held room line sees its Approve card, never "waiting for the owner" (#179). if (item.kind === 'face_room_message') { settings.approvalNotices[item.id] = { at: now(), kind: 'waiting' }; changed = true; continue } // Owner 1:1 chats use the Approve / Reject dock. Do not post a waiting bubble there (#140). - await postChatNote(item, WAITING_OTHERS, { chats: false }) + await postChatNote(item, waitingNote(noteLanguage()), { chats: false }) settings.approvalNotices[item.id] = { at: now(), kind: 'waiting' } changed = true } @@ -3561,7 +3565,7 @@ export function createSocial(service, config = {}, { client: given, api: givenAp const item = pendingCache.items.find(entry => entry.id === approvalId) // A rejected room line already reads "Not sent" where it would have stood (#456): no second note. if (!item || item.kind === 'face_room_message') return - await postChatNote(item, REJECT_NOTE) + await postChatNote(item, rejectNote(noteLanguage())) settings.approvalNotices ??= {} settings.approvalNotices[approvalId] = { at: now(), kind: 'rejected' } saveSettings() diff --git a/plugins/social/test/social.test.js b/plugins/social/test/social.test.js index 8e0db2ca8..74f2e4932 100644 --- a/plugins/social/test/social.test.js +++ b/plugins/social/test/social.test.js @@ -1724,6 +1724,64 @@ test('#278: "Waiting for the owner\'s approval" is posted into the rooms a hold assert.deepEqual(posted.map(([room]) => room), ['group-1']) }) +// #3124: the two notes the host writes beside an approval card, through the real host, with the +// window's language set the way the browser sets it (the `locale` of its state read; no call means +// no window has asked yet). The hold carries a finding so it stays pending, and the fake server +// keeps it until the reject call, so one run captures the waiting note and the reject note. +async function approvalNotesWithWindow(t, locale) { + const { ctx, call, stop } = await team() + t.after(stop) + if (locale !== undefined) await call('state', { locale }) + const server = holdingServer({ reasons: ['dlp.commitment'] }) + const posted = [] + const scope = ctx.flybot.scope + ctx.flybot.scope = (name) => { + const scoped = scope(name) + scoped.rooms = { + ...scoped.rooms, + list: () => [{ id: 'group-1', origin: 'group', participants: [{ handle: '@coder.bob.home', remote: true }] }], + ofFace: () => undefined, + postNotice: (roomId, text) => posted.push([roomId, text]), + } + return scoped + } + const notes = [] + const orig = ctx.flybot.remote.chats.deliver + ctx.flybot.remote.chats.deliver = async (msg) => { notes.push(msg); return orig?.(msg) } + const social = createSocial(ctx.flybot, { autoAccept: true, inboxPollMs: 0 }, { client: createMcpClient({ server: 'https://s', token: 'owner-token', fetch: server.fetch }), home: { id: 'h1', handle: '@bob.home' } }) + t.after(() => social.dispose()) + await grantTeam(ctx.flybot) + await social.registerAll() + assert.equal((await ctx.flybot.bot.send({ from: 'a', to: '@coder.bob.home', text: 'a Bot line' })).action, 'allow') + await call('flybot/social/status', {}) + const approvalId = server.queue[0]?.approval_id + assert.ok(approvalId, 'the fake server kept the hold') + await call('flybot/social/decide-approval', { approvalId, decision: 'reject' }) + return { posted, notes } +} + +test('#3124: a Chinese window gets both notes in the language its card is drawn in', async (t) => { + const { posted, notes } = await approvalNotesWithWindow(t, 'zh-CN') + assert.deepEqual(posted, [['group-1', '等待主人批准'], ['group-1', '已拒绝。']], `the room notes follow the window, saw ${JSON.stringify(posted)}`) + assert.equal(posted.some(([, text]) => text === WAITING_OTHERS || text === REJECT_NOTE), false, 'no English note is posted in a Chinese window') + assert.ok(notes.some(n => n.text === '已拒绝。'), `the reject note follows the window, saw ${JSON.stringify(notes)}`) + assert.equal(notes.some(n => n.text === REJECT_NOTE), false, 'the English reject note is not posted in a Chinese window') +}) + +test('#3124: an English window keeps both notes exactly as they read today', async (t) => { + const { posted, notes } = await approvalNotesWithWindow(t, 'en-US') + assert.deepEqual(posted, [['group-1', WAITING_OTHERS], ['group-1', REJECT_NOTE]], `saw ${JSON.stringify(posted)}`) + assert.ok(notes.some(n => n.text === REJECT_NOTE), `saw ${JSON.stringify(notes)}`) +}) + +test('#3124: with no window, or a language the host does not translate, the notes stay English', async (t) => { + for (const locale of [undefined, 'fr-FR']) { + const { posted, notes } = await approvalNotesWithWindow(t, locale) + assert.deepEqual(posted, [['group-1', WAITING_OTHERS], ['group-1', REJECT_NOTE]], `${locale ?? 'no window'}: saw ${JSON.stringify(posted)}`) + assert.ok(notes.some(n => n.text === REJECT_NOTE), `${locale ?? 'no window'}: saw ${JSON.stringify(notes)}`) + } +}) + const heldOutbound = { approval_id: 'apr-hold-1', kind: 'outbound_message',