fix(provider): robust validation of Gemini thought_signature rejecting reasoning_content and ASCII strings
This commit is contained in:
+15
-4
@@ -1873,11 +1873,22 @@ function antgWithQueue<T>(fn: () => Promise<T>): Promise<T> {
|
||||
|
||||
function isValidGeminiThoughtSignature(sig: any): sig is string {
|
||||
if (typeof sig !== "string" || !sig.trim()) return false;
|
||||
// I payload di reasoning di altri provider (es. DeepSeek / OpenAI) sono stringhe JSON come {"id":"rs_..."}
|
||||
// che Google rifiuta con errore di decodifica Base64 (TYPE_BYTES).
|
||||
if (sig.startsWith("{") || sig.startsWith("[")) return false;
|
||||
// I payload di reasoning di altri provider possono essere stringhe JSON come {"id":"rs_..."}
|
||||
// o etichette come "reasoning_content" / "thought" che Google rifiuta con Base64 decoding failed.
|
||||
if (sig.startsWith("{") || sig.startsWith("[") || sig === "reasoning_content" || sig === "thought" || sig.length < 32) {
|
||||
return false;
|
||||
}
|
||||
if (!/^[A-Za-z0-9+/=_-]+$/.test(sig)) return false;
|
||||
return sig.length >= 16;
|
||||
try {
|
||||
const buf = Buffer.from(sig, "base64");
|
||||
if (buf.length < 24) return false;
|
||||
// Le firme crittografiche Gemini contengono byte binari (non solo testo ASCII leggibile)
|
||||
const str = buf.toString("utf8");
|
||||
if (/^[a-zA-Z0-9_ -]+$/.test(str)) return false;
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function antgBuildGeminiRequest(model: Model<Api>, context: Context, options?: SimpleStreamOptions): any {
|
||||
|
||||
Reference in New Issue
Block a user