mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-18 15:48:39 +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
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package helps
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/MoeForge/moego/ojson"
|
|
)
|
|
|
|
// StripVertexOpenAIResponsesToolCallIDs removes OpenAI Responses call IDs that
|
|
// Vertex rejects in Gemini functionCall/functionResponse payloads.
|
|
func StripVertexOpenAIResponsesToolCallIDs(payload []byte, sourceFormat string) []byte {
|
|
if len(payload) == 0 || !strings.EqualFold(strings.TrimSpace(sourceFormat), "openai-response") {
|
|
return payload
|
|
}
|
|
doc := ojson.NewDoc(payload)
|
|
if !StripVertexOpenAIResponsesToolCallIDsDoc(doc, sourceFormat) {
|
|
return payload
|
|
}
|
|
return doc.Bytes()
|
|
}
|
|
|
|
// StripVertexOpenAIResponsesToolCallIDsDoc removes OpenAI Responses call IDs that
|
|
// Vertex rejects in Gemini functionCall/functionResponse payloads in place on doc.
|
|
func StripVertexOpenAIResponsesToolCallIDsDoc(doc *ojson.Doc, sourceFormat string) bool {
|
|
if doc == nil || doc.Len() == 0 || !strings.EqualFold(strings.TrimSpace(sourceFormat), "openai-response") {
|
|
return false
|
|
}
|
|
|
|
contents := doc.Get("contents")
|
|
if !contents.IsArray() {
|
|
return false
|
|
}
|
|
|
|
changed := false
|
|
for cIdx, content := range contents.Array() {
|
|
parts := content.Get("parts")
|
|
if !parts.IsArray() {
|
|
continue
|
|
}
|
|
for pIdx, part := range parts.Array() {
|
|
for _, field := range []string{"functionCall.id", "functionResponse.id"} {
|
|
if !part.Get(field).Exists() {
|
|
continue
|
|
}
|
|
if errDel := doc.Delete(fmt.Sprintf("contents.%d.parts.%d.%s", cIdx, pIdx, field)); errDel == nil {
|
|
changed = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return changed
|
|
}
|