修复会话消息中的思考状态显示不正确

This commit is contained in:
xintaofei
2026-03-11 14:06:17 +08:00
parent ced25b6169
commit 99cfc6c91e
12 changed files with 54 additions and 34 deletions

View File

@@ -169,7 +169,15 @@ export function MessageListView({
const { threadItems, nonStreamingAdapted } = useMemo(() => {
const allTurns = timelineTurns.map((item) => item.turn)
const allAdapted = adaptMessageTurns(allTurns, adapterText)
const streamingIndices = new Set<number>()
timelineTurns.forEach((item, i) => {
if (item.phase === "streaming") streamingIndices.add(i)
})
const allAdapted = adaptMessageTurns(
allTurns,
adapterText,
streamingIndices.size > 0 ? streamingIndices : undefined
)
// Collect non-streaming adapted messages for plan extraction
const nonStreaming = allAdapted.filter(

View File

@@ -1185,9 +1185,9 @@
"running": "قيد التشغيل"
},
"reasoning": {
"thinking": "جارٍ التفكير...",
"thoughtForFewSeconds": "فكر لبضع ثوانٍ",
"thoughtForSeconds": "فكر لمدة {duration} ثانية"
"thinking": "جارٍ التفكير",
"thoughtForFewSeconds": "تفكير",
"thoughtForSeconds": "تفكير"
},
"messageList": {
"attachedResources": "الموارد المرفقة",

View File

@@ -1185,9 +1185,9 @@
"running": "Läuft"
},
"reasoning": {
"thinking": "Denkt nach...",
"thoughtForFewSeconds": "Dachte einige Sekunden nach",
"thoughtForSeconds": "Dachte {duration} Sekunden nach"
"thinking": "Denkt nach",
"thoughtForFewSeconds": "Nachgedacht",
"thoughtForSeconds": "Nachgedacht"
},
"messageList": {
"attachedResources": "Angehängte Ressourcen",

View File

@@ -1185,9 +1185,9 @@
"running": "Running"
},
"reasoning": {
"thinking": "Thinking...",
"thoughtForFewSeconds": "Thought for a few seconds",
"thoughtForSeconds": "Thought for {duration} seconds"
"thinking": "Thinking",
"thoughtForFewSeconds": "Thought",
"thoughtForSeconds": "Thought"
},
"messageList": {
"attachedResources": "Attached resources",

View File

@@ -1185,9 +1185,9 @@
"running": "En ejecución"
},
"reasoning": {
"thinking": "Pensando...",
"thoughtForFewSeconds": "Pensó durante unos segundos",
"thoughtForSeconds": "Pensó durante {duration} segundos"
"thinking": "Pensando",
"thoughtForFewSeconds": "Pensamiento",
"thoughtForSeconds": "Pensamiento"
},
"messageList": {
"attachedResources": "Recursos adjuntos",

View File

@@ -1185,9 +1185,9 @@
"running": "En cours"
},
"reasoning": {
"thinking": "Réflexion...",
"thoughtForFewSeconds": "A réfléchi pendant quelques secondes",
"thoughtForSeconds": "A réfléchi pendant {duration} secondes"
"thinking": "Réflexion",
"thoughtForFewSeconds": "Réflexion",
"thoughtForSeconds": "Réflexion"
},
"messageList": {
"attachedResources": "Ressources jointes",

View File

@@ -1185,9 +1185,9 @@
"running": "実行中"
},
"reasoning": {
"thinking": "考え中...",
"thoughtForFewSeconds": "数秒間考えました",
"thoughtForSeconds": "{duration} 秒間考えました"
"thinking": "考え中",
"thoughtForFewSeconds": "考えた",
"thoughtForSeconds": "考えた"
},
"messageList": {
"attachedResources": "添付リソース",

View File

@@ -1185,9 +1185,9 @@
"running": "실행 중"
},
"reasoning": {
"thinking": "생각 중...",
"thoughtForFewSeconds": "몇 초 동안 생각했습니다",
"thoughtForSeconds": "{duration}초 동안 생각했습니다"
"thinking": "생각 중",
"thoughtForFewSeconds": "생각함",
"thoughtForSeconds": "생각함"
},
"messageList": {
"attachedResources": "첨부된 리소스",

View File

@@ -1185,9 +1185,9 @@
"running": "Em execução"
},
"reasoning": {
"thinking": "Pensando...",
"thoughtForFewSeconds": "Pensou por alguns segundos",
"thoughtForSeconds": "Pensou por {duration} segundos"
"thinking": "Pensando",
"thoughtForFewSeconds": "Pensamento",
"thoughtForSeconds": "Pensamento"
},
"messageList": {
"attachedResources": "Recursos anexados",

View File

@@ -1185,9 +1185,9 @@
"running": "运行中"
},
"reasoning": {
"thinking": "思考中...",
"thoughtForFewSeconds": "思考了几秒",
"thoughtForSeconds": "思考了 {duration} 秒"
"thinking": "思考中",
"thoughtForFewSeconds": "思考",
"thoughtForSeconds": "思考"
},
"messageList": {
"attachedResources": "附加资源",

View File

@@ -1185,9 +1185,9 @@
"running": "執行中"
},
"reasoning": {
"thinking": "思考中...",
"thoughtForFewSeconds": "思考了幾秒",
"thoughtForSeconds": "思考了 {duration} 秒"
"thinking": "思考中",
"thoughtForFewSeconds": "思考",
"thoughtForSeconds": "思考"
},
"messageList": {
"attachedResources": "附加資源",

View File

@@ -603,7 +603,8 @@ function buildToolResultMap(
*/
export function adaptMessageTurn(
turn: MessageTurn,
text: AdapterMessageText
text: AdapterMessageText,
isStreaming: boolean = false
): AdaptedMessage {
const adaptedContent: AdaptedContentPart[] = []
const resultMap = buildToolResultMap(turn.blocks)
@@ -703,6 +704,14 @@ export function adaptMessageTurn(
}
}
// Mark the last reasoning block as streaming if the turn is actively streaming
if (isStreaming) {
const last = adaptedContent[adaptedContent.length - 1]
if (last?.type === "reasoning") {
last.isStreaming = true
}
}
const userSplit =
turn.role === "user"
? splitUserTextAndResources(adaptedContent, text.attachedResources)
@@ -730,9 +739,12 @@ export function adaptMessageTurn(
*/
export function adaptMessageTurns(
turns: MessageTurn[],
text: AdapterMessageText
text: AdapterMessageText,
streamingIndices?: Set<number>
): AdaptedMessage[] {
return turns.map((turn) => adaptMessageTurn(turn, text))
return turns.map((turn, i) =>
adaptMessageTurn(turn, text, streamingIndices?.has(i) ?? false)
)
}
/**