Skip to content
Draft
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
3 changes: 2 additions & 1 deletion docs/fixture.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
- Linux 无显示器:先起 `Xvfb :99 &`,再 `DISPLAY=:99 npm run fixture -- all`。缺 libgtk-3 时 `sudo apt-get install -y libgtk-3-0 libnss3 libgbm1 libasound2`。
- 每次用临时 `--user-data-dir`,跑完删掉;不读写任何 BotArk 数据目录。
- 假平台只在 `?e2e=1`(或 localStorage `BOTHUB_E2E=1`)且有 `BOTARK_FAKE_SCRIPT` 时注册,正常使用不会出现(`src/adapters/fake/FakeAdapter.ts`)。
- 剧本:`bots`(名字、账号)、`script.accounts[].steps`(`text` 回复;`kind: silent | abort | error`;`delayMs`)、`rounds`(`say` 发消息或 `retry` 再发一次,`expect` 见 `scripts/fixture/check.mjs`)。
- 剧本:`bots`(名字、账号)、`script.accounts[].steps`(`text` 回复;`kind: silent | abort | error | lost`;`delayMs`;`error` = 没发出去,`lost` = 发出后确认前超时,记「可能已送达,未确认」,PR #61)、`rounds`(`say` 发消息或 `retry` 再发一次,`expect` 见 `scripts/fixture/check.mjs`)。
- 每步输出 `<剧本>-<步>.png` 和 `.json`(消息、错误条、平台收到的原文)。退出码 0 = 全过。
- 剧本 uncertain-delivery:确认前超时显示「可能已送达,未确认」而不是「未送达」(PR #61)。
- 剧本 route-by-description 需要「谁来答」(PR #48)。
- 「谁来答」第 1 步剧本:coordinator-no-pick(选不出→总控,总控派给成员)、coordinator-quota-backup(总控额度不足→备用)、coordinator-error-best(总控、备用都报错→打分最高的在线成员)、mention-direct(@成员直达、@总控、成员答不上→总控)。
- 剧本可选字段:`prefs`(并入 bothub-prefs-v1,如 `roomCoordinatorId`、`roomBackupCoordinatorId`)、`roomBots`(进群的 bot id,默认全部;总控可以不在群里,需要时自动加入);`expect` 新增 `routeReasons`、`sentIncludes`、`members`(见 scripts/fixture/check.mjs)。
Expand Down
54 changes: 54 additions & 0 deletions scripts/fixture/uncertain-delivery.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"title": "确认前超时:可能已送达,不算未送达",
"mode": "auto",
"limit": 4,
"bots": [
{
"id": "bot-a",
"name": "甲",
"account": "fa"
},
{
"id": "bot-b",
"name": "乙",
"account": "fb"
}
],
"script": {
"platform": "meta-muse",
"accounts": [
{
"id": "fa",
"displayName": "甲",
"steps": [
{
"kind": "lost",
"delayMs": 800
}
]
},
{
"id": "fb",
"displayName": "乙",
"steps": []
}
]
},
"rounds": [
{
"say": "@甲 在吗",
"expect": {
"order": [],
"includes": [
"甲 本轮可能已送达,未确认。"
],
"excludes": [
"甲 本轮未送达。"
],
"sentTo": {
"fa": 1
}
}
}
]
}
13 changes: 12 additions & 1 deletion src/adapters/fake/FakeAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export type FakeStep =
| { kind: 'abort'; text?: string; delayMs?: number }
/** The send fails before the platform takes it. */
| { kind: 'error'; text: string; delayMs?: number }
/** The send goes out but times out before the platform confirms it; `text`, if any, arrives later as a late reply. */
| { kind: 'lost'; text?: string; delayMs?: number; lateMs?: number }

export interface FakeAccount {
id: string
Expand Down Expand Up @@ -95,7 +97,16 @@ export class FakeAdapter implements PlatformAdapter {
const step: FakeStep = this.queues.get(accountId)?.shift() ?? { text: OUT_OF_SCRIPT }
if (step.kind === 'error') {
await wait(step.delayMs ?? 0, signal)
throw new AdapterError('network', step.text)
throw new AdapterError('not-connected', step.text)
}
if (step.kind === 'lost') {
await wait(step.delayMs ?? 500, signal)
const late = step.text
if (late) setTimeout(() => this.emit({
type: 'message',
message: { id: createId('fake_in'), conversationId, accountId, text: late, createdAt: Date.now() }
}), step.lateMs ?? 1_000)
throw new AdapterError('timeout', '等待确认超时')
}
const receipt: SendReceipt = { messageId: createId('fake_out'), acceptedAt: Date.now() }
message.onAccepted?.()
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/lib/desktopCopy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe('desktop localization', () => {
usePrefsStore.getState().setLocale('en')
expect(desktopNotice('已达 1 轮上限,待回复:@成员 A')).toBe('Round limit reached (1). Still awaiting: @成员 A')
expect(desktopNotice('成员 A 本轮未送达。')).toBe('The message wasn’t delivered to 成员 A.')
expect(desktopNotice('成员 A 本轮可能已送达,未确认。')).toBe('成员 A may have received the message, but it wasn’t confirmed.')
expect(desktopNotice('可能已送达,未确认(超时)')).toBe('May have been delivered, not confirmed (超时).')
expect(desktopNotice('目录:项目 A')).toBe('目录:项目 A')
const unknown = "Error invoking remote method 'bothub:grok:rpc': Error: 自定义错误"
expect(desktopNotice(unknown)).toBe(unknown)
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/lib/desktopNotices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const desktopNotices: Record<string, string> = {
"{0} 中未包含任何 MCP 服务": "{0} does not contain any MCP services",
"{0} 已收到消息,本轮还没有回复。": "{0} received the message but hasn’t replied yet.",
"{0} 必须为对象": "{0} must be an object.",
"{0} 本轮可能已送达,未确认。": "{0} may have received the message, but it wasn’t confirmed.",
"{0} 本轮未送达。": "The message wasn’t delivered to {0}.",
"@{0} 正忙或已断开连接": "@{0} is busy or disconnected.",
"⚠️ **Grok Bot 执行中断 ({0})**:{1}": "⚠️ **Grok Bot stopped ({0})**: {1}",
Expand Down Expand Up @@ -220,6 +221,7 @@ export const desktopNotices: Record<string, string> = {
"已退出 Grok Bot": "Exited Grok Bot",
"已送达,但应用关闭时回复还没收完": "Delivered, but the app closed before the reply finished.",
"已送达,但没有回复({0})": "Delivered, but no reply was received ({0}).",
"可能已送达,未确认({0})": "May have been delivered, not confirmed ({0}).",
"已送达,但没有收到回复": "Delivered, but no reply received",
"已送达,但等待回复时出错;重发前先确认对方是否已回复": "Delivered, but waiting for the reply failed. Check for a reply before sending again.",
"已送达,后续新消息已接替等待": "Delivered. A newer message is now being tracked.",
Expand Down
86 changes: 86 additions & 0 deletions src/renderer/src/mock/mocks/v34-room-uncertain.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import type { ReactNode } from 'react'
import { AlertCircle, CircleHelp, Quote, RotateCw, Undo2 } from 'lucide-react'
import { Button } from '@/components/ui/Button'
import { cn } from '@/lib/cn'

/**
* v34:发出后、平台确认前超时或断线(PR #61)。
* 左 = 现在:记成「未送达」,红字 + 重试,点了 Bot 可能收到两遍。
* 右 = 方案:灰字「可能已送达,未确认」+ 问号图标;点重试先弹一句确认;迟到的回复照样补进群。
*/
const metaButton = 'press inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 text-[11.5px] text-ink-muted hover:bg-hover hover:text-ink'
const retryButton = 'inline-flex items-center gap-1 rounded-full px-1 text-[11px] font-medium underline-offset-2 hover:underline'

function Column({ title, children }: { title: string; children: ReactNode }) {
return (
<div className="flex w-[560px] flex-col gap-2">
<div className="px-1 text-[13px] font-semibold text-ink">{title}</div>
<div className="flex flex-col gap-4 rounded-2xl border border-line bg-main p-5">{children}</div>
</div>
)
}

function Notice({ text, retry }: { text: string; retry: string }) {
return (
<div className="flex items-center justify-center gap-2 text-[12px] text-ink-muted">
<span>{text}</span>
<span className={cn(retryButton, retry)}><RotateCw className="size-3" aria-hidden /> 重试</span>
</div>
)
}

function Human({ plan }: { plan: boolean }) {
return (
<div className="flex w-full flex-col items-end gap-1">
<div className="max-w-[76%] rounded-[20px] bg-bubble-user px-4 py-2.5 text-[14px] leading-[22px] break-words text-main">@Muse 把上周的周报整理成三段</div>
<div className="flex flex-wrap items-center justify-end gap-1 px-1">
<span className="px-1 text-[11.5px] text-ink-muted tabular-nums">20:14</span>
<span className={metaButton}><Quote className="size-3" aria-hidden /> 引用</span>
<span className={metaButton}><Undo2 className="size-3" aria-hidden /> 撤回</span>
{plan ? (
<span title="等待确认超时" className="inline-flex items-center gap-1.5 px-1 text-[11px] text-ink-secondary">
<CircleHelp className="size-3" aria-hidden /> 可能已送达,未确认(等待确认超时)
<span className={cn(retryButton, 'text-ink-secondary')}><RotateCw className="size-3" aria-hidden /> 重试</span>
</span>
) : (
<span className="inline-flex items-center gap-1.5 px-1 text-[11px] text-status-attention-ink">
<AlertCircle className="size-3" aria-hidden /> 未送达:等待确认超时
<span className={cn(retryButton, 'text-status-attention-ink')}><RotateCw className="size-3" aria-hidden /> 重试</span>
</span>
)}
</div>
</div>
)
}

function Confirm() {
return (
<div className="ml-auto flex w-[340px] flex-col gap-3 rounded-2xl border border-line bg-main p-4 shadow-pop">
<div className="text-[13px] font-medium text-ink">再发一次给 @Muse?</div>
<p className="text-[12px] leading-5 text-ink-secondary">这条可能已经发出,只是平台没确认。再发一次,Muse 可能收到两遍。它的回复如果晚到,会自动补进群里。</p>
<div className="flex justify-end gap-2">
<Button size="sm" variant="secondary">先等等</Button>
<Button size="sm" variant="primary">仍要重试</Button>
</div>
</div>
)
}

export function V34RoomUncertainMock() {
return (
<div className="flex flex-col gap-3">
<div className="flex gap-6">
<Column title="群聊 · 现在">
<Human plan={false} />
<Notice text="Muse 本轮未送达。" retry="text-status-attention-ink" />
</Column>
<Column title="群聊 · 方案:可能已送达,重试先确认">
<Human plan />
<Notice text="Muse 本轮可能已送达,未确认。" retry="text-ink-secondary" />
<Confirm />
</Column>
</div>
<p className="px-1 text-[12px] text-ink-muted">右下是点「重试」后弹出的确认。真没发出去(未连接、账号不存在)仍显示原来的「未送达」,不弹确认。</p>
</div>
)
}
32 changes: 32 additions & 0 deletions src/renderer/src/mock/mocks/v34b-room-uncertain-real.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useEffect } from 'react'
import type { CollabRoom, RoomMember, RoomMessage } from '@/rooms/model'
import { RoomTranscript } from '@/rooms/RoomTranscript'
import { useRooms } from '@/rooms/roomStore'

/** v34 真实组件:可能已送达 / 未送达 两种失败,并自动点开「可能已送达」那条的重试确认。 */
const member = (botId: string, name: string): RoomMember => ({ botId, name, accountId: `acc-${botId}`, platform: 'meta-muse' } as RoomMember)
const MEMBERS = [member('m', 'Muse'), member('d', 'Dot')]
const at = new Date(2026, 11, 3, 20, 14).getTime()
const MESSAGES: RoomMessage[] = [
{ id: 'h1', author: 'User', text: '@Muse 把上周的周报整理成三段', createdAt: at,
failures: [{ botId: 'm', name: 'Muse', error: '等待确认超时', delivered: false, uncertain: true, noticeId: 'n1' }] },
{ id: 'n1', author: 'BotArk', notice: true, text: 'Muse 本轮可能已送达,未确认。', createdAt: at },
{ id: 'h2', author: 'User', text: '@Dot 也看一下', createdAt: at,
failures: [{ botId: 'd', name: 'Dot', error: '未连接', delivered: false, noticeId: 'n2' }] },
{ id: 'n2', author: 'BotArk', notice: true, text: 'Dot 本轮未送达。', createdAt: at }
]
useRooms.setState({ rooms: [{ id: 'mock', title: '周报', members: MEMBERS, messages: MESSAGES, mode: 'manual', limit: 8, brief: '' } as CollabRoom] })

export function V34bRoomUncertainRealMock() {
useEffect(() => {
const button = [...document.querySelectorAll('p button')].find((b) => b.parentElement?.textContent?.includes('可能已送达'))
;(button as HTMLButtonElement | undefined)?.click()
}, [])
return (
<div className="h-[760px] w-[1140px]">
<div className="flex w-[620px] flex-col gap-5 rounded-2xl border border-line bg-main p-5">
<RoomTranscript roomId="mock" members={MEMBERS} messages={MESSAGES} onMentionReply={() => {}} onExport={() => {}} />
</div>
</div>
)
}
4 changes: 4 additions & 0 deletions src/renderer/src/mock/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { V30RoomRoutedMock } from './mocks/v30-room-routed'
import { V31ProjectRowMock } from './mocks/v31-project-row'
import { V33ExternalConfirmMock, V33ExternalFormsMock } from './mocks/v33-external-agents'
import { V33bExternalRealMock } from './mocks/v33b-external-real'
import { V34RoomUncertainMock } from './mocks/v34-room-uncertain'
import { V34bRoomUncertainRealMock } from './mocks/v34b-room-uncertain-real'
import { V32RoomContextMock } from './mocks/v32-room-context'
import { V32bRoomContextLiveMock } from './mocks/v32b-room-context-live'
import { V32RoomWorkflowMock } from './mocks/v32-room-workflow'
Expand Down Expand Up @@ -46,6 +48,8 @@ export const MOCKS: Record<string, ComponentType> = {
'v33-external-forms': V33ExternalFormsMock,
'v33-external-confirm': V33ExternalConfirmMock,
'v33b-external-real': V33bExternalRealMock,
'v34-room-uncertain': V34RoomUncertainMock,
'v34b-room-uncertain-real': V34bRoomUncertainRealMock,
'v32-room-context': V32RoomContextMock,
'v32b-room-context-live': V32bRoomContextLiveMock,
'v32-room-workflow': V32RoomWorkflowMock,
Expand Down
35 changes: 25 additions & 10 deletions src/renderer/src/rooms/RoomMessageStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { desktopCopy, desktopNotice, useDesktopLocale } from '@/lib/desktopCopy'
import { AlertCircle, Check, CheckCheck, Loader2, RotateCw, Route } from 'lucide-react'
import { AlertCircle, Check, CheckCheck, CircleHelp, Loader2, RotateCw, Route } from 'lucide-react'
import { cn } from '@/lib/cn'
import type { RoomMember, RoomMessage } from './model'
import { NO_REPLY_ERROR, resendRoomMessage, useRooms } from './roomStore'
import { messageRouteSteps, routeLineText } from './roomCoordinator'
import { findRetryTarget, retryRoomMember, roomDeliveryState } from './roomRetry'
import { failureKind, UNCERTAIN_NOTICE } from './roomDeliveryKind'
import { useUncertainRetry } from './RoomRetryConfirm'

const retryButton = 'inline-flex items-center gap-1 rounded-full px-1 text-[11px] font-medium underline-offset-2 hover:underline disabled:opacity-50 disabled:no-underline'

Expand All @@ -24,8 +26,10 @@ export function RoomDeliveryState({ roomId, message, members }: {
const speaking = useRooms((s) => Boolean(s.speakers[roomId]))
const state = useRooms((s) => roomDeliveryState(s.rooms.find((r) => r.id === roomId)?.messages ?? [], message.id, speaking))
const failures = message.failures ?? []
const confirm = useUncertainRetry()
return (
<>
{confirm.dialog}
{state === 'replying' && (
<span className="inline-flex items-center gap-1 px-1 text-[11px] text-ink-muted">
<Loader2 className="size-3 animate-spin" aria-hidden /> {desktopCopy("已发出 · 回复中", "Delivered · replying")}
Expand All @@ -37,24 +41,28 @@ export function RoomDeliveryState({ roomId, message, members }: {
</span>
)}
{failures.map((raw) => {
const delivered = raw.delivered ?? (raw.error === NO_REPLY_ERROR || /送达|已收到/.test(raw.error))
// A delivered message never reads as undelivered.
const kind = failureKind(raw, NO_REPLY_ERROR)
const delivered = kind === 'received'
// A delivered message never reads as undelivered; one that may have arrived says so.
const text = delivered
? raw.error === NO_REPLY_ERROR ? NO_REPLY_ERROR : `已送达,但没有回复(${raw.error})`
: `未送达:${raw.error}`
: kind === 'uncertain' ? `可能已送达,未确认(${raw.error})` : `未送达:${raw.error}`
const tone = kind === 'not-sent' ? 'text-status-attention-ink' : kind === 'uncertain' ? 'text-ink-secondary' : 'text-ink-muted'
const Icon = delivered ? CheckCheck : kind === 'uncertain' ? CircleHelp : AlertCircle
const member = members.find((m) => m.botId === raw.botId)
return (
<span key={raw.botId} title={raw.error}
className={cn('inline-flex items-center gap-1.5 px-1 text-[11px]', delivered ? 'text-ink-muted' : 'text-status-attention-ink')}>
{delivered ? <CheckCheck className="size-3" aria-hidden /> : <AlertCircle className="size-3" aria-hidden />}
className={cn('inline-flex items-center gap-1.5 px-1 text-[11px]', tone)}>
<Icon className="size-3" aria-hidden />
{desktopNotice(failures.length > 1 ? `@${raw.name}:${text}` : text)}
{member && (
<button
type="button"
disabled={speaking}
title={speaking ? busyTitle() : desktopCopy("只让 @{0} 再回答这一条", "Ask only @{0} to answer this again", [member.name])}
onClick={() => retryRoomMember(roomId, { messageId: message.id, botId: member.botId })}
className={cn(retryButton, delivered ? 'text-ink-secondary' : 'text-status-attention-ink')}
onClick={() => confirm.ask(kind === 'uncertain', member.name,
() => retryRoomMember(roomId, { messageId: message.id, botId: member.botId }))}
className={cn(retryButton, kind === 'not-sent' ? 'text-status-attention-ink' : 'text-ink-secondary')}
>
<RotateCw className="size-3" aria-hidden /> {desktopCopy("重试", "Retry")}
</button>
Expand All @@ -66,7 +74,10 @@ export function RoomDeliveryState({ roomId, message, members }: {
<button
type="button"
title={desktopCopy("把这条消息再发一次", "Post this message again")}
onClick={() => resendRoomMessage(roomId, message.id)}
onClick={() => {
const unsure = failures.filter((f) => failureKind(f, NO_REPLY_ERROR) === 'uncertain').map((f) => f.name)
confirm.ask(unsure.length > 0, unsure.join('、'), () => resendRoomMessage(roomId, message.id))
}}
className={cn(retryButton, 'text-status-attention-ink')}
>
<RotateCw className="size-3" aria-hidden /> {desktopCopy("再发一次", "Send again")}
Expand All @@ -85,8 +96,11 @@ export function RoomNoticeRow({ roomId, message }: { roomId: string; message: Ro
const found = room ? findRetryTarget(room, message.id) : undefined
return found ? `${found.messageId}\u0000${found.botId}` : undefined
})
const confirm = useUncertainRetry()
const uncertain = message.text.endsWith(UNCERTAIN_NOTICE)
return (
<p className="mx-auto flex items-center gap-1.5 text-xs text-ink-muted">
{confirm.dialog}
{desktopNotice(message.text)}
{target && (
<button
Expand All @@ -95,7 +109,8 @@ export function RoomNoticeRow({ roomId, message }: { roomId: string; message: Ro
title={speaking ? busyTitle() : desktopCopy("让这位成员重新回答同一条", "Ask this member to answer the same message again")}
onClick={() => {
const [messageId, botId] = target.split('\u0000') as [string, string]
retryRoomMember(roomId, { messageId, botId, noticeId: message.id })
const name = message.text.slice(0, -UNCERTAIN_NOTICE.length).trim()
confirm.ask(uncertain, name, () => retryRoomMember(roomId, { messageId, botId, noticeId: message.id }))
}}
className={cn(retryButton, 'text-accent-700 dark:text-accent-400')}
>
Expand Down
Loading