The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): localize the Bot Mode row context menu and attention hints
teknium171c5a0bd0a62
diff --git a/apps/desktop/e2e/bot-mode-roster-localized.spec.ts b/apps/desktop/e2e/bot-mode-roster-localized.spec.tsnew file mode 100644index 00000000000..1ded251058c--- /dev/null+++ b/apps/desktop/e2e/bot-mode-roster-localized.spec.ts@@ -0,0 +1,141 @@+import fs from 'node:fs'+import path from 'node:path'++import {+ buildAppEnv,+ createSandbox,+ launchDesktop,+ type MockBackendFixture,+ waitForAppReady,+ writeEnvFile,+ writeMockProviderConfig+} from './fixtures'+import { startMockServer } from '../../../tests-js/scripts/mock-server'+import { RealSessionBuilder } from './real-session-builder'+import { expect, test } from './test'++// The Bot Mode roster ships locale bundles (en/ja/zh/zh-hant), but a handful of+// row strings stayed English literals after the bundle landed: the bot row's+// right-click Pin/Hide/Groups entries and the group row's "N bots" / "N of M+// available" preview and accessible name. Under display.language=zh a Chinese+// reader saw an English menu inside an otherwise translated pane.++type Page = MockBackendFixture['page']++let fixture: MockBackendFixture | null = null++const SHOTS = process.env.BOTS_I18N_SHOTS || ''++async function shot(page: Page, name: string): Promise<void> {+ if (!SHOTS) {+ return+ }++ fs.mkdirSync(SHOTS, { recursive: true })+ await page.screenshot({ path: path.join(SHOTS, `${name}.png`) })+}++async function openBots(page: Page): Promise<void> {+ const tab = page+ .getByRole('button', { name: 'Bots', exact: true })+ .or(page.getByRole('tab', { name: 'Bots', exact: true }))+ .first()++ await tab.click()+ // The `+` button's accessible name comes from the zh bundle.+ await expect(page.getByRole('button', { name: '新建机器人或群聊' })).toBeVisible()+}++async function seedBot(hermesHome: string, mockUrl: string, name: string): Promise<void> {+ const dir = path.join(hermesHome, 'profiles', name)+ fs.mkdirSync(dir, { recursive: true })+ writeMockProviderConfig(dir, mockUrl, ' language: zh')+ writeEnvFile(dir)++ const builder = await RealSessionBuilder.start(dir)++ try {+ await builder.createSession({ title: 'Bot Chat', turns: [`Hello ${name}`] })+ } finally {+ await builder.close()+ }+}++test.beforeAll(async () => {+ const mock = await startMockServer()+ const sandbox = createSandbox('bots-i18n')+ writeMockProviderConfig(sandbox.hermesHome, mock.url, ' language: zh')+ writeEnvFile(sandbox.hermesHome)+ await seedBot(sandbox.hermesHome, mock.url, 'alpha')+ await seedBot(sandbox.hermesHome, mock.url, 'beta')++ const { app, page } = await launchDesktop(buildAppEnv(sandbox))++ fixture = {+ app,+ page,+ mock,+ mockUrl: mock.url,+ sandbox,+ cleanup: async () => {+ await app.close().catch(() => undefined)+ await mock.close()+ sandbox.cleanup()+ }+ }+ await waitForAppReady(fixture, 120_000)+})++test.afterAll(async () => {+ await fixture?.cleanup()+ fixture = null+})++test('the bot row context menu is in the active language (zh)', async () => {+ test.setTimeout(300_000)+ const page = fixture!.page++ await openBots(page)++ const alphaRow = page.getByRole('button', { name: /^alpha\b/i }).filter({ visible: true }).first()+ await expect(alphaRow).toBeVisible({ timeout: 30_000 })+ await alphaRow.click({ button: 'right' })++ const menu = page.getByRole('menu').filter({ visible: true }).first()+ await expect(menu).toBeVisible({ timeout: 10_000 })+ await expect(menu.getByRole('menuitem', { name: '置顶' })).toBeVisible()+ await expect(menu.getByRole('menuitem', { name: '隐藏' })).toBeVisible()+ await expect(menu.getByRole('menuitem', { name: '管理群聊…' })).toBeVisible()+ await expect(menu.getByRole('menuitem', { name: 'Pin to top' })).toHaveCount(0)+ await expect(menu.getByRole('menuitem', { name: 'Hide' })).toHaveCount(0)+ await shot(page, 'bot-row-context-menu-zh')+ await page.keyboard.press('Escape')+ await expect(menu).toBeHidden()+})++test('a fresh group row previews its member count and availability in zh', async () => {+ test.setTimeout(300_000)+ const page = fixture!.page++ await openBots(page)+ await page.getByRole('button', { name: '新建机器人或群聊' }).click()+ await page.getByRole('menuitem', { name: '新建群聊' }).click()++ const dialog = page.getByRole('dialog', { name: '新建群聊' })+ await expect(dialog).toBeVisible({ timeout: 15_000 })++ for (const name of ['Alpha @alpha', 'Beta @beta']) {+ await dialog.getByRole('checkbox', { name }).click()+ }++ await dialog.getByRole('textbox', { name: '群组名称' }).fill('crew')+ await dialog.getByRole('button', { name: /Create Group|创建群聊/ }).click()+ await expect(dialog).toBeHidden({ timeout: 30_000 })++ const groupRow = page.getByRole('button', { name: /^crew, / }).filter({ visible: true }).first()+ await expect(groupRow).toBeVisible({ timeout: 30_000 })+ await expect(groupRow).toHaveAccessibleName('crew, 2 个机器人, 2 个中 2 个可用')+ await expect(groupRow.getByText('2 个机器人', { exact: true })).toBeVisible()+ await expect(page.getByText('2 bots', { exact: true })).toHaveCount(0)+ await shot(page, 'group-row-zh')+})diff --git a/apps/desktop/src/plugins/hermes-bots/bot-row.test.tsx b/apps/desktop/src/plugins/hermes-bots/bot-row.test.tsxindex 6a65729764c..4cb5a1c69fa 100644--- a/apps/desktop/src/plugins/hermes-bots/bot-row.test.tsx+++ b/apps/desktop/src/plugins/hermes-bots/bot-row.test.tsx@@ -16,8 +16,8 @@*/import type * as HermesSdk from '@hermes/plugin-sdk'-import { act, fireEvent, render, screen } from '@testing-library/react'-import { beforeEach, describe, expect, it, vi } from 'vitest'+import { act, fireEvent, render, screen, within } from '@testing-library/react'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { BotRow, GroupRow } from './bot-row'import { $groupChats } from './group-chat'@@ -27,7 +27,7 @@ import type { GroupMember, RosterRow } from './types'// Which shipped bundle the rendered rows resolve their strings against. `en`// matches the literals this file once carried, so a case that has to prove a// string comes from the catalog reads the same row under `ja`.-const locale = vi.hoisted(() => ({ current: 'en' as 'en' | 'ja' }))+const locale = vi.hoisted(() => ({ current: 'en' as 'en' | 'ja' | 'zh' }))const { ensureAgent, ensureBotMetadata, notifyError, openRosterBot, requestProfile, warmAgent, warmProfile } =vi.hoisted(() => ({@@ -205,6 +205,28 @@ describe('context-menu mutations hydrate the alias first', () => {})})+describe('the bot row context menu speaks the active language', () => {+ afterEach(() => {+ locale.current = 'en'+ })++ it('renders the pin/hide toggles and the groups entry from the catalog, not English literals', async () => {+ // Regression guard for the roster menu items that stayed hardcoded after+ // the bundle landed: under `zh` no English label may survive.+ locale.current = 'zh'+ fireEvent.contextMenu(renderRow({ name: 'worker', connectionId: 'local' }))++ const menu = await screen.findByRole('menu')++ expect(within(menu).getByText('置顶')).toBeTruthy()+ expect(within(menu).getByText('隐藏')).toBeTruthy()+ expect(within(menu).getByText('管理群聊…')).toBeTruthy()+ expect(within(menu).queryByText('Pin to top')).toBeNull()+ expect(within(menu).queryByText('Hide')).toBeNull()+ expect(within(menu).queryByText('Manage groups…')).toBeNull()+ })+})+describe('a group row', () => {const members = [{ name: 'alpha' }, { name: 'beta' }, { name: 'gamma' }] as GroupMember[]const row = <GroupRow active={false} group="crew" members={members} needsYou={false} onDisband={noop} onOpen={noop} />diff --git a/apps/desktop/src/plugins/hermes-bots/bot-row.tsx b/apps/desktop/src/plugins/hermes-bots/bot-row.tsxindex 24db705077f..8ca682e7d8d 100644--- a/apps/desktop/src/plugins/hermes-bots/bot-row.tsx+++ b/apps/desktop/src/plugins/hermes-bots/bot-row.tsx@@ -43,8 +43,8 @@ import {$botAttention,$botMeta,$lastRoster,- BOT_ATTENTION_HINTS,botActivitySession,+ botAttentionHint,botHandle,botRosterKey,botSelectionKey,@@ -189,7 +189,7 @@ export function BotRow({ bot, onDelete, onEdit, onGroup, onNewSection, showHandl)const handle = botHandle(bot.name, bot)- const gatewayLabel = bot.connectionLabel || (bot.connectionId === 'local' ? 'This device' : '')+ const gatewayLabel = bot.connectionLabel || (bot.connectionId === 'local' ? b.bot.thisDevice : '')const showDetailsRow = Boolean(showHandle || displayPreview || fromBot)const rowTooltip = [displayName(bot, meta), `@${handle}`, gatewayLabel, sourceStatus.label]@@ -287,7 +287,7 @@ export function BotRow({ bot, onDelete, onEdit, onGroup, onNewSection, showHandl</Tip></div>{attention ? (- <Tip label={BOT_ATTENTION_HINTS[attention.reason] || 'Needs attention'}>+ <Tip label={botAttentionHint(attention.reason)}><Codiconaria-label={b.roster.needsAttention}className="shrink-0 text-[0.6875rem] text-amber-600 dark:text-amber-300"@@ -332,13 +332,13 @@ export function BotRow({ bot, onDelete, onEdit, onGroup, onNewSection, showHandl})host.notify({kind: 'info',- message: `${displayName(bot, current)} ${pinned ? 'unpinned' : 'pinned to top'}`+ message: pinned ? b.bot.unpinnedToast(displayName(bot, current)) : b.bot.pinnedToast(displayName(bot, current))})})- .catch(error => host.notifyError?.(error, 'Could not load bot metadata'))+ .catch(error => host.notifyError?.(error, b.bot.metadataLoadFailed))}}>- {pinned ? 'Unpin' : 'Pin to top'}+ {pinned ? b.bot.unpin : b.bot.pinToTop}</ContextMenuItem><ContextMenuItemonSelect={() => {@@ -356,21 +356,21 @@ export function BotRow({ bot, onDelete, onEdit, onGroup, onNewSection, showHandlhost.notify({kind: 'info',message: hidden- ? `${displayName(bot, current)} is back in the roster`- : `${displayName(bot, current)} hidden — use the eye button in the Bots header to see hidden bots`+ ? b.bot.unhiddenToast(displayName(bot, current))+ : b.bot.hiddenToast(displayName(bot, current))})})- .catch(error => host.notifyError?.(error, 'Could not load bot metadata'))+ .catch(error => host.notifyError?.(error, b.bot.metadataLoadFailed))}}>- {hidden ? 'Unhide' : 'Hide'}+ {hidden ? b.bot.unhide : b.bot.hide}</ContextMenuItem><ContextMenuSeparator /><ContextMenuItemonSelect={() =>void ensureBotMetadata(bot).then(() => onEdit(bot))- .catch(error => host.notifyError?.(error, 'Could not load bot'))+ .catch(error => host.notifyError?.(error, b.bot.loadFailed))}>{b.bot.editMenu}@@ -379,10 +379,10 @@ export function BotRow({ bot, onDelete, onEdit, onGroup, onNewSection, showHandlonSelect={() =>void ensureBotMetadata(bot).then(() => onGroup(bot))- .catch(error => host.notifyError?.(error, 'Could not load bot groups'))+ .catch(error => host.notifyError?.(error, b.bot.groupsLoadFailed))}>- {groups.length ? `Groups: ${groups.join(', ')}…` : 'Manage groups…'}+ {groups.length ? b.bot.groupsMenu(groups.join(', ')) : b.bot.manageGroups}</ContextMenuItem><ContextMenuItemonSelect={() => {diff --git a/apps/desktop/src/plugins/hermes-bots/data.ts b/apps/desktop/src/plugins/hermes-bots/data.tsindex 60ee12472ec..d5fcd31711c 100644--- a/apps/desktop/src/plugins/hermes-bots/data.ts+++ b/apps/desktop/src/plugins/hermes-bots/data.ts@@ -8,6 +8,7 @@import { atom, host, queryClient, useQuery, useValue } from '@hermes/plugin-sdk'+import { botsText } from './i18n'import { displayName } from './labels'import {aliasIdentityFor,@@ -62,12 +63,18 @@ const BOT_ATTENTION_CLASSES: ReadonlySet<string> = new Set<AttentionClass>(['missing_config'])-/** One-line user hint per attention class (roster badge tooltip). */-export const BOT_ATTENTION_HINTS: Record<string, string> = {- provider_auth_or_access: 'Sign in again for this profile',- provider_quota_limit: 'Quota or balance exhausted',- missing_config: 'Provider not configured — run hermes model',- agent_blocked: 'Bot is blocked — see its last message'+/** One-line user hint per attention class (roster badge tooltip), in the+ * active locale; unknown classes fall back to the generic hint. */+export function botAttentionHint(reason: string): string {+ const text = botsText().bot+ const hints: Record<string, string> = {+ provider_auth_or_access: text.attentionProviderAuth,+ provider_quota_limit: text.attentionQuota,+ missing_config: text.attentionMissingConfig,+ agent_blocked: text.attentionBlocked+ }++ return hints[reason] || text.attentionFallback}/** Map an error (a #93091 reason code or raw error text) to an attentiondiff --git a/apps/desktop/src/plugins/hermes-bots/i18n.ts b/apps/desktop/src/plugins/hermes-bots/i18n.tsindex 4a85d35c7df..34ecaaf19cb 100644--- a/apps/desktop/src/plugins/hermes-bots/i18n.ts+++ b/apps/desktop/src/plugins/hermes-bots/i18n.ts@@ -107,6 +107,27 @@ type BotsMessages = {/** Re-opens the forever-chat on purpose. A plain row click only returns to* the tabs already open, so a closed Bot Chat needs an explicit ask. */openBotChat: string+ /** Row context menu: pin/hide toggles, their toasts, and the groups entry. */+ pinToTop: string+ unpin: string+ pinnedToast: (name: string) => string+ unpinnedToast: (name: string) => string+ hide: string+ unhide: string+ hiddenToast: (name: string) => string+ unhiddenToast: (name: string) => string+ groupsMenu: (groups: string) => string+ manageGroups: string+ metadataLoadFailed: string+ loadFailed: string+ groupsLoadFailed: string+ thisDevice: string+ /** Roster badge tooltips per attention class; `attentionFallback` when the class is unknown. */+ attentionFallback: string+ attentionProviderAuth: string+ attentionQuota: string+ attentionMissingConfig: string+ attentionBlocked: stringduplicate: stringduplicateFailed: stringdeleteTitle: string@@ -349,6 +370,25 @@ const en: BotsMessages = {descriptionHint: 'Leave blank to generate from the bot’s name and description.',newChatWith: 'New chat with this bot',openBotChat: 'Open Bot Chat',+ pinToTop: 'Pin to top',+ unpin: 'Unpin',+ pinnedToast: name => `${name} pinned to top`,+ unpinnedToast: name => `${name} unpinned`,+ hide: 'Hide',+ unhide: 'Unhide',+ hiddenToast: name => `${name} hidden — use the eye button in the Bots header to see hidden bots`,+ unhiddenToast: name => `${name} is back in the roster`,+ groupsMenu: groups => `Groups: ${groups}…`,+ manageGroups: 'Manage groups…',+ metadataLoadFailed: 'Could not load bot metadata',+ loadFailed: 'Could not load bot',+ groupsLoadFailed: 'Could not load bot groups',+ thisDevice: 'This device',+ attentionFallback: 'Needs attention',+ attentionProviderAuth: 'Sign in again for this profile',+ attentionQuota: 'Quota or balance exhausted',+ attentionMissingConfig: 'Provider not configured — run hermes model',+ attentionBlocked: 'Bot is blocked — see its last message',duplicate: 'Duplicate',duplicateFailed: 'Duplicate failed',deleteTitle: 'Delete bot and profile?',@@ -577,6 +617,25 @@ const ja: BotsMessages = {descriptionHint: '空欄のままにすると、ボットの名前と説明から生成します。',newChatWith: 'このボットと新しいチャット',openBotChat: 'ボットチャットを開く',+ pinToTop: '先頭にピン留め',+ unpin: 'ピン留めを解除',+ pinnedToast: name => `${name}を先頭にピン留めしました`,+ unpinnedToast: name => `${name}のピン留めを解除しました`,+ hide: '非表示',+ unhide: '再表示',+ hiddenToast: name => `${name}を非表示にしました — Botsヘッダーの目のボタンで非表示のボットを表示できます`,+ unhiddenToast: name => `${name}が一覧に戻りました`,+ groupsMenu: groups => `グループ: ${groups}…`,+ manageGroups: 'グループを管理…',+ metadataLoadFailed: 'ボットのメタデータを読み込めませんでした',+ loadFailed: 'ボットを読み込めませんでした',+ groupsLoadFailed: 'ボットのグループを読み込めませんでした',+ thisDevice: 'このデバイス',+ attentionFallback: '要対応',+ attentionProviderAuth: 'このプロファイルで再度サインインしてください',+ attentionQuota: 'クォータまたは残高が不足しています',+ attentionMissingConfig: 'プロバイダーが未設定です — hermes model を実行してください',+ attentionBlocked: 'ボットがブロックされています — 最後のメッセージを確認してください',duplicate: '複製',duplicateFailed: '複製に失敗しました',deleteTitle: 'ボットとプロファイルを削除しますか?',@@ -801,6 +860,25 @@ const zh: BotsMessages = {descriptionHint: '留空则根据机器人的名称和描述生成。',newChatWith: '与此机器人开新聊天',openBotChat: '打开机器人聊天',+ pinToTop: '置顶',+ unpin: '取消置顶',+ pinnedToast: name => `已将 ${name} 置顶`,+ unpinnedToast: name => `已取消置顶 ${name}`,+ hide: '隐藏',+ unhide: '取消隐藏',+ hiddenToast: name => `已隐藏 ${name} — 点击机器人标题栏的眼睛按钮可查看隐藏的机器人`,+ unhiddenToast: name => `${name} 已回到列表`,+ groupsMenu: groups => `群聊:${groups}…`,+ manageGroups: '管理群聊…',+ metadataLoadFailed: '无法加载机器人元数据',+ loadFailed: '无法加载机器人',+ groupsLoadFailed: '无法加载机器人的群聊',+ thisDevice: '本设备',+ attentionFallback: '需要处理',+ attentionProviderAuth: '请为此配置档案重新登录',+ attentionQuota: '配额或余额已用尽',+ attentionMissingConfig: '未配置提供商 — 请运行 hermes model',+ attentionBlocked: '机器人已被阻止 — 请查看其最后一条消息',duplicate: '复制',duplicateFailed: '复制失败',deleteTitle: '删除机器人和配置档案?',@@ -1024,6 +1102,25 @@ const zhHant: BotsMessages = {descriptionHint: '留空則依機器人的名稱和描述產生。',newChatWith: '與此機器人開新聊天',openBotChat: '開啟機器人聊天',+ pinToTop: '釘選到頂端',+ unpin: '取消釘選',+ pinnedToast: name => `已將 ${name} 釘選到頂端`,+ unpinnedToast: name => `已取消釘選 ${name}`,+ hide: '隱藏',+ unhide: '取消隱藏',+ hiddenToast: name => `已隱藏 ${name} — 點擊機器人標題列的眼睛按鈕可查看隱藏的機器人`,+ unhiddenToast: name => `${name} 已回到名單`,+ groupsMenu: groups => `群組:${groups}…`,+ manageGroups: '管理群組…',+ metadataLoadFailed: '無法載入機器人中繼資料',+ loadFailed: '無法載入機器人',+ groupsLoadFailed: '無法載入機器人的群組',+ thisDevice: '本裝置',+ attentionFallback: '需要處理',+ attentionProviderAuth: '請為此設定檔重新登入',+ attentionQuota: '配額或餘額已用盡',+ attentionMissingConfig: '未設定供應商 — 請執行 hermes model',+ attentionBlocked: '機器人已被封鎖 — 請查看其最後一則訊息',duplicate: '複製',duplicateFailed: '複製失敗',deleteTitle: '刪除機器人和設定檔?',