Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions internal/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func convertMessages(claudeMessages []models.ClaudeMessage, system string) []mod
case []interface{}:
// Handle complex content blocks
var textParts []string
var thinkingParts []string
var toolCalls []models.OpenAIToolCall
var hasToolResult bool

Expand All @@ -258,6 +259,16 @@ func convertMessages(claudeMessages []models.ClaudeMessage, system string) []mod
textParts = append(textParts, text)
}

case "thinking":
// Carry Anthropic thinking blocks back upstream as
// reasoning_content on the assistant message. Required
// by Moonshot AI / Kimi when thinking is enabled —
// without this the provider rejects multi-turn tool
// calls with "reasoning_content is missing".
if text, ok := blockMap["thinking"].(string); ok {
thinkingParts = append(thinkingParts, text)
}

case "tool_use":
// Convert tool_use to OpenAI's tool_calls format
toolUseID, _ := blockMap["id"].(string)
Expand Down Expand Up @@ -317,9 +328,10 @@ func convertMessages(claudeMessages []models.ClaudeMessage, system string) []mod
if !hasToolResult {
textContent := strings.Join(textParts, "\n")
openaiMessages = append(openaiMessages, models.OpenAIMessage{
Role: msg.Role,
Content: textContent,
ToolCalls: toolCalls,
Role: msg.Role,
Content: textContent,
ToolCalls: toolCalls,
ReasoningContent: strings.Join(thinkingParts, "\n"),
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/models/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ type OpenAIMessage struct {
ToolCalls []OpenAIToolCall `json:"tool_calls,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
ReasoningDetails []interface{} `json:"reasoning_details,omitempty"` // OpenRouter reasoning
// ReasoningContent carries prior assistant reasoning (Anthropic `thinking`
// blocks) on multi-turn tool-use messages. Moonshot AI / Kimi rejects
// assistant tool_call messages when thinking is enabled and reasoning_content
// is missing (error: "thinking is enabled but reasoning_content is missing
// in assistant tool call message").
ReasoningContent string `json:"reasoning_content,omitempty"`
}

// OpenAIToolCall represents a tool call in OpenAI format
Expand Down