mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-16 22:57:53 +08:00
- Replace tidwall/gjson and tidwall/sjson with github.com/MoeForge/moego/ojson and encoding/base64 with github.com/MoeForge/moego/base64 across the main module and examples - Introduce cross-method *ojson.Doc request rewriting pipelines across thinking, signature, client/codex, runtime/executor/helps, pluginhost, and all provider executors with FinalizePayloadDoc as the final semantic barrier - Convert all consecutive JSON mutations (>= 2 Set/SetRaw/Delete operations) to batch edits on ojson.Doc - Upgrade read-only byte paths to ojson.GetBytesNoCopy, ojson.GetManyBytesNoCopy, and util.ParseGJSONBytesNoCopy with explicit strings.Clone ownership protection across streaming and persistent state - Use base64.StdEncoding.ValidateString for zero-allocation signature checks and base64.EncodeDataURL for single-allocation data URL construction
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package thinking
|
|
|
|
import (
|
|
"github.com/MoeForge/moego/ojson"
|
|
)
|
|
|
|
// GetThinkingText extracts the thinking text from a content part.
|
|
// Handles various formats:
|
|
// - Simple string: { "thinking": "text" } or { "text": "text" }
|
|
// - Wrapped object: { "thinking": { "text": "text", "cache_control": {...} } }
|
|
// - Gemini-style: { "thought": true, "text": "text" }
|
|
// Returns the extracted text string.
|
|
func GetThinkingText(part ojson.Result) string {
|
|
// Try direct text field first (Gemini-style)
|
|
if text := part.Get("text"); text.Exists() && text.Type == ojson.String {
|
|
return text.String()
|
|
}
|
|
|
|
// Try thinking field
|
|
thinkingField := part.Get("thinking")
|
|
if !thinkingField.Exists() {
|
|
return ""
|
|
}
|
|
|
|
// thinking is a string
|
|
if thinkingField.Type == ojson.String {
|
|
return thinkingField.String()
|
|
}
|
|
|
|
// thinking is an object with inner text/thinking
|
|
if thinkingField.IsObject() {
|
|
if inner := thinkingField.Get("text"); inner.Exists() && inner.Type == ojson.String {
|
|
return inner.String()
|
|
}
|
|
if inner := thinkingField.Get("thinking"); inner.Exists() && inner.Type == ojson.String {
|
|
return inner.String()
|
|
}
|
|
}
|
|
|
|
return ""
|
|
}
|