feat: preserve and echo thinking blocks for extended-thinking models (DeepSeek, Claude thinking mode)

This commit is contained in:
sausheong committed 2026-07-12 20:30:48 +08:00
1 parent d3c74e5681
commit 152d8b972e
6 files changed
+116 -17

No files matched your search

+21 -2
View File
@@ -36,10 +36,18 @@ type ImageData struct {
Data string `json:"data"` // base64-encoded
}
// ThinkingBlockData stores a thinking block from a model response.
// It must be echoed back verbatim in subsequent turns.
type ThinkingBlockData struct {
Thinking string `json:"thinking"`
Signature string `json:"signature,omitempty"`
}
// MessageData holds text message content.
type MessageData struct {
Text string `json:"text"`
Images []ImageData `json:"images,omitempty"`
Text string `json:"text"`
Images []ImageData `json:"images,omitempty"`
ThinkingBlocks []ThinkingBlockData `json:"thinking_blocks,omitempty"`
}
// ToolCallData holds a tool call's details.
@@ -338,6 +346,17 @@ func AssistantMessageEntry(text string) SessionEntry {
}
}
// AssistantMessageEntryWithThinking creates an assistant message entry that
// includes thinking blocks which must be echoed back in subsequent turns.
func AssistantMessageEntryWithThinking(text string, blocks []ThinkingBlockData) SessionEntry {
data, _ := json.Marshal(MessageData{Text: text, ThinkingBlocks: blocks})
return SessionEntry{
Type: EntryTypeMessage,
Role: "assistant",
Data: data,
}
}
// ToolCallEntry creates a tool call entry.
//
// input is sanitised to "{}" when empty or not valid JSON. The