mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 16:07:33 +00:00
fix(apicompat): skip foreign CC Switch reasoning envelopes
This commit is contained in:
1 parent
f178e5ae32
commit
552d1ab4bb
2 files changed
+50
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package apicompat
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
@@ -197,6 +198,50 @@ func TestAnthropicToResponses_ThinkingSignatureBecomesReasoning(t *testing.T) {
|
||||
assert.Equal(t, "function_call", items[3].Type)
|
||||
}
|
||||
|
||||
func TestAnthropicToResponses_ForeignReasoningEnvelopePreservesToolHistory(t *testing.T) {
|
||||
envelope := "ccswitch-openai-reasoning-v1:" + base64.RawURLEncoding.EncodeToString([]byte(
|
||||
`{"type":"reasoning","id":"rs_1","summary":[],"encrypted_content":"gAAAA-foreign"}`,
|
||||
))
|
||||
for _, tc := range []struct{ name, signature string }{
|
||||
{"valid envelope", envelope},
|
||||
{"surrounding whitespace", " \n" + envelope + "\t"},
|
||||
{"malformed envelope", "ccswitch-openai-reasoning-v1:not-base64!"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
blocks, err := json.Marshal([]AnthropicContentBlock{
|
||||
{Type: "thinking", Signature: tc.signature},
|
||||
{Type: "thinking", Signature: "native-ciphertext"},
|
||||
{Type: "text", Text: "Checking now."},
|
||||
{Type: "tool_use", ID: "call_1", Name: "lookup", Input: json.RawMessage(`{"key":"value"}`)},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
resp, err := AnthropicToResponses(&AnthropicRequest{
|
||||
Model: "gpt-6.1-sol", MaxTokens: 1024,
|
||||
Messages: []AnthropicMessage{
|
||||
{Role: "user", Content: json.RawMessage(`"Check this"`)},
|
||||
{Role: "assistant", Content: blocks},
|
||||
{Role: "user", Content: json.RawMessage(`[{"type":"tool_result","tool_use_id":"call_1","content":"found"}]`)},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
var items []ResponsesInputItem
|
||||
require.NoError(t, json.Unmarshal(resp.Input, &items))
|
||||
require.Len(t, items, 5)
|
||||
require.Equal(t, "reasoning", items[1].Type)
|
||||
require.Equal(t, "native-ciphertext", items[1].EncryptedContent)
|
||||
require.Equal(t, "assistant", items[2].Role)
|
||||
require.JSONEq(t, `[{"type":"output_text","text":"Checking now."}]`, string(items[2].Content))
|
||||
require.Equal(t, "function_call", items[3].Type)
|
||||
require.Equal(t, "call_1", items[3].CallID)
|
||||
require.Equal(t, "lookup", items[3].Name)
|
||||
require.JSONEq(t, `{"key":"value"}`, items[3].Arguments)
|
||||
require.Equal(t, "function_call_output", items[4].Type)
|
||||
require.Equal(t, "call_1", items[4].CallID)
|
||||
require.Equal(t, "found", items[4].Output)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnthropicToResponses_MaxTokensFloor(t *testing.T) {
|
||||
req := &AnthropicRequest{
|
||||
Model: "gpt-5.2",
|
||||
|
||||
@@ -302,6 +302,11 @@ func anthropicAssistantToResponses(raw json.RawMessage) ([]ResponsesInputItem, e
|
||||
if sig == "" || strings.HasPrefix(sig, "gAAAA") {
|
||||
continue
|
||||
}
|
||||
// CC Switch carries a JSON reasoning item in this versioned envelope,
|
||||
// not provider ciphertext. Ignore the foreign state when resuming directly.
|
||||
if strings.HasPrefix(sig, "ccswitch-openai-reasoning-v1:") {
|
||||
continue
|
||||
}
|
||||
items = append(items, ResponsesInputItem{
|
||||
Type: "reasoning",
|
||||
EncryptedContent: sig,
|
||||
|
||||
Reference in new issue
Block a user