fix: keep Pascal agent progress visible

This commit is contained in:
134 2026-07-13 10:09:55 +08:00
parent e820df7eb6
commit 603163d6ec

View File

@ -140,6 +140,28 @@ function ToolActivity({ part }: { part: DisplayPart }) {
)
}
function processingStatusText(messages: UIMessage[], status: string): string {
if (status === 'submitted') return '正在分析当前场景'
for (let messageIndex = messages.length - 1; messageIndex >= 0; messageIndex--) {
const message = messages[messageIndex]
if (message?.role !== 'assistant') continue
for (let partIndex = message.parts.length - 1; partIndex >= 0; partIndex--) {
const part = displayPartFrom(message.parts[partIndex])
const toolName = toolNameFromPart(part)
if (toolName) {
if (part.state === 'output-available') return '正在校验并保存建模结果'
if (part.state === 'output-error') return '正在调整执行方案'
return `正在${TOOL_LABELS[toolName] ?? toolName.replaceAll('_', ' ')}`
}
if (part.type === 'text' && part.text) return '正在继续处理建模任务'
}
}
return '正在生成建模方案'
}
export function AiDesignAgentPanel({ sceneId }: AiDesignAgentPanelProps) {
const activeConversationKey = `pascal-agent-active-conversation:${sceneId}`
const [input, setInput] = useState('')
@ -174,6 +196,10 @@ export function AiDesignAgentPanel({ sceneId }: AiDesignAgentPanelProps) {
transport,
})
const isRunning = status === 'submitted' || status === 'streaming'
const runningStatusText = useMemo(
() => processingStatusText(messages, status),
[messages, status],
)
const latestMessageRenderKey = useMemo(() => {
const latest = messages.at(-1)
if (!latest) return ''
@ -538,15 +564,19 @@ export function AiDesignAgentPanel({ sceneId }: AiDesignAgentPanelProps) {
</div>
</div>
))}
{status === 'submitted' ? (
<div className="flex items-center gap-2 text-muted-foreground text-xs">
<LoaderCircle className="h-3.5 w-3.5 animate-spin" />
正在分析当前场景
</div>
) : null}
<div ref={endRef} />
</div>
)}
{isRunning ? (
<div
aria-live="polite"
className="mt-4 flex items-center gap-2 text-muted-foreground text-xs"
role="status"
>
<LoaderCircle className="h-3.5 w-3.5 shrink-0 animate-spin" />
<span>{runningStatusText}</span>
</div>
) : null}
<div ref={endRef} />
</div>
<div className="shrink-0 border-border/70 border-t p-3">