Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3133-face-notices-language.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The lines the host posts into a chat or room follow the window's language as well: a Chinese window reads 已加入、已离开房间、总负责人:…、房间现已开放,号码不再有效。 for join/leave/lead/started notices, 未发送:… for a line that was not delivered, and 没有为 … 发起调用:… for a typed @ that could not call a friend's Bot, instead of the English sentences; every other language keeps the English words ([#3133](https://github.com/ThinkFlowLab/FlyBot/issues/3133)).
1 change: 1 addition & 0 deletions docs/subsystems/social.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Creating a group opens its Session with zero turns, and the host draws no sessio
- **#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 <Bot> 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.
- The lines the host posts into a room or a chat follow the window's language the same way (#3133): the face-room join/leave/lead/started notices (已加入 · 已离开房间 · 总负责人:… · 房间现已开放,号码不再有效。), the Not-sent line in the owner's chat (未发送:…), and the no-call line for a typed @ that could not ride the legacy envelope (没有为 … 发起调用:…) are Chinese in a `zh` window and English in every other or unknown one. `leaveNoticeCoveredByClose` hides the short leave behind the closed banner in either language, so the close line is never doubled (#1103).
- **#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).

Expand Down
56 changes: 33 additions & 23 deletions plugins/social/src/face-rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import { socialFetch } from './mcp-client.js'
import { lookFromServer } from './look.js'
import { formatFaceRoomTitle, faceRoomCreatedAt } from './face-title.js'
import { chineseUi } from './hidden-remotes.js'

export const FACE_JOIN_CODE = /^\d{6}$/
export const FACE_MAX_MEMBERS = 8
Expand Down Expand Up @@ -84,7 +85,7 @@
// system copy that embeds those names.
export function cleanFaceName(value, fallback = 'a remote Bot') {
const text = cutCodePoints(stripFaceMarkers(String(value ?? ''))
.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, ' ')

Check warning on line 88 in plugins/social/src/face-rooms.js

View workflow job for this annotation

GitHub Actions / plugins (social)

eslint(no-control-regex)

Unexpected control characters
.replace(/[[\]"<>`@]/g, '')
.replace(/\s+/g, ' ')
.trim(), NAME_MAX)
Expand Down Expand Up @@ -428,25 +429,31 @@
return undefined
}

export function platformJoinText(member) {
// #3133: the notices the host posts for a room event follow the window's language, the seam #3124
// gave the approval notes; English is the fallback.
export function platformJoinText(member, language) {
const who = faceMemberLabel(member)
// Server copy; we rebuild from sanitized fields so a poisoned payload cannot instruct.
if (member?.roomOnly === true || member?.published !== true) return `${who} joined; available to this room only`
return `${who} joined`
if (member?.roomOnly === true || member?.published !== true) {
return chineseUi(language) ? `${who} 已加入;仅在此房间可用` : `${who} joined; available to this room only`
}
return chineseUi(language) ? `${who} 已加入` : `${who} joined`
}

// A leave names the person, not their Bot (#191): "Bob left the room".
export function platformLeaveText(member) {
export function platformLeaveText(member, language) {
const owner = faceOwnerName(member)
return owner ? `${owner} left the room` : `${faceMemberLabel(member)} left`
if (owner) return chineseUi(language) ? `${owner} 已离开房间` : `${owner} left the room`
return chineseUi(language) ? `${faceMemberLabel(member)} 已离开` : `${faceMemberLabel(member)} left`
}

// The closed status line already says who left and that the room closed (#1103):
// "Bob left the room. Room closed." The short platform leave is the same fact.
// "Bob left the room. Room closed." The short platform leave is the same fact, in either language
// (#3133), so the pattern reads both the English and the Chinese leave.
// Same rule as core `leaveNoticeCoveredByClose` (`cells.js`), which hides a line already drawn.
export function leaveNoticeCoveredByClose(room, text) {
if (room?.origin !== 'face-to-face' || room.face?.status !== 'closed') return false
const match = String(text ?? '').trim().match(/^(.+) left(?: the room)?$/)
const match = String(text ?? '').trim().match(/^(.+) (?:left(?: the room)?|已离开(?:房间)?)$/)
if (!match) return false
const who = match[1]
for (const participant of room.participants ?? []) {
Expand All @@ -457,14 +464,17 @@
return false
}

export function platformLeadText(member, reason) {
if (member) return `Room lead: ${faceMemberLabel(member)}`
return reason === 'lead_left' ? 'The room lead left. The default lead takes over.' : 'The room lead is back to the default.'
export function platformLeadText(member, reason, language) {
if (member) return chineseUi(language) ? `总负责人:${faceMemberLabel(member)}` : `Room lead: ${faceMemberLabel(member)}`
if (reason === 'lead_left') return chineseUi(language) ? '总负责人已离开,由默认总负责人接手。' : 'The room lead left. The default lead takes over.'
return chineseUi(language) ? '总负责人恢复为默认。' : 'The room lead is back to the default.'
}

export function platformStartedText(reason) {
if (reason === 'expired') return 'Joining has ended. The room is now open. The number is no longer valid.'
return 'The room is now open. The number is no longer valid.'
export function platformStartedText(reason, language) {
if (reason === 'expired') {
return chineseUi(language) ? '加入期已结束。房间现已开放,号码不再有效。' : 'Joining has ended. The room is now open. The number is no longer valid.'
}
return chineseUi(language) ? '房间现已开放,号码不再有效。' : 'The room is now open. The number is no longer valid.'
}

// Peer look is optional: only pass through a stored color / avatar when the payload
Expand All @@ -479,7 +489,7 @@
|| (typeof member.color === 'string' && !HEX_ONLY.test(member.color) ? member.color.trim().slice(0, 32) : '')
if (color && !/[\n<>]/.test(color)) out.color = color
const src = member.avatar && typeof member.avatar === 'object' ? member.avatar : {}
const avatar = { ...(fromServer.avatar ?? {}) }

Check warning on line 492 in plugins/social/src/face-rooms.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-useless-fallback-in-spread)

Empty fallbacks in spreads are unnecessary
if (typeof src.shape === 'string' && /^[a-z][\w-]{0,31}$/.test(src.shape)) avatar.shape = src.shape
const image = typeof src.image === 'string' ? src.image.trim() : (typeof member.image === 'string' ? member.image.trim() : '')
if (image && image.length <= 65536 && /^(https?:\/\/|data:image\/)/i.test(image) && !/[\s<>]/.test(image)) avatar.image = image
Expand Down Expand Up @@ -509,7 +519,7 @@
export function cleanFaceRole(value) {
if (typeof value !== 'string') return ''
return cutCodePoints(stripFaceMarkers(value)
.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, ' ')

Check warning on line 522 in plugins/social/src/face-rooms.js

View workflow job for this annotation

GitHub Actions / plugins (social)

eslint(no-control-regex)

Unexpected control characters
.replace(/[[\]"<>`@]/g, '')
.replace(/\s+/g, ' ')
.trim(), FACE_ROLE_MAX)
Expand Down Expand Up @@ -542,7 +552,7 @@
eventCursor: Number(body.event_cursor ?? body.eventCursor ?? 0) || 0,
members,
...(lead ? { lead } : {}),
events: (body.events ?? []).map(viewFaceEvent).filter(Boolean),
events: (body.events ?? []).map(event => viewFaceEvent(event)).filter(Boolean),
memberCount: Number(body.member_count ?? body.members?.length ?? 0) || 0,
myBots: (body.my_bots ?? body.myBots ?? []).map(viewFaceMember).filter(Boolean),
}
Expand Down Expand Up @@ -580,7 +590,7 @@
return faceUntrustedText(raw ?? event.untrustedText)
}

export function viewFaceEvent(event) {
export function viewFaceEvent(event, language) {
if (!event || typeof event !== 'object') return undefined
const raw = String(event.type || event.event_type || '')
const mapped = INBOX_TYPES[raw] || raw
Expand All @@ -598,7 +608,7 @@
trust: event.trust,
member,
from,
text: mapped === 'room.message' ? undefined : sanitizePlatformText(event.text, mapped, member, event.reason),
text: mapped === 'room.message' ? undefined : sanitizePlatformText(event.text, mapped, member, event.reason, language),
// A viewed event (renderFaceEvent views again) already holds the plain text: keep it as is (#302).
untrustedText: mapped === 'room.message' ? stripFaceMarkers(viewedFaceText(event)) : undefined,
// Stamped by Bot Social (never read from the text): the owner typed this line themselves. A viewed
Expand All @@ -610,15 +620,15 @@
}
}

function sanitizePlatformText(text, type, member, reason) {
function sanitizePlatformText(text, type, member, reason, language) {
// Rebuild join/leave/start from sanitized fields so a 60-char name cap cannot
// truncate the sentence, and a poisoned `text` cannot instruct.
if (type === 'member.joined' && member) return platformJoinText(member)
if (type === 'member.left' && member) return platformLeaveText(member)
if (type === 'room.started') return platformStartedText(reason)
if (type === 'room.lead_changed') return platformLeadText(member, reason)
if (type === 'member.joined' && member) return platformJoinText(member, language)
if (type === 'member.left' && member) return platformLeaveText(member, language)
if (type === 'room.started') return platformStartedText(reason, language)
if (type === 'room.lead_changed') return platformLeadText(member, reason, language)
const cleaned = cutCodePoints(String(text ?? '')
.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, ' ')

Check warning on line 631 in plugins/social/src/face-rooms.js

View workflow job for this annotation

GitHub Actions / plugins (social)

eslint(no-control-regex)

Unexpected control characters
.replace(/[[\]"<>`@]/g, '')
.replace(/\s+/g, ' ')
.trim(), 200)
Expand All @@ -629,8 +639,8 @@
// it carries that stamp; the FLYBOT-FACE-HUMAN text is then never an attribution (any Bot can write
// it), though its inner text is still unwrapped for display. Without it (an older server) the envelope
// keeps its legacy meaning (#180).
export function renderFaceEvent(event, { attested = false } = {}) {
const viewed = viewFaceEvent(event)
export function renderFaceEvent(event, { attested = false, language } = {}) {
const viewed = viewFaceEvent(event, language)
if (!viewed) return undefined
if (viewed.type === 'room.message') {
const from = viewed.from || {}
Expand Down
3 changes: 2 additions & 1 deletion plugins/social/src/hidden-remotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ export const REJECT_NOTE = 'Rejected.'
// 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 ?? ''))
// #3133: the face-room notices and the social room lines pick their words through the same test.
export 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)

Expand Down
18 changes: 14 additions & 4 deletions plugins/social/src/social.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {
revealHiddenIfPresent,
waitingNote,
rejectNote,
chineseUi,
} from './hidden-remotes.js'

export const NS = 'social'
Expand Down Expand Up @@ -2494,7 +2495,10 @@ export function createSocial(service, config = {}, { client: given, api: givenAp
handle,
home: event.to?.home_handle ? norm(event.to.home_handle) : undefined,
name: cleanText(event.to?.display_name, handle),
text: `Not sent: ${friendBotTitle(handle)} was not ready to talk with you yet, so it did not get your message. Send it again.`,
// #3133: the note follows the window's language (#3124's seam); English is the fallback.
text: chineseUi(flybot.uiLanguage?.())
? `未发送:${friendBotTitle(handle)} 还没有准备好与你对话,因此没有收到你的消息。请重新发送。`
: `Not sent: ${friendBotTitle(handle)} was not ready to talk with you yet, so it did not get your message. Send it again.`,
})
}
// Tells the sender (through Bot Social) that this home could not hand their message to its Bot. A server
Expand Down Expand Up @@ -4221,7 +4225,7 @@ export function createSocial(service, config = {}, { client: given, api: givenAp
// is the last resort for a server that stamps neither an id nor a cursor (#1063).
const eventKey = faceEventKey(event, position)
if (eventKey && seen.includes(eventKey)) continue
const line = renderFaceEvent(event, { attested })
const line = renderFaceEvent(event, { attested, language: flybot.uiLanguage?.() })
if (!line) continue
seen = rememberEvent(seen, eventKey)
if (line.system) {
Expand Down Expand Up @@ -4263,7 +4267,7 @@ export function createSocial(service, config = {}, { client: given, api: givenAp
if (handle && !localHandles.has(handle)) markRoomRemote(handle, snapshot.roomId)
const key = `join:${handle}`
if (!handle || previousLive.has(handle) || joinedFromEvents.has(handle) || seen.includes(key)) continue
const text = platformJoinText(member)
const text = platformJoinText(member, flybot.uiLanguage?.())
if (alreadyJoined(text)) {
seen = rememberEvent(seen, key)
continue
Expand Down Expand Up @@ -4608,7 +4612,13 @@ export function createSocial(service, config = {}, { client: given, api: givenAp
// itself (core `openingSpeakers`), attested or as the envelope, so its call is not lost.
const seats = new Set((room.participants ?? []).filter(item => item.remote === true).map(item => norm(item.handle)))
const lost = [...new Set(mentions.map(handle => (typeof handle === 'string' ? norm(handle) : '')).filter(handle => handle && seats.has(handle)))]
if (lost.length > 0) flybot.rooms.postNotice?.(room.id, `No call went out for ${lost.join(', ')}: this connector token may not attest typed lines, so the other home reads this line as a Bot's.`)
if (lost.length > 0) {
// #3133: the room line follows the window's language (#3124's seam); English is the fallback.
const lostLine = chineseUi(flybot.uiLanguage?.())
? `没有为 ${lost.join(', ')} 发起调用:此连接器令牌无法证明输入行,对方主机会把这一行当作 Bot 的行。`
: `No call went out for ${lost.join(', ')}: this connector token may not attest typed lines, so the other home reads this line as a Bot's.`
flybot.rooms.postNotice?.(room.id, lostLine)
}
}
if (sent?.status === 'pending_approval') {
rememberHoldRoom(sent.approvalId, serverId)
Expand Down
Loading
Loading