fix: make inbox confirmation retry safe

This commit is contained in:
2026-07-21 18:42:47 +08:00
parent 85a25ca017
commit 7c363bb473
4 changed files with 83 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
import { useMemo, useRef, useState } from 'react'
import { Alert, Button, Card, Checkbox, Empty, Space, Tag, Typography } from '@arco-design/web-react'
import { IconCheckCircle, IconRobot } from '@arco-design/web-react/icon'
import { ApiError } from '../../api/client'
import type { InboxSuggestionDTO } from '../../api/inbox'
import type { InboxConfirmationOutcome, InboxItem, ProjectWorkspace } from './project-types'
@@ -76,7 +77,7 @@ export function ProjectInbox({ activeWorkspace, onAnalyze, onConfirm }: ProjectI
setSuccess(`已创建 ${outcome.createdCount} 个对象`)
setRefreshWarning(outcome.refreshError ?? '')
} catch (reason) {
setError(reason instanceof Error ? reason.message : '确认创建失败,请稍后重试')
setError(confirmationErrorMessage(reason))
} finally {
setConfirming(false)
}
@@ -191,7 +192,7 @@ export function ProjectInbox({ activeWorkspace, onAnalyze, onConfirm }: ProjectI
<Button
type="primary"
loading={confirming}
disabled={analyzing || isInboxItemProcessed(selectedItem, locallyConfirmedItemIds) || draftSuggestions.length === 0}
disabled={confirming || analyzing || isInboxItemProcessed(selectedItem, locallyConfirmedItemIds) || draftSuggestions.length === 0}
onClick={() => void confirmSelectedSuggestions()}
>
@@ -206,6 +207,13 @@ export function ProjectInbox({ activeWorkspace, onAnalyze, onConfirm }: ProjectI
)
}
function confirmationErrorMessage(reason: unknown) {
if (reason instanceof ApiError && (reason.code === 'network_error' || reason.code === 'invalid_response')) {
return '确认结果未知,服务端支持幂等处理,可安全重试'
}
return reason instanceof Error ? reason.message : '确认创建失败,请稍后重试'
}
function isInboxItemProcessed(item: InboxItem, locallyConfirmedItemIds: string[]) {
return item.status !== 'open' || locallyConfirmedItemIds.includes(item.id)
}