Add thinking duration to message parts

Why: The chat timeline needs a persisted thinking duration, and tool duration already lives on the tool call, so the thinking part had nowhere to put it.
Evidence: go test ./... passes; the message golden now includes durationMs on the thinking part.
Impact: Additive JSON field with omitempty. Existing clients ignore unknown fields.
Refs: feature/chat-timeline-preview
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-01 06:03:19 +00:00
co-authored by Cursor
parent 1b04a34bbc
commit d4375300cd
4 changed files with 8 additions and 2 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ func sampleMessage() Message {
ID: "msg_abc123def456", ConversationID: "cnv_abc123def456", RunID: "run_abc123def456",
Role: RoleAssistant,
Parts: []Part{
{Type: PartThinking, Text: "考虑先检索…", Process: true},
{Type: PartThinking, Text: "考虑先检索…", Process: true, DurationMs: 1500},
{Type: PartToolCall, Process: true, ToolCall: &ToolCallPart{ID: "call_1", Name: "history_search", Arguments: `{"q":"部署"}`, Duration: 12.5}},
{Type: PartToolResult, Process: true, ToolResult: &ToolResultPart{CallID: "call_1", Status: "ok", Summary: "3 条命中"}},
{Type: PartText, Text: "根据历史记录……"},
+4
View File
@@ -89,6 +89,10 @@ type Part struct {
// 过程标记:true 的部件在 run 终态后由前端折叠为摘要行(4.2)。
Process bool `json:"process,omitempty"`
// DurationMs 是 thinking 部件的思考时长(毫秒,从首个推理增量到最后一个)。
// 工具耗时在 ToolCallPart.Duration,不复用本字段。
DurationMs float64 `json:"durationMs,omitempty"`
}
type ToolCallPart struct {
+2 -1
View File
@@ -7,7 +7,8 @@
{
"type": "thinking",
"text": "考虑先检索…",
"process": true
"process": true,
"durationMs": 1500
},
{
"type": "tool_call",
+1
View File
@@ -35,6 +35,7 @@ export interface Part {
card?: { kind: string; data: UINode[]; cardId?: ID }; // cardId 非空 = 收件箱卡片引用部件(submit_card)
error?: { code: string; message: string };
process?: boolean; // run 终态后折叠为摘要行
durationMs?: number; // thinking 部件的思考时长(毫秒);工具耗时在 toolCall.durationMs
}
export interface Message {