mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-04 14:26:45 +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
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package helps
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
|
|
"github.com/MoeForge/moego/ojson"
|
|
)
|
|
|
|
// IsGeminiTerminalStreamChunk recognizes terminal output from Gemini stream translators.
|
|
func IsGeminiTerminalStreamChunk(chunk []byte) bool {
|
|
for _, line := range bytes.Split(chunk, []byte("\n")) {
|
|
trimmed := bytes.TrimSpace(line)
|
|
if bytes.Equal(trimmed, []byte("data: [DONE]")) || bytes.Equal(trimmed, []byte("[DONE]")) {
|
|
return true
|
|
}
|
|
payload := JSONPayload(line)
|
|
if len(payload) == 0 {
|
|
continue
|
|
}
|
|
eventType := ojson.GetBytesNoCopy(payload, "type").String()
|
|
if eventType == "response.completed" || eventType == "response.incomplete" || eventType == "response.done" || eventType == "message_stop" {
|
|
return true
|
|
}
|
|
for _, path := range []string{
|
|
"choices.0.finish_reason",
|
|
"response.choices.0.finish_reason",
|
|
"candidates.0.finishReason",
|
|
"response.candidates.0.finishReason",
|
|
} {
|
|
if finishReason := ojson.GetBytesNoCopy(payload, path); finishReason.Exists() && strings.TrimSpace(finishReason.String()) != "" {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|