gateway: a Command Code Go conversation moved onto its plugin keeps its reasoning — the built-in replayed each assistant turn's reasoning to /alpha/generate, and the chat request built for the plugin carried reasoning_content only to DeepSeek, so the plugin, which reads it, had none to replay. Command Code's plugin gets it too. TestCommandCodePluginReasoning fails without the change.

This commit is contained in:
yetone
2026-10-01 03:41:45 +08:00
parent 4157b279f9
commit db024bcd50
2 changed files with 25 additions and 2 deletions
+6 -2
View File
@@ -7,6 +7,8 @@ import (
"net"
"strings"
"time"
"github.com/yetone/magpie/internal/provider"
)
// ---- OpenAI Chat Completions --------------------------------------------------
@@ -176,7 +178,9 @@ func buildChat(r *Request, model, host string, rejectTemp bool) []byte {
if r.System != "" {
msgs = append(msgs, map[string]any{"role": "system", "content": r.System})
}
deepseek := strings.Contains(host, "deepseek")
// DeepSeek takes a turn's reasoning back, as Command Code's plugin does
// for a Go key, as the built-in replayed it to /alpha/generate
replay := strings.Contains(host, "deepseek") || host == provider.CommandCodePlanID
// A tool message holds text only, so the images tools returned go to
// the model in a user message after the tool messages, as the start of
// the user's own message when one comes next: some models' chat
@@ -231,7 +235,7 @@ func buildChat(r *Request, model, host string, rejectTemp bool) []byte {
if len(calls) > 0 {
am["tool_calls"] = calls
}
if deepseek && think != "" {
if replay && think != "" {
am["reasoning_content"] = think
}
msgs = append(msgs, am)
+19
View File
@@ -118,3 +118,22 @@ func TestCursorPluginFast(t *testing.T) {
}
}
}
// A Command Code Go conversation moved onto its plugin keeps its
// reasoning, as the built-in replayed it to /alpha/generate: its plugin
// reads reasoning_content. DeepSeek still gets it, others don't.
func TestCommandCodePluginReasoning(t *testing.T) {
reasoning := func(host string) any {
return chatBody(t, host)["messages"].([]any)[1].(map[string]any)["reasoning_content"]
}
for _, host := range []string{provider.CommandCodePlanID, "api.deepseek.com"} {
if got := reasoning(host); got != "pondered" {
t.Errorf("%s got reasoning %v", host, got)
}
}
for _, host := range []string{"api.openai.com", "cursor", "zed"} {
if got := reasoning(host); got != nil {
t.Errorf("%s got reasoning_content %v", host, got)
}
}
}