Add projects

This commit is contained in:
Alois 2026-08-24 00:10:41 +02:00
commit 8b607dd700
Signed by: alois
SSH key fingerprint: SHA256:GBzT2DXvAuGV9XIV5W3WrzVpjU54FThmxHXdbz95J24
1802 changed files with 503346 additions and 2 deletions

View file

@ -0,0 +1,39 @@
package helps
import (
translatorcommon "github.com/router-for-me/CLIProxyAPI/v7/internal/translator/common"
"github.com/router-for-me/CLIProxyAPI/v7/internal/util"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)
var emptyGeminiUserTurnJSON = []byte(`{"role":"user","parts":[{"text":""}]}`)
// EnsureGeminiLeadingUserContent ensures that the contents array at the given path
// starts with a user turn when sending to Gemini/Antigravity upstreams.
func EnsureGeminiLeadingUserContent(payload []byte, path string) []byte {
firstRole := gjson.GetBytes(payload, path+".0.role")
if firstRole.String() != "model" {
return payload
}
contents := util.GetGJSONBytesNoCopy(payload, path)
if !contents.IsArray() {
return payload
}
contentArray := contents.Array()
if len(contentArray) == 0 {
return payload
}
contentItems := make([][]byte, 0, len(contentArray)+1)
contentItems = append(contentItems, emptyGeminiUserTurnJSON)
for _, content := range contentArray {
contentItems = append(contentItems, []byte(content.Raw))
}
out, errSet := sjson.SetRawBytes(payload, path, translatorcommon.JoinRawArray(contentItems))
if errSet != nil {
return payload
}
return out
}